book-index-ui 0.1.6 → 0.1.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 +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -2
- package/dist/{storage-entry-C5i8mBl3.cjs → storage-entry-CAvzCo5k.cjs} +1 -1
- package/dist/{storage-entry-0bL59zPV.js → storage-entry-CT6PuEDo.js} +10 -0
- package/dist/storage.cjs +1 -1
- package/dist/storage.d.ts +2 -0
- package/dist/storage.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var Ot=Object.create;var He=Object.defineProperty;var Dt=Object.getOwnPropertyDescriptor;var Vt=Object.getOwnPropertyNames;var Nt=Object.getPrototypeOf,Ut=Object.prototype.hasOwnProperty;var Yt=(t,n,r,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of Vt(n))!Ut.call(t,i)&&i!==r&&He(t,i,{get:()=>n[i],enumerable:!(o=Dt(n,i))||o.enumerable});return t};var Gt=(t,n,r)=>(r=t!=null?Ot(Nt(t)):{},Yt(n||!t||!t.__esModule?He(r,"default",{value:t,enumerable:!0}):r,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("./storage-entry-C5i8mBl3.cjs"),e=require("react/jsx-runtime"),p=require("react"),je=p.createContext(null),xt={indexType:{work:"作品",book:"書籍",collection:"叢編"},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:"+ 添加收錄來源",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:"上級作品",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:"📖 著錄於",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",appendix:"附錄",containedIn:"收入",belongsToWork:"所屬作品",locationHistory:"流轉���史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄",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:"清除全部",searchTitle:"搜索古籍索引",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"叢書目錄",siteTab:"在線資源",recommendTab:"推薦",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",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:"圖片資源"}},Jt={indexType:{work:"作品",book:"书籍",collection:"丛编"},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:"+ 添加收录来源",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:"上级作品",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:"📖 著录于",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",appendix:"附录",containedIn:"收入",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录",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:"清除全部",searchTitle:"搜索古籍索引",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"丛书目录",siteTab:"在线资源",recommendTab:"推荐",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",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:"图片资源"}},Kt={"zh-Hant":xt,"zh-Hans":Jt},Zt=({locale:t,onLocaleChange:n,children:r})=>{const[o,i]=p.useState(t??"zh-Hant"),s=t??o,[a,l]=p.useState(null);p.useEffect(()=>{s==="zh-Hans"?import("opencc-js/t2cn").then(g=>{const x=g.Converter({from:"tw",to:"cn"});l(()=>x)}).catch(()=>{l(()=>g=>g)}):l(null)},[s]);const d=p.useCallback(g=>{i(g),n==null||n(g)},[n]),u=p.useMemo(()=>({locale:s,setLocale:d,messages:Kt[s],converter:a}),[s,d,a]);return e.jsx(je.Provider,{value:u,children:r})};function W(){const t=p.useContext(je);return(t==null?void 0:t.messages)??xt}const Xt=2e3;function F(){const t=p.useContext(je),n=(t==null?void 0:t.locale)??"zh-Hant",r=(t==null?void 0:t.converter)??null,o=p.useRef(new Map),i=p.useRef(n);i.current!==n&&(o.current.clear(),i.current=n);const s=p.useCallback(a=>{if(!a)return"";if(!r)return a;const l=o.current.get(a);if(l!==void 0)return l;const d=r(a);if(o.current.size>=Xt){const u=o.current.keys().next().value;u!==void 0&&o.current.delete(u)}return o.current.set(a,d),d},[r]);return p.useMemo(()=>({convert:s,locale:n,isSimplified:n==="zh-Hans"}),[s,n])}function Se(t,n){return t.replace(/\{(\w+)\}/g,(r,o)=>String(n[o]??""))}function qt(t){if(!t)return"";try{const n=new URL(t).hostname,r={"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(r[n])return r[n];const o=n.split(".");return o.length>=2?o[o.length-2]:n}catch{return""}}function Qt(){return{id:"",name:"",url:"",type:"text",details:""}}const We=({items:t,onChange:n,onDownload:r,downloadStatuses:o,filterType:i})=>{const s=W(),[a,l]=p.useState(null),d=[{value:"text",label:s.resourceTypeShort.text},{value:"image",label:s.resourceTypeShort.image},{value:"text+image",label:s.resourceTypeShort.textImage},{value:"physical",label:s.resourceTypeShort.physical}],u=[{value:"catalog",label:s.rootType.catalog},{value:"search",label:s.rootType.search}],g=m=>i?i==="text"?m==="text"||m==="text+image":i==="image"?m==="image"||m==="text+image"||m==="physical":m===i:!0,x=t.map((m,S)=>({item:m,originalIndex:S})).filter(({item:m})=>g(m.type)),f=()=>{const m=Qt();i&&(m.type=i),n([...t,m]),l(t.length)},c=m=>{n(t.filter((S,y)=>y!==m)),l(null)},j=(m,S,y)=>{const I=[...t];if(I[m]={...I[m],[S]:y},S==="url"&&!I[m].id){const T=qt(y);T&&(I[m].id=T)}n(I)},w=(m,S,y)=>{const T={...t[m].metadata||{}};y?T[S]=y:delete T[S],j(m,"metadata",Object.keys(T).length>0?T:void 0)},b=(m,S)=>{const y=S.trim()?S.split(/[,,、]/).map(I=>I.trim()).filter(Boolean):void 0;j(m,"structure",y)},E=(m,S,y)=>{const T=t[m].coverage||{level:1,ranges:""};S==="level"?T.level=parseInt(y)||1:T.ranges=y,j(m,"coverage",T.ranges?T:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:m,originalIndex:S})=>{var y,I,T,v;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:()=>l(a===S?null:S),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:a===S?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:en(m.type),color:"#fff"},children:((y=d.find(h=>h.value===m.type))==null?void 0:y.label)||m.type}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.name||`${s.editor.resourcePlaceholder} ${S+1}`}),m.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:m.id}),m.url&&e.jsx("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",onClick:h=>h.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),r&&m.url&&tn(S,o==null?void 0:o[S],r,s),e.jsx("button",{onClick:h=>{h.stopPropagation(),c(S)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:s.editor.deleteThisResource,children:"✕"})]}),a===S&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(m.type==="image"||m.type==="text+image")&&m.url&&nn(m,s),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:be,children:[e.jsx("span",{style:me,children:s.label.type}),e.jsx("select",{value:m.type,onChange:h=>j(S,"type",h.target.value),style:{...oe,flex:1},children:d.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value))})]}),e.jsxs("label",{style:be,children:[e.jsx("span",{style:me,children:s.label.rootType}),e.jsx("select",{value:m.root_type||"catalog",onChange:h=>j(S,"root_type",h.target.value),style:{...oe,flex:1},children:u.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:m.id,onChange:h=>j(S,"id",h.target.value),placeholder:s.editor.idAutoExtract,style:{...oe,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:m.name,onChange:h=>j(S,"name",h.target.value),placeholder:s.editor.resourceName,style:{...oe,flex:1}})]}),e.jsx("input",{type:"text",value:m.url,onChange:h=>j(S,"url",h.target.value),placeholder:s.editor.resourceUrl,style:oe}),e.jsx("input",{type:"text",value:((I=m.structure)==null?void 0:I.join("、"))||"",onChange:h=>b(S,h.target.value),placeholder:s.editor.structurePlaceholder,style:oe}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:be,children:[e.jsx("span",{style:me,children:s.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((T=m.coverage)==null?void 0:T.level)??"",onChange:h=>E(S,"level",h.target.value),placeholder:"1",style:{...oe,width:"60px"}})]}),e.jsxs("label",{style:{...be,flex:1},children:[e.jsx("span",{style:me,children:s.label.coverageRange}),e.jsx("input",{type:"text",value:((v=m.coverage)==null?void 0:v.ranges)||"",onChange:h=>E(S,"ranges",h.target.value),placeholder:s.editor.coverageRangePlaceholder,style:{...oe,flex:1}})]})]}),e.jsx("textarea",{value:m.details||"",onChange:h=>j(S,"details",h.target.value),placeholder:s.editor.detailsPlaceholder,style:{...oe,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:s.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(s.metadata).map(([h,R])=>{var C;return e.jsxs("label",{style:{...be,gap:"4px"},children:[e.jsx("span",{style:{...me,minWidth:"56px"},children:R}),e.jsx("input",{type:"text",value:((C=m.metadata)==null?void 0:C[h])||"",onChange:_=>w(S,h,_.target.value),placeholder:R,style:{...oe,flex:1}})]},h)})})]})]})]})]},S)}),e.jsxs("button",{onClick:f,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:s.action.addResource})]})]})};function en(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function tn(t,n,r,o){const i=(n==null?void 0:n.status)==="downloading",s=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:a=>{a.stopPropagation(),i||r(t,"")},disabled:i,style:{background:"transparent",border:"none",color:s?"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:s?o.download.completed:i?`${o.download.downloading} ${(n==null?void 0:n.progress)||0}%`:o.download.downloadThis,children:s?"✓":i?"⏳":"⬇"})}function nn(t,n){const r=/\.(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:r?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:o=>{o.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 oe={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"},be={display:"flex",alignItems:"center",gap:"6px"},me={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},on={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function rn(t){try{const n=new URL(t).hostname;return on[n]}catch{return}}const Oe={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"},ln=["text","image","text+image","physical"];function sn(t){const n=s=>{const a=s.match(/^(.+?)·第(\d+)[冊册]$/);if(a)return[a[1],parseInt(a[2])];const l=s.match(/^(.+?)[·(](\d+)[)]?$/);return l?[l[1],parseInt(l[2])]:null},r=new Map,o=[],i=new Set;for(let s=0;s<t.length;s++){const a=t[s];if(a.volumes&&a.volumes.length>0)continue;const l=n(a.name);if(!l)continue;const[d,u]=l,g=`${d}|${a.type}`;r.has(g)||r.set(g,{base:{...a,name:d,url:"",volumes:[]},volumes:[]}),r.get(g).volumes.push({volume:u,url:a.url||void 0,status:"found"}),i.add(s)}for(const[,s]of r)if(s.volumes.length>=2)s.volumes.sort((a,l)=>a.volume-l.volume),s.base.volumes=s.volumes,s.base.expected_volumes=s.volumes.length,o.push(s.base);else for(let a=0;a<t.length;a++)if(i.has(a)){const l=n(t[a].name);l&&`${l[0]}|${t[a].type}`==`${s.base.name}|${s.base.type}`&&i.delete(a)}for(let s=0;s<t.length;s++)i.has(s)||o.push(t[s]);return o}const Me=({items:t,groupByType:n=!0})=>{const r=W(),o=p.useMemo(()=>sn(t||[]),[t]),i={text:r.resourceType.text,image:r.resourceType.image,"text+image":r.resourceType.textImage,physical:r.resourceType.physical};if(!o||o.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:r.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:o.map((a,l)=>e.jsx(Ve,{item:a},a.id||l))});const s=ln.map(a=>({type:a,items:o.filter(l=>l.type===a)})).filter(a=>a.items.length>0);return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:s.map(({type:a,items:l})=>e.jsxs("div",{children:[e.jsxs("h4",{style:{margin:"0 0 8px",fontSize:"13px",fontWeight:600,color:Oe[a],display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx("span",{style:{display:"inline-block",width:"4px",height:"14px",borderRadius:"2px",background:Oe[a]}}),i[a],e.jsxs("span",{style:{fontWeight:400,opacity:.6},children:["(",l.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:l.map((d,u)=>e.jsx(Ve,{item:d},d.id||u))})]},a))})},De=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},ut=({value:t})=>{const r=W().checkType[t];return r?e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:r.bg,color:r.fg},children:r.label}):e.jsx("span",{children:t})},an=(t,n,r)=>t==="check_type"&&typeof n=="string"?e.jsx(ut,{value:n}):t==="has_translation"?n?r.misc.hasTranslation:r.misc.noTranslation:String(n);function dn(t){if(t.url)return t.url;for(const[n,r]of Object.entries(t))if(n.endsWith("_url")&&typeof r=="string")return r}const cn={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},Ve=({item:t})=>{var f;const n=W(),{convert:r}=F(),[o,i]=p.useState(!1),s=p.useMemo(()=>(t.url?rn(t.url):void 0)||r(t.name),[t.url,t.name,r]),a=p.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(c=>({...c,url:c.url||dn(c)})),[t.volumes]),l=a&&a.length>0,d=l?a.filter(c=>c.status!=="missing").length:0,u=l?a.length-d:0,g=t.expected_volumes??(l?a.length:0),x=t.color_mode?{...cn[t.color_mode],label:n.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:De(t)||l?"6px":"0"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:s}),x&&e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:x.bg,color:x.fg},children:x.label}),t.source_label&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",fontStyle:"italic"},children:t.source_label}),((f=t.metadata)==null?void 0:f.check_type)&&e.jsx(ut,{value:t.metadata.check_type}),l&&e.jsxs("button",{onClick:()=>i(!o),style:{padding:"1px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer"},children:[d,"/",g,n.unit.volume,u>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"4px"},children:["缺",u]}),e.jsx("span",{style:{marginLeft:"4px"},children:o?"▲":"▼"})]}),t.url&&e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:n.action.visit})]}),De(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(([c])=>c!=="check_type").map(([c,j])=>e.jsxs("span",{children:[n.metadata[c]||c,": ",an(c,j,n)]},c)),t.details&&!l&&e.jsx("span",{children:t.details}),t.structure&&e.jsxs("span",{children:[n.misc.structure,": ",t.structure.join(" → ")]}),t.coverage&&e.jsxs("span",{children:[n.misc.coverage,": L",t.coverage.level," ",t.coverage.ranges]})]}),l&&o&&e.jsx("div",{style:{marginTop:"8px",padding:"8px 0",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",display:"flex",flexWrap:"wrap",gap:"4px"},children:a.map(c=>{const j=c.status==="missing";return e.jsx("span",{style:{display:"inline-flex"},children:c.url&&!j?e.jsx("a",{href:c.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:c.label||`${c.volume}`,children:c.volume}):e.jsx("span",{style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid transparent",color:j?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:j?"line-through":"none",opacity:j?.6:1,lineHeight:1.4},children:c.volume})},c.volume)})})]})},gt=({indexSource:t,syncConfig:n,variant:r="index-browser",onSwitchMode:o,onToggleDraft:i,onConfigurePath:s,onSelectFolder:a})=>{const l=W(),d=t==="local",u=(n==null?void 0:n.isDraft)??!0,g=(n==null?void 0:n.repoPath)||"",x=g?g.split(/[/\\]/).pop()||g:"",f={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)"},c={onMouseOver:w=>w.currentTarget.style.opacity="0.8",onMouseOut:w=>w.currentTarget.style.opacity="1"},j=e.jsxs("div",{onClick:i,title:u?l.mode.switchToOfficial:l.mode.switchToDraft,style:{...f,background:u?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...c,children:[e.jsx("span",{children:u?"📝":"📚"}),e.jsx("span",{children:u?"draft":"official"})]});return r==="index-browser"?d?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[j,e.jsxs("div",{onClick:o,title:l.mode.switchToSync,style:f,...c,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:l.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:a,title:g||l.mode.selectFolder,style:{...f,paddingLeft:"8px",paddingRight:"8px"},...c,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[j,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:o,title:l.mode.switchToLocal,style:f,...c,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:l.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:s,title:x||l.mode.configurePath,style:{...f,background:"transparent",padding:"6px",fontSize:"12px"},...c,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:o,title:d?l.mode.switchToGithub:l.mode.switchToLocal,style:f,...c,children:[e.jsx("span",{children:d?"📁":"🌐"}),e.jsx("span",{children:d?l.mode.localMode:l.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),d&&e.jsxs("div",{onClick:a,title:g||l.mode.selectFolder,style:{...f,paddingLeft:"8px",paddingRight:"8px",minWidth:g?"100px":"auto",justifyContent:"space-between"},...c,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!d&&x&&e.jsxs("div",{style:{...f,background:"#2196f3",color:"white",cursor:"default"},title:g,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:x})]})]})},Te="bim-search-history",Ne=10,Ue=8;function ve(){try{const t=localStorage.getItem(Te);return t?JSON.parse(t):[]}catch{return[]}}function pn(t){try{const n=ve().filter(r=>r!==t);n.unshift(t),n.length>Ne&&(n.length=Ne),localStorage.setItem(Te,JSON.stringify(n))}catch{}}function xn(t){try{const n=ve().filter(r=>r!==t);localStorage.setItem(Te,JSON.stringify(n))}catch{}}function un(){try{localStorage.removeItem(Te)}catch{}}const ft=({transport:t,value:n,onChange:r,onSearch:o,onEntrySelect:i,placeholder:s})=>{const a=W(),l=s??a.search.placeholder,d={work:a.indexType.work,book:a.indexType.book,collection:a.indexType.collection},[u,g]=p.useState(!1),[x,f]=p.useState([]),[c,j]=p.useState(-1),[w,b]=p.useState(null),[E,m]=p.useState(ve),S=p.useRef(null),y=p.useRef(null),I=p.useRef(null);p.useEffect(()=>{if(!t.getAllEntries)return;let k=!1;return t.getAllEntries().then($=>{k||b($)}).catch(()=>{}),()=>{k=!0}},[t]);const T=p.useCallback(k=>{if(!k.trim())return E.map(L=>({type:"history",text:L}));if(!w)return[];const $=k.toLowerCase(),D=[],U=[];for(const L of w){if(D.length+U.length>=Ue*2)break;const M=L.title.toLowerCase();if(M.startsWith($))D.push({type:"entry",text:L.title,entry:L});else if(M.includes($))U.push({type:"entry",text:L.title,entry:L});else if(L.additional_titles){for(const V of L.additional_titles)if(V.toLowerCase().includes($)){D.push({type:"entry",text:`${L.title}`,entry:L});break}}}return[...D,...U].slice(0,Ue)},[w,E]);p.useEffect(()=>{f(T(n)),j(-1)},[n,T]),p.useEffect(()=>{const k=$=>{I.current&&!I.current.contains($.target)&&g(!1)};return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[]),p.useEffect(()=>{const k=$=>{var D,U;if($.key==="/"&&document.activeElement!==S.current){const L=(D=document.activeElement)==null?void 0:D.tagName;if(L==="INPUT"||L==="TEXTAREA"||L==="SELECT")return;$.preventDefault(),(U=S.current)==null||U.focus()}};return document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[]);const v=p.useCallback(k=>{k.trim()&&(pn(k.trim()),m(ve())),o(k),g(!1)},[o]),h=p.useCallback(k=>{k.type==="history"?(r(k.text),v(k.text)):k.entry&&(i?(i(k.entry),g(!1)):(r(k.text),v(k.text)))},[r,v,i]),R=p.useCallback(k=>{if(!u||x.length===0){k.key==="Enter"&&v(n);return}switch(k.key){case"ArrowDown":k.preventDefault(),j($=>($+1)%x.length);break;case"ArrowUp":k.preventDefault(),j($=>($-1+x.length)%x.length);break;case"Enter":k.preventDefault(),c>=0&&c<x.length?h(x[c]):v(n);break;case"Escape":k.preventDefault(),g(!1);break}},[u,x,c,n,v,h]),C=p.useCallback((k,$)=>{$.stopPropagation(),xn(k),m(ve()),f(D=>D.filter(U=>!(U.type==="history"&&U.text===k)))},[]),_=p.useCallback(k=>{k.stopPropagation(),un(),m([]),f([])},[]);p.useEffect(()=>{if(c>=0&&y.current){const k=y.current.children;k[c]&&k[c].scrollIntoView({block:"nearest"})}},[c]);const P=!n.trim()&&E.length>0;return e.jsxs("div",{ref:I,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:S,type:"text",placeholder:l,value:n,onChange:k=>{r(k.target.value),g(!0)},onFocus:()=>g(!0),onKeyDown:R,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&&x.length>0&&e.jsxs("div",{ref:y,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[P&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:a.search.history}),e.jsx("button",{onClick:_,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:a.search.clearAll})]}),x.map((k,$)=>e.jsxs("div",{onClick:()=>h(k),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:$===c?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:k.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:k.text}),k.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[d[k.entry.type],k.entry.edition&&` · ${k.entry.edition}`,k.entry.author&&` · ${k.entry.author}`]}),k.type==="history"&&e.jsx("button",{onClick:D=>C(k.text,D),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:a.action.remove,children:"×"})]},`${k.type}-${k.text}-${$}`))]})]})},$e="bim-recent-ids",Ye="bim-recent-entries",Ge=50,Re=5,gn=50,fn=200;function Pe(){try{const t=localStorage.getItem($e);if(t)return JSON.parse(t);const n=localStorage.getItem(Ye);if(n){const r=JSON.parse(n).map(o=>o.id);return localStorage.setItem($e,JSON.stringify(r)),localStorage.removeItem(Ye),r}return[]}catch{return[]}}function hn(t){try{const n=Pe().filter(r=>r!==t);n.unshift(t),n.length>Ge&&(n.length=Ge),localStorage.setItem($e,JSON.stringify(n))}catch{}}const bn={works:"totalWorks",books:"totalBooks",collections:"totalCollections"},ht=({transport:t,indexSource:n="local",syncConfig:r,onEntryClick:o,onNewEntry:i,onSwitchMode:s,onToggleDraft:a,onConfigurePath:l,onSelectFolder:d,hideModeIndicator:u,initialQuery:g,onQueryChange:x,headerRight:f})=>{const c=W(),j=[{type:"work",icon:"✍️",name:c.indexType.work,key:"works"},{type:"book",icon:"📖",name:c.indexType.book,key:"books"},{type:"collection",icon:"📚",name:c.indexType.collection,key:"collections"}],[w,b]=p.useState(g??""),[E,m]=p.useState(null),[S,y]=p.useState(null),[I,T]=p.useState(!1),[v,h]=p.useState(null),[R,C]=p.useState(""),[_,P]=p.useState(!g),[k,$]=p.useState(Pe),[D,U]=p.useState([]),[L,M]=p.useState(!1),[V,Y]=p.useState(!1),[A,ee]=p.useState(null),q=p.useRef(void 0),te=p.useRef(!1),ne=p.useCallback(async(B,G)=>{if(!B.trim()){P(!0),m(null),y(null);return}P(!1),T(!0),C("");try{if(t.searchAll){const O=await t.searchAll(B,G??Re);m(O)}else{const O=["work","book","collection"],Z=await Promise.all(O.map(se=>t.search(B,se,{page:1,pageSize:G??Re})));m({works:Z[0].entries,books:Z[1].entries,collections:Z[2].entries,totalWorks:Z[0].total,totalBooks:Z[1].total,totalCollections:Z[2].total})}}catch(O){C(O instanceof Error?O.message:String(O)),m(null)}finally{T(!1)}},[t]);p.useEffect(()=>{let B=!1;const G=["work","book","collection"];return Promise.all(G.map(O=>t.loadEntries(O,{page:1,pageSize:1}).catch(()=>({total:0})))).then(O=>{B||ee({works:O[0].total,books:O[1].total,collections:O[2].total})}),()=>{B=!0}},[t]),p.useEffect(()=>{te.current||!(g!=null&&g.trim())||(te.current=!0,ne(g))},[g,ne]);const xe=p.useCallback(B=>{if(b(B),x==null||x(B),!B.trim()){P(!0),m(null),y(null);return}q.current&&clearTimeout(q.current),q.current=setTimeout(()=>{y(null),ne(B)},fn)},[ne,x]),le=p.useCallback(B=>{q.current&&clearTimeout(q.current),x==null||x(B),ne(B)},[ne,x]),N=p.useCallback(B=>{y(B),ne(w,gn)},[w,ne]);p.useEffect(()=>{if(!k.length){U([]);return}let B=!1;return M(!0),Promise.all(k.slice(0,10).map(async G=>{var O,Z,se;try{if(t.getEntry){const J=await t.getEntry(G);if(J)return J}const ae=await t.getItem(G);if(ae){const J=ae.authors;return{id:G,title:ae.title||G,type:ae.type||"work",author:(O=J==null?void 0:J[0])==null?void 0:O.name,dynasty:(Z=J==null?void 0:J[0])==null?void 0:Z.dynasty,role:(se=J==null?void 0:J[0])==null?void 0:se.role,edition:ae.edition||void 0}}}catch{}return null})).then(G=>{B||(U(G.filter(O=>O!==null)),M(!1))}),()=>{B=!0}},[k,t]);const he=B=>{h(B.id),hn(B.id),$(Pe()),o==null||o(B)},ke=B=>j.find(G=>G.type===B),_e=E&&(E.works.length>0||E.books.length>0||E.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:c.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[f,!u&&e.jsx(gt,{variant:"index-browser",indexSource:n,syncConfig:r,onSwitchMode:s,onToggleDraft:a,onConfigurePath:l,onSelectFolder:d})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(ft,{transport:t,value:w,onChange:xe,onSearch:le,onEntrySelect:he}),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:c.action.newEntry})]}),A&&_&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[c.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:A.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),c.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:A.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),c.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:A.collections.toLocaleString()})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:I?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:c.search.searching}):R?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:R})]}):_?e.jsx("div",{style:{flex:1},children:L?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:c.search.loading}):D.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:c.search.recentBrowse}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:D.slice(0,V?10:3).map(B=>e.jsx(Je,{entry:B,selected:v===B.id,onClick:he,getConfig:ke},B.id))}),!V&&D.length>3&&e.jsx("button",{onClick:()=>Y(!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:c.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:c.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.search.searchSubtitle})]})}):_e?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:j.map(({type:B,icon:G,name:O,key:Z})=>{const se=E[Z],ae=bn[Z],J=E[ae];if(se.length===0)return null;const we=!(S===B)&&J>Re;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:[G," ",O,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[J," ",c.unit.items]})]}),we&&e.jsx("button",{onClick:()=>N(B),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:c.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:se.map(z=>e.jsx(Je,{entry:z,selected:v===z.id,onClick:he,getConfig:ke,query:w},z.id))})]},B)})}):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:Se(c.search.noResultsFor,{query:w})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.search.tryOther})]})})]})},Je=({entry:t,selected:n,onClick:r,getConfig:o,query:i})=>{const s=W(),{convert:a}=F(),l=i&&t.additional_titles?t.additional_titles.find(d=>d.toLowerCase().includes(i.toLowerCase())):void 0;return e.jsxs("div",{onClick:()=>r(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:o(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:o(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:a(t.title)}),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:a(t.edition)}),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]})]}),(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:["〔",a(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:a(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",a(t.role)]})]}),l&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[s.search.alias,":",a(l)]})]}),e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},mn=["〇","一","二","三","四","五","六","七","八","九"],Ke=["","十","百","千"];function bt(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),r=n.length;let o="",i=!1;for(let s=0;s<r;s++){const a=parseInt(n[s]),l=r-1-s;a===0?i=!0:(i&&o&&(o+="〇"),i=!1,a===1&&l===1&&s===0?o+=Ke[l]:o+=mn[a]+Ke[l])}return o}function mt({type:t}){const n=W(),r={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3"};return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:r[t],border:`1px solid ${r[t]}40`,borderRadius:"2px",background:`${r[t]}08`},children:n.indexType[t]})}function yn({isDraft:t}){const n=W();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 vn({id:t}){const n=W(),[r,o]=p.useState(!1),i=()=>{navigator.clipboard.writeText(t).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"3px 8px 3px 10px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"#f6f6f6",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"12px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:i,title:r?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"13px",opacity:r?1:.5,transition:"opacity 0.15s"},onMouseEnter:s=>s.currentTarget.style.opacity="1",onMouseLeave:s=>s.currentTarget.style.opacity=r?"1":"0.5",children:r?"✓":"⧉"})]})}function Q({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 ie({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 yt({authors:t,type:n}){const{convert:r}=F();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((o,i)=>e.jsxs("span",{children:[i>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),o.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",r(o.dynasty),"〕"]}),e.jsx("span",{style:{fontWeight:500},children:r(o.name)}),o.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",r(o.role)]})]},i))})}function pe({id:t,label:n,onNavigate:r,renderLink:o}){return o?e.jsx(e.Fragment,{children:o(t,n)}):r?e.jsx("a",{href:`/${t}`,onClick:i=>{i.preventDefault(),r(t)},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:i=>i.currentTarget.style.borderBottomStyle="solid",onMouseLeave:i=>i.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function jn({id:t,title:n,edition:r,type:o,isDraft:i,authors:s,volumeText:a,meta:l,headerExtra:d}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"12px"},children:[e.jsxs("h1",{style:{fontSize:"24px",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.3,letterSpacing:"0.5px",flex:1,minWidth:0},children:[n,r&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:r}),a&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:a})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexShrink:0,paddingTop:"4px"},children:[e.jsx(mt,{type:o}),e.jsx(yn,{isDraft:i}),e.jsx(vn,{id:t}),d]})]}),((s==null?void 0:s.length)||l.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[s&&s.length>0&&e.jsx(yt,{authors:s,type:o}),l]})]})}function Sn({items:t,onNavigate:n,renderLink:r}){const o=W(),{convert:i}=F();if(!t.length)return null;const[s,a]=p.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:o.section.indexed}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((l,d)=>{const u=s===d;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...u?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>a(u?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:u?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:i(l.source)}),!u&&l.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i(l.title_info)}),l.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(pe,{id:l.source_bid,label:o.action.view,onNavigate:n,renderLink:r})})]}),u&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(l.title_info||l.author_info||l.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[l.title_info&&e.jsx(ie,{label:o.label.titleInfo,children:i(l.title_info)}),l.author_info&&e.jsx(ie,{label:o.label.authorInfo,children:i(l.author_info)}),l.edition&&e.jsx(ie,{label:o.label.edition,children:i(l.edition)})]}),l.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:i(l.summary)})]}),l.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:i(l.comment)})]}),l.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:i(l.additional_comment)})]})]})]},d)})})]})}function kn({items:t}){const n=W(),{convert:r}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:n.section.aliases}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((o,i)=>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:r(o)},i))})]}):null}function wn({items:t}){const n=W(),{convert:r}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((o,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:["《",r(o.book_title),"》",o.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[o.n_juan,n.unit.juan]})]},i))})]}):null}function Cn({items:t}){const n=W(),{convert:r}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((o,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:r(o.name)}),o.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:r(o.description)})]},i))]})]}):null}function zn({items:t}){const n=W(),{convert:r}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((o,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:"·"}),r(o)]},i))})]}):null}function Ze({title:t,ids:n,transport:r,onNavigate:o,renderLink:i}){const{convert:s}=F(),[a,l]=p.useState([]);return p.useEffect(()=>{if(!n.length){l([]);return}if(!r){l(n.map(u=>({id:u})));return}let d=!1;return Promise.all(n.map(u=>r.getItem(u).then(g=>({id:u,title:g?g.title:void 0,edition:g?g.edition:void 0,type:g?g.type:void 0})).catch(()=>({id:u})))).then(u=>{d||l(u)}),()=>{d=!0}},[n,r]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(Q,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(a.length?a:n.map(d=>({id:d}))).map(d=>{const u=d.edition?`${s(d.title)||d.id}(${s(d.edition)})`:s(d.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(pe,{id:d.id,label:u,onNavigate:o,renderLink:i})},d.id)})})]}):null}function In({book:t,onNavigate:n,renderLink:r}){const o=W(),{convert:i}=F(),[s,a]=p.useState(!1),l=t.resources&&t.resources.length>0,d=t.edition?`${i(t.title)||t.id}(${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:l&&!s?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1},children:e.jsx(pe,{id:t.id,label:d,onNavigate:n,renderLink:r})}),l&&e.jsx("span",{onClick:()=>a(u=>!u),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:s?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:s?o.action.expand:o.action.collapse,children:"▼"})]}),l&&!s&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(Me,{items:t.resources,groupByType:!0})})]})}function Tn({ids:t,transport:n,onNavigate:r,renderLink:o}){const i=W(),[s,a]=p.useState([]);return p.useEffect(()=>{if(!t.length){a([]);return}if(!n){a(t.map(d=>({id:d})));return}let l=!1;return Promise.all(t.map(d=>n.getItem(d).then(u=>({id:d,title:u?u.title:void 0,edition:u?u.edition:void 0,resources:u?u.resources:void 0})).catch(()=>({id:d})))).then(d=>{l||a(d)}),()=>{l=!0}},[t,n]),t.length?e.jsxs(e.Fragment,{children:[e.jsxs(Q,{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:(s.length?s:t.map(l=>({id:l}))).map(l=>e.jsx(In,{book:l,onNavigate:r,renderLink:o},l.id))})]}):null}function _n({workData:t,onNavigate:n,renderLink:r}){var s,a,l;const o=W(),{convert:i}=F();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(mt,{type:"work"}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(pe,{id:t.id,label:i(t.title),onNavigate:n,renderLink:r})}),((s=t.juan_count)==null?void 0:s.number)&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[bt(t.juan_count.number),o.unit.juan]})]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(yt,{authors:t.authors,type:"work"}),((a=t.description)==null?void 0:a.text)&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,margin:(l=t.authors)!=null&&l.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(ie,{label:o.label.parentWork,children:e.jsx(pe,{id:t.parent_work.id,label:i(t.parent_work.title),onNavigate:n,renderLink:r})})})]})]})}function Rn({items:t,onNavigate:n,renderLink:r}){const o=W(),{convert:i}=F();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(s=>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:o.indexType.collection}),e.jsx(pe,{id:s.id,label:i(s.title)||s.id,onNavigate:n,renderLink:r}),s.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:Se(o.catalog.volume,{n:s.volume_index})})]},s.id))}):null}const vt=({data:t,id:n,transport:r,onNavigate:o,renderLink:i,headerExtra:s,className:a,style:l})=>{var _,P,k,$,D,U;const d=W(),{convert:u}=F(),[g,x]=p.useState(null),[f,c]=p.useState(!1),[j,w]=p.useState(null),[b,E]=p.useState(null),[m,S]=p.useState([]),y=t||g;if(p.useEffect(()=>{if(t||!n||!r)return;let L=!1;return c(!0),w(null),r.getItem(n).then(M=>{L||(M?x(M):w(d.misc.notFoundEntry))}).catch(M=>{L||w(M instanceof Error?M.message:d.misc.loadFailed)}).finally(()=>{L||c(!1)}),()=>{L=!0}},[t,n,r]),p.useEffect(()=>{if(!y||!r){E(null),S([]);return}let L=!1;const M=y.type==="book"||y.type==="collection"?y.work_id:void 0;if(M?r.getItem(M).then(V=>{!L&&V&&V.type==="work"&&E(V)}).catch(()=>{}):E(null),y.type==="book"){const V=y;V.contained_in&&V.contained_in.length>0?Promise.all(V.contained_in.map(Y=>{const A=typeof Y=="string"?Y:Y.id,ee=typeof Y=="string"?void 0:Y.volume_index;return r.getItem(A).then(q=>({id:A,title:q&&q.title||A,volume_index:ee})).catch(()=>({id:A,title:A,volume_index:ee}))})).then(Y=>{L||S(Y)}):S([])}else S([]);return()=>{L=!0}},[y,r]),f)return e.jsx("div",{className:a,style:{...l,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((L,M)=>e.jsx("div",{style:{height:M===1?"32px":"16px",width:`${L}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},M))})});if(j)return e.jsx("div",{className:a,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:j});if(!y)return null;const I=y.type==="book"?y:null,T=y.type==="collection"?y:null,v=y.type==="work"?y:null;let h=!1;try{h=H.extractStatus(y.id)==="draft"}catch{}let R="";(_=y.juan_count)!=null&&_.number?R=bt(y.juan_count.number)+d.unit.juan:(P=y.juan_count)!=null&&P.description&&(R=u(y.juan_count.description));const C=[];return(k=y.publication_info)!=null&&k.year&&C.push(e.jsx(ie,{label:d.label.year,children:y.publication_info.year},"year")),($=y.current_location)!=null&&$.name&&C.push(e.jsx(ie,{label:d.label.currentLocation,children:u(y.current_location.name)},"loc")),(D=y.page_count)!=null&&D.description&&C.push(e.jsx(ie,{label:d.label.pageCount,children:y.page_count.description},"page")),I!=null&&I.edition&&C.push(e.jsx(ie,{label:d.label.edition,children:u(I.edition)},"ver")),v!=null&&v.parent_work&&C.push(e.jsx(ie,{label:d.label.parentWork,children:e.jsx(pe,{id:v.parent_work.id,label:u(v.parent_work.title),onNavigate:o,renderLink:i})},"pw")),v!=null&&v.parent_works&&v.parent_works.length>0&&!v.parent_work&&C.push(e.jsx(ie,{label:d.label.parentWork,children:v.parent_works.map((L,M)=>e.jsxs("span",{children:[M>0&&"、",e.jsx(pe,{id:L,onNavigate:o,renderLink:i})]},L))},"pws")),e.jsxs("div",{className:a,style:l,children:[e.jsx(jn,{id:y.id,title:u(y.title),edition:y.edition?u(y.edition):void 0,type:y.type,isDraft:h,authors:y.authors,volumeText:R,meta:C,headerExtra:s}),((U=y.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(y.description.text)}),m.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:d.section.containedIn}),e.jsx(Rn,{items:m,onNavigate:o,renderLink:i})]}),b&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:d.section.belongsToWork}),e.jsx(_n,{workData:b,onNavigate:o,renderLink:i})]}),y.additional_works&&y.additional_works.length>0&&e.jsx(wn,{items:y.additional_works}),y.additional_titles&&y.additional_titles.length>0&&e.jsx(kn,{items:y.additional_titles}),y.indexed_by&&y.indexed_by.length>0&&e.jsx(Sn,{items:y.indexed_by,onNavigate:o,renderLink:i}),y.resources&&y.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:d.section.resources}),e.jsx(Me,{items:y.resources,groupByType:!0})]}),(I==null?void 0:I.location_history)&&I.location_history.length>0&&e.jsx(Cn,{items:I.location_history}),(T==null?void 0:T.history)&&T.history.length>0&&e.jsx(zn,{items:T.history}),(I==null?void 0:I.related_books)&&I.related_books.length>0&&e.jsx(Ze,{title:d.section.relatedVersions,ids:I.related_books,transport:r,onNavigate:o,renderLink:i}),(T==null?void 0:T.books)&&T.books.length>0&&e.jsx(Ze,{title:d.section.containedBooks,ids:T.books,transport:r,onNavigate:o,renderLink:i}),(v==null?void 0:v.books)&&v.books.length>0&&e.jsx(Tn,{ids:v.books,transport:r,onNavigate:o,renderLink:i}),(v==null?void 0:v.related_works)&&v.related_works.length>0&&(()=>{const L=[],M=v.related_works.filter(A=>A.relation==="part_of"),V=v.related_works.filter(A=>A.relation==="has_part"),Y=v.related_works.filter(A=>!A.relation);return M.length>0&&L.push({label:d.section.belongsToWork,items:M}),V.length>0&&L.push({label:d.section.containedWorks,items:V}),Y.length>0&&L.push({label:d.section.relatedWorks,items:Y}),L.map(A=>e.jsxs("div",{children:[e.jsxs(Q,{children:[A.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",A.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:A.items.map(ee=>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(pe,{id:ee.id,label:u(ee.title),onNavigate:o,renderLink:i})},ee.id))})]},A.label))})()]})};function Ln({data:t}){const n=W(),{convert:r}=F(),{stats:o}=t,i=o.processed_volumes??o.total_found_volumes,s=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:r(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:r(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]}),s!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:i})," ",n.unit.volume," (",s,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.total_books})," ",n.unit.bu]}),o.matched_works!=null&&o.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.matched_works})," ",n.unit.bu]}),o.unmatched_works!=null&&o.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"#e67e22"},children:o.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function En({sections:t,activeSection:n,onSelect:r}){const o=W();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>r(null),style:Xe(n===null),children:o.catalog.all}),t.map(i=>e.jsxs("button",{onClick:()=>r(i.name),style:Xe(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 Xe(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 Bn({id:t,label:n,onNavigate:r,renderLink:o}){return o?e.jsx(e.Fragment,{children:o(t,n)}):r?e.jsx("a",{href:`/${t}`,onClick:i=>{i.preventDefault(),r(t)},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px",fontSize:"12px"},onMouseEnter:i=>i.currentTarget.style.borderBottomStyle="solid",onMouseLeave:i=>i.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function Wn(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const r=t[0],o=t[t.length-1];return o-r+1===t.length?`${r}–${o}`:t.length<=3?t.join(", "):`${r}–${o} (${t.length}${n})`}function qe({book:t,onNavigate:n,renderLink:r,showVolumes:o}){const i=W(),{convert:s}=F(),a=t.book_id||t.work_id,l=o&&t.volumes.length>0?Wn(t.volumes,i.unit.volume):null,d=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[o&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:l}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[s(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=>s(u)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:s(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:d?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,i.unit.volume]}),a&&e.jsx(Bn,{id:a,label:t.book_id?i.indexType.book:i.indexType.work,onNavigate:n,renderLink:r}),!a&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:i.catalog.unmatched_label})]})}const jt=({data:t,collectionId:n,transport:r,onNavigate:o,renderLink:i,className:s,style:a})=>{const l=W(),[d,u]=p.useState(null),[g,x]=p.useState(!1),[f,c]=p.useState(null),[j,w]=p.useState(null),[b,E]=p.useState(""),m=t||d;p.useEffect(()=>{if(t||!n||!(r!=null&&r.getCollectionCatalog))return;let v=!1;return x(!0),c(null),r.getCollectionCatalog(n).then(h=>{v||(h?u(h):c(l.catalog.notFound))}).catch(h=>{v||c(h instanceof Error?h.message:l.catalog.loadFailed)}).finally(()=>{v||x(!1)}),()=>{v=!0}},[t,n,r,l]);const S=(m==null?void 0:m.sections)&&m.sections.length>0,y=p.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const v=m.books.map(R=>R.volumes[0]).filter(R=>R!=null);return new Set(v).size<v.length},[m]),I=p.useMemo(()=>{if(!m)return[];let v=m.books;if(j&&(v=v.filter(h=>h.section===j)),b.trim()){const h=b.trim().toLowerCase();v=v.filter(R=>R.title.toLowerCase().includes(h)||R.sub_items&&R.sub_items.some(C=>C.toLowerCase().includes(h))||R.edition&&R.edition.toLowerCase().includes(h))}return v},[m,j,b]),T=p.useMemo(()=>{if(!y)return null;const v=[],h=new Map;for(const C of I){if(!C.volumes||C.volumes.length===0)continue;const _=C.volumes[0];h.has(_)||h.set(_,[]),h.get(_).push(C)}const R=[...h.keys()].sort((C,_)=>C-_);for(const C of R)v.push({volume:C,books:h.get(C)});return v},[I,y]);return g?e.jsx("div",{className:s,style:{...a,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:l.catalog.loading})}):f?e.jsx("div",{className:s,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:f}):m?e.jsxs("div",{className:s,style:a,children:[e.jsx(Ln,{data:m}),S&&e.jsx(En,{sections:m.sections,activeSection:j,onSelect:w}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:l.search.searchBookName,value:b,onChange:v=>E(v.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[I.length," ",l.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[T?T.map((v,h)=>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:Se(l.catalog.volume,{n:v.volume})}),v.books.map((R,C)=>e.jsx(qe,{book:R,onNavigate:o,renderLink:i,showVolumes:R.volumes.length>1},`${v.volume}-${C}`))]},`${v.volume}-${h}`)):I.map((v,h)=>e.jsx(qe,{book:v,onNavigate:o,renderLink:i,showVolumes:!0},h)),I.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:l.catalog.noMatch})]})]}):null},$n=["〇","一","二","三","四","五","六","七","八","九"],Qe=["","十","百","千"],Pn=["","萬","億"];function St(t){if(t===0)return"〇";if(t<0)return`負${St(-t)}`;const n=[];let r=t,o=0;for(;r>0;){const i=r%1e4;i>0?n.unshift(An(i,o>0)+Pn[o]):n.length>0&&n.unshift("〇"),r=Math.floor(r/1e4),o++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function An(t,n){const r=[];let o=t;for(;o>0;)r.unshift(o%10),o=Math.floor(o/10);let i="";for(let s=0;s<r.length;s++){const a=r[s],l=r.length-1-s;a===0?i&&!i.endsWith("〇")&&(i+="〇"):a===1&&l===1&&s===0&&!n?i+=Qe[l]:i+=$n[a]+Qe[l]}return i.replace(/〇$/,"")}const kt={部:"#2471a3",类:"#8e6f3e",书:"#c0392b",其他:"#717171"};function Mn(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 wt({file:t,isActive:n,onSelect:r}){return e.jsx("button",{onClick:()=>r(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:Mn(t)})}function Ct(t,n){var r;return t.files.includes(n)?!0:!!((r=t.children)!=null&&r.some(o=>Ct(o,n)))}function zt(t){var o;const n=t.files.length,r=((o=t.children)==null?void 0:o.reduce((i,s)=>i+zt(s),0))||0;return n+r}function It({group:t,activeFile:n,onSelect:r,depth:o=0}){var u;const i=Ct(t,n||""),[s,a]=p.useState(i),l=zt(t),d=!!((u=t.children)!=null&&u.length);return p.useEffect(()=>{i&&a(!0)},[i]),e.jsxs("div",{style:{marginBottom:o===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>a(!s),style:{display:"flex",alignItems:"center",gap:"6px",padding:o===0?"4px 8px":"2px 8px",paddingLeft:`${8+o*16}px`,cursor:"pointer",userSelect:"none",fontSize:o===0?"13px":"12px",fontWeight:o===0?600:500,color:i?"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:["(",l,")"]})]}),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+o*16}px`},children:t.files.map(g=>e.jsx(wt,{file:g,isActive:n===g,onSelect:r},g))}),d&&t.children.map((g,x)=>e.jsx(It,{group:g,activeFile:n,onSelect:r,depth:o+1},x))]})]})}function Fn({files:t,groups:n,activeFile:r,onSelect:o}){return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((i,s)=>e.jsx(It,{group:i,activeFile:r,onSelect:o},s))}):e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:t.map(i=>e.jsx(wt,{file:i,isActive:r===i,onSelect:o},i))})}function Hn({type:t}){const n=kt[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 On({section:t,onNavigate:n}){const{convert:r}=F(),[o,i]=p.useState(!1),s=!!t.summary,a=!!t.comment,l=!!t.additional_comment,d=s||a||l;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&&i(!o),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:o?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)",flex:1},children:[t.book_title?`《${r(t.book_title)}》`:r(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[St(t.n_juan),"卷"]})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(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:`/${t.work_id}`,onClick:u=>{u.preventDefault(),u.stopPropagation(),n(t.work_id)},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),o&&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:r(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:r(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:r(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:r(t.additional_comment)})]})]})]})}function Dn({section:t}){const{convert:n}=F(),[r,o]=p.useState(!1),i=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>i&&o(!r),style:{display:"flex",alignItems:"center",gap:"8px",cursor:i?"pointer":"default",userSelect:"none"},children:[e.jsx(Hn,{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:r?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),r&&i&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${kt[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 Vn({section:t}){const{convert:n}=F();if(!t.content&&!t.title)return null;const r=n((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
1
|
+
"use strict";var Ot=Object.create;var He=Object.defineProperty;var Dt=Object.getOwnPropertyDescriptor;var Vt=Object.getOwnPropertyNames;var Nt=Object.getPrototypeOf,Ut=Object.prototype.hasOwnProperty;var Yt=(t,n,r,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of Vt(n))!Ut.call(t,i)&&i!==r&&He(t,i,{get:()=>n[i],enumerable:!(o=Dt(n,i))||o.enumerable});return t};var Gt=(t,n,r)=>(r=t!=null?Ot(Nt(t)):{},Yt(n||!t||!t.__esModule?He(r,"default",{value:t,enumerable:!0}):r,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("./storage-entry-CAvzCo5k.cjs"),e=require("react/jsx-runtime"),p=require("react"),je=p.createContext(null),xt={indexType:{work:"作品",book:"書籍",collection:"叢編"},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:"+ 添加收錄來源",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:"上級作品",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:"📖 著錄於",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",appendix:"附錄",containedIn:"收入",belongsToWork:"所屬作品",locationHistory:"流轉���史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄",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:"清除全部",searchTitle:"搜索古籍索引",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"叢書目錄",siteTab:"在線資源",recommendTab:"推薦",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",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:"圖片資源"}},Jt={indexType:{work:"作品",book:"书籍",collection:"丛编"},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:"+ 添加收录来源",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:"上级作品",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:"📖 著录于",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",appendix:"附录",containedIn:"收入",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录",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:"清除全部",searchTitle:"搜索古籍索引",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"丛书目录",siteTab:"在线资源",recommendTab:"推荐",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",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:"图片资源"}},Kt={"zh-Hant":xt,"zh-Hans":Jt},Zt=({locale:t,onLocaleChange:n,children:r})=>{const[o,i]=p.useState(t??"zh-Hant"),s=t??o,[a,l]=p.useState(null);p.useEffect(()=>{s==="zh-Hans"?import("opencc-js/t2cn").then(g=>{const x=g.Converter({from:"tw",to:"cn"});l(()=>x)}).catch(()=>{l(()=>g=>g)}):l(null)},[s]);const d=p.useCallback(g=>{i(g),n==null||n(g)},[n]),u=p.useMemo(()=>({locale:s,setLocale:d,messages:Kt[s],converter:a}),[s,d,a]);return e.jsx(je.Provider,{value:u,children:r})};function W(){const t=p.useContext(je);return(t==null?void 0:t.messages)??xt}const Xt=2e3;function F(){const t=p.useContext(je),n=(t==null?void 0:t.locale)??"zh-Hant",r=(t==null?void 0:t.converter)??null,o=p.useRef(new Map),i=p.useRef(n);i.current!==n&&(o.current.clear(),i.current=n);const s=p.useCallback(a=>{if(!a)return"";if(!r)return a;const l=o.current.get(a);if(l!==void 0)return l;const d=r(a);if(o.current.size>=Xt){const u=o.current.keys().next().value;u!==void 0&&o.current.delete(u)}return o.current.set(a,d),d},[r]);return p.useMemo(()=>({convert:s,locale:n,isSimplified:n==="zh-Hans"}),[s,n])}function Se(t,n){return t.replace(/\{(\w+)\}/g,(r,o)=>String(n[o]??""))}function qt(t){if(!t)return"";try{const n=new URL(t).hostname,r={"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(r[n])return r[n];const o=n.split(".");return o.length>=2?o[o.length-2]:n}catch{return""}}function Qt(){return{id:"",name:"",url:"",type:"text",details:""}}const We=({items:t,onChange:n,onDownload:r,downloadStatuses:o,filterType:i})=>{const s=W(),[a,l]=p.useState(null),d=[{value:"text",label:s.resourceTypeShort.text},{value:"image",label:s.resourceTypeShort.image},{value:"text+image",label:s.resourceTypeShort.textImage},{value:"physical",label:s.resourceTypeShort.physical}],u=[{value:"catalog",label:s.rootType.catalog},{value:"search",label:s.rootType.search}],g=m=>i?i==="text"?m==="text"||m==="text+image":i==="image"?m==="image"||m==="text+image"||m==="physical":m===i:!0,x=t.map((m,S)=>({item:m,originalIndex:S})).filter(({item:m})=>g(m.type)),f=()=>{const m=Qt();i&&(m.type=i),n([...t,m]),l(t.length)},c=m=>{n(t.filter((S,y)=>y!==m)),l(null)},j=(m,S,y)=>{const I=[...t];if(I[m]={...I[m],[S]:y},S==="url"&&!I[m].id){const T=qt(y);T&&(I[m].id=T)}n(I)},w=(m,S,y)=>{const T={...t[m].metadata||{}};y?T[S]=y:delete T[S],j(m,"metadata",Object.keys(T).length>0?T:void 0)},b=(m,S)=>{const y=S.trim()?S.split(/[,,、]/).map(I=>I.trim()).filter(Boolean):void 0;j(m,"structure",y)},E=(m,S,y)=>{const T=t[m].coverage||{level:1,ranges:""};S==="level"?T.level=parseInt(y)||1:T.ranges=y,j(m,"coverage",T.ranges?T:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:m,originalIndex:S})=>{var y,I,T,v;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:()=>l(a===S?null:S),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:a===S?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:en(m.type),color:"#fff"},children:((y=d.find(h=>h.value===m.type))==null?void 0:y.label)||m.type}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.name||`${s.editor.resourcePlaceholder} ${S+1}`}),m.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:m.id}),m.url&&e.jsx("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",onClick:h=>h.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),r&&m.url&&tn(S,o==null?void 0:o[S],r,s),e.jsx("button",{onClick:h=>{h.stopPropagation(),c(S)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:s.editor.deleteThisResource,children:"✕"})]}),a===S&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(m.type==="image"||m.type==="text+image")&&m.url&&nn(m,s),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:be,children:[e.jsx("span",{style:me,children:s.label.type}),e.jsx("select",{value:m.type,onChange:h=>j(S,"type",h.target.value),style:{...oe,flex:1},children:d.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value))})]}),e.jsxs("label",{style:be,children:[e.jsx("span",{style:me,children:s.label.rootType}),e.jsx("select",{value:m.root_type||"catalog",onChange:h=>j(S,"root_type",h.target.value),style:{...oe,flex:1},children:u.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:m.id,onChange:h=>j(S,"id",h.target.value),placeholder:s.editor.idAutoExtract,style:{...oe,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:m.name,onChange:h=>j(S,"name",h.target.value),placeholder:s.editor.resourceName,style:{...oe,flex:1}})]}),e.jsx("input",{type:"text",value:m.url,onChange:h=>j(S,"url",h.target.value),placeholder:s.editor.resourceUrl,style:oe}),e.jsx("input",{type:"text",value:((I=m.structure)==null?void 0:I.join("、"))||"",onChange:h=>b(S,h.target.value),placeholder:s.editor.structurePlaceholder,style:oe}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:be,children:[e.jsx("span",{style:me,children:s.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((T=m.coverage)==null?void 0:T.level)??"",onChange:h=>E(S,"level",h.target.value),placeholder:"1",style:{...oe,width:"60px"}})]}),e.jsxs("label",{style:{...be,flex:1},children:[e.jsx("span",{style:me,children:s.label.coverageRange}),e.jsx("input",{type:"text",value:((v=m.coverage)==null?void 0:v.ranges)||"",onChange:h=>E(S,"ranges",h.target.value),placeholder:s.editor.coverageRangePlaceholder,style:{...oe,flex:1}})]})]}),e.jsx("textarea",{value:m.details||"",onChange:h=>j(S,"details",h.target.value),placeholder:s.editor.detailsPlaceholder,style:{...oe,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:s.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(s.metadata).map(([h,R])=>{var C;return e.jsxs("label",{style:{...be,gap:"4px"},children:[e.jsx("span",{style:{...me,minWidth:"56px"},children:R}),e.jsx("input",{type:"text",value:((C=m.metadata)==null?void 0:C[h])||"",onChange:_=>w(S,h,_.target.value),placeholder:R,style:{...oe,flex:1}})]},h)})})]})]})]})]},S)}),e.jsxs("button",{onClick:f,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:s.action.addResource})]})]})};function en(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function tn(t,n,r,o){const i=(n==null?void 0:n.status)==="downloading",s=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:a=>{a.stopPropagation(),i||r(t,"")},disabled:i,style:{background:"transparent",border:"none",color:s?"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:s?o.download.completed:i?`${o.download.downloading} ${(n==null?void 0:n.progress)||0}%`:o.download.downloadThis,children:s?"✓":i?"⏳":"⬇"})}function nn(t,n){const r=/\.(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:r?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:o=>{o.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 oe={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"},be={display:"flex",alignItems:"center",gap:"6px"},me={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},on={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function rn(t){try{const n=new URL(t).hostname;return on[n]}catch{return}}const Oe={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"},ln=["text","image","text+image","physical"];function sn(t){const n=s=>{const a=s.match(/^(.+?)·第(\d+)[冊册]$/);if(a)return[a[1],parseInt(a[2])];const l=s.match(/^(.+?)[·(](\d+)[)]?$/);return l?[l[1],parseInt(l[2])]:null},r=new Map,o=[],i=new Set;for(let s=0;s<t.length;s++){const a=t[s];if(a.volumes&&a.volumes.length>0)continue;const l=n(a.name);if(!l)continue;const[d,u]=l,g=`${d}|${a.type}`;r.has(g)||r.set(g,{base:{...a,name:d,url:"",volumes:[]},volumes:[]}),r.get(g).volumes.push({volume:u,url:a.url||void 0,status:"found"}),i.add(s)}for(const[,s]of r)if(s.volumes.length>=2)s.volumes.sort((a,l)=>a.volume-l.volume),s.base.volumes=s.volumes,s.base.expected_volumes=s.volumes.length,o.push(s.base);else for(let a=0;a<t.length;a++)if(i.has(a)){const l=n(t[a].name);l&&`${l[0]}|${t[a].type}`==`${s.base.name}|${s.base.type}`&&i.delete(a)}for(let s=0;s<t.length;s++)i.has(s)||o.push(t[s]);return o}const Me=({items:t,groupByType:n=!0})=>{const r=W(),o=p.useMemo(()=>sn(t||[]),[t]),i={text:r.resourceType.text,image:r.resourceType.image,"text+image":r.resourceType.textImage,physical:r.resourceType.physical};if(!o||o.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:r.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:o.map((a,l)=>e.jsx(Ve,{item:a},a.id||l))});const s=ln.map(a=>({type:a,items:o.filter(l=>l.type===a)})).filter(a=>a.items.length>0);return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:s.map(({type:a,items:l})=>e.jsxs("div",{children:[e.jsxs("h4",{style:{margin:"0 0 8px",fontSize:"13px",fontWeight:600,color:Oe[a],display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx("span",{style:{display:"inline-block",width:"4px",height:"14px",borderRadius:"2px",background:Oe[a]}}),i[a],e.jsxs("span",{style:{fontWeight:400,opacity:.6},children:["(",l.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:l.map((d,u)=>e.jsx(Ve,{item:d},d.id||u))})]},a))})},De=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},ut=({value:t})=>{const r=W().checkType[t];return r?e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:r.bg,color:r.fg},children:r.label}):e.jsx("span",{children:t})},an=(t,n,r)=>t==="check_type"&&typeof n=="string"?e.jsx(ut,{value:n}):t==="has_translation"?n?r.misc.hasTranslation:r.misc.noTranslation:String(n);function dn(t){if(t.url)return t.url;for(const[n,r]of Object.entries(t))if(n.endsWith("_url")&&typeof r=="string")return r}const cn={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},Ve=({item:t})=>{var f;const n=W(),{convert:r}=F(),[o,i]=p.useState(!1),s=p.useMemo(()=>(t.url?rn(t.url):void 0)||r(t.name),[t.url,t.name,r]),a=p.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(c=>({...c,url:c.url||dn(c)})),[t.volumes]),l=a&&a.length>0,d=l?a.filter(c=>c.status!=="missing").length:0,u=l?a.length-d:0,g=t.expected_volumes??(l?a.length:0),x=t.color_mode?{...cn[t.color_mode],label:n.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:De(t)||l?"6px":"0"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:s}),x&&e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:x.bg,color:x.fg},children:x.label}),t.source_label&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",fontStyle:"italic"},children:t.source_label}),((f=t.metadata)==null?void 0:f.check_type)&&e.jsx(ut,{value:t.metadata.check_type}),l&&e.jsxs("button",{onClick:()=>i(!o),style:{padding:"1px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer"},children:[d,"/",g,n.unit.volume,u>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"4px"},children:["缺",u]}),e.jsx("span",{style:{marginLeft:"4px"},children:o?"▲":"▼"})]}),t.url&&e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:n.action.visit})]}),De(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(([c])=>c!=="check_type").map(([c,j])=>e.jsxs("span",{children:[n.metadata[c]||c,": ",an(c,j,n)]},c)),t.details&&!l&&e.jsx("span",{children:t.details}),t.structure&&e.jsxs("span",{children:[n.misc.structure,": ",t.structure.join(" → ")]}),t.coverage&&e.jsxs("span",{children:[n.misc.coverage,": L",t.coverage.level," ",t.coverage.ranges]})]}),l&&o&&e.jsx("div",{style:{marginTop:"8px",padding:"8px 0",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",display:"flex",flexWrap:"wrap",gap:"4px"},children:a.map(c=>{const j=c.status==="missing";return e.jsx("span",{style:{display:"inline-flex"},children:c.url&&!j?e.jsx("a",{href:c.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:c.label||`${c.volume}`,children:c.volume}):e.jsx("span",{style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid transparent",color:j?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:j?"line-through":"none",opacity:j?.6:1,lineHeight:1.4},children:c.volume})},c.volume)})})]})},gt=({indexSource:t,syncConfig:n,variant:r="index-browser",onSwitchMode:o,onToggleDraft:i,onConfigurePath:s,onSelectFolder:a})=>{const l=W(),d=t==="local",u=(n==null?void 0:n.isDraft)??!0,g=(n==null?void 0:n.repoPath)||"",x=g?g.split(/[/\\]/).pop()||g:"",f={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)"},c={onMouseOver:w=>w.currentTarget.style.opacity="0.8",onMouseOut:w=>w.currentTarget.style.opacity="1"},j=e.jsxs("div",{onClick:i,title:u?l.mode.switchToOfficial:l.mode.switchToDraft,style:{...f,background:u?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...c,children:[e.jsx("span",{children:u?"📝":"📚"}),e.jsx("span",{children:u?"draft":"official"})]});return r==="index-browser"?d?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[j,e.jsxs("div",{onClick:o,title:l.mode.switchToSync,style:f,...c,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:l.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:a,title:g||l.mode.selectFolder,style:{...f,paddingLeft:"8px",paddingRight:"8px"},...c,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[j,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:o,title:l.mode.switchToLocal,style:f,...c,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:l.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:s,title:x||l.mode.configurePath,style:{...f,background:"transparent",padding:"6px",fontSize:"12px"},...c,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:o,title:d?l.mode.switchToGithub:l.mode.switchToLocal,style:f,...c,children:[e.jsx("span",{children:d?"📁":"🌐"}),e.jsx("span",{children:d?l.mode.localMode:l.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),d&&e.jsxs("div",{onClick:a,title:g||l.mode.selectFolder,style:{...f,paddingLeft:"8px",paddingRight:"8px",minWidth:g?"100px":"auto",justifyContent:"space-between"},...c,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!d&&x&&e.jsxs("div",{style:{...f,background:"#2196f3",color:"white",cursor:"default"},title:g,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:x})]})]})},Te="bim-search-history",Ne=10,Ue=8;function ve(){try{const t=localStorage.getItem(Te);return t?JSON.parse(t):[]}catch{return[]}}function pn(t){try{const n=ve().filter(r=>r!==t);n.unshift(t),n.length>Ne&&(n.length=Ne),localStorage.setItem(Te,JSON.stringify(n))}catch{}}function xn(t){try{const n=ve().filter(r=>r!==t);localStorage.setItem(Te,JSON.stringify(n))}catch{}}function un(){try{localStorage.removeItem(Te)}catch{}}const ft=({transport:t,value:n,onChange:r,onSearch:o,onEntrySelect:i,placeholder:s})=>{const a=W(),l=s??a.search.placeholder,d={work:a.indexType.work,book:a.indexType.book,collection:a.indexType.collection},[u,g]=p.useState(!1),[x,f]=p.useState([]),[c,j]=p.useState(-1),[w,b]=p.useState(null),[E,m]=p.useState(ve),S=p.useRef(null),y=p.useRef(null),I=p.useRef(null);p.useEffect(()=>{if(!t.getAllEntries)return;let k=!1;return t.getAllEntries().then($=>{k||b($)}).catch(()=>{}),()=>{k=!0}},[t]);const T=p.useCallback(k=>{if(!k.trim())return E.map(L=>({type:"history",text:L}));if(!w)return[];const $=k.toLowerCase(),D=[],U=[];for(const L of w){if(D.length+U.length>=Ue*2)break;const M=L.title.toLowerCase();if(M.startsWith($))D.push({type:"entry",text:L.title,entry:L});else if(M.includes($))U.push({type:"entry",text:L.title,entry:L});else if(L.additional_titles){for(const V of L.additional_titles)if(V.toLowerCase().includes($)){D.push({type:"entry",text:`${L.title}`,entry:L});break}}}return[...D,...U].slice(0,Ue)},[w,E]);p.useEffect(()=>{f(T(n)),j(-1)},[n,T]),p.useEffect(()=>{const k=$=>{I.current&&!I.current.contains($.target)&&g(!1)};return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[]),p.useEffect(()=>{const k=$=>{var D,U;if($.key==="/"&&document.activeElement!==S.current){const L=(D=document.activeElement)==null?void 0:D.tagName;if(L==="INPUT"||L==="TEXTAREA"||L==="SELECT")return;$.preventDefault(),(U=S.current)==null||U.focus()}};return document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[]);const v=p.useCallback(k=>{k.trim()&&(pn(k.trim()),m(ve())),o(k),g(!1)},[o]),h=p.useCallback(k=>{k.type==="history"?(r(k.text),v(k.text)):k.entry&&(i?(i(k.entry),g(!1)):(r(k.text),v(k.text)))},[r,v,i]),R=p.useCallback(k=>{if(!u||x.length===0){k.key==="Enter"&&v(n);return}switch(k.key){case"ArrowDown":k.preventDefault(),j($=>($+1)%x.length);break;case"ArrowUp":k.preventDefault(),j($=>($-1+x.length)%x.length);break;case"Enter":k.preventDefault(),c>=0&&c<x.length?h(x[c]):v(n);break;case"Escape":k.preventDefault(),g(!1);break}},[u,x,c,n,v,h]),C=p.useCallback((k,$)=>{$.stopPropagation(),xn(k),m(ve()),f(D=>D.filter(U=>!(U.type==="history"&&U.text===k)))},[]),_=p.useCallback(k=>{k.stopPropagation(),un(),m([]),f([])},[]);p.useEffect(()=>{if(c>=0&&y.current){const k=y.current.children;k[c]&&k[c].scrollIntoView({block:"nearest"})}},[c]);const P=!n.trim()&&E.length>0;return e.jsxs("div",{ref:I,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:S,type:"text",placeholder:l,value:n,onChange:k=>{r(k.target.value),g(!0)},onFocus:()=>g(!0),onKeyDown:R,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&&x.length>0&&e.jsxs("div",{ref:y,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[P&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:a.search.history}),e.jsx("button",{onClick:_,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:a.search.clearAll})]}),x.map((k,$)=>e.jsxs("div",{onClick:()=>h(k),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:$===c?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:k.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:k.text}),k.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[d[k.entry.type],k.entry.edition&&` · ${k.entry.edition}`,k.entry.author&&` · ${k.entry.author}`]}),k.type==="history"&&e.jsx("button",{onClick:D=>C(k.text,D),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:a.action.remove,children:"×"})]},`${k.type}-${k.text}-${$}`))]})]})},$e="bim-recent-ids",Ye="bim-recent-entries",Ge=50,Re=5,gn=50,fn=200;function Pe(){try{const t=localStorage.getItem($e);if(t)return JSON.parse(t);const n=localStorage.getItem(Ye);if(n){const r=JSON.parse(n).map(o=>o.id);return localStorage.setItem($e,JSON.stringify(r)),localStorage.removeItem(Ye),r}return[]}catch{return[]}}function hn(t){try{const n=Pe().filter(r=>r!==t);n.unshift(t),n.length>Ge&&(n.length=Ge),localStorage.setItem($e,JSON.stringify(n))}catch{}}const bn={works:"totalWorks",books:"totalBooks",collections:"totalCollections"},ht=({transport:t,indexSource:n="local",syncConfig:r,onEntryClick:o,onNewEntry:i,onSwitchMode:s,onToggleDraft:a,onConfigurePath:l,onSelectFolder:d,hideModeIndicator:u,initialQuery:g,onQueryChange:x,headerRight:f})=>{const c=W(),j=[{type:"work",icon:"✍️",name:c.indexType.work,key:"works"},{type:"book",icon:"📖",name:c.indexType.book,key:"books"},{type:"collection",icon:"📚",name:c.indexType.collection,key:"collections"}],[w,b]=p.useState(g??""),[E,m]=p.useState(null),[S,y]=p.useState(null),[I,T]=p.useState(!1),[v,h]=p.useState(null),[R,C]=p.useState(""),[_,P]=p.useState(!g),[k,$]=p.useState(Pe),[D,U]=p.useState([]),[L,M]=p.useState(!1),[V,Y]=p.useState(!1),[A,ee]=p.useState(null),q=p.useRef(void 0),te=p.useRef(!1),ne=p.useCallback(async(B,G)=>{if(!B.trim()){P(!0),m(null),y(null);return}P(!1),T(!0),C("");try{if(t.searchAll){const O=await t.searchAll(B,G??Re);m(O)}else{const O=["work","book","collection"],Z=await Promise.all(O.map(se=>t.search(B,se,{page:1,pageSize:G??Re})));m({works:Z[0].entries,books:Z[1].entries,collections:Z[2].entries,totalWorks:Z[0].total,totalBooks:Z[1].total,totalCollections:Z[2].total})}}catch(O){C(O instanceof Error?O.message:String(O)),m(null)}finally{T(!1)}},[t]);p.useEffect(()=>{let B=!1;const G=["work","book","collection"];return Promise.all(G.map(O=>t.loadEntries(O,{page:1,pageSize:1}).catch(()=>({total:0})))).then(O=>{B||ee({works:O[0].total,books:O[1].total,collections:O[2].total})}),()=>{B=!0}},[t]),p.useEffect(()=>{te.current||!(g!=null&&g.trim())||(te.current=!0,ne(g))},[g,ne]);const xe=p.useCallback(B=>{if(b(B),x==null||x(B),!B.trim()){P(!0),m(null),y(null);return}q.current&&clearTimeout(q.current),q.current=setTimeout(()=>{y(null),ne(B)},fn)},[ne,x]),le=p.useCallback(B=>{q.current&&clearTimeout(q.current),x==null||x(B),ne(B)},[ne,x]),N=p.useCallback(B=>{y(B),ne(w,gn)},[w,ne]);p.useEffect(()=>{if(!k.length){U([]);return}let B=!1;return M(!0),Promise.all(k.slice(0,10).map(async G=>{var O,Z,se;try{if(t.getEntry){const J=await t.getEntry(G);if(J)return J}const ae=await t.getItem(G);if(ae){const J=ae.authors;return{id:G,title:ae.title||G,type:ae.type||"work",author:(O=J==null?void 0:J[0])==null?void 0:O.name,dynasty:(Z=J==null?void 0:J[0])==null?void 0:Z.dynasty,role:(se=J==null?void 0:J[0])==null?void 0:se.role,edition:ae.edition||void 0}}}catch{}return null})).then(G=>{B||(U(G.filter(O=>O!==null)),M(!1))}),()=>{B=!0}},[k,t]);const he=B=>{h(B.id),hn(B.id),$(Pe()),o==null||o(B)},ke=B=>j.find(G=>G.type===B),_e=E&&(E.works.length>0||E.books.length>0||E.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:c.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[f,!u&&e.jsx(gt,{variant:"index-browser",indexSource:n,syncConfig:r,onSwitchMode:s,onToggleDraft:a,onConfigurePath:l,onSelectFolder:d})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(ft,{transport:t,value:w,onChange:xe,onSearch:le,onEntrySelect:he}),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:c.action.newEntry})]}),A&&_&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[c.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:A.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),c.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:A.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),c.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:A.collections.toLocaleString()})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:I?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:c.search.searching}):R?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:R})]}):_?e.jsx("div",{style:{flex:1},children:L?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:c.search.loading}):D.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:c.search.recentBrowse}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:D.slice(0,V?10:3).map(B=>e.jsx(Je,{entry:B,selected:v===B.id,onClick:he,getConfig:ke},B.id))}),!V&&D.length>3&&e.jsx("button",{onClick:()=>Y(!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:c.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:c.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.search.searchSubtitle})]})}):_e?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:j.map(({type:B,icon:G,name:O,key:Z})=>{const se=E[Z],ae=bn[Z],J=E[ae];if(se.length===0)return null;const we=!(S===B)&&J>Re;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:[G," ",O,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[J," ",c.unit.items]})]}),we&&e.jsx("button",{onClick:()=>N(B),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:c.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:se.map(z=>e.jsx(Je,{entry:z,selected:v===z.id,onClick:he,getConfig:ke,query:w},z.id))})]},B)})}):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:Se(c.search.noResultsFor,{query:w})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.search.tryOther})]})})]})},Je=({entry:t,selected:n,onClick:r,getConfig:o,query:i})=>{const s=W(),{convert:a}=F(),l=i&&t.additional_titles?t.additional_titles.find(d=>d.toLowerCase().includes(i.toLowerCase())):void 0;return e.jsxs("div",{onClick:()=>r(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:o(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:o(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:a(t.title)}),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:a(t.edition)}),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]})]}),(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:["〔",a(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:a(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",a(t.role)]})]}),l&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[s.search.alias,":",a(l)]})]}),e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},mn=["〇","一","二","三","四","五","六","七","八","九"],Ke=["","十","百","千"];function bt(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),r=n.length;let o="",i=!1;for(let s=0;s<r;s++){const a=parseInt(n[s]),l=r-1-s;a===0?i=!0:(i&&o&&(o+="〇"),i=!1,a===1&&l===1&&s===0?o+=Ke[l]:o+=mn[a]+Ke[l])}return o}function mt({type:t}){const n=W(),r={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3"};return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:r[t],border:`1px solid ${r[t]}40`,borderRadius:"2px",background:`${r[t]}08`},children:n.indexType[t]})}function yn({isDraft:t}){const n=W();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 vn({id:t}){const n=W(),[r,o]=p.useState(!1),i=()=>{navigator.clipboard.writeText(t).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"3px 8px 3px 10px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"#f6f6f6",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"12px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:i,title:r?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"13px",opacity:r?1:.5,transition:"opacity 0.15s"},onMouseEnter:s=>s.currentTarget.style.opacity="1",onMouseLeave:s=>s.currentTarget.style.opacity=r?"1":"0.5",children:r?"✓":"⧉"})]})}function Q({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 ie({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 yt({authors:t,type:n}){const{convert:r}=F();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((o,i)=>e.jsxs("span",{children:[i>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),o.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",r(o.dynasty),"〕"]}),e.jsx("span",{style:{fontWeight:500},children:r(o.name)}),o.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",r(o.role)]})]},i))})}function pe({id:t,label:n,onNavigate:r,renderLink:o}){return o?e.jsx(e.Fragment,{children:o(t,n)}):r?e.jsx("a",{href:`/${t}`,onClick:i=>{i.preventDefault(),r(t)},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:i=>i.currentTarget.style.borderBottomStyle="solid",onMouseLeave:i=>i.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function jn({id:t,title:n,edition:r,type:o,isDraft:i,authors:s,volumeText:a,meta:l,headerExtra:d}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"12px"},children:[e.jsxs("h1",{style:{fontSize:"24px",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.3,letterSpacing:"0.5px",flex:1,minWidth:0},children:[n,r&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:r}),a&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:a})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexShrink:0,paddingTop:"4px"},children:[e.jsx(mt,{type:o}),e.jsx(yn,{isDraft:i}),e.jsx(vn,{id:t}),d]})]}),((s==null?void 0:s.length)||l.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[s&&s.length>0&&e.jsx(yt,{authors:s,type:o}),l]})]})}function Sn({items:t,onNavigate:n,renderLink:r}){const o=W(),{convert:i}=F();if(!t.length)return null;const[s,a]=p.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:o.section.indexed}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((l,d)=>{const u=s===d;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...u?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>a(u?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:u?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:i(l.source)}),!u&&l.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i(l.title_info)}),l.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(pe,{id:l.source_bid,label:o.action.view,onNavigate:n,renderLink:r})})]}),u&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(l.title_info||l.author_info||l.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[l.title_info&&e.jsx(ie,{label:o.label.titleInfo,children:i(l.title_info)}),l.author_info&&e.jsx(ie,{label:o.label.authorInfo,children:i(l.author_info)}),l.edition&&e.jsx(ie,{label:o.label.edition,children:i(l.edition)})]}),l.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:i(l.summary)})]}),l.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:i(l.comment)})]}),l.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:i(l.additional_comment)})]})]})]},d)})})]})}function kn({items:t}){const n=W(),{convert:r}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:n.section.aliases}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((o,i)=>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:r(o)},i))})]}):null}function wn({items:t}){const n=W(),{convert:r}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((o,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:["《",r(o.book_title),"》",o.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[o.n_juan,n.unit.juan]})]},i))})]}):null}function Cn({items:t}){const n=W(),{convert:r}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((o,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:r(o.name)}),o.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:r(o.description)})]},i))]})]}):null}function zn({items:t}){const n=W(),{convert:r}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((o,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:"·"}),r(o)]},i))})]}):null}function Ze({title:t,ids:n,transport:r,onNavigate:o,renderLink:i}){const{convert:s}=F(),[a,l]=p.useState([]);return p.useEffect(()=>{if(!n.length){l([]);return}if(!r){l(n.map(u=>({id:u})));return}let d=!1;return Promise.all(n.map(u=>r.getItem(u).then(g=>({id:u,title:g?g.title:void 0,edition:g?g.edition:void 0,type:g?g.type:void 0})).catch(()=>({id:u})))).then(u=>{d||l(u)}),()=>{d=!0}},[n,r]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(Q,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(a.length?a:n.map(d=>({id:d}))).map(d=>{const u=d.edition?`${s(d.title)||d.id}(${s(d.edition)})`:s(d.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(pe,{id:d.id,label:u,onNavigate:o,renderLink:i})},d.id)})})]}):null}function In({book:t,onNavigate:n,renderLink:r}){const o=W(),{convert:i}=F(),[s,a]=p.useState(!1),l=t.resources&&t.resources.length>0,d=t.edition?`${i(t.title)||t.id}(${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:l&&!s?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1},children:e.jsx(pe,{id:t.id,label:d,onNavigate:n,renderLink:r})}),l&&e.jsx("span",{onClick:()=>a(u=>!u),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:s?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:s?o.action.expand:o.action.collapse,children:"▼"})]}),l&&!s&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(Me,{items:t.resources,groupByType:!0})})]})}function Tn({ids:t,transport:n,onNavigate:r,renderLink:o}){const i=W(),[s,a]=p.useState([]);return p.useEffect(()=>{if(!t.length){a([]);return}if(!n){a(t.map(d=>({id:d})));return}let l=!1;return Promise.all(t.map(d=>n.getItem(d).then(u=>({id:d,title:u?u.title:void 0,edition:u?u.edition:void 0,resources:u?u.resources:void 0})).catch(()=>({id:d})))).then(d=>{l||a(d)}),()=>{l=!0}},[t,n]),t.length?e.jsxs(e.Fragment,{children:[e.jsxs(Q,{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:(s.length?s:t.map(l=>({id:l}))).map(l=>e.jsx(In,{book:l,onNavigate:r,renderLink:o},l.id))})]}):null}function _n({workData:t,onNavigate:n,renderLink:r}){var s,a,l;const o=W(),{convert:i}=F();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(mt,{type:"work"}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(pe,{id:t.id,label:i(t.title),onNavigate:n,renderLink:r})}),((s=t.juan_count)==null?void 0:s.number)&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[bt(t.juan_count.number),o.unit.juan]})]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(yt,{authors:t.authors,type:"work"}),((a=t.description)==null?void 0:a.text)&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,margin:(l=t.authors)!=null&&l.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(ie,{label:o.label.parentWork,children:e.jsx(pe,{id:t.parent_work.id,label:i(t.parent_work.title),onNavigate:n,renderLink:r})})})]})]})}function Rn({items:t,onNavigate:n,renderLink:r}){const o=W(),{convert:i}=F();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(s=>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:o.indexType.collection}),e.jsx(pe,{id:s.id,label:i(s.title)||s.id,onNavigate:n,renderLink:r}),s.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:Se(o.catalog.volume,{n:s.volume_index})})]},s.id))}):null}const vt=({data:t,id:n,transport:r,onNavigate:o,renderLink:i,headerExtra:s,className:a,style:l})=>{var _,P,k,$,D,U;const d=W(),{convert:u}=F(),[g,x]=p.useState(null),[f,c]=p.useState(!1),[j,w]=p.useState(null),[b,E]=p.useState(null),[m,S]=p.useState([]),y=t||g;if(p.useEffect(()=>{if(t||!n||!r)return;let L=!1;return c(!0),w(null),r.getItem(n).then(M=>{L||(M?x(M):w(d.misc.notFoundEntry))}).catch(M=>{L||w(M instanceof Error?M.message:d.misc.loadFailed)}).finally(()=>{L||c(!1)}),()=>{L=!0}},[t,n,r]),p.useEffect(()=>{if(!y||!r){E(null),S([]);return}let L=!1;const M=y.type==="book"||y.type==="collection"?y.work_id:void 0;if(M?r.getItem(M).then(V=>{!L&&V&&V.type==="work"&&E(V)}).catch(()=>{}):E(null),y.type==="book"){const V=y;V.contained_in&&V.contained_in.length>0?Promise.all(V.contained_in.map(Y=>{const A=typeof Y=="string"?Y:Y.id,ee=typeof Y=="string"?void 0:Y.volume_index;return r.getItem(A).then(q=>({id:A,title:q&&q.title||A,volume_index:ee})).catch(()=>({id:A,title:A,volume_index:ee}))})).then(Y=>{L||S(Y)}):S([])}else S([]);return()=>{L=!0}},[y,r]),f)return e.jsx("div",{className:a,style:{...l,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((L,M)=>e.jsx("div",{style:{height:M===1?"32px":"16px",width:`${L}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},M))})});if(j)return e.jsx("div",{className:a,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:j});if(!y)return null;const I=y.type==="book"?y:null,T=y.type==="collection"?y:null,v=y.type==="work"?y:null;let h=!1;try{h=H.extractStatus(y.id)==="draft"}catch{}let R="";(_=y.juan_count)!=null&&_.number?R=bt(y.juan_count.number)+d.unit.juan:(P=y.juan_count)!=null&&P.description&&(R=u(y.juan_count.description));const C=[];return(k=y.publication_info)!=null&&k.year&&C.push(e.jsx(ie,{label:d.label.year,children:y.publication_info.year},"year")),($=y.current_location)!=null&&$.name&&C.push(e.jsx(ie,{label:d.label.currentLocation,children:u(y.current_location.name)},"loc")),(D=y.page_count)!=null&&D.description&&C.push(e.jsx(ie,{label:d.label.pageCount,children:y.page_count.description},"page")),I!=null&&I.edition&&C.push(e.jsx(ie,{label:d.label.edition,children:u(I.edition)},"ver")),v!=null&&v.parent_work&&C.push(e.jsx(ie,{label:d.label.parentWork,children:e.jsx(pe,{id:v.parent_work.id,label:u(v.parent_work.title),onNavigate:o,renderLink:i})},"pw")),v!=null&&v.parent_works&&v.parent_works.length>0&&!v.parent_work&&C.push(e.jsx(ie,{label:d.label.parentWork,children:v.parent_works.map((L,M)=>e.jsxs("span",{children:[M>0&&"、",e.jsx(pe,{id:L,onNavigate:o,renderLink:i})]},L))},"pws")),e.jsxs("div",{className:a,style:l,children:[e.jsx(jn,{id:y.id,title:u(y.title),edition:y.edition?u(y.edition):void 0,type:y.type,isDraft:h,authors:y.authors,volumeText:R,meta:C,headerExtra:s}),((U=y.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(y.description.text)}),m.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:d.section.containedIn}),e.jsx(Rn,{items:m,onNavigate:o,renderLink:i})]}),b&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:d.section.belongsToWork}),e.jsx(_n,{workData:b,onNavigate:o,renderLink:i})]}),y.additional_works&&y.additional_works.length>0&&e.jsx(wn,{items:y.additional_works}),y.additional_titles&&y.additional_titles.length>0&&e.jsx(kn,{items:y.additional_titles}),y.indexed_by&&y.indexed_by.length>0&&e.jsx(Sn,{items:y.indexed_by,onNavigate:o,renderLink:i}),y.resources&&y.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:d.section.resources}),e.jsx(Me,{items:y.resources,groupByType:!0})]}),(I==null?void 0:I.location_history)&&I.location_history.length>0&&e.jsx(Cn,{items:I.location_history}),(T==null?void 0:T.history)&&T.history.length>0&&e.jsx(zn,{items:T.history}),(I==null?void 0:I.related_books)&&I.related_books.length>0&&e.jsx(Ze,{title:d.section.relatedVersions,ids:I.related_books,transport:r,onNavigate:o,renderLink:i}),(T==null?void 0:T.books)&&T.books.length>0&&e.jsx(Ze,{title:d.section.containedBooks,ids:T.books,transport:r,onNavigate:o,renderLink:i}),(v==null?void 0:v.books)&&v.books.length>0&&e.jsx(Tn,{ids:v.books,transport:r,onNavigate:o,renderLink:i}),(v==null?void 0:v.related_works)&&v.related_works.length>0&&(()=>{const L=[],M=v.related_works.filter(A=>A.relation==="part_of"),V=v.related_works.filter(A=>A.relation==="has_part"),Y=v.related_works.filter(A=>!A.relation);return M.length>0&&L.push({label:d.section.belongsToWork,items:M}),V.length>0&&L.push({label:d.section.containedWorks,items:V}),Y.length>0&&L.push({label:d.section.relatedWorks,items:Y}),L.map(A=>e.jsxs("div",{children:[e.jsxs(Q,{children:[A.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",A.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:A.items.map(ee=>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(pe,{id:ee.id,label:u(ee.title),onNavigate:o,renderLink:i})},ee.id))})]},A.label))})()]})};function Ln({data:t}){const n=W(),{convert:r}=F(),{stats:o}=t,i=o.processed_volumes??o.total_found_volumes,s=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:r(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:r(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]}),s!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:i})," ",n.unit.volume," (",s,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.total_books})," ",n.unit.bu]}),o.matched_works!=null&&o.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.matched_works})," ",n.unit.bu]}),o.unmatched_works!=null&&o.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"#e67e22"},children:o.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function En({sections:t,activeSection:n,onSelect:r}){const o=W();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>r(null),style:Xe(n===null),children:o.catalog.all}),t.map(i=>e.jsxs("button",{onClick:()=>r(i.name),style:Xe(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 Xe(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 Bn({id:t,label:n,onNavigate:r,renderLink:o}){return o?e.jsx(e.Fragment,{children:o(t,n)}):r?e.jsx("a",{href:`/${t}`,onClick:i=>{i.preventDefault(),r(t)},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px",fontSize:"12px"},onMouseEnter:i=>i.currentTarget.style.borderBottomStyle="solid",onMouseLeave:i=>i.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function Wn(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const r=t[0],o=t[t.length-1];return o-r+1===t.length?`${r}–${o}`:t.length<=3?t.join(", "):`${r}–${o} (${t.length}${n})`}function qe({book:t,onNavigate:n,renderLink:r,showVolumes:o}){const i=W(),{convert:s}=F(),a=t.book_id||t.work_id,l=o&&t.volumes.length>0?Wn(t.volumes,i.unit.volume):null,d=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[o&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:l}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[s(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=>s(u)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:s(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:d?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,i.unit.volume]}),a&&e.jsx(Bn,{id:a,label:t.book_id?i.indexType.book:i.indexType.work,onNavigate:n,renderLink:r}),!a&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:i.catalog.unmatched_label})]})}const jt=({data:t,collectionId:n,transport:r,onNavigate:o,renderLink:i,className:s,style:a})=>{const l=W(),[d,u]=p.useState(null),[g,x]=p.useState(!1),[f,c]=p.useState(null),[j,w]=p.useState(null),[b,E]=p.useState(""),m=t||d;p.useEffect(()=>{if(t||!n||!(r!=null&&r.getCollectionCatalog))return;let v=!1;return x(!0),c(null),r.getCollectionCatalog(n).then(h=>{v||(h?u(h):c(l.catalog.notFound))}).catch(h=>{v||c(h instanceof Error?h.message:l.catalog.loadFailed)}).finally(()=>{v||x(!1)}),()=>{v=!0}},[t,n,r,l]);const S=(m==null?void 0:m.sections)&&m.sections.length>0,y=p.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const v=m.books.map(R=>R.volumes[0]).filter(R=>R!=null);return new Set(v).size<v.length},[m]),I=p.useMemo(()=>{if(!m)return[];let v=m.books;if(j&&(v=v.filter(h=>h.section===j)),b.trim()){const h=b.trim().toLowerCase();v=v.filter(R=>R.title.toLowerCase().includes(h)||R.sub_items&&R.sub_items.some(C=>C.toLowerCase().includes(h))||R.edition&&R.edition.toLowerCase().includes(h))}return v},[m,j,b]),T=p.useMemo(()=>{if(!y)return null;const v=[],h=new Map;for(const C of I){if(!C.volumes||C.volumes.length===0)continue;const _=C.volumes[0];h.has(_)||h.set(_,[]),h.get(_).push(C)}const R=[...h.keys()].sort((C,_)=>C-_);for(const C of R)v.push({volume:C,books:h.get(C)});return v},[I,y]);return g?e.jsx("div",{className:s,style:{...a,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:l.catalog.loading})}):f?e.jsx("div",{className:s,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:f}):m?e.jsxs("div",{className:s,style:a,children:[e.jsx(Ln,{data:m}),S&&e.jsx(En,{sections:m.sections,activeSection:j,onSelect:w}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:l.search.searchBookName,value:b,onChange:v=>E(v.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[I.length," ",l.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[T?T.map((v,h)=>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:Se(l.catalog.volume,{n:v.volume})}),v.books.map((R,C)=>e.jsx(qe,{book:R,onNavigate:o,renderLink:i,showVolumes:R.volumes.length>1},`${v.volume}-${C}`))]},`${v.volume}-${h}`)):I.map((v,h)=>e.jsx(qe,{book:v,onNavigate:o,renderLink:i,showVolumes:!0},h)),I.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:l.catalog.noMatch})]})]}):null},$n=["〇","一","二","三","四","五","六","七","八","九"],Qe=["","十","百","千"],Pn=["","萬","億"];function St(t){if(t===0)return"〇";if(t<0)return`負${St(-t)}`;const n=[];let r=t,o=0;for(;r>0;){const i=r%1e4;i>0?n.unshift(An(i,o>0)+Pn[o]):n.length>0&&n.unshift("〇"),r=Math.floor(r/1e4),o++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function An(t,n){const r=[];let o=t;for(;o>0;)r.unshift(o%10),o=Math.floor(o/10);let i="";for(let s=0;s<r.length;s++){const a=r[s],l=r.length-1-s;a===0?i&&!i.endsWith("〇")&&(i+="〇"):a===1&&l===1&&s===0&&!n?i+=Qe[l]:i+=$n[a]+Qe[l]}return i.replace(/〇$/,"")}const kt={部:"#2471a3",类:"#8e6f3e",书:"#c0392b",其他:"#717171"};function Mn(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 wt({file:t,isActive:n,onSelect:r}){return e.jsx("button",{onClick:()=>r(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:Mn(t)})}function Ct(t,n){var r;return t.files.includes(n)?!0:!!((r=t.children)!=null&&r.some(o=>Ct(o,n)))}function zt(t){var o;const n=t.files.length,r=((o=t.children)==null?void 0:o.reduce((i,s)=>i+zt(s),0))||0;return n+r}function It({group:t,activeFile:n,onSelect:r,depth:o=0}){var u;const i=Ct(t,n||""),[s,a]=p.useState(i),l=zt(t),d=!!((u=t.children)!=null&&u.length);return p.useEffect(()=>{i&&a(!0)},[i]),e.jsxs("div",{style:{marginBottom:o===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>a(!s),style:{display:"flex",alignItems:"center",gap:"6px",padding:o===0?"4px 8px":"2px 8px",paddingLeft:`${8+o*16}px`,cursor:"pointer",userSelect:"none",fontSize:o===0?"13px":"12px",fontWeight:o===0?600:500,color:i?"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:["(",l,")"]})]}),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+o*16}px`},children:t.files.map(g=>e.jsx(wt,{file:g,isActive:n===g,onSelect:r},g))}),d&&t.children.map((g,x)=>e.jsx(It,{group:g,activeFile:n,onSelect:r,depth:o+1},x))]})]})}function Fn({files:t,groups:n,activeFile:r,onSelect:o}){return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((i,s)=>e.jsx(It,{group:i,activeFile:r,onSelect:o},s))}):e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:t.map(i=>e.jsx(wt,{file:i,isActive:r===i,onSelect:o},i))})}function Hn({type:t}){const n=kt[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 On({section:t,onNavigate:n}){const{convert:r}=F(),[o,i]=p.useState(!1),s=!!t.summary,a=!!t.comment,l=!!t.additional_comment,d=s||a||l;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&&i(!o),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:o?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)",flex:1},children:[t.book_title?`《${r(t.book_title)}》`:r(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[St(t.n_juan),"卷"]})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(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:`/${t.work_id}`,onClick:u=>{u.preventDefault(),u.stopPropagation(),n(t.work_id)},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),o&&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:r(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:r(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:r(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:r(t.additional_comment)})]})]})]})}function Dn({section:t}){const{convert:n}=F(),[r,o]=p.useState(!1),i=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>i&&o(!r),style:{display:"flex",alignItems:"center",gap:"8px",cursor:i?"pointer":"default",userSelect:"none"},children:[e.jsx(Hn,{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:r?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),r&&i&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${kt[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 Vn({section:t}){const{convert:n}=F();if(!t.content&&!t.title)return null;const r=n((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
2
2
|
`));return e.jsx("div",{style:{padding:"6px 0",fontSize:"13px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.7,whiteSpace:"pre-line"},children:r})}function Nn({juan:t,searchQuery:n,onNavigate:r}){const{convert:o}=F(),i=p.useMemo(()=>{if(!n.trim())return t.sections;const a=n.trim().toLowerCase();return t.sections.filter(l=>{var d,u,g,x,f;return((d=l.title)==null?void 0:d.toLowerCase().includes(a))||((u=l.book_title)==null?void 0:u.toLowerCase().includes(a))||((g=l.author)==null?void 0:g.toLowerCase().includes(a))||((x=l.author_info)==null?void 0:x.toLowerCase().includes(a))||((f=l.summary)==null?void 0:f.toLowerCase().includes(a))})},[t.sections,n]),s=i.filter(a=>a.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:o(t.title)}),t.source_url&&e.jsx("a",{href:t.source_url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:"原文 ↗"}),e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:[s," 部书"]})]}),i.map((a,l)=>a.type==="书"?e.jsx(On,{section:a,onNavigate:r},l):a.type==="部"||a.type==="类"?e.jsx(Dn,{section:a},l):e.jsx(Vn,{section:a},l)),i.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}const Tt=({index:t,workId:n,transport:r,onNavigate:o,activeJuan:i,onJuanChange:s,className:a,style:l})=>{const[d,u]=p.useState(null),[g,x]=p.useState(!1),[f,c]=p.useState(null),[j,w]=p.useState(null),[b,E]=p.useState(null),[m,S]=p.useState(!1),[y,I]=p.useState(""),T=i??j,v=p.useCallback(P=>{w(P),s==null||s(P)},[s]),h=t||d;p.useEffect(()=>{if(t||!n||!(r!=null&&r.getCollatedEditionIndex))return;let P=!1;return x(!0),c(null),r.getCollatedEditionIndex(n).then(k=>{P||(k?(u(k),!i&&k.juan_files.length>0&&v(k.juan_files[0])):c("未找到整理本数据"))}).catch(k=>{P||c(k instanceof Error?k.message:"加载失败")}).finally(()=>{P||x(!1)}),()=>{P=!0}},[t,n,r,i,v]),p.useEffect(()=>{t&&t.juan_files.length>0&&!T&&v(t.juan_files[0])},[t,T,v]);const R=n||(h==null?void 0:h.work_id),C=p.useCallback(async P=>{if(!(!R||!(r!=null&&r.getCollatedJuan))){S(!0),E(null);try{const k=await r.getCollatedJuan(R,P);E(k)}catch{E(null)}finally{S(!1)}}},[R,r]);p.useEffect(()=>{T&&C(T)},[T,C]);const _=P=>{v(P),I("")};return g?e.jsx("div",{className:a,style:{...l,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})}):f?e.jsx("div",{className:a,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:f}):h?e.jsxs("div",{className:a,style:l,children:[e.jsx("div",{style:{marginBottom:"16px"},children:e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:h.total_juan})," 卷"]})}),e.jsx(Fn,{files:h.juan_files,groups:h.juan_groups,activeFile:T,onSelect:_}),e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("input",{type:"text",placeholder:"搜索书名、作者...",value:y,onChange:P=>I(P.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("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载中..."}):b?e.jsx(Nn,{juan:b,searchQuery:y,onNavigate:o}):T?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null]}):null},Un=[{id:"FCNcSJbF77V",title:"欽定四庫全書·文淵閣本",description:"清·紀昀等編,藏於臺灣國立故宮博物院",group:"推薦叢編"},{id:"FCmH8kWxMhR",title:"二十四史百衲本",description:"民國·張元濟輯,商務印書館影印",group:"推薦叢編"},{id:"FCmYiXcTfuZ",title:"二十四史武英殿本",description:"清乾隆四年武英殿刻本",group:"推薦叢編"},{id:"FCmbeajrbJw",title:"武英殿聚珍版叢書",description:"清乾隆間武英殿活字印本",group:"推薦叢編"},{id:"GY4HvsY3w3u",title:"欽定四庫全書總目",description:"清·紀昀等編,200卷",group:"經典作品"},{id:"GY4JKKQaPYB",title:"欽定四庫全書簡明目錄",description:"清·紀昀等編,20卷",group:"經典作品"},{id:"GY4JM7j7yi7",title:"史記",description:"西漢·司馬遷,130卷",group:"經典作品"},{id:"GY3ty2LN9ro",title:"易經",description:"西周·周文王",group:"經典作品"}],_t=({transport:t,onNavigate:n,recommendedIds:r,activeTab:o,onTabChange:i})=>{const s=W(),[a,l]=p.useState(null),[d,u]=p.useState([]),[g,x]=p.useState("recommend"),f=o??g,c=S=>{x(S),i==null||i(S)},[j,w]=p.useState(null),[b,E]=p.useState(null);p.useEffect(()=>{if(!t.getAllEntries)return;let S=!1;return t.getAllEntries().then(y=>{if(S)return;const I=y.filter(h=>h.type==="work").length,T=y.filter(h=>h.type==="book").length,v=y.filter(h=>h.type==="collection").length;l({works:I,books:T,collections:v})}).catch(()=>{}),()=>{S=!0}},[t]),p.useEffect(()=>{let S=!1;return(async()=>{if(r)return r;if(t.getRecommended)try{const I=await t.getRecommended();if(I!=null&&I.groups)return I.groups.flatMap(T=>T.items.map(v=>({...v,group:T.name})))}catch{}return Un})().then(async I=>{if(S)return;const T=I.filter(h=>h.id);if(T.length===0)return;const v=await Promise.all(T.map(async h=>{try{let R=null;if(t.getEntry)R=await t.getEntry(h.id);else{const C=await t.getItem(h.id);C&&(R={id:h.id,title:C.title||h.id,type:C.type||"work"})}if(R)return{...R,group:h.group,fallbackDescription:h.description}}catch{}return{id:h.id,title:h.title,type:h.id.startsWith("FC")?"collection":"work",group:h.group,fallbackDescription:h.description}}));S||u(v.filter(h=>h!==null))}),()=>{S=!0}},[t,r]),p.useEffect(()=>{if(!t.getResourceProgress)return;let S=!1;return t.getResourceProgress().then(y=>{S||w(y)}).catch(()=>{}),()=>{S=!0}},[t]),p.useEffect(()=>{if(!t.getSiteProgress)return;let S=!1;return t.getSiteProgress().then(y=>{S||E(y)}).catch(()=>{}),()=>{S=!0}},[t]);const m=S=>{switch(S){case"work":return"✍️";case"book":return"📖";case"collection":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:f==="recommend",onClick:()=>c("recommend")}),e.jsx(Le,{label:s.home.catalogTab,active:f==="catalog",onClick:()=>c("catalog")}),e.jsx(Le,{label:s.home.siteTab,active:f==="site",onClick:()=>c("site")})]}),f==="recommend"&&e.jsx(Yn,{recommended:d,onNavigate:n,getIcon:m,t:s}),f==="catalog"&&e.jsx(Gn,{progress:j,t:s,onNavigate:n}),f==="site"&&e.jsx(Kn,{progress:b,t:s,totalWorks:(a==null?void 0:a.works)??0})]})})},Le=({label:t,active:n,onClick:r})=>e.jsx("button",{onClick:r,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}),Yn=({recommended:t,onNavigate:n,getIcon:r,t:o})=>{if(t.length===0)return null;const i=new Map;for(const s of t){const a=s.group||o.home.recommendedBrowse;i.has(a)||i.set(a,[]),i.get(a).push(s)}return e.jsx(e.Fragment,{children:Array.from(i.entries()).map(([s,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:s}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(l=>{const d=l.dynasty||l.author?`${l.dynasty?`〔${l.dynasty}〕`:""}${l.author||""}`:l.fallbackDescription;return e.jsxs("a",{href:`/${l.id}`,onClick:u=>{u.preventDefault(),n==null||n(l.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(l.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[l.title,l.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:l.edition})]}),d&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d})]})]},l.id)})})]},s))})},Gn=({progress:t,t:n,onNavigate:r})=>{if(!t)return e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"..."});const o=[...t.resources].sort((l,d)=>l.priority-d.priority),i=["in_progress","done","todo"],s={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},a={in_progress:"#f59e0b",done:"#10b981",todo:"#9ca3af"};return e.jsx("div",{children:i.map(l=>{const d=o.filter(u=>u.status===l);return d.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:a[l]}}),s[l]," (",d.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:d.map(u=>e.jsx(Jn,{item:u,t:n,statusColor:a[l],onNavigate:r},u.id))})]},l)})})},Jn=({item:t,t:n,statusColor:r,onNavigate:o})=>{const i=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 a=t.edition?`${t.name}·${t.edition}`:t.name,l=t.collection_id||t.work_id;return l&&o?e.jsx("a",{href:`/${l}`,onClick:d=>{d.preventDefault(),o(l)},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:a}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:a}):a})()}),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?Se(n.home.progressFormat,{imported:String(t.imported),total:String(t.total)}):n.home.totalPending})]}),t.total>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${i}%`,borderRadius:"2px",background:r,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},Kn=({progress:t,t:n,totalWorks:r})=>{if(!t)return e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"..."});const o=[...t.resources].sort((d,u)=>d.priority-u.priority),i=o.filter(d=>d.imported>0),s=o.filter(d=>d.imported===0),a=i.reduce((d,u)=>Math.max(d,u.imported),0),l=r>0?Math.round(a/r*100):0;return e.jsxs("div",{children:[r>0&&e.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)",fontSize:"13px",color:"var(--bim-fg, #333)"},children:[n.home.siteCoverage,": ",e.jsx("strong",{children:a.toLocaleString()})," / ",r.toLocaleString()," ",n.indexType.work," (",l,"%)"]}),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(d=>e.jsx(et,{item:d,t:n,totalWorks:r},d.id))})]}),s.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"#9ca3af"}}),n.home.statusTodo," (",s.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(d=>e.jsx(et,{item:d,t:n,totalWorks:r},d.id))})]})]})},et=({item:t,t:n,totalWorks:r})=>{const o=r>0?Math.round(t.imported/r*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${o}%)`:n.home.statusTodo})]}),t.imported>0&&r>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${o}%`,borderRadius:"2px",background:"#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})]})},Zn=({transport:t,hideModeIndicator:n=!0,onEntryClick:r,recommendedIds:o})=>{var R;const[i,s]=p.useState(null),[a,l]=p.useState(null),[d,u]=p.useState(!1),[g,x]=p.useState("detail"),[f,c]=p.useState([]),[j,w]=p.useState(!1),[b,E]=p.useState(null),[m,S]=p.useState(!1),y=p.useCallback(async C=>{if(!t.getCollatedEditionIndex){E(null);return}S(!0);try{const _=await t.getCollatedEditionIndex(C);E(_)}catch{E(null)}finally{S(!1)}},[t]),I=p.useCallback(async C=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){c([]);return}w(!0);try{if(t.getCollectionCatalogs){const _=await t.getCollectionCatalogs(C);c(_||[])}else if(t.getCollectionCatalog){const _=await t.getCollectionCatalog(C);c(_?[{resource_id:"",data:_}]:[])}}catch{c([])}finally{w(!1)}},[t]),T=p.useCallback(async C=>{if(r){r(C);return}s(C),l(null),c([]),E(null),x("detail"),u(!0);try{const _=await t.getItem(C.id);_&&(l(_),_.type==="collection"?I(C.id):_.type==="work"&&_.has_collated&&y(C.id))}catch(_){console.error("加载详情失败:",_)}finally{u(!1)}},[t,r,I,y]),v=p.useCallback(async C=>{l(null),c([]),E(null),x("detail"),u(!0);try{const _=await t.getItem(C);_&&(l(_),s({id:C,title:_.title||C,type:_.type||"book"}),_.type==="collection"?I(C):_.type==="work"&&_.has_collated&&y(C))}catch(_){console.error("导航失败:",_)}finally{u(!1)}},[t,I,y]),h=(a==null?void 0:a.type)==="collection"&&(f.length>0||j)||(a==null?void 0:a.type)==="work"&&(b||m);return 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(ht,{transport:t,onEntryClick:T,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:d?e.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:e.jsx("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中..."})}):a?e.jsxs(e.Fragment,{children:[h&&e.jsxs("div",{style:{display:"flex",gap:"0",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0},children:[e.jsx("button",{onClick:()=>x("detail"),style:Ce(g==="detail"),children:"基本信息"}),a.type==="collection"&&j&&f.length===0&&e.jsxs("button",{onClick:()=>{},style:Ce(!1),children:["目錄",e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),a.type==="collection"&&f.map(C=>e.jsx("button",{onClick:()=>x(`catalog:${C.resource_id}`),style:Ce(g===`catalog:${C.resource_id}`),children:C.short_name?`${C.short_name}·目錄`:"叢編目錄"},C.resource_id)),a.type==="work"&&(b||m)&&e.jsxs("button",{onClick:()=>x("collated"),style:Ce(g==="collated"),children:["整理本",m&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),e.jsx("div",{style:{padding:"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:g==="detail"?e.jsx(vt,{data:a,transport:t,onNavigate:v}):g.startsWith("catalog:")?e.jsx(jt,{data:(R=f.find(C=>`catalog:${C.resource_id}`===g))==null?void 0:R.data,onNavigate:v}):g==="collated"?e.jsx(Tt,{index:b||void 0,workId:a.id,transport:t,onNavigate:v}):null})]}):e.jsx(_t,{transport:t,onNavigate:v,recommendedIds:o})})]})};function Ce(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 Xn=({data:t,onNavigate:n,className:r,style:o})=>{var g;const i=W(),{convert:s}=F(),[a,l]=p.useState(((g=t.divisions[0])==null?void 0:g.name)??null),[d,u]=p.useState(null);return e.jsxs("div",{className:r,style:o,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:s(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(x=>e.jsx(qn,{division:x,expanded:a===x.name,onToggle:()=>l(a===x.name?null:x.name),expandedCat:d,onCatToggle:f=>u(d===f?null:f),onNavigate:n},x.name))})]})},qn=({division:t,expanded:n,onToggle:r,expandedCat:o,onCatToggle:i,onNavigate:s})=>{const{convert:a}=F(),l=t.categories.reduce((d,u)=>{const g=u.stats||{zhulu:0,cunmu:0};return d+(g.zhulu||0)+(g.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:r,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)":"var(--bim-bg, #f8f8f8)",cursor:"pointer",fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsx("span",{children:a(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",l," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(d=>{const u=`${t.name}/${d.name}`;return e.jsx(Qn,{category:d,expanded:o===u,onToggle:()=>i(u),onNavigate:s},d.name)})})]})},Qn=({category:t,expanded:n,onToggle:r,onNavigate:o})=>{var d,u,g,x;const{convert:i}=F(),s=((d=t.books)==null?void 0:d.zhulu)||[],a=((u=t.books)==null?void 0:u.cunmu)||[],l=(((g=t.stats)==null?void 0:g.zhulu)||s.length)+(((x=t.stats)==null?void 0:x.cunmu)||a.length);return e.jsxs("div",{children:[e.jsxs("button",{onClick:r,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:[l," 部 ",n?"▲":"▼"]})]}),n&&(s.length>0||a.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[s.length>0&&e.jsx(tt,{label:"著錄",books:s,onNavigate:o}),a.length>0&&e.jsx(tt,{label:"存目",books:a,onNavigate:o})]})]})},tt=({label:t,books:n,onNavigate:r})=>{const{convert:o}=F(),[i,s]=p.useState(n.length<=20),a=i?n:n.slice(0,10);return e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"4px",fontWeight:500},children:[t," (",n.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:a.map((l,d)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:l.work_id&&r?e.jsx("a",{href:`/${l.work_id}`,onClick:u=>{u.preventDefault(),r(l.work_id)},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:o(l.title)}):o(l.title)}),l.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:o(l.volumes)}),l.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:o(l.author).slice(0,20)})]},d))}),!i&&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," 條"]})]})},re=({title:t,onSave:n,onAskAI:r,extraButtons:o,children:i})=>{const s=W();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[o,r&&e.jsx("button",{onClick:r,style:to,children:"AI"}),n&&e.jsx("button",{onClick:n,style:eo,children:s.action.save})]})]}),i]})},eo={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},to={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},X=({label:t,value:n,onChange:r,placeholder:o,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:s=>r(s.target.value),placeholder:o,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"}})]}),ue=({value:t,onChange:n,placeholder:r})=>{const o=p.useRef(null);return p.useEffect(()=>{o.current&&(o.current.style.height="auto",o.current.style.height=`${o.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:o,value:t||"",onChange:i=>n(i.target.value),placeholder:r,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"}})},Ie=({children:t,color:n,style:r})=>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)",...r},children:t});function no(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const ze=({value:t,onChange:n,label:r})=>{const[o,i]=p.useState(!1),s=p.useRef(null),a=no(t||"");return p.useEffect(()=>{o&&s.current&&s.current.focus()},[o]),!o&&a?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:nt,children:r}),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:a.name}),e.jsx(Ie,{children:a.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:nt,children:r}),e.jsx("input",{ref:s,type:"text",value:t||"",onChange:l=>n(l.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"}})]})},nt={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function oo(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function ro(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Rt=({items:t,onChange:n,onOpenEntityPicker:r})=>{const o=W(),[i,s]=p.useState(null),a=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),s(t.length)},l=x=>{n(t.filter((f,c)=>c!==x)),i===x&&s(null)},d=(x,f,c)=>{const j=[...t];j[x]={...j[x],[f]:c},n(j)},u=(x,f)=>{const c=[...t];c[x]={...c[x],type:f,id:"",name:""},n(c),f==="bookID"&&r&&r(j=>{const w=[...t];w[x]={...w[x],id:j.id,name:j.title,type:"bookID"},n(w)})},g=x=>{r&&r(f=>{const c=[...t];c[x]={...c[x],id:f.id,name:f.title,type:"bookID"},n(c)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((x,f)=>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:()=>s(i===f?null:f),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:i===f?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:x.name||`${o.editor.sourcePlaceholder} ${f+1}`}),x.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:oo(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:ro(x.type)}),e.jsx("button",{onClick:c=>{c.stopPropagation(),l(f)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:o.editor.deleteThisSource,children:"✕"})]}),i===f&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!x.type&&e.jsxs("div",{children:[e.jsx("label",{style:ce,children:o.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>u(f,"bookID"),style:{...ot,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:o.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>u(f,"url"),style:{...ot,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:o.editor.enterUrl})]})]})]}),x.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:ce,children:o.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const c=[...t];c[f]={...c[f],type:"",id:"",name:""},n(c)},style:rt,children:o.action.changeType})]}),x.id&&x.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid #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:x.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:x.id})]}),e.jsx("button",{onClick:()=>g(f),style:{background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-fg, #333)",cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:o.action.reselect})]}):e.jsxs("button",{onClick:()=>g(f),style:{width:"100%",padding:"14px",border:"2px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:o.action.clickToSelectBookOrWork})]})]})}),x.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:ce,children:o.label.sourceName}),e.jsx("button",{onClick:()=>{const c=[...t];c[f]={...c[f],type:"",id:"",name:""},n(c)},style:rt,children:o.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:c=>d(f,"name",c.target.value),placeholder:o.editor.sourceNamePlaceholder,style:ge})]}),e.jsxs("div",{children:[e.jsx("label",{style:ce,children:o.label.urlAddress}),e.jsx("input",{type:"text",value:x.id,onChange:c=>d(f,"id",c.target.value),placeholder:"https://...",style:ge})]})]}),x.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:"1px dashed var(--bim-widget-border, #e0e0e0)",paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...ce,opacity:.7},children:o.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:ce,children:o.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:c=>d(f,"details",c.target.value),placeholder:o.editor.detailsPlaceholder,style:ge})]}),e.jsxs("div",{children:[e.jsx("label",{style:ce,children:o.label.positionOptional}),e.jsx("input",{type:"text",value:x.position,onChange:c=>d(f,"position",c.target.value),placeholder:"如: 卷三, p.52",style:ge})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:ce,children:o.label.dataVersionOptional}),e.jsx("input",{type:"text",value:x.version,onChange:c=>d(f,"version",c.target.value),placeholder:"如: v1.0, 2024-01",style:ge})]}),e.jsxs("div",{children:[e.jsx("label",{style:ce,children:o.label.processorVersionOptional}),e.jsx("input",{type:"text",value:x.processor_version,onChange:c=>d(f,"processor_version",c.target.value),placeholder:"如: v0.1",style:ge})]})]})]})]})})]},f)),e.jsxs("button",{onClick:a,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:o.action.addSource})]})]})},ce={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},ge={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"},ot={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"},rt={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function Lt(t){if(!t||!t.trim())return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(r=>({id:r.id||"",name:r.name||"",type:r.type||"",details:r.details||"",position:r.position||"",version:r.version||"",processor_version:r.processor_version||""}))}catch{}return[]}function Et(t){return!t||t.length===0?"":JSON.stringify(t)}const Bt=({entityType:t,entityId:n,entityTitle:r,parentWork:o,parentCollection:i,belongsToWork:s,belongsToCollection:a,childWorks:l,childCollections:d,containedBooks:u,siblingBooks:g,onLinkEntity:x,onUnlinkEntity:f,onViewEntity:c,onCreateAndLink:j,onSaveRelations:w})=>{const b=W();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:b.section.relations})]}),w&&e.jsx("button",{onClick:w,style:io,children:b.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(ye,{direction:"up",title:b.relation.belongsToWork,entity:s,onView:c,onUnlink:()=>f("workId"),onLink:()=>x("workId","work"),onCreate:()=>j("workId","work",{title:r}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),e.jsx(ye,{direction:"up",title:b.relation.containedInCollection,entity:a,onView:c,onUnlink:()=>f("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>j("collectionId","collection",{title:r}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),s&&g&&g.length>0&&e.jsx(fe,{direction:"horizontal",title:`${b.relation.siblingVersions} (${g.length})`,entities:g,onView:c,onAdd:()=>j("siblingBook","book",{workId:s.id}),addLabel:b.relation.addVersionForWork,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(ye,{direction:"up",title:b.relation.parentWork,entity:o,onView:c,onUnlink:()=>f("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>j("parentWorkId","work"),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),l&&l.length>0&&e.jsx(fe,{direction:"down",title:`${b.relation.childWorks} (${l.length})`,entities:l,onView:c,onAdd:()=>j("childWork","work",{parentWorkId:n}),addLabel:b.action.addSubWork,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),d&&d.length>0&&e.jsx(fe,{direction:"down",title:`${b.relation.collectionImpl} (${d.length})`,entities:d,onView:c,onAdd:()=>j("childCollection","collection",{workId:n}),addLabel:b.action.addCollectionImpl,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),e.jsx(fe,{direction:"down",title:`${b.relation.allVersions} (${(u==null?void 0:u.length)??0})`,entities:u||[],onView:c,onAdd:()=>j("childBook","book",{workId:n}),addLabel:b.action.addVersion,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(ye,{direction:"up",title:b.relation.correspondingWork,entity:s,onView:c,onUnlink:()=>f("workId"),onLink:()=>x("workId","work"),onCreate:()=>j("workId","work",{title:r}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),e.jsx(ye,{direction:"up",title:b.relation.parentCollection,entity:i,onView:c,onUnlink:()=>f("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>j("parentCollectionId","collection"),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),e.jsx(fe,{direction:"down",title:`${b.relation.childCollections} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:c,onAdd:()=>j("childCollection","collection",{parentCollectionId:n}),addLabel:b.action.addSubCollection,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),e.jsx(fe,{direction:"down",title:`${b.relation.containedBooks} (${(u==null?void 0:u.length)??0})`,entities:u||[],onView:c,onAdd:()=>j("childBook","book",{collectionId:n}),addLabel:b.action.addBook,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]})]})]})},ye=({direction:t,title:n,entity:r,onView:o,onUnlink:i,onLink:s,onCreate:a,linkLabel:l,createLabel:d,notLinkedLabel:u,viewLabel:g,unlinkLabel:x})=>{const f=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",c=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:f,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:c}),e.jsx("span",{children:n})]}),r?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:Wt(r.type)}),e.jsx("span",{style:{fontWeight:500},children:r.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:r.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(it,{onClick:()=>o(r),title:g,children:"👁️"}),e.jsx(it,{onClick:i,title:x,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:u}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(Ae,{onClick:s,children:l}),e.jsx(Ae,{onClick:a,primary:!0,children:d})]})]})},fe=({direction:t,title:n,entities:r,onView:o,onAdd:i,addLabel:s,noneLabel:a,expandMoreLabel:l})=>{const[d,u]=p.useState(!1),g=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",f=d?r:r.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:g,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:x}),e.jsx("span",{children:n})]}),r.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[f.map(c=>e.jsxs("div",{onClick:()=>o(c),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:Wt(c.type)}),e.jsx("span",{children:c.title})]},c.id)),r.length>5&&!d&&e.jsxs("div",{onClick:()=>u(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[l," (",r.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:a}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(Ae,{onClick:i,primary:!0,children:["+ ",s]})})]})},it=({onClick:t,title:n,danger:r,children:o})=>e.jsx("button",{onClick:i=>{i.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:r?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:o}),Ae=({onClick:t,primary:n,children:r})=>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:r});function Wt(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const io={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"},$t=({isOpen:t,entityType:n,title:r,onSelect:o,onCancel:i,onCreate:s,searchResults:a,onSearch:l,isLoading:d,excludeId:u})=>{const[g,x]=p.useState(""),f=u?a.filter(b=>b.id!==u):a;p.useEffect(()=>{t&&(x(""),l(""))},[t]);const c=b=>{x(b),l(b)};if(!t)return null;const j=n==="work"?"作品":n==="book"?"书籍":"丛编",w=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:lo,children:e.jsxs("div",{style:so,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:r}),e.jsx("button",{onClick:i,style:ao,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:g,onChange:b=>c(b.target.value),placeholder:`搜索${j}名称或 ID...`,autoFocus:!0,style:co})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:d?e.jsx("div",{style:Ee,children:"搜索中..."}):f.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:f.map(b=>e.jsxs("div",{onClick:()=>o(b),style:po,children:[e.jsx("span",{style:{fontSize:"16px"},children:w}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[b.title,b.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:b.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[b.id,b.author&&` · ${b.author}`,b.dynasty&&` · ${b.dynasty}`]})]})]},b.id))}):g?e.jsxs("div",{style:Ee,children:["未找到匹配的",j]}):e.jsxs("div",{style:Ee,children:["输入关键词搜索",j]})}),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:s,style:xo,children:["创建新",j,"并关联"]})]})]})})},lo={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},so={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"500px",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},ao={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},co={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"},po={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Ee={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},xo={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},lt={work:"作品",book:"书籍",collection:"丛编"},uo={work:"📜",book:"📖",collection:"📚"},Pt=({isOpen:t,entityType:n,relationField:r,inheritData:o,onConfirm:i,onCancel:s})=>{const[a,l]=p.useState(""),d=p.useRef(null);p.useEffect(()=>{t&&(l((o==null?void 0:o.title)||""),setTimeout(()=>{var f,c;(f=d.current)==null||f.focus(),(c=d.current)==null||c.select()},100))},[t,o==null?void 0:o.title]);const u=f=>{f.key==="Enter"&&a.trim()?g():f.key==="Escape"&&s()},g=()=>{a.trim()&&i(a.trim(),{...o,title:a.trim()})};if(!t)return null;const x=()=>{switch(r){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`创建新${lt[n]}`}};return e.jsx("div",{style:go,onClick:f=>{f.target===f.currentTarget&&s()},children:e.jsxs("div",{style:fo,onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:uo[n]}),e.jsx("span",{children:x()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:d,type:"text",value:a,onChange:f=>l(f.target.value),onKeyDown:u,placeholder:`请输入${lt[n]}名称...`,style:ho})]}),((o==null?void 0:o.author)||(o==null?void 0:o.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-input-bg, #fff)",padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(o==null?void 0:o.author)&&e.jsxs("div",{children:["作者: ",o.author]}),(o==null?void 0:o.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",o.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:s,style:bo,children:"取消"}),e.jsx("button",{onClick:g,disabled:!a.trim(),style:{...mo,opacity:a.trim()?1:.6,cursor:a.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},go={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",padding:"20px",minWidth:"400px",maxWidth:"500px",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},ho={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"},bo={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},mo={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function yo(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function At(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function vo(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const Mt=({isOpen:t,title:n,filterType:r="all",recentEntities:o=[],excludeId:i,showCreateButton:s=!1,createButtonText:a,onSelect:l,onCancel:d,onCreate:u,onSearch:g})=>{const[x,f]=p.useState(""),[c,j]=p.useState([]),[w,b]=p.useState(!1),[E,m]=p.useState("recent");p.useEffect(()=>{t&&(f(""),j([]),m(o.length>0?"recent":"search"))},[t,o.length]),p.useEffect(()=>{if(!x.trim()){j([]);return}const h=setTimeout(async()=>{b(!0);try{j(await g(x,r))}catch{j([])}finally{b(!1)}},300);return()=>clearTimeout(h)},[x,r,g]);const S=p.useCallback(h=>{f(h.target.value),h.target.value.trim()&&m("search")},[]),y=p.useCallback(h=>i?h.filter(R=>R.id!==i):h,[i]);if(!t)return null;const I=n||(r==="all"?"选择实体":`选择${At(r)}`),T=y(o),v=y(c);return e.jsx("div",{style:So,children:e.jsxs("div",{style:ko,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:I}),e.jsx("button",{onClick:d,style:wo,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:x,onChange:S,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Co}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),w&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),T.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(st,{active:E==="recent",onClick:()=>m("recent"),children:["最近使用 (",T.length,")"]}),e.jsxs(st,{active:E==="search",onClick:()=>m("search"),children:["搜索结果 ",v.length>0&&`(${v.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:E==="recent"&&T.length>0?e.jsx(at,{entities:T,onSelect:l}):x.trim()?w?e.jsx(Be,{message:"搜索中..."}):v.length>0?e.jsx(at,{entities:v,onSelect:l}):e.jsx(Be,{message:"未找到匹配的结果"}):e.jsx(Be,{message:"输入关键词开始搜索"})}),s&&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:zo,children:a||"创建新实体"})]})]})})},st=({active:t,onClick:n,children:r})=>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:r}),at=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(r=>e.jsx(jo,{entity:r,onClick:()=>n(r)},r.id))}),jo=({entity:t,onClick:n})=>{const[r,o]=p.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:r?"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:yo(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:vo(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:At(t.type)})]})},Be=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),So={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},ko={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"550px",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},wo={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Co={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"},zo={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Io={work:"#4caf50",collection:"#2196f3",book:"#ff9800"},To={work:"📜",collection:"📚",book:"📖"},_o=({data:t,onChange:n,onSave:r,transport:o,onNavigate:i,showDelete:s,onDelete:a,onAskAI:l,renderSectionActions:d,onDownloadResource:u,downloadStatuses:g,relations:x,onRelationsChange:f})=>{var we;const c=W(),[j,w]=p.useState(!1),[b,E]=p.useState("work"),[m,S]=p.useState(""),[y,I]=p.useState(""),[T,v]=p.useState([]),[h,R]=p.useState(!1),[C,_]=p.useState(!1),[P,k]=p.useState("work"),[$,D]=p.useState(""),[U,L]=p.useState(),[M,V]=p.useState(!1),[Y,A]=p.useState(null),[ee,q]=p.useState([]);p.useRef(null);const te=t.type,ne=te==="work",xe=te==="collection",le=te==="book",N=p.useCallback((z,K)=>{n({...t,[z]:K})},[t,n]),he=p.useCallback((z,K)=>{S(z),E(K),I(c.editor.selectToLink+c.indexType[K]),v([]),w(!0)},[c]),ke=p.useCallback(z=>{o!=null&&o.unlinkEntity&&o.unlinkEntity(t.id,z)},[o,t.id]),_e=p.useCallback(z=>{i==null||i(z.id,z.type)},[i]),B=p.useCallback((z,K,de)=>{const Ht={...de,author:(de==null?void 0:de.author)||t.author,dynasty:(de==null?void 0:de.dynasty)||t.dynasty};k(K),D(z),L(Ht),_(!0)},[t.author,t.dynasty]),G=p.useCallback((z,K)=>{o!=null&&o.createAndLink&&o.createAndLink(t.id,$,{type:P,title:z,inheritData:K}),_(!1)},[o,t.id,$,P]),O=p.useCallback(z=>{if(!z.trim()){v([]);return}R(!0),o!=null&&o.searchEntities&&o.searchEntities(z,b).then(K=>{v(K),R(!1)}).catch(()=>{v([]),R(!1)})},[o,b]),Z=p.useCallback(z=>{o!=null&&o.linkEntity&&o.linkEntity(t.id,m,z.id),w(!1)},[o,t.id,m]),se=p.useCallback(()=>{r()},[r]),ae=p.useCallback(z=>{A(()=>z),V(!0),o!=null&&o.getRecentEntities&&o.getRecentEntities().then(q).catch(()=>{})},[o]),J=p.useCallback((z,K)=>o!=null&&o.searchEntities?o.searchEntities(z,K==="all"?void 0:K):Promise.resolve([]),[o]),Fe=p.useCallback(z=>{o!=null&&o.addRecentEntity&&o.addRecentEntity(z),q(K=>[z,...K.filter(de=>de.id!==z.id)].slice(0,10)),Y==null||Y(z),V(!1),A(null)},[o,Y]);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:To[te]}),e.jsx("span",{children:t.title||c.editor.untitled}),e.jsx(Ie,{children:t.id}),e.jsx(Ie,{color:Io[te],children:c.indexType[te]})]})}),e.jsx(re,{title:c.section.basicInfo,onSave:r,onAskAI:l?()=>l("基本信息"):void 0,extraButtons:d==null?void 0:d("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(ze,{label:ne?c.editor.workTitle:xe?c.editor.collectionTitle:c.editor.bookTitle,value:t.title,onChange:z=>N("title",z)}),le&&e.jsx(ze,{label:c.editor.belongsToWork,value:t.workName||"",onChange:z=>N("workName",z)}),e.jsx(X,{label:c.editor.authorLabel,value:t.author||"",onChange:z=>N("author",z)}),e.jsx(X,{label:c.editor.dynastyLabel,value:t.dynasty||"",onChange:z=>N("dynasty",z)}),(le||xe)&&e.jsx(ze,{label:c.editor.containedIn,value:t.collection||"",onChange:z=>N("collection",z)}),(le||xe)&&e.jsx(X,{label:c.editor.holderLabel,value:t.holder||"",onChange:z=>N("holder",z)}),(le||xe)&&e.jsx(X,{label:le?c.editor.pageLabel:c.editor.volumeLabel,value:t.pages||"",onChange:z=>N("pages",z)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(X,{label:c.editor.firstImageLabel,value:t.firstImage||"",onChange:z=>N("firstImage",z)})})]})}),e.jsx(re,{title:c.section.description,onSave:r,onAskAI:l?()=>l("介绍"):void 0,children:e.jsx(ue,{value:t.description||"",onChange:z=>N("description",z),placeholder:c.editor.descriptionPlaceholder})}),(((we=t.additional_works)==null?void 0:we.length)||0)>0&&e.jsx(re,{title:c.section.additionalWorks,onSave:r,children:e.jsx(Ro,{items:t.additional_works||[],onChange:z=>N("additional_works",z)})}),e.jsx(re,{title:c.section.indexedBy,onSave:r,onAskAI:l?()=>l("收录于"):void 0,children:e.jsx(Lo,{items:t.indexed_by||[],onChange:z=>N("indexed_by",z)})}),e.jsx(re,{title:c.section.textResources,onSave:r,onAskAI:l?()=>l("资源"):void 0,children:e.jsx(We,{items:t.resources||[],onChange:z=>N("resources",z),onDownload:u,downloadStatuses:g,filterType:"text"})}),e.jsx(re,{title:c.section.imageResources,onSave:r,children:e.jsx(We,{items:t.resources||[],onChange:z=>N("resources",z),onDownload:u,downloadStatuses:g,filterType:"image"})}),e.jsx(re,{title:c.section.sources,onSave:r,onAskAI:l?()=>l("资料来源"):void 0,children:e.jsx(Rt,{items:Lt(t.sources||""),onChange:z=>N("sources",Et(z)),onOpenEntityPicker:ae})}),(le||xe)&&e.jsx(re,{title:c.section.provenance,onSave:r,onAskAI:l?()=>l("收藏历史"):void 0,children:e.jsx(ue,{value:t.provenance||"",onChange:z=>N("provenance",z),placeholder:c.editor.provenancePlaceholder})}),le&&e.jsx(re,{title:c.section.otherEditions,onSave:r,onAskAI:l?()=>l("其他版本"):void 0,children:e.jsx(ue,{value:t.otherEditions||"",onChange:z=>N("otherEditions",z),placeholder:c.editor.otherEditionsPlaceholder})}),e.jsx(Bt,{entityType:te,entityId:t.id,entityTitle:t.title,parentWork:x==null?void 0:x.parentWork,parentCollection:x==null?void 0:x.parentCollection,belongsToWork:x==null?void 0:x.belongsToWork,belongsToCollection:x==null?void 0:x.belongsToCollection,childWorks:x==null?void 0:x.childWorks,childCollections:x==null?void 0:x.childCollections,containedBooks:x==null?void 0:x.containedBooks,siblingBooks:x==null?void 0:x.siblingBooks,onLinkEntity:he,onUnlinkEntity:ke,onViewEntity:_e,onCreateAndLink:B,onSaveRelations:se}),s&&a&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:c.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:c.editor.dangerZoneDesc}),e.jsx("button",{onClick:a,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:c.editor.deleteEntity})]}),e.jsx($t,{isOpen:j,entityType:b,title:y,onSelect:Z,onCancel:()=>w(!1),onCreate:()=>{w(!1),B(m,b)},searchResults:T,onSearch:O,isLoading:h,excludeId:t.id}),e.jsx(Pt,{isOpen:C,entityType:P,relationField:$,inheritData:U,onConfirm:G,onCancel:()=>_(!1)}),e.jsx(Mt,{isOpen:M,title:c.action.selectBookOrWork,filterType:"all",recentEntities:ee,excludeId:t.id,onSelect:Fe,onCancel:()=>{V(!1),A(null)},onSearch:J})]})};function Ro({items:t,onChange:n}){const r=W(),o=(a,l,d)=>{const u=t.map((g,x)=>x===a?{...g,[l]:d}:g);n(u)},i=a=>n(t.filter((l,d)=>d!==a)),s=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((a,l)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(X,{label:r.editor.bookNameLabel,value:a.book_title,onChange:d=>o(l,"book_title",d)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(X,{label:r.label.juanCount,value:a.n_juan!=null?String(a.n_juan):"",onChange:d=>o(l,"n_juan",d&&parseInt(d,10)||void 0)})}),e.jsx("button",{onClick:()=>i(l),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},l)),e.jsx("button",{onClick:s,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:r.action.addAdditionalWork})]})}function Lo({items:t,onChange:n}){const r=W(),[o,i]=p.useState(null),s=(d,u,g)=>{const x=t.map((f,c)=>c===d?{...f,[u]:g||void 0}:f);n(x)},a=d=>{n(t.filter((u,g)=>g!==d)),o===d&&i(null)},l=()=>{n([...t,{source:""}]),i(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((d,u)=>{const g=o===u;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>i(g?null:u),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:g?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:d.source||r.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(u)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid #ddd",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"#999"},children:"✕"})]}),!g&&(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]}),g&&e.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(X,{label:r.label.sourceName,value:d.source,onChange:x=>s(u,"source",x)}),e.jsx(X,{label:r.label.sourceBid,value:d.source_bid||"",onChange:x=>s(u,"source_bid",x)})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(X,{label:r.label.titleInfo,value:d.title_info||"",onChange:x=>s(u,"title_info",x)}),e.jsx(X,{label:r.label.authorInfo,value:d.author_info||"",onChange:x=>s(u,"author_info",x)})]}),e.jsx(X,{label:r.label.edition,value:d.edition||"",onChange:x=>s(u,"edition",x)}),e.jsx(ue,{value:d.summary||"",onChange:x=>s(u,"summary",x),placeholder:r.editor.summaryPlaceholder}),e.jsx(ue,{value:d.comment||"",onChange:x=>s(u,"comment",x),placeholder:r.editor.commentPlaceholder}),e.jsx(ue,{value:d.additional_comment||"",onChange:x=>s(u,"additional_comment",x),placeholder:r.editor.additionalCommentPlaceholder})]})]},u)}),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:r.action.addIndexedBy})]})}const dt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Ft=({isOpen:t,onClose:n,onSubmit:r})=>{const[o,i]=p.useState(null),[s,a]=p.useState(""),[l,d]=p.useState("idle"),[u,g]=p.useState(""),x=p.useRef(null);p.useEffect(()=>{t&&(i(null),a(""),d("idle"),g(""))},[t]),p.useEffect(()=>{o&&setTimeout(()=>{var w;return(w=x.current)==null?void 0:w.focus()},100)},[o]),p.useEffect(()=>{if(l==="success"){const w=setTimeout(n,2e3);return()=>clearTimeout(w)}},[l,n]),p.useEffect(()=>{if(!t)return;const w=b=>{b.key==="Escape"&&n()};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[t,n]);const f=async()=>{if(!(!o||!s.trim())){d("submitting"),g("");try{await r({type:o,content:s.trim()}),d("success")}catch(w){d("error"),g(w instanceof Error?w.message:"提交失败,请稍后重试")}}};if(!t)return null;const c=o&&s.trim()&&l!=="submitting",j=dt.find(w=>w.value===o);return e.jsx("div",{style:Eo,onClick:w=>{w.target===w.currentTarget&&n()},children:e.jsxs("div",{style:Bo,onClick:w=>w.stopPropagation(),children:[e.jsxs("div",{style:Wo,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:$o,"aria-label":"关闭",children:"✕"})]}),l==="success"?e.jsxs("div",{style:Ho,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:dt.map(w=>e.jsxs("button",{onClick:()=>i(w.value),style:{...Po,...o===w.value?Ao:{}},children:[e.jsx("span",{children:w.icon})," ",w.label]},w.value))}),e.jsx("textarea",{ref:x,value:s,onChange:w=>a(w.target.value),placeholder:(j==null?void 0:j.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!o||l==="submitting",style:{...Mo,opacity:o?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[s.length," / 2000"]}),l==="error"&&e.jsx("div",{style:Oo,children:u}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:f,disabled:!c,style:{...Fo,opacity:c?1:.6,cursor:c?"pointer":"not-allowed"},children:l==="submitting"?"提交中...":"提交反馈"})})]})]})})},Eo={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},Bo={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)"},Wo={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},$o={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},Po={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"},Ao={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Mo={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"},Fo={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Ho={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},Oo={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},Do=({onSubmit:t,position:n={bottom:24,right:24}})=>{const[r,o]=p.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>o(!0),style:{...Vo,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(Ft,{isOpen:r,onClose:()=>o(!1),onSubmit:t})]})},Vo={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"},No={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},Uo={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function Yo(t){try{const n=new Date(t),r=o=>String(o).padStart(2,"0");return`${n.getFullYear()}-${r(n.getMonth()+1)}-${r(n.getDate())} ${r(n.getHours())}:${r(n.getMinutes())}`}catch{return t}}const Go=({items:t,loading:n})=>n?e.jsx("div",{style:ct,children:"加载中..."}):t.length===0?e.jsx("div",{style:ct,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const o=No[r.type],i=Uo[r.status];return e.jsxs("div",{style:Jo,children:[e.jsxs("div",{style:Ko,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...pt,background:o.color},children:o.label}),e.jsx("span",{style:{...pt,background:i.color},children:i.label})]}),e.jsx("span",{style:Zo,children:Yo(r.createdAt)})]}),e.jsx("div",{style:Xo,children:r.content}),r.reply&&e.jsxs("div",{style:qo,children:[e.jsx("div",{style:Qo,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})}),ct={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},Jo={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},Ko={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},pt={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},Zo={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},Xo={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},qo={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},Qo={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},er=({style:t})=>{const n=p.useContext(je);if(!n)return null;const{locale:r,setLocale:o}=n,i=r==="zh-Hant",s=()=>o(i?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:s,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=H.BidLink;exports.BookIndexError=H.BookIndexError;exports.BookIndexManager=H.BookIndexManager;exports.BookIndexStorage=H.BookIndexStorage;exports.BundleStorage=H.BundleStorage;exports.ConfigError=H.ConfigError;exports.GithubStorage=H.GithubStorage;exports.IdGenerationError=H.IdGenerationError;exports.IdGenerator=H.IdGenerator;exports.LocalStorage=H.LocalStorage;exports.MigrationError=H.MigrationError;exports.StorageError=H.StorageError;exports.base58Decode=H.base58Decode;exports.base58Encode=H.base58Encode;exports.buildId=H.buildId;exports.decodeIdString=H.decodeIdString;exports.extractIdFromUrl=H.extractIdFromUrl;exports.extractStatus=H.extractStatus;exports.extractType=H.extractType;exports.normalizeCatalog=H.normalizeCatalog;exports.parseId=H.parseId;exports.validateResource=H.validateResource;exports.Badge=Ie;exports.CollatedEdition=Tt;exports.CollectionCatalog=jt;exports.CreateEntityDialog=Pt;exports.EntityPickerDialog=Mt;exports.EntitySelector=$t;exports.FeedbackButton=Do;exports.FeedbackDialog=Ft;exports.FeedbackList=Go;exports.FormInput=X;exports.FormTextArea=ue;exports.HomePage=_t;exports.IndexApp=Zn;exports.IndexBrowser=ht;exports.IndexDetail=vt;exports.IndexEditor=_o;exports.LocaleContext=je;exports.LocaleProvider=Zt;exports.LocaleToggle=er;exports.ModeIndicator=gt;exports.RelationPanel=Bt;exports.ResourceEditor=We;exports.ResourceList=Me;exports.SearchInput=ft;exports.Section=re;exports.SmartBidInput=ze;exports.SourceEditor=Rt;exports.WorkCatalog=Xn;exports.formatTemplate=Se;exports.parseSourceString=Lt;exports.stringifySources=Et;exports.useConvert=F;exports.useT=W;
|
package/dist/index.d.ts
CHANGED
|
@@ -237,6 +237,7 @@ export declare class BundleStorage implements IndexStorage {
|
|
|
237
237
|
getCollatedEditionIndex(workId: string): Promise<CollatedEditionIndex | null>;
|
|
238
238
|
getCollatedJuan(workId: string, juanFile: string): Promise<CollatedJuan | null>;
|
|
239
239
|
getResourceProgress(): Promise<ResourceProgress | null>;
|
|
240
|
+
getSiteProgress(): Promise<ResourceProgress | null>;
|
|
240
241
|
getRecommended(): Promise<RecommendedData | null>;
|
|
241
242
|
clearCache(): void;
|
|
242
243
|
}
|
|
@@ -633,6 +634,7 @@ export declare class GithubStorage implements IndexStorage {
|
|
|
633
634
|
getCollatedEditionIndex(workId: string): Promise<CollatedEditionIndex | null>;
|
|
634
635
|
getCollatedJuan(workId: string, juanFile: string): Promise<CollatedJuan | null>;
|
|
635
636
|
getResourceProgress(): Promise<ResourceProgress | null>;
|
|
637
|
+
getSiteProgress(): Promise<ResourceProgress | null>;
|
|
636
638
|
getRecommended(): Promise<RecommendedData | null>;
|
|
637
639
|
/** 清除缓存(用于切换数据源后刷新) */
|
|
638
640
|
clearCache(): void;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { e as Wt } from "./storage-entry-
|
|
2
|
-
import { B as ai, a as di, b as ci, c as si, d as pi, C as gi, G as ui, I as fi, f as hi, L as xi, M as bi, S as mi, g as yi, h as vi, i as ki, j as Si, k as wi, l as Ci, n as zi, p as Ii, v as Ti } from "./storage-entry-
|
|
1
|
+
import { e as Wt } from "./storage-entry-CT6PuEDo.js";
|
|
2
|
+
import { B as ai, a as di, b as ci, c as si, d as pi, C as gi, G as ui, I as fi, f as hi, L as xi, M as bi, S as mi, g as yi, h as vi, i as ki, j as Si, k as wi, l as Ci, n as zi, p as Ii, v as Ti } from "./storage-entry-CT6PuEDo.js";
|
|
3
3
|
import { jsx as t, jsxs as r, Fragment as F } from "react/jsx-runtime";
|
|
4
4
|
import xt, { createContext as Et, useState as k, useEffect as j, useCallback as A, useMemo as he, useContext as Fe, useRef as te } from "react";
|
|
5
5
|
const Re = Et(null), bt = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var nt=Object.create;var H=Object.defineProperty;var ot=Object.getOwnPropertyDescriptor;var it=Object.getOwnPropertyNames;var rt=Object.getPrototypeOf,at=Object.prototype.hasOwnProperty;var ct=(a,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of it(t))!at.call(a,n)&&n!==e&&H(a,n,{get:()=>t[n],enumerable:!(s=ot(t,n))||s.enumerable});return a};var q=(a,t,e)=>(e=a!=null?nt(rt(a)):{},ct(t||!a||!a.__esModule?H(e,"default",{value:a,enumerable:!0}):e,a));const lt={official:0,draft:1},ht={0:"official",1:"draft"},ut={book:0,collection:2,work:3},dt={0:"book",2:"collection",3:"work"},X=62n,V=59n,Q=19n,Z=8n,tt=(1n<<40n)-1n,ft=(1n<<3n)-1n,gt=(1n<<11n)-1n,yt=(1n<<8n)-1n,O="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",et=new Map;for(let a=0;a<O.length;a++)et.set(O[a],BigInt(a));function R(a){if(a===0n)return O[0];let t="";for(;a>0n;)t=O[Number(a%58n)]+t,a=a/58n;return t}function x(a){let t=0n;for(const e of a){const s=et.get(e);if(s===void 0)throw new Error(`Invalid Base58 character: ${e}`);t=t*58n+s}return t}function C(a){const t=Number(a>>X&1n),e=Number(a>>V&ft),s=a>>Q&tt,n=Number(a>>Z>),o=Number(a&yt);return{status:ht[t]??"draft",type:dt[e]??"book",timestamp:s,machineId:n,sequence:o}}function U(a,t,e,s,n){return BigInt(lt[a])<<X|BigInt(ut[t])<<V|(e&tt)<<Q|BigInt(s)<<Z|BigInt(n)}function A(a){return C(x(a))}function pt(a){return A(a).type}function mt(a){return A(a).status}const M={book:"Book",collection:"Collection",work:"Work"},wt={Book:"book",Collection:"collection",Work:"work"},$=16;function D(a,t=$){let e=0;for(let s=0;s<a.length;s++)e=Math.imul(e,31)+a.charCodeAt(s)>>>0;return e%t}function k(...a){const t=a.join("/");return t.startsWith("//")?"//"+t.slice(2).replace(/\/+/g,"/"):t.replace(/\/+/g,"/")}function _t(a){return a.replace(/[^\u4e00-\u9fa5a-zA-Z0-9]/g,"")||"Undefined"}class W{constructor(t,e){this.fs=t,this.officialRoot=k(e,"book-index"),this.draftRoot=k(e,"book-index-draft")}getRootByStatus(t){return t==="draft"?this.draftRoot:this.officialRoot}getRootById(t){const e=x(t),s=C(e);return this.getRootByStatus(s.status)}getPath(t,e,s){const n=this.getRootById(e),o=e.padEnd(3,"_").substring(0,3),[i,r,c]=[o[0],o[1],o[2]],l=M[t];return k(n,l,i,r,c,`${e}-${_t(s)}.json`)}async saveItem(t,e,s){const n=s.title||s.书名||"未命名",o=s.edition||"",i=o?`${n}${o}`:n,r=this.getPath(t,e,i),c=await this.findFileById(e);if(c&&c!==r)try{await this.fs.deleteFile(c)}catch{}const l=r.substring(0,r.lastIndexOf("/"));await this.fs.mkdir(l),s.id=e,s.type=t,await this.fs.writeFile(r,JSON.stringify(s,kt,2));const d=this.getRootById(e),h=r.substring(d.length+1);return await this.updateIndexEntry(d,s,t,h),r}async updateIndexEntry(t,e,s,n){const o=e.id||"";if(!o)return;const i=`${s}s`,r=await this.loadShard(t,i,o);let c="";const l=e.authors;if(Array.isArray(l)&&l.length>0){const y=l[0];c=typeof y=="object"&&y!==null?y.name||"":String(y)}else typeof l=="string"&&(c=l);let d="";const h=e.publication_info;typeof h=="object"&&h!==null?d=h.year||"":typeof h=="string"&&(d=h);let u="";const f=e.current_location;typeof f=="object"&&f!==null?u=f.name||"":typeof f=="string"&&(u=f);const g=Array.isArray(e.additional_titles)?e.additional_titles.filter(y=>typeof y=="string"&&y):void 0;let _;const b=e.juan_count;typeof b=="number"?_=b:typeof b=="object"&&b!==null&&(_=b.number||void 0);let E=!1,v=!1;const S=e.resources;if(Array.isArray(S))for(const y of S){const m=typeof y=="object"&&y!==null?y.type:"";(m==="text"||m==="text+image")&&(E=!0),(m==="image"||m==="text+image")&&(v=!0)}const I={id:o,title:e.title||"未命名",type:M[s],path:n,author:c,year:d,holder:u};g&&g.length>0&&(I.additional_titles=g),_&&(I.juan_count=_);const j=typeof e.edition=="string"?e.edition:"";j&&(I.edition=j),E&&(I.has_text=!0),v&&(I.has_image=!0),r[o]=I,await this.saveShard(t,i,o,r)}async deleteItem(t){const e=await this.findFileById(t);if(!e)return!1;const s=x(t),n=C(s),o=this.getRootByStatus(n.status),i=`${n.type}s`,r=await this.loadShard(o,i,t);return r[t]&&(delete r[t],await this.saveShard(o,i,t,r)),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 r of["Book","Collection","Work"]){const c=k(i,r,s,n,o);if(await this.fs.exists(c))try{const d=(await this.fs.readdir(c)).find(h=>h.startsWith(`${t}-`)&&h.endsWith(".json"));if(d)return k(c,d)}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 r=await this.loadAllShards(i,o);for(const[c,l]of Object.entries(r))n.push({id:c,title:l.title,type:t,author:l.author||void 0,dynasty:l.dynasty||void 0,role:l.role||void 0,path:k(i,l.path),additional_titles:l.additional_titles,edition:l.edition,juan_count:l.juan_count,has_text:l.has_text,has_image:l.has_image})}return n}async searchEntries(t,e,s){const n=await this.loadEntries(e,s);return P(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:$},(i,r)=>[r,{}])),collections:{0:{}},works:Object.fromEntries(Array.from({length:$},(i,r)=>[r,{}]))};for(const i of["Book","Collection","Work"]){const r=k(e,i);if(!await this.fs.exists(r))continue;const l=`${wt[i]}s`,d=await this.fs.glob(r,"**/*.json");for(const h of d)if(!h.includes("/index/"))try{const u=await this.loadMetadata(h);let f=u.id||u.ID||"";if(!f){const p=h.substring(h.lastIndexOf("/")+1);p.includes("-")&&(f=p.split("-")[0])}if(!f)continue;const g=h.substring(e.length+1);let _="";const b=u.authors;if(Array.isArray(b)&&b.length>0){const p=b[0];_=typeof p=="object"&&p!==null?p.name||"":String(p)}const E=Array.isArray(u.additional_titles)?u.additional_titles.filter(p=>typeof p=="string"&&p):void 0;let v;const S=u.juan_count;typeof S=="number"?v=S:typeof S=="object"&&S!==null&&(v=S.number||void 0);let I=!1,j=!1;const y=u.resources;if(Array.isArray(y))for(const p of y){const B=typeof p=="object"&&p!==null?p.type:"";(B==="text"||B==="text+image")&&(I=!0),(B==="image"||B==="text+image")&&(j=!0)}const m={id:f,title:u.title||"未命名",type:i,path:g,author:_,year:typeof u.publication_info=="object"&&((n=u.publication_info)==null?void 0:n.year)||"",holder:typeof u.current_location=="object"&&((o=u.current_location)==null?void 0:o.name)||""};E&&E.length>0&&(m.additional_titles=E),v&&(m.juan_count=v);const G=typeof u.edition=="string"?u.edition:"";G&&(m.edition=G),I&&(m.has_text=!0),j&&(m.has_image=!0);const st=l==="collections"?0:D(f);s[l][st][f]=m}catch{}}for(const[i,r]of Object.entries(s))for(const[c,l]of Object.entries(r)){const d=this.shardPath(e,i,Number(c)),h=d.substring(0,d.lastIndexOf("/"));await this.fs.mkdir(h),await this.fs.writeFile(d,JSON.stringify(l,null,2))}}getAssetDir(t){const e=this.getRootById(t),s=x(t),o=C(s).type,i=t.padEnd(3,"_").substring(0,3),[r,c,l]=[i[0],i[1],i[2]],d=M[o];return k(e,d,r,c,l,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"?k(t,"index","collections.json"):k(t,"index",e,`${s.toString(16)}.json`)}async loadShard(t,e,s){const n=D(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=D(s),i=this.shardPath(t,e,o),r=i.substring(0,i.lastIndexOf("/"));await this.fs.mkdir(r),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<$;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 L(a,t){const e=t.toLowerCase();let s=0;const n=a.title.toLowerCase();if(n===e?s+=200:n.startsWith(e)?s+=150:n.includes(e)&&(s+=100),a.additional_titles){let o=0;for(const i of a.additional_titles){const r=i.toLowerCase();r===e?o=Math.max(o,120):r.startsWith(e)?o=Math.max(o,90):r.includes(e)&&(o=Math.max(o,60))}s+=o}if(a.author){const o=a.author.toLowerCase();o===e?s+=80:o.includes(e)&&(s+=50)}return a.dynasty&&a.dynasty.toLowerCase().includes(e)&&(s+=30),s===0?0:(a.type==="work"?s=Math.round(s*1.1):a.type==="collection"&&(s=Math.round(s*1.05)),a.has_text&&(s+=15),a.has_image&&(s+=10),s)}function kt(a,t){return t===null?void 0:t}function P(a,t){const e=a.map(s=>({entry:s,score:L(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 F(a,t,e,s){const n=a.map(o=>{const i=L(o,t);let r=0;const c=s[o.id];if(c&&e){const l={...o,title:c.t??o.title,author:c.a??o.author,additional_titles:c.at??o.additional_titles};r=L(l,e)}return{entry:o,score:Math.max(i,r)}}).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 bt(a){const t=a.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 r={};for(const[c,l]of Object.entries(o))c==="volume"||c==="status"||c==="file"||typeof l=="string"&&(c.includes("url")||c.includes("id"))&&(r[c]=l);s.push({volume:i,status:o.status,urls:Object.keys(r).length>0?r:void 0,file:o.file})}}const n={title:a.title??"",book_id:a.book_id??null,work_id:a.work_id??null,volumes:e,section:a.section,sub_items:a.sub_items,edition:a.edition,expected_volumes:a.expected_volumes,found_volumes:a.found_volumes,missing_volumes:a.missing_vols??a.missing_volumes};s&&(n.volume_details=s);for(const o of Object.keys(n))n[o]===void 0&&delete n[o];return n}function It(a){const t={total_books:a.total_books??0};return a.processed_volumes!=null&&(t.processed_volumes=a.processed_volumes),a.matched_works!=null&&(t.matched_works=a.matched_works),a.unmatched_works!=null&&(t.unmatched_works=a.unmatched_works),a.total_found_volumes!=null&&(t.total_found_volumes=a.total_found_volumes),t}function J(a){var n;const t=a,e=(t.books??[]).map(bt),s={collection_id:t.collection_id??"",title:t.title??"",total_volumes:t.total_volumes??0,stats:It(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 St="https://raw.githubusercontent.com",xt=["https://fastly.jsdelivr.net/gh","https://cdn.jsdelivr.net/gh"],vt=5e3;class Et{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??St,cdnUrls:t.cdnUrls??xt,timeout:t.timeout??vt}}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 fetchIndex(t){const e={books:{},collections:{},works:{}};try{const n=await this.fetchFileWithFallback(t,"index/collections.json");e.collections=n}catch{}const s=[];for(const n of["books","works"])for(let o=0;o<$;o++){const i=`index/${n}/${o.toString(16)}.json`;s.push(this.fetchFileWithFallback(t,i).then(r=>{Object.assign(e[n],r)}).catch(()=>{}))}return await Promise.all(s),e}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){const s=[],n=[["books","book"],["collections","collection"],["works","work"]];for(const[o,i]of n){const r=t[o];if(r)for(const c of Object.values(r)){const l=c;s.push({id:c.id,title:c.title||c.name||c.id,type:i,isDraft:e,author:c.author,dynasty:c.dynasty,role:c.role,path:c.path,additional_titles:l.additional_titles,edition:l.edition,juan_count:l.juan_count,has_text:l.has_text,has_image:l.has_image,has_collated:l.has_collated}),this.pathMap.set(c.id,{path:c.path,isDraft:e})}}return s}async ensureSearchSBuilt(){var n;if(this.searchSCache)return{searchS:this.searchSCache,converter:this.t2sConverter||null};if(this.t2sConverter===!1)return{searchS:{},converter:null};try{const o=await import("opencc-js");this.t2sConverter=o.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 o of t){const i={},r=e(o.title);if(r!==o.title&&(i.t=r),o.author){const c=e(o.author);c!==o.author&&(i.a=c)}if((n=o.additional_titles)!=null&&n.length){const c=o.additional_titles.map(e);c.some((l,d)=>l!==o.additional_titles[d])&&(i.at=c)}Object.keys(i).length>0&&(s[o.id]=i)}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,u)=>{const f=String(h[o]??""),g=String(u[o]??""),_=f.localeCompare(g,"zh");return i==="asc"?_:-_});const r=e.page||1,c=e.pageSize||50,l=(r-1)*c;return{entries:n.slice(l,l+c),total:n.length,page:r,pageSize:c}}async search(t,e,s){const n=await this.ensureLoaded(),{searchS:o,converter:i}=await this.ensureSearchSBuilt(),r=n.filter(g=>g.type===e),c=i?i(t):void 0,d=Object.keys(o).length>0?F(r,t,c,o):P(r,t),h=s.page||1,u=s.pageSize||50,f=(h-1)*u;return{entries:d.slice(f,f+u),total:d.length,page:h,pageSize:u}}async searchAll(t,e=5){const s=await this.ensureLoaded(),{searchS:n,converter:o}=await this.ensureSearchSBuilt(),i=["work","book","collection"],r=o?o(t):void 0,c=Object.keys(n).length>0,l=i.map(d=>{const h=s.filter(u=>u.type===d);return c?F(h,t,r,n):P(h,t)});return{works:l[0].slice(0,e),books:l[1].slice(0,e),collections:l[2].slice(0,e),totalWorks:l[0].length,totalBooks:l[1].length,totalCollections:l[2].length}}async getItem(t){const e=await this.ensureLoaded(),s=this.pathMap.get(t);if(!s)return null;const n=s.isDraft?this.config.repos.draft:this.config.repos.official;let o=null;const i=`${this.config.baseUrl}/${this.config.org}/${n}/main/${encodeURI(s.path)}`;try{o=await this.fetchJson(i)}catch{}if(!o)for(const r of this.config.cdnUrls){const c=`${r}/${this.config.org}/${n}@main/${encodeURI(s.path)}`;try{o=await this.fetchJson(c);break}catch{continue}}if(o){const r=e.find(c=>c.id===t);r!=null&&r.has_collated&&(o.has_collated=!0)}return o}async getEntry(t){return(await this.ensureLoaded()).find(s=>s.id===t)||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 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();const e=this.pathMap.get(t);if(!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 r=`${e.dir}/${t}/${i.id}/volume_book_mapping.json`,c=await this.fetchFile(e.repo,r);c&&o.push({resource_id:i.id,short_name:i.short_name,data:J(c)})}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 getRecommended(){return this.fetchFile(this.config.repos.draft,"recommended.json")}clearCache(){this.cache=null,this.pathMap.clear(),this.searchSCache=null,this.t2sConverter=null}}const K=255;class z{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&K,this.sequence===0&&(s=this._tilNextUnit(this.lastTimestamp,t))):this.sequence=0,this.lastTimestamp=s,this.lastStatus=t;const n=U(t,e,BigInt(s),this.machineId,this.sequence);return R(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&K,this.sequence===0&&(s=this._tilNextUnit(this.lastTimestamp,t))):this.sequence=0,this.lastTimestamp=s,this.lastStatus=t,U(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 Ct{constructor(t){this.recentEntities=[],this.storage=new W(t.fs,t.workspaceRoot),this.idGen=new z(t.machineId??0)}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){return this.storage.getItem(t)}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 r=await this.resolveEntity(i);r&&(s.belongsToCollection={...r,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(c=>(typeof c=="string"?c:c.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 r of i)n.push({id:r.id,title:r.title,type:r.type,author:r.author,dynasty:r.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}}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=x(t);return C(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 c=e.sortBy,l=e.sortOrder==="desc"?-1:1;t.sort((d,h)=>{const u=d[c]??"",f=h[c]??"";return u<f?-l:u>f?l:0})}const o=t.length,i=(s-1)*n;return{entries:t.slice(i,i+n),total:o,page:s,pageSize:n}}}const At="/data",Tt=1e4;class jt{constructor(t={}){this.indexCache=null,this.pathMap=new Map,this.chunkCache=new Map,this.tiyaoCache=new Map,this.searchSCache=null,this.searchSLoaded=!1,this.t2sConverter=null,this.basePath=t.basePath??At,this.timeout=t.timeout??Tt}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(){if(this.indexCache)return this.indexCache;const t=await this.fetchJson(`${this.basePath}/index.json`),e=[],s=[["books","book"],["collections","collection"],["works","work"]];for(const[n,o]of s){const i=t[n];if(i)for(const r of Object.values(i))e.push({id:r.id,title:r.title||r.name||r.id,type:o,isDraft:!0,author:r.author,dynasty:r.dynasty,role:r.role,path:r.path,additional_titles:r.additional_titles,edition:r.edition,juan_count:r.juan_count,has_text:r.has_text,has_image:r.has_image,has_collated:r.has_collated}),this.pathMap.set(r.id,{path:r.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 loadChunk(t){if(this.chunkCache.has(t))return this.chunkCache.get(t);const e=await this.fetchJson(`${this.basePath}/chunks/${t}.json`);return this.chunkCache.set(t,e),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 loadEntries(t,e){let n=(await this.ensureLoaded()).filter(d=>d.type===t);const o=e.sortBy||"title",i=e.sortOrder||"asc";n.sort((d,h)=>{const u=String(d[o]??""),f=String(h[o]??""),g=u.localeCompare(f,"zh");return i==="asc"?g:-g});const r=e.page||1,c=e.pageSize||50,l=(r-1)*c;return{entries:n.slice(l,l+c),total:n.length,page:r,pageSize:c}}async search(t,e,s){const n=await this.ensureLoaded(),o=await this.ensureSearchSLoaded(),i=await this.ensureT2S(),r=n.filter(g=>g.type===e),c=i?i(t):void 0,d=Object.keys(o).length>0?F(r,t,c,o):P(r,t),h=s.page||1,u=s.pageSize||50,f=(h-1)*u;return{entries:d.slice(f,f+u),total:d.length,page:h,pageSize:u}}async searchAll(t,e=5){const s=await this.ensureLoaded(),n=await this.ensureSearchSLoaded(),o=await this.ensureT2S(),i=["work","book","collection"],r=o?o(t):void 0,c=Object.keys(n).length>0,l=i.map(d=>{const h=s.filter(u=>u.type===d);return c?F(h,t,r,n):P(h,t)});return{works:l[0].slice(0,e),books:l[1].slice(0,e),collections:l[2].slice(0,e),totalWorks:l[0].length,totalBooks:l[1].length,totalCollections:l[2].length}}async getItem(t){const e=t.slice(0,2);try{const n=(await this.loadChunk(e))[t]||null;if(n){const o=(await this.ensureLoaded()).find(i=>i.id===t);o!=null&&o.has_collated&&(n.has_collated=!0)}return n}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){const i=`${t}/${o.id}/volume_book_mapping`,r=t.slice(0,2);try{const l=(await this.loadChunk(r))[i];l&&n.push({resource_id:o.id,short_name:o.short_name,data:J(l)})}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){const e=t.slice(0,2);try{const s=await this.loadChunk(e),n=`${t}/collated_edition_index`;return s[n]||null}catch{return null}}async getCollatedJuan(t,e){if(e.includes("..")||!e.endsWith(".json"))return null;const s=e.match(/juan(\d+)/);if(!s)return null;const n=parseInt(s[1]),o=10,i=Math.ceil(n/o),r=(i-1)*o+1,c=i*o;try{return(await this.loadTiyaoGroup(r,c))[e]||null}catch{return null}}async getResourceProgress(){try{return await this.fetchJson(`${this.basePath}/resource.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.tiyaoCache.clear(),this.searchSCache=null,this.searchSLoaded=!1,this.t2sConverter=null}}class T extends Error{constructor(t){super(t),this.name="BookIndexError"}}class $t extends T{constructor(t){super(t),this.name="StorageError"}}class Pt extends T{constructor(t){super(t),this.name="IdGenerationError"}}class Bt extends T{constructor(t){super(t),this.name="ConfigError"}}class Ot extends T{constructor(t){super(t),this.name="MigrationError"}}class Ft{constructor(t,e,s=1){this.storage=new W(t,e),this.idGen=new z(s)}generateId(t="book",e="draft"){return this.idGen.nextIdRaw(e,t)}encodeId(t){return R(t)}decodeId(t){return x(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"},r=e in i?i[e]:e;if(r===null)return!1;if(r==="description"&&typeof s=="string"){const l=o[r]||{};o[r]={text:s,sources:l.sources||[]}}else o[r]=s;const c=A(t);return await this.storage.saveItem(c.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 Rt={wikisource:"wikisource",shidianguji:"shidianguji",archive:"archive",ctext:"ctext",nlc:"nlc","read.nlc":"nlc","db.sido":"sido","guji.artx":"guji-artx","digital.library":"digital-library"},Y=new Set(["text","image","text+image","physical"]),Mt=new Set(["catalog","search"]),Dt=new Set(["com","org","net","cn","edu","gov","io","jp","tw","hk"]);function Ut(a){if(!a)return"";try{const e=new URL(a).hostname;for(const[n,o]of Object.entries(Rt))if(e.includes(n))return o;const s=e.split(".");if(s.length>=2){const n=s.filter(o=>!Dt.has(o)&&o.length>2);return n.length>0?n[n.length-1]:s[s.length-2]}return e}catch{return""}}function Lt(a){const t=[];return a.name||t.push("name is required"),Y.has(a.type)||t.push(`invalid type '${a.type}', must be one of ${[...Y].join(", ")}`),a.root_type&&!Mt.has(a.root_type)&&t.push(`invalid root_type '${a.root_type}'`),a.type!=="physical"&&!a.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=x(t)}catch{this.idInt=0n}}else this.idInt=t,this.idStr=R(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 N=w;exports.BidLink=N;exports.BookIndexError=T;exports.BookIndexManager=Ft;exports.BookIndexStorage=W;exports.BundleStorage=jt;exports.ConfigError=Bt;exports.GithubStorage=Et;exports.IdGenerationError=Pt;exports.IdGenerator=z;exports.LocalStorage=Ct;exports.MigrationError=Ot;exports.StorageError=$t;exports.base58Decode=x;exports.base58Encode=R;exports.buildId=U;exports.decodeIdString=A;exports.extractIdFromUrl=Ut;exports.extractStatus=mt;exports.extractType=pt;exports.normalizeCatalog=J;exports.parseId=C;exports.validateResource=Lt;
|
|
1
|
+
"use strict";var nt=Object.create;var H=Object.defineProperty;var ot=Object.getOwnPropertyDescriptor;var it=Object.getOwnPropertyNames;var rt=Object.getPrototypeOf,at=Object.prototype.hasOwnProperty;var ct=(a,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of it(t))!at.call(a,n)&&n!==e&&H(a,n,{get:()=>t[n],enumerable:!(s=ot(t,n))||s.enumerable});return a};var q=(a,t,e)=>(e=a!=null?nt(rt(a)):{},ct(t||!a||!a.__esModule?H(e,"default",{value:a,enumerable:!0}):e,a));const lt={official:0,draft:1},ht={0:"official",1:"draft"},ut={book:0,collection:2,work:3},dt={0:"book",2:"collection",3:"work"},X=62n,V=59n,Q=19n,Z=8n,tt=(1n<<40n)-1n,ft=(1n<<3n)-1n,gt=(1n<<11n)-1n,yt=(1n<<8n)-1n,F="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",et=new Map;for(let a=0;a<F.length;a++)et.set(F[a],BigInt(a));function R(a){if(a===0n)return F[0];let t="";for(;a>0n;)t=F[Number(a%58n)]+t,a=a/58n;return t}function x(a){let t=0n;for(const e of a){const s=et.get(e);if(s===void 0)throw new Error(`Invalid Base58 character: ${e}`);t=t*58n+s}return t}function C(a){const t=Number(a>>X&1n),e=Number(a>>V&ft),s=a>>Q&tt,n=Number(a>>Z>),o=Number(a&yt);return{status:ht[t]??"draft",type:dt[e]??"book",timestamp:s,machineId:n,sequence:o}}function U(a,t,e,s,n){return BigInt(lt[a])<<X|BigInt(ut[t])<<V|(e&tt)<<Q|BigInt(s)<<Z|BigInt(n)}function A(a){return C(x(a))}function pt(a){return A(a).type}function mt(a){return A(a).status}const M={book:"Book",collection:"Collection",work:"Work"},wt={Book:"book",Collection:"collection",Work:"work"},$=16;function D(a,t=$){let e=0;for(let s=0;s<a.length;s++)e=Math.imul(e,31)+a.charCodeAt(s)>>>0;return e%t}function k(...a){const t=a.join("/");return t.startsWith("//")?"//"+t.slice(2).replace(/\/+/g,"/"):t.replace(/\/+/g,"/")}function _t(a){return a.replace(/[^\u4e00-\u9fa5a-zA-Z0-9]/g,"")||"Undefined"}class W{constructor(t,e){this.fs=t,this.officialRoot=k(e,"book-index"),this.draftRoot=k(e,"book-index-draft")}getRootByStatus(t){return t==="draft"?this.draftRoot:this.officialRoot}getRootById(t){const e=x(t),s=C(e);return this.getRootByStatus(s.status)}getPath(t,e,s){const n=this.getRootById(e),o=e.padEnd(3,"_").substring(0,3),[i,r,c]=[o[0],o[1],o[2]],l=M[t];return k(n,l,i,r,c,`${e}-${_t(s)}.json`)}async saveItem(t,e,s){const n=s.title||s.书名||"未命名",o=s.edition||"",i=o?`${n}${o}`:n,r=this.getPath(t,e,i),c=await this.findFileById(e);if(c&&c!==r)try{await this.fs.deleteFile(c)}catch{}const l=r.substring(0,r.lastIndexOf("/"));await this.fs.mkdir(l),s.id=e,s.type=t,await this.fs.writeFile(r,JSON.stringify(s,kt,2));const d=this.getRootById(e),h=r.substring(d.length+1);return await this.updateIndexEntry(d,s,t,h),r}async updateIndexEntry(t,e,s,n){const o=e.id||"";if(!o)return;const i=`${s}s`,r=await this.loadShard(t,i,o);let c="";const l=e.authors;if(Array.isArray(l)&&l.length>0){const y=l[0];c=typeof y=="object"&&y!==null?y.name||"":String(y)}else typeof l=="string"&&(c=l);let d="";const h=e.publication_info;typeof h=="object"&&h!==null?d=h.year||"":typeof h=="string"&&(d=h);let u="";const f=e.current_location;typeof f=="object"&&f!==null?u=f.name||"":typeof f=="string"&&(u=f);const g=Array.isArray(e.additional_titles)?e.additional_titles.filter(y=>typeof y=="string"&&y):void 0;let _;const b=e.juan_count;typeof b=="number"?_=b:typeof b=="object"&&b!==null&&(_=b.number||void 0);let E=!1,v=!1;const S=e.resources;if(Array.isArray(S))for(const y of S){const m=typeof y=="object"&&y!==null?y.type:"";(m==="text"||m==="text+image")&&(E=!0),(m==="image"||m==="text+image")&&(v=!0)}const I={id:o,title:e.title||"未命名",type:M[s],path:n,author:c,year:d,holder:u};g&&g.length>0&&(I.additional_titles=g),_&&(I.juan_count=_);const j=typeof e.edition=="string"?e.edition:"";j&&(I.edition=j),E&&(I.has_text=!0),v&&(I.has_image=!0),r[o]=I,await this.saveShard(t,i,o,r)}async deleteItem(t){const e=await this.findFileById(t);if(!e)return!1;const s=x(t),n=C(s),o=this.getRootByStatus(n.status),i=`${n.type}s`,r=await this.loadShard(o,i,t);return r[t]&&(delete r[t],await this.saveShard(o,i,t,r)),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 r of["Book","Collection","Work"]){const c=k(i,r,s,n,o);if(await this.fs.exists(c))try{const d=(await this.fs.readdir(c)).find(h=>h.startsWith(`${t}-`)&&h.endsWith(".json"));if(d)return k(c,d)}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 r=await this.loadAllShards(i,o);for(const[c,l]of Object.entries(r))n.push({id:c,title:l.title,type:t,author:l.author||void 0,dynasty:l.dynasty||void 0,role:l.role||void 0,path:k(i,l.path),additional_titles:l.additional_titles,edition:l.edition,juan_count:l.juan_count,has_text:l.has_text,has_image:l.has_image})}return n}async searchEntries(t,e,s){const n=await this.loadEntries(e,s);return P(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:$},(i,r)=>[r,{}])),collections:{0:{}},works:Object.fromEntries(Array.from({length:$},(i,r)=>[r,{}]))};for(const i of["Book","Collection","Work"]){const r=k(e,i);if(!await this.fs.exists(r))continue;const l=`${wt[i]}s`,d=await this.fs.glob(r,"**/*.json");for(const h of d)if(!h.includes("/index/"))try{const u=await this.loadMetadata(h);let f=u.id||u.ID||"";if(!f){const p=h.substring(h.lastIndexOf("/")+1);p.includes("-")&&(f=p.split("-")[0])}if(!f)continue;const g=h.substring(e.length+1);let _="";const b=u.authors;if(Array.isArray(b)&&b.length>0){const p=b[0];_=typeof p=="object"&&p!==null?p.name||"":String(p)}const E=Array.isArray(u.additional_titles)?u.additional_titles.filter(p=>typeof p=="string"&&p):void 0;let v;const S=u.juan_count;typeof S=="number"?v=S:typeof S=="object"&&S!==null&&(v=S.number||void 0);let I=!1,j=!1;const y=u.resources;if(Array.isArray(y))for(const p of y){const B=typeof p=="object"&&p!==null?p.type:"";(B==="text"||B==="text+image")&&(I=!0),(B==="image"||B==="text+image")&&(j=!0)}const m={id:f,title:u.title||"未命名",type:i,path:g,author:_,year:typeof u.publication_info=="object"&&((n=u.publication_info)==null?void 0:n.year)||"",holder:typeof u.current_location=="object"&&((o=u.current_location)==null?void 0:o.name)||""};E&&E.length>0&&(m.additional_titles=E),v&&(m.juan_count=v);const G=typeof u.edition=="string"?u.edition:"";G&&(m.edition=G),I&&(m.has_text=!0),j&&(m.has_image=!0);const st=l==="collections"?0:D(f);s[l][st][f]=m}catch{}}for(const[i,r]of Object.entries(s))for(const[c,l]of Object.entries(r)){const d=this.shardPath(e,i,Number(c)),h=d.substring(0,d.lastIndexOf("/"));await this.fs.mkdir(h),await this.fs.writeFile(d,JSON.stringify(l,null,2))}}getAssetDir(t){const e=this.getRootById(t),s=x(t),o=C(s).type,i=t.padEnd(3,"_").substring(0,3),[r,c,l]=[i[0],i[1],i[2]],d=M[o];return k(e,d,r,c,l,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"?k(t,"index","collections.json"):k(t,"index",e,`${s.toString(16)}.json`)}async loadShard(t,e,s){const n=D(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=D(s),i=this.shardPath(t,e,o),r=i.substring(0,i.lastIndexOf("/"));await this.fs.mkdir(r),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<$;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 L(a,t){const e=t.toLowerCase();let s=0;const n=a.title.toLowerCase();if(n===e?s+=200:n.startsWith(e)?s+=150:n.includes(e)&&(s+=100),a.additional_titles){let o=0;for(const i of a.additional_titles){const r=i.toLowerCase();r===e?o=Math.max(o,120):r.startsWith(e)?o=Math.max(o,90):r.includes(e)&&(o=Math.max(o,60))}s+=o}if(a.author){const o=a.author.toLowerCase();o===e?s+=80:o.includes(e)&&(s+=50)}return a.dynasty&&a.dynasty.toLowerCase().includes(e)&&(s+=30),s===0?0:(a.type==="work"?s=Math.round(s*1.1):a.type==="collection"&&(s=Math.round(s*1.05)),a.has_text&&(s+=15),a.has_image&&(s+=10),s)}function kt(a,t){return t===null?void 0:t}function P(a,t){const e=a.map(s=>({entry:s,score:L(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(a,t,e,s){const n=a.map(o=>{const i=L(o,t);let r=0;const c=s[o.id];if(c&&e){const l={...o,title:c.t??o.title,author:c.a??o.author,additional_titles:c.at??o.additional_titles};r=L(l,e)}return{entry:o,score:Math.max(i,r)}}).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 bt(a){const t=a.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 r={};for(const[c,l]of Object.entries(o))c==="volume"||c==="status"||c==="file"||typeof l=="string"&&(c.includes("url")||c.includes("id"))&&(r[c]=l);s.push({volume:i,status:o.status,urls:Object.keys(r).length>0?r:void 0,file:o.file})}}const n={title:a.title??"",book_id:a.book_id??null,work_id:a.work_id??null,volumes:e,section:a.section,sub_items:a.sub_items,edition:a.edition,expected_volumes:a.expected_volumes,found_volumes:a.found_volumes,missing_volumes:a.missing_vols??a.missing_volumes};s&&(n.volume_details=s);for(const o of Object.keys(n))n[o]===void 0&&delete n[o];return n}function It(a){const t={total_books:a.total_books??0};return a.processed_volumes!=null&&(t.processed_volumes=a.processed_volumes),a.matched_works!=null&&(t.matched_works=a.matched_works),a.unmatched_works!=null&&(t.unmatched_works=a.unmatched_works),a.total_found_volumes!=null&&(t.total_found_volumes=a.total_found_volumes),t}function J(a){var n;const t=a,e=(t.books??[]).map(bt),s={collection_id:t.collection_id??"",title:t.title??"",total_volumes:t.total_volumes??0,stats:It(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 St="https://raw.githubusercontent.com",xt=["https://fastly.jsdelivr.net/gh","https://cdn.jsdelivr.net/gh"],vt=5e3;class Et{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??St,cdnUrls:t.cdnUrls??xt,timeout:t.timeout??vt}}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 fetchIndex(t){const e={books:{},collections:{},works:{}};try{const n=await this.fetchFileWithFallback(t,"index/collections.json");e.collections=n}catch{}const s=[];for(const n of["books","works"])for(let o=0;o<$;o++){const i=`index/${n}/${o.toString(16)}.json`;s.push(this.fetchFileWithFallback(t,i).then(r=>{Object.assign(e[n],r)}).catch(()=>{}))}return await Promise.all(s),e}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){const s=[],n=[["books","book"],["collections","collection"],["works","work"]];for(const[o,i]of n){const r=t[o];if(r)for(const c of Object.values(r)){const l=c;s.push({id:c.id,title:c.title||c.name||c.id,type:i,isDraft:e,author:c.author,dynasty:c.dynasty,role:c.role,path:c.path,additional_titles:l.additional_titles,edition:l.edition,juan_count:l.juan_count,has_text:l.has_text,has_image:l.has_image,has_collated:l.has_collated}),this.pathMap.set(c.id,{path:c.path,isDraft:e})}}return s}async ensureSearchSBuilt(){var n;if(this.searchSCache)return{searchS:this.searchSCache,converter:this.t2sConverter||null};if(this.t2sConverter===!1)return{searchS:{},converter:null};try{const o=await import("opencc-js");this.t2sConverter=o.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 o of t){const i={},r=e(o.title);if(r!==o.title&&(i.t=r),o.author){const c=e(o.author);c!==o.author&&(i.a=c)}if((n=o.additional_titles)!=null&&n.length){const c=o.additional_titles.map(e);c.some((l,d)=>l!==o.additional_titles[d])&&(i.at=c)}Object.keys(i).length>0&&(s[o.id]=i)}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,u)=>{const f=String(h[o]??""),g=String(u[o]??""),_=f.localeCompare(g,"zh");return i==="asc"?_:-_});const r=e.page||1,c=e.pageSize||50,l=(r-1)*c;return{entries:n.slice(l,l+c),total:n.length,page:r,pageSize:c}}async search(t,e,s){const n=await this.ensureLoaded(),{searchS:o,converter:i}=await this.ensureSearchSBuilt(),r=n.filter(g=>g.type===e),c=i?i(t):void 0,d=Object.keys(o).length>0?O(r,t,c,o):P(r,t),h=s.page||1,u=s.pageSize||50,f=(h-1)*u;return{entries:d.slice(f,f+u),total:d.length,page:h,pageSize:u}}async searchAll(t,e=5){const s=await this.ensureLoaded(),{searchS:n,converter:o}=await this.ensureSearchSBuilt(),i=["work","book","collection"],r=o?o(t):void 0,c=Object.keys(n).length>0,l=i.map(d=>{const h=s.filter(u=>u.type===d);return c?O(h,t,r,n):P(h,t)});return{works:l[0].slice(0,e),books:l[1].slice(0,e),collections:l[2].slice(0,e),totalWorks:l[0].length,totalBooks:l[1].length,totalCollections:l[2].length}}async getItem(t){const e=await this.ensureLoaded(),s=this.pathMap.get(t);if(!s)return null;const n=s.isDraft?this.config.repos.draft:this.config.repos.official;let o=null;const i=`${this.config.baseUrl}/${this.config.org}/${n}/main/${encodeURI(s.path)}`;try{o=await this.fetchJson(i)}catch{}if(!o)for(const r of this.config.cdnUrls){const c=`${r}/${this.config.org}/${n}@main/${encodeURI(s.path)}`;try{o=await this.fetchJson(c);break}catch{continue}}if(o){const r=e.find(c=>c.id===t);r!=null&&r.has_collated&&(o.has_collated=!0)}return o}async getEntry(t){return(await this.ensureLoaded()).find(s=>s.id===t)||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 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();const e=this.pathMap.get(t);if(!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 r=`${e.dir}/${t}/${i.id}/volume_book_mapping.json`,c=await this.fetchFile(e.repo,r);c&&o.push({resource_id:i.id,short_name:i.short_name,data:J(c)})}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 K=255;class z{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&K,this.sequence===0&&(s=this._tilNextUnit(this.lastTimestamp,t))):this.sequence=0,this.lastTimestamp=s,this.lastStatus=t;const n=U(t,e,BigInt(s),this.machineId,this.sequence);return R(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&K,this.sequence===0&&(s=this._tilNextUnit(this.lastTimestamp,t))):this.sequence=0,this.lastTimestamp=s,this.lastStatus=t,U(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 Ct{constructor(t){this.recentEntities=[],this.storage=new W(t.fs,t.workspaceRoot),this.idGen=new z(t.machineId??0)}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){return this.storage.getItem(t)}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 r=await this.resolveEntity(i);r&&(s.belongsToCollection={...r,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(c=>(typeof c=="string"?c:c.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 r of i)n.push({id:r.id,title:r.title,type:r.type,author:r.author,dynasty:r.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}}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=x(t);return C(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 c=e.sortBy,l=e.sortOrder==="desc"?-1:1;t.sort((d,h)=>{const u=d[c]??"",f=h[c]??"";return u<f?-l:u>f?l:0})}const o=t.length,i=(s-1)*n;return{entries:t.slice(i,i+n),total:o,page:s,pageSize:n}}}const At="/data",Tt=1e4;class jt{constructor(t={}){this.indexCache=null,this.pathMap=new Map,this.chunkCache=new Map,this.tiyaoCache=new Map,this.searchSCache=null,this.searchSLoaded=!1,this.t2sConverter=null,this.basePath=t.basePath??At,this.timeout=t.timeout??Tt}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(){if(this.indexCache)return this.indexCache;const t=await this.fetchJson(`${this.basePath}/index.json`),e=[],s=[["books","book"],["collections","collection"],["works","work"]];for(const[n,o]of s){const i=t[n];if(i)for(const r of Object.values(i))e.push({id:r.id,title:r.title||r.name||r.id,type:o,isDraft:!0,author:r.author,dynasty:r.dynasty,role:r.role,path:r.path,additional_titles:r.additional_titles,edition:r.edition,juan_count:r.juan_count,has_text:r.has_text,has_image:r.has_image,has_collated:r.has_collated}),this.pathMap.set(r.id,{path:r.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 loadChunk(t){if(this.chunkCache.has(t))return this.chunkCache.get(t);const e=await this.fetchJson(`${this.basePath}/chunks/${t}.json`);return this.chunkCache.set(t,e),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 loadEntries(t,e){let n=(await this.ensureLoaded()).filter(d=>d.type===t);const o=e.sortBy||"title",i=e.sortOrder||"asc";n.sort((d,h)=>{const u=String(d[o]??""),f=String(h[o]??""),g=u.localeCompare(f,"zh");return i==="asc"?g:-g});const r=e.page||1,c=e.pageSize||50,l=(r-1)*c;return{entries:n.slice(l,l+c),total:n.length,page:r,pageSize:c}}async search(t,e,s){const n=await this.ensureLoaded(),o=await this.ensureSearchSLoaded(),i=await this.ensureT2S(),r=n.filter(g=>g.type===e),c=i?i(t):void 0,d=Object.keys(o).length>0?O(r,t,c,o):P(r,t),h=s.page||1,u=s.pageSize||50,f=(h-1)*u;return{entries:d.slice(f,f+u),total:d.length,page:h,pageSize:u}}async searchAll(t,e=5){const s=await this.ensureLoaded(),n=await this.ensureSearchSLoaded(),o=await this.ensureT2S(),i=["work","book","collection"],r=o?o(t):void 0,c=Object.keys(n).length>0,l=i.map(d=>{const h=s.filter(u=>u.type===d);return c?O(h,t,r,n):P(h,t)});return{works:l[0].slice(0,e),books:l[1].slice(0,e),collections:l[2].slice(0,e),totalWorks:l[0].length,totalBooks:l[1].length,totalCollections:l[2].length}}async getItem(t){const e=t.slice(0,2);try{const n=(await this.loadChunk(e))[t]||null;if(n){const o=(await this.ensureLoaded()).find(i=>i.id===t);o!=null&&o.has_collated&&(n.has_collated=!0)}return n}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){const i=`${t}/${o.id}/volume_book_mapping`,r=t.slice(0,2);try{const l=(await this.loadChunk(r))[i];l&&n.push({resource_id:o.id,short_name:o.short_name,data:J(l)})}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){const e=t.slice(0,2);try{const s=await this.loadChunk(e),n=`${t}/collated_edition_index`;return s[n]||null}catch{return null}}async getCollatedJuan(t,e){if(e.includes("..")||!e.endsWith(".json"))return null;const s=e.match(/juan(\d+)/);if(!s)return null;const n=parseInt(s[1]),o=10,i=Math.ceil(n/o),r=(i-1)*o+1,c=i*o;try{return(await this.loadTiyaoGroup(r,c))[e]||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.tiyaoCache.clear(),this.searchSCache=null,this.searchSLoaded=!1,this.t2sConverter=null}}class T extends Error{constructor(t){super(t),this.name="BookIndexError"}}class $t extends T{constructor(t){super(t),this.name="StorageError"}}class Pt extends T{constructor(t){super(t),this.name="IdGenerationError"}}class Bt extends T{constructor(t){super(t),this.name="ConfigError"}}class Ft extends T{constructor(t){super(t),this.name="MigrationError"}}class Ot{constructor(t,e,s=1){this.storage=new W(t,e),this.idGen=new z(s)}generateId(t="book",e="draft"){return this.idGen.nextIdRaw(e,t)}encodeId(t){return R(t)}decodeId(t){return x(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"},r=e in i?i[e]:e;if(r===null)return!1;if(r==="description"&&typeof s=="string"){const l=o[r]||{};o[r]={text:s,sources:l.sources||[]}}else o[r]=s;const c=A(t);return await this.storage.saveItem(c.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 Rt={wikisource:"wikisource",shidianguji:"shidianguji",archive:"archive",ctext:"ctext",nlc:"nlc","read.nlc":"nlc","db.sido":"sido","guji.artx":"guji-artx","digital.library":"digital-library"},Y=new Set(["text","image","text+image","physical"]),Mt=new Set(["catalog","search"]),Dt=new Set(["com","org","net","cn","edu","gov","io","jp","tw","hk"]);function Ut(a){if(!a)return"";try{const e=new URL(a).hostname;for(const[n,o]of Object.entries(Rt))if(e.includes(n))return o;const s=e.split(".");if(s.length>=2){const n=s.filter(o=>!Dt.has(o)&&o.length>2);return n.length>0?n[n.length-1]:s[s.length-2]}return e}catch{return""}}function Lt(a){const t=[];return a.name||t.push("name is required"),Y.has(a.type)||t.push(`invalid type '${a.type}', must be one of ${[...Y].join(", ")}`),a.root_type&&!Mt.has(a.root_type)&&t.push(`invalid root_type '${a.root_type}'`),a.type!=="physical"&&!a.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=x(t)}catch{this.idInt=0n}}else this.idInt=t,this.idStr=R(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 N=w;exports.BidLink=N;exports.BookIndexError=T;exports.BookIndexManager=Ot;exports.BookIndexStorage=W;exports.BundleStorage=jt;exports.ConfigError=Bt;exports.GithubStorage=Et;exports.IdGenerationError=Pt;exports.IdGenerator=z;exports.LocalStorage=Ct;exports.MigrationError=Ft;exports.StorageError=$t;exports.base58Decode=x;exports.base58Encode=R;exports.buildId=U;exports.decodeIdString=A;exports.extractIdFromUrl=Ut;exports.extractStatus=mt;exports.extractType=pt;exports.normalizeCatalog=J;exports.parseId=C;exports.validateResource=Lt;
|
|
@@ -751,6 +751,9 @@ class St {
|
|
|
751
751
|
async getResourceProgress() {
|
|
752
752
|
return this.fetchFile(this.config.repos.draft, "resource.json");
|
|
753
753
|
}
|
|
754
|
+
async getSiteProgress() {
|
|
755
|
+
return this.fetchFile(this.config.repos.draft, "resource-site.json");
|
|
756
|
+
}
|
|
754
757
|
async getRecommended() {
|
|
755
758
|
return this.fetchFile(this.config.repos.draft, "recommended.json");
|
|
756
759
|
}
|
|
@@ -1262,6 +1265,13 @@ class xt {
|
|
|
1262
1265
|
return null;
|
|
1263
1266
|
}
|
|
1264
1267
|
}
|
|
1268
|
+
async getSiteProgress() {
|
|
1269
|
+
try {
|
|
1270
|
+
return await this.fetchJson(`${this.basePath}/resource-site.json`);
|
|
1271
|
+
} catch {
|
|
1272
|
+
return null;
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1265
1275
|
async getRecommended() {
|
|
1266
1276
|
try {
|
|
1267
1277
|
return await this.fetchJson(`${this.basePath}/recommended.json`);
|
package/dist/storage.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./storage-entry-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./storage-entry-CAvzCo5k.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.d.ts
CHANGED
|
@@ -220,6 +220,7 @@ export declare class BundleStorage implements IndexStorage {
|
|
|
220
220
|
getCollatedEditionIndex(workId: string): Promise<CollatedEditionIndex | null>;
|
|
221
221
|
getCollatedJuan(workId: string, juanFile: string): Promise<CollatedJuan | null>;
|
|
222
222
|
getResourceProgress(): Promise<ResourceProgress | null>;
|
|
223
|
+
getSiteProgress(): Promise<ResourceProgress | null>;
|
|
223
224
|
getRecommended(): Promise<RecommendedData | null>;
|
|
224
225
|
clearCache(): void;
|
|
225
226
|
}
|
|
@@ -397,6 +398,7 @@ export declare class GithubStorage implements IndexStorage {
|
|
|
397
398
|
getCollatedEditionIndex(workId: string): Promise<CollatedEditionIndex | null>;
|
|
398
399
|
getCollatedJuan(workId: string, juanFile: string): Promise<CollatedJuan | null>;
|
|
399
400
|
getResourceProgress(): Promise<ResourceProgress | null>;
|
|
401
|
+
getSiteProgress(): Promise<ResourceProgress | null>;
|
|
400
402
|
getRecommended(): Promise<RecommendedData | null>;
|
|
401
403
|
/** 清除缓存(用于切换数据源后刷新) */
|
|
402
404
|
clearCache(): void;
|
package/dist/storage.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as o, a as e, b as s, c as t, d as n, C as d, G as g, I as i, f as I, L as B, M as S, S as k, k as x, v as E } from "./storage-entry-
|
|
1
|
+
import { B as o, a as e, b as s, c as t, d as n, C as d, G as g, I as i, f as I, L as B, M as S, S as k, k as x, v as E } from "./storage-entry-CT6PuEDo.js";
|
|
2
2
|
export {
|
|
3
3
|
o as BidLink,
|
|
4
4
|
e as BookIndexError,
|