book-index-ui 0.9.7 → 0.9.8
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 +12 -9
- package/dist/index.d.ts +85 -2
- package/dist/index.js +2689 -2549
- package/dist/storage.d.ts +12 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
"use strict";var Eo=Object.create;var ii=Object.defineProperty;var Bo=Object.getOwnPropertyDescriptor;var Lo=Object.getOwnPropertyNames;var Wo=Object.getPrototypeOf,$o=Object.prototype.hasOwnProperty;var Ao=(t,n,i,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Lo(n))!$o.call(t,s)&&s!==i&&ii(t,s,{get:()=>n[s],enumerable:!(r=Bo(n,s))||r.enumerable});return t};var pt=(t,n,i)=>(i=t!=null?Eo(Wo(t)):{},Ao(n||!t||!t.__esModule?ii(i,"default",{value:t,enumerable:!0}):i,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Z=require("./storage-entry-BLfpDWdl.cjs"),e=require("react/jsx-runtime"),f=require("react"),Fo=require("react-markdown"),Po=require("remark-gfm"),Mo=require("react-dom"),Oo=t=>`/book-index?id=${t}`,Zi=f.createContext(Oo);function Ho({buildUrl:t,children:n}){const i=f.useMemo(()=>t,[t]);return e.jsx(Zi.Provider,{value:i,children:n})}function je(){return f.useContext(Zi)}const Qi="",er="";function tr(t){const n=[];let i=!1,r=t;for(;r.length;){const s=i?er:Qi,o=r.indexOf(s);if(o===-1){n.push({text:r,marked:i});break}o>0&&n.push({text:r.slice(0,o),marked:i}),r=r.slice(o+1),i=!i}return n}function Xe(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function Do(t,n){return Xe(t).includes(n)}const nr={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},No={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},Vo={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},Ct=f.createContext(null),ir={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:"圖片資源"}},Go={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:"图片资源"}},Uo={"zh-Hant":ir,"zh-Hans":Go},rr="bim-locale";function Yo(){try{const t=localStorage.getItem(rr);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function Ko(t){try{localStorage.setItem(rr,t)}catch{}}const Jo="zh-Hans",qo=({locale:t,onLocaleChange:n,children:i})=>{const[r,s]=f.useState(t??Jo),o=t??r;f.useEffect(()=>{if(t)return;const p=Yo();p&&p!==r&&s(p)},[]);const[l,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 a=f.useCallback(p=>{s(p),Ko(p),n==null||n(p)},[n]),d=f.useMemo(()=>({locale:o,setLocale:a,messages:Uo[o],converter:l}),[o,a,l]);return e.jsx(Ct.Provider,{value:d,children:i})};function N(){const t=f.useContext(Ct);return(t==null?void 0:t.messages)??ir}const Xo=2e3;function M(){const t=f.useContext(Ct),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(l=>{if(!l)return"";if(!i)return l;const c=r.current.get(l);if(c!==void 0)return c;const a=i(l);if(r.current.size>=Xo){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(l,a),a},[i]);return f.useMemo(()=>({convert:o,locale:n,isSimplified:n==="zh-Hans"}),[o,n])}function Tt(t,n){return t.replace(/\{(\w+)\}/g,(i,r)=>String(n[r]??""))}function Zo(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 Qo(){return{id:"",name:"",url:"",type:"text",details:""}}const gn=({items:t,onChange:n,onDownload:i,downloadStatuses:r,filterType:s})=>{const o=N(),[l,c]=f.useState(null),a=[{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=Xe(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=Qo();s&&(m.type=s),n([...t,m]),c(t.length)},u=m=>{n(t.filter((j,_)=>_!==m)),c(null)},b=(m,j,_)=>{const w=[...t];if(w[m]={...w[m],[j]:_},j==="url"&&!w[m].id){const T=Zo(_);T&&(w[m].id=T)}n(w)},y=(m,j,_)=>{const T={...t[m].metadata||{}};_?T[j]=_:delete T[j],b(m,"metadata",Object.keys(T).length>0?T:void 0)},h=(m,j)=>{const _=j.trim()?j.split(/[,,、]/).map(w=>w.trim()).filter(Boolean):void 0;b(m,"structure",_)},S=(m,j,_)=>{const T=t[m].coverage||{level:1,ranges:""};j==="level"?T.level=parseInt(_)||1:T.ranges=_,b(m,"coverage",T.ranges?T:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:m,originalIndex:j})=>{var _,w,T;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>c(l===j?null:j),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:l===j?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:es(m.type??"text"),color:"#fff"},children:(()=>{var k,z;const C=Xe(m);return C.length===0?m.type??"text":C.length===1?((k=a.find(I=>I.value===C[0]))==null?void 0:k.label)??C[0]:C.includes("text")&&C.includes("image")?((z=a.find(I=>I.value==="text+image"))==null?void 0:z.label)??"text+image":C.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:C=>C.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&m.url&&ts(j,r==null?void 0:r[j],i,o),e.jsx("button",{onClick:C=>{C.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:"✕"})]}),l===j&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[Do(m,"image")&&m.url&&ns(m,o),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:ut,children:[e.jsx("span",{style:ft,children:o.label.type}),e.jsx("select",{value:m.type,onChange:C=>b(j,"type",C.target.value),style:{...We,flex:1},children:a.map(C=>e.jsx("option",{value:C.value,children:C.label},C.value))})]}),e.jsxs("label",{style:ut,children:[e.jsx("span",{style:ft,children:o.label.rootType}),e.jsx("select",{value:m.root_type||"catalog",onChange:C=>b(j,"root_type",C.target.value),style:{...We,flex:1},children:d.map(C=>e.jsx("option",{value:C.value,children:C.label},C.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:m.id,onChange:C=>b(j,"id",C.target.value),placeholder:o.editor.idAutoExtract,style:{...We,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:m.name,onChange:C=>b(j,"name",C.target.value),placeholder:o.editor.resourceName,style:{...We,flex:1}})]}),e.jsx("input",{type:"text",value:m.url,onChange:C=>b(j,"url",C.target.value),placeholder:o.editor.resourceUrl,style:We}),e.jsx("input",{type:"text",value:((_=m.structure)==null?void 0:_.join("、"))||"",onChange:C=>h(j,C.target.value),placeholder:o.editor.structurePlaceholder,style:We}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:ut,children:[e.jsx("span",{style:ft,children:o.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((w=m.coverage)==null?void 0:w.level)??"",onChange:C=>S(j,"level",C.target.value),placeholder:"1",style:{...We,width:"60px"}})]}),e.jsxs("label",{style:{...ut,flex:1},children:[e.jsx("span",{style:ft,children:o.label.coverageRange}),e.jsx("input",{type:"text",value:((T=m.coverage)==null?void 0:T.ranges)||"",onChange:C=>S(j,"ranges",C.target.value),placeholder:o.editor.coverageRangePlaceholder,style:{...We,flex:1}})]})]}),e.jsx("textarea",{value:m.details||"",onChange:C=>b(j,"details",C.target.value),placeholder:o.editor.detailsPlaceholder,style:{...We,minHeight:"60px",resize:"vertical"}}),e.jsxs("div",{style:{borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",paddingTop:"8px",marginTop:"4px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:o.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(o.metadata).map(([C,k])=>{var z;return e.jsxs("label",{style:{...ut,gap:"4px"},children:[e.jsx("span",{style:{...ft,minWidth:"56px"},children:k}),e.jsx("input",{type:"text",value:((z=m.metadata)==null?void 0:z[C])||"",onChange:I=>y(j,C,I.target.value),placeholder:k,style:{...We,flex:1}})]},C)})})]})]})]})]},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 es(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 ts(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:l=>{l.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 ns(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 We={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},ut={display:"flex",alignItems:"center",gap:"6px"},ft={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},is={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive"};function kt(t){try{return is[new URL(t).hostname]}catch{return}}const ri={text:0,image:1,physical:2};function _n(t){return t.length===0?"physical":[...t].sort((n,i)=>(ri[n]??99)-(ri[i]??99)).join("+")}function Cn(t){var l;const n=c=>{const a=c.match(/^(.+?)·第(\d+)[冊册]$/);if(a)return[a[1],parseInt(a[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 a=t[c];if(a.volumes&&a.volumes.length>0)continue;const d=n(a.name);if(!d)continue;const[p,x]=d,g=`${p}|${_n(Xe(a))}`;i.has(g)||i.set(g,{base:{...a,name:p,url:"",volumes:[]},volumes:[],indices:[]});const u=i.get(g);u.volumes.push({volume:x,url:a.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((a,d)=>a.volume-d.volume),c.base.volumes=c.volumes,c.base.expected_volumes=c.volumes.length,c.base.url||(c.base.url=((l=c.volumes.find(a=>a.url))==null?void 0:l.url)??""),r.push(c.base);for(const a of c.indices)s.add(a)}const o=[...r];for(let c=0;c<t.length;c++)s.has(c)||o.push(t[c]);return o}function or(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 sr(t){return!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(n=>({...n,url:n.url||or(n)}))}function Tn(t){const n=sr(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 In(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 zn(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 Ht(t){if(!t.url)return;const n=In(t.metadata);return n?zn(t.url,n):t.url}const oi={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 rs(t){return t.includes("text")&&t.includes("image")?oi["text+image"]:oi[t[0]||"physical"]}const Rn=({items:t,groupByType:n=!0,resourceGroups:i,onNavigate:r,renderLink:s})=>{const o=N(),{convert:l}=M(),c=f.useMemo(()=>Cn(t||[]),[t]),{mirrorGroups:a,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,_)=>{const w=T=>T.group_role==="origin"?0:T.group_role==="mirror"?1:2;return w(j)-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(nn,{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,_=m==null?void 0:m.description;return e.jsxs("div",{style:{padding:"10px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fafafa)",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(j)}),_&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.5},children:l(_)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.map((w,T)=>e.jsx(nn,{item:w,onNavigate:r,renderLink:s},w.id||T))})]},`group-${h}`)},u=new Map;for(const h of d){const S=_n(Xe(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:[[...a.entries()].map(([h,S])=>g(h,S)),y.map(h=>{const S=u.get(h),m=rs(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,_)=>e.jsx(nn,{item:j,onNavigate:r,renderLink:s},j.id||_))})]},h)})]})},os={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)"}},nn=({item:t})=>{const n=N(),{convert:i}=M(),[r,s]=f.useState(!1),o=f.useMemo(()=>(t.url?kt(t.url):void 0)||i(t.name),[t.url,t.name,i]),l=f.useMemo(()=>!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(b=>({...b,url:b.url||or(b)})),[t.volumes]),c=l&&l.length>0,a=c?new Set(l.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,d=c?new Set(l.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,p=t.expected_volumes??(c?a+d:0),x=t.color_mode?{...os[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:[a,"/",p,n.unit.volume,d>0&&e.jsxs("span",{style:{color:"var(--bim-missing-fg, #e67e22)",marginLeft:"3px"},children:["缺",d]})]}),t.url&&e.jsx("a",{href:(()=>{const b=In(t.metadata);return b?zn(t.url,b):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),c&&e.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),c&&r&&e.jsx("div",{style:{padding:"6px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:l.map(b=>{const y=b.status==="missing";return b.url&&!y?e.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:b.volume},b.volume):e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:y?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",textDecoration:y?"line-through":"none",opacity:y?.6:1},children:b.volume},b.volume)})})]})},lr=({indexSource:t,syncConfig:n,variant:i="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:o,onSelectFolder:l})=>{const c=N(),a=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"?a?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:l,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:a?c.mode.switchToGithub:c.mode.switchToLocal,style:g,...u,children:[e.jsx("span",{children:a?"📁":"🌐"}),e.jsx("span",{children:a?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&e.jsxs("div",{onClick:l,title:p||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:p?"100px":"auto",justifyContent:"space-between"},...u,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!a&&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})]})]})},Gt="bim-search-history",si=10,li=8;function yt(){try{const t=localStorage.getItem(Gt);return t?JSON.parse(t):[]}catch{return[]}}function ss(t){try{const n=yt().filter(i=>i!==t);n.unshift(t),n.length>si&&(n.length=si),localStorage.setItem(Gt,JSON.stringify(n))}catch{}}function ls(t){try{const n=yt().filter(i=>i!==t);localStorage.setItem(Gt,JSON.stringify(n))}catch{}}function as(){try{localStorage.removeItem(Gt)}catch{}}const ar=({transport:t,value:n,onChange:i,onSearch:r,onEntrySelect:s,placeholder:o})=>{const l=N(),c=o??l.search.placeholder,a={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[d,p]=f.useState(!1),[x,g]=f.useState([]),[u,b]=f.useState(-1),[y,h]=f.useState(yt),S=f.useRef(null),m=f.useRef(null),j=f.useRef(null),_=f.useRef(!1);f.useEffect(()=>{b(-1);const v=n.trim();if(!v){g(y.map(P=>({type:"history",text:P})));return}if(!t.searchAll){g([]);return}let E=!1;const R=setTimeout(()=>{t.searchAll(v,li).then(P=>{if(E)return;const $=[...P.works,...P.books,...P.collections,...P.entities??[]];g($.slice(0,li).map(H=>({type:"entry",text:H.title||H.id,entry:H})))}).catch(()=>{E||g([])})},80);return()=>{E=!0,clearTimeout(R)}},[n,y,t]),f.useEffect(()=>{const v=E=>{j.current&&!j.current.contains(E.target)&&p(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]),f.useEffect(()=>{const v=E=>{var R,P;if(E.key==="/"&&document.activeElement!==S.current){const $=(R=document.activeElement)==null?void 0:R.tagName;if($==="INPUT"||$==="TEXTAREA"||$==="SELECT")return;E.preventDefault(),(P=S.current)==null||P.focus()}};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[]);const w=f.useCallback(v=>{v.trim()&&(ss(v.trim()),h(yt())),r(v),p(!1)},[r]),T=f.useCallback(v=>{v.type==="history"?(i(v.text),w(v.text)):v.entry&&(s?(s(v.entry),p(!1)):(i(v.text),w(v.text)))},[i,w,s]),C=f.useCallback(v=>{if(!d||x.length===0){v.key==="Enter"&&w(n);return}switch(v.key){case"ArrowDown":v.preventDefault(),b(E=>(E+1)%x.length);break;case"ArrowUp":v.preventDefault(),b(E=>(E-1+x.length)%x.length);break;case"Enter":v.preventDefault(),u>=0&&u<x.length?T(x[u]):w(n);break;case"Escape":v.preventDefault(),p(!1);break}},[d,x,u,n,w,T]),k=f.useCallback((v,E)=>{E.stopPropagation(),ls(v),h(yt()),g(R=>R.filter(P=>!(P.type==="history"&&P.text===v)))},[]),z=f.useCallback(v=>{v.stopPropagation(),as(),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:()=>{_.current=!0},onCompositionEnd:()=>{_.current=!1},onFocus:()=>{p(!0)},onKeyDown:C,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:l.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:l.search.clearAll})]}),x.map((v,E)=>e.jsxs("div",{onClick:()=>T(v),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:E===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:[a[v.entry.type],v.entry.edition&&` · ${v.entry.edition}`,v.entry.author&&` · ${v.entry.author}`]}),v.type==="history"&&e.jsx("button",{onClick:R=>k(v.text,R),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:l.action.remove,children:"×"})]},`${v.type}-${v.text}-${E}`))]})]})},wt="bim-recent-ids",ai="bim-recent-entries",ci=50,rn=5,cs=50,ds=200;function vt(){try{const t=localStorage.getItem(wt);if(t)return JSON.parse(t);const n=localStorage.getItem(ai);if(n){const i=JSON.parse(n).map(r=>r.id);return localStorage.setItem(wt,JSON.stringify(i)),localStorage.removeItem(ai),i}return[]}catch{return[]}}function ps(t){try{const n=vt().filter(i=>i!==t);n.unshift(t),n.length>ci&&(n.length=ci),localStorage.setItem(wt,JSON.stringify(n))}catch{}}function us(t){try{const n=vt().filter(i=>i!==t);localStorage.setItem(wt,JSON.stringify(n))}catch{}}function fs(){try{localStorage.removeItem(wt)}catch{}}const xs={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},mn=({transport:t,indexSource:n="local",syncConfig:i,onEntryClick:r,onNewEntry:s,onSwitchMode:o,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a,hideModeIndicator:d,resultVariant:p="compact",renderEntry:x,initialQuery:g,onQueryChange:u,headerRight:b})=>{const y=N(),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,_]=f.useState(null),[w,T]=f.useState(null),[C,k]=f.useState(!1),[z,I]=f.useState(null),[v,E]=f.useState(""),[R,P]=f.useState(!g),[$,H]=f.useState(vt),[A,F]=f.useState([]),[q,W]=f.useState(!1),[K,ie]=f.useState(!1),[Y,L]=f.useState(null),[J,X]=f.useState(null),G=f.useRef(void 0),U=f.useRef(!1),ce=f.useCallback(async(D,se)=>{if(!D.trim()){P(!0),_(null),T(null);return}P(!1),k(!0),E("");try{if(t.searchAll){const ee=await t.searchAll(D,se??rn);_(ee)}else{const ee=["work","book","collection","entity"],B=await Promise.all(ee.map(Q=>t.search(D,Q,{page:1,pageSize:se??rn})));_({works:B[0].entries,books:B[1].entries,collections:B[2].entries,entities:B[3].entries,totalWorks:B[0].total,totalBooks:B[1].total,totalCollections:B[2].total,totalEntities:B[3].total})}}catch(ee){E(ee instanceof Error?ee.message:String(ee)),_(null)}finally{k(!1)}},[t]);f.useEffect(()=>{let D=!1;const se=()=>{var oe,_e;const ee=["work","book","collection","entity"],B=Promise.all(ee.map(Ce=>t.loadEntries(Ce,{page:1,pageSize:1}).catch(()=>({total:0})))),Q=((oe=t.getResourceCounts)==null?void 0:oe.call(t).catch(()=>null))??Promise.resolve(null),le=((_e=t.getSubtypeStats)==null?void 0:_e.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([B,Q,le]).then(([Ce,me,Ge])=>{D||(L({works:Ce[0].total,books:Ce[1].total,collections:Ce[2].total,entities:Ce[3].total,hasText:me==null?void 0:me.hasText,hasImage:me==null?void 0:me.hasImage}),Ge&&X(Ge))})};return t.getCounts?t.getCounts().then(ee=>{var B,Q;D||(L({works:ee.works,books:ee.books,collections:ee.collections,entities:ee.entities,hasText:(B=ee.resourceCounts)==null?void 0:B.hasText,hasImage:(Q=ee.resourceCounts)==null?void 0:Q.hasImage}),ee.subtypeStats&&X(ee.subtypeStats))}).catch(()=>{D||se()}):se(),()=>{D=!0}},[t]),f.useEffect(()=>{U.current||!(g!=null&&g.trim())||(U.current=!0,ce(g))},[g,ce]);const we=f.useCallback(D=>{if(m(D),!D.trim()){u==null||u(D),P(!0),_(null),T(null);return}G.current&&clearTimeout(G.current),G.current=setTimeout(()=>{T(null),u==null||u(D),ce(D)},ds)},[ce,u]),fe=f.useCallback(D=>{G.current&&clearTimeout(G.current),u==null||u(D),ce(D)},[ce,u]),ae=f.useCallback(D=>{T(D),ce(S,cs)},[S,ce]);f.useEffect(()=>{if(!$.length){F([]);return}let D=!1;return W(!0),Promise.all($.slice(0,10).map(async se=>{var ee,B,Q;try{if(t.getEntry){const oe=await t.getEntry(se);if(oe)return oe}const le=await t.getItem(se);if(le){const oe=le.authors;return{id:se,title:le.title||se,type:le.type||"work",author:(ee=oe==null?void 0:oe[0])==null?void 0:ee.name,dynasty:(B=oe==null?void 0:oe[0])==null?void 0:B.dynasty,role:(Q=oe==null?void 0:oe[0])==null?void 0:Q.role,edition:le.edition||void 0}}}catch{}return{id:se,title:se,type:"work",notFound:!0}})).then(se=>{D||(F(se),W(!1))}),()=>{D=!0}},[$,t]);const Se=D=>{I(D.id),ps(D.id),H(vt()),r==null||r(D)},Ee=D=>{us(D),H(vt())},dt=()=>{fs(),H([])},Fe=D=>h.find(se=>se.type===D),Be=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(lr,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:o,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(ar,{transport:t,value:S,onChange:we,onSearch:fe,onEntrySelect:Se}),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})]}),Y&&R&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[e.jsx("span",{children:J?e.jsxs(e.Fragment,{children:[(J.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:J.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Y.books.toLocaleString()})," 本"]}),J.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:J.article.toLocaleString()})," 篇"]}):null,J.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:J.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Y.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[y.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Y.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Y.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Y.collections.toLocaleString()}),Y.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:Y.entities.toLocaleString()})]})]})}),Y.hasImage!=null&&Y.hasText!=null&&e.jsxs("span",{children:[y.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Y.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Y.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:C?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})]}):R?e.jsx("div",{style:{flex:1},children:q?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:dt,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,K?10:3).map(D=>D.notFound?e.jsx(hs,{id:D.id,onRemove:Ee,t:y},D.id):e.jsx(di,{entry:D,selected:z===D.id,onClick:Se,getConfig:Fe,onRemove:Ee},D.id))}),!K&&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})]})}):Be?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:h.map(({type:D,icon:se,name:ee,key:B})=>{const Q=j[B]??[],le=xs[B],oe=j[le]??0;if(Q.length===0)return null;const Ce=!(w===D)&&oe>rn;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:[se," ",ee,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[oe," ",y.unit.items]})]}),Ce&&e.jsx("button",{onClick:()=>ae(D),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:Q.map(me=>{if(x)return e.jsx(f.Fragment,{children:x(me)},me.id);const Ge=p==="card"?ms:di;return e.jsx(Ge,{entry:me,selected:z===me.id,onClick:Se,getConfig:Fe,query:S},me.id)})})]},D)})}):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:Tt(y.search.noResultsFor,{query:S})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y.search.tryOther})]})})]})},gs=({snippet:t})=>{const{convert:n}=M();return e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.6},children:tr(t).map((i,r)=>i.marked?e.jsx("mark",{style:{background:"var(--bim-highlight-bg, #fff3a3)",color:"var(--bim-highlight-fg, inherit)",padding:"0 1px",borderRadius:"2px"},children:n(i.text)},r):e.jsx(f.Fragment,{children:n(i.text)},r))})},ms=({entry:t,selected:n,onClick:i,getConfig:r,query:s})=>{const o=N(),{convert:l}=M(),c=l(t.title||t.primary_name||t.id),a=t.measure_info?l(t.measure_info):t.juan_count!=null&&t.juan_count>0?`${t.juan_count}${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}),a&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:a})]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[t.dynasty&&e.jsxs("span",{children:["〔",l(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:l(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",l(t.role)]})]}),(t.era||t.edition)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[t.era&&e.jsxs("span",{children:["〔",l(t.era),"〕"]}),t.edition&&e.jsx("span",{children:l(t.edition)})]}),p&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[o.search.alias,":",l(typeof p=="string"?p:p.book_title||"")]}),t.descriptionSnippet&&e.jsx(gs,{snippet:t.descriptionSnippet}),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]})]})]})]})},di=({entry:t,selected:n,onClick:i,getConfig:r,query:s,onRemove:o})=>{const l=N(),{convert:c}=M(),a=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&a.length?a.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:l.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:l.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,l.unit.juan]}):null]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",c(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:c(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",c(t.role)]}),t.type==="entity"&&(t.birth_year!=null||t.death_year!=null)&&e.jsxs("span",{style:{marginLeft:t.dynasty?"4px":0},children:[t.birth_year??"?","—",t.death_year??"?"]})]}),d&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[l.search.alias,":",c(d)]})]}),o?e.jsx("button",{onClick:p=>{p.stopPropagation(),o(t.id)},title:l.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1,opacity:.5,marginTop:"2px"},children:"×"}):e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},hs=({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 bs(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 ys({data:t}){const{convert:n}=M(),{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 vs({alt_names:t}){const{convert:n}=M(),i=new Map;for(const o of t){const l=o.type||"別名";i.has(l)||i.set(l,[]),i.get(l).push(o.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((o,l)=>{const c=r.indexOf(o),a=r.indexOf(l);return c===-1&&a===-1?0:c===-1?1:a===-1?-1:c-a});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:s.map(o=>{const l=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:l.map((c,a)=>e.jsxs("span",{children:[a>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(c)]},a))})]},o)})})}function js({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 Ss({works:t,transport:n,onNavigate:i,renderLink:r}){const s=N(),{convert:o}=M(),l=je(),[c,a]=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 _=!0;for(let w=0;w<u.length;w++){const T=j[w];T!=null&&T.title?y.set(u[w],T.title):T!=null&&T.primary_name?y.set(u[w],T.primary_name):_=!1}if(_)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 T=await n.getEntry(j);if(T!=null&&T.title){y.set(j,T.title);continue}}const _=await n.getItem(j),w=_&&(_.title||_.primary_name)||j;y.set(j,w)}catch{y.set(j,j)}}});return await Promise.all(m),y})().then(y=>{g||a(y)}),()=>{g=!0}},[t,n]);const d=new Map;for(const g of t){const u=g.role||"";d.has(u)||d.set(u,[]),d.get(u).push(g)}const p=["撰","編","注","輯","集","校","評","譯","述","作",""],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:l(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 cr=({data:t,transport:n,onNavigate:i,renderLink:r,headerExtra:s,hideHeader:o})=>{var x;const l=N(),{convert:c}=M();let a=!1;try{a=Z.extractStatus(t.id)==="draft"}catch{}const d=bs(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(ys,{data:t})]}),s]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:"var(--bim-type-entity, #5b3e8e)",border:"1px solid color-mix(in srgb, var(--bim-type-entity, #5b3e8e) 25%, transparent)",borderRadius:"2px",background:"color-mix(in srgb, var(--bim-type-entity, #5b3e8e) 3%, transparent)"},children:l.indexType.entity}),p&&t.subtype!=="people"&&e.jsx("span",{children:p}),a&&e.jsx("span",{style:{padding:"1px 6px",background:"var(--bim-warn-bg, #fff3cd)",border:"1px solid var(--bim-warn-border, #ffc107)",borderRadius:"2px",color:"var(--bim-warn-fg, #856404)"},children:l.status.draft}),e.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:t.id})]})]}),d&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #999)",fontStyle:"italic",padding:"8px 12px",background:"var(--bim-widget-bg, #f8f8f8)",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),t.alt_names&&t.alt_names.length>0&&e.jsx(vs,{alt_names:t.alt_names}),e.jsx(js,{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(Ss,{works:t.works,transport:n,onNavigate:i,renderLink:r})]})},dr={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})},ks={...dr,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},Oe=({text:t,plainStrong:n,style:i,className:r})=>{const{convert:s}=M(),o=n?ks:dr;return e.jsx("div",{className:r,style:i,children:e.jsx(Fo,{remarkPlugins:[Po],components:o,children:s(t)})})},ws=["〇","一","二","三","四","五","六","七","八","九"],pi=["","十","百","千"];function pr(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 l=parseInt(n[o]),c=i-1-o;l===0?s=!0:(s&&r&&(r+="〇"),s=!1,l===1&&c===1&&o===0?r+=pi[c]:r+=ws[l]+pi[c])}return r}function ur(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 _s={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 Cs({type:t}){const n=N();return e.jsx("span",{style:ur(_s[t]),children:n.indexType[t]})}function Ts({isDraft:t}){const n=N(),i=t?"var(--bim-status-draft, #e67e22)":"var(--bim-status-official, #27ae60)";return e.jsx("span",{style:ur(i),children:t?n.status.draft:n.status.official})}function Is({id:t}){const n=N(),[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 ke({children:t,extra:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",letterSpacing:"1px"},children:t}),e.jsx("span",{style:{flex:1}}),n]})}function $e({label:t,children:n}){return e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[e.jsx("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:t}),e.jsx("span",{style:{color:"var(--bim-fg, #333)"},children:n})]})}function fr({authors:t,type:n,onNavigate:i,renderLink:r}){const{convert:s}=M();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((o,l)=>{const c=s(o.name),a=o.entity_id?e.jsx(Ie,{id:o.entity_id,label:c,onNavigate:i,renderLink:r}):e.jsx("span",{style:{fontWeight:500},children:c});return e.jsxs("span",{children:[l>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),o.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",s(o.dynasty),"〕"]}),a,o.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",s(o.role)]})]},l)})})}function Ie({id:t,label:n,onNavigate:i,renderLink:r}){const s=je();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 zs({id:t,title:n,edition:i,type:r,isDraft:s,authors:o,volumeText:l,meta:c,headerExtra:a,onNavigate:d,renderLink:p}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,i&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:i}),l&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:l})]}),a&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:a})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(Cs,{type:r}),e.jsx(Ts,{isDraft:s}),e.jsx(Is,{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(fr,{authors:o,type:r,onNavigate:d,renderLink:p}),c]})]})}function xr({items:t,label:n,showMeta:i,onNavigate:r,renderLink:s}){const o=N(),{convert:l}=M();if(!t.length)return null;const[c,a]=f.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(ke,{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:()=>a(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:l(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:l(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(Ie,{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($e,{label:o.label.titleInfo,children:l(d.title_info)}),d.author_info&&e.jsx($e,{label:o.label.authorInfo,children:l(d.author_info)}),d.edition&&e.jsx($e,{label:o.label.edition,children:l(d.edition)})]}),d.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(d.summary)})]}),d.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(d.comment)})]}),d.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(d.additional_comment)})]})]})]},p)})})]})}function Rs({items:t,onNavigate:n,renderLink:i}){const r=N();return e.jsx(xr,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function gr({items:t,onNavigate:n,renderLink:i}){const r=N();return e.jsx(xr,{items:t,label:r.section.emendated,onNavigate:n,renderLink:i})}function mr({label:t,items:n}){const{convert:i}=M();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(ke,{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 Es({items:t}){const n=N();return e.jsx(mr,{label:n.section.aliases,items:t})}function Bs({items:t}){const n=N();return e.jsx(mr,{label:n.section.attachedTexts,items:t})}function Ls({items:t}){const n=N(),{convert:i}=M();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ke,{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 Ws({items:t}){const n=N(),{convert:i}=M();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ke,{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 $s({items:t}){const n=N(),{convert:i}=M();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ke,{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 ui({title:t,ids:n,transport:i,onNavigate:r,renderLink:s}){const{convert:o}=M(),[l,c]=f.useState([]);return f.useEffect(()=>{if(!n.length){c([]);return}if(!i){c(n.map(d=>({id:d})));return}let a=!1;return Promise.all(n.map(d=>i.getItem(d).then(p=>({id:d,title:p?p.title:void 0,edition:p?p.edition:void 0,type:p?p.type:void 0})).catch(()=>({id:d})))).then(d=>{a||c(d)}),()=>{a=!0}},[n,i]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(ke,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(l.length?l:n.map(a=>({id:a}))).map(a=>{const d=a.edition?`${o(a.title)||a.id}(${o(a.edition)})`:o(a.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(Ie,{id:a.id,label:d,onNavigate:r,renderLink:s})},a.id)})})]}):null}function on({book:t,onNavigate:n,renderLink:i}){const r=N(),{convert:s}=M(),[o,l]=f.useState(!1),c=t.resources&&t.resources.length>0,a=t.edition?s(t.edition):s(t.title)||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{padding:"6px 12px",borderBottom:c&&!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(Ie,{id:t.id,label:a,onNavigate:n,renderLink:i})}),c&&e.jsx("span",{onClick:()=>l(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform: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(Rn,{items:t.resources,resourceGroups:t.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function As({ids:t,workData:n,transport:i,onNavigate:r,renderLink:s,footer:o}){const l=N(),{convert:c}=M(),[a,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=a.length?a: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(ke,{children:[l.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(on,{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(on,{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(on,{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,l=!o&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!o&&l.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(r),a=new Set([...s,...l]),d=m=>{if(a.has(m))return!0;const 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 _=b.get(m);return{id:m,label:(_==null?void 0:_.label)??m,description:_==null?void 0:_.description,ids:j}});return g.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:p,groupedIds:y}}function Ps({workData:t,onNavigate:n,renderLink:i}){var l,c,a,d;const r=N(),{convert:s}=M(),o=!!((l=t.description)!=null&&l.text)||!!t.parent_work;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"6px 14px",borderBottom: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(Ie,{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:[pr(t.juan_count.number),r.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(fr,{authors:t.authors,type:"work",onNavigate:n,renderLink:i})})]}),o&&e.jsxs("div",{style:{padding:"8px 14px"},children:[((a=t.description)==null?void 0:a.text)&&e.jsx(Oe,{text:t.description.text,style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,textAlign:"justify"}}),t.parent_work&&e.jsx("div",{style:{marginTop:(d=t.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:e.jsx($e,{label:r.label.parentWork,children:e.jsx(Ie,{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=N(),{convert:s}=M();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(Ie,{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:Tt(r.catalog.volume,{n:o.volume_index})})]},o.id))}):null}const En=({data:t,id:n,transport:i,onNavigate:r,renderLink:s,headerExtra:o,relatedBooksFooter:l,className:c,style:a})=>{var E,R,P,$,H,A,F,q;const d=N(),{convert:p}=M(),[x,g]=f.useState(null),[u,b]=f.useState(!1),[y,h]=f.useState(null),[S,m]=f.useState(null),[j,_]=f.useState([]),w=t||x;if(f.useEffect(()=>{if(t||!n||!i)return;let W=!1;return b(!0),h(null),i.getItem(n).then(K=>{W||(K?g(K):h(d.misc.notFoundEntry))}).catch(K=>{W||h(K instanceof Error?K.message:d.misc.loadFailed)}).finally(()=>{W||b(!1)}),()=>{W=!0}},[t,n,i]),f.useEffect(()=>{if(!w||!i){m(null),_([]);return}let W=!1;const K=w.type==="book"||w.type==="collection"?w.work_id:void 0;if(K?i.getItem(K).then(ie=>{!W&&ie&&ie.type==="work"&&m(ie)}).catch(()=>{}):m(null),w.type==="book"){const ie=w;ie.contained_in&&ie.contained_in.length>0?Promise.all(ie.contained_in.map(Y=>{const L=typeof Y=="string"?Y:Y.id,J=typeof Y=="string"?void 0:Y.volume_index;return i.getItem(L).then(X=>({id:L,title:X&&X.title||L,volume_index:J})).catch(()=>({id:L,title:L,volume_index:J}))})).then(Y=>{W||_(Y)}):_([])}else _([]);return()=>{W=!0}},[w,i]),u)return e.jsx("div",{className:c,style:{...a,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((W,K)=>e.jsx("div",{style:{height:K===1?"32px":"16px",width:`${W}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},K))})});if(y)return e.jsx("div",{className:c,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y});if(!w)return null;if(w.type==="entity")return e.jsx("div",{className:c,style:a,children:e.jsx(cr,{data:w,transport:i,onNavigate:r,renderLink:s,headerExtra:o})});const T=w.type==="book"?w:null,C=w.type==="collection"?w:null,k=w.type==="work"?w:null;let z=!1;try{z=Z.extractStatus(w.id)==="draft"}catch{}let I="";w.measure_info?I=p(w.measure_info):(E=w.juan_count)!=null&&E.number?I=pr(w.juan_count.number)+d.unit.juan:(R=w.juan_count)!=null&&R.description&&(I=p(w.juan_count.description));const v=[];return(P=w.publication_info)!=null&&P.year&&v.push(e.jsx($e,{label:d.label.year,children:w.publication_info.year},"year")),($=w.current_location)!=null&&$.name&&v.push(e.jsx($e,{label:d.label.currentLocation,children:p(w.current_location.name)},"loc")),(H=w.page_count)!=null&&H.description&&v.push(e.jsx($e,{label:d.label.pageCount,children:w.page_count.description},"page")),T!=null&&T.edition&&v.push(e.jsx($e,{label:d.label.edition,children:p(T.edition)},"ver")),k!=null&&k.parent_work&&v.push(e.jsx($e,{label:d.label.parentWork,children:e.jsx(Ie,{id:k.parent_work.id,label:p(k.parent_work.title),onNavigate:r,renderLink:s})},"pw")),k!=null&&k.parent_works&&k.parent_works.length>0&&!k.parent_work&&v.push(e.jsx($e,{label:d.label.parentWork,children:k.parent_works.map((W,K)=>e.jsxs("span",{children:[K>0&&"、",e.jsx(Ie,{id:W,onNavigate:r,renderLink:s})]},W))},"pws")),e.jsxs("div",{className:c,style:a,children:[e.jsx(zs,{id:w.id,title:p(w.title),edition:w.edition?p(w.edition):void 0,type:w.type,isDraft:z,authors:w.authors,volumeText:I,meta:v,headerExtra:o,onNavigate:r,renderLink:s}),((A=w.description)==null?void 0:A.text)&&e.jsx(Oe,{text:w.description.text,style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),w.appendix&&w.appendix.length>0&&e.jsx("div",{style:{marginTop:8,marginBottom:4},children:w.appendix.map((W,K)=>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(Oe,{text:W.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:"var(--bim-fg, #444)"}})]},K))}),j.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{children:d.section.containedIn}),e.jsx(Ms,{items:j,onNavigate:r,renderLink:s})]}),S&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{children:d.section.belongsToWork}),e.jsx(Ps,{workData:S,onNavigate:r,renderLink:s})]}),w.additional_works&&w.additional_works.length>0&&e.jsx(Ls,{items:w.additional_works}),w.additional_titles&&w.additional_titles.length>0&&e.jsx(Es,{items:w.additional_titles}),w.attached_texts&&w.attached_texts.length>0&&e.jsx(Bs,{items:w.attached_texts}),w.indexed_by&&w.indexed_by.length>0&&e.jsx(Rs,{items:w.indexed_by,onNavigate:r,renderLink:s}),w.emendated_by&&w.emendated_by.length>0&&e.jsx(gr,{items:w.emendated_by,onNavigate:r,renderLink:s}),w.resources&&w.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{children:d.section.resources}),e.jsx(Rn,{items:w.resources,resourceGroups:w.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(T==null?void 0:T.location_history)&&T.location_history.length>0&&e.jsx(Ws,{items:T.location_history}),(C==null?void 0:C.history)&&C.history.length>0&&e.jsx($s,{items:C.history}),(T==null?void 0:T.related_books)&&T.related_books.length>0&&e.jsx(ui,{title:d.section.relatedVersions,ids:T.related_books,transport:i,onNavigate:r,renderLink:s}),(C==null?void 0:C.books)&&C.books.length>0&&e.jsx(ui,{title:d.section.containedBooks,ids:C.books,transport:i,onNavigate:r,renderLink:s}),(C==null?void 0:C.contained_works)&&C.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(ke,{children:[d.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",C.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:C.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(Ie,{id:W.id,label:p(W.title),onNavigate:r,renderLink:s})},W.id))})]}),(((F=k==null?void 0:k.books)==null?void 0:F.length)||0)+(((q=k==null?void 0:k.collections)==null?void 0:q.length)||0)>0&&e.jsx(As,{ids:[...(k==null?void 0:k.books)||[],...(k==null?void 0:k.collections)||[]],workData:k,transport:i,onNavigate:r,renderLink:s,footer:l}),(k==null?void 0:k.related_works)&&k.related_works.length>0&&(()=>{const W=[],K=k.related_works.filter(G=>G.relation==="part_of"),ie=k.related_works.filter(G=>G.relation==="has_part"),Y=k.related_works.filter(G=>G.relation==="has_adaptation"),L=k.related_works.filter(G=>G.relation==="text_carried_by"),J=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),X=k.related_works.filter(G=>!G.relation||!J.has(G.relation));return K.length>0&&W.push({label:d.section.belongsToWork,items:K}),ie.length>0&&W.push({label:d.section.containedWorks,items:ie}),Y.length>0&&W.push({label:d.section.adaptations,items:Y}),L.length>0&&W.push({label:d.section.derivativeWorks,items:L}),X.length>0&&W.push({label:d.section.relatedWorks,items:X}),W.map(G=>e.jsxs("div",{children:[e.jsxs(ke,{children:[G.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",G.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:G.items.map(U=>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(Ie,{id:U.id,label:p(U.title),onNavigate:r,renderLink:s})},U.id))})]},G.label))})()]})};function Os({data:t}){const n=N(),{convert:i}=M(),{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 Hs({sections:t,activeSection:n,onSelect:i}){const r=N();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>i(null),style:fi(n===null),children:r.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>i(s.name),style:fi(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 fi(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 Ds({id:t,label:n,onNavigate:i,renderLink:r}){const s=je();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 Ns(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 xi({book:t,onNavigate:n,renderLink:i,showVolumes:r}){const s=N(),{convert:o}=M(),l=t.book_id||t.work_id,c=r&&t.volumes.length>0?Ns(t.volumes,s.unit.volume):null,a=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[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:a?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),l&&e.jsx(Ds,{id:l,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!l&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:s.catalog.unmatched_label})]})}const Bn=({data:t,collectionId:n,transport:i,onNavigate:r,renderLink:s,className:o,style:l})=>{const c=N(),[a,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||a;f.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollectionCatalog))return;let C=!1;return x(!0),u(null),i.getCollectionCatalog(n).then(k=>{C||(k?d(k):u(c.catalog.notFound))}).catch(k=>{C||u(k instanceof Error?k.message:c.catalog.loadFailed)}).finally(()=>{C||x(!1)}),()=>{C=!0}},[t,n,i,c]);const j=(m==null?void 0:m.sections)&&m.sections.length>0,_=f.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const C=m.books.map(z=>z.volumes[0]).filter(z=>z!=null);return new Set(C).size<C.length},[m]),w=f.useMemo(()=>{if(!m)return[];let C=m.books;if(b&&(C=C.filter(k=>k.section===b)),h.trim()){const k=h.trim().toLowerCase();C=C.filter(z=>z.title.toLowerCase().includes(k)||z.sub_items&&z.sub_items.some(I=>I.toLowerCase().includes(k))||z.edition&&z.edition.toLowerCase().includes(k))}return C},[m,b,h]),T=f.useMemo(()=>{if(!_)return null;const C=[],k=new Map;for(const I of w){if(!I.volumes||I.volumes.length===0)continue;const v=I.volumes[0];k.has(v)||k.set(v,[]),k.get(v).push(I)}const z=[...k.keys()].sort((I,v)=>I-v);for(const I of z)C.push({volume:I,books:k.get(I)});return C},[w,_]);return p?e.jsx("div",{className:o,style:{...l,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.catalog.loading})}):g?e.jsx("div",{className:o,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g}):m?e.jsxs("div",{className:o,style:l,children:[e.jsx(Os,{data:m}),j&&e.jsx(Hs,{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:C=>S(C.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[w.length," ",c.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[T?T.map((C,k)=>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:Tt(c.catalog.volume,{n:C.volume})}),C.books.map((z,I)=>e.jsx(xi,{book:z,onNavigate:r,renderLink:s,showVolumes:z.volumes.length>1},`${C.volume}-${I}`))]},`${C.volume}-${k}`)):w.map((C,k)=>e.jsx(xi,{book:C,onNavigate:r,renderLink:s,showVolumes:!0},k)),w.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:c.catalog.noMatch})]})]}):null},et=()=>{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)})},he=6,Wt=7,Vs=({content:t,children:n,placement:i="top",delayMs:r=100,maxWidth:s=280,wrapperStyle:o})=>{const[l,c]=f.useState(!1),[a,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(),_=window.innerHeight,w=document.documentElement.clientWidth;let T=i;i==="top"&&m.top-j.height-Wt<8&&(T="bottom"),i==="bottom"&&m.bottom+j.height+Wt>_-8&&(T="top");const C=T==="top"?m.top-j.height-Wt:m.bottom+Wt;let k=m.left+m.width/2-j.width/2;k=Math.max(8,Math.min(k,w-j.width-8)),d({left:k,top:C,placement:T})},[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(!l)return;const h=requestAnimationFrame(u);return()=>cancelAnimationFrame(h)},[l,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}),l&&Mo.createPortal(e.jsxs("div",{ref:g,role:"tooltip",style:{position:"fixed",left:(a==null?void 0:a.left)??-9999,top:(a==null?void 0:a.top)??-9999,maxWidth:s,padding:"6px 10px",fontSize:"12px",lineHeight:1.5,color:"var(--bim-fg, #333)",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.08)",pointerEvents:"none",zIndex:9999,opacity:a?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,a&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-he,width:0,height:0,...a.placement==="top"?{bottom:-he,borderTop:`${he}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${he}px solid transparent`,borderRight:`${he}px solid transparent`}:{top:-he,borderBottom:`${he}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${he}px solid transparent`,borderRight:`${he}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...a.placement==="top"?{bottom:-5,borderTop:`${he-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${he-1}px solid transparent`,borderRight:`${he-1}px solid transparent`}:{top:-5,borderBottom:`${he-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${he-1}px solid transparent`,borderRight:`${he-1}px solid transparent`}}})]})]}),document.body)]})},hr=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Gs={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function ue(t){return Gs[t]??t}const it=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],rt={熹平: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},br={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function Ut(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 Us(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 Ys=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,gi={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function Ln(t){const n=t.trim().replace(/[代朝]$/,"");for(const s of Object.keys(gi))if(n.startsWith(s))return gi[s];const i=ue(n);if(Ke[i]!=null)return i;const r=Me(n);if(r&&n.length<=r.length+1)return ue(r)}function Ye(t,n){if(n){const i=br[`${n}|${t}`];if(i!=null)return i}return rt[t]}const Ks=1911;function Js(t){const n=rt[t];if(n==null)return;const i=Ae[t];let r;for(const[s,o]of Object.entries(rt))Ae[s]===i&&o>n&&(r==null||o<r)&&(r=o);return r!=null?r-1:void 0}const qs={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function Dt(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 l=qs[o];if(l===void 0)return;r=!0,o==="十"?i=(i||1)*10:o==="廿"||o==="卅"?(n+=l,i=0):i>=10?(n+=i+l,i=0):i=i*10+l}const s=n+i;return r&&s>0?s:void 0}function Me(t){for(const n of hr)if(t.startsWith(n))return n}const Ae={};{const t=(n,i)=>{for(const r of i)Ae[r]=n};t("東漢",["熹平","建安"]),t("三國",["黃初","正始"]),t("五代",["廣政"]),t("西晉",["太康"]),t("東晉",["永和"]),t("隋",["開皇"]),t("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),t("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),t("金",["大定","明昌"]),t("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),t("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),t("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),t("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function Je(t,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(rt))if(t.includes(r)&&!(i&&Ae[r]&&Ae[r]!==i&&br[`${i}|${r}`]==null))return r}function It(t){var l,c,a;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=(l=t.lineage)==null?void 0:l.year_text;if(r){const d=Me(r)??"";return{era:ue(d),reign:Je(r,d)??"",source:"lineage"}}const s=(c=t.publication_info)==null?void 0:c.year;if(s){const d=Ut(s);if(d)return{era:Us(d.from),reign:"",source:"publication"};const p=Me(s)??Ln(s)??((a=it.find(u=>u.pattern.test(s)))==null?void 0:a.era)??"",x=Je(s,p)??"",g=p||(x?Ae[x]??"":"");if(g||x)return{era:ue(g),reign:x,source:"publication"}}const o=t.edition||t.title||"";if(o){const d=Me(o);if(d)return{era:ue(d),reign:Je(o,d)??"",source:"edition"};const p=it.find(x=>x.pattern.test(o));if(p)return{era:ue(p.era),reign:Je(o,p.era)??p.reign??"",source:"edition"}}return n}function Yt(t){var r,s,o,l,c,a,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=Ut(n);if(g)return g.from}const i=[(l=t.lineage)==null?void 0:l.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=((a=t.publication_info)==null?void 0:a.year)||((d=t.lineage)==null?void 0:d.year_text);if(u&&g!==u&&(Me(u)||Ln(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=Me(g);if(!j||ue(j)==="民國"){const w=Dt(y[1]);if(w!=null&&w>=1&&w<=120)return Ks+w}}const h=Me(g)??((p=it.find(j=>j.pattern.test(g)))==null?void 0:p.era),S=h?ue(h):void 0,m=Je(g,S)??(Me(g)||(x=it.find(j=>j.pattern.test(g)))==null?void 0:x.reign);if(m){const j=Ye(m,S);if(j==null)continue;const _=g.indexOf(m),w=_>=0?g.slice(_+m.length):"",T=w.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??w.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),C=T?Dt(T[1]):void 0;return j+(C?C-1:0)}}}function Wn(t){var l,c,a,d,p,x;const n=(l=t.dating)==null?void 0:l.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=(a=t.lineage)==null?void 0:a.year_text;if(r){const g=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(g){const u=hn[ue(g[1])],b=Ke[ue(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=Ut(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=hn[ue(u[1])],y=Ke[ue(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=Me(g)??Ln(g)??((x=it.find(h=>h.pattern.test(g)))==null?void 0:x.era),b=u?ue(u):void 0,y=[];for(const h of Object.keys(rt))g.includes(h)&&(b&&Ae[h]&&Ae[h]!==b||Ye(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(rt))if(Ae[m]===b&&!(m[0]!==S&&m[m.length-1]!==S)&&Ye(m,b)!=null){y.push(m);break}}}if(y.length>0){const h=y.map(_=>Ye(_,b)).filter(_=>_!=null),S=Math.min(...h),m=y.reduce((_,w)=>Ye(_,b)>=Ye(w,b)?_:w),j=Js(m)??sn(b??"")??Math.max(...h);return{from:S,to:j>S?j:sn(b??Ae[m]??"")??S}}if(b&&Ke[b]!=null)return{from:Ke[b],to:sn(b)??Ke[b]}}}const Ke={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Xs=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Zs=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,mi=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function hi(t,n){for(const i of hr){const r=t.indexOf(i);if(r<0)continue;if(i.length===1){const a=t[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(a)&&!Je(t.slice(r),ue(i)))continue}const s=ue(i);if(s===n)continue;const o=t.slice(r),l=Je(o,s)??"";let c;if(l){const a=Ye(l,s);if(a!=null){const p=o.slice(o.indexOf(l)+l.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),x=p?Dt(p[1]):void 0;c=a+(x?x-1:0)}}return{era:s,reign:l,year:c}}for(const i of it)if(i.pattern.test(t))return{era:ue(i.era),reign:i.reign??""}}function Qs(t){var S,m,j,_,w;const n=It(t),i=((S=t.publication_info)==null?void 0:S.year)??"",r=i?Ut(i):void 0;if(!n.era&&!n.reign&&!r)return;const s=t.edition||t.title||"",o=/[間间]/.test(s),l=((m=t.lineage)==null?void 0:m.year_text)??"",c=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(l),a=n.source==="publication"&&Ys.test(i),d=n.source==="publication"&&/[間间]/.test(i),p=l.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let x;o||c||a||d?x=void 0:p?x=parseInt(p[2],10):x=Yt(t);const g=x==null?Wn(t):void 0;let u;n.source==="publication"&&(a||mi.test(i))?u="uncertain":n.source==="lineage"||n.source==="publication"?u="attested":mi.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)??((_=t.lineage)==null?void 0:_.year)??""}」`:`出版著錄「${((w=t.publication_info)==null?void 0:w.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 T=l.match(/[、,,]\s*([宋元明清])/);T&&T[1]!==y.era&&(y.laterRepair={era:T[1]})}if(!y.laterRepair&&Zs.test(s)){const T=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);T&&T[1]!==n.era&&(y.laterRepair={era:T[1]})}const h=Xs.find(T=>T.re.test(s));if(h){const T=s.search(h.re),C=s.slice(T),k=hi(C,n.era)??hi(s,n.era);k&&(y.basedOn={era:k.era,reign:k.reign,year:k.year,relation:h.relation})}return y}const hn={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function sn(t){return hn[t]}function yr(t){const n=Yt(t);if(n!=null)return n;const i=Wn(t);if(i)return i.from;const r=It(t).era;return r?Ke[r]:void 0}const bi=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function bn(t){const n=bi.indexOf(t);return n===-1?bi.length:n}function vr(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 Kt(t,n){const i=Cn(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=Xe(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]})),a=[...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:a,total:i.length}}function $n(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=Tn(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 el(t,n){if($n(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 jr(t,n){var o,l;const i=t.resources||[],r=[],s=[];for(const c of i){const a=Xe(c);a.includes("image")&&r.push(c),a.includes("physical")&&s.push(c)}return{id:t.id,name:t.edition||t.title||t.id,era:It(t),year:Yt(t),sortYear:yr(t),images:r,holders:s,locationName:(o=t.current_location)==null?void 0:o.name,important:tl(t.id,n),group:(l=n==null?void 0:n.node_groups)==null?void 0:l[t.id],hasImage:r.length>0}}function tl(t,n){var c,a;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)??[],l=(a=n.node_groups)==null?void 0:a[t];return!!l&&o.includes(l)}function Sr(t,n,i={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=t.filter(a=>!r.has(a.id)).map(a=>jr(a,n));let o=s;i.era&&(o=o.filter(a=>a.era.era===i.era)),i.scanOnly&&(o=o.filter(a=>a.hasImage)),i.sort==="year"?o=o.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const p=a.r.sortYear,x=d.r.sortYear;return p!=null&&x!=null?p-x||a.i-d.i:p!=null?-1:x!=null?1:a.i-d.i}).map(a=>a.r):o=o.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const p=x=>(x.important?0:1)*2+(x.hasImage?0:1);return p(a.r)-p(d.r)||a.i-d.i}).map(a=>a.r);const c=[...new Set(s.map(a=>a.era.era).filter(Boolean))].sort((a,d)=>bn(a)-bn(d));return{rows:o,allRows:s,eras:c,hasInferredEra:s.some(a=>a.era.source==="edition")}}function nl(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,l=!o&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!o&&l.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(r),a=new Set([...s,...l]),d=m=>{if(a.has(m))return!0;const 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 _=b.get(m);return{id:m,label:(_==null?void 0:_.label)??m,description:_==null?void 0:_.description,ids:j}});return g.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:p,groupedIds:y}}const kr=["撰","編","注","校","譯","繪","其他"],il=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function An(t){if(!t||!t.trim())return"撰";const n=t.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:r}of il)if(r.test(n))return i;return"其他"}function Fn(t){if(!t)return"";const n=t.trim();return!n||!/[一-鿿]/.test(n)?"":n}function wr(t){const n=new Map;for(const r of t){const s=An(r);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:t.length}];for(const r of kr){const s=n.get(r);s&&i.push({cls:r,label:r,count:s})}return i.length>2?i:[]}function _r(t,n,i){if(n&&n.books&&n.books.length>0){const s=n.books.map(l=>({id:l.work_id||l.book_id||void 0,title:l.title,section:l.section,volumes:l.volumes||[],subItems:l.sub_items,edition:l.edition,found:l.found_volumes,expected:l.expected_volumes})),o=[...new Set(s.map(l=>l.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:jt(o.volume_index)})),source:"works",sections:[]}:{rows:(t.books||[]).map(s=>{var o,l;return{id:s,title:((o=i==null?void 0:i.get(s))==null?void 0:o.title)||s,edition:(l=i==null?void 0:i.get(s))==null?void 0:l.edition,volumes:[]}}),source:"books",sections:[]}}function jt(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 Pn(t,n="冊"){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const i=[...t].sort((o,l)=>o-l),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 rl=["〇","一","二","三","四","五","六","七","八","九"],yi=["","十","百","千"];function Cr(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 l=parseInt(n[o]),c=i-1-o;l===0?s=!0:(s&&r&&(r+="〇"),s=!1,l===1&&c===1&&o===0?r+=yi[c]:r+=rl[l]+yi[c])}return r}function ol(t){return t==null?"":typeof t=="string"?t:t.title??""}function Ze(t,n="卷"){var r,s;const i=t;return i.measure_info?i.measure_info:(r=i.juan_count)!=null&&r.number?Cr(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function Tr(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 ht=1e3,ln=208,sl="(max-width: 719px)",Ir=`
|
|
1
|
+
"use strict";var Fo=Object.create;var ri=Object.defineProperty;var Mo=Object.getOwnPropertyDescriptor;var Po=Object.getOwnPropertyNames;var Oo=Object.getPrototypeOf,Ho=Object.prototype.hasOwnProperty;var Do=(e,n,i,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of Po(n))!Ho.call(e,o)&&o!==i&&ri(e,o,{get:()=>n[o],enumerable:!(r=Mo(n,o))||r.enumerable});return e};var pt=(e,n,i)=>(i=e!=null?Fo(Oo(e)):{},Do(n||!e||!e.__esModule?ri(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Z=require("./storage-entry-BLfpDWdl.cjs"),t=require("react/jsx-runtime"),f=require("react"),No=require("react-markdown"),Vo=require("remark-gfm"),Go=require("react-dom"),Uo=e=>`/book-index?id=${e}`,Qi=f.createContext(Uo);function Yo({buildUrl:e,children:n}){const i=f.useMemo(()=>e,[e]);return t.jsx(Qi.Provider,{value:i,children:n})}function je(){return f.useContext(Qi)}const er="",tr="";function nr(e){const n=[];let i=!1,r=e;for(;r.length;){const o=i?tr:er,s=r.indexOf(o);if(s===-1){n.push({text:r,marked:i});break}s>0&&n.push({text:r.slice(0,s),marked:i}),r=r.slice(s+1),i=!i}return n}function Xe(e){return e.types&&e.types.length>0?e.types:e.type?e.type==="text+image"?["text","image"]:[e.type]:[]}function Ko(e,n){return Xe(e).includes(n)}const ir={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},qo={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},Jo={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},Ct=f.createContext(null),rr={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入叢編",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:"圖片資源"}},Xo={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:"图片资源"}},Zo={"zh-Hant":rr,"zh-Hans":Xo},or="bim-locale";function Qo(){try{const e=localStorage.getItem(or);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function es(e){try{localStorage.setItem(or,e)}catch{}}const ts="zh-Hans",ns=({locale:e,onLocaleChange:n,children:i})=>{const[r,o]=f.useState(e??ts),s=e??r;f.useEffect(()=>{if(e)return;const p=Qo();p&&p!==r&&o(p)},[]);const[l,c]=f.useState(null);f.useEffect(()=>{s==="zh-Hans"?import("opencc-js/t2cn").then(p=>{const x=p.Converter({from:"tw",to:"cn"});c(()=>x)}).catch(()=>{c(()=>p=>p)}):c(null)},[s]);const a=f.useCallback(p=>{o(p),es(p),n==null||n(p)},[n]),d=f.useMemo(()=>({locale:s,setLocale:a,messages:Zo[s],converter:l}),[s,a,l]);return t.jsx(Ct.Provider,{value:d,children:i})};function N(){const e=f.useContext(Ct);return(e==null?void 0:e.messages)??rr}const is=2e3;function P(){const e=f.useContext(Ct),n=(e==null?void 0:e.locale)??"zh-Hant",i=(e==null?void 0:e.converter)??null,r=f.useRef(new Map),o=f.useRef(n);o.current!==n&&(r.current.clear(),o.current=n);const s=f.useCallback(l=>{if(!l)return"";if(!i)return l;const c=r.current.get(l);if(c!==void 0)return c;const a=i(l);if(r.current.size>=is){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(l,a),a},[i]);return f.useMemo(()=>({convert:s,locale:n,isSimplified:n==="zh-Hans"}),[s,n])}function Tt(e,n){return e.replace(/\{(\w+)\}/g,(i,r)=>String(n[r]??""))}function rs(e){if(!e)return"";try{const n=new URL(e).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 os(){return{id:"",name:"",url:"",type:"text",details:""}}const gn=({items:e,onChange:n,onDownload:i,downloadStatuses:r,filterType:o})=>{const s=N(),[l,c]=f.useState(null),a=[{value:"text",label:s.resourceTypeShort.text},{value:"image",label:s.resourceTypeShort.image},{value:"text+image",label:s.resourceTypeShort.textImage},{value:"physical",label:s.resourceTypeShort.physical}],d=[{value:"catalog",label:s.rootType.catalog},{value:"search",label:s.rootType.search}],p=m=>{if(!o)return!0;const j=Xe(m);return o==="text"?j.includes("text"):o==="image"?j.includes("image")||j.includes("physical"):o==="physical"?j.includes("physical"):j.includes(o)},x=e.map((m,j)=>({item:m,originalIndex:j})).filter(({item:m})=>p(m)),g=()=>{const m=os();o&&(m.type=o),n([...e,m]),c(e.length)},u=m=>{n(e.filter((j,_)=>_!==m)),c(null)},b=(m,j,_)=>{const w=[...e];if(w[m]={...w[m],[j]:_},j==="url"&&!w[m].id){const T=rs(_);T&&(w[m].id=T)}n(w)},y=(m,j,_)=>{const T={...e[m].metadata||{}};_?T[j]=_:delete T[j],b(m,"metadata",Object.keys(T).length>0?T:void 0)},h=(m,j)=>{const _=j.trim()?j.split(/[,,、]/).map(w=>w.trim()).filter(Boolean):void 0;b(m,"structure",_)},S=(m,j,_)=>{const T=e[m].coverage||{level:1,ranges:""};j==="level"?T.level=parseInt(_)||1:T.ranges=_,b(m,"coverage",T.ranges?T:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:m,originalIndex:j})=>{var _,w,T;return t.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>c(l===j?null:j),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:l===j?"▼":"▶"}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:ss(m.type??"text"),color:"#fff"},children:(()=>{var k,z;const C=Xe(m);return C.length===0?m.type??"text":C.length===1?((k=a.find(I=>I.value===C[0]))==null?void 0:k.label)??C[0]:C.includes("text")&&C.includes("image")?((z=a.find(I=>I.value==="text+image"))==null?void 0:z.label)??"text+image":C.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.name||`${s.editor.resourcePlaceholder} ${j+1}`}),m.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:m.id}),m.url&&t.jsx("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",onClick:C=>C.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&m.url&&ls(j,r==null?void 0:r[j],i,s),t.jsx("button",{onClick:C=>{C.stopPropagation(),u(j)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:s.editor.deleteThisResource,children:"✕"})]}),l===j&&t.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[Ko(m,"image")&&m.url&&as(m,s),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:ut,children:[t.jsx("span",{style:ft,children:s.label.type}),t.jsx("select",{value:m.type,onChange:C=>b(j,"type",C.target.value),style:{...We,flex:1},children:a.map(C=>t.jsx("option",{value:C.value,children:C.label},C.value))})]}),t.jsxs("label",{style:ut,children:[t.jsx("span",{style:ft,children:s.label.rootType}),t.jsx("select",{value:m.root_type||"catalog",onChange:C=>b(j,"root_type",C.target.value),style:{...We,flex:1},children:d.map(C=>t.jsx("option",{value:C.value,children:C.label},C.value))})]})]}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsx("input",{type:"text",value:m.id,onChange:C=>b(j,"id",C.target.value),placeholder:s.editor.idAutoExtract,style:{...We,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:m.name,onChange:C=>b(j,"name",C.target.value),placeholder:s.editor.resourceName,style:{...We,flex:1}})]}),t.jsx("input",{type:"text",value:m.url,onChange:C=>b(j,"url",C.target.value),placeholder:s.editor.resourceUrl,style:We}),t.jsx("input",{type:"text",value:((_=m.structure)==null?void 0:_.join("、"))||"",onChange:C=>h(j,C.target.value),placeholder:s.editor.structurePlaceholder,style:We}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:ut,children:[t.jsx("span",{style:ft,children:s.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((w=m.coverage)==null?void 0:w.level)??"",onChange:C=>S(j,"level",C.target.value),placeholder:"1",style:{...We,width:"60px"}})]}),t.jsxs("label",{style:{...ut,flex:1},children:[t.jsx("span",{style:ft,children:s.label.coverageRange}),t.jsx("input",{type:"text",value:((T=m.coverage)==null?void 0:T.ranges)||"",onChange:C=>S(j,"ranges",C.target.value),placeholder:s.editor.coverageRangePlaceholder,style:{...We,flex:1}})]})]}),t.jsx("textarea",{value:m.details||"",onChange:C=>b(j,"details",C.target.value),placeholder:s.editor.detailsPlaceholder,style:{...We,minHeight:"60px",resize:"vertical"}}),t.jsxs("div",{style:{borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",paddingTop:"8px",marginTop:"4px"},children:[t.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:s.label.metadata}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(s.metadata).map(([C,k])=>{var z;return t.jsxs("label",{style:{...ut,gap:"4px"},children:[t.jsx("span",{style:{...ft,minWidth:"56px"},children:k}),t.jsx("input",{type:"text",value:((z=m.metadata)==null?void 0:z[C])||"",onChange:I=>y(j,C,I.target.value),placeholder:k,style:{...We,flex:1}})]},C)})})]})]})]})]},j)}),t.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:[t.jsx("span",{children:"+"}),t.jsx("span",{children:s.action.addResource})]})]})};function ss(e){switch(e){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 ls(e,n,i,r){const o=(n==null?void 0:n.status)==="downloading",s=(n==null?void 0:n.status)==="completed";return t.jsx("button",{onClick:l=>{l.stopPropagation(),o||i(e,"")},disabled:o,style:{background:"transparent",border:"none",color:s?"var(--bim-success, #4caf50)":o?"var(--bim-desc-fg, #717171)":"var(--bim-link-fg, #0066cc)",cursor:o?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:o?.6:.9},title:s?r.download.completed:o?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:s?"✓":o?"⏳":"⬇"})}function as(e,n){const i=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(e.url)||e.url.includes("iiif")||e.url.includes("image");return t.jsx("div",{style:{marginBottom:"12px"},children:i?t.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"var(--bim-overlay-bg, #00000010)"},children:t.jsx("img",{src:e.url,alt:e.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):t.jsx("div",{style:{padding:"12px",background:"var(--bim-overlay-bg, #00000010)",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const We={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},ut={display:"flex",alignItems:"center",gap:"6px"},ft={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},cs={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive"};function kt(e){try{return cs[new URL(e).hostname]}catch{return}}const oi={text:0,image:1,physical:2};function Cn(e){return e.length===0?"physical":[...e].sort((n,i)=>(oi[n]??99)-(oi[i]??99)).join("+")}function Tn(e){var l;const n=c=>{const a=c.match(/^(.+?)·第(\d+)[冊册]$/);if(a)return[a[1],parseInt(a[2])];const d=c.match(/^(.+?)[·(](\d+)[)]?$/);return d?[d[1],parseInt(d[2])]:null},i=new Map;for(let c=0;c<e.length;c++){const a=e[c];if(a.volumes&&a.volumes.length>0)continue;const d=n(a.name);if(!d)continue;const[p,x]=d,g=`${p}|${Cn(Xe(a))}`;i.has(g)||i.set(g,{base:{...a,name:p,url:"",volumes:[]},volumes:[],indices:[]});const u=i.get(g);u.volumes.push({volume:x,url:a.url||void 0,status:"found"}),u.indices.push(c)}const r=[],o=new Set;for(const c of i.values())if(!(c.volumes.length<2)){c.volumes.sort((a,d)=>a.volume-d.volume),c.base.volumes=c.volumes,c.base.expected_volumes=c.volumes.length,c.base.url||(c.base.url=((l=c.volumes.find(a=>a.url))==null?void 0:l.url)??""),r.push(c.base);for(const a of c.indices)o.add(a)}const s=[...r];for(let c=0;c<e.length;c++)o.has(c)||s.push(e[c]);return s}function sr(e){if(e.url)return e.url;for(const[n,i]of Object.entries(e))if(n.endsWith("_url")&&typeof i=="string")return i}function lr(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||sr(n)}))}function In(e){const n=lr(e);if(!n)return null;const i=new Set(n.filter(o=>o.status!=="missing").map(o=>o.volume)).size,r=new Set(n.filter(o=>o.status==="missing").map(o=>o.volume)).size;return{found:i,missing:r,expected:e.expected_volumes??i+r}}function zn(e){if(!e)return;const n=e.file_page_range||e.page_range;if(!n||typeof n!="string")return;const i=n.match(/^(\d+)/);return i?parseInt(i[1],10):void 0}function Rn(e,n){try{if(new URL(e).hostname.includes("wikimedia.org")){const r=e.match(/\/wiki\/File:(.+?)(?:#|$)/);if(r)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(r[1]))}&page=${n}`;const o=new URL(e);return o.searchParams.set("page",String(n)),o.toString()}return e}catch{return e}}function Ht(e){if(!e.url)return;const n=zn(e.metadata);return n?Rn(e.url,n):e.url}const si={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 ds(e){return e.includes("text")&&e.includes("image")?si["text+image"]:si[e[0]||"physical"]}const En=({items:e,groupByType:n=!0,resourceGroups:i,onNavigate:r,renderLink:o})=>{const s=N(),{convert:l}=P(),c=f.useMemo(()=>Tn(e||[]),[e]),{mirrorGroups:a,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,_)=>{const w=T=>T.group_role==="origin"?0:T.group_role==="mirror"?1:2;return w(j)-w(_)});return{mirrorGroups:h,ungroupedItems:S}},[c]),p={text:s.resourceType.text,image:s.resourceType.image,"text+image":s.resourceType.textImage,physical:s.resourceType.physical},x=h=>p[h]?p[h]:h.split("+").map(S=>p[S]||S).join("+");if(!c||c.length===0)return t.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:s.misc.noResources});if(!n)return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:c.map((h,S)=>t.jsx(nn,{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,_=m==null?void 0:m.description;return t.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:[t.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(j)}),_&&t.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.5},children:l(_)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.map((w,T)=>t.jsx(nn,{item:w,onNavigate:r,renderLink:o},w.id||T))})]},`group-${h}`)},u=new Map;for(const h of d){const S=Cn(Xe(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 t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...a.entries()].map(([h,S])=>g(h,S)),y.map(h=>{const S=u.get(h),m=ds(h.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:m,whiteSpace:"nowrap",flexShrink:0},children:x(h)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.map((j,_)=>t.jsx(nn,{item:j,onNavigate:r,renderLink:o},j.id||_))})]},h)})]})},ps={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)"}},nn=({item:e})=>{const n=N(),{convert:i}=P(),[r,o]=f.useState(!1),s=f.useMemo(()=>(e.url?kt(e.url):void 0)||i(e.name),[e.url,e.name,i]),l=f.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(b=>({...b,url:b.url||sr(b)})),[e.volumes]),c=l&&l.length>0,a=c?new Set(l.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,d=c?new Set(l.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,p=e.expected_volumes??(c?a+d:0),x=e.color_mode?{...ps[e.color_mode],label:n.colorMode[e.color_mode]}:null,g=e.details&&!c?i(e.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 t.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[t.jsxs("div",{style:u,children:[t.jsx("span",{style:{fontWeight:500},children:s}),x&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:x.bg,color:x.fg},children:x.label}),g&&t.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:g}),c&&t.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[a,"/",p,n.unit.volume,d>0&&t.jsxs("span",{style:{color:"var(--bim-missing-fg, #e67e22)",marginLeft:"3px"},children:["缺",d]})]}),e.url&&t.jsx("a",{href:(()=>{const b=zn(e.metadata);return b?Rn(e.url,b):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),c&&t.jsx("button",{onClick:()=>o(!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&&t.jsx("div",{style:{padding:"6px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:l.map(b=>{const y=b.status==="missing";return b.url&&!y?t.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):t.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)})})]})},ar=({indexSource:e,syncConfig:n,variant:i="index-browser",onSwitchMode:r,onToggleDraft:o,onConfigurePath:s,onSelectFolder:l})=>{const c=N(),a=e==="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=t.jsxs("div",{onClick:o,title:d?c.mode.switchToOfficial:c.mode.switchToDraft,style:{...g,background:d?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...u,children:[t.jsx("span",{children:d?"📝":"📚"}),t.jsx("span",{children:d?"draft":"official"})]});return i==="index-browser"?a?t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,t.jsxs("div",{onClick:r,title:c.mode.switchToSync,style:g,...u,children:[t.jsx("span",{children:"📁"}),t.jsx("span",{children:c.mode.localMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsxs("div",{onClick:l,title:p||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px"},...u,children:[t.jsx("span",{children:"📂"}),x&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[t.jsxs("div",{onClick:r,title:c.mode.switchToLocal,style:g,...u,children:[t.jsx("span",{children:"🌐"}),t.jsx("span",{children:c.mode.syncMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsx("div",{onClick:s,title:x||c.mode.configurePath,style:{...g,background:"transparent",padding:"6px",fontSize:"12px"},...u,children:t.jsx("span",{children:"⚙️"})})]})]}):t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[t.jsxs("div",{onClick:r,title:a?c.mode.switchToGithub:c.mode.switchToLocal,style:g,...u,children:[t.jsx("span",{children:a?"📁":"🌐"}),t.jsx("span",{children:a?c.mode.localMode:c.mode.githubSync}),t.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&t.jsxs("div",{onClick:l,title:p||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:p?"100px":"auto",justifyContent:"space-between"},...u,children:[t.jsx("span",{children:"📂"}),x&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!a&&x&&t.jsxs("div",{style:{...g,background:"var(--bim-mode-active-bg, #2196f3)",color:"white",cursor:"default"},title:p,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:x})]})]})},Gt="bim-search-history",li=10,ai=8;function yt(){try{const e=localStorage.getItem(Gt);return e?JSON.parse(e):[]}catch{return[]}}function us(e){try{const n=yt().filter(i=>i!==e);n.unshift(e),n.length>li&&(n.length=li),localStorage.setItem(Gt,JSON.stringify(n))}catch{}}function fs(e){try{const n=yt().filter(i=>i!==e);localStorage.setItem(Gt,JSON.stringify(n))}catch{}}function xs(){try{localStorage.removeItem(Gt)}catch{}}const cr=({transport:e,value:n,onChange:i,onSearch:r,onEntrySelect:o,placeholder:s})=>{const l=N(),c=s??l.search.placeholder,a={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[d,p]=f.useState(!1),[x,g]=f.useState([]),[u,b]=f.useState(-1),[y,h]=f.useState(yt),S=f.useRef(null),m=f.useRef(null),j=f.useRef(null),_=f.useRef(!1);f.useEffect(()=>{b(-1);const v=n.trim();if(!v){g(y.map(M=>({type:"history",text:M})));return}if(!e.searchAll){g([]);return}let E=!1;const R=setTimeout(()=>{e.searchAll(v,ai).then(M=>{if(E)return;const $=[...M.works,...M.books,...M.collections,...M.entities??[]];g($.slice(0,ai).map(H=>({type:"entry",text:H.title||H.id,entry:H})))}).catch(()=>{E||g([])})},80);return()=>{E=!0,clearTimeout(R)}},[n,y,e]),f.useEffect(()=>{const v=E=>{j.current&&!j.current.contains(E.target)&&p(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]),f.useEffect(()=>{const v=E=>{var R,M;if(E.key==="/"&&document.activeElement!==S.current){const $=(R=document.activeElement)==null?void 0:R.tagName;if($==="INPUT"||$==="TEXTAREA"||$==="SELECT")return;E.preventDefault(),(M=S.current)==null||M.focus()}};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[]);const w=f.useCallback(v=>{v.trim()&&(us(v.trim()),h(yt())),r(v),p(!1)},[r]),T=f.useCallback(v=>{v.type==="history"?(i(v.text),w(v.text)):v.entry&&(o?(o(v.entry),p(!1)):(i(v.text),w(v.text)))},[i,w,o]),C=f.useCallback(v=>{if(!d||x.length===0){v.key==="Enter"&&w(n);return}switch(v.key){case"ArrowDown":v.preventDefault(),b(E=>(E+1)%x.length);break;case"ArrowUp":v.preventDefault(),b(E=>(E-1+x.length)%x.length);break;case"Enter":v.preventDefault(),u>=0&&u<x.length?T(x[u]):w(n);break;case"Escape":v.preventDefault(),p(!1);break}},[d,x,u,n,w,T]),k=f.useCallback((v,E)=>{E.stopPropagation(),fs(v),h(yt()),g(R=>R.filter(M=>!(M.type==="history"&&M.text===v)))},[]),z=f.useCallback(v=>{v.stopPropagation(),xs(),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 t.jsxs("div",{ref:j,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:S,type:"text",placeholder:c,value:n,onChange:v=>{i(v.target.value),p(!0)},onCompositionStart:()=>{_.current=!0},onCompositionEnd:()=>{_.current=!1},onFocus:()=>{p(!0)},onKeyDown:C,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&&t.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&&t.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:[t.jsx("span",{children:l.search.history}),t.jsx("button",{onClick:z,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),x.map((v,E)=>t.jsxs("div",{onClick:()=>T(v),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:E===u?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:v.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:v.text}),v.entry&&t.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[a[v.entry.type],v.entry.edition&&` · ${v.entry.edition}`,v.entry.author&&` · ${v.entry.author}`]}),v.type==="history"&&t.jsx("button",{onClick:R=>k(v.text,R),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:l.action.remove,children:"×"})]},`${v.type}-${v.text}-${E}`))]})]})},wt="bim-recent-ids",ci="bim-recent-entries",di=50,rn=5,gs=50,ms=200;function vt(){try{const e=localStorage.getItem(wt);if(e)return JSON.parse(e);const n=localStorage.getItem(ci);if(n){const i=JSON.parse(n).map(r=>r.id);return localStorage.setItem(wt,JSON.stringify(i)),localStorage.removeItem(ci),i}return[]}catch{return[]}}function hs(e){try{const n=vt().filter(i=>i!==e);n.unshift(e),n.length>di&&(n.length=di),localStorage.setItem(wt,JSON.stringify(n))}catch{}}function bs(e){try{const n=vt().filter(i=>i!==e);localStorage.setItem(wt,JSON.stringify(n))}catch{}}function ys(){try{localStorage.removeItem(wt)}catch{}}const vs={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},mn=({transport:e,indexSource:n="local",syncConfig:i,onEntryClick:r,onNewEntry:o,onSwitchMode:s,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a,hideModeIndicator:d,resultVariant:p="compact",renderEntry:x,initialQuery:g,onQueryChange:u,headerRight:b})=>{const y=N(),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,_]=f.useState(null),[w,T]=f.useState(null),[C,k]=f.useState(!1),[z,I]=f.useState(null),[v,E]=f.useState(""),[R,M]=f.useState(!g),[$,H]=f.useState(vt),[A,F]=f.useState([]),[J,W]=f.useState(!1),[K,ie]=f.useState(!1),[Y,L]=f.useState(null),[q,X]=f.useState(null),G=f.useRef(void 0),U=f.useRef(!1),ce=f.useCallback(async(D,se)=>{if(!D.trim()){M(!0),_(null),T(null);return}M(!1),k(!0),E("");try{if(e.searchAll){const ee=await e.searchAll(D,se??rn);_(ee)}else{const ee=["work","book","collection","entity"],B=await Promise.all(ee.map(Q=>e.search(D,Q,{page:1,pageSize:se??rn})));_({works:B[0].entries,books:B[1].entries,collections:B[2].entries,entities:B[3].entries,totalWorks:B[0].total,totalBooks:B[1].total,totalCollections:B[2].total,totalEntities:B[3].total})}}catch(ee){E(ee instanceof Error?ee.message:String(ee)),_(null)}finally{k(!1)}},[e]);f.useEffect(()=>{let D=!1;const se=()=>{var oe,_e;const ee=["work","book","collection","entity"],B=Promise.all(ee.map(Ce=>e.loadEntries(Ce,{page:1,pageSize:1}).catch(()=>({total:0})))),Q=((oe=e.getResourceCounts)==null?void 0:oe.call(e).catch(()=>null))??Promise.resolve(null),le=((_e=e.getSubtypeStats)==null?void 0:_e.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([B,Q,le]).then(([Ce,me,Ge])=>{D||(L({works:Ce[0].total,books:Ce[1].total,collections:Ce[2].total,entities:Ce[3].total,hasText:me==null?void 0:me.hasText,hasImage:me==null?void 0:me.hasImage}),Ge&&X(Ge))})};return e.getCounts?e.getCounts().then(ee=>{var B,Q;D||(L({works:ee.works,books:ee.books,collections:ee.collections,entities:ee.entities,hasText:(B=ee.resourceCounts)==null?void 0:B.hasText,hasImage:(Q=ee.resourceCounts)==null?void 0:Q.hasImage}),ee.subtypeStats&&X(ee.subtypeStats))}).catch(()=>{D||se()}):se(),()=>{D=!0}},[e]),f.useEffect(()=>{U.current||!(g!=null&&g.trim())||(U.current=!0,ce(g))},[g,ce]);const we=f.useCallback(D=>{if(m(D),!D.trim()){u==null||u(D),M(!0),_(null),T(null);return}G.current&&clearTimeout(G.current),G.current=setTimeout(()=>{T(null),u==null||u(D),ce(D)},ms)},[ce,u]),fe=f.useCallback(D=>{G.current&&clearTimeout(G.current),u==null||u(D),ce(D)},[ce,u]),ae=f.useCallback(D=>{T(D),ce(S,gs)},[S,ce]);f.useEffect(()=>{if(!$.length){F([]);return}let D=!1;return W(!0),Promise.all($.slice(0,10).map(async se=>{var ee,B,Q;try{if(e.getEntry){const oe=await e.getEntry(se);if(oe)return oe}const le=await e.getItem(se);if(le){const oe=le.authors;return{id:se,title:le.title||se,type:le.type||"work",author:(ee=oe==null?void 0:oe[0])==null?void 0:ee.name,dynasty:(B=oe==null?void 0:oe[0])==null?void 0:B.dynasty,role:(Q=oe==null?void 0:oe[0])==null?void 0:Q.role,edition:le.edition||void 0}}}catch{}return{id:se,title:se,type:"work",notFound:!0}})).then(se=>{D||(F(se),W(!1))}),()=>{D=!0}},[$,e]);const Se=D=>{I(D.id),hs(D.id),H(vt()),r==null||r(D)},Ee=D=>{bs(D),H(vt())},dt=()=>{ys(),H([])},Fe=D=>h.find(se=>se.type===D),Be=j&&(j.works.length>0||j.books.length>0||j.collections.length>0);return t.jsxs("div",{className:"bim-browser-container",children:[t.jsx("header",{style:{padding:"12px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("h1",{style:{margin:0,fontSize:"18px",color:"var(--bim-fg, #333)"},children:y.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,!d&&t.jsx(ar,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:s,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a})]})]})}),t.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[t.jsx(cr,{transport:e,value:S,onChange:we,onSearch:fe,onEntrySelect:Se}),o&&t.jsx("button",{onClick:()=>o("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})]}),Y&&R&&t.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:[t.jsx("span",{children:q?t.jsxs(t.Fragment,{children:[(q.book??0)>0&&t.jsxs(t.Fragment,{children:["書 ",t.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:q.book.toLocaleString()})," 部 ,",t.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Y.books.toLocaleString()})," 本"]}),q.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",t.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:q.article.toLocaleString()})," 篇"]}):null,q.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",t.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:q.poem.toLocaleString()})," 首"]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",t.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Y.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[y.indexType.work," ",t.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Y.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.book," ",t.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Y.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.collection," ",t.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Y.collections.toLocaleString()}),Y.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.entity," ",t.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Y.entities.toLocaleString()})]})]})}),Y.hasImage!=null&&Y.hasText!=null&&t.jsxs("span",{children:[y.resourceType.image," ",t.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Y.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.resourceType.text," ",t.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Y.hasText.toLocaleString()})]})]}),t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:C?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:y.search.searching}):v?t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("div",{style:{fontSize:"24px",marginBottom:"8px"},children:"⚠️"}),t.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)"},children:v})]}):R?t.jsx("div",{style:{flex:1},children:J?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:y.search.loading}):A.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{children:y.search.recentBrowse}),t.jsx("button",{onClick:dt,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:y.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:A.slice(0,K?10:3).map(D=>D.notFound?t.jsx(ks,{id:D.id,onRemove:Ee,t:y},D.id):t.jsx(pi,{entry:D,selected:z===D.id,onClick:Se,getConfig:Fe,onRemove:Ee},D.id))}),!K&&A.length>3&&t.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})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),t.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:y.search.searchTitle}),t.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y.search.searchSubtitle})]})}):Be?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:h.map(({type:D,icon:se,name:ee,key:B})=>{const Q=j[B]??[],le=vs[B],oe=j[le]??0;if(Q.length===0)return null;const Ce=!(w===D)&&oe>rn;return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"6px"},children:[t.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:[se," ",ee,t.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[oe," ",y.unit.items]})]}),Ce&&t.jsx("button",{onClick:()=>ae(D),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:y.action.viewAll})]}),t.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:Q.map(me=>{if(x)return t.jsx(f.Fragment,{children:x(me)},me.id);const Ge=p==="card"?Ss:pi;return t.jsx(Ge,{entry:me,selected:z===me.id,onClick:Se,getConfig:Fe,query:S},me.id)})})]},D)})}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),t.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:Tt(y.search.noResultsFor,{query:S})}),t.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y.search.tryOther})]})})]})},js=({snippet:e})=>{const{convert:n}=P();return t.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.6},children:nr(e).map((i,r)=>i.marked?t.jsx("mark",{style:{background:"var(--bim-highlight-bg, #fff3a3)",color:"var(--bim-highlight-fg, inherit)",padding:"0 1px",borderRadius:"2px"},children:n(i.text)},r):t.jsx(f.Fragment,{children:n(i.text)},r))})},Ss=({entry:e,selected:n,onClick:i,getConfig:r,query:o})=>{const s=N(),{convert:l}=P(),c=l(e.title||e.primary_name||e.id),a=e.measure_info?l(e.measure_info):e.juan_count!=null&&e.juan_count>0?`${e.juan_count}${s.unit.juan}`:"",d=[...e.additional_titles||[],...e.attached_texts||[]],p=o&&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(o.toLowerCase())}):void 0,x="var(--bim-cover-accent, #8e6f3e)";return t.jsxs("div",{onClick:()=>i(e),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:[t.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:[t.jsx("span",{style:{position:"absolute",left:"6px",top:0,bottom:0,borderLeft:`1px dashed color-mix(in srgb, ${x} 45%, transparent)`}}),t.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)=>t.jsx("span",{children:g},u))})]}),t.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:"var(--bim-fg, #333)"},children:c}),a&&t.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:a})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.dynasty&&t.jsxs("span",{children:["〔",l(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:l(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",l(e.role)]})]}),(e.era||e.edition)&&t.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[e.era&&t.jsxs("span",{children:["〔",l(e.era),"〕"]}),e.edition&&t.jsx("span",{children:l(e.edition)})]}),p&&t.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[s.search.alias,":",l(typeof p=="string"?p:p.book_title||"")]}),e.descriptionSnippet&&t.jsx(js,{snippet:e.descriptionSnippet}),t.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"auto",paddingTop:"4px"},children:[t.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(e.type).icon," ",r(e.type).name]}),e.has_text&&t.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:["📝 ",s.misc.textResource]}),e.has_image&&t.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:["🖼️ ",s.misc.imageResource]})]})]})]})},pi=({entry:e,selected:n,onClick:i,getConfig:r,query:o,onRemove:s})=>{const l=N(),{convert:c}=P(),a=[...e.additional_titles||[],...e.attached_texts||[]],d=o&&a.length?a.find(p=>{const x=typeof p=="string"?p:p==null?void 0:p.book_title;return x==null?void 0:x.toLowerCase().includes(o.toLowerCase())}):void 0;return t.jsxs("div",{onClick:()=>i(e),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:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[t.jsx("span",{style:{fontSize:"16px"},children:r(e.type).icon}),t.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:r(e.type).name})]}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:c(e.title||e.primary_name||e.id)}),t.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[e.has_text&&t.jsx("span",{title:l.misc.textResource,children:"📝"}),e.has_image&&t.jsx("span",{title:l.misc.imageResource,children:"🖼️"})]}),(e.era||e.edition)&&t.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[e.era&&t.jsxs(t.Fragment,{children:["〔",c(e.era),"〕"]}),e.edition&&c(e.edition)]}),e.measure_info?t.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[e.juan_count,l.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[e.dynasty&&t.jsxs("span",{children:["〔",c(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:c(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",c(e.role)]}),e.type==="entity"&&(e.birth_year!=null||e.death_year!=null)&&t.jsxs("span",{style:{marginLeft:e.dynasty?"4px":0},children:[e.birth_year??"?","—",e.death_year??"?"]})]}),d&&t.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[l.search.alias,":",c(d)]})]}),s?t.jsx("button",{onClick:p=>{p.stopPropagation(),s(e.id)},title:l.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1,opacity:.5,marginTop:"2px"},children:"×"}):t.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},ks=({id:e,onRemove:n,t:i})=>t.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:[t.jsx("span",{style:{fontSize:"16px"},children:"❓"}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",fontFamily:"monospace"},children:e}),t.jsx("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginTop:"2px"},children:i.search.itemNotFound})]}),t.jsx("button",{onClick:()=>n(e),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 ws(e){var n;return!e.dynasty&&!e.birth_year&&!e.death_year&&(!e.alt_names||e.alt_names.length===0)&&!((n=e.description)!=null&&n.text)}function _s({data:e}){const{convert:n}=P(),{dynasty:i,birth_year:r,death_year:o}=e,s=[];return i&&s.push(`〔${n(i)}〕`),r!==void 0&&o!==void 0?s.push(`${r}—${o}`):r!==void 0?s.push(`${r}—?`):o!==void 0&&s.push(`?—${o}`),s.length===0?null:t.jsx("span",{style:{fontSize:"14px",color:"var(--bim-desc-fg, #717171)",marginLeft:"8px",fontWeight:"normal"},children:s.join(" ")})}function Cs({alt_names:e}){const{convert:n}=P(),i=new Map;for(const s of e){const l=s.type||"別名";i.has(l)||i.set(l,[]),i.get(l).push(s.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],o=[...i.keys()].sort((s,l)=>{const c=r.indexOf(s),a=r.indexOf(l);return c===-1&&a===-1?0:c===-1?1:a===-1?-1:c-a});return t.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:o.map(s=>{const l=i.get(s);return t.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[t.jsx("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:s}),t.jsx("span",{children:l.map((c,a)=>t.jsxs("span",{children:[a>0&&t.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(c)]},a))})]},s)})})}function Ts({data:e}){const n=e.external_ids;if(!n)return null;const i=[];return n.cbdb_id&&i.push(t.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:t.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:i})}function Is({works:e,transport:n,onNavigate:i,renderLink:r}){const o=N(),{convert:s}=P(),l=je(),[c,a]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let g=!1;const u=e.map(y=>y.work_id);return(async()=>{const y=new Map;if(n.getEntriesByIds)try{const j=await n.getEntriesByIds(u);let _=!0;for(let w=0;w<u.length;w++){const T=j[w];T!=null&&T.title?y.set(u[w],T.title):T!=null&&T.primary_name?y.set(u[w],T.primary_name):_=!1}if(_)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 T=await n.getEntry(j);if(T!=null&&T.title){y.set(j,T.title);continue}}const _=await n.getItem(j),w=_&&(_.title||_.primary_name)||j;y.set(j,w)}catch{y.set(j,j)}}});return await Promise.all(m),y})().then(y=>{g||a(y)}),()=>{g=!0}},[e,n]);const d=new Map;for(const g of e){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 t.jsxs("div",{style:{marginTop:"12px"},children:[t.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:[o.label.relatedWorks," ",t.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",e.length,")"]})]}),x.map(g=>{const u=d.get(g);return t.jsxs("div",{style:{marginBottom:"8px"},children:[g&&t.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginBottom:"2px"},children:[s(g)," ",t.jsxs("span",{style:{color:"var(--bim-desc-fg, #bbb)"},children:["(",u.length,")"]})]}),t.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=s(c.get(b.work_id)||b.work_id);return r?t.jsx("li",{children:r(b.work_id,h)},y):i?t.jsx("li",{children:t.jsx("a",{href:l(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):t.jsx("li",{children:h},y)})})]},g)})]})}const dr=({data:e,transport:n,onNavigate:i,renderLink:r,headerExtra:o,hideHeader:s})=>{var x;const l=N(),{convert:c}=P();let a=!1;try{a=Z.extractStatus(e.id)==="draft"}catch{}const d=ws(e),p=e.subtype==="people"?"人物":e.subtype==="place"?"地名":e.subtype==="dynasty"?"朝代":e.subtype==="anonymous"?"佚名":e.subtype==="collective"?"集体":e.subtype;return t.jsxs("div",{children:[!s&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:"var(--bim-fg, #222)"},children:[c(e.primary_name),t.jsx(_s,{data:e})]}),o]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:"var(--bim-type-entity, #5b3e8e)",border:"1px solid color-mix(in srgb, var(--bim-type-entity, #5b3e8e) 25%, transparent)",borderRadius:"2px",background:"color-mix(in srgb, var(--bim-type-entity, #5b3e8e) 3%, transparent)"},children:l.indexType.entity}),p&&e.subtype!=="people"&&t.jsx("span",{children:p}),a&&t.jsx("span",{style:{padding:"1px 6px",background:"var(--bim-warn-bg, #fff3cd)",border:"1px solid var(--bim-warn-border, #ffc107)",borderRadius:"2px",color:"var(--bim-warn-fg, #856404)"},children:l.status.draft}),t.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:e.id})]})]}),d&&t.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 仅作为作者占位,详细生平资料尚待补充。"}),e.alt_names&&e.alt_names.length>0&&t.jsx(Cs,{alt_names:e.alt_names}),t.jsx(Ts,{data:e}),((x=e.description)==null?void 0:x.text)&&t.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:c(e.description.text)}),e.works&&e.works.length>0&&t.jsx(Is,{works:e.works,transport:n,onNavigate:i,renderLink:r})]})},pr={p:({children:e})=>t.jsx("p",{style:{margin:"0 0 0.5em"},children:e}),ul:({children:e})=>t.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:e}),ol:({children:e})=>t.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:e}),li:({children:e})=>t.jsx("li",{style:{marginBottom:"2px"},children:e}),a:({href:e,children:n})=>t.jsx("a",{href:e,target:e!=null&&e.startsWith("http")?"_blank":void 0,rel:e!=null&&e.startsWith("http")?"noopener noreferrer":void 0,style:{color:"var(--bim-link, #1976d2)"},children:n}),code:({children:e})=>t.jsx("code",{style:{background:"var(--bim-bg-subtle, #f4f4f4)",padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})},zs={...pr,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},Oe=({text:e,plainStrong:n,style:i,className:r})=>{const{convert:o}=P(),s=n?zs:pr;return t.jsx("div",{className:r,style:i,children:t.jsx(No,{remarkPlugins:[Vo],components:s,children:o(e)})})},Rs=["〇","一","二","三","四","五","六","七","八","九"],ui=["","十","百","千"];function ur(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),i=n.length;let r="",o=!1;for(let s=0;s<i;s++){const l=parseInt(n[s]),c=i-1-s;l===0?o=!0:(o&&r&&(r+="〇"),o=!1,l===1&&c===1&&s===0?r+=ui[c]:r+=Rs[l]+ui[c])}return r}function fr(e){return{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:e,border:`1px solid color-mix(in srgb, ${e} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${e} 3%, transparent)`}}const Es={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 Bs({type:e}){const n=N();return t.jsx("span",{style:fr(Es[e]),children:n.indexType[e]})}function Ls({isDraft:e}){const n=N(),i=e?"var(--bim-status-draft, #e67e22)":"var(--bim-status-official, #27ae60)";return t.jsx("span",{style:fr(i),children:e?n.status.draft:n.status.official})}function Ws({id:e}){const n=N(),[i,r]=f.useState(!1),o=()=>{navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return t.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:[t.jsx("span",{children:n.label.id}),t.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:"var(--bim-fg, #333)"},children:e}),t.jsx("span",{onClick:o,title:i?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:i?1:.5,transition:"opacity 0.15s"},onMouseEnter:s=>s.currentTarget.style.opacity="1",onMouseLeave:s=>s.currentTarget.style.opacity=i?"1":"0.5",children:i?"✓":"⧉"})]})}function ke({children:e,extra:n}){return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",letterSpacing:"1px"},children:e}),t.jsx("span",{style:{flex:1}}),n]})}function $e({label:e,children:n}){return t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[t.jsx("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:e}),t.jsx("span",{style:{color:"var(--bim-fg, #333)"},children:n})]})}function xr({authors:e,type:n,onNavigate:i,renderLink:r}){const{convert:o}=P();return t.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:e.map((s,l)=>{const c=o(s.name),a=s.entity_id?t.jsx(Ie,{id:s.entity_id,label:c,onNavigate:i,renderLink:r}):t.jsx("span",{style:{fontWeight:500},children:c});return t.jsxs("span",{children:[l>0&&t.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),s.dynasty&&t.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",o(s.dynasty),"〕"]}),a,s.role&&t.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",o(s.role)]})]},l)})})}function Ie({id:e,label:n,onNavigate:i,renderLink:r}){const o=je();return r?t.jsx(t.Fragment,{children:r(e,n)}):i?t.jsx("a",{href:o(e),onClick:s=>{s.metaKey||s.ctrlKey||(s.preventDefault(),i(e))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:s=>s.currentTarget.style.borderBottomStyle="solid",onMouseLeave:s=>s.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{children:n||e})}function $s({id:e,title:n,edition:i,type:r,isDraft:o,authors:s,volumeText:l,meta:c,headerExtra:a,onNavigate:d,renderLink:p}){return t.jsxs("div",{style:{marginBottom:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[t.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&&t.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:i}),l&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:l})]}),a&&t.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:a})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[t.jsx(Bs,{type:r}),t.jsx(Ls,{isDraft:o}),t.jsx(Ws,{id:e})]}),((s==null?void 0:s.length)||c.length>0)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[s&&s.length>0&&t.jsx(xr,{authors:s,type:r,onNavigate:d,renderLink:p}),c]})]})}function gr({items:e,label:n,showMeta:i,onNavigate:r,renderLink:o}){const s=N(),{convert:l}=P();if(!e.length)return null;const[c,a]=f.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(ke,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((d,p)=>{const x=c===p;return t.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:[t.jsxs("div",{onClick:()=>a(x?null:p),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[t.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:"▶"}),t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(d.source)}),!x&&i&&d.title_info&&t.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(d.title_info)}),d.source_bid&&t.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(Ie,{id:d.source_bid,label:s.action.view,onNavigate:r,renderLink:o})})]}),x&&t.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)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&t.jsx($e,{label:s.label.titleInfo,children:l(d.title_info)}),d.author_info&&t.jsx($e,{label:s.label.authorInfo,children:l(d.author_info)}),d.edition&&t.jsx($e,{label:s.label.edition,children:l(d.edition)})]}),d.summary&&t.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:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:s.section.summary}),t.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(d.summary)})]}),d.comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:s.section.comment}),t.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(d.comment)})]}),d.additional_comment&&t.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:s.section.additionalComment}),t.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(d.additional_comment)})]})]})]},p)})})]})}function As({items:e,onNavigate:n,renderLink:i}){const r=N();return t.jsx(gr,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function mr({items:e,onNavigate:n,renderLink:i}){const r=N();return t.jsx(gr,{items:e,label:r.section.emendated,onNavigate:n,renderLink:i})}function hr({label:e,items:n}){const{convert:i}=P();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(ke,{children:e}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,o)=>{const s=typeof r=="string"?r:r.book_title;return t.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(s)},o)})})]}):null}function Fs({items:e}){const n=N();return t.jsx(hr,{label:n.section.aliases,items:e})}function Ms({items:e}){const n=N();return t.jsx(hr,{label:n.section.attachedTexts,items:e})}function Ps({items:e}){const n=N(),{convert:i}=P();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(ke,{children:n.section.appendix}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:e.map((r,o)=>t.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&&t.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},o))})]}):null}function Os({items:e}){const n=N(),{convert:i}=P();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(ke,{children:n.section.locationHistory}),t.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[t.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),e.map((r,o)=>t.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[t.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)"}}),t.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:i(r.name)}),r.description&&t.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:i(r.description)})]},o))]})]}):null}function Hs({items:e}){const n=N(),{convert:i}=P();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(ke,{children:n.section.historyOverview}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map((r,o)=>t.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[t.jsx("span",{style:{position:"absolute",left:0,top:0,color:"var(--bim-desc-fg, #ccc)"},children:"·"}),i(r)]},o))})]}):null}function fi({title:e,ids:n,transport:i,onNavigate:r,renderLink:o}){const{convert:s}=P(),[l,c]=f.useState([]);return f.useEffect(()=>{if(!n.length){c([]);return}if(!i){c(n.map(d=>({id:d})));return}let a=!1;return Promise.all(n.map(d=>i.getItem(d).then(p=>({id:d,title:p?p.title:void 0,edition:p?p.edition:void 0,type:p?p.type:void 0})).catch(()=>({id:d})))).then(d=>{a||c(d)}),()=>{a=!0}},[n,i]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(ke,{children:[e,t.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(l.length?l:n.map(a=>({id:a}))).map(a=>{const d=a.edition?`${s(a.title)||a.id}(${s(a.edition)})`:s(a.title)||void 0;return t.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:t.jsx(Ie,{id:a.id,label:d,onNavigate:r,renderLink:o})},a.id)})})]}):null}function on({book:e,onNavigate:n,renderLink:i}){const r=N(),{convert:o}=P(),[s,l]=f.useState(!1),c=e.resources&&e.resources.length>0,a=e.edition?o(e.edition):o(e.title)||void 0;return t.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[t.jsxs("div",{style:{padding:"6px 12px",borderBottom:c&&!s?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:t.jsx(Ie,{id:e.id,label:a,onNavigate:n,renderLink:i})}),c&&t.jsx("span",{onClick:()=>l(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:s?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:s?r.action.expand:r.action.collapse,children:"▼"})]}),c&&!s&&t.jsx("div",{style:{padding:"10px 14px"},children:t.jsx(En,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function Ds({ids:e,workData:n,transport:i,onNavigate:r,renderLink:o,footer:s}){const l=N(),{convert:c}=P(),[a,d]=f.useState([]);if(f.useEffect(()=>{if(!e.length){d([]);return}if(!i){d(e.map(y=>({id:y})));return}let b=!1;return Promise.all(e.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}},[e,i]),!e.length)return null;const p=a.length?a:e.map(b=>({id:b})),x=new Map(p.map(b=>[b.id,b])),g=n==null?void 0:n.version_graph,u=Ns(e,g);return t.jsxs(t.Fragment,{children:[t.jsxs(ke,{children:[l.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",e.length,")"]})]}),s,u.useGrouping?t.jsxs(t.Fragment,{children:[u.coreIds.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.coreIds.map(b=>{const y=x.get(b);return y?t.jsx(on,{book:y,onNavigate:r,renderLink:o},b):null})}),u.groupedIds.map(b=>t.jsxs("details",{style:{marginTop:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:6,background:"var(--bim-bg-subtle, #fafafa)"},children:[t.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:"var(--bim-fg, #333)",userSelect:"none"},children:[c(b.label),t.jsxs("span",{style:{marginLeft:6,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:["(",b.ids.length,")"]}),b.description&&t.jsx("span",{style:{marginLeft:8,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:c(b.description)})]}),t.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?t.jsx(on,{book:h,onNavigate:r,renderLink:o},y):null})})]},b.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:p.map(b=>t.jsx(on,{book:b,onNavigate:r,renderLink:o},b.id))})]})}function Ns(e,n){var h,S;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(h=n.collections)==null?void 0:h[n.default_collection],r=(i==null?void 0:i.groups)??[],o=(i==null?void 0:i.book_ids)??[],s=r.length>0||o.length>0,l=!s&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!s&&l.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const c=new Set(r),a=new Set([...o,...l]),d=m=>{if(a.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 e)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:e,groupedIds:[]};const b=new Map((n.groups??[]).map(m=>[m.id,m])),y=[...x.entries()].map(([m,j])=>{const _=b.get(m);return{id:m,label:(_==null?void 0:_.label)??m,description:_==null?void 0:_.description,ids:j}});return g.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:p,groupedIds:y}}function Vs({workData:e,onNavigate:n,renderLink:i}){var l,c,a,d;const r=N(),{convert:o}=P(),s=!!((l=e.description)!=null&&l.text)||!!e.parent_work;return t.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[t.jsxs("div",{style:{padding:"6px 14px",borderBottom:s?"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:[t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t.jsx(Ie,{id:e.id,label:o(e.title),onNavigate:n,renderLink:i})}),e.measure_info?t.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:o(e.measure_info)}):((c=e.juan_count)==null?void 0:c.number)!=null&&e.juan_count.number>0?t.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[ur(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(xr,{authors:e.authors,type:"work",onNavigate:n,renderLink:i})})]}),s&&t.jsxs("div",{style:{padding:"8px 14px"},children:[((a=e.description)==null?void 0:a.text)&&t.jsx(Oe,{text:e.description.text,style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,textAlign:"justify"}}),e.parent_work&&t.jsx("div",{style:{marginTop:(d=e.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:t.jsx($e,{label:r.label.parentWork,children:t.jsx(Ie,{id:e.parent_work.id,label:o(e.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function Gs({items:e,onNavigate:n,renderLink:i}){const r=N(),{convert:o}=P();return e.length?t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:e.map(s=>t.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:[t.jsx("span",{style:{fontSize:"11px",color:"var(--bim-type-collection, #2471a3)"},children:r.indexType.collection}),t.jsx(Ie,{id:s.id,label:o(s.title)||s.id,onNavigate:n,renderLink:i}),s.volume_index!=null&&t.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:Tt(r.catalog.volume,{n:s.volume_index})})]},s.id))}):null}const Bn=({data:e,id:n,transport:i,onNavigate:r,renderLink:o,headerExtra:s,relatedBooksFooter:l,className:c,style:a})=>{var E,R,M,$,H,A,F,J;const d=N(),{convert:p}=P(),[x,g]=f.useState(null),[u,b]=f.useState(!1),[y,h]=f.useState(null),[S,m]=f.useState(null),[j,_]=f.useState([]),w=e||x;if(f.useEffect(()=>{if(e||!n||!i)return;let W=!1;return b(!0),h(null),i.getItem(n).then(K=>{W||(K?g(K):h(d.misc.notFoundEntry))}).catch(K=>{W||h(K instanceof Error?K.message:d.misc.loadFailed)}).finally(()=>{W||b(!1)}),()=>{W=!0}},[e,n,i]),f.useEffect(()=>{if(!w||!i){m(null),_([]);return}let W=!1;const K=w.type==="book"||w.type==="collection"?w.work_id:void 0;if(K?i.getItem(K).then(ie=>{!W&&ie&&ie.type==="work"&&m(ie)}).catch(()=>{}):m(null),w.type==="book"){const ie=w;ie.contained_in&&ie.contained_in.length>0?Promise.all(ie.contained_in.map(Y=>{const L=typeof Y=="string"?Y:Y.id,q=typeof Y=="string"?void 0:Y.volume_index;return i.getItem(L).then(X=>({id:L,title:X&&X.title||L,volume_index:q})).catch(()=>({id:L,title:L,volume_index:q}))})).then(Y=>{W||_(Y)}):_([])}else _([]);return()=>{W=!0}},[w,i]),u)return t.jsx("div",{className:c,style:{...a,padding:"24px"},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((W,K)=>t.jsx("div",{style:{height:K===1?"32px":"16px",width:`${W}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},K))})});if(y)return t.jsx("div",{className:c,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y});if(!w)return null;if(w.type==="entity")return t.jsx("div",{className:c,style:a,children:t.jsx(dr,{data:w,transport:i,onNavigate:r,renderLink:o,headerExtra:s})});const T=w.type==="book"?w:null,C=w.type==="collection"?w:null,k=w.type==="work"?w:null;let z=!1;try{z=Z.extractStatus(w.id)==="draft"}catch{}let I="";w.measure_info?I=p(w.measure_info):(E=w.juan_count)!=null&&E.number?I=ur(w.juan_count.number)+d.unit.juan:(R=w.juan_count)!=null&&R.description&&(I=p(w.juan_count.description));const v=[];return(M=w.publication_info)!=null&&M.year&&v.push(t.jsx($e,{label:d.label.year,children:w.publication_info.year},"year")),($=w.current_location)!=null&&$.name&&v.push(t.jsx($e,{label:d.label.currentLocation,children:p(w.current_location.name)},"loc")),(H=w.page_count)!=null&&H.description&&v.push(t.jsx($e,{label:d.label.pageCount,children:w.page_count.description},"page")),T!=null&&T.edition&&v.push(t.jsx($e,{label:d.label.edition,children:p(T.edition)},"ver")),k!=null&&k.parent_work&&v.push(t.jsx($e,{label:d.label.parentWork,children:t.jsx(Ie,{id:k.parent_work.id,label:p(k.parent_work.title),onNavigate:r,renderLink:o})},"pw")),k!=null&&k.parent_works&&k.parent_works.length>0&&!k.parent_work&&v.push(t.jsx($e,{label:d.label.parentWork,children:k.parent_works.map((W,K)=>t.jsxs("span",{children:[K>0&&"、",t.jsx(Ie,{id:W,onNavigate:r,renderLink:o})]},W))},"pws")),t.jsxs("div",{className:c,style:a,children:[t.jsx($s,{id:w.id,title:p(w.title),edition:w.edition?p(w.edition):void 0,type:w.type,isDraft:z,authors:w.authors,volumeText:I,meta:v,headerExtra:s,onNavigate:r,renderLink:o}),((A=w.description)==null?void 0:A.text)&&t.jsx(Oe,{text:w.description.text,style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),w.appendix&&w.appendix.length>0&&t.jsx("div",{style:{marginTop:8,marginBottom:4},children:w.appendix.map((W,K)=>t.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:[t.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:"var(--bim-muted, #666)"},children:p(W.title)}),t.jsx(Oe,{text:W.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:"var(--bim-fg, #444)"}})]},K))}),j.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(ke,{children:d.section.containedIn}),t.jsx(Gs,{items:j,onNavigate:r,renderLink:o})]}),S&&t.jsxs(t.Fragment,{children:[t.jsx(ke,{children:d.section.belongsToWork}),t.jsx(Vs,{workData:S,onNavigate:r,renderLink:o})]}),w.additional_works&&w.additional_works.length>0&&t.jsx(Ps,{items:w.additional_works}),w.additional_titles&&w.additional_titles.length>0&&t.jsx(Fs,{items:w.additional_titles}),w.attached_texts&&w.attached_texts.length>0&&t.jsx(Ms,{items:w.attached_texts}),w.indexed_by&&w.indexed_by.length>0&&t.jsx(As,{items:w.indexed_by,onNavigate:r,renderLink:o}),w.emendated_by&&w.emendated_by.length>0&&t.jsx(mr,{items:w.emendated_by,onNavigate:r,renderLink:o}),w.resources&&w.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(ke,{children:d.section.resources}),t.jsx(En,{items:w.resources,resourceGroups:w.resource_groups,groupByType:!0,onNavigate:r,renderLink:o})]}),(T==null?void 0:T.location_history)&&T.location_history.length>0&&t.jsx(Os,{items:T.location_history}),(C==null?void 0:C.history)&&C.history.length>0&&t.jsx(Hs,{items:C.history}),(T==null?void 0:T.related_books)&&T.related_books.length>0&&t.jsx(fi,{title:d.section.relatedVersions,ids:T.related_books,transport:i,onNavigate:r,renderLink:o}),(C==null?void 0:C.books)&&C.books.length>0&&t.jsx(fi,{title:d.section.containedBooks,ids:C.books,transport:i,onNavigate:r,renderLink:o}),(C==null?void 0:C.contained_works)&&C.contained_works.length>0&&t.jsxs("div",{children:[t.jsxs(ke,{children:[d.section.containedWorks,t.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",C.contained_works.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:C.contained_works.map(W=>t.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:t.jsx(Ie,{id:W.id,label:p(W.title),onNavigate:r,renderLink:o})},W.id))})]}),(((F=k==null?void 0:k.books)==null?void 0:F.length)||0)+(((J=k==null?void 0:k.collections)==null?void 0:J.length)||0)>0&&t.jsx(Ds,{ids:[...(k==null?void 0:k.books)||[],...(k==null?void 0:k.collections)||[]],workData:k,transport:i,onNavigate:r,renderLink:o,footer:l}),(k==null?void 0:k.related_works)&&k.related_works.length>0&&(()=>{const W=[],K=k.related_works.filter(G=>G.relation==="part_of"),ie=k.related_works.filter(G=>G.relation==="has_part"),Y=k.related_works.filter(G=>G.relation==="has_adaptation"),L=k.related_works.filter(G=>G.relation==="text_carried_by"),q=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),X=k.related_works.filter(G=>!G.relation||!q.has(G.relation));return K.length>0&&W.push({label:d.section.belongsToWork,items:K}),ie.length>0&&W.push({label:d.section.containedWorks,items:ie}),Y.length>0&&W.push({label:d.section.adaptations,items:Y}),L.length>0&&W.push({label:d.section.derivativeWorks,items:L}),X.length>0&&W.push({label:d.section.relatedWorks,items:X}),W.map(G=>t.jsxs("div",{children:[t.jsxs(ke,{children:[G.label,t.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",G.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:G.items.map(U=>t.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:t.jsx(Ie,{id:U.id,label:p(U.title),onNavigate:r,renderLink:o})},U.id))})]},G.label))})()]})};function Us({data:e}){const n=N(),{convert:i}=P(),{stats:r}=e,o=r.processed_volumes??r.total_found_volumes,s=o!=null&&e.total_volumes>0?Math.round(o/e.total_volumes*100):null;return t.jsxs("div",{style:{marginBottom:"24px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:i(e.title)}),e.resource_name&&t.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:i(e.resource_name)}),t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[t.jsxs("span",{children:[n.catalog.totalVolumes," ",t.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:e.total_volumes})," ",n.unit.volume]}),s!=null&&t.jsxs("span",{children:[n.catalog.processed," ",t.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o})," ",n.unit.volume," (",s,"%)"]}),t.jsxs("span",{children:[n.catalog.contains," ",t.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&t.jsxs("span",{children:[n.catalog.matched," ",t.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&t.jsxs("span",{children:[n.catalog.unmatched," ",t.jsx("strong",{style:{color:"var(--bim-missing-fg, #e67e22)"},children:r.unmatched_works})," ",n.unit.bu]})]}),e.source&&t.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",e.source]})]})}function Ys({sections:e,activeSection:n,onSelect:i}){const r=N();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>i(null),style:xi(n===null),children:r.catalog.all}),e.map(o=>t.jsxs("button",{onClick:()=>i(o.name),style:xi(n===o.name),children:[o.name,o.volume_range&&t.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[o.volume_range[0],"–",o.volume_range[1]]})]},o.name))]})}function xi(e){return{padding:"4px 12px",border:e?"1px solid var(--bim-primary, #2471a3)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:e?"color-mix(in srgb, var(--bim-primary, #2471a3) 8%, transparent)":"transparent",color:e?"var(--bim-primary, #2471a3)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function Ks({id:e,label:n,onNavigate:i,renderLink:r}){const o=je();return r?t.jsx(t.Fragment,{children:r(e,n)}):i?t.jsx("a",{href:o(e),onClick:s=>{s.metaKey||s.ctrlKey||(s.preventDefault(),i(e))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px",fontSize:"12px"},onMouseEnter:s=>s.currentTarget.style.borderBottomStyle="solid",onMouseLeave:s=>s.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||e})}function qs(e,n){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=e[0],r=e[e.length-1];return r-i+1===e.length?`${i}–${r}`:e.length<=3?e.join(", "):`${i}–${r} (${e.length}${n})`}function gi({book:e,onNavigate:n,renderLink:i,showVolumes:r}){const o=N(),{convert:s}=P(),l=e.book_id||e.work_id,c=r&&e.volumes.length>0?qs(e.volumes,o.unit.volume):null,a=e.missing_volumes&&e.missing_volumes.length>0;return t.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&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:c}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[s(e.title),e.sub_items&&e.sub_items.length>0&&t.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",e.sub_items.map(d=>s(d)).join("、"),")"]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:s(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:a?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,o.unit.volume]}),l&&t.jsx(Ks,{id:l,label:e.book_id?o.indexType.book:o.indexType.work,onNavigate:n,renderLink:i}),!l&&t.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:o.catalog.unmatched_label})]})}const Ln=({data:e,collectionId:n,transport:i,onNavigate:r,renderLink:o,className:s,style:l})=>{const c=N(),[a,d]=f.useState(null),[p,x]=f.useState(!1),[g,u]=f.useState(null),[b,y]=f.useState(null),[h,S]=f.useState(""),m=e||a;f.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollectionCatalog))return;let C=!1;return x(!0),u(null),i.getCollectionCatalog(n).then(k=>{C||(k?d(k):u(c.catalog.notFound))}).catch(k=>{C||u(k instanceof Error?k.message:c.catalog.loadFailed)}).finally(()=>{C||x(!1)}),()=>{C=!0}},[e,n,i,c]);const j=(m==null?void 0:m.sections)&&m.sections.length>0,_=f.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const C=m.books.map(z=>z.volumes[0]).filter(z=>z!=null);return new Set(C).size<C.length},[m]),w=f.useMemo(()=>{if(!m)return[];let C=m.books;if(b&&(C=C.filter(k=>k.section===b)),h.trim()){const k=h.trim().toLowerCase();C=C.filter(z=>z.title.toLowerCase().includes(k)||z.sub_items&&z.sub_items.some(I=>I.toLowerCase().includes(k))||z.edition&&z.edition.toLowerCase().includes(k))}return C},[m,b,h]),T=f.useMemo(()=>{if(!_)return null;const C=[],k=new Map;for(const I of w){if(!I.volumes||I.volumes.length===0)continue;const v=I.volumes[0];k.has(v)||k.set(v,[]),k.get(v).push(I)}const z=[...k.keys()].sort((I,v)=>I-v);for(const I of z)C.push({volume:I,books:k.get(I)});return C},[w,_]);return p?t.jsx("div",{className:s,style:{...l,padding:"24px"},children:t.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.catalog.loading})}):g?t.jsx("div",{className:s,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g}):m?t.jsxs("div",{className:s,style:l,children:[t.jsx(Us,{data:m}),j&&t.jsx(Ys,{sections:m.sections,activeSection:b,onSelect:y}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:c.search.searchBookName,value:h,onChange:C=>S(C.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"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[w.length," ",c.unit.bu]})]}),t.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[T?T.map((C,k)=>t.jsxs("div",{children:[t.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:Tt(c.catalog.volume,{n:C.volume})}),C.books.map((z,I)=>t.jsx(gi,{book:z,onNavigate:r,renderLink:o,showVolumes:z.volumes.length>1},`${C.volume}-${I}`))]},`${C.volume}-${k}`)):w.map((C,k)=>t.jsx(gi,{book:C,onNavigate:r,renderLink:o,showVolumes:!0},k)),w.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:c.catalog.noMatch})]})]}):null},et=()=>{const[e,n]=f.useState(1);return f.useEffect(()=>{const i=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(i)},[]),t.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(e)})},he=6,Wt=7,Js=({content:e,children:n,placement:i="top",delayMs:r=100,maxWidth:o=280,wrapperStyle:s})=>{const[l,c]=f.useState(!1),[a,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(),_=window.innerHeight,w=document.documentElement.clientWidth;let T=i;i==="top"&&m.top-j.height-Wt<8&&(T="bottom"),i==="bottom"&&m.bottom+j.height+Wt>_-8&&(T="top");const C=T==="top"?m.top-j.height-Wt:m.bottom+Wt;let k=m.left+m.width/2-j.width/2;k=Math.max(8,Math.min(k,w-j.width-8)),d({left:k,top:C,placement:T})},[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(!l)return;const h=requestAnimationFrame(u);return()=>cancelAnimationFrame(h)},[l,u]),f.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]),t.jsxs(t.Fragment,{children:[t.jsx("span",{ref:x,onMouseEnter:b,onMouseLeave:y,onFocus:b,onBlur:y,style:{display:"inline-block",...s},children:n}),l&&Go.createPortal(t.jsxs("div",{ref:g,role:"tooltip",style:{position:"fixed",left:(a==null?void 0:a.left)??-9999,top:(a==null?void 0:a.top)??-9999,maxWidth:o,padding:"6px 10px",fontSize:"12px",lineHeight:1.5,color:"var(--bim-fg, #333)",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.08)",pointerEvents:"none",zIndex:9999,opacity:a?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[e,a&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-he,width:0,height:0,...a.placement==="top"?{bottom:-he,borderTop:`${he}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${he}px solid transparent`,borderRight:`${he}px solid transparent`}:{top:-he,borderBottom:`${he}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${he}px solid transparent`,borderRight:`${he}px solid transparent`}}}),t.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...a.placement==="top"?{bottom:-5,borderTop:`${he-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${he-1}px solid transparent`,borderRight:`${he-1}px solid transparent`}:{top:-5,borderBottom:`${he-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${he-1}px solid transparent`,borderRight:`${he-1}px solid transparent`}}})]})]}),document.body)]})},br=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Xs={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function ue(e){return Xs[e]??e}const it=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],rt={熹平: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},yr={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function Ut(e){const n=e.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 Zs(e){return e>=1950?"":e>=1912?"民國":e>=1645?"清":e>=1368?"明":e>=1279?"元":e>=960?"宋":e>=907?"五代":e>=618?"唐":e>=581?"隋":e>=420?"南北朝":e>=265?"晉":e>=220?"三國":e>=-202?"漢":""}const Qs=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,mi={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function Wn(e){const n=e.trim().replace(/[代朝]$/,"");for(const o of Object.keys(mi))if(n.startsWith(o))return mi[o];const i=ue(n);if(Ke[i]!=null)return i;const r=Pe(n);if(r&&n.length<=r.length+1)return ue(r)}function Ye(e,n){if(n){const i=yr[`${n}|${e}`];if(i!=null)return i}return rt[e]}const el=1911;function tl(e){const n=rt[e];if(n==null)return;const i=Ae[e];let r;for(const[o,s]of Object.entries(rt))Ae[o]===i&&s>n&&(r==null||s<r)&&(r=s);return r!=null?r-1:void 0}const nl={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function Dt(e){if(!e)return;if(/^\d+$/.test(e))return parseInt(e,10);let n=0,i=0,r=!1;for(const s of e){const l=nl[s];if(l===void 0)return;r=!0,s==="十"?i=(i||1)*10:s==="廿"||s==="卅"?(n+=l,i=0):i>=10?(n+=i+l,i=0):i=i*10+l}const o=n+i;return r&&o>0?o:void 0}function Pe(e){for(const n of br)if(e.startsWith(n))return n}const Ae={};{const e=(n,i)=>{for(const r of i)Ae[r]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function qe(e,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(rt))if(e.includes(r)&&!(i&&Ae[r]&&Ae[r]!==i&&yr[`${i}|${r}`]==null))return r}function It(e){var l,c,a;const n={era:"",reign:"",source:"none"},i=e.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=(l=e.lineage)==null?void 0:l.year_text;if(r){const d=Pe(r)??"";return{era:ue(d),reign:qe(r,d)??"",source:"lineage"}}const o=(c=e.publication_info)==null?void 0:c.year;if(o){const d=Ut(o);if(d)return{era:Zs(d.from),reign:"",source:"publication"};const p=Pe(o)??Wn(o)??((a=it.find(u=>u.pattern.test(o)))==null?void 0:a.era)??"",x=qe(o,p)??"",g=p||(x?Ae[x]??"":"");if(g||x)return{era:ue(g),reign:x,source:"publication"}}const s=e.edition||e.title||"";if(s){const d=Pe(s);if(d)return{era:ue(d),reign:qe(s,d)??"",source:"edition"};const p=it.find(x=>x.pattern.test(s));if(p)return{era:ue(p.era),reign:qe(s,p.era)??p.reign??"",source:"edition"}}return n}function Yt(e){var r,o,s,l,c,a,d,p,x;if(((r=e.dating)==null?void 0:r.year)!=null)return e.dating.year;if(typeof((o=e.lineage)==null?void 0:o.year)=="number")return e.lineage.year;const n=(s=e.publication_info)==null?void 0:s.year;if(n){const g=Ut(n);if(g)return g.from}const i=[(l=e.lineage)==null?void 0:l.year_text,(c=e.publication_info)==null?void 0:c.year,e.edition,e.edition?void 0:e.title].filter(Boolean);for(const g of i){const u=((a=e.publication_info)==null?void 0:a.year)||((d=e.lineage)==null?void 0:d.year_text);if(u&&g!==u&&(Pe(u)||Wn(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=Pe(g);if(!j||ue(j)==="民國"){const w=Dt(y[1]);if(w!=null&&w>=1&&w<=120)return el+w}}const h=Pe(g)??((p=it.find(j=>j.pattern.test(g)))==null?void 0:p.era),S=h?ue(h):void 0,m=qe(g,S)??(Pe(g)||(x=it.find(j=>j.pattern.test(g)))==null?void 0:x.reign);if(m){const j=Ye(m,S);if(j==null)continue;const _=g.indexOf(m),w=_>=0?g.slice(_+m.length):"",T=w.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??w.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),C=T?Dt(T[1]):void 0;return j+(C?C-1:0)}}}function $n(e){var l,c,a,d,p,x;const n=(l=e.dating)==null?void 0:l.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const i=(c=e.lineage)==null?void 0:c.year_range;if(i&&i.length===2)return{from:i[0],to:i[1]};const r=(a=e.lineage)==null?void 0:a.year_text;if(r){const g=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(g){const u=hn[ue(g[1])],b=Ke[ue(g[2])];if(u!=null&&b!=null)return{from:Math.min(u,b)-20,to:Math.max(u,b)+40}}}const o=(d=e.publication_info)==null?void 0:d.year;if(o){const g=Ut(o);if((g==null?void 0:g.to)!=null)return{from:g.from,to:g.to};const u=o.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(u){const b=hn[ue(u[1])],y=Ke[ue(u[2])];if(b!=null&&y!=null)return{from:Math.min(b,y)-20,to:Math.max(b,y)+40}}}const s=[(p=e.publication_info)==null?void 0:p.year,e.edition,e.title].filter(Boolean);for(const g of s){if(!/[間间]/.test(g))continue;const u=Pe(g)??Wn(g)??((x=it.find(h=>h.pattern.test(g)))==null?void 0:x.era),b=u?ue(u):void 0,y=[];for(const h of Object.keys(rt))g.includes(h)&&(b&&Ae[h]&&Ae[h]!==b||Ye(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(rt))if(Ae[m]===b&&!(m[0]!==S&&m[m.length-1]!==S)&&Ye(m,b)!=null){y.push(m);break}}}if(y.length>0){const h=y.map(_=>Ye(_,b)).filter(_=>_!=null),S=Math.min(...h),m=y.reduce((_,w)=>Ye(_,b)>=Ye(w,b)?_:w),j=tl(m)??sn(b??"")??Math.max(...h);return{from:S,to:j>S?j:sn(b??Ae[m]??"")??S}}if(b&&Ke[b]!=null)return{from:Ke[b],to:sn(b)??Ke[b]}}}const Ke={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},il=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],rl=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,hi=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function bi(e,n){for(const i of br){const r=e.indexOf(i);if(r<0)continue;if(i.length===1){const a=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(a)&&!qe(e.slice(r),ue(i)))continue}const o=ue(i);if(o===n)continue;const s=e.slice(r),l=qe(s,o)??"";let c;if(l){const a=Ye(l,o);if(a!=null){const p=s.slice(s.indexOf(l)+l.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),x=p?Dt(p[1]):void 0;c=a+(x?x-1:0)}}return{era:o,reign:l,year:c}}for(const i of it)if(i.pattern.test(e))return{era:ue(i.era),reign:i.reign??""}}function ol(e){var S,m,j,_,w;const n=It(e),i=((S=e.publication_info)==null?void 0:S.year)??"",r=i?Ut(i):void 0;if(!n.era&&!n.reign&&!r)return;const o=e.edition||e.title||"",s=/[間间]/.test(o),l=((m=e.lineage)==null?void 0:m.year_text)??"",c=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(l),a=n.source==="publication"&&Qs.test(i),d=n.source==="publication"&&/[間间]/.test(i),p=l.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let x;s||c||a||d?x=void 0:p?x=parseInt(p[2],10):x=Yt(e);const g=x==null?$n(e):void 0;let u;n.source==="publication"&&(a||hi.test(i))?u="uncertain":n.source==="lineage"||n.source==="publication"?u="attested":hi.test(o)||!n.reign&&x==null?u="uncertain":u="inferred";const b=n.source==="edition"?`題名「${o}」`:n.source==="lineage"?`版本傳承著錄「${((j=e.lineage)==null?void 0:j.year_text)??((_=e.lineage)==null?void 0:_.year)??""}」`:`出版著錄「${((w=e.publication_info)==null?void 0:w.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 T=l.match(/[、,,]\s*([宋元明清])/);T&&T[1]!==y.era&&(y.laterRepair={era:T[1]})}if(!y.laterRepair&&rl.test(o)){const T=o.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);T&&T[1]!==n.era&&(y.laterRepair={era:T[1]})}const h=il.find(T=>T.re.test(o));if(h){const T=o.search(h.re),C=o.slice(T),k=bi(C,n.era)??bi(o,n.era);k&&(y.basedOn={era:k.era,reign:k.reign,year:k.year,relation:h.relation})}return y}const hn={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function sn(e){return hn[e]}function vr(e){const n=Yt(e);if(n!=null)return n;const i=$n(e);if(i)return i.from;const r=It(e).era;return r?Ke[r]:void 0}const yi=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function bn(e){const n=yi.indexOf(e);return n===-1?yi.length:n}function jr(e){const n={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const o of e){const s=o.relation;s==="part_of"?n.belongsTo.push(o):s==="collected_in"?n.collected.push(o):s==="has_part"||s==="contains_text_of"?n.contains.push(o):s==="text_carried_by"||s==="studied_by"||s==="derived_from"||s==="followed_by"||s==="has_adaptation"?n.derivative.push(o):s==="studies"||s==="preceded_by"?n.studies.push(o):n.related.push(o)}const i=[],r=(o,s)=>{n[o].length&&i.push({key:o,labelKey:s,items:n[o]})};return r("belongsTo","belongsToWork"),r("collected","collectedIn"),r("contains","containedWorks"),r("derivative","derivativeWorks"),r("studies","studies"),r("related","relatedWorks"),i}function Kt(e,n){const i=Tn(e||[]),r=new Map,o=[];for(const d of i)d.group?(r.has(d.group)||r.set(d.group,[]),r.get(d.group).push(d)):o.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 s={text:[],image:[],textImage:[],physical:[]};for(const d of o){const p=Xe(d),x=p.includes("text"),g=p.includes("image");x&&g?s.textImage.push(d):x?s.text.push(d):g?s.image.push(d):s.physical.push(d)}const c=["text","image","textImage","physical"].filter(d=>s[d].length>0).map(d=>({key:d,items:s[d]})),a=[...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:a,total:i.length}}function An(e){const n=[],i=e.metadata||{};i.edition&&n.push(String(i.edition)),e.source_label&&n.push(e.source_label),e.details&&n.push(e.details);const r=In(e);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 sl(e,n){if(An(e)||n.filter(r=>r.name===e.name).length<2)return"";try{const r=new URL(e.url),o=r.searchParams.get("res")||r.searchParams.get("id");if(o)return o;const s=r.pathname.split("/").filter(Boolean).pop();if(s)return decodeURIComponent(s)}catch{}return""}function Sr(e,n){var s,l;const i=e.resources||[],r=[],o=[];for(const c of i){const a=Xe(c);a.includes("image")&&r.push(c),a.includes("physical")&&o.push(c)}return{id:e.id,name:e.edition||e.title||e.id,era:It(e),year:Yt(e),sortYear:vr(e),images:r,holders:o,locationName:(s=e.current_location)==null?void 0:s.name,important:ll(e.id,n),group:(l=n==null?void 0:n.node_groups)==null?void 0:l[e.id],hasImage:r.length>0}}function ll(e,n){var c,a;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(e))return!0;const s=(r==null?void 0:r.groups)??[],l=(a=n.node_groups)==null?void 0:a[e];return!!l&&s.includes(l)}function kr(e,n,i={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),o=e.filter(a=>!r.has(a.id)).map(a=>Sr(a,n));let s=o;i.era&&(s=s.filter(a=>a.era.era===i.era)),i.scanOnly&&(s=s.filter(a=>a.hasImage)),i.sort==="year"?s=s.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const p=a.r.sortYear,x=d.r.sortYear;return p!=null&&x!=null?p-x||a.i-d.i:p!=null?-1:x!=null?1:a.i-d.i}).map(a=>a.r):s=s.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const p=x=>(x.important?0:1)*2+(x.hasImage?0:1);return p(a.r)-p(d.r)||a.i-d.i}).map(a=>a.r);const c=[...new Set(o.map(a=>a.era.era).filter(Boolean))].sort((a,d)=>bn(a)-bn(d));return{rows:s,allRows:o,eras:c,hasInferredEra:o.some(a=>a.era.source==="edition")}}function al(e,n){var h,S;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(h=n.collections)==null?void 0:h[n.default_collection],r=(i==null?void 0:i.groups)??[],o=(i==null?void 0:i.book_ids)??[],s=r.length>0||o.length>0,l=!s&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!s&&l.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const c=new Set(r),a=new Set([...o,...l]),d=m=>{if(a.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 e)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:e,groupedIds:[]};const b=new Map((n.groups??[]).map(m=>[m.id,m])),y=[...x.entries()].map(([m,j])=>{const _=b.get(m);return{id:m,label:(_==null?void 0:_.label)??m,description:_==null?void 0:_.description,ids:j}});return g.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:p,groupedIds:y}}const wr=["撰","編","注","校","譯","繪","其他"],cl=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function Fn(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:r}of cl)if(r.test(n))return i;return"其他"}function Mn(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function _r(e){const n=new Map;for(const r of e){const o=Fn(r);n.set(o,(n.get(o)??0)+1)}const i=[{cls:"全部",label:"全部",count:e.length}];for(const r of wr){const o=n.get(r);o&&i.push({cls:r,label:r,count:o})}return i.length>2?i:[]}function Cr(e,n,i){if(n&&n.books&&n.books.length>0){const o=n.books.map(l=>({id:l.work_id||l.book_id||void 0,title:l.title,section:l.section,volumes:l.volumes||[],subItems:l.sub_items,edition:l.edition,found:l.found_volumes,expected:l.expected_volumes})),s=[...new Set(o.map(l=>l.section).filter(Boolean))];return{rows:o,source:"catalog",sections:s,totalVolumes:n.total_volumes}}return e.contained_works&&e.contained_works.length>0?{rows:e.contained_works.map(s=>({id:s.id,title:s.title,volumes:jt(s.volume_index)})),source:"works",sections:[]}:{rows:(e.books||[]).map(o=>{var s,l;return{id:o,title:((s=i==null?void 0:i.get(o))==null?void 0:s.title)||o,edition:(l=i==null?void 0:i.get(o))==null?void 0:l.edition,volumes:[]}}),source:"books",sections:[]}}function jt(e){if(e==null)return[];if(typeof e=="number")return[e];if(Array.isArray(e))return e.filter(n=>typeof n=="number");if(typeof e=="string"){const n=e.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)},(o,s)=>i+s)}return e.split(/[,、]/).map(i=>parseInt(i.trim())).filter(i=>!isNaN(i))}return[]}function Pn(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=[...e].sort((s,l)=>s-l),r=i[0],o=i[i.length-1];return o-r+1===i.length?`${r}–${o}`:i.length<=3?i.join(", "):`${r}–${o} (${i.length}${n})`}const dl=["〇","一","二","三","四","五","六","七","八","九"],vi=["","十","百","千"];function Tr(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),i=n.length;let r="",o=!1;for(let s=0;s<i;s++){const l=parseInt(n[s]),c=i-1-s;l===0?o=!0:(o&&r&&(r+="〇"),o=!1,l===1&&c===1&&s===0?r+=vi[c]:r+=dl[l]+vi[c])}return r}function pl(e){return e==null?"":typeof e=="string"?e:e.title??""}function Ze(e,n="卷"){var r,o;const i=e;return i.measure_info?i.measure_info:(r=i.juan_count)!=null&&r.number?Tr(i.juan_count.number)+n:(o=i.juan_count)!=null&&o.description?i.juan_count.description:""}function Ir(e){var r;if((r=e.lineage)!=null&&r.category)return e.lineage.category;const n=e.edition||e.title||"",i=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[o,s]of i)if(o.test(n))return s;return""}const ul="guji_markdown";function yn(e){const n=e==null?void 0:e.guji_markdown;if(typeof n!="string")return!1;const i=/^(\d+)\.(\d+)(?:\.\d+)?$/.exec(n.trim());if(!i)return!1;const r=parseInt(i[1],10),o=parseInt(i[2],10);return r>0||o>=2}const fl=/^□\{guess=([^\s{}]+)\}/;function xl(e,n){const i=e[n+1];return i!==void 0&&!/[A-Za-z/!?>\s]/.test(i)}function gl(e,n){let i=0;for(let r=n;r<e.length;r++){const o=e[r];if(o===`
|
|
2
|
+
`)return-1;if(o==="\\"){r++;continue}if(o==="[")i++;else if(o==="]"&&(i--,i===0))return r}return-1}function ml(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function hl(e,n){const i=e[n];if(i==="["&&e[n+1]==="["){const r=e.indexOf("]]",n+2);return r>=0&&e.slice(n+2,r).indexOf(`
|
|
3
|
+
`)<0?{node:{type:"qw",label:e.slice(n+2,r)},end:r+2}:null}if(i===":"&&e.startsWith(":zi[",n)){const r=gl(e,n+3);return r>n+4?{node:{type:"zi",label:ml(e.slice(n+4,r))},end:r+1}:null}if(i==="□"&&e[n+1]==="{"){const r=fl.exec(e.slice(n,n+64));if(r)return{node:{type:"qz",guess:r[1]},end:n+r[0].length}}return null}function zr(e,n,i,r){const o=[];let s="";const l=()=>{if(!s)return;const c=r?s.replace(/\\?\|/g,""):s;c&&o.push({type:"text",text:c}),s=""};for(;n<e.length;){const c=e[n];if(i!==null){if(c===i)return l(),{nodes:o,end:n};if(c===`
|
|
4
|
+
`)return null}const a=hl(e,n);if(a){l(),o.push(a.node),n=a.end;continue}let d=null;if(c==="⟨"?d="⟩":c==="<"&&xl(e,n)&&(d=">"),d){const p=zr(e,n+1,d,!0);if(p){l(),o.push({type:"jz",children:p.nodes}),n=p.end+1;continue}}s+=c,n++}return i!==null?null:(l(),{nodes:o,end:n})}function Rr(e){return zr(e,0,null,!1).nodes}function bl(e){return/[<⟨□]|\[\[|:zi\[/.test(e)}function Er(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${Er(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const ht=1e3,ln=208,yl="(max-width: 719px)",Br=`
|
|
2
5
|
.bim-d-page {
|
|
3
6
|
background: var(--bim-page-bg, #fbf9f3);
|
|
4
7
|
color: var(--bim-ink, #2a231c);
|
|
@@ -75,7 +78,7 @@
|
|
|
75
78
|
align-items: start; margin-bottom: 48px; }
|
|
76
79
|
.bim-d-pair-wide { grid-template-columns: 1fr 1.2fr; }
|
|
77
80
|
|
|
78
|
-
@media ${
|
|
81
|
+
@media ${yl} {
|
|
79
82
|
.bim-d-intro { grid-template-columns: 1fr; gap: 20px; margin-bottom: 32px; }
|
|
80
83
|
.bim-d-pair, .bim-d-pair-wide { grid-template-columns: 1fr; gap: 40px; }
|
|
81
84
|
/* 表格:meta 列折到第二行,表头隐藏 */
|
|
@@ -93,10 +96,10 @@
|
|
|
93
96
|
padding-right: 0; padding-bottom: 12px;
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
|
-
`;function Ft({children:
|
|
97
|
-
`)||(n.push({start:i,end:o+1,inner:l}),i=o)}return n}function Ar(t,n){if(t.length<=n)return t;let i=n;for(const r of $r(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 be(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 $r(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 Pt({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 yn({title:t,tag:n,children:i}){const{convert:r}=M();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 Fr({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 st({item:t,siblings:n,showVolumes:i=!0,fallbackNote:r}){const{convert:s}=M(),[o,l]=f.useState(!1),c=Tn(t),a=i&&!!c&&c.expected>0,d=(t.url?kt(t.url):void 0)||s(t.name),p=n?el(t,n):"",x=p?`${d}(${p})`:d;return e.jsx(Fr,{name:x,note:$n(t)||r,href:Ht(t),extra:a?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>l(g=>!g),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:"var(--bim-meta-fg, #7b6a54)",borderBottom:"1px solid var(--bim-rule, #e0d6c0)"},children:o?"收起分冊":`展開 ${c.expected} 冊`}),o&&e.jsx(Pr,{item:t})]}):void 0})}function Pr({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 On({label:t,items:n}){const{convert:i}=M();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(Et,{children:i(r)},s))]}):null}function Mr({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(On,{label:i.label,items:i.items},i.label))}):null}function _t(t){return(t||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Or({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 lt({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 ze({id:t,label:n,onNavigate:i,renderLink:r,style:s,dense:o}){const l=je();return r?e.jsx(e.Fragment,{children:r(t,typeof n=="string"?n:void 0,{dense:o})}):e.jsx("a",{href:l(t),onClick:i?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),i(t))}:void 0,style:s,children:n??t})}function vn({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 vi={A:"fine",B:"rough",C:"rough",D:"ocr"};function ll(t){return typeof t!="string"?null:t in nr?t:t in vi?vi[t]:null}const al={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},cl={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function ge(t){return typeof t!="string"?"":al[t]??cl[t]??t}const dl=["〇","一","二","三","四","五","六","七","八","九"],ji=["","十","百","千"],pl=["","萬","億"];function Hr(t){if(t===0)return"〇";if(t<0)return`負${Hr(-t)}`;const n=[];let i=t,r=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(ul(s,r>0)+pl[r]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function ul(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 l=i[o],c=i.length-1-o;l===0?s&&!s.endsWith("〇")&&(s+="〇"):l===1&&c===1&&o===0&&!n?s+=ji[c]:s+=dl[l]+ji[c]}return s.replace(/〇$/,"")}let St=null,$t=null;const Nt=new Set;function fl(){return St?Promise.resolve():$t||($t=import("opencc-js/t2cn").then(t=>{St=t.Converter({from:"tw",to:"cn"}),Nt.forEach(n=>n())}).catch(()=>{St=t=>t,Nt.forEach(t=>t())}),$t)}function He(){const[,t]=f.useState(0);return f.useEffect(()=>{if(St)return;const n=()=>t(i=>i+1);return Nt.add(n),fl(),()=>{Nt.delete(n)}},[]),St??(n=>n)}function at(t,n){return n(t).toLowerCase()}const Hn="var(--bim-highlight-bg, #fff59d)";function ct(t,n,i){if(!n)return t;const r=at(n,i);if(!r)return t;const s=at(t,i);if(s.length!==t.length)return t;const o=[];let l=0,c=0;for(;l<t.length;){const a=s.indexOf(r,l);if(a===-1){o.push(t.slice(l));break}a>l&&o.push(t.slice(l,a)),o.push(e.jsx("mark",{style:{background:Hn,padding:0,color:"inherit"},children:t.slice(a,a+r.length)},c++)),l=a+r.length}return e.jsx(e.Fragment,{children:o})}function Dn(t,n,i,r){if(!n)return!0;const s=at(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(l=>typeof l=="string"&&at(l,r).includes(s))}function xl(t,n,i){return n?at(t,i).includes(at(n,i)):!0}const Nn={类:"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)"},gl={考证:"var(--bim-section-kaozhen, #5d6d7e)"};function ml(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 jn({file:t,isActive:n,onSelect:i,meta:r,matchState:s,vertical:o}){const l=s===0,c=s==="loading",a=typeof s=="number"&&s>0,d=r!=null&&r.vol_label?`${r.vol_label}冊`:null,p=d??ml(t),x=!d&&!!(r!=null&&r.vol_label)&&!p.includes(r.vol_label);return e.jsxs("button",{onClick:()=>{l||i(t)},disabled:l,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)":l?"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)":a?`${Hn}40`:"transparent",color:n?"var(--bim-primary, #8e6f3e)":l?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:l?"not-allowed":"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4,opacity:l?.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,"冊)"]}),a&&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 Dr(t,n){var i;return t.files.includes(n)?!0:!!((i=t.children)!=null&&i.some(r=>Dr(r,n)))}function Nr(t){var r;const n=t.files.length,i=((r=t.children)==null?void 0:r.reduce((s,o)=>s+Nr(o),0))||0;return n+i}function hl(t,n){const i=[],r=l=>{var c;i.push(...l.files),(c=l.children)==null||c.forEach(r)};if(r(t),i.length===0)return;const s=i.map(l=>n[l]);if(s.every(l=>l===void 0))return;if(s.some(l=>l==="loading"))return"loading";let o=0;for(const l of s)typeof l=="number"&&(o+=l);return o}function Vr({group:t,activeFile:n,onSelect:i,depth:r=0,juanMeta:s,matchStates:o,vertical:l}){var y;const c=Dr(t,n||""),a=hl(t,o),d=typeof a=="number"&&a>0,p=a===0,[x,g]=f.useState(c||d),u=Nr(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,_=m==="loading",w=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)":w?`${Hn}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,w&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:m}),_&&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:["匹配 ",a]}),a==="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:l?"column":"row",flexWrap:l?"nowrap":"wrap",gap:l?"1px":"4px",padding:l?`2px 0 2px ${8+r*10}px`:`4px 0 4px ${24+r*16}px`},children:t.files.map(h=>e.jsx(jn,{file:h,isActive:n===h,onSelect:i,meta:s==null?void 0:s[h],matchState:o[h],vertical:l},h))}),b&&t.children.map((h,S)=>e.jsx(Vr,{group:h,activeFile:n,onSelect:i,depth:r+1,juanMeta:s,matchStates:o,vertical:l},S))]})]})}function bl({files:t,groups:n,activeFile:i,onSelect:r,juanMeta:s,matchStates:o,vertical:l}){const c=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:l?0:"16px"},children:n.map((a,d)=>e.jsx(Vr,{group:a,activeFile:i,onSelect:r,juanMeta:s,matchStates:o,vertical:l},d))}):c.length===0?null:l?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"1px"},children:c.map(a=>e.jsx(jn,{file:a,isActive:i===a,onSelect:r,meta:s==null?void 0:s[a],matchState:o[a],vertical:!0},a))}):e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:c.map(a=>e.jsx(jn,{file:a,isActive:i===a,onSelect:r,meta:s==null?void 0:s[a],matchState:o[a]},a))})}function yl({type:t}){const n=ge(t),i=Nn[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 vl({section:t,onNavigate:n,highlightQuery:i=""}){const{convert:r}=M(),s=je(),o=He(),l=y=>y?be(r(y),h=>i?ct(h,i,o):h):"",[c,a]=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&&a(!0)},[i]);const b=!c&&g?Ar(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&&a(!c),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:u?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[u&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:c?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[t.book_title?e.jsxs(e.Fragment,{children:["《",l(t.book_title),"》"]}):l(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[Hr(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:l(t.author_info||t.author)})]}),!c&&b&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:l(b)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:l(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-section-tag-fg, #e74c3c)"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:s(t.work_id),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),c&&u&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:l(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.additional_comment)})]}),g&&!d&&!p&&!x&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:l(t.content)})]})]})}function jl({section:t,highlightQuery:n=""}){const{convert:i}=M(),r=He(),s=a=>a?be(i(a),d=>n?ct(d,n,r):d):"",[o,l]=f.useState(!1),c=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>c&&l(!o),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[e.jsx(yl,{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, ${Nn[ge(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 Sl=100;function Gr(t){return ge(t.type)!=="page_header"?!1:(t.content||"").length>=Sl}function kl({section:t,highlightQuery:n=""}){const{convert:i}=M(),r=He();if(ge(t.type)==="page_header"&&!Gr(t)||!t.content&&!t.title)return null;const s=i((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
98
|
-
`)),
|
|
99
|
-
`);return e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:o.map((l,c)=>{if(l.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:s(l.slice(2))},c);if(l.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:s(l.slice(3))},c);if(l.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:s(l.slice(4))},c);if(!l.trim())return c>0&&!o[c-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},c);const a=l.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:a.map((d,p)=>d.startsWith("**")&&d.endsWith("**")?e.jsx("strong",{children:s(d.slice(2,-2))},p):e.jsx(f.Fragment,{children:s(d)},p))},c)})})}function Il({sections:t,onNavigate:n,highlightQuery:i=""}){const{convert:r}=M(),s=je(),o=He(),l=d=>d?be(r(d),p=>i?ct(p,i,o):p):"",c=[];let a=null;for(const d of t){const p=ge(d.type);p==="page_header"&&!Gr(d)||(p==="类"?(a&&c.push(a),a={category:d.title,categoryContent:d.content||void 0,items:[]}):p==="书"||p==="诗"||p==="考证"||p==="注释"?(a||(a={category:"",items:[]}),a.items.push(d)):(p==="序"||p==="结语")&&(a||(a={category:"",items:[]}),a.items.push(d),p==="结语"&&(c.push(a),a=null)))}return a&&c.push(a),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:c.map((d,p)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[d.category&&e.jsxs("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:[l(d.category),d.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:l(d.categoryContent)})]}),d.items.map((x,g)=>ge(x.type)==="序"||ge(x.type)==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:l(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:l(x.title)})}):e.jsx("strong",{children:l(x.title)}),x.content&&l(x.content)]},g))]},p))})}function zl({juan:t,rawText:n,searchQuery:i,onNavigate:r}){const{convert:s}=M(),o=He(),[l,c]=f.useState("catalog"),a=i.trim(),d=f.useMemo(()=>a?t.sections.filter(u=>Dn(u,a,!1,o)):t.sections,[t.sections,a,o]),p=t.sections.filter(u=>ge(u.type)==="书").length,x=t.sections.filter(u=>ge(u.type)==="诗").length,g=a?d.filter(u=>ge(u.type)==="书"||ge(u.type)==="诗").length:null;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"12px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:s(t.title)}),e.jsx("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:l===u?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:l===u?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:u==="catalog"?"目錄":"原文"},u))})]}),l==="raw"&&(n?e.jsx(Tl,{text:n,highlightQuery:a}):e.jsx(Il,{sections:t.sections,onNavigate:r,highlightQuery:a})),l==="catalog"&&d.map((u,b)=>{const y=ge(u.type);return y==="书"||y==="诗"||y==="考证"?e.jsx(vl,{section:u,onNavigate:r,highlightQuery:a},b):y==="类"?e.jsx(jl,{section:u,highlightQuery:a},b):e.jsx(kl,{section:u,highlightQuery:a},b)}),l==="catalog"&&d.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function Ur(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 Rl(t){const n=Ur(t);return n.length>0?n[0]:null}function El(t){const{workId:n,transport:i,files:r,activeFile:s,activeJuan:o,activeRawText:l,query:c,isKaozhen:a}=t,d=He(),p=f.useRef(new Map),[x,g]=f.useState({});f.useEffect(()=>{s&&o&&p.current.set(s,{juan:o,rawText:l})},[s,o,l]),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)Dn(S,y,a,d)&&h++;return h===0&&b.rawText&&xl(b.rawText,y,d)&&(h=1),h},[a,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 T of r){const C=p.current.get(T);C?h[T]=u(C,b):(h[T]="loading",S.push(T))}g(h);const m=8;let j=0;const _=async()=>{var T;for(;j<S.length;){if(y)return;const C=j++,k=S[C];try{const[z,I]=await Promise.all([i.getCollatedJuan(n,k),((T=i.getCollatedJuanText)==null?void 0:T.call(i,n,k))??Promise.resolve(null)]),v={juan:z,rawText:I};if(p.current.set(k,v),y)return;g(E=>({...E,[k]:u(v,b)}))}catch{if(y)return;g(z=>({...z,[k]:0}))}}},w=Array.from({length:Math.min(m,S.length)},()=>_());return Promise.all(w),()=>{y=!0}},[c,n,i,r.join(","),u,d]),{matchStates:x}}const Vn=({index:t,workId:n,transport:i,onNavigate:r,activeJuan:s,onJuanChange:o,className:l,style:c})=>{const[a,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]=f.useState(null),[T,C]=f.useState(""),k=f.useRef(new Map),z=f.useRef(0),I=s??b,v=f.useCallback(F=>{y(F),o==null||o(F)},[o]),E=t||a;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(q=>{F||(q?d(q):u("未找到整理本数据"))}).catch(q=>{F||u(q instanceof Error?q.message:"加载失败")}).finally(()=>{F||x(!1)}),()=>{F=!0}},[t,n,i]),f.useEffect(()=>{if(E&&!I){const F=Rl(E);F&&v(F)}},[E,I,v]);const R=n||(E==null?void 0:E.work_id),P=f.useCallback(async F=>{var W;if(!R||!(i!=null&&i.getCollatedJuan))return;const q=++z.current;j(!0),S(null),w(null);try{const[K,ie]=await Promise.all([i.getCollatedJuan(R,F),((W=i.getCollatedJuanText)==null?void 0:W.call(i,R,F))??Promise.resolve(null)]);if(q!==z.current)return;S(K),w(ie)}catch{if(q!==z.current)return;S(null),w(null)}finally{q===z.current&&j(!1)}},[R,i]);f.useEffect(()=>{I&&P(I)},[I,P]);const $=F=>{v(F)};if(p)return e.jsx("div",{className:l,style:{...c,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(g)return e.jsx("div",{className:l,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g});if(!E)return null;const H=E.type==="kaozhen",A=Ur(E);return e.jsx(Bl,{className:l,style:c,index:E,allFiles:A,isKaozhen:H,effectiveWorkId:R,transport:i,activeFile:I,handleSelectFile:$,juanData:h,juanRawText:_,juanLoading:m,searchQuery:T,setSearchQuery:C,onNavigate:r,workLabelCacheRef:k})},Bl=({className:t,style:n,index:i,allFiles:r,isKaozhen:s,effectiveWorkId:o,transport:l,activeFile:c,handleSelectFile:a,juanData:d,juanRawText:p,juanLoading:x,searchQuery:g,setSearchQuery:u,onNavigate:b,workLabelCacheRef:y})=>{const{matchStates:h}=El({workId:o,transport:l,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(bl,{files:r,groups:i.juan_groups,activeFile:c,onSelect:a,juanMeta:i.juan_metadata,matchStates:h,vertical:!0})]});return e.jsx("div",{className:t,style:n,children:e.jsxs(zr,{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=ll(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(Vs,{content:No[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:Vo[m],cursor:"help"},children:nr[m]})}),i.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",i.text_quality.source_note]})]}):null})()]}),x?e.jsx(et,{}):d?s?e.jsx(Cl,{juan:d,searchQuery:g,onNavigate:b,transport:l,workLabelCache:y}):e.jsx(zl,{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))]})]})})},Ll={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)"}},Wl={label:"其他",color:"var(--bim-desc-fg, #999)"},$l={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)"}},Al={label:"待处理",color:"var(--bim-warning, #ff9800)"};function Fl(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 Pl(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 Gn=({items:t,loading:n})=>{const i=je();return n?e.jsx(et,{}):t.length===0?e.jsx("div",{style:Ml,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const s=Ll[r.type]||Wl,o=$l[r.status]||Al,l=typeof window<"u"&&Pl(r.pageUrl,window.location.href);return e.jsxs("div",{style:Ol,children:[e.jsxs("div",{style:Hl,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...Si,background:s.color},children:s.label}),e.jsx("span",{style:{...Si,background:o.color},children:o.label})]}),e.jsx("span",{style:Dl,children:Fl(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&e.jsxs("div",{style:Nl,children:[r.resourceId&&e.jsx("a",{href:i(r.resourceId),style:an,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(l?e.jsx("a",{href:r.pageUrl,style:an,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):e.jsx("span",{style:an,children:r.pageUrl}))]}),e.jsx("div",{style:Vl,children:r.content}),r.reply&&e.jsxs("div",{style:Gl,children:[e.jsx("div",{style:Ul,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})})},Ml={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},Ol={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},Hl={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Si={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},Dl={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},Nl={fontSize:"12px",marginBottom:"6px"},an={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},Vl={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},Gl={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},Ul={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},Sn=({transport:t,onNavigate:n,recommendedIds:i,activeTab:r,onTabChange:s,feedbackApiUrl:o})=>{const l=N(),[c,a]=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,_]=f.useState(!0),[w,T]=f.useState(null),[C,k]=f.useState(null),[z,I]=f.useState(null);f.useEffect(()=>{let $=!1;if(t.getCounts)return t.getCounts().then(H=>{$||a({works:H.works,books:H.books,collections:H.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(q=>({...q,group:F.name})))}catch{}return[]})().then(async A=>{if($)return;const F=A.filter(W=>W.id);if(F.length===0){_(!1);return}const q=await Promise.all(F.map(async W=>{if(W.type)return{id:W.id,title:W.title,type:W.type,author:W.author,dynasty:W.dynasty,role:W.role,edition:W.edition,has_text:W.has_text,has_image:W.has_image,has_collated:W.has_collated,subtype:W.subtype,primary_name:W.primary_name,group:W.group,fallbackDescription:W.description};try{let K=null;if(t.getEntry)K=await t.getEntry(W.id);else{const ie=await t.getItem(W.id);ie&&(K={id:W.id,title:ie.title||W.id,type:ie.type||"work"})}if(K)return{...K,group:W.group,fallbackDescription:W.description}}catch{}return{id:W.id,title:W.title,type:Z.extractType(W.id),group:W.group,fallbackDescription:W.description}}));$||(p(q.filter(W=>W!==null)),_(!1))}),()=>{$=!0}},[t,i]);const v=f.useRef(!1),E=f.useRef(!1),R=f.useRef(!1);f.useEffect(()=>{if(S!=="catalog"||v.current)return;const $=t.getCatalogProgress??t.getResourceProgress;if(!$)return;v.current=!0;let H=!1;return $.call(t).then(A=>{H||T(A)}).catch(()=>{v.current=!1}),()=>{H=!0}},[t,S]),f.useEffect(()=>{if(S!=="collection"||E.current||!t.getCollectionProgress)return;E.current=!0;let $=!1;return t.getCollectionProgress().then(H=>{$||k(H)}).catch(()=>{E.current=!1}),()=>{$=!0}},[t,S]),f.useEffect(()=>{if(S!=="site"||R.current||!t.getSiteProgress)return;R.current=!0;let $=!1;return t.getSiteProgress().then(H=>{$||I(H)}).catch(()=>{R.current=!1}),()=>{$=!0}},[t,S]),f.useEffect(()=>{if(!o||S!=="feedback")return;let $=!1;return h(!0),fetch(o).then(H=>H.json()).then(H=>{!$&&H.success&&b(H.items||[])}).catch(()=>{}).finally(()=>{$||h(!1)}),()=>{$=!0}},[o,S]);const P=$=>{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:l.home.recommendTab,active:S==="recommend",onClick:()=>m("recommend")}),e.jsx(xt,{label:l.home.catalogTab,active:S==="catalog",onClick:()=>m("catalog")}),e.jsx(xt,{label:l.home.collectionTab,active:S==="collection",onClick:()=>m("collection")}),e.jsx(xt,{label:l.home.siteTab,active:S==="site",onClick:()=>m("site")}),o&&e.jsx(xt,{label:l.home.feedbackTab,active:S==="feedback",onClick:()=>m("feedback")})]}),S==="recommend"&&e.jsx(Yl,{recommended:d,loading:j,onNavigate:n,getIcon:P,t:l}),S==="catalog"&&e.jsx(ki,{progress:w,t:l,onNavigate:n}),S==="collection"&&e.jsx(ki,{progress:C,t:l,onNavigate:n}),S==="site"&&e.jsx(Jl,{progress:z,t:l,totalWorks:(c==null?void 0:c.works)??0}),S==="feedback"&&o&&e.jsx(Gn,{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}),Yl=({recommended:t,loading:n,onNavigate:i,getIcon:r,t:s})=>{const o=je();if(n)return e.jsx(et,{});if(t.length===0)return null;const l=new Map;for(const c of t){const a=c.group||s.home.recommendedBrowse;l.has(a)||l.set(a,[]),l.get(a).push(c)}return e.jsx(e.Fragment,{children:Array.from(l.entries()).map(([c,a])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:c}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(d=>{const p=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return e.jsxs("a",{href: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))})},ki=({progress:t,t:n,onNavigate:i})=>{if(!t)return e.jsx(et,{});const r=[...t.resources].sort((c,a)=>c.priority-a.priority),s=["in_progress","done","todo"],o={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},l={in_progress:"var(--bim-progress-active, #f59e0b)",done:"var(--bim-progress-done, #10b981)",todo:"var(--bim-progress-todo, #9ca3af)"};return e.jsx("div",{children:s.map(c=>{const a=r.filter(d=>d.status===c);return a.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:l[c]}}),o[c]," (",a.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(d=>e.jsx(Kl,{item:d,t:n,statusColor:l[c],onNavigate:i},d.id))})]},c)})})},Kl=({item:t,t:n,statusColor:i,onNavigate:r})=>{const s=je(),o=t.total>0?Math.round(t.imported/t.total*100):0,l=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const c=t.edition?`${t.name}·${t.edition}`:t.name,a=t.collection_id||t.work_id;return a&&r?e.jsx("a",{href:s(a),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(a))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:c}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:c}):c})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:l})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?Tt(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})]})},Jl=({progress:t,t:n,totalWorks:i})=>{if(!t)return e.jsx(et,{});const r=[...t.resources].sort((a,d)=>a.priority-d.priority),s=r.filter(a=>a.imported>0),o=r.filter(a=>a.imported===0),l=s.reduce((a,d)=>Math.max(a,d.imported),0),c=i>0?Math.round(l/i*100):0;return e.jsxs("div",{children:[i>0&&e.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)",fontSize:"13px",color:"var(--bim-fg, #333)"},children:[n.home.siteCoverage,": ",e.jsx("strong",{children:l.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",c,"%)"]}),s.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"var(--bim-progress-done, #10b981)"}}),n.home.statusInProgress," (",s.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(a=>e.jsx(wi,{item:a,t:n,totalWorks:i},a.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(a=>e.jsx(wi,{item:a,t:n,totalWorks:i},a.id))})]})]})},wi=({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})]})},_i="(max-width: 768px)";function ql(){const[t,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(_i).matches);return f.useEffect(()=>{const i=window.matchMedia(_i),r=s=>n(s.matches);return i.addEventListener("change",r),()=>i.removeEventListener("change",r)},[]),t}const Xl=({transport:t,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:r,headerRight:s})=>{var H;const o=N(),{convert:l}=M(),c=ql(),[a,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]=f.useState(null),[T,C]=f.useState(!1),k=f.useCallback(async A=>{if(!t.getCollatedEditionIndex){w(null);return}C(!0);try{const F=await t.getCollatedEditionIndex(A);w(F)}catch{w(null)}finally{C(!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([]),w(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&&k(A.id))}catch(F){console.error("加载详情失败:",F)}finally{u(!1)}},[t,i,z,k]),v=f.useCallback(async A=>{x(null),S([]),w(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&&k(A))}catch(F){console.error("导航失败:",F)}finally{u(!1)}},[t,z,k]),E=(p==null?void 0:p.type)==="collection"&&(h.length>0||m)||(p==null?void 0:p.type)==="work"&&(_||T),R=c&&(g||p),P=f.useCallback(()=>{d(null),x(null),S([]),w(null),y("detail")},[]),$=e.jsx(e.Fragment,{children:g?e.jsx(et,{}):p?e.jsxs(e.Fragment,{children:[(E||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:[E&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>y("detail"),style:At(b==="detail"),children:o.detailTab.basicInfo}),p.type==="collection"&&m&&h.length===0&&e.jsxs("button",{onClick:()=>{},style:At(!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:At(b===`catalog:${A.resource_id}`),children:A.short_name?`${l(A.short_name)}${o.detailTab.catalogSuffix}`:o.detailTab.collectionCatalog},A.resource_id)),p.type==="work"&&(_||T)&&e.jsxs("button",{onClick:()=>y("collated"),style:At(b==="collated"),children:[o.detailTab.collatedEdition,T&&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(En,{data:p,transport:t,onNavigate:v}):b.startsWith("catalog:")?e.jsx(Bn,{data:(H=h.find(A=>`catalog:${A.resource_id}`===b))==null?void 0:H.data,onNavigate:v}):b==="collated"?e.jsx(Vn,{index:_||void 0,workId:p.id,transport:t,onNavigate:v}):null})]}):e.jsx(Sn,{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:R?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",flexShrink:0},children:e.jsxs("button",{onClick:P,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(mn,{transport:t,onEntryClick:I,hideModeIndicator:n}),!p&&e.jsx(Sn,{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(mn,{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 At(t){return{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-primary, #0078d4)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}const Yr="guji-table-v1";function Kr(t){return!!t&&t.table_notation===Yr}const Zl=/^:::table(?:\{[^}]*\})?[ \t]*$/,Ql=/^:::[ \t]*$/;function Jr(t){const n=[];let i="";for(let r=0;r<t.length;r++){const s=t[r];let o=null;if(s==="⟨")o="⟩";else if(s==="<"){const l=t[r+1];l!==void 0&&!/[A-Za-z/!?>\s]/.test(l)&&(o=">")}if(o){const l=t.indexOf(o,r+1);if(l>0){i+=t.slice(r,l+1),r=l;continue}}s==="|"?(n.push(i),i=""):i+=s}return n.push(i),n.map(r=>r.trim())}const ea=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function ta(t){if(t==="^")return{cont:!0};const n=ea.exec(t),i=n[1].trim(),r=n[2]?Math.max(1,parseInt(n[2],10)):1,s=n[3]?Math.max(1,parseInt(n[3],10)):1,o=i==="_";return{cont:!1,cell:{text:o?"":i,empty:o,colspan:r,rowspan:s}}}function qr(t,n=1){const i=[],r=[],s=[];let o=[];t.forEach((c,a)=>{const d=a+n+1;let p=c.trim();if(!p)return;let x=!1;p.startsWith("!")&&(x=!0,p=p.slice(1));const g=Jr(p).map(ta),u=o.map(S=>S>0),b=o.map(S=>S>0?S-1:0),y=[];let h=0;for(const S of g){if(S.cont){u[h]||i.push(`第 ${d} 行第 ${h+1} 列:续格 ^ 上方没有跨行格`),h+=1;continue}const{cell:m}=S;for(let j=h;j<h+m.colspan;j++)if(u[j]){i.push(`第 ${d} 行第 ${j+1} 列:此处被上方跨行格占住,应写 ^`);break}if(m.rowspan>1)for(let j=h;j<h+m.colspan;j++)b[j]=m.rowspan-1;y.push(m),h+=m.colspan}for(let S=h;S<u.length;S++)u[S]&&i.push(`第 ${d} 行第 ${S+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let S=0;S<b.length;S++)b[S]===void 0&&(b[S]=0);o=b,r.push({header:x,cells:y}),s.push({width:h,line:d})});const l=s.reduce((c,a)=>Math.max(c,a.width),0);for(const c of s)c.width!==l&&i.push(`第 ${c.line} 行:占 ${c.width} 列,与总列数 ${l} 不符`);return o.some(c=>c>0)&&i.push("表尾:有跨行格超出了表的最后一行"),r.length===0&&i.push("空表"),{rows:r,columns:l,warnings:i}}function Xr(t){const n=t.split(`
|
|
100
|
-
`),i=[];let r=[];const
|
|
101
|
-
`);r=[],i.push({type:"text",text:l})};let
|
|
102
|
-
`)}),o=l+1;continue}}r.push(n[o]),o++}return s(),i.map((l,c)=>{var d,p;if(l.type!=="text")return l;let a=l.text;return((d=i[c-1])==null?void 0:d.type)==="table"&&(a=a.replace(/^\n+/,"")),((p=i[c+1])==null?void 0:p.type)==="table"&&(a=a.replace(/\n+$/,"")),{type:"text",text:a}}).filter(l=>l.type!=="text"||l.text!=="")}const na={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},ia={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},ra="1px solid var(--bim-table-border, color-mix(in srgb, currentColor 28%, transparent))",Zr={border:ra,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},oa={...Zr,background:"var(--bim-table-head-bg, color-mix(in srgb, currentColor 8%, transparent))",fontWeight:600};function Qr({table:t}){return e.jsx("div",{className:"bim-guji-table-wrap",style:na,children:e.jsx("table",{className:"bim-guji-table",style:ia,children:e.jsx("tbody",{children:t.rows.map((n,i)=>e.jsx("tr",{children:n.cells.map((r,s)=>{const o=n.header?"th":"td";return e.jsx(o,{colSpan:r.colspan>1?r.colspan:void 0,rowSpan:r.rowspan>1?r.rowspan:void 0,style:n.header?oa:Zr,children:r.empty?null:be(r.text)},s)})},i))})})})}function sa(t){return t.indexOf("**")<0?be(t):t.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((i,r)=>r%2===1?e.jsx("strong",{children:be(i.trim().slice(2,-2))},r):e.jsx(f.Fragment,{children:be(i)},r))}function eo(t,n){return n?Xr(t).map((i,r)=>i.type==="table"?e.jsx(Qr,{table:i.table},r):e.jsx(f.Fragment,{children:sa(i.text)},r)):be(t)}function Ue(t){return t.replace(/\.md$/,"")}function la(t){let n="";if(t.source_url)try{const r=new URL(t.source_url).pathname.split("/").filter(Boolean).pop()??"";n=decodeURIComponent(r).replace(/_/g," ")}catch{}return[t.source_name,n||t.version_label].filter(Boolean).join(" · ")||t.key}const cn={padding:24,color:"var(--bim-desc-fg, #999)"},kn=({index:t,bookId:n,transport:i,activeChapter:r,onChapterChange:s,workKey:o,versions:l,onVersionChange:c})=>{const[a,d]=f.useState(t??null),[p,x]=f.useState(!1),[g,u]=f.useState(null),b=r!==void 0?r:g,y=f.useCallback(C=>{s?s(C):u(C)},[s]),[h,S]=f.useState(null),[m,j]=f.useState(!1);f.useEffect(()=>{t&&d(t)},[t]),f.useEffect(()=>{if(t)return;d(null),x(!1);const C=o!==void 0?i.getWorkFullTextIndex?()=>i.getWorkFullTextIndex(n,o):null:i.getBookFullTextIndex?()=>i.getBookFullTextIndex(n):null;if(!n||!C){x(!0);return}let k=!1;return Promise.resolve().then(C).then(z=>{k||(z?d(z):x(!0))}).catch(()=>{k||x(!0)}),()=>{k=!0}},[n,i,t,o]),f.useEffect(()=>{if(!a||a.chapters.length===0)return;const C=Ue(a.chapters[0].file);if(!b){y(C);return}const k=Ue(b);a.chapters.some(I=>Ue(I.file)===k)||y(C)},[a,b,y]);const _=f.useMemo(()=>{if(!a||!b)return null;const C=Ue(b);return a.chapters.find(k=>Ue(k.file)===C)??null},[a,b]);f.useEffect(()=>{if(!n||!_)return;const C=o!==void 0?i.getWorkFullTextChapter?z=>i.getWorkFullTextChapter(n,o,z):null:i.getBookFullTextChapter?z=>i.getBookFullTextChapter(n,z):null;if(!C)return;let k=!1;return j(!0),S(null),Promise.resolve(_.file).then(C).then(z=>{k||S(z)}).catch(()=>{k||S(null)}).finally(()=>{k||j(!1)}),()=>{k=!0}},[n,_,i,o]);const w=l&&l.length>1&&c?e.jsx("div",{style:{marginBottom:12,fontSize:13,color:"var(--bim-desc-fg, #888)"},children:e.jsxs("label",{children:["版本:",e.jsx("select",{value:o,onChange:C=>c(C.target.value),style:{fontSize:13,fontFamily:"inherit"},children:l.map(C=>e.jsx("option",{value:C.key,children:la(C)},C.key))})]})}):null;if(!a)return p?e.jsxs("div",{style:cn,children:[w,"无法加载全文目录"]}):e.jsxs("div",{style:cn,children:[w,"加载全文目录…"]});if(a.chapters.length===0)return e.jsxs("div",{style:cn,children:[w,"全文目录为空"]});const T=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:a.version_label}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:a.chapters.map(C=>{const k=Ue(C.file),z=k===Ue(b??"");return e.jsx("li",{children:e.jsx("button",{onClick:()=>y(k),style:{display:"block",width:"100%",textAlign:"left",padding:"6px 12px",background:z?"var(--bim-primary-bg, #fdf4f4)":"transparent",border:"none",borderLeft:z?"3px solid var(--bim-primary, #8B0000)":"3px solid transparent",color:z?"var(--bim-primary, #8B0000)":"var(--bim-fg, #2c2c2c)",cursor:"pointer",fontSize:14,lineHeight:1.5},children:C.title})},C.file)})})]});return e.jsx(zr,{aside:T,children:e.jsxs("div",{children:[w,_&&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:_.title}),e.jsxs("div",{style:{marginTop:6,fontSize:12,color:"var(--bim-desc-fg, #888)"},children:["来源:",e.jsx("a",{href:a.source.url,target:"_blank",rel:"noreferrer",style:{color:"var(--bim-primary, #8B0000)"},children:a.source.name}),a.source.license&&e.jsxs(e.Fragment,{children:[" · ",a.source.license]})]})]}),m&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"加载中…"}),!m&&h&&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:eo(h.replace(/^##\s+[^\n]+\n+/,""),Kr(a))}),!m&&!h&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"无法加载章节内容"})]})})},aa=({data:t,onNavigate:n,className:i,style:r})=>{var p;const s=N(),{convert:o}=M(),[l,c]=f.useState(((p=t.divisions[0])==null?void 0:p.name)??null),[a,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(ca,{division:x,expanded:l===x.name,onToggle:()=>c(l===x.name?null:x.name),expandedCat:a,onCatToggle:g=>d(a===g?null:g),onNavigate:n},x.name))})]})},ca=({division:t,expanded:n,onToggle:i,expandedCat:r,onCatToggle:s,onNavigate:o})=>{const{convert:l}=M(),c=t.categories.reduce((a,d)=>{const p=d.stats||{zhulu:0,cunmu:0};return a+(p.zhulu||0)+(p.cunmu||0)},0);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)":"var(--bim-bg, #f8f8f8)",cursor:"pointer",fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsx("span",{children:l(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",c," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(a=>{const d=`${t.name}/${a.name}`;return e.jsx(da,{category:a,expanded:r===d,onToggle:()=>s(d),onNavigate:o},a.name)})})]})},da=({category:t,expanded:n,onToggle:i,onNavigate:r})=>{var a,d,p,x;const{convert:s}=M(),o=((a=t.books)==null?void 0:a.zhulu)||[],l=((d=t.books)==null?void 0:d.cunmu)||[],c=(((p=t.stats)==null?void 0:p.zhulu)||o.length)+(((x=t.stats)==null?void 0:x.cunmu)||l.length);return e.jsxs("div",{children:[e.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?"var(--bim-input-bg, #fff)":"transparent",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsxs("span",{style:{fontWeight:500},children:[s(t.name),t.volumes&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px",fontWeight:400},children:["卷",t.volumes]})]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[c," 部 ",n?"▲":"▼"]})]}),n&&(o.length>0||l.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[o.length>0&&e.jsx(Ci,{label:"著錄",books:o,onNavigate:r}),l.length>0&&e.jsx(Ci,{label:"存目",books:l,onNavigate:r})]})]})},Ci=({label:t,books:n,onNavigate:i})=>{const{convert:r}=M(),s=je(),[o,l]=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((a,d)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:a.work_id&&i?e.jsx("a",{href:s(a.work_id),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),i(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(a.title)}):r(a.title)}),a.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(a.volumes)}),a.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(a.author).slice(0,20)})]},d))}),!o&&e.jsxs("button",{onClick:()=>l(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},Te=({title:t,onSave:n,onAskAI:i,extraButtons:r,children:s})=>{const o=N();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,i&&e.jsx("button",{onClick:i,style:ua,children:"AI"}),n&&e.jsx("button",{onClick:n,style:pa,children:o.action.save})]})]}),s]})},pa={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},ua={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},ve=({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"}})]}),qe=({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"}})},Vt=({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 fa(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Mt=({value:t,onChange:n,label:i})=>{const[r,s]=f.useState(!1),o=f.useRef(null),l=fa(t||"");return f.useEffect(()=>{r&&o.current&&o.current.focus()},[r]),!r&&l?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Ti,children:i}),e.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",minHeight:"30px"},children:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:"var(--bim-fg, #333)"},children:l.name}),e.jsx(Vt,{children:l.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Ti,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"}})]})},Ti={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function xa(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 ga(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const to=({items:t,onChange:n,onOpenEntityPicker:i})=>{const r=N(),[s,o]=f.useState(null),l=()=>{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)},a=(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:xa(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:ga(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:Pe,children:r.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>d(g,"bookID"),style:{...Ii,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:{...Ii,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:Pe,children:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const u=[...t];u[g]={...u[g],type:"",id:"",name:""},n(u)},style:zi,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:Pe,children:r.label.sourceName}),e.jsx("button",{onClick:()=>{const u=[...t];u[g]={...u[g],type:"",id:"",name:""},n(u)},style:zi,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:u=>a(g,"name",u.target.value),placeholder:r.editor.sourceNamePlaceholder,style:tt})]}),e.jsxs("div",{children:[e.jsx("label",{style:Pe,children:r.label.urlAddress}),e.jsx("input",{type:"text",value:x.id,onChange:u=>a(g,"id",u.target.value),placeholder:"https://...",style:tt})]})]}),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:{...Pe,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:Pe,children:r.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:u=>a(g,"details",u.target.value),placeholder:r.editor.detailsPlaceholder,style:tt})]}),e.jsxs("div",{children:[e.jsx("label",{style:Pe,children:r.label.positionOptional}),e.jsx("input",{type:"text",value:x.position,onChange:u=>a(g,"position",u.target.value),placeholder:"如: 卷三, p.52",style:tt})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:Pe,children:r.label.dataVersionOptional}),e.jsx("input",{type:"text",value:x.version,onChange:u=>a(g,"version",u.target.value),placeholder:"如: v1.0, 2024-01",style:tt})]}),e.jsxs("div",{children:[e.jsx("label",{style:Pe,children:r.label.processorVersionOptional}),e.jsx("input",{type:"text",value:x.processor_version,onChange:u=>a(g,"processor_version",u.target.value),placeholder:"如: v0.1",style:tt})]})]})]})]})})]},g)),e.jsxs("button",{onClick:l,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:r.action.addSource})]})]})},Pe={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},tt={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"},Ii={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"},zi={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function no(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 io(t){return!t||t.length===0?"":JSON.stringify(t)}const ro=({entityType:t,entityId:n,entityTitle:i,parentWork:r,parentCollection:s,belongsToWork:o,belongsToCollection:l,childWorks:c,childCollections:a,containedBooks:d,siblingBooks:p,onLinkEntity:x,onUnlinkEntity:g,onViewEntity:u,onCreateAndLink:b,onSaveRelations:y})=>{const h=N();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:h.section.relations})]}),y&&e.jsx("button",{onClick:y,style:ma,children:h.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(gt,{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(gt,{direction:"up",title:h.relation.containedInCollection,entity:l,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(nt,{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(gt,{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(nt,{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}),a&&a.length>0&&e.jsx(nt,{direction:"down",title:`${h.relation.collectionImpl} (${a.length})`,entities:a,onView:u,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:h.action.addCollectionImpl,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),e.jsx(nt,{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(gt,{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(gt,{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(nt,{direction:"down",title:`${h.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:u,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:h.action.addSubCollection,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),e.jsx(nt,{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})]})]})]})},gt=({direction:t,title:n,entity:i,onView:r,onUnlink:s,onLink:o,onCreate:l,linkLabel:c,createLabel:a,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:oo(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(Ri,{onClick:()=>r(i),title:p,children:"👁️"}),e.jsx(Ri,{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(wn,{onClick:o,children:c}),e.jsx(wn,{onClick:l,primary:!0,children:a})]})]})},nt=({direction:t,title:n,entities:i,onView:r,onAdd:s,addLabel:o,noneLabel:l,expandMoreLabel:c})=>{const[a,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=a?i:i.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:p,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children: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:oo(u.type)}),e.jsx("span",{children:u.title})]},u.id)),i.length>5&&!a&&e.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[c," (",i.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:l}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(wn,{onClick:s,primary:!0,children:["+ ",o]})})]})},Ri=({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}),wn=({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 oo(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const ma={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"},so=({isOpen:t,entityType:n,title:i,onSelect:r,onCancel:s,onCreate:o,searchResults:l,onSearch:c,isLoading:a,excludeId:d})=>{const[p,x]=f.useState(""),g=d?l.filter(h=>h.id!==d):l;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:ha,children:e.jsxs("div",{style:ba,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:ya,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:va})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?e.jsx("div",{style:dn,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:ja,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:dn,children:["未找到匹配的",b]}):e.jsxs("div",{style:dn,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:Sa,children:["创建新",b,"并关联"]})]})]})})},ha={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},ba={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)"},ya={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},va={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"},ja={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},dn={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},Sa={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Ei={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},ka={work:"📜",book:"📖",collection:"📚",entity:"👤"},lo=({isOpen:t,entityType:n,relationField:i,inheritData:r,onConfirm:s,onCancel:o})=>{const[l,c]=f.useState(""),a=f.useRef(null);f.useEffect(()=>{t&&(c((r==null?void 0:r.title)||""),setTimeout(()=>{var g,u;(g=a.current)==null||g.focus(),(u=a.current)==null||u.select()},100))},[t,r==null?void 0:r.title]);const d=g=>{g.key==="Enter"&&l.trim()?p():g.key==="Escape"&&o()},p=()=>{l.trim()&&s(l.trim(),{...r,title:l.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`创建新${Ei[n]}`}};return e.jsx("div",{style:wa,onClick:g=>{g.target===g.currentTarget&&o()},children:e.jsxs("div",{style:_a,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:ka[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:a,type:"text",value:l,onChange:g=>c(g.target.value),onKeyDown:d,placeholder:`请输入${Ei[n]}名称...`,style:Ca})]}),((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:Ta,children:"取消"}),e.jsx("button",{onClick:p,disabled:!l.trim(),style:{...Ia,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},wa={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},_a={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)"},Ca={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"},Ta={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Ia={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function za(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function ao(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Ra(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 co=({isOpen:t,title:n,filterType:i="all",recentEntities:r=[],excludeId:s,showCreateButton:o=!1,createButtonText:l,onSelect:c,onCancel:a,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 k=setTimeout(async()=>{h(!0);try{b(await p(x,i))}catch{b([])}finally{h(!1)}},300);return()=>clearTimeout(k)},[x,i,p]);const j=f.useCallback(k=>{g(k.target.value),k.target.value.trim()&&m("search")},[]),_=f.useCallback(k=>s?k.filter(z=>z.id!==s):k,[s]);if(!t)return null;const w=n||(i==="all"?"选择实体":`选择${ao(i)}`),T=_(r),C=_(u);return e.jsx("div",{style:Ba,children:e.jsxs("div",{style:La,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:w}),e.jsx("button",{onClick:a,style:Wa,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:$a}),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:"搜索中..."})]})}),T.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(Bi,{active:S==="recent",onClick:()=>m("recent"),children:["最近使用 (",T.length,")"]}),e.jsxs(Bi,{active:S==="search",onClick:()=>m("search"),children:["搜索结果 ",C.length>0&&`(${C.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:S==="recent"&&T.length>0?e.jsx(Li,{entities:T,onSelect:c}):x.trim()?y?e.jsx(pn,{message:"搜索中..."}):C.length>0?e.jsx(Li,{entities:C,onSelect:c}):e.jsx(pn,{message:"未找到匹配的结果"}):e.jsx(pn,{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:Aa,children:l||"创建新实体"})]})]})})},Bi=({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}),Li=({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:za(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:Ra(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:ao(t.type)})]})},pn=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),Ba={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},La={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)"},Wa={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},$a={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"},Aa={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Fa={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)"},Pa={work:"📜",collection:"📚",book:"📖",entity:"👤"},po=({data:t,onChange:n,onSave:i,transport:r,onNavigate:s,showDelete:o,onDelete:l,onAskAI:c,renderSectionActions:a,onDownloadResource:d,downloadStatuses:p,relations:x,onRelationsChange:g})=>{var ee;const u=N(),[b,y]=f.useState(!1),[h,S]=f.useState("work"),[m,j]=f.useState(""),[_,w]=f.useState(""),[T,C]=f.useState([]),[k,z]=f.useState(!1),[I,v]=f.useState(!1),[E,R]=f.useState("work"),[P,$]=f.useState(""),[H,A]=f.useState(),[F,q]=f.useState(!1),[W,K]=f.useState(null),[ie,Y]=f.useState([]);f.useRef(null);const L=t.type,J=L==="work",X=L==="collection",G=L==="book",U=f.useCallback((B,Q)=>{n({...t,[B]:Q})},[t,n]),ce=f.useCallback((B,Q)=>{j(B),S(Q),w(u.editor.selectToLink+u.indexType[Q]),C([]),y(!0)},[u]),we=f.useCallback(B=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,B)},[r,t.id]),fe=f.useCallback(B=>{s==null||s(B.id,B.type)},[s]),ae=f.useCallback((B,Q,le)=>{const oe={...le,author:(le==null?void 0:le.author)||t.author,dynasty:le==null?void 0:le.dynasty};R(Q),$(B),A(oe),v(!0)},[t.author]),Se=f.useCallback((B,Q)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,P,{type:E,title:B,inheritData:Q}),v(!1)},[r,t.id,P,E]),Ee=f.useCallback(B=>{if(!B.trim()){C([]);return}z(!0),r!=null&&r.searchEntities&&r.searchEntities(B,h).then(Q=>{C(Q),z(!1)}).catch(()=>{C([]),z(!1)})},[r,h]),dt=f.useCallback(B=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,m,B.id),y(!1)},[r,t.id,m]),Fe=f.useCallback(()=>{i()},[i]),Be=f.useCallback(B=>{K(()=>B),q(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(Y).catch(()=>{})},[r]),D=f.useCallback((B,Q)=>r!=null&&r.searchEntities?r.searchEntities(B,Q==="all"?void 0:Q):Promise.resolve([]),[r]),se=f.useCallback(B=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(B),Y(Q=>[B,...Q.filter(le=>le.id!==B.id)].slice(0,10)),W==null||W(B),q(!1),K(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:Pa[L]}),e.jsx("span",{children:t.title||u.editor.untitled}),e.jsx(Vt,{children:t.id}),e.jsx(Vt,{color:Fa[L],children:u.indexType[L]})]})}),e.jsx(Te,{title:u.section.basicInfo,onSave:i,onAskAI:c?()=>c("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(Mt,{label:J?u.editor.workTitle:X?u.editor.collectionTitle:u.editor.bookTitle,value:t.title,onChange:B=>U("title",B)}),G&&e.jsx(Mt,{label:u.editor.belongsToWork,value:t.workName||"",onChange:B=>U("workName",B)}),e.jsx(ve,{label:u.editor.authorLabel,value:t.author||"",onChange:B=>U("author",B)}),e.jsx(ve,{label:u.editor.publicationYearLabel,value:t.publicationYear||"",onChange:B=>U("publicationYear",B)}),(G||X)&&e.jsx(Mt,{label:u.editor.containedIn,value:t.collection||"",onChange:B=>U("collection",B)}),(G||X)&&e.jsx(ve,{label:u.editor.holderLabel,value:t.holder||"",onChange:B=>U("holder",B)}),(G||X)&&e.jsx(ve,{label:G?u.editor.pageLabel:u.editor.volumeLabel,value:t.pages||"",onChange:B=>U("pages",B)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(ve,{label:u.editor.firstImageLabel,value:t.firstImage||"",onChange:B=>U("firstImage",B)})})]})}),e.jsx(Te,{title:u.section.description,onSave:i,onAskAI:c?()=>c("介绍"):void 0,children:e.jsx(qe,{value:t.description||"",onChange:B=>U("description",B),placeholder:u.editor.descriptionPlaceholder})}),(((ee=t.additional_works)==null?void 0:ee.length)||0)>0&&e.jsx(Te,{title:u.section.additionalWorks,onSave:i,children:e.jsx(Ma,{items:t.additional_works||[],onChange:B=>U("additional_works",B)})}),e.jsx(Te,{title:u.section.indexedBy,onSave:i,onAskAI:c?()=>c("收录于"):void 0,children:e.jsx(Oa,{items:t.indexed_by||[],onChange:B=>U("indexed_by",B)})}),e.jsx(Te,{title:u.section.emendatedBy,onSave:i,onAskAI:c?()=>c("考证"):void 0,children:e.jsx(Ha,{items:t.emendated_by||[],onChange:B=>U("emendated_by",B)})}),e.jsx(Te,{title:u.section.textResources,onSave:i,onAskAI:c?()=>c("资源"):void 0,children:e.jsx(gn,{items:t.resources||[],onChange:B=>U("resources",B),onDownload:d,downloadStatuses:p,filterType:"text"})}),e.jsx(Te,{title:u.section.imageResources,onSave:i,children:e.jsx(gn,{items:t.resources||[],onChange:B=>U("resources",B),onDownload:d,downloadStatuses:p,filterType:"image"})}),e.jsx(Te,{title:u.section.sources,onSave:i,onAskAI:c?()=>c("资料来源"):void 0,children:e.jsx(to,{items:no(t.sources||""),onChange:B=>U("sources",io(B)),onOpenEntityPicker:Be})}),(G||X)&&e.jsx(Te,{title:u.section.provenance,onSave:i,onAskAI:c?()=>c("收藏历史"):void 0,children:e.jsx(qe,{value:t.provenance||"",onChange:B=>U("provenance",B),placeholder:u.editor.provenancePlaceholder})}),G&&e.jsx(Te,{title:u.section.otherEditions,onSave:i,onAskAI:c?()=>c("其他版本"):void 0,children:e.jsx(qe,{value:t.otherEditions||"",onChange:B=>U("otherEditions",B),placeholder:u.editor.otherEditionsPlaceholder})}),e.jsx(ro,{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:ce,onUnlinkEntity:we,onViewEntity:fe,onCreateAndLink:ae,onSaveRelations:Fe}),o&&l&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:u.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:u.editor.dangerZoneDesc}),e.jsx("button",{onClick:l,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:u.editor.deleteEntity})]}),e.jsx(so,{isOpen:b,entityType:h,title:_,onSelect:dt,onCancel:()=>y(!1),onCreate:()=>{y(!1),ae(m,h)},searchResults:T,onSearch:Ee,isLoading:k,excludeId:t.id}),e.jsx(lo,{isOpen:I,entityType:E,relationField:P,inheritData:H,onConfirm:Se,onCancel:()=>v(!1)}),e.jsx(co,{isOpen:F,title:u.action.selectBookOrWork,filterType:"all",recentEntities:ie,excludeId:t.id,onSelect:se,onCancel:()=>{q(!1),K(null)},onSearch:D})]})};function Ma({items:t,onChange:n}){const i=N(),r=(l,c,a)=>{const d=t.map((p,x)=>x===l?{...p,[c]:a}:p);n(d)},s=l=>n(t.filter((c,a)=>a!==l)),o=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((l,c)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(ve,{label:i.editor.bookNameLabel,value:l.book_title,onChange:a=>r(c,"book_title",a)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(ve,{label:i.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:a=>r(c,"n_juan",a&&parseInt(a,10)||void 0)})}),e.jsx("button",{onClick:()=>s(c),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"var(--bim-muted, #999)",marginTop:"18px"},children:"✕"})]},c)),e.jsx("button",{onClick: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 uo({items:t,onChange:n,showMeta:i,addLabel:r}){const s=N(),[o,l]=f.useState(null),c=(p,x,g)=>{const u=t.map((b,y)=>y===p?{...b,[x]:g||void 0}:b);n(u)},a=p=>{n(t.filter((x,g)=>g!==p)),o===p&&l(null)},d=()=>{n([...t,{source:""}]),l(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((p,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:()=>l(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(),a(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(ve,{label:s.label.sourceName,value:p.source,onChange:u=>c(x,"source",u)}),e.jsx(ve,{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(ve,{label:s.label.titleInfo,value:p.title_info||"",onChange:u=>c(x,"title_info",u)}),e.jsx(ve,{label:s.label.authorInfo,value:p.author_info||"",onChange:u=>c(x,"author_info",u)})]}),e.jsx(ve,{label:s.label.edition,value:p.edition||"",onChange:u=>c(x,"edition",u)})]}),e.jsx(qe,{value:p.summary||"",onChange:u=>c(x,"summary",u),placeholder:s.editor.summaryPlaceholder}),e.jsx(qe,{value:p.comment||"",onChange:u=>c(x,"comment",u),placeholder:s.editor.commentPlaceholder}),e.jsx(qe,{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=N();return e.jsx(uo,{items:t,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function Ha({items:t,onChange:n}){const i=N();return e.jsx(uo,{items:t,onChange:n,addLabel:i.action.addEmendatedBy})}function fo(t){var c,a,d,p,x,g,u;const n=((a=(c=t.authors)==null?void 0:c[0])==null?void 0:a.name)||"",i=((d=t.publication_info)==null?void 0:d.year)||"",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||"",l={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&&(l.parentWorkId=y.id,l.parentWorkName=y.title)}}if(t.type==="book"){const b=t;l.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(l.collectionId=(u=b.contained_in[0])==null?void 0:u.id)}return l}function Da(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 Na=t=>{const{data:n,id:i,transport:r,mode:s="view",onModeChange:o,onChange:l,onSave:c,onDelete:a,onNavigate:d,renderLink:p,onAskAI:x,renderSectionActions:g,onDownloadResource:u,downloadStatuses:b,relations:y,onRelationsChange:h,headerExtra:S,className:m,style:j}=t;N();const[_,w]=f.useState(s),T=o?s:_;f.useEffect(()=>{s!==_&&w(s)},[s]);const C=f.useCallback(()=>{const P=T==="view"?"edit":"view";o?o(P):w(P)},[T,o]),[k,z]=f.useState(null);f.useEffect(()=>{i&&r&&r.getItem(i).then(P=>{P&&z(P)})},[i,r]);const I=n||k,v=f.useMemo(()=>I?fo(I):null,[I]),E=o||!n?e.jsx("button",{onClick:C,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:T==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:T==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:T==="view"?"切换到编辑模式":"切换到查看模式",children:T==="view"?"✏️ 编辑":"👁 查看"}):null,R=e.jsxs(e.Fragment,{children:[E,S]});return!I&&!v?e.jsx(et,{}):T==="view"?e.jsx(En,{data:I,transport:r,onNavigate:d?P=>d(P):void 0,renderLink:p,headerExtra:R,className:m,style:j}):v?e.jsxs("div",{className:m,style:j,children:[R&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:R}),e.jsx(po,{data:v,onChange:l||(()=>{}),onSave:c||(()=>{}),transport:r,onNavigate:d,showDelete:!!a,onDelete:a,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:"无数据"})},Wi=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],xo=({isOpen:t,onClose:n,onSubmit:i,feedbackListUrl:r})=>{const[s,o]=f.useState(null),[l,c]=f.useState(""),[a,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||!l.trim())){x("submitting"),u("");try{await i({type:s,content:l.trim(),...a.trim()?{contact:a.trim()}:{}}),x("success")}catch(m){x("error"),u(m instanceof Error?m.message:"提交失败,请稍后重试")}}};if(!t)return null;const h=s&&l.trim()&&p!=="submitting",S=Wi.find(m=>m.value===s);return e.jsx("div",{style:Va,onClick:m=>{m.target===m.currentTarget&&n()},children:e.jsxs("div",{style:Ga,onClick:m=>m.stopPropagation(),children:[e.jsxs("div",{style:Ua,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:Ya,"aria-label":"关闭",children:"✕"})]}),p==="success"?e.jsxs("div",{style:Za,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:Wi.map(m=>e.jsxs("button",{onClick:()=>o(m.value),style:{...Ka,...s===m.value?Ja:{}},children:[e.jsx("span",{children:m.icon})," ",m.label]},m.value))}),e.jsx("textarea",{ref:b,value:l,onChange:m=>c(m.target.value),placeholder:(S==null?void 0:S.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||p==="submitting",style:{...qa,opacity:s?1:.6}}),e.jsx("input",{type:"text",value:a,onChange:m=>d(m.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||p==="submitting","aria-label":"联系方式(选填)",style:ec}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[l.length," / 2000"]}),p==="error"&&e.jsx("div",{style:Qa,children:g}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:y,disabled:!h,style:{...Xa,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交反馈"})})]})]})})},Va={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},Ga={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)"},Ua={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Ya={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},Ka={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"},Ja={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},qa={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"},Xa={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Za={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},Qa={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},ec={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"},tc=({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:{...nc,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(xo,{isOpen:r,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:i})]})},nc={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"},$i=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],go=({onSubmit:t})=>{const[n,i]=f.useState("bug"),[r,s]=f.useState(""),[o,l]=f.useState(""),[c,a]=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())){a("submitting"),p("");try{await t({type:n,content:r.trim(),...o.trim()?{contact:o.trim()}:{}}),a("success"),s(""),l(""),i("bug")}catch(y){a("error"),p(y instanceof Error?y.message:"提交失败,请稍后重试")}}},u=n&&r.trim()&&c!=="submitting",b=$i.find(y=>y.value===n);return c==="success"?e.jsx("div",{style:Ai,children:e.jsxs("div",{style:lc,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>a("idle"),style:ac,children:"继续提交"})]})}):e.jsxs("div",{style:Ai,children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:$i.map(y=>e.jsxs("button",{onClick:()=>i(y.value),style:{...ic,...n===y.value?rc:{}},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:{...oc}}),e.jsx("input",{type:"text",value:o,onChange:y=>l(y.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:c==="submitting","aria-label":"联系方式(选填)",style:dc}),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:{...sc,opacity:u?1:.6,cursor:u?"pointer":"not-allowed"},children:c==="submitting"?"提交中...":"提交"})]}),c==="error"&&e.jsx("div",{style:cc,children:d})]})},Ai={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},ic={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"},rc={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},oc={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"},sc={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},lc={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},ac={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},cc={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"},dc={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 Fi(t){return typeof t=="function"?t():t??"/api/feedback"}const mo=({resourceId:t,apiUrl:n})=>{const[i,r]=f.useState([]),[s,o]=f.useState(!0),l=f.useCallback(async()=>{const a=Fi(n);o(!0);try{const p=await(await fetch(`${a}?resourceId=${encodeURIComponent(t)}`)).json();p.success&&r(p.items)}catch{}finally{o(!1)}},[t,n]);f.useEffect(()=>{l()},[l]);const c=async a=>{const d=Fi(n),p=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,pageUrl:typeof window<"u"?window.location.href:"",resourceId:t})});if(!p.ok){const x=await p.json().catch(()=>null);throw new Error((x==null?void 0:x.error)||"提交失败")}setTimeout(()=>l(),500)};return e.jsxs("div",{children:[e.jsx(Gn,{items:i,loading:s}),e.jsx("div",{style:{marginTop:"24px"},children:e.jsx(go,{onSubmit:c})})]})},bt={versions:12,catalogs:8,chips:12},ho={leadWidth:22,metaWidth:424,mainLabel:"版本名稱",columns:[{label:"刊刻年代",width:"118px"},{label:"影印圖源",width:"156px"},{label:"收藏機構",width:"138px"}]},bo=({data:t,transport:n,onNavigate:i,renderLink:r,lineageAction:s,collatedSection:o})=>{var E,R,P,$,H,A,F,q,W,K,ie,Y;const l=N(),{convert:c}=M(),a=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",_=f.useMemo(()=>j?a:a.slice(0,bt.versions),[a,j]);f.useEffect(()=>{if(!n||_.length===0)return;const L=_.filter(X=>!d.has(X));if(L.length===0)return;let J=!1;return Promise.all(L.map(X=>n.getItem(X).then(G=>{const U=G??{};return[X,{id:X,title:U.title,edition:U.edition,resources:U.resources,publication_info:U.publication_info,current_location:U.current_location,lineage:U.lineage}]}).catch(()=>[X,{id:X}]))).then(X=>{J||p(G=>{const U=new Map(G);for(const[ce,we]of X)U.set(ce,we);return U})}),()=>{J=!0}},[n,_,d]);const w=f.useMemo(()=>a.map(L=>d.get(L)??{id:L}),[a,d]),T=f.useMemo(()=>Sr(w,t.version_graph,{era:u,scanOnly:y,sort:S}),[w,t.version_graph,u,y,S]),C=x?T.rows:T.rows.slice(0,bt.versions),k=f.useMemo(()=>Kt(t.resources,t.resource_groups),[t.resources,t.resource_groups]),z=f.useMemo(()=>vr((t.related_works||[]).map(L=>({id:L.id,title:L.title,relation:L.relation}))),[t.related_works]),I=f.useMemo(()=>{var U,ce,we,fe;const L=[],J=(ce=(U=t.authors)==null?void 0:U[0])==null?void 0:ce.dynasty;J&&L.push({label:"成書",value:c(J)});const X=Ze(t,l.unit.juan);if(X){const ae=(we=t.juan_count)==null?void 0:we.description;L.push({label:"卷帙",value:c(X),title:ae?c(ae):void 0})}const G=T.allRows.filter(ae=>ae.sortYear!=null);if(G.length>0){const ae=G.reduce((Se,Ee)=>Se.sortYear<=Ee.sortYear?Se:Ee);ae.era.era&&L.push({label:"最早存世刻本",value:`${ae.era.era}${ae.era.reign?" "+ae.era.reign:""}`,title:ae.era.source==="edition"?"據版本題名推斷":void 0})}return(fe=t.indexed_by)!=null&&fe.length&&L.push({label:"著錄",value:`${t.indexed_by.length} ${l.unit.bu}`}),L},[t,c,l,T.allRows,j,a.length]),v=!o&&a.length===0&&k.buckets.length===0&&k.mirrors.length===0&&!((E=t.indexed_by)!=null&&E.length)&&!((R=t.emendated_by)!=null&&R.length)&&z.length===0&&!((P=t.description)!=null&&P.text);return e.jsxs(e.Fragment,{children:[e.jsxs(zt,{facts:I.length?e.jsx(Rt,{items:I}):void 0,children:[(($=t.description)==null?void 0:$.text)&&e.jsxs(e.Fragment,{children:[e.jsx(Oe,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}),(H=t.description.sources)!=null&&H.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(ol(L))).filter(Boolean).join(" · ")}):null]}),(A=t.appendix)==null?void 0:A.map((L,J)=>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(Oe,{text:L.text,plainStrong:!0,style:{marginTop:10,fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"}})]},J)),e.jsx(Mr,{rows:[{label:l.section.aliases,items:_t(t.additional_titles)},{label:l.section.attachedTexts,items:_t(t.attached_texts)},{label:l.section.appendix,items:(t.additional_works||[]).map(L=>L.book_title+(L.n_juan!=null?` ${L.n_juan}${l.unit.juan}`:""))}]})]}),o,a.length>0&&e.jsxs(Re,{children:[e.jsx(xe,{glyph:"版",title:l.section.relatedVersions,count:T.rows.length===T.allRows.length?`${T.allRows.length} 種`:`${T.allRows.length} 種 · 當前 ${T.rows.length} 種`,actions:e.jsxs(e.Fragment,{children:[s,e.jsx(Ne,{label:"僅看有影印",active:y,dashed:!0,onClick:()=>{h(L=>!L),g(!1)}}),e.jsx(Jt,{label:S==="default"?"排序:預設順序":"排序:年代先後",onClick:()=>m(L=>L==="default"?"year":"default")})]})}),T.allRows.length>=6&&T.eras.length>=2&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:14},children:[e.jsx(Ne,{label:l.catalog.all,active:!u,onClick:()=>{b(""),g(!1)}}),T.eras.map(L=>e.jsx(Ne,{label:L,active:u===L,onClick:()=>{b(L),g(!1)}},L))]}),e.jsxs(Qe,{children:[e.jsx(Xt,{spec:ho}),C.map((L,J)=>e.jsx(fc,{row:L,no:J,onNavigate:i,renderLink:r},L.id)),C.length===0&&e.jsx(lt,{children:u||y?"當前篩選下沒有版本":"暫無版本著錄"})]}),T.rows.length>C.length&&e.jsx(Ve,{label:`展開其餘 ${T.rows.length-C.length} 種版本`,onClick:()=>g(!0)}),T.hasInferredEra&&e.jsx("div",{className:"bim-d-ui",style:{marginTop:10,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:"部分刊刻年代據版本題名推斷,非著錄原文"})]}),(k.buckets.length>0||k.mirrors.length>0)&&e.jsxs(Re,{children:[e.jsx(xe,{glyph:"源",title:"在線數字資源"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(210px, 1fr))",gap:26},children:[k.mirrors.map(L=>e.jsx(yn,{title:c(L.label),tag:L.description?c(L.description):void 0,children:L.items.map((J,X)=>e.jsx(st,{item:J,siblings:L.items},`${J.id||J.url||J.name}-${X}`))},L.key)),k.buckets.map(L=>e.jsx(yn,{title:pc[L.key],tag:uc[L.key],children:L.items.map((J,X)=>e.jsx(st,{item:J,siblings:L.items},`${J.id||J.url||J.name}-${X}`))},L.key))]})]}),(F=t.indexed_by)!=null&&F.length||(q=t.emendated_by)!=null&&q.length?e.jsxs("div",{className:(W=t.emendated_by)!=null&&W.length?"bim-d-pair":void 0,style:(K=t.emendated_by)!=null&&K.length?void 0:{marginBottom:48},children:[(ie=t.indexed_by)!=null&&ie.length?e.jsx(Mi,{id:"catalogs",glyph:"目",title:l.section.indexed,items:t.indexed_by,unit:l.unit.bu,cap:bt.catalogs,showMeta:!0,t:l,convert:c,onNavigate:i,renderLink:r}):null,(Y=t.emendated_by)!=null&&Y.length?e.jsx(Mi,{id:"studies",glyph:"考",title:l.section.emendated,items:t.emendated_by,unit:l.unit.bu,cap:bt.catalogs,t:l,convert:c,onNavigate:i,renderLink:r}):null]}):null,z.map(L=>e.jsx(xc,{glyph:L.key==="derivative"?"續":"叢",title:l.section[L.labelKey]??l.section.relatedWorks,items:L.items,convert:c,onNavigate:i,renderLink:r},L.key)),v&&e.jsxs(Re,{style:{marginBottom:0},children:[e.jsx(xe,{glyph:"著",title:l.section.relatedVersions}),e.jsx(Qe,{children:e.jsx(lt,{children:"尚未著錄該作品的版本、資源與書目收錄。"})})]})]})},pc={text:"文字全文庫",image:"影印資源",textImage:"圖文對照",physical:"館藏"},uc={text:"純文本",image:"原卷掃描",textImage:"圖文對照",physical:"實體"};function fc({row:t,no:n,onNavigate:i,renderLink:r}){const{convert:s}=M(),o=[t.era.era,t.era.reign].filter(Boolean).join(" · "),l=t.era.source==="edition";return e.jsx(Zt,{no:Qt(n),spec:ho,main:e.jsx(ze,{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:l?"據版本題名推斷":void 0,children:o||e.jsx(ot,{})}),e.jsx(Pi,{items:t.images,convert:s}),e.jsx(Pi,{items:t.holders,convert:s,fallback:t.locationName})]})})}function Pi({items:t,convert:n,fallback:i}){if(t.length===0)return i?e.jsx("span",{style:{minWidth:0},children:n(i)}):e.jsx(ot,{});if(t.length===1){const l=t[0],c=(l.url?kt(l.url):void 0)||n(l.name),a=Ht(l);return e.jsx("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},children:a?e.jsx(vn,{href:a,children:c}):c})}const r=t[0],s=(r.url?kt(r.url):void 0)||n(r.name),o=Ht(r);return e.jsxs("span",{style:{minWidth:0},children:[o?e.jsx(vn,{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 Mi({id:t,glyph:n,title:i,items:r,unit:s,cap:o,showMeta:l,t:c,convert:a,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(xe,{glyph:n,tone:"ink",title:i,count:`${r.length} ${s}`,actions:e.jsx(Jt,{label:y?"收起全部":"+ 展開提要",onClick:h})}),e.jsx(Qe,{children:S.map((m,j)=>{const _=m;return e.jsxs(Wr,{open:!!x[j],onToggle:()=>g(w=>({...w,[j]:!w[j]})),main:e.jsxs(e.Fragment,{children:[_.source_bid?e.jsx(ze,{id:_.source_bid,label:a(_.source),onNavigate:d,renderLink:p,dense:!0}):a(_.source),l&&_.section&&e.jsx("span",{className:"bim-d-ui",style:{marginLeft:8,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:a(_.section)})]}),action:_.source_bid?e.jsx(ze,{id:_.source_bid,label:c.action.view,onNavigate:d,renderLink:p,dense:!0,style:{fontFamily:"var(--bim-font-ui, system-ui, sans-serif)",fontSize:11.5,color:"var(--bim-meta-fg, #7b6a54)"}}):void 0,children:[l&&(_.title_info||_.author_info||_.edition)&&e.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:"4px 16px",marginBottom:8,fontSize:12,color:"var(--bim-meta-fg, #7b6a54)"},children:[_.title_info&&e.jsxs("span",{children:[c.label.titleInfo," ",a(_.title_info)]}),_.author_info&&e.jsxs("span",{children:[c.label.authorInfo," ",a(_.author_info)]}),_.edition&&e.jsxs("span",{children:[c.label.edition," ",a(_.edition)]})]}),_.summary&&e.jsx(Pt,{children:be(a(_.summary))}),_.comment&&e.jsx(Pt,{label:c.section.comment,children:be(a(_.comment))}),_.additional_comment&&e.jsx(Pt,{label:c.section.additionalComment,children:be(a(_.additional_comment))}),l&&_.page&&e.jsx("div",{className:"bim-d-ui",style:{fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:_.page})]},j)})}),r.length>S.length&&e.jsx(Ve,{label:`展開其餘 ${r.length-S.length} ${s}`,onClick:()=>b(!0)})]})}function xc({glyph:t,title:n,items:i,convert:r,onNavigate:s,renderLink:o}){const[l,c]=f.useState(!1),a=l?i:i.slice(0,bt.chips);return e.jsxs(Re,{style:{marginBottom:44},children:[e.jsx(xe,{glyph:t,tone:"ink",title:n,count:`${i.length} 種`}),e.jsxs(qt,{children:[a.map(d=>e.jsx(Et,{children:e.jsx(ze,{id:d.id,label:r(d.title),onNavigate:s,renderLink:o,dense:!0,style:{color:"inherit"}})},d.id)),i.length>a.length&&e.jsx(Ve,{inline:!0,label:`更多 ${i.length-a.length} 種`,onClick:()=>c(!0)})]})]})}const gc=8,yo=({data:t,transport:n,onNavigate:i,renderLink:r,fullTextSection:s})=>{var _,w,T,C;const o=N(),{convert:l}=M(),[c,a]=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){a(null);return}let k=!1;return n.getItem(t.work_id).then(z=>{!k&&z&&z.type==="work"&&a(z)}).catch(()=>{}),()=>{k=!0}},[n,t.work_id]),f.useEffect(()=>{const k=t.contained_in||[];if(!n||k.length===0){p(new Map);return}let z=!1;return Promise.all(k.map(I=>{const v=typeof I=="string"?I:I.id;return n.getItem(v).then(E=>[v,E]).catch(()=>[v,null])})).then(I=>{if(z)return;const v=new Map;for(const[E,R]of I)R&&v.set(E,R);p(v)}),()=>{z=!0}},[n,t.contained_in]);const y=f.useMemo(()=>{const k=new Set([...(c==null?void 0:c.books)||[],...t.related_books||[]]);return k.delete(t.id),[...k]},[c==null?void 0:c.books,t.related_books,t.id]);f.useEffect(()=>{if(!n||y.length===0){g([]);return}const k=u?y:y.slice(0,gc);let z=!1;return Promise.all(k.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(()=>Kt(t.resources,t.resource_groups),[t.resources,t.resource_groups]),S=f.useMemo(()=>{var P,$,H;const k=[],z=It(t),I=Tr(t);I&&k.push({label:"版本類型",value:I,title:(P=t.lineage)!=null&&P.category?void 0:"據版本題名推斷"}),(z.era||z.reign)&&k.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"?[]:jt(A.volume_index));v.length&&(k.push({label:"冊數",value:`${v.length} ${o.unit.volume}`}),k.push({label:"冊次",value:`第 ${Pn(v,o.unit.volume)} ${o.unit.volume}`}));const E=Ze(t,o.unit.juan);E&&k.push({label:"卷帙",value:l(E)});const R=(t.resources||[]).filter(A=>(A.types||(A.type?[A.type]:[])).includes("physical"));return R.length?k.push({label:"存藏",value:R.slice(0,2).map(A=>l(A.name)).join("、")+(R.length>2?` 等 ${R.length} 處`:"")}):($=t.current_location)!=null&&$.name&&k.push({label:"存藏",value:l(t.current_location.name)}),(H=t.page_count)!=null&&H.description&&k.push({label:o.label.pageCount,value:t.page_count.description}),k},[t,l,o]),m=!!((_=t.description)!=null&&_.text),j=(t.contained_in||[]).some(k=>typeof k!="string"&&jt(k.volume_index).length>0);return e.jsxs(e.Fragment,{children:[e.jsx(zt,{facts:S.length?e.jsx(Rt,{items:S,horizontal:!m}):void 0,children:m?e.jsx(Oe,{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(Re,{children:[e.jsx(xe,{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((k,z)=>{var P,$;const I=typeof k=="string"?k:k.id,v=typeof k=="string"?[]:jt(k.volume_index),E=d.get(I),R=((P=E==null?void 0:E.books)==null?void 0:P.length)||(($=E==null?void 0:E.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(ze,{id:I,label:E?l(E.title):I,onNavigate:i,renderLink:r})}),e.jsxs("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:[R>0&&`全 ${R} ${o.unit.bu}`,R>0&&v.length>0&&" · ",v.length>0&&`本書佔 ${v.length} ${o.unit.volume}`]})]}),v.length>0&&e.jsx(Lr,{volumes:v,unit:o.unit.volume})]},`${I}-${z}`)})})]}),e.jsxs("div",{className:"bim-d-pair",children:[c&&e.jsxs("section",{children:[e.jsx(xe,{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(ze,{id:c.id,label:l(c.title),onNavigate:i,renderLink:r})}),e.jsx("span",{style:{fontSize:12.5,color:"var(--bim-meta-fg, #7b6a54)"},children:[l(Ze(c,o.unit.juan)),(w=c.authors)==null?void 0:w.map(k=>{const z=Fn(k.role);return`${k.dynasty?`〔${l(k.dynasty)}〕`:""}${l(k.name)}${z?" "+l(z):""}`}).join(" · ")].filter(Boolean).join(" · ")})]}),((T=c.description)==null?void 0:T.text)&&e.jsx(Oe,{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(On,{label:o.section.aliases,items:[..._t(t.additional_titles),..._t(t.attached_texts)]})})]})]}),(h.buckets.length>0||h.mirrors.length>0)&&e.jsxs("section",{children:[e.jsx(xe,{glyph:"源",tone:"ink",title:"影印與全文"}),e.jsxs("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:[h.mirrors.map(k=>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:l(k.label)}),k.items.map((z,I)=>e.jsx(st,{item:z,showVolumes:!j},`${z.id||z.url||z.name}-${I}`))]},k.key)),h.buckets.flatMap(k=>k.items).map((k,z)=>e.jsx(st,{item:k,showVolumes:!j},`${k.id||k.url||k.name}-${z}`))]})]})]}),(C=t.location_history)!=null&&C.length?e.jsxs(Re,{children:[e.jsx(xe,{glyph:"藏",tone:"ink",title:o.section.locationHistory}),e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:t.location_history.map((k,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:l(k.name)}),k.description&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:l(k.description)})]},z))})]}):null,y.length>0&&e.jsxs(Re,{style:{marginBottom:0},children:[e.jsx(xe,{glyph:"版",tone:"ink",title:o.relation.siblingVersions,count:`${y.length} 種`,actions:c?e.jsx(ze,{id:c.id,label:"在作品頁查看全部 →",onNavigate:i,renderLink:r,style:{color:"var(--bim-meta-fg, #7b6a54)",fontSize:11.5}}):void 0}),e.jsxs(qt,{children:[x.map(k=>e.jsx(Et,{children:e.jsx(ze,{id:k.id,label:l(k.edition||k.title||k.id),onNavigate:i,renderLink:r,dense:!0,style:{color:"inherit"}})},k.id)),y.length>x.length&&e.jsx(Ve,{inline:!0,label:`更多 ${y.length-x.length} 種`,onClick:()=>b(!0)})]})]})]})},Oi={titles:16,works:16},vo=({data:t,catalog:n,onNavigate:i,renderLink:r,catalogAction:s})=>{var z,I;const o=N(),{convert:l}=M(),[c,a]=f.useState(""),[d,p]=f.useState(!1),[x,g]=f.useState(!1),u=f.useMemo(()=>_r(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,Oi.titles),h=f.useMemo(()=>Kt(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)),_=(()=>{const v=u.rows.map(E=>E.edition).filter(Boolean);return v.length>1&&new Set(v).size===1})(),w=x?S:S.slice(0,Oi.works),T=u.sections.length>0,C=f.useMemo(()=>({leadWidth:26,metaWidth:300,mainLabel:"書名",columns:[...T?[{label:"部類",width:"64px"}]:[],{label:"全帙冊次",width:"1fr"}]}),[T]),k=f.useMemo(()=>{var P,$,H,A;const v=[];t.subtype&&v.push({label:o.label.type,value:t.subtype==="work_collection"?"叢編 · 作品集":"叢編"}),(P=t.publication_info)!=null&&P.details&&v.push({label:"刊印",value:l(t.publication_info.details)}),($=t.publication_info)!=null&&$.year&&v.push({label:"年代",value:t.publication_info.year});const E=((H=t.books)==null?void 0:H.length)||S.length,R=Ze(t,o.unit.juan);return(E||R)&&v.push({label:"種數 / 卷數",value:[E?`${E} ${o.unit.bu}`:"",l(R)].filter(Boolean).join(" · "),title:(A=t.juan_count)!=null&&A.description?l(t.juan_count.description):void 0}),u.totalVolumes&&v.push({label:"全帙冊數",value:`${u.totalVolumes} ${o.unit.volume}`}),v},[t,S.length,u.totalVolumes,l,o]);return e.jsxs(e.Fragment,{children:[e.jsxs(zt,{facts:k.length?e.jsx(Rt,{items:k}):void 0,children:[((z=t.description)==null?void 0:z.text)&&e.jsx(Oe,{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,E)=>e.jsxs("div",{style:{fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"},children:["· ",l(v)]},E))}):null]}),u.rows.length>0&&e.jsxs(Re,{children:[e.jsx(xe,{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,T&&e.jsxs(e.Fragment,{children:[e.jsx(Ne,{label:o.catalog.all,active:!c,onClick:()=>{a(""),p(!1)}}),u.sections.map(v=>e.jsx(Ne,{label:v,active:c===v,onClick:()=>{a(v),p(!1)}},v))]})]})}),e.jsxs(Qe,{children:[e.jsx(Xt,{spec:C}),y.map((v,E)=>{var R;return e.jsx(Zt,{no:Qt(E),spec:C,main:e.jsxs(e.Fragment,{children:[v.id?e.jsx(ze,{id:v.id,label:l(v.title),onNavigate:i,renderLink:r,dense:!0}):e.jsx("span",{children:l(v.title)}),(R=v.subItems)!=null&&R.length?e.jsxs("span",{className:"bim-d-ui",style:{marginLeft:6,fontSize:11.5,color:"var(--bim-hint-fg, #b3a385)"},children:["(",v.subItems.map(P=>l(P)).join("、"),")"]}):null,v.edition&&!_&&e.jsx("span",{className:"bim-d-ui",style:{marginLeft:8,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:l(v.edition)})]}),meta:e.jsxs(e.Fragment,{children:[T&&e.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)"},children:v.section?v.section.endsWith("部")?v.section:`${v.section}部`:e.jsx(ot,{})}),e.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)"},children:v.volumes.length>0?`第 ${Pn(v.volumes,o.unit.volume)} ${o.unit.volume}`:v.expected!=null?`${v.found??0}/${v.expected} ${o.unit.volume}`:e.jsx(ot,{})})]})},`${v.id??v.title}-${E}`)}),y.length===0&&e.jsx(lt,{children:o.catalog.noMatch})]}),b.length>y.length&&e.jsx(Ve,{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(xe,{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,E)=>e.jsx(st,{item:v,fallbackNote:v.details?l(v.details):void 0},`${v.id||v.url||v.name}-${E}`))})]}),j&&e.jsxs("section",{children:[e.jsx(xe,{glyph:"叢",tone:"ink",title:o.section.containedWorks,count:`${S.length} 種`}),e.jsxs(qt,{children:[w.map(v=>e.jsx(Et,{children:e.jsx(ze,{id:v.id,label:l(v.title),onNavigate:i,renderLink:r,dense:!0,style:{color:"inherit"}})},v.id)),S.length>w.length&&e.jsx(Ve,{inline:!0,label:`更多 ${S.length-w.length} 種`,onClick:()=>g(!0)})]})]})]})]})},mc=16,Hi={leadWidth:26,metaWidth:300,mainLabel:"作品名稱",columns:[{label:"職任",width:"72px"},{label:"存世版本",width:"1fr"}]},un=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Di(t){if(!t)return un.length;const n=un.indexOf(t);return n===-1?un.length:n}const jo=({data:t,transport:n,onNavigate:i,renderLink:r})=>{var C,k,z;const s=N(),{convert:o}=M(),[l,c]=f.useState("全部"),[a,d]=f.useState(!1),[p,x]=f.useState("default"),[g,u]=f.useState(new Map),b=f.useMemo(()=>(t.works||[]).map(v=>{const E=g.get(v.work_id);return{id:v.work_id,title:(E==null?void 0:E.title)??v.work_id,role:v.role||"",cls:An(v.role),versionCount:E==null?void 0:E.versionCount,loaded:!!(E!=null&&E.loaded)}}),[t.works,g]),y=f.useMemo(()=>wr((t.works||[]).map(I=>I.role)),[t.works]),h=f.useMemo(()=>{const I=l==="全部"?b:b.filter(v=>v.cls===l);return p==="versions"?[...I].sort((v,E)=>(E.versionCount??-1)-(v.versionCount??-1)):I},[b,l,p]),S=a?h:h.slice(0,mc),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(E=>{var $,H;const R=E??{},P=((($=R.books)==null?void 0:$.length)??0)+(((H=R.collections)==null?void 0:H.length)??0);return[v,{id:v,title:R.title,versionCount:P,loaded:!0}]}).catch(()=>[v,{id:v,loaded:!0}]))).then(v=>{I||u(E=>{const R=new Map(E);for(const[P,$]of v)R.set(P,$);return R})}),()=>{I=!0}},[n,m]);const j=f.useMemo(()=>{const I=new Map;for(const v of t.alt_names||[]){const E=v.type||s.section.aliases;I.has(E)||I.set(E,[]),I.get(E).push(v.name)}return[...I.entries()].sort((v,E)=>Di(v[0])-Di(E[0])).map(([v,E])=>({label:v,names:E}))},[t.alt_names,s]),_=f.useMemo(()=>{const I=[];t.dynasty&&I.push({label:"時代",value:o(t.dynasty)});const v=R=>R==null?"":R<0?`前${-R}`:String(R);(t.birth_year!=null||t.death_year!=null)&&I.push({label:"生卒",value:`${v(t.birth_year)||"?"}—${v(t.death_year)||"?"}`});const E=(t.works||[]).length;return E&&I.push({label:"著作數",value:`${E} 種`}),I},[t,o]),w=(C=t.external_ids)==null?void 0:C.cbdb_id,T=!!((k=t.description)!=null&&k.text);return e.jsxs(e.Fragment,{children:[e.jsx(zt,{facts:_.length?e.jsx(Rt,{items:_}):void 0,children:(j.length>0||T)&&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))}),T&&e.jsx(Oe,{text:t.description.text,style:{fontSize:14,lineHeight:2,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}})]})}),b.length===0&&e.jsxs(Re,{style:{marginBottom:0},children:[e.jsx(xe,{glyph:"著",title:s.label.relatedWorks}),e.jsx(Qe,{children:e.jsx(lt,{children:"尚未著錄該人物的關聯作品。"})})]}),b.length>0&&e.jsxs(Re,{style:{marginBottom:0},children:[e.jsx(xe,{glyph:"著",title:s.label.relatedWorks,count:h.length===b.length?`${b.length} 種`:`${b.length} 種 · 當前 ${h.length} 種`,actions:e.jsx(Jt,{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(Ne,{label:`${I.label} ${I.count}`,active:l===I.cls,onClick:()=>{c(I.cls),d(!1)}},I.cls))}),e.jsxs(Qe,{children:[e.jsx(Xt,{spec:Hi}),S.map((I,v)=>e.jsx(Zt,{no:Qt(v),spec:Hi,main:e.jsx(ze,{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(ot,{})}),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(lt,{children:"該職任下的著作尚未著錄。"})]}),h.length>S.length&&e.jsx(Ve,{label:`展開其餘 ${h.length-S.length} 條著作`,onClick:()=>d(!0)}),w!=null&&e.jsxs("div",{className:"bim-d-ui",style:{marginTop:14,fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:["人物編號 CBDB ",w,((z=t.external_ids)==null?void 0:z.cbdb_match)==="auto"&&e.jsxs("span",{title:"由姓名、朝代与著作重合度自动匹配,未经人工复核",children:[" ","· 自動匹配"]})]})]})]})};function hc(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 bc(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 Ni(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 yc(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 vc(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 l=r?new Set(i.groups):null,c=new Set(i.book_ids??[]);if(l&&t.node_groups)for(const[p,x]of Object.entries(t.node_groups))l.has(x)&&c.add(p);let a=null;if(i.hypothetical_ids&&(a=new Set(i.hypothetical_ids)),l){a||(a=new Set);for(const p of t.hypothetical_nodes??[])p.group&&l.has(p.group)&&a.add(p.id)}return{books:c,hypos:a}}function Ot(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??[]),l=r.node_groups??{},c=vc(r,i??r.default_collection??"all"),a=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(a){const _=new Map(n.map(I=>[I.id,I])),w=new Map((r.hypothetical_nodes??[]).map(I=>[I.id,I])),T=I=>{const v=_.get(I);if(v&&v.lineage)return(v.lineage.derived_from??[]).map(R=>R.ref);const E=w.get(I);return E?(E.derived_from??[]).map(R=>R.ref):[]},C=I=>w.has(I)?!p||p.has(I):!d||d.has(I),k=new Set,z=I=>{if(!k.has(I)){k.add(I);for(const v of T(I))o.has(v)||(C(v)||(w.has(v)?g.add(v):_.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(_=>!o.has(_.id)).filter(_=>!d||d.has(_.id)||x.has(_.id)).map(_=>{const w=bc(_,l);return w&&x.has(_.id)&&(w.bridge=!0),w}).filter(_=>_!==null),b=(r.hypothetical_nodes??[]).filter(_=>!p||p.has(_.id)||g.has(_.id)).map(_=>{const w=hc(_);return g.has(_.id)&&(w.bridge=!0),w}),y=[...u,...b],h=new Set(y.map(_=>_.id)),S=new Set,m=[],j=_=>{S.has(_.id)||!h.has(_.source)||!h.has(_.target)||(S.add(_.id),m.push(_))};for(const _ of n)o.has(_.id)||!_.lineage||d&&!d.has(_.id)&&!x.has(_.id)||((_.lineage.derived_from??[]).forEach((w,T)=>{j(Ni(_.id,w,T))}),(_.lineage.related_to??[]).forEach((w,T)=>{j(yc(_.id,w,T))}));for(const _ of r.hypothetical_nodes??[])p&&!p.has(_.id)&&!g.has(_.id)||(_.derived_from??[]).forEach((w,T)=>{j(Ni(_.id,w,T))});return{nodes:y,edges:m,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(o)}}function So(t,n,i){const r=(t??(n!=null?String(n):"")).trim();return r?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function jc(t,n){const i=[],r=t.version_graph;if(!r)return i;const s=new Set(n.map(a=>a.id)),o=new Set((r.hypothetical_nodes??[]).map(a=>a.id)),l=new Set([...s,...o]),c=(a,d)=>{l.has(d.ref)||i.push(`${a}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&i.push(`${a}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!o.has(d.ref)&&i.push(`${a}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const a of n){if(!a.lineage)continue;const d=`Book ${a.id} (${a.title})`;(a.lineage.derived_from??[]).forEach(p=>c(d,p)),(a.lineage.related_to??[]).forEach(p=>{s.has(p.book_id)||i.push(`${d}: related_to.book_id "${p.book_id}" 不在 books 列表中`)})}for(const a of r.hypothetical_nodes??[]){const d=`Hypothetical ${a.id} (${a.label})`;(a.derived_from??[]).forEach(p=>c(d,p))}return i}const ko=({graph:t,renderLink:n,className:i,style:r})=>{const{convert:s}=M();if(!t.nodes.length)return e.jsx("div",{style:{...$c,...r},className:i,children:"暂无版本图数据"});const o=new Map,l=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=l.get(u)??[];b.push(g),l.set(u,b)}const c=new Map(t.nodes.map(g=>[g.id,g])),a=new Map,d=[];for(const g of t.nodes)if(g.group){const u=a.get(g.group)??[];u.push(g),a.set(g.group,u)}else d.push(g);const p=(g,u)=>(g.year??9999)-(u.year??9999);a.forEach(g=>g.sort(p)),d.sort(p);const x=t.groups.filter(g=>a.has(g.id));return e.jsxs("div",{className:i,style:{...kc,...r},children:[t.title&&e.jsx("div",{style:wc,children:s(t.title)}),t.description&&e.jsx("div",{style:_c,children:s(t.description)}),x.map(g=>e.jsx(Vi,{label:g.label,color:g.color,nodes:a.get(g.id),incomingMap:o,siblingMap:l,nodeMap:c,renderLink:n},g.id)),d.length>0&&e.jsx(Vi,{label:"其他",nodes:d,incomingMap:o,siblingMap:l,nodeMap:c,renderLink:n})]})},Vi=({label:t,color:n,nodes:i,incomingMap:r,siblingMap:s,nodeMap:o,renderLink:l})=>{const{convert:c}=M();return e.jsxs("div",{style:Cc,children:[e.jsx("div",{style:{...Tc,borderLeftColor:n??"var(--bim-widget-border, #ddd)"},children:c(t)}),i.map(a=>e.jsx(Sc,{node:a,incoming:r.get(a.id)??[],siblings:s.get(a.id)??[],nodeMap:o,renderLink:l},a.id))]})},Sc=({node:t,incoming:n,siblings:i,nodeMap:r,renderLink:s})=>{const o=t.kind==="hypothetical",l=t.bridge,{convert:c}=M();return e.jsxs("div",{style:{...Ic,borderStyle:o||l?"dashed":"solid",opacity:l?.55:t.status==="lost"?.7:1,background:l?"var(--bim-bg-subtle, #fafafa)":void 0},title:l?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsxs("div",{style:zc,children:[e.jsx("span",{style:Rc,children:o||!s?c(t.label):s(t.id,c(t.label))}),(t.year_text||t.year!=null)&&e.jsx("span",{style:Ec,children:So(c(t.year_text),t.year,t.year_uncertain)})]}),e.jsxs("div",{style:Bc,children:[t.category&&e.jsx(mt,{children:c(t.category)}),t.status==="lost"&&e.jsx(mt,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(mt,{tone:"warn",children:"残本"}),o&&e.jsx(mt,{tone:"info",children:"假想祖本"}),l&&e.jsx(mt,{tone:"info",children:"桥接"})]}),t.extant_juan&&e.jsxs("div",{style:Lc,children:["现存:",c(t.extant_juan)]}),t.note&&e.jsx("div",{style:Wc,children:c(t.note)}),n.length>0&&e.jsxs("div",{style:Ui,children:[e.jsx("div",{style:Yi,children:"来源:"}),n.map(a=>{const d=r.get(a.source);return e.jsxs("div",{style:Ki(a.confidence),children:[e.jsx("span",{style:Ji,children:c(a.relation)}),e.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,c(d.label)):c((d==null?void 0:d.label)??a.source)}),a.confidence!=="consensus"&&a.confidence!=="certain"&&e.jsx(Gi,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:qi,children:["· ",c(a.evidence)]})]},a.id)})]}),i.length>0&&e.jsxs("div",{style:Ui,children:[e.jsx("div",{style:Yi,children:"关联:"}),i.map(a=>{const d=a.source===t.id?a.target:a.source,p=r.get(d);return e.jsxs("div",{style:Ki(a.confidence),children:[e.jsx("span",{style:Ji,children:c(a.relation)}),e.jsx("span",{children:(p==null?void 0:p.kind)==="book"&&s?s(p.id,c(p.label)):c((p==null?void 0:p.label)??d)}),e.jsx(Gi,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:qi,children:["· ",c(a.evidence)]})]},a.id)})]})]})},mt=({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})},Gi=({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},kc={fontSize:"14px",color:"var(--bim-fg, #333)"},wc={fontSize:"16px",fontWeight:600,marginBottom:"8px"},_c={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},Cc={marginBottom:"16px"},Tc={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:"var(--bim-fg, #333)"},Ic={border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:"var(--bim-bg, #fff)"},zc={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Rc={fontSize:"15px",fontWeight:600},Ec={fontSize:"12px",color:"var(--bim-muted, #777)"},Bc={marginBottom:"6px"},Lc={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},Wc={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},Ui={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},Yi={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},Ki=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),Ji={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},qi={fontSize:"11px",color:"var(--bim-muted, #888)"},$c={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},wo=({selectedNodeId:t,...n})=>{const[i,r]=f.useState("loading"),[s,o]=f.useState(null);return f.useEffect(()=>{let l=!1;return Ac().then(c=>{l||(c?(o(c),r("ready")):r("missing"))}),()=>{l=!0}},[]),i==="loading"?e.jsx("div",{style:Xi,children:"加载图组件中…"}):i==="missing"||!s?e.jsxs("div",{style:Xi,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(Fc,{modules:s,selectedNodeId:t,...n})};async function Ac(){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 Fc=({graph:t,renderLink:n,height:i=600,className:r,style:s,selectedNodeId:o,modules:l})=>{const{ReactFlow:c,Background:a,Controls:d,Handle:p,Position:x,BaseEdge:g,EdgeLabelRenderer:u,getSmoothStepPath:b,dagre:y}=l,h=f.useMemo(()=>({lineage:T=>{var H,A,F,q;const C=((H=T.data)==null?void 0:H.stepPosition)??.85,[k,z,I]=b({sourceX:T.sourceX,sourceY:T.sourceY,sourcePosition:T.sourcePosition,targetX:T.targetX,targetY:T.targetY,targetPosition:T.targetPosition,stepPosition:C,borderRadius:5}),v=!!((A=T.data)!=null&&A.isSibling),E=v?z:T.targetX-18,R=v?I:T.targetY-12,P=(F=T.data)==null?void 0:F.labelStyle,$=(q=T.data)==null?void 0:q.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(g,{id:T.id,path:k,style:T.style,markerStart:T.markerStart,markerEnd:T.markerEnd}),T.label&&e.jsx(u,{children:e.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${E}px,${R}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:"var(--bim-bg, #fff)",border:"0.5px solid var(--bim-widget-border, #ddd)",...$,...P},children:T.label})})]})}}),[g,u,b]),S=f.useMemo(()=>({version:T=>{const C=T.data,k=C.kind==="hypothetical",z=C.status==="lost",I=C.isSelected,v=C.bridge,E=C.borderColor??"var(--bim-muted, #888)",R=v||k?"dashed":"solid",P=v?.5:z?.6:1;return e.jsxs("div",{style:{background:v?"var(--bim-bg-subtle, #fafafa)":"var(--bim-bg, #fff)",border:`2px ${R} ${I?"var(--bim-primary, #0078d4)":E}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:P,boxShadow:I?"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)":k||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:k||!C.renderLink?C.label:C.renderLink(C.bookId,C.label)}),C.description&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.25,marginTop:1},children:C.description}),C.yearText&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.2},children:So(C.yearText,void 0,C.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}=M(),{rfNodes:j,rfEdges:_}=f.useMemo(()=>Pc(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:_,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(a,{gap:16}),e.jsx(d,{showInteractive:!1})]})})};function Pc(t,n,i,r,s=o=>o??""){const c=t.layout==="LR"||!t.layout,a=new n.graphlib.Graph;a.setGraph({rankdir:c?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),a.setDefaultEdgeLabel(()=>({}));const d=new Map(t.groups.map(S=>[S.id,S.color??"var(--bim-muted, #888)"]));for(const S of t.nodes)a.setNode(S.id,{width:160,height:90});const p=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const S of t.edges)S.kind==="derive"&&(p.has(S.relation)||a.setEdge(S.source,S.target));n.layout(a);const x=t.nodes.map(S=>{const m=a.node(S.id),j=r&&S.id===r,_={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:_,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((w,T)=>{var z,I;const C=((z=a.node(w.target))==null?void 0:z.y)??0,k=((I=a.node(T.target))==null?void 0:I.y)??0;return C-k}),_=j.length;j.forEach((w,T)=>{const C=(T-(_-1)/2)*u;y.set(w.id,g+C)})}const h=t.edges.map(S=>Mc(S,y.get(S.id),s));return{rfNodes:x,rfEdges:h}}function Mc(t,n,i=r=>r??""){const r=t.confidence==="probable"||t.confidence==="disputed",s=t.kind==="sibling",o=Hc(t.confidence),l={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:l,markerStart:s?l: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 Hc(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 Xi={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)"},_o=({graph:t,defaultMode:n="list",renderLink:i,graphHeight:r=600,selectedNodeId:s,onModeChange:o,collection:l,onCollectionChange:c,collectionsAvailable:a,collectionCounts:d,className:p,style:x})=>{var m;const[g,u]=f.useState(n),b=j=>{u(j),o==null||o(j)},y=(()=>{if(!a)return[];const j=Object.entries(a);return j.length===0||a.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=l?(m=a==null?void 0:a[l])==null?void 0:m.description:void 0;return e.jsxs("div",{className:p,style:x,children:[e.jsxs("div",{style:Dc,children:[e.jsx("button",{onClick:()=>b("list"),style:fn(g==="list"),children:"列表"}),e.jsx("button",{onClick:()=>b("graph"),style:fn(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,_])=>{const w=d==null?void 0:d[j];return e.jsxs("button",{onClick:()=>c==null?void 0:c(j),style:fn(l===j),title:_.description,children:[_.label,w!=null?` ${w}`:""]},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(ko,{graph:t,renderLink:i}):e.jsx(wo,{graph:t,renderLink:i,height:r,selectedNodeId:s})]})},Dc={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},fn=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"}),Co=({style:t})=>{const n=f.useContext(Ct);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:"简"})]})},To=({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"})})}),Nc=({id:t,transport:n,activeTab:i,onTabChange:r,activeJuan:s,onJuanChange:o,lineageMode:l="list",onLineageModeChange:c,lineageCollection:a,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:_,height:w,footerExtra:T,className:C,style:k})=>{const z=N(),{convert:I}=M(),[v,E]=f.useState(null),[R,P]=f.useState(null),[$,H]=f.useState(!0),[A,F]=f.useState(!1),[q,W]=f.useState([]),[K,ie]=f.useState(!1),[Y,L]=f.useState(null),[J,X]=f.useState(!1),[G,U]=f.useState(null),[ce,we]=f.useState(!1),[fe,ae]=f.useState([]),[Se,Ee]=f.useState(!1),[dt,Fe]=f.useState(null),[Be,D]=f.useState(null),[se,ee]=f.useState(!1),B=f.useRef(null),[Q,le]=f.useState(null),oe=s!==void 0?s:Q,_e=f.useCallback(O=>{o?o(O):le(O)},[o]),Ce=f.useCallback(async O=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){W([]);return}ie(!0);try{if(n.getCollectionCatalogs)W(await n.getCollectionCatalogs(O)||[]);else if(n.getCollectionCatalog){const te=await n.getCollectionCatalog(O);W(te?[{resource_id:"",data:te}]:[])}}catch{W([])}finally{ie(!1)}},[n]),me=f.useCallback(async O=>{if(!n.getCollatedEditionIndex){L(null);return}X(!0);try{L(await n.getCollatedEditionIndex(O))}catch{L(null)}finally{X(!1)}},[n]),Ge=f.useCallback(async O=>{if(!n.getBookFullTextIndex){U(null);return}we(!0);try{U(await n.getBookFullTextIndex(O))}catch{U(null)}finally{we(!1)}},[n]),Un=f.useCallback(async O=>{var te;if(!n.getWorkFullTextList){ae([]);return}Ee(!0);try{const re=(await n.getWorkFullTextList(O)??[]).filter(ne=>ne.owner_type!=="Book");ae(re),Fe(((te=re.find(ne=>ne.primary)??re[0])==null?void 0:te.key)??null)}catch{ae([])}finally{Ee(!1)}},[n]),Yn=f.useCallback(async(O,te)=>{ee(!0);try{if(n.getLineageGraph){const De=await n.getLineageGraph(O);De&&D(De)}const re=te.version_graph;if(!re||!re.enabled){Be||D(null),B.current=null;return}const ne=te.books??[],de=[];for(const De of ne)try{const Le=await n.getItem(De);Le&&de.push(Le)}catch{}B.current={work:te,books:de};const V=a??re.default_collection??(re.core_books&&re.core_books.length>0?"core":"all"),pe=V==="core"&&Array.isArray(re.core_books)&&re.core_books.length>0?"core":V??"all";D(Ot(te,de,pe))}catch{D(null),B.current=null}finally{ee(!1)}},[n]);f.useEffect(()=>{let O=!1;return(async()=>{H(!0),F(!1),E(null),P(null),W([]),L(null),U(null),ae([]),Fe(null),D(null),B.current=null;try{const re=await n.getItem(t);if(O)return;if(!re){F(!0);return}const ne=re;let de=null;if(n.getEntry&&(de=await n.getEntry(t),O))return;de||(de={id:t,title:ne.title??ne.primary_name??t,type:ne.type??"book"}),h&&h(de,ne),E(de),P(ne),ne.type==="collection"?Ce(t):ne.type==="work"?((ne.has_collated||n.getCollatedEditionIndex)&&me(t),(ne.version_graph||n.getLineageGraph)&&Yn(t,ne),n.getWorkFullTextList&&Un(t)):ne.type==="book"&&ne.has_full_text&&n.getBookFullTextIndex&&Ge(t)}catch{O||F(!0)}finally{O||H(!1)}})(),()=>{O=!0}},[t,n,h,Ce,me,Yn,Ge,Un]),f.useEffect(()=>{const O=B.current;!O||!a||D(Ot(O.work,O.books,a))},[a]);const ye=[];if(R){if(ye.push({key:"basic",label:z.detailTab.basicInfo}),R.type==="collection"){K&&q.length===0&&ye.push({key:"catalog:loading",label:`${z.detailTab.catalog}…`});for(const O of q)ye.push({key:`catalog:${O.resource_id}`,label:O.short_name?`${I(O.short_name)}${z.detailTab.catalogSuffix}`:z.detailTab.collectionCatalog})}R.type==="work"&&(Y||J)&&i==="collated"&&ye.push({key:"collated",label:J?`${z.detailTab.collatedEdition}…`:z.detailTab.collatedEdition}),R.type==="book"&&(G||ce)&&i==="fulltext"&&ye.push({key:"fulltext",label:ce?`${z.detailTab.fullText}…`:z.detailTab.fullText}),R.type==="work"&&(fe.length>0||Se)&&i==="fulltext"&&ye.push({key:"fulltext",label:Se?`${z.detailTab.fullText}…`:z.detailTab.fullText}),R.type==="work"&&(Be||se)&&ye.push({key:"lineage",label:se?`${z.detailTab.lineage}…`:z.detailTab.lineage});for(const O of m)(O.position??"before-feedback")==="before-feedback"&&O.shouldShow(R)&&ye.push({key:O.key,label:O.label});j&&i==="feedback"&&ye.push({key:"feedback",label:z.detailTab.feedback});for(const O of m)O.position==="after-feedback"&&O.shouldShow(R)&&ye.push({key:O.key,label:O.label})}f.useEffect(()=>{if(i!=="emendated"||!R)return;r("basic");const O=setTimeout(()=>{var te;(te=document.getElementById("studies"))==null||te.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(O)},[i,R,r]);const Bt=v&&R&&S?S({activeTab:i,activeJuan:oe,entry:v,detail:R}):null,en=f.useMemo(()=>{var de;if(!R)return null;const te=(R.authors??[]).map(V=>{const pe=Fn(V.role);return`${V.dynasty?`〔${I(V.dynasty)}〕`:""}${I(V.name)}${pe?` ${I(pe)}`:""}`}).join(" · ");let re=!1;try{re=Z.extractStatus(R.id)==="draft"}catch{}if(R.type==="book"){const V=R;return{title:I(V.title),subtitle:V.edition?I(V.edition):te||void 0,aside:[re?z.status.draft:"",te&&V.edition?te:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(R.type==="collection"){const V=R;return{title:I(V.title),subtitle:I(Ze(V,z.unit.juan))||void 0,aside:[(de=V.publication_info)==null?void 0:de.year,re?z.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:te||void 0}}if(R.type==="entity"){const V=R,pe=Le=>Le==null?"":Le<0?`前${-Le}`:String(Le),De=V.birth_year!=null||V.death_year!=null?`${pe(V.birth_year)||"?"}—${pe(V.death_year)||"?"}`:"";return{title:I(V.primary_name||V.title),subtitle:[V.dynasty?`〔${I(V.dynasty)}〕`:"",De].filter(Boolean).join(" ")||void 0,aside:re?z.status.draft:void 0,secondLine:void 0}}const ne=I(Ze(R,z.unit.juan));return{title:I(R.title),subtitle:[ne,te].filter(Boolean).join(" · ")||void 0,aside:[Gc(z,R.subtype),re?z.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[R,I,z]),Io=()=>{var O,te,re;return R?R.type==="work"?e.jsx(bo,{data:R,transport:n,onNavigate:g,renderLink:y,collatedSection:Y&&(((O=Y.juan_files)==null?void 0:O.length)??0)>0||fe.length>0?e.jsxs(e.Fragment,{children:[Y&&(((te=Y.juan_files)==null?void 0:te.length)??0)>0&&e.jsx(xn,{title:R.title,measure:`${Y.juan_files.length} ${I(z.unit.juan)}`,onOpen:()=>{_e(Y.juan_files[0]),r("collated")}}),fe.length>0&&(()=>{const ne=fe.find(de=>de.primary)??fe[0];return e.jsx(xn,{title:R.title,measure:[ne.source_name?I(ne.source_name):"",fe.length>1?I(`${fe.length} 種`):""].filter(Boolean).join(" · "),onOpen:()=>{Fe(ne.key),_e(null),r("fulltext")}})})()]}):null,lineageAction:Be&&Be.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}):R.type==="book"?e.jsx(yo,{data:R,transport:n,onNavigate:g,renderLink:y,fullTextSection:G&&G.chapters.length>0?e.jsx(xn,{title:R.title,measure:[`${G.total_chapters} ${I("章")}`,I(G.version_label)].filter(Boolean).join(" · "),onOpen:()=>{_e(null),r("fulltext")}}):null}):R.type==="collection"?e.jsx(vo,{data:R,catalog:(re=q[0])==null?void 0:re.data,transport:n,onNavigate:g,renderLink:y,catalogAction:q.length>0?e.jsxs("button",{type:"button",onClick:()=>r(`catalog:${q[0].resource_id}`),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-accent, #9c3a2c)",borderBottom:"1px solid var(--bim-rule, #d6c9ae)"},children:[z.detailTab.collectionCatalog," →"]}):null}):e.jsx(jo,{data:R,transport:n,onNavigate:g,renderLink:y}):null},zo=()=>{var te,re,ne,de;if(!v||!R)return null;if(i==="basic"||i==="emendated")return Io();if(typeof i=="string"&&i.startsWith("catalog:")){const V=(te=q.find(pe=>`catalog:${pe.resource_id}`===i))==null?void 0:te.data;return e.jsx(Bn,{data:V,onNavigate:g,renderLink:y})}if(i==="collated")return e.jsx(Vn,{index:Y||void 0,workId:t,transport:n,onNavigate:g,activeJuan:oe,onJuanChange:_e});if(i==="fulltext"&&R.type==="work"){const V=dt??((re=fe[0])==null?void 0:re.key);return V?e.jsx(kn,{bookId:t,workKey:V,versions:fe,onVersionChange:pe=>{Fe(pe),_e(null)},transport:n,activeChapter:oe,onChapterChange:_e},V):e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:Se?"加载全文目录…":"暂无全文"})}if(i==="fulltext")return e.jsx(kn,{index:G||void 0,bookId:t,transport:n,activeChapter:oe,onChapterChange:_e});if(i==="lineage"){if(!Be)return e.jsx("div",{style:{color:"var(--bim-label-fg, #a3937b)",padding:"24px 0"},children:se?"加載中…":"暫無版本圖數據"});const V=R.type==="work"?R:null;return e.jsx(_o,{graph:Be,renderLink:y,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:l,onModeChange:c,selectedNodeId:x,collection:a??((ne=V==null?void 0:V.version_graph)==null?void 0:ne.default_collection),onCollectionChange:d,collectionsAvailable:(de=V==null?void 0:V.version_graph)==null?void 0:de.collections,collectionCounts:(()=>{var Kn,Jn,qn,Xn,Zn,Qn,ei;if(!V)return;const pe={},De=((Kn=B.current)==null?void 0:Kn.books)??[];pe.all=(((Jn=V.books)==null?void 0:Jn.length)??0)-(((Xn=(qn=V.version_graph)==null?void 0:qn.excluded_books)==null?void 0:Xn.length)??0);const Le=(Zn=V.version_graph)==null?void 0:Zn.collections;if(Le)for(const ti of Object.keys(Le))pe[ti]=Ot(V,De,ti).nodes.filter(ni=>ni.kind==="book"&&!ni.bridge).length;return pe.core==null&&((ei=(Qn=V.version_graph)==null?void 0:Qn.core_books)!=null&&ei.length)&&(pe.core=V.version_graph.core_books.length),pe})()})}if(i==="feedback"&&j)return e.jsx(mo,{resourceId:t,apiUrl:_});const O=m.find(V=>V.key===i);return O?O.render({detail:R,entry:v,transport:n,onNavigate:g}):null};if($)return e.jsx(Ft,{style:{minHeight:w,...k},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((O,te)=>e.jsx("div",{style:{height:te===1?40:16,width:O,opacity:.35,background:"var(--bim-rule, #e0d6c0)"}},te))})});if(A||!R||!v||!en)return e.jsx(Ft,{style:{minHeight:w,...k},children:e.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:"var(--bim-label-fg, #a3937b)",fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const Ro=i==="basic"||i==="emendated",tn=[{label:b??z.detailTab.backToIndex,onClick:u}];if(R.type==="book"&&R.work_id){const O=R.work_id;tn.push({label:z.indexType.work,id:O,onClick:()=>g==null?void 0:g(O)})}tn.push({label:z.indexType[R.type]});const Lt=i==="collated"||i==="fulltext";return e.jsx("div",{className:C,children:e.jsxs(Ft,{wide:Lt,style:{minHeight:w,...k},children:[e.jsx(Rr,{breadcrumb:e.jsxs(e.Fragment,{children:[e.jsx(Mn,{char:"籍"}),e.jsx(Er,{items:tn})]}),actions:e.jsxs(e.Fragment,{children:[e.jsx(Co,{}),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}),Bt&&e.jsx(To,{...Bt})]})}),e.jsx(Br,{...en,aside:Lt?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("作品信息")," →"]}):en.aside}),!Lt&&ye.length>1&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:ye.map(O=>e.jsx(Ne,{label:O.label,active:O.key===i||Ro&&O.key==="basic",onClick:()=>r(O.key)},O.key))}),e.jsx("div",{style:{marginTop:!Lt&&ye.length>1?8:0},children:zo()}),e.jsx(Or,{left:e.jsxs(e.Fragment,{children:[T,T?" · ":"",e.jsx(Vc,{id:R.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}),Bt&&e.jsx("a",{href:Bt.href,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-meta-fg, #7b6a54)"},children:z.detailTab.dataLicense})]})})]})})};function Vc({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 Gc(t,n){return n?t.workSubtype[n]??n:""}function xn({title:t,measure:n,onOpen:i}){const{convert:r}=M(),[s,o]=f.useState(!1),l=r(t?`進入《${t}》全文閲讀`:"進入全文閲讀"),c=[n,r("全文檢索"),r("原書對照")].filter(Boolean).join(" · ");return e.jsx(Re,{style:{marginTop:-12,marginBottom:28},children:e.jsxs("div",{role:"button",tabIndex:0,onClick:i,onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.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:l}),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=Z.BidLink;exports.BookIndexError=Z.BookIndexError;exports.BookIndexManager=Z.BookIndexManager;exports.BookIndexStorage=Z.BookIndexStorage;exports.BundleStorage=Z.BundleStorage;exports.ConfigError=Z.ConfigError;exports.GithubStorage=Z.GithubStorage;exports.IdGenerationError=Z.IdGenerationError;exports.IdGenerator=Z.IdGenerator;exports.LocalStorage=Z.LocalStorage;exports.MigrationError=Z.MigrationError;exports.StorageError=Z.StorageError;exports.base36Decode=Z.base36Decode;exports.base36Encode=Z.base36Encode;exports.base58Decode=Z.base58Decode;exports.buildId=Z.buildId;exports.buildPromotionMap=Z.buildPromotionMap;exports.cleanName=Z.cleanName;exports.decodeId=Z.decodeId;exports.decodeIdString=Z.decodeIdString;exports.encodeId=Z.encodeId;exports.extractIdFromUrl=Z.extractIdFromUrl;exports.extractStatus=Z.extractStatus;exports.extractType=Z.extractType;exports.normalizeCatalog=Z.normalizeCatalog;exports.parseId=Z.parseId;exports.shardOf=Z.shardOf;exports.smartDecode=Z.smartDecode;exports.validateResource=Z.validateResource;exports.Badge=Vt;exports.BidUrlProvider=Ho;exports.BookDetailLayout=Nc;exports.BookFullText=kn;exports.BookPage=yo;exports.Breadcrumb=Er;exports.Chip=Et;exports.ChipWall=qt;exports.CollatedEdition=Vn;exports.CollectionCatalog=Bn;exports.CollectionPage=vo;exports.CreateEntityDialog=lo;exports.DETAIL_CSS=Ir;exports.Dash=ot;exports.DataTable=Qe;exports.DetailFooter=Or;exports.DetailHeader=Br;exports.EmendatedBySection=gr;exports.EmptyNote=lt;exports.EntityDetail=cr;exports.EntityPage=jo;exports.EntityPickerDialog=co;exports.EntitySelector=so;exports.ExpandRow=Wr;exports.ExtLink=vn;exports.FactList=Rt;exports.FeedbackButton=tc;exports.FeedbackDialog=xo;exports.FeedbackForm=go;exports.FeedbackList=Gn;exports.FeedbackTab=mo;exports.FilterChip=Ne;exports.FormInput=ve;exports.FormTextArea=qe;exports.GUJI_TABLE_NOTATION=Yr;exports.GlyphBadge=Mn;exports.GujiTable=Qr;exports.HomePage=Sn;exports.IndexApp=Xl;exports.IndexBrowser=mn;exports.IndexDetail=En;exports.IndexEditor=po;exports.IndexView=Na;exports.IntroGrid=zt;exports.LocaleContext=Ct;exports.LocaleProvider=qo;exports.LocaleToggle=Co;exports.ModeIndicator=lr;exports.MoreButton=Ve;exports.PAGE_MAX_WIDTH=ht;exports.PageFrame=Ft;exports.Quote=Pt;exports.ROLE_CLASS_ORDER=kr;exports.RelationPanel=ro;exports.RepoSourceLink=To;exports.ResourceEditor=gn;exports.ResourceGroup=yn;exports.ResourceLine=st;exports.ResourceList=Rn;exports.ResourceRow=Fr;exports.SNIPPET_MARK_END=er;exports.SNIPPET_MARK_START=Qi;exports.SearchInput=ar;exports.Section=Te;exports.SectionHead=xe;exports.SmartBidInput=Mt;exports.SourceEditor=to;exports.TableHead=Xt;exports.TableRow=Zt;exports.TagRow=On;exports.TagRows=Mr;exports.TextButton=Jt;exports.TopStrip=Rr;exports.VersionLineageGraph=wo;exports.VersionLineageList=ko;exports.VersionLineageView=_o;exports.VolumeChips=Lr;exports.VolumeLinks=Pr;exports.WorkCatalog=aa;exports.WorkPage=bo;exports.bucketResources=Kt;exports.buildCollectionTable=_r;exports.buildLineageGraph=Ot;exports.buildPageUrl=zn;exports.buildVersionRow=jr;exports.buildVersionTable=Sr;exports.computeVersionPartition=nl;exports.deriveDating=Qs;exports.deriveEditionType=Tr;exports.deriveEra=It;exports.deriveYear=Yt;exports.deriveYearRange=Wn;exports.detailToEditor=fo;exports.displayAuthorRole=Fn;exports.editorToDetail=Da;exports.eraRank=bn;exports.flattenTitles=_t;exports.formatTemplate=Tt;exports.formatVolumeRange=Pn;exports.getDisplayNameFromUrl=kt;exports.getStartPage=In;exports.getTypeGroupKey=_n;exports.groupRelatedWorks=vr;exports.hasGujiTableNotation=Kr;exports.measureText=Ze;exports.mergeVolumeResources=Cn;exports.normalizeEra=ue;exports.normalizeRole=An;exports.normalizeVolumeIndex=jt;exports.normalizeVolumes=sr;exports.numberToChinese=Cr;exports.parseChineseNumber=Dt;exports.parseGujiTable=qr;exports.parseSourceString=no;exports.renderFullTextBody=eo;exports.resourceHref=Ht;exports.resourceNote=$n;exports.roleFacets=wr;exports.rowNo=Qt;exports.sortYear=yr;exports.splitFullTextTables=Xr;exports.splitHighlightSnippet=tr;exports.splitTableRow=Jr;exports.stringifySources=io;exports.useBidUrl=je;exports.useConvert=M;exports.useT=N;exports.validateLineageGraph=jc;exports.volumeStats=Tn;
|
|
99
|
+
`;function Ft({children:e,style:n,wide:i}){return t.jsxs("div",{className:"bim-d-page",style:n,children:[t.jsx("style",{children:Br}),t.jsx("div",{className:i?"bim-d-main bim-d-main-wide":"bim-d-main",children:e})]})}function Lr({aside:e,children:n}){return t.jsxs("div",{className:"bim-d-reader",children:[t.jsx("aside",{className:"bim-d-reader-aside bim-d-ui",children:e}),t.jsx("div",{className:"bim-d-reader-main",children:n})]})}function Wr({breadcrumb:e,actions:n}){return t.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:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:e}),n&&t.jsx("div",{style:{display:"flex",alignItems:"center",gap:16},children:n})]})}function On({char:e,tone:n="accent"}){return t.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:e})}function $r({items:e}){const n=je();return t.jsx(t.Fragment,{children:e.map((i,r)=>{const o=r===e.length-1,s=r>0&&t.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"/"},`s${r}`),l=i.id?n(i.id):i.href,c=o||!i.onClick&&!l?t.jsx("span",{style:{color:"var(--bim-ink, #2a231c)"},children:i.label},r):t.jsx("a",{href:l??"#",onClick:i.onClick?a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),i.onClick())}:void 0,style:{color:"var(--bim-meta-fg, #7b6a54)"},children:i.label},r);return t.jsxs(f.Fragment,{children:[s,c]},r)})})}function Ar({title:e,subtitle:n,aside:i,secondLine:r}){return t.jsxs("header",{style:{borderBottom:"2px solid var(--bim-rule-strong, #2a231c)",paddingBottom:18},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"flex-end",justifyContent:"space-between",gap:"10px 24px"},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 14px",minWidth:0},children:[t.jsx("h1",{className:"bim-d-h1",style:{margin:0,fontSize:42,fontWeight:700,letterSpacing:".06em",lineHeight:1.1,wordBreak:"break-word"},children:e}),n&&t.jsx("span",{style:{fontSize:15,color:"var(--bim-meta-fg, #7b6a54)",letterSpacing:".06em"},children:n})]}),i&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)",letterSpacing:".06em"},children:i})]}),r&&t.jsx("div",{style:{marginTop:12,fontSize:13.5,color:"var(--bim-quiet-fg, #5b4f40)"},children:r})]})}function zt({children:e,facts:n}){return!e&&n?t.jsx("div",{style:{padding:"20px 0 26px",borderBottom:"1px solid var(--bim-rule, #e4dbc9)",marginBottom:40},children:n}):t.jsxs("div",{className:"bim-d-intro",children:[t.jsx("div",{style:{minWidth:0},children:e}),n]})}function Rt({items:e,horizontal:n}){const{convert:i}=P();return e.length?t.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:e.map((r,o)=>t.jsxs("div",{title:r.title,style:n?{display:"flex",flexDirection:"column",gap:3}:{display:"flex",justifyContent:"space-between",gap:10},children:[t.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)",letterSpacing:".08em",flex:"none"},children:i(r.label)}),t.jsx("span",{style:{color:"var(--bim-body-fg, #3b3228)",textAlign:n?"left":"right",minWidth:0},children:r.value})]},o))}):null}function xe({glyph:e,tone:n,title:i,count:r,actions:o,id:s}){const{convert:l}=P();return t.jsxs("div",{id:s,style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"10px 16px",marginBottom:14,scrollMarginTop:16},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[t.jsx(On,{char:e,tone:n}),t.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:l(i)}),r!=null&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:r})]}),o&&t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:o})]})}function Re({children:e,style:n}){return t.jsx("section",{style:{marginBottom:48,...n},children:e})}function Ne({label:e,active:n,onClick:i,dashed:r}){const{convert:o}=P();return t.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:o(e)})}function qt({label:e,onClick:n}){const{convert:i}=P();return t.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(e)})}function Ve({label:e,onClick:n,inline:i}){const{convert:r}=P();return t.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(e)})}function Et({children:e,href:n,onClick:i,title:r}){const o={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?t.jsx("a",{href:n??"#",title:r,onClick:i?s=>{s.metaKey||s.ctrlKey||(s.preventDefault(),i())}:void 0,style:o,children:e}):t.jsx("span",{title:r,style:o,children:e})}function Jt({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function Fr({volumes:e,unit:n="冊",max:i=60}){const[r,o]=f.useState(!1);if(!e.length)return null;const s=r?e:e.slice(0,i);return t.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[s.map(l=>t.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:"1px solid var(--bim-rule, #e0d6c0)",color:"var(--bim-meta-fg, #7b6a54)"},children:l},l)),!r&&e.length>i&&t.jsxs("button",{type:"button",onClick:()=>o(!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:["+",e.length-i]}),t.jsx("span",{style:{padding:"2px 6px",color:"var(--bim-hint-fg, #b3a385)"},children:n})]})}function Qe({children:e}){return t.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:e})}function Xt({spec:e}){const{convert:n}=P();return t.jsxs("div",{className:"bim-d-thead bim-d-ui",style:{display:"grid",gridTemplateColumns:`${e.leadWidth}px 1fr ${e.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:[t.jsx("span",{}),t.jsx("span",{children:n(e.mainLabel)}),t.jsx("span",{style:{display:"grid",gridTemplateColumns:e.columns.map(i=>i.width).join(" "),gap:12},children:e.columns.map(i=>t.jsx("span",{children:n(i.label)},i.label))})]})}function Zt({no:e,main:n,meta:i,spec:r}){return t.jsxs("div",{className:"bim-d-row",style:{gridTemplateColumns:`${r.leadWidth}px 1fr ${r.metaWidth}px`,gap:12},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:"var(--bim-hint-fg, #c2b294)",textAlign:"right"},children:e}),t.jsx("span",{style:{minWidth:0},children:n}),t.jsx("span",{className:"bim-d-row-meta",style:{display:"grid",gridTemplateColumns:r.columns.map(o=>o.width).join(" "),gap:12,alignItems:"center",fontSize:12},children:i})]})}function Qt(e){return String(e+1).padStart(2,"0")}function ot(){return t.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"—"})}function Mr({open:e,onToggle:n,main:i,action:r,children:o}){return t.jsxs("div",{style:{borderBottom:"1px solid var(--bim-rule, #eae2d0)"},children:[t.jsxs("div",{className:"bim-d-expand-head",style:{display:"grid",gridTemplateColumns:"26px 1fr auto",gap:12,alignItems:"baseline",padding:"9px 4px"},children:[t.jsx("button",{type:"button",onClick:n,"aria-expanded":e,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 ${e?"var(--bim-accent, #9c3a2c)":"var(--bim-rule-dashed, #d6c9ae)"}`,background:e?"var(--bim-accent, #9c3a2c)":"transparent",color:e?"var(--bim-page-bg, #fbf9f3)":"var(--bim-accent, #9c3a2c)"},children:e?"-":"+"}),t.jsx("span",{style:{fontSize:14,minWidth:0},children:i}),r]}),e&&o&&t.jsx("div",{style:{padding:"2px 4px 14px 38px",borderLeft:"2px solid var(--bim-rule-accent-soft, #e0d3b6)",marginLeft:12},children:o})]})}function Pr(e){const n=[];for(let i=0;i<e.length;i++){const r=e[i];let o;if(r==="⟨")o="⟩";else if(r==="<"){const c=e[i+1];if(c===void 0||/[A-Za-z/!?>\s]/.test(c))continue;o=">"}else continue;const s=e.indexOf(o,i+1);if(s<0)continue;const l=e.slice(i+1,s);l.includes(`
|
|
100
|
+
`)||(n.push({start:i,end:s+1,inner:l}),i=s)}return n}function Or(e,n){if(e.length<=n)return e;let i=n;for(const r of Pr(e)){if(r.start>=i)break;if(r.end>i){i=r.start>0?r.start:r.end;break}}return e.slice(0,i)}const Hr={fontSize:".78em",color:"var(--bim-meta-fg, #7b6a54)",lineHeight:1.55},vl={display:"inline-block",fontSize:"1em",lineHeight:1.15,padding:"0 .12em",margin:"0 .05em",border:"1px solid color-mix(in srgb, currentColor 40%, transparent)",borderRadius:2,verticalAlign:"baseline",whiteSpace:"nowrap"};function Dr(e,n,i){return e.map((r,o)=>{switch(r.type){case"text":return t.jsx(f.Fragment,{children:n(r.text)},o);case"jz":return t.jsx("span",{className:"bim-jiazhu",style:i===0?Hr:void 0,children:Dr(r.children,n,i+1)},o);case"qw":return t.jsx("span",{className:"bim-qw guji-qw",title:r.label?`闕文:${r.label}`:"闕文",children:"□"},o);case"qz":return t.jsx("span",{className:"bim-qz guji-qz","data-guji-guess":r.guess,children:"□"},o);case"zi":return t.jsx("span",{className:"bim-zi guji-zi",title:`組字:${r.label}`,style:vl,children:r.label},o)}})}function be(e,n=r=>r,i){if(!e)return"";if(i!=null&&i.gujiMarkdown)return bl(e)?Dr(Rr(e),n,0):n(e);if(e.indexOf("⟨")<0&&e.indexOf("<")<0)return n(e);const r=[];let o=0,s=0;for(const l of Pr(e))l.start>o&&r.push(t.jsx(f.Fragment,{children:n(e.slice(o,l.start))},s++)),r.push(t.jsx("span",{className:"bim-jiazhu",style:Hr,children:n(l.inner)},s++)),o=l.end;return o<e.length&&r.push(t.jsx(f.Fragment,{children:n(e.slice(o))},s++)),r}function Mt({label:e,children:n}){return t.jsxs("div",{style:{marginBottom:10},children:[e&&t.jsx("div",{className:"bim-d-ui",style:{fontSize:11,fontWeight:600,letterSpacing:".1em",color:"var(--bim-label-fg, #a3937b)",marginBottom:4},children:e}),t.jsx("div",{style:{fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)",textAlign:"justify"},children:n})]})}function vn({title:e,tag:n,children:i}){const{convert:r}=P();return t.jsxs("div",{children:[t.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:[t.jsx("span",{style:{fontSize:14.5,letterSpacing:".08em"},children:r(e)}),n&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:"var(--bim-accent, #9c3a2c)",letterSpacing:".06em"},children:r(n)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column"},children:i})]})}function Nr({name:e,note:n,href:i,extra:r}){const o=t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{fontSize:14,minWidth:0},children:e}),t.jsx("span",{className:"bim-d-ui",style:{fontSize:11,color:"var(--bim-hint-fg, #b3a385)",flex:"none"},children:i?"↗":""}),n&&t.jsx("span",{className:"bim-d-ui",style:{gridColumn:"1 / -1",fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:n})]}),s={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 t.jsxs(t.Fragment,{children:[i?t.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",style:s,children:o}):t.jsx("div",{style:s,children:o}),r]})}function st({item:e,siblings:n,showVolumes:i=!0,fallbackNote:r}){const{convert:o}=P(),[s,l]=f.useState(!1),c=In(e),a=i&&!!c&&c.expected>0,d=(e.url?kt(e.url):void 0)||o(e.name),p=n?sl(e,n):"",x=p?`${d}(${p})`:d;return t.jsx(Nr,{name:x,note:An(e)||r,href:Ht(e),extra:a?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>l(g=>!g),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:"var(--bim-meta-fg, #7b6a54)",borderBottom:"1px solid var(--bim-rule, #e0d6c0)"},children:s?"收起分冊":`展開 ${c.expected} 冊`}),s&&t.jsx(Vr,{item:e})]}):void 0})}function Vr({item:e}){return t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,padding:"6px 0 10px",fontSize:11},children:(e.volumes||[]).map((n,i)=>{const r=n.status==="missing";return n.url&&!r?t.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):t.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 Hn({label:e,items:n}){const{convert:i}=P();return n.length?t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)",letterSpacing:".08em"},children:e}),n.map((r,o)=>t.jsx(Et,{children:i(r)},o))]}):null}function Gr({rows:e}){const n=e.filter(i=>i.items.length>0);return n.length?t.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",gap:8},children:n.map(i=>t.jsx(Hn,{label:i.label,items:i.items},i.label))}):null}function _t(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Ur({left:e,right:n}){return t.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:[t.jsx("span",{children:e}),n&&t.jsx("span",{style:{display:"flex",gap:16},children:n})]})}function lt({children:e,action:n}){return t.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:[t.jsx("span",{children:e}),n]})}function ze({id:e,label:n,onNavigate:i,renderLink:r,style:o,dense:s}){const l=je();return r?t.jsx(t.Fragment,{children:r(e,typeof n=="string"?n:void 0,{dense:s})}):t.jsx("a",{href:l(e),onClick:i?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),i(e))}:void 0,style:o,children:n??e})}function jn({href:e,children:n}){return t.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[n," ",t.jsx("span",{className:"bim-d-ui",style:{fontSize:11},children:"↗"})]})}const ji={A:"fine",B:"rough",C:"rough",D:"ocr"};function jl(e){return typeof e!="string"?null:e in ir?e:e in ji?ji[e]:null}const Sl={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},kl={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function ge(e){return typeof e!="string"?"":Sl[e]??kl[e]??e}const wl=["〇","一","二","三","四","五","六","七","八","九"],Si=["","十","百","千"],_l=["","萬","億"];function Yr(e){if(e===0)return"〇";if(e<0)return`負${Yr(-e)}`;const n=[];let i=e,r=0;for(;i>0;){const o=i%1e4;o>0?n.unshift(Cl(o,r>0)+_l[r]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Cl(e,n){const i=[];let r=e;for(;r>0;)i.unshift(r%10),r=Math.floor(r/10);let o="";for(let s=0;s<i.length;s++){const l=i[s],c=i.length-1-s;l===0?o&&!o.endsWith("〇")&&(o+="〇"):l===1&&c===1&&s===0&&!n?o+=Si[c]:o+=wl[l]+Si[c]}return o.replace(/〇$/,"")}let St=null,$t=null;const Nt=new Set;function Tl(){return St?Promise.resolve():$t||($t=import("opencc-js/t2cn").then(e=>{St=e.Converter({from:"tw",to:"cn"}),Nt.forEach(n=>n())}).catch(()=>{St=e=>e,Nt.forEach(e=>e())}),$t)}function He(){const[,e]=f.useState(0);return f.useEffect(()=>{if(St)return;const n=()=>e(i=>i+1);return Nt.add(n),Tl(),()=>{Nt.delete(n)}},[]),St??(n=>n)}function at(e,n){return n(e).toLowerCase()}const Dn="var(--bim-highlight-bg, #fff59d)";function ct(e,n,i){if(!n)return e;const r=at(n,i);if(!r)return e;const o=at(e,i);if(o.length!==e.length)return e;const s=[];let l=0,c=0;for(;l<e.length;){const a=o.indexOf(r,l);if(a===-1){s.push(e.slice(l));break}a>l&&s.push(e.slice(l,a)),s.push(t.jsx("mark",{style:{background:Dn,padding:0,color:"inherit"},children:e.slice(a,a+r.length)},c++)),l=a+r.length}return t.jsx(t.Fragment,{children:s})}function Nn(e,n,i,r){if(!n)return!0;const o=at(n,r);return(i?[e.title,e.header_line,e.content,e.comment]:[e.title,e.book_title,e.author,e.author_info,e.summary,e.content,e.comment,e.additional_comment]).some(l=>typeof l=="string"&&at(l,r).includes(o))}function Il(e,n,i){return n?at(e,i).includes(at(n,i)):!0}const Vn={类:"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)"},zl={考证:"var(--bim-section-kaozhen, #5d6d7e)"};function Rl(e){const n=e.replace(".json","").replace(/[/\\]/g,"");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function Sn({file:e,isActive:n,onSelect:i,meta:r,matchState:o,vertical:s}){const l=o===0,c=o==="loading",a=typeof o=="number"&&o>0,d=r!=null&&r.vol_label?`${r.vol_label}冊`:null,p=d??Rl(e),x=!d&&!!(r!=null&&r.vol_label)&&!p.includes(r.vol_label);return t.jsxs("button",{onClick:()=>{l||i(e)},disabled:l,style:{padding:s?"4px 8px":"3px 8px",textAlign:s?"left":"center",width:s?"100%":void 0,border:s?"1px solid transparent":n?"1px solid var(--bim-primary, #8e6f3e)":l?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderLeft:s?`2px solid ${n?"var(--bim-primary, #8e6f3e)":"transparent"}`:void 0,borderRadius:s?0:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":a?`${Dn}40`:"transparent",color:n?"var(--bim-primary, #8e6f3e)":l?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:l?"not-allowed":"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4,opacity:l?.5:1},children:[p,x&&t.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",r.vol_label,"冊)"]}),a&&t.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:o}),c&&t.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function Kr(e,n){var i;return e.files.includes(n)?!0:!!((i=e.children)!=null&&i.some(r=>Kr(r,n)))}function qr(e){var r;const n=e.files.length,i=((r=e.children)==null?void 0:r.reduce((o,s)=>o+qr(s),0))||0;return n+i}function El(e,n){const i=[],r=l=>{var c;i.push(...l.files),(c=l.children)==null||c.forEach(r)};if(r(e),i.length===0)return;const o=i.map(l=>n[l]);if(o.every(l=>l===void 0))return;if(o.some(l=>l==="loading"))return"loading";let s=0;for(const l of o)typeof l=="number"&&(s+=l);return s}function Jr({group:e,activeFile:n,onSelect:i,depth:r=0,juanMeta:o,matchStates:s,vertical:l}){var y;const c=Kr(e,n||""),a=El(e,s),d=typeof a=="number"&&a>0,p=a===0,[x,g]=f.useState(c||d),u=qr(e),b=!!((y=e.children)!=null&&y.length);if(f.useEffect(()=>{c&&g(!0)},[c]),f.useEffect(()=>{d&&g(!0)},[d]),e.files.length===1&&!b){const h=e.files[0],S=n===h,m=s[h],j=m===0,_=m==="loading",w=typeof m=="number"&&m>0;return t.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)":w?`${Dn}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:[e.label,w&&t.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:m}),_&&t.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}return t.jsxs("div",{style:{marginBottom:r===0?"4px":"2px"},children:[t.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:[t.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:x?"rotate(90deg)":"none",display:"inline-block"},children:"▶"}),t.jsx("span",{children:e.label}),t.jsxs("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",u,")"]}),d&&t.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:["匹配 ",a]}),a==="loading"&&t.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]}),x&&t.jsxs(t.Fragment,{children:[e.files.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:l?"column":"row",flexWrap:l?"nowrap":"wrap",gap:l?"1px":"4px",padding:l?`2px 0 2px ${8+r*10}px`:`4px 0 4px ${24+r*16}px`},children:e.files.map(h=>t.jsx(Sn,{file:h,isActive:n===h,onSelect:i,meta:o==null?void 0:o[h],matchState:s[h],vertical:l},h))}),b&&e.children.map((h,S)=>t.jsx(Jr,{group:h,activeFile:n,onSelect:i,depth:r+1,juanMeta:o,matchStates:s,vertical:l},S))]})]})}function Bl({files:e,groups:n,activeFile:i,onSelect:r,juanMeta:o,matchStates:s,vertical:l}){const c=e||[];return n&&n.length>0?t.jsx("div",{style:{marginBottom:l?0:"16px"},children:n.map((a,d)=>t.jsx(Jr,{group:a,activeFile:i,onSelect:r,juanMeta:o,matchStates:s,vertical:l},d))}):c.length===0?null:l?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"1px"},children:c.map(a=>t.jsx(Sn,{file:a,isActive:i===a,onSelect:r,meta:o==null?void 0:o[a],matchState:s[a],vertical:!0},a))}):t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:c.map(a=>t.jsx(Sn,{file:a,isActive:i===a,onSelect:r,meta:o==null?void 0:o[a],matchState:s[a]},a))})}function Ll({type:e}){const n=ge(e),i=Vn[n]||"var(--bim-desc-fg, #717171)";return t.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 Wl({section:e,onNavigate:n,highlightQuery:i=""}){const{convert:r}=P(),o=je(),s=He(),l=y=>y?be(r(y),h=>i?ct(h,i,s):h):"",[c,a]=f.useState(!1),d=!!e.summary,p=!!e.comment,x=!!e.additional_comment,g=!!(e.content&&e.content.length>60),u=d||p||x||g;f.useEffect(()=>{i&&a(!0)},[i]);const b=!c&&g?Or(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[t.jsxs("div",{onClick:()=>u&&a(!c),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:u?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[u&&t.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:"▶"}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[e.book_title?t.jsxs(t.Fragment,{children:["《",l(e.book_title),"》"]}):l(e.title),e.n_juan!=null&&t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[Yr(e.n_juan),"卷"]}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:l(e.author_info||e.author)})]}),!c&&b&&t.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:l(b)})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:l(e.edition)}),e.tag&&t.jsx("span",{style:{fontSize:"11px",color:"var(--bim-section-tag-fg, #e74c3c)"},children:e.tag==="triangle"?"△":e.tag}),e.work_id&&n&&t.jsx("a",{href:o(e.work_id),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.stopPropagation(),n(e.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),c&&u&&t.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[e.author_info&&t.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:l(e.author_info)}),e.summary&&t.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:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),t.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(e.summary)})]}),e.comment&&t.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),t.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(e.comment)})]}),e.additional_comment&&t.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),t.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(e.additional_comment)})]}),g&&!d&&!p&&!x&&t.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:l(e.content)})]})]})}function $l({section:e,highlightQuery:n=""}){const{convert:i}=P(),r=He(),o=a=>a?be(i(a),d=>n?ct(d,n,r):d):"",[s,l]=f.useState(!1),c=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs("div",{onClick:()=>c&&l(!s),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[t.jsx(Ll,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:o(e.title)}),c&&t.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",transition:"transform 0.15s",transform:s?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),s&&c&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${Vn[ge(e.type)]||"var(--bim-desc-fg, #717171)"} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:t.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:o(e.content)})})]})}const Al=100;function Xr(e){return ge(e.type)!=="page_header"?!1:(e.content||"").length>=Al}function Fl({section:e,highlightQuery:n=""}){const{convert:i}=P(),r=He();if(ge(e.type)==="page_header"&&!Xr(e)||!e.content&&!e.title)return null;const o=i((e.content||e.title||"").replace(/\n{2,}/g,`
|
|
101
|
+
`)),s=be(o,d=>n?ct(d,n,r):d),l=ge(e.type),c=Vn[l]||"var(--bim-desc-fg, #717171)",a=l==="序"||l==="结语"||l==="注释";return t.jsxs("div",{style:{padding:a?"10px 12px":"6px 0",margin:a?"8px 0":void 0,fontSize:"13px",color:"var(--bim-desc-fg, #555)",lineHeight:1.8,whiteSpace:"pre-line",borderLeft:a?`3px solid ${c}40`:void 0,background:a?"var(--bim-bg, #fafafa)":void 0,borderRadius:a?"0 4px 4px 0":void 0,position:"relative"},children:[a&&t.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:c,marginRight:"8px",padding:"1px 5px",border:`1px solid ${c}40`,borderRadius:"2px",background:`${c}08`,verticalAlign:"middle"},children:l}),s]})}function Ml(e,n,i){const[r,o]=f.useState({});return f.useEffect(()=>{var d;if(!n||e.length===0)return;let s=!1;const l=e.filter(p=>{var x;return!((x=i==null?void 0:i.current)!=null&&x.has(p))}),c={};for(const p of e)(d=i==null?void 0:i.current)!=null&&d.has(p)&&(c[p]=i.current.get(p));if(Object.keys(c).length>0&&o(c),l.length===0)return;const a=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(l.map(async p=>{var g;const x=await a(p);return(g=i==null?void 0:i.current)==null||g.set(p,x),[p,x]})).then(p=>{s||o(x=>{const g={...x};for(const[u,b]of p)g[u]=b;return g})}),()=>{s=!0}},[e.join(","),n]),r}function Pl({section:e,onNavigate:n,transport:i,workLabelCache:r,highlightQuery:o=""}){const{convert:s}=P(),l=je(),c=He(),a=m=>m?be(s(m),j=>o?ct(j,o,c):j):"",[d,p]=f.useState(!1);f.useEffect(()=>{o&&p(!0)},[o]);const x=ge(e.type),g=zl[x]||"var(--bim-desc-fg, #717171)",u=!!e.content,b=e.work_ids||[],y=b.length>1,h=Ml(y?b:[],i,r),S=u&&!d&&e.content.length>80?Or(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>u&&p(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:u?"pointer":"default",userSelect:"none"},children:[u&&t.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:"▶"}),t.jsxs("div",{style:{flex:1},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)",lineHeight:1.6},children:e.header_line?a(e.header_line):a(e.title)}),!d&&S&&t.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:a(S)})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&t.jsx("a",{href:l(b[0]),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),m.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),y&&t.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",flexShrink:0},children:[b.length,"部作品"]}),t.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&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(m=>{const j=h[m],_=j?`${s(j.title)}${j.author?`(${s(j.author)})`:""}`:m.slice(0,8)+"…";return t.jsxs("a",{href:l(m),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),w.stopPropagation(),n(m))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:m,children:["→",_]},m)})}),d&&u&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${g}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:[t.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(e.content)}),e.comment&&t.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:"1px solid var(--bim-widget-border, #eee)",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.8,fontStyle:"italic"},children:a(e.comment)})]})]})}function Ol({juan:e,searchQuery:n,onNavigate:i,transport:r,workLabelCache:o}){const{convert:s}=P(),l=He(),c=n.trim(),a=f.useMemo(()=>c?e.sections.filter(x=>Nn(x,c,!0,l)):e.sections,[e.sections,c,l]),d=e.sections.filter(x=>ge(x.type)==="考证").length,p=a.filter(x=>ge(x.type)==="考证").length;return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"4px"},children:[t.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:s(e.title)}),t.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:c?`${p} / ${d} 條`:`${d} 條`})]}),e.source_url&&t.jsx("div",{style:{marginBottom:"12px"},children:t.jsx("a",{href:e.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:"原文來源"})}),t.jsx("div",{children:a.map((x,g)=>t.jsx(Pl,{section:x,onNavigate:i,transport:r,workLabelCache:o,highlightQuery:c},g))}),a.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function Hl({text:e,highlightQuery:n=""}){const{convert:i}=P(),r=He(),o=l=>be(i(l),c=>n?ct(c,n,r):c),s=e.split(`
|
|
102
|
+
`);return t.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:s.map((l,c)=>{if(l.startsWith("# "))return t.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:o(l.slice(2))},c);if(l.startsWith("## "))return t.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:o(l.slice(3))},c);if(l.startsWith("### "))return t.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:o(l.slice(4))},c);if(!l.trim())return c>0&&!s[c-1].trim()?null:t.jsx("div",{style:{height:"0.5em"}},c);const a=l.split(/(\*\*[^*]+\*\*)/g);return t.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:a.map((d,p)=>d.startsWith("**")&&d.endsWith("**")?t.jsx("strong",{children:o(d.slice(2,-2))},p):t.jsx(f.Fragment,{children:o(d)},p))},c)})})}function Dl({sections:e,onNavigate:n,highlightQuery:i=""}){const{convert:r}=P(),o=je(),s=He(),l=d=>d?be(r(d),p=>i?ct(p,i,s):p):"",c=[];let a=null;for(const d of e){const p=ge(d.type);p==="page_header"&&!Xr(d)||(p==="类"?(a&&c.push(a),a={category:d.title,categoryContent:d.content||void 0,items:[]}):p==="书"||p==="诗"||p==="考证"||p==="注释"?(a||(a={category:"",items:[]}),a.items.push(d)):(p==="序"||p==="结语")&&(a||(a={category:"",items:[]}),a.items.push(d),p==="结语"&&(c.push(a),a=null)))}return a&&c.push(a),t.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:c.map((d,p)=>t.jsxs("div",{style:{marginBottom:"20px"},children:[d.category&&t.jsxs("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:[l(d.category),d.categoryContent&&t.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:l(d.categoryContent)})]}),d.items.map((x,g)=>ge(x.type)==="序"||ge(x.type)==="结语"?t.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:l(x.content||"")},g):t.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&x.work_id?t.jsx("a",{href:o(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:t.jsx("strong",{children:l(x.title)})}):t.jsx("strong",{children:l(x.title)}),x.content&&l(x.content)]},g))]},p))})}function Nl({juan:e,rawText:n,searchQuery:i,onNavigate:r}){const{convert:o}=P(),s=He(),[l,c]=f.useState("catalog"),a=i.trim(),d=f.useMemo(()=>a?e.sections.filter(u=>Nn(u,a,!1,s)):e.sections,[e.sections,a,s]),p=e.sections.filter(u=>ge(u.type)==="书").length,x=e.sections.filter(u=>ge(u.type)==="诗").length,g=a?d.filter(u=>ge(u.type)==="书"||ge(u.type)==="诗").length:null;return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"12px"},children:[t.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:o(e.title)}),t.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} 部书`:""}),t.jsx("div",{style:{display:"flex",gap:"2px"},children:["catalog","raw"].map(u=>t.jsx("button",{onClick:()=>c(u),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:u==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:l===u?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:l===u?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:u==="catalog"?"目錄":"原文"},u))})]}),l==="raw"&&(n?t.jsx(Hl,{text:n,highlightQuery:a}):t.jsx(Dl,{sections:e.sections,onNavigate:r,highlightQuery:a})),l==="catalog"&&d.map((u,b)=>{const y=ge(u.type);return y==="书"||y==="诗"||y==="考证"?t.jsx(Wl,{section:u,onNavigate:r,highlightQuery:a},b):y==="类"?t.jsx($l,{section:u,highlightQuery:a},b):t.jsx(Fl,{section:u,highlightQuery:a},b)}),l==="catalog"&&d.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function Zr(e){return e.juan_files&&e.juan_files.length>0?e.juan_files:e.files&&e.files.length>0?e.files.map(n=>n.filename):[]}function Vl(e){const n=Zr(e);return n.length>0?n[0]:null}function Gl(e){const{workId:n,transport:i,files:r,activeFile:o,activeJuan:s,activeRawText:l,query:c,isKaozhen:a}=e,d=He(),p=f.useRef(new Map),[x,g]=f.useState({});f.useEffect(()=>{o&&s&&p.current.set(o,{juan:s,rawText:l})},[o,s,l]),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)Nn(S,y,a,d)&&h++;return h===0&&b.rawText&&Il(b.rawText,y,d)&&(h=1),h},[a,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 T of r){const C=p.current.get(T);C?h[T]=u(C,b):(h[T]="loading",S.push(T))}g(h);const m=8;let j=0;const _=async()=>{var T;for(;j<S.length;){if(y)return;const C=j++,k=S[C];try{const[z,I]=await Promise.all([i.getCollatedJuan(n,k),((T=i.getCollatedJuanText)==null?void 0:T.call(i,n,k))??Promise.resolve(null)]),v={juan:z,rawText:I};if(p.current.set(k,v),y)return;g(E=>({...E,[k]:u(v,b)}))}catch{if(y)return;g(z=>({...z,[k]:0}))}}},w=Array.from({length:Math.min(m,S.length)},()=>_());return Promise.all(w),()=>{y=!0}},[c,n,i,r.join(","),u,d]),{matchStates:x}}const Gn=({index:e,workId:n,transport:i,onNavigate:r,activeJuan:o,onJuanChange:s,className:l,style:c})=>{const[a,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]=f.useState(null),[T,C]=f.useState(""),k=f.useRef(new Map),z=f.useRef(0),I=o??b,v=f.useCallback(F=>{y(F),s==null||s(F)},[s]),E=e||a;f.useEffect(()=>{e&&(x(!1),u(null))},[e]),f.useEffect(()=>{if(e||!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}},[e,n,i]),f.useEffect(()=>{if(E&&!I){const F=Vl(E);F&&v(F)}},[E,I,v]);const R=n||(E==null?void 0:E.work_id),M=f.useCallback(async F=>{var W;if(!R||!(i!=null&&i.getCollatedJuan))return;const J=++z.current;j(!0),S(null),w(null);try{const[K,ie]=await Promise.all([i.getCollatedJuan(R,F),((W=i.getCollatedJuanText)==null?void 0:W.call(i,R,F))??Promise.resolve(null)]);if(J!==z.current)return;S(K),w(ie)}catch{if(J!==z.current)return;S(null),w(null)}finally{J===z.current&&j(!1)}},[R,i]);f.useEffect(()=>{I&&M(I)},[I,M]);const $=F=>{v(F)};if(p)return t.jsx("div",{className:l,style:{...c,padding:"24px"},children:t.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(g)return t.jsx("div",{className:l,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g});if(!E)return null;const H=E.type==="kaozhen",A=Zr(E);return t.jsx(Ul,{className:l,style:c,index:E,allFiles:A,isKaozhen:H,effectiveWorkId:R,transport:i,activeFile:I,handleSelectFile:$,juanData:h,juanRawText:_,juanLoading:m,searchQuery:T,setSearchQuery:C,onNavigate:r,workLabelCacheRef:k})},Ul=({className:e,style:n,index:i,allFiles:r,isKaozhen:o,effectiveWorkId:s,transport:l,activeFile:c,handleSelectFile:a,juanData:d,juanRawText:p,juanLoading:x,searchQuery:g,setSearchQuery:u,onNavigate:b,workLabelCacheRef:y})=>{const{matchStates:h}=Gl({workId:s,transport:l,files:r,activeFile:c,activeJuan:d,activeRawText:p,query:g,isKaozhen:o}),S=t.jsxs(t.Fragment,{children:[t.jsx("input",{type:"text",placeholder:o?"搜索全部章节…":"搜索全部卷…",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"}}),t.jsx(Bl,{files:r,groups:i.juan_groups,activeFile:c,onSelect:a,juanMeta:i.juan_metadata,matchStates:h,vertical:!0})]});return t.jsx("div",{className:e,style:n,children:t.jsxs(Lr,{aside:S,children:[t.jsxs("div",{style:{marginBottom:"16px",display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[t.jsx("div",{children:o&&i.target_source&&t.jsxs("span",{children:["考證對象:",t.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:i.target_source})]})}),i.text_quality&&(()=>{const m=jl(i.text_quality.grade);return m?t.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:"文本質量:"}),t.jsx(Js,{content:qo[m],children:t.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:Jo[m],cursor:"help"},children:ir[m]})}),i.text_quality.source_note&&t.jsxs("span",{style:{marginLeft:"4px"},children:["— ",i.text_quality.source_note]})]}):null})()]}),x?t.jsx(et,{}):d?o?t.jsx(Ol,{juan:d,searchQuery:g,onNavigate:b,transport:l,workLabelCache:y}):t.jsx(Nl,{juan:d,rawText:p,searchQuery:g,onNavigate:b}):c?t.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null,i.references&&i.references.length>0&&t.jsxs("div",{style:{marginTop:"32px",paddingTop:"16px",borderTop:"1px solid var(--bim-widget-border, #eee)"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #aaa)",marginBottom:"8px",letterSpacing:"2px"},children:"參考文獻"}),i.references.map((m,j)=>t.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[t.jsxs("span",{children:[j+1,". "]}),m.url?t.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}):t.jsx("span",{children:m.title}),m.author&&t.jsxs("span",{children:[",",m.author]}),m.note&&t.jsxs("span",{children:["。",m.note]})]},j))]})]})})},Yl={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)"}},Kl={label:"其他",color:"var(--bim-desc-fg, #999)"},ql={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)"}},Jl={label:"待处理",color:"var(--bim-warning, #ff9800)"};function Xl(e){try{const n=new Date(e),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 e}}function Zl(e,n){if(!e)return!1;try{const i=new URL(e,n);if(i.protocol!=="http:"&&i.protocol!=="https:")return!1;const r=new URL(n);return i.hostname===r.hostname}catch{return!1}}const Un=({items:e,loading:n})=>{const i=je();return n?t.jsx(et,{}):e.length===0?t.jsx("div",{style:Ql,children:"暂无反馈"}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const o=Yl[r.type]||Kl,s=ql[r.status]||Jl,l=typeof window<"u"&&Zl(r.pageUrl,window.location.href);return t.jsxs("div",{style:ea,children:[t.jsxs("div",{style:ta,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...ki,background:o.color},children:o.label}),t.jsx("span",{style:{...ki,background:s.color},children:s.label})]}),t.jsx("span",{style:na,children:Xl(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&t.jsxs("div",{style:ia,children:[r.resourceId&&t.jsx("a",{href:i(r.resourceId),style:an,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(l?t.jsx("a",{href:r.pageUrl,style:an,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:an,children:r.pageUrl}))]}),t.jsx("div",{style:ra,children:r.content}),r.reply&&t.jsxs("div",{style:oa,children:[t.jsx("div",{style:sa,children:"回复"}),t.jsx("div",{children:r.reply})]})]},r.id)})})},Ql={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},ea={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},ta={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},ki={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},na={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},ia={fontSize:"12px",marginBottom:"6px"},an={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},ra={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},oa={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},sa={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},kn=({transport:e,onNavigate:n,recommendedIds:i,activeTab:r,onTabChange:o,feedbackApiUrl:s})=>{const l=N(),[c,a]=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($),o==null||o($)},[j,_]=f.useState(!0),[w,T]=f.useState(null),[C,k]=f.useState(null),[z,I]=f.useState(null);f.useEffect(()=>{let $=!1;if(e.getCounts)return e.getCounts().then(H=>{$||a({works:H.works,books:H.books,collections:H.collections})}).catch(()=>{}),()=>{$=!0}},[e]),f.useEffect(()=>{let $=!1;return(async()=>{if(i)return i;if(e.getRecommended)try{const A=await e.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){_(!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 K=null;if(e.getEntry)K=await e.getEntry(W.id);else{const ie=await e.getItem(W.id);ie&&(K={id:W.id,title:ie.title||W.id,type:ie.type||"work"})}if(K)return{...K,group:W.group,fallbackDescription:W.description}}catch{}return{id:W.id,title:W.title,type:Z.extractType(W.id),group:W.group,fallbackDescription:W.description}}));$||(p(J.filter(W=>W!==null)),_(!1))}),()=>{$=!0}},[e,i]);const v=f.useRef(!1),E=f.useRef(!1),R=f.useRef(!1);f.useEffect(()=>{if(S!=="catalog"||v.current)return;const $=e.getCatalogProgress??e.getResourceProgress;if(!$)return;v.current=!0;let H=!1;return $.call(e).then(A=>{H||T(A)}).catch(()=>{v.current=!1}),()=>{H=!0}},[e,S]),f.useEffect(()=>{if(S!=="collection"||E.current||!e.getCollectionProgress)return;E.current=!0;let $=!1;return e.getCollectionProgress().then(H=>{$||k(H)}).catch(()=>{E.current=!1}),()=>{$=!0}},[e,S]),f.useEffect(()=>{if(S!=="site"||R.current||!e.getSiteProgress)return;R.current=!0;let $=!1;return e.getSiteProgress().then(H=>{$||I(H)}).catch(()=>{R.current=!1}),()=>{$=!0}},[e,S]),f.useEffect(()=>{if(!s||S!=="feedback")return;let $=!1;return h(!0),fetch(s).then(H=>H.json()).then(H=>{!$&&H.success&&b(H.items||[])}).catch(()=>{}).finally(()=>{$||h(!1)}),()=>{$=!0}},[s,S]);const M=$=>{switch($){case"work":return"✍️";case"book":return"📖";case"collection":return"📚";case"entity":return"👤";default:return""}};return t.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:"var(--bim-fg, #333)"},children:t.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[t.jsxs("div",{style:{display:"flex",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"16px"},children:[t.jsx(xt,{label:l.home.recommendTab,active:S==="recommend",onClick:()=>m("recommend")}),t.jsx(xt,{label:l.home.catalogTab,active:S==="catalog",onClick:()=>m("catalog")}),t.jsx(xt,{label:l.home.collectionTab,active:S==="collection",onClick:()=>m("collection")}),t.jsx(xt,{label:l.home.siteTab,active:S==="site",onClick:()=>m("site")}),s&&t.jsx(xt,{label:l.home.feedbackTab,active:S==="feedback",onClick:()=>m("feedback")})]}),S==="recommend"&&t.jsx(la,{recommended:d,loading:j,onNavigate:n,getIcon:M,t:l}),S==="catalog"&&t.jsx(wi,{progress:w,t:l,onNavigate:n}),S==="collection"&&t.jsx(wi,{progress:C,t:l,onNavigate:n}),S==="site"&&t.jsx(ca,{progress:z,t:l,totalWorks:(c==null?void 0:c.works)??0}),S==="feedback"&&s&&t.jsx(Un,{items:u,loading:y})]})})},xt=({label:e,active:n,onClick:i})=>t.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:e}),la=({recommended:e,loading:n,onNavigate:i,getIcon:r,t:o})=>{const s=je();if(n)return t.jsx(et,{});if(e.length===0)return null;const l=new Map;for(const c of e){const a=c.group||o.home.recommendedBrowse;l.has(a)||l.set(a,[]),l.get(a).push(c)}return t.jsx(t.Fragment,{children:Array.from(l.entries()).map(([c,a])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:c}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(d=>{const p=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return t.jsxs("a",{href:s(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:[t.jsx("span",{style:{fontSize:"20px"},children:r(d.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:d.edition})]}),p&&t.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:p})]})]},d.id)})})]},c))})},wi=({progress:e,t:n,onNavigate:i})=>{if(!e)return t.jsx(et,{});const r=[...e.resources].sort((c,a)=>c.priority-a.priority),o=["in_progress","done","todo"],s={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},l={in_progress:"var(--bim-progress-active, #f59e0b)",done:"var(--bim-progress-done, #10b981)",todo:"var(--bim-progress-todo, #9ca3af)"};return t.jsx("div",{children:o.map(c=>{const a=r.filter(d=>d.status===c);return a.length===0?null:t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:l[c]}}),s[c]," (",a.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(d=>t.jsx(aa,{item:d,t:n,statusColor:l[c],onNavigate:i},d.id))})]},c)})})},aa=({item:e,t:n,statusColor:i,onNavigate:r})=>{const o=je(),s=e.total>0?Math.round(e.imported/e.total*100):0,l=e.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const c=e.edition?`${e.name}·${e.edition}`:e.name,a=e.collection_id||e.work_id;return a&&r?t.jsx("a",{href:o(a),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(a))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:c}):e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:c}):c})()}),t.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:e.collection_id?n.indexType.collection:e.work_id?n.indexType.work:l})]}),t.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?Tt(n.home.progressFormat,{imported:String(e.imported),total:String(e.total)}):n.home.totalPending})]}),e.total>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${s}%`,borderRadius:"2px",background:i,transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:e.description})]})},ca=({progress:e,t:n,totalWorks:i})=>{if(!e)return t.jsx(et,{});const r=[...e.resources].sort((a,d)=>a.priority-d.priority),o=r.filter(a=>a.imported>0),s=r.filter(a=>a.imported===0),l=o.reduce((a,d)=>Math.max(a,d.imported),0),c=i>0?Math.round(l/i*100):0;return t.jsxs("div",{children:[i>0&&t.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,": ",t.jsx("strong",{children:l.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",c,"%)"]}),o.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"var(--bim-progress-done, #10b981)"}}),n.home.statusInProgress," (",o.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:o.map(a=>t.jsx(_i,{item:a,t:n,totalWorks:i},a.id))})]}),s.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"var(--bim-progress-todo, #9ca3af)"}}),n.home.statusTodo," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(a=>t.jsx(_i,{item:a,t:n,totalWorks:i},a.id))})]})]})},_i=({item:e,t:n,totalWorks:i})=>{const r=i>0?Math.round(e.imported/i*100):0;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:t.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:e.name}):e.name})}),t.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:e.imported>0?`${e.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),e.imported>0&&i>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:"var(--bim-progress-done, #10b981)",transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:e.description})]})},Ci="(max-width: 768px)";function da(){const[e,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(Ci).matches);return f.useEffect(()=>{const i=window.matchMedia(Ci),r=o=>n(o.matches);return i.addEventListener("change",r),()=>i.removeEventListener("change",r)},[]),e}const pa=({transport:e,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:r,headerRight:o})=>{var H;const s=N(),{convert:l}=P(),c=da(),[a,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]=f.useState(null),[T,C]=f.useState(!1),k=f.useCallback(async A=>{if(!e.getCollatedEditionIndex){w(null);return}C(!0);try{const F=await e.getCollatedEditionIndex(A);w(F)}catch{w(null)}finally{C(!1)}},[e]),z=f.useCallback(async A=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){S([]);return}j(!0);try{if(e.getCollectionCatalogs){const F=await e.getCollectionCatalogs(A);S(F||[])}else if(e.getCollectionCatalog){const F=await e.getCollectionCatalog(A);S(F?[{resource_id:"",data:F}]:[])}}catch{S([])}finally{j(!1)}},[e]),I=f.useCallback(async A=>{if(i){i(A);return}d(A),x(null),S([]),w(null),y("detail"),u(!0);try{const F=await e.getItem(A.id);F&&(x(F),F.type==="collection"?z(A.id):F.type==="work"&&F.has_collated&&k(A.id))}catch(F){console.error("加载详情失败:",F)}finally{u(!1)}},[e,i,z,k]),v=f.useCallback(async A=>{x(null),S([]),w(null),y("detail"),u(!0);try{const F=await e.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&&k(A))}catch(F){console.error("导航失败:",F)}finally{u(!1)}},[e,z,k]),E=(p==null?void 0:p.type)==="collection"&&(h.length>0||m)||(p==null?void 0:p.type)==="work"&&(_||T),R=c&&(g||p),M=f.useCallback(()=>{d(null),x(null),S([]),w(null),y("detail")},[]),$=t.jsx(t.Fragment,{children:g?t.jsx(et,{}):p?t.jsxs(t.Fragment,{children:[(E||o)&&t.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:[E&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>y("detail"),style:At(b==="detail"),children:s.detailTab.basicInfo}),p.type==="collection"&&m&&h.length===0&&t.jsxs("button",{onClick:()=>{},style:At(!1),children:[s.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),p.type==="collection"&&h.map(A=>t.jsx("button",{onClick:()=>y(`catalog:${A.resource_id}`),style:At(b===`catalog:${A.resource_id}`),children:A.short_name?`${l(A.short_name)}${s.detailTab.catalogSuffix}`:s.detailTab.collectionCatalog},A.resource_id)),p.type==="work"&&(_||T)&&t.jsxs("button",{onClick:()=>y("collated"),style:At(b==="collated"),children:[s.detailTab.collatedEdition,T&&t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),o&&t.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:o})]}),t.jsx("div",{style:{padding:c?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?t.jsx(Bn,{data:p,transport:e,onNavigate:v}):b.startsWith("catalog:")?t.jsx(Ln,{data:(H=h.find(A=>`catalog:${A.resource_id}`===b))==null?void 0:H.data,onNavigate:v}):b==="collated"?t.jsx(Gn,{index:_||void 0,workId:p.id,transport:e,onNavigate:v}):null})]}):t.jsx(kn,{transport:e,onNavigate:v,recommendedIds:r})});return c?t.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:R?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",flexShrink:0},children:t.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:["← ",s.detailTab.basicInfo]})}),t.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:$})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(mn,{transport:e,onEntryClick:I,hideModeIndicator:n}),!p&&t.jsx(kn,{transport:e,onNavigate:v,recommendedIds:r})]})}):t.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:[t.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:t.jsx("div",{style:{flex:1,overflow:"auto"},children:t.jsx(mn,{transport:e,onEntryClick:I,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:$})]})};function At(e){return{padding:"10px 16px",border:"none",borderBottom:e?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:e?"var(--bim-primary, #0078d4)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}const Qr="guji-table-v1";function eo(e){return!!e&&e.table_notation===Qr}const ua=/^:::table(?:\{[^}]*\})?[ \t]*$/,fa=/^:::[ \t]*$/;function to(e){const n=[];let i="";for(let r=0;r<e.length;r++){const o=e[r];let s=null;if(o==="⟨")s="⟩";else if(o==="<"){const l=e[r+1];l!==void 0&&!/[A-Za-z/!?>\s]/.test(l)&&(s=">")}if(s){const l=e.indexOf(s,r+1);if(l>0){i+=e.slice(r,l+1),r=l;continue}}o==="|"?(n.push(i),i=""):i+=o}return n.push(i),n.map(r=>r.trim())}const xa=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function ga(e){if(e==="^")return{cont:!0};const n=xa.exec(e),i=n[1].trim(),r=n[2]?Math.max(1,parseInt(n[2],10)):1,o=n[3]?Math.max(1,parseInt(n[3],10)):1,s=i==="_";return{cont:!1,cell:{text:s?"":i,empty:s,colspan:r,rowspan:o}}}function no(e,n=1){const i=[],r=[],o=[];let s=[];e.forEach((c,a)=>{const d=a+n+1;let p=c.trim();if(!p)return;let x=!1;p.startsWith("!")&&(x=!0,p=p.slice(1));const g=to(p).map(ga),u=s.map(S=>S>0),b=s.map(S=>S>0?S-1:0),y=[];let h=0;for(const S of g){if(S.cont){u[h]||i.push(`第 ${d} 行第 ${h+1} 列:续格 ^ 上方没有跨行格`),h+=1;continue}const{cell:m}=S;for(let j=h;j<h+m.colspan;j++)if(u[j]){i.push(`第 ${d} 行第 ${j+1} 列:此处被上方跨行格占住,应写 ^`);break}if(m.rowspan>1)for(let j=h;j<h+m.colspan;j++)b[j]=m.rowspan-1;y.push(m),h+=m.colspan}for(let S=h;S<u.length;S++)u[S]&&i.push(`第 ${d} 行第 ${S+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let S=0;S<b.length;S++)b[S]===void 0&&(b[S]=0);s=b,r.push({header:x,cells:y}),o.push({width:h,line:d})});const l=o.reduce((c,a)=>Math.max(c,a.width),0);for(const c of o)c.width!==l&&i.push(`第 ${c.line} 行:占 ${c.width} 列,与总列数 ${l} 不符`);return s.some(c=>c>0)&&i.push("表尾:有跨行格超出了表的最后一行"),r.length===0&&i.push("空表"),{rows:r,columns:l,warnings:i}}function io(e){const n=e.split(`
|
|
103
|
+
`),i=[];let r=[];const o=()=>{if(r.length===0)return;const l=r.join(`
|
|
104
|
+
`);r=[],i.push({type:"text",text:l})};let s=0;for(;s<n.length;){if(ua.test(n[s].trim())){let l=s+1;for(;l<n.length&&!fa.test(n[l].trim());)l++;if(l<n.length){o();const c=n.slice(s+1,l);i.push({type:"table",table:no(c,s+1),source:n.slice(s,l+1).join(`
|
|
105
|
+
`)}),s=l+1;continue}}r.push(n[s]),s++}return o(),i.map((l,c)=>{var d,p;if(l.type!=="text")return l;let a=l.text;return((d=i[c-1])==null?void 0:d.type)==="table"&&(a=a.replace(/^\n+/,"")),((p=i[c+1])==null?void 0:p.type)==="table"&&(a=a.replace(/\n+$/,"")),{type:"text",text:a}}).filter(l=>l.type!=="text"||l.text!=="")}const ma={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},ha={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},ba="1px solid var(--bim-table-border, color-mix(in srgb, currentColor 28%, transparent))",ro={border:ba,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},ya={...ro,background:"var(--bim-table-head-bg, color-mix(in srgb, currentColor 8%, transparent))",fontWeight:600};function oo({table:e,opts:n}){return t.jsx("div",{className:"bim-guji-table-wrap",style:ma,children:t.jsx("table",{className:"bim-guji-table",style:ha,children:t.jsx("tbody",{children:e.rows.map((i,r)=>t.jsx("tr",{children:i.cells.map((o,s)=>{const l=i.header?"th":"td";return t.jsx(l,{colSpan:o.colspan>1?o.colspan:void 0,rowSpan:o.rowspan>1?o.rowspan:void 0,style:i.header?ya:ro,children:o.empty?null:be(o.text,void 0,n)},s)})},r))})})})}function va(e,n){return e.indexOf("**")<0?be(e,void 0,n):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((r,o)=>o%2===1?t.jsx("strong",{children:be(r.trim().slice(2,-2),void 0,n)},o):t.jsx(f.Fragment,{children:be(r,void 0,n)},o))}function so(e,n,i=!1){const r=i?{gujiMarkdown:!0}:void 0;return n?io(e).map((o,s)=>o.type==="table"?t.jsx(oo,{table:o.table,opts:r},s):t.jsx(f.Fragment,{children:va(o.text,r)},s)):be(e,void 0,r)}function Ue(e){return e.replace(/\.md$/,"")}function ja(e){let n="";if(e.source_url)try{const r=new URL(e.source_url).pathname.split("/").filter(Boolean).pop()??"";n=decodeURIComponent(r).replace(/_/g," ")}catch{}return[e.source_name,n||e.version_label].filter(Boolean).join(" · ")||e.key}const cn={padding:24,color:"var(--bim-desc-fg, #999)"},wn=({index:e,bookId:n,transport:i,activeChapter:r,onChapterChange:o,workKey:s,versions:l,onVersionChange:c})=>{const[a,d]=f.useState(e??null),[p,x]=f.useState(!1),[g,u]=f.useState(null),b=r!==void 0?r:g,y=f.useCallback(C=>{o?o(C):u(C)},[o]),[h,S]=f.useState(null),[m,j]=f.useState(!1);f.useEffect(()=>{e&&d(e)},[e]),f.useEffect(()=>{if(e)return;d(null),x(!1);const C=s!==void 0?i.getWorkFullTextIndex?()=>i.getWorkFullTextIndex(n,s):null:i.getBookFullTextIndex?()=>i.getBookFullTextIndex(n):null;if(!n||!C){x(!0);return}let k=!1;return Promise.resolve().then(C).then(z=>{k||(z?d(z):x(!0))}).catch(()=>{k||x(!0)}),()=>{k=!0}},[n,i,e,s]),f.useEffect(()=>{if(!a||a.chapters.length===0)return;const C=Ue(a.chapters[0].file);if(!b){y(C);return}const k=Ue(b);a.chapters.some(I=>Ue(I.file)===k)||y(C)},[a,b,y]);const _=f.useMemo(()=>{if(!a||!b)return null;const C=Ue(b);return a.chapters.find(k=>Ue(k.file)===C)??null},[a,b]);f.useEffect(()=>{if(!n||!_)return;const C=s!==void 0?i.getWorkFullTextChapter?z=>i.getWorkFullTextChapter(n,s,z):null:i.getBookFullTextChapter?z=>i.getBookFullTextChapter(n,z):null;if(!C)return;let k=!1;return j(!0),S(null),Promise.resolve(_.file).then(C).then(z=>{k||S(z)}).catch(()=>{k||S(null)}).finally(()=>{k||j(!1)}),()=>{k=!0}},[n,_,i,s]);const w=l&&l.length>1&&c?t.jsx("div",{style:{marginBottom:12,fontSize:13,color:"var(--bim-desc-fg, #888)"},children:t.jsxs("label",{children:["版本:",t.jsx("select",{value:s,onChange:C=>c(C.target.value),style:{fontSize:13,fontFamily:"inherit"},children:l.map(C=>t.jsx("option",{value:C.key,children:ja(C)},C.key))})]})}):null;if(!a)return p?t.jsxs("div",{style:cn,children:[w,"无法加载全文目录"]}):t.jsxs("div",{style:cn,children:[w,"加载全文目录…"]});if(a.chapters.length===0)return t.jsxs("div",{style:cn,children:[w,"全文目录为空"]});const T=t.jsxs(t.Fragment,{children:[t.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:a.version_label}),t.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:a.chapters.map(C=>{const k=Ue(C.file),z=k===Ue(b??"");return t.jsx("li",{children:t.jsx("button",{onClick:()=>y(k),style:{display:"block",width:"100%",textAlign:"left",padding:"6px 12px",background:z?"var(--bim-primary-bg, #fdf4f4)":"transparent",border:"none",borderLeft:z?"3px solid var(--bim-primary, #8B0000)":"3px solid transparent",color:z?"var(--bim-primary, #8B0000)":"var(--bim-fg, #2c2c2c)",cursor:"pointer",fontSize:14,lineHeight:1.5},children:C.title})},C.file)})})]});return t.jsx(Lr,{aside:T,children:t.jsxs("div",{children:[w,_&&t.jsxs("header",{style:{marginBottom:16,paddingBottom:12,borderBottom:"1px solid var(--bim-border, #e5e5e5)"},children:[t.jsx("h2",{style:{margin:0,fontSize:20,color:"var(--bim-fg, #2c2c2c)"},children:_.title}),t.jsxs("div",{style:{marginTop:6,fontSize:12,color:"var(--bim-desc-fg, #888)"},children:["来源:",t.jsx("a",{href:a.source.url,target:"_blank",rel:"noreferrer",style:{color:"var(--bim-primary, #8B0000)"},children:a.source.name}),a.source.license&&t.jsxs(t.Fragment,{children:[" · ",a.source.license]})]})]}),m&&t.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"加载中…"}),!m&&h&&t.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:so(h.replace(/^##\s+[^\n]+\n+/,""),eo(a)||yn(a),yn(a))}),!m&&!h&&t.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"无法加载章节内容"})]})})},Sa=({data:e,onNavigate:n,className:i,style:r})=>{var p;const o=N(),{convert:s}=P(),[l,c]=f.useState(((p=e.divisions[0])==null?void 0:p.name)??null),[a,d]=f.useState(null);return t.jsxs("div",{className:i,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:s(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"16px"},children:[e.total_volumes!=null&&t.jsxs("span",{children:[o.catalog.totalVolumes," ",t.jsx("strong",{children:e.total_volumes})," ",o.unit.juan]}),e.stats.zhulu!=null&&t.jsxs("span",{children:["著錄 ",t.jsx("strong",{children:e.stats.zhulu})," ",o.unit.bu]}),e.stats.cunmu!=null&&t.jsxs("span",{children:["存目 ",t.jsx("strong",{children:e.stats.cunmu})," ",o.unit.bu]}),e.stats.categories!=null&&t.jsxs("span",{children:[e.stats.categories," 類"]})]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(x=>t.jsx(ka,{division:x,expanded:l===x.name,onToggle:()=>c(l===x.name?null:x.name),expandedCat:a,onCatToggle:g=>d(a===g?null:g),onNavigate:n},x.name))})]})},ka=({division:e,expanded:n,onToggle:i,expandedCat:r,onCatToggle:o,onNavigate:s})=>{const{convert:l}=P(),c=e.categories.reduce((a,d)=>{const p=d.stats||{zhulu:0,cunmu:0};return a+(p.zhulu||0)+(p.cunmu||0)},0);return t.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[t.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:[t.jsx("span",{children:l(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[e.categories.length," 類 · ",c," 部",t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(a=>{const d=`${e.name}/${a.name}`;return t.jsx(wa,{category:a,expanded:r===d,onToggle:()=>o(d),onNavigate:s},a.name)})})]})},wa=({category:e,expanded:n,onToggle:i,onNavigate:r})=>{var a,d,p,x;const{convert:o}=P(),s=((a=e.books)==null?void 0:a.zhulu)||[],l=((d=e.books)==null?void 0:d.cunmu)||[],c=(((p=e.stats)==null?void 0:p.zhulu)||s.length)+(((x=e.stats)==null?void 0:x.cunmu)||l.length);return t.jsxs("div",{children:[t.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:[t.jsxs("span",{style:{fontWeight:500},children:[o(e.name),e.volumes&&t.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px",fontWeight:400},children:["卷",e.volumes]})]}),t.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[c," 部 ",n?"▲":"▼"]})]}),n&&(s.length>0||l.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[s.length>0&&t.jsx(Ti,{label:"著錄",books:s,onNavigate:r}),l.length>0&&t.jsx(Ti,{label:"存目",books:l,onNavigate:r})]})]})},Ti=({label:e,books:n,onNavigate:i})=>{const{convert:r}=P(),o=je(),[s,l]=f.useState(n.length<=20),c=s?n:n.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"4px",fontWeight:500},children:[e," (",n.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:c.map((a,d)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:a.work_id&&i?t.jsx("a",{href:o(a.work_id),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),i(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(a.title)}):r(a.title)}),a.volumes&&t.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(a.volumes)}),a.author&&t.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(a.author).slice(0,20)})]},d))}),!s&&t.jsxs("button",{onClick:()=>l(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},Te=({title:e,onSave:n,onAskAI:i,extraButtons:r,children:o})=>{const s=N();return t.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,i&&t.jsx("button",{onClick:i,style:Ca,children:"AI"}),n&&t.jsx("button",{onClick:n,style:_a,children:s.action.save})]})]}),o]})},_a={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Ca={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},ve=({label:e,value:n,onChange:i,placeholder:r,disabled:o})=>t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:{display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},children:e}),t.jsx("input",{type:"text",value:n,onChange:s=>i(s.target.value),placeholder:r,disabled:o,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"}})]}),Je=({value:e,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`)},[e]),t.jsx("textarea",{ref:r,value:e||"",onChange:o=>n(o.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"}})},Vt=({children:e,color:n,style:i})=>t.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:e});function Ta(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Pt=({value:e,onChange:n,label:i})=>{const[r,o]=f.useState(!1),s=f.useRef(null),l=Ta(e||"");return f.useEffect(()=>{r&&s.current&&s.current.focus()},[r]),!r&&l?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Ii,children:i}),t.jsxs("div",{onClick:()=>o(!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:[t.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:"var(--bim-fg, #333)"},children:l.name}),t.jsx(Vt,{children:l.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Ii,children:i}),t.jsx("input",{ref:s,type:"text",value:e||"",onChange:c=>n(c.target.value),onBlur:()=>o(!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"}})]})},Ii={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function Ia(e){switch(e){case"url":return"var(--bim-source-url, #2196f3)";case"bookID":return"var(--bim-source-bookid, #4caf50)";default:return"var(--bim-desc-fg, #717171)"}}function za(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const lo=({items:e,onChange:n,onOpenEntityPicker:i})=>{const r=N(),[o,s]=f.useState(null),l=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),s(e.length)},c=x=>{n(e.filter((g,u)=>u!==x)),o===x&&s(null)},a=(x,g,u)=>{const b=[...e];b[x]={...b[x],[g]:u},n(b)},d=(x,g)=>{const u=[...e];u[x]={...u[x],type:g,id:"",name:""},n(u),g==="bookID"&&i&&i(b=>{const y=[...e];y[x]={...y[x],id:b.id,name:b.title,type:"bookID"},n(y)})},p=x=>{i&&i(g=>{const u=[...e];u[x]={...u[x],id:g.id,name:g.title,type:"bookID"},n(u)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((x,g)=>t.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>s(o===g?null:g),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:o===g?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:x.name||`${r.editor.sourcePlaceholder} ${g+1}`}),x.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Ia(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:za(x.type)}),t.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:"✕"})]}),o===g&&t.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!x.type&&t.jsxs("div",{children:[t.jsx("label",{style:Me,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>d(g,"bookID"),style:{...zi,borderColor:"var(--bim-source-bookid, #4caf50)",color:"var(--bim-source-bookid, #4caf50)"},children:[t.jsx("span",{style:{fontSize:"18px"},children:"📚"}),t.jsx("span",{children:"Book ID"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),t.jsxs("button",{onClick:()=>d(g,"url"),style:{...zi,borderColor:"var(--bim-source-url, #2196f3)",color:"var(--bim-source-url, #2196f3)"},children:[t.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),t.jsx("span",{children:"URL"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),x.type==="bookID"&&t.jsx(t.Fragment,{children:t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:Me,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const u=[...e];u[g]={...u[g],type:"",id:"",name:""},n(u)},style:Ri,children:r.action.changeType})]}),x.id&&x.name?t.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:[t.jsx("span",{style:{color:"var(--bim-source-bookid, #4caf50)",fontSize:"16px"},children:"✓"}),t.jsxs("div",{style:{flex:1},children:[t.jsx("div",{style:{fontWeight:500},children:x.name}),t.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:x.id})]}),t.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})]}):t.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:[t.jsx("span",{children:"🔍"}),t.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),x.type==="url"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:Me,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const u=[...e];u[g]={...u[g],type:"",id:"",name:""},n(u)},style:Ri,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:x.name,onChange:u=>a(g,"name",u.target.value),placeholder:r.editor.sourceNamePlaceholder,style:tt})]}),t.jsxs("div",{children:[t.jsx("label",{style:Me,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:x.id,onChange:u=>a(g,"id",u.target.value),placeholder:"https://...",style:tt})]})]}),x.type&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{borderTop:"1px dashed var(--bim-widget-border, #e0e0e0)",paddingTop:"12px",marginTop:"4px"},children:t.jsx("label",{style:{...Me,opacity:.7},children:r.label.optionalInfo})}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:Me,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:x.details,onChange:u=>a(g,"details",u.target.value),placeholder:r.editor.detailsPlaceholder,style:tt})]}),t.jsxs("div",{children:[t.jsx("label",{style:Me,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:x.position,onChange:u=>a(g,"position",u.target.value),placeholder:"如: 卷三, p.52",style:tt})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:Me,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:x.version,onChange:u=>a(g,"version",u.target.value),placeholder:"如: v1.0, 2024-01",style:tt})]}),t.jsxs("div",{children:[t.jsx("label",{style:Me,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:x.processor_version,onChange:u=>a(g,"processor_version",u.target.value),placeholder:"如: v0.1",style:tt})]})]})]})]})})]},g)),t.jsxs("button",{onClick:l,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:r.action.addSource})]})]})},Me={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},tt={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"},zi={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"},Ri={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function ao(e){if(!e||!e.trim())return[];try{const n=JSON.parse(e);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 co(e){return!e||e.length===0?"":JSON.stringify(e)}const po=({entityType:e,entityId:n,entityTitle:i,parentWork:r,parentCollection:o,belongsToWork:s,belongsToCollection:l,childWorks:c,childCollections:a,containedBooks:d,siblingBooks:p,onLinkEntity:x,onUnlinkEntity:g,onViewEntity:u,onCreateAndLink:b,onSaveRelations:y})=>{const h=N();return t.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.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:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:"🔗"}),t.jsx("span",{children:h.section.relations})]}),y&&t.jsx("button",{onClick:y,style:Ra,children:h.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(gt,{direction:"up",title:h.relation.belongsToWork,entity:s,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}),t.jsx(gt,{direction:"up",title:h.relation.containedInCollection,entity:l,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}),s&&p&&p.length>0&&t.jsx(nt,{direction:"horizontal",title:`${h.relation.siblingVersions} (${p.length})`,entities:p,onView:u,onAdd:()=>b("siblingBook","book",{workId:s.id}),addLabel:h.relation.addVersionForWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(gt,{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&&t.jsx(nt,{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}),a&&a.length>0&&t.jsx(nt,{direction:"down",title:`${h.relation.collectionImpl} (${a.length})`,entities:a,onView:u,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:h.action.addCollectionImpl,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(nt,{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})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx(gt,{direction:"up",title:h.relation.correspondingWork,entity:s,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}),t.jsx(gt,{direction:"up",title:h.relation.parentCollection,entity:o,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}),t.jsx(nt,{direction:"down",title:`${h.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:u,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:h.action.addSubCollection,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(nt,{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})]})]})]})},gt=({direction:e,title:n,entity:i,onView:r,onUnlink:o,onLink:s,onCreate:l,linkLabel:c,createLabel:a,notLinkedLabel:d,viewLabel:p,unlinkLabel:x})=>{const g=e==="up"?"var(--bim-relation-up, #2196f3)":e==="down"?"var(--bim-relation-down, #4caf50)":"var(--bim-relation-flat, #ff9800)",u=e==="up"?"⬆️":e==="down"?"⬇️":"↔️";return t.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[t.jsxs("div",{style:{fontSize:"12px",color:g,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:u}),t.jsx("span",{children:n})]}),i?t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:uo(i.type)}),t.jsx("span",{style:{fontWeight:500},children:i.title}),t.jsx("span",{style:{fontSize:"11px",opacity:.6},children:i.id})]}),t.jsxs("div",{style:{display:"flex",gap:"4px"},children:[t.jsx(Ei,{onClick:()=>r(i),title:p,children:"👁️"}),t.jsx(Ei,{onClick:o,title:x,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:d}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(_n,{onClick:s,children:c}),t.jsx(_n,{onClick:l,primary:!0,children:a})]})]})},nt=({direction:e,title:n,entities:i,onView:r,onAdd:o,addLabel:s,noneLabel:l,expandMoreLabel:c})=>{const[a,d]=f.useState(!1),p=e==="up"?"var(--bim-relation-up, #2196f3)":e==="down"?"var(--bim-relation-down, #4caf50)":"var(--bim-relation-flat, #ff9800)",x=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",g=a?i:i.slice(0,5);return t.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[t.jsxs("div",{style:{fontSize:"12px",color:p,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:x}),t.jsx("span",{children:n})]}),i.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[g.map(u=>t.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:[t.jsx("span",{children:uo(u.type)}),t.jsx("span",{children:u.title})]},u.id)),i.length>5&&!a&&t.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,")"]})]}):t.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:l}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(_n,{onClick:o,primary:!0,children:["+ ",s]})})]})},Ei=({onClick:e,title:n,danger:i,children:r})=>t.jsx("button",{onClick:o=>{o.stopPropagation(),e()},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}),_n=({onClick:e,primary:n,children:i})=>t.jsx("button",{onClick:e,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 uo(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Ra={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"},fo=({isOpen:e,entityType:n,title:i,onSelect:r,onCancel:o,onCreate:s,searchResults:l,onSearch:c,isLoading:a,excludeId:d})=>{const[p,x]=f.useState(""),g=d?l.filter(h=>h.id!==d):l;f.useEffect(()=>{e&&(x(""),c(""))},[e]);const u=h=>{x(h),c(h)};if(!e)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",y=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:Ea,children:t.jsxs("div",{style:Ba,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:i}),t.jsx("button",{onClick:o,style:La,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:p,onChange:h=>u(h.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:Wa})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?t.jsx("div",{style:dn,children:"搜索中..."}):g.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:g.map(h=>t.jsxs("div",{onClick:()=>r(h),style:$a,children:[t.jsx("span",{style:{fontSize:"16px"},children:y}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[h.title,h.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:h.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[h.id,h.author&&` · ${h.author}`,h.dynasty&&` · ${h.dynasty}`]})]})]},h.id))}):p?t.jsxs("div",{style:dn,children:["未找到匹配的",b]}):t.jsxs("div",{style:dn,children:["输入关键词搜索",b]})}),t.jsxs("div",{style:{padding:"12px 16px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsxs("button",{onClick:s,style:Aa,children:["创建新",b,"并关联"]})]})]})})},Ea={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},Ba={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)"},La={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Wa={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"},$a={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},dn={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},Aa={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Bi={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Fa={work:"📜",book:"📖",collection:"📚",entity:"👤"},xo=({isOpen:e,entityType:n,relationField:i,inheritData:r,onConfirm:o,onCancel:s})=>{const[l,c]=f.useState(""),a=f.useRef(null);f.useEffect(()=>{e&&(c((r==null?void 0:r.title)||""),setTimeout(()=>{var g,u;(g=a.current)==null||g.focus(),(u=a.current)==null||u.select()},100))},[e,r==null?void 0:r.title]);const d=g=>{g.key==="Enter"&&l.trim()?p():g.key==="Escape"&&s()},p=()=>{l.trim()&&o(l.trim(),{...r,title:l.trim()})};if(!e)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`创建新${Bi[n]}`}};return t.jsx("div",{style:Ma,onClick:g=>{g.target===g.currentTarget&&s()},children:t.jsxs("div",{style:Pa,onClick:g=>g.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Fa[n]}),t.jsx("span",{children:x()})]}),t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",t.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),t.jsx("input",{ref:a,type:"text",value:l,onChange:g=>c(g.target.value),onKeyDown:d,placeholder:`请输入${Bi[n]}名称...`,style:Oa})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&t.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:[t.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&t.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&t.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[t.jsx("button",{onClick:s,style:Ha,children:"取消"}),t.jsx("button",{onClick:p,disabled:!l.trim(),style:{...Da,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Ma={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},Pa={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)"},Oa={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"},Ha={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Da={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Na(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function go(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Va(e){switch(e){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 mo=({isOpen:e,title:n,filterType:i="all",recentEntities:r=[],excludeId:o,showCreateButton:s=!1,createButtonText:l,onSelect:c,onCancel:a,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(()=>{e&&(g(""),b([]),m(r.length>0?"recent":"search"))},[e,r.length]),f.useEffect(()=>{if(!x.trim()){b([]);return}const k=setTimeout(async()=>{h(!0);try{b(await p(x,i))}catch{b([])}finally{h(!1)}},300);return()=>clearTimeout(k)},[x,i,p]);const j=f.useCallback(k=>{g(k.target.value),k.target.value.trim()&&m("search")},[]),_=f.useCallback(k=>o?k.filter(z=>z.id!==o):k,[o]);if(!e)return null;const w=n||(i==="all"?"选择实体":`选择${go(i)}`),T=_(r),C=_(u);return t.jsx("div",{style:Ua,children:t.jsxs("div",{style:Ya,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[t.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:w}),t.jsx("button",{onClick:a,style:Ka,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:x,onChange:j,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:qa}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),y&&t.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),T.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[t.jsxs(Li,{active:S==="recent",onClick:()=>m("recent"),children:["最近使用 (",T.length,")"]}),t.jsxs(Li,{active:S==="search",onClick:()=>m("search"),children:["搜索结果 ",C.length>0&&`(${C.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:S==="recent"&&T.length>0?t.jsx(Wi,{entities:T,onSelect:c}):x.trim()?y?t.jsx(pn,{message:"搜索中..."}):C.length>0?t.jsx(Wi,{entities:C,onSelect:c}):t.jsx(pn,{message:"未找到匹配的结果"}):t.jsx(pn,{message:"输入关键词开始搜索"})}),s&&d&&t.jsxs("div",{style:{padding:"12px 20px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsx("button",{onClick:d,style:Ja,children:l||"创建新实体"})]})]})})},Li=({active:e,onClick:n,children:i})=>t.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:e?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:e?"var(--bim-fg, #333)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",fontWeight:e?600:400,marginBottom:"-1px"},children:i}),Wi=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(i=>t.jsx(Ga,{entity:i,onClick:()=>n(i)},i.id))}),Ga=({entity:e,onClick:n})=>{const[i,r]=f.useState(!1);return t.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:[t.jsx("span",{style:{fontSize:"18px"},children:Na(e.type)}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[e.title,e.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:e.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[t.jsx("code",{style:{fontSize:"10px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"1px 4px",borderRadius:"2px"},children:e.id}),e.author&&t.jsx("span",{children:e.author}),e.dynasty&&t.jsx("span",{children:e.dynasty})]})]}),t.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:Va(e.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:go(e.type)})]})},pn=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:e}),Ua={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},Ya={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)"},Ka={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},qa={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"},Ja={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Xa={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)"},Za={work:"📜",collection:"📚",book:"📖",entity:"👤"},ho=({data:e,onChange:n,onSave:i,transport:r,onNavigate:o,showDelete:s,onDelete:l,onAskAI:c,renderSectionActions:a,onDownloadResource:d,downloadStatuses:p,relations:x,onRelationsChange:g})=>{var ee;const u=N(),[b,y]=f.useState(!1),[h,S]=f.useState("work"),[m,j]=f.useState(""),[_,w]=f.useState(""),[T,C]=f.useState([]),[k,z]=f.useState(!1),[I,v]=f.useState(!1),[E,R]=f.useState("work"),[M,$]=f.useState(""),[H,A]=f.useState(),[F,J]=f.useState(!1),[W,K]=f.useState(null),[ie,Y]=f.useState([]);f.useRef(null);const L=e.type,q=L==="work",X=L==="collection",G=L==="book",U=f.useCallback((B,Q)=>{n({...e,[B]:Q})},[e,n]),ce=f.useCallback((B,Q)=>{j(B),S(Q),w(u.editor.selectToLink+u.indexType[Q]),C([]),y(!0)},[u]),we=f.useCallback(B=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,B)},[r,e.id]),fe=f.useCallback(B=>{o==null||o(B.id,B.type)},[o]),ae=f.useCallback((B,Q,le)=>{const oe={...le,author:(le==null?void 0:le.author)||e.author,dynasty:le==null?void 0:le.dynasty};R(Q),$(B),A(oe),v(!0)},[e.author]),Se=f.useCallback((B,Q)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,M,{type:E,title:B,inheritData:Q}),v(!1)},[r,e.id,M,E]),Ee=f.useCallback(B=>{if(!B.trim()){C([]);return}z(!0),r!=null&&r.searchEntities&&r.searchEntities(B,h).then(Q=>{C(Q),z(!1)}).catch(()=>{C([]),z(!1)})},[r,h]),dt=f.useCallback(B=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,m,B.id),y(!1)},[r,e.id,m]),Fe=f.useCallback(()=>{i()},[i]),Be=f.useCallback(B=>{K(()=>B),J(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(Y).catch(()=>{})},[r]),D=f.useCallback((B,Q)=>r!=null&&r.searchEntities?r.searchEntities(B,Q==="all"?void 0:Q):Promise.resolve([]),[r]),se=f.useCallback(B=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(B),Y(Q=>[B,...Q.filter(le=>le.id!==B.id)].slice(0,10)),W==null||W(B),J(!1),K(null)},[r,W]);return t.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[t.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",paddingBottom:"16px"},children:t.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Za[L]}),t.jsx("span",{children:e.title||u.editor.untitled}),t.jsx(Vt,{children:e.id}),t.jsx(Vt,{color:Xa[L],children:u.indexType[L]})]})}),t.jsx(Te,{title:u.section.basicInfo,onSave:i,onAskAI:c?()=>c("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(Pt,{label:q?u.editor.workTitle:X?u.editor.collectionTitle:u.editor.bookTitle,value:e.title,onChange:B=>U("title",B)}),G&&t.jsx(Pt,{label:u.editor.belongsToWork,value:e.workName||"",onChange:B=>U("workName",B)}),t.jsx(ve,{label:u.editor.authorLabel,value:e.author||"",onChange:B=>U("author",B)}),t.jsx(ve,{label:u.editor.publicationYearLabel,value:e.publicationYear||"",onChange:B=>U("publicationYear",B)}),(G||X)&&t.jsx(Pt,{label:u.editor.containedIn,value:e.collection||"",onChange:B=>U("collection",B)}),(G||X)&&t.jsx(ve,{label:u.editor.holderLabel,value:e.holder||"",onChange:B=>U("holder",B)}),(G||X)&&t.jsx(ve,{label:G?u.editor.pageLabel:u.editor.volumeLabel,value:e.pages||"",onChange:B=>U("pages",B)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(ve,{label:u.editor.firstImageLabel,value:e.firstImage||"",onChange:B=>U("firstImage",B)})})]})}),t.jsx(Te,{title:u.section.description,onSave:i,onAskAI:c?()=>c("介绍"):void 0,children:t.jsx(Je,{value:e.description||"",onChange:B=>U("description",B),placeholder:u.editor.descriptionPlaceholder})}),(((ee=e.additional_works)==null?void 0:ee.length)||0)>0&&t.jsx(Te,{title:u.section.additionalWorks,onSave:i,children:t.jsx(Qa,{items:e.additional_works||[],onChange:B=>U("additional_works",B)})}),t.jsx(Te,{title:u.section.indexedBy,onSave:i,onAskAI:c?()=>c("收录于"):void 0,children:t.jsx(ec,{items:e.indexed_by||[],onChange:B=>U("indexed_by",B)})}),t.jsx(Te,{title:u.section.emendatedBy,onSave:i,onAskAI:c?()=>c("考证"):void 0,children:t.jsx(tc,{items:e.emendated_by||[],onChange:B=>U("emendated_by",B)})}),t.jsx(Te,{title:u.section.textResources,onSave:i,onAskAI:c?()=>c("资源"):void 0,children:t.jsx(gn,{items:e.resources||[],onChange:B=>U("resources",B),onDownload:d,downloadStatuses:p,filterType:"text"})}),t.jsx(Te,{title:u.section.imageResources,onSave:i,children:t.jsx(gn,{items:e.resources||[],onChange:B=>U("resources",B),onDownload:d,downloadStatuses:p,filterType:"image"})}),t.jsx(Te,{title:u.section.sources,onSave:i,onAskAI:c?()=>c("资料来源"):void 0,children:t.jsx(lo,{items:ao(e.sources||""),onChange:B=>U("sources",co(B)),onOpenEntityPicker:Be})}),(G||X)&&t.jsx(Te,{title:u.section.provenance,onSave:i,onAskAI:c?()=>c("收藏历史"):void 0,children:t.jsx(Je,{value:e.provenance||"",onChange:B=>U("provenance",B),placeholder:u.editor.provenancePlaceholder})}),G&&t.jsx(Te,{title:u.section.otherEditions,onSave:i,onAskAI:c?()=>c("其他版本"):void 0,children:t.jsx(Je,{value:e.otherEditions||"",onChange:B=>U("otherEditions",B),placeholder:u.editor.otherEditionsPlaceholder})}),t.jsx(po,{entityType:L,entityId:e.id,entityTitle:e.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:ce,onUnlinkEntity:we,onViewEntity:fe,onCreateAndLink:ae,onSaveRelations:Fe}),s&&l&&t.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:[t.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:u.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:u.editor.dangerZoneDesc}),t.jsx("button",{onClick:l,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:u.editor.deleteEntity})]}),t.jsx(fo,{isOpen:b,entityType:h,title:_,onSelect:dt,onCancel:()=>y(!1),onCreate:()=>{y(!1),ae(m,h)},searchResults:T,onSearch:Ee,isLoading:k,excludeId:e.id}),t.jsx(xo,{isOpen:I,entityType:E,relationField:M,inheritData:H,onConfirm:Se,onCancel:()=>v(!1)}),t.jsx(mo,{isOpen:F,title:u.action.selectBookOrWork,filterType:"all",recentEntities:ie,excludeId:e.id,onSelect:se,onCancel:()=>{J(!1),K(null)},onSearch:D})]})};function Qa({items:e,onChange:n}){const i=N(),r=(l,c,a)=>{const d=e.map((p,x)=>x===l?{...p,[c]:a}:p);n(d)},o=l=>n(e.filter((c,a)=>a!==l)),s=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((l,c)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(ve,{label:i.editor.bookNameLabel,value:l.book_title,onChange:a=>r(c,"book_title",a)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(ve,{label:i.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:a=>r(c,"n_juan",a&&parseInt(a,10)||void 0)})}),t.jsx("button",{onClick:()=>o(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)),t.jsx("button",{onClick:s,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 bo({items:e,onChange:n,showMeta:i,addLabel:r}){const o=N(),[s,l]=f.useState(null),c=(p,x,g)=>{const u=e.map((b,y)=>y===p?{...b,[x]:g||void 0}:b);n(u)},a=p=>{n(e.filter((x,g)=>g!==p)),s===p&&l(null)},d=()=>{n([...e,{source:""}]),l(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((p,x)=>{const g=s===x;return t.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>l(g?null:x),children:[t.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:g?"rotate(90deg)":"none"},children:"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:p.source||o.editor.unnamedSource}),p.source_bid&&t.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:p.source_bid}),t.jsx("button",{onClick:u=>{u.stopPropagation(),a(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)&&t.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&&t.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(ve,{label:o.label.sourceName,value:p.source,onChange:u=>c(x,"source",u)}),t.jsx(ve,{label:o.label.sourceBid,value:p.source_bid||"",onChange:u=>c(x,"source_bid",u)})]}),i&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(ve,{label:o.label.titleInfo,value:p.title_info||"",onChange:u=>c(x,"title_info",u)}),t.jsx(ve,{label:o.label.authorInfo,value:p.author_info||"",onChange:u=>c(x,"author_info",u)})]}),t.jsx(ve,{label:o.label.edition,value:p.edition||"",onChange:u=>c(x,"edition",u)})]}),t.jsx(Je,{value:p.summary||"",onChange:u=>c(x,"summary",u),placeholder:o.editor.summaryPlaceholder}),t.jsx(Je,{value:p.comment||"",onChange:u=>c(x,"comment",u),placeholder:o.editor.commentPlaceholder}),t.jsx(Je,{value:p.additional_comment||"",onChange:u=>c(x,"additional_comment",u),placeholder:o.editor.additionalCommentPlaceholder})]})]},x)}),t.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 ec({items:e,onChange:n}){const i=N();return t.jsx(bo,{items:e,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function tc({items:e,onChange:n}){const i=N();return t.jsx(bo,{items:e,onChange:n,addLabel:i.action.addEmendatedBy})}function yo(e){var c,a,d,p,x,g,u;const n=((a=(c=e.authors)==null?void 0:c[0])==null?void 0:a.name)||"",i=((d=e.publication_info)==null?void 0:d.year)||"",r=((p=e.current_location)==null?void 0:p.name)||"",o=(x=e.page_count)!=null&&x.number?String(e.page_count.number):((g=e.page_count)==null?void 0:g.description)||"",s=typeof e.description=="object"&&e.description!==null&&e.description.text||"",l={id:e.id,title:e.title,type:e.type,author:n,publicationYear:i,holder:r,pages:o,description:s,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};if(e.type==="work"){const b=e;if(Array.isArray(b.related_works)){const y=b.related_works.find(h=>h.relation==="part_of");y&&(l.parentWorkId=y.id,l.parentWorkName=y.title)}}if(e.type==="book"){const b=e;l.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(l.collectionId=(u=b.contained_in[0])==null?void 0:u.id)}return l}function nc(e){const n={id:e.id,title:e.title,type:e.type,description:e.description?{text:e.description}:void 0,authors:e.author?[{name:e.author}]:void 0,publication_info:e.publicationYear?{year:e.publicationYear}:void 0,current_location:e.holder?{name:e.holder}:void 0,page_count:e.pages?{number:parseInt(e.pages)||0,description:e.pages}:void 0,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};return e.type==="work"&&e.parentWorkId&&(n.related_works=[{id:e.parentWorkId,title:e.parentWorkName||"",relation:"part_of"}]),e.type==="book"&&(n.work_id=e.workId,e.collectionId&&(n.contained_in=[{id:e.collectionId}])),n}const ic=e=>{const{data:n,id:i,transport:r,mode:o="view",onModeChange:s,onChange:l,onSave:c,onDelete:a,onNavigate:d,renderLink:p,onAskAI:x,renderSectionActions:g,onDownloadResource:u,downloadStatuses:b,relations:y,onRelationsChange:h,headerExtra:S,className:m,style:j}=e;N();const[_,w]=f.useState(o),T=s?o:_;f.useEffect(()=>{o!==_&&w(o)},[o]);const C=f.useCallback(()=>{const M=T==="view"?"edit":"view";s?s(M):w(M)},[T,s]),[k,z]=f.useState(null);f.useEffect(()=>{i&&r&&r.getItem(i).then(M=>{M&&z(M)})},[i,r]);const I=n||k,v=f.useMemo(()=>I?yo(I):null,[I]),E=s||!n?t.jsx("button",{onClick:C,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:T==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:T==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:T==="view"?"切换到编辑模式":"切换到查看模式",children:T==="view"?"✏️ 编辑":"👁 查看"}):null,R=t.jsxs(t.Fragment,{children:[E,S]});return!I&&!v?t.jsx(et,{}):T==="view"?t.jsx(Bn,{data:I,transport:r,onNavigate:d?M=>d(M):void 0,renderLink:p,headerExtra:R,className:m,style:j}):v?t.jsxs("div",{className:m,style:j,children:[R&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:R}),t.jsx(ho,{data:v,onChange:l||(()=>{}),onSave:c||(()=>{}),transport:r,onNavigate:d,showDelete:!!a,onDelete:a,onAskAI:x,renderSectionActions:g,onDownloadResource:u,downloadStatuses:b,relations:y,onRelationsChange:h})]}):t.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:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],vo=({isOpen:e,onClose:n,onSubmit:i,feedbackListUrl:r})=>{const[o,s]=f.useState(null),[l,c]=f.useState(""),[a,d]=f.useState(""),[p,x]=f.useState("idle"),[g,u]=f.useState(""),b=f.useRef(null);f.useEffect(()=>{e&&(s(null),c(""),d(""),x("idle"),u(""))},[e]),f.useEffect(()=>{o&&setTimeout(()=>{var m;return(m=b.current)==null?void 0:m.focus()},100)},[o]),f.useEffect(()=>{if(p==="success"){const m=setTimeout(n,2e3);return()=>clearTimeout(m)}},[p,n]),f.useEffect(()=>{if(!e)return;const m=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[e,n]);const y=async()=>{if(!(!o||!l.trim())){x("submitting"),u("");try{await i({type:o,content:l.trim(),...a.trim()?{contact:a.trim()}:{}}),x("success")}catch(m){x("error"),u(m instanceof Error?m.message:"提交失败,请稍后重试")}}};if(!e)return null;const h=o&&l.trim()&&p!=="submitting",S=$i.find(m=>m.value===o);return t.jsx("div",{style:rc,onClick:m=>{m.target===m.currentTarget&&n()},children:t.jsxs("div",{style:oc,onClick:m=>m.stopPropagation(),children:[t.jsxs("div",{style:sc,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),t.jsx("button",{onClick:n,style:lc,"aria-label":"关闭",children:"✕"})]}),p==="success"?t.jsxs("div",{style:uc,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&t.jsx("a",{href:r,style:{fontSize:"13px",color:"var(--bim-primary, #2563eb)",marginTop:"8px"},children:"查看反馈列表 →"})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:$i.map(m=>t.jsxs("button",{onClick:()=>s(m.value),style:{...ac,...o===m.value?cc:{}},children:[t.jsx("span",{children:m.icon})," ",m.label]},m.value))}),t.jsx("textarea",{ref:b,value:l,onChange:m=>c(m.target.value),placeholder:(S==null?void 0:S.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!o||p==="submitting",style:{...dc,opacity:o?1:.6}}),t.jsx("input",{type:"text",value:a,onChange:m=>d(m.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!o||p==="submitting","aria-label":"联系方式(选填)",style:xc}),t.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[l.length," / 2000"]}),p==="error"&&t.jsx("div",{style:fc,children:g}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:y,disabled:!h,style:{...pc,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交反馈"})})]})]})})},rc={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},oc={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)"},sc={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},lc={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},ac={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"},cc={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},dc={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"},pc={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},uc={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},fc={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},xc={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"},gc=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:i})=>{const[r,o]=f.useState(!1);return t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>o(!0),style:{...mc,bottom:n.bottom,right:n.right},"aria-label":"反馈",title:"反馈",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.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"})})}),t.jsx(vo,{isOpen:r,onClose:()=>o(!1),onSubmit:e,feedbackListUrl:i})]})},mc={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"},Ai=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],jo=({onSubmit:e})=>{const[n,i]=f.useState("bug"),[r,o]=f.useState(""),[s,l]=f.useState(""),[c,a]=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())){a("submitting"),p("");try{await e({type:n,content:r.trim(),...s.trim()?{contact:s.trim()}:{}}),a("success"),o(""),l(""),i("bug")}catch(y){a("error"),p(y instanceof Error?y.message:"提交失败,请稍后重试")}}},u=n&&r.trim()&&c!=="submitting",b=Ai.find(y=>y.value===n);return c==="success"?t.jsx("div",{style:Fi,children:t.jsxs("div",{style:jc,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>a("idle"),style:Sc,children:"继续提交"})]})}):t.jsxs("div",{style:Fi,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Ai.map(y=>t.jsxs("button",{onClick:()=>i(y.value),style:{...hc,...n===y.value?bc:{}},children:[t.jsx("span",{children:y.icon})," ",y.label]},y.value))}),t.jsx("textarea",{ref:x,value:r,onChange:y=>o(y.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:c==="submitting",style:{...yc}}),t.jsx("input",{type:"text",value:s,onChange:y=>l(y.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:c==="submitting","aria-label":"联系方式(选填)",style:wc}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[r.length," / 2000"]}),t.jsx("button",{onClick:g,disabled:!u,style:{...vc,opacity:u?1:.6,cursor:u?"pointer":"not-allowed"},children:c==="submitting"?"提交中...":"提交"})]}),c==="error"&&t.jsx("div",{style:kc,children:d})]})},Fi={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},hc={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"},bc={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},yc={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"},vc={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},jc={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Sc={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},kc={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"},wc={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 Mi(e){return typeof e=="function"?e():e??"/api/feedback"}const So=({resourceId:e,apiUrl:n})=>{const[i,r]=f.useState([]),[o,s]=f.useState(!0),l=f.useCallback(async()=>{const a=Mi(n);s(!0);try{const p=await(await fetch(`${a}?resourceId=${encodeURIComponent(e)}`)).json();p.success&&r(p.items)}catch{}finally{s(!1)}},[e,n]);f.useEffect(()=>{l()},[l]);const c=async a=>{const d=Mi(n),p=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!p.ok){const x=await p.json().catch(()=>null);throw new Error((x==null?void 0:x.error)||"提交失败")}setTimeout(()=>l(),500)};return t.jsxs("div",{children:[t.jsx(Un,{items:i,loading:o}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(jo,{onSubmit:c})})]})},bt={versions:12,catalogs:8,chips:12},ko={leadWidth:22,metaWidth:424,mainLabel:"版本名稱",columns:[{label:"刊刻年代",width:"118px"},{label:"影印圖源",width:"156px"},{label:"收藏機構",width:"138px"}]},wo=({data:e,transport:n,onNavigate:i,renderLink:r,lineageAction:o,collatedSection:s})=>{var E,R,M,$,H,A,F,J,W,K,ie,Y;const l=N(),{convert:c}=P(),a=f.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.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",_=f.useMemo(()=>j?a:a.slice(0,bt.versions),[a,j]);f.useEffect(()=>{if(!n||_.length===0)return;const L=_.filter(X=>!d.has(X));if(L.length===0)return;let q=!1;return Promise.all(L.map(X=>n.getItem(X).then(G=>{const U=G??{};return[X,{id:X,title:U.title,edition:U.edition,resources:U.resources,publication_info:U.publication_info,current_location:U.current_location,lineage:U.lineage}]}).catch(()=>[X,{id:X}]))).then(X=>{q||p(G=>{const U=new Map(G);for(const[ce,we]of X)U.set(ce,we);return U})}),()=>{q=!0}},[n,_,d]);const w=f.useMemo(()=>a.map(L=>d.get(L)??{id:L}),[a,d]),T=f.useMemo(()=>kr(w,e.version_graph,{era:u,scanOnly:y,sort:S}),[w,e.version_graph,u,y,S]),C=x?T.rows:T.rows.slice(0,bt.versions),k=f.useMemo(()=>Kt(e.resources,e.resource_groups),[e.resources,e.resource_groups]),z=f.useMemo(()=>jr((e.related_works||[]).map(L=>({id:L.id,title:L.title,relation:L.relation}))),[e.related_works]),I=f.useMemo(()=>{var U,ce,we,fe;const L=[],q=(ce=(U=e.authors)==null?void 0:U[0])==null?void 0:ce.dynasty;q&&L.push({label:"成書",value:c(q)});const X=Ze(e,l.unit.juan);if(X){const ae=(we=e.juan_count)==null?void 0:we.description;L.push({label:"卷帙",value:c(X),title:ae?c(ae):void 0})}const G=T.allRows.filter(ae=>ae.sortYear!=null);if(G.length>0){const ae=G.reduce((Se,Ee)=>Se.sortYear<=Ee.sortYear?Se:Ee);ae.era.era&&L.push({label:"最早存世刻本",value:`${ae.era.era}${ae.era.reign?" "+ae.era.reign:""}`,title:ae.era.source==="edition"?"據版本題名推斷":void 0})}return(fe=e.indexed_by)!=null&&fe.length&&L.push({label:"著錄",value:`${e.indexed_by.length} ${l.unit.bu}`}),L},[e,c,l,T.allRows,j,a.length]),v=!s&&a.length===0&&k.buckets.length===0&&k.mirrors.length===0&&!((E=e.indexed_by)!=null&&E.length)&&!((R=e.emendated_by)!=null&&R.length)&&z.length===0&&!((M=e.description)!=null&&M.text);return t.jsxs(t.Fragment,{children:[t.jsxs(zt,{facts:I.length?t.jsx(Rt,{items:I}):void 0,children:[(($=e.description)==null?void 0:$.text)&&t.jsxs(t.Fragment,{children:[t.jsx(Oe,{text:e.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}),(H=e.description.sources)!=null&&H.length?t.jsx("div",{className:"bim-d-ui",style:{marginTop:8,fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:e.description.sources.map(L=>c(pl(L))).filter(Boolean).join(" · ")}):null]}),(A=e.appendix)==null?void 0:A.map((L,q)=>t.jsxs("details",{style:{marginTop:12},children:[t.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)}),t.jsx(Oe,{text:L.text,plainStrong:!0,style:{marginTop:10,fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"}})]},q)),t.jsx(Gr,{rows:[{label:l.section.aliases,items:_t(e.additional_titles)},{label:l.section.attachedTexts,items:_t(e.attached_texts)},{label:l.section.appendix,items:(e.additional_works||[]).map(L=>L.book_title+(L.n_juan!=null?` ${L.n_juan}${l.unit.juan}`:""))}]})]}),s,a.length>0&&t.jsxs(Re,{children:[t.jsx(xe,{glyph:"版",title:l.section.relatedVersions,count:T.rows.length===T.allRows.length?`${T.allRows.length} 種`:`${T.allRows.length} 種 · 當前 ${T.rows.length} 種`,actions:t.jsxs(t.Fragment,{children:[o,t.jsx(Ne,{label:"僅看有影印",active:y,dashed:!0,onClick:()=>{h(L=>!L),g(!1)}}),t.jsx(qt,{label:S==="default"?"排序:預設順序":"排序:年代先後",onClick:()=>m(L=>L==="default"?"year":"default")})]})}),T.allRows.length>=6&&T.eras.length>=2&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:14},children:[t.jsx(Ne,{label:l.catalog.all,active:!u,onClick:()=>{b(""),g(!1)}}),T.eras.map(L=>t.jsx(Ne,{label:L,active:u===L,onClick:()=>{b(L),g(!1)}},L))]}),t.jsxs(Qe,{children:[t.jsx(Xt,{spec:ko}),C.map((L,q)=>t.jsx(Tc,{row:L,no:q,onNavigate:i,renderLink:r},L.id)),C.length===0&&t.jsx(lt,{children:u||y?"當前篩選下沒有版本":"暫無版本著錄"})]}),T.rows.length>C.length&&t.jsx(Ve,{label:`展開其餘 ${T.rows.length-C.length} 種版本`,onClick:()=>g(!0)}),T.hasInferredEra&&t.jsx("div",{className:"bim-d-ui",style:{marginTop:10,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:"部分刊刻年代據版本題名推斷,非著錄原文"})]}),(k.buckets.length>0||k.mirrors.length>0)&&t.jsxs(Re,{children:[t.jsx(xe,{glyph:"源",title:"在線數字資源"}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(210px, 1fr))",gap:26},children:[k.mirrors.map(L=>t.jsx(vn,{title:c(L.label),tag:L.description?c(L.description):void 0,children:L.items.map((q,X)=>t.jsx(st,{item:q,siblings:L.items},`${q.id||q.url||q.name}-${X}`))},L.key)),k.buckets.map(L=>t.jsx(vn,{title:_c[L.key],tag:Cc[L.key],children:L.items.map((q,X)=>t.jsx(st,{item:q,siblings:L.items},`${q.id||q.url||q.name}-${X}`))},L.key))]})]}),(F=e.indexed_by)!=null&&F.length||(J=e.emendated_by)!=null&&J.length?t.jsxs("div",{className:(W=e.emendated_by)!=null&&W.length?"bim-d-pair":void 0,style:(K=e.emendated_by)!=null&&K.length?void 0:{marginBottom:48},children:[(ie=e.indexed_by)!=null&&ie.length?t.jsx(Oi,{id:"catalogs",glyph:"目",title:l.section.indexed,items:e.indexed_by,unit:l.unit.bu,cap:bt.catalogs,showMeta:!0,t:l,convert:c,onNavigate:i,renderLink:r}):null,(Y=e.emendated_by)!=null&&Y.length?t.jsx(Oi,{id:"studies",glyph:"考",title:l.section.emendated,items:e.emendated_by,unit:l.unit.bu,cap:bt.catalogs,t:l,convert:c,onNavigate:i,renderLink:r}):null]}):null,z.map(L=>t.jsx(Ic,{glyph:L.key==="derivative"?"續":"叢",title:l.section[L.labelKey]??l.section.relatedWorks,items:L.items,convert:c,onNavigate:i,renderLink:r},L.key)),v&&t.jsxs(Re,{style:{marginBottom:0},children:[t.jsx(xe,{glyph:"著",title:l.section.relatedVersions}),t.jsx(Qe,{children:t.jsx(lt,{children:"尚未著錄該作品的版本、資源與書目收錄。"})})]})]})},_c={text:"文字全文庫",image:"影印資源",textImage:"圖文對照",physical:"館藏"},Cc={text:"純文本",image:"原卷掃描",textImage:"圖文對照",physical:"實體"};function Tc({row:e,no:n,onNavigate:i,renderLink:r}){const{convert:o}=P(),s=[e.era.era,e.era.reign].filter(Boolean).join(" · "),l=e.era.source==="edition";return t.jsx(Zt,{no:Qt(n),spec:ko,main:t.jsx(ze,{id:e.id,label:o(e.name),onNavigate:i,renderLink:r,dense:!0,style:{fontWeight:e.important?600:400}}),meta:t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)",letterSpacing:".04em"},title:l?"據版本題名推斷":void 0,children:s||t.jsx(ot,{})}),t.jsx(Pi,{items:e.images,convert:o}),t.jsx(Pi,{items:e.holders,convert:o,fallback:e.locationName})]})})}function Pi({items:e,convert:n,fallback:i}){if(e.length===0)return i?t.jsx("span",{style:{minWidth:0},children:n(i)}):t.jsx(ot,{});if(e.length===1){const l=e[0],c=(l.url?kt(l.url):void 0)||n(l.name),a=Ht(l);return t.jsx("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},children:a?t.jsx(jn,{href:a,children:c}):c})}const r=e[0],o=(r.url?kt(r.url):void 0)||n(r.name),s=Ht(r);return t.jsxs("span",{style:{minWidth:0},children:[s?t.jsx(jn,{href:s,children:o}):o,t.jsxs("span",{className:"bim-d-ui",style:{marginLeft:4,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:["+",e.length-1]})]})}function Oi({id:e,glyph:n,title:i,items:r,unit:o,cap:s,showMeta:l,t:c,convert:a,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,s);return t.jsxs("section",{id:e,style:{scrollMarginTop:16},children:[t.jsx(xe,{glyph:n,tone:"ink",title:i,count:`${r.length} ${o}`,actions:t.jsx(qt,{label:y?"收起全部":"+ 展開提要",onClick:h})}),t.jsx(Qe,{children:S.map((m,j)=>{const _=m;return t.jsxs(Mr,{open:!!x[j],onToggle:()=>g(w=>({...w,[j]:!w[j]})),main:t.jsxs(t.Fragment,{children:[_.source_bid?t.jsx(ze,{id:_.source_bid,label:a(_.source),onNavigate:d,renderLink:p,dense:!0}):a(_.source),l&&_.section&&t.jsx("span",{className:"bim-d-ui",style:{marginLeft:8,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:a(_.section)})]}),action:_.source_bid?t.jsx(ze,{id:_.source_bid,label:c.action.view,onNavigate:d,renderLink:p,dense:!0,style:{fontFamily:"var(--bim-font-ui, system-ui, sans-serif)",fontSize:11.5,color:"var(--bim-meta-fg, #7b6a54)"}}):void 0,children:[l&&(_.title_info||_.author_info||_.edition)&&t.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:"4px 16px",marginBottom:8,fontSize:12,color:"var(--bim-meta-fg, #7b6a54)"},children:[_.title_info&&t.jsxs("span",{children:[c.label.titleInfo," ",a(_.title_info)]}),_.author_info&&t.jsxs("span",{children:[c.label.authorInfo," ",a(_.author_info)]}),_.edition&&t.jsxs("span",{children:[c.label.edition," ",a(_.edition)]})]}),_.summary&&t.jsx(Mt,{children:be(a(_.summary))}),_.comment&&t.jsx(Mt,{label:c.section.comment,children:be(a(_.comment))}),_.additional_comment&&t.jsx(Mt,{label:c.section.additionalComment,children:be(a(_.additional_comment))}),l&&_.page&&t.jsx("div",{className:"bim-d-ui",style:{fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:_.page})]},j)})}),r.length>S.length&&t.jsx(Ve,{label:`展開其餘 ${r.length-S.length} ${o}`,onClick:()=>b(!0)})]})}function Ic({glyph:e,title:n,items:i,convert:r,onNavigate:o,renderLink:s}){const[l,c]=f.useState(!1),a=l?i:i.slice(0,bt.chips);return t.jsxs(Re,{style:{marginBottom:44},children:[t.jsx(xe,{glyph:e,tone:"ink",title:n,count:`${i.length} 種`}),t.jsxs(Jt,{children:[a.map(d=>t.jsx(Et,{children:t.jsx(ze,{id:d.id,label:r(d.title),onNavigate:o,renderLink:s,dense:!0,style:{color:"inherit"}})},d.id)),i.length>a.length&&t.jsx(Ve,{inline:!0,label:`更多 ${i.length-a.length} 種`,onClick:()=>c(!0)})]})]})}const zc=8,_o=({data:e,transport:n,onNavigate:i,renderLink:r,fullTextSection:o})=>{var _,w,T,C;const s=N(),{convert:l}=P(),[c,a]=f.useState(null),[d,p]=f.useState(new Map),[x,g]=f.useState([]),[u,b]=f.useState(!1);f.useEffect(()=>{if(!n||!e.work_id){a(null);return}let k=!1;return n.getItem(e.work_id).then(z=>{!k&&z&&z.type==="work"&&a(z)}).catch(()=>{}),()=>{k=!0}},[n,e.work_id]),f.useEffect(()=>{const k=e.contained_in||[];if(!n||k.length===0){p(new Map);return}let z=!1;return Promise.all(k.map(I=>{const v=typeof I=="string"?I:I.id;return n.getItem(v).then(E=>[v,E]).catch(()=>[v,null])})).then(I=>{if(z)return;const v=new Map;for(const[E,R]of I)R&&v.set(E,R);p(v)}),()=>{z=!0}},[n,e.contained_in]);const y=f.useMemo(()=>{const k=new Set([...(c==null?void 0:c.books)||[],...e.related_books||[]]);return k.delete(e.id),[...k]},[c==null?void 0:c.books,e.related_books,e.id]);f.useEffect(()=>{if(!n||y.length===0){g([]);return}const k=u?y:y.slice(0,zc);let z=!1;return Promise.all(k.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(()=>Kt(e.resources,e.resource_groups),[e.resources,e.resource_groups]),S=f.useMemo(()=>{var M,$,H;const k=[],z=It(e),I=Ir(e);I&&k.push({label:"版本類型",value:I,title:(M=e.lineage)!=null&&M.category?void 0:"據版本題名推斷"}),(z.era||z.reign)&&k.push({label:"刊寫年代",value:[z.era,z.reign].filter(Boolean).join(" "),title:z.source==="edition"?"據版本題名推斷":void 0});const v=(e.contained_in||[]).flatMap(A=>typeof A=="string"?[]:jt(A.volume_index));v.length&&(k.push({label:"冊數",value:`${v.length} ${s.unit.volume}`}),k.push({label:"冊次",value:`第 ${Pn(v,s.unit.volume)} ${s.unit.volume}`}));const E=Ze(e,s.unit.juan);E&&k.push({label:"卷帙",value:l(E)});const R=(e.resources||[]).filter(A=>(A.types||(A.type?[A.type]:[])).includes("physical"));return R.length?k.push({label:"存藏",value:R.slice(0,2).map(A=>l(A.name)).join("、")+(R.length>2?` 等 ${R.length} 處`:"")}):($=e.current_location)!=null&&$.name&&k.push({label:"存藏",value:l(e.current_location.name)}),(H=e.page_count)!=null&&H.description&&k.push({label:s.label.pageCount,value:e.page_count.description}),k},[e,l,s]),m=!!((_=e.description)!=null&&_.text),j=(e.contained_in||[]).some(k=>typeof k!="string"&&jt(k.volume_index).length>0);return t.jsxs(t.Fragment,{children:[t.jsx(zt,{facts:S.length?t.jsx(Rt,{items:S,horizontal:!m}):void 0,children:m?t.jsx(Oe,{text:e.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}):void 0}),o,(e.contained_in||[]).length>0&&t.jsxs(Re,{children:[t.jsx(xe,{glyph:"收",title:s.section.containedIn}),t.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:(e.contained_in||[]).map((k,z)=>{var M,$;const I=typeof k=="string"?k:k.id,v=typeof k=="string"?[]:jt(k.volume_index),E=d.get(I),R=((M=E==null?void 0:E.books)==null?void 0:M.length)||(($=E==null?void 0:E.contained_works)==null?void 0:$.length)||0;return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"8px 16px",marginBottom:12},children:[t.jsx("span",{style:{fontSize:16},children:t.jsx(ze,{id:I,label:E?l(E.title):I,onNavigate:i,renderLink:r})}),t.jsxs("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:[R>0&&`全 ${R} ${s.unit.bu}`,R>0&&v.length>0&&" · ",v.length>0&&`本書佔 ${v.length} ${s.unit.volume}`]})]}),v.length>0&&t.jsx(Fr,{volumes:v,unit:s.unit.volume})]},`${I}-${z}`)})})]}),t.jsxs("div",{className:"bim-d-pair",children:[c&&t.jsxs("section",{children:[t.jsx(xe,{glyph:"作",tone:"ink",title:s.section.belongsToWork}),t.jsxs("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)",padding:"12px 4px 0"},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 12px",marginBottom:10},children:[t.jsx("span",{style:{fontSize:16},children:t.jsx(ze,{id:c.id,label:l(c.title),onNavigate:i,renderLink:r})}),t.jsx("span",{style:{fontSize:12.5,color:"var(--bim-meta-fg, #7b6a54)"},children:[l(Ze(c,s.unit.juan)),(w=c.authors)==null?void 0:w.map(k=>{const z=Mn(k.role);return`${k.dynasty?`〔${l(k.dynasty)}〕`:""}${l(k.name)}${z?" "+l(z):""}`}).join(" · ")].filter(Boolean).join(" · ")})]}),((T=c.description)==null?void 0:T.text)&&t.jsx(Oe,{text:c.description.text,style:{fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)",textAlign:"justify"}}),t.jsx("div",{style:{marginTop:14},children:t.jsx(Hn,{label:s.section.aliases,items:[..._t(e.additional_titles),..._t(e.attached_texts)]})})]})]}),(h.buckets.length>0||h.mirrors.length>0)&&t.jsxs("section",{children:[t.jsx(xe,{glyph:"源",tone:"ink",title:"影印與全文"}),t.jsxs("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:[h.mirrors.map(k=>t.jsxs("div",{style:{marginBottom:8},children:[t.jsx("div",{className:"bim-d-ui",style:{padding:"8px 4px 4px",fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:l(k.label)}),k.items.map((z,I)=>t.jsx(st,{item:z,showVolumes:!j},`${z.id||z.url||z.name}-${I}`))]},k.key)),h.buckets.flatMap(k=>k.items).map((k,z)=>t.jsx(st,{item:k,showVolumes:!j},`${k.id||k.url||k.name}-${z}`))]})]})]}),(C=e.location_history)!=null&&C.length?t.jsxs(Re,{children:[t.jsx(xe,{glyph:"藏",tone:"ink",title:s.section.locationHistory}),t.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:e.location_history.map((k,z)=>t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px 12px",padding:"9px 4px",fontSize:14,borderBottom:"1px solid var(--bim-rule, #eae2d0)"},children:[t.jsx("span",{children:l(k.name)}),k.description&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:l(k.description)})]},z))})]}):null,y.length>0&&t.jsxs(Re,{style:{marginBottom:0},children:[t.jsx(xe,{glyph:"版",tone:"ink",title:s.relation.siblingVersions,count:`${y.length} 種`,actions:c?t.jsx(ze,{id:c.id,label:"在作品頁查看全部 →",onNavigate:i,renderLink:r,style:{color:"var(--bim-meta-fg, #7b6a54)",fontSize:11.5}}):void 0}),t.jsxs(Jt,{children:[x.map(k=>t.jsx(Et,{children:t.jsx(ze,{id:k.id,label:l(k.edition||k.title||k.id),onNavigate:i,renderLink:r,dense:!0,style:{color:"inherit"}})},k.id)),y.length>x.length&&t.jsx(Ve,{inline:!0,label:`更多 ${y.length-x.length} 種`,onClick:()=>b(!0)})]})]})]})},Hi={titles:16,works:16},Co=({data:e,catalog:n,onNavigate:i,renderLink:r,catalogAction:o})=>{var z,I;const s=N(),{convert:l}=P(),[c,a]=f.useState(""),[d,p]=f.useState(!1),[x,g]=f.useState(!1),u=f.useMemo(()=>Cr(e,n),[e,n]),b=f.useMemo(()=>c?u.rows.filter(v=>v.section===c):u.rows,[u.rows,c]),y=d?b:b.slice(0,Hi.titles),h=f.useMemo(()=>Kt(e.resources,e.resource_groups),[e.resources,e.resource_groups]),S=e.contained_works||[],m=new Set(u.rows.map(v=>v.id).filter(Boolean)),j=S.length>0&&!S.every(v=>m.has(v.id)),_=(()=>{const v=u.rows.map(E=>E.edition).filter(Boolean);return v.length>1&&new Set(v).size===1})(),w=x?S:S.slice(0,Hi.works),T=u.sections.length>0,C=f.useMemo(()=>({leadWidth:26,metaWidth:300,mainLabel:"書名",columns:[...T?[{label:"部類",width:"64px"}]:[],{label:"全帙冊次",width:"1fr"}]}),[T]),k=f.useMemo(()=>{var M,$,H,A;const v=[];e.subtype&&v.push({label:s.label.type,value:e.subtype==="work_collection"?"叢編 · 作品集":"叢編"}),(M=e.publication_info)!=null&&M.details&&v.push({label:"刊印",value:l(e.publication_info.details)}),($=e.publication_info)!=null&&$.year&&v.push({label:"年代",value:e.publication_info.year});const E=((H=e.books)==null?void 0:H.length)||S.length,R=Ze(e,s.unit.juan);return(E||R)&&v.push({label:"種數 / 卷數",value:[E?`${E} ${s.unit.bu}`:"",l(R)].filter(Boolean).join(" · "),title:(A=e.juan_count)!=null&&A.description?l(e.juan_count.description):void 0}),u.totalVolumes&&v.push({label:"全帙冊數",value:`${u.totalVolumes} ${s.unit.volume}`}),v},[e,S.length,u.totalVolumes,l,s]);return t.jsxs(t.Fragment,{children:[t.jsxs(zt,{facts:k.length?t.jsx(Rt,{items:k}):void 0,children:[((z=e.description)==null?void 0:z.text)&&t.jsx(Oe,{text:e.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}),(I=e.history)!=null&&I.length?t.jsx("div",{style:{marginTop:14},children:e.history.map((v,E)=>t.jsxs("div",{style:{fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"},children:["· ",l(v)]},E))}):null]}),u.rows.length>0&&t.jsxs(Re,{children:[t.jsx(xe,{glyph:"目",title:s.section.containedBooks,count:b.length===u.rows.length?`${s.catalog.contains} ${u.rows.length} ${s.unit.items}`:`${u.rows.length} ${s.unit.items} · 當前 ${b.length} ${s.unit.items}`,actions:t.jsxs(t.Fragment,{children:[o,T&&t.jsxs(t.Fragment,{children:[t.jsx(Ne,{label:s.catalog.all,active:!c,onClick:()=>{a(""),p(!1)}}),u.sections.map(v=>t.jsx(Ne,{label:v,active:c===v,onClick:()=>{a(v),p(!1)}},v))]})]})}),t.jsxs(Qe,{children:[t.jsx(Xt,{spec:C}),y.map((v,E)=>{var R;return t.jsx(Zt,{no:Qt(E),spec:C,main:t.jsxs(t.Fragment,{children:[v.id?t.jsx(ze,{id:v.id,label:l(v.title),onNavigate:i,renderLink:r,dense:!0}):t.jsx("span",{children:l(v.title)}),(R=v.subItems)!=null&&R.length?t.jsxs("span",{className:"bim-d-ui",style:{marginLeft:6,fontSize:11.5,color:"var(--bim-hint-fg, #b3a385)"},children:["(",v.subItems.map(M=>l(M)).join("、"),")"]}):null,v.edition&&!_&&t.jsx("span",{className:"bim-d-ui",style:{marginLeft:8,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:l(v.edition)})]}),meta:t.jsxs(t.Fragment,{children:[T&&t.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)"},children:v.section?v.section.endsWith("部")?v.section:`${v.section}部`:t.jsx(ot,{})}),t.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)"},children:v.volumes.length>0?`第 ${Pn(v.volumes,s.unit.volume)} ${s.unit.volume}`:v.expected!=null?`${v.found??0}/${v.expected} ${s.unit.volume}`:t.jsx(ot,{})})]})},`${v.id??v.title}-${E}`)}),y.length===0&&t.jsx(lt,{children:s.catalog.noMatch})]}),b.length>y.length&&t.jsx(Ve,{label:`展開其餘 ${b.length-y.length} ${s.unit.items}子目`,onClick:()=>p(!0)})]}),(h.buckets.length>0||j)&&t.jsxs("div",{className:"bim-d-pair bim-d-pair-wide",children:[(h.buckets.length>0||h.mirrors.length>0)&&t.jsxs("section",{children:[t.jsx(xe,{glyph:"源",tone:"ink",title:"影印與全文"}),t.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,E)=>t.jsx(st,{item:v,fallbackNote:v.details?l(v.details):void 0},`${v.id||v.url||v.name}-${E}`))})]}),j&&t.jsxs("section",{children:[t.jsx(xe,{glyph:"叢",tone:"ink",title:s.section.containedWorks,count:`${S.length} 種`}),t.jsxs(Jt,{children:[w.map(v=>t.jsx(Et,{children:t.jsx(ze,{id:v.id,label:l(v.title),onNavigate:i,renderLink:r,dense:!0,style:{color:"inherit"}})},v.id)),S.length>w.length&&t.jsx(Ve,{inline:!0,label:`更多 ${S.length-w.length} 種`,onClick:()=>g(!0)})]})]})]})]})},Rc=16,Di={leadWidth:26,metaWidth:300,mainLabel:"作品名稱",columns:[{label:"職任",width:"72px"},{label:"存世版本",width:"1fr"}]},un=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Ni(e){if(!e)return un.length;const n=un.indexOf(e);return n===-1?un.length:n}const To=({data:e,transport:n,onNavigate:i,renderLink:r})=>{var C,k,z;const o=N(),{convert:s}=P(),[l,c]=f.useState("全部"),[a,d]=f.useState(!1),[p,x]=f.useState("default"),[g,u]=f.useState(new Map),b=f.useMemo(()=>(e.works||[]).map(v=>{const E=g.get(v.work_id);return{id:v.work_id,title:(E==null?void 0:E.title)??v.work_id,role:v.role||"",cls:Fn(v.role),versionCount:E==null?void 0:E.versionCount,loaded:!!(E!=null&&E.loaded)}}),[e.works,g]),y=f.useMemo(()=>_r((e.works||[]).map(I=>I.role)),[e.works]),h=f.useMemo(()=>{const I=l==="全部"?b:b.filter(v=>v.cls===l);return p==="versions"?[...I].sort((v,E)=>(E.versionCount??-1)-(v.versionCount??-1)):I},[b,l,p]),S=a?h:h.slice(0,Rc),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(E=>{var $,H;const R=E??{},M=((($=R.books)==null?void 0:$.length)??0)+(((H=R.collections)==null?void 0:H.length)??0);return[v,{id:v,title:R.title,versionCount:M,loaded:!0}]}).catch(()=>[v,{id:v,loaded:!0}]))).then(v=>{I||u(E=>{const R=new Map(E);for(const[M,$]of v)R.set(M,$);return R})}),()=>{I=!0}},[n,m]);const j=f.useMemo(()=>{const I=new Map;for(const v of e.alt_names||[]){const E=v.type||o.section.aliases;I.has(E)||I.set(E,[]),I.get(E).push(v.name)}return[...I.entries()].sort((v,E)=>Ni(v[0])-Ni(E[0])).map(([v,E])=>({label:v,names:E}))},[e.alt_names,o]),_=f.useMemo(()=>{const I=[];e.dynasty&&I.push({label:"時代",value:s(e.dynasty)});const v=R=>R==null?"":R<0?`前${-R}`:String(R);(e.birth_year!=null||e.death_year!=null)&&I.push({label:"生卒",value:`${v(e.birth_year)||"?"}—${v(e.death_year)||"?"}`});const E=(e.works||[]).length;return E&&I.push({label:"著作數",value:`${E} 種`}),I},[e,s]),w=(C=e.external_ids)==null?void 0:C.cbdb_id,T=!!((k=e.description)!=null&&k.text);return t.jsxs(t.Fragment,{children:[t.jsx(zt,{facts:_.length?t.jsx(Rt,{items:_}):void 0,children:(j.length>0||T)&&t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[j.length>0&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 26px",fontSize:14},children:j.map(I=>t.jsxs("span",{style:{display:"flex",alignItems:"baseline",gap:8,minWidth:0},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)",letterSpacing:".1em",flex:"none"},children:s(I.label)}),t.jsx("span",{style:{color:"var(--bim-ink, #2a231c)"},children:I.names.map(v=>s(v)).join(" · ")})]},I.label))}),T&&t.jsx(Oe,{text:e.description.text,style:{fontSize:14,lineHeight:2,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}})]})}),b.length===0&&t.jsxs(Re,{style:{marginBottom:0},children:[t.jsx(xe,{glyph:"著",title:o.label.relatedWorks}),t.jsx(Qe,{children:t.jsx(lt,{children:"尚未著錄該人物的關聯作品。"})})]}),b.length>0&&t.jsxs(Re,{style:{marginBottom:0},children:[t.jsx(xe,{glyph:"著",title:o.label.relatedWorks,count:h.length===b.length?`${b.length} 種`:`${b.length} 種 · 當前 ${h.length} 種`,actions:t.jsx(qt,{label:p==="default"?"排序:著錄順序":"排序:版本數量",onClick:()=>{x(I=>(I==="default"&&d(!0),I==="default"?"versions":"default"))}})}),y.length>0&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:14},children:y.map(I=>t.jsx(Ne,{label:`${I.label} ${I.count}`,active:l===I.cls,onClick:()=>{c(I.cls),d(!1)}},I.cls))}),t.jsxs(Qe,{children:[t.jsx(Xt,{spec:Di}),S.map((I,v)=>t.jsx(Zt,{no:Qt(v),spec:Di,main:t.jsx(ze,{id:I.id,label:s(I.title),onNavigate:i,renderLink:r,dense:!0}),meta:t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)"},children:I.role?s(I.role):t.jsx(ot,{})}),t.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)"},children:I.loaded?I.versionCount?`${I.versionCount} 種版本`:t.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"未著錄版本"}):""})]})},I.id)),S.length===0&&t.jsx(lt,{children:"該職任下的著作尚未著錄。"})]}),h.length>S.length&&t.jsx(Ve,{label:`展開其餘 ${h.length-S.length} 條著作`,onClick:()=>d(!0)}),w!=null&&t.jsxs("div",{className:"bim-d-ui",style:{marginTop:14,fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:["人物編號 CBDB ",w,((z=e.external_ids)==null?void 0:z.cbdb_match)==="auto"&&t.jsxs("span",{title:"由姓名、朝代与著作重合度自动匹配,未经人工复核",children:[" ","· 自動匹配"]})]})]})]})};function Ec(e){var n;return{id:e.id,kind:"hypothetical",label:e.label,year:e.year??((n=e.year_range)==null?void 0:n[0]),year_range:e.year_range,year_uncertain:e.year_uncertain,group:e.group,note:e.note,description:e.description}}function Bc(e,n){if(!e.lineage)return null;const i=e.lineage;return{id:e.id,kind:"book",label:e.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[e.id],note:i.note}}function Vi(e,n,i){return{id:`derive:${n.ref}->${e}:${i}`,source:n.ref,target:e,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Lc(e,n,i){const[r,o]=[e,n.book_id].sort();return{id:`sibling:${r}-${o}:${i}`,source:r,target:o,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Wc(e,n){var d;if(n==="all")return null;const i=(d=e.collections)==null?void 0:d[n],r=Array.isArray(i==null?void 0:i.groups)&&i.groups.length>0,o=Array.isArray(i==null?void 0:i.book_ids)&&i.book_ids.length>0,s=r||o||!!(i!=null&&i.hypothetical_ids);if(!s&&n==="core"&&Array.isArray(e.core_books)&&e.core_books.length>0)return{books:new Set(e.core_books),hypos:e.core_hypotheticals?new Set(e.core_hypotheticals):null};if(!i||!s)return null;const l=r?new Set(i.groups):null,c=new Set(i.book_ids??[]);if(l&&e.node_groups)for(const[p,x]of Object.entries(e.node_groups))l.has(x)&&c.add(p);let a=null;if(i.hypothetical_ids&&(a=new Set(i.hypothetical_ids)),l){a||(a=new Set);for(const p of e.hypothetical_nodes??[])p.group&&l.has(p.group)&&a.add(p.id)}return{books:c,hypos:a}}function Ot(e,n,i){const r=e.version_graph,o={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return o;const s=new Set(r.excluded_books??[]),l=r.node_groups??{},c=Wc(r,i??r.default_collection??"all"),a=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(a){const _=new Map(n.map(I=>[I.id,I])),w=new Map((r.hypothetical_nodes??[]).map(I=>[I.id,I])),T=I=>{const v=_.get(I);if(v&&v.lineage)return(v.lineage.derived_from??[]).map(R=>R.ref);const E=w.get(I);return E?(E.derived_from??[]).map(R=>R.ref):[]},C=I=>w.has(I)?!p||p.has(I):!d||d.has(I),k=new Set,z=I=>{if(!k.has(I)){k.add(I);for(const v of T(I))s.has(v)||(C(v)||(w.has(v)?g.add(v):_.has(v)&&x.add(v)),z(v))}};for(const I of n)d&&d.has(I.id)&&!s.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(_=>!s.has(_.id)).filter(_=>!d||d.has(_.id)||x.has(_.id)).map(_=>{const w=Bc(_,l);return w&&x.has(_.id)&&(w.bridge=!0),w}).filter(_=>_!==null),b=(r.hypothetical_nodes??[]).filter(_=>!p||p.has(_.id)||g.has(_.id)).map(_=>{const w=Ec(_);return g.has(_.id)&&(w.bridge=!0),w}),y=[...u,...b],h=new Set(y.map(_=>_.id)),S=new Set,m=[],j=_=>{S.has(_.id)||!h.has(_.source)||!h.has(_.target)||(S.add(_.id),m.push(_))};for(const _ of n)s.has(_.id)||!_.lineage||d&&!d.has(_.id)&&!x.has(_.id)||((_.lineage.derived_from??[]).forEach((w,T)=>{j(Vi(_.id,w,T))}),(_.lineage.related_to??[]).forEach((w,T)=>{j(Lc(_.id,w,T))}));for(const _ of r.hypothetical_nodes??[])p&&!p.has(_.id)&&!g.has(_.id)||(_.derived_from??[]).forEach((w,T)=>{j(Vi(_.id,w,T))});return{nodes:y,edges:m,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(s)}}function Io(e,n,i){const r=(e??(n!=null?String(n):"")).trim();return r?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function $c(e,n){const i=[],r=e.version_graph;if(!r)return i;const o=new Set(n.map(a=>a.id)),s=new Set((r.hypothetical_nodes??[]).map(a=>a.id)),l=new Set([...o,...s]),c=(a,d)=>{l.has(d.ref)||i.push(`${a}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!o.has(d.ref)&&i.push(`${a}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!s.has(d.ref)&&i.push(`${a}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const a of n){if(!a.lineage)continue;const d=`Book ${a.id} (${a.title})`;(a.lineage.derived_from??[]).forEach(p=>c(d,p)),(a.lineage.related_to??[]).forEach(p=>{o.has(p.book_id)||i.push(`${d}: related_to.book_id "${p.book_id}" 不在 books 列表中`)})}for(const a of r.hypothetical_nodes??[]){const d=`Hypothetical ${a.id} (${a.label})`;(a.derived_from??[]).forEach(p=>c(d,p))}return i}const zo=({graph:e,renderLink:n,className:i,style:r})=>{const{convert:o}=P();if(!e.nodes.length)return t.jsx("div",{style:{...qc,...r},className:i,children:"暂无版本图数据"});const s=new Map,l=new Map;for(const g of e.edges)if(g.kind==="derive"){const u=s.get(g.target)??[];u.push(g),s.set(g.target,u)}else for(const u of[g.source,g.target]){const b=l.get(u)??[];b.push(g),l.set(u,b)}const c=new Map(e.nodes.map(g=>[g.id,g])),a=new Map,d=[];for(const g of e.nodes)if(g.group){const u=a.get(g.group)??[];u.push(g),a.set(g.group,u)}else d.push(g);const p=(g,u)=>(g.year??9999)-(u.year??9999);a.forEach(g=>g.sort(p)),d.sort(p);const x=e.groups.filter(g=>a.has(g.id));return t.jsxs("div",{className:i,style:{...Fc,...r},children:[e.title&&t.jsx("div",{style:Mc,children:o(e.title)}),e.description&&t.jsx("div",{style:Pc,children:o(e.description)}),x.map(g=>t.jsx(Gi,{label:g.label,color:g.color,nodes:a.get(g.id),incomingMap:s,siblingMap:l,nodeMap:c,renderLink:n},g.id)),d.length>0&&t.jsx(Gi,{label:"其他",nodes:d,incomingMap:s,siblingMap:l,nodeMap:c,renderLink:n})]})},Gi=({label:e,color:n,nodes:i,incomingMap:r,siblingMap:o,nodeMap:s,renderLink:l})=>{const{convert:c}=P();return t.jsxs("div",{style:Oc,children:[t.jsx("div",{style:{...Hc,borderLeftColor:n??"var(--bim-widget-border, #ddd)"},children:c(e)}),i.map(a=>t.jsx(Ac,{node:a,incoming:r.get(a.id)??[],siblings:o.get(a.id)??[],nodeMap:s,renderLink:l},a.id))]})},Ac=({node:e,incoming:n,siblings:i,nodeMap:r,renderLink:o})=>{const s=e.kind==="hypothetical",l=e.bridge,{convert:c}=P();return t.jsxs("div",{style:{...Dc,borderStyle:s||l?"dashed":"solid",opacity:l?.55:e.status==="lost"?.7:1,background:l?"var(--bim-bg-subtle, #fafafa)":void 0},title:l?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsxs("div",{style:Nc,children:[t.jsx("span",{style:Vc,children:s||!o?c(e.label):o(e.id,c(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Gc,children:Io(c(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Uc,children:[e.category&&t.jsx(mt,{children:c(e.category)}),e.status==="lost"&&t.jsx(mt,{tone:"warn",children:"已佚"}),e.status==="fragment"&&t.jsx(mt,{tone:"warn",children:"残本"}),s&&t.jsx(mt,{tone:"info",children:"假想祖本"}),l&&t.jsx(mt,{tone:"info",children:"桥接"})]}),e.extant_juan&&t.jsxs("div",{style:Yc,children:["现存:",c(e.extant_juan)]}),e.note&&t.jsx("div",{style:Kc,children:c(e.note)}),n.length>0&&t.jsxs("div",{style:Yi,children:[t.jsx("div",{style:Ki,children:"来源:"}),n.map(a=>{const d=r.get(a.source);return t.jsxs("div",{style:qi(a.confidence),children:[t.jsx("span",{style:Ji,children:c(a.relation)}),t.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&o?o(d.id,c(d.label)):c((d==null?void 0:d.label)??a.source)}),a.confidence!=="consensus"&&a.confidence!=="certain"&&t.jsx(Ui,{level:a.confidence}),a.evidence&&t.jsxs("span",{style:Xi,children:["· ",c(a.evidence)]})]},a.id)})]}),i.length>0&&t.jsxs("div",{style:Yi,children:[t.jsx("div",{style:Ki,children:"关联:"}),i.map(a=>{const d=a.source===e.id?a.target:a.source,p=r.get(d);return t.jsxs("div",{style:qi(a.confidence),children:[t.jsx("span",{style:Ji,children:c(a.relation)}),t.jsx("span",{children:(p==null?void 0:p.kind)==="book"&&o?o(p.id,c(p.label)):c((p==null?void 0:p.label)??d)}),t.jsx(Ui,{level:a.confidence}),a.evidence&&t.jsxs("span",{style:Xi,children:["· ",c(a.evidence)]})]},a.id)})]})]})},mt=({children:e,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 t.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:e})},Ui=({level:e})=>{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)"}}[e];return i?t.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},Fc={fontSize:"14px",color:"var(--bim-fg, #333)"},Mc={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Pc={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},Oc={marginBottom:"16px"},Hc={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:"var(--bim-fg, #333)"},Dc={border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:"var(--bim-bg, #fff)"},Nc={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Vc={fontSize:"15px",fontWeight:600},Gc={fontSize:"12px",color:"var(--bim-muted, #777)"},Uc={marginBottom:"6px"},Yc={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},Kc={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},Yi={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},Ki={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},qi=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),Ji={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},Xi={fontSize:"11px",color:"var(--bim-muted, #888)"},qc={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},Ro=({selectedNodeId:e,...n})=>{const[i,r]=f.useState("loading"),[o,s]=f.useState(null);return f.useEffect(()=>{let l=!1;return Jc().then(c=>{l||(c?(s(c),r("ready")):r("missing"))}),()=>{l=!0}},[]),i==="loading"?t.jsx("div",{style:Zi,children:"加载图组件中…"}):i==="missing"||!o?t.jsxs("div",{style:Zi,children:[t.jsxs("div",{children:["图组件未安装。请安装 ",t.jsx("code",{children:"@xyflow/react"})," 与 ",t.jsx("code",{children:"@dagrejs/dagre"}),"。"]}),t.jsxs("div",{style:{fontSize:"12px",marginTop:"4px"},children:["或使用 ",t.jsx("code",{children:"VersionLineageList"})," 列表视图。"]})]}):t.jsx(Xc,{modules:o,selectedNodeId:e,...n})};async function Jc(){try{const[e,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:e.ReactFlow,Background:e.Background,Controls:e.Controls,Handle:e.Handle,Position:e.Position,BaseEdge:e.BaseEdge,EdgeLabelRenderer:e.EdgeLabelRenderer,getSmoothStepPath:e.getSmoothStepPath,dagre:n,cssLoaded:i}}catch{return null}}const Xc=({graph:e,renderLink:n,height:i=600,className:r,style:o,selectedNodeId:s,modules:l})=>{const{ReactFlow:c,Background:a,Controls:d,Handle:p,Position:x,BaseEdge:g,EdgeLabelRenderer:u,getSmoothStepPath:b,dagre:y}=l,h=f.useMemo(()=>({lineage:T=>{var H,A,F,J;const C=((H=T.data)==null?void 0:H.stepPosition)??.85,[k,z,I]=b({sourceX:T.sourceX,sourceY:T.sourceY,sourcePosition:T.sourcePosition,targetX:T.targetX,targetY:T.targetY,targetPosition:T.targetPosition,stepPosition:C,borderRadius:5}),v=!!((A=T.data)!=null&&A.isSibling),E=v?z:T.targetX-18,R=v?I:T.targetY-12,M=(F=T.data)==null?void 0:F.labelStyle,$=(J=T.data)==null?void 0:J.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(g,{id:T.id,path:k,style:T.style,markerStart:T.markerStart,markerEnd:T.markerEnd}),T.label&&t.jsx(u,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${E}px,${R}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:"var(--bim-bg, #fff)",border:"0.5px solid var(--bim-widget-border, #ddd)",...$,...M},children:T.label})})]})}}),[g,u,b]),S=f.useMemo(()=>({version:T=>{const C=T.data,k=C.kind==="hypothetical",z=C.status==="lost",I=C.isSelected,v=C.bridge,E=C.borderColor??"var(--bim-muted, #888)",R=v||k?"dashed":"solid",M=v?.5:z?.6:1;return t.jsxs("div",{style:{background:v?"var(--bim-bg-subtle, #fafafa)":"var(--bim-bg, #fff)",border:`2px ${R} ${I?"var(--bim-primary, #0078d4)":E}`,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)":k||v?"none":"0 1px 3px rgba(0,0,0,0.1)"},title:v?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[t.jsx(p,{type:"target",position:x.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:k||!C.renderLink?C.label:C.renderLink(C.bookId,C.label)}),C.description&&t.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.25,marginTop:1},children:C.description}),C.yearText&&t.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.2},children:Io(C.yearText,void 0,C.uncertain)}),z&&t.jsx("div",{style:{fontSize:9,color:"var(--bim-lost-fg, #c62828)",marginTop:1},children:"已佚"}),t.jsx(p,{type:"source",position:x.Right,style:{visibility:"hidden"}})]})}}),[p,x]),{convert:m}=P(),{rfNodes:j,rfEdges:_}=f.useMemo(()=>Zc(e,y,n,s,m),[e,y,n,s,m]);return t.jsx("div",{style:{width:"100%",height:i,...o},className:r,children:t.jsxs(c,{nodes:j,edges:_,nodeTypes:S,edgeTypes:h,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(a,{gap:16}),t.jsx(d,{showInteractive:!1})]})})};function Zc(e,n,i,r,o=s=>s??""){const c=e.layout==="LR"||!e.layout,a=new n.graphlib.Graph;a.setGraph({rankdir:c?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),a.setDefaultEdgeLabel(()=>({}));const d=new Map(e.groups.map(S=>[S.id,S.color??"var(--bim-muted, #888)"]));for(const S of e.nodes)a.setNode(S.id,{width:160,height:90});const p=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const S of e.edges)S.kind==="derive"&&(p.has(S.relation)||a.setEdge(S.source,S.target));n.layout(a);const x=e.nodes.map(S=>{const m=a.node(S.id),j=r&&S.id===r,_={kind:S.kind,label:o(S.label),bookId:S.kind==="book"?S.id:void 0,yearText:o(S.year_text??ed(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:o(S.description),bridge:S.bridge};return{id:S.id,type:"version",position:{x:m.x-160/2,y:m.y-90/2},data:_,draggable:!1,selected:j}}),g=.78,u=.06,b=new Map;for(const S of e.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((w,T)=>{var z,I;const C=((z=a.node(w.target))==null?void 0:z.y)??0,k=((I=a.node(T.target))==null?void 0:I.y)??0;return C-k}),_=j.length;j.forEach((w,T)=>{const C=(T-(_-1)/2)*u;y.set(w.id,g+C)})}const h=e.edges.map(S=>Qc(S,y.get(S.id),o));return{rfNodes:x,rfEdges:h}}function Qc(e,n,i=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",o=e.kind==="sibling",s=td(e.confidence),l={type:"arrowclosed",color:s,width:14,height:14};return{id:e.id,source:e.source,target:e.target,type:"lineage",label:i(e.relation),data:{labelStyle:{color:"var(--bim-fg, #444)"},isSibling:o,stepPosition:n},style:{stroke:s,strokeWidth:o?1:1.5,strokeDasharray:o?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:l,markerStart:o?l:void 0,zIndex:1e3}}function ed(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function td(e){switch(e){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 Zi={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)"},Eo=({graph:e,defaultMode:n="list",renderLink:i,graphHeight:r=600,selectedNodeId:o,onModeChange:s,collection:l,onCollectionChange:c,collectionsAvailable:a,collectionCounts:d,className:p,style:x})=>{var m;const[g,u]=f.useState(n),b=j=>{u(j),s==null||s(j)},y=(()=>{if(!a)return[];const j=Object.entries(a);return j.length===0||a.all?j:[...j,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),h=!!(c&&y.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:"var(--bim-muted, #999)",textAlign:"center"},children:"暂无版本传承数据"});const S=l?(m=a==null?void 0:a[l])==null?void 0:m.description:void 0;return t.jsxs("div",{className:p,style:x,children:[t.jsxs("div",{style:nd,children:[t.jsx("button",{onClick:()=>b("list"),style:fn(g==="list"),children:"列表"}),t.jsx("button",{onClick:()=>b("graph"),style:fn(g==="graph"),children:"关系图"}),h&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:"var(--bim-muted, #888)",marginRight:4},children:"集合:"}),y.map(([j,_])=>{const w=d==null?void 0:d[j];return t.jsxs("button",{onClick:()=>c==null?void 0:c(j),style:fn(l===j),title:_.description,children:[_.label,w!=null?` ${w}`:""]},j)})]})]}),h&&S&&t.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"?t.jsx(zo,{graph:e,renderLink:i}):t.jsx(Ro,{graph:e,renderLink:i,height:r,selectedNodeId:o})]})},nd={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},fn=e=>({padding:"4px 12px",fontSize:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:4,background:e?"var(--bim-primary, #0078d4)":"transparent",color:e?"var(--bim-primary-fg, #fff)":"var(--bim-fg, #333)",cursor:"pointer"}),Bo=({style:e})=>{const n=f.useContext(Ct);if(!n)return null;const{locale:i,setLocale:r}=n,o=i==="zh-Hant",s=()=>r(o?"zh-Hans":"zh-Hant");return t.jsxs("button",{type:"button",onClick:s,title:o?"切换为简体":"切換為繁體",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",...e},children:[t.jsx("span",{style:{color:o?"var(--bim-primary, #0078d4)":void 0,fontWeight:o?700:400},children:"繁"}),t.jsx("span",{style:{opacity:.3},children:"/"}),t.jsx("span",{style:{color:o?void 0:"var(--bim-primary, #0078d4)",fontWeight:o?400:700},children:"简"})]})},Lo=({href:e,label:n="在 GitHub 查看本条目源文件",size:i=16,className:r,style:o})=>t.jsx("a",{href:e,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",...o},onMouseEnter:s=>{s.currentTarget.style.color="var(--bim-fg, #1a1a1a)"},onMouseLeave:s=>{s.currentTarget.style.color="var(--bim-desc-fg, #717171)"},children:t.jsx("svg",{width:i,height:i,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:t.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"})})}),id=({id:e,transport:n,activeTab:i,onTabChange:r,activeJuan:o,onJuanChange:s,lineageMode:l="list",onLineageModeChange:c,lineageCollection:a,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:_,height:w,footerExtra:T,className:C,style:k})=>{const z=N(),{convert:I}=P(),[v,E]=f.useState(null),[R,M]=f.useState(null),[$,H]=f.useState(!0),[A,F]=f.useState(!1),[J,W]=f.useState([]),[K,ie]=f.useState(!1),[Y,L]=f.useState(null),[q,X]=f.useState(!1),[G,U]=f.useState(null),[ce,we]=f.useState(!1),[fe,ae]=f.useState([]),[Se,Ee]=f.useState(!1),[dt,Fe]=f.useState(null),[Be,D]=f.useState(null),[se,ee]=f.useState(!1),B=f.useRef(null),[Q,le]=f.useState(null),oe=o!==void 0?o:Q,_e=f.useCallback(O=>{s?s(O):le(O)},[s]),Ce=f.useCallback(async O=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){W([]);return}ie(!0);try{if(n.getCollectionCatalogs)W(await n.getCollectionCatalogs(O)||[]);else if(n.getCollectionCatalog){const te=await n.getCollectionCatalog(O);W(te?[{resource_id:"",data:te}]:[])}}catch{W([])}finally{ie(!1)}},[n]),me=f.useCallback(async O=>{if(!n.getCollatedEditionIndex){L(null);return}X(!0);try{L(await n.getCollatedEditionIndex(O))}catch{L(null)}finally{X(!1)}},[n]),Ge=f.useCallback(async O=>{if(!n.getBookFullTextIndex){U(null);return}we(!0);try{U(await n.getBookFullTextIndex(O))}catch{U(null)}finally{we(!1)}},[n]),Yn=f.useCallback(async O=>{var te;if(!n.getWorkFullTextList){ae([]);return}Ee(!0);try{const re=(await n.getWorkFullTextList(O)??[]).filter(ne=>ne.owner_type!=="Book");ae(re),Fe(((te=re.find(ne=>ne.primary)??re[0])==null?void 0:te.key)??null)}catch{ae([])}finally{Ee(!1)}},[n]),Kn=f.useCallback(async(O,te)=>{ee(!0);try{if(n.getLineageGraph){const De=await n.getLineageGraph(O);De&&D(De)}const re=te.version_graph;if(!re||!re.enabled){Be||D(null),B.current=null;return}const ne=te.books??[],de=[];for(const De of ne)try{const Le=await n.getItem(De);Le&&de.push(Le)}catch{}B.current={work:te,books:de};const V=a??re.default_collection??(re.core_books&&re.core_books.length>0?"core":"all"),pe=V==="core"&&Array.isArray(re.core_books)&&re.core_books.length>0?"core":V??"all";D(Ot(te,de,pe))}catch{D(null),B.current=null}finally{ee(!1)}},[n]);f.useEffect(()=>{let O=!1;return(async()=>{H(!0),F(!1),E(null),M(null),W([]),L(null),U(null),ae([]),Fe(null),D(null),B.current=null;try{const re=await n.getItem(e);if(O)return;if(!re){F(!0);return}const ne=re;let de=null;if(n.getEntry&&(de=await n.getEntry(e),O))return;de||(de={id:e,title:ne.title??ne.primary_name??e,type:ne.type??"book"}),h&&h(de,ne),E(de),M(ne),ne.type==="collection"?Ce(e):ne.type==="work"?((ne.has_collated||n.getCollatedEditionIndex)&&me(e),(ne.version_graph||n.getLineageGraph)&&Kn(e,ne),n.getWorkFullTextList&&Yn(e)):ne.type==="book"&&ne.has_full_text&&n.getBookFullTextIndex&&Ge(e)}catch{O||F(!0)}finally{O||H(!1)}})(),()=>{O=!0}},[e,n,h,Ce,me,Kn,Ge,Yn]),f.useEffect(()=>{const O=B.current;!O||!a||D(Ot(O.work,O.books,a))},[a]);const ye=[];if(R){if(ye.push({key:"basic",label:z.detailTab.basicInfo}),R.type==="collection"){K&&J.length===0&&ye.push({key:"catalog:loading",label:`${z.detailTab.catalog}…`});for(const O of J)ye.push({key:`catalog:${O.resource_id}`,label:O.short_name?`${I(O.short_name)}${z.detailTab.catalogSuffix}`:z.detailTab.collectionCatalog})}R.type==="work"&&(Y||q)&&i==="collated"&&ye.push({key:"collated",label:q?`${z.detailTab.collatedEdition}…`:z.detailTab.collatedEdition}),R.type==="book"&&(G||ce)&&i==="fulltext"&&ye.push({key:"fulltext",label:ce?`${z.detailTab.fullText}…`:z.detailTab.fullText}),R.type==="work"&&(fe.length>0||Se)&&i==="fulltext"&&ye.push({key:"fulltext",label:Se?`${z.detailTab.fullText}…`:z.detailTab.fullText}),R.type==="work"&&(Be||se)&&ye.push({key:"lineage",label:se?`${z.detailTab.lineage}…`:z.detailTab.lineage});for(const O of m)(O.position??"before-feedback")==="before-feedback"&&O.shouldShow(R)&&ye.push({key:O.key,label:O.label});j&&i==="feedback"&&ye.push({key:"feedback",label:z.detailTab.feedback});for(const O of m)O.position==="after-feedback"&&O.shouldShow(R)&&ye.push({key:O.key,label:O.label})}f.useEffect(()=>{if(i!=="emendated"||!R)return;r("basic");const O=setTimeout(()=>{var te;(te=document.getElementById("studies"))==null||te.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(O)},[i,R,r]);const Bt=v&&R&&S?S({activeTab:i,activeJuan:oe,entry:v,detail:R}):null,en=f.useMemo(()=>{var de;if(!R)return null;const te=(R.authors??[]).map(V=>{const pe=Mn(V.role);return`${V.dynasty?`〔${I(V.dynasty)}〕`:""}${I(V.name)}${pe?` ${I(pe)}`:""}`}).join(" · ");let re=!1;try{re=Z.extractStatus(R.id)==="draft"}catch{}if(R.type==="book"){const V=R;return{title:I(V.title),subtitle:V.edition?I(V.edition):te||void 0,aside:[re?z.status.draft:"",te&&V.edition?te:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(R.type==="collection"){const V=R;return{title:I(V.title),subtitle:I(Ze(V,z.unit.juan))||void 0,aside:[(de=V.publication_info)==null?void 0:de.year,re?z.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:te||void 0}}if(R.type==="entity"){const V=R,pe=Le=>Le==null?"":Le<0?`前${-Le}`:String(Le),De=V.birth_year!=null||V.death_year!=null?`${pe(V.birth_year)||"?"}—${pe(V.death_year)||"?"}`:"";return{title:I(V.primary_name||V.title),subtitle:[V.dynasty?`〔${I(V.dynasty)}〕`:"",De].filter(Boolean).join(" ")||void 0,aside:re?z.status.draft:void 0,secondLine:void 0}}const ne=I(Ze(R,z.unit.juan));return{title:I(R.title),subtitle:[ne,te].filter(Boolean).join(" · ")||void 0,aside:[od(z,R.subtype),re?z.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[R,I,z]),Wo=()=>{var O,te,re;return R?R.type==="work"?t.jsx(wo,{data:R,transport:n,onNavigate:g,renderLink:y,collatedSection:Y&&(((O=Y.juan_files)==null?void 0:O.length)??0)>0||fe.length>0?t.jsxs(t.Fragment,{children:[Y&&(((te=Y.juan_files)==null?void 0:te.length)??0)>0&&t.jsx(xn,{title:R.title,measure:`${Y.juan_files.length} ${I(z.unit.juan)}`,onOpen:()=>{_e(Y.juan_files[0]),r("collated")}}),fe.length>0&&(()=>{const ne=fe.find(de=>de.primary)??fe[0];return t.jsx(xn,{title:R.title,measure:[ne.source_name?I(ne.source_name):"",fe.length>1?I(`${fe.length} 種`):""].filter(Boolean).join(" · "),onOpen:()=>{Fe(ne.key),_e(null),r("fulltext")}})})()]}):null,lineageAction:Be&&Be.nodes.length>0?t.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}):R.type==="book"?t.jsx(_o,{data:R,transport:n,onNavigate:g,renderLink:y,fullTextSection:G&&G.chapters.length>0?t.jsx(xn,{title:R.title,measure:[`${G.total_chapters} ${I("章")}`,I(G.version_label)].filter(Boolean).join(" · "),onOpen:()=>{_e(null),r("fulltext")}}):null}):R.type==="collection"?t.jsx(Co,{data:R,catalog:(re=J[0])==null?void 0:re.data,transport:n,onNavigate:g,renderLink:y,catalogAction:J.length>0?t.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}):t.jsx(To,{data:R,transport:n,onNavigate:g,renderLink:y}):null},$o=()=>{var te,re,ne,de;if(!v||!R)return null;if(i==="basic"||i==="emendated")return Wo();if(typeof i=="string"&&i.startsWith("catalog:")){const V=(te=J.find(pe=>`catalog:${pe.resource_id}`===i))==null?void 0:te.data;return t.jsx(Ln,{data:V,onNavigate:g,renderLink:y})}if(i==="collated")return t.jsx(Gn,{index:Y||void 0,workId:e,transport:n,onNavigate:g,activeJuan:oe,onJuanChange:_e});if(i==="fulltext"&&R.type==="work"){const V=dt??((re=fe[0])==null?void 0:re.key);return V?t.jsx(wn,{bookId:e,workKey:V,versions:fe,onVersionChange:pe=>{Fe(pe),_e(null)},transport:n,activeChapter:oe,onChapterChange:_e},V):t.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:Se?"加载全文目录…":"暂无全文"})}if(i==="fulltext")return t.jsx(wn,{index:G||void 0,bookId:e,transport:n,activeChapter:oe,onChapterChange:_e});if(i==="lineage"){if(!Be)return t.jsx("div",{style:{color:"var(--bim-label-fg, #a3937b)",padding:"24px 0"},children:se?"加載中…":"暫無版本圖數據"});const V=R.type==="work"?R:null;return t.jsx(Eo,{graph:Be,renderLink:y,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:l,onModeChange:c,selectedNodeId:x,collection:a??((ne=V==null?void 0:V.version_graph)==null?void 0:ne.default_collection),onCollectionChange:d,collectionsAvailable:(de=V==null?void 0:V.version_graph)==null?void 0:de.collections,collectionCounts:(()=>{var qn,Jn,Xn,Zn,Qn,ei,ti;if(!V)return;const pe={},De=((qn=B.current)==null?void 0:qn.books)??[];pe.all=(((Jn=V.books)==null?void 0:Jn.length)??0)-(((Zn=(Xn=V.version_graph)==null?void 0:Xn.excluded_books)==null?void 0:Zn.length)??0);const Le=(Qn=V.version_graph)==null?void 0:Qn.collections;if(Le)for(const ni of Object.keys(Le))pe[ni]=Ot(V,De,ni).nodes.filter(ii=>ii.kind==="book"&&!ii.bridge).length;return pe.core==null&&((ti=(ei=V.version_graph)==null?void 0:ei.core_books)!=null&&ti.length)&&(pe.core=V.version_graph.core_books.length),pe})()})}if(i==="feedback"&&j)return t.jsx(So,{resourceId:e,apiUrl:_});const O=m.find(V=>V.key===i);return O?O.render({detail:R,entry:v,transport:n,onNavigate:g}):null};if($)return t.jsx(Ft,{style:{minHeight:w,...k},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((O,te)=>t.jsx("div",{style:{height:te===1?40:16,width:O,opacity:.35,background:"var(--bim-rule, #e0d6c0)"}},te))})});if(A||!R||!v||!en)return t.jsx(Ft,{style:{minHeight:w,...k},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:"var(--bim-label-fg, #a3937b)",fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const Ao=i==="basic"||i==="emendated",tn=[{label:b??z.detailTab.backToIndex,onClick:u}];if(R.type==="book"&&R.work_id){const O=R.work_id;tn.push({label:z.indexType.work,id:O,onClick:()=>g==null?void 0:g(O)})}tn.push({label:z.indexType[R.type]});const Lt=i==="collated"||i==="fulltext";return t.jsx("div",{className:C,children:t.jsxs(Ft,{wide:Lt,style:{minHeight:w,...k},children:[t.jsx(Wr,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(On,{char:"籍"}),t.jsx($r,{items:tn})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx(Bo,{}),j&&t.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}),Bt&&t.jsx(Lo,{...Bt})]})}),t.jsx(Ar,{...en,aside:Lt?t.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("作品信息")," →"]}):en.aside}),!Lt&&ye.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:ye.map(O=>t.jsx(Ne,{label:O.label,active:O.key===i||Ao&&O.key==="basic",onClick:()=>r(O.key)},O.key))}),t.jsx("div",{style:{marginTop:!Lt&&ye.length>1?8:0},children:$o()}),t.jsx(Ur,{left:t.jsxs(t.Fragment,{children:[T,T?" · ":"",t.jsx(rd,{id:R.id,label:z.label.id,copied:z.action.copied})]}),right:t.jsxs(t.Fragment,{children:[j&&t.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}),Bt&&t.jsx("a",{href:Bt.href,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-meta-fg, #7b6a54)"},children:z.detailTab.dataLicense})]})})]})})};function rd({id:e,label:n,copied:i}){const[r,o]=f.useState(!1);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[n," ",e]}),t.jsx("button",{type:"button",onClick:()=>{var s;(s=navigator.clipboard)==null||s.writeText(e).then(()=>{o(!0),setTimeout(()=>o(!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 od(e,n){return n?e.workSubtype[n]??n:""}function xn({title:e,measure:n,onOpen:i}){const{convert:r}=P(),[o,s]=f.useState(!1),l=r(e?`進入《${e}》全文閲讀`:"進入全文閲讀"),c=[n,r("全文檢索"),r("原書對照")].filter(Boolean).join(" · ");return t.jsx(Re,{style:{marginTop:-12,marginBottom:28},children:t.jsxs("div",{role:"button",tabIndex:0,onClick:i,onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),i())},onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:24,flexWrap:"wrap",padding:"14px 26px",cursor:"pointer",background:o?"var(--bim-band-bg-hover, #e6d5b4)":"var(--bim-band-bg, #f0e4cb)",borderLeft:"3px solid var(--bim-accent, #9c3a2c)",transition:"background .18s ease"},children:[t.jsxs("div",{style:{minWidth:0},children:[t.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:l}),t.jsx("div",{className:"bim-d-ui",style:{marginTop:4,fontSize:12.5,letterSpacing:".06em",color:"var(--bim-meta-fg, #7b6a54)"},children:c})]}),t.jsxs("span",{className:"bim-d-ui","aria-hidden":!0,style:{flex:"none",padding:"11px 22px",fontSize:14,letterSpacing:".08em",background:o?"var(--bim-accent-deep, #6f2a20)":"var(--bim-accent, #9c3a2c)",color:"var(--bim-page-bg, #fbf9f3)",transition:"background .18s ease"},children:[r("開始閲讀")," →"]})]})})}exports.BidLink=Z.BidLink;exports.BookIndexError=Z.BookIndexError;exports.BookIndexManager=Z.BookIndexManager;exports.BookIndexStorage=Z.BookIndexStorage;exports.BundleStorage=Z.BundleStorage;exports.ConfigError=Z.ConfigError;exports.GithubStorage=Z.GithubStorage;exports.IdGenerationError=Z.IdGenerationError;exports.IdGenerator=Z.IdGenerator;exports.LocalStorage=Z.LocalStorage;exports.MigrationError=Z.MigrationError;exports.StorageError=Z.StorageError;exports.base36Decode=Z.base36Decode;exports.base36Encode=Z.base36Encode;exports.base58Decode=Z.base58Decode;exports.buildId=Z.buildId;exports.buildPromotionMap=Z.buildPromotionMap;exports.cleanName=Z.cleanName;exports.decodeId=Z.decodeId;exports.decodeIdString=Z.decodeIdString;exports.encodeId=Z.encodeId;exports.extractIdFromUrl=Z.extractIdFromUrl;exports.extractStatus=Z.extractStatus;exports.extractType=Z.extractType;exports.normalizeCatalog=Z.normalizeCatalog;exports.parseId=Z.parseId;exports.shardOf=Z.shardOf;exports.smartDecode=Z.smartDecode;exports.validateResource=Z.validateResource;exports.Badge=Vt;exports.BidUrlProvider=Yo;exports.BookDetailLayout=id;exports.BookFullText=wn;exports.BookPage=_o;exports.Breadcrumb=$r;exports.Chip=Et;exports.ChipWall=Jt;exports.CollatedEdition=Gn;exports.CollectionCatalog=Ln;exports.CollectionPage=Co;exports.CreateEntityDialog=xo;exports.DETAIL_CSS=Br;exports.Dash=ot;exports.DataTable=Qe;exports.DetailFooter=Ur;exports.DetailHeader=Ar;exports.EmendatedBySection=mr;exports.EmptyNote=lt;exports.EntityDetail=dr;exports.EntityPage=To;exports.EntityPickerDialog=mo;exports.EntitySelector=fo;exports.ExpandRow=Mr;exports.ExtLink=jn;exports.FactList=Rt;exports.FeedbackButton=gc;exports.FeedbackDialog=vo;exports.FeedbackForm=jo;exports.FeedbackList=Un;exports.FeedbackTab=So;exports.FilterChip=Ne;exports.FormInput=ve;exports.FormTextArea=Je;exports.GUJI_MARKDOWN_FIELD=ul;exports.GUJI_TABLE_NOTATION=Qr;exports.GlyphBadge=On;exports.GujiTable=oo;exports.HomePage=kn;exports.IndexApp=pa;exports.IndexBrowser=mn;exports.IndexDetail=Bn;exports.IndexEditor=ho;exports.IndexView=ic;exports.IntroGrid=zt;exports.LocaleContext=Ct;exports.LocaleProvider=ns;exports.LocaleToggle=Bo;exports.ModeIndicator=ar;exports.MoreButton=Ve;exports.PAGE_MAX_WIDTH=ht;exports.PageFrame=Ft;exports.Quote=Mt;exports.ROLE_CLASS_ORDER=wr;exports.RelationPanel=po;exports.RepoSourceLink=Lo;exports.ResourceEditor=gn;exports.ResourceGroup=vn;exports.ResourceLine=st;exports.ResourceList=En;exports.ResourceRow=Nr;exports.SNIPPET_MARK_END=tr;exports.SNIPPET_MARK_START=er;exports.SearchInput=cr;exports.Section=Te;exports.SectionHead=xe;exports.SmartBidInput=Pt;exports.SourceEditor=lo;exports.TableHead=Xt;exports.TableRow=Zt;exports.TagRow=Hn;exports.TagRows=Gr;exports.TextButton=qt;exports.TopStrip=Wr;exports.VersionLineageGraph=Ro;exports.VersionLineageList=zo;exports.VersionLineageView=Eo;exports.VolumeChips=Fr;exports.VolumeLinks=Vr;exports.WorkCatalog=Sa;exports.WorkPage=wo;exports.bucketResources=Kt;exports.buildCollectionTable=Cr;exports.buildLineageGraph=Ot;exports.buildPageUrl=Rn;exports.buildVersionRow=Sr;exports.buildVersionTable=kr;exports.computeVersionPartition=al;exports.deriveDating=ol;exports.deriveEditionType=Ir;exports.deriveEra=It;exports.deriveYear=Yt;exports.deriveYearRange=$n;exports.detailToEditor=yo;exports.displayAuthorRole=Mn;exports.editorToDetail=nc;exports.eraRank=bn;exports.flattenTitles=_t;exports.formatTemplate=Tt;exports.formatVolumeRange=Pn;exports.getDisplayNameFromUrl=kt;exports.getStartPage=zn;exports.getTypeGroupKey=Cn;exports.groupRelatedWorks=jr;exports.gujiInlineToPlain=Er;exports.hasGujiMarkdownV02=yn;exports.hasGujiTableNotation=eo;exports.measureText=Ze;exports.mergeVolumeResources=Tn;exports.normalizeEra=ue;exports.normalizeRole=Fn;exports.normalizeVolumeIndex=jt;exports.normalizeVolumes=lr;exports.numberToChinese=Tr;exports.parseChineseNumber=Dt;exports.parseGujiInline=Rr;exports.parseGujiTable=no;exports.parseSourceString=ao;exports.renderFullTextBody=so;exports.resourceHref=Ht;exports.resourceNote=An;exports.roleFacets=_r;exports.rowNo=Qt;exports.sortYear=vr;exports.splitFullTextTables=io;exports.splitHighlightSnippet=nr;exports.splitTableRow=to;exports.stringifySources=co;exports.useBidUrl=je;exports.useConvert=P;exports.useT=N;exports.validateLineageGraph=$c;exports.volumeStats=In;
|