book-index-ui 0.2.6 → 0.2.7

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 CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var dn=Object.create;var Je=Object.defineProperty;var pn=Object.getOwnPropertyDescriptor;var xn=Object.getOwnPropertyNames;var un=Object.getPrototypeOf,fn=Object.prototype.hasOwnProperty;var gn=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of xn(n))!fn.call(t,i)&&i!==o&&Je(t,i,{get:()=>n[i],enumerable:!(r=pn(n,i))||r.enumerable});return t};var hn=(t,n,o)=>(o=t!=null?dn(un(t)):{},gn(n||!t||!t.__esModule?Je(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("./storage-entry-BTHh3quk.cjs"),e=require("react/jsx-runtime"),f=require("react"),bn=require("react-dom"),mn=t=>`/book-index?id=${t}`,zt=f.createContext(mn);function yn({buildUrl:t,children:n}){const o=f.useMemo(()=>t,[t]);return e.jsx(zt.Provider,{value:o,children:n})}function re(){return f.useContext(zt)}const ze=f.createContext(null),It={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"實體資源"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"實體"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入",belongsToWork:"所屬作品",locationHistory:"流轉���史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"叢書目錄",siteTab:"在線資源",recommendTab:"推薦",feedbackTab:"反饋",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},detailTab:{basicInfo:"基本信息",catalog:"目錄",collectionCatalog:"叢編目錄",collatedEdition:"整理本",catalogSuffix:"·目錄"},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",total_pages:"總頁數",page_range:"頁碼範圍",page_count:"頁數",file_page_range:"文件頁碼",file_page_count:"文件頁數",content_page_range:"影印頁碼",volume:"冊",color_mode:"色彩",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},vn={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"实体资源"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"实体"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"丛书目录",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"基本信息",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"整理本",catalogSuffix:"·目录"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},jn={"zh-Hant":It,"zh-Hans":vn},Tt="bim-locale";function Sn(){try{const t=localStorage.getItem(Tt);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function kn(t){try{localStorage.setItem(Tt,t)}catch{}}const wn="zh-Hant",Cn=({locale:t,onLocaleChange:n,children:o})=>{const[r,i]=f.useState(t??wn),l=t??r;f.useEffect(()=>{if(t)return;const d=Sn();d&&d!==r&&i(d)},[]);const[s,c]=f.useState(null);f.useEffect(()=>{l==="zh-Hans"?import("opencc-js/t2cn").then(d=>{const p=d.Converter({from:"tw",to:"cn"});c(()=>p)}).catch(()=>{c(()=>d=>d)}):c(null)},[l]);const a=f.useCallback(d=>{i(d),kn(d),n==null||n(d)},[n]),u=f.useMemo(()=>({locale:l,setLocale:a,messages:jn[l],converter:s}),[l,a,s]);return e.jsx(ze.Provider,{value:u,children:o})};function A(){const t=f.useContext(ze);return(t==null?void 0:t.messages)??It}const _n=2e3;function D(){const t=f.useContext(ze),n=(t==null?void 0:t.locale)??"zh-Hant",o=(t==null?void 0:t.converter)??null,r=f.useRef(new Map),i=f.useRef(n);i.current!==n&&(r.current.clear(),i.current=n);const l=f.useCallback(s=>{if(!s)return"";if(!o)return s;const c=r.current.get(s);if(c!==void 0)return c;const a=o(s);if(r.current.size>=_n){const u=r.current.keys().next().value;u!==void 0&&r.current.delete(u)}return r.current.set(s,a),a},[o]);return f.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Ie(t,n){return t.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function zn(t){if(!t)return"";try{const n=new URL(t).hostname,o={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(o[n])return o[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function In(){return{id:"",name:"",url:"",type:"text",details:""}}const Ue=({items:t,onChange:n,onDownload:o,downloadStatuses:r,filterType:i})=>{const l=A(),[s,c]=f.useState(null),a=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],u=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],d=m=>i?i==="text"?m==="text"||m==="text+image":i==="image"?m==="image"||m==="text+image"||m==="physical":m===i:!0,p=t.map((m,v)=>({item:m,originalIndex:v})).filter(({item:m})=>d(m.type)),h=()=>{const m=In();i&&(m.type=i),n([...t,m]),c(t.length)},x=m=>{n(t.filter((v,b)=>b!==m)),c(null)},y=(m,v,b)=>{const z=[...t];if(z[m]={...z[m],[v]:b},v==="url"&&!z[m].id){const k=zn(b);k&&(z[m].id=k)}n(z)},j=(m,v,b)=>{const k={...t[m].metadata||{}};b?k[v]=b:delete k[v],y(m,"metadata",Object.keys(k).length>0?k:void 0)},g=(m,v)=>{const b=v.trim()?v.split(/[,,、]/).map(z=>z.trim()).filter(Boolean):void 0;y(m,"structure",b)},I=(m,v,b)=>{const k=t[m].coverage||{level:1,ranges:""};v==="level"?k.level=parseInt(b)||1:k.ranges=b,y(m,"coverage",k.ranges?k:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[p.map(({item:m,originalIndex:v})=>{var b,z,k,w;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>c(s===v?null:v),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===v?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Tn(m.type),color:"#fff"},children:((b=a.find(C=>C.value===m.type))==null?void 0:b.label)||m.type}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.name||`${l.editor.resourcePlaceholder} ${v+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:"🔗"}),o&&m.url&&Rn(v,r==null?void 0:r[v],o,l),e.jsx("button",{onClick:C=>{C.stopPropagation(),x(v)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),s===v&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(m.type==="image"||m.type==="text+image")&&m.url&&Ln(m,l),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:je,children:[e.jsx("span",{style:Se,children:l.label.type}),e.jsx("select",{value:m.type,onChange:C=>y(v,"type",C.target.value),style:{...ae,flex:1},children:a.map(C=>e.jsx("option",{value:C.value,children:C.label},C.value))})]}),e.jsxs("label",{style:je,children:[e.jsx("span",{style:Se,children:l.label.rootType}),e.jsx("select",{value:m.root_type||"catalog",onChange:C=>y(v,"root_type",C.target.value),style:{...ae,flex:1},children:u.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=>y(v,"id",C.target.value),placeholder:l.editor.idAutoExtract,style:{...ae,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:m.name,onChange:C=>y(v,"name",C.target.value),placeholder:l.editor.resourceName,style:{...ae,flex:1}})]}),e.jsx("input",{type:"text",value:m.url,onChange:C=>y(v,"url",C.target.value),placeholder:l.editor.resourceUrl,style:ae}),e.jsx("input",{type:"text",value:((z=m.structure)==null?void 0:z.join("、"))||"",onChange:C=>g(v,C.target.value),placeholder:l.editor.structurePlaceholder,style:ae}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:je,children:[e.jsx("span",{style:Se,children:l.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((k=m.coverage)==null?void 0:k.level)??"",onChange:C=>I(v,"level",C.target.value),placeholder:"1",style:{...ae,width:"60px"}})]}),e.jsxs("label",{style:{...je,flex:1},children:[e.jsx("span",{style:Se,children:l.label.coverageRange}),e.jsx("input",{type:"text",value:((w=m.coverage)==null?void 0:w.ranges)||"",onChange:C=>I(v,"ranges",C.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...ae,flex:1}})]})]}),e.jsx("textarea",{value:m.details||"",onChange:C=>y(v,"details",C.target.value),placeholder:l.editor.detailsPlaceholder,style:{...ae,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:l.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(l.metadata).map(([C,B])=>{var R;return e.jsxs("label",{style:{...je,gap:"4px"},children:[e.jsx("span",{style:{...Se,minWidth:"56px"},children:B}),e.jsx("input",{type:"text",value:((R=m.metadata)==null?void 0:R[C])||"",onChange:E=>j(v,C,E.target.value),placeholder:B,style:{...ae,flex:1}})]},C)})})]})]})]})]},v)}),e.jsxs("button",{onClick:h,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:l.action.addResource})]})]})};function Tn(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function Rn(t,n,o,r){const i=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:s=>{s.stopPropagation(),i||o(t,"")},disabled:i,style:{background:"transparent",border:"none",color:l?"var(--bim-success, #4caf50)":i?"var(--bim-desc-fg, #717171)":"var(--bim-link-fg, #0066cc)",cursor:i?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:i?.6:.9},title:l?r.download.completed:i?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:l?"✓":i?"⏳":"⬇"})}function Ln(t,n){const o=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url)||t.url.includes("iiif")||t.url.includes("image");return e.jsx("div",{style:{marginBottom:"12px"},children:o?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"#00000010"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"#00000010",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const ae={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"},je={display:"flex",alignItems:"center",gap:"6px"},Se={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},En={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function Bn(t){try{const n=new URL(t).hostname;return En[n]}catch{return}}const Ze={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"},Wn=["text","image","text+image","physical"];function $n(t){const n=l=>{const s=l.match(/^(.+?)·第(\d+)[冊册]$/);if(s)return[s[1],parseInt(s[2])];const c=l.match(/^(.+?)[·(](\d+)[)]?$/);return c?[c[1],parseInt(c[2])]:null},o=new Map,r=[],i=new Set;for(let l=0;l<t.length;l++){const s=t[l];if(s.volumes&&s.volumes.length>0)continue;const c=n(s.name);if(!c)continue;const[a,u]=c,d=`${a}|${s.type}`;o.has(d)||o.set(d,{base:{...s,name:a,url:"",volumes:[]},volumes:[]}),o.get(d).volumes.push({volume:u,url:s.url||void 0,status:"found"}),i.add(l)}for(const[,l]of o)if(l.volumes.length>=2)l.volumes.sort((s,c)=>s.volume-c.volume),l.base.volumes=l.volumes,l.base.expected_volumes=l.volumes.length,r.push(l.base);else for(let s=0;s<t.length;s++)if(i.has(s)){const c=n(t[s].name);c&&`${c[0]}|${t[s].type}`==`${l.base.name}|${l.base.type}`&&i.delete(s)}for(let l=0;l<t.length;l++)i.has(l)||r.push(t[l]);return r}const Ye=({items:t,groupByType:n=!0,onNavigate:o,renderLink:r})=>{const i=A(),l=f.useMemo(()=>$n(t||[]),[t]),s={text:i.resourceType.text,image:i.resourceType.image,"text+image":i.resourceType.textImage,physical:i.resourceType.physical};if(!l||l.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:i.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:l.map((a,u)=>e.jsx(Qe,{item:a},a.id||u))});const c=Wn.map(a=>({type:a,items:l.filter(u=>u.type===a)})).filter(a=>a.items.length>0);return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:c.map(({type:a,items:u})=>e.jsxs("div",{children:[e.jsxs("h4",{style:{margin:"0 0 8px",fontSize:"13px",fontWeight:600,color:Ze[a],display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx("span",{style:{display:"inline-block",width:"4px",height:"14px",borderRadius:"2px",background:Ze[a]}}),s[a],e.jsxs("span",{style:{fontWeight:400,opacity:.6},children:["(",u.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:u.map((d,p)=>e.jsx(Qe,{item:d,onNavigate:o,renderLink:r},d.id||p))})]},a))})},Xe=t=>{const n=t.volumes&&t.volumes.length>0;return t.details&&!n||t.structure||t.coverage||t.metadata&&Object.keys(t.metadata).length>0},Rt=({value:t})=>{const o=A().checkType[t];return o?e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:o.bg,color:o.fg},children:o.label}):e.jsx("span",{children:t})},An=(t,n,o,r)=>{if(t==="check_type"&&typeof n=="string")return e.jsx(Rt,{value:n});if(t==="has_translation")return n?o.misc.hasTranslation:o.misc.noTranslation;const i=String(n);return r?r(i):i};function Pn(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const i=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(i)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(i[1]))}&page=${n}`;const l=new URL(t);return l.searchParams.set("page",String(n)),l.toString()}return t}catch{return t}}function Fn(t){if(!t)return;const n=t.file_page_range||t.page_range;if(!n||typeof n!="string")return;const o=n.match(/^(\d+)/);return o?parseInt(o[1],10):void 0}function Mn(t){if(t.url)return t.url;for(const[n,o]of Object.entries(t))if(n.endsWith("_url")&&typeof o=="string")return o}const Dn={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},Qe=({item:t,onNavigate:n,renderLink:o})=>{var j;const r=A(),{convert:i}=D(),l=re(),[s,c]=f.useState(!1),a=f.useMemo(()=>(t.url?Bn(t.url):void 0)||i(t.name),[t.url,t.name,i]),u=f.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(g=>({...g,url:g.url||Mn(g)})),[t.volumes]),d=u&&u.length>0,p=d?new Set(u.filter(g=>g.status!=="missing").map(g=>g.volume)).size:0,h=d?new Set(u.filter(g=>g.status==="missing").map(g=>g.volume)).size:0,x=t.expected_volumes??(d?p+h:0),y=t.color_mode?{...Dn[t.color_mode],label:r.colorMode[t.color_mode]}:null;return e.jsxs("div",{style:{padding:"10px 14px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:Xe(t)||d?"6px":"0"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:a}),y&&e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:y.bg,color:y.fg},children:y.label}),t.source_label&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",fontStyle:"italic"},children:t.source_label}),((j=t.metadata)==null?void 0:j.check_type)&&e.jsx(Rt,{value:t.metadata.check_type}),d&&e.jsxs("span",{style:{padding:"1px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:"transparent",color:"var(--bim-desc-fg, #717171)"},children:[p,"/",x,r.unit.volume,h>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"4px"},children:["缺",h]})]}),t.url&&e.jsx("a",{href:(()=>{const g=Fn(t.metadata);return g?Pn(t.url,g):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:r.action.visit}),d&&e.jsx("button",{onClick:()=>c(!s),title:s?"收起分册":"展开分册",style:{marginLeft:"auto",padding:"1px 10px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:s?"var(--bim-widget-border, #e0e0e0)":"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",lineHeight:1.4},children:s?"收起 ▲":"展开 ▼"})]}),Xe(t)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"12px",flexWrap:"wrap"},children:[t.metadata&&Object.entries(t.metadata).filter(([g])=>g!=="check_type").map(([g,I])=>e.jsxs("span",{children:[r.metadata[g]||g,": ",An(g,I,r,i)]},g)),t.details&&!d&&e.jsx("span",{children:i(t.details)}),t.structure&&e.jsxs("span",{children:[r.misc.structure,": ",t.structure.join(" → ")]}),t.coverage&&e.jsxs("span",{children:[r.misc.coverage,": L",t.coverage.level," ",t.coverage.ranges]})]}),d&&s&&(()=>{const g=u.some(v=>v.group),I=[];if(g){let v=null;for(const b of u){const z=b.group||"";(!v||v.title!==z)&&(v={title:z,group_id:b.group_id,vols:[]},I.push(v)),v.vols.push(b)}}else I.push({vols:u});const m=v=>{const b=v.status==="missing";return v.url&&!b?e.jsx("a",{href:v.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",lineHeight:1.4},title:v.label||`${v.volume}`,children:v.volume},v.volume):e.jsx("span",{style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid transparent",color:b?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:b?"line-through":"none",opacity:b?.6:1,lineHeight:1.4},children:v.volume},v.volume)};return e.jsx("div",{style:{marginTop:"8px",padding:"8px 0",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",display:"flex",flexDirection:"column",gap:"8px"},children:I.map((v,b)=>{const z=v.title?i(v.title):"";let k=z;return v.title&&v.group_id&&(o?k=o(v.group_id,z):n&&(k=e.jsx("a",{href:l(v.group_id),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),n(v.group_id))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:w=>w.currentTarget.style.borderBottomStyle="solid",onMouseLeave:w=>w.currentTarget.style.borderBottomStyle="dashed",children:z}))),e.jsxs("div",{children:[v.title&&e.jsxs("div",{style:{fontSize:"12px",fontWeight:500,color:"var(--bim-fg, #333)",marginBottom:"4px"},children:[k,e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",v.vols.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px"},children:v.vols.map(m)})]},b)})})})()]})},Lt=({indexSource:t,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:i,onConfigurePath:l,onSelectFolder:s})=>{const c=A(),a=t==="local",u=(n==null?void 0:n.isDraft)??!0,d=(n==null?void 0:n.repoPath)||"",p=d?d.split(/[/\\]/).pop()||d:"",h={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:"var(--bim-primary-soft, #0078d415)",color:"var(--bim-primary, #0078d4)"},x={onMouseOver:j=>j.currentTarget.style.opacity="0.8",onMouseOut:j=>j.currentTarget.style.opacity="1"},y=e.jsxs("div",{onClick:i,title:u?c.mode.switchToOfficial:c.mode.switchToDraft,style:{...h,background:u?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...x,children:[e.jsx("span",{children:u?"📝":"📚"}),e.jsx("span",{children:u?"draft":"official"})]});return o==="index-browser"?a?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[y,e.jsxs("div",{onClick:r,title:c.mode.switchToSync,style:h,...x,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:c.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:s,title:d||c.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px"},...x,children:[e.jsx("span",{children:"📂"}),p&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:p})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[y,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:r,title:c.mode.switchToLocal,style:h,...x,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:c.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:l,title:p||c.mode.configurePath,style:{...h,background:"transparent",padding:"6px",fontSize:"12px"},...x,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:r,title:a?c.mode.switchToGithub:c.mode.switchToLocal,style:h,...x,children:[e.jsx("span",{children:a?"📁":"🌐"}),e.jsx("span",{children:a?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&e.jsxs("div",{onClick:s,title:d||c.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px",minWidth:d?"100px":"auto",justifyContent:"space-between"},...x,children:[e.jsx("span",{children:"📂"}),p&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:p})]}),!a&&p&&e.jsxs("div",{style:{...h,background:"#2196f3",color:"white",cursor:"default"},title:d,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:p})]})]})},$e="bim-search-history",et=10,tt=8;function we(){try{const t=localStorage.getItem($e);return t?JSON.parse(t):[]}catch{return[]}}function Hn(t){try{const n=we().filter(o=>o!==t);n.unshift(t),n.length>et&&(n.length=et),localStorage.setItem($e,JSON.stringify(n))}catch{}}function On(t){try{const n=we().filter(o=>o!==t);localStorage.setItem($e,JSON.stringify(n))}catch{}}function Un(){try{localStorage.removeItem($e)}catch{}}const Et=({transport:t,value:n,onChange:o,onSearch:r,onEntrySelect:i,placeholder:l})=>{const s=A(),c=l??s.search.placeholder,a={work:s.indexType.work,book:s.indexType.book,collection:s.indexType.collection,entity:s.indexType.entity},[u,d]=f.useState(!1),[p,h]=f.useState([]),[x,y]=f.useState(-1),[j,g]=f.useState(null),[I,m]=f.useState(we),v=f.useRef(null),b=f.useRef(null),z=f.useRef(null);f.useEffect(()=>{if(!t.getAllEntries)return;let _=!1;return t.getAllEntries().then($=>{_||g($)}).catch(()=>{}),()=>{_=!0}},[t]);const k=f.useCallback(_=>{if(!_.trim())return I.map(S=>({type:"history",text:S}));if(!j)return[];const $=_.toLowerCase(),W=[],U=[];for(const S of j){if(W.length+U.length>=tt*2)break;const L=(S.title??"").toLowerCase();if(L.startsWith($))W.push({type:"entry",text:S.title,entry:S});else if(L.includes($))U.push({type:"entry",text:S.title,entry:S});else{const K=[...S.additional_titles||[],...S.attached_texts||[]];for(const V of K){const F=typeof V=="string"?V:V==null?void 0:V.book_title;if(F!=null&&F.toLowerCase().includes($)){W.push({type:"entry",text:`${S.title}`,entry:S});break}}}}return[...W,...U].slice(0,tt)},[j,I]);f.useEffect(()=>{h(k(n)),y(-1)},[n,k]),f.useEffect(()=>{const _=$=>{z.current&&!z.current.contains($.target)&&d(!1)};return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[]),f.useEffect(()=>{const _=$=>{var W,U;if($.key==="/"&&document.activeElement!==v.current){const S=(W=document.activeElement)==null?void 0:W.tagName;if(S==="INPUT"||S==="TEXTAREA"||S==="SELECT")return;$.preventDefault(),(U=v.current)==null||U.focus()}};return document.addEventListener("keydown",_),()=>document.removeEventListener("keydown",_)},[]);const w=f.useCallback(_=>{_.trim()&&(Hn(_.trim()),m(we())),r(_),d(!1)},[r]),C=f.useCallback(_=>{_.type==="history"?(o(_.text),w(_.text)):_.entry&&(i?(i(_.entry),d(!1)):(o(_.text),w(_.text)))},[o,w,i]),B=f.useCallback(_=>{if(!u||p.length===0){_.key==="Enter"&&w(n);return}switch(_.key){case"ArrowDown":_.preventDefault(),y($=>($+1)%p.length);break;case"ArrowUp":_.preventDefault(),y($=>($-1+p.length)%p.length);break;case"Enter":_.preventDefault(),x>=0&&x<p.length?C(p[x]):w(n);break;case"Escape":_.preventDefault(),d(!1);break}},[u,p,x,n,w,C]),R=f.useCallback((_,$)=>{$.stopPropagation(),On(_),m(we()),h(W=>W.filter(U=>!(U.type==="history"&&U.text===_)))},[]),E=f.useCallback(_=>{_.stopPropagation(),Un(),m([]),h([])},[]);f.useEffect(()=>{if(x>=0&&b.current){const _=b.current.children;_[x]&&_[x].scrollIntoView({block:"nearest"})}},[x]);const H=!n.trim()&&I.length>0;return e.jsxs("div",{ref:z,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:v,type:"text",placeholder:c,value:n,onChange:_=>{o(_.target.value),d(!0)},onFocus:()=>d(!0),onKeyDown:B,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"}}),u&&p.length>0&&e.jsxs("div",{ref:b,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[H&&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:s.search.history}),e.jsx("button",{onClick:E,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:s.search.clearAll})]}),p.map((_,$)=>e.jsxs("div",{onClick:()=>C(_),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:$===x?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:_.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:_.text}),_.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[a[_.entry.type],_.entry.edition&&` · ${_.entry.edition}`,_.entry.author&&` · ${_.entry.author}`]}),_.type==="history"&&e.jsx("button",{onClick:W=>R(_.text,W),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:s.action.remove,children:"×"})]},`${_.type}-${_.text}-${$}`))]})]})},_e="bim-recent-ids",nt="bim-recent-entries",rt=50,De=5,Vn=50,Kn=200;function Ce(){try{const t=localStorage.getItem(_e);if(t)return JSON.parse(t);const n=localStorage.getItem(nt);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(_e,JSON.stringify(o)),localStorage.removeItem(nt),o}return[]}catch{return[]}}function Nn(t){try{const n=Ce().filter(o=>o!==t);n.unshift(t),n.length>rt&&(n.length=rt),localStorage.setItem(_e,JSON.stringify(n))}catch{}}function Yn(t){try{const n=Ce().filter(o=>o!==t);localStorage.setItem(_e,JSON.stringify(n))}catch{}}function Gn(){try{localStorage.removeItem(_e)}catch{}}const qn={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Ve=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:i,onSwitchMode:l,onToggleDraft:s,onConfigurePath:c,onSelectFolder:a,hideModeIndicator:u,initialQuery:d,onQueryChange:p,headerRight:h})=>{const x=A(),y=[{type:"work",icon:"✍️",name:x.indexType.work,key:"works"},{type:"book",icon:"📖",name:x.indexType.book,key:"books"},{type:"collection",icon:"📚",name:x.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:x.indexType.entity,key:"entities"}],[j,g]=f.useState(d??""),[I,m]=f.useState(null),[v,b]=f.useState(null),[z,k]=f.useState(!1),[w,C]=f.useState(null),[B,R]=f.useState(""),[E,H]=f.useState(!d),[_,$]=f.useState(Ce),[W,U]=f.useState([]),[S,L]=f.useState(!1),[K,V]=f.useState(!1),[F,le]=f.useState(null),[Q,de]=f.useState(null),ue=f.useRef(void 0),xe=f.useRef(!1),J=f.useCallback(async(P,Y)=>{if(!P.trim()){H(!0),m(null),b(null);return}H(!1),k(!0),R("");try{if(t.searchAll){const Z=await t.searchAll(P,Y??De);m(Z)}else{const Z=["work","book","collection","entity"],G=await Promise.all(Z.map(te=>t.search(P,te,{page:1,pageSize:Y??De})));m({works:G[0].entries,books:G[1].entries,collections:G[2].entries,entities:G[3].entries,totalWorks:G[0].total,totalBooks:G[1].total,totalCollections:G[2].total,totalEntities:G[3].total})}}catch(Z){R(Z instanceof Error?Z.message:String(Z)),m(null)}finally{k(!1)}},[t]);f.useEffect(()=>{var T,M;let P=!1;const Y=["work","book","collection","entity"],Z=Promise.all(Y.map(q=>t.loadEntries(q,{page:1,pageSize:1}).catch(()=>({total:0})))),G=((T=t.getResourceCounts)==null?void 0:T.call(t).catch(()=>null))??Promise.resolve(null),te=((M=t.getSubtypeStats)==null?void 0:M.call(t).catch(()=>null))??Promise.resolve(null);return Promise.all([Z,G,te]).then(([q,se,he])=>{P||(le({works:q[0].total,books:q[1].total,collections:q[2].total,entities:q[3].total,hasText:se==null?void 0:se.hasText,hasImage:se==null?void 0:se.hasImage}),he&&de(he))}),()=>{P=!0}},[t]),f.useEffect(()=>{xe.current||!(d!=null&&d.trim())||(xe.current=!0,J(d))},[d,J]);const N=f.useCallback(P=>{if(g(P),p==null||p(P),!P.trim()){H(!0),m(null),b(null);return}ue.current&&clearTimeout(ue.current),ue.current=setTimeout(()=>{b(null),J(P)},Kn)},[J,p]),Ae=f.useCallback(P=>{ue.current&&clearTimeout(ue.current),p==null||p(P),J(P)},[J,p]),Pe=f.useCallback(P=>{b(P),J(j,Vn)},[j,J]);f.useEffect(()=>{if(!_.length){U([]);return}let P=!1;return L(!0),Promise.all(_.slice(0,10).map(async Y=>{var Z,G,te;try{if(t.getEntry){const M=await t.getEntry(Y);if(M)return M}const T=await t.getItem(Y);if(T){const M=T.authors;return{id:Y,title:T.title||Y,type:T.type||"work",author:(Z=M==null?void 0:M[0])==null?void 0:Z.name,dynasty:(G=M==null?void 0:M[0])==null?void 0:G.dynasty,role:(te=M==null?void 0:M[0])==null?void 0:te.role,edition:T.edition||void 0}}}catch{}return{id:Y,title:Y,type:"work",notFound:!0}})).then(Y=>{P||(U(Y),L(!1))}),()=>{P=!0}},[_,t]);const ye=P=>{C(P.id),Nn(P.id),$(Ce()),r==null||r(P)},ve=P=>{Yn(P),$(Ce())},Fe=()=>{Gn(),$([])},Te=P=>y.find(Y=>Y.type===P),Me=I&&(I.works.length>0||I.books.length>0||I.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:x.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,!u&&e.jsx(Lt,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:l,onToggleDraft:s,onConfigurePath:c,onSelectFolder:a})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Et,{transport:t,value:j,onChange:N,onSearch:Ae,onEntrySelect:ye}),i&&e.jsx("button",{onClick:()=>i("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:x.action.newEntry})]}),F&&E&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[e.jsx("span",{children:Q?e.jsxs(e.Fragment,{children:[(Q.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Q.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.books.toLocaleString()})," 本"]}),Q.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Q.article.toLocaleString()})," 篇"]}):null,Q.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Q.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[x.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),x.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),x.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.collections.toLocaleString()}),F.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),x.indexType.entity," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.entities.toLocaleString()})]})]})}),F.hasImage!=null&&F.hasText!=null&&e.jsxs("span",{children:[x.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),x.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:z?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:x.search.searching}):B?e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"24px",marginBottom:"8px"},children:"⚠️"}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)"},children:B})]}):E?e.jsx("div",{style:{flex:1},children:S?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:x.search.loading}):W.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{children:x.search.recentBrowse}),e.jsx("button",{onClick:Fe,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:x.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:W.slice(0,K?10:3).map(P=>P.notFound?e.jsx(Jn,{id:P.id,onRemove:ve,t:x},P.id):e.jsx(ot,{entry:P,selected:w===P.id,onClick:ye,getConfig:Te,onRemove:ve},P.id))}),!K&&W.length>3&&e.jsx("button",{onClick:()=>V(!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:x.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:x.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:x.search.searchSubtitle})]})}):Me?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:y.map(({type:P,icon:Y,name:Z,key:G})=>{const te=I[G]??[],T=qn[G],M=I[T]??0;if(te.length===0)return null;const se=!(v===P)&&M>De;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:[Y," ",Z,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[M," ",x.unit.items]})]}),se&&e.jsx("button",{onClick:()=>Pe(P),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:x.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:te.map(he=>e.jsx(ot,{entry:he,selected:w===he.id,onClick:ye,getConfig:Te,query:j},he.id))})]},P)})}):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:Ie(x.search.noResultsFor,{query:j})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:x.search.tryOther})]})})]})},ot=({entry:t,selected:n,onClick:o,getConfig:r,query:i,onRemove:l})=>{const s=A(),{convert:c}=D(),a=[...t.additional_titles||[],...t.attached_texts||[]],u=i&&a.length?a.find(d=>{const p=typeof d=="string"?d:d==null?void 0:d.book_title;return p==null?void 0:p.toLowerCase().includes(i.toLowerCase())}):void 0;return e.jsxs("div",{onClick:()=>o(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:r(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:r(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:c(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:s.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:s.misc.imageResource,children:"🖼️"})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.edition)}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,s.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??"?"]})]}),u&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[s.search.alias,":",c(u)]})]}),l?e.jsx("button",{onClick:d=>{d.stopPropagation(),l(t.id)},title:s.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:"→"})]})},Jn=({id:t,onRemove:n,t:o})=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",opacity:.6},children:[e.jsx("span",{style:{fontSize:"16px"},children:"❓"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",fontFamily:"monospace"},children:t}),e.jsx("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginTop:"2px"},children:o.search.itemNotFound})]}),e.jsx("button",{onClick:()=>n(t),title:o.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function Zn(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 Xn({data:t}){const{convert:n}=D(),{dynasty:o,birth_year:r,death_year:i}=t,l=[];return o&&l.push(`〔${n(o)}〕`),r!==void 0&&i!==void 0?l.push(`${r}—${i}`):r!==void 0?l.push(`${r}—?`):i!==void 0&&l.push(`?—${i}`),l.length===0?null:e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-desc-fg, #717171)",marginLeft:"8px",fontWeight:"normal"},children:l.join(" ")})}function Qn({alt_names:t}){const{convert:n}=D(),o=new Map;for(const l of t){const s=l.type||"別名";o.has(s)||o.set(s,[]),o.get(s).push(l.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],i=[...o.keys()].sort((l,s)=>{const c=r.indexOf(l),a=r.indexOf(s);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:i.map(l=>{const s=o.get(l);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:l}),e.jsx("span",{children:s.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))})]},l)})})}function er({data:t}){const n=t.external_ids;if(!n)return null;const o=[];return n.cbdb_id&&o.push(e.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${n.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",border:"1px solid var(--bim-link-fg, #0066cc)40",borderRadius:"3px",textDecoration:"none",background:"var(--bim-link-fg, #0066cc)08"},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),o.length===0?null:e.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:o})}function tr({works:t,transport:n,onNavigate:o,renderLink:r}){const i=A(),{convert:l}=D(),s=re(),[c,a]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let h=!1;const x=t.map(j=>j.work_id);return(async()=>{const j=new Map;if(n.getEntriesByIds)try{const v=await n.getEntriesByIds(x);let b=!0;for(let z=0;z<x.length;z++){const k=v[z];k!=null&&k.title?j.set(x[z],k.title):k!=null&&k.primary_name?j.set(x[z],k.primary_name):b=!1}if(b)return j}catch{}if(n.getAllEntries)try{const v=await n.getAllEntries(),b=new Map(v.map(k=>[k.id,k.title||k.primary_name||k.id]));let z=!0;for(const k of x){const w=b.get(k);w?j.set(k,w):z=!1}if(z)return j}catch{}const g=[...x],I=8,m=new Array(I).fill(0).map(async()=>{for(;g.length;){const v=g.shift();if(!v)break;if(!j.has(v))try{if(n.getEntry){const k=await n.getEntry(v);if(k!=null&&k.title){j.set(v,k.title);continue}}const b=await n.getItem(v),z=b&&(b.title||b.primary_name)||v;j.set(v,z)}catch{j.set(v,v)}}});return await Promise.all(m),j})().then(j=>{h||a(j)}),()=>{h=!0}},[t,n]);const u=new Map;for(const h of t){const x=h.role||"";u.has(x)||u.set(x,[]),u.get(x).push(h)}const d=["撰","編","注","輯","集","校","評","譯","述","作",""],p=[...u.keys()].sort((h,x)=>{const y=d.indexOf(h),j=d.indexOf(x);return y===-1&&j===-1?h.localeCompare(x):y===-1?1:j===-1?-1:y-j});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:[i.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),p.map(h=>{const x=u.get(h);return e.jsxs("div",{style:{marginBottom:"8px"},children:[h&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginBottom:"2px"},children:[l(h)," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #bbb)"},children:["(",x.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:h?"16px":"0",listStyle:h?"disc":"none",fontSize:"14px",lineHeight:1.8},children:x.map((y,j)=>{const g=l(c.get(y.work_id)||y.work_id);return r?e.jsx("li",{children:r(y.work_id,g)},j):o?e.jsx("li",{children:e.jsx("a",{href:s(y.work_id),onClick:I=>{I.metaKey||I.ctrlKey||(I.preventDefault(),o(y.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:g})},j):e.jsx("li",{children:g},j)})})]},h)})]})}const Bt=({data:t,transport:n,onNavigate:o,renderLink:r,headerExtra:i})=>{var d;const l=A(),{convert:s}=D();let c=!1;try{c=O.extractStatus(t.id)==="draft"}catch{}const a=Zn(t),u=t.subtype==="people"?"人物":t.subtype==="place"?"地名":t.subtype==="dynasty"?"朝代":t.subtype==="anonymous"?"佚名":t.subtype==="collective"?"集体":t.subtype;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:"var(--bim-fg, #222)"},children:[s(t.primary_name),e.jsx(Xn,{data:t})]}),i]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:"#5b3e8e",border:"1px solid #5b3e8e40",borderRadius:"2px",background:"#5b3e8e08"},children:l.indexType.entity}),u&&t.subtype!=="people"&&e.jsx("span",{children:u}),c&&e.jsx("span",{style:{padding:"1px 6px",background:"#fff3cd",border:"1px solid #ffc107",borderRadius:"2px",color:"#856404"},children:l.status.draft}),e.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:t.id})]}),a&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #999)",fontStyle:"italic",padding:"8px 12px",background:"var(--bim-widget-bg, #f8f8f8)",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),t.alt_names&&t.alt_names.length>0&&e.jsx(Qn,{alt_names:t.alt_names}),e.jsx(er,{data:t}),((d=t.description)==null?void 0:d.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:s(t.description.text)}),t.works&&t.works.length>0&&e.jsx(tr,{works:t.works,transport:n,onNavigate:o,renderLink:r})]})},nr=["〇","一","二","三","四","五","六","七","八","九"],it=["","十","百","千"];function Wt(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),o=n.length;let r="",i=!1;for(let l=0;l<o;l++){const s=parseInt(n[l]),c=o-1-l;s===0?i=!0:(i&&r&&(r+="〇"),i=!1,s===1&&c===1&&l===0?r+=it[c]:r+=nr[s]+it[c])}return r}function $t({type:t}){const n=A(),o={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3",entity:"#5b3e8e"};return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:o[t],border:`1px solid ${o[t]}40`,borderRadius:"2px",background:`${o[t]}08`},children:n.indexType[t]})}function rr({isDraft:t}){const n=A();return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t?"#e67e22":"#27ae60",border:`1px solid ${t?"#e67e2240":"#27ae6040"}`,borderRadius:"2px",background:t?"#e67e2208":"#27ae6008"},children:t?n.status.draft:n.status.official})}function or({id:t}){const n=A(),[o,r]=f.useState(!1),i=()=>{navigator.clipboard.writeText(t).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",background:"#f6f6f6",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"2px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:i,title:o?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:o?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=o?"1":"0.5",children:o?"✓":"⧉"})]})}function ne({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 ce({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 At({authors:t,type:n,onNavigate:o,renderLink:r}){const{convert:i}=D();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((l,s)=>{const c=i(l.name),a=l.entity_id?e.jsx(ie,{id:l.entity_id,label:c,onNavigate:o,renderLink:r}):e.jsx("span",{style:{fontWeight:500},children:c});return e.jsxs("span",{children:[s>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),l.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",i(l.dynasty),"〕"]}),a,l.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",i(l.role)]})]},s)})})}function ie({id:t,label:n,onNavigate:o,renderLink:r}){const i=re();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:i(t),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),o(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function ir({id:t,title:n,edition:o,type:r,isDraft:i,authors:l,volumeText:s,meta:c,headerExtra:a,onNavigate:u,renderLink:d}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,o&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:o}),s&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:s})]}),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($t,{type:r}),e.jsx(rr,{isDraft:i}),e.jsx(or,{id:t})]}),((l==null?void 0:l.length)||c.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&e.jsx(At,{authors:l,type:r,onNavigate:u,renderLink:d}),c]})]})}function Pt({items:t,label:n,showMeta:o,onNavigate:r,renderLink:i}){const l=A(),{convert:s}=D();if(!t.length)return null;const[c,a]=f.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((u,d)=>{const p=c===d;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...p?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>a(p?null:d),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:p?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:s(u.source)}),!p&&o&&u.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s(u.title_info)}),u.source_bid&&e.jsx("span",{onClick:h=>h.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(ie,{id:u.source_bid,label:l.action.view,onNavigate:r,renderLink:i})})]}),p&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[o&&(u.title_info||u.author_info||u.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[u.title_info&&e.jsx(ce,{label:l.label.titleInfo,children:s(u.title_info)}),u.author_info&&e.jsx(ce,{label:l.label.authorInfo,children:s(u.author_info)}),u.edition&&e.jsx(ce,{label:l.label.edition,children:s(u.edition)})]}),u.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:l.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:s(u.summary)})]}),u.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:l.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:s(u.comment)})]}),u.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:l.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:s(u.additional_comment)})]})]})]},d)})})]})}function lr({items:t,onNavigate:n,renderLink:o}){const r=A();return e.jsx(Pt,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function Ft({items:t,onNavigate:n,renderLink:o}){const r=A();return e.jsx(Pt,{items:t,label:r.section.emendated,onNavigate:n,renderLink:o})}function Mt({label:t,items:n}){const{convert:o}=D();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,i)=>{const l=typeof r=="string"?r:r.book_title;return e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:o(l)},i)})})]}):null}function sr({items:t}){const n=A();return e.jsx(Mt,{label:n.section.aliases,items:t})}function ar({items:t}){const n=A();return e.jsx(Mt,{label:n.section.attachedTexts,items:t})}function cr({items:t}){const n=A(),{convert:o}=D();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((r,i)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:["《",o(r.book_title),"》",r.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},i))})]}):null}function dr({items:t}){const n=A(),{convert:o}=D();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{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,i)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:"var(--bim-primary, #8e6f3e)",border:"1.5px solid var(--bim-input-bg, #fff)"}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:o(r.name)}),r.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:o(r.description)})]},i))]})]}):null}function pr({items:t}){const n=A(),{convert:o}=D();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((r,i)=>e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:"var(--bim-desc-fg, #ccc)"},children:"·"}),o(r)]},i))})]}):null}function lt({title:t,ids:n,transport:o,onNavigate:r,renderLink:i}){const{convert:l}=D(),[s,c]=f.useState([]);return f.useEffect(()=>{if(!n.length){c([]);return}if(!o){c(n.map(u=>({id:u})));return}let a=!1;return Promise.all(n.map(u=>o.getItem(u).then(d=>({id:u,title:d?d.title:void 0,edition:d?d.edition:void 0,type:d?d.type:void 0})).catch(()=>({id:u})))).then(u=>{a||c(u)}),()=>{a=!0}},[n,o]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(ne,{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:(s.length?s:n.map(a=>({id:a}))).map(a=>{const u=a.edition?`${l(a.title)||a.id}(${l(a.edition)})`:l(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:u,onNavigate:r,renderLink:i})},a.id)})})]}):null}function xr({book:t,onNavigate:n,renderLink:o}){const r=A(),{convert:i}=D(),[l,s]=f.useState(!1),c=t.resources&&t.resources.length>0,a=t.edition?i(t.edition):i(t.title)||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{padding:"10px 14px",borderBottom:c&&!l?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1},children:e.jsx(ie,{id:t.id,label:a,onNavigate:n,renderLink:o})}),c&&e.jsx("span",{onClick:()=>s(u=>!u),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:l?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:l?r.action.expand:r.action.collapse,children:"▼"})]}),c&&!l&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(Ye,{items:t.resources,groupByType:!0,onNavigate:n,renderLink:o})})]})}function ur({ids:t,transport:n,onNavigate:o,renderLink:r}){const i=A(),[l,s]=f.useState([]);return f.useEffect(()=>{if(!t.length){s([]);return}if(!n){s(t.map(a=>({id:a})));return}let c=!1;return Promise.all(t.map(a=>n.getItem(a).then(u=>({id:a,title:u?u.title:void 0,edition:u?u.edition:void 0,resources:u?u.resources:void 0})).catch(()=>({id:a})))).then(a=>{c||s(a)}),()=>{c=!0}},[t,n]),t.length?e.jsxs(e.Fragment,{children:[e.jsxs(ne,{children:[i.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:(l.length?l:t.map(c=>({id:c}))).map(c=>e.jsx(xr,{book:c,onNavigate:o,renderLink:r},c.id))})]}):null}function fr({workData:t,onNavigate:n,renderLink:o}){var l,s,c;const r=A(),{convert:i}=D();return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx($t,{type:"work"}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(ie,{id:t.id,label:i(t.title),onNavigate:n,renderLink:o})}),t.measure_info?e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:i(t.measure_info)}):((l=t.juan_count)==null?void 0:l.number)!=null&&t.juan_count.number>0?e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[Wt(t.juan_count.number),r.unit.juan]}):null]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(At,{authors:t.authors,type:"work",onNavigate:n,renderLink:o}),((s=t.description)==null?void 0:s.text)&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,margin:(c=t.authors)!=null&&c.length?"8px 0 0":"0",textAlign:"justify"},children:i(t.description.text)}),t.parent_work&&e.jsx("div",{style:{marginTop:"8px",fontSize:"13px"},children:e.jsx(ce,{label:r.label.parentWork,children:e.jsx(ie,{id:t.parent_work.id,label:i(t.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function gr({items:t,onNavigate:n,renderLink:o}){const r=A(),{convert:i}=D();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(l=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid #2471a340",borderRadius:"4px",background:"#2471a308"},children:[e.jsx("span",{style:{fontSize:"11px",color:"#2471a3"},children:r.indexType.collection}),e.jsx(ie,{id:l.id,label:i(l.title)||l.id,onNavigate:n,renderLink:o}),l.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:Ie(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const Ge=({data:t,id:n,transport:o,onNavigate:r,renderLink:i,headerExtra:l,className:s,style:c})=>{var E,H,_,$,W,U;const a=A(),{convert:u}=D(),[d,p]=f.useState(null),[h,x]=f.useState(!1),[y,j]=f.useState(null),[g,I]=f.useState(null),[m,v]=f.useState([]),b=t||d;if(f.useEffect(()=>{if(t||!n||!o)return;let S=!1;return x(!0),j(null),o.getItem(n).then(L=>{S||(L?p(L):j(a.misc.notFoundEntry))}).catch(L=>{S||j(L instanceof Error?L.message:a.misc.loadFailed)}).finally(()=>{S||x(!1)}),()=>{S=!0}},[t,n,o]),f.useEffect(()=>{if(!b||!o){I(null),v([]);return}let S=!1;const L=b.type==="book"||b.type==="collection"?b.work_id:void 0;if(L?o.getItem(L).then(K=>{!S&&K&&K.type==="work"&&I(K)}).catch(()=>{}):I(null),b.type==="book"){const K=b;K.contained_in&&K.contained_in.length>0?Promise.all(K.contained_in.map(V=>{const F=typeof V=="string"?V:V.id,le=typeof V=="string"?void 0:V.volume_index;return o.getItem(F).then(Q=>({id:F,title:Q&&Q.title||F,volume_index:le})).catch(()=>({id:F,title:F,volume_index:le}))})).then(V=>{S||v(V)}):v([])}else v([]);return()=>{S=!0}},[b,o]),h)return e.jsx("div",{className:s,style:{...c,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((S,L)=>e.jsx("div",{style:{height:L===1?"32px":"16px",width:`${S}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},L))})});if(y)return e.jsx("div",{className:s,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y});if(!b)return null;if(b.type==="entity")return e.jsx("div",{className:s,style:c,children:e.jsx(Bt,{data:b,transport:o,onNavigate:r,renderLink:i,headerExtra:l})});const z=b.type==="book"?b:null,k=b.type==="collection"?b:null,w=b.type==="work"?b:null;let C=!1;try{C=O.extractStatus(b.id)==="draft"}catch{}let B="";b.measure_info?B=u(b.measure_info):(E=b.juan_count)!=null&&E.number?B=Wt(b.juan_count.number)+a.unit.juan:(H=b.juan_count)!=null&&H.description&&(B=u(b.juan_count.description));const R=[];return(_=b.publication_info)!=null&&_.year&&R.push(e.jsx(ce,{label:a.label.year,children:b.publication_info.year},"year")),($=b.current_location)!=null&&$.name&&R.push(e.jsx(ce,{label:a.label.currentLocation,children:u(b.current_location.name)},"loc")),(W=b.page_count)!=null&&W.description&&R.push(e.jsx(ce,{label:a.label.pageCount,children:b.page_count.description},"page")),z!=null&&z.edition&&R.push(e.jsx(ce,{label:a.label.edition,children:u(z.edition)},"ver")),w!=null&&w.parent_work&&R.push(e.jsx(ce,{label:a.label.parentWork,children:e.jsx(ie,{id:w.parent_work.id,label:u(w.parent_work.title),onNavigate:r,renderLink:i})},"pw")),w!=null&&w.parent_works&&w.parent_works.length>0&&!w.parent_work&&R.push(e.jsx(ce,{label:a.label.parentWork,children:w.parent_works.map((S,L)=>e.jsxs("span",{children:[L>0&&"、",e.jsx(ie,{id:S,onNavigate:r,renderLink:i})]},S))},"pws")),e.jsxs("div",{className:s,style:c,children:[e.jsx(ir,{id:b.id,title:u(b.title),edition:b.edition?u(b.edition):void 0,type:b.type,isDraft:C,authors:b.authors,volumeText:B,meta:R,headerExtra:l,onNavigate:r,renderLink:i}),((U=b.description)==null?void 0:U.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"},children:u(b.description.text)}),m.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:a.section.containedIn}),e.jsx(gr,{items:m,onNavigate:r,renderLink:i})]}),g&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:a.section.belongsToWork}),e.jsx(fr,{workData:g,onNavigate:r,renderLink:i})]}),b.additional_works&&b.additional_works.length>0&&e.jsx(cr,{items:b.additional_works}),b.additional_titles&&b.additional_titles.length>0&&e.jsx(sr,{items:b.additional_titles}),b.attached_texts&&b.attached_texts.length>0&&e.jsx(ar,{items:b.attached_texts}),b.indexed_by&&b.indexed_by.length>0&&e.jsx(lr,{items:b.indexed_by,onNavigate:r,renderLink:i}),b.emendated_by&&b.emendated_by.length>0&&e.jsx(Ft,{items:b.emendated_by,onNavigate:r,renderLink:i}),b.resources&&b.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:a.section.resources}),e.jsx(Ye,{items:b.resources,groupByType:!0,onNavigate:r,renderLink:i})]}),(z==null?void 0:z.location_history)&&z.location_history.length>0&&e.jsx(dr,{items:z.location_history}),(k==null?void 0:k.history)&&k.history.length>0&&e.jsx(pr,{items:k.history}),(z==null?void 0:z.related_books)&&z.related_books.length>0&&e.jsx(lt,{title:a.section.relatedVersions,ids:z.related_books,transport:o,onNavigate:r,renderLink:i}),(k==null?void 0:k.books)&&k.books.length>0&&e.jsx(lt,{title:a.section.containedBooks,ids:k.books,transport:o,onNavigate:r,renderLink:i}),(k==null?void 0:k.contained_works)&&k.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(ne,{children:[a.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",k.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:k.contained_works.map(S=>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:S.id,label:u(S.title),onNavigate:r,renderLink:i})},S.id))})]}),(w==null?void 0:w.books)&&w.books.length>0&&e.jsx(ur,{ids:w.books,transport:o,onNavigate:r,renderLink:i}),(w==null?void 0:w.related_works)&&w.related_works.length>0&&(()=>{const S=[],L=w.related_works.filter(F=>F.relation==="part_of"),K=w.related_works.filter(F=>F.relation==="has_part"),V=w.related_works.filter(F=>!F.relation);return L.length>0&&S.push({label:a.section.belongsToWork,items:L}),K.length>0&&S.push({label:a.section.containedWorks,items:K}),V.length>0&&S.push({label:a.section.relatedWorks,items:V}),S.map(F=>e.jsxs("div",{children:[e.jsxs(ne,{children:[F.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",F.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:F.items.map(le=>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:le.id,label:u(le.title),onNavigate:r,renderLink:i})},le.id))})]},F.label))})()]})};function hr({data:t}){const n=A(),{convert:o}=D(),{stats:r}=t,i=r.processed_volumes??r.total_found_volumes,l=i!=null&&t.total_volumes>0?Math.round(i/t.total_volumes*100):null;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:o(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:o(t.resource_name)}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsxs("span",{children:[n.catalog.totalVolumes," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:t.total_volumes})," ",n.unit.volume]}),l!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:i})," ",n.unit.volume," (",l,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"#e67e22"},children:r.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function br({sections:t,activeSection:n,onSelect:o}){const r=A();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>o(null),style:st(n===null),children:r.catalog.all}),t.map(i=>e.jsxs("button",{onClick:()=>o(i.name),style:st(n===i.name),children:[i.name,i.volume_range&&e.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[i.volume_range[0],"–",i.volume_range[1]]})]},i.name))]})}function st(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 mr({id:t,label:n,onNavigate:o,renderLink:r}){const i=re();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:i(t),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),o(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px",fontSize:"12px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function yr(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const o=t[0],r=t[t.length-1];return r-o+1===t.length?`${o}–${r}`:t.length<=3?t.join(", "):`${o}–${r} (${t.length}${n})`}function at({book:t,onNavigate:n,renderLink:o,showVolumes:r}){const i=A(),{convert:l}=D(),s=t.book_id||t.work_id,c=r&&t.volumes.length>0?yr(t.volumes,i.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:[l(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(u=>l(u)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:l(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:a?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,i.unit.volume]}),s&&e.jsx(mr,{id:s,label:t.book_id?i.indexType.book:i.indexType.work,onNavigate:n,renderLink:o}),!s&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:i.catalog.unmatched_label})]})}const Dt=({data:t,collectionId:n,transport:o,onNavigate:r,renderLink:i,className:l,style:s})=>{const c=A(),[a,u]=f.useState(null),[d,p]=f.useState(!1),[h,x]=f.useState(null),[y,j]=f.useState(null),[g,I]=f.useState(""),m=t||a;f.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollectionCatalog))return;let w=!1;return p(!0),x(null),o.getCollectionCatalog(n).then(C=>{w||(C?u(C):x(c.catalog.notFound))}).catch(C=>{w||x(C instanceof Error?C.message:c.catalog.loadFailed)}).finally(()=>{w||p(!1)}),()=>{w=!0}},[t,n,o,c]);const v=(m==null?void 0:m.sections)&&m.sections.length>0,b=f.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const w=m.books.map(B=>B.volumes[0]).filter(B=>B!=null);return new Set(w).size<w.length},[m]),z=f.useMemo(()=>{if(!m)return[];let w=m.books;if(y&&(w=w.filter(C=>C.section===y)),g.trim()){const C=g.trim().toLowerCase();w=w.filter(B=>B.title.toLowerCase().includes(C)||B.sub_items&&B.sub_items.some(R=>R.toLowerCase().includes(C))||B.edition&&B.edition.toLowerCase().includes(C))}return w},[m,y,g]),k=f.useMemo(()=>{if(!b)return null;const w=[],C=new Map;for(const R of z){if(!R.volumes||R.volumes.length===0)continue;const E=R.volumes[0];C.has(E)||C.set(E,[]),C.get(E).push(R)}const B=[...C.keys()].sort((R,E)=>R-E);for(const R of B)w.push({volume:R,books:C.get(R)});return w},[z,b]);return d?e.jsx("div",{className:l,style:{...s,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.catalog.loading})}):h?e.jsx("div",{className:l,style:{...s,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h}):m?e.jsxs("div",{className:l,style:s,children:[e.jsx(hr,{data:m}),v&&e.jsx(br,{sections:m.sections,activeSection:y,onSelect:j}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:c.search.searchBookName,value:g,onChange:w=>I(w.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:[z.length," ",c.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[k?k.map((w,C)=>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:Ie(c.catalog.volume,{n:w.volume})}),w.books.map((B,R)=>e.jsx(at,{book:B,onNavigate:r,renderLink:i,showVolumes:B.volumes.length>1},`${w.volume}-${R}`))]},`${w.volume}-${C}`)):z.map((w,C)=>e.jsx(at,{book:w,onNavigate:r,renderLink:i,showVolumes:!0},C)),z.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:c.catalog.noMatch})]})]}):null},Ht={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},vr={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},jr={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},ge=()=>{const[t,n]=f.useState(1);return f.useEffect(()=>{const o=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(o)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(t)})},X=6,Re=7,Sr=({content:t,children:n,placement:o="top",delayMs:r=100,maxWidth:i=280,wrapperStyle:l})=>{const[s,c]=f.useState(!1),[a,u]=f.useState(null),d=f.useRef(null),p=f.useRef(null),h=f.useRef(null),x=f.useCallback(()=>{const g=p.current,I=h.current;if(!g||!I)return;const m=g.getBoundingClientRect(),v=I.getBoundingClientRect(),b=window.innerHeight,z=document.documentElement.clientWidth;let k=o;o==="top"&&m.top-v.height-Re<8&&(k="bottom"),o==="bottom"&&m.bottom+v.height+Re>b-8&&(k="top");const w=k==="top"?m.top-v.height-Re:m.bottom+Re;let C=m.left+m.width/2-v.width/2;C=Math.max(8,Math.min(C,z-v.width-8)),u({left:C,top:w,placement:k})},[o]),y=f.useCallback(()=>{d.current&&clearTimeout(d.current),d.current=setTimeout(()=>c(!0),r)},[r]),j=f.useCallback(()=>{d.current&&clearTimeout(d.current),c(!1),u(null)},[]);return f.useEffect(()=>{if(!s)return;const g=requestAnimationFrame(x);return()=>cancelAnimationFrame(g)},[s,x]),f.useEffect(()=>()=>{d.current&&clearTimeout(d.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:p,onMouseEnter:y,onMouseLeave:j,onFocus:y,onBlur:j,style:{display:"inline-block",...l},children:n}),s&&bn.createPortal(e.jsxs("div",{ref:h,role:"tooltip",style:{position:"fixed",left:(a==null?void 0:a.left)??-9999,top:(a==null?void 0:a.top)??-9999,maxWidth:i,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:-X,width:0,height:0,...a.placement==="top"?{bottom:-X,borderTop:`${X}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${X}px solid transparent`,borderRight:`${X}px solid transparent`}:{top:-X,borderBottom:`${X}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${X}px solid transparent`,borderRight:`${X}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...a.placement==="top"?{bottom:-5,borderTop:`${X-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${X-1}px solid transparent`,borderRight:`${X-1}px solid transparent`}:{top:-5,borderBottom:`${X-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${X-1}px solid transparent`,borderRight:`${X-1}px solid transparent`}}})]})]}),document.body)]})},ct={A:"fine",B:"rough",C:"rough",D:"ocr"};function kr(t){return typeof t!="string"?null:t in Ht?t:t in ct?ct[t]:null}const wr=["〇","一","二","三","四","五","六","七","八","九"],dt=["","十","百","千"],Cr=["","萬","億"];function Ot(t){if(t===0)return"〇";if(t<0)return`負${Ot(-t)}`;const n=[];let o=t,r=0;for(;o>0;){const i=o%1e4;i>0?n.unshift(_r(i,r>0)+Cr[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function _r(t,n){const o=[];let r=t;for(;r>0;)o.unshift(r%10),r=Math.floor(r/10);let i="";for(let l=0;l<o.length;l++){const s=o[l],c=o.length-1-l;s===0?i&&!i.endsWith("〇")&&(i+="〇"):s===1&&c===1&&l===0&&!n?i+=dt[c]:i+=wr[s]+dt[c]}return i.replace(/〇$/,"")}const qe={类:"#8e6f3e",书:"#c0392b",序:"#1a5276",结语:"#7d6608"},zr={考证:"#5d6d7e"};function Ir(t){const n=t.replace(".json","");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function Ut({file:t,isActive:n,onSelect:o,meta:r}){return e.jsxs("button",{onClick:()=>o(t),style:{padding:"3px 8px",border:n?"1px solid var(--bim-primary, #8e6f3e)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":"transparent",color:n?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4},children:[Ir(t),(r==null?void 0:r.vol_label)&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",r.vol_label,"冊)"]})]})}function Vt(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(r=>Vt(r,n)))}function Kt(t){var r;const n=t.files.length,o=((r=t.children)==null?void 0:r.reduce((i,l)=>i+Kt(l),0))||0;return n+o}function Nt({group:t,activeFile:n,onSelect:o,depth:r=0,juanMeta:i}){var d;const l=Vt(t,n||""),[s,c]=f.useState(l),a=Kt(t),u=!!((d=t.children)!=null&&d.length);if(f.useEffect(()=>{l&&c(!0)},[l]),t.files.length===1&&!u){const p=t.files[0],h=n===p;return e.jsx("button",{onClick:()=>o(p),style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:h?"1px solid var(--bim-primary, #8e6f3e)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:h?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":"transparent",color:h?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"12px",fontWeight:h?600:400,lineHeight:1.4},children:t.label})}return e.jsxs("div",{style:{marginBottom:r===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>c(!s),style:{display:"flex",alignItems:"center",gap:"6px",padding:r===0?"4px 8px":"2px 8px",paddingLeft:`${8+r*16}px`,cursor:"pointer",userSelect:"none",fontSize:r===0?"13px":"12px",fontWeight:r===0?600:500,color:l?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)"},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:s?"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:["(",a,")"]})]}),s&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",padding:`4px 0 4px ${24+r*16}px`},children:t.files.map(p=>e.jsx(Ut,{file:p,isActive:n===p,onSelect:o,meta:i==null?void 0:i[p]},p))}),u&&t.children.map((p,h)=>e.jsx(Nt,{group:p,activeFile:n,onSelect:o,depth:r+1,juanMeta:i},h))]})]})}function Tr({files:t,groups:n,activeFile:o,onSelect:r,juanMeta:i}){const l=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((s,c)=>e.jsx(Nt,{group:s,activeFile:o,onSelect:r,juanMeta:i},c))}):l.length===0?null:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:l.map(s=>e.jsx(Ut,{file:s,isActive:o===s,onSelect:r,meta:i==null?void 0:i[s]},s))})}function Rr({type:t}){const n=qe[t]||"#717171";return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:n,border:`1px solid ${n}40`,borderRadius:"2px",background:`${n}08`,flexShrink:0},children:t})}function Lr({section:t,onNavigate:n}){const{convert:o}=D(),r=re(),[i,l]=f.useState(!1),s=!!t.summary,c=!!t.comment,a=!!t.additional_comment,u=!!(t.content&&t.content.length>60),d=s||c||a||u,p=!i&&u?t.content.replace(/\n/g," ").slice(0,80)+"…":null;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>d&&l(!i),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:d?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[d&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:i?"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?`《${o(t.book_title)}》`:o(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[Ot(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:o(t.author_info||t.author)})]}),!i&&p&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:o(p)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:o(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"#e74c3c"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:r(t.work_id),onClick:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),h.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),i&&d&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:o(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:o(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:o(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:o(t.additional_comment)})]}),u&&!s&&!c&&!a&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:o(t.content)})]})]})}function Er({section:t}){const{convert:n}=D(),[o,r]=f.useState(!1),i=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>i&&r(!o),style:{display:"flex",alignItems:"center",gap:"8px",cursor:i?"pointer":"default",userSelect:"none"},children:[e.jsx(Rr,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:n(t.title)}),i&&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&&i&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${qe[t.type]||"#717171"}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:n(t.content)})})]})}function Br({section:t}){const{convert:n}=D();if(!t.content&&!t.title)return null;const o=n((t.content||t.title||"").replace(/\n{2,}/g,`
1
+ "use strict";var dn=Object.create;var Je=Object.defineProperty;var pn=Object.getOwnPropertyDescriptor;var xn=Object.getOwnPropertyNames;var un=Object.getPrototypeOf,fn=Object.prototype.hasOwnProperty;var gn=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of xn(n))!fn.call(t,i)&&i!==o&&Je(t,i,{get:()=>n[i],enumerable:!(r=pn(n,i))||r.enumerable});return t};var hn=(t,n,o)=>(o=t!=null?dn(un(t)):{},gn(n||!t||!t.__esModule?Je(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("./storage-entry-2AJlDQPr.cjs"),e=require("react/jsx-runtime"),f=require("react"),bn=require("react-dom"),mn=t=>`/book-index?id=${t}`,zt=f.createContext(mn);function yn({buildUrl:t,children:n}){const o=f.useMemo(()=>t,[t]);return e.jsx(zt.Provider,{value:o,children:n})}function re(){return f.useContext(zt)}const ze=f.createContext(null),It={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"實體資源"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"實體"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入",belongsToWork:"所屬作品",locationHistory:"流轉���史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"叢書目錄",siteTab:"在線資源",recommendTab:"推薦",feedbackTab:"反饋",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},detailTab:{basicInfo:"基本信息",catalog:"目錄",collectionCatalog:"叢編目錄",collatedEdition:"整理本",catalogSuffix:"·目錄"},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",total_pages:"總頁數",page_range:"頁碼範圍",page_count:"頁數",file_page_range:"文件頁碼",file_page_count:"文件頁數",content_page_range:"影印頁碼",volume:"冊",color_mode:"色彩",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},vn={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"实体资源"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"实体"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"丛书目录",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"基本信息",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"整理本",catalogSuffix:"·目录"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},jn={"zh-Hant":It,"zh-Hans":vn},Tt="bim-locale";function Sn(){try{const t=localStorage.getItem(Tt);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function kn(t){try{localStorage.setItem(Tt,t)}catch{}}const wn="zh-Hant",Cn=({locale:t,onLocaleChange:n,children:o})=>{const[r,i]=f.useState(t??wn),l=t??r;f.useEffect(()=>{if(t)return;const d=Sn();d&&d!==r&&i(d)},[]);const[s,c]=f.useState(null);f.useEffect(()=>{l==="zh-Hans"?import("opencc-js/t2cn").then(d=>{const p=d.Converter({from:"tw",to:"cn"});c(()=>p)}).catch(()=>{c(()=>d=>d)}):c(null)},[l]);const a=f.useCallback(d=>{i(d),kn(d),n==null||n(d)},[n]),u=f.useMemo(()=>({locale:l,setLocale:a,messages:jn[l],converter:s}),[l,a,s]);return e.jsx(ze.Provider,{value:u,children:o})};function A(){const t=f.useContext(ze);return(t==null?void 0:t.messages)??It}const _n=2e3;function D(){const t=f.useContext(ze),n=(t==null?void 0:t.locale)??"zh-Hant",o=(t==null?void 0:t.converter)??null,r=f.useRef(new Map),i=f.useRef(n);i.current!==n&&(r.current.clear(),i.current=n);const l=f.useCallback(s=>{if(!s)return"";if(!o)return s;const c=r.current.get(s);if(c!==void 0)return c;const a=o(s);if(r.current.size>=_n){const u=r.current.keys().next().value;u!==void 0&&r.current.delete(u)}return r.current.set(s,a),a},[o]);return f.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Ie(t,n){return t.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function zn(t){if(!t)return"";try{const n=new URL(t).hostname,o={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(o[n])return o[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function In(){return{id:"",name:"",url:"",type:"text",details:""}}const Ue=({items:t,onChange:n,onDownload:o,downloadStatuses:r,filterType:i})=>{const l=A(),[s,c]=f.useState(null),a=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],u=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],d=m=>i?i==="text"?m==="text"||m==="text+image":i==="image"?m==="image"||m==="text+image"||m==="physical":m===i:!0,p=t.map((m,v)=>({item:m,originalIndex:v})).filter(({item:m})=>d(m.type)),h=()=>{const m=In();i&&(m.type=i),n([...t,m]),c(t.length)},x=m=>{n(t.filter((v,b)=>b!==m)),c(null)},y=(m,v,b)=>{const z=[...t];if(z[m]={...z[m],[v]:b},v==="url"&&!z[m].id){const k=zn(b);k&&(z[m].id=k)}n(z)},j=(m,v,b)=>{const k={...t[m].metadata||{}};b?k[v]=b:delete k[v],y(m,"metadata",Object.keys(k).length>0?k:void 0)},g=(m,v)=>{const b=v.trim()?v.split(/[,,、]/).map(z=>z.trim()).filter(Boolean):void 0;y(m,"structure",b)},I=(m,v,b)=>{const k=t[m].coverage||{level:1,ranges:""};v==="level"?k.level=parseInt(b)||1:k.ranges=b,y(m,"coverage",k.ranges?k:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[p.map(({item:m,originalIndex:v})=>{var b,z,k,w;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>c(s===v?null:v),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===v?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Tn(m.type),color:"#fff"},children:((b=a.find(C=>C.value===m.type))==null?void 0:b.label)||m.type}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.name||`${l.editor.resourcePlaceholder} ${v+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:"🔗"}),o&&m.url&&Rn(v,r==null?void 0:r[v],o,l),e.jsx("button",{onClick:C=>{C.stopPropagation(),x(v)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),s===v&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(m.type==="image"||m.type==="text+image")&&m.url&&Ln(m,l),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:je,children:[e.jsx("span",{style:Se,children:l.label.type}),e.jsx("select",{value:m.type,onChange:C=>y(v,"type",C.target.value),style:{...ae,flex:1},children:a.map(C=>e.jsx("option",{value:C.value,children:C.label},C.value))})]}),e.jsxs("label",{style:je,children:[e.jsx("span",{style:Se,children:l.label.rootType}),e.jsx("select",{value:m.root_type||"catalog",onChange:C=>y(v,"root_type",C.target.value),style:{...ae,flex:1},children:u.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=>y(v,"id",C.target.value),placeholder:l.editor.idAutoExtract,style:{...ae,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:m.name,onChange:C=>y(v,"name",C.target.value),placeholder:l.editor.resourceName,style:{...ae,flex:1}})]}),e.jsx("input",{type:"text",value:m.url,onChange:C=>y(v,"url",C.target.value),placeholder:l.editor.resourceUrl,style:ae}),e.jsx("input",{type:"text",value:((z=m.structure)==null?void 0:z.join("、"))||"",onChange:C=>g(v,C.target.value),placeholder:l.editor.structurePlaceholder,style:ae}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:je,children:[e.jsx("span",{style:Se,children:l.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((k=m.coverage)==null?void 0:k.level)??"",onChange:C=>I(v,"level",C.target.value),placeholder:"1",style:{...ae,width:"60px"}})]}),e.jsxs("label",{style:{...je,flex:1},children:[e.jsx("span",{style:Se,children:l.label.coverageRange}),e.jsx("input",{type:"text",value:((w=m.coverage)==null?void 0:w.ranges)||"",onChange:C=>I(v,"ranges",C.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...ae,flex:1}})]})]}),e.jsx("textarea",{value:m.details||"",onChange:C=>y(v,"details",C.target.value),placeholder:l.editor.detailsPlaceholder,style:{...ae,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:l.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(l.metadata).map(([C,B])=>{var R;return e.jsxs("label",{style:{...je,gap:"4px"},children:[e.jsx("span",{style:{...Se,minWidth:"56px"},children:B}),e.jsx("input",{type:"text",value:((R=m.metadata)==null?void 0:R[C])||"",onChange:E=>j(v,C,E.target.value),placeholder:B,style:{...ae,flex:1}})]},C)})})]})]})]})]},v)}),e.jsxs("button",{onClick:h,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:l.action.addResource})]})]})};function Tn(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function Rn(t,n,o,r){const i=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:s=>{s.stopPropagation(),i||o(t,"")},disabled:i,style:{background:"transparent",border:"none",color:l?"var(--bim-success, #4caf50)":i?"var(--bim-desc-fg, #717171)":"var(--bim-link-fg, #0066cc)",cursor:i?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:i?.6:.9},title:l?r.download.completed:i?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:l?"✓":i?"⏳":"⬇"})}function Ln(t,n){const o=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url)||t.url.includes("iiif")||t.url.includes("image");return e.jsx("div",{style:{marginBottom:"12px"},children:o?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"#00000010"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"#00000010",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const ae={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"},je={display:"flex",alignItems:"center",gap:"6px"},Se={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},En={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function Bn(t){try{const n=new URL(t).hostname;return En[n]}catch{return}}const Ze={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"},Wn=["text","image","text+image","physical"];function $n(t){const n=l=>{const s=l.match(/^(.+?)·第(\d+)[冊册]$/);if(s)return[s[1],parseInt(s[2])];const c=l.match(/^(.+?)[·(](\d+)[)]?$/);return c?[c[1],parseInt(c[2])]:null},o=new Map,r=[],i=new Set;for(let l=0;l<t.length;l++){const s=t[l];if(s.volumes&&s.volumes.length>0)continue;const c=n(s.name);if(!c)continue;const[a,u]=c,d=`${a}|${s.type}`;o.has(d)||o.set(d,{base:{...s,name:a,url:"",volumes:[]},volumes:[]}),o.get(d).volumes.push({volume:u,url:s.url||void 0,status:"found"}),i.add(l)}for(const[,l]of o)if(l.volumes.length>=2)l.volumes.sort((s,c)=>s.volume-c.volume),l.base.volumes=l.volumes,l.base.expected_volumes=l.volumes.length,r.push(l.base);else for(let s=0;s<t.length;s++)if(i.has(s)){const c=n(t[s].name);c&&`${c[0]}|${t[s].type}`==`${l.base.name}|${l.base.type}`&&i.delete(s)}for(let l=0;l<t.length;l++)i.has(l)||r.push(t[l]);return r}const Ye=({items:t,groupByType:n=!0,onNavigate:o,renderLink:r})=>{const i=A(),l=f.useMemo(()=>$n(t||[]),[t]),s={text:i.resourceType.text,image:i.resourceType.image,"text+image":i.resourceType.textImage,physical:i.resourceType.physical};if(!l||l.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:i.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:l.map((a,u)=>e.jsx(Qe,{item:a},a.id||u))});const c=Wn.map(a=>({type:a,items:l.filter(u=>u.type===a)})).filter(a=>a.items.length>0);return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:c.map(({type:a,items:u})=>e.jsxs("div",{children:[e.jsxs("h4",{style:{margin:"0 0 8px",fontSize:"13px",fontWeight:600,color:Ze[a],display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx("span",{style:{display:"inline-block",width:"4px",height:"14px",borderRadius:"2px",background:Ze[a]}}),s[a],e.jsxs("span",{style:{fontWeight:400,opacity:.6},children:["(",u.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:u.map((d,p)=>e.jsx(Qe,{item:d,onNavigate:o,renderLink:r},d.id||p))})]},a))})},Xe=t=>{const n=t.volumes&&t.volumes.length>0;return t.details&&!n||t.structure||t.coverage||t.metadata&&Object.keys(t.metadata).length>0},Rt=({value:t})=>{const o=A().checkType[t];return o?e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:o.bg,color:o.fg},children:o.label}):e.jsx("span",{children:t})},An=(t,n,o,r)=>{if(t==="check_type"&&typeof n=="string")return e.jsx(Rt,{value:n});if(t==="has_translation")return n?o.misc.hasTranslation:o.misc.noTranslation;const i=String(n);return r?r(i):i};function Pn(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const i=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(i)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(i[1]))}&page=${n}`;const l=new URL(t);return l.searchParams.set("page",String(n)),l.toString()}return t}catch{return t}}function Fn(t){if(!t)return;const n=t.file_page_range||t.page_range;if(!n||typeof n!="string")return;const o=n.match(/^(\d+)/);return o?parseInt(o[1],10):void 0}function Mn(t){if(t.url)return t.url;for(const[n,o]of Object.entries(t))if(n.endsWith("_url")&&typeof o=="string")return o}const Dn={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},Qe=({item:t,onNavigate:n,renderLink:o})=>{var j;const r=A(),{convert:i}=D(),l=re(),[s,c]=f.useState(!1),a=f.useMemo(()=>(t.url?Bn(t.url):void 0)||i(t.name),[t.url,t.name,i]),u=f.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(g=>({...g,url:g.url||Mn(g)})),[t.volumes]),d=u&&u.length>0,p=d?new Set(u.filter(g=>g.status!=="missing").map(g=>g.volume)).size:0,h=d?new Set(u.filter(g=>g.status==="missing").map(g=>g.volume)).size:0,x=t.expected_volumes??(d?p+h:0),y=t.color_mode?{...Dn[t.color_mode],label:r.colorMode[t.color_mode]}:null;return e.jsxs("div",{style:{padding:"10px 14px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:Xe(t)||d?"6px":"0"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:a}),y&&e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:y.bg,color:y.fg},children:y.label}),t.source_label&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",fontStyle:"italic"},children:t.source_label}),((j=t.metadata)==null?void 0:j.check_type)&&e.jsx(Rt,{value:t.metadata.check_type}),d&&e.jsxs("span",{style:{padding:"1px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:"transparent",color:"var(--bim-desc-fg, #717171)"},children:[p,"/",x,r.unit.volume,h>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"4px"},children:["缺",h]})]}),t.url&&e.jsx("a",{href:(()=>{const g=Fn(t.metadata);return g?Pn(t.url,g):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:r.action.visit}),d&&e.jsx("button",{onClick:()=>c(!s),title:s?"收起分册":"展开分册",style:{marginLeft:"auto",padding:"1px 10px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:s?"var(--bim-widget-border, #e0e0e0)":"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",lineHeight:1.4},children:s?"收起 ▲":"展开 ▼"})]}),Xe(t)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"12px",flexWrap:"wrap"},children:[t.metadata&&Object.entries(t.metadata).filter(([g])=>g!=="check_type").map(([g,I])=>e.jsxs("span",{children:[r.metadata[g]||g,": ",An(g,I,r,i)]},g)),t.details&&!d&&e.jsx("span",{children:i(t.details)}),t.structure&&e.jsxs("span",{children:[r.misc.structure,": ",t.structure.join(" → ")]}),t.coverage&&e.jsxs("span",{children:[r.misc.coverage,": L",t.coverage.level," ",t.coverage.ranges]})]}),d&&s&&(()=>{const g=u.some(v=>v.group),I=[];if(g){let v=null;for(const b of u){const z=b.group||"";(!v||v.title!==z)&&(v={title:z,group_id:b.group_id,vols:[]},I.push(v)),v.vols.push(b)}}else I.push({vols:u});const m=v=>{const b=v.status==="missing";return v.url&&!b?e.jsx("a",{href:v.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",lineHeight:1.4},title:v.label||`${v.volume}`,children:v.volume},v.volume):e.jsx("span",{style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid transparent",color:b?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:b?"line-through":"none",opacity:b?.6:1,lineHeight:1.4},children:v.volume},v.volume)};return e.jsx("div",{style:{marginTop:"8px",padding:"8px 0",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",display:"flex",flexDirection:"column",gap:"8px"},children:I.map((v,b)=>{const z=v.title?i(v.title):"";let k=z;return v.title&&v.group_id&&(o?k=o(v.group_id,z):n&&(k=e.jsx("a",{href:l(v.group_id),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),n(v.group_id))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:w=>w.currentTarget.style.borderBottomStyle="solid",onMouseLeave:w=>w.currentTarget.style.borderBottomStyle="dashed",children:z}))),e.jsxs("div",{children:[v.title&&e.jsxs("div",{style:{fontSize:"12px",fontWeight:500,color:"var(--bim-fg, #333)",marginBottom:"4px"},children:[k,e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",v.vols.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px"},children:v.vols.map(m)})]},b)})})})()]})},Lt=({indexSource:t,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:i,onConfigurePath:l,onSelectFolder:s})=>{const c=A(),a=t==="local",u=(n==null?void 0:n.isDraft)??!0,d=(n==null?void 0:n.repoPath)||"",p=d?d.split(/[/\\]/).pop()||d:"",h={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:"var(--bim-primary-soft, #0078d415)",color:"var(--bim-primary, #0078d4)"},x={onMouseOver:j=>j.currentTarget.style.opacity="0.8",onMouseOut:j=>j.currentTarget.style.opacity="1"},y=e.jsxs("div",{onClick:i,title:u?c.mode.switchToOfficial:c.mode.switchToDraft,style:{...h,background:u?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...x,children:[e.jsx("span",{children:u?"📝":"📚"}),e.jsx("span",{children:u?"draft":"official"})]});return o==="index-browser"?a?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[y,e.jsxs("div",{onClick:r,title:c.mode.switchToSync,style:h,...x,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:c.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:s,title:d||c.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px"},...x,children:[e.jsx("span",{children:"📂"}),p&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:p})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[y,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:r,title:c.mode.switchToLocal,style:h,...x,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:c.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:l,title:p||c.mode.configurePath,style:{...h,background:"transparent",padding:"6px",fontSize:"12px"},...x,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:r,title:a?c.mode.switchToGithub:c.mode.switchToLocal,style:h,...x,children:[e.jsx("span",{children:a?"📁":"🌐"}),e.jsx("span",{children:a?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&e.jsxs("div",{onClick:s,title:d||c.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px",minWidth:d?"100px":"auto",justifyContent:"space-between"},...x,children:[e.jsx("span",{children:"📂"}),p&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:p})]}),!a&&p&&e.jsxs("div",{style:{...h,background:"#2196f3",color:"white",cursor:"default"},title:d,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:p})]})]})},$e="bim-search-history",et=10,tt=8;function we(){try{const t=localStorage.getItem($e);return t?JSON.parse(t):[]}catch{return[]}}function Hn(t){try{const n=we().filter(o=>o!==t);n.unshift(t),n.length>et&&(n.length=et),localStorage.setItem($e,JSON.stringify(n))}catch{}}function On(t){try{const n=we().filter(o=>o!==t);localStorage.setItem($e,JSON.stringify(n))}catch{}}function Un(){try{localStorage.removeItem($e)}catch{}}const Et=({transport:t,value:n,onChange:o,onSearch:r,onEntrySelect:i,placeholder:l})=>{const s=A(),c=l??s.search.placeholder,a={work:s.indexType.work,book:s.indexType.book,collection:s.indexType.collection,entity:s.indexType.entity},[u,d]=f.useState(!1),[p,h]=f.useState([]),[x,y]=f.useState(-1),[j,g]=f.useState(null),[I,m]=f.useState(we),v=f.useRef(null),b=f.useRef(null),z=f.useRef(null);f.useEffect(()=>{if(!t.getAllEntries)return;let _=!1;return t.getAllEntries().then($=>{_||g($)}).catch(()=>{}),()=>{_=!0}},[t]);const k=f.useCallback(_=>{if(!_.trim())return I.map(S=>({type:"history",text:S}));if(!j)return[];const $=_.toLowerCase(),W=[],U=[];for(const S of j){if(W.length+U.length>=tt*2)break;const L=(S.title??"").toLowerCase();if(L.startsWith($))W.push({type:"entry",text:S.title,entry:S});else if(L.includes($))U.push({type:"entry",text:S.title,entry:S});else{const K=[...S.additional_titles||[],...S.attached_texts||[]];for(const V of K){const F=typeof V=="string"?V:V==null?void 0:V.book_title;if(F!=null&&F.toLowerCase().includes($)){W.push({type:"entry",text:`${S.title}`,entry:S});break}}}}return[...W,...U].slice(0,tt)},[j,I]);f.useEffect(()=>{h(k(n)),y(-1)},[n,k]),f.useEffect(()=>{const _=$=>{z.current&&!z.current.contains($.target)&&d(!1)};return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[]),f.useEffect(()=>{const _=$=>{var W,U;if($.key==="/"&&document.activeElement!==v.current){const S=(W=document.activeElement)==null?void 0:W.tagName;if(S==="INPUT"||S==="TEXTAREA"||S==="SELECT")return;$.preventDefault(),(U=v.current)==null||U.focus()}};return document.addEventListener("keydown",_),()=>document.removeEventListener("keydown",_)},[]);const w=f.useCallback(_=>{_.trim()&&(Hn(_.trim()),m(we())),r(_),d(!1)},[r]),C=f.useCallback(_=>{_.type==="history"?(o(_.text),w(_.text)):_.entry&&(i?(i(_.entry),d(!1)):(o(_.text),w(_.text)))},[o,w,i]),B=f.useCallback(_=>{if(!u||p.length===0){_.key==="Enter"&&w(n);return}switch(_.key){case"ArrowDown":_.preventDefault(),y($=>($+1)%p.length);break;case"ArrowUp":_.preventDefault(),y($=>($-1+p.length)%p.length);break;case"Enter":_.preventDefault(),x>=0&&x<p.length?C(p[x]):w(n);break;case"Escape":_.preventDefault(),d(!1);break}},[u,p,x,n,w,C]),R=f.useCallback((_,$)=>{$.stopPropagation(),On(_),m(we()),h(W=>W.filter(U=>!(U.type==="history"&&U.text===_)))},[]),E=f.useCallback(_=>{_.stopPropagation(),Un(),m([]),h([])},[]);f.useEffect(()=>{if(x>=0&&b.current){const _=b.current.children;_[x]&&_[x].scrollIntoView({block:"nearest"})}},[x]);const H=!n.trim()&&I.length>0;return e.jsxs("div",{ref:z,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:v,type:"text",placeholder:c,value:n,onChange:_=>{o(_.target.value),d(!0)},onFocus:()=>d(!0),onKeyDown:B,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"}}),u&&p.length>0&&e.jsxs("div",{ref:b,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[H&&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:s.search.history}),e.jsx("button",{onClick:E,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:s.search.clearAll})]}),p.map((_,$)=>e.jsxs("div",{onClick:()=>C(_),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:$===x?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:_.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:_.text}),_.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[a[_.entry.type],_.entry.edition&&` · ${_.entry.edition}`,_.entry.author&&` · ${_.entry.author}`]}),_.type==="history"&&e.jsx("button",{onClick:W=>R(_.text,W),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:s.action.remove,children:"×"})]},`${_.type}-${_.text}-${$}`))]})]})},_e="bim-recent-ids",nt="bim-recent-entries",rt=50,De=5,Vn=50,Kn=200;function Ce(){try{const t=localStorage.getItem(_e);if(t)return JSON.parse(t);const n=localStorage.getItem(nt);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(_e,JSON.stringify(o)),localStorage.removeItem(nt),o}return[]}catch{return[]}}function Nn(t){try{const n=Ce().filter(o=>o!==t);n.unshift(t),n.length>rt&&(n.length=rt),localStorage.setItem(_e,JSON.stringify(n))}catch{}}function Yn(t){try{const n=Ce().filter(o=>o!==t);localStorage.setItem(_e,JSON.stringify(n))}catch{}}function Gn(){try{localStorage.removeItem(_e)}catch{}}const qn={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Ve=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:i,onSwitchMode:l,onToggleDraft:s,onConfigurePath:c,onSelectFolder:a,hideModeIndicator:u,initialQuery:d,onQueryChange:p,headerRight:h})=>{const x=A(),y=[{type:"work",icon:"✍️",name:x.indexType.work,key:"works"},{type:"book",icon:"📖",name:x.indexType.book,key:"books"},{type:"collection",icon:"📚",name:x.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:x.indexType.entity,key:"entities"}],[j,g]=f.useState(d??""),[I,m]=f.useState(null),[v,b]=f.useState(null),[z,k]=f.useState(!1),[w,C]=f.useState(null),[B,R]=f.useState(""),[E,H]=f.useState(!d),[_,$]=f.useState(Ce),[W,U]=f.useState([]),[S,L]=f.useState(!1),[K,V]=f.useState(!1),[F,le]=f.useState(null),[Q,de]=f.useState(null),ue=f.useRef(void 0),xe=f.useRef(!1),J=f.useCallback(async(P,Y)=>{if(!P.trim()){H(!0),m(null),b(null);return}H(!1),k(!0),R("");try{if(t.searchAll){const Z=await t.searchAll(P,Y??De);m(Z)}else{const Z=["work","book","collection","entity"],G=await Promise.all(Z.map(te=>t.search(P,te,{page:1,pageSize:Y??De})));m({works:G[0].entries,books:G[1].entries,collections:G[2].entries,entities:G[3].entries,totalWorks:G[0].total,totalBooks:G[1].total,totalCollections:G[2].total,totalEntities:G[3].total})}}catch(Z){R(Z instanceof Error?Z.message:String(Z)),m(null)}finally{k(!1)}},[t]);f.useEffect(()=>{var T,M;let P=!1;const Y=["work","book","collection","entity"],Z=Promise.all(Y.map(q=>t.loadEntries(q,{page:1,pageSize:1}).catch(()=>({total:0})))),G=((T=t.getResourceCounts)==null?void 0:T.call(t).catch(()=>null))??Promise.resolve(null),te=((M=t.getSubtypeStats)==null?void 0:M.call(t).catch(()=>null))??Promise.resolve(null);return Promise.all([Z,G,te]).then(([q,se,he])=>{P||(le({works:q[0].total,books:q[1].total,collections:q[2].total,entities:q[3].total,hasText:se==null?void 0:se.hasText,hasImage:se==null?void 0:se.hasImage}),he&&de(he))}),()=>{P=!0}},[t]),f.useEffect(()=>{xe.current||!(d!=null&&d.trim())||(xe.current=!0,J(d))},[d,J]);const N=f.useCallback(P=>{if(g(P),p==null||p(P),!P.trim()){H(!0),m(null),b(null);return}ue.current&&clearTimeout(ue.current),ue.current=setTimeout(()=>{b(null),J(P)},Kn)},[J,p]),Ae=f.useCallback(P=>{ue.current&&clearTimeout(ue.current),p==null||p(P),J(P)},[J,p]),Pe=f.useCallback(P=>{b(P),J(j,Vn)},[j,J]);f.useEffect(()=>{if(!_.length){U([]);return}let P=!1;return L(!0),Promise.all(_.slice(0,10).map(async Y=>{var Z,G,te;try{if(t.getEntry){const M=await t.getEntry(Y);if(M)return M}const T=await t.getItem(Y);if(T){const M=T.authors;return{id:Y,title:T.title||Y,type:T.type||"work",author:(Z=M==null?void 0:M[0])==null?void 0:Z.name,dynasty:(G=M==null?void 0:M[0])==null?void 0:G.dynasty,role:(te=M==null?void 0:M[0])==null?void 0:te.role,edition:T.edition||void 0}}}catch{}return{id:Y,title:Y,type:"work",notFound:!0}})).then(Y=>{P||(U(Y),L(!1))}),()=>{P=!0}},[_,t]);const ye=P=>{C(P.id),Nn(P.id),$(Ce()),r==null||r(P)},ve=P=>{Yn(P),$(Ce())},Fe=()=>{Gn(),$([])},Te=P=>y.find(Y=>Y.type===P),Me=I&&(I.works.length>0||I.books.length>0||I.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:x.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,!u&&e.jsx(Lt,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:l,onToggleDraft:s,onConfigurePath:c,onSelectFolder:a})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Et,{transport:t,value:j,onChange:N,onSearch:Ae,onEntrySelect:ye}),i&&e.jsx("button",{onClick:()=>i("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:x.action.newEntry})]}),F&&E&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[e.jsx("span",{children:Q?e.jsxs(e.Fragment,{children:[(Q.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Q.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.books.toLocaleString()})," 本"]}),Q.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Q.article.toLocaleString()})," 篇"]}):null,Q.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Q.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[x.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),x.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),x.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.collections.toLocaleString()}),F.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),x.indexType.entity," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.entities.toLocaleString()})]})]})}),F.hasImage!=null&&F.hasText!=null&&e.jsxs("span",{children:[x.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),x.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:z?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:x.search.searching}):B?e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"24px",marginBottom:"8px"},children:"⚠️"}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)"},children:B})]}):E?e.jsx("div",{style:{flex:1},children:S?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:x.search.loading}):W.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{children:x.search.recentBrowse}),e.jsx("button",{onClick:Fe,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:x.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:W.slice(0,K?10:3).map(P=>P.notFound?e.jsx(Jn,{id:P.id,onRemove:ve,t:x},P.id):e.jsx(ot,{entry:P,selected:w===P.id,onClick:ye,getConfig:Te,onRemove:ve},P.id))}),!K&&W.length>3&&e.jsx("button",{onClick:()=>V(!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:x.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:x.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:x.search.searchSubtitle})]})}):Me?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:y.map(({type:P,icon:Y,name:Z,key:G})=>{const te=I[G]??[],T=qn[G],M=I[T]??0;if(te.length===0)return null;const se=!(v===P)&&M>De;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:[Y," ",Z,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[M," ",x.unit.items]})]}),se&&e.jsx("button",{onClick:()=>Pe(P),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:x.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:te.map(he=>e.jsx(ot,{entry:he,selected:w===he.id,onClick:ye,getConfig:Te,query:j},he.id))})]},P)})}):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:Ie(x.search.noResultsFor,{query:j})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:x.search.tryOther})]})})]})},ot=({entry:t,selected:n,onClick:o,getConfig:r,query:i,onRemove:l})=>{const s=A(),{convert:c}=D(),a=[...t.additional_titles||[],...t.attached_texts||[]],u=i&&a.length?a.find(d=>{const p=typeof d=="string"?d:d==null?void 0:d.book_title;return p==null?void 0:p.toLowerCase().includes(i.toLowerCase())}):void 0;return e.jsxs("div",{onClick:()=>o(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:r(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:r(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:c(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:s.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:s.misc.imageResource,children:"🖼️"})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.edition)}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,s.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??"?"]})]}),u&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[s.search.alias,":",c(u)]})]}),l?e.jsx("button",{onClick:d=>{d.stopPropagation(),l(t.id)},title:s.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:"→"})]})},Jn=({id:t,onRemove:n,t:o})=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",opacity:.6},children:[e.jsx("span",{style:{fontSize:"16px"},children:"❓"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",fontFamily:"monospace"},children:t}),e.jsx("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginTop:"2px"},children:o.search.itemNotFound})]}),e.jsx("button",{onClick:()=>n(t),title:o.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function Zn(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 Xn({data:t}){const{convert:n}=D(),{dynasty:o,birth_year:r,death_year:i}=t,l=[];return o&&l.push(`〔${n(o)}〕`),r!==void 0&&i!==void 0?l.push(`${r}—${i}`):r!==void 0?l.push(`${r}—?`):i!==void 0&&l.push(`?—${i}`),l.length===0?null:e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-desc-fg, #717171)",marginLeft:"8px",fontWeight:"normal"},children:l.join(" ")})}function Qn({alt_names:t}){const{convert:n}=D(),o=new Map;for(const l of t){const s=l.type||"別名";o.has(s)||o.set(s,[]),o.get(s).push(l.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],i=[...o.keys()].sort((l,s)=>{const c=r.indexOf(l),a=r.indexOf(s);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:i.map(l=>{const s=o.get(l);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:l}),e.jsx("span",{children:s.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))})]},l)})})}function er({data:t}){const n=t.external_ids;if(!n)return null;const o=[];return n.cbdb_id&&o.push(e.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${n.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",border:"1px solid var(--bim-link-fg, #0066cc)40",borderRadius:"3px",textDecoration:"none",background:"var(--bim-link-fg, #0066cc)08"},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),o.length===0?null:e.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:o})}function tr({works:t,transport:n,onNavigate:o,renderLink:r}){const i=A(),{convert:l}=D(),s=re(),[c,a]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let h=!1;const x=t.map(j=>j.work_id);return(async()=>{const j=new Map;if(n.getEntriesByIds)try{const v=await n.getEntriesByIds(x);let b=!0;for(let z=0;z<x.length;z++){const k=v[z];k!=null&&k.title?j.set(x[z],k.title):k!=null&&k.primary_name?j.set(x[z],k.primary_name):b=!1}if(b)return j}catch{}if(n.getAllEntries)try{const v=await n.getAllEntries(),b=new Map(v.map(k=>[k.id,k.title||k.primary_name||k.id]));let z=!0;for(const k of x){const w=b.get(k);w?j.set(k,w):z=!1}if(z)return j}catch{}const g=[...x],I=8,m=new Array(I).fill(0).map(async()=>{for(;g.length;){const v=g.shift();if(!v)break;if(!j.has(v))try{if(n.getEntry){const k=await n.getEntry(v);if(k!=null&&k.title){j.set(v,k.title);continue}}const b=await n.getItem(v),z=b&&(b.title||b.primary_name)||v;j.set(v,z)}catch{j.set(v,v)}}});return await Promise.all(m),j})().then(j=>{h||a(j)}),()=>{h=!0}},[t,n]);const u=new Map;for(const h of t){const x=h.role||"";u.has(x)||u.set(x,[]),u.get(x).push(h)}const d=["撰","編","注","輯","集","校","評","譯","述","作",""],p=[...u.keys()].sort((h,x)=>{const y=d.indexOf(h),j=d.indexOf(x);return y===-1&&j===-1?h.localeCompare(x):y===-1?1:j===-1?-1:y-j});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:[i.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),p.map(h=>{const x=u.get(h);return e.jsxs("div",{style:{marginBottom:"8px"},children:[h&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginBottom:"2px"},children:[l(h)," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #bbb)"},children:["(",x.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:h?"16px":"0",listStyle:h?"disc":"none",fontSize:"14px",lineHeight:1.8},children:x.map((y,j)=>{const g=l(c.get(y.work_id)||y.work_id);return r?e.jsx("li",{children:r(y.work_id,g)},j):o?e.jsx("li",{children:e.jsx("a",{href:s(y.work_id),onClick:I=>{I.metaKey||I.ctrlKey||(I.preventDefault(),o(y.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:g})},j):e.jsx("li",{children:g},j)})})]},h)})]})}const Bt=({data:t,transport:n,onNavigate:o,renderLink:r,headerExtra:i})=>{var d;const l=A(),{convert:s}=D();let c=!1;try{c=O.extractStatus(t.id)==="draft"}catch{}const a=Zn(t),u=t.subtype==="people"?"人物":t.subtype==="place"?"地名":t.subtype==="dynasty"?"朝代":t.subtype==="anonymous"?"佚名":t.subtype==="collective"?"集体":t.subtype;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:"var(--bim-fg, #222)"},children:[s(t.primary_name),e.jsx(Xn,{data:t})]}),i]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:"#5b3e8e",border:"1px solid #5b3e8e40",borderRadius:"2px",background:"#5b3e8e08"},children:l.indexType.entity}),u&&t.subtype!=="people"&&e.jsx("span",{children:u}),c&&e.jsx("span",{style:{padding:"1px 6px",background:"#fff3cd",border:"1px solid #ffc107",borderRadius:"2px",color:"#856404"},children:l.status.draft}),e.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:t.id})]}),a&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #999)",fontStyle:"italic",padding:"8px 12px",background:"var(--bim-widget-bg, #f8f8f8)",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),t.alt_names&&t.alt_names.length>0&&e.jsx(Qn,{alt_names:t.alt_names}),e.jsx(er,{data:t}),((d=t.description)==null?void 0:d.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:s(t.description.text)}),t.works&&t.works.length>0&&e.jsx(tr,{works:t.works,transport:n,onNavigate:o,renderLink:r})]})},nr=["〇","一","二","三","四","五","六","七","八","九"],it=["","十","百","千"];function Wt(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),o=n.length;let r="",i=!1;for(let l=0;l<o;l++){const s=parseInt(n[l]),c=o-1-l;s===0?i=!0:(i&&r&&(r+="〇"),i=!1,s===1&&c===1&&l===0?r+=it[c]:r+=nr[s]+it[c])}return r}function $t({type:t}){const n=A(),o={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3",entity:"#5b3e8e"};return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:o[t],border:`1px solid ${o[t]}40`,borderRadius:"2px",background:`${o[t]}08`},children:n.indexType[t]})}function rr({isDraft:t}){const n=A();return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t?"#e67e22":"#27ae60",border:`1px solid ${t?"#e67e2240":"#27ae6040"}`,borderRadius:"2px",background:t?"#e67e2208":"#27ae6008"},children:t?n.status.draft:n.status.official})}function or({id:t}){const n=A(),[o,r]=f.useState(!1),i=()=>{navigator.clipboard.writeText(t).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",background:"#f6f6f6",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"2px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:i,title:o?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:o?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=o?"1":"0.5",children:o?"✓":"⧉"})]})}function ne({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 ce({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 At({authors:t,type:n,onNavigate:o,renderLink:r}){const{convert:i}=D();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((l,s)=>{const c=i(l.name),a=l.entity_id?e.jsx(ie,{id:l.entity_id,label:c,onNavigate:o,renderLink:r}):e.jsx("span",{style:{fontWeight:500},children:c});return e.jsxs("span",{children:[s>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),l.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",i(l.dynasty),"〕"]}),a,l.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",i(l.role)]})]},s)})})}function ie({id:t,label:n,onNavigate:o,renderLink:r}){const i=re();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:i(t),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),o(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function ir({id:t,title:n,edition:o,type:r,isDraft:i,authors:l,volumeText:s,meta:c,headerExtra:a,onNavigate:u,renderLink:d}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,o&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:o}),s&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:s})]}),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($t,{type:r}),e.jsx(rr,{isDraft:i}),e.jsx(or,{id:t})]}),((l==null?void 0:l.length)||c.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&e.jsx(At,{authors:l,type:r,onNavigate:u,renderLink:d}),c]})]})}function Pt({items:t,label:n,showMeta:o,onNavigate:r,renderLink:i}){const l=A(),{convert:s}=D();if(!t.length)return null;const[c,a]=f.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((u,d)=>{const p=c===d;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...p?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>a(p?null:d),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:p?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:s(u.source)}),!p&&o&&u.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s(u.title_info)}),u.source_bid&&e.jsx("span",{onClick:h=>h.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(ie,{id:u.source_bid,label:l.action.view,onNavigate:r,renderLink:i})})]}),p&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[o&&(u.title_info||u.author_info||u.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[u.title_info&&e.jsx(ce,{label:l.label.titleInfo,children:s(u.title_info)}),u.author_info&&e.jsx(ce,{label:l.label.authorInfo,children:s(u.author_info)}),u.edition&&e.jsx(ce,{label:l.label.edition,children:s(u.edition)})]}),u.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:l.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:s(u.summary)})]}),u.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:l.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:s(u.comment)})]}),u.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:l.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:s(u.additional_comment)})]})]})]},d)})})]})}function lr({items:t,onNavigate:n,renderLink:o}){const r=A();return e.jsx(Pt,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function Ft({items:t,onNavigate:n,renderLink:o}){const r=A();return e.jsx(Pt,{items:t,label:r.section.emendated,onNavigate:n,renderLink:o})}function Mt({label:t,items:n}){const{convert:o}=D();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,i)=>{const l=typeof r=="string"?r:r.book_title;return e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:o(l)},i)})})]}):null}function sr({items:t}){const n=A();return e.jsx(Mt,{label:n.section.aliases,items:t})}function ar({items:t}){const n=A();return e.jsx(Mt,{label:n.section.attachedTexts,items:t})}function cr({items:t}){const n=A(),{convert:o}=D();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((r,i)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:["《",o(r.book_title),"》",r.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},i))})]}):null}function dr({items:t}){const n=A(),{convert:o}=D();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{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,i)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:"var(--bim-primary, #8e6f3e)",border:"1.5px solid var(--bim-input-bg, #fff)"}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:o(r.name)}),r.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:o(r.description)})]},i))]})]}):null}function pr({items:t}){const n=A(),{convert:o}=D();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((r,i)=>e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:"var(--bim-desc-fg, #ccc)"},children:"·"}),o(r)]},i))})]}):null}function lt({title:t,ids:n,transport:o,onNavigate:r,renderLink:i}){const{convert:l}=D(),[s,c]=f.useState([]);return f.useEffect(()=>{if(!n.length){c([]);return}if(!o){c(n.map(u=>({id:u})));return}let a=!1;return Promise.all(n.map(u=>o.getItem(u).then(d=>({id:u,title:d?d.title:void 0,edition:d?d.edition:void 0,type:d?d.type:void 0})).catch(()=>({id:u})))).then(u=>{a||c(u)}),()=>{a=!0}},[n,o]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(ne,{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:(s.length?s:n.map(a=>({id:a}))).map(a=>{const u=a.edition?`${l(a.title)||a.id}(${l(a.edition)})`:l(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:u,onNavigate:r,renderLink:i})},a.id)})})]}):null}function xr({book:t,onNavigate:n,renderLink:o}){const r=A(),{convert:i}=D(),[l,s]=f.useState(!1),c=t.resources&&t.resources.length>0,a=t.edition?i(t.edition):i(t.title)||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{padding:"10px 14px",borderBottom:c&&!l?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1},children:e.jsx(ie,{id:t.id,label:a,onNavigate:n,renderLink:o})}),c&&e.jsx("span",{onClick:()=>s(u=>!u),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:l?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:l?r.action.expand:r.action.collapse,children:"▼"})]}),c&&!l&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(Ye,{items:t.resources,groupByType:!0,onNavigate:n,renderLink:o})})]})}function ur({ids:t,transport:n,onNavigate:o,renderLink:r}){const i=A(),[l,s]=f.useState([]);return f.useEffect(()=>{if(!t.length){s([]);return}if(!n){s(t.map(a=>({id:a})));return}let c=!1;return Promise.all(t.map(a=>n.getItem(a).then(u=>({id:a,title:u?u.title:void 0,edition:u?u.edition:void 0,resources:u?u.resources:void 0})).catch(()=>({id:a})))).then(a=>{c||s(a)}),()=>{c=!0}},[t,n]),t.length?e.jsxs(e.Fragment,{children:[e.jsxs(ne,{children:[i.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:(l.length?l:t.map(c=>({id:c}))).map(c=>e.jsx(xr,{book:c,onNavigate:o,renderLink:r},c.id))})]}):null}function fr({workData:t,onNavigate:n,renderLink:o}){var l,s,c;const r=A(),{convert:i}=D();return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx($t,{type:"work"}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(ie,{id:t.id,label:i(t.title),onNavigate:n,renderLink:o})}),t.measure_info?e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:i(t.measure_info)}):((l=t.juan_count)==null?void 0:l.number)!=null&&t.juan_count.number>0?e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[Wt(t.juan_count.number),r.unit.juan]}):null]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(At,{authors:t.authors,type:"work",onNavigate:n,renderLink:o}),((s=t.description)==null?void 0:s.text)&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,margin:(c=t.authors)!=null&&c.length?"8px 0 0":"0",textAlign:"justify"},children:i(t.description.text)}),t.parent_work&&e.jsx("div",{style:{marginTop:"8px",fontSize:"13px"},children:e.jsx(ce,{label:r.label.parentWork,children:e.jsx(ie,{id:t.parent_work.id,label:i(t.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function gr({items:t,onNavigate:n,renderLink:o}){const r=A(),{convert:i}=D();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(l=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid #2471a340",borderRadius:"4px",background:"#2471a308"},children:[e.jsx("span",{style:{fontSize:"11px",color:"#2471a3"},children:r.indexType.collection}),e.jsx(ie,{id:l.id,label:i(l.title)||l.id,onNavigate:n,renderLink:o}),l.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:Ie(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const Ge=({data:t,id:n,transport:o,onNavigate:r,renderLink:i,headerExtra:l,className:s,style:c})=>{var E,H,_,$,W,U;const a=A(),{convert:u}=D(),[d,p]=f.useState(null),[h,x]=f.useState(!1),[y,j]=f.useState(null),[g,I]=f.useState(null),[m,v]=f.useState([]),b=t||d;if(f.useEffect(()=>{if(t||!n||!o)return;let S=!1;return x(!0),j(null),o.getItem(n).then(L=>{S||(L?p(L):j(a.misc.notFoundEntry))}).catch(L=>{S||j(L instanceof Error?L.message:a.misc.loadFailed)}).finally(()=>{S||x(!1)}),()=>{S=!0}},[t,n,o]),f.useEffect(()=>{if(!b||!o){I(null),v([]);return}let S=!1;const L=b.type==="book"||b.type==="collection"?b.work_id:void 0;if(L?o.getItem(L).then(K=>{!S&&K&&K.type==="work"&&I(K)}).catch(()=>{}):I(null),b.type==="book"){const K=b;K.contained_in&&K.contained_in.length>0?Promise.all(K.contained_in.map(V=>{const F=typeof V=="string"?V:V.id,le=typeof V=="string"?void 0:V.volume_index;return o.getItem(F).then(Q=>({id:F,title:Q&&Q.title||F,volume_index:le})).catch(()=>({id:F,title:F,volume_index:le}))})).then(V=>{S||v(V)}):v([])}else v([]);return()=>{S=!0}},[b,o]),h)return e.jsx("div",{className:s,style:{...c,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((S,L)=>e.jsx("div",{style:{height:L===1?"32px":"16px",width:`${S}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},L))})});if(y)return e.jsx("div",{className:s,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y});if(!b)return null;if(b.type==="entity")return e.jsx("div",{className:s,style:c,children:e.jsx(Bt,{data:b,transport:o,onNavigate:r,renderLink:i,headerExtra:l})});const z=b.type==="book"?b:null,k=b.type==="collection"?b:null,w=b.type==="work"?b:null;let C=!1;try{C=O.extractStatus(b.id)==="draft"}catch{}let B="";b.measure_info?B=u(b.measure_info):(E=b.juan_count)!=null&&E.number?B=Wt(b.juan_count.number)+a.unit.juan:(H=b.juan_count)!=null&&H.description&&(B=u(b.juan_count.description));const R=[];return(_=b.publication_info)!=null&&_.year&&R.push(e.jsx(ce,{label:a.label.year,children:b.publication_info.year},"year")),($=b.current_location)!=null&&$.name&&R.push(e.jsx(ce,{label:a.label.currentLocation,children:u(b.current_location.name)},"loc")),(W=b.page_count)!=null&&W.description&&R.push(e.jsx(ce,{label:a.label.pageCount,children:b.page_count.description},"page")),z!=null&&z.edition&&R.push(e.jsx(ce,{label:a.label.edition,children:u(z.edition)},"ver")),w!=null&&w.parent_work&&R.push(e.jsx(ce,{label:a.label.parentWork,children:e.jsx(ie,{id:w.parent_work.id,label:u(w.parent_work.title),onNavigate:r,renderLink:i})},"pw")),w!=null&&w.parent_works&&w.parent_works.length>0&&!w.parent_work&&R.push(e.jsx(ce,{label:a.label.parentWork,children:w.parent_works.map((S,L)=>e.jsxs("span",{children:[L>0&&"、",e.jsx(ie,{id:S,onNavigate:r,renderLink:i})]},S))},"pws")),e.jsxs("div",{className:s,style:c,children:[e.jsx(ir,{id:b.id,title:u(b.title),edition:b.edition?u(b.edition):void 0,type:b.type,isDraft:C,authors:b.authors,volumeText:B,meta:R,headerExtra:l,onNavigate:r,renderLink:i}),((U=b.description)==null?void 0:U.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"},children:u(b.description.text)}),m.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:a.section.containedIn}),e.jsx(gr,{items:m,onNavigate:r,renderLink:i})]}),g&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:a.section.belongsToWork}),e.jsx(fr,{workData:g,onNavigate:r,renderLink:i})]}),b.additional_works&&b.additional_works.length>0&&e.jsx(cr,{items:b.additional_works}),b.additional_titles&&b.additional_titles.length>0&&e.jsx(sr,{items:b.additional_titles}),b.attached_texts&&b.attached_texts.length>0&&e.jsx(ar,{items:b.attached_texts}),b.indexed_by&&b.indexed_by.length>0&&e.jsx(lr,{items:b.indexed_by,onNavigate:r,renderLink:i}),b.emendated_by&&b.emendated_by.length>0&&e.jsx(Ft,{items:b.emendated_by,onNavigate:r,renderLink:i}),b.resources&&b.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:a.section.resources}),e.jsx(Ye,{items:b.resources,groupByType:!0,onNavigate:r,renderLink:i})]}),(z==null?void 0:z.location_history)&&z.location_history.length>0&&e.jsx(dr,{items:z.location_history}),(k==null?void 0:k.history)&&k.history.length>0&&e.jsx(pr,{items:k.history}),(z==null?void 0:z.related_books)&&z.related_books.length>0&&e.jsx(lt,{title:a.section.relatedVersions,ids:z.related_books,transport:o,onNavigate:r,renderLink:i}),(k==null?void 0:k.books)&&k.books.length>0&&e.jsx(lt,{title:a.section.containedBooks,ids:k.books,transport:o,onNavigate:r,renderLink:i}),(k==null?void 0:k.contained_works)&&k.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(ne,{children:[a.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",k.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:k.contained_works.map(S=>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:S.id,label:u(S.title),onNavigate:r,renderLink:i})},S.id))})]}),(w==null?void 0:w.books)&&w.books.length>0&&e.jsx(ur,{ids:w.books,transport:o,onNavigate:r,renderLink:i}),(w==null?void 0:w.related_works)&&w.related_works.length>0&&(()=>{const S=[],L=w.related_works.filter(F=>F.relation==="part_of"),K=w.related_works.filter(F=>F.relation==="has_part"),V=w.related_works.filter(F=>!F.relation);return L.length>0&&S.push({label:a.section.belongsToWork,items:L}),K.length>0&&S.push({label:a.section.containedWorks,items:K}),V.length>0&&S.push({label:a.section.relatedWorks,items:V}),S.map(F=>e.jsxs("div",{children:[e.jsxs(ne,{children:[F.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",F.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:F.items.map(le=>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:le.id,label:u(le.title),onNavigate:r,renderLink:i})},le.id))})]},F.label))})()]})};function hr({data:t}){const n=A(),{convert:o}=D(),{stats:r}=t,i=r.processed_volumes??r.total_found_volumes,l=i!=null&&t.total_volumes>0?Math.round(i/t.total_volumes*100):null;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:o(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:o(t.resource_name)}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsxs("span",{children:[n.catalog.totalVolumes," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:t.total_volumes})," ",n.unit.volume]}),l!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:i})," ",n.unit.volume," (",l,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"#e67e22"},children:r.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function br({sections:t,activeSection:n,onSelect:o}){const r=A();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>o(null),style:st(n===null),children:r.catalog.all}),t.map(i=>e.jsxs("button",{onClick:()=>o(i.name),style:st(n===i.name),children:[i.name,i.volume_range&&e.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[i.volume_range[0],"–",i.volume_range[1]]})]},i.name))]})}function st(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 mr({id:t,label:n,onNavigate:o,renderLink:r}){const i=re();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:i(t),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),o(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px",fontSize:"12px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function yr(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const o=t[0],r=t[t.length-1];return r-o+1===t.length?`${o}–${r}`:t.length<=3?t.join(", "):`${o}–${r} (${t.length}${n})`}function at({book:t,onNavigate:n,renderLink:o,showVolumes:r}){const i=A(),{convert:l}=D(),s=t.book_id||t.work_id,c=r&&t.volumes.length>0?yr(t.volumes,i.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:[l(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(u=>l(u)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:l(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:a?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,i.unit.volume]}),s&&e.jsx(mr,{id:s,label:t.book_id?i.indexType.book:i.indexType.work,onNavigate:n,renderLink:o}),!s&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:i.catalog.unmatched_label})]})}const Dt=({data:t,collectionId:n,transport:o,onNavigate:r,renderLink:i,className:l,style:s})=>{const c=A(),[a,u]=f.useState(null),[d,p]=f.useState(!1),[h,x]=f.useState(null),[y,j]=f.useState(null),[g,I]=f.useState(""),m=t||a;f.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollectionCatalog))return;let w=!1;return p(!0),x(null),o.getCollectionCatalog(n).then(C=>{w||(C?u(C):x(c.catalog.notFound))}).catch(C=>{w||x(C instanceof Error?C.message:c.catalog.loadFailed)}).finally(()=>{w||p(!1)}),()=>{w=!0}},[t,n,o,c]);const v=(m==null?void 0:m.sections)&&m.sections.length>0,b=f.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const w=m.books.map(B=>B.volumes[0]).filter(B=>B!=null);return new Set(w).size<w.length},[m]),z=f.useMemo(()=>{if(!m)return[];let w=m.books;if(y&&(w=w.filter(C=>C.section===y)),g.trim()){const C=g.trim().toLowerCase();w=w.filter(B=>B.title.toLowerCase().includes(C)||B.sub_items&&B.sub_items.some(R=>R.toLowerCase().includes(C))||B.edition&&B.edition.toLowerCase().includes(C))}return w},[m,y,g]),k=f.useMemo(()=>{if(!b)return null;const w=[],C=new Map;for(const R of z){if(!R.volumes||R.volumes.length===0)continue;const E=R.volumes[0];C.has(E)||C.set(E,[]),C.get(E).push(R)}const B=[...C.keys()].sort((R,E)=>R-E);for(const R of B)w.push({volume:R,books:C.get(R)});return w},[z,b]);return d?e.jsx("div",{className:l,style:{...s,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.catalog.loading})}):h?e.jsx("div",{className:l,style:{...s,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h}):m?e.jsxs("div",{className:l,style:s,children:[e.jsx(hr,{data:m}),v&&e.jsx(br,{sections:m.sections,activeSection:y,onSelect:j}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:c.search.searchBookName,value:g,onChange:w=>I(w.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:[z.length," ",c.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[k?k.map((w,C)=>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:Ie(c.catalog.volume,{n:w.volume})}),w.books.map((B,R)=>e.jsx(at,{book:B,onNavigate:r,renderLink:i,showVolumes:B.volumes.length>1},`${w.volume}-${R}`))]},`${w.volume}-${C}`)):z.map((w,C)=>e.jsx(at,{book:w,onNavigate:r,renderLink:i,showVolumes:!0},C)),z.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:c.catalog.noMatch})]})]}):null},Ht={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},vr={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},jr={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},ge=()=>{const[t,n]=f.useState(1);return f.useEffect(()=>{const o=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(o)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(t)})},X=6,Re=7,Sr=({content:t,children:n,placement:o="top",delayMs:r=100,maxWidth:i=280,wrapperStyle:l})=>{const[s,c]=f.useState(!1),[a,u]=f.useState(null),d=f.useRef(null),p=f.useRef(null),h=f.useRef(null),x=f.useCallback(()=>{const g=p.current,I=h.current;if(!g||!I)return;const m=g.getBoundingClientRect(),v=I.getBoundingClientRect(),b=window.innerHeight,z=document.documentElement.clientWidth;let k=o;o==="top"&&m.top-v.height-Re<8&&(k="bottom"),o==="bottom"&&m.bottom+v.height+Re>b-8&&(k="top");const w=k==="top"?m.top-v.height-Re:m.bottom+Re;let C=m.left+m.width/2-v.width/2;C=Math.max(8,Math.min(C,z-v.width-8)),u({left:C,top:w,placement:k})},[o]),y=f.useCallback(()=>{d.current&&clearTimeout(d.current),d.current=setTimeout(()=>c(!0),r)},[r]),j=f.useCallback(()=>{d.current&&clearTimeout(d.current),c(!1),u(null)},[]);return f.useEffect(()=>{if(!s)return;const g=requestAnimationFrame(x);return()=>cancelAnimationFrame(g)},[s,x]),f.useEffect(()=>()=>{d.current&&clearTimeout(d.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:p,onMouseEnter:y,onMouseLeave:j,onFocus:y,onBlur:j,style:{display:"inline-block",...l},children:n}),s&&bn.createPortal(e.jsxs("div",{ref:h,role:"tooltip",style:{position:"fixed",left:(a==null?void 0:a.left)??-9999,top:(a==null?void 0:a.top)??-9999,maxWidth:i,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:-X,width:0,height:0,...a.placement==="top"?{bottom:-X,borderTop:`${X}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${X}px solid transparent`,borderRight:`${X}px solid transparent`}:{top:-X,borderBottom:`${X}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${X}px solid transparent`,borderRight:`${X}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...a.placement==="top"?{bottom:-5,borderTop:`${X-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${X-1}px solid transparent`,borderRight:`${X-1}px solid transparent`}:{top:-5,borderBottom:`${X-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${X-1}px solid transparent`,borderRight:`${X-1}px solid transparent`}}})]})]}),document.body)]})},ct={A:"fine",B:"rough",C:"rough",D:"ocr"};function kr(t){return typeof t!="string"?null:t in Ht?t:t in ct?ct[t]:null}const wr=["〇","一","二","三","四","五","六","七","八","九"],dt=["","十","百","千"],Cr=["","萬","億"];function Ot(t){if(t===0)return"〇";if(t<0)return`負${Ot(-t)}`;const n=[];let o=t,r=0;for(;o>0;){const i=o%1e4;i>0?n.unshift(_r(i,r>0)+Cr[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function _r(t,n){const o=[];let r=t;for(;r>0;)o.unshift(r%10),r=Math.floor(r/10);let i="";for(let l=0;l<o.length;l++){const s=o[l],c=o.length-1-l;s===0?i&&!i.endsWith("〇")&&(i+="〇"):s===1&&c===1&&l===0&&!n?i+=dt[c]:i+=wr[s]+dt[c]}return i.replace(/〇$/,"")}const qe={类:"#8e6f3e",书:"#c0392b",序:"#1a5276",结语:"#7d6608"},zr={考证:"#5d6d7e"};function Ir(t){const n=t.replace(".json","");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function Ut({file:t,isActive:n,onSelect:o,meta:r}){return e.jsxs("button",{onClick:()=>o(t),style:{padding:"3px 8px",border:n?"1px solid var(--bim-primary, #8e6f3e)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":"transparent",color:n?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4},children:[Ir(t),(r==null?void 0:r.vol_label)&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",r.vol_label,"冊)"]})]})}function Vt(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(r=>Vt(r,n)))}function Kt(t){var r;const n=t.files.length,o=((r=t.children)==null?void 0:r.reduce((i,l)=>i+Kt(l),0))||0;return n+o}function Nt({group:t,activeFile:n,onSelect:o,depth:r=0,juanMeta:i}){var d;const l=Vt(t,n||""),[s,c]=f.useState(l),a=Kt(t),u=!!((d=t.children)!=null&&d.length);if(f.useEffect(()=>{l&&c(!0)},[l]),t.files.length===1&&!u){const p=t.files[0],h=n===p;return e.jsx("button",{onClick:()=>o(p),style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:h?"1px solid var(--bim-primary, #8e6f3e)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:h?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":"transparent",color:h?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"12px",fontWeight:h?600:400,lineHeight:1.4},children:t.label})}return e.jsxs("div",{style:{marginBottom:r===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>c(!s),style:{display:"flex",alignItems:"center",gap:"6px",padding:r===0?"4px 8px":"2px 8px",paddingLeft:`${8+r*16}px`,cursor:"pointer",userSelect:"none",fontSize:r===0?"13px":"12px",fontWeight:r===0?600:500,color:l?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)"},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:s?"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:["(",a,")"]})]}),s&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",padding:`4px 0 4px ${24+r*16}px`},children:t.files.map(p=>e.jsx(Ut,{file:p,isActive:n===p,onSelect:o,meta:i==null?void 0:i[p]},p))}),u&&t.children.map((p,h)=>e.jsx(Nt,{group:p,activeFile:n,onSelect:o,depth:r+1,juanMeta:i},h))]})]})}function Tr({files:t,groups:n,activeFile:o,onSelect:r,juanMeta:i}){const l=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((s,c)=>e.jsx(Nt,{group:s,activeFile:o,onSelect:r,juanMeta:i},c))}):l.length===0?null:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:l.map(s=>e.jsx(Ut,{file:s,isActive:o===s,onSelect:r,meta:i==null?void 0:i[s]},s))})}function Rr({type:t}){const n=qe[t]||"#717171";return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:n,border:`1px solid ${n}40`,borderRadius:"2px",background:`${n}08`,flexShrink:0},children:t})}function Lr({section:t,onNavigate:n}){const{convert:o}=D(),r=re(),[i,l]=f.useState(!1),s=!!t.summary,c=!!t.comment,a=!!t.additional_comment,u=!!(t.content&&t.content.length>60),d=s||c||a||u,p=!i&&u?t.content.replace(/\n/g," ").slice(0,80)+"…":null;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>d&&l(!i),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:d?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[d&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:i?"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?`《${o(t.book_title)}》`:o(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[Ot(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:o(t.author_info||t.author)})]}),!i&&p&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:o(p)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:o(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"#e74c3c"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:r(t.work_id),onClick:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),h.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),i&&d&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:o(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:o(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:o(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:o(t.additional_comment)})]}),u&&!s&&!c&&!a&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:o(t.content)})]})]})}function Er({section:t}){const{convert:n}=D(),[o,r]=f.useState(!1),i=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>i&&r(!o),style:{display:"flex",alignItems:"center",gap:"8px",cursor:i?"pointer":"default",userSelect:"none"},children:[e.jsx(Rr,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:n(t.title)}),i&&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&&i&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${qe[t.type]||"#717171"}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:n(t.content)})})]})}function Br({section:t}){const{convert:n}=D();if(!t.content&&!t.title)return null;const o=n((t.content||t.title||"").replace(/\n{2,}/g,`
2
2
  `)),r=qe[t.type]||"#717171",i=t.type==="序"||t.type==="结语";return e.jsxs("div",{style:{padding:i?"10px 12px":"6px 0",margin:i?"8px 0":void 0,fontSize:"13px",color:"var(--bim-desc-fg, #555)",lineHeight:1.8,whiteSpace:"pre-line",borderLeft:i?`3px solid ${r}40`:void 0,background:i?"var(--bim-bg, #fafafa)":void 0,borderRadius:i?"0 4px 4px 0":void 0,position:"relative"},children:[i&&e.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:r,marginRight:"8px",padding:"1px 5px",border:`1px solid ${r}40`,borderRadius:"2px",background:`${r}08`,verticalAlign:"middle"},children:t.type}),o]})}function Wr(t,n,o){const[r,i]=f.useState({});return f.useEffect(()=>{var u;if(!n||t.length===0)return;let l=!1;const s=t.filter(d=>{var p;return!((p=o==null?void 0:o.current)!=null&&p.has(d))}),c={};for(const d of t)(u=o==null?void 0:o.current)!=null&&u.has(d)&&(c[d]=o.current.get(d));if(Object.keys(c).length>0&&i(c),s.length===0)return;const a=async d=>{var p;try{if(n.getEntry){const g=await n.getEntry(d);if(g)return{title:g.title,author:g.author}}const h=await n.getItem(d);if(!h)return null;const x=h.title||d,y=h.authors,j=(p=y==null?void 0:y[0])==null?void 0:p.name;return{title:x,author:j}}catch{return null}};return Promise.all(s.map(async d=>{var h;const p=await a(d);return(h=o==null?void 0:o.current)==null||h.set(d,p),[d,p]})).then(d=>{l||i(p=>{const h={...p};for(const[x,y]of d)h[x]=y;return h})}),()=>{l=!0}},[t.join(","),n]),r}function $r({section:t,onNavigate:n,transport:o,workLabelCache:r}){const{convert:i}=D(),l=re(),[s,c]=f.useState(!1),a=t.type,u=zr[a]||"#717171",d=!!t.content,p=t.work_ids||[],h=p.length>1,x=Wr(h?p:[],o,r),y=d&&!s&&t.content.length>80?t.content.slice(0,80)+"……":null;return e.jsxs("div",{style:{borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",padding:"10px 0"},children:[e.jsxs("div",{onClick:()=>d&&c(!s),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:d?"pointer":"default",userSelect:"none"},children:[d&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #aaa)",marginTop:"5px",transition:"transform 0.15s",transform:s?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)",lineHeight:1.6},children:t.header_line?i(t.header_line):i(t.title)}),!s&&y&&e.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:i(y)})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[p.length===1&&n&&e.jsx("a",{href:l(p[0]),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),j.stopPropagation(),n(p[0]))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),h&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",flexShrink:0},children:[p.length,"部作品"]}),e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:u,border:`1px solid ${u}40`,borderRadius:"2px",background:`${u}08`},children:a})]})]}),h&&n&&e.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:p.map(j=>{const g=x[j],I=g?`${i(g.title)}${g.author?`(${i(g.author)})`:""}`:j.slice(0,8)+"…";return e.jsxs("a",{href:l(j),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),m.stopPropagation(),n(j))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:j,children:["→",I]},j)})}),s&&d&&e.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${u}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:[e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:i(t.content)}),t.comment&&e.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:"1px solid var(--bim-widget-border, #eee)",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.8,fontStyle:"italic"},children:i(t.comment)})]})]})}function Ar({juan:t,searchQuery:n,onNavigate:o,transport:r,workLabelCache:i}){const{convert:l}=D(),s=f.useMemo(()=>{if(!n.trim())return t.sections;const a=n.trim().toLowerCase();return t.sections.filter(u=>{var d,p,h;return((d=u.title)==null?void 0:d.toLowerCase().includes(a))||((p=u.content)==null?void 0:p.toLowerCase().includes(a))||((h=u.comment)==null?void 0:h.toLowerCase().includes(a))})},[t.sections,n]),c=s.filter(a=>a.type==="考证").length;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"4px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:l(t.title)}),c>0&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:[c," 條"]})]}),t.source_url&&e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("a",{href:t.source_url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:"原文來源"})}),e.jsx("div",{children:s.map((a,u)=>e.jsx($r,{section:a,onNavigate:o,transport:r,workLabelCache:i},u))}),s.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function Pr({text:t}){const{convert:n}=D(),o=t.split(`
3
3
  `);return e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:o.map((r,i)=>{if(r.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:n(r.slice(2))},i);if(r.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:n(r.slice(3))},i);if(r.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:n(r.slice(4))},i);if(!r.trim())return i>0&&!o[i-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},i);const l=r.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:l.map((s,c)=>s.startsWith("**")&&s.endsWith("**")?e.jsx("strong",{children:n(s.slice(2,-2))},c):n(s))},i)})})}function Fr({sections:t,onNavigate:n}){const{convert:o}=D(),r=re(),i=[];let l=null;for(const s of t)s.type==="类"?(l&&i.push(l),l={category:s.title,categoryContent:s.content||void 0,items:[]}):s.type==="书"?(l||(l={category:"",items:[]}),l.items.push(s)):(s.type==="序"||s.type==="结语")&&(l||(l={category:"",items:[]}),l.items.push(s),s.type==="结语"&&(i.push(l),l=null));return l&&i.push(l),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:i.map((s,c)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[s.category&&e.jsxs("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:[o(s.category),s.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:o(s.categoryContent)})]}),s.items.map((a,u)=>a.type==="序"||a.type==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:o(a.content||"")},u):(a.content?a.title+a.content:a.title,e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&a.work_id?e.jsx("a",{href:r(a.work_id),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),d.stopPropagation(),n(a.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:o(a.title),children:e.jsx("strong",{children:o(a.title)})}):e.jsx("strong",{children:o(a.title)}),a.content&&o(a.content)]},u)))]},c))})}function Mr({juan:t,rawText:n,searchQuery:o,onNavigate:r}){const{convert:i}=D(),[l,s]=f.useState("catalog"),c=f.useMemo(()=>{if(!o.trim())return t.sections;const d=o.trim().toLowerCase();return t.sections.filter(p=>{var h,x,y,j,g,I;return((h=p.title)==null?void 0:h.toLowerCase().includes(d))||((x=p.book_title)==null?void 0:x.toLowerCase().includes(d))||((y=p.author)==null?void 0:y.toLowerCase().includes(d))||((j=p.author_info)==null?void 0:j.toLowerCase().includes(d))||((g=p.summary)==null?void 0:g.toLowerCase().includes(d))||((I=p.content)==null?void 0:I.toLowerCase().includes(d))})},[t.sections,o]),a=c.filter(d=>d.type==="书").length,u=c.filter(d=>d.type==="詩").length;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:i(t.title)}),e.jsx("div",{style:{display:"flex",gap:"2px",marginLeft:"8px"},children:["catalog","raw"].map(d=>e.jsx("button",{onClick:()=>s(d),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:d==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:l===d?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:l===d?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:d==="catalog"?"目錄":"原文"},d))}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:u>0?`${u} 首`:`${a} 部书`})]}),l==="raw"&&(n?e.jsx(Pr,{text:n}):e.jsx(Fr,{sections:c,onNavigate:r})),l==="catalog"&&c.map((d,p)=>d.type==="书"||d.type==="詩"?e.jsx(Lr,{section:d,onNavigate:r},p):d.type==="类"?e.jsx(Er,{section:d},p):e.jsx(Br,{section:d},p)),c.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function Yt(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 pt(t){const n=Yt(t);return n.length>0?n[0]:null}const Gt=({index:t,workId:n,transport:o,onNavigate:r,activeJuan:i,onJuanChange:l,className:s,style:c})=>{const[a,u]=f.useState(null),[d,p]=f.useState(!1),[h,x]=f.useState(null),[y,j]=f.useState(null),[g,I]=f.useState(null),[m,v]=f.useState(!1),[b,z]=f.useState(null),[k,w]=f.useState(""),C=f.useRef(new Map),B=i??y,R=f.useCallback(S=>{j(S),l==null||l(S)},[l]),E=t||a;f.useEffect(()=>{t&&(p(!1),x(null))},[t]),f.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollatedEditionIndex))return;let S=!1;return p(!0),x(null),o.getCollatedEditionIndex(n).then(L=>{if(!S)if(!L)x("未找到整理本数据");else{u(L);const K=pt(L);!i&&K&&R(K)}}).catch(L=>{S||x(L instanceof Error?L.message:"加载失败")}).finally(()=>{S||p(!1)}),()=>{S=!0}},[t,n,o,i,R]),f.useEffect(()=>{const S=t||a;if(S&&!B){const L=pt(S);L&&R(L)}},[t,a,B,R]);const H=n||(E==null?void 0:E.work_id),_=f.useCallback(async S=>{var L;if(!(!H||!(o!=null&&o.getCollatedJuan))){v(!0),I(null),z(null);try{const[K,V]=await Promise.all([o.getCollatedJuan(H,S),((L=o.getCollatedJuanText)==null?void 0:L.call(o,H,S))??Promise.resolve(null)]);I(K),z(V)}catch{I(null),z(null)}finally{v(!1)}}},[H,o]);f.useEffect(()=>{B&&_(B)},[B,_]);const $=S=>{R(S),w("")};if(d)return e.jsx("div",{className:s,style:{...c,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(h)return e.jsx("div",{className:s,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h});if(!E)return null;const W=E.type==="kaozhen",U=Yt(E);return e.jsxs("div",{className:s,style:c,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:W?e.jsxs(e.Fragment,{children:[E.target_source&&e.jsxs("span",{children:["考證對象:",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:E.target_source})," "]}),"共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:U.length})," 章"]}):e.jsxs("span",{children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:E.total_juan})," 卷"]})}),E.text_quality&&(()=>{const S=kr(E.text_quality.grade);return S?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(Sr,{content:vr[S],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:jr[S],cursor:"help"},children:Ht[S]})}),E.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",E.text_quality.source_note]})]}):null})()]}),e.jsx(Tr,{files:U,groups:E.juan_groups,activeFile:B,onSelect:$,juanMeta:E.juan_metadata}),e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("input",{type:"text",placeholder:W?"搜索条目、考证内容...":"搜索书名、作者...",value:k,onChange:S=>w(S.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}})}),m?e.jsx(ge,{}):g?W?e.jsx(Ar,{juan:g,searchQuery:k,onNavigate:r,transport:o,workLabelCache:C}):e.jsx(Mr,{juan:g,rawText:b,searchQuery:k,onNavigate:r}):B?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null,E.references&&E.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:"參考文獻"}),E.references.map((S,L)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[L+1,". "]}),S.url?e.jsx("a",{href:S.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:S.title}):e.jsx("span",{children:S.title}),S.author&&e.jsxs("span",{children:[",",S.author]}),S.note&&e.jsxs("span",{children:["。",S.note]})]},L))]})]})},Dr={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},Hr={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function Or(t){try{const n=new Date(t),o=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${o(n.getMonth()+1)}-${o(n.getDate())} ${o(n.getHours())}:${o(n.getMinutes())}`}catch{return t}}const qt=({items:t,loading:n})=>{const o=re();return n?e.jsx(ge,{}):t.length===0?e.jsx("div",{style:Ur,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const i=Dr[r.type],l=Hr[r.status];return e.jsxs("div",{style:Vr,children:[e.jsxs("div",{style:Kr,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...xt,background:i.color},children:i.label}),e.jsx("span",{style:{...xt,background:l.color},children:l.label})]}),e.jsx("span",{style:Nr,children:Or(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&e.jsxs("div",{style:Yr,children:[r.resourceId&&e.jsx("a",{href:o(r.resourceId),style:ut,children:r.resourceId}),r.pageUrl&&!r.resourceId&&e.jsx("a",{href:r.pageUrl,style:ut,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:Gr,children:r.content}),r.reply&&e.jsxs("div",{style:qr,children:[e.jsx("div",{style:Jr,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})})},Ur={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},Vr={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},Kr={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},xt={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},Nr={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},Yr={fontSize:"12px",marginBottom:"6px"},ut={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},Gr={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},qr={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},Jr={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},Ke=({transport:t,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:i,feedbackApiUrl:l})=>{const s=A(),[c,a]=f.useState(null),[u,d]=f.useState([]),[p,h]=f.useState("recommend"),[x,y]=f.useState([]),[j,g]=f.useState(!1),I=r??p,m=R=>{h(R),i==null||i(R)},[v,b]=f.useState(!0),[z,k]=f.useState(null),[w,C]=f.useState(null);f.useEffect(()=>{if(!t.getAllEntries)return;let R=!1;return t.getAllEntries().then(E=>{if(R)return;const H=E.filter(W=>W.type==="work").length,_=E.filter(W=>W.type==="book").length,$=E.filter(W=>W.type==="collection").length;a({works:H,books:_,collections:$})}).catch(()=>{}),()=>{R=!0}},[t]),f.useEffect(()=>{let R=!1;return(async()=>{if(o)return o;if(t.getRecommended)try{const H=await t.getRecommended();if(H!=null&&H.groups)return H.groups.flatMap(_=>_.items.map($=>({...$,group:_.name})))}catch{}return[]})().then(async H=>{if(R)return;const _=H.filter(W=>W.id);if(_.length===0){b(!1);return}const $=await Promise.all(_.map(async W=>{try{let U=null;if(t.getEntry)U=await t.getEntry(W.id);else{const S=await t.getItem(W.id);S&&(U={id:W.id,title:S.title||W.id,type:S.type||"work"})}if(U)return{...U,group:W.group,fallbackDescription:W.description}}catch{}return{id:W.id,title:W.title,type:O.extractType(W.id),group:W.group,fallbackDescription:W.description}}));R||(d($.filter(W=>W!==null)),b(!1))}),()=>{R=!0}},[t,o]),f.useEffect(()=>{if(!t.getResourceProgress)return;let R=!1;return t.getResourceProgress().then(E=>{R||k(E)}).catch(()=>{}),()=>{R=!0}},[t]),f.useEffect(()=>{if(!t.getSiteProgress)return;let R=!1;return t.getSiteProgress().then(E=>{R||C(E)}).catch(()=>{}),()=>{R=!0}},[t]),f.useEffect(()=>{if(!l||I!=="feedback")return;let R=!1;return g(!0),fetch(l).then(E=>E.json()).then(E=>{!R&&E.success&&y(E.items||[])}).catch(()=>{}).finally(()=>{R||g(!1)}),()=>{R=!0}},[l,I]);const B=R=>{switch(R){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(Le,{label:s.home.recommendTab,active:I==="recommend",onClick:()=>m("recommend")}),e.jsx(Le,{label:s.home.catalogTab,active:I==="catalog",onClick:()=>m("catalog")}),e.jsx(Le,{label:s.home.siteTab,active:I==="site",onClick:()=>m("site")}),l&&e.jsx(Le,{label:s.home.feedbackTab,active:I==="feedback",onClick:()=>m("feedback")})]}),I==="recommend"&&e.jsx(Zr,{recommended:u,loading:v,onNavigate:n,getIcon:B,t:s}),I==="catalog"&&e.jsx(Xr,{progress:z,t:s,onNavigate:n}),I==="site"&&e.jsx(eo,{progress:w,t:s,totalWorks:(c==null?void 0:c.works)??0}),I==="feedback"&&l&&e.jsx(qt,{items:x,loading:j})]})})},Le=({label:t,active:n,onClick:o})=>e.jsx("button",{onClick:o,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:n?"var(--bim-primary, #2563eb)":"var(--bim-desc-fg, #717171)",background:"none",border:"none",borderBottom:n?"2px solid var(--bim-primary, #2563eb)":"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:t}),Zr=({recommended:t,loading:n,onNavigate:o,getIcon:r,t:i})=>{const l=re();if(n)return e.jsx(ge,{});if(t.length===0)return null;const s=new Map;for(const c of t){const a=c.group||i.home.recommendedBrowse;s.has(a)||s.set(a,[]),s.get(a).push(c)}return e.jsx(e.Fragment,{children:Array.from(s.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(u=>{const d=u.dynasty||u.author?`${u.dynasty?`〔${u.dynasty}〕`:""}${u.author||""}`:u.fallbackDescription;return e.jsxs("a",{href:l(u.id),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),o==null||o(u.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(u.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[u.title,u.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:u.edition})]}),d&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d})]})]},u.id)})})]},c))})},Xr=({progress:t,t:n,onNavigate:o})=>{if(!t)return e.jsx(ge,{});const r=[...t.resources].sort((c,a)=>c.priority-a.priority),i=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},s={in_progress:"#f59e0b",done:"#10b981",todo:"#9ca3af"};return e.jsx("div",{children:i.map(c=>{const a=r.filter(u=>u.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:s[c]}}),l[c]," (",a.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(u=>e.jsx(Qr,{item:u,t:n,statusColor:s[c],onNavigate:o},u.id))})]},c)})})},Qr=({item:t,t:n,statusColor:o,onNavigate:r})=>{const i=re(),l=t.total>0?Math.round(t.imported/t.total*100):0,s=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:i(a),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),r(a))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:u=>u.currentTarget.style.borderBottomStyle="solid",onMouseLeave:u=>u.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:s})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?Ie(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:`${l}%`,borderRadius:"2px",background:o,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},eo=({progress:t,t:n,totalWorks:o})=>{if(!t)return e.jsx(ge,{});const r=[...t.resources].sort((a,u)=>a.priority-u.priority),i=r.filter(a=>a.imported>0),l=r.filter(a=>a.imported===0),s=i.reduce((a,u)=>Math.max(a,u.imported),0),c=o>0?Math.round(s/o*100):0;return e.jsxs("div",{children:[o>0&&e.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)",fontSize:"13px",color:"var(--bim-fg, #333)"},children:[n.home.siteCoverage,": ",e.jsx("strong",{children:s.toLocaleString()})," / ",o.toLocaleString()," ",n.indexType.work," (",c,"%)"]}),i.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"#10b981"}}),n.home.statusInProgress," (",i.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:i.map(a=>e.jsx(ft,{item:a,t:n,totalWorks:o},a.id))})]}),l.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"#9ca3af"}}),n.home.statusTodo," (",l.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(a=>e.jsx(ft,{item:a,t:n,totalWorks:o},a.id))})]})]})},ft=({item:t,t:n,totalWorks:o})=>{const r=o>0?Math.round(t.imported/o*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),t.imported>0&&o>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:"#10b981",transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},gt="(max-width: 768px)";function to(){const[t,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(gt).matches);return f.useEffect(()=>{const o=window.matchMedia(gt),r=i=>n(i.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),t}const no=({transport:t,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:i})=>{var U;const l=A(),{convert:s}=D(),c=to(),[a,u]=f.useState(null),[d,p]=f.useState(null),[h,x]=f.useState(!1),[y,j]=f.useState("detail"),[g,I]=f.useState([]),[m,v]=f.useState(!1),[b,z]=f.useState(null),[k,w]=f.useState(!1),C=f.useCallback(async S=>{if(!t.getCollatedEditionIndex){z(null);return}w(!0);try{const L=await t.getCollatedEditionIndex(S);z(L)}catch{z(null)}finally{w(!1)}},[t]),B=f.useCallback(async S=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){I([]);return}v(!0);try{if(t.getCollectionCatalogs){const L=await t.getCollectionCatalogs(S);I(L||[])}else if(t.getCollectionCatalog){const L=await t.getCollectionCatalog(S);I(L?[{resource_id:"",data:L}]:[])}}catch{I([])}finally{v(!1)}},[t]),R=f.useCallback(async S=>{if(o){o(S);return}u(S),p(null),I([]),z(null),j("detail"),x(!0);try{const L=await t.getItem(S.id);L&&(p(L),L.type==="collection"?B(S.id):L.type==="work"&&L.has_collated&&C(S.id))}catch(L){console.error("加载详情失败:",L)}finally{x(!1)}},[t,o,B,C]),E=f.useCallback(async S=>{p(null),I([]),z(null),j("detail"),x(!0);try{const L=await t.getItem(S);L&&(p(L),u({id:S,title:L.title||S,type:L.type||"book"}),L.type==="collection"?B(S):L.type==="work"&&L.has_collated&&C(S))}catch(L){console.error("导航失败:",L)}finally{x(!1)}},[t,B,C]),H=(d==null?void 0:d.type)==="collection"&&(g.length>0||m)||(d==null?void 0:d.type)==="work"&&(b||k),_=c&&(h||d),$=f.useCallback(()=>{u(null),p(null),I([]),z(null),j("detail")},[]),W=e.jsx(e.Fragment,{children:h?e.jsx(ge,{}):d?e.jsxs(e.Fragment,{children:[(H||i)&&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:[H&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>j("detail"),style:Ee(y==="detail"),children:l.detailTab.basicInfo}),d.type==="collection"&&m&&g.length===0&&e.jsxs("button",{onClick:()=>{},style:Ee(!1),children:[l.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),d.type==="collection"&&g.map(S=>e.jsx("button",{onClick:()=>j(`catalog:${S.resource_id}`),style:Ee(y===`catalog:${S.resource_id}`),children:S.short_name?`${s(S.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},S.resource_id)),d.type==="work"&&(b||k)&&e.jsxs("button",{onClick:()=>j("collated"),style:Ee(y==="collated"),children:[l.detailTab.collatedEdition,k&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),i&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:i})]}),e.jsx("div",{style:{padding:c?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:y==="detail"?e.jsx(Ge,{data:d,transport:t,onNavigate:E}):y.startsWith("catalog:")?e.jsx(Dt,{data:(U=g.find(S=>`catalog:${S.resource_id}`===y))==null?void 0:U.data,onNavigate:E}):y==="collated"?e.jsx(Gt,{index:b||void 0,workId:d.id,transport:t,onNavigate:E}):null})]}):e.jsx(Ke,{transport:t,onNavigate:E,recommendedIds:r})});return c?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:_?e.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:$,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:["← ",l.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:W})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(Ve,{transport:t,onEntryClick:R,hideModeIndicator:n}),!d&&e.jsx(Ke,{transport:t,onNavigate:E,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(Ve,{transport:t,onEntryClick:R,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:W})]})};function Ee(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 ro=({data:t,onNavigate:n,className:o,style:r})=>{var d;const i=A(),{convert:l}=D(),[s,c]=f.useState(((d=t.divisions[0])==null?void 0:d.name)??null),[a,u]=f.useState(null);return e.jsxs("div",{className:o,style:r,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:l(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:[i.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",i.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",i.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",i.unit.bu]}),t.stats.categories!=null&&e.jsxs("span",{children:[t.stats.categories," 類"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.divisions.map(p=>e.jsx(oo,{division:p,expanded:s===p.name,onToggle:()=>c(s===p.name?null:p.name),expandedCat:a,onCatToggle:h=>u(a===h?null:h),onNavigate:n},p.name))})]})},oo=({division:t,expanded:n,onToggle:o,expandedCat:r,onCatToggle:i,onNavigate:l})=>{const{convert:s}=D(),c=t.categories.reduce((a,u)=>{const d=u.stats||{zhulu:0,cunmu:0};return a+(d.zhulu||0)+(d.cunmu||0)},0);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)":"var(--bim-bg, #f8f8f8)",cursor:"pointer",fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsx("span",{children:s(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 u=`${t.name}/${a.name}`;return e.jsx(io,{category:a,expanded:r===u,onToggle:()=>i(u),onNavigate:l},a.name)})})]})},io=({category:t,expanded:n,onToggle:o,onNavigate:r})=>{var a,u,d,p;const{convert:i}=D(),l=((a=t.books)==null?void 0:a.zhulu)||[],s=((u=t.books)==null?void 0:u.cunmu)||[],c=(((d=t.stats)==null?void 0:d.zhulu)||l.length)+(((p=t.stats)==null?void 0:p.cunmu)||s.length);return e.jsxs("div",{children:[e.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?"var(--bim-input-bg, #fff)":"transparent",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsxs("span",{style:{fontWeight:500},children:[i(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&&(l.length>0||s.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&e.jsx(ht,{label:"著錄",books:l,onNavigate:r}),s.length>0&&e.jsx(ht,{label:"存目",books:s,onNavigate:r})]})]})},ht=({label:t,books:n,onNavigate:o})=>{const{convert:r}=D(),i=re(),[l,s]=f.useState(n.length<=20),c=l?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,u)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:a.work_id&&o?e.jsx("a",{href:i(a.work_id),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),o(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(a.title)}):r(a.title)}),a.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(a.volumes)}),a.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(a.author).slice(0,20)})]},u))}),!l&&e.jsxs("button",{onClick:()=>s(!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," 條"]})]})},oe=({title:t,onSave:n,onAskAI:o,extraButtons:r,children:i})=>{const l=A();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,o&&e.jsx("button",{onClick:o,style:so,children:"AI"}),n&&e.jsx("button",{onClick:n,style:lo,children:l.action.save})]})]}),i]})},lo={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},so={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},ee=({label:t,value:n,onChange:o,placeholder:r,disabled:i})=>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:l=>o(l.target.value),placeholder:r,disabled:i,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"}})]}),fe=({value:t,onChange:n,placeholder:o})=>{const r=f.useRef(null);return f.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:r,value:t||"",onChange:i=>n(i.target.value),placeholder:o,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},We=({children:t,color:n,style:o})=>e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||"var(--bim-primary-soft, rgba(0,120,212,0.15))",color:n?"#fff":"var(--bim-fg, #333)",...o},children:t});function ao(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Be=({value:t,onChange:n,label:o})=>{const[r,i]=f.useState(!1),l=f.useRef(null),s=ao(t||"");return f.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&s?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:bt,children:o}),e.jsxs("div",{onClick:()=>i(!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:s.name}),e.jsx(We,{children:s.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:bt,children:o}),e.jsx("input",{ref:l,type:"text",value:t||"",onChange:c=>n(c.target.value),onBlur:()=>i(!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"}})]})},bt={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function co(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function po(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Jt=({items:t,onChange:n,onOpenEntityPicker:o})=>{const r=A(),[i,l]=f.useState(null),s=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(t.length)},c=p=>{n(t.filter((h,x)=>x!==p)),i===p&&l(null)},a=(p,h,x)=>{const y=[...t];y[p]={...y[p],[h]:x},n(y)},u=(p,h)=>{const x=[...t];x[p]={...x[p],type:h,id:"",name:""},n(x),h==="bookID"&&o&&o(y=>{const j=[...t];j[p]={...j[p],id:y.id,name:y.title,type:"bookID"},n(j)})},d=p=>{o&&o(h=>{const x=[...t];x[p]={...x[p],id:h.id,name:h.title,type:"bookID"},n(x)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((p,h)=>e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(i===h?null:h),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:i===h?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:p.name||`${r.editor.sourcePlaceholder} ${h+1}`}),p.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:co(p.type),color:"white",borderRadius:"3px",fontWeight:500},children:po(p.type)}),e.jsx("button",{onClick:x=>{x.stopPropagation(),c(h)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),i===h&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!p.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:()=>u(h,"bookID"),style:{...mt,borderColor:"#4caf50",color:"#4caf50"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>u(h,"url"),style:{...mt,borderColor:"#2196f3",color:"#2196f3"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),p.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:pe,children:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const x=[...t];x[h]={...x[h],type:"",id:"",name:""},n(x)},style:yt,children:r.action.changeType})]}),p.id&&p.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid #4caf50",borderRadius:"6px"},children:[e.jsx("span",{style:{color:"#4caf50",fontSize:"16px"},children:"✓"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:p.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:p.id})]}),e.jsx("button",{onClick:()=>d(h),style:{background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-fg, #333)",cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):e.jsxs("button",{onClick:()=>d(h),style:{width:"100%",padding:"14px",border:"2px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),p.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:pe,children:r.label.sourceName}),e.jsx("button",{onClick:()=>{const x=[...t];x[h]={...x[h],type:"",id:"",name:""},n(x)},style:yt,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:p.name,onChange:x=>a(h,"name",x.target.value),placeholder:r.editor.sourceNamePlaceholder,style:be})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.urlAddress}),e.jsx("input",{type:"text",value:p.id,onChange:x=>a(h,"id",x.target.value),placeholder:"https://...",style:be})]})]}),p.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:"1px dashed var(--bim-widget-border, #e0e0e0)",paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...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:p.details,onChange:x=>a(h,"details",x.target.value),placeholder:r.editor.detailsPlaceholder,style:be})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.positionOptional}),e.jsx("input",{type:"text",value:p.position,onChange:x=>a(h,"position",x.target.value),placeholder:"如: 卷三, p.52",style:be})]})]}),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:p.version,onChange:x=>a(h,"version",x.target.value),placeholder:"如: v1.0, 2024-01",style:be})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.processorVersionOptional}),e.jsx("input",{type:"text",value:p.processor_version,onChange:x=>a(h,"processor_version",x.target.value),placeholder:"如: v0.1",style:be})]})]})]})]})})]},h)),e.jsxs("button",{onClick:s,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},be={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"},mt={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"},yt={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function Zt(t){if(!t||!t.trim())return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(o=>({id:o.id||"",name:o.name||"",type:o.type||"",details:o.details||"",position:o.position||"",version:o.version||"",processor_version:o.processor_version||""}))}catch{}return[]}function Xt(t){return!t||t.length===0?"":JSON.stringify(t)}const Qt=({entityType:t,entityId:n,entityTitle:o,parentWork:r,parentCollection:i,belongsToWork:l,belongsToCollection:s,childWorks:c,childCollections:a,containedBooks:u,siblingBooks:d,onLinkEntity:p,onUnlinkEntity:h,onViewEntity:x,onCreateAndLink:y,onSaveRelations:j})=>{const g=A();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:g.section.relations})]}),j&&e.jsx("button",{onClick:j,style:xo,children:g.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{direction:"up",title:g.relation.belongsToWork,entity:l,onView:x,onUnlink:()=>h("workId"),onLink:()=>p("workId","work"),onCreate:()=>y("workId","work",{title:o}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(ke,{direction:"up",title:g.relation.containedInCollection,entity:s,onView:x,onUnlink:()=>h("collectionId"),onLink:()=>p("collectionId","collection"),onCreate:()=>y("collectionId","collection",{title:o}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),l&&d&&d.length>0&&e.jsx(me,{direction:"horizontal",title:`${g.relation.siblingVersions} (${d.length})`,entities:d,onView:x,onAdd:()=>y("siblingBook","book",{workId:l.id}),addLabel:g.relation.addVersionForWork,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{direction:"up",title:g.relation.parentWork,entity:r,onView:x,onUnlink:()=>h("parentWorkId"),onLink:()=>p("parentWorkId","work"),onCreate:()=>y("parentWorkId","work"),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),c&&c.length>0&&e.jsx(me,{direction:"down",title:`${g.relation.childWorks} (${c.length})`,entities:c,onView:x,onAdd:()=>y("childWork","work",{parentWorkId:n}),addLabel:g.action.addSubWork,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),a&&a.length>0&&e.jsx(me,{direction:"down",title:`${g.relation.collectionImpl} (${a.length})`,entities:a,onView:x,onAdd:()=>y("childCollection","collection",{workId:n}),addLabel:g.action.addCollectionImpl,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),e.jsx(me,{direction:"down",title:`${g.relation.allVersions} (${(u==null?void 0:u.length)??0})`,entities:u||[],onView:x,onAdd:()=>y("childBook","book",{workId:n}),addLabel:g.action.addVersion,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{direction:"up",title:g.relation.correspondingWork,entity:l,onView:x,onUnlink:()=>h("workId"),onLink:()=>p("workId","work"),onCreate:()=>y("workId","work",{title:o}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(ke,{direction:"up",title:g.relation.parentCollection,entity:i,onView:x,onUnlink:()=>h("parentCollectionId"),onLink:()=>p("parentCollectionId","collection"),onCreate:()=>y("parentCollectionId","collection"),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(me,{direction:"down",title:`${g.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:x,onAdd:()=>y("childCollection","collection",{parentCollectionId:n}),addLabel:g.action.addSubCollection,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),e.jsx(me,{direction:"down",title:`${g.relation.containedBooks} (${(u==null?void 0:u.length)??0})`,entities:u||[],onView:x,onAdd:()=>y("childBook","book",{collectionId:n}),addLabel:g.action.addBook,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]})]})]})},ke=({direction:t,title:n,entity:o,onView:r,onUnlink:i,onLink:l,onCreate:s,linkLabel:c,createLabel:a,notLinkedLabel:u,viewLabel:d,unlinkLabel:p})=>{const h=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:h,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:x}),e.jsx("span",{children:n})]}),o?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:en(o.type)}),e.jsx("span",{style:{fontWeight:500},children:o.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:o.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(vt,{onClick:()=>r(o),title:d,children:"👁️"}),e.jsx(vt,{onClick:i,title:p,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:u}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(Ne,{onClick:l,children:c}),e.jsx(Ne,{onClick:s,primary:!0,children:a})]})]})},me=({direction:t,title:n,entities:o,onView:r,onAdd:i,addLabel:l,noneLabel:s,expandMoreLabel:c})=>{const[a,u]=f.useState(!1),d=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",p=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",h=a?o:o.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:d,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:p}),e.jsx("span",{children:n})]}),o.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[h.map(x=>e.jsxs("div",{onClick:()=>r(x),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[e.jsx("span",{children:en(x.type)}),e.jsx("span",{children:x.title})]},x.id)),o.length>5&&!a&&e.jsxs("div",{onClick:()=>u(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[c," (",o.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:s}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(Ne,{onClick:i,primary:!0,children:["+ ",l]})})]})},vt=({onClick:t,title:n,danger:o,children:r})=>e.jsx("button",{onClick:i=>{i.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:o?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:r}),Ne=({onClick:t,primary:n,children:o})=>e.jsx("button",{onClick:t,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:n?"var(--bim-primary, #0078d4)":"transparent",color:n?"var(--bim-primary-fg, #fff)":"inherit",cursor:"pointer"},children:o});function en(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const xo={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"},tn=({isOpen:t,entityType:n,title:o,onSelect:r,onCancel:i,onCreate:l,searchResults:s,onSearch:c,isLoading:a,excludeId:u})=>{const[d,p]=f.useState(""),h=u?s.filter(g=>g.id!==u):s;f.useEffect(()=>{t&&(p(""),c(""))},[t]);const x=g=>{p(g),c(g)};if(!t)return null;const y=n==="work"?"作品":n==="book"?"书籍":"丛编",j=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:uo,children:e.jsxs("div",{style:fo,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:o}),e.jsx("button",{onClick:i,style:go,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:d,onChange:g=>x(g.target.value),placeholder:`搜索${y}名称或 ID...`,autoFocus:!0,style:ho})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?e.jsx("div",{style:He,children:"搜索中..."}):h.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:h.map(g=>e.jsxs("div",{onClick:()=>r(g),style:bo,children:[e.jsx("span",{style:{fontSize:"16px"},children:j}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[g.title,g.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:g.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[g.id,g.author&&` · ${g.author}`,g.dynasty&&` · ${g.dynasty}`]})]})]},g.id))}):d?e.jsxs("div",{style:He,children:["未找到匹配的",y]}):e.jsxs("div",{style:He,children:["输入关键词搜索",y]})}),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:l,style:mo,children:["创建新",y,"并关联"]})]})]})})},uo={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},fo={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)"},go={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},ho={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"},bo={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},He={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},mo={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},jt={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},yo={work:"📜",book:"📖",collection:"📚",entity:"👤"},nn=({isOpen:t,entityType:n,relationField:o,inheritData:r,onConfirm:i,onCancel:l})=>{const[s,c]=f.useState(""),a=f.useRef(null);f.useEffect(()=>{t&&(c((r==null?void 0:r.title)||""),setTimeout(()=>{var h,x;(h=a.current)==null||h.focus(),(x=a.current)==null||x.select()},100))},[t,r==null?void 0:r.title]);const u=h=>{h.key==="Enter"&&s.trim()?d():h.key==="Escape"&&l()},d=()=>{s.trim()&&i(s.trim(),{...r,title:s.trim()})};if(!t)return null;const p=()=>{switch(o){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${jt[n]}`}};return e.jsx("div",{style:vo,onClick:h=>{h.target===h.currentTarget&&l()},children:e.jsxs("div",{style:jo,onClick:h=>h.stopPropagation(),children:[e.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:yo[n]}),e.jsx("span",{children:p()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:a,type:"text",value:s,onChange:h=>c(h.target.value),onKeyDown:u,placeholder:`请输入${jt[n]}名称...`,style:So})]}),((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:l,style:ko,children:"取消"}),e.jsx("button",{onClick:d,disabled:!s.trim(),style:{...wo,opacity:s.trim()?1:.6,cursor:s.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},vo={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},jo={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)"},So={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"},ko={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},wo={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Co(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function rn(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function _o(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const on=({isOpen:t,title:n,filterType:o="all",recentEntities:r=[],excludeId:i,showCreateButton:l=!1,createButtonText:s,onSelect:c,onCancel:a,onCreate:u,onSearch:d})=>{const[p,h]=f.useState(""),[x,y]=f.useState([]),[j,g]=f.useState(!1),[I,m]=f.useState("recent");f.useEffect(()=>{t&&(h(""),y([]),m(r.length>0?"recent":"search"))},[t,r.length]),f.useEffect(()=>{if(!p.trim()){y([]);return}const C=setTimeout(async()=>{g(!0);try{y(await d(p,o))}catch{y([])}finally{g(!1)}},300);return()=>clearTimeout(C)},[p,o,d]);const v=f.useCallback(C=>{h(C.target.value),C.target.value.trim()&&m("search")},[]),b=f.useCallback(C=>i?C.filter(B=>B.id!==i):C,[i]);if(!t)return null;const z=n||(o==="all"?"选择实体":`选择${rn(o)}`),k=b(r),w=b(x);return e.jsx("div",{style:Io,children:e.jsxs("div",{style:To,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:z}),e.jsx("button",{onClick:a,style:Ro,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:p,onChange:v,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Lo}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),j&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),k.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(St,{active:I==="recent",onClick:()=>m("recent"),children:["最近使用 (",k.length,")"]}),e.jsxs(St,{active:I==="search",onClick:()=>m("search"),children:["搜索结果 ",w.length>0&&`(${w.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:I==="recent"&&k.length>0?e.jsx(kt,{entities:k,onSelect:c}):p.trim()?j?e.jsx(Oe,{message:"搜索中..."}):w.length>0?e.jsx(kt,{entities:w,onSelect:c}):e.jsx(Oe,{message:"未找到匹配的结果"}):e.jsx(Oe,{message:"输入关键词开始搜索"})}),l&&u&&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:u,style:Eo,children:s||"创建新实体"})]})]})})},St=({active:t,onClick:n,children:o})=>e.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-fg, #333)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",fontWeight:t?600:400,marginBottom:"-1px"},children:o}),kt=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(o=>e.jsx(zo,{entity:o,onClick:()=>n(o)},o.id))}),zo=({entity:t,onClick:n})=>{const[o,r]=f.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:o?"var(--bim-primary-soft, rgba(0,120,212,0.15))":"var(--bim-primary-soft, rgba(0,120,212,0.05))",transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:Co(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:_o(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:rn(t.type)})]})},Oe=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),Io={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},To={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)"},Ro={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Lo={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"},Eo={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Bo={work:"#4caf50",collection:"#2196f3",book:"#ff9800",entity:"#9c27b0"},Wo={work:"📜",collection:"📚",book:"📖",entity:"👤"},ln=({data:t,onChange:n,onSave:o,transport:r,onNavigate:i,showDelete:l,onDelete:s,onAskAI:c,renderSectionActions:a,onDownloadResource:u,downloadStatuses:d,relations:p,onRelationsChange:h})=>{var te;const x=A(),[y,j]=f.useState(!1),[g,I]=f.useState("work"),[m,v]=f.useState(""),[b,z]=f.useState(""),[k,w]=f.useState([]),[C,B]=f.useState(!1),[R,E]=f.useState(!1),[H,_]=f.useState("work"),[$,W]=f.useState(""),[U,S]=f.useState(),[L,K]=f.useState(!1),[V,F]=f.useState(null),[le,Q]=f.useState([]);f.useRef(null);const de=t.type,ue=de==="work",xe=de==="collection",J=de==="book",N=f.useCallback((T,M)=>{n({...t,[T]:M})},[t,n]),Ae=f.useCallback((T,M)=>{v(T),I(M),z(x.editor.selectToLink+x.indexType[M]),w([]),j(!0)},[x]),Pe=f.useCallback(T=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,T)},[r,t.id]),ye=f.useCallback(T=>{i==null||i(T.id,T.type)},[i]),ve=f.useCallback((T,M,q)=>{const se={...q,author:(q==null?void 0:q.author)||t.author,dynasty:(q==null?void 0:q.dynasty)||t.dynasty};_(M),W(T),S(se),E(!0)},[t.author,t.dynasty]),Fe=f.useCallback((T,M)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,$,{type:H,title:T,inheritData:M}),E(!1)},[r,t.id,$,H]),Te=f.useCallback(T=>{if(!T.trim()){w([]);return}B(!0),r!=null&&r.searchEntities&&r.searchEntities(T,g).then(M=>{w(M),B(!1)}).catch(()=>{w([]),B(!1)})},[r,g]),Me=f.useCallback(T=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,m,T.id),j(!1)},[r,t.id,m]),P=f.useCallback(()=>{o()},[o]),Y=f.useCallback(T=>{F(()=>T),K(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(Q).catch(()=>{})},[r]),Z=f.useCallback((T,M)=>r!=null&&r.searchEntities?r.searchEntities(T,M==="all"?void 0:M):Promise.resolve([]),[r]),G=f.useCallback(T=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(T),Q(M=>[T,...M.filter(q=>q.id!==T.id)].slice(0,10)),V==null||V(T),K(!1),F(null)},[r,V]);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:Wo[de]}),e.jsx("span",{children:t.title||x.editor.untitled}),e.jsx(We,{children:t.id}),e.jsx(We,{color:Bo[de],children:x.indexType[de]})]})}),e.jsx(oe,{title:x.section.basicInfo,onSave:o,onAskAI:c?()=>c("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(Be,{label:ue?x.editor.workTitle:xe?x.editor.collectionTitle:x.editor.bookTitle,value:t.title,onChange:T=>N("title",T)}),J&&e.jsx(Be,{label:x.editor.belongsToWork,value:t.workName||"",onChange:T=>N("workName",T)}),e.jsx(ee,{label:x.editor.authorLabel,value:t.author||"",onChange:T=>N("author",T)}),e.jsx(ee,{label:x.editor.dynastyLabel,value:t.dynasty||"",onChange:T=>N("dynasty",T)}),(J||xe)&&e.jsx(Be,{label:x.editor.containedIn,value:t.collection||"",onChange:T=>N("collection",T)}),(J||xe)&&e.jsx(ee,{label:x.editor.holderLabel,value:t.holder||"",onChange:T=>N("holder",T)}),(J||xe)&&e.jsx(ee,{label:J?x.editor.pageLabel:x.editor.volumeLabel,value:t.pages||"",onChange:T=>N("pages",T)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(ee,{label:x.editor.firstImageLabel,value:t.firstImage||"",onChange:T=>N("firstImage",T)})})]})}),e.jsx(oe,{title:x.section.description,onSave:o,onAskAI:c?()=>c("介绍"):void 0,children:e.jsx(fe,{value:t.description||"",onChange:T=>N("description",T),placeholder:x.editor.descriptionPlaceholder})}),(((te=t.additional_works)==null?void 0:te.length)||0)>0&&e.jsx(oe,{title:x.section.additionalWorks,onSave:o,children:e.jsx($o,{items:t.additional_works||[],onChange:T=>N("additional_works",T)})}),e.jsx(oe,{title:x.section.indexedBy,onSave:o,onAskAI:c?()=>c("收录于"):void 0,children:e.jsx(Ao,{items:t.indexed_by||[],onChange:T=>N("indexed_by",T)})}),e.jsx(oe,{title:x.section.emendatedBy,onSave:o,onAskAI:c?()=>c("考证"):void 0,children:e.jsx(Po,{items:t.emendated_by||[],onChange:T=>N("emendated_by",T)})}),e.jsx(oe,{title:x.section.textResources,onSave:o,onAskAI:c?()=>c("资源"):void 0,children:e.jsx(Ue,{items:t.resources||[],onChange:T=>N("resources",T),onDownload:u,downloadStatuses:d,filterType:"text"})}),e.jsx(oe,{title:x.section.imageResources,onSave:o,children:e.jsx(Ue,{items:t.resources||[],onChange:T=>N("resources",T),onDownload:u,downloadStatuses:d,filterType:"image"})}),e.jsx(oe,{title:x.section.sources,onSave:o,onAskAI:c?()=>c("资料来源"):void 0,children:e.jsx(Jt,{items:Zt(t.sources||""),onChange:T=>N("sources",Xt(T)),onOpenEntityPicker:Y})}),(J||xe)&&e.jsx(oe,{title:x.section.provenance,onSave:o,onAskAI:c?()=>c("收藏历史"):void 0,children:e.jsx(fe,{value:t.provenance||"",onChange:T=>N("provenance",T),placeholder:x.editor.provenancePlaceholder})}),J&&e.jsx(oe,{title:x.section.otherEditions,onSave:o,onAskAI:c?()=>c("其他版本"):void 0,children:e.jsx(fe,{value:t.otherEditions||"",onChange:T=>N("otherEditions",T),placeholder:x.editor.otherEditionsPlaceholder})}),e.jsx(Qt,{entityType:de,entityId:t.id,entityTitle:t.title,parentWork:p==null?void 0:p.parentWork,parentCollection:p==null?void 0:p.parentCollection,belongsToWork:p==null?void 0:p.belongsToWork,belongsToCollection:p==null?void 0:p.belongsToCollection,childWorks:p==null?void 0:p.childWorks,childCollections:p==null?void 0:p.childCollections,containedBooks:p==null?void 0:p.containedBooks,siblingBooks:p==null?void 0:p.siblingBooks,onLinkEntity:Ae,onUnlinkEntity:Pe,onViewEntity:ye,onCreateAndLink:ve,onSaveRelations:P}),l&&s&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:x.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:x.editor.dangerZoneDesc}),e.jsx("button",{onClick:s,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:x.editor.deleteEntity})]}),e.jsx(tn,{isOpen:y,entityType:g,title:b,onSelect:Me,onCancel:()=>j(!1),onCreate:()=>{j(!1),ve(m,g)},searchResults:k,onSearch:Te,isLoading:C,excludeId:t.id}),e.jsx(nn,{isOpen:R,entityType:H,relationField:$,inheritData:U,onConfirm:Fe,onCancel:()=>E(!1)}),e.jsx(on,{isOpen:L,title:x.action.selectBookOrWork,filterType:"all",recentEntities:le,excludeId:t.id,onSelect:G,onCancel:()=>{K(!1),F(null)},onSearch:Z})]})};function $o({items:t,onChange:n}){const o=A(),r=(s,c,a)=>{const u=t.map((d,p)=>p===s?{...d,[c]:a}:d);n(u)},i=s=>n(t.filter((c,a)=>a!==s)),l=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((s,c)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(ee,{label:o.editor.bookNameLabel,value:s.book_title,onChange:a=>r(c,"book_title",a)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(ee,{label:o.label.juanCount,value:s.n_juan!=null?String(s.n_juan):"",onChange:a=>r(c,"n_juan",a&&parseInt(a,10)||void 0)})}),e.jsx("button",{onClick:()=>i(c),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},c)),e.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:o.action.addAdditionalWork})]})}function sn({items:t,onChange:n,showMeta:o,addLabel:r}){const i=A(),[l,s]=f.useState(null),c=(d,p,h)=>{const x=t.map((y,j)=>j===d?{...y,[p]:h||void 0}:y);n(x)},a=d=>{n(t.filter((p,h)=>h!==d)),l===d&&s(null)},u=()=>{n([...t,{source:""}]),s(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((d,p)=>{const h=l===p;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:h?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>s(h?null:p),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:h?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:d.source||i.editor.unnamedSource}),d.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:d.source_bid}),e.jsx("button",{onClick:x=>{x.stopPropagation(),a(p)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid #ddd",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"#999"},children:"✕"})]}),!h&&o&&(d.title_info||d.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[d.title_info,d.title_info&&d.author_info&&" — ",d.author_info]}),h&&e.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(ee,{label:i.label.sourceName,value:d.source,onChange:x=>c(p,"source",x)}),e.jsx(ee,{label:i.label.sourceBid,value:d.source_bid||"",onChange:x=>c(p,"source_bid",x)})]}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(ee,{label:i.label.titleInfo,value:d.title_info||"",onChange:x=>c(p,"title_info",x)}),e.jsx(ee,{label:i.label.authorInfo,value:d.author_info||"",onChange:x=>c(p,"author_info",x)})]}),e.jsx(ee,{label:i.label.edition,value:d.edition||"",onChange:x=>c(p,"edition",x)})]}),e.jsx(fe,{value:d.summary||"",onChange:x=>c(p,"summary",x),placeholder:i.editor.summaryPlaceholder}),e.jsx(fe,{value:d.comment||"",onChange:x=>c(p,"comment",x),placeholder:i.editor.commentPlaceholder}),e.jsx(fe,{value:d.additional_comment||"",onChange:x=>c(p,"additional_comment",x),placeholder:i.editor.additionalCommentPlaceholder})]})]},p)}),e.jsx("button",{onClick:u,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:r})]})}function Ao({items:t,onChange:n}){const o=A();return e.jsx(sn,{items:t,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function Po({items:t,onChange:n}){const o=A();return e.jsx(sn,{items:t,onChange:n,addLabel:o.action.addEmendatedBy})}function an(t){var c,a,u,d,p,h,x;const n=((a=(c=t.authors)==null?void 0:c[0])==null?void 0:a.name)||"",o=((u=t.publication_info)==null?void 0:u.year)||"",r=((d=t.current_location)==null?void 0:d.name)||"",i=(p=t.page_count)!=null&&p.number?String(t.page_count.number):((h=t.page_count)==null?void 0:h.description)||"",l=typeof t.description=="object"&&t.description!==null&&t.description.text||"",s={id:t.id,title:t.title,type:t.type,author:n,dynasty:o,holder:r,pages:i,description:l,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};if(t.type==="work"){const y=t;if(Array.isArray(y.related_works)){const j=y.related_works.find(g=>g.relation==="part_of");j&&(s.parentWorkId=j.id,s.parentWorkName=j.title)}}if(t.type==="book"){const y=t;s.workId=y.work_id,Array.isArray(y.contained_in)&&y.contained_in.length>0&&(s.collectionId=(x=y.contained_in[0])==null?void 0:x.id)}return s}function Fo(t){const n={id:t.id,title:t.title,type:t.type,description:t.description?{text:t.description}:void 0,authors:t.author?[{name:t.author}]:void 0,publication_info:t.dynasty?{year:t.dynasty}:void 0,current_location:t.holder?{name:t.holder}:void 0,page_count:t.pages?{number:parseInt(t.pages)||0,description:t.pages}:void 0,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};return t.type==="work"&&t.parentWorkId&&(n.related_works=[{id:t.parentWorkId,title:t.parentWorkName||"",relation:"part_of"}]),t.type==="book"&&(n.work_id=t.workId,t.collectionId&&(n.contained_in=[{id:t.collectionId}])),n}const Mo=t=>{const{data:n,id:o,transport:r,mode:i="view",onModeChange:l,onChange:s,onSave:c,onDelete:a,onNavigate:u,renderLink:d,onAskAI:p,renderSectionActions:h,onDownloadResource:x,downloadStatuses:y,relations:j,onRelationsChange:g,headerExtra:I,className:m,style:v}=t;A();const[b,z]=f.useState(i),k=l?i:b;f.useEffect(()=>{i!==b&&z(i)},[i]);const w=f.useCallback(()=>{const $=k==="view"?"edit":"view";l?l($):z($)},[k,l]),[C,B]=f.useState(null);f.useEffect(()=>{o&&r&&r.getItem(o).then($=>{$&&B($)})},[o,r]);const R=n||C,E=f.useMemo(()=>R?an(R):null,[R]),H=l||!n?e.jsx("button",{onClick:w,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:k==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:k==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:k==="view"?"切换到编辑模式":"切换到查看模式",children:k==="view"?"✏️ 编辑":"👁 查看"}):null,_=e.jsxs(e.Fragment,{children:[H,I]});return!R&&!E?e.jsx(ge,{}):k==="view"?e.jsx(Ge,{data:R,transport:r,onNavigate:u?$=>u($):void 0,renderLink:d,headerExtra:_,className:m,style:v}):E?e.jsxs("div",{className:m,style:v,children:[_&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:_}),e.jsx(ln,{data:E,onChange:s||(()=>{}),onSave:c||(()=>{}),transport:r,onNavigate:u,showDelete:!!a,onDelete:a,onAskAI:p,renderSectionActions:h,onDownloadResource:x,downloadStatuses:y,relations:j,onRelationsChange:g})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},wt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],cn=({isOpen:t,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const[i,l]=f.useState(null),[s,c]=f.useState(""),[a,u]=f.useState("idle"),[d,p]=f.useState(""),h=f.useRef(null);f.useEffect(()=>{t&&(l(null),c(""),u("idle"),p(""))},[t]),f.useEffect(()=>{i&&setTimeout(()=>{var g;return(g=h.current)==null?void 0:g.focus()},100)},[i]),f.useEffect(()=>{if(a==="success"){const g=setTimeout(n,2e3);return()=>clearTimeout(g)}},[a,n]),f.useEffect(()=>{if(!t)return;const g=I=>{I.key==="Escape"&&n()};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[t,n]);const x=async()=>{if(!(!i||!s.trim())){u("submitting"),p("");try{await o({type:i,content:s.trim()}),u("success")}catch(g){u("error"),p(g instanceof Error?g.message:"提交失败,请稍后重试")}}};if(!t)return null;const y=i&&s.trim()&&a!=="submitting",j=wt.find(g=>g.value===i);return e.jsx("div",{style:Do,onClick:g=>{g.target===g.currentTarget&&n()},children:e.jsxs("div",{style:Ho,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:Oo,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:Uo,"aria-label":"关闭",children:"✕"})]}),a==="success"?e.jsxs("div",{style:Go,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&e.jsx("a",{href:r,style:{fontSize:"13px",color:"var(--bim-primary, #2563eb)",marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:wt.map(g=>e.jsxs("button",{onClick:()=>l(g.value),style:{...Vo,...i===g.value?Ko:{}},children:[e.jsx("span",{children:g.icon})," ",g.label]},g.value))}),e.jsx("textarea",{ref:h,value:s,onChange:g=>c(g.target.value),placeholder:(j==null?void 0:j.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!i||a==="submitting",style:{...No,opacity:i?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[s.length," / 2000"]}),a==="error"&&e.jsx("div",{style:qo,children:d}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:x,disabled:!y,style:{...Yo,opacity:y?1:.6,cursor:y?"pointer":"not-allowed"},children:a==="submitting"?"提交中...":"提交反馈"})})]})]})})},Do={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},Ho={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)"},Oo={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Uo={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},Vo={flex:1,padding:"10px 12px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Ko={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},No={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"},Yo={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Go={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},qo={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},Jo=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:o})=>{const[r,i]=f.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>i(!0),style:{...Zo,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(cn,{isOpen:r,onClose:()=>i(!1),onSubmit:t,feedbackListUrl:o})]})},Zo={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"},Ct=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Xo=({onSubmit:t})=>{const[n,o]=f.useState("bug"),[r,i]=f.useState(""),[l,s]=f.useState("idle"),[c,a]=f.useState(""),u=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var x;return(x=u.current)==null?void 0:x.focus()},100)},[n]);const d=async()=>{if(!(!n||!r.trim())){s("submitting"),a("");try{await t({type:n,content:r.trim()}),s("success"),i(""),o("bug")}catch(x){s("error"),a(x instanceof Error?x.message:"提交失败,请稍后重试")}}},p=n&&r.trim()&&l!=="submitting",h=Ct.find(x=>x.value===n);return l==="success"?e.jsx("div",{style:_t,children:e.jsxs("div",{style:ri,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>s("idle"),style:oi,children:"继续提交"})]})}):e.jsxs("div",{style:_t,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:Ct.map(x=>e.jsxs("button",{onClick:()=>o(x.value),style:{...Qo,...n===x.value?ei:{}},children:[e.jsx("span",{children:x.icon})," ",x.label]},x.value))}),e.jsx("textarea",{ref:u,value:r,onChange:x=>i(x.target.value),placeholder:(h==null?void 0:h.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:l==="submitting",style:{...ti}}),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:d,disabled:!p,style:{...ni,opacity:p?1:.6,cursor:p?"pointer":"not-allowed"},children:l==="submitting"?"提交中...":"提交"})]}),l==="error"&&e.jsx("div",{style:ii,children:c})]})},_t={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},Qo={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"},ei={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},ti={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"},ni={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},ri={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},oi={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},ii={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"},li=({style:t})=>{const n=f.useContext(ze);if(!n)return null;const{locale:o,setLocale:r}=n,i=o==="zh-Hant",l=()=>r(i?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:l,title:i?"切换为简体":"切換為繁體",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:i?"var(--bim-primary, #0078d4)":void 0,fontWeight:i?700:400},children:"繁"}),e.jsx("span",{style:{opacity:.3},children:"/"}),e.jsx("span",{style:{color:i?void 0:"var(--bim-primary, #0078d4)",fontWeight:i?400:700},children:"简"})]})};exports.BidLink=O.BidLink;exports.BookIndexError=O.BookIndexError;exports.BookIndexManager=O.BookIndexManager;exports.BookIndexStorage=O.BookIndexStorage;exports.BundleStorage=O.BundleStorage;exports.ConfigError=O.ConfigError;exports.GithubStorage=O.GithubStorage;exports.IdGenerationError=O.IdGenerationError;exports.IdGenerator=O.IdGenerator;exports.LocalStorage=O.LocalStorage;exports.MigrationError=O.MigrationError;exports.StorageError=O.StorageError;exports.base36Decode=O.base36Decode;exports.base36Encode=O.base36Encode;exports.base58Decode=O.base58Decode;exports.buildId=O.buildId;exports.decodeId=O.decodeId;exports.decodeIdString=O.decodeIdString;exports.encodeId=O.encodeId;exports.extractIdFromUrl=O.extractIdFromUrl;exports.extractStatus=O.extractStatus;exports.extractType=O.extractType;exports.normalizeCatalog=O.normalizeCatalog;exports.parseId=O.parseId;exports.smartDecode=O.smartDecode;exports.validateResource=O.validateResource;exports.Badge=We;exports.BidUrlProvider=yn;exports.CollatedEdition=Gt;exports.CollectionCatalog=Dt;exports.CreateEntityDialog=nn;exports.EmendatedBySection=Ft;exports.EntityDetail=Bt;exports.EntityPickerDialog=on;exports.EntitySelector=tn;exports.FeedbackButton=Jo;exports.FeedbackDialog=cn;exports.FeedbackForm=Xo;exports.FeedbackList=qt;exports.FormInput=ee;exports.FormTextArea=fe;exports.HomePage=Ke;exports.IndexApp=no;exports.IndexBrowser=Ve;exports.IndexDetail=Ge;exports.IndexEditor=ln;exports.IndexView=Mo;exports.LocaleContext=ze;exports.LocaleProvider=Cn;exports.LocaleToggle=li;exports.ModeIndicator=Lt;exports.RelationPanel=Qt;exports.ResourceEditor=Ue;exports.ResourceList=Ye;exports.SearchInput=Et;exports.Section=oe;exports.SmartBidInput=Be;exports.SourceEditor=Jt;exports.WorkCatalog=ro;exports.detailToEditor=an;exports.editorToDetail=Fo;exports.formatTemplate=Ie;exports.parseSourceString=Zt;exports.stringifySources=Xt;exports.useBidUrl=re;exports.useConvert=D;exports.useT=A;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { e as Lt, a as en } from "./storage-entry-CQvuThmT.js";
2
- import { B as hr, b as xr, c as br, d as mr, f as yr, C as vr, G as kr, I as Sr, g as wr, L as _r, M as zr, S as Cr, h as Ir, i as Tr, j as Rr, k as Lr, l as Br, m as Wr, n as Er, o as $r, p as Ar, q as Pr, s as Hr, v as Dr } from "./storage-entry-CQvuThmT.js";
1
+ import { e as Lt, a as en } from "./storage-entry-BiThJ6BH.js";
2
+ import { B as hr, b as xr, c as br, d as mr, f as yr, C as vr, G as kr, I as Sr, g as wr, L as _r, M as zr, S as Cr, h as Ir, i as Tr, j as Rr, k as Lr, l as Br, m as Wr, n as Er, o as $r, p as Ar, q as Pr, s as Hr, v as Dr } from "./storage-entry-BiThJ6BH.js";
3
3
  import { jsx as t, jsxs as r, Fragment as j } from "react/jsx-runtime";
4
4
  import Bt, { createContext as Wt, useMemo as ae, useContext as Pe, useState as k, useEffect as H, useCallback as F, useRef as Q } from "react";
5
5
  import { createPortal as tn } from "react-dom";
@@ -1 +1 @@
1
- "use strict";var lt=Object.create;var K=Object.defineProperty;var ht=Object.getOwnPropertyDescriptor;var ut=Object.getOwnPropertyNames;var dt=Object.getPrototypeOf,ft=Object.prototype.hasOwnProperty;var yt=(r,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of ut(t))!ft.call(r,n)&&n!==e&&K(r,n,{get:()=>t[n],enumerable:!(s=ht(t,n))||s.enumerable});return r};var X=(r,t,e)=>(e=r!=null?lt(dt(r)):{},yt(t||!r||!r.__esModule?K(e,"default",{value:r,enumerable:!0}):e,r));const gt={official:0,draft:1},pt={0:"official",1:"draft"},mt={book:0,collection:2,work:3,entity:4},_t={0:"book",2:"collection",3:"work",4:"entity"},tt=62n,et=59n,st=19n,nt=8n,ot=(1n<<40n)-1n,wt=(1n<<3n)-1n,bt=(1n<<11n)-1n,kt=(1n<<8n)-1n,M="0123456789abcdefghijklmnopqrstuvwxyz",it=new Map;for(let r=0;r<M.length;r++)it.set(M[r],BigInt(r));function F(r){if(r===0n)return M[0];let t="";for(;r>0n;)t=M[Number(r%36n)]+t,r=r/36n;return t}function z(r){let t=0n;for(const e of r){const s=it.get(e);if(s===void 0)throw new Error(`Invalid Base36 character: ${e}`);t=t*36n+s}return t}const V="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",rt=new Map;for(let r=0;r<V.length;r++)rt.set(V[r],BigInt(r));function at(r){let t=0n;for(const e of r){const s=rt.get(e);if(s===void 0)throw new Error(`Invalid Base58 character: ${e}`);t=t*58n+s}return t}function k(r){return/[A-Z]/.test(r)?at(r):z(r)}const It=F,St=z;function v(r){const t=Number(r>>tt&1n),e=Number(r>>et&wt),s=r>>st&ot,n=Number(r>>nt&bt),o=Number(r&kt);return{status:pt[t]??"draft",type:_t[e]??"book",timestamp:s,machineId:n,sequence:o}}function N(r,t,e,s,n){return BigInt(gt[r])<<tt|BigInt(mt[t])<<et|(e&ot)<<st|BigInt(s)<<nt|BigInt(n)}function A(r){return v(k(r))}function xt(r){return A(r).type}function Et(r){return A(r).status}const U={book:"Book",collection:"Collection",work:"Work",entity:"Entity"},vt={Book:"book",Collection:"collection",Work:"work",Entity:"entity"},B=16;function L(r,t=B){let e=0;for(let s=0;s<r.length;s++)e=Math.imul(e,31)+r.charCodeAt(s)>>>0;return e%t}function b(...r){const t=r.join("/");return t.startsWith("//")?"//"+t.slice(2).replace(/\/+/g,"/"):t.replace(/\/+/g,"/")}function Ct(r){return r.replace(/[^\u4e00-\u9fa5a-zA-Z0-9]/g,"")||"Undefined"}class H{constructor(t,e){this.fs=t,this.officialRoot=b(e,"book-index"),this.draftRoot=b(e,"book-index-draft")}getRootByStatus(t){return t==="draft"?this.draftRoot:this.officialRoot}getRootById(t){const e=k(t),s=v(e);return this.getRootByStatus(s.status)}getPath(t,e,s){const n=this.getRootById(e),o=e.padEnd(3,"_").substring(0,3),[i,c,l]=[o[0],o[1],o[2]],a=U[t];return b(n,a,i,c,l,`${e}-${Ct(s)}.json`)}async saveItem(t,e,s){const n=s.title||s.书名||"未命名",o=s.edition||"",i=o?`${n}${o}`:n,c=this.getPath(t,e,i),l=await this.findFileById(e);if(l&&l!==c)try{await this.fs.deleteFile(l)}catch{}const a=c.substring(0,c.lastIndexOf("/"));await this.fs.mkdir(a),s.id=e,s.type=t,await this.fs.writeFile(c,JSON.stringify(s,$t,2));const u=this.getRootById(e),h=c.substring(u.length+1);return await this.updateIndexEntry(u,s,t,h),c}async updateIndexEntry(t,e,s,n){const o=e.id||"";if(!o)return;const i=`${s}s`,c=await this.loadShard(t,i,o);let l="";const a=e.authors;if(Array.isArray(a)&&a.length>0){const y=a[0];l=typeof y=="object"&&y!==null?y.name||"":String(y)}else typeof a=="string"&&(l=a);let u="";const h=e.publication_info;typeof h=="object"&&h!==null?u=h.year||"":typeof h=="string"&&(u=h);let d="";const f=e.current_location;typeof f=="object"&&f!==null?d=f.name||"":typeof f=="string"&&(d=f);const p=Array.isArray(e.additional_titles)?e.additional_titles.map(y=>typeof y=="string"?y:y==null?void 0:y.book_title).filter(Boolean):void 0,I=Array.isArray(e.attached_texts)?e.attached_texts.map(y=>typeof y=="string"?y:y==null?void 0:y.book_title).filter(Boolean):void 0;let x;const S=e.juan_count;typeof S=="number"?x=S:typeof S=="object"&&S!==null&&(x=S.number||void 0);const $=typeof e.measure_info=="string"?e.measure_info:"";let C=!1,E=!1;const j=e.resources;if(Array.isArray(j))for(const y of j){const m=typeof y=="object"&&y!==null?y.type:"";(m==="text"||m==="text+image")&&(C=!0),(m==="image"||m==="text+image")&&(E=!0)}const _={id:o,title:e.title||"未命名",type:U[s],path:n,author:l,year:u,holder:d};p&&p.length>0&&(_.additional_titles=p),I&&I.length>0&&(_.attached_texts=I),x&&(_.juan_count=x),$&&(_.measure_info=$);const P=typeof e.edition=="string"?e.edition:"";P&&(_.edition=P),C&&(_.has_text=!0),E&&(_.has_image=!0),c[o]=_,await this.saveShard(t,i,o,c)}async deleteItem(t){const e=await this.findFileById(t);if(!e)return!1;const s=k(t),n=v(s),o=this.getRootByStatus(n.status),i=`${n.type}s`,c=await this.loadShard(o,i,t);return c[t]&&(delete c[t],await this.saveShard(o,i,t,c)),await this.fs.deleteFile(e),!0}async findFileById(t){const e=t.padEnd(3,"_").substring(0,3),[s,n,o]=[e[0],e[1],e[2]];for(const i of[this.officialRoot,this.draftRoot])for(const c of["Book","Collection","Work"]){const l=b(i,c,s,n,o);if(await this.fs.exists(l))try{const u=(await this.fs.readdir(l)).find(h=>h.startsWith(`${t}-`)&&h.endsWith(".json"));if(u)return b(l,u)}catch{}}return null}async loadMetadata(t){try{const e=await this.fs.readFile(t);return JSON.parse(e)}catch{return{}}}async getItem(t){const e=await this.findFileById(t);if(!e)return null;const s=await this.loadMetadata(e);return Object.keys(s).length>0?s:null}async loadEntries(t,e){const s=e?[this.getRootByStatus(e)]:[this.officialRoot,this.draftRoot],n=[],o=`${t}s`;for(const i of s){const c=await this.loadAllShards(i,o);for(const[l,a]of Object.entries(c))n.push({id:l,title:a.title,type:t,author:a.author||void 0,dynasty:a.dynasty||void 0,role:a.role||void 0,path:b(i,a.path),additional_titles:a.additional_titles,attached_texts:a.attached_texts,edition:a.edition,juan_count:a.juan_count,has_text:a.has_text,has_image:a.has_image})}return n}async searchEntries(t,e,s){const n=await this.loadEntries(e,s);return R(n,t)}async searchAll(t,e=5,s){const n=["work","book","collection"],o=await Promise.all(n.map(i=>this.searchEntries(t,i,s)));return{works:o[0].slice(0,e),books:o[1].slice(0,e),collections:o[2].slice(0,e),totalWorks:o[0].length,totalBooks:o[1].length,totalCollections:o[2].length}}async rebuildIndex(t){var n,o;const e=this.getRootByStatus(t),s={books:Object.fromEntries(Array.from({length:B},(i,c)=>[c,{}])),collections:{0:{}},works:Object.fromEntries(Array.from({length:B},(i,c)=>[c,{}]))};for(const i of["Book","Collection","Work"]){const c=b(e,i);if(!await this.fs.exists(c))continue;const a=`${vt[i]}s`,u=await this.fs.glob(c,"**/*.json");for(const h of u)if(!h.includes("/index/"))try{const d=await this.loadMetadata(h);let f=d.id||d.ID||"";if(!f){const g=h.substring(h.lastIndexOf("/")+1);g.includes("-")&&(f=g.split("-")[0])}if(!f)continue;const p=h.substring(e.length+1);let I="";const x=d.authors;if(Array.isArray(x)&&x.length>0){const g=x[0];I=typeof g=="object"&&g!==null?g.name||"":String(g)}const S=Array.isArray(d.additional_titles)?d.additional_titles.map(g=>typeof g=="string"?g:g==null?void 0:g.book_title).filter(Boolean):void 0,$=Array.isArray(d.attached_texts)?d.attached_texts.map(g=>typeof g=="string"?g:g==null?void 0:g.book_title).filter(Boolean):void 0;let C;const E=d.juan_count;typeof E=="number"?C=E:typeof E=="object"&&E!==null&&(C=E.number||void 0);const j=typeof d.measure_info=="string"?d.measure_info:"";let _=!1,P=!1;const y=d.resources;if(Array.isArray(y))for(const g of y){const D=typeof g=="object"&&g!==null?g.type:"";(D==="text"||D==="text+image")&&(_=!0),(D==="image"||D==="text+image")&&(P=!0)}const m={id:f,title:d.title||"未命名",type:i,path:p,author:I,year:typeof d.publication_info=="object"&&((n=d.publication_info)==null?void 0:n.year)||"",holder:typeof d.current_location=="object"&&((o=d.current_location)==null?void 0:o.name)||""};S&&S.length>0&&(m.additional_titles=S),$&&$.length>0&&(m.attached_texts=$),C&&(m.juan_count=C),j&&(m.measure_info=j);const Y=typeof d.edition=="string"?d.edition:"";Y&&(m.edition=Y),_&&(m.has_text=!0),P&&(m.has_image=!0);const ct=a==="collections"?0:L(f);s[a][ct][f]=m}catch{}}for(const[i,c]of Object.entries(s))for(const[l,a]of Object.entries(c)){const u=this.shardPath(e,i,Number(l)),h=u.substring(0,u.lastIndexOf("/"));await this.fs.mkdir(h),await this.fs.writeFile(u,JSON.stringify(a,null,2))}}getAssetDir(t){const e=this.getRootById(t),s=k(t),o=v(s).type,i=t.padEnd(3,"_").substring(0,3),[c,l,a]=[i[0],i[1],i[2]],u=U[o];return b(e,u,c,l,a,t)}async initAssetDir(t){const e=this.getAssetDir(t);return await this.fs.mkdir(e),e}async hasAssetDir(t){const e=this.getAssetDir(t);return this.fs.exists(e)}shardPath(t,e,s){return e==="collections"?b(t,"index","collections.json"):b(t,"index",e,`${s.toString(16)}.json`)}async loadShard(t,e,s){const n=L(s),o=this.shardPath(t,e,n);try{if(!await this.fs.exists(o))return{};const i=await this.fs.readFile(o);return JSON.parse(i)}catch{return{}}}async saveShard(t,e,s,n){const o=L(s),i=this.shardPath(t,e,o),c=i.substring(0,i.lastIndexOf("/"));await this.fs.mkdir(c),await this.fs.writeFile(i,JSON.stringify(n,null,2))}async loadAllShards(t,e){const s={};if(e==="collections"){const n=this.shardPath(t,e,0);try{if(await this.fs.exists(n)){const o=await this.fs.readFile(n);Object.assign(s,JSON.parse(o))}}catch{}return s}for(let n=0;n<B;n++){const o=this.shardPath(t,e,n);try{if(await this.fs.exists(o)){const i=await this.fs.readFile(o);Object.assign(s,JSON.parse(i))}}catch{}}return s}}function W(r,t){const e=t.toLowerCase();let s=0;const n=r.title.toLowerCase();n===e?s=200:n.startsWith(e)?s=150:n.includes(e)&&(s=100);const o=[...r.additional_titles||[],...r.attached_texts||[]];for(const a of o){const u=a.toLowerCase();u===e?s=Math.max(s,120):u.startsWith(e)?s=Math.max(s,90):u.includes(e)&&(s=Math.max(s,60))}let i=0;if(r.author){const a=r.author.toLowerCase();a===e?i=80:a.includes(e)&&(i=50)}let c=0;r.dynasty&&r.dynasty.toLowerCase().includes(e)&&(c=30);let l=s;return l===0&&(l=Math.max(i,c)),l===0?0:(l+=Math.max(0,20-n.length),r.type==="work"?l=Math.round(l*1.05):r.type==="collection"&&(l=Math.round(l*1.02)),r.has_text&&(l+=3),r.has_image&&(l+=2),l)}function $t(r,t){return t===null?void 0:t}function R(r,t){const e=r.map(s=>({entry:s,score:W(s,t)})).filter(s=>s.score>0);return e.sort((s,n)=>n.score!==s.score?n.score-s.score:s.entry.title.length-n.entry.title.length),e.map(s=>s.entry)}function O(r,t,e,s){const n=r.map(o=>{const i=W(o,t);let c=0;const l=s[o.id];if(l&&e){const a={...o,title:l.t??o.title,author:l.a??o.author,additional_titles:l.at??o.additional_titles,attached_texts:l.axt??o.attached_texts};c=W(a,e)}return{entry:o,score:Math.max(i,c)}}).filter(o=>o.score>0);return n.sort((o,i)=>i.score!==o.score?i.score-o.score:o.entry.title.length-i.entry.title.length),n.map(o=>o.entry)}function At(r){const t=r.volumes??[];let e,s;if(t.length===0)e=[];else if(typeof t[0]=="number")e=t;else{s=[],e=[];for(const o of t){const i=o.volume;e.push(i);const c={};for(const[l,a]of Object.entries(o))l==="volume"||l==="status"||l==="file"||typeof a=="string"&&(l.includes("url")||l.includes("id"))&&(c[l]=a);s.push({volume:i,status:o.status,urls:Object.keys(c).length>0?c:void 0,file:o.file})}}const n={title:r.title??"",book_id:r.book_id??null,work_id:r.work_id??null,volumes:e,section:r.section,sub_items:r.sub_items,edition:r.edition,expected_volumes:r.expected_volumes,found_volumes:r.found_volumes,missing_volumes:r.missing_vols??r.missing_volumes};s&&(n.volume_details=s);for(const o of Object.keys(n))n[o]===void 0&&delete n[o];return n}function Tt(r){const t={total_books:r.total_books??0};return r.processed_volumes!=null&&(t.processed_volumes=r.processed_volumes),r.matched_works!=null&&(t.matched_works=r.matched_works),r.unmatched_works!=null&&(t.unmatched_works=r.unmatched_works),r.total_found_volumes!=null&&(t.total_found_volumes=r.total_found_volumes),t}function G(r){var n;const t=r,e=(t.books??[]).map(At),s={collection_id:t.collection_id??"",title:t.title??"",total_volumes:t.total_volumes??0,stats:Tt(t.stats??{}),books:e};return t.source&&(s.source=t.source),t.resource_id&&(s.resource_id=t.resource_id),t.resource_name&&(s.resource_name=t.resource_name),(n=t.sections)!=null&&n.length&&(s.sections=t.sections),t.volume_index&&Object.keys(t.volume_index).length>0&&(s.volume_index=t.volume_index),s}const jt="https://raw.githubusercontent.com",Pt=["https://fastly.jsdelivr.net/gh","https://cdn.jsdelivr.net/gh"],Bt=5e3;class Rt{constructor(t){this.cache=null,this.pathMap=new Map,this.searchSCache=null,this.t2sConverter=null,this.config={org:t.org,repos:t.repos,baseUrl:t.baseUrl??jt,cdnUrls:t.cdnUrls??Pt,timeout:t.timeout??Bt}}async ensureLoaded(){if(this.cache)return this.cache;const t=[];for(const s of[!0,!1])try{const n=s?this.config.repos.draft:this.config.repos.official,o=await this.fetchIndex(n),i=this.parseIndexResponse(o,s);t.push(...i)}catch(n){console.warn(`Failed to fetch ${s?"draft":"official"} index:`,n)}const e=new Map;for(const s of t)e.set(s.id,s);return this.cache=Array.from(e.values()),this.cache}async fetchFileWithFallback(t,e){const s=`${this.config.baseUrl}/${this.config.org}/${t}/main/${encodeURI(e)}`;try{return await this.fetchJson(s)}catch{}for(const n of this.config.cdnUrls){const o=`${n}/${this.config.org}/${t}@main/${encodeURI(e)}`;try{return await this.fetchJson(o)}catch{continue}}throw new Error(`Failed to fetch ${e} for ${t} from all sources`)}async probeIndex(t){const e="index/collections.json",s=`${this.config.baseUrl}/${this.config.org}/${t}/main/${encodeURI(e)}`;try{if((await fetch(s,{method:"HEAD",signal:AbortSignal.timeout(this.config.timeout)})).ok)return!0}catch{}for(const i of this.config.cdnUrls){const c=`${i}/${this.config.org}/${t}@main/${encodeURI(e)}`;try{if((await fetch(c,{method:"HEAD",signal:AbortSignal.timeout(this.config.timeout)})).ok)return!0}catch{continue}}const n="index/works/0.json",o=`${this.config.baseUrl}/${this.config.org}/${t}/main/${encodeURI(n)}`;try{if((await fetch(o,{method:"HEAD",signal:AbortSignal.timeout(this.config.timeout)})).ok)return!0}catch{}for(const i of this.config.cdnUrls){const c=`${i}/${this.config.org}/${t}@main/${encodeURI(n)}`;try{if((await fetch(c,{method:"HEAD",signal:AbortSignal.timeout(this.config.timeout)})).ok)return!0}catch{continue}}return!1}async fetchIndex(t){if(!await this.probeIndex(t))return{books:{},collections:{},works:{}};const s={books:{},collections:{},works:{}};try{const o=await this.fetchFileWithFallback(t,"index/collections.json");s.collections=o}catch{}const n=[];for(const o of["books","works"])for(let i=0;i<B;i++){const c=`index/${o}/${i.toString(16)}.json`;n.push(this.fetchFileWithFallback(t,c).then(l=>{Object.assign(s[o],l)}).catch(()=>{}))}return await Promise.all(n),s}async fetchJson(t){const e=await fetch(t,{cache:"no-store",signal:AbortSignal.timeout(this.config.timeout)});if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`);return e.json()}parseIndexResponse(t,e){var o,i;const s=[],n=[["books","book"],["collections","collection"],["works","work"],["entities","entity"]];for(const[c,l]of n){const a=t[c];if(a)for(const u of Object.values(a)){const h=u,d=l==="entity"?h.primary_name||u.title||u.name||u.id:u.title||u.name||u.id;s.push({id:u.id,title:d,type:l,isDraft:e,author:u.author,dynasty:u.dynasty,role:u.role,path:u.path,additional_titles:(o=h.additional_titles)==null?void 0:o.map(f=>typeof f=="string"?f:f==null?void 0:f.book_title).filter(Boolean),attached_texts:(i=h.attached_texts)==null?void 0:i.map(f=>typeof f=="string"?f:f==null?void 0:f.book_title).filter(Boolean),edition:h.edition,juan_count:h.juan_count,has_text:h.has_text,has_image:h.has_image,has_collated:h.has_collated,subtype:h.subtype,primary_name:h.primary_name,birth_year:h.birth_year,death_year:h.death_year,cbdb_id:h.cbdb_id}),this.pathMap.set(u.id,{path:u.path,isDraft:e})}}return s}async ensureSearchSBuilt(){var n,o;if(this.searchSCache)return{searchS:this.searchSCache,converter:this.t2sConverter||null};if(this.t2sConverter===!1)return{searchS:{},converter:null};try{const i=await import("opencc-js");this.t2sConverter=i.Converter({from:"tw",to:"cn"})}catch{return this.t2sConverter=!1,this.searchSCache={},{searchS:{},converter:null}}const t=await this.ensureLoaded(),e=this.t2sConverter,s={};for(const i of t){const c={},l=e(i.title);if(l!==i.title&&(c.t=l),i.author){const a=e(i.author);a!==i.author&&(c.a=a)}if((n=i.additional_titles)!=null&&n.length){const a=i.additional_titles.map(e);a.some((u,h)=>u!==i.additional_titles[h])&&(c.at=a)}if((o=i.attached_texts)!=null&&o.length){const a=i.attached_texts.map(e);a.some((u,h)=>u!==i.attached_texts[h])&&(c.axt=a)}Object.keys(c).length>0&&(s[i.id]=c)}return this.searchSCache=s,{searchS:s,converter:e}}async loadEntries(t,e){let n=(await this.ensureLoaded()).filter(h=>h.type===t);const o=e.sortBy||"title",i=e.sortOrder||"asc";n.sort((h,d)=>{const f=String(h[o]??""),p=String(d[o]??""),I=f.localeCompare(p,"zh");return i==="asc"?I:-I});const c=e.page||1,l=e.pageSize||50,a=(c-1)*l;return{entries:n.slice(a,a+l),total:n.length,page:c,pageSize:l}}async search(t,e,s){const n=await this.ensureLoaded(),{searchS:o,converter:i}=await this.ensureSearchSBuilt(),c=n.filter(p=>p.type===e),l=i?i(t):void 0,u=Object.keys(o).length>0?O(c,t,l,o):R(c,t),h=s.page||1,d=s.pageSize||50,f=(h-1)*d;return{entries:u.slice(f,f+d),total:u.length,page:h,pageSize:d}}async searchAll(t,e=5){const s=await this.ensureLoaded(),{searchS:n,converter:o}=await this.ensureSearchSBuilt(),i=["work","book","collection"],c=o?o(t):void 0,l=Object.keys(n).length>0,a=i.map(u=>{const h=s.filter(d=>d.type===u);return l?O(h,t,c,n):R(h,t)});return{works:a[0].slice(0,e),books:a[1].slice(0,e),collections:a[2].slice(0,e),totalWorks:a[0].length,totalBooks:a[1].length,totalCollections:a[2].length}}async getItem(t){const e=await this.ensureLoaded(),s=this.pathMap.get(t);let n=null;if(s){const o=s.isDraft?this.config.repos.draft:this.config.repos.official;if(n=await this.fetchItemByPath(o,s.path),n){const i=e.find(c=>c.id===t);i!=null&&i.has_collated&&(n.has_collated=!0)}}else n=await this.findItemById(t);return n&&n.type==="entity"&&!n.title&&n.primary_name&&(n.title=n.primary_name),n}async getEntry(t){const s=(await this.ensureLoaded()).find(o=>o.id===t);if(s)return s;const n=await this.findItemById(t);return n?this.buildEntryFromItem(t,n):null}async getAllEntries(){return this.ensureLoaded()}async saveItem(){throw new Error("GithubStorage 为只读模式,不支持保存")}async deleteItem(){throw new Error("GithubStorage 为只读模式,不支持删除")}async generateId(){throw new Error("GithubStorage 为只读模式,不支持生成 ID")}async fetchItemByPath(t,e){let s=null;const n=`${this.config.baseUrl}/${this.config.org}/${t}/main/${encodeURI(e)}`;try{s=await this.fetchJson(n)}catch{}if(!s)for(const o of this.config.cdnUrls){const i=`${o}/${this.config.org}/${t}@main/${encodeURI(e)}`;try{s=await this.fetchJson(i);break}catch{continue}}return s}async findItemById(t){const e={book:"Book",collection:"Collection",work:"Work",entity:"Entity"};let s,n;try{const u=v(k(t));s=u.type,n=u.status}catch{return null}const o=n==="draft"?this.config.repos.draft:this.config.repos.official,i=e[s],c=t.padEnd(3,"_").substring(0,3),l=`${i}/${c[0]}/${c[1]}/${c[2]}`,a=`https://api.github.com/repos/${this.config.org}/${o}/contents/${l}`;try{const u=await fetch(a,{signal:AbortSignal.timeout(this.config.timeout)});if(!u.ok)return null;const d=(await u.json()).find(p=>p.name.startsWith(`${t}-`)&&p.name.endsWith(".json"));if(!d)return null;const f=await this.fetchItemByPath(o,d.path);return f&&this.pathMap.set(t,{path:d.path,isDraft:n==="draft"}),f}catch{return null}}buildEntryFromItem(t,e){const s=(e.type||"").toLowerCase(),n=s==="work"?"work":s==="collection"?"collection":"book";let o;const i=e.authors;if(Array.isArray(i)&&i.length>0){const a=i[0];o=typeof a=="object"&&a!==null?a.name||"":String(a)}let c=!0;try{c=v(k(t)).status==="draft"}catch{}const l=this.pathMap.get(t);return{id:t,title:e.title||e.书名||t,type:n,isDraft:c,author:o,dynasty:e.dynasty,role:e.role,path:(l==null?void 0:l.path)||"",juan_count:e.n_juan,has_collated:e.has_collated}}async fetchFile(t,e){const s=`${this.config.baseUrl}/${this.config.org}/${t}/main/${encodeURI(e)}`;try{return await this.fetchJson(s)}catch{}for(const n of this.config.cdnUrls){const o=`${n}/${this.config.org}/${t}@main/${encodeURI(e)}`;try{return await this.fetchJson(o)}catch{continue}}return null}async resolveItemPath(t){await this.ensureLoaded();let e=this.pathMap.get(t);if(!e&&(await this.findItemById(t),e=this.pathMap.get(t),!e))return null;const s=e.isDraft?this.config.repos.draft:this.config.repos.official,n=e.path.substring(0,e.path.lastIndexOf("/"));return{repo:s,dir:n}}async getCollectionCatalogs(t){const e=await this.resolveItemPath(t);if(!e)return null;const s=await this.getItem(t);if(!s)return null;const n=s.resources||[];if(n.length===0)return null;const o=[];for(const i of n){const c=`${e.dir}/${t}/${i.id}/volume_book_mapping.json`,l=await this.fetchFile(e.repo,c);l&&o.push({resource_id:i.id,short_name:i.short_name,data:G(l)})}return o.length>0?o:null}async getCollectionCatalog(t){var s;const e=await this.getCollectionCatalogs(t);return((s=e==null?void 0:e[0])==null?void 0:s.data)??null}async getCollatedEditionIndex(t){const e=await this.resolveItemPath(t);if(!e)return null;const s=`${e.dir}/${t}/collated_edition_index.json`;return this.fetchFile(e.repo,s)}async getCollatedJuan(t,e){if(e.includes("..")||!e.endsWith(".json"))return null;const s=await this.resolveItemPath(t);if(!s)return null;const n=`${s.dir}/${t}/collated_edition/${e}`;return this.fetchFile(s.repo,n)}async getResourceProgress(){return this.fetchFile(this.config.repos.draft,"resource.json")}async getSiteProgress(){return this.fetchFile(this.config.repos.draft,"resource-site.json")}async getRecommended(){return this.fetchFile(this.config.repos.draft,"recommended.json")}clearCache(){this.cache=null,this.pathMap.clear(),this.searchSCache=null,this.t2sConverter=null}}const Q=255;class q{constructor(t){if(this.lastTimestamp=-1,this.lastStatus=null,this.sequence=0,t<0||t>2047)throw new Error("Machine ID must be between 0 and 2047");this.machineId=t}nextId(t,e){let s=this._getCurrentTimestamp(t);if(s<this.lastTimestamp&&t===this.lastStatus)throw new Error("Clock moved backwards. Refusing to generate ID.");s===this.lastTimestamp&&t===this.lastStatus?(this.sequence=this.sequence+1&Q,this.sequence===0&&(s=this._tilNextUnit(this.lastTimestamp,t))):this.sequence=0,this.lastTimestamp=s,this.lastStatus=t;const n=N(t,e,BigInt(s),this.machineId,this.sequence);return F(n)}nextIdRaw(t,e){let s=this._getCurrentTimestamp(t);if(s<this.lastTimestamp&&t===this.lastStatus)throw new Error("Clock moved backwards. Refusing to generate ID.");return s===this.lastTimestamp&&t===this.lastStatus?(this.sequence=this.sequence+1&Q,this.sequence===0&&(s=this._tilNextUnit(this.lastTimestamp,t))):this.sequence=0,this.lastTimestamp=s,this.lastStatus=t,N(t,e,BigInt(s),this.machineId,this.sequence)}_getCurrentTimestamp(t){const e=Date.now();return t==="draft"?e:Math.floor(e/1e3)}_tilNextUnit(t,e){let s=this._getCurrentTimestamp(e);for(;s<=t;)s=this._getCurrentTimestamp(e);return s}}class Ft{constructor(t){this.recentEntities=[],this.storage=new H(t.fs,t.workspaceRoot),this.idGen=new q(t.machineId??0),this.fs=t.fs,this.workspaceRoot=t.workspaceRoot}async loadEntries(t,e){const s=await this.storage.loadEntries(t);return this.paginate(s,e)}async search(t,e,s){const n=await this.storage.searchEntries(t,e);return this.paginate(n,s)}async searchAll(t,e){return this.storage.searchAll(t,e)}async getItem(t){const e=await this.storage.getItem(t);return e&&e.type==="entity"&&!e.title&&e.primary_name&&(e.title=e.primary_name),e}async saveItem(t){const e=t.id;if(!e)throw new Error("metadata.id is required");const s=t.type||this.extractTypeFromId(e),n=await this.storage.saveItem(s,e,t);return{id:e,path:n}}async deleteItem(t){if(!await this.storage.deleteItem(t))throw new Error(`Item not found: ${t}`)}async generateId(t,e){return this.idGen.nextId(e,t)}async getEntry(t){const e=await this.storage.getItem(t);if(!e)return null;const s=e.type||this.extractTypeFromId(t);return{id:t,title:e.title||"未命名",type:s,author:this.extractAuthor(e),dynasty:this.extractYear(e)}}async getAllEntries(){const t=["book","collection","work"],e=[];for(const s of t){const n=await this.storage.loadEntries(s);e.push(...n)}return e}async getRelations(t){const e=await this.storage.getItem(t);if(!e)return null;const s={},n=e.type||this.extractTypeFromId(t);if(n==="book"){if(e.work_id){const o=await this.resolveEntity(e.work_id);o&&(s.belongsToWork={...o,type:"work"})}if(e.contained_in&&Array.isArray(e.contained_in)&&e.contained_in.length>0){const o=e.contained_in[0],i=typeof o=="string"?o:o.id;if(i){const c=await this.resolveEntity(i);c&&(s.belongsToCollection={...c,type:"collection"})}}}else if(n==="collection"){if(e.books&&Array.isArray(e.books)){const o=await Promise.all(e.books.map(i=>this.resolveEntity(i)));s.containedBooks=o.filter(i=>i!==null).map(i=>({...i,type:"book"}))}}else if(n==="work"){if(e.parent_work&&typeof e.parent_work=="object"){const o=e.parent_work;s.parentWork={id:o.id,title:o.title,type:"work"}}if(e.books&&Array.isArray(e.books)){const o=await Promise.all(e.books.map(i=>this.resolveEntity(i)));s.containedBooks=o.filter(i=>i!==null).map(i=>({...i,type:"book"}))}}return s}async linkEntity(t,e,s){const n=await this.storage.getItem(t);if(!n)throw new Error(`Source not found: ${t}`);const o=n.type||this.extractTypeFromId(t);switch(e){case"belongsToWork":case"work_id":n.work_id=s;break;case"belongsToCollection":case"contained_in":Array.isArray(n.contained_in)||(n.contained_in=[]);{const i=n.contained_in;i.some(l=>(typeof l=="string"?l:l.id)===s)||i.push({id:s})}break;case"parentWork":case"parent_work":{const i=await this.storage.getItem(s);n.parent_work={id:s,title:(i==null?void 0:i.title)||""};break}case"containedBooks":case"books":Array.isArray(n.books)||(n.books=[]),n.books.includes(s)||n.books.push(s);break;default:throw new Error(`Unknown relation field: ${e}`)}await this.storage.saveItem(o,t,n)}async unlinkEntity(t,e){const s=await this.storage.getItem(t);if(!s)throw new Error(`Source not found: ${t}`);const n=s.type||this.extractTypeFromId(t);switch(e){case"belongsToWork":case"work_id":delete s.work_id;break;case"belongsToCollection":case"contained_in":s.contained_in=[];break;case"parentWork":case"parent_work":delete s.parent_work;break;case"containedBooks":case"books":s.books=[];break;default:throw new Error(`Unknown relation field: ${e}`)}await this.storage.saveItem(n,t,s)}async createAndLink(t,e,s){const n=this.idGen.nextId("draft",s.type),o={id:n,type:s.type,title:s.title,...s.inheritData||{}};return await this.storage.saveItem(s.type,n,o),await this.linkEntity(t,e,n),{id:n}}async searchEntities(t,e){const s=e&&e!=="all"?[e]:["book","collection","work"],n=[];for(const o of s){const i=await this.storage.searchEntries(t,o);for(const c of i)n.push({id:c.id,title:c.title,type:c.type,author:c.author,dynasty:c.dynasty})}return n}async getRecentEntities(){return this.recentEntities}async addRecentEntity(t){this.recentEntities=[t,...this.recentEntities.filter(e=>e.id!==t.id)].slice(0,20)}async getCollectionCatalog(t){const e=await this.storage.findFileById(t);if(!e)return null;const n=e.substring(0,e.lastIndexOf("/"))+"/volume_book_mapping.json";try{const o=await this.storage.loadMetadata(n);return Object.keys(o).length===0?null:o}catch{return null}}async getRecommended(){const t=this.workspaceRoot+"/book-index-draft/recommended.json";try{const e=await this.fs.readFile(t);return JSON.parse(e)}catch{return null}}getAssetDir(t){return this.storage.getAssetDir(t)}async initAssetDir(t){return this.storage.initAssetDir(t)}async hasAssetDir(t){return this.storage.hasAssetDir(t)}getBookIndexStorage(){return this.storage}async rebuildIndex(t){await this.storage.rebuildIndex(t)}extractTypeFromId(t){try{const e=k(t);return v(e).type}catch{return"book"}}extractAuthor(t){const e=t.authors;if(Array.isArray(e)&&e.length>0){const s=e[0];return typeof s=="object"&&s!==null?s.name||"":String(s)}}extractYear(t){const e=t.publication_info;if(typeof e=="object"&&e!==null)return e.year||void 0}async resolveEntity(t){const e=await this.storage.getItem(t);return e?{id:t,title:e.title||"未命名"}:null}paginate(t,e){const s=e.page??1,n=e.pageSize??50;if(e.sortBy){const l=e.sortBy,a=e.sortOrder==="desc"?-1:1;t.sort((u,h)=>{const d=u[l]??"",f=h[l]??"";return d<f?-a:d>f?a:0})}const o=t.length,i=(s-1)*n;return{entries:t.slice(i,i+n),total:o,page:s,pageSize:n}}}const Dt="/data",Mt=1e4;class Ot{constructor(t={}){this.indexCache=null,this.pathMap=new Map,this.chunkCache=new Map,this.manifest=null,this.tiyaoCache=new Map,this.searchSCache=null,this.searchSLoaded=!1,this.t2sConverter=null,this.basePath=t.basePath??Dt,this.timeout=t.timeout??Mt}async fetchJson(t){const e=await fetch(t,{signal:AbortSignal.timeout(this.timeout)});if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`);return e.json()}async ensureLoaded(){var n,o;if(this.indexCache)return this.indexCache;const t=await this.fetchJson(`${this.basePath}/index.json`),e=[],s=[["books","book"],["collections","collection"],["works","work"],["entities","entity"]];for(const[i,c]of s){const l=t[i];if(l)for(const a of Object.values(l)){const u=c==="entity"?a.primary_name||a.title||a.name||a.id:a.title||a.name||a.id;e.push({id:a.id,title:u,type:c,isDraft:!0,author:a.author,dynasty:a.dynasty,role:a.role,path:a.path,additional_titles:(n=a.additional_titles)==null?void 0:n.map(h=>typeof h=="string"?h:h==null?void 0:h.book_title).filter(Boolean),attached_texts:(o=a.attached_texts)==null?void 0:o.map(h=>typeof h=="string"?h:h==null?void 0:h.book_title).filter(Boolean),edition:a.edition,juan_count:a.juan_count,has_text:a.has_text,has_image:a.has_image,has_collated:a.has_collated,subtype:a.subtype,primary_name:a.primary_name,birth_year:a.birth_year,death_year:a.death_year,cbdb_id:a.cbdb_id}),this.pathMap.set(a.id,{path:a.path,isDraft:!0})}}return this.indexCache=e,e}async ensureSearchSLoaded(){if(this.searchSLoaded)return this.searchSCache??{};this.searchSLoaded=!0;try{this.searchSCache=await this.fetchJson(`${this.basePath}/search_s.json`)}catch{this.searchSCache={}}return this.searchSCache}async ensureT2S(){if(this.t2sConverter===!1)return null;if(this.t2sConverter)return this.t2sConverter;try{const t=await import("opencc-js");return this.t2sConverter=t.Converter({from:"tw",to:"cn"}),this.t2sConverter}catch{return this.t2sConverter=!1,null}}async loadManifest(){if(this.manifest)return this.manifest;try{this.manifest=await this.fetchJson(`${this.basePath}/chunks/_manifest.json`)}catch{this.manifest=[]}return this.manifest}async resolvePrefix(t){const e=await this.loadManifest();let s=0,n=e.length-1,o=null;for(;s<=n;){const i=s+n>>1;e[i]<=t?(o=e[i],s=i+1):n=i-1}if(o&&t.startsWith(o))return o;for(const i of e)if(t.startsWith(i))return i;return null}async loadChunk(t){if(this.chunkCache.has(t))return this.chunkCache.get(t);try{const e=await this.fetchJson(`${this.basePath}/chunks/${t}.json`);return this.chunkCache.set(t,e),e}catch{return this.chunkCache.set(t,{}),{}}}async loadChunkForId(t){const e=await this.resolvePrefix(t);return e?this.loadChunk(e):{}}async loadTiyaoGroup(t,e){const s=`${t}-${e}`;if(this.tiyaoCache.has(s))return this.tiyaoCache.get(s);const n=i=>String(i).padStart(3,"0"),o=await this.fetchJson(`${this.basePath}/tiyao/juan-${n(t)}-${n(e)}.json`);return this.tiyaoCache.set(s,o),o}async getResourceCounts(){const t=await this.ensureLoaded();let e=0,s=0;for(const n of t)n.type==="work"&&(n.has_text&&e++,n.has_image&&s++);return{hasText:e,hasImage:s}}async loadEntries(t,e){let n=(await this.ensureLoaded()).filter(u=>u.type===t);const o=e.sortBy||"title",i=e.sortOrder||"asc";n.sort((u,h)=>{const d=String(u[o]??""),f=String(h[o]??""),p=d.localeCompare(f,"zh");return i==="asc"?p:-p});const c=e.page||1,l=e.pageSize||50,a=(c-1)*l;return{entries:n.slice(a,a+l),total:n.length,page:c,pageSize:l}}async search(t,e,s){const n=await this.ensureLoaded(),o=await this.ensureSearchSLoaded(),i=await this.ensureT2S(),c=n.filter(p=>p.type===e),l=i?i(t):void 0,u=Object.keys(o).length>0?O(c,t,l,o):R(c,t),h=s.page||1,d=s.pageSize||50,f=(h-1)*d;return{entries:u.slice(f,f+d),total:u.length,page:h,pageSize:d}}async searchAll(t,e=5){const s=await this.ensureLoaded(),n=await this.ensureSearchSLoaded(),o=await this.ensureT2S(),i=["work","book","collection","entity"],c=o?o(t):void 0,l=Object.keys(n).length>0,a=i.map(u=>{const h=s.filter(d=>d.type===u);return l?O(h,t,c,n):R(h,t)});return{works:a[0].slice(0,e),books:a[1].slice(0,e),collections:a[2].slice(0,e),entities:a[3].slice(0,e),totalWorks:a[0].length,totalBooks:a[1].length,totalCollections:a[2].length,totalEntities:a[3].length}}async getItem(t){try{const s=(await this.loadChunkForId(t))[t]||null;if(s){const n=(await this.ensureLoaded()).find(o=>o.id===t);n!=null&&n.has_collated&&(s.has_collated=!0),s.type==="entity"&&!s.title&&s.primary_name&&(s.title=s.primary_name)}return s}catch{return null}}async getEntry(t){return(await this.ensureLoaded()).find(s=>s.id===t)||null}async getAllEntries(){return this.ensureLoaded()}async saveItem(){throw new Error("BundleStorage 为只读模式,不支持保存")}async deleteItem(){throw new Error("BundleStorage 为只读模式,不支持删除")}async generateId(){throw new Error("BundleStorage 为只读模式,不支持生成 ID")}async getCollectionCatalogs(t){const e=await this.getItem(t);if(!e)return null;const s=e.resources||[];if(s.length===0)return null;const n=[];for(const o of s)try{const i=await this.fetchJson(`${this.basePath}/items/${t}/${o.id}/volume_book_mapping.json`);i&&n.push({resource_id:o.id,short_name:o.short_name,data:G(i)})}catch{}return n.length>0?n:null}async getCollectionCatalog(t){var s;const e=await this.getCollectionCatalogs(t);return((s=e==null?void 0:e[0])==null?void 0:s.data)??null}async getCollatedEditionIndex(t){try{return await this.fetchJson(`${this.basePath}/items/${t}/collated_edition_index.json`)}catch{return null}}async getCollatedJuan(t,e){if(e.includes("..")||!e.endsWith(".json"))return null;try{return await this.fetchJson(`${this.basePath}/items/${t}/collated_edition/${e}`)}catch{return null}}async getCollatedJuanText(t,e){if(e.includes("..")||!e.endsWith(".json"))return null;const s=e.replace(/\.json$/,".md");try{const n=await fetch(`${this.basePath}/items/${t}/collated_edition/text/${s}`);return n.ok?await n.text():null}catch{return null}}async getResourceProgress(){try{return await this.fetchJson(`${this.basePath}/resource.json`)}catch{return null}}async getSiteProgress(){try{return await this.fetchJson(`${this.basePath}/resource-site.json`)}catch{return null}}async getRecommended(){try{return await this.fetchJson(`${this.basePath}/recommended.json`)}catch{return null}}clearCache(){this.indexCache=null,this.pathMap.clear(),this.chunkCache.clear(),this.manifest=null,this.tiyaoCache.clear(),this.searchSCache=null,this.searchSLoaded=!1,this.t2sConverter=null}}class T extends Error{constructor(t){super(t),this.name="BookIndexError"}}class Ut extends T{constructor(t){super(t),this.name="StorageError"}}class Lt extends T{constructor(t){super(t),this.name="IdGenerationError"}}class Nt extends T{constructor(t){super(t),this.name="ConfigError"}}class Wt extends T{constructor(t){super(t),this.name="MigrationError"}}class Jt{constructor(t,e,s=1){this.storage=new H(t,e),this.idGen=new q(s)}generateId(t="book",e="draft"){return this.idGen.nextIdRaw(e,t)}encodeId(t){return F(t)}decodeId(t){return k(t)}async saveItem(t,e,s="draft"){let n=t.id||t.ID;if(n)try{const i=A(n);e||(e=i.type)}catch{throw new T(`Invalid ID format: ${n}`)}else e||(e=t.type||"book"),n=this.idGen.nextId(s,e),t.id=n;return await this.storage.saveItem(e,n,t)}async getItem(t){return this.storage.getItem(t)}async findItemPath(t){return this.storage.findFileById(t)}async updateField(t,e,s){const n=await this.storage.findFileById(t);if(!n)return!1;try{const o=await this.storage.loadMetadata(n),i={基本信息:null,介绍:"description",资源:"resources",收藏历史:"history",其他版本:"related_books"},c=e in i?i[e]:e;if(c===null)return!1;if(c==="description"&&typeof s=="string"){const a=o[c]||{};o[c]={text:s,sources:a.sources||[]}}else o[c]=s;const l=A(t);return await this.storage.saveItem(l.type,t,o),!0}catch{return!1}}async deleteItem(t){return this.storage.deleteItem(t)}async rebuildIndices(){await this.storage.rebuildIndex("official"),await this.storage.rebuildIndex("draft")}getAssetDir(t){return this.storage.getAssetDir(t)}async initAssetDir(t){return this.storage.initAssetDir(t)}async hasAssetDir(t){return this.storage.hasAssetDir(t)}getStorage(){return this.storage}}const zt={wikisource:"wikisource",shidianguji:"shidianguji",archive:"archive",ctext:"ctext",nlc:"nlc","read.nlc":"nlc","db.sido":"sido","guji.artx":"guji-artx","digital.library":"digital-library"},Z=new Set(["text","image","text+image","physical"]),Ht=new Set(["catalog","search"]),Gt=new Set(["com","org","net","cn","edu","gov","io","jp","tw","hk"]);function qt(r){if(!r)return"";try{const e=new URL(r).hostname;for(const[n,o]of Object.entries(zt))if(e.includes(n))return o;const s=e.split(".");if(s.length>=2){const n=s.filter(o=>!Gt.has(o)&&o.length>2);return n.length>0?n[n.length-1]:s[s.length-2]}return e}catch{return""}}function Yt(r){const t=[];return r.name||t.push("name is required"),Z.has(r.type)||t.push(`invalid type '${r.type}', must be one of ${[...Z].join(", ")}`),r.root_type&&!Ht.has(r.root_type)&&t.push(`invalid root_type '${r.root_type}'`),r.type!=="physical"&&!r.url&&t.push("url is required for non-physical resources"),t}const w=class w{constructor(t,e=""){if(this._type=null,this.title=e,typeof t=="string"){t.startsWith(w.PREFIX)&&(t=t.slice(w.PREFIX.length)),this.idStr=t;try{this.idInt=k(t)}catch{this.idInt=0n}}else this.idInt=t,this.idStr=F(t);if(this.idInt>0n)try{const s=A(this.idStr);this._type=s.type}catch{}}get type(){return this._type}getIcon(){return this._type===null?"":this._type==="book"?"📖 ":this._type==="collection"?"📚 ":this._type==="work"?"📜 ":""}render(t=!1){return`[${t?this.getIcon():""}${this.title}](${w.PREFIX}${this.idStr})`}static parseFromLink(t){const e=t.match(/\[(.*?)\]\((.*?)\)/);if(e){const s=e[1],n=e[2];if(n.startsWith(w.PREFIX)){const o=n.slice(w.PREFIX.length);return new w(o,s)}}return null}static isBidLink(t){return t.startsWith(w.PREFIX)}};w.PROTOCOL="bid:\\\\",w.PREFIX="bid:\\\\";let J=w;exports.BidLink=J;exports.BookIndexError=T;exports.BookIndexManager=Jt;exports.BookIndexStorage=H;exports.BundleStorage=Ot;exports.ConfigError=Nt;exports.GithubStorage=Rt;exports.IdGenerationError=Lt;exports.IdGenerator=q;exports.LocalStorage=Ft;exports.MigrationError=Wt;exports.StorageError=Ut;exports.base36Decode=z;exports.base36Encode=F;exports.base58Decode=at;exports.buildId=N;exports.decodeId=St;exports.decodeIdString=A;exports.encodeId=It;exports.extractIdFromUrl=qt;exports.extractStatus=Et;exports.extractType=xt;exports.normalizeCatalog=G;exports.parseId=v;exports.smartDecode=k;exports.validateResource=Yt;
1
+ "use strict";var lt=Object.create;var K=Object.defineProperty;var ht=Object.getOwnPropertyDescriptor;var ut=Object.getOwnPropertyNames;var dt=Object.getPrototypeOf,ft=Object.prototype.hasOwnProperty;var yt=(r,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of ut(t))!ft.call(r,n)&&n!==e&&K(r,n,{get:()=>t[n],enumerable:!(s=ht(t,n))||s.enumerable});return r};var X=(r,t,e)=>(e=r!=null?lt(dt(r)):{},yt(t||!r||!r.__esModule?K(e,"default",{value:r,enumerable:!0}):e,r));const gt={official:0,draft:1},pt={0:"official",1:"draft"},mt={book:0,collection:2,work:3,entity:4},_t={0:"book",2:"collection",3:"work",4:"entity"},tt=62n,et=59n,st=19n,nt=8n,ot=(1n<<40n)-1n,wt=(1n<<3n)-1n,bt=(1n<<11n)-1n,kt=(1n<<8n)-1n,M="0123456789abcdefghijklmnopqrstuvwxyz",it=new Map;for(let r=0;r<M.length;r++)it.set(M[r],BigInt(r));function F(r){if(r===0n)return M[0];let t="";for(;r>0n;)t=M[Number(r%36n)]+t,r=r/36n;return t}function z(r){let t=0n;for(const e of r){const s=it.get(e);if(s===void 0)throw new Error(`Invalid Base36 character: ${e}`);t=t*36n+s}return t}const V="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",rt=new Map;for(let r=0;r<V.length;r++)rt.set(V[r],BigInt(r));function at(r){let t=0n;for(const e of r){const s=rt.get(e);if(s===void 0)throw new Error(`Invalid Base58 character: ${e}`);t=t*58n+s}return t}function k(r){return/[A-Z]/.test(r)?at(r):z(r)}const It=F,St=z;function v(r){const t=Number(r>>tt&1n),e=Number(r>>et&wt),s=r>>st&ot,n=Number(r>>nt&bt),o=Number(r&kt);return{status:pt[t]??"draft",type:_t[e]??"book",timestamp:s,machineId:n,sequence:o}}function N(r,t,e,s,n){return BigInt(gt[r])<<tt|BigInt(mt[t])<<et|(e&ot)<<st|BigInt(s)<<nt|BigInt(n)}function A(r){return v(k(r))}function xt(r){return A(r).type}function Et(r){return A(r).status}const U={book:"Book",collection:"Collection",work:"Work",entity:"Entity"},vt={Book:"book",Collection:"collection",Work:"work",Entity:"entity"},B=16;function L(r,t=B){let e=0;for(let s=0;s<r.length;s++)e=Math.imul(e,31)+r.charCodeAt(s)>>>0;return e%t}function b(...r){const t=r.join("/");return t.startsWith("//")?"//"+t.slice(2).replace(/\/+/g,"/"):t.replace(/\/+/g,"/")}function Ct(r){return r.replace(/[^\u4e00-\u9fa5a-zA-Z0-9]/g,"")||"Undefined"}class H{constructor(t,e){this.fs=t,this.officialRoot=b(e,"book-index"),this.draftRoot=b(e,"book-index-draft")}getRootByStatus(t){return t==="draft"?this.draftRoot:this.officialRoot}getRootById(t){const e=k(t),s=v(e);return this.getRootByStatus(s.status)}getPath(t,e,s){const n=this.getRootById(e),o=e.padEnd(3,"_").substring(0,3),[i,c,l]=[o[0],o[1],o[2]],a=U[t];return b(n,a,i,c,l,`${e}-${Ct(s)}.json`)}async saveItem(t,e,s){const n=s.title||s.书名||"未命名",o=s.edition||"",i=o?`${n}${o}`:n,c=this.getPath(t,e,i),l=await this.findFileById(e);if(l&&l!==c)try{await this.fs.deleteFile(l)}catch{}const a=c.substring(0,c.lastIndexOf("/"));await this.fs.mkdir(a),s.id=e,s.type=t,await this.fs.writeFile(c,JSON.stringify(s,$t,2));const u=this.getRootById(e),h=c.substring(u.length+1);return await this.updateIndexEntry(u,s,t,h),c}async updateIndexEntry(t,e,s,n){const o=e.id||"";if(!o)return;const i=`${s}s`,c=await this.loadShard(t,i,o);let l="";const a=e.authors;if(Array.isArray(a)&&a.length>0){const y=a[0];l=typeof y=="object"&&y!==null?y.name||"":String(y)}else typeof a=="string"&&(l=a);let u="";const h=e.publication_info;typeof h=="object"&&h!==null?u=h.year||"":typeof h=="string"&&(u=h);let d="";const f=e.current_location;typeof f=="object"&&f!==null?d=f.name||"":typeof f=="string"&&(d=f);const p=Array.isArray(e.additional_titles)?e.additional_titles.map(y=>typeof y=="string"?y:y==null?void 0:y.book_title).filter(Boolean):void 0,I=Array.isArray(e.attached_texts)?e.attached_texts.map(y=>typeof y=="string"?y:y==null?void 0:y.book_title).filter(Boolean):void 0;let x;const S=e.juan_count;typeof S=="number"?x=S:typeof S=="object"&&S!==null&&(x=S.number||void 0);const $=typeof e.measure_info=="string"?e.measure_info:"";let C=!1,E=!1;const j=e.resources;if(Array.isArray(j))for(const y of j){const m=typeof y=="object"&&y!==null?y.type:"";(m==="text"||m==="text+image")&&(C=!0),(m==="image"||m==="text+image")&&(E=!0)}const _={id:o,title:e.title||"未命名",type:U[s],path:n,author:l,year:u,holder:d};p&&p.length>0&&(_.additional_titles=p),I&&I.length>0&&(_.attached_texts=I),x&&(_.juan_count=x),$&&(_.measure_info=$);const P=typeof e.edition=="string"?e.edition:"";P&&(_.edition=P),C&&(_.has_text=!0),E&&(_.has_image=!0),c[o]=_,await this.saveShard(t,i,o,c)}async deleteItem(t){const e=await this.findFileById(t);if(!e)return!1;const s=k(t),n=v(s),o=this.getRootByStatus(n.status),i=`${n.type}s`,c=await this.loadShard(o,i,t);return c[t]&&(delete c[t],await this.saveShard(o,i,t,c)),await this.fs.deleteFile(e),!0}async findFileById(t){const e=t.padEnd(3,"_").substring(0,3),[s,n,o]=[e[0],e[1],e[2]];for(const i of[this.officialRoot,this.draftRoot])for(const c of["Book","Collection","Work"]){const l=b(i,c,s,n,o);if(await this.fs.exists(l))try{const u=(await this.fs.readdir(l)).find(h=>h.startsWith(`${t}-`)&&h.endsWith(".json"));if(u)return b(l,u)}catch{}}return null}async loadMetadata(t){try{const e=await this.fs.readFile(t);return JSON.parse(e)}catch{return{}}}async getItem(t){const e=await this.findFileById(t);if(!e)return null;const s=await this.loadMetadata(e);return Object.keys(s).length>0?s:null}async loadEntries(t,e){const s=e?[this.getRootByStatus(e)]:[this.officialRoot,this.draftRoot],n=[],o=`${t}s`;for(const i of s){const c=await this.loadAllShards(i,o);for(const[l,a]of Object.entries(c))n.push({id:l,title:a.title,type:t,author:a.author||void 0,dynasty:a.dynasty||void 0,role:a.role||void 0,path:b(i,a.path),additional_titles:a.additional_titles,attached_texts:a.attached_texts,edition:a.edition,juan_count:a.juan_count,has_text:a.has_text,has_image:a.has_image})}return n}async searchEntries(t,e,s){const n=await this.loadEntries(e,s);return R(n,t)}async searchAll(t,e=5,s){const n=["work","book","collection"],o=await Promise.all(n.map(i=>this.searchEntries(t,i,s)));return{works:o[0].slice(0,e),books:o[1].slice(0,e),collections:o[2].slice(0,e),totalWorks:o[0].length,totalBooks:o[1].length,totalCollections:o[2].length}}async rebuildIndex(t){var n,o;const e=this.getRootByStatus(t),s={books:Object.fromEntries(Array.from({length:B},(i,c)=>[c,{}])),collections:{0:{}},works:Object.fromEntries(Array.from({length:B},(i,c)=>[c,{}]))};for(const i of["Book","Collection","Work"]){const c=b(e,i);if(!await this.fs.exists(c))continue;const a=`${vt[i]}s`,u=await this.fs.glob(c,"**/*.json");for(const h of u)if(!h.includes("/index/"))try{const d=await this.loadMetadata(h);let f=d.id||d.ID||"";if(!f){const g=h.substring(h.lastIndexOf("/")+1);g.includes("-")&&(f=g.split("-")[0])}if(!f)continue;const p=h.substring(e.length+1);let I="";const x=d.authors;if(Array.isArray(x)&&x.length>0){const g=x[0];I=typeof g=="object"&&g!==null?g.name||"":String(g)}const S=Array.isArray(d.additional_titles)?d.additional_titles.map(g=>typeof g=="string"?g:g==null?void 0:g.book_title).filter(Boolean):void 0,$=Array.isArray(d.attached_texts)?d.attached_texts.map(g=>typeof g=="string"?g:g==null?void 0:g.book_title).filter(Boolean):void 0;let C;const E=d.juan_count;typeof E=="number"?C=E:typeof E=="object"&&E!==null&&(C=E.number||void 0);const j=typeof d.measure_info=="string"?d.measure_info:"";let _=!1,P=!1;const y=d.resources;if(Array.isArray(y))for(const g of y){const D=typeof g=="object"&&g!==null?g.type:"";(D==="text"||D==="text+image")&&(_=!0),(D==="image"||D==="text+image")&&(P=!0)}const m={id:f,title:d.title||"未命名",type:i,path:p,author:I,year:typeof d.publication_info=="object"&&((n=d.publication_info)==null?void 0:n.year)||"",holder:typeof d.current_location=="object"&&((o=d.current_location)==null?void 0:o.name)||""};S&&S.length>0&&(m.additional_titles=S),$&&$.length>0&&(m.attached_texts=$),C&&(m.juan_count=C),j&&(m.measure_info=j);const Y=typeof d.edition=="string"?d.edition:"";Y&&(m.edition=Y),_&&(m.has_text=!0),P&&(m.has_image=!0);const ct=a==="collections"?0:L(f);s[a][ct][f]=m}catch{}}for(const[i,c]of Object.entries(s))for(const[l,a]of Object.entries(c)){const u=this.shardPath(e,i,Number(l)),h=u.substring(0,u.lastIndexOf("/"));await this.fs.mkdir(h),await this.fs.writeFile(u,JSON.stringify(a,null,2))}}getAssetDir(t){const e=this.getRootById(t),s=k(t),o=v(s).type,i=t.padEnd(3,"_").substring(0,3),[c,l,a]=[i[0],i[1],i[2]],u=U[o];return b(e,u,c,l,a,t)}async initAssetDir(t){const e=this.getAssetDir(t);return await this.fs.mkdir(e),e}async hasAssetDir(t){const e=this.getAssetDir(t);return this.fs.exists(e)}shardPath(t,e,s){return e==="collections"?b(t,"index","collections.json"):b(t,"index",e,`${s.toString(16)}.json`)}async loadShard(t,e,s){const n=L(s),o=this.shardPath(t,e,n);try{if(!await this.fs.exists(o))return{};const i=await this.fs.readFile(o);return JSON.parse(i)}catch{return{}}}async saveShard(t,e,s,n){const o=L(s),i=this.shardPath(t,e,o),c=i.substring(0,i.lastIndexOf("/"));await this.fs.mkdir(c),await this.fs.writeFile(i,JSON.stringify(n,null,2))}async loadAllShards(t,e){const s={};if(e==="collections"){const n=this.shardPath(t,e,0);try{if(await this.fs.exists(n)){const o=await this.fs.readFile(n);Object.assign(s,JSON.parse(o))}}catch{}return s}for(let n=0;n<B;n++){const o=this.shardPath(t,e,n);try{if(await this.fs.exists(o)){const i=await this.fs.readFile(o);Object.assign(s,JSON.parse(i))}}catch{}}return s}}function W(r,t){const e=t.toLowerCase();let s=0;const n=r.title.toLowerCase();n===e?s=200:n.startsWith(e)?s=150:n.includes(e)&&(s=100);const o=[...r.additional_titles||[],...r.attached_texts||[]];for(const a of o){const u=a.toLowerCase();u===e?s=Math.max(s,120):u.startsWith(e)?s=Math.max(s,90):u.includes(e)&&(s=Math.max(s,60))}let i=0;if(r.author){const a=r.author.toLowerCase();a===e?i=80:a.includes(e)&&(i=50)}let c=0;r.dynasty&&r.dynasty.toLowerCase().includes(e)&&(c=30);let l=s;return l===0&&(l=Math.max(i,c)),l===0?0:(l+=Math.max(0,20-n.length),r.type==="work"?l=Math.round(l*1.05):r.type==="collection"&&(l=Math.round(l*1.02)),r.has_text&&(l+=3),r.has_image&&(l+=2),l)}function $t(r,t){return t===null?void 0:t}function R(r,t){const e=r.map(s=>({entry:s,score:W(s,t)})).filter(s=>s.score>0);return e.sort((s,n)=>n.score!==s.score?n.score-s.score:s.entry.title.length-n.entry.title.length),e.map(s=>s.entry)}function O(r,t,e,s){const n=r.map(o=>{const i=W(o,t);let c=0;const l=s[o.id];if(l&&e){const a={...o,title:l.t??o.title,author:l.a??o.author,additional_titles:l.at??o.additional_titles,attached_texts:l.axt??o.attached_texts};c=W(a,e)}return{entry:o,score:Math.max(i,c)}}).filter(o=>o.score>0);return n.sort((o,i)=>i.score!==o.score?i.score-o.score:o.entry.title.length-i.entry.title.length),n.map(o=>o.entry)}function At(r){const t=r.volumes??[];let e,s;if(t.length===0)e=[];else if(typeof t[0]=="number")e=t;else{s=[],e=[];for(const o of t){const i=o.volume;e.push(i);const c={};for(const[l,a]of Object.entries(o))l==="volume"||l==="status"||l==="file"||typeof a=="string"&&(l.includes("url")||l.includes("id"))&&(c[l]=a);s.push({volume:i,status:o.status,urls:Object.keys(c).length>0?c:void 0,file:o.file})}}const n={title:r.title??"",book_id:r.book_id??null,work_id:r.work_id??null,volumes:e,section:r.section,sub_items:r.sub_items,edition:r.edition,expected_volumes:r.expected_volumes,found_volumes:r.found_volumes,missing_volumes:r.missing_vols??r.missing_volumes};s&&(n.volume_details=s);for(const o of Object.keys(n))n[o]===void 0&&delete n[o];return n}function Tt(r){const t={total_books:r.total_books??0};return r.processed_volumes!=null&&(t.processed_volumes=r.processed_volumes),r.matched_works!=null&&(t.matched_works=r.matched_works),r.unmatched_works!=null&&(t.unmatched_works=r.unmatched_works),r.total_found_volumes!=null&&(t.total_found_volumes=r.total_found_volumes),t}function G(r){var n;const t=r,e=(t.books??[]).map(At),s={collection_id:t.collection_id??"",title:t.title??"",total_volumes:t.total_volumes??0,stats:Tt(t.stats??{}),books:e};return t.source&&(s.source=t.source),t.resource_id&&(s.resource_id=t.resource_id),t.resource_name&&(s.resource_name=t.resource_name),(n=t.sections)!=null&&n.length&&(s.sections=t.sections),t.volume_index&&Object.keys(t.volume_index).length>0&&(s.volume_index=t.volume_index),s}const jt="https://raw.githubusercontent.com",Pt=["https://fastly.jsdelivr.net/gh","https://cdn.jsdelivr.net/gh"],Bt=5e3;class Rt{constructor(t){this.cache=null,this.pathMap=new Map,this.searchSCache=null,this.t2sConverter=null,this.config={org:t.org,repos:t.repos,baseUrl:t.baseUrl??jt,cdnUrls:t.cdnUrls??Pt,timeout:t.timeout??Bt}}async ensureLoaded(){if(this.cache)return this.cache;const t=[];for(const s of[!0,!1])try{const n=s?this.config.repos.draft:this.config.repos.official,o=await this.fetchIndex(n),i=this.parseIndexResponse(o,s);t.push(...i)}catch(n){console.warn(`Failed to fetch ${s?"draft":"official"} index:`,n)}const e=new Map;for(const s of t)e.set(s.id,s);return this.cache=Array.from(e.values()),this.cache}async fetchFileWithFallback(t,e){const s=`${this.config.baseUrl}/${this.config.org}/${t}/main/${encodeURI(e)}`;try{return await this.fetchJson(s)}catch{}for(const n of this.config.cdnUrls){const o=`${n}/${this.config.org}/${t}@main/${encodeURI(e)}`;try{return await this.fetchJson(o)}catch{continue}}throw new Error(`Failed to fetch ${e} for ${t} from all sources`)}async probeIndex(t){const e="index/collections.json",s=`${this.config.baseUrl}/${this.config.org}/${t}/main/${encodeURI(e)}`;try{if((await fetch(s,{method:"HEAD",signal:AbortSignal.timeout(this.config.timeout)})).ok)return!0}catch{}for(const i of this.config.cdnUrls){const c=`${i}/${this.config.org}/${t}@main/${encodeURI(e)}`;try{if((await fetch(c,{method:"HEAD",signal:AbortSignal.timeout(this.config.timeout)})).ok)return!0}catch{continue}}const n="index/works/0.json",o=`${this.config.baseUrl}/${this.config.org}/${t}/main/${encodeURI(n)}`;try{if((await fetch(o,{method:"HEAD",signal:AbortSignal.timeout(this.config.timeout)})).ok)return!0}catch{}for(const i of this.config.cdnUrls){const c=`${i}/${this.config.org}/${t}@main/${encodeURI(n)}`;try{if((await fetch(c,{method:"HEAD",signal:AbortSignal.timeout(this.config.timeout)})).ok)return!0}catch{continue}}return!1}async fetchIndex(t){if(!await this.probeIndex(t))return{books:{},collections:{},works:{}};const s={books:{},collections:{},works:{}};try{const o=await this.fetchFileWithFallback(t,"index/collections.json");s.collections=o}catch{}const n=[];for(const o of["books","works"])for(let i=0;i<B;i++){const c=`index/${o}/${i.toString(16)}.json`;n.push(this.fetchFileWithFallback(t,c).then(l=>{Object.assign(s[o],l)}).catch(()=>{}))}return await Promise.all(n),s}async fetchJson(t){const e=await fetch(t,{cache:"no-store",signal:AbortSignal.timeout(this.config.timeout)});if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`);return e.json()}parseIndexResponse(t,e){var o,i;const s=[],n=[["books","book"],["collections","collection"],["works","work"],["entities","entity"]];for(const[c,l]of n){const a=t[c];if(a)for(const u of Object.values(a)){const h=u,d=l==="entity"?h.primary_name||u.title||u.name||u.id:u.title||u.name||u.id;s.push({id:u.id,title:d,type:l,isDraft:e,author:u.author,dynasty:u.dynasty,role:u.role,path:u.path,additional_titles:(o=h.additional_titles)==null?void 0:o.map(f=>typeof f=="string"?f:f==null?void 0:f.book_title).filter(Boolean),attached_texts:(i=h.attached_texts)==null?void 0:i.map(f=>typeof f=="string"?f:f==null?void 0:f.book_title).filter(Boolean),edition:h.edition,juan_count:h.juan_count,has_text:h.has_text,has_image:h.has_image,has_collated:h.has_collated,subtype:h.subtype,primary_name:h.primary_name,birth_year:h.birth_year,death_year:h.death_year,cbdb_id:h.cbdb_id}),this.pathMap.set(u.id,{path:u.path,isDraft:e})}}return s}async ensureSearchSBuilt(){var n,o;if(this.searchSCache)return{searchS:this.searchSCache,converter:this.t2sConverter||null};if(this.t2sConverter===!1)return{searchS:{},converter:null};try{const i=await import("opencc-js");this.t2sConverter=i.Converter({from:"tw",to:"cn"})}catch{return this.t2sConverter=!1,this.searchSCache={},{searchS:{},converter:null}}const t=await this.ensureLoaded(),e=this.t2sConverter,s={};for(const i of t){const c={},l=e(i.title);if(l!==i.title&&(c.t=l),i.author){const a=e(i.author);a!==i.author&&(c.a=a)}if((n=i.additional_titles)!=null&&n.length){const a=i.additional_titles.map(e);a.some((u,h)=>u!==i.additional_titles[h])&&(c.at=a)}if((o=i.attached_texts)!=null&&o.length){const a=i.attached_texts.map(e);a.some((u,h)=>u!==i.attached_texts[h])&&(c.axt=a)}Object.keys(c).length>0&&(s[i.id]=c)}return this.searchSCache=s,{searchS:s,converter:e}}async loadEntries(t,e){let n=(await this.ensureLoaded()).filter(h=>h.type===t);const o=e.sortBy||"title",i=e.sortOrder||"asc";n.sort((h,d)=>{const f=String(h[o]??""),p=String(d[o]??""),I=f.localeCompare(p,"zh");return i==="asc"?I:-I});const c=e.page||1,l=e.pageSize||50,a=(c-1)*l;return{entries:n.slice(a,a+l),total:n.length,page:c,pageSize:l}}async search(t,e,s){const n=await this.ensureLoaded(),{searchS:o,converter:i}=await this.ensureSearchSBuilt(),c=n.filter(p=>p.type===e),l=i?i(t):void 0,u=Object.keys(o).length>0?O(c,t,l,o):R(c,t),h=s.page||1,d=s.pageSize||50,f=(h-1)*d;return{entries:u.slice(f,f+d),total:u.length,page:h,pageSize:d}}async searchAll(t,e=5){const s=await this.ensureLoaded(),{searchS:n,converter:o}=await this.ensureSearchSBuilt(),i=["work","book","collection"],c=o?o(t):void 0,l=Object.keys(n).length>0,a=i.map(u=>{const h=s.filter(d=>d.type===u);return l?O(h,t,c,n):R(h,t)});return{works:a[0].slice(0,e),books:a[1].slice(0,e),collections:a[2].slice(0,e),totalWorks:a[0].length,totalBooks:a[1].length,totalCollections:a[2].length}}async getItem(t){const e=await this.ensureLoaded(),s=this.pathMap.get(t);let n=null;if(s){const o=s.isDraft?this.config.repos.draft:this.config.repos.official;if(n=await this.fetchItemByPath(o,s.path),n){const i=e.find(c=>c.id===t);i!=null&&i.has_collated&&(n.has_collated=!0)}}else n=await this.findItemById(t);return n&&n.type==="entity"&&!n.title&&n.primary_name&&(n.title=n.primary_name),n}async getEntry(t){const s=(await this.ensureLoaded()).find(o=>o.id===t);if(s)return s;const n=await this.findItemById(t);return n?this.buildEntryFromItem(t,n):null}async getAllEntries(){return this.ensureLoaded()}async saveItem(){throw new Error("GithubStorage 为只读模式,不支持保存")}async deleteItem(){throw new Error("GithubStorage 为只读模式,不支持删除")}async generateId(){throw new Error("GithubStorage 为只读模式,不支持生成 ID")}async fetchItemByPath(t,e){let s=null;const n=`${this.config.baseUrl}/${this.config.org}/${t}/main/${encodeURI(e)}`;try{s=await this.fetchJson(n)}catch{}if(!s)for(const o of this.config.cdnUrls){const i=`${o}/${this.config.org}/${t}@main/${encodeURI(e)}`;try{s=await this.fetchJson(i);break}catch{continue}}return s}async findItemById(t){const e={book:"Book",collection:"Collection",work:"Work",entity:"Entity"};let s,n;try{const u=v(k(t));s=u.type,n=u.status}catch{return null}const o=n==="draft"?this.config.repos.draft:this.config.repos.official,i=e[s],c=t.padEnd(3,"_").substring(0,3),l=`${i}/${c[0]}/${c[1]}/${c[2]}`,a=`https://api.github.com/repos/${this.config.org}/${o}/contents/${l}`;try{const u=await fetch(a,{signal:AbortSignal.timeout(this.config.timeout)});if(!u.ok)return null;const d=(await u.json()).find(p=>p.name.startsWith(`${t}-`)&&p.name.endsWith(".json"));if(!d)return null;const f=await this.fetchItemByPath(o,d.path);return f&&this.pathMap.set(t,{path:d.path,isDraft:n==="draft"}),f}catch{return null}}buildEntryFromItem(t,e){const s=(e.type||"").toLowerCase(),n=s==="work"?"work":s==="collection"?"collection":"book";let o;const i=e.authors;if(Array.isArray(i)&&i.length>0){const a=i[0];o=typeof a=="object"&&a!==null?a.name||"":String(a)}let c=!0;try{c=v(k(t)).status==="draft"}catch{}const l=this.pathMap.get(t);return{id:t,title:e.title||e.书名||t,type:n,isDraft:c,author:o,dynasty:e.dynasty,role:e.role,path:(l==null?void 0:l.path)||"",juan_count:e.n_juan,has_collated:e.has_collated}}async fetchFile(t,e){const s=`${this.config.baseUrl}/${this.config.org}/${t}/main/${encodeURI(e)}`;try{return await this.fetchJson(s)}catch{}for(const n of this.config.cdnUrls){const o=`${n}/${this.config.org}/${t}@main/${encodeURI(e)}`;try{return await this.fetchJson(o)}catch{continue}}return null}async resolveItemPath(t){await this.ensureLoaded();let e=this.pathMap.get(t);if(!e&&(await this.findItemById(t),e=this.pathMap.get(t),!e))return null;const s=e.isDraft?this.config.repos.draft:this.config.repos.official,n=e.path.substring(0,e.path.lastIndexOf("/"));return{repo:s,dir:n}}async getCollectionCatalogs(t){const e=await this.resolveItemPath(t);if(!e)return null;const s=await this.getItem(t);if(!s)return null;const n=s.resources||[];if(n.length===0)return null;const o=[];for(const i of n){const c=`${e.dir}/${t}/${i.id}/volume_book_mapping.json`,l=await this.fetchFile(e.repo,c);l&&o.push({resource_id:i.id,short_name:i.short_name,data:G(l)})}return o.length>0?o:null}async getCollectionCatalog(t){var s;const e=await this.getCollectionCatalogs(t);return((s=e==null?void 0:e[0])==null?void 0:s.data)??null}async getCollatedEditionIndex(t){const e=await this.resolveItemPath(t);if(!e)return null;const s=`${e.dir}/${t}/collated_edition/collated_edition_index.json`;return this.fetchFile(e.repo,s)}async getCollatedJuan(t,e){if(e.includes("..")||!e.endsWith(".json"))return null;const s=await this.resolveItemPath(t);if(!s)return null;const n=`${s.dir}/${t}/collated_edition/${e}`;return this.fetchFile(s.repo,n)}async getResourceProgress(){return this.fetchFile(this.config.repos.draft,"resource.json")}async getSiteProgress(){return this.fetchFile(this.config.repos.draft,"resource-site.json")}async getRecommended(){return this.fetchFile(this.config.repos.draft,"recommended.json")}clearCache(){this.cache=null,this.pathMap.clear(),this.searchSCache=null,this.t2sConverter=null}}const Q=255;class q{constructor(t){if(this.lastTimestamp=-1,this.lastStatus=null,this.sequence=0,t<0||t>2047)throw new Error("Machine ID must be between 0 and 2047");this.machineId=t}nextId(t,e){let s=this._getCurrentTimestamp(t);if(s<this.lastTimestamp&&t===this.lastStatus)throw new Error("Clock moved backwards. Refusing to generate ID.");s===this.lastTimestamp&&t===this.lastStatus?(this.sequence=this.sequence+1&Q,this.sequence===0&&(s=this._tilNextUnit(this.lastTimestamp,t))):this.sequence=0,this.lastTimestamp=s,this.lastStatus=t;const n=N(t,e,BigInt(s),this.machineId,this.sequence);return F(n)}nextIdRaw(t,e){let s=this._getCurrentTimestamp(t);if(s<this.lastTimestamp&&t===this.lastStatus)throw new Error("Clock moved backwards. Refusing to generate ID.");return s===this.lastTimestamp&&t===this.lastStatus?(this.sequence=this.sequence+1&Q,this.sequence===0&&(s=this._tilNextUnit(this.lastTimestamp,t))):this.sequence=0,this.lastTimestamp=s,this.lastStatus=t,N(t,e,BigInt(s),this.machineId,this.sequence)}_getCurrentTimestamp(t){const e=Date.now();return t==="draft"?e:Math.floor(e/1e3)}_tilNextUnit(t,e){let s=this._getCurrentTimestamp(e);for(;s<=t;)s=this._getCurrentTimestamp(e);return s}}class Ft{constructor(t){this.recentEntities=[],this.storage=new H(t.fs,t.workspaceRoot),this.idGen=new q(t.machineId??0),this.fs=t.fs,this.workspaceRoot=t.workspaceRoot}async loadEntries(t,e){const s=await this.storage.loadEntries(t);return this.paginate(s,e)}async search(t,e,s){const n=await this.storage.searchEntries(t,e);return this.paginate(n,s)}async searchAll(t,e){return this.storage.searchAll(t,e)}async getItem(t){const e=await this.storage.getItem(t);return e&&e.type==="entity"&&!e.title&&e.primary_name&&(e.title=e.primary_name),e}async saveItem(t){const e=t.id;if(!e)throw new Error("metadata.id is required");const s=t.type||this.extractTypeFromId(e),n=await this.storage.saveItem(s,e,t);return{id:e,path:n}}async deleteItem(t){if(!await this.storage.deleteItem(t))throw new Error(`Item not found: ${t}`)}async generateId(t,e){return this.idGen.nextId(e,t)}async getEntry(t){const e=await this.storage.getItem(t);if(!e)return null;const s=e.type||this.extractTypeFromId(t);return{id:t,title:e.title||"未命名",type:s,author:this.extractAuthor(e),dynasty:this.extractYear(e)}}async getAllEntries(){const t=["book","collection","work"],e=[];for(const s of t){const n=await this.storage.loadEntries(s);e.push(...n)}return e}async getRelations(t){const e=await this.storage.getItem(t);if(!e)return null;const s={},n=e.type||this.extractTypeFromId(t);if(n==="book"){if(e.work_id){const o=await this.resolveEntity(e.work_id);o&&(s.belongsToWork={...o,type:"work"})}if(e.contained_in&&Array.isArray(e.contained_in)&&e.contained_in.length>0){const o=e.contained_in[0],i=typeof o=="string"?o:o.id;if(i){const c=await this.resolveEntity(i);c&&(s.belongsToCollection={...c,type:"collection"})}}}else if(n==="collection"){if(e.books&&Array.isArray(e.books)){const o=await Promise.all(e.books.map(i=>this.resolveEntity(i)));s.containedBooks=o.filter(i=>i!==null).map(i=>({...i,type:"book"}))}}else if(n==="work"){if(e.parent_work&&typeof e.parent_work=="object"){const o=e.parent_work;s.parentWork={id:o.id,title:o.title,type:"work"}}if(e.books&&Array.isArray(e.books)){const o=await Promise.all(e.books.map(i=>this.resolveEntity(i)));s.containedBooks=o.filter(i=>i!==null).map(i=>({...i,type:"book"}))}}return s}async linkEntity(t,e,s){const n=await this.storage.getItem(t);if(!n)throw new Error(`Source not found: ${t}`);const o=n.type||this.extractTypeFromId(t);switch(e){case"belongsToWork":case"work_id":n.work_id=s;break;case"belongsToCollection":case"contained_in":Array.isArray(n.contained_in)||(n.contained_in=[]);{const i=n.contained_in;i.some(l=>(typeof l=="string"?l:l.id)===s)||i.push({id:s})}break;case"parentWork":case"parent_work":{const i=await this.storage.getItem(s);n.parent_work={id:s,title:(i==null?void 0:i.title)||""};break}case"containedBooks":case"books":Array.isArray(n.books)||(n.books=[]),n.books.includes(s)||n.books.push(s);break;default:throw new Error(`Unknown relation field: ${e}`)}await this.storage.saveItem(o,t,n)}async unlinkEntity(t,e){const s=await this.storage.getItem(t);if(!s)throw new Error(`Source not found: ${t}`);const n=s.type||this.extractTypeFromId(t);switch(e){case"belongsToWork":case"work_id":delete s.work_id;break;case"belongsToCollection":case"contained_in":s.contained_in=[];break;case"parentWork":case"parent_work":delete s.parent_work;break;case"containedBooks":case"books":s.books=[];break;default:throw new Error(`Unknown relation field: ${e}`)}await this.storage.saveItem(n,t,s)}async createAndLink(t,e,s){const n=this.idGen.nextId("draft",s.type),o={id:n,type:s.type,title:s.title,...s.inheritData||{}};return await this.storage.saveItem(s.type,n,o),await this.linkEntity(t,e,n),{id:n}}async searchEntities(t,e){const s=e&&e!=="all"?[e]:["book","collection","work"],n=[];for(const o of s){const i=await this.storage.searchEntries(t,o);for(const c of i)n.push({id:c.id,title:c.title,type:c.type,author:c.author,dynasty:c.dynasty})}return n}async getRecentEntities(){return this.recentEntities}async addRecentEntity(t){this.recentEntities=[t,...this.recentEntities.filter(e=>e.id!==t.id)].slice(0,20)}async getCollectionCatalog(t){const e=await this.storage.findFileById(t);if(!e)return null;const n=e.substring(0,e.lastIndexOf("/"))+"/volume_book_mapping.json";try{const o=await this.storage.loadMetadata(n);return Object.keys(o).length===0?null:o}catch{return null}}async getRecommended(){const t=this.workspaceRoot+"/book-index-draft/recommended.json";try{const e=await this.fs.readFile(t);return JSON.parse(e)}catch{return null}}getAssetDir(t){return this.storage.getAssetDir(t)}async initAssetDir(t){return this.storage.initAssetDir(t)}async hasAssetDir(t){return this.storage.hasAssetDir(t)}getBookIndexStorage(){return this.storage}async rebuildIndex(t){await this.storage.rebuildIndex(t)}extractTypeFromId(t){try{const e=k(t);return v(e).type}catch{return"book"}}extractAuthor(t){const e=t.authors;if(Array.isArray(e)&&e.length>0){const s=e[0];return typeof s=="object"&&s!==null?s.name||"":String(s)}}extractYear(t){const e=t.publication_info;if(typeof e=="object"&&e!==null)return e.year||void 0}async resolveEntity(t){const e=await this.storage.getItem(t);return e?{id:t,title:e.title||"未命名"}:null}paginate(t,e){const s=e.page??1,n=e.pageSize??50;if(e.sortBy){const l=e.sortBy,a=e.sortOrder==="desc"?-1:1;t.sort((u,h)=>{const d=u[l]??"",f=h[l]??"";return d<f?-a:d>f?a:0})}const o=t.length,i=(s-1)*n;return{entries:t.slice(i,i+n),total:o,page:s,pageSize:n}}}const Dt="/data",Mt=1e4;class Ot{constructor(t={}){this.indexCache=null,this.pathMap=new Map,this.chunkCache=new Map,this.manifest=null,this.tiyaoCache=new Map,this.searchSCache=null,this.searchSLoaded=!1,this.t2sConverter=null,this.basePath=t.basePath??Dt,this.timeout=t.timeout??Mt}async fetchJson(t){const e=await fetch(t,{signal:AbortSignal.timeout(this.timeout)});if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`);return e.json()}async ensureLoaded(){var n,o;if(this.indexCache)return this.indexCache;const t=await this.fetchJson(`${this.basePath}/index.json`),e=[],s=[["books","book"],["collections","collection"],["works","work"],["entities","entity"]];for(const[i,c]of s){const l=t[i];if(l)for(const a of Object.values(l)){const u=c==="entity"?a.primary_name||a.title||a.name||a.id:a.title||a.name||a.id;e.push({id:a.id,title:u,type:c,isDraft:!0,author:a.author,dynasty:a.dynasty,role:a.role,path:a.path,additional_titles:(n=a.additional_titles)==null?void 0:n.map(h=>typeof h=="string"?h:h==null?void 0:h.book_title).filter(Boolean),attached_texts:(o=a.attached_texts)==null?void 0:o.map(h=>typeof h=="string"?h:h==null?void 0:h.book_title).filter(Boolean),edition:a.edition,juan_count:a.juan_count,has_text:a.has_text,has_image:a.has_image,has_collated:a.has_collated,subtype:a.subtype,primary_name:a.primary_name,birth_year:a.birth_year,death_year:a.death_year,cbdb_id:a.cbdb_id}),this.pathMap.set(a.id,{path:a.path,isDraft:!0})}}return this.indexCache=e,e}async ensureSearchSLoaded(){if(this.searchSLoaded)return this.searchSCache??{};this.searchSLoaded=!0;try{this.searchSCache=await this.fetchJson(`${this.basePath}/search_s.json`)}catch{this.searchSCache={}}return this.searchSCache}async ensureT2S(){if(this.t2sConverter===!1)return null;if(this.t2sConverter)return this.t2sConverter;try{const t=await import("opencc-js");return this.t2sConverter=t.Converter({from:"tw",to:"cn"}),this.t2sConverter}catch{return this.t2sConverter=!1,null}}async loadManifest(){if(this.manifest)return this.manifest;try{this.manifest=await this.fetchJson(`${this.basePath}/chunks/_manifest.json`)}catch{this.manifest=[]}return this.manifest}async resolvePrefix(t){const e=await this.loadManifest();let s=0,n=e.length-1,o=null;for(;s<=n;){const i=s+n>>1;e[i]<=t?(o=e[i],s=i+1):n=i-1}if(o&&t.startsWith(o))return o;for(const i of e)if(t.startsWith(i))return i;return null}async loadChunk(t){if(this.chunkCache.has(t))return this.chunkCache.get(t);try{const e=await this.fetchJson(`${this.basePath}/chunks/${t}.json`);return this.chunkCache.set(t,e),e}catch{return this.chunkCache.set(t,{}),{}}}async loadChunkForId(t){const e=await this.resolvePrefix(t);return e?this.loadChunk(e):{}}async loadTiyaoGroup(t,e){const s=`${t}-${e}`;if(this.tiyaoCache.has(s))return this.tiyaoCache.get(s);const n=i=>String(i).padStart(3,"0"),o=await this.fetchJson(`${this.basePath}/tiyao/juan-${n(t)}-${n(e)}.json`);return this.tiyaoCache.set(s,o),o}async getResourceCounts(){const t=await this.ensureLoaded();let e=0,s=0;for(const n of t)n.type==="work"&&(n.has_text&&e++,n.has_image&&s++);return{hasText:e,hasImage:s}}async loadEntries(t,e){let n=(await this.ensureLoaded()).filter(u=>u.type===t);const o=e.sortBy||"title",i=e.sortOrder||"asc";n.sort((u,h)=>{const d=String(u[o]??""),f=String(h[o]??""),p=d.localeCompare(f,"zh");return i==="asc"?p:-p});const c=e.page||1,l=e.pageSize||50,a=(c-1)*l;return{entries:n.slice(a,a+l),total:n.length,page:c,pageSize:l}}async search(t,e,s){const n=await this.ensureLoaded(),o=await this.ensureSearchSLoaded(),i=await this.ensureT2S(),c=n.filter(p=>p.type===e),l=i?i(t):void 0,u=Object.keys(o).length>0?O(c,t,l,o):R(c,t),h=s.page||1,d=s.pageSize||50,f=(h-1)*d;return{entries:u.slice(f,f+d),total:u.length,page:h,pageSize:d}}async searchAll(t,e=5){const s=await this.ensureLoaded(),n=await this.ensureSearchSLoaded(),o=await this.ensureT2S(),i=["work","book","collection","entity"],c=o?o(t):void 0,l=Object.keys(n).length>0,a=i.map(u=>{const h=s.filter(d=>d.type===u);return l?O(h,t,c,n):R(h,t)});return{works:a[0].slice(0,e),books:a[1].slice(0,e),collections:a[2].slice(0,e),entities:a[3].slice(0,e),totalWorks:a[0].length,totalBooks:a[1].length,totalCollections:a[2].length,totalEntities:a[3].length}}async getItem(t){try{const s=(await this.loadChunkForId(t))[t]||null;if(s){const n=(await this.ensureLoaded()).find(o=>o.id===t);n!=null&&n.has_collated&&(s.has_collated=!0),s.type==="entity"&&!s.title&&s.primary_name&&(s.title=s.primary_name)}return s}catch{return null}}async getEntry(t){return(await this.ensureLoaded()).find(s=>s.id===t)||null}async getAllEntries(){return this.ensureLoaded()}async saveItem(){throw new Error("BundleStorage 为只读模式,不支持保存")}async deleteItem(){throw new Error("BundleStorage 为只读模式,不支持删除")}async generateId(){throw new Error("BundleStorage 为只读模式,不支持生成 ID")}async getCollectionCatalogs(t){const e=await this.getItem(t);if(!e)return null;const s=e.resources||[];if(s.length===0)return null;const n=[];for(const o of s)try{const i=await this.fetchJson(`${this.basePath}/items/${t}/${o.id}/volume_book_mapping.json`);i&&n.push({resource_id:o.id,short_name:o.short_name,data:G(i)})}catch{}return n.length>0?n:null}async getCollectionCatalog(t){var s;const e=await this.getCollectionCatalogs(t);return((s=e==null?void 0:e[0])==null?void 0:s.data)??null}async getCollatedEditionIndex(t){try{return await this.fetchJson(`${this.basePath}/items/${t}/collated_edition/collated_edition_index.json`)}catch{return null}}async getCollatedJuan(t,e){if(e.includes("..")||!e.endsWith(".json"))return null;try{return await this.fetchJson(`${this.basePath}/items/${t}/collated_edition/${e}`)}catch{return null}}async getCollatedJuanText(t,e){if(e.includes("..")||!e.endsWith(".json"))return null;const s=e.replace(/\.json$/,".md");try{const n=await fetch(`${this.basePath}/items/${t}/collated_edition/text/${s}`);return n.ok?await n.text():null}catch{return null}}async getResourceProgress(){try{return await this.fetchJson(`${this.basePath}/resource.json`)}catch{return null}}async getSiteProgress(){try{return await this.fetchJson(`${this.basePath}/resource-site.json`)}catch{return null}}async getRecommended(){try{return await this.fetchJson(`${this.basePath}/recommended.json`)}catch{return null}}clearCache(){this.indexCache=null,this.pathMap.clear(),this.chunkCache.clear(),this.manifest=null,this.tiyaoCache.clear(),this.searchSCache=null,this.searchSLoaded=!1,this.t2sConverter=null}}class T extends Error{constructor(t){super(t),this.name="BookIndexError"}}class Ut extends T{constructor(t){super(t),this.name="StorageError"}}class Lt extends T{constructor(t){super(t),this.name="IdGenerationError"}}class Nt extends T{constructor(t){super(t),this.name="ConfigError"}}class Wt extends T{constructor(t){super(t),this.name="MigrationError"}}class Jt{constructor(t,e,s=1){this.storage=new H(t,e),this.idGen=new q(s)}generateId(t="book",e="draft"){return this.idGen.nextIdRaw(e,t)}encodeId(t){return F(t)}decodeId(t){return k(t)}async saveItem(t,e,s="draft"){let n=t.id||t.ID;if(n)try{const i=A(n);e||(e=i.type)}catch{throw new T(`Invalid ID format: ${n}`)}else e||(e=t.type||"book"),n=this.idGen.nextId(s,e),t.id=n;return await this.storage.saveItem(e,n,t)}async getItem(t){return this.storage.getItem(t)}async findItemPath(t){return this.storage.findFileById(t)}async updateField(t,e,s){const n=await this.storage.findFileById(t);if(!n)return!1;try{const o=await this.storage.loadMetadata(n),i={基本信息:null,介绍:"description",资源:"resources",收藏历史:"history",其他版本:"related_books"},c=e in i?i[e]:e;if(c===null)return!1;if(c==="description"&&typeof s=="string"){const a=o[c]||{};o[c]={text:s,sources:a.sources||[]}}else o[c]=s;const l=A(t);return await this.storage.saveItem(l.type,t,o),!0}catch{return!1}}async deleteItem(t){return this.storage.deleteItem(t)}async rebuildIndices(){await this.storage.rebuildIndex("official"),await this.storage.rebuildIndex("draft")}getAssetDir(t){return this.storage.getAssetDir(t)}async initAssetDir(t){return this.storage.initAssetDir(t)}async hasAssetDir(t){return this.storage.hasAssetDir(t)}getStorage(){return this.storage}}const zt={wikisource:"wikisource",shidianguji:"shidianguji",archive:"archive",ctext:"ctext",nlc:"nlc","read.nlc":"nlc","db.sido":"sido","guji.artx":"guji-artx","digital.library":"digital-library"},Z=new Set(["text","image","text+image","physical"]),Ht=new Set(["catalog","search"]),Gt=new Set(["com","org","net","cn","edu","gov","io","jp","tw","hk"]);function qt(r){if(!r)return"";try{const e=new URL(r).hostname;for(const[n,o]of Object.entries(zt))if(e.includes(n))return o;const s=e.split(".");if(s.length>=2){const n=s.filter(o=>!Gt.has(o)&&o.length>2);return n.length>0?n[n.length-1]:s[s.length-2]}return e}catch{return""}}function Yt(r){const t=[];return r.name||t.push("name is required"),Z.has(r.type)||t.push(`invalid type '${r.type}', must be one of ${[...Z].join(", ")}`),r.root_type&&!Ht.has(r.root_type)&&t.push(`invalid root_type '${r.root_type}'`),r.type!=="physical"&&!r.url&&t.push("url is required for non-physical resources"),t}const w=class w{constructor(t,e=""){if(this._type=null,this.title=e,typeof t=="string"){t.startsWith(w.PREFIX)&&(t=t.slice(w.PREFIX.length)),this.idStr=t;try{this.idInt=k(t)}catch{this.idInt=0n}}else this.idInt=t,this.idStr=F(t);if(this.idInt>0n)try{const s=A(this.idStr);this._type=s.type}catch{}}get type(){return this._type}getIcon(){return this._type===null?"":this._type==="book"?"📖 ":this._type==="collection"?"📚 ":this._type==="work"?"📜 ":""}render(t=!1){return`[${t?this.getIcon():""}${this.title}](${w.PREFIX}${this.idStr})`}static parseFromLink(t){const e=t.match(/\[(.*?)\]\((.*?)\)/);if(e){const s=e[1],n=e[2];if(n.startsWith(w.PREFIX)){const o=n.slice(w.PREFIX.length);return new w(o,s)}}return null}static isBidLink(t){return t.startsWith(w.PREFIX)}};w.PROTOCOL="bid:\\\\",w.PREFIX="bid:\\\\";let J=w;exports.BidLink=J;exports.BookIndexError=T;exports.BookIndexManager=Jt;exports.BookIndexStorage=H;exports.BundleStorage=Ot;exports.ConfigError=Nt;exports.GithubStorage=Rt;exports.IdGenerationError=Lt;exports.IdGenerator=q;exports.LocalStorage=Ft;exports.MigrationError=Wt;exports.StorageError=Ut;exports.base36Decode=z;exports.base36Encode=F;exports.base58Decode=at;exports.buildId=N;exports.decodeId=St;exports.decodeIdString=A;exports.encodeId=It;exports.extractIdFromUrl=qt;exports.extractStatus=Et;exports.extractType=xt;exports.normalizeCatalog=G;exports.parseId=v;exports.smartDecode=k;exports.validateResource=Yt;
@@ -884,7 +884,7 @@ class jt {
884
884
  async getCollatedEditionIndex(t) {
885
885
  const e = await this.resolveItemPath(t);
886
886
  if (!e) return null;
887
- const s = `${e.dir}/${t}/collated_edition_index.json`;
887
+ const s = `${e.dir}/${t}/collated_edition/collated_edition_index.json`;
888
888
  return this.fetchFile(e.repo, s);
889
889
  }
890
890
  async getCollatedJuan(t, e) {
@@ -1449,7 +1449,7 @@ class Bt {
1449
1449
  async getCollatedEditionIndex(t) {
1450
1450
  try {
1451
1451
  return await this.fetchJson(
1452
- `${this.basePath}/items/${t}/collated_edition_index.json`
1452
+ `${this.basePath}/items/${t}/collated_edition/collated_edition_index.json`
1453
1453
  );
1454
1454
  } catch {
1455
1455
  return null;
package/dist/storage.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./storage-entry-BTHh3quk.cjs");exports.BidLink=r.BidLink;exports.BookIndexError=r.BookIndexError;exports.BookIndexManager=r.BookIndexManager;exports.BookIndexStorage=r.BookIndexStorage;exports.BundleStorage=r.BundleStorage;exports.ConfigError=r.ConfigError;exports.GithubStorage=r.GithubStorage;exports.IdGenerationError=r.IdGenerationError;exports.IdGenerator=r.IdGenerator;exports.LocalStorage=r.LocalStorage;exports.MigrationError=r.MigrationError;exports.StorageError=r.StorageError;exports.extractIdFromUrl=r.extractIdFromUrl;exports.validateResource=r.validateResource;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./storage-entry-2AJlDQPr.cjs");exports.BidLink=r.BidLink;exports.BookIndexError=r.BookIndexError;exports.BookIndexManager=r.BookIndexManager;exports.BookIndexStorage=r.BookIndexStorage;exports.BundleStorage=r.BundleStorage;exports.ConfigError=r.ConfigError;exports.GithubStorage=r.GithubStorage;exports.IdGenerationError=r.IdGenerationError;exports.IdGenerator=r.IdGenerator;exports.LocalStorage=r.LocalStorage;exports.MigrationError=r.MigrationError;exports.StorageError=r.StorageError;exports.extractIdFromUrl=r.extractIdFromUrl;exports.validateResource=r.validateResource;
package/dist/storage.js CHANGED
@@ -1,4 +1,4 @@
1
- import { B as o, b as e, c as s, d as t, f as n, C as d, G as g, I as i, g as I, L as B, M as S, S as x, o as E, v as c } from "./storage-entry-CQvuThmT.js";
1
+ import { B as o, b as e, c as s, d as t, f as n, C as d, G as g, I as i, g as I, L as B, M as S, S as x, o as E, v as c } from "./storage-entry-BiThJ6BH.js";
2
2
  export {
3
3
  o as BidLink,
4
4
  e as BookIndexError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "book-index-ui",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "React components for browsing and editing ancient book index metadata",
5
5
  "author": "Li Shaodong",
6
6
  "repository": {