book-index-ui 0.2.24 → 0.2.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,31 +1,3 @@
1
- "use strict";var Nl=Object.create;var Sr=Object.defineProperty;var Hl=Object.getOwnPropertyDescriptor;var Ul=Object.getOwnPropertyNames;var Vl=Object.getPrototypeOf,ql=Object.prototype.hasOwnProperty;var Yl=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ul(t))!ql.call(e,o)&&o!==n&&Sr(e,o,{get:()=>t[o],enumerable:!(r=Hl(t,o))||r.enumerable});return e};var St=(e,t,n)=>(n=e!=null?Nl(Vl(e)):{},Yl(t||!e||!e.__esModule?Sr(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ne=require("./storage-entry-C7sHSk4U.cjs"),i=require("react/jsx-runtime"),v=require("react"),Gl=require("react-dom"),Kl=e=>`/book-index?id=${e}`,Zi=v.createContext(Kl);function Xl({buildUrl:e,children:t}){const n=v.useMemo(()=>e,[e]);return i.jsx(Zi.Provider,{value:n,children:t})}function Fe(){return v.useContext(Zi)}function et(e){return e.types&&e.types.length>0?e.types:e.type?e.type==="text+image"?["text","image"]:[e.type]:[]}function Jl(e,t){return et(e).includes(t)}const Qi={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Zl={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},Ql={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},$t=v.createContext(null),eo={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入",belongsToWork:"所屬作品",locationHistory:"流轉歷史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄於",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"目錄",collectionTab:"叢編",siteTab:"在線資源",recommendTab:"推薦",feedbackTab:"反饋",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},detailTab:{basicInfo:"基本信息",catalog:"目錄",collectionCatalog:"叢編目錄",collatedEdition:"整理本",catalogSuffix:"·目錄"},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",total_pages:"總頁數",page_range:"頁碼範圍",page_count:"頁數",file_page_range:"文件頁碼",file_page_count:"文件頁數",content_page_range:"影印頁碼",volume:"冊",color_mode:"色彩",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},es={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录于",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"目录",collectionTab:"丛编",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"基本信息",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"整理本",catalogSuffix:"·目录"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},ts={"zh-Hant":eo,"zh-Hans":es},to="bim-locale";function ns(){try{const e=localStorage.getItem(to);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function rs(e){try{localStorage.setItem(to,e)}catch{}}const is="zh-Hans",os=({locale:e,onLocaleChange:t,children:n})=>{const[r,o]=v.useState(e??is),l=e??r;v.useEffect(()=>{if(e)return;const p=ns();p&&p!==r&&o(p)},[]);const[s,a]=v.useState(null);v.useEffect(()=>{l==="zh-Hans"?import("opencc-js/t2cn").then(p=>{const d=p.Converter({from:"tw",to:"cn"});a(()=>d)}).catch(()=>{a(()=>p=>p)}):a(null)},[l]);const c=v.useCallback(p=>{o(p),rs(p),t==null||t(p)},[t]),u=v.useMemo(()=>({locale:l,setLocale:c,messages:ts[l],converter:s}),[l,c,s]);return i.jsx($t.Provider,{value:u,children:n})};function G(){const e=v.useContext($t);return(e==null?void 0:e.messages)??eo}const ls=2e3;function X(){const e=v.useContext($t),t=(e==null?void 0:e.locale)??"zh-Hant",n=(e==null?void 0:e.converter)??null,r=v.useRef(new Map),o=v.useRef(t);o.current!==t&&(r.current.clear(),o.current=t);const l=v.useCallback(s=>{if(!s)return"";if(!n)return s;const a=r.current.get(s);if(a!==void 0)return a;const c=n(s);if(r.current.size>=ls){const u=r.current.keys().next().value;u!==void 0&&r.current.delete(u)}return r.current.set(s,c),c},[n]);return v.useMemo(()=>({convert:l,locale:t,isSimplified:t==="zh-Hans"}),[l,t])}function Nt(e,t){return e.replace(/\{(\w+)\}/g,(n,r)=>String(t[r]??""))}function ss(e){if(!e)return"";try{const t=new URL(e).hostname,n={"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(n[t])return n[t];const r=t.split(".");return r.length>=2?r[r.length-2]:t}catch{return""}}function as(){return{id:"",name:"",url:"",type:"text",details:""}}const Dn=({items:e,onChange:t,onDownload:n,downloadStatuses:r,filterType:o})=>{const l=G(),[s,a]=v.useState(null),c=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],u=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],p=k=>{if(!o)return!0;const w=et(k);return o==="text"?w.includes("text"):o==="image"?w.includes("image")||w.includes("physical"):o==="physical"?w.includes("physical"):w.includes(o)},d=e.map((k,w)=>({item:k,originalIndex:w})).filter(({item:k})=>p(k)),h=()=>{const k=as();o&&(k.type=o),t([...e,k]),a(e.length)},f=k=>{t(e.filter((w,_)=>_!==k)),a(null)},g=(k,w,_)=>{const I=[...e];if(I[k]={...I[k],[w]:_},w==="url"&&!I[k].id){const S=ss(_);S&&(I[k].id=S)}t(I)},b=(k,w,_)=>{const S={...e[k].metadata||{}};_?S[w]=_:delete S[w],g(k,"metadata",Object.keys(S).length>0?S:void 0)},x=(k,w)=>{const _=w.trim()?w.split(/[,,、]/).map(I=>I.trim()).filter(Boolean):void 0;g(k,"structure",_)},m=(k,w,_)=>{const S=e[k].coverage||{level:1,ranges:""};w==="level"?S.level=parseInt(_)||1:S.ranges=_,g(k,"coverage",S.ranges?S:void 0)};return i.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[d.map(({item:k,originalIndex:w})=>{var _,I,S;return i.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>a(s===w?null:w),children:[i.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===w?"▼":"▶"}),i.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:cs(k.type??"text"),color:"#fff"},children:(()=>{var z,B;const T=et(k);return T.length===0?k.type??"text":T.length===1?((z=c.find(C=>C.value===T[0]))==null?void 0:z.label)??T[0]:T.includes("text")&&T.includes("image")?((B=c.find(C=>C.value==="text+image"))==null?void 0:B.label)??"text+image":T.join("+")})()}),i.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:k.name||`${l.editor.resourcePlaceholder} ${w+1}`}),k.id&&i.jsx("span",{style:{fontSize:"11px",opacity:.5},children:k.id}),k.url&&i.jsx("a",{href:k.url,target:"_blank",rel:"noopener noreferrer",onClick:T=>T.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),n&&k.url&&us(w,r==null?void 0:r[w],n,l),i.jsx("button",{onClick:T=>{T.stopPropagation(),f(w)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),s===w&&i.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[Jl(k,"image")&&k.url&&ds(k,l),i.jsxs("div",{style:{display:"grid",gap:"8px"},children:[i.jsxs("div",{style:{display:"flex",gap:"8px"},children:[i.jsxs("label",{style:wt,children:[i.jsx("span",{style:jt,children:l.label.type}),i.jsx("select",{value:k.type,onChange:T=>g(w,"type",T.target.value),style:{...We,flex:1},children:c.map(T=>i.jsx("option",{value:T.value,children:T.label},T.value))})]}),i.jsxs("label",{style:wt,children:[i.jsx("span",{style:jt,children:l.label.rootType}),i.jsx("select",{value:k.root_type||"catalog",onChange:T=>g(w,"root_type",T.target.value),style:{...We,flex:1},children:u.map(T=>i.jsx("option",{value:T.value,children:T.label},T.value))})]})]}),i.jsxs("div",{style:{display:"flex",gap:"8px"},children:[i.jsx("input",{type:"text",value:k.id,onChange:T=>g(w,"id",T.target.value),placeholder:l.editor.idAutoExtract,style:{...We,width:"140px",flexShrink:0}}),i.jsx("input",{type:"text",value:k.name,onChange:T=>g(w,"name",T.target.value),placeholder:l.editor.resourceName,style:{...We,flex:1}})]}),i.jsx("input",{type:"text",value:k.url,onChange:T=>g(w,"url",T.target.value),placeholder:l.editor.resourceUrl,style:We}),i.jsx("input",{type:"text",value:((_=k.structure)==null?void 0:_.join("、"))||"",onChange:T=>x(w,T.target.value),placeholder:l.editor.structurePlaceholder,style:We}),i.jsxs("div",{style:{display:"flex",gap:"8px"},children:[i.jsxs("label",{style:wt,children:[i.jsx("span",{style:jt,children:l.label.coverageLevel}),i.jsx("input",{type:"number",min:1,value:((I=k.coverage)==null?void 0:I.level)??"",onChange:T=>m(w,"level",T.target.value),placeholder:"1",style:{...We,width:"60px"}})]}),i.jsxs("label",{style:{...wt,flex:1},children:[i.jsx("span",{style:jt,children:l.label.coverageRange}),i.jsx("input",{type:"text",value:((S=k.coverage)==null?void 0:S.ranges)||"",onChange:T=>m(w,"ranges",T.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...We,flex:1}})]})]}),i.jsx("textarea",{value:k.details||"",onChange:T=>g(w,"details",T.target.value),placeholder:l.editor.detailsPlaceholder,style:{...We,minHeight:"60px",resize:"vertical"}}),i.jsxs("div",{style:{borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",paddingTop:"8px",marginTop:"4px"},children:[i.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:l.label.metadata}),i.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(l.metadata).map(([T,z])=>{var B;return i.jsxs("label",{style:{...wt,gap:"4px"},children:[i.jsx("span",{style:{...jt,minWidth:"56px"},children:z}),i.jsx("input",{type:"text",value:((B=k.metadata)==null?void 0:B[T])||"",onChange:C=>b(w,T,C.target.value),placeholder:z,style:{...We,flex:1}})]},T)})})]})]})]})]},w)}),i.jsxs("button",{onClick:h,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[i.jsx("span",{children:"+"}),i.jsx("span",{children:l.action.addResource})]})]})};function cs(e){switch(e){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function us(e,t,n,r){const o=(t==null?void 0:t.status)==="downloading",l=(t==null?void 0:t.status)==="completed";return i.jsx("button",{onClick:s=>{s.stopPropagation(),o||n(e,"")},disabled:o,style:{background:"transparent",border:"none",color:l?"var(--bim-success, #4caf50)":o?"var(--bim-desc-fg, #717171)":"var(--bim-link-fg, #0066cc)",cursor:o?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:o?.6:.9},title:l?r.download.completed:o?`${r.download.downloading} ${(t==null?void 0:t.progress)||0}%`:r.download.downloadThis,children:l?"✓":o?"⏳":"⬇"})}function ds(e,t){const n=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(e.url)||e.url.includes("iiif")||e.url.includes("image");return i.jsx("div",{style:{marginBottom:"12px"},children:n?i.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"#00000010"},children:i.jsx("img",{src:e.url,alt:e.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):i.jsx("div",{style:{padding:"12px",background:"#00000010",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:t.editor.imageResourceLink})})}const We={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},wt={display:"flex",alignItems:"center",gap:"6px"},jt={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},ps={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function fs(e){try{const t=new URL(e).hostname;return ps[t]}catch{return}}const wr={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"};function hs(e){return e.includes("text")&&e.includes("image")?wr["text+image"]:wr[e[0]||"physical"]}const jr={text:0,image:1,physical:2};function Qt(e){return e.length===0?"physical":[...e].sort((t,n)=>(jr[t]??99)-(jr[n]??99)).join("+")}function gs(e){const t=l=>{const s=l.match(/^(.+?)·第(\d+)[冊册]$/);if(s)return[s[1],parseInt(s[2])];const a=l.match(/^(.+?)[·(](\d+)[)]?$/);return a?[a[1],parseInt(a[2])]:null},n=new Map,r=[],o=new Set;for(let l=0;l<e.length;l++){const s=e[l];if(s.volumes&&s.volumes.length>0)continue;const a=t(s.name);if(!a)continue;const[c,u]=a,p=`${c}|${Qt(et(s))}`;n.has(p)||n.set(p,{base:{...s,name:c,url:"",volumes:[]},volumes:[]}),n.get(p).volumes.push({volume:u,url:s.url||void 0,status:"found"}),o.add(l)}for(const[,l]of n)if(l.volumes.length>=2)l.volumes.sort((s,a)=>s.volume-a.volume),l.base.volumes=l.volumes,l.base.expected_volumes=l.volumes.length,r.push(l.base);else for(let s=0;s<e.length;s++)if(o.has(s)){const a=t(e[s].name),c=a&&`${a[0]}|${Qt(et(e[s]))}`,u=`${l.base.name}|${Qt(et(l.base))}`;c===u&&o.delete(s)}for(let l=0;l<e.length;l++)o.has(l)||r.push(e[l]);return r}const Qn=({items:e,groupByType:t=!0,onNavigate:n,renderLink:r})=>{const o=G(),l=v.useMemo(()=>gs(e||[]),[e]),s={text:o.resourceType.text,image:o.resourceType.image,"text+image":o.resourceType.textImage,physical:o.resourceType.physical},a=d=>s[d]?s[d]:d.split("+").map(h=>s[h]||h).join("+");if(!l||l.length===0)return i.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:o.misc.noResources});if(!t)return i.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:l.map((d,h)=>i.jsx(Cr,{item:d},d.id||h))});const c=new Map;for(const d of l){const h=Qt(et(d));c.has(h)||c.set(h,[]),c.get(h).push(d)}const u=["text","image","text+image","physical"],p=[...u.filter(d=>c.has(d)),...[...c.keys()].filter(d=>!u.includes(d)).sort()];return i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:p.map(d=>{const h=c.get(d),f=hs(d.split("+"));return i.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[i.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:f,whiteSpace:"nowrap",flexShrink:0},children:a(d)}),i.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:h.map((g,b)=>i.jsx(Cr,{item:g,onNavigate:n,renderLink:r},g.id||b))})]},d)})})};function xs(e,t){try{if(new URL(e).hostname.includes("wikimedia.org")){const o=e.match(/\/wiki\/File:(.+?)(?:#|$)/);if(o)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(o[1]))}&page=${t}`;const l=new URL(e);return l.searchParams.set("page",String(t)),l.toString()}return e}catch{return e}}function ms(e){if(!e)return;const t=e.file_page_range||e.page_range;if(!t||typeof t!="string")return;const n=t.match(/^(\d+)/);return n?parseInt(n[1],10):void 0}function bs(e){if(e.url)return e.url;for(const[t,n]of Object.entries(e))if(t.endsWith("_url")&&typeof n=="string")return n}const ys={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},Cr=({item:e})=>{const t=G(),{convert:n}=X(),[r,o]=v.useState(!1),l=v.useMemo(()=>(e.url?fs(e.url):void 0)||n(e.name),[e.url,e.name,n]),s=v.useMemo(()=>!e.volumes||e.volumes.length===0?null:e.volumes.map(g=>({...g,url:g.url||bs(g)})),[e.volumes]),a=s&&s.length>0,c=a?new Set(s.filter(g=>g.status!=="missing").map(g=>g.volume)).size:0,u=a?new Set(s.filter(g=>g.status==="missing").map(g=>g.volume)).size:0,p=e.expected_volumes??(a?c+u:0),d=e.color_mode?{...ys[e.color_mode],label:t.colorMode[e.color_mode]}:null,h=e.details&&!a?n(e.details):null,f={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",background:"var(--bim-input-bg, #fff)",fontSize:"12px",color:"var(--bim-fg, #333)",lineHeight:1.4,verticalAlign:"middle"};return i.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[i.jsxs("div",{style:f,children:[i.jsx("span",{style:{fontWeight:500},children:l}),d&&i.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:d.bg,color:d.fg},children:d.label}),h&&i.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:h}),a&&i.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[c,"/",p,t.unit.volume,u>0&&i.jsxs("span",{style:{color:"#e67e22",marginLeft:"3px"},children:["缺",u]})]}),e.url&&i.jsx("a",{href:(()=>{const g=ms(e.metadata);return g?xs(e.url,g):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",whiteSpace:"nowrap"},children:t.action.visit}),a&&i.jsx("button",{onClick:()=>o(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),a&&r&&i.jsx("div",{style:{padding:"6px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:s.map(g=>{const b=g.status==="missing";return g.url&&!b?i.jsx("a",{href:g.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:g.volume},g.volume):i.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:b?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:b?"line-through":"none",opacity:b?.6:1},children:g.volume},g.volume)})})]})},no=({indexSource:e,syncConfig:t,variant:n="index-browser",onSwitchMode:r,onToggleDraft:o,onConfigurePath:l,onSelectFolder:s})=>{const a=G(),c=e==="local",u=(t==null?void 0:t.isDraft)??!0,p=(t==null?void 0:t.repoPath)||"",d=p?p.split(/[/\\]/).pop()||p:"",h={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:"var(--bim-primary-soft, #0078d415)",color:"var(--bim-primary, #0078d4)"},f={onMouseOver:b=>b.currentTarget.style.opacity="0.8",onMouseOut:b=>b.currentTarget.style.opacity="1"},g=i.jsxs("div",{onClick:o,title:u?a.mode.switchToOfficial:a.mode.switchToDraft,style:{...h,background:u?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...f,children:[i.jsx("span",{children:u?"📝":"📚"}),i.jsx("span",{children:u?"draft":"official"})]});return n==="index-browser"?c?i.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[g,i.jsxs("div",{onClick:r,title:a.mode.switchToSync,style:h,...f,children:[i.jsx("span",{children:"📁"}),i.jsx("span",{children:a.mode.localMode}),i.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),i.jsxs("div",{onClick:s,title:p||a.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px"},...f,children:[i.jsx("span",{children:"📂"}),d&&i.jsx("span",{style:{fontSize:"11px",opacity:.9},children:d})]})]}):i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[g,i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[i.jsxs("div",{onClick:r,title:a.mode.switchToLocal,style:h,...f,children:[i.jsx("span",{children:"🌐"}),i.jsx("span",{children:a.mode.syncMode}),i.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),i.jsx("div",{onClick:l,title:d||a.mode.configurePath,style:{...h,background:"transparent",padding:"6px",fontSize:"12px"},...f,children:i.jsx("span",{children:"⚙️"})})]})]}):i.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[i.jsxs("div",{onClick:r,title:c?a.mode.switchToGithub:a.mode.switchToLocal,style:h,...f,children:[i.jsx("span",{children:c?"📁":"🌐"}),i.jsx("span",{children:c?a.mode.localMode:a.mode.githubSync}),i.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&i.jsxs("div",{onClick:s,title:p||a.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px",minWidth:p?"100px":"auto",justifyContent:"space-between"},...f,children:[i.jsx("span",{children:"📂"}),d&&i.jsx("span",{style:{fontSize:"11px",opacity:.9},children:d})]}),!c&&d&&i.jsxs("div",{style:{...h,background:"#2196f3",color:"white",cursor:"default"},title:p,children:[i.jsx("span",{children:"📂"}),i.jsx("span",{style:{fontSize:"11px"},children:d})]})]})},cn="bim-search-history",Ir=10,Er=8;function Lt(){try{const e=localStorage.getItem(cn);return e?JSON.parse(e):[]}catch{return[]}}function ks(e){try{const t=Lt().filter(n=>n!==e);t.unshift(e),t.length>Ir&&(t.length=Ir),localStorage.setItem(cn,JSON.stringify(t))}catch{}}function vs(e){try{const t=Lt().filter(n=>n!==e);localStorage.setItem(cn,JSON.stringify(t))}catch{}}function Ss(){try{localStorage.removeItem(cn)}catch{}}const ro=({transport:e,value:t,onChange:n,onSearch:r,onEntrySelect:o,placeholder:l})=>{const s=G(),a=l??s.search.placeholder,c={work:s.indexType.work,book:s.indexType.book,collection:s.indexType.collection,entity:s.indexType.entity},[u,p]=v.useState(!1),[d,h]=v.useState([]),[f,g]=v.useState(-1),[b,x]=v.useState(Lt),m=v.useRef(null),k=v.useRef(null),w=v.useRef(null),_=v.useRef(!1);v.useEffect(()=>{g(-1);const E=t.trim();if(!E){h(b.map(P=>({type:"history",text:P})));return}if(!e.searchAll){h([]);return}let A=!1;const $=setTimeout(()=>{e.searchAll(E,Er).then(P=>{if(A)return;const L=[...P.works,...P.books,...P.collections,...P.entities??[]];h(L.slice(0,Er).map(N=>({type:"entry",text:N.title||N.id,entry:N})))}).catch(()=>{A||h([])})},80);return()=>{A=!0,clearTimeout($)}},[t,b,e]),v.useEffect(()=>{const E=A=>{w.current&&!w.current.contains(A.target)&&p(!1)};return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[]),v.useEffect(()=>{const E=A=>{var $,P;if(A.key==="/"&&document.activeElement!==m.current){const L=($=document.activeElement)==null?void 0:$.tagName;if(L==="INPUT"||L==="TEXTAREA"||L==="SELECT")return;A.preventDefault(),(P=m.current)==null||P.focus()}};return document.addEventListener("keydown",E),()=>document.removeEventListener("keydown",E)},[]);const I=v.useCallback(E=>{E.trim()&&(ks(E.trim()),x(Lt())),r(E),p(!1)},[r]),S=v.useCallback(E=>{E.type==="history"?(n(E.text),I(E.text)):E.entry&&(o?(o(E.entry),p(!1)):(n(E.text),I(E.text)))},[n,I,o]),T=v.useCallback(E=>{if(!u||d.length===0){E.key==="Enter"&&I(t);return}switch(E.key){case"ArrowDown":E.preventDefault(),g(A=>(A+1)%d.length);break;case"ArrowUp":E.preventDefault(),g(A=>(A-1+d.length)%d.length);break;case"Enter":E.preventDefault(),f>=0&&f<d.length?S(d[f]):I(t);break;case"Escape":E.preventDefault(),p(!1);break}},[u,d,f,t,I,S]),z=v.useCallback((E,A)=>{A.stopPropagation(),vs(E),x(Lt()),h($=>$.filter(P=>!(P.type==="history"&&P.text===E)))},[]),B=v.useCallback(E=>{E.stopPropagation(),Ss(),x([]),h([])},[]);v.useEffect(()=>{if(f>=0&&k.current){const E=k.current.children;E[f]&&E[f].scrollIntoView({block:"nearest"})}},[f]);const C=!t.trim()&&b.length>0;return i.jsxs("div",{ref:w,style:{position:"relative",flex:1},children:[i.jsx("input",{ref:m,type:"text",placeholder:a,value:t,onChange:E=>{n(E.target.value),p(!0)},onCompositionStart:()=>{_.current=!0},onCompositionEnd:()=>{_.current=!1},onFocus:()=>{p(!0)},onKeyDown:T,style:{width:"100%",padding:"8px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"14px",boxSizing:"border-box"}}),u&&d.length>0&&i.jsxs("div",{ref:k,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[C&&i.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:[i.jsx("span",{children:s.search.history}),i.jsx("button",{onClick:B,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:s.search.clearAll})]}),d.map((E,A)=>i.jsxs("div",{onClick:()=>S(E),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:A===f?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[i.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:E.type==="history"?"🕐":"🔍"}),i.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:E.text}),E.entry&&i.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[c[E.entry.type],E.entry.edition&&` · ${E.entry.edition}`,E.entry.author&&` · ${E.entry.author}`]}),E.type==="history"&&i.jsx("button",{onClick:$=>z(E.text,$),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:s.action.remove,children:"×"})]},`${E.type}-${E.text}-${A}`))]})]})},Mt="bim-recent-ids",Tr="bim-recent-entries",_r=50,gn=5,ws=50,js=200;function At(){try{const e=localStorage.getItem(Mt);if(e)return JSON.parse(e);const t=localStorage.getItem(Tr);if(t){const n=JSON.parse(t).map(r=>r.id);return localStorage.setItem(Mt,JSON.stringify(n)),localStorage.removeItem(Tr),n}return[]}catch{return[]}}function Cs(e){try{const t=At().filter(n=>n!==e);t.unshift(e),t.length>_r&&(t.length=_r),localStorage.setItem(Mt,JSON.stringify(t))}catch{}}function Is(e){try{const t=At().filter(n=>n!==e);localStorage.setItem(Mt,JSON.stringify(t))}catch{}}function Es(){try{localStorage.removeItem(Mt)}catch{}}const Ts={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Mn=({transport:e,indexSource:t="local",syncConfig:n,onEntryClick:r,onNewEntry:o,onSwitchMode:l,onToggleDraft:s,onConfigurePath:a,onSelectFolder:c,hideModeIndicator:u,initialQuery:p,onQueryChange:d,headerRight:h})=>{const f=G(),g=[{type:"work",icon:"✍️",name:f.indexType.work,key:"works"},{type:"book",icon:"📖",name:f.indexType.book,key:"books"},{type:"collection",icon:"📚",name:f.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:f.indexType.entity,key:"entities"}],[b,x]=v.useState(p??""),[m,k]=v.useState(null),[w,_]=v.useState(null),[I,S]=v.useState(!1),[T,z]=v.useState(null),[B,C]=v.useState(""),[E,A]=v.useState(!p),[$,P]=v.useState(At),[L,N]=v.useState([]),[M,D]=v.useState(!1),[U,y]=v.useState(!1),[q,Z]=v.useState(null),[j,ce]=v.useState(null),be=v.useRef(void 0),se=v.useRef(!1),pe=v.useCallback(async(V,de)=>{if(!V.trim()){A(!0),k(null),_(null);return}A(!1),S(!0),C("");try{if(e.searchAll){const ie=await e.searchAll(V,de??gn);k(ie)}else{const ie=["work","book","collection","entity"],ue=await Promise.all(ie.map(he=>e.search(V,he,{page:1,pageSize:de??gn})));k({works:ue[0].entries,books:ue[1].entries,collections:ue[2].entries,entities:ue[3].entries,totalWorks:ue[0].total,totalBooks:ue[1].total,totalCollections:ue[2].total,totalEntities:ue[3].total})}}catch(ie){C(ie instanceof Error?ie.message:String(ie)),k(null)}finally{S(!1)}},[e]);v.useEffect(()=>{let V=!1;const de=()=>{var Q,ye;const ie=["work","book","collection","entity"],ue=Promise.all(ie.map(Te=>e.loadEntries(Te,{page:1,pageSize:1}).catch(()=>({total:0})))),he=((Q=e.getResourceCounts)==null?void 0:Q.call(e).catch(()=>null))??Promise.resolve(null),W=((ye=e.getSubtypeStats)==null?void 0:ye.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([ue,he,W]).then(([Te,_e,R])=>{V||(Z({works:Te[0].total,books:Te[1].total,collections:Te[2].total,entities:Te[3].total,hasText:_e==null?void 0:_e.hasText,hasImage:_e==null?void 0:_e.hasImage}),R&&ce(R))})};return e.getCounts?e.getCounts().then(ie=>{var ue,he;V||(Z({works:ie.works,books:ie.books,collections:ie.collections,entities:ie.entities,hasText:(ue=ie.resourceCounts)==null?void 0:ue.hasText,hasImage:(he=ie.resourceCounts)==null?void 0:he.hasImage}),ie.subtypeStats&&ce(ie.subtypeStats))}).catch(()=>{V||de()}):de(),()=>{V=!0}},[e]),v.useEffect(()=>{se.current||!(p!=null&&p.trim())||(se.current=!0,pe(p))},[p,pe]);const re=v.useCallback(V=>{if(x(V),!V.trim()){d==null||d(V),A(!0),k(null),_(null);return}be.current&&clearTimeout(be.current),be.current=setTimeout(()=>{_(null),d==null||d(V),pe(V)},js)},[pe,d]),De=v.useCallback(V=>{be.current&&clearTimeout(be.current),d==null||d(V),pe(V)},[pe,d]),Me=v.useCallback(V=>{_(V),pe(b,ws)},[b,pe]);v.useEffect(()=>{if(!$.length){N([]);return}let V=!1;return D(!0),Promise.all($.slice(0,10).map(async de=>{var ie,ue,he;try{if(e.getEntry){const Q=await e.getEntry(de);if(Q)return Q}const W=await e.getItem(de);if(W){const Q=W.authors;return{id:de,title:W.title||de,type:W.type||"work",author:(ie=Q==null?void 0:Q[0])==null?void 0:ie.name,dynasty:(ue=Q==null?void 0:Q[0])==null?void 0:ue.dynasty,role:(he=Q==null?void 0:Q[0])==null?void 0:he.role,edition:W.edition||void 0}}}catch{}return{id:de,title:de,type:"work",notFound:!0}})).then(de=>{V||(N(de),D(!1))}),()=>{V=!0}},[$,e]);const Oe=V=>{z(V.id),Cs(V.id),P(At()),r==null||r(V)},Je=V=>{Is(V),P(At())},yt=()=>{Es(),P([])},ot=V=>g.find(de=>de.type===V),lt=m&&(m.works.length>0||m.books.length>0||m.collections.length>0);return i.jsxs("div",{className:"bim-browser-container",children:[i.jsx("header",{style:{padding:"12px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:i.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[i.jsx("h1",{style:{margin:0,fontSize:"18px",color:"var(--bim-fg, #333)"},children:f.browser.title}),i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,!u&&i.jsx(no,{variant:"index-browser",indexSource:t,syncConfig:n,onSwitchMode:l,onToggleDraft:s,onConfigurePath:a,onSelectFolder:c})]})]})}),i.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[i.jsx(ro,{transport:e,value:b,onChange:re,onSearch:De,onEntrySelect:Oe}),o&&i.jsx("button",{onClick:()=>o("work"),style:{padding:"8px 14px",border:"1px solid var(--bim-primary, #0078d4)",borderRadius:"6px",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px"},children:f.action.newEntry})]}),q&&E&&i.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[i.jsx("span",{children:j?i.jsxs(i.Fragment,{children:[(j.book??0)>0&&i.jsxs(i.Fragment,{children:["書 ",i.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:j.book.toLocaleString()})," 部 ,",i.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:q.books.toLocaleString()})," 本"]}),j.article?i.jsxs(i.Fragment,{children:[i.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",i.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:j.article.toLocaleString()})," 篇"]}):null,j.poem?i.jsxs(i.Fragment,{children:[i.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",i.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:j.poem.toLocaleString()})," 首"]}):null,i.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",i.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:q.collections.toLocaleString()})]}):i.jsxs(i.Fragment,{children:[f.indexType.work," ",i.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:q.works.toLocaleString()}),i.jsx("span",{style:{margin:"0 6px"},children:"·"}),f.indexType.book," ",i.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:q.books.toLocaleString()}),i.jsx("span",{style:{margin:"0 6px"},children:"·"}),f.indexType.collection," ",i.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:q.collections.toLocaleString()}),q.entities>0&&i.jsxs(i.Fragment,{children:[i.jsx("span",{style:{margin:"0 6px"},children:"·"}),f.indexType.entity," ",i.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:q.entities.toLocaleString()})]})]})}),q.hasImage!=null&&q.hasText!=null&&i.jsxs("span",{children:[f.resourceType.image," ",i.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:q.hasImage.toLocaleString()}),i.jsx("span",{style:{margin:"0 6px"},children:"·"}),f.resourceType.text," ",i.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:q.hasText.toLocaleString()})]})]}),i.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:I?i.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:f.search.searching}):B?i.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[i.jsx("div",{style:{fontSize:"24px",marginBottom:"8px"},children:"⚠️"}),i.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)"},children:B})]}):E?i.jsx("div",{style:{flex:1},children:M?i.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:f.search.loading}):L.length>0?i.jsxs(i.Fragment,{children:[i.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[i.jsx("span",{children:f.search.recentBrowse}),i.jsx("button",{onClick:yt,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:f.search.clearRecent})]}),i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:L.slice(0,U?10:3).map(V=>V.notFound?i.jsx(_s,{id:V.id,onRemove:Je,t:f},V.id):i.jsx(zr,{entry:V,selected:T===V.id,onClick:Oe,getConfig:ot,onRemove:Je},V.id))}),!U&&L.length>3&&i.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:f.action.expandMore})]}):i.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[i.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),i.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:f.search.searchTitle}),i.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:f.search.searchSubtitle})]})}):lt?i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:g.map(({type:V,icon:de,name:ie,key:ue})=>{const he=m[ue]??[],W=Ts[ue],Q=m[W]??0;if(he.length===0)return null;const Te=!(w===V)&&Q>gn;return i.jsxs("div",{children:[i.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"6px"},children:[i.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:[de," ",ie,i.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[Q," ",f.unit.items]})]}),Te&&i.jsx("button",{onClick:()=>Me(V),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:f.action.viewAll})]}),i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:he.map(_e=>i.jsx(zr,{entry:_e,selected:T===_e.id,onClick:Oe,getConfig:ot,query:b},_e.id))})]},V)})}):i.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[i.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),i.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:Nt(f.search.noResultsFor,{query:b})}),i.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:f.search.tryOther})]})})]})},zr=({entry:e,selected:t,onClick:n,getConfig:r,query:o,onRemove:l})=>{const s=G(),{convert:a}=X(),c=[...e.additional_titles||[],...e.attached_texts||[]],u=o&&c.length?c.find(p=>{const d=typeof p=="string"?p:p==null?void 0:p.book_title;return d==null?void 0:d.toLowerCase().includes(o.toLowerCase())}):void 0;return i.jsxs("div",{onClick:()=>n(e),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:t?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[i.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[i.jsx("span",{style:{fontSize:"16px"},children:r(e.type).icon}),i.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:r(e.type).name})]}),i.jsxs("div",{style:{flex:1,minWidth:0},children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[i.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:a(e.title||e.primary_name||e.id)}),i.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[e.has_text&&i.jsx("span",{title:s.misc.textResource,children:"📝"}),e.has_image&&i.jsx("span",{title:s.misc.imageResource,children:"🖼️"})]}),e.edition&&i.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:a(e.edition)}),e.measure_info?i.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:a(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?i.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[e.juan_count,s.unit.juan]}):null]}),(e.dynasty||e.author)&&i.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[e.dynasty&&i.jsxs("span",{children:["〔",a(e.dynasty),"〕"]}),e.author&&i.jsx("span",{children:a(e.author)}),e.role&&e.role!=="author"&&i.jsxs("span",{children:[" ",a(e.role)]}),e.type==="entity"&&(e.birth_year!=null||e.death_year!=null)&&i.jsxs("span",{style:{marginLeft:e.dynasty?"4px":0},children:[e.birth_year??"?","—",e.death_year??"?"]})]}),u&&i.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[s.search.alias,":",a(u)]})]}),l?i.jsx("button",{onClick:p=>{p.stopPropagation(),l(e.id)},title:s.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1,opacity:.5,marginTop:"2px"},children:"×"}):i.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},_s=({id:e,onRemove:t,t:n})=>i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",opacity:.6},children:[i.jsx("span",{style:{fontSize:"16px"},children:"❓"}),i.jsxs("div",{style:{flex:1,minWidth:0},children:[i.jsx("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",fontFamily:"monospace"},children:e}),i.jsx("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginTop:"2px"},children:n.search.itemNotFound})]}),i.jsx("button",{onClick:()=>t(e),title:n.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function zs(e){var t;return!e.dynasty&&!e.birth_year&&!e.death_year&&(!e.alt_names||e.alt_names.length===0)&&!((t=e.description)!=null&&t.text)}function Rs({data:e}){const{convert:t}=X(),{dynasty:n,birth_year:r,death_year:o}=e,l=[];return n&&l.push(`〔${t(n)}〕`),r!==void 0&&o!==void 0?l.push(`${r}—${o}`):r!==void 0?l.push(`${r}—?`):o!==void 0&&l.push(`?—${o}`),l.length===0?null:i.jsx("span",{style:{fontSize:"14px",color:"var(--bim-desc-fg, #717171)",marginLeft:"8px",fontWeight:"normal"},children:l.join(" ")})}function Ls({alt_names:e}){const{convert:t}=X(),n=new Map;for(const l of e){const s=l.type||"別名";n.has(s)||n.set(s,[]),n.get(s).push(l.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],o=[...n.keys()].sort((l,s)=>{const a=r.indexOf(l),c=r.indexOf(s);return a===-1&&c===-1?0:a===-1?1:c===-1?-1:a-c});return i.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:o.map(l=>{const s=n.get(l);return i.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[i.jsx("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:l}),i.jsx("span",{children:s.map((a,c)=>i.jsxs("span",{children:[c>0&&i.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),t(a)]},c))})]},l)})})}function As({data:e}){const t=e.external_ids;if(!t)return null;const n=[];return t.cbdb_id&&n.push(i.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${t.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",border:"1px solid var(--bim-link-fg, #0066cc)40",borderRadius:"3px",textDecoration:"none",background:"var(--bim-link-fg, #0066cc)08"},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",t.cbdb_id]},"cbdb")),n.length===0?null:i.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:n})}function Bs({works:e,transport:t,onNavigate:n,renderLink:r}){const o=G(),{convert:l}=X(),s=Fe(),[a,c]=v.useState(new Map);v.useEffect(()=>{if(!t)return;let h=!1;const f=e.map(b=>b.work_id);return(async()=>{const b=new Map;if(t.getEntriesByIds)try{const w=await t.getEntriesByIds(f);let _=!0;for(let I=0;I<f.length;I++){const S=w[I];S!=null&&S.title?b.set(f[I],S.title):S!=null&&S.primary_name?b.set(f[I],S.primary_name):_=!1}if(_)return b}catch{}const x=[...f],m=8,k=new Array(m).fill(0).map(async()=>{for(;x.length;){const w=x.shift();if(!w)break;if(!b.has(w))try{if(t.getEntry){const S=await t.getEntry(w);if(S!=null&&S.title){b.set(w,S.title);continue}}const _=await t.getItem(w),I=_&&(_.title||_.primary_name)||w;b.set(w,I)}catch{b.set(w,w)}}});return await Promise.all(k),b})().then(b=>{h||c(b)}),()=>{h=!0}},[e,t]);const u=new Map;for(const h of e){const f=h.role||"";u.has(f)||u.set(f,[]),u.get(f).push(h)}const p=["撰","編","注","輯","集","校","評","譯","述","作",""],d=[...u.keys()].sort((h,f)=>{const g=p.indexOf(h),b=p.indexOf(f);return g===-1&&b===-1?h.localeCompare(f):g===-1?1:b===-1?-1:g-b});return i.jsxs("div",{style:{marginTop:"12px"},children:[i.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)",margin:"0 0 8px",paddingBottom:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[o.label.relatedWorks," ",i.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",e.length,")"]})]}),d.map(h=>{const f=u.get(h);return i.jsxs("div",{style:{marginBottom:"8px"},children:[h&&i.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginBottom:"2px"},children:[l(h)," ",i.jsxs("span",{style:{color:"var(--bim-desc-fg, #bbb)"},children:["(",f.length,")"]})]}),i.jsx("ul",{style:{margin:0,paddingLeft:h?"16px":"0",listStyle:h?"disc":"none",fontSize:"14px",lineHeight:1.8},children:f.map((g,b)=>{const x=l(a.get(g.work_id)||g.work_id);return r?i.jsx("li",{children:r(g.work_id,x)},b):n?i.jsx("li",{children:i.jsx("a",{href:s(g.work_id),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),n(g.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:x})},b):i.jsx("li",{children:x},b)})})]},h)})]})}const io=({data:e,transport:t,onNavigate:n,renderLink:r,headerExtra:o})=>{var p;const l=G(),{convert:s}=X();let a=!1;try{a=ne.extractStatus(e.id)==="draft"}catch{}const c=zs(e),u=e.subtype==="people"?"人物":e.subtype==="place"?"地名":e.subtype==="dynasty"?"朝代":e.subtype==="anonymous"?"佚名":e.subtype==="collective"?"集体":e.subtype;return i.jsxs("div",{children:[i.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[i.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:"var(--bim-fg, #222)"},children:[s(e.primary_name),i.jsx(Rs,{data:e})]}),o]}),i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"8px"},children:[i.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:"#5b3e8e",border:"1px solid #5b3e8e40",borderRadius:"2px",background:"#5b3e8e08"},children:l.indexType.entity}),u&&e.subtype!=="people"&&i.jsx("span",{children:u}),a&&i.jsx("span",{style:{padding:"1px 6px",background:"#fff3cd",border:"1px solid #ffc107",borderRadius:"2px",color:"#856404"},children:l.status.draft}),i.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:e.id})]}),c&&i.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #999)",fontStyle:"italic",padding:"8px 12px",background:"var(--bim-widget-bg, #f8f8f8)",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),e.alt_names&&e.alt_names.length>0&&i.jsx(Ls,{alt_names:e.alt_names}),i.jsx(As,{data:e}),((p=e.description)==null?void 0:p.text)&&i.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:s(e.description.text)}),e.works&&e.works.length>0&&i.jsx(Bs,{works:e.works,transport:t,onNavigate:n,renderLink:r})]})};function Ps(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const Fs=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Ds=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Ms={};function Rr(e,t){return(Ms.jsx?Ds:Fs).test(e)}const Os=/[ \t\n\f\r]/g;function Ws(e){return typeof e=="object"?e.type==="text"?Lr(e.value):!1:Lr(e)}function Lr(e){return e.replace(Os,"")===""}class Ht{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}Ht.prototype.normal={};Ht.prototype.property={};Ht.prototype.space=void 0;function oo(e,t){const n={},r={};for(const o of e)Object.assign(n,o.property),Object.assign(r,o.normal);return new Ht(n,r,t)}function On(e){return e.toLowerCase()}class we{constructor(t,n){this.attribute=n,this.property=t}}we.prototype.attribute="";we.prototype.booleanish=!1;we.prototype.boolean=!1;we.prototype.commaOrSpaceSeparated=!1;we.prototype.commaSeparated=!1;we.prototype.defined=!1;we.prototype.mustUseProperty=!1;we.prototype.number=!1;we.prototype.overloadedBoolean=!1;we.prototype.property="";we.prototype.spaceSeparated=!1;we.prototype.space=void 0;let $s=0;const K=rt(),fe=rt(),Wn=rt(),F=rt(),ae=rt(),ft=rt(),Ce=rt();function rt(){return 2**++$s}const $n=Object.freeze(Object.defineProperty({__proto__:null,boolean:K,booleanish:fe,commaOrSpaceSeparated:Ce,commaSeparated:ft,number:F,overloadedBoolean:Wn,spaceSeparated:ae},Symbol.toStringTag,{value:"Module"})),xn=Object.keys($n);class er extends we{constructor(t,n,r,o){let l=-1;if(super(t,n),Ar(this,"space",o),typeof r=="number")for(;++l<xn.length;){const s=xn[l];Ar(this,xn[l],(r&$n[s])===$n[s])}}}er.prototype.defined=!0;function Ar(e,t,n){n&&(e[t]=n)}function xt(e){const t={},n={};for(const[r,o]of Object.entries(e.properties)){const l=new er(r,e.transform(e.attributes||{},r),o,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(l.mustUseProperty=!0),t[r]=l,n[On(r)]=r,n[On(l.attribute)]=r}return new Ht(t,n,e.space)}const lo=xt({properties:{ariaActiveDescendant:null,ariaAtomic:fe,ariaAutoComplete:null,ariaBusy:fe,ariaChecked:fe,ariaColCount:F,ariaColIndex:F,ariaColSpan:F,ariaControls:ae,ariaCurrent:null,ariaDescribedBy:ae,ariaDetails:null,ariaDisabled:fe,ariaDropEffect:ae,ariaErrorMessage:null,ariaExpanded:fe,ariaFlowTo:ae,ariaGrabbed:fe,ariaHasPopup:null,ariaHidden:fe,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:ae,ariaLevel:F,ariaLive:null,ariaModal:fe,ariaMultiLine:fe,ariaMultiSelectable:fe,ariaOrientation:null,ariaOwns:ae,ariaPlaceholder:null,ariaPosInSet:F,ariaPressed:fe,ariaReadOnly:fe,ariaRelevant:null,ariaRequired:fe,ariaRoleDescription:ae,ariaRowCount:F,ariaRowIndex:F,ariaRowSpan:F,ariaSelected:fe,ariaSetSize:F,ariaSort:null,ariaValueMax:F,ariaValueMin:F,ariaValueNow:F,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function so(e,t){return t in e?e[t]:t}function ao(e,t){return so(e,t.toLowerCase())}const Ns=xt({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:ft,acceptCharset:ae,accessKey:ae,action:null,allow:null,allowFullScreen:K,allowPaymentRequest:K,allowUserMedia:K,alt:null,as:null,async:K,autoCapitalize:null,autoComplete:ae,autoFocus:K,autoPlay:K,blocking:ae,capture:null,charSet:null,checked:K,cite:null,className:ae,cols:F,colSpan:null,content:null,contentEditable:fe,controls:K,controlsList:ae,coords:F|ft,crossOrigin:null,data:null,dateTime:null,decoding:null,default:K,defer:K,dir:null,dirName:null,disabled:K,download:Wn,draggable:fe,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:K,formTarget:null,headers:ae,height:F,hidden:Wn,high:F,href:null,hrefLang:null,htmlFor:ae,httpEquiv:ae,id:null,imageSizes:null,imageSrcSet:null,inert:K,inputMode:null,integrity:null,is:null,isMap:K,itemId:null,itemProp:ae,itemRef:ae,itemScope:K,itemType:ae,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:K,low:F,manifest:null,max:null,maxLength:F,media:null,method:null,min:null,minLength:F,multiple:K,muted:K,name:null,nonce:null,noModule:K,noValidate:K,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:K,optimum:F,pattern:null,ping:ae,placeholder:null,playsInline:K,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:K,referrerPolicy:null,rel:ae,required:K,reversed:K,rows:F,rowSpan:F,sandbox:ae,scope:null,scoped:K,seamless:K,selected:K,shadowRootClonable:K,shadowRootDelegatesFocus:K,shadowRootMode:null,shape:null,size:F,sizes:null,slot:null,span:F,spellCheck:fe,src:null,srcDoc:null,srcLang:null,srcSet:null,start:F,step:null,style:null,tabIndex:F,target:null,title:null,translate:null,type:null,typeMustMatch:K,useMap:null,value:fe,width:F,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:ae,axis:null,background:null,bgColor:null,border:F,borderColor:null,bottomMargin:F,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:K,declare:K,event:null,face:null,frame:null,frameBorder:null,hSpace:F,leftMargin:F,link:null,longDesc:null,lowSrc:null,marginHeight:F,marginWidth:F,noResize:K,noHref:K,noShade:K,noWrap:K,object:null,profile:null,prompt:null,rev:null,rightMargin:F,rules:null,scheme:null,scrolling:fe,standby:null,summary:null,text:null,topMargin:F,valueType:null,version:null,vAlign:null,vLink:null,vSpace:F,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:K,disableRemotePlayback:K,prefix:null,property:null,results:F,security:null,unselectable:null},space:"html",transform:ao}),Hs=xt({attributes:{accentHeight:"accent-height",alignmentBaseline:"alignment-baseline",arabicForm:"arabic-form",baselineShift:"baseline-shift",capHeight:"cap-height",className:"class",clipPath:"clip-path",clipRule:"clip-rule",colorInterpolation:"color-interpolation",colorInterpolationFilters:"color-interpolation-filters",colorProfile:"color-profile",colorRendering:"color-rendering",crossOrigin:"crossorigin",dataType:"datatype",dominantBaseline:"dominant-baseline",enableBackground:"enable-background",fillOpacity:"fill-opacity",fillRule:"fill-rule",floodColor:"flood-color",floodOpacity:"flood-opacity",fontFamily:"font-family",fontSize:"font-size",fontSizeAdjust:"font-size-adjust",fontStretch:"font-stretch",fontStyle:"font-style",fontVariant:"font-variant",fontWeight:"font-weight",glyphName:"glyph-name",glyphOrientationHorizontal:"glyph-orientation-horizontal",glyphOrientationVertical:"glyph-orientation-vertical",hrefLang:"hreflang",horizAdvX:"horiz-adv-x",horizOriginX:"horiz-origin-x",horizOriginY:"horiz-origin-y",imageRendering:"image-rendering",letterSpacing:"letter-spacing",lightingColor:"lighting-color",markerEnd:"marker-end",markerMid:"marker-mid",markerStart:"marker-start",navDown:"nav-down",navDownLeft:"nav-down-left",navDownRight:"nav-down-right",navLeft:"nav-left",navNext:"nav-next",navPrev:"nav-prev",navRight:"nav-right",navUp:"nav-up",navUpLeft:"nav-up-left",navUpRight:"nav-up-right",onAbort:"onabort",onActivate:"onactivate",onAfterPrint:"onafterprint",onBeforePrint:"onbeforeprint",onBegin:"onbegin",onCancel:"oncancel",onCanPlay:"oncanplay",onCanPlayThrough:"oncanplaythrough",onChange:"onchange",onClick:"onclick",onClose:"onclose",onCopy:"oncopy",onCueChange:"oncuechange",onCut:"oncut",onDblClick:"ondblclick",onDrag:"ondrag",onDragEnd:"ondragend",onDragEnter:"ondragenter",onDragExit:"ondragexit",onDragLeave:"ondragleave",onDragOver:"ondragover",onDragStart:"ondragstart",onDrop:"ondrop",onDurationChange:"ondurationchange",onEmptied:"onemptied",onEnd:"onend",onEnded:"onended",onError:"onerror",onFocus:"onfocus",onFocusIn:"onfocusin",onFocusOut:"onfocusout",onHashChange:"onhashchange",onInput:"oninput",onInvalid:"oninvalid",onKeyDown:"onkeydown",onKeyPress:"onkeypress",onKeyUp:"onkeyup",onLoad:"onload",onLoadedData:"onloadeddata",onLoadedMetadata:"onloadedmetadata",onLoadStart:"onloadstart",onMessage:"onmessage",onMouseDown:"onmousedown",onMouseEnter:"onmouseenter",onMouseLeave:"onmouseleave",onMouseMove:"onmousemove",onMouseOut:"onmouseout",onMouseOver:"onmouseover",onMouseUp:"onmouseup",onMouseWheel:"onmousewheel",onOffline:"onoffline",onOnline:"ononline",onPageHide:"onpagehide",onPageShow:"onpageshow",onPaste:"onpaste",onPause:"onpause",onPlay:"onplay",onPlaying:"onplaying",onPopState:"onpopstate",onProgress:"onprogress",onRateChange:"onratechange",onRepeat:"onrepeat",onReset:"onreset",onResize:"onresize",onScroll:"onscroll",onSeeked:"onseeked",onSeeking:"onseeking",onSelect:"onselect",onShow:"onshow",onStalled:"onstalled",onStorage:"onstorage",onSubmit:"onsubmit",onSuspend:"onsuspend",onTimeUpdate:"ontimeupdate",onToggle:"ontoggle",onUnload:"onunload",onVolumeChange:"onvolumechange",onWaiting:"onwaiting",onZoom:"onzoom",overlinePosition:"overline-position",overlineThickness:"overline-thickness",paintOrder:"paint-order",panose1:"panose-1",pointerEvents:"pointer-events",referrerPolicy:"referrerpolicy",renderingIntent:"rendering-intent",shapeRendering:"shape-rendering",stopColor:"stop-color",stopOpacity:"stop-opacity",strikethroughPosition:"strikethrough-position",strikethroughThickness:"strikethrough-thickness",strokeDashArray:"stroke-dasharray",strokeDashOffset:"stroke-dashoffset",strokeLineCap:"stroke-linecap",strokeLineJoin:"stroke-linejoin",strokeMiterLimit:"stroke-miterlimit",strokeOpacity:"stroke-opacity",strokeWidth:"stroke-width",tabIndex:"tabindex",textAnchor:"text-anchor",textDecoration:"text-decoration",textRendering:"text-rendering",transformOrigin:"transform-origin",typeOf:"typeof",underlinePosition:"underline-position",underlineThickness:"underline-thickness",unicodeBidi:"unicode-bidi",unicodeRange:"unicode-range",unitsPerEm:"units-per-em",vAlphabetic:"v-alphabetic",vHanging:"v-hanging",vIdeographic:"v-ideographic",vMathematical:"v-mathematical",vectorEffect:"vector-effect",vertAdvY:"vert-adv-y",vertOriginX:"vert-origin-x",vertOriginY:"vert-origin-y",wordSpacing:"word-spacing",writingMode:"writing-mode",xHeight:"x-height",playbackOrder:"playbackorder",timelineBegin:"timelinebegin"},properties:{about:Ce,accentHeight:F,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:F,amplitude:F,arabicForm:null,ascent:F,attributeName:null,attributeType:null,azimuth:F,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:F,by:null,calcMode:null,capHeight:F,className:ae,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:F,diffuseConstant:F,direction:null,display:null,dur:null,divisor:F,dominantBaseline:null,download:K,dx:null,dy:null,edgeMode:null,editable:null,elevation:F,enableBackground:null,end:null,event:null,exponent:F,externalResourcesRequired:null,fill:null,fillOpacity:F,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:ft,g2:ft,glyphName:ft,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:F,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:F,horizOriginX:F,horizOriginY:F,id:null,ideographic:F,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:F,k:F,k1:F,k2:F,k3:F,k4:F,kernelMatrix:Ce,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:F,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:F,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:F,overlineThickness:F,paintOrder:null,panose1:null,path:null,pathLength:F,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:ae,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:F,pointsAtY:F,pointsAtZ:F,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:Ce,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:Ce,rev:Ce,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:Ce,requiredFeatures:Ce,requiredFonts:Ce,requiredFormats:Ce,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:F,specularExponent:F,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:F,strikethroughThickness:F,string:null,stroke:null,strokeDashArray:Ce,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:F,strokeOpacity:F,strokeWidth:null,style:null,surfaceScale:F,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:Ce,tabIndex:F,tableValues:null,target:null,targetX:F,targetY:F,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:Ce,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:F,underlineThickness:F,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:F,values:null,vAlphabetic:F,vMathematical:F,vectorEffect:null,vHanging:F,vIdeographic:F,version:null,vertAdvY:F,vertOriginX:F,vertOriginY:F,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:F,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:so}),co=xt({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:"xlink",transform(e,t){return"xlink:"+t.slice(5).toLowerCase()}}),uo=xt({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:ao}),po=xt({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),Us={classId:"classID",dataType:"datatype",itemId:"itemID",strokeDashArray:"strokeDasharray",strokeDashOffset:"strokeDashoffset",strokeLineCap:"strokeLinecap",strokeLineJoin:"strokeLinejoin",strokeMiterLimit:"strokeMiterlimit",typeOf:"typeof",xLinkActuate:"xlinkActuate",xLinkArcRole:"xlinkArcrole",xLinkHref:"xlinkHref",xLinkRole:"xlinkRole",xLinkShow:"xlinkShow",xLinkTitle:"xlinkTitle",xLinkType:"xlinkType",xmlnsXLink:"xmlnsXlink"},Vs=/[A-Z]/g,Br=/-[a-z]/g,qs=/^data[-\w.:]+$/i;function Ys(e,t){const n=On(t);let r=t,o=we;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&qs.test(t)){if(t.charAt(4)==="-"){const l=t.slice(5).replace(Br,Ks);r="data"+l.charAt(0).toUpperCase()+l.slice(1)}else{const l=t.slice(4);if(!Br.test(l)){let s=l.replace(Vs,Gs);s.charAt(0)!=="-"&&(s="-"+s),t="data"+s}}o=er}return new o(r,t)}function Gs(e){return"-"+e.toLowerCase()}function Ks(e){return e.charAt(1).toUpperCase()}const Xs=oo([lo,Ns,co,uo,po],"html"),tr=oo([lo,Hs,co,uo,po],"svg");function Js(e){return e.join(" ").trim()}function fo(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var at={},mn,Pr;function Zs(){if(Pr)return mn;Pr=1;var e=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,t=/\n/g,n=/^\s*/,r=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,o=/^:\s*/,l=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,s=/^[;\s]*/,a=/^\s+|\s+$/g,c=`
2
- `,u="/",p="*",d="",h="comment",f="declaration";function g(x,m){if(typeof x!="string")throw new TypeError("First argument must be a string");if(!x)return[];m=m||{};var k=1,w=1;function _(P){var L=P.match(t);L&&(k+=L.length);var N=P.lastIndexOf(c);w=~N?P.length-N:w+P.length}function I(){var P={line:k,column:w};return function(L){return L.position=new S(P),B(),L}}function S(P){this.start=P,this.end={line:k,column:w},this.source=m.source}S.prototype.content=x;function T(P){var L=new Error(m.source+":"+k+":"+w+": "+P);if(L.reason=P,L.filename=m.source,L.line=k,L.column=w,L.source=x,!m.silent)throw L}function z(P){var L=P.exec(x);if(L){var N=L[0];return _(N),x=x.slice(N.length),L}}function B(){z(n)}function C(P){var L;for(P=P||[];L=E();)L!==!1&&P.push(L);return P}function E(){var P=I();if(!(u!=x.charAt(0)||p!=x.charAt(1))){for(var L=2;d!=x.charAt(L)&&(p!=x.charAt(L)||u!=x.charAt(L+1));)++L;if(L+=2,d===x.charAt(L-1))return T("End of comment missing");var N=x.slice(2,L-2);return w+=2,_(N),x=x.slice(L),w+=2,P({type:h,comment:N})}}function A(){var P=I(),L=z(r);if(L){if(E(),!z(o))return T("property missing ':'");var N=z(l),M=P({type:f,property:b(L[0].replace(e,d)),value:N?b(N[0].replace(e,d)):d});return z(s),M}}function $(){var P=[];C(P);for(var L;L=A();)L!==!1&&(P.push(L),C(P));return P}return B(),$()}function b(x){return x?x.replace(a,d):d}return mn=g,mn}var Fr;function Qs(){if(Fr)return at;Fr=1;var e=at&&at.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(at,"__esModule",{value:!0}),at.default=n;const t=e(Zs());function n(r,o){let l=null;if(!r||typeof r!="string")return l;const s=(0,t.default)(r),a=typeof o=="function";return s.forEach(c=>{if(c.type!=="declaration")return;const{property:u,value:p}=c;a?o(u,p,c):p&&(l=l||{},l[u]=p)}),l}return at}var Ct={},Dr;function ea(){if(Dr)return Ct;Dr=1,Object.defineProperty(Ct,"__esModule",{value:!0}),Ct.camelCase=void 0;var e=/^--[a-zA-Z0-9_-]+$/,t=/-([a-z])/g,n=/^[^-]+$/,r=/^-(webkit|moz|ms|o|khtml)-/,o=/^-(ms)-/,l=function(u){return!u||n.test(u)||e.test(u)},s=function(u,p){return p.toUpperCase()},a=function(u,p){return"".concat(p,"-")},c=function(u,p){return p===void 0&&(p={}),l(u)?u:(u=u.toLowerCase(),p.reactCompat?u=u.replace(o,a):u=u.replace(r,a),u.replace(t,s))};return Ct.camelCase=c,Ct}var It,Mr;function ta(){if(Mr)return It;Mr=1;var e=It&&It.__importDefault||function(o){return o&&o.__esModule?o:{default:o}},t=e(Qs()),n=ea();function r(o,l){var s={};return!o||typeof o!="string"||(0,t.default)(o,function(a,c){a&&c&&(s[(0,n.camelCase)(a,l)]=c)}),s}return r.default=r,It=r,It}var na=ta();const ra=fo(na),ho=go("end"),nr=go("start");function go(e){return t;function t(n){const r=n&&n.position&&n.position[e]||{};if(typeof r.line=="number"&&r.line>0&&typeof r.column=="number"&&r.column>0)return{line:r.line,column:r.column,offset:typeof r.offset=="number"&&r.offset>-1?r.offset:void 0}}}function ia(e){const t=nr(e),n=ho(e);if(t&&n)return{start:t,end:n}}function Bt(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?Or(e.position):"start"in e||"end"in e?Or(e):"line"in e||"column"in e?Nn(e):""}function Nn(e){return Wr(e&&e.line)+":"+Wr(e&&e.column)}function Or(e){return Nn(e&&e.start)+"-"+Nn(e&&e.end)}function Wr(e){return e&&typeof e=="number"?e:1}class me extends Error{constructor(t,n,r){super(),typeof n=="string"&&(r=n,n=void 0);let o="",l={},s=!1;if(n&&("line"in n&&"column"in n?l={place:n}:"start"in n&&"end"in n?l={place:n}:"type"in n?l={ancestors:[n],place:n.position}:l={...n}),typeof t=="string"?o=t:!l.cause&&t&&(s=!0,o=t.message,l.cause=t),!l.ruleId&&!l.source&&typeof r=="string"){const c=r.indexOf(":");c===-1?l.ruleId=r:(l.source=r.slice(0,c),l.ruleId=r.slice(c+1))}if(!l.place&&l.ancestors&&l.ancestors){const c=l.ancestors[l.ancestors.length-1];c&&(l.place=c.position)}const a=l.place&&"start"in l.place?l.place.start:l.place;this.ancestors=l.ancestors||void 0,this.cause=l.cause||void 0,this.column=a?a.column:void 0,this.fatal=void 0,this.file="",this.message=o,this.line=a?a.line:void 0,this.name=Bt(l.place)||"1:1",this.place=l.place||void 0,this.reason=this.message,this.ruleId=l.ruleId||void 0,this.source=l.source||void 0,this.stack=s&&l.cause&&typeof l.cause.stack=="string"?l.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}}me.prototype.file="";me.prototype.name="";me.prototype.reason="";me.prototype.message="";me.prototype.stack="";me.prototype.column=void 0;me.prototype.line=void 0;me.prototype.ancestors=void 0;me.prototype.cause=void 0;me.prototype.fatal=void 0;me.prototype.place=void 0;me.prototype.ruleId=void 0;me.prototype.source=void 0;const rr={}.hasOwnProperty,oa=new Map,la=/[A-Z]/g,sa=new Set(["table","tbody","thead","tfoot","tr"]),aa=new Set(["td","th"]),xo="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function ca(e,t){if(!t||t.Fragment===void 0)throw new TypeError("Expected `Fragment` in options");const n=t.filePath||void 0;let r;if(t.development){if(typeof t.jsxDEV!="function")throw new TypeError("Expected `jsxDEV` in options when `development: true`");r=ma(n,t.jsxDEV)}else{if(typeof t.jsx!="function")throw new TypeError("Expected `jsx` in production options");if(typeof t.jsxs!="function")throw new TypeError("Expected `jsxs` in production options");r=xa(n,t.jsx,t.jsxs)}const o={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||"react",evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space==="svg"?tr:Xs,stylePropertyNameCase:t.stylePropertyNameCase||"dom",tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},l=mo(o,e,void 0);return l&&typeof l!="string"?l:o.create(e,o.Fragment,{children:l||void 0},void 0)}function mo(e,t,n){if(t.type==="element")return ua(e,t,n);if(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression")return da(e,t);if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement")return fa(e,t,n);if(t.type==="mdxjsEsm")return pa(e,t);if(t.type==="root")return ha(e,t,n);if(t.type==="text")return ga(e,t)}function ua(e,t,n){const r=e.schema;let o=r;t.tagName.toLowerCase()==="svg"&&r.space==="html"&&(o=tr,e.schema=o),e.ancestors.push(t);const l=yo(e,t.tagName,!1),s=ba(e,t);let a=or(e,t);return sa.has(t.tagName)&&(a=a.filter(function(c){return typeof c=="string"?!Ws(c):!0})),bo(e,s,l,t),ir(s,a),e.ancestors.pop(),e.schema=r,e.create(t,l,s,n)}function da(e,t){if(t.data&&t.data.estree&&e.evaluater){const r=t.data.estree.body[0];return r.type,e.evaluater.evaluateExpression(r.expression)}Ot(e,t.position)}function pa(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);Ot(e,t.position)}function fa(e,t,n){const r=e.schema;let o=r;t.name==="svg"&&r.space==="html"&&(o=tr,e.schema=o),e.ancestors.push(t);const l=t.name===null?e.Fragment:yo(e,t.name,!0),s=ya(e,t),a=or(e,t);return bo(e,s,l,t),ir(s,a),e.ancestors.pop(),e.schema=r,e.create(t,l,s,n)}function ha(e,t,n){const r={};return ir(r,or(e,t)),e.create(t,e.Fragment,r,n)}function ga(e,t){return t.value}function bo(e,t,n,r){typeof n!="string"&&n!==e.Fragment&&e.passNode&&(t.node=r)}function ir(e,t){if(t.length>0){const n=t.length>1?t:t[0];n&&(e.children=n)}}function xa(e,t,n){return r;function r(o,l,s,a){const u=Array.isArray(s.children)?n:t;return a?u(l,s,a):u(l,s)}}function ma(e,t){return n;function n(r,o,l,s){const a=Array.isArray(l.children),c=nr(r);return t(o,l,s,a,{columnNumber:c?c.column-1:void 0,fileName:e,lineNumber:c?c.line:void 0},void 0)}}function ba(e,t){const n={};let r,o;for(o in t.properties)if(o!=="children"&&rr.call(t.properties,o)){const l=ka(e,o,t.properties[o]);if(l){const[s,a]=l;e.tableCellAlignToStyle&&s==="align"&&typeof a=="string"&&aa.has(t.tagName)?r=a:n[s]=a}}if(r){const l=n.style||(n.style={});l[e.stylePropertyNameCase==="css"?"text-align":"textAlign"]=r}return n}function ya(e,t){const n={};for(const r of t.attributes)if(r.type==="mdxJsxExpressionAttribute")if(r.data&&r.data.estree&&e.evaluater){const l=r.data.estree.body[0];l.type;const s=l.expression;s.type;const a=s.properties[0];a.type,Object.assign(n,e.evaluater.evaluateExpression(a.argument))}else Ot(e,t.position);else{const o=r.name;let l;if(r.value&&typeof r.value=="object")if(r.value.data&&r.value.data.estree&&e.evaluater){const a=r.value.data.estree.body[0];a.type,l=e.evaluater.evaluateExpression(a.expression)}else Ot(e,t.position);else l=r.value===null?!0:r.value;n[o]=l}return n}function or(e,t){const n=[];let r=-1;const o=e.passKeys?new Map:oa;for(;++r<t.children.length;){const l=t.children[r];let s;if(e.passKeys){const c=l.type==="element"?l.tagName:l.type==="mdxJsxFlowElement"||l.type==="mdxJsxTextElement"?l.name:void 0;if(c){const u=o.get(c)||0;s=c+"-"+u,o.set(c,u+1)}}const a=mo(e,l,s);a!==void 0&&n.push(a)}return n}function ka(e,t,n){const r=Ys(e.schema,t);if(!(n==null||typeof n=="number"&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?Ps(n):Js(n)),r.property==="style"){let o=typeof n=="object"?n:va(e,String(n));return e.stylePropertyNameCase==="css"&&(o=Sa(o)),["style",o]}return[e.elementAttributeNameCase==="react"&&r.space?Us[r.property]||r.property:r.attribute,n]}}function va(e,t){try{return ra(t,{reactCompat:!0})}catch(n){if(e.ignoreInvalidStyle)return{};const r=n,o=new me("Cannot parse `style` attribute",{ancestors:e.ancestors,cause:r,ruleId:"style",source:"hast-util-to-jsx-runtime"});throw o.file=e.filePath||void 0,o.url=xo+"#cannot-parse-style-attribute",o}}function yo(e,t,n){let r;if(!n)r={type:"Literal",value:t};else if(t.includes(".")){const o=t.split(".");let l=-1,s;for(;++l<o.length;){const a=Rr(o[l])?{type:"Identifier",name:o[l]}:{type:"Literal",value:o[l]};s=s?{type:"MemberExpression",object:s,property:a,computed:!!(l&&a.type==="Literal"),optional:!1}:a}r=s}else r=Rr(t)&&!/^[a-z]/.test(t)?{type:"Identifier",name:t}:{type:"Literal",value:t};if(r.type==="Literal"){const o=r.value;return rr.call(e.components,o)?e.components[o]:o}if(e.evaluater)return e.evaluater.evaluateExpression(r);Ot(e)}function Ot(e,t){const n=new me("Cannot handle MDX estrees without `createEvaluater`",{ancestors:e.ancestors,place:t,ruleId:"mdx-estree",source:"hast-util-to-jsx-runtime"});throw n.file=e.filePath||void 0,n.url=xo+"#cannot-handle-mdx-estrees-without-createevaluater",n}function Sa(e){const t={};let n;for(n in e)rr.call(e,n)&&(t[wa(n)]=e[n]);return t}function wa(e){let t=e.replace(la,ja);return t.slice(0,3)==="ms-"&&(t="-"+t),t}function ja(e){return"-"+e.toLowerCase()}const bn={action:["form"],cite:["blockquote","del","ins","q"],data:["object"],formAction:["button","input"],href:["a","area","base","link"],icon:["menuitem"],itemId:null,manifest:["html"],ping:["a","area"],poster:["video"],src:["audio","embed","iframe","img","input","script","source","track","video"]},Ca={};function lr(e,t){const n=Ca,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,o=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return ko(e,r,o)}function ko(e,t,n){if(Ia(e)){if("value"in e)return e.type==="html"&&!n?"":e.value;if(t&&"alt"in e&&e.alt)return e.alt;if("children"in e)return $r(e.children,t,n)}return Array.isArray(e)?$r(e,t,n):""}function $r(e,t,n){const r=[];let o=-1;for(;++o<e.length;)r[o]=ko(e[o],t,n);return r.join("")}function Ia(e){return!!(e&&typeof e=="object")}const Nr=document.createElement("i");function sr(e){const t="&"+e+";";Nr.innerHTML=t;const n=Nr.textContent;return n.charCodeAt(n.length-1)===59&&e!=="semi"||n===t?!1:n}function Ee(e,t,n,r){const o=e.length;let l=0,s;if(t<0?t=-t>o?0:o+t:t=t>o?o:t,n=n>0?n:0,r.length<1e4)s=Array.from(r),s.unshift(t,n),e.splice(...s);else for(n&&e.splice(t,n);l<r.length;)s=r.slice(l,l+1e4),s.unshift(t,0),e.splice(...s),l+=1e4,t+=1e4}function ze(e,t){return e.length>0?(Ee(e,e.length,0,t),e):t}const Hr={}.hasOwnProperty;function vo(e){const t={};let n=-1;for(;++n<e.length;)Ea(t,e[n]);return t}function Ea(e,t){let n;for(n in t){const o=(Hr.call(e,n)?e[n]:void 0)||(e[n]={}),l=t[n];let s;if(l)for(s in l){Hr.call(o,s)||(o[s]=[]);const a=l[s];Ta(o[s],Array.isArray(a)?a:a?[a]:[])}}}function Ta(e,t){let n=-1;const r=[];for(;++n<t.length;)(t[n].add==="after"?e:r).push(t[n]);Ee(e,0,0,r)}function So(e,t){const n=Number.parseInt(e,t);return n<9||n===11||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)===65535||(n&65535)===65534||n>1114111?"�":String.fromCodePoint(n)}function Pe(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const ve=Xe(/[A-Za-z]/),xe=Xe(/[\dA-Za-z]/),_a=Xe(/[#-'*+\--9=?A-Z^-~]/);function nn(e){return e!==null&&(e<32||e===127)}const Hn=Xe(/\d/),za=Xe(/[\dA-Fa-f]/),Ra=Xe(/[!-/:-@[-`{-~]/);function H(e){return e!==null&&e<-2}function le(e){return e!==null&&(e<0||e===32)}function J(e){return e===-2||e===-1||e===32}const un=Xe(new RegExp("\\p{P}|\\p{S}","u")),nt=Xe(/\s/);function Xe(e){return t;function t(n){return n!==null&&n>-1&&e.test(String.fromCharCode(n))}}function mt(e){const t=[];let n=-1,r=0,o=0;for(;++n<e.length;){const l=e.charCodeAt(n);let s="";if(l===37&&xe(e.charCodeAt(n+1))&&xe(e.charCodeAt(n+2)))o=2;else if(l<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(l))||(s=String.fromCharCode(l));else if(l>55295&&l<57344){const a=e.charCodeAt(n+1);l<56320&&a>56319&&a<57344?(s=String.fromCharCode(l,a),o=1):s="�"}else s=String.fromCharCode(l);s&&(t.push(e.slice(r,n),encodeURIComponent(s)),r=n+o+1,s=""),o&&(n+=o,o=0)}return t.join("")+e.slice(r)}function te(e,t,n,r){const o=r?r-1:Number.POSITIVE_INFINITY;let l=0;return s;function s(c){return J(c)?(e.enter(n),a(c)):t(c)}function a(c){return J(c)&&l++<o?(e.consume(c),a):(e.exit(n),t(c))}}const La={tokenize:Aa};function Aa(e){const t=e.attempt(this.parser.constructs.contentInitial,r,o);let n;return t;function r(a){if(a===null){e.consume(a);return}return e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),te(e,t,"linePrefix")}function o(a){return e.enter("paragraph"),l(a)}function l(a){const c=e.enter("chunkText",{contentType:"text",previous:n});return n&&(n.next=c),n=c,s(a)}function s(a){if(a===null){e.exit("chunkText"),e.exit("paragraph"),e.consume(a);return}return H(a)?(e.consume(a),e.exit("chunkText"),l):(e.consume(a),s)}}const Ba={tokenize:Pa},Ur={tokenize:Fa};function Pa(e){const t=this,n=[];let r=0,o,l,s;return a;function a(w){if(r<n.length){const _=n[r];return t.containerState=_[1],e.attempt(_[0].continuation,c,u)(w)}return u(w)}function c(w){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,o&&k();const _=t.events.length;let I=_,S;for(;I--;)if(t.events[I][0]==="exit"&&t.events[I][1].type==="chunkFlow"){S=t.events[I][1].end;break}m(r);let T=_;for(;T<t.events.length;)t.events[T][1].end={...S},T++;return Ee(t.events,I+1,0,t.events.slice(_)),t.events.length=T,u(w)}return a(w)}function u(w){if(r===n.length){if(!o)return h(w);if(o.currentConstruct&&o.currentConstruct.concrete)return g(w);t.interrupt=!!(o.currentConstruct&&!o._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(Ur,p,d)(w)}function p(w){return o&&k(),m(r),h(w)}function d(w){return t.parser.lazy[t.now().line]=r!==n.length,s=t.now().offset,g(w)}function h(w){return t.containerState={},e.attempt(Ur,f,g)(w)}function f(w){return r++,n.push([t.currentConstruct,t.containerState]),h(w)}function g(w){if(w===null){o&&k(),m(0),e.consume(w);return}return o=o||t.parser.flow(t.now()),e.enter("chunkFlow",{_tokenizer:o,contentType:"flow",previous:l}),b(w)}function b(w){if(w===null){x(e.exit("chunkFlow"),!0),m(0),e.consume(w);return}return H(w)?(e.consume(w),x(e.exit("chunkFlow")),r=0,t.interrupt=void 0,a):(e.consume(w),b)}function x(w,_){const I=t.sliceStream(w);if(_&&I.push(null),w.previous=l,l&&(l.next=w),l=w,o.defineSkip(w.start),o.write(I),t.parser.lazy[w.start.line]){let S=o.events.length;for(;S--;)if(o.events[S][1].start.offset<s&&(!o.events[S][1].end||o.events[S][1].end.offset>s))return;const T=t.events.length;let z=T,B,C;for(;z--;)if(t.events[z][0]==="exit"&&t.events[z][1].type==="chunkFlow"){if(B){C=t.events[z][1].end;break}B=!0}for(m(r),S=T;S<t.events.length;)t.events[S][1].end={...C},S++;Ee(t.events,z+1,0,t.events.slice(T)),t.events.length=S}}function m(w){let _=n.length;for(;_-- >w;){const I=n[_];t.containerState=I[1],I[0].exit.call(t,e)}n.length=w}function k(){o.write([null]),l=void 0,o=void 0,t.containerState._closeFlow=void 0}}function Fa(e,t,n){return te(e,e.attempt(this.parser.constructs.document,t,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function ht(e){if(e===null||le(e)||nt(e))return 1;if(un(e))return 2}function dn(e,t,n){const r=[];let o=-1;for(;++o<e.length;){const l=e[o].resolveAll;l&&!r.includes(l)&&(t=l(t,n),r.push(l))}return t}const Un={name:"attention",resolveAll:Da,tokenize:Ma};function Da(e,t){let n=-1,r,o,l,s,a,c,u,p;for(;++n<e.length;)if(e[n][0]==="enter"&&e[n][1].type==="attentionSequence"&&e[n][1]._close){for(r=n;r--;)if(e[r][0]==="exit"&&e[r][1].type==="attentionSequence"&&e[r][1]._open&&t.sliceSerialize(e[r][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[r][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[r][1].end.offset-e[r][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;c=e[r][1].end.offset-e[r][1].start.offset>1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;const d={...e[r][1].end},h={...e[n][1].start};Vr(d,-c),Vr(h,c),s={type:c>1?"strongSequence":"emphasisSequence",start:d,end:{...e[r][1].end}},a={type:c>1?"strongSequence":"emphasisSequence",start:{...e[n][1].start},end:h},l={type:c>1?"strongText":"emphasisText",start:{...e[r][1].end},end:{...e[n][1].start}},o={type:c>1?"strong":"emphasis",start:{...s.start},end:{...a.end}},e[r][1].end={...s.start},e[n][1].start={...a.end},u=[],e[r][1].end.offset-e[r][1].start.offset&&(u=ze(u,[["enter",e[r][1],t],["exit",e[r][1],t]])),u=ze(u,[["enter",o,t],["enter",s,t],["exit",s,t],["enter",l,t]]),u=ze(u,dn(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),u=ze(u,[["exit",l,t],["enter",a,t],["exit",a,t],["exit",o,t]]),e[n][1].end.offset-e[n][1].start.offset?(p=2,u=ze(u,[["enter",e[n][1],t],["exit",e[n][1],t]])):p=0,Ee(e,r-1,n-r+3,u),n=r+u.length-p-2;break}}for(n=-1;++n<e.length;)e[n][1].type==="attentionSequence"&&(e[n][1].type="data");return e}function Ma(e,t){const n=this.parser.constructs.attentionMarkers.null,r=this.previous,o=ht(r);let l;return s;function s(c){return l=c,e.enter("attentionSequence"),a(c)}function a(c){if(c===l)return e.consume(c),a;const u=e.exit("attentionSequence"),p=ht(c),d=!p||p===2&&o||n.includes(c),h=!o||o===2&&p||n.includes(r);return u._open=!!(l===42?d:d&&(o||!h)),u._close=!!(l===42?h:h&&(p||!d)),t(c)}}function Vr(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}const Oa={name:"autolink",tokenize:Wa};function Wa(e,t,n){let r=0;return o;function o(f){return e.enter("autolink"),e.enter("autolinkMarker"),e.consume(f),e.exit("autolinkMarker"),e.enter("autolinkProtocol"),l}function l(f){return ve(f)?(e.consume(f),s):f===64?n(f):u(f)}function s(f){return f===43||f===45||f===46||xe(f)?(r=1,a(f)):u(f)}function a(f){return f===58?(e.consume(f),r=0,c):(f===43||f===45||f===46||xe(f))&&r++<32?(e.consume(f),a):(r=0,u(f))}function c(f){return f===62?(e.exit("autolinkProtocol"),e.enter("autolinkMarker"),e.consume(f),e.exit("autolinkMarker"),e.exit("autolink"),t):f===null||f===32||f===60||nn(f)?n(f):(e.consume(f),c)}function u(f){return f===64?(e.consume(f),p):_a(f)?(e.consume(f),u):n(f)}function p(f){return xe(f)?d(f):n(f)}function d(f){return f===46?(e.consume(f),r=0,p):f===62?(e.exit("autolinkProtocol").type="autolinkEmail",e.enter("autolinkMarker"),e.consume(f),e.exit("autolinkMarker"),e.exit("autolink"),t):h(f)}function h(f){if((f===45||xe(f))&&r++<63){const g=f===45?h:d;return e.consume(f),g}return n(f)}}const Ut={partial:!0,tokenize:$a};function $a(e,t,n){return r;function r(l){return J(l)?te(e,o,"linePrefix")(l):o(l)}function o(l){return l===null||H(l)?t(l):n(l)}}const wo={continuation:{tokenize:Ha},exit:Ua,name:"blockQuote",tokenize:Na};function Na(e,t,n){const r=this;return o;function o(s){if(s===62){const a=r.containerState;return a.open||(e.enter("blockQuote",{_container:!0}),a.open=!0),e.enter("blockQuotePrefix"),e.enter("blockQuoteMarker"),e.consume(s),e.exit("blockQuoteMarker"),l}return n(s)}function l(s){return J(s)?(e.enter("blockQuotePrefixWhitespace"),e.consume(s),e.exit("blockQuotePrefixWhitespace"),e.exit("blockQuotePrefix"),t):(e.exit("blockQuotePrefix"),t(s))}}function Ha(e,t,n){const r=this;return o;function o(s){return J(s)?te(e,l,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(s):l(s)}function l(s){return e.attempt(wo,t,n)(s)}}function Ua(e){e.exit("blockQuote")}const jo={name:"characterEscape",tokenize:Va};function Va(e,t,n){return r;function r(l){return e.enter("characterEscape"),e.enter("escapeMarker"),e.consume(l),e.exit("escapeMarker"),o}function o(l){return Ra(l)?(e.enter("characterEscapeValue"),e.consume(l),e.exit("characterEscapeValue"),e.exit("characterEscape"),t):n(l)}}const Co={name:"characterReference",tokenize:qa};function qa(e,t,n){const r=this;let o=0,l,s;return a;function a(d){return e.enter("characterReference"),e.enter("characterReferenceMarker"),e.consume(d),e.exit("characterReferenceMarker"),c}function c(d){return d===35?(e.enter("characterReferenceMarkerNumeric"),e.consume(d),e.exit("characterReferenceMarkerNumeric"),u):(e.enter("characterReferenceValue"),l=31,s=xe,p(d))}function u(d){return d===88||d===120?(e.enter("characterReferenceMarkerHexadecimal"),e.consume(d),e.exit("characterReferenceMarkerHexadecimal"),e.enter("characterReferenceValue"),l=6,s=za,p):(e.enter("characterReferenceValue"),l=7,s=Hn,p(d))}function p(d){if(d===59&&o){const h=e.exit("characterReferenceValue");return s===xe&&!sr(r.sliceSerialize(h))?n(d):(e.enter("characterReferenceMarker"),e.consume(d),e.exit("characterReferenceMarker"),e.exit("characterReference"),t)}return s(d)&&o++<l?(e.consume(d),p):n(d)}}const qr={partial:!0,tokenize:Ga},Yr={concrete:!0,name:"codeFenced",tokenize:Ya};function Ya(e,t,n){const r=this,o={partial:!0,tokenize:I};let l=0,s=0,a;return c;function c(S){return u(S)}function u(S){const T=r.events[r.events.length-1];return l=T&&T[1].type==="linePrefix"?T[2].sliceSerialize(T[1],!0).length:0,a=S,e.enter("codeFenced"),e.enter("codeFencedFence"),e.enter("codeFencedFenceSequence"),p(S)}function p(S){return S===a?(s++,e.consume(S),p):s<3?n(S):(e.exit("codeFencedFenceSequence"),J(S)?te(e,d,"whitespace")(S):d(S))}function d(S){return S===null||H(S)?(e.exit("codeFencedFence"),r.interrupt?t(S):e.check(qr,b,_)(S)):(e.enter("codeFencedFenceInfo"),e.enter("chunkString",{contentType:"string"}),h(S))}function h(S){return S===null||H(S)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),d(S)):J(S)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),te(e,f,"whitespace")(S)):S===96&&S===a?n(S):(e.consume(S),h)}function f(S){return S===null||H(S)?d(S):(e.enter("codeFencedFenceMeta"),e.enter("chunkString",{contentType:"string"}),g(S))}function g(S){return S===null||H(S)?(e.exit("chunkString"),e.exit("codeFencedFenceMeta"),d(S)):S===96&&S===a?n(S):(e.consume(S),g)}function b(S){return e.attempt(o,_,x)(S)}function x(S){return e.enter("lineEnding"),e.consume(S),e.exit("lineEnding"),m}function m(S){return l>0&&J(S)?te(e,k,"linePrefix",l+1)(S):k(S)}function k(S){return S===null||H(S)?e.check(qr,b,_)(S):(e.enter("codeFlowValue"),w(S))}function w(S){return S===null||H(S)?(e.exit("codeFlowValue"),k(S)):(e.consume(S),w)}function _(S){return e.exit("codeFenced"),t(S)}function I(S,T,z){let B=0;return C;function C(L){return S.enter("lineEnding"),S.consume(L),S.exit("lineEnding"),E}function E(L){return S.enter("codeFencedFence"),J(L)?te(S,A,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(L):A(L)}function A(L){return L===a?(S.enter("codeFencedFenceSequence"),$(L)):z(L)}function $(L){return L===a?(B++,S.consume(L),$):B>=s?(S.exit("codeFencedFenceSequence"),J(L)?te(S,P,"whitespace")(L):P(L)):z(L)}function P(L){return L===null||H(L)?(S.exit("codeFencedFence"),T(L)):z(L)}}}function Ga(e,t,n){const r=this;return o;function o(s){return s===null?n(s):(e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),l)}function l(s){return r.parser.lazy[r.now().line]?n(s):t(s)}}const yn={name:"codeIndented",tokenize:Xa},Ka={partial:!0,tokenize:Ja};function Xa(e,t,n){const r=this;return o;function o(u){return e.enter("codeIndented"),te(e,l,"linePrefix",5)(u)}function l(u){const p=r.events[r.events.length-1];return p&&p[1].type==="linePrefix"&&p[2].sliceSerialize(p[1],!0).length>=4?s(u):n(u)}function s(u){return u===null?c(u):H(u)?e.attempt(Ka,s,c)(u):(e.enter("codeFlowValue"),a(u))}function a(u){return u===null||H(u)?(e.exit("codeFlowValue"),s(u)):(e.consume(u),a)}function c(u){return e.exit("codeIndented"),t(u)}}function Ja(e,t,n){const r=this;return o;function o(s){return r.parser.lazy[r.now().line]?n(s):H(s)?(e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),o):te(e,l,"linePrefix",5)(s)}function l(s){const a=r.events[r.events.length-1];return a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?t(s):H(s)?o(s):n(s)}}const Za={name:"codeText",previous:ec,resolve:Qa,tokenize:tc};function Qa(e){let t=e.length-4,n=3,r,o;if((e[n][1].type==="lineEnding"||e[n][1].type==="space")&&(e[t][1].type==="lineEnding"||e[t][1].type==="space")){for(r=n;++r<t;)if(e[r][1].type==="codeTextData"){e[n][1].type="codeTextPadding",e[t][1].type="codeTextPadding",n+=2,t-=2;break}}for(r=n-1,t++;++r<=t;)o===void 0?r!==t&&e[r][1].type!=="lineEnding"&&(o=r):(r===t||e[r][1].type==="lineEnding")&&(e[o][1].type="codeTextData",r!==o+2&&(e[o][1].end=e[r-1][1].end,e.splice(o+2,r-o-2),t-=r-o-2,r=o+2),o=void 0);return e}function ec(e){return e!==96||this.events[this.events.length-1][1].type==="characterEscape"}function tc(e,t,n){let r=0,o,l;return s;function s(d){return e.enter("codeText"),e.enter("codeTextSequence"),a(d)}function a(d){return d===96?(e.consume(d),r++,a):(e.exit("codeTextSequence"),c(d))}function c(d){return d===null?n(d):d===32?(e.enter("space"),e.consume(d),e.exit("space"),c):d===96?(l=e.enter("codeTextSequence"),o=0,p(d)):H(d)?(e.enter("lineEnding"),e.consume(d),e.exit("lineEnding"),c):(e.enter("codeTextData"),u(d))}function u(d){return d===null||d===32||d===96||H(d)?(e.exit("codeTextData"),c(d)):(e.consume(d),u)}function p(d){return d===96?(e.consume(d),o++,p):o===r?(e.exit("codeTextSequence"),e.exit("codeText"),t(d)):(l.type="codeTextData",u(d))}}class nc{constructor(t){this.left=t?[...t]:[],this.right=[]}get(t){if(t<0||t>=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+t+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return t<this.left.length?this.left[t]:this.right[this.right.length-t+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(t,n){const r=n??Number.POSITIVE_INFINITY;return r<this.left.length?this.left.slice(t,r):t>this.left.length?this.right.slice(this.right.length-r+this.left.length,this.right.length-t+this.left.length).reverse():this.left.slice(t).concat(this.right.slice(this.right.length-r+this.left.length).reverse())}splice(t,n,r){const o=n||0;this.setCursor(Math.trunc(t));const l=this.right.splice(this.right.length-o,Number.POSITIVE_INFINITY);return r&&Et(this.left,r),l.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(t){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(t)}pushMany(t){this.setCursor(Number.POSITIVE_INFINITY),Et(this.left,t)}unshift(t){this.setCursor(0),this.right.push(t)}unshiftMany(t){this.setCursor(0),Et(this.right,t.reverse())}setCursor(t){if(!(t===this.left.length||t>this.left.length&&this.right.length===0||t<0&&this.left.length===0))if(t<this.left.length){const n=this.left.splice(t,Number.POSITIVE_INFINITY);Et(this.right,n.reverse())}else{const n=this.right.splice(this.left.length+this.right.length-t,Number.POSITIVE_INFINITY);Et(this.left,n.reverse())}}}function Et(e,t){let n=0;if(t.length<1e4)e.push(...t);else for(;n<t.length;)e.push(...t.slice(n,n+1e4)),n+=1e4}function Io(e){const t={};let n=-1,r,o,l,s,a,c,u;const p=new nc(e);for(;++n<p.length;){for(;n in t;)n=t[n];if(r=p.get(n),n&&r[1].type==="chunkFlow"&&p.get(n-1)[1].type==="listItemPrefix"&&(c=r[1]._tokenizer.events,l=0,l<c.length&&c[l][1].type==="lineEndingBlank"&&(l+=2),l<c.length&&c[l][1].type==="content"))for(;++l<c.length&&c[l][1].type!=="content";)c[l][1].type==="chunkText"&&(c[l][1]._isInFirstContentOfListItem=!0,l++);if(r[0]==="enter")r[1].contentType&&(Object.assign(t,rc(p,n)),n=t[n],u=!0);else if(r[1]._container){for(l=n,o=void 0;l--;)if(s=p.get(l),s[1].type==="lineEnding"||s[1].type==="lineEndingBlank")s[0]==="enter"&&(o&&(p.get(o)[1].type="lineEndingBlank"),s[1].type="lineEnding",o=l);else if(!(s[1].type==="linePrefix"||s[1].type==="listItemIndent"))break;o&&(r[1].end={...p.get(o)[1].start},a=p.slice(o,n),a.unshift(r),p.splice(o,n-o+1,a))}}return Ee(e,0,Number.POSITIVE_INFINITY,p.slice(0)),!u}function rc(e,t){const n=e.get(t)[1],r=e.get(t)[2];let o=t-1;const l=[];let s=n._tokenizer;s||(s=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(s._contentTypeTextTrailing=!0));const a=s.events,c=[],u={};let p,d,h=-1,f=n,g=0,b=0;const x=[b];for(;f;){for(;e.get(++o)[1]!==f;);l.push(o),f._tokenizer||(p=r.sliceStream(f),f.next||p.push(null),d&&s.defineSkip(f.start),f._isInFirstContentOfListItem&&(s._gfmTasklistFirstContentOfListItem=!0),s.write(p),f._isInFirstContentOfListItem&&(s._gfmTasklistFirstContentOfListItem=void 0)),d=f,f=f.next}for(f=n;++h<a.length;)a[h][0]==="exit"&&a[h-1][0]==="enter"&&a[h][1].type===a[h-1][1].type&&a[h][1].start.line!==a[h][1].end.line&&(b=h+1,x.push(b),f._tokenizer=void 0,f.previous=void 0,f=f.next);for(s.events=[],f?(f._tokenizer=void 0,f.previous=void 0):x.pop(),h=x.length;h--;){const m=a.slice(x[h],x[h+1]),k=l.pop();c.push([k,k+m.length-1]),e.splice(k,2,m)}for(c.reverse(),h=-1;++h<c.length;)u[g+c[h][0]]=g+c[h][1],g+=c[h][1]-c[h][0]-1;return u}const ic={resolve:lc,tokenize:sc},oc={partial:!0,tokenize:ac};function lc(e){return Io(e),e}function sc(e,t){let n;return r;function r(a){return e.enter("content"),n=e.enter("chunkContent",{contentType:"content"}),o(a)}function o(a){return a===null?l(a):H(a)?e.check(oc,s,l)(a):(e.consume(a),o)}function l(a){return e.exit("chunkContent"),e.exit("content"),t(a)}function s(a){return e.consume(a),e.exit("chunkContent"),n.next=e.enter("chunkContent",{contentType:"content",previous:n}),n=n.next,o}}function ac(e,t,n){const r=this;return o;function o(s){return e.exit("chunkContent"),e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),te(e,l,"linePrefix")}function l(s){if(s===null||H(s))return n(s);const a=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes("codeIndented")&&a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?t(s):e.interrupt(r.parser.constructs.flow,n,t)(s)}}function Eo(e,t,n,r,o,l,s,a,c){const u=c||Number.POSITIVE_INFINITY;let p=0;return d;function d(m){return m===60?(e.enter(r),e.enter(o),e.enter(l),e.consume(m),e.exit(l),h):m===null||m===32||m===41||nn(m)?n(m):(e.enter(r),e.enter(s),e.enter(a),e.enter("chunkString",{contentType:"string"}),b(m))}function h(m){return m===62?(e.enter(l),e.consume(m),e.exit(l),e.exit(o),e.exit(r),t):(e.enter(a),e.enter("chunkString",{contentType:"string"}),f(m))}function f(m){return m===62?(e.exit("chunkString"),e.exit(a),h(m)):m===null||m===60||H(m)?n(m):(e.consume(m),m===92?g:f)}function g(m){return m===60||m===62||m===92?(e.consume(m),f):f(m)}function b(m){return!p&&(m===null||m===41||le(m))?(e.exit("chunkString"),e.exit(a),e.exit(s),e.exit(r),t(m)):p<u&&m===40?(e.consume(m),p++,b):m===41?(e.consume(m),p--,b):m===null||m===32||m===40||nn(m)?n(m):(e.consume(m),m===92?x:b)}function x(m){return m===40||m===41||m===92?(e.consume(m),b):b(m)}}function To(e,t,n,r,o,l){const s=this;let a=0,c;return u;function u(f){return e.enter(r),e.enter(o),e.consume(f),e.exit(o),e.enter(l),p}function p(f){return a>999||f===null||f===91||f===93&&!c||f===94&&!a&&"_hiddenFootnoteSupport"in s.parser.constructs?n(f):f===93?(e.exit(l),e.enter(o),e.consume(f),e.exit(o),e.exit(r),t):H(f)?(e.enter("lineEnding"),e.consume(f),e.exit("lineEnding"),p):(e.enter("chunkString",{contentType:"string"}),d(f))}function d(f){return f===null||f===91||f===93||H(f)||a++>999?(e.exit("chunkString"),p(f)):(e.consume(f),c||(c=!J(f)),f===92?h:d)}function h(f){return f===91||f===92||f===93?(e.consume(f),a++,d):d(f)}}function _o(e,t,n,r,o,l){let s;return a;function a(h){return h===34||h===39||h===40?(e.enter(r),e.enter(o),e.consume(h),e.exit(o),s=h===40?41:h,c):n(h)}function c(h){return h===s?(e.enter(o),e.consume(h),e.exit(o),e.exit(r),t):(e.enter(l),u(h))}function u(h){return h===s?(e.exit(l),c(s)):h===null?n(h):H(h)?(e.enter("lineEnding"),e.consume(h),e.exit("lineEnding"),te(e,u,"linePrefix")):(e.enter("chunkString",{contentType:"string"}),p(h))}function p(h){return h===s||h===null||H(h)?(e.exit("chunkString"),u(h)):(e.consume(h),h===92?d:p)}function d(h){return h===s||h===92?(e.consume(h),p):p(h)}}function Pt(e,t){let n;return r;function r(o){return H(o)?(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),n=!0,r):J(o)?te(e,r,n?"linePrefix":"lineSuffix")(o):t(o)}}const cc={name:"definition",tokenize:dc},uc={partial:!0,tokenize:pc};function dc(e,t,n){const r=this;let o;return l;function l(f){return e.enter("definition"),s(f)}function s(f){return To.call(r,e,a,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(f)}function a(f){return o=Pe(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),f===58?(e.enter("definitionMarker"),e.consume(f),e.exit("definitionMarker"),c):n(f)}function c(f){return le(f)?Pt(e,u)(f):u(f)}function u(f){return Eo(e,p,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(f)}function p(f){return e.attempt(uc,d,d)(f)}function d(f){return J(f)?te(e,h,"whitespace")(f):h(f)}function h(f){return f===null||H(f)?(e.exit("definition"),r.parser.defined.push(o),t(f)):n(f)}}function pc(e,t,n){return r;function r(a){return le(a)?Pt(e,o)(a):n(a)}function o(a){return _o(e,l,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(a)}function l(a){return J(a)?te(e,s,"whitespace")(a):s(a)}function s(a){return a===null||H(a)?t(a):n(a)}}const fc={name:"hardBreakEscape",tokenize:hc};function hc(e,t,n){return r;function r(l){return e.enter("hardBreakEscape"),e.consume(l),o}function o(l){return H(l)?(e.exit("hardBreakEscape"),t(l)):n(l)}}const gc={name:"headingAtx",resolve:xc,tokenize:mc};function xc(e,t){let n=e.length-2,r=3,o,l;return e[r][1].type==="whitespace"&&(r+=2),n-2>r&&e[n][1].type==="whitespace"&&(n-=2),e[n][1].type==="atxHeadingSequence"&&(r===n-1||n-4>r&&e[n-2][1].type==="whitespace")&&(n-=r+1===n?2:4),n>r&&(o={type:"atxHeadingText",start:e[r][1].start,end:e[n][1].end},l={type:"chunkText",start:e[r][1].start,end:e[n][1].end,contentType:"text"},Ee(e,r,n-r+1,[["enter",o,t],["enter",l,t],["exit",l,t],["exit",o,t]])),e}function mc(e,t,n){let r=0;return o;function o(p){return e.enter("atxHeading"),l(p)}function l(p){return e.enter("atxHeadingSequence"),s(p)}function s(p){return p===35&&r++<6?(e.consume(p),s):p===null||le(p)?(e.exit("atxHeadingSequence"),a(p)):n(p)}function a(p){return p===35?(e.enter("atxHeadingSequence"),c(p)):p===null||H(p)?(e.exit("atxHeading"),t(p)):J(p)?te(e,a,"whitespace")(p):(e.enter("atxHeadingText"),u(p))}function c(p){return p===35?(e.consume(p),c):(e.exit("atxHeadingSequence"),a(p))}function u(p){return p===null||p===35||le(p)?(e.exit("atxHeadingText"),a(p)):(e.consume(p),u)}}const bc=["address","article","aside","base","basefont","blockquote","body","caption","center","col","colgroup","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],Gr=["pre","script","style","textarea"],yc={concrete:!0,name:"htmlFlow",resolveTo:Sc,tokenize:wc},kc={partial:!0,tokenize:Cc},vc={partial:!0,tokenize:jc};function Sc(e){let t=e.length;for(;t--&&!(e[t][0]==="enter"&&e[t][1].type==="htmlFlow"););return t>1&&e[t-2][1].type==="linePrefix"&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function wc(e,t,n){const r=this;let o,l,s,a,c;return u;function u(j){return p(j)}function p(j){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(j),d}function d(j){return j===33?(e.consume(j),h):j===47?(e.consume(j),l=!0,b):j===63?(e.consume(j),o=3,r.interrupt?t:y):ve(j)?(e.consume(j),s=String.fromCharCode(j),x):n(j)}function h(j){return j===45?(e.consume(j),o=2,f):j===91?(e.consume(j),o=5,a=0,g):ve(j)?(e.consume(j),o=4,r.interrupt?t:y):n(j)}function f(j){return j===45?(e.consume(j),r.interrupt?t:y):n(j)}function g(j){const ce="CDATA[";return j===ce.charCodeAt(a++)?(e.consume(j),a===ce.length?r.interrupt?t:A:g):n(j)}function b(j){return ve(j)?(e.consume(j),s=String.fromCharCode(j),x):n(j)}function x(j){if(j===null||j===47||j===62||le(j)){const ce=j===47,be=s.toLowerCase();return!ce&&!l&&Gr.includes(be)?(o=1,r.interrupt?t(j):A(j)):bc.includes(s.toLowerCase())?(o=6,ce?(e.consume(j),m):r.interrupt?t(j):A(j)):(o=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(j):l?k(j):w(j))}return j===45||xe(j)?(e.consume(j),s+=String.fromCharCode(j),x):n(j)}function m(j){return j===62?(e.consume(j),r.interrupt?t:A):n(j)}function k(j){return J(j)?(e.consume(j),k):C(j)}function w(j){return j===47?(e.consume(j),C):j===58||j===95||ve(j)?(e.consume(j),_):J(j)?(e.consume(j),w):C(j)}function _(j){return j===45||j===46||j===58||j===95||xe(j)?(e.consume(j),_):I(j)}function I(j){return j===61?(e.consume(j),S):J(j)?(e.consume(j),I):w(j)}function S(j){return j===null||j===60||j===61||j===62||j===96?n(j):j===34||j===39?(e.consume(j),c=j,T):J(j)?(e.consume(j),S):z(j)}function T(j){return j===c?(e.consume(j),c=null,B):j===null||H(j)?n(j):(e.consume(j),T)}function z(j){return j===null||j===34||j===39||j===47||j===60||j===61||j===62||j===96||le(j)?I(j):(e.consume(j),z)}function B(j){return j===47||j===62||J(j)?w(j):n(j)}function C(j){return j===62?(e.consume(j),E):n(j)}function E(j){return j===null||H(j)?A(j):J(j)?(e.consume(j),E):n(j)}function A(j){return j===45&&o===2?(e.consume(j),N):j===60&&o===1?(e.consume(j),M):j===62&&o===4?(e.consume(j),q):j===63&&o===3?(e.consume(j),y):j===93&&o===5?(e.consume(j),U):H(j)&&(o===6||o===7)?(e.exit("htmlFlowData"),e.check(kc,Z,$)(j)):j===null||H(j)?(e.exit("htmlFlowData"),$(j)):(e.consume(j),A)}function $(j){return e.check(vc,P,Z)(j)}function P(j){return e.enter("lineEnding"),e.consume(j),e.exit("lineEnding"),L}function L(j){return j===null||H(j)?$(j):(e.enter("htmlFlowData"),A(j))}function N(j){return j===45?(e.consume(j),y):A(j)}function M(j){return j===47?(e.consume(j),s="",D):A(j)}function D(j){if(j===62){const ce=s.toLowerCase();return Gr.includes(ce)?(e.consume(j),q):A(j)}return ve(j)&&s.length<8?(e.consume(j),s+=String.fromCharCode(j),D):A(j)}function U(j){return j===93?(e.consume(j),y):A(j)}function y(j){return j===62?(e.consume(j),q):j===45&&o===2?(e.consume(j),y):A(j)}function q(j){return j===null||H(j)?(e.exit("htmlFlowData"),Z(j)):(e.consume(j),q)}function Z(j){return e.exit("htmlFlow"),t(j)}}function jc(e,t,n){const r=this;return o;function o(s){return H(s)?(e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),l):n(s)}function l(s){return r.parser.lazy[r.now().line]?n(s):t(s)}}function Cc(e,t,n){return r;function r(o){return e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),e.attempt(Ut,t,n)}}const Ic={name:"htmlText",tokenize:Ec};function Ec(e,t,n){const r=this;let o,l,s;return a;function a(y){return e.enter("htmlText"),e.enter("htmlTextData"),e.consume(y),c}function c(y){return y===33?(e.consume(y),u):y===47?(e.consume(y),I):y===63?(e.consume(y),w):ve(y)?(e.consume(y),z):n(y)}function u(y){return y===45?(e.consume(y),p):y===91?(e.consume(y),l=0,g):ve(y)?(e.consume(y),k):n(y)}function p(y){return y===45?(e.consume(y),f):n(y)}function d(y){return y===null?n(y):y===45?(e.consume(y),h):H(y)?(s=d,M(y)):(e.consume(y),d)}function h(y){return y===45?(e.consume(y),f):d(y)}function f(y){return y===62?N(y):y===45?h(y):d(y)}function g(y){const q="CDATA[";return y===q.charCodeAt(l++)?(e.consume(y),l===q.length?b:g):n(y)}function b(y){return y===null?n(y):y===93?(e.consume(y),x):H(y)?(s=b,M(y)):(e.consume(y),b)}function x(y){return y===93?(e.consume(y),m):b(y)}function m(y){return y===62?N(y):y===93?(e.consume(y),m):b(y)}function k(y){return y===null||y===62?N(y):H(y)?(s=k,M(y)):(e.consume(y),k)}function w(y){return y===null?n(y):y===63?(e.consume(y),_):H(y)?(s=w,M(y)):(e.consume(y),w)}function _(y){return y===62?N(y):w(y)}function I(y){return ve(y)?(e.consume(y),S):n(y)}function S(y){return y===45||xe(y)?(e.consume(y),S):T(y)}function T(y){return H(y)?(s=T,M(y)):J(y)?(e.consume(y),T):N(y)}function z(y){return y===45||xe(y)?(e.consume(y),z):y===47||y===62||le(y)?B(y):n(y)}function B(y){return y===47?(e.consume(y),N):y===58||y===95||ve(y)?(e.consume(y),C):H(y)?(s=B,M(y)):J(y)?(e.consume(y),B):N(y)}function C(y){return y===45||y===46||y===58||y===95||xe(y)?(e.consume(y),C):E(y)}function E(y){return y===61?(e.consume(y),A):H(y)?(s=E,M(y)):J(y)?(e.consume(y),E):B(y)}function A(y){return y===null||y===60||y===61||y===62||y===96?n(y):y===34||y===39?(e.consume(y),o=y,$):H(y)?(s=A,M(y)):J(y)?(e.consume(y),A):(e.consume(y),P)}function $(y){return y===o?(e.consume(y),o=void 0,L):y===null?n(y):H(y)?(s=$,M(y)):(e.consume(y),$)}function P(y){return y===null||y===34||y===39||y===60||y===61||y===96?n(y):y===47||y===62||le(y)?B(y):(e.consume(y),P)}function L(y){return y===47||y===62||le(y)?B(y):n(y)}function N(y){return y===62?(e.consume(y),e.exit("htmlTextData"),e.exit("htmlText"),t):n(y)}function M(y){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(y),e.exit("lineEnding"),D}function D(y){return J(y)?te(e,U,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(y):U(y)}function U(y){return e.enter("htmlTextData"),s(y)}}const ar={name:"labelEnd",resolveAll:Rc,resolveTo:Lc,tokenize:Ac},Tc={tokenize:Bc},_c={tokenize:Pc},zc={tokenize:Fc};function Rc(e){let t=-1;const n=[];for(;++t<e.length;){const r=e[t][1];if(n.push(e[t]),r.type==="labelImage"||r.type==="labelLink"||r.type==="labelEnd"){const o=r.type==="labelImage"?4:2;r.type="data",t+=o}}return e.length!==n.length&&Ee(e,0,e.length,n),e}function Lc(e,t){let n=e.length,r=0,o,l,s,a;for(;n--;)if(o=e[n][1],l){if(o.type==="link"||o.type==="labelLink"&&o._inactive)break;e[n][0]==="enter"&&o.type==="labelLink"&&(o._inactive=!0)}else if(s){if(e[n][0]==="enter"&&(o.type==="labelImage"||o.type==="labelLink")&&!o._balanced&&(l=n,o.type!=="labelLink")){r=2;break}}else o.type==="labelEnd"&&(s=n);const c={type:e[l][1].type==="labelLink"?"link":"image",start:{...e[l][1].start},end:{...e[e.length-1][1].end}},u={type:"label",start:{...e[l][1].start},end:{...e[s][1].end}},p={type:"labelText",start:{...e[l+r+2][1].end},end:{...e[s-2][1].start}};return a=[["enter",c,t],["enter",u,t]],a=ze(a,e.slice(l+1,l+r+3)),a=ze(a,[["enter",p,t]]),a=ze(a,dn(t.parser.constructs.insideSpan.null,e.slice(l+r+4,s-3),t)),a=ze(a,[["exit",p,t],e[s-2],e[s-1],["exit",u,t]]),a=ze(a,e.slice(s+1)),a=ze(a,[["exit",c,t]]),Ee(e,l,e.length,a),e}function Ac(e,t,n){const r=this;let o=r.events.length,l,s;for(;o--;)if((r.events[o][1].type==="labelImage"||r.events[o][1].type==="labelLink")&&!r.events[o][1]._balanced){l=r.events[o][1];break}return a;function a(h){return l?l._inactive?d(h):(s=r.parser.defined.includes(Pe(r.sliceSerialize({start:l.end,end:r.now()}))),e.enter("labelEnd"),e.enter("labelMarker"),e.consume(h),e.exit("labelMarker"),e.exit("labelEnd"),c):n(h)}function c(h){return h===40?e.attempt(Tc,p,s?p:d)(h):h===91?e.attempt(_c,p,s?u:d)(h):s?p(h):d(h)}function u(h){return e.attempt(zc,p,d)(h)}function p(h){return t(h)}function d(h){return l._balanced=!0,n(h)}}function Bc(e,t,n){return r;function r(d){return e.enter("resource"),e.enter("resourceMarker"),e.consume(d),e.exit("resourceMarker"),o}function o(d){return le(d)?Pt(e,l)(d):l(d)}function l(d){return d===41?p(d):Eo(e,s,a,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(d)}function s(d){return le(d)?Pt(e,c)(d):p(d)}function a(d){return n(d)}function c(d){return d===34||d===39||d===40?_o(e,u,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(d):p(d)}function u(d){return le(d)?Pt(e,p)(d):p(d)}function p(d){return d===41?(e.enter("resourceMarker"),e.consume(d),e.exit("resourceMarker"),e.exit("resource"),t):n(d)}}function Pc(e,t,n){const r=this;return o;function o(a){return To.call(r,e,l,s,"reference","referenceMarker","referenceString")(a)}function l(a){return r.parser.defined.includes(Pe(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(a):n(a)}function s(a){return n(a)}}function Fc(e,t,n){return r;function r(l){return e.enter("reference"),e.enter("referenceMarker"),e.consume(l),e.exit("referenceMarker"),o}function o(l){return l===93?(e.enter("referenceMarker"),e.consume(l),e.exit("referenceMarker"),e.exit("reference"),t):n(l)}}const Dc={name:"labelStartImage",resolveAll:ar.resolveAll,tokenize:Mc};function Mc(e,t,n){const r=this;return o;function o(a){return e.enter("labelImage"),e.enter("labelImageMarker"),e.consume(a),e.exit("labelImageMarker"),l}function l(a){return a===91?(e.enter("labelMarker"),e.consume(a),e.exit("labelMarker"),e.exit("labelImage"),s):n(a)}function s(a){return a===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(a):t(a)}}const Oc={name:"labelStartLink",resolveAll:ar.resolveAll,tokenize:Wc};function Wc(e,t,n){const r=this;return o;function o(s){return e.enter("labelLink"),e.enter("labelMarker"),e.consume(s),e.exit("labelMarker"),e.exit("labelLink"),l}function l(s){return s===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(s):t(s)}}const kn={name:"lineEnding",tokenize:$c};function $c(e,t){return n;function n(r){return e.enter("lineEnding"),e.consume(r),e.exit("lineEnding"),te(e,t,"linePrefix")}}const en={name:"thematicBreak",tokenize:Nc};function Nc(e,t,n){let r=0,o;return l;function l(u){return e.enter("thematicBreak"),s(u)}function s(u){return o=u,a(u)}function a(u){return u===o?(e.enter("thematicBreakSequence"),c(u)):r>=3&&(u===null||H(u))?(e.exit("thematicBreak"),t(u)):n(u)}function c(u){return u===o?(e.consume(u),r++,c):(e.exit("thematicBreakSequence"),J(u)?te(e,a,"whitespace")(u):a(u))}}const Se={continuation:{tokenize:qc},exit:Gc,name:"list",tokenize:Vc},Hc={partial:!0,tokenize:Kc},Uc={partial:!0,tokenize:Yc};function Vc(e,t,n){const r=this,o=r.events[r.events.length-1];let l=o&&o[1].type==="linePrefix"?o[2].sliceSerialize(o[1],!0).length:0,s=0;return a;function a(f){const g=r.containerState.type||(f===42||f===43||f===45?"listUnordered":"listOrdered");if(g==="listUnordered"?!r.containerState.marker||f===r.containerState.marker:Hn(f)){if(r.containerState.type||(r.containerState.type=g,e.enter(g,{_container:!0})),g==="listUnordered")return e.enter("listItemPrefix"),f===42||f===45?e.check(en,n,u)(f):u(f);if(!r.interrupt||f===49)return e.enter("listItemPrefix"),e.enter("listItemValue"),c(f)}return n(f)}function c(f){return Hn(f)&&++s<10?(e.consume(f),c):(!r.interrupt||s<2)&&(r.containerState.marker?f===r.containerState.marker:f===41||f===46)?(e.exit("listItemValue"),u(f)):n(f)}function u(f){return e.enter("listItemMarker"),e.consume(f),e.exit("listItemMarker"),r.containerState.marker=r.containerState.marker||f,e.check(Ut,r.interrupt?n:p,e.attempt(Hc,h,d))}function p(f){return r.containerState.initialBlankLine=!0,l++,h(f)}function d(f){return J(f)?(e.enter("listItemPrefixWhitespace"),e.consume(f),e.exit("listItemPrefixWhitespace"),h):n(f)}function h(f){return r.containerState.size=l+r.sliceSerialize(e.exit("listItemPrefix"),!0).length,t(f)}}function qc(e,t,n){const r=this;return r.containerState._closeFlow=void 0,e.check(Ut,o,l);function o(a){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,te(e,t,"listItemIndent",r.containerState.size+1)(a)}function l(a){return r.containerState.furtherBlankLines||!J(a)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,s(a)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(Uc,t,s)(a))}function s(a){return r.containerState._closeFlow=!0,r.interrupt=void 0,te(e,e.attempt(Se,t,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(a)}}function Yc(e,t,n){const r=this;return te(e,o,"listItemIndent",r.containerState.size+1);function o(l){const s=r.events[r.events.length-1];return s&&s[1].type==="listItemIndent"&&s[2].sliceSerialize(s[1],!0).length===r.containerState.size?t(l):n(l)}}function Gc(e){e.exit(this.containerState.type)}function Kc(e,t,n){const r=this;return te(e,o,"listItemPrefixWhitespace",r.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function o(l){const s=r.events[r.events.length-1];return!J(l)&&s&&s[1].type==="listItemPrefixWhitespace"?t(l):n(l)}}const Kr={name:"setextUnderline",resolveTo:Xc,tokenize:Jc};function Xc(e,t){let n=e.length,r,o,l;for(;n--;)if(e[n][0]==="enter"){if(e[n][1].type==="content"){r=n;break}e[n][1].type==="paragraph"&&(o=n)}else e[n][1].type==="content"&&e.splice(n,1),!l&&e[n][1].type==="definition"&&(l=n);const s={type:"setextHeading",start:{...e[r][1].start},end:{...e[e.length-1][1].end}};return e[o][1].type="setextHeadingText",l?(e.splice(o,0,["enter",s,t]),e.splice(l+1,0,["exit",e[r][1],t]),e[r][1].end={...e[l][1].end}):e[r][1]=s,e.push(["exit",s,t]),e}function Jc(e,t,n){const r=this;let o;return l;function l(u){let p=r.events.length,d;for(;p--;)if(r.events[p][1].type!=="lineEnding"&&r.events[p][1].type!=="linePrefix"&&r.events[p][1].type!=="content"){d=r.events[p][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||d)?(e.enter("setextHeadingLine"),o=u,s(u)):n(u)}function s(u){return e.enter("setextHeadingLineSequence"),a(u)}function a(u){return u===o?(e.consume(u),a):(e.exit("setextHeadingLineSequence"),J(u)?te(e,c,"lineSuffix")(u):c(u))}function c(u){return u===null||H(u)?(e.exit("setextHeadingLine"),t(u)):n(u)}}const Zc={tokenize:Qc};function Qc(e){const t=this,n=e.attempt(Ut,r,e.attempt(this.parser.constructs.flowInitial,o,te(e,e.attempt(this.parser.constructs.flow,o,e.attempt(ic,o)),"linePrefix")));return n;function r(l){if(l===null){e.consume(l);return}return e.enter("lineEndingBlank"),e.consume(l),e.exit("lineEndingBlank"),t.currentConstruct=void 0,n}function o(l){if(l===null){e.consume(l);return}return e.enter("lineEnding"),e.consume(l),e.exit("lineEnding"),t.currentConstruct=void 0,n}}const eu={resolveAll:Ro()},tu=zo("string"),nu=zo("text");function zo(e){return{resolveAll:Ro(e==="text"?ru:void 0),tokenize:t};function t(n){const r=this,o=this.parser.constructs[e],l=n.attempt(o,s,a);return s;function s(p){return u(p)?l(p):a(p)}function a(p){if(p===null){n.consume(p);return}return n.enter("data"),n.consume(p),c}function c(p){return u(p)?(n.exit("data"),l(p)):(n.consume(p),c)}function u(p){if(p===null)return!0;const d=o[p];let h=-1;if(d)for(;++h<d.length;){const f=d[h];if(!f.previous||f.previous.call(r,r.previous))return!0}return!1}}}function Ro(e){return t;function t(n,r){let o=-1,l;for(;++o<=n.length;)l===void 0?n[o]&&n[o][1].type==="data"&&(l=o,o++):(!n[o]||n[o][1].type!=="data")&&(o!==l+2&&(n[l][1].end=n[o-1][1].end,n.splice(l+2,o-l-2),o=l+2),l=void 0);return e?e(n,r):n}}function ru(e,t){let n=0;for(;++n<=e.length;)if((n===e.length||e[n][1].type==="lineEnding")&&e[n-1][1].type==="data"){const r=e[n-1][1],o=t.sliceStream(r);let l=o.length,s=-1,a=0,c;for(;l--;){const u=o[l];if(typeof u=="string"){for(s=u.length;u.charCodeAt(s-1)===32;)a++,s--;if(s)break;s=-1}else if(u===-2)c=!0,a++;else if(u!==-1){l++;break}}if(t._contentTypeTextTrailing&&n===e.length&&(a=0),a){const u={type:n===e.length||c||a<2?"lineSuffix":"hardBreakTrailing",start:{_bufferIndex:l?s:r.start._bufferIndex+s,_index:r.start._index+l,line:r.end.line,column:r.end.column-a,offset:r.end.offset-a},end:{...r.end}};r.end={...u.start},r.start.offset===r.end.offset?Object.assign(r,u):(e.splice(n,0,["enter",u,t],["exit",u,t]),n+=2)}n++}return e}const iu={42:Se,43:Se,45:Se,48:Se,49:Se,50:Se,51:Se,52:Se,53:Se,54:Se,55:Se,56:Se,57:Se,62:wo},ou={91:cc},lu={[-2]:yn,[-1]:yn,32:yn},su={35:gc,42:en,45:[Kr,en],60:yc,61:Kr,95:en,96:Yr,126:Yr},au={38:Co,92:jo},cu={[-5]:kn,[-4]:kn,[-3]:kn,33:Dc,38:Co,42:Un,60:[Oa,Ic],91:Oc,92:[fc,jo],93:ar,95:Un,96:Za},uu={null:[Un,eu]},du={null:[42,95]},pu={null:[]},fu=Object.freeze(Object.defineProperty({__proto__:null,attentionMarkers:du,contentInitial:ou,disable:pu,document:iu,flow:su,flowInitial:lu,insideSpan:uu,string:au,text:cu},Symbol.toStringTag,{value:"Module"}));function hu(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0};const o={},l=[];let s=[],a=[];const c={attempt:T(I),check:T(S),consume:k,enter:w,exit:_,interrupt:T(S,{interrupt:!0})},u={code:null,containerState:{},defineSkip:b,events:[],now:g,parser:e,previous:null,sliceSerialize:h,sliceStream:f,write:d};let p=t.tokenize.call(u,c);return t.resolveAll&&l.push(t),u;function d(E){return s=ze(s,E),x(),s[s.length-1]!==null?[]:(z(t,0),u.events=dn(l,u.events,u),u.events)}function h(E,A){return xu(f(E),A)}function f(E){return gu(s,E)}function g(){const{_bufferIndex:E,_index:A,line:$,column:P,offset:L}=r;return{_bufferIndex:E,_index:A,line:$,column:P,offset:L}}function b(E){o[E.line]=E.column,C()}function x(){let E;for(;r._index<s.length;){const A=s[r._index];if(typeof A=="string")for(E=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===E&&r._bufferIndex<A.length;)m(A.charCodeAt(r._bufferIndex));else m(A)}}function m(E){p=p(E)}function k(E){H(E)?(r.line++,r.column=1,r.offset+=E===-3?2:1,C()):E!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===s[r._index].length&&(r._bufferIndex=-1,r._index++)),u.previous=E}function w(E,A){const $=A||{};return $.type=E,$.start=g(),u.events.push(["enter",$,u]),a.push($),$}function _(E){const A=a.pop();return A.end=g(),u.events.push(["exit",A,u]),A}function I(E,A){z(E,A.from)}function S(E,A){A.restore()}function T(E,A){return $;function $(P,L,N){let M,D,U,y;return Array.isArray(P)?Z(P):"tokenize"in P?Z([P]):q(P);function q(se){return pe;function pe(re){const De=re!==null&&se[re],Me=re!==null&&se.null,Oe=[...Array.isArray(De)?De:De?[De]:[],...Array.isArray(Me)?Me:Me?[Me]:[]];return Z(Oe)(re)}}function Z(se){return M=se,D=0,se.length===0?N:j(se[D])}function j(se){return pe;function pe(re){return y=B(),U=se,se.partial||(u.currentConstruct=se),se.name&&u.parser.constructs.disable.null.includes(se.name)?be():se.tokenize.call(A?Object.assign(Object.create(u),A):u,c,ce,be)(re)}}function ce(se){return E(U,y),L}function be(se){return y.restore(),++D<M.length?j(M[D]):N}}}function z(E,A){E.resolveAll&&!l.includes(E)&&l.push(E),E.resolve&&Ee(u.events,A,u.events.length-A,E.resolve(u.events.slice(A),u)),E.resolveTo&&(u.events=E.resolveTo(u.events,u))}function B(){const E=g(),A=u.previous,$=u.currentConstruct,P=u.events.length,L=Array.from(a);return{from:P,restore:N};function N(){r=E,u.previous=A,u.currentConstruct=$,u.events.length=P,a=L,C()}}function C(){r.line in o&&r.column<2&&(r.column=o[r.line],r.offset+=o[r.line]-1)}}function gu(e,t){const n=t.start._index,r=t.start._bufferIndex,o=t.end._index,l=t.end._bufferIndex;let s;if(n===o)s=[e[n].slice(r,l)];else{if(s=e.slice(n,o),r>-1){const a=s[0];typeof a=="string"?s[0]=a.slice(r):s.shift()}l>0&&s.push(e[o].slice(0,l))}return s}function xu(e,t){let n=-1;const r=[];let o;for(;++n<e.length;){const l=e[n];let s;if(typeof l=="string")s=l;else switch(l){case-5:{s="\r";break}case-4:{s=`
3
- `;break}case-3:{s=`\r
4
- `;break}case-2:{s=t?" ":" ";break}case-1:{if(!t&&o)continue;s=" ";break}default:s=String.fromCharCode(l)}o=l===-2,r.push(s)}return r.join("")}function mu(e){const r={constructs:vo([fu,...(e||{}).extensions||[]]),content:o(La),defined:[],document:o(Ba),flow:o(Zc),lazy:{},string:o(tu),text:o(nu)};return r;function o(l){return s;function s(a){return hu(r,l,a)}}}function bu(e){for(;!Io(e););return e}const Xr=/[\0\t\n\r]/g;function yu(){let e=1,t="",n=!0,r;return o;function o(l,s,a){const c=[];let u,p,d,h,f;for(l=t+(typeof l=="string"?l.toString():new TextDecoder(s||void 0).decode(l)),d=0,t="",n&&(l.charCodeAt(0)===65279&&d++,n=void 0);d<l.length;){if(Xr.lastIndex=d,u=Xr.exec(l),h=u&&u.index!==void 0?u.index:l.length,f=l.charCodeAt(h),!u){t=l.slice(d);break}if(f===10&&d===h&&r)c.push(-3),r=void 0;else switch(r&&(c.push(-5),r=void 0),d<h&&(c.push(l.slice(d,h)),e+=h-d),f){case 0:{c.push(65533),e++;break}case 9:{for(p=Math.ceil(e/4)*4,c.push(-2);e++<p;)c.push(-1);break}case 10:{c.push(-4),e=1;break}default:r=!0,e=1}d=h+1}return a&&(r&&c.push(-5),t&&c.push(t),c.push(null)),c}}const ku=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function vu(e){return e.replace(ku,Su)}function Su(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){const o=n.charCodeAt(1),l=o===120||o===88;return So(n.slice(l?2:1),l?16:10)}return sr(n)||e}const Lo={}.hasOwnProperty;function wu(e,t,n){return t&&typeof t=="object"&&(n=t,t=void 0),ju(n)(bu(mu(n).document().write(yu()(e,t,!0))))}function ju(e){const t={transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:l(ue),autolinkProtocol:B,autolinkEmail:B,atxHeading:l(lt),blockQuote:l(Me),characterEscape:B,characterReference:B,codeFenced:l(Oe),codeFencedFenceInfo:s,codeFencedFenceMeta:s,codeIndented:l(Oe,s),codeText:l(Je,s),codeTextData:B,data:B,codeFlowValue:B,definition:l(yt),definitionDestinationString:s,definitionLabelString:s,definitionTitleString:s,emphasis:l(ot),hardBreakEscape:l(V),hardBreakTrailing:l(V),htmlFlow:l(de,s),htmlFlowData:B,htmlText:l(de,s),htmlTextData:B,image:l(ie),label:s,link:l(ue),listItem:l(W),listItemValue:h,listOrdered:l(he,d),listUnordered:l(he),paragraph:l(Q),reference:j,referenceString:s,resourceDestinationString:s,resourceTitleString:s,setextHeading:l(lt),strong:l(ye),thematicBreak:l(_e)},exit:{atxHeading:c(),atxHeadingSequence:I,autolink:c(),autolinkEmail:De,autolinkProtocol:re,blockQuote:c(),characterEscapeValue:C,characterReferenceMarkerHexadecimal:be,characterReferenceMarkerNumeric:be,characterReferenceValue:se,characterReference:pe,codeFenced:c(x),codeFencedFence:b,codeFencedFenceInfo:f,codeFencedFenceMeta:g,codeFlowValue:C,codeIndented:c(m),codeText:c(L),codeTextData:C,data:C,definition:c(),definitionDestinationString:_,definitionLabelString:k,definitionTitleString:w,emphasis:c(),hardBreakEscape:c(A),hardBreakTrailing:c(A),htmlFlow:c($),htmlFlowData:C,htmlText:c(P),htmlTextData:C,image:c(M),label:U,labelText:D,lineEnding:E,link:c(N),listItem:c(),listOrdered:c(),listUnordered:c(),paragraph:c(),referenceString:ce,resourceDestinationString:y,resourceTitleString:q,resource:Z,setextHeading:c(z),setextHeadingLineSequence:T,setextHeadingText:S,strong:c(),thematicBreak:c()}};Ao(t,(e||{}).mdastExtensions||[]);const n={};return r;function r(R){let O={type:"root",children:[]};const Y={stack:[O],tokenStack:[],config:t,enter:a,exit:u,buffer:s,resume:p,data:n},ee=[];let oe=-1;for(;++oe<R.length;)if(R[oe][1].type==="listOrdered"||R[oe][1].type==="listUnordered")if(R[oe][0]==="enter")ee.push(oe);else{const Le=ee.pop();oe=o(R,Le,oe)}for(oe=-1;++oe<R.length;){const Le=t[R[oe][0]];Lo.call(Le,R[oe][1].type)&&Le[R[oe][1].type].call(Object.assign({sliceSerialize:R[oe][2].sliceSerialize},Y),R[oe][1])}if(Y.tokenStack.length>0){const Le=Y.tokenStack[Y.tokenStack.length-1];(Le[1]||Jr).call(Y,void 0,Le[0])}for(O.position={start:Ke(R.length>0?R[0][1].start:{line:1,column:1,offset:0}),end:Ke(R.length>0?R[R.length-2][1].end:{line:1,column:1,offset:0})},oe=-1;++oe<t.transforms.length;)O=t.transforms[oe](O)||O;return O}function o(R,O,Y){let ee=O-1,oe=-1,Le=!1,Ze,Ue,kt,vt;for(;++ee<=Y;){const je=R[ee];switch(je[1].type){case"listUnordered":case"listOrdered":case"blockQuote":{je[0]==="enter"?oe++:oe--,vt=void 0;break}case"lineEndingBlank":{je[0]==="enter"&&(Ze&&!vt&&!oe&&!kt&&(kt=ee),vt=void 0);break}case"linePrefix":case"listItemValue":case"listItemMarker":case"listItemPrefix":case"listItemPrefixWhitespace":break;default:vt=void 0}if(!oe&&je[0]==="enter"&&je[1].type==="listItemPrefix"||oe===-1&&je[0]==="exit"&&(je[1].type==="listUnordered"||je[1].type==="listOrdered")){if(Ze){let st=ee;for(Ue=void 0;st--;){const Ve=R[st];if(Ve[1].type==="lineEnding"||Ve[1].type==="lineEndingBlank"){if(Ve[0]==="exit")continue;Ue&&(R[Ue][1].type="lineEndingBlank",Le=!0),Ve[1].type="lineEnding",Ue=st}else if(!(Ve[1].type==="linePrefix"||Ve[1].type==="blockQuotePrefix"||Ve[1].type==="blockQuotePrefixWhitespace"||Ve[1].type==="blockQuoteMarker"||Ve[1].type==="listItemIndent"))break}kt&&(!Ue||kt<Ue)&&(Ze._spread=!0),Ze.end=Object.assign({},Ue?R[Ue][1].start:je[1].end),R.splice(Ue||ee,0,["exit",Ze,je[2]]),ee++,Y++}if(je[1].type==="listItemPrefix"){const st={type:"listItem",_spread:!1,start:Object.assign({},je[1].start),end:void 0};Ze=st,R.splice(ee,0,["enter",st,je[2]]),ee++,Y++,kt=void 0,vt=!0}}}return R[O][1]._spread=Le,Y}function l(R,O){return Y;function Y(ee){a.call(this,R(ee),ee),O&&O.call(this,ee)}}function s(){this.stack.push({type:"fragment",children:[]})}function a(R,O,Y){this.stack[this.stack.length-1].children.push(R),this.stack.push(R),this.tokenStack.push([O,Y||void 0]),R.position={start:Ke(O.start),end:void 0}}function c(R){return O;function O(Y){R&&R.call(this,Y),u.call(this,Y)}}function u(R,O){const Y=this.stack.pop(),ee=this.tokenStack.pop();if(ee)ee[0].type!==R.type&&(O?O.call(this,R,ee[0]):(ee[1]||Jr).call(this,R,ee[0]));else throw new Error("Cannot close `"+R.type+"` ("+Bt({start:R.start,end:R.end})+"): it’s not open");Y.position.end=Ke(R.end)}function p(){return lr(this.stack.pop())}function d(){this.data.expectingFirstListItemValue=!0}function h(R){if(this.data.expectingFirstListItemValue){const O=this.stack[this.stack.length-2];O.start=Number.parseInt(this.sliceSerialize(R),10),this.data.expectingFirstListItemValue=void 0}}function f(){const R=this.resume(),O=this.stack[this.stack.length-1];O.lang=R}function g(){const R=this.resume(),O=this.stack[this.stack.length-1];O.meta=R}function b(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function x(){const R=this.resume(),O=this.stack[this.stack.length-1];O.value=R.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),this.data.flowCodeInside=void 0}function m(){const R=this.resume(),O=this.stack[this.stack.length-1];O.value=R.replace(/(\r?\n|\r)$/g,"")}function k(R){const O=this.resume(),Y=this.stack[this.stack.length-1];Y.label=O,Y.identifier=Pe(this.sliceSerialize(R)).toLowerCase()}function w(){const R=this.resume(),O=this.stack[this.stack.length-1];O.title=R}function _(){const R=this.resume(),O=this.stack[this.stack.length-1];O.url=R}function I(R){const O=this.stack[this.stack.length-1];if(!O.depth){const Y=this.sliceSerialize(R).length;O.depth=Y}}function S(){this.data.setextHeadingSlurpLineEnding=!0}function T(R){const O=this.stack[this.stack.length-1];O.depth=this.sliceSerialize(R).codePointAt(0)===61?1:2}function z(){this.data.setextHeadingSlurpLineEnding=void 0}function B(R){const Y=this.stack[this.stack.length-1].children;let ee=Y[Y.length-1];(!ee||ee.type!=="text")&&(ee=Te(),ee.position={start:Ke(R.start),end:void 0},Y.push(ee)),this.stack.push(ee)}function C(R){const O=this.stack.pop();O.value+=this.sliceSerialize(R),O.position.end=Ke(R.end)}function E(R){const O=this.stack[this.stack.length-1];if(this.data.atHardBreak){const Y=O.children[O.children.length-1];Y.position.end=Ke(R.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(O.type)&&(B.call(this,R),C.call(this,R))}function A(){this.data.atHardBreak=!0}function $(){const R=this.resume(),O=this.stack[this.stack.length-1];O.value=R}function P(){const R=this.resume(),O=this.stack[this.stack.length-1];O.value=R}function L(){const R=this.resume(),O=this.stack[this.stack.length-1];O.value=R}function N(){const R=this.stack[this.stack.length-1];if(this.data.inReference){const O=this.data.referenceType||"shortcut";R.type+="Reference",R.referenceType=O,delete R.url,delete R.title}else delete R.identifier,delete R.label;this.data.referenceType=void 0}function M(){const R=this.stack[this.stack.length-1];if(this.data.inReference){const O=this.data.referenceType||"shortcut";R.type+="Reference",R.referenceType=O,delete R.url,delete R.title}else delete R.identifier,delete R.label;this.data.referenceType=void 0}function D(R){const O=this.sliceSerialize(R),Y=this.stack[this.stack.length-2];Y.label=vu(O),Y.identifier=Pe(O).toLowerCase()}function U(){const R=this.stack[this.stack.length-1],O=this.resume(),Y=this.stack[this.stack.length-1];if(this.data.inReference=!0,Y.type==="link"){const ee=R.children;Y.children=ee}else Y.alt=O}function y(){const R=this.resume(),O=this.stack[this.stack.length-1];O.url=R}function q(){const R=this.resume(),O=this.stack[this.stack.length-1];O.title=R}function Z(){this.data.inReference=void 0}function j(){this.data.referenceType="collapsed"}function ce(R){const O=this.resume(),Y=this.stack[this.stack.length-1];Y.label=O,Y.identifier=Pe(this.sliceSerialize(R)).toLowerCase(),this.data.referenceType="full"}function be(R){this.data.characterReferenceType=R.type}function se(R){const O=this.sliceSerialize(R),Y=this.data.characterReferenceType;let ee;Y?(ee=So(O,Y==="characterReferenceMarkerNumeric"?10:16),this.data.characterReferenceType=void 0):ee=sr(O);const oe=this.stack[this.stack.length-1];oe.value+=ee}function pe(R){const O=this.stack.pop();O.position.end=Ke(R.end)}function re(R){C.call(this,R);const O=this.stack[this.stack.length-1];O.url=this.sliceSerialize(R)}function De(R){C.call(this,R);const O=this.stack[this.stack.length-1];O.url="mailto:"+this.sliceSerialize(R)}function Me(){return{type:"blockquote",children:[]}}function Oe(){return{type:"code",lang:null,meta:null,value:""}}function Je(){return{type:"inlineCode",value:""}}function yt(){return{type:"definition",identifier:"",label:null,title:null,url:""}}function ot(){return{type:"emphasis",children:[]}}function lt(){return{type:"heading",depth:0,children:[]}}function V(){return{type:"break"}}function de(){return{type:"html",value:""}}function ie(){return{type:"image",title:null,url:"",alt:null}}function ue(){return{type:"link",title:null,url:"",children:[]}}function he(R){return{type:"list",ordered:R.type==="listOrdered",start:null,spread:R._spread,children:[]}}function W(R){return{type:"listItem",spread:R._spread,checked:null,children:[]}}function Q(){return{type:"paragraph",children:[]}}function ye(){return{type:"strong",children:[]}}function Te(){return{type:"text",value:""}}function _e(){return{type:"thematicBreak"}}}function Ke(e){return{line:e.line,column:e.column,offset:e.offset}}function Ao(e,t){let n=-1;for(;++n<t.length;){const r=t[n];Array.isArray(r)?Ao(e,r):Cu(e,r)}}function Cu(e,t){let n;for(n in t)if(Lo.call(t,n))switch(n){case"canContainEols":{const r=t[n];r&&e[n].push(...r);break}case"transforms":{const r=t[n];r&&e[n].push(...r);break}case"enter":case"exit":{const r=t[n];r&&Object.assign(e[n],r);break}}}function Jr(e,t){throw e?new Error("Cannot close `"+e.type+"` ("+Bt({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+Bt({start:t.start,end:t.end})+") is open"):new Error("Cannot close document, a token (`"+t.type+"`, "+Bt({start:t.start,end:t.end})+") is still open")}function Iu(e){const t=this;t.parser=n;function n(r){return wu(r,{...t.data("settings"),...e,extensions:t.data("micromarkExtensions")||[],mdastExtensions:t.data("fromMarkdownExtensions")||[]})}}function Eu(e,t){const n={type:"element",tagName:"blockquote",properties:{},children:e.wrap(e.all(t),!0)};return e.patch(t,n),e.applyData(t,n)}function Tu(e,t){const n={type:"element",tagName:"br",properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:"text",value:`
5
- `}]}function _u(e,t){const n=t.value?t.value+`
6
- `:"",r={},o=t.lang?t.lang.split(/\s+/):[];o.length>0&&(r.className=["language-"+o[0]]);let l={type:"element",tagName:"code",properties:r,children:[{type:"text",value:n}]};return t.meta&&(l.data={meta:t.meta}),e.patch(t,l),l=e.applyData(t,l),l={type:"element",tagName:"pre",properties:{},children:[l]},e.patch(t,l),l}function zu(e,t){const n={type:"element",tagName:"del",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function Ru(e,t){const n={type:"element",tagName:"em",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function Lu(e,t){const n=typeof e.options.clobberPrefix=="string"?e.options.clobberPrefix:"user-content-",r=String(t.identifier).toUpperCase(),o=mt(r.toLowerCase()),l=e.footnoteOrder.indexOf(r);let s,a=e.footnoteCounts.get(r);a===void 0?(a=0,e.footnoteOrder.push(r),s=e.footnoteOrder.length):s=l+1,a+=1,e.footnoteCounts.set(r,a);const c={type:"element",tagName:"a",properties:{href:"#"+n+"fn-"+o,id:n+"fnref-"+o+(a>1?"-"+a:""),dataFootnoteRef:!0,ariaDescribedBy:["footnote-label"]},children:[{type:"text",value:String(s)}]};e.patch(t,c);const u={type:"element",tagName:"sup",properties:{},children:[c]};return e.patch(t,u),e.applyData(t,u)}function Au(e,t){const n={type:"element",tagName:"h"+t.depth,properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function Bu(e,t){if(e.options.allowDangerousHtml){const n={type:"raw",value:t.value};return e.patch(t,n),e.applyData(t,n)}}function Bo(e,t){const n=t.referenceType;let r="]";if(n==="collapsed"?r+="[]":n==="full"&&(r+="["+(t.label||t.identifier)+"]"),t.type==="imageReference")return[{type:"text",value:"!["+t.alt+r}];const o=e.all(t),l=o[0];l&&l.type==="text"?l.value="["+l.value:o.unshift({type:"text",value:"["});const s=o[o.length-1];return s&&s.type==="text"?s.value+=r:o.push({type:"text",value:r}),o}function Pu(e,t){const n=String(t.identifier).toUpperCase(),r=e.definitionById.get(n);if(!r)return Bo(e,t);const o={src:mt(r.url||""),alt:t.alt};r.title!==null&&r.title!==void 0&&(o.title=r.title);const l={type:"element",tagName:"img",properties:o,children:[]};return e.patch(t,l),e.applyData(t,l)}function Fu(e,t){const n={src:mt(t.url)};t.alt!==null&&t.alt!==void 0&&(n.alt=t.alt),t.title!==null&&t.title!==void 0&&(n.title=t.title);const r={type:"element",tagName:"img",properties:n,children:[]};return e.patch(t,r),e.applyData(t,r)}function Du(e,t){const n={type:"text",value:t.value.replace(/\r?\n|\r/g," ")};e.patch(t,n);const r={type:"element",tagName:"code",properties:{},children:[n]};return e.patch(t,r),e.applyData(t,r)}function Mu(e,t){const n=String(t.identifier).toUpperCase(),r=e.definitionById.get(n);if(!r)return Bo(e,t);const o={href:mt(r.url||"")};r.title!==null&&r.title!==void 0&&(o.title=r.title);const l={type:"element",tagName:"a",properties:o,children:e.all(t)};return e.patch(t,l),e.applyData(t,l)}function Ou(e,t){const n={href:mt(t.url)};t.title!==null&&t.title!==void 0&&(n.title=t.title);const r={type:"element",tagName:"a",properties:n,children:e.all(t)};return e.patch(t,r),e.applyData(t,r)}function Wu(e,t,n){const r=e.all(t),o=n?$u(n):Po(t),l={},s=[];if(typeof t.checked=="boolean"){const p=r[0];let d;p&&p.type==="element"&&p.tagName==="p"?d=p:(d={type:"element",tagName:"p",properties:{},children:[]},r.unshift(d)),d.children.length>0&&d.children.unshift({type:"text",value:" "}),d.children.unshift({type:"element",tagName:"input",properties:{type:"checkbox",checked:t.checked,disabled:!0},children:[]}),l.className=["task-list-item"]}let a=-1;for(;++a<r.length;){const p=r[a];(o||a!==0||p.type!=="element"||p.tagName!=="p")&&s.push({type:"text",value:`
7
- `}),p.type==="element"&&p.tagName==="p"&&!o?s.push(...p.children):s.push(p)}const c=r[r.length-1];c&&(o||c.type!=="element"||c.tagName!=="p")&&s.push({type:"text",value:`
8
- `});const u={type:"element",tagName:"li",properties:l,children:s};return e.patch(t,u),e.applyData(t,u)}function $u(e){let t=!1;if(e.type==="list"){t=e.spread||!1;const n=e.children;let r=-1;for(;!t&&++r<n.length;)t=Po(n[r])}return t}function Po(e){const t=e.spread;return t??e.children.length>1}function Nu(e,t){const n={},r=e.all(t);let o=-1;for(typeof t.start=="number"&&t.start!==1&&(n.start=t.start);++o<r.length;){const s=r[o];if(s.type==="element"&&s.tagName==="li"&&s.properties&&Array.isArray(s.properties.className)&&s.properties.className.includes("task-list-item")){n.className=["contains-task-list"];break}}const l={type:"element",tagName:t.ordered?"ol":"ul",properties:n,children:e.wrap(r,!0)};return e.patch(t,l),e.applyData(t,l)}function Hu(e,t){const n={type:"element",tagName:"p",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function Uu(e,t){const n={type:"root",children:e.wrap(e.all(t))};return e.patch(t,n),e.applyData(t,n)}function Vu(e,t){const n={type:"element",tagName:"strong",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function qu(e,t){const n=e.all(t),r=n.shift(),o=[];if(r){const s={type:"element",tagName:"thead",properties:{},children:e.wrap([r],!0)};e.patch(t.children[0],s),o.push(s)}if(n.length>0){const s={type:"element",tagName:"tbody",properties:{},children:e.wrap(n,!0)},a=nr(t.children[1]),c=ho(t.children[t.children.length-1]);a&&c&&(s.position={start:a,end:c}),o.push(s)}const l={type:"element",tagName:"table",properties:{},children:e.wrap(o,!0)};return e.patch(t,l),e.applyData(t,l)}function Yu(e,t,n){const r=n?n.children:void 0,l=(r?r.indexOf(t):1)===0?"th":"td",s=n&&n.type==="table"?n.align:void 0,a=s?s.length:t.children.length;let c=-1;const u=[];for(;++c<a;){const d=t.children[c],h={},f=s?s[c]:void 0;f&&(h.align=f);let g={type:"element",tagName:l,properties:h,children:[]};d&&(g.children=e.all(d),e.patch(d,g),g=e.applyData(d,g)),u.push(g)}const p={type:"element",tagName:"tr",properties:{},children:e.wrap(u,!0)};return e.patch(t,p),e.applyData(t,p)}function Gu(e,t){const n={type:"element",tagName:"td",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}const Zr=9,Qr=32;function Ku(e){const t=String(e),n=/\r?\n|\r/g;let r=n.exec(t),o=0;const l=[];for(;r;)l.push(ei(t.slice(o,r.index),o>0,!0),r[0]),o=r.index+r[0].length,r=n.exec(t);return l.push(ei(t.slice(o),o>0,!1)),l.join("")}function ei(e,t,n){let r=0,o=e.length;if(t){let l=e.codePointAt(r);for(;l===Zr||l===Qr;)r++,l=e.codePointAt(r)}if(n){let l=e.codePointAt(o-1);for(;l===Zr||l===Qr;)o--,l=e.codePointAt(o-1)}return o>r?e.slice(r,o):""}function Xu(e,t){const n={type:"text",value:Ku(String(t.value))};return e.patch(t,n),e.applyData(t,n)}function Ju(e,t){const n={type:"element",tagName:"hr",properties:{},children:[]};return e.patch(t,n),e.applyData(t,n)}const Zu={blockquote:Eu,break:Tu,code:_u,delete:zu,emphasis:Ru,footnoteReference:Lu,heading:Au,html:Bu,imageReference:Pu,image:Fu,inlineCode:Du,linkReference:Mu,link:Ou,listItem:Wu,list:Nu,paragraph:Hu,root:Uu,strong:Vu,table:qu,tableCell:Gu,tableRow:Yu,text:Xu,thematicBreak:Ju,toml:qt,yaml:qt,definition:qt,footnoteDefinition:qt};function qt(){}const Fo=-1,pn=0,Ft=1,rn=2,cr=3,ur=4,dr=5,pr=6,Do=7,Mo=8,Qu=typeof self=="object"?self:globalThis,ti=(e,t)=>{switch(e){case"Function":case"SharedWorker":case"Worker":case"eval":case"setInterval":case"setTimeout":throw new TypeError("unable to deserialize "+e)}return new Qu[e](t)},ed=(e,t)=>{const n=(o,l)=>(e.set(l,o),o),r=o=>{if(e.has(o))return e.get(o);const[l,s]=t[o];switch(l){case pn:case Fo:return n(s,o);case Ft:{const a=n([],o);for(const c of s)a.push(r(c));return a}case rn:{const a=n({},o);for(const[c,u]of s)a[r(c)]=r(u);return a}case cr:return n(new Date(s),o);case ur:{const{source:a,flags:c}=s;return n(new RegExp(a,c),o)}case dr:{const a=n(new Map,o);for(const[c,u]of s)a.set(r(c),r(u));return a}case pr:{const a=n(new Set,o);for(const c of s)a.add(r(c));return a}case Do:{const{name:a,message:c}=s;return n(ti(a,c),o)}case Mo:return n(BigInt(s),o);case"BigInt":return n(Object(BigInt(s)),o);case"ArrayBuffer":return n(new Uint8Array(s).buffer,s);case"DataView":{const{buffer:a}=new Uint8Array(s);return n(new DataView(a),s)}}return n(ti(l,s),o)};return r},ni=e=>ed(new Map,e)(0),ct="",{toString:td}={},{keys:nd}=Object,Tt=e=>{const t=typeof e;if(t!=="object"||!e)return[pn,t];const n=td.call(e).slice(8,-1);switch(n){case"Array":return[Ft,ct];case"Object":return[rn,ct];case"Date":return[cr,ct];case"RegExp":return[ur,ct];case"Map":return[dr,ct];case"Set":return[pr,ct];case"DataView":return[Ft,n]}return n.includes("Array")?[Ft,n]:n.includes("Error")?[Do,n]:[rn,n]},Yt=([e,t])=>e===pn&&(t==="function"||t==="symbol"),rd=(e,t,n,r)=>{const o=(s,a)=>{const c=r.push(s)-1;return n.set(a,c),c},l=s=>{if(n.has(s))return n.get(s);let[a,c]=Tt(s);switch(a){case pn:{let p=s;switch(c){case"bigint":a=Mo,p=s.toString();break;case"function":case"symbol":if(e)throw new TypeError("unable to serialize "+c);p=null;break;case"undefined":return o([Fo],s)}return o([a,p],s)}case Ft:{if(c){let h=s;return c==="DataView"?h=new Uint8Array(s.buffer):c==="ArrayBuffer"&&(h=new Uint8Array(s)),o([c,[...h]],s)}const p=[],d=o([a,p],s);for(const h of s)p.push(l(h));return d}case rn:{if(c)switch(c){case"BigInt":return o([c,s.toString()],s);case"Boolean":case"Number":case"String":return o([c,s.valueOf()],s)}if(t&&"toJSON"in s)return l(s.toJSON());const p=[],d=o([a,p],s);for(const h of nd(s))(e||!Yt(Tt(s[h])))&&p.push([l(h),l(s[h])]);return d}case cr:return o([a,s.toISOString()],s);case ur:{const{source:p,flags:d}=s;return o([a,{source:p,flags:d}],s)}case dr:{const p=[],d=o([a,p],s);for(const[h,f]of s)(e||!(Yt(Tt(h))||Yt(Tt(f))))&&p.push([l(h),l(f)]);return d}case pr:{const p=[],d=o([a,p],s);for(const h of s)(e||!Yt(Tt(h)))&&p.push(l(h));return d}}const{message:u}=s;return o([a,{name:c,message:u}],s)};return l},ri=(e,{json:t,lossy:n}={})=>{const r=[];return rd(!(t||n),!!t,new Map,r)(e),r},on=typeof structuredClone=="function"?(e,t)=>t&&("json"in t||"lossy"in t)?ni(ri(e,t)):structuredClone(e):(e,t)=>ni(ri(e,t));function id(e,t){const n=[{type:"text",value:"↩"}];return t>1&&n.push({type:"element",tagName:"sup",properties:{},children:[{type:"text",value:String(t)}]}),n}function od(e,t){return"Back to reference "+(e+1)+(t>1?"-"+t:"")}function ld(e){const t=typeof e.options.clobberPrefix=="string"?e.options.clobberPrefix:"user-content-",n=e.options.footnoteBackContent||id,r=e.options.footnoteBackLabel||od,o=e.options.footnoteLabel||"Footnotes",l=e.options.footnoteLabelTagName||"h2",s=e.options.footnoteLabelProperties||{className:["sr-only"]},a=[];let c=-1;for(;++c<e.footnoteOrder.length;){const u=e.footnoteById.get(e.footnoteOrder[c]);if(!u)continue;const p=e.all(u),d=String(u.identifier).toUpperCase(),h=mt(d.toLowerCase());let f=0;const g=[],b=e.footnoteCounts.get(d);for(;b!==void 0&&++f<=b;){g.length>0&&g.push({type:"text",value:" "});let k=typeof n=="string"?n:n(c,f);typeof k=="string"&&(k={type:"text",value:k}),g.push({type:"element",tagName:"a",properties:{href:"#"+t+"fnref-"+h+(f>1?"-"+f:""),dataFootnoteBackref:"",ariaLabel:typeof r=="string"?r:r(c,f),className:["data-footnote-backref"]},children:Array.isArray(k)?k:[k]})}const x=p[p.length-1];if(x&&x.type==="element"&&x.tagName==="p"){const k=x.children[x.children.length-1];k&&k.type==="text"?k.value+=" ":x.children.push({type:"text",value:" "}),x.children.push(...g)}else p.push(...g);const m={type:"element",tagName:"li",properties:{id:t+"fn-"+h},children:e.wrap(p,!0)};e.patch(u,m),a.push(m)}if(a.length!==0)return{type:"element",tagName:"section",properties:{dataFootnotes:!0,className:["footnotes"]},children:[{type:"element",tagName:l,properties:{...on(s),id:"footnote-label"},children:[{type:"text",value:o}]},{type:"text",value:`
9
- `},{type:"element",tagName:"ol",properties:{},children:e.wrap(a,!0)},{type:"text",value:`
10
- `}]}}const fn=(function(e){if(e==null)return ud;if(typeof e=="function")return hn(e);if(typeof e=="object")return Array.isArray(e)?sd(e):ad(e);if(typeof e=="string")return cd(e);throw new Error("Expected function, string, or object as test")});function sd(e){const t=[];let n=-1;for(;++n<e.length;)t[n]=fn(e[n]);return hn(r);function r(...o){let l=-1;for(;++l<t.length;)if(t[l].apply(this,o))return!0;return!1}}function ad(e){const t=e;return hn(n);function n(r){const o=r;let l;for(l in e)if(o[l]!==t[l])return!1;return!0}}function cd(e){return hn(t);function t(n){return n&&n.type===e}}function hn(e){return t;function t(n,r,o){return!!(dd(n)&&e.call(this,n,typeof r=="number"?r:void 0,o||void 0))}}function ud(){return!0}function dd(e){return e!==null&&typeof e=="object"&&"type"in e}const Oo=[],pd=!0,Vn=!1,fd="skip";function Wo(e,t,n,r){let o;typeof t=="function"&&typeof n!="function"?(r=n,n=t):o=t;const l=fn(o),s=r?-1:1;a(e,void 0,[])();function a(c,u,p){const d=c&&typeof c=="object"?c:{};if(typeof d.type=="string"){const f=typeof d.tagName=="string"?d.tagName:typeof d.name=="string"?d.name:void 0;Object.defineProperty(h,"name",{value:"node ("+(c.type+(f?"<"+f+">":""))+")"})}return h;function h(){let f=Oo,g,b,x;if((!t||l(c,u,p[p.length-1]||void 0))&&(f=hd(n(c,p)),f[0]===Vn))return f;if("children"in c&&c.children){const m=c;if(m.children&&f[0]!==fd)for(b=(r?m.children.length:-1)+s,x=p.concat(m);b>-1&&b<m.children.length;){const k=m.children[b];if(g=a(k,b,x)(),g[0]===Vn)return g;b=typeof g[1]=="number"?g[1]:b+s}}return f}}}function hd(e){return Array.isArray(e)?e:typeof e=="number"?[pd,e]:e==null?Oo:[e]}function fr(e,t,n,r){let o,l,s;typeof t=="function"&&typeof n!="function"?(l=void 0,s=t,o=n):(l=t,s=n,o=r),Wo(e,l,a,o);function a(c,u){const p=u[u.length-1],d=p?p.children.indexOf(c):void 0;return s(c,d,p)}}const qn={}.hasOwnProperty,gd={};function xd(e,t){const n=t||gd,r=new Map,o=new Map,l=new Map,s={...Zu,...n.handlers},a={all:u,applyData:bd,definitionById:r,footnoteById:o,footnoteCounts:l,footnoteOrder:[],handlers:s,one:c,options:n,patch:md,wrap:kd};return fr(e,function(p){if(p.type==="definition"||p.type==="footnoteDefinition"){const d=p.type==="definition"?r:o,h=String(p.identifier).toUpperCase();d.has(h)||d.set(h,p)}}),a;function c(p,d){const h=p.type,f=a.handlers[h];if(qn.call(a.handlers,h)&&f)return f(a,p,d);if(a.options.passThrough&&a.options.passThrough.includes(h)){if("children"in p){const{children:b,...x}=p,m=on(x);return m.children=a.all(p),m}return on(p)}return(a.options.unknownHandler||yd)(a,p,d)}function u(p){const d=[];if("children"in p){const h=p.children;let f=-1;for(;++f<h.length;){const g=a.one(h[f],p);if(g){if(f&&h[f-1].type==="break"&&(!Array.isArray(g)&&g.type==="text"&&(g.value=ii(g.value)),!Array.isArray(g)&&g.type==="element")){const b=g.children[0];b&&b.type==="text"&&(b.value=ii(b.value))}Array.isArray(g)?d.push(...g):d.push(g)}}}return d}}function md(e,t){e.position&&(t.position=ia(e))}function bd(e,t){let n=t;if(e&&e.data){const r=e.data.hName,o=e.data.hChildren,l=e.data.hProperties;if(typeof r=="string")if(n.type==="element")n.tagName=r;else{const s="children"in n?n.children:[n];n={type:"element",tagName:r,properties:{},children:s}}n.type==="element"&&l&&Object.assign(n.properties,on(l)),"children"in n&&n.children&&o!==null&&o!==void 0&&(n.children=o)}return n}function yd(e,t){const n=t.data||{},r="value"in t&&!(qn.call(n,"hProperties")||qn.call(n,"hChildren"))?{type:"text",value:t.value}:{type:"element",tagName:"div",properties:{},children:e.all(t)};return e.patch(t,r),e.applyData(t,r)}function kd(e,t){const n=[];let r=-1;for(t&&n.push({type:"text",value:`
11
- `});++r<e.length;)r&&n.push({type:"text",value:`
12
- `}),n.push(e[r]);return t&&e.length>0&&n.push({type:"text",value:`
13
- `}),n}function ii(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function oi(e,t){const n=xd(e,t),r=n.one(e,void 0),o=ld(n),l=Array.isArray(r)?{type:"root",children:r}:r||{type:"root",children:[]};return o&&l.children.push({type:"text",value:`
14
- `},o),l}function vd(e,t){return e&&"run"in e?async function(n,r){const o=oi(n,{file:r,...t});await e.run(o,r)}:function(n,r){return oi(n,{file:r,...e||t})}}function li(e){if(e)throw e}var vn,si;function Sd(){if(si)return vn;si=1;var e=Object.prototype.hasOwnProperty,t=Object.prototype.toString,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,o=function(u){return typeof Array.isArray=="function"?Array.isArray(u):t.call(u)==="[object Array]"},l=function(u){if(!u||t.call(u)!=="[object Object]")return!1;var p=e.call(u,"constructor"),d=u.constructor&&u.constructor.prototype&&e.call(u.constructor.prototype,"isPrototypeOf");if(u.constructor&&!p&&!d)return!1;var h;for(h in u);return typeof h>"u"||e.call(u,h)},s=function(u,p){n&&p.name==="__proto__"?n(u,p.name,{enumerable:!0,configurable:!0,value:p.newValue,writable:!0}):u[p.name]=p.newValue},a=function(u,p){if(p==="__proto__")if(e.call(u,p)){if(r)return r(u,p).value}else return;return u[p]};return vn=function c(){var u,p,d,h,f,g,b=arguments[0],x=1,m=arguments.length,k=!1;for(typeof b=="boolean"&&(k=b,b=arguments[1]||{},x=2),(b==null||typeof b!="object"&&typeof b!="function")&&(b={});x<m;++x)if(u=arguments[x],u!=null)for(p in u)d=a(b,p),h=a(u,p),b!==h&&(k&&h&&(l(h)||(f=o(h)))?(f?(f=!1,g=d&&o(d)?d:[]):g=d&&l(d)?d:{},s(b,{name:p,newValue:c(k,g,h)})):typeof h<"u"&&s(b,{name:p,newValue:h}));return b},vn}var wd=Sd();const Sn=fo(wd);function Yn(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function jd(){const e=[],t={run:n,use:r};return t;function n(...o){let l=-1;const s=o.pop();if(typeof s!="function")throw new TypeError("Expected function as last argument, not "+s);a(null,...o);function a(c,...u){const p=e[++l];let d=-1;if(c){s(c);return}for(;++d<o.length;)(u[d]===null||u[d]===void 0)&&(u[d]=o[d]);o=u,p?Cd(p,a)(...u):s(null,...u)}}function r(o){if(typeof o!="function")throw new TypeError("Expected `middelware` to be a function, not "+o);return e.push(o),t}}function Cd(e,t){let n;return r;function r(...s){const a=e.length>s.length;let c;a&&s.push(o);try{c=e.apply(this,s)}catch(u){const p=u;if(a&&n)throw p;return o(p)}a||(c&&c.then&&typeof c.then=="function"?c.then(l,o):c instanceof Error?o(c):l(c))}function o(s,...a){n||(n=!0,t(s,...a))}function l(s){o(null,s)}}const $e={basename:Id,dirname:Ed,extname:Td,join:_d,sep:"/"};function Id(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');Vt(e);let n=0,r=-1,o=e.length,l;if(t===void 0||t.length===0||t.length>e.length){for(;o--;)if(e.codePointAt(o)===47){if(l){n=o+1;break}}else r<0&&(l=!0,r=o+1);return r<0?"":e.slice(n,r)}if(t===e)return"";let s=-1,a=t.length-1;for(;o--;)if(e.codePointAt(o)===47){if(l){n=o+1;break}}else s<0&&(l=!0,s=o+1),a>-1&&(e.codePointAt(o)===t.codePointAt(a--)?a<0&&(r=o):(a=-1,r=s));return n===r?r=s:r<0&&(r=e.length),e.slice(n,r)}function Ed(e){if(Vt(e),e.length===0)return".";let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||(r=!0);return t<0?e.codePointAt(0)===47?"/":".":t===1&&e.codePointAt(0)===47?"//":e.slice(0,t)}function Td(e){Vt(e);let t=e.length,n=-1,r=0,o=-1,l=0,s;for(;t--;){const a=e.codePointAt(t);if(a===47){if(s){r=t+1;break}continue}n<0&&(s=!0,n=t+1),a===46?o<0?o=t:l!==1&&(l=1):o>-1&&(l=-1)}return o<0||n<0||l===0||l===1&&o===n-1&&o===r+1?"":e.slice(o,n)}function _d(...e){let t=-1,n;for(;++t<e.length;)Vt(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":zd(n)}function zd(e){Vt(e);const t=e.codePointAt(0)===47;let n=Rd(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function Rd(e,t){let n="",r=0,o=-1,l=0,s=-1,a,c;for(;++s<=e.length;){if(s<e.length)a=e.codePointAt(s);else{if(a===47)break;a=47}if(a===47){if(!(o===s-1||l===1))if(o!==s-1&&l===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(c=n.lastIndexOf("/"),c!==n.length-1){c<0?(n="",r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf("/")),o=s,l=0;continue}}else if(n.length>0){n="",r=0,o=s,l=0;continue}}t&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+e.slice(o+1,s):n=e.slice(o+1,s),r=s-o-1;o=s,l=0}else a===46&&l>-1?l++:l=-1}return n}function Vt(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const Ld={cwd:Ad};function Ad(){return"/"}function Gn(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function Bd(e){if(typeof e=="string")e=new URL(e);else if(!Gn(e)){const t=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code="ERR_INVALID_ARG_TYPE",t}if(e.protocol!=="file:"){const t=new TypeError("The URL must be of scheme file");throw t.code="ERR_INVALID_URL_SCHEME",t}return Pd(e)}function Pd(e){if(e.hostname!==""){const r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}const t=e.pathname;let n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){const r=t.codePointAt(n+2);if(r===70||r===102){const o=new TypeError("File URL path must not include encoded / characters");throw o.code="ERR_INVALID_FILE_URL_PATH",o}}return decodeURIComponent(t)}const wn=["history","path","basename","stem","extname","dirname"];class $o{constructor(t){let n;t?Gn(t)?n={path:t}:typeof t=="string"||Fd(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":Ld.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<wn.length;){const l=wn[r];l in n&&n[l]!==void 0&&n[l]!==null&&(this[l]=l==="history"?[...n[l]]:n[l])}let o;for(o in n)wn.includes(o)||(this[o]=n[o])}get basename(){return typeof this.path=="string"?$e.basename(this.path):void 0}set basename(t){Cn(t,"basename"),jn(t,"basename"),this.path=$e.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?$e.dirname(this.path):void 0}set dirname(t){ai(this.basename,"dirname"),this.path=$e.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?$e.extname(this.path):void 0}set extname(t){if(jn(t,"extname"),ai(this.dirname,"extname"),t){if(t.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(t.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=$e.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){Gn(t)&&(t=Bd(t)),Cn(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?$e.basename(this.path,this.extname):void 0}set stem(t){Cn(t,"stem"),jn(t,"stem"),this.path=$e.join(this.dirname||"",t+(this.extname||""))}fail(t,n,r){const o=this.message(t,n,r);throw o.fatal=!0,o}info(t,n,r){const o=this.message(t,n,r);return o.fatal=void 0,o}message(t,n,r){const o=new me(t,n,r);return this.path&&(o.name=this.path+":"+o.name,o.file=this.path),o.fatal=!1,this.messages.push(o),o}toString(t){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(t||void 0).decode(this.value)}}function jn(e,t){if(e&&e.includes($e.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+$e.sep+"`")}function Cn(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function ai(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function Fd(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Dd=(function(e){const r=this.constructor.prototype,o=r[e],l=function(){return o.apply(l,arguments)};return Object.setPrototypeOf(l,r),l}),Md={}.hasOwnProperty;class hr extends Dd{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=jd()}copy(){const t=new hr;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(Sn(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(Tn("data",this.frozen),this.namespace[t]=n,this):Md.call(this.namespace,t)&&this.namespace[t]||void 0:t?(Tn("data",this.frozen),this.namespace=t,this):this.namespace}freeze(){if(this.frozen)return this;const t=this;for(;++this.freezeIndex<this.attachers.length;){const[n,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);const o=n.call(t,...r);typeof o=="function"&&this.transformers.use(o)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();const n=Gt(t),r=this.parser||this.Parser;return In("parse",r),r(String(n),n)}process(t,n){const r=this;return this.freeze(),In("process",this.parser||this.Parser),En("process",this.compiler||this.Compiler),n?o(void 0,n):new Promise(o);function o(l,s){const a=Gt(t),c=r.parse(a);r.run(c,a,function(p,d,h){if(p||!d||!h)return u(p);const f=d,g=r.stringify(f,h);$d(g)?h.value=g:h.result=g,u(p,h)});function u(p,d){p||!d?s(p):l?l(d):n(void 0,d)}}}processSync(t){let n=!1,r;return this.freeze(),In("processSync",this.parser||this.Parser),En("processSync",this.compiler||this.Compiler),this.process(t,o),ui("processSync","process",n),r;function o(l,s){n=!0,li(l),r=s}}run(t,n,r){ci(t),this.freeze();const o=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?l(void 0,r):new Promise(l);function l(s,a){const c=Gt(n);o.run(t,c,u);function u(p,d,h){const f=d||t;p?a(p):s?s(f):r(void 0,f,h)}}}runSync(t,n){let r=!1,o;return this.run(t,n,l),ui("runSync","run",r),o;function l(s,a){li(s),o=a,r=!0}}stringify(t,n){this.freeze();const r=Gt(n),o=this.compiler||this.Compiler;return En("stringify",o),ci(t),o(t,r)}use(t,...n){const r=this.attachers,o=this.namespace;if(Tn("use",this.frozen),t!=null)if(typeof t=="function")c(t,n);else if(typeof t=="object")Array.isArray(t)?a(t):s(t);else throw new TypeError("Expected usable value, not `"+t+"`");return this;function l(u){if(typeof u=="function")c(u,[]);else if(typeof u=="object")if(Array.isArray(u)){const[p,...d]=u;c(p,d)}else s(u);else throw new TypeError("Expected usable value, not `"+u+"`")}function s(u){if(!("plugins"in u)&&!("settings"in u))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");a(u.plugins),u.settings&&(o.settings=Sn(!0,o.settings,u.settings))}function a(u){let p=-1;if(u!=null)if(Array.isArray(u))for(;++p<u.length;){const d=u[p];l(d)}else throw new TypeError("Expected a list of plugins, not `"+u+"`")}function c(u,p){let d=-1,h=-1;for(;++d<r.length;)if(r[d][0]===u){h=d;break}if(h===-1)r.push([u,...p]);else if(p.length>0){let[f,...g]=p;const b=r[h][1];Yn(b)&&Yn(f)&&(f=Sn(!0,b,f)),r[h]=[u,f,...g]}}}}const Od=new hr().freeze();function In(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function En(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function Tn(e,t){if(t)throw new Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function ci(e){if(!Yn(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function ui(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function Gt(e){return Wd(e)?e:new $o(e)}function Wd(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function $d(e){return typeof e=="string"||Nd(e)}function Nd(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Hd="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",di=[],pi={allowDangerousHtml:!0},Ud=/^(https?|ircs?|mailto|xmpp)$/i,Vd=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function qd(e){const t=Yd(e),n=Gd(e);return Kd(t.runSync(t.parse(n),n),e)}function Yd(e){const t=e.rehypePlugins||di,n=e.remarkPlugins||di,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...pi}:pi;return Od().use(Iu).use(n).use(vd,r).use(t)}function Gd(e){const t=e.children||"",n=new $o;return typeof t=="string"&&(n.value=t),n}function Kd(e,t){const n=t.allowedElements,r=t.allowElement,o=t.components,l=t.disallowedElements,s=t.skipHtml,a=t.unwrapDisallowed,c=t.urlTransform||Xd;for(const p of Vd)Object.hasOwn(t,p.from)&&(""+p.from+(p.to?"use `"+p.to+"` instead":"remove it")+Hd+p.id,void 0);return t.className&&(e={type:"element",tagName:"div",properties:{className:t.className},children:e.type==="root"?e.children:[e]}),fr(e,u),ca(e,{Fragment:i.Fragment,components:o,ignoreInvalidStyle:!0,jsx:i.jsx,jsxs:i.jsxs,passKeys:!0,passNode:!0});function u(p,d,h){if(p.type==="raw"&&h&&typeof d=="number")return s?h.children.splice(d,1):h.children[d]={type:"text",value:p.value},d;if(p.type==="element"){let f;for(f in bn)if(Object.hasOwn(bn,f)&&Object.hasOwn(p.properties,f)){const g=p.properties[f],b=bn[f];(b===null||b.includes(p.tagName))&&(p.properties[f]=c(String(g||""),f,p))}}if(p.type==="element"){let f=n?!n.includes(p.tagName):l?l.includes(p.tagName):!1;if(!f&&r&&typeof d=="number"&&(f=!r(p,d,h)),f&&h&&typeof d=="number")return a&&p.children?h.children.splice(d,1,...p.children):h.children.splice(d,1),d}}}function Xd(e){const t=e.indexOf(":"),n=e.indexOf("?"),r=e.indexOf("#"),o=e.indexOf("/");return t===-1||o!==-1&&t>o||n!==-1&&t>n||r!==-1&&t>r||Ud.test(e.slice(0,t))?e:""}function fi(e,t){const n=String(e);if(typeof t!="string")throw new TypeError("Expected character");let r=0,o=n.indexOf(t);for(;o!==-1;)r++,o=n.indexOf(t,o+t.length);return r}function Jd(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function Zd(e,t,n){const o=fn((n||{}).ignore||[]),l=Qd(t);let s=-1;for(;++s<l.length;)Wo(e,"text",a);function a(u,p){let d=-1,h;for(;++d<p.length;){const f=p[d],g=h?h.children:void 0;if(o(f,g?g.indexOf(f):void 0,h))return;h=f}if(h)return c(u,p)}function c(u,p){const d=p[p.length-1],h=l[s][0],f=l[s][1];let g=0;const x=d.children.indexOf(u);let m=!1,k=[];h.lastIndex=0;let w=h.exec(u.value);for(;w;){const _=w.index,I={index:w.index,input:w.input,stack:[...p,u]};let S=f(...w,I);if(typeof S=="string"&&(S=S.length>0?{type:"text",value:S}:void 0),S===!1?h.lastIndex=_+1:(g!==_&&k.push({type:"text",value:u.value.slice(g,_)}),Array.isArray(S)?k.push(...S):S&&k.push(S),g=_+w[0].length,m=!0),!h.global)break;w=h.exec(u.value)}return m?(g<u.value.length&&k.push({type:"text",value:u.value.slice(g)}),d.children.splice(x,1,...k)):k=[u],x+k.length}}function Qd(e){const t=[];if(!Array.isArray(e))throw new TypeError("Expected find and replace tuple or list of tuples");const n=!e[0]||Array.isArray(e[0])?e:[e];let r=-1;for(;++r<n.length;){const o=n[r];t.push([ep(o[0]),tp(o[1])])}return t}function ep(e){return typeof e=="string"?new RegExp(Jd(e),"g"):e}function tp(e){return typeof e=="function"?e:function(){return e}}const _n="phrasing",zn=["autolink","link","image","label"];function np(){return{transforms:[cp],enter:{literalAutolink:ip,literalAutolinkEmail:Rn,literalAutolinkHttp:Rn,literalAutolinkWww:Rn},exit:{literalAutolink:ap,literalAutolinkEmail:sp,literalAutolinkHttp:op,literalAutolinkWww:lp}}}function rp(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:_n,notInConstruct:zn},{character:".",before:"[Ww]",after:"[\\-.\\w]",inConstruct:_n,notInConstruct:zn},{character:":",before:"[ps]",after:"\\/",inConstruct:_n,notInConstruct:zn}]}}function ip(e){this.enter({type:"link",title:null,url:"",children:[]},e)}function Rn(e){this.config.enter.autolinkProtocol.call(this,e)}function op(e){this.config.exit.autolinkProtocol.call(this,e)}function lp(e){this.config.exit.data.call(this,e);const t=this.stack[this.stack.length-1];t.type,t.url="http://"+this.sliceSerialize(e)}function sp(e){this.config.exit.autolinkEmail.call(this,e)}function ap(e){this.exit(e)}function cp(e){Zd(e,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,up],[new RegExp("(?<=^|\\s|\\p{P}|\\p{S})([-.\\w+]+)@([-\\w]+(?:\\.[-\\w]+)+)","gu"),dp]],{ignore:["link","linkReference"]})}function up(e,t,n,r,o){let l="";if(!No(o)||(/^w/i.test(t)&&(n=t+n,t="",l="http://"),!pp(n)))return!1;const s=fp(n+r);if(!s[0])return!1;const a={type:"link",title:null,url:l+t+s[0],children:[{type:"text",value:t+s[0]}]};return s[1]?[a,{type:"text",value:s[1]}]:a}function dp(e,t,n,r){return!No(r,!0)||/[-\d_]$/.test(n)?!1:{type:"link",title:null,url:"mailto:"+t+"@"+n,children:[{type:"text",value:t+"@"+n}]}}function pp(e){const t=e.split(".");return!(t.length<2||t[t.length-1]&&(/_/.test(t[t.length-1])||!/[a-zA-Z\d]/.test(t[t.length-1]))||t[t.length-2]&&(/_/.test(t[t.length-2])||!/[a-zA-Z\d]/.test(t[t.length-2])))}function fp(e){const t=/[!"&'),.:;<>?\]}]+$/.exec(e);if(!t)return[e,void 0];e=e.slice(0,t.index);let n=t[0],r=n.indexOf(")");const o=fi(e,"(");let l=fi(e,")");for(;r!==-1&&o>l;)e+=n.slice(0,r+1),n=n.slice(r+1),r=n.indexOf(")"),l++;return[e,n]}function No(e,t){const n=e.input.charCodeAt(e.index-1);return(e.index===0||nt(n)||un(n))&&(!t||n!==47)}Ho.peek=Sp;function hp(){this.buffer()}function gp(e){this.enter({type:"footnoteReference",identifier:"",label:""},e)}function xp(){this.buffer()}function mp(e){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},e)}function bp(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Pe(this.sliceSerialize(e)).toLowerCase(),n.label=t}function yp(e){this.exit(e)}function kp(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Pe(this.sliceSerialize(e)).toLowerCase(),n.label=t}function vp(e){this.exit(e)}function Sp(){return"["}function Ho(e,t,n,r){const o=n.createTracker(r);let l=o.move("[^");const s=n.enter("footnoteReference"),a=n.enter("reference");return l+=o.move(n.safe(n.associationId(e),{after:"]",before:l})),a(),s(),l+=o.move("]"),l}function wp(){return{enter:{gfmFootnoteCallString:hp,gfmFootnoteCall:gp,gfmFootnoteDefinitionLabelString:xp,gfmFootnoteDefinition:mp},exit:{gfmFootnoteCallString:bp,gfmFootnoteCall:yp,gfmFootnoteDefinitionLabelString:kp,gfmFootnoteDefinition:vp}}}function jp(e){let t=!1;return e&&e.firstLineBlank&&(t=!0),{handlers:{footnoteDefinition:n,footnoteReference:Ho},unsafe:[{character:"[",inConstruct:["label","phrasing","reference"]}]};function n(r,o,l,s){const a=l.createTracker(s);let c=a.move("[^");const u=l.enter("footnoteDefinition"),p=l.enter("label");return c+=a.move(l.safe(l.associationId(r),{before:c,after:"]"})),p(),c+=a.move("]:"),r.children&&r.children.length>0&&(a.shift(4),c+=a.move((t?`
15
- `:" ")+l.indentLines(l.containerFlow(r,a.current()),t?Uo:Cp))),u(),c}}function Cp(e,t,n){return t===0?e:Uo(e,t,n)}function Uo(e,t,n){return(n?"":" ")+e}const Ip=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"];Vo.peek=Rp;function Ep(){return{canContainEols:["delete"],enter:{strikethrough:_p},exit:{strikethrough:zp}}}function Tp(){return{unsafe:[{character:"~",inConstruct:"phrasing",notInConstruct:Ip}],handlers:{delete:Vo}}}function _p(e){this.enter({type:"delete",children:[]},e)}function zp(e){this.exit(e)}function Vo(e,t,n,r){const o=n.createTracker(r),l=n.enter("strikethrough");let s=o.move("~~");return s+=n.containerPhrasing(e,{...o.current(),before:s,after:"~"}),s+=o.move("~~"),l(),s}function Rp(){return"~"}function Lp(e){return e.length}function Ap(e,t){const n=t||{},r=(n.align||[]).concat(),o=n.stringLength||Lp,l=[],s=[],a=[],c=[];let u=0,p=-1;for(;++p<e.length;){const b=[],x=[];let m=-1;for(e[p].length>u&&(u=e[p].length);++m<e[p].length;){const k=Bp(e[p][m]);if(n.alignDelimiters!==!1){const w=o(k);x[m]=w,(c[m]===void 0||w>c[m])&&(c[m]=w)}b.push(k)}s[p]=b,a[p]=x}let d=-1;if(typeof r=="object"&&"length"in r)for(;++d<u;)l[d]=hi(r[d]);else{const b=hi(r);for(;++d<u;)l[d]=b}d=-1;const h=[],f=[];for(;++d<u;){const b=l[d];let x="",m="";b===99?(x=":",m=":"):b===108?x=":":b===114&&(m=":");let k=n.alignDelimiters===!1?1:Math.max(1,c[d]-x.length-m.length);const w=x+"-".repeat(k)+m;n.alignDelimiters!==!1&&(k=x.length+k+m.length,k>c[d]&&(c[d]=k),f[d]=k),h[d]=w}s.splice(1,0,h),a.splice(1,0,f),p=-1;const g=[];for(;++p<s.length;){const b=s[p],x=a[p];d=-1;const m=[];for(;++d<u;){const k=b[d]||"";let w="",_="";if(n.alignDelimiters!==!1){const I=c[d]-(x[d]||0),S=l[d];S===114?w=" ".repeat(I):S===99?I%2?(w=" ".repeat(I/2+.5),_=" ".repeat(I/2-.5)):(w=" ".repeat(I/2),_=w):_=" ".repeat(I)}n.delimiterStart!==!1&&!d&&m.push("|"),n.padding!==!1&&!(n.alignDelimiters===!1&&k==="")&&(n.delimiterStart!==!1||d)&&m.push(" "),n.alignDelimiters!==!1&&m.push(w),m.push(k),n.alignDelimiters!==!1&&m.push(_),n.padding!==!1&&m.push(" "),(n.delimiterEnd!==!1||d!==u-1)&&m.push("|")}g.push(n.delimiterEnd===!1?m.join("").replace(/ +$/,""):m.join(""))}return g.join(`
16
- `)}function Bp(e){return e==null?"":String(e)}function hi(e){const t=typeof e=="string"?e.codePointAt(0):0;return t===67||t===99?99:t===76||t===108?108:t===82||t===114?114:0}function Pp(e,t,n,r){const o=n.enter("blockquote"),l=n.createTracker(r);l.move("> "),l.shift(2);const s=n.indentLines(n.containerFlow(e,l.current()),Fp);return o(),s}function Fp(e,t,n){return">"+(n?"":" ")+e}function Dp(e,t){return gi(e,t.inConstruct,!0)&&!gi(e,t.notInConstruct,!1)}function gi(e,t,n){if(typeof t=="string"&&(t=[t]),!t||t.length===0)return n;let r=-1;for(;++r<t.length;)if(e.includes(t[r]))return!0;return!1}function xi(e,t,n,r){let o=-1;for(;++o<n.unsafe.length;)if(n.unsafe[o].character===`
17
- `&&Dp(n.stack,n.unsafe[o]))return/[ \t]/.test(r.before)?"":" ";return`\\
18
- `}function Mp(e,t){const n=String(e);let r=n.indexOf(t),o=r,l=0,s=0;if(typeof t!="string")throw new TypeError("Expected substring");for(;r!==-1;)r===o?++l>s&&(s=l):l=1,o=r+t.length,r=n.indexOf(t,o);return s}function Op(e,t){return!!(t.options.fences===!1&&e.value&&!e.lang&&/[^ \r\n]/.test(e.value)&&!/^[\t ]*(?:[\r\n]|$)|(?:^|[\r\n])[\t ]*$/.test(e.value))}function Wp(e){const t=e.options.fence||"`";if(t!=="`"&&t!=="~")throw new Error("Cannot serialize code with `"+t+"` for `options.fence`, expected `` ` `` or `~`");return t}function $p(e,t,n,r){const o=Wp(n),l=e.value||"",s=o==="`"?"GraveAccent":"Tilde";if(Op(e,n)){const d=n.enter("codeIndented"),h=n.indentLines(l,Np);return d(),h}const a=n.createTracker(r),c=o.repeat(Math.max(Mp(l,o)+1,3)),u=n.enter("codeFenced");let p=a.move(c);if(e.lang){const d=n.enter(`codeFencedLang${s}`);p+=a.move(n.safe(e.lang,{before:p,after:" ",encode:["`"],...a.current()})),d()}if(e.lang&&e.meta){const d=n.enter(`codeFencedMeta${s}`);p+=a.move(" "),p+=a.move(n.safe(e.meta,{before:p,after:`
19
- `,encode:["`"],...a.current()})),d()}return p+=a.move(`
20
- `),l&&(p+=a.move(l+`
21
- `)),p+=a.move(c),u(),p}function Np(e,t,n){return(n?"":" ")+e}function gr(e){const t=e.options.quote||'"';if(t!=='"'&&t!=="'")throw new Error("Cannot serialize title with `"+t+"` for `options.quote`, expected `\"`, or `'`");return t}function Hp(e,t,n,r){const o=gr(n),l=o==='"'?"Quote":"Apostrophe",s=n.enter("definition");let a=n.enter("label");const c=n.createTracker(r);let u=c.move("[");return u+=c.move(n.safe(n.associationId(e),{before:u,after:"]",...c.current()})),u+=c.move("]: "),a(),!e.url||/[\0- \u007F]/.test(e.url)?(a=n.enter("destinationLiteral"),u+=c.move("<"),u+=c.move(n.safe(e.url,{before:u,after:">",...c.current()})),u+=c.move(">")):(a=n.enter("destinationRaw"),u+=c.move(n.safe(e.url,{before:u,after:e.title?" ":`
22
- `,...c.current()}))),a(),e.title&&(a=n.enter(`title${l}`),u+=c.move(" "+o),u+=c.move(n.safe(e.title,{before:u,after:o,...c.current()})),u+=c.move(o),a()),s(),u}function Up(e){const t=e.options.emphasis||"*";if(t!=="*"&&t!=="_")throw new Error("Cannot serialize emphasis with `"+t+"` for `options.emphasis`, expected `*`, or `_`");return t}function Wt(e){return"&#x"+e.toString(16).toUpperCase()+";"}function ln(e,t,n){const r=ht(e),o=ht(t);return r===void 0?o===void 0?n==="_"?{inside:!0,outside:!0}:{inside:!1,outside:!1}:o===1?{inside:!0,outside:!0}:{inside:!1,outside:!0}:r===1?o===void 0?{inside:!1,outside:!1}:o===1?{inside:!0,outside:!0}:{inside:!1,outside:!1}:o===void 0?{inside:!1,outside:!1}:o===1?{inside:!0,outside:!1}:{inside:!1,outside:!1}}qo.peek=Vp;function qo(e,t,n,r){const o=Up(n),l=n.enter("emphasis"),s=n.createTracker(r),a=s.move(o);let c=s.move(n.containerPhrasing(e,{after:o,before:a,...s.current()}));const u=c.charCodeAt(0),p=ln(r.before.charCodeAt(r.before.length-1),u,o);p.inside&&(c=Wt(u)+c.slice(1));const d=c.charCodeAt(c.length-1),h=ln(r.after.charCodeAt(0),d,o);h.inside&&(c=c.slice(0,-1)+Wt(d));const f=s.move(o);return l(),n.attentionEncodeSurroundingInfo={after:h.outside,before:p.outside},a+c+f}function Vp(e,t,n){return n.options.emphasis||"*"}function qp(e,t){let n=!1;return fr(e,function(r){if("value"in r&&/\r?\n|\r/.test(r.value)||r.type==="break")return n=!0,Vn}),!!((!e.depth||e.depth<3)&&lr(e)&&(t.options.setext||n))}function Yp(e,t,n,r){const o=Math.max(Math.min(6,e.depth||1),1),l=n.createTracker(r);if(qp(e,n)){const p=n.enter("headingSetext"),d=n.enter("phrasing"),h=n.containerPhrasing(e,{...l.current(),before:`
23
- `,after:`
24
- `});return d(),p(),h+`
25
- `+(o===1?"=":"-").repeat(h.length-(Math.max(h.lastIndexOf("\r"),h.lastIndexOf(`
26
- `))+1))}const s="#".repeat(o),a=n.enter("headingAtx"),c=n.enter("phrasing");l.move(s+" ");let u=n.containerPhrasing(e,{before:"# ",after:`
27
- `,...l.current()});return/^[\t ]/.test(u)&&(u=Wt(u.charCodeAt(0))+u.slice(1)),u=u?s+" "+u:s,n.options.closeAtx&&(u+=" "+s),c(),a(),u}Yo.peek=Gp;function Yo(e){return e.value||""}function Gp(){return"<"}Go.peek=Kp;function Go(e,t,n,r){const o=gr(n),l=o==='"'?"Quote":"Apostrophe",s=n.enter("image");let a=n.enter("label");const c=n.createTracker(r);let u=c.move("![");return u+=c.move(n.safe(e.alt,{before:u,after:"]",...c.current()})),u+=c.move("]("),a(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(a=n.enter("destinationLiteral"),u+=c.move("<"),u+=c.move(n.safe(e.url,{before:u,after:">",...c.current()})),u+=c.move(">")):(a=n.enter("destinationRaw"),u+=c.move(n.safe(e.url,{before:u,after:e.title?" ":")",...c.current()}))),a(),e.title&&(a=n.enter(`title${l}`),u+=c.move(" "+o),u+=c.move(n.safe(e.title,{before:u,after:o,...c.current()})),u+=c.move(o),a()),u+=c.move(")"),s(),u}function Kp(){return"!"}Ko.peek=Xp;function Ko(e,t,n,r){const o=e.referenceType,l=n.enter("imageReference");let s=n.enter("label");const a=n.createTracker(r);let c=a.move("![");const u=n.safe(e.alt,{before:c,after:"]",...a.current()});c+=a.move(u+"]["),s();const p=n.stack;n.stack=[],s=n.enter("reference");const d=n.safe(n.associationId(e),{before:c,after:"]",...a.current()});return s(),n.stack=p,l(),o==="full"||!u||u!==d?c+=a.move(d+"]"):o==="shortcut"?c=c.slice(0,-1):c+=a.move("]"),c}function Xp(){return"!"}Xo.peek=Jp;function Xo(e,t,n){let r=e.value||"",o="`",l=-1;for(;new RegExp("(^|[^`])"+o+"([^`]|$)").test(r);)o+="`";for(/[^ \r\n]/.test(r)&&(/^[ \r\n]/.test(r)&&/[ \r\n]$/.test(r)||/^`|`$/.test(r))&&(r=" "+r+" ");++l<n.unsafe.length;){const s=n.unsafe[l],a=n.compilePattern(s);let c;if(s.atBreak)for(;c=a.exec(r);){let u=c.index;r.charCodeAt(u)===10&&r.charCodeAt(u-1)===13&&u--,r=r.slice(0,u)+" "+r.slice(c.index+1)}}return o+r+o}function Jp(){return"`"}function Jo(e,t){const n=lr(e);return!!(!t.options.resourceLink&&e.url&&!e.title&&e.children&&e.children.length===1&&e.children[0].type==="text"&&(n===e.url||"mailto:"+n===e.url)&&/^[a-z][a-z+.-]+:/i.test(e.url)&&!/[\0- <>\u007F]/.test(e.url))}Zo.peek=Zp;function Zo(e,t,n,r){const o=gr(n),l=o==='"'?"Quote":"Apostrophe",s=n.createTracker(r);let a,c;if(Jo(e,n)){const p=n.stack;n.stack=[],a=n.enter("autolink");let d=s.move("<");return d+=s.move(n.containerPhrasing(e,{before:d,after:">",...s.current()})),d+=s.move(">"),a(),n.stack=p,d}a=n.enter("link"),c=n.enter("label");let u=s.move("[");return u+=s.move(n.containerPhrasing(e,{before:u,after:"](",...s.current()})),u+=s.move("]("),c(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(c=n.enter("destinationLiteral"),u+=s.move("<"),u+=s.move(n.safe(e.url,{before:u,after:">",...s.current()})),u+=s.move(">")):(c=n.enter("destinationRaw"),u+=s.move(n.safe(e.url,{before:u,after:e.title?" ":")",...s.current()}))),c(),e.title&&(c=n.enter(`title${l}`),u+=s.move(" "+o),u+=s.move(n.safe(e.title,{before:u,after:o,...s.current()})),u+=s.move(o),c()),u+=s.move(")"),a(),u}function Zp(e,t,n){return Jo(e,n)?"<":"["}Qo.peek=Qp;function Qo(e,t,n,r){const o=e.referenceType,l=n.enter("linkReference");let s=n.enter("label");const a=n.createTracker(r);let c=a.move("[");const u=n.containerPhrasing(e,{before:c,after:"]",...a.current()});c+=a.move(u+"]["),s();const p=n.stack;n.stack=[],s=n.enter("reference");const d=n.safe(n.associationId(e),{before:c,after:"]",...a.current()});return s(),n.stack=p,l(),o==="full"||!u||u!==d?c+=a.move(d+"]"):o==="shortcut"?c=c.slice(0,-1):c+=a.move("]"),c}function Qp(){return"["}function xr(e){const t=e.options.bullet||"*";if(t!=="*"&&t!=="+"&&t!=="-")throw new Error("Cannot serialize items with `"+t+"` for `options.bullet`, expected `*`, `+`, or `-`");return t}function ef(e){const t=xr(e),n=e.options.bulletOther;if(!n)return t==="*"?"-":"*";if(n!=="*"&&n!=="+"&&n!=="-")throw new Error("Cannot serialize items with `"+n+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(n===t)throw new Error("Expected `bullet` (`"+t+"`) and `bulletOther` (`"+n+"`) to be different");return n}function tf(e){const t=e.options.bulletOrdered||".";if(t!=="."&&t!==")")throw new Error("Cannot serialize items with `"+t+"` for `options.bulletOrdered`, expected `.` or `)`");return t}function el(e){const t=e.options.rule||"*";if(t!=="*"&&t!=="-"&&t!=="_")throw new Error("Cannot serialize rules with `"+t+"` for `options.rule`, expected `*`, `-`, or `_`");return t}function nf(e,t,n,r){const o=n.enter("list"),l=n.bulletCurrent;let s=e.ordered?tf(n):xr(n);const a=e.ordered?s==="."?")":".":ef(n);let c=t&&n.bulletLastUsed?s===n.bulletLastUsed:!1;if(!e.ordered){const p=e.children?e.children[0]:void 0;if((s==="*"||s==="-")&&p&&(!p.children||!p.children[0])&&n.stack[n.stack.length-1]==="list"&&n.stack[n.stack.length-2]==="listItem"&&n.stack[n.stack.length-3]==="list"&&n.stack[n.stack.length-4]==="listItem"&&n.indexStack[n.indexStack.length-1]===0&&n.indexStack[n.indexStack.length-2]===0&&n.indexStack[n.indexStack.length-3]===0&&(c=!0),el(n)===s&&p){let d=-1;for(;++d<e.children.length;){const h=e.children[d];if(h&&h.type==="listItem"&&h.children&&h.children[0]&&h.children[0].type==="thematicBreak"){c=!0;break}}}}c&&(s=a),n.bulletCurrent=s;const u=n.containerFlow(e,r);return n.bulletLastUsed=s,n.bulletCurrent=l,o(),u}function rf(e){const t=e.options.listItemIndent||"one";if(t!=="tab"&&t!=="one"&&t!=="mixed")throw new Error("Cannot serialize items with `"+t+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return t}function of(e,t,n,r){const o=rf(n);let l=n.bulletCurrent||xr(n);t&&t.type==="list"&&t.ordered&&(l=(typeof t.start=="number"&&t.start>-1?t.start:1)+(n.options.incrementListMarker===!1?0:t.children.indexOf(e))+l);let s=l.length+1;(o==="tab"||o==="mixed"&&(t&&t.type==="list"&&t.spread||e.spread))&&(s=Math.ceil(s/4)*4);const a=n.createTracker(r);a.move(l+" ".repeat(s-l.length)),a.shift(s);const c=n.enter("listItem"),u=n.indentLines(n.containerFlow(e,a.current()),p);return c(),u;function p(d,h,f){return h?(f?"":" ".repeat(s))+d:(f?l:l+" ".repeat(s-l.length))+d}}function lf(e,t,n,r){const o=n.enter("paragraph"),l=n.enter("phrasing"),s=n.containerPhrasing(e,r);return l(),o(),s}const sf=fn(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function af(e,t,n,r){return(e.children.some(function(s){return sf(s)})?n.containerPhrasing:n.containerFlow).call(n,e,r)}function cf(e){const t=e.options.strong||"*";if(t!=="*"&&t!=="_")throw new Error("Cannot serialize strong with `"+t+"` for `options.strong`, expected `*`, or `_`");return t}tl.peek=uf;function tl(e,t,n,r){const o=cf(n),l=n.enter("strong"),s=n.createTracker(r),a=s.move(o+o);let c=s.move(n.containerPhrasing(e,{after:o,before:a,...s.current()}));const u=c.charCodeAt(0),p=ln(r.before.charCodeAt(r.before.length-1),u,o);p.inside&&(c=Wt(u)+c.slice(1));const d=c.charCodeAt(c.length-1),h=ln(r.after.charCodeAt(0),d,o);h.inside&&(c=c.slice(0,-1)+Wt(d));const f=s.move(o+o);return l(),n.attentionEncodeSurroundingInfo={after:h.outside,before:p.outside},a+c+f}function uf(e,t,n){return n.options.strong||"*"}function df(e,t,n,r){return n.safe(e.value,r)}function pf(e){const t=e.options.ruleRepetition||3;if(t<3)throw new Error("Cannot serialize rules with repetition `"+t+"` for `options.ruleRepetition`, expected `3` or more");return t}function ff(e,t,n){const r=(el(n)+(n.options.ruleSpaces?" ":"")).repeat(pf(n));return n.options.ruleSpaces?r.slice(0,-1):r}const nl={blockquote:Pp,break:xi,code:$p,definition:Hp,emphasis:qo,hardBreak:xi,heading:Yp,html:Yo,image:Go,imageReference:Ko,inlineCode:Xo,link:Zo,linkReference:Qo,list:nf,listItem:of,paragraph:lf,root:af,strong:tl,text:df,thematicBreak:ff};function hf(){return{enter:{table:gf,tableData:mi,tableHeader:mi,tableRow:mf},exit:{codeText:bf,table:xf,tableData:Ln,tableHeader:Ln,tableRow:Ln}}}function gf(e){const t=e._align;this.enter({type:"table",align:t.map(function(n){return n==="none"?null:n}),children:[]},e),this.data.inTable=!0}function xf(e){this.exit(e),this.data.inTable=void 0}function mf(e){this.enter({type:"tableRow",children:[]},e)}function Ln(e){this.exit(e)}function mi(e){this.enter({type:"tableCell",children:[]},e)}function bf(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,yf));const n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function yf(e,t){return t==="|"?t:e}function kf(e){const t=e||{},n=t.tableCellPadding,r=t.tablePipeAlign,o=t.stringLength,l=n?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:`
28
- `,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:h,table:s,tableCell:c,tableRow:a}};function s(f,g,b,x){return u(p(f,b,x),f.align)}function a(f,g,b,x){const m=d(f,b,x),k=u([m]);return k.slice(0,k.indexOf(`
29
- `))}function c(f,g,b,x){const m=b.enter("tableCell"),k=b.enter("phrasing"),w=b.containerPhrasing(f,{...x,before:l,after:l});return k(),m(),w}function u(f,g){return Ap(f,{align:g,alignDelimiters:r,padding:n,stringLength:o})}function p(f,g,b){const x=f.children;let m=-1;const k=[],w=g.enter("table");for(;++m<x.length;)k[m]=d(x[m],g,b);return w(),k}function d(f,g,b){const x=f.children;let m=-1;const k=[],w=g.enter("tableRow");for(;++m<x.length;)k[m]=c(x[m],f,g,b);return w(),k}function h(f,g,b){let x=nl.inlineCode(f,g,b);return b.stack.includes("tableCell")&&(x=x.replace(/\|/g,"\\$&")),x}}function vf(){return{exit:{taskListCheckValueChecked:bi,taskListCheckValueUnchecked:bi,paragraph:wf}}}function Sf(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:jf}}}function bi(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function wf(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const r=n.children[0];if(r&&r.type==="text"){const o=t.children;let l=-1,s;for(;++l<o.length;){const a=o[l];if(a.type==="paragraph"){s=a;break}}s===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(e)}function jf(e,t,n,r){const o=e.children[0],l=typeof e.checked=="boolean"&&o&&o.type==="paragraph",s="["+(e.checked?"x":" ")+"] ",a=n.createTracker(r);l&&a.move(s);let c=nl.listItem(e,t,n,{...r,...a.current()});return l&&(c=c.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,u)),c;function u(p){return p+s}}function Cf(){return[np(),wp(),Ep(),hf(),vf()]}function If(e){return{extensions:[rp(),jp(e),Tp(),kf(e),Sf()]}}const Ef={tokenize:Af,partial:!0},rl={tokenize:Bf,partial:!0},il={tokenize:Pf,partial:!0},ol={tokenize:Ff,partial:!0},Tf={tokenize:Df,partial:!0},ll={name:"wwwAutolink",tokenize:Rf,previous:al},sl={name:"protocolAutolink",tokenize:Lf,previous:cl},Ye={name:"emailAutolink",tokenize:zf,previous:ul},He={};function _f(){return{text:He}}let Qe=48;for(;Qe<123;)He[Qe]=Ye,Qe++,Qe===58?Qe=65:Qe===91&&(Qe=97);He[43]=Ye;He[45]=Ye;He[46]=Ye;He[95]=Ye;He[72]=[Ye,sl];He[104]=[Ye,sl];He[87]=[Ye,ll];He[119]=[Ye,ll];function zf(e,t,n){const r=this;let o,l;return s;function s(d){return!Kn(d)||!ul.call(r,r.previous)||mr(r.events)?n(d):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),a(d))}function a(d){return Kn(d)?(e.consume(d),a):d===64?(e.consume(d),c):n(d)}function c(d){return d===46?e.check(Tf,p,u)(d):d===45||d===95||xe(d)?(l=!0,e.consume(d),c):p(d)}function u(d){return e.consume(d),o=!0,c}function p(d){return l&&o&&ve(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(d)):n(d)}}function Rf(e,t,n){const r=this;return o;function o(s){return s!==87&&s!==119||!al.call(r,r.previous)||mr(r.events)?n(s):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(Ef,e.attempt(rl,e.attempt(il,l),n),n)(s))}function l(s){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(s)}}function Lf(e,t,n){const r=this;let o="",l=!1;return s;function s(d){return(d===72||d===104)&&cl.call(r,r.previous)&&!mr(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),o+=String.fromCodePoint(d),e.consume(d),a):n(d)}function a(d){if(ve(d)&&o.length<5)return o+=String.fromCodePoint(d),e.consume(d),a;if(d===58){const h=o.toLowerCase();if(h==="http"||h==="https")return e.consume(d),c}return n(d)}function c(d){return d===47?(e.consume(d),l?u:(l=!0,c)):n(d)}function u(d){return d===null||nn(d)||le(d)||nt(d)||un(d)?n(d):e.attempt(rl,e.attempt(il,p),n)(d)}function p(d){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(d)}}function Af(e,t,n){let r=0;return o;function o(s){return(s===87||s===119)&&r<3?(r++,e.consume(s),o):s===46&&r===3?(e.consume(s),l):n(s)}function l(s){return s===null?n(s):t(s)}}function Bf(e,t,n){let r,o,l;return s;function s(u){return u===46||u===95?e.check(ol,c,a)(u):u===null||le(u)||nt(u)||u!==45&&un(u)?c(u):(l=!0,e.consume(u),s)}function a(u){return u===95?r=!0:(o=r,r=void 0),e.consume(u),s}function c(u){return o||r||!l?n(u):t(u)}}function Pf(e,t){let n=0,r=0;return o;function o(s){return s===40?(n++,e.consume(s),o):s===41&&r<n?l(s):s===33||s===34||s===38||s===39||s===41||s===42||s===44||s===46||s===58||s===59||s===60||s===63||s===93||s===95||s===126?e.check(ol,t,l)(s):s===null||le(s)||nt(s)?t(s):(e.consume(s),o)}function l(s){return s===41&&r++,e.consume(s),o}}function Ff(e,t,n){return r;function r(a){return a===33||a===34||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===63||a===95||a===126?(e.consume(a),r):a===38?(e.consume(a),l):a===93?(e.consume(a),o):a===60||a===null||le(a)||nt(a)?t(a):n(a)}function o(a){return a===null||a===40||a===91||le(a)||nt(a)?t(a):r(a)}function l(a){return ve(a)?s(a):n(a)}function s(a){return a===59?(e.consume(a),r):ve(a)?(e.consume(a),s):n(a)}}function Df(e,t,n){return r;function r(l){return e.consume(l),o}function o(l){return xe(l)?n(l):t(l)}}function al(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||le(e)}function cl(e){return!ve(e)}function ul(e){return!(e===47||Kn(e))}function Kn(e){return e===43||e===45||e===46||e===95||xe(e)}function mr(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const Mf={tokenize:qf,partial:!0};function Of(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:Hf,continuation:{tokenize:Uf},exit:Vf}},text:{91:{name:"gfmFootnoteCall",tokenize:Nf},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Wf,resolveTo:$f}}}}function Wf(e,t,n){const r=this;let o=r.events.length;const l=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s;for(;o--;){const c=r.events[o][1];if(c.type==="labelImage"){s=c;break}if(c.type==="gfmFootnoteCall"||c.type==="labelLink"||c.type==="label"||c.type==="image"||c.type==="link")break}return a;function a(c){if(!s||!s._balanced)return n(c);const u=Pe(r.sliceSerialize({start:s.end,end:r.now()}));return u.codePointAt(0)!==94||!l.includes(u.slice(1))?n(c):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(c),e.exit("gfmFootnoteCallLabelMarker"),t(c))}}function $f(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},o={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};o.end.column++,o.end.offset++,o.end._bufferIndex++;const l={type:"gfmFootnoteCallString",start:Object.assign({},o.end),end:Object.assign({},e[e.length-1][1].start)},s={type:"chunkString",contentType:"string",start:Object.assign({},l.start),end:Object.assign({},l.end)},a=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",o,t],["exit",o,t],["enter",l,t],["enter",s,t],["exit",s,t],["exit",l,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...a),e}function Nf(e,t,n){const r=this,o=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let l=0,s;return a;function a(d){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),c}function c(d){return d!==94?n(d):(e.enter("gfmFootnoteCallMarker"),e.consume(d),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",u)}function u(d){if(l>999||d===93&&!s||d===null||d===91||le(d))return n(d);if(d===93){e.exit("chunkString");const h=e.exit("gfmFootnoteCallString");return o.includes(Pe(r.sliceSerialize(h)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(d)}return le(d)||(s=!0),l++,e.consume(d),d===92?p:u}function p(d){return d===91||d===92||d===93?(e.consume(d),l++,u):u(d)}}function Hf(e,t,n){const r=this,o=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let l,s=0,a;return c;function c(g){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(g),e.exit("gfmFootnoteDefinitionLabelMarker"),u}function u(g){return g===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(g),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",p):n(g)}function p(g){if(s>999||g===93&&!a||g===null||g===91||le(g))return n(g);if(g===93){e.exit("chunkString");const b=e.exit("gfmFootnoteDefinitionLabelString");return l=Pe(r.sliceSerialize(b)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(g),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),h}return le(g)||(a=!0),s++,e.consume(g),g===92?d:p}function d(g){return g===91||g===92||g===93?(e.consume(g),s++,p):p(g)}function h(g){return g===58?(e.enter("definitionMarker"),e.consume(g),e.exit("definitionMarker"),o.includes(l)||o.push(l),te(e,f,"gfmFootnoteDefinitionWhitespace")):n(g)}function f(g){return t(g)}}function Uf(e,t,n){return e.check(Ut,t,e.attempt(Mf,t,n))}function Vf(e){e.exit("gfmFootnoteDefinition")}function qf(e,t,n){const r=this;return te(e,o,"gfmFootnoteDefinitionIndent",5);function o(l){const s=r.events[r.events.length-1];return s&&s[1].type==="gfmFootnoteDefinitionIndent"&&s[2].sliceSerialize(s[1],!0).length===4?t(l):n(l)}}function Yf(e){let n=(e||{}).singleTilde;const r={name:"strikethrough",tokenize:l,resolveAll:o};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function o(s,a){let c=-1;for(;++c<s.length;)if(s[c][0]==="enter"&&s[c][1].type==="strikethroughSequenceTemporary"&&s[c][1]._close){let u=c;for(;u--;)if(s[u][0]==="exit"&&s[u][1].type==="strikethroughSequenceTemporary"&&s[u][1]._open&&s[c][1].end.offset-s[c][1].start.offset===s[u][1].end.offset-s[u][1].start.offset){s[c][1].type="strikethroughSequence",s[u][1].type="strikethroughSequence";const p={type:"strikethrough",start:Object.assign({},s[u][1].start),end:Object.assign({},s[c][1].end)},d={type:"strikethroughText",start:Object.assign({},s[u][1].end),end:Object.assign({},s[c][1].start)},h=[["enter",p,a],["enter",s[u][1],a],["exit",s[u][1],a],["enter",d,a]],f=a.parser.constructs.insideSpan.null;f&&Ee(h,h.length,0,dn(f,s.slice(u+1,c),a)),Ee(h,h.length,0,[["exit",d,a],["enter",s[c][1],a],["exit",s[c][1],a],["exit",p,a]]),Ee(s,u-1,c-u+3,h),c=u+h.length-2;break}}for(c=-1;++c<s.length;)s[c][1].type==="strikethroughSequenceTemporary"&&(s[c][1].type="data");return s}function l(s,a,c){const u=this.previous,p=this.events;let d=0;return h;function h(g){return u===126&&p[p.length-1][1].type!=="characterEscape"?c(g):(s.enter("strikethroughSequenceTemporary"),f(g))}function f(g){const b=ht(u);if(g===126)return d>1?c(g):(s.consume(g),d++,f);if(d<2&&!n)return c(g);const x=s.exit("strikethroughSequenceTemporary"),m=ht(g);return x._open=!m||m===2&&!!b,x._close=!b||b===2&&!!m,a(g)}}}class Gf{constructor(){this.map=[]}add(t,n,r){Kf(this,t,n,r)}consume(t){if(this.map.sort(function(l,s){return l[0]-s[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];r.push(t.slice()),t.length=0;let o=r.pop();for(;o;){for(const l of o)t.push(l);o=r.pop()}this.map.length=0}}function Kf(e,t,n,r){let o=0;if(!(n===0&&r.length===0)){for(;o<e.map.length;){if(e.map[o][0]===t){e.map[o][1]+=n,e.map[o][2].push(...r);return}o+=1}e.map.push([t,n,r])}}function Xf(e,t){let n=!1;const r=[];for(;t<e.length;){const o=e[t];if(n){if(o[0]==="enter")o[1].type==="tableContent"&&r.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(o[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const l=r.length-1;r[l]=r[l]==="left"?"center":"right"}}else if(o[1].type==="tableDelimiterRow")break}else o[0]==="enter"&&o[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return r}function Jf(){return{flow:{null:{name:"table",tokenize:Zf,resolveAll:Qf}}}}function Zf(e,t,n){const r=this;let o=0,l=0,s;return a;function a(C){let E=r.events.length-1;for(;E>-1;){const P=r.events[E][1].type;if(P==="lineEnding"||P==="linePrefix")E--;else break}const A=E>-1?r.events[E][1].type:null,$=A==="tableHead"||A==="tableRow"?S:c;return $===S&&r.parser.lazy[r.now().line]?n(C):$(C)}function c(C){return e.enter("tableHead"),e.enter("tableRow"),u(C)}function u(C){return C===124||(s=!0,l+=1),p(C)}function p(C){return C===null?n(C):H(C)?l>1?(l=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(C),e.exit("lineEnding"),f):n(C):J(C)?te(e,p,"whitespace")(C):(l+=1,s&&(s=!1,o+=1),C===124?(e.enter("tableCellDivider"),e.consume(C),e.exit("tableCellDivider"),s=!0,p):(e.enter("data"),d(C)))}function d(C){return C===null||C===124||le(C)?(e.exit("data"),p(C)):(e.consume(C),C===92?h:d)}function h(C){return C===92||C===124?(e.consume(C),d):d(C)}function f(C){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(C):(e.enter("tableDelimiterRow"),s=!1,J(C)?te(e,g,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(C):g(C))}function g(C){return C===45||C===58?x(C):C===124?(s=!0,e.enter("tableCellDivider"),e.consume(C),e.exit("tableCellDivider"),b):I(C)}function b(C){return J(C)?te(e,x,"whitespace")(C):x(C)}function x(C){return C===58?(l+=1,s=!0,e.enter("tableDelimiterMarker"),e.consume(C),e.exit("tableDelimiterMarker"),m):C===45?(l+=1,m(C)):C===null||H(C)?_(C):I(C)}function m(C){return C===45?(e.enter("tableDelimiterFiller"),k(C)):I(C)}function k(C){return C===45?(e.consume(C),k):C===58?(s=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(C),e.exit("tableDelimiterMarker"),w):(e.exit("tableDelimiterFiller"),w(C))}function w(C){return J(C)?te(e,_,"whitespace")(C):_(C)}function _(C){return C===124?g(C):C===null||H(C)?!s||o!==l?I(C):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(C)):I(C)}function I(C){return n(C)}function S(C){return e.enter("tableRow"),T(C)}function T(C){return C===124?(e.enter("tableCellDivider"),e.consume(C),e.exit("tableCellDivider"),T):C===null||H(C)?(e.exit("tableRow"),t(C)):J(C)?te(e,T,"whitespace")(C):(e.enter("data"),z(C))}function z(C){return C===null||C===124||le(C)?(e.exit("data"),T(C)):(e.consume(C),C===92?B:z)}function B(C){return C===92||C===124?(e.consume(C),z):z(C)}}function Qf(e,t){let n=-1,r=!0,o=0,l=[0,0,0,0],s=[0,0,0,0],a=!1,c=0,u,p,d;const h=new Gf;for(;++n<e.length;){const f=e[n],g=f[1];f[0]==="enter"?g.type==="tableHead"?(a=!1,c!==0&&(yi(h,t,c,u,p),p=void 0,c=0),u={type:"table",start:Object.assign({},g.start),end:Object.assign({},g.end)},h.add(n,0,[["enter",u,t]])):g.type==="tableRow"||g.type==="tableDelimiterRow"?(r=!0,d=void 0,l=[0,0,0,0],s=[0,n+1,0,0],a&&(a=!1,p={type:"tableBody",start:Object.assign({},g.start),end:Object.assign({},g.end)},h.add(n,0,[["enter",p,t]])),o=g.type==="tableDelimiterRow"?2:p?3:1):o&&(g.type==="data"||g.type==="tableDelimiterMarker"||g.type==="tableDelimiterFiller")?(r=!1,s[2]===0&&(l[1]!==0&&(s[0]=s[1],d=Kt(h,t,l,o,void 0,d),l=[0,0,0,0]),s[2]=n)):g.type==="tableCellDivider"&&(r?r=!1:(l[1]!==0&&(s[0]=s[1],d=Kt(h,t,l,o,void 0,d)),l=s,s=[l[1],n,0,0])):g.type==="tableHead"?(a=!0,c=n):g.type==="tableRow"||g.type==="tableDelimiterRow"?(c=n,l[1]!==0?(s[0]=s[1],d=Kt(h,t,l,o,n,d)):s[1]!==0&&(d=Kt(h,t,s,o,n,d)),o=0):o&&(g.type==="data"||g.type==="tableDelimiterMarker"||g.type==="tableDelimiterFiller")&&(s[3]=n)}for(c!==0&&yi(h,t,c,u,p),h.consume(t.events),n=-1;++n<t.events.length;){const f=t.events[n];f[0]==="enter"&&f[1].type==="table"&&(f[1]._align=Xf(t.events,n))}return e}function Kt(e,t,n,r,o,l){const s=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",a="tableContent";n[0]!==0&&(l.end=Object.assign({},pt(t.events,n[0])),e.add(n[0],0,[["exit",l,t]]));const c=pt(t.events,n[1]);if(l={type:s,start:Object.assign({},c),end:Object.assign({},c)},e.add(n[1],0,[["enter",l,t]]),n[2]!==0){const u=pt(t.events,n[2]),p=pt(t.events,n[3]),d={type:a,start:Object.assign({},u),end:Object.assign({},p)};if(e.add(n[2],0,[["enter",d,t]]),r!==2){const h=t.events[n[2]],f=t.events[n[3]];if(h[1].end=Object.assign({},f[1].end),h[1].type="chunkText",h[1].contentType="text",n[3]>n[2]+1){const g=n[2]+1,b=n[3]-n[2]-1;e.add(g,b,[])}}e.add(n[3]+1,0,[["exit",d,t]])}return o!==void 0&&(l.end=Object.assign({},pt(t.events,o)),e.add(o,0,[["exit",l,t]]),l=void 0),l}function yi(e,t,n,r,o){const l=[],s=pt(t.events,n);o&&(o.end=Object.assign({},s),l.push(["exit",o,t])),r.end=Object.assign({},s),l.push(["exit",r,t]),e.add(n+1,0,l)}function pt(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const eh={name:"tasklistCheck",tokenize:nh};function th(){return{text:{91:eh}}}function nh(e,t,n){const r=this;return o;function o(c){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(c):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(c),e.exit("taskListCheckMarker"),l)}function l(c){return le(c)?(e.enter("taskListCheckValueUnchecked"),e.consume(c),e.exit("taskListCheckValueUnchecked"),s):c===88||c===120?(e.enter("taskListCheckValueChecked"),e.consume(c),e.exit("taskListCheckValueChecked"),s):n(c)}function s(c){return c===93?(e.enter("taskListCheckMarker"),e.consume(c),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),a):n(c)}function a(c){return H(c)?t(c):J(c)?e.check({tokenize:rh},t,n)(c):n(c)}}function rh(e,t,n){return te(e,r,"whitespace");function r(o){return o===null?n(o):t(o)}}function ih(e){return vo([_f(),Of(),Yf(e),Jf(),th()])}const oh={};function lh(e){const t=this,n=e||oh,r=t.data(),o=r.micromarkExtensions||(r.micromarkExtensions=[]),l=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),s=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);o.push(ih(n)),l.push(Cf()),s.push(If(n))}const dl={p:({children:e})=>i.jsx("p",{style:{margin:"0 0 0.5em"},children:e}),ul:({children:e})=>i.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:e}),ol:({children:e})=>i.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:e}),li:({children:e})=>i.jsx("li",{style:{marginBottom:"2px"},children:e}),a:({href:e,children:t})=>i.jsx("a",{href:e,target:e!=null&&e.startsWith("http")?"_blank":void 0,rel:e!=null&&e.startsWith("http")?"noopener noreferrer":void 0,style:{color:"var(--bim-link, #1976d2)"},children:t}),code:({children:e})=>i.jsx("code",{style:{background:"var(--bim-bg-subtle, #f4f4f4)",padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})},sh={...dl,strong:({children:e})=>i.jsx(i.Fragment,{children:e})},Xn=({text:e,plainStrong:t,style:n,className:r})=>{const{convert:o}=X(),l=t?sh:dl;return i.jsx("div",{className:r,style:n,children:i.jsx(qd,{remarkPlugins:[lh],components:l,children:o(e)})})},ah=["〇","一","二","三","四","五","六","七","八","九"],ki=["","十","百","千"];function pl(e){if(e<=0)return"";if(e>=1e4)return String(e);const t=String(e),n=t.length;let r="",o=!1;for(let l=0;l<n;l++){const s=parseInt(t[l]),a=n-1-l;s===0?o=!0:(o&&r&&(r+="〇"),o=!1,s===1&&a===1&&l===0?r+=ki[a]:r+=ah[s]+ki[a])}return r}function ch({type:e}){const t=G(),n={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3",entity:"#5b3e8e"};return i.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:n[e],border:`1px solid ${n[e]}40`,borderRadius:"2px",background:`${n[e]}08`},children:t.indexType[e]})}function uh({isDraft:e}){const t=G();return i.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:e?"#e67e22":"#27ae60",border:`1px solid ${e?"#e67e2240":"#27ae6040"}`,borderRadius:"2px",background:e?"#e67e2208":"#27ae6008"},children:e?t.status.draft:t.status.official})}function dh({id:e}){const t=G(),[n,r]=v.useState(!1),o=()=>{navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return i.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",background:"#f6f6f6",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"2px"},children:[i.jsx("span",{children:t.label.id}),i.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:"var(--bim-fg, #333)"},children:e}),i.jsx("span",{onClick:o,title:n?t.action.copied:t.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:n?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=n?"1":"0.5",children:n?"✓":"⧉"})]})}function Re({children:e,extra:t}){return i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[i.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",letterSpacing:"1px"},children:e}),i.jsx("span",{style:{flex:1}}),t]})}function Ne({label:e,children:t}){return i.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[i.jsx("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:e}),i.jsx("span",{style:{color:"var(--bim-fg, #333)"},children:t})]})}function fl({authors:e,type:t,onNavigate:n,renderLink:r}){const{convert:o}=X();return i.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:e.map((l,s)=>{const a=o(l.name),c=l.entity_id?i.jsx(Be,{id:l.entity_id,label:a,onNavigate:n,renderLink:r}):i.jsx("span",{style:{fontWeight:500},children:a});return i.jsxs("span",{children:[s>0&&i.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),l.dynasty&&i.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",o(l.dynasty),"〕"]}),c,l.role&&i.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",o(l.role)]})]},s)})})}function Be({id:e,label:t,onNavigate:n,renderLink:r}){const o=Fe();return r?i.jsx(i.Fragment,{children:r(e,t)}):n?i.jsx("a",{href:o(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),n(e))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:t||e}):i.jsx("span",{children:t||e})}function ph({id:e,title:t,edition:n,type:r,isDraft:o,authors:l,volumeText:s,meta:a,headerExtra:c,onNavigate:u,renderLink:p}){return i.jsxs("div",{style:{marginBottom:"4px"},children:[i.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[i.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[t,n&&i.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:n}),s&&i.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:s})]}),c&&i.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:c})]}),i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[i.jsx(ch,{type:r}),i.jsx(uh,{isDraft:o}),i.jsx(dh,{id:e})]}),((l==null?void 0:l.length)||a.length>0)&&i.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&i.jsx(fl,{authors:l,type:r,onNavigate:u,renderLink:p}),a]})]})}function hl({items:e,label:t,showMeta:n,onNavigate:r,renderLink:o}){const l=G(),{convert:s}=X();if(!e.length)return null;const[a,c]=v.useState(null);return i.jsxs(i.Fragment,{children:[i.jsx(Re,{children:t}),i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((u,p)=>{const d=a===p;return i.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...d?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[i.jsxs("div",{onClick:()=>c(d?null:p),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[i.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:d?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),i.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:s(u.source)}),!d&&n&&u.title_info&&i.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s(u.title_info)}),u.source_bid&&i.jsx("span",{onClick:h=>h.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:i.jsx(Be,{id:u.source_bid,label:l.action.view,onNavigate:r,renderLink:o})})]}),d&&i.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[n&&(u.title_info||u.author_info||u.edition)&&i.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[u.title_info&&i.jsx(Ne,{label:l.label.titleInfo,children:s(u.title_info)}),u.author_info&&i.jsx(Ne,{label:l.label.authorInfo,children:s(u.author_info)}),u.edition&&i.jsx(Ne,{label:l.label.edition,children:s(u.edition)})]}),u.summary&&i.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:[i.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:l.section.summary}),i.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:s(u.summary)})]}),u.comment&&i.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[i.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:l.section.comment}),i.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:s(u.comment)})]}),u.additional_comment&&i.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[i.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:l.section.additionalComment}),i.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:s(u.additional_comment)})]})]})]},p)})})]})}function fh({items:e,onNavigate:t,renderLink:n}){const r=G();return i.jsx(hl,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:t,renderLink:n})}function gl({items:e,onNavigate:t,renderLink:n}){const r=G();return i.jsx(hl,{items:e,label:r.section.emendated,onNavigate:t,renderLink:n})}function xl({label:e,items:t}){const{convert:n}=X();return t.length?i.jsxs(i.Fragment,{children:[i.jsx(Re,{children:e}),i.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((r,o)=>{const l=typeof r=="string"?r:r.book_title;return i.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:n(l)},o)})})]}):null}function hh({items:e}){const t=G();return i.jsx(xl,{label:t.section.aliases,items:e})}function gh({items:e}){const t=G();return i.jsx(xl,{label:t.section.attachedTexts,items:e})}function xh({items:e}){const t=G(),{convert:n}=X();return e.length?i.jsxs(i.Fragment,{children:[i.jsx(Re,{children:t.section.appendix}),i.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:e.map((r,o)=>i.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:["《",n(r.book_title),"》",r.n_juan!=null&&i.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[r.n_juan,t.unit.juan]})]},o))})]}):null}function mh({items:e}){const t=G(),{convert:n}=X();return e.length?i.jsxs(i.Fragment,{children:[i.jsx(Re,{children:t.section.locationHistory}),i.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[i.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),e.map((r,o)=>i.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[i.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)"}}),i.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:n(r.name)}),r.description&&i.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:n(r.description)})]},o))]})]}):null}function bh({items:e}){const t=G(),{convert:n}=X();return e.length?i.jsxs(i.Fragment,{children:[i.jsx(Re,{children:t.section.historyOverview}),i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map((r,o)=>i.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[i.jsx("span",{style:{position:"absolute",left:0,top:0,color:"var(--bim-desc-fg, #ccc)"},children:"·"}),n(r)]},o))})]}):null}function vi({title:e,ids:t,transport:n,onNavigate:r,renderLink:o}){const{convert:l}=X(),[s,a]=v.useState([]);return v.useEffect(()=>{if(!t.length){a([]);return}if(!n){a(t.map(u=>({id:u})));return}let c=!1;return Promise.all(t.map(u=>n.getItem(u).then(p=>({id:u,title:p?p.title:void 0,edition:p?p.edition:void 0,type:p?p.type:void 0})).catch(()=>({id:u})))).then(u=>{c||a(u)}),()=>{c=!0}},[t,n]),t.length?i.jsxs(i.Fragment,{children:[i.jsxs(Re,{children:[e,i.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),i.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(s.length?s:t.map(c=>({id:c}))).map(c=>{const u=c.edition?`${l(c.title)||c.id}(${l(c.edition)})`:l(c.title)||void 0;return i.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:i.jsx(Be,{id:c.id,label:u,onNavigate:r,renderLink:o})},c.id)})})]}):null}function An({book:e,onNavigate:t,renderLink:n}){const r=G(),{convert:o}=X(),[l,s]=v.useState(!1),a=e.resources&&e.resources.length>0,c=e.edition?o(e.edition):o(e.title)||void 0;return i.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[i.jsxs("div",{style:{padding:"6px 12px",borderBottom:a&&!l?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[i.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:i.jsx(Be,{id:e.id,label:c,onNavigate:t,renderLink:n})}),a&&i.jsx("span",{onClick:()=>s(u=>!u),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:l?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:l?r.action.expand:r.action.collapse,children:"▼"})]}),a&&!l&&i.jsx("div",{style:{padding:"10px 14px"},children:i.jsx(Qn,{items:e.resources,groupByType:!0,onNavigate:t,renderLink:n})})]})}function yh({ids:e,workData:t,transport:n,onNavigate:r,renderLink:o,footer:l}){const s=G(),{convert:a}=X(),[c,u]=v.useState([]);if(v.useEffect(()=>{if(!e.length){u([]);return}if(!n){u(e.map(b=>({id:b})));return}let g=!1;return Promise.all(e.map(b=>n.getItem(b).then(x=>({id:b,title:x?x.title:void 0,edition:x?x.edition:void 0,resources:x?x.resources:void 0})).catch(()=>({id:b})))).then(b=>{g||u(b)}),()=>{g=!0}},[e,n]),!e.length)return null;const p=c.length?c:e.map(g=>({id:g})),d=new Map(p.map(g=>[g.id,g])),h=t==null?void 0:t.version_graph,f=kh(e,h);return i.jsxs(i.Fragment,{children:[i.jsxs(Re,{children:[s.section.relatedVersions,i.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",e.length,")"]})]}),l,f.useGrouping?i.jsxs(i.Fragment,{children:[f.coreIds.length>0&&i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:f.coreIds.map(g=>{const b=d.get(g);return b?i.jsx(An,{book:b,onNavigate:r,renderLink:o},g):null})}),f.groupedIds.map(g=>i.jsxs("details",{style:{marginTop:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:6,background:"var(--bim-bg-subtle, #fafafa)"},children:[i.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:"var(--bim-fg, #333)",userSelect:"none"},children:[a(g.label),i.jsxs("span",{style:{marginLeft:6,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:["(",g.ids.length,")"]}),g.description&&i.jsx("span",{style:{marginLeft:8,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:a(g.description)})]}),i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:g.ids.map(b=>{const x=d.get(b);return x?i.jsx(An,{book:x,onNavigate:r,renderLink:o},b):null})})]},g.id))]}):i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:p.map(g=>i.jsx(An,{book:g,onNavigate:r,renderLink:o},g.id))})]})}function kh(e,t){var x,m;if(!t||!t.default_collection||!t.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const n=(x=t.collections)==null?void 0:x[t.default_collection],r=(n==null?void 0:n.groups)??[],o=(n==null?void 0:n.book_ids)??[],l=r.length>0||o.length>0,s=!l&&t.default_collection==="core"&&Array.isArray(t.core_books)?t.core_books:[];if(!l&&s.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const a=new Set(r),c=new Set([...o,...s]),u=k=>{if(c.has(k))return!0;const w=t.node_groups[k];return w!=null&&a.has(w)},p=[],d=new Map,h=[];for(const k of e)if(!((m=t.excluded_books)!=null&&m.includes(k)))if(u(k))p.push(k);else{const w=t.node_groups[k];w?(d.has(w)||d.set(w,[]),d.get(w).push(k)):h.push(k)}if(h.length+[...d.values()].reduce((k,w)=>k+w.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const g=new Map((t.groups??[]).map(k=>[k.id,k])),b=[...d.entries()].map(([k,w])=>{const _=g.get(k);return{id:k,label:(_==null?void 0:_.label)??k,description:_==null?void 0:_.description,ids:w}});return h.length>0&&b.push({id:"__other__",label:"其他版本",description:void 0,ids:h}),{useGrouping:!0,coreIds:p,groupedIds:b}}function vh({workData:e,onNavigate:t,renderLink:n}){var s,a,c,u;const r=G(),{convert:o}=X(),l=!!((s=e.description)!=null&&s.text)||!!e.parent_work;return i.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[i.jsxs("div",{style:{padding:"6px 14px",borderBottom:l?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[i.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:i.jsx(Be,{id:e.id,label:o(e.title),onNavigate:t,renderLink:n})}),e.measure_info?i.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:o(e.measure_info)}):((a=e.juan_count)==null?void 0:a.number)!=null&&e.juan_count.number>0?i.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[pl(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&i.jsx("span",{style:{fontSize:"13px"},children:i.jsx(fl,{authors:e.authors,type:"work",onNavigate:t,renderLink:n})})]}),l&&i.jsxs("div",{style:{padding:"8px 14px"},children:[((c=e.description)==null?void 0:c.text)&&i.jsx(Xn,{text:e.description.text,style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,textAlign:"justify"}}),e.parent_work&&i.jsx("div",{style:{marginTop:(u=e.description)!=null&&u.text?"8px":0,fontSize:"13px"},children:i.jsx(Ne,{label:r.label.parentWork,children:i.jsx(Be,{id:e.parent_work.id,label:o(e.parent_work.title),onNavigate:t,renderLink:n})})})]})]})}function Sh({items:e,onNavigate:t,renderLink:n}){const r=G(),{convert:o}=X();return e.length?i.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:e.map(l=>i.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid #2471a340",borderRadius:"4px",background:"#2471a308"},children:[i.jsx("span",{style:{fontSize:"11px",color:"#2471a3"},children:r.indexType.collection}),i.jsx(Be,{id:l.id,label:o(l.title)||l.id,onNavigate:t,renderLink:n}),l.volume_index!=null&&i.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:Nt(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const br=({data:e,id:t,transport:n,onNavigate:r,renderLink:o,headerExtra:l,relatedBooksFooter:s,className:a,style:c})=>{var A,$,P,L,N,M;const u=G(),{convert:p}=X(),[d,h]=v.useState(null),[f,g]=v.useState(!1),[b,x]=v.useState(null),[m,k]=v.useState(null),[w,_]=v.useState([]),I=e||d;if(v.useEffect(()=>{if(e||!t||!n)return;let D=!1;return g(!0),x(null),n.getItem(t).then(U=>{D||(U?h(U):x(u.misc.notFoundEntry))}).catch(U=>{D||x(U instanceof Error?U.message:u.misc.loadFailed)}).finally(()=>{D||g(!1)}),()=>{D=!0}},[e,t,n]),v.useEffect(()=>{if(!I||!n){k(null),_([]);return}let D=!1;const U=I.type==="book"||I.type==="collection"?I.work_id:void 0;if(U?n.getItem(U).then(y=>{!D&&y&&y.type==="work"&&k(y)}).catch(()=>{}):k(null),I.type==="book"){const y=I;y.contained_in&&y.contained_in.length>0?Promise.all(y.contained_in.map(q=>{const Z=typeof q=="string"?q:q.id,j=typeof q=="string"?void 0:q.volume_index;return n.getItem(Z).then(ce=>({id:Z,title:ce&&ce.title||Z,volume_index:j})).catch(()=>({id:Z,title:Z,volume_index:j}))})).then(q=>{D||_(q)}):_([])}else _([]);return()=>{D=!0}},[I,n]),f)return i.jsx("div",{className:a,style:{...c,padding:"24px"},children:i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((D,U)=>i.jsx("div",{style:{height:U===1?"32px":"16px",width:`${D}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},U))})});if(b)return i.jsx("div",{className:a,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:b});if(!I)return null;if(I.type==="entity")return i.jsx("div",{className:a,style:c,children:i.jsx(io,{data:I,transport:n,onNavigate:r,renderLink:o,headerExtra:l})});const S=I.type==="book"?I:null,T=I.type==="collection"?I:null,z=I.type==="work"?I:null;let B=!1;try{B=ne.extractStatus(I.id)==="draft"}catch{}let C="";I.measure_info?C=p(I.measure_info):(A=I.juan_count)!=null&&A.number?C=pl(I.juan_count.number)+u.unit.juan:($=I.juan_count)!=null&&$.description&&(C=p(I.juan_count.description));const E=[];return(P=I.publication_info)!=null&&P.year&&E.push(i.jsx(Ne,{label:u.label.year,children:I.publication_info.year},"year")),(L=I.current_location)!=null&&L.name&&E.push(i.jsx(Ne,{label:u.label.currentLocation,children:p(I.current_location.name)},"loc")),(N=I.page_count)!=null&&N.description&&E.push(i.jsx(Ne,{label:u.label.pageCount,children:I.page_count.description},"page")),S!=null&&S.edition&&E.push(i.jsx(Ne,{label:u.label.edition,children:p(S.edition)},"ver")),z!=null&&z.parent_work&&E.push(i.jsx(Ne,{label:u.label.parentWork,children:i.jsx(Be,{id:z.parent_work.id,label:p(z.parent_work.title),onNavigate:r,renderLink:o})},"pw")),z!=null&&z.parent_works&&z.parent_works.length>0&&!z.parent_work&&E.push(i.jsx(Ne,{label:u.label.parentWork,children:z.parent_works.map((D,U)=>i.jsxs("span",{children:[U>0&&"、",i.jsx(Be,{id:D,onNavigate:r,renderLink:o})]},D))},"pws")),i.jsxs("div",{className:a,style:c,children:[i.jsx(ph,{id:I.id,title:p(I.title),edition:I.edition?p(I.edition):void 0,type:I.type,isDraft:B,authors:I.authors,volumeText:C,meta:E,headerExtra:l,onNavigate:r,renderLink:o}),((M=I.description)==null?void 0:M.text)&&i.jsx(Xn,{text:I.description.text,style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),I.appendix&&I.appendix.length>0&&i.jsx("div",{style:{marginTop:8,marginBottom:4},children:I.appendix.map((D,U)=>i.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:"var(--bim-bg-subtle, #fafafa)",borderRadius:4,border:"1px solid var(--bim-widget-border, #ececec)"},children:[i.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:"var(--bim-muted, #666)"},children:p(D.title)}),i.jsx(Xn,{text:D.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:"var(--bim-fg, #444)"}})]},U))}),w.length>0&&i.jsxs(i.Fragment,{children:[i.jsx(Re,{children:u.section.containedIn}),i.jsx(Sh,{items:w,onNavigate:r,renderLink:o})]}),m&&i.jsxs(i.Fragment,{children:[i.jsx(Re,{children:u.section.belongsToWork}),i.jsx(vh,{workData:m,onNavigate:r,renderLink:o})]}),I.additional_works&&I.additional_works.length>0&&i.jsx(xh,{items:I.additional_works}),I.additional_titles&&I.additional_titles.length>0&&i.jsx(hh,{items:I.additional_titles}),I.attached_texts&&I.attached_texts.length>0&&i.jsx(gh,{items:I.attached_texts}),I.indexed_by&&I.indexed_by.length>0&&i.jsx(fh,{items:I.indexed_by,onNavigate:r,renderLink:o}),I.emendated_by&&I.emendated_by.length>0&&i.jsx(gl,{items:I.emendated_by,onNavigate:r,renderLink:o}),I.resources&&I.resources.length>0&&i.jsxs(i.Fragment,{children:[i.jsx(Re,{children:u.section.resources}),i.jsx(Qn,{items:I.resources,groupByType:!0,onNavigate:r,renderLink:o})]}),(S==null?void 0:S.location_history)&&S.location_history.length>0&&i.jsx(mh,{items:S.location_history}),(T==null?void 0:T.history)&&T.history.length>0&&i.jsx(bh,{items:T.history}),(S==null?void 0:S.related_books)&&S.related_books.length>0&&i.jsx(vi,{title:u.section.relatedVersions,ids:S.related_books,transport:n,onNavigate:r,renderLink:o}),(T==null?void 0:T.books)&&T.books.length>0&&i.jsx(vi,{title:u.section.containedBooks,ids:T.books,transport:n,onNavigate:r,renderLink:o}),(T==null?void 0:T.contained_works)&&T.contained_works.length>0&&i.jsxs("div",{children:[i.jsxs(Re,{children:[u.section.containedWorks,i.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",T.contained_works.length,")"]})]}),i.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:T.contained_works.map(D=>i.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:i.jsx(Be,{id:D.id,label:p(D.title),onNavigate:r,renderLink:o})},D.id))})]}),(z==null?void 0:z.books)&&z.books.length>0&&i.jsx(yh,{ids:z.books,workData:z,transport:n,onNavigate:r,renderLink:o,footer:s}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const D=[],U=z.related_works.filter(Z=>Z.relation==="part_of"),y=z.related_works.filter(Z=>Z.relation==="has_part"),q=z.related_works.filter(Z=>!Z.relation);return U.length>0&&D.push({label:u.section.belongsToWork,items:U}),y.length>0&&D.push({label:u.section.containedWorks,items:y}),q.length>0&&D.push({label:u.section.relatedWorks,items:q}),D.map(Z=>i.jsxs("div",{children:[i.jsxs(Re,{children:[Z.label,i.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",Z.items.length,")"]})]}),i.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:Z.items.map(j=>i.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:i.jsx(Be,{id:j.id,label:p(j.title),onNavigate:r,renderLink:o})},j.id))})]},Z.label))})()]})};function wh({data:e}){const t=G(),{convert:n}=X(),{stats:r}=e,o=r.processed_volumes??r.total_found_volumes,l=o!=null&&e.total_volumes>0?Math.round(o/e.total_volumes*100):null;return i.jsxs("div",{style:{marginBottom:"24px"},children:[i.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:n(e.title)}),e.resource_name&&i.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:n(e.resource_name)}),i.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[i.jsxs("span",{children:[t.catalog.totalVolumes," ",i.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:e.total_volumes})," ",t.unit.volume]}),l!=null&&i.jsxs("span",{children:[t.catalog.processed," ",i.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o})," ",t.unit.volume," (",l,"%)"]}),i.jsxs("span",{children:[t.catalog.contains," ",i.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.total_books})," ",t.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&i.jsxs("span",{children:[t.catalog.matched," ",i.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.matched_works})," ",t.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&i.jsxs("span",{children:[t.catalog.unmatched," ",i.jsx("strong",{style:{color:"#e67e22"},children:r.unmatched_works})," ",t.unit.bu]})]}),e.source&&i.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[t.catalog.source," ",e.source]})]})}function jh({sections:e,activeSection:t,onSelect:n}){const r=G();return i.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[i.jsx("button",{onClick:()=>n(null),style:Si(t===null),children:r.catalog.all}),e.map(o=>i.jsxs("button",{onClick:()=>n(o.name),style:Si(t===o.name),children:[o.name,o.volume_range&&i.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[o.volume_range[0],"–",o.volume_range[1]]})]},o.name))]})}function Si(e){return{padding:"4px 12px",border:e?"1px solid var(--bim-primary, #2471a3)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:e?"color-mix(in srgb, var(--bim-primary, #2471a3) 8%, transparent)":"transparent",color:e?"var(--bim-primary, #2471a3)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function Ch({id:e,label:t,onNavigate:n,renderLink:r}){const o=Fe();return r?i.jsx(i.Fragment,{children:r(e,t)}):n?i.jsx("a",{href:o(e),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),n(e))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px",fontSize:"12px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:t||e}):i.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:t||e})}function Ih(e,t){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const n=e[0],r=e[e.length-1];return r-n+1===e.length?`${n}–${r}`:e.length<=3?e.join(", "):`${n}–${r} (${e.length}${t})`}function wi({book:e,onNavigate:t,renderLink:n,showVolumes:r}){const o=G(),{convert:l}=X(),s=e.book_id||e.work_id,a=r&&e.volumes.length>0?Ih(e.volumes,o.unit.volume):null,c=e.missing_volumes&&e.missing_volumes.length>0;return i.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[r&&i.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:a}),i.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[l(e.title),e.sub_items&&e.sub_items.length>0&&i.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",e.sub_items.map(u=>l(u)).join("、"),")"]}),e.edition&&i.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:l(e.edition)})]}),e.expected_volumes!=null&&i.jsxs("span",{style:{fontSize:"11px",color:c?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,o.unit.volume]}),s&&i.jsx(Ch,{id:s,label:e.book_id?o.indexType.book:o.indexType.work,onNavigate:t,renderLink:n}),!s&&i.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:o.catalog.unmatched_label})]})}const ml=({data:e,collectionId:t,transport:n,onNavigate:r,renderLink:o,className:l,style:s})=>{const a=G(),[c,u]=v.useState(null),[p,d]=v.useState(!1),[h,f]=v.useState(null),[g,b]=v.useState(null),[x,m]=v.useState(""),k=e||c;v.useEffect(()=>{if(e||!t||!(n!=null&&n.getCollectionCatalog))return;let T=!1;return d(!0),f(null),n.getCollectionCatalog(t).then(z=>{T||(z?u(z):f(a.catalog.notFound))}).catch(z=>{T||f(z instanceof Error?z.message:a.catalog.loadFailed)}).finally(()=>{T||d(!1)}),()=>{T=!0}},[e,t,n,a]);const w=(k==null?void 0:k.sections)&&k.sections.length>0,_=v.useMemo(()=>{if(!k)return!1;if(k.volume_index&&Object.keys(k.volume_index).length>0)return!0;const T=k.books.map(B=>B.volumes[0]).filter(B=>B!=null);return new Set(T).size<T.length},[k]),I=v.useMemo(()=>{if(!k)return[];let T=k.books;if(g&&(T=T.filter(z=>z.section===g)),x.trim()){const z=x.trim().toLowerCase();T=T.filter(B=>B.title.toLowerCase().includes(z)||B.sub_items&&B.sub_items.some(C=>C.toLowerCase().includes(z))||B.edition&&B.edition.toLowerCase().includes(z))}return T},[k,g,x]),S=v.useMemo(()=>{if(!_)return null;const T=[],z=new Map;for(const C of I){if(!C.volumes||C.volumes.length===0)continue;const E=C.volumes[0];z.has(E)||z.set(E,[]),z.get(E).push(C)}const B=[...z.keys()].sort((C,E)=>C-E);for(const C of B)T.push({volume:C,books:z.get(C)});return T},[I,_]);return p?i.jsx("div",{className:l,style:{...s,padding:"24px"},children:i.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:a.catalog.loading})}):h?i.jsx("div",{className:l,style:{...s,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h}):k?i.jsxs("div",{className:l,style:s,children:[i.jsx(wh,{data:k}),w&&i.jsx(jh,{sections:k.sections,activeSection:g,onSelect:b}),i.jsxs("div",{style:{marginBottom:"12px"},children:[i.jsx("input",{type:"text",placeholder:a.search.searchBookName,value:x,onChange:T=>m(T.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}}),i.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[I.length," ",a.unit.bu]})]}),i.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[S?S.map((T,z)=>i.jsxs("div",{children:[i.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:Nt(a.catalog.volume,{n:T.volume})}),T.books.map((B,C)=>i.jsx(wi,{book:B,onNavigate:r,renderLink:o,showVolumes:B.volumes.length>1},`${T.volume}-${C}`))]},`${T.volume}-${z}`)):I.map((T,z)=>i.jsx(wi,{book:T,onNavigate:r,renderLink:o,showVolumes:!0},z)),I.length===0&&i.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:a.catalog.noMatch})]})]}):null},it=()=>{const[e,t]=v.useState(1);return v.useEffect(()=>{const n=setInterval(()=>t(r=>r>=3?1:r+1),500);return()=>clearInterval(n)},[]),i.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(e)})},ke=6,Xt=7,Eh=({content:e,children:t,placement:n="top",delayMs:r=100,maxWidth:o=280,wrapperStyle:l})=>{const[s,a]=v.useState(!1),[c,u]=v.useState(null),p=v.useRef(null),d=v.useRef(null),h=v.useRef(null),f=v.useCallback(()=>{const x=d.current,m=h.current;if(!x||!m)return;const k=x.getBoundingClientRect(),w=m.getBoundingClientRect(),_=window.innerHeight,I=document.documentElement.clientWidth;let S=n;n==="top"&&k.top-w.height-Xt<8&&(S="bottom"),n==="bottom"&&k.bottom+w.height+Xt>_-8&&(S="top");const T=S==="top"?k.top-w.height-Xt:k.bottom+Xt;let z=k.left+k.width/2-w.width/2;z=Math.max(8,Math.min(z,I-w.width-8)),u({left:z,top:T,placement:S})},[n]),g=v.useCallback(()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>a(!0),r)},[r]),b=v.useCallback(()=>{p.current&&clearTimeout(p.current),a(!1),u(null)},[]);return v.useEffect(()=>{if(!s)return;const x=requestAnimationFrame(f);return()=>cancelAnimationFrame(x)},[s,f]),v.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]),i.jsxs(i.Fragment,{children:[i.jsx("span",{ref:d,onMouseEnter:g,onMouseLeave:b,onFocus:g,onBlur:b,style:{display:"inline-block",...l},children:t}),s&&Gl.createPortal(i.jsxs("div",{ref:h,role:"tooltip",style:{position:"fixed",left:(c==null?void 0:c.left)??-9999,top:(c==null?void 0:c.top)??-9999,maxWidth:o,padding:"6px 10px",fontSize:"12px",lineHeight:1.5,color:"var(--bim-fg, #333)",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.08)",pointerEvents:"none",zIndex:9999,opacity:c?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[e,c&&i.jsxs(i.Fragment,{children:[i.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-ke,width:0,height:0,...c.placement==="top"?{bottom:-ke,borderTop:`${ke}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${ke}px solid transparent`,borderRight:`${ke}px solid transparent`}:{top:-ke,borderBottom:`${ke}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${ke}px solid transparent`,borderRight:`${ke}px solid transparent`}}}),i.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...c.placement==="top"?{bottom:-5,borderTop:`${ke-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${ke-1}px solid transparent`,borderRight:`${ke-1}px solid transparent`}:{top:-5,borderBottom:`${ke-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${ke-1}px solid transparent`,borderRight:`${ke-1}px solid transparent`}}})]})]}),document.body)]})},ji={A:"fine",B:"rough",C:"rough",D:"ocr"};function Th(e){return typeof e!="string"?null:e in Qi?e:e in ji?ji[e]:null}const _h={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"};function ge(e){return typeof e!="string"?"":_h[e]??e}const zh=["〇","一","二","三","四","五","六","七","八","九"],Ci=["","十","百","千"],Rh=["","萬","億"];function bl(e){if(e===0)return"〇";if(e<0)return`負${bl(-e)}`;const t=[];let n=e,r=0;for(;n>0;){const o=n%1e4;o>0?t.unshift(Lh(o,r>0)+Rh[r]):t.length>0&&t.unshift("〇"),n=Math.floor(n/1e4),r++}return t.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Lh(e,t){const n=[];let r=e;for(;r>0;)n.unshift(r%10),r=Math.floor(r/10);let o="";for(let l=0;l<n.length;l++){const s=n[l],a=n.length-1-l;s===0?o&&!o.endsWith("〇")&&(o+="〇"):s===1&&a===1&&l===0&&!t?o+=Ci[a]:o+=zh[s]+Ci[a]}return o.replace(/〇$/,"")}let Dt=null,Jt=null;const sn=new Set;function Ah(){return Dt?Promise.resolve():Jt||(Jt=import("opencc-js/t2cn").then(e=>{Dt=e.Converter({from:"tw",to:"cn"}),sn.forEach(t=>t())}).catch(()=>{Dt=e=>e,sn.forEach(e=>e())}),Jt)}function Ge(){const[,e]=v.useState(0);return v.useEffect(()=>{if(Dt)return;const t=()=>e(n=>n+1);return sn.add(t),Ah(),()=>{sn.delete(t)}},[]),Dt??(t=>t)}function gt(e,t){return t(e).toLowerCase()}const yr="#fff59d";function bt(e,t,n){if(!t)return e;const r=gt(t,n);if(!r)return e;const o=gt(e,n);if(o.length!==e.length)return e;const l=[];let s=0,a=0;for(;s<e.length;){const c=o.indexOf(r,s);if(c===-1){l.push(e.slice(s));break}c>s&&l.push(e.slice(s,c)),l.push(i.jsx("mark",{style:{background:yr,padding:0,color:"inherit"},children:e.slice(c,c+r.length)},a++)),s=c+r.length}return i.jsx(i.Fragment,{children:l})}function kr(e,t,n,r){if(!t)return!0;const o=gt(t,r);return(n?[e.title,e.header_line,e.content,e.comment]:[e.title,e.book_title,e.author,e.author_info,e.summary,e.content,e.comment,e.additional_comment]).some(s=>typeof s=="string"&&gt(s,r).includes(o))}function Bh(e,t,n){return t?gt(e,n).includes(gt(t,n)):!0}const vr={类:"#8e6f3e",书:"#c0392b",序:"#1a5276",结语:"#7d6608"},Ph={考证:"#5d6d7e"};function Fh(e){const t=e.replace(".json","");return t==="fulu"?"附錄":t.startsWith("juanshou")?`卷首${t.replace("juanshou","")}`:t.startsWith("juan")?`卷${t.replace("juan","").replace(/^0+/,"")}`:t}function yl({file:e,isActive:t,onSelect:n,meta:r,matchState:o}){const l=o===0,s=o==="loading",a=typeof o=="number"&&o>0,c=Fh(e),u=!!(r!=null&&r.vol_label)&&!c.includes(r.vol_label);return i.jsxs("button",{onClick:()=>{l||n(e)},disabled:l,style:{padding:"3px 8px",border:t?"1px solid var(--bim-primary, #8e6f3e)":l?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:t?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":a?`${yr}40`:"transparent",color:t?"var(--bim-primary, #8e6f3e)":l?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:l?"not-allowed":"pointer",fontSize:"12px",fontWeight:t?600:400,lineHeight:1.4,opacity:l?.5:1},children:[c,u&&i.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",r.vol_label,"冊)"]}),a&&i.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:o}),s&&i.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function kl(e,t){var n;return e.files.includes(t)?!0:!!((n=e.children)!=null&&n.some(r=>kl(r,t)))}function vl(e){var r;const t=e.files.length,n=((r=e.children)==null?void 0:r.reduce((o,l)=>o+vl(l),0))||0;return t+n}function Dh(e,t){const n=[],r=s=>{var a;n.push(...s.files),(a=s.children)==null||a.forEach(r)};if(r(e),n.length===0)return;const o=n.map(s=>t[s]);if(o.every(s=>s===void 0))return;if(o.some(s=>s==="loading"))return"loading";let l=0;for(const s of o)typeof s=="number"&&(l+=s);return l}function Sl({group:e,activeFile:t,onSelect:n,depth:r=0,juanMeta:o,matchStates:l}){var g;const s=kl(e,t||""),a=Dh(e,l),c=typeof a=="number"&&a>0,u=a===0,[p,d]=v.useState(s||c),h=vl(e),f=!!((g=e.children)!=null&&g.length);if(v.useEffect(()=>{s&&d(!0)},[s]),v.useEffect(()=>{c&&d(!0)},[c]),e.files.length===1&&!f){const b=e.files[0],x=t===b,m=l[b],k=m===0,w=m==="loading",_=typeof m=="number"&&m>0;return i.jsxs("button",{onClick:()=>{k||n(b)},disabled:k,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:x?"1px solid var(--bim-primary, #8e6f3e)":k?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:x?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":_?`${yr}40`:"transparent",color:x?"var(--bim-primary, #8e6f3e)":k?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:k?"not-allowed":"pointer",fontSize:"12px",fontWeight:x?600:400,lineHeight:1.4,opacity:k?.5:1},children:[e.label,_&&i.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:m}),w&&i.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}return i.jsxs("div",{style:{marginBottom:r===0?"4px":"2px"},children:[i.jsxs("div",{onClick:()=>d(!p),style:{display:"flex",alignItems:"center",gap:"6px",padding:r===0?"4px 8px":"2px 8px",paddingLeft:`${8+r*16}px`,cursor:"pointer",userSelect:"none",fontSize:r===0?"13px":"12px",fontWeight:r===0?600:500,color:s?"var(--bim-primary, #8e6f3e)":u?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",opacity:u?.6:1},children:[i.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:p?"rotate(90deg)":"none",display:"inline-block"},children:"▶"}),i.jsx("span",{children:e.label}),i.jsxs("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",h,")"]}),c&&i.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"#b78900"},children:["匹配 ",a]}),a==="loading"&&i.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]}),p&&i.jsxs(i.Fragment,{children:[e.files.length>0&&i.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",padding:`4px 0 4px ${24+r*16}px`},children:e.files.map(b=>i.jsx(yl,{file:b,isActive:t===b,onSelect:n,meta:o==null?void 0:o[b],matchState:l[b]},b))}),f&&e.children.map((b,x)=>i.jsx(Sl,{group:b,activeFile:t,onSelect:n,depth:r+1,juanMeta:o,matchStates:l},x))]})]})}function Mh({files:e,groups:t,activeFile:n,onSelect:r,juanMeta:o,matchStates:l}){const s=e||[];return t&&t.length>0?i.jsx("div",{style:{marginBottom:"16px"},children:t.map((a,c)=>i.jsx(Sl,{group:a,activeFile:n,onSelect:r,juanMeta:o,matchStates:l},c))}):s.length===0?null:i.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:s.map(a=>i.jsx(yl,{file:a,isActive:n===a,onSelect:r,meta:o==null?void 0:o[a],matchState:l[a]},a))})}function Oh({type:e}){const t=vr[e]||"#717171";return i.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:t,border:`1px solid ${t}40`,borderRadius:"2px",background:`${t}08`,flexShrink:0},children:e})}function Wh({section:e,onNavigate:t,highlightQuery:n=""}){const{convert:r}=X(),o=Fe(),l=Ge(),s=b=>{if(!b)return"";const x=r(b);return n?bt(x,n,l):x},[a,c]=v.useState(!1),u=!!e.summary,p=!!e.comment,d=!!e.additional_comment,h=!!(e.content&&e.content.length>60),f=u||p||d||h;v.useEffect(()=>{n&&c(!0)},[n]);const g=!a&&h?e.content.replace(/\n/g," ").slice(0,80)+"…":null;return i.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[i.jsxs("div",{onClick:()=>f&&c(!a),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:f?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[f&&i.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:a?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),i.jsxs("div",{style:{flex:1,minWidth:0},children:[i.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[e.book_title?i.jsxs(i.Fragment,{children:["《",s(e.book_title),"》"]}):s(e.title),e.n_juan!=null&&i.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[bl(e.n_juan),"卷"]}),(e.author_info||e.author)&&i.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:s(e.author_info||e.author)})]}),!a&&g&&i.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:s(g)})]}),e.edition&&i.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:s(e.edition)}),e.tag&&i.jsx("span",{style:{fontSize:"11px",color:"#e74c3c"},children:e.tag==="triangle"?"△":e.tag}),e.work_id&&t&&i.jsx("a",{href:o(e.work_id),onClick:b=>{b.metaKey||b.ctrlKey||(b.preventDefault(),b.stopPropagation(),t(e.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),a&&f&&i.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[e.author_info&&i.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:s(e.author_info)}),e.summary&&i.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:[i.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),i.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:s(e.summary)})]}),e.comment&&i.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[i.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),i.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:s(e.comment)})]}),e.additional_comment&&i.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[i.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),i.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:s(e.additional_comment)})]}),h&&!u&&!p&&!d&&i.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(e.content)})]})]})}function $h({section:e,highlightQuery:t=""}){const{convert:n}=X(),r=Ge(),o=c=>{if(!c)return"";const u=n(c);return t?bt(u,t,r):u},[l,s]=v.useState(!1),a=!!e.content;return i.jsxs("div",{style:{padding:"12px 0 6px"},children:[i.jsxs("div",{onClick:()=>a&&s(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:a?"pointer":"default",userSelect:"none"},children:[i.jsx(Oh,{type:e.type}),i.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:o(e.title)}),a&&i.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),l&&a&&i.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${vr[e.type]||"#717171"}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:i.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:o(e.content)})})]})}function Nh({section:e,highlightQuery:t=""}){const{convert:n}=X(),r=Ge();if(!e.content&&!e.title)return null;const o=n((e.content||e.title||"").replace(/\n{2,}/g,`
30
- `)),l=t?bt(o,t,r):o,s=vr[e.type]||"#717171",a=ge(e.type)==="序"||ge(e.type)==="结语";return i.jsxs("div",{style:{padding:a?"10px 12px":"6px 0",margin:a?"8px 0":void 0,fontSize:"13px",color:"var(--bim-desc-fg, #555)",lineHeight:1.8,whiteSpace:"pre-line",borderLeft:a?`3px solid ${s}40`:void 0,background:a?"var(--bim-bg, #fafafa)":void 0,borderRadius:a?"0 4px 4px 0":void 0,position:"relative"},children:[a&&i.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:s,marginRight:"8px",padding:"1px 5px",border:`1px solid ${s}40`,borderRadius:"2px",background:`${s}08`,verticalAlign:"middle"},children:e.type}),l]})}function Hh(e,t,n){const[r,o]=v.useState({});return v.useEffect(()=>{var u;if(!t||e.length===0)return;let l=!1;const s=e.filter(p=>{var d;return!((d=n==null?void 0:n.current)!=null&&d.has(p))}),a={};for(const p of e)(u=n==null?void 0:n.current)!=null&&u.has(p)&&(a[p]=n.current.get(p));if(Object.keys(a).length>0&&o(a),s.length===0)return;const c=async p=>{var d;try{if(t.getEntry){const x=await t.getEntry(p);if(x)return{title:x.title,author:x.author}}const h=await t.getItem(p);if(!h)return null;const f=h.title||p,g=h.authors,b=(d=g==null?void 0:g[0])==null?void 0:d.name;return{title:f,author:b}}catch{return null}};return Promise.all(s.map(async p=>{var h;const d=await c(p);return(h=n==null?void 0:n.current)==null||h.set(p,d),[p,d]})).then(p=>{l||o(d=>{const h={...d};for(const[f,g]of p)h[f]=g;return h})}),()=>{l=!0}},[e.join(","),t]),r}function Uh({section:e,onNavigate:t,transport:n,workLabelCache:r,highlightQuery:o=""}){const{convert:l}=X(),s=Fe(),a=Ge(),c=k=>{if(!k)return"";const w=l(k);return o?bt(w,o,a):w},[u,p]=v.useState(!1);v.useEffect(()=>{o&&p(!0)},[o]);const d=e.type,h=Ph[d]||"#717171",f=!!e.content,g=e.work_ids||[],b=g.length>1,x=Hh(b?g:[],n,r),m=f&&!u&&e.content.length>80?e.content.slice(0,80)+"……":null;return i.jsxs("div",{style:{borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",padding:"10px 0"},children:[i.jsxs("div",{onClick:()=>f&&p(!u),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:f?"pointer":"default",userSelect:"none"},children:[f&&i.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #aaa)",marginTop:"5px",transition:"transform 0.15s",transform:u?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),i.jsxs("div",{style:{flex:1},children:[i.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)",lineHeight:1.6},children:e.header_line?c(e.header_line):c(e.title)}),!u&&m&&i.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:c(m)})]}),i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[g.length===1&&t&&i.jsx("a",{href:s(g[0]),onClick:k=>{k.metaKey||k.ctrlKey||(k.preventDefault(),k.stopPropagation(),t(g[0]))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),b&&i.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",flexShrink:0},children:[g.length,"部作品"]}),i.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:h,border:`1px solid ${h}40`,borderRadius:"2px",background:`${h}08`},children:d})]})]}),b&&t&&i.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:g.map(k=>{const w=x[k],_=w?`${l(w.title)}${w.author?`(${l(w.author)})`:""}`:k.slice(0,8)+"…";return i.jsxs("a",{href:s(k),onClick:I=>{I.metaKey||I.ctrlKey||(I.preventDefault(),I.stopPropagation(),t(k))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:k,children:["→",_]},k)})}),u&&f&&i.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${h}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:[i.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:c(e.content)}),e.comment&&i.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:"1px solid var(--bim-widget-border, #eee)",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.8,fontStyle:"italic"},children:c(e.comment)})]})]})}function Vh({juan:e,searchQuery:t,onNavigate:n,transport:r,workLabelCache:o}){const{convert:l}=X(),s=Ge(),a=t.trim(),c=v.useMemo(()=>a?e.sections.filter(d=>kr(d,a,!0,s)):e.sections,[e.sections,a,s]),u=e.sections.filter(d=>ge(d.type)==="考证").length,p=c.filter(d=>ge(d.type)==="考证").length;return i.jsxs("div",{children:[i.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"4px"},children:[i.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:l(e.title)}),i.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:a?`${p} / ${u} 條`:`${u} 條`})]}),e.source_url&&i.jsx("div",{style:{marginBottom:"12px"},children:i.jsx("a",{href:e.source_url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:"原文來源"})}),i.jsx("div",{children:c.map((d,h)=>i.jsx(Uh,{section:d,onNavigate:n,transport:r,workLabelCache:o,highlightQuery:a},h))}),c.length===0&&i.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function qh({text:e,highlightQuery:t=""}){const{convert:n}=X(),r=Ge(),o=s=>{const a=n(s);return t?bt(a,t,r):a},l=e.split(`
31
- `);return i.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:l.map((s,a)=>{if(s.startsWith("# "))return i.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:o(s.slice(2))},a);if(s.startsWith("## "))return i.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:o(s.slice(3))},a);if(s.startsWith("### "))return i.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:o(s.slice(4))},a);if(!s.trim())return a>0&&!l[a-1].trim()?null:i.jsx("div",{style:{height:"0.5em"}},a);const c=s.split(/(\*\*[^*]+\*\*)/g);return i.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:c.map((u,p)=>u.startsWith("**")&&u.endsWith("**")?i.jsx("strong",{children:o(u.slice(2,-2))},p):i.jsx(v.Fragment,{children:o(u)},p))},a)})})}function Yh({sections:e,onNavigate:t,highlightQuery:n=""}){const{convert:r}=X(),o=Fe(),l=Ge(),s=u=>{if(!u)return"";const p=r(u);return n?bt(p,n,l):p},a=[];let c=null;for(const u of e)ge(u.type)==="类"?(c&&a.push(c),c={category:u.title,categoryContent:u.content||void 0,items:[]}):ge(u.type)==="书"?(c||(c={category:"",items:[]}),c.items.push(u)):(ge(u.type)==="序"||ge(u.type)==="结语")&&(c||(c={category:"",items:[]}),c.items.push(u),ge(u.type)==="结语"&&(a.push(c),c=null));return c&&a.push(c),i.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:a.map((u,p)=>i.jsxs("div",{style:{marginBottom:"20px"},children:[u.category&&i.jsxs("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:[s(u.category),u.categoryContent&&i.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:s(u.categoryContent)})]}),u.items.map((d,h)=>ge(d.type)==="序"||ge(d.type)==="结语"?i.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:s(d.content||"")},h):i.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[t&&d.work_id?i.jsx("a",{href:o(d.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),f.stopPropagation(),t(d.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:r(d.title),children:i.jsx("strong",{children:s(d.title)})}):i.jsx("strong",{children:s(d.title)}),d.content&&s(d.content)]},h))]},p))})}function Gh({juan:e,rawText:t,searchQuery:n,onNavigate:r}){const{convert:o}=X(),l=Ge(),[s,a]=v.useState("catalog"),c=n.trim(),u=v.useMemo(()=>c?e.sections.filter(f=>kr(f,c,!1,l)):e.sections,[e.sections,c,l]),p=e.sections.filter(f=>ge(f.type)==="书").length,d=e.sections.filter(f=>ge(f.type)==="诗").length,h=c?u.filter(f=>ge(f.type)==="书"||ge(f.type)==="诗").length:null;return i.jsxs("div",{children:[i.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"12px"},children:[i.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:o(e.title)}),i.jsx("div",{style:{display:"flex",gap:"2px",marginLeft:"8px"},children:["catalog","raw"].map(f=>i.jsx("button",{onClick:()=>a(f),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:f==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:s===f?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:s===f?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:f==="catalog"?"目錄":"原文"},f))}),i.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:h!=null?`${h} / ${d>0?`${d} 首`:`${p} 部書`}`:d>0?`${d} 首`:`${p} 部书`})]}),s==="raw"&&(t?i.jsx(qh,{text:t,highlightQuery:c}):i.jsx(Yh,{sections:e.sections,onNavigate:r,highlightQuery:c})),s==="catalog"&&u.map((f,g)=>ge(f.type)==="书"||ge(f.type)==="诗"?i.jsx(Wh,{section:f,onNavigate:r,highlightQuery:c},g):ge(f.type)==="类"?i.jsx($h,{section:f,highlightQuery:c},g):i.jsx(Nh,{section:f,highlightQuery:c},g)),s==="catalog"&&u.length===0&&i.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function wl(e){return e.juan_files&&e.juan_files.length>0?e.juan_files:e.files&&e.files.length>0?e.files.map(t=>t.filename):[]}function Ii(e){const t=wl(e);return t.length>0?t[0]:null}function Kh(e){const{workId:t,transport:n,files:r,activeFile:o,activeJuan:l,activeRawText:s,query:a,isKaozhen:c}=e,u=Ge(),p=v.useRef(new Map),[d,h]=v.useState({});v.useEffect(()=>{o&&l&&p.current.set(o,{juan:l,rawText:s})},[o,l,s]),v.useEffect(()=>{p.current.clear(),h({})},[t]);const f=v.useCallback((g,b)=>{let x=0;if(g.juan)for(const m of g.juan.sections)kr(m,b,c,u)&&x++;return x===0&&g.rawText&&Bh(g.rawText,b,u)&&(x=1),x},[c,u]);return v.useEffect(()=>{const g=a.trim();if(!g){h({});return}if(!t||!(n!=null&&n.getCollatedJuan)||r.length===0)return;let b=!1;const x={},m=[];for(const S of r){const T=p.current.get(S);T?x[S]=f(T,g):(x[S]="loading",m.push(S))}h(x);const k=8;let w=0;const _=async()=>{var S;for(;w<m.length;){if(b)return;const T=w++,z=m[T];try{const[B,C]=await Promise.all([n.getCollatedJuan(t,z),((S=n.getCollatedJuanText)==null?void 0:S.call(n,t,z))??Promise.resolve(null)]),E={juan:B,rawText:C};if(p.current.set(z,E),b)return;h(A=>({...A,[z]:f(E,g)}))}catch{if(b)return;h(B=>({...B,[z]:0}))}}},I=Array.from({length:Math.min(k,m.length)},()=>_());return Promise.all(I),()=>{b=!0}},[a,t,n,r.join(","),f,u]),{matchStates:d}}const jl=({index:e,workId:t,transport:n,onNavigate:r,activeJuan:o,onJuanChange:l,className:s,style:a})=>{const[c,u]=v.useState(null),[p,d]=v.useState(!1),[h,f]=v.useState(null),[g,b]=v.useState(null),[x,m]=v.useState(null),[k,w]=v.useState(!1),[_,I]=v.useState(null),[S,T]=v.useState(""),z=v.useRef(new Map),B=o??g,C=v.useCallback(M=>{b(M),l==null||l(M)},[l]),E=e||c;v.useEffect(()=>{e&&(d(!1),f(null))},[e]),v.useEffect(()=>{if(e||!t||!(n!=null&&n.getCollatedEditionIndex))return;let M=!1;return d(!0),f(null),n.getCollatedEditionIndex(t).then(D=>{if(!M)if(!D)f("未找到整理本数据");else{u(D);const U=Ii(D);!o&&U&&C(U)}}).catch(D=>{M||f(D instanceof Error?D.message:"加载失败")}).finally(()=>{M||d(!1)}),()=>{M=!0}},[e,t,n,o,C]),v.useEffect(()=>{const M=e||c;if(M&&!B){const D=Ii(M);D&&C(D)}},[e,c,B,C]);const A=t||(E==null?void 0:E.work_id),$=v.useCallback(async M=>{var D;if(!(!A||!(n!=null&&n.getCollatedJuan))){w(!0),m(null),I(null);try{const[U,y]=await Promise.all([n.getCollatedJuan(A,M),((D=n.getCollatedJuanText)==null?void 0:D.call(n,A,M))??Promise.resolve(null)]);m(U),I(y)}catch{m(null),I(null)}finally{w(!1)}}},[A,n]);v.useEffect(()=>{B&&$(B)},[B,$]);const P=M=>{C(M)};if(p)return i.jsx("div",{className:s,style:{...a,padding:"24px"},children:i.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(h)return i.jsx("div",{className:s,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h});if(!E)return null;const L=E.type==="kaozhen",N=wl(E);return i.jsx(Xh,{className:s,style:a,index:E,allFiles:N,isKaozhen:L,effectiveWorkId:A,transport:n,activeFile:B,handleSelectFile:P,juanData:x,juanRawText:_,juanLoading:k,searchQuery:S,setSearchQuery:T,onNavigate:r,workLabelCacheRef:z})},Xh=({className:e,style:t,index:n,allFiles:r,isKaozhen:o,effectiveWorkId:l,transport:s,activeFile:a,handleSelectFile:c,juanData:u,juanRawText:p,juanLoading:d,searchQuery:h,setSearchQuery:f,onNavigate:g,workLabelCacheRef:b})=>{const{matchStates:x}=Kh({workId:l,transport:s,files:r,activeFile:a,activeJuan:u,activeRawText:p,query:h,isKaozhen:o});return i.jsxs("div",{className:e,style:t,children:[i.jsx("div",{style:{marginBottom:"12px"},children:i.jsx("input",{type:"text",placeholder:o?"搜索全部章节(条目、考证内容)...":"搜索全部册(书名、作者、正文)...",value:h,onChange:m=>f(m.target.value),style:{width:"100%",maxWidth:"420px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}})}),i.jsxs("div",{style:{marginBottom:"16px",display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[i.jsx("div",{children:o?i.jsxs(i.Fragment,{children:[n.target_source&&i.jsxs("span",{children:["考證對象:",i.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:n.target_source})," "]}),"共 ",i.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.length})," 章"]}):i.jsxs("span",{children:["共 ",i.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:n.total_juan})," 卷"]})}),n.text_quality&&(()=>{const m=Th(n.text_quality.grade);return m?i.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[i.jsx("span",{children:"文本質量:"}),i.jsx(Eh,{content:Zl[m],children:i.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:Ql[m],cursor:"help"},children:Qi[m]})}),n.text_quality.source_note&&i.jsxs("span",{style:{marginLeft:"4px"},children:["— ",n.text_quality.source_note]})]}):null})()]}),i.jsx(Mh,{files:r,groups:n.juan_groups,activeFile:a,onSelect:c,juanMeta:n.juan_metadata,matchStates:x}),d?i.jsx(it,{}):u?o?i.jsx(Vh,{juan:u,searchQuery:h,onNavigate:g,transport:s,workLabelCache:b}):i.jsx(Gh,{juan:u,rawText:p,searchQuery:h,onNavigate:g}):a?i.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null,n.references&&n.references.length>0&&i.jsxs("div",{style:{marginTop:"32px",paddingTop:"16px",borderTop:"1px solid var(--bim-widget-border, #eee)"},children:[i.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #aaa)",marginBottom:"8px",letterSpacing:"2px"},children:"參考文獻"}),n.references.map((m,k)=>i.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[i.jsxs("span",{children:[k+1,". "]}),m.url?i.jsx("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:m.title}):i.jsx("span",{children:m.title}),m.author&&i.jsxs("span",{children:[",",m.author]}),m.note&&i.jsxs("span",{children:["。",m.note]})]},k))]})]})},Jh={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},Zh={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function Qh(e){try{const t=new Date(e),n=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}catch{return e}}const Cl=({items:e,loading:t})=>{const n=Fe();return t?i.jsx(it,{}):e.length===0?i.jsx("div",{style:eg,children:"暂无反馈"}):i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const o=Jh[r.type],l=Zh[r.status];return i.jsxs("div",{style:tg,children:[i.jsxs("div",{style:ng,children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[i.jsx("span",{style:{...Ei,background:o.color},children:o.label}),i.jsx("span",{style:{...Ei,background:l.color},children:l.label})]}),i.jsx("span",{style:rg,children:Qh(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&i.jsxs("div",{style:ig,children:[r.resourceId&&i.jsx("a",{href:n(r.resourceId),style:Ti,children:r.resourceId}),r.pageUrl&&!r.resourceId&&i.jsx("a",{href:r.pageUrl,style:Ti,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),i.jsx("div",{style:og,children:r.content}),r.reply&&i.jsxs("div",{style:lg,children:[i.jsx("div",{style:sg,children:"回复"}),i.jsx("div",{children:r.reply})]})]},r.id)})})},eg={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},tg={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},ng={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Ei={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},rg={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},ig={fontSize:"12px",marginBottom:"6px"},Ti={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},og={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},lg={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},sg={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},Jn=({transport:e,onNavigate:t,recommendedIds:n,activeTab:r,onTabChange:o,feedbackApiUrl:l})=>{const s=G(),[a,c]=v.useState(null),[u,p]=v.useState([]),[d,h]=v.useState("recommend"),[f,g]=v.useState([]),[b,x]=v.useState(!1),m=r??d,k=L=>{h(L),o==null||o(L)},[w,_]=v.useState(!0),[I,S]=v.useState(null),[T,z]=v.useState(null),[B,C]=v.useState(null);v.useEffect(()=>{let L=!1;if(e.getCounts)return e.getCounts().then(N=>{L||c({works:N.works,books:N.books,collections:N.collections})}).catch(()=>{}),()=>{L=!0}},[e]),v.useEffect(()=>{let L=!1;return(async()=>{if(n)return n;if(e.getRecommended)try{const M=await e.getRecommended();if(M!=null&&M.groups)return M.groups.flatMap(D=>D.items.map(U=>({...U,group:D.name})))}catch{}return[]})().then(async M=>{if(L)return;const D=M.filter(y=>y.id);if(D.length===0){_(!1);return}const U=await Promise.all(D.map(async y=>{if(y.type)return{id:y.id,title:y.title,type:y.type,author:y.author,dynasty:y.dynasty,role:y.role,edition:y.edition,has_text:y.has_text,has_image:y.has_image,has_collated:y.has_collated,subtype:y.subtype,primary_name:y.primary_name,group:y.group,fallbackDescription:y.description};try{let q=null;if(e.getEntry)q=await e.getEntry(y.id);else{const Z=await e.getItem(y.id);Z&&(q={id:y.id,title:Z.title||y.id,type:Z.type||"work"})}if(q)return{...q,group:y.group,fallbackDescription:y.description}}catch{}return{id:y.id,title:y.title,type:ne.extractType(y.id),group:y.group,fallbackDescription:y.description}}));L||(p(U.filter(y=>y!==null)),_(!1))}),()=>{L=!0}},[e,n]);const E=v.useRef(!1),A=v.useRef(!1),$=v.useRef(!1);v.useEffect(()=>{if(m!=="catalog"||E.current)return;const L=e.getCatalogProgress??e.getResourceProgress;if(!L)return;E.current=!0;let N=!1;return L.call(e).then(M=>{N||S(M)}).catch(()=>{E.current=!1}),()=>{N=!0}},[e,m]),v.useEffect(()=>{if(m!=="collection"||A.current||!e.getCollectionProgress)return;A.current=!0;let L=!1;return e.getCollectionProgress().then(N=>{L||z(N)}).catch(()=>{A.current=!1}),()=>{L=!0}},[e,m]),v.useEffect(()=>{if(m!=="site"||$.current||!e.getSiteProgress)return;$.current=!0;let L=!1;return e.getSiteProgress().then(N=>{L||C(N)}).catch(()=>{$.current=!1}),()=>{L=!0}},[e,m]),v.useEffect(()=>{if(!l||m!=="feedback")return;let L=!1;return x(!0),fetch(l).then(N=>N.json()).then(N=>{!L&&N.success&&g(N.items||[])}).catch(()=>{}).finally(()=>{L||x(!1)}),()=>{L=!0}},[l,m]);const P=L=>{switch(L){case"work":return"✍️";case"book":return"📖";case"collection":return"📚";case"entity":return"👤";default:return""}};return i.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:"var(--bim-fg, #333)"},children:i.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[i.jsxs("div",{style:{display:"flex",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"16px"},children:[i.jsx(_t,{label:s.home.recommendTab,active:m==="recommend",onClick:()=>k("recommend")}),i.jsx(_t,{label:s.home.catalogTab,active:m==="catalog",onClick:()=>k("catalog")}),i.jsx(_t,{label:s.home.collectionTab,active:m==="collection",onClick:()=>k("collection")}),i.jsx(_t,{label:s.home.siteTab,active:m==="site",onClick:()=>k("site")}),l&&i.jsx(_t,{label:s.home.feedbackTab,active:m==="feedback",onClick:()=>k("feedback")})]}),m==="recommend"&&i.jsx(ag,{recommended:u,loading:w,onNavigate:t,getIcon:P,t:s}),m==="catalog"&&i.jsx(_i,{progress:I,t:s,onNavigate:t}),m==="collection"&&i.jsx(_i,{progress:T,t:s,onNavigate:t}),m==="site"&&i.jsx(ug,{progress:B,t:s,totalWorks:(a==null?void 0:a.works)??0}),m==="feedback"&&l&&i.jsx(Cl,{items:f,loading:b})]})})},_t=({label:e,active:t,onClick:n})=>i.jsx("button",{onClick:n,style:{padding:"8px 16px",fontSize:"14px",fontWeight:t?600:400,color:t?"var(--bim-primary, #2563eb)":"var(--bim-desc-fg, #717171)",background:"none",border:"none",borderBottom:t?"2px solid var(--bim-primary, #2563eb)":"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:e}),ag=({recommended:e,loading:t,onNavigate:n,getIcon:r,t:o})=>{const l=Fe();if(t)return i.jsx(it,{});if(e.length===0)return null;const s=new Map;for(const a of e){const c=a.group||o.home.recommendedBrowse;s.has(c)||s.set(c,[]),s.get(c).push(a)}return i.jsx(i.Fragment,{children:Array.from(s.entries()).map(([a,c])=>i.jsxs("div",{style:{marginBottom:"20px"},children:[i.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:a}),i.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:c.map(u=>{const p=u.dynasty||u.author?`${u.dynasty?`〔${u.dynasty}〕`:""}${u.author||""}`:u.fallbackDescription;return i.jsxs("a",{href:l(u.id),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),n==null||n(u.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)",textDecoration:"none",color:"inherit"},children:[i.jsx("span",{style:{fontSize:"20px"},children:r(u.type)}),i.jsxs("div",{style:{minWidth:0},children:[i.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[u.title,u.edition&&i.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:u.edition})]}),p&&i.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:p})]})]},u.id)})})]},a))})},_i=({progress:e,t,onNavigate:n})=>{if(!e)return i.jsx(it,{});const r=[...e.resources].sort((a,c)=>a.priority-c.priority),o=["in_progress","done","todo"],l={in_progress:t.home.statusInProgress,done:t.home.statusDone,todo:t.home.statusTodo},s={in_progress:"#f59e0b",done:"#10b981",todo:"#9ca3af"};return i.jsx("div",{children:o.map(a=>{const c=r.filter(u=>u.status===a);return c.length===0?null:i.jsxs("div",{style:{marginBottom:"20px"},children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[i.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:s[a]}}),l[a]," (",c.length,")"]}),i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(u=>i.jsx(cg,{item:u,t,statusColor:s[a],onNavigate:n},u.id))})]},a)})})},cg=({item:e,t,statusColor:n,onNavigate:r})=>{const o=Fe(),l=e.total>0?Math.round(e.imported/e.total*100):0,s=e.type==="catalog"?t.home.typeCatalog:t.home.typeCollection;return i.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[i.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const a=e.edition?`${e.name}·${e.edition}`:e.name,c=e.collection_id||e.work_id;return c&&r?i.jsx("a",{href:o(c),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),r(c))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:u=>u.currentTarget.style.borderBottomStyle="solid",onMouseLeave:u=>u.currentTarget.style.borderBottomStyle="dashed",children:a}):e.url?i.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:a}):a})()}),i.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:e.collection_id?t.indexType.collection:e.work_id?t.indexType.work:s})]}),i.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?Nt(t.home.progressFormat,{imported:String(e.imported),total:String(e.total)}):t.home.totalPending})]}),e.total>0&&i.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:i.jsx("div",{style:{height:"100%",width:`${l}%`,borderRadius:"2px",background:n,transition:"width 0.3s ease"}})}),e.description&&i.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:e.description})]})},ug=({progress:e,t,totalWorks:n})=>{if(!e)return i.jsx(it,{});const r=[...e.resources].sort((c,u)=>c.priority-u.priority),o=r.filter(c=>c.imported>0),l=r.filter(c=>c.imported===0),s=o.reduce((c,u)=>Math.max(c,u.imported),0),a=n>0?Math.round(s/n*100):0;return i.jsxs("div",{children:[n>0&&i.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:[t.home.siteCoverage,": ",i.jsx("strong",{children:s.toLocaleString()})," / ",n.toLocaleString()," ",t.indexType.work," (",a,"%)"]}),o.length>0&&i.jsxs("div",{style:{marginBottom:"20px"},children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[i.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"#10b981"}}),t.home.statusInProgress," (",o.length,")"]}),i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:o.map(c=>i.jsx(zi,{item:c,t,totalWorks:n},c.id))})]}),l.length>0&&i.jsxs("div",{style:{marginBottom:"20px"},children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[i.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"#9ca3af"}}),t.home.statusTodo," (",l.length,")"]}),i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(c=>i.jsx(zi,{item:c,t,totalWorks:n},c.id))})]})]})},zi=({item:e,t,totalWorks:n})=>{const r=n>0?Math.round(e.imported/n*100):0;return i.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[i.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:i.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:e.url?i.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:e.name}):e.name})}),i.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:e.imported>0?`${e.imported.toLocaleString()} ${t.indexType.work} (${r}%)`:t.home.statusTodo})]}),e.imported>0&&n>0&&i.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:i.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:"#10b981",transition:"width 0.3s ease"}})}),e.description&&i.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:e.description})]})},Ri="(max-width: 768px)";function dg(){const[e,t]=v.useState(()=>typeof window>"u"?!1:window.matchMedia(Ri).matches);return v.useEffect(()=>{const n=window.matchMedia(Ri),r=o=>t(o.matches);return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}const pg=({transport:e,hideModeIndicator:t=!0,onEntryClick:n,recommendedIds:r,headerRight:o})=>{var N;const l=G(),{convert:s}=X(),a=dg(),[c,u]=v.useState(null),[p,d]=v.useState(null),[h,f]=v.useState(!1),[g,b]=v.useState("detail"),[x,m]=v.useState([]),[k,w]=v.useState(!1),[_,I]=v.useState(null),[S,T]=v.useState(!1),z=v.useCallback(async M=>{if(!e.getCollatedEditionIndex){I(null);return}T(!0);try{const D=await e.getCollatedEditionIndex(M);I(D)}catch{I(null)}finally{T(!1)}},[e]),B=v.useCallback(async M=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){m([]);return}w(!0);try{if(e.getCollectionCatalogs){const D=await e.getCollectionCatalogs(M);m(D||[])}else if(e.getCollectionCatalog){const D=await e.getCollectionCatalog(M);m(D?[{resource_id:"",data:D}]:[])}}catch{m([])}finally{w(!1)}},[e]),C=v.useCallback(async M=>{if(n){n(M);return}u(M),d(null),m([]),I(null),b("detail"),f(!0);try{const D=await e.getItem(M.id);D&&(d(D),D.type==="collection"?B(M.id):D.type==="work"&&D.has_collated&&z(M.id))}catch(D){console.error("加载详情失败:",D)}finally{f(!1)}},[e,n,B,z]),E=v.useCallback(async M=>{d(null),m([]),I(null),b("detail"),f(!0);try{const D=await e.getItem(M);D&&(d(D),u({id:M,title:D.title||M,type:D.type||"book"}),D.type==="collection"?B(M):D.type==="work"&&D.has_collated&&z(M))}catch(D){console.error("导航失败:",D)}finally{f(!1)}},[e,B,z]),A=(p==null?void 0:p.type)==="collection"&&(x.length>0||k)||(p==null?void 0:p.type)==="work"&&(_||S),$=a&&(h||p),P=v.useCallback(()=>{u(null),d(null),m([]),I(null),b("detail")},[]),L=i.jsx(i.Fragment,{children:h?i.jsx(it,{}):p?i.jsxs(i.Fragment,{children:[(A||o)&&i.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:a?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:a?"auto":void 0},children:[A&&i.jsxs(i.Fragment,{children:[i.jsx("button",{onClick:()=>b("detail"),style:Zt(g==="detail"),children:l.detailTab.basicInfo}),p.type==="collection"&&k&&x.length===0&&i.jsxs("button",{onClick:()=>{},style:Zt(!1),children:[l.detailTab.catalog,i.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),p.type==="collection"&&x.map(M=>i.jsx("button",{onClick:()=>b(`catalog:${M.resource_id}`),style:Zt(g===`catalog:${M.resource_id}`),children:M.short_name?`${s(M.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},M.resource_id)),p.type==="work"&&(_||S)&&i.jsxs("button",{onClick:()=>b("collated"),style:Zt(g==="collated"),children:[l.detailTab.collatedEdition,S&&i.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),o&&i.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:o})]}),i.jsx("div",{style:{padding:a?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:g==="detail"?i.jsx(br,{data:p,transport:e,onNavigate:E}):g.startsWith("catalog:")?i.jsx(ml,{data:(N=x.find(M=>`catalog:${M.resource_id}`===g))==null?void 0:N.data,onNavigate:E}):g==="collated"?i.jsx(jl,{index:_||void 0,workId:p.id,transport:e,onNavigate:E}):null})]}):i.jsx(Jn,{transport:e,onNavigate:E,recommendedIds:r})});return a?i.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:$?i.jsxs(i.Fragment,{children:[i.jsx("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",flexShrink:0},children:i.jsxs("button",{onClick:P,style:{padding:"4px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px"},children:["← ",l.detailTab.basicInfo]})}),i.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:L})]}):i.jsxs("div",{style:{flex:1,overflow:"auto"},children:[i.jsx(Mn,{transport:e,onEntryClick:C,hideModeIndicator:t}),!p&&i.jsx(Jn,{transport:e,onNavigate:E,recommendedIds:r})]})}):i.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:[i.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:i.jsx("div",{style:{flex:1,overflow:"auto"},children:i.jsx(Mn,{transport:e,onEntryClick:C,hideModeIndicator:t})})}),i.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:L})]})};function Zt(e){return{padding:"10px 16px",border:"none",borderBottom:e?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:e?"var(--bim-primary, #0078d4)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}const fg=({data:e,onNavigate:t,className:n,style:r})=>{var p;const o=G(),{convert:l}=X(),[s,a]=v.useState(((p=e.divisions[0])==null?void 0:p.name)??null),[c,u]=v.useState(null);return i.jsxs("div",{className:n,style:r,children:[i.jsxs("div",{style:{marginBottom:"16px"},children:[i.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:l(e.title)}),e.stats&&i.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"16px"},children:[e.total_volumes!=null&&i.jsxs("span",{children:[o.catalog.totalVolumes," ",i.jsx("strong",{children:e.total_volumes})," ",o.unit.juan]}),e.stats.zhulu!=null&&i.jsxs("span",{children:["著錄 ",i.jsx("strong",{children:e.stats.zhulu})," ",o.unit.bu]}),e.stats.cunmu!=null&&i.jsxs("span",{children:["存目 ",i.jsx("strong",{children:e.stats.cunmu})," ",o.unit.bu]}),e.stats.categories!=null&&i.jsxs("span",{children:[e.stats.categories," 類"]})]})]}),i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(d=>i.jsx(hg,{division:d,expanded:s===d.name,onToggle:()=>a(s===d.name?null:d.name),expandedCat:c,onCatToggle:h=>u(c===h?null:h),onNavigate:t},d.name))})]})},hg=({division:e,expanded:t,onToggle:n,expandedCat:r,onCatToggle:o,onNavigate:l})=>{const{convert:s}=X(),a=e.categories.reduce((c,u)=>{const p=u.stats||{zhulu:0,cunmu:0};return c+(p.zhulu||0)+(p.cunmu||0)},0);return i.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[i.jsxs("button",{onClick:n,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:t?"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:[i.jsx("span",{children:s(e.name)}),i.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[e.categories.length," 類 · ",a," 部",i.jsx("span",{style:{marginLeft:"8px"},children:t?"▲":"▼"})]})]}),t&&i.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(c=>{const u=`${e.name}/${c.name}`;return i.jsx(gg,{category:c,expanded:r===u,onToggle:()=>o(u),onNavigate:l},c.name)})})]})},gg=({category:e,expanded:t,onToggle:n,onNavigate:r})=>{var c,u,p,d;const{convert:o}=X(),l=((c=e.books)==null?void 0:c.zhulu)||[],s=((u=e.books)==null?void 0:u.cunmu)||[],a=(((p=e.stats)==null?void 0:p.zhulu)||l.length)+(((d=e.stats)==null?void 0:d.cunmu)||s.length);return i.jsxs("div",{children:[i.jsxs("button",{onClick:n,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:t?"var(--bim-input-bg, #fff)":"transparent",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",textAlign:"left"},children:[i.jsxs("span",{style:{fontWeight:500},children:[o(e.name),e.volumes&&i.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px",fontWeight:400},children:["卷",e.volumes]})]}),i.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[a," 部 ",t?"▲":"▼"]})]}),t&&(l.length>0||s.length>0)&&i.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&i.jsx(Li,{label:"著錄",books:l,onNavigate:r}),s.length>0&&i.jsx(Li,{label:"存目",books:s,onNavigate:r})]})]})},Li=({label:e,books:t,onNavigate:n})=>{const{convert:r}=X(),o=Fe(),[l,s]=v.useState(t.length<=20),a=l?t:t.slice(0,10);return i.jsxs("div",{style:{marginBottom:"8px"},children:[i.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"4px",fontWeight:500},children:[e," (",t.length,")"]}),i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:a.map((c,u)=>i.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[i.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:c.work_id&&n?i.jsx("a",{href:o(c.work_id),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),n(c.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(c.title)}):r(c.title)}),c.volumes&&i.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(c.volumes)}),c.author&&i.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(c.author).slice(0,20)})]},u))}),!l&&i.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:["展開全部 ",t.length," 條"]})]})},Ae=({title:e,onSave:t,onAskAI:n,extraButtons:r,children:o})=>{const l=G();return i.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[i.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[i.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e}),i.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,n&&i.jsx("button",{onClick:n,style:mg,children:"AI"}),t&&i.jsx("button",{onClick:t,style:xg,children:l.action.save})]})]}),o]})},xg={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},mg={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Ie=({label:e,value:t,onChange:n,placeholder:r,disabled:o})=>i.jsxs("div",{style:{marginBottom:"16px"},children:[i.jsx("label",{style:{display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},children:e}),i.jsx("input",{type:"text",value:t,onChange:l=>n(l.target.value),placeholder:r,disabled:o,style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),tt=({value:e,onChange:t,placeholder:n})=>{const r=v.useRef(null);return v.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[e]),i.jsx("textarea",{ref:r,value:e||"",onChange:o=>t(o.target.value),placeholder:n,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"}})},an=({children:e,color:t,style:n})=>i.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:t||"var(--bim-primary-soft, rgba(0,120,212,0.15))",color:t?"#fff":"var(--bim-fg, #333)",...n},children:e});function bg(e){const t=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return t?{name:t[1],id:t[2]}:null}const tn=({value:e,onChange:t,label:n})=>{const[r,o]=v.useState(!1),l=v.useRef(null),s=bg(e||"");return v.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&s?i.jsxs("div",{style:{marginBottom:"16px"},children:[i.jsx("label",{style:Ai,children:n}),i.jsxs("div",{onClick:()=>o(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",minHeight:"30px"},children:[i.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:"var(--bim-fg, #333)"},children:s.name}),i.jsx(an,{children:s.id})]})]}):i.jsxs("div",{style:{marginBottom:"16px"},children:[i.jsx("label",{style:Ai,children:n}),i.jsx("input",{ref:l,type:"text",value:e||"",onChange:a=>t(a.target.value),onBlur:()=>o(!1),style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},Ai={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function yg(e){switch(e){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function kg(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Il=({items:e,onChange:t,onOpenEntityPicker:n})=>{const r=G(),[o,l]=v.useState(null),s=()=>{t([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(e.length)},a=d=>{t(e.filter((h,f)=>f!==d)),o===d&&l(null)},c=(d,h,f)=>{const g=[...e];g[d]={...g[d],[h]:f},t(g)},u=(d,h)=>{const f=[...e];f[d]={...f[d],type:h,id:"",name:""},t(f),h==="bookID"&&n&&n(g=>{const b=[...e];b[d]={...b[d],id:g.id,name:g.title,type:"bookID"},t(b)})},p=d=>{n&&n(h=>{const f=[...e];f[d]={...f[d],id:h.id,name:h.title,type:"bookID"},t(f)})};return i.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((d,h)=>i.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(o===h?null:h),children:[i.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:o===h?"▼":"▶"}),i.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:d.name||`${r.editor.sourcePlaceholder} ${h+1}`}),d.type&&i.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:yg(d.type),color:"white",borderRadius:"3px",fontWeight:500},children:kg(d.type)}),i.jsx("button",{onClick:f=>{f.stopPropagation(),a(h)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),o===h&&i.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:i.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!d.type&&i.jsxs("div",{children:[i.jsx("label",{style:qe,children:r.editor.selectSourceType}),i.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[i.jsxs("button",{onClick:()=>u(h,"bookID"),style:{...Bi,borderColor:"#4caf50",color:"#4caf50"},children:[i.jsx("span",{style:{fontSize:"18px"},children:"📚"}),i.jsx("span",{children:"Book ID"}),i.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),i.jsxs("button",{onClick:()=>u(h,"url"),style:{...Bi,borderColor:"#2196f3",color:"#2196f3"},children:[i.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),i.jsx("span",{children:"URL"}),i.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),d.type==="bookID"&&i.jsx(i.Fragment,{children:i.jsxs("div",{children:[i.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[i.jsx("label",{style:qe,children:r.action.selectBookOrWork}),i.jsx("button",{onClick:()=>{const f=[...e];f[h]={...f[h],type:"",id:"",name:""},t(f)},style:Pi,children:r.action.changeType})]}),d.id&&d.name?i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid #4caf50",borderRadius:"6px"},children:[i.jsx("span",{style:{color:"#4caf50",fontSize:"16px"},children:"✓"}),i.jsxs("div",{style:{flex:1},children:[i.jsx("div",{style:{fontWeight:500},children:d.name}),i.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:d.id})]}),i.jsx("button",{onClick:()=>p(h),style:{background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-fg, #333)",cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):i.jsxs("button",{onClick:()=>p(h),style:{width:"100%",padding:"14px",border:"2px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[i.jsx("span",{children:"🔍"}),i.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),d.type==="url"&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[i.jsx("label",{style:qe,children:r.label.sourceName}),i.jsx("button",{onClick:()=>{const f=[...e];f[h]={...f[h],type:"",id:"",name:""},t(f)},style:Pi,children:r.action.changeType})]}),i.jsx("input",{type:"text",value:d.name,onChange:f=>c(h,"name",f.target.value),placeholder:r.editor.sourceNamePlaceholder,style:ut})]}),i.jsxs("div",{children:[i.jsx("label",{style:qe,children:r.label.urlAddress}),i.jsx("input",{type:"text",value:d.id,onChange:f=>c(h,"id",f.target.value),placeholder:"https://...",style:ut})]})]}),d.type&&i.jsxs(i.Fragment,{children:[i.jsx("div",{style:{borderTop:"1px dashed var(--bim-widget-border, #e0e0e0)",paddingTop:"12px",marginTop:"4px"},children:i.jsx("label",{style:{...qe,opacity:.7},children:r.label.optionalInfo})}),i.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[i.jsxs("div",{children:[i.jsx("label",{style:qe,children:r.label.detailsOptional}),i.jsx("input",{type:"text",value:d.details,onChange:f=>c(h,"details",f.target.value),placeholder:r.editor.detailsPlaceholder,style:ut})]}),i.jsxs("div",{children:[i.jsx("label",{style:qe,children:r.label.positionOptional}),i.jsx("input",{type:"text",value:d.position,onChange:f=>c(h,"position",f.target.value),placeholder:"如: 卷三, p.52",style:ut})]})]}),i.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[i.jsxs("div",{children:[i.jsx("label",{style:qe,children:r.label.dataVersionOptional}),i.jsx("input",{type:"text",value:d.version,onChange:f=>c(h,"version",f.target.value),placeholder:"如: v1.0, 2024-01",style:ut})]}),i.jsxs("div",{children:[i.jsx("label",{style:qe,children:r.label.processorVersionOptional}),i.jsx("input",{type:"text",value:d.processor_version,onChange:f=>c(h,"processor_version",f.target.value),placeholder:"如: v0.1",style:ut})]})]})]})]})})]},h)),i.jsxs("button",{onClick:s,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[i.jsx("span",{children:"+"}),i.jsx("span",{children:r.action.addSource})]})]})},qe={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},ut={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"},Bi={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"},Pi={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function El(e){if(!e||!e.trim())return[];try{const t=JSON.parse(e);if(Array.isArray(t))return t.map(n=>({id:n.id||"",name:n.name||"",type:n.type||"",details:n.details||"",position:n.position||"",version:n.version||"",processor_version:n.processor_version||""}))}catch{}return[]}function Tl(e){return!e||e.length===0?"":JSON.stringify(e)}const _l=({entityType:e,entityId:t,entityTitle:n,parentWork:r,parentCollection:o,belongsToWork:l,belongsToCollection:s,childWorks:a,childCollections:c,containedBooks:u,siblingBooks:p,onLinkEntity:d,onUnlinkEntity:h,onViewEntity:f,onCreateAndLink:g,onSaveRelations:b})=>{const x=G();return i.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[i.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:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[i.jsx("span",{children:"🔗"}),i.jsx("span",{children:x.section.relations})]}),b&&i.jsx("button",{onClick:b,style:vg,children:x.action.save})]}),i.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&i.jsxs(i.Fragment,{children:[i.jsx(zt,{direction:"up",title:x.relation.belongsToWork,entity:l,onView:f,onUnlink:()=>h("workId"),onLink:()=>d("workId","work"),onCreate:()=>g("workId","work",{title:n}),linkLabel:x.action.linkExisting,createLabel:x.action.createAndLink,notLinkedLabel:x.relation.notLinked,viewLabel:x.action.viewEntity,unlinkLabel:x.action.unlink}),i.jsx(zt,{direction:"up",title:x.relation.containedInCollection,entity:s,onView:f,onUnlink:()=>h("collectionId"),onLink:()=>d("collectionId","collection"),onCreate:()=>g("collectionId","collection",{title:n}),linkLabel:x.action.linkExisting,createLabel:x.action.createAndLink,notLinkedLabel:x.relation.notLinked,viewLabel:x.action.viewEntity,unlinkLabel:x.action.unlink}),l&&p&&p.length>0&&i.jsx(dt,{direction:"horizontal",title:`${x.relation.siblingVersions} (${p.length})`,entities:p,onView:f,onAdd:()=>g("siblingBook","book",{workId:l.id}),addLabel:x.relation.addVersionForWork,noneLabel:x.relation.none,expandMoreLabel:x.action.expandMore})]}),e==="work"&&i.jsxs(i.Fragment,{children:[i.jsx(zt,{direction:"up",title:x.relation.parentWork,entity:r,onView:f,onUnlink:()=>h("parentWorkId"),onLink:()=>d("parentWorkId","work"),onCreate:()=>g("parentWorkId","work"),linkLabel:x.action.linkExisting,createLabel:x.action.createAndLink,notLinkedLabel:x.relation.notLinked,viewLabel:x.action.viewEntity,unlinkLabel:x.action.unlink}),a&&a.length>0&&i.jsx(dt,{direction:"down",title:`${x.relation.childWorks} (${a.length})`,entities:a,onView:f,onAdd:()=>g("childWork","work",{parentWorkId:t}),addLabel:x.action.addSubWork,noneLabel:x.relation.none,expandMoreLabel:x.action.expandMore}),c&&c.length>0&&i.jsx(dt,{direction:"down",title:`${x.relation.collectionImpl} (${c.length})`,entities:c,onView:f,onAdd:()=>g("childCollection","collection",{workId:t}),addLabel:x.action.addCollectionImpl,noneLabel:x.relation.none,expandMoreLabel:x.action.expandMore}),i.jsx(dt,{direction:"down",title:`${x.relation.allVersions} (${(u==null?void 0:u.length)??0})`,entities:u||[],onView:f,onAdd:()=>g("childBook","book",{workId:t}),addLabel:x.action.addVersion,noneLabel:x.relation.none,expandMoreLabel:x.action.expandMore})]}),e==="collection"&&i.jsxs(i.Fragment,{children:[i.jsx(zt,{direction:"up",title:x.relation.correspondingWork,entity:l,onView:f,onUnlink:()=>h("workId"),onLink:()=>d("workId","work"),onCreate:()=>g("workId","work",{title:n}),linkLabel:x.action.linkExisting,createLabel:x.action.createAndLink,notLinkedLabel:x.relation.notLinked,viewLabel:x.action.viewEntity,unlinkLabel:x.action.unlink}),i.jsx(zt,{direction:"up",title:x.relation.parentCollection,entity:o,onView:f,onUnlink:()=>h("parentCollectionId"),onLink:()=>d("parentCollectionId","collection"),onCreate:()=>g("parentCollectionId","collection"),linkLabel:x.action.linkExisting,createLabel:x.action.createAndLink,notLinkedLabel:x.relation.notLinked,viewLabel:x.action.viewEntity,unlinkLabel:x.action.unlink}),i.jsx(dt,{direction:"down",title:`${x.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:f,onAdd:()=>g("childCollection","collection",{parentCollectionId:t}),addLabel:x.action.addSubCollection,noneLabel:x.relation.none,expandMoreLabel:x.action.expandMore}),i.jsx(dt,{direction:"down",title:`${x.relation.containedBooks} (${(u==null?void 0:u.length)??0})`,entities:u||[],onView:f,onAdd:()=>g("childBook","book",{collectionId:t}),addLabel:x.action.addBook,noneLabel:x.relation.none,expandMoreLabel:x.action.expandMore})]})]})]})},zt=({direction:e,title:t,entity:n,onView:r,onUnlink:o,onLink:l,onCreate:s,linkLabel:a,createLabel:c,notLinkedLabel:u,viewLabel:p,unlinkLabel:d})=>{const h=e==="up"?"#2196f3":e==="down"?"#4caf50":"#ff9800",f=e==="up"?"⬆️":e==="down"?"⬇️":"↔️";return i.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[i.jsxs("div",{style:{fontSize:"12px",color:h,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[i.jsx("span",{children:f}),i.jsx("span",{children:t})]}),n?i.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px"},children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[i.jsx("span",{children:zl(n.type)}),i.jsx("span",{style:{fontWeight:500},children:n.title}),i.jsx("span",{style:{fontSize:"11px",opacity:.6},children:n.id})]}),i.jsxs("div",{style:{display:"flex",gap:"4px"},children:[i.jsx(Fi,{onClick:()=>r(n),title:p,children:"👁️"}),i.jsx(Fi,{onClick:o,title:d,danger:!0,children:"✕"})]})]}):i.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:u}),i.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[i.jsx(Zn,{onClick:l,children:a}),i.jsx(Zn,{onClick:s,primary:!0,children:c})]})]})},dt=({direction:e,title:t,entities:n,onView:r,onAdd:o,addLabel:l,noneLabel:s,expandMoreLabel:a})=>{const[c,u]=v.useState(!1),p=e==="up"?"#2196f3":e==="down"?"#4caf50":"#ff9800",d=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",h=c?n:n.slice(0,5);return i.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[i.jsxs("div",{style:{fontSize:"12px",color:p,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[i.jsx("span",{children:d}),i.jsx("span",{children:t})]}),n.length>0?i.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[h.map(f=>i.jsxs("div",{onClick:()=>r(f),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[i.jsx("span",{children:zl(f.type)}),i.jsx("span",{children:f.title})]},f.id)),n.length>5&&!c&&i.jsxs("div",{onClick:()=>u(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[a," (",n.length-5,")"]})]}):i.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:s}),i.jsx("div",{style:{marginTop:"8px"},children:i.jsxs(Zn,{onClick:o,primary:!0,children:["+ ",l]})})]})},Fi=({onClick:e,title:t,danger:n,children:r})=>i.jsx("button",{onClick:o=>{o.stopPropagation(),e()},title:t,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:n?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:r}),Zn=({onClick:e,primary:t,children:n})=>i.jsx("button",{onClick:e,style:{padding:"4px 10px",fontSize:"11px",border:t?"none":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:t?"var(--bim-primary, #0078d4)":"transparent",color:t?"var(--bim-primary-fg, #fff)":"inherit",cursor:"pointer"},children:n});function zl(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const vg={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"},Rl=({isOpen:e,entityType:t,title:n,onSelect:r,onCancel:o,onCreate:l,searchResults:s,onSearch:a,isLoading:c,excludeId:u})=>{const[p,d]=v.useState(""),h=u?s.filter(x=>x.id!==u):s;v.useEffect(()=>{e&&(d(""),a(""))},[e]);const f=x=>{d(x),a(x)};if(!e)return null;const g=t==="work"?"作品":t==="book"?"书籍":"丛编",b=t==="work"?"📜":t==="book"?"📖":"📚";return i.jsx("div",{style:Sg,children:i.jsxs("div",{style:wg,children:[i.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[i.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:n}),i.jsx("button",{onClick:o,style:jg,children:"✕"})]}),i.jsx("div",{style:{padding:"12px 16px"},children:i.jsx("input",{type:"text",value:p,onChange:x=>f(x.target.value),placeholder:`搜索${g}名称或 ID...`,autoFocus:!0,style:Cg})}),i.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?i.jsx("div",{style:Bn,children:"搜索中..."}):h.length>0?i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:h.map(x=>i.jsxs("div",{onClick:()=>r(x),style:Ig,children:[i.jsx("span",{style:{fontSize:"16px"},children:b}),i.jsxs("div",{style:{flex:1},children:[i.jsxs("div",{style:{fontWeight:500},children:[x.title,x.edition&&i.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:x.edition})]}),i.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[x.id,x.author&&` · ${x.author}`,x.dynasty&&` · ${x.dynasty}`]})]})]},x.id))}):p?i.jsxs("div",{style:Bn,children:["未找到匹配的",g]}):i.jsxs("div",{style:Bn,children:["输入关键词搜索",g]})}),i.jsxs("div",{style:{padding:"12px 16px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[i.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),i.jsxs("button",{onClick:l,style:Eg,children:["创建新",g,"并关联"]})]})]})})},Sg={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},wg={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},jg={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Cg={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"},Ig={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Bn={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},Eg={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Di={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Tg={work:"📜",book:"📖",collection:"📚",entity:"👤"},Ll=({isOpen:e,entityType:t,relationField:n,inheritData:r,onConfirm:o,onCancel:l})=>{const[s,a]=v.useState(""),c=v.useRef(null);v.useEffect(()=>{e&&(a((r==null?void 0:r.title)||""),setTimeout(()=>{var h,f;(h=c.current)==null||h.focus(),(f=c.current)==null||f.select()},100))},[e,r==null?void 0:r.title]);const u=h=>{h.key==="Enter"&&s.trim()?p():h.key==="Escape"&&l()},p=()=>{s.trim()&&o(s.trim(),{...r,title:s.trim()})};if(!e)return null;const d=()=>{switch(n){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`创建新${Di[t]}`}};return i.jsx("div",{style:_g,onClick:h=>{h.target===h.currentTarget&&l()},children:i.jsxs("div",{style:zg,onClick:h=>h.stopPropagation(),children:[i.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[i.jsx("span",{children:Tg[t]}),i.jsx("span",{children:d()})]}),i.jsxs("div",{style:{marginBottom:"16px"},children:[i.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[t==="work"?"作品名":t==="collection"?"丛编名":"书名",i.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),i.jsx("input",{ref:c,type:"text",value:s,onChange:h=>a(h.target.value),onKeyDown:u,placeholder:`请输入${Di[t]}名称...`,style:Rg})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&i.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:[i.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&i.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&i.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),i.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[i.jsx("button",{onClick:l,style:Lg,children:"取消"}),i.jsx("button",{onClick:p,disabled:!s.trim(),style:{...Ag,opacity:s.trim()?1:.6,cursor:s.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},_g={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},zg={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Rg={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"},Lg={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Ag={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Bg(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Al(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Pg(e){switch(e){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const Bl=({isOpen:e,title:t,filterType:n="all",recentEntities:r=[],excludeId:o,showCreateButton:l=!1,createButtonText:s,onSelect:a,onCancel:c,onCreate:u,onSearch:p})=>{const[d,h]=v.useState(""),[f,g]=v.useState([]),[b,x]=v.useState(!1),[m,k]=v.useState("recent");v.useEffect(()=>{e&&(h(""),g([]),k(r.length>0?"recent":"search"))},[e,r.length]),v.useEffect(()=>{if(!d.trim()){g([]);return}const z=setTimeout(async()=>{x(!0);try{g(await p(d,n))}catch{g([])}finally{x(!1)}},300);return()=>clearTimeout(z)},[d,n,p]);const w=v.useCallback(z=>{h(z.target.value),z.target.value.trim()&&k("search")},[]),_=v.useCallback(z=>o?z.filter(B=>B.id!==o):z,[o]);if(!e)return null;const I=t||(n==="all"?"选择实体":`选择${Al(n)}`),S=_(r),T=_(f);return i.jsx("div",{style:Dg,children:i.jsxs("div",{style:Mg,children:[i.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[i.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:I}),i.jsx("button",{onClick:c,style:Og,children:"✕"})]}),i.jsx("div",{style:{padding:"16px 20px 12px"},children:i.jsxs("div",{style:{position:"relative"},children:[i.jsx("input",{type:"text",value:d,onChange:w,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Wg}),i.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),b&&i.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),S.length>0&&i.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[i.jsxs(Mi,{active:m==="recent",onClick:()=>k("recent"),children:["最近使用 (",S.length,")"]}),i.jsxs(Mi,{active:m==="search",onClick:()=>k("search"),children:["搜索结果 ",T.length>0&&`(${T.length})`]})]}),i.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:m==="recent"&&S.length>0?i.jsx(Oi,{entities:S,onSelect:a}):d.trim()?b?i.jsx(Pn,{message:"搜索中..."}):T.length>0?i.jsx(Oi,{entities:T,onSelect:a}):i.jsx(Pn,{message:"未找到匹配的结果"}):i.jsx(Pn,{message:"输入关键词开始搜索"})}),l&&u&&i.jsxs("div",{style:{padding:"12px 20px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[i.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),i.jsx("button",{onClick:u,style:$g,children:s||"创建新实体"})]})]})})},Mi=({active:e,onClick:t,children:n})=>i.jsx("button",{onClick:t,style:{padding:"10px 16px",border:"none",borderBottom:e?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:e?"var(--bim-fg, #333)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",fontWeight:e?600:400,marginBottom:"-1px"},children:n}),Oi=({entities:e,onSelect:t})=>i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(n=>i.jsx(Fg,{entity:n,onClick:()=>t(n)},n.id))}),Fg=({entity:e,onClick:t})=>{const[n,r]=v.useState(!1);return i.jsxs("div",{onClick:t,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:n?"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:[i.jsx("span",{style:{fontSize:"18px"},children:Bg(e.type)}),i.jsxs("div",{style:{flex:1,minWidth:0},children:[i.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[e.title,e.edition&&i.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:e.edition})]}),i.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[i.jsx("code",{style:{fontSize:"10px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"1px 4px",borderRadius:"2px"},children:e.id}),e.author&&i.jsx("span",{children:e.author}),e.dynasty&&i.jsx("span",{children:e.dynasty})]})]}),i.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:Pg(e.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:Al(e.type)})]})},Pn=({message:e})=>i.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:e}),Dg={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},Mg={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Og={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Wg={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"},$g={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Ng={work:"#4caf50",collection:"#2196f3",book:"#ff9800",entity:"#9c27b0"},Hg={work:"📜",collection:"📚",book:"📖",entity:"👤"},Pl=({data:e,onChange:t,onSave:n,transport:r,onNavigate:o,showDelete:l,onDelete:s,onAskAI:a,renderSectionActions:c,onDownloadResource:u,downloadStatuses:p,relations:d,onRelationsChange:h})=>{var he;const f=G(),[g,b]=v.useState(!1),[x,m]=v.useState("work"),[k,w]=v.useState(""),[_,I]=v.useState(""),[S,T]=v.useState([]),[z,B]=v.useState(!1),[C,E]=v.useState(!1),[A,$]=v.useState("work"),[P,L]=v.useState(""),[N,M]=v.useState(),[D,U]=v.useState(!1),[y,q]=v.useState(null),[Z,j]=v.useState([]);v.useRef(null);const ce=e.type,be=ce==="work",se=ce==="collection",pe=ce==="book",re=v.useCallback((W,Q)=>{t({...e,[W]:Q})},[e,t]),De=v.useCallback((W,Q)=>{w(W),m(Q),I(f.editor.selectToLink+f.indexType[Q]),T([]),b(!0)},[f]),Me=v.useCallback(W=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,W)},[r,e.id]),Oe=v.useCallback(W=>{o==null||o(W.id,W.type)},[o]),Je=v.useCallback((W,Q,ye)=>{const Te={...ye,author:(ye==null?void 0:ye.author)||e.author,dynasty:(ye==null?void 0:ye.dynasty)||e.dynasty};$(Q),L(W),M(Te),E(!0)},[e.author,e.dynasty]),yt=v.useCallback((W,Q)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,P,{type:A,title:W,inheritData:Q}),E(!1)},[r,e.id,P,A]),ot=v.useCallback(W=>{if(!W.trim()){T([]);return}B(!0),r!=null&&r.searchEntities&&r.searchEntities(W,x).then(Q=>{T(Q),B(!1)}).catch(()=>{T([]),B(!1)})},[r,x]),lt=v.useCallback(W=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,k,W.id),b(!1)},[r,e.id,k]),V=v.useCallback(()=>{n()},[n]),de=v.useCallback(W=>{q(()=>W),U(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(j).catch(()=>{})},[r]),ie=v.useCallback((W,Q)=>r!=null&&r.searchEntities?r.searchEntities(W,Q==="all"?void 0:Q):Promise.resolve([]),[r]),ue=v.useCallback(W=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(W),j(Q=>[W,...Q.filter(ye=>ye.id!==W.id)].slice(0,10)),y==null||y(W),U(!1),q(null)},[r,y]);return i.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[i.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",paddingBottom:"16px"},children:i.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[i.jsx("span",{children:Hg[ce]}),i.jsx("span",{children:e.title||f.editor.untitled}),i.jsx(an,{children:e.id}),i.jsx(an,{color:Ng[ce],children:f.indexType[ce]})]})}),i.jsx(Ae,{title:f.section.basicInfo,onSave:n,onAskAI:a?()=>a("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:i.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[i.jsx(tn,{label:be?f.editor.workTitle:se?f.editor.collectionTitle:f.editor.bookTitle,value:e.title,onChange:W=>re("title",W)}),pe&&i.jsx(tn,{label:f.editor.belongsToWork,value:e.workName||"",onChange:W=>re("workName",W)}),i.jsx(Ie,{label:f.editor.authorLabel,value:e.author||"",onChange:W=>re("author",W)}),i.jsx(Ie,{label:f.editor.dynastyLabel,value:e.dynasty||"",onChange:W=>re("dynasty",W)}),(pe||se)&&i.jsx(tn,{label:f.editor.containedIn,value:e.collection||"",onChange:W=>re("collection",W)}),(pe||se)&&i.jsx(Ie,{label:f.editor.holderLabel,value:e.holder||"",onChange:W=>re("holder",W)}),(pe||se)&&i.jsx(Ie,{label:pe?f.editor.pageLabel:f.editor.volumeLabel,value:e.pages||"",onChange:W=>re("pages",W)}),i.jsx("div",{style:{gridColumn:"1 / -1"},children:i.jsx(Ie,{label:f.editor.firstImageLabel,value:e.firstImage||"",onChange:W=>re("firstImage",W)})})]})}),i.jsx(Ae,{title:f.section.description,onSave:n,onAskAI:a?()=>a("介绍"):void 0,children:i.jsx(tt,{value:e.description||"",onChange:W=>re("description",W),placeholder:f.editor.descriptionPlaceholder})}),(((he=e.additional_works)==null?void 0:he.length)||0)>0&&i.jsx(Ae,{title:f.section.additionalWorks,onSave:n,children:i.jsx(Ug,{items:e.additional_works||[],onChange:W=>re("additional_works",W)})}),i.jsx(Ae,{title:f.section.indexedBy,onSave:n,onAskAI:a?()=>a("收录于"):void 0,children:i.jsx(Vg,{items:e.indexed_by||[],onChange:W=>re("indexed_by",W)})}),i.jsx(Ae,{title:f.section.emendatedBy,onSave:n,onAskAI:a?()=>a("考证"):void 0,children:i.jsx(qg,{items:e.emendated_by||[],onChange:W=>re("emendated_by",W)})}),i.jsx(Ae,{title:f.section.textResources,onSave:n,onAskAI:a?()=>a("资源"):void 0,children:i.jsx(Dn,{items:e.resources||[],onChange:W=>re("resources",W),onDownload:u,downloadStatuses:p,filterType:"text"})}),i.jsx(Ae,{title:f.section.imageResources,onSave:n,children:i.jsx(Dn,{items:e.resources||[],onChange:W=>re("resources",W),onDownload:u,downloadStatuses:p,filterType:"image"})}),i.jsx(Ae,{title:f.section.sources,onSave:n,onAskAI:a?()=>a("资料来源"):void 0,children:i.jsx(Il,{items:El(e.sources||""),onChange:W=>re("sources",Tl(W)),onOpenEntityPicker:de})}),(pe||se)&&i.jsx(Ae,{title:f.section.provenance,onSave:n,onAskAI:a?()=>a("收藏历史"):void 0,children:i.jsx(tt,{value:e.provenance||"",onChange:W=>re("provenance",W),placeholder:f.editor.provenancePlaceholder})}),pe&&i.jsx(Ae,{title:f.section.otherEditions,onSave:n,onAskAI:a?()=>a("其他版本"):void 0,children:i.jsx(tt,{value:e.otherEditions||"",onChange:W=>re("otherEditions",W),placeholder:f.editor.otherEditionsPlaceholder})}),i.jsx(_l,{entityType:ce,entityId:e.id,entityTitle:e.title,parentWork:d==null?void 0:d.parentWork,parentCollection:d==null?void 0:d.parentCollection,belongsToWork:d==null?void 0:d.belongsToWork,belongsToCollection:d==null?void 0:d.belongsToCollection,childWorks:d==null?void 0:d.childWorks,childCollections:d==null?void 0:d.childCollections,containedBooks:d==null?void 0:d.containedBooks,siblingBooks:d==null?void 0:d.siblingBooks,onLinkEntity:De,onUnlinkEntity:Me,onViewEntity:Oe,onCreateAndLink:Je,onSaveRelations:V}),l&&s&&i.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:[i.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:f.section.dangerZone}),i.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:f.editor.dangerZoneDesc}),i.jsx("button",{onClick:s,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:f.editor.deleteEntity})]}),i.jsx(Rl,{isOpen:g,entityType:x,title:_,onSelect:lt,onCancel:()=>b(!1),onCreate:()=>{b(!1),Je(k,x)},searchResults:S,onSearch:ot,isLoading:z,excludeId:e.id}),i.jsx(Ll,{isOpen:C,entityType:A,relationField:P,inheritData:N,onConfirm:yt,onCancel:()=>E(!1)}),i.jsx(Bl,{isOpen:D,title:f.action.selectBookOrWork,filterType:"all",recentEntities:Z,excludeId:e.id,onSelect:ue,onCancel:()=>{U(!1),q(null)},onSearch:ie})]})};function Ug({items:e,onChange:t}){const n=G(),r=(s,a,c)=>{const u=e.map((p,d)=>d===s?{...p,[a]:c}:p);t(u)},o=s=>t(e.filter((a,c)=>c!==s)),l=()=>t([...e,{book_title:""}]);return i.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((s,a)=>i.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[i.jsx(Ie,{label:n.editor.bookNameLabel,value:s.book_title,onChange:c=>r(a,"book_title",c)}),i.jsx("div",{style:{width:"100px"},children:i.jsx(Ie,{label:n.label.juanCount,value:s.n_juan!=null?String(s.n_juan):"",onChange:c=>r(a,"n_juan",c&&parseInt(c,10)||void 0)})}),i.jsx("button",{onClick:()=>o(a),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},a)),i.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:n.action.addAdditionalWork})]})}function Fl({items:e,onChange:t,showMeta:n,addLabel:r}){const o=G(),[l,s]=v.useState(null),a=(p,d,h)=>{const f=e.map((g,b)=>b===p?{...g,[d]:h||void 0}:g);t(f)},c=p=>{t(e.filter((d,h)=>h!==p)),l===p&&s(null)},u=()=>{t([...e,{source:""}]),s(e.length)};return i.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((p,d)=>{const h=l===d;return i.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:h?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>s(h?null:d),children:[i.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:h?"rotate(90deg)":"none"},children:"▶"}),i.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:p.source||o.editor.unnamedSource}),p.source_bid&&i.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:p.source_bid}),i.jsx("button",{onClick:f=>{f.stopPropagation(),c(d)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid #ddd",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"#999"},children:"✕"})]}),!h&&n&&(p.title_info||p.author_info)&&i.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[p.title_info,p.title_info&&p.author_info&&" — ",p.author_info]}),h&&i.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[i.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[i.jsx(Ie,{label:o.label.sourceName,value:p.source,onChange:f=>a(d,"source",f)}),i.jsx(Ie,{label:o.label.sourceBid,value:p.source_bid||"",onChange:f=>a(d,"source_bid",f)})]}),n&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[i.jsx(Ie,{label:o.label.titleInfo,value:p.title_info||"",onChange:f=>a(d,"title_info",f)}),i.jsx(Ie,{label:o.label.authorInfo,value:p.author_info||"",onChange:f=>a(d,"author_info",f)})]}),i.jsx(Ie,{label:o.label.edition,value:p.edition||"",onChange:f=>a(d,"edition",f)})]}),i.jsx(tt,{value:p.summary||"",onChange:f=>a(d,"summary",f),placeholder:o.editor.summaryPlaceholder}),i.jsx(tt,{value:p.comment||"",onChange:f=>a(d,"comment",f),placeholder:o.editor.commentPlaceholder}),i.jsx(tt,{value:p.additional_comment||"",onChange:f=>a(d,"additional_comment",f),placeholder:o.editor.additionalCommentPlaceholder})]})]},d)}),i.jsx("button",{onClick:u,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:r})]})}function Vg({items:e,onChange:t}){const n=G();return i.jsx(Fl,{items:e,onChange:t,showMeta:!0,addLabel:n.action.addIndexedBy})}function qg({items:e,onChange:t}){const n=G();return i.jsx(Fl,{items:e,onChange:t,addLabel:n.action.addEmendatedBy})}function Dl(e){var a,c,u,p,d,h,f;const t=((c=(a=e.authors)==null?void 0:a[0])==null?void 0:c.name)||"",n=((u=e.publication_info)==null?void 0:u.year)||"",r=((p=e.current_location)==null?void 0:p.name)||"",o=(d=e.page_count)!=null&&d.number?String(e.page_count.number):((h=e.page_count)==null?void 0:h.description)||"",l=typeof e.description=="object"&&e.description!==null&&e.description.text||"",s={id:e.id,title:e.title,type:e.type,author:t,dynasty:n,holder:r,pages:o,description:l,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};if(e.type==="work"){const g=e;if(Array.isArray(g.related_works)){const b=g.related_works.find(x=>x.relation==="part_of");b&&(s.parentWorkId=b.id,s.parentWorkName=b.title)}}if(e.type==="book"){const g=e;s.workId=g.work_id,Array.isArray(g.contained_in)&&g.contained_in.length>0&&(s.collectionId=(f=g.contained_in[0])==null?void 0:f.id)}return s}function Yg(e){const t={id:e.id,title:e.title,type:e.type,description:e.description?{text:e.description}:void 0,authors:e.author?[{name:e.author}]:void 0,publication_info:e.dynasty?{year:e.dynasty}:void 0,current_location:e.holder?{name:e.holder}:void 0,page_count:e.pages?{number:parseInt(e.pages)||0,description:e.pages}:void 0,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};return e.type==="work"&&e.parentWorkId&&(t.related_works=[{id:e.parentWorkId,title:e.parentWorkName||"",relation:"part_of"}]),e.type==="book"&&(t.work_id=e.workId,e.collectionId&&(t.contained_in=[{id:e.collectionId}])),t}const Gg=e=>{const{data:t,id:n,transport:r,mode:o="view",onModeChange:l,onChange:s,onSave:a,onDelete:c,onNavigate:u,renderLink:p,onAskAI:d,renderSectionActions:h,onDownloadResource:f,downloadStatuses:g,relations:b,onRelationsChange:x,headerExtra:m,className:k,style:w}=e;G();const[_,I]=v.useState(o),S=l?o:_;v.useEffect(()=>{o!==_&&I(o)},[o]);const T=v.useCallback(()=>{const P=S==="view"?"edit":"view";l?l(P):I(P)},[S,l]),[z,B]=v.useState(null);v.useEffect(()=>{n&&r&&r.getItem(n).then(P=>{P&&B(P)})},[n,r]);const C=t||z,E=v.useMemo(()=>C?Dl(C):null,[C]),A=l||!t?i.jsx("button",{onClick:T,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:S==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:S==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:S==="view"?"切换到编辑模式":"切换到查看模式",children:S==="view"?"✏️ 编辑":"👁 查看"}):null,$=i.jsxs(i.Fragment,{children:[A,m]});return!C&&!E?i.jsx(it,{}):S==="view"?i.jsx(br,{data:C,transport:r,onNavigate:u?P=>u(P):void 0,renderLink:p,headerExtra:$,className:k,style:w}):E?i.jsxs("div",{className:k,style:w,children:[$&&i.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:$}),i.jsx(Pl,{data:E,onChange:s||(()=>{}),onSave:a||(()=>{}),transport:r,onNavigate:u,showDelete:!!c,onDelete:c,onAskAI:d,renderSectionActions:h,onDownloadResource:f,downloadStatuses:g,relations:b,onRelationsChange:x})]}):i.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},Wi=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Ml=({isOpen:e,onClose:t,onSubmit:n,feedbackListUrl:r})=>{const[o,l]=v.useState(null),[s,a]=v.useState(""),[c,u]=v.useState("idle"),[p,d]=v.useState(""),h=v.useRef(null);v.useEffect(()=>{e&&(l(null),a(""),u("idle"),d(""))},[e]),v.useEffect(()=>{o&&setTimeout(()=>{var x;return(x=h.current)==null?void 0:x.focus()},100)},[o]),v.useEffect(()=>{if(c==="success"){const x=setTimeout(t,2e3);return()=>clearTimeout(x)}},[c,t]),v.useEffect(()=>{if(!e)return;const x=m=>{m.key==="Escape"&&t()};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[e,t]);const f=async()=>{if(!(!o||!s.trim())){u("submitting"),d("");try{await n({type:o,content:s.trim()}),u("success")}catch(x){u("error"),d(x instanceof Error?x.message:"提交失败,请稍后重试")}}};if(!e)return null;const g=o&&s.trim()&&c!=="submitting",b=Wi.find(x=>x.value===o);return i.jsx("div",{style:Kg,onClick:x=>{x.target===x.currentTarget&&t()},children:i.jsxs("div",{style:Xg,onClick:x=>x.stopPropagation(),children:[i.jsxs("div",{style:Jg,children:[i.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),i.jsx("button",{onClick:t,style:Zg,"aria-label":"关闭",children:"✕"})]}),c==="success"?i.jsxs("div",{style:rx,children:[i.jsx("span",{style:{fontSize:"32px"},children:"✓"}),i.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&i.jsx("a",{href:r,style:{fontSize:"13px",color:"var(--bim-primary, #2563eb)",marginTop:"8px"},children:"查看反馈列表 →"})]}):i.jsxs(i.Fragment,{children:[i.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:Wi.map(x=>i.jsxs("button",{onClick:()=>l(x.value),style:{...Qg,...o===x.value?ex:{}},children:[i.jsx("span",{children:x.icon})," ",x.label]},x.value))}),i.jsx("textarea",{ref:h,value:s,onChange:x=>a(x.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!o||c==="submitting",style:{...tx,opacity:o?1:.6}}),i.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[s.length," / 2000"]}),c==="error"&&i.jsx("div",{style:ix,children:p}),i.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:i.jsx("button",{onClick:f,disabled:!g,style:{...nx,opacity:g?1:.6,cursor:g?"pointer":"not-allowed"},children:c==="submitting"?"提交中...":"提交反馈"})})]})]})})},Kg={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},Xg={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)"},Jg={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Zg={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},Qg={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"},ex={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},tx={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"},nx={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},rx={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},ix={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},ox=({onSubmit:e,position:t={bottom:24,right:24},feedbackListUrl:n})=>{const[r,o]=v.useState(!1);return i.jsxs(i.Fragment,{children:[i.jsx("button",{onClick:()=>o(!0),style:{...lx,bottom:t.bottom,right:t.right},"aria-label":"反馈",title:"反馈",children:i.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:i.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"})})}),i.jsx(Ml,{isOpen:r,onClose:()=>o(!1),onSubmit:e,feedbackListUrl:n})]})},lx={position:"fixed",zIndex:900,width:"48px",height:"48px",borderRadius:"50%",border:"none",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 2px 8px rgba(0,0,0,0.25)",transition:"transform 0.2s, box-shadow 0.2s"},$i=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],sx=({onSubmit:e})=>{const[t,n]=v.useState("bug"),[r,o]=v.useState(""),[l,s]=v.useState("idle"),[a,c]=v.useState(""),u=v.useRef(null);v.useEffect(()=>{t&&setTimeout(()=>{var f;return(f=u.current)==null?void 0:f.focus()},100)},[t]);const p=async()=>{if(!(!t||!r.trim())){s("submitting"),c("");try{await e({type:t,content:r.trim()}),s("success"),o(""),n("bug")}catch(f){s("error"),c(f instanceof Error?f.message:"提交失败,请稍后重试")}}},d=t&&r.trim()&&l!=="submitting",h=$i.find(f=>f.value===t);return l==="success"?i.jsx("div",{style:Ni,children:i.jsxs("div",{style:px,children:[i.jsx("span",{children:"✓ 感谢您的反馈!"}),i.jsx("button",{onClick:()=>s("idle"),style:fx,children:"继续提交"})]})}):i.jsxs("div",{style:Ni,children:[i.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:$i.map(f=>i.jsxs("button",{onClick:()=>n(f.value),style:{...ax,...t===f.value?cx:{}},children:[i.jsx("span",{children:f.icon})," ",f.label]},f.value))}),i.jsx("textarea",{ref:u,value:r,onChange:f=>o(f.target.value),placeholder:(h==null?void 0:h.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:l==="submitting",style:{...ux}}),i.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[i.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[r.length," / 2000"]}),i.jsx("button",{onClick:p,disabled:!d,style:{...dx,opacity:d?1:.6,cursor:d?"pointer":"not-allowed"},children:l==="submitting"?"提交中...":"提交"})]}),l==="error"&&i.jsx("div",{style:hx,children:a})]})},Ni={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},ax={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},cx={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},ux={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},dx={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},px={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},fx={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},hx={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"};function gx(e){var t;return{id:e.id,kind:"hypothetical",label:e.label,year:e.year??((t=e.year_range)==null?void 0:t[0]),year_range:e.year_range,year_uncertain:e.year_uncertain,group:e.group,note:e.note,description:e.description}}function xx(e,t){if(!e.lineage)return null;const n=e.lineage;return{id:e.id,kind:"book",label:e.title,year:n.year,year_text:n.year_text,year_uncertain:n.year_uncertain,category:n.category,status:n.status,extant_juan:n.extant_juan,group:t[e.id],note:n.note}}function Hi(e,t,n){return{id:`derive:${t.ref}->${e}:${n}`,source:t.ref,target:e,kind:"derive",relation:t.relation,confidence:t.confidence,evidence:t.evidence,note:t.note}}function mx(e,t,n){const[r,o]=[e,t.book_id].sort();return{id:`sibling:${r}-${o}:${n}`,source:r,target:o,kind:"sibling",relation:t.relation,confidence:t.confidence,evidence:t.evidence,note:t.note}}function bx(e,t){var u;if(t==="all")return null;const n=(u=e.collections)==null?void 0:u[t],r=Array.isArray(n==null?void 0:n.groups)&&n.groups.length>0,o=Array.isArray(n==null?void 0:n.book_ids)&&n.book_ids.length>0,l=r||o||!!(n!=null&&n.hypothetical_ids);if(!l&&t==="core"&&Array.isArray(e.core_books)&&e.core_books.length>0)return{books:new Set(e.core_books),hypos:e.core_hypotheticals?new Set(e.core_hypotheticals):null};if(!n||!l)return null;const s=r?new Set(n.groups):null,a=new Set(n.book_ids??[]);if(s&&e.node_groups)for(const[p,d]of Object.entries(e.node_groups))s.has(d)&&a.add(p);let c=null;if(n.hypothetical_ids&&(c=new Set(n.hypothetical_ids)),s){c||(c=new Set);for(const p of e.hypothetical_nodes??[])p.group&&s.has(p.group)&&c.add(p.id)}return{books:a,hypos:c}}function yx(e,t,n){const r=e.version_graph,o={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return o;const l=new Set(r.excluded_books??[]),s=r.node_groups??{},a=bx(r,n??r.default_collection??"all"),c=a!==null,u=(a==null?void 0:a.books)??null,p=(a==null?void 0:a.hypos)??null,d=new Set,h=new Set;if(c){const _=new Map(t.map(C=>[C.id,C])),I=new Map((r.hypothetical_nodes??[]).map(C=>[C.id,C])),S=C=>{const E=_.get(C);if(E&&E.lineage)return(E.lineage.derived_from??[]).map($=>$.ref);const A=I.get(C);return A?(A.derived_from??[]).map($=>$.ref):[]},T=C=>I.has(C)?!p||p.has(C):!u||u.has(C),z=new Set,B=C=>{if(!z.has(C)){z.add(C);for(const E of S(C))l.has(E)||(T(E)||(I.has(E)?h.add(E):_.has(E)&&d.add(E)),B(E))}};for(const C of t)u&&u.has(C.id)&&!l.has(C.id)&&B(C.id);for(const C of r.hypothetical_nodes??[])p&&p.has(C.id)&&B(C.id)}const f=t.filter(_=>!l.has(_.id)).filter(_=>!u||u.has(_.id)||d.has(_.id)).map(_=>{const I=xx(_,s);return I&&d.has(_.id)&&(I.bridge=!0),I}).filter(_=>_!==null),g=(r.hypothetical_nodes??[]).filter(_=>!p||p.has(_.id)||h.has(_.id)).map(_=>{const I=gx(_);return h.has(_.id)&&(I.bridge=!0),I}),b=[...f,...g],x=new Set(b.map(_=>_.id)),m=new Set,k=[],w=_=>{m.has(_.id)||!x.has(_.source)||!x.has(_.target)||(m.add(_.id),k.push(_))};for(const _ of t)l.has(_.id)||!_.lineage||u&&!u.has(_.id)&&!d.has(_.id)||((_.lineage.derived_from??[]).forEach((I,S)=>{w(Hi(_.id,I,S))}),(_.lineage.related_to??[]).forEach((I,S)=>{w(mx(_.id,I,S))}));for(const _ of r.hypothetical_nodes??[])p&&!p.has(_.id)&&!h.has(_.id)||(_.derived_from??[]).forEach((I,S)=>{w(Hi(_.id,I,S))});return{nodes:b,edges:k,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(l)}}function Ol(e,t,n){const r=(e??(t!=null?String(t):"")).trim();return r?!n||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function kx(e,t){const n=[],r=e.version_graph;if(!r)return n;const o=new Set(t.map(c=>c.id)),l=new Set((r.hypothetical_nodes??[]).map(c=>c.id)),s=new Set([...o,...l]),a=(c,u)=>{s.has(u.ref)||n.push(`${c}: derived_from.ref "${u.ref}" 未在 books 或 hypothetical_nodes 中找到`),u.ref_type==="book"&&!o.has(u.ref)&&n.push(`${c}: derived_from.ref "${u.ref}" 标记为 book 但不在 books 列表中`),u.ref_type==="hypothetical"&&!l.has(u.ref)&&n.push(`${c}: derived_from.ref "${u.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const c of t){if(!c.lineage)continue;const u=`Book ${c.id} (${c.title})`;(c.lineage.derived_from??[]).forEach(p=>a(u,p)),(c.lineage.related_to??[]).forEach(p=>{o.has(p.book_id)||n.push(`${u}: related_to.book_id "${p.book_id}" 不在 books 列表中`)})}for(const c of r.hypothetical_nodes??[]){const u=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(p=>a(u,p))}return n}const Wl=({graph:e,renderLink:t,className:n,style:r})=>{const{convert:o}=X();if(!e.nodes.length)return i.jsx("div",{style:{...Bx,...r},className:n,children:"暂无版本图数据"});const l=new Map,s=new Map;for(const h of e.edges)if(h.kind==="derive"){const f=l.get(h.target)??[];f.push(h),l.set(h.target,f)}else for(const f of[h.source,h.target]){const g=s.get(f)??[];g.push(h),s.set(f,g)}const a=new Map(e.nodes.map(h=>[h.id,h])),c=new Map,u=[];for(const h of e.nodes)if(h.group){const f=c.get(h.group)??[];f.push(h),c.set(h.group,f)}else u.push(h);const p=(h,f)=>(h.year??9999)-(f.year??9999);c.forEach(h=>h.sort(p)),u.sort(p);const d=e.groups.filter(h=>c.has(h.id));return i.jsxs("div",{className:n,style:{...Sx,...r},children:[e.title&&i.jsx("div",{style:wx,children:o(e.title)}),e.description&&i.jsx("div",{style:jx,children:o(e.description)}),d.map(h=>i.jsx(Ui,{label:h.label,color:h.color,nodes:c.get(h.id),incomingMap:l,siblingMap:s,nodeMap:a,renderLink:t},h.id)),u.length>0&&i.jsx(Ui,{label:"其他",nodes:u,incomingMap:l,siblingMap:s,nodeMap:a,renderLink:t})]})},Ui=({label:e,color:t,nodes:n,incomingMap:r,siblingMap:o,nodeMap:l,renderLink:s})=>{const{convert:a}=X();return i.jsxs("div",{style:Cx,children:[i.jsx("div",{style:{...Ix,borderLeftColor:t??"var(--bim-widget-border, #ddd)"},children:a(e)}),n.map(c=>i.jsx(vx,{node:c,incoming:r.get(c.id)??[],siblings:o.get(c.id)??[],nodeMap:l,renderLink:s},c.id))]})},vx=({node:e,incoming:t,siblings:n,nodeMap:r,renderLink:o})=>{const l=e.kind==="hypothetical",s=e.bridge,{convert:a}=X();return i.jsxs("div",{style:{...Ex,borderStyle:l||s?"dashed":"solid",opacity:s?.55:e.status==="lost"?.7:1,background:s?"var(--bim-bg-subtle, #fafafa)":void 0},title:s?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[i.jsxs("div",{style:Tx,children:[i.jsx("span",{style:_x,children:l||!o?a(e.label):o(e.id,a(e.label))}),(e.year_text||e.year!=null)&&i.jsx("span",{style:zx,children:Ol(a(e.year_text),e.year,e.year_uncertain)})]}),i.jsxs("div",{style:Rx,children:[e.category&&i.jsx(Rt,{children:a(e.category)}),e.status==="lost"&&i.jsx(Rt,{tone:"warn",children:"已佚"}),e.status==="fragment"&&i.jsx(Rt,{tone:"warn",children:"残本"}),l&&i.jsx(Rt,{tone:"info",children:"假想祖本"}),s&&i.jsx(Rt,{tone:"info",children:"桥接"})]}),e.extant_juan&&i.jsxs("div",{style:Lx,children:["现存:",a(e.extant_juan)]}),e.note&&i.jsx("div",{style:Ax,children:a(e.note)}),t.length>0&&i.jsxs("div",{style:qi,children:[i.jsx("div",{style:Yi,children:"来源:"}),t.map(c=>{const u=r.get(c.source);return i.jsxs("div",{style:Gi(c.confidence),children:[i.jsx("span",{style:Ki,children:a(c.relation)}),i.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&o?o(u.id,a(u.label)):a((u==null?void 0:u.label)??c.source)}),c.confidence!=="consensus"&&c.confidence!=="certain"&&i.jsx(Vi,{level:c.confidence}),c.evidence&&i.jsxs("span",{style:Xi,children:["· ",a(c.evidence)]})]},c.id)})]}),n.length>0&&i.jsxs("div",{style:qi,children:[i.jsx("div",{style:Yi,children:"关联:"}),n.map(c=>{const u=c.source===e.id?c.target:c.source,p=r.get(u);return i.jsxs("div",{style:Gi(c.confidence),children:[i.jsx("span",{style:Ki,children:a(c.relation)}),i.jsx("span",{children:(p==null?void 0:p.kind)==="book"&&o?o(p.id,a(p.label)):a((p==null?void 0:p.label)??u)}),i.jsx(Vi,{level:c.confidence}),c.evidence&&i.jsxs("span",{style:Xi,children:["· ",a(c.evidence)]})]},c.id)})]})]})},Rt=({children:e,tone:t="default"})=>{const r={default:{bg:"var(--bim-tag-bg, #f0f0f0)",fg:"var(--bim-fg, #555)"},warn:{bg:"var(--bim-warn-bg, #fff3cd)",fg:"var(--bim-warn-fg, #856404)"},info:{bg:"var(--bim-info-bg, #e7f3ff)",fg:"var(--bim-info-fg, #0c5380)"}}[t];return i.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:e})},Vi=({level:e})=>{const n={certain:{label:"确定",color:"#2e7d32"},consensus:{label:"共识",color:"#1976d2"},probable:{label:"推测",color:"#ed6c02"},disputed:{label:"有争议",color:"#c62828"}}[e];return n?i.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${n.color}`,color:n.color,borderRadius:"8px",marginLeft:"4px"},children:n.label}):null},Sx={fontSize:"14px",color:"var(--bim-fg, #333)"},wx={fontSize:"16px",fontWeight:600,marginBottom:"8px"},jx={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},Cx={marginBottom:"16px"},Ix={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:"var(--bim-fg, #333)"},Ex={border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:"var(--bim-bg, #fff)"},Tx={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},_x={fontSize:"15px",fontWeight:600},zx={fontSize:"12px",color:"var(--bim-muted, #777)"},Rx={marginBottom:"6px"},Lx={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},Ax={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},qi={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},Yi={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},Gi=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),Ki={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},Xi={fontSize:"11px",color:"var(--bim-muted, #888)"},Bx={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},$l=({selectedNodeId:e,...t})=>{const[n,r]=v.useState("loading"),[o,l]=v.useState(null);return v.useEffect(()=>{let s=!1;return Px().then(a=>{s||(a?(l(a),r("ready")):r("missing"))}),()=>{s=!0}},[]),n==="loading"?i.jsx("div",{style:Ji,children:"加载图组件中…"}):n==="missing"||!o?i.jsxs("div",{style:Ji,children:[i.jsxs("div",{children:["图组件未安装。请安装 ",i.jsx("code",{children:"@xyflow/react"})," 与 ",i.jsx("code",{children:"@dagrejs/dagre"}),"。"]}),i.jsxs("div",{style:{fontSize:"12px",marginTop:"4px"},children:["或使用 ",i.jsx("code",{children:"VersionLineageList"})," 列表视图。"]})]}):i.jsx(Fx,{modules:o,selectedNodeId:e,...t})};async function Px(){try{const[e,t]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let n=!1;try{await import("@xyflow/react/dist/style.css"),n=!0}catch{n=!1}return{ReactFlow:e.ReactFlow,Background:e.Background,Controls:e.Controls,Handle:e.Handle,Position:e.Position,BaseEdge:e.BaseEdge,EdgeLabelRenderer:e.EdgeLabelRenderer,getSmoothStepPath:e.getSmoothStepPath,dagre:t,cssLoaded:n}}catch{return null}}const Fx=({graph:e,renderLink:t,height:n=600,className:r,style:o,selectedNodeId:l,modules:s})=>{const{ReactFlow:a,Background:c,Controls:u,Handle:p,Position:d,BaseEdge:h,EdgeLabelRenderer:f,getSmoothStepPath:g,dagre:b}=s,x=v.useMemo(()=>({lineage:S=>{var N,M,D,U;const T=((N=S.data)==null?void 0:N.stepPosition)??.85,[z,B,C]=g({sourceX:S.sourceX,sourceY:S.sourceY,sourcePosition:S.sourcePosition,targetX:S.targetX,targetY:S.targetY,targetPosition:S.targetPosition,stepPosition:T,borderRadius:5}),E=!!((M=S.data)!=null&&M.isSibling),A=E?B:S.targetX-18,$=E?C:S.targetY-12,P=(D=S.data)==null?void 0:D.labelStyle,L=(U=S.data)==null?void 0:U.labelBgStyle;return i.jsxs(i.Fragment,{children:[i.jsx(h,{id:S.id,path:z,style:S.style,markerStart:S.markerStart,markerEnd:S.markerEnd}),S.label&&i.jsx(f,{children:i.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${A}px,${$}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:"var(--bim-bg, #fff)",border:"0.5px solid var(--bim-widget-border, #ddd)",...L,...P},children:S.label})})]})}}),[h,f,g]),m=v.useMemo(()=>({version:S=>{const T=S.data,z=T.kind==="hypothetical",B=T.status==="lost",C=T.isSelected,E=T.bridge,A=T.borderColor??"#888",$=E||z?"dashed":"solid",P=E?.5:B?.6:1;return i.jsxs("div",{style:{background:E?"var(--bim-bg-subtle, #fafafa)":"var(--bim-bg, #fff)",border:`2px ${$} ${C?"#0078d4":A}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:P,boxShadow:C?"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)":z||E?"none":"0 1px 3px rgba(0,0,0,0.1)"},title:E?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[i.jsx(p,{type:"target",position:d.Left,style:{visibility:"hidden"}}),i.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:z||!T.renderLink?T.label:T.renderLink(T.bookId,T.label)}),T.description&&i.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.25,marginTop:1},children:T.description}),T.yearText&&i.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.2},children:Ol(T.yearText,void 0,T.uncertain)}),B&&i.jsx("div",{style:{fontSize:9,color:"#c62828",marginTop:1},children:"已佚"}),i.jsx(p,{type:"source",position:d.Right,style:{visibility:"hidden"}})]})}}),[p,d]),{convert:k}=X(),{rfNodes:w,rfEdges:_}=v.useMemo(()=>Dx(e,b,t,l,k),[e,b,t,l,k]);return i.jsx("div",{style:{width:"100%",height:n,...o},className:r,children:i.jsxs(a,{nodes:w,edges:_,nodeTypes:m,edgeTypes:x,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[i.jsx(c,{gap:16}),i.jsx(u,{showInteractive:!1})]})})};function Dx(e,t,n,r,o=l=>l??""){const a=e.layout==="LR"||!e.layout,c=new t.graphlib.Graph;c.setGraph({rankdir:a?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),c.setDefaultEdgeLabel(()=>({}));const u=new Map(e.groups.map(m=>[m.id,m.color??"#888"]));for(const m of e.nodes)c.setNode(m.id,{width:160,height:90});const p=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const m of e.edges)m.kind==="derive"&&(p.has(m.relation)||c.setEdge(m.source,m.target));t.layout(c);const d=e.nodes.map(m=>{const k=c.node(m.id),w=r&&m.id===r,_={kind:m.kind,label:o(m.label),bookId:m.kind==="book"?m.id:void 0,yearText:o(m.year_text??Ox(m)),uncertain:m.year_uncertain,category:m.category,status:m.status,borderColor:m.group?u.get(m.group):void 0,renderLink:n,isSelected:w,description:o(m.description),bridge:m.bridge};return{id:m.id,type:"version",position:{x:k.x-160/2,y:k.y-90/2},data:_,draggable:!1,selected:w}}),h=.78,f=.06,g=new Map;for(const m of e.edges)m.kind==="derive"&&(g.has(m.source)||g.set(m.source,[]),g.get(m.source).push(m));const b=new Map;for(const[m,k]of g){if(k.length<=1)continue;const w=[...k].sort((I,S)=>{var B,C;const T=((B=c.node(I.target))==null?void 0:B.y)??0,z=((C=c.node(S.target))==null?void 0:C.y)??0;return T-z}),_=w.length;w.forEach((I,S)=>{const T=(S-(_-1)/2)*f;b.set(I.id,h+T)})}const x=e.edges.map(m=>Mx(m,b.get(m.id),o));return{rfNodes:d,rfEdges:x}}function Mx(e,t,n=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",o=e.kind==="sibling",l=Wx(e.confidence),s={type:"arrowclosed",color:l,width:14,height:14};return{id:e.id,source:e.source,target:e.target,type:"lineage",label:n(e.relation),data:{labelStyle:{color:"#444"},isSibling:o,stepPosition:t},style:{stroke:l,strokeWidth:o?1:1.5,strokeDasharray:o?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:s,markerStart:o?s:void 0,zIndex:1e3}}function Ox(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Wx(e){switch(e){case"certain":return"#2e7d32";case"consensus":return"#555";case"probable":return"#ed6c02";case"disputed":return"#c62828";default:return"#888"}}const Ji={padding:"40px 20px",textAlign:"center",color:"var(--bim-muted, #888)",fontSize:"13px",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:8,background:"var(--bim-bg, #fafafa)"},$x=({graph:e,defaultMode:t="list",renderLink:n,graphHeight:r=600,selectedNodeId:o,onModeChange:l,collection:s,onCollectionChange:a,collectionsAvailable:c,collectionCounts:u,className:p,style:d})=>{var k;const[h,f]=v.useState(t),g=w=>{f(w),l==null||l(w)},b=(()=>{if(!c)return[];const w=Object.entries(c);return w.length===0||c.all?w:[...w,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),x=!!(a&&b.length>0);if(!e.nodes.length)return i.jsx("div",{style:{padding:24,color:"var(--bim-muted, #999)",textAlign:"center"},children:"暂无版本传承数据"});const m=s?(k=c==null?void 0:c[s])==null?void 0:k.description:void 0;return i.jsxs("div",{className:p,style:d,children:[i.jsxs("div",{style:Nx,children:[i.jsx("button",{onClick:()=>g("list"),style:Fn(h==="list"),children:"列表"}),i.jsx("button",{onClick:()=>g("graph"),style:Fn(h==="graph"),children:"关系图"}),x&&i.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[i.jsx("span",{style:{fontSize:12,color:"var(--bim-muted, #888)",marginRight:4},children:"集合:"}),b.map(([w,_])=>{const I=u==null?void 0:u[w];return i.jsxs("button",{onClick:()=>a==null?void 0:a(w),style:Fn(s===w),title:_.description,children:[_.label,I!=null?` ${I}`:""]},w)})]})]}),x&&m&&i.jsx("div",{style:{fontSize:12,color:"var(--bim-muted, #888)",marginBottom:8,padding:"4px 8px",background:"var(--bim-bg-subtle, #fafafa)",borderRadius:4},children:m}),h==="list"?i.jsx(Wl,{graph:e,renderLink:n}):i.jsx($l,{graph:e,renderLink:n,height:r,selectedNodeId:o})]})},Nx={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Fn=e=>({padding:"4px 12px",fontSize:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:4,background:e?"var(--bim-primary, #0078d4)":"transparent",color:e?"var(--bim-primary-fg, #fff)":"var(--bim-fg, #333)",cursor:"pointer"}),Hx=({style:e})=>{const t=v.useContext($t);if(!t)return null;const{locale:n,setLocale:r}=t,o=n==="zh-Hant",l=()=>r(o?"zh-Hans":"zh-Hant");return i.jsxs("button",{type:"button",onClick:l,title:o?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:"1px solid var(--bim-border, #ddd)",borderRadius:"4px",background:"var(--bim-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",userSelect:"none",...e},children:[i.jsx("span",{style:{color:o?"var(--bim-primary, #0078d4)":void 0,fontWeight:o?700:400},children:"繁"}),i.jsx("span",{style:{opacity:.3},children:"/"}),i.jsx("span",{style:{color:o?void 0:"var(--bim-primary, #0078d4)",fontWeight:o?400:700},children:"简"})]})};exports.BidLink=ne.BidLink;exports.BookIndexError=ne.BookIndexError;exports.BookIndexManager=ne.BookIndexManager;exports.BookIndexStorage=ne.BookIndexStorage;exports.BundleStorage=ne.BundleStorage;exports.ConfigError=ne.ConfigError;exports.GithubStorage=ne.GithubStorage;exports.IdGenerationError=ne.IdGenerationError;exports.IdGenerator=ne.IdGenerator;exports.LocalStorage=ne.LocalStorage;exports.MigrationError=ne.MigrationError;exports.StorageError=ne.StorageError;exports.base36Decode=ne.base36Decode;exports.base36Encode=ne.base36Encode;exports.base58Decode=ne.base58Decode;exports.buildId=ne.buildId;exports.cleanName=ne.cleanName;exports.decodeId=ne.decodeId;exports.decodeIdString=ne.decodeIdString;exports.encodeId=ne.encodeId;exports.extractIdFromUrl=ne.extractIdFromUrl;exports.extractStatus=ne.extractStatus;exports.extractType=ne.extractType;exports.normalizeCatalog=ne.normalizeCatalog;exports.parseId=ne.parseId;exports.shardOf=ne.shardOf;exports.smartDecode=ne.smartDecode;exports.validateResource=ne.validateResource;exports.Badge=an;exports.BidUrlProvider=Xl;exports.CollatedEdition=jl;exports.CollectionCatalog=ml;exports.CreateEntityDialog=Ll;exports.EmendatedBySection=gl;exports.EntityDetail=io;exports.EntityPickerDialog=Bl;exports.EntitySelector=Rl;exports.FeedbackButton=ox;exports.FeedbackDialog=Ml;exports.FeedbackForm=sx;exports.FeedbackList=Cl;exports.FormInput=Ie;exports.FormTextArea=tt;exports.HomePage=Jn;exports.IndexApp=pg;exports.IndexBrowser=Mn;exports.IndexDetail=br;exports.IndexEditor=Pl;exports.IndexView=Gg;exports.LocaleContext=$t;exports.LocaleProvider=os;exports.LocaleToggle=Hx;exports.ModeIndicator=no;exports.RelationPanel=_l;exports.ResourceEditor=Dn;exports.ResourceList=Qn;exports.SearchInput=ro;exports.Section=Ae;exports.SmartBidInput=tn;exports.SourceEditor=Il;exports.VersionLineageGraph=$l;exports.VersionLineageList=Wl;exports.VersionLineageView=$x;exports.WorkCatalog=fg;exports.buildLineageGraph=yx;exports.detailToEditor=Dl;exports.editorToDetail=Yg;exports.formatTemplate=Nt;exports.parseSourceString=El;exports.stringifySources=Tl;exports.useBidUrl=Fe;exports.useConvert=X;exports.useT=G;exports.validateLineageGraph=kx;
1
+ "use strict";var Fn=Object.create;var ut=Object.defineProperty;var Hn=Object.getOwnPropertyDescriptor;var On=Object.getOwnPropertyNames;var Dn=Object.getPrototypeOf,Vn=Object.prototype.hasOwnProperty;var Un=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of On(n))!Vn.call(t,s)&&s!==o&&ut(t,s,{get:()=>n[s],enumerable:!(r=Hn(n,s))||r.enumerable});return t};var Ce=(t,n,o)=>(o=t!=null?Fn(Dn(t)):{},Un(n||!t||!t.__esModule?ut(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./storage-entry-C7sHSk4U.cjs"),e=require("react/jsx-runtime"),f=require("react"),Nn=require("react-markdown"),Gn=require("remark-gfm"),Yn=require("react-dom"),Kn=t=>`/book-index?id=${t}`,en=f.createContext(Kn);function Jn({buildUrl:t,children:n}){const o=f.useMemo(()=>t,[t]);return e.jsx(en.Provider,{value:o,children:n})}function ae(){return f.useContext(en)}function be(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function qn(t,n){return be(t).includes(n)}const tn={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Xn={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},Zn={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},Pe=f.createContext(null),nn={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入",belongsToWork:"所屬作品",locationHistory:"流轉歷史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄於",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"目錄",collectionTab:"叢編",siteTab:"在線資源",recommendTab:"推薦",feedbackTab:"反饋",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},detailTab:{basicInfo:"基本信息",catalog:"目錄",collectionCatalog:"叢編目錄",collatedEdition:"整理本",catalogSuffix:"·目錄"},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",total_pages:"總頁數",page_range:"頁碼範圍",page_count:"頁數",file_page_range:"文件頁碼",file_page_count:"文件頁數",content_page_range:"影印頁碼",volume:"冊",color_mode:"色彩",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},Qn={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录于",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"目录",collectionTab:"丛编",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"基本信息",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"整理本",catalogSuffix:"·目录"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},eo={"zh-Hant":nn,"zh-Hans":Qn},on="bim-locale";function to(){try{const t=localStorage.getItem(on);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function no(t){try{localStorage.setItem(on,t)}catch{}}const oo="zh-Hans",ro=({locale:t,onLocaleChange:n,children:o})=>{const[r,s]=f.useState(t??oo),i=t??r;f.useEffect(()=>{if(t)return;const u=to();u&&u!==r&&s(u)},[]);const[a,c]=f.useState(null);f.useEffect(()=>{i==="zh-Hans"?import("opencc-js/t2cn").then(u=>{const x=u.Converter({from:"tw",to:"cn"});c(()=>x)}).catch(()=>{c(()=>u=>u)}):c(null)},[i]);const l=f.useCallback(u=>{s(u),no(u),n==null||n(u)},[n]),d=f.useMemo(()=>({locale:i,setLocale:l,messages:eo[i],converter:a}),[i,l,a]);return e.jsx(Pe.Provider,{value:d,children:o})};function A(){const t=f.useContext(Pe);return(t==null?void 0:t.messages)??nn}const io=2e3;function F(){const t=f.useContext(Pe),n=(t==null?void 0:t.locale)??"zh-Hant",o=(t==null?void 0:t.converter)??null,r=f.useRef(new Map),s=f.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const i=f.useCallback(a=>{if(!a)return"";if(!o)return a;const c=r.current.get(a);if(c!==void 0)return c;const l=o(a);if(r.current.size>=io){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(a,l),l},[o]);return f.useMemo(()=>({convert:i,locale:n,isSimplified:n==="zh-Hans"}),[i,n])}function Ae(t,n){return t.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function so(t){if(!t)return"";try{const n=new URL(t).hostname,o={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(o[n])return o[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function lo(){return{id:"",name:"",url:"",type:"text",details:""}}const nt=({items:t,onChange:n,onDownload:o,downloadStatuses:r,filterType:s})=>{const i=A(),[a,c]=f.useState(null),l=[{value:"text",label:i.resourceTypeShort.text},{value:"image",label:i.resourceTypeShort.image},{value:"text+image",label:i.resourceTypeShort.textImage},{value:"physical",label:i.resourceTypeShort.physical}],d=[{value:"catalog",label:i.rootType.catalog},{value:"search",label:i.rootType.search}],u=m=>{if(!s)return!0;const k=be(m);return s==="text"?k.includes("text"):s==="image"?k.includes("image")||k.includes("physical"):s==="physical"?k.includes("physical"):k.includes(s)},x=t.map((m,k)=>({item:m,originalIndex:k})).filter(({item:m})=>u(m)),g=()=>{const m=lo();s&&(m.type=s),n([...t,m]),c(t.length)},p=m=>{n(t.filter((k,_)=>_!==m)),c(null)},h=(m,k,_)=>{const v=[...t];if(v[m]={...v[m],[k]:_},k==="url"&&!v[m].id){const w=so(_);w&&(v[m].id=w)}n(v)},y=(m,k,_)=>{const w={...t[m].metadata||{}};_?w[k]=_:delete w[k],h(m,"metadata",Object.keys(w).length>0?w:void 0)},b=(m,k)=>{const _=k.trim()?k.split(/[,,、]/).map(v=>v.trim()).filter(Boolean):void 0;h(m,"structure",_)},j=(m,k,_)=>{const w=t[m].coverage||{level:1,ranges:""};k==="level"?w.level=parseInt(_)||1:w.ranges=_,h(m,"coverage",w.ranges?w:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:m,originalIndex:k})=>{var _,v,w;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>c(a===k?null:k),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:a===k?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:ao(m.type??"text"),color:"#fff"},children:(()=>{var z,E;const S=be(m);return S.length===0?m.type??"text":S.length===1?((z=l.find(I=>I.value===S[0]))==null?void 0:z.label)??S[0]:S.includes("text")&&S.includes("image")?((E=l.find(I=>I.value==="text+image"))==null?void 0:E.label)??"text+image":S.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.name||`${i.editor.resourcePlaceholder} ${k+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:S=>S.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&m.url&&co(k,r==null?void 0:r[k],o,i),e.jsx("button",{onClick:S=>{S.stopPropagation(),p(k)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:i.editor.deleteThisResource,children:"✕"})]}),a===k&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[qn(m,"image")&&m.url&&po(m,i),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:ze,children:[e.jsx("span",{style:Ie,children:i.label.type}),e.jsx("select",{value:m.type,onChange:S=>h(k,"type",S.target.value),style:{...pe,flex:1},children:l.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))})]}),e.jsxs("label",{style:ze,children:[e.jsx("span",{style:Ie,children:i.label.rootType}),e.jsx("select",{value:m.root_type||"catalog",onChange:S=>h(k,"root_type",S.target.value),style:{...pe,flex:1},children:d.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:m.id,onChange:S=>h(k,"id",S.target.value),placeholder:i.editor.idAutoExtract,style:{...pe,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:m.name,onChange:S=>h(k,"name",S.target.value),placeholder:i.editor.resourceName,style:{...pe,flex:1}})]}),e.jsx("input",{type:"text",value:m.url,onChange:S=>h(k,"url",S.target.value),placeholder:i.editor.resourceUrl,style:pe}),e.jsx("input",{type:"text",value:((_=m.structure)==null?void 0:_.join("、"))||"",onChange:S=>b(k,S.target.value),placeholder:i.editor.structurePlaceholder,style:pe}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:ze,children:[e.jsx("span",{style:Ie,children:i.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((v=m.coverage)==null?void 0:v.level)??"",onChange:S=>j(k,"level",S.target.value),placeholder:"1",style:{...pe,width:"60px"}})]}),e.jsxs("label",{style:{...ze,flex:1},children:[e.jsx("span",{style:Ie,children:i.label.coverageRange}),e.jsx("input",{type:"text",value:((w=m.coverage)==null?void 0:w.ranges)||"",onChange:S=>j(k,"ranges",S.target.value),placeholder:i.editor.coverageRangePlaceholder,style:{...pe,flex:1}})]})]}),e.jsx("textarea",{value:m.details||"",onChange:S=>h(k,"details",S.target.value),placeholder:i.editor.detailsPlaceholder,style:{...pe,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:i.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(i.metadata).map(([S,z])=>{var E;return e.jsxs("label",{style:{...ze,gap:"4px"},children:[e.jsx("span",{style:{...Ie,minWidth:"56px"},children:z}),e.jsx("input",{type:"text",value:((E=m.metadata)==null?void 0:E[S])||"",onChange:I=>y(k,S,I.target.value),placeholder:z,style:{...pe,flex:1}})]},S)})})]})]})]})]},k)}),e.jsxs("button",{onClick:g,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:i.action.addResource})]})]})};function ao(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function co(t,n,o,r){const s=(n==null?void 0:n.status)==="downloading",i=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:a=>{a.stopPropagation(),s||o(t,"")},disabled:s,style:{background:"transparent",border:"none",color:i?"var(--bim-success, #4caf50)":s?"var(--bim-desc-fg, #717171)":"var(--bim-link-fg, #0066cc)",cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:i?r.download.completed:s?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:i?"✓":s?"⏳":"⬇"})}function po(t,n){const o=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url)||t.url.includes("iiif")||t.url.includes("image");return e.jsx("div",{style:{marginBottom:"12px"},children:o?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"#00000010"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"#00000010",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const pe={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"},ze={display:"flex",alignItems:"center",gap:"6px"},Ie={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},xo={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function uo(t){try{const n=new URL(t).hostname;return xo[n]}catch{return}}const ft={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"};function fo(t){return t.includes("text")&&t.includes("image")?ft["text+image"]:ft[t[0]||"physical"]}const gt={text:0,image:1,physical:2};function De(t){return t.length===0?"physical":[...t].sort((n,o)=>(gt[n]??99)-(gt[o]??99)).join("+")}function go(t){const n=i=>{const a=i.match(/^(.+?)·第(\d+)[冊册]$/);if(a)return[a[1],parseInt(a[2])];const c=i.match(/^(.+?)[·(](\d+)[)]?$/);return c?[c[1],parseInt(c[2])]:null},o=new Map,r=[],s=new Set;for(let i=0;i<t.length;i++){const a=t[i];if(a.volumes&&a.volumes.length>0)continue;const c=n(a.name);if(!c)continue;const[l,d]=c,u=`${l}|${De(be(a))}`;o.has(u)||o.set(u,{base:{...a,name:l,url:"",volumes:[]},volumes:[]}),o.get(u).volumes.push({volume:d,url:a.url||void 0,status:"found"}),s.add(i)}for(const[,i]of o)if(i.volumes.length>=2)i.volumes.sort((a,c)=>a.volume-c.volume),i.base.volumes=i.volumes,i.base.expected_volumes=i.volumes.length,r.push(i.base);else for(let a=0;a<t.length;a++)if(s.has(a)){const c=n(t[a].name),l=c&&`${c[0]}|${De(be(t[a]))}`,d=`${i.base.name}|${De(be(i.base))}`;l===d&&s.delete(a)}for(let i=0;i<t.length;i++)s.has(i)||r.push(t[i]);return r}const lt=({items:t,groupByType:n=!0,onNavigate:o,renderLink:r})=>{const s=A(),i=f.useMemo(()=>go(t||[]),[t]),a={text:s.resourceType.text,image:s.resourceType.image,"text+image":s.resourceType.textImage,physical:s.resourceType.physical},c=x=>a[x]?a[x]:x.split("+").map(g=>a[g]||g).join("+");if(!i||i.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:s.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:i.map((x,g)=>e.jsx(ht,{item:x},x.id||g))});const l=new Map;for(const x of i){const g=De(be(x));l.has(g)||l.set(g,[]),l.get(g).push(x)}const d=["text","image","text+image","physical"],u=[...d.filter(x=>l.has(x)),...[...l.keys()].filter(x=>!d.includes(x)).sort()];return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:u.map(x=>{const g=l.get(x),p=fo(x.split("+"));return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:p,whiteSpace:"nowrap",flexShrink:0},children:c(x)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:g.map((h,y)=>e.jsx(ht,{item:h,onNavigate:o,renderLink:r},h.id||y))})]},x)})})};function ho(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const s=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(s)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(s[1]))}&page=${n}`;const i=new URL(t);return i.searchParams.set("page",String(n)),i.toString()}return t}catch{return t}}function bo(t){if(!t)return;const n=t.file_page_range||t.page_range;if(!n||typeof n!="string")return;const o=n.match(/^(\d+)/);return o?parseInt(o[1],10):void 0}function mo(t){if(t.url)return t.url;for(const[n,o]of Object.entries(t))if(n.endsWith("_url")&&typeof o=="string")return o}const yo={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},ht=({item:t})=>{const n=A(),{convert:o}=F(),[r,s]=f.useState(!1),i=f.useMemo(()=>(t.url?uo(t.url):void 0)||o(t.name),[t.url,t.name,o]),a=f.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(h=>({...h,url:h.url||mo(h)})),[t.volumes]),c=a&&a.length>0,l=c?new Set(a.filter(h=>h.status!=="missing").map(h=>h.volume)).size:0,d=c?new Set(a.filter(h=>h.status==="missing").map(h=>h.volume)).size:0,u=t.expected_volumes??(c?l+d:0),x=t.color_mode?{...yo[t.color_mode],label:n.colorMode[t.color_mode]}:null,g=t.details&&!c?o(t.details):null,p={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",background:"var(--bim-input-bg, #fff)",fontSize:"12px",color:"var(--bim-fg, #333)",lineHeight:1.4,verticalAlign:"middle"};return e.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[e.jsxs("div",{style:p,children:[e.jsx("span",{style:{fontWeight:500},children:i}),x&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:x.bg,color:x.fg},children:x.label}),g&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:g}),c&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[l,"/",u,n.unit.volume,d>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"3px"},children:["缺",d]})]}),t.url&&e.jsx("a",{href:(()=>{const h=bo(t.metadata);return h?ho(t.url,h):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),c&&e.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),c&&r&&e.jsx("div",{style:{padding:"6px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:a.map(h=>{const y=h.status==="missing";return h.url&&!y?e.jsx("a",{href:h.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:h.volume},h.volume):e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:y?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:y?"line-through":"none",opacity:y?.6:1},children:h.volume},h.volume)})})]})},rn=({indexSource:t,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:i,onSelectFolder:a})=>{const c=A(),l=t==="local",d=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",x=u?u.split(/[/\\]/).pop()||u:"",g={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:"var(--bim-primary-soft, #0078d415)",color:"var(--bim-primary, #0078d4)"},p={onMouseOver:y=>y.currentTarget.style.opacity="0.8",onMouseOut:y=>y.currentTarget.style.opacity="1"},h=e.jsxs("div",{onClick:s,title:d?c.mode.switchToOfficial:c.mode.switchToDraft,style:{...g,background:d?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...p,children:[e.jsx("span",{children:d?"📝":"📚"}),e.jsx("span",{children:d?"draft":"official"})]});return o==="index-browser"?l?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[h,e.jsxs("div",{onClick:r,title:c.mode.switchToSync,style:g,...p,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:c.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:a,title:u||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px"},...p,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:[h,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:r,title:c.mode.switchToLocal,style:g,...p,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:c.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:i,title:x||c.mode.configurePath,style:{...g,background:"transparent",padding:"6px",fontSize:"12px"},...p,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:r,title:l?c.mode.switchToGithub:c.mode.switchToLocal,style:g,...p,children:[e.jsx("span",{children:l?"📁":"🌐"}),e.jsx("span",{children:l?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),l&&e.jsxs("div",{onClick:a,title:u||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...p,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!l&&x&&e.jsxs("div",{style:{...g,background:"#2196f3",color:"white",cursor:"default"},title:u,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:x})]})]})},Ge="bim-search-history",bt=10,mt=8;function Le(){try{const t=localStorage.getItem(Ge);return t?JSON.parse(t):[]}catch{return[]}}function vo(t){try{const n=Le().filter(o=>o!==t);n.unshift(t),n.length>bt&&(n.length=bt),localStorage.setItem(Ge,JSON.stringify(n))}catch{}}function jo(t){try{const n=Le().filter(o=>o!==t);localStorage.setItem(Ge,JSON.stringify(n))}catch{}}function So(){try{localStorage.removeItem(Ge)}catch{}}const sn=({transport:t,value:n,onChange:o,onSearch:r,onEntrySelect:s,placeholder:i})=>{const a=A(),c=i??a.search.placeholder,l={work:a.indexType.work,book:a.indexType.book,collection:a.indexType.collection,entity:a.indexType.entity},[d,u]=f.useState(!1),[x,g]=f.useState([]),[p,h]=f.useState(-1),[y,b]=f.useState(Le),j=f.useRef(null),m=f.useRef(null),k=f.useRef(null),_=f.useRef(!1);f.useEffect(()=>{h(-1);const C=n.trim();if(!C){g(y.map(M=>({type:"history",text:M})));return}if(!t.searchAll){g([]);return}let B=!1;const H=setTimeout(()=>{t.searchAll(C,mt).then(M=>{if(B)return;const $=[...M.works,...M.books,...M.collections,...M.entities??[]];g($.slice(0,mt).map(D=>({type:"entry",text:D.title||D.id,entry:D})))}).catch(()=>{B||g([])})},80);return()=>{B=!0,clearTimeout(H)}},[n,y,t]),f.useEffect(()=>{const C=B=>{k.current&&!k.current.contains(B.target)&&u(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),f.useEffect(()=>{const C=B=>{var H,M;if(B.key==="/"&&document.activeElement!==j.current){const $=(H=document.activeElement)==null?void 0:H.tagName;if($==="INPUT"||$==="TEXTAREA"||$==="SELECT")return;B.preventDefault(),(M=j.current)==null||M.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const v=f.useCallback(C=>{C.trim()&&(vo(C.trim()),b(Le())),r(C),u(!1)},[r]),w=f.useCallback(C=>{C.type==="history"?(o(C.text),v(C.text)):C.entry&&(s?(s(C.entry),u(!1)):(o(C.text),v(C.text)))},[o,v,s]),S=f.useCallback(C=>{if(!d||x.length===0){C.key==="Enter"&&v(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),h(B=>(B+1)%x.length);break;case"ArrowUp":C.preventDefault(),h(B=>(B-1+x.length)%x.length);break;case"Enter":C.preventDefault(),p>=0&&p<x.length?w(x[p]):v(n);break;case"Escape":C.preventDefault(),u(!1);break}},[d,x,p,n,v,w]),z=f.useCallback((C,B)=>{B.stopPropagation(),jo(C),b(Le()),g(H=>H.filter(M=>!(M.type==="history"&&M.text===C)))},[]),E=f.useCallback(C=>{C.stopPropagation(),So(),b([]),g([])},[]);f.useEffect(()=>{if(p>=0&&m.current){const C=m.current.children;C[p]&&C[p].scrollIntoView({block:"nearest"})}},[p]);const I=!n.trim()&&y.length>0;return e.jsxs("div",{ref:k,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:j,type:"text",placeholder:c,value:n,onChange:C=>{o(C.target.value),u(!0)},onCompositionStart:()=>{_.current=!0},onCompositionEnd:()=>{_.current=!1},onFocus:()=>{u(!0)},onKeyDown:S,style:{width:"100%",padding:"8px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"14px",boxSizing:"border-box"}}),d&&x.length>0&&e.jsxs("div",{ref:m,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[I&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:a.search.history}),e.jsx("button",{onClick:E,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:a.search.clearAll})]}),x.map((C,B)=>e.jsxs("div",{onClick:()=>w(C),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:B===p?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:C.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.text}),C.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[l[C.entry.type],C.entry.edition&&` · ${C.entry.edition}`,C.entry.author&&` · ${C.entry.author}`]}),C.type==="history"&&e.jsx("button",{onClick:H=>z(C.text,H),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:"×"})]},`${C.type}-${C.text}-${B}`))]})]})},$e="bim-recent-ids",yt="bim-recent-entries",vt=50,Xe=5,ko=50,wo=200;function Be(){try{const t=localStorage.getItem($e);if(t)return JSON.parse(t);const n=localStorage.getItem(yt);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem($e,JSON.stringify(o)),localStorage.removeItem(yt),o}return[]}catch{return[]}}function _o(t){try{const n=Be().filter(o=>o!==t);n.unshift(t),n.length>vt&&(n.length=vt),localStorage.setItem($e,JSON.stringify(n))}catch{}}function Co(t){try{const n=Be().filter(o=>o!==t);localStorage.setItem($e,JSON.stringify(n))}catch{}}function zo(){try{localStorage.removeItem($e)}catch{}}const Io={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},ot=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:s,onSwitchMode:i,onToggleDraft:a,onConfigurePath:c,onSelectFolder:l,hideModeIndicator:d,initialQuery:u,onQueryChange:x,headerRight:g})=>{const p=A(),h=[{type:"work",icon:"✍️",name:p.indexType.work,key:"works"},{type:"book",icon:"📖",name:p.indexType.book,key:"books"},{type:"collection",icon:"📚",name:p.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:p.indexType.entity,key:"entities"}],[y,b]=f.useState(u??""),[j,m]=f.useState(null),[k,_]=f.useState(null),[v,w]=f.useState(!1),[S,z]=f.useState(null),[E,I]=f.useState(""),[C,B]=f.useState(!u),[H,M]=f.useState(Be),[$,D]=f.useState([]),[L,T]=f.useState(!1),[O,W]=f.useState(!1),[U,G]=f.useState(null),[Z,ne]=f.useState(null),he=f.useRef(void 0),ge=f.useRef(!1),Q=f.useCallback(async(P,J)=>{if(!P.trim()){B(!0),m(null),_(null);return}B(!1),w(!0),I("");try{if(t.searchAll){const Y=await t.searchAll(P,J??Xe);m(Y)}else{const Y=["work","book","collection","entity"],K=await Promise.all(Y.map(ee=>t.search(P,ee,{page:1,pageSize:J??Xe})));m({works:K[0].entries,books:K[1].entries,collections:K[2].entries,entities:K[3].entries,totalWorks:K[0].total,totalBooks:K[1].total,totalCollections:K[2].total,totalEntities:K[3].total})}}catch(Y){I(Y instanceof Error?Y.message:String(Y)),m(null)}finally{w(!1)}},[t]);f.useEffect(()=>{let P=!1;const J=()=>{var V,oe;const Y=["work","book","collection","entity"],K=Promise.all(Y.map(ce=>t.loadEntries(ce,{page:1,pageSize:1}).catch(()=>({total:0})))),ee=((V=t.getResourceCounts)==null?void 0:V.call(t).catch(()=>null))??Promise.resolve(null),R=((oe=t.getSubtypeStats)==null?void 0:oe.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([K,ee,R]).then(([ce,de,xt])=>{P||(G({works:ce[0].total,books:ce[1].total,collections:ce[2].total,entities:ce[3].total,hasText:de==null?void 0:de.hasText,hasImage:de==null?void 0:de.hasImage}),xt&&ne(xt))})};return t.getCounts?t.getCounts().then(Y=>{var K,ee;P||(G({works:Y.works,books:Y.books,collections:Y.collections,entities:Y.entities,hasText:(K=Y.resourceCounts)==null?void 0:K.hasText,hasImage:(ee=Y.resourceCounts)==null?void 0:ee.hasImage}),Y.subtypeStats&&ne(Y.subtypeStats))}).catch(()=>{P||J()}):J(),()=>{P=!0}},[t]),f.useEffect(()=>{ge.current||!(u!=null&&u.trim())||(ge.current=!0,Q(u))},[u,Q]);const q=f.useCallback(P=>{if(b(P),!P.trim()){x==null||x(P),B(!0),m(null),_(null);return}he.current&&clearTimeout(he.current),he.current=setTimeout(()=>{_(null),x==null||x(P),Q(P)},wo)},[Q,x]),Ye=f.useCallback(P=>{he.current&&clearTimeout(he.current),x==null||x(P),Q(P)},[Q,x]),Ke=f.useCallback(P=>{_(P),Q(y,ko)},[y,Q]);f.useEffect(()=>{if(!H.length){D([]);return}let P=!1;return T(!0),Promise.all(H.slice(0,10).map(async J=>{var Y,K,ee;try{if(t.getEntry){const V=await t.getEntry(J);if(V)return V}const R=await t.getItem(J);if(R){const V=R.authors;return{id:J,title:R.title||J,type:R.type||"work",author:(Y=V==null?void 0:V[0])==null?void 0:Y.name,dynasty:(K=V==null?void 0:V[0])==null?void 0:K.dynasty,role:(ee=V==null?void 0:V[0])==null?void 0:ee.role,edition:R.edition||void 0}}}catch{}return{id:J,title:J,type:"work",notFound:!0}})).then(J=>{P||(D(J),T(!1))}),()=>{P=!0}},[H,t]);const we=P=>{z(P.id),_o(P.id),M(Be()),r==null||r(P)},_e=P=>{Co(P),M(Be())},Je=()=>{zo(),M([])},Me=P=>h.find(J=>J.type===P),qe=j&&(j.works.length>0||j.books.length>0||j.collections.length>0);return e.jsxs("div",{className:"bim-browser-container",children:[e.jsx("header",{style:{padding:"12px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h1",{style:{margin:0,fontSize:"18px",color:"var(--bim-fg, #333)"},children:p.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[g,!d&&e.jsx(rn,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:i,onToggleDraft:a,onConfigurePath:c,onSelectFolder:l})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(sn,{transport:t,value:y,onChange:q,onSearch:Ye,onEntrySelect:we}),s&&e.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:"1px solid var(--bim-primary, #0078d4)",borderRadius:"6px",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px"},children:p.action.newEntry})]}),U&&C&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[e.jsx("span",{children:Z?e.jsxs(e.Fragment,{children:[(Z.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Z.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.books.toLocaleString()})," 本"]}),Z.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Z.article.toLocaleString()})," 篇"]}):null,Z.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Z.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[p.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.collections.toLocaleString()}),U.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.indexType.entity," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.entities.toLocaleString()})]})]})}),U.hasImage!=null&&U.hasText!=null&&e.jsxs("span",{children:[p.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:v?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:p.search.searching}):E?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:E})]}):C?e.jsx("div",{style:{flex:1},children:L?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:p.search.loading}):$.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{children:p.search.recentBrowse}),e.jsx("button",{onClick:Je,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:p.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:$.slice(0,O?10:3).map(P=>P.notFound?e.jsx(To,{id:P.id,onRemove:_e,t:p},P.id):e.jsx(jt,{entry:P,selected:S===P.id,onClick:we,getConfig:Me,onRemove:_e},P.id))}),!O&&$.length>3&&e.jsx("button",{onClick:()=>W(!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:p.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:p.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:p.search.searchSubtitle})]})}):qe?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:h.map(({type:P,icon:J,name:Y,key:K})=>{const ee=j[K]??[],R=Io[K],V=j[R]??0;if(ee.length===0)return null;const ce=!(k===P)&&V>Xe;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:[J," ",Y,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[V," ",p.unit.items]})]}),ce&&e.jsx("button",{onClick:()=>Ke(P),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:p.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:ee.map(de=>e.jsx(jt,{entry:de,selected:S===de.id,onClick:we,getConfig:Me,query:y},de.id))})]},P)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:Ae(p.search.noResultsFor,{query:y})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:p.search.tryOther})]})})]})},jt=({entry:t,selected:n,onClick:o,getConfig:r,query:s,onRemove:i})=>{const a=A(),{convert:c}=F(),l=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&l.length?l.find(u=>{const x=typeof u=="string"?u:u==null?void 0:u.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0;return e.jsxs("div",{onClick:()=>o(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:r(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:r(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:c(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:a.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:a.misc.imageResource,children:"🖼️"})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.edition)}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,a.unit.juan]}):null]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",c(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:c(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",c(t.role)]}),t.type==="entity"&&(t.birth_year!=null||t.death_year!=null)&&e.jsxs("span",{style:{marginLeft:t.dynasty?"4px":0},children:[t.birth_year??"?","—",t.death_year??"?"]})]}),d&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[a.search.alias,":",c(d)]})]}),i?e.jsx("button",{onClick:u=>{u.stopPropagation(),i(t.id)},title:a.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1,opacity:.5,marginTop:"2px"},children:"×"}):e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},To=({id:t,onRemove:n,t:o})=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",opacity:.6},children:[e.jsx("span",{style:{fontSize:"16px"},children:"❓"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",fontFamily:"monospace"},children:t}),e.jsx("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginTop:"2px"},children:o.search.itemNotFound})]}),e.jsx("button",{onClick:()=>n(t),title:o.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function Ro(t){var n;return!t.dynasty&&!t.birth_year&&!t.death_year&&(!t.alt_names||t.alt_names.length===0)&&!((n=t.description)!=null&&n.text)}function Eo({data:t}){const{convert:n}=F(),{dynasty:o,birth_year:r,death_year:s}=t,i=[];return o&&i.push(`〔${n(o)}〕`),r!==void 0&&s!==void 0?i.push(`${r}—${s}`):r!==void 0?i.push(`${r}—?`):s!==void 0&&i.push(`?—${s}`),i.length===0?null:e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-desc-fg, #717171)",marginLeft:"8px",fontWeight:"normal"},children:i.join(" ")})}function Lo({alt_names:t}){const{convert:n}=F(),o=new Map;for(const i of t){const a=i.type||"別名";o.has(a)||o.set(a,[]),o.get(a).push(i.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...o.keys()].sort((i,a)=>{const c=r.indexOf(i),l=r.indexOf(a);return c===-1&&l===-1?0:c===-1?1:l===-1?-1:c-l});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:s.map(i=>{const a=o.get(i);return e.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[e.jsx("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:i}),e.jsx("span",{children:a.map((c,l)=>e.jsxs("span",{children:[l>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(c)]},l))})]},i)})})}function Bo({data:t}){const n=t.external_ids;if(!n)return null;const o=[];return n.cbdb_id&&o.push(e.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${n.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",border:"1px solid var(--bim-link-fg, #0066cc)40",borderRadius:"3px",textDecoration:"none",background:"var(--bim-link-fg, #0066cc)08"},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),o.length===0?null:e.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:o})}function Wo({works:t,transport:n,onNavigate:o,renderLink:r}){const s=A(),{convert:i}=F(),a=ae(),[c,l]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let g=!1;const p=t.map(y=>y.work_id);return(async()=>{const y=new Map;if(n.getEntriesByIds)try{const k=await n.getEntriesByIds(p);let _=!0;for(let v=0;v<p.length;v++){const w=k[v];w!=null&&w.title?y.set(p[v],w.title):w!=null&&w.primary_name?y.set(p[v],w.primary_name):_=!1}if(_)return y}catch{}const b=[...p],j=8,m=new Array(j).fill(0).map(async()=>{for(;b.length;){const k=b.shift();if(!k)break;if(!y.has(k))try{if(n.getEntry){const w=await n.getEntry(k);if(w!=null&&w.title){y.set(k,w.title);continue}}const _=await n.getItem(k),v=_&&(_.title||_.primary_name)||k;y.set(k,v)}catch{y.set(k,k)}}});return await Promise.all(m),y})().then(y=>{g||l(y)}),()=>{g=!0}},[t,n]);const d=new Map;for(const g of t){const p=g.role||"";d.has(p)||d.set(p,[]),d.get(p).push(g)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],x=[...d.keys()].sort((g,p)=>{const h=u.indexOf(g),y=u.indexOf(p);return h===-1&&y===-1?g.localeCompare(p):h===-1?1:y===-1?-1:h-y});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)",margin:"0 0 8px",paddingBottom:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[s.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),x.map(g=>{const p=d.get(g);return e.jsxs("div",{style:{marginBottom:"8px"},children:[g&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginBottom:"2px"},children:[i(g)," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #bbb)"},children:["(",p.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:g?"16px":"0",listStyle:g?"disc":"none",fontSize:"14px",lineHeight:1.8},children:p.map((h,y)=>{const b=i(c.get(h.work_id)||h.work_id);return r?e.jsx("li",{children:r(h.work_id,b)},y):o?e.jsx("li",{children:e.jsx("a",{href:a(h.work_id),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),o(h.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:b})},y):e.jsx("li",{children:b},y)})})]},g)})]})}const ln=({data:t,transport:n,onNavigate:o,renderLink:r,headerExtra:s})=>{var u;const i=A(),{convert:a}=F();let c=!1;try{c=N.extractStatus(t.id)==="draft"}catch{}const l=Ro(t),d=t.subtype==="people"?"人物":t.subtype==="place"?"地名":t.subtype==="dynasty"?"朝代":t.subtype==="anonymous"?"佚名":t.subtype==="collective"?"集体":t.subtype;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:"var(--bim-fg, #222)"},children:[a(t.primary_name),e.jsx(Eo,{data:t})]}),s]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:"#5b3e8e",border:"1px solid #5b3e8e40",borderRadius:"2px",background:"#5b3e8e08"},children:i.indexType.entity}),d&&t.subtype!=="people"&&e.jsx("span",{children:d}),c&&e.jsx("span",{style:{padding:"1px 6px",background:"#fff3cd",border:"1px solid #ffc107",borderRadius:"2px",color:"#856404"},children:i.status.draft}),e.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:t.id})]}),l&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #999)",fontStyle:"italic",padding:"8px 12px",background:"var(--bim-widget-bg, #f8f8f8)",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),t.alt_names&&t.alt_names.length>0&&e.jsx(Lo,{alt_names:t.alt_names}),e.jsx(Bo,{data:t}),((u=t.description)==null?void 0:u.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:a(t.description.text)}),t.works&&t.works.length>0&&e.jsx(Wo,{works:t.works,transport:n,onNavigate:o,renderLink:r})]})},an={p:({children:t})=>e.jsx("p",{style:{margin:"0 0 0.5em"},children:t}),ul:({children:t})=>e.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:t}),ol:({children:t})=>e.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:t}),li:({children:t})=>e.jsx("li",{style:{marginBottom:"2px"},children:t}),a:({href:t,children:n})=>e.jsx("a",{href:t,target:t!=null&&t.startsWith("http")?"_blank":void 0,rel:t!=null&&t.startsWith("http")?"noopener noreferrer":void 0,style:{color:"var(--bim-link, #1976d2)"},children:n}),code:({children:t})=>e.jsx("code",{style:{background:"var(--bim-bg-subtle, #f4f4f4)",padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:t})},$o={...an,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},rt=({text:t,plainStrong:n,style:o,className:r})=>{const{convert:s}=F(),i=n?$o:an;return e.jsx("div",{className:r,style:o,children:e.jsx(Nn,{remarkPlugins:[Gn],components:i,children:s(t)})})},Po=["〇","一","二","三","四","五","六","七","八","九"],St=["","十","百","千"];function cn(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),o=n.length;let r="",s=!1;for(let i=0;i<o;i++){const a=parseInt(n[i]),c=o-1-i;a===0?s=!0:(s&&r&&(r+="〇"),s=!1,a===1&&c===1&&i===0?r+=St[c]:r+=Po[a]+St[c])}return r}function Ao({type:t}){const n=A(),o={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3",entity:"#5b3e8e"};return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:o[t],border:`1px solid ${o[t]}40`,borderRadius:"2px",background:`${o[t]}08`},children:n.indexType[t]})}function Mo({isDraft:t}){const n=A();return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t?"#e67e22":"#27ae60",border:`1px solid ${t?"#e67e2240":"#27ae6040"}`,borderRadius:"2px",background:t?"#e67e2208":"#27ae6008"},children:t?n.status.draft:n.status.official})}function Fo({id:t}){const n=A(),[o,r]=f.useState(!1),s=()=>{navigator.clipboard.writeText(t).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",background:"#f6f6f6",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"2px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:s,title:o?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:o?1:.5,transition:"opacity 0.15s"},onMouseEnter:i=>i.currentTarget.style.opacity="1",onMouseLeave:i=>i.currentTarget.style.opacity=o?"1":"0.5",children:o?"✓":"⧉"})]})}function ie({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 xe({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 dn({authors:t,type:n,onNavigate:o,renderLink:r}){const{convert:s}=F();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((i,a)=>{const c=s(i.name),l=i.entity_id?e.jsx(le,{id:i.entity_id,label:c,onNavigate:o,renderLink:r}):e.jsx("span",{style:{fontWeight:500},children:c});return e.jsxs("span",{children:[a>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),i.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",s(i.dynasty),"〕"]}),l,i.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",s(i.role)]})]},a)})})}function le({id:t,label:n,onNavigate:o,renderLink:r}){const s=ae();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:s(t),onClick:i=>{i.metaKey||i.ctrlKey||(i.preventDefault(),o(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:i=>i.currentTarget.style.borderBottomStyle="solid",onMouseLeave:i=>i.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function Ho({id:t,title:n,edition:o,type:r,isDraft:s,authors:i,volumeText:a,meta:c,headerExtra:l,onNavigate:d,renderLink:u}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,o&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:o}),a&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:a})]}),l&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:l})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(Ao,{type:r}),e.jsx(Mo,{isDraft:s}),e.jsx(Fo,{id:t})]}),((i==null?void 0:i.length)||c.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[i&&i.length>0&&e.jsx(dn,{authors:i,type:r,onNavigate:d,renderLink:u}),c]})]})}function pn({items:t,label:n,showMeta:o,onNavigate:r,renderLink:s}){const i=A(),{convert:a}=F();if(!t.length)return null;const[c,l]=f.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((d,u)=>{const x=c===u;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...x?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>l(x?null:u),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:x?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:a(d.source)}),!x&&o&&d.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(le,{id:d.source_bid,label:i.action.view,onNavigate:r,renderLink:s})})]}),x&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[o&&(d.title_info||d.author_info||d.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&e.jsx(xe,{label:i.label.titleInfo,children:a(d.title_info)}),d.author_info&&e.jsx(xe,{label:i.label.authorInfo,children:a(d.author_info)}),d.edition&&e.jsx(xe,{label:i.label.edition,children:a(d.edition)})]}),d.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:a(d.summary)})]}),d.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.comment)})]}),d.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.additional_comment)})]})]})]},u)})})]})}function Oo({items:t,onNavigate:n,renderLink:o}){const r=A();return e.jsx(pn,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function xn({items:t,onNavigate:n,renderLink:o}){const r=A();return e.jsx(pn,{items:t,label:r.section.emendated,onNavigate:n,renderLink:o})}function un({label:t,items:n}){const{convert:o}=F();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,s)=>{const i=typeof r=="string"?r:r.book_title;return e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:o(i)},s)})})]}):null}function Do({items:t}){const n=A();return e.jsx(un,{label:n.section.aliases,items:t})}function Vo({items:t}){const n=A();return e.jsx(un,{label:n.section.attachedTexts,items:t})}function Uo({items:t}){const n=A(),{convert:o}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((r,s)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:["《",o(r.book_title),"》",r.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},s))})]}):null}function No({items:t}){const n=A(),{convert:o}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((r,s)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:"var(--bim-primary, #8e6f3e)",border:"1.5px solid var(--bim-input-bg, #fff)"}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:o(r.name)}),r.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:o(r.description)})]},s))]})]}):null}function Go({items:t}){const n=A(),{convert:o}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((r,s)=>e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:"var(--bim-desc-fg, #ccc)"},children:"·"}),o(r)]},s))})]}):null}function kt({title:t,ids:n,transport:o,onNavigate:r,renderLink:s}){const{convert:i}=F(),[a,c]=f.useState([]);return f.useEffect(()=>{if(!n.length){c([]);return}if(!o){c(n.map(d=>({id:d})));return}let l=!1;return Promise.all(n.map(d=>o.getItem(d).then(u=>({id:d,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:d})))).then(d=>{l||c(d)}),()=>{l=!0}},[n,o]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(ie,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(a.length?a:n.map(l=>({id:l}))).map(l=>{const d=l.edition?`${i(l.title)||l.id}(${i(l.edition)})`:i(l.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(le,{id:l.id,label:d,onNavigate:r,renderLink:s})},l.id)})})]}):null}function Ze({book:t,onNavigate:n,renderLink:o}){const r=A(),{convert:s}=F(),[i,a]=f.useState(!1),c=t.resources&&t.resources.length>0,l=t.edition?s(t.edition):s(t.title)||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{padding:"6px 12px",borderBottom:c&&!i?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:e.jsx(le,{id:t.id,label:l,onNavigate:n,renderLink:o})}),c&&e.jsx("span",{onClick:()=>a(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:i?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:i?r.action.expand:r.action.collapse,children:"▼"})]}),c&&!i&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(lt,{items:t.resources,groupByType:!0,onNavigate:n,renderLink:o})})]})}function Yo({ids:t,workData:n,transport:o,onNavigate:r,renderLink:s,footer:i}){const a=A(),{convert:c}=F(),[l,d]=f.useState([]);if(f.useEffect(()=>{if(!t.length){d([]);return}if(!o){d(t.map(y=>({id:y})));return}let h=!1;return Promise.all(t.map(y=>o.getItem(y).then(b=>({id:y,title:b?b.title:void 0,edition:b?b.edition:void 0,resources:b?b.resources:void 0})).catch(()=>({id:y})))).then(y=>{h||d(y)}),()=>{h=!0}},[t,o]),!t.length)return null;const u=l.length?l:t.map(h=>({id:h})),x=new Map(u.map(h=>[h.id,h])),g=n==null?void 0:n.version_graph,p=Ko(t,g);return e.jsxs(e.Fragment,{children:[e.jsxs(ie,{children:[a.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),i,p.useGrouping?e.jsxs(e.Fragment,{children:[p.coreIds.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:p.coreIds.map(h=>{const y=x.get(h);return y?e.jsx(Ze,{book:y,onNavigate:r,renderLink:s},h):null})}),p.groupedIds.map(h=>e.jsxs("details",{style:{marginTop:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:6,background:"var(--bim-bg-subtle, #fafafa)"},children:[e.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:"var(--bim-fg, #333)",userSelect:"none"},children:[c(h.label),e.jsxs("span",{style:{marginLeft:6,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:["(",h.ids.length,")"]}),h.description&&e.jsx("span",{style:{marginLeft:8,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:c(h.description)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:h.ids.map(y=>{const b=x.get(y);return b?e.jsx(Ze,{book:b,onNavigate:r,renderLink:s},y):null})})]},h.id))]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(h=>e.jsx(Ze,{book:h,onNavigate:r,renderLink:s},h.id))})]})}function Ko(t,n){var b,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const o=(b=n.collections)==null?void 0:b[n.default_collection],r=(o==null?void 0:o.groups)??[],s=(o==null?void 0:o.book_ids)??[],i=r.length>0||s.length>0,a=!i&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!i&&a.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(r),l=new Set([...s,...a]),d=m=>{if(l.has(m))return!0;const k=n.node_groups[m];return k!=null&&c.has(k)},u=[],x=new Map,g=[];for(const m of t)if(!((j=n.excluded_books)!=null&&j.includes(m)))if(d(m))u.push(m);else{const k=n.node_groups[m];k?(x.has(k)||x.set(k,[]),x.get(k).push(m)):g.push(m)}if(g.length+[...x.values()].reduce((m,k)=>m+k.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const h=new Map((n.groups??[]).map(m=>[m.id,m])),y=[...x.entries()].map(([m,k])=>{const _=h.get(m);return{id:m,label:(_==null?void 0:_.label)??m,description:_==null?void 0:_.description,ids:k}});return g.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:u,groupedIds:y}}function Jo({workData:t,onNavigate:n,renderLink:o}){var a,c,l,d;const r=A(),{convert:s}=F(),i=!!((a=t.description)!=null&&a.text)||!!t.parent_work;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"6px 14px",borderBottom:i?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(le,{id:t.id,label:s(t.title),onNavigate:n,renderLink:o})}),t.measure_info?e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:s(t.measure_info)}):((c=t.juan_count)==null?void 0:c.number)!=null&&t.juan_count.number>0?e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[cn(t.juan_count.number),r.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(dn,{authors:t.authors,type:"work",onNavigate:n,renderLink:o})})]}),i&&e.jsxs("div",{style:{padding:"8px 14px"},children:[((l=t.description)==null?void 0:l.text)&&e.jsx(rt,{text:t.description.text,style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,textAlign:"justify"}}),t.parent_work&&e.jsx("div",{style:{marginTop:(d=t.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:e.jsx(xe,{label:r.label.parentWork,children:e.jsx(le,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function qo({items:t,onNavigate:n,renderLink:o}){const r=A(),{convert:s}=F();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(i=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid #2471a340",borderRadius:"4px",background:"#2471a308"},children:[e.jsx("span",{style:{fontSize:"11px",color:"#2471a3"},children:r.indexType.collection}),e.jsx(le,{id:i.id,label:s(i.title)||i.id,onNavigate:n,renderLink:o}),i.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:Ae(r.catalog.volume,{n:i.volume_index})})]},i.id))}):null}const at=({data:t,id:n,transport:o,onNavigate:r,renderLink:s,headerExtra:i,relatedBooksFooter:a,className:c,style:l})=>{var B,H,M,$,D,L;const d=A(),{convert:u}=F(),[x,g]=f.useState(null),[p,h]=f.useState(!1),[y,b]=f.useState(null),[j,m]=f.useState(null),[k,_]=f.useState([]),v=t||x;if(f.useEffect(()=>{if(t||!n||!o)return;let T=!1;return h(!0),b(null),o.getItem(n).then(O=>{T||(O?g(O):b(d.misc.notFoundEntry))}).catch(O=>{T||b(O instanceof Error?O.message:d.misc.loadFailed)}).finally(()=>{T||h(!1)}),()=>{T=!0}},[t,n,o]),f.useEffect(()=>{if(!v||!o){m(null),_([]);return}let T=!1;const O=v.type==="book"||v.type==="collection"?v.work_id:void 0;if(O?o.getItem(O).then(W=>{!T&&W&&W.type==="work"&&m(W)}).catch(()=>{}):m(null),v.type==="book"){const W=v;W.contained_in&&W.contained_in.length>0?Promise.all(W.contained_in.map(U=>{const G=typeof U=="string"?U:U.id,Z=typeof U=="string"?void 0:U.volume_index;return o.getItem(G).then(ne=>({id:G,title:ne&&ne.title||G,volume_index:Z})).catch(()=>({id:G,title:G,volume_index:Z}))})).then(U=>{T||_(U)}):_([])}else _([]);return()=>{T=!0}},[v,o]),p)return e.jsx("div",{className:c,style:{...l,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((T,O)=>e.jsx("div",{style:{height:O===1?"32px":"16px",width:`${T}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},O))})});if(y)return e.jsx("div",{className:c,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y});if(!v)return null;if(v.type==="entity")return e.jsx("div",{className:c,style:l,children:e.jsx(ln,{data:v,transport:o,onNavigate:r,renderLink:s,headerExtra:i})});const w=v.type==="book"?v:null,S=v.type==="collection"?v:null,z=v.type==="work"?v:null;let E=!1;try{E=N.extractStatus(v.id)==="draft"}catch{}let I="";v.measure_info?I=u(v.measure_info):(B=v.juan_count)!=null&&B.number?I=cn(v.juan_count.number)+d.unit.juan:(H=v.juan_count)!=null&&H.description&&(I=u(v.juan_count.description));const C=[];return(M=v.publication_info)!=null&&M.year&&C.push(e.jsx(xe,{label:d.label.year,children:v.publication_info.year},"year")),($=v.current_location)!=null&&$.name&&C.push(e.jsx(xe,{label:d.label.currentLocation,children:u(v.current_location.name)},"loc")),(D=v.page_count)!=null&&D.description&&C.push(e.jsx(xe,{label:d.label.pageCount,children:v.page_count.description},"page")),w!=null&&w.edition&&C.push(e.jsx(xe,{label:d.label.edition,children:u(w.edition)},"ver")),z!=null&&z.parent_work&&C.push(e.jsx(xe,{label:d.label.parentWork,children:e.jsx(le,{id:z.parent_work.id,label:u(z.parent_work.title),onNavigate:r,renderLink:s})},"pw")),z!=null&&z.parent_works&&z.parent_works.length>0&&!z.parent_work&&C.push(e.jsx(xe,{label:d.label.parentWork,children:z.parent_works.map((T,O)=>e.jsxs("span",{children:[O>0&&"、",e.jsx(le,{id:T,onNavigate:r,renderLink:s})]},T))},"pws")),e.jsxs("div",{className:c,style:l,children:[e.jsx(Ho,{id:v.id,title:u(v.title),edition:v.edition?u(v.edition):void 0,type:v.type,isDraft:E,authors:v.authors,volumeText:I,meta:C,headerExtra:i,onNavigate:r,renderLink:s}),((L=v.description)==null?void 0:L.text)&&e.jsx(rt,{text:v.description.text,style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),v.appendix&&v.appendix.length>0&&e.jsx("div",{style:{marginTop:8,marginBottom:4},children:v.appendix.map((T,O)=>e.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:"var(--bim-bg-subtle, #fafafa)",borderRadius:4,border:"1px solid var(--bim-widget-border, #ececec)"},children:[e.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:"var(--bim-muted, #666)"},children:u(T.title)}),e.jsx(rt,{text:T.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:"var(--bim-fg, #444)"}})]},O))}),k.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:d.section.containedIn}),e.jsx(qo,{items:k,onNavigate:r,renderLink:s})]}),j&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:d.section.belongsToWork}),e.jsx(Jo,{workData:j,onNavigate:r,renderLink:s})]}),v.additional_works&&v.additional_works.length>0&&e.jsx(Uo,{items:v.additional_works}),v.additional_titles&&v.additional_titles.length>0&&e.jsx(Do,{items:v.additional_titles}),v.attached_texts&&v.attached_texts.length>0&&e.jsx(Vo,{items:v.attached_texts}),v.indexed_by&&v.indexed_by.length>0&&e.jsx(Oo,{items:v.indexed_by,onNavigate:r,renderLink:s}),v.emendated_by&&v.emendated_by.length>0&&e.jsx(xn,{items:v.emendated_by,onNavigate:r,renderLink:s}),v.resources&&v.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:d.section.resources}),e.jsx(lt,{items:v.resources,groupByType:!0,onNavigate:r,renderLink:s})]}),(w==null?void 0:w.location_history)&&w.location_history.length>0&&e.jsx(No,{items:w.location_history}),(S==null?void 0:S.history)&&S.history.length>0&&e.jsx(Go,{items:S.history}),(w==null?void 0:w.related_books)&&w.related_books.length>0&&e.jsx(kt,{title:d.section.relatedVersions,ids:w.related_books,transport:o,onNavigate:r,renderLink:s}),(S==null?void 0:S.books)&&S.books.length>0&&e.jsx(kt,{title:d.section.containedBooks,ids:S.books,transport:o,onNavigate:r,renderLink:s}),(S==null?void 0:S.contained_works)&&S.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(ie,{children:[d.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",S.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.contained_works.map(T=>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(le,{id:T.id,label:u(T.title),onNavigate:r,renderLink:s})},T.id))})]}),(z==null?void 0:z.books)&&z.books.length>0&&e.jsx(Yo,{ids:z.books,workData:z,transport:o,onNavigate:r,renderLink:s,footer:a}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const T=[],O=z.related_works.filter(G=>G.relation==="part_of"),W=z.related_works.filter(G=>G.relation==="has_part"),U=z.related_works.filter(G=>!G.relation);return O.length>0&&T.push({label:d.section.belongsToWork,items:O}),W.length>0&&T.push({label:d.section.containedWorks,items:W}),U.length>0&&T.push({label:d.section.relatedWorks,items:U}),T.map(G=>e.jsxs("div",{children:[e.jsxs(ie,{children:[G.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",G.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:G.items.map(Z=>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(le,{id:Z.id,label:u(Z.title),onNavigate:r,renderLink:s})},Z.id))})]},G.label))})()]})};function Xo({data:t}){const n=A(),{convert:o}=F(),{stats:r}=t,s=r.processed_volumes??r.total_found_volumes,i=s!=null&&t.total_volumes>0?Math.round(s/t.total_volumes*100):null;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:o(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:o(t.resource_name)}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsxs("span",{children:[n.catalog.totalVolumes," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:t.total_volumes})," ",n.unit.volume]}),i!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:s})," ",n.unit.volume," (",i,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"#e67e22"},children:r.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function Zo({sections:t,activeSection:n,onSelect:o}){const r=A();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>o(null),style:wt(n===null),children:r.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>o(s.name),style:wt(n===s.name),children:[s.name,s.volume_range&&e.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[s.volume_range[0],"–",s.volume_range[1]]})]},s.name))]})}function wt(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 Qo({id:t,label:n,onNavigate:o,renderLink:r}){const s=ae();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:s(t),onClick:i=>{i.metaKey||i.ctrlKey||(i.preventDefault(),o(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px",fontSize:"12px"},onMouseEnter: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 er(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const o=t[0],r=t[t.length-1];return r-o+1===t.length?`${o}–${r}`:t.length<=3?t.join(", "):`${o}–${r} (${t.length}${n})`}function _t({book:t,onNavigate:n,renderLink:o,showVolumes:r}){const s=A(),{convert:i}=F(),a=t.book_id||t.work_id,c=r&&t.volumes.length>0?er(t.volumes,s.unit.volume):null,l=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[r&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:c}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[i(t.title),t.sub_items&&t.sub_items.length>0&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",t.sub_items.map(d=>i(d)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:i(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:l?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),a&&e.jsx(Qo,{id:a,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:o}),!a&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:s.catalog.unmatched_label})]})}const fn=({data:t,collectionId:n,transport:o,onNavigate:r,renderLink:s,className:i,style:a})=>{const c=A(),[l,d]=f.useState(null),[u,x]=f.useState(!1),[g,p]=f.useState(null),[h,y]=f.useState(null),[b,j]=f.useState(""),m=t||l;f.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollectionCatalog))return;let S=!1;return x(!0),p(null),o.getCollectionCatalog(n).then(z=>{S||(z?d(z):p(c.catalog.notFound))}).catch(z=>{S||p(z instanceof Error?z.message:c.catalog.loadFailed)}).finally(()=>{S||x(!1)}),()=>{S=!0}},[t,n,o,c]);const k=(m==null?void 0:m.sections)&&m.sections.length>0,_=f.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const S=m.books.map(E=>E.volumes[0]).filter(E=>E!=null);return new Set(S).size<S.length},[m]),v=f.useMemo(()=>{if(!m)return[];let S=m.books;if(h&&(S=S.filter(z=>z.section===h)),b.trim()){const z=b.trim().toLowerCase();S=S.filter(E=>E.title.toLowerCase().includes(z)||E.sub_items&&E.sub_items.some(I=>I.toLowerCase().includes(z))||E.edition&&E.edition.toLowerCase().includes(z))}return S},[m,h,b]),w=f.useMemo(()=>{if(!_)return null;const S=[],z=new Map;for(const I of v){if(!I.volumes||I.volumes.length===0)continue;const C=I.volumes[0];z.has(C)||z.set(C,[]),z.get(C).push(I)}const E=[...z.keys()].sort((I,C)=>I-C);for(const I of E)S.push({volume:I,books:z.get(I)});return S},[v,_]);return u?e.jsx("div",{className:i,style:{...a,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.catalog.loading})}):g?e.jsx("div",{className:i,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g}):m?e.jsxs("div",{className:i,style:a,children:[e.jsx(Xo,{data:m}),k&&e.jsx(Zo,{sections:m.sections,activeSection:h,onSelect:y}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:c.search.searchBookName,value:b,onChange:S=>j(S.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[v.length," ",c.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[w?w.map((S,z)=>e.jsxs("div",{children:[e.jsx("div",{style:{padding:"4px 12px",background:"var(--bim-bg, #f8f8f8)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",fontSize:"12px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",position:"sticky",top:0,zIndex:1},children:Ae(c.catalog.volume,{n:S.volume})}),S.books.map((E,I)=>e.jsx(_t,{book:E,onNavigate:r,renderLink:s,showVolumes:E.volumes.length>1},`${S.volume}-${I}`))]},`${S.volume}-${z}`)):v.map((S,z)=>e.jsx(_t,{book:S,onNavigate:r,renderLink:s,showVolumes:!0},z)),v.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:c.catalog.noMatch})]})]}):null},ye=()=>{const[t,n]=f.useState(1);return f.useEffect(()=>{const o=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(o)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(t)})},te=6,Fe=7,tr=({content:t,children:n,placement:o="top",delayMs:r=100,maxWidth:s=280,wrapperStyle:i})=>{const[a,c]=f.useState(!1),[l,d]=f.useState(null),u=f.useRef(null),x=f.useRef(null),g=f.useRef(null),p=f.useCallback(()=>{const b=x.current,j=g.current;if(!b||!j)return;const m=b.getBoundingClientRect(),k=j.getBoundingClientRect(),_=window.innerHeight,v=document.documentElement.clientWidth;let w=o;o==="top"&&m.top-k.height-Fe<8&&(w="bottom"),o==="bottom"&&m.bottom+k.height+Fe>_-8&&(w="top");const S=w==="top"?m.top-k.height-Fe:m.bottom+Fe;let z=m.left+m.width/2-k.width/2;z=Math.max(8,Math.min(z,v-k.width-8)),d({left:z,top:S,placement:w})},[o]),h=f.useCallback(()=>{u.current&&clearTimeout(u.current),u.current=setTimeout(()=>c(!0),r)},[r]),y=f.useCallback(()=>{u.current&&clearTimeout(u.current),c(!1),d(null)},[]);return f.useEffect(()=>{if(!a)return;const b=requestAnimationFrame(p);return()=>cancelAnimationFrame(b)},[a,p]),f.useEffect(()=>()=>{u.current&&clearTimeout(u.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:x,onMouseEnter:h,onMouseLeave:y,onFocus:h,onBlur:y,style:{display:"inline-block",...i},children:n}),a&&Yn.createPortal(e.jsxs("div",{ref:g,role:"tooltip",style:{position:"fixed",left:(l==null?void 0:l.left)??-9999,top:(l==null?void 0:l.top)??-9999,maxWidth:s,padding:"6px 10px",fontSize:"12px",lineHeight:1.5,color:"var(--bim-fg, #333)",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.08)",pointerEvents:"none",zIndex:9999,opacity:l?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,l&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-te,width:0,height:0,...l.placement==="top"?{bottom:-te,borderTop:`${te}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${te}px solid transparent`,borderRight:`${te}px solid transparent`}:{top:-te,borderBottom:`${te}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${te}px solid transparent`,borderRight:`${te}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...l.placement==="top"?{bottom:-5,borderTop:`${te-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${te-1}px solid transparent`,borderRight:`${te-1}px solid transparent`}:{top:-5,borderBottom:`${te-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${te-1}px solid transparent`,borderRight:`${te-1}px solid transparent`}}})]})]}),document.body)]})},Ct={A:"fine",B:"rough",C:"rough",D:"ocr"};function nr(t){return typeof t!="string"?null:t in tn?t:t in Ct?Ct[t]:null}const or={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"};function X(t){return typeof t!="string"?"":or[t]??t}const rr=["〇","一","二","三","四","五","六","七","八","九"],zt=["","十","百","千"],ir=["","萬","億"];function gn(t){if(t===0)return"〇";if(t<0)return`負${gn(-t)}`;const n=[];let o=t,r=0;for(;o>0;){const s=o%1e4;s>0?n.unshift(sr(s,r>0)+ir[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function sr(t,n){const o=[];let r=t;for(;r>0;)o.unshift(r%10),r=Math.floor(r/10);let s="";for(let i=0;i<o.length;i++){const a=o[i],c=o.length-1-i;a===0?s&&!s.endsWith("〇")&&(s+="〇"):a===1&&c===1&&i===0&&!n?s+=zt[c]:s+=rr[a]+zt[c]}return s.replace(/〇$/,"")}let We=null,He=null;const Ue=new Set;function lr(){return We?Promise.resolve():He||(He=import("opencc-js/t2cn").then(t=>{We=t.Converter({from:"tw",to:"cn"}),Ue.forEach(n=>n())}).catch(()=>{We=t=>t,Ue.forEach(t=>t())}),He)}function fe(){const[,t]=f.useState(0);return f.useEffect(()=>{if(We)return;const n=()=>t(o=>o+1);return Ue.add(n),lr(),()=>{Ue.delete(n)}},[]),We??(n=>n)}function Se(t,n){return n(t).toLowerCase()}const ct="#fff59d";function ke(t,n,o){if(!n)return t;const r=Se(n,o);if(!r)return t;const s=Se(t,o);if(s.length!==t.length)return t;const i=[];let a=0,c=0;for(;a<t.length;){const l=s.indexOf(r,a);if(l===-1){i.push(t.slice(a));break}l>a&&i.push(t.slice(a,l)),i.push(e.jsx("mark",{style:{background:ct,padding:0,color:"inherit"},children:t.slice(l,l+r.length)},c++)),a=l+r.length}return e.jsx(e.Fragment,{children:i})}function dt(t,n,o,r){if(!n)return!0;const s=Se(n,r);return(o?[t.title,t.header_line,t.content,t.comment]:[t.title,t.book_title,t.author,t.author_info,t.summary,t.content,t.comment,t.additional_comment]).some(a=>typeof a=="string"&&Se(a,r).includes(s))}function ar(t,n,o){return n?Se(t,o).includes(Se(n,o)):!0}const pt={类:"#8e6f3e",书:"#c0392b",序:"#1a5276",结语:"#7d6608"},cr={考证:"#5d6d7e"};function dr(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 hn({file:t,isActive:n,onSelect:o,meta:r,matchState:s}){const i=s===0,a=s==="loading",c=typeof s=="number"&&s>0,l=dr(t),d=!!(r!=null&&r.vol_label)&&!l.includes(r.vol_label);return e.jsxs("button",{onClick:()=>{i||o(t)},disabled:i,style:{padding:"3px 8px",border:n?"1px solid var(--bim-primary, #8e6f3e)":i?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":c?`${ct}40`:"transparent",color:n?"var(--bim-primary, #8e6f3e)":i?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:i?"not-allowed":"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4,opacity:i?.5:1},children:[l,d&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",r.vol_label,"冊)"]}),c&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:s}),a&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function bn(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(r=>bn(r,n)))}function mn(t){var r;const n=t.files.length,o=((r=t.children)==null?void 0:r.reduce((s,i)=>s+mn(i),0))||0;return n+o}function pr(t,n){const o=[],r=a=>{var c;o.push(...a.files),(c=a.children)==null||c.forEach(r)};if(r(t),o.length===0)return;const s=o.map(a=>n[a]);if(s.every(a=>a===void 0))return;if(s.some(a=>a==="loading"))return"loading";let i=0;for(const a of s)typeof a=="number"&&(i+=a);return i}function yn({group:t,activeFile:n,onSelect:o,depth:r=0,juanMeta:s,matchStates:i}){var h;const a=bn(t,n||""),c=pr(t,i),l=typeof c=="number"&&c>0,d=c===0,[u,x]=f.useState(a||l),g=mn(t),p=!!((h=t.children)!=null&&h.length);if(f.useEffect(()=>{a&&x(!0)},[a]),f.useEffect(()=>{l&&x(!0)},[l]),t.files.length===1&&!p){const y=t.files[0],b=n===y,j=i[y],m=j===0,k=j==="loading",_=typeof j=="number"&&j>0;return e.jsxs("button",{onClick:()=>{m||o(y)},disabled:m,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:b?"1px solid var(--bim-primary, #8e6f3e)":m?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:b?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":_?`${ct}40`:"transparent",color:b?"var(--bim-primary, #8e6f3e)":m?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:m?"not-allowed":"pointer",fontSize:"12px",fontWeight:b?600:400,lineHeight:1.4,opacity:m?.5:1},children:[t.label,_&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:j}),k&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}return e.jsxs("div",{style:{marginBottom:r===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>x(!u),style:{display:"flex",alignItems:"center",gap:"6px",padding:r===0?"4px 8px":"2px 8px",paddingLeft:`${8+r*16}px`,cursor:"pointer",userSelect:"none",fontSize:r===0?"13px":"12px",fontWeight:r===0?600:500,color:a?"var(--bim-primary, #8e6f3e)":d?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",opacity:d?.6:1},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:u?"rotate(90deg)":"none",display:"inline-block"},children:"▶"}),e.jsx("span",{children:t.label}),e.jsxs("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",g,")"]}),l&&e.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"#b78900"},children:["匹配 ",c]}),c==="loading"&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]}),u&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",padding:`4px 0 4px ${24+r*16}px`},children:t.files.map(y=>e.jsx(hn,{file:y,isActive:n===y,onSelect:o,meta:s==null?void 0:s[y],matchState:i[y]},y))}),p&&t.children.map((y,b)=>e.jsx(yn,{group:y,activeFile:n,onSelect:o,depth:r+1,juanMeta:s,matchStates:i},b))]})]})}function xr({files:t,groups:n,activeFile:o,onSelect:r,juanMeta:s,matchStates:i}){const a=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((c,l)=>e.jsx(yn,{group:c,activeFile:o,onSelect:r,juanMeta:s,matchStates:i},l))}):a.length===0?null:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:a.map(c=>e.jsx(hn,{file:c,isActive:o===c,onSelect:r,meta:s==null?void 0:s[c],matchState:i[c]},c))})}function ur({type:t}){const n=pt[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 fr({section:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=F(),s=ae(),i=fe(),a=y=>{if(!y)return"";const b=r(y);return o?ke(b,o,i):b},[c,l]=f.useState(!1),d=!!t.summary,u=!!t.comment,x=!!t.additional_comment,g=!!(t.content&&t.content.length>60),p=d||u||x||g;f.useEffect(()=>{o&&l(!0)},[o]);const h=!c&&g?t.content.replace(/\n/g," ").slice(0,80)+"…":null;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>p&&l(!c),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:p?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[p&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:c?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[t.book_title?e.jsxs(e.Fragment,{children:["《",a(t.book_title),"》"]}):a(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[gn(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:a(t.author_info||t.author)})]}),!c&&h&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:a(h)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:a(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"#e74c3c"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:s(t.work_id),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),c&&p&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:a(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:a(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(t.additional_comment)})]}),g&&!d&&!u&&!x&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(t.content)})]})]})}function gr({section:t,highlightQuery:n=""}){const{convert:o}=F(),r=fe(),s=l=>{if(!l)return"";const d=o(l);return n?ke(d,n,r):d},[i,a]=f.useState(!1),c=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>c&&a(!i),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[e.jsx(ur,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:s(t.title)}),c&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",transition:"transform 0.15s",transform:i?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),i&&c&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${pt[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:s(t.content)})})]})}function hr({section:t,highlightQuery:n=""}){const{convert:o}=F(),r=fe();if(!t.content&&!t.title)return null;const s=o((t.content||t.title||"").replace(/\n{2,}/g,`
2
+ `)),i=n?ke(s,n,r):s,a=pt[t.type]||"#717171",c=X(t.type)==="序"||X(t.type)==="结语";return e.jsxs("div",{style:{padding:c?"10px 12px":"6px 0",margin:c?"8px 0":void 0,fontSize:"13px",color:"var(--bim-desc-fg, #555)",lineHeight:1.8,whiteSpace:"pre-line",borderLeft:c?`3px solid ${a}40`:void 0,background:c?"var(--bim-bg, #fafafa)":void 0,borderRadius:c?"0 4px 4px 0":void 0,position:"relative"},children:[c&&e.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:a,marginRight:"8px",padding:"1px 5px",border:`1px solid ${a}40`,borderRadius:"2px",background:`${a}08`,verticalAlign:"middle"},children:t.type}),i]})}function br(t,n,o){const[r,s]=f.useState({});return f.useEffect(()=>{var d;if(!n||t.length===0)return;let i=!1;const a=t.filter(u=>{var x;return!((x=o==null?void 0:o.current)!=null&&x.has(u))}),c={};for(const u of t)(d=o==null?void 0:o.current)!=null&&d.has(u)&&(c[u]=o.current.get(u));if(Object.keys(c).length>0&&s(c),a.length===0)return;const l=async u=>{var x;try{if(n.getEntry){const b=await n.getEntry(u);if(b)return{title:b.title,author:b.author}}const g=await n.getItem(u);if(!g)return null;const p=g.title||u,h=g.authors,y=(x=h==null?void 0:h[0])==null?void 0:x.name;return{title:p,author:y}}catch{return null}};return Promise.all(a.map(async u=>{var g;const x=await l(u);return(g=o==null?void 0:o.current)==null||g.set(u,x),[u,x]})).then(u=>{i||s(x=>{const g={...x};for(const[p,h]of u)g[p]=h;return g})}),()=>{i=!0}},[t.join(","),n]),r}function mr({section:t,onNavigate:n,transport:o,workLabelCache:r,highlightQuery:s=""}){const{convert:i}=F(),a=ae(),c=fe(),l=m=>{if(!m)return"";const k=i(m);return s?ke(k,s,c):k},[d,u]=f.useState(!1);f.useEffect(()=>{s&&u(!0)},[s]);const x=t.type,g=cr[x]||"#717171",p=!!t.content,h=t.work_ids||[],y=h.length>1,b=br(y?h:[],o,r),j=p&&!d&&t.content.length>80?t.content.slice(0,80)+"……":null;return e.jsxs("div",{style:{borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",padding:"10px 0"},children:[e.jsxs("div",{onClick:()=>p&&u(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[p&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #aaa)",marginTop:"5px",transition:"transform 0.15s",transform:d?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)",lineHeight:1.6},children:t.header_line?l(t.header_line):l(t.title)}),!d&&j&&e.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:l(j)})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[h.length===1&&n&&e.jsx("a",{href:a(h[0]),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),m.stopPropagation(),n(h[0]))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),y&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",flexShrink:0},children:[h.length,"部作品"]}),e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:g,border:`1px solid ${g}40`,borderRadius:"2px",background:`${g}08`},children:x})]})]}),y&&n&&e.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:h.map(m=>{const k=b[m],_=k?`${i(k.title)}${k.author?`(${i(k.author)})`:""}`:m.slice(0,8)+"…";return e.jsxs("a",{href:a(m),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),n(m))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:m,children:["→",_]},m)})}),d&&p&&e.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${g}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:[e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:l(t.content)}),t.comment&&e.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:"1px solid var(--bim-widget-border, #eee)",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.8,fontStyle:"italic"},children:l(t.comment)})]})]})}function yr({juan:t,searchQuery:n,onNavigate:o,transport:r,workLabelCache:s}){const{convert:i}=F(),a=fe(),c=n.trim(),l=f.useMemo(()=>c?t.sections.filter(x=>dt(x,c,!0,a)):t.sections,[t.sections,c,a]),d=t.sections.filter(x=>X(x.type)==="考证").length,u=l.filter(x=>X(x.type)==="考证").length;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"4px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:i(t.title)}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:c?`${u} / ${d} 條`:`${d} 條`})]}),t.source_url&&e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("a",{href:t.source_url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:"原文來源"})}),e.jsx("div",{children:l.map((x,g)=>e.jsx(mr,{section:x,onNavigate:o,transport:r,workLabelCache:s,highlightQuery:c},g))}),l.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function vr({text:t,highlightQuery:n=""}){const{convert:o}=F(),r=fe(),s=a=>{const c=o(a);return n?ke(c,n,r):c},i=t.split(`
3
+ `);return e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:i.map((a,c)=>{if(a.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:s(a.slice(2))},c);if(a.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:s(a.slice(3))},c);if(a.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:s(a.slice(4))},c);if(!a.trim())return c>0&&!i[c-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},c);const l=a.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:l.map((d,u)=>d.startsWith("**")&&d.endsWith("**")?e.jsx("strong",{children:s(d.slice(2,-2))},u):e.jsx(f.Fragment,{children:s(d)},u))},c)})})}function jr({sections:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=F(),s=ae(),i=fe(),a=d=>{if(!d)return"";const u=r(d);return o?ke(u,o,i):u},c=[];let l=null;for(const d of t)X(d.type)==="类"?(l&&c.push(l),l={category:d.title,categoryContent:d.content||void 0,items:[]}):X(d.type)==="书"?(l||(l={category:"",items:[]}),l.items.push(d)):(X(d.type)==="序"||X(d.type)==="结语")&&(l||(l={category:"",items:[]}),l.items.push(d),X(d.type)==="结语"&&(c.push(l),l=null));return l&&c.push(l),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:c.map((d,u)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[d.category&&e.jsxs("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:[a(d.category),d.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:a(d.categoryContent)})]}),d.items.map((x,g)=>X(x.type)==="序"||X(x.type)==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:a(x.content||"")},g):e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&x.work_id?e.jsx("a",{href:s(x.work_id),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),p.stopPropagation(),n(x.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:r(x.title),children:e.jsx("strong",{children:a(x.title)})}):e.jsx("strong",{children:a(x.title)}),x.content&&a(x.content)]},g))]},u))})}function Sr({juan:t,rawText:n,searchQuery:o,onNavigate:r}){const{convert:s}=F(),i=fe(),[a,c]=f.useState("catalog"),l=o.trim(),d=f.useMemo(()=>l?t.sections.filter(p=>dt(p,l,!1,i)):t.sections,[t.sections,l,i]),u=t.sections.filter(p=>X(p.type)==="书").length,x=t.sections.filter(p=>X(p.type)==="诗").length,g=l?d.filter(p=>X(p.type)==="书"||X(p.type)==="诗").length:null;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"12px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:s(t.title)}),e.jsx("div",{style:{display:"flex",gap:"2px",marginLeft:"8px"},children:["catalog","raw"].map(p=>e.jsx("button",{onClick:()=>c(p),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:p==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:a===p?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:a===p?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:p==="catalog"?"目錄":"原文"},p))}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:g!=null?`${g} / ${x>0?`${x} 首`:`${u} 部書`}`:x>0?`${x} 首`:`${u} 部书`})]}),a==="raw"&&(n?e.jsx(vr,{text:n,highlightQuery:l}):e.jsx(jr,{sections:t.sections,onNavigate:r,highlightQuery:l})),a==="catalog"&&d.map((p,h)=>X(p.type)==="书"||X(p.type)==="诗"?e.jsx(fr,{section:p,onNavigate:r,highlightQuery:l},h):X(p.type)==="类"?e.jsx(gr,{section:p,highlightQuery:l},h):e.jsx(hr,{section:p,highlightQuery:l},h)),a==="catalog"&&d.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function vn(t){return t.juan_files&&t.juan_files.length>0?t.juan_files:t.files&&t.files.length>0?t.files.map(n=>n.filename):[]}function It(t){const n=vn(t);return n.length>0?n[0]:null}function kr(t){const{workId:n,transport:o,files:r,activeFile:s,activeJuan:i,activeRawText:a,query:c,isKaozhen:l}=t,d=fe(),u=f.useRef(new Map),[x,g]=f.useState({});f.useEffect(()=>{s&&i&&u.current.set(s,{juan:i,rawText:a})},[s,i,a]),f.useEffect(()=>{u.current.clear(),g({})},[n]);const p=f.useCallback((h,y)=>{let b=0;if(h.juan)for(const j of h.juan.sections)dt(j,y,l,d)&&b++;return b===0&&h.rawText&&ar(h.rawText,y,d)&&(b=1),b},[l,d]);return f.useEffect(()=>{const h=c.trim();if(!h){g({});return}if(!n||!(o!=null&&o.getCollatedJuan)||r.length===0)return;let y=!1;const b={},j=[];for(const w of r){const S=u.current.get(w);S?b[w]=p(S,h):(b[w]="loading",j.push(w))}g(b);const m=8;let k=0;const _=async()=>{var w;for(;k<j.length;){if(y)return;const S=k++,z=j[S];try{const[E,I]=await Promise.all([o.getCollatedJuan(n,z),((w=o.getCollatedJuanText)==null?void 0:w.call(o,n,z))??Promise.resolve(null)]),C={juan:E,rawText:I};if(u.current.set(z,C),y)return;g(B=>({...B,[z]:p(C,h)}))}catch{if(y)return;g(E=>({...E,[z]:0}))}}},v=Array.from({length:Math.min(m,j.length)},()=>_());return Promise.all(v),()=>{y=!0}},[c,n,o,r.join(","),p,d]),{matchStates:x}}const jn=({index:t,workId:n,transport:o,onNavigate:r,activeJuan:s,onJuanChange:i,className:a,style:c})=>{const[l,d]=f.useState(null),[u,x]=f.useState(!1),[g,p]=f.useState(null),[h,y]=f.useState(null),[b,j]=f.useState(null),[m,k]=f.useState(!1),[_,v]=f.useState(null),[w,S]=f.useState(""),z=f.useRef(new Map),E=s??h,I=f.useCallback(L=>{y(L),i==null||i(L)},[i]),C=t||l;f.useEffect(()=>{t&&(x(!1),p(null))},[t]),f.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollatedEditionIndex))return;let L=!1;return x(!0),p(null),o.getCollatedEditionIndex(n).then(T=>{if(!L)if(!T)p("未找到整理本数据");else{d(T);const O=It(T);!s&&O&&I(O)}}).catch(T=>{L||p(T instanceof Error?T.message:"加载失败")}).finally(()=>{L||x(!1)}),()=>{L=!0}},[t,n,o,s,I]),f.useEffect(()=>{const L=t||l;if(L&&!E){const T=It(L);T&&I(T)}},[t,l,E,I]);const B=n||(C==null?void 0:C.work_id),H=f.useCallback(async L=>{var T;if(!(!B||!(o!=null&&o.getCollatedJuan))){k(!0),j(null),v(null);try{const[O,W]=await Promise.all([o.getCollatedJuan(B,L),((T=o.getCollatedJuanText)==null?void 0:T.call(o,B,L))??Promise.resolve(null)]);j(O),v(W)}catch{j(null),v(null)}finally{k(!1)}}},[B,o]);f.useEffect(()=>{E&&H(E)},[E,H]);const M=L=>{I(L)};if(u)return e.jsx("div",{className:a,style:{...c,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(g)return e.jsx("div",{className:a,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g});if(!C)return null;const $=C.type==="kaozhen",D=vn(C);return e.jsx(wr,{className:a,style:c,index:C,allFiles:D,isKaozhen:$,effectiveWorkId:B,transport:o,activeFile:E,handleSelectFile:M,juanData:b,juanRawText:_,juanLoading:m,searchQuery:w,setSearchQuery:S,onNavigate:r,workLabelCacheRef:z})},wr=({className:t,style:n,index:o,allFiles:r,isKaozhen:s,effectiveWorkId:i,transport:a,activeFile:c,handleSelectFile:l,juanData:d,juanRawText:u,juanLoading:x,searchQuery:g,setSearchQuery:p,onNavigate:h,workLabelCacheRef:y})=>{const{matchStates:b}=kr({workId:i,transport:a,files:r,activeFile:c,activeJuan:d,activeRawText:u,query:g,isKaozhen:s});return e.jsxs("div",{className:t,style:n,children:[e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("input",{type:"text",placeholder:s?"搜索全部章节(条目、考证内容)...":"搜索全部册(书名、作者、正文)...",value:g,onChange:j=>p(j.target.value),style:{width:"100%",maxWidth:"420px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}})}),e.jsxs("div",{style:{marginBottom:"16px",display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsx("div",{children:s?e.jsxs(e.Fragment,{children:[o.target_source&&e.jsxs("span",{children:["考證對象:",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.target_source})," "]}),"共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.length})," 章"]}):e.jsxs("span",{children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.total_juan})," 卷"]})}),o.text_quality&&(()=>{const j=nr(o.text_quality.grade);return j?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(tr,{content:Xn[j],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:Zn[j],cursor:"help"},children:tn[j]})}),o.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",o.text_quality.source_note]})]}):null})()]}),e.jsx(xr,{files:r,groups:o.juan_groups,activeFile:c,onSelect:l,juanMeta:o.juan_metadata,matchStates:b}),x?e.jsx(ye,{}):d?s?e.jsx(yr,{juan:d,searchQuery:g,onNavigate:h,transport:a,workLabelCache:y}):e.jsx(Sr,{juan:d,rawText:u,searchQuery:g,onNavigate:h}):c?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null,o.references&&o.references.length>0&&e.jsxs("div",{style:{marginTop:"32px",paddingTop:"16px",borderTop:"1px solid var(--bim-widget-border, #eee)"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #aaa)",marginBottom:"8px",letterSpacing:"2px"},children:"參考文獻"}),o.references.map((j,m)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[m+1,". "]}),j.url?e.jsx("a",{href:j.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:j.title}):e.jsx("span",{children:j.title}),j.author&&e.jsxs("span",{children:[",",j.author]}),j.note&&e.jsxs("span",{children:["。",j.note]})]},m))]})]})},_r={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},Cr={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function zr(t){try{const n=new Date(t),o=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${o(n.getMonth()+1)}-${o(n.getDate())} ${o(n.getHours())}:${o(n.getMinutes())}`}catch{return t}}const Sn=({items:t,loading:n})=>{const o=ae();return n?e.jsx(ye,{}):t.length===0?e.jsx("div",{style:Ir,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const s=_r[r.type],i=Cr[r.status];return e.jsxs("div",{style:Tr,children:[e.jsxs("div",{style:Rr,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...Tt,background:s.color},children:s.label}),e.jsx("span",{style:{...Tt,background:i.color},children:i.label})]}),e.jsx("span",{style:Er,children:zr(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&e.jsxs("div",{style:Lr,children:[r.resourceId&&e.jsx("a",{href:o(r.resourceId),style:Rt,children:r.resourceId}),r.pageUrl&&!r.resourceId&&e.jsx("a",{href:r.pageUrl,style:Rt,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:Br,children:r.content}),r.reply&&e.jsxs("div",{style:Wr,children:[e.jsx("div",{style:$r,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})})},Ir={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},Tr={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},Rr={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Tt={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},Er={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},Lr={fontSize:"12px",marginBottom:"6px"},Rt={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},Br={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},Wr={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},$r={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},it=({transport:t,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:s,feedbackApiUrl:i})=>{const a=A(),[c,l]=f.useState(null),[d,u]=f.useState([]),[x,g]=f.useState("recommend"),[p,h]=f.useState([]),[y,b]=f.useState(!1),j=r??x,m=$=>{g($),s==null||s($)},[k,_]=f.useState(!0),[v,w]=f.useState(null),[S,z]=f.useState(null),[E,I]=f.useState(null);f.useEffect(()=>{let $=!1;if(t.getCounts)return t.getCounts().then(D=>{$||l({works:D.works,books:D.books,collections:D.collections})}).catch(()=>{}),()=>{$=!0}},[t]),f.useEffect(()=>{let $=!1;return(async()=>{if(o)return o;if(t.getRecommended)try{const L=await t.getRecommended();if(L!=null&&L.groups)return L.groups.flatMap(T=>T.items.map(O=>({...O,group:T.name})))}catch{}return[]})().then(async L=>{if($)return;const T=L.filter(W=>W.id);if(T.length===0){_(!1);return}const O=await Promise.all(T.map(async W=>{if(W.type)return{id:W.id,title:W.title,type:W.type,author:W.author,dynasty:W.dynasty,role:W.role,edition:W.edition,has_text:W.has_text,has_image:W.has_image,has_collated:W.has_collated,subtype:W.subtype,primary_name:W.primary_name,group:W.group,fallbackDescription:W.description};try{let U=null;if(t.getEntry)U=await t.getEntry(W.id);else{const G=await t.getItem(W.id);G&&(U={id:W.id,title:G.title||W.id,type:G.type||"work"})}if(U)return{...U,group:W.group,fallbackDescription:W.description}}catch{}return{id:W.id,title:W.title,type:N.extractType(W.id),group:W.group,fallbackDescription:W.description}}));$||(u(O.filter(W=>W!==null)),_(!1))}),()=>{$=!0}},[t,o]);const C=f.useRef(!1),B=f.useRef(!1),H=f.useRef(!1);f.useEffect(()=>{if(j!=="catalog"||C.current)return;const $=t.getCatalogProgress??t.getResourceProgress;if(!$)return;C.current=!0;let D=!1;return $.call(t).then(L=>{D||w(L)}).catch(()=>{C.current=!1}),()=>{D=!0}},[t,j]),f.useEffect(()=>{if(j!=="collection"||B.current||!t.getCollectionProgress)return;B.current=!0;let $=!1;return t.getCollectionProgress().then(D=>{$||z(D)}).catch(()=>{B.current=!1}),()=>{$=!0}},[t,j]),f.useEffect(()=>{if(j!=="site"||H.current||!t.getSiteProgress)return;H.current=!0;let $=!1;return t.getSiteProgress().then(D=>{$||I(D)}).catch(()=>{H.current=!1}),()=>{$=!0}},[t,j]),f.useEffect(()=>{if(!i||j!=="feedback")return;let $=!1;return b(!0),fetch(i).then(D=>D.json()).then(D=>{!$&&D.success&&h(D.items||[])}).catch(()=>{}).finally(()=>{$||b(!1)}),()=>{$=!0}},[i,j]);const M=$=>{switch($){case"work":return"✍️";case"book":return"📖";case"collection":return"📚";case"entity":return"👤";default:return""}};return e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:"var(--bim-fg, #333)"},children:e.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"16px"},children:[e.jsx(Te,{label:a.home.recommendTab,active:j==="recommend",onClick:()=>m("recommend")}),e.jsx(Te,{label:a.home.catalogTab,active:j==="catalog",onClick:()=>m("catalog")}),e.jsx(Te,{label:a.home.collectionTab,active:j==="collection",onClick:()=>m("collection")}),e.jsx(Te,{label:a.home.siteTab,active:j==="site",onClick:()=>m("site")}),i&&e.jsx(Te,{label:a.home.feedbackTab,active:j==="feedback",onClick:()=>m("feedback")})]}),j==="recommend"&&e.jsx(Pr,{recommended:d,loading:k,onNavigate:n,getIcon:M,t:a}),j==="catalog"&&e.jsx(Et,{progress:v,t:a,onNavigate:n}),j==="collection"&&e.jsx(Et,{progress:S,t:a,onNavigate:n}),j==="site"&&e.jsx(Mr,{progress:E,t:a,totalWorks:(c==null?void 0:c.works)??0}),j==="feedback"&&i&&e.jsx(Sn,{items:p,loading:y})]})})},Te=({label:t,active:n,onClick:o})=>e.jsx("button",{onClick:o,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:n?"var(--bim-primary, #2563eb)":"var(--bim-desc-fg, #717171)",background:"none",border:"none",borderBottom:n?"2px solid var(--bim-primary, #2563eb)":"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:t}),Pr=({recommended:t,loading:n,onNavigate:o,getIcon:r,t:s})=>{const i=ae();if(n)return e.jsx(ye,{});if(t.length===0)return null;const a=new Map;for(const c of t){const l=c.group||s.home.recommendedBrowse;a.has(l)||a.set(l,[]),a.get(l).push(c)}return e.jsx(e.Fragment,{children:Array.from(a.entries()).map(([c,l])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:c}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:l.map(d=>{const u=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return e.jsxs("a",{href:i(d.id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),o==null||o(d.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)",textDecoration:"none",color:"inherit"},children:[e.jsx("span",{style:{fontSize:"20px"},children:r(d.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:d.edition})]}),u&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},d.id)})})]},c))})},Et=({progress:t,t:n,onNavigate:o})=>{if(!t)return e.jsx(ye,{});const r=[...t.resources].sort((c,l)=>c.priority-l.priority),s=["in_progress","done","todo"],i={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:s.map(c=>{const l=r.filter(d=>d.status===c);return l.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:a[c]}}),i[c]," (",l.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(d=>e.jsx(Ar,{item:d,t:n,statusColor:a[c],onNavigate:o},d.id))})]},c)})})},Ar=({item:t,t:n,statusColor:o,onNavigate:r})=>{const s=ae(),i=t.total>0?Math.round(t.imported/t.total*100):0,a=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const c=t.edition?`${t.name}·${t.edition}`:t.name,l=t.collection_id||t.work_id;return l&&r?e.jsx("a",{href:s(l),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(l))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:c}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:c}):c})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:a})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?Ae(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:o,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},Mr=({progress:t,t:n,totalWorks:o})=>{if(!t)return e.jsx(ye,{});const r=[...t.resources].sort((l,d)=>l.priority-d.priority),s=r.filter(l=>l.imported>0),i=r.filter(l=>l.imported===0),a=s.reduce((l,d)=>Math.max(l,d.imported),0),c=o>0?Math.round(a/o*100):0;return e.jsxs("div",{children:[o>0&&e.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)",fontSize:"13px",color:"var(--bim-fg, #333)"},children:[n.home.siteCoverage,": ",e.jsx("strong",{children:a.toLocaleString()})," / ",o.toLocaleString()," ",n.indexType.work," (",c,"%)"]}),s.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"#10b981"}}),n.home.statusInProgress," (",s.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(l=>e.jsx(Lt,{item:l,t:n,totalWorks:o},l.id))})]}),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:"#9ca3af"}}),n.home.statusTodo," (",i.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:i.map(l=>e.jsx(Lt,{item:l,t:n,totalWorks:o},l.id))})]})]})},Lt=({item:t,t:n,totalWorks:o})=>{const r=o>0?Math.round(t.imported/o*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),t.imported>0&&o>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:"#10b981",transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},Bt="(max-width: 768px)";function Fr(){const[t,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(Bt).matches);return f.useEffect(()=>{const o=window.matchMedia(Bt),r=s=>n(s.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),t}const Hr=({transport:t,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:s})=>{var D;const i=A(),{convert:a}=F(),c=Fr(),[l,d]=f.useState(null),[u,x]=f.useState(null),[g,p]=f.useState(!1),[h,y]=f.useState("detail"),[b,j]=f.useState([]),[m,k]=f.useState(!1),[_,v]=f.useState(null),[w,S]=f.useState(!1),z=f.useCallback(async L=>{if(!t.getCollatedEditionIndex){v(null);return}S(!0);try{const T=await t.getCollatedEditionIndex(L);v(T)}catch{v(null)}finally{S(!1)}},[t]),E=f.useCallback(async L=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){j([]);return}k(!0);try{if(t.getCollectionCatalogs){const T=await t.getCollectionCatalogs(L);j(T||[])}else if(t.getCollectionCatalog){const T=await t.getCollectionCatalog(L);j(T?[{resource_id:"",data:T}]:[])}}catch{j([])}finally{k(!1)}},[t]),I=f.useCallback(async L=>{if(o){o(L);return}d(L),x(null),j([]),v(null),y("detail"),p(!0);try{const T=await t.getItem(L.id);T&&(x(T),T.type==="collection"?E(L.id):T.type==="work"&&T.has_collated&&z(L.id))}catch(T){console.error("加载详情失败:",T)}finally{p(!1)}},[t,o,E,z]),C=f.useCallback(async L=>{x(null),j([]),v(null),y("detail"),p(!0);try{const T=await t.getItem(L);T&&(x(T),d({id:L,title:T.title||L,type:T.type||"book"}),T.type==="collection"?E(L):T.type==="work"&&T.has_collated&&z(L))}catch(T){console.error("导航失败:",T)}finally{p(!1)}},[t,E,z]),B=(u==null?void 0:u.type)==="collection"&&(b.length>0||m)||(u==null?void 0:u.type)==="work"&&(_||w),H=c&&(g||u),M=f.useCallback(()=>{d(null),x(null),j([]),v(null),y("detail")},[]),$=e.jsx(e.Fragment,{children:g?e.jsx(ye,{}):u?e.jsxs(e.Fragment,{children:[(B||s)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:c?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:c?"auto":void 0},children:[B&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>y("detail"),style:Oe(h==="detail"),children:i.detailTab.basicInfo}),u.type==="collection"&&m&&b.length===0&&e.jsxs("button",{onClick:()=>{},style:Oe(!1),children:[i.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&b.map(L=>e.jsx("button",{onClick:()=>y(`catalog:${L.resource_id}`),style:Oe(h===`catalog:${L.resource_id}`),children:L.short_name?`${a(L.short_name)}${i.detailTab.catalogSuffix}`:i.detailTab.collectionCatalog},L.resource_id)),u.type==="work"&&(_||w)&&e.jsxs("button",{onClick:()=>y("collated"),style:Oe(h==="collated"),children:[i.detailTab.collatedEdition,w&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),e.jsx("div",{style:{padding:c?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:h==="detail"?e.jsx(at,{data:u,transport:t,onNavigate:C}):h.startsWith("catalog:")?e.jsx(fn,{data:(D=b.find(L=>`catalog:${L.resource_id}`===h))==null?void 0:D.data,onNavigate:C}):h==="collated"?e.jsx(jn,{index:_||void 0,workId:u.id,transport:t,onNavigate:C}):null})]}):e.jsx(it,{transport:t,onNavigate:C,recommendedIds:r})});return c?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:H?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",flexShrink:0},children:e.jsxs("button",{onClick:M,style:{padding:"4px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px"},children:["← ",i.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:$})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(ot,{transport:t,onEntryClick:I,hideModeIndicator:n}),!u&&e.jsx(it,{transport:t,onNavigate:C,recommendedIds:r})]})}):e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",flexDirection:"column",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(ot,{transport:t,onEntryClick:I,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:$})]})};function Oe(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 Or=({data:t,onNavigate:n,className:o,style:r})=>{var u;const s=A(),{convert:i}=F(),[a,c]=f.useState(((u=t.divisions[0])==null?void 0:u.name)??null),[l,d]=f.useState(null);return e.jsxs("div",{className:o,style:r,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:i(t.title)}),t.stats&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"16px"},children:[t.total_volumes!=null&&e.jsxs("span",{children:[s.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",s.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",s.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",s.unit.bu]}),t.stats.categories!=null&&e.jsxs("span",{children:[t.stats.categories," 類"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.divisions.map(x=>e.jsx(Dr,{division:x,expanded:a===x.name,onToggle:()=>c(a===x.name?null:x.name),expandedCat:l,onCatToggle:g=>d(l===g?null:g),onNavigate:n},x.name))})]})},Dr=({division:t,expanded:n,onToggle:o,expandedCat:r,onCatToggle:s,onNavigate:i})=>{const{convert:a}=F(),c=t.categories.reduce((l,d)=>{const u=d.stats||{zhulu:0,cunmu:0};return l+(u.zhulu||0)+(u.cunmu||0)},0);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)":"var(--bim-bg, #f8f8f8)",cursor:"pointer",fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsx("span",{children:a(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",c," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(l=>{const d=`${t.name}/${l.name}`;return e.jsx(Vr,{category:l,expanded:r===d,onToggle:()=>s(d),onNavigate:i},l.name)})})]})},Vr=({category:t,expanded:n,onToggle:o,onNavigate:r})=>{var l,d,u,x;const{convert:s}=F(),i=((l=t.books)==null?void 0:l.zhulu)||[],a=((d=t.books)==null?void 0:d.cunmu)||[],c=(((u=t.stats)==null?void 0:u.zhulu)||i.length)+(((x=t.stats)==null?void 0:x.cunmu)||a.length);return e.jsxs("div",{children:[e.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?"var(--bim-input-bg, #fff)":"transparent",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsxs("span",{style:{fontWeight:500},children:[s(t.name),t.volumes&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px",fontWeight:400},children:["卷",t.volumes]})]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[c," 部 ",n?"▲":"▼"]})]}),n&&(i.length>0||a.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[i.length>0&&e.jsx(Wt,{label:"著錄",books:i,onNavigate:r}),a.length>0&&e.jsx(Wt,{label:"存目",books:a,onNavigate:r})]})]})},Wt=({label:t,books:n,onNavigate:o})=>{const{convert:r}=F(),s=ae(),[i,a]=f.useState(n.length<=20),c=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:c.map((l,d)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:l.work_id&&o?e.jsx("a",{href:s(l.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),o(l.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(l.title)}):r(l.title)}),l.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(l.volumes)}),l.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(l.author).slice(0,20)})]},d))}),!i&&e.jsxs("button",{onClick:()=>a(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},se=({title:t,onSave:n,onAskAI:o,extraButtons:r,children:s})=>{const i=A();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,o&&e.jsx("button",{onClick:o,style:Nr,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Ur,children:i.action.save})]})]}),s]})},Ur={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Nr={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},re=({label:t,value:n,onChange:o,placeholder:r,disabled:s})=>e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},children:t}),e.jsx("input",{type:"text",value:n,onChange:i=>o(i.target.value),placeholder:r,disabled:s,style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),me=({value:t,onChange:n,placeholder:o})=>{const r=f.useRef(null);return f.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:r,value:t||"",onChange:s=>n(s.target.value),placeholder:o,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},Ne=({children:t,color:n,style:o})=>e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||"var(--bim-primary-soft, rgba(0,120,212,0.15))",color:n?"#fff":"var(--bim-fg, #333)",...o},children:t});function Gr(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Ve=({value:t,onChange:n,label:o})=>{const[r,s]=f.useState(!1),i=f.useRef(null),a=Gr(t||"");return f.useEffect(()=>{r&&i.current&&i.current.focus()},[r]),!r&&a?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:$t,children:o}),e.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",minHeight:"30px"},children:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:"var(--bim-fg, #333)"},children:a.name}),e.jsx(Ne,{children:a.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:$t,children:o}),e.jsx("input",{ref:i,type:"text",value:t||"",onChange:c=>n(c.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},$t={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function Yr(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function Kr(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const kn=({items:t,onChange:n,onOpenEntityPicker:o})=>{const r=A(),[s,i]=f.useState(null),a=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),i(t.length)},c=x=>{n(t.filter((g,p)=>p!==x)),s===x&&i(null)},l=(x,g,p)=>{const h=[...t];h[x]={...h[x],[g]:p},n(h)},d=(x,g)=>{const p=[...t];p[x]={...p[x],type:g,id:"",name:""},n(p),g==="bookID"&&o&&o(h=>{const y=[...t];y[x]={...y[x],id:h.id,name:h.title,type:"bookID"},n(y)})},u=x=>{o&&o(g=>{const p=[...t];p[x]={...p[x],id:g.id,name:g.title,type:"bookID"},n(p)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((x,g)=>e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>i(s===g?null:g),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===g?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:x.name||`${r.editor.sourcePlaceholder} ${g+1}`}),x.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Yr(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:Kr(x.type)}),e.jsx("button",{onClick:p=>{p.stopPropagation(),c(g)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===g&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!x.type&&e.jsxs("div",{children:[e.jsx("label",{style:ue,children:r.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>d(g,"bookID"),style:{...Pt,borderColor:"#4caf50",color:"#4caf50"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>d(g,"url"),style:{...Pt,borderColor:"#2196f3",color:"#2196f3"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),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:ue,children:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const p=[...t];p[g]={...p[g],type:"",id:"",name:""},n(p)},style:At,children:r.action.changeType})]}),x.id&&x.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid #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:()=>u(g),style:{background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-fg, #333)",cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):e.jsxs("button",{onClick:()=>u(g),style:{width:"100%",padding:"14px",border:"2px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),x.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:ue,children:r.label.sourceName}),e.jsx("button",{onClick:()=>{const p=[...t];p[g]={...p[g],type:"",id:"",name:""},n(p)},style:At,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:p=>l(g,"name",p.target.value),placeholder:r.editor.sourceNamePlaceholder,style:ve})]}),e.jsxs("div",{children:[e.jsx("label",{style:ue,children:r.label.urlAddress}),e.jsx("input",{type:"text",value:x.id,onChange:p=>l(g,"id",p.target.value),placeholder:"https://...",style:ve})]})]}),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:{...ue,opacity:.7},children:r.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:ue,children:r.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:p=>l(g,"details",p.target.value),placeholder:r.editor.detailsPlaceholder,style:ve})]}),e.jsxs("div",{children:[e.jsx("label",{style:ue,children:r.label.positionOptional}),e.jsx("input",{type:"text",value:x.position,onChange:p=>l(g,"position",p.target.value),placeholder:"如: 卷三, p.52",style:ve})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:ue,children:r.label.dataVersionOptional}),e.jsx("input",{type:"text",value:x.version,onChange:p=>l(g,"version",p.target.value),placeholder:"如: v1.0, 2024-01",style:ve})]}),e.jsxs("div",{children:[e.jsx("label",{style:ue,children:r.label.processorVersionOptional}),e.jsx("input",{type:"text",value:x.processor_version,onChange:p=>l(g,"processor_version",p.target.value),placeholder:"如: v0.1",style:ve})]})]})]})]})})]},g)),e.jsxs("button",{onClick:a,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:r.action.addSource})]})]})},ue={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},ve={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Pt={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"},At={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function wn(t){if(!t||!t.trim())return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(o=>({id:o.id||"",name:o.name||"",type:o.type||"",details:o.details||"",position:o.position||"",version:o.version||"",processor_version:o.processor_version||""}))}catch{}return[]}function _n(t){return!t||t.length===0?"":JSON.stringify(t)}const Cn=({entityType:t,entityId:n,entityTitle:o,parentWork:r,parentCollection:s,belongsToWork:i,belongsToCollection:a,childWorks:c,childCollections:l,containedBooks:d,siblingBooks:u,onLinkEntity:x,onUnlinkEntity:g,onViewEntity:p,onCreateAndLink:h,onSaveRelations:y})=>{const b=A();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:b.section.relations})]}),y&&e.jsx("button",{onClick:y,style:Jr,children:b.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(Re,{direction:"up",title:b.relation.belongsToWork,entity:i,onView:p,onUnlink:()=>g("workId"),onLink:()=>x("workId","work"),onCreate:()=>h("workId","work",{title:o}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),e.jsx(Re,{direction:"up",title:b.relation.containedInCollection,entity:a,onView:p,onUnlink:()=>g("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>h("collectionId","collection",{title:o}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),i&&u&&u.length>0&&e.jsx(je,{direction:"horizontal",title:`${b.relation.siblingVersions} (${u.length})`,entities:u,onView:p,onAdd:()=>h("siblingBook","book",{workId:i.id}),addLabel:b.relation.addVersionForWork,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(Re,{direction:"up",title:b.relation.parentWork,entity:r,onView:p,onUnlink:()=>g("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>h("parentWorkId","work"),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),c&&c.length>0&&e.jsx(je,{direction:"down",title:`${b.relation.childWorks} (${c.length})`,entities:c,onView:p,onAdd:()=>h("childWork","work",{parentWorkId:n}),addLabel:b.action.addSubWork,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),l&&l.length>0&&e.jsx(je,{direction:"down",title:`${b.relation.collectionImpl} (${l.length})`,entities:l,onView:p,onAdd:()=>h("childCollection","collection",{workId:n}),addLabel:b.action.addCollectionImpl,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),e.jsx(je,{direction:"down",title:`${b.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:p,onAdd:()=>h("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(Re,{direction:"up",title:b.relation.correspondingWork,entity:i,onView:p,onUnlink:()=>g("workId"),onLink:()=>x("workId","work"),onCreate:()=>h("workId","work",{title:o}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),e.jsx(Re,{direction:"up",title:b.relation.parentCollection,entity:s,onView:p,onUnlink:()=>g("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>h("parentCollectionId","collection"),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),e.jsx(je,{direction:"down",title:`${b.relation.childCollections} (${(l==null?void 0:l.length)??0})`,entities:l||[],onView:p,onAdd:()=>h("childCollection","collection",{parentCollectionId:n}),addLabel:b.action.addSubCollection,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),e.jsx(je,{direction:"down",title:`${b.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:p,onAdd:()=>h("childBook","book",{collectionId:n}),addLabel:b.action.addBook,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]})]})]})},Re=({direction:t,title:n,entity:o,onView:r,onUnlink:s,onLink:i,onCreate:a,linkLabel:c,createLabel:l,notLinkedLabel:d,viewLabel:u,unlinkLabel:x})=>{const g=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",p=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:g,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:p}),e.jsx("span",{children:n})]}),o?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:zn(o.type)}),e.jsx("span",{style:{fontWeight:500},children:o.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:o.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(Mt,{onClick:()=>r(o),title:u,children:"👁️"}),e.jsx(Mt,{onClick:s,title:x,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:d}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(st,{onClick:i,children:c}),e.jsx(st,{onClick:a,primary:!0,children:l})]})]})},je=({direction:t,title:n,entities:o,onView:r,onAdd:s,addLabel:i,noneLabel:a,expandMoreLabel:c})=>{const[l,d]=f.useState(!1),u=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",g=l?o:o.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:x}),e.jsx("span",{children:n})]}),o.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[g.map(p=>e.jsxs("div",{onClick:()=>r(p),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:zn(p.type)}),e.jsx("span",{children:p.title})]},p.id)),o.length>5&&!l&&e.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[c," (",o.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:a}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(st,{onClick:s,primary:!0,children:["+ ",i]})})]})},Mt=({onClick:t,title:n,danger:o,children:r})=>e.jsx("button",{onClick:s=>{s.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:o?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:r}),st=({onClick:t,primary:n,children:o})=>e.jsx("button",{onClick:t,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:n?"var(--bim-primary, #0078d4)":"transparent",color:n?"var(--bim-primary-fg, #fff)":"inherit",cursor:"pointer"},children:o});function zn(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Jr={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"},In=({isOpen:t,entityType:n,title:o,onSelect:r,onCancel:s,onCreate:i,searchResults:a,onSearch:c,isLoading:l,excludeId:d})=>{const[u,x]=f.useState(""),g=d?a.filter(b=>b.id!==d):a;f.useEffect(()=>{t&&(x(""),c(""))},[t]);const p=b=>{x(b),c(b)};if(!t)return null;const h=n==="work"?"作品":n==="book"?"书籍":"丛编",y=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:qr,children:e.jsxs("div",{style:Xr,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:o}),e.jsx("button",{onClick:s,style:Zr,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:u,onChange:b=>p(b.target.value),placeholder:`搜索${h}名称或 ID...`,autoFocus:!0,style:Qr})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:l?e.jsx("div",{style:Qe,children:"搜索中..."}):g.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:g.map(b=>e.jsxs("div",{onClick:()=>r(b),style:ei,children:[e.jsx("span",{style:{fontSize:"16px"},children:y}),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))}):u?e.jsxs("div",{style:Qe,children:["未找到匹配的",h]}):e.jsxs("div",{style:Qe,children:["输入关键词搜索",h]})}),e.jsxs("div",{style:{padding:"12px 16px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsxs("button",{onClick:i,style:ti,children:["创建新",h,"并关联"]})]})]})})},qr={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},Xr={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Zr={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Qr={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"},ei={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Qe={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},ti={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Ft={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},ni={work:"📜",book:"📖",collection:"📚",entity:"👤"},Tn=({isOpen:t,entityType:n,relationField:o,inheritData:r,onConfirm:s,onCancel:i})=>{const[a,c]=f.useState(""),l=f.useRef(null);f.useEffect(()=>{t&&(c((r==null?void 0:r.title)||""),setTimeout(()=>{var g,p;(g=l.current)==null||g.focus(),(p=l.current)==null||p.select()},100))},[t,r==null?void 0:r.title]);const d=g=>{g.key==="Enter"&&a.trim()?u():g.key==="Escape"&&i()},u=()=>{a.trim()&&s(a.trim(),{...r,title:a.trim()})};if(!t)return null;const x=()=>{switch(o){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${Ft[n]}`}};return e.jsx("div",{style:oi,onClick:g=>{g.target===g.currentTarget&&i()},children:e.jsxs("div",{style:ri,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:ni[n]}),e.jsx("span",{children:x()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:l,type:"text",value:a,onChange:g=>c(g.target.value),onKeyDown:d,placeholder:`请输入${Ft[n]}名称...`,style:ii})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-input-bg, #fff)",padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&e.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:i,style:si,children:"取消"}),e.jsx("button",{onClick:u,disabled:!a.trim(),style:{...li,opacity:a.trim()?1:.6,cursor:a.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},oi={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},ri={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},ii={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"},si={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},li={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function ai(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Rn(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function ci(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const En=({isOpen:t,title:n,filterType:o="all",recentEntities:r=[],excludeId:s,showCreateButton:i=!1,createButtonText:a,onSelect:c,onCancel:l,onCreate:d,onSearch:u})=>{const[x,g]=f.useState(""),[p,h]=f.useState([]),[y,b]=f.useState(!1),[j,m]=f.useState("recent");f.useEffect(()=>{t&&(g(""),h([]),m(r.length>0?"recent":"search"))},[t,r.length]),f.useEffect(()=>{if(!x.trim()){h([]);return}const z=setTimeout(async()=>{b(!0);try{h(await u(x,o))}catch{h([])}finally{b(!1)}},300);return()=>clearTimeout(z)},[x,o,u]);const k=f.useCallback(z=>{g(z.target.value),z.target.value.trim()&&m("search")},[]),_=f.useCallback(z=>s?z.filter(E=>E.id!==s):z,[s]);if(!t)return null;const v=n||(o==="all"?"选择实体":`选择${Rn(o)}`),w=_(r),S=_(p);return e.jsx("div",{style:pi,children:e.jsxs("div",{style:xi,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:v}),e.jsx("button",{onClick:l,style:ui,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:k,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:fi}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),y&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),w.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(Ht,{active:j==="recent",onClick:()=>m("recent"),children:["最近使用 (",w.length,")"]}),e.jsxs(Ht,{active:j==="search",onClick:()=>m("search"),children:["搜索结果 ",S.length>0&&`(${S.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:j==="recent"&&w.length>0?e.jsx(Ot,{entities:w,onSelect:c}):x.trim()?y?e.jsx(et,{message:"搜索中..."}):S.length>0?e.jsx(Ot,{entities:S,onSelect:c}):e.jsx(et,{message:"未找到匹配的结果"}):e.jsx(et,{message:"输入关键词开始搜索"})}),i&&d&&e.jsxs("div",{style:{padding:"12px 20px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsx("button",{onClick:d,style:gi,children:a||"创建新实体"})]})]})})},Ht=({active:t,onClick:n,children:o})=>e.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-fg, #333)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",fontWeight:t?600:400,marginBottom:"-1px"},children:o}),Ot=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(o=>e.jsx(di,{entity:o,onClick:()=>n(o)},o.id))}),di=({entity:t,onClick:n})=>{const[o,r]=f.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:o?"var(--bim-primary-soft, rgba(0,120,212,0.15))":"var(--bim-primary-soft, rgba(0,120,212,0.05))",transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:ai(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:ci(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:Rn(t.type)})]})},et=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),pi={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},xi={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},ui={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},fi={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"},gi={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},hi={work:"#4caf50",collection:"#2196f3",book:"#ff9800",entity:"#9c27b0"},bi={work:"📜",collection:"📚",book:"📖",entity:"👤"},Ln=({data:t,onChange:n,onSave:o,transport:r,onNavigate:s,showDelete:i,onDelete:a,onAskAI:c,renderSectionActions:l,onDownloadResource:d,downloadStatuses:u,relations:x,onRelationsChange:g})=>{var ee;const p=A(),[h,y]=f.useState(!1),[b,j]=f.useState("work"),[m,k]=f.useState(""),[_,v]=f.useState(""),[w,S]=f.useState([]),[z,E]=f.useState(!1),[I,C]=f.useState(!1),[B,H]=f.useState("work"),[M,$]=f.useState(""),[D,L]=f.useState(),[T,O]=f.useState(!1),[W,U]=f.useState(null),[G,Z]=f.useState([]);f.useRef(null);const ne=t.type,he=ne==="work",ge=ne==="collection",Q=ne==="book",q=f.useCallback((R,V)=>{n({...t,[R]:V})},[t,n]),Ye=f.useCallback((R,V)=>{k(R),j(V),v(p.editor.selectToLink+p.indexType[V]),S([]),y(!0)},[p]),Ke=f.useCallback(R=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,R)},[r,t.id]),we=f.useCallback(R=>{s==null||s(R.id,R.type)},[s]),_e=f.useCallback((R,V,oe)=>{const ce={...oe,author:(oe==null?void 0:oe.author)||t.author,dynasty:(oe==null?void 0:oe.dynasty)||t.dynasty};H(V),$(R),L(ce),C(!0)},[t.author,t.dynasty]),Je=f.useCallback((R,V)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,M,{type:B,title:R,inheritData:V}),C(!1)},[r,t.id,M,B]),Me=f.useCallback(R=>{if(!R.trim()){S([]);return}E(!0),r!=null&&r.searchEntities&&r.searchEntities(R,b).then(V=>{S(V),E(!1)}).catch(()=>{S([]),E(!1)})},[r,b]),qe=f.useCallback(R=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,m,R.id),y(!1)},[r,t.id,m]),P=f.useCallback(()=>{o()},[o]),J=f.useCallback(R=>{U(()=>R),O(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(Z).catch(()=>{})},[r]),Y=f.useCallback((R,V)=>r!=null&&r.searchEntities?r.searchEntities(R,V==="all"?void 0:V):Promise.resolve([]),[r]),K=f.useCallback(R=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(R),Z(V=>[R,...V.filter(oe=>oe.id!==R.id)].slice(0,10)),W==null||W(R),O(!1),U(null)},[r,W]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:bi[ne]}),e.jsx("span",{children:t.title||p.editor.untitled}),e.jsx(Ne,{children:t.id}),e.jsx(Ne,{color:hi[ne],children:p.indexType[ne]})]})}),e.jsx(se,{title:p.section.basicInfo,onSave:o,onAskAI:c?()=>c("基本信息"):void 0,extraButtons:l==null?void 0:l("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(Ve,{label:he?p.editor.workTitle:ge?p.editor.collectionTitle:p.editor.bookTitle,value:t.title,onChange:R=>q("title",R)}),Q&&e.jsx(Ve,{label:p.editor.belongsToWork,value:t.workName||"",onChange:R=>q("workName",R)}),e.jsx(re,{label:p.editor.authorLabel,value:t.author||"",onChange:R=>q("author",R)}),e.jsx(re,{label:p.editor.dynastyLabel,value:t.dynasty||"",onChange:R=>q("dynasty",R)}),(Q||ge)&&e.jsx(Ve,{label:p.editor.containedIn,value:t.collection||"",onChange:R=>q("collection",R)}),(Q||ge)&&e.jsx(re,{label:p.editor.holderLabel,value:t.holder||"",onChange:R=>q("holder",R)}),(Q||ge)&&e.jsx(re,{label:Q?p.editor.pageLabel:p.editor.volumeLabel,value:t.pages||"",onChange:R=>q("pages",R)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(re,{label:p.editor.firstImageLabel,value:t.firstImage||"",onChange:R=>q("firstImage",R)})})]})}),e.jsx(se,{title:p.section.description,onSave:o,onAskAI:c?()=>c("介绍"):void 0,children:e.jsx(me,{value:t.description||"",onChange:R=>q("description",R),placeholder:p.editor.descriptionPlaceholder})}),(((ee=t.additional_works)==null?void 0:ee.length)||0)>0&&e.jsx(se,{title:p.section.additionalWorks,onSave:o,children:e.jsx(mi,{items:t.additional_works||[],onChange:R=>q("additional_works",R)})}),e.jsx(se,{title:p.section.indexedBy,onSave:o,onAskAI:c?()=>c("收录于"):void 0,children:e.jsx(yi,{items:t.indexed_by||[],onChange:R=>q("indexed_by",R)})}),e.jsx(se,{title:p.section.emendatedBy,onSave:o,onAskAI:c?()=>c("考证"):void 0,children:e.jsx(vi,{items:t.emendated_by||[],onChange:R=>q("emendated_by",R)})}),e.jsx(se,{title:p.section.textResources,onSave:o,onAskAI:c?()=>c("资源"):void 0,children:e.jsx(nt,{items:t.resources||[],onChange:R=>q("resources",R),onDownload:d,downloadStatuses:u,filterType:"text"})}),e.jsx(se,{title:p.section.imageResources,onSave:o,children:e.jsx(nt,{items:t.resources||[],onChange:R=>q("resources",R),onDownload:d,downloadStatuses:u,filterType:"image"})}),e.jsx(se,{title:p.section.sources,onSave:o,onAskAI:c?()=>c("资料来源"):void 0,children:e.jsx(kn,{items:wn(t.sources||""),onChange:R=>q("sources",_n(R)),onOpenEntityPicker:J})}),(Q||ge)&&e.jsx(se,{title:p.section.provenance,onSave:o,onAskAI:c?()=>c("收藏历史"):void 0,children:e.jsx(me,{value:t.provenance||"",onChange:R=>q("provenance",R),placeholder:p.editor.provenancePlaceholder})}),Q&&e.jsx(se,{title:p.section.otherEditions,onSave:o,onAskAI:c?()=>c("其他版本"):void 0,children:e.jsx(me,{value:t.otherEditions||"",onChange:R=>q("otherEditions",R),placeholder:p.editor.otherEditionsPlaceholder})}),e.jsx(Cn,{entityType:ne,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:Ye,onUnlinkEntity:Ke,onViewEntity:we,onCreateAndLink:_e,onSaveRelations:P}),i&&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:p.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:p.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:p.editor.deleteEntity})]}),e.jsx(In,{isOpen:h,entityType:b,title:_,onSelect:qe,onCancel:()=>y(!1),onCreate:()=>{y(!1),_e(m,b)},searchResults:w,onSearch:Me,isLoading:z,excludeId:t.id}),e.jsx(Tn,{isOpen:I,entityType:B,relationField:M,inheritData:D,onConfirm:Je,onCancel:()=>C(!1)}),e.jsx(En,{isOpen:T,title:p.action.selectBookOrWork,filterType:"all",recentEntities:G,excludeId:t.id,onSelect:K,onCancel:()=>{O(!1),U(null)},onSearch:Y})]})};function mi({items:t,onChange:n}){const o=A(),r=(a,c,l)=>{const d=t.map((u,x)=>x===a?{...u,[c]:l}:u);n(d)},s=a=>n(t.filter((c,l)=>l!==a)),i=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((a,c)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(re,{label:o.editor.bookNameLabel,value:a.book_title,onChange:l=>r(c,"book_title",l)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(re,{label:o.label.juanCount,value:a.n_juan!=null?String(a.n_juan):"",onChange:l=>r(c,"n_juan",l&&parseInt(l,10)||void 0)})}),e.jsx("button",{onClick:()=>s(c),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},c)),e.jsx("button",{onClick:i,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:o.action.addAdditionalWork})]})}function Bn({items:t,onChange:n,showMeta:o,addLabel:r}){const s=A(),[i,a]=f.useState(null),c=(u,x,g)=>{const p=t.map((h,y)=>y===u?{...h,[x]:g||void 0}:h);n(p)},l=u=>{n(t.filter((x,g)=>g!==u)),i===u&&a(null)},d=()=>{n([...t,{source:""}]),a(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((u,x)=>{const g=i===x;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>a(g?null:x),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:g?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:u.source_bid}),e.jsx("button",{onClick:p=>{p.stopPropagation(),l(x)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid #ddd",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"#999"},children:"✕"})]}),!g&&o&&(u.title_info||u.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.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(re,{label:s.label.sourceName,value:u.source,onChange:p=>c(x,"source",p)}),e.jsx(re,{label:s.label.sourceBid,value:u.source_bid||"",onChange:p=>c(x,"source_bid",p)})]}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(re,{label:s.label.titleInfo,value:u.title_info||"",onChange:p=>c(x,"title_info",p)}),e.jsx(re,{label:s.label.authorInfo,value:u.author_info||"",onChange:p=>c(x,"author_info",p)})]}),e.jsx(re,{label:s.label.edition,value:u.edition||"",onChange:p=>c(x,"edition",p)})]}),e.jsx(me,{value:u.summary||"",onChange:p=>c(x,"summary",p),placeholder:s.editor.summaryPlaceholder}),e.jsx(me,{value:u.comment||"",onChange:p=>c(x,"comment",p),placeholder:s.editor.commentPlaceholder}),e.jsx(me,{value:u.additional_comment||"",onChange:p=>c(x,"additional_comment",p),placeholder:s.editor.additionalCommentPlaceholder})]})]},x)}),e.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:r})]})}function yi({items:t,onChange:n}){const o=A();return e.jsx(Bn,{items:t,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function vi({items:t,onChange:n}){const o=A();return e.jsx(Bn,{items:t,onChange:n,addLabel:o.action.addEmendatedBy})}function Wn(t){var c,l,d,u,x,g,p;const n=((l=(c=t.authors)==null?void 0:c[0])==null?void 0:l.name)||"",o=((d=t.publication_info)==null?void 0:d.year)||"",r=((u=t.current_location)==null?void 0:u.name)||"",s=(x=t.page_count)!=null&&x.number?String(t.page_count.number):((g=t.page_count)==null?void 0:g.description)||"",i=typeof t.description=="object"&&t.description!==null&&t.description.text||"",a={id:t.id,title:t.title,type:t.type,author:n,dynasty:o,holder:r,pages:s,description:i,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};if(t.type==="work"){const h=t;if(Array.isArray(h.related_works)){const y=h.related_works.find(b=>b.relation==="part_of");y&&(a.parentWorkId=y.id,a.parentWorkName=y.title)}}if(t.type==="book"){const h=t;a.workId=h.work_id,Array.isArray(h.contained_in)&&h.contained_in.length>0&&(a.collectionId=(p=h.contained_in[0])==null?void 0:p.id)}return a}function ji(t){const n={id:t.id,title:t.title,type:t.type,description:t.description?{text:t.description}:void 0,authors:t.author?[{name:t.author}]:void 0,publication_info:t.dynasty?{year:t.dynasty}:void 0,current_location:t.holder?{name:t.holder}:void 0,page_count:t.pages?{number:parseInt(t.pages)||0,description:t.pages}:void 0,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};return t.type==="work"&&t.parentWorkId&&(n.related_works=[{id:t.parentWorkId,title:t.parentWorkName||"",relation:"part_of"}]),t.type==="book"&&(n.work_id=t.workId,t.collectionId&&(n.contained_in=[{id:t.collectionId}])),n}const Si=t=>{const{data:n,id:o,transport:r,mode:s="view",onModeChange:i,onChange:a,onSave:c,onDelete:l,onNavigate:d,renderLink:u,onAskAI:x,renderSectionActions:g,onDownloadResource:p,downloadStatuses:h,relations:y,onRelationsChange:b,headerExtra:j,className:m,style:k}=t;A();const[_,v]=f.useState(s),w=i?s:_;f.useEffect(()=>{s!==_&&v(s)},[s]);const S=f.useCallback(()=>{const M=w==="view"?"edit":"view";i?i(M):v(M)},[w,i]),[z,E]=f.useState(null);f.useEffect(()=>{o&&r&&r.getItem(o).then(M=>{M&&E(M)})},[o,r]);const I=n||z,C=f.useMemo(()=>I?Wn(I):null,[I]),B=i||!n?e.jsx("button",{onClick:S,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:w==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:w==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:w==="view"?"切换到编辑模式":"切换到查看模式",children:w==="view"?"✏️ 编辑":"👁 查看"}):null,H=e.jsxs(e.Fragment,{children:[B,j]});return!I&&!C?e.jsx(ye,{}):w==="view"?e.jsx(at,{data:I,transport:r,onNavigate:d?M=>d(M):void 0,renderLink:u,headerExtra:H,className:m,style:k}):C?e.jsxs("div",{className:m,style:k,children:[H&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:H}),e.jsx(Ln,{data:C,onChange:a||(()=>{}),onSave:c||(()=>{}),transport:r,onNavigate:d,showDelete:!!l,onDelete:l,onAskAI:x,renderSectionActions:g,onDownloadResource:p,downloadStatuses:h,relations:y,onRelationsChange:b})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},Dt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],$n=({isOpen:t,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const[s,i]=f.useState(null),[a,c]=f.useState(""),[l,d]=f.useState("idle"),[u,x]=f.useState(""),g=f.useRef(null);f.useEffect(()=>{t&&(i(null),c(""),d("idle"),x(""))},[t]),f.useEffect(()=>{s&&setTimeout(()=>{var b;return(b=g.current)==null?void 0:b.focus()},100)},[s]),f.useEffect(()=>{if(l==="success"){const b=setTimeout(n,2e3);return()=>clearTimeout(b)}},[l,n]),f.useEffect(()=>{if(!t)return;const b=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[t,n]);const p=async()=>{if(!(!s||!a.trim())){d("submitting"),x("");try{await o({type:s,content:a.trim()}),d("success")}catch(b){d("error"),x(b instanceof Error?b.message:"提交失败,请稍后重试")}}};if(!t)return null;const h=s&&a.trim()&&l!=="submitting",y=Dt.find(b=>b.value===s);return e.jsx("div",{style:ki,onClick:b=>{b.target===b.currentTarget&&n()},children:e.jsxs("div",{style:wi,onClick:b=>b.stopPropagation(),children:[e.jsxs("div",{style:_i,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:Ci,"aria-label":"关闭",children:"✕"})]}),l==="success"?e.jsxs("div",{style:Ei,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&e.jsx("a",{href:r,style:{fontSize:"13px",color:"var(--bim-primary, #2563eb)",marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:Dt.map(b=>e.jsxs("button",{onClick:()=>i(b.value),style:{...zi,...s===b.value?Ii:{}},children:[e.jsx("span",{children:b.icon})," ",b.label]},b.value))}),e.jsx("textarea",{ref:g,value:a,onChange:b=>c(b.target.value),placeholder:(y==null?void 0:y.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||l==="submitting",style:{...Ti,opacity:s?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[a.length," / 2000"]}),l==="error"&&e.jsx("div",{style:Li,children:u}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:p,disabled:!h,style:{...Ri,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:l==="submitting"?"提交中...":"提交反馈"})})]})]})})},ki={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},wi={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)"},_i={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Ci={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},zi={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"},Ii={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Ti={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"},Ri={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Ei={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},Li={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},Bi=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:o})=>{const[r,s]=f.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>s(!0),style:{...Wi,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($n,{isOpen:r,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:o})]})},Wi={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"},Vt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],$i=({onSubmit:t})=>{const[n,o]=f.useState("bug"),[r,s]=f.useState(""),[i,a]=f.useState("idle"),[c,l]=f.useState(""),d=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var p;return(p=d.current)==null?void 0:p.focus()},100)},[n]);const u=async()=>{if(!(!n||!r.trim())){a("submitting"),l("");try{await t({type:n,content:r.trim()}),a("success"),s(""),o("bug")}catch(p){a("error"),l(p instanceof Error?p.message:"提交失败,请稍后重试")}}},x=n&&r.trim()&&i!=="submitting",g=Vt.find(p=>p.value===n);return i==="success"?e.jsx("div",{style:Ut,children:e.jsxs("div",{style:Hi,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>a("idle"),style:Oi,children:"继续提交"})]})}):e.jsxs("div",{style:Ut,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:Vt.map(p=>e.jsxs("button",{onClick:()=>o(p.value),style:{...Pi,...n===p.value?Ai:{}},children:[e.jsx("span",{children:p.icon})," ",p.label]},p.value))}),e.jsx("textarea",{ref:d,value:r,onChange:p=>s(p.target.value),placeholder:(g==null?void 0:g.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:i==="submitting",style:{...Mi}}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[r.length," / 2000"]}),e.jsx("button",{onClick:u,disabled:!x,style:{...Fi,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:i==="submitting"?"提交中...":"提交"})]}),i==="error"&&e.jsx("div",{style:Di,children:c})]})},Ut={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},Pi={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Ai={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Mi={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Fi={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Hi={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Oi={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Di={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"};function Vi(t){var n;return{id:t.id,kind:"hypothetical",label:t.label,year:t.year??((n=t.year_range)==null?void 0:n[0]),year_range:t.year_range,year_uncertain:t.year_uncertain,group:t.group,note:t.note,description:t.description}}function Ui(t,n){if(!t.lineage)return null;const o=t.lineage;return{id:t.id,kind:"book",label:t.title,year:o.year,year_text:o.year_text,year_uncertain:o.year_uncertain,category:o.category,status:o.status,extant_juan:o.extant_juan,group:n[t.id],note:o.note}}function Nt(t,n,o){return{id:`derive:${n.ref}->${t}:${o}`,source:n.ref,target:t,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Ni(t,n,o){const[r,s]=[t,n.book_id].sort();return{id:`sibling:${r}-${s}:${o}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Gi(t,n){var d;if(n==="all")return null;const o=(d=t.collections)==null?void 0:d[n],r=Array.isArray(o==null?void 0:o.groups)&&o.groups.length>0,s=Array.isArray(o==null?void 0:o.book_ids)&&o.book_ids.length>0,i=r||s||!!(o!=null&&o.hypothetical_ids);if(!i&&n==="core"&&Array.isArray(t.core_books)&&t.core_books.length>0)return{books:new Set(t.core_books),hypos:t.core_hypotheticals?new Set(t.core_hypotheticals):null};if(!o||!i)return null;const a=r?new Set(o.groups):null,c=new Set(o.book_ids??[]);if(a&&t.node_groups)for(const[u,x]of Object.entries(t.node_groups))a.has(x)&&c.add(u);let l=null;if(o.hypothetical_ids&&(l=new Set(o.hypothetical_ids)),a){l||(l=new Set);for(const u of t.hypothetical_nodes??[])u.group&&a.has(u.group)&&l.add(u.id)}return{books:c,hypos:l}}function Yi(t,n,o){const r=t.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const i=new Set(r.excluded_books??[]),a=r.node_groups??{},c=Gi(r,o??r.default_collection??"all"),l=c!==null,d=(c==null?void 0:c.books)??null,u=(c==null?void 0:c.hypos)??null,x=new Set,g=new Set;if(l){const _=new Map(n.map(I=>[I.id,I])),v=new Map((r.hypothetical_nodes??[]).map(I=>[I.id,I])),w=I=>{const C=_.get(I);if(C&&C.lineage)return(C.lineage.derived_from??[]).map(H=>H.ref);const B=v.get(I);return B?(B.derived_from??[]).map(H=>H.ref):[]},S=I=>v.has(I)?!u||u.has(I):!d||d.has(I),z=new Set,E=I=>{if(!z.has(I)){z.add(I);for(const C of w(I))i.has(C)||(S(C)||(v.has(C)?g.add(C):_.has(C)&&x.add(C)),E(C))}};for(const I of n)d&&d.has(I.id)&&!i.has(I.id)&&E(I.id);for(const I of r.hypothetical_nodes??[])u&&u.has(I.id)&&E(I.id)}const p=n.filter(_=>!i.has(_.id)).filter(_=>!d||d.has(_.id)||x.has(_.id)).map(_=>{const v=Ui(_,a);return v&&x.has(_.id)&&(v.bridge=!0),v}).filter(_=>_!==null),h=(r.hypothetical_nodes??[]).filter(_=>!u||u.has(_.id)||g.has(_.id)).map(_=>{const v=Vi(_);return g.has(_.id)&&(v.bridge=!0),v}),y=[...p,...h],b=new Set(y.map(_=>_.id)),j=new Set,m=[],k=_=>{j.has(_.id)||!b.has(_.source)||!b.has(_.target)||(j.add(_.id),m.push(_))};for(const _ of n)i.has(_.id)||!_.lineage||d&&!d.has(_.id)&&!x.has(_.id)||((_.lineage.derived_from??[]).forEach((v,w)=>{k(Nt(_.id,v,w))}),(_.lineage.related_to??[]).forEach((v,w)=>{k(Ni(_.id,v,w))}));for(const _ of r.hypothetical_nodes??[])u&&!u.has(_.id)&&!g.has(_.id)||(_.derived_from??[]).forEach((v,w)=>{k(Nt(_.id,v,w))});return{nodes:y,edges:m,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(i)}}function Pn(t,n,o){const r=(t??(n!=null?String(n):"")).trim();return r?!o||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function Ki(t,n){const o=[],r=t.version_graph;if(!r)return o;const s=new Set(n.map(l=>l.id)),i=new Set((r.hypothetical_nodes??[]).map(l=>l.id)),a=new Set([...s,...i]),c=(l,d)=>{a.has(d.ref)||o.push(`${l}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&o.push(`${l}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!i.has(d.ref)&&o.push(`${l}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const l of n){if(!l.lineage)continue;const d=`Book ${l.id} (${l.title})`;(l.lineage.derived_from??[]).forEach(u=>c(d,u)),(l.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||o.push(`${d}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const l of r.hypothetical_nodes??[]){const d=`Hypothetical ${l.id} (${l.label})`;(l.derived_from??[]).forEach(u=>c(d,u))}return o}const An=({graph:t,renderLink:n,className:o,style:r})=>{const{convert:s}=F();if(!t.nodes.length)return e.jsx("div",{style:{...as,...r},className:o,children:"暂无版本图数据"});const i=new Map,a=new Map;for(const g of t.edges)if(g.kind==="derive"){const p=i.get(g.target)??[];p.push(g),i.set(g.target,p)}else for(const p of[g.source,g.target]){const h=a.get(p)??[];h.push(g),a.set(p,h)}const c=new Map(t.nodes.map(g=>[g.id,g])),l=new Map,d=[];for(const g of t.nodes)if(g.group){const p=l.get(g.group)??[];p.push(g),l.set(g.group,p)}else d.push(g);const u=(g,p)=>(g.year??9999)-(p.year??9999);l.forEach(g=>g.sort(u)),d.sort(u);const x=t.groups.filter(g=>l.has(g.id));return e.jsxs("div",{className:o,style:{...qi,...r},children:[t.title&&e.jsx("div",{style:Xi,children:s(t.title)}),t.description&&e.jsx("div",{style:Zi,children:s(t.description)}),x.map(g=>e.jsx(Gt,{label:g.label,color:g.color,nodes:l.get(g.id),incomingMap:i,siblingMap:a,nodeMap:c,renderLink:n},g.id)),d.length>0&&e.jsx(Gt,{label:"其他",nodes:d,incomingMap:i,siblingMap:a,nodeMap:c,renderLink:n})]})},Gt=({label:t,color:n,nodes:o,incomingMap:r,siblingMap:s,nodeMap:i,renderLink:a})=>{const{convert:c}=F();return e.jsxs("div",{style:Qi,children:[e.jsx("div",{style:{...es,borderLeftColor:n??"var(--bim-widget-border, #ddd)"},children:c(t)}),o.map(l=>e.jsx(Ji,{node:l,incoming:r.get(l.id)??[],siblings:s.get(l.id)??[],nodeMap:i,renderLink:a},l.id))]})},Ji=({node:t,incoming:n,siblings:o,nodeMap:r,renderLink:s})=>{const i=t.kind==="hypothetical",a=t.bridge,{convert:c}=F();return e.jsxs("div",{style:{...ts,borderStyle:i||a?"dashed":"solid",opacity:a?.55:t.status==="lost"?.7:1,background:a?"var(--bim-bg-subtle, #fafafa)":void 0},title:a?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsxs("div",{style:ns,children:[e.jsx("span",{style:os,children:i||!s?c(t.label):s(t.id,c(t.label))}),(t.year_text||t.year!=null)&&e.jsx("span",{style:rs,children:Pn(c(t.year_text),t.year,t.year_uncertain)})]}),e.jsxs("div",{style:is,children:[t.category&&e.jsx(Ee,{children:c(t.category)}),t.status==="lost"&&e.jsx(Ee,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(Ee,{tone:"warn",children:"残本"}),i&&e.jsx(Ee,{tone:"info",children:"假想祖本"}),a&&e.jsx(Ee,{tone:"info",children:"桥接"})]}),t.extant_juan&&e.jsxs("div",{style:ss,children:["现存:",c(t.extant_juan)]}),t.note&&e.jsx("div",{style:ls,children:c(t.note)}),n.length>0&&e.jsxs("div",{style:Kt,children:[e.jsx("div",{style:Jt,children:"来源:"}),n.map(l=>{const d=r.get(l.source);return e.jsxs("div",{style:qt(l.confidence),children:[e.jsx("span",{style:Xt,children:c(l.relation)}),e.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,c(d.label)):c((d==null?void 0:d.label)??l.source)}),l.confidence!=="consensus"&&l.confidence!=="certain"&&e.jsx(Yt,{level:l.confidence}),l.evidence&&e.jsxs("span",{style:Zt,children:["· ",c(l.evidence)]})]},l.id)})]}),o.length>0&&e.jsxs("div",{style:Kt,children:[e.jsx("div",{style:Jt,children:"关联:"}),o.map(l=>{const d=l.source===t.id?l.target:l.source,u=r.get(d);return e.jsxs("div",{style:qt(l.confidence),children:[e.jsx("span",{style:Xt,children:c(l.relation)}),e.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&s?s(u.id,c(u.label)):c((u==null?void 0:u.label)??d)}),e.jsx(Yt,{level:l.confidence}),l.evidence&&e.jsxs("span",{style:Zt,children:["· ",c(l.evidence)]})]},l.id)})]})]})},Ee=({children:t,tone:n="default"})=>{const r={default:{bg:"var(--bim-tag-bg, #f0f0f0)",fg:"var(--bim-fg, #555)"},warn:{bg:"var(--bim-warn-bg, #fff3cd)",fg:"var(--bim-warn-fg, #856404)"},info:{bg:"var(--bim-info-bg, #e7f3ff)",fg:"var(--bim-info-fg, #0c5380)"}}[n];return e.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:t})},Yt=({level:t})=>{const o={certain:{label:"确定",color:"#2e7d32"},consensus:{label:"共识",color:"#1976d2"},probable:{label:"推测",color:"#ed6c02"},disputed:{label:"有争议",color:"#c62828"}}[t];return o?e.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${o.color}`,color:o.color,borderRadius:"8px",marginLeft:"4px"},children:o.label}):null},qi={fontSize:"14px",color:"var(--bim-fg, #333)"},Xi={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Zi={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},Qi={marginBottom:"16px"},es={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:"var(--bim-fg, #333)"},ts={border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:"var(--bim-bg, #fff)"},ns={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},os={fontSize:"15px",fontWeight:600},rs={fontSize:"12px",color:"var(--bim-muted, #777)"},is={marginBottom:"6px"},ss={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},ls={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},Kt={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},Jt={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},qt=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),Xt={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},Zt={fontSize:"11px",color:"var(--bim-muted, #888)"},as={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},Mn=({selectedNodeId:t,...n})=>{const[o,r]=f.useState("loading"),[s,i]=f.useState(null);return f.useEffect(()=>{let a=!1;return cs().then(c=>{a||(c?(i(c),r("ready")):r("missing"))}),()=>{a=!0}},[]),o==="loading"?e.jsx("div",{style:Qt,children:"加载图组件中…"}):o==="missing"||!s?e.jsxs("div",{style:Qt,children:[e.jsxs("div",{children:["图组件未安装。请安装 ",e.jsx("code",{children:"@xyflow/react"})," 与 ",e.jsx("code",{children:"@dagrejs/dagre"}),"。"]}),e.jsxs("div",{style:{fontSize:"12px",marginTop:"4px"},children:["或使用 ",e.jsx("code",{children:"VersionLineageList"})," 列表视图。"]})]}):e.jsx(ds,{modules:s,selectedNodeId:t,...n})};async function cs(){try{const[t,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let o=!1;try{await import("@xyflow/react/dist/style.css"),o=!0}catch{o=!1}return{ReactFlow:t.ReactFlow,Background:t.Background,Controls:t.Controls,Handle:t.Handle,Position:t.Position,BaseEdge:t.BaseEdge,EdgeLabelRenderer:t.EdgeLabelRenderer,getSmoothStepPath:t.getSmoothStepPath,dagre:n,cssLoaded:o}}catch{return null}}const ds=({graph:t,renderLink:n,height:o=600,className:r,style:s,selectedNodeId:i,modules:a})=>{const{ReactFlow:c,Background:l,Controls:d,Handle:u,Position:x,BaseEdge:g,EdgeLabelRenderer:p,getSmoothStepPath:h,dagre:y}=a,b=f.useMemo(()=>({lineage:w=>{var D,L,T,O;const S=((D=w.data)==null?void 0:D.stepPosition)??.85,[z,E,I]=h({sourceX:w.sourceX,sourceY:w.sourceY,sourcePosition:w.sourcePosition,targetX:w.targetX,targetY:w.targetY,targetPosition:w.targetPosition,stepPosition:S,borderRadius:5}),C=!!((L=w.data)!=null&&L.isSibling),B=C?E:w.targetX-18,H=C?I:w.targetY-12,M=(T=w.data)==null?void 0:T.labelStyle,$=(O=w.data)==null?void 0:O.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(g,{id:w.id,path:z,style:w.style,markerStart:w.markerStart,markerEnd:w.markerEnd}),w.label&&e.jsx(p,{children:e.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${B}px,${H}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:"var(--bim-bg, #fff)",border:"0.5px solid var(--bim-widget-border, #ddd)",...$,...M},children:w.label})})]})}}),[g,p,h]),j=f.useMemo(()=>({version:w=>{const S=w.data,z=S.kind==="hypothetical",E=S.status==="lost",I=S.isSelected,C=S.bridge,B=S.borderColor??"#888",H=C||z?"dashed":"solid",M=C?.5:E?.6:1;return e.jsxs("div",{style:{background:C?"var(--bim-bg-subtle, #fafafa)":"var(--bim-bg, #fff)",border:`2px ${H} ${I?"#0078d4":B}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:M,boxShadow:I?"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)":z||C?"none":"0 1px 3px rgba(0,0,0,0.1)"},title:C?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsx(u,{type:"target",position:x.Left,style:{visibility:"hidden"}}),e.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:z||!S.renderLink?S.label:S.renderLink(S.bookId,S.label)}),S.description&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.25,marginTop:1},children:S.description}),S.yearText&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.2},children:Pn(S.yearText,void 0,S.uncertain)}),E&&e.jsx("div",{style:{fontSize:9,color:"#c62828",marginTop:1},children:"已佚"}),e.jsx(u,{type:"source",position:x.Right,style:{visibility:"hidden"}})]})}}),[u,x]),{convert:m}=F(),{rfNodes:k,rfEdges:_}=f.useMemo(()=>ps(t,y,n,i,m),[t,y,n,i,m]);return e.jsx("div",{style:{width:"100%",height:o,...s},className:r,children:e.jsxs(c,{nodes:k,edges:_,nodeTypes:j,edgeTypes:b,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[e.jsx(l,{gap:16}),e.jsx(d,{showInteractive:!1})]})})};function ps(t,n,o,r,s=i=>i??""){const c=t.layout==="LR"||!t.layout,l=new n.graphlib.Graph;l.setGraph({rankdir:c?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),l.setDefaultEdgeLabel(()=>({}));const d=new Map(t.groups.map(j=>[j.id,j.color??"#888"]));for(const j of t.nodes)l.setNode(j.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const j of t.edges)j.kind==="derive"&&(u.has(j.relation)||l.setEdge(j.source,j.target));n.layout(l);const x=t.nodes.map(j=>{const m=l.node(j.id),k=r&&j.id===r,_={kind:j.kind,label:s(j.label),bookId:j.kind==="book"?j.id:void 0,yearText:s(j.year_text??us(j)),uncertain:j.year_uncertain,category:j.category,status:j.status,borderColor:j.group?d.get(j.group):void 0,renderLink:o,isSelected:k,description:s(j.description),bridge:j.bridge};return{id:j.id,type:"version",position:{x:m.x-160/2,y:m.y-90/2},data:_,draggable:!1,selected:k}}),g=.78,p=.06,h=new Map;for(const j of t.edges)j.kind==="derive"&&(h.has(j.source)||h.set(j.source,[]),h.get(j.source).push(j));const y=new Map;for(const[j,m]of h){if(m.length<=1)continue;const k=[...m].sort((v,w)=>{var E,I;const S=((E=l.node(v.target))==null?void 0:E.y)??0,z=((I=l.node(w.target))==null?void 0:I.y)??0;return S-z}),_=k.length;k.forEach((v,w)=>{const S=(w-(_-1)/2)*p;y.set(v.id,g+S)})}const b=t.edges.map(j=>xs(j,y.get(j.id),s));return{rfNodes:x,rfEdges:b}}function xs(t,n,o=r=>r??""){const r=t.confidence==="probable"||t.confidence==="disputed",s=t.kind==="sibling",i=fs(t.confidence),a={type:"arrowclosed",color:i,width:14,height:14};return{id:t.id,source:t.source,target:t.target,type:"lineage",label:o(t.relation),data:{labelStyle:{color:"#444"},isSibling:s,stepPosition:n},style:{stroke:i,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:a,markerStart:s?a:void 0,zIndex:1e3}}function us(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function fs(t){switch(t){case"certain":return"#2e7d32";case"consensus":return"#555";case"probable":return"#ed6c02";case"disputed":return"#c62828";default:return"#888"}}const Qt={padding:"40px 20px",textAlign:"center",color:"var(--bim-muted, #888)",fontSize:"13px",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:8,background:"var(--bim-bg, #fafafa)"},gs=({graph:t,defaultMode:n="list",renderLink:o,graphHeight:r=600,selectedNodeId:s,onModeChange:i,collection:a,onCollectionChange:c,collectionsAvailable:l,collectionCounts:d,className:u,style:x})=>{var m;const[g,p]=f.useState(n),h=k=>{p(k),i==null||i(k)},y=(()=>{if(!l)return[];const k=Object.entries(l);return k.length===0||l.all?k:[...k,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),b=!!(c&&y.length>0);if(!t.nodes.length)return e.jsx("div",{style:{padding:24,color:"var(--bim-muted, #999)",textAlign:"center"},children:"暂无版本传承数据"});const j=a?(m=l==null?void 0:l[a])==null?void 0:m.description:void 0;return e.jsxs("div",{className:u,style:x,children:[e.jsxs("div",{style:hs,children:[e.jsx("button",{onClick:()=>h("list"),style:tt(g==="list"),children:"列表"}),e.jsx("button",{onClick:()=>h("graph"),style:tt(g==="graph"),children:"关系图"}),b&&e.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,color:"var(--bim-muted, #888)",marginRight:4},children:"集合:"}),y.map(([k,_])=>{const v=d==null?void 0:d[k];return e.jsxs("button",{onClick:()=>c==null?void 0:c(k),style:tt(a===k),title:_.description,children:[_.label,v!=null?` ${v}`:""]},k)})]})]}),b&&j&&e.jsx("div",{style:{fontSize:12,color:"var(--bim-muted, #888)",marginBottom:8,padding:"4px 8px",background:"var(--bim-bg-subtle, #fafafa)",borderRadius:4},children:j}),g==="list"?e.jsx(An,{graph:t,renderLink:o}):e.jsx(Mn,{graph:t,renderLink:o,height:r,selectedNodeId:s})]})},hs={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},tt=t=>({padding:"4px 12px",fontSize:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:4,background:t?"var(--bim-primary, #0078d4)":"transparent",color:t?"var(--bim-primary-fg, #fff)":"var(--bim-fg, #333)",cursor:"pointer"}),bs=({style:t})=>{const n=f.useContext(Pe);if(!n)return null;const{locale:o,setLocale:r}=n,s=o==="zh-Hant",i=()=>r(s?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:i,title:s?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:"1px solid var(--bim-border, #ddd)",borderRadius:"4px",background:"var(--bim-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",userSelect:"none",...t},children:[e.jsx("span",{style:{color:s?"var(--bim-primary, #0078d4)":void 0,fontWeight:s?700:400},children:"繁"}),e.jsx("span",{style:{opacity:.3},children:"/"}),e.jsx("span",{style:{color:s?void 0:"var(--bim-primary, #0078d4)",fontWeight:s?400:700},children:"简"})]})},ms=({href:t,label:n="在 GitHub 查看本条目源文件",size:o=16,className:r,style:s})=>e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:o+8,height:o+8,borderRadius:4,color:"var(--bim-desc-fg, #717171)",textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:i=>{i.currentTarget.style.color="var(--bim-fg, #1a1a1a)"},onMouseLeave:i=>{i.currentTarget.style.color="var(--bim-desc-fg, #717171)"},children:e.jsx("svg",{width:o,height:o,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M8 0C3.58 0 0 3.58 0 8a8 8 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"})})});exports.BidLink=N.BidLink;exports.BookIndexError=N.BookIndexError;exports.BookIndexManager=N.BookIndexManager;exports.BookIndexStorage=N.BookIndexStorage;exports.BundleStorage=N.BundleStorage;exports.ConfigError=N.ConfigError;exports.GithubStorage=N.GithubStorage;exports.IdGenerationError=N.IdGenerationError;exports.IdGenerator=N.IdGenerator;exports.LocalStorage=N.LocalStorage;exports.MigrationError=N.MigrationError;exports.StorageError=N.StorageError;exports.base36Decode=N.base36Decode;exports.base36Encode=N.base36Encode;exports.base58Decode=N.base58Decode;exports.buildId=N.buildId;exports.cleanName=N.cleanName;exports.decodeId=N.decodeId;exports.decodeIdString=N.decodeIdString;exports.encodeId=N.encodeId;exports.extractIdFromUrl=N.extractIdFromUrl;exports.extractStatus=N.extractStatus;exports.extractType=N.extractType;exports.normalizeCatalog=N.normalizeCatalog;exports.parseId=N.parseId;exports.shardOf=N.shardOf;exports.smartDecode=N.smartDecode;exports.validateResource=N.validateResource;exports.Badge=Ne;exports.BidUrlProvider=Jn;exports.CollatedEdition=jn;exports.CollectionCatalog=fn;exports.CreateEntityDialog=Tn;exports.EmendatedBySection=xn;exports.EntityDetail=ln;exports.EntityPickerDialog=En;exports.EntitySelector=In;exports.FeedbackButton=Bi;exports.FeedbackDialog=$n;exports.FeedbackForm=$i;exports.FeedbackList=Sn;exports.FormInput=re;exports.FormTextArea=me;exports.HomePage=it;exports.IndexApp=Hr;exports.IndexBrowser=ot;exports.IndexDetail=at;exports.IndexEditor=Ln;exports.IndexView=Si;exports.LocaleContext=Pe;exports.LocaleProvider=ro;exports.LocaleToggle=bs;exports.ModeIndicator=rn;exports.RelationPanel=Cn;exports.RepoSourceLink=ms;exports.ResourceEditor=nt;exports.ResourceList=lt;exports.SearchInput=sn;exports.Section=se;exports.SmartBidInput=Ve;exports.SourceEditor=kn;exports.VersionLineageGraph=Mn;exports.VersionLineageList=An;exports.VersionLineageView=gs;exports.WorkCatalog=Or;exports.buildLineageGraph=Yi;exports.detailToEditor=Wn;exports.editorToDetail=ji;exports.formatTemplate=Ae;exports.parseSourceString=wn;exports.stringifySources=_n;exports.useBidUrl=ae;exports.useConvert=F;exports.useT=A;exports.validateLineageGraph=Ki;