lantern-harness 0.1.2 → 0.1.3

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.
Files changed (81) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +6 -6
  3. package/builtin/session/lh-spaces.mjs +102 -0
  4. package/cli/data-root.mjs +80 -3
  5. package/cli/lantern.mjs +2 -1
  6. package/cli/server.mjs +4 -0
  7. package/cli/spaces.mjs +91 -5
  8. package/config/app.defaults.json +4 -2
  9. package/dist/500.html +9 -5
  10. package/dist/_astro/Base.ByB0D4ZA.css +1 -0
  11. package/dist/_astro/{Base.astro_astro_type_script_index_0_lang.lxEwQ1R4.js → Base.astro_astro_type_script_index_0_lang.Cg_8YLVA.js} +1 -1
  12. package/dist/_astro/CaseGenerateApp.BlZyjWEr.js +9 -0
  13. package/dist/_astro/CasesLibrary.C76La3Xj.js +1 -0
  14. package/dist/_astro/ChatApp.gfsPLvan.js +269 -0
  15. package/dist/_astro/ColumnResize.Bs6GL3DJ.js +1 -0
  16. package/dist/_astro/DatePicker.BdwFRioL.js +1 -0
  17. package/dist/_astro/{DocsFileBrowser.DkE26UTR.js → DocsFileBrowser.BxAyrkkw.js} +1 -1
  18. package/dist/_astro/KnowledgeLibrary.Cv488Hot.js +1 -0
  19. package/dist/_astro/NavLibraries.ALZ9e12z.js +1 -0
  20. package/dist/_astro/PluginsPage.B2uxCiHL.js +1 -0
  21. package/dist/_astro/{PluginsPage.BNzpPg2H.js → PluginsPage.DEkyOfQE.js} +2 -2
  22. package/dist/_astro/PromptsLibrary.BUC1OiCH.js +1 -0
  23. package/dist/_astro/RequirementsLibrary.D3olQI63.js +1 -0
  24. package/dist/_astro/{SearchableSelect.DMS2XmXc.js → SearchableSelect.DP74JRWW.js} +1 -1
  25. package/dist/_astro/SelectDropdown.D2i7-lQC.js +1 -0
  26. package/dist/_astro/{SettingsDialog.DC0e7580.js → SettingsDialog.CrMDjSLJ.js} +1 -1
  27. package/dist/_astro/SlideOverDrawer.C7UVeCX1.js +1 -0
  28. package/dist/_astro/SpaceSwitcher.Wf8EPYUx.js +7 -0
  29. package/dist/_astro/TasksBoard.2j7rGT9O.js +1 -0
  30. package/dist/_astro/TemplatesLibrary.J0x7yIcY.js +1 -0
  31. package/dist/_astro/TodosBoard.BugeB7_7.js +1 -0
  32. package/dist/_astro/app-config.vqDkEMS3.js +1 -0
  33. package/dist/_astro/doc-roots.DAJP9Svr.js +1 -0
  34. package/dist/_astro/i18n.9qZsrs3u.js +7 -0
  35. package/dist/_astro/{open-docs-in-session.D3JCwMWB.js → open-docs-in-session.fLwnA5qh.js} +1 -1
  36. package/dist/_astro/plugins.DSUPSizB.js +1 -0
  37. package/dist/_astro/project-docs.Cd2gKPKh.js +1 -0
  38. package/dist/_astro/{settings.BoQ0e0m1.js → settings.CkbipdPI.js} +2 -2
  39. package/dist/_astro/{useListAnim.CnbC_9MC.js → useListAnim.Y3N2budK.js} +1 -1
  40. package/dist/cases/generate/index.html +10 -6
  41. package/dist/cases/library/index.html +10 -6
  42. package/dist/docs/changelog/index.html +69 -6
  43. package/dist/docs/install/index.html +22 -8
  44. package/dist/docs/manual/index.html +74 -11
  45. package/dist/index.html +10 -6
  46. package/dist/knowledge/index.html +10 -6
  47. package/dist/knowledge//345/212/237/350/203/275/346/265/213/350/257/225/347/224/250/344/276/213/347/274/226/345/206/231/350/247/204/350/214/203/index.html +9 -5
  48. package/dist/plugins/index.html +10 -6
  49. package/dist/prompts/index.html +10 -6
  50. package/dist/requirements/index.html +10 -6
  51. package/dist/tasks/index.html +253 -0
  52. package/dist/templates/index.html +10 -6
  53. package/dist/templates//345/212/237/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212//345/212/237/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212/346/250/241/346/235/277/index.html +9 -5
  54. package/dist/templates//346/200/247/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212//346/200/247/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212/346/250/241/346/235/277/index.html +9 -5
  55. package/dist/templates//346/200/247/350/203/275/346/265/213/350/257/225/347/224/250/344/276/213//346/200/247/350/203/275/346/265/213/350/257/225/347/224/250/344/276/213/346/250/241/346/235/277/index.html +9 -5
  56. package/dist/templates//346/216/245/345/217/243/346/265/213/350/257/225/346/212/245/345/221/212//346/216/245/345/217/243/346/265/213/350/257/225/346/212/245/345/221/212/346/250/241/346/235/277/index.html +9 -5
  57. package/dist/templates//350/207/252/345/212/250/345/214/226/346/265/213/350/257/225/347/224/250/344/276/213//350/207/252/345/212/250/345/214/226/346/265/213/350/257/225/347/224/250/344/276/213/346/250/241/346/235/277/index.html +9 -5
  58. package/dist/todos/index.html +253 -0
  59. package/docs//345/205/250/345/261/200/346/217/222/344/273/266.md +2 -2
  60. package/docs//345/256/211/350/243/205/346/211/213/345/206/214.md +10 -8
  61. package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +73 -23
  62. package/lh-plugins/lh-project-docs.mjs +2 -0
  63. package/lh-plugins/lh-tasks.mjs +223 -0
  64. package/lh-plugins/lh-todos.mjs +297 -0
  65. package/lh-plugins/storage-domain.mjs +1 -0
  66. package/package.json +1 -1
  67. package/dist/_astro/Base.B9f_iFAZ.css +0 -1
  68. package/dist/_astro/CaseGenerateApp.Br4uKjun.js +0 -9
  69. package/dist/_astro/CasesLibrary.CpPoVQ4P.js +0 -1
  70. package/dist/_astro/ChatApp.CYSPlSNP.js +0 -258
  71. package/dist/_astro/KnowledgeLibrary.DZinlAWn.js +0 -1
  72. package/dist/_astro/NavLibraries.EayBsg5g.js +0 -1
  73. package/dist/_astro/PluginsPage.CY61glLU.js +0 -1
  74. package/dist/_astro/PromptsLibrary.DfrrCjs7.js +0 -1
  75. package/dist/_astro/RequirementsLibrary.Dt0Gj6Nr.js +0 -1
  76. package/dist/_astro/SelectDropdown.Dc7QaPbH.js +0 -1
  77. package/dist/_astro/SpaceSwitcher.Yy2w8MDF.js +0 -7
  78. package/dist/_astro/TemplatesLibrary.uK-SjK1z.js +0 -1
  79. package/dist/_astro/app-config.CpjKWnzM.js +0 -1
  80. package/dist/_astro/i18n.BVvhz-vw.js +0 -7
  81. package/dist/_astro/plugins.CrpY8UI9.js +0 -1
@@ -1 +1 @@
1
- import{c as e,n as t,t as n}from"./react-dom.CqAxpHMt.js";import{B as r,H as i,U as a,V as o,p as s,r as c,t as l,u}from"./app-config.CpjKWnzM.js";import{t as d}from"./jsx-runtime.BUXbF_vF.js";import{C as f,D as p,E as m,S as h,T as g,_,a as v,c as y,f as b,g as x,h as S,i as C,l as w,m as T,n as E,o as D,p as O,r as k,s as ee,u as A,v as j,w as te,x as M,y as ne}from"./use-text-value.C0IDspmh.js";import{C as N,F as re,H as P,I as ie,J as F,L as ae,M as oe,P as I,U as L,X as se,_ as ce,_t as R,at as le,c as ue,d as de,dt as fe,f as pe,ft as me,g as he,gt as ge,h as _e,ht as z,it as ve,j as ye,l as be,lt as B,m as xe,mt as Se,n as Ce,nt as we,o as Te,ot as Ee,p as De,pt as V,s as Oe,tt as H,v as ke,x as Ae,yt as je,z as U}from"./portal.C3KrUREL.js";import{a as Me,c as Ne,l as Pe,o as Fe,s as Ie,u as Le}from"./listbox.DdDDDJ5Z.js";import{t as Re}from"./use-tree-walker.oRTnhHS-.js";r.map(e=>({value:e.id,label:e.label,casesFolder:e.casesFolder,templateFolder:e.templateFolder}));function W(){let e=c().caseTypes;return e?.length?e.map(e=>({...e})):r.map(e=>({...e}))}function ze(e){let t=W();return t.find(t=>t.id===e)??t[0]??r[0]}function Be(e){let t=a(e);return u({caseTypes:t}),l(),t}function Ve(e){let t=e.trim();if(!t)throw Error(`类型名称不能为空`);if(t.length>40)throw Error(`类型名称过长(最多 40 字)`);let n=W();if(n.some(e=>e.label===t))throw Error(`已存在「${t}」`);let r=o(t),a={id:i(),label:t,...r};return Be([...n,a]),a}function He(e,t){let n=t.trim();if(!n)throw Error(`类型名称不能为空`);if(n.length>40)throw Error(`类型名称过长(最多 40 字)`);let r=W(),i=r.findIndex(t=>t.id===e);if(i<0)throw Error(`类型不存在`);if(r.some(t=>t.id!==e&&t.label===n))throw Error(`已存在「${n}」`);let a=o(n),s={...r[i],label:n,...a},c=[...r];return c[i]=s,Be(c),s}function Ue(e){let t=W();if(t.length<=1)throw Error(`至少保留一个用例类型`);if(!t.some(t=>t.id===e))throw Error(`类型不存在`);return Be(t.filter(t=>t.id!==e))}var We=`/__tb_case_sessions`,Ge=`tw.case.sessions.v1`,Ke=!1;function qe(){return`csess_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`}function Je(e){if(typeof e==`string`&&e.trim()){let t=e.trim();return W().some(e=>e.id===t),t}return W()[0]?.id??`functional`}function Ye(e){if(!e||!Array.isArray(e.sessions))return{sessions:[],activeId:``};let t=e.sessions.filter(e=>e&&typeof e==`object`&&e.id).map(e=>({...e,caseType:Je(e.caseType)})),n=typeof e.activeId==`string`?e.activeId:``;return t.length&&!t.some(e=>e.id===n)&&(n=t[0].id),t.length||(n=``),{sessions:t,activeId:n}}function Xe(){try{let e=localStorage.getItem(s(Ge));return e?Ye(JSON.parse(e)):{sessions:[],activeId:``}}catch{return{sessions:[],activeId:``}}}function Ze(e){try{localStorage.setItem(s(Ge),JSON.stringify(e))}catch{}}async function Qe(){try{let e=await fetch(We,{signal:AbortSignal.timeout(2e3)});if(e.ok){let t=await e.json();Ke=!0;let n=Ye(t.store);return Ze(n),n}}catch{}return Ke=!1,Xe()}function $e(){return Xe()}async function et(e){if(Ze(e),Ke)try{await fetch(We,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({store:e})})}catch{}}function tt(e){Ze(e),et(e)}function nt(e){let t=Date.now(),n={id:qe(),title:e.title?.trim()||`用例生成`,createdAt:t,updatedAt:t,caseType:e.caseType,outputFormat:e.outputFormat,reqPaths:e.reqPaths,templateId:e.templateId,templateTitle:e.templateTitle,promptPath:e.promptPath,knowledgePaths:e.knowledgePaths?.length?[...e.knowledgePaths]:void 0,messages:[]};return tt({sessions:[n,...Xe().sessions],activeId:n.id}),n}function rt(e,t){let n=Xe(),r=n.sessions.map(n=>n.id===e?{...n,...t,updatedAt:Date.now()}:n),i={...n,sessions:r};return tt(i),i}var G=e(t(),1),K=d();function it({options:e,values:t,onChange:n,placeholder:r=`选择…`,disabled:i=!1}){let[a,o]=(0,G.useState)(!1),s=(0,G.useRef)(null);(0,G.useEffect)(()=>{if(!a)return;function e(e){s.current?.contains(e.target)||o(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[a]);let c=e.filter(e=>t.includes(e.value)).map(e=>e.label),l=i||c.length===0?r:c.length<=2?c.join(`、`):`已选 ${c.length} 项`;function u(e){t.includes(e)?n(t.filter(t=>t!==e)):n([...t,e])}return(0,K.jsxs)(`div`,{className:`relative mt-1`,ref:s,children:[(0,K.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>o(e=>!e),className:i?`w-full h-9 flex items-center justify-between gap-2 rounded-lg border border-stone-200 bg-stone-50 px-3 text-sm text-left text-stone-400 cursor-not-allowed`:`w-full h-9 flex items-center justify-between gap-2 rounded-lg border border-stone-200 bg-white px-3 text-sm text-left text-stone-800 outline-none hover:border-stone-300 focus:ring-2 focus:ring-[#4176e6]/30`,children:[(0,K.jsx)(`span`,{className:`truncate ${i||c.length?``:`text-stone-400`}`,children:l}),(0,K.jsx)(`svg`,{className:`w-4 h-4 text-stone-400 shrink-0`,viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,K.jsx)(`path`,{fillRule:`evenodd`,d:`M5.23 7.21a.75.75 0 011.06.02L10 11.17l3.71-3.94a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z`,clipRule:`evenodd`})})]}),a?(0,K.jsx)(`div`,{className:`tw-select-menu tw-popover-anim absolute z-80 mt-1 max-h-56 w-full overflow-auto rounded-lg p-1 shadow-lg ring-1 ring-stone-200`,children:e.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-stone-400`,children:`暂无可选项`}):e.map(e=>{let n=t.includes(e.value);return(0,K.jsxs)(`label`,{className:`flex items-center gap-2 rounded-md px-3 py-2 text-sm text-stone-700 cursor-pointer hover:bg-stone-50`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:n,onChange:()=>u(e.value),className:`rounded border-stone-300 text-[#4176e6] focus:ring-[#4176e6]/40`}),(0,K.jsx)(`span`,{className:`truncate`,children:e.label})]},e.value)})}):null]})}var q=e(n(),1);function at(e){return typeof e==`object`?e.key:e}function ot(e,t){let n=e.length;return new Proxy(e,{get(e,r,i){if(typeof r==`string`){let i=r.charCodeAt(0);if(i>=48&&i<=57){let i=+r;if(Number.isInteger(i)&&i>=0&&i<n){let n=e[i];if(typeof n!=`object`){let r=t[i*2];n=e[i]={index:i,key:n,start:r,size:t[i*2+1],end:r+t[i*2+1],lane:0}}return n}}if(r===`length`)return n}return Reflect.get(e,r,i)}})}function J(e,t,n){let r=n.initialDeps??[],i,a=!0;function o(){let o=e();return(o.length!==r.length||o.some((e,t)=>r[t]!==e))&&(r=o,i=t(...o),n?.onChange&&!(a&&n.skipInitialOnChange)&&n.onChange(i),a=!1),i}return o.updateDeps=e=>{r=e},o}function st(e,t){if(e===void 0)throw Error(`Unexpected undefined${t?`: ${t}`:``}`);return e}var Y=(e,t)=>Math.abs(e-t)<1.01,ct=(e,t,n)=>{let r;return Object.assign(function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)},{cancel:()=>{e.clearTimeout(r)}})},lt,ut=()=>{if(lt!==void 0)return lt;if(typeof navigator>`u`)return lt=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return lt=!0;let e=navigator.maxTouchPoints;return lt=navigator.platform===`MacIntel`&&e!==void 0&&e>0},dt=e=>{let{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},ft=e=>e,pt=e=>{let t=e.overscan*Math.max(e.lanes??1,1),n=Math.max(e.startIndex-t,0),r=Math.min(e.endIndex+t,e.count-1)-n+1,i=Array(r);for(let e=0;e<r;e++)i[e]=n+e;return i},mt=(e,t)=>{let n=e.scrollElement;if(!n)return;let r=e.targetWindow;if(!r)return;let i=e=>{let{width:n,height:r}=e;t({width:Math.round(n),height:Math.round(r)})};if(i(dt(n)),!r.ResizeObserver)return()=>{};let a=new r.ResizeObserver(t=>{let r=()=>{let e=t[0];if(e?.borderBoxSize){let t=e.borderBoxSize[0];if(t){i({width:t.inlineSize,height:t.blockSize});return}}i(dt(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(r):r()});return a.observe(n,{box:`border-box`}),()=>{a.unobserve(n)}},ht={passive:!0},gt=typeof window>`u`||`onscrollend`in window,_t=(e,t,n)=>{let r=e.scrollElement;if(!r)return;let i=e.targetWindow;if(!i)return;let a=e.options.useScrollendEvent&&gt,o=0,s=a?null:ct(i,()=>t(n(r),!1),e.options.isScrollingResetDelay),c=e=>()=>{o=n(r),s?.(),t(o,e)},l=c(!0),u=c(!1);return r.addEventListener(`scroll`,l,ht),a&&r.addEventListener(`scrollend`,u,ht),()=>{r.removeEventListener(`scroll`,l),a&&r.removeEventListener(`scrollend`,u),s?.cancel()}},vt=(e,t)=>_t(e,t,t=>{let{horizontal:n,isRtl:r}=e.options;return n?t.scrollLeft*(r&&-1||1):t.scrollTop}),yt=(e,t,n)=>{if(n.options.useCachedMeasurements){let t=n.indexFromElement(e),r=n.options.getItemKey(t);return n.itemSizeCache.get(r)??n.options.estimateSize(t)}if(t?.borderBoxSize){let e=t.borderBoxSize[0];if(e)return Math.round(e[n.options.horizontal?`inlineSize`:`blockSize`])}if(!t){let t=n.indexFromElement(e),r=n.options.getItemKey(t),i=n.itemSizeCache.get(r);if(i!==void 0)return i}return e[n.options.horizontal?`offsetWidth`:`offsetHeight`]},bt=(e,{adjustments:t=0,behavior:n},r)=>{var i,a;(a=(i=r.scrollElement)?.scrollTo)==null||a.call(i,{[r.options.horizontal?`left`:`top`]:e+t,behavior:n})},xt=(e,t)=>e===`smooth`?t?`smoothLanded`:`smooth`:`instant`,St=e=>e?.phase===`smooth`||e?.phase===`smoothLanded`,Ct=e=>e.phase===`smooth`||e.phase===`smoothFinishing`;function wt(e,t,n,r){if(t===0)return!1;let i=r(0),a=new Set,o=0;for(;o<e;){let e=n(o);if(e===i)break;a.add(e),o++}let s=e-o;if(s===0||s>=t)return!1;for(let e=0;e<s;e++)if(r(e)!==n(o+e))return!1;for(let e=s;e<t;e++)if(a.has(r(e)))return!1;return!0}var Tt=class{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this._clampedAdjustment=null,this.elementsCache=new Map,this._resizeBatch=null,this.now=()=>{var e;return((e=this.targetWindow?.performance)?.now)?.call(e)??Date.now()},this.observer=(()=>{let e=null,t=()=>e||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:e=new this.targetWindow.ResizeObserver(e=>{let t=()=>{let t={sync:!1};this._resizeBatch=t;try{e.forEach(n)}finally{this._resizeBatch=null,t.notify&&(this.notify(t.sync),this._retryClampedAdjustment())}};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(t):t()})),n=e=>{let t=e.target,n=this.indexFromElement(t);if(t.isConnected)this.isIndexInRange(n)&&this.shouldMeasureDuringScroll(n)&&this.resizeItem(n,this.options.measureElement(t,e,this));else{this.observer.unobserve(t);for(let[e,n]of this.elementsCache)if(n===t){this.elementsCache.delete(e);break}}};return{disconnect:()=>{var n;(n=t())==null||n.disconnect(),e=null},observe:e=>t()?.observe(e,{box:`border-box`}),unobserve:e=>t()?.unobserve(e)}})(),this.range=null,this.setOptions=e=>{let t={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:ft,rangeExtractor:pt,onChange:()=>{},measureElement:yt,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:`data-index`,initialMeasurementsCache:[],lanes:1,anchorTo:`start`,followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:`estimate`,useCachedMeasurements:!1};for(let n in e){let r=e[n];r!==void 0&&(t[n]=r)}let n=this.options,r=null,i=null,a=!1;if(n!==void 0&&n.enabled&&t.enabled&&t.anchorTo===`end`&&this.scrollElement!==null){let e=n.count,o=t.count,s=this.getMeasurements(),c=this._singleLaneMeasurements?.items??s,l=e=>at(c[e]),u=e>0?l(0):null,d=e>0?l(e-1):null;if(o!==e||e>0&&o>0&&(t.getItemKey(0)!==u||t.getItemKey(o-1)!==d)){a=!0;let c=e>0?this.getVirtualItemForOffset(this.getScrollOffset())??s[0]:null;c&&(r=[c.key,this.getScrollOffset()-c.start]);let u=t.followOnAppend===!0?`auto`:t.followOnAppend||null;u&&o>0&&this.isAtEnd(n.scrollEndThreshold)&&(e===0||t.getItemKey(o-1)!==d)&&(o>e||wt(e,o,l,t.getItemKey))&&(i=u)}}this.options=t,a&&(this.pendingMin=0,this.itemSizeCacheVersion++);let o=!1,s=0;if(r&&this.scrollOffset!==null){let[e,t]=r,n=this.getMeasurements(),{count:a,getItemKey:c}=this.options,l=0;for(;l<a&&c(l)!==e;)l++;if(l<a){let e=n[l];if(e){let n=Math.max(0,e.start+t);!i&&n!==this.scrollOffset&&(s=n-this.scrollOffset,this.scrollOffset=n,o=!0)}}}(o||i)&&(this.pendingScrollAnchor=[o?r[0]:null,o?r[1]:0,i,s])},this.notify=e=>{var t,n;(n=(t=this.options).onChange)==null||n.call(t,this,e)},this.maybeNotify=J(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),e=>{this.notify(e)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(e=>e()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.isScrolling=!1,this.scrollDirection=null,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._clampedAdjustment=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{let e=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==e){if(this.cleanup(),!e){this.maybeNotify();return}if(this.scrollElement=e,this.targetWindow=this.scrollElement&&`ownerDocument`in this.scrollElement?this.scrollElement.ownerDocument.defaultView:this.scrollElement?.window??null,this.elementsCache.forEach(e=>{this.observer.observe(e)}),this.unsubs.push(this.options.observeElementRect(this,e=>{this.scrollRect=e,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(e,t)=>{if(t&&this._intendedScrollOffset===null&&e===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(e-this._intendedScrollOffset)<1.5?e=this._intendedScrollOffset:this.scrollState?.index!=null&&!Ct(this.scrollState)&&!Y(e,this.scrollState.lastTargetOffset)&&!Y(e,this.getScrollStateTarget(this.scrollState))&&(this._clampedAdjustment===null||Math.abs(e-this._clampedAdjustment.maxAtWrite)>=1.5)&&(this.scrollState=null),this._intendedScrollOffset=null,this.scrollState&&(this.scrollState.writtenOffset=null),this._clampedAdjustment!==null&&Math.abs(e-this._clampedAdjustment.maxAtWrite)>=1.5&&(this._clampedAdjustment=null),this.scrollAdjustments=0;let n=this.getScrollOffset();this.scrollDirection=t?n===e?this.scrollDirection:n<e?`forward`:`backward`:null,this.scrollOffset=e,this.isScrolling=t,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),`addEventListener`in this.scrollElement){let e=this.scrollElement,t=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},n=()=>{this._iosTouching=!1,ut()&&this.targetWindow!=null&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};e.addEventListener(`touchstart`,t,ht),e.addEventListener(`touchend`,n,ht),e.addEventListener(`touchcancel`,n,ht),this.unsubs.push(()=>{e.removeEventListener(`touchstart`,t),e.removeEventListener(`touchend`,n),e.removeEventListener(`touchcancel`,n),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}let t=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,t&&this.scrollElement&&this.options.enabled){let[e,n,r,i]=t;e!==null&&!r&&(ut()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?i!==0&&(this._iosDeferredAdjustment+=i):St(this.scrollState)&&!Y(this.getScrollOffset()-i,this.scrollState.lastTargetOffset)||this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),r&&this.scrollToEnd({behavior:r})}this._retryClampedAdjustment()},this._retryClampedAdjustment=()=>{if(this._clampedAdjustment===null||!this.scrollElement||!this.options.enabled)return;let{target:e,maxAtWrite:t}=this._clampedAdjustment,n=this.getMaxScrollOffset();n>t+.5&&(this._clampedAdjustment=e>n+.5?{target:e,maxAtWrite:n}:null,this._scrollToOffset(e,{adjustments:void 0,behavior:void 0}))},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;let e=this.getScrollOffset(),t=this.getMaxScrollOffset();if(e<0||e>t)return;if(this._iosDeferredAdjustment<0&&e>=t-1){this._iosDeferredAdjustment=0;return}let n=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(e,{adjustments:this.scrollAdjustments+=n,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?`width`:`height`]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset==`function`?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=J(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(e,t,n,r,i,a,o,s)=>(this.prevLanes!==void 0&&this.prevLanes!==a&&(this.lanesChangedFlag=!0),this.prevLanes=a,this.pendingMin=null,{count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o,gap:s}),{key:!1}),this.isIndexInRange=e=>e>=0&&e<this.options.count,this.getMeasurements=J(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o,gap:s},c)=>{let l=this.itemSizeCache;if(!i)return this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>e)for(let t of this.laneAssignments.keys())t>=e&&this.laneAssignments.delete(t);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(e=>{this.itemSizeCache.set(e.key,e.size)}));let u=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===e&&(this.lanesSettling=!1),a===1){let i=e*2,a=this._singleLaneMeasurements?.flat;if(!a||a.length<i){let e=new Float64Array(i);a&&u>0&&e.set(a.subarray(0,u*2)),a=e}let o=u===0?Array(e):this._singleLaneMeasurements.items.slice(),c;if(u===0)c=t+n;else{let e=u-1;c=a[e*2]+a[e*2+1]+s}for(let t=u;t<e;t++){let e=r(t);o[t]=e;let n=l.get(e),i=typeof n==`number`?n:this.options.estimateSize(t);a[t*2]=c,a[t*2+1]=i,c+=i+s}this._singleLaneMeasurements={flat:a,items:o};let d=ot(o,a);return this.measurementsCache=d,d}let d=this.measurementsCache.slice(0,u),f=Array(a).fill(void 0),p=new Float64Array(a),m=0;for(let e=0;e<u;e++){let t=d[e];t&&(f[t.lane]===void 0&&m++,f[t.lane]=e,p[t.lane]=t.end)}for(let i=u;i<e;i++){let e=r(i),c=this.laneAssignments.get(i),u,h,g=o===`estimate`||l.has(e);if(c!==void 0&&this.options.lanes>1){u=c;let e=f[u],r=e===void 0?void 0:d[e];h=r?r.end+s:t+n}else if(m===a){let e=0,t=p[0],n=f[0];for(let r=1;r<a;r++){let i=p[r];(i<t||i===t&&f[r]<n)&&(e=r,t=i,n=f[r])}u=e,h=t+s,g&&this.laneAssignments.set(i,u)}else u=i%this.options.lanes,h=t+n,g&&this.laneAssignments.set(i,u);let _=l.get(e),v=typeof _==`number`?_:this.options.estimateSize(i),y=h+v;d[i]={index:i,start:h,size:v,end:y,key:e,lane:u},f[u]===void 0&&m++,f[u]=i,p[u]=y}return this.measurementsCache=d,d},{key:!1,debug:()=>this.options.debug}),this.calculateRange=J(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,r)=>e.length===0||t===0?(this.range=null,null):(this.range=Ot(e,t,n,r,r===1&&this._singleLaneMeasurements!==null?this._singleLaneMeasurements.flat:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=J(()=>{let e=null,t=null,n=this.calculateRange();return n&&(e=n.startIndex,t=n.endIndex),this.maybeNotify.updateDeps([this.isScrolling,e,t]),[this.options.rangeExtractor,this.options.overscan,this.options.count,e,t,this.options.lanes]},(e,t,n,r,i,a)=>r===null||i===null?[]:e({startIndex:r,endIndex:i,overscan:t,count:n,lanes:a}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=e=>{let t=this.options.indexAttribute,n=e.getAttribute(t);return n?parseInt(n,10):(console.warn(`Missing attribute name '${t}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=e=>{if(!St(this.scrollState))return!0;let t=this.scrollState.index??this.getVirtualItemForOffset(this.scrollState.lastTargetOffset)?.index;if(t!==void 0&&this.range){let n=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),r=Math.max(0,t-n),i=Math.min(this.options.count-1,t+n);return e>=r&&e<=i}return!0},this.measureElement=e=>{if(!e){this.elementsCache.forEach((e,t)=>{e.isConnected||(this.observer.unobserve(e),this.elementsCache.delete(t))});return}let t=this.indexFromElement(e);if(!this.isIndexInRange(t))return;let n=this.options.getItemKey(t),r=this.elementsCache.get(n);r!==e&&(r&&this.observer.unobserve(r),this.observer.observe(e),this.elementsCache.set(n,e)),e.isConnected&&(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(t)&&this.resizeItem(t,this.options.measureElement(e,void 0,this))},this.resizeItem=(e,t)=>{var n;if(!this.isIndexInRange(e))return;this._resizeBatch?.sync&&this.getMeasurements();let r,i,a,o=this._singleLaneMeasurements?.flat;if(this.options.lanes===1&&o!=null)a=this.options.getItemKey(e),i=o[e*2],r=o[e*2+1];else{let t=this.measurementsCache[e];if(!t)return;a=t.key,i=t.start,r=t.size}let s=this.itemSizeCache.get(a)??r,c=t-s;if(c!==0){let o=this.options.anchorTo===`end`&&!St(this.scrollState)&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,l=o?this.getTotalSize():0,u=this.getScrollOffset()+this.scrollAdjustments,d=this.itemSizeCache.has(a)?i+s<=u&&this.scrollDirection!==`backward`:i<u,f=!St(this.scrollState)&&(this.shouldAdjustScrollPositionOnItemSizeChange===void 0?d:this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[e]??{index:e,key:a,start:i,size:r,end:i+r,lane:0},c,this));(this.pendingMin===null||e<this.pendingMin)&&(this.pendingMin=e),this.itemSizeCache.set(a,t),this.itemSizeCacheVersion++;let p=this.scrollState?.writtenOffset!=null&&!Y(this.scrollState.writtenOffset,this.getScrollOffset()+this.scrollAdjustments),m=!1;if(p||(o?m=this.applyScrollAdjustment(this.getTotalSize()-l):f&&(m=this.applyScrollAdjustment(c))),this._resizeBatch){this._resizeBatch.notify=!0,(n=this._resizeBatch).sync||(n.sync=m);return}this.notify(m),this._retryClampedAdjustment()}},this.getVirtualItems=J(()=>[this.getVirtualIndexes(),this.getMeasurements()],(e,t)=>{let n=[];for(let r=0,i=e.length;r<i;r++){let i=t[e[r]];n.push(i)}return n},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=e=>{let t=this.getMeasurements();if(t.length===0)return;let n=this._singleLaneMeasurements?.flat,r=this.options.lanes===1&&n!=null;return st(t[Et(0,t.length-1,r?e=>n[e*2]:e=>st(t[e]).start,e)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if(`scrollHeight`in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{let e=this.scrollElement.document.documentElement;return this.options.horizontal?e.scrollWidth-this.scrollElement.innerWidth:e.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(e=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=e,this.getOffsetForAlignment=(e,t,n=0)=>{if(!this.scrollElement)return 0;let r=this.getSize(),i=this.getScrollOffset();t===`auto`&&(t=e>=i+r?`end`:`start`),t===`center`?e+=(n-r)/2:t===`end`&&(e-=r);let a=this.getMaxScrollOffset();return Math.max(Math.min(a,e),0)},this.getOffsetForIndex=(e,t=`auto`)=>{e=Math.max(0,Math.min(e,this.options.count-1));let n=this.getSize(),r=this.getScrollOffset(),i=this.measurementsCache[e];if(!i)return;if(t===`auto`){if(i.end>=r+n-this.options.scrollPaddingEnd)t=`end`;else if(i.start<=r+this.options.scrollPaddingStart)t=`start`;else return[r,t]}if(t===`end`&&e===this.options.count-1){let e=this.getMaxScrollOffset(),n=e-this.options.paddingEnd+this.options.scrollPaddingEnd;return[Math.max(Math.min(n,e),0),t]}let a=t===`end`?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,t,i.size),t]},this.scrollToOffset=(e,{align:t=`start`,behavior:n=`auto`}={})=>{this._iosDeferredAdjustment=0;let r=this.getOffsetForAlignment(e,t),i=this.now();this.scrollState={index:null,align:t,startedAt:i,lastTargetOffset:r,stableFrames:0,phase:xt(n,!1)},this._scrollToOffset(r,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollToIndex=(e,{align:t=`auto`,behavior:n=`auto`}={})=>{this._iosDeferredAdjustment=0,e=Math.max(0,Math.min(e,this.options.count-1));let r=this.getOffsetForIndex(e,t);if(!r)return;let[i,a]=r,o=this.now();this.scrollState={index:e,align:a,startedAt:o,lastTargetOffset:i,stableFrames:0,phase:xt(n,Y(i,this.getScrollOffset()))},this._scrollToOffset(i,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollBy=(e,{behavior:t=`auto`}={})=>{let n=this.getOffsetForAlignment((this.scrollState?.writtenOffset??this.getScrollOffset())+e,`start`),r=this.now();this.scrollState={index:null,align:`start`,startedAt:r,lastTargetOffset:n,stableFrames:0,phase:xt(t,!1)},this._scrollToOffset(n,{adjustments:void 0,behavior:t}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:e=`auto`}={})=>{if(this.options.count>0){this._iosDeferredAdjustment=0;let t=Math.max(this.getMaxScrollOffset(),0);this.scrollState={index:this.options.count-1,align:`end`,toEnd:!0,startedAt:this.now(),lastTargetOffset:t,stableFrames:0,phase:xt(e,Y(t,this.getScrollOffset()))},this._scrollToOffset(t,{adjustments:void 0,behavior:e}),this.scheduleScrollReconcile()}else this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:e})},this.cancelScroll=()=>{this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null},this.getTotalSize=()=>{let e=this.getMeasurements(),t;if(e.length===0)t=this.options.paddingStart;else if(this.options.lanes===1){let n=e.length-1,r=this._singleLaneMeasurements?.flat;t=r==null?e[n]?.end??0:r[n*2]+r[n*2+1]}else{let n=Array(this.options.lanes).fill(null),r=e.length-1;for(;r>=0&&n.some(e=>e===null);){let t=e[r];n[t.lane]===null&&(n[t.lane]=t.end),r--}t=Math.max(...n.filter(e=>e!==null))}return Math.max(t-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{let e=[];if(this.itemSizeCache.size===0)return e;let t=this.getMeasurements();for(let n of t)n&&this.itemSizeCache.has(n.key)&&e.push({index:n.index,key:n.key,start:n.start,size:n.size,end:n.end,lane:n.lane});return e},this._scrollToOffset=(e,{adjustments:t,behavior:n})=>{this._intendedScrollOffset=e+(t??0),this.scrollState&&(this.scrollState.writtenOffset=n===`smooth`?null:this._intendedScrollOffset),this.options.scrollToFn(e,{behavior:n,adjustments:t},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(e)}applyScrollAdjustment(e,t){if(e===0)return!1;if(ut()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded))return this.scrollState?.index??(this._iosDeferredAdjustment+=e),!1;{let n=this.getScrollOffset()+this.scrollAdjustments+e,r=this.scrollElement,i=r!==null&&(`scrollHeight`in r||`document`in r)?this.getMaxScrollOffset():null;return this._clampedAdjustment=i!==null&&n>i+.5?{target:n,maxAtWrite:i}:null,this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=e,behavior:t}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollOffset<0&&(this.scrollOffset=0),this.scrollAdjustments=0),!0}}scheduleScrollReconcile(){this.targetWindow?this.rafId??=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}):this.scrollState=null}getScrollStateTarget(e){let t=e.toEnd?[Math.max(this.getMaxScrollOffset(),0)]:e.index==null?void 0:this.getOffsetForIndex(e.index,e.align);return t?t[0]:e.lastTargetOffset}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}this.getMeasurements();let e=this.getScrollStateTarget(this.scrollState),t=this.scrollState.index==null?1:this.options.useAnimationFrameWithResizeObserver?3:2,n=e!==this.scrollState.lastTargetOffset;if(!n&&Y(e,this.getScrollOffset())){if(this.scrollState.phase===`smooth`?this.scrollState.phase=`smoothLanded`:this.scrollState.phase===`smoothFinishing`&&(this.scrollState.phase=`instant`),this.scrollState.stableFrames++,this.scrollState.stableFrames>=t){this.getScrollOffset()!==e&&this._scrollToOffset(e,{adjustments:void 0,behavior:`auto`}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,n){let t=this.getSize()||600,n=Math.abs(e-this.getScrollOffset()),r=St(this.scrollState)&&n>t;this.scrollState.lastTargetOffset=e,r?this.scrollState.phase=`smooth`:this.scrollState.phase===`smooth`?this.scrollState.phase=`smoothFinishing`:this.scrollState.phase===`smoothLanded`&&(this.scrollState.phase=`instant`),this._scrollToOffset(e,{adjustments:void 0,behavior:r?`smooth`:`auto`})}this.scheduleScrollReconcile()}},Et=(e,t,n,r)=>{for(;e<=t;){let i=(e+t)/2|0,a=n(i);if(a<r)e=i+1;else if(a>r)t=i-1;else return i}return e>0?e-1:0};function Dt(e,t,n){let r=0;for(;r<=t;){let i=(r+t)/2|0,a=e[i*2];if(a<n)r=i+1;else if(a>n)t=i-1;else return i}return r>0?r-1:0}function Ot(e,t,n,r,i){let a=e.length-1;if(e.length<=r)return{startIndex:0,endIndex:a};if(r===1&&i!==null){let e=Dt(i,a,n),r=e,o=n+t;for(;r<a&&i[r*2]+i[r*2+1]<o;)r++;return{startIndex:e,endIndex:r}}let o=Et(0,a,t=>e[t].start,n),s=o;if(r===1)for(;s<a&&e[s].end<n+t;)s++;else if(r>1){let i=Array(r).fill(0);for(;s<a&&i.some(e=>e<n+t);){let t=e[s];i[t.lane]=t.end,s++}let c=Array(r).fill(n+t);for(;o>=0&&c.some(e=>e>=n);){let t=e[o];c[t.lane]=t.start,o--}o=Math.max(0,o-o%r),s=Math.min(a,s+(r-1-s%r))}return{startIndex:o,endIndex:s}}var kt=typeof document<`u`?G.useLayoutEffect:G.useEffect;function At({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:n=`transform`,...r}){let i=G.useReducer(e=>e+1,0)[1],a=G.useRef({enabled:t,mode:n,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});a.current.enabled=t,a.current.mode=n;let o=G.useRef(!1),s=e=>{let t=a.current;if(!t.enabled||!t.container)return;let n=e.getTotalSize();if(n!==t.lastSize){t.lastSize=n;let r=e.options.horizontal?`width`:`height`;t.container.style[r]=`${n}px`}},c=(e,t,n)=>{let r=a.current,i=!!e.options.horizontal,o=t.start-e.options.scrollMargin;r.lastPositions.get(n)!==o&&(r.lastPositions.set(n,o),r.mode===`transform`?n.style.transform=i?`translate3d(${o}px, 0, 0)`:`translate3d(0, ${o}px, 0)`:n.style[i?`left`:`top`]=`${o}px`)},l=e=>{let t=a.current;if(t.enabled&&t.container){s(e);for(let t of e.getVirtualItems()){let n=e.elementsCache.get(t.key);n&&c(e,t,n)}}},u={...r,onChange:(t,n)=>{var s;let c=a.current,u=!0;if(c.enabled){l(t);let e=t.range,n=c.prevRange;u=!n||n.isScrolling!==t.isScrolling||n.startIndex!==e?.startIndex||n.endIndex!==e?.endIndex,u&&(c.prevRange=e?{startIndex:e.startIndex,endIndex:e.endIndex,isScrolling:t.isScrolling}:null)}u&&(e&&n&&!o.current?(0,q.flushSync)(i):i()),(s=r.onChange)==null||s.call(r,t,n)}},[d]=G.useState(()=>{let e=new Tt(u),t=e.measureElement;return e.measureElement=n=>{o.current=!0;try{t(n)}finally{o.current=!1}let r=a.current;if(n!==null&&r.enabled&&r.container){let t=e.measurementsCache[e.indexFromElement(n)];t&&c(e,t,n)}},Object.assign(e,{containerRef:t=>{let n=a.current;n.container=t,n.lastSize=null,t!==null&&l(e)}})});return d.setOptions(u),kt(()=>d._didMount(),[]),kt(()=>(s(d),d._willUpdate())),kt(()=>{l(d)}),d}function jt(e){return At({observeElementRect:mt,observeElementOffset:vt,scrollToFn:bt,...e})}function Mt(e){let t=(0,G.useRef)({value:``,selectionStart:null,selectionEnd:null});return he(e,`blur`,e=>{let n=e.target;F(n)&&(t.current={value:n.value,selectionStart:n.selectionStart,selectionEnd:n.selectionEnd})}),V(()=>{if(!je(e)&&F(e)&&e.isConnected){if(e.focus({preventScroll:!0}),e.value!==t.current.value)e.setSelectionRange(e.value.length,e.value.length);else{let{selectionStart:n,selectionEnd:r}=t.current;n!==null&&r!==null&&e.setSelectionRange(n,r)}t.current={value:``,selectionStart:null,selectionEnd:null}}})}var Nt=Object.defineProperty,Pt=(e,t,n)=>t in e?Nt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ft=(e,t,n)=>(Pt(e,typeof t==`symbol`?t:t+``,n),n),X=(e=>(e[e.Open=0]=`Open`,e[e.Closed=1]=`Closed`,e))(X||{}),Z=(e=>(e[e.Single=0]=`Single`,e[e.Multi=1]=`Multi`,e))(Z||{}),Q=(e=>(e[e.Pointer=0]=`Pointer`,e[e.Focus=1]=`Focus`,e[e.Other=2]=`Other`,e))(Q||{}),It=(e=>(e[e.OpenCombobox=0]=`OpenCombobox`,e[e.CloseCombobox=1]=`CloseCombobox`,e[e.GoToOption=2]=`GoToOption`,e[e.SetTyping=3]=`SetTyping`,e[e.RegisterOption=4]=`RegisterOption`,e[e.UnregisterOption=5]=`UnregisterOption`,e[e.DefaultToFirstOption=6]=`DefaultToFirstOption`,e[e.SetActivationTrigger=7]=`SetActivationTrigger`,e[e.UpdateVirtualConfiguration=8]=`UpdateVirtualConfiguration`,e[e.SetInputElement=9]=`SetInputElement`,e[e.SetButtonElement=10]=`SetButtonElement`,e[e.SetOptionsElement=11]=`SetOptionsElement`,e[e.MarkInputAsMoved=12]=`MarkInputAsMoved`,e))(It||{});function Lt(e,t=e=>e){let n=e.activeOptionIndex===null?null:e.options[e.activeOptionIndex],r=t(e.options.slice()),i=r.length>0&&r[0].dataRef.current.order!==null?r.sort((e,t)=>e.dataRef.current.order-t.dataRef.current.order):N(r,e=>e.dataRef.current.domRef.current),a=n?i.indexOf(n):null;return a===-1&&(a=null),{options:i,activeOptionIndex:a}}var Rt={1(e){var t;if((t=e.dataRef.current)!=null&&t.disabled||e.comboboxState===1)return e;let n=e.inputElement?k.Tracked(E(e.inputElement)):e.inputPositionState;return{...e,activeOptionIndex:null,comboboxState:1,isTyping:!1,activationTrigger:2,inputPositionState:n,__demoMode:!1}},0(e){var t,n;if((t=e.dataRef.current)!=null&&t.disabled||e.comboboxState===0)return e;if((n=e.dataRef.current)!=null&&n.value){let t=e.dataRef.current.calculateIndex(e.dataRef.current.value);if(t!==-1)return{...e,activeOptionIndex:t,comboboxState:0,__demoMode:!1,inputPositionState:k.Idle}}return{...e,comboboxState:0,inputPositionState:k.Idle,__demoMode:!1}},3(e,t){return e.isTyping===t.isTyping?e:{...e,isTyping:t.isTyping}},2(e,t){var n,r;if((n=e.dataRef.current)!=null&&n.disabled||e.optionsElement&&!((r=e.dataRef.current)!=null&&r.optionsPropsRef.current.static)&&e.comboboxState===1)return e;if(e.virtual){let{options:n,disabled:r}=e.virtual,i=t.focus===v.Specific?t.idx:D(t,{resolveItems:()=>n,resolveActiveIndex:()=>e.activeOptionIndex??n.findIndex(e=>!r(e))??null,resolveDisabled:r,resolveId(){throw Error(`Function not implemented.`)}}),a=t.trigger??2;return e.activeOptionIndex===i&&e.activationTrigger===a?e:{...e,activeOptionIndex:i,activationTrigger:a,isTyping:!1,__demoMode:!1}}let i=Lt(e);if(i.activeOptionIndex===null){let e=i.options.findIndex(e=>!e.dataRef.current.disabled);e!==-1&&(i.activeOptionIndex=e)}let a=t.focus===v.Specific?t.idx:D(t,{resolveItems:()=>i.options,resolveActiveIndex:()=>i.activeOptionIndex,resolveId:e=>e.id,resolveDisabled:e=>e.dataRef.current.disabled}),o=t.trigger??2;return e.activeOptionIndex===a&&e.activationTrigger===o?e:{...e,...i,isTyping:!1,activeOptionIndex:a,activationTrigger:o,__demoMode:!1}},4:(e,t)=>{var n,r,i,a;if((n=e.dataRef.current)!=null&&n.virtual)return{...e,options:[...e.options,t.payload]};let o=t.payload,s=Lt(e,e=>(e.push(o),e));e.activeOptionIndex===null&&(i=(r=e.dataRef.current).isSelected)!=null&&i.call(r,t.payload.dataRef.current.value)&&(s.activeOptionIndex=s.options.indexOf(o));let c={...e,...s,activationTrigger:2};return(a=e.dataRef.current)!=null&&a.__demoMode&&e.dataRef.current.value===void 0&&(c.activeOptionIndex=0),c},5:(e,t)=>{var n;if((n=e.dataRef.current)!=null&&n.virtual)return{...e,options:e.options.filter(e=>e.id!==t.id)};let r=Lt(e,e=>{let n=e.findIndex(e=>e.id===t.id);return n!==-1&&e.splice(n,1),e});return{...e,...r,activationTrigger:2}},6:(e,t)=>e.defaultToFirstOption===t.value?e:{...e,defaultToFirstOption:t.value},7:(e,t)=>e.activationTrigger===t.trigger?e:{...e,activationTrigger:t.trigger},8:(e,t)=>{if(e.virtual===null)return{...e,virtual:{options:t.options,disabled:t.disabled??(()=>!1)}};if(e.virtual.options===t.options&&e.virtual.disabled===t.disabled)return e;let n=e.activeOptionIndex;if(e.activeOptionIndex!==null){let r=t.options.indexOf(e.virtual.options[e.activeOptionIndex]);n=r===-1?null:r}return{...e,activeOptionIndex:n,virtual:{options:t.options,disabled:t.disabled??(()=>!1)}}},9:(e,t)=>e.inputElement===t.element?e:{...e,inputElement:t.element},10:(e,t)=>e.buttonElement===t.element?e:{...e,buttonElement:t.element},11:(e,t)=>e.optionsElement===t.element?e:{...e,optionsElement:t.element},12(e){return e.inputPositionState.kind===`Tracked`?{...e,inputPositionState:k.Moved}:e}},zt=class e extends ae{constructor(e){super(e),Ft(this,`actions`,{onChange:e=>{let{onChange:t,compare:n,mode:r,value:i}=this.state.dataRef.current;return B(r,{0:()=>t?.(e),1:()=>{let r=i.slice(),a=r.findIndex(t=>n(t,e));return a===-1?r.push(e):r.splice(a,1),t?.(r)}})},registerOption:(e,t)=>(this.send({type:4,payload:{id:e,dataRef:t}}),()=>{this.state.activeOptionIndex===this.state.dataRef.current.calculateIndex(t.current.value)&&this.send({type:6,value:!0}),this.send({type:5,id:e})}),goToOption:(e,t)=>(this.send({type:6,value:!1}),this.send({type:2,...e,trigger:t})),setIsTyping:e=>{this.send({type:3,isTyping:e})},closeCombobox:()=>{var e,t;this.send({type:1}),this.send({type:6,value:!1}),(t=(e=this.state.dataRef.current).onClose)==null||t.call(e)},openCombobox:()=>{this.send({type:0}),this.send({type:6,value:!0})},setActivationTrigger:e=>{this.send({type:7,trigger:e})},selectActiveOption:()=>{let e=this.selectors.activeOptionIndex(this.state);if(e!==null){if(this.actions.setIsTyping(!1),this.state.virtual)this.actions.onChange(this.state.virtual.options[e]);else{let{dataRef:t}=this.state.options[e];this.actions.onChange(t.current.value)}this.actions.goToOption({focus:v.Specific,idx:e})}},setInputElement:e=>{this.send({type:9,element:e})},setButtonElement:e=>{this.send({type:10,element:e})},setOptionsElement:e=>{this.send({type:11,element:e})}}),Ft(this,`selectors`,{activeDescendantId:e=>{let t=this.selectors.activeOptionIndex(e);if(t!==null)return e.virtual?e.options.find(n=>!n.dataRef.current.disabled&&e.dataRef.current.compare(n.dataRef.current.value,e.virtual.options[t]))?.id:e.options[t]?.id},activeOptionIndex:e=>{if(e.defaultToFirstOption&&e.activeOptionIndex===null&&(e.virtual?e.virtual.options.length>0:e.options.length>0)){if(e.virtual){let{options:t,disabled:n}=e.virtual,r=t.findIndex(e=>{var t;return!((t=n?.(e))!=null&&t)});if(r!==-1)return r}let t=e.options.findIndex(e=>!e.dataRef.current.disabled);if(t!==-1)return t}return e.activeOptionIndex},activeOption:e=>{let t=this.selectors.activeOptionIndex(e);return t===null?null:e.virtual?e.virtual.options[t??0]:e.options[t]?.dataRef.current.value??null},isActive:(e,t,n)=>{let r=this.selectors.activeOptionIndex(e);return r===null?!1:e.virtual?r===e.dataRef.current.calculateIndex(t):e.options[r]?.id===n},shouldScrollIntoView:(e,t,n)=>!(e.virtual||e.__demoMode||e.comboboxState!==0||e.activationTrigger===0||!this.selectors.isActive(e,t,n)),didInputMove(e){return e.inputPositionState.kind===`Moved`}});{let e=this.state.id,t=ie.get(null);this.disposables.add(t.on(re.Push,n=>{!t.selectors.isTop(n,e)&&this.state.comboboxState===0&&this.actions.closeCombobox()})),this.on(0,()=>t.actions.push(e)),this.on(1,()=>t.actions.pop(e))}this.disposables.group(e=>{this.on(1,t=>{t.inputElement&&(e.dispose(),e.add(C(t.inputElement,t.inputPositionState,()=>{this.send({type:12})})))})})}static new({id:t,virtual:n=null,__demoMode:r=!1}){return new e({id:t,dataRef:{current:{}},comboboxState:+!r,isTyping:!1,options:[],virtual:n?{options:n.options,disabled:n.disabled??(()=>!1)}:null,activeOptionIndex:null,activationTrigger:2,inputElement:null,buttonElement:null,optionsElement:null,__demoMode:r,inputPositionState:k.Idle})}reduce(e,t){return B(t.type,Rt,e,t)}},Bt=(0,G.createContext)(null);function Vt(e){let t=(0,G.useContext)(Bt);if(t===null){let t=Error(`<${e} /> is missing a parent <Combobox /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(t,Ht),t}return t}function Ht({id:e,virtual:t=null,__demoMode:n=!1}){let r=(0,G.useMemo)(()=>zt.new({id:e,virtual:t,__demoMode:n}),[]);return Te(()=>r.dispose()),r}var Ut=(0,G.createContext)(null);Ut.displayName=`ComboboxDataContext`;function $(e){let t=(0,G.useContext)(Ut);if(t===null){let t=Error(`<${e} /> is missing a parent <Combobox /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(t,$),t}return t}var Wt=(0,G.createContext)(null);function Gt(e){let t=Vt(`VirtualProvider`),{options:n}=$(`VirtualProvider`).virtual,r=I(t,e=>e.optionsElement),[i,a]=(0,G.useMemo)(()=>{let e=r;if(!e)return[0,0];let t=window.getComputedStyle(e);return[parseFloat(t.paddingBlockStart||t.paddingTop),parseFloat(t.paddingBlockEnd||t.paddingBottom)]},[r]),o=jt({enabled:n.length!==0,scrollPaddingStart:i,scrollPaddingEnd:a,count:n.length,estimateSize(){return 40},getScrollElement(){return t.state.optionsElement},overscan:12}),[s,c]=(0,G.useState)(0);z(()=>{c(e=>e+1)},[n]);let l=o.getVirtualItems(),u=I(t,e=>e.activationTrigger===Q.Pointer),d=I(t,t.selectors.activeOptionIndex);return l.length===0?null:G.createElement(Wt.Provider,{value:o},G.createElement(`div`,{style:{position:`relative`,width:`100%`,height:`${o.getTotalSize()}px`},ref:e=>{e&&(u||d!==null&&n.length>d&&o.scrollToIndex(d))}},l.map(t=>G.createElement(G.Fragment,{key:t.key},G.cloneElement(e.children?.call(e,{...e.slot,option:n[t.index]}),{key:`${s}-${t.key}`,"data-index":t.index,"aria-setsize":n.length,"aria-posinset":t.index+1,style:{position:`absolute`,top:0,left:0,transform:`translateY(${t.start}px)`,overflowAnchor:`none`}})))))}var Kt=G.Fragment;function qt(e,t){let n=(0,H.useId)(),r=fe(),{value:i,defaultValue:a,onChange:o,form:s,name:c,by:l,invalid:u=!1,disabled:d=r||!1,onClose:f,__demoMode:p=!1,multiple:m=!1,immediate:g=!1,virtual:_=null,nullable:v,...y}=e,b=Pe(a),[x=m?[]:void 0,S]=Le(i,o,b),C=Ht({id:n,virtual:_,__demoMode:p}),w=(0,G.useRef)({static:!1,hold:!1}),T=Ie(l),E=V(e=>_?l===null?_.options.indexOf(e):_.options.findIndex(t=>T(t,e)):C.state.options.findIndex(t=>T(t.dataRef.current.value,e))),D=(0,G.useCallback)(e=>B(A.mode,{[Z.Multi]:()=>x.some(t=>T(t,e)),[Z.Single]:()=>T(x,e)}),[x]),O=I(C,e=>e.virtual),k=V(()=>f?.()),A=(0,G.useMemo)(()=>({__demoMode:p,immediate:g,optionsPropsRef:w,value:x,defaultValue:b,disabled:d,invalid:u,mode:m?Z.Multi:Z.Single,virtual:_?O:null,onChange:S,isSelected:D,calculateIndex:E,compare:T,onClose:k}),[p,g,w,x,b,d,u,m,_,O,S,D,E,T,k]);z(()=>{_&&C.send({type:It.UpdateVirtualConfiguration,options:_.options,disabled:_.disabled??null})},[_,_?.options,_?.disabled]),z(()=>{C.state.dataRef.current=A},[A]);let[j,te,M,ne]=I(C,e=>[e.comboboxState,e.buttonElement,e.inputElement,e.optionsElement]),N=ie.get(null),re=I(N,(0,G.useCallback)(e=>N.selectors.isTop(e,n),[N,n]));ke(re,[te,M,ne],()=>C.actions.closeCombobox());let P=I(C,C.selectors.activeOptionIndex),F=I(C,C.selectors.activeOption),ae=me({open:j===X.Open,disabled:d,invalid:u,activeIndex:P,activeOption:F,value:x}),[oe,L]=h(),se=t===null?{}:{ref:t},ce=(0,G.useCallback)(()=>{if(b!==void 0)return S?.(b)},[S,b]),R=ve();return G.createElement(L,{value:oe,props:{htmlFor:M?.id},slot:{open:j===X.Open,disabled:d}},G.createElement(ee,null,G.createElement(Ut.Provider,{value:A},G.createElement(Bt.Provider,{value:C},G.createElement(ue,{value:B(j,{[X.Open]:be.Open,[X.Closed]:be.Closed})},c!=null&&G.createElement(Ne,{disabled:d,data:x==null?{}:{[c]:x},form:s,onReset:ce}),R({ourProps:se,theirProps:y,slot:ae,defaultTag:Kt,name:`Combobox`}))))))}var Jt=`input`;function Yt(e,t){let n=Vt(`Combobox.Input`),r=$(`Combobox.Input`),i=(0,H.useId)(),a=te(),{id:o=a||`headlessui-combobox-input-${i}`,onChange:s,displayValue:c,disabled:l=r.disabled||!1,autoFocus:u=!1,type:d=`text`,...f}=e,h=(0,G.useRef)(null),g=L(h,t,y(),n.actions.setInputElement),[_,b]=I(n,e=>[e.comboboxState,e.isTyping]),x=ge(),S=V(()=>{n.actions.onChange(null),n.state.optionsElement&&(n.state.optionsElement.scrollTop=0),n.actions.goToOption({focus:v.Nothing})}),C=(0,G.useMemo)(()=>typeof c==`function`&&r.value!==void 0?c(r.value)??``:typeof r.value==`string`?r.value:``,[r.value,c]);pe(([e,t],[r,i])=>{if(n.state.isTyping)return;let a=h.current;a&&((i===X.Open&&t===X.Closed||e!==r)&&(a.value=e),requestAnimationFrame(()=>{if(n.state.isTyping||!a||je(a))return;let{selectionStart:e,selectionEnd:t}=a;Math.abs((t??0)-(e??0))===0&&e===0&&a.setSelectionRange(a.value.length,a.value.length)}))},[C,_,b]),pe(([e],[t])=>{if(e===X.Open&&t===X.Closed){if(n.state.isTyping)return;let e=h.current;if(!e)return;let t=e.value,{selectionStart:r,selectionEnd:i,selectionDirection:a}=e;e.value=``,e.value=t,a===null?e.setSelectionRange(r,i):e.setSelectionRange(r,i,a)}},[_]);let w=(0,G.useRef)(!1),T=V(()=>{w.current=!0}),E=V(()=>{x.nextFrame(()=>{w.current=!1})}),D=V(e=>{switch(n.actions.setIsTyping(!0),e.key){case U.Enter:if(n.state.comboboxState!==X.Open||w.current)return;if(e.preventDefault(),e.stopPropagation(),n.selectors.activeOptionIndex(n.state)===null){n.actions.closeCombobox();return}n.actions.selectActiveOption(),r.mode===Z.Single&&n.actions.closeCombobox();break;case U.ArrowDown:return e.preventDefault(),e.stopPropagation(),B(n.state.comboboxState,{[X.Open]:()=>n.actions.goToOption({focus:v.Next}),[X.Closed]:()=>n.actions.openCombobox()});case U.ArrowUp:return e.preventDefault(),e.stopPropagation(),B(n.state.comboboxState,{[X.Open]:()=>n.actions.goToOption({focus:v.Previous}),[X.Closed]:()=>{(0,q.flushSync)(()=>n.actions.openCombobox()),r.value||n.actions.goToOption({focus:v.Last})}});case U.Home:if(n.state.comboboxState===X.Closed||e.shiftKey)break;return e.preventDefault(),e.stopPropagation(),n.actions.goToOption({focus:v.First});case U.PageUp:return e.preventDefault(),e.stopPropagation(),n.actions.goToOption({focus:v.First});case U.End:if(n.state.comboboxState===X.Closed||e.shiftKey)break;return e.preventDefault(),e.stopPropagation(),n.actions.goToOption({focus:v.Last});case U.PageDown:return e.preventDefault(),e.stopPropagation(),n.actions.goToOption({focus:v.Last});case U.Escape:return n.state.comboboxState===X.Open?(e.preventDefault(),n.state.optionsElement&&!r.optionsPropsRef.current.static&&e.stopPropagation(),r.mode===Z.Single&&r.value===null&&S(),n.actions.closeCombobox()):void 0;case U.Tab:if(n.actions.setIsTyping(!1),n.state.comboboxState!==X.Open)return;r.mode===Z.Single&&n.state.activationTrigger!==Q.Focus&&n.actions.selectActiveOption(),n.actions.closeCombobox()}}),O=V(e=>{s?.(e),r.mode===Z.Single&&e.target.value===``&&S(),n.actions.openCombobox()}),k=V(e=>{var t,i;let a=e.relatedTarget??Oe.find(t=>t!==e.currentTarget);if(!((t=n.state.optionsElement)!=null&&t.contains(a))&&!((i=n.state.buttonElement)!=null&&i.contains(a))&&n.state.comboboxState===X.Open)return e.preventDefault(),r.mode===Z.Single&&r.value===null&&S(),n.actions.closeCombobox()}),ee=V(e=>{var t,i;let a=e.relatedTarget??Oe.find(t=>t!==e.currentTarget);(t=n.state.buttonElement)!=null&&t.contains(a)||(i=n.state.optionsElement)!=null&&i.contains(a)||r.disabled||r.immediate&&n.state.comboboxState!==X.Open&&x.microTask(()=>{(0,q.flushSync)(()=>n.actions.openCombobox()),n.actions.setActivationTrigger(Q.Focus)})}),A=M(),j=P(),{isFocused:ne,focusProps:N}=p({autoFocus:u}),{isHovered:re,hoverProps:ie}=m({isDisabled:l}),F=I(n,e=>e.optionsElement),ae=me({open:_===X.Open,disabled:l,invalid:r.invalid,hover:re,focus:ne,autofocus:u}),oe=le({ref:g,id:o,role:`combobox`,type:d,"aria-controls":F?.id,"aria-expanded":_===X.Open,"aria-activedescendant":I(n,n.selectors.activeDescendantId),"aria-labelledby":A,"aria-describedby":j,"aria-autocomplete":`list`,defaultValue:e.defaultValue??(r.defaultValue===void 0?null:c?.(r.defaultValue))??r.defaultValue,disabled:l||void 0,autoFocus:u,onCompositionStart:T,onCompositionEnd:E,onKeyDown:D,onChange:O,onFocus:ee,onBlur:k},N,ie);return ve()({ourProps:oe,theirProps:f,slot:ae,defaultTag:Jt,name:`Combobox.Input`})}var Xt=`button`;function Zt(e,t){let n=Vt(`Combobox.Button`),r=$(`Combobox.Button`),[i,a]=(0,G.useState)(null),o=L(t,a,n.actions.setButtonElement),s=(0,H.useId)(),{id:c=`headlessui-combobox-button-${s}`,disabled:l=r.disabled||!1,autoFocus:u=!1,...d}=e,[f,h,y]=I(n,e=>[e.comboboxState,e.inputElement,e.optionsElement]),b=Mt(h),C=f===X.Open;S(C,{trigger:i,action:(0,G.useCallback)(e=>{if(i!=null&&i.contains(e.target)||h!=null&&h.contains(e.target))return x.Ignore;let t=e.target.closest(`[role="option"]:not([data-disabled])`);return se(t)?x.Select(t):y!=null&&y.contains(e.target)?x.Ignore:x.Close},[i,h,y]),close:n.actions.closeCombobox,select:n.actions.selectActiveOption});let w=V(e=>{switch(e.key){case U.Space:case U.Enter:e.preventDefault(),e.stopPropagation(),n.state.comboboxState===X.Closed&&(0,q.flushSync)(()=>n.actions.openCombobox()),b();return;case U.ArrowDown:e.preventDefault(),e.stopPropagation(),n.state.comboboxState===X.Closed&&((0,q.flushSync)(()=>n.actions.openCombobox()),n.state.dataRef.current.value||n.actions.goToOption({focus:v.First})),b();return;case U.ArrowUp:e.preventDefault(),e.stopPropagation(),n.state.comboboxState===X.Closed&&((0,q.flushSync)(()=>n.actions.openCombobox()),n.state.dataRef.current.value||n.actions.goToOption({focus:v.Last})),b();return;case U.Escape:if(n.state.comboboxState!==X.Open)return;e.preventDefault(),n.state.optionsElement&&!r.optionsPropsRef.current.static&&e.stopPropagation(),(0,q.flushSync)(()=>n.actions.closeCombobox()),b();return;default:return}}),E=_(()=>{n.state.comboboxState===X.Open?n.actions.closeCombobox():n.actions.openCombobox(),b()}),D=M([c]),{isFocusVisible:O,focusProps:k}=p({autoFocus:u}),{isHovered:ee,hoverProps:A}=m({isDisabled:l}),{pressed:j,pressProps:te}=g({disabled:l}),ne=me({open:f===X.Open,active:j||f===X.Open,disabled:l,invalid:r.invalid,value:r.value,hover:ee,focus:O}),N=le({ref:o,id:c,type:T(e,i),tabIndex:-1,"aria-haspopup":`listbox`,"aria-controls":y?.id,"aria-expanded":f===X.Open,"aria-labelledby":D,disabled:l||void 0,autoFocus:u,onKeyDown:w},E,k,A,te);return ve()({ourProps:N,theirProps:d,slot:ne,defaultTag:Xt,name:`Combobox.Button`})}var Qt=`div`,$t=we.RenderStrategy|we.Static;function en(e,t){let n=(0,H.useId)(),{id:r=`headlessui-combobox-options-${n}`,hold:i=!1,anchor:a,portal:o=!1,modal:s=!0,transition:c=!1,...l}=e,u=Vt(`Combobox.Options`),d=$(`Combobox.Options`),f=b(a);f&&(o=!0);let[p,m]=w(f),[h,g]=(0,G.useState)(null),_=A(),v=L(t,f?p:null,u.actions.setOptionsElement,g),[y,x,S,C,T]=I(u,e=>[e.comboboxState,e.inputElement,e.buttonElement,e.optionsElement,e.activationTrigger]),E=ce(x||S),D=ce(C),O=de(),[k,ee]=De(c,h,O===null?y===X.Open:(O&be.Open)===be.Open);ye(k,x,u.actions.closeCombobox);let j=!d.__demoMode&&s&&y===X.Open;_e(j,D);let te=!d.__demoMode&&s&&y===X.Open;oe(te,{allowed:(0,G.useCallback)(()=>[x,S,C],[x,S,C])});let N=!I(u,u.selectors.didInputMove)&&k;z(()=>{d.optionsPropsRef.current.static=e.static??!1},[d.optionsPropsRef,e.static]),z(()=>{d.optionsPropsRef.current.hold=i},[d.optionsPropsRef,i]),Re(y===X.Open,{container:C,accept(e){return e.getAttribute(`role`)===`option`?NodeFilter.FILTER_REJECT:e.hasAttribute(`role`)?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT},walk(e){e.setAttribute(`role`,`none`)}});let re=M([S?.id]),P=me({open:y===X.Open,option:void 0}),ie=V(()=>{u.actions.setActivationTrigger(Q.Pointer)}),F=V(e=>{e.preventDefault(),u.actions.setActivationTrigger(Q.Pointer)}),ae=le(f?_():{},{"aria-labelledby":re,role:`listbox`,"aria-multiselectable":d.mode===Z.Multi||void 0,id:r,ref:v,style:{...l.style,...m,"--input-width":ne(k,x,!0).width,"--button-width":ne(k,S,!0).width},onWheel:T===Q.Pointer?void 0:ie,onMouseDown:F,...xe(ee)}),se=k&&y===X.Closed&&!e.static,R=Fe(se,d.virtual?.options),ue=Fe(se,d.value),fe=(0,G.useCallback)(e=>d.compare(ue,e),[d.compare,ue]),pe=(0,G.useMemo)(()=>{if(!d.virtual)return d;if(R===void 0)throw Error("Missing `options` in virtual mode");return R===d.virtual.options?d:{...d,virtual:{...d.virtual,options:R}}},[d,R,d.virtual?.options]);d.virtual&&Object.assign(l,{children:G.createElement(Ut.Provider,{value:pe},G.createElement(Gt,{slot:P},l.children))});let he=ve(),ge=(0,G.useMemo)(()=>d.mode===Z.Multi?d:{...d,isSelected:fe},[d,fe]);return G.createElement(Ce,{enabled:o?e.static||k:!1,ownerDocument:E},G.createElement(Ut.Provider,{value:ge},he({ourProps:ae,theirProps:{...l,children:G.createElement(Me,{freeze:se},typeof l.children==`function`?l.children?.call(l,P):l.children)},slot:P,defaultTag:Qt,features:$t,visible:N,name:`Combobox.Options`})))}var tn=`div`;function nn(e,t){var n;let r=$(`Combobox.Option`),i=Vt(`Combobox.Option`),a=(0,H.useId)(),{id:o=`headlessui-combobox-option-${a}`,value:s,disabled:c=((n=r.virtual)?.disabled)?.call(n,s)??!1,order:l=null,...u}=e,[d]=I(i,e=>[e.inputElement]),f=Mt(d),p=I(i,(0,G.useCallback)(e=>i.selectors.isActive(e,s,o),[s,o])),m=r.isSelected(s),h=(0,G.useRef)(null),g=Se({disabled:c,value:s,domRef:h,order:l}),_=(0,G.useContext)(Wt),y=L(t,h,_?_.measureElement:null),b=V(()=>{i.actions.setIsTyping(!1),i.actions.onChange(s)});z(()=>i.actions.registerOption(o,g),[g,o]);let x=I(i,(0,G.useCallback)(e=>i.selectors.shouldScrollIntoView(e,s,o),[s,o]));z(()=>{if(x)return R().requestAnimationFrame(()=>{var e,t;(t=(e=h.current)?.scrollIntoView)==null||t.call(e,{block:`nearest`})})},[x,h]);let S=V(e=>{e.preventDefault(),e.button===j.Left&&(c||(b(),Ae()||requestAnimationFrame(()=>f()),r.mode===Z.Single&&i.actions.closeCombobox()))}),C=V(()=>{if(c)return i.actions.goToOption({focus:v.Nothing});let e=r.calculateIndex(s);i.actions.goToOption({focus:v.Specific,idx:e})}),w=O(),T=V(e=>w.update(e)),E=V(e=>{if(!w.wasMoved(e)||c||p&&i.state.activationTrigger===Q.Pointer)return;let t=r.calculateIndex(s);i.actions.goToOption({focus:v.Specific,idx:t},Q.Pointer)}),D=V(e=>{w.wasMoved(e)&&(c||p&&(r.optionsPropsRef.current.hold||i.state.activationTrigger===Q.Pointer&&i.actions.goToOption({focus:v.Nothing})))}),k=me({active:p,focus:p,selected:m,disabled:c}),ee={id:o,ref:y,role:`option`,tabIndex:c===!0?void 0:-1,"aria-disabled":c===!0||void 0,"aria-selected":m,disabled:void 0,onMouseDown:S,onFocus:C,onPointerEnter:T,onMouseEnter:T,onPointerMove:E,onMouseMove:E,onPointerLeave:D,onMouseLeave:D};return ve()({ourProps:ee,theirProps:u,slot:k,defaultTag:tn,name:`Combobox.Option`})}var rn=Ee(qt),an=Ee(Zt),on=Ee(Yt),sn=f,cn=Ee(en),ln=Ee(nn),un=Object.assign(rn,{Input:on,Button:an,Label:sn,Options:cn,Option:ln});function dn({options:e,value:t,onChange:n,placeholder:r=`搜索并选择…`,disabled:i=!1,allowEmpty:a=!0,emptyLabel:o=`不选择`}){let[s,c]=(0,G.useState)(``),l=(0,G.useMemo)(()=>{let t=s.trim().toLowerCase();return t?e.filter(e=>e.label.toLowerCase().includes(t)||e.value.toLowerCase().includes(t)):e},[e,s]),u=e.find(e=>e.value===t)??null;return i?(0,K.jsx)(`div`,{className:`relative mt-1`,children:(0,K.jsxs)(`button`,{type:`button`,disabled:!0,className:`w-full h-9 flex items-center justify-between gap-2 rounded-lg border border-stone-200 bg-stone-50 px-3 text-sm text-left text-stone-400 cursor-not-allowed`,children:[(0,K.jsx)(`span`,{className:`truncate`,children:r}),(0,K.jsx)(`svg`,{className:`w-4 h-4 text-stone-400 shrink-0`,viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,K.jsx)(`path`,{fillRule:`evenodd`,d:`M5.23 7.21a.75.75 0 011.06.02L10 11.17l3.71-3.94a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z`,clipRule:`evenodd`})})]})}):(0,K.jsx)(un,{value:u,onChange:e=>{n(e?.value??``),c(``)},immediate:!0,children:(0,K.jsxs)(`div`,{className:`relative mt-1`,children:[(0,K.jsx)(on,{className:`w-full h-9 rounded-lg border border-stone-200 bg-white px-3 pr-8 text-sm outline-none cursor-text placeholder:text-stone-400 focus:ring-2 focus:ring-[#4176e6]/30 focus:border-[#4176e6]`,displayValue:e=>e?.label??``,onChange:e=>c(e.target.value),placeholder:r}),(0,K.jsx)(an,{className:`absolute inset-y-0 right-0 flex items-center pr-2 text-stone-400 cursor-pointer`,children:(0,K.jsx)(`svg`,{className:`w-4 h-4`,viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,K.jsx)(`path`,{fillRule:`evenodd`,d:`M5.23 7.21a.75.75 0 011.06.02L10 11.17l3.71-3.94a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z`,clipRule:`evenodd`})})}),(0,K.jsxs)(cn,{transition:!0,anchor:{to:`bottom start`,gap:4},className:`tw-select-menu tw-menu-anim z-80 max-h-56 w-(--input-width) overflow-auto rounded-lg p-1 shadow-lg ring-1 ring-stone-200 focus:outline-none`,children:[a?(0,K.jsx)(ln,{value:null,className:`cursor-pointer select-none rounded-md px-3 py-2 text-sm text-stone-400 data-[focus]:bg-stone-50`,children:o}):null,l.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-stone-400`,children:`无匹配项`}):l.map(e=>(0,K.jsx)(ln,{value:e,className:`cursor-pointer select-none rounded-md px-3 py-2 text-sm text-stone-700 data-[focus]:bg-stone-50 data-[selected]:font-medium`,children:e.label},e.value))]})]})})}export{$e as a,Ve as c,Ue as d,He as f,Qe as i,ze as l,it as n,tt as o,nt as r,rt as s,dn as t,W as u};
1
+ import{c as e,n as t,t as n}from"./react-dom.CqAxpHMt.js";import{H as r,U as i,V as a,W as o,p as s,r as c,t as l,u}from"./app-config.vqDkEMS3.js";import{t as d}from"./jsx-runtime.BUXbF_vF.js";import{C as f,D as p,E as m,S as h,T as g,_,a as v,c as y,f as b,g as x,h as S,i as C,l as w,m as T,n as E,o as D,p as O,r as k,s as ee,u as A,v as j,w as te,x as M,y as ne}from"./use-text-value.C0IDspmh.js";import{C as N,F as re,H as P,I as ie,J as F,L as ae,M as oe,P as I,U as L,X as se,_ as ce,_t as R,at as le,c as ue,d as de,dt as fe,f as pe,ft as me,g as he,gt as ge,h as _e,ht as z,it as ve,j as ye,l as be,lt as B,m as xe,mt as Se,n as Ce,nt as we,o as Te,ot as Ee,p as De,pt as V,s as Oe,tt as H,v as ke,x as Ae,yt as je,z as U}from"./portal.C3KrUREL.js";import{a as Me,c as Ne,l as Pe,o as Fe,s as Ie,u as Le}from"./listbox.DdDDDJ5Z.js";import{t as Re}from"./use-tree-walker.oRTnhHS-.js";a.map(e=>({value:e.id,label:e.label,casesFolder:e.casesFolder,templateFolder:e.templateFolder}));function W(){let e=c().caseTypes;return e?.length?e.map(e=>({...e})):a.map(e=>({...e}))}function ze(e){let t=W();return t.find(t=>t.id===e)??t[0]??a[0]}function Be(e){let t=o(e);return u({caseTypes:t}),l(),t}function Ve(e){let t=e.trim();if(!t)throw Error(`类型名称不能为空`);if(t.length>40)throw Error(`类型名称过长(最多 40 字)`);let n=W();if(n.some(e=>e.label===t))throw Error(`已存在「${t}」`);let a=r(t),o={id:i(),label:t,...a};return Be([...n,o]),o}function He(e,t){let n=t.trim();if(!n)throw Error(`类型名称不能为空`);if(n.length>40)throw Error(`类型名称过长(最多 40 字)`);let i=W(),a=i.findIndex(t=>t.id===e);if(a<0)throw Error(`类型不存在`);if(i.some(t=>t.id!==e&&t.label===n))throw Error(`已存在「${n}」`);let o=r(n),s={...i[a],label:n,...o},c=[...i];return c[a]=s,Be(c),s}function Ue(e){let t=W();if(t.length<=1)throw Error(`至少保留一个用例类型`);if(!t.some(t=>t.id===e))throw Error(`类型不存在`);return Be(t.filter(t=>t.id!==e))}var We=`/__tb_case_sessions`,Ge=`tw.case.sessions.v1`,Ke=!1;function qe(){return`csess_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`}function Je(e){if(typeof e==`string`&&e.trim()){let t=e.trim();return W().some(e=>e.id===t),t}return W()[0]?.id??`functional`}function Ye(e){if(!e||!Array.isArray(e.sessions))return{sessions:[],activeId:``};let t=e.sessions.filter(e=>e&&typeof e==`object`&&e.id).map(e=>({...e,caseType:Je(e.caseType)})),n=typeof e.activeId==`string`?e.activeId:``;return t.length&&!t.some(e=>e.id===n)&&(n=t[0].id),t.length||(n=``),{sessions:t,activeId:n}}function Xe(){try{let e=localStorage.getItem(s(Ge));return e?Ye(JSON.parse(e)):{sessions:[],activeId:``}}catch{return{sessions:[],activeId:``}}}function Ze(e){try{localStorage.setItem(s(Ge),JSON.stringify(e))}catch{}}async function Qe(){try{let e=await fetch(We,{signal:AbortSignal.timeout(2e3)});if(e.ok){let t=await e.json();Ke=!0;let n=Ye(t.store);return Ze(n),n}}catch{}return Ke=!1,Xe()}function $e(){return Xe()}async function et(e){if(Ze(e),Ke)try{await fetch(We,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({store:e})})}catch{}}function tt(e){Ze(e),et(e)}function nt(e){let t=Date.now(),n={id:qe(),title:e.title?.trim()||`用例生成`,createdAt:t,updatedAt:t,caseType:e.caseType,outputFormat:e.outputFormat,reqPaths:e.reqPaths,templateId:e.templateId,templateTitle:e.templateTitle,promptPath:e.promptPath,knowledgePaths:e.knowledgePaths?.length?[...e.knowledgePaths]:void 0,messages:[]};return tt({sessions:[n,...Xe().sessions],activeId:n.id}),n}function rt(e,t){let n=Xe(),r=n.sessions.map(n=>n.id===e?{...n,...t,updatedAt:Date.now()}:n),i={...n,sessions:r};return tt(i),i}var G=e(t(),1),K=d();function it({options:e,values:t,onChange:n,placeholder:r=`选择…`,disabled:i=!1}){let[a,o]=(0,G.useState)(!1),s=(0,G.useRef)(null);(0,G.useEffect)(()=>{if(!a)return;function e(e){s.current?.contains(e.target)||o(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[a]);let c=e.filter(e=>t.includes(e.value)).map(e=>e.label),l=i||c.length===0?r:c.length<=2?c.join(`、`):`已选 ${c.length} 项`;function u(e){t.includes(e)?n(t.filter(t=>t!==e)):n([...t,e])}return(0,K.jsxs)(`div`,{className:`relative mt-1`,ref:s,children:[(0,K.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>o(e=>!e),className:i?`w-full h-9 flex items-center justify-between gap-2 rounded-lg border border-stone-200 bg-stone-50 px-3 text-sm text-left text-stone-400 cursor-not-allowed`:`w-full h-9 flex items-center justify-between gap-2 rounded-lg border border-stone-200 bg-white px-3 text-sm text-left text-stone-800 outline-none hover:border-stone-300 focus:ring-2 focus:ring-[#4176e6]/30`,children:[(0,K.jsx)(`span`,{className:`truncate ${i||c.length?``:`text-stone-400`}`,children:l}),(0,K.jsx)(`svg`,{className:`w-4 h-4 text-stone-400 shrink-0`,viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,K.jsx)(`path`,{fillRule:`evenodd`,d:`M5.23 7.21a.75.75 0 011.06.02L10 11.17l3.71-3.94a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z`,clipRule:`evenodd`})})]}),a?(0,K.jsx)(`div`,{className:`tw-select-menu tw-popover-anim absolute z-80 mt-1 max-h-56 w-full overflow-auto rounded-lg p-1 shadow-lg ring-1 ring-stone-200`,children:e.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-stone-400`,children:`暂无可选项`}):e.map(e=>{let n=t.includes(e.value);return(0,K.jsxs)(`label`,{className:`flex items-center gap-2 rounded-md px-3 py-2 text-sm text-stone-700 cursor-pointer hover:bg-stone-50`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:n,onChange:()=>u(e.value),className:`rounded border-stone-300 text-[#4176e6] focus:ring-[#4176e6]/40`}),(0,K.jsx)(`span`,{className:`truncate`,children:e.label})]},e.value)})}):null]})}var q=e(n(),1);function at(e){return typeof e==`object`?e.key:e}function ot(e,t){let n=e.length;return new Proxy(e,{get(e,r,i){if(typeof r==`string`){let i=r.charCodeAt(0);if(i>=48&&i<=57){let i=+r;if(Number.isInteger(i)&&i>=0&&i<n){let n=e[i];if(typeof n!=`object`){let r=t[i*2];n=e[i]={index:i,key:n,start:r,size:t[i*2+1],end:r+t[i*2+1],lane:0}}return n}}if(r===`length`)return n}return Reflect.get(e,r,i)}})}function J(e,t,n){let r=n.initialDeps??[],i,a=!0;function o(){let o=e();return(o.length!==r.length||o.some((e,t)=>r[t]!==e))&&(r=o,i=t(...o),n?.onChange&&!(a&&n.skipInitialOnChange)&&n.onChange(i),a=!1),i}return o.updateDeps=e=>{r=e},o}function st(e,t){if(e===void 0)throw Error(`Unexpected undefined${t?`: ${t}`:``}`);return e}var Y=(e,t)=>Math.abs(e-t)<1.01,ct=(e,t,n)=>{let r;return Object.assign(function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)},{cancel:()=>{e.clearTimeout(r)}})},lt,ut=()=>{if(lt!==void 0)return lt;if(typeof navigator>`u`)return lt=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return lt=!0;let e=navigator.maxTouchPoints;return lt=navigator.platform===`MacIntel`&&e!==void 0&&e>0},dt=e=>{let{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},ft=e=>e,pt=e=>{let t=e.overscan*Math.max(e.lanes??1,1),n=Math.max(e.startIndex-t,0),r=Math.min(e.endIndex+t,e.count-1)-n+1,i=Array(r);for(let e=0;e<r;e++)i[e]=n+e;return i},mt=(e,t)=>{let n=e.scrollElement;if(!n)return;let r=e.targetWindow;if(!r)return;let i=e=>{let{width:n,height:r}=e;t({width:Math.round(n),height:Math.round(r)})};if(i(dt(n)),!r.ResizeObserver)return()=>{};let a=new r.ResizeObserver(t=>{let r=()=>{let e=t[0];if(e?.borderBoxSize){let t=e.borderBoxSize[0];if(t){i({width:t.inlineSize,height:t.blockSize});return}}i(dt(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(r):r()});return a.observe(n,{box:`border-box`}),()=>{a.unobserve(n)}},ht={passive:!0},gt=typeof window>`u`||`onscrollend`in window,_t=(e,t,n)=>{let r=e.scrollElement;if(!r)return;let i=e.targetWindow;if(!i)return;let a=e.options.useScrollendEvent&&gt,o=0,s=a?null:ct(i,()=>t(n(r),!1),e.options.isScrollingResetDelay),c=e=>()=>{o=n(r),s?.(),t(o,e)},l=c(!0),u=c(!1);return r.addEventListener(`scroll`,l,ht),a&&r.addEventListener(`scrollend`,u,ht),()=>{r.removeEventListener(`scroll`,l),a&&r.removeEventListener(`scrollend`,u),s?.cancel()}},vt=(e,t)=>_t(e,t,t=>{let{horizontal:n,isRtl:r}=e.options;return n?t.scrollLeft*(r&&-1||1):t.scrollTop}),yt=(e,t,n)=>{if(n.options.useCachedMeasurements){let t=n.indexFromElement(e),r=n.options.getItemKey(t);return n.itemSizeCache.get(r)??n.options.estimateSize(t)}if(t?.borderBoxSize){let e=t.borderBoxSize[0];if(e)return Math.round(e[n.options.horizontal?`inlineSize`:`blockSize`])}if(!t){let t=n.indexFromElement(e),r=n.options.getItemKey(t),i=n.itemSizeCache.get(r);if(i!==void 0)return i}return e[n.options.horizontal?`offsetWidth`:`offsetHeight`]},bt=(e,{adjustments:t=0,behavior:n},r)=>{var i,a;(a=(i=r.scrollElement)?.scrollTo)==null||a.call(i,{[r.options.horizontal?`left`:`top`]:e+t,behavior:n})},xt=(e,t)=>e===`smooth`?t?`smoothLanded`:`smooth`:`instant`,St=e=>e?.phase===`smooth`||e?.phase===`smoothLanded`,Ct=e=>e.phase===`smooth`||e.phase===`smoothFinishing`;function wt(e,t,n,r){if(t===0)return!1;let i=r(0),a=new Set,o=0;for(;o<e;){let e=n(o);if(e===i)break;a.add(e),o++}let s=e-o;if(s===0||s>=t)return!1;for(let e=0;e<s;e++)if(r(e)!==n(o+e))return!1;for(let e=s;e<t;e++)if(a.has(r(e)))return!1;return!0}var Tt=class{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this._clampedAdjustment=null,this.elementsCache=new Map,this._resizeBatch=null,this.now=()=>{var e;return((e=this.targetWindow?.performance)?.now)?.call(e)??Date.now()},this.observer=(()=>{let e=null,t=()=>e||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:e=new this.targetWindow.ResizeObserver(e=>{let t=()=>{let t={sync:!1};this._resizeBatch=t;try{e.forEach(n)}finally{this._resizeBatch=null,t.notify&&(this.notify(t.sync),this._retryClampedAdjustment())}};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(t):t()})),n=e=>{let t=e.target,n=this.indexFromElement(t);if(t.isConnected)this.isIndexInRange(n)&&this.shouldMeasureDuringScroll(n)&&this.resizeItem(n,this.options.measureElement(t,e,this));else{this.observer.unobserve(t);for(let[e,n]of this.elementsCache)if(n===t){this.elementsCache.delete(e);break}}};return{disconnect:()=>{var n;(n=t())==null||n.disconnect(),e=null},observe:e=>t()?.observe(e,{box:`border-box`}),unobserve:e=>t()?.unobserve(e)}})(),this.range=null,this.setOptions=e=>{let t={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:ft,rangeExtractor:pt,onChange:()=>{},measureElement:yt,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:`data-index`,initialMeasurementsCache:[],lanes:1,anchorTo:`start`,followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:`estimate`,useCachedMeasurements:!1};for(let n in e){let r=e[n];r!==void 0&&(t[n]=r)}let n=this.options,r=null,i=null,a=!1;if(n!==void 0&&n.enabled&&t.enabled&&t.anchorTo===`end`&&this.scrollElement!==null){let e=n.count,o=t.count,s=this.getMeasurements(),c=this._singleLaneMeasurements?.items??s,l=e=>at(c[e]),u=e>0?l(0):null,d=e>0?l(e-1):null;if(o!==e||e>0&&o>0&&(t.getItemKey(0)!==u||t.getItemKey(o-1)!==d)){a=!0;let c=e>0?this.getVirtualItemForOffset(this.getScrollOffset())??s[0]:null;c&&(r=[c.key,this.getScrollOffset()-c.start]);let u=t.followOnAppend===!0?`auto`:t.followOnAppend||null;u&&o>0&&this.isAtEnd(n.scrollEndThreshold)&&(e===0||t.getItemKey(o-1)!==d)&&(o>e||wt(e,o,l,t.getItemKey))&&(i=u)}}this.options=t,a&&(this.pendingMin=0,this.itemSizeCacheVersion++);let o=!1,s=0;if(r&&this.scrollOffset!==null){let[e,t]=r,n=this.getMeasurements(),{count:a,getItemKey:c}=this.options,l=0;for(;l<a&&c(l)!==e;)l++;if(l<a){let e=n[l];if(e){let n=Math.max(0,e.start+t);!i&&n!==this.scrollOffset&&(s=n-this.scrollOffset,this.scrollOffset=n,o=!0)}}}(o||i)&&(this.pendingScrollAnchor=[o?r[0]:null,o?r[1]:0,i,s])},this.notify=e=>{var t,n;(n=(t=this.options).onChange)==null||n.call(t,this,e)},this.maybeNotify=J(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),e=>{this.notify(e)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(e=>e()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.isScrolling=!1,this.scrollDirection=null,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._clampedAdjustment=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{let e=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==e){if(this.cleanup(),!e){this.maybeNotify();return}if(this.scrollElement=e,this.targetWindow=this.scrollElement&&`ownerDocument`in this.scrollElement?this.scrollElement.ownerDocument.defaultView:this.scrollElement?.window??null,this.elementsCache.forEach(e=>{this.observer.observe(e)}),this.unsubs.push(this.options.observeElementRect(this,e=>{this.scrollRect=e,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(e,t)=>{if(t&&this._intendedScrollOffset===null&&e===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(e-this._intendedScrollOffset)<1.5?e=this._intendedScrollOffset:this.scrollState?.index!=null&&!Ct(this.scrollState)&&!Y(e,this.scrollState.lastTargetOffset)&&!Y(e,this.getScrollStateTarget(this.scrollState))&&(this._clampedAdjustment===null||Math.abs(e-this._clampedAdjustment.maxAtWrite)>=1.5)&&(this.scrollState=null),this._intendedScrollOffset=null,this.scrollState&&(this.scrollState.writtenOffset=null),this._clampedAdjustment!==null&&Math.abs(e-this._clampedAdjustment.maxAtWrite)>=1.5&&(this._clampedAdjustment=null),this.scrollAdjustments=0;let n=this.getScrollOffset();this.scrollDirection=t?n===e?this.scrollDirection:n<e?`forward`:`backward`:null,this.scrollOffset=e,this.isScrolling=t,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),`addEventListener`in this.scrollElement){let e=this.scrollElement,t=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},n=()=>{this._iosTouching=!1,ut()&&this.targetWindow!=null&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};e.addEventListener(`touchstart`,t,ht),e.addEventListener(`touchend`,n,ht),e.addEventListener(`touchcancel`,n,ht),this.unsubs.push(()=>{e.removeEventListener(`touchstart`,t),e.removeEventListener(`touchend`,n),e.removeEventListener(`touchcancel`,n),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}let t=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,t&&this.scrollElement&&this.options.enabled){let[e,n,r,i]=t;e!==null&&!r&&(ut()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?i!==0&&(this._iosDeferredAdjustment+=i):St(this.scrollState)&&!Y(this.getScrollOffset()-i,this.scrollState.lastTargetOffset)||this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),r&&this.scrollToEnd({behavior:r})}this._retryClampedAdjustment()},this._retryClampedAdjustment=()=>{if(this._clampedAdjustment===null||!this.scrollElement||!this.options.enabled)return;let{target:e,maxAtWrite:t}=this._clampedAdjustment,n=this.getMaxScrollOffset();n>t+.5&&(this._clampedAdjustment=e>n+.5?{target:e,maxAtWrite:n}:null,this._scrollToOffset(e,{adjustments:void 0,behavior:void 0}))},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;let e=this.getScrollOffset(),t=this.getMaxScrollOffset();if(e<0||e>t)return;if(this._iosDeferredAdjustment<0&&e>=t-1){this._iosDeferredAdjustment=0;return}let n=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(e,{adjustments:this.scrollAdjustments+=n,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?`width`:`height`]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset==`function`?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=J(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(e,t,n,r,i,a,o,s)=>(this.prevLanes!==void 0&&this.prevLanes!==a&&(this.lanesChangedFlag=!0),this.prevLanes=a,this.pendingMin=null,{count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o,gap:s}),{key:!1}),this.isIndexInRange=e=>e>=0&&e<this.options.count,this.getMeasurements=J(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o,gap:s},c)=>{let l=this.itemSizeCache;if(!i)return this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>e)for(let t of this.laneAssignments.keys())t>=e&&this.laneAssignments.delete(t);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(e=>{this.itemSizeCache.set(e.key,e.size)}));let u=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===e&&(this.lanesSettling=!1),a===1){let i=e*2,a=this._singleLaneMeasurements?.flat;if(!a||a.length<i){let e=new Float64Array(i);a&&u>0&&e.set(a.subarray(0,u*2)),a=e}let o=u===0?Array(e):this._singleLaneMeasurements.items.slice(),c;if(u===0)c=t+n;else{let e=u-1;c=a[e*2]+a[e*2+1]+s}for(let t=u;t<e;t++){let e=r(t);o[t]=e;let n=l.get(e),i=typeof n==`number`?n:this.options.estimateSize(t);a[t*2]=c,a[t*2+1]=i,c+=i+s}this._singleLaneMeasurements={flat:a,items:o};let d=ot(o,a);return this.measurementsCache=d,d}let d=this.measurementsCache.slice(0,u),f=Array(a).fill(void 0),p=new Float64Array(a),m=0;for(let e=0;e<u;e++){let t=d[e];t&&(f[t.lane]===void 0&&m++,f[t.lane]=e,p[t.lane]=t.end)}for(let i=u;i<e;i++){let e=r(i),c=this.laneAssignments.get(i),u,h,g=o===`estimate`||l.has(e);if(c!==void 0&&this.options.lanes>1){u=c;let e=f[u],r=e===void 0?void 0:d[e];h=r?r.end+s:t+n}else if(m===a){let e=0,t=p[0],n=f[0];for(let r=1;r<a;r++){let i=p[r];(i<t||i===t&&f[r]<n)&&(e=r,t=i,n=f[r])}u=e,h=t+s,g&&this.laneAssignments.set(i,u)}else u=i%this.options.lanes,h=t+n,g&&this.laneAssignments.set(i,u);let _=l.get(e),v=typeof _==`number`?_:this.options.estimateSize(i),y=h+v;d[i]={index:i,start:h,size:v,end:y,key:e,lane:u},f[u]===void 0&&m++,f[u]=i,p[u]=y}return this.measurementsCache=d,d},{key:!1,debug:()=>this.options.debug}),this.calculateRange=J(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,r)=>e.length===0||t===0?(this.range=null,null):(this.range=Ot(e,t,n,r,r===1&&this._singleLaneMeasurements!==null?this._singleLaneMeasurements.flat:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=J(()=>{let e=null,t=null,n=this.calculateRange();return n&&(e=n.startIndex,t=n.endIndex),this.maybeNotify.updateDeps([this.isScrolling,e,t]),[this.options.rangeExtractor,this.options.overscan,this.options.count,e,t,this.options.lanes]},(e,t,n,r,i,a)=>r===null||i===null?[]:e({startIndex:r,endIndex:i,overscan:t,count:n,lanes:a}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=e=>{let t=this.options.indexAttribute,n=e.getAttribute(t);return n?parseInt(n,10):(console.warn(`Missing attribute name '${t}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=e=>{if(!St(this.scrollState))return!0;let t=this.scrollState.index??this.getVirtualItemForOffset(this.scrollState.lastTargetOffset)?.index;if(t!==void 0&&this.range){let n=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),r=Math.max(0,t-n),i=Math.min(this.options.count-1,t+n);return e>=r&&e<=i}return!0},this.measureElement=e=>{if(!e){this.elementsCache.forEach((e,t)=>{e.isConnected||(this.observer.unobserve(e),this.elementsCache.delete(t))});return}let t=this.indexFromElement(e);if(!this.isIndexInRange(t))return;let n=this.options.getItemKey(t),r=this.elementsCache.get(n);r!==e&&(r&&this.observer.unobserve(r),this.observer.observe(e),this.elementsCache.set(n,e)),e.isConnected&&(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(t)&&this.resizeItem(t,this.options.measureElement(e,void 0,this))},this.resizeItem=(e,t)=>{var n;if(!this.isIndexInRange(e))return;this._resizeBatch?.sync&&this.getMeasurements();let r,i,a,o=this._singleLaneMeasurements?.flat;if(this.options.lanes===1&&o!=null)a=this.options.getItemKey(e),i=o[e*2],r=o[e*2+1];else{let t=this.measurementsCache[e];if(!t)return;a=t.key,i=t.start,r=t.size}let s=this.itemSizeCache.get(a)??r,c=t-s;if(c!==0){let o=this.options.anchorTo===`end`&&!St(this.scrollState)&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,l=o?this.getTotalSize():0,u=this.getScrollOffset()+this.scrollAdjustments,d=this.itemSizeCache.has(a)?i+s<=u&&this.scrollDirection!==`backward`:i<u,f=!St(this.scrollState)&&(this.shouldAdjustScrollPositionOnItemSizeChange===void 0?d:this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[e]??{index:e,key:a,start:i,size:r,end:i+r,lane:0},c,this));(this.pendingMin===null||e<this.pendingMin)&&(this.pendingMin=e),this.itemSizeCache.set(a,t),this.itemSizeCacheVersion++;let p=this.scrollState?.writtenOffset!=null&&!Y(this.scrollState.writtenOffset,this.getScrollOffset()+this.scrollAdjustments),m=!1;if(p||(o?m=this.applyScrollAdjustment(this.getTotalSize()-l):f&&(m=this.applyScrollAdjustment(c))),this._resizeBatch){this._resizeBatch.notify=!0,(n=this._resizeBatch).sync||(n.sync=m);return}this.notify(m),this._retryClampedAdjustment()}},this.getVirtualItems=J(()=>[this.getVirtualIndexes(),this.getMeasurements()],(e,t)=>{let n=[];for(let r=0,i=e.length;r<i;r++){let i=t[e[r]];n.push(i)}return n},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=e=>{let t=this.getMeasurements();if(t.length===0)return;let n=this._singleLaneMeasurements?.flat,r=this.options.lanes===1&&n!=null;return st(t[Et(0,t.length-1,r?e=>n[e*2]:e=>st(t[e]).start,e)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if(`scrollHeight`in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{let e=this.scrollElement.document.documentElement;return this.options.horizontal?e.scrollWidth-this.scrollElement.innerWidth:e.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(e=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=e,this.getOffsetForAlignment=(e,t,n=0)=>{if(!this.scrollElement)return 0;let r=this.getSize(),i=this.getScrollOffset();t===`auto`&&(t=e>=i+r?`end`:`start`),t===`center`?e+=(n-r)/2:t===`end`&&(e-=r);let a=this.getMaxScrollOffset();return Math.max(Math.min(a,e),0)},this.getOffsetForIndex=(e,t=`auto`)=>{e=Math.max(0,Math.min(e,this.options.count-1));let n=this.getSize(),r=this.getScrollOffset(),i=this.measurementsCache[e];if(!i)return;if(t===`auto`){if(i.end>=r+n-this.options.scrollPaddingEnd)t=`end`;else if(i.start<=r+this.options.scrollPaddingStart)t=`start`;else return[r,t]}if(t===`end`&&e===this.options.count-1){let e=this.getMaxScrollOffset(),n=e-this.options.paddingEnd+this.options.scrollPaddingEnd;return[Math.max(Math.min(n,e),0),t]}let a=t===`end`?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,t,i.size),t]},this.scrollToOffset=(e,{align:t=`start`,behavior:n=`auto`}={})=>{this._iosDeferredAdjustment=0;let r=this.getOffsetForAlignment(e,t),i=this.now();this.scrollState={index:null,align:t,startedAt:i,lastTargetOffset:r,stableFrames:0,phase:xt(n,!1)},this._scrollToOffset(r,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollToIndex=(e,{align:t=`auto`,behavior:n=`auto`}={})=>{this._iosDeferredAdjustment=0,e=Math.max(0,Math.min(e,this.options.count-1));let r=this.getOffsetForIndex(e,t);if(!r)return;let[i,a]=r,o=this.now();this.scrollState={index:e,align:a,startedAt:o,lastTargetOffset:i,stableFrames:0,phase:xt(n,Y(i,this.getScrollOffset()))},this._scrollToOffset(i,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollBy=(e,{behavior:t=`auto`}={})=>{let n=this.getOffsetForAlignment((this.scrollState?.writtenOffset??this.getScrollOffset())+e,`start`),r=this.now();this.scrollState={index:null,align:`start`,startedAt:r,lastTargetOffset:n,stableFrames:0,phase:xt(t,!1)},this._scrollToOffset(n,{adjustments:void 0,behavior:t}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:e=`auto`}={})=>{if(this.options.count>0){this._iosDeferredAdjustment=0;let t=Math.max(this.getMaxScrollOffset(),0);this.scrollState={index:this.options.count-1,align:`end`,toEnd:!0,startedAt:this.now(),lastTargetOffset:t,stableFrames:0,phase:xt(e,Y(t,this.getScrollOffset()))},this._scrollToOffset(t,{adjustments:void 0,behavior:e}),this.scheduleScrollReconcile()}else this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:e})},this.cancelScroll=()=>{this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null},this.getTotalSize=()=>{let e=this.getMeasurements(),t;if(e.length===0)t=this.options.paddingStart;else if(this.options.lanes===1){let n=e.length-1,r=this._singleLaneMeasurements?.flat;t=r==null?e[n]?.end??0:r[n*2]+r[n*2+1]}else{let n=Array(this.options.lanes).fill(null),r=e.length-1;for(;r>=0&&n.some(e=>e===null);){let t=e[r];n[t.lane]===null&&(n[t.lane]=t.end),r--}t=Math.max(...n.filter(e=>e!==null))}return Math.max(t-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{let e=[];if(this.itemSizeCache.size===0)return e;let t=this.getMeasurements();for(let n of t)n&&this.itemSizeCache.has(n.key)&&e.push({index:n.index,key:n.key,start:n.start,size:n.size,end:n.end,lane:n.lane});return e},this._scrollToOffset=(e,{adjustments:t,behavior:n})=>{this._intendedScrollOffset=e+(t??0),this.scrollState&&(this.scrollState.writtenOffset=n===`smooth`?null:this._intendedScrollOffset),this.options.scrollToFn(e,{behavior:n,adjustments:t},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(e)}applyScrollAdjustment(e,t){if(e===0)return!1;if(ut()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded))return this.scrollState?.index??(this._iosDeferredAdjustment+=e),!1;{let n=this.getScrollOffset()+this.scrollAdjustments+e,r=this.scrollElement,i=r!==null&&(`scrollHeight`in r||`document`in r)?this.getMaxScrollOffset():null;return this._clampedAdjustment=i!==null&&n>i+.5?{target:n,maxAtWrite:i}:null,this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=e,behavior:t}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollOffset<0&&(this.scrollOffset=0),this.scrollAdjustments=0),!0}}scheduleScrollReconcile(){this.targetWindow?this.rafId??=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}):this.scrollState=null}getScrollStateTarget(e){let t=e.toEnd?[Math.max(this.getMaxScrollOffset(),0)]:e.index==null?void 0:this.getOffsetForIndex(e.index,e.align);return t?t[0]:e.lastTargetOffset}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}this.getMeasurements();let e=this.getScrollStateTarget(this.scrollState),t=this.scrollState.index==null?1:this.options.useAnimationFrameWithResizeObserver?3:2,n=e!==this.scrollState.lastTargetOffset;if(!n&&Y(e,this.getScrollOffset())){if(this.scrollState.phase===`smooth`?this.scrollState.phase=`smoothLanded`:this.scrollState.phase===`smoothFinishing`&&(this.scrollState.phase=`instant`),this.scrollState.stableFrames++,this.scrollState.stableFrames>=t){this.getScrollOffset()!==e&&this._scrollToOffset(e,{adjustments:void 0,behavior:`auto`}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,n){let t=this.getSize()||600,n=Math.abs(e-this.getScrollOffset()),r=St(this.scrollState)&&n>t;this.scrollState.lastTargetOffset=e,r?this.scrollState.phase=`smooth`:this.scrollState.phase===`smooth`?this.scrollState.phase=`smoothFinishing`:this.scrollState.phase===`smoothLanded`&&(this.scrollState.phase=`instant`),this._scrollToOffset(e,{adjustments:void 0,behavior:r?`smooth`:`auto`})}this.scheduleScrollReconcile()}},Et=(e,t,n,r)=>{for(;e<=t;){let i=(e+t)/2|0,a=n(i);if(a<r)e=i+1;else if(a>r)t=i-1;else return i}return e>0?e-1:0};function Dt(e,t,n){let r=0;for(;r<=t;){let i=(r+t)/2|0,a=e[i*2];if(a<n)r=i+1;else if(a>n)t=i-1;else return i}return r>0?r-1:0}function Ot(e,t,n,r,i){let a=e.length-1;if(e.length<=r)return{startIndex:0,endIndex:a};if(r===1&&i!==null){let e=Dt(i,a,n),r=e,o=n+t;for(;r<a&&i[r*2]+i[r*2+1]<o;)r++;return{startIndex:e,endIndex:r}}let o=Et(0,a,t=>e[t].start,n),s=o;if(r===1)for(;s<a&&e[s].end<n+t;)s++;else if(r>1){let i=Array(r).fill(0);for(;s<a&&i.some(e=>e<n+t);){let t=e[s];i[t.lane]=t.end,s++}let c=Array(r).fill(n+t);for(;o>=0&&c.some(e=>e>=n);){let t=e[o];c[t.lane]=t.start,o--}o=Math.max(0,o-o%r),s=Math.min(a,s+(r-1-s%r))}return{startIndex:o,endIndex:s}}var kt=typeof document<`u`?G.useLayoutEffect:G.useEffect;function At({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:n=`transform`,...r}){let i=G.useReducer(e=>e+1,0)[1],a=G.useRef({enabled:t,mode:n,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});a.current.enabled=t,a.current.mode=n;let o=G.useRef(!1),s=e=>{let t=a.current;if(!t.enabled||!t.container)return;let n=e.getTotalSize();if(n!==t.lastSize){t.lastSize=n;let r=e.options.horizontal?`width`:`height`;t.container.style[r]=`${n}px`}},c=(e,t,n)=>{let r=a.current,i=!!e.options.horizontal,o=t.start-e.options.scrollMargin;r.lastPositions.get(n)!==o&&(r.lastPositions.set(n,o),r.mode===`transform`?n.style.transform=i?`translate3d(${o}px, 0, 0)`:`translate3d(0, ${o}px, 0)`:n.style[i?`left`:`top`]=`${o}px`)},l=e=>{let t=a.current;if(t.enabled&&t.container){s(e);for(let t of e.getVirtualItems()){let n=e.elementsCache.get(t.key);n&&c(e,t,n)}}},u={...r,onChange:(t,n)=>{var s;let c=a.current,u=!0;if(c.enabled){l(t);let e=t.range,n=c.prevRange;u=!n||n.isScrolling!==t.isScrolling||n.startIndex!==e?.startIndex||n.endIndex!==e?.endIndex,u&&(c.prevRange=e?{startIndex:e.startIndex,endIndex:e.endIndex,isScrolling:t.isScrolling}:null)}u&&(e&&n&&!o.current?(0,q.flushSync)(i):i()),(s=r.onChange)==null||s.call(r,t,n)}},[d]=G.useState(()=>{let e=new Tt(u),t=e.measureElement;return e.measureElement=n=>{o.current=!0;try{t(n)}finally{o.current=!1}let r=a.current;if(n!==null&&r.enabled&&r.container){let t=e.measurementsCache[e.indexFromElement(n)];t&&c(e,t,n)}},Object.assign(e,{containerRef:t=>{let n=a.current;n.container=t,n.lastSize=null,t!==null&&l(e)}})});return d.setOptions(u),kt(()=>d._didMount(),[]),kt(()=>(s(d),d._willUpdate())),kt(()=>{l(d)}),d}function jt(e){return At({observeElementRect:mt,observeElementOffset:vt,scrollToFn:bt,...e})}function Mt(e){let t=(0,G.useRef)({value:``,selectionStart:null,selectionEnd:null});return he(e,`blur`,e=>{let n=e.target;F(n)&&(t.current={value:n.value,selectionStart:n.selectionStart,selectionEnd:n.selectionEnd})}),V(()=>{if(!je(e)&&F(e)&&e.isConnected){if(e.focus({preventScroll:!0}),e.value!==t.current.value)e.setSelectionRange(e.value.length,e.value.length);else{let{selectionStart:n,selectionEnd:r}=t.current;n!==null&&r!==null&&e.setSelectionRange(n,r)}t.current={value:``,selectionStart:null,selectionEnd:null}}})}var Nt=Object.defineProperty,Pt=(e,t,n)=>t in e?Nt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ft=(e,t,n)=>(Pt(e,typeof t==`symbol`?t:t+``,n),n),X=(e=>(e[e.Open=0]=`Open`,e[e.Closed=1]=`Closed`,e))(X||{}),Z=(e=>(e[e.Single=0]=`Single`,e[e.Multi=1]=`Multi`,e))(Z||{}),Q=(e=>(e[e.Pointer=0]=`Pointer`,e[e.Focus=1]=`Focus`,e[e.Other=2]=`Other`,e))(Q||{}),It=(e=>(e[e.OpenCombobox=0]=`OpenCombobox`,e[e.CloseCombobox=1]=`CloseCombobox`,e[e.GoToOption=2]=`GoToOption`,e[e.SetTyping=3]=`SetTyping`,e[e.RegisterOption=4]=`RegisterOption`,e[e.UnregisterOption=5]=`UnregisterOption`,e[e.DefaultToFirstOption=6]=`DefaultToFirstOption`,e[e.SetActivationTrigger=7]=`SetActivationTrigger`,e[e.UpdateVirtualConfiguration=8]=`UpdateVirtualConfiguration`,e[e.SetInputElement=9]=`SetInputElement`,e[e.SetButtonElement=10]=`SetButtonElement`,e[e.SetOptionsElement=11]=`SetOptionsElement`,e[e.MarkInputAsMoved=12]=`MarkInputAsMoved`,e))(It||{});function Lt(e,t=e=>e){let n=e.activeOptionIndex===null?null:e.options[e.activeOptionIndex],r=t(e.options.slice()),i=r.length>0&&r[0].dataRef.current.order!==null?r.sort((e,t)=>e.dataRef.current.order-t.dataRef.current.order):N(r,e=>e.dataRef.current.domRef.current),a=n?i.indexOf(n):null;return a===-1&&(a=null),{options:i,activeOptionIndex:a}}var Rt={1(e){var t;if((t=e.dataRef.current)!=null&&t.disabled||e.comboboxState===1)return e;let n=e.inputElement?k.Tracked(E(e.inputElement)):e.inputPositionState;return{...e,activeOptionIndex:null,comboboxState:1,isTyping:!1,activationTrigger:2,inputPositionState:n,__demoMode:!1}},0(e){var t,n;if((t=e.dataRef.current)!=null&&t.disabled||e.comboboxState===0)return e;if((n=e.dataRef.current)!=null&&n.value){let t=e.dataRef.current.calculateIndex(e.dataRef.current.value);if(t!==-1)return{...e,activeOptionIndex:t,comboboxState:0,__demoMode:!1,inputPositionState:k.Idle}}return{...e,comboboxState:0,inputPositionState:k.Idle,__demoMode:!1}},3(e,t){return e.isTyping===t.isTyping?e:{...e,isTyping:t.isTyping}},2(e,t){var n,r;if((n=e.dataRef.current)!=null&&n.disabled||e.optionsElement&&!((r=e.dataRef.current)!=null&&r.optionsPropsRef.current.static)&&e.comboboxState===1)return e;if(e.virtual){let{options:n,disabled:r}=e.virtual,i=t.focus===v.Specific?t.idx:D(t,{resolveItems:()=>n,resolveActiveIndex:()=>e.activeOptionIndex??n.findIndex(e=>!r(e))??null,resolveDisabled:r,resolveId(){throw Error(`Function not implemented.`)}}),a=t.trigger??2;return e.activeOptionIndex===i&&e.activationTrigger===a?e:{...e,activeOptionIndex:i,activationTrigger:a,isTyping:!1,__demoMode:!1}}let i=Lt(e);if(i.activeOptionIndex===null){let e=i.options.findIndex(e=>!e.dataRef.current.disabled);e!==-1&&(i.activeOptionIndex=e)}let a=t.focus===v.Specific?t.idx:D(t,{resolveItems:()=>i.options,resolveActiveIndex:()=>i.activeOptionIndex,resolveId:e=>e.id,resolveDisabled:e=>e.dataRef.current.disabled}),o=t.trigger??2;return e.activeOptionIndex===a&&e.activationTrigger===o?e:{...e,...i,isTyping:!1,activeOptionIndex:a,activationTrigger:o,__demoMode:!1}},4:(e,t)=>{var n,r,i,a;if((n=e.dataRef.current)!=null&&n.virtual)return{...e,options:[...e.options,t.payload]};let o=t.payload,s=Lt(e,e=>(e.push(o),e));e.activeOptionIndex===null&&(i=(r=e.dataRef.current).isSelected)!=null&&i.call(r,t.payload.dataRef.current.value)&&(s.activeOptionIndex=s.options.indexOf(o));let c={...e,...s,activationTrigger:2};return(a=e.dataRef.current)!=null&&a.__demoMode&&e.dataRef.current.value===void 0&&(c.activeOptionIndex=0),c},5:(e,t)=>{var n;if((n=e.dataRef.current)!=null&&n.virtual)return{...e,options:e.options.filter(e=>e.id!==t.id)};let r=Lt(e,e=>{let n=e.findIndex(e=>e.id===t.id);return n!==-1&&e.splice(n,1),e});return{...e,...r,activationTrigger:2}},6:(e,t)=>e.defaultToFirstOption===t.value?e:{...e,defaultToFirstOption:t.value},7:(e,t)=>e.activationTrigger===t.trigger?e:{...e,activationTrigger:t.trigger},8:(e,t)=>{if(e.virtual===null)return{...e,virtual:{options:t.options,disabled:t.disabled??(()=>!1)}};if(e.virtual.options===t.options&&e.virtual.disabled===t.disabled)return e;let n=e.activeOptionIndex;if(e.activeOptionIndex!==null){let r=t.options.indexOf(e.virtual.options[e.activeOptionIndex]);n=r===-1?null:r}return{...e,activeOptionIndex:n,virtual:{options:t.options,disabled:t.disabled??(()=>!1)}}},9:(e,t)=>e.inputElement===t.element?e:{...e,inputElement:t.element},10:(e,t)=>e.buttonElement===t.element?e:{...e,buttonElement:t.element},11:(e,t)=>e.optionsElement===t.element?e:{...e,optionsElement:t.element},12(e){return e.inputPositionState.kind===`Tracked`?{...e,inputPositionState:k.Moved}:e}},zt=class e extends ae{constructor(e){super(e),Ft(this,`actions`,{onChange:e=>{let{onChange:t,compare:n,mode:r,value:i}=this.state.dataRef.current;return B(r,{0:()=>t?.(e),1:()=>{let r=i.slice(),a=r.findIndex(t=>n(t,e));return a===-1?r.push(e):r.splice(a,1),t?.(r)}})},registerOption:(e,t)=>(this.send({type:4,payload:{id:e,dataRef:t}}),()=>{this.state.activeOptionIndex===this.state.dataRef.current.calculateIndex(t.current.value)&&this.send({type:6,value:!0}),this.send({type:5,id:e})}),goToOption:(e,t)=>(this.send({type:6,value:!1}),this.send({type:2,...e,trigger:t})),setIsTyping:e=>{this.send({type:3,isTyping:e})},closeCombobox:()=>{var e,t;this.send({type:1}),this.send({type:6,value:!1}),(t=(e=this.state.dataRef.current).onClose)==null||t.call(e)},openCombobox:()=>{this.send({type:0}),this.send({type:6,value:!0})},setActivationTrigger:e=>{this.send({type:7,trigger:e})},selectActiveOption:()=>{let e=this.selectors.activeOptionIndex(this.state);if(e!==null){if(this.actions.setIsTyping(!1),this.state.virtual)this.actions.onChange(this.state.virtual.options[e]);else{let{dataRef:t}=this.state.options[e];this.actions.onChange(t.current.value)}this.actions.goToOption({focus:v.Specific,idx:e})}},setInputElement:e=>{this.send({type:9,element:e})},setButtonElement:e=>{this.send({type:10,element:e})},setOptionsElement:e=>{this.send({type:11,element:e})}}),Ft(this,`selectors`,{activeDescendantId:e=>{let t=this.selectors.activeOptionIndex(e);if(t!==null)return e.virtual?e.options.find(n=>!n.dataRef.current.disabled&&e.dataRef.current.compare(n.dataRef.current.value,e.virtual.options[t]))?.id:e.options[t]?.id},activeOptionIndex:e=>{if(e.defaultToFirstOption&&e.activeOptionIndex===null&&(e.virtual?e.virtual.options.length>0:e.options.length>0)){if(e.virtual){let{options:t,disabled:n}=e.virtual,r=t.findIndex(e=>{var t;return!((t=n?.(e))!=null&&t)});if(r!==-1)return r}let t=e.options.findIndex(e=>!e.dataRef.current.disabled);if(t!==-1)return t}return e.activeOptionIndex},activeOption:e=>{let t=this.selectors.activeOptionIndex(e);return t===null?null:e.virtual?e.virtual.options[t??0]:e.options[t]?.dataRef.current.value??null},isActive:(e,t,n)=>{let r=this.selectors.activeOptionIndex(e);return r===null?!1:e.virtual?r===e.dataRef.current.calculateIndex(t):e.options[r]?.id===n},shouldScrollIntoView:(e,t,n)=>!(e.virtual||e.__demoMode||e.comboboxState!==0||e.activationTrigger===0||!this.selectors.isActive(e,t,n)),didInputMove(e){return e.inputPositionState.kind===`Moved`}});{let e=this.state.id,t=ie.get(null);this.disposables.add(t.on(re.Push,n=>{!t.selectors.isTop(n,e)&&this.state.comboboxState===0&&this.actions.closeCombobox()})),this.on(0,()=>t.actions.push(e)),this.on(1,()=>t.actions.pop(e))}this.disposables.group(e=>{this.on(1,t=>{t.inputElement&&(e.dispose(),e.add(C(t.inputElement,t.inputPositionState,()=>{this.send({type:12})})))})})}static new({id:t,virtual:n=null,__demoMode:r=!1}){return new e({id:t,dataRef:{current:{}},comboboxState:+!r,isTyping:!1,options:[],virtual:n?{options:n.options,disabled:n.disabled??(()=>!1)}:null,activeOptionIndex:null,activationTrigger:2,inputElement:null,buttonElement:null,optionsElement:null,__demoMode:r,inputPositionState:k.Idle})}reduce(e,t){return B(t.type,Rt,e,t)}},Bt=(0,G.createContext)(null);function Vt(e){let t=(0,G.useContext)(Bt);if(t===null){let t=Error(`<${e} /> is missing a parent <Combobox /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(t,Ht),t}return t}function Ht({id:e,virtual:t=null,__demoMode:n=!1}){let r=(0,G.useMemo)(()=>zt.new({id:e,virtual:t,__demoMode:n}),[]);return Te(()=>r.dispose()),r}var Ut=(0,G.createContext)(null);Ut.displayName=`ComboboxDataContext`;function $(e){let t=(0,G.useContext)(Ut);if(t===null){let t=Error(`<${e} /> is missing a parent <Combobox /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(t,$),t}return t}var Wt=(0,G.createContext)(null);function Gt(e){let t=Vt(`VirtualProvider`),{options:n}=$(`VirtualProvider`).virtual,r=I(t,e=>e.optionsElement),[i,a]=(0,G.useMemo)(()=>{let e=r;if(!e)return[0,0];let t=window.getComputedStyle(e);return[parseFloat(t.paddingBlockStart||t.paddingTop),parseFloat(t.paddingBlockEnd||t.paddingBottom)]},[r]),o=jt({enabled:n.length!==0,scrollPaddingStart:i,scrollPaddingEnd:a,count:n.length,estimateSize(){return 40},getScrollElement(){return t.state.optionsElement},overscan:12}),[s,c]=(0,G.useState)(0);z(()=>{c(e=>e+1)},[n]);let l=o.getVirtualItems(),u=I(t,e=>e.activationTrigger===Q.Pointer),d=I(t,t.selectors.activeOptionIndex);return l.length===0?null:G.createElement(Wt.Provider,{value:o},G.createElement(`div`,{style:{position:`relative`,width:`100%`,height:`${o.getTotalSize()}px`},ref:e=>{e&&(u||d!==null&&n.length>d&&o.scrollToIndex(d))}},l.map(t=>G.createElement(G.Fragment,{key:t.key},G.cloneElement(e.children?.call(e,{...e.slot,option:n[t.index]}),{key:`${s}-${t.key}`,"data-index":t.index,"aria-setsize":n.length,"aria-posinset":t.index+1,style:{position:`absolute`,top:0,left:0,transform:`translateY(${t.start}px)`,overflowAnchor:`none`}})))))}var Kt=G.Fragment;function qt(e,t){let n=(0,H.useId)(),r=fe(),{value:i,defaultValue:a,onChange:o,form:s,name:c,by:l,invalid:u=!1,disabled:d=r||!1,onClose:f,__demoMode:p=!1,multiple:m=!1,immediate:g=!1,virtual:_=null,nullable:v,...y}=e,b=Pe(a),[x=m?[]:void 0,S]=Le(i,o,b),C=Ht({id:n,virtual:_,__demoMode:p}),w=(0,G.useRef)({static:!1,hold:!1}),T=Ie(l),E=V(e=>_?l===null?_.options.indexOf(e):_.options.findIndex(t=>T(t,e)):C.state.options.findIndex(t=>T(t.dataRef.current.value,e))),D=(0,G.useCallback)(e=>B(A.mode,{[Z.Multi]:()=>x.some(t=>T(t,e)),[Z.Single]:()=>T(x,e)}),[x]),O=I(C,e=>e.virtual),k=V(()=>f?.()),A=(0,G.useMemo)(()=>({__demoMode:p,immediate:g,optionsPropsRef:w,value:x,defaultValue:b,disabled:d,invalid:u,mode:m?Z.Multi:Z.Single,virtual:_?O:null,onChange:S,isSelected:D,calculateIndex:E,compare:T,onClose:k}),[p,g,w,x,b,d,u,m,_,O,S,D,E,T,k]);z(()=>{_&&C.send({type:It.UpdateVirtualConfiguration,options:_.options,disabled:_.disabled??null})},[_,_?.options,_?.disabled]),z(()=>{C.state.dataRef.current=A},[A]);let[j,te,M,ne]=I(C,e=>[e.comboboxState,e.buttonElement,e.inputElement,e.optionsElement]),N=ie.get(null),re=I(N,(0,G.useCallback)(e=>N.selectors.isTop(e,n),[N,n]));ke(re,[te,M,ne],()=>C.actions.closeCombobox());let P=I(C,C.selectors.activeOptionIndex),F=I(C,C.selectors.activeOption),ae=me({open:j===X.Open,disabled:d,invalid:u,activeIndex:P,activeOption:F,value:x}),[oe,L]=h(),se=t===null?{}:{ref:t},ce=(0,G.useCallback)(()=>{if(b!==void 0)return S?.(b)},[S,b]),R=ve();return G.createElement(L,{value:oe,props:{htmlFor:M?.id},slot:{open:j===X.Open,disabled:d}},G.createElement(ee,null,G.createElement(Ut.Provider,{value:A},G.createElement(Bt.Provider,{value:C},G.createElement(ue,{value:B(j,{[X.Open]:be.Open,[X.Closed]:be.Closed})},c!=null&&G.createElement(Ne,{disabled:d,data:x==null?{}:{[c]:x},form:s,onReset:ce}),R({ourProps:se,theirProps:y,slot:ae,defaultTag:Kt,name:`Combobox`}))))))}var Jt=`input`;function Yt(e,t){let n=Vt(`Combobox.Input`),r=$(`Combobox.Input`),i=(0,H.useId)(),a=te(),{id:o=a||`headlessui-combobox-input-${i}`,onChange:s,displayValue:c,disabled:l=r.disabled||!1,autoFocus:u=!1,type:d=`text`,...f}=e,h=(0,G.useRef)(null),g=L(h,t,y(),n.actions.setInputElement),[_,b]=I(n,e=>[e.comboboxState,e.isTyping]),x=ge(),S=V(()=>{n.actions.onChange(null),n.state.optionsElement&&(n.state.optionsElement.scrollTop=0),n.actions.goToOption({focus:v.Nothing})}),C=(0,G.useMemo)(()=>typeof c==`function`&&r.value!==void 0?c(r.value)??``:typeof r.value==`string`?r.value:``,[r.value,c]);pe(([e,t],[r,i])=>{if(n.state.isTyping)return;let a=h.current;a&&((i===X.Open&&t===X.Closed||e!==r)&&(a.value=e),requestAnimationFrame(()=>{if(n.state.isTyping||!a||je(a))return;let{selectionStart:e,selectionEnd:t}=a;Math.abs((t??0)-(e??0))===0&&e===0&&a.setSelectionRange(a.value.length,a.value.length)}))},[C,_,b]),pe(([e],[t])=>{if(e===X.Open&&t===X.Closed){if(n.state.isTyping)return;let e=h.current;if(!e)return;let t=e.value,{selectionStart:r,selectionEnd:i,selectionDirection:a}=e;e.value=``,e.value=t,a===null?e.setSelectionRange(r,i):e.setSelectionRange(r,i,a)}},[_]);let w=(0,G.useRef)(!1),T=V(()=>{w.current=!0}),E=V(()=>{x.nextFrame(()=>{w.current=!1})}),D=V(e=>{switch(n.actions.setIsTyping(!0),e.key){case U.Enter:if(n.state.comboboxState!==X.Open||w.current)return;if(e.preventDefault(),e.stopPropagation(),n.selectors.activeOptionIndex(n.state)===null){n.actions.closeCombobox();return}n.actions.selectActiveOption(),r.mode===Z.Single&&n.actions.closeCombobox();break;case U.ArrowDown:return e.preventDefault(),e.stopPropagation(),B(n.state.comboboxState,{[X.Open]:()=>n.actions.goToOption({focus:v.Next}),[X.Closed]:()=>n.actions.openCombobox()});case U.ArrowUp:return e.preventDefault(),e.stopPropagation(),B(n.state.comboboxState,{[X.Open]:()=>n.actions.goToOption({focus:v.Previous}),[X.Closed]:()=>{(0,q.flushSync)(()=>n.actions.openCombobox()),r.value||n.actions.goToOption({focus:v.Last})}});case U.Home:if(n.state.comboboxState===X.Closed||e.shiftKey)break;return e.preventDefault(),e.stopPropagation(),n.actions.goToOption({focus:v.First});case U.PageUp:return e.preventDefault(),e.stopPropagation(),n.actions.goToOption({focus:v.First});case U.End:if(n.state.comboboxState===X.Closed||e.shiftKey)break;return e.preventDefault(),e.stopPropagation(),n.actions.goToOption({focus:v.Last});case U.PageDown:return e.preventDefault(),e.stopPropagation(),n.actions.goToOption({focus:v.Last});case U.Escape:return n.state.comboboxState===X.Open?(e.preventDefault(),n.state.optionsElement&&!r.optionsPropsRef.current.static&&e.stopPropagation(),r.mode===Z.Single&&r.value===null&&S(),n.actions.closeCombobox()):void 0;case U.Tab:if(n.actions.setIsTyping(!1),n.state.comboboxState!==X.Open)return;r.mode===Z.Single&&n.state.activationTrigger!==Q.Focus&&n.actions.selectActiveOption(),n.actions.closeCombobox()}}),O=V(e=>{s?.(e),r.mode===Z.Single&&e.target.value===``&&S(),n.actions.openCombobox()}),k=V(e=>{var t,i;let a=e.relatedTarget??Oe.find(t=>t!==e.currentTarget);if(!((t=n.state.optionsElement)!=null&&t.contains(a))&&!((i=n.state.buttonElement)!=null&&i.contains(a))&&n.state.comboboxState===X.Open)return e.preventDefault(),r.mode===Z.Single&&r.value===null&&S(),n.actions.closeCombobox()}),ee=V(e=>{var t,i;let a=e.relatedTarget??Oe.find(t=>t!==e.currentTarget);(t=n.state.buttonElement)!=null&&t.contains(a)||(i=n.state.optionsElement)!=null&&i.contains(a)||r.disabled||r.immediate&&n.state.comboboxState!==X.Open&&x.microTask(()=>{(0,q.flushSync)(()=>n.actions.openCombobox()),n.actions.setActivationTrigger(Q.Focus)})}),A=M(),j=P(),{isFocused:ne,focusProps:N}=p({autoFocus:u}),{isHovered:re,hoverProps:ie}=m({isDisabled:l}),F=I(n,e=>e.optionsElement),ae=me({open:_===X.Open,disabled:l,invalid:r.invalid,hover:re,focus:ne,autofocus:u}),oe=le({ref:g,id:o,role:`combobox`,type:d,"aria-controls":F?.id,"aria-expanded":_===X.Open,"aria-activedescendant":I(n,n.selectors.activeDescendantId),"aria-labelledby":A,"aria-describedby":j,"aria-autocomplete":`list`,defaultValue:e.defaultValue??(r.defaultValue===void 0?null:c?.(r.defaultValue))??r.defaultValue,disabled:l||void 0,autoFocus:u,onCompositionStart:T,onCompositionEnd:E,onKeyDown:D,onChange:O,onFocus:ee,onBlur:k},N,ie);return ve()({ourProps:oe,theirProps:f,slot:ae,defaultTag:Jt,name:`Combobox.Input`})}var Xt=`button`;function Zt(e,t){let n=Vt(`Combobox.Button`),r=$(`Combobox.Button`),[i,a]=(0,G.useState)(null),o=L(t,a,n.actions.setButtonElement),s=(0,H.useId)(),{id:c=`headlessui-combobox-button-${s}`,disabled:l=r.disabled||!1,autoFocus:u=!1,...d}=e,[f,h,y]=I(n,e=>[e.comboboxState,e.inputElement,e.optionsElement]),b=Mt(h),C=f===X.Open;S(C,{trigger:i,action:(0,G.useCallback)(e=>{if(i!=null&&i.contains(e.target)||h!=null&&h.contains(e.target))return x.Ignore;let t=e.target.closest(`[role="option"]:not([data-disabled])`);return se(t)?x.Select(t):y!=null&&y.contains(e.target)?x.Ignore:x.Close},[i,h,y]),close:n.actions.closeCombobox,select:n.actions.selectActiveOption});let w=V(e=>{switch(e.key){case U.Space:case U.Enter:e.preventDefault(),e.stopPropagation(),n.state.comboboxState===X.Closed&&(0,q.flushSync)(()=>n.actions.openCombobox()),b();return;case U.ArrowDown:e.preventDefault(),e.stopPropagation(),n.state.comboboxState===X.Closed&&((0,q.flushSync)(()=>n.actions.openCombobox()),n.state.dataRef.current.value||n.actions.goToOption({focus:v.First})),b();return;case U.ArrowUp:e.preventDefault(),e.stopPropagation(),n.state.comboboxState===X.Closed&&((0,q.flushSync)(()=>n.actions.openCombobox()),n.state.dataRef.current.value||n.actions.goToOption({focus:v.Last})),b();return;case U.Escape:if(n.state.comboboxState!==X.Open)return;e.preventDefault(),n.state.optionsElement&&!r.optionsPropsRef.current.static&&e.stopPropagation(),(0,q.flushSync)(()=>n.actions.closeCombobox()),b();return;default:return}}),E=_(()=>{n.state.comboboxState===X.Open?n.actions.closeCombobox():n.actions.openCombobox(),b()}),D=M([c]),{isFocusVisible:O,focusProps:k}=p({autoFocus:u}),{isHovered:ee,hoverProps:A}=m({isDisabled:l}),{pressed:j,pressProps:te}=g({disabled:l}),ne=me({open:f===X.Open,active:j||f===X.Open,disabled:l,invalid:r.invalid,value:r.value,hover:ee,focus:O}),N=le({ref:o,id:c,type:T(e,i),tabIndex:-1,"aria-haspopup":`listbox`,"aria-controls":y?.id,"aria-expanded":f===X.Open,"aria-labelledby":D,disabled:l||void 0,autoFocus:u,onKeyDown:w},E,k,A,te);return ve()({ourProps:N,theirProps:d,slot:ne,defaultTag:Xt,name:`Combobox.Button`})}var Qt=`div`,$t=we.RenderStrategy|we.Static;function en(e,t){let n=(0,H.useId)(),{id:r=`headlessui-combobox-options-${n}`,hold:i=!1,anchor:a,portal:o=!1,modal:s=!0,transition:c=!1,...l}=e,u=Vt(`Combobox.Options`),d=$(`Combobox.Options`),f=b(a);f&&(o=!0);let[p,m]=w(f),[h,g]=(0,G.useState)(null),_=A(),v=L(t,f?p:null,u.actions.setOptionsElement,g),[y,x,S,C,T]=I(u,e=>[e.comboboxState,e.inputElement,e.buttonElement,e.optionsElement,e.activationTrigger]),E=ce(x||S),D=ce(C),O=de(),[k,ee]=De(c,h,O===null?y===X.Open:(O&be.Open)===be.Open);ye(k,x,u.actions.closeCombobox);let j=!d.__demoMode&&s&&y===X.Open;_e(j,D);let te=!d.__demoMode&&s&&y===X.Open;oe(te,{allowed:(0,G.useCallback)(()=>[x,S,C],[x,S,C])});let N=!I(u,u.selectors.didInputMove)&&k;z(()=>{d.optionsPropsRef.current.static=e.static??!1},[d.optionsPropsRef,e.static]),z(()=>{d.optionsPropsRef.current.hold=i},[d.optionsPropsRef,i]),Re(y===X.Open,{container:C,accept(e){return e.getAttribute(`role`)===`option`?NodeFilter.FILTER_REJECT:e.hasAttribute(`role`)?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT},walk(e){e.setAttribute(`role`,`none`)}});let re=M([S?.id]),P=me({open:y===X.Open,option:void 0}),ie=V(()=>{u.actions.setActivationTrigger(Q.Pointer)}),F=V(e=>{e.preventDefault(),u.actions.setActivationTrigger(Q.Pointer)}),ae=le(f?_():{},{"aria-labelledby":re,role:`listbox`,"aria-multiselectable":d.mode===Z.Multi||void 0,id:r,ref:v,style:{...l.style,...m,"--input-width":ne(k,x,!0).width,"--button-width":ne(k,S,!0).width},onWheel:T===Q.Pointer?void 0:ie,onMouseDown:F,...xe(ee)}),se=k&&y===X.Closed&&!e.static,R=Fe(se,d.virtual?.options),ue=Fe(se,d.value),fe=(0,G.useCallback)(e=>d.compare(ue,e),[d.compare,ue]),pe=(0,G.useMemo)(()=>{if(!d.virtual)return d;if(R===void 0)throw Error("Missing `options` in virtual mode");return R===d.virtual.options?d:{...d,virtual:{...d.virtual,options:R}}},[d,R,d.virtual?.options]);d.virtual&&Object.assign(l,{children:G.createElement(Ut.Provider,{value:pe},G.createElement(Gt,{slot:P},l.children))});let he=ve(),ge=(0,G.useMemo)(()=>d.mode===Z.Multi?d:{...d,isSelected:fe},[d,fe]);return G.createElement(Ce,{enabled:o?e.static||k:!1,ownerDocument:E},G.createElement(Ut.Provider,{value:ge},he({ourProps:ae,theirProps:{...l,children:G.createElement(Me,{freeze:se},typeof l.children==`function`?l.children?.call(l,P):l.children)},slot:P,defaultTag:Qt,features:$t,visible:N,name:`Combobox.Options`})))}var tn=`div`;function nn(e,t){var n;let r=$(`Combobox.Option`),i=Vt(`Combobox.Option`),a=(0,H.useId)(),{id:o=`headlessui-combobox-option-${a}`,value:s,disabled:c=((n=r.virtual)?.disabled)?.call(n,s)??!1,order:l=null,...u}=e,[d]=I(i,e=>[e.inputElement]),f=Mt(d),p=I(i,(0,G.useCallback)(e=>i.selectors.isActive(e,s,o),[s,o])),m=r.isSelected(s),h=(0,G.useRef)(null),g=Se({disabled:c,value:s,domRef:h,order:l}),_=(0,G.useContext)(Wt),y=L(t,h,_?_.measureElement:null),b=V(()=>{i.actions.setIsTyping(!1),i.actions.onChange(s)});z(()=>i.actions.registerOption(o,g),[g,o]);let x=I(i,(0,G.useCallback)(e=>i.selectors.shouldScrollIntoView(e,s,o),[s,o]));z(()=>{if(x)return R().requestAnimationFrame(()=>{var e,t;(t=(e=h.current)?.scrollIntoView)==null||t.call(e,{block:`nearest`})})},[x,h]);let S=V(e=>{e.preventDefault(),e.button===j.Left&&(c||(b(),Ae()||requestAnimationFrame(()=>f()),r.mode===Z.Single&&i.actions.closeCombobox()))}),C=V(()=>{if(c)return i.actions.goToOption({focus:v.Nothing});let e=r.calculateIndex(s);i.actions.goToOption({focus:v.Specific,idx:e})}),w=O(),T=V(e=>w.update(e)),E=V(e=>{if(!w.wasMoved(e)||c||p&&i.state.activationTrigger===Q.Pointer)return;let t=r.calculateIndex(s);i.actions.goToOption({focus:v.Specific,idx:t},Q.Pointer)}),D=V(e=>{w.wasMoved(e)&&(c||p&&(r.optionsPropsRef.current.hold||i.state.activationTrigger===Q.Pointer&&i.actions.goToOption({focus:v.Nothing})))}),k=me({active:p,focus:p,selected:m,disabled:c}),ee={id:o,ref:y,role:`option`,tabIndex:c===!0?void 0:-1,"aria-disabled":c===!0||void 0,"aria-selected":m,disabled:void 0,onMouseDown:S,onFocus:C,onPointerEnter:T,onMouseEnter:T,onPointerMove:E,onMouseMove:E,onPointerLeave:D,onMouseLeave:D};return ve()({ourProps:ee,theirProps:u,slot:k,defaultTag:tn,name:`Combobox.Option`})}var rn=Ee(qt),an=Ee(Zt),on=Ee(Yt),sn=f,cn=Ee(en),ln=Ee(nn),un=Object.assign(rn,{Input:on,Button:an,Label:sn,Options:cn,Option:ln});function dn({options:e,value:t,onChange:n,placeholder:r=`搜索并选择…`,disabled:i=!1,allowEmpty:a=!0,emptyLabel:o=`不选择`}){let[s,c]=(0,G.useState)(``),l=(0,G.useMemo)(()=>{let t=s.trim().toLowerCase();return t?e.filter(e=>e.label.toLowerCase().includes(t)||e.value.toLowerCase().includes(t)):e},[e,s]),u=e.find(e=>e.value===t)??null;return i?(0,K.jsx)(`div`,{className:`relative mt-1`,children:(0,K.jsxs)(`button`,{type:`button`,disabled:!0,className:`w-full h-9 flex items-center justify-between gap-2 rounded-lg border border-stone-200 bg-stone-50 px-3 text-sm text-left text-stone-400 cursor-not-allowed`,children:[(0,K.jsx)(`span`,{className:`truncate`,children:r}),(0,K.jsx)(`svg`,{className:`w-4 h-4 text-stone-400 shrink-0`,viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,K.jsx)(`path`,{fillRule:`evenodd`,d:`M5.23 7.21a.75.75 0 011.06.02L10 11.17l3.71-3.94a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z`,clipRule:`evenodd`})})]})}):(0,K.jsx)(un,{value:u,onChange:e=>{n(e?.value??``),c(``)},immediate:!0,children:(0,K.jsxs)(`div`,{className:`relative mt-1`,children:[(0,K.jsx)(on,{className:`w-full h-9 rounded-lg border border-stone-200 bg-white px-3 pr-8 text-sm outline-none cursor-text placeholder:text-stone-400 focus:ring-2 focus:ring-[#4176e6]/30 focus:border-[#4176e6]`,displayValue:e=>e?.label??``,onChange:e=>c(e.target.value),placeholder:r}),(0,K.jsx)(an,{className:`absolute inset-y-0 right-0 flex items-center pr-2 text-stone-400 cursor-pointer`,children:(0,K.jsx)(`svg`,{className:`w-4 h-4`,viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,K.jsx)(`path`,{fillRule:`evenodd`,d:`M5.23 7.21a.75.75 0 011.06.02L10 11.17l3.71-3.94a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z`,clipRule:`evenodd`})})}),(0,K.jsxs)(cn,{transition:!0,anchor:{to:`bottom start`,gap:4},className:`tw-select-menu tw-menu-anim z-80 max-h-56 w-(--input-width) overflow-auto rounded-lg p-1 shadow-lg ring-1 ring-stone-200 focus:outline-none`,children:[a?(0,K.jsx)(ln,{value:null,className:`cursor-pointer select-none rounded-md px-3 py-2 text-sm text-stone-400 data-[focus]:bg-stone-50`,children:o}):null,l.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-stone-400`,children:`无匹配项`}):l.map(e=>(0,K.jsx)(ln,{value:e,className:`cursor-pointer select-none rounded-md px-3 py-2 text-sm text-stone-700 data-[focus]:bg-stone-50 data-[selected]:font-medium`,children:e.label},e.value))]})]})})}export{$e as a,Ve as c,Ue as d,He as f,Qe as i,ze as l,it as n,tt as o,nt as r,rt as s,dn as t,W as u};
@@ -0,0 +1 @@
1
+ import{t as e}from"./jsx-runtime.BUXbF_vF.js";import{i as t,n,r,t as i}from"./listbox.DdDDDJ5Z.js";var a=e();function o({className:e=`w-4 h-4 text-stone-400 shrink-0`}){return(0,a.jsx)(`svg`,{className:e,viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,a.jsx)(`path`,{fillRule:`evenodd`,d:`M5.23 7.21a.75.75 0 011.06.02L10 11.17l3.71-3.94a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z`,clipRule:`evenodd`})})}function s(){return(0,a.jsx)(`svg`,{className:`w-4 h-4 shrink-0`,viewBox:`0 0 20 20`,fill:`currentColor`,"aria-hidden":!0,children:(0,a.jsx)(`path`,{fillRule:`evenodd`,d:`M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z`,clipRule:`evenodd`})})}function c({options:e,value:c,onChange:l,disabled:u=!1,className:d=``,compact:f=!1,ariaLabel:p,showCheck:m=!0,centerContent:h=!1,unstyled:g=!1,triggerClassName:_=``,hideChevron:v=!1,flat:y=!1,menuMinWidth:b,renderTrigger:x,renderOptionPrefix:S}){let C=e.find(e=>e.value===c),w=h?`relative justify-center`:`justify-between`,T=h?`w-4 h-4 text-stone-400 shrink-0 absolute right-2.5`:void 0,E=g?`w-full flex items-center cursor-pointer outline-none disabled:cursor-not-allowed`:f?`w-full h-8 flex items-center gap-1.5 rounded-lg border border-stone-300 bg-white px-2.5 text-sm text-left text-stone-700 outline-none cursor-pointer hover:border-stone-400 focus:ring-2 focus:ring-[#4176e6]/30 focus:border-[#4176e6] disabled:bg-stone-50 disabled:text-stone-400 disabled:cursor-not-allowed`:y?`w-full h-9 flex items-center gap-2 rounded-lg border border-stone-200 bg-white px-2.5 text-sm text-left text-stone-700 outline-none cursor-pointer hover:border-stone-300 focus:ring-2 focus:ring-[#4176e6]/30 focus:border-[#4176e6] disabled:bg-stone-50 disabled:text-stone-400 disabled:cursor-not-allowed`:`w-full h-9 flex items-center gap-2 rounded-lg border border-stone-200 bg-white px-3 text-sm text-left text-stone-800 outline-none cursor-pointer hover:border-stone-300 focus:ring-2 focus:ring-[#4176e6]/30 focus:border-[#4176e6] disabled:bg-stone-50 disabled:text-stone-400 disabled:cursor-not-allowed`;return(0,a.jsx)(r,{value:c,onChange:l,disabled:u,children:(0,a.jsxs)(`div`,{className:`relative ${g?``:f?`inline-block`:y?``:`mt-1`} ${d}`,children:[(0,a.jsxs)(t,{"aria-label":p,className:`${E} ${w} ${_}`,children:[x?x(C):(0,a.jsx)(`span`,{className:`truncate`,children:C?.label??c}),v?null:(0,a.jsx)(o,{className:T})]}),(0,a.jsx)(i,{transition:!0,anchor:{to:`bottom start`,gap:4},style:b?{minWidth:b}:void 0,className:`tw-select-menu tw-menu-anim z-80 max-h-56 w-max min-w-(--button-width) max-w-[320px] overflow-auto rounded-lg p-1 shadow-lg ring-1 ring-stone-200 focus:outline-none`,children:e.map(e=>(0,a.jsxs)(n,{value:e.value,className:`group cursor-pointer select-none flex items-center gap-2 rounded-md px-3 py-2 text-sm leading-5 data-[focus]:bg-stone-50 data-[selected]:bg-(--tw-accent-soft) ${m?`text-stone-700 data-[selected]:text-stone-900`:`data-[selected]:text-(--tw-accent) data-[selected]:font-medium`} ${h&&!m&&!S?`justify-center px-2`:``}`,children:[m?(0,a.jsx)(`span`,{className:`w-4 shrink-0 text-[#4176e6] opacity-0 group-data-[selected]:opacity-100`,children:(0,a.jsx)(s,{})}):S?(0,a.jsx)(`span`,{className:`flex w-3.5 shrink-0 items-center justify-center`,children:S(e)}):null,(0,a.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label})]},e.value))})]})})}export{c as t};
@@ -1 +1 @@
1
- import{c as e,n as t}from"./react-dom.CqAxpHMt.js";import{a as n,i as r,n as i,s as ee}from"./app-config.CpjKWnzM.js";import{i as te}from"./llm.BZEzE0x2.js";import{_ as ne,a,c as re,d as ie,g as ae,h as oe,i as se,l as o,n as s,o as ce,r as le,s as c,t as l,u as ue,v as de}from"./settings.BoQ0e0m1.js";import{t as u}from"./jsx-runtime.BUXbF_vF.js";import{i as fe,n as pe,r as me,t as he}from"./listbox.DdDDDJ5Z.js";import{o as ge,s as _e,t as ve}from"./ConfirmDialog.BYz4HREM.js";import{n as d}from"./i18n.BVvhz-vw.js";var f=e(t(),1),ye=`0.1.2`,p=u();function be(e){try{return new URL(e).host}catch{return``}}var xe=[{value:`zh-CN`,label:`中文`},{value:`en`,label:`English`}],m=`w-full px-3 py-2 text-sm border border-stone-300 rounded-lg bg-white focus:outline-none focus:ring-2 focus:ring-[#4176e6]/35 focus:border-[#4176e6] transition-colors`,h=`inline-flex items-center gap-1.5 h-9 min-w-30 px-3 rounded-lg bg-stone-100 text-sm text-stone-700 hover:bg-stone-200/80 transition-colors outline-none focus:outline-none`;function Se({className:e=`w-3.5 h-3.5`}){return(0,p.jsx)(`svg`,{className:e,viewBox:`0 0 20 20`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:(0,p.jsx)(`path`,{d:`M6 8l4 4 4-4`,strokeLinecap:`round`,strokeLinejoin:`round`})})}function g({className:e=`w-4 h-4`}){return(0,p.jsx)(`svg`,{className:e,viewBox:`0 0 20 20`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,p.jsx)(`path`,{d:`M5 10.5l3.5 3.5L15 6.5`,strokeLinecap:`round`,strokeLinejoin:`round`})})}function Ce({className:e=`w-4 h-4`}){return(0,p.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,children:[(0,p.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`}),(0,p.jsx)(`path`,{d:`M12 1v2M12 21v2M4.2 4.2l1.4 1.4M18.4 18.4l1.4 1.4M1 12h2M21 12h2M4.2 19.8l1.4-1.4M18.4 5.6l1.4-1.4`})]})}function we({className:e=`w-4 h-4`}){return(0,p.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,children:[(0,p.jsx)(`ellipse`,{cx:`12`,cy:`5`,rx:`8`,ry:`3`}),(0,p.jsx)(`path`,{d:`M4 5v6c0 1.7 3.6 3 8 3s8-1.3 8-3V5`}),(0,p.jsx)(`path`,{d:`M4 11v6c0 1.7 3.6 3 8 3s8-1.3 8-3v-6`})]})}function Te({kind:e}){let t=`w-5 h-5`;return e===`sun`?(0,p.jsxs)(`svg`,{className:t,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,children:[(0,p.jsx)(`circle`,{cx:`12`,cy:`12`,r:`4`}),(0,p.jsx)(`path`,{d:`M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4`})]}):e===`moon`?(0,p.jsx)(`svg`,{className:t,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,children:(0,p.jsx)(`path`,{d:`M21 14.5A8.5 8.5 0 1 1 9.5 3a7 7 0 0 0 11.5 11.5z`})}):(0,p.jsxs)(`svg`,{className:t,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,children:[(0,p.jsx)(`rect`,{x:`3`,y:`4`,width:`18`,height:`12`,rx:`2`}),(0,p.jsx)(`path`,{d:`M8 20h8M12 16v4`})]})}function _({title:e,description:t,control:n}){return(0,p.jsxs)(`div`,{className:`flex items-center gap-4 py-4 border-b border-stone-100 last:border-b-0`,children:[(0,p.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,p.jsx)(`div`,{className:`text-sm font-medium text-stone-800`,children:e}),t?(0,p.jsx)(`div`,{className:`mt-0.5 text-xs text-stone-400 leading-5`,children:t}):null]}),(0,p.jsx)(`div`,{className:`shrink-0`,children:n})]})}function v({value:e,options:t,onChange:n}){let r=t.find(t=>t.value===e)?.label??e;return(0,p.jsxs)(me,{value:e,onChange:n,children:[(0,p.jsxs)(fe,{className:h,children:[(0,p.jsx)(`span`,{className:`flex-1 text-left truncate`,children:r}),(0,p.jsx)(Se,{className:`w-3.5 h-3.5 text-stone-400 shrink-0`})]}),(0,p.jsx)(he,{transition:!0,anchor:{to:`bottom end`,gap:6},className:`tw-select-menu tw-menu-anim z-60 min-w-40 rounded-xl py-1 shadow-lg ring-1 ring-stone-200 focus:outline-none`,children:t.map(e=>(0,p.jsxs)(pe,{value:e.value,className:`group cursor-pointer select-none flex items-center justify-between gap-3 px-3 py-2 text-sm text-stone-700 data-[focus]:bg-stone-50 data-[selected]:text-stone-900`,children:[(0,p.jsx)(`span`,{children:e.label}),(0,p.jsx)(g,{className:`w-4 h-4 text-[#4176e6] opacity-0 group-data-[selected]:opacity-100 shrink-0`})]},e.value))})]})}function y(){let[e,t]=(0,f.useState)(!1),[u,h]=(0,f.useState)(`general`),[y,b]=(0,f.useState)([]),[x,S]=(0,f.useState)(``),[C,w]=(0,f.useState)(null),[T,E]=(0,f.useState)(``),[Ee,D]=(0,f.useState)(`DeepSeek`),[O,k]=(0,f.useState)(``),[A,j]=(0,f.useState)(``),[M,N]=(0,f.useState)(``),[P,F]=(0,f.useState)([]),[I,L]=(0,f.useState)(`idle`),[De,R]=(0,f.useState)(!1),[Oe,z]=(0,f.useState)(`readonly`),[ke,Ae]=(0,f.useState)(!1),[je,B]=(0,f.useState)(!1),[Me,V]=(0,f.useState)(null),[H,U]=(0,f.useState)({language:`zh-CN`,appearance:`system`,sessionFontSize:14,toolStepDetail:`standard`,busySendBehavior:`queue`,subagentModel:``}),[W,G]=(0,f.useState)(`14`),K=(0,f.useRef)(0),q=C!==null,J=H.language,Y=y.find(e=>e.id===x),X=(Y?.name||``).trim(),Ne=X||(J===`en`?`No model`:`未配置`),Pe=X?Y?.model?.trim()?`${X} · ${Y.model.trim()}`:X:J===`en`?`No model configured`:`未配置模型`;function Fe(e=`general`){h(e),r().then(()=>{Z(),t(!0)})}function Z(){Ae(n()),b(re()),S(a()),B(!!o()),U(c()),le(c()),z(ce()),w(null)}function Ie(e){if(!e){let e=ee();w(e),E(`DeepSeek`),D(`DeepSeek`),k(`https://api.deepseek.com/v1`),j(``),N(``),F([]),L(`idle`),R(!1);return}w(e.id),E(e.name),k(e.baseURL);let t=e.apiKey?.trim()||(e.id===a()?i().trim():``)||``;j(t),N(e.model),F(e.availableModels??[]),L(e.availableModels?.length?`ok`:`idle`),D(s.find(t=>t.baseURL===e.baseURL)?.label??`自定义`),R(!1)}(0,f.useEffect)(()=>{r().then(()=>Z());let e=e=>{let n=e.detail;h(n?.tab===`model`?`model`:`general`),r().then(()=>{Z(),t(!0)})};window.addEventListener(l,e);let n=ie(e=>U(e)),i=ue(e=>z(e));return()=>{window.removeEventListener(l,e),n(),i()}},[]),(0,f.useEffect)(()=>{if(!e||u!==`model`||!q)return;let t=O.trim(),n=A.trim();if(!t||!n){L(e=>e===`ok`?`ok`:`idle`);return}L(`loading`);let r=++K.current,i=setTimeout(()=>{te(t,n).then(e=>{r===K.current&&(F(e),L(`ok`))}).catch(()=>{r===K.current&&L(`fail`)})},800);return()=>clearTimeout(i)},[e,u,q,O,A]);function Le(e){D(e);let t=s.find(t=>t.label===e);t&&(t.baseURL&&k(t.baseURL),(!T.trim()||s.some(e=>e.label===T))&&E(t.label)),N(``)}function Q(e){U(ae(e))}(0,f.useEffect)(()=>{G(String(H.sessionFontSize))},[H.sessionFontSize]);function Re(){let e=Number(W);if(!W.trim()||!Number.isFinite(e)){G(String(H.sessionFontSize));return}let t=ae({sessionFontSize:Math.round(e)});U(t),G(String(t.sessionFontSize))}let ze=!!(T.trim()&&O.trim()&&A.trim()&&M.trim()),$=P.length>0;function Be(){if(!ze||!C)return;let e=de({id:C,name:T.trim(),baseURL:O.trim(),apiKey:A.trim(),model:M.trim(),availableModels:$?P:void 0},{activate:!0});b(e),S(C),w(null),B(!!o())}function Ve(e){V(e)}function He(){let e=Me;if(!e)return;V(null);let t=se(e);b(t),S(a()),C===e&&w(null),B(!!o())}function Ue(e){ne(e),S(e),B(!!o())}let We=[{value:`readonly`,label:d(`settings.access.readonly`,void 0,J)},{value:`readwrite`,label:d(`settings.access.readwrite`,void 0,J)},{value:`full`,label:d(`settings.access.full`,void 0,J)}],Ge=[{value:`concise`,label:d(`settings.step.concise`,void 0,J)},{value:`standard`,label:d(`settings.step.standard`,void 0,J)},{value:`detailed`,label:d(`settings.step.detailed`,void 0,J)},{value:`full`,label:d(`settings.step.full`,void 0,J)}],Ke=[{value:`queue`,label:d(`settings.busySend.queue`,void 0,J)},{value:`interrupt`,label:d(`settings.busySend.interrupt`,void 0,J)}],qe=[{value:`light`,label:d(`settings.appear.light`,void 0,J),icon:`sun`},{value:`dark`,label:d(`settings.appear.dark`,void 0,J),icon:`moon`},{value:`system`,label:d(`settings.appear.system`,void 0,J),icon:`monitor`}],Je=[{id:`general`,label:d(`settings.general`,void 0,J),icon:(0,p.jsx)(Ce,{})},{id:`model`,label:d(`settings.model`,void 0,J),icon:(0,p.jsx)(we,{})}],Ye=u===`general`?d(`settings.general`,void 0,J):q?y.some(e=>e.id===C)?d(`settings.editProvider`,void 0,J):d(`settings.addProviderTitle`,void 0,J):d(`settings.model`,void 0,J);return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`div`,{className:`tw-nav-foot-row`,children:[(0,p.jsxs)(`button`,{type:`button`,onClick:()=>Fe(`general`),className:`tw-nav-settings-btn`,"data-hint":je?`设置(已配置模型)`:`设置`,children:[(0,p.jsxs)(`svg`,{className:`tw-nav-ico w-4.5 h-4.5 shrink-0`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,"aria-hidden":`true`,children:[(0,p.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`}),(0,p.jsx)(`path`,{d:`M19.4 15a1.7 1.7 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.8-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-1-1.5 1.7 1.7 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.8 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.7 1.7 0 0 0 1.5-1 1.7 1.7 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.8.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.8V9c.2.6.7 1 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1z`})]}),(0,p.jsx)(`span`,{"data-i18n":`nav.settings`,children:d(`nav.settings`,void 0,J)})]}),(0,p.jsxs)(`button`,{type:`button`,className:`tw-nav-provider-chip${X?``:` is-empty`}`,"data-hint":Pe,onClick:()=>Fe(`model`),children:[(0,p.jsx)(`span`,{className:`tw-nav-provider-dot`,"aria-hidden":`true`}),(0,p.jsx)(`span`,{className:`tw-nav-provider-name`,children:Ne})]})]}),(0,p.jsx)(ge,{show:e,children:(0,p.jsxs)(`div`,{className:`fixed inset-0 z-110 flex items-center justify-center p-4`,children:[(0,p.jsx)(_e,{children:(0,p.jsx)(`div`,{className:`tw-dialog-backdrop-anim absolute inset-0 bg-stone-950/45`,onClick:()=>t(!1),"aria-hidden":`true`})}),(0,p.jsx)(_e,{children:(0,p.jsxs)(`div`,{className:`tw-settings-dialog tw-dialog-panel-anim relative bg-white rounded-2xl shadow-2xl w-full max-w-3xl h-[min(92vh,720px)] overflow-hidden flex flex-col`,children:[(0,p.jsxs)(`div`,{className:`shrink-0 h-12 px-4 flex items-center justify-between border-b border-stone-100 bg-white`,children:[(0,p.jsx)(`h2`,{className:`text-sm font-semibold text-stone-800 truncate pr-3`,children:Ye}),(0,p.jsx)(`button`,{type:`button`,"aria-label":d(`settings.close`,void 0,J),onClick:()=>t(!1),className:`w-8 h-8 inline-flex items-center justify-center rounded-lg text-stone-400 hover:text-stone-700 hover:bg-stone-100 transition-colors`,children:(0,p.jsx)(`svg`,{className:`w-4 h-4`,viewBox:`0 0 20 20`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,children:(0,p.jsx)(`path`,{d:`M5 5l10 10M15 5L5 15`,strokeLinecap:`round`})})})]}),(0,p.jsxs)(`div`,{className:`flex-1 min-h-0 flex`,children:[(0,p.jsx)(`aside`,{className:`w-38 shrink-0 border-r border-stone-100 bg-[#f4f5f7] py-3 px-2 space-y-0.5`,children:Je.map(e=>{let t=u===e.id;return(0,p.jsxs)(`button`,{type:`button`,onClick:()=>{h(e.id),e.id===`model`&&w(null)},className:`w-full flex items-center gap-2 px-3 py-2.5 rounded-lg text-sm transition-colors ${t?`bg-[#e8f0fe] text-[#4176e6] font-medium`:`text-stone-600 hover:bg-white/70 hover:text-stone-800`}`,children:[(0,p.jsx)(`span`,{className:t?`text-[#4176e6]`:`text-stone-400`,children:e.icon}),e.label]},e.id)})}),(0,p.jsx)(`div`,{className:`flex-1 min-w-0 flex flex-col min-h-0 bg-white`,children:u===`general`?(0,p.jsxs)(`div`,{className:`flex-1 min-h-0 flex flex-col`,children:[(0,p.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-6 py-1`,children:[(0,p.jsx)(_,{title:d(`settings.access`,void 0,J),description:d(`settings.accessDesc`,void 0,J),control:(0,p.jsx)(v,{value:Oe,options:We,onChange:e=>{z(e),oe(e)}})}),(0,p.jsx)(_,{title:d(`settings.language`,void 0,J),control:(0,p.jsx)(v,{value:H.language,options:xe,onChange:e=>Q({language:e})})}),(0,p.jsxs)(`div`,{className:`py-4 border-b border-stone-100`,children:[(0,p.jsx)(`div`,{className:`text-sm font-medium text-stone-800 mb-3`,children:d(`settings.appearance`,void 0,J)}),(0,p.jsx)(`div`,{className:`grid grid-cols-3 gap-2.5`,children:qe.map(e=>{let t=H.appearance===e.value;return(0,p.jsxs)(`button`,{type:`button`,onClick:()=>Q({appearance:e.value}),className:`flex flex-col items-center justify-center gap-2 h-19 rounded-xl border transition-colors ${t?`border-[#4176e6] bg-[#edf3fe] text-[#4176e6] ring-1 ring-[#4176e6]/30`:`border-stone-200 text-stone-500 hover:border-stone-300 hover:bg-stone-50`}`,children:[(0,p.jsx)(Te,{kind:e.icon}),(0,p.jsx)(`span`,{className:`text-xs font-medium`,children:e.label})]},e.value)})})]}),(0,p.jsx)(_,{title:d(`settings.fontSize`,void 0,J),description:d(`settings.fontSizeDesc`,void 0,J),control:(0,p.jsxs)(`div`,{className:`inline-flex items-center gap-1.5`,children:[(0,p.jsx)(`input`,{type:`number`,min:12,max:22,value:W,onChange:e=>G(e.target.value),onBlur:Re,onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()},className:`w-14 h-9 px-2 text-sm text-center rounded-lg bg-stone-100 border-0 outline-none focus:ring-2 focus:ring-[#4176e6]/30`}),(0,p.jsx)(`span`,{className:`text-sm text-stone-400`,children:`px`})]})}),(0,p.jsx)(_,{title:d(`settings.toolSteps`,void 0,J),description:d(`settings.toolStepsDesc`,void 0,J),control:(0,p.jsx)(v,{value:H.toolStepDetail,options:Ge,onChange:e=>Q({toolStepDetail:e})})}),(0,p.jsx)(_,{title:d(`settings.busySend`,void 0,J),description:d(`settings.busySendDesc`,void 0,J),control:(0,p.jsx)(v,{value:H.busySendBehavior,options:Ke,onChange:e=>Q({busySendBehavior:e})})}),(0,p.jsx)(_,{title:d(`settings.subagentModel`,void 0,J),description:d(`settings.subagentModelDesc`,void 0,J),control:(0,p.jsx)(v,{value:H.subagentModel?.trim()?H.subagentModel:`inherit`,options:[{value:`inherit`,label:d(`settings.subagentModel.inherit`,void 0,J)},...Array.from(new Set([...Y?.availableModels??[],...Y?.model?[Y.model]:[]])).filter(Boolean).map(e=>({value:e,label:e}))],onChange:e=>Q({subagentModel:e===`inherit`?``:e})})})]}),(0,p.jsxs)(`div`,{className:`shrink-0 px-6 py-3 border-t border-stone-100 flex items-center justify-between text-[11px] text-stone-400`,children:[(0,p.jsx)(`span`,{children:d(`settings.platformVersion`,void 0,J)}),(0,p.jsxs)(`span`,{className:`tabular-nums text-stone-500`,children:[`v`,ye]})]})]}):q?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`div`,{className:`shrink-0 px-5 pt-3 pb-2 flex items-center gap-2 border-b border-stone-100`,children:(0,p.jsx)(`button`,{type:`button`,onClick:()=>w(null),className:`text-sm text-stone-500 hover:text-stone-800`,children:d(`settings.back`,void 0,J)})}),(0,p.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-4`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:`block text-xs font-medium text-stone-500 mb-1.5`,children:d(`settings.displayName`,void 0,J)}),(0,p.jsx)(`input`,{type:`text`,value:T,onChange:e=>E(e.target.value),placeholder:`DeepSeek`,className:m})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:`block text-xs font-medium text-stone-500 mb-1.5`,children:d(`settings.preset`,void 0,J)}),(0,p.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:s.map(e=>{let t=Ee===e.label;return(0,p.jsxs)(`button`,{type:`button`,onClick:()=>Le(e.label),className:`text-left px-3 py-2 rounded-lg border transition-colors ${t?`border-[#4176e6] bg-[#edf3fe] ring-1 ring-[#4176e6]/30`:`border-stone-200 hover:border-stone-300 hover:bg-stone-50`}`,children:[(0,p.jsx)(`div`,{className:`text-sm ${t?`text-[#3565c7] font-medium`:`text-stone-700`}`,children:e.label}),(0,p.jsx)(`div`,{className:`text-[11px] text-stone-400 truncate`,children:e.baseURL?be(e.baseURL):`OpenAI compatible`})]},e.label)})})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:`block text-xs font-medium text-stone-500 mb-1.5`,children:d(`settings.baseUrl`,void 0,J)}),(0,p.jsx)(`input`,{type:`text`,value:O,onChange:e=>k(e.target.value),placeholder:`https://api.deepseek.com/v1`,className:m})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:`block text-xs font-medium text-stone-500 mb-1.5`,children:d(`settings.apiKey`,void 0,J)}),(0,p.jsxs)(`div`,{className:`relative`,children:[(0,p.jsx)(`input`,{type:De?`text`:`password`,value:A,onChange:e=>j(e.target.value),placeholder:`sk-...`,className:`${m} pr-14`}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>R(e=>!e),className:`absolute right-2 top-1/2 -translate-y-1/2 text-[11px] text-stone-400 hover:text-stone-600 px-1.5 py-1`,children:De?J===`en`?`Hide`:`隐藏`:J===`en`?`Show`:`显示`})]}),ke?(0,p.jsx)(`p`,{className:`mt-1.5 text-[11px] text-stone-400 leading-5`,children:d(`settings.keyHint`,void 0,J)}):null]}),(0,p.jsxs)(`div`,{children:[(0,p.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,p.jsx)(`label`,{className:`text-xs font-medium text-stone-500`,children:d(`settings.modelField`,void 0,J)}),I===`loading`&&(0,p.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:d(`settings.recognizing`,void 0,J)}),$&&I===`ok`&&(0,p.jsx)(`span`,{className:`text-[11px] text-emerald-600`,children:d(`settings.recognized`,{n:P.length},J)}),I===`fail`&&!$&&(0,p.jsx)(`span`,{className:`text-[11px] text-amber-600`,children:d(`settings.recognizeFail`,void 0,J)}),I===`fail`&&$&&(0,p.jsx)(`span`,{className:`text-[11px] text-amber-600`,children:d(`settings.recognizeKeep`,void 0,J)})]}),$?(0,p.jsxs)(me,{value:M,onChange:N,children:[(0,p.jsxs)(fe,{className:`${m} flex items-center justify-between text-left hover:border-stone-400 cursor-pointer`,children:[(0,p.jsx)(`span`,{className:`truncate text-stone-800`,children:M||(J===`en`?`Select a model`:`请选择模型`)}),(0,p.jsx)(Se,{className:`w-4 h-4 shrink-0 ml-2 text-stone-400`})]}),(0,p.jsx)(he,{transition:!0,anchor:{to:`bottom start`,gap:6},className:`tw-select-menu tw-menu-anim z-60 w-(--button-width) max-h-60 overflow-auto rounded-lg py-1 shadow-lg ring-1 ring-stone-200 focus:outline-none`,children:P.map(e=>(0,p.jsxs)(pe,{value:e,className:`group cursor-pointer select-none flex items-center justify-between px-3 py-2 text-sm text-stone-700 data-[focus]:bg-[#edf3fe] data-[selected]:text-[#3565c7] data-[selected]:font-medium`,children:[(0,p.jsx)(`span`,{className:`truncate`,children:e}),(0,p.jsx)(g,{className:`w-4 h-4 text-[#4176e6] opacity-0 group-data-[selected]:opacity-100 shrink-0 ml-2`})]},e))})]}):(0,p.jsx)(`input`,{type:`text`,value:M,onChange:e=>N(e.target.value),placeholder:d(`settings.modelPlaceholder`,void 0,J),className:m})]})]}),(0,p.jsxs)(`div`,{className:`shrink-0 px-5 py-3.5 bg-stone-50 border-t border-stone-100 flex justify-end gap-2`,children:[(0,p.jsx)(`button`,{type:`button`,onClick:()=>w(null),className:`px-3.5 py-1.5 text-sm text-stone-600 hover:bg-stone-200/60 rounded-lg`,children:d(`settings.cancel`,void 0,J)}),(0,p.jsx)(`button`,{type:`button`,onClick:Be,disabled:!ze,className:`px-3.5 py-1.5 text-sm font-medium text-white bg-[#4176e6] hover:bg-[#3565c7] rounded-lg disabled:opacity-40 disabled:cursor-not-allowed`,children:d(`settings.save`,void 0,J)})]})]}):(0,p.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-6 py-5 bg-[#f4f5f7]`,children:[(0,p.jsx)(`p`,{className:`text-sm text-stone-500`,children:d(`settings.modelIntro`,void 0,J)}),(0,p.jsxs)(`div`,{className:`mt-5 space-y-2.5`,children:[y.map(e=>{let t=!!(e.apiKey?.trim()&&e.baseURL.trim()&&e.model.trim()),n=e.id===x;return(0,p.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl border border-stone-200/90 bg-white px-4 py-3.5 shadow-[0_1px_0_rgba(15,23,42,0.02)]`,children:[(0,p.jsxs)(`button`,{type:`button`,"data-hint":n?J===`en`?`Active`:`当前使用`:J===`en`?`Set active`:`设为当前`,onClick:()=>Ue(e.id),className:`flex-1 min-w-0 flex items-center gap-2 text-left`,children:[(0,p.jsx)(`span`,{className:`text-sm font-medium text-stone-800 truncate`,children:e.name}),t?(0,p.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0 bg-emerald-500`}):null]}),(0,p.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[(0,p.jsx)(`button`,{type:`button`,onClick:()=>Ie(e),className:`h-8 px-3 text-sm text-stone-700 rounded-lg border border-stone-200 bg-white hover:bg-stone-50`,children:d(`settings.edit`,void 0,J)}),y.length>1?(0,p.jsx)(`button`,{type:`button`,onClick:()=>Ve(e.id),className:`h-8 px-3 text-sm text-red-600 rounded-lg hover:bg-red-50`,children:d(`settings.delete`,void 0,J)}):null]})]},e.id)}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>Ie(null),className:`w-full h-12 rounded-xl border border-dashed border-stone-300 bg-white/60 text-sm text-stone-600 hover:border-[#4176e6] hover:text-[#4176e6] hover:bg-[#edf3fe]/50 transition-colors`,children:d(`settings.addProvider`,void 0,J)})]})]})})]})]})})]})}),(0,p.jsx)(ve,{open:Me!=null,title:d(`settings.delete`,void 0,J),message:d(`settings.deleteConfirm`,void 0,J),confirmLabel:d(`settings.delete`,void 0,J),cancelLabel:J===`en`?`Cancel`:`取消`,danger:!0,onClose:()=>V(null),onConfirm:He})]})}export{y as default};
1
+ import{c as e,n as t}from"./react-dom.CqAxpHMt.js";import{a as n,i as r,n as i,s as ee}from"./app-config.vqDkEMS3.js";import{i as te}from"./llm.BZEzE0x2.js";import{_ as ne,a,c as re,d as ie,g as ae,h as oe,i as se,l as o,n as s,o as ce,r as le,s as c,t as l,u as ue,v as de}from"./settings.CkbipdPI.js";import{t as u}from"./jsx-runtime.BUXbF_vF.js";import{i as fe,n as pe,r as me,t as he}from"./listbox.DdDDDJ5Z.js";import{o as ge,s as _e,t as ve}from"./ConfirmDialog.BYz4HREM.js";import{n as d}from"./i18n.9qZsrs3u.js";var f=e(t(),1),ye=`0.1.2`,p=u();function be(e){try{return new URL(e).host}catch{return``}}var xe=[{value:`zh-CN`,label:`中文`},{value:`en`,label:`English`}],m=`w-full px-3 py-2 text-sm border border-stone-300 rounded-lg bg-white focus:outline-none focus:ring-2 focus:ring-[#4176e6]/35 focus:border-[#4176e6] transition-colors`,h=`inline-flex items-center gap-1.5 h-9 min-w-30 px-3 rounded-lg bg-stone-100 text-sm text-stone-700 hover:bg-stone-200/80 transition-colors outline-none focus:outline-none`;function Se({className:e=`w-3.5 h-3.5`}){return(0,p.jsx)(`svg`,{className:e,viewBox:`0 0 20 20`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:(0,p.jsx)(`path`,{d:`M6 8l4 4 4-4`,strokeLinecap:`round`,strokeLinejoin:`round`})})}function g({className:e=`w-4 h-4`}){return(0,p.jsx)(`svg`,{className:e,viewBox:`0 0 20 20`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,p.jsx)(`path`,{d:`M5 10.5l3.5 3.5L15 6.5`,strokeLinecap:`round`,strokeLinejoin:`round`})})}function Ce({className:e=`w-4 h-4`}){return(0,p.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,children:[(0,p.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`}),(0,p.jsx)(`path`,{d:`M12 1v2M12 21v2M4.2 4.2l1.4 1.4M18.4 18.4l1.4 1.4M1 12h2M21 12h2M4.2 19.8l1.4-1.4M18.4 5.6l1.4-1.4`})]})}function we({className:e=`w-4 h-4`}){return(0,p.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,children:[(0,p.jsx)(`ellipse`,{cx:`12`,cy:`5`,rx:`8`,ry:`3`}),(0,p.jsx)(`path`,{d:`M4 5v6c0 1.7 3.6 3 8 3s8-1.3 8-3V5`}),(0,p.jsx)(`path`,{d:`M4 11v6c0 1.7 3.6 3 8 3s8-1.3 8-3v-6`})]})}function Te({kind:e}){let t=`w-5 h-5`;return e===`sun`?(0,p.jsxs)(`svg`,{className:t,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,children:[(0,p.jsx)(`circle`,{cx:`12`,cy:`12`,r:`4`}),(0,p.jsx)(`path`,{d:`M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4`})]}):e===`moon`?(0,p.jsx)(`svg`,{className:t,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,children:(0,p.jsx)(`path`,{d:`M21 14.5A8.5 8.5 0 1 1 9.5 3a7 7 0 0 0 11.5 11.5z`})}):(0,p.jsxs)(`svg`,{className:t,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,children:[(0,p.jsx)(`rect`,{x:`3`,y:`4`,width:`18`,height:`12`,rx:`2`}),(0,p.jsx)(`path`,{d:`M8 20h8M12 16v4`})]})}function _({title:e,description:t,control:n}){return(0,p.jsxs)(`div`,{className:`flex items-center gap-4 py-4 border-b border-stone-100 last:border-b-0`,children:[(0,p.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,p.jsx)(`div`,{className:`text-sm font-medium text-stone-800`,children:e}),t?(0,p.jsx)(`div`,{className:`mt-0.5 text-xs text-stone-400 leading-5`,children:t}):null]}),(0,p.jsx)(`div`,{className:`shrink-0`,children:n})]})}function v({value:e,options:t,onChange:n}){let r=t.find(t=>t.value===e)?.label??e;return(0,p.jsxs)(me,{value:e,onChange:n,children:[(0,p.jsxs)(fe,{className:h,children:[(0,p.jsx)(`span`,{className:`flex-1 text-left truncate`,children:r}),(0,p.jsx)(Se,{className:`w-3.5 h-3.5 text-stone-400 shrink-0`})]}),(0,p.jsx)(he,{transition:!0,anchor:{to:`bottom end`,gap:6},className:`tw-select-menu tw-menu-anim z-60 min-w-40 rounded-xl py-1 shadow-lg ring-1 ring-stone-200 focus:outline-none`,children:t.map(e=>(0,p.jsxs)(pe,{value:e.value,className:`group cursor-pointer select-none flex items-center justify-between gap-3 px-3 py-2 text-sm text-stone-700 data-[focus]:bg-stone-50 data-[selected]:text-stone-900`,children:[(0,p.jsx)(`span`,{children:e.label}),(0,p.jsx)(g,{className:`w-4 h-4 text-[#4176e6] opacity-0 group-data-[selected]:opacity-100 shrink-0`})]},e.value))})]})}function y(){let[e,t]=(0,f.useState)(!1),[u,h]=(0,f.useState)(`general`),[y,b]=(0,f.useState)([]),[x,S]=(0,f.useState)(``),[C,w]=(0,f.useState)(null),[T,E]=(0,f.useState)(``),[Ee,D]=(0,f.useState)(`DeepSeek`),[O,k]=(0,f.useState)(``),[A,j]=(0,f.useState)(``),[M,N]=(0,f.useState)(``),[P,F]=(0,f.useState)([]),[I,L]=(0,f.useState)(`idle`),[De,R]=(0,f.useState)(!1),[Oe,z]=(0,f.useState)(`readonly`),[ke,Ae]=(0,f.useState)(!1),[je,B]=(0,f.useState)(!1),[Me,V]=(0,f.useState)(null),[H,U]=(0,f.useState)({language:`zh-CN`,appearance:`system`,sessionFontSize:14,toolStepDetail:`standard`,busySendBehavior:`queue`,subagentModel:``}),[W,G]=(0,f.useState)(`14`),K=(0,f.useRef)(0),q=C!==null,J=H.language,Y=y.find(e=>e.id===x),X=(Y?.name||``).trim(),Ne=X||(J===`en`?`No model`:`未配置`),Pe=X?Y?.model?.trim()?`${X} · ${Y.model.trim()}`:X:J===`en`?`No model configured`:`未配置模型`;function Fe(e=`general`){h(e),r().then(()=>{Z(),t(!0)})}function Z(){Ae(n()),b(re()),S(a()),B(!!o()),U(c()),le(c()),z(ce()),w(null)}function Ie(e){if(!e){let e=ee();w(e),E(`DeepSeek`),D(`DeepSeek`),k(`https://api.deepseek.com/v1`),j(``),N(``),F([]),L(`idle`),R(!1);return}w(e.id),E(e.name),k(e.baseURL);let t=e.apiKey?.trim()||(e.id===a()?i().trim():``)||``;j(t),N(e.model),F(e.availableModels??[]),L(e.availableModels?.length?`ok`:`idle`),D(s.find(t=>t.baseURL===e.baseURL)?.label??`自定义`),R(!1)}(0,f.useEffect)(()=>{r().then(()=>Z());let e=e=>{let n=e.detail;h(n?.tab===`model`?`model`:`general`),r().then(()=>{Z(),t(!0)})};window.addEventListener(l,e);let n=ie(e=>U(e)),i=ue(e=>z(e));return()=>{window.removeEventListener(l,e),n(),i()}},[]),(0,f.useEffect)(()=>{if(!e||u!==`model`||!q)return;let t=O.trim(),n=A.trim();if(!t||!n){L(e=>e===`ok`?`ok`:`idle`);return}L(`loading`);let r=++K.current,i=setTimeout(()=>{te(t,n).then(e=>{r===K.current&&(F(e),L(`ok`))}).catch(()=>{r===K.current&&L(`fail`)})},800);return()=>clearTimeout(i)},[e,u,q,O,A]);function Le(e){D(e);let t=s.find(t=>t.label===e);t&&(t.baseURL&&k(t.baseURL),(!T.trim()||s.some(e=>e.label===T))&&E(t.label)),N(``)}function Q(e){U(ae(e))}(0,f.useEffect)(()=>{G(String(H.sessionFontSize))},[H.sessionFontSize]);function Re(){let e=Number(W);if(!W.trim()||!Number.isFinite(e)){G(String(H.sessionFontSize));return}let t=ae({sessionFontSize:Math.round(e)});U(t),G(String(t.sessionFontSize))}let ze=!!(T.trim()&&O.trim()&&A.trim()&&M.trim()),$=P.length>0;function Be(){if(!ze||!C)return;let e=de({id:C,name:T.trim(),baseURL:O.trim(),apiKey:A.trim(),model:M.trim(),availableModels:$?P:void 0},{activate:!0});b(e),S(C),w(null),B(!!o())}function Ve(e){V(e)}function He(){let e=Me;if(!e)return;V(null);let t=se(e);b(t),S(a()),C===e&&w(null),B(!!o())}function Ue(e){ne(e),S(e),B(!!o())}let We=[{value:`readonly`,label:d(`settings.access.readonly`,void 0,J)},{value:`readwrite`,label:d(`settings.access.readwrite`,void 0,J)},{value:`full`,label:d(`settings.access.full`,void 0,J)}],Ge=[{value:`concise`,label:d(`settings.step.concise`,void 0,J)},{value:`standard`,label:d(`settings.step.standard`,void 0,J)},{value:`detailed`,label:d(`settings.step.detailed`,void 0,J)},{value:`full`,label:d(`settings.step.full`,void 0,J)}],Ke=[{value:`queue`,label:d(`settings.busySend.queue`,void 0,J)},{value:`interrupt`,label:d(`settings.busySend.interrupt`,void 0,J)}],qe=[{value:`light`,label:d(`settings.appear.light`,void 0,J),icon:`sun`},{value:`dark`,label:d(`settings.appear.dark`,void 0,J),icon:`moon`},{value:`system`,label:d(`settings.appear.system`,void 0,J),icon:`monitor`}],Je=[{id:`general`,label:d(`settings.general`,void 0,J),icon:(0,p.jsx)(Ce,{})},{id:`model`,label:d(`settings.model`,void 0,J),icon:(0,p.jsx)(we,{})}],Ye=u===`general`?d(`settings.general`,void 0,J):q?y.some(e=>e.id===C)?d(`settings.editProvider`,void 0,J):d(`settings.addProviderTitle`,void 0,J):d(`settings.model`,void 0,J);return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`div`,{className:`tw-nav-foot-row`,children:[(0,p.jsxs)(`button`,{type:`button`,onClick:()=>Fe(`general`),className:`tw-nav-settings-btn`,"data-hint":je?`设置(已配置模型)`:`设置`,children:[(0,p.jsxs)(`svg`,{className:`tw-nav-ico w-4.5 h-4.5 shrink-0`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,"aria-hidden":`true`,children:[(0,p.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`}),(0,p.jsx)(`path`,{d:`M19.4 15a1.7 1.7 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.8-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-1-1.5 1.7 1.7 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.8 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.7 1.7 0 0 0 1.5-1 1.7 1.7 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.8.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.8V9c.2.6.7 1 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1z`})]}),(0,p.jsx)(`span`,{"data-i18n":`nav.settings`,children:d(`nav.settings`,void 0,J)})]}),(0,p.jsxs)(`button`,{type:`button`,className:`tw-nav-provider-chip${X?``:` is-empty`}`,"data-hint":Pe,onClick:()=>Fe(`model`),children:[(0,p.jsx)(`span`,{className:`tw-nav-provider-dot`,"aria-hidden":`true`}),(0,p.jsx)(`span`,{className:`tw-nav-provider-name`,children:Ne})]})]}),(0,p.jsx)(ge,{show:e,children:(0,p.jsxs)(`div`,{className:`fixed inset-0 z-110 flex items-center justify-center p-4`,children:[(0,p.jsx)(_e,{children:(0,p.jsx)(`div`,{className:`tw-dialog-backdrop-anim absolute inset-0 bg-stone-950/45`,onClick:()=>t(!1),"aria-hidden":`true`})}),(0,p.jsx)(_e,{children:(0,p.jsxs)(`div`,{className:`tw-settings-dialog tw-dialog-panel-anim relative bg-white rounded-2xl shadow-2xl w-full max-w-3xl h-[min(92vh,720px)] overflow-hidden flex flex-col`,children:[(0,p.jsxs)(`div`,{className:`shrink-0 h-12 px-4 flex items-center justify-between border-b border-stone-100 bg-white`,children:[(0,p.jsx)(`h2`,{className:`text-sm font-semibold text-stone-800 truncate pr-3`,children:Ye}),(0,p.jsx)(`button`,{type:`button`,"aria-label":d(`settings.close`,void 0,J),onClick:()=>t(!1),className:`w-8 h-8 inline-flex items-center justify-center rounded-lg text-stone-400 hover:text-stone-700 hover:bg-stone-100 transition-colors`,children:(0,p.jsx)(`svg`,{className:`w-4 h-4`,viewBox:`0 0 20 20`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,children:(0,p.jsx)(`path`,{d:`M5 5l10 10M15 5L5 15`,strokeLinecap:`round`})})})]}),(0,p.jsxs)(`div`,{className:`flex-1 min-h-0 flex`,children:[(0,p.jsx)(`aside`,{className:`w-38 shrink-0 border-r border-stone-100 bg-[#f4f5f7] py-3 px-2 space-y-0.5`,children:Je.map(e=>{let t=u===e.id;return(0,p.jsxs)(`button`,{type:`button`,onClick:()=>{h(e.id),e.id===`model`&&w(null)},className:`w-full flex items-center gap-2 px-3 py-2.5 rounded-lg text-sm transition-colors ${t?`bg-[#e8f0fe] text-[#4176e6] font-medium`:`text-stone-600 hover:bg-white/70 hover:text-stone-800`}`,children:[(0,p.jsx)(`span`,{className:t?`text-[#4176e6]`:`text-stone-400`,children:e.icon}),e.label]},e.id)})}),(0,p.jsx)(`div`,{className:`flex-1 min-w-0 flex flex-col min-h-0 bg-white`,children:u===`general`?(0,p.jsxs)(`div`,{className:`flex-1 min-h-0 flex flex-col`,children:[(0,p.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-6 py-1`,children:[(0,p.jsx)(_,{title:d(`settings.access`,void 0,J),description:d(`settings.accessDesc`,void 0,J),control:(0,p.jsx)(v,{value:Oe,options:We,onChange:e=>{z(e),oe(e)}})}),(0,p.jsx)(_,{title:d(`settings.language`,void 0,J),control:(0,p.jsx)(v,{value:H.language,options:xe,onChange:e=>Q({language:e})})}),(0,p.jsxs)(`div`,{className:`py-4 border-b border-stone-100`,children:[(0,p.jsx)(`div`,{className:`text-sm font-medium text-stone-800 mb-3`,children:d(`settings.appearance`,void 0,J)}),(0,p.jsx)(`div`,{className:`grid grid-cols-3 gap-2.5`,children:qe.map(e=>{let t=H.appearance===e.value;return(0,p.jsxs)(`button`,{type:`button`,onClick:()=>Q({appearance:e.value}),className:`flex flex-col items-center justify-center gap-2 h-19 rounded-xl border transition-colors ${t?`border-[#4176e6] bg-[#edf3fe] text-[#4176e6] ring-1 ring-[#4176e6]/30`:`border-stone-200 text-stone-500 hover:border-stone-300 hover:bg-stone-50`}`,children:[(0,p.jsx)(Te,{kind:e.icon}),(0,p.jsx)(`span`,{className:`text-xs font-medium`,children:e.label})]},e.value)})})]}),(0,p.jsx)(_,{title:d(`settings.fontSize`,void 0,J),description:d(`settings.fontSizeDesc`,void 0,J),control:(0,p.jsxs)(`div`,{className:`inline-flex items-center gap-1.5`,children:[(0,p.jsx)(`input`,{type:`number`,min:12,max:22,value:W,onChange:e=>G(e.target.value),onBlur:Re,onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()},className:`w-14 h-9 px-2 text-sm text-center rounded-lg bg-stone-100 border-0 outline-none focus:ring-2 focus:ring-[#4176e6]/30`}),(0,p.jsx)(`span`,{className:`text-sm text-stone-400`,children:`px`})]})}),(0,p.jsx)(_,{title:d(`settings.toolSteps`,void 0,J),description:d(`settings.toolStepsDesc`,void 0,J),control:(0,p.jsx)(v,{value:H.toolStepDetail,options:Ge,onChange:e=>Q({toolStepDetail:e})})}),(0,p.jsx)(_,{title:d(`settings.busySend`,void 0,J),description:d(`settings.busySendDesc`,void 0,J),control:(0,p.jsx)(v,{value:H.busySendBehavior,options:Ke,onChange:e=>Q({busySendBehavior:e})})}),(0,p.jsx)(_,{title:d(`settings.subagentModel`,void 0,J),description:d(`settings.subagentModelDesc`,void 0,J),control:(0,p.jsx)(v,{value:H.subagentModel?.trim()?H.subagentModel:`inherit`,options:[{value:`inherit`,label:d(`settings.subagentModel.inherit`,void 0,J)},...Array.from(new Set([...Y?.availableModels??[],...Y?.model?[Y.model]:[]])).filter(Boolean).map(e=>({value:e,label:e}))],onChange:e=>Q({subagentModel:e===`inherit`?``:e})})})]}),(0,p.jsxs)(`div`,{className:`shrink-0 px-6 py-3 border-t border-stone-100 flex items-center justify-between text-[11px] text-stone-400`,children:[(0,p.jsx)(`span`,{children:d(`settings.platformVersion`,void 0,J)}),(0,p.jsxs)(`span`,{className:`tabular-nums text-stone-500`,children:[`v`,ye]})]})]}):q?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`div`,{className:`shrink-0 px-5 pt-3 pb-2 flex items-center gap-2 border-b border-stone-100`,children:(0,p.jsx)(`button`,{type:`button`,onClick:()=>w(null),className:`text-sm text-stone-500 hover:text-stone-800`,children:d(`settings.back`,void 0,J)})}),(0,p.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-4`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:`block text-xs font-medium text-stone-500 mb-1.5`,children:d(`settings.displayName`,void 0,J)}),(0,p.jsx)(`input`,{type:`text`,value:T,onChange:e=>E(e.target.value),placeholder:`DeepSeek`,className:m})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:`block text-xs font-medium text-stone-500 mb-1.5`,children:d(`settings.preset`,void 0,J)}),(0,p.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:s.map(e=>{let t=Ee===e.label;return(0,p.jsxs)(`button`,{type:`button`,onClick:()=>Le(e.label),className:`text-left px-3 py-2 rounded-lg border transition-colors ${t?`border-[#4176e6] bg-[#edf3fe] ring-1 ring-[#4176e6]/30`:`border-stone-200 hover:border-stone-300 hover:bg-stone-50`}`,children:[(0,p.jsx)(`div`,{className:`text-sm ${t?`text-[#3565c7] font-medium`:`text-stone-700`}`,children:e.label}),(0,p.jsx)(`div`,{className:`text-[11px] text-stone-400 truncate`,children:e.baseURL?be(e.baseURL):`OpenAI compatible`})]},e.label)})})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:`block text-xs font-medium text-stone-500 mb-1.5`,children:d(`settings.baseUrl`,void 0,J)}),(0,p.jsx)(`input`,{type:`text`,value:O,onChange:e=>k(e.target.value),placeholder:`https://api.deepseek.com/v1`,className:m})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:`block text-xs font-medium text-stone-500 mb-1.5`,children:d(`settings.apiKey`,void 0,J)}),(0,p.jsxs)(`div`,{className:`relative`,children:[(0,p.jsx)(`input`,{type:De?`text`:`password`,value:A,onChange:e=>j(e.target.value),placeholder:`sk-...`,className:`${m} pr-14`}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>R(e=>!e),className:`absolute right-2 top-1/2 -translate-y-1/2 text-[11px] text-stone-400 hover:text-stone-600 px-1.5 py-1`,children:De?J===`en`?`Hide`:`隐藏`:J===`en`?`Show`:`显示`})]}),ke?(0,p.jsx)(`p`,{className:`mt-1.5 text-[11px] text-stone-400 leading-5`,children:d(`settings.keyHint`,void 0,J)}):null]}),(0,p.jsxs)(`div`,{children:[(0,p.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,p.jsx)(`label`,{className:`text-xs font-medium text-stone-500`,children:d(`settings.modelField`,void 0,J)}),I===`loading`&&(0,p.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:d(`settings.recognizing`,void 0,J)}),$&&I===`ok`&&(0,p.jsx)(`span`,{className:`text-[11px] text-emerald-600`,children:d(`settings.recognized`,{n:P.length},J)}),I===`fail`&&!$&&(0,p.jsx)(`span`,{className:`text-[11px] text-amber-600`,children:d(`settings.recognizeFail`,void 0,J)}),I===`fail`&&$&&(0,p.jsx)(`span`,{className:`text-[11px] text-amber-600`,children:d(`settings.recognizeKeep`,void 0,J)})]}),$?(0,p.jsxs)(me,{value:M,onChange:N,children:[(0,p.jsxs)(fe,{className:`${m} flex items-center justify-between text-left hover:border-stone-400 cursor-pointer`,children:[(0,p.jsx)(`span`,{className:`truncate text-stone-800`,children:M||(J===`en`?`Select a model`:`请选择模型`)}),(0,p.jsx)(Se,{className:`w-4 h-4 shrink-0 ml-2 text-stone-400`})]}),(0,p.jsx)(he,{transition:!0,anchor:{to:`bottom start`,gap:6},className:`tw-select-menu tw-menu-anim z-60 w-(--button-width) max-h-60 overflow-auto rounded-lg py-1 shadow-lg ring-1 ring-stone-200 focus:outline-none`,children:P.map(e=>(0,p.jsxs)(pe,{value:e,className:`group cursor-pointer select-none flex items-center justify-between px-3 py-2 text-sm text-stone-700 data-[focus]:bg-[#edf3fe] data-[selected]:text-[#3565c7] data-[selected]:font-medium`,children:[(0,p.jsx)(`span`,{className:`truncate`,children:e}),(0,p.jsx)(g,{className:`w-4 h-4 text-[#4176e6] opacity-0 group-data-[selected]:opacity-100 shrink-0 ml-2`})]},e))})]}):(0,p.jsx)(`input`,{type:`text`,value:M,onChange:e=>N(e.target.value),placeholder:d(`settings.modelPlaceholder`,void 0,J),className:m})]})]}),(0,p.jsxs)(`div`,{className:`shrink-0 px-5 py-3.5 bg-stone-50 border-t border-stone-100 flex justify-end gap-2`,children:[(0,p.jsx)(`button`,{type:`button`,onClick:()=>w(null),className:`px-3.5 py-1.5 text-sm text-stone-600 hover:bg-stone-200/60 rounded-lg`,children:d(`settings.cancel`,void 0,J)}),(0,p.jsx)(`button`,{type:`button`,onClick:Be,disabled:!ze,className:`px-3.5 py-1.5 text-sm font-medium text-white bg-[#4176e6] hover:bg-[#3565c7] rounded-lg disabled:opacity-40 disabled:cursor-not-allowed`,children:d(`settings.save`,void 0,J)})]})]}):(0,p.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-6 py-5 bg-[#f4f5f7]`,children:[(0,p.jsx)(`p`,{className:`text-sm text-stone-500`,children:d(`settings.modelIntro`,void 0,J)}),(0,p.jsxs)(`div`,{className:`mt-5 space-y-2.5`,children:[y.map(e=>{let t=!!(e.apiKey?.trim()&&e.baseURL.trim()&&e.model.trim()),n=e.id===x;return(0,p.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl border border-stone-200/90 bg-white px-4 py-3.5 shadow-[0_1px_0_rgba(15,23,42,0.02)]`,children:[(0,p.jsxs)(`button`,{type:`button`,"data-hint":n?J===`en`?`Active`:`当前使用`:J===`en`?`Set active`:`设为当前`,onClick:()=>Ue(e.id),className:`flex-1 min-w-0 flex items-center gap-2 text-left`,children:[(0,p.jsx)(`span`,{className:`text-sm font-medium text-stone-800 truncate`,children:e.name}),t?(0,p.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0 bg-emerald-500`}):null]}),(0,p.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[(0,p.jsx)(`button`,{type:`button`,onClick:()=>Ie(e),className:`h-8 px-3 text-sm text-stone-700 rounded-lg border border-stone-200 bg-white hover:bg-stone-50`,children:d(`settings.edit`,void 0,J)}),y.length>1?(0,p.jsx)(`button`,{type:`button`,onClick:()=>Ve(e.id),className:`h-8 px-3 text-sm text-red-600 rounded-lg hover:bg-red-50`,children:d(`settings.delete`,void 0,J)}):null]})]},e.id)}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>Ie(null),className:`w-full h-12 rounded-xl border border-dashed border-stone-300 bg-white/60 text-sm text-stone-600 hover:border-[#4176e6] hover:text-[#4176e6] hover:bg-[#edf3fe]/50 transition-colors`,children:d(`settings.addProvider`,void 0,J)})]})]})})]})]})})]})}),(0,p.jsx)(ve,{open:Me!=null,title:d(`settings.delete`,void 0,J),message:d(`settings.deleteConfirm`,void 0,J),confirmLabel:d(`settings.delete`,void 0,J),cancelLabel:J===`en`?`Cancel`:`取消`,danger:!0,onClose:()=>V(null),onConfirm:He})]})}export{y as default};
@@ -0,0 +1 @@
1
+ import{c as e,n as t}from"./react-dom.CqAxpHMt.js";import{t as n}from"./jsx-runtime.BUXbF_vF.js";var r=e(t(),1),i=n(),a=220;function o({open:e,onClose:t,title:n,closeAriaLabel:o=`关闭面板`,children:s,footer:c}){let[l,u]=(0,r.useState)(e),[d,f]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{if(e){u(!0);let e=window.requestAnimationFrame(()=>{window.requestAnimationFrame(()=>f(!0))});return()=>window.cancelAnimationFrame(e)}f(!1);let t=window.setTimeout(()=>u(!1),a);return()=>window.clearTimeout(t)},[e]),(0,r.useEffect)(()=>{if(!e)return;function n(e){e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),t())}return window.addEventListener(`keydown`,n,!0),()=>window.removeEventListener(`keydown`,n,!0)},[e,t]),l?(0,i.jsxs)(`div`,{className:`fixed inset-0 z-60 flex justify-end`,role:`dialog`,"aria-modal":`true`,children:[(0,i.jsx)(`button`,{type:`button`,className:`absolute inset-0 bg-stone-900/30 transition-opacity duration-200 ease-out ${d?`opacity-100`:`opacity-0`}`,"aria-label":o,onClick:t}),(0,i.jsxs)(`aside`,{className:`tw-slide-over relative w-full max-w-md h-full shadow-2xl border-l border-stone-200 flex flex-col transition-transform duration-200 ease-out will-change-transform ${d?`translate-x-0`:`translate-x-full`}`,children:[(0,i.jsxs)(`header`,{className:`shrink-0 h-12 px-4 border-b border-stone-100 flex items-center gap-2`,children:[(0,i.jsx)(`h2`,{className:`tw-slide-over-title text-sm font-semibold text-stone-800 flex-1`,children:n}),(0,i.jsx)(`button`,{type:`button`,onClick:t,className:`tw-icon-btn w-8 h-8 rounded-lg`,"data-hint":`关闭(Esc)`,children:`✕`})]}),(0,i.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 space-y-4`,children:s}),c]})]}):null}export{o as t};
@@ -0,0 +1,7 @@
1
+ import{c as e,n as t}from"./react-dom.CqAxpHMt.js";import{f as n,i as r}from"./app-config.vqDkEMS3.js";import{n as i}from"./llm.BZEzE0x2.js";import{f as a}from"./project-docs.Cd2gKPKh.js";import{t as o}from"./prompts-meta.F4wwkjUA.js";import{l as s}from"./settings.CkbipdPI.js";import{t as c}from"./jsx-runtime.BUXbF_vF.js";import{a as l,i as u,n as d,r as f,t as p}from"./ConfirmDialog.BYz4HREM.js";import{i as m,n as h,r as g,t as _}from"./menu.CqkL87bV.js";import{n as v}from"./i18n.9qZsrs3u.js";var y=e(t(),1),b=`/__tb_spaces`;async function x(e,t){try{let n=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t??{})}),r=await n.json();return n.ok?r:{ok:!1,error:r?.error||`请求失败(HTTP ${n.status})`}}catch(e){return{ok:!1,error:e instanceof Error?e.message:String(e)}}}async function S(e){try{return(await fetch(b,{signal:e??AbortSignal.timeout(2e3)})).ok}catch{return!1}}async function ee(e){try{let t=e?.stats?`${b}?stats=1`:b,r=await fetch(t);if(!r.ok)return null;let i=await r.json();return i?.activeId&&n(i.activeId),i}catch{return null}}async function te(e){let t=await x(`${b}/switch`,{id:e});return t.ok&&n(e),t}function ne(e,t){return x(`${b}/create`,{name:e,managedParent:t?.managedParent,switch:t?.switch===!0,systemPrompt:t?.systemPrompt,promptBrief:t?.promptBrief})}function C(e){let t=e instanceof Error?e.message:String(e??``);return!t.trim()||/^not found$/i.test(t.trim())?`本地服务版本较旧,还没有空间编辑接口;请重启本地服务后再试`:t}async function re(e){try{let t=await fetch(`${b}/detail?id=${encodeURIComponent(e)}`),n=await t.json();return t.ok?n:{ok:!1,error:C(n?.error??`HTTP ${t.status}`)}}catch(e){return{ok:!1,error:C(e)}}}async function ie(e,t){let n=await x(`${b}/update`,{id:e,...t});return n.ok?n:{...n,error:C(n.error)}}function ae(e,t){return x(`${b}/copy`,{id:e,name:t})}function oe(e,t){return x(`${b}/delete`,{id:e,purge:t,confirm:t===!0})}function se(e,t=`full`){return`${b}/export?id=${encodeURIComponent(e)}${t===`content`?`&scope=content`:``}`}function ce(e){return x(`${b}/discover`,Array.isArray(e)&&e.length?{adopt:e}:{})}async function le(e,t){let n=await e.arrayBuffer(),r=new Uint8Array(n),i=``,a=32768;for(let e=0;e<r.length;e+=a)i+=String.fromCharCode(...r.subarray(e,e+a));let o=btoa(i);return x(`${b}/import`,{zipBase64:o,name:t})}function w(e){return e.isPublic?v(`space.publicName`):e.name}function T(e,t){let n=e.includes(`\\`)?`\\`:`/`,r=t.replace(/[/\\]+$/,``),i=`${r}${n}空间池`;if(e===i)return r;let a=`${i}${n}`;return e.startsWith(a)?`${r}${n}${e.slice(a.length)}`:e}function ue(e){if(!e||e<=0)return`—`;let t=[`B`,`KB`,`MB`,`GB`,`TB`],n=0,r=e;for(;r>=1024&&n<t.length-1;)r/=1024,n+=1;return`${r<10&&n>0?r.toFixed(1):Math.round(r)} ${t[n]}`}var de=`你是提示词作者。根据用户对这个数据空间的要求,写一份「默认提示词」正文(Markdown 纯文本,不要用代码围栏)。
2
+ 这份提示词将作为 Lantern Harness 该空间里 AI 助手的默认人设与回答原则。
3
+ 要求:
4
+ - 用「你是…」起头设定角色;
5
+ - 紧扣用户描述的领域与工作方式;
6
+ - 写几条简洁的回答原则(问什么答什么、先结论);
7
+ - 只输出提示词正文,不要解释、不要标题。`;function fe(e){let t=String(e??``).replace(/^\uFEFF/,``).trim(),n=/^```(?:markdown|md|text)?\s*\n([\s\S]*?)\n```$/i.exec(t);return n&&(t=n[1].trim()),t}var E=c();function pe(e){return e instanceof DOMException&&e.name===`AbortError`||e instanceof Error&&e.name===`AbortError`}function me({hint:e,children:t}){return e?(0,E.jsx)(`span`,{className:`inline-flex cursor-help`,"data-hint":e,"data-hint-always":``,children:t}):t}function he(e){let{value:t,onChange:n,onGenerate:r,onStop:i,generating:a,disabled:o}=e,s=(0,y.useRef)(null);(0,y.useLayoutEffect)(()=>{let e=s.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,96)}px`)},[t]);let c=!!t.trim()&&!a&&!o;return(0,E.jsxs)(`div`,{className:`tw-space-prompt-composer pt-1 rounded-lg bg-white border border-stone-200 outline-none transition-colors focus-within:ring-2 focus-within:ring-[#4176e6]/30 focus-within:border-[#4176e6]`,children:[(0,E.jsx)(`textarea`,{ref:s,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{if(e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing){if(e.preventDefault(),a){i();return}c&&r()}},placeholder:v(`space.promptBriefPlaceholder`),rows:1,disabled:o,className:`block w-full min-h-6 pl-3.5 pr-2 pt-0.5 pb-0 text-sm leading-5 text-stone-800 bg-transparent resize-none focus:outline-none placeholder:text-stone-400 disabled:opacity-60`}),(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-2 px-3 pb-2 pt-1`,children:[(0,E.jsx)(`span`,{className:`flex-1`}),(0,E.jsx)(`button`,{type:`button`,onClick:()=>a?i():r(),disabled:!a&&!c,"aria-label":v(a?`space.promptStop`:`space.promptGenerate`),className:`w-7 h-7 shrink-0 rounded-full flex items-center justify-center outline-none transition-colors ${a?`bg-stone-200 text-stone-700 hover:bg-stone-300`:`bg-[#4176e6] text-white hover:bg-[#3565c7] disabled:bg-[#a9c3ef] disabled:cursor-not-allowed`}`,children:a?(0,E.jsx)(`span`,{className:`w-2.5 h-2.5 bg-current rounded-xs`}):(0,E.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,className:`w-4 h-4`,"aria-hidden":!0,children:[(0,E.jsx)(`path`,{d:`m5 12 7-7 7 7`}),(0,E.jsx)(`path`,{d:`M12 19V5`})]})})]})]})}function ge(e){return(0,E.jsxs)(E.Fragment,{children:[(0,E.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-2 mb-1.5`,children:[(0,E.jsx)(`label`,{className:`text-xs font-medium text-stone-500`,children:v(`space.promptBodyLabel`)}),(0,E.jsx)(`span`,{className:`text-[11px] text-stone-400 font-mono truncate`,children:o})]}),(0,E.jsx)(`textarea`,{value:e.value,onChange:t=>e.onChange(t.target.value),placeholder:v(`space.promptBodyPlaceholder`),rows:8,disabled:e.disabled,className:`w-full min-h-36 px-3 py-2 text-sm leading-relaxed rounded-lg border border-stone-200 text-stone-800 outline-none focus:ring-2 focus:ring-[#4176e6]/30 focus:border-[#4176e6] transition-colors resize-y font-[inherit]`}),(0,E.jsx)(`p`,{className:`mt-1.5 text-[11px] text-stone-400 leading-snug`,children:e.hint??v(`space.promptHint`)})]})}function D({open:e,onClose:t,onListChanged:c}){let[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(null),[b,x]=(0,y.useState)(``),[S,C]=(0,y.useState)(``),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(``),[j,M]=(0,y.useState)(``),[N,P]=(0,y.useState)(``),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(``),[_e,ve]=(0,y.useState)(``),[ye,z]=(0,y.useState)(``),[B,be]=(0,y.useState)(!1),[xe,Se]=(0,y.useState)(!1),[V,H]=(0,y.useState)(null),[U,W]=(0,y.useState)(null),[Ce,we]=(0,y.useState)(``),[G,K]=(0,y.useState)([]),[Te,q]=(0,y.useState)({}),Ee=(0,y.useRef)(null),De=(0,y.useRef)(null),Oe=(0,y.useRef)(null),J=(0,y.useRef)(null),[ke,Ae]=(0,y.useState)(null),Y=(0,y.useCallback)(async(e=!1)=>{e&&_(`stats`);let t=await ee({stats:e});e&&_(null),t?(h(t),c?.(t)):x(`无法读取数据空间列表(本地服务未运行?)`)},[c]),je=(0,y.useRef)(Y);(0,y.useEffect)(()=>{je.current=Y},[Y]);function X(){J.current?.abort()}(0,y.useEffect)(()=>{e?(x(``),C(``),O(!1),I(null),je.current(!1)):(X(),O(!1),I(null),Ae(null))},[e]);async function Me(e){if(ke||g!==null)return;let t=(e===`create`?j:_e).trim();if(!t){x(v(`space.promptNeedReq`));return}x(``);let n=new AbortController;J.current=n,Ae(e);try{await r();let a=s();if(!a?.apiKey?.trim()||!a.model?.trim()||!a.baseURL?.trim()){x(v(`space.promptNeedModel`));return}let o=(e===`create`?k:L).trim(),c=await i(a,[{role:`system`,content:de},{role:`user`,content:(o?`空间名称:${o}\n\n`:``)+`用户要求:\n${t}`}],n.signal);if(n.signal.aborted)return;let l=fe(c);if(!l){x(v(`space.promptGenEmpty`));return}e===`create`?P(l):z(l)}catch(e){if(pe(e)||n.signal.aborted)return;x(e instanceof Error?e.message:String(e))}finally{J.current===n&&(J.current=null),Ae(null)}}function Ne(){X(),x(``),C(``),A(``),M(``),P(``),O(!0),requestAnimationFrame(()=>De.current?.scrollIntoView({block:`nearest`}))}async function Pe(){if(g!==null)return;let e=k.trim();if(!e){x(v(`space.needName`));return}X();let t=N.trim(),r=j.trim();_(`create`),x(``);let i=await ne(e,{switch:!0,...t?{systemPrompt:t}:{},...r?{promptBrief:r}:{}});if(_(null),!i.ok){x(i.error||v(`space.create`)+` 失败`);return}let a=i.space?.id;a&&n(a),window.location.reload()}async function Fe(e){X(),x(``),C(``),I(e),R(e.name),ve(``),Se(!1),z(``),be(!0),requestAnimationFrame(()=>Oe.current?.scrollIntoView({block:`nearest`}));let t=await re(e.id),n=``,r=``;if(t.ok)n=t.brief??``,r=t.systemPrompt??``;else if(e.isActive)try{r=(await a(`prompts`,o)).content.trim()}catch{}if(be(!1),!t.ok&&!r){I(null),x(t.error||v(`space.detailFailed`));return}t.space&&R(t.space.name),z(r);let i=!n.trim()&&!!r;ve(i?r:n),Se(i)}async function Ie(){if(!F||g!==null)return;let e=L.trim();if(!e){x(v(`space.needName`));return}X(),_(`update`),x(``);let t=await ie(F.id,{name:e,...xe?{}:{brief:_e},systemPrompt:ye});if(_(null),!t.ok){x(t.error||v(`space.updateFailed`));return}let n=!!(t.space&&t.space.name!==F.name),r=F.isActive;I(null),C(v(`space.updated`,{name:t.space?.name??e})),n&&r?window.location.reload():await Y(!1)}async function Le(e){if(e.isActive||g!==null)return;_(`update`),x(``);let t=await te(e.id);_(null),t.ok?window.location.reload():x(t.error||`切换失败`)}async function Re(){if(!U)return;let e=Ce.trim();if(!e)return;_(`copy`),x(``);let t=await ae(U.id,e);_(null),t.ok?(W(null),C(`已复制为「${t.space?.name}」`),await Y(!1)):x(t.error||`复制失败`)}async function ze(e,t){_(`delete`),x(``);let r=await oe(e.id,t);_(null),r.ok?(H(null),e.isActive?(n(`public`),window.location.reload()):(C(r.warning?r.warning:r.purged?`已删除「${e.name}」及其数据`:`已从列表移除「${e.name}」(数据保留在磁盘)`),await Y(!1))):x(r.error||`删除失败`)}async function Be(){_(`discover`),x(``),C(``),K([]);let e=await ce();if(_(null),!e.ok){x(e.error||`扫描失败`);return}let t=e.added?.length??0,n=e.backfilled?.length??0,r=e.skipped?.length??0,i=e.candidates??[],a=[];t?a.push(v(`space.discoverAdded`,{n:t})):i.length||a.push(v(`space.discoverNone`)),n&&a.push(v(`space.discoverBackfilled`,{n})),r&&a.push(v(`space.discoverSkipped`,{n:r})),C(a.join(`;`)),K(i),q(Object.fromEntries(i.map(e=>[e.path,e.hasContent===!0]))),await Y(!1)}async function Ve(){let e=G.filter(e=>Te[e.path]).map(e=>e.path);if(!e.length){K([]),C(v(`space.candidatesIgnored`));return}_(`discover`),x(``);let t=await ce(e);if(_(null),!t.ok){x(t.error||`纳入失败`);return}K([]);let n=t.added?.length??0,r=t.skipped??[],i=[n?v(`space.candidatesAdopted`,{n}):v(`space.candidatesIgnored`)];r.length&&i.push(v(`space.candidatesRejected`,{names:r.map(e=>e.reason).join(`、`)})),C(i.join(`;`)),await Y(!1)}async function He(e){let t=e.target.files?.[0];if(e.target.value=``,!t)return;_(`import`),x(``);let n=await le(t);_(null),n.ok?(C(`已导入为「${n.space?.name}」`),await Y(!1)):x(n.error||`导入失败`)}let Z=m?.spaces??[],Ue=new Map(Z.map((e,t)=>[e.id,t])),We=e=>e.isPublic?0:e.isActive?1:2,Ge=[...Z].sort((e,t)=>We(e)-We(t)||(Ue.get(e.id)??0)-(Ue.get(t.id)??0)),Q=m?.baseRoot,$=g!==null,Ke=ke===`create`,qe=ke===`edit`;return(0,E.jsxs)(E.Fragment,{children:[(0,E.jsxs)(u,{open:e,onClose:t,transition:!0,className:`relative z-95`,children:[(0,E.jsx)(d,{transition:!0,className:`tw-dialog-backdrop-anim fixed inset-0 bg-black/30`,"aria-hidden":`true`}),(0,E.jsx)(`div`,{className:`fixed inset-0 flex items-center justify-center p-4`,children:(0,E.jsxs)(l,{transition:!0,className:`tw-dialog-panel-anim tw-space-dialog w-full max-w-4xl rounded-xl shadow-xl border border-stone-200 bg-white flex flex-col h-[86vh]`,children:[(0,E.jsxs)(`div`,{className:`flex items-start justify-between gap-4 px-5 pt-4 pb-3 border-b border-stone-200`,children:[(0,E.jsxs)(`div`,{className:`min-w-0`,children:[(0,E.jsx)(f,{className:`tw-confirm-title text-base font-semibold text-stone-900`,children:v(`space.manageTitle`)}),(0,E.jsx)(`p`,{className:`mt-1 text-xs text-stone-500 leading-relaxed`,children:v(`space.manageDesc`)})]}),(0,E.jsx)(`div`,{className:`shrink-0 flex items-center gap-2`,children:(0,E.jsx)(`button`,{type:`button`,onClick:t,className:`tw-confirm-cancel w-7 h-7 flex items-center justify-center rounded-md text-stone-400 hover:bg-stone-100 hover:text-stone-700 transition-colors`,"aria-label":`关闭`,children:`✕`})})]}),(0,E.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-5 py-4`,children:[b?(0,E.jsxs)(`div`,{className:`mb-3 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700 flex items-start gap-2`,children:[(0,E.jsx)(`span`,{className:`flex-1 min-w-0`,children:b}),(0,E.jsx)(`button`,{type:`button`,onClick:()=>x(``),className:`shrink-0 w-5 h-5 -mr-0.5 flex items-center justify-center rounded text-red-700/70 hover:bg-red-100 hover:text-red-900`,"aria-label":`关闭`,children:`✕`})]}):null,S?(0,E.jsxs)(`div`,{className:`mb-3 rounded-lg border border-emerald-200 bg-emerald-50 px-3 py-2 text-xs text-emerald-700 flex items-start gap-2`,children:[(0,E.jsx)(`span`,{className:`flex-1 min-w-0`,children:S}),(0,E.jsx)(`button`,{type:`button`,onClick:()=>C(``),className:`shrink-0 w-5 h-5 -mr-0.5 flex items-center justify-center rounded text-emerald-700/70 hover:bg-emerald-100 hover:text-emerald-900`,"aria-label":`关闭`,children:`✕`})]}):null,G.length?(0,E.jsxs)(`div`,{className:`mb-3 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2.5`,children:[(0,E.jsx)(`div`,{className:`text-xs font-medium text-amber-800`,children:v(`space.candidatesTitle`,{n:G.length})}),(0,E.jsx)(`p`,{className:`mt-1 text-[11px] leading-snug text-amber-700/90`,children:v(`space.candidatesHint`)}),(0,E.jsx)(`div`,{className:`mt-2 max-h-44 overflow-auto rounded-md border border-amber-200/70 bg-white divide-y divide-stone-100`,children:G.map(e=>(0,E.jsxs)(`label`,{className:`flex items-start gap-2 px-2.5 py-1.5 cursor-pointer hover:bg-stone-50`,children:[(0,E.jsx)(`input`,{type:`checkbox`,checked:Te[e.path]===!0,onChange:t=>q(n=>({...n,[e.path]:t.target.checked})),className:`mt-0.5 accent-[#4176e6]`}),(0,E.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,E.jsx)(`span`,{className:`block text-xs text-stone-800 truncate`,children:e.name}),(0,E.jsx)(`span`,{className:`block text-[10px] text-stone-400 truncate font-mono`,children:Q?T(e.path,Q):e.path})]})]},e.path))}),(0,E.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,E.jsx)(`button`,{type:`button`,onClick:()=>q(Object.fromEntries(G.map(e=>[e.path,!0]))),className:`text-[11px] text-[#4176e6] hover:underline`,children:v(`space.candidatesSelectAll`)}),(0,E.jsx)(`button`,{type:`button`,onClick:()=>q({}),className:`text-[11px] text-stone-500 hover:underline`,children:v(`space.candidatesClear`)}),(0,E.jsx)(`span`,{className:`flex-1`}),(0,E.jsx)(`button`,{type:`button`,onClick:()=>{K([]),q({}),C(v(`space.candidatesIgnored`))},className:`px-2.5 py-1 text-[11px] rounded-md border border-stone-200 text-stone-600 hover:bg-stone-50`,children:v(`space.candidatesIgnore`)}),(0,E.jsx)(`button`,{type:`button`,disabled:$,onClick:()=>void Ve(),className:`px-2.5 py-1 text-[11px] rounded-md bg-[#4176e6] text-white hover:bg-[#3565c7] disabled:opacity-40`,children:v(`space.candidatesAdopt`)})]})]}):null,D?(0,E.jsxs)(`div`,{ref:De,children:[(0,E.jsxs)(`div`,{className:`mb-2`,children:[(0,E.jsx)(`div`,{className:`text-xs font-medium text-stone-500`,children:v(`space.newTitle`)}),(0,E.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-stone-400`,children:v(`space.newDesc`)})]}),(0,E.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,E.jsx)(`input`,{autoFocus:!0,value:k,onChange:e=>A(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),Pe())},placeholder:v(`space.namePlaceholder`),className:`w-full h-9 px-3 text-sm rounded-lg border border-stone-200 text-stone-800 outline-none focus:ring-2 focus:ring-[#4176e6]/30 focus:border-[#4176e6] transition-colors`})}),m?(0,E.jsx)(`div`,{className:`mt-1.5 text-[11px] text-stone-400 truncate`,children:(0,E.jsx)(`code`,{children:T(m.dataRoot,m.baseRoot)})}):null,(0,E.jsxs)(`div`,{className:`mt-4 pt-3 border-t border-stone-200`,children:[(0,E.jsx)(`div`,{className:`text-xs font-medium text-stone-500 mb-1.5`,children:v(`space.promptBriefLabel`)}),(0,E.jsx)(he,{value:j,onChange:M,onGenerate:()=>void Me(`create`),onStop:X,generating:Ke,disabled:$}),(0,E.jsxs)(`div`,{className:`mt-1.5 flex items-start gap-3`,children:[(0,E.jsx)(`p`,{className:`flex-1 min-w-0 text-[11px] text-stone-400 leading-snug`,children:v(`space.promptHint`)}),Ke?(0,E.jsxs)(`p`,{className:`tw-busy-status shrink-0`,"aria-live":`polite`,children:[v(`space.promptGeneratingStatus`),(0,E.jsx)(`span`,{className:`tw-busy-ellipsis`,"aria-hidden":!0})]}):null]}),(0,E.jsx)(ge,{value:N,onChange:P,disabled:$})]})]}):F?(0,E.jsxs)(`div`,{ref:Oe,children:[(0,E.jsxs)(`div`,{className:`mb-2`,children:[(0,E.jsx)(`div`,{className:`text-xs font-medium text-stone-500`,children:v(`space.editTitle`)}),(0,E.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-stone-400 font-mono truncate`,children:Q?T(F.path,Q):F.path})]}),(0,E.jsxs)(`label`,{className:`block text-xs font-medium text-stone-500`,children:[v(`space.nameLabel`),(0,E.jsx)(`input`,{autoFocus:!0,value:L,disabled:B||F.isPublic===!0,onChange:e=>R(e.target.value),className:`mt-1.5 w-full h-9 px-3 text-sm rounded-lg border border-stone-200 text-stone-800 outline-none focus:ring-2 focus:ring-[#4176e6]/30 focus:border-[#4176e6] transition-colors disabled:bg-stone-50 disabled:text-stone-400`})]}),F.isPublic?(0,E.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:v(`space.publicNameLocked`)}):null,(0,E.jsxs)(`div`,{className:`mt-4 pt-3 border-t border-stone-200`,children:[(0,E.jsx)(`div`,{className:`text-xs font-medium text-stone-500 mb-1.5`,children:v(`space.promptBriefLabel`)}),(0,E.jsx)(he,{value:_e,onChange:e=>{ve(e),Se(!1)},onGenerate:()=>void Me(`edit`),onStop:X,generating:qe,disabled:$||B}),(0,E.jsxs)(`div`,{className:`mt-1.5 flex items-start gap-3`,children:[(0,E.jsx)(`p`,{className:`flex-1 min-w-0 text-[11px] text-stone-400 leading-snug`,children:v(`space.promptBriefHint`)}),qe?(0,E.jsxs)(`p`,{className:`tw-busy-status shrink-0`,"aria-live":`polite`,children:[v(`space.promptGeneratingStatus`),(0,E.jsx)(`span`,{className:`tw-busy-ellipsis`,"aria-hidden":!0})]}):null]}),(0,E.jsx)(ge,{value:ye,onChange:z,disabled:$||B,hint:v(`space.promptEditHint`)}),B?(0,E.jsx)(`p`,{className:`mt-2 text-[11px] text-stone-400`,children:v(`space.loading`)}):null]})]}):(0,E.jsxs)(E.Fragment,{children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,E.jsxs)(`div`,{className:`text-xs font-medium text-stone-500`,children:[v(`space.listTitle`),Z.length?(0,E.jsx)(`span`,{className:`ml-1.5 text-[11px] text-stone-400 tabular-nums`,children:Z.length}):null]}),(0,E.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,E.jsx)(`button`,{type:`button`,disabled:$,onClick:()=>Ee.current?.click(),className:`text-xs text-[#4176e6] hover:underline disabled:opacity-40`,children:g===`import`?`…`:v(`space.import`)}),(0,E.jsx)(`input`,{ref:Ee,type:`file`,accept:`.zip,application/zip`,className:`hidden`,onChange:e=>void He(e)}),(0,E.jsx)(`button`,{type:`button`,disabled:$,onClick:()=>void Be(),"data-hint":v(`space.discoverTitle`),"data-hint-always":``,className:`text-xs text-[#4176e6] hover:underline disabled:opacity-40`,children:v(g===`discover`?`space.discovering`:`space.discover`)}),(0,E.jsx)(`button`,{type:`button`,disabled:$,onClick:()=>void Y(!0),"data-hint":v(`space.sizeTitle`),"data-hint-always":``,className:`text-xs text-[#4176e6] hover:underline disabled:opacity-40`,children:v(g===`stats`?`space.sizing`:`space.size`)})]})]}),(0,E.jsx)(`div`,{className:`rounded-lg border border-stone-200 divide-y divide-stone-100 overflow-hidden`,children:Z.length===0?(0,E.jsx)(`div`,{className:`px-3 py-8 text-center text-xs text-stone-400`,children:v(`space.empty`)}):Ge.map(e=>(0,E.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2.5`,children:[(0,E.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,E.jsx)(`span`,{className:`text-sm font-medium text-stone-800 truncate`,children:w(e)}),e.isPublic?(0,E.jsx)(`span`,{className:`shrink-0 rounded px-1.5 py-px text-[10px] bg-stone-100 text-stone-500`,children:v(`space.builtin`)}):null,e.isActive?(0,E.jsx)(`span`,{className:`shrink-0 rounded px-1.5 py-px text-[10px] bg-[#4176e6]/10 text-[#3565c7]`,children:v(`space.activeTag`)}):null,e.exists?null:(0,E.jsx)(`span`,{className:`shrink-0 rounded px-1.5 py-px text-[10px] bg-amber-50 text-amber-600`,children:v(`space.missing`)}),e.bytes==null?null:(0,E.jsx)(`span`,{className:`shrink-0 rounded px-1.5 py-px text-[10px] bg-stone-100 text-stone-500 tabular-nums`,children:ue(e.bytes)})]}),(0,E.jsx)(`div`,{className:`mt-0.5 text-[11px] text-stone-400 truncate cursor-help hover:text-stone-500`,"data-hint":Q?T(e.path,Q):e.path,"data-hint-always":``,children:Q?T(e.path,Q):e.path})]}),(0,E.jsxs)(`div`,{className:`shrink-0 flex flex-wrap justify-end items-center gap-1`,children:[!e.isActive&&e.exists?(0,E.jsx)(`button`,{type:`button`,disabled:$,onClick:()=>void Le(e),className:`h-7 px-2 text-xs rounded-md border border-stone-200 text-stone-600 hover:bg-stone-100 disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:v(`space.switch`)}):null,(0,E.jsx)(`button`,{type:`button`,disabled:$||!e.exists,onClick:()=>void Fe(e),className:`h-7 px-2 text-xs rounded-md border border-stone-200 text-stone-600 hover:bg-stone-100 disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:v(`space.edit`)}),(0,E.jsx)(`button`,{type:`button`,disabled:$,onClick:()=>{W(e),we(`${e.name}-copy`)},className:`h-7 px-2 text-xs rounded-md border border-stone-200 text-stone-600 hover:bg-stone-100 disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:v(`space.copy`)}),(0,E.jsx)(`a`,{href:se(e.id,`content`),"data-hint":v(`space.exportContentTitle`),"data-hint-always":``,className:`h-7 px-2 text-xs rounded-md border border-stone-200 text-stone-600 hover:bg-stone-100 inline-flex items-center transition-colors`,children:v(`space.exportContent`)}),(0,E.jsx)(`a`,{href:se(e.id,`full`),"data-hint":v(`space.exportFullTitle`),"data-hint-always":``,className:`h-7 px-2 text-xs rounded-md border border-stone-200 text-stone-600 hover:bg-stone-100 inline-flex items-center transition-colors`,children:v(`space.exportFull`)}),(0,E.jsx)(me,{hint:e.removable?void 0:v(`space.publicLocked`),children:(0,E.jsx)(`button`,{type:`button`,disabled:!e.removable||$,onClick:()=>H({kind:`remove`,space:e}),className:`h-7 px-2 text-xs rounded-md border border-stone-200 text-stone-600 hover:bg-stone-100 disabled:opacity-30 disabled:cursor-not-allowed disabled:pointer-events-none transition-colors`,children:v(`space.removeList`)})}),(0,E.jsx)(me,{hint:e.removable?void 0:v(`space.publicLocked`),children:(0,E.jsx)(`button`,{type:`button`,disabled:!e.removable||$,onClick:()=>H({kind:`delete`,space:e}),className:`h-7 px-2 text-xs rounded-md border border-red-200 text-red-600 hover:bg-red-50 disabled:opacity-30 disabled:cursor-not-allowed disabled:pointer-events-none transition-colors`,children:v(`space.deleteDisk`)})})]})]},e.id))})]})]}),(0,E.jsxs)(`div`,{className:`flex items-center gap-2 px-5 py-3 border-t border-stone-200`,children:[(0,E.jsx)(`button`,{type:`button`,disabled:$||D||F!==null,onClick:()=>{!D&&F===null&&Ne()},className:`h-8 px-3 text-xs font-medium text-white bg-[#4176e6] rounded-lg hover:bg-[#3565c7] disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-[#4176e6] transition-colors`,children:v(`space.addNew`)}),(0,E.jsx)(`span`,{className:`flex-1`}),D||F?(0,E.jsx)(`button`,{type:`button`,disabled:$,onClick:()=>{X(),O(!1),I(null)},className:`tw-confirm-cancel h-8 px-4 text-sm rounded-lg border border-stone-200 text-stone-600 hover:bg-stone-100 disabled:opacity-40 transition-colors`,children:v(`space.cancel`)}):null,D?(0,E.jsx)(`button`,{type:`button`,disabled:!k.trim()||$,onClick:()=>void Pe(),className:`h-8 px-4 text-sm font-medium text-white bg-[#4176e6] rounded-lg hover:bg-[#3565c7] disabled:opacity-40 transition-colors`,children:g===`create`?`…`:v(`space.create`)}):F?(0,E.jsx)(`button`,{type:`button`,disabled:!L.trim()||$||B,onClick:()=>void Ie(),className:`h-8 px-4 text-sm font-medium text-white bg-[#4176e6] rounded-lg hover:bg-[#3565c7] disabled:opacity-40 transition-colors`,children:g===`update`?`…`:v(`space.save`)}):null]})]})})]}),(0,E.jsxs)(u,{open:U!==null,onClose:()=>W(null),transition:!0,className:`relative z-96`,children:[(0,E.jsx)(d,{transition:!0,className:`tw-dialog-backdrop-anim fixed inset-0 bg-black/30`,"aria-hidden":`true`}),(0,E.jsx)(`div`,{className:`fixed inset-0 flex items-center justify-center p-4`,children:(0,E.jsxs)(l,{transition:!0,className:`tw-confirm-dialog tw-dialog-panel-anim w-full max-w-sm rounded-xl shadow-xl border border-stone-200 p-5 bg-white`,children:[(0,E.jsx)(f,{className:`tw-confirm-title text-base font-semibold text-stone-900`,children:v(`space.confirmCopyTitle`)}),(0,E.jsx)(`p`,{className:`tw-confirm-msg mt-3 text-sm text-stone-600 leading-relaxed`,children:v(`space.confirmCopyMsg`,{name:U?.name??``})}),(0,E.jsxs)(`label`,{className:`mt-3 block text-xs font-medium text-stone-500`,children:[v(`space.copyName`),(0,E.jsx)(`input`,{autoFocus:!0,value:Ce,onChange:e=>we(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),Re())},className:`mt-1.5 w-full h-9 px-3 text-sm rounded-lg border border-stone-200 text-stone-800 outline-none focus:ring-2 focus:ring-[#4176e6]/30 focus:border-[#4176e6] transition-colors`})]}),(0,E.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,E.jsx)(`button`,{type:`button`,onClick:()=>W(null),className:`tw-confirm-cancel h-8 px-3 text-sm rounded-lg border border-stone-200 text-stone-600 hover:bg-stone-100 transition-colors`,children:v(`space.cancel`)}),(0,E.jsx)(`button`,{type:`button`,disabled:!Ce.trim()||$,onClick:()=>void Re(),className:`h-8 px-4 text-sm font-medium text-white bg-[#4176e6] rounded-lg hover:bg-[#3565c7] disabled:opacity-40 transition-colors`,children:g===`copy`?`…`:v(`space.copy`)})]})]})})]}),(0,E.jsx)(p,{open:V?.kind===`remove`,title:v(`space.confirmRemoveTitle`),message:V?.kind===`remove`?v(`space.confirmRemoveMsg`,{name:V.space.name,path:V.space.path}):``,confirmLabel:v(`space.removeList`),onClose:()=>H(null),onConfirm:()=>{V?.kind===`remove`&&ze(V.space,!1)}}),(0,E.jsx)(p,{open:V?.kind===`delete`,title:v(`space.confirmDeleteTitle`),message:V?.kind===`delete`?v(`space.confirmDeleteMsg`,{name:V.space.name,path:V.space.path}):``,confirmLabel:v(`space.deleteDisk`),danger:`solid`,onClose:()=>H(null),onConfirm:()=>{V?.kind===`delete`&&ze(V.space,!0)}})]})}var O=`tw.spaces.list.v1`;function k(){try{let e=sessionStorage.getItem(O);if(!e)return null;let t=JSON.parse(e);return t&&Array.isArray(t.spaces)?t:null}catch{return null}}function A(e){try{sessionStorage.setItem(O,JSON.stringify(e))}catch{}}function j(e){try{e?document.documentElement.dataset.spaceService=`none`:delete document.documentElement.dataset.spaceService}catch{}}function M(){let e=k(),[t,n]=(0,y.useState)(e!==null),[r,i]=(0,y.useState)(e!==null),[a,o]=(0,y.useState)(e),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(``);(0,y.useEffect)(()=>{let e=!0;return(async()=>{let t=await S();if(!e)return;if(i(!0),!t){n(!1),j(!0);return}j(!1),n(!0);let r=await ee();e&&r&&(o(r),A(r))})(),()=>{e=!1}},[]);async function p(e){if(e===a?.activeId)return;u(!0),f(``);let t=await te(e);t.ok?(a&&A({...a,activeId:e,spaces:a.spaces.map(t=>({...t,isActive:t.id===e}))}),window.location.reload()):(u(!1),f(t.error||`切换失败`))}if(!r)return null;if(!t)return(0,E.jsx)(`div`,{className:`tw-nav-space`,children:(0,E.jsxs)(`div`,{className:`tw-nav-space-btn tw-nav-space-btn--off`,children:[(0,E.jsx)(`span`,{className:`tw-nav-space-ico`,"aria-hidden":`true`,children:(0,E.jsx)(N,{})}),(0,E.jsxs)(`span`,{className:`tw-nav-space-text`,children:[(0,E.jsx)(`span`,{className:`tw-nav-space-cap`,children:v(`space.offlineCap`)}),(0,E.jsx)(`span`,{className:`tw-nav-space-name`,children:v(`space.offline`)})]})]})});let b=a?.spaces.find(e=>e.isActive),x=(a?.spaces??[]).filter(e=>!e.isActive);return(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`div`,{className:`tw-nav-space`,children:(0,E.jsxs)(g,{as:`div`,className:`tw-nav-space-menu`,children:[(0,E.jsxs)(_,{className:`tw-nav-space-btn`,"data-hint":v(`space.label`),children:[(0,E.jsx)(`span`,{className:`tw-nav-space-ico`,"aria-hidden":`true`,children:(0,E.jsx)(N,{})}),(0,E.jsxs)(`span`,{className:`tw-nav-space-text`,children:[(0,E.jsx)(`span`,{className:`tw-nav-space-cap`,children:v(`space.current`)}),(0,E.jsx)(`span`,{className:`tw-nav-space-name`,children:l?v(`space.switching`):b?w(b):`—`})]}),(0,E.jsx)(`svg`,{className:`tw-nav-space-caret`,viewBox:`0 0 24 24`,width:`13`,height:`13`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`m6 9 6 6 6-6`})})]}),(0,E.jsxs)(m,{transition:!0,anchor:{to:`bottom start`,gap:`0.375rem`},className:`tw-nav-space-pop tw-menu-anim`,children:[d?(0,E.jsx)(`div`,{className:`tw-nav-space-err`,role:`alert`,children:d}):null,(0,E.jsx)(`div`,{className:`tw-nav-space-group`,children:v(`space.others`)}),x.length===0?(0,E.jsx)(`p`,{className:`tw-nav-space-hint`,children:v(`space.othersEmpty`)}):x.map(e=>(0,E.jsx)(h,{children:(0,E.jsxs)(`button`,{type:`button`,className:`tw-nav-space-item`,disabled:l,onClick:()=>void p(e.id),children:[(0,E.jsx)(`span`,{className:`tw-nav-space-item-main`,children:(0,E.jsx)(`span`,{className:`tw-nav-space-item-name`,"data-hint":w(e),children:w(e)})}),(0,E.jsx)(`svg`,{className:`tw-nav-space-item-go`,viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`m9 6 6 6-6 6`})})]})},e.id)),(0,E.jsx)(`div`,{className:`tw-nav-space-sep`}),(0,E.jsx)(h,{children:(0,E.jsxs)(`button`,{type:`button`,className:`tw-nav-space-item tw-nav-space-item--manage`,onClick:()=>c(!0),children:[(0,E.jsx)(`span`,{className:`tw-nav-space-item-ico`,"aria-hidden":`true`,children:(0,E.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,children:[(0,E.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`}),(0,E.jsx)(`path`,{d:`M19.4 15a1.7 1.7 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.8-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-1-1.5 1.7 1.7 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.8 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.7 1.7 0 0 0 1.5-1 1.7 1.7 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.8.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.8V9c.2.6.7 1 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1z`})]})}),(0,E.jsx)(`span`,{className:`tw-nav-space-item-main`,children:(0,E.jsx)(`span`,{className:`tw-nav-space-item-name`,children:v(`space.manage`)})}),(0,E.jsx)(`svg`,{className:`tw-nav-space-item-go`,viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,E.jsx)(`path`,{d:`m9 6 6 6-6 6`})})]})})]})]})}),(0,E.jsx)(D,{open:s,onClose:()=>c(!1),onListChanged:e=>{o(e),A(e)}})]})}function N(){return(0,E.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`15`,height:`15`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,E.jsx)(`path`,{d:`M3 7.5 12 3l9 4.5-9 4.5-9-4.5Z`}),(0,E.jsx)(`path`,{d:`m3 12.5 9 4.5 9-4.5`}),(0,E.jsx)(`path`,{d:`m3 17 9 4.5 9-4.5`})]})}export{M as default};
@@ -0,0 +1 @@
1
+ import{c as e,n as t}from"./react-dom.CqAxpHMt.js";import{i as n}from"./app-config.vqDkEMS3.js";import{t as r}from"./jsx-runtime.BUXbF_vF.js";import{t as i}from"./ConfirmDialog.BYz4HREM.js";import{t as a}from"./SelectDropdown.D2i7-lQC.js";import{a as ee,o,r as s}from"./plugins.DSUPSizB.js";import{I as c,M as l,S as u,T as d,_ as f,a as p,c as m,f as h,g as te,h as g,i as _,k as v,l as y,m as ne,o as b,r as x,s as S,t as C,u as w,v as re}from"./DatePicker.BdwFRioL.js";import{t as T}from"./SlideOverDrawer.C7UVeCX1.js";import{n as ie,t as E}from"./ColumnResize.Bs6GL3DJ.js";var D=e(t(),1),O=r(),ae=8e3,k=[{key:`title`,min:200},{key:`status`,width:104,min:80},{key:`priority`,width:104,min:88},{key:`start`,width:108,min:88},{key:`due`,width:108,min:88},{key:`cycle`,width:76,min:60},{key:`todos`,width:84,min:68},{key:`progress`,width:132,min:104},{key:`note`,width:140,min:88},{key:`action`,width:56,min:52}],A={pool:`bg-stone-100 text-stone-600`,in_progress:`bg-[#e1eaff] text-[#1f4ec2]`,done:`bg-[#d9f5d2] text-[#1d7a12]`,closed:`bg-stone-100 text-stone-400`},j={urgent_important:`bg-[#f54a45] text-white`,important:`bg-[#ff8800] text-white`,urgent:`bg-[#f7ba1e] text-stone-800`,normal:`bg-stone-200 text-stone-600`,"":`bg-transparent text-stone-400`},M={pool:`bg-stone-400`,in_progress:`bg-[#3370ff]`,done:`bg-[#34c724]`,closed:`bg-stone-300`},N={urgent_important:`bg-[#f54a45]`,important:`bg-[#ff8800]`,urgent:`bg-[#f7ba1e]`,normal:`bg-stone-300`,"":`border border-stone-300 bg-transparent`},oe=p.map(e=>({value:e,label:b[e]})),se=[{value:``,label:`未设置`},...x.map(e=>({value:e,label:_[e]}))],ce=[{value:`all`,label:`全部优先级`},...x.map(e=>({value:e,label:_[e]}))],le=[{value:`all`,label:`全部`},{value:`pool`,label:`任务池`},{value:`in_progress`,label:`进行中`},{value:`done`,label:`已完成`},{value:`closed`,label:`已关闭`}],P=`h-8 w-full min-w-0 truncate rounded-md border border-transparent bg-transparent px-1.5 text-sm text-stone-800 outline-none transition-colors hover:border-stone-200 focus:border-[#3370ff] focus:bg-white placeholder:text-stone-300`;function F(e){return(0,O.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1 rounded-xl border px-4 py-3 ${e.tone===`urgent`?`border-red-100 bg-red-50/60`:`border-stone-200 bg-white`}`,children:[(0,O.jsx)(`span`,{className:`text-2xl font-semibold tabular-nums ${e.tone===`urgent`?`text-[#c02a26]`:`text-stone-900`}`,children:e.value}),(0,O.jsx)(`span`,{className:`truncate text-xs text-stone-500`,children:e.label})]})}function ue(e){let{open:t,task:n,todos:r,onClose:i,onSaved:ee}=e,[o,s]=(0,D.useState)({title:``}),[c,f]=(0,D.useState)(``),[p,m]=(0,D.useState)(!1);(0,D.useEffect)(()=>{t&&(f(``),m(!1),s(n?{title:n.title,status:n.status,priority:n.priority,startDate:n.startDate,dueDate:n.dueDate,note:n.note}:{title:``,status:`pool`,priority:``,startDate:l(),dueDate:l()}))},[t,n]);function h(e){s(t=>({...t,...e}))}let g=te({startDate:o.startDate??``,dueDate:o.dueDate??``}),v=n?r.filter(e=>e.taskId===n.id):[],y=v.filter(e=>e.status===`done`).length,ne=v.length?Math.round(y/v.length*100):0;async function x(){let e=(o.title??``).trim();if(!e)f(`请填写任务名称`);else if(o.startDate&&o.dueDate&&o.dueDate<o.startDate)f(`截止日期不能早于开始日期`);else{m(!0),f(``);try{n?await re(n.id,o):await S([{...o,title:e}],{mode:`manual`}),await ee(),i()}catch(e){f(e instanceof Error?e.message:String(e))}finally{m(!1)}}}let w=`w-[92px] shrink-0 pt-2 text-sm text-stone-500`;return(0,O.jsx)(T,{open:t,onClose:i,title:n?`任务详情`:`新建任务`,footer:(0,O.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-stone-100 px-4 py-3`,children:[(0,O.jsx)(`button`,{type:`button`,onClick:i,disabled:p,className:`h-8 rounded-lg border border-stone-200 px-4 text-sm text-stone-600 transition-colors hover:bg-stone-100 disabled:opacity-40`,children:`取消`}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>void x(),disabled:p,className:`h-8 rounded-lg bg-[#3370ff] px-4 text-sm font-medium text-white transition-colors hover:bg-[#2b5fd9] disabled:opacity-40`,children:p?`保存中…`:n?`保存`:`新建`})]}),children:(0,O.jsxs)(`div`,{className:`space-y-1`,children:[(0,O.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,O.jsx)(`span`,{className:w,children:`任务名称`}),(0,O.jsx)(`input`,{autoFocus:!0,value:o.title,onChange:e=>h({title:e.target.value}),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),x())},placeholder:`请输入内容`,className:`${P} h-9`})]}),(0,O.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,O.jsx)(`span`,{className:w,children:`任务状态`}),(0,O.jsx)(a,{unstyled:!0,hideChevron:!0,showCheck:!1,ariaLabel:`任务状态`,menuMinWidth:120,className:`w-fit`,options:oe,value:o.status??`pool`,onChange:e=>h({status:e}),triggerClassName:`h-8 rounded-md px-2.5 text-center text-sm font-medium focus:ring-2 focus:ring-[#3370ff]/30 ${A[o.status??`pool`]}`,renderTrigger:()=>(0,O.jsx)(`span`,{children:b[o.status??`pool`]}),renderOptionPrefix:e=>(0,O.jsx)(`span`,{className:`h-2 w-2 rounded-full ${M[e.value]}`})})]}),(0,O.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,O.jsx)(`span`,{className:w,children:`紧急程度`}),(0,O.jsx)(a,{unstyled:!0,hideChevron:!0,showCheck:!1,ariaLabel:`紧急程度`,menuMinWidth:128,className:`w-fit`,options:se,value:o.priority??``,onChange:e=>h({priority:e}),triggerClassName:`h-8 rounded-md px-2.5 text-center text-sm font-medium focus:ring-2 focus:ring-[#3370ff]/30 ${j[o.priority??``]}`,renderTrigger:()=>(0,O.jsx)(`span`,{children:o.priority?_[o.priority]:`未设置`}),renderOptionPrefix:e=>(0,O.jsx)(`span`,{className:`h-2 w-2 rounded-full ${N[e.value]}`})})]}),(0,O.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,O.jsx)(`span`,{className:w,children:`开始日期`}),(0,O.jsx)(C,{value:o.startDate??``,onChange:e=>h({startDate:e}),className:`h-9 rounded-md px-2 text-sm tabular-nums`})]}),(0,O.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,O.jsx)(`span`,{className:w,children:`截止日期`}),(0,O.jsx)(C,{value:o.dueDate??``,onChange:e=>h({dueDate:e}),className:`h-9 rounded-md px-2 text-sm tabular-nums`})]}),(0,O.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,O.jsx)(`span`,{className:w,children:`任务周期`}),(0,O.jsx)(`div`,{className:`px-2 pt-2 text-sm text-stone-500`,children:g===null?`—`:`${g} 天`})]}),(0,O.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,O.jsx)(`span`,{className:w,children:`待办进度`}),(0,O.jsx)(`div`,{className:`pt-2 text-sm text-stone-500`,children:v.length?`${y}/${v.length} · ${ne}%`:`还没有关联待办`})]}),(0,O.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,O.jsx)(`span`,{className:w,children:`备注`}),(0,O.jsx)(`textarea`,{value:o.note??``,onChange:e=>h({note:e.target.value}),rows:4,placeholder:`请输入内容`,className:`w-full resize-y rounded-md border border-transparent bg-transparent px-2 py-1.5 text-sm text-stone-800 outline-none transition-colors hover:border-stone-200 focus:border-[#3370ff] focus:bg-white placeholder:text-stone-400`})]}),n&&v.length?(0,O.jsxs)(`div`,{className:`!mt-4 rounded-lg border border-stone-100 bg-stone-50/60 px-3 py-2`,children:[(0,O.jsx)(`div`,{className:`mb-1.5 text-xs font-medium text-stone-500`,children:`关联待办`}),(0,O.jsx)(`ul`,{className:`space-y-1`,children:v.map(e=>{let t=d(e,l());return(0,O.jsxs)(`li`,{className:`flex items-center gap-2 text-sm text-stone-700`,children:[(0,O.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.title}),(0,O.jsx)(`span`,{className:`shrink-0 text-xs text-stone-400`,children:u[t]})]},e.id)})})]}):null,c?(0,O.jsx)(`div`,{className:`!mt-3 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700`,children:c}):null]})})}function I(){let[e,t]=(0,D.useState)(!1),[r,l]=(0,D.useState)(!0),[u,d]=(0,D.useState)(!0),[p,x]=(0,D.useState)(null),[S,T]=(0,D.useState)([]),[P,I]=(0,D.useState)([]),[L,R]=(0,D.useState)(null),[z,B]=(0,D.useState)(!1),[V,de]=(0,D.useState)(``),[H,fe]=(0,D.useState)(`all`),[U,pe]=(0,D.useState)(`all`),[W,G]=(0,D.useState)(null),[K,q]=(0,D.useState)(null),J=(0,D.useRef)(!0),Y=ie(`lh:tasks:cols:v1`,k);(0,D.useEffect)(()=>(J.current=!0,()=>{J.current=!1}),[]);let X=(0,D.useCallback)(async()=>{try{let[e,t]=await Promise.all([h(),u?v().catch(()=>[]):Promise.resolve([])]);if(!J.current)return;T(e),I(t),R(null)}catch(e){if(!J.current)return;R(e instanceof Error?e.message:String(e))}},[u]);(0,D.useEffect)(()=>{let e=ee(e=>{l(!!e.tasks),d(!!e.todos)});return n().then(()=>{l(s(`tasks`)),d(s(`todos`)),t(!0)}),e},[]),(0,D.useEffect)(()=>{e&&r&&(async()=>{let e=await y();J.current&&(e?(await X(),J.current&&x(!0)):x(!1))})()},[e,r,X]),(0,D.useEffect)(()=>{if(p!==!0)return;let e=window.setInterval(()=>void X(),ae),t=()=>void X();return window.addEventListener(`focus`,t),()=>{window.clearInterval(e),window.removeEventListener(`focus`,t)}},[p,X]);let me=(0,D.useMemo)(()=>f(P),[P]),Z=(0,D.useMemo)(()=>g(S),[S]),he=(0,D.useMemo)(()=>w(S,{status:H,priority:U,keyword:V}),[S,H,U,V]),Q=(0,D.useMemo)(()=>ne(he),[he]);async function $(e,t){T(n=>n.map(n=>n.id===e?{...n,...t}:n));try{let n=await re(e,t);if(!J.current)return;T(t=>t.map(t=>t.id===e?n:t)),R(null)}catch(e){R(e instanceof Error?e.message:String(e)),await X()}}async function ge(){let e=K;if(e){q(null),B(!0);try{await m([e.id]),await Promise.all(P.filter(t=>t.taskId===e.id).map(e=>c(e.id,{taskId:``,linkedTask:``}).catch(()=>null))),await X()}catch(e){R(e instanceof Error?e.message:String(e))}finally{J.current&&B(!1)}}}return e?r?p===null?(0,O.jsx)(`div`,{className:`flex min-h-0 flex-col overflow-hidden rounded-xl border border-stone-200 bg-white`,"aria-busy":`true`,"aria-label":`正在连接任务服务`,children:(0,O.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center`,children:(0,O.jsx)(`span`,{className:`tw-lib-spin`,"aria-hidden":`true`})})}):p?(0,O.jsxs)(`section`,{className:`flex min-h-0 flex-col gap-4`,children:[(0,O.jsxs)(`div`,{className:`grid shrink-0 grid-cols-2 gap-3 sm:grid-cols-3 xl:grid-cols-6`,children:[(0,O.jsx)(F,{label:`全部任务`,value:Z.total}),(0,O.jsx)(F,{label:`任务池`,value:Z.pool}),(0,O.jsx)(F,{label:`进行中`,value:Z.in_progress}),(0,O.jsx)(F,{label:`已完成`,value:Z.done}),(0,O.jsx)(F,{label:`已关闭`,value:Z.closed}),(0,O.jsx)(F,{label:`需要紧急`,value:Z.urgent,tone:`urgent`})]}),(0,O.jsxs)(`div`,{className:`flex min-h-0 flex-col overflow-hidden rounded-xl border border-stone-200 bg-white`,children:[(0,O.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2 border-b border-stone-100 px-4 py-3`,children:[(0,O.jsx)(`input`,{value:V,onChange:e=>de(e.target.value),placeholder:`搜索任务…`,className:`h-9 w-52 rounded-lg border border-stone-200 px-3 text-sm text-stone-800 outline-none focus:border-[#3370ff]`}),(0,O.jsx)(`div`,{className:`flex items-center gap-0.5 rounded-lg bg-stone-100/80 p-0.5`,children:le.map(e=>(0,O.jsx)(`button`,{type:`button`,onClick:()=>fe(e.value),className:`h-8 rounded-md px-3 text-sm transition-colors ${H===e.value?`bg-white font-medium text-stone-900 shadow-sm`:`text-stone-600 hover:text-stone-900`}`,children:e.label},e.value))}),(0,O.jsx)(a,{flat:!0,className:`w-[136px]`,ariaLabel:`优先级筛选`,options:ce,value:U,onChange:e=>pe(e)}),(0,O.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,O.jsx)(`button`,{type:`button`,onClick:()=>void X(),"aria-label":`刷新`,className:`flex h-9 w-9 items-center justify-center rounded-lg border border-stone-200 text-stone-500 transition-colors hover:bg-stone-50 hover:text-stone-800`,children:(0,O.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`16`,height:`16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,O.jsx)(`path`,{d:`M21 12a9 9 0 1 1-3-6.7`}),(0,O.jsx)(`path`,{d:`M21 4v5h-5`})]})}),(0,O.jsx)(`button`,{type:`button`,disabled:z,onClick:()=>G({task:null}),className:`h-9 shrink-0 rounded-lg bg-[#3370ff] px-3 text-sm font-medium whitespace-nowrap text-white transition-colors hover:bg-[#2b5fd9] disabled:opacity-40`,children:`+ 新建任务`})]})]}),L?(0,O.jsxs)(`div`,{className:`mx-4 mt-3 flex shrink-0 items-start gap-2 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700`,children:[(0,O.jsx)(`span`,{className:`min-w-0 flex-1`,children:L}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>R(null),"aria-label":`关闭`,className:`-mr-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded text-red-700/70 hover:bg-red-100 hover:text-red-900`,children:`✕`})]}):null,(0,O.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:(0,O.jsxs)(`table`,{className:`tw-task-table w-full table-fixed border-collapse text-sm`,style:Y.tableStyle,children:[(0,O.jsx)(`colgroup`,{children:k.map(e=>(0,O.jsx)(`col`,{style:Y.widthOf(e.key)?{width:Y.widthOf(e.key)}:void 0},e.key))}),(0,O.jsx)(`thead`,{className:`tw-table-head sticky top-0 z-10 text-xs text-stone-500`,children:(0,O.jsxs)(`tr`,{children:[(0,O.jsxs)(`th`,{className:`relative px-3 py-2 text-left font-medium whitespace-nowrap`,children:[`任务描述`,(0,O.jsx)(E,{...Y.resizeProps(0)})]}),(0,O.jsxs)(`th`,{className:`relative px-2 py-2 text-left font-medium whitespace-nowrap`,children:[`任务状态`,(0,O.jsx)(E,{...Y.resizeProps(1)})]}),(0,O.jsxs)(`th`,{className:`relative px-2 py-2 text-left font-medium whitespace-nowrap`,children:[`紧急程度`,(0,O.jsx)(E,{...Y.resizeProps(2)})]}),(0,O.jsxs)(`th`,{className:`relative px-2 py-2 text-left font-medium whitespace-nowrap`,children:[`开始日期`,(0,O.jsx)(E,{...Y.resizeProps(3)})]}),(0,O.jsxs)(`th`,{className:`relative px-2 py-2 text-left font-medium whitespace-nowrap`,children:[`截止日期`,(0,O.jsx)(E,{...Y.resizeProps(4)})]}),(0,O.jsxs)(`th`,{className:`relative px-2 py-2 text-left font-medium whitespace-nowrap`,children:[`任务周期`,(0,O.jsx)(E,{...Y.resizeProps(5)})]}),(0,O.jsxs)(`th`,{className:`relative px-2 py-2 text-left font-medium whitespace-nowrap`,children:[`待办数量`,(0,O.jsx)(E,{...Y.resizeProps(6)})]}),(0,O.jsxs)(`th`,{className:`relative px-2 py-2 text-left font-medium whitespace-nowrap`,children:[`完成进度`,(0,O.jsx)(E,{...Y.resizeProps(7)})]}),(0,O.jsxs)(`th`,{className:`relative px-2 py-2 text-left font-medium whitespace-nowrap`,children:[`备注`,(0,O.jsx)(E,{...Y.resizeProps(8)})]}),(0,O.jsx)(`th`,{className:`px-1 py-2 text-center font-medium whitespace-nowrap`,children:`操作`})]})}),(0,O.jsxs)(`tbody`,{children:[Q.map(e=>{let t=te(e),n=me[e.id]??{total:0,done:0,percent:0};return(0,O.jsxs)(`tr`,{className:`group/row border-t border-stone-100 hover:bg-[#f7f8fa]`,children:[(0,O.jsx)(`td`,{className:`px-3 py-1 align-middle`,children:(0,O.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[e.source===`ai`?(0,O.jsx)(`span`,{className:`shrink-0 rounded bg-[#e1eaff] px-1 py-px text-[10px] text-[#1f4ec2]`,children:`AI`}):null,(0,O.jsx)(`button`,{type:`button`,onClick:()=>G({task:e}),className:`min-w-0 truncate rounded-md px-1.5 py-1 text-left text-sm text-stone-800 hover:bg-stone-100`,children:e.title})]})}),(0,O.jsx)(`td`,{className:`px-1 py-1 align-middle`,children:(0,O.jsx)(a,{unstyled:!0,hideChevron:!0,showCheck:!1,centerContent:!0,ariaLabel:`任务状态`,menuMinWidth:120,options:oe,value:e.status,onChange:t=>void $(e.id,{status:t}),triggerClassName:`h-7 w-full rounded-md px-2 text-center text-xs font-medium focus:ring-2 focus:ring-[#3370ff]/30 ${A[e.status]}`,renderTrigger:()=>(0,O.jsx)(`span`,{className:`w-full truncate text-center`,children:b[e.status]}),renderOptionPrefix:e=>(0,O.jsx)(`span`,{className:`h-2 w-2 rounded-full ${M[e.value]}`})})}),(0,O.jsx)(`td`,{className:`px-1 py-1 align-middle`,children:(0,O.jsx)(a,{unstyled:!0,hideChevron:!0,showCheck:!1,centerContent:!0,ariaLabel:`紧急程度`,menuMinWidth:128,options:se,value:e.priority,onChange:t=>void $(e.id,{priority:t}),triggerClassName:`h-7 w-full rounded-md px-1.5 text-center text-xs font-medium focus:ring-2 focus:ring-[#3370ff]/30 ${j[e.priority]}`,renderTrigger:()=>(0,O.jsx)(`span`,{className:`w-full truncate text-center`,children:e.priority?_[e.priority]:`未设置`}),renderOptionPrefix:e=>(0,O.jsx)(`span`,{className:`h-2 w-2 rounded-full ${N[e.value]}`})})}),(0,O.jsx)(`td`,{className:`px-1 py-1 align-middle`,children:(0,O.jsx)(C,{value:e.startDate,onChange:t=>void $(e.id,{startDate:t}),placeholder:`选择日期`,className:`h-8 rounded-md px-1.5 text-sm tabular-nums`})}),(0,O.jsx)(`td`,{className:`px-1 py-1 align-middle`,children:(0,O.jsx)(C,{value:e.dueDate,onChange:t=>void $(e.id,{dueDate:t}),placeholder:`选择日期`,className:`h-8 rounded-md px-1.5 text-sm tabular-nums`})}),(0,O.jsx)(`td`,{className:`px-2 py-1 align-middle text-xs whitespace-nowrap text-stone-500 tabular-nums`,children:t===null?`—`:`${t} 天`}),(0,O.jsx)(`td`,{className:`px-2 py-1 align-middle text-xs text-stone-500 tabular-nums`,children:u?n.total?`${n.total} 条`:`0`:(0,O.jsx)(`span`,{className:`whitespace-nowrap text-stone-400`,children:`待办事项未启用`})}),(0,O.jsx)(`td`,{className:`px-2 py-1 align-middle`,children:u?(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(`span`,{className:`h-1.5 min-w-0 flex-1 overflow-hidden rounded-full bg-stone-100`,children:(0,O.jsx)(`span`,{className:`block h-full rounded-full bg-[#3370ff] transition-[width]`,style:{width:`${n.percent}%`}})}),(0,O.jsxs)(`span`,{className:`w-9 shrink-0 text-right text-xs text-stone-500 tabular-nums`,children:[n.percent,`%`]})]}):(0,O.jsx)(`span`,{className:`whitespace-nowrap text-xs text-stone-400`,children:`待办事项未启用`})}),(0,O.jsx)(`td`,{className:`truncate px-2 py-1 align-middle text-xs text-stone-500`,children:e.note||`—`}),(0,O.jsx)(`td`,{className:`px-1 py-1 text-right align-middle`,children:(0,O.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5`,children:[(0,O.jsx)(`button`,{type:`button`,onClick:()=>G({task:e}),"aria-label":`展开 ${e.title}`,className:`rounded p-1 text-stone-300 transition-colors hover:bg-stone-100 hover:text-stone-600 focus:text-stone-600`,children:(0,O.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,O.jsx)(`path`,{d:`M14 4h6v6`}),(0,O.jsx)(`path`,{d:`M20 4 13 11`}),(0,O.jsx)(`path`,{d:`M10 20H4v-6`}),(0,O.jsx)(`path`,{d:`M4 20l7-7`})]})}),(0,O.jsx)(`button`,{type:`button`,disabled:z,onClick:()=>q(e),"aria-label":`删除 ${e.title}`,className:`rounded p-1 text-stone-300 transition-colors hover:bg-red-50 hover:text-red-600 focus:text-red-600 disabled:opacity-40`,children:(0,O.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,O.jsx)(`path`,{d:`M3 6h18`}),(0,O.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,O.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`}),(0,O.jsx)(`path`,{d:`M10 11v6M14 11v6`})]})})]})})]},e.id)}),Q.length===0?(0,O.jsx)(`tr`,{children:(0,O.jsx)(`td`,{colSpan:10,className:`px-3 py-16 text-center text-sm text-stone-400`,children:S.length===0?`还没有任务`:`没有匹配的任务,试试调整搜索或筛选`})}):null]})]})}),(0,O.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-t border-stone-100 px-4 py-2.5 text-xs text-stone-500`,children:[(0,O.jsxs)(`span`,{children:[`共 `,Q.length,` 条`]}),(0,O.jsx)(`span`,{className:`ml-auto text-stone-400`,children:`任务下关联的待办可直接在「待办事项」里维护`})]})]}),(0,O.jsx)(ue,{open:W!==null,task:W?.task??null,todos:P,onClose:()=>G(null),onSaved:X}),(0,O.jsx)(i,{open:K!=null,title:`删除任务`,message:`删除「${K?.title??``}」?已关联的待办会保留,但不再挂在该任务下。`,confirmLabel:`删除`,cancelLabel:`取消`,danger:!0,onClose:()=>q(null),onConfirm:()=>void ge()})]}):(0,O.jsx)(`div`,{className:`tw-lib-notice rounded-xl border border-amber-200 bg-amber-50 px-5 py-8 text-sm text-amber-900`,children:`任务管理需要本地服务,当前未就绪(仅 npm run dev / 本地一体服务可用)。`}):(0,O.jsx)(`div`,{className:`tw-lib-notice rounded-xl border border-amber-200 bg-amber-50 px-5 py-8 text-sm text-amber-900`,children:o(`tasks`)}):(0,O.jsx)(`div`,{className:`flex min-h-0 flex-col overflow-hidden rounded-xl border border-stone-200 bg-white`,"aria-busy":`true`,"aria-label":`正在读取插件开关`,children:(0,O.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center`,children:(0,O.jsx)(`span`,{className:`tw-lib-spin`,"aria-hidden":`true`})})})}export{I as default};
@@ -0,0 +1 @@
1
+ import{c as e,n as t}from"./react-dom.CqAxpHMt.js";import{i as n}from"./app-config.vqDkEMS3.js";import{a as r,i,r as a,t as o}from"./ExcelFieldTags.B_XMwNNx.js";import{a as s,c,d as l,f as u,h as ee,i as te,l as d,m as ne,n as re,o as ie,p as ae,r as f,s as p,t as oe,u as se}from"./project-docs.Cd2gKPKh.js";import{n as ce}from"./doc-roots.DAJP9Svr.js";import{t as m}from"./jsx-runtime.BUXbF_vF.js";import{t as le}from"./ConfirmDialog.BYz4HREM.js";import{a as ue,o as de,r as h}from"./plugins.DSUPSizB.js";import{n as fe,r as pe,t as me}from"./useListAnim.Y3N2budK.js";import{t as g}from"./NamePromptDialog.DGBlDH_k.js";var _=e(t(),1),v=m(),he=5;async function ge(e){let t=e.name.toLowerCase();try{if(t.endsWith(`.xlsx`)||t.endsWith(`.xls`)){let t=await l(`templates`,e.path);if(t.encoding===`base64`&&t.contentBase64)return r(t.contentBase64).headers}else if(t.endsWith(`.csv`)){let t=await u(`templates`,e.path);return a(t.content).headers}else if(t.endsWith(`.md`)||t.endsWith(`.txt`)){let t=await u(`templates`,e.path);return i(t.content).headers}}catch{}return[]}function y({className:e=`w-4 h-4`,open:t=!1}){return(0,v.jsx)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,children:t?(0,v.jsx)(`path`,{d:`M6 14l1.45-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.55 6a2 2 0 0 1-1.94 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2`}):(0,v.jsx)(`path`,{d:`M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7z`})})}function b({className:e=`w-3 h-3`}){return(0,v.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,v.jsx)(`path`,{d:`M21.17 6.81a1 1 0 0 0-3.99-3.99L3.84 16.17a2 2 0 0 0-.5.83l-1.32 4.35a.5.5 0 0 0 .62.62l4.35-1.32a2 2 0 0 0 .83-.5z`}),(0,v.jsx)(`path`,{d:`m15 5 4 4`})]})}function x({className:e=`w-3 h-3`}){return(0,v.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,v.jsx)(`path`,{d:`M3 6h18`}),(0,v.jsx)(`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`}),(0,v.jsx)(`path`,{d:`M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`}),(0,v.jsx)(`path`,{d:`M10 11v6`}),(0,v.jsx)(`path`,{d:`M14 11v6`})]})}function S({node:e,depth:t,activePath:n,expanded:r,globalOpen:i,onToggle:a,onSelect:o}){let s=r[e.path]??i,c=n===e.path;return(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`div`,{className:`group flex items-center rounded-md ${c?`bg-[#e8f0fe]`:`hover:bg-stone-100`}`,style:{paddingLeft:8+t*12},children:(0,v.jsxs)(`button`,{type:`button`,onClick:()=>{o(e.path),e.children.length&&a(e.path)},"aria-expanded":e.children.length?s:void 0,className:`flex-1 min-w-0 flex items-center gap-1.5 py-1.5 pr-1 text-sm text-left ${c?`text-[#4176e6]`:`text-stone-600`}`,children:[(0,v.jsx)(`span`,{className:`w-3.5 shrink-0`,"aria-hidden":`true`}),(0,v.jsx)(y,{open:!!(e.children.length&&s),className:`w-3.5 h-3.5 shrink-0 text-[#4176e6]`}),(0,v.jsx)(`span`,{className:`flex-1 min-w-0 truncate`,children:e.name}),(0,v.jsxs)(`span`,{className:`shrink-0 tabular-nums text-[11px] text-stone-400`,children:[`(`,e.fileCount??0,`)`]})]})}),(0,v.jsx)(`div`,{className:`tw-collapse ${s?`is-open`:``}`,children:(0,v.jsx)(`div`,{className:`tw-collapse-inner`,children:e.children.map(e=>(0,v.jsx)(S,{node:e,depth:t+1,activePath:n,expanded:r,globalOpen:i,onToggle:a,onSelect:o},e.path))})})]})}function C(e){return e==null?`—`:e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function w(){let[e,t]=(0,_.useState)(()=>h(`templates`)),[r,i]=(0,_.useState)(!1),[a,l]=(0,_.useState)(null),[u,m]=(0,_.useState)([]),[w,_e]=(0,_.useState)(0),[T,E]=(0,_.useState)(`.`),[D,O]=(0,_.useState)([]),[ve,ye]=(0,_.useState)({}),[be,k]=(0,_.useState)({}),[A,xe]=(0,_.useState)(!0),[j,M]=(0,_.useState)(null),[N,P]=(0,_.useState)(!1),[Se,F]=(0,_.useState)(!1),[I,L]=(0,_.useState)(null),[R,z]=(0,_.useState)(null),[Ce,B]=(0,_.useState)(1),[V,we]=pe(he),[Te,H]=(0,_.useState)(null),U=(0,_.useRef)(null),{cls:Ee,play:W}=me(),G=(0,_.useCallback)(async e=>{let t={};await Promise.all(e.map(async e=>{let n=await ge(e);n.length&&(t[e.path]=n)})),ye(t)},[]),K=(0,_.useCallback)(async()=>{let e=await te(`templates`);m(e.tree),_e(e.totalFiles)},[]),q=(0,_.useCallback)(async(e=T)=>{M(null);try{let[t]=await Promise.all([p(`templates`,e),K()]);O(t.entries),E(t.path);let n=t.entries.filter(e=>e.type===`file`);await G(n)}catch(e){M(e instanceof Error?e.message:String(e))}},[T,G,K]);(0,_.useEffect)(()=>{let e=ue(e=>t(!!e.templates));return n().then(()=>{t(h(`templates`)),i(!0)}),e},[]),(0,_.useEffect)(()=>{r&&e&&(async()=>{let e=await f(`templates`);if(l(e),e)try{let[e]=await Promise.all([p(`templates`,`.`),K()]);O(e.entries),E(e.path),await G(e.entries.filter(e=>e.type===`file`))}catch(e){M(e instanceof Error?e.message:String(e))}})()},[r,e,G,K]);function De(){xe(e=>!e),k({})}async function J(e){W(),E(e),B(1),H(null),M(null);try{let t=await p(`templates`,e);O(t.entries),await G(t.entries.filter(e=>e.type===`file`))}catch(e){M(e instanceof Error?e.message:String(e))}}async function Oe(e){F(!1),P(!0),M(null);try{await c(`templates`,T,e),await q(T)}catch(e){M(e instanceof Error?e.message:String(e))}finally{P(!1)}}async function ke(e){if(e?.length){P(!0),M(null);try{for(let t of Array.from(e))await ee(`templates`,T,t);await q(T)}catch(e){M(e instanceof Error?e.message:String(e))}finally{P(!1),U.current&&(U.current.value=``)}}}async function Ae(e){if(e.type===`file`){P(!0),M(null);try{await d(`templates`,e.path)}catch(e){M(e instanceof Error?e.message:String(e))}finally{P(!1)}}}function je(e){let t=s(u,e.path),n=t?.fileCount??0,r=t?oe(t):0;L({...e,isDir:!0,blocked:n>0||r>0,files:n,dirs:r})}function Me(e){L({name:e.name,path:e.path,isDir:!1})}function Y(e,t){z({...e,isDir:t})}async function Ne(){let e=I;if(e&&(L(null),!e.blocked)){P(!0),M(null);try{await re(`templates`,e.path);let t=ie(T,e.path)?se(e.path):T;await q(t)}catch(e){M(e instanceof Error?e.message:String(e))}finally{P(!1)}}}async function Pe(e){let t=R;if(t&&(z(null),e!==t.name)){P(!0),M(null);try{let n=await ne(`templates`,t.path,e);await q(ae(T,t.path,n))}catch(e){M(e instanceof Error?e.message:String(e))}finally{P(!1)}}}let Fe=(()=>{if(!I)return``;if(!I.isDir)return`删除文件「${I.name}」?将移入系统废纸篓,可随时找回。`;if(I.blocked){let e=[];return I.files&&e.push(`${I.files} 个文件`),I.dirs&&e.push(`${I.dirs} 个子文件夹`),`文件夹「${I.name}」中还有 ${e.join(`、`)},请先清空内部内容后再删除。`}return`删除文件夹「${I.name}」?将移入系统废纸篓。`})();if(!r)return(0,v.jsx)(`div`,{className:`tw-lib-probing`,"aria-busy":`true`,"aria-label":`正在读取插件开关`,children:(0,v.jsx)(`span`,{className:`tw-lib-spin`,"aria-hidden":`true`})});if(!e)return(0,v.jsx)(`div`,{className:`tw-lib-notice rounded-xl border border-amber-200 bg-amber-50 px-5 py-8 text-sm text-amber-900`,children:de(`templates`)});if(a===null)return(0,v.jsx)(`div`,{className:`tw-lib-probing`,"aria-busy":`true`,"aria-label":`正在连接本地文档服务`,children:(0,v.jsx)(`span`,{className:`tw-lib-spin`,"aria-hidden":`true`})});if(!a)return(0,v.jsx)(`div`,{className:`tw-lib-notice rounded-xl border border-amber-200 bg-amber-50 px-5 py-8 text-sm text-amber-900`,children:`模板库需要本地文档服务,当前未就绪。`});let X=D.filter(e=>e.type===`file`),Z=D.filter(e=>e.type===`dir`),Q=Math.max(1,Math.ceil(X.length/V)),$=Math.min(Ce,Q),Ie=X.slice(($-1)*V,$*V);function Le(e){W(),we(e),B(1)}return(0,v.jsxs)(`div`,{className:`flex gap-4 min-h-0`,children:[(0,v.jsxs)(`aside`,{className:`w-56 shrink-0 rounded-xl border border-stone-200 bg-white flex flex-col overflow-hidden`,children:[(0,v.jsxs)(`div`,{className:`px-3 py-2.5 border-b border-stone-100 flex items-center justify-between`,children:[(0,v.jsx)(`span`,{className:`text-xs font-semibold text-stone-500`,children:`文件夹`}),(0,v.jsx)(`button`,{type:`button`,disabled:N,onClick:()=>F(!0),className:`tw-mkdir-btn disabled:opacity-40`,children:`+ 新建`})]}),(0,v.jsxs)(`div`,{className:`flex-1 overflow-y-auto py-2 px-1`,children:[(0,v.jsx)(`div`,{className:`group flex items-center rounded-md ${T===`.`?`bg-[#e8f0fe]`:`hover:bg-stone-100`}`,style:{paddingLeft:8},children:(0,v.jsxs)(`button`,{type:`button`,onClick:()=>{J(`.`),De()},"aria-expanded":A,className:`flex-1 min-w-0 flex items-center gap-1.5 py-1.5 pr-1 text-sm text-left ${T===`.`?`text-[#4176e6]`:`text-stone-600`}`,children:[(0,v.jsx)(y,{open:A,className:`w-3.5 h-3.5 shrink-0 text-[#4176e6]`}),(0,v.jsx)(`span`,{className:`flex-1 min-w-0 truncate`,children:`全部模板`}),(0,v.jsxs)(`span`,{className:`shrink-0 tabular-nums text-[11px] text-stone-400`,children:[`(`,w,`)`]})]})}),(0,v.jsx)(`div`,{className:`tw-collapse ${A?`is-open`:``}`,children:(0,v.jsx)(`div`,{className:`tw-collapse-inner`,children:u.map(e=>(0,v.jsx)(S,{node:e,depth:0,activePath:T,expanded:be,globalOpen:A,onToggle:e=>k(t=>({...t,[e]:!(t[e]??A)})),onSelect:e=>void J(e)},e.path))})})]})]}),(0,v.jsxs)(`section`,{className:`flex-1 min-w-0 rounded-xl border border-stone-200 bg-white flex flex-col overflow-hidden`,children:[(0,v.jsxs)(`div`,{className:`px-4 py-3 border-b border-stone-100 flex items-center gap-2 flex-wrap`,children:[(0,v.jsxs)(`div`,{className:`text-sm text-stone-600 flex-1 min-w-0 truncate`,children:[(0,v.jsx)(`span`,{className:`text-stone-400`,children:ce(`templates`)}),T===`.`?``:T]}),(0,v.jsx)(`input`,{ref:U,type:`file`,multiple:!0,accept:`.md,.txt,.docx,.xlsx,.xls,.csv,text/plain,text/markdown,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,className:`hidden`,onChange:e=>void ke(e.target.files)}),(0,v.jsx)(`button`,{type:`button`,disabled:N,onClick:()=>U.current?.click(),className:`h-8 px-3 shrink-0 whitespace-nowrap text-sm font-medium text-white bg-[#4176e6] rounded-lg hover:bg-[#3565c7] disabled:opacity-40`,children:`上传文件`})]}),j?(0,v.jsx)(`div`,{className:`mx-4 mt-3 px-3 py-2 text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg`,children:j}):null,(0,v.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[Z.length>0&&(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`div`,{className:`text-xs font-medium text-stone-400 mb-2`,children:`子文件夹`}),(0,v.jsx)(`ul`,{className:`space-y-1`,children:Z.map(e=>(0,v.jsxs)(`li`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg border border-stone-100 hover:bg-stone-50`,children:[(0,v.jsxs)(`button`,{type:`button`,className:`flex-1 min-w-0 flex items-center gap-2 text-left text-sm text-stone-700`,onClick:()=>void J(e.path),children:[(0,v.jsx)(y,{className:`w-4 h-4 text-[#4176e6] shrink-0`}),(0,v.jsx)(`span`,{className:`flex-1 min-w-0 truncate`,children:e.name})]}),(0,v.jsx)(`button`,{type:`button`,disabled:N,"aria-label":`重命名 ${e.name}`,onClick:()=>Y({name:e.name,path:e.path},!0),className:`p-1.5 rounded text-stone-400 hover:text-[#4176e6] hover:bg-[#e8f0fe] disabled:opacity-40`,children:(0,v.jsx)(b,{className:`w-3.5 h-3.5`})}),(0,v.jsx)(`button`,{type:`button`,disabled:N,"aria-label":`删除 ${e.name}`,onClick:()=>je({name:e.name,path:e.path}),className:`p-1.5 rounded text-red-600 hover:bg-red-50 disabled:opacity-40`,children:(0,v.jsx)(x,{className:`w-3.5 h-3.5`})})]},e.path))})]}),(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`div`,{className:`text-xs font-medium text-stone-400 mb-2`,children:`文件`}),X.length===0?(0,v.jsx)(`p`,{className:`text-sm text-stone-400 py-6 text-center border border-dashed border-stone-200 rounded-lg`,children:`当前文件夹为空,点击「上传文件」添加模板(.md / .xlsx / .docx 等)`}):(0,v.jsx)(`ul`,{className:`${Ee}space-y-1`,children:Ie.map(e=>{let t=ve[e.path]??[],n=Te===e.path;return(0,v.jsxs)(`li`,{className:`flex items-start gap-2 px-3 py-2 rounded-lg border transition-colors ${n?`border-[#c7dcff] bg-[#e8f0fe]`:`border-stone-100 hover:bg-stone-50`}`,children:[(0,v.jsxs)(`button`,{type:`button`,className:`flex-1 min-w-0 text-left`,disabled:N,onClick:()=>H(e.path),onDoubleClick:()=>void Ae(e),children:[(0,v.jsx)(`div`,{className:`text-sm text-stone-800 truncate`,"data-hint":e.name,children:e.name}),(0,v.jsx)(`div`,{className:`text-[11px] text-stone-400`,children:C(e.size)}),t.length>0?(0,v.jsx)(o,{fields:t}):null]}),(0,v.jsx)(`button`,{type:`button`,disabled:N,"aria-label":`重命名 ${e.name}`,onClick:()=>Y({name:e.name,path:e.path},!1),className:`p-1.5 rounded text-stone-400 hover:text-[#4176e6] hover:bg-[#e8f0fe] disabled:opacity-40 shrink-0 mt-0.5`,children:(0,v.jsx)(b,{className:`w-3.5 h-3.5`})}),(0,v.jsx)(`button`,{type:`button`,disabled:N,"aria-label":`删除 ${e.name}`,onClick:()=>Me(e),className:`p-1.5 rounded text-red-600 hover:bg-red-50 disabled:opacity-40 shrink-0 mt-0.5`,children:(0,v.jsx)(x,{className:`w-3.5 h-3.5`})})]},e.path)})})]})]}),X.length>0?(0,v.jsx)(fe,{page:$,totalPages:Q,pageSize:V,busy:N,onPage:e=>{W(),B(e)},onPageSize:Le}):null]}),(0,v.jsx)(g,{open:Se,title:`新建文件夹`,onClose:()=>F(!1),onConfirm:e=>void Oe(e)}),(0,v.jsx)(g,{open:R!=null,title:R?.isDir?`重命名文件夹`:`重命名文件`,label:R?.isDir?`文件夹名称`:`文件名称`,initialValue:R?.name??``,lockExtension:R!=null&&!R.isDir,confirmLabel:`保存`,onClose:()=>z(null),onConfirm:e=>void Pe(e)}),(0,v.jsx)(le,{open:I!=null,title:I?.blocked?`无法删除文件夹`:I?.isDir?`删除文件夹`:`删除模板`,message:Fe,confirmLabel:I?.blocked?`知道了`:`删除`,cancelLabel:`取消`,danger:!I?.blocked,hideCancel:!!I?.blocked,onClose:()=>L(null),onConfirm:()=>void Ne()})]})}export{w as default};