@neuralis/brain-core 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -3
- package/app/filesystem/api/README.md +1 -1
- package/app/filesystem/api/index.ts +24 -24
- package/app/filesystem/store/README.md +1 -1
- package/app/filesystem/store/filesystemStore.ts +11 -3
- package/app/filesystem/store/listSlice.ts +1 -0
- package/app/filesystem/ui/FileEditor.tsx +42 -4
- package/app/filesystem/ui/GitControlPanel.tsx +0 -1
- package/app/filesystem/ui/GitDiffView.tsx +12 -5
- package/app/filesystem/ui/GitFileDiff.tsx +15 -9
- package/app/filesystem/ui/PendingChangesPanel.tsx +95 -34
- package/app/filesystem/ui/README.md +9 -9
- package/app/filesystem/ui/SourcesPanel.tsx +1 -3
- package/app/filesystem/ui/Toolbar.tsx +5 -4
- package/app/filesystem/ui/VectorHealthPanel.tsx +43 -14
- package/dist/app/host.js +40 -40
- package/dist/src/config/env.d.ts +4 -0
- package/dist/src/config/env.d.ts.map +1 -1
- package/dist/src/config/env.js +13 -0
- package/dist/src/config/env.js.map +1 -1
- package/dist/src/connectors/LocalDiskConnector.d.ts +9 -1
- package/dist/src/connectors/LocalDiskConnector.d.ts.map +1 -1
- package/dist/src/connectors/LocalDiskConnector.js +51 -2
- package/dist/src/connectors/LocalDiskConnector.js.map +1 -1
- package/dist/src/domain/healthTypes.d.ts +1 -7
- package/dist/src/domain/healthTypes.d.ts.map +1 -1
- package/dist/src/domain/pendingChange.d.ts +31 -0
- package/dist/src/domain/pendingChange.d.ts.map +1 -1
- package/dist/src/domain/pendingChange.js.map +1 -1
- package/dist/src/routes/health.js +2 -3
- package/dist/src/routes/health.js.map +1 -1
- package/dist/src/routes/pending.d.ts +7 -7
- package/dist/src/routes/pending.d.ts.map +1 -1
- package/dist/src/routes/pending.js +21 -21
- package/dist/src/routes/pending.js.map +1 -1
- package/dist/src/services/FilesystemService.d.ts +13 -61
- package/dist/src/services/FilesystemService.d.ts.map +1 -1
- package/dist/src/services/FilesystemService.js +47 -189
- package/dist/src/services/FilesystemService.js.map +1 -1
- package/dist/src/services/FilesystemUiService.d.ts +33 -1
- package/dist/src/services/FilesystemUiService.d.ts.map +1 -1
- package/dist/src/services/FilesystemUiService.js +50 -1
- package/dist/src/services/FilesystemUiService.js.map +1 -1
- package/dist/src/store/PendingChangeStore.d.ts +3 -0
- package/dist/src/store/PendingChangeStore.d.ts.map +1 -1
- package/dist/src/store/PendingChangeStore.js +84 -25
- package/dist/src/store/PendingChangeStore.js.map +1 -1
- package/dist/src/usecases/orphanedPending.d.ts +2 -2
- package/dist/src/usecases/orphanedPending.d.ts.map +1 -1
- package/dist/src/usecases/orphanedPending.js +5 -3
- package/dist/src/usecases/orphanedPending.js.map +1 -1
- package/dist/src/usecases/pendingListing.d.ts +34 -0
- package/dist/src/usecases/pendingListing.d.ts.map +1 -0
- package/dist/src/usecases/pendingListing.js +244 -0
- package/dist/src/usecases/pendingListing.js.map +1 -0
- package/dist/src/usecases/vectorMaintenance.d.ts +6 -9
- package/dist/src/usecases/vectorMaintenance.d.ts.map +1 -1
- package/dist/src/usecases/vectorMaintenance.js +4 -13
- package/dist/src/usecases/vectorMaintenance.js.map +1 -1
- package/dist/src/vector/InMemoryVectorIndex.d.ts.map +1 -1
- package/dist/src/vector/InMemoryVectorIndex.js +30 -9
- package/dist/src/vector/InMemoryVectorIndex.js.map +1 -1
- package/package.json +26 -4
- package/rules/brain-rules.md +1 -1
- package/skills/create-package/SKILL.md +3 -3
- package/skills/create-package/references/config-and-credentials.md +1 -1
- package/skills/create-package/references/runtime-and-build.md +1 -1
- package/skills/create-package/references/skills-and-context.md +25 -12
- package/skills/create-package/references/test-and-ship.md +9 -16
- package/skills/create-package/scripts/verify-loaded.sh +18 -27
- package/skills/git/SKILL.md +27 -29
- package/skills/manage-files/SKILL.md +37 -32
- package/skills/manage-files/scripts/upload.sh +7 -9
- package/skills/manage-files/scripts/write.sh +2 -6
- package/skills/manage-sources/SKILL.md +93 -95
- package/skills/manage-sources/scripts/reembed.sh +2 -6
- package/skills/manage-uri-policy/SKILL.md +30 -58
- package/skills/git/scripts/git.sh +0 -48
- package/skills/manage-files/scripts/approve.sh +0 -9
- package/skills/manage-files/scripts/list.sh +0 -9
- package/skills/manage-files/scripts/pending.sh +0 -23
- package/skills/manage-files/scripts/raw.sh +0 -11
- package/skills/manage-files/scripts/read.sh +0 -9
- package/skills/manage-files/scripts/search.sh +0 -15
- package/skills/manage-sources/scripts/browse.sh +0 -12
- package/skills/manage-sources/scripts/cancel.sh +0 -14
- package/skills/manage-sources/scripts/create.sh +0 -13
- package/skills/manage-sources/scripts/delete.sh +0 -17
- package/skills/manage-sources/scripts/discoverable.sh +0 -6
- package/skills/manage-sources/scripts/get.sh +0 -7
- package/skills/manage-sources/scripts/kind-schema.sh +0 -7
- package/skills/manage-sources/scripts/kinds.sh +0 -6
- package/skills/manage-sources/scripts/list.sh +0 -6
- package/skills/manage-sources/scripts/purge-index.sh +0 -18
- package/skills/manage-sources/scripts/reindex.sh +0 -13
- package/skills/manage-sources/scripts/reset.sh +0 -11
- package/skills/manage-sources/scripts/set-enabled.sh +0 -17
- package/skills/manage-sources/scripts/sync-status.sh +0 -14
- package/skills/manage-sources/scripts/sync.sh +0 -13
- package/skills/manage-sources/scripts/update.sh +0 -18
- package/skills/manage-uri-policy/scripts/manifests.sh +0 -20
- package/skills/manage-uri-policy/scripts/set-uri.sh +0 -66
- package/skills/manage-uri-policy/scripts/show-uri.sh +0 -23
package/dist/app/host.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import{a as Vi,c as j}from"./chunks/chunk-DCANE7XH.js";var $e=Vi((FO,y0)=>{var qf=globalThis.__neuralis_shared_modules__,x0=qf&&Object.prototype.hasOwnProperty.call(qf,"react")?qf.react:void 0;if(x0===void 0)throw new Error("[neuralis-ui] shared module react is not provided by the host");y0.exports=x0});var Wn=Vi((EO,w0)=>{var $f=globalThis.__neuralis_shared_modules__,b0=$f&&Object.prototype.hasOwnProperty.call($f,"@neuralis/package-system/client")?$f["@neuralis/package-system/client"]:void 0;if(b0===void 0)throw new Error("[neuralis-ui] shared module @neuralis/package-system/client is not provided by the host");w0.exports=b0});var Zr=Vi((OO,k0)=>{var Kf=globalThis.__neuralis_shared_modules__,v0=Kf&&Object.prototype.hasOwnProperty.call(Kf,"@neuralis/agent-core/app/chat")?Kf["@neuralis/agent-core/app/chat"]:void 0;if(v0===void 0)throw new Error("[neuralis-ui] shared module @neuralis/agent-core/app/chat is not provided by the host");k0.exports=v0});var ie=Vi((qU,Tb)=>{var fh=globalThis.__neuralis_shared_modules__,Mb=fh&&Object.prototype.hasOwnProperty.call(fh,"react/jsx-runtime")?fh["react/jsx-runtime"]:void 0;if(Mb===void 0)throw new Error("[neuralis-ui] shared module react/jsx-runtime is not provided by the host");Tb.exports=Mb});var Za=Vi((a8,Ob)=>{var mh=globalThis.__neuralis_shared_modules__,Eb=mh&&Object.prototype.hasOwnProperty.call(mh,"react-dom")?mh["react-dom"]:void 0;if(Eb===void 0)throw new Error("[neuralis-ui] shared module react-dom is not provided by the host");Ob.exports=Eb});var r2=Vi((w9,n2)=>{var o0=globalThis.__neuralis_shared_modules__,t2=o0&&Object.prototype.hasOwnProperty.call(o0,"@neuralis/agent-core/app/chat/store")?o0["@neuralis/agent-core/app/chat/store"]:void 0;if(t2===void 0)throw new Error("[neuralis-ui] shared module @neuralis/agent-core/app/chat/store is not provided by the host");n2.exports=t2});var ol=j($e(),1),Gf=j(Wn(),1),b2=j(Zr(),1);var Rn=j($e(),1);var ya=j($e(),1);var S0=t=>{let e,n=new Set,r=(u,c)=>{let d=typeof u=="function"?u(e):u;if(!Object.is(d,e)){let f=e;e=c??(typeof d!="object"||d===null)?d:Object.assign({},e,d),n.forEach(h=>h(e,f))}},a=()=>e,o={setState:r,getState:a,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u))},l=e=t(r,a,o);return o},Xf=(t=>t?S0(t):S0);var ul=j($e(),1);var B2=t=>t;function C0(t,e=B2){let n=ul.default.useSyncExternalStore(t.subscribe,ul.default.useCallback(()=>e(t.getState()),[t,e]),ul.default.useCallback(()=>e(t.getInitialState()),[t,e]));return ul.default.useDebugValue(n),n}function Jf(t,e){let n;try{n=t()}catch{return}return{getItem:a=>{var s;let i=l=>l===null?null:JSON.parse(l,e?.reviver),o=(s=n.getItem(a))!=null?s:null;return o instanceof Promise?o.then(i):i(o)},setItem:(a,s)=>n.setItem(a,JSON.stringify(s,e?.replacer)),removeItem:a=>n.removeItem(a)}}var Yf=t=>e=>{try{let n=t(e);return n instanceof Promise?n:{then(r){return Yf(r)(n)},catch(r){return this}}}catch(n){return{then(r){return this},catch(r){return Yf(r)(n)}}}},_2=(t,e)=>(n,r,a)=>{let s={storage:Jf(()=>window.localStorage),partialize:m=>m,version:0,merge:(m,x)=>({...x,...m}),...e},i=!1,o=0,l=new Set,u=new Set,c=s.storage;if(!c)return t((...m)=>{console.warn(`[zustand persist middleware] Unable to update item '${s.name}', the given storage is currently unavailable.`),n(...m)},r,a);let d=()=>{let m=s.partialize({...r()});return c.setItem(s.name,{state:m,version:s.version})},f=a.setState;a.setState=(m,x)=>(f(m,x),d());let h=t((...m)=>(n(...m),d()),r,a);a.getInitialState=()=>h;let p,g=()=>{var m,x;if(!c)return;let y=++o;i=!1,l.forEach(C=>{var L;return C((L=r())!=null?L:h)});let b=((x=s.onRehydrateStorage)==null?void 0:x.call(s,(m=r())!=null?m:h))||void 0;return Yf(c.getItem.bind(c))(s.name).then(C=>{if(C)if(typeof C.version=="number"&&C.version!==s.version){if(s.migrate){let L=s.migrate(C.state,C.version);return L instanceof Promise?L.then(P=>[!0,P]):[!0,L]}console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return[!1,C.state];return[!1,void 0]}).then(C=>{var L;if(y!==o)return;let[P,w]=C;if(p=s.merge(w,(L=r())!=null?L:h),n(p,!0),P)return d()}).then(()=>{y===o&&(b?.(r(),void 0),p=r(),i=!0,u.forEach(C=>C(p)))}).catch(C=>{y===o&&b?.(void 0,C)})};return a.persist={setOptions:m=>{s={...s,...m},m.storage&&(c=m.storage)},clearStorage:()=>{++o,c?.removeItem(s.name)},getOptions:()=>s,rehydrate:()=>g(),hasHydrated:()=>i,onHydrate:m=>(l.add(m),()=>{l.delete(m)}),onFinishHydration:m=>(u.add(m),()=>{u.delete(m)})},s.skipHydration||g(),p||h},I0=_2;var Sx=j(Wn(),1);var L0=j(Wn(),1);async function qi(t,e,n,r){let a={agentId:t};return e&&(a.projectId=e),n?.uri&&(a.uri=n.uri),typeof n?.recursive=="boolean"&&(a.recursive=n.recursive),n?.include&&(a.include=n.include),typeof n?.summary_chars=="number"&&(a.summary_chars=n.summary_chars),typeof n?.include_metadata=="boolean"&&(a.include_metadata=n.include_metadata),typeof n?.only_indexed=="boolean"&&(a.only_indexed=n.only_indexed),typeof n?.sources_only=="boolean"&&(a.sources_only=n.sources_only),typeof n?.include_counts=="boolean"&&(a.include_counts=n.include_counts),typeof n?.limit=="number"&&(a.limit=n.limit),r.post("list",a)}async function A0(t,e,n,r){return(await qi(t,e,{uri:`${n}://`,recursive:!1,include:"folders",include_counts:!0,limit:1},r)).sources?.[0]??null}async function $i(t,e){return(e??await(0,L0.tryGetPackageApiImperativeAsync)("brain-core")).post("read",t)}async function P0(t,e){let n={agentId:t.agentId};return t.projectId&&(n.projectId=t.projectId),t.scope&&(n.scope=t.scope),t.observed&&(n.observed="1"),e.get("sources",n)}async function Zf(t,e){return e.patch("sources",{agentId:t.agentId,...t.projectId?{projectId:t.projectId}:{},...t.config})}async function N0(t,e){return e.post("sources/sync",t)}async function R0(t,e){let n={agentId:t.agentId};return t.projectId&&(n.projectId=t.projectId),t.source&&(n.source=t.source),e.get("sources/sync-status",n)}async function M0(t,e){return e.post("sources/enabled",{agentId:t.agentId,...t.projectId?{projectId:t.projectId}:{},source:t.source,enabled:t.enabled})}async function ic(t,e){let n=new URLSearchParams;return n.set("agentId",t.agentId),t.projectId&&n.set("projectId",t.projectId),e.get("sources/discoverable",Object.fromEntries(n))}function ps(t){return t?{repo:t}:{}}function xr(t){return t?{repo:t}:{}}async function Ki(t,e){let n={agentId:t.agentId,source:t.source};return t.projectId&&(n.projectId=t.projectId),e.get("git/repos",n)}async function oc(t,e){let n={agentId:t.agentId,source:t.source,...ps(t.repo)};return t.projectId&&(n.projectId=t.projectId),e.get("git/status",n)}async function T0(t,e){let n={agentId:t.agentId,source:t.source,...ps(t.repo)};return t.projectId&&(n.projectId=t.projectId),e.get("git/branch",n)}async function lc(t,e){let n={agentId:t.agentId,source:t.source,...ps(t.repo),path:t.path};return typeof t.commit=="string"&&(n.commit=t.commit),typeof t.base=="string"&&(n.base=t.base),typeof t.head=="string"&&(n.head=t.head),typeof t.staged=="boolean"&&(n.staged=t.staged?"1":"0"),t.projectId&&(n.projectId=t.projectId),e.get("git/diff",n)}async function uc(t,e){let n={agentId:t.agentId,source:t.source,...ps(t.repo)};return t.projectId&&(n.projectId=t.projectId),typeof t.maxCount=="number"&&(n.maxCount=String(t.maxCount)),typeof t.skip=="number"&&(n.skip=String(t.skip)),t.ref&&(n.ref=t.ref),e.get("git/log",n)}async function D0(t,e){let n={agentId:t.agentId,source:t.source,...ps(t.repo)};return t.projectId&&(n.projectId=t.projectId),typeof t.maxCount=="number"&&(n.maxCount=String(t.maxCount)),typeof t.skip=="number"&&(n.skip=String(t.skip)),t.ref&&(n.ref=t.ref),e.get("git/log-stats",n)}async function cc(t,e){let n={agentId:t.agentId,source:t.source,...ps(t.repo),sha:t.sha};return t.projectId&&(n.projectId=t.projectId),e.get("git/commit",n)}async function cl(t,e){let n={agentId:t.agentId,source:t.source,...ps(t.repo)};return t.projectId&&(n.projectId=t.projectId),e.get("git/outgoing",n)}async function F0(t,e){let n={agentId:t.agentId,source:t.source,...ps(t.repo),path:t.path,rev:t.rev};return t.projectId&&(n.projectId=t.projectId),e.get("git/show",n)}async function E0(t,e){return e.post("git/stage",{source:t.source,...xr(t.repo),paths:t.paths,...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function O0(t,e){return e.post("git/unstage",{source:t.source,...xr(t.repo),paths:t.paths,...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function B0(t,e){return e.post("git/stage",{source:t.source,...xr(t.repo),hunk:t.hunk,...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function _0(t,e){return e.post("git/unstage",{source:t.source,...xr(t.repo),hunk:t.hunk,...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function H0(t,e){return e.post("git/discard",{source:t.source,...xr(t.repo),paths:t.paths,...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function U0(t,e){return e.post("git/commit",{source:t.source,...xr(t.repo),message:t.message,...t.amend?{amend:!0}:{},...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function G0(t,e){return e.post("git/branch",{source:t.source,...xr(t.repo),action:"create",name:t.name,...t.startPoint?{startPoint:t.startPoint}:{},...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function W0(t,e){return e.post("git/branch",{source:t.source,...xr(t.repo),action:"delete",name:t.name,...t.force?{force:!0}:{},...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function z0(t,e){return e.post("git/restore",{source:t.source,...xr(t.repo),rescue:t.rescue,...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function Qf(t,e){return e.post("git/checkout",{source:t.source,...xr(t.repo),ref:t.ref,...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function j0(t,e){return e.post("git/fetch",{source:t.source,...xr(t.repo),...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function V0(t,e){return e.post("git/pull",{source:t.source,...xr(t.repo),...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function q0(t,e){return e.post("git/push",{source:t.source,...xr(t.repo),...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function $0(t,e){return e.post("search",t)}async function dc(t,e){let n=new FormData;return n.append("agentId",t.agentId),t.projectId&&n.append("projectId",t.projectId),n.append("file",t.file),t.uri&&n.append("uri",t.uri),t.tags?.length&&n.append("tags",t.tags.join(",")),e.upload("upload",n)}async function yr(t,e){return e.post("write",t)}function ga(t,e){return t?.code==="destination_exists"?"Something is already there \u2014 nothing was overwritten. Pick another name.":t?.message||t?.error||e}async function fc(t,e){return e.post("approve",t)}async function Xi(t,e){return(await e.post("pending",{...t,action:"preview"})).preview}async function K0(t,e){let n=await e.post("pending",t);return{ok:n?.ok!==!1,changes:Array.isArray(n?.changes)?n.changes:[],orphanIds:Array.isArray(n?.orphanIds)?n.orphanIds:[]}}async function X0(t,e){let n={agentId:t.agentId,count_only:"1"};t.projectId&&(n.projectId=t.projectId);let r=await e.get("pending",n);return typeof r?.count=="number"?r.count:0}async function Y0(t,e){return e.post("pending",{...t,action:"revert"})}async function J0(t,e){return e.post("pending",{...t,action:"discard"})}async function Z0(t,e){return e.post("pending",{...t,action:"dismiss"})}async function Q0(t,e){let n=await e.post("pending",{...t,action:"discard-orphans"});return{ok:n?.ok!==!1,discarded:typeof n?.discarded=="number"?n.discarded:0}}function ex(t,e,n){let r=new URLSearchParams({agentId:t,uri:e});return n&&r.set("projectId",n),`/api/packages/brain-core/raw?${r.toString()}`}async function tx(t,e){return e.post("health",t)}async function nx(t,e){return e.post("health/scan",t)}async function rx(t,e){return e.post("health/gc",t)}async function ax(t,e){return e.post("sources",t)}async function sx(t,e){let n=new URLSearchParams({agentId:t.agentId});return t.projectId&&n.set("projectId",t.projectId),t.purgeVectors&&n.set("purge","1"),e.del(`sources/${encodeURIComponent(t.source)}?${n.toString()}`)}async function ix(t,e){return e.post("sources/reset",t)}async function ox(t,e){return e.post("sources/reindex",t)}async function lx(t,e){return e.post("sources/purge",t)}function Zs(t){return typeof t=="number"&&Number.isFinite(t)?t:null}function H2(t){let e=t&&typeof t=="object"?t:null,n=e?.estimate&&typeof e.estimate=="object"?e.estimate:null,r=Zs(n?.points),a=Zs(n?.tokens);if(!e||!n||r===null||a===null)return null;let s=Zs(n.relStdErr),i=Zs(n.usd);return{documents:Zs(e.documents),truncated:e.truncated===!0,points:r,tokens:a,tokensMargin:s!==null?Math.round(a*s):null,usd:i,usdMargin:s!==null&&i!==null?i*s:null,durationSeconds:Zs(n.seconds)}}var ux=t=>t==="pending"?{embeddingOnly:!0}:{force:!0};async function cx(t,e,n){return H2(await n.post("sources/reindex",{...t,...ux(e),estimate:!0}))}async function hc(t,e,n){let r=await n.post("sources/reindex",{...t,...ux(e)}),a=r?.job&&typeof r.job=="object"?r.job:null;return{documents:Zs(r?.documents),truncated:r?.truncated===!0,job:a}}async function dx(t,e){return e.post("sources/cancel",t)}async function fx(t,e){let n={agentId:t.agentId};return t.projectId&&(n.projectId=t.projectId),e.get("sources/health",n)}async function eh(t,e){let n={path:t.path,agentId:t.agentId};return t.projectId&&(n.projectId=t.projectId),e.get("sources/browse",n)}async function hx(t){return t.get("sources/kinds",{})}function qe(t){let e=t.indexOf("://");return e>0?t.slice(0,e):"brain"}function sr(t){let e=t.indexOf("://");return e>0?t.slice(0,e+3):`${t}://`}function et(t){let e=t.indexOf("://");if(e<1)return t;let n=t.slice(0,e+3),r=t.lastIndexOf("/");return r<=e+2?n:t.slice(0,r)}function xa(t){let e=t.indexOf("://");if(e<1)return[];let r=`${t.slice(0,e)}://`,a=t.slice(e+3);if(!a)return[];let s=a.split("/").filter(Boolean);if(s.length===0)return[];let i=[r],o=r;for(let l=0;l<s.length-1;l++)o=o.endsWith("/")?`${o}${s[l]}`:`${o}/${s[l]}`,i.push(o);return i}function gt(t){let e=t.indexOf("://"),n=e>=0?t.slice(e+3):t,r=n.lastIndexOf("/");return r>=0?n.slice(r+1):n}var px=t=>t;function Va(t){return t.uri}function U2(t,e,n){for(let r of e){if(t[r]?.type==="folder")continue;let a=r.endsWith("://")?r.slice(0,r.indexOf("://")):r.split("/").pop()||"",s=et(r),i=t[r];t[r]={...i||{},storeKey:r,name:a,uri:r,type:"folder",parentUri:s===r?void 0:s,lastUpdated:n}}}function Qs(t,e,n){U2(t,xa(e),n)}function dl(t){if(typeof t=="string")return t;if(Array.isArray(t)){let e=t.map(n=>{if(n){if(typeof n=="string")return n;if(typeof n=="object"){let r=typeof n.text=="string"?n.text:void 0,a=typeof n.content=="string"?n.content:void 0;return r??a}}}).filter(n=>!!(n&&n.trim()));if(e.length>0)return e.join(`
|
|
2
|
-
`)}if(t&&typeof t=="object"){let e=t;if(typeof e.text=="string")return e.text;if(typeof e.content=="string")return e.content;if(Array.isArray(e.content)){let n=dl(e.content);if(n)return n}try{return JSON.stringify(t,null,2)}catch{return}}}function Yi(t){return Array.isArray(t?.files)?t.files:Array.isArray(t?.widget?.files)?t.widget.files:Array.isArray(t?.state?.files)?t.state.files:Array.isArray(t?.data?.files)?t.data.files:[]}function Ji(t){return dl(t?.text)??dl(t?.content)??dl(t?.file_content)??dl(t?.fileContent)??""}function pc(t){if(!t||typeof t!="object")return;let e=t;if(e.content!=null)return{content:typeof e.content=="string"?e.content:JSON.stringify(e.content,null,2),updatedAt:typeof e.updatedAt=="string"?e.updatedAt:"",...typeof e.uri=="string"?{uri:e.uri}:{},...typeof e.status=="string"?{status:e.status}:{},...typeof e.sourceVersion=="string"?{sourceVersion:e.sourceVersion}:{},...e.metadata&&typeof e.metadata=="object"?{metadata:e.metadata}:{}}}function mc(t,e){return typeof t.fileErrorByPath[e]=="string"||typeof t.fileBaseContentByPath[e]=="string"}function ei(t,e,n){return`${t??""}::${e??""}::${n}`}var th={glob:"",category:"",status:"",tags:"",createdAfter:"",createdBefore:"",scopeToFolder:!1},mx={searchQuery:"",searchMode:"keyword",searchFilters:th,searchResults:[],searchLoading:!1,searchError:void 0,searchEffect:{}};function nh(t,e,n){let r=typeof t=="string"&&t.includes("://")?t:null;if(n&&r)return r.startsWith("brain://")?null:r;let a=r?sr(r):null;return a&&!a.startsWith("brain://")?a:(e??[]).find(i=>i.source_kind!=="brain"&&typeof i.uri_root=="string")?.uri_root??null}function gx(t,e){let n=0;return{setSearchQuery:r=>t(()=>({searchQuery:r})),setSearchMode:r=>t(()=>({searchMode:r})),setSearchFilters:r=>t(a=>({searchFilters:{...a.searchFilters,...r}})),clearSearch:()=>t(()=>({searchQuery:"",searchFilters:th,searchResults:[],searchLoading:!1,searchError:void 0,searchEffect:{}})),async runSearch({agentId:r,projectId:a}){let{searchQuery:s,searchMode:i,searchFilters:o,activeFolderPath:l,sources:u}=e(),c=(s??"").trim(),d=o??th,f=d.glob.trim(),h=i==="keyword"?c.length>=2||f.length>=2:c.length>=2;if(!r||!h){t(()=>({searchResults:[],searchLoading:!1,searchError:void 0,searchEffect:{}}));return}let p=typeof l=="string"&&l.includes("://")?l:void 0,g=i==="grep"?nh(l,u,d.scopeToFolder):d.scopeToFolder?p:void 0;if(i==="grep"&&!g){t(()=>({searchResults:[],searchLoading:!1,searchError:"Grep needs a non-brain folder scope \u2014 select a folder in a disk-backed source.",searchEffect:{}}));return}let m=d.tags.split(",").map(y=>y.trim()).filter(y=>y.length>0),x=++n;t(()=>({searchLoading:!0,searchError:void 0}));try{let y=await $0({agentId:r,...a?{projectId:a}:{},search_mode:i==="keyword"?"filter":i,...c?{query:c}:{},...g?{folder_uri:g}:{},...f?{glob:f}:{},...i!=="grep"&&d.category.trim()?{category:d.category.trim()}:{},...i!=="grep"&&d.status.trim()?{status:d.status.trim()}:{},...i!=="grep"&&m.length>0?{tags:m}:{},...i!=="grep"&&d.createdAfter.trim()?{created_after:d.createdAfter.trim()}:{},...i!=="grep"&&d.createdBefore.trim()?{created_before:d.createdBefore.trim()}:{},limit:i==="semantic"?30:50},e().client);if(x!==n)return;let b=y.results||[],C=b.find(P=>typeof P.error=="string"&&P.error.length>0),L=b.filter(P=>typeof P.uri=="string"&&P.uri.includes("://")&&!P.error).map(P=>({id:P.id||`fs:${P.uri}:${P.chunk_start??""}`,uri:P.uri,filename:P.filename||String(P.uri).split("/").pop(),content_preview:P.content_preview,snippet:P.snippet,chunk_start:P.chunk_start,chunk_end:P.chunk_end,match_type:P.match_type,score:P.score,...typeof P.embedding_status=="string"?{embedding_status:P.embedding_status}:{}}));t(()=>({searchResults:L,searchLoading:!1,searchError:C?String(C.error):void 0,searchEffect:{...y.requested_mode?{requestedMode:y.requested_mode}:{},...y.effective_mode?{effectiveMode:y.effective_mode}:{},...y.embedding_degraded?{embeddingDegraded:y.embedding_degraded}:{},...y.warning?{warning:y.warning}:{}}}))}catch(y){if(x!==n)return;t(()=>({searchResults:[],searchLoading:!1,searchError:y instanceof Error?y.message:"Search failed",searchEffect:{}}))}}}}function Zi(){return{files:{},folderBadges:{},fileContentByPath:{},fileBaseContentByPath:{},fileErrorByPath:{},filePrevByPath:{},openFiles:[],activeFile:null,tabMeta:{},pendingReviewPaths:new Set,pendingCount:0,expandedFolders:new Set,sidebarView:"tree",activeWorkspaceTab:"file",workspacePanels:{upload:!1,sources:!1,packages:!1,pending:!1},pendingSourceSuggestion:null,vectorHealthOpen:!1,searchQuery:"",searchResults:[],searchLoading:!1,searchError:void 0,searchEffect:{},gitStatus:null,gitTotals:null,gitOutgoingStat:null,gitBranches:[],gitLoading:!1,gitError:void 0,gitDiffTarget:null,gitCommitTarget:null,sources:[],sourcesLoading:!0,activeSource:null,activeRepoRel:"",loadedFolders:{},hydrationState:{},dirtySources:{},sourceChangeRevision:{},organizeError:null,pendingPanelFilter:{},activeFolderPath:"brain://docs",snapshotError:void 0}}var G2=200;function gc(t,e=G2){let n=[...t],r=[],a=!0;for(;n.length>e&&a;){a=!1;for(let s=0;s<n.length&&n.length>e;){let i=n[s],o=`${i}/`;if(i.endsWith("://")||n.some(l=>l.startsWith(o))){s+=1;continue}n.splice(s,1),r.push(i),a=!0}}return{kept:n,evicted:r}}var W2=Object.keys(Zi());function z2(t){let e={};for(let n of W2)e[n]=t[n];return e}function xc(t){let e=t.expandedFolders;return{openFiles:Array.isArray(t.openFiles)?t.openFiles:[],activeFile:typeof t.activeFile=="string"?t.activeFile:null,tabMeta:t.tabMeta??{},expandedFolders:e instanceof Set?gc(Array.from(e)).kept:[],sidebarView:t.sidebarView??"tree",activeWorkspaceTab:t.activeWorkspaceTab??"file",workspacePanels:t.workspacePanels??{upload:!1,sources:!1,packages:!1,pending:!1},activeFolderPath:t.activeFolderPath??"brain://docs"}}function xx(t){let e=Zi();return t?{...e,openFiles:Array.isArray(t.openFiles)?t.openFiles:[],activeFile:typeof t.activeFile=="string"?t.activeFile:null,tabMeta:t.tabMeta??{},expandedFolders:new Set(Array.isArray(t.expandedFolders)?gc(t.expandedFolders).kept:[]),sidebarView:t.sidebarView??e.sidebarView,activeWorkspaceTab:t.activeWorkspaceTab??e.activeWorkspaceTab,workspacePanels:t.workspacePanels??e.workspacePanels,activeFolderPath:t.activeFolderPath??e.activeFolderPath}:e}function yx(t,e){let n=new Map;return{async loadList({agentId:r,projectId:a,userId:s,withCounts:i}){if(!r)return;let o=`${r}:${a||""}:${i?"c":""}`,l=n.get(o);if(l){await l;return}let u="brain://",c=e(),d=s===void 0?c.activeUserId:s,f=c.activeUserId!==null&&c.activeUserId!==d,h=c.activeAgentId!==r||c.activeProjectId!==a||f,p;if(h?(e().fenceInFlightWriters(),t(m=>{let x={...m.contextStateByKey};m.activeAgentId&&(x[ei(m.activeUserId,m.activeProjectId,m.activeAgentId)]=z2(m));let y=ei(d,a,r);return p=x[y],delete x[y],{activeUserId:d,activeAgentId:r,activeProjectId:a,...Zi(),...p??{},contextStateByKey:x}})):t(()=>({activeUserId:d,activeAgentId:r,activeProjectId:a,sourcesLoading:!0})),p){let m=p.loadedFolders??{},x=new Set;for(let[y,b]of Object.entries(m)){if(!b)continue;let C=qe(y);C&&x.add(C)}for(let y of x)e().reconcileSourceFolders({agentId:r,projectId:a,source:y})}e().rehydrateActiveTab();let g=(async()=>{let m;try{m=await qi(r,a??void 0,{sources_only:!0,recursive:!1,...i?{include_counts:!0}:{}},e().client)}catch{t(()=>({snapshotError:"Filesystem service unavailable",sourcesLoading:!1}));return}let x=Array.isArray(m.folders)?m.folders:[],y=Array.isArray(m.files)?m.files:[],b=Array.isArray(m.sources)?m.sources:[];t(C=>{let L=C.activeAgentId===r&&C.activeProjectId===a,P=L?{...C.files}:{},w=Date.now();P[u]||(P[u]={storeKey:u,name:"brain",uri:u,type:"folder",lastUpdated:w,presence:"brain"});for(let M of x){let R=typeof M=="string"?M:typeof M?.uri=="string"?M.uri:"";if(!R)continue;let U=typeof M?.name=="string"?M.name:R.split("/").pop()||"folder",v=M?.presence??(qe(R)==="brain"?"brain":"stale_indexed");Qs(P,`${R}/placeholder`,w),P[R]={storeKey:R,name:U,uri:R,type:"folder",parentUri:R.endsWith("://")?void 0:et(R),lastUpdated:w,presence:v,git:typeof M.git=="string"?String(M.git):void 0}}for(let M of y){let R=typeof M?.uri=="string"?String(M.uri):"";if(!R)continue;let U=typeof M?.id=="string"?String(M.id):void 0,v=typeof M.status=="string"?String(M.status):void 0,T=Array.isArray(M.tags)&&M.tags.length>0?M.tags:void 0,V=typeof M.category=="string"?String(M.category):void 0,Y=M.version&&typeof M.version=="object"?M.version:void 0,N=typeof M.agent_id=="string"?String(M.agent_id):void 0,A=typeof M.project_id=="string"?String(M.project_id):void 0,B=M?.presence??(qe(R)==="brain"?"brain":"stale_indexed"),K=typeof M.git=="string"?String(M.git):void 0;Qs(P,R,w),P[R]={storeKey:R,id:U,name:String(M.filename||M.name||gt(R)),uri:R,os_uri:typeof M.os_uri=="string"?String(M.os_uri):void 0,type:"file",status:v,parentUri:et(R),lastUpdated:w,category:V,tags:T,metadata:M.metadata&&typeof M.metadata=="object"?M.metadata:void 0,createdAt:typeof M.createdAt=="string"?String(M.createdAt):void 0,updatedAt:typeof M.updatedAt=="string"?String(M.updatedAt):void 0,version:Y,sourceAgentId:N,sourceProjectId:A,presence:B,git:K};let te=et(R),ne=P[te];ne&&ne.type==="folder"&&(P[te]={...ne,sourceAgentId:N??ne.sourceAgentId,sourceProjectId:A??ne.sourceProjectId,lastUpdated:w})}let k=L?{...C.loadedFolders||{}}:{},_=L?{...C.hydrationState||{}}:{};for(let M of b)!k[M.uri_root]&&!_[M.uri_root]&&(_[M.uri_root]="idle");return{files:P,sources:b,sourcesLoading:!1,snapshotError:void 0,loadedFolders:k,hydrationState:_}})})();n.set(o,g);try{await g}finally{n.delete(o)}},async refresh({agentId:r,projectId:a,withCounts:s}){await e().loadList({agentId:r,projectId:a,withCounts:s})}}}var wx={gitStatus:null,gitTotals:null,gitOutgoingStat:null,gitBranches:[],gitLoading:!1,gitError:void 0,gitViewMode:"list",gitDiffTarget:null,gitCommitTarget:null,gitLogNonce:0};function rh(t,e){let n=t??(typeof e=="string"?e:"");return n?n.includes("://")?qe(n):n:""}function bx(t,e){return typeof t=="string"?t:typeof e=="string"?e:""}function vx(t,e){let n=0,r=0;return{setGitViewMode:a=>t(()=>({gitViewMode:a})),setGitDiffTarget:a=>t(()=>({gitDiffTarget:a})),setGitCommitTarget:a=>t(s=>({gitCommitTarget:a,...a===null&&s.activeWorkspaceTab==="git-commit"?{activeWorkspaceTab:"file"}:{}})),notifyGitLogChanged:a=>{if(!a)return;let s=rh(void 0,e().activeSource);a===s&&t(i=>({gitLogNonce:(typeof i.gitLogNonce=="number"?i.gitLogNonce:0)+1}))},clearGit:()=>t(a=>({gitStatus:null,gitBranches:[],gitLoading:!1,gitError:void 0,gitDiffTarget:null,gitCommitTarget:null,...a.activeWorkspaceTab==="git-commit"?{activeWorkspaceTab:"file"}:{}})),setGitOutgoingStat(a){t(()=>({gitOutgoingStat:a}))},async loadGitStatus({agentId:a,projectId:s,source:i,repo:o}){let l=rh(i,e().activeSource),u=bx(o,e().activeRepoRel);if(!a||!l){t(()=>({gitStatus:null,gitTotals:null,gitLoading:!1,gitError:void 0}));return}let c=++n;t(()=>({gitLoading:!0,gitError:void 0}));try{let d=await oc({agentId:a,...s?{projectId:s}:{},source:l,...u?{repo:u}:{}},e().client);if(c!==n)return;t(()=>({gitStatus:d?.status??null,gitTotals:d?.totals??null,gitLoading:!1,gitError:void 0}))}catch(d){if(c!==n)return;t(()=>({gitStatus:null,gitTotals:null,gitLoading:!1,gitError:d instanceof Error?d.message:"Git status failed"}))}},async loadGitBranches({agentId:a,projectId:s,source:i,repo:o}){let l=rh(i,e().activeSource),u=bx(o,e().activeRepoRel);if(!a||!l){t(()=>({gitBranches:[]}));return}let c=++r;try{let d=await T0({agentId:a,...s?{projectId:s}:{},source:l,...u?{repo:u}:{}},e().client);if(c!==r)return;t(()=>({gitBranches:Array.isArray(d?.branches)?d.branches:[]}))}catch(d){if(c!==r)return;t(()=>({gitBranches:[],gitError:d instanceof Error?d.message:"Git branches failed"}))}}}}var ah=5e4,j2=3;function V2(){return{resetEpoch:0,pendingCountSeq:0,rehydrateInFlight:new Set,liveFolderLoadInFlight:new Map,reconcileJobs:new Map,folderGeneration:new Map}}function oh(t,e){let n=(t.folderGeneration.get(e)??0)+1;return t.folderGeneration.set(e,n),n}function Cx(t,e,n){return t.folderGeneration.get(e)===n}function sh(t){return{storeKey:t,uri:t,name:gt(t),type:"file",parentUri:et(t)}}function kx(t,e,n){let r=et(e);if(r===e||n.parentUri===r)return n;let a={...n,parentUri:r};return t[e]=a,a}function Ix(t,e,n,r){let a=r?.issuedAt??n,s=r?.pending;for(let i of e.folders||[]){let o=typeof i=="string"?i:typeof i?.uri=="string"?i.uri:"";if(!o)continue;let l=typeof i?.name=="string"?i.name:o.split("/").pop()||"folder",u=i?.presence??"unindexed",c=typeof i?.git=="string"?String(i.git):void 0,d=typeof i?.status=="string"?i.status:void 0,f=t[o];if(!f){t[o]={storeKey:o,name:l,uri:o,type:"folder",parentUri:o.endsWith("://")?void 0:et(o),lastUpdated:n,presence:u,git:c,status:d};continue}f=kx(t,o,f),!((f.lastUpdated??0)>=a)&&(f.git!==c||f.presence!==u||f.name!==l||f.status!==d)&&(t[o]={...f,name:l,presence:u,git:c,status:d})}for(let i of e.files||[]){let o=typeof i?.uri=="string"?String(i.uri):"";if(!o)continue;Qs(t,o,n);let l=typeof i.git=="string"?String(i.git):void 0,u=typeof i.status=="string"?i.status:void 0,c=i.presence??"unindexed",d=typeof i.os_uri=="string"?i.os_uri:void 0,f=t[o];if(!f){t[o]={storeKey:o,name:gt(o),uri:o,type:"file",id:typeof i.id=="string"?i.id:void 0,os_uri:d,status:u,parentUri:et(o),lastUpdated:n,category:typeof i.category=="string"?i.category:void 0,presence:c,pinned:i.pinned===!0,git:l},s&&u==="pending_review"&&s.add.add(o);continue}if(f=kx(t,o,f),(f.lastUpdated??0)>=a)continue;let h={...f,name:gt(o)||f.name,presence:c,status:u,os_uri:d,git:l};typeof i.id=="string"&&(h.id=i.id),"category"in i&&(h.category=typeof i.category=="string"?i.category:void 0),"version"in i&&(h.version=i.version),"pinned"in i&&(h.pinned=i.pinned===!0),t[o]=h,s&&f.status!==u&&(u==="pending_review"?s.add.add(o):f.status==="pending_review"&&s.remove.add(o))}}function lh(t,e,n){if(n.add.size===0&&n.remove.size===0)return t;let r=new Set(e);for(let a of n.add)r.add(a);for(let a of n.remove)r.delete(a);return t.pendingReviewPaths=r,t}var q2=4;function $2(t,e){if(t.endsWith("://"))return!0;if(!e.has(t))return!1;for(let n of xa(t))if(!n.endsWith("://")&&!e.has(n))return!1;return!0}function Lx(t,e){return e.some(n=>t===n||t.startsWith(n.endsWith("://")?n:`${n}/`))}function Ax(t,e){let n=t;for(let[r,a]of Object.entries(t))a!==!0||!Lx(r,e)||(n===t&&(n={...t}),n[r]=!1);return n}function yc(t,e){let n=new Set(e),r=Array.from(t.expandedFolders).filter(l=>!n.has(l));r.push(...n);let{kept:a,evicted:s}=gc(r);if(s.length===0)return{expandedFolders:new Set(a)};let i=t.loadedFolders||{},o=Ax(i,s);return o===i?{expandedFolders:new Set(a)}:{expandedFolders:new Set(a),loadedFolders:o}}async function K2(t,e,n){if(t.length===0)return[];let r=Math.max(1,Math.min(e,t.length)),a=new Array(t.length),s=0;return await Promise.all(Array.from({length:r},async()=>{for(;;){let i=s++;if(i>=t.length)return;a[i]=await n(t[i])}})),a}async function X2(t,e){let{agentId:n,projectId:r,source:a,extraTargets:s,wide:i}=e,o=t.fences.resetEpoch,l=t.get(),u=l.loadedFolders||{},c=new Set;if(i)for(let p of Object.keys(u))qe(p)===a&&$2(p,l.expandedFolders)&&c.add(p);for(let p of s)qe(p)===a&&u[p]!==void 0&&c.add(p);let d=p=>{let g=p.indexOf("://"),m=(g>=0?p.slice(g+3):p).replace(/\/+$/,"");return m?m.split("/").length:0},f=Array.from(c).sort((p,g)=>d(g)-d(p));if(f.length===0)return;let h=await K2(f,q2,async p=>{let g=oh(t.fences,p),m=Date.now();try{let x=await qi(n,r??void 0,{uri:p,recursive:!1},t.client);return Cx(t.fences,p,g)?{folderKey:p,res:x,issuedAt:m,ok:!0}:{folderKey:p,res:null,issuedAt:m,ok:!1}}catch{return{folderKey:p,res:null,issuedAt:m,ok:!1}}});t.set(p=>{if(o!==t.fences.resetEpoch)return p;let g={...p.files},m=Date.now(),x={add:new Set,remove:new Set},y=[],b=!1,C=!1;for(let M of h){if(!M.ok||!M.res){C=!0;continue}Ix(g,M.res,m,{issuedAt:M.issuedAt,pending:x}),M.res.truncated?C=!0:b=!0}let L=C===!!p.dirtySources[a]?p.dirtySources:(()=>{let M={...p.dirtySources};return C?M[a]=!0:delete M[a],M})(),P=p.loadedFolders;for(let M of h)!M.ok||!M.res||P?.[M.folderKey]!==!1||(P===p.loadedFolders&&(P={...P}),P[M.folderKey]=!0);if(!b)return lh({files:uh(g,p.expandedFolders,p.openFiles),dirtySources:L,loadedFolders:P},p.pendingReviewPaths,x);let w=new Map;for(let M of Object.keys(g)){let R=g[M]?.parentUri;if(!R)continue;let U=w.get(R);U?U.push(M):w.set(R,[M])}for(let M of h){if(!M.ok||!M.res)continue;let R=M.res;if(R.truncated)continue;let U=new Set;for(let v of R.files||[]){let T=typeof v?.uri=="string"?v.uri:"";T&&U.add(T)}for(let v of R.folders||[]){let T=typeof v=="string"?v:typeof v?.uri=="string"?v.uri:"";T&&U.add(T)}for(let v of w.get(M.folderKey)||[]){let T=g[v];if(T&&!U.has(v)&&!((T.lastUpdated??0)>=M.issuedAt)){if(T.type==="folder"){let Y=(w.get(v)||[]).filter(A=>g[A]!==void 0);if(Y.filter(A=>g[A].status!=="deleted").length>0)continue;Y.length===0?delete g[v]:T.status!=="deleted"&&(g[v]={...T,status:"deleted",lastUpdated:m});continue}T.presence==="unindexed"?(delete g[v],y.push(v),T.status==="pending_review"&&x.remove.add(v)):T.status!=="deleted"&&(g[v]={...T,status:"deleted",lastUpdated:m},T.status==="pending_review"&&x.remove.add(v))}}}let _={files:uh(g,p.expandedFolders,p.openFiles),dirtySources:L,loadedFolders:P};if(y.length){let M=new Set(y),R=p.openFiles.filter(N=>!M.has(N));_.openFiles=R;let U={...p.tabMeta};for(let N of y)delete U[N];_.tabMeta=U,_.activeFile=p.activeFile&&M.has(p.activeFile)?R.length?R[R.length-1]:null:p.activeFile;let v={...p.fileContentByPath},T={...p.fileBaseContentByPath},V={...p.fileErrorByPath},Y={...p.filePrevByPath};for(let N of y)delete v[N],delete T[N],delete V[N],delete Y[N];_.fileContentByPath=v,_.fileBaseContentByPath=T,_.fileErrorByPath=V,_.filePrevByPath=Y}return lh(_,p.pendingReviewPaths,x)})}async function bc(t,e){let{agentId:n,projectId:r,source:a,targets:s}=e,i=e.wide!==!1;if(!n||!a)return;let o=t.fences.reconcileJobs.get(a);if(o){if(o.rerun=!0,i&&(o.wide=!0),s)for(let u of s)o.extra.add(u);await o.promise;return}let l={rerun:!1,wide:i,extra:new Set(s??[]),promise:Promise.resolve()};t.fences.reconcileJobs.set(a,l),l.promise=(async()=>{try{for(let u=0;u<j2;u++){l.rerun=!1;let c=l.wide;l.wide=!1;let d=Array.from(l.extra);if(l.extra.clear(),await X2(t,{agentId:n,projectId:r,source:a,extraTargets:d,wide:c}),!l.rerun)break}}finally{t.fences.reconcileJobs.delete(a)}})(),await l.promise}function wc(t,e){let n=`${e}/`,r=Object.keys(t.get().files).filter(a=>a===e||a.startsWith(n));r.length!==0&&t.set(a=>{let s={...a.files};for(let h of r)delete s[h];let i=new Set(r),o=a.openFiles.filter(h=>!i.has(h)),l={...a.tabMeta},u={...a.fileContentByPath},c={...a.fileBaseContentByPath},d={...a.fileErrorByPath},f={...a.filePrevByPath};for(let h of r)delete l[h],delete u[h],delete c[h],delete d[h],delete f[h];return{files:s,openFiles:o,activeFile:a.activeFile&&i.has(a.activeFile)?o.length?o[o.length-1]:null:a.activeFile,tabMeta:l,fileContentByPath:u,fileBaseContentByPath:c,fileErrorByPath:d,filePrevByPath:f}})}var Y2=30;function uh(t,e,n){let r=Object.keys(t);if(r.length<=ah)return t;let a=new Set;for(let u of e){a.add(u);let c=u;for(;c;){a.add(c);let d=et(c);if(!d||d===c)break;c=d}}for(let u of n){a.add(u);let c=et(u);for(;c;){a.add(c);let d=et(c);if(!d||d===c)break;c=d}}for(let u of r)u.endsWith("://")&&a.add(u);let s=r.filter(u=>{if(a.has(u))return!1;let c=t[u].parentUri;return!(c&&e.has(c))}).map(u=>({key:u,ts:t[u].lastUpdated??0})).sort((u,c)=>u.ts-c.ts),i=r.length-ah;if(i<=0||s.length===0)return t;let o={...t},l=Math.min(i,s.length);for(let u=0;u<l;u++)delete o[s[u].key];return console.warn("[Filesystem] cold-row eviction",{total:r.length,cap:ah,removed:l,protected:r.length-s.length}),o}var Px="filesystem",fl=120,ih=240,Nx="neuralis.filesystem.sidebarWidth";function J2(){if(typeof window>"u")return ih;try{let t=window.localStorage.getItem(Nx),e=t?Number(t):NaN;return Number.isFinite(e)&&e>=fl?e:ih}catch{return ih}}function Z2(t){let e=V2(),n=t.client;return Xf()((r,a)=>({windowId:t.windowId??null,client:n,files:{},folderBadges:{},fileContentByPath:{},fileBaseContentByPath:{},fileErrorByPath:{},filePrevByPath:{},openFiles:[],activeFile:null,tabMeta:{},activeUserId:t.userId??null,contextStateByKey:{},previewEditorsEnabled:t.previewEditorsEnabled??!1,expandedFolders:new Set,sidebarOpen:!0,sidebarWidth:J2(),sidebarView:"tree",activeAgentId:t.agentId??null,activeProjectId:t.projectId??null,sources:[],sourcesLoading:!0,activeSource:null,activeRepoRel:"",activeFolderPath:"brain://docs",uploading:!1,workspacePanels:{upload:!1,sources:!1,packages:!1,pending:!1},activeWorkspaceTab:"file",pendingSourceSuggestion:null,vectorHealthOpen:!1,diffViewMode:t.diffViewMode??"auto",pendingPanelFilter:{},loadedFolders:{},hydrationState:{},dirtySources:{},sourceChangeRevision:{},organizeError:null,snapshotError:void 0,pendingReviewPaths:new Set,pendingCount:0,...mx,...gx(r,a),...yx(r,a),...wx,...vx(r,a),toggleSidebar:()=>r(s=>({sidebarOpen:!s.sidebarOpen})),setSidebarView:s=>r(()=>({sidebarView:s})),setSidebarWidth:s=>r(()=>{let i=Math.max(fl,Math.round(s));if(typeof window<"u")try{window.localStorage.setItem(Nx,String(i))}catch{}return{sidebarWidth:i}}),setActiveFolderPath:s=>r(()=>({activeFolderPath:s?String(s):null})),setActiveSource:(s,i)=>r(()=>({activeSource:s,activeRepoRel:typeof i=="string"?i:"",gitOutgoingStat:null})),setWorkspacePanelOpen:(s,i)=>r(o=>{let l={upload:!1,sources:!1,packages:!1,pending:!1};i?l[s]=!0:(l.upload=o.workspacePanels.upload,l.sources=o.workspacePanels.sources,l.packages=o.workspacePanels.packages,l.pending=o.workspacePanels.pending,l[s]=!1);let u=i?s:o.activeWorkspaceTab===s?"file":o.activeWorkspaceTab;return{workspacePanels:l,activeWorkspaceTab:u}}),setPendingSourceSuggestion:s=>r(()=>({pendingSourceSuggestion:s})),setVectorHealthOpen:s=>r(()=>({vectorHealthOpen:s})),setActiveWorkspaceTab:s=>r(()=>({activeWorkspaceTab:s})),setDiffViewMode:s=>r(()=>({diffViewMode:s})),setPreviewEditorsEnabled:s=>r(()=>({previewEditorsEnabled:s})),reorderOpenFiles:(s,i)=>r(o=>{if(s===i)return o;let l=[...o.openFiles],u=l.indexOf(s),c=l.indexOf(i);if(u<0||c<0)return o;let[d]=l.splice(u,1);return l.splice(c,0,d),{openFiles:l}}),toggleTabPin:s=>r(i=>{let o=i.tabMeta[s]||{};return{tabMeta:{...i.tabMeta,[s]:{...o,pinned:!o.pinned,preview:!1}}}}),promoteTab:s=>r(i=>{let o=i.tabMeta[s];return!o||!o.preview?i:{tabMeta:{...i.tabMeta,[s]:{...o,preview:!1}}}}),closeAllFiles:()=>r(s=>{let i=s.openFiles.filter(l=>s.tabMeta[l]?.pinned),o=s.activeFile&&i.includes(s.activeFile)?s.activeFile:i[i.length-1]??null;return{openFiles:i,activeFile:o}}),closeSavedFiles:()=>r(s=>{let i=u=>{let c=s.fileBaseContentByPath[u],d=s.fileContentByPath[u];return typeof c=="string"&&c!==d},o=s.openFiles.filter(u=>s.tabMeta[u]?.pinned||i(u)||s.files[u]?.status==="pending_review"),l=s.activeFile&&o.includes(s.activeFile)?s.activeFile:o[o.length-1]??null;return{openFiles:o,activeFile:l}}),closeOtherFiles:s=>r(i=>{let o=i.openFiles.filter(l=>l===s||i.tabMeta[l]?.pinned);return{openFiles:o,activeFile:o.includes(s)?s:o[o.length-1]??null}}),setPendingPanelFilter:s=>r(()=>({pendingPanelFilter:s})),toggleFolder:s=>r(i=>{if(i.expandedFolders.has(s)){let u=new Set(Array.from(i.expandedFolders).filter(f=>!Lx(f,[s]))),c=i.loadedFolders||{},d=Ax(c,[s]);return d===c?{expandedFolders:u}:{expandedFolders:u,loadedFolders:d}}let o=!!i.folderBadges[s],l=o?{...i.folderBadges}:i.folderBadges;return o&&delete l[s],{...yc(i,[s]),folderBadges:l}}),async ensureFolderLoaded({agentId:s,projectId:i,uri:o,force:l}){if(!s||!o)return;let u=a().loadedFolders?.[o];if(!l&&u)return;if(!l&&u===!1){await bc({get:a,set:r,fences:e,client:n},{agentId:s,projectId:i,source:qe(o),targets:[o],wide:!1});return}let c=e.liveFolderLoadInFlight.get(o);if(c){await c;return}r(f=>({hydrationState:{...f.hydrationState||{},[o]:"loading"}}));let d=(async()=>{let f=oh(e,o),h=Date.now();try{let p=await qi(s,i??void 0,{uri:o,recursive:!1},n);if(!Cx(e,o,f)){r(g=>({hydrationState:{...g.hydrationState||{},[o]:g.loadedFolders?.[o]?"ready":"idle"}}));return}r(g=>{let m={...g.files},x={add:new Set,remove:new Set};return Ix(m,p,Date.now(),{issuedAt:h,pending:x}),lh({files:uh(m,g.expandedFolders,g.openFiles),loadedFolders:{...g.loadedFolders||{},[o]:!0},hydrationState:{...g.hydrationState||{},[o]:"ready"}},g.pendingReviewPaths,x)})}catch(p){console.error("[Filesystem] subfolder load failed",p),r(g=>({hydrationState:{...g.hydrationState||{},[o]:"error"}}))}})();e.liveFolderLoadInFlight.set(o,d);try{await d}finally{e.liveFolderLoadInFlight.delete(o)}},clearOrganizeError:()=>r(()=>({organizeError:null})),clearSnapshotError:()=>r(()=>({snapshotError:void 0})),setSourceDirty:(s,i)=>r(o=>{if(!!o.dirtySources[s]===i)return o;let u={...o.dirtySources};return i?u[s]=!0:delete u[s],{dirtySources:u}}),async reconcileSourceFolders({agentId:s,projectId:i,source:o}){await bc({get:a,set:r,fences:e,client:n},{agentId:s,projectId:i,source:o})},fenceInFlightWriters(){e.resetEpoch+=1;for(let s of Array.from(e.folderGeneration.keys()))oh(e,s);e.liveFolderLoadInFlight.clear(),e.rehydrateInFlight.clear()},resetClientState(s){let i=a();if(!i.activeProjectId||s.projectId!==i.activeProjectId||s.level!=="project"&&s.agentId!==i.activeAgentId||(s.level==="widget"||s.level==="instance")&&(s.widgetType!==Px||s.instanceId!==i.windowId))return;a().fenceInFlightWriters();let o=`${i.activeUserId??""}::${i.activeProjectId}::`,l=ei(i.activeUserId,i.activeProjectId,i.activeAgentId??""),u={};for(let[c,d]of Object.entries(i.contextStateByKey))(s.level==="project"?c.startsWith(o):c===l)||(u[c]=d);r(()=>({...Zi(),contextStateByKey:u}))},async reconcileFolders({agentId:s,projectId:i,folders:o}){if(!s||!Array.isArray(o)||o.length===0)return;let l=new Map,u=a().loadedFolders||{};for(let c of o){if(!c)continue;let d=qe(c);if(!d||u[c]===!1)continue;if(!u[c]){a().setSourceDirty(d,!0);continue}let f=l.get(d);f?f.push(c):l.set(d,[c])}l.size!==0&&await Promise.all(Array.from(l.entries()).map(([c,d])=>bc({get:a,set:r,fences:e,client:n},{agentId:s,projectId:i,source:c,targets:d})))},async refreshTree({agentId:s,projectId:i}){if(!s)return;await a().loadList({agentId:s,projectId:i});let o=a(),l=new Set;for(let[u,c]of Object.entries(o.loadedFolders||{})){if(!c)continue;let d=qe(u);d&&l.add(d)}await Promise.all(Array.from(l).map(u=>bc({get:a,set:r,fences:e,client:n},{agentId:s,projectId:i,source:u})))},setActiveFile:s=>{r({activeFile:s,activeWorkspaceTab:"file"}),a().rehydrateActiveTab()},async rehydrateActiveTab(){let s=a(),i=s.activeFile,o=s.activeAgentId;if(!(!i||!o)&&!mc(s,i)&&!e.rehydrateInFlight.has(i)){e.rehydrateInFlight.add(i);try{let l=s.tabMeta[i]?.sourceAgentId,u=l&&l!==o&&!/^__.*__$/.test(l)?l:void 0;await s.openFile({agentId:o,projectId:s.activeProjectId,uri:i,readAgentId:u,revealPane:!1})}finally{e.rehydrateInFlight.delete(i)}}},closeFile:s=>r(i=>{let o=i.openFiles.filter(c=>c!==s),l=i.activeFile===s?o.length?o[o.length-1]:null:i.activeFile,u={...i.tabMeta};return delete u[s],{openFiles:o,activeFile:l,tabMeta:u}}),replaceFilePath:(s,i)=>r(o=>{if(!s||!i||s===i)return o;let l=o.files[s],u={...o.files};l&&(delete u[s],u[i]={...l,storeKey:i,uri:i,name:gt(i)||l.name,parentUri:et(i),lastUpdated:Date.now()});let c={...o.fileContentByPath},d={...o.fileBaseContentByPath},f={...o.fileErrorByPath},h={...o.filePrevByPath};Object.prototype.hasOwnProperty.call(c,s)&&(c[i]=c[s],delete c[s]),Object.prototype.hasOwnProperty.call(d,s)&&(d[i]=d[s],delete d[s]),Object.prototype.hasOwnProperty.call(f,s)&&(f[i]=f[s],delete f[s]),Object.prototype.hasOwnProperty.call(h,s)&&(h[i]=h[s],delete h[s]);let p=[];for(let g of o.openFiles){let m=g===s?i:g;p.includes(m)||p.push(m)}return{files:u,fileContentByPath:c,fileBaseContentByPath:d,fileErrorByPath:f,filePrevByPath:h,openFiles:p,activeFile:o.activeFile===s?i:o.activeFile}}),patchFileNode:(s,i)=>r(o=>{let l=o.files[s];return l?{files:{...o.files,[s]:{...l,...i,lastUpdated:Date.now()}}}:o}),clearFilePrev:s=>r(i=>{if(!i.filePrevByPath[s])return i;let o={...i.filePrevByPath};return delete o[s],{filePrevByPath:o}}),upsertFileNodeFromEvent:({id:s,uri:i,folder_ancestors:o,status:l,sourceAgentId:u,sourceProjectId:c})=>r(d=>{if(!i||!d.files[i]&&l==="deleted")return d;let f=Date.now(),h={...d.files},p=o||xa(i);Qs(h,i,f);let g=et(i),m=h[g];m&&m.type==="folder"&&(h[g]={...m,sourceAgentId:u??m.sourceAgentId,sourceProjectId:c??m.sourceProjectId});let x=h[i],y=qe(i)==="brain";h[i]={...x||sh(i),id:s??x?.id,name:gt(i)||x?.name||"file",type:"file",uri:i,status:l??x?.status,parentUri:g,sourceAgentId:u??x?.sourceAgentId,sourceProjectId:c??x?.sourceProjectId,lastUpdated:f,presence:x?.presence??(y?"brain":"synced"),git:x?.git};let b=new Set(d.pendingReviewPaths);if(l==="pending_review"?b.add(i):x?.status==="pending_review"&&l&&l!=="pending_review"&&b.delete(i),l==="active"&&x?.status==="pending_review"&&d.filePrevByPath[i]){let L={...d.filePrevByPath};return delete L[i],{files:h,filePrevByPath:L,pendingReviewPaths:b}}return{files:h,pendingReviewPaths:b}}),removeFilePath:s=>r(i=>{if(!s||!i.files[s]&&!i.openFiles.includes(s)&&!i.tabMeta[s])return i;let o={...i.files};delete o[s];let l=i.openFiles.filter(g=>g!==s),u=i.activeFile===s?l.length?l[l.length-1]:null:i.activeFile,c={...i.fileContentByPath},d={...i.fileBaseContentByPath},f={...i.fileErrorByPath},h={...i.filePrevByPath};delete c[s],delete d[s],delete f[s],delete h[s];let p={...i.tabMeta};return delete p[s],{files:o,openFiles:l,activeFile:u,tabMeta:p,fileContentByPath:c,fileBaseContentByPath:d,fileErrorByPath:f,filePrevByPath:h}}),incrementFolderBadges:s=>r(i=>{if(!Array.isArray(s)||s.length===0)return i;let o={...i.folderBadges};for(let l of s)l&&(i.expandedFolders.has(l)||(o[l]=(o[l]||0)+1));return{folderBadges:o}}),clearFolderBadge:s=>r(i=>{if(!s||!i.folderBadges[s])return i;let o={...i.folderBadges};return delete o[s],{folderBadges:o}}),autoExpandToFile:s=>r(i=>yc(i,[sr(s),...xa(s)])),updateFileContent:(s,i)=>r(o=>({fileContentByPath:{...o.fileContentByPath,[s]:i},fileErrorByPath:{...o.fileErrorByPath,[s]:void 0}})),async saveFileInPlace({agentId:s,projectId:i,readAgentId:o,node:l,targetUri:u,content:c,currentContent:d}){let f=l.uri,h=!!u&&u!==f,p=c!==d;if(!h&&!p)return{uri:f,moved:!1,contentChanged:!1};let g=e.resetEpoch,m=()=>g!==e.resetEpoch,x=f;if(h){let y=await yr({agentId:s,...i?{projectId:i}:{},id:l.id,uri:f,move:u},n);if(!y||y.ok!==!0)throw new Error(ga(y,"Move failed"));if(x=u,m())return{uri:x,moved:h,contentChanged:!1};a().replaceFilePath(l.storeKey||f,u)}if(p){let y=await yr({agentId:s,...i?{projectId:i}:{},id:l.id,uri:x,overwrite:{content:c}},n);if(!y||y.ok!==!0)throw new Error(ga(y,"Save failed"));if(m())return{uri:x,moved:h,contentChanged:p};let b=h?x:l.storeKey||f;a().updateFileContent(b,c),a().patchFileNode(b,{status:"pending_review"})}return await a().reconcileFolders({agentId:s,projectId:i,folders:Array.from(new Set([et(f),et(x)]))}),m()?{uri:x,moved:h,contentChanged:p}:(await a().openFile({agentId:s,projectId:i,uri:x,readAgentId:o,force:!0}),{uri:x,moved:h,contentChanged:p})},async refreshPendingCount({agentId:s,projectId:i}){if(!s)return;let o=++e.pendingCountSeq,l;try{l=await X0({agentId:s,...i?{projectId:i}:{}},n)}catch{return}if(o!==e.pendingCountSeq)return;let u=a();u.activeAgentId!==s||u.activeProjectId!==i||r(()=>({pendingCount:l}))},async markFileDeleted({agentId:s,projectId:i,node:o}){let l=e.resetEpoch,u=await yr({agentId:s,...i?{projectId:i}:{},id:o.id,uri:o.uri,delete:!0},n);if(!u||u.ok!==!0)throw new Error(ga(u,"Delete failed"));l===e.resetEpoch&&await a().reconcileFolders({agentId:s,projectId:i,folders:[et(o.uri)]})},async moveFileToFolder({agentId:s,projectId:i,fromUri:o,toFolderUri:l,id:u}){if(!s||!o||!l)return;let c=gt(o);if(!c)return;let d=l.endsWith("://")?`${l}${c}`:`${l}/${c}`;if(d===o)return;let f=et(o),h=a().files[o]?.type==="folder",p;try{p=await yr({agentId:s,...i?{projectId:i}:{},id:u,uri:o,move:d},n)}catch(m){console.error("[Filesystem] move failed",o,m),r(()=>({organizeError:"Move failed"}));return}if(p&&p.ok===!1){console.error("[Filesystem] move rejected",o,p.code,p.error),r(()=>({organizeError:ga(p,"Move rejected")})),await a().reconcileFolders({agentId:s,projectId:i,folders:[f,l]});return}let g=p?.warning==="moved_with_source_retained";g&&r(()=>({organizeError:"Copied to the destination, but the original could not be removed \u2014 both copies exist."})),h?(g||wc({get:a,set:r,fences:e,client:n},o),await a().ensureFolderLoaded({agentId:s,projectId:i,uri:l,force:!0})):(r(m=>{let x=m.openFiles.map(y=>y===o?d:y);return{activeFolderPath:l,openFiles:Array.from(new Set(x)),activeFile:m.activeFile===o?d:m.activeFile}}),g||a().replaceFilePath(o,d)),await a().reconcileFolders({agentId:s,projectId:i,folders:[f,l]})},async renameNode({agentId:s,projectId:i,uri:o,id:l,newName:u}){let c=(u??"").trim();if(!s||!o||!c||c===gt(o))return;let d=et(o),f=d.endsWith("://")?`${d}${c}`:`${d}/${c}`;if(f===o)return;let h=a().files[o]?.type==="folder",p;try{p=await yr({agentId:s,...i?{projectId:i}:{},id:l,uri:o,move:h?f:c},n)}catch(g){console.error("[Filesystem] rename failed",o,g),r(()=>({organizeError:"Rename failed"}));return}if(p&&p.ok===!1){console.error("[Filesystem] rename rejected",o,p.code,p.error),r(()=>({organizeError:ga(p,"Rename rejected")})),await a().reconcileFolders({agentId:s,projectId:i,folders:[d]});return}h?(wc({get:a,set:r,fences:e,client:n},o),await a().ensureFolderLoaded({agentId:s,projectId:i,uri:d,force:!0})):a().replaceFilePath(o,f),await a().reconcileFolders({agentId:s,projectId:i,folders:[d]})},async createNode({agentId:s,projectId:i,parentUri:o,name:l,kind:u}){let c=(l??"").trim();if(!s||!o||!c)return;let d=o.endsWith("://")?`${o}${c}`:`${o}/${c}`,f=e.resetEpoch;try{if(u==="folder"){let h=await yr({agentId:s,...i?{projectId:i}:{},uri:d,mkdir:!0},n);h?.ok&&f===e.resetEpoch?r(p=>({...yc(p,[o]),files:{...p.files,[d]:{storeKey:d,name:c,uri:d,type:"folder",parentUri:o,presence:"unindexed",lastUpdated:Date.now()}}})):h&&h.ok===!1&&(console.error("[Filesystem] create folder rejected",d,h.code,h.error),r(()=>({organizeError:ga(h,"Could not create folder")})))}else await dc({agentId:s,...i?{projectId:i}:{},file:new File([""],c),uri:o,tags:[]},n)}catch(h){console.error("[Filesystem] create failed",u,d,h),r(()=>({organizeError:`Could not create ${u==="folder"?"folder":"file"}`}))}await a().reconcileFolders({agentId:s,projectId:i,folders:[o]})},async pasteNodes({agentId:s,projectId:i,targetFolderUri:o,op:l,uris:u}){if(!s||!o||!Array.isArray(u)||u.length===0)return;let c=new Set([o]),d=[];for(let f of u){if(!f)continue;let h=gt(f);if(!h)continue;let p=o.endsWith("://")?`${o}${h}`:`${o}/${h}`;if(p!==f){c.add(et(f));try{if(l==="copy"){let g=await yr({agentId:s,...i?{projectId:i}:{},uri:f,copy:p},n);g&&g.ok===!1&&d.push(h)}else{let g=await yr({agentId:s,...i?{projectId:i}:{},uri:f,move:p},n);g&&g.ok===!1?d.push(h):g?.warning==="moved_with_source_retained"?d.push(`${h} (original retained)`):a().files[f]?.type==="folder"&&wc({get:a,set:r,fences:e,client:n},f)}}catch(g){console.error("[Filesystem] paste failed",l,f,g),d.push(h)}}}d.length&&r(()=>({organizeError:`${l==="copy"?"Copy":"Move"} incomplete: ${d.join(", ")}`})),await a().reconcileFolders({agentId:s,projectId:i,folders:Array.from(c)})},async deleteNodes({agentId:s,projectId:i,targets:o}){if(!s||!Array.isArray(o)||o.length===0)return;let l=new Set,u=[],c=null;for(let d of o){if(!d?.uri)continue;l.add(et(d.uri));let f=a().files[d.uri]?.type==="folder";try{let h=await yr({agentId:s,...i?{projectId:i}:{},id:d.id,uri:d.uri,delete:!0},n);if(h&&h.ok===!1){console.error("[Filesystem] delete rejected",d.uri,h.code,h.error),u.push(gt(d.uri)||d.uri),(typeof h.affected=="number"||h.failed?.length)&&(c={affected:h.affected,failed:h.failed});continue}f?wc({get:a,set:r,fences:e,client:n},d.uri):a().patchFileNode(d.uri,{status:"deleted"})}catch(h){console.error("[Filesystem] delete failed",d.uri,h),u.push(gt(d.uri)||d.uri)}}if(u.length){let d=c?.failed?.length?` \u2014 ${c.affected??0} removed, could not remove: ${c.failed.slice(0,5).join(", ")}${c.failed.length>5?"\u2026":""}`:"";r(()=>({organizeError:`Delete failed: ${u.join(", ")}${d}`}))}await a().reconcileFolders({agentId:s,projectId:i,folders:Array.from(l)})},async openFile({agentId:s,projectId:i,uri:o,readAgentId:l,force:u,revealPane:c=!0}){if(!s||!o)return;r(p=>{let g=p.openFiles.includes(o),m=p.previewEditorsEnabled&&!g&&!p.tabMeta[o]?.pinned,x=p.openFiles,y=p.tabMeta;if(m){let C=p.openFiles.find(L=>L!==o&&p.tabMeta[L]?.preview&&!p.tabMeta[L]?.pinned);C&&(x=x.filter(L=>L!==C),y={...y},delete y[C]),y={...y,[o]:{...y[o]||{},preview:!0}}}let b=x.includes(o)?x:[...x,o];if(b.length>Y2){let C=b.findIndex(L=>L!==o&&!p.tabMeta[L]?.pinned);C>=0&&(b=b.filter((L,P)=>P!==C))}return{openFiles:b,activeFile:o,activeAgentId:s,activeProjectId:i,...c?{activeWorkspaceTab:"file"}:{},tabMeta:y}}),a().autoExpandToFile(o);{let p=new Set([sr(o),...xa(o)]);for(let g of p)!g||g===o||a().ensureFolderLoaded({agentId:s,projectId:i,uri:g})}let d=a(),f=typeof d.fileBaseContentByPath[o]=="string"||typeof d.fileContentByPath[o]=="string"&&(d.fileContentByPath[o]?.length||0)>0;if(!u&&f)return;let h=e.resetEpoch;try{let p=await $i({agentId:l||s,...i?{projectId:i}:{},files:[o]},n);if(h!==e.resetEpoch)return;let g=Yi(p);if(g.length>0){let m=g[0],x=Ji(m),y=typeof m.error=="string"?m.error:void 0,b=typeof m.code=="string"&&m.code==="not_found";if(y&&b){a().removeFilePath(o);return}let C=typeof m.status=="string"?String(m.status):void 0,L=typeof m.category=="string"?m.category:void 0,P=Array.isArray(m.tags)?m.tags:void 0,w=m.metadata&&typeof m.metadata=="object"?m.metadata:void 0,k=typeof m.createdAt=="string"?m.createdAt:void 0,_=typeof m.updatedAt=="string"?m.updatedAt:void 0,M=m.version&&typeof m.version=="object"?m.version:void 0,R=typeof m.readSource=="string"?m.readSource:void 0,U=typeof m.id=="string"?m.id:void 0,v=typeof m.uri=="string"?String(m.uri):o,T=typeof m.agent_id=="string"?String(m.agent_id):l||s,V=typeof m.project_id=="string"?String(m.project_id):i||void 0,Y=qe(v)==="brain",N=M?.sync?.status,A=pc(M?.baseline);r(B=>{let K=B.files[v],te=B.fileContentByPath[v],ne=B.fileBaseContentByPath[v],pe=y&&typeof te=="string"?te:x,Se=y&&typeof ne=="string"?ne:x,le={...B.files},re=!!U||!!C||!!M,he=Y?"brain":K?.presence??(re?"synced":R==="live"?"unindexed":"synced");Qs(le,v,Date.now());let Ne=B.openFiles.includes(v)?B.openFiles:B.openFiles.map(Ee=>Ee===o?v:Ee);return{files:{...le,[v]:{...K||sh(v),id:U??K?.id,name:String(m.filename||K?.name||gt(v)),type:"file",uri:v,parentUri:et(v),status:C??K?.status,sourceAgentId:T,sourceProjectId:V??K?.sourceProjectId,lastUpdated:K?.lastUpdated??Date.now(),category:L??K?.category,tags:P??K?.tags,metadata:w??K?.metadata,createdAt:k??K?.createdAt,updatedAt:_??K?.updatedAt,version:M??K?.version,presence:he,readSource:R??K?.readSource}},fileContentByPath:{...B.fileContentByPath,[v]:pe},fileBaseContentByPath:{...B.fileBaseContentByPath,[v]:Se},fileErrorByPath:{...B.fileErrorByPath,[v]:y},filePrevByPath:{...B.filePrevByPath,[v]:A},openFiles:Array.from(new Set(Ne)),activeFile:v,tabMeta:{...B.tabMeta,[v]:{...B.tabMeta[v]||B.tabMeta[o]||{},name:String(m.filename||K?.name||gt(v)),status:C??K?.status,sourceAgentId:T}}}})}}catch(p){let g=p instanceof Error?p.message:"Read failed";if(console.error("[Filesystem] read failed",p),h!==e.resetEpoch)return;r(m=>({files:{...m.files,[o]:{...m.files[o]||sh(o),sourceAgentId:l||s,sourceProjectId:i||void 0,lastUpdated:m.files[o]?.lastUpdated??Date.now()}},fileErrorByPath:{...m.fileErrorByPath,[o]:g}}))}},async applyNav({agentId:s,projectId:i,nav:o,readAgentId:l,force:u}){if(!s||!o||o.kind!=="filesystem")return;let c=String(o.action||""),d=o.uri;if((c==="read"||c==="open"||c==="modify"||c==="save")&&d){await a().openFile({agentId:s,projectId:i,uri:d,readAgentId:l,force:u});return}if(c==="open-pending"){r(()=>({activeAgentId:s,activeProjectId:i})),a().setPendingPanelFilter(o.filter??{}),a().setWorkspacePanelOpen("pending",!0);return}if(c==="open-sources"||c==="open-vector-health"){r(()=>({activeAgentId:s,activeProjectId:i,...c==="open-vector-health"?{vectorHealthOpen:!0}:{}})),a().setWorkspacePanelOpen("sources",!0);return}c==="list"&&d&&r(f=>{let h=sr(d),p=f.expandedFolders.has(d)&&f.expandedFolders.has(h),g=f.activeAgentId===s,m=f.activeProjectId===i;return p&&g&&m?f:{...yc(f,[h,d]),activeAgentId:s,activeProjectId:i}})},async upload({agentId:s,projectId:i,file:o,uri:l}){if(!s)return;let u=l||"brain://docs";r(()=>({uploading:!0}));try{await dc({agentId:s,...i?{projectId:i}:{},file:o,uri:u,tags:["upload"]},n),await a().reconcileFolders({agentId:s,projectId:i,folders:[u]})}finally{r(()=>({uploading:!1}))}},async uploadMany({agentId:s,projectId:i,files:o,uri:l}){if(!s)return;let u=Array.isArray(o)?o.filter(Boolean):[];if(u.length===0)return;let c=l||"brain://docs";r(()=>({uploading:!0}));try{for(let d of u)await dc({agentId:s,...i?{projectId:i}:{},file:d,uri:c,tags:["upload"]},n);await a().reconcileFolders({agentId:s,projectId:i,folders:[c]})}finally{r(()=>({uploading:!1}))}},...t.projection?xx(t.projection):{}}))}var Qi=Xf()(I0(()=>({previewEditorsEnabled:!1,diffViewMode:"auto",activeUserId:null,activeAgentId:null,activeProjectId:null,contexts:{}}),{name:"neuralis.filesystem.tabs",version:2,migrate:(t,e)=>{if(e>=2)return t;let n=t??{},r=n.activeAgentId?ei(null,n.activeProjectId??null,n.activeAgentId):null;return{previewEditorsEnabled:n.previewEditorsEnabled??!1,diffViewMode:n.diffViewMode??"auto",activeUserId:null,activeAgentId:n.activeAgentId??null,activeProjectId:n.activeProjectId??null,contexts:r?{[r]:xc({...Zi(),openFiles:n.openFiles??[],activeFile:n.activeFile??null,tabMeta:n.tabMeta??{}})}:{}}},merge:(t,e)=>{let n=t;return n?{previewEditorsEnabled:n.previewEditorsEnabled??e.previewEditorsEnabled,diffViewMode:n.diffViewMode??e.diffViewMode,activeUserId:n.activeUserId??null,activeAgentId:n.activeAgentId??null,activeProjectId:n.activeProjectId??null,contexts:n.contexts??{},...n.windows?{windows:n.windows}:{}}:e},storage:Jf(()=>typeof window<"u"&&window.localStorage?window.localStorage:{getItem:()=>null,setItem:()=>{},removeItem:()=>{}}),partialize:t=>({previewEditorsEnabled:t.previewEditorsEnabled,diffViewMode:t.diffViewMode,activeUserId:t.activeUserId,activeAgentId:t.activeAgentId,activeProjectId:t.activeProjectId,contexts:t.contexts,...t.windows?{windows:t.windows}:{}})}));function Q2(t,e){return t.userId===e.userId&&t.projectId===e.projectId&&t.agentId===e.agentId}function eA(t){let{userId:e,projectId:n,agentId:r,...a}=t;return a}function tA(t){let e=Qi.getState(),n=e.windows?.[t.windowId],r=n&&Q2(n,t)?eA(n):void 0;return Z2({client:(0,Sx.createPackageApi)({slug:"brain-core",getProjectId:()=>t.projectId,getAgentId:()=>t.agentId}),windowId:t.windowId,userId:t.userId,projectId:t.projectId,agentId:t.agentId,previewEditorsEnabled:e.previewEditorsEnabled,diffViewMode:e.diffViewMode,...r?{projection:r}:{}})}var nA=["openFiles","activeFile","tabMeta","expandedFolders","sidebarView","activeWorkspaceTab","workspacePanels","activeFolderPath"];function rA(t,e){let n=JSON.stringify(xc(t.getState()));return t.subscribe((r,a)=>{if(r.previewEditorsEnabled!==a.previewEditorsEnabled||r.diffViewMode!==a.diffViewMode){let o=Qi.getState();(o.previewEditorsEnabled!==r.previewEditorsEnabled||o.diffViewMode!==r.diffViewMode)&&Qi.setState({previewEditorsEnabled:r.previewEditorsEnabled,diffViewMode:r.diffViewMode})}if(!nA.some(o=>r[o]!==a[o])||r.activeUserId!==e.userId||r.activeProjectId!==e.projectId||r.activeAgentId!==e.agentId)return;let s=xc(r),i=JSON.stringify(s);i!==n&&(n=i,Qi.setState(o=>({windows:{...o.windows??{},[e.windowId]:{userId:e.userId,projectId:e.projectId,agentId:e.agentId,...s}}})))})}var ch=new Set,Rx=null;function Mx(t){Rx=t}function aA(t,e){let n={identity:e,store:t};ch.add(n);let r=rA(t,e);return()=>{r(),ch.delete(n),t.getState().fenceInFlightWriters()}}function sA(t,e){return t.projectId!==e.projectId?!1:t.level==="project"?!0:t.agentId!==e.agentId?!1:t.level==="agent"||t.instanceId===e.windowId}function iA(t,e){if((t.level==="instance"||t.level==="widget")&&t.widgetType!==Px)return;let n=Qi.getState(),r=(o,l)=>l.projectId!==t.projectId?!1:t.level==="instance"||t.level==="widget"?o===t.instanceId&&l.agentId===t.agentId:e===null||l.userId!==e?!1:t.level==="project"||l.agentId===t.agentId,a=o=>t.level==="instance"?!1:t.level==="project"?o.startsWith(`${e??""}::${t.projectId}::`):o===ei(e,t.projectId,t.agentId),s=n.windows;for(let[o,l]of Object.entries(n.windows??{}))r(o,l)&&(s===n.windows&&(s={...n.windows}),delete s[o]);let i=n.contexts;for(let o of Object.keys(n.contexts))a(o)&&(i===n.contexts&&(i={...n.contexts}),delete i[o]);s===n.windows&&i===n.contexts||Qi.setState({contexts:i,...s?{windows:s}:{}})}function Tx(t){for(let e of ch)sA(t,e.identity)&&e.store.getState().resetClientState(t);iA(t,Rx)}function Dx(t,e,n,r){let a=(0,ya.useMemo)(()=>{if(!t||!e||!n||!r)return null;let s={windowId:t,userId:e,projectId:n,agentId:r};return{identity:s,store:tA(s)}},[t,e,n,r]);return(0,ya.useLayoutEffect)(()=>a?aA(a.store,a.identity):void 0,[a]),a?.store??null}var Fx=(0,ya.createContext)(null);function Ex({store:t,children:e}){return(0,ya.createElement)(Fx.Provider,{value:t},e)}function ti(){let t=(0,ya.useContext)(Fx);if(!t)throw new Error("useFilesystemStore must be used inside a Files window (FilesystemStoreProvider)");return t}function H(t){return C0(ti(),t)}var Vl=j(Wn(),1);var vc=j($e(),1);var Ox=t=>t?.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();function Bx(t,e,n=[]){if(e==null)throw new Error("[lucide]: iconNode is required when icon name is used");return{name:Ox(t),size:24,node:e,...n.length>0?{aliases:n}:{}}}var _x=t=>{let e="",n=!1;for(let r of t){if(r==="-"||r==="_"||r<=" "){n=e.length>0;continue}e.length===0?e+=r.toLowerCase():e+=n?r.toUpperCase():r,n=!1}return e};var Hx=t=>{let e=_x(t);return e.charAt(0).toUpperCase()+e.slice(1)};var pl=j($e(),1);var hl=(...t)=>t.filter((e,n,r)=>!!e&&e.trim()!==""&&r.indexOf(e)===n).join(" ").trim();var ms={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":2,"stroke-linecap":"round","stroke-linejoin":"round"};function dh(t){return t!=null}function Ux(t,e={}){let n=e.attributeNames??{},r=f=>n[f]??f,a=t.size??t.width??ms.width,s=t.size??t.height??ms.height,i=t.aliases?.filter(f=>typeof f=="string"&&f.trim()!=="").map(f=>`lucide-${f}`)??[],o=[...t.name?[`lucide-${t.name}`]:[],...i],l=e.className?.split(" ").filter(Boolean)??[],u=e.includeDefaultClasses===!1?hl(...l):hl("lucide",...o,...l),c=e.absoluteStrokeWidth?Number(e.strokeWidth??ms["stroke-width"])*Number(t.size??t.width??ms.width)/Number(e.size??e.width??ms.width):e.strokeWidth??ms["stroke-width"];return["svg",{...Object.entries(ms).reduce((f,[h,p])=>(f[r(h)]=p,f),{}),..."color"in e&&e.color&&{[r("stroke")]:e.color},..."size"in e&&dh(e.size)&&{[r("width")]:e.size,[r("height")]:e.size},..."width"in e&&dh(e.width)&&{[r("width")]:e.width},..."height"in e&&dh(e.height)&&{[r("height")]:e.height},[r("stroke-width")]:c,...u&&{[r("class")]:u},[r("viewBox")]:`0 0 ${a} ${s}`,...e.hasA11yProp===!1?{[r("aria-hidden")]:"true"}:{},..."attributes"in e&&e.attributes},t.node.map(f=>{let[h,p,g]=f,m=e.nonScalingStroke?{[r("vector-effect")]:"non-scaling-stroke",...p}:p;return g?[h,m,g]:[h,m]})]}function Gx(t,e={}){return Ux(t,{...e,attributeNames:{...e.attributeNames,class:"className","stroke-width":"strokeWidth","stroke-linecap":"strokeLinecap","stroke-linejoin":"strokeLinejoin","vector-effect":"vectorEffect"}})}var Wx=t=>{for(let e in t)if(e.startsWith("aria-")||e==="role"||e==="title")return!0;return!1};var eo=j($e(),1);var oA=(0,eo.createContext)({});var zx=()=>(0,eo.useContext)(oA);var jx=(0,pl.forwardRef)(({color:t,size:e,width:n,height:r,strokeWidth:a,absoluteStrokeWidth:s,nonScalingStroke:i,className:o="",children:l,iconNode:u=[],icon:c={node:u,aliases:[],size:24},...d},f)=>{let{size:h=24,strokeWidth:p=2,absoluteStrokeWidth:g=!1,nonScalingStroke:m=!1,color:x="currentColor",className:y=""}=zx()??{},b=!!l||Wx(d),[C,L,P=[]]=Gx(c,{color:t??x,width:n??e??h,height:r??e??h,strokeWidth:a??p,absoluteStrokeWidth:s??g,nonScalingStroke:i??m,className:hl(y,o),hasA11yProp:b,attributes:d});return(0,pl.createElement)(C,{ref:f,...L},[...P.map(([w,k])=>(0,pl.createElement)(w,k)),...Array.isArray(l)?l:[l]])});function W(t,e=[],n=[]){let r=typeof t=="string"?Bx(t,e,n):t,a=(0,vc.forwardRef)(({className:s,...i},o)=>(0,vc.createElement)(jx,{ref:o,icon:r,className:s,...i}));return r.name&&(a.displayName=Hx(r.name)),a}var Vx={name:"archive",size:24,node:[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]]};Vx.node;var to=W(Vx);var qx={name:"arrow-down",size:24,node:[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]};qx.node;var ml=W(qx);var $x={name:"arrow-right",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]};$x.node;var no=W($x);var Kx={name:"arrow-up-down",size:24,node:[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]]};Kx.node;var gl=W(Kx);var Xx={name:"arrow-up",size:24,node:[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]};Xx.node;var xl=W(Xx);var Yx={name:"bot",size:24,node:[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]]};Yx.node;var yl=W(Yx);var Jx={name:"braces",size:24,node:[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]],aliases:["curly-braces"]};Jx.node;var ba=W(Jx);var Zx={name:"check-check",size:24,node:[["path",{d:"M18 6 7 17l-5-5",key:"116fxf"}],["path",{d:"m22 10-7.5 7.5L13 16",key:"ke71qq"}]]};Zx.node;var gs=W(Zx);var Qx={name:"check",size:24,node:[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]};Qx.node;var Dn=W(Qx);var ey={name:"chevron-down",size:24,node:[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]};ey.node;var Et=W(ey);var ty={name:"chevron-left",size:24,node:[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]};ty.node;var bl=W(ty);var ny={name:"chevron-right",size:24,node:[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]};ny.node;var un=W(ny);var ry={name:"chevron-up",size:24,node:[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]]};ry.node;var qa=W(ry);var ay={name:"circle-alert",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]],aliases:["alert-circle"]};ay.node;var xs=W(ay);var sy={name:"circle-check",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16 9-5.5 5.5L8 12",key:"xofnsj"}]],aliases:["check-circle-2"]};sy.node;var Qr=W(sy);var iy={name:"circle-question-mark",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]],aliases:["help-circle","circle-help"]};iy.node;var ea=W(iy);var oy={name:"circle-x",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]],aliases:["x-circle"]};oy.node;var ta=W(oy);var ly={name:"clipboard-paste",size:24,node:[["path",{d:"M11 14h10",key:"1w8e9d"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v1.344",key:"1e62lh"}],["path",{d:"m17 18 4-4-4-4",key:"z2g111"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113",key:"bjbb7m"}],["rect",{x:"8",y:"2",width:"8",height:"4",rx:"1",key:"ublpy"}]]};ly.node;var wl=W(ly);var uy={name:"clock-3",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6h4",key:"135r8i"}]]};uy.node;var wa=W(uy);var cy={name:"cloud",size:24,node:[["path",{d:"M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z",key:"p7xjir"}]]};cy.node;var vl=W(cy);var dy={name:"cloud-upload",size:24,node:[["path",{d:"M12 13v8",key:"1l5pq0"}],["path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242",key:"1pljnt"}],["path",{d:"m8 17 4-4 4 4",key:"1quai1"}]],aliases:["upload-cloud"]};dy.node;var Mr=W(dy);var fy={name:"columns-2",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]],aliases:["columns"]};fy.node;var ys=W(fy);var hy={name:"copy",size:24,node:[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]};hy.node;var na=W(hy);var py={name:"corner-up-right",size:24,node:[["path",{d:"m15 14 5-5-5-5",key:"12vg1m"}],["path",{d:"M4 20v-7a4 4 0 0 1 4-4h12",key:"1lu4f8"}]]};py.node;var kl=W(py);var my={name:"database",size:24,node:[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]};my.node;var ir=W(my);var gy={name:"ellipsis",size:24,node:[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],aliases:["more-horizontal"]};gy.node;var bs=W(gy);var xy={name:"eye",size:24,node:[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]};xy.node;var Sl=W(xy);var yy={name:"file-code",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 12.5 8 15l2 2.5",key:"1tg20x"}],["path",{d:"m14 12.5 2 2.5-2 2.5",key:"yinavb"}]]};yy.node;var Cl=W(yy);var by={name:"file-code-corner",size:24,node:[["path",{d:"M4 12.15V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2h-3.35",key:"1wthlu"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"m5 16-3 3 3 3",key:"331omg"}],["path",{d:"m9 22 3-3-3-3",key:"lsp7cz"}]],aliases:["file-code-2"]};by.node;var $a=W(by);var wy={name:"file-diff",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M9 10h6",key:"9gxzsh"}],["path",{d:"M12 13V7",key:"h0r20n"}],["path",{d:"M9 17h6",key:"r8uit2"}]]};wy.node;var Ka=W(wy);var vy={name:"file-exclamation-point",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],aliases:["file-warning"]};vy.node;var ws=W(vy);var ky={name:"file-image",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["circle",{cx:"10",cy:"12",r:"2",key:"737tya"}],["path",{d:"m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22",key:"wt3hpn"}]]};ky.node;var Il=W(ky);var Sy={name:"file-pen",size:24,node:[["path",{d:"M12.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v9.34",key:"o6klzx"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10.378 12.622a1 1 0 0 1 3 3.003L8.36 20.637a2 2 0 0 1-.854.506l-2.867.837a.5.5 0 0 1-.62-.62l.836-2.869a2 2 0 0 1 .506-.853z",key:"zhnas1"}]],aliases:["file-edit"]};Sy.node;var vs=W(Sy);var Cy={name:"file-play",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M15.033 13.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56v-4.704a.645.645 0 0 1 .967-.56z",key:"1tzo1f"}]],aliases:["file-video"]};Cy.node;var ks=W(Cy);var Iy={name:"file-plus-corner",size:24,node:[["path",{d:"M11.35 22H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v5.35",key:"17jvcc"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M14 19h6",key:"bvotb8"}],["path",{d:"M17 16v6",key:"18yu1i"}]],aliases:["file-plus-2"]};Iy.node;var Ss=W(Iy);var Ly={name:"file-plus",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M9 15h6",key:"cctwl0"}],["path",{d:"M12 18v-6",key:"17g6i2"}]]};Ly.node;var Cs=W(Ly);var Ay={name:"file-text",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]]};Ay.node;var va=W(Ay);var Py={name:"file",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}]]};Py.node;var Ll=W(Py);var Ny={name:"folder-open",size:24,node:[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 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",key:"usdka0"}]]};Ny.node;var Is=W(Ny);var Ry={name:"folder-plus",size:24,node:[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]};Ry.node;var br=W(Ry);var My={name:"folder-tree",size:24,node:[["path",{d:"M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"hod4my"}],["path",{d:"M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"w4yl2u"}],["path",{d:"M3 5a2 2 0 0 0 2 2h3",key:"f2jnh7"}],["path",{d:"M3 3v13a2 2 0 0 0 2 2h3",key:"k8epm1"}]]};My.node;var Al=W(My);var Ty={name:"folder",size:24,node:[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]};Ty.node;var Tr=W(Ty);var Dy={name:"git-branch",size:24,node:[["path",{d:"M15 6a9 9 0 0 0-9 9V3",key:"1cii5b"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}]]};Dy.node;var Cn=W(Dy);var Fy={name:"git-commit-horizontal",size:24,node:[["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["line",{x1:"3",x2:"9",y1:"12",y2:"12",key:"1dyftd"}],["line",{x1:"15",x2:"21",y1:"12",y2:"12",key:"oup4p8"}]],aliases:["git-commit"]};Fy.node;var Dr=W(Fy);var Ey={name:"git-compare-arrows",size:24,node:[["circle",{cx:"5",cy:"6",r:"3",key:"1qnov2"}],["path",{d:"M12 6h5a2 2 0 0 1 2 2v7",key:"1yj91y"}],["path",{d:"m15 9-3-3 3-3",key:"1lwv8l"}],["circle",{cx:"19",cy:"18",r:"3",key:"1qljk2"}],["path",{d:"M12 18H7a2 2 0 0 1-2-2V9",key:"16sdep"}],["path",{d:"m9 15 3 3-3 3",key:"1m3kbl"}]]};Ey.node;var or=W(Ey);var Oy={name:"git-compare",size:24,node:[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M13 6h3a2 2 0 0 1 2 2v7",key:"1yeb86"}],["path",{d:"M11 18H8a2 2 0 0 1-2-2V9",key:"19pyzm"}]]};Oy.node;var ro=W(Oy);var By={name:"hard-drive",size:24,node:[["path",{d:"M10 16h.01",key:"1bzywj"}],["path",{d:"M2.212 11.577a2 2 0 0 0-.212.896V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-5.527a2 2 0 0 0-.212-.896L18.55 5.11A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"18tbho"}],["path",{d:"M21.946 12.013H2.054",key:"zqlbp7"}],["path",{d:"M6 16h.01",key:"1pmjb7"}]]};By.node;var zn=W(By);var _y={name:"info",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]]};_y.node;var Pl=W(_y);var Hy={name:"link-2",size:24,node:[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]]};Hy.node;var Nl=W(Hy);var Uy={name:"link-2-off",size:24,node:[["path",{d:"M9 17H7A5 5 0 0 1 7 7",key:"10o201"}],["path",{d:"M15 7h2a5 5 0 0 1 4 8",key:"1d3206"}],["line",{x1:"8",x2:"12",y1:"12",y2:"12",key:"rvw6j4"}],["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}]]};Uy.node;var Rl=W(Uy);var Gy={name:"list",size:24,node:[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]]};Gy.node;var ni=W(Gy);var Wy={name:"loader-circle",size:24,node:[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],aliases:["loader-2"]};Wy.node;var We=W(Wy);var zy={name:"lock",size:24,node:[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4",key:"fwvmzm"}]]};zy.node;var ri=W(zy);var jy={name:"minus",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}]]};jy.node;var ai=W(jy);var Vy={name:"mouse-pointer-click",size:24,node:[["path",{d:"M14 4.1 12 6",key:"ita8i4"}],["path",{d:"m5.1 8-2.9-.8",key:"1go3kf"}],["path",{d:"m6 12-1.9 2",key:"mnht97"}],["path",{d:"M7.2 2.2 8 5.1",key:"1cfko1"}],["path",{d:"M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z",key:"s0h3yz"}]]};Vy.node;var Ml=W(Vy);var qy={name:"move-right",size:24,node:[["path",{d:"M18 8L22 12L18 16",key:"1r0oui"}],["path",{d:"M2 12H22",key:"1m8cig"}]]};qy.node;var Tl=W(qy);var $y={name:"music-4",size:24,node:[["path",{d:"M9 18V5l12-2v13",key:"1jmyc2"}],["path",{d:"m9 9 12-2",key:"1e64n2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["circle",{cx:"18",cy:"16",r:"3",key:"1hluhg"}]]};$y.node;var Dl=W($y);var Ky={name:"network",size:24,node:[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]};Ky.node;var Fl=W(Ky);var Xy={name:"package",size:24,node:[["path",{d:"M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z",key:"1a0edw"}],["path",{d:"M12 22V12",key:"d0xqtd"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}]]};Xy.node;var wr=W(Xy);var Yy={name:"panel-left",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]],aliases:["sidebar"]};Yy.node;var Ls=W(Yy);var Jy={name:"pen-line",size:24,node:[["path",{d:"M13 21h8",key:"1jsn5i"}],["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]],aliases:["edit-3"]};Jy.node;var As=W(Jy);var Zy={name:"pencil",size:24,node:[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]};Zy.node;var si=W(Zy);var Qy={name:"pin",size:24,node:[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]};Qy.node;var ii=W(Qy);var eb={name:"play",size:24,node:[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]]};eb.node;var El=W(eb);var tb={name:"plus",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]};tb.node;var Fn=W(tb);var nb={name:"radio",size:24,node:[["path",{d:"M16.247 7.761a6 6 0 0 1 0 8.478",key:"1fwjs5"}],["path",{d:"M19.075 4.933a10 10 0 0 1 0 14.134",key:"ehdyv1"}],["path",{d:"M4.925 19.067a10 10 0 0 1 0-14.134",key:"1q22gi"}],["path",{d:"M7.753 16.239a6 6 0 0 1 0-8.478",key:"r2q7qm"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]};nb.node;var Xa=W(nb);var rb={name:"refresh-ccw",size:24,node:[["path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"14sxne"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16",key:"1hlbsb"}],["path",{d:"M16 16h5v5",key:"ccwih5"}]]};rb.node;var ka=W(rb);var ab={name:"refresh-cw",size:24,node:[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]};ab.node;var _t=W(ab);var sb={name:"rotate-ccw",size:24,node:[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]};sb.node;var oi=W(sb);var ib={name:"save",size:24,node:[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]};ib.node;var li=W(ib);var ob={name:"scan-search",size:24,node:[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["path",{d:"m16 16-1.9-1.9",key:"1dq9hf"}]]};ob.node;var Ya=W(ob);var lb={name:"scissors",size:24,node:[["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M8.12 8.12 12 12",key:"1alkpv"}],["path",{d:"M20 4 8.12 15.88",key:"xgtan2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M14.8 14.8 20 20",key:"ptml3r"}]]};lb.node;var Ol=W(lb);var ub={name:"search",size:24,node:[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]};ub.node;var Bl=W(ub);var cb={name:"settings",size:24,node:[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",key:"1i5ecw"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]};cb.node;var ao=W(cb);var db={name:"shield-alert",size:24,node:[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]};db.node;var Sa=W(db);var fb={name:"shield-check",size:24,node:[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]};fb.node;var so=W(fb);var hb={name:"shield-off",size:24,node:[["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71",key:"1jlk70"}],["path",{d:"M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264",key:"18rp1v"}]]};hb.node;var _l=W(hb);var pb={name:"shield",size:24,node:[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]]};pb.node;var Ps=W(pb);var mb={name:"sigma",size:24,node:[["path",{d:"M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2",key:"wuwx1p"}]]};mb.node;var Hl=W(mb);var gb={name:"sliders-horizontal",size:24,node:[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]]};gb.node;var ui=W(gb);var xb={name:"square",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]};xb.node;var Ul=W(xb);var yb={name:"tag",size:24,node:[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]]};yb.node;var Gl=W(yb);var bb={name:"terminal",size:24,node:[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]]};bb.node;var io=W(bb);var wb={name:"text-align-justify",size:24,node:[["path",{d:"M3 5h18",key:"1u36vt"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 19h18",key:"awlh7x"}]],aliases:["align-justify"]};wb.node;var Ns=W(wb);var vb={name:"trash",size:24,node:[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],aliases:["trash-2"]};vb.node;var Nt=W(vb);var kb={name:"triangle-alert",size:24,node:[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],aliases:["alert-triangle"]};kb.node;var ot=W(kb);var Sb={name:"undo-2",size:24,node:[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]};Sb.node;var Ca=W(Sb);var Cb={name:"unfold-vertical",size:24,node:[["path",{d:"M12 22v-6",key:"6o8u61"}],["path",{d:"M12 8V2",key:"1wkif3"}],["path",{d:"M4 12H2",key:"rhcxmi"}],["path",{d:"M10 12H8",key:"s88cx1"}],["path",{d:"M16 12h-2",key:"10asgb"}],["path",{d:"M22 12h-2",key:"14jgyd"}],["path",{d:"m15 19-3 3-3-3",key:"11eu04"}],["path",{d:"m15 5-3-3-3 3",key:"itvq4r"}]]};Cb.node;var Wl=W(Cb);var Ib={name:"unlink",size:24,node:[["path",{d:"m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71",key:"yqzxt4"}],["path",{d:"m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71",key:"4qinb0"}],["line",{x1:"8",x2:"8",y1:"2",y2:"5",key:"1041cp"}],["line",{x1:"2",x2:"5",y1:"8",y2:"8",key:"14m1p5"}],["line",{x1:"16",x2:"16",y1:"19",y2:"22",key:"rzdirn"}],["line",{x1:"19",x2:"22",y1:"16",y2:"16",key:"ox905f"}]]};Ib.node;var zl=W(Ib);var Lb={name:"upload",size:24,node:[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]]};Lb.node;var Ia=W(Lb);var Ab={name:"wand-sparkles",size:24,node:[["path",{d:"m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72",key:"ul74o6"}],["path",{d:"m14 7 3 3",key:"1r5n42"}],["path",{d:"M5 6v4",key:"ilb8ba"}],["path",{d:"M19 14v4",key:"blhpug"}],["path",{d:"M10 2v2",key:"7u0qdc"}],["path",{d:"M7 8H3",key:"zfb6yr"}],["path",{d:"M21 16h-4",key:"1cnmox"}],["path",{d:"M11 3H9",key:"1obp7u"}]],aliases:["wand-2"]};Ab.node;var Rs=W(Ab);var Pb={name:"wrench",size:24,node:[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]]};Pb.node;var ci=W(Pb);var Nb={name:"x",size:24,node:[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]};Nb.node;var Ht=W(Nb);var Rb={name:"zap",size:24,node:[["path",{d:"M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z",key:"1v7up4"}]]};Rb.node;var jl=W(Rb);var Xt=j(ie(),1);function hh(t){let{agentId:e,agentName:n,agentIcon:r,agentAccent:a,supportsSources:s=!0}=t,i=(0,Vl.resolveAgentIcon)(r),o=H(m=>m.toggleSidebar),l=H(m=>m.sidebarOpen),u=H(m=>m.refreshTree),c=H(m=>m.activeProjectId),d=H(m=>m.uploading),f=H(m=>m.workspacePanels),h=H(m=>m.setWorkspacePanelOpen),p=H(m=>m.activeWorkspaceTab),g=H(m=>m.pendingCount);return(0,Xt.jsxs)("div",{className:"h-10 flex items-center px-3 shrink-0 gap-2.5",style:{backgroundColor:"transparent",borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,Xt.jsx)("div",{className:"flex items-center gap-1",children:(0,Xt.jsx)("button",{onClick:o,className:`p-1.5 rounded-lg transition-colors ${l?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white"}`,title:"Toggle Sidebar",children:(0,Xt.jsx)(Ls,{className:"w-4 h-4"})})}),(0,Xt.jsx)("div",{className:"h-4 w-[1px] bg-white/10"}),(0,Xt.jsx)("span",{className:"inline-flex h-6 w-6 shrink-0 items-center justify-center",style:{color:a||"var(--icon-muted)"},title:n||"Agent","aria-label":n||"Agent",children:(0,Xt.jsx)(i,{className:"h-4 w-4"})}),(0,Xt.jsxs)("div",{className:"flex items-center gap-1",children:[(0,Xt.jsx)("button",{onClick:()=>u({agentId:e,projectId:c??null}),className:"p-1.5 rounded-lg text-white/50 hover:bg-white/5 hover:text-white transition-colors",title:"Refresh",children:(0,Xt.jsx)(_t,{className:"w-4 h-4"})}),(0,Xt.jsx)("button",{className:"p-1.5 rounded-lg text-white/50 hover:bg-white/5 hover:text-white transition-colors disabled:opacity-50 disabled:cursor-not-allowed",title:"Upload files",disabled:d,onClick:()=>{if(f.upload&&p==="upload"){h("upload",!1);return}h("upload",!0)},children:d?(0,Xt.jsx)(We,{className:"w-4 h-4 animate-spin"}):(0,Xt.jsx)(Ia,{className:"w-4 h-4"})}),s?(0,Xt.jsx)("button",{className:`p-1.5 rounded-lg transition-colors ${f.sources&&p==="sources"?"bg-cyan-500/15 text-cyan-400":"text-white/50 hover:bg-white/5 hover:text-cyan-300"}`,title:"Data Sources & Sync",onClick:()=>{if(f.sources&&p==="sources"){h("sources",!1);return}h("sources",!0)},children:(0,Xt.jsx)(ir,{className:"w-4 h-4"})}):null,s?(0,Xt.jsx)(Vl.SkillLauncher,{variant:"icon",size:"sm",skill:"sync",packageId:"@neuralis/brain-core",label:"Sync sources with the agent",icon:"brain"}):null,(0,Xt.jsx)(Vl.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-files",packageId:"@neuralis/brain-core",scripts:["scripts/mkdir.sh","scripts/copy.sh","scripts/modify.sh","scripts/search.sh"],label:"Create, copy, edit or search files with the agent",icon:"Folder"}),(0,Xt.jsx)("button",{className:`p-1.5 rounded-lg transition-colors ${f.packages&&p==="packages"?"bg-violet-500/15 text-violet-300":"text-white/50 hover:bg-white/5 hover:text-violet-200"}`,title:"Packages \u2014 trust & build",onClick:()=>{if(f.packages&&p==="packages"){h("packages",!1);return}h("packages",!0)},children:(0,Xt.jsx)(wr,{className:"w-4 h-4"})}),(0,Xt.jsxs)("button",{className:`relative p-1.5 rounded-lg transition-colors ${f.pending&&p==="pending"?"bg-amber-500/15 text-amber-300":"text-white/50 hover:bg-white/5 hover:text-amber-200"}`,title:g>0?`Pending changes \u2014 ${g} to review`:"Pending changes \u2014 review, approve & revert",onClick:()=>{if(f.pending&&p==="pending"){h("pending",!1);return}h("pending",!0)},children:[(0,Xt.jsx)(Ka,{className:"w-4 h-4"}),g>0?(0,Xt.jsx)("span",{"data-testid":"pending-count-badge",className:"absolute -top-1 -right-1 min-w-[14px] rounded-full px-1 text-center text-[9px] leading-[14px] font-semibold bg-amber-500/15 text-amber-300",children:g>=1e3?"1000+":g}):null]})]})]})}var _e=j($e(),1),F1=j(Wn(),1);function Ja(t,e){let n=t.grantedFeatures;return n?n.includes("*")||n.includes(e):!1}function oo(t,e){let n=e?.features;return!n||n.length===0?!0:n.every(r=>Ja(t,r))}var ph={owner:1,admin:2,manager:10,member:20,viewer:30};var lA=ph.member,Db=Number.MAX_SAFE_INTEGER;var ra=j($e(),1),Vb=j(Za(),1);function Bb(t){return typeof t=="object"?t.key:t}function _b(t,e){let n=t.length;return new Proxy(t,{get(r,a,s){if(typeof a=="string"){let i=a.charCodeAt(0);if(i>=48&&i<=57){let o=+a;if(Number.isInteger(o)&&o>=0&&o<n){let l=r[o];if(typeof l!="object"){let u=e[o*2];l=r[o]={index:o,key:l,start:u,size:e[o*2+1],end:u+e[o*2+1],lane:0}}return l}}if(a==="length")return n}return Reflect.get(r,a,s)}})}function di(t,e,n){let r=n.initialDeps??[],a,s=!0;function i(){var o;let u=0,c=t();if(!(c.length!==r.length||c.some((h,p)=>r[p]!==h)))return a;r=c;let f=0;return a=e(...c),n?.onChange&&!(s&&n.skipInitialOnChange)&&n.onChange(a),s=!1,a}return i.updateDeps=o=>{r=o},i}function gh(t,e){if(t===void 0)throw new Error(`Unexpected undefined${e?`: ${e}`:""}`);return t}var xh=(t,e)=>Math.abs(t-e)<1.01,Hb=(t,e,n)=>{let r;return Object.assign(function(...a){t.clearTimeout(r),r=t.setTimeout(()=>e.apply(this,a),n)},{cancel:()=>{t.clearTimeout(r)}})};var ql,yh=()=>{if(ql!==void 0)return ql;if(typeof navigator>"u")return ql=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return ql=!0;let t=navigator.maxTouchPoints;return ql=navigator.platform==="MacIntel"&&t!==void 0&&t>0};var Ub=t=>{let{offsetWidth:e,offsetHeight:n}=t;return{width:e,height:n}},mA=t=>t,gA=t=>{let e=Math.max(t.startIndex-t.overscan,0),r=Math.min(t.endIndex+t.overscan,t.count-1)-e+1,a=new Array(r);for(let s=0;s<r;s++)a[s]=e+s;return a},Gb=(t,e)=>{let n=t.scrollElement;if(!n)return;let r=t.targetWindow;if(!r)return;let a=i=>{let{width:o,height:l}=i;e({width:Math.round(o),height:Math.round(l)})};if(a(Ub(n)),!r.ResizeObserver)return()=>{};let s=new r.ResizeObserver(i=>{let o=()=>{let l=i[0];if(l?.borderBoxSize){let u=l.borderBoxSize[0];if(u){a({width:u.inlineSize,height:u.blockSize});return}}a(Ub(n))};t.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(o):o()});return s.observe(n,{box:"border-box"}),()=>{s.unobserve(n)}},kc={passive:!0};var xA=typeof window>"u"?!0:"onscrollend"in window,yA=(t,e,n)=>{let r=t.scrollElement;if(!r)return;let a=t.targetWindow;if(!a)return;let s=t.options.useScrollendEvent&&xA,i=0,o=s?null:Hb(a,()=>e(n(r),!1),t.options.isScrollingResetDelay),l=d=>()=>{i=n(r),o?.(),e(i,d)},u=l(!0),c=l(!1);return r.addEventListener("scroll",u,kc),s&&r.addEventListener("scrollend",c,kc),()=>{r.removeEventListener("scroll",u),s&&r.removeEventListener("scrollend",c),o?.cancel()}},Wb=(t,e)=>yA(t,e,n=>{let{horizontal:r,isRtl:a}=t.options;return r?n.scrollLeft*(a&&-1||1):n.scrollTop});var bA=(t,e,n)=>{if(n.options.useCachedMeasurements){let r=n.indexFromElement(t),a=n.options.getItemKey(r);return n.itemSizeCache.get(a)??n.options.estimateSize(r)}if(e?.borderBoxSize){let r=e.borderBoxSize[0];if(r)return Math.round(r[n.options.horizontal?"inlineSize":"blockSize"])}if(!e){let r=n.indexFromElement(t),a=n.options.getItemKey(r),s=n.itemSizeCache.get(a);if(s!==void 0)return s}return t[n.options.horizontal?"offsetWidth":"offsetHeight"]},wA=(t,{adjustments:e=0,behavior:n},r)=>{var a,s;(s=(a=r.scrollElement)==null?void 0:a.scrollTo)==null||s.call(a,{[r.options.horizontal?"left":"top"]:t+e,behavior:n})};var zb=wA;function vA(t,e,n,r){if(e===0)return!1;let a=r(0),s=new Set,i=0;for(;i<t;){let l=n(i);if(l===a)break;s.add(l),i++}let o=t-i;if(o===0||o>=e)return!1;for(let l=0;l<o;l++)if(r(l)!==n(i+l))return!1;for(let l=o;l<e;l++)if(s.has(r(l)))return!1;return!0}var Sc=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.now=()=>{var n,r,a;return((a=(r=(n=this.targetWindow)==null?void 0:n.performance)==null?void 0:r.now)==null?void 0:a.call(r))??Date.now()},this.observer=(()=>{let n=null,r=()=>n||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:n=new this.targetWindow.ResizeObserver(a=>{a.forEach(s=>{let i=()=>{let o=s.target,l=this.indexFromElement(o);if(!o.isConnected){this.observer.unobserve(o);for(let[u,c]of this.elementsCache)if(c===o){this.elementsCache.delete(u);break}return}this.isIndexInRange(l)&&this.shouldMeasureDuringScroll(l)&&this.resizeItem(l,this.options.measureElement(o,s,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(i):i()})}));return{disconnect:()=>{var a;(a=r())==null||a.disconnect(),n=null},observe:a=>{var s;return(s=r())==null?void 0:s.observe(a,{box:"border-box"})},unobserve:a=>{var s;return(s=r())==null?void 0:s.unobserve(a)}}})(),this.range=null,this.setOptions=n=>{var r;let a={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:mA,rangeExtractor:gA,onChange:()=>{},measureElement:bA,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 d in n){let f=n[d];f!==void 0&&(a[d]=f)}let s=this.options,i=null,o=null,l=!1;if(s!==void 0&&s.enabled&&a.enabled&&a.anchorTo==="end"&&this.scrollElement!==null){let d=s.count,f=a.count,h=this.getMeasurements(),p=((r=this._singleLaneMeasurements)==null?void 0:r.items)??h,g=C=>Bb(p[C]),m=d>0?g(0):null,x=d>0?g(d-1):null;if(f!==d||d>0&&f>0&&(a.getItemKey(0)!==m||a.getItemKey(f-1)!==x)){l=!0;let C=d>0?this.getVirtualItemForOffset(this.getScrollOffset())??h[0]:null;C&&(i=[C.key,this.getScrollOffset()-C.start]);let L=a.followOnAppend===!0?"auto":a.followOnAppend||null;L&&f>0&&this.isAtEnd(s.scrollEndThreshold)&&(d===0||a.getItemKey(f-1)!==x)&&(f>d||vA(d,f,g,a.getItemKey))&&(o=L)}}this.options=a,l&&(this.pendingMin=0,this.itemSizeCacheVersion++);let u=!1,c=0;if(i&&this.scrollOffset!==null){let[d,f]=i,h=this.getMeasurements(),{count:p,getItemKey:g}=this.options,m=0;for(;m<p&&g(m)!==d;)m++;if(m<p){let x=h[m];if(x){let y=Math.max(0,x.start+f);!o&&y!==this.scrollOffset&&(c=y-this.scrollOffset,this.scrollOffset=y,u=!0)}}}(u||o)&&(this.pendingScrollAnchor=[u?i[0]:null,u?i[1]:0,o,c])},this.notify=n=>{var r,a;(a=(r=this.options).onChange)==null||a.call(r,this,n)},this.maybeNotify=di(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),n=>{this.notify(n)},{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(n=>n()),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=()=>{var n,r;let a=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==a){if(this.cleanup(),!a){this.maybeNotify();return}if(this.scrollElement=a,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((n=this.scrollElement)==null?void 0:n.window)??null,this.elementsCache.forEach(i=>{this.observer.observe(i)}),this.unsubs.push(this.options.observeElementRect(this,i=>{this.scrollRect=i,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(i,o)=>{if(o&&this._intendedScrollOffset===null&&i===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(i-this._intendedScrollOffset)<1.5&&(i=this._intendedScrollOffset),this._intendedScrollOffset=null,this._clampedAdjustment!==null&&Math.abs(i-this._clampedAdjustment.maxAtWrite)>=1.5&&(this._clampedAdjustment=null),this.scrollAdjustments=0;let l=this.getScrollOffset();this.scrollDirection=o?l===i?this.scrollDirection:l<i?"forward":"backward":null,this.scrollOffset=i,this.isScrolling=o,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){let i=this.scrollElement,o=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},l=()=>{this._iosTouching=!1,!(!yh()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};i.addEventListener("touchstart",o,kc),i.addEventListener("touchend",l,kc),this.unsubs.push(()=>{i.removeEventListener("touchstart",o),i.removeEventListener("touchend",l),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 s=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,s&&this.scrollElement&&this.options.enabled){let[i,o,l,u]=s;i!==null&&!l&&(yh()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?u!==0&&(this._iosDeferredAdjustment+=u):((r=this.scrollState)==null?void 0:r.behavior)==="smooth"&&!xh(this.getScrollOffset()-u,this.scrollState.lastTargetOffset)||this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),l&&this.scrollToEnd({behavior:l})}this._retryClampedAdjustment()},this._retryClampedAdjustment=()=>{if(this._clampedAdjustment===null||!this.scrollElement||!this.options.enabled)return;let{target:n,maxAtWrite:r}=this._clampedAdjustment,a=this.getMaxScrollOffset();a>r+.5&&(this._clampedAdjustment=n>a+.5?{target:n,maxAtWrite:a}:null,this._scrollToOffset(n,{adjustments:void 0,behavior:void 0}))},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;let n=this.getScrollOffset(),r=this.getMaxScrollOffset();if(n<0||n>r)return;if(this._iosDeferredAdjustment<0&&n>=r-1){this._iosDeferredAdjustment=0;return}let a=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(n,{adjustments:this.scrollAdjustments+=a,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=di(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(n,r,a,s,i,o,l,u)=>(this.prevLanes!==void 0&&this.prevLanes!==o&&(this.lanesChangedFlag=!0),this.prevLanes=o,this.pendingMin=null,{count:n,paddingStart:r,scrollMargin:a,getItemKey:s,enabled:i,lanes:o,laneAssignmentMode:l,gap:u}),{key:!1}),this.isIndexInRange=n=>n>=0&&n<this.options.count,this.getMeasurements=di(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:n,paddingStart:r,scrollMargin:a,getItemKey:s,enabled:i,lanes:o,laneAssignmentMode:l,gap:u},c)=>{var d;let f=this.itemSizeCache;if(!i)return this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>n)for(let y of this.laneAssignments.keys())y>=n&&this.laneAssignments.delete(y);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(y=>{this.itemSizeCache.set(y.key,y.size)}));let h=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===n&&(this.lanesSettling=!1),o===1){let y=n*2,b=(d=this._singleLaneMeasurements)==null?void 0:d.flat;if(!b||b.length<y){let w=new Float64Array(y);b&&h>0&&w.set(b.subarray(0,h*2)),b=w}let C=h===0?new Array(n):this._singleLaneMeasurements.items.slice(),L;if(h===0)L=r+a;else{let w=h-1;L=b[w*2]+b[w*2+1]+u}for(let w=h;w<n;w++){let k=s(w);C[w]=k;let _=f.get(k),M=typeof _=="number"?_:this.options.estimateSize(w);b[w*2]=L,b[w*2+1]=M,L+=M+u}this._singleLaneMeasurements={flat:b,items:C};let P=_b(C,b);return this.measurementsCache=P,P}let p=this.measurementsCache.slice(0,h),g=new Array(o).fill(void 0),m=new Float64Array(o),x=0;for(let y=0;y<h;y++){let b=p[y];b&&(g[b.lane]===void 0&&x++,g[b.lane]=y,m[b.lane]=b.end)}for(let y=h;y<n;y++){let b=s(y),C=this.laneAssignments.get(y),L,P,w=l==="estimate"||f.has(b);if(C!==void 0&&this.options.lanes>1){L=C;let R=g[L],U=R!==void 0?p[R]:void 0;P=U?U.end+u:r+a}else if(x===o){let R=0,U=m[0],v=g[0];for(let T=1;T<o;T++){let V=m[T];(V<U||V===U&&g[T]<v)&&(R=T,U=V,v=g[T])}L=R,P=U+u,w&&this.laneAssignments.set(y,L)}else L=y%this.options.lanes,P=r+a,w&&this.laneAssignments.set(y,L);let k=f.get(b),_=typeof k=="number"?k:this.options.estimateSize(y),M=P+_;p[y]={index:y,start:P,size:_,end:M,key:b,lane:L},g[L]===void 0&&x++,g[L]=y,m[L]=M}return this.measurementsCache=p,p},{key:!1,debug:()=>this.options.debug}),this.calculateRange=di(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,a,s)=>n.length===0||r===0?(this.range=null,null):(this.range=SA(n,r,a,s,s===1&&this._singleLaneMeasurements!==null?this._singleLaneMeasurements.flat:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=di(()=>{let n=null,r=null,a=this.calculateRange();return a&&(n=a.startIndex,r=a.endIndex),this.maybeNotify.updateDeps([this.isScrolling,n,r]),[this.options.rangeExtractor,this.options.overscan,this.options.count,n,r]},(n,r,a,s,i)=>s===null||i===null?[]:n({startIndex:s,endIndex:i,overscan:r,count:a}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=n=>{let r=this.options.indexAttribute,a=n.getAttribute(r);return a?parseInt(a,10):(console.warn(`Missing attribute name '${r}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=n=>{var r;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;let a=this.scrollState.index??((r=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:r.index);if(a!==void 0&&this.range){let s=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),i=Math.max(0,a-s),o=Math.min(this.options.count-1,a+s);return n>=i&&n<=o}return!0},this.measureElement=n=>{if(!n){this.elementsCache.forEach((i,o)=>{i.isConnected||(this.observer.unobserve(i),this.elementsCache.delete(o))});return}let r=this.indexFromElement(n);if(!this.isIndexInRange(r))return;let a=this.options.getItemKey(r),s=this.elementsCache.get(a);s!==n&&(s&&this.observer.unobserve(s),this.observer.observe(n),this.elementsCache.set(a,n)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(r)&&this.resizeItem(r,this.options.measureElement(n,void 0,this))},this.resizeItem=(n,r)=>{var a,s,i;if(!this.isIndexInRange(n))return;let o,l,u,c=(a=this._singleLaneMeasurements)==null?void 0:a.flat;if(this.options.lanes===1&&c!=null)u=this.options.getItemKey(n),l=c[n*2],o=c[n*2+1];else{let h=this.measurementsCache[n];if(!h)return;u=h.key,l=h.start,o=h.size}let d=this.itemSizeCache.get(u)??o,f=r-d;if(f!==0){let h=this.options.anchorTo==="end"&&((s=this.scrollState)==null?void 0:s.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,p=h?this.getTotalSize():0,g=this.getScrollOffset()+this.scrollAdjustments,x=!this.itemSizeCache.has(u)?l<g:l+d<=g&&this.scrollDirection!=="backward",y=((i=this.scrollState)==null?void 0:i.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[n]??{index:n,key:u,start:l,size:o,end:l+o,lane:0},f,this):x);(this.pendingMin===null||n<this.pendingMin)&&(this.pendingMin=n),this.itemSizeCache.set(u,r),this.itemSizeCacheVersion++;let b=!1;h?b=this.applyScrollAdjustment(this.getTotalSize()-p):y&&(b=this.applyScrollAdjustment(f)),this.notify(b),this._retryClampedAdjustment()}},this.getVirtualItems=di(()=>[this.getVirtualIndexes(),this.getMeasurements()],(n,r)=>{let a=[];for(let s=0,i=n.length;s<i;s++){let o=n[s],l=r[o];a.push(l)}return a},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=n=>{var r;let a=this.getMeasurements();if(a.length===0)return;let s=(r=this._singleLaneMeasurements)==null?void 0:r.flat,i=this.options.lanes===1&&s!=null,o=jb(0,a.length-1,i?l=>s[l*2]:l=>gh(a[l]).start,n);return gh(a[o])},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 n=this.scrollElement.document.documentElement;return this.options.horizontal?n.scrollWidth-this.scrollElement.innerWidth:n.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=(n=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=n,this.getOffsetForAlignment=(n,r,a=0)=>{if(!this.scrollElement)return 0;let s=this.getSize(),i=this.getScrollOffset();r==="auto"&&(r=n>=i+s?"end":"start"),r==="center"?n+=(a-s)/2:r==="end"&&(n-=s);let o=this.getMaxScrollOffset();return Math.max(Math.min(o,n),0)},this.getOffsetForIndex=(n,r="auto")=>{n=Math.max(0,Math.min(n,this.options.count-1));let a=this.getSize(),s=this.getScrollOffset(),i=this.measurementsCache[n];if(!i)return;if(r==="auto")if(i.end>=s+a-this.options.scrollPaddingEnd)r="end";else if(i.start<=s+this.options.scrollPaddingStart)r="start";else return[s,r];if(r==="end"&&n===this.options.count-1)return[this.getMaxScrollOffset(),r];let o=r==="end"?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(o,r,i.size),r]},this.scrollToOffset=(n,{align:r="start",behavior:a="auto"}={})=>{this._iosDeferredAdjustment=0;let s=this.getOffsetForAlignment(n,r),i=this.now();this.scrollState={index:null,align:r,behavior:a,startedAt:i,lastTargetOffset:s,stableFrames:0},this._scrollToOffset(s,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollToIndex=(n,{align:r="auto",behavior:a="auto"}={})=>{this._iosDeferredAdjustment=0,n=Math.max(0,Math.min(n,this.options.count-1));let s=this.getOffsetForIndex(n,r);if(!s)return;let[i,o]=s,l=this.now();this.scrollState={index:n,align:o,behavior:a,startedAt:l,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollBy=(n,{behavior:r="auto"}={})=>{let a=this.getScrollOffset()+n,s=this.now();this.scrollState={index:null,align:"start",behavior:r,startedAt:s,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:r}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:n="auto"}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:"end",behavior:n});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:n})},this.getTotalSize=()=>{var n,r;let a=this.getMeasurements(),s;if(a.length===0)s=this.options.paddingStart;else if(this.options.lanes===1){let i=a.length-1,o=(n=this._singleLaneMeasurements)==null?void 0:n.flat;o!=null?s=o[i*2]+o[i*2+1]:s=((r=a[i])==null?void 0:r.end)??0}else{let i=Array(this.options.lanes).fill(null),o=a.length-1;for(;o>=0&&i.some(l=>l===null);){let l=a[o];i[l.lane]===null&&(i[l.lane]=l.end),o--}s=Math.max(...i.filter(l=>l!==null))}return Math.max(s-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{let n=[];if(this.itemSizeCache.size===0)return n;let r=this.getMeasurements();for(let a of r)a&&this.itemSizeCache.has(a.key)&&n.push({index:a.index,key:a.key,start:a.start,size:a.size,end:a.end,lane:a.lane});return n},this._scrollToOffset=(n,{adjustments:r,behavior:a})=>{this._intendedScrollOffset=n+(r??0),this.options.scrollToFn(n,{behavior:a,adjustments:r},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(e)}applyScrollAdjustment(e,n){if(e===0)return!1;if(yh()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded))return this._iosDeferredAdjustment+=e,!1;{let r=this.getScrollOffset()+this.scrollAdjustments+e,a=this.scrollElement,s=a!==null&&("scrollHeight"in a||"document"in a)?this.getMaxScrollOffset():null;return this._clampedAdjustment=s!==null&&r>s+.5?{target:r,maxAtWrite:s}:null,this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=e,behavior:n}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollOffset<0&&(this.scrollOffset=0),this.scrollAdjustments=0),!0}}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}let r=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,a=r?r[0]:this.scrollState.lastTargetOffset,s=1,i=a!==this.scrollState.lastTargetOffset;if(!i&&xh(a,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=s){this.getScrollOffset()!==a&&this._scrollToOffset(a,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,i){let o=this.getSize()||600,l=Math.abs(a-this.getScrollOffset()),u=this.scrollState.behavior==="smooth"&&l>o;this.scrollState.lastTargetOffset=a,u||(this.scrollState.behavior="auto"),this._scrollToOffset(a,{adjustments:void 0,behavior:u?"smooth":"auto"})}this.scheduleScrollReconcile()}},jb=(t,e,n,r)=>{for(;t<=e;){let a=(t+e)/2|0,s=n(a);if(s<r)t=a+1;else if(s>r)e=a-1;else return a}return t>0?t-1:0};function kA(t,e,n){let r=0;for(;r<=e;){let a=(r+e)/2|0,s=t[a*2];if(s<n)r=a+1;else if(s>n)e=a-1;else return a}return r>0?r-1:0}function SA(t,e,n,r,a){let s=t.length-1;if(t.length<=r)return{startIndex:0,endIndex:s};if(r===1&&a!==null){let u=kA(a,s,n),c=u,d=n+e;for(;c<s&&a[c*2]+a[c*2+1]<d;)c++;return{startIndex:u,endIndex:c}}let o=jb(0,s,u=>t[u].start,n),l=o;if(r===1)for(;l<s&&t[l].end<n+e;)l++;else if(r>1){let u=Array(r).fill(0);for(;l<s&&u.some(d=>d<n+e);){let d=t[l];u[d.lane]=d.end,l++}let c=Array(r).fill(n+e);for(;o>=0&&c.some(d=>d>=n);){let d=t[o];c[d.lane]=d.start,o--}o=Math.max(0,o-o%r),l=Math.min(s,l+(r-1-l%r))}return{startIndex:o,endIndex:l}}var bh=typeof document<"u"?ra.useLayoutEffect:ra.useEffect;function CA({useFlushSync:t=!0,directDomUpdates:e=!1,directDomUpdatesMode:n="transform",...r}){let a=ra.useReducer(d=>d+1,0)[1],s=ra.useRef({enabled:e,mode:n,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});s.current.enabled=e,s.current.mode=n;let i=ra.useRef(!1),o=d=>{let f=s.current;if(!f.enabled||!f.container)return;let h=d.getTotalSize();if(h!==f.lastSize){f.lastSize=h;let p=d.options.horizontal?"width":"height";f.container.style[p]=`${h}px`}},l=d=>{let f=s.current;if(!f.enabled||!f.container)return;o(d);let h=!!d.options.horizontal,p=f.mode==="transform",g=h?"left":"top",m=d.options.scrollMargin,x=d.getVirtualItems();for(let y of x){let b=y.start-m,C=d.elementsCache.get(y.key);C&&f.lastPositions.get(C)!==b&&(f.lastPositions.set(C,b),p?C.style.transform=h?`translate3d(${b}px, 0, 0)`:`translate3d(0, ${b}px, 0)`:C.style[g]=`${b}px`)}},u={...r,onChange:(d,f)=>{var h;let p=s.current,g=!0;if(p.enabled){l(d);let m=d.range,x=p.prevRange;g=!x||x.isScrolling!==d.isScrolling||x.startIndex!==m?.startIndex||x.endIndex!==m?.endIndex,g&&(p.prevRange=m?{startIndex:m.startIndex,endIndex:m.endIndex,isScrolling:d.isScrolling}:null)}g&&(t&&f&&!i.current?(0,Vb.flushSync)(a):a()),(h=r.onChange)==null||h.call(r,d,f)}},[c]=ra.useState(()=>{let d=new Sc(u),f=d.measureElement;return d.measureElement=h=>{i.current=!0;try{f(h)}finally{i.current=!1}},Object.assign(d,{containerRef:h=>{let p=s.current;if(p.container=h,p.lastSize=null,h&&p.enabled){let g=d.getTotalSize();p.lastSize=g;let m=d.options.horizontal?"width":"height";h.style[m]=`${g}px`}}})});return c.setOptions(u),bh(()=>c._didMount(),[]),bh(()=>(o(c),c._willUpdate())),bh(()=>{l(c)}),c}function lo(t){return CA({observeElementRect:Gb,observeElementOffset:Wb,scrollToFn:zb,...t})}var Qa=j($e(),1);function qb(t){let e=H(u=>u.client),{agentId:n,projectId:r,enabled:a}=t,[s,i]=(0,Qa.useState)([]),o=(0,Qa.useRef)(!0);(0,Qa.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let l=(0,Qa.useRef)(!1);return(0,Qa.useEffect)(()=>{l.current=!1,i([])},[n,r]),(0,Qa.useEffect)(()=>{!n||!a||l.current||(l.current=!0,ic({agentId:n,...r?{projectId:r}:{}},e).then(u=>{o.current&&i(u.suggestions??[])}).catch(()=>{o.current&&i([])}))},[n,r,a,e]),s}var Lc=j($e(),1);var lr=j(Wn(),1);var La=j(ie(),1);function IA({className:t}){return(0,La.jsxs)("svg",{viewBox:"0 0 64 64",className:t,"aria-hidden":"true",children:[(0,La.jsx)("path",{d:"M10 52L24 28L36 36L52 12",fill:"none",stroke:"currentColor",strokeWidth:"3.5",strokeLinecap:"round",strokeLinejoin:"round"}),(0,La.jsx)("circle",{cx:"10",cy:"52",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"}),(0,La.jsx)("circle",{cx:"24",cy:"28",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"}),(0,La.jsx)("circle",{cx:"36",cy:"36",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"}),(0,La.jsx)("circle",{cx:"52",cy:"12",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"})]})}function LA(t){if(!t)return"aged";let e=Date.parse(t);if(!Number.isFinite(e))return"aged";let n=Math.max(0,(Date.now()-e)/6e4);return n<=15?"fresh":n<=180?"recent":n<=1440?"aged":"stale"}function fi(t){switch(LA(t)){case"fresh":return{pillClassName:"border-emerald-400/25 bg-emerald-500/14 text-emerald-100",iconClassName:"text-emerald-300/85",label:"Changed just now"};case"recent":return{pillClassName:"border-amber-400/22 bg-amber-500/10 text-amber-100/92",iconClassName:"text-amber-300/76",label:"Changed recently"};case"aged":return{pillClassName:"border-white/10 bg-white/[0.05] text-white/60",iconClassName:"text-white/40",label:"Older change"};default:return{pillClassName:"border-rose-400/18 bg-rose-500/10 text-rose-100/80",iconClassName:"text-rose-300/70",label:"Older indexed change"}}}function $l(t){let e=t.status==="deleted",n=t.status==="pending_review",r=t.status==="pinned";return e?{tone:"text-red-100/70",iconTone:"text-red-300/70",secondaryTone:"text-red-200/60",highlightTone:"bg-red-500/12",icon:xs,label:"Deleted",title:"Marked as deleted",ghosted:!0}:n?{tone:"text-amber-50/95",iconTone:"text-amber-300/85",secondaryTone:"text-amber-200/75",highlightTone:"bg-amber-500/10",icon:ot,label:"Review pending",title:"Pending review before approval"}:t.presence==="brain"?{tone:"text-violet-50/92",iconTone:"text-violet-300/80",secondaryTone:"text-violet-200/68",highlightTone:"bg-violet-500/10",icon:ir,label:"Brain node",title:"Stored in brain index"}:t.presence==="stale_indexed"?{tone:"text-rose-100/78",iconTone:"text-rose-300/75",secondaryTone:"text-rose-200/65",highlightTone:"bg-rose-500/8",icon:Ya,label:"Missing from disk",title:"Indexed but not found in live source",ghosted:!0}:t.presence==="unindexed"?{tone:"text-white/55",iconTone:"text-white/70",secondaryTone:"text-white/45",highlightTone:"bg-white/[0.04]",icon:Xa,label:"Unindexed",title:"Connector entry not vector-indexed yet"}:r?{tone:"text-white/82",iconTone:"text-amber-200/80",secondaryTone:"text-amber-100/65",highlightTone:"bg-amber-500/8",icon:ii,label:"Pinned",title:"Pinned item"}:t.presence==="synced"?{tone:"text-white",iconTone:"text-sky-300/80",secondaryTone:"text-white/82",highlightTone:"bg-sky-500/10",icon:IA,label:"Synced",title:"Indexed and present on the connector"}:{tone:"text-white/72",iconTone:"text-white/48",secondaryTone:"text-white/48",highlightTone:"bg-white/[0.04]",icon:wa,label:"Neutral",title:"File entry"}}function $b(t){return t?Is:Tr}function Kb(t){let n=[$l(t).label];return t.version?.changedAt&&n.push(fi(t.version.changedAt).label),t.status==="pinned"&&n.push("Pinned"),n}function Cc(t){return{iconClassName:"text-white/35",labelClassName:"text-white/45",detailClassName:"text-white/30",containerClassName:"opacity-55",title:t==="disabled"?"Source disabled in this scope \u2014 toggle in the Sources panel.":"Source discovered but not yet attached \u2014 click to add."}}function Ic(t){let e=t.enabled===!1,n=t.enabled==="auto"&&t.enabled_effective===!1;return e||n?{iconClassName:"text-white/35",labelClassName:"text-white/45",detailClassName:"text-white/30"}:t.live===!1?{iconClassName:"text-white/35",labelClassName:"text-white/45",detailClassName:"text-white/30"}:t.sync_status==="error"?{iconClassName:"text-rose-300/80",labelClassName:"text-rose-50/92",detailClassName:"text-rose-200/65"}:t.sync_status==="paused"?{iconClassName:"text-amber-300/80",labelClassName:"text-amber-50/90",detailClassName:"text-amber-200/65"}:t.sync_status==="active"?{iconClassName:"text-sky-300/80",labelClassName:"text-sky-50/90",detailClassName:"text-sky-200/62"}:t.source_kind==="brain"?{iconClassName:"text-violet-300/85",labelClassName:"text-violet-50/92",detailClassName:"text-violet-200/60"}:{iconClassName:"text-white/80",labelClassName:"text-white/90",detailClassName:"text-white/55"}}var AA={runtime_offline:"Machine offline \u2014 container not running",fs_unreachable:"Filesystem unreachable \u2014 mount missing",fs_permission:"Filesystem unreadable \u2014 permission denied",store_unreachable:"Store offline \u2014 backing service unreachable"};function wh(t){return(t?AA[t]:void 0)??"Disconnected \u2014 connector cannot reach its backing filesystem"}function Xb(t){return t.enabled===!1?"Source disabled":t.enabled==="auto"&&t.enabled_effective===!1?"Source auto \u2014 currently stopped":t.live===!1?wh(t.live_reason):t.sync_status==="error"?t.last_error??"Sync error":t.sync_status==="paused"?"Sync paused":t.sync_status==="active"?"Sync active":null}function vh(t){if(!t)return null;let e=Date.parse(t);if(!Number.isFinite(e))return null;let n=Math.max(0,Math.round((Date.now()-e)/6e4));if(n<1)return"now";if(n<60)return`${n}m`;let r=Math.round(n/60);return r<24?`${r}h`:`${Math.round(r/24)}d`}function Yb({className:t,title:e}){return(0,La.jsx)("span",{title:e,className:"inline-flex",children:(0,La.jsx)(or,{className:t})})}function $(...t){return t.filter(Boolean).join(" ")}var Qn=j(ie(),1),PA=5,Jb=28;function Zb({suggestions:t,expanded:e,onToggleExpanded:n,onPick:r,overlay:a}){return t.length===0?null:(0,Qn.jsxs)("div",{className:$("group/discover shrink-0 border-t border-white/[0.06] bg-[#0b0b0f]/95",a?"absolute inset-x-0 bottom-0 z-20 shadow-[0_-8px_24px_rgba(0,0,0,0.45)]":""),"data-testid":"discover-dock",children:[(0,Qn.jsxs)("div",{className:"flex items-center justify-between px-2 pt-1.5 pb-1",children:[(0,Qn.jsx)("span",{className:"text-[10px] font-bold uppercase tracking-wider text-white/40",children:"Discover"}),(0,Qn.jsx)("button",{type:"button",onClick:n,className:"inline-flex h-4 w-4 items-center justify-center rounded text-white/40 opacity-0 transition-opacity hover:text-white/70 focus-visible:opacity-100 group-hover/discover:opacity-60",title:e?"Collapse discoverable sources":"Show all discoverable sources","aria-label":e?"Collapse discoverable sources":"Show all discoverable sources","aria-expanded":e,children:e?(0,Qn.jsx)(Et,{className:"h-3 w-3"}):(0,Qn.jsx)(qa,{className:"h-3 w-3"})})]}),(0,Qn.jsx)("ul",{className:"overlay-scroll overflow-y-auto pb-1",style:{maxHeight:e?"60vh":PA*Jb},children:t.map(s=>(0,Qn.jsx)(NA,{suggestion:s,onPick:r},s.id))})]})}var NA=Lc.default.memo(function({suggestion:e,onPick:n}){let r=Cc("unattached"),a=(0,lr.resolveLucideIcon)(e.icon??null)??zn,s=(0,Lc.useCallback)(()=>n(e),[n,e]),i=[e.description,e.root].filter(Boolean).join(`
|
|
3
|
-
`);return(0,
|
|
4
|
-
${ze}`:""}`,"aria-label":`${e.name} \u2014 ${ze}`,children:[(0,rn.jsx)("span",{className:"shrink-0 text-white/40",children:v?i?(0,rn.jsx)(Et,{className:"w-3.5 h-3.5"}):(0,rn.jsx)(un,{className:"w-3.5 h-3.5"}):(0,rn.jsx)("span",{className:"w-3.5 h-3.5 inline-block"})}),v?(0,rn.jsx)("span",{title:te.title,children:(0,rn.jsx)(Ee,{className:$("w-4 h-4 shrink-0",te.iconTone),style:{color:e.presence==="brain"&&K||void 0}})}):(0,rn.jsx)(OA,{uri:e.uri,tone:te.iconTone,title:te.title}),k?(0,rn.jsx)(BA,{initial:e.name,onCommit:Le=>R?.({node:e,newName:Le}),onCancel:()=>U?.()}):(0,rn.jsx)("span",{className:$("min-w-0 text-xs truncate flex-1 transition-colors",te.tone,te.ghosted&&"opacity-70",T&&"line-through"),children:e.name}),ct?(0,rn.jsxs)("span",{className:"ml-1 shrink-0 flex items-center justify-end gap-1",children:[V?(0,rn.jsx)("span",{title:"Pending review",className:"shrink-0 flex items-center",children:(0,rn.jsx)(sw.LivePulseDot,{className:"text-amber-400/80 shrink-0"})}):null,Se?(0,rn.jsx)("span",{className:$("w-1.5 h-1.5 rounded-full shrink-0",c?.kind==="new"?"bg-emerald-400":"bg-blue-400"),title:c?.kind==="new"?"New file":"Modified"}):null,le&&e.git?(0,rn.jsx)(Ac,{code:e.git,dot:v}):null,ne?(0,rn.jsx)(Yb,{className:$("w-3.5 h-3.5 shrink-0",re.iconClassName),title:re.label}):null,pe?(0,rn.jsx)("span",{className:$("inline-flex items-center justify-center min-w-[16px] h-4 px-1 rounded-full text-[9px] font-semibold",L?"bg-amber-500/20 text-amber-200":"bg-sky-500/15 text-sky-200"),children:o}):null]}):null]})});function BA({initial:t,onCommit:e,onCancel:n}){let r=(0,vr.useRef)(!1);return(0,rn.jsx)("input",{autoFocus:!0,defaultValue:t,spellCheck:!1,onFocus:a=>{let s=a.currentTarget.value,i=s.lastIndexOf(".");a.currentTarget.setSelectionRange(0,i>0?i:s.length)},onClick:a=>a.stopPropagation(),onMouseDown:a=>a.stopPropagation(),onKeyDown:a=>{a.stopPropagation(),a.key==="Enter"?r.current||(r.current=!0,e(a.currentTarget.value)):a.key==="Escape"&&(r.current||(r.current=!0,n()))},onBlur:a=>{r.current||(r.current=!0,e(a.currentTarget.value))},className:"min-w-0 flex-1 rounded border border-sky-400/60 bg-black/50 px-1 py-0 text-xs text-white outline-none"})}var Ds=j($e(),1),ow=j(Za(),1);var Ts=j(ie(),1),_A=[{kind:"item",action:"new-file",label:"New File\u2026",Icon:Cs},{kind:"item",action:"new-folder",label:"New Folder\u2026",Icon:br},{kind:"sep"},{kind:"item",action:"cut",label:"Cut",Icon:Ol,shortcut:"\u2318X"},{kind:"item",action:"copy",label:"Copy",Icon:na,shortcut:"\u2318C"},{kind:"item",action:"paste",label:"Paste",Icon:wl,shortcut:"\u2318V"},{kind:"sep"},{kind:"item",action:"copy-path",label:"Copy Path",Icon:Nl},{kind:"item",action:"copy-relative-path",label:"Copy Relative Path",Icon:kl},{kind:"sep"},{kind:"item",action:"reembed",label:"Re-embed\u2026",Icon:ka},{kind:"sep"},{kind:"item",action:"rename",label:"Rename",Icon:As,shortcut:"F2"},{kind:"item",action:"delete",label:"Delete",Icon:Nt,danger:!0,shortcut:"Del"}],HA=[{kind:"item",action:"new-file",label:"New File\u2026",Icon:Cs},{kind:"item",action:"new-folder",label:"New Folder\u2026",Icon:br}],UA=210;function lw({x:t,y:e,enabled:n,onAction:r,onClose:a,variant:s="node"}){let i=s==="source"?HA:_A,o=(0,Ds.useRef)(null),[l,u]=(0,Ds.useState)({top:e,left:t});return(0,Ds.useLayoutEffect)(()=>{let c=o.current;if(!c)return;let d=c.getBoundingClientRect(),f=t,h=e;f+d.width>window.innerWidth-4&&(f=Math.max(4,window.innerWidth-d.width-4)),h+d.height>window.innerHeight-4&&(h=Math.max(4,window.innerHeight-d.height-4)),u({top:h,left:f})},[t,e]),(0,Ds.useEffect)(()=>{let c=h=>{o.current?.contains(h.target)||a()},d=h=>{h.key==="Escape"&&a()},f=()=>a();return document.addEventListener("mousedown",c,!0),document.addEventListener("keydown",d,!0),window.addEventListener("resize",f),window.addEventListener("scroll",f,!0),()=>{document.removeEventListener("mousedown",c,!0),document.removeEventListener("keydown",d,!0),window.removeEventListener("resize",f),window.removeEventListener("scroll",f,!0)}},[a]),(0,ow.createPortal)((0,Ts.jsx)("div",{ref:o,role:"menu",style:{position:"fixed",top:l.top,left:l.left,width:UA},className:"z-[1000] rounded-lg border border-white/10 bg-[#14141b] py-1 text-[11px] text-white/80 shadow-[0_18px_46px_-20px_rgba(0,0,0,0.8)]",onContextMenu:c=>c.preventDefault(),children:i.map((c,d)=>{if(c.kind==="sep")return(0,Ts.jsx)("div",{className:"my-1 h-px bg-white/[0.06]"},`s${d}`);let f=n[c.action]===!0,h=c.Icon;return(0,Ts.jsxs)("button",{type:"button",role:"menuitem",disabled:!f,onClick:()=>{f&&(r(c.action),a())},className:$("flex w-full items-center gap-2 px-3 py-1.5 text-left transition",f?"hover:bg-white/[0.06]":"opacity-35 cursor-not-allowed",c.danger&&f?"text-rose-200 hover:bg-rose-500/10":""),children:[(0,Ts.jsx)(h,{className:$("w-3.5 h-3.5 shrink-0",c.danger?"text-rose-300/80":"text-white/45")}),(0,Ts.jsx)("span",{className:"flex-1 truncate",children:c.label}),c.shortcut?(0,Ts.jsx)("span",{className:"text-[9px] text-white/30 tabular-nums",children:c.shortcut}):null]},c.action)})}),document.body)}var uw=j($e(),1),cw=j(Za(),1);var bn=j(ie(),1);function dw({names:t,busy:e,onCancel:n,onConfirm:r}){(0,uw.useEffect)(()=>{let i=o=>{e||(o.key==="Escape"?(o.preventDefault(),n()):o.key==="Enter"&&(o.preventDefault(),r()))};return document.addEventListener("keydown",i,!0),()=>document.removeEventListener("keydown",i,!0)},[e,n,r]);let a=t.length>1,s=a?`Delete ${t.length} items?`:`Delete '${t[0]}'?`;return(0,cw.createPortal)((0,bn.jsx)("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/40 backdrop-blur-[1px]",onMouseDown:i=>{i.target===i.currentTarget&&!e&&n()},children:(0,bn.jsxs)("div",{className:"w-[340px] rounded-xl border border-rose-400/25 bg-[#15151d] p-4 shadow-[0_30px_80px_-24px_rgba(0,0,0,0.85)]",children:[(0,bn.jsxs)("div",{className:"flex items-start gap-2.5",children:[(0,bn.jsx)(ot,{className:"h-4 w-4 text-rose-300 shrink-0 mt-0.5"}),(0,bn.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,bn.jsx)("div",{className:"text-[12px] font-semibold text-white/90",children:s}),(0,bn.jsxs)("div",{className:"mt-1 text-[10.5px] text-white/55 leading-relaxed",children:[a?"The selected files move to Pending Changes. ":"The file moves to Pending Changes. ",(0,bn.jsx)("span",{className:"text-white/75",children:"You can restore"})," ",a?"them":"it"," from there \u2014 this is not a permanent erase."]}),a?(0,bn.jsxs)("div",{className:"mt-2 max-h-24 overflow-auto rounded-md bg-white/[0.03] px-2 py-1.5 text-[10px] font-mono text-white/50 space-y-0.5 overlay-scroll",children:[t.slice(0,12).map(i=>(0,bn.jsx)("div",{className:"truncate",children:i},i)),t.length>12?(0,bn.jsxs)("div",{className:"text-white/35",children:["+",t.length-12," more\u2026"]}):null]}):null]})]}),(0,bn.jsxs)("div",{className:"mt-4 flex items-center justify-end gap-2",children:[(0,bn.jsxs)("button",{type:"button",onClick:n,disabled:e,className:"h-7 px-2.5 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[11px] font-medium text-white/70 transition disabled:opacity-40 inline-flex items-center gap-1",children:[(0,bn.jsx)(Ht,{className:"h-3 w-3"}),"Cancel"]}),(0,bn.jsxs)("button",{type:"button",onClick:r,disabled:e,className:$("h-7 px-3 rounded-md text-[11px] font-semibold transition disabled:opacity-40 inline-flex items-center gap-1.5","bg-rose-500/20 hover:bg-rose-500/30 border border-rose-400/40 text-rose-100"),children:[e?(0,bn.jsx)(We,{className:"h-3 w-3 animate-spin"}):(0,bn.jsx)(Nt,{className:"h-3 w-3"}),"Delete"]})]})]})}),document.body)}var es=j($e(),1),fw=j(Za(),1);var xt=j(ie(),1);function GA(t){return t.usd===null?"unpriced \u2014 the active model has no price":`~$${t.usd.toFixed(2)}${t.usdMargin!==null?` \xB1 $${t.usdMargin.toFixed(2)}`:""}`}function WA(t){return t===null?"time unknown":t<90?`~${Math.round(t)} s`:t<5400?`~${Math.round(t/60)} min`:`~${(t/3600).toFixed(1)} h`}function Xl({agentId:t,projectId:e,target:n,onClose:r,onStarted:a,kind:s="reembed"}){let i=H(b=>b.client),[o,l]=(0,es.useState)(null),[u,c]=(0,es.useState)(!0),[d,f]=(0,es.useState)(!1),[h,p]=(0,es.useState)(null),[g,m]=(0,es.useState)(!1),x={agentId:t,...e?{projectId:e}:{},source:n.source,...n.folder?{folder:n.folder}:{},...n.uri?{uri:n.uri}:{}};(0,es.useEffect)(()=>{let b=!0;return c(!0),cx(x,s,i).then(C=>{b&&l(C)}).catch(C=>{b&&p(C instanceof Error?C.message:"Estimate failed")}).finally(()=>{b&&c(!1)}),()=>{b=!1}},[]),(0,es.useEffect)(()=>{let b=C=>{C.key==="Escape"&&!d&&(C.preventDefault(),r())};return document.addEventListener("keydown",b,!0),()=>document.removeEventListener("keydown",b,!0)},[d,r]);let y=async()=>{f(!0),p(null);try{if(!(await hc(x,s,i)).job){m(!0),f(!1);return}a?.(),r()}catch(b){p(b instanceof Error?b.message:"Re-embed failed"),f(!1)}};return(0,fw.createPortal)((0,xt.jsx)("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/40 backdrop-blur-[1px]",onMouseDown:b=>{b.target===b.currentTarget&&!d&&r()},children:(0,xt.jsxs)("div",{role:"dialog","aria-label":`${s==="pending"?"Embed pending files of":"Re-embed"} ${n.label}`,className:"w-[360px] rounded-xl border border-cyan-400/25 bg-[#15151d] p-4 shadow-[0_30px_80px_-24px_rgba(0,0,0,0.85)]",children:[(0,xt.jsxs)("div",{className:"flex items-start gap-2.5",children:[(0,xt.jsx)(ka,{className:"h-4 w-4 text-cyan-300 shrink-0 mt-0.5"}),(0,xt.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,xt.jsx)("div",{className:"truncate text-[12px] font-semibold text-white/90",children:s==="pending"?`Embed pending files of ${n.label}?`:`Re-embed ${n.label}?`}),(0,xt.jsx)("div",{className:"mt-1 text-[10.5px] text-white/55 leading-relaxed",children:s==="pending"?(0,xt.jsxs)(xt.Fragment,{children:["Only files whose semantic embedding is missing or stale are embedded, with the"," ",(0,xt.jsx)("span",{className:"text-white/75",children:"active"})," model. The figures below cover the whole scope \u2014 an upper bound; files already embedded are skipped. Contents and text search are not touched."]}):(0,xt.jsxs)(xt.Fragment,{children:["Every file in this scope is read again and embedded with the ",(0,xt.jsx)("span",{className:"text-white/75",children:"active"})," ","model, whether it changed or not. File contents and history are not touched \u2014 only the vectors are replaced."]})}),(0,xt.jsx)("div",{className:"mt-2 rounded-md bg-white/[0.03] px-2 py-1.5 text-[10.5px] text-white/65 space-y-0.5",children:u?(0,xt.jsxs)("div",{className:"inline-flex items-center gap-1.5 text-white/45",children:[(0,xt.jsx)(We,{className:"h-3 w-3 animate-spin"}),"Estimating from a sample\u2026"]}):o?(0,xt.jsxs)(xt.Fragment,{children:[(0,xt.jsxs)("div",{children:[o.documents!==null?`${o.documents.toLocaleString()} documents \xB7 `:null,o.points.toLocaleString()," points"]}),(0,xt.jsxs)("div",{children:["~",o.tokens.toLocaleString(),o.tokensMargin!==null?` \xB1 ${o.tokensMargin.toLocaleString()}`:""," tokens"]}),(0,xt.jsxs)("div",{children:[GA(o)," \xB7 ",WA(o.durationSeconds)]}),o.truncated?(0,xt.jsx)("div",{className:"text-amber-300/80",children:"The scope is larger than one listing \u2014 these figures cover its first part."}):null]}):h?null:(0,xt.jsx)("div",{className:"text-white/45",children:"No estimate available for this scope."})}),h?(0,xt.jsx)("div",{className:"mt-2 text-[10px] text-rose-300/90",children:h}):null,g?(0,xt.jsx)("div",{className:"mt-2 text-[10px] text-white/55",children:"Nothing readable in this scope \u2014 nothing was queued."}):null]})]}),(0,xt.jsxs)("div",{className:"mt-4 flex items-center justify-end gap-2",children:[(0,xt.jsxs)("button",{type:"button",onClick:r,disabled:d,className:"h-7 px-2.5 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[11px] font-medium text-white/70 transition disabled:opacity-40 inline-flex items-center gap-1",children:[(0,xt.jsx)(Ht,{className:"h-3 w-3"}),"Cancel"]}),(0,xt.jsxs)("button",{type:"button",onClick:()=>{y()},disabled:d||u||g,className:"h-7 px-3 rounded-md text-[11px] font-semibold transition disabled:opacity-40 inline-flex items-center gap-1.5 bg-cyan-500/20 hover:bg-cyan-500/30 border border-cyan-400/40 text-cyan-100",children:[d?(0,xt.jsx)(We,{className:"h-3 w-3 animate-spin"}):(0,xt.jsx)(ka,{className:"h-3 w-3"}),s==="pending"?"Embed pending":"Re-embed"]})]})]})}),document.body)}var ho=j($e(),1);var pw=j(Zr(),1);var In=j(ie(),1);function zA(t){if(!t)return null;if(t.isRepo&&t.repoName)return{label:t.repoName,title:`Repository: ${t.repoName}`};if(t.containsRepos&&t.repoNames&&t.repoNames.length>0){let e=t.repoNames,n=e.slice(0,2).join(", ");return{label:e.length>2?`${n} +${e.length-2}`:n,title:`Repositories: ${e.join(", ")}`}}return null}function jA({info:t}){let e=(0,lr.resolveIconWithFallback)(t.kind_icon??void 0,zn),n=t.source_kind==="brain"||t.source_kind==="local-disk",r=!!(t.git?.isRepo||t.git?.containsRepos);return(0,In.jsxs)("span",{className:"relative inline-flex items-center justify-center",children:[(0,In.jsx)(e,{className:"w-4 h-4"}),n?(0,In.jsx)(Fl,{className:"absolute -right-1.5 -bottom-1.5 w-2.5 h-2.5 text-current bg-black/80 rounded-full p-[1px] opacity-80"}):null,r?(0,In.jsx)(Cn,{className:"absolute -right-1.5 -top-1.5 w-2.5 h-2.5 text-violet-300/90 bg-black/80 rounded-full p-[1px]"}):null]})}function hw(t){return t.source_kind==="brain"?"brain":qe(t.uri_root)}var mw=ho.default.memo(function({info:e,expanded:n,onToggle:r,onContextMenu:a,onRefresh:s,hydration:i="ready",dirty:o=!1,hideChevron:l=!0,compact:u=!1}){let c=(0,ho.useCallback)(()=>r(e.uri_root),[r,e.uri_root]),d=(0,ho.useCallback)(x=>a?.(e.uri_root,x),[a,e.uri_root]),f=(0,ho.useCallback)(x=>{x.stopPropagation(),x.preventDefault(),s?.(e.uri_root)},[s,e.uri_root]),h=Ic(e),p=Xb(e),g=zA(e.git),m=i==="loading";return(0,In.jsxs)("div",{className:$("group flex w-full items-center gap-2 rounded-md select-none text-left transition-colors",u?"py-1 px-1.5":"py-1.5 px-2","hover:bg-white/5",n&&"bg-white/[0.03]"),onContextMenu:d,"aria-busy":m||void 0,children:[(0,In.jsxs)("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-2 bg-transparent text-left outline-none",onClick:c,"aria-expanded":n,title:p?`${e.uri_root} \u2014 ${p}`:e.uri_root,children:[l?null:(0,In.jsx)("span",{className:"w-0","aria-hidden":"true"}),(0,In.jsx)("span",{className:$("shrink-0",h.iconClassName,i==="idle"||i==="error"?"opacity-50":""),children:(0,In.jsx)(jA,{info:e})}),(0,In.jsx)("span",{className:$("text-xs font-medium flex-1 truncate transition-colors",h.labelClassName,i==="idle"||i==="error"?"opacity-70":""),children:hw(e)})]}),g?(0,In.jsxs)("span",{className:"ml-1 inline-flex max-w-[120px] shrink-0 items-center gap-0.5 text-[10px] text-violet-300/70",title:g.title,children:[(0,In.jsx)(Cn,{className:"h-2.5 w-2.5 shrink-0"}),(0,In.jsx)("span",{className:"truncate",children:g.label})]}):null,s?(0,In.jsx)("button",{type:"button",onClick:f,disabled:m,"aria-label":`Refresh ${hw(e)}`,title:i==="error"?"Last listing failed \u2014 click to retry":o?"This source may be out of date \u2014 click to refresh":"Refresh this source",className:$("shrink-0 inline-flex h-4 w-4 items-center justify-center rounded transition-opacity","text-white/40 hover:text-white/80 focus-visible:opacity-100",m||o||i==="error"?"opacity-100":"opacity-0 group-hover:opacity-100",o||i==="error"?"text-amber-300/80 hover:text-amber-200":""),children:m?(0,In.jsx)(pw.LiveSpinner,{className:"h-3 w-3"}):(0,In.jsx)(_t,{className:"h-3 w-3","aria-hidden":"true"})}):null]})});var mo=j($e(),1);var tt=j(ie(),1),VA=[{id:"keyword",label:"Keyword",hint:"Indexed word search (primary)"},{id:"semantic",label:"Semantic",hint:"Embedding search by meaning"},{id:"grep",label:"Grep",hint:"Literal scan of live connector content"}],po="h-6 w-full bg-transparent border border-white/[0.06] rounded px-1.5 text-[11px] text-white/80 placeholder:text-white/25 outline-none focus:border-white/20";function qA(t){return t?t.requestedMode==="semantic"&&t.effectiveMode&&t.effectiveMode!=="semantic"?`Searched as keyword \u2014 semantic search unavailable${t.embeddingDegraded?` (${t.embeddingDegraded})`:""}. Use specific words.`:t.warning??null:null}function gw({agentId:t}){let e=H(k=>k.activeProjectId),n=H(k=>k.setActiveFolderPath),r=H(k=>k.openFile),a=H(k=>k.searchQuery),s=H(k=>k.searchMode),i=H(k=>k.setSearchMode),o=H(k=>k.searchFilters),l=H(k=>k.setSearchFilters),u=H(k=>k.searchResults),c=H(k=>k.searchLoading),d=H(k=>k.searchError),f=H(k=>k.searchEffect),h=qA(f),p=H(k=>k.runSearch),g=H(k=>k.activeFolderPath),m=H(k=>k.sources),[x,y]=(0,mo.useState)(!1),b=a.trim(),C=o.glob.trim(),L=s==="keyword"?b.length>=2||C.length>=2:b.length>=2,P=(0,mo.useMemo)(()=>nh(g,m,o.scopeToFolder),[g,m,o.scopeToFolder]);(0,mo.useEffect)(()=>{if(!L)return;let k=setTimeout(()=>{p({agentId:t,projectId:e??null})},250);return()=>clearTimeout(k)},[t,e,L,s,a,o,p]);let w=(C?1:0)+(o.category.trim()?1:0)+(o.status.trim()?1:0)+(o.tags.trim()?1:0)+(o.createdAfter.trim()?1:0)+(o.createdBefore.trim()?1:0)+(o.scopeToFolder?1:0);return(0,tt.jsxs)("div",{className:"px-2 pb-2",children:[(0,tt.jsxs)("div",{className:"flex items-center gap-1 pb-1.5",children:[(0,tt.jsx)("div",{className:"flex-1 flex items-center rounded-md border border-white/[0.06] overflow-hidden",children:VA.map(k=>{let _=k.id==="grep"&&!P;return(0,tt.jsx)("button",{type:"button",disabled:_,onClick:()=>i(k.id),title:_?"Grep needs a disk-backed source (brain:// has no live text)":k.hint,className:`flex-1 h-6 text-[10px] uppercase tracking-wide transition-colors ${s===k.id?"bg-white/[0.08] text-white/85":_?"text-white/20 cursor-not-allowed":"text-white/40 hover:text-white/70"}`,"aria-pressed":s===k.id,children:k.label},k.id)})}),(0,tt.jsxs)("button",{type:"button",onClick:()=>y(k=>!k),className:`h-6 w-6 shrink-0 rounded-md inline-flex items-center justify-center transition-colors ${x||w>0?"text-white/85":"text-white/40 hover:text-white/70"}`,title:"Search filters","aria-label":"Toggle search filters","aria-pressed":x,children:[(0,tt.jsx)(ui,{className:"w-3.5 h-3.5"}),w>0?(0,tt.jsx)("span",{className:"absolute translate-x-2.5 -translate-y-2 text-[8px] text-white/70",children:w}):null]})]}),x?(0,tt.jsxs)("div",{className:"pb-2 space-y-1",children:[(0,tt.jsxs)("div",{className:"flex items-center gap-1",children:[(0,tt.jsx)("input",{type:"text",value:o.glob,onChange:k=>l({glob:k.target.value}),placeholder:"Filename\u2026",className:po}),(0,tt.jsxs)("label",{className:"flex items-center gap-1 shrink-0 text-[10px] text-white/45 select-none cursor-pointer",title:"Scope to the active folder",children:[(0,tt.jsx)("input",{type:"checkbox",checked:o.scopeToFolder,onChange:k=>l({scopeToFolder:k.target.checked}),className:"accent-white/60"}),"folder"]})]}),s!=="grep"?(0,tt.jsxs)(tt.Fragment,{children:[(0,tt.jsxs)("div",{className:"flex items-center gap-1",children:[(0,tt.jsx)("input",{type:"text",value:o.category,onChange:k=>l({category:k.target.value}),placeholder:"Category\u2026",className:po}),(0,tt.jsx)("input",{type:"text",value:o.status,onChange:k=>l({status:k.target.value}),placeholder:"Status\u2026",className:po})]}),(0,tt.jsx)("input",{type:"text",value:o.tags,onChange:k=>l({tags:k.target.value}),placeholder:"Tags (comma-separated)\u2026",className:po}),(0,tt.jsxs)("div",{className:"flex items-center gap-1",children:[(0,tt.jsx)("input",{type:"date",value:o.createdAfter,onChange:k=>l({createdAfter:k.target.value}),title:"Created after",className:po}),(0,tt.jsx)("input",{type:"date",value:o.createdBefore,onChange:k=>l({createdBefore:k.target.value}),title:"Created before",className:po})]})]}):null]}):null,L?c?(0,tt.jsx)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:"Searching\u2026"}):d?(0,tt.jsx)("div",{className:"px-2 py-3 text-[11px] text-red-300/70",children:d}):u.length===0?(0,tt.jsxs)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:[h?(0,tt.jsx)("div",{role:"status",className:"mb-1 text-[10px] text-amber-200/70",children:h}):null,"No matches"]}):(0,tt.jsxs)("div",{className:"space-y-1",children:[h?(0,tt.jsx)("div",{role:"status",className:"px-2 py-1 text-[10px] text-amber-200/70",children:h}):null,u.map(k=>(0,tt.jsxs)("button",{type:"button",className:"w-full text-left px-2 py-2 rounded-md hover:bg-white/5 border border-white/[0.04] transition-colors",onClick:()=>{n(et(k.uri)),r({agentId:t,projectId:e??null,uri:k.uri})},children:[(0,tt.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,tt.jsx)("span",{className:"text-[11px] text-white/80 truncate flex-1",children:k.filename}),typeof k.score=="number"?(0,tt.jsx)("span",{className:"text-[9px] text-white/30 shrink-0",children:k.score.toFixed(2)}):null,k.embedding_status==="missing"||k.embedding_status==="stale"?(0,tt.jsxs)("span",{className:"text-[9px] px-1 py-0.5 rounded bg-white/[0.06] text-white/40 shrink-0",title:"This file is text-searchable; its semantic embedding is not current",children:["embedding ",k.embedding_status]}):null,k.match_type?(0,tt.jsx)("span",{className:"text-[9px] px-1 py-0.5 rounded bg-white/[0.06] text-white/40 shrink-0",children:k.match_type==="hybrid"?"H":k.match_type==="semantic"?"S":"K"}):null]}),(0,tt.jsxs)("div",{className:"text-[10px] text-white/35 font-mono truncate",children:[k.uri,s==="grep"&&typeof k.chunk_start=="number"?`:${k.chunk_start}`:""]}),k.snippet??k.content_preview?(0,tt.jsx)("div",{className:"text-[10px] text-white/45 mt-1 line-clamp-2",children:k.snippet??k.content_preview}):null]},`${k.id}:${k.uri}:${k.chunk_start??""}`))]}):(0,tt.jsx)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:s==="keyword"?"Type to search (or set a filename filter)\u2026":"Type to search\u2026"})]})}var we=j($e(),1),A1=j(Za(),1);var P1=j(Wn(),1);var nt=j($e(),1);var h1=j(Zr(),1);var hi=j(ie(),1);function $A(t){return t<1e4?String(t):t<1e6?`${Math.round(t/1e3)}k`:`${(t/1e6).toFixed(1)}M`}function Aa({added:t,removed:e,binary:n,unknown:r,compact:a,className:s}){if(n)return(0,hi.jsx)("span",{className:$("shrink-0 text-[9px] tabular-nums text-white/40",s),title:"Binary file \u2014 git reports no line count",children:"bin"});if(!(typeof t=="number"&&typeof e=="number")||t===0&&e===0&&!r)return null;let o=a?$A:String,l=r?"+":"";return(0,hi.jsxs)("span",{className:$("flex shrink-0 items-center gap-1 text-[9px] tabular-nums",s),title:r?`+${t} \u2212${e} across the counted files; ${r} more could not be measured`:`+${t} \u2212${e}`,children:[t>0?(0,hi.jsx)("span",{className:"text-emerald-400/80",children:`+${o(t)}${l}`}):null,e>0?(0,hi.jsx)("span",{className:"text-rose-400/80",children:`\u2212${o(e)}${l}`}):null,t===0&&e===0?(0,hi.jsx)("span",{className:"text-white/35",children:`0${l}`}):null]})}function KA(t){return(t.refs??[]).some(e=>e==="HEAD"||e.startsWith("HEAD ")||e.startsWith("HEAD-")||e.includes("HEAD ->"))}function xw(t){let e=[],n=[];if(!Array.isArray(t)||t.length===0)return{nodes:e,edges:n,rowSegments:[],laneCount:0};let r=[],a=new Map,s=0,i=u=>{let c=r.indexOf(u);if(c>=0)return c;let d=r.indexOf(null);return d>=0?(r[d]=u,d):(r.push(u),r.length-1)};for(let u=0;u<t.length;u++){let c=t[u],d=c.sha,f=r.indexOf(d);f<0&&(f=i(d));for(let p=0;p<r.length;p++)r[p]===d&&(r[p]=null);f>s&&(s=f),a.set(d,{row:u,lane:f});let h=Array.isArray(c.parents)?c.parents:[];if(h.length!==0){r[f]=h[0];for(let p=1;p<h.length;p++){let g=i(h[p]);g>s&&(s=g)}}e.push({commit:c,row:u,lane:f,isHead:KA(c),isMerge:h.length>=2})}let o=t.map(()=>[]),l=(u,c)=>{u>=0&&u<o.length&&o[u].push(c)};for(let u of e){let c=Array.isArray(u.commit.parents)?u.commit.parents:[];for(let d=0;d<c.length;d++){let f=a.get(c[d]);if(f){n.push({fromRow:u.row,fromLane:u.lane,toRow:f.row,toLane:f.lane,colorLane:u.lane,open:!1});let h=u.row,p=f.row,g=u.lane,m=f.lane,x=u.lane;if(p<=h)continue;if(g===m){l(h,{kind:"pass",fromLane:g,toLane:g,fromY:"center",toY:"edge",colorLane:x});for(let y=h+1;y<p;y++)l(y,{kind:"pass",fromLane:g,toLane:g,fromY:"edge",toY:"edge",colorLane:x});l(p,{kind:"pass",fromLane:g,toLane:g,fromY:"edge",toY:"center",colorLane:x})}else{let y=(g+m)/2,b=d>0?"merge":"fork";if(d>0){if(l(h,{kind:b,fromLane:g,toLane:y,fromY:"center",toY:"edge",colorLane:x}),l(h+1,{kind:b,fromLane:y,toLane:m,fromY:"edge",toY:"center",colorLane:x}),h+1<p){l(h+1,{kind:"pass",fromLane:m,toLane:m,fromY:"center",toY:"edge",colorLane:x});for(let C=h+2;C<p;C++)l(C,{kind:"pass",fromLane:m,toLane:m,fromY:"edge",toY:"edge",colorLane:x});l(p,{kind:"pass",fromLane:m,toLane:m,fromY:"edge",toY:"center",colorLane:x})}}else{if(p-1>h){l(h,{kind:"pass",fromLane:g,toLane:g,fromY:"center",toY:"edge",colorLane:x});for(let C=h+1;C<p-1;C++)l(C,{kind:"pass",fromLane:g,toLane:g,fromY:"edge",toY:"edge",colorLane:x});l(p-1,{kind:"pass",fromLane:g,toLane:g,fromY:"edge",toY:"center",colorLane:x})}l(p-1,{kind:b,fromLane:g,toLane:y,fromY:"center",toY:"edge",colorLane:x}),l(p,{kind:b,fromLane:y,toLane:m,fromY:"edge",toY:"center",colorLane:x})}}}else n.push({fromRow:u.row,fromLane:u.lane,toRow:u.row+1,toLane:u.lane,colorLane:u.lane,open:!0}),l(u.row,{kind:"stub",fromLane:u.lane,toLane:u.lane,fromY:"center",toY:"edge",colorLane:u.lane})}}return{nodes:e,edges:n,rowSegments:o,laneCount:s+1}}function yw(t,e){if(!Array.isArray(t)||e<=0||e>=t.length)return[];let n=[],r=new Set;for(let a of t[e]??[]){if(a.fromY!=="edge")continue;let s=`${a.fromLane}|${a.colorLane}`;r.has(s)||(r.add(s),n.push({kind:"pass",fromLane:a.fromLane,toLane:a.fromLane,fromY:"edge",toY:"edge",colorLane:a.colorLane}))}return n}var Ih={commits:[],nextSkip:0,hasMore:!1};function bw(t,e){let n=[];for(let r of e.commits)!r||typeof r.sha!="string"||t.has(r.sha)||(t.add(r.sha),n.push(r));return n}function ww(t,e){let n=new Set(t.commits.map(a=>a.sha)),r=bw(n,e);return{commits:r.length>0?[...t.commits,...r]:t.commits,nextSkip:t.nextSkip+e.commits.length,hasMore:e.hasMore,outgoing:t.outgoing}}function vw(t){return{commits:bw(new Set,t),nextSkip:t.commits.length,hasMore:t.hasMore,outgoing:t.outgoing}}function Lh(t){return Math.min(1e3,Math.max(t,200))}function kw(t,e){let n=[],r=e&&e.length>0?new Set(e):null,a=!1;for(let s=0;s<t.length;s++)!a&&r&&r.has(t[s].sha)&&(n.push({kind:"outgoing-divider"}),a=!0),n.push({kind:"commit",row:s});return n}function Sw(t,e){return t.kind==="outgoing-divider"?"#outgoing-divider":e[t.row]?.sha??`row-${t.row}`}function Cw(t){let e=t.trim();return e.startsWith("tag:")?"tag":e.startsWith("origin/")?"remote":"local"}function Iw(t,e){return e?"outgoing":t?"merge":"filled"}var XA="#89b4fa";function Lw(t,e){return t==="outgoing"?XA:e}function Ah(t,e=Date.now()){let n=Date.parse(t);if(Number.isNaN(n))return t;let r=Math.max(0,Math.floor((e-n)/1e3));if(r<60)return"just now";let a=Math.floor(r/60);if(a<60)return`${a}m ago`;let s=Math.floor(a/60);if(s<24)return`${s}h ago`;let i=Math.floor(s/24);if(i<30)return`${i}d ago`;let o=Math.floor(i/30);return o<12?`${o}mo ago`:`${Math.floor(o/12)}y ago`}function Aw(t){return!t||typeof t.upstream!="string"||t.upstream.length===0?null:{upstream:t.upstream,ahead:typeof t.ahead=="number"&&t.ahead>=0?t.ahead:0,behind:typeof t.behind=="number"&&t.behind>=0?t.behind:0}}function Ph(t,e){if(typeof window>"u")return e;try{let n=JSON.parse(window.localStorage.getItem(t)??"null");return typeof n=="boolean"?n:e}catch{return e}}function Nh(t,e){if(!(typeof window>"u"))try{window.localStorage.setItem(t,JSON.stringify(e))}catch{}}function Fs(t,e){return typeof e=="string"&&e.length>0?{prefix:`${t}://`,name:e,title:`Source "${t}" \u2014 repository "${e}"`}:{prefix:"",name:t,title:`Repository: ${t}`}}var ns=j($e(),1);var En=j($e(),1),YA=3,Pw=200,Nw=8*1024*1024,JA="200% 0px";function Pc(t){let e=(0,En.useRef)(new Map),n=(0,En.useRef)(null),[r,a]=(0,En.useState)(new Set),s=(0,En.useRef)(0),i=(0,En.useRef)([]),o=(0,En.useRef)(new Map),l=(0,En.useRef)(0),u=(0,En.useRef)(new Map),c=(0,En.useCallback)((p,g)=>{let m=e.current.get(p);m!==g&&(m&&n.current?.unobserve(m),g?(g.dataset.diffCardKey=p,e.current.set(p,g),n.current?.observe(g)):e.current.delete(p))},[]);(0,En.useEffect)(()=>{if(a(new Set),!t||typeof IntersectionObserver>"u")return;let p=new IntersectionObserver(g=>{a(m=>{let x=new Set(m);for(let y of g){let b=y.target.dataset.diffCardKey;b&&(y.isIntersecting?x.add(b):x.delete(b))}return x.size===m.size&&[...x].every(y=>m.has(y))?m:x})},{root:t,rootMargin:JA});n.current=p;for(let g of e.current.values())p.observe(g);return()=>{p.disconnect(),n.current=null}},[t]);let d=(0,En.useCallback)((p,g,m,x)=>{let y=o.current,b=y.get(p);if(b&&(y.delete(p),l.current-=b.bytes),!(m>Nw)){y.set(p,{value:g,bytes:m}),l.current+=m,x&&(u.current.delete(x),u.current.set(x,p)),u.current.size>Pw&&u.current.delete(u.current.keys().next().value);for(let[C,L]of y){if(y.size<=Pw&&l.current<=Nw)break;y.delete(C),l.current-=L.bytes}}},[]),f=(0,En.useCallback)((p,g,m)=>{if(m&&!m.fresh){let x=o.current.get(m.key);if(x)return o.current.delete(m.key),o.current.set(m.key,x),Promise.resolve(x.value)}return new Promise((x,y)=>{let b=()=>{s.current+=1;let C=()=>{s.current-=1,i.current.shift()?.()};if(!g()){C(),x(void 0);return}p().then(L=>{m&&d(m.key,L,m.bytes(L),m.family),C(),x(L)},L=>{C(),y(L)})};s.current<YA?b():i.current.push(b)})},[d]),h=(0,En.useCallback)((p,g)=>(o.current.get(p)??(g?o.current.get(u.current.get(g)??""):void 0))?.value,[]);return{register:c,visible:r,run:f,peek:h}}var ht=j($e(),1);var Be=j(ie()),St=j($e());function Rw(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(a){return Object.getOwnPropertyDescriptor(t,a).enumerable}))),n.push.apply(n,r)}return n}function Rt(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?Rw(Object(n),!0).forEach((function(r){Fh(t,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Rw(Object(n)).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))}))}return t}function Fh(t,e,n){return(e=(function(r){var a=(function(s,i){if(typeof s!="object"||s===null)return s;var o=s[Symbol.toPrimitive];if(o!==void 0){var l=o.call(s,i||"default");if(typeof l!="object")return l;throw new TypeError("@@toPrimitive must return a primitive value.")}return(i==="string"?String:Number)(s)})(r,"string");return typeof a=="symbol"?a:String(a)})(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Os(t,e){if(t==null)return{};var n,r,a=(function(i,o){if(i==null)return{};var l,u,c={},d=Object.keys(i);for(u=0;u<d.length;u++)l=d[u],o.indexOf(l)>=0||(c[l]=i[l]);return c})(t,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(r=0;r<s.length;r++)n=s[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(a[n]=t[n])}return a}function en(t,e){return sv(t)||(function(n,r){var a=n==null?null:typeof Symbol<"u"&&n[Symbol.iterator]||n["@@iterator"];if(a!=null){var s,i,o,l,u=[],c=!0,d=!1;try{if(o=(a=a.call(n)).next,r===0){if(Object(a)!==a)return;c=!1}else for(;!(c=(s=o.call(a)).done)&&(u.push(s.value),u.length!==r);c=!0);}catch(f){d=!0,i=f}finally{try{if(!c&&a.return!=null&&(l=a.return(),Object(l)!==l))return}finally{if(d)throw i}}return u}})(t,e)||Hc(t,e)||ov()}function ZA(t){return sv(t)||iv(t)||Hc(t)||ov()}function kr(t){return(function(e){if(Array.isArray(e))return Eh(e)})(t)||iv(t)||Hc(t)||(function(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
5
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)})()}function
|
|
6
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function
|
|
7
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s,i=!0,o=!1;return{s:function(){n=n.call(t)},n:function(){var l=n.next();return i=l.done,l},e:function(l){o=!0,s=l},f:function(){try{i||n.return==null||n.return()}finally{if(o)throw s}}}}var
|
|
8
|
-
`),p=h.length,g=0;g<p;){var m=h[g];if(m.indexOf("diff --git")===0){i={hunks:[],oldEndingNewLine:!0,newEndingNewLine:!0,oldPath:(c=r(m)).oldPath,newPath:c.newPath},d.push(i);var x,
|
|
1
|
+
import{a as so,c as W}from"./chunks/chunk-DCANE7XH.js";var Je=so((FO,P0)=>{var rh=globalThis.__neuralis_shared_modules__,A0=rh&&Object.prototype.hasOwnProperty.call(rh,"react")?rh.react:void 0;if(A0===void 0)throw new Error("[neuralis-ui] shared module react is not provided by the host");P0.exports=A0});var nr=so((EO,N0)=>{var ah=globalThis.__neuralis_shared_modules__,R0=ah&&Object.prototype.hasOwnProperty.call(ah,"@neuralis/package-system/client")?ah["@neuralis/package-system/client"]:void 0;if(R0===void 0)throw new Error("[neuralis-ui] shared module @neuralis/package-system/client is not provided by the host");N0.exports=R0});var fa=so((OO,T0)=>{var sh=globalThis.__neuralis_shared_modules__,M0=sh&&Object.prototype.hasOwnProperty.call(sh,"@neuralis/agent-core/app/chat")?sh["@neuralis/agent-core/app/chat"]:void 0;if(M0===void 0)throw new Error("[neuralis-ui] shared module @neuralis/agent-core/app/chat is not provided by the host");T0.exports=M0});var ue=so((VU,Gy)=>{var Sh=globalThis.__neuralis_shared_modules__,Uy=Sh&&Object.prototype.hasOwnProperty.call(Sh,"react/jsx-runtime")?Sh["react/jsx-runtime"]:void 0;if(Uy===void 0)throw new Error("[neuralis-ui] shared module react/jsx-runtime is not provided by the host");Gy.exports=Uy});var ds=so((a8,qy)=>{var Lh=globalThis.__neuralis_shared_modules__,jy=Lh&&Object.prototype.hasOwnProperty.call(Lh,"react-dom")?Lh["react-dom"]:void 0;if(jy===void 0)throw new Error("[neuralis-ui] shared module react-dom is not provided by the host");qy.exports=jy});var d2=so((C9,c2)=>{var b0=globalThis.__neuralis_shared_modules__,u2=b0&&Object.prototype.hasOwnProperty.call(b0,"@neuralis/agent-core/app/chat/store")?b0["@neuralis/agent-core/app/chat/store"]:void 0;if(u2===void 0)throw new Error("[neuralis-ui] shared module @neuralis/agent-core/app/chat/store is not provided by the host");c2.exports=u2});var kl=W(Je(),1),Qf=W(nr(),1),A2=W(fa(),1);var Wn=W(Je(),1);var Na=W(Je(),1);var D0=t=>{let e,n=new Set,r=(u,c)=>{let d=typeof u=="function"?u(e):u;if(!Object.is(d,e)){let f=e;e=c??(typeof d!="object"||d===null)?d:Object.assign({},e,d),n.forEach(h=>h(e,f))}},a=()=>e,o={setState:r,getState:a,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u))},l=e=t(r,a,o);return o},ih=(t=>t?D0(t):D0);var Sl=W(Je(),1);var B2=t=>t;function F0(t,e=B2){let n=Sl.default.useSyncExternalStore(t.subscribe,Sl.default.useCallback(()=>e(t.getState()),[t,e]),Sl.default.useCallback(()=>e(t.getInitialState()),[t,e]));return Sl.default.useDebugValue(n),n}function lh(t,e){let n;try{n=t()}catch{return}return{getItem:a=>{var s;let i=l=>l===null?null:JSON.parse(l,e?.reviver),o=(s=n.getItem(a))!=null?s:null;return o instanceof Promise?o.then(i):i(o)},setItem:(a,s)=>n.setItem(a,JSON.stringify(s,e?.replacer)),removeItem:a=>n.removeItem(a)}}var oh=t=>e=>{try{let n=t(e);return n instanceof Promise?n:{then(r){return oh(r)(n)},catch(r){return this}}}catch(n){return{then(r){return this},catch(r){return oh(r)(n)}}}},_2=(t,e)=>(n,r,a)=>{let s={storage:lh(()=>window.localStorage),partialize:m=>m,version:0,merge:(m,x)=>({...x,...m}),...e},i=!1,o=0,l=new Set,u=new Set,c=s.storage;if(!c)return t((...m)=>{console.warn(`[zustand persist middleware] Unable to update item '${s.name}', the given storage is currently unavailable.`),n(...m)},r,a);let d=()=>{let m=s.partialize({...r()});return c.setItem(s.name,{state:m,version:s.version})},f=a.setState;a.setState=(m,x)=>(f(m,x),d());let h=t((...m)=>(n(...m),d()),r,a);a.getInitialState=()=>h;let p,g=()=>{var m,x;if(!c)return;let b=++o;i=!1,l.forEach(C=>{var I;return C((I=r())!=null?I:h)});let y=((x=s.onRehydrateStorage)==null?void 0:x.call(s,(m=r())!=null?m:h))||void 0;return oh(c.getItem.bind(c))(s.name).then(C=>{if(C)if(typeof C.version=="number"&&C.version!==s.version){if(s.migrate){let I=s.migrate(C.state,C.version);return I instanceof Promise?I.then(L=>[!0,L]):[!0,I]}console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return[!1,C.state];return[!1,void 0]}).then(C=>{var I;if(b!==o)return;let[L,v]=C;if(p=s.merge(v,(I=r())!=null?I:h),n(p,!0),L)return d()}).then(()=>{b===o&&(y?.(r(),void 0),p=r(),i=!0,u.forEach(C=>C(p)))}).catch(C=>{b===o&&y?.(void 0,C)})};return a.persist={setOptions:m=>{s={...s,...m},m.storage&&(c=m.storage)},clearStorage:()=>{++o,c?.removeItem(s.name)},getOptions:()=>s,rehydrate:()=>g(),hasHydrated:()=>i,onHydrate:m=>(l.add(m),()=>{l.delete(m)}),onFinishHydration:m=>(u.add(m),()=>{u.delete(m)})},s.skipHydration||g(),p||h},E0=_2;var Tx=W(nr(),1);var O0=W(nr(),1);async function io(t,e,n,r){let a={agentId:t};return e&&(a.projectId=e),n?.uri&&(a.uri=n.uri),typeof n?.recursive=="boolean"&&(a.recursive=n.recursive),n?.include&&(a.include=n.include),typeof n?.summary_chars=="number"&&(a.summary_chars=n.summary_chars),typeof n?.include_metadata=="boolean"&&(a.include_metadata=n.include_metadata),typeof n?.only_indexed=="boolean"&&(a.only_indexed=n.only_indexed),typeof n?.sources_only=="boolean"&&(a.sources_only=n.sources_only),typeof n?.include_counts=="boolean"&&(a.include_counts=n.include_counts),typeof n?.limit=="number"&&(a.limit=n.limit),r.post("list",a)}async function B0(t,e,n,r){return(await io(t,e,{uri:`${n}://`,recursive:!1,include:"folders",include_counts:!0,limit:1},r)).sources?.[0]??null}async function oo(t,e){return(e??await(0,O0.tryGetPackageApiImperativeAsync)("brain-core")).post("read",t)}async function _0(t,e){let n={agentId:t.agentId};return t.projectId&&(n.projectId=t.projectId),t.scope&&(n.scope=t.scope),t.observed&&(n.observed="1"),e.get("sources",n)}async function uh(t,e){return e.patch("sources",{agentId:t.agentId,...t.projectId?{projectId:t.projectId}:{},...t.config})}async function H0(t,e){return e.post("sources/sync",t)}async function U0(t,e){let n={agentId:t.agentId};return t.projectId&&(n.projectId=t.projectId),t.source&&(n.source=t.source),e.get("sources/sync-status",n)}async function G0(t,e){return e.post("sources/enabled",{agentId:t.agentId,...t.projectId?{projectId:t.projectId}:{},source:t.source,enabled:t.enabled})}async function xc(t,e){let n=new URLSearchParams;return n.set("agentId",t.agentId),t.projectId&&n.set("projectId",t.projectId),e.get("sources/discoverable",Object.fromEntries(n))}function Ps(t){return t?{repo:t}:{}}function Fr(t){return t?{repo:t}:{}}async function lo(t,e){let n={agentId:t.agentId,source:t.source};return t.projectId&&(n.projectId=t.projectId),e.get("git/repos",n)}async function bc(t,e){let n={agentId:t.agentId,source:t.source,...Ps(t.repo)};return t.projectId&&(n.projectId=t.projectId),e.get("git/status",n)}async function z0(t,e){let n={agentId:t.agentId,source:t.source,...Ps(t.repo)};return t.projectId&&(n.projectId=t.projectId),e.get("git/branch",n)}async function yc(t,e){let n={agentId:t.agentId,source:t.source,...Ps(t.repo),path:t.path};return typeof t.commit=="string"&&(n.commit=t.commit),typeof t.base=="string"&&(n.base=t.base),typeof t.head=="string"&&(n.head=t.head),typeof t.staged=="boolean"&&(n.staged=t.staged?"1":"0"),t.projectId&&(n.projectId=t.projectId),e.get("git/diff",n)}async function vc(t,e){let n={agentId:t.agentId,source:t.source,...Ps(t.repo)};return t.projectId&&(n.projectId=t.projectId),typeof t.maxCount=="number"&&(n.maxCount=String(t.maxCount)),typeof t.skip=="number"&&(n.skip=String(t.skip)),t.ref&&(n.ref=t.ref),e.get("git/log",n)}async function W0(t,e){let n={agentId:t.agentId,source:t.source,...Ps(t.repo)};return t.projectId&&(n.projectId=t.projectId),typeof t.maxCount=="number"&&(n.maxCount=String(t.maxCount)),typeof t.skip=="number"&&(n.skip=String(t.skip)),t.ref&&(n.ref=t.ref),e.get("git/log-stats",n)}async function wc(t,e){let n={agentId:t.agentId,source:t.source,...Ps(t.repo),sha:t.sha};return t.projectId&&(n.projectId=t.projectId),e.get("git/commit",n)}async function Cl(t,e){let n={agentId:t.agentId,source:t.source,...Ps(t.repo)};return t.projectId&&(n.projectId=t.projectId),e.get("git/outgoing",n)}async function j0(t,e){let n={agentId:t.agentId,source:t.source,...Ps(t.repo),path:t.path,rev:t.rev};return t.projectId&&(n.projectId=t.projectId),e.get("git/show",n)}async function q0(t,e){return e.post("git/stage",{source:t.source,...Fr(t.repo),paths:t.paths,...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function V0(t,e){return e.post("git/unstage",{source:t.source,...Fr(t.repo),paths:t.paths,...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function $0(t,e){return e.post("git/stage",{source:t.source,...Fr(t.repo),hunk:t.hunk,...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function K0(t,e){return e.post("git/unstage",{source:t.source,...Fr(t.repo),hunk:t.hunk,...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function X0(t,e){return e.post("git/discard",{source:t.source,...Fr(t.repo),paths:t.paths,...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function Y0(t,e){return e.post("git/commit",{source:t.source,...Fr(t.repo),message:t.message,...t.amend?{amend:!0}:{},...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function J0(t,e){return e.post("git/branch",{source:t.source,...Fr(t.repo),action:"create",name:t.name,...t.startPoint?{startPoint:t.startPoint}:{},...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function Z0(t,e){return e.post("git/branch",{source:t.source,...Fr(t.repo),action:"delete",name:t.name,...t.force?{force:!0}:{},...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function Q0(t,e){return e.post("git/restore",{source:t.source,...Fr(t.repo),rescue:t.rescue,...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function ch(t,e){return e.post("git/checkout",{source:t.source,...Fr(t.repo),ref:t.ref,...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function ex(t,e){return e.post("git/fetch",{source:t.source,...Fr(t.repo),...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function tx(t,e){return e.post("git/pull",{source:t.source,...Fr(t.repo),...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function nx(t,e){return e.post("git/push",{source:t.source,...Fr(t.repo),...t.projectId?{projectId:t.projectId}:{},agentId:t.agentId})}async function rx(t,e){return e.post("search",t)}async function kc(t,e){let n=new FormData;return n.append("agentId",t.agentId),t.projectId&&n.append("projectId",t.projectId),n.append("file",t.file),t.uri&&n.append("uri",t.uri),t.tags?.length&&n.append("tags",t.tags.join(",")),e.upload("upload",n)}async function Er(t,e){return e.post("write",t)}function Pa(t,e){return t?.code==="destination_exists"?"Something is already there \u2014 nothing was overwritten. Pick another name.":t?.message||t?.error||e}async function Sc(t,e){return e.post("approve",t)}async function uo(t,e){return(await e.post("pending",{...t,action:"preview"})).preview}async function Cc(t,e){let n=await e.post("pending",t);if(!Array.isArray(n.changes)||typeof n.complete!="boolean"||typeof n.partial!="boolean")throw new Error("Pending listing unavailable; retry the request");return n}async function ax(t,e){let n={agentId:t.agentId,count_only:"1"};t.projectId&&(n.projectId=t.projectId);let r=await e.get("pending",n);if(!Number.isInteger(r.count)||r.count<0||typeof r.exact!="boolean")throw new Error("Pending count unavailable");return r}async function sx(t,e){return e.post("pending",{...t,action:"revert"})}async function ix(t,e){return e.post("pending",{...t,action:"discard"})}async function ox(t,e){return e.post("pending",{...t,action:"dismiss"})}async function lx(t,e){return e.post("pending",{...t,action:"discard-orphans"})}function ux(t,e,n){let r=new URLSearchParams({agentId:t,uri:e});return n&&r.set("projectId",n),`/api/packages/brain-core/raw?${r.toString()}`}async function cx(t,e){return e.post("health",t)}async function dx(t,e){return e.post("health/scan",t)}async function fx(t,e){return e.post("health/gc",t)}async function hx(t,e){return e.post("sources",t)}async function px(t,e){let n=new URLSearchParams({agentId:t.agentId});return t.projectId&&n.set("projectId",t.projectId),t.purgeVectors&&n.set("purge","1"),e.del(`sources/${encodeURIComponent(t.source)}?${n.toString()}`)}async function mx(t,e){return e.post("sources/reset",t)}async function gx(t,e){return e.post("sources/reindex",t)}async function xx(t,e){return e.post("sources/purge",t)}function fi(t){return typeof t=="number"&&Number.isFinite(t)?t:null}function H2(t){let e=t&&typeof t=="object"?t:null,n=e?.estimate&&typeof e.estimate=="object"?e.estimate:null,r=fi(n?.points),a=fi(n?.tokens);if(!e||!n||r===null||a===null)return null;let s=fi(n.relStdErr),i=fi(n.usd);return{documents:fi(e.documents),truncated:e.truncated===!0,points:r,tokens:a,tokensMargin:s!==null?Math.round(a*s):null,usd:i,usdMargin:s!==null&&i!==null?i*s:null,durationSeconds:fi(n.seconds)}}var bx=t=>t==="pending"?{embeddingOnly:!0}:{force:!0};async function yx(t,e,n){return H2(await n.post("sources/reindex",{...t,...bx(e),estimate:!0}))}async function Ic(t,e,n){let r=await n.post("sources/reindex",{...t,...bx(e)}),a=r?.job&&typeof r.job=="object"?r.job:null;return{documents:fi(r?.documents),truncated:r?.truncated===!0,job:a}}async function vx(t,e){return e.post("sources/cancel",t)}async function wx(t,e){let n={agentId:t.agentId};return t.projectId&&(n.projectId=t.projectId),e.get("sources/health",n)}async function dh(t,e){let n={path:t.path,agentId:t.agentId};return t.projectId&&(n.projectId=t.projectId),e.get("sources/browse",n)}async function kx(t){return t.get("sources/kinds",{})}function Ke(t){let e=t.indexOf("://");return e>0?t.slice(0,e):"brain"}function kr(t){let e=t.indexOf("://");return e>0?t.slice(0,e+3):`${t}://`}function ct(t){let e=t.indexOf("://");if(e<1)return t;let n=t.slice(0,e+3),r=t.lastIndexOf("/");return r<=e+2?n:t.slice(0,r)}function Ra(t){let e=t.indexOf("://");if(e<1)return[];let r=`${t.slice(0,e)}://`,a=t.slice(e+3);if(!a)return[];let s=a.split("/").filter(Boolean);if(s.length===0)return[];let i=[r],o=r;for(let l=0;l<s.length-1;l++)o=o.endsWith("/")?`${o}${s[l]}`:`${o}/${s[l]}`,i.push(o);return i}function It(t){let e=t.indexOf("://"),n=e>=0?t.slice(e+3):t,r=n.lastIndexOf("/");return r>=0?n.slice(r+1):n}var Sx=t=>t;function as(t){return t.uri}function U2(t,e,n){for(let r of e){if(t[r]?.type==="folder")continue;let a=r.endsWith("://")?r.slice(0,r.indexOf("://")):r.split("/").pop()||"",s=ct(r),i=t[r];t[r]={...i||{},storeKey:r,name:a,uri:r,type:"folder",parentUri:s===r?void 0:s,lastUpdated:n}}}function hi(t,e,n){U2(t,Ra(e),n)}function Il(t){if(typeof t=="string")return t;if(Array.isArray(t)){let e=t.map(n=>{if(n){if(typeof n=="string")return n;if(typeof n=="object"){let r=typeof n.text=="string"?n.text:void 0,a=typeof n.content=="string"?n.content:void 0;return r??a}}}).filter(n=>!!(n&&n.trim()));if(e.length>0)return e.join(`
|
|
2
|
+
`)}if(t&&typeof t=="object"){let e=t;if(typeof e.text=="string")return e.text;if(typeof e.content=="string")return e.content;if(Array.isArray(e.content)){let n=Il(e.content);if(n)return n}try{return JSON.stringify(t,null,2)}catch{return}}}function co(t){return Array.isArray(t?.files)?t.files:Array.isArray(t?.widget?.files)?t.widget.files:Array.isArray(t?.state?.files)?t.state.files:Array.isArray(t?.data?.files)?t.data.files:[]}function fo(t){return Il(t?.text)??Il(t?.content)??Il(t?.file_content)??Il(t?.fileContent)??""}function Lc(t){if(!t||typeof t!="object")return;let e=t;if(e.content!=null)return{content:typeof e.content=="string"?e.content:JSON.stringify(e.content,null,2),updatedAt:typeof e.updatedAt=="string"?e.updatedAt:"",...typeof e.uri=="string"?{uri:e.uri}:{},...typeof e.status=="string"?{status:e.status}:{},...typeof e.sourceVersion=="string"?{sourceVersion:e.sourceVersion}:{},...e.metadata&&typeof e.metadata=="object"?{metadata:e.metadata}:{}}}function Ac(t,e){return typeof t.fileErrorByPath[e]=="string"||typeof t.fileBaseContentByPath[e]=="string"}function pi(t,e,n){return`${t??""}::${e??""}::${n}`}var fh={glob:"",category:"",status:"",tags:"",createdAfter:"",createdBefore:"",scopeToFolder:!1},Cx={searchQuery:"",searchMode:"keyword",searchFilters:fh,searchResults:[],searchLoading:!1,searchError:void 0,searchEffect:{}};function hh(t,e,n){let r=typeof t=="string"&&t.includes("://")?t:null;if(n&&r)return r.startsWith("brain://")?null:r;let a=r?kr(r):null;return a&&!a.startsWith("brain://")?a:(e??[]).find(i=>i.source_kind!=="brain"&&typeof i.uri_root=="string")?.uri_root??null}function Ix(t,e){let n=0;return{setSearchQuery:r=>t(()=>({searchQuery:r})),setSearchMode:r=>t(()=>({searchMode:r})),setSearchFilters:r=>t(a=>({searchFilters:{...a.searchFilters,...r}})),clearSearch:()=>t(()=>({searchQuery:"",searchFilters:fh,searchResults:[],searchLoading:!1,searchError:void 0,searchEffect:{}})),async runSearch({agentId:r,projectId:a}){let{searchQuery:s,searchMode:i,searchFilters:o,activeFolderPath:l,sources:u}=e(),c=(s??"").trim(),d=o??fh,f=d.glob.trim(),h=i==="keyword"?c.length>=2||f.length>=2:c.length>=2;if(!r||!h){t(()=>({searchResults:[],searchLoading:!1,searchError:void 0,searchEffect:{}}));return}let p=typeof l=="string"&&l.includes("://")?l:void 0,g=i==="grep"?hh(l,u,d.scopeToFolder):d.scopeToFolder?p:void 0;if(i==="grep"&&!g){t(()=>({searchResults:[],searchLoading:!1,searchError:"Grep needs a non-brain folder scope \u2014 select a folder in a disk-backed source.",searchEffect:{}}));return}let m=d.tags.split(",").map(b=>b.trim()).filter(b=>b.length>0),x=++n;t(()=>({searchLoading:!0,searchError:void 0}));try{let b=await rx({agentId:r,...a?{projectId:a}:{},search_mode:i==="keyword"?"filter":i,...c?{query:c}:{},...g?{folder_uri:g}:{},...f?{glob:f}:{},...i!=="grep"&&d.category.trim()?{category:d.category.trim()}:{},...i!=="grep"&&d.status.trim()?{status:d.status.trim()}:{},...i!=="grep"&&m.length>0?{tags:m}:{},...i!=="grep"&&d.createdAfter.trim()?{created_after:d.createdAfter.trim()}:{},...i!=="grep"&&d.createdBefore.trim()?{created_before:d.createdBefore.trim()}:{},limit:i==="semantic"?30:50},e().client);if(x!==n)return;let y=b.results||[],C=y.find(L=>typeof L.error=="string"&&L.error.length>0),I=y.filter(L=>typeof L.uri=="string"&&L.uri.includes("://")&&!L.error).map(L=>({id:L.id||`fs:${L.uri}:${L.chunk_start??""}`,uri:L.uri,filename:L.filename||String(L.uri).split("/").pop(),content_preview:L.content_preview,snippet:L.snippet,chunk_start:L.chunk_start,chunk_end:L.chunk_end,match_type:L.match_type,score:L.score,...typeof L.embedding_status=="string"?{embedding_status:L.embedding_status}:{}}));t(()=>({searchResults:I,searchLoading:!1,searchError:C?String(C.error):void 0,searchEffect:{...b.requested_mode?{requestedMode:b.requested_mode}:{},...b.effective_mode?{effectiveMode:b.effective_mode}:{},...b.embedding_degraded?{embeddingDegraded:b.embedding_degraded}:{},...b.warning?{warning:b.warning}:{}}}))}catch(b){if(x!==n)return;t(()=>({searchResults:[],searchLoading:!1,searchError:b instanceof Error?b.message:"Search failed",searchEffect:{}}))}}}}function ho(){return{files:{},folderBadges:{},fileContentByPath:{},fileBaseContentByPath:{},fileErrorByPath:{},filePrevByPath:{},openFiles:[],activeFile:null,tabMeta:{},pendingReviewPaths:new Set,pendingCount:0,pendingCountState:"stale",expandedFolders:new Set,sidebarView:"tree",activeWorkspaceTab:"file",workspacePanels:{upload:!1,sources:!1,packages:!1,pending:!1},pendingSourceSuggestion:null,vectorHealthOpen:!1,searchQuery:"",searchResults:[],searchLoading:!1,searchError:void 0,searchEffect:{},gitStatus:null,gitTotals:null,gitOutgoingStat:null,gitBranches:[],gitLoading:!1,gitError:void 0,gitDiffTarget:null,gitCommitTarget:null,sources:[],sourcesLoading:!0,activeSource:null,activeRepoRel:"",loadedFolders:{},hydrationState:{},dirtySources:{},sourceChangeRevision:{},organizeError:null,pendingPanelFilter:{},activeFolderPath:"brain://docs",snapshotError:void 0}}var G2=200;function Pc(t,e=G2){let n=[...t],r=[],a=!0;for(;n.length>e&&a;){a=!1;for(let s=0;s<n.length&&n.length>e;){let i=n[s],o=`${i}/`;if(i.endsWith("://")||n.some(l=>l.startsWith(o))){s+=1;continue}n.splice(s,1),r.push(i),a=!0}}return{kept:n,evicted:r}}var z2=Object.keys(ho());function W2(t){let e={};for(let n of z2)e[n]=t[n];return e}function Rc(t){let e=t.expandedFolders;return{openFiles:Array.isArray(t.openFiles)?t.openFiles:[],activeFile:typeof t.activeFile=="string"?t.activeFile:null,tabMeta:t.tabMeta??{},expandedFolders:e instanceof Set?Pc(Array.from(e)).kept:[],sidebarView:t.sidebarView??"tree",activeWorkspaceTab:t.activeWorkspaceTab??"file",workspacePanels:t.workspacePanels??{upload:!1,sources:!1,packages:!1,pending:!1},activeFolderPath:t.activeFolderPath??"brain://docs"}}function Lx(t){let e=ho();return t?{...e,openFiles:Array.isArray(t.openFiles)?t.openFiles:[],activeFile:typeof t.activeFile=="string"?t.activeFile:null,tabMeta:t.tabMeta??{},expandedFolders:new Set(Array.isArray(t.expandedFolders)?Pc(t.expandedFolders).kept:[]),sidebarView:t.sidebarView??e.sidebarView,activeWorkspaceTab:t.activeWorkspaceTab??e.activeWorkspaceTab,workspacePanels:t.workspacePanels??e.workspacePanels,activeFolderPath:t.activeFolderPath??e.activeFolderPath}:e}function Ax(t,e){let n=new Map;return{async loadList({agentId:r,projectId:a,userId:s,withCounts:i}){if(!r)return;let o=`${r}:${a||""}:${i?"c":""}`,l=n.get(o);if(l){await l;return}let u="brain://",c=e(),d=s===void 0?c.activeUserId:s,f=c.activeUserId!==null&&c.activeUserId!==d,h=c.activeAgentId!==r||c.activeProjectId!==a||f,p;if(h?(e().fenceInFlightWriters(),t(m=>{let x={...m.contextStateByKey};m.activeAgentId&&(x[pi(m.activeUserId,m.activeProjectId,m.activeAgentId)]=W2(m));let b=pi(d,a,r);return p=x[b],delete x[b],{activeUserId:d,activeAgentId:r,activeProjectId:a,...ho(),...p??{},contextStateByKey:x}})):t(()=>({activeUserId:d,activeAgentId:r,activeProjectId:a,sourcesLoading:!0})),p){let m=p.loadedFolders??{},x=new Set;for(let[b,y]of Object.entries(m)){if(!y)continue;let C=Ke(b);C&&x.add(C)}for(let b of x)e().reconcileSourceFolders({agentId:r,projectId:a,source:b})}e().rehydrateActiveTab();let g=(async()=>{let m;try{m=await io(r,a??void 0,{sources_only:!0,recursive:!1,...i?{include_counts:!0}:{}},e().client)}catch{t(()=>({snapshotError:"Filesystem service unavailable",sourcesLoading:!1}));return}let x=Array.isArray(m.folders)?m.folders:[],b=Array.isArray(m.files)?m.files:[],y=Array.isArray(m.sources)?m.sources:[];t(C=>{let I=C.activeAgentId===r&&C.activeProjectId===a,L=I?{...C.files}:{},v=Date.now();L[u]||(L[u]={storeKey:u,name:"brain",uri:u,type:"folder",lastUpdated:v,presence:"brain"});for(let R of x){let P=typeof R=="string"?R:typeof R?.uri=="string"?R.uri:"";if(!P)continue;let H=typeof R?.name=="string"?R.name:P.split("/").pop()||"folder",w=R?.presence??(Ke(P)==="brain"?"brain":"stale_indexed");hi(L,`${P}/placeholder`,v),L[P]={storeKey:P,name:H,uri:P,type:"folder",parentUri:P.endsWith("://")?void 0:ct(P),lastUpdated:v,presence:w,git:typeof R.git=="string"?String(R.git):void 0}}for(let R of b){let P=typeof R?.uri=="string"?String(R.uri):"";if(!P)continue;let H=typeof R?.id=="string"?String(R.id):void 0,w=typeof R.status=="string"?String(R.status):void 0,N=Array.isArray(R.tags)&&R.tags.length>0?R.tags:void 0,j=typeof R.category=="string"?String(R.category):void 0,K=R.version&&typeof R.version=="object"?R.version:void 0,A=typeof R.agent_id=="string"?String(R.agent_id):void 0,F=typeof R.project_id=="string"?String(R.project_id):void 0,_=R?.presence??(Ke(P)==="brain"?"brain":"stale_indexed"),X=typeof R.git=="string"?String(R.git):void 0;hi(L,P,v),L[P]={storeKey:P,id:H,name:String(R.filename||R.name||It(P)),uri:P,os_uri:typeof R.os_uri=="string"?String(R.os_uri):void 0,type:"file",status:w,parentUri:ct(P),lastUpdated:v,category:j,tags:N,metadata:R.metadata&&typeof R.metadata=="object"?R.metadata:void 0,createdAt:typeof R.createdAt=="string"?String(R.createdAt):void 0,updatedAt:typeof R.updatedAt=="string"?String(R.updatedAt):void 0,version:K,sourceAgentId:A,sourceProjectId:F,presence:_,git:X};let re=ct(P),ae=L[re];ae&&ae.type==="folder"&&(L[re]={...ae,sourceAgentId:A??ae.sourceAgentId,sourceProjectId:F??ae.sourceProjectId,lastUpdated:v})}let k=I?{...C.loadedFolders||{}}:{},O=I?{...C.hydrationState||{}}:{};for(let R of y)!k[R.uri_root]&&!O[R.uri_root]&&(O[R.uri_root]="idle");return{files:L,sources:y,sourcesLoading:!1,snapshotError:void 0,loadedFolders:k,hydrationState:O}})})();n.set(o,g);try{await g}finally{n.delete(o)}},async refresh({agentId:r,projectId:a,withCounts:s}){await e().loadList({agentId:r,projectId:a,withCounts:s})}}}var Rx={gitStatus:null,gitTotals:null,gitOutgoingStat:null,gitBranches:[],gitLoading:!1,gitError:void 0,gitViewMode:"list",gitDiffTarget:null,gitCommitTarget:null,gitLogNonce:0};function ph(t,e){let n=t??(typeof e=="string"?e:"");return n?n.includes("://")?Ke(n):n:""}function Px(t,e){return typeof t=="string"?t:typeof e=="string"?e:""}function Nx(t,e){let n=0,r=0;return{setGitViewMode:a=>t(()=>({gitViewMode:a})),setGitDiffTarget:a=>t(()=>({gitDiffTarget:a})),setGitCommitTarget:a=>t(s=>({gitCommitTarget:a,...a===null&&s.activeWorkspaceTab==="git-commit"?{activeWorkspaceTab:"file"}:{}})),notifyGitLogChanged:a=>{if(!a)return;let s=ph(void 0,e().activeSource);a===s&&t(i=>({gitLogNonce:(typeof i.gitLogNonce=="number"?i.gitLogNonce:0)+1}))},clearGit:()=>t(a=>({gitStatus:null,gitBranches:[],gitLoading:!1,gitError:void 0,gitDiffTarget:null,gitCommitTarget:null,...a.activeWorkspaceTab==="git-commit"?{activeWorkspaceTab:"file"}:{}})),setGitOutgoingStat(a){t(()=>({gitOutgoingStat:a}))},async loadGitStatus({agentId:a,projectId:s,source:i,repo:o}){let l=ph(i,e().activeSource),u=Px(o,e().activeRepoRel);if(!a||!l){t(()=>({gitStatus:null,gitTotals:null,gitLoading:!1,gitError:void 0}));return}let c=++n;t(()=>({gitLoading:!0,gitError:void 0}));try{let d=await bc({agentId:a,...s?{projectId:s}:{},source:l,...u?{repo:u}:{}},e().client);if(c!==n)return;t(()=>({gitStatus:d?.status??null,gitTotals:d?.totals??null,gitLoading:!1,gitError:void 0}))}catch(d){if(c!==n)return;t(()=>({gitStatus:null,gitTotals:null,gitLoading:!1,gitError:d instanceof Error?d.message:"Git status failed"}))}},async loadGitBranches({agentId:a,projectId:s,source:i,repo:o}){let l=ph(i,e().activeSource),u=Px(o,e().activeRepoRel);if(!a||!l){t(()=>({gitBranches:[]}));return}let c=++r;try{let d=await z0({agentId:a,...s?{projectId:s}:{},source:l,...u?{repo:u}:{}},e().client);if(c!==r)return;t(()=>({gitBranches:Array.isArray(d?.branches)?d.branches:[]}))}catch(d){if(c!==r)return;t(()=>({gitBranches:[],gitError:d instanceof Error?d.message:"Git branches failed"}))}}}}var mh=5e4,j2=3;function q2(){return{resetEpoch:0,pendingCountSeq:0,rehydrateInFlight:new Set,liveFolderLoadInFlight:new Map,reconcileJobs:new Map,folderGeneration:new Map}}function bh(t,e){let n=(t.folderGeneration.get(e)??0)+1;return t.folderGeneration.set(e,n),n}function Dx(t,e,n){return t.folderGeneration.get(e)===n}function gh(t){return{storeKey:t,uri:t,name:It(t),type:"file",parentUri:ct(t)}}function Mx(t,e,n){let r=ct(e);if(r===e||n.parentUri===r)return n;let a={...n,parentUri:r};return t[e]=a,a}function Fx(t,e,n,r){let a=r?.issuedAt??n,s=r?.pending;for(let i of e.folders||[]){let o=typeof i=="string"?i:typeof i?.uri=="string"?i.uri:"";if(!o)continue;let l=typeof i?.name=="string"?i.name:o.split("/").pop()||"folder",u=i?.presence??"unindexed",c=typeof i?.git=="string"?String(i.git):void 0,d=typeof i?.status=="string"?i.status:void 0,f=t[o];if(!f){t[o]={storeKey:o,name:l,uri:o,type:"folder",parentUri:o.endsWith("://")?void 0:ct(o),lastUpdated:n,presence:u,git:c,status:d};continue}f=Mx(t,o,f),!((f.lastUpdated??0)>=a)&&(f.git!==c||f.presence!==u||f.name!==l||f.status!==d)&&(t[o]={...f,name:l,presence:u,git:c,status:d})}for(let i of e.files||[]){let o=typeof i?.uri=="string"?String(i.uri):"";if(!o)continue;hi(t,o,n);let l=typeof i.git=="string"?String(i.git):void 0,u=typeof i.status=="string"?i.status:void 0,c=i.presence??"unindexed",d=typeof i.os_uri=="string"?i.os_uri:void 0,f=t[o];if(!f){t[o]={storeKey:o,name:It(o),uri:o,type:"file",id:typeof i.id=="string"?i.id:void 0,os_uri:d,status:u,parentUri:ct(o),lastUpdated:n,category:typeof i.category=="string"?i.category:void 0,presence:c,pinned:i.pinned===!0,git:l},s&&u==="pending_review"&&s.add.add(o);continue}if(f=Mx(t,o,f),(f.lastUpdated??0)>=a)continue;let h={...f,name:It(o)||f.name,presence:c,status:u,os_uri:d,git:l};typeof i.id=="string"&&(h.id=i.id),"category"in i&&(h.category=typeof i.category=="string"?i.category:void 0),"version"in i&&(h.version=i.version),"pinned"in i&&(h.pinned=i.pinned===!0),t[o]=h,s&&f.status!==u&&(u==="pending_review"?s.add.add(o):f.status==="pending_review"&&s.remove.add(o))}}function yh(t,e,n){if(n.add.size===0&&n.remove.size===0)return t;let r=new Set(e);for(let a of n.add)r.add(a);for(let a of n.remove)r.delete(a);return t.pendingReviewPaths=r,t}var V2=4;function $2(t,e){if(t.endsWith("://"))return!0;if(!e.has(t))return!1;for(let n of Ra(t))if(!n.endsWith("://")&&!e.has(n))return!1;return!0}function Ex(t,e){return e.some(n=>t===n||t.startsWith(n.endsWith("://")?n:`${n}/`))}function Ox(t,e){let n=t;for(let[r,a]of Object.entries(t))a!==!0||!Ex(r,e)||(n===t&&(n={...t}),n[r]=!1);return n}function Nc(t,e){let n=new Set(e),r=Array.from(t.expandedFolders).filter(l=>!n.has(l));r.push(...n);let{kept:a,evicted:s}=Pc(r);if(s.length===0)return{expandedFolders:new Set(a)};let i=t.loadedFolders||{},o=Ox(i,s);return o===i?{expandedFolders:new Set(a)}:{expandedFolders:new Set(a),loadedFolders:o}}async function K2(t,e,n){if(t.length===0)return[];let r=Math.max(1,Math.min(e,t.length)),a=new Array(t.length),s=0;return await Promise.all(Array.from({length:r},async()=>{for(;;){let i=s++;if(i>=t.length)return;a[i]=await n(t[i])}})),a}async function X2(t,e){let{agentId:n,projectId:r,source:a,extraTargets:s,wide:i}=e,o=t.fences.resetEpoch,l=t.get(),u=l.loadedFolders||{},c=new Set;if(i)for(let p of Object.keys(u))Ke(p)===a&&$2(p,l.expandedFolders)&&c.add(p);for(let p of s)Ke(p)===a&&u[p]!==void 0&&c.add(p);let d=p=>{let g=p.indexOf("://"),m=(g>=0?p.slice(g+3):p).replace(/\/+$/,"");return m?m.split("/").length:0},f=Array.from(c).sort((p,g)=>d(g)-d(p));if(f.length===0)return;let h=await K2(f,V2,async p=>{let g=bh(t.fences,p),m=Date.now();try{let x=await io(n,r??void 0,{uri:p,recursive:!1},t.client);return Dx(t.fences,p,g)?{folderKey:p,res:x,issuedAt:m,ok:!0}:{folderKey:p,res:null,issuedAt:m,ok:!1}}catch{return{folderKey:p,res:null,issuedAt:m,ok:!1}}});t.set(p=>{if(o!==t.fences.resetEpoch)return p;let g={...p.files},m=Date.now(),x={add:new Set,remove:new Set},b=[],y=!1,C=!1;for(let R of h){if(!R.ok||!R.res){C=!0;continue}Fx(g,R.res,m,{issuedAt:R.issuedAt,pending:x}),R.res.truncated?C=!0:y=!0}let I=C===!!p.dirtySources[a]?p.dirtySources:(()=>{let R={...p.dirtySources};return C?R[a]=!0:delete R[a],R})(),L=p.loadedFolders;for(let R of h)!R.ok||!R.res||L?.[R.folderKey]!==!1||(L===p.loadedFolders&&(L={...L}),L[R.folderKey]=!0);if(!y)return yh({files:vh(g,p.expandedFolders,p.openFiles),dirtySources:I,loadedFolders:L},p.pendingReviewPaths,x);let v=new Map;for(let R of Object.keys(g)){let P=g[R]?.parentUri;if(!P)continue;let H=v.get(P);H?H.push(R):v.set(P,[R])}for(let R of h){if(!R.ok||!R.res)continue;let P=R.res;if(P.truncated)continue;let H=new Set;for(let w of P.files||[]){let N=typeof w?.uri=="string"?w.uri:"";N&&H.add(N)}for(let w of P.folders||[]){let N=typeof w=="string"?w:typeof w?.uri=="string"?w.uri:"";N&&H.add(N)}for(let w of v.get(R.folderKey)||[]){let N=g[w];if(N&&!H.has(w)&&!((N.lastUpdated??0)>=R.issuedAt)){if(N.type==="folder"){let K=(v.get(w)||[]).filter(F=>g[F]!==void 0);if(K.filter(F=>g[F].status!=="deleted").length>0)continue;K.length===0?delete g[w]:N.status!=="deleted"&&(g[w]={...N,status:"deleted",lastUpdated:m});continue}N.presence==="unindexed"?(delete g[w],b.push(w),N.status==="pending_review"&&x.remove.add(w)):N.status!=="deleted"&&(g[w]={...N,status:"deleted",lastUpdated:m},N.status==="pending_review"&&x.remove.add(w))}}}let O={files:vh(g,p.expandedFolders,p.openFiles),dirtySources:I,loadedFolders:L};if(b.length){let R=new Set(b),P=p.openFiles.filter(A=>!R.has(A));O.openFiles=P;let H={...p.tabMeta};for(let A of b)delete H[A];O.tabMeta=H,O.activeFile=p.activeFile&&R.has(p.activeFile)?P.length?P[P.length-1]:null:p.activeFile;let w={...p.fileContentByPath},N={...p.fileBaseContentByPath},j={...p.fileErrorByPath},K={...p.filePrevByPath};for(let A of b)delete w[A],delete N[A],delete j[A],delete K[A];O.fileContentByPath=w,O.fileBaseContentByPath=N,O.fileErrorByPath=j,O.filePrevByPath=K}return yh(O,p.pendingReviewPaths,x)})}async function Mc(t,e){let{agentId:n,projectId:r,source:a,targets:s}=e,i=e.wide!==!1;if(!n||!a)return;let o=t.fences.reconcileJobs.get(a);if(o){if(o.rerun=!0,i&&(o.wide=!0),s)for(let u of s)o.extra.add(u);await o.promise;return}let l={rerun:!1,wide:i,extra:new Set(s??[]),promise:Promise.resolve()};t.fences.reconcileJobs.set(a,l),l.promise=(async()=>{try{for(let u=0;u<j2;u++){l.rerun=!1;let c=l.wide;l.wide=!1;let d=Array.from(l.extra);if(l.extra.clear(),await X2(t,{agentId:n,projectId:r,source:a,extraTargets:d,wide:c}),!l.rerun)break}}finally{t.fences.reconcileJobs.delete(a)}})(),await l.promise}function Tc(t,e){let n=`${e}/`,r=Object.keys(t.get().files).filter(a=>a===e||a.startsWith(n));r.length!==0&&t.set(a=>{let s={...a.files};for(let h of r)delete s[h];let i=new Set(r),o=a.openFiles.filter(h=>!i.has(h)),l={...a.tabMeta},u={...a.fileContentByPath},c={...a.fileBaseContentByPath},d={...a.fileErrorByPath},f={...a.filePrevByPath};for(let h of r)delete l[h],delete u[h],delete c[h],delete d[h],delete f[h];return{files:s,openFiles:o,activeFile:a.activeFile&&i.has(a.activeFile)?o.length?o[o.length-1]:null:a.activeFile,tabMeta:l,fileContentByPath:u,fileBaseContentByPath:c,fileErrorByPath:d,filePrevByPath:f}})}var Y2=30;function vh(t,e,n){let r=Object.keys(t);if(r.length<=mh)return t;let a=new Set;for(let u of e){a.add(u);let c=u;for(;c;){a.add(c);let d=ct(c);if(!d||d===c)break;c=d}}for(let u of n){a.add(u);let c=ct(u);for(;c;){a.add(c);let d=ct(c);if(!d||d===c)break;c=d}}for(let u of r)u.endsWith("://")&&a.add(u);let s=r.filter(u=>{if(a.has(u))return!1;let c=t[u].parentUri;return!(c&&e.has(c))}).map(u=>({key:u,ts:t[u].lastUpdated??0})).sort((u,c)=>u.ts-c.ts),i=r.length-mh;if(i<=0||s.length===0)return t;let o={...t},l=Math.min(i,s.length);for(let u=0;u<l;u++)delete o[s[u].key];return console.warn("[Filesystem] cold-row eviction",{total:r.length,cap:mh,removed:l,protected:r.length-s.length}),o}var Bx="filesystem",Ll=120,xh=240,_x="neuralis.filesystem.sidebarWidth";function J2(){if(typeof window>"u")return xh;try{let t=window.localStorage.getItem(_x),e=t?Number(t):NaN;return Number.isFinite(e)&&e>=Ll?e:xh}catch{return xh}}function Z2(t){let e=q2(),n=t.client;return ih()((r,a)=>({windowId:t.windowId??null,client:n,files:{},folderBadges:{},fileContentByPath:{},fileBaseContentByPath:{},fileErrorByPath:{},filePrevByPath:{},openFiles:[],activeFile:null,tabMeta:{},activeUserId:t.userId??null,contextStateByKey:{},previewEditorsEnabled:t.previewEditorsEnabled??!1,expandedFolders:new Set,sidebarOpen:!0,sidebarWidth:J2(),sidebarView:"tree",activeAgentId:t.agentId??null,activeProjectId:t.projectId??null,sources:[],sourcesLoading:!0,activeSource:null,activeRepoRel:"",activeFolderPath:"brain://docs",uploading:!1,workspacePanels:{upload:!1,sources:!1,packages:!1,pending:!1},activeWorkspaceTab:"file",pendingSourceSuggestion:null,vectorHealthOpen:!1,diffViewMode:t.diffViewMode??"auto",pendingPanelFilter:{},loadedFolders:{},hydrationState:{},dirtySources:{},sourceChangeRevision:{},organizeError:null,snapshotError:void 0,pendingReviewPaths:new Set,pendingCount:0,pendingCountState:"stale",...Cx,...Ix(r,a),...Ax(r,a),...Rx,...Nx(r,a),toggleSidebar:()=>r(s=>({sidebarOpen:!s.sidebarOpen})),setSidebarView:s=>r(()=>({sidebarView:s})),setSidebarWidth:s=>r(()=>{let i=Math.max(Ll,Math.round(s));if(typeof window<"u")try{window.localStorage.setItem(_x,String(i))}catch{}return{sidebarWidth:i}}),setActiveFolderPath:s=>r(()=>({activeFolderPath:s?String(s):null})),setActiveSource:(s,i)=>r(()=>({activeSource:s,activeRepoRel:typeof i=="string"?i:"",gitOutgoingStat:null})),setWorkspacePanelOpen:(s,i)=>r(o=>{let l={upload:!1,sources:!1,packages:!1,pending:!1};i?l[s]=!0:(l.upload=o.workspacePanels.upload,l.sources=o.workspacePanels.sources,l.packages=o.workspacePanels.packages,l.pending=o.workspacePanels.pending,l[s]=!1);let u=i?s:o.activeWorkspaceTab===s?"file":o.activeWorkspaceTab;return{workspacePanels:l,activeWorkspaceTab:u}}),setPendingSourceSuggestion:s=>r(()=>({pendingSourceSuggestion:s})),setVectorHealthOpen:s=>r(()=>({vectorHealthOpen:s})),setActiveWorkspaceTab:s=>r(()=>({activeWorkspaceTab:s})),setDiffViewMode:s=>r(()=>({diffViewMode:s})),setPreviewEditorsEnabled:s=>r(()=>({previewEditorsEnabled:s})),reorderOpenFiles:(s,i)=>r(o=>{if(s===i)return o;let l=[...o.openFiles],u=l.indexOf(s),c=l.indexOf(i);if(u<0||c<0)return o;let[d]=l.splice(u,1);return l.splice(c,0,d),{openFiles:l}}),toggleTabPin:s=>r(i=>{let o=i.tabMeta[s]||{};return{tabMeta:{...i.tabMeta,[s]:{...o,pinned:!o.pinned,preview:!1}}}}),promoteTab:s=>r(i=>{let o=i.tabMeta[s];return!o||!o.preview?i:{tabMeta:{...i.tabMeta,[s]:{...o,preview:!1}}}}),closeAllFiles:()=>r(s=>{let i=s.openFiles.filter(l=>s.tabMeta[l]?.pinned),o=s.activeFile&&i.includes(s.activeFile)?s.activeFile:i[i.length-1]??null;return{openFiles:i,activeFile:o}}),closeSavedFiles:()=>r(s=>{let i=u=>{let c=s.fileBaseContentByPath[u],d=s.fileContentByPath[u];return typeof c=="string"&&c!==d},o=s.openFiles.filter(u=>s.tabMeta[u]?.pinned||i(u)||s.files[u]?.status==="pending_review"),l=s.activeFile&&o.includes(s.activeFile)?s.activeFile:o[o.length-1]??null;return{openFiles:o,activeFile:l}}),closeOtherFiles:s=>r(i=>{let o=i.openFiles.filter(l=>l===s||i.tabMeta[l]?.pinned);return{openFiles:o,activeFile:o.includes(s)?s:o[o.length-1]??null}}),setPendingPanelFilter:s=>r(()=>({pendingPanelFilter:s})),toggleFolder:s=>r(i=>{if(i.expandedFolders.has(s)){let u=new Set(Array.from(i.expandedFolders).filter(f=>!Ex(f,[s]))),c=i.loadedFolders||{},d=Ox(c,[s]);return d===c?{expandedFolders:u}:{expandedFolders:u,loadedFolders:d}}let o=!!i.folderBadges[s],l=o?{...i.folderBadges}:i.folderBadges;return o&&delete l[s],{...Nc(i,[s]),folderBadges:l}}),async ensureFolderLoaded({agentId:s,projectId:i,uri:o,force:l}){if(!s||!o)return;let u=a().loadedFolders?.[o];if(!l&&u)return;if(!l&&u===!1){await Mc({get:a,set:r,fences:e,client:n},{agentId:s,projectId:i,source:Ke(o),targets:[o],wide:!1});return}let c=e.liveFolderLoadInFlight.get(o);if(c){await c;return}r(f=>({hydrationState:{...f.hydrationState||{},[o]:"loading"}}));let d=(async()=>{let f=bh(e,o),h=Date.now();try{let p=await io(s,i??void 0,{uri:o,recursive:!1},n);if(!Dx(e,o,f)){r(g=>({hydrationState:{...g.hydrationState||{},[o]:g.loadedFolders?.[o]?"ready":"idle"}}));return}r(g=>{let m={...g.files},x={add:new Set,remove:new Set};return Fx(m,p,Date.now(),{issuedAt:h,pending:x}),yh({files:vh(m,g.expandedFolders,g.openFiles),loadedFolders:{...g.loadedFolders||{},[o]:!0},hydrationState:{...g.hydrationState||{},[o]:"ready"}},g.pendingReviewPaths,x)})}catch(p){console.error("[Filesystem] subfolder load failed",p),r(g=>({hydrationState:{...g.hydrationState||{},[o]:"error"}}))}})();e.liveFolderLoadInFlight.set(o,d);try{await d}finally{e.liveFolderLoadInFlight.delete(o)}},clearOrganizeError:()=>r(()=>({organizeError:null})),clearSnapshotError:()=>r(()=>({snapshotError:void 0})),setSourceDirty:(s,i)=>r(o=>{if(!!o.dirtySources[s]===i)return o;let u={...o.dirtySources};return i?u[s]=!0:delete u[s],{dirtySources:u}}),async reconcileSourceFolders({agentId:s,projectId:i,source:o}){await Mc({get:a,set:r,fences:e,client:n},{agentId:s,projectId:i,source:o})},fenceInFlightWriters(){e.resetEpoch+=1;for(let s of Array.from(e.folderGeneration.keys()))bh(e,s);e.liveFolderLoadInFlight.clear(),e.rehydrateInFlight.clear()},resetClientState(s){let i=a();if(!i.activeProjectId||s.projectId!==i.activeProjectId||s.level!=="project"&&s.agentId!==i.activeAgentId||(s.level==="widget"||s.level==="instance")&&(s.widgetType!==Bx||s.instanceId!==i.windowId))return;a().fenceInFlightWriters();let o=`${i.activeUserId??""}::${i.activeProjectId}::`,l=pi(i.activeUserId,i.activeProjectId,i.activeAgentId??""),u={};for(let[c,d]of Object.entries(i.contextStateByKey))(s.level==="project"?c.startsWith(o):c===l)||(u[c]=d);r(()=>({...ho(),contextStateByKey:u}))},async reconcileFolders({agentId:s,projectId:i,folders:o}){if(!s||!Array.isArray(o)||o.length===0)return;let l=new Map,u=a().loadedFolders||{};for(let c of o){if(!c)continue;let d=Ke(c);if(!d||u[c]===!1)continue;if(!u[c]){a().setSourceDirty(d,!0);continue}let f=l.get(d);f?f.push(c):l.set(d,[c])}l.size!==0&&await Promise.all(Array.from(l.entries()).map(([c,d])=>Mc({get:a,set:r,fences:e,client:n},{agentId:s,projectId:i,source:c,targets:d})))},async refreshTree({agentId:s,projectId:i}){if(!s)return;await a().loadList({agentId:s,projectId:i});let o=a(),l=new Set;for(let[u,c]of Object.entries(o.loadedFolders||{})){if(!c)continue;let d=Ke(u);d&&l.add(d)}await Promise.all(Array.from(l).map(u=>Mc({get:a,set:r,fences:e,client:n},{agentId:s,projectId:i,source:u})))},setActiveFile:s=>{r({activeFile:s,activeWorkspaceTab:"file"}),a().rehydrateActiveTab()},async rehydrateActiveTab(){let s=a(),i=s.activeFile,o=s.activeAgentId;if(!(!i||!o)&&!Ac(s,i)&&!e.rehydrateInFlight.has(i)){e.rehydrateInFlight.add(i);try{let l=s.tabMeta[i]?.sourceAgentId,u=l&&l!==o&&!/^__.*__$/.test(l)?l:void 0;await s.openFile({agentId:o,projectId:s.activeProjectId,uri:i,readAgentId:u,revealPane:!1})}finally{e.rehydrateInFlight.delete(i)}}},closeFile:s=>r(i=>{let o=i.openFiles.filter(c=>c!==s),l=i.activeFile===s?o.length?o[o.length-1]:null:i.activeFile,u={...i.tabMeta};return delete u[s],{openFiles:o,activeFile:l,tabMeta:u}}),replaceFilePath:(s,i)=>r(o=>{if(!s||!i||s===i)return o;let l=o.files[s],u={...o.files};l&&(delete u[s],u[i]={...l,storeKey:i,uri:i,name:It(i)||l.name,parentUri:ct(i),lastUpdated:Date.now()});let c={...o.fileContentByPath},d={...o.fileBaseContentByPath},f={...o.fileErrorByPath},h={...o.filePrevByPath};Object.prototype.hasOwnProperty.call(c,s)&&(c[i]=c[s],delete c[s]),Object.prototype.hasOwnProperty.call(d,s)&&(d[i]=d[s],delete d[s]),Object.prototype.hasOwnProperty.call(f,s)&&(f[i]=f[s],delete f[s]),Object.prototype.hasOwnProperty.call(h,s)&&(h[i]=h[s],delete h[s]);let p=[];for(let g of o.openFiles){let m=g===s?i:g;p.includes(m)||p.push(m)}return{files:u,fileContentByPath:c,fileBaseContentByPath:d,fileErrorByPath:f,filePrevByPath:h,openFiles:p,activeFile:o.activeFile===s?i:o.activeFile}}),patchFileNode:(s,i)=>r(o=>{let l=o.files[s];return l?{files:{...o.files,[s]:{...l,...i,lastUpdated:Date.now()}}}:o}),clearFilePrev:s=>r(i=>{if(!i.filePrevByPath[s])return i;let o={...i.filePrevByPath};return delete o[s],{filePrevByPath:o}}),upsertFileNodeFromEvent:({id:s,uri:i,folder_ancestors:o,status:l,sourceAgentId:u,sourceProjectId:c})=>r(d=>{if(!i||!d.files[i]&&l==="deleted")return d;let f=Date.now(),h={...d.files},p=o||Ra(i);hi(h,i,f);let g=ct(i),m=h[g];m&&m.type==="folder"&&(h[g]={...m,sourceAgentId:u??m.sourceAgentId,sourceProjectId:c??m.sourceProjectId});let x=h[i],b=Ke(i)==="brain";h[i]={...x||gh(i),id:s??x?.id,name:It(i)||x?.name||"file",type:"file",uri:i,status:l??x?.status,parentUri:g,sourceAgentId:u??x?.sourceAgentId,sourceProjectId:c??x?.sourceProjectId,lastUpdated:f,presence:x?.presence??(b?"brain":"synced"),git:x?.git};let y=new Set(d.pendingReviewPaths);if(l==="pending_review"?y.add(i):x?.status==="pending_review"&&l&&l!=="pending_review"&&y.delete(i),l==="active"&&x?.status==="pending_review"&&d.filePrevByPath[i]){let I={...d.filePrevByPath};return delete I[i],{files:h,filePrevByPath:I,pendingReviewPaths:y}}return{files:h,pendingReviewPaths:y}}),removeFilePath:s=>r(i=>{if(!s||!i.files[s]&&!i.openFiles.includes(s)&&!i.tabMeta[s])return i;let o={...i.files};delete o[s];let l=i.openFiles.filter(g=>g!==s),u=i.activeFile===s?l.length?l[l.length-1]:null:i.activeFile,c={...i.fileContentByPath},d={...i.fileBaseContentByPath},f={...i.fileErrorByPath},h={...i.filePrevByPath};delete c[s],delete d[s],delete f[s],delete h[s];let p={...i.tabMeta};return delete p[s],{files:o,openFiles:l,activeFile:u,tabMeta:p,fileContentByPath:c,fileBaseContentByPath:d,fileErrorByPath:f,filePrevByPath:h}}),incrementFolderBadges:s=>r(i=>{if(!Array.isArray(s)||s.length===0)return i;let o={...i.folderBadges};for(let l of s)l&&(i.expandedFolders.has(l)||(o[l]=(o[l]||0)+1));return{folderBadges:o}}),clearFolderBadge:s=>r(i=>{if(!s||!i.folderBadges[s])return i;let o={...i.folderBadges};return delete o[s],{folderBadges:o}}),autoExpandToFile:s=>r(i=>Nc(i,[kr(s),...Ra(s)])),updateFileContent:(s,i)=>r(o=>({fileContentByPath:{...o.fileContentByPath,[s]:i},fileErrorByPath:{...o.fileErrorByPath,[s]:void 0}})),async saveFileInPlace({agentId:s,projectId:i,readAgentId:o,node:l,targetUri:u,content:c,currentContent:d}){let f=l.uri,h=!!u&&u!==f,p=c!==d;if(!h&&!p)return{uri:f,moved:!1,contentChanged:!1};let g=e.resetEpoch,m=()=>g!==e.resetEpoch,x=f;if(h){let b=await Er({agentId:s,...i?{projectId:i}:{},id:l.id,uri:f,move:u},n);if(!b||b.ok!==!0)throw new Error(Pa(b,"Move failed"));if(x=u,m())return{uri:x,moved:h,contentChanged:!1};a().replaceFilePath(l.storeKey||f,u)}if(p){let b=await Er({agentId:s,...i?{projectId:i}:{},id:l.id,uri:x,overwrite:{content:c}},n);if(!b||b.ok!==!0)throw new Error(Pa(b,"Save failed"));if(m())return{uri:x,moved:h,contentChanged:p};let y=h?x:l.storeKey||f;a().updateFileContent(y,c),a().patchFileNode(y,{status:"pending_review"})}return await a().reconcileFolders({agentId:s,projectId:i,folders:Array.from(new Set([ct(f),ct(x)]))}),m()?{uri:x,moved:h,contentChanged:p}:(await a().openFile({agentId:s,projectId:i,uri:x,readAgentId:o,force:!0}),{uri:x,moved:h,contentChanged:p})},async refreshPendingCount({agentId:s,projectId:i}){if(!s)return;let o=++e.pendingCountSeq,l;try{l=await ax({agentId:s,...i?{projectId:i}:{}},n)}catch{o===e.pendingCountSeq&&a().activeAgentId===s&&a().activeProjectId===i&&r({pendingCountState:"stale"});return}if(o!==e.pendingCountSeq)return;let u=a();if(!(u.activeAgentId!==s||u.activeProjectId!==i)){if(l.unavailable?.includes("journal")&&l.unavailable.includes("vector")){r({pendingCountState:"stale"});return}r(()=>({pendingCount:l.count,pendingCountState:l.exact?"exact":"partial"}))}},async markFileDeleted({agentId:s,projectId:i,node:o}){let l=e.resetEpoch,u=await Er({agentId:s,...i?{projectId:i}:{},id:o.id,uri:o.uri,delete:!0},n);if(!u||u.ok!==!0)throw new Error(Pa(u,"Delete failed"));l===e.resetEpoch&&await a().reconcileFolders({agentId:s,projectId:i,folders:[ct(o.uri)]})},async moveFileToFolder({agentId:s,projectId:i,fromUri:o,toFolderUri:l,id:u}){if(!s||!o||!l)return;let c=It(o);if(!c)return;let d=l.endsWith("://")?`${l}${c}`:`${l}/${c}`;if(d===o)return;let f=ct(o),h=a().files[o]?.type==="folder",p;try{p=await Er({agentId:s,...i?{projectId:i}:{},id:u,uri:o,move:d},n)}catch(m){console.error("[Filesystem] move failed",o,m),r(()=>({organizeError:"Move failed"}));return}if(p&&p.ok===!1){console.error("[Filesystem] move rejected",o,p.code,p.error),r(()=>({organizeError:Pa(p,"Move rejected")})),await a().reconcileFolders({agentId:s,projectId:i,folders:[f,l]});return}let g=p?.warning==="moved_with_source_retained";g&&r(()=>({organizeError:"Copied to the destination, but the original could not be removed \u2014 both copies exist."})),h?(g||Tc({get:a,set:r,fences:e,client:n},o),await a().ensureFolderLoaded({agentId:s,projectId:i,uri:l,force:!0})):(r(m=>{let x=m.openFiles.map(b=>b===o?d:b);return{activeFolderPath:l,openFiles:Array.from(new Set(x)),activeFile:m.activeFile===o?d:m.activeFile}}),g||a().replaceFilePath(o,d)),await a().reconcileFolders({agentId:s,projectId:i,folders:[f,l]})},async renameNode({agentId:s,projectId:i,uri:o,id:l,newName:u}){let c=(u??"").trim();if(!s||!o||!c||c===It(o))return;let d=ct(o),f=d.endsWith("://")?`${d}${c}`:`${d}/${c}`;if(f===o)return;let h=a().files[o]?.type==="folder",p;try{p=await Er({agentId:s,...i?{projectId:i}:{},id:l,uri:o,move:h?f:c},n)}catch(g){console.error("[Filesystem] rename failed",o,g),r(()=>({organizeError:"Rename failed"}));return}if(p&&p.ok===!1){console.error("[Filesystem] rename rejected",o,p.code,p.error),r(()=>({organizeError:Pa(p,"Rename rejected")})),await a().reconcileFolders({agentId:s,projectId:i,folders:[d]});return}h?(Tc({get:a,set:r,fences:e,client:n},o),await a().ensureFolderLoaded({agentId:s,projectId:i,uri:d,force:!0})):a().replaceFilePath(o,f),await a().reconcileFolders({agentId:s,projectId:i,folders:[d]})},async createNode({agentId:s,projectId:i,parentUri:o,name:l,kind:u}){let c=(l??"").trim();if(!s||!o||!c)return;let d=o.endsWith("://")?`${o}${c}`:`${o}/${c}`,f=e.resetEpoch;try{if(u==="folder"){let h=await Er({agentId:s,...i?{projectId:i}:{},uri:d,mkdir:!0},n);h?.ok&&f===e.resetEpoch?r(p=>({...Nc(p,[o]),files:{...p.files,[d]:{storeKey:d,name:c,uri:d,type:"folder",parentUri:o,presence:"unindexed",lastUpdated:Date.now()}}})):h&&h.ok===!1&&(console.error("[Filesystem] create folder rejected",d,h.code,h.error),r(()=>({organizeError:Pa(h,"Could not create folder")})))}else await kc({agentId:s,...i?{projectId:i}:{},file:new File([""],c),uri:o,tags:[]},n)}catch(h){console.error("[Filesystem] create failed",u,d,h),r(()=>({organizeError:`Could not create ${u==="folder"?"folder":"file"}`}))}await a().reconcileFolders({agentId:s,projectId:i,folders:[o]})},async pasteNodes({agentId:s,projectId:i,targetFolderUri:o,op:l,uris:u}){if(!s||!o||!Array.isArray(u)||u.length===0)return;let c=new Set([o]),d=[];for(let f of u){if(!f)continue;let h=It(f);if(!h)continue;let p=o.endsWith("://")?`${o}${h}`:`${o}/${h}`;if(p!==f){c.add(ct(f));try{if(l==="copy"){let g=await Er({agentId:s,...i?{projectId:i}:{},uri:f,copy:p},n);g&&g.ok===!1&&d.push(h)}else{let g=await Er({agentId:s,...i?{projectId:i}:{},uri:f,move:p},n);g&&g.ok===!1?d.push(h):g?.warning==="moved_with_source_retained"?d.push(`${h} (original retained)`):a().files[f]?.type==="folder"&&Tc({get:a,set:r,fences:e,client:n},f)}}catch(g){console.error("[Filesystem] paste failed",l,f,g),d.push(h)}}}d.length&&r(()=>({organizeError:`${l==="copy"?"Copy":"Move"} incomplete: ${d.join(", ")}`})),await a().reconcileFolders({agentId:s,projectId:i,folders:Array.from(c)})},async deleteNodes({agentId:s,projectId:i,targets:o}){if(!s||!Array.isArray(o)||o.length===0)return;let l=new Set,u=[],c=null;for(let d of o){if(!d?.uri)continue;l.add(ct(d.uri));let f=a().files[d.uri]?.type==="folder";try{let h=await Er({agentId:s,...i?{projectId:i}:{},id:d.id,uri:d.uri,delete:!0},n);if(h&&h.ok===!1){console.error("[Filesystem] delete rejected",d.uri,h.code,h.error),u.push(It(d.uri)||d.uri),(typeof h.affected=="number"||h.failed?.length)&&(c={affected:h.affected,failed:h.failed});continue}f?Tc({get:a,set:r,fences:e,client:n},d.uri):a().patchFileNode(d.uri,{status:"deleted"})}catch(h){console.error("[Filesystem] delete failed",d.uri,h),u.push(It(d.uri)||d.uri)}}if(u.length){let d=c?.failed?.length?` \u2014 ${c.affected??0} removed, could not remove: ${c.failed.slice(0,5).join(", ")}${c.failed.length>5?"\u2026":""}`:"";r(()=>({organizeError:`Delete failed: ${u.join(", ")}${d}`}))}await a().reconcileFolders({agentId:s,projectId:i,folders:Array.from(l)})},async openFile({agentId:s,projectId:i,uri:o,readAgentId:l,force:u,revealPane:c=!0}){if(!s||!o)return;r(p=>{let g=p.openFiles.includes(o),m=p.previewEditorsEnabled&&!g&&!p.tabMeta[o]?.pinned,x=p.openFiles,b=p.tabMeta;if(m){let C=p.openFiles.find(I=>I!==o&&p.tabMeta[I]?.preview&&!p.tabMeta[I]?.pinned);C&&(x=x.filter(I=>I!==C),b={...b},delete b[C]),b={...b,[o]:{...b[o]||{},preview:!0}}}let y=x.includes(o)?x:[...x,o];if(y.length>Y2){let C=y.findIndex(I=>I!==o&&!p.tabMeta[I]?.pinned);C>=0&&(y=y.filter((I,L)=>L!==C))}return{openFiles:y,activeFile:o,activeAgentId:s,activeProjectId:i,...c?{activeWorkspaceTab:"file"}:{},tabMeta:b}}),a().autoExpandToFile(o);{let p=new Set([kr(o),...Ra(o)]);for(let g of p)!g||g===o||a().ensureFolderLoaded({agentId:s,projectId:i,uri:g})}let d=a(),f=typeof d.fileBaseContentByPath[o]=="string"||typeof d.fileContentByPath[o]=="string"&&(d.fileContentByPath[o]?.length||0)>0;if(!u&&f)return;let h=e.resetEpoch;try{let p=await oo({agentId:l||s,...i?{projectId:i}:{},files:[o]},n);if(h!==e.resetEpoch)return;let g=co(p);if(g.length>0){let m=g[0],x=fo(m),b=typeof m.error=="string"?m.error:void 0,y=typeof m.code=="string"&&m.code==="not_found";if(b&&y){a().removeFilePath(o);return}let C=typeof m.status=="string"?String(m.status):void 0,I=typeof m.category=="string"?m.category:void 0,L=Array.isArray(m.tags)?m.tags:void 0,v=m.metadata&&typeof m.metadata=="object"?m.metadata:void 0,k=typeof m.createdAt=="string"?m.createdAt:void 0,O=typeof m.updatedAt=="string"?m.updatedAt:void 0,R=m.version&&typeof m.version=="object"?m.version:void 0,P=typeof m.readSource=="string"?m.readSource:void 0,H=typeof m.id=="string"?m.id:void 0,w=typeof m.uri=="string"?String(m.uri):o,N=typeof m.agent_id=="string"?String(m.agent_id):l||s,j=typeof m.project_id=="string"?String(m.project_id):i||void 0,K=Ke(w)==="brain",A=R?.sync?.status,F=Lc(R?.baseline);r(_=>{let X=_.files[w],re=_.fileContentByPath[w],ae=_.fileBaseContentByPath[w],Le=b&&typeof re=="string"?re:x,ye=b&&typeof ae=="string"?ae:x,q={..._.files},Q=!!H||!!C||!!R,te=K?"brain":X?.presence??(Q?"synced":P==="live"?"unindexed":"synced");hi(q,w,Date.now());let ge=_.openFiles.includes(w)?_.openFiles:_.openFiles.map(de=>de===o?w:de);return{files:{...q,[w]:{...X||gh(w),id:H??X?.id,name:String(m.filename||X?.name||It(w)),type:"file",uri:w,parentUri:ct(w),status:C??X?.status,sourceAgentId:N,sourceProjectId:j??X?.sourceProjectId,lastUpdated:X?.lastUpdated??Date.now(),category:I??X?.category,tags:L??X?.tags,metadata:v??X?.metadata,createdAt:k??X?.createdAt,updatedAt:O??X?.updatedAt,version:R??X?.version,presence:te,readSource:P??X?.readSource}},fileContentByPath:{..._.fileContentByPath,[w]:Le},fileBaseContentByPath:{..._.fileBaseContentByPath,[w]:ye},fileErrorByPath:{..._.fileErrorByPath,[w]:b},filePrevByPath:{..._.filePrevByPath,[w]:F},openFiles:Array.from(new Set(ge)),activeFile:w,tabMeta:{..._.tabMeta,[w]:{..._.tabMeta[w]||_.tabMeta[o]||{},name:String(m.filename||X?.name||It(w)),status:C??X?.status,sourceAgentId:N}}}})}}catch(p){let g=p instanceof Error?p.message:"Read failed";if(console.error("[Filesystem] read failed",p),h!==e.resetEpoch)return;r(m=>({files:{...m.files,[o]:{...m.files[o]||gh(o),sourceAgentId:l||s,sourceProjectId:i||void 0,lastUpdated:m.files[o]?.lastUpdated??Date.now()}},fileErrorByPath:{...m.fileErrorByPath,[o]:g}}))}},async applyNav({agentId:s,projectId:i,nav:o,readAgentId:l,force:u}){if(!s||!o||o.kind!=="filesystem")return;let c=String(o.action||""),d=o.uri;if((c==="read"||c==="open"||c==="modify"||c==="save")&&d){await a().openFile({agentId:s,projectId:i,uri:d,readAgentId:l,force:u});return}if(c==="open-pending"){r(()=>({activeAgentId:s,activeProjectId:i})),a().setPendingPanelFilter(o.filter??{}),a().setWorkspacePanelOpen("pending",!0);return}if(c==="open-sources"||c==="open-vector-health"){r(()=>({activeAgentId:s,activeProjectId:i,...c==="open-vector-health"?{vectorHealthOpen:!0}:{}})),a().setWorkspacePanelOpen("sources",!0);return}c==="list"&&d&&r(f=>{let h=kr(d),p=f.expandedFolders.has(d)&&f.expandedFolders.has(h),g=f.activeAgentId===s,m=f.activeProjectId===i;return p&&g&&m?f:{...Nc(f,[h,d]),activeAgentId:s,activeProjectId:i}})},async upload({agentId:s,projectId:i,file:o,uri:l}){if(!s)return;let u=l||"brain://docs";r(()=>({uploading:!0}));try{await kc({agentId:s,...i?{projectId:i}:{},file:o,uri:u,tags:["upload"]},n),await a().reconcileFolders({agentId:s,projectId:i,folders:[u]})}finally{r(()=>({uploading:!1}))}},async uploadMany({agentId:s,projectId:i,files:o,uri:l}){if(!s)return;let u=Array.isArray(o)?o.filter(Boolean):[];if(u.length===0)return;let c=l||"brain://docs";r(()=>({uploading:!0}));try{for(let d of u)await kc({agentId:s,...i?{projectId:i}:{},file:d,uri:c,tags:["upload"]},n);await a().reconcileFolders({agentId:s,projectId:i,folders:[c]})}finally{r(()=>({uploading:!1}))}},...t.projection?Lx(t.projection):{}}))}var po=ih()(E0(()=>({previewEditorsEnabled:!1,diffViewMode:"auto",activeUserId:null,activeAgentId:null,activeProjectId:null,contexts:{}}),{name:"neuralis.filesystem.tabs",version:2,migrate:(t,e)=>{if(e>=2)return t;let n=t??{},r=n.activeAgentId?pi(null,n.activeProjectId??null,n.activeAgentId):null;return{previewEditorsEnabled:n.previewEditorsEnabled??!1,diffViewMode:n.diffViewMode??"auto",activeUserId:null,activeAgentId:n.activeAgentId??null,activeProjectId:n.activeProjectId??null,contexts:r?{[r]:Rc({...ho(),openFiles:n.openFiles??[],activeFile:n.activeFile??null,tabMeta:n.tabMeta??{}})}:{}}},merge:(t,e)=>{let n=t;return n?{previewEditorsEnabled:n.previewEditorsEnabled??e.previewEditorsEnabled,diffViewMode:n.diffViewMode??e.diffViewMode,activeUserId:n.activeUserId??null,activeAgentId:n.activeAgentId??null,activeProjectId:n.activeProjectId??null,contexts:n.contexts??{},...n.windows?{windows:n.windows}:{}}:e},storage:lh(()=>typeof window<"u"&&window.localStorage?window.localStorage:{getItem:()=>null,setItem:()=>{},removeItem:()=>{}}),partialize:t=>({previewEditorsEnabled:t.previewEditorsEnabled,diffViewMode:t.diffViewMode,activeUserId:t.activeUserId,activeAgentId:t.activeAgentId,activeProjectId:t.activeProjectId,contexts:t.contexts,...t.windows?{windows:t.windows}:{}})}));function Q2(t,e){return t.userId===e.userId&&t.projectId===e.projectId&&t.agentId===e.agentId}function eA(t){let{userId:e,projectId:n,agentId:r,...a}=t;return a}function tA(t){let e=po.getState(),n=e.windows?.[t.windowId],r=n&&Q2(n,t)?eA(n):void 0;return Z2({client:(0,Tx.createPackageApi)({slug:"brain-core",getProjectId:()=>t.projectId,getAgentId:()=>t.agentId}),windowId:t.windowId,userId:t.userId,projectId:t.projectId,agentId:t.agentId,previewEditorsEnabled:e.previewEditorsEnabled,diffViewMode:e.diffViewMode,...r?{projection:r}:{}})}var nA=["openFiles","activeFile","tabMeta","expandedFolders","sidebarView","activeWorkspaceTab","workspacePanels","activeFolderPath"];function rA(t,e){let n=JSON.stringify(Rc(t.getState()));return t.subscribe((r,a)=>{if(r.previewEditorsEnabled!==a.previewEditorsEnabled||r.diffViewMode!==a.diffViewMode){let o=po.getState();(o.previewEditorsEnabled!==r.previewEditorsEnabled||o.diffViewMode!==r.diffViewMode)&&po.setState({previewEditorsEnabled:r.previewEditorsEnabled,diffViewMode:r.diffViewMode})}if(!nA.some(o=>r[o]!==a[o])||r.activeUserId!==e.userId||r.activeProjectId!==e.projectId||r.activeAgentId!==e.agentId)return;let s=Rc(r),i=JSON.stringify(s);i!==n&&(n=i,po.setState(o=>({windows:{...o.windows??{},[e.windowId]:{userId:e.userId,projectId:e.projectId,agentId:e.agentId,...s}}})))})}var wh=new Set,Hx=null;function Ux(t){Hx=t}function aA(t,e){let n={identity:e,store:t};wh.add(n);let r=rA(t,e);return()=>{r(),wh.delete(n),t.getState().fenceInFlightWriters()}}function sA(t,e){return t.projectId!==e.projectId?!1:t.level==="project"?!0:t.agentId!==e.agentId?!1:t.level==="agent"||t.instanceId===e.windowId}function iA(t,e){if((t.level==="instance"||t.level==="widget")&&t.widgetType!==Bx)return;let n=po.getState(),r=(o,l)=>l.projectId!==t.projectId?!1:t.level==="instance"||t.level==="widget"?o===t.instanceId&&l.agentId===t.agentId:e===null||l.userId!==e?!1:t.level==="project"||l.agentId===t.agentId,a=o=>t.level==="instance"?!1:t.level==="project"?o.startsWith(`${e??""}::${t.projectId}::`):o===pi(e,t.projectId,t.agentId),s=n.windows;for(let[o,l]of Object.entries(n.windows??{}))r(o,l)&&(s===n.windows&&(s={...n.windows}),delete s[o]);let i=n.contexts;for(let o of Object.keys(n.contexts))a(o)&&(i===n.contexts&&(i={...n.contexts}),delete i[o]);s===n.windows&&i===n.contexts||po.setState({contexts:i,...s?{windows:s}:{}})}function Gx(t){for(let e of wh)sA(t,e.identity)&&e.store.getState().resetClientState(t);iA(t,Hx)}function zx(t,e,n,r){let a=(0,Na.useMemo)(()=>{if(!t||!e||!n||!r)return null;let s={windowId:t,userId:e,projectId:n,agentId:r};return{identity:s,store:tA(s)}},[t,e,n,r]);return(0,Na.useLayoutEffect)(()=>a?aA(a.store,a.identity):void 0,[a]),a?.store??null}var Wx=(0,Na.createContext)(null);function jx({store:t,children:e}){return(0,Na.createElement)(Wx.Provider,{value:t},e)}function mi(){let t=(0,Na.useContext)(Wx);if(!t)throw new Error("useFilesystemStore must be used inside a Files window (FilesystemStoreProvider)");return t}function B(t){return F0(mi(),t)}var su=W(nr(),1);var Dc=W(Je(),1);var qx=t=>t?.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();function Vx(t,e,n=[]){if(e==null)throw new Error("[lucide]: iconNode is required when icon name is used");return{name:qx(t),size:24,node:e,...n.length>0?{aliases:n}:{}}}var $x=t=>{let e="",n=!1;for(let r of t){if(r==="-"||r==="_"||r<=" "){n=e.length>0;continue}e.length===0?e+=r.toLowerCase():e+=n?r.toUpperCase():r,n=!1}return e};var Kx=t=>{let e=$x(t);return e.charAt(0).toUpperCase()+e.slice(1)};var Pl=W(Je(),1);var Al=(...t)=>t.filter((e,n,r)=>!!e&&e.trim()!==""&&r.indexOf(e)===n).join(" ").trim();var Rs={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":2,"stroke-linecap":"round","stroke-linejoin":"round"};function kh(t){return t!=null}function Xx(t,e={}){let n=e.attributeNames??{},r=f=>n[f]??f,a=t.size??t.width??Rs.width,s=t.size??t.height??Rs.height,i=t.aliases?.filter(f=>typeof f=="string"&&f.trim()!=="").map(f=>`lucide-${f}`)??[],o=[...t.name?[`lucide-${t.name}`]:[],...i],l=e.className?.split(" ").filter(Boolean)??[],u=e.includeDefaultClasses===!1?Al(...l):Al("lucide",...o,...l),c=e.absoluteStrokeWidth?Number(e.strokeWidth??Rs["stroke-width"])*Number(t.size??t.width??Rs.width)/Number(e.size??e.width??Rs.width):e.strokeWidth??Rs["stroke-width"];return["svg",{...Object.entries(Rs).reduce((f,[h,p])=>(f[r(h)]=p,f),{}),..."color"in e&&e.color&&{[r("stroke")]:e.color},..."size"in e&&kh(e.size)&&{[r("width")]:e.size,[r("height")]:e.size},..."width"in e&&kh(e.width)&&{[r("width")]:e.width},..."height"in e&&kh(e.height)&&{[r("height")]:e.height},[r("stroke-width")]:c,...u&&{[r("class")]:u},[r("viewBox")]:`0 0 ${a} ${s}`,...e.hasA11yProp===!1?{[r("aria-hidden")]:"true"}:{},..."attributes"in e&&e.attributes},t.node.map(f=>{let[h,p,g]=f,m=e.nonScalingStroke?{[r("vector-effect")]:"non-scaling-stroke",...p}:p;return g?[h,m,g]:[h,m]})]}function Yx(t,e={}){return Xx(t,{...e,attributeNames:{...e.attributeNames,class:"className","stroke-width":"strokeWidth","stroke-linecap":"strokeLinecap","stroke-linejoin":"strokeLinejoin","vector-effect":"vectorEffect"}})}var Jx=t=>{for(let e in t)if(e.startsWith("aria-")||e==="role"||e==="title")return!0;return!1};var mo=W(Je(),1);var oA=(0,mo.createContext)({});var Zx=()=>(0,mo.useContext)(oA);var Qx=(0,Pl.forwardRef)(({color:t,size:e,width:n,height:r,strokeWidth:a,absoluteStrokeWidth:s,nonScalingStroke:i,className:o="",children:l,iconNode:u=[],icon:c={node:u,aliases:[],size:24},...d},f)=>{let{size:h=24,strokeWidth:p=2,absoluteStrokeWidth:g=!1,nonScalingStroke:m=!1,color:x="currentColor",className:b=""}=Zx()??{},y=!!l||Jx(d),[C,I,L=[]]=Yx(c,{color:t??x,width:n??e??h,height:r??e??h,strokeWidth:a??p,absoluteStrokeWidth:s??g,nonScalingStroke:i??m,className:Al(b,o),hasA11yProp:y,attributes:d});return(0,Pl.createElement)(C,{ref:f,...I},[...L.map(([v,k])=>(0,Pl.createElement)(v,k)),...Array.isArray(l)?l:[l]])});function z(t,e=[],n=[]){let r=typeof t=="string"?Vx(t,e,n):t,a=(0,Dc.forwardRef)(({className:s,...i},o)=>(0,Dc.createElement)(Qx,{ref:o,icon:r,className:s,...i}));return r.name&&(a.displayName=Kx(r.name)),a}var eb={name:"archive",size:24,node:[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]]};eb.node;var go=z(eb);var tb={name:"arrow-down",size:24,node:[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]};tb.node;var Rl=z(tb);var nb={name:"arrow-right",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]};nb.node;var xo=z(nb);var rb={name:"arrow-up-down",size:24,node:[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]]};rb.node;var Nl=z(rb);var ab={name:"arrow-up",size:24,node:[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]};ab.node;var Ml=z(ab);var sb={name:"bot",size:24,node:[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]]};sb.node;var Tl=z(sb);var ib={name:"braces",size:24,node:[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]],aliases:["curly-braces"]};ib.node;var Ma=z(ib);var ob={name:"check-check",size:24,node:[["path",{d:"M18 6 7 17l-5-5",key:"116fxf"}],["path",{d:"m22 10-7.5 7.5L13 16",key:"ke71qq"}]]};ob.node;var Ns=z(ob);var lb={name:"check",size:24,node:[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]};lb.node;var Vn=z(lb);var ub={name:"chevron-down",size:24,node:[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]};ub.node;var qt=z(ub);var cb={name:"chevron-left",size:24,node:[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]};cb.node;var Dl=z(cb);var db={name:"chevron-right",size:24,node:[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]};db.node;var Sn=z(db);var fb={name:"chevron-up",size:24,node:[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]]};fb.node;var ss=z(fb);var hb={name:"circle-alert",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]],aliases:["alert-circle"]};hb.node;var Ms=z(hb);var pb={name:"circle-check",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16 9-5.5 5.5L8 12",key:"xofnsj"}]],aliases:["check-circle-2"]};pb.node;var ha=z(pb);var mb={name:"circle-question-mark",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]],aliases:["help-circle","circle-help"]};mb.node;var pa=z(mb);var gb={name:"circle-x",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]],aliases:["x-circle"]};gb.node;var ma=z(gb);var xb={name:"clipboard-paste",size:24,node:[["path",{d:"M11 14h10",key:"1w8e9d"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v1.344",key:"1e62lh"}],["path",{d:"m17 18 4-4-4-4",key:"z2g111"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113",key:"bjbb7m"}],["rect",{x:"8",y:"2",width:"8",height:"4",rx:"1",key:"ublpy"}]]};xb.node;var Fl=z(xb);var bb={name:"clock-3",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6h4",key:"135r8i"}]]};bb.node;var Ta=z(bb);var yb={name:"cloud",size:24,node:[["path",{d:"M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z",key:"p7xjir"}]]};yb.node;var El=z(yb);var vb={name:"cloud-upload",size:24,node:[["path",{d:"M12 13v8",key:"1l5pq0"}],["path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242",key:"1pljnt"}],["path",{d:"m8 17 4-4 4 4",key:"1quai1"}]],aliases:["upload-cloud"]};vb.node;var Vr=z(vb);var wb={name:"columns-2",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]],aliases:["columns"]};wb.node;var Ts=z(wb);var kb={name:"copy",size:24,node:[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]};kb.node;var ga=z(kb);var Sb={name:"corner-up-right",size:24,node:[["path",{d:"m15 14 5-5-5-5",key:"12vg1m"}],["path",{d:"M4 20v-7a4 4 0 0 1 4-4h12",key:"1lu4f8"}]]};Sb.node;var Ol=z(Sb);var Cb={name:"database",size:24,node:[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]};Cb.node;var Sr=z(Cb);var Ib={name:"ellipsis",size:24,node:[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],aliases:["more-horizontal"]};Ib.node;var Ds=z(Ib);var Lb={name:"eye",size:24,node:[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]};Lb.node;var Bl=z(Lb);var Ab={name:"file-code",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 12.5 8 15l2 2.5",key:"1tg20x"}],["path",{d:"m14 12.5 2 2.5-2 2.5",key:"yinavb"}]]};Ab.node;var _l=z(Ab);var Pb={name:"file-code-corner",size:24,node:[["path",{d:"M4 12.15V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2h-3.35",key:"1wthlu"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"m5 16-3 3 3 3",key:"331omg"}],["path",{d:"m9 22 3-3-3-3",key:"lsp7cz"}]],aliases:["file-code-2"]};Pb.node;var is=z(Pb);var Rb={name:"file-diff",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M9 10h6",key:"9gxzsh"}],["path",{d:"M12 13V7",key:"h0r20n"}],["path",{d:"M9 17h6",key:"r8uit2"}]]};Rb.node;var os=z(Rb);var Nb={name:"file-exclamation-point",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],aliases:["file-warning"]};Nb.node;var Fs=z(Nb);var Mb={name:"file-image",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["circle",{cx:"10",cy:"12",r:"2",key:"737tya"}],["path",{d:"m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22",key:"wt3hpn"}]]};Mb.node;var Hl=z(Mb);var Tb={name:"file-pen",size:24,node:[["path",{d:"M12.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v9.34",key:"o6klzx"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10.378 12.622a1 1 0 0 1 3 3.003L8.36 20.637a2 2 0 0 1-.854.506l-2.867.837a.5.5 0 0 1-.62-.62l.836-2.869a2 2 0 0 1 .506-.853z",key:"zhnas1"}]],aliases:["file-edit"]};Tb.node;var Es=z(Tb);var Db={name:"file-play",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M15.033 13.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56v-4.704a.645.645 0 0 1 .967-.56z",key:"1tzo1f"}]],aliases:["file-video"]};Db.node;var Os=z(Db);var Fb={name:"file-plus-corner",size:24,node:[["path",{d:"M11.35 22H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v5.35",key:"17jvcc"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M14 19h6",key:"bvotb8"}],["path",{d:"M17 16v6",key:"18yu1i"}]],aliases:["file-plus-2"]};Fb.node;var Bs=z(Fb);var Eb={name:"file-plus",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M9 15h6",key:"cctwl0"}],["path",{d:"M12 18v-6",key:"17g6i2"}]]};Eb.node;var _s=z(Eb);var Ob={name:"file-text",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]]};Ob.node;var Da=z(Ob);var Bb={name:"file",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}]]};Bb.node;var Ul=z(Bb);var _b={name:"folder-open",size:24,node:[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 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",key:"usdka0"}]]};_b.node;var Hs=z(_b);var Hb={name:"folder-plus",size:24,node:[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]};Hb.node;var Or=z(Hb);var Ub={name:"folder-tree",size:24,node:[["path",{d:"M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"hod4my"}],["path",{d:"M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"w4yl2u"}],["path",{d:"M3 5a2 2 0 0 0 2 2h3",key:"f2jnh7"}],["path",{d:"M3 3v13a2 2 0 0 0 2 2h3",key:"k8epm1"}]]};Ub.node;var Gl=z(Ub);var Gb={name:"folder",size:24,node:[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]};Gb.node;var $r=z(Gb);var zb={name:"git-branch",size:24,node:[["path",{d:"M15 6a9 9 0 0 0-9 9V3",key:"1cii5b"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}]]};zb.node;var Bn=z(zb);var Wb={name:"git-commit-horizontal",size:24,node:[["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["line",{x1:"3",x2:"9",y1:"12",y2:"12",key:"1dyftd"}],["line",{x1:"15",x2:"21",y1:"12",y2:"12",key:"oup4p8"}]],aliases:["git-commit"]};Wb.node;var Kr=z(Wb);var jb={name:"git-compare-arrows",size:24,node:[["circle",{cx:"5",cy:"6",r:"3",key:"1qnov2"}],["path",{d:"M12 6h5a2 2 0 0 1 2 2v7",key:"1yj91y"}],["path",{d:"m15 9-3-3 3-3",key:"1lwv8l"}],["circle",{cx:"19",cy:"18",r:"3",key:"1qljk2"}],["path",{d:"M12 18H7a2 2 0 0 1-2-2V9",key:"16sdep"}],["path",{d:"m9 15 3 3-3 3",key:"1m3kbl"}]]};jb.node;var Cr=z(jb);var qb={name:"git-compare",size:24,node:[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M13 6h3a2 2 0 0 1 2 2v7",key:"1yeb86"}],["path",{d:"M11 18H8a2 2 0 0 1-2-2V9",key:"19pyzm"}]]};qb.node;var bo=z(qb);var Vb={name:"hard-drive",size:24,node:[["path",{d:"M10 16h.01",key:"1bzywj"}],["path",{d:"M2.212 11.577a2 2 0 0 0-.212.896V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-5.527a2 2 0 0 0-.212-.896L18.55 5.11A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"18tbho"}],["path",{d:"M21.946 12.013H2.054",key:"zqlbp7"}],["path",{d:"M6 16h.01",key:"1pmjb7"}]]};Vb.node;var rr=z(Vb);var $b={name:"info",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]]};$b.node;var zl=z($b);var Kb={name:"link-2",size:24,node:[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]]};Kb.node;var Wl=z(Kb);var Xb={name:"link-2-off",size:24,node:[["path",{d:"M9 17H7A5 5 0 0 1 7 7",key:"10o201"}],["path",{d:"M15 7h2a5 5 0 0 1 4 8",key:"1d3206"}],["line",{x1:"8",x2:"12",y1:"12",y2:"12",key:"rvw6j4"}],["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}]]};Xb.node;var jl=z(Xb);var Yb={name:"list",size:24,node:[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]]};Yb.node;var gi=z(Yb);var Jb={name:"loader-circle",size:24,node:[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],aliases:["loader-2"]};Jb.node;var $e=z(Jb);var Zb={name:"lock",size:24,node:[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4",key:"fwvmzm"}]]};Zb.node;var xi=z(Zb);var Qb={name:"minus",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}]]};Qb.node;var bi=z(Qb);var ey={name:"mouse-pointer-click",size:24,node:[["path",{d:"M14 4.1 12 6",key:"ita8i4"}],["path",{d:"m5.1 8-2.9-.8",key:"1go3kf"}],["path",{d:"m6 12-1.9 2",key:"mnht97"}],["path",{d:"M7.2 2.2 8 5.1",key:"1cfko1"}],["path",{d:"M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z",key:"s0h3yz"}]]};ey.node;var ql=z(ey);var ty={name:"move-right",size:24,node:[["path",{d:"M18 8L22 12L18 16",key:"1r0oui"}],["path",{d:"M2 12H22",key:"1m8cig"}]]};ty.node;var Vl=z(ty);var ny={name:"music-4",size:24,node:[["path",{d:"M9 18V5l12-2v13",key:"1jmyc2"}],["path",{d:"m9 9 12-2",key:"1e64n2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["circle",{cx:"18",cy:"16",r:"3",key:"1hluhg"}]]};ny.node;var $l=z(ny);var ry={name:"network",size:24,node:[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]};ry.node;var Kl=z(ry);var ay={name:"package",size:24,node:[["path",{d:"M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z",key:"1a0edw"}],["path",{d:"M12 22V12",key:"d0xqtd"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}]]};ay.node;var Br=z(ay);var sy={name:"panel-left",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]],aliases:["sidebar"]};sy.node;var Us=z(sy);var iy={name:"pen-line",size:24,node:[["path",{d:"M13 21h8",key:"1jsn5i"}],["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]],aliases:["edit-3"]};iy.node;var Gs=z(iy);var oy={name:"pencil",size:24,node:[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]};oy.node;var yi=z(oy);var ly={name:"pin",size:24,node:[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]};ly.node;var vi=z(ly);var uy={name:"play",size:24,node:[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]]};uy.node;var Xl=z(uy);var cy={name:"plus",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]};cy.node;var $n=z(cy);var dy={name:"radio",size:24,node:[["path",{d:"M16.247 7.761a6 6 0 0 1 0 8.478",key:"1fwjs5"}],["path",{d:"M19.075 4.933a10 10 0 0 1 0 14.134",key:"ehdyv1"}],["path",{d:"M4.925 19.067a10 10 0 0 1 0-14.134",key:"1q22gi"}],["path",{d:"M7.753 16.239a6 6 0 0 1 0-8.478",key:"r2q7qm"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]};dy.node;var ls=z(dy);var fy={name:"refresh-ccw",size:24,node:[["path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"14sxne"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16",key:"1hlbsb"}],["path",{d:"M16 16h5v5",key:"ccwih5"}]]};fy.node;var Fa=z(fy);var hy={name:"refresh-cw",size:24,node:[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]};hy.node;var Xt=z(hy);var py={name:"rotate-ccw",size:24,node:[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]};py.node;var wi=z(py);var my={name:"save",size:24,node:[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]};my.node;var ki=z(my);var gy={name:"scan-search",size:24,node:[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["path",{d:"m16 16-1.9-1.9",key:"1dq9hf"}]]};gy.node;var us=z(gy);var xy={name:"scissors",size:24,node:[["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M8.12 8.12 12 12",key:"1alkpv"}],["path",{d:"M20 4 8.12 15.88",key:"xgtan2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M14.8 14.8 20 20",key:"ptml3r"}]]};xy.node;var Yl=z(xy);var by={name:"search",size:24,node:[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]};by.node;var Jl=z(by);var yy={name:"settings",size:24,node:[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",key:"1i5ecw"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]};yy.node;var yo=z(yy);var vy={name:"shield-alert",size:24,node:[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]};vy.node;var Ea=z(vy);var wy={name:"shield-check",size:24,node:[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]};wy.node;var vo=z(wy);var ky={name:"shield-off",size:24,node:[["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71",key:"1jlk70"}],["path",{d:"M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264",key:"18rp1v"}]]};ky.node;var Zl=z(ky);var Sy={name:"shield",size:24,node:[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]]};Sy.node;var zs=z(Sy);var Cy={name:"sigma",size:24,node:[["path",{d:"M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2",key:"wuwx1p"}]]};Cy.node;var Ql=z(Cy);var Iy={name:"sliders-horizontal",size:24,node:[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]]};Iy.node;var Si=z(Iy);var Ly={name:"square",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]};Ly.node;var eu=z(Ly);var Ay={name:"tag",size:24,node:[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]]};Ay.node;var tu=z(Ay);var Py={name:"terminal",size:24,node:[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]]};Py.node;var wo=z(Py);var Ry={name:"text-align-justify",size:24,node:[["path",{d:"M3 5h18",key:"1u36vt"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 19h18",key:"awlh7x"}]],aliases:["align-justify"]};Ry.node;var Ws=z(Ry);var Ny={name:"trash",size:24,node:[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],aliases:["trash-2"]};Ny.node;var _t=z(Ny);var My={name:"triangle-alert",size:24,node:[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],aliases:["alert-triangle"]};My.node;var gt=z(My);var Ty={name:"undo-2",size:24,node:[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]};Ty.node;var Oa=z(Ty);var Dy={name:"unfold-vertical",size:24,node:[["path",{d:"M12 22v-6",key:"6o8u61"}],["path",{d:"M12 8V2",key:"1wkif3"}],["path",{d:"M4 12H2",key:"rhcxmi"}],["path",{d:"M10 12H8",key:"s88cx1"}],["path",{d:"M16 12h-2",key:"10asgb"}],["path",{d:"M22 12h-2",key:"14jgyd"}],["path",{d:"m15 19-3 3-3-3",key:"11eu04"}],["path",{d:"m15 5-3-3-3 3",key:"itvq4r"}]]};Dy.node;var nu=z(Dy);var Fy={name:"unlink",size:24,node:[["path",{d:"m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71",key:"yqzxt4"}],["path",{d:"m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71",key:"4qinb0"}],["line",{x1:"8",x2:"8",y1:"2",y2:"5",key:"1041cp"}],["line",{x1:"2",x2:"5",y1:"8",y2:"8",key:"14m1p5"}],["line",{x1:"16",x2:"16",y1:"19",y2:"22",key:"rzdirn"}],["line",{x1:"19",x2:"22",y1:"16",y2:"16",key:"ox905f"}]]};Fy.node;var ru=z(Fy);var Ey={name:"upload",size:24,node:[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]]};Ey.node;var Ba=z(Ey);var Oy={name:"wand-sparkles",size:24,node:[["path",{d:"m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72",key:"ul74o6"}],["path",{d:"m14 7 3 3",key:"1r5n42"}],["path",{d:"M5 6v4",key:"ilb8ba"}],["path",{d:"M19 14v4",key:"blhpug"}],["path",{d:"M10 2v2",key:"7u0qdc"}],["path",{d:"M7 8H3",key:"zfb6yr"}],["path",{d:"M21 16h-4",key:"1cnmox"}],["path",{d:"M11 3H9",key:"1obp7u"}]],aliases:["wand-2"]};Oy.node;var js=z(Oy);var By={name:"wrench",size:24,node:[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]]};By.node;var Ci=z(By);var _y={name:"x",size:24,node:[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]};_y.node;var Yt=z(_y);var Hy={name:"zap",size:24,node:[["path",{d:"M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z",key:"1v7up4"}]]};Hy.node;var au=z(Hy);var ln=W(ue(),1);function Ch(t){let{agentId:e,agentName:n,agentIcon:r,agentAccent:a,supportsSources:s=!0}=t,i=(0,su.resolveAgentIcon)(r),o=B(x=>x.toggleSidebar),l=B(x=>x.sidebarOpen),u=B(x=>x.refreshTree),c=B(x=>x.activeProjectId),d=B(x=>x.uploading),f=B(x=>x.workspacePanels),h=B(x=>x.setWorkspacePanelOpen),p=B(x=>x.activeWorkspaceTab),g=B(x=>x.pendingCountState),m=B(x=>x.pendingCount);return(0,ln.jsxs)("div",{className:"h-10 flex items-center px-3 shrink-0 gap-2.5",style:{backgroundColor:"transparent",borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,ln.jsx)("div",{className:"flex items-center gap-1",children:(0,ln.jsx)("button",{onClick:o,className:`p-1.5 rounded-lg transition-colors ${l?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white"}`,title:"Toggle Sidebar",children:(0,ln.jsx)(Us,{className:"w-4 h-4"})})}),(0,ln.jsx)("div",{className:"h-4 w-[1px] bg-white/10"}),(0,ln.jsx)("span",{className:"inline-flex h-6 w-6 shrink-0 items-center justify-center",style:{color:a||"var(--icon-muted)"},title:n||"Agent","aria-label":n||"Agent",children:(0,ln.jsx)(i,{className:"h-4 w-4"})}),(0,ln.jsxs)("div",{className:"flex items-center gap-1",children:[(0,ln.jsx)("button",{onClick:()=>u({agentId:e,projectId:c??null}),className:"p-1.5 rounded-lg text-white/50 hover:bg-white/5 hover:text-white transition-colors",title:"Refresh",children:(0,ln.jsx)(Xt,{className:"w-4 h-4"})}),(0,ln.jsx)("button",{className:"p-1.5 rounded-lg text-white/50 hover:bg-white/5 hover:text-white transition-colors disabled:opacity-50 disabled:cursor-not-allowed",title:"Upload files",disabled:d,onClick:()=>{if(f.upload&&p==="upload"){h("upload",!1);return}h("upload",!0)},children:d?(0,ln.jsx)($e,{className:"w-4 h-4 animate-spin"}):(0,ln.jsx)(Ba,{className:"w-4 h-4"})}),s?(0,ln.jsx)("button",{className:`p-1.5 rounded-lg transition-colors ${f.sources&&p==="sources"?"bg-cyan-500/15 text-cyan-400":"text-white/50 hover:bg-white/5 hover:text-cyan-300"}`,title:"Data Sources & Sync",onClick:()=>{if(f.sources&&p==="sources"){h("sources",!1);return}h("sources",!0)},children:(0,ln.jsx)(Sr,{className:"w-4 h-4"})}):null,s?(0,ln.jsx)(su.SkillLauncher,{variant:"icon",size:"sm",skill:"sync",packageId:"@neuralis/brain-core",label:"Sync sources with the agent",icon:"brain"}):null,(0,ln.jsx)(su.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-files",packageId:"@neuralis/brain-core",scripts:["scripts/mkdir.sh","scripts/copy.sh","scripts/modify.sh"],label:"Create, copy, edit or search files with the agent",icon:"Folder"}),(0,ln.jsx)("button",{className:`p-1.5 rounded-lg transition-colors ${f.packages&&p==="packages"?"bg-violet-500/15 text-violet-300":"text-white/50 hover:bg-white/5 hover:text-violet-200"}`,title:"Packages \u2014 trust & build",onClick:()=>{if(f.packages&&p==="packages"){h("packages",!1);return}h("packages",!0)},children:(0,ln.jsx)(Br,{className:"w-4 h-4"})}),(0,ln.jsxs)("button",{className:`relative p-1.5 rounded-lg transition-colors ${f.pending&&p==="pending"?"bg-amber-500/15 text-amber-300":"text-white/50 hover:bg-white/5 hover:text-amber-200"}`,title:g==="stale"?`Pending changes \u2014 count unavailable${m>0?` (last count ${m})`:""}`:g==="partial"?`Pending changes \u2014 ${m}+ (incomplete) to review`:m>0?`Pending changes \u2014 ${m} to review`:"Pending changes \u2014 review, approve & revert",onClick:()=>{if(f.pending&&p==="pending"){h("pending",!1);return}h("pending",!0)},children:[(0,ln.jsx)(os,{className:"w-4 h-4"}),m>0||g!=="exact"?(0,ln.jsxs)("span",{"data-testid":"pending-count-badge",className:"absolute -top-1 -right-1 min-w-[14px] rounded-full px-1 text-center text-[9px] leading-[14px] font-semibold bg-amber-500/15 text-amber-300",children:[m>999?"1000+":m,g==="partial"&&m<=999?"+":g==="stale"?"?":""]}):null]})]})]})}var qe=W(Je(),1),W1=W(nr(),1);function cs(t,e){let n=t.grantedFeatures;return n?n.includes("*")||n.includes(e):!1}function ko(t,e){let n=e?.features;return!n||n.length===0?!0:n.every(r=>cs(t,r))}var Ih={owner:1,admin:2,manager:10,member:20,viewer:30};var lA=Ih.member,zy=Number.MAX_SAFE_INTEGER;var xa=W(Je(),1),ev=W(ds(),1);function Vy(t){return typeof t=="object"?t.key:t}function $y(t,e){let n=t.length;return new Proxy(t,{get(r,a,s){if(typeof a=="string"){let i=a.charCodeAt(0);if(i>=48&&i<=57){let o=+a;if(Number.isInteger(o)&&o>=0&&o<n){let l=r[o];if(typeof l!="object"){let u=e[o*2];l=r[o]={index:o,key:l,start:u,size:e[o*2+1],end:u+e[o*2+1],lane:0}}return l}}if(a==="length")return n}return Reflect.get(r,a,s)}})}function Ii(t,e,n){let r=n.initialDeps??[],a,s=!0;function i(){var o;let u=0,c=t();if(!(c.length!==r.length||c.some((h,p)=>r[p]!==h)))return a;r=c;let f=0;return a=e(...c),n?.onChange&&!(s&&n.skipInitialOnChange)&&n.onChange(a),s=!1,a}return i.updateDeps=o=>{r=o},i}function Ah(t,e){if(t===void 0)throw new Error(`Unexpected undefined${e?`: ${e}`:""}`);return t}var Ph=(t,e)=>Math.abs(t-e)<1.01,Ky=(t,e,n)=>{let r;return Object.assign(function(...a){t.clearTimeout(r),r=t.setTimeout(()=>e.apply(this,a),n)},{cancel:()=>{t.clearTimeout(r)}})};var iu,Rh=()=>{if(iu!==void 0)return iu;if(typeof navigator>"u")return iu=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return iu=!0;let t=navigator.maxTouchPoints;return iu=navigator.platform==="MacIntel"&&t!==void 0&&t>0};var Xy=t=>{let{offsetWidth:e,offsetHeight:n}=t;return{width:e,height:n}},mA=t=>t,gA=t=>{let e=Math.max(t.startIndex-t.overscan,0),r=Math.min(t.endIndex+t.overscan,t.count-1)-e+1,a=new Array(r);for(let s=0;s<r;s++)a[s]=e+s;return a},Yy=(t,e)=>{let n=t.scrollElement;if(!n)return;let r=t.targetWindow;if(!r)return;let a=i=>{let{width:o,height:l}=i;e({width:Math.round(o),height:Math.round(l)})};if(a(Xy(n)),!r.ResizeObserver)return()=>{};let s=new r.ResizeObserver(i=>{let o=()=>{let l=i[0];if(l?.borderBoxSize){let u=l.borderBoxSize[0];if(u){a({width:u.inlineSize,height:u.blockSize});return}}a(Xy(n))};t.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(o):o()});return s.observe(n,{box:"border-box"}),()=>{s.unobserve(n)}},Fc={passive:!0};var xA=typeof window>"u"?!0:"onscrollend"in window,bA=(t,e,n)=>{let r=t.scrollElement;if(!r)return;let a=t.targetWindow;if(!a)return;let s=t.options.useScrollendEvent&&xA,i=0,o=s?null:Ky(a,()=>e(n(r),!1),t.options.isScrollingResetDelay),l=d=>()=>{i=n(r),o?.(),e(i,d)},u=l(!0),c=l(!1);return r.addEventListener("scroll",u,Fc),s&&r.addEventListener("scrollend",c,Fc),()=>{r.removeEventListener("scroll",u),s&&r.removeEventListener("scrollend",c),o?.cancel()}},Jy=(t,e)=>bA(t,e,n=>{let{horizontal:r,isRtl:a}=t.options;return r?n.scrollLeft*(a&&-1||1):n.scrollTop});var yA=(t,e,n)=>{if(n.options.useCachedMeasurements){let r=n.indexFromElement(t),a=n.options.getItemKey(r);return n.itemSizeCache.get(a)??n.options.estimateSize(r)}if(e?.borderBoxSize){let r=e.borderBoxSize[0];if(r)return Math.round(r[n.options.horizontal?"inlineSize":"blockSize"])}if(!e){let r=n.indexFromElement(t),a=n.options.getItemKey(r),s=n.itemSizeCache.get(a);if(s!==void 0)return s}return t[n.options.horizontal?"offsetWidth":"offsetHeight"]},vA=(t,{adjustments:e=0,behavior:n},r)=>{var a,s;(s=(a=r.scrollElement)==null?void 0:a.scrollTo)==null||s.call(a,{[r.options.horizontal?"left":"top"]:t+e,behavior:n})};var Zy=vA;function wA(t,e,n,r){if(e===0)return!1;let a=r(0),s=new Set,i=0;for(;i<t;){let l=n(i);if(l===a)break;s.add(l),i++}let o=t-i;if(o===0||o>=e)return!1;for(let l=0;l<o;l++)if(r(l)!==n(i+l))return!1;for(let l=o;l<e;l++)if(s.has(r(l)))return!1;return!0}var Ec=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.now=()=>{var n,r,a;return((a=(r=(n=this.targetWindow)==null?void 0:n.performance)==null?void 0:r.now)==null?void 0:a.call(r))??Date.now()},this.observer=(()=>{let n=null,r=()=>n||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:n=new this.targetWindow.ResizeObserver(a=>{a.forEach(s=>{let i=()=>{let o=s.target,l=this.indexFromElement(o);if(!o.isConnected){this.observer.unobserve(o);for(let[u,c]of this.elementsCache)if(c===o){this.elementsCache.delete(u);break}return}this.isIndexInRange(l)&&this.shouldMeasureDuringScroll(l)&&this.resizeItem(l,this.options.measureElement(o,s,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(i):i()})}));return{disconnect:()=>{var a;(a=r())==null||a.disconnect(),n=null},observe:a=>{var s;return(s=r())==null?void 0:s.observe(a,{box:"border-box"})},unobserve:a=>{var s;return(s=r())==null?void 0:s.unobserve(a)}}})(),this.range=null,this.setOptions=n=>{var r;let a={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:mA,rangeExtractor:gA,onChange:()=>{},measureElement:yA,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 d in n){let f=n[d];f!==void 0&&(a[d]=f)}let s=this.options,i=null,o=null,l=!1;if(s!==void 0&&s.enabled&&a.enabled&&a.anchorTo==="end"&&this.scrollElement!==null){let d=s.count,f=a.count,h=this.getMeasurements(),p=((r=this._singleLaneMeasurements)==null?void 0:r.items)??h,g=C=>Vy(p[C]),m=d>0?g(0):null,x=d>0?g(d-1):null;if(f!==d||d>0&&f>0&&(a.getItemKey(0)!==m||a.getItemKey(f-1)!==x)){l=!0;let C=d>0?this.getVirtualItemForOffset(this.getScrollOffset())??h[0]:null;C&&(i=[C.key,this.getScrollOffset()-C.start]);let I=a.followOnAppend===!0?"auto":a.followOnAppend||null;I&&f>0&&this.isAtEnd(s.scrollEndThreshold)&&(d===0||a.getItemKey(f-1)!==x)&&(f>d||wA(d,f,g,a.getItemKey))&&(o=I)}}this.options=a,l&&(this.pendingMin=0,this.itemSizeCacheVersion++);let u=!1,c=0;if(i&&this.scrollOffset!==null){let[d,f]=i,h=this.getMeasurements(),{count:p,getItemKey:g}=this.options,m=0;for(;m<p&&g(m)!==d;)m++;if(m<p){let x=h[m];if(x){let b=Math.max(0,x.start+f);!o&&b!==this.scrollOffset&&(c=b-this.scrollOffset,this.scrollOffset=b,u=!0)}}}(u||o)&&(this.pendingScrollAnchor=[u?i[0]:null,u?i[1]:0,o,c])},this.notify=n=>{var r,a;(a=(r=this.options).onChange)==null||a.call(r,this,n)},this.maybeNotify=Ii(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),n=>{this.notify(n)},{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(n=>n()),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=()=>{var n,r;let a=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==a){if(this.cleanup(),!a){this.maybeNotify();return}if(this.scrollElement=a,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((n=this.scrollElement)==null?void 0:n.window)??null,this.elementsCache.forEach(i=>{this.observer.observe(i)}),this.unsubs.push(this.options.observeElementRect(this,i=>{this.scrollRect=i,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(i,o)=>{if(o&&this._intendedScrollOffset===null&&i===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(i-this._intendedScrollOffset)<1.5&&(i=this._intendedScrollOffset),this._intendedScrollOffset=null,this._clampedAdjustment!==null&&Math.abs(i-this._clampedAdjustment.maxAtWrite)>=1.5&&(this._clampedAdjustment=null),this.scrollAdjustments=0;let l=this.getScrollOffset();this.scrollDirection=o?l===i?this.scrollDirection:l<i?"forward":"backward":null,this.scrollOffset=i,this.isScrolling=o,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){let i=this.scrollElement,o=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},l=()=>{this._iosTouching=!1,!(!Rh()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};i.addEventListener("touchstart",o,Fc),i.addEventListener("touchend",l,Fc),this.unsubs.push(()=>{i.removeEventListener("touchstart",o),i.removeEventListener("touchend",l),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 s=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,s&&this.scrollElement&&this.options.enabled){let[i,o,l,u]=s;i!==null&&!l&&(Rh()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?u!==0&&(this._iosDeferredAdjustment+=u):((r=this.scrollState)==null?void 0:r.behavior)==="smooth"&&!Ph(this.getScrollOffset()-u,this.scrollState.lastTargetOffset)||this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),l&&this.scrollToEnd({behavior:l})}this._retryClampedAdjustment()},this._retryClampedAdjustment=()=>{if(this._clampedAdjustment===null||!this.scrollElement||!this.options.enabled)return;let{target:n,maxAtWrite:r}=this._clampedAdjustment,a=this.getMaxScrollOffset();a>r+.5&&(this._clampedAdjustment=n>a+.5?{target:n,maxAtWrite:a}:null,this._scrollToOffset(n,{adjustments:void 0,behavior:void 0}))},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;let n=this.getScrollOffset(),r=this.getMaxScrollOffset();if(n<0||n>r)return;if(this._iosDeferredAdjustment<0&&n>=r-1){this._iosDeferredAdjustment=0;return}let a=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(n,{adjustments:this.scrollAdjustments+=a,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=Ii(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(n,r,a,s,i,o,l,u)=>(this.prevLanes!==void 0&&this.prevLanes!==o&&(this.lanesChangedFlag=!0),this.prevLanes=o,this.pendingMin=null,{count:n,paddingStart:r,scrollMargin:a,getItemKey:s,enabled:i,lanes:o,laneAssignmentMode:l,gap:u}),{key:!1}),this.isIndexInRange=n=>n>=0&&n<this.options.count,this.getMeasurements=Ii(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:n,paddingStart:r,scrollMargin:a,getItemKey:s,enabled:i,lanes:o,laneAssignmentMode:l,gap:u},c)=>{var d;let f=this.itemSizeCache;if(!i)return this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>n)for(let b of this.laneAssignments.keys())b>=n&&this.laneAssignments.delete(b);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(b=>{this.itemSizeCache.set(b.key,b.size)}));let h=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===n&&(this.lanesSettling=!1),o===1){let b=n*2,y=(d=this._singleLaneMeasurements)==null?void 0:d.flat;if(!y||y.length<b){let v=new Float64Array(b);y&&h>0&&v.set(y.subarray(0,h*2)),y=v}let C=h===0?new Array(n):this._singleLaneMeasurements.items.slice(),I;if(h===0)I=r+a;else{let v=h-1;I=y[v*2]+y[v*2+1]+u}for(let v=h;v<n;v++){let k=s(v);C[v]=k;let O=f.get(k),R=typeof O=="number"?O:this.options.estimateSize(v);y[v*2]=I,y[v*2+1]=R,I+=R+u}this._singleLaneMeasurements={flat:y,items:C};let L=$y(C,y);return this.measurementsCache=L,L}let p=this.measurementsCache.slice(0,h),g=new Array(o).fill(void 0),m=new Float64Array(o),x=0;for(let b=0;b<h;b++){let y=p[b];y&&(g[y.lane]===void 0&&x++,g[y.lane]=b,m[y.lane]=y.end)}for(let b=h;b<n;b++){let y=s(b),C=this.laneAssignments.get(b),I,L,v=l==="estimate"||f.has(y);if(C!==void 0&&this.options.lanes>1){I=C;let P=g[I],H=P!==void 0?p[P]:void 0;L=H?H.end+u:r+a}else if(x===o){let P=0,H=m[0],w=g[0];for(let N=1;N<o;N++){let j=m[N];(j<H||j===H&&g[N]<w)&&(P=N,H=j,w=g[N])}I=P,L=H+u,v&&this.laneAssignments.set(b,I)}else I=b%this.options.lanes,L=r+a,v&&this.laneAssignments.set(b,I);let k=f.get(y),O=typeof k=="number"?k:this.options.estimateSize(b),R=L+O;p[b]={index:b,start:L,size:O,end:R,key:y,lane:I},g[I]===void 0&&x++,g[I]=b,m[I]=R}return this.measurementsCache=p,p},{key:!1,debug:()=>this.options.debug}),this.calculateRange=Ii(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,a,s)=>n.length===0||r===0?(this.range=null,null):(this.range=SA(n,r,a,s,s===1&&this._singleLaneMeasurements!==null?this._singleLaneMeasurements.flat:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Ii(()=>{let n=null,r=null,a=this.calculateRange();return a&&(n=a.startIndex,r=a.endIndex),this.maybeNotify.updateDeps([this.isScrolling,n,r]),[this.options.rangeExtractor,this.options.overscan,this.options.count,n,r]},(n,r,a,s,i)=>s===null||i===null?[]:n({startIndex:s,endIndex:i,overscan:r,count:a}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=n=>{let r=this.options.indexAttribute,a=n.getAttribute(r);return a?parseInt(a,10):(console.warn(`Missing attribute name '${r}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=n=>{var r;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;let a=this.scrollState.index??((r=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:r.index);if(a!==void 0&&this.range){let s=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),i=Math.max(0,a-s),o=Math.min(this.options.count-1,a+s);return n>=i&&n<=o}return!0},this.measureElement=n=>{if(!n){this.elementsCache.forEach((i,o)=>{i.isConnected||(this.observer.unobserve(i),this.elementsCache.delete(o))});return}let r=this.indexFromElement(n);if(!this.isIndexInRange(r))return;let a=this.options.getItemKey(r),s=this.elementsCache.get(a);s!==n&&(s&&this.observer.unobserve(s),this.observer.observe(n),this.elementsCache.set(a,n)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(r)&&this.resizeItem(r,this.options.measureElement(n,void 0,this))},this.resizeItem=(n,r)=>{var a,s,i;if(!this.isIndexInRange(n))return;let o,l,u,c=(a=this._singleLaneMeasurements)==null?void 0:a.flat;if(this.options.lanes===1&&c!=null)u=this.options.getItemKey(n),l=c[n*2],o=c[n*2+1];else{let h=this.measurementsCache[n];if(!h)return;u=h.key,l=h.start,o=h.size}let d=this.itemSizeCache.get(u)??o,f=r-d;if(f!==0){let h=this.options.anchorTo==="end"&&((s=this.scrollState)==null?void 0:s.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,p=h?this.getTotalSize():0,g=this.getScrollOffset()+this.scrollAdjustments,x=!this.itemSizeCache.has(u)?l<g:l+d<=g&&this.scrollDirection!=="backward",b=((i=this.scrollState)==null?void 0:i.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[n]??{index:n,key:u,start:l,size:o,end:l+o,lane:0},f,this):x);(this.pendingMin===null||n<this.pendingMin)&&(this.pendingMin=n),this.itemSizeCache.set(u,r),this.itemSizeCacheVersion++;let y=!1;h?y=this.applyScrollAdjustment(this.getTotalSize()-p):b&&(y=this.applyScrollAdjustment(f)),this.notify(y),this._retryClampedAdjustment()}},this.getVirtualItems=Ii(()=>[this.getVirtualIndexes(),this.getMeasurements()],(n,r)=>{let a=[];for(let s=0,i=n.length;s<i;s++){let o=n[s],l=r[o];a.push(l)}return a},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=n=>{var r;let a=this.getMeasurements();if(a.length===0)return;let s=(r=this._singleLaneMeasurements)==null?void 0:r.flat,i=this.options.lanes===1&&s!=null,o=Qy(0,a.length-1,i?l=>s[l*2]:l=>Ah(a[l]).start,n);return Ah(a[o])},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 n=this.scrollElement.document.documentElement;return this.options.horizontal?n.scrollWidth-this.scrollElement.innerWidth:n.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=(n=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=n,this.getOffsetForAlignment=(n,r,a=0)=>{if(!this.scrollElement)return 0;let s=this.getSize(),i=this.getScrollOffset();r==="auto"&&(r=n>=i+s?"end":"start"),r==="center"?n+=(a-s)/2:r==="end"&&(n-=s);let o=this.getMaxScrollOffset();return Math.max(Math.min(o,n),0)},this.getOffsetForIndex=(n,r="auto")=>{n=Math.max(0,Math.min(n,this.options.count-1));let a=this.getSize(),s=this.getScrollOffset(),i=this.measurementsCache[n];if(!i)return;if(r==="auto")if(i.end>=s+a-this.options.scrollPaddingEnd)r="end";else if(i.start<=s+this.options.scrollPaddingStart)r="start";else return[s,r];if(r==="end"&&n===this.options.count-1)return[this.getMaxScrollOffset(),r];let o=r==="end"?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(o,r,i.size),r]},this.scrollToOffset=(n,{align:r="start",behavior:a="auto"}={})=>{this._iosDeferredAdjustment=0;let s=this.getOffsetForAlignment(n,r),i=this.now();this.scrollState={index:null,align:r,behavior:a,startedAt:i,lastTargetOffset:s,stableFrames:0},this._scrollToOffset(s,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollToIndex=(n,{align:r="auto",behavior:a="auto"}={})=>{this._iosDeferredAdjustment=0,n=Math.max(0,Math.min(n,this.options.count-1));let s=this.getOffsetForIndex(n,r);if(!s)return;let[i,o]=s,l=this.now();this.scrollState={index:n,align:o,behavior:a,startedAt:l,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollBy=(n,{behavior:r="auto"}={})=>{let a=this.getScrollOffset()+n,s=this.now();this.scrollState={index:null,align:"start",behavior:r,startedAt:s,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:r}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:n="auto"}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:"end",behavior:n});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:n})},this.getTotalSize=()=>{var n,r;let a=this.getMeasurements(),s;if(a.length===0)s=this.options.paddingStart;else if(this.options.lanes===1){let i=a.length-1,o=(n=this._singleLaneMeasurements)==null?void 0:n.flat;o!=null?s=o[i*2]+o[i*2+1]:s=((r=a[i])==null?void 0:r.end)??0}else{let i=Array(this.options.lanes).fill(null),o=a.length-1;for(;o>=0&&i.some(l=>l===null);){let l=a[o];i[l.lane]===null&&(i[l.lane]=l.end),o--}s=Math.max(...i.filter(l=>l!==null))}return Math.max(s-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{let n=[];if(this.itemSizeCache.size===0)return n;let r=this.getMeasurements();for(let a of r)a&&this.itemSizeCache.has(a.key)&&n.push({index:a.index,key:a.key,start:a.start,size:a.size,end:a.end,lane:a.lane});return n},this._scrollToOffset=(n,{adjustments:r,behavior:a})=>{this._intendedScrollOffset=n+(r??0),this.options.scrollToFn(n,{behavior:a,adjustments:r},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(e)}applyScrollAdjustment(e,n){if(e===0)return!1;if(Rh()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded))return this._iosDeferredAdjustment+=e,!1;{let r=this.getScrollOffset()+this.scrollAdjustments+e,a=this.scrollElement,s=a!==null&&("scrollHeight"in a||"document"in a)?this.getMaxScrollOffset():null;return this._clampedAdjustment=s!==null&&r>s+.5?{target:r,maxAtWrite:s}:null,this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=e,behavior:n}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollOffset<0&&(this.scrollOffset=0),this.scrollAdjustments=0),!0}}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}let r=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,a=r?r[0]:this.scrollState.lastTargetOffset,s=1,i=a!==this.scrollState.lastTargetOffset;if(!i&&Ph(a,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=s){this.getScrollOffset()!==a&&this._scrollToOffset(a,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,i){let o=this.getSize()||600,l=Math.abs(a-this.getScrollOffset()),u=this.scrollState.behavior==="smooth"&&l>o;this.scrollState.lastTargetOffset=a,u||(this.scrollState.behavior="auto"),this._scrollToOffset(a,{adjustments:void 0,behavior:u?"smooth":"auto"})}this.scheduleScrollReconcile()}},Qy=(t,e,n,r)=>{for(;t<=e;){let a=(t+e)/2|0,s=n(a);if(s<r)t=a+1;else if(s>r)e=a-1;else return a}return t>0?t-1:0};function kA(t,e,n){let r=0;for(;r<=e;){let a=(r+e)/2|0,s=t[a*2];if(s<n)r=a+1;else if(s>n)e=a-1;else return a}return r>0?r-1:0}function SA(t,e,n,r,a){let s=t.length-1;if(t.length<=r)return{startIndex:0,endIndex:s};if(r===1&&a!==null){let u=kA(a,s,n),c=u,d=n+e;for(;c<s&&a[c*2]+a[c*2+1]<d;)c++;return{startIndex:u,endIndex:c}}let o=Qy(0,s,u=>t[u].start,n),l=o;if(r===1)for(;l<s&&t[l].end<n+e;)l++;else if(r>1){let u=Array(r).fill(0);for(;l<s&&u.some(d=>d<n+e);){let d=t[l];u[d.lane]=d.end,l++}let c=Array(r).fill(n+e);for(;o>=0&&c.some(d=>d>=n);){let d=t[o];c[d.lane]=d.start,o--}o=Math.max(0,o-o%r),l=Math.min(s,l+(r-1-l%r))}return{startIndex:o,endIndex:l}}var Nh=typeof document<"u"?xa.useLayoutEffect:xa.useEffect;function CA({useFlushSync:t=!0,directDomUpdates:e=!1,directDomUpdatesMode:n="transform",...r}){let a=xa.useReducer(d=>d+1,0)[1],s=xa.useRef({enabled:e,mode:n,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});s.current.enabled=e,s.current.mode=n;let i=xa.useRef(!1),o=d=>{let f=s.current;if(!f.enabled||!f.container)return;let h=d.getTotalSize();if(h!==f.lastSize){f.lastSize=h;let p=d.options.horizontal?"width":"height";f.container.style[p]=`${h}px`}},l=d=>{let f=s.current;if(!f.enabled||!f.container)return;o(d);let h=!!d.options.horizontal,p=f.mode==="transform",g=h?"left":"top",m=d.options.scrollMargin,x=d.getVirtualItems();for(let b of x){let y=b.start-m,C=d.elementsCache.get(b.key);C&&f.lastPositions.get(C)!==y&&(f.lastPositions.set(C,y),p?C.style.transform=h?`translate3d(${y}px, 0, 0)`:`translate3d(0, ${y}px, 0)`:C.style[g]=`${y}px`)}},u={...r,onChange:(d,f)=>{var h;let p=s.current,g=!0;if(p.enabled){l(d);let m=d.range,x=p.prevRange;g=!x||x.isScrolling!==d.isScrolling||x.startIndex!==m?.startIndex||x.endIndex!==m?.endIndex,g&&(p.prevRange=m?{startIndex:m.startIndex,endIndex:m.endIndex,isScrolling:d.isScrolling}:null)}g&&(t&&f&&!i.current?(0,ev.flushSync)(a):a()),(h=r.onChange)==null||h.call(r,d,f)}},[c]=xa.useState(()=>{let d=new Ec(u),f=d.measureElement;return d.measureElement=h=>{i.current=!0;try{f(h)}finally{i.current=!1}},Object.assign(d,{containerRef:h=>{let p=s.current;if(p.container=h,p.lastSize=null,h&&p.enabled){let g=d.getTotalSize();p.lastSize=g;let m=d.options.horizontal?"width":"height";h.style[m]=`${g}px`}}})});return c.setOptions(u),Nh(()=>c._didMount(),[]),Nh(()=>(o(c),c._willUpdate())),Nh(()=>{l(c)}),c}function So(t){return CA({observeElementRect:Yy,observeElementOffset:Jy,scrollToFn:Zy,...t})}var fs=W(Je(),1);function tv(t){let e=B(u=>u.client),{agentId:n,projectId:r,enabled:a}=t,[s,i]=(0,fs.useState)([]),o=(0,fs.useRef)(!0);(0,fs.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let l=(0,fs.useRef)(!1);return(0,fs.useEffect)(()=>{l.current=!1,i([])},[n,r]),(0,fs.useEffect)(()=>{!n||!a||l.current||(l.current=!0,xc({agentId:n,...r?{projectId:r}:{}},e).then(u=>{o.current&&i(u.suggestions??[])}).catch(()=>{o.current&&i([])}))},[n,r,a,e]),s}var _c=W(Je(),1);var Ir=W(nr(),1);var _a=W(ue(),1);function IA({className:t}){return(0,_a.jsxs)("svg",{viewBox:"0 0 64 64",className:t,"aria-hidden":"true",children:[(0,_a.jsx)("path",{d:"M10 52L24 28L36 36L52 12",fill:"none",stroke:"currentColor",strokeWidth:"3.5",strokeLinecap:"round",strokeLinejoin:"round"}),(0,_a.jsx)("circle",{cx:"10",cy:"52",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"}),(0,_a.jsx)("circle",{cx:"24",cy:"28",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"}),(0,_a.jsx)("circle",{cx:"36",cy:"36",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"}),(0,_a.jsx)("circle",{cx:"52",cy:"12",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"})]})}function LA(t){if(!t)return"aged";let e=Date.parse(t);if(!Number.isFinite(e))return"aged";let n=Math.max(0,(Date.now()-e)/6e4);return n<=15?"fresh":n<=180?"recent":n<=1440?"aged":"stale"}function Li(t){switch(LA(t)){case"fresh":return{pillClassName:"border-emerald-400/25 bg-emerald-500/14 text-emerald-100",iconClassName:"text-emerald-300/85",label:"Changed just now"};case"recent":return{pillClassName:"border-amber-400/22 bg-amber-500/10 text-amber-100/92",iconClassName:"text-amber-300/76",label:"Changed recently"};case"aged":return{pillClassName:"border-white/10 bg-white/[0.05] text-white/60",iconClassName:"text-white/40",label:"Older change"};default:return{pillClassName:"border-rose-400/18 bg-rose-500/10 text-rose-100/80",iconClassName:"text-rose-300/70",label:"Older indexed change"}}}function ou(t){let e=t.status==="deleted",n=t.status==="pending_review",r=t.status==="pinned";return e?{tone:"text-red-100/70",iconTone:"text-red-300/70",secondaryTone:"text-red-200/60",highlightTone:"bg-red-500/12",icon:Ms,label:"Deleted",title:"Marked as deleted",ghosted:!0}:n?{tone:"text-amber-50/95",iconTone:"text-amber-300/85",secondaryTone:"text-amber-200/75",highlightTone:"bg-amber-500/10",icon:gt,label:"Review pending",title:"Pending review before approval"}:t.presence==="brain"?{tone:"text-violet-50/92",iconTone:"text-violet-300/80",secondaryTone:"text-violet-200/68",highlightTone:"bg-violet-500/10",icon:Sr,label:"Brain node",title:"Stored in brain index"}:t.presence==="stale_indexed"?{tone:"text-rose-100/78",iconTone:"text-rose-300/75",secondaryTone:"text-rose-200/65",highlightTone:"bg-rose-500/8",icon:us,label:"Missing from disk",title:"Indexed but not found in live source",ghosted:!0}:t.presence==="unindexed"?{tone:"text-white/55",iconTone:"text-white/70",secondaryTone:"text-white/45",highlightTone:"bg-white/[0.04]",icon:ls,label:"Unindexed",title:"Connector entry not vector-indexed yet"}:r?{tone:"text-white/82",iconTone:"text-amber-200/80",secondaryTone:"text-amber-100/65",highlightTone:"bg-amber-500/8",icon:vi,label:"Pinned",title:"Pinned item"}:t.presence==="synced"?{tone:"text-white",iconTone:"text-sky-300/80",secondaryTone:"text-white/82",highlightTone:"bg-sky-500/10",icon:IA,label:"Synced",title:"Indexed and present on the connector"}:{tone:"text-white/72",iconTone:"text-white/48",secondaryTone:"text-white/48",highlightTone:"bg-white/[0.04]",icon:Ta,label:"Neutral",title:"File entry"}}function nv(t){return t?Hs:$r}function rv(t){let n=[ou(t).label];return t.version?.changedAt&&n.push(Li(t.version.changedAt).label),t.status==="pinned"&&n.push("Pinned"),n}function Oc(t){return{iconClassName:"text-white/35",labelClassName:"text-white/45",detailClassName:"text-white/30",containerClassName:"opacity-55",title:t==="disabled"?"Source disabled in this scope \u2014 toggle in the Sources panel.":"Source discovered but not yet attached \u2014 click to add."}}function Bc(t){let e=t.enabled===!1,n=t.enabled==="auto"&&t.enabled_effective===!1;return e||n?{iconClassName:"text-white/35",labelClassName:"text-white/45",detailClassName:"text-white/30"}:t.live===!1?{iconClassName:"text-white/35",labelClassName:"text-white/45",detailClassName:"text-white/30"}:t.sync_status==="error"?{iconClassName:"text-rose-300/80",labelClassName:"text-rose-50/92",detailClassName:"text-rose-200/65"}:t.sync_status==="paused"?{iconClassName:"text-amber-300/80",labelClassName:"text-amber-50/90",detailClassName:"text-amber-200/65"}:t.sync_status==="active"?{iconClassName:"text-sky-300/80",labelClassName:"text-sky-50/90",detailClassName:"text-sky-200/62"}:t.source_kind==="brain"?{iconClassName:"text-violet-300/85",labelClassName:"text-violet-50/92",detailClassName:"text-violet-200/60"}:{iconClassName:"text-white/80",labelClassName:"text-white/90",detailClassName:"text-white/55"}}var AA={runtime_offline:"Machine offline \u2014 container not running",fs_unreachable:"Filesystem unreachable \u2014 mount missing",fs_permission:"Filesystem unreadable \u2014 permission denied",store_unreachable:"Store offline \u2014 backing service unreachable"};function Mh(t){return(t?AA[t]:void 0)??"Disconnected \u2014 connector cannot reach its backing filesystem"}function av(t){return t.enabled===!1?"Source disabled":t.enabled==="auto"&&t.enabled_effective===!1?"Source auto \u2014 currently stopped":t.live===!1?Mh(t.live_reason):t.sync_status==="error"?t.last_error??"Sync error":t.sync_status==="paused"?"Sync paused":t.sync_status==="active"?"Sync active":null}function Th(t){if(!t)return null;let e=Date.parse(t);if(!Number.isFinite(e))return null;let n=Math.max(0,Math.round((Date.now()-e)/6e4));if(n<1)return"now";if(n<60)return`${n}m`;let r=Math.round(n/60);return r<24?`${r}h`:`${Math.round(r/24)}d`}function sv({className:t,title:e}){return(0,_a.jsx)("span",{title:e,className:"inline-flex",children:(0,_a.jsx)(Cr,{className:t})})}function V(...t){return t.filter(Boolean).join(" ")}var mr=W(ue(),1),PA=5,iv=28;function ov({suggestions:t,expanded:e,onToggleExpanded:n,onPick:r,overlay:a}){return t.length===0?null:(0,mr.jsxs)("div",{className:V("group/discover shrink-0 border-t border-white/[0.06] bg-[#0b0b0f]/95",a?"absolute inset-x-0 bottom-0 z-20 shadow-[0_-8px_24px_rgba(0,0,0,0.45)]":""),"data-testid":"discover-dock",children:[(0,mr.jsxs)("div",{className:"flex items-center justify-between px-2 pt-1.5 pb-1",children:[(0,mr.jsx)("span",{className:"text-[10px] font-bold uppercase tracking-wider text-white/40",children:"Discover"}),(0,mr.jsx)("button",{type:"button",onClick:n,className:"inline-flex h-4 w-4 items-center justify-center rounded text-white/40 opacity-0 transition-opacity hover:text-white/70 focus-visible:opacity-100 group-hover/discover:opacity-60",title:e?"Collapse discoverable sources":"Show all discoverable sources","aria-label":e?"Collapse discoverable sources":"Show all discoverable sources","aria-expanded":e,children:e?(0,mr.jsx)(qt,{className:"h-3 w-3"}):(0,mr.jsx)(ss,{className:"h-3 w-3"})})]}),(0,mr.jsx)("ul",{className:"overlay-scroll overflow-y-auto pb-1",style:{maxHeight:e?"60vh":PA*iv},children:t.map(s=>(0,mr.jsx)(RA,{suggestion:s,onPick:r},s.id))})]})}var RA=_c.default.memo(function({suggestion:e,onPick:n}){let r=Oc("unattached"),a=(0,Ir.resolveLucideIcon)(e.icon??null)??rr,s=(0,_c.useCallback)(()=>n(e),[n,e]),i=[e.description,e.root].filter(Boolean).join(`
|
|
3
|
+
`);return(0,mr.jsx)("li",{children:(0,mr.jsxs)("button",{type:"button",onClick:s,title:i||r.title,style:{height:iv},className:V("flex w-full items-center gap-2 px-2 text-left transition-colors hover:bg-white/[0.05]",r.containerClassName),children:[(0,mr.jsx)(a,{className:V("h-4 w-4 shrink-0",r.iconClassName)}),(0,mr.jsx)("span",{className:V("truncate text-xs font-medium",r.labelClassName),children:e.label}),(0,mr.jsxs)("span",{className:V("shrink-0 font-mono text-[9px]",r.detailClassName),children:[e.suggestedScheme,"://"]})]})})});var Co=W(Je(),1),dv=W(ue(),1),lv=(0,Co.createContext)(null),Dh=null;function Ln(){let t=(0,Co.useContext)(lv);if(!t)throw new Error("useFilesystemHost must be used within a FilesystemHostProvider");return t}function uv(){return Dh}function cv({value:t,children:e}){return Dh=t,(0,Co.useEffect)(()=>{Dh=t},[t]),(0,dv.jsx)(lv.Provider,{value:t,children:e})}var hv=W(nr(),1);function fv(t){return String(t||"").trim().toLowerCase().replace(/[\s_]+/g,"-")}function qs(t){let e=new Map,n=new Map,r=new Map;return t.ids.forEach((a,s)=>{let i=t.byId[a];if(!i)return;e.set(a,i);let o=i.slug?fv(i.slug):"";o&&n.set(o,i);let l=i.name?fv(i.name):"";l&&n.set(l,i);let u=i.config?.appearance?.color,c=(0,hv.resolveAgentColor)(u,s);r.set(a,c)}),{byId:e,bySlug:n,accentById:r}}function Io(t,e){if(t)return e.accentById.get(t)}var _r=W(Je(),1);var pv=W(fa(),1);var TA=W(ue(),1);function Lo(t){let e=It(t)||t.split("/").pop()||"",n=NA(e);return MA(e.toLowerCase(),n)}function NA(t){return t.includes(".")?t.split(".").pop().toLowerCase():""}function MA(t,e){if(t==="dockerfile")return go;if(t==="package.json")return Ma;if(t===".gitignore"||t===".env"||t.startsWith(".env."))return Da;if(t==="tsconfig.json"||t==="tsconfig.base.json")return Ma;if(t.endsWith(".d.ts"))return is;let n=new Set(["ts","tsx","js","jsx","py","java","kt","php","go","rs","cpp","c","hpp","cs","swift","sh","bash","zsh","ps1","prisma"]),r=new Set(["md","mdx","txt","yml","yaml","xml","ini","toml","css","scss","html","csv","xls","xlsx"]),a=new Set(["png","jpg","jpeg","gif","webp","svg"]),s=new Set(["mp4","mov","webm"]),i=new Set(["mp3","wav"]),o=new Set(["zip","gz","tar","rar","lock"]);return e==="json"||e==="jsonl"?Ma:n.has(e)?is:r.has(e)?Da:a.has(e)?Hl:s.has(e)?Os:i.has(e)?$l:o.has(e)?go:Ul}var Eh=W(ue(),1),DA={M:"text-amber-400",A:"text-emerald-400",D:"text-rose-400",R:"text-sky-400",C:"text-sky-400",U:"text-rose-400","?":"text-emerald-400"},FA={M:"bg-amber-400",A:"bg-emerald-400",D:"bg-rose-400",R:"bg-sky-400",C:"bg-sky-400",U:"bg-rose-400","?":"bg-emerald-400"},Fh={M:"Modified",A:"Added",D:"Deleted",R:"Renamed",C:"Copied",U:"Unmerged","?":"Untracked"};function EA(t){let e=t[0]??" ",n=t[1]??" ";if(e==="?"||n==="?")return"?";let r=n!==" "?n:e;return r===" "?null:r}function Hc({code:t,dot:e=!1}){let n=EA(t);if(!n)return null;let r=t[0]!==" "&&t[0]!=="?",a=t[1]!==" "&&t[1]!=="?",s=(Fh[n]??"Changed")+(r&&a?" (staged + unstaged)":r?" (staged)":"");if(e)return(0,Eh.jsx)("span",{className:V("shrink-0 w-1.5 h-1.5 rounded-full",FA[n]??"bg-white/60"),title:`Git: contains ${(Fh[n]??"changes").toLowerCase()}`,"aria-label":`Git: folder contains changes (${Fh[n]??"changed"})`});let i=n==="?"?"U":n;return(0,Eh.jsx)("span",{className:V("shrink-0 text-[10px] font-bold leading-none tabular-nums",DA[n]??"text-white/60"),title:`Git: ${s}`,"aria-label":`Git status: ${s}`,children:i})}var vn=W(ue(),1),lu="application/x-neuralis-fs-node";function OA({uri:t,tone:e,title:n}){let r=Lo(t);return(0,vn.jsx)("span",{className:V("inline-flex items-center justify-center shrink-0",e),title:n,children:(0,vn.jsx)(r,{className:"w-4 h-4"})})}var mv=_r.default.memo(function({node:e,depth:n=0,agentId:r,projectId:a,isActive:s,isExpanded:i,badgeCount:o,isDrop:l,isSelectedFolder:u,mark:c,agentIndex:d,fallbackAgent:f,uploading:h,packageIconBySlug:p,onToggleFolder:g,onOpenFile:m,onClearFileMark:x,onSetDropTarget:b,onUploadMany:y,onMoveFileToFolder:C,pendingReviewCount:I,isSelected:L,isCut:v,renaming:k,onNodeClick:O,onNodeContextMenu:R,onRenameCommit:P,onRenameCancel:H}){let w=e.type==="folder",N=e.status==="deleted",j=e.status==="pending_review",K=!w&&e.version?.diff?e.version.diff:void 0,A=e.storeKey||as(e),F=(0,_r.useRef)(null),_=e.sourceAgentId?d.byId.get(e.sourceAgentId)??null:f,X=Io(_?.id,d),re=(0,_r.useMemo)(()=>ou(e),[e]),ae=!!(K&&(K.added>0||K.removed>0)),Le=!!(w&&o),ye=!!c,q=!!e.git,Q=Li(e.version?.changedAt),te=(0,_r.useMemo)(()=>{if(!w||!p)return null;let Ue=e.uri.match(/^(packages|data):\/\/([^/]+)\/?$/);return Ue?Ue[2]:null},[w,e.uri,p]),de=(te?p?.[te]:void 0)??nv(i),De=rv(e).join(" \u2022 "),Xe=ae||Le||ye||j||q,Qe=(0,_r.useCallback)(()=>{g({key:A})},[A,g]),rt=(0,_r.useCallback)(()=>{m({agentId:r,projectId:a??null,uri:e.uri,readAgentId:_?.id}),c&&x({agentId:r,path:e.uri})},[r,e.uri,_?.id,m,x,a,c]),at=(0,_r.useCallback)(Ue=>{let ut=Ue.metaKey||Ue.ctrlKey,st=Ue.shiftKey;if(ut||st){O?.({node:e,additive:ut,range:st});return}O?.({node:e,additive:!1,range:!1}),w?Qe():rt()},[e,w,O,Qe,rt]),Ft=(0,_r.useCallback)(Ue=>{Ue.preventDefault(),Ue.stopPropagation(),R?.({node:e,x:Ue.clientX,y:Ue.clientY})},[e,R]);return(0,vn.jsxs)("div",{ref:F,className:V("group flex h-7 items-center gap-1.5 px-2 rounded-md cursor-pointer select-none transition-colors",s?"bg-white/10 text-white":"text-white/70 hover:bg-white/5 hover:text-white",u?"bg-sky-500/15 text-sky-100":"",L&&!s?"bg-sky-400/20 ring-1 ring-inset ring-sky-400/30 text-white":"",j&&!s?"bg-amber-500/[0.08] border-l-2 border-l-amber-400/60":"",N?"opacity-70":"",v?"opacity-45":"",l?"bg-white/10":""),style:{paddingLeft:`${n*12+8}px`},draggable:!k,onDragStart:Ue=>{let ut={kind:"filesystem",action:w?"list":"read",uri:e.uri};Ue.dataTransfer.setData("application/x-neuralis-fs-ref",JSON.stringify(ut)),Ue.dataTransfer.setData(lu,JSON.stringify({type:e.type,uri:e.uri,id:e.id,name:e.name})),Ue.dataTransfer.setData("text/plain",`\u27E6fs:${w?"list":"read"}:${e.uri}\u27E7`),Ue.dataTransfer.effectAllowed="copyMove"},onClick:at,onContextMenu:Ft,onDragOver:Ue=>{if(!w||h)return;let ut=Array.from(Ue.dataTransfer.types||[]);(ut.includes("Files")||ut.includes(lu))&&(Ue.preventDefault(),Ue.dataTransfer.dropEffect=ut.includes(lu)?"move":"copy",b(A))},onDragLeave:()=>{l&&b(null)},onDrop:async Ue=>{if(!w||h)return;let ut=Array.from(Ue.dataTransfer.types||[]),st=ut.includes("Files"),yt=ut.includes(lu);if(!(!st&&!yt)){if(Ue.preventDefault(),b(null),yt){let vt=Ue.dataTransfer.getData(lu);if(!vt)return;try{let Ut=JSON.parse(vt);if(!Ut.uri||Ut.uri===e.uri||e.uri===Ut.uri||e.uri.startsWith(`${Ut.uri}/`))return;await C({fromUri:Ut.uri,id:Ut.id,toFolderUri:e.uri});return}catch{return}}if(st){let vt=Array.from(Ue.dataTransfer.files||[]);if(vt.length===0)return;await y({agentId:r,projectId:a??null,files:vt,uri:e.uri})}}},title:`${e.uri}${De?`
|
|
4
|
+
${De}`:""}`,"aria-label":`${e.name} \u2014 ${De}`,children:[(0,vn.jsx)("span",{className:"shrink-0 text-white/40",children:w?i?(0,vn.jsx)(qt,{className:"w-3.5 h-3.5"}):(0,vn.jsx)(Sn,{className:"w-3.5 h-3.5"}):(0,vn.jsx)("span",{className:"w-3.5 h-3.5 inline-block"})}),w?(0,vn.jsx)("span",{title:re.title,children:(0,vn.jsx)(de,{className:V("w-4 h-4 shrink-0",re.iconTone),style:{color:e.presence==="brain"&&X||void 0}})}):(0,vn.jsx)(OA,{uri:e.uri,tone:re.iconTone,title:re.title}),k?(0,vn.jsx)(BA,{initial:e.name,onCommit:Ue=>P?.({node:e,newName:Ue}),onCancel:()=>H?.()}):(0,vn.jsx)("span",{className:V("min-w-0 text-xs truncate flex-1 transition-colors",re.tone,re.ghosted&&"opacity-70",N&&"line-through"),children:e.name}),Xe?(0,vn.jsxs)("span",{className:"ml-1 shrink-0 flex items-center justify-end gap-1",children:[j?(0,vn.jsx)("span",{title:"Pending review",className:"shrink-0 flex items-center",children:(0,vn.jsx)(pv.LivePulseDot,{className:"text-amber-400/80 shrink-0"})}):null,ye?(0,vn.jsx)("span",{className:V("w-1.5 h-1.5 rounded-full shrink-0",c?.kind==="new"?"bg-emerald-400":"bg-blue-400"),title:c?.kind==="new"?"New file":"Modified"}):null,q&&e.git?(0,vn.jsx)(Hc,{code:e.git,dot:w}):null,ae?(0,vn.jsx)(sv,{className:V("w-3.5 h-3.5 shrink-0",Q.iconClassName),title:Q.label}):null,Le?(0,vn.jsx)("span",{className:V("inline-flex items-center justify-center min-w-[16px] h-4 px-1 rounded-full text-[9px] font-semibold",I?"bg-amber-500/20 text-amber-200":"bg-sky-500/15 text-sky-200"),children:o}):null]}):null]})});function BA({initial:t,onCommit:e,onCancel:n}){let r=(0,_r.useRef)(!1);return(0,vn.jsx)("input",{autoFocus:!0,defaultValue:t,spellCheck:!1,onFocus:a=>{let s=a.currentTarget.value,i=s.lastIndexOf(".");a.currentTarget.setSelectionRange(0,i>0?i:s.length)},onClick:a=>a.stopPropagation(),onMouseDown:a=>a.stopPropagation(),onKeyDown:a=>{a.stopPropagation(),a.key==="Enter"?r.current||(r.current=!0,e(a.currentTarget.value)):a.key==="Escape"&&(r.current||(r.current=!0,n()))},onBlur:a=>{r.current||(r.current=!0,e(a.currentTarget.value))},className:"min-w-0 flex-1 rounded border border-sky-400/60 bg-black/50 px-1 py-0 text-xs text-white outline-none"})}var $s=W(Je(),1),gv=W(ds(),1);var Vs=W(ue(),1),_A=[{kind:"item",action:"new-file",label:"New File\u2026",Icon:_s},{kind:"item",action:"new-folder",label:"New Folder\u2026",Icon:Or},{kind:"sep"},{kind:"item",action:"cut",label:"Cut",Icon:Yl,shortcut:"\u2318X"},{kind:"item",action:"copy",label:"Copy",Icon:ga,shortcut:"\u2318C"},{kind:"item",action:"paste",label:"Paste",Icon:Fl,shortcut:"\u2318V"},{kind:"sep"},{kind:"item",action:"copy-path",label:"Copy Path",Icon:Wl},{kind:"item",action:"copy-relative-path",label:"Copy Relative Path",Icon:Ol},{kind:"sep"},{kind:"item",action:"reembed",label:"Re-embed\u2026",Icon:Fa},{kind:"sep"},{kind:"item",action:"rename",label:"Rename",Icon:Gs,shortcut:"F2"},{kind:"item",action:"delete",label:"Delete",Icon:_t,danger:!0,shortcut:"Del"}],HA=[{kind:"item",action:"new-file",label:"New File\u2026",Icon:_s},{kind:"item",action:"new-folder",label:"New Folder\u2026",Icon:Or}],UA=210;function xv({x:t,y:e,enabled:n,onAction:r,onClose:a,variant:s="node"}){let i=s==="source"?HA:_A,o=(0,$s.useRef)(null),[l,u]=(0,$s.useState)({top:e,left:t});return(0,$s.useLayoutEffect)(()=>{let c=o.current;if(!c)return;let d=c.getBoundingClientRect(),f=t,h=e;f+d.width>window.innerWidth-4&&(f=Math.max(4,window.innerWidth-d.width-4)),h+d.height>window.innerHeight-4&&(h=Math.max(4,window.innerHeight-d.height-4)),u({top:h,left:f})},[t,e]),(0,$s.useEffect)(()=>{let c=h=>{o.current?.contains(h.target)||a()},d=h=>{h.key==="Escape"&&a()},f=()=>a();return document.addEventListener("mousedown",c,!0),document.addEventListener("keydown",d,!0),window.addEventListener("resize",f),window.addEventListener("scroll",f,!0),()=>{document.removeEventListener("mousedown",c,!0),document.removeEventListener("keydown",d,!0),window.removeEventListener("resize",f),window.removeEventListener("scroll",f,!0)}},[a]),(0,gv.createPortal)((0,Vs.jsx)("div",{ref:o,role:"menu",style:{position:"fixed",top:l.top,left:l.left,width:UA},className:"z-[1000] rounded-lg border border-white/10 bg-[#14141b] py-1 text-[11px] text-white/80 shadow-[0_18px_46px_-20px_rgba(0,0,0,0.8)]",onContextMenu:c=>c.preventDefault(),children:i.map((c,d)=>{if(c.kind==="sep")return(0,Vs.jsx)("div",{className:"my-1 h-px bg-white/[0.06]"},`s${d}`);let f=n[c.action]===!0,h=c.Icon;return(0,Vs.jsxs)("button",{type:"button",role:"menuitem",disabled:!f,onClick:()=>{f&&(r(c.action),a())},className:V("flex w-full items-center gap-2 px-3 py-1.5 text-left transition",f?"hover:bg-white/[0.06]":"opacity-35 cursor-not-allowed",c.danger&&f?"text-rose-200 hover:bg-rose-500/10":""),children:[(0,Vs.jsx)(h,{className:V("w-3.5 h-3.5 shrink-0",c.danger?"text-rose-300/80":"text-white/45")}),(0,Vs.jsx)("span",{className:"flex-1 truncate",children:c.label}),c.shortcut?(0,Vs.jsx)("span",{className:"text-[9px] text-white/30 tabular-nums",children:c.shortcut}):null]},c.action)})}),document.body)}var bv=W(Je(),1),yv=W(ds(),1);var Dn=W(ue(),1);function vv({names:t,busy:e,onCancel:n,onConfirm:r}){(0,bv.useEffect)(()=>{let i=o=>{e||(o.key==="Escape"?(o.preventDefault(),n()):o.key==="Enter"&&(o.preventDefault(),r()))};return document.addEventListener("keydown",i,!0),()=>document.removeEventListener("keydown",i,!0)},[e,n,r]);let a=t.length>1,s=a?`Delete ${t.length} items?`:`Delete '${t[0]}'?`;return(0,yv.createPortal)((0,Dn.jsx)("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/40 backdrop-blur-[1px]",onMouseDown:i=>{i.target===i.currentTarget&&!e&&n()},children:(0,Dn.jsxs)("div",{className:"w-[340px] rounded-xl border border-rose-400/25 bg-[#15151d] p-4 shadow-[0_30px_80px_-24px_rgba(0,0,0,0.85)]",children:[(0,Dn.jsxs)("div",{className:"flex items-start gap-2.5",children:[(0,Dn.jsx)(gt,{className:"h-4 w-4 text-rose-300 shrink-0 mt-0.5"}),(0,Dn.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,Dn.jsx)("div",{className:"text-[12px] font-semibold text-white/90",children:s}),(0,Dn.jsxs)("div",{className:"mt-1 text-[10.5px] text-white/55 leading-relaxed",children:[a?"The selected files move to Pending Changes. ":"The file moves to Pending Changes. ",(0,Dn.jsx)("span",{className:"text-white/75",children:"You can restore"})," ",a?"them":"it"," from there \u2014 this is not a permanent erase."]}),a?(0,Dn.jsxs)("div",{className:"mt-2 max-h-24 overflow-auto rounded-md bg-white/[0.03] px-2 py-1.5 text-[10px] font-mono text-white/50 space-y-0.5 overlay-scroll",children:[t.slice(0,12).map(i=>(0,Dn.jsx)("div",{className:"truncate",children:i},i)),t.length>12?(0,Dn.jsxs)("div",{className:"text-white/35",children:["+",t.length-12," more\u2026"]}):null]}):null]})]}),(0,Dn.jsxs)("div",{className:"mt-4 flex items-center justify-end gap-2",children:[(0,Dn.jsxs)("button",{type:"button",onClick:n,disabled:e,className:"h-7 px-2.5 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[11px] font-medium text-white/70 transition disabled:opacity-40 inline-flex items-center gap-1",children:[(0,Dn.jsx)(Yt,{className:"h-3 w-3"}),"Cancel"]}),(0,Dn.jsxs)("button",{type:"button",onClick:r,disabled:e,className:V("h-7 px-3 rounded-md text-[11px] font-semibold transition disabled:opacity-40 inline-flex items-center gap-1.5","bg-rose-500/20 hover:bg-rose-500/30 border border-rose-400/40 text-rose-100"),children:[e?(0,Dn.jsx)($e,{className:"h-3 w-3 animate-spin"}):(0,Dn.jsx)(_t,{className:"h-3 w-3"}),"Delete"]})]})]})}),document.body)}var hs=W(Je(),1),wv=W(ds(),1);var Lt=W(ue(),1);function GA(t){return t.usd===null?"unpriced \u2014 the active model has no price":`~$${t.usd.toFixed(2)}${t.usdMargin!==null?` \xB1 $${t.usdMargin.toFixed(2)}`:""}`}function zA(t){return t===null?"time unknown":t<90?`~${Math.round(t)} s`:t<5400?`~${Math.round(t/60)} min`:`~${(t/3600).toFixed(1)} h`}function uu({agentId:t,projectId:e,target:n,onClose:r,onStarted:a,kind:s="reembed"}){let i=B(y=>y.client),[o,l]=(0,hs.useState)(null),[u,c]=(0,hs.useState)(!0),[d,f]=(0,hs.useState)(!1),[h,p]=(0,hs.useState)(null),[g,m]=(0,hs.useState)(!1),x={agentId:t,...e?{projectId:e}:{},source:n.source,...n.folder?{folder:n.folder}:{},...n.uri?{uri:n.uri}:{}};(0,hs.useEffect)(()=>{let y=!0;return c(!0),yx(x,s,i).then(C=>{y&&l(C)}).catch(C=>{y&&p(C instanceof Error?C.message:"Estimate failed")}).finally(()=>{y&&c(!1)}),()=>{y=!1}},[]),(0,hs.useEffect)(()=>{let y=C=>{C.key==="Escape"&&!d&&(C.preventDefault(),r())};return document.addEventListener("keydown",y,!0),()=>document.removeEventListener("keydown",y,!0)},[d,r]);let b=async()=>{f(!0),p(null);try{if(!(await Ic(x,s,i)).job){m(!0),f(!1);return}a?.(),r()}catch(y){p(y instanceof Error?y.message:"Re-embed failed"),f(!1)}};return(0,wv.createPortal)((0,Lt.jsx)("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/40 backdrop-blur-[1px]",onMouseDown:y=>{y.target===y.currentTarget&&!d&&r()},children:(0,Lt.jsxs)("div",{role:"dialog","aria-label":`${s==="pending"?"Embed pending files of":"Re-embed"} ${n.label}`,className:"w-[360px] rounded-xl border border-cyan-400/25 bg-[#15151d] p-4 shadow-[0_30px_80px_-24px_rgba(0,0,0,0.85)]",children:[(0,Lt.jsxs)("div",{className:"flex items-start gap-2.5",children:[(0,Lt.jsx)(Fa,{className:"h-4 w-4 text-cyan-300 shrink-0 mt-0.5"}),(0,Lt.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,Lt.jsx)("div",{className:"truncate text-[12px] font-semibold text-white/90",children:s==="pending"?`Embed pending files of ${n.label}?`:`Re-embed ${n.label}?`}),(0,Lt.jsx)("div",{className:"mt-1 text-[10.5px] text-white/55 leading-relaxed",children:s==="pending"?(0,Lt.jsxs)(Lt.Fragment,{children:["Only files whose semantic embedding is missing or stale are embedded, with the"," ",(0,Lt.jsx)("span",{className:"text-white/75",children:"active"})," model. The figures below cover the whole scope \u2014 an upper bound; files already embedded are skipped. Contents and text search are not touched."]}):(0,Lt.jsxs)(Lt.Fragment,{children:["Every file in this scope is read again and embedded with the ",(0,Lt.jsx)("span",{className:"text-white/75",children:"active"})," ","model, whether it changed or not. File contents and history are not touched \u2014 only the vectors are replaced."]})}),(0,Lt.jsx)("div",{className:"mt-2 rounded-md bg-white/[0.03] px-2 py-1.5 text-[10.5px] text-white/65 space-y-0.5",children:u?(0,Lt.jsxs)("div",{className:"inline-flex items-center gap-1.5 text-white/45",children:[(0,Lt.jsx)($e,{className:"h-3 w-3 animate-spin"}),"Estimating from a sample\u2026"]}):o?(0,Lt.jsxs)(Lt.Fragment,{children:[(0,Lt.jsxs)("div",{children:[o.documents!==null?`${o.documents.toLocaleString()} documents \xB7 `:null,o.points.toLocaleString()," points"]}),(0,Lt.jsxs)("div",{children:["~",o.tokens.toLocaleString(),o.tokensMargin!==null?` \xB1 ${o.tokensMargin.toLocaleString()}`:""," tokens"]}),(0,Lt.jsxs)("div",{children:[GA(o)," \xB7 ",zA(o.durationSeconds)]}),o.truncated?(0,Lt.jsx)("div",{className:"text-amber-300/80",children:"The scope is larger than one listing \u2014 these figures cover its first part."}):null]}):h?null:(0,Lt.jsx)("div",{className:"text-white/45",children:"No estimate available for this scope."})}),h?(0,Lt.jsx)("div",{className:"mt-2 text-[10px] text-rose-300/90",children:h}):null,g?(0,Lt.jsx)("div",{className:"mt-2 text-[10px] text-white/55",children:"Nothing readable in this scope \u2014 nothing was queued."}):null]})]}),(0,Lt.jsxs)("div",{className:"mt-4 flex items-center justify-end gap-2",children:[(0,Lt.jsxs)("button",{type:"button",onClick:r,disabled:d,className:"h-7 px-2.5 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[11px] font-medium text-white/70 transition disabled:opacity-40 inline-flex items-center gap-1",children:[(0,Lt.jsx)(Yt,{className:"h-3 w-3"}),"Cancel"]}),(0,Lt.jsxs)("button",{type:"button",onClick:()=>{b()},disabled:d||u||g,className:"h-7 px-3 rounded-md text-[11px] font-semibold transition disabled:opacity-40 inline-flex items-center gap-1.5 bg-cyan-500/20 hover:bg-cyan-500/30 border border-cyan-400/40 text-cyan-100",children:[d?(0,Lt.jsx)($e,{className:"h-3 w-3 animate-spin"}):(0,Lt.jsx)(Fa,{className:"h-3 w-3"}),s==="pending"?"Embed pending":"Re-embed"]})]})]})}),document.body)}var Ao=W(Je(),1);var Sv=W(fa(),1);var _n=W(ue(),1);function WA(t){if(!t)return null;if(t.isRepo&&t.repoName)return{label:t.repoName,title:`Repository: ${t.repoName}`};if(t.containsRepos&&t.repoNames&&t.repoNames.length>0){let e=t.repoNames,n=e.slice(0,2).join(", ");return{label:e.length>2?`${n} +${e.length-2}`:n,title:`Repositories: ${e.join(", ")}`}}return null}function jA({info:t}){let e=(0,Ir.resolveIconWithFallback)(t.kind_icon??void 0,rr),n=t.source_kind==="brain"||t.source_kind==="local-disk",r=!!(t.git?.isRepo||t.git?.containsRepos);return(0,_n.jsxs)("span",{className:"relative inline-flex items-center justify-center",children:[(0,_n.jsx)(e,{className:"w-4 h-4"}),n?(0,_n.jsx)(Kl,{className:"absolute -right-1.5 -bottom-1.5 w-2.5 h-2.5 text-current bg-black/80 rounded-full p-[1px] opacity-80"}):null,r?(0,_n.jsx)(Bn,{className:"absolute -right-1.5 -top-1.5 w-2.5 h-2.5 text-violet-300/90 bg-black/80 rounded-full p-[1px]"}):null]})}function kv(t){return t.source_kind==="brain"?"brain":Ke(t.uri_root)}var Cv=Ao.default.memo(function({info:e,expanded:n,onToggle:r,onContextMenu:a,onRefresh:s,hydration:i="ready",dirty:o=!1,hideChevron:l=!0,compact:u=!1}){let c=(0,Ao.useCallback)(()=>r(e.uri_root),[r,e.uri_root]),d=(0,Ao.useCallback)(x=>a?.(e.uri_root,x),[a,e.uri_root]),f=(0,Ao.useCallback)(x=>{x.stopPropagation(),x.preventDefault(),s?.(e.uri_root)},[s,e.uri_root]),h=Bc(e),p=av(e),g=WA(e.git),m=i==="loading";return(0,_n.jsxs)("div",{className:V("group flex w-full items-center gap-2 rounded-md select-none text-left transition-colors",u?"py-1 px-1.5":"py-1.5 px-2","hover:bg-white/5",n&&"bg-white/[0.03]"),onContextMenu:d,"aria-busy":m||void 0,children:[(0,_n.jsxs)("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-2 bg-transparent text-left outline-none",onClick:c,"aria-expanded":n,title:p?`${e.uri_root} \u2014 ${p}`:e.uri_root,children:[l?null:(0,_n.jsx)("span",{className:"w-0","aria-hidden":"true"}),(0,_n.jsx)("span",{className:V("shrink-0",h.iconClassName,i==="idle"||i==="error"?"opacity-50":""),children:(0,_n.jsx)(jA,{info:e})}),(0,_n.jsx)("span",{className:V("text-xs font-medium flex-1 truncate transition-colors",h.labelClassName,i==="idle"||i==="error"?"opacity-70":""),children:kv(e)})]}),g?(0,_n.jsxs)("span",{className:"ml-1 inline-flex max-w-[120px] shrink-0 items-center gap-0.5 text-[10px] text-violet-300/70",title:g.title,children:[(0,_n.jsx)(Bn,{className:"h-2.5 w-2.5 shrink-0"}),(0,_n.jsx)("span",{className:"truncate",children:g.label})]}):null,s?(0,_n.jsx)("button",{type:"button",onClick:f,disabled:m,"aria-label":`Refresh ${kv(e)}`,title:i==="error"?"Last listing failed \u2014 click to retry":o?"This source may be out of date \u2014 click to refresh":"Refresh this source",className:V("shrink-0 inline-flex h-4 w-4 items-center justify-center rounded transition-opacity","text-white/40 hover:text-white/80 focus-visible:opacity-100",m||o||i==="error"?"opacity-100":"opacity-0 group-hover:opacity-100",o||i==="error"?"text-amber-300/80 hover:text-amber-200":""),children:m?(0,_n.jsx)(Sv.LiveSpinner,{className:"h-3 w-3"}):(0,_n.jsx)(Xt,{className:"h-3 w-3","aria-hidden":"true"})}):null]})});var Ro=W(Je(),1);var dt=W(ue(),1),qA=[{id:"keyword",label:"Keyword",hint:"Indexed word search (primary)"},{id:"semantic",label:"Semantic",hint:"Embedding search by meaning"},{id:"grep",label:"Grep",hint:"Literal scan of live connector content"}],Po="h-6 w-full bg-transparent border border-white/[0.06] rounded px-1.5 text-[11px] text-white/80 placeholder:text-white/25 outline-none focus:border-white/20";function VA(t){return t?t.requestedMode==="semantic"&&t.effectiveMode&&t.effectiveMode!=="semantic"?`Searched as keyword \u2014 semantic search unavailable${t.embeddingDegraded?` (${t.embeddingDegraded})`:""}. Use specific words.`:t.warning??null:null}function Iv({agentId:t}){let e=B(k=>k.activeProjectId),n=B(k=>k.setActiveFolderPath),r=B(k=>k.openFile),a=B(k=>k.searchQuery),s=B(k=>k.searchMode),i=B(k=>k.setSearchMode),o=B(k=>k.searchFilters),l=B(k=>k.setSearchFilters),u=B(k=>k.searchResults),c=B(k=>k.searchLoading),d=B(k=>k.searchError),f=B(k=>k.searchEffect),h=VA(f),p=B(k=>k.runSearch),g=B(k=>k.activeFolderPath),m=B(k=>k.sources),[x,b]=(0,Ro.useState)(!1),y=a.trim(),C=o.glob.trim(),I=s==="keyword"?y.length>=2||C.length>=2:y.length>=2,L=(0,Ro.useMemo)(()=>hh(g,m,o.scopeToFolder),[g,m,o.scopeToFolder]);(0,Ro.useEffect)(()=>{if(!I)return;let k=setTimeout(()=>{p({agentId:t,projectId:e??null})},250);return()=>clearTimeout(k)},[t,e,I,s,a,o,p]);let v=(C?1:0)+(o.category.trim()?1:0)+(o.status.trim()?1:0)+(o.tags.trim()?1:0)+(o.createdAfter.trim()?1:0)+(o.createdBefore.trim()?1:0)+(o.scopeToFolder?1:0);return(0,dt.jsxs)("div",{className:"px-2 pb-2",children:[(0,dt.jsxs)("div",{className:"flex items-center gap-1 pb-1.5",children:[(0,dt.jsx)("div",{className:"flex-1 flex items-center rounded-md border border-white/[0.06] overflow-hidden",children:qA.map(k=>{let O=k.id==="grep"&&!L;return(0,dt.jsx)("button",{type:"button",disabled:O,onClick:()=>i(k.id),title:O?"Grep needs a disk-backed source (brain:// has no live text)":k.hint,className:`flex-1 h-6 text-[10px] uppercase tracking-wide transition-colors ${s===k.id?"bg-white/[0.08] text-white/85":O?"text-white/20 cursor-not-allowed":"text-white/40 hover:text-white/70"}`,"aria-pressed":s===k.id,children:k.label},k.id)})}),(0,dt.jsxs)("button",{type:"button",onClick:()=>b(k=>!k),className:`h-6 w-6 shrink-0 rounded-md inline-flex items-center justify-center transition-colors ${x||v>0?"text-white/85":"text-white/40 hover:text-white/70"}`,title:"Search filters","aria-label":"Toggle search filters","aria-pressed":x,children:[(0,dt.jsx)(Si,{className:"w-3.5 h-3.5"}),v>0?(0,dt.jsx)("span",{className:"absolute translate-x-2.5 -translate-y-2 text-[8px] text-white/70",children:v}):null]})]}),x?(0,dt.jsxs)("div",{className:"pb-2 space-y-1",children:[(0,dt.jsxs)("div",{className:"flex items-center gap-1",children:[(0,dt.jsx)("input",{type:"text",value:o.glob,onChange:k=>l({glob:k.target.value}),placeholder:"Filename\u2026",className:Po}),(0,dt.jsxs)("label",{className:"flex items-center gap-1 shrink-0 text-[10px] text-white/45 select-none cursor-pointer",title:"Scope to the active folder",children:[(0,dt.jsx)("input",{type:"checkbox",checked:o.scopeToFolder,onChange:k=>l({scopeToFolder:k.target.checked}),className:"accent-white/60"}),"folder"]})]}),s!=="grep"?(0,dt.jsxs)(dt.Fragment,{children:[(0,dt.jsxs)("div",{className:"flex items-center gap-1",children:[(0,dt.jsx)("input",{type:"text",value:o.category,onChange:k=>l({category:k.target.value}),placeholder:"Category\u2026",className:Po}),(0,dt.jsx)("input",{type:"text",value:o.status,onChange:k=>l({status:k.target.value}),placeholder:"Status\u2026",className:Po})]}),(0,dt.jsx)("input",{type:"text",value:o.tags,onChange:k=>l({tags:k.target.value}),placeholder:"Tags (comma-separated)\u2026",className:Po}),(0,dt.jsxs)("div",{className:"flex items-center gap-1",children:[(0,dt.jsx)("input",{type:"date",value:o.createdAfter,onChange:k=>l({createdAfter:k.target.value}),title:"Created after",className:Po}),(0,dt.jsx)("input",{type:"date",value:o.createdBefore,onChange:k=>l({createdBefore:k.target.value}),title:"Created before",className:Po})]})]}):null]}):null,I?c?(0,dt.jsx)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:"Searching\u2026"}):d?(0,dt.jsx)("div",{className:"px-2 py-3 text-[11px] text-red-300/70",children:d}):u.length===0?(0,dt.jsxs)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:[h?(0,dt.jsx)("div",{role:"status",className:"mb-1 text-[10px] text-amber-200/70",children:h}):null,"No matches"]}):(0,dt.jsxs)("div",{className:"space-y-1",children:[h?(0,dt.jsx)("div",{role:"status",className:"px-2 py-1 text-[10px] text-amber-200/70",children:h}):null,u.map(k=>(0,dt.jsxs)("button",{type:"button",className:"w-full text-left px-2 py-2 rounded-md hover:bg-white/5 border border-white/[0.04] transition-colors",onClick:()=>{n(ct(k.uri)),r({agentId:t,projectId:e??null,uri:k.uri})},children:[(0,dt.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,dt.jsx)("span",{className:"text-[11px] text-white/80 truncate flex-1",children:k.filename}),typeof k.score=="number"?(0,dt.jsx)("span",{className:"text-[9px] text-white/30 shrink-0",children:k.score.toFixed(2)}):null,k.embedding_status==="missing"||k.embedding_status==="stale"?(0,dt.jsxs)("span",{className:"text-[9px] px-1 py-0.5 rounded bg-white/[0.06] text-white/40 shrink-0",title:"This file is text-searchable; its semantic embedding is not current",children:["embedding ",k.embedding_status]}):null,k.match_type?(0,dt.jsx)("span",{className:"text-[9px] px-1 py-0.5 rounded bg-white/[0.06] text-white/40 shrink-0",children:k.match_type==="hybrid"?"H":k.match_type==="semantic"?"S":"K"}):null]}),(0,dt.jsxs)("div",{className:"text-[10px] text-white/35 font-mono truncate",children:[k.uri,s==="grep"&&typeof k.chunk_start=="number"?`:${k.chunk_start}`:""]}),k.snippet??k.content_preview?(0,dt.jsx)("div",{className:"text-[10px] text-white/45 mt-1 line-clamp-2",children:k.snippet??k.content_preview}):null]},`${k.id}:${k.uri}:${k.chunk_start??""}`))]}):(0,dt.jsx)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:s==="keyword"?"Type to search (or set a filename filter)\u2026":"Type to search\u2026"})]})}var ke=W(Je(),1),O1=W(ds(),1);var B1=W(nr(),1);var ft=W(Je(),1);var k1=W(fa(),1);var Ai=W(ue(),1);function $A(t){return t<1e4?String(t):t<1e6?`${Math.round(t/1e3)}k`:`${(t/1e6).toFixed(1)}M`}function Ha({added:t,removed:e,binary:n,unknown:r,compact:a,className:s}){if(n)return(0,Ai.jsx)("span",{className:V("shrink-0 text-[9px] tabular-nums text-white/40",s),title:"Binary file \u2014 git reports no line count",children:"bin"});if(!(typeof t=="number"&&typeof e=="number")||t===0&&e===0&&!r)return null;let o=a?$A:String,l=r?"+":"";return(0,Ai.jsxs)("span",{className:V("flex shrink-0 items-center gap-1 text-[9px] tabular-nums",s),title:r?`+${t} \u2212${e} across the counted files; ${r} more could not be measured`:`+${t} \u2212${e}`,children:[t>0?(0,Ai.jsx)("span",{className:"text-emerald-400/80",children:`+${o(t)}${l}`}):null,e>0?(0,Ai.jsx)("span",{className:"text-rose-400/80",children:`\u2212${o(e)}${l}`}):null,t===0&&e===0?(0,Ai.jsx)("span",{className:"text-white/35",children:`0${l}`}):null]})}function KA(t){return(t.refs??[]).some(e=>e==="HEAD"||e.startsWith("HEAD ")||e.startsWith("HEAD-")||e.includes("HEAD ->"))}function Lv(t){let e=[],n=[];if(!Array.isArray(t)||t.length===0)return{nodes:e,edges:n,rowSegments:[],laneCount:0};let r=[],a=new Map,s=0,i=u=>{let c=r.indexOf(u);if(c>=0)return c;let d=r.indexOf(null);return d>=0?(r[d]=u,d):(r.push(u),r.length-1)};for(let u=0;u<t.length;u++){let c=t[u],d=c.sha,f=r.indexOf(d);f<0&&(f=i(d));for(let p=0;p<r.length;p++)r[p]===d&&(r[p]=null);f>s&&(s=f),a.set(d,{row:u,lane:f});let h=Array.isArray(c.parents)?c.parents:[];if(h.length!==0){r[f]=h[0];for(let p=1;p<h.length;p++){let g=i(h[p]);g>s&&(s=g)}}e.push({commit:c,row:u,lane:f,isHead:KA(c),isMerge:h.length>=2})}let o=t.map(()=>[]),l=(u,c)=>{u>=0&&u<o.length&&o[u].push(c)};for(let u of e){let c=Array.isArray(u.commit.parents)?u.commit.parents:[];for(let d=0;d<c.length;d++){let f=a.get(c[d]);if(f){n.push({fromRow:u.row,fromLane:u.lane,toRow:f.row,toLane:f.lane,colorLane:u.lane,open:!1});let h=u.row,p=f.row,g=u.lane,m=f.lane,x=u.lane;if(p<=h)continue;if(g===m){l(h,{kind:"pass",fromLane:g,toLane:g,fromY:"center",toY:"edge",colorLane:x});for(let b=h+1;b<p;b++)l(b,{kind:"pass",fromLane:g,toLane:g,fromY:"edge",toY:"edge",colorLane:x});l(p,{kind:"pass",fromLane:g,toLane:g,fromY:"edge",toY:"center",colorLane:x})}else{let b=(g+m)/2,y=d>0?"merge":"fork";if(d>0){if(l(h,{kind:y,fromLane:g,toLane:b,fromY:"center",toY:"edge",colorLane:x}),l(h+1,{kind:y,fromLane:b,toLane:m,fromY:"edge",toY:"center",colorLane:x}),h+1<p){l(h+1,{kind:"pass",fromLane:m,toLane:m,fromY:"center",toY:"edge",colorLane:x});for(let C=h+2;C<p;C++)l(C,{kind:"pass",fromLane:m,toLane:m,fromY:"edge",toY:"edge",colorLane:x});l(p,{kind:"pass",fromLane:m,toLane:m,fromY:"edge",toY:"center",colorLane:x})}}else{if(p-1>h){l(h,{kind:"pass",fromLane:g,toLane:g,fromY:"center",toY:"edge",colorLane:x});for(let C=h+1;C<p-1;C++)l(C,{kind:"pass",fromLane:g,toLane:g,fromY:"edge",toY:"edge",colorLane:x});l(p-1,{kind:"pass",fromLane:g,toLane:g,fromY:"edge",toY:"center",colorLane:x})}l(p-1,{kind:y,fromLane:g,toLane:b,fromY:"center",toY:"edge",colorLane:x}),l(p,{kind:y,fromLane:b,toLane:m,fromY:"edge",toY:"center",colorLane:x})}}}else n.push({fromRow:u.row,fromLane:u.lane,toRow:u.row+1,toLane:u.lane,colorLane:u.lane,open:!0}),l(u.row,{kind:"stub",fromLane:u.lane,toLane:u.lane,fromY:"center",toY:"edge",colorLane:u.lane})}}return{nodes:e,edges:n,rowSegments:o,laneCount:s+1}}function Av(t,e){if(!Array.isArray(t)||e<=0||e>=t.length)return[];let n=[],r=new Set;for(let a of t[e]??[]){if(a.fromY!=="edge")continue;let s=`${a.fromLane}|${a.colorLane}`;r.has(s)||(r.add(s),n.push({kind:"pass",fromLane:a.fromLane,toLane:a.fromLane,fromY:"edge",toY:"edge",colorLane:a.colorLane}))}return n}var Oh={commits:[],nextSkip:0,hasMore:!1};function Pv(t,e){let n=[];for(let r of e.commits)!r||typeof r.sha!="string"||t.has(r.sha)||(t.add(r.sha),n.push(r));return n}function Rv(t,e){let n=new Set(t.commits.map(a=>a.sha)),r=Pv(n,e);return{commits:r.length>0?[...t.commits,...r]:t.commits,nextSkip:t.nextSkip+e.commits.length,hasMore:e.hasMore,outgoing:t.outgoing}}function Nv(t){return{commits:Pv(new Set,t),nextSkip:t.commits.length,hasMore:t.hasMore,outgoing:t.outgoing}}function Bh(t){return Math.min(1e3,Math.max(t,200))}function Mv(t,e){let n=[],r=e&&e.length>0?new Set(e):null,a=!1;for(let s=0;s<t.length;s++)!a&&r&&r.has(t[s].sha)&&(n.push({kind:"outgoing-divider"}),a=!0),n.push({kind:"commit",row:s});return n}function Tv(t,e){return t.kind==="outgoing-divider"?"#outgoing-divider":e[t.row]?.sha??`row-${t.row}`}function Dv(t){let e=t.trim();return e.startsWith("tag:")?"tag":e.startsWith("origin/")?"remote":"local"}function Fv(t,e){return e?"outgoing":t?"merge":"filled"}var XA="#89b4fa";function Ev(t,e){return t==="outgoing"?XA:e}function _h(t,e=Date.now()){let n=Date.parse(t);if(Number.isNaN(n))return t;let r=Math.max(0,Math.floor((e-n)/1e3));if(r<60)return"just now";let a=Math.floor(r/60);if(a<60)return`${a}m ago`;let s=Math.floor(a/60);if(s<24)return`${s}h ago`;let i=Math.floor(s/24);if(i<30)return`${i}d ago`;let o=Math.floor(i/30);return o<12?`${o}mo ago`:`${Math.floor(o/12)}y ago`}function Ov(t){return!t||typeof t.upstream!="string"||t.upstream.length===0?null:{upstream:t.upstream,ahead:typeof t.ahead=="number"&&t.ahead>=0?t.ahead:0,behind:typeof t.behind=="number"&&t.behind>=0?t.behind:0}}function Hh(t,e){if(typeof window>"u")return e;try{let n=JSON.parse(window.localStorage.getItem(t)??"null");return typeof n=="boolean"?n:e}catch{return e}}function Uh(t,e){if(!(typeof window>"u"))try{window.localStorage.setItem(t,JSON.stringify(e))}catch{}}function Ks(t,e){return typeof e=="string"&&e.length>0?{prefix:`${t}://`,name:e,title:`Source "${t}" \u2014 repository "${e}"`}:{prefix:"",name:t,title:`Repository: ${t}`}}var ms=W(Je(),1);var Kn=W(Je(),1),YA=3,Bv=200,_v=8*1024*1024,JA="200% 0px";function No(t){let e=(0,Kn.useRef)(new Map),n=(0,Kn.useRef)(null),[r,a]=(0,Kn.useState)(new Set),s=(0,Kn.useRef)(0),i=(0,Kn.useRef)([]),o=(0,Kn.useRef)(new Map),l=(0,Kn.useRef)(0),u=(0,Kn.useRef)(new Map),c=(0,Kn.useCallback)((p,g)=>{let m=e.current.get(p);m!==g&&(m&&n.current?.unobserve(m),g?(g.dataset.diffCardKey=p,e.current.set(p,g),n.current?.observe(g)):e.current.delete(p))},[]);(0,Kn.useEffect)(()=>{if(a(new Set),!t||typeof IntersectionObserver>"u")return;let p=new IntersectionObserver(g=>{a(m=>{let x=new Set(m);for(let b of g){let y=b.target.dataset.diffCardKey;y&&(b.isIntersecting?x.add(y):x.delete(y))}return x.size===m.size&&[...x].every(b=>m.has(b))?m:x})},{root:t,rootMargin:JA});n.current=p;for(let g of e.current.values())p.observe(g);return()=>{p.disconnect(),n.current=null}},[t]);let d=(0,Kn.useCallback)((p,g,m,x)=>{let b=o.current,y=b.get(p);if(y&&(b.delete(p),l.current-=y.bytes),!(m>_v)){b.set(p,{value:g,bytes:m}),l.current+=m,x&&(u.current.delete(x),u.current.set(x,p)),u.current.size>Bv&&u.current.delete(u.current.keys().next().value);for(let[C,I]of b){if(b.size<=Bv&&l.current<=_v)break;b.delete(C),l.current-=I.bytes}}},[]),f=(0,Kn.useCallback)((p,g,m)=>{if(m&&!m.fresh){let x=o.current.get(m.key);if(x)return o.current.delete(m.key),o.current.set(m.key,x),Promise.resolve(x.value)}return new Promise((x,b)=>{let y=()=>{s.current+=1;let C=()=>{s.current-=1,i.current.shift()?.()};if(!g()){C(),x(void 0);return}p().then(I=>{m&&d(m.key,I,m.bytes(I),m.family),C(),x(I)},I=>{C(),b(I)})};s.current<YA?y():i.current.push(y)})},[d]),h=(0,Kn.useCallback)((p,g)=>(o.current.get(p)??(g?o.current.get(u.current.get(g)??""):void 0))?.value,[]);return{register:c,visible:r,run:f,peek:h}}var St=W(Je(),1);var je=W(ue()),Mt=W(Je());function Hv(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(a){return Object.getOwnPropertyDescriptor(t,a).enumerable}))),n.push.apply(n,r)}return n}function Ht(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?Hv(Object(n),!0).forEach((function(r){qh(t,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Hv(Object(n)).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))}))}return t}function qh(t,e,n){return(e=(function(r){var a=(function(s,i){if(typeof s!="object"||s===null)return s;var o=s[Symbol.toPrimitive];if(o!==void 0){var l=o.call(s,i||"default");if(typeof l!="object")return l;throw new TypeError("@@toPrimitive must return a primitive value.")}return(i==="string"?String:Number)(s)})(r,"string");return typeof a=="symbol"?a:String(a)})(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Ys(t,e){if(t==null)return{};var n,r,a=(function(i,o){if(i==null)return{};var l,u,c={},d=Object.keys(i);for(u=0;u<d.length;u++)l=d[u],o.indexOf(l)>=0||(c[l]=i[l]);return c})(t,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(r=0;r<s.length;r++)n=s[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(a[n]=t[n])}return a}function mn(t,e){return pw(t)||(function(n,r){var a=n==null?null:typeof Symbol<"u"&&n[Symbol.iterator]||n["@@iterator"];if(a!=null){var s,i,o,l,u=[],c=!0,d=!1;try{if(o=(a=a.call(n)).next,r===0){if(Object(a)!==a)return;c=!1}else for(;!(c=(s=o.call(a)).done)&&(u.push(s.value),u.length!==r);c=!0);}catch(f){d=!0,i=f}finally{try{if(!c&&a.return!=null&&(l=a.return(),Object(l)!==l))return}finally{if(d)throw i}}return u}})(t,e)||Yc(t,e)||gw()}function ZA(t){return pw(t)||mw(t)||Yc(t)||gw()}function Hr(t){return(function(e){if(Array.isArray(e))return Vh(e)})(t)||mw(t)||Yc(t)||(function(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
5
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)})()}function pw(t){if(Array.isArray(t))return t}function mw(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function Yc(t,e){if(t){if(typeof t=="string")return Vh(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set"?Array.from(t):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Vh(t,e):void 0}}function Vh(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function gw(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
6
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ep(t,e){var n=typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=Yc(t))||e&&t&&typeof t.length=="number"){n&&(t=n);var r=0,a=function(){};return{s:a,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(l){throw l},f:a}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
7
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s,i=!0,o=!1;return{s:function(){n=n.call(t)},n:function(){var l=n.next();return i=l.done,l},e:function(l){o=!0,s=l},f:function(){try{i||n.return==null||n.return()}finally{if(o)throw s}}}}var Uc=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function gu(t,e){return t(e={exports:{}},e.exports),e.exports}var Fn=gu((function(t){(function(){var e={}.hasOwnProperty;function n(){for(var r=[],a=0;a<arguments.length;a++){var s=arguments[a];if(s){var i=typeof s;if(i==="string"||i==="number")r.push(s);else if(Array.isArray(s)){if(s.length){var o=n.apply(null,s);o&&r.push(o)}}else if(i==="object"){if(s.toString!==Object.prototype.toString&&!s.toString.toString().includes("[native code]")){r.push(s.toString());continue}for(var l in s)e.call(s,l)&&s[l]&&r.push(l)}}}return r.join(" ")}t.exports?(n.default=n,t.exports=n):window.classNames=n})()})),Lr={hunkClassName:"",lineClassName:"",gutterClassName:"",codeClassName:"",monotonous:!1,gutterType:"default",viewType:"split",widgets:{},hideGutter:!1,selectedChanges:[],generateAnchorID:function(){},generateLineClassName:function(){},renderGutter:function(t){var e=t.renderDefault;return(0,t.wrapInAnchor)(e())},codeEvents:{},gutterEvents:{}},xw=(0,Mt.createContext)(Lr),QA=xw.Provider,bw=function(){return(0,Mt.useContext)(xw)},eP=gu((function(t,e){(function(n){function r(s){var i=s.slice(11),o=null,l=null;switch(i.indexOf('"')){case-1:o=(d=i.split(" "))[0].slice(2),l=d[1].slice(2);break;case 0:var u=i.indexOf('"',2);o=i.slice(3,u);var c=i.indexOf('"',u+1);l=c<0?i.slice(u+4):i.slice(c+3,-1);break;default:var d;o=(d=i.split(" "))[0].slice(2),l=d[1].slice(3,-1)}return{oldPath:o,newPath:l}}var a={parse:function(s){for(var i,o,l,u,c,d=[],f=2,h=s.split(`
|
|
8
|
+
`),p=h.length,g=0;g<p;){var m=h[g];if(m.indexOf("diff --git")===0){i={hunks:[],oldEndingNewLine:!0,newEndingNewLine:!0,oldPath:(c=r(m)).oldPath,newPath:c.newPath},d.push(i);var x,b=null;e:for(;x=h[++g];){var y=x.indexOf(" "),C=y>-1?x.slice(0,y):C;switch(C){case"diff":g--;break e;case"deleted":case"new":var I=x.slice(y+1);I.indexOf("file mode")===0&&(i[C==="new"?"newMode":"oldMode"]=I.slice(10));break;case"similarity":i.similarity=parseInt(x.split(" ")[2],10);break;case"index":var L=x.slice(y+1).split(" "),v=L[0].split("..");i.oldRevision=v[0],i.newRevision=v[1],L[1]&&(i.oldMode=i.newMode=L[1]);break;case"copy":case"rename":var k=x.slice(y+1);k.indexOf("from")===0?i.oldPath=k.slice(5):i.newPath=k.slice(3),b=C;break;case"---":var O=x.slice(y+1),R=h[++g].slice(4);O==="/dev/null"?(R=R.slice(2),b="add"):R==="/dev/null"?(O=O.slice(2),b="delete"):(b="modify",O=O.slice(2),R=R.slice(2)),O&&(i.oldPath=O),R&&(i.newPath=R),f=5;break e}}i.type=b||"modify"}else if(m.indexOf("Binary")===0)i.isBinary=!0,i.type=m.indexOf("/dev/null and")>=0?"add":m.indexOf("and /dev/null")>=0?"delete":"modify",f=2,i=null;else if(f===5)if(m.indexOf("@@")===0){var P=/^@@\s+-([0-9]+)(,([0-9]+))?\s+\+([0-9]+)(,([0-9]+))?/.exec(m);o={content:m,oldStart:P[1]-0,newStart:P[4]-0,oldLines:P[3]-0||1,newLines:P[6]-0||1,changes:[]},i.hunks.push(o),l=o.oldStart,u=o.newStart}else{var H=m.slice(0,1),w={content:m.slice(1)};switch(H){case"+":w.type="insert",w.isInsert=!0,w.lineNumber=u,u++;break;case"-":w.type="delete",w.isDelete=!0,w.lineNumber=l,l++;break;case" ":w.type="normal",w.isNormal=!0,w.oldLineNumber=l,w.newLineNumber=u,l++,u++;break;case"\\":var N=o.changes[o.changes.length-1];N.isDelete||(i.newEndingNewLine=!1),N.isInsert||(i.oldEndingNewLine=!1)}w.type&&o.changes.push(w)}g++}return d}};t.exports=a})()}));function Zs(t){return t.type==="insert"}function ba(t){return t.type==="delete"}function Ua(t){return t.type==="normal"}function tP(t,e){var n=e.nearbySequences==="zip"?(function(r){var a=r.reduce((function(s,i,o){var l=mn(s,3),u=l[0],c=l[1],d=l[2];return c?Zs(i)&&d>=0?(u.splice(d+1,0,i),[u,i,d+2]):(u.push(i),[u,i,ba(i)&&ba(c)?d:o]):(u.push(i),[u,i,ba(i)?o:-1])}),[[],null,-1]);return mn(a,1)[0]})(t.changes):t.changes;return Ht(Ht({},t),{},{isPlain:!1,changes:n})}function yw(t){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=(function(r){if(r.startsWith("diff --git"))return r;var a=r.indexOf(`
|
|
9
9
|
`),s=r.indexOf(`
|
|
10
10
|
`,a+1),i=r.slice(0,a),o=r.slice(a+1,s),l=i.split(" ").slice(1,-3).join(" "),u=o.split(" ").slice(1,-3).join(" ");return["diff --git a/".concat(l," b/").concat(u),"index 1111111..2222222 100644","--- a/".concat(l),"+++ b/".concat(u),r.slice(s+1)].join(`
|
|
11
|
-
`)})(t.trimStart());return eP.parse(n).map((function(r){return(function(a,s){var i=a.hunks.map((function(o){return tP(o,s)}));return Rt(Rt({},a),{},{hunks:i})})(r,e)}))}function dv(t){return t[0]}function fv(t){return t[t.length-1]}function Oh(t){return["".concat(t,"Start"),"".concat(t,"Lines")]}function Bs(t){return t==="old"?function(e){return _s(e)?-1:Pa(e)?e.oldLineNumber:e.lineNumber}:function(e){return aa(e)?-1:Pa(e)?e.newLineNumber:e.lineNumber}}function jh(t,e){return function(n,r){var a=n[t],s=a+n[e];return r>=a&&r<s}}function hv(t,e){return function(n,r,a){var s=n[t]+n[e],i=r[t];return a>=s&&a<i}}function pv(t){var e=Bs(t),n=(function(r){var a=en(Oh(r),2),s=jh(a[0],a[1]);return function(i,o){return i.find((function(l){return s(l,o)}))}})(t);return function(r,a){var s=n(r,a);if(s)return s.changes.find((function(i){return e(i)===a}))}}function Vh(t){var e=t==="old"?"new":"old",n=en(Oh(t),2),r=n[0],a=n[1],s=en(Oh(e),2),i=s[0],o=s[1],l=Bs(t),u=Bs(e),c=jh(r,a),d=hv(r,a);return function(f,h){var p=dv(f);if(h<p[r]){var g=p[r]-h;return p[i]-g}var m=fv(f);if(m[r]+m[a]<=h){var x=h-m[r]-m[a];return m[i]+m[o]+x}for(var y=0;y<f.length;y++){var b=f[y],C=f[y+1];if(c(b,h)){var L=b.changes.findIndex((function(R){return l(R)===h})),P=b.changes[L];if(Pa(P))return u(P);var w=aa(P)?L+1:L-1,k=b.changes[w];if(!k)return-1;var _=_s(P)?"delete":"insert";return k.type===_?u(k):-1}if(d(b,C,h)){var M=h-b[r]-b[a];return b[i]+b[o]+M}}throw new Error("Unexpected line position ".concat(h))}}var nP=function(t,e,n,r){for(var a=t.length,s=n+(r?1:-1);r?s--:++s<a;)if(e(t[s],s,t))return s;return-1},rP=function(){this.__data__=[],this.size=0},mv=function(t,e){return t===e||t!=t&&e!=e},Uc=function(t,e){for(var n=t.length;n--;)if(mv(t[n][0],e))return n;return-1},aP=Array.prototype.splice,sP=function(t){var e=this.__data__,n=Uc(e,t);return!(n<0)&&(n==e.length-1?e.pop():aP.call(e,n,1),--this.size,!0)},iP=function(t){var e=this.__data__,n=Uc(e,t);return n<0?void 0:e[n][1]},oP=function(t){return Uc(this.__data__,t)>-1},lP=function(t,e){var n=this.__data__,r=Uc(n,t);return r<0?(++this.size,n.push([t,e])):n[r][1]=e,this};function go(t){var e=-1,n=t==null?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}go.prototype.clear=rP,go.prototype.delete=sP,go.prototype.get=iP,go.prototype.has=oP,go.prototype.set=lP;var Gc=go,uP=function(){this.__data__=new Gc,this.size=0},cP=function(t){var e=this.__data__,n=e.delete(t);return this.size=e.size,n},dP=function(t){return this.__data__.get(t)},fP=function(t){return this.__data__.has(t)},gv=typeof Nc=="object"&&Nc&&Nc.Object===Object&&Nc,hP=typeof self=="object"&&self&&self.Object===Object&&self,ts=gv||hP||Function("return this")(),Na=ts.Symbol,xv=Object.prototype,pP=xv.hasOwnProperty,mP=xv.toString,Yl=Na?Na.toStringTag:void 0,gP=function(t){var e=pP.call(t,Yl),n=t[Yl];try{t[Yl]=void 0;var r=!0}catch{}var a=mP.call(t);return r&&(e?t[Yl]=n:delete t[Yl]),a},xP=Object.prototype.toString,yP=function(t){return xP.call(t)},Mw=Na?Na.toStringTag:void 0,vo=function(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Mw&&Mw in Object(t)?gP(t):yP(t)},Zl=function(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")},yv=function(t){if(!Zl(t))return!1;var e=vo(t);return e=="[object Function]"||e=="[object GeneratorFunction]"||e=="[object AsyncFunction]"||e=="[object Proxy]"},Rh=ts["__core-js_shared__"],Tw=(function(){var t=/[^.]+$/.exec(Rh&&Rh.keys&&Rh.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""})(),bP=function(t){return!!Tw&&Tw in t},wP=Function.prototype.toString,mi=function(t){if(t!=null){try{return wP.call(t)}catch{}try{return t+""}catch{}}return""},vP=/^\[object .+?Constructor\]$/,kP=Function.prototype,SP=Object.prototype,CP=kP.toString,IP=SP.hasOwnProperty,LP=RegExp("^"+CP.call(IP).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),AP=function(t){return!(!Zl(t)||bP(t))&&(yv(t)?LP:vP).test(mi(t))},PP=function(t,e){return t?.[e]},gi=function(t,e){var n=PP(t,e);return AP(n)?n:void 0},Ql=gi(ts,"Map"),eu=gi(Object,"create"),NP=function(){this.__data__=eu?eu(null):{},this.size=0},RP=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},MP=Object.prototype.hasOwnProperty,TP=function(t){var e=this.__data__;if(eu){var n=e[t];return n==="__lodash_hash_undefined__"?void 0:n}return MP.call(e,t)?e[t]:void 0},DP=Object.prototype.hasOwnProperty,FP=function(t){var e=this.__data__;return eu?e[t]!==void 0:DP.call(e,t)},EP=function(t,e){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=eu&&e===void 0?"__lodash_hash_undefined__":e,this};function xo(t){var e=-1,n=t==null?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}xo.prototype.clear=NP,xo.prototype.delete=RP,xo.prototype.get=TP,xo.prototype.has=FP,xo.prototype.set=EP;var Dw=xo,OP=function(){this.size=0,this.__data__={hash:new Dw,map:new(Ql||Gc),string:new Dw}},BP=function(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null},Wc=function(t,e){var n=t.__data__;return BP(e)?n[typeof e=="string"?"string":"hash"]:n.map},_P=function(t){var e=Wc(this,t).delete(t);return this.size-=e?1:0,e},HP=function(t){return Wc(this,t).get(t)},UP=function(t){return Wc(this,t).has(t)},GP=function(t,e){var n=Wc(this,t),r=n.size;return n.set(t,e),this.size+=n.size==r?0:1,this};function yo(t){var e=-1,n=t==null?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}yo.prototype.clear=OP,yo.prototype.delete=_P,yo.prototype.get=HP,yo.prototype.has=UP,yo.prototype.set=GP;var zc=yo,WP=function(t,e){var n=this.__data__;if(n instanceof Gc){var r=n.__data__;if(!Ql||r.length<199)return r.push([t,e]),this.size=++n.size,this;n=this.__data__=new zc(r)}return n.set(t,e),this.size=n.size,this};function bo(t){var e=this.__data__=new Gc(t);this.size=e.size}bo.prototype.clear=uP,bo.prototype.delete=cP,bo.prototype.get=dP,bo.prototype.has=fP,bo.prototype.set=WP;var Ec=bo,zP=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},jP=function(t){return this.__data__.has(t)};function Oc(t){var e=-1,n=t==null?0:t.length;for(this.__data__=new zc;++e<n;)this.add(t[e])}Oc.prototype.add=Oc.prototype.push=zP,Oc.prototype.has=jP;var VP=Oc,qP=function(t,e){for(var n=-1,r=t==null?0:t.length;++n<r;)if(e(t[n],n,t))return!0;return!1},$P=function(t,e){return t.has(e)},bv=function(t,e,n,r,a,s){var i=1&n,o=t.length,l=e.length;if(o!=l&&!(i&&l>o))return!1;var u=s.get(t),c=s.get(e);if(u&&c)return u==e&&c==t;var d=-1,f=!0,h=2&n?new VP:void 0;for(s.set(t,e),s.set(e,t);++d<o;){var p=t[d],g=e[d];if(r)var m=i?r(g,p,d,e,t,s):r(p,g,d,t,e,s);if(m!==void 0){if(m)continue;f=!1;break}if(h){if(!qP(e,(function(x,y){if(!$P(h,y)&&(p===x||a(p,x,n,r,s)))return h.push(y)}))){f=!1;break}}else if(p!==g&&!a(p,g,n,r,s)){f=!1;break}}return s.delete(t),s.delete(e),f},Fw=ts.Uint8Array,KP=function(t){var e=-1,n=Array(t.size);return t.forEach((function(r,a){n[++e]=[a,r]})),n},XP=function(t){var e=-1,n=Array(t.size);return t.forEach((function(r){n[++e]=r})),n},Ew=Na?Na.prototype:void 0,Mh=Ew?Ew.valueOf:void 0,YP=function(t,e,n,r,a,s,i){switch(n){case"[object DataView]":if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=e.byteLength||!s(new Fw(t),new Fw(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return mv(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var o=KP;case"[object Set]":var l=1&r;if(o||(o=XP),t.size!=e.size&&!l)return!1;var u=i.get(t);if(u)return u==e;r|=2,i.set(t,e);var c=bv(o(t),o(e),r,a,s,i);return i.delete(t),c;case"[object Symbol]":if(Mh)return Mh.call(t)==Mh.call(e)}return!1},wv=function(t,e){for(var n=-1,r=e.length,a=t.length;++n<r;)t[a+n]=e[n];return t},Fr=Array.isArray,JP=function(t,e,n){var r=e(t);return Fr(t)?r:wv(r,n(t))},ZP=function(t,e){for(var n=-1,r=t==null?0:t.length,a=0,s=[];++n<r;){var i=t[n];e(i,n,t)&&(s[a++]=i)}return s},QP=function(){return[]},eN=Object.prototype.propertyIsEnumerable,Ow=Object.getOwnPropertySymbols,tN=Ow?function(t){return t==null?[]:(t=Object(t),ZP(Ow(t),(function(e){return eN.call(t,e)})))}:QP,nN=function(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r},wo=function(t){return t!=null&&typeof t=="object"},Bw=function(t){return wo(t)&&vo(t)=="[object Arguments]"},vv=Object.prototype,rN=vv.hasOwnProperty,aN=vv.propertyIsEnumerable,qh=Bw((function(){return arguments})())?Bw:function(t){return wo(t)&&rN.call(t,"callee")&&!aN.call(t,"callee")},sN=function(){return!1},Bh=nu((function(t,e){var n=e&&!e.nodeType&&e,r=n&&t&&!t.nodeType&&t,a=r&&r.exports===n?ts.Buffer:void 0,s=(a?a.isBuffer:void 0)||sN;t.exports=s})),iN=/^(?:0|[1-9]\d*)$/,kv=function(t,e){var n=typeof t;return!!(e=e??9007199254740991)&&(n=="number"||n!="symbol"&&iN.test(t))&&t>-1&&t%1==0&&t<e},$h=function(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=9007199254740991},$t={};$t["[object Float32Array]"]=$t["[object Float64Array]"]=$t["[object Int8Array]"]=$t["[object Int16Array]"]=$t["[object Int32Array]"]=$t["[object Uint8Array]"]=$t["[object Uint8ClampedArray]"]=$t["[object Uint16Array]"]=$t["[object Uint32Array]"]=!0,$t["[object Arguments]"]=$t["[object Array]"]=$t["[object ArrayBuffer]"]=$t["[object Boolean]"]=$t["[object DataView]"]=$t["[object Date]"]=$t["[object Error]"]=$t["[object Function]"]=$t["[object Map]"]=$t["[object Number]"]=$t["[object Object]"]=$t["[object RegExp]"]=$t["[object Set]"]=$t["[object String]"]=$t["[object WeakMap]"]=!1;var oN=function(t){return wo(t)&&$h(t.length)&&!!$t[vo(t)]},lN=function(t){return function(e){return t(e)}},_w=nu((function(t,e){var n=e&&!e.nodeType&&e,r=n&&t&&!t.nodeType&&t,a=r&&r.exports===n&&gv.process,s=(function(){try{var i=r&&r.require&&r.require("util").types;return i||a&&a.binding&&a.binding("util")}catch{}})();t.exports=s})),Hw=_w&&_w.isTypedArray,Sv=Hw?lN(Hw):oN,uN=Object.prototype.hasOwnProperty,cN=function(t,e){var n=Fr(t),r=!n&&qh(t),a=!n&&!r&&Bh(t),s=!n&&!r&&!a&&Sv(t),i=n||r||a||s,o=i?nN(t.length,String):[],l=o.length;for(var u in t)!e&&!uN.call(t,u)||i&&(u=="length"||a&&(u=="offset"||u=="parent")||s&&(u=="buffer"||u=="byteLength"||u=="byteOffset")||kv(u,l))||o.push(u);return o},dN=Object.prototype,fN=function(t){var e=t&&t.constructor;return t===(typeof e=="function"&&e.prototype||dN)},hN=(function(t,e){return function(n){return t(e(n))}})(Object.keys,Object),pN=Object.prototype.hasOwnProperty,mN=function(t){if(!fN(t))return hN(t);var e=[];for(var n in Object(t))pN.call(t,n)&&n!="constructor"&&e.push(n);return e},Kh=function(t){return t!=null&&$h(t.length)&&!yv(t)},Xh=function(t){return Kh(t)?cN(t):mN(t)},Uw=function(t){return JP(t,Xh,tN)},gN=Object.prototype.hasOwnProperty,xN=function(t,e,n,r,a,s){var i=1&n,o=Uw(t),l=o.length;if(l!=Uw(e).length&&!i)return!1;for(var u=l;u--;){var c=o[u];if(!(i?c in e:gN.call(e,c)))return!1}var d=s.get(t),f=s.get(e);if(d&&f)return d==e&&f==t;var h=!0;s.set(t,e),s.set(e,t);for(var p=i;++u<l;){var g=t[c=o[u]],m=e[c];if(r)var x=i?r(m,g,c,e,t,s):r(g,m,c,t,e,s);if(!(x===void 0?g===m||a(g,m,n,r,s):x)){h=!1;break}p||(p=c=="constructor")}if(h&&!p){var y=t.constructor,b=e.constructor;y==b||!("constructor"in t)||!("constructor"in e)||typeof y=="function"&&y instanceof y&&typeof b=="function"&&b instanceof b||(h=!1)}return s.delete(t),s.delete(e),h},_h=gi(ts,"DataView"),Hh=gi(ts,"Promise"),Uh=gi(ts,"Set"),Gh=gi(ts,"WeakMap"),yN=mi(_h),bN=mi(Ql),wN=mi(Hh),vN=mi(Uh),kN=mi(Gh),pi=vo;(_h&&pi(new _h(new ArrayBuffer(1)))!="[object DataView]"||Ql&&pi(new Ql)!="[object Map]"||Hh&&pi(Hh.resolve())!="[object Promise]"||Uh&&pi(new Uh)!="[object Set]"||Gh&&pi(new Gh)!="[object WeakMap]")&&(pi=function(t){var e=vo(t),n=e=="[object Object]"?t.constructor:void 0,r=n?mi(n):"";if(r)switch(r){case yN:return"[object DataView]";case bN:return"[object Map]";case wN:return"[object Promise]";case vN:return"[object Set]";case kN:return"[object WeakMap]"}return e});var Gw=pi,Rc="[object Object]",Ww=Object.prototype.hasOwnProperty,SN=function(t,e,n,r,a,s){var i=Fr(t),o=Fr(e),l=i?"[object Array]":Gw(t),u=o?"[object Array]":Gw(e),c=(l=l=="[object Arguments]"?Rc:l)==Rc,d=(u=u=="[object Arguments]"?Rc:u)==Rc,f=l==u;if(f&&Bh(t)){if(!Bh(e))return!1;i=!0,c=!1}if(f&&!c)return s||(s=new Ec),i||Sv(t)?bv(t,e,n,r,a,s):YP(t,e,l,n,r,a,s);if(!(1&n)){var h=c&&Ww.call(t,"__wrapped__"),p=d&&Ww.call(e,"__wrapped__");if(h||p){var g=h?t.value():t,m=p?e.value():e;return s||(s=new Ec),a(g,m,n,r,s)}}return!!f&&(s||(s=new Ec),xN(t,e,n,r,a,s))},jc=function t(e,n,r,a,s){return e===n||(e==null||n==null||!wo(e)&&!wo(n)?e!=e&&n!=n:SN(e,n,r,a,t,s))},CN=function(t,e,n,r){var a=n.length,s=a,i=!r;if(t==null)return!s;for(t=Object(t);a--;){var o=n[a];if(i&&o[2]?o[1]!==t[o[0]]:!(o[0]in t))return!1}for(;++a<s;){var l=(o=n[a])[0],u=t[l],c=o[1];if(i&&o[2]){if(u===void 0&&!(l in t))return!1}else{var d=new Ec;if(r)var f=r(u,c,l,t,e,d);if(!(f===void 0?jc(c,u,3,r,d):f))return!1}}return!0},Cv=function(t){return t==t&&!Zl(t)},IN=function(t){for(var e=Xh(t),n=e.length;n--;){var r=e[n],a=t[r];e[n]=[r,a,Cv(a)]}return e},Iv=function(t,e){return function(n){return n!=null&&n[t]===e&&(e!==void 0||t in Object(n))}},LN=function(t){var e=IN(t);return e.length==1&&e[0][2]?Iv(e[0][0],e[0][1]):function(n){return n===t||CN(n,t,e)}},Vc=function(t){return typeof t=="symbol"||wo(t)&&vo(t)=="[object Symbol]"},AN=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,PN=/^\w*$/,Yh=function(t,e){if(Fr(t))return!1;var n=typeof t;return!(n!="number"&&n!="symbol"&&n!="boolean"&&t!=null&&!Vc(t))||PN.test(t)||!AN.test(t)||e!=null&&t in Object(e)};function Jh(t,e){if(typeof t!="function"||e!=null&&typeof e!="function")throw new TypeError("Expected a function");var n=function(){var r=arguments,a=e?e.apply(this,r):r[0],s=n.cache;if(s.has(a))return s.get(a);var i=t.apply(this,r);return n.cache=s.set(a,i)||s,i};return n.cache=new(Jh.Cache||zc),n}Jh.Cache=zc;var NN=Jh,RN=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,MN=/\\(\\)?/g,TN=(function(t){var e=NN(t,(function(r){return n.size===500&&n.clear(),r})),n=e.cache;return e})((function(t){var e=[];return t.charCodeAt(0)===46&&e.push(""),t.replace(RN,(function(n,r,a,s){e.push(a?s.replace(MN,"$1"):r||n)})),e})),Lv=function(t,e){for(var n=-1,r=t==null?0:t.length,a=Array(r);++n<r;)a[n]=e(t[n],n,t);return a},zw=Na?Na.prototype:void 0,jw=zw?zw.toString:void 0,DN=function t(e){if(typeof e=="string")return e;if(Fr(e))return Lv(e,t)+"";if(Vc(e))return jw?jw.call(e):"";var n=e+"";return n=="0"&&1/e==-1/0?"-0":n},FN=function(t){return t==null?"":DN(t)},Av=function(t,e){return Fr(t)?t:Yh(t,e)?[t]:TN(FN(t))},qc=function(t){if(typeof t=="string"||Vc(t))return t;var e=t+"";return e=="0"&&1/t==-1/0?"-0":e},Pv=function(t,e){for(var n=0,r=(e=Av(e,t)).length;t!=null&&n<r;)t=t[qc(e[n++])];return n&&n==r?t:void 0},EN=function(t,e,n){var r=t==null?void 0:Pv(t,e);return r===void 0?n:r},ON=function(t,e){return t!=null&&e in Object(t)},BN=function(t,e,n){for(var r=-1,a=(e=Av(e,t)).length,s=!1;++r<a;){var i=qc(e[r]);if(!(s=t!=null&&n(t,i)))break;t=t[i]}return s||++r!=a?s:!!(a=t==null?0:t.length)&&$h(a)&&kv(i,a)&&(Fr(t)||qh(t))},_N=function(t,e){return t!=null&&BN(t,e,ON)},HN=function(t,e){return Yh(t)&&Cv(e)?Iv(qc(t),e):function(n){var r=EN(n,t);return r===void 0&&r===e?_N(n,t):jc(e,r,3)}},UN=function(t){return t},GN=function(t){return function(e){return e?.[t]}},WN=function(t){return function(e){return Pv(e,t)}},zN=function(t){return Yh(t)?GN(qc(t)):WN(t)},$c=function(t){return typeof t=="function"?t:t==null?UN:typeof t=="object"?Fr(t)?HN(t[0],t[1]):LN(t):zN(t)},jN=/\s/,VN=function(t){for(var e=t.length;e--&&jN.test(t.charAt(e)););return e},qN=/^\s+/,$N=function(t){return t&&t.slice(0,VN(t)+1).replace(qN,"")},KN=/^[-+]0x[0-9a-f]+$/i,XN=/^0b[01]+$/i,YN=/^0o[0-7]+$/i,JN=parseInt,ZN=function(t){if(typeof t=="number")return t;if(Vc(t))return NaN;if(Zl(t)){var e=typeof t.valueOf=="function"?t.valueOf():t;t=Zl(e)?e+"":e}if(typeof t!="string")return t===0?t:+t;t=$N(t);var n=XN.test(t);return n||YN.test(t)?JN(t.slice(2),n?2:8):KN.test(t)?NaN:+t},QN=function(t){return t?(t=ZN(t))===1/0||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:t===0?t:0},eR=function(t){var e=QN(t),n=e%1;return e==e?n?e-n:e:0},tR=Math.max,nR=Math.min,Vw=function(t,e,n){var r=t==null?0:t.length;if(!r)return-1;var a=r-1;return n!==void 0&&(a=eR(n),a=n<0?tR(r+a,0):nR(a,r-1)),nP(t,$c(e),a,!0)},tu=Bs("old"),rR=Bs("new");function qw(t){var e=t.oldStart;return[e,e+t.oldLines-1]}function Bc(t){if(!t.length)return null;var e=t.reduce((function(i,o){return Pa(o)||(i.isPlain=!1),_s(o)||(i.oldLines=i.oldLines+1,i.oldStart===-1&&(i.oldStart=tu(o))),aa(o)||(i.newLines=i.newLines+1,i.newStart===-1&&(i.newStart=rR(o))),i}),{isPlain:!0,content:"",oldStart:-1,oldLines:0,newStart:-1,newLines:0}),n=e.oldStart,r=e.oldLines,a=e.newStart,s=e.newLines;return Rt(Rt({},e),{},{content:"@@ -".concat(n,",").concat(r," +").concat(a,",").concat(s),changes:t})}function aR(t,e,n){return Bc(t.map((function(r,a){return{type:"normal",isNormal:!0,oldLineNumber:e+a,newLineNumber:n+a,content:""+r}})))}function Mc(t,e,n){var r=t.changes,a=r.findIndex((function(o){return tu(o)>=e}));if(a===-1)return null;var s=(function(){if(a===0)return a;var o=Vw(r,(function(l){return!_s(l)}),a-1);return o===-1?a:o+1})();if(n===void 0)return Bc(r.slice(s));var i=Vw(r,(function(o){return tu(o)<=n}));return Bc(r.slice(s,i===-1?void 0:i))}function Jl(t,e){if(!t)return e;if(!e)return t;var n=en(qw(t),2),r=n[0],a=n[1],s=en(qw(e),2),i=s[0],o=s[1];if(a+1===i)return Bc([].concat(kr(t.changes),kr(e.changes)));if(r<=i&&a>=o){if(t.isPlain&&!e.isPlain){var l=Mc(t,r,i),u=Mc(t,o+1);return Jl(Jl(l,e),u)}return t}return t.isPlain?Jl(Mc(t,r,i),e):Jl(t,Mc(e,a+1))}function sR(t,e){var n=fv(t);if(!n)return[e];if(n.oldStart+n.oldLines<e.oldStart)return t.concat(e);var r=Jl(n,e);return r?[].concat(kr(t.slice(0,-1)),[r]):t}function iR(t,e){var n=tu(e.changes[0]),r=t.findIndex((function(a){var s=a.changes;return!!s.length&&tu(s[0])>=n}));return(r===-1?t.concat(e):[].concat(kr(t.slice(0,r)),[e],kr(t.slice(r)))).reduce(sR,[])}function Es(t){if(!t)throw new Error("change is not provided");if(Pa(t))return"N".concat(t.oldLineNumber);var e=_s(t)?"I":"D";return"".concat(e).concat(t.lineNumber)}var oR=Vh("old"),Th=Bs("old"),$w=jh("oldStart","oldLines"),lR=hv("oldStart","oldLines");function Wh(t,e,n){var r=(function(h,p){if(!h.length)return-1;var g=dv(h);if(p<g.oldStart||$w(g,p))return 0;for(var m=1;m<h.length;m++){var x=h[m];if($w(x,p))return m;var y=h[m-1];if(lR(y,x,p))return m}return-1})(t,e);if(r===-1)return[[e,n]];var a=t[r];if(e<a.oldStart){var s=a.changes.findIndex((function(h){return!Pa(h)})),i=a.oldStart+Math.max(s,0);return i>=n?[[e,n]]:[[e,i]].concat(kr(Wh(t,i+1,n)))}var o=a.changes,l=(function(h,p){var g=h.changes,m=g.findIndex((function(y){return Th(y)===p}));if(m<0)return-1;for(var x=m;x<g.length;x++)if(Pa(g[x]))return x;return-1})(a,e);if(l===-1)return[];var u=o[l],c=Th(u),d=o.slice(l+1).findIndex((function(h){return!Pa(h)})),f=Th(u)+Math.max(d,0);return f>=n?[[c,n]]:[[c,f]].concat(kr(Wh(t,f+1,n)))}function Nv(t,e,n,r){return Wh(t,n,r).reduce((function(a,s){return(function(i,o,l){var u=en(l,2),c=u[0],d=u[1],f=(typeof o=="string"?o.split(`
|
|
12
|
-
`):o).slice(Math.max(c,1)-1,d-1);if(!f.length)return i;var h=aR(f,c,oR(i,c));return h?iR(i,h):i})(a,e,s)}),t)}function Rv(t,e){if(!t)return e.oldStart-1;var n=t.oldStart+t.oldLines;return e.oldStart-n}var Kc=Bs("old"),Xc=Bs("new"),yW=pv("old"),bW=pv("new"),wW=Vh("new"),vW=Vh("old"),Kw=(function(){try{var t=gi(Object,"defineProperty");return t({},"",{}),t}catch{}})(),Zh=function(t,e,n){e=="__proto__"&&Kw?Kw(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n},uR=function(t){return function(e,n,r){for(var a=-1,s=Object(e),i=r(e),o=i.length;o--;){var l=i[t?o:++a];if(n(s[l],l,s)===!1)break}return e}},cR=uR(),Mv=function(t,e){return t&&cR(t,e,Xh)},Tv=function(t,e){var n={};return e=$c(e),Mv(t,(function(r,a,s){Zh(n,a,e(r,a,s))})),n},dR=["changeKey","text","tokens","renderToken"],Xw=function t(e,n){var r=e.type,a=e.value,s=e.markType,i=e.properties,o=e.className,l=e.children,u=function(d){return(0,Be.jsx)("span",{className:d,children:a||l&&l.map(t)},n)};switch(r){case"text":return a;case"mark":return u("diff-code-mark diff-code-mark-".concat(s));case"edit":return u("diff-code-edit");default:var c=i&&i.className;return u(wn(o||c))}};function fR(t){if(!Array.isArray(t))return!0;if(t.length>1)return!1;if(t.length===1){var e=en(t,1)[0];return e.type==="text"&&!e.value}return!0}function hR(t){var e=t.changeKey,n=t.text,r=t.tokens,a=t.renderToken,s=Os(t,dR),i=a?function(o,l){return a(o,Xw,l)}:Xw;return(0,Be.jsx)("td",Rt(Rt({},s),{},{"data-change-key":e,children:r?fR(r)?" ":r.map(i):n||" "}))}var Dv=(0,St.memo)(hR);function Fv(t,e){return function(){var n=e==="old"?Kc(t):Xc(t);return n===-1?void 0:n}}function Ev(t,e){return function(n){return t&&n?(0,Be.jsx)("a",{href:e?"#"+e:void 0,children:n}):n}}function _c(t,e){return e?function(n){t(),e(n)}:t}function Yw(t,e,n,r){return(0,St.useMemo)((function(){var a=Tv(t,(function(s){return function(i){return s&&s(e,i)}}));return a.onMouseEnter=_c(n,a.onMouseEnter),a.onMouseLeave=_c(r,a.onMouseLeave),a}),[t,n,r,e])}function Jw(t,e,n,r,a,s,i,o,l){var u={change:e,side:r,inHoverState:o,renderDefault:Fv(e,r),wrapInAnchor:Ev(a,s)};return(0,Be.jsx)("td",Rt(Rt({className:t},i),{},{"data-change-key":n,children:l(u)}))}function pR(t){var e,n,r,a=t.change,s=t.selected,i=t.tokens,o=t.className,l=t.generateLineClassName,u=t.gutterClassName,c=t.codeClassName,d=t.gutterEvents,f=t.codeEvents,h=t.hideGutter,p=t.gutterAnchor,g=t.generateAnchorID,m=t.renderToken,x=t.renderGutter,y=a.type,b=a.content,C=Es(a),L=(e=en((0,St.useState)(!1),2),n=e[0],r=e[1],[n,(0,St.useCallback)((function(){return r(!0)}),[]),(0,St.useCallback)((function(){return r(!1)}),[])]),P=en(L,3),w=P[0],k=P[1],_=P[2],M=(0,St.useMemo)((function(){return{change:a}}),[a]),R=Yw(d,M,k,_),U=Yw(f,M,k,_),v=g(a),T=l({changes:[a],defaultGenerate:function(){return o}}),V=wn("diff-gutter","diff-gutter-".concat(y),u,{"diff-gutter-selected":s}),Y=wn("diff-code","diff-code-".concat(y),c,{"diff-code-selected":s});return(0,Be.jsxs)("tr",{id:v,className:wn("diff-line",T),children:[!h&&Jw(V,a,C,"old",p,v,R,w,x),!h&&Jw(V,a,C,"new",p,v,R,w,x),(0,Be.jsx)(Dv,Rt({className:Y,changeKey:C,text:b,tokens:i,renderToken:m},U))]})}var mR=(0,St.memo)(pR);function gR(t){var e=t.hideGutter,n=t.element;return(0,Be.jsx)("tr",{className:"diff-widget",children:(0,Be.jsx)("td",{colSpan:e?1:3,className:"diff-widget-content",children:n})})}var xR=["hideGutter","selectedChanges","tokens","lineClassName"],yR=["hunk","widgets","className"];function bR(t){var e=t.hunk,n=t.widgets,r=t.className,a=Os(t,yR),s=(function(i,o){return i.reduce((function(l,u){var c=Es(u);l.push(["change",c,u]);var d=o[c];return d&&l.push(["widget",c,d]),l}),[])})(e.changes,n);return(0,Be.jsx)("tbody",{className:wn("diff-hunk",r),children:s.map((function(i){return(function(o,l){var u=en(o,3),c=u[0],d=u[1],f=u[2],h=l.hideGutter,p=l.selectedChanges,g=l.tokens,m=l.lineClassName,x=Os(l,xR);if(c==="change"){var y=aa(f)?"old":"new",b=aa(f)?Kc(f):Xc(f),C=g?g[y][b-1]:null;return(0,Be.jsx)(mR,Rt({className:m,change:f,hideGutter:h,selected:p.includes(d),tokens:C},x),"change".concat(d))}return c==="widget"?(0,Be.jsx)(gR,{hideGutter:h,element:f},"widget".concat(d)):null})(i,a)}))})}var Ov=0;function Tc(t,e,n,r){var a=(0,St.useCallback)((function(){return e(t)}),[t,e]),s=(0,St.useCallback)((function(){return e("")}),[e]);return(0,St.useMemo)((function(){var i=Tv(r,(function(o){return function(l){return o&&o({side:t,change:n},l)}}));return i.onMouseEnter=_c(a,i.onMouseEnter),i.onMouseLeave=_c(s,i.onMouseLeave),i}),[n,r,a,t,s])}function Dh(t){var e=t.change,n=t.side,r=t.selected,a=t.tokens,s=t.gutterClassName,i=t.codeClassName,o=t.gutterEvents,l=t.codeEvents,u=t.anchorID,c=t.gutterAnchor,d=t.gutterAnchorTarget,f=t.hideGutter,h=t.hover,p=t.renderToken,g=t.renderGutter;if(!e){var m=wn("diff-gutter","diff-gutter-omit",s),x=wn("diff-code","diff-code-omit",i);return[!f&&(0,Be.jsx)("td",{className:m},"gutter"),(0,Be.jsx)("td",{className:x},"code")]}var y=e.type,b=e.content,C=Es(e),L=n===Ov?"old":"new",P=Rt({id:u||void 0,className:wn("diff-gutter","diff-gutter-".concat(y),Fh({"diff-gutter-selected":r},"diff-line-hover-"+L,h),s),children:g({change:e,side:L,inHoverState:h,renderDefault:Fv(e,L),wrapInAnchor:Ev(c,d)})},o),w=wn("diff-code","diff-code-".concat(y),Fh({"diff-code-selected":r},"diff-line-hover-"+L,h),i);return[!f&&(0,Be.jsx)("td",Rt(Rt({},P),{},{"data-change-key":C}),"gutter"),(0,Be.jsx)(Dv,Rt({className:w,changeKey:C,text:b,tokens:a,renderToken:p},l),"code")]}function wR(t){var e=t.className,n=t.oldChange,r=t.newChange,a=t.oldSelected,s=t.newSelected,i=t.oldTokens,o=t.newTokens,l=t.monotonous,u=t.gutterClassName,c=t.codeClassName,d=t.gutterEvents,f=t.codeEvents,h=t.hideGutter,p=t.generateAnchorID,g=t.generateLineClassName,m=t.gutterAnchor,x=t.renderToken,y=t.renderGutter,b=en((0,St.useState)(""),2),C=b[0],L=b[1],P=Tc("old",L,n,d),w=Tc("new",L,r,d),k=Tc("old",L,n,f),_=Tc("new",L,r,f),M=n&&p(n),R=r&&p(r),U=g({changes:[n,r],defaultGenerate:function(){return e}}),v={monotonous:l,hideGutter:h,gutterClassName:u,codeClassName:c,gutterEvents:d,codeEvents:f,renderToken:x,renderGutter:y},T=Rt(Rt({},v),{},{change:n,side:Ov,selected:a,tokens:i,gutterEvents:P,codeEvents:k,anchorID:M,gutterAnchor:m,gutterAnchorTarget:M,hover:C==="old"}),V=Rt(Rt({},v),{},{change:r,side:1,selected:s,tokens:o,gutterEvents:w,codeEvents:_,anchorID:n===r?null:R,gutterAnchor:m,gutterAnchorTarget:n===r?M:R,hover:C==="new"});if(l)return(0,Be.jsx)("tr",{className:wn("diff-line",U),children:Dh(n?T:V)});var Y=(function(N,A){return N&&!A?"diff-line-old-only":!N&&A?"diff-line-new-only":N===A?"diff-line-normal":"diff-line-compare"})(n,r);return(0,Be.jsxs)("tr",{className:wn("diff-line",Y,U),children:[Dh(T),Dh(V)]})}var vR=(0,St.memo)(wR);function kR(t){var e=t.hideGutter,n=t.oldElement,r=t.newElement;return t.monotonous?(0,Be.jsx)("tr",{className:"diff-widget",children:(0,Be.jsx)("td",{colSpan:e?1:2,className:"diff-widget-content",children:n||r})}):n===r?(0,Be.jsx)("tr",{className:"diff-widget",children:(0,Be.jsx)("td",{colSpan:e?2:4,className:"diff-widget-content",children:n})}):(0,Be.jsxs)("tr",{className:"diff-widget",children:[(0,Be.jsx)("td",{colSpan:e?1:2,className:"diff-widget-content",children:n}),(0,Be.jsx)("td",{colSpan:e?1:2,className:"diff-widget-content",children:r})]})}var SR=["selectedChanges","monotonous","hideGutter","tokens","lineClassName"],CR=["hunk","widgets","className"];function Dc(t,e){return(t?Es(t):"00")+(e?Es(e):"00")}function IR(t){var e=t.hunk,n=t.widgets,r=t.className,a=Os(t,CR),s=(function(i,o){for(var l=function(x){if(!x)return null;var y=Es(x);return o[y]||null},u=[],c=0;c<i.length;c++){var d=i[c];if(Pa(d))u.push(["change",Dc(d,d),d,d]);else if(aa(d)){var f=i[c+1];f&&_s(f)?(c+=1,u.push(["change",Dc(d,f),d,f])):u.push(["change",Dc(d,null),d,null])}else u.push(["change",Dc(null,d),null,d]);var h=u[u.length-1],p=l(h[2]),g=l(h[3]);if(p||g){var m=h[1];u.push(["widget",m,p,g])}}return u})(e.changes,n);return(0,Be.jsx)("tbody",{className:wn("diff-hunk",r),children:s.map((function(i){return(function(o,l){var u=en(o,4),c=u[0],d=u[1],f=u[2],h=u[3],p=l.selectedChanges,g=l.monotonous,m=l.hideGutter,x=l.tokens,y=l.lineClassName,b=Os(l,SR);if(c==="change"){var C=!!f&&p.includes(Es(f)),L=!!h&&p.includes(Es(h)),P=f&&x?x.old[Kc(f)-1]:null,w=h&&x?x.new[Xc(h)-1]:null;return(0,Be.jsx)(vR,Rt({className:y,oldChange:f,newChange:h,monotonous:g,hideGutter:m,oldSelected:C,newSelected:L,oldTokens:P,newTokens:w},b),"change".concat(d))}return c==="widget"?(0,Be.jsx)(kR,{monotonous:g,hideGutter:m,oldElement:f,newElement:h},"widget".concat(d)):null})(i,a)}))})}var LR=["gutterType","hunkClassName"];function Qh(t){var e=t.hunk,n=uv(),r=n.gutterType,a=n.hunkClassName,s=Os(n,LR),i=r==="none",o=r==="anchor",l=s.viewType==="unified"?bR:IR;return(0,Be.jsx)(l,Rt(Rt({},s),{},{hunk:e,hideGutter:i,gutterAnchor:o,className:a}))}function AR(){}function Zw(t,e){var n=e?"auto":"none";t instanceof HTMLElement&&t.style.userSelect!==n&&(t.style.userSelect=n)}function PR(t){return t.map((function(e){return(0,Be.jsx)(Qh,{hunk:e},(function(n){return"-".concat(n.oldStart,",").concat(n.oldLines," +").concat(n.newStart,",").concat(n.newLines)})(e))}))}function NR(t){var e=t.diffType,n=t.hunks,r=t.optimizeSelection,a=t.className,s=t.hunkClassName,i=s===void 0?ur.hunkClassName:s,o=t.lineClassName,l=o===void 0?ur.lineClassName:o,u=t.generateLineClassName,c=u===void 0?ur.generateLineClassName:u,d=t.gutterClassName,f=d===void 0?ur.gutterClassName:d,h=t.codeClassName,p=h===void 0?ur.codeClassName:h,g=t.gutterType,m=g===void 0?ur.gutterType:g,x=t.viewType,y=x===void 0?ur.viewType:x,b=t.gutterEvents,C=b===void 0?ur.gutterEvents:b,L=t.codeEvents,P=L===void 0?ur.codeEvents:L,w=t.generateAnchorID,k=w===void 0?ur.generateAnchorID:w,_=t.selectedChanges,M=_===void 0?ur.selectedChanges:_,R=t.widgets,U=R===void 0?ur.widgets:R,v=t.renderGutter,T=v===void 0?ur.renderGutter:v,V=t.tokens,Y=t.renderToken,N=t.children,A=N===void 0?PR:N,B=(0,St.useRef)(null),K=(0,St.useCallback)((function(re){var he=re.target;if(re.button===0){var Ne=(function(Ye,Lt){for(var Le=Ye;Le&&Le!==document.documentElement&&!Le.classList.contains(Lt);)Le=Le.parentElement;return Le===document.documentElement?null:Le})(he,"diff-code");if(Ne&&Ne.parentElement){var Ee=window.getSelection();Ee&&Ee.removeAllRanges();var ze=kr(Ne.parentElement.children).indexOf(Ne);if(ze===1||ze===3){var ct,it=zh(B.current?B.current.querySelectorAll(".diff-line"):[]);try{for(it.s();!(ct=it.n()).done;){var Qe=ct.value.children;Zw(Qe[1],ze===1),Zw(Qe[3],ze===3)}}catch(Ye){it.e(Ye)}finally{it.f()}}}}}),[]),te=m==="none",ne=e==="add"||e==="delete",pe=y==="split"&&!ne&&r?K:AR,Se=(0,St.useMemo)((function(){return(0,Be.jsxs)("colgroup",y==="unified"?{children:[!te&&(0,Be.jsx)("col",{className:"diff-gutter-col"}),!te&&(0,Be.jsx)("col",{className:"diff-gutter-col"}),(0,Be.jsx)("col",{})]}:ne?{children:[!te&&(0,Be.jsx)("col",{className:"diff-gutter-col"}),(0,Be.jsx)("col",{})]}:{children:[!te&&(0,Be.jsx)("col",{className:"diff-gutter-col"}),(0,Be.jsx)("col",{}),!te&&(0,Be.jsx)("col",{className:"diff-gutter-col"}),(0,Be.jsx)("col",{})]})}),[y,ne,te]),le=(0,St.useMemo)((function(){return{hunkClassName:i,lineClassName:l,generateLineClassName:c,gutterClassName:f,codeClassName:p,monotonous:ne,hideGutter:te,viewType:y,gutterType:m,codeEvents:P,gutterEvents:C,generateAnchorID:k,selectedChanges:M,widgets:U,renderGutter:T,tokens:V,renderToken:Y}}),[p,P,k,f,C,m,te,i,l,c,ne,T,Y,M,V,y,U]);return(0,Be.jsx)(QA,{value:le,children:(0,Be.jsxs)("table",{ref:B,className:wn("diff","diff-".concat(y),a),onMouseDown:pe,children:[Se,A(n)]})})}var Bv=(0,St.memo)(NR),RR=function(){};var Qw=RR;function MR(t){var e=t.hideGutter,n=t.monotonous,r=t.className,a=t.gutterClassName,s=t.contentClassName,i=t.children,o=wn("diff-decoration",r),l=wn("diff-decoration-gutter",a),u=wn("diff-decoration-content",s),c=(e?2:4)/(n?2:1),d=c-(e?0:1);if(St.Children.count(i)===1)return(0,Be.jsx)("tbody",{className:o,children:(0,Be.jsx)("tr",{children:(0,Be.jsx)("td",{colSpan:c,className:u,children:i})})});var f=en(i,2),h=f[0],p=f[1];return(0,Be.jsx)("tbody",{className:o,children:(0,Be.jsxs)("tr",{children:[!e&&(0,Be.jsx)("td",{className:l,children:h}),(0,Be.jsx)("td",{colSpan:d,className:u,children:p})]})})}function TR(t){var e=t.hideGutter,n=t.className,r=t.gutterClassName,a=t.contentClassName,s=t.children,i=wn("diff-decoration",n),o=wn("diff-decoration-gutter",r),l=wn("diff-decoration-content",a);if(St.Children.count(s)===1)return(0,Be.jsx)("tbody",{className:i,children:(0,Be.jsx)("tr",{children:(0,Be.jsx)("td",{colSpan:e?1:3,className:l,children:s})})});var u=en(s,2),c=u[0],d=u[1];return(0,Be.jsx)("tbody",{className:i,children:(0,Be.jsxs)("tr",{children:[!e&&(0,Be.jsx)("td",{colSpan:2,className:o,children:c}),(0,Be.jsx)("td",{className:l,children:d})]})})}function Yc(t){var e=t.className,n=e===void 0?"":e,r=t.gutterClassName,a=r===void 0?"":r,s=t.contentClassName,i=s===void 0?"":s,o=t.children,l=uv(),u=l.viewType,c=l.gutterType,d=l.monotonous,f=u==="split"?MR:TR,h=St.Children.count(o),p=c==="none";return Qw(h<=2,"Decoration only accepts a maxium of 2 children"),Qw(h<2||!p,"Gutter element in decoration will not be rendered since hideGutter prop is set to true"),(0,Be.jsx)(f,{hideGutter:p,monotonous:d,className:n,gutterClassName:a,contentClassName:i,children:o})}var DR=function(t,e,n,r){for(var a=-1,s=t==null?0:t.length;++a<s;){var i=t[a];e(r,i,n(i),t)}return r},FR=function(t,e){return function(n,r){if(n==null)return n;if(!Kh(n))return t(n,r);for(var a=n.length,s=e?a:-1,i=Object(n);(e?s--:++s<a)&&r(i[s],s,i)!==!1;);return n}},_v=FR(Mv),ER=function(t,e,n,r){return _v(t,(function(a,s,i){e(r,a,n(a),i)})),r},Hv=function(t,e){return function(n,r){var a=Fr(n)?DR:ER,s=e?e():{};return a(n,t,$c(r),s)}},OR=Hv((function(t,e,n){Zh(t,n,e)})),ev=Na?Na.isConcatSpreadable:void 0,BR=function(t){return Fr(t)||qh(t)||!!(ev&&t&&t[ev])},_R=function t(e,n,r,a,s){var i=-1,o=e.length;for(r||(r=BR),s||(s=[]);++i<o;){var l=e[i];n>0&&r(l)?n>1?t(l,n-1,r,a,s):wv(s,l):a||(s[s.length]=l)}return s},HR=function(t,e){var n=-1,r=Kh(t)?Array(t.length):[];return _v(t,(function(a,s,i){r[++n]=e(a,s,i)})),r},UR=function(t,e){return(Fr(t)?Lv:HR)(t,$c(e))},GR=function(t,e){return _R(UR(t,e),1)};function WR(t,e){var n=e.newStart,r=e.changes.reduce((function(a,s){var i=en(a,2),o=i[0],l=i[1];return aa(s)?(o.splice(l,1),[o,l]):(_s(s)&&o.splice(l,0,s.content),[o,l+1])}),[t,n-1]);return en(r,1)[0]}function tv(t,e,n){if(!t.length)return[];var r=e==="old"?Kc:Xc,a=OR(t,r),s=r(t[t.length-1]);return Array.from({length:s}).map((function(i,o){return n(a[o+1])}))}function zR(t){var e=(function(i){return GR(i,(function(o){return o.changes})).reduce((function(o,l){var u=en(o,2),c=u[0],d=u[1];return Pa(l)?(c.push(l),d.push(l)):aa(l)?c.push(l):d.push(l),[c,d]}),[[],[]])})(t),n=en(e,2),r=n[0],a=n[1],s=function(i){return i?i.content:""};return[tv(r,"old",s).join(`
|
|
13
|
-
`),
|
|
14
|
-
`)]}function
|
|
11
|
+
`)})(t.trimStart());return eP.parse(n).map((function(r){return(function(a,s){var i=a.hunks.map((function(o){return tP(o,s)}));return Ht(Ht({},a),{},{hunks:i})})(r,e)}))}function vw(t){return t[0]}function ww(t){return t[t.length-1]}function $h(t){return["".concat(t,"Start"),"".concat(t,"Lines")]}function Js(t){return t==="old"?function(e){return Zs(e)?-1:Ua(e)?e.oldLineNumber:e.lineNumber}:function(e){return ba(e)?-1:Ua(e)?e.newLineNumber:e.lineNumber}}function tp(t,e){return function(n,r){var a=n[t],s=a+n[e];return r>=a&&r<s}}function kw(t,e){return function(n,r,a){var s=n[t]+n[e],i=r[t];return a>=s&&a<i}}function Sw(t){var e=Js(t),n=(function(r){var a=mn($h(r),2),s=tp(a[0],a[1]);return function(i,o){return i.find((function(l){return s(l,o)}))}})(t);return function(r,a){var s=n(r,a);if(s)return s.changes.find((function(i){return e(i)===a}))}}function np(t){var e=t==="old"?"new":"old",n=mn($h(t),2),r=n[0],a=n[1],s=mn($h(e),2),i=s[0],o=s[1],l=Js(t),u=Js(e),c=tp(r,a),d=kw(r,a);return function(f,h){var p=vw(f);if(h<p[r]){var g=p[r]-h;return p[i]-g}var m=ww(f);if(m[r]+m[a]<=h){var x=h-m[r]-m[a];return m[i]+m[o]+x}for(var b=0;b<f.length;b++){var y=f[b],C=f[b+1];if(c(y,h)){var I=y.changes.findIndex((function(P){return l(P)===h})),L=y.changes[I];if(Ua(L))return u(L);var v=ba(L)?I+1:I-1,k=y.changes[v];if(!k)return-1;var O=Zs(L)?"delete":"insert";return k.type===O?u(k):-1}if(d(y,C,h)){var R=h-y[r]-y[a];return y[i]+y[o]+R}}throw new Error("Unexpected line position ".concat(h))}}var nP=function(t,e,n,r){for(var a=t.length,s=n+(r?1:-1);r?s--:++s<a;)if(e(t[s],s,t))return s;return-1},rP=function(){this.__data__=[],this.size=0},Cw=function(t,e){return t===e||t!=t&&e!=e},Jc=function(t,e){for(var n=t.length;n--;)if(Cw(t[n][0],e))return n;return-1},aP=Array.prototype.splice,sP=function(t){var e=this.__data__,n=Jc(e,t);return!(n<0)&&(n==e.length-1?e.pop():aP.call(e,n,1),--this.size,!0)},iP=function(t){var e=this.__data__,n=Jc(e,t);return n<0?void 0:e[n][1]},oP=function(t){return Jc(this.__data__,t)>-1},lP=function(t,e){var n=this.__data__,r=Jc(n,t);return r<0?(++this.size,n.push([t,e])):n[r][1]=e,this};function Mo(t){var e=-1,n=t==null?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}Mo.prototype.clear=rP,Mo.prototype.delete=sP,Mo.prototype.get=iP,Mo.prototype.has=oP,Mo.prototype.set=lP;var Zc=Mo,uP=function(){this.__data__=new Zc,this.size=0},cP=function(t){var e=this.__data__,n=e.delete(t);return this.size=e.size,n},dP=function(t){return this.__data__.get(t)},fP=function(t){return this.__data__.has(t)},Iw=typeof Uc=="object"&&Uc&&Uc.Object===Object&&Uc,hP=typeof self=="object"&&self&&self.Object===Object&&self,ps=Iw||hP||Function("return this")(),Ga=ps.Symbol,Lw=Object.prototype,pP=Lw.hasOwnProperty,mP=Lw.toString,cu=Ga?Ga.toStringTag:void 0,gP=function(t){var e=pP.call(t,cu),n=t[cu];try{t[cu]=void 0;var r=!0}catch{}var a=mP.call(t);return r&&(e?t[cu]=n:delete t[cu]),a},xP=Object.prototype.toString,bP=function(t){return xP.call(t)},Uv=Ga?Ga.toStringTag:void 0,Oo=function(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Uv&&Uv in Object(t)?gP(t):bP(t)},fu=function(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")},Aw=function(t){if(!fu(t))return!1;var e=Oo(t);return e=="[object Function]"||e=="[object GeneratorFunction]"||e=="[object AsyncFunction]"||e=="[object Proxy]"},Gh=ps["__core-js_shared__"],Gv=(function(){var t=/[^.]+$/.exec(Gh&&Gh.keys&&Gh.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""})(),yP=function(t){return!!Gv&&Gv in t},vP=Function.prototype.toString,Ri=function(t){if(t!=null){try{return vP.call(t)}catch{}try{return t+""}catch{}}return""},wP=/^\[object .+?Constructor\]$/,kP=Function.prototype,SP=Object.prototype,CP=kP.toString,IP=SP.hasOwnProperty,LP=RegExp("^"+CP.call(IP).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),AP=function(t){return!(!fu(t)||yP(t))&&(Aw(t)?LP:wP).test(Ri(t))},PP=function(t,e){return t?.[e]},Ni=function(t,e){var n=PP(t,e);return AP(n)?n:void 0},hu=Ni(ps,"Map"),pu=Ni(Object,"create"),RP=function(){this.__data__=pu?pu(null):{},this.size=0},NP=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},MP=Object.prototype.hasOwnProperty,TP=function(t){var e=this.__data__;if(pu){var n=e[t];return n==="__lodash_hash_undefined__"?void 0:n}return MP.call(e,t)?e[t]:void 0},DP=Object.prototype.hasOwnProperty,FP=function(t){var e=this.__data__;return pu?e[t]!==void 0:DP.call(e,t)},EP=function(t,e){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=pu&&e===void 0?"__lodash_hash_undefined__":e,this};function To(t){var e=-1,n=t==null?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}To.prototype.clear=RP,To.prototype.delete=NP,To.prototype.get=TP,To.prototype.has=FP,To.prototype.set=EP;var zv=To,OP=function(){this.size=0,this.__data__={hash:new zv,map:new(hu||Zc),string:new zv}},BP=function(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null},Qc=function(t,e){var n=t.__data__;return BP(e)?n[typeof e=="string"?"string":"hash"]:n.map},_P=function(t){var e=Qc(this,t).delete(t);return this.size-=e?1:0,e},HP=function(t){return Qc(this,t).get(t)},UP=function(t){return Qc(this,t).has(t)},GP=function(t,e){var n=Qc(this,t),r=n.size;return n.set(t,e),this.size+=n.size==r?0:1,this};function Do(t){var e=-1,n=t==null?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}Do.prototype.clear=OP,Do.prototype.delete=_P,Do.prototype.get=HP,Do.prototype.has=UP,Do.prototype.set=GP;var ed=Do,zP=function(t,e){var n=this.__data__;if(n instanceof Zc){var r=n.__data__;if(!hu||r.length<199)return r.push([t,e]),this.size=++n.size,this;n=this.__data__=new ed(r)}return n.set(t,e),this.size=n.size,this};function Fo(t){var e=this.__data__=new Zc(t);this.size=e.size}Fo.prototype.clear=uP,Fo.prototype.delete=cP,Fo.prototype.get=dP,Fo.prototype.has=fP,Fo.prototype.set=zP;var Vc=Fo,WP=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},jP=function(t){return this.__data__.has(t)};function $c(t){var e=-1,n=t==null?0:t.length;for(this.__data__=new ed;++e<n;)this.add(t[e])}$c.prototype.add=$c.prototype.push=WP,$c.prototype.has=jP;var qP=$c,VP=function(t,e){for(var n=-1,r=t==null?0:t.length;++n<r;)if(e(t[n],n,t))return!0;return!1},$P=function(t,e){return t.has(e)},Pw=function(t,e,n,r,a,s){var i=1&n,o=t.length,l=e.length;if(o!=l&&!(i&&l>o))return!1;var u=s.get(t),c=s.get(e);if(u&&c)return u==e&&c==t;var d=-1,f=!0,h=2&n?new qP:void 0;for(s.set(t,e),s.set(e,t);++d<o;){var p=t[d],g=e[d];if(r)var m=i?r(g,p,d,e,t,s):r(p,g,d,t,e,s);if(m!==void 0){if(m)continue;f=!1;break}if(h){if(!VP(e,(function(x,b){if(!$P(h,b)&&(p===x||a(p,x,n,r,s)))return h.push(b)}))){f=!1;break}}else if(p!==g&&!a(p,g,n,r,s)){f=!1;break}}return s.delete(t),s.delete(e),f},Wv=ps.Uint8Array,KP=function(t){var e=-1,n=Array(t.size);return t.forEach((function(r,a){n[++e]=[a,r]})),n},XP=function(t){var e=-1,n=Array(t.size);return t.forEach((function(r){n[++e]=r})),n},jv=Ga?Ga.prototype:void 0,zh=jv?jv.valueOf:void 0,YP=function(t,e,n,r,a,s,i){switch(n){case"[object DataView]":if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=e.byteLength||!s(new Wv(t),new Wv(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return Cw(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var o=KP;case"[object Set]":var l=1&r;if(o||(o=XP),t.size!=e.size&&!l)return!1;var u=i.get(t);if(u)return u==e;r|=2,i.set(t,e);var c=Pw(o(t),o(e),r,a,s,i);return i.delete(t),c;case"[object Symbol]":if(zh)return zh.call(t)==zh.call(e)}return!1},Rw=function(t,e){for(var n=-1,r=e.length,a=t.length;++n<r;)t[a+n]=e[n];return t},Xr=Array.isArray,JP=function(t,e,n){var r=e(t);return Xr(t)?r:Rw(r,n(t))},ZP=function(t,e){for(var n=-1,r=t==null?0:t.length,a=0,s=[];++n<r;){var i=t[n];e(i,n,t)&&(s[a++]=i)}return s},QP=function(){return[]},eR=Object.prototype.propertyIsEnumerable,qv=Object.getOwnPropertySymbols,tR=qv?function(t){return t==null?[]:(t=Object(t),ZP(qv(t),(function(e){return eR.call(t,e)})))}:QP,nR=function(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r},Eo=function(t){return t!=null&&typeof t=="object"},Vv=function(t){return Eo(t)&&Oo(t)=="[object Arguments]"},Nw=Object.prototype,rR=Nw.hasOwnProperty,aR=Nw.propertyIsEnumerable,rp=Vv((function(){return arguments})())?Vv:function(t){return Eo(t)&&rR.call(t,"callee")&&!aR.call(t,"callee")},sR=function(){return!1},Kh=gu((function(t,e){var n=e&&!e.nodeType&&e,r=n&&t&&!t.nodeType&&t,a=r&&r.exports===n?ps.Buffer:void 0,s=(a?a.isBuffer:void 0)||sR;t.exports=s})),iR=/^(?:0|[1-9]\d*)$/,Mw=function(t,e){var n=typeof t;return!!(e=e??9007199254740991)&&(n=="number"||n!="symbol"&&iR.test(t))&&t>-1&&t%1==0&&t<e},ap=function(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=9007199254740991},sn={};sn["[object Float32Array]"]=sn["[object Float64Array]"]=sn["[object Int8Array]"]=sn["[object Int16Array]"]=sn["[object Int32Array]"]=sn["[object Uint8Array]"]=sn["[object Uint8ClampedArray]"]=sn["[object Uint16Array]"]=sn["[object Uint32Array]"]=!0,sn["[object Arguments]"]=sn["[object Array]"]=sn["[object ArrayBuffer]"]=sn["[object Boolean]"]=sn["[object DataView]"]=sn["[object Date]"]=sn["[object Error]"]=sn["[object Function]"]=sn["[object Map]"]=sn["[object Number]"]=sn["[object Object]"]=sn["[object RegExp]"]=sn["[object Set]"]=sn["[object String]"]=sn["[object WeakMap]"]=!1;var oR=function(t){return Eo(t)&&ap(t.length)&&!!sn[Oo(t)]},lR=function(t){return function(e){return t(e)}},$v=gu((function(t,e){var n=e&&!e.nodeType&&e,r=n&&t&&!t.nodeType&&t,a=r&&r.exports===n&&Iw.process,s=(function(){try{var i=r&&r.require&&r.require("util").types;return i||a&&a.binding&&a.binding("util")}catch{}})();t.exports=s})),Kv=$v&&$v.isTypedArray,Tw=Kv?lR(Kv):oR,uR=Object.prototype.hasOwnProperty,cR=function(t,e){var n=Xr(t),r=!n&&rp(t),a=!n&&!r&&Kh(t),s=!n&&!r&&!a&&Tw(t),i=n||r||a||s,o=i?nR(t.length,String):[],l=o.length;for(var u in t)!e&&!uR.call(t,u)||i&&(u=="length"||a&&(u=="offset"||u=="parent")||s&&(u=="buffer"||u=="byteLength"||u=="byteOffset")||Mw(u,l))||o.push(u);return o},dR=Object.prototype,fR=function(t){var e=t&&t.constructor;return t===(typeof e=="function"&&e.prototype||dR)},hR=(function(t,e){return function(n){return t(e(n))}})(Object.keys,Object),pR=Object.prototype.hasOwnProperty,mR=function(t){if(!fR(t))return hR(t);var e=[];for(var n in Object(t))pR.call(t,n)&&n!="constructor"&&e.push(n);return e},sp=function(t){return t!=null&&ap(t.length)&&!Aw(t)},ip=function(t){return sp(t)?cR(t):mR(t)},Xv=function(t){return JP(t,ip,tR)},gR=Object.prototype.hasOwnProperty,xR=function(t,e,n,r,a,s){var i=1&n,o=Xv(t),l=o.length;if(l!=Xv(e).length&&!i)return!1;for(var u=l;u--;){var c=o[u];if(!(i?c in e:gR.call(e,c)))return!1}var d=s.get(t),f=s.get(e);if(d&&f)return d==e&&f==t;var h=!0;s.set(t,e),s.set(e,t);for(var p=i;++u<l;){var g=t[c=o[u]],m=e[c];if(r)var x=i?r(m,g,c,e,t,s):r(g,m,c,t,e,s);if(!(x===void 0?g===m||a(g,m,n,r,s):x)){h=!1;break}p||(p=c=="constructor")}if(h&&!p){var b=t.constructor,y=e.constructor;b==y||!("constructor"in t)||!("constructor"in e)||typeof b=="function"&&b instanceof b&&typeof y=="function"&&y instanceof y||(h=!1)}return s.delete(t),s.delete(e),h},Xh=Ni(ps,"DataView"),Yh=Ni(ps,"Promise"),Jh=Ni(ps,"Set"),Zh=Ni(ps,"WeakMap"),bR=Ri(Xh),yR=Ri(hu),vR=Ri(Yh),wR=Ri(Jh),kR=Ri(Zh),Pi=Oo;(Xh&&Pi(new Xh(new ArrayBuffer(1)))!="[object DataView]"||hu&&Pi(new hu)!="[object Map]"||Yh&&Pi(Yh.resolve())!="[object Promise]"||Jh&&Pi(new Jh)!="[object Set]"||Zh&&Pi(new Zh)!="[object WeakMap]")&&(Pi=function(t){var e=Oo(t),n=e=="[object Object]"?t.constructor:void 0,r=n?Ri(n):"";if(r)switch(r){case bR:return"[object DataView]";case yR:return"[object Map]";case vR:return"[object Promise]";case wR:return"[object Set]";case kR:return"[object WeakMap]"}return e});var Yv=Pi,Gc="[object Object]",Jv=Object.prototype.hasOwnProperty,SR=function(t,e,n,r,a,s){var i=Xr(t),o=Xr(e),l=i?"[object Array]":Yv(t),u=o?"[object Array]":Yv(e),c=(l=l=="[object Arguments]"?Gc:l)==Gc,d=(u=u=="[object Arguments]"?Gc:u)==Gc,f=l==u;if(f&&Kh(t)){if(!Kh(e))return!1;i=!0,c=!1}if(f&&!c)return s||(s=new Vc),i||Tw(t)?Pw(t,e,n,r,a,s):YP(t,e,l,n,r,a,s);if(!(1&n)){var h=c&&Jv.call(t,"__wrapped__"),p=d&&Jv.call(e,"__wrapped__");if(h||p){var g=h?t.value():t,m=p?e.value():e;return s||(s=new Vc),a(g,m,n,r,s)}}return!!f&&(s||(s=new Vc),xR(t,e,n,r,a,s))},td=function t(e,n,r,a,s){return e===n||(e==null||n==null||!Eo(e)&&!Eo(n)?e!=e&&n!=n:SR(e,n,r,a,t,s))},CR=function(t,e,n,r){var a=n.length,s=a,i=!r;if(t==null)return!s;for(t=Object(t);a--;){var o=n[a];if(i&&o[2]?o[1]!==t[o[0]]:!(o[0]in t))return!1}for(;++a<s;){var l=(o=n[a])[0],u=t[l],c=o[1];if(i&&o[2]){if(u===void 0&&!(l in t))return!1}else{var d=new Vc;if(r)var f=r(u,c,l,t,e,d);if(!(f===void 0?td(c,u,3,r,d):f))return!1}}return!0},Dw=function(t){return t==t&&!fu(t)},IR=function(t){for(var e=ip(t),n=e.length;n--;){var r=e[n],a=t[r];e[n]=[r,a,Dw(a)]}return e},Fw=function(t,e){return function(n){return n!=null&&n[t]===e&&(e!==void 0||t in Object(n))}},LR=function(t){var e=IR(t);return e.length==1&&e[0][2]?Fw(e[0][0],e[0][1]):function(n){return n===t||CR(n,t,e)}},nd=function(t){return typeof t=="symbol"||Eo(t)&&Oo(t)=="[object Symbol]"},AR=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,PR=/^\w*$/,op=function(t,e){if(Xr(t))return!1;var n=typeof t;return!(n!="number"&&n!="symbol"&&n!="boolean"&&t!=null&&!nd(t))||PR.test(t)||!AR.test(t)||e!=null&&t in Object(e)};function lp(t,e){if(typeof t!="function"||e!=null&&typeof e!="function")throw new TypeError("Expected a function");var n=function(){var r=arguments,a=e?e.apply(this,r):r[0],s=n.cache;if(s.has(a))return s.get(a);var i=t.apply(this,r);return n.cache=s.set(a,i)||s,i};return n.cache=new(lp.Cache||ed),n}lp.Cache=ed;var RR=lp,NR=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,MR=/\\(\\)?/g,TR=(function(t){var e=RR(t,(function(r){return n.size===500&&n.clear(),r})),n=e.cache;return e})((function(t){var e=[];return t.charCodeAt(0)===46&&e.push(""),t.replace(NR,(function(n,r,a,s){e.push(a?s.replace(MR,"$1"):r||n)})),e})),Ew=function(t,e){for(var n=-1,r=t==null?0:t.length,a=Array(r);++n<r;)a[n]=e(t[n],n,t);return a},Zv=Ga?Ga.prototype:void 0,Qv=Zv?Zv.toString:void 0,DR=function t(e){if(typeof e=="string")return e;if(Xr(e))return Ew(e,t)+"";if(nd(e))return Qv?Qv.call(e):"";var n=e+"";return n=="0"&&1/e==-1/0?"-0":n},FR=function(t){return t==null?"":DR(t)},Ow=function(t,e){return Xr(t)?t:op(t,e)?[t]:TR(FR(t))},rd=function(t){if(typeof t=="string"||nd(t))return t;var e=t+"";return e=="0"&&1/t==-1/0?"-0":e},Bw=function(t,e){for(var n=0,r=(e=Ow(e,t)).length;t!=null&&n<r;)t=t[rd(e[n++])];return n&&n==r?t:void 0},ER=function(t,e,n){var r=t==null?void 0:Bw(t,e);return r===void 0?n:r},OR=function(t,e){return t!=null&&e in Object(t)},BR=function(t,e,n){for(var r=-1,a=(e=Ow(e,t)).length,s=!1;++r<a;){var i=rd(e[r]);if(!(s=t!=null&&n(t,i)))break;t=t[i]}return s||++r!=a?s:!!(a=t==null?0:t.length)&&ap(a)&&Mw(i,a)&&(Xr(t)||rp(t))},_R=function(t,e){return t!=null&&BR(t,e,OR)},HR=function(t,e){return op(t)&&Dw(e)?Fw(rd(t),e):function(n){var r=ER(n,t);return r===void 0&&r===e?_R(n,t):td(e,r,3)}},UR=function(t){return t},GR=function(t){return function(e){return e?.[t]}},zR=function(t){return function(e){return Bw(e,t)}},WR=function(t){return op(t)?GR(rd(t)):zR(t)},ad=function(t){return typeof t=="function"?t:t==null?UR:typeof t=="object"?Xr(t)?HR(t[0],t[1]):LR(t):WR(t)},jR=/\s/,qR=function(t){for(var e=t.length;e--&&jR.test(t.charAt(e)););return e},VR=/^\s+/,$R=function(t){return t&&t.slice(0,qR(t)+1).replace(VR,"")},KR=/^[-+]0x[0-9a-f]+$/i,XR=/^0b[01]+$/i,YR=/^0o[0-7]+$/i,JR=parseInt,ZR=function(t){if(typeof t=="number")return t;if(nd(t))return NaN;if(fu(t)){var e=typeof t.valueOf=="function"?t.valueOf():t;t=fu(e)?e+"":e}if(typeof t!="string")return t===0?t:+t;t=$R(t);var n=XR.test(t);return n||YR.test(t)?JR(t.slice(2),n?2:8):KR.test(t)?NaN:+t},QR=function(t){return t?(t=ZR(t))===1/0||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:t===0?t:0},eN=function(t){var e=QR(t),n=e%1;return e==e?n?e-n:e:0},tN=Math.max,nN=Math.min,ew=function(t,e,n){var r=t==null?0:t.length;if(!r)return-1;var a=r-1;return n!==void 0&&(a=eN(n),a=n<0?tN(r+a,0):nN(a,r-1)),nP(t,ad(e),a,!0)},mu=Js("old"),rN=Js("new");function tw(t){var e=t.oldStart;return[e,e+t.oldLines-1]}function Kc(t){if(!t.length)return null;var e=t.reduce((function(i,o){return Ua(o)||(i.isPlain=!1),Zs(o)||(i.oldLines=i.oldLines+1,i.oldStart===-1&&(i.oldStart=mu(o))),ba(o)||(i.newLines=i.newLines+1,i.newStart===-1&&(i.newStart=rN(o))),i}),{isPlain:!0,content:"",oldStart:-1,oldLines:0,newStart:-1,newLines:0}),n=e.oldStart,r=e.oldLines,a=e.newStart,s=e.newLines;return Ht(Ht({},e),{},{content:"@@ -".concat(n,",").concat(r," +").concat(a,",").concat(s),changes:t})}function aN(t,e,n){return Kc(t.map((function(r,a){return{type:"normal",isNormal:!0,oldLineNumber:e+a,newLineNumber:n+a,content:""+r}})))}function zc(t,e,n){var r=t.changes,a=r.findIndex((function(o){return mu(o)>=e}));if(a===-1)return null;var s=(function(){if(a===0)return a;var o=ew(r,(function(l){return!Zs(l)}),a-1);return o===-1?a:o+1})();if(n===void 0)return Kc(r.slice(s));var i=ew(r,(function(o){return mu(o)<=n}));return Kc(r.slice(s,i===-1?void 0:i))}function du(t,e){if(!t)return e;if(!e)return t;var n=mn(tw(t),2),r=n[0],a=n[1],s=mn(tw(e),2),i=s[0],o=s[1];if(a+1===i)return Kc([].concat(Hr(t.changes),Hr(e.changes)));if(r<=i&&a>=o){if(t.isPlain&&!e.isPlain){var l=zc(t,r,i),u=zc(t,o+1);return du(du(l,e),u)}return t}return t.isPlain?du(zc(t,r,i),e):du(t,zc(e,a+1))}function sN(t,e){var n=ww(t);if(!n)return[e];if(n.oldStart+n.oldLines<e.oldStart)return t.concat(e);var r=du(n,e);return r?[].concat(Hr(t.slice(0,-1)),[r]):t}function iN(t,e){var n=mu(e.changes[0]),r=t.findIndex((function(a){var s=a.changes;return!!s.length&&mu(s[0])>=n}));return(r===-1?t.concat(e):[].concat(Hr(t.slice(0,r)),[e],Hr(t.slice(r)))).reduce(sN,[])}function Xs(t){if(!t)throw new Error("change is not provided");if(Ua(t))return"N".concat(t.oldLineNumber);var e=Zs(t)?"I":"D";return"".concat(e).concat(t.lineNumber)}var oN=np("old"),Wh=Js("old"),nw=tp("oldStart","oldLines"),lN=kw("oldStart","oldLines");function Qh(t,e,n){var r=(function(h,p){if(!h.length)return-1;var g=vw(h);if(p<g.oldStart||nw(g,p))return 0;for(var m=1;m<h.length;m++){var x=h[m];if(nw(x,p))return m;var b=h[m-1];if(lN(b,x,p))return m}return-1})(t,e);if(r===-1)return[[e,n]];var a=t[r];if(e<a.oldStart){var s=a.changes.findIndex((function(h){return!Ua(h)})),i=a.oldStart+Math.max(s,0);return i>=n?[[e,n]]:[[e,i]].concat(Hr(Qh(t,i+1,n)))}var o=a.changes,l=(function(h,p){var g=h.changes,m=g.findIndex((function(b){return Wh(b)===p}));if(m<0)return-1;for(var x=m;x<g.length;x++)if(Ua(g[x]))return x;return-1})(a,e);if(l===-1)return[];var u=o[l],c=Wh(u),d=o.slice(l+1).findIndex((function(h){return!Ua(h)})),f=Wh(u)+Math.max(d,0);return f>=n?[[c,n]]:[[c,f]].concat(Hr(Qh(t,f+1,n)))}function _w(t,e,n,r){return Qh(t,n,r).reduce((function(a,s){return(function(i,o,l){var u=mn(l,2),c=u[0],d=u[1],f=(typeof o=="string"?o.split(`
|
|
12
|
+
`):o).slice(Math.max(c,1)-1,d-1);if(!f.length)return i;var h=aN(f,c,oN(i,c));return h?iN(i,h):i})(a,e,s)}),t)}function Hw(t,e){if(!t)return e.oldStart-1;var n=t.oldStart+t.oldLines;return e.oldStart-n}var sd=Js("old"),id=Js("new"),bz=Sw("old"),yz=Sw("new"),vz=np("new"),wz=np("old"),rw=(function(){try{var t=Ni(Object,"defineProperty");return t({},"",{}),t}catch{}})(),up=function(t,e,n){e=="__proto__"&&rw?rw(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n},uN=function(t){return function(e,n,r){for(var a=-1,s=Object(e),i=r(e),o=i.length;o--;){var l=i[t?o:++a];if(n(s[l],l,s)===!1)break}return e}},cN=uN(),Uw=function(t,e){return t&&cN(t,e,ip)},Gw=function(t,e){var n={};return e=ad(e),Uw(t,(function(r,a,s){up(n,a,e(r,a,s))})),n},dN=["changeKey","text","tokens","renderToken"],aw=function t(e,n){var r=e.type,a=e.value,s=e.markType,i=e.properties,o=e.className,l=e.children,u=function(d){return(0,je.jsx)("span",{className:d,children:a||l&&l.map(t)},n)};switch(r){case"text":return a;case"mark":return u("diff-code-mark diff-code-mark-".concat(s));case"edit":return u("diff-code-edit");default:var c=i&&i.className;return u(Fn(o||c))}};function fN(t){if(!Array.isArray(t))return!0;if(t.length>1)return!1;if(t.length===1){var e=mn(t,1)[0];return e.type==="text"&&!e.value}return!0}function hN(t){var e=t.changeKey,n=t.text,r=t.tokens,a=t.renderToken,s=Ys(t,dN),i=a?function(o,l){return a(o,aw,l)}:aw;return(0,je.jsx)("td",Ht(Ht({},s),{},{"data-change-key":e,children:r?fN(r)?" ":r.map(i):n||" "}))}var zw=(0,Mt.memo)(hN);function Ww(t,e){return function(){var n=e==="old"?sd(t):id(t);return n===-1?void 0:n}}function jw(t,e){return function(n){return t&&n?(0,je.jsx)("a",{href:e?"#"+e:void 0,children:n}):n}}function Xc(t,e){return e?function(n){t(),e(n)}:t}function sw(t,e,n,r){return(0,Mt.useMemo)((function(){var a=Gw(t,(function(s){return function(i){return s&&s(e,i)}}));return a.onMouseEnter=Xc(n,a.onMouseEnter),a.onMouseLeave=Xc(r,a.onMouseLeave),a}),[t,n,r,e])}function iw(t,e,n,r,a,s,i,o,l){var u={change:e,side:r,inHoverState:o,renderDefault:Ww(e,r),wrapInAnchor:jw(a,s)};return(0,je.jsx)("td",Ht(Ht({className:t},i),{},{"data-change-key":n,children:l(u)}))}function pN(t){var e,n,r,a=t.change,s=t.selected,i=t.tokens,o=t.className,l=t.generateLineClassName,u=t.gutterClassName,c=t.codeClassName,d=t.gutterEvents,f=t.codeEvents,h=t.hideGutter,p=t.gutterAnchor,g=t.generateAnchorID,m=t.renderToken,x=t.renderGutter,b=a.type,y=a.content,C=Xs(a),I=(e=mn((0,Mt.useState)(!1),2),n=e[0],r=e[1],[n,(0,Mt.useCallback)((function(){return r(!0)}),[]),(0,Mt.useCallback)((function(){return r(!1)}),[])]),L=mn(I,3),v=L[0],k=L[1],O=L[2],R=(0,Mt.useMemo)((function(){return{change:a}}),[a]),P=sw(d,R,k,O),H=sw(f,R,k,O),w=g(a),N=l({changes:[a],defaultGenerate:function(){return o}}),j=Fn("diff-gutter","diff-gutter-".concat(b),u,{"diff-gutter-selected":s}),K=Fn("diff-code","diff-code-".concat(b),c,{"diff-code-selected":s});return(0,je.jsxs)("tr",{id:w,className:Fn("diff-line",N),children:[!h&&iw(j,a,C,"old",p,w,P,v,x),!h&&iw(j,a,C,"new",p,w,P,v,x),(0,je.jsx)(zw,Ht({className:K,changeKey:C,text:y,tokens:i,renderToken:m},H))]})}var mN=(0,Mt.memo)(pN);function gN(t){var e=t.hideGutter,n=t.element;return(0,je.jsx)("tr",{className:"diff-widget",children:(0,je.jsx)("td",{colSpan:e?1:3,className:"diff-widget-content",children:n})})}var xN=["hideGutter","selectedChanges","tokens","lineClassName"],bN=["hunk","widgets","className"];function yN(t){var e=t.hunk,n=t.widgets,r=t.className,a=Ys(t,bN),s=(function(i,o){return i.reduce((function(l,u){var c=Xs(u);l.push(["change",c,u]);var d=o[c];return d&&l.push(["widget",c,d]),l}),[])})(e.changes,n);return(0,je.jsx)("tbody",{className:Fn("diff-hunk",r),children:s.map((function(i){return(function(o,l){var u=mn(o,3),c=u[0],d=u[1],f=u[2],h=l.hideGutter,p=l.selectedChanges,g=l.tokens,m=l.lineClassName,x=Ys(l,xN);if(c==="change"){var b=ba(f)?"old":"new",y=ba(f)?sd(f):id(f),C=g?g[b][y-1]:null;return(0,je.jsx)(mN,Ht({className:m,change:f,hideGutter:h,selected:p.includes(d),tokens:C},x),"change".concat(d))}return c==="widget"?(0,je.jsx)(gN,{hideGutter:h,element:f},"widget".concat(d)):null})(i,a)}))})}var qw=0;function Wc(t,e,n,r){var a=(0,Mt.useCallback)((function(){return e(t)}),[t,e]),s=(0,Mt.useCallback)((function(){return e("")}),[e]);return(0,Mt.useMemo)((function(){var i=Gw(r,(function(o){return function(l){return o&&o({side:t,change:n},l)}}));return i.onMouseEnter=Xc(a,i.onMouseEnter),i.onMouseLeave=Xc(s,i.onMouseLeave),i}),[n,r,a,t,s])}function jh(t){var e=t.change,n=t.side,r=t.selected,a=t.tokens,s=t.gutterClassName,i=t.codeClassName,o=t.gutterEvents,l=t.codeEvents,u=t.anchorID,c=t.gutterAnchor,d=t.gutterAnchorTarget,f=t.hideGutter,h=t.hover,p=t.renderToken,g=t.renderGutter;if(!e){var m=Fn("diff-gutter","diff-gutter-omit",s),x=Fn("diff-code","diff-code-omit",i);return[!f&&(0,je.jsx)("td",{className:m},"gutter"),(0,je.jsx)("td",{className:x},"code")]}var b=e.type,y=e.content,C=Xs(e),I=n===qw?"old":"new",L=Ht({id:u||void 0,className:Fn("diff-gutter","diff-gutter-".concat(b),qh({"diff-gutter-selected":r},"diff-line-hover-"+I,h),s),children:g({change:e,side:I,inHoverState:h,renderDefault:Ww(e,I),wrapInAnchor:jw(c,d)})},o),v=Fn("diff-code","diff-code-".concat(b),qh({"diff-code-selected":r},"diff-line-hover-"+I,h),i);return[!f&&(0,je.jsx)("td",Ht(Ht({},L),{},{"data-change-key":C}),"gutter"),(0,je.jsx)(zw,Ht({className:v,changeKey:C,text:y,tokens:a,renderToken:p},l),"code")]}function vN(t){var e=t.className,n=t.oldChange,r=t.newChange,a=t.oldSelected,s=t.newSelected,i=t.oldTokens,o=t.newTokens,l=t.monotonous,u=t.gutterClassName,c=t.codeClassName,d=t.gutterEvents,f=t.codeEvents,h=t.hideGutter,p=t.generateAnchorID,g=t.generateLineClassName,m=t.gutterAnchor,x=t.renderToken,b=t.renderGutter,y=mn((0,Mt.useState)(""),2),C=y[0],I=y[1],L=Wc("old",I,n,d),v=Wc("new",I,r,d),k=Wc("old",I,n,f),O=Wc("new",I,r,f),R=n&&p(n),P=r&&p(r),H=g({changes:[n,r],defaultGenerate:function(){return e}}),w={monotonous:l,hideGutter:h,gutterClassName:u,codeClassName:c,gutterEvents:d,codeEvents:f,renderToken:x,renderGutter:b},N=Ht(Ht({},w),{},{change:n,side:qw,selected:a,tokens:i,gutterEvents:L,codeEvents:k,anchorID:R,gutterAnchor:m,gutterAnchorTarget:R,hover:C==="old"}),j=Ht(Ht({},w),{},{change:r,side:1,selected:s,tokens:o,gutterEvents:v,codeEvents:O,anchorID:n===r?null:P,gutterAnchor:m,gutterAnchorTarget:n===r?R:P,hover:C==="new"});if(l)return(0,je.jsx)("tr",{className:Fn("diff-line",H),children:jh(n?N:j)});var K=(function(A,F){return A&&!F?"diff-line-old-only":!A&&F?"diff-line-new-only":A===F?"diff-line-normal":"diff-line-compare"})(n,r);return(0,je.jsxs)("tr",{className:Fn("diff-line",K,H),children:[jh(N),jh(j)]})}var wN=(0,Mt.memo)(vN);function kN(t){var e=t.hideGutter,n=t.oldElement,r=t.newElement;return t.monotonous?(0,je.jsx)("tr",{className:"diff-widget",children:(0,je.jsx)("td",{colSpan:e?1:2,className:"diff-widget-content",children:n||r})}):n===r?(0,je.jsx)("tr",{className:"diff-widget",children:(0,je.jsx)("td",{colSpan:e?2:4,className:"diff-widget-content",children:n})}):(0,je.jsxs)("tr",{className:"diff-widget",children:[(0,je.jsx)("td",{colSpan:e?1:2,className:"diff-widget-content",children:n}),(0,je.jsx)("td",{colSpan:e?1:2,className:"diff-widget-content",children:r})]})}var SN=["selectedChanges","monotonous","hideGutter","tokens","lineClassName"],CN=["hunk","widgets","className"];function jc(t,e){return(t?Xs(t):"00")+(e?Xs(e):"00")}function IN(t){var e=t.hunk,n=t.widgets,r=t.className,a=Ys(t,CN),s=(function(i,o){for(var l=function(x){if(!x)return null;var b=Xs(x);return o[b]||null},u=[],c=0;c<i.length;c++){var d=i[c];if(Ua(d))u.push(["change",jc(d,d),d,d]);else if(ba(d)){var f=i[c+1];f&&Zs(f)?(c+=1,u.push(["change",jc(d,f),d,f])):u.push(["change",jc(d,null),d,null])}else u.push(["change",jc(null,d),null,d]);var h=u[u.length-1],p=l(h[2]),g=l(h[3]);if(p||g){var m=h[1];u.push(["widget",m,p,g])}}return u})(e.changes,n);return(0,je.jsx)("tbody",{className:Fn("diff-hunk",r),children:s.map((function(i){return(function(o,l){var u=mn(o,4),c=u[0],d=u[1],f=u[2],h=u[3],p=l.selectedChanges,g=l.monotonous,m=l.hideGutter,x=l.tokens,b=l.lineClassName,y=Ys(l,SN);if(c==="change"){var C=!!f&&p.includes(Xs(f)),I=!!h&&p.includes(Xs(h)),L=f&&x?x.old[sd(f)-1]:null,v=h&&x?x.new[id(h)-1]:null;return(0,je.jsx)(wN,Ht({className:b,oldChange:f,newChange:h,monotonous:g,hideGutter:m,oldSelected:C,newSelected:I,oldTokens:L,newTokens:v},y),"change".concat(d))}return c==="widget"?(0,je.jsx)(kN,{monotonous:g,hideGutter:m,oldElement:f,newElement:h},"widget".concat(d)):null})(i,a)}))})}var LN=["gutterType","hunkClassName"];function cp(t){var e=t.hunk,n=bw(),r=n.gutterType,a=n.hunkClassName,s=Ys(n,LN),i=r==="none",o=r==="anchor",l=s.viewType==="unified"?yN:IN;return(0,je.jsx)(l,Ht(Ht({},s),{},{hunk:e,hideGutter:i,gutterAnchor:o,className:a}))}function AN(){}function ow(t,e){var n=e?"auto":"none";t instanceof HTMLElement&&t.style.userSelect!==n&&(t.style.userSelect=n)}function PN(t){return t.map((function(e){return(0,je.jsx)(cp,{hunk:e},(function(n){return"-".concat(n.oldStart,",").concat(n.oldLines," +").concat(n.newStart,",").concat(n.newLines)})(e))}))}function RN(t){var e=t.diffType,n=t.hunks,r=t.optimizeSelection,a=t.className,s=t.hunkClassName,i=s===void 0?Lr.hunkClassName:s,o=t.lineClassName,l=o===void 0?Lr.lineClassName:o,u=t.generateLineClassName,c=u===void 0?Lr.generateLineClassName:u,d=t.gutterClassName,f=d===void 0?Lr.gutterClassName:d,h=t.codeClassName,p=h===void 0?Lr.codeClassName:h,g=t.gutterType,m=g===void 0?Lr.gutterType:g,x=t.viewType,b=x===void 0?Lr.viewType:x,y=t.gutterEvents,C=y===void 0?Lr.gutterEvents:y,I=t.codeEvents,L=I===void 0?Lr.codeEvents:I,v=t.generateAnchorID,k=v===void 0?Lr.generateAnchorID:v,O=t.selectedChanges,R=O===void 0?Lr.selectedChanges:O,P=t.widgets,H=P===void 0?Lr.widgets:P,w=t.renderGutter,N=w===void 0?Lr.renderGutter:w,j=t.tokens,K=t.renderToken,A=t.children,F=A===void 0?PN:A,_=(0,Mt.useRef)(null),X=(0,Mt.useCallback)((function(Q){var te=Q.target;if(Q.button===0){var ge=(function(at,Ft){for(var Ue=at;Ue&&Ue!==document.documentElement&&!Ue.classList.contains(Ft);)Ue=Ue.parentElement;return Ue===document.documentElement?null:Ue})(te,"diff-code");if(ge&&ge.parentElement){var de=window.getSelection();de&&de.removeAllRanges();var De=Hr(ge.parentElement.children).indexOf(ge);if(De===1||De===3){var Xe,Qe=ep(_.current?_.current.querySelectorAll(".diff-line"):[]);try{for(Qe.s();!(Xe=Qe.n()).done;){var rt=Xe.value.children;ow(rt[1],De===1),ow(rt[3],De===3)}}catch(at){Qe.e(at)}finally{Qe.f()}}}}}),[]),re=m==="none",ae=e==="add"||e==="delete",Le=b==="split"&&!ae&&r?X:AN,ye=(0,Mt.useMemo)((function(){return(0,je.jsxs)("colgroup",b==="unified"?{children:[!re&&(0,je.jsx)("col",{className:"diff-gutter-col"}),!re&&(0,je.jsx)("col",{className:"diff-gutter-col"}),(0,je.jsx)("col",{})]}:ae?{children:[!re&&(0,je.jsx)("col",{className:"diff-gutter-col"}),(0,je.jsx)("col",{})]}:{children:[!re&&(0,je.jsx)("col",{className:"diff-gutter-col"}),(0,je.jsx)("col",{}),!re&&(0,je.jsx)("col",{className:"diff-gutter-col"}),(0,je.jsx)("col",{})]})}),[b,ae,re]),q=(0,Mt.useMemo)((function(){return{hunkClassName:i,lineClassName:l,generateLineClassName:c,gutterClassName:f,codeClassName:p,monotonous:ae,hideGutter:re,viewType:b,gutterType:m,codeEvents:L,gutterEvents:C,generateAnchorID:k,selectedChanges:R,widgets:H,renderGutter:N,tokens:j,renderToken:K}}),[p,L,k,f,C,m,re,i,l,c,ae,N,K,R,j,b,H]);return(0,je.jsx)(QA,{value:q,children:(0,je.jsxs)("table",{ref:_,className:Fn("diff","diff-".concat(b),a),onMouseDown:Le,children:[ye,F(n)]})})}var Vw=(0,Mt.memo)(RN),NN=function(){};var lw=NN;function MN(t){var e=t.hideGutter,n=t.monotonous,r=t.className,a=t.gutterClassName,s=t.contentClassName,i=t.children,o=Fn("diff-decoration",r),l=Fn("diff-decoration-gutter",a),u=Fn("diff-decoration-content",s),c=(e?2:4)/(n?2:1),d=c-(e?0:1);if(Mt.Children.count(i)===1)return(0,je.jsx)("tbody",{className:o,children:(0,je.jsx)("tr",{children:(0,je.jsx)("td",{colSpan:c,className:u,children:i})})});var f=mn(i,2),h=f[0],p=f[1];return(0,je.jsx)("tbody",{className:o,children:(0,je.jsxs)("tr",{children:[!e&&(0,je.jsx)("td",{className:l,children:h}),(0,je.jsx)("td",{colSpan:d,className:u,children:p})]})})}function TN(t){var e=t.hideGutter,n=t.className,r=t.gutterClassName,a=t.contentClassName,s=t.children,i=Fn("diff-decoration",n),o=Fn("diff-decoration-gutter",r),l=Fn("diff-decoration-content",a);if(Mt.Children.count(s)===1)return(0,je.jsx)("tbody",{className:i,children:(0,je.jsx)("tr",{children:(0,je.jsx)("td",{colSpan:e?1:3,className:l,children:s})})});var u=mn(s,2),c=u[0],d=u[1];return(0,je.jsx)("tbody",{className:i,children:(0,je.jsxs)("tr",{children:[!e&&(0,je.jsx)("td",{colSpan:2,className:o,children:c}),(0,je.jsx)("td",{className:l,children:d})]})})}function od(t){var e=t.className,n=e===void 0?"":e,r=t.gutterClassName,a=r===void 0?"":r,s=t.contentClassName,i=s===void 0?"":s,o=t.children,l=bw(),u=l.viewType,c=l.gutterType,d=l.monotonous,f=u==="split"?MN:TN,h=Mt.Children.count(o),p=c==="none";return lw(h<=2,"Decoration only accepts a maxium of 2 children"),lw(h<2||!p,"Gutter element in decoration will not be rendered since hideGutter prop is set to true"),(0,je.jsx)(f,{hideGutter:p,monotonous:d,className:n,gutterClassName:a,contentClassName:i,children:o})}var DN=function(t,e,n,r){for(var a=-1,s=t==null?0:t.length;++a<s;){var i=t[a];e(r,i,n(i),t)}return r},FN=function(t,e){return function(n,r){if(n==null)return n;if(!sp(n))return t(n,r);for(var a=n.length,s=e?a:-1,i=Object(n);(e?s--:++s<a)&&r(i[s],s,i)!==!1;);return n}},$w=FN(Uw),EN=function(t,e,n,r){return $w(t,(function(a,s,i){e(r,a,n(a),i)})),r},Kw=function(t,e){return function(n,r){var a=Xr(n)?DN:EN,s=e?e():{};return a(n,t,ad(r),s)}},ON=Kw((function(t,e,n){up(t,n,e)})),uw=Ga?Ga.isConcatSpreadable:void 0,BN=function(t){return Xr(t)||rp(t)||!!(uw&&t&&t[uw])},_N=function t(e,n,r,a,s){var i=-1,o=e.length;for(r||(r=BN),s||(s=[]);++i<o;){var l=e[i];n>0&&r(l)?n>1?t(l,n-1,r,a,s):Rw(s,l):a||(s[s.length]=l)}return s},HN=function(t,e){var n=-1,r=sp(t)?Array(t.length):[];return $w(t,(function(a,s,i){r[++n]=e(a,s,i)})),r},UN=function(t,e){return(Xr(t)?Ew:HN)(t,ad(e))},GN=function(t,e){return _N(UN(t,e),1)};function zN(t,e){var n=e.newStart,r=e.changes.reduce((function(a,s){var i=mn(a,2),o=i[0],l=i[1];return ba(s)?(o.splice(l,1),[o,l]):(Zs(s)&&o.splice(l,0,s.content),[o,l+1])}),[t,n-1]);return mn(r,1)[0]}function cw(t,e,n){if(!t.length)return[];var r=e==="old"?sd:id,a=ON(t,r),s=r(t[t.length-1]);return Array.from({length:s}).map((function(i,o){return n(a[o+1])}))}function WN(t){var e=(function(i){return GN(i,(function(o){return o.changes})).reduce((function(o,l){var u=mn(o,2),c=u[0],d=u[1];return Ua(l)?(c.push(l),d.push(l)):ba(l)?c.push(l):d.push(l),[c,d]}),[[],[]])})(t),n=mn(e,2),r=n[0],a=n[1],s=function(i){return i?i.content:""};return[cw(r,"old",s).join(`
|
|
13
|
+
`),cw(a,"new",s).join(`
|
|
14
|
+
`)]}function qc(t){return{type:"root",children:t}}function jN(t,e){if(e.oldSource){var n=(function(l,u){return u.reduce(zN,l.split(`
|
|
15
15
|
`)).join(`
|
|
16
|
-
`)})(e.oldSource,t),r=e.highlight?function(l){return e.refractor.highlight(l,e.language)}:function(l){return[{type:"text",value:l}]};return[
|
|
16
|
+
`)})(e.oldSource,t),r=e.highlight?function(l){return e.refractor.highlight(l,e.language)}:function(l){return[{type:"text",value:l}]};return[qc(r(e.oldSource)),qc(r(n))]}var a=mn(WN(t),2),s=a[0],i=a[1],o=e.highlight?function(l){return qc(e.refractor.highlight(l,e.language))}:function(l){return qc([{type:"text",value:l}])};return[o(s),o(i)]}function Xw(t){return t.map((function(e){return Ht({},e)}))}function qN(t,e){return[].concat(Hr(Xw(t.slice(0,-1))),[e])}function VN(t){return t.type==="text"}function $N(t){var e=t[t.length-1];if(VN(e))return e;throw new Error("Invalid token path with leaf of type ".concat(e.type))}var KN=["children"];function Yw(t){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[],n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:[];if(t.children){var r=t.children,a=Ys(t,KN);n.push(a);var s,i=ep(r);try{for(i.s();!(s=i.n()).done;)Yw(s.value,e,n)}catch(o){i.e(o)}finally{i.f()}n.pop()}else e.push(Xw([].concat(Hr(n.slice(1)),[t])));return e}function XN(t){return t.reduce((function(e,n){var r=e[e.length-1],a=(function(l){var u=$N(l);return u.value.includes(`
|
|
17
17
|
`)?u.value.split(`
|
|
18
|
-
`).map((function(c){return
|
|
19
|
-
`,d))==-1&&(f=u.length-1);var p=u.substring(d,f+1);(s.hasOwnProperty?s.hasOwnProperty(p):s[p]!==void 0)?c+=String.fromCharCode(s[p]):(h==o&&(p=u.substring(d),f=u.length),c+=String.fromCharCode(h),s[p]=h,a[h++]=p),d=f+1}return c}a[0]="";var o=4e4,l=i(n);return o=65535,{chars1:l,chars2:i(r),lineArray:a}},e.prototype.diff_charsToLines_=function(n,r){for(var a=0;a<n.length;a++){for(var s=n[a][1],i=[],o=0;o<s.length;o++)i[o]=r[s.charCodeAt(o)];n[a][1]=i.join("")}},e.prototype.diff_commonPrefix=function(n,r){if(!n||!r||n.charAt(0)!=r.charAt(0))return 0;for(var a=0,s=Math.min(n.length,r.length),i=s,o=0;a<i;)n.substring(o,i)==r.substring(o,i)?o=a=i:s=i,i=Math.floor((s-a)/2+a);return i},e.prototype.diff_commonSuffix=function(n,r){if(!n||!r||n.charAt(n.length-1)!=r.charAt(r.length-1))return 0;for(var a=0,s=Math.min(n.length,r.length),i=s,o=0;a<i;)n.substring(n.length-i,n.length-o)==r.substring(r.length-i,r.length-o)?o=a=i:s=i,i=Math.floor((s-a)/2+a);return i},e.prototype.diff_commonOverlap_=function(n,r){var a=n.length,s=r.length;if(a==0||s==0)return 0;a>s?n=n.substring(a-s):a<s&&(r=r.substring(0,a));var i=Math.min(a,s);if(n==r)return i;for(var o=0,l=1;;){var u=n.substring(i-l),c=r.indexOf(u);if(c==-1)return o;l+=c,c!=0&&n.substring(i-l)!=r.substring(0,l)||(o=l,l++)}},e.prototype.diff_halfMatch_=function(n,r){if(this.Diff_Timeout<=0)return null;var a=n.length>r.length?n:r,s=n.length>r.length?r:n;if(a.length<4||2*s.length<a.length)return null;var i=this;function o(g,m,x){for(var y,b,C,L,P=g.substring(x,x+Math.floor(g.length/4)),w=-1,k="";(w=m.indexOf(P,w+1))!=-1;){var _=i.diff_commonPrefix(g.substring(x),m.substring(w)),M=i.diff_commonSuffix(g.substring(0,x),m.substring(0,w));k.length<M+_&&(k=m.substring(w-M,w)+m.substring(w,w+_),y=g.substring(0,x-M),b=g.substring(x+_),C=m.substring(0,w-M),L=m.substring(w+_))}return 2*k.length>=g.length?[y,b,C,L,k]:null}var l,u,c,d,f,h=o(a,s,Math.ceil(a.length/4)),p=o(a,s,Math.ceil(a.length/2));return h||p?(l=p?h&&h[4].length>p[4].length?h:p:h,n.length>r.length?(u=l[0],c=l[1],d=l[2],f=l[3]):(d=l[0],f=l[1],u=l[2],c=l[3]),[u,c,d,f,l[4]]):null},e.prototype.diff_cleanupSemantic=function(n){for(var r=!1,a=[],s=0,i=null,o=0,l=0,u=0,c=0,d=0;o<n.length;)n[o][0]==0?(a[s++]=o,l=c,u=d,c=0,d=0,i=n[o][1]):(n[o][0]==1?c+=n[o][1].length:d+=n[o][1].length,i&&i.length<=Math.max(l,u)&&i.length<=Math.max(c,d)&&(n.splice(a[s-1],0,new e.Diff(-1,i)),n[a[s-1]+1][0]=1,s--,o=--s>0?a[s-1]:-1,l=0,u=0,c=0,d=0,i=null,r=!0)),o++;for(r&&this.diff_cleanupMerge(n),this.diff_cleanupSemanticLossless(n),o=1;o<n.length;){if(n[o-1][0]==-1&&n[o][0]==1){var f=n[o-1][1],h=n[o][1],p=this.diff_commonOverlap_(f,h),g=this.diff_commonOverlap_(h,f);p>=g?(p>=f.length/2||p>=h.length/2)&&(n.splice(o,0,new e.Diff(0,h.substring(0,p))),n[o-1][1]=f.substring(0,f.length-p),n[o+1][1]=h.substring(p),o++):(g>=f.length/2||g>=h.length/2)&&(n.splice(o,0,new e.Diff(0,f.substring(0,g))),n[o-1][0]=1,n[o-1][1]=h.substring(0,h.length-g),n[o+1][0]=-1,n[o+1][1]=f.substring(g),o++),o++}o++}},e.prototype.diff_cleanupSemanticLossless=function(n){function r(g,m){if(!g||!m)return 6;var x=g.charAt(g.length-1),y=m.charAt(0),b=x.match(e.nonAlphaNumericRegex_),C=y.match(e.nonAlphaNumericRegex_),L=b&&x.match(e.whitespaceRegex_),P=C&&y.match(e.whitespaceRegex_),w=L&&x.match(e.linebreakRegex_),k=P&&y.match(e.linebreakRegex_),_=w&&g.match(e.blanklineEndRegex_),M=k&&m.match(e.blanklineStartRegex_);return _||M?5:w||k?4:b&&!L&&P?3:L||P?2:b||C?1:0}for(var a=1;a<n.length-1;){if(n[a-1][0]==0&&n[a+1][0]==0){var s=n[a-1][1],i=n[a][1],o=n[a+1][1],l=this.diff_commonSuffix(s,i);if(l){var u=i.substring(i.length-l);s=s.substring(0,s.length-l),i=u+i.substring(0,i.length-l),o=u+o}for(var c=s,d=i,f=o,h=r(s,i)+r(i,o);i.charAt(0)===o.charAt(0);){s+=i.charAt(0),i=i.substring(1)+o.charAt(0),o=o.substring(1);var p=r(s,i)+r(i,o);p>=h&&(h=p,c=s,d=i,f=o)}n[a-1][1]!=c&&(c?n[a-1][1]=c:(n.splice(a-1,1),a--),n[a][1]=d,f?n[a+1][1]=f:(n.splice(a+1,1),a--))}a++}},e.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/,e.whitespaceRegex_=/\s/,e.linebreakRegex_=/[\r\n]/,e.blanklineEndRegex_=/\n\r?\n$/,e.blanklineStartRegex_=/^\r?\n\r?\n/,e.prototype.diff_cleanupEfficiency=function(n){for(var r=!1,a=[],s=0,i=null,o=0,l=!1,u=!1,c=!1,d=!1;o<n.length;)n[o][0]==0?(n[o][1].length<this.Diff_EditCost&&(c||d)?(a[s++]=o,l=c,u=d,i=n[o][1]):(s=0,i=null),c=d=!1):(n[o][0]==-1?d=!0:c=!0,i&&(l&&u&&c&&d||i.length<this.Diff_EditCost/2&&l+u+c+d==3)&&(n.splice(a[s-1],0,new e.Diff(-1,i)),n[a[s-1]+1][0]=1,s--,i=null,l&&u?(c=d=!0,s=0):(o=--s>0?a[s-1]:-1,c=d=!1),r=!0)),o++;r&&this.diff_cleanupMerge(n)},e.prototype.diff_cleanupMerge=function(n){n.push(new e.Diff(0,""));for(var r,a=0,s=0,i=0,o="",l="";a<n.length;)switch(n[a][0]){case 1:i++,l+=n[a][1],a++;break;case-1:s++,o+=n[a][1],a++;break;case 0:s+i>1?(s!==0&&i!==0&&((r=this.diff_commonPrefix(l,o))!==0&&(a-s-i>0&&n[a-s-i-1][0]==0?n[a-s-i-1][1]+=l.substring(0,r):(n.splice(0,0,new e.Diff(0,l.substring(0,r))),a++),l=l.substring(r),o=o.substring(r)),(r=this.diff_commonSuffix(l,o))!==0&&(n[a][1]=l.substring(l.length-r)+n[a][1],l=l.substring(0,l.length-r),o=o.substring(0,o.length-r))),a-=s+i,n.splice(a,s+i),o.length&&(n.splice(a,0,new e.Diff(-1,o)),a++),l.length&&(n.splice(a,0,new e.Diff(1,l)),a++),a++):a!==0&&n[a-1][0]==0?(n[a-1][1]+=n[a][1],n.splice(a,1)):a++,i=0,s=0,o="",l=""}n[n.length-1][1]===""&&n.pop();var u=!1;for(a=1;a<n.length-1;)n[a-1][0]==0&&n[a+1][0]==0&&(n[a][1].substring(n[a][1].length-n[a-1][1].length)==n[a-1][1]?(n[a][1]=n[a-1][1]+n[a][1].substring(0,n[a][1].length-n[a-1][1].length),n[a+1][1]=n[a-1][1]+n[a+1][1],n.splice(a-1,1),u=!0):n[a][1].substring(0,n[a+1][1].length)==n[a+1][1]&&(n[a-1][1]+=n[a+1][1],n[a][1]=n[a][1].substring(n[a+1][1].length)+n[a+1][1],n.splice(a+1,1),u=!0)),a++;u&&this.diff_cleanupMerge(n)},e.prototype.diff_xIndex=function(n,r){var a,s=0,i=0,o=0,l=0;for(a=0;a<n.length&&(n[a][0]!==1&&(s+=n[a][1].length),n[a][0]!==-1&&(i+=n[a][1].length),!(s>r));a++)o=s,l=i;return n.length!=a&&n[a][0]===-1?l:l+(r-o)},e.prototype.diff_prettyHtml=function(n){for(var r=[],a=/&/g,s=/</g,i=/>/g,o=/\n/g,l=0;l<n.length;l++){var u=n[l][0],c=n[l][1].replace(a,"&").replace(s,"<").replace(i,">").replace(o,"¶<br>");switch(u){case 1:r[l]='<ins style="background:#e6ffe6;">'+c+"</ins>";break;case-1:r[l]='<del style="background:#ffe6e6;">'+c+"</del>";break;case 0:r[l]="<span>"+c+"</span>"}}return r.join("")},e.prototype.diff_text1=function(n){for(var r=[],a=0;a<n.length;a++)n[a][0]!==1&&(r[a]=n[a][1]);return r.join("")},e.prototype.diff_text2=function(n){for(var r=[],a=0;a<n.length;a++)n[a][0]!==-1&&(r[a]=n[a][1]);return r.join("")},e.prototype.diff_levenshtein=function(n){for(var r=0,a=0,s=0,i=0;i<n.length;i++){var o=n[i][0],l=n[i][1];switch(o){case 1:a+=l.length;break;case-1:s+=l.length;break;case 0:r+=Math.max(a,s),a=0,s=0}}return r+=Math.max(a,s)},e.prototype.diff_toDelta=function(n){for(var r=[],a=0;a<n.length;a++)switch(n[a][0]){case 1:r[a]="+"+encodeURI(n[a][1]);break;case-1:r[a]="-"+n[a][1].length;break;case 0:r[a]="="+n[a][1].length}return r.join(" ").replace(/%20/g," ")},e.prototype.diff_fromDelta=function(n,r){for(var a=[],s=0,i=0,o=r.split(/\t/g),l=0;l<o.length;l++){var u=o[l].substring(1);switch(o[l].charAt(0)){case"+":try{a[s++]=new e.Diff(1,decodeURI(u))}catch{throw new Error("Illegal escape in diff_fromDelta: "+u)}break;case"-":case"=":var c=parseInt(u,10);if(isNaN(c)||c<0)throw new Error("Invalid number in diff_fromDelta: "+u);var d=n.substring(i,i+=c);o[l].charAt(0)=="="?a[s++]=new e.Diff(0,d):a[s++]=new e.Diff(-1,d);break;default:if(o[l])throw new Error("Invalid diff operation in diff_fromDelta: "+o[l])}}if(i!=n.length)throw new Error("Delta length ("+i+") does not equal source text length ("+n.length+").");return a},e.prototype.match_main=function(n,r,a){if(n==null||r==null||a==null)throw new Error("Null input. (match_main)");return a=Math.max(0,Math.min(a,n.length)),n==r?0:n.length?n.substring(a,a+r.length)==r?a:this.match_bitap_(n,r,a):-1},e.prototype.match_bitap_=function(n,r,a){if(r.length>this.Match_MaxBits)throw new Error("Pattern too long for this browser.");var s=this.match_alphabet_(r),i=this;function o(P,w){var k=P/r.length,_=Math.abs(a-w);return i.Match_Distance?k+_/i.Match_Distance:_?1:k}var l=this.Match_Threshold,u=n.indexOf(r,a);u!=-1&&(l=Math.min(o(0,u),l),(u=n.lastIndexOf(r,a+r.length))!=-1&&(l=Math.min(o(0,u),l)));var c,d,f=1<<r.length-1;u=-1;for(var h,p=r.length+n.length,g=0;g<r.length;g++){for(c=0,d=p;c<d;)o(g,a+d)<=l?c=d:p=d,d=Math.floor((p-c)/2+c);p=d;var m=Math.max(1,a-d+1),x=Math.min(a+d,n.length)+r.length,y=Array(x+2);y[x+1]=(1<<g)-1;for(var b=x;b>=m;b--){var C=s[n.charAt(b-1)];if(y[b]=g===0?(y[b+1]<<1|1)&C:(y[b+1]<<1|1)&C|(h[b+1]|h[b])<<1|1|h[b+1],y[b]&f){var L=o(g,b-1);if(L<=l){if(l=L,!((u=b-1)>a))break;m=Math.max(1,2*a-u)}}}if(o(g+1,a)>l)break;h=y}return u},e.prototype.match_alphabet_=function(n){for(var r={},a=0;a<n.length;a++)r[n.charAt(a)]=0;for(a=0;a<n.length;a++)r[n.charAt(a)]|=1<<n.length-a-1;return r},e.prototype.patch_addContext_=function(n,r){if(r.length!=0){if(n.start2===null)throw Error("patch not initialized");for(var a=r.substring(n.start2,n.start2+n.length1),s=0;r.indexOf(a)!=r.lastIndexOf(a)&&a.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)s+=this.Patch_Margin,a=r.substring(n.start2-s,n.start2+n.length1+s);s+=this.Patch_Margin;var i=r.substring(n.start2-s,n.start2);i&&n.diffs.unshift(new e.Diff(0,i));var o=r.substring(n.start2+n.length1,n.start2+n.length1+s);o&&n.diffs.push(new e.Diff(0,o)),n.start1-=i.length,n.start2-=i.length,n.length1+=i.length+o.length,n.length2+=i.length+o.length}},e.prototype.patch_make=function(n,r,a){var s,i;if(typeof n=="string"&&typeof r=="string"&&a===void 0)s=n,(i=this.diff_main(s,r,!0)).length>2&&(this.diff_cleanupSemantic(i),this.diff_cleanupEfficiency(i));else if(n&&typeof n=="object"&&r===void 0&&a===void 0)i=n,s=this.diff_text1(i);else if(typeof n=="string"&&r&&typeof r=="object"&&a===void 0)s=n,i=r;else{if(typeof n!="string"||typeof r!="string"||!a||typeof a!="object")throw new Error("Unknown call format to patch_make.");s=n,i=a}if(i.length===0)return[];for(var o=[],l=new e.patch_obj,u=0,c=0,d=0,f=s,h=s,p=0;p<i.length;p++){var g=i[p][0],m=i[p][1];switch(u||g===0||(l.start1=c,l.start2=d),g){case 1:l.diffs[u++]=i[p],l.length2+=m.length,h=h.substring(0,d)+m+h.substring(d);break;case-1:l.length1+=m.length,l.diffs[u++]=i[p],h=h.substring(0,d)+h.substring(d+m.length);break;case 0:m.length<=2*this.Patch_Margin&&u&&i.length!=p+1?(l.diffs[u++]=i[p],l.length1+=m.length,l.length2+=m.length):m.length>=2*this.Patch_Margin&&u&&(this.patch_addContext_(l,f),o.push(l),l=new e.patch_obj,u=0,f=h,c=d)}g!==1&&(c+=m.length),g!==-1&&(d+=m.length)}return u&&(this.patch_addContext_(l,f),o.push(l)),o},e.prototype.patch_deepCopy=function(n){for(var r=[],a=0;a<n.length;a++){var s=n[a],i=new e.patch_obj;i.diffs=[];for(var o=0;o<s.diffs.length;o++)i.diffs[o]=new e.Diff(s.diffs[o][0],s.diffs[o][1]);i.start1=s.start1,i.start2=s.start2,i.length1=s.length1,i.length2=s.length2,r[a]=i}return r},e.prototype.patch_apply=function(n,r){if(n.length==0)return[r,[]];n=this.patch_deepCopy(n);var a=this.patch_addPadding(n);r=a+r+a,this.patch_splitMax(n);for(var s=0,i=[],o=0;o<n.length;o++){var l,u,c=n[o].start2+s,d=this.diff_text1(n[o].diffs),f=-1;if(d.length>this.Match_MaxBits?(l=this.match_main(r,d.substring(0,this.Match_MaxBits),c))!=-1&&((f=this.match_main(r,d.substring(d.length-this.Match_MaxBits),c+d.length-this.Match_MaxBits))==-1||l>=f)&&(l=-1):l=this.match_main(r,d,c),l==-1)i[o]=!1,s-=n[o].length2-n[o].length1;else if(i[o]=!0,s=l-c,d==(u=f==-1?r.substring(l,l+d.length):r.substring(l,f+this.Match_MaxBits)))r=r.substring(0,l)+this.diff_text2(n[o].diffs)+r.substring(l+d.length);else{var h=this.diff_main(d,u,!1);if(d.length>this.Match_MaxBits&&this.diff_levenshtein(h)/d.length>this.Patch_DeleteThreshold)i[o]=!1;else{this.diff_cleanupSemanticLossless(h);for(var p,g=0,m=0;m<n[o].diffs.length;m++){var x=n[o].diffs[m];x[0]!==0&&(p=this.diff_xIndex(h,g)),x[0]===1?r=r.substring(0,l+p)+x[1]+r.substring(l+p):x[0]===-1&&(r=r.substring(0,l+p)+r.substring(l+this.diff_xIndex(h,g+x[1].length))),x[0]!==-1&&(g+=x[1].length)}}}}return[r=r.substring(a.length,r.length-a.length),i]},e.prototype.patch_addPadding=function(n){for(var r=this.Patch_Margin,a="",s=1;s<=r;s++)a+=String.fromCharCode(s);for(s=0;s<n.length;s++)n[s].start1+=r,n[s].start2+=r;var i=n[0],o=i.diffs;if(o.length==0||o[0][0]!=0)o.unshift(new e.Diff(0,a)),i.start1-=r,i.start2-=r,i.length1+=r,i.length2+=r;else if(r>o[0][1].length){var l=r-o[0][1].length;o[0][1]=a.substring(o[0][1].length)+o[0][1],i.start1-=l,i.start2-=l,i.length1+=l,i.length2+=l}return(o=(i=n[n.length-1]).diffs).length==0||o[o.length-1][0]!=0?(o.push(new e.Diff(0,a)),i.length1+=r,i.length2+=r):r>o[o.length-1][1].length&&(l=r-o[o.length-1][1].length,o[o.length-1][1]+=a.substring(0,l),i.length1+=l,i.length2+=l),a},e.prototype.patch_splitMax=function(n){for(var r=this.Match_MaxBits,a=0;a<n.length;a++)if(!(n[a].length1<=r)){var s=n[a];n.splice(a--,1);for(var i=s.start1,o=s.start2,l="";s.diffs.length!==0;){var u=new e.patch_obj,c=!0;for(u.start1=i-l.length,u.start2=o-l.length,l!==""&&(u.length1=u.length2=l.length,u.diffs.push(new e.Diff(0,l)));s.diffs.length!==0&&u.length1<r-this.Patch_Margin;){var d=s.diffs[0][0],f=s.diffs[0][1];d===1?(u.length2+=f.length,o+=f.length,u.diffs.push(s.diffs.shift()),c=!1):d===-1&&u.diffs.length==1&&u.diffs[0][0]==0&&f.length>2*r?(u.length1+=f.length,i+=f.length,c=!1,u.diffs.push(new e.Diff(d,f)),s.diffs.shift()):(f=f.substring(0,r-u.length1-this.Patch_Margin),u.length1+=f.length,i+=f.length,d===0?(u.length2+=f.length,o+=f.length):c=!1,u.diffs.push(new e.Diff(d,f)),f==s.diffs[0][1]?s.diffs.shift():s.diffs[0][1]=s.diffs[0][1].substring(f.length))}l=(l=this.diff_text2(u.diffs)).substring(l.length-this.Patch_Margin);var h=this.diff_text1(s.diffs).substring(0,this.Patch_Margin);h!==""&&(u.length1+=h.length,u.length2+=h.length,u.diffs.length!==0&&u.diffs[u.diffs.length-1][0]===0?u.diffs[u.diffs.length-1][1]+=h:u.diffs.push(new e.Diff(0,h))),c||n.splice(++a,0,u)}}},e.prototype.patch_toText=function(n){for(var r=[],a=0;a<n.length;a++)r[a]=n[a];return r.join("")},e.prototype.patch_fromText=function(n){var r=[];if(!n)return r;for(var a=n.split(`
|
|
18
|
+
`).map((function(c){return qN(l,Ht(Ht({},u),{},{value:c}))})):[l]})(n),s=ZA(a),i=s[0],o=s.slice(1);return[].concat(Hr(e.slice(0,-1)),[[].concat(Hr(r),[i])],Hr(o.map((function(l){return[l]}))))}),[[]])}function dw(t){return XN(Yw(t))}var YN=function(t,e,n){var r=(n=typeof n=="function"?n:void 0)?n(t,e):void 0;return r===void 0?td(t,e,void 0,n):!!r},JN=function(t,e){return td(t,e)},ZN=function(t){var e=t==null?0:t.length;return e?t[e-1]:void 0};function QN(t,e){if(!t.children)throw new Error("parent node missing children property");var n,r,a=ZN(t.children);return a&&(r=e,(n=a).type===r.type&&(n.type==="text"||n.children&&r.children&&YN(n,r,(function(s,i,o){return o==="chlidren"||JN(s,i)}))))?t.children[t.children.length-1]=(function(s,i){return"value"in s&&"value"in i?Ht(Ht({},s),{},{value:"".concat(s.value).concat(i.value)}):s})(a,e):t.children.push(e),t.children[t.children.length-1]}function fw(t){var e,n={type:"root",children:[]},r=ep(t);try{var a=function(){var s=e.value;s.reduce((function(i,o,l){return QN(i,l===s.length-1?Ht({},o):Ht(Ht({},o),{},{children:[]}))}),n)};for(r.s();!(e=r.n()).done;)a()}catch(s){r.e(s)}finally{r.f()}return n}var eM=Object.prototype.hasOwnProperty,kz=Kw((function(t,e,n){eM.call(t,n)?t[n].push(e):up(t,n,[e])}));var dp=gu((function(t){var e=function(){this.Diff_Timeout=1,this.Diff_EditCost=4,this.Match_Threshold=.5,this.Match_Distance=1e3,this.Patch_DeleteThreshold=.5,this.Patch_Margin=4,this.Match_MaxBits=32};e.Diff=function(n,r){return[n,r]},e.prototype.diff_main=function(n,r,a,s){s===void 0&&(s=this.Diff_Timeout<=0?Number.MAX_VALUE:new Date().getTime()+1e3*this.Diff_Timeout);var i=s;if(n==null||r==null)throw new Error("Null input. (diff_main)");if(n==r)return n?[new e.Diff(0,n)]:[];a===void 0&&(a=!0);var o=a,l=this.diff_commonPrefix(n,r),u=n.substring(0,l);n=n.substring(l),r=r.substring(l),l=this.diff_commonSuffix(n,r);var c=n.substring(n.length-l);n=n.substring(0,n.length-l),r=r.substring(0,r.length-l);var d=this.diff_compute_(n,r,o,i);return u&&d.unshift(new e.Diff(0,u)),c&&d.push(new e.Diff(0,c)),this.diff_cleanupMerge(d),d},e.prototype.diff_compute_=function(n,r,a,s){var i;if(!n)return[new e.Diff(1,r)];if(!r)return[new e.Diff(-1,n)];var o=n.length>r.length?n:r,l=n.length>r.length?r:n,u=o.indexOf(l);if(u!=-1)return i=[new e.Diff(1,o.substring(0,u)),new e.Diff(0,l),new e.Diff(1,o.substring(u+l.length))],n.length>r.length&&(i[0][0]=i[2][0]=-1),i;if(l.length==1)return[new e.Diff(-1,n),new e.Diff(1,r)];var c=this.diff_halfMatch_(n,r);if(c){var d=c[0],f=c[1],h=c[2],p=c[3],g=c[4],m=this.diff_main(d,h,a,s),x=this.diff_main(f,p,a,s);return m.concat([new e.Diff(0,g)],x)}return a&&n.length>100&&r.length>100?this.diff_lineMode_(n,r,s):this.diff_bisect_(n,r,s)},e.prototype.diff_lineMode_=function(n,r,a){var s=this.diff_linesToChars_(n,r);n=s.chars1,r=s.chars2;var i=s.lineArray,o=this.diff_main(n,r,!1,a);this.diff_charsToLines_(o,i),this.diff_cleanupSemantic(o),o.push(new e.Diff(0,""));for(var l=0,u=0,c=0,d="",f="";l<o.length;){switch(o[l][0]){case 1:c++,f+=o[l][1];break;case-1:u++,d+=o[l][1];break;case 0:if(u>=1&&c>=1){o.splice(l-u-c,u+c),l=l-u-c;for(var h=this.diff_main(d,f,!1,a),p=h.length-1;p>=0;p--)o.splice(l,0,h[p]);l+=h.length}c=0,u=0,d="",f=""}l++}return o.pop(),o},e.prototype.diff_bisect_=function(n,r,a){for(var s=n.length,i=r.length,o=Math.ceil((s+i)/2),l=o,u=2*o,c=new Array(u),d=new Array(u),f=0;f<u;f++)c[f]=-1,d[f]=-1;c[l+1]=0,d[l+1]=0;for(var h=s-i,p=h%2!=0,g=0,m=0,x=0,b=0,y=0;y<o&&!(new Date().getTime()>a);y++){for(var C=-y+g;C<=y-m;C+=2){for(var I=l+C,L=(P=C==-y||C!=y&&c[I-1]<c[I+1]?c[I+1]:c[I-1]+1)-C;P<s&&L<i&&n.charAt(P)==r.charAt(L);)P++,L++;if(c[I]=P,P>s)m+=2;else if(L>i)g+=2;else if(p&&(O=l+h-C)>=0&&O<u&&d[O]!=-1&&P>=(k=s-d[O]))return this.diff_bisectSplit_(n,r,P,L,a)}for(var v=-y+x;v<=y-b;v+=2){for(var k,O=l+v,R=(k=v==-y||v!=y&&d[O-1]<d[O+1]?d[O+1]:d[O-1]+1)-v;k<s&&R<i&&n.charAt(s-k-1)==r.charAt(i-R-1);)k++,R++;if(d[O]=k,k>s)b+=2;else if(R>i)x+=2;else if(!p&&(I=l+h-v)>=0&&I<u&&c[I]!=-1){var P;if(L=l+(P=c[I])-I,P>=(k=s-k))return this.diff_bisectSplit_(n,r,P,L,a)}}}return[new e.Diff(-1,n),new e.Diff(1,r)]},e.prototype.diff_bisectSplit_=function(n,r,a,s,i){var o=n.substring(0,a),l=r.substring(0,s),u=n.substring(a),c=r.substring(s),d=this.diff_main(o,l,!1,i),f=this.diff_main(u,c,!1,i);return d.concat(f)},e.prototype.diff_linesToChars_=function(n,r){var a=[],s={};function i(u){for(var c="",d=0,f=-1,h=a.length;f<u.length-1;){(f=u.indexOf(`
|
|
19
|
+
`,d))==-1&&(f=u.length-1);var p=u.substring(d,f+1);(s.hasOwnProperty?s.hasOwnProperty(p):s[p]!==void 0)?c+=String.fromCharCode(s[p]):(h==o&&(p=u.substring(d),f=u.length),c+=String.fromCharCode(h),s[p]=h,a[h++]=p),d=f+1}return c}a[0]="";var o=4e4,l=i(n);return o=65535,{chars1:l,chars2:i(r),lineArray:a}},e.prototype.diff_charsToLines_=function(n,r){for(var a=0;a<n.length;a++){for(var s=n[a][1],i=[],o=0;o<s.length;o++)i[o]=r[s.charCodeAt(o)];n[a][1]=i.join("")}},e.prototype.diff_commonPrefix=function(n,r){if(!n||!r||n.charAt(0)!=r.charAt(0))return 0;for(var a=0,s=Math.min(n.length,r.length),i=s,o=0;a<i;)n.substring(o,i)==r.substring(o,i)?o=a=i:s=i,i=Math.floor((s-a)/2+a);return i},e.prototype.diff_commonSuffix=function(n,r){if(!n||!r||n.charAt(n.length-1)!=r.charAt(r.length-1))return 0;for(var a=0,s=Math.min(n.length,r.length),i=s,o=0;a<i;)n.substring(n.length-i,n.length-o)==r.substring(r.length-i,r.length-o)?o=a=i:s=i,i=Math.floor((s-a)/2+a);return i},e.prototype.diff_commonOverlap_=function(n,r){var a=n.length,s=r.length;if(a==0||s==0)return 0;a>s?n=n.substring(a-s):a<s&&(r=r.substring(0,a));var i=Math.min(a,s);if(n==r)return i;for(var o=0,l=1;;){var u=n.substring(i-l),c=r.indexOf(u);if(c==-1)return o;l+=c,c!=0&&n.substring(i-l)!=r.substring(0,l)||(o=l,l++)}},e.prototype.diff_halfMatch_=function(n,r){if(this.Diff_Timeout<=0)return null;var a=n.length>r.length?n:r,s=n.length>r.length?r:n;if(a.length<4||2*s.length<a.length)return null;var i=this;function o(g,m,x){for(var b,y,C,I,L=g.substring(x,x+Math.floor(g.length/4)),v=-1,k="";(v=m.indexOf(L,v+1))!=-1;){var O=i.diff_commonPrefix(g.substring(x),m.substring(v)),R=i.diff_commonSuffix(g.substring(0,x),m.substring(0,v));k.length<R+O&&(k=m.substring(v-R,v)+m.substring(v,v+O),b=g.substring(0,x-R),y=g.substring(x+O),C=m.substring(0,v-R),I=m.substring(v+O))}return 2*k.length>=g.length?[b,y,C,I,k]:null}var l,u,c,d,f,h=o(a,s,Math.ceil(a.length/4)),p=o(a,s,Math.ceil(a.length/2));return h||p?(l=p?h&&h[4].length>p[4].length?h:p:h,n.length>r.length?(u=l[0],c=l[1],d=l[2],f=l[3]):(d=l[0],f=l[1],u=l[2],c=l[3]),[u,c,d,f,l[4]]):null},e.prototype.diff_cleanupSemantic=function(n){for(var r=!1,a=[],s=0,i=null,o=0,l=0,u=0,c=0,d=0;o<n.length;)n[o][0]==0?(a[s++]=o,l=c,u=d,c=0,d=0,i=n[o][1]):(n[o][0]==1?c+=n[o][1].length:d+=n[o][1].length,i&&i.length<=Math.max(l,u)&&i.length<=Math.max(c,d)&&(n.splice(a[s-1],0,new e.Diff(-1,i)),n[a[s-1]+1][0]=1,s--,o=--s>0?a[s-1]:-1,l=0,u=0,c=0,d=0,i=null,r=!0)),o++;for(r&&this.diff_cleanupMerge(n),this.diff_cleanupSemanticLossless(n),o=1;o<n.length;){if(n[o-1][0]==-1&&n[o][0]==1){var f=n[o-1][1],h=n[o][1],p=this.diff_commonOverlap_(f,h),g=this.diff_commonOverlap_(h,f);p>=g?(p>=f.length/2||p>=h.length/2)&&(n.splice(o,0,new e.Diff(0,h.substring(0,p))),n[o-1][1]=f.substring(0,f.length-p),n[o+1][1]=h.substring(p),o++):(g>=f.length/2||g>=h.length/2)&&(n.splice(o,0,new e.Diff(0,f.substring(0,g))),n[o-1][0]=1,n[o-1][1]=h.substring(0,h.length-g),n[o+1][0]=-1,n[o+1][1]=f.substring(g),o++),o++}o++}},e.prototype.diff_cleanupSemanticLossless=function(n){function r(g,m){if(!g||!m)return 6;var x=g.charAt(g.length-1),b=m.charAt(0),y=x.match(e.nonAlphaNumericRegex_),C=b.match(e.nonAlphaNumericRegex_),I=y&&x.match(e.whitespaceRegex_),L=C&&b.match(e.whitespaceRegex_),v=I&&x.match(e.linebreakRegex_),k=L&&b.match(e.linebreakRegex_),O=v&&g.match(e.blanklineEndRegex_),R=k&&m.match(e.blanklineStartRegex_);return O||R?5:v||k?4:y&&!I&&L?3:I||L?2:y||C?1:0}for(var a=1;a<n.length-1;){if(n[a-1][0]==0&&n[a+1][0]==0){var s=n[a-1][1],i=n[a][1],o=n[a+1][1],l=this.diff_commonSuffix(s,i);if(l){var u=i.substring(i.length-l);s=s.substring(0,s.length-l),i=u+i.substring(0,i.length-l),o=u+o}for(var c=s,d=i,f=o,h=r(s,i)+r(i,o);i.charAt(0)===o.charAt(0);){s+=i.charAt(0),i=i.substring(1)+o.charAt(0),o=o.substring(1);var p=r(s,i)+r(i,o);p>=h&&(h=p,c=s,d=i,f=o)}n[a-1][1]!=c&&(c?n[a-1][1]=c:(n.splice(a-1,1),a--),n[a][1]=d,f?n[a+1][1]=f:(n.splice(a+1,1),a--))}a++}},e.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/,e.whitespaceRegex_=/\s/,e.linebreakRegex_=/[\r\n]/,e.blanklineEndRegex_=/\n\r?\n$/,e.blanklineStartRegex_=/^\r?\n\r?\n/,e.prototype.diff_cleanupEfficiency=function(n){for(var r=!1,a=[],s=0,i=null,o=0,l=!1,u=!1,c=!1,d=!1;o<n.length;)n[o][0]==0?(n[o][1].length<this.Diff_EditCost&&(c||d)?(a[s++]=o,l=c,u=d,i=n[o][1]):(s=0,i=null),c=d=!1):(n[o][0]==-1?d=!0:c=!0,i&&(l&&u&&c&&d||i.length<this.Diff_EditCost/2&&l+u+c+d==3)&&(n.splice(a[s-1],0,new e.Diff(-1,i)),n[a[s-1]+1][0]=1,s--,i=null,l&&u?(c=d=!0,s=0):(o=--s>0?a[s-1]:-1,c=d=!1),r=!0)),o++;r&&this.diff_cleanupMerge(n)},e.prototype.diff_cleanupMerge=function(n){n.push(new e.Diff(0,""));for(var r,a=0,s=0,i=0,o="",l="";a<n.length;)switch(n[a][0]){case 1:i++,l+=n[a][1],a++;break;case-1:s++,o+=n[a][1],a++;break;case 0:s+i>1?(s!==0&&i!==0&&((r=this.diff_commonPrefix(l,o))!==0&&(a-s-i>0&&n[a-s-i-1][0]==0?n[a-s-i-1][1]+=l.substring(0,r):(n.splice(0,0,new e.Diff(0,l.substring(0,r))),a++),l=l.substring(r),o=o.substring(r)),(r=this.diff_commonSuffix(l,o))!==0&&(n[a][1]=l.substring(l.length-r)+n[a][1],l=l.substring(0,l.length-r),o=o.substring(0,o.length-r))),a-=s+i,n.splice(a,s+i),o.length&&(n.splice(a,0,new e.Diff(-1,o)),a++),l.length&&(n.splice(a,0,new e.Diff(1,l)),a++),a++):a!==0&&n[a-1][0]==0?(n[a-1][1]+=n[a][1],n.splice(a,1)):a++,i=0,s=0,o="",l=""}n[n.length-1][1]===""&&n.pop();var u=!1;for(a=1;a<n.length-1;)n[a-1][0]==0&&n[a+1][0]==0&&(n[a][1].substring(n[a][1].length-n[a-1][1].length)==n[a-1][1]?(n[a][1]=n[a-1][1]+n[a][1].substring(0,n[a][1].length-n[a-1][1].length),n[a+1][1]=n[a-1][1]+n[a+1][1],n.splice(a-1,1),u=!0):n[a][1].substring(0,n[a+1][1].length)==n[a+1][1]&&(n[a-1][1]+=n[a+1][1],n[a][1]=n[a][1].substring(n[a+1][1].length)+n[a+1][1],n.splice(a+1,1),u=!0)),a++;u&&this.diff_cleanupMerge(n)},e.prototype.diff_xIndex=function(n,r){var a,s=0,i=0,o=0,l=0;for(a=0;a<n.length&&(n[a][0]!==1&&(s+=n[a][1].length),n[a][0]!==-1&&(i+=n[a][1].length),!(s>r));a++)o=s,l=i;return n.length!=a&&n[a][0]===-1?l:l+(r-o)},e.prototype.diff_prettyHtml=function(n){for(var r=[],a=/&/g,s=/</g,i=/>/g,o=/\n/g,l=0;l<n.length;l++){var u=n[l][0],c=n[l][1].replace(a,"&").replace(s,"<").replace(i,">").replace(o,"¶<br>");switch(u){case 1:r[l]='<ins style="background:#e6ffe6;">'+c+"</ins>";break;case-1:r[l]='<del style="background:#ffe6e6;">'+c+"</del>";break;case 0:r[l]="<span>"+c+"</span>"}}return r.join("")},e.prototype.diff_text1=function(n){for(var r=[],a=0;a<n.length;a++)n[a][0]!==1&&(r[a]=n[a][1]);return r.join("")},e.prototype.diff_text2=function(n){for(var r=[],a=0;a<n.length;a++)n[a][0]!==-1&&(r[a]=n[a][1]);return r.join("")},e.prototype.diff_levenshtein=function(n){for(var r=0,a=0,s=0,i=0;i<n.length;i++){var o=n[i][0],l=n[i][1];switch(o){case 1:a+=l.length;break;case-1:s+=l.length;break;case 0:r+=Math.max(a,s),a=0,s=0}}return r+=Math.max(a,s)},e.prototype.diff_toDelta=function(n){for(var r=[],a=0;a<n.length;a++)switch(n[a][0]){case 1:r[a]="+"+encodeURI(n[a][1]);break;case-1:r[a]="-"+n[a][1].length;break;case 0:r[a]="="+n[a][1].length}return r.join(" ").replace(/%20/g," ")},e.prototype.diff_fromDelta=function(n,r){for(var a=[],s=0,i=0,o=r.split(/\t/g),l=0;l<o.length;l++){var u=o[l].substring(1);switch(o[l].charAt(0)){case"+":try{a[s++]=new e.Diff(1,decodeURI(u))}catch{throw new Error("Illegal escape in diff_fromDelta: "+u)}break;case"-":case"=":var c=parseInt(u,10);if(isNaN(c)||c<0)throw new Error("Invalid number in diff_fromDelta: "+u);var d=n.substring(i,i+=c);o[l].charAt(0)=="="?a[s++]=new e.Diff(0,d):a[s++]=new e.Diff(-1,d);break;default:if(o[l])throw new Error("Invalid diff operation in diff_fromDelta: "+o[l])}}if(i!=n.length)throw new Error("Delta length ("+i+") does not equal source text length ("+n.length+").");return a},e.prototype.match_main=function(n,r,a){if(n==null||r==null||a==null)throw new Error("Null input. (match_main)");return a=Math.max(0,Math.min(a,n.length)),n==r?0:n.length?n.substring(a,a+r.length)==r?a:this.match_bitap_(n,r,a):-1},e.prototype.match_bitap_=function(n,r,a){if(r.length>this.Match_MaxBits)throw new Error("Pattern too long for this browser.");var s=this.match_alphabet_(r),i=this;function o(L,v){var k=L/r.length,O=Math.abs(a-v);return i.Match_Distance?k+O/i.Match_Distance:O?1:k}var l=this.Match_Threshold,u=n.indexOf(r,a);u!=-1&&(l=Math.min(o(0,u),l),(u=n.lastIndexOf(r,a+r.length))!=-1&&(l=Math.min(o(0,u),l)));var c,d,f=1<<r.length-1;u=-1;for(var h,p=r.length+n.length,g=0;g<r.length;g++){for(c=0,d=p;c<d;)o(g,a+d)<=l?c=d:p=d,d=Math.floor((p-c)/2+c);p=d;var m=Math.max(1,a-d+1),x=Math.min(a+d,n.length)+r.length,b=Array(x+2);b[x+1]=(1<<g)-1;for(var y=x;y>=m;y--){var C=s[n.charAt(y-1)];if(b[y]=g===0?(b[y+1]<<1|1)&C:(b[y+1]<<1|1)&C|(h[y+1]|h[y])<<1|1|h[y+1],b[y]&f){var I=o(g,y-1);if(I<=l){if(l=I,!((u=y-1)>a))break;m=Math.max(1,2*a-u)}}}if(o(g+1,a)>l)break;h=b}return u},e.prototype.match_alphabet_=function(n){for(var r={},a=0;a<n.length;a++)r[n.charAt(a)]=0;for(a=0;a<n.length;a++)r[n.charAt(a)]|=1<<n.length-a-1;return r},e.prototype.patch_addContext_=function(n,r){if(r.length!=0){if(n.start2===null)throw Error("patch not initialized");for(var a=r.substring(n.start2,n.start2+n.length1),s=0;r.indexOf(a)!=r.lastIndexOf(a)&&a.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)s+=this.Patch_Margin,a=r.substring(n.start2-s,n.start2+n.length1+s);s+=this.Patch_Margin;var i=r.substring(n.start2-s,n.start2);i&&n.diffs.unshift(new e.Diff(0,i));var o=r.substring(n.start2+n.length1,n.start2+n.length1+s);o&&n.diffs.push(new e.Diff(0,o)),n.start1-=i.length,n.start2-=i.length,n.length1+=i.length+o.length,n.length2+=i.length+o.length}},e.prototype.patch_make=function(n,r,a){var s,i;if(typeof n=="string"&&typeof r=="string"&&a===void 0)s=n,(i=this.diff_main(s,r,!0)).length>2&&(this.diff_cleanupSemantic(i),this.diff_cleanupEfficiency(i));else if(n&&typeof n=="object"&&r===void 0&&a===void 0)i=n,s=this.diff_text1(i);else if(typeof n=="string"&&r&&typeof r=="object"&&a===void 0)s=n,i=r;else{if(typeof n!="string"||typeof r!="string"||!a||typeof a!="object")throw new Error("Unknown call format to patch_make.");s=n,i=a}if(i.length===0)return[];for(var o=[],l=new e.patch_obj,u=0,c=0,d=0,f=s,h=s,p=0;p<i.length;p++){var g=i[p][0],m=i[p][1];switch(u||g===0||(l.start1=c,l.start2=d),g){case 1:l.diffs[u++]=i[p],l.length2+=m.length,h=h.substring(0,d)+m+h.substring(d);break;case-1:l.length1+=m.length,l.diffs[u++]=i[p],h=h.substring(0,d)+h.substring(d+m.length);break;case 0:m.length<=2*this.Patch_Margin&&u&&i.length!=p+1?(l.diffs[u++]=i[p],l.length1+=m.length,l.length2+=m.length):m.length>=2*this.Patch_Margin&&u&&(this.patch_addContext_(l,f),o.push(l),l=new e.patch_obj,u=0,f=h,c=d)}g!==1&&(c+=m.length),g!==-1&&(d+=m.length)}return u&&(this.patch_addContext_(l,f),o.push(l)),o},e.prototype.patch_deepCopy=function(n){for(var r=[],a=0;a<n.length;a++){var s=n[a],i=new e.patch_obj;i.diffs=[];for(var o=0;o<s.diffs.length;o++)i.diffs[o]=new e.Diff(s.diffs[o][0],s.diffs[o][1]);i.start1=s.start1,i.start2=s.start2,i.length1=s.length1,i.length2=s.length2,r[a]=i}return r},e.prototype.patch_apply=function(n,r){if(n.length==0)return[r,[]];n=this.patch_deepCopy(n);var a=this.patch_addPadding(n);r=a+r+a,this.patch_splitMax(n);for(var s=0,i=[],o=0;o<n.length;o++){var l,u,c=n[o].start2+s,d=this.diff_text1(n[o].diffs),f=-1;if(d.length>this.Match_MaxBits?(l=this.match_main(r,d.substring(0,this.Match_MaxBits),c))!=-1&&((f=this.match_main(r,d.substring(d.length-this.Match_MaxBits),c+d.length-this.Match_MaxBits))==-1||l>=f)&&(l=-1):l=this.match_main(r,d,c),l==-1)i[o]=!1,s-=n[o].length2-n[o].length1;else if(i[o]=!0,s=l-c,d==(u=f==-1?r.substring(l,l+d.length):r.substring(l,f+this.Match_MaxBits)))r=r.substring(0,l)+this.diff_text2(n[o].diffs)+r.substring(l+d.length);else{var h=this.diff_main(d,u,!1);if(d.length>this.Match_MaxBits&&this.diff_levenshtein(h)/d.length>this.Patch_DeleteThreshold)i[o]=!1;else{this.diff_cleanupSemanticLossless(h);for(var p,g=0,m=0;m<n[o].diffs.length;m++){var x=n[o].diffs[m];x[0]!==0&&(p=this.diff_xIndex(h,g)),x[0]===1?r=r.substring(0,l+p)+x[1]+r.substring(l+p):x[0]===-1&&(r=r.substring(0,l+p)+r.substring(l+this.diff_xIndex(h,g+x[1].length))),x[0]!==-1&&(g+=x[1].length)}}}}return[r=r.substring(a.length,r.length-a.length),i]},e.prototype.patch_addPadding=function(n){for(var r=this.Patch_Margin,a="",s=1;s<=r;s++)a+=String.fromCharCode(s);for(s=0;s<n.length;s++)n[s].start1+=r,n[s].start2+=r;var i=n[0],o=i.diffs;if(o.length==0||o[0][0]!=0)o.unshift(new e.Diff(0,a)),i.start1-=r,i.start2-=r,i.length1+=r,i.length2+=r;else if(r>o[0][1].length){var l=r-o[0][1].length;o[0][1]=a.substring(o[0][1].length)+o[0][1],i.start1-=l,i.start2-=l,i.length1+=l,i.length2+=l}return(o=(i=n[n.length-1]).diffs).length==0||o[o.length-1][0]!=0?(o.push(new e.Diff(0,a)),i.length1+=r,i.length2+=r):r>o[o.length-1][1].length&&(l=r-o[o.length-1][1].length,o[o.length-1][1]+=a.substring(0,l),i.length1+=l,i.length2+=l),a},e.prototype.patch_splitMax=function(n){for(var r=this.Match_MaxBits,a=0;a<n.length;a++)if(!(n[a].length1<=r)){var s=n[a];n.splice(a--,1);for(var i=s.start1,o=s.start2,l="";s.diffs.length!==0;){var u=new e.patch_obj,c=!0;for(u.start1=i-l.length,u.start2=o-l.length,l!==""&&(u.length1=u.length2=l.length,u.diffs.push(new e.Diff(0,l)));s.diffs.length!==0&&u.length1<r-this.Patch_Margin;){var d=s.diffs[0][0],f=s.diffs[0][1];d===1?(u.length2+=f.length,o+=f.length,u.diffs.push(s.diffs.shift()),c=!1):d===-1&&u.diffs.length==1&&u.diffs[0][0]==0&&f.length>2*r?(u.length1+=f.length,i+=f.length,c=!1,u.diffs.push(new e.Diff(d,f)),s.diffs.shift()):(f=f.substring(0,r-u.length1-this.Patch_Margin),u.length1+=f.length,i+=f.length,d===0?(u.length2+=f.length,o+=f.length):c=!1,u.diffs.push(new e.Diff(d,f)),f==s.diffs[0][1]?s.diffs.shift():s.diffs[0][1]=s.diffs[0][1].substring(f.length))}l=(l=this.diff_text2(u.diffs)).substring(l.length-this.Patch_Margin);var h=this.diff_text1(s.diffs).substring(0,this.Patch_Margin);h!==""&&(u.length1+=h.length,u.length2+=h.length,u.diffs.length!==0&&u.diffs[u.diffs.length-1][0]===0?u.diffs[u.diffs.length-1][1]+=h:u.diffs.push(new e.Diff(0,h))),c||n.splice(++a,0,u)}}},e.prototype.patch_toText=function(n){for(var r=[],a=0;a<n.length;a++)r[a]=n[a];return r.join("")},e.prototype.patch_fromText=function(n){var r=[];if(!n)return r;for(var a=n.split(`
|
|
20
20
|
`),s=0,i=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;s<a.length;){var o=a[s].match(i);if(!o)throw new Error("Invalid patch string: "+a[s]);var l=new e.patch_obj;for(r.push(l),l.start1=parseInt(o[1],10),o[2]===""?(l.start1--,l.length1=1):o[2]=="0"?l.length1=0:(l.start1--,l.length1=parseInt(o[2],10)),l.start2=parseInt(o[3],10),o[4]===""?(l.start2--,l.length2=1):o[4]=="0"?l.length2=0:(l.start2--,l.length2=parseInt(o[4],10)),s++;s<a.length;){var u=a[s].charAt(0);try{var c=decodeURI(a[s].substring(1))}catch{throw new Error("Illegal escape in patch_fromText: "+c)}if(u=="-")l.diffs.push(new e.Diff(-1,c));else if(u=="+")l.diffs.push(new e.Diff(1,c));else if(u==" ")l.diffs.push(new e.Diff(0,c));else{if(u=="@")break;if(u!=="")throw new Error('Invalid patch mode "'+u+'" in: '+c)}s++}}return r},(e.patch_obj=function(){this.diffs=[],this.start1=null,this.start2=null,this.length1=0,this.length2=0}).prototype.toString=function(){for(var n,r=["@@ -"+(this.length1===0?this.start1+",0":this.length1==1?this.start1+1:this.start1+1+","+this.length1)+" +"+(this.length2===0?this.start2+",0":this.length2==1?this.start2+1:this.start2+1+","+this.length2)+` @@
|
|
21
21
|
`],a=0;a<this.diffs.length;a++){switch(this.diffs[a][0]){case 1:n="+";break;case-1:n="-";break;case 0:n=" "}r[a+1]=n+encodeURI(this.diffs[a][1])+`
|
|
22
|
-
`}return r.join("").replace(/%20/g," ")},t.exports=e,t.exports.diff_match_patch=e,t.exports.DIFF_DELETE=-1,t.exports.DIFF_INSERT=1,t.exports.DIFF_EQUAL=0})),
|
|
22
|
+
`}return r.join("").replace(/%20/g," ")},t.exports=e,t.exports.diff_match_patch=e,t.exports.DIFF_DELETE=-1,t.exports.DIFF_INSERT=1,t.exports.DIFF_EQUAL=0})),Sz=dp.DIFF_EQUAL,Cz=dp.DIFF_DELETE,Iz=dp.DIFF_INSERT;var tM=["enhancers"],Jw=function(t){var e,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=n.enhancers,a=r===void 0?[]:r,s=mn(jN(t,Ys(n,tM)),2),i=s[0],o=s[1],l=[dw(i),dw(o)],u=(e=[l[0],l[1]],a.reduce((function(g,m){return m(g)}),e)),c=mn(u,2),d=c[0],f=c[1],h=[d.map(fw),f.map(fw)],p=h[1];return{old:h[0].map((function(g){var m;return(m=g.children)!==null&&m!==void 0?m:[]})),new:p.map((function(g){var m;return(m=g.children)!==null&&m!==void 0?m:[]}))}};var hw;var Lz=(hw=0,function(){return hw+=1});var pp=W(fa(),1);function Zw(t){let e=t.split(`
|
|
23
23
|
`),n=[],r=0;for(;r<e.length&&!e[r].startsWith("@@");)n.push(e[r]),r++;let a=[],s=null;for(;r<e.length;r++){let i=e[r];i.startsWith("@@")?(s&&a.push(s.join(`
|
|
24
24
|
`)),s=[i]):s&&s.push(i)}return s&&a.push(s.join(`
|
|
25
25
|
`)),{header:n.join(`
|
|
26
|
-
`),hunks:a}}function
|
|
26
|
+
`),hunks:a}}function Qw(t,e){let n=t.replace(/\n+$/,"");if(!n.trim())return null;let r=`${n}
|
|
27
27
|
${e}`;return r.endsWith(`
|
|
28
28
|
`)?r:`${r}
|
|
29
|
-
`}function
|
|
30
|
-
`);return e.length>1&&e[e.length-1]===""&&e.pop(),e}function
|
|
31
|
-
`})}),a}}}function i1(t,e,n="dark-plus"){let r=So(e);if(r&&td(r))try{return Wv(t,{highlight:!0,refractor:aM(n),language:r})}catch{return}}var o1=(t,e,n)=>{let r=t.color;return t.type==="element"&&typeof r=="string"?(0,s1.createElement)("span",{key:n,style:{color:r}},t.children?.map((a,s)=>e(a,s))):e(t,n)};function rd(t){let e=gt(String(t||"")).toLowerCase().trim();if(!e)return;let n=e;if(n==="dockerfile")return"docker";let r=n.includes(".")?n.split(".").pop():"";if(!r)return;let a={js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",json:"json",jsonl:"json",py:"python",rb:"ruby",php:"php",java:"java",kt:"kotlin",go:"go",rs:"rust",c:"c",h:"c",cpp:"cpp",cc:"cpp",cxx:"cpp",hpp:"cpp",cs:"csharp",swift:"swift",scala:"scala",r:"r",sql:"sql",sh:"bash",bash:"bash",zsh:"bash",fish:"bash",ps1:"powershell",yaml:"yaml",yml:"yaml",toml:"toml",ini:"ini",xml:"xml",html:"html",css:"css",scss:"scss",less:"less",graphql:"graphql",gql:"graphql",lua:"lua",dart:"dart",elm:"elm",tex:"latex",clj:"clojure",ex:"elixir",exs:"elixir",hs:"haskell",nim:"nim",pl:"perl",proto:"protobuf",md:"markdown",mdx:"mdx"};return r==="env"?"bash":a[r]??r}var l1=j(Wn(),1);var ad=j(ie(),1),sM=[{key:"auto",label:"Auto",Icon:Rs},{key:"unified",label:"Unified",Icon:Ns},{key:"split",label:"Split",Icon:ys}];function sd({className:t}){let e=H(r=>r.diffViewMode),n=H(r=>r.setDiffViewMode);return(0,ad.jsx)("div",{className:$("inline-flex items-center gap-0.5 rounded-md bg-white/5 p-0.5",t),children:sM.map(({key:r,label:a,Icon:s})=>(0,ad.jsx)("button",{type:"button",onClick:()=>n(r),className:$("inline-flex items-center justify-center rounded p-1 transition",e===r?"bg-white/12 text-white/90":"text-white/40 hover:text-white/70 hover:bg-white/[0.06]"),title:`Diff layout: ${a}${r==="auto"?" (by width)":""}`,"aria-label":`Diff layout ${a}`,"aria-pressed":e===r,children:(0,ad.jsx)(s,{className:"w-3 h-3"})},r))})}var Xe=j(ie(),1),iM={"--diff-background-color":"transparent","--diff-text-color":"rgba(255,255,255,0.82)","--diff-font-family":"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace","--diff-selection-background-color":"rgba(139,92,246,0.35)","--diff-gutter-insert-background-color":"rgba(16,185,129,0.16)","--diff-gutter-delete-background-color":"rgba(244,63,94,0.16)","--diff-gutter-selected-background-color":"rgba(139,92,246,0.22)","--diff-code-insert-background-color":"rgba(16,185,129,0.10)","--diff-code-delete-background-color":"rgba(244,63,94,0.10)","--diff-code-insert-edit-background-color":"rgba(16,185,129,0.30)","--diff-code-delete-edit-background-color":"rgba(244,63,94,0.32)","--diff-code-selected-background-color":"rgba(139,92,246,0.16)","--diff-omit-gutter-line-color":"transparent"};function np(t,e,n,r){let a=r.kind==="working"?{kind:r.kind,staged:r.staged}:r.kind==="commit"?{kind:r.kind,sha:r.sha}:{kind:r.kind,base:r.base,head:r.head};return`diff\0${t}\0${e}\0${n}\0${JSON.stringify(a)}`}function bi({source:t,repo:e="",path:n,mode:r,agentId:a,projectId:s,variant:i="tab",revision:o=0,canWrite:l=!1,runContent:u,peekContent:c}){let d=H(ee=>ee.client),[f]=(0,ht.useState)(()=>c?.(`${np(t,e,n,r)}\0${o}`,np(t,e,n,r))),[h,p]=(0,ht.useState)(()=>f===void 0?null:f&&f.ok!==!1?f.diff:""),[g,m]=(0,ht.useState)(!1),[x,y]=(0,ht.useState)(null),[b,C]=(0,ht.useState)(()=>f!==void 0&&f.ok!==!1&&f.truncated===!0),[L,P]=(0,ht.useState)(()=>f!==void 0&&f.ok===!1),[w,k]=(0,ht.useState)(0),[_,M]=(0,ht.useState)(null),[R,U]=(0,ht.useState)(null),[v,T]=(0,ht.useState)([]),[V,Y]=(0,ht.useState)(null),[N,A]=(0,ht.useState)(!1),B=(0,ht.useRef)(new Map),K=(0,ht.useRef)(0),te=H(ee=>ee.loadGitStatus),ne=r.kind,pe=r.kind==="working"?r.staged:!1,Se=r.kind==="commit"?r.sha:null,le=r.kind==="range"?r.base:null,re=r.kind==="range"?r.head:null,he=(0,ht.useMemo)(()=>ne==="working"?{kind:ne,staged:pe}:ne==="commit"?{kind:ne,sha:Se??""}:{kind:ne,base:le??"",head:re??""},[ne,pe,Se,le,re]),Ne=(0,ht.useMemo)(()=>Jv(he),[he]),Ee=H(ee=>ee.diffViewMode),ze=(0,ht.useRef)(null),ct=(0,l1.useContainerWidth)(ze),it=Ee==="auto"?ct?"split":"unified":Ee,Qe=(0,ht.useMemo)(()=>rd(n),[n]),[Ye,Lt]=(0,ht.useState)(!1);(0,ht.useEffect)(()=>{let ee=So(Qe);if(!ee){Lt(!1);return}if(td(ee)){Lt(!0);return}let oe=!1;return Lt(!1),au().then(()=>nd(ee)).then(He=>{oe||Lt(He)}),()=>{oe=!0}},[Qe]),(0,ht.useEffect)(()=>{if(B.current.clear(),T([]),Y(null),A(!1),!a||!t||!n){C(!1),P(!1),p(null),y(null),m(!1);return}let ee=++K.current;return m(!0),y(null),(async()=>{try{let oe=()=>lc({agentId:a,...s?{projectId:s}:{},source:t,...e?{repo:e}:{},path:n,...Yv(he)},d),He=np(t,e,n,he),Ve={key:`${He}\0${o}`,family:He,bytes:ce=>ce&&ce.ok!==!1?ce.diff.length*2:64,fresh:w>0},Ae=u?await u(oe,()=>ee===K.current,Ve):await oe();if(!Ae||ee!==K.current)return;Ae&&Ae.ok===!1?(p(""),P(!0),C(!1)):(p(typeof Ae?.diff=="string"?Ae.diff:""),P(!1),C(Ae?.truncated===!0)),m(!1)}catch(oe){if(ee!==K.current)return;y(oe instanceof Error?oe.message:"Diff failed"),p(null),P(!1),C(!1),m(!1)}})(),()=>{K.current++}},[a,s,t,e,n,he,w,o,u]);let{files:Le,truncated:at,hunkPatches:ft}=(0,ht.useMemo)(()=>Vv(h,b),[h,b]),bt=Le.some(ee=>ee.hunks.length>0),At=gt(n)||n,Tt=t1(x),Ue=Le.length===1?Le[0]:null,me=l&&ne==="working"&&!!a&&!!Ue&&Ue.type==="modify"&&!at&&!!ft&&ft.hunks.length===Ue.hunks.length,Ot=!!a&&!!Ue&&!at&&Ue.hunks.length>0,Jt=(0,ht.useCallback)(async()=>{if(!a)return null;let ee=K.current,oe=Ne.type==="worktree"?"wt":Ne.rev,He=`${t}\0${e}\0${n}\0${oe}`,Ve=B.current.get(He),Ae=ce=>(B.current.set(He,ce),ee===K.current&&(ce.ok?Y(ce.content):A(!0)),ce.ok?ce.content:null);if(Ve)return Ae(Ve);try{if(Ne.type==="show"){let Zt=()=>F0({agentId:a,...s?{projectId:s}:{},source:t,...e?{repo:e}:{},path:n,rev:Ne.rev},d),dn=u?await u(Zt,()=>ee===K.current):await Zt();return!dn||ee!==K.current?null:Ae(dn.ok?{ok:!0,content:dn.content}:{ok:!1})}let ce=()=>$i({agentId:a,...s?{projectId:s}:{},files:[`${t}://${e?`${e}/`:""}${n}`]},d),Pt=u?await u(ce,()=>ee===K.current):await ce();if(!Pt||ee!==K.current)return null;let Ft=Yi(Pt)[0];return!Ft||typeof Ft.error=="string"?Ae({ok:!1}):Ae({ok:!0,content:Ji(Ft)})}catch{return Ae({ok:!1})}},[a,s,t,e,n,Ne,u]),ue=(0,ht.useMemo)(()=>Ue&&V!==null?Zc(Ue.hunks,V):null,[Ue,V]),be=(0,ht.useMemo)(()=>Le.map(ee=>ee!==Ue||!ue||v.length===0?ee.hunks:$v(ee.hunks,ue,v)),[Le,Ue,ue,v]),Ge=ue?ue.length:null,Re=(0,ht.useMemo)(()=>Ye?Le.map((ee,oe)=>i1(be[oe]??ee.hunks,Qe)):Le.map(()=>{}),[Le,be,Qe,Ye]),Te=(0,ht.useCallback)(async ee=>{if(!Ot)return;let oe=K.current,He=V??await Jt();if(He===null||oe!==K.current||!Ue)return;let Ve;if(ee.lines===null){let Ae=ru(Ue.hunks[Ue.hunks.length-1]??null,Zc(Ue.hunks,He).length);if(!Ae||Ae.lines===null)return;Ve={start:Ae.start,end:Ae.end}}else Ve={start:ee.start,end:ee.end};T(Ae=>[...Ae,Ve])},[Ot,V,Jt,Ue]),vt=(0,ht.useCallback)(async()=>{if(!Ot||!Ue)return;let ee=K.current,oe=V??await Jt();if(oe===null||ee!==K.current)return;let He=qv(Ue.hunks,Zc(Ue.hunks,oe).length);He.length>0&&T(Ve=>[...Ve,...He])},[Ot,Ue,V,Jt]),mt=(0,ht.useMemo)(()=>{if(!Ot||!Ue)return!1;let ee=Le.indexOf(Ue),oe=be[ee]??Ue.hunks;for(let He=0;He<oe.length;He++)if(Jc(He===0?null:oe[He-1],oe[He]))return!0;return ru(oe[oe.length-1]??null,Ge)!==null},[Ot,Ue,Le,be,Ge]),Gt=(0,ht.useCallback)(async ee=>{if(g||!me||!ft||!a)return;let oe=jv(ft.header,ft.hunks[ee]);if(!oe){U("Could not build a hunk patch for this change.");return}M(ee),U(null);try{pe?await _0({agentId:a,...s?{projectId:s}:{},source:t,...e?{repo:e}:{},hunk:oe},d):await B0({agentId:a,...s?{projectId:s}:{},source:t,...e?{repo:e}:{},hunk:oe},d),B.current.clear(),te({agentId:a,projectId:s}),k(He=>He+1)}catch(He){U(He instanceof Error?He.message:"Hunk apply failed")}finally{M(null)}},[g,me,ft,a,s,t,e,pe,te]),je=ee=>{let oe=ee.lines===null?"Expand to end of file":`${ee.lines} hidden ${ee.lines===1?"line":"lines"}`;return N?ee.lines===null?null:(0,Xe.jsx)(Yc,{children:(0,Xe.jsxs)("div",{className:"px-3 py-0.5 font-mono text-[10px] text-white/30",children:["\u22EF ",oe]})},`gap-${ee.start}`):(0,Xe.jsx)(Yc,{children:(0,Xe.jsxs)("button",{type:"button",onClick:()=>{Te(ee)},className:"block w-full px-3 py-0.5 text-left font-mono text-[10px] text-violet-300/70 transition-colors hover:bg-violet-500/10 hover:text-violet-200/90",title:"Expand this hidden region",children:["\u22EF ",oe]})},`gap-${ee.start}`)},kt=(ee,oe)=>oe.length===0?null:(0,Xe.jsx)(Yc,{children:(0,Xe.jsx)("div",{className:"flex items-center justify-end gap-2 px-2 py-1",children:oe.map(He=>(0,Xe.jsxs)("button",{type:"button",onClick:()=>{Gt(He)},disabled:_!==null||g,className:$("inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-[10px] transition-colors disabled:opacity-40",pe?"border-white/12 bg-white/[0.04] text-white/70 hover:bg-white/[0.09]":"border-emerald-500/25 bg-emerald-500/12 text-emerald-100/90 hover:bg-emerald-500/18"),title:pe?"Unstage this hunk":"Stage this hunk",children:[_===He?(0,Xe.jsx)(rp.LiveSpinner,{className:"h-3 w-3"}):pe?(0,Xe.jsx)(ai,{className:"h-3 w-3"}):(0,Xe.jsx)(Fn,{className:"h-3 w-3"}),pe?"Unstage hunk":"Stage hunk",oe.length>1?(0,Xe.jsxs)("span",{className:"font-mono text-white/45",children:["@",Ue?.hunks[He]?.oldStart]}):null]},He))})},`stage-${ee.oldStart}`),on=(0,Xe.jsxs)("button",{type:"button",onClick:()=>{vt()},className:"inline-flex shrink-0 items-center gap-1 rounded-md border border-white/10 px-1.5 py-0.5 text-[10px] text-white/55 transition-colors hover:bg-white/[0.06] hover:text-white/80",title:"Expand all hidden regions",children:[(0,Xe.jsx)(Wl,{className:"h-3 w-3"}),"Expand all"]}),Oe=x?Tt?(0,Xe.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,Xe.jsx)(ri,{className:"h-3.5 w-3.5 shrink-0 text-white/35"}),(0,Xe.jsx)("span",{children:"You don't have permission to view this file's changes."})]}):(0,Xe.jsx)("div",{className:"px-3 py-4 text-[11px] text-rose-300/70",children:x}):g&&!h?(0,Xe.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,Xe.jsx)(rp.LiveSpinner,{className:"h-3.5 w-3.5"}),"Loading diff\u2026"]}):L?(0,Xe.jsxs)("div",{className:"flex items-center justify-center gap-1.5 px-3 py-6 text-center text-[11px] text-amber-200/70",children:[(0,Xe.jsx)(ot,{className:"h-3.5 w-3.5 shrink-0"}),(0,Xe.jsx)("span",{children:"Diff too large to display \u2014 the change exceeds the server output bound."})]}):bt?(0,Xe.jsx)("div",{style:iM,className:$("nrs-git-diff px-1 py-1 text-[12px] leading-[18px]"),children:Le.map((ee,oe)=>{let He=ee===Ue&&Ot;return(0,Xe.jsx)(Bv,{viewType:it,diffType:ee.type,hunks:be[oe]??ee.hunks,tokens:Re[oe],renderToken:o1,children:Ve=>{let Ae=[],ce=Pt=>{Pt&&Ae.push(Pt)};if(Ve.forEach((Pt,Ft)=>{if(He){let Zt=Jc(Ft===0?null:Ve[Ft-1],Pt);Zt&&ce(je(Zt))}me&&ee===Ue&&ce(kt(Pt,Kv(Pt,ee.hunks))),Ae.push((0,Xe.jsx)(Qh,{hunk:Pt},`h-${Pt.oldStart}-${Pt.oldLines}`))}),He){let Pt=ru(Ve[Ve.length-1]??null,Ge);Pt&&ce(je(Pt))}return Ae}},`${ee.oldRevision??""}-${ee.newRevision??""}-${oe}`)})}):(0,Xe.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:Qv(he)});return(0,Xe.jsxs)("div",{ref:ze,className:$("flex w-full flex-col",i==="tab"&&"h-full min-h-0"),children:[i==="tab"?(0,Xe.jsxs)("div",{className:"flex shrink-0 items-center gap-2 px-3 py-1.5 text-[11px]",style:{borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,Xe.jsx)(or,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),(0,Xe.jsx)("span",{className:"shrink-0 font-medium text-white/85",children:At}),(0,Xe.jsx)("span",{className:"truncate font-mono text-white/40",children:n}),(0,Xe.jsx)("span",{className:"ml-auto shrink-0 rounded-full border border-white/10 px-2 py-0.5 text-[9px] uppercase tracking-wider text-white/45",children:Zv(he)}),(0,Xe.jsx)(sd,{}),mt&&!N?on:null]}):mt&&!N?(0,Xe.jsx)("div",{className:"flex shrink-0 items-center justify-end px-2 pt-1",children:on}):null,at?(0,Xe.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5 px-3 py-1 text-[10px] text-amber-200/70",children:[(0,Xe.jsx)(ot,{className:"h-3 w-3 shrink-0"}),(0,Xe.jsx)("span",{children:"Diff truncated by the server (2 MB cap) \u2014 showing the leading hunks; hunk staging is disabled."})]}):null,R?(0,Xe.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5 px-3 py-1 text-[10px] text-rose-300/75",children:[(0,Xe.jsx)(ot,{className:"h-3 w-3 shrink-0"}),(0,Xe.jsx)("span",{className:"truncate",children:R})]}):null,i==="tab"?(0,Xe.jsx)("div",{className:"min-h-0 flex-1 overflow-auto",children:Oe}):Oe]})}var Je=j(ie(),1),ap={M:"text-amber-400",A:"text-emerald-400",D:"text-rose-400",R:"text-sky-400",C:"text-sky-400",T:"text-white/60"},id={M:"Modified",A:"Added",D:"Deleted",R:"Renamed",C:"Copied",T:"Type changed"};function oM(t){let e=new Date(t);return Number.isNaN(e.getTime())?t:e.toLocaleString()}var lM=(0,ns.memo)(function({file:e,mode:n,source:r,repo:a,agentId:s,projectId:i,defaultExpanded:o,queue:l}){let[u,c]=(0,ns.useState)(o),d=(e.status[0]??"M").toUpperCase(),f=e.path.includes("/")?e.path.slice(0,e.path.lastIndexOf("/")):"",h=e.path.includes("/")?e.path.slice(e.path.lastIndexOf("/")+1):e.path;return(0,Je.jsxs)("div",{ref:p=>l.register(e.path,p),className:"overflow-hidden rounded-lg border border-white/8 bg-black/20",children:[(0,Je.jsxs)("button",{type:"button",onClick:()=>c(p=>!p),className:"flex w-full items-center gap-2 px-2.5 py-1.5 text-left transition-colors hover:bg-white/[0.03]",title:e.path,"aria-expanded":u,children:[u?(0,Je.jsx)(Et,{className:"h-3.5 w-3.5 shrink-0 text-white/40"}):(0,Je.jsx)(un,{className:"h-3.5 w-3.5 shrink-0 text-white/40"}),(0,Je.jsx)("span",{className:$("shrink-0 text-[10px] font-bold leading-none tabular-nums",ap[d]??"text-white/60"),title:id[d]??"Changed","aria-label":`Status: ${id[d]??"Changed"}`,children:d}),(0,Je.jsxs)("span",{className:"min-w-0 flex-1 truncate text-xs text-white/85",children:[h,f?(0,Je.jsxs)("span",{className:"ml-1.5 font-mono text-[10px] text-white/30",children:[f,"/"]}):null]}),e.renamedFrom?(0,Je.jsxs)("span",{className:"shrink-0 truncate font-mono text-[10px] text-white/35",title:`Renamed from ${e.renamedFrom}`,children:["\u2190 ",e.renamedFrom]}):null,(0,Je.jsx)(Aa,{added:e.added,removed:e.removed,binary:e.binary,className:"shrink-0"})]}),u&&l.visible.has(e.path)?(0,Je.jsx)("div",{className:"border-t border-white/5",children:(0,Je.jsx)("div",{className:"max-h-96 overflow-auto",style:{scrollbarGutter:"auto"},children:(0,Je.jsx)(bi,{variant:"card",canWrite:!1,runContent:l.run,source:r,repo:a,path:e.path,mode:n,agentId:s,projectId:i})})}):null]})});function sp({target:t,agentId:e,projectId:n}){let r=H(x=>x.client),[a,s]=(0,ns.useState)(null),i=Pc(a),[o,l]=(0,ns.useState)({phase:"loading"}),[u,c]=(0,ns.useState)(null),{source:d}=t,f=t.repo??"",h=t.kind==="commit"?`c:${f}:${t.sha}`:`o:${f}:${t.base}..${t.head}`;(0,ns.useEffect)(()=>{if(l({phase:"loading"}),c(null),!e||!d)return;let x=!1;return(async()=>{try{if(t.kind==="commit"){let y=await cc({agentId:e,...n?{projectId:n}:{},source:d,...f?{repo:f}:{},sha:t.sha},r);if(x)return;y.ok===!1?l({phase:"unavailable"}):l({phase:"ready",files:y.files,range:null});try{let b=await uc({agentId:e,...n?{projectId:n}:{},source:d,...f?{repo:f}:{},maxCount:1,ref:t.sha},r),C=Array.isArray(b?.commits)?b.commits[0]:void 0;!x&&C&&c({author:C.author,date:C.date})}catch{}}else{let y=await cl({agentId:e,...n?{projectId:n}:{},source:d,...f?{repo:f}:{}},r);if(x)return;!y.ok||!y.baseSha||!y.headSha?l({phase:"no-upstream"}):l({phase:"ready",files:Array.isArray(y.files)?y.files:[],range:{base:y.baseSha,head:y.headSha}})}}catch(y){if(x)return;l({phase:"error",message:y instanceof Error?y.message:"Change-set failed"})}})(),()=>{x=!0}},[e,n,d,h]);let p=t.kind==="commit"?t:null,g=p!==null,m=o.phase==="ready"&&o.range?`${tn(o.range.base)}..${tn(o.range.head)}`:t.kind==="outgoing"?`${tn(t.base)}..${tn(t.head)}`:"";return(0,Je.jsxs)("div",{className:"flex h-full w-full min-h-0 flex-col",children:[(0,Je.jsx)("div",{className:"flex shrink-0 items-center gap-2 px-3 py-1.5 text-[11px]",style:{borderBottom:"1px solid rgba(255,255,255,0.05)"},children:p?(0,Je.jsxs)(Je.Fragment,{children:[(0,Je.jsx)(Dr,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),(0,Je.jsx)("span",{className:"shrink-0 rounded bg-white/[0.06] px-1.5 py-0.5 font-mono text-[10px] text-violet-200/90",children:tn(p.sha)}),(0,Je.jsx)("span",{className:"min-w-0 truncate font-medium text-white/85",children:p.subject}),u?(0,Je.jsxs)("span",{className:"ml-auto shrink-0 text-[10px] text-white/40",children:[u.author," \xB7 ",oM(u.date)]}):null]}):(0,Je.jsxs)(Je.Fragment,{children:[(0,Je.jsx)(Mr,{className:"h-3.5 w-3.5 shrink-0 text-blue-300/80"}),(0,Je.jsx)("span",{className:"shrink-0 font-medium text-white/85",children:"Outgoing changes"}),(0,Je.jsx)("span",{className:"truncate font-mono text-[10px] text-white/40",children:m}),(0,Je.jsx)("span",{className:"ml-auto shrink-0 text-[10px] text-white/35",title:"Computed from local refs (last fetch) \u2014 fetching/pulling remotes lands in a later increment.",children:"Local refs only \u2014 fetch lands later"})]})}),(0,Je.jsx)("div",{ref:s,className:"min-h-0 flex-1 overflow-auto px-2 py-2",children:o.phase==="loading"?(0,Je.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,Je.jsx)(We,{className:"h-3.5 w-3.5 animate-spin"}),"Loading changes\u2026"]}):o.phase==="error"?(0,Je.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-4 text-[11px] text-rose-300/70",children:[(0,Je.jsx)(ot,{className:"h-3.5 w-3.5 shrink-0"}),(0,Je.jsx)("span",{className:"truncate",children:o.message})]}):o.phase==="unavailable"?(0,Je.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:"Commit details unavailable \u2014 the commit may no longer exist in this repository."}):o.phase==="no-upstream"?(0,Je.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:"No upstream to compare against \u2014 everything here is local."}):o.files.length===0?(0,Je.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:g?"This commit changed no files.":"Nothing outgoing \u2014 the upstream is up to date."}):(0,Je.jsx)("div",{className:"flex flex-col gap-1.5",children:o.files.map(x=>(0,Je.jsx)(lM,{file:x,mode:p?{kind:"commit",sha:p.sha}:{kind:"range",base:o.range?.base??"",head:o.range?.head??""},source:d,repo:f,agentId:e,projectId:n,defaultExpanded:!0,queue:i},x.path))})})]})}var ae=j(ie(),1),Er=30,p1=16,up=14,u1=4.5,od=["#cba6f7","#a6e3a1","#f9e2af","#f38ba8","#94e2d5","#fab387","#b4befe","#89b4fa"];function op(t){return od[(t%od.length+od.length)%od.length]}var lp=t=>up+t*p1;function uM(){let t=null,e=new Set;return{get:()=>t,set:n=>{let r=typeof n=="function"?n(t):n;if(r!==t){t=r;for(let a of e)a()}},subscribe:n=>(e.add(n),()=>{e.delete(n)})}}var cM=null,dM=()=>cM;function fM({store:t,commits:e,expandedShas:n}){let r=nt.default.useSyncExternalStore(t.subscribe,t.get,dM);if(!r||n.has(r.sha))return null;let a=e.find(s=>s.sha===r.sha);return a?(0,ae.jsxs)("div",{className:"pointer-events-none absolute z-30 overflow-hidden rounded-md border border-white/10 bg-[#1b1b26] px-2.5 py-2 shadow-lg shadow-black/50",style:{left:up,right:8,maxHeight:"55%",...r.flip?{bottom:r.above}:{top:r.below}},children:[(0,ae.jsx)("div",{className:"whitespace-pre-wrap break-words text-[11px] font-medium leading-snug text-white/90",children:a.subject||"(no message)"}),a.body?(0,ae.jsx)("div",{className:"mt-1 whitespace-pre-wrap break-words text-[10px] leading-snug text-white/55",children:a.body}):null,(0,ae.jsxs)("div",{className:"mt-1.5 flex items-center gap-2 text-[10px] text-white/40",children:[(0,ae.jsx)("span",{className:"font-mono",children:tn(a.sha)}),(0,ae.jsx)("span",{className:"min-w-0 truncate",children:a.author}),(0,ae.jsx)("span",{children:Ah(a.date)})]})]}):null}function c1(t){let e=lp(t.fromLane),n=lp(t.toLane),r=t.fromY==="edge"?0:Er/2,a=t.toY==="edge"?Er:Er/2;if(e===n)return`M${e} ${r} L${n} ${a}`;if(t.toY==="edge"){let i=2*n-e;return`M${e} ${r} C ${e} ${(r+a)/2} ${(3*e+i)/4} ${(r+3*a)/4} ${n} ${a}`}let s=2*e-n;return`M${e} ${r} C ${(s+3*n)/4} ${(3*r+a)/4} ${n} ${(r+a)/2} ${n} ${a}`}function hM(t){return(t.split("->").pop()??t).replace(/^tag:\s*/,"").trim()}function d1(t,e){(t.key==="Enter"||t.key===" ")&&(t.preventDefault(),e())}function pM({file:t,onClick:e,showCounts:n}){let r=t.path.lastIndexOf("/"),a=r<0?t.path:t.path.slice(r+1),s=r<0?"":t.path.slice(0,r),i=(t.status[0]??"M").toUpperCase(),o=fo(t.path);return(0,ae.jsxs)("button",{type:"button",onClick:()=>e(t),className:"flex w-full min-w-0 items-center gap-1.5 overflow-hidden rounded-md py-1 pl-2 pr-1.5 text-left transition-colors hover:bg-white/[0.05]",title:t.renamedFrom?`${t.renamedFrom} \u2192 ${t.path}`:t.path,children:[(0,ae.jsx)(o,{className:"h-4 w-4 shrink-0 text-white/55"}),(0,ae.jsx)("span",{className:"shrink-0 truncate text-xs text-white/85",children:a}),s?(0,ae.jsx)("span",{className:"min-w-0 flex-1 truncate text-[10px] text-white/35",children:s}):(0,ae.jsx)("span",{className:"flex-1"}),n?(0,ae.jsx)(Aa,{added:t.added,removed:t.removed,binary:t.binary,className:"mr-1"}):null,(0,ae.jsx)("span",{className:$("shrink-0 text-[10px] font-bold leading-none tabular-nums",ap[i]??"text-white/60"),"aria-label":`Status: ${id[i]??"Changed"}`,children:i})]})}function f1({entry:t,emptyText:e,unavailableText:n,onFileClick:r,showCounts:a}){return t.status==="loading"?(0,ae.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[10px] text-white/40",children:[(0,ae.jsx)(h1.LiveSpinner,{className:"h-3 w-3"}),"Loading files\u2026"]}):t.status==="error"?(0,ae.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[10px] text-rose-300/70",children:[(0,ae.jsx)(ot,{className:"h-3 w-3 shrink-0"}),(0,ae.jsx)("span",{className:"truncate",children:t.message})]}):t.status==="unavailable"?(0,ae.jsx)("div",{className:"px-2 py-1 text-[10px] text-white/35",children:n}):t.files.length===0?(0,ae.jsx)("div",{className:"px-2 py-1 text-[10px] text-white/35",children:e}):(0,ae.jsx)("div",{className:"space-y-px",children:t.files.map(s=>(0,ae.jsx)(pM,{file:s,onClick:r,showCounts:a},s.path))})}function m1({source:t,repo:e="",agentId:n,projectId:r,repoName:a,showCounts:s=!0,onOutgoingStat:i}){let o=H(ue=>ue.client),[l,u]=(0,nt.useState)(Ih),[c,d]=(0,nt.useState)(!1),[f,h]=(0,nt.useState)(null),p=(0,nt.useRef)(0),g=(0,nt.useRef)(!1),m=(0,nt.useRef)(!1),x=(0,nt.useRef)(l);x.current=l;let[y,b]=(0,nt.useState)(()=>new Set),[C,L]=(0,nt.useState)(!1),[P,w]=(0,nt.useState)(()=>new Map),[k,_]=(0,nt.useState)({status:"idle"}),M=(0,nt.useRef)(null),R=(0,nt.useRef)(null);R.current===null&&(R.current=uM());let U=R.current,v=(0,nt.useRef)(0),T=(0,nt.useRef)(0),V=H(ue=>ue.gitLogNonce),Y=H(ue=>ue.setGitDiffTarget),N=H(ue=>ue.setGitCommitTarget),A=H(ue=>ue.setActiveWorkspaceTab),[B,K]=(0,nt.useState)(null),[te,ne]=(0,nt.useState)(null),[pe,Se]=(0,nt.useState)({}),le=(0,nt.useRef)(s);le.current=s;let re=(0,nt.useRef)(i);re.current=i;let he=(0,nt.useCallback)(async(ue,be,Ge)=>{if(!n||!t)return;let Re=++p.current;g.current=!0,d(!0),h(null);try{let Te=await uc({agentId:n,...r?{projectId:r}:{},source:t,...e?{repo:e}:{},maxCount:be,skip:ue},o);if(Re!==p.current)return;let vt={commits:Array.isArray(Te?.commits)?Te.commits:[],hasMore:Te?.hasMore===!0,outgoing:Array.isArray(Te?.outgoing)?Te.outgoing:void 0};u(mt=>Ge==="append"?ww(mt,vt):vw(vt)),le.current&&D0({agentId:n,...r?{projectId:r}:{},source:t,...e?{repo:e}:{},maxCount:be,skip:ue},o).then(mt=>{Re===p.current&&(Se(Gt=>Ge==="append"?{...Gt,...mt.stats}:{...mt.stats}),Ge==="replace"&&re.current?.(mt.outgoingStat??null))}).catch(()=>{}),Ge==="replace"&&(T.current++,_(mt=>mt.status==="idle"?mt:{status:"idle"})),d(!1)}catch(Te){if(Re!==p.current)return;h(Te instanceof Error?Te.message:"Git log failed"),d(!1)}finally{Re===p.current&&(g.current=!1)}},[n,r,t,e]);(0,nt.useEffect)(()=>{if(p.current++,g.current=!1,v.current++,T.current++,u(Ih),h(null),b(new Set),L(!1),w(new Map),_({status:"idle"}),!n||!t){d(!1);return}he(0,200,"replace")},[n,r,t,he]);let Ne=(0,nt.useRef)(V);(0,nt.useEffect)(()=>{V!==Ne.current&&(Ne.current=V,!(!n||!t)&&he(0,Lh(x.current.commits.length),"replace"))},[V,n,t,he]),(0,nt.useEffect)(()=>{if(!B||!te||(m.current=!1,typeof IntersectionObserver>"u"))return;let ue=new IntersectionObserver(be=>{for(let Re of be)m.current=Re.isIntersecting;if(!m.current)return;let Ge=x.current;!Ge.hasMore||g.current||he(Ge.nextSkip,200,"append")},{root:B,rootMargin:"120px"});return ue.observe(te),()=>ue.disconnect()},[B,te,he]),(0,nt.useEffect)(()=>{c||f!==null||!m.current||g.current||l.hasMore&&he(l.nextSkip,200,"append")},[l,c,f,he]);let Ee=(0,nt.useCallback)(async ue=>{if(!n||!t)return;let be=v.current;w(Ge=>new Map(Ge).set(ue,{status:"loading"}));try{let Ge=await cc({agentId:n,...r?{projectId:r}:{},source:t,...e?{repo:e}:{},sha:ue},o);if(be!==v.current)return;w(Re=>new Map(Re).set(ue,Ge.ok===!1?{status:"unavailable"}:{status:"ready",files:Array.isArray(Ge.files)?Ge.files:[]}))}catch(Ge){if(be!==v.current)return;w(Re=>new Map(Re).set(ue,{status:"error",message:Ge instanceof Error?Ge.message:"Commit files failed"}))}},[n,r,t,e]),ze=l.commits,ct=Fs(t,a),it=(0,nt.useMemo)(()=>xw(ze),[ze]),Qe=Math.max(40,up+it.laneCount*p1+8),Ye=(0,nt.useMemo)(()=>kw(ze,l.outgoing),[ze,l.outgoing]),Lt=(0,nt.useMemo)(()=>new Set(l.outgoing??[]),[l.outgoing]),Le=(0,nt.useMemo)(()=>Ye.some(ue=>ue.kind==="outgoing-divider"),[Ye]);(0,nt.useEffect)(()=>{if(!C||k.status!=="idle"||!Le||!n||!t)return;let ue=++T.current;_({status:"loading"}),(async()=>{try{let be=await cl({agentId:n,...r?{projectId:r}:{},source:t,...e?{repo:e}:{}},o);if(ue!==T.current)return;!be.ok||!be.baseSha||!be.headSha?_({status:"no-upstream"}):_({status:"ready",base:be.baseSha,head:be.headSha,files:Array.isArray(be.files)?be.files:[]})}catch(be){if(ue!==T.current)return;_({status:"error",message:be instanceof Error?be.message:"Outgoing changes failed"})}})()},[C,k.status,Le,n,r,t,e]);let at=lo({count:Ye.length,getScrollElement:()=>B,estimateSize:()=>Er,overscan:12,getItemKey:ue=>Sw(Ye[ue],ze)}),ft=()=>{!n||!t||he(0,Lh(x.current.commits.length),"replace")},bt=(ue,be)=>{if(y.has(ue)){at.resizeItem(be,Er),b(Re=>{let Te=new Set(Re);return Te.delete(ue),Te});return}b(Re=>new Set(Re).add(ue));let Ge=P.get(ue);(!Ge||Ge.status==="error")&&Ee(ue)},At=ue=>{let be=!C;be||at.resizeItem(ue,Er),be&&k.status==="error"&&_({status:"idle"}),L(be)},Tt=e?{repo:e}:{},Ue=(ue,be)=>{t&&(Y({source:t,...Tt,path:be.path,commit:ue}),A("git-diff"))},me=ue=>{t&&(N({source:t,...Tt,kind:"commit",sha:ue.sha,subject:ue.subject}),A("git-commit"))},Ot=ue=>{!t||k.status!=="ready"||(Y({source:t,...Tt,path:ue.path,base:k.base,head:k.head}),A("git-diff"))},Jt=()=>{if(!t||!n)return;if(k.status==="ready"){N({source:t,...Tt,kind:"outgoing",base:k.base,head:k.head}),A("git-commit");return}let ue=++T.current;_({status:"loading"}),(async()=>{try{let be=await cl({agentId:n,...r?{projectId:r}:{},source:t,...e?{repo:e}:{}},o);if(ue!==T.current)return;if(!be.ok||!be.baseSha||!be.headSha){_({status:"no-upstream"});return}_({status:"ready",base:be.baseSha,head:be.headSha,files:Array.isArray(be.files)?be.files:[]}),N({source:t,...Tt,kind:"outgoing",base:be.baseSha,head:be.headSha}),A("git-commit")}catch(be){if(ue!==T.current)return;_({status:"error",message:be instanceof Error?be.message:"Outgoing changes failed"})}})()};return(0,ae.jsxs)("div",{ref:M,className:"relative flex h-full w-full min-h-0 flex-col",children:[(0,ae.jsxs)("div",{className:"flex shrink-0 items-center gap-2 px-3 py-1.5 text-[11px]",style:{borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,ae.jsx)(Dr,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),(0,ae.jsx)("span",{className:"shrink-0 font-medium text-white/85",children:"Commit graph"}),ct.prefix?(0,ae.jsxs)(ae.Fragment,{children:[(0,ae.jsx)("span",{className:"shrink-0 font-mono text-white/40",children:ct.prefix}),(0,ae.jsx)("span",{className:"truncate font-medium text-white/85",children:ct.name})]}):(0,ae.jsx)("span",{className:"truncate font-mono text-white/40",children:ct.name}),(0,ae.jsxs)("span",{className:"ml-auto shrink-0 tabular-nums text-white/40",children:[ze.length,l.hasMore?"+":""," commit",ze.length===1?"":"s"]}),(0,ae.jsx)("button",{type:"button",onClick:ft,className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-white/40 transition-colors hover:bg-white/[0.06] hover:text-white/70",title:"Refresh commit graph","aria-label":"Refresh commit graph",children:(0,ae.jsx)(_t,{className:$("h-3 w-3",c&&"animate-spin")})})]}),f&&ze.length>0?(0,ae.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5 border-b border-white/[0.05] px-3 py-1 text-[10px] text-rose-300/70",children:[(0,ae.jsx)(ot,{className:"h-3 w-3 shrink-0"}),(0,ae.jsx)("span",{className:"truncate",children:f})]}):null,(0,ae.jsx)("div",{ref:K,className:"min-h-0 flex-1 overflow-auto",children:f&&ze.length===0?(0,ae.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-4 text-[11px] text-rose-300/70",children:[(0,ae.jsx)(ot,{className:"h-3 w-3 shrink-0"}),f]}):c&&ze.length===0?(0,ae.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,ae.jsx)(We,{className:"h-3.5 w-3.5 animate-spin"}),"Loading commit graph\u2026"]}):ze.length===0?(0,ae.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:"No commits yet."}):(0,ae.jsxs)(ae.Fragment,{children:[(0,ae.jsx)("div",{style:{height:at.getTotalSize(),width:"100%",position:"relative"},children:at.getVirtualItems().map(ue=>{let be=Ye[ue.index];if(!be)return null;if(be.kind==="outgoing-divider"){let ee=k.status==="ready"?{status:"ready",files:k.files}:k.status==="error"?k:{status:"loading"},oe=Ye[ue.index+1],He=yw(it.rowSegments,oe?.kind==="commit"?oe.row:-1);return(0,ae.jsxs)("div",{"data-index":ue.index,ref:C?at.measureElement:void 0,className:"absolute left-0 top-0 w-full",style:{transform:`translateY(${ue.start}px)`},children:[(0,ae.jsxs)("div",{role:"button",tabIndex:0,onClick:()=>At(ue.index),onKeyDown:Ve=>d1(Ve,()=>At(ue.index)),className:$("group flex w-full min-w-0 cursor-pointer items-center gap-1.5 text-[11px] transition-colors hover:bg-white/[0.04]",He.length>0?"pr-2":"px-2"),style:{height:Er},title:"The blue hollow dots mark commits not yet pushed to origin (local refs only, from the last known upstream). On a diverged/interleaved history this divider is an approximate boundary \u2014 the dots are the source of truth.",children:[He.length>0?(0,ae.jsx)("svg",{"data-divider-lanes":!0,width:Qe,height:Er,className:"shrink-0",style:{display:"block"},"aria-hidden":!0,children:He.map((Ve,Ae)=>(0,ae.jsx)("path",{d:c1(Ve),fill:"none",stroke:op(Ve.colorLane),strokeWidth:1.5,strokeOpacity:.55,strokeLinecap:"round"},Ae))}):null,C?(0,ae.jsx)(Et,{className:"h-3 w-3 shrink-0 text-white/40"}):(0,ae.jsx)(un,{className:"h-3 w-3 shrink-0 text-white/40"}),(0,ae.jsx)(Mr,{className:"h-3 w-3 shrink-0 text-blue-300/80"}),(0,ae.jsx)("span",{className:"shrink-0 text-[9px] font-bold uppercase tracking-wider text-blue-200/85",children:"Outgoing changes"}),(0,ae.jsx)("span",{className:"shrink-0 rounded bg-blue-400/15 px-1 py-0.5 text-[9px] leading-none tabular-nums text-blue-100/80",children:l.outgoing?.length??0}),(0,ae.jsx)("span",{className:"h-px min-w-0 flex-1 bg-blue-400/20","aria-hidden":!0}),(0,ae.jsx)("button",{type:"button",onClick:Ve=>{Ve.stopPropagation(),Jt()},className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-white/40 opacity-0 transition group-hover:opacity-100 focus-visible:opacity-100 hover:bg-white/10 hover:text-white/75",title:"Open Changes (all outgoing files)","aria-label":"Open outgoing changes",children:(0,ae.jsx)(ro,{className:"h-3 w-3"})})]}),C?(0,ae.jsx)("div",{className:"border-t border-white/[0.05] pb-1.5 pl-1 pr-2 pt-1",children:k.status==="no-upstream"?(0,ae.jsx)("div",{className:"px-2 py-1 text-[10px] text-white/35",children:"No upstream to compare against."}):(0,ae.jsx)(f1,{entry:ee,emptyText:"Nothing outgoing \u2014 the upstream is up to date.",unavailableText:"Outgoing changes unavailable.",onFileClick:Ot,showCounts:s})}):null]},ue.key)}let Ge=it.nodes[be.row];if(!Ge)return null;let Re=Ge.commit,Te=it.rowSegments[be.row]??[],vt=lp(Ge.lane),mt=op(Ge.lane),Gt=Re.refs??[],je=y.has(Re.sha),kt=Iw(Ge.isMerge,Lt.has(Re.sha)),on=Lw(kt,mt),Oe=P.get(Re.sha);return(0,ae.jsxs)("div",{"data-index":ue.index,ref:je?at.measureElement:void 0,className:"absolute left-0 top-0 w-full",style:{transform:`translateY(${ue.start}px)`},children:[(0,ae.jsxs)("div",{role:"button",tabIndex:0,"data-sha":Re.sha,onClick:()=>bt(Re.sha,ue.index),onKeyDown:ee=>d1(ee,()=>bt(Re.sha,ue.index)),onMouseEnter:ee=>{if(je)return;let oe=M.current;if(!oe)return;let He=oe.getBoundingClientRect(),Ve=ee.currentTarget.getBoundingClientRect(),Ae=Ve.bottom-He.top,ce=He.bottom-Ve.top;U.set({sha:Re.sha,below:Ae,above:ce,flip:Ae>He.height*.55})},onMouseLeave:()=>U.set(ee=>ee&&ee.sha===Re.sha?null:ee),className:"group/commit relative flex min-w-0 cursor-pointer items-center text-[11px] transition-colors hover:bg-white/[0.04]",style:{height:Er},children:[(0,ae.jsxs)("svg",{width:Qe,height:Er,className:"shrink-0",style:{display:"block"},"aria-hidden":!0,children:[Te.map((ee,oe)=>(0,ae.jsx)("path",{d:c1(ee),fill:"none",stroke:op(ee.colorLane),strokeWidth:1.5,strokeOpacity:ee.kind==="stub"?.3:.55,strokeDasharray:ee.kind==="stub"?"2 3":void 0,strokeLinecap:"round"},oe)),Ge.isHead?(0,ae.jsx)("circle",{cx:vt,cy:Er/2,r:u1+2.5,fill:"none",stroke:on,strokeWidth:1.5,strokeOpacity:.7}):null,(0,ae.jsx)("circle",{cx:vt,cy:Er/2,r:u1,fill:kt==="outgoing"?"transparent":kt==="merge"?"rgba(0,0,0,0.35)":mt,stroke:on,strokeWidth:kt==="filled"?1:1.5,fillOpacity:kt==="filled"?.9:1})]}),(0,ae.jsxs)("div",{className:"flex min-w-0 flex-1 items-center gap-2 pr-1",children:[je?(0,ae.jsx)(Et,{className:"h-3 w-3 shrink-0 text-white/35"}):(0,ae.jsx)(un,{className:"h-3 w-3 shrink-0 text-white/25"}),Gt.length?(0,ae.jsx)("span",{className:"flex shrink-0 items-center gap-1",children:Gt.slice(0,3).map(ee=>{let oe=Cw(ee);return(0,ae.jsxs)("span",{className:$("flex max-w-[120px] items-center gap-0.5 rounded px-1 py-0.5 text-[9px] font-medium leading-none",oe==="tag"?"bg-amber-400/15 text-amber-100/80":oe==="remote"?"border border-white/20 bg-transparent text-white/55":"bg-violet-400/20 text-violet-100/90"),children:[oe==="remote"?(0,ae.jsx)(vl,{className:"h-2 w-2 shrink-0","aria-hidden":!0}):null,(0,ae.jsx)("span",{className:"truncate",children:hM(ee)})]},ee)})}):null,(0,ae.jsx)("span",{className:"min-w-0 flex-1 truncate text-white/82",children:Re.subject||"(no message)"}),(0,ae.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/35 transition-opacity group-hover/commit:opacity-0",children:tn(Re.sha)}),(0,ae.jsx)("span",{className:"hidden shrink-0 max-w-[120px] truncate text-[10px] text-white/40 transition-opacity group-hover/commit:opacity-0 sm:inline",children:Re.author}),s&&pe[Re.sha]?(0,ae.jsx)(Aa,{...pe[Re.sha],compact:!0,className:"transition-opacity group-hover/commit:opacity-0"}):null,(0,ae.jsx)("button",{type:"button",onClick:ee=>{ee.stopPropagation(),me(Re)},className:"absolute right-1 top-1/2 inline-flex h-5 w-5 -translate-y-1/2 items-center justify-center rounded bg-white/10 text-white/50 opacity-0 transition group-hover/commit:opacity-100 focus-visible:opacity-100 hover:bg-white/20 hover:text-white/85",title:"Open Changes (all files in this commit)","aria-label":`Open changes of commit ${tn(Re.sha)}`,children:(0,ae.jsx)(ro,{className:"h-3 w-3"})})]})]}),je?(0,ae.jsxs)("div",{className:"pb-1.5 pl-1 pr-2 pt-0.5",children:[(0,ae.jsxs)("div",{className:"flex items-center gap-2 px-2 text-[10px] text-white/40",children:[(0,ae.jsx)("span",{className:"font-mono",children:tn(Re.sha)}),(0,ae.jsx)("span",{className:"min-w-0 truncate",children:Re.author}),(0,ae.jsx)("span",{title:Re.date,children:Ah(Re.date)})]}),(0,ae.jsx)("div",{className:"mt-1 border-t border-white/[0.05] pt-1",children:(0,ae.jsx)(f1,{entry:Oe??{status:"loading"},emptyText:"This commit changed no files.",unavailableText:"Commit details unavailable \u2014 the commit may no longer exist.",onFileClick:ee=>Ue(Re.sha,ee),showCounts:s})})]}):null]},ue.key)})}),l.hasMore?(0,ae.jsxs)("div",{ref:ne,className:"flex items-center justify-center gap-1.5 px-3 py-2 text-[11px] text-white/40",children:[(0,ae.jsx)(We,{className:$("h-3 w-3",c&&"animate-spin")}),"Loading more commits\u2026"]}):null]})}),(0,ae.jsx)(fM,{store:U,commits:ze,expandedShas:y})]})}var pn=j($e(),1);function su(t){return Number.isFinite(t)?Math.min(20,Math.max(.05,t)):1}function g1(t){return t>0&&t<1?1/t:1}function x1(t){if(!t)return{};try{let e=JSON.parse(t);if(!e||typeof e!="object"||Array.isArray(e))return{};let n={};for(let[r,a]of Object.entries(e)){if(!a||typeof a!="object"||Array.isArray(a))continue;let s=a;typeof s.collapsed!="boolean"||typeof s.weight!="number"||(n[r]={collapsed:s.collapsed,weight:su(s.weight)})}return n}catch{return{}}}function y1(t){return JSON.stringify(t)}function iu(t,e,n,r=1){return t[e]??{collapsed:n,weight:su(r)}}function b1(t,e,n,r,a=1){let s=iu(t,e,r,a),i=!n&&s.weight<.15?su(a):s.weight;return{...t,[e]:{collapsed:n,weight:i}}}function w1(t){let e=t.minBodyPx??72,n=t.heightAbove+t.heightBelow,r=t.weightAbove+t.weightBelow;if(!(n>0)||!(r>0)||n<e*2)return{above:t.weightAbove,below:t.weightBelow};let a=Math.min(n-e,Math.max(e,t.heightAbove+t.deltaY)),s=su(r*(a/n)),i=su(r-s);return{above:s,below:i}}var Or=j(ie(),1),mM=4;function gM(t){if(typeof window>"u")return{};try{return x1(window.localStorage.getItem(t))}catch{return{}}}function v1({sections:t,storageKey:e}){let[n,r]=(0,pn.useState)(()=>gM(e)),[a,s]=(0,pn.useState)(!1),i=(0,pn.useRef)(n);i.current=n;let o=(0,pn.useRef)(new Map),l=(0,pn.useRef)(null),u=(0,pn.useRef)(!1),c=(0,pn.useCallback)(w=>{if(typeof window<"u")try{window.localStorage.setItem(e,y1(w))}catch{}},[e]),d=(0,pn.useCallback)((w,k,_)=>{r(M=>{let R=iu(M,w,k,_),U=b1(M,w,!R.collapsed,k,_);return c(U),U})},[c]),f=(0,pn.useCallback)((w,k,_,M,R,U,v)=>{let T=o.current.get(k),V=o.current.get(_);U&&w.preventDefault(),l.current={aboveId:k,belowId:_,startY:w.clientY,weightAbove:M,weightBelow:R,heightAbove:T?.getBoundingClientRect().height??0,heightBelow:V?.getBoundingClientRect().height??0,engaged:U,belowCollapsed:v,expanded:!1,rebaselined:!1},u.current=!1,s(U),w.currentTarget.setPointerCapture(w.pointerId)},[]),h=(0,pn.useCallback)((w,k,_,M,R,U)=>{f(w,k,_,M,R,!0,U)},[f]),p=(0,pn.useCallback)((w,k,_,M,R,U)=>{w.button===0&&f(w,k,_,M,R,!1,U)},[f]),g=(0,pn.useCallback)(()=>{l.current&&(l.current=null,s(!1),c(i.current))},[c]);(0,pn.useEffect)(()=>{if(a)return window.addEventListener("pointerup",g),window.addEventListener("pointercancel",g),()=>{window.removeEventListener("pointerup",g),window.removeEventListener("pointercancel",g)}},[a,g]);let m=(0,pn.useCallback)(w=>{let k=l.current;if(!k)return;if((w.buttons&1)===0){g();return}let _=w.clientY-k.startY;if(!k.engaged){if(Math.abs(_)<mM)return;k.engaged=!0,u.current=!0,s(!0)}if(k.belowCollapsed&&!k.expanded){k.expanded=!0,r(U=>({...U,[k.belowId]:{collapsed:!1,weight:k.weightBelow}}));return}if(k.belowCollapsed&&!k.rebaselined){let U=o.current.get(k.belowId);if(!U)return;let v=o.current.get(k.aboveId);k.heightAbove=v?.getBoundingClientRect().height??k.heightAbove,k.heightBelow=U.getBoundingClientRect().height,k.startY=w.clientY,k.weightAbove=i.current[k.aboveId]?.weight??k.weightAbove,k.weightBelow=i.current[k.belowId]?.weight??k.weightBelow,k.rebaselined=!0;return}let{above:M,below:R}=w1({weightAbove:k.weightAbove,weightBelow:k.weightBelow,heightAbove:k.heightAbove,heightBelow:k.heightBelow,deltaY:_});r(U=>({...U,[k.aboveId]:{...U[k.aboveId]??{collapsed:!1,weight:1},weight:M},[k.belowId]:{...U[k.belowId]??{collapsed:!1,weight:1},weight:R}}))},[g]),x=(0,pn.useCallback)(w=>{w.currentTarget.hasPointerCapture(w.pointerId)&&w.currentTarget.releasePointerCapture(w.pointerId),g()},[g]),y=(0,pn.useCallback)((w,k,_,M)=>{let R=l.current?.engaged??!1,U=l.current!=null;w.currentTarget.hasPointerCapture(w.pointerId)&&w.currentTarget.releasePointerCapture(w.pointerId),g(),U&&!R&&d(k,_,M)},[g,d]),b=t.reduce((w,k)=>{let _=iu(n,k.id,k.defaultCollapsed??!1,k.defaultWeight??1);return _.collapsed?w:w+_.weight},0),C=g1(b),L=[],P=null;for(let w of t){let k=w.defaultCollapsed??!1,_=w.defaultWeight??1,M=iu(n,w.id,k,_),R=P&&!P.collapsed?P:null,U=M.collapsed?_:M.weight;R&&L.push((0,Or.jsx)("div",{role:"separator","aria-orientation":"horizontal",onPointerDown:v=>h(v,R.id,w.id,R.weight,U,M.collapsed),onPointerMove:m,onPointerUp:x,onPointerCancel:g,onLostPointerCapture:g,className:"relative h-1.5 shrink-0 cursor-row-resize touch-none bg-white/0 transition hover:bg-white/[0.06]",children:(0,Or.jsx)("div",{className:"absolute inset-x-6 top-1/2 h-[2px] -translate-y-1/2 rounded-full bg-white/[0.07]"})},`h:${R.id}:${w.id}`)),L.push((0,Or.jsxs)("div",{onPointerDown:R?v=>{v.target.closest("[data-section-actions]")||p(v,R.id,w.id,R.weight,U,M.collapsed)}:void 0,onPointerMove:R?m:void 0,onPointerUp:R?v=>y(v,w.id,k,_):void 0,onPointerCancel:R?g:void 0,onLostPointerCapture:R?g:void 0,className:$("group/section flex h-7 shrink-0 items-center gap-1.5 border-t border-white/[0.04] px-1 first:border-t-0",R&&"touch-none"),children:[(0,Or.jsxs)("button",{type:"button",onClick:v=>{R&&v.detail!==0||d(w.id,k,_)},"aria-expanded":!M.collapsed,className:"flex h-full min-w-0 flex-1 items-center gap-1 rounded px-1 text-left transition-colors hover:bg-white/[0.04]",children:[(0,Or.jsx)(un,{className:$("h-3 w-3 shrink-0 text-white/40 transition-transform",!M.collapsed&&"rotate-90")}),(0,Or.jsx)("span",{className:"truncate text-[10px] font-bold uppercase tracking-wider text-white/40",children:w.title}),typeof w.count=="number"?(0,Or.jsx)("span",{className:"text-[9px] tabular-nums text-white/30",children:w.count}):null,w.badge]}),w.actions?(0,Or.jsx)("div",{"data-section-actions":!0,className:"ml-auto flex shrink-0 items-center gap-1 opacity-0 transition-opacity focus-within:opacity-100 group-hover/section:opacity-100",children:w.actions}):null]},`s:${w.id}`)),M.collapsed||L.push((0,Or.jsx)("div",{ref:v=>{v?o.current.set(w.id,v):o.current.delete(w.id)},className:"min-h-0 overflow-auto",style:{flexGrow:M.weight*C,flexBasis:0},children:w.content},`b:${w.id}`)),P={id:w.id,collapsed:M.collapsed,weight:M.weight}}return(0,Or.jsx)("div",{className:$("flex min-h-0 flex-1 flex-col overflow-hidden",a&&"cursor-row-resize select-none"),children:L})}var G=j(ie(),1);function cp(t,e,n){(0,we.useEffect)(()=>{if(!t)return;let r=a=>{let s=a.target;s instanceof Node&&e.current?.contains(s)||n()};return document.addEventListener("mousedown",r,!0),()=>document.removeEventListener("mousedown",r,!0)},[t,e,n])}var xM="neuralis.filesystem.gitPanel.sections",k1="neuralis.filesystem.gitPanel.commitOpen",S1="neuralis.filesystem.gitPanel.diffCounts";function yM(t){return typeof t!="string"||!t?"":t.includes("://")?qe(t):t}function bM(t){let e=t.lastIndexOf("/");return e<0?{name:t,dir:""}:{name:t.slice(e+1),dir:t.slice(0,e)}}function wM(t){let e={name:"",path:"",children:new Map};for(let n of t){let r=n.path.split("/").filter(Boolean),a=e,s="";for(let i=0;i<r.length;i++){let o=r[i];s=s?`${s}/${o}`:o;let l=a.children.get(o);l||(l={name:o,path:s,children:new Map},a.children.set(o,l)),a=l,i===r.length-1&&(a.change=n)}}return e}function N1(t,e){let n=[],r=[...t.children.values()].sort((a,s)=>{let i=a.children.size>0,o=s.children.size>0;return i!==o?i?-1:1:a.name.localeCompare(s.name)});for(let a of r)n.push({node:a,depth:e}),a.children.size>0&&n.push(...N1(a,e+1));return n}var C1=Object.freeze({}),I1=we.default.memo(function({change:e,onClick:n,actions:r,busy:a,showCounts:s}){let{name:i,dir:o}=bM(e.path),l=fo(e.path),u=d=>d.stopPropagation(),c=!!(r.onDiscard||r.onUnstage||r.onStage);return(0,G.jsxs)("div",{className:"group/row relative flex w-full items-center rounded-md pr-1.5 transition-colors hover:bg-white/[0.05]",children:[(0,G.jsxs)("button",{type:"button",onClick:()=>n(e),title:e.origPath?`${e.origPath} \u2192 ${e.path}`:e.path,className:"flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden py-1 pl-2 pr-1 text-left",children:[(0,G.jsx)(l,{className:"h-4 w-4 shrink-0 text-white/55"}),(0,G.jsx)("span",{className:"shrink-0 truncate text-xs text-white/85",children:i}),o?(0,G.jsx)("span",{className:"min-w-0 flex-1 truncate text-[10px] text-white/35",children:o}):(0,G.jsx)("span",{className:"flex-1"})]}),s?(0,G.jsx)(Aa,{added:e.added,removed:e.removed,binary:e.binary,className:"mr-1 transition-opacity group-hover/row:opacity-0"}):null,(0,G.jsx)("span",{className:"flex w-3.5 shrink-0 items-center justify-center",children:(0,G.jsx)(Ac,{code:e.code})}),c?(0,G.jsxs)("div",{className:"absolute right-6 top-1/2 flex -translate-y-1/2 items-center gap-0.5 rounded bg-gradient-to-r from-transparent via-black/30 to-black/45 pl-4 opacity-0 transition-opacity group-hover/row:opacity-100 focus-within:opacity-100",children:[r.onDiscard?(0,G.jsx)("button",{type:"button",onClick:d=>{u(d),r.onDiscard(e)},disabled:a,className:"inline-flex h-5 w-5 items-center justify-center rounded text-rose-300/70 transition-colors hover:bg-rose-500/15 hover:text-rose-200 disabled:opacity-40",title:"Discard changes (destructive)","aria-label":`Discard changes to ${i}`,children:(0,G.jsx)(Nt,{className:"h-3 w-3"})}):null,r.onUnstage?(0,G.jsx)("button",{type:"button",onClick:d=>{u(d),r.onUnstage(e)},disabled:a,className:"inline-flex h-5 w-5 items-center justify-center rounded text-white/50 transition-colors hover:bg-white/10 hover:text-white/80 disabled:opacity-40",title:"Unstage","aria-label":`Unstage ${i}`,children:(0,G.jsx)(ai,{className:"h-3 w-3"})}):null,r.onStage?(0,G.jsx)("button",{type:"button",onClick:d=>{u(d),r.onStage(e)},disabled:a,className:"inline-flex h-5 w-5 items-center justify-center rounded text-emerald-300/80 transition-colors hover:bg-emerald-500/15 hover:text-emerald-200 disabled:opacity-40",title:"Stage","aria-label":`Stage ${i}`,children:(0,G.jsx)(Fn,{className:"h-3 w-3"})}):null]}):null]})});function L1({changes:t,viewMode:e,staged:n,onRowClick:r,actionsFor:a,busy:s,showCounts:i}){let o=(0,we.useMemo)(()=>e==="tree"?N1(wM(t),0):[],[t,e]),l=(0,we.useCallback)(u=>r(u,n),[r,n]);return(0,G.jsx)("div",{className:"px-1 py-0.5",children:e==="list"?(0,G.jsx)("div",{className:"space-y-px",children:t.map(u=>(0,G.jsx)(I1,{change:u,onClick:l,actions:a(u),busy:s,showCounts:i},`${u.code}:${u.path}`))}):(0,G.jsx)("div",{className:"space-y-px",children:o.map(({node:u,depth:c})=>u.change?(0,G.jsx)("div",{style:{paddingLeft:`${c*12}px`},children:(0,G.jsx)(I1,{change:u.change,onClick:l,actions:a(u.change),busy:s,showCounts:i})},`f:${u.path}`):(0,G.jsxs)("div",{style:{paddingLeft:`${c*12}px`},className:"flex items-center gap-1.5 px-2 py-1 text-[11px] text-white/45",children:[(0,G.jsx)(Tr,{className:"h-3.5 w-3.5 shrink-0 text-white/35"}),(0,G.jsx)("span",{className:"truncate",children:u.name})]},`d:${u.path}`))})})}function dp({tone:t,onClick:e,disabled:n,title:r,children:a}){return(0,G.jsx)("button",{type:"button",onClick:e,disabled:n,className:$("rounded px-1 py-0.5 text-[9px] transition-colors disabled:opacity-40",t==="discard"?"text-rose-300/70 hover:bg-rose-500/15 hover:text-rose-200":t==="unstage"?"text-white/55 hover:bg-white/10 hover:text-white/85":"text-emerald-300/80 hover:bg-emerald-500/15 hover:text-emerald-200"),title:r,children:a})}function R1({agentId:t}){let e=H(D=>D.client),n=H(D=>D.sources),r=H(D=>D.activeProjectId),a=H(D=>D.activeSource),s=H(D=>D.activeRepoRel),i=H(D=>D.setActiveSource),o=H(D=>D.gitStatus),l=H(D=>D.gitTotals),u=H(D=>D.gitOutgoingStat),c=H(D=>D.setGitOutgoingStat),d=H(D=>D.gitLoading),f=H(D=>D.gitError),h=H(D=>D.gitViewMode),p=H(D=>D.setGitViewMode),g=H(D=>D.gitBranches),m=H(D=>D.loadGitStatus),x=H(D=>D.loadGitBranches),y=H(D=>D.setGitDiffTarget),b=H(D=>D.setActiveWorkspaceTab),C=H(D=>D.gitLogNonce),[L,P]=(0,we.useState)(!1),[w,k]=(0,we.useState)(!1),_=(0,we.useRef)(null),M=(0,we.useRef)(null),[R,U]=(0,we.useState)(!1),[v,T]=(0,we.useState)(!1),[V,Y]=(0,we.useState)(null),[N,A]=(0,we.useState)(""),[B,K]=(0,we.useState)(!1),[te,ne]=(0,we.useState)(()=>Ph(k1,!1)),[pe,Se]=(0,we.useState)(()=>Ph(S1,!0)),le=(0,we.useCallback)(()=>{Se(D=>{let xe=!D;return Nh(S1,xe),xe})},[]),[re,he]=(0,we.useState)(null),[Ne,Ee]=(0,we.useState)(null),[ze,ct]=(0,we.useState)(!1),it=(0,we.useCallback)(()=>P(!1),[]),Qe=(0,we.useCallback)(()=>{k(!1),ct(!1)},[]),Ye=(0,we.useCallback)(()=>U(!1),[]);cp(L,_,it),cp(w,M,Qe),cp(R,M,Ye);let[Lt,Le]=(0,we.useState)(""),[at,ft]=(0,we.useState)(""),bt=(0,we.useMemo)(()=>n.filter(D=>D.git?.isRepo||D.git?.containsRepos),[n]),At=(0,we.useMemo)(()=>bt.map(D=>D.uri_root).join("|"),[bt]),Tt=(0,we.useMemo)(()=>yM(a),[a]),Ue=(0,we.useMemo)(()=>bt.find(D=>qe(D.uri_root)===Tt)??bt[0]??null,[bt,Tt]),me=Ue?qe(Ue.uri_root):"",Ot=bt.length>1||bt.some(D=>!D.git?.isRepo&&D.git?.containsRepos),Jt=(0,we.useRef)(new Map),[ue,be]=(0,we.useState)(()=>new Map),Ge=(0,we.useCallback)(async(D,xe)=>{if(!t||!D)return[];let Mt=Jt.current.get(D);if(Mt&&(Mt instanceof Promise||!xe?.force))return Mt;let zt=(async()=>{try{let yn=await Ki({agentId:t,...r?{projectId:r}:{},source:D},e),Sn=Array.isArray(yn?.repos)?yn.repos:[];return Jt.current.set(D,Sn),be(nc=>new Map(nc).set(D,Sn)),Sn}catch{return Jt.current.delete(D),be(yn=>yn.has(D)?yn:new Map(yn).set(D,[])),[]}})();return Jt.current.set(D,zt),zt},[t,r]),Re=(0,we.useMemo)(()=>s?ue.get(me)?.find(D=>D.rel===s)??null:null,[s,ue,me]),Te=s?Re?.canWrite===!0:Ue?.git?.canWrite===!0,vt=s?Re?.canExec===!0:Ue?.git?.canExec===!0,mt=o?.staged.length??0,Gt=Fs(me,s?Re?.name??s:Ue?.git?.repoName),je=(0,we.useMemo)(()=>Aw(o),[o]);(0,we.useEffect)(()=>{me&&me!==Tt&&i(me)},[t,r,me,At]),(0,we.useEffect)(()=>{let D=Ue?.git;if(!me||!D||D.isRepo||!D.containsRepos)return;let xe=!1;return Ge(me).then(Mt=>{xe||s||Mt.length===0||i(me,Mt[0].rel)}),()=>{xe=!0}},[me,Ue,s,Ge,i]);let kt=(0,we.useRef)(C);(0,we.useEffect)(()=>{if(C===kt.current)return;kt.current=C;let D=Ue?.git;!me||!D||D.isRepo||!D.containsRepos||Ge(me,{force:!0})},[C,me,Ue,Ge]),(0,we.useEffect)(()=>{me&&m({agentId:t,projectId:r??null,source:me,repo:s})},[t,r,me,s,At]),(0,we.useEffect)(()=>{if(!Ne)return;let D=setTimeout(()=>Ee(null),9e3);return()=>clearTimeout(D)},[Ne]);let on=(0,we.useCallback)((D,xe)=>{P(!1),i(D,xe)},[i]),Oe=(0,we.useCallback)(()=>{k(!1),ct(!1),U(!1),P(D=>{let xe=!D;if(xe)for(let Mt of bt){let zt=Mt.git;zt&&!zt.isRepo&&zt.containsRepos&&Ge(qe(Mt.uri_root),{force:!0})}return xe})},[bt,Ge]),ee=(0,we.useCallback)(()=>{ne(D=>{let xe=!D;return Nh(k1,xe),xe})},[]),He=(0,we.useCallback)(()=>{me&&m({agentId:t,projectId:r??null,source:me,repo:s})},[t,r,me,s,m]),Ve=(0,we.useCallback)((D,xe)=>{me&&(y({source:me,...s?{repo:s}:{},path:D.path,staged:xe}),b("git-diff"))},[me,s,y,b]),Ae=(0,we.useCallback)(async D=>{if(me){T(!0),Y(null);try{let xe=await D();return m({agentId:t,projectId:r??null,source:me,repo:s}),xe}catch(xe){Y(xe instanceof Error?xe.message:"Git operation failed");return}finally{T(!1)}}},[me,s,t,r,m]),ce=(0,we.useMemo)(()=>({...r?{projectId:r}:{},...s?{repo:s}:{}}),[r,s]),Pt=(0,we.useCallback)(D=>{D.length!==0&&Ae(()=>E0({agentId:t,...ce,source:me,paths:D},e))},[Ae,t,ce,me]),Ft=(0,we.useCallback)(D=>{D.length!==0&&Ae(()=>O0({agentId:t,...ce,source:me,paths:D},e))},[Ae,t,ce,me]),Zt=(0,we.useCallback)(D=>{(async()=>{let xe=await Ae(()=>H0({agentId:t,...ce,source:me,paths:D},e));xe&&xe.rescue&&Ee({message:`Discarded ${D.length} file${D.length===1?"":"s"} \u2014 recoverable`,rescue:xe.rescue})})()},[Ae,t,ce,me]),dn=(0,we.useCallback)(D=>{D.length!==0&&he({title:"Discard changes",message:`Overwrite the working-tree version of ${D.length} file${D.length===1?"":"s"} with the last committed/indexed content? A rescue snapshot is saved server-side so it can be recovered.`,confirmLabel:"Discard",onConfirm:()=>{he(null),Zt(D)}})},[Zt]),rr=(0,we.useCallback)(D=>Pt([D.path]),[Pt]),qr=(0,we.useCallback)(D=>Ft([D.path]),[Ft]),Mn=(0,we.useCallback)(D=>dn([D.path]),[dn]),Yn=(0,we.useMemo)(()=>({onStage:rr}),[rr]),$r=(0,we.useMemo)(()=>({onStage:rr,onDiscard:Mn}),[rr,Mn]),ar=(0,we.useMemo)(()=>({onUnstage:qr}),[qr]),Pr=(0,we.useCallback)(D=>Te?D.code==="??"?Yn:$r:C1,[Te,Yn,$r]),Kr=(0,we.useCallback)(()=>Te?ar:C1,[Te,ar]),ln=(0,we.useCallback)(()=>{let D=N.trim();D&&(async()=>{let xe=await Ae(()=>U0({agentId:t,...ce,source:me,message:D,amend:B},e));xe&&xe.ok&&(A(""),K(!1))})()},[N,B,Ae,t,ce,me]),Jn=(0,we.useCallback)(()=>{P(!1),U(!1),k(D=>{let xe=!D;return xe&&me&&x({agentId:t,projectId:r??null,source:me,repo:s}),xe}),ct(!1)},[me,s,t,r,x]),Wt=(0,we.useCallback)(D=>{k(!1),(async()=>await Ae(()=>Qf({agentId:t,...ce,source:me,ref:D},e))&&x({agentId:t,projectId:r??null,source:me,repo:s}))()},[Ae,t,ce,me,s,x,r]),gr=(0,we.useCallback)(()=>{let D=Lt.trim();if(!D)return;let xe=at.trim();k(!1),ct(!1),Le(""),ft(""),(async()=>await Ae(()=>G0({agentId:t,...ce,source:me,name:D,...xe?{startPoint:xe}:{}},e))&&(await Ae(()=>Qf({agentId:t,...ce,source:me,ref:D},e)),x({agentId:t,projectId:r??null,source:me,repo:s})))()},[Lt,at,Ae,t,ce,me,s,x,r]),Un=(0,we.useCallback)(D=>{(async()=>{let xe=await Ae(()=>W0({agentId:t,...ce,source:me,name:D},e));xe&&xe.rescue&&Ee({message:`Deleted branch "${D}" \u2014 recoverable`,rescue:xe.rescue}),x({agentId:t,projectId:r??null,source:me,repo:s})})()},[Ae,t,ce,me,s,x,r]),Nr=(0,we.useCallback)(D=>{k(!1),he({title:"Delete branch",message:`Delete the local branch "${D.name}"? A rescue ref is saved so it can be recreated (git will refuse if it has unmerged commits).`,confirmLabel:"Delete branch",onConfirm:()=>{he(null),Un(D.name)}})},[Un]),pa=(0,we.useCallback)(()=>{if(!Ne)return;let D=Ne.rescue;Ee(null),Ae(()=>z0({agentId:t,...ce,source:me,rescue:D},e))},[Ne,Ae,t,ce,me]),fn=(0,we.useCallback)(()=>{U(!1),Ae(()=>j0({agentId:t,...ce,source:me},e))},[Ae,t,ce,me]),Xr=(0,we.useCallback)(()=>{U(!1),Ae(()=>V0({agentId:t,...ce,source:me},e))},[Ae,t,ce,me]),ma=(0,we.useCallback)(()=>{U(!1),Ae(()=>q0({agentId:t,...ce,source:me},e))},[Ae,t,ce,me]),xn=o?.unstaged??[],Tn=o?.staged??[],z=o?.untracked??[],I=(0,we.useMemo)(()=>[...xn,...z].sort((D,xe)=>D.path.localeCompare(xe.path)),[xn,z]);if(bt.length===0)return(0,G.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 px-4 py-10 text-center",children:[(0,G.jsx)(Cn,{className:"h-5 w-5 text-white/25"}),(0,G.jsx)("div",{className:"text-xs text-white/40",children:"No git repositories"}),(0,G.jsx)("div",{className:"max-w-[200px] text-[10px] text-white/30",children:"Sources whose root is \u2014 or whose folders contain \u2014 a git checkout appear here."})]});let q=Te&&N.trim().length>0&&(mt>0||B)&&!v,F=f?(0,G.jsx)("div",{className:"px-2 py-3 text-[11px] text-rose-300/70",children:f}):d&&!o?(0,G.jsx)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:"Loading git status\u2026"}):I.length===0?(0,G.jsx)("div",{className:"px-2 py-4 text-center text-[11px] text-white/35",children:"No changes"}):(0,G.jsx)(L1,{changes:I,viewMode:h,staged:!1,showCounts:pe,onRowClick:Ve,actionsFor:Pr,busy:v}),de=[{id:"changes",title:"Changes",count:I.length,badge:l?(0,G.jsx)(Aa,{...l.changes,compact:!0,className:"ml-auto pr-1"}):void 0,actions:Te&&I.length>0?(0,G.jsxs)(G.Fragment,{children:[xn.length>0?(0,G.jsx)(dp,{tone:"discard",onClick:()=>dn(xn.map(D=>D.path)),disabled:v,title:"Discard all tracked changes in this group (destructive)",children:"Discard all"}):null,(0,G.jsx)(dp,{tone:"stage",onClick:()=>Pt(I.map(D=>D.path)),disabled:v,title:"Stage all",children:"Stage all"})]}):void 0,content:F},...Tn.length>0?[{id:"staged",title:"Staged Changes",count:Tn.length,badge:l?(0,G.jsx)(Aa,{...l.staged,compact:!0,className:"ml-auto pr-1"}):void 0,actions:Te?(0,G.jsx)(dp,{tone:"unstage",onClick:()=>Ft(Tn.map(D=>D.path)),disabled:v,title:"Unstage all",children:"Unstage all"}):void 0,content:(0,G.jsx)(L1,{changes:Tn,viewMode:h,staged:!0,showCounts:pe,onRowClick:Ve,actionsFor:Kr,busy:v})}]:[],{id:"graph",title:"Graph",badge:u?(0,G.jsx)(Aa,{added:u.added,removed:u.removed,unknown:u.commits-u.covered,compact:!0,className:"ml-auto pr-1"}):void 0,defaultCollapsed:!0,defaultWeight:2,content:(0,G.jsx)(m1,{showCounts:pe,onOutgoingStat:c,source:me,repo:s,agentId:t,projectId:r??null,repoName:s?Re?.name??s:Ue?.git?.repoName},`${me}\0${s}`)}];return(0,G.jsxs)("div",{className:"flex h-full min-h-0 flex-col",children:[(0,G.jsxs)("div",{ref:_,className:"relative px-2 pt-1 pb-1.5",children:[(0,G.jsxs)("div",{className:"flex items-center gap-1",children:[(0,G.jsxs)("button",{type:"button",onClick:Oe,disabled:!Ot,className:$("flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-2 py-1 text-left transition-colors","bg-white/[0.03] hover:bg-white/[0.06] disabled:hover:bg-white/[0.03]"),title:me?Gt.title:"Select a repository",children:[(0,G.jsx)(Cn,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),Gt.prefix?(0,G.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:Gt.prefix}):null,(0,G.jsx)("span",{className:"min-w-0 flex-1 truncate text-xs font-medium text-white/85",children:Gt.name||"Select repository"}),Ot?(0,G.jsx)(Et,{className:"h-3 w-3 shrink-0 text-white/40"}):null]}),(0,G.jsx)("button",{type:"button",onClick:He,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-white/40 transition-colors hover:bg-white/[0.06] hover:text-white/70",title:"Refresh git status","aria-label":"Refresh git status",children:(0,G.jsx)(_t,{className:$("h-3.5 w-3.5",d&&"animate-spin")})}),(0,G.jsx)(P1.SkillLauncher,{variant:"icon",size:"sm",skill:"git",packageId:"@neuralis/brain-core",scripts:["scripts/git.sh"],label:"Status, diff, commit, branch, fetch or push with the agent",icon:"GitBranch"})]}),L&&Ot?(0,G.jsx)(G.Fragment,{children:(0,G.jsx)("div",{className:"absolute left-2 right-2 z-50 mt-1 max-h-56 overflow-auto rounded-md border border-white/10 bg-[rgba(var(--w-bg-rgb),0.96)] py-1 shadow-lg",children:bt.map(D=>{let xe=qe(D.uri_root);if(D.git?.isRepo){let zt=xe===me&&!s,yn=Fs(xe,D.git?.repoName);return(0,G.jsxs)("button",{type:"button",onClick:()=>on(xe,""),className:$("flex w-full items-center gap-1.5 px-2 py-1.5 text-left text-xs transition-colors hover:bg-white/[0.06]",zt?"text-white/90":"text-white/65"),children:[(0,G.jsx)(Cn,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/70"}),yn.prefix?(0,G.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:yn.prefix}):null,(0,G.jsx)("span",{className:"min-w-0 flex-1 truncate",children:yn.name}),D.git?.branch?(0,G.jsx)("span",{className:"shrink-0 truncate text-[10px] text-white/35",children:D.git.branch}):null,zt?(0,G.jsx)(Dn,{className:"h-3 w-3 shrink-0 text-violet-300/80"}):null]},D.uri_root)}let Mt=ue.get(xe);return Mt?Mt.length===0?(0,G.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5 text-[11px] text-white/35",children:[(0,G.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:`${xe}://`}),(0,G.jsx)("span",{className:"truncate",children:"No repositories found."})]},D.uri_root):Mt.map(zt=>{let yn=xe===me&&s===zt.rel,Sn=Fs(xe,zt.name||zt.rel);return(0,G.jsxs)("button",{type:"button",onClick:()=>on(xe,zt.rel),className:$("flex w-full items-center gap-1.5 px-2 py-1.5 text-left text-xs transition-colors hover:bg-white/[0.06]",yn?"text-white/90":"text-white/65"),children:[(0,G.jsx)(Cn,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/70"}),Sn.prefix?(0,G.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:Sn.prefix}):null,(0,G.jsx)("span",{className:"min-w-0 flex-1 truncate",children:Sn.name}),zt.branch?(0,G.jsx)("span",{className:"shrink-0 truncate text-[10px] text-white/35",children:zt.branch}):null,yn?(0,G.jsx)(Dn,{className:"h-3 w-3 shrink-0 text-violet-300/80"}):null]},`${D.uri_root}\0${zt.rel}`)}):(0,G.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5 text-[11px] text-white/35",children:[(0,G.jsx)(We,{className:"h-3 w-3 shrink-0 animate-spin"}),(0,G.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:`${xe}://`}),(0,G.jsx)("span",{className:"truncate",children:"Scanning repositories\u2026"})]},D.uri_root)})})}):null]}),(0,G.jsxs)("div",{ref:M,className:"relative flex items-center justify-between gap-2 px-2 pb-1.5",children:[(0,G.jsxs)("div",{className:"flex min-w-0 items-center gap-1",children:[(0,G.jsxs)("button",{type:"button",onClick:Jn,className:"flex min-w-0 items-center gap-1.5 rounded-md px-1.5 py-0.5 text-[11px] text-white/55 transition-colors hover:bg-white/[0.05] hover:text-white/80",title:"Switch or create branch","aria-haspopup":"menu","aria-expanded":w,children:[(0,G.jsx)(Cn,{className:"h-3 w-3 shrink-0 text-white/40"}),(0,G.jsx)("span",{className:"truncate",children:o?.branch??"\u2014"}),(0,G.jsx)(Et,{className:"h-3 w-3 shrink-0 text-white/30"})]}),Te?(0,G.jsx)("button",{type:"button",onClick:()=>{P(!1),k(!1),ct(!1),U(D=>!D)},className:"flex shrink-0 items-center gap-1.5 rounded bg-white/[0.05] px-1.5 py-0.5 text-[10px] leading-none tabular-nums text-white/60 transition-colors hover:bg-white/[0.08] hover:text-white/85",title:"Fetch / pull / push","aria-haspopup":"menu","aria-expanded":R,children:je?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${je.ahead} commits ahead of ${je.upstream}`,children:[(0,G.jsx)("span",{className:"text-blue-300/60",children:"\u2191"}),(0,G.jsx)("span",{className:"text-blue-200/90",children:je.ahead})]}),(0,G.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${je.behind} commits behind ${je.upstream}`,children:[(0,G.jsx)("span",{className:"text-white/40",children:"\u2193"}),(0,G.jsx)("span",{className:"text-white/70",children:je.behind})]})]}):(0,G.jsx)(gl,{className:"h-3 w-3 text-white/40"})}):je?(0,G.jsxs)("span",{className:"flex shrink-0 cursor-default items-center gap-1.5 rounded bg-white/[0.05] px-1 py-0.5 text-[10px] leading-none tabular-nums",title:`${je.upstream}: ahead/behind vs the tracked upstream (local refs)`,children:[(0,G.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${je.ahead} commits ahead of ${je.upstream}`,children:[(0,G.jsx)("span",{className:"text-blue-300/60",children:"\u2191"}),(0,G.jsx)("span",{className:"text-blue-200/90",children:je.ahead})]}),(0,G.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${je.behind} commits behind ${je.upstream}`,children:[(0,G.jsx)("span",{className:"text-white/40",children:"\u2193"}),(0,G.jsx)("span",{className:"text-white/70",children:je.behind})]})]}):null,Te?(0,G.jsxs)("button",{type:"button",onClick:ee,className:"flex shrink-0 items-center gap-1 rounded-md px-1.5 py-0.5 text-[11px] text-white/55 transition-colors hover:bg-white/[0.05] hover:text-white/80",title:te?"Hide the commit box":"Show the commit box","aria-expanded":te,children:[(0,G.jsx)("span",{children:"Commit"}),mt>0?(0,G.jsx)("span",{className:"rounded bg-white/[0.08] px-1 py-0.5 text-[9px] leading-none tabular-nums text-white/70",children:mt}):null,te?(0,G.jsx)(qa,{className:"h-3 w-3 shrink-0 text-white/30"}):(0,G.jsx)(Et,{className:"h-3 w-3 shrink-0 text-white/30"})]}):null]}),(0,G.jsxs)("div",{className:"flex shrink-0 items-center gap-0.5 rounded-md bg-white/[0.03] p-0.5",children:[(0,G.jsx)("button",{type:"button",onClick:()=>p("list"),className:$("inline-flex h-5 w-5 items-center justify-center rounded transition-colors",h==="list"?"bg-white/10 text-white/85":"text-white/40 hover:text-white/70"),title:"Flat list","aria-label":"Flat list view","aria-pressed":h==="list",children:(0,G.jsx)(ni,{className:"h-3 w-3"})}),(0,G.jsx)("button",{type:"button",onClick:()=>p("tree"),className:$("inline-flex h-5 w-5 items-center justify-center rounded transition-colors",h==="tree"?"bg-white/10 text-white/85":"text-white/40 hover:text-white/70"),title:"Folder tree","aria-label":"Folder tree view","aria-pressed":h==="tree",children:(0,G.jsx)(Al,{className:"h-3 w-3"})})]}),(0,G.jsx)("button",{type:"button",onClick:le,className:$("inline-flex h-5 w-5 shrink-0 items-center justify-center rounded transition-colors",pe?"text-white/85":"text-white/35 hover:text-white/60"),title:pe?"Hide per-row diff counts":"Show per-row diff counts","aria-label":"Toggle per-row diff counts","aria-pressed":pe,children:(0,G.jsx)(Hl,{className:"h-3 w-3"})}),w?(0,G.jsx)(G.Fragment,{children:(0,G.jsxs)("div",{className:"absolute left-2 right-2 top-full z-50 mt-1 max-h-72 overflow-auto rounded-md border border-white/10 bg-[rgba(var(--w-bg-rgb),0.97)] py-1 shadow-lg",children:[(0,G.jsx)("div",{className:"px-2 py-1 text-[9px] font-bold uppercase tracking-wider text-white/35",children:"Branches"}),g.length===0?(0,G.jsx)("div",{className:"px-2 py-1.5 text-[11px] text-white/35",children:"No branches loaded."}):g.map(D=>(0,G.jsxs)("div",{className:"group flex items-center gap-1.5 pr-1",children:[(0,G.jsxs)("button",{type:"button",onClick:()=>!D.current&&Wt(D.name),disabled:D.current||v,className:$("flex min-w-0 flex-1 items-center gap-1.5 px-2 py-1.5 text-left text-xs transition-colors",D.current?"text-violet-200/90":"text-white/70 hover:bg-white/[0.06]"),title:D.current?`${D.name} (current)`:`Switch to ${D.name}`,children:[(0,G.jsx)(Cn,{className:"h-3.5 w-3.5 shrink-0 text-white/40"}),(0,G.jsx)("span",{className:"min-w-0 flex-1 truncate",children:D.name}),D.current?(0,G.jsx)(Dn,{className:"h-3 w-3 shrink-0 text-violet-300/80"}):null]}),Te&&!D.current?(0,G.jsx)("button",{type:"button",onClick:()=>Nr(D),disabled:v,className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-rose-300/60 opacity-0 transition group-hover:opacity-100 hover:bg-rose-500/15 hover:text-rose-200 disabled:opacity-40",title:`Delete branch ${D.name}`,"aria-label":`Delete branch ${D.name}`,children:(0,G.jsx)(Nt,{className:"h-3 w-3"})}):null]},D.name)),Te?(0,G.jsx)("div",{className:"mt-1 border-t border-white/[0.06] pt-1",children:ze?(0,G.jsxs)("div",{className:"px-2 py-1.5",children:[(0,G.jsx)("input",{value:Lt,onChange:D=>Le(D.target.value),onKeyDown:D=>{D.key==="Enter"&&gr()},placeholder:"new-branch-name",autoFocus:!0,className:"mb-1 h-6 w-full rounded border border-white/[0.12] bg-white/[0.04] px-1.5 text-[11px] text-white/85 outline-none placeholder:text-white/25 focus:border-white/25"}),(0,G.jsx)("input",{value:at,onChange:D=>ft(D.target.value),onKeyDown:D=>{D.key==="Enter"&&gr()},placeholder:"from (optional ref \u2014 default HEAD)",className:"mb-1.5 h-6 w-full rounded border border-white/[0.12] bg-white/[0.04] px-1.5 text-[11px] text-white/85 outline-none placeholder:text-white/25 focus:border-white/25"}),(0,G.jsxs)("div",{className:"flex items-center gap-1",children:[(0,G.jsxs)("button",{type:"button",onClick:gr,disabled:v||Lt.trim().length===0,className:"inline-flex items-center gap-1 rounded bg-violet-500/20 px-2 py-1 text-[10px] text-violet-100/90 transition-colors hover:bg-violet-500/30 disabled:opacity-40",children:[(0,G.jsx)(Fn,{className:"h-3 w-3"})," Create & switch"]}),(0,G.jsx)("button",{type:"button",onClick:()=>{ct(!1),Le(""),ft("")},className:"rounded px-2 py-1 text-[10px] text-white/50 transition-colors hover:bg-white/[0.06] hover:text-white/80",children:"Cancel"})]})]}):(0,G.jsxs)("button",{type:"button",onClick:()=>ct(!0),className:"flex w-full items-center gap-1.5 px-2 py-1.5 text-left text-xs text-white/70 transition-colors hover:bg-white/[0.06]",children:[(0,G.jsx)(Fn,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/70"}),(0,G.jsx)("span",{children:"Create new branch\u2026"})]})}):null]})}):null,R?(0,G.jsx)(G.Fragment,{children:(0,G.jsxs)("div",{className:"absolute right-2 top-full z-50 mt-1 w-52 max-w-[calc(100%-1rem)] overflow-auto rounded-md border border-white/10 bg-[rgba(var(--w-bg-rgb),0.97)] py-1 shadow-lg",children:[(0,G.jsx)("div",{className:"px-2 py-1 text-[9px] font-bold uppercase tracking-wider text-white/35",children:"Remote"}),vt?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)("button",{type:"button",onClick:Xr,disabled:v,className:"flex w-full items-center gap-2 px-2 py-1.5 text-left text-xs text-white/75 transition-colors hover:bg-white/[0.06] disabled:opacity-40",title:"Fetch + fast-forward merge (git pull, ff-only)",children:[(0,G.jsx)(ml,{className:"h-3.5 w-3.5 shrink-0 text-white/45"}),(0,G.jsx)("span",{className:"min-w-0 flex-1",children:"Pull"}),je&&je.behind>0?(0,G.jsxs)("span",{className:"shrink-0 tabular-nums text-[10px] text-white/50",children:["\u2193",je.behind]}):null]}),(0,G.jsxs)("button",{type:"button",onClick:ma,disabled:v,className:"flex w-full items-center gap-2 px-2 py-1.5 text-left text-xs text-white/75 transition-colors hover:bg-white/[0.06] disabled:opacity-40",title:"Push the current branch (git push origin HEAD)",children:[(0,G.jsx)(xl,{className:"h-3.5 w-3.5 shrink-0 text-blue-300/60"}),(0,G.jsx)("span",{className:"min-w-0 flex-1",children:"Push"}),je&&je.ahead>0?(0,G.jsxs)("span",{className:"shrink-0 tabular-nums text-[10px] text-blue-200/80",children:["\u2191",je.ahead]}):null]}),(0,G.jsxs)("button",{type:"button",onClick:fn,disabled:v,className:"flex w-full items-center gap-2 px-2 py-1.5 text-left text-xs text-white/75 transition-colors hover:bg-white/[0.06] disabled:opacity-40",title:"Fetch remote refs (git fetch origin)",children:[(0,G.jsx)(_t,{className:"h-3.5 w-3.5 shrink-0 text-white/45"}),(0,G.jsx)("span",{className:"min-w-0 flex-1",children:"Fetch"})]})]}):(0,G.jsxs)("div",{className:"flex items-start gap-1.5 px-2 py-2",children:[(0,G.jsx)(ri,{className:"mt-0.5 h-3 w-3 shrink-0 text-amber-300/70"}),(0,G.jsxs)("div",{className:"min-w-0 text-[11px] leading-snug text-white/55",children:["Remote git operations need ",(0,G.jsx)("span",{className:"font-medium text-white/75",children:"exec"})," permission on this source. Ask an owner to grant it."]})]})]})}):null]}),Ne?(0,G.jsxs)("div",{className:"mx-2 mb-1 flex items-start gap-1.5 rounded-md border border-amber-500/20 bg-amber-500/[0.07] px-2 py-1.5",children:[(0,G.jsx)(ot,{className:"mt-0.5 h-3 w-3 shrink-0 text-amber-300/80"}),(0,G.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,G.jsx)("div",{className:"text-[11px] text-amber-100/85",children:Ne.message}),(0,G.jsxs)("div",{className:"truncate font-mono text-[9px] text-amber-100/45",title:Ne.rescue.ref,children:["rescue: ",Ne.rescue.ref]})]}),(0,G.jsx)("button",{type:"button",onClick:pa,disabled:v,className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-semibold text-amber-100 transition-colors hover:bg-amber-500/20 disabled:opacity-40",children:"Undo"}),(0,G.jsx)("button",{type:"button",onClick:()=>Ee(null),className:"shrink-0 rounded p-0.5 text-amber-200/60 transition-colors hover:bg-amber-500/15 hover:text-amber-100","aria-label":"Dismiss recovery notice",children:(0,G.jsx)(Ht,{className:"h-3 w-3"})})]}):null,V?(0,G.jsxs)("div",{className:"mx-2 mb-1 flex items-start gap-1.5 rounded-md border border-rose-500/20 bg-rose-500/[0.06] px-2 py-1.5",children:[(0,G.jsx)(ot,{className:"mt-0.5 h-3 w-3 shrink-0 text-rose-300/80"}),(0,G.jsx)("div",{className:"min-w-0 flex-1 text-[11px] text-rose-200/85",children:V}),(0,G.jsx)("button",{type:"button",onClick:()=>Y(null),className:"shrink-0 rounded p-0.5 text-rose-200/60 transition-colors hover:bg-rose-500/15 hover:text-rose-100","aria-label":"Dismiss error",children:(0,G.jsx)(Ht,{className:"h-3 w-3"})})]}):null,Te&&te?(0,G.jsxs)("div",{className:"mx-2 mb-1.5 rounded-md border border-white/[0.07] bg-white/[0.02] p-1",children:[(0,G.jsx)("textarea",{value:N,onChange:D=>A(D.target.value),onKeyDown:D=>{D.key==="Enter"&&(D.metaKey||D.ctrlKey)&&!D.nativeEvent.isComposing&&q&&(D.preventDefault(),ln())},placeholder:mt>0?`Commit message (${mt} staged)`:"Commit message",rows:2,className:"w-full resize-none rounded bg-transparent px-1 text-[11px] text-white/85 outline-none placeholder:text-white/30"}),(0,G.jsxs)("div",{className:"mt-0.5 flex items-center justify-end gap-2",children:[(0,G.jsxs)("label",{className:"flex cursor-pointer select-none items-center gap-1 text-[10px] text-white/50",children:[(0,G.jsx)("input",{type:"checkbox",checked:B,onChange:D=>K(D.target.checked),className:"h-3 w-3 accent-violet-400"}),"Amend"]}),(0,G.jsxs)("button",{type:"button",onClick:ln,disabled:!q,className:"inline-flex items-center gap-1 rounded-md bg-violet-500/20 px-2.5 py-1 text-[11px] font-medium text-violet-100/90 transition-colors hover:bg-violet-500/30 disabled:opacity-40",title:B?"Amend the last commit":"Commit the staged changes",children:[v?(0,G.jsx)(We,{className:"h-3 w-3 animate-spin"}):(0,G.jsx)(Dn,{className:"h-3 w-3"}),B?"Amend":"Commit"]})]})]}):null,(0,G.jsx)(v1,{storageKey:xM,sections:de}),re&&typeof document<"u"?(0,A1.createPortal)((0,G.jsxs)("div",{className:"fixed inset-0 z-[100000] flex items-center justify-center p-4",children:[(0,G.jsx)("button",{type:"button","aria-hidden":!0,tabIndex:-1,onClick:()=>he(null),className:"absolute inset-0 cursor-default bg-black/50"}),(0,G.jsxs)("div",{className:"relative z-10 w-full max-w-xs rounded-lg border border-white/10 bg-[rgba(var(--w-bg-rgb),0.98)] p-4 shadow-xl",children:[(0,G.jsxs)("div",{className:"mb-1 flex items-center gap-2",children:[(0,G.jsx)(ot,{className:"h-4 w-4 shrink-0 text-rose-300/80"}),(0,G.jsx)("span",{className:"text-sm font-semibold text-white/90",children:re.title})]}),(0,G.jsx)("p",{className:"mb-3 text-[11px] leading-relaxed text-white/55",children:re.message}),(0,G.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,G.jsx)("button",{type:"button",onClick:()=>he(null),className:"rounded-md px-3 py-1.5 text-[11px] text-white/60 transition-colors hover:bg-white/[0.06] hover:text-white/85",children:"Cancel"}),(0,G.jsxs)("button",{type:"button",onClick:re.onConfirm,className:"inline-flex items-center gap-1 rounded-md border border-rose-500/30 bg-rose-500/15 px-3 py-1.5 text-[11px] font-semibold text-rose-100 transition-colors hover:bg-rose-500/25",children:[(0,G.jsx)(Nt,{className:"h-3 w-3"}),re.confirmLabel]})]})]})]}),document.body):null]})}var Ct=j(ie(),1),M1={},T1="brain://",vM=32,kM=28,SM=114;function CM(t){return t==="header"?vM:t==="empty"?SM:kM}function IM(t){return t!=="node"}function D1(t,e){return t.type===e.type?t.name.localeCompare(e.name):t.type==="folder"?-1:1}function LM(t){let e=new Map,n=new Set;for(let a of t)n.add(a.uri);for(let a of t){let s=a.parentUri??et(a.uri);if(!s||a.uri===s)continue;let i=e.get(s);i?i.push(a):e.set(s,[a])}for(let a of e.values())a.sort(D1);let r=new Map;for(let a of t){let s=sr(a.uri);if(!s||a.uri===s)continue;let i=a.parentUri??et(a.uri);if(!(!i||i===s||!n.has(i)))continue;let l=r.get(s);l?l.push(a):r.set(s,[a])}for(let a of r.values())a.sort(D1);return{childrenByParent:e,rootsBySource:r}}function AM(t,e,n){let r=[],a=(i,o)=>{r.push({node:i,depth:o});let l=i.storeKey||Va(i);if(i.type==="folder"&&n.has(l)){let u=t.childrenByParent.get(i.uri);if(u)for(let c=0;c<u.length;c++)a(u[c],o+1)}},s=t.rootsBySource.get(e);if(s)for(let i=0;i<s.length;i++)a(s[i],0);return r}function fp(t){let{agentId:e,sidebarView:n="tree"}=t,r=hn(),a=ti(),s=H(I=>I.files),i=H(I=>I.folderBadges),o=H(I=>I.expandedFolders),l=H(I=>I.activeFile),u=H(I=>I.toggleFolder),c=H(I=>I.openFile),d=H(I=>I.activeProjectId),f=H(I=>I.setActiveFolderPath),h=H(I=>I.activeFolderPath),p=H(I=>I.uploadMany),g=H(I=>I.moveFileToFolder),m=H(I=>I.uploading),x=H(I=>I.sources),y=H(I=>I.sourcesLoading),b=H(I=>I.hydrationState),C=H(I=>I.dirtySources),L=H(I=>I.organizeError),P=H(I=>I.clearOrganizeError),w=H(I=>I.snapshotError),k=H(I=>I.clearSnapshotError),_=H(I=>I.loadList),M=H(I=>I.pendingReviewPaths),R=H(I=>I.renameNode),U=H(I=>I.deleteNodes),v=H(I=>I.createNode),T=H(I=>I.pasteNodes),[V,Y]=(0,_e.useState)(null),[N,A]=(0,_e.useState)({}),[B,K]=(0,_e.useState)(()=>new Set),[te,ne]=(0,_e.useState)(null),[pe,Se]=(0,_e.useState)(null),[le,re]=(0,_e.useState)(null),[he,Ne]=(0,_e.useState)(null),[Ee,ze]=(0,_e.useState)(null),[ct,it]=(0,_e.useState)(null),[Qe,Ye]=(0,_e.useState)(!1),[Lt,Le]=(0,_e.useState)(!1),at=H(I=>I.setPendingSourceSuggestion),ft=H(I=>I.setWorkspacePanelOpen);(0,_e.useEffect)(()=>{if(!l)return;let I=`${qe(l)}://`;A(q=>q[I]?q:{...q,[I]:!0})},[l]);let bt=r.useFileMarks(e),At=r.useAgents(),Tt=r.usePackageIconBySlug?.()??M1,Ue=(0,_e.useMemo)(()=>bt||M1,[bt]),me=(0,_e.useMemo)(()=>Ms(At),[At]),Ot=(0,_e.useMemo)(()=>me.byId.get(e)??null,[me,e]),Jt=(0,_e.useMemo)(()=>{let I={};for(let q of M){let F=xa(q);for(let de of F)I[de]=(I[de]||0)+1}return I},[M]),ue=x.length>0,be=(0,_e.useMemo)(()=>Object.values(s),[s]),Ge=(0,_e.useMemo)(()=>LM(be),[be]),Re=(0,_e.useMemo)(()=>{let I={uri_root:T1,source_kind:"brain",writable:!0};return ue?x.length>0?x:[I]:[I]},[ue,x]),Te=n==="search",vt=(0,_e.useMemo)(()=>{let I=h?sr(h):null;return I&&Re.some(F=>F.uri_root===I)?I:Re.find(F=>F.source_kind!=="brain")?.uri_root??Re[0]?.uri_root??T1},[h,Re]),mt=(0,_e.useMemo)(()=>{if(Te)return[];let I=[];for(let q of Re){let F=N[q.uri_root]??!1;if(I.push({kind:"header",key:`h:${q.uri_root}`,info:q,expanded:F}),!F)continue;let de=AM(Ge,q.uri_root,o);if(de.length===0)I.push({kind:"empty",key:`e:${q.uri_root}`,sourceRoot:q.uri_root});else for(let D of de)I.push({kind:"node",key:`n:${D.node.uri}`,node:D.node,depth:D.depth})}if(le){let q=le.parentUri,F=-1,de=0;if(q.endsWith("://"))F=I.findIndex(D=>D.kind==="header"&&D.info.uri_root===q),de=0;else{let D=I.findIndex(xe=>xe.kind==="node"&&xe.node.uri===q);D>=0&&(F=D,de=I[D].depth+1)}F>=0&&I.splice(F+1,0,{kind:"creating",key:"creating-row",parentUri:q,createKind:le.kind,depth:de})}return I},[Ge,o,Re,N,Te,le]),Gt=(0,_e.useMemo)(()=>mt.filter(I=>I.kind==="node").map(I=>I.node.uri),[mt]),je=(0,_e.useCallback)(({node:I,additive:q,range:F})=>{K(de=>{if(F&&te){let D=Gt.indexOf(te),xe=Gt.indexOf(I.uri);if(D>=0&&xe>=0){let[Mt,zt]=D<=xe?[D,xe]:[xe,D];return new Set(Gt.slice(Mt,zt+1))}}if(q){let D=new Set(de);return D.has(I.uri)?D.delete(I.uri):D.add(I.uri),D}return new Set([I.uri])}),F||ne(I.uri)},[Gt,te]),kt=(0,_e.useCallback)(({node:I,x:q,y:F})=>{K(de=>de.has(I.uri)&&de.size>1?de:new Set([I.uri])),ne(I.uri),ze({kind:"node",node:I,x:q,y:F})},[]),on=(0,_e.useCallback)((I,q)=>{q.preventDefault(),q.stopPropagation(),A(F=>F[I]?F:{...F,[I]:!0}),ze({kind:"source",sourceRoot:I,x:q.clientX,y:q.clientY})},[]),Oe=(0,_e.useCallback)(I=>{I.target.closest('button, input, textarea, [role="menu"]')||on(vt,I)},[vt,on]),ee=(0,_e.useMemo)(()=>Ee?.kind!=="node"?[]:(B.has(Ee.node.uri)&&B.size>0?[...B]:[Ee.node.uri]).map(q=>s[q]).filter(Boolean),[Ee,B,s]),oe=(0,_e.useMemo)(()=>oo({grantedFeatures:[...r.grantedFeatures??[]]},{features:["drive.sync"]}),[r.grantedFeatures]),[He,Ve]=(0,_e.useState)(null),Ae=(0,_e.useMemo)(()=>{if(Ee?.kind==="source")return{"new-file":!0,"new-folder":qe(Ee.sourceRoot)!=="brain"};let I=ee.length===1?ee[0]:null,q=I??ee[0],F=q?q.type==="folder"?q.uri:et(q.uri):null;return{"copy-path":!!I,"copy-relative-path":!!I,reembed:!!I&&oe&&qe(I.uri)!=="brain",rename:!!I,delete:ee.length>0,"new-file":!!I,"new-folder":!!I&&qe(I.uri)!=="brain",cut:ee.length>0,copy:ee.length>0,paste:!!he&&he.uris.length>0&&!!F}},[Ee,ee,he,oe]),ce=(0,_e.useCallback)(I=>{if(Ee?.kind==="source"){(I==="new-file"||I==="new-folder")&&re({parentUri:Ee.sourceRoot,kind:I==="new-file"?"file":"folder"});return}let q=ee,F=q.length===1?q[0]:null;if(I==="copy-path"&&F)navigator.clipboard?.writeText(F.uri);else if(I==="copy-relative-path"&&F)navigator.clipboard?.writeText(F.uri.replace(/^[a-z0-9_-]+:\/\//i,""));else if(I==="reembed"&&F){let de=qe(F.uri);de&&Ve({source:de,...F.type==="folder"?{folder:F.uri}:{uri:F.uri},label:F.type==="folder"?`${F.name}/`:F.name})}else if(I==="rename"&&F)Se(F.uri);else if(I==="delete")q.length&&it({targets:q.map(de=>({uri:de.uri,id:de.id,name:de.name}))});else if(I==="cut"||I==="copy")q.length&&Ne({op:I,uris:q.map(de=>de.uri)});else if(I==="paste"){let de=F??q[0];if(de&&he){let D=de.type==="folder"?de.uri:et(de.uri);D&&(T({agentId:e,projectId:d??null,targetFolderUri:D,op:he.op,uris:he.uris}),he.op==="cut"&&Ne(null))}}else if(I==="new-file"||I==="new-folder"){let de=I==="new-file"?"file":"folder",D=F??q[0];if(!D)return;let xe=D.type==="folder"?D.uri:et(D.uri);if(!xe)return;!xe.endsWith("://")&&!o.has(xe)&&(u(xe),a.getState().ensureFolderLoaded({agentId:e,projectId:d,uri:xe})),re({parentUri:xe,kind:de})}},[Ee,ee,o,u,e,d,he,T,a]),Pt=(0,_e.useCallback)(async I=>{let q=le;if(re(null),!q)return;let F=(I??"").trim();F&&await v({agentId:e,projectId:d??null,parentUri:q.parentUri,name:F,kind:q.kind})},[le,v,e,d]),Ft=(0,_e.useCallback)(()=>re(null),[]),Zt=(0,_e.useCallback)(async({node:I,newName:q})=>{Se(null);let F=(q??"").trim();!F||F===I.name||await R({agentId:e,projectId:d??null,uri:I.uri,id:I.id,newName:F})},[R,e,d]),dn=(0,_e.useCallback)(()=>Se(null),[]),rr=(0,_e.useCallback)(async()=>{if(ct){Ye(!0);try{await U({agentId:e,projectId:d??null,targets:ct.targets.map(I=>({uri:I.uri,id:I.id}))}),K(new Set)}finally{Ye(!1),it(null)}}},[ct,U,e,d]),qr=(0,_e.useCallback)(I=>{if(!pe)if(I.key==="F2"){let q=B.size===1?[...B][0]:null;q&&s[q]&&(I.preventDefault(),Se(q))}else if(I.key==="Delete"||I.key==="Backspace"){let q=[...B].map(F=>s[F]).filter(F=>!!F);q.length&&(I.preventDefault(),it({targets:q.map(F=>({uri:F.uri,id:F.id,name:F.name}))}))}else I.key==="Escape"&&K(new Set)},[pe,B,s]),Mn=(0,_e.useCallback)(async I=>{let q=o.has(I.key);f(I.key),u(I.key),!q&&await a.getState().ensureFolderLoaded({agentId:e,projectId:d,uri:I.key})},[e,o,d,f,u,a]),Yn=(0,_e.useCallback)(I=>{I.uri&&f(et(I.uri)),c(I)},[f,c]),$r=(0,_e.useCallback)(I=>{r.clearFileMark(I)},[r]),ar=(0,_e.useCallback)(I=>{A(q=>({...q,[I]:!q[I]}))},[]),Pr=(0,_e.useCallback)(async I=>{if(!e)return;let q=a.getState();if(A(F=>F[I]?F:{...F,[I]:!0}),q.loadedFolders?.[I]){let F=qe(I);F&&await q.reconcileSourceFolders({agentId:e,projectId:d,source:F});return}await q.ensureFolderLoaded({agentId:e,projectId:d,uri:I,force:!0})},[e,d,a]);(0,_e.useEffect)(()=>{if(!e)return;let I=a.getState(),q=[];for(let F of Re)N[F.uri_root]&&q.push(F.uri_root);for(let F of o)q.push(F);for(let F of q){if(I.loadedFolders?.[F])continue;let de=I.hydrationState?.[F];de&&de!=="idle"||I.ensureFolderLoaded({agentId:e,projectId:d,uri:F})}},[e,d,Re,N,o,a]);let Kr=(0,_e.useCallback)(async({fromUri:I,id:q,toFolderUri:F})=>{await g({agentId:e,projectId:d??null,fromUri:I,toFolderUri:F,id:q})},[e,d,g]),ln=(0,_e.useMemo)(()=>Re.every(I=>!N[I.uri_root]),[Re,N]),Jn=(0,_e.useMemo)(()=>oo({grantedFeatures:[...r.grantedFeatures??[]]},{features:["drive.mount"]}),[r.grantedFeatures]),Wt=qb({agentId:e,projectId:d??void 0,enabled:Jn&&ln}),gr=ln&&Jn&&Wt.length>0,Un=(0,_e.useCallback)(I=>{at(I),ft("sources",!0)},[at,ft]),Nr=(0,_e.useCallback)(()=>Le(I=>!I),[]),pa=(0,_e.useRef)(null),fn=(0,_e.useRef)(mt);fn.current=mt;let Xr=(0,_e.useCallback)(I=>CM(fn.current[I]?.kind??"node"),[]),ma=(0,_e.useCallback)(I=>fn.current[I]?.key??I,[]),xn=lo({count:mt.length,getScrollElement:()=>pa.current,estimateSize:Xr,overscan:8,getItemKey:ma});if(n==="git")return(0,Ct.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:(0,Ct.jsx)(R1,{agentId:e})});if(y&&!ue&&!Te)return(0,Ct.jsx)("div",{className:"p-4 text-center text-xs text-white/40 animate-pulse",children:"Loading sources"});let Tn=w&&!Te?(0,Ct.jsxs)("div",{role:"status",className:"mx-2 mb-1 mt-1 flex items-start gap-2 rounded-md border border-rose-400/30 bg-rose-500/10 px-2 py-1.5 text-[11px] text-rose-100/90",children:[(0,Ct.jsx)("span",{className:"min-w-0 flex-1 break-words",children:w}),(0,Ct.jsx)("button",{type:"button",onClick:()=>{e&&_({agentId:e,projectId:d??null})},className:"shrink-0 rounded px-1 font-medium text-rose-200/80 transition-colors hover:text-rose-100",children:"Retry"}),(0,Ct.jsx)("button",{type:"button",onClick:k,"aria-label":"Dismiss",className:"shrink-0 rounded px-1 text-rose-200/70 transition-colors hover:text-rose-100",children:"\xD7"})]}):null;if(!be.length&&!Te&&!ue)return Tn??(0,Ct.jsx)("div",{className:"p-4 text-center text-xs text-white/30",children:"Empty Drive"});let z=(I,q)=>{let F=I.type==="folder",de=I.storeKey||Va(I);return(0,Ct.jsx)(iw,{node:I,depth:q,agentId:e,projectId:d,isActive:!F&&l===de,isExpanded:F&&o.has(de),badgeCount:F?i[de]:void 0,isDrop:V===de,isSelectedFolder:F&&h===de,mark:Ue[I.uri],agentIndex:me,fallbackAgent:Ot,uploading:m,packageIconBySlug:Tt,onToggleFolder:Mn,onOpenFile:Yn,onClearFileMark:$r,onSetDropTarget:Y,onUploadMany:p,onMoveFileToFolder:Kr,pendingReviewCount:F?Jt[de]:void 0,isSelected:B.has(I.uri),isCut:he?.op==="cut"&&he.uris.includes(I.uri),renaming:pe===I.uri,onNodeClick:je,onNodeContextMenu:kt,onRenameCommit:Zt,onRenameCancel:dn})};return(0,Ct.jsxs)("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[(0,Ct.jsxs)("div",{ref:pa,tabIndex:0,onKeyDown:qr,onContextMenu:Oe,className:"min-h-0 flex-1 overflow-auto pt-0 pb-2 outline-none",children:[Tn,L&&!Te?(0,Ct.jsxs)("div",{role:"status",className:"mx-2 mb-1 mt-1 flex items-start gap-2 rounded-md border border-amber-400/30 bg-amber-500/10 px-2 py-1.5 text-[11px] text-amber-100/90",children:[(0,Ct.jsx)("span",{className:"min-w-0 flex-1 break-words",children:L}),(0,Ct.jsx)("button",{type:"button",onClick:P,"aria-label":"Dismiss",className:"shrink-0 rounded px-1 text-amber-200/70 transition-colors hover:text-amber-100",children:"\xD7"})]}):null,Te?(0,Ct.jsx)(gw,{agentId:e}):null,Te?null:(0,Ct.jsx)("div",{style:{height:xn.getTotalSize(),width:"100%",position:"relative"},children:xn.getVirtualItems().map(I=>{let q=mt[I.index];if(!q)return null;let F=IM(q.kind);return(0,Ct.jsx)("div",{"data-index":I.index,ref:F?xn.measureElement:void 0,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${I.start}px)`},children:q.kind==="header"?(0,Ct.jsx)(mw,{info:q.info,expanded:q.expanded,onToggle:ar,onContextMenu:on,onRefresh:Pr,hydration:b[q.info.uri_root]??"idle",dirty:!!C[qe(q.info.uri_root)],hideChevron:!0,compact:!0}):q.kind==="empty"?(0,Ct.jsxs)("div",{className:"flex flex-col items-start gap-1.5 px-4 py-2",onContextMenu:de=>on(q.sourceRoot,de),children:[(0,Ct.jsxs)("span",{className:"text-xs text-white/35",children:["No files for ",qe(q.sourceRoot)]}),(0,Ct.jsx)(F1.SkillLauncher,{variant:"label",skill:"manage-files",packageId:"@neuralis/brain-core",scripts:["scripts/upload.sh","scripts/modify.sh"],label:"Populate this source with the agent"})]}):q.kind==="creating"?(0,Ct.jsx)(PM,{kind:q.createKind,depth:q.depth,onCommit:Pt,onCancel:Ft}):z(q.node,q.depth)},I.key)})}),Ee?(0,Ct.jsx)(lw,{x:Ee.x,y:Ee.y,variant:Ee.kind==="source"?"source":"node",enabled:Ae,onAction:ce,onClose:()=>ze(null)}):null,He?(0,Ct.jsx)(Xl,{agentId:e,...d?{projectId:d}:{},target:He,onClose:()=>Ve(null)}):null,ct?(0,Ct.jsx)(dw,{names:ct.targets.map(I=>I.name),busy:Qe,onCancel:()=>{Qe||it(null)},onConfirm:rr}):null]}),gr&&!Te?(0,Ct.jsx)(Zb,{suggestions:Wt,expanded:Lt,onToggleExpanded:Nr,onPick:Un,overlay:Lt}):null]})}function PM({kind:t,depth:e,onCommit:n,onCancel:r}){let a=(0,_e.useRef)(!1),s=t==="folder"?br:Cs;return(0,Ct.jsxs)("div",{className:"flex h-7 items-center gap-1.5 px-2",style:{paddingLeft:`${e*12+8}px`},children:[(0,Ct.jsx)("span",{className:"w-3.5 h-3.5 inline-block shrink-0"}),(0,Ct.jsx)(s,{className:"w-4 h-4 shrink-0 text-sky-300/80"}),(0,Ct.jsx)("input",{autoFocus:!0,spellCheck:!1,placeholder:t==="folder"?"Folder name":"File name",onClick:i=>i.stopPropagation(),onMouseDown:i=>i.stopPropagation(),onKeyDown:i=>{i.stopPropagation(),i.key==="Enter"?a.current||(a.current=!0,n(i.currentTarget.value)):i.key==="Escape"&&(a.current||(a.current=!0,r()))},onBlur:i=>{if(a.current)return;a.current=!0;let o=i.currentTarget.value.trim();o?n(o):r()},className:"min-w-0 flex-1 rounded border border-sky-400/60 bg-black/50 px-1 py-0 text-xs text-white outline-none placeholder:text-white/30"})]})}var yt=j($e(),1);var ZL=j(Wn(),1);function E1(t){if(!t)return{lines:new Map,deletedBefore:new Set};let e=new Map,n=new Set,r=0,a=!1,s=0,i=0,o=()=>{s>0&&i===0&&n.add(r),s=0,i=0};for(let l of t.split(`
|
|
32
|
-
`)){if(l.startsWith("@@")){o();let u=/^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(l);r=u?parseInt(u[1],10):0,a=r>0;continue}a&&(l.startsWith("+")&&!l.startsWith("+++")?(e.set(r,s>0?"modified":"added"),i++,r++):l.startsWith("-")&&!l.startsWith("---")?s++:(o(),l.startsWith(" ")&&r++))}return o(),{lines:e,deletedBefore:n}}function ld(t){return t.lines.size===0&&t.deletedBefore.size===0}var jn=j($e(),1),B1=j(Za(),1);var ou=j(ie(),1);function hp({sourceType:t,className:e}){return t==="blob"?(0,ou.jsx)("span",{title:"Blob + Vector",children:(0,ou.jsx)(zn,{className:$("w-3 h-3",e)})}):(0,ou.jsx)("span",{title:"Vector only",children:(0,ou.jsx)(ir,{className:$("w-3 h-3",e)})})}var Br=j(ie(),1);function pp({node:t,active:e,mark:n,isDirty:r,hasPendingReview:a,preview:s,pinned:i,onTogglePin:o}){let l=H(h=>h.setActiveFile),u=H(h=>h.closeFile),c=H(h=>h.activeAgentId),d=hn(),f=t.status==="deleted";return(0,Br.jsxs)("div",{className:$("group flex items-center gap-1.5 px-3 py-2 text-xs cursor-pointer min-w-[120px] max-w-[240px] rounded-lg",e?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>{l(t.storeKey||t.path),c&&n&&d.clearFileMark({agentId:c,path:t.path})},onDoubleClick:()=>o?.(),title:t.path,children:[(0,Br.jsx)(hp,{sourceType:t.sourceType,className:$("shrink-0",t.sourceType==="blob"?"text-sky-400/60":"text-violet-400/60")}),(0,Br.jsxs)("span",{className:$("truncate flex-1",s&&"italic",f&&"line-through text-white/45"),children:[t.name,r?(0,Br.jsx)("span",{className:"ml-1",style:{color:"var(--warning)"},children:"*"}):null]}),a?(0,Br.jsx)("span",{className:"inline-flex items-center rounded-full px-1.5 py-0.5 text-[9px] font-semibold bg-amber-500/15 text-amber-200",children:"REVIEW"}):n?(0,Br.jsx)("span",{className:$("inline-flex items-center rounded-full px-1.5 py-0.5 text-[9px] font-semibold",n==="new"?"bg-emerald-500/15 text-emerald-200":"bg-blue-500/15 text-blue-200"),children:n==="new"?"NEW":"MOD"}):null,i?(0,Br.jsx)("button",{onClick:h=>{h.stopPropagation(),o?.()},className:"p-0.5 rounded text-amber-300/80 hover:bg-white/10",title:"Unpin tab",children:(0,Br.jsx)(ii,{className:"w-3 h-3 fill-current"})}):(0,Br.jsx)("button",{onClick:h=>{h.stopPropagation(),u(t.storeKey||t.path)},className:$("opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10"),title:"Close (double-click tab to pin)",children:(0,Br.jsx)(Ht,{className:"w-3 h-3"})})]})}var Ln=j(ie(),1),ud="data-tab-scroller",O1="data-tab-active";function NM(t,e){return e.left<t.left?e.left-t.left:e.right>t.right?Math.min(e.right-t.right,e.left-t.left):0}function RM(t,e){return e.scrollWidth<=e.clientWidth||Math.abs(t.deltaX)>=Math.abs(t.deltaY)?0:t.deltaY}function _1(){let t=H(b=>b.openFiles),e=H(b=>b.activeFile),n=H(b=>b.files),r=H(b=>b.tabMeta),a=H(b=>b.fileContentByPath),s=H(b=>b.fileBaseContentByPath),i=H(b=>b.filePrevByPath),o=H(b=>b.activeAgentId),l=H(b=>b.reorderOpenFiles),u=H(b=>b.toggleTabPin),d=hn().useFileMarks(o??void 0)||{},[f,h]=(0,jn.useState)(null),[p,g]=(0,jn.useState)(null),m=(0,jn.useRef)(null),x=t.length>0,y=(0,jn.useCallback)(()=>{let b=m.current,C=b?.closest(`[${ud}]`),L=b?.querySelector(`[${O1}="true"]`);if(!C||!L)return;let P=NM(C.getBoundingClientRect(),L.getBoundingClientRect());P!==0&&(C.scrollLeft+=P)},[]);return(0,jn.useLayoutEffect)(()=>{y()},[e,t,y]),(0,jn.useEffect)(()=>{let b=m.current?.closest(`[${ud}]`);if(!b)return;let C=P=>{let w=RM(P,b);w!==0&&(P.preventDefault(),b.scrollLeft+=w)};b.addEventListener("wheel",C,{passive:!1});let L=typeof ResizeObserver<"u"?new ResizeObserver(()=>{b.clientWidth>0&&y()}):null;return L?.observe(b),()=>{b.removeEventListener("wheel",C),L?.disconnect()}},[x,y]),t.length===0?null:(0,Ln.jsx)("div",{ref:m,className:"flex items-center",children:t.map(b=>{let C=n[b],L=r[b],P=C?.uri??b,w=C?.name??L?.name??gt(b),k=C?.status??L?.status,_=a[b]??"",M=s[b],R=typeof M=="string"&&M!==_,v=!!i[b]&&k==="pending_review";return(0,Ln.jsx)("div",{draggable:!0,[O1]:e===b?"true":void 0,onDragStart:T=>{h(b),T.dataTransfer.effectAllowed="move";try{T.dataTransfer.setData("text/plain",b)}catch{}},onDragOver:T=>{T.preventDefault(),T.dataTransfer.dropEffect="move",p!==b&&g(b)},onDrop:T=>{T.preventDefault(),f&&f!==b&&l(f,b),h(null),g(null)},onDragEnd:()=>{h(null),g(null)},className:$("shrink-0 rounded-lg",p===b&&f&&f!==b?"ring-1 ring-violet-400/50":"",f===b?"opacity-50":""),children:(0,Ln.jsx)(pp,{node:{storeKey:C?.storeKey??b,path:P,name:w,status:k,sourceAgentId:C?.sourceAgentId??L?.sourceAgentId,sourceType:C?.sourceType},active:e===b,mark:d[P]?.kind,isDirty:R,hasPendingReview:v,preview:!!L?.preview,pinned:!!L?.pinned,onTogglePin:()=>u(b)})},b)})})}function H1(){let t=H(p=>p.openFiles),e=H(p=>p.activeFile),n=H(p=>p.closeAllFiles),r=H(p=>p.closeSavedFiles),a=H(p=>p.closeOtherFiles),s=H(p=>p.previewEditorsEnabled),i=H(p=>p.setPreviewEditorsEnabled),[o,l]=(0,jn.useState)(!1),[u,c]=(0,jn.useState)(null),d=(0,jn.useRef)(null),f=(0,jn.useRef)(null);return(0,jn.useEffect)(()=>{if(!o)return;let p=x=>{let y=x.target;d.current?.contains(y)||f.current?.contains(y)||l(!1)},g=x=>{x.key==="Escape"&&l(!1)},m=()=>l(!1);return document.addEventListener("mousedown",p),document.addEventListener("keydown",g),window.addEventListener("resize",m),window.addEventListener("scroll",m,!0),()=>{document.removeEventListener("mousedown",p),document.removeEventListener("keydown",g),window.removeEventListener("resize",m),window.removeEventListener("scroll",m,!0)}},[o]),t.length===0?null:(0,Ln.jsxs)("div",{className:"flex shrink-0 items-center border-l border-white/[0.05]",children:[(0,Ln.jsx)("button",{ref:d,type:"button",onClick:()=>{if(o){l(!1);return}let p=d.current?.getBoundingClientRect();p&&c({top:p.bottom+4,right:Math.max(4,window.innerWidth-p.right)}),l(!0)},className:$("flex items-center justify-center w-6 h-6 mx-1 rounded-md transition",o?"bg-white/10 text-white/80":"text-white/40 hover:bg-white/5 hover:text-white/70"),title:"Editor actions","aria-haspopup":"menu","aria-expanded":o,children:(0,Ln.jsx)(bs,{className:"w-4 h-4"})}),o&&u?(0,B1.createPortal)((0,Ln.jsxs)("div",{ref:f,role:"menu",style:{position:"fixed",top:u.top,right:u.right},className:"z-[1000] min-w-[190px] rounded-lg border border-white/10 bg-[#14141b] py-1 text-[11px] text-white/80 shadow-[0_18px_46px_-20px_rgba(0,0,0,0.8)]",children:[(0,Ln.jsx)(mp,{label:"Close All",onClick:()=>{n(),l(!1)}}),(0,Ln.jsx)(mp,{label:"Close Saved",onClick:()=>{r(),l(!1)}}),(0,Ln.jsx)(mp,{label:"Close Others",disabled:!e,onClick:()=>{e&&a(e),l(!1)}}),(0,Ln.jsx)("div",{className:"my-1 h-px bg-white/[0.06]"}),(0,Ln.jsxs)("button",{type:"button",role:"menuitemcheckbox","aria-checked":s,onClick:()=>i(!s),className:"flex w-full items-center gap-2 px-3 py-1.5 text-left hover:bg-white/[0.06]",children:[(0,Ln.jsx)("span",{className:"w-3.5 shrink-0 text-emerald-300",children:s?(0,Ln.jsx)(Dn,{className:"w-3.5 h-3.5"}):null}),(0,Ln.jsx)("span",{children:"Enable Preview Editors"})]})]}),document.body):null]})}function mp({label:t,onClick:e,disabled:n}){return(0,Ln.jsx)("button",{type:"button",role:"menuitem",disabled:n,onClick:e,className:"flex w-full items-center px-3 py-1.5 text-left hover:bg-white/[0.06] disabled:opacity-40 disabled:cursor-not-allowed",children:t})}var wi=j($e(),1);var dt=j(ie(),1);function MM(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function gp(t){if(!t)return null;try{return new Date(t).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"})}catch{return t}}function xp({node:t,className:e,hideVersionDiff:n=!1}){let{tags:r,category:a,createdAt:s,updatedAt:i,metadata:o,sourceAgentId:l,version:u,readSource:c}=t,d=t.uri?qe(t.uri):void 0,h=hn().useAgents(),p=(0,wi.useMemo)(()=>Ms(h),[h]),g=(0,wi.useMemo)(()=>l?p.byId.get(l)??null:null,[p,l]),m=g?.name||g?.slug,x=co(g?.id,p);if(!yp(t))return null;let b=o&&typeof o.mimeType=="string"?o.mimeType:void 0,C=o&&typeof o.size=="number"?o.size:void 0,L=$l(t),P=u?.sync,w=fi(u?.changedAt),k=vh(u?.changedAt),_=vh(P?.syncedAt);return(0,dt.jsxs)("div",{className:$("flex flex-wrap items-center gap-1.5 px-2 py-2 text-[10px]",e),style:{background:"linear-gradient(180deg, rgba(255,255,255,0.03) 0%, rgba(255,255,255,0.01) 100%)",borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,dt.jsxs)("span",{className:$("inline-flex items-center gap-1 rounded-full border px-2 py-1",L.highlightTone,"border-white/[0.07]",L.tone),children:[(0,dt.jsx)(L.icon,{className:$("w-3 h-3",L.iconTone)}),L.label]}),d?(0,dt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/60",children:[(0,dt.jsx)(Xa,{className:"w-3 h-3 text-white/35"}),(0,dt.jsx)("span",{className:"uppercase font-semibold tracking-wide",children:d})]}):null,t.os_uri?(0,dt.jsx)(TM,{value:t.os_uri}):null,m?(0,dt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/55",title:`Created by ${m}`,children:[(0,dt.jsx)(yl,{className:"w-3 h-3 text-white/35"}),(0,dt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide",style:{color:x||"var(--icon-muted)",backgroundColor:x?`${x}20`:"rgba(255,255,255,0.04)"},children:[(0,dt.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:x||"var(--icon-muted)"}}),m]})]}):null,a?(0,dt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/55",children:[(0,dt.jsx)(Tr,{className:"w-3 h-3 text-white/35"}),a]}):null,r&&r.length>0?(0,dt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/55",children:[(0,dt.jsx)(Gl,{className:"w-3 h-3 text-white/35"}),r.map(M=>(0,dt.jsx)("span",{className:"inline-flex rounded-full px-1.5 py-0.5 text-[9px] font-medium bg-white/[0.06] text-white/70",children:M},M))]}):null,b?(0,dt.jsx)("span",{className:"rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/40",children:b}):null,C?(0,dt.jsx)("span",{className:"rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/40",children:MM(C)}):null,s?(0,dt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/38",children:[(0,dt.jsx)(wa,{className:"w-3 h-3"}),gp(s)]}):null,i&&i!==s?(0,dt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/40",children:[(0,dt.jsx)(_t,{className:"w-2.5 h-2.5"}),gp(i)]}):null,u?.changedAt?(0,dt.jsxs)("span",{className:$("inline-flex items-center gap-1 rounded-full border px-2 py-1",w.pillClassName),children:[(0,dt.jsx)(wa,{className:$("w-3 h-3",w.iconClassName)}),"changed ",k?`${k} ago`:gp(u.changedAt)]}):null,!n&&u?.diff?(0,dt.jsxs)("span",{className:$("inline-flex items-center gap-1 rounded-full border px-2 py-1",w.pillClassName),children:[(0,dt.jsx)(or,{className:$("w-3 h-3",w.iconClassName)}),(0,dt.jsxs)("span",{className:"text-emerald-200/95",children:["+",u.diff.added]}),(0,dt.jsx)("span",{className:"text-white/25",children:"/"}),(0,dt.jsxs)("span",{className:"text-rose-200/95",children:["-",u.diff.removed]})]}):null,_?(0,dt.jsxs)("span",{className:"rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/38",children:["synced ",_," ago"]}):null]})}function TM({value:t}){let[e,n]=(0,wi.useState)(!1),r=(0,wi.useCallback)(()=>{navigator.clipboard.writeText(t).then(()=>{n(!0),setTimeout(()=>n(!1),1500)}).catch(()=>{})},[t]),a=t.length>60?"..."+t.slice(-57):t;return(0,dt.jsxs)("button",{type:"button",onClick:r,title:t,className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/45 hover:text-white/70 hover:bg-white/[0.06] transition-colors cursor-pointer",children:[e?(0,dt.jsx)(na,{className:"w-3 h-3 text-emerald-300/80"}):(0,dt.jsx)(zn,{className:"w-3 h-3 text-white/35"}),(0,dt.jsx)("span",{className:"font-mono truncate max-w-[280px]",children:a})]})}function yp(t){let{tags:e,category:n,createdAt:r,updatedAt:a,metadata:s,sourceAgentId:i,version:o}=t,l=t.uri?qe(t.uri):void 0;return!!i||!!e?.length||!!n||!!l||!!t.os_uri||!!r||!!a||!!o||!!(s&&Object.keys(s).length>0)}var xf=j($e(),1);var wp=[],z1=[];(()=>{let t="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,1n,9,16,o,,x,1i,3,,i,,7,a,2,t,3,1k,,,7,2,2,2,3,9,,a,2,q,,2,3,1k,,,5,4,2,2,3,3,,u,2,3,,b,3,1k,,,8,,3,,3,k,2,m,6,,3,1k,,,7,2,2,2,3,7,3,a,2,u,,1n,5,3,3,,4,9,,14,5,1j,,,7,,3,,4,7,2,b,2,t,3,1k,,,7,,3,,4,7,2,b,2,f,,c,4,1j,2,,7,,3,,4,9,,a,2,t,3,1y,,4,6,,,,8,i,2,1p,,,8,c,8,2q,,,a,b,7,21,2,r,,,,,,4,2,1d,k,,2,5,b,,10,9,,2u,b,,6,n,4,4,3,g,4,d,,,3,6,,f,,jj,3,qa,4,s,3,t,2,u,2,1s,w,9,,19,3,,,39,2,y,,3a,c,4,c,63,5,1l,a,,,,,2,o,2,,1c,1a,2,c,k,5,1b,h,12,9,c,3,u,d,1k,e,1c,k,48,3,,l,4,,6,,2,3,5i,1s,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,n,5,4,,2b,2,1e,i,q,i,d,,12,8,p,d,18,4,1b,e,10,,1v,e,c,,8,2,1a,,1f,,,3,2,2,5,2,,,15,5,5,2,6k,8,,2,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,1t,5,8t,2,25,6,1y,b,1d,4,3e,3,1h,f,15,,2,2,a,4,19,b,7,,1p,3,10,e,g,2,18,,c,3,1c,e,8,4,,2,2k,c,6,,2,,4d,c,l,4,1j,2,,7,2,2,2,3,9,,a,2,2,7,3,5,1v,9,,,2,,,4,,5,,,e,2,2a,i,n,,29,k,6j,7,2,9,r,2,2a,h,2y,d,2t,3,2,a,74,f,6t,6,,2,2,4,,,,2,3x,7,2,7,3,,s,a,14,7,,4,8,,9,b,1a,g,5i,8,5j,8,,8,2a,m,,e,3e,6,3,,,2,,7,,,1u,5,,2,,5,9n,4,9,2,,,1c,7,3,5,n,,44l,,6,f,8ug,i,1xc,5,1n,7,t4,,,1j,7,4,29,,b,2,f57,2,3mp,1a,2,n,f2,5,3,6,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,2s,,4g,7,af,,1p,4,e4,4,72,2,6r,,2,,7,2,5,,d6,7,31,7,240,5".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,n=0;e<t.length;e++)(e%2?z1:wp).push(n=n+t[e])})();function DM(t){if(t<768)return!1;for(let e=0,n=wp.length;;){let r=e+n>>1;if(t<wp[r])n=r;else if(t>=z1[r])e=r+1;else return!0;if(e==n)return!1}}function U1(t){return t>=127462&&t<=127487}var G1=8205;function j1(t,e,n=!0,r=!0){return(n?V1:FM)(t,e,r)}function V1(t,e,n){if(e==t.length)return e;e&&q1(t.charCodeAt(e))&&$1(t.charCodeAt(e-1))&&e--;let r=bp(t,e);for(e+=W1(r);e<t.length;){let a=bp(t,e);if(r==G1||a==G1||n&&DM(a))e+=W1(a),r=a;else if(U1(a)){let s=0,i=e-2;for(;i>=0&&U1(bp(t,i));)s++,i-=2;if(s%2==0)break;e+=2}else break}return e}function FM(t,e,n){for(;e>1;){let r=V1(t,e-2,n);if(r<e)return r;e--}return 0}function bp(t,e){let n=t.charCodeAt(e);if(!$1(n)||e+1==t.length)return n;let r=t.charCodeAt(e+1);return q1(r)?(n-55296<<10)+(r-56320)+65536:n}function q1(t){return t>=56320&&t<57344}function $1(t){return t>=55296&&t<56320}function W1(t){return t<65536?1:2}var st=class t{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,n,r){[e,n]=Po(this,e,n);let a=[];return this.decompose(0,e,a,2),r.length&&r.decompose(0,r.length,a,3),this.decompose(n,this.length,a,1),Io.from(a,this.length-(n-e)+r.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,n=this.length){[e,n]=Po(this,e,n);let r=[];return this.decompose(e,n,r,0),Io.from(r,n-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let n=this.scanIdentical(e,1),r=this.length-this.scanIdentical(e,-1),a=new Ci(this),s=new Ci(e);for(let i=n,o=n;;){if(a.next(i),s.next(i),i=0,a.lineBreak!=s.lineBreak||a.done!=s.done||a.value!=s.value)return!1;if(o+=a.value.length,a.done||o>=r)return!0}}iter(e=1){return new Ci(this,e)}iterRange(e,n=this.length){return new pd(this,e,n)}iterLines(e,n){let r;if(e==null)r=this.iter();else{n==null&&(n=this.lines+1);let a=this.line(e).from;r=this.iterRange(a,Math.max(a,n==this.lines+1?this.length:n<=1?0:this.line(n-1).to))}return new md(r)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?t.empty:e.length<=32?new Sr(e):Io.from(Sr.split(e,[]))}},Sr=class t extends st{constructor(e,n=EM(e)){super(),this.text=e,this.length=n}get lines(){return this.text.length}get children(){return null}lineInner(e,n,r,a){for(let s=0;;s++){let i=this.text[s],o=a+i.length;if((n?r:o)>=e)return new kp(a,o,r,i);a=o+1,r++}}decompose(e,n,r,a){let s=e<=0&&n>=this.length?this:new t(K1(this.text,e,n),Math.min(n,this.length)-Math.max(0,e));if(a&1){let i=r.pop(),o=hd(s.text,i.text.slice(),0,s.length);if(o.length<=32)r.push(new t(o,i.length+s.length));else{let l=o.length>>1;r.push(new t(o.slice(0,l)),new t(o.slice(l)))}}else r.push(s)}replace(e,n,r){if(!(r instanceof t))return super.replace(e,n,r);[e,n]=Po(this,e,n);let a=hd(this.text,hd(r.text,K1(this.text,0,e)),n),s=this.length+r.length-(n-e);return a.length<=32?new t(a,s):Io.from(t.split(a,[]),s)}sliceString(e,n=this.length,r=`
|
|
33
|
-
`){[e,n]=
|
|
34
|
-
`){[e,n]=
|
|
35
|
-
`,this;e--}else if(a instanceof Sr){let l=a.text[i+(n<0?-1:0)];if(this.offsets[r]+=n,l.length>Math.max(0,e))return this.value=e==0?l:n>0?l.slice(e):l.slice(0,l.length-e),this;e-=l.length}else{let l=a.children[i+(n<0?-1:0)];e>l.length?(e-=l.length,this.offsets[r]+=n):(n<0&&this.offsets[r]--,this.nodes.push(l),this.offsets.push(n>0?1:(l instanceof Sr?l.text.length:l.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}},pd=class{constructor(e,n,r){this.value="",this.done=!1,this.cursor=new Ci(e,n>r?-1:1),this.pos=n>r?e.length:0,this.from=Math.min(n,r),this.to=Math.max(n,r)}nextInner(e,n){if(n<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,n<0?this.pos-this.to:this.from-this.pos);let r=n<0?this.pos-this.from:this.to-this.pos;e>r&&(e=r),r-=e;let{value:a}=this.cursor.next(e);return this.pos+=(a.length+e)*n,this.value=a.length<=r?a:n<0?a.slice(a.length-r):a.slice(0,r),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}},md=class{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:n,lineBreak:r,value:a}=this.inner.next(e);return n&&this.afterBreak?(this.value="",this.afterBreak=!1):n?(this.done=!0,this.value=""):r?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=a,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol<"u"&&(st.prototype[Symbol.iterator]=function(){return this.iter()},Ci.prototype[Symbol.iterator]=pd.prototype[Symbol.iterator]=md.prototype[Symbol.iterator]=function(){return this});var kp=class{constructor(e,n,r,a){this.from=e,this.to=n,this.number=r,this.text=a}get length(){return this.to-this.from}};function Po(t,e,n){return e=Math.max(0,Math.min(t.length,e)),[e,Math.max(e,Math.min(t.length,n))]}function Pn(t,e,n=!0,r=!0){return j1(t,e,n,r)}function OM(t){return t>=56320&&t<57344}function BM(t){return t>=55296&&t<56320}function Q1(t,e){let n=t.charCodeAt(e);if(!BM(n)||e+1==t.length)return n;let r=t.charCodeAt(e+1);return OM(r)?(n-55296<<10)+(r-56320)+65536:n}function ek(t){return t<65536?1:2}var Sp=/\r\n?|\n/,cr=(function(t){return t[t.Simple=0]="Simple",t[t.TrackDel=1]="TrackDel",t[t.TrackBefore=2]="TrackBefore",t[t.TrackAfter=3]="TrackAfter",t})(cr||(cr={})),rs=class t{constructor(e){this.sections=e}get length(){let e=0;for(let n=0;n<this.sections.length;n+=2)e+=this.sections[n];return e}get newLength(){let e=0;for(let n=0;n<this.sections.length;n+=2){let r=this.sections[n+1];e+=r<0?this.sections[n]:r}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let n=0,r=0,a=0;n<this.sections.length;){let s=this.sections[n++],i=this.sections[n++];i<0?(e(r,a,s),a+=s):a+=i,r+=s}}iterChangedRanges(e,n=!1){Cp(this,e,n)}get invertedDesc(){let e=[];for(let n=0;n<this.sections.length;){let r=this.sections[n++],a=this.sections[n++];a<0?e.push(r,a):e.push(a,r)}return new t(e)}composeDesc(e){return this.empty?e:e.empty?this:tk(this,e)}mapDesc(e,n=!1){return e.empty?this:Ip(this,e,n)}mapPos(e,n=-1,r=cr.Simple){let a=0,s=0;for(let i=0;i<this.sections.length;){let o=this.sections[i++],l=this.sections[i++],u=a+o;if(l<0){if(u>e)return s+(e-a);s+=o}else{if(r!=cr.Simple&&u>=e&&(r==cr.TrackDel&&a<e&&u>e||r==cr.TrackBefore&&a<e||r==cr.TrackAfter&&u>e))return null;if(u>e||u==e&&n<0&&!o)return e==a||n<0?s:s+l;s+=l}a=u}if(e>a)throw new RangeError(`Position ${e} is out of range for changeset of length ${a}`);return s}touchesRange(e,n=e){for(let r=0,a=0;r<this.sections.length&&a<=n;){let s=this.sections[r++],i=this.sections[r++],o=a+s;if(i>=0&&a<=n&&o>=e)return a<e&&o>n?"cover":!0;a=o}return!1}toString(){let e="";for(let n=0;n<this.sections.length;){let r=this.sections[n++],a=this.sections[n++];e+=(e?" ":"")+r+(a>=0?":"+a:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(n=>typeof n!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new t(e)}static create(e){return new t(e)}},Nn=class t extends rs{constructor(e,n){super(e),this.inserted=n}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return Cp(this,(n,r,a,s,i)=>e=e.replace(a,a+(r-n),i),!1),e}mapDesc(e,n=!1){return Ip(this,e,n,!0)}invert(e){let n=this.sections.slice(),r=[];for(let a=0,s=0;a<n.length;a+=2){let i=n[a],o=n[a+1];if(o>=0){n[a]=o,n[a+1]=i;let l=a>>1;for(;r.length<l;)r.push(st.empty);r.push(i?e.slice(s,s+i):st.empty)}s+=i}return new t(n,r)}compose(e){return this.empty?e:e.empty?this:tk(this,e,!0)}map(e,n=!1){return e.empty?this:Ip(this,e,n,!0)}iterChanges(e,n=!1){Cp(this,e,n)}get desc(){return rs.create(this.sections)}filter(e){let n=[],r=[],a=[],s=new Ii(this);e:for(let i=0,o=0;;){let l=i==e.length?1e9:e[i++];for(;o<l||o==l&&s.len==0;){if(s.done)break e;let c=Math.min(s.len,l-o);Vn(a,c,-1);let d=s.ins==-1?-1:s.off==0?s.ins:0;Vn(n,c,d),d>0&&Hs(r,n,s.text),s.forward(c),o+=c}let u=e[i++];for(;o<u;){if(s.done)break e;let c=Math.min(s.len,u-o);Vn(n,c,-1),Vn(a,c,s.ins==-1?-1:s.off==0?s.ins:0),s.forward(c),o+=c}}return{changes:new t(n,r),filtered:rs.create(a)}}toJSON(){let e=[];for(let n=0;n<this.sections.length;n+=2){let r=this.sections[n],a=this.sections[n+1];a<0?e.push(r):a==0?e.push([r]):e.push([r].concat(this.inserted[n>>1].toJSON()))}return e}static of(e,n,r){let a=[],s=[],i=0,o=null;function l(c=!1){if(!c&&!a.length)return;i<n&&Vn(a,n-i,-1);let d=new t(a,s);o=o?o.compose(d.map(o)):d,a=[],s=[],i=0}function u(c){if(Array.isArray(c))for(let d of c)u(d);else if(c instanceof t){if(c.length!=n)throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${n})`);l(),o=o?o.compose(c.map(o)):c}else{let{from:d,to:f=d,insert:h}=c;if(d>f||d<0||f>n)throw new RangeError(`Invalid change range ${d} to ${f} (in doc of length ${n})`);let p=h?typeof h=="string"?st.of(h.split(r||Sp)):h:st.empty,g=p.length;if(d==f&&g==0)return;d<i&&l(),d>i&&Vn(a,d-i,-1),Vn(a,f-d,g),Hs(s,a,p),i=f}}return u(e),l(!o),o}static empty(e){return new t(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let n=[],r=[];for(let a=0;a<e.length;a++){let s=e[a];if(typeof s=="number")n.push(s,-1);else{if(!Array.isArray(s)||typeof s[0]!="number"||s.some((i,o)=>o&&typeof i!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(s.length==1)n.push(s[0],0);else{for(;r.length<a;)r.push(st.empty);r[a]=st.of(s.slice(1)),n.push(s[0],r[a].length)}}}return new t(n,r)}static createSet(e,n){return new t(e,n)}};function Vn(t,e,n,r=!1){if(e==0&&n<=0)return;let a=t.length-2;a>=0&&n<=0&&n==t[a+1]?t[a]+=e:a>=0&&e==0&&t[a]==0?t[a+1]+=n:r?(t[a]+=e,t[a+1]+=n):t.push(e,n)}function Hs(t,e,n){if(n.length==0)return;let r=e.length-2>>1;if(r<t.length)t[t.length-1]=t[t.length-1].append(n);else{for(;t.length<r;)t.push(st.empty);t.push(n)}}function Cp(t,e,n){let r=t.inserted;for(let a=0,s=0,i=0;i<t.sections.length;){let o=t.sections[i++],l=t.sections[i++];if(l<0)a+=o,s+=o;else{let u=a,c=s,d=st.empty;for(;u+=o,c+=l,l&&r&&(d=d.append(r[i-2>>1])),!(n||i==t.sections.length||t.sections[i+1]<0);)o=t.sections[i++],l=t.sections[i++];e(a,u,s,c,d),a=u,s=c}}}function Ip(t,e,n,r=!1){let a=[],s=r?[]:null,i=new Ii(t),o=new Ii(e);for(let l=-1;;){if(i.done&&o.len||o.done&&i.len)throw new Error("Mismatched change set lengths");if(i.ins==-1&&o.ins==-1){let u=Math.min(i.len,o.len);Vn(a,u,-1),i.forward(u),o.forward(u)}else if(o.ins>=0&&(i.ins<0||l==i.i||i.off==0&&(o.len<i.len||o.len==i.len&&!n))){let u=o.len;for(Vn(a,o.ins,-1);u;){let c=Math.min(i.len,u);i.ins>=0&&l<i.i&&i.len<=c&&(Vn(a,0,i.ins),s&&Hs(s,a,i.text),l=i.i),i.forward(c),u-=c}o.next()}else if(i.ins>=0){let u=0,c=i.len;for(;c;)if(o.ins==-1){let d=Math.min(c,o.len);u+=d,c-=d,o.forward(d)}else if(o.ins==0&&o.len<c)c-=o.len,o.next();else break;Vn(a,u,l<i.i?i.ins:0),s&&l<i.i&&Hs(s,a,i.text),l=i.i,i.forward(i.len-c)}else{if(i.done&&o.done)return s?Nn.createSet(a,s):rs.create(a);throw new Error("Mismatched change set lengths")}}}function tk(t,e,n=!1){let r=[],a=n?[]:null,s=new Ii(t),i=new Ii(e);for(let o=!1;;){if(s.done&&i.done)return a?Nn.createSet(r,a):rs.create(r);if(s.ins==0)Vn(r,s.len,0,o),s.next();else if(i.len==0&&!i.done)Vn(r,0,i.ins,o),a&&Hs(a,r,i.text),i.next();else{if(s.done||i.done)throw new Error("Mismatched change set lengths");{let l=Math.min(s.len2,i.len),u=r.length;if(s.ins==-1){let c=i.ins==-1?-1:i.off?0:i.ins;Vn(r,l,c,o),a&&c&&Hs(a,r,i.text)}else i.ins==-1?(Vn(r,s.off?0:s.len,l,o),a&&Hs(a,r,s.textBit(l))):(Vn(r,s.off?0:s.len,i.off?0:i.ins,o),a&&!i.off&&Hs(a,r,i.text));o=(s.ins>l||i.ins>=0&&i.len>l)&&(o||r.length>u),s.forward2(l),i.forward(l)}}}}var Ii=class{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,n=this.i-2>>1;return n>=e.length?st.empty:e[n]}textBit(e){let{inserted:n}=this.set,r=this.i-2>>1;return r>=n.length&&!e?st.empty:n[r].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}},vi=class t{constructor(e,n,r,a){this.from=e,this.to=n,this.flags=r,this.goalColumn=a}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get undirectional(){return(this.flags&64)>0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}map(e,n=-1){let r,a;return this.empty?r=a=e.mapPos(this.from,n):(r=e.mapPos(this.from,1),a=e.mapPos(this.to,-1)),r==this.from&&a==this.to?this:new t(r,a,this.flags,this.goalColumn)}extend(e,n=e,r=0){if(e<=this.anchor&&n>=this.anchor)return se.range(e,n,void 0,void 0,r);let a=Math.abs(e-this.anchor)>Math.abs(n-this.anchor)?e:n;return se.range(this.anchor,a,void 0,void 0,r)}eq(e,n=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!n||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return se.range(e.anchor,e.head)}static create(e,n,r,a){return new t(e,n,r,a)}},se=class t{constructor(e,n){this.ranges=e,this.mainIndex=n}map(e,n=-1){return e.empty?this:t.create(this.ranges.map(r=>r.map(e,n)),this.mainIndex)}eq(e,n=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let r=0;r<this.ranges.length;r++)if(!this.ranges[r].eq(e.ranges[r],n))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new t([this.main],0)}addRange(e,n=!0){return t.create([e].concat(this.ranges),n?0:this.mainIndex+1)}replaceRange(e,n=this.mainIndex){let r=this.ranges.slice();return r[n]=e,t.create(r,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new t(e.ranges.map(n=>vi.fromJSON(n)),e.main)}static single(e,n=e){return new t([t.range(e,n)],0)}static create(e,n=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let r=0,a=0;a<e.length;a++){let s=e[a];if(s.empty?s.from<=r:s.from<r)return t.normalized(e.slice(),n);r=s.to}return new t(e,n)}static cursor(e,n=0,r,a){return vi.create(e,e,(n==0?0:n<0?8:16)|(r==null?7:Math.min(6,r)),a)}static range(e,n,r,a,s){let i=a==null?7:Math.min(6,a);return!s&&e!=n&&(s=n<e?1:-1),s&&(i|=s<0?8:16),n<e?vi.create(n,e,i|32,r):vi.create(e,n,i,r)}static undirectionalRange(e,n){return vi.create(e,n,64,void 0)}static normalized(e,n=0){let r=e[n];e.sort((a,s)=>a.from-s.from),n=e.indexOf(r);for(let a=1;a<e.length;a++){let s=e[a],i=e[a-1];if(s.empty?s.from<=i.to:s.from<i.to){let o=i.from,l=Math.max(s.to,i.to);a<=n&&n--,e.splice(--a,2,s.anchor>s.head?t.range(l,o):t.range(o,l))}}return new t(e,n)}};function nk(t,e){for(let n of t.ranges)if(n.to>e)throw new RangeError("Selection points outside of document")}var Ep=0,Me=class t{constructor(e,n,r,a,s){this.combine=e,this.compareInput=n,this.compare=r,this.isStatic=a,this.id=Ep++,this.default=e([]),this.extensions=typeof s=="function"?s(this):s}get reader(){return this}static define(e={}){return new t(e.combine||(n=>n),e.compareInput||((n,r)=>n===r),e.compare||(e.combine?(n,r)=>n===r:Op),!!e.static,e.enables)}of(e){return new Lo([],this,0,e)}compute(e,n){if(this.isStatic)throw new Error("Can't compute a static facet");return new Lo(e,this,1,n)}computeN(e,n){if(this.isStatic)throw new Error("Can't compute a static facet");return new Lo(e,this,2,n)}from(e,n){return n||(n=r=>r),this.compute([e],r=>n(r.field(e)))}};function Op(t,e){return t==e||t.length==e.length&&t.every((n,r)=>n===e[r])}var Lo=class{constructor(e,n,r,a){this.dependencies=e,this.facet=n,this.type=r,this.value=a,this.id=Ep++}dynamicSlot(e){var n;let r=this.value,a=this.facet.compareInput,s=this.id,i=e[s]>>1,o=this.type==2,l=!1,u=!1,c=[];for(let d of this.dependencies)d=="doc"?l=!0:d=="selection"?u=!0:(((n=e[d.id])!==null&&n!==void 0?n:1)&1)==0&&c.push(e[d.id]);return{create(d){return d.values[i]=r(d),1},update(d,f){if(l&&f.docChanged||u&&(f.docChanged||f.selection)||Lp(d,c)){let h=r(d);if(o?!X1(h,d.values[i],a):!a(h,d.values[i]))return d.values[i]=h,1}return 0},reconfigure:(d,f)=>{let h,p=f.config.address[s];if(p!=null){let g=yd(f,p);if(this.dependencies.every(m=>m instanceof Me?f.facet(m)===d.facet(m):m instanceof vn?f.field(m,!1)==d.field(m,!1):!0)||(o?X1(h=r(d),g,a):a(h=r(d),g)))return d.values[i]=g,0}else h=r(d);return d.values[i]=h,1}}}get extension(){return this}};function X1(t,e,n){if(t.length!=e.length)return!1;for(let r=0;r<t.length;r++)if(!n(t[r],e[r]))return!1;return!0}function Lp(t,e){let n=!1;for(let r of e)uu(t,r)&1&&(n=!0);return n}function _M(t,e,n){let r=n.map(l=>t[l.id]),a=n.map(l=>l.type),s=r.filter(l=>!(l&1)),i=t[e.id]>>1;function o(l){let u=[];for(let c=0;c<r.length;c++){let d=yd(l,r[c]);if(a[c]==2)for(let f of d)u.push(f);else u.push(d)}return e.combine(u)}return{create(l){for(let u of r)uu(l,u);return l.values[i]=o(l),1},update(l,u){if(!Lp(l,s))return 0;let c=o(l);return e.compare(c,l.values[i])?0:(l.values[i]=c,1)},reconfigure(l,u){let c=Lp(l,r),d=u.config.facets[e.id],f=u.facet(e);if(d&&!c&&Op(n,d))return l.values[i]=f,0;let h=o(l);return e.compare(h,f)?(l.values[i]=f,0):(l.values[i]=h,1)}}}var cd=Me.define({static:!0}),vn=class t{constructor(e,n,r,a,s){this.id=e,this.createF=n,this.updateF=r,this.compareF=a,this.spec=s,this.provides=void 0}static define(e){let n=new t(Ep++,e.create,e.update,e.compare||((r,a)=>r===a),e);return e.provide&&(n.provides=e.provide(n)),n}create(e){let n=e.facet(cd).find(r=>r.field==this);return(n?.create||this.createF)(e)}slot(e){let n=e[this.id]>>1;return{create:r=>(r.values[n]=this.create(r),1),update:(r,a)=>{let s=r.values[n],i=this.updateF(s,a);return this.compareF(s,i)?0:(r.values[n]=i,1)},reconfigure:(r,a)=>{let s=r.facet(cd),i=a.facet(cd),o;return(o=s.find(l=>l.field==this))&&o!=i.find(l=>l.field==this)?(r.values[n]=o.create(r),1):a.config.address[this.id]!=null?(r.values[n]=a.field(this),0):(r.values[n]=this.create(r),1)}}}init(e){return[this,cd.of({field:this,create:e})]}get extension(){return this}},ki={lowest:4,low:3,default:2,high:1,highest:0};function lu(t){return e=>new gd(e,t)}var Ma={highest:lu(ki.highest),high:lu(ki.high),default:lu(ki.default),low:lu(ki.low),lowest:lu(ki.lowest)},gd=class{constructor(e,n){this.inner=e,this.prec=n}get extension(){return this}},_r=class t{of(e){return new cu(this,e)}reconfigure(e){return t.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}},cu=class{constructor(e,n){this.compartment=e,this.inner=n}get extension(){return this}},xd=class t{constructor(e,n,r,a,s,i){for(this.base=e,this.compartments=n,this.dynamicSlots=r,this.address=a,this.staticValues=s,this.facets=i,this.statusTemplate=[];this.statusTemplate.length<r.length;)this.statusTemplate.push(0)}staticFacet(e){let n=this.address[e.id];return n==null?e.default:this.staticValues[n>>1]}static resolve(e,n,r){let a=[],s=Object.create(null),i=new Map;for(let f of HM(e,n,i))f instanceof vn?a.push(f):(s[f.facet.id]||(s[f.facet.id]=[])).push(f);let o=Object.create(null),l=[],u=[];for(let f of a)o[f.id]=u.length<<1,u.push(h=>f.slot(h));let c=r?.config.facets;for(let f in s){let h=s[f],p=h[0].facet,g=c&&c[f]||[];if(h.every(m=>m.type==0))if(o[p.id]=l.length<<1|1,Op(g,h))l.push(r.facet(p));else{let m=p.combine(h.map(x=>x.value));l.push(r&&p.compare(m,r.facet(p))?r.facet(p):m)}else{for(let m of h)m.type==0?(o[m.id]=l.length<<1|1,l.push(m.value)):(o[m.id]=u.length<<1,u.push(x=>m.dynamicSlot(x)));o[p.id]=u.length<<1,u.push(m=>_M(m,p,h))}}let d=u.map(f=>f(o));return new t(e,i,d,o,l,s)}};function HM(t,e,n){let r=[[],[],[],[],[]],a=new Map;function s(i,o){let l=a.get(i);if(l!=null){if(l<=o)return;let u=r[l].indexOf(i);u>-1&&r[l].splice(u,1),i instanceof cu&&n.delete(i.compartment)}if(a.set(i,o),Array.isArray(i))for(let u of i)s(u,o);else if(i instanceof cu){if(n.has(i.compartment))throw new RangeError("Duplicate use of compartment in extensions");let u=e.get(i.compartment)||i.inner;n.set(i.compartment,u),s(u,o)}else if(i instanceof gd)s(i.inner,i.prec);else if(i instanceof vn)r[o].push(i),i.provides&&s(i.provides,o);else if(i instanceof Lo)r[o].push(i),i.facet.extensions&&s(i.facet.extensions,ki.default);else{let u=i.extension;if(!u)throw new Error(`Unrecognized extension value in extension set (${i}).`);if(u==i)throw new Error(`Unrecognized extension value in extension set (${i}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);s(u,o)}}return s(t,ki.default),r.reduce((i,o)=>i.concat(o))}function uu(t,e){if(e&1)return 2;let n=e>>1,r=t.status[n];if(r==4)throw new Error("Cyclic dependency between fields and/or facets");if(r&2)return r;t.status[n]=4;let a=t.computeSlot(t,t.config.dynamicSlots[n]);return t.status[n]=2|a}function yd(t,e){return e&1?t.config.staticValues[e>>1]:t.values[e>>1]}var rk=Me.define(),Ap=Me.define({combine:t=>t.some(e=>e),static:!0}),ak=Me.define({combine:t=>t.length?t[0]:void 0,static:!0}),sk=Me.define(),ik=Me.define(),ok=Me.define(),lk=Me.define({combine:t=>t.length?t[0]:!1}),Hr=class{constructor(e,n){this.type=e,this.value=n}static define(){return new Pp}},Pp=class{of(e){return new Hr(this,e)}},Np=class{constructor(e){this.map=e}of(e){return new pt(this,e)}},pt=class t{constructor(e,n){this.type=e,this.value=n}map(e){let n=this.type.map(this.value,e);return n===void 0?void 0:n==this.value?this:new t(this.type,n)}is(e){return this.type==e}static define(e={}){return new Np(e.map||(n=>n))}static mapEffects(e,n){if(!e.length)return e;let r=[];for(let a of e){let s=a.map(n);s&&r.push(s)}return r}};pt.reconfigure=pt.define();pt.appendConfig=pt.define();var An=class t{constructor(e,n,r,a,s,i){this.startState=e,this.changes=n,this.selection=r,this.effects=a,this.annotations=s,this.scrollIntoView=i,this._doc=null,this._state=null,r&&nk(r,n.newLength),s.some(o=>o.type==t.time)||(this.annotations=s.concat(t.time.of(Date.now())))}static create(e,n,r,a,s,i){return new t(e,n,r,a,s,i)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let n of this.annotations)if(n.type==e)return n.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let n=this.annotation(t.userEvent);return!!(n&&(n==e||n.length>e.length&&n.slice(0,e.length)==e&&n[e.length]=="."))}};An.time=Hr.define();An.userEvent=Hr.define();An.addToHistory=Hr.define();An.remote=Hr.define();function UM(t,e){let n=[];for(let r=0,a=0;;){let s,i;if(r<t.length&&(a==e.length||e[a]>=t[r]))s=t[r++],i=t[r++];else if(a<e.length)s=e[a++],i=e[a++];else return n;!n.length||n[n.length-1]<s?n.push(s,i):n[n.length-1]<i&&(n[n.length-1]=i)}}function uk(t,e,n){var r;let a,s,i;return n?(a=e.changes,s=Nn.empty(e.changes.length),i=t.changes.compose(e.changes)):(a=e.changes.map(t.changes),s=t.changes.mapDesc(e.changes,!0),i=t.changes.compose(a)),{changes:i,selection:e.selection?e.selection.map(s):(r=t.selection)===null||r===void 0?void 0:r.map(a),effects:pt.mapEffects(t.effects,a).concat(pt.mapEffects(e.effects,s)),annotations:t.annotations.length?t.annotations.concat(e.annotations):e.annotations,scrollIntoView:t.scrollIntoView||e.scrollIntoView}}function Rp(t,e,n){let r=e.selection,a=Ao(e.annotations);return e.userEvent&&(a=a.concat(An.userEvent.of(e.userEvent))),{changes:e.changes instanceof Nn?e.changes:Nn.of(e.changes||[],n,t.facet(ak)),selection:r&&(r instanceof se?r:se.single(r.anchor,r.head)),effects:Ao(e.effects),annotations:a,scrollIntoView:!!e.scrollIntoView}}function ck(t,e,n){let r=Rp(t,e.length?e[0]:{},t.doc.length);e.length&&e[0].filter===!1&&(n=!1);for(let s=1;s<e.length;s++){e[s].filter===!1&&(n=!1);let i=!!e[s].sequential;r=uk(r,Rp(t,e[s],i?r.changes.newLength:t.doc.length),i)}let a=An.create(t,r.changes,r.selection,r.effects,r.annotations,r.scrollIntoView);return WM(n?GM(a):a)}function GM(t){let e=t.startState,n=!0;for(let a of e.facet(sk)){let s=a(t);if(s===!1){n=!1;break}Array.isArray(s)&&(n=n===!0?s:UM(n,s))}if(n!==!0){let a,s;if(n===!1)s=t.changes.invertedDesc,a=Nn.empty(e.doc.length);else{let i=t.changes.filter(n);a=i.changes,s=i.filtered.mapDesc(i.changes).invertedDesc}t=An.create(e,a,t.selection&&t.selection.map(s),pt.mapEffects(t.effects,s),t.annotations,t.scrollIntoView)}let r=e.facet(ik);for(let a=r.length-1;a>=0;a--){let s=r[a](t);s instanceof An?t=s:Array.isArray(s)&&s.length==1&&s[0]instanceof An?t=s[0]:t=ck(e,Ao(s),!1)}return t}function WM(t){let e=t.startState,n=e.facet(ok),r=t;for(let a=n.length-1;a>=0;a--){let s=n[a](t);s&&Object.keys(s).length&&(r=uk(r,Rp(e,s,t.changes.newLength),!0))}return r==t?t:An.create(e,t.changes,t.selection,r.effects,r.annotations,r.scrollIntoView)}var zM=[];function Ao(t){return t==null?zM:Array.isArray(t)?t:[t]}var sa=(function(t){return t[t.Word=0]="Word",t[t.Space=1]="Space",t[t.Other=2]="Other",t})(sa||(sa={})),jM=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,Mp;try{Mp=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function VM(t){if(Mp)return Mp.test(t);for(let e=0;e<t.length;e++){let n=t[e];if(/\w/.test(n)||n>"\x80"&&(n.toUpperCase()!=n.toLowerCase()||jM.test(n)))return!0}return!1}function qM(t){return e=>{if(!/\S/.test(e))return sa.Space;if(VM(e))return sa.Word;for(let n=0;n<t.length;n++)if(e.indexOf(t[n])>-1)return sa.Word;return sa.Other}}var It=class t{constructor(e,n,r,a,s,i){this.config=e,this.doc=n,this.selection=r,this.values=a,this.status=e.statusTemplate.slice(),this.computeSlot=s,i&&(i._state=this);for(let o=0;o<this.config.dynamicSlots.length;o++)uu(this,o<<1);this.computeSlot=null}field(e,n=!0){let r=this.config.address[e.id];if(r==null){if(n)throw new RangeError("Field is not present in this state");return}return uu(this,r),yd(this,r)}update(...e){return ck(this,e,!0)}applyTransaction(e){let n=this.config,{base:r,compartments:a}=n;for(let o of e.effects)o.is(_r.reconfigure)?(n&&(a=new Map,n.compartments.forEach((l,u)=>a.set(u,l)),n=null),a.set(o.value.compartment,o.value.extension)):o.is(pt.reconfigure)?(n=null,r=o.value):o.is(pt.appendConfig)&&(n=null,r=Ao(r).concat(o.value));let s;n?s=e.startState.values.slice():(n=xd.resolve(r,a,this),s=new t(n,this.doc,this.selection,n.dynamicSlots.map(()=>null),(l,u)=>u.reconfigure(l,this),null).values);let i=e.startState.facet(Ap)?e.newSelection:e.newSelection.asSingle();new t(n,e.newDoc,i,s,(o,l)=>l.update(o,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(n=>({changes:{from:n.from,to:n.to,insert:e},range:se.cursor(n.from+e.length,-1)}))}changeByRange(e){let n=this.selection,r=e(n.ranges[0]),a=this.changes(r.changes),s=[r.range],i=Ao(r.effects);for(let o=1;o<n.ranges.length;o++){let l=e(n.ranges[o]),u=this.changes(l.changes),c=u.map(a);for(let f=0;f<o;f++)s[f]=s[f].map(c);let d=a.mapDesc(u,!0);s.push(l.range.map(d)),a=a.compose(c),i=pt.mapEffects(i,c).concat(pt.mapEffects(Ao(l.effects),d))}return{changes:a,selection:se.create(s,n.mainIndex),effects:i}}changes(e=[]){return e instanceof Nn?e:Nn.of(e,this.doc.length,this.facet(t.lineSeparator))}toText(e){return st.of(e.split(this.facet(t.lineSeparator)||Sp))}sliceDoc(e=0,n=this.doc.length){return this.doc.sliceString(e,n,this.lineBreak)}facet(e){let n=this.config.address[e.id];return n==null?e.default:(uu(this,n),yd(this,n))}toJSON(e){let n={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let r in e){let a=e[r];a instanceof vn&&this.config.address[a.id]!=null&&(n[r]=a.spec.toJSON(this.field(e[r]),this))}return n}static fromJSON(e,n={},r){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let a=[];if(r){for(let s in r)if(Object.prototype.hasOwnProperty.call(e,s)){let i=r[s],o=e[s];a.push(i.init(l=>i.spec.fromJSON(o,l)))}}return t.create({doc:e.doc,selection:se.fromJSON(e.selection),extensions:n.extensions?a.concat([n.extensions]):a})}static create(e={}){let n=xd.resolve(e.extensions||[],new Map),r=e.doc instanceof st?e.doc:st.of((e.doc||"").split(n.staticFacet(t.lineSeparator)||Sp)),a=e.selection?e.selection instanceof se?e.selection:se.single(e.selection.anchor,e.selection.head):se.single(0);return nk(a,r.length),n.staticFacet(Ap)||(a=a.asSingle()),new t(n,r,a,n.dynamicSlots.map(()=>null),(s,i)=>i.create(s),null)}get tabSize(){return this.facet(t.tabSize)}get lineBreak(){return this.facet(t.lineSeparator)||`
|
|
36
|
-
`}get readOnly(){return this.facet(lk)}phrase(e,...n){for(let r of this.facet(t.phrases))if(Object.prototype.hasOwnProperty.call(r,e)){e=r[e];break}return n.length&&(e=e.replace(/\$(\$|\d*)/g,(r,a)=>{if(a=="$")return"$";let s=+(a||1);return!s||s>n.length?r:n[s-1]})),e}languageDataAt(e,n,r=-1){let a=[];for(let s of this.facet(rk))for(let i of s(this,n,r))Object.prototype.hasOwnProperty.call(i,e)&&a.push(i[e]);return a}charCategorizer(e){let n=this.languageDataAt("wordChars",e);return qM(n.length?n[0]:"")}wordAt(e){let{text:n,from:r,length:a}=this.doc.lineAt(e),s=this.charCategorizer(e),i=e-r,o=e-r;for(;i>0;){let l=Pn(n,i,!1);if(s(n.slice(l,i))!=sa.Word)break;i=l}for(;o<a;){let l=Pn(n,o);if(s(n.slice(o,l))!=sa.Word)break;o=l}return i==o?null:se.range(i+r,o+r)}};It.allowMultipleSelections=Ap;It.tabSize=Me.define({combine:t=>t.length?t[0]:4});It.lineSeparator=ak;It.readOnly=lk;It.phrases=Me.define({compare(t,e){let n=Object.keys(t),r=Object.keys(e);return n.length==r.length&&n.every(a=>t[a]==e[a])}});It.languageData=rk;It.changeFilter=sk;It.transactionFilter=ik;It.transactionExtender=ok;_r.reconfigure=pt.define();function No(t,e,n={}){let r={};for(let a of t)for(let s of Object.keys(a)){let i=a[s],o=r[s];if(o===void 0)r[s]=i;else if(!(o===i||i===void 0))if(Object.hasOwnProperty.call(n,s))r[s]=n[s](o,i);else throw new Error("Config merge conflict for field "+s)}for(let a in e)r[a]===void 0&&(r[a]=e[a]);return r}var Ra=class{eq(e){return this==e}range(e,n=e){return du.create(e,n,this)}};Ra.prototype.startSide=Ra.prototype.endSide=0;Ra.prototype.point=!1;Ra.prototype.mapMode=cr.TrackDel;function Bp(t,e){return t==e||t.constructor==e.constructor&&t.eq(e)}var du=class t{constructor(e,n,r){this.from=e,this.to=n,this.value=r}static create(e,n,r){return new t(e,n,r)}};function Tp(t,e){return t.from-e.from||t.value.startSide-e.value.startSide}var Dp=class t{constructor(e,n,r,a){this.from=e,this.to=n,this.value=r,this.maxPoint=a}get length(){return Co(this.to)}findIndex(e,n,r,a=0){let s=r?this.to:this.from;for(let i=a,o=s.length;;){if(i==o)return i;let l=i+o>>1,u=s[l]-e||(r?this.value[l].endSide:this.value[l].startSide)-n;if(l==i)return u>=0?i:o;u>=0?o=l:i=l+1}}between(e,n,r,a){for(let s=this.findIndex(n,-1e9,!0),i=this.findIndex(r,1e9,!1,s);s<i;s++)if(a(this.from[s]+e,this.to[s]+e,this.value[s])===!1)return!1}map(e,n,r,a,s){let i=[],o=[],l=[],u=-1,c=-1;e:for(let d=0;d<this.value.length;d++){let f=this.value[d],h=this.from[d]+e,p=this.to[d]+e,g,m;if(h==p){let x=n.mapPos(h,f.startSide,f.mapMode);if(x==null||(g=m=x,f.startSide!=f.endSide&&(m=n.mapPos(h,f.endSide),m<g)))continue}else if(g=n.mapPos(h,f.startSide),m=n.mapPos(p,f.endSide),g>m||g==m&&f.startSide>0&&f.endSide<=0)continue;if(!((m-g||f.endSide-f.startSide)<0))if(u<0&&(u=g),f.point&&(c=Math.max(c,m-g)),(g-r||f.startSide-a)>=0)i.push(f),o.push(g-u),l.push(m-u),r=m,a=f.endSide;else{if(g==m)for(let x=i.length;x>0;x--){if((g-(l[x-1]+u)||f.startSide-i[x-1].endSide)>=0){i.splice(x,0,f),o.splice(x,0,g-u),l.splice(x,0,m-u);continue e}if((g-(o[x-1]+u)||f.endSide-i[x-1].startSide)>0)break}s(g,m,f)}}return{mapped:i.length?new t(o,l,i,c):null,pos:u}}},wt=class t{constructor(e,n,r,a){this.chunkPos=e,this.chunk=n,this.nextLayer=r,this.maxPoint=a}static create(e,n,r,a){return new t(e,n,r,a)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let n of this.chunk)e+=n.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:n=[],sort:r=!1,filterFrom:a=0,filterTo:s=this.length}=e,i=e.filter;if(n.length==0&&!i)return this;if(r&&(n=n.slice().sort(Tp)),this.isEmpty)return n.length?t.of(n):this;let o=new bd(this,null,-1).goto(0),l=0,u=[],c=new qn;for(;o.value||l<n.length;)if(l<n.length&&(o.from-n[l].from||o.startSide-n[l].value.startSide)>=0){let d=n[l++];c.addInner(d.from,d.to,d.value,!1)||u.push(d)}else o.rangeIndex==1&&o.chunkIndex<this.chunk.length&&(l==n.length||this.chunkEnd(o.chunkIndex)<n[l].from)&&(!i||a>this.chunkEnd(o.chunkIndex)||s<this.chunkPos[o.chunkIndex])&&c.addChunk(this.chunkPos[o.chunkIndex],this.chunk[o.chunkIndex])?o.nextChunk():((!i||a>o.to||s<o.from||i(o.from,o.to,o.value))&&(c.addInner(o.from,o.to,o.value,!1)||u.push(du.create(o.from,o.to,o.value))),o.next());return c.finishInner(this.nextLayer.isEmpty&&!u.length?t.empty:this.nextLayer.update({add:u,filter:i,filterFrom:a,filterTo:s}))}map(e){if(e.empty||this.isEmpty)return this;let n=[],r=[],a=-1,s,i=(l,u,c)=>{s||(s=new qn),s.addRange(l,u,c,!1)};for(let l=0;l<this.chunk.length;l++){let u=this.chunkPos[l],c=this.chunk[l],d=e.touchesRange(u,u+c.length);if(d===!1)a=Math.max(a,c.maxPoint),n.push(c),r.push(e.mapPos(u));else if(d===!0){let[f,h]=n.length?[Co(r)+Co(n).length,Co(Co(n).value).endSide]:[-1,-1],{mapped:p,pos:g}=c.map(u,e,f,h,i);p&&(a=Math.max(a,p.maxPoint),n.push(p),r.push(g))}}let o=this.nextLayer.map(e);return s&&(o=s.finishInner(o)),n.length==0?o:new t(r,n,o||t.empty,a)}between(e,n,r){if(!this.isEmpty){for(let a=0;a<this.chunk.length;a++){let s=this.chunkPos[a],i=this.chunk[a];if(n>=s&&e<=s+i.length&&i.between(s,e-s,n-s,r)===!1)return}this.nextLayer.between(e,n,r)}}iter(e=0){return fu.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,n=0){return fu.from(e).goto(n)}static compare(e,n,r,a,s=-1){let i=e.filter(d=>d.maxPoint>0||!d.isEmpty&&d.maxPoint>=s),o=n.filter(d=>d.maxPoint>0||!d.isEmpty&&d.maxPoint>=s),l=Y1(i,o,r),u=new Si(i,l,s),c=new Si(o,l,s);r.iterGaps((d,f,h)=>J1(u,d,c,f,h,a)),r.empty&&r.length==0&&J1(u,0,c,0,0,a)}static eq(e,n,r=0,a){a==null&&(a=999999999);let s=e.filter(c=>!c.isEmpty&&n.indexOf(c)<0),i=n.filter(c=>!c.isEmpty&&e.indexOf(c)<0);if(s.length!=i.length)return!1;if(!s.length)return!0;let o=Y1(s,i),l=new Si(s,o,0).goto(r),u=new Si(i,o,0).goto(r);for(;;){if(l.to!=u.to||!Fp(l.active,u.active)||l.point&&(!u.point||!Bp(l.point,u.point)))return!1;if(l.to>a)return!0;l.next(),u.next()}}static spans(e,n,r,a,s=-1){let i=new Si(e,null,s).goto(n),o=n,l=i.openStart;for(;;){let u=Math.min(i.to,r);if(i.point){let c=i.activeForPoint(i.to),d=i.pointFrom<n?c.length+1:i.point.startSide<0?c.length:Math.min(c.length,l);a.point(o,u,i.point,c,d,i.pointRank),l=Math.min(i.openEnd(u),c.length)}else u>o&&(a.span(o,u,i.active,l),l=i.openEnd(u));if(i.to>r)return l+(i.point&&i.to>r?1:0);o=i.to,i.next()}}static of(e,n=!1){let r=new qn;for(let a of e instanceof du?[e]:n?$M(e):e)r.add(a.from,a.to,a.value);return r.finish()}static join(e){if(!e.length)return t.empty;let n=Co(e);for(let r=e.length-2;r>=0;r--)for(let a=e[r];a!=t.empty;a=a.nextLayer)n=new t(a.chunkPos,a.chunk,n,Math.max(a.maxPoint,n.maxPoint));return n}};wt.empty=new wt([],[],null,-1);function Co(t){return t[t.length-1]}function $M(t){if(t.length>1)for(let e=t[0],n=1;n<t.length;n++){let r=t[n];if(Tp(e,r)>0)return t.slice().sort(Tp);e=r}return t}wt.empty.nextLayer=wt.empty;var qn=class t{finishChunk(e){this.chunks.push(new Dp(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(e,n,r){this.addRange(e,n,r,!0)}addRange(e,n,r,a){this.addInner(e,n,r,a)||(this.nextLayer||(this.nextLayer=new t)).addRange(e,n,r,a)}addInner(e,n,r,a){let s=e-this.lastTo||r.startSide-this.last.endSide;if(a&&s<=0&&(e-this.lastFrom||r.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return s<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(n-this.chunkStart),this.last=r,this.lastFrom=e,this.lastTo=n,this.value.push(r),r.point&&(this.maxPoint=Math.max(this.maxPoint,n-e)),!0)}addChunk(e,n){if((e-this.lastTo||n.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,n.maxPoint),this.chunks.push(n),this.chunkPos.push(e);let r=n.value.length-1;return this.last=n.value[r],this.lastFrom=n.from[r]+e,this.lastTo=n.to[r]+e,!0}finish(){return this.finishInner(wt.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let n=wt.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,n}};function Y1(t,e,n){let r=new Map;for(let s of t)for(let i=0;i<s.chunk.length;i++)s.chunk[i].maxPoint<=0&&r.set(s.chunk[i],s.chunkPos[i]);let a=new Set;for(let s of e)for(let i=0;i<s.chunk.length;i++){let o=r.get(s.chunk[i]);o!=null&&(n?n.mapPos(o):o)==s.chunkPos[i]&&!n?.touchesRange(o,o+s.chunk[i].length)&&a.add(s.chunk[i])}return a}var bd=class{constructor(e,n,r,a=0){this.layer=e,this.skip=n,this.minPoint=r,this.rank=a}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,n=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,n,!1),this}gotoInner(e,n,r){for(;this.chunkIndex<this.layer.chunk.length;){let a=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(a)||this.layer.chunkEnd(this.chunkIndex)<e||a.maxPoint<this.minPoint))break;this.chunkIndex++,r=!1}if(this.chunkIndex<this.layer.chunk.length){let a=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],n,!0);(!r||this.rangeIndex<a)&&this.setRangeIndex(a)}this.next()}forward(e,n){(this.to-e||this.endSide-n)<0&&this.gotoInner(e,n,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],n=this.layer.chunk[this.chunkIndex],r=e+n.from[this.rangeIndex];if(this.from=r,this.to=e+n.to[this.rangeIndex],this.value=n.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}},fu=class t{constructor(e){this.heap=e}static from(e,n=null,r=-1){let a=[];for(let s=0;s<e.length;s++)for(let i=e[s];!i.isEmpty;i=i.nextLayer)i.maxPoint>=r&&a.push(new bd(i,n,r,s));return a.length==1?a[0]:new t(a)}get startSide(){return this.value?this.value.startSide:0}goto(e,n=-1e9){for(let r of this.heap)r.goto(e,n);for(let r=this.heap.length>>1;r>=0;r--)vp(this.heap,r);return this.next(),this}forward(e,n){for(let r of this.heap)r.forward(e,n);for(let r=this.heap.length>>1;r>=0;r--)vp(this.heap,r);(this.to-e||this.value.endSide-n)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),vp(this.heap,0)}}};function vp(t,e){for(let n=t[e];;){let r=(e<<1)+1;if(r>=t.length)break;let a=t[r];if(r+1<t.length&&a.compare(t[r+1])>=0&&(a=t[r+1],r++),n.compare(a)<0)break;t[r]=n,t[e]=a,e=r}}var Si=class{constructor(e,n,r){this.minPoint=r,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=fu.from(e,n,r)}goto(e,n=-1e9){return this.cursor.goto(e,n),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=n,this.openStart=-1,this.next(),this}forward(e,n){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-n)<0;)this.removeActive(this.minActive);this.cursor.forward(e,n)}removeActive(e){dd(this.active,e),dd(this.activeTo,e),dd(this.activeRank,e),this.minActive=Z1(this.active,this.activeTo)}addActive(e){let n=0,{value:r,to:a,rank:s}=this.cursor;for(;n<this.activeRank.length&&(s-this.activeRank[n]||a-this.activeTo[n])>0;)n++;fd(this.active,n,r),fd(this.activeTo,n,a),fd(this.activeRank,n,s),e&&fd(e,n,this.cursor.from),this.minActive=Z1(this.active,this.activeTo)}next(){let e=this.to,n=this.point;this.point=null;let r=this.openStart<0?[]:null;for(;;){let a=this.minActive;if(a>-1&&(this.activeTo[a]-this.cursor.from||this.active[a].endSide-this.cursor.startSide)<0){if(this.activeTo[a]>e){this.to=this.activeTo[a],this.endSide=this.active[a].endSide;break}this.removeActive(a),r&&dd(r,a)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let s=this.cursor.value;if(!s.point)this.addActive(r),this.cursor.next();else if(n&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=s,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=s.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(r){this.openStart=0;for(let a=r.length-1;a>=0&&r[a]<e;a--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let n=[];for(let r=this.active.length-1;r>=0&&!(this.activeRank[r]<this.pointRank);r--)(this.activeTo[r]>e||this.activeTo[r]==e&&this.active[r].endSide>=this.point.endSide)&&n.push(this.active[r]);return n.reverse()}openEnd(e){let n=0;for(let r=this.activeTo.length-1;r>=0&&this.activeTo[r]>e;r--)n++;return n}};function J1(t,e,n,r,a,s){t.goto(e),n.goto(r);let i=r+a,o=r,l=r-e,u=!!s.boundChange;for(let c=!1;;){let d=t.to+l-n.to,f=d||t.endSide-n.endSide,h=f<0?t.to+l:n.to,p=Math.min(h,i);if(t.point||n.point?(t.point&&n.point&&Bp(t.point,n.point)&&Fp(t.activeForPoint(t.to),n.activeForPoint(n.to))||s.comparePoint(o,p,t.point,n.point),c=!1):(c&&(s.boundChange(o),c=!1),p>o&&!Fp(t.active,n.active)&&s.compareRange(o,p,t.active,n.active),u&&p<i&&(d||t.openEnd(h)!=n.openEnd(h))&&(c=!0)),h>i)break;o=h,f<=0&&t.next(),f>=0&&n.next()}}function Fp(t,e){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!=e[n]&&!Bp(t[n],e[n]))return!1;return!0}function dd(t,e){for(let n=e,r=t.length-1;n<r;n++)t[n]=t[n+1];t.pop()}function fd(t,e,n){for(let r=t.length-1;r>=e;r--)t[r+1]=t[r];t[e]=n}function Z1(t,e){let n=-1,r=1e9;for(let a=0;a<e.length;a++)(e[a]-r||t[a].endSide-t[n].endSide)<0&&(n=a,r=e[a]);return n}function Li(t,e,n=t.length){let r=0;for(let a=0;a<n&&a<t.length;)t.charCodeAt(a)==9?(r+=e-r%e,a++):(r++,a=Pn(t,a));return r}function dk(t,e,n,r){for(let a=0,s=0;;){if(s>=e)return a;if(a==t.length)break;s+=t.charCodeAt(a)==9?n-s%n:1,a=Pn(t,a)}return r===!0?-1:t.length}var fk=typeof Symbol>"u"?"__\u037C":Symbol.for("\u037C"),_p=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),hk=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{},dr=class{constructor(e,n){this.rules=[];let{finish:r}=n||{};function a(i){return/^@/.test(i)?[i]:i.split(/,\s*/)}function s(i,o,l,u){let c=[],d=/^@(\w+)\b/.exec(i[0]),f=d&&d[1]=="keyframes";if(d&&o==null)return l.push(i[0]+";");for(let h in o){let p=o[h];if(/&/.test(h))s(h.split(/,\s*/).map(g=>i.map(m=>g.replace(/&/,m))).reduce((g,m)=>g.concat(m)),p,l);else if(p&&typeof p=="object"){if(!d)throw new RangeError("The value of a property ("+h+") should be a primitive value.");s(a(h),p,c,f)}else p!=null&&c.push(h.replace(/_.*/,"").replace(/[A-Z]/g,g=>"-"+g.toLowerCase())+": "+p+";")}(c.length||f)&&l.push((r&&!d&&!u?i.map(r):i).join(", ")+" {"+c.join(" ")+"}")}for(let i in e)s(a(i),e[i],this.rules)}getRules(){return this.rules.join(`
|
|
37
|
-
`)}static newName(){let e=
|
|
38
|
-
`;this.styleTag.textContent=l}let o=n.head||n;this.styleTag.parentNode!=o&&o.insertBefore(this.styleTag,o.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}};var as={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},Ro={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},KM=typeof navigator<"u"&&/Mac/.test(navigator.platform),XM=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(mn=0;mn<10;mn++)as[48+mn]=as[96+mn]=String(mn);var mn;for(mn=1;mn<=24;mn++)as[mn+111]="F"+mn;var mn;for(mn=65;mn<=90;mn++)as[mn]=String.fromCharCode(mn+32),Ro[mn]=String.fromCharCode(mn);var mn;for(wd in as)Ro.hasOwnProperty(wd)||(Ro[wd]=as[wd]);var wd;function mk(t){var e=KM&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||XM&&t.shiftKey&&t.key&&t.key.length==1||t.key=="Unidentified",n=!e&&t.key||(t.shiftKey?Ro:as)[t.keyCode]||t.key||"Unidentified";return n=="Esc"&&(n="Escape"),n=="Del"&&(n="Delete"),n=="Left"&&(n="ArrowLeft"),n=="Up"&&(n="ArrowUp"),n=="Right"&&(n="ArrowRight"),n=="Down"&&(n="ArrowDown"),n}var er=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},qp=typeof document<"u"?document:{documentElement:{style:{}}},$p=/Edge\/(\d+)/.exec(er.userAgent),$k=/MSIE \d/.test(er.userAgent),Kp=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(er.userAgent),Vd=!!($k||Kp||$p),gk=!Vd&&/gecko\/(\d+)/i.test(er.userAgent),Up=!Vd&&/Chrome\/(\d+)/.exec(er.userAgent),xk="webkitFontSmoothing"in qp.documentElement.style,Xp=!Vd&&/Apple Computer/.test(er.vendor),yk=Xp&&(/Mobile\/\w+/.test(er.userAgent)||er.maxTouchPoints>2),ke={mac:yk||/Mac/.test(er.platform),windows:/Win/.test(er.platform),linux:/Linux|X11/.test(er.platform),ie:Vd,ie_version:$k?qp.documentMode||6:Kp?+Kp[1]:$p?+$p[1]:0,gecko:gk,gecko_version:gk?+(/Firefox\/(\d+)/.exec(er.userAgent)||[0,0])[1]:0,chrome:!!Up,chrome_version:Up?+Up[1]:0,ios:yk,android:/Android\b/.test(er.userAgent),webkit:xk,webkit_version:xk?+(/\bAppleWebKit\/(\d+)/.exec(er.userAgent)||[0,0])[1]:0,safari:Xp,safari_version:Xp?+(/\bVersion\/(\d+(\.\d+)?)/.exec(er.userAgent)||[0,0])[1]:0,tabSize:qp.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function Om(t,e){for(let n in t)n=="class"&&e.class?e.class+=" "+t.class:n=="style"&&e.style?e.style+=";"+t.style:e[n]=t[n];return e}var Md=Object.create(null);function Bm(t,e,n){if(t==e)return!0;t||(t=Md),e||(e=Md);let r=Object.keys(t),a=Object.keys(e);if(r.length-(n&&r.indexOf(n)>-1?1:0)!=a.length-(n&&a.indexOf(n)>-1?1:0))return!1;for(let s of r)if(s!=n&&(a.indexOf(s)==-1||t[s]!==e[s]))return!1;return!0}function YM(t,e){for(let n=t.attributes.length-1;n>=0;n--){let r=t.attributes[n].name;e[r]==null&&t.removeAttribute(r)}for(let n in e){let r=e[n];n=="style"?t.style.cssText=r:t.getAttribute(n)!=r&&t.setAttribute(n,r)}}function bk(t,e,n){let r=!1;if(e)for(let a in e)n&&a in n||(r=!0,a=="style"?t.style.cssText="":t.removeAttribute(a));if(n)for(let a in n)e&&e[a]==n[a]||(r=!0,a=="style"?t.style.cssText=n[a]:t.setAttribute(a,n[a]));return r}function JM(t){let e=Object.create(null);for(let n=0;n<t.attributes.length;n++){let r=t.attributes[n];e[r.name]=r.value}return e}var Ir=class{eq(e){return!1}updateDOM(e,n,r){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,n,r){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}},On=(function(t){return t[t.Text=0]="Text",t[t.WidgetBefore=1]="WidgetBefore",t[t.WidgetAfter=2]="WidgetAfter",t[t.WidgetRange=3]="WidgetRange",t})(On||(On={})),Ke=class extends Ra{constructor(e,n,r,a){super(),this.startSide=e,this.endSide=n,this.widget=r,this.spec=a}get heightRelevant(){return!1}static mark(e){return new Iu(e)}static widget(e){let n=Math.max(-1e4,Math.min(1e4,e.side||0)),r=!!e.block;return n+=r&&!e.inlineOrder?n>0?3e8:-4e8:n>0?1e8:-1e8,new Ri(e,n,n,r,e.widget||null,!1)}static replace(e){let n=!!e.block,r,a;if(e.isBlockGap)r=-5e8,a=4e8;else{let{start:s,end:i}=Kk(e,n);r=(s?n?-3e8:-1:5e8)-1,a=(i?n?2e8:1:-6e8)+1}return new Ri(e,r,a,n,e.widget||null,!0)}static line(e){return new Lu(e)}static set(e,n=!1){return wt.of(e,n)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}};Ke.none=wt.empty;var Iu=class t extends Ke{constructor(e){let{start:n,end:r}=Kk(e);super(n?-1:5e8,r?1:-6e8,null,e),this.tagName=e.tagName||"span",this.attrs=e.class&&e.attributes?Om(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||Md}eq(e){return this==e||e instanceof t&&this.tagName==e.tagName&&Bm(this.attrs,e.attrs)}range(e,n=e){if(e>=n)throw new RangeError("Mark decorations may not be empty");return super.range(e,n)}};Iu.prototype.point=!1;var Lu=class t extends Ke{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof t&&this.spec.class==e.spec.class&&Bm(this.spec.attributes,e.spec.attributes)}range(e,n=e){if(n!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,n)}};Lu.prototype.mapMode=cr.TrackBefore;Lu.prototype.point=!0;var Ri=class t extends Ke{constructor(e,n,r,a,s,i){super(n,r,s,e),this.block=a,this.isReplace=i,this.mapMode=a?n<=0?cr.TrackBefore:cr.TrackAfter:cr.TrackDel}get type(){return this.startSide!=this.endSide?On.WidgetRange:this.startSide<=0?On.WidgetBefore:On.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof t&&ZM(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}range(e,n=e){if(this.isReplace&&(e>n||e==n&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&n!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,n)}};Ri.prototype.point=!0;function Kk(t,e=!1){let{inclusiveStart:n,inclusiveEnd:r}=t;return n==null&&(n=t.inclusive),r==null&&(r=t.inclusive),{start:n??e,end:r??e}}function ZM(t,e){return t==e||!!(t&&e&&t.compare(e))}function Eo(t,e,n,r=0){let a=n.length-1;a>=0&&n[a]+r>=t?n[a]=Math.max(n[a],e):n.push(t,e)}var Td=class t extends Ra{constructor(e,n,r){super(),this.tagName=e,this.attributes=n,this.rank=r}eq(e){return e==this||e instanceof t&&this.tagName==e.tagName&&Bm(this.attributes,e.attributes)}static create(e){return new t(e.tagName,e.attributes||Md,e.rank==null?50:Math.max(0,Math.min(e.rank,100)))}static set(e,n=!1){return wt.of(e,n)}};Td.prototype.startSide=Td.prototype.endSide=-1;function Au(t){let e;return t.nodeType==11?e=t.getSelection?t:t.ownerDocument:e=t,e.getSelection()}function Yp(t,e){return e?t==e||t.contains(e.nodeType!=1?e.parentNode:e):!1}function mu(t,e){if(!e.anchorNode)return!1;try{return Yp(t,e.anchorNode)}catch{return!1}}function gu(t){return t.nodeType==3?Nu(t,0,t.nodeValue.length).getClientRects():t.nodeType==1?t.getClientRects():[]}function xu(t,e,n,r){return n?wk(t,e,n,r,-1)||wk(t,e,n,r,1):!1}function Ws(t){for(var e=0;;e++)if(t=t.previousSibling,!t)return e}function Dd(t){return t.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(t.nodeName)}function wk(t,e,n,r,a){for(;;){if(t==n&&e==r)return!0;if(e==(a<0?0:os(t))){if(t.nodeName=="DIV")return!1;let s=t.parentNode;if(!s||s.nodeType!=1)return!1;e=Ws(t)+(a<0?0:1),t=s}else if(t.nodeType==1){if(t=t.childNodes[e+(a<0?-1:0)],t.nodeType==1&&t.contentEditable=="false")return!1;e=a<0?os(t):0}else return!1}}function os(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function Pu(t,e){let{left:n,right:r}=t;if(n==r)return t;let a=e?n:r;return{left:a,right:a,top:t.top,bottom:t.bottom}}function QM(t){let e=t.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.innerWidth,top:0,bottom:t.innerHeight}}function Xk(t,e){let n=e.width/t.offsetWidth,r=e.height/t.offsetHeight;return(n>.995&&n<1.005||!isFinite(n)||Math.abs(e.width-t.offsetWidth)<1)&&(n=1),(r>.995&&r<1.005||!isFinite(r)||Math.abs(e.height-t.offsetHeight)<1)&&(r=1),{scaleX:n,scaleY:r}}function eT(t,e,n,r,a,s,i,o){let l=t.ownerDocument,u=l.defaultView||window;for(let c=t,d=!1;c&&!d;)if(c.nodeType==1){let f,h=c==l.body,p=1,g=1;if(h)f=QM(u);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(d=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let y=c.getBoundingClientRect();({scaleX:p,scaleY:g}=Xk(c,y)),f={left:y.left,right:y.left+c.clientWidth*p,top:y.top,bottom:y.top+c.clientHeight*g}}let m=0,x=0;if(a=="nearest")e.top<f.top+i?(x=e.top-(f.top+i),n>0&&e.bottom>f.bottom+x&&(x=e.bottom-f.bottom+i)):e.bottom>f.bottom-i&&(x=e.bottom-f.bottom+i,n<0&&e.top-x<f.top&&(x=e.top-(f.top+i)));else{let y=e.bottom-e.top,b=f.bottom-f.top;x=(a=="center"&&y<=b?e.top+y/2-b/2:a=="start"||a=="center"&&n<0?e.top-i:e.bottom-b+i)-f.top}if(r=="nearest"?e.left<f.left+s?(m=e.left-(f.left+s),n>0&&e.right>f.right+m&&(m=e.right-f.right+s)):e.right>f.right-s&&(m=e.right-f.right+s,n<0&&e.left<f.left+m&&(m=e.left-(f.left+s))):m=(r=="center"?e.left+(e.right-e.left)/2-(f.right-f.left)/2:r=="start"==o?e.left-s:e.right-(f.right-f.left)+s)-f.left,m||x)if(h)u.scrollBy(m,x);else{let y=0,b=0;if(x){let C=c.scrollTop;c.scrollTop+=x/g,b=(c.scrollTop-C)*g}if(m){let C=c.scrollLeft;c.scrollLeft+=m/p,y=(c.scrollLeft-C)*p}e={left:e.left-y,top:e.top-b,right:e.right-y,bottom:e.bottom-b},y&&Math.abs(y-m)<1&&(r="nearest"),b&&Math.abs(b-x)<1&&(a="nearest")}if(h)break;(e.top<f.top||e.bottom>f.bottom||e.left<f.left||e.right>f.right)&&(e={left:Math.max(e.left,f.left),right:Math.min(e.right,f.right),top:Math.max(e.top,f.top),bottom:Math.min(e.bottom,f.bottom)}),c=c.assignedSlot||c.parentNode}else if(c.nodeType==11)c=c.host;else break}function Yk(t,e=!0){let n=t.ownerDocument,r=null,a=null;for(let s=t.parentNode;s&&!(s==n.body||(!e||r)&&a);)if(s.nodeType==1)!a&&s.scrollHeight>s.clientHeight&&(a=s),e&&!r&&s.scrollWidth>s.clientWidth&&(r=s),s=s.assignedSlot||s.parentNode;else if(s.nodeType==11)s=s.host;else break;return{x:r,y:a}}var Jp=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:n,focusNode:r}=e;this.set(n,Math.min(e.anchorOffset,n?os(n):0),r,Math.min(e.focusOffset,r?os(r):0))}set(e,n,r,a){this.anchorNode=e,this.anchorOffset=n,this.focusNode=r,this.focusOffset=a}};function Jk(t){let e=[];for(let n=t;n;n=n.nodeType==11?n.host:n.parentNode)n.nodeType==1&&e.push({node:n,left:n.scrollLeft,top:n.scrollTop});return e}function Zk(t,e=!0){for(let{node:n,left:r,top:a}of t)e&&n.scrollTop!=a&&(n.scrollTop=a),n.scrollLeft!=r&&(n.scrollLeft=r)}var Ai=null;ke.safari&&ke.safari_version>=26&&(Ai=!1);function Qk(t){if(t.setActive)return t.setActive();if(Ai)return t.focus(Ai);let e=Jk(t);t.focus(Ai==null?{get preventScroll(){return Ai={preventScroll:!0},!0}}:void 0),Ai||(Ai=!1,Zk(e))}var vk;function Nu(t,e,n=e){let r=vk||(vk=document.createRange());return r.setEnd(t,n),r.setStart(t,e),r}function Oo(t,e,n,r){let a={key:e,code:e,keyCode:n,which:n,cancelable:!0};r&&({altKey:a.altKey,ctrlKey:a.ctrlKey,shiftKey:a.shiftKey,metaKey:a.metaKey}=r);let s=new KeyboardEvent("keydown",a);s.synthetic=!0,t.dispatchEvent(s);let i=new KeyboardEvent("keyup",a);return i.synthetic=!0,t.dispatchEvent(i),s.defaultPrevented||i.defaultPrevented}function tT(t){for(;t;){if(t&&(t.nodeType==9||t.nodeType==11&&t.host))return t;t=t.assignedSlot||t.parentNode}return null}function nT(t,e){let n=e.focusNode,r=e.focusOffset;if(!n||e.anchorNode!=n||e.anchorOffset!=r)return!1;for(r=Math.min(r,os(n));;)if(r){if(n.nodeType!=1)return!1;let a=n.childNodes[r-1];a.contentEditable=="false"?r--:(n=a,r=os(n))}else{if(n==t)return!0;r=Ws(n),n=n.parentNode}}function eS(t){return t instanceof Window?t.pageYOffset>Math.max(0,t.document.documentElement.scrollHeight-t.innerHeight-4):t.scrollTop>Math.max(1,t.scrollHeight-t.clientHeight-4)}function tS(t,e){for(let n=t,r=e;;){if(n.nodeType==3&&r>0)return{node:n,offset:r};if(n.nodeType==1&&r>0){if(n.contentEditable=="false")return null;n=n.childNodes[r-1],r=os(n)}else if(n.parentNode&&!Dd(n))r=Ws(n),n=n.parentNode;else return null}}function nS(t,e){for(let n=t,r=e;;){if(n.nodeType==3&&r<n.nodeValue.length)return{node:n,offset:r};if(n.nodeType==1&&r<n.childNodes.length){if(n.contentEditable=="false")return null;n=n.childNodes[r],r=0}else if(n.parentNode&&!Dd(n))r=Ws(n)+1,n=n.parentNode;else return null}}var Da=class t{constructor(e,n,r=!0){this.node=e,this.offset=n,this.precise=r}static before(e,n){return new t(e.parentNode,Ws(e),n)}static after(e,n){return new t(e.parentNode,Ws(e)+1,n)}},Vt=(function(t){return t[t.LTR=0]="LTR",t[t.RTL=1]="RTL",t})(Vt||(Vt={})),Mi=Vt.LTR,_m=Vt.RTL;function rS(t){let e=[];for(let n=0;n<t.length;n++)e.push(1<<+t[n]);return e}var rT=rS("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),aT=rS("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Zp=Object.create(null),Ta=[];for(let t of["()","[]","{}"]){let e=t.charCodeAt(0),n=t.charCodeAt(1);Zp[e]=n,Zp[n]=-e}function aS(t){return t<=247?rT[t]:1424<=t&&t<=1524?2:1536<=t&&t<=1785?aT[t-1536]:1774<=t&&t<=2220?4:8192<=t&&t<=8204?256:64336<=t&&t<=65023?4:1}var sT=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/,Wr=class{get dir(){return this.level%2?_m:Mi}constructor(e,n,r){this.from=e,this.to=n,this.level=r}side(e,n){return this.dir==n==e?this.to:this.from}forward(e,n){return e==(this.dir==n)}static find(e,n,r,a){let s=-1;for(let i=0;i<e.length;i++){let o=e[i];if(o.from<=n&&o.to>=n){if(o.level==r)return i;(s<0||(a!=0?a<0?o.from<n:o.to>n:e[s].level>o.level))&&(s=i)}}if(s<0)throw new RangeError("Index out of range");return s}};function sS(t,e){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++){let r=t[n],a=e[n];if(r.from!=a.from||r.to!=a.to||r.direction!=a.direction||!sS(r.inner,a.inner))return!1}return!0}var Ut=[];function iT(t,e,n,r,a){for(let s=0;s<=r.length;s++){let i=s?r[s-1].to:e,o=s<r.length?r[s].from:n,l=s?256:a;for(let u=i,c=l,d=l;u<o;u++){let f=aS(t.charCodeAt(u));f==512?f=c:f==8&&d==4&&(f=16),Ut[u]=f==4?2:f,f&7&&(d=f),c=f}for(let u=i,c=l,d=l;u<o;u++){let f=Ut[u];if(f==128)u<o-1&&c==Ut[u+1]&&c&24?f=Ut[u]=c:Ut[u]=256;else if(f==64){let h=u+1;for(;h<o&&Ut[h]==64;)h++;let p=u&&c==8||h<n&&Ut[h]==8?d==1?1:8:256;for(let g=u;g<h;g++)Ut[g]=p;u=h-1}else f==8&&d==1&&(Ut[u]=1);c=f,f&7&&(d=f)}}}function oT(t,e,n,r,a){let s=a==1?2:1;for(let i=0,o=0,l=0;i<=r.length;i++){let u=i?r[i-1].to:e,c=i<r.length?r[i].from:n;for(let d=u,f,h,p;d<c;d++)if(h=Zp[f=t.charCodeAt(d)])if(h<0){for(let g=o-3;g>=0;g-=3)if(Ta[g+1]==-h){let m=Ta[g+2],x=m&2?a:m&4?m&1?s:a:0;x&&(Ut[d]=Ut[Ta[g]]=x),o=g;break}}else{if(Ta.length==189)break;Ta[o++]=d,Ta[o++]=f,Ta[o++]=l}else if((p=Ut[d])==2||p==1){let g=p==a;l=g?0:1;for(let m=o-3;m>=0;m-=3){let x=Ta[m+2];if(x&2)break;if(g)Ta[m+2]|=2;else{if(x&4)break;Ta[m+2]|=4}}}}}function lT(t,e,n,r){for(let a=0,s=r;a<=n.length;a++){let i=a?n[a-1].to:t,o=a<n.length?n[a].from:e;for(let l=i;l<o;){let u=Ut[l];if(u==256){let c=l+1;for(;;)if(c==o){if(a==n.length)break;c=n[a++].to,o=a<n.length?n[a].from:e}else if(Ut[c]==256)c++;else break;let d=s==1,f=(c<e?Ut[c]:r)==1,h=d==f?d?1:2:r;for(let p=c,g=a,m=g?n[g-1].to:t;p>l;)p==m&&(p=n[--g].from,m=g?n[g-1].to:t),Ut[--p]=h;l=c}else s=u,l++}}}function Qp(t,e,n,r,a,s,i){let o=r%2?2:1;if(r%2==a%2)for(let l=e,u=0;l<n;){let c=!0,d=!1;if(u==s.length||l<s[u].from){let g=Ut[l];g!=o&&(c=!1,d=g==16)}let f=!c&&o==1?[]:null,h=c?r:r+1,p=l;e:for(;;)if(u<s.length&&p==s[u].from){if(d)break e;let g=s[u];if(!c)for(let m=g.to,x=u+1;;){if(m==n)break e;if(x<s.length&&s[x].from==m)m=s[x++].to;else{if(Ut[m]==o)break e;break}}if(u++,f)f.push(g);else{g.from>l&&i.push(new Wr(l,g.from,h));let m=g.direction==Mi!=!(h%2);em(t,m?r+1:r,a,g.inner,g.from,g.to,i),l=g.to}p=g.to}else{if(p==n||(c?Ut[p]!=o:Ut[p]==o))break;p++}f?Qp(t,l,p,r+1,a,f,i):l<p&&i.push(new Wr(l,p,h)),l=p}else for(let l=n,u=s.length;l>e;){let c=!0,d=!1;if(!u||l>s[u-1].to){let g=Ut[l-1];g!=o&&(c=!1,d=g==16)}let f=!c&&o==1?[]:null,h=c?r:r+1,p=l;e:for(;;)if(u&&p==s[u-1].to){if(d)break e;let g=s[--u];if(!c)for(let m=g.from,x=u;;){if(m==e)break e;if(x&&s[x-1].to==m)m=s[--x].from;else{if(Ut[m-1]==o)break e;break}}if(f)f.push(g);else{g.to<l&&i.push(new Wr(g.to,l,h));let m=g.direction==Mi!=!(h%2);em(t,m?r+1:r,a,g.inner,g.from,g.to,i),l=g.from}p=g.from}else{if(p==e||(c?Ut[p-1]!=o:Ut[p-1]==o))break;p--}f?Qp(t,p,l,r+1,a,f,i):p<l&&i.push(new Wr(p,l,h)),l=p}}function em(t,e,n,r,a,s,i){let o=e%2?2:1;iT(t,a,s,r,o),oT(t,a,s,r,o),lT(a,s,r,o),Qp(t,a,s,e,n,r,i)}function uT(t,e,n){if(!t)return[new Wr(0,0,e==_m?1:0)];if(e==Mi&&!n.length&&!sT.test(t))return iS(t.length);if(n.length)for(;t.length>Ut.length;)Ut[Ut.length]=256;let r=[],a=e==Mi?0:1;return em(t,a,a,n,0,t.length,r),r}function iS(t){return[new Wr(0,t,0)]}var oS="";function cT(t,e,n,r,a){var s;if(!t.length)return null;let i=r.head-t.from,o;if(r.head==t.from&&r.assoc<0){if(!a)return null;i=e[o=0].side(!1,n)}else if(r.head==t.to&&r.assoc>0){if(a)return null;i=e[o=e.length-1].side(!0,n)}else o=Wr.find(e,i,(s=r.bidiLevel)!==null&&s!==void 0?s:-1,r.assoc);let l=e[o],u=l.side(a,n);if(i==u){let f=o+=a?1:-1;if(f<0||f>=e.length)return null;l=e[o=f],i=l.side(!a,n),u=l.side(a,n)}let c=Pn(t.text,i,l.forward(a,n));(c<l.from||c>l.to)&&(c=u),oS=t.text.slice(Math.min(i,c),Math.max(i,c));let d=o==(a?e.length-1:0)?null:e[o+(a?1:-1)];if(c==u){if(!d)return a?se.cursor(t.to,1):se.cursor(t.from,-1);if(d.level+(a?0:1)<l.level)return se.cursor(d.side(!a,n)+t.from,d.forward(a,n)?1:-1,d.level)}return se.cursor(c+t.from,l.forward(a,n)?-1:1,l.level)}function dT(t,e,n){for(let r=e;r<n;r++){let a=aS(t.charCodeAt(r));if(a==1)return Mi;if(a==2||a==4)return _m}return Mi}var lS=Me.define(),uS=Me.define(),cS=Me.define(),dS=Me.define(),tm=Me.define(),fS=Me.define(),hS=Me.define(),Hm=Me.define(),Um=Me.define(),pS=Me.define({combine:t=>t.some(e=>e)}),mS=Me.define({combine:t=>t.some(e=>e)}),gS=Me.define(),yu=class t{constructor(e,n,r,a,s,i=!1){this.range=e,this.y=n,this.x=r,this.yMargin=a,this.xMargin=s,this.isSnapshot=i}map(e){return e.empty?this:new t(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new t(se.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}},vd=pt.define({map:(t,e)=>t.map(e)}),xS=pt.define();function oa(t,e,n){let r=t.facet(dS);r.length?r[0](e):window.onerror&&window.onerror(String(e),n,void 0,void 0,e)||(n?console.error(n+":",e):console.error(e))}var ss=Me.define({combine:t=>t.length?t[0]:!0}),fT=0,To=Me.define({combine(t){return t.filter((e,n)=>{for(let r=0;r<n;r++)if(t[r].plugin==e.plugin)return!1;return!0})}}),hr=class t{constructor(e,n,r,a,s){this.id=e,this.create=n,this.domEventHandlers=r,this.domEventObservers=a,this.baseExtensions=s(this),this.extension=this.baseExtensions.concat(To.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(To.of({plugin:this,arg:e}))}static define(e,n){let{eventHandlers:r,eventObservers:a,provide:s,decorations:i}=n||{};return new t(fT++,e,r,a,o=>{let l=[];return i&&l.push(qd.of(u=>{let c=u.plugin(o);return c?i(c):Ke.none})),s&&l.push(s(o)),l})}static fromClass(e,n){return t.define((r,a)=>new e(r,a),n)}},bu=class{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(e){if(this.value){if(this.mustUpdate){let n=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(n)}catch(r){if(oa(n.state,r,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(e,this.spec.arg)}catch(n){oa(e.state,n,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var n;if(!((n=this.value)===null||n===void 0)&&n.destroy)try{this.value.destroy()}catch(r){oa(e.state,r,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}},yS=Me.define(),Gm=Me.define(),qd=Me.define(),bS=Me.define(),Wm=Me.define(),Ru=Me.define(),wS=Me.define();function kk(t,e){let n=t.state.facet(wS);if(!n.length)return n;let r=n.map(s=>s instanceof Function?s(t):s),a=[];return wt.spans(r,e.from,e.to,{point(){},span(s,i,o,l){let u=s-e.from,c=i-e.from,d=a;for(let f=o.length-1;f>=0;f--,l--){let h=o[f].spec.bidiIsolate,p;if(h==null&&(h=dT(e.text,u,c)),l>0&&d.length&&(p=d[d.length-1]).to==u&&p.direction==h)p.to=c,d=p.inner;else{let g={from:u,to:c,direction:h,inner:[]};d.push(g),d=g.inner}}}}),a}var vS=Me.define();function kS(t){let e=0,n=0,r=0,a=0;for(let s of t.state.facet(vS)){let i=s(t);i&&(i.left!=null&&(e=Math.max(e,i.left)),i.right!=null&&(n=Math.max(n,i.right)),i.top!=null&&(r=Math.max(r,i.top)),i.bottom!=null&&(a=Math.max(a,i.bottom)))}return{left:e,right:n,top:r,bottom:a}}var hu=Me.define(),la=class t{constructor(e,n,r,a){this.fromA=e,this.toA=n,this.fromB=r,this.toB=a}join(e){return new t(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let n=e.length,r=this;for(;n>0;n--){let a=e[n-1];if(!(a.fromA>r.toA)){if(a.toA<r.fromA)break;r=r.join(a),e.splice(n-1,1)}}return e.splice(n,0,r),e}static extendWithRanges(e,n){if(n.length==0)return e;let r=[];for(let a=0,s=0,i=0;;){let o=a<e.length?e[a].fromB:1e9,l=s<n.length?n[s]:1e9,u=Math.min(o,l);if(u==1e9)break;let c=u+i,d=u,f=c;for(;;)if(s<n.length&&n[s]<=d){let h=n[s+1];s+=2,d=Math.max(d,h);for(let p=a;p<e.length&&e[p].fromB<=d;p++)i=e[p].toA-e[p].toB;f=Math.max(f,h+i)}else if(a<e.length&&e[a].fromB<=d){let h=e[a++];d=Math.max(d,h.toB),f=Math.max(f,h.toA),i=h.toA-h.toB}else break;r.push(new t(c,f,u,d))}return r}},Fd=class t{constructor(e,n,r){this.view=e,this.state=n,this.transactions=r,this.flags=0,this.startState=e.state,this.changes=Nn.empty(this.startState.doc.length);for(let s of r)this.changes=this.changes.compose(s.changes);let a=[];this.changes.iterChangedRanges((s,i,o,l)=>a.push(new la(s,i,o,l))),this.changedRanges=a}static create(e,n,r){return new t(e,n,r)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}},hT=[],Yt=class{constructor(e,n,r=0){this.dom=e,this.length=n,this.flags=r,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return hT}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,this.flags&4){this.flags&=-5;let n=this.domAttrs;n&&YM(this.dom,n)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,n=this.posAtStart){let r=n;for(let a of this.children){if(a==e)return r;r+=a.length+a.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,n,r){return null}domPosFor(e,n){let r=Ws(this.dom),a=this.length?e>0:n>0;return new Da(this.parent.dom,r+(a?1:0),e==0||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof _o)return e;return null}static get(e){return e.cmTile}},Bo=class extends Yt{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let n=this.dom,r=null,a,s=e?.node==n?e:null,i=0;for(let o of this.children){if(o.sync(e),i+=o.length+o.breakAfter,a=r?r.nextSibling:n.firstChild,s&&a!=o.dom&&(s.written=!0),o.dom.parentNode==n)for(;a&&a!=o.dom;)a=Sk(a);else n.insertBefore(o.dom,a);r=o.dom}for(a=r?r.nextSibling:n.firstChild,s&&a&&(s.written=!0);a;)a=Sk(a);this.length=i}};function Sk(t){let e=t.nextSibling;return t.parentNode.removeChild(t),e}var _o=class extends Bo{constructor(e,n){super(n),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let n=Yt.get(e);if(n&&this.owns(n))return n;e=e.parentNode}}blockTiles(e){for(let n=[],r=this,a=0,s=0;;)if(a==r.children.length){if(!n.length)return;r=r.parent,r.breakAfter&&s++,a=n.pop()}else{let i=r.children[a++];if(i instanceof is)n.push(a),r=i,a=0;else{let o=s+i.length,l=e(i,s);if(l!==void 0)return l;s=o+i.breakAfter}}}resolveBlock(e,n){let r,a=-1,s,i=-1;if(this.blockTiles((o,l)=>{let u=l+o.length;if(e>=l&&e<=u){if(o.isWidget()&&n>=-1&&n<=1){if(o.flags&32)return!0;o.flags&16&&(r=void 0)}(l<e||e==u&&(n<-1?o.length:o.covers(1)))&&(!r||!o.isWidget()&&r.isWidget())&&(r=o,a=e-l),(u>e||e==l&&(n>1?o.length:o.covers(-1)))&&(!s||!o.isWidget()&&s.isWidget())&&(s=o,i=e-l)}}),!r&&!s)throw new Error("No tile at position "+e);return r&&n<0||!s?{tile:r,offset:a}:{tile:s,offset:i}}},is=class t extends Bo{constructor(e,n){super(e),this.wrapper=n}isBlock(){return!0}covers(e){return this.children.length?e<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(e,n){let r=new t(n||document.createElement(e.tagName),e);return n||(r.flags|=4),r}},Ho=class t extends Bo{constructor(e,n){super(e),this.attrs=n}isLine(){return!0}static start(e,n,r){let a=new t(n||document.createElement("div"),e);return(!n||!r)&&(a.flags|=4),a}get domAttrs(){return this.attrs}resolveInline(e,n,r){let a=null,s=-1,i=null,o=-1;function l(c,d){for(let f=0,h=0;f<c.children.length&&h<=d;f++){let p=c.children[f],g=h+p.length;g>=d&&(p.isComposite()?l(p,d-h):(!i||i.isHidden&&(n>0&&!(i.flags&32)||r&&mT(i,p)))&&(g>d||p.flags&32&&n<=1)?(i=p,o=d-h):(h<d||p.flags&16&&!p.isHidden&&n>=-1)&&(a=p,s=d-h)),h=g}}l(this,e);let u=(n<0?a:i)||a||i;return u?{tile:u,offset:u==a?s:o}:null}coordsIn(e,n,r){let a=this.resolveInline(e,n,!0);return a?a.tile.coordsIn(Math.max(0,a.offset),n,r):pT(this)}domIn(e,n){let r=this.resolveInline(e,n);if(r){let{tile:a,offset:s}=r;if(this.dom.contains(a.dom))return a.isText()?new Da(a.dom,Math.min(a.dom.nodeValue.length,s)):a.domPosFor(s,a.flags&16?1:a.flags&32?-1:n);let i=r.tile.parent,o=!1;for(let l of i.children){if(o)return new Da(l.dom,0);l==r.tile&&(o=!0)}}return new Da(this.dom,0)}};function pT(t){let e=t.dom.lastChild;if(!e)return t.dom.getBoundingClientRect();let n=gu(e);return n[n.length-1]||null}function mT(t,e){let n=t.coordsIn(0,1),r=e.coordsIn(0,1);return n&&r&&r.top<n.bottom}var fr=class t extends Bo{constructor(e,n){super(e),this.mark=n}get domAttrs(){return this.mark.attrs}static of(e,n){let r=new t(n||document.createElement(e.tagName),e);return n||(r.flags|=4),r}},Pi=class t extends Yt{constructor(e,n){super(e,n.length),this.text=n}sync(e){this.flags&2||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,n,r){let a=this.dom.nodeValue.length;e>a&&(e=a);let s=e,i=e,o=0;e==0&&n<0||e==a&&n>=0?ke.chrome||ke.gecko||(e?(s--,o=1):i<a&&(i++,o=-1)):n<0?s--:i<a&&i++;let l=Nu(this.dom,s,i).getClientRects();if(!l.length)return null;let u=l[(o?o<0:n>=0)?0:l.length-1];return ke.safari&&!o&&u.width==0&&(u=Array.prototype.find.call(l,c=>c.width)||u),r==null?u:Pu(u,(o?o>0:n<0)==r)}static of(e,n){let r=new t(n||document.createTextNode(e),e);return n||(r.flags|=2),r}},Ti=class t extends Yt{constructor(e,n,r,a){super(e,n,a),this.widget=r}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,n){return this.coordsInWidget(e,n,!1)}coordsInWidget(e,n,r){let a=this.widget.coordsAt(this.dom,e,n);if(a)return a;if(r)return Pu(this.dom.getBoundingClientRect(),this.length?e==0:n<=0);{let s=this.dom.getClientRects(),i=null;if(!s.length)return null;let o=this.flags&16?!0:this.flags&32?!1:e>0;for(let l=o?s.length-1:0;i=s[l],!(e>0?l==0:l==s.length-1||i.top<i.bottom);l+=o?-1:1);return Pu(i,!o)}}get overrideDOMText(){if(!this.length)return st.empty;let{root:e}=this;if(!e)return st.empty;let n=this.posAtStart;return e.view.state.doc.slice(n,n+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(e,n,r,a,s){return s||(s=e.toDOM(n),e.editable||(s.contentEditable="false")),new t(s,r,e,a)}},Uo=class extends Yt{constructor(e){let n=document.createElement("img");n.className="cm-widgetBuffer",n.setAttribute("aria-hidden","true"),super(n,0,e)}get isHidden(){return!0}get overrideDOMText(){return st.empty}coordsIn(e,n,r){let a=this.dom.getBoundingClientRect();return r==null?a:Pu(a,n>0==r)}},nm=class{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,n,r){let{tile:a,index:s,beforeBreak:i,parents:o}=this;for(;e||n>0;)if(a.isComposite())if(i){if(!e)break;r&&r.break(),e--,i=!1}else if(s==a.children.length){if(!e&&!o.length)break;r&&r.leave(a),i=!!a.breakAfter,{tile:a,index:s}=o.pop(),s++}else{let l=a.children[s],u=l.breakAfter;(n>0?l.length<=e:l.length<e)&&(!r||r.skip(l,0,l.length)!==!1||!l.isComposite)?(i=!!u,s++,e-=l.length):(o.push({tile:a,index:s}),a=l,s=0,r&&l.isComposite()&&r.enter(l))}else{let l=a.length;if(s<l&&e){let u=Math.min(e,l-s);r&&r.skip(a,s,s+u),e-=u,s+=u}if(s==l)i=!!a.breakAfter,{tile:a,index:s}=o.pop(),s++;else if(!e)break}return this.tile=a,this.index=s,this.beforeBreak=i,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}},rm=class{constructor(e,n,r,a){this.from=e,this.to=n,this.wrapper=r,this.rank=a}},am=class{constructor(e,n,r){this.cache=e,this.root=n,this.blockWrappers=r,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,n,r,a){var s;this.flushBuffer();let i=this.ensureMarks(n,r),o=i.lastChild;if(o&&o.isText()&&!(o.flags&8)&&o.length+e.length<512){this.cache.reused.set(o,2);let l=i.children[i.children.length-1]=new Pi(o.dom,o.text+e);l.parent=i}else i.append(a||Pi.of(e,(s=this.cache.find(Pi))===null||s===void 0?void 0:s.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,n){let r=this.curLine;r.dom!=n.line.dom&&(r.setDOM(this.cache.reused.has(n.line)?Gp(n.line.dom):n.line.dom),this.cache.reused.set(n.line,2));let a=r;for(let o=n.marks.length-1;o>=0;o--){let l=n.marks[o],u=a.lastChild;if(u instanceof fr&&u.mark.eq(l.mark))u.dom!=l.dom&&u.setDOM(Gp(l.dom)),a=u;else{let{dom:c}=l;this.cache.reused.get(l)&&Yt.get(l.dom)&&(c=Gp(l.dom));let d=fr.of(l.mark,c);a.append(d),a=d}this.cache.reused.set(l,2)}let s=Yt.get(e.text);s&&this.cache.reused.set(s,2);let i=new Pi(e.text,e.text.nodeValue);i.flags|=8,this.pos=e.range.toB,a.append(i)}addInlineWidget(e,n,r){let a=this.afterWidget&&e.flags&48&&(this.afterWidget.flags&48)==(e.flags&48);a||this.flushBuffer();let s=this.ensureMarks(n,r);!a&&!(e.flags&16)&&s.append(this.getBuffer(1)),s.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,n,r){this.flushBuffer(),this.ensureMarks(n,r).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){let n=this.afterWidget||this.lastBlock;n.length+=e,this.pos+=e}addLineStart(e,n){var r;e||(e=SS);let a=Ho.start(e,n||((r=this.cache.find(Ho))===null||r===void 0?void 0:r.dom),!!n);this.getBlockPos().append(this.lastBlock=this.curLine=a)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,n){var r;let a=this.curLine;for(let s=e.length-1;s>=0;s--){let i=e[s],o;if(n>0&&(o=a.lastChild)&&o instanceof fr&&o.mark.eq(i))a=o,n--;else{let l=fr.of(i,(r=this.cache.find(fr,u=>u.mark.eq(i)))===null||r===void 0?void 0:r.dom);a.append(l),a=l,n=0}}return a}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;(!e||!Ck(this.curLine,!1)||e.dom.nodeName!="BR"&&e.isWidget()&&!(ke.ios&&Ck(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(Wp,0,32)||new Ti(Wp.toDOM(),0,Wp,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let n=e.rank*102+e.value.rank,r=new rm(e.from,e.to,e.value,n),a=this.wrappers.length;for(;a>0&&(this.wrappers[a-1].rank-r.rank||this.wrappers[a-1].to-r.to)<0;)a--;this.wrappers.splice(a,0,r)}this.wrapperPos=this.pos}getBlockPos(){var e;this.updateBlockWrappers();let n=this.root;for(let r of this.wrappers){let a=n.lastChild;if(r.from<this.pos&&a instanceof is&&a.wrapper.eq(r.wrapper))n=a;else{let s=is.of(r.wrapper,(e=this.cache.find(is,i=>i.wrapper.eq(r.wrapper)))===null||e===void 0?void 0:e.dom);n.append(s),n=s}}return n}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let n=2|(e<0?16:32),r=this.cache.find(Uo,void 0,1);return r&&(r.flags=n),r||new Uo(n)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}},sm=class{constructor(e){this.skipCount=0,this.text="",this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:a,lineBreak:s,done:i}=this.cursor.next(this.skipCount);if(this.skipCount=0,i)throw new Error("Ran out of text content when drawing inline views");this.text=a;let o=this.textOff=Math.min(e,a.length);return s?null:a.slice(0,o)}let n=Math.min(this.text.length,this.textOff+e),r=this.text.slice(this.textOff,n);return this.textOff=n,r}},Ed=[Ti,Ho,Pi,fr,Uo,is,_o];for(let t=0;t<Ed.length;t++)Ed[t].bucket=t;var im=class{constructor(e){this.view=e,this.buckets=Ed.map(()=>[]),this.index=Ed.map(()=>0),this.reused=new Map}add(e){let n=e.constructor.bucket,r=this.buckets[n];r.length<6?r.push(e):r[this.index[n]=(this.index[n]+1)%6]=e}find(e,n,r=2){let a=e.bucket,s=this.buckets[a],i=this.index[a];for(let o=0;o<s.length;o++){let l=(o+i)%s.length,u=s[l];if((!n||n(u))&&!this.reused.has(u))return s.splice(l,1),l<i&&this.index[a]--,this.reused.set(u,r),u}return null}findWidget(e,n,r){let a=this.buckets[0];if(a.length)for(let s=0,i=0;;s++){if(s==a.length){if(i)return null;i=1,s=0}let o=a[s];if(!this.reused.has(o)&&(i==0?o.widget.compare(e):o.widget.constructor==e.constructor&&e.updateDOM(o.dom,this.view,o.widget)))return a.splice(s,1),s<this.index[0]&&this.index[0]--,o.widget==e&&o.length==n&&(o.flags&497)==r?(this.reused.set(o,1),o):(this.reused.set(o,2),new Ti(o.dom,n,e,o.flags&-498|r))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,n=2){if(!this.reused.has(e))return this.reused.set(e,n),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}},om=class{constructor(e,n,r,a,s){this.view=e,this.decorations=a,this.disallowBlockEffectsFor=s,this.openWidget=!1,this.openMarks=0,this.cache=new im(e),this.text=new sm(e.state.doc),this.builder=new am(this.cache,new _o(e,e.contentDOM),wt.iter(r)),this.cache.reused.set(n,2),this.old=new nm(n),this.reuseWalker={skip:(i,o,l)=>{if(this.cache.add(i),i.isComposite())return!1},enter:i=>this.cache.add(i),leave:()=>{},break:()=>{}}}run(e,n){let r=n&&this.getCompositionContext(n.text);for(let a=0,s=0,i=0;;){let o=i<e.length?e[i++]:null,l=o?o.fromA:this.old.root.length;if(l>a){let u=l-a;this.preserve(u,!i,!o),a=l,s+=u}if(!o)break;n&&o.fromA<=n.range.fromA&&o.toA>=n.range.toA?(this.forward(o.fromA,n.range.fromA,n.range.fromA<n.range.toA?1:-1),this.emit(s,n.range.fromB),this.builder.flushBuffer(),this.cache.clear(),this.builder.addComposition(n,r),this.text.skip(n.range.toB-n.range.fromB),this.forward(n.range.fromA,o.toA),this.emit(n.range.toB,o.toB)):(this.forward(o.fromA,o.toA),this.emit(s,o.toB)),s=o.toB,a=o.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,n,r){let a=yT(this.old),s=this.openMarks;this.old.advance(e,r?1:-1,{skip:(i,o,l)=>{if(i.isWidget())if(this.openWidget)this.builder.continueWidget(l-o);else{let u=l>0||o<i.length?Ti.of(i.widget,this.view,l-o,i.flags&496,this.cache.maybeReuse(i)):this.cache.reuse(i);u.flags&256?(u.flags&=-2,this.builder.addBlockWidget(u)):(this.builder.ensureLine(null),this.builder.addInlineWidget(u,a,s),s=a.length)}else if(i.isText())this.builder.ensureLine(null),!o&&l==i.length&&!this.cache.reused.has(i)?this.builder.addText(i.text,a,s,this.cache.reuse(i)):(this.cache.add(i),this.builder.addText(i.text.slice(o,l),a,s)),s=a.length;else if(i.isLine())i.flags&=-2,this.cache.reused.set(i,1),this.builder.addLine(i);else if(i instanceof Uo)this.cache.add(i);else if(i instanceof fr)this.builder.ensureLine(null),this.builder.addMark(i,a,s),this.cache.reused.set(i,1),s=a.length;else return!1;this.openWidget=!1},enter:i=>{i.isLine()?this.builder.addLineStart(i.attrs,this.cache.maybeReuse(i)):(this.cache.add(i),i instanceof fr&&a.unshift(i.mark)),this.openWidget=!1},leave:i=>{i.isLine()?a.length&&(a.length=s=0):i instanceof fr&&(a.shift(),s=Math.min(s,a.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,n){let r=null,a=this.builder,s=-1,i=wt.spans(this.decorations,e,n,{point:(o,l,u,c,d,f)=>{if(u instanceof Ri){if(this.disallowBlockEffectsFor[f]){if(u.block)throw new RangeError("Block decorations may not be specified via plugins");if(l>this.view.state.doc.lineAt(o).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(s=c.length,d>c.length)a.continueWidget(l-o);else{let h=u.widget||(u.block?zs.block:zs.inline),p=gT(u),g=this.cache.findWidget(h,l-o,p)||Ti.of(h,this.view,l-o,p);u.block?(u.startSide>0&&a.addLineStartIfNotCovered(r),a.addBlockWidget(g)):(a.ensureLine(r),a.addInlineWidget(g,c,d))}r=null}else r=xT(r,u);l>o&&this.text.skip(l-o)},span:(o,l,u,c)=>{for(let d=o;d<l;){let f=this.text.next(Math.min(512,l-d));f==null?(a.addLineStartIfNotCovered(r),a.addBreak(),d++):(a.ensureLine(r),a.addText(f,u,d==o?c:u.length),d+=f.length),r=null}s=u.length}});s>-1&&(this.openWidget=i>s),this.openWidget||a.addLineStartIfNotCovered(r),this.openMarks=i}forward(e,n,r=1){n-e<=10?this.old.advance(n-e,r,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(n-e-10,-1),this.old.advance(5,r,this.reuseWalker))}getCompositionContext(e){let n=[],r=null;for(let a=e.parentNode;;a=a.parentNode){let s=Yt.get(a);if(a==this.view.contentDOM)break;s instanceof fr?n.push(s):s?.isLine()?r=s:s instanceof is||(a.nodeName=="DIV"&&!r?r=new Ho(a,SS):r||n.push(fr.of(new Iu({tagName:a.nodeName.toLowerCase(),attributes:JM(a)}),a)))}return r?{line:r,marks:n}:null}};function Ck(t,e){let n=r=>{for(let a of r.children)if((e?a.isText():a.length)||n(a))return!0;return!1};return n(t)}function gT(t){let e=t.isReplace?(t.startSide<0?64:0)|(t.endSide>0?128:0):t.startSide>0?32:16;return t.block&&(e|=256),e}var SS={class:"cm-line"};function xT(t,e){let n=e.spec.attributes,r=e.spec.class;return!n&&!r||(t||(t={class:"cm-line"}),n&&Om(n,t),r&&(t.class+=" "+r)),t}function yT(t){let e=[];for(let n=t.parents.length;n>1;n--){let r=n==t.parents.length?t.tile:t.parents[n].tile;r instanceof fr&&e.push(r.mark)}return e}function Gp(t){let e=Yt.get(t);return e&&e.setDOM(t.cloneNode()),t}var zs=class extends Ir{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}};zs.inline=new zs("span");zs.block=new zs("div");var Wp=new class extends Ir{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}},Od=class{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=Ke.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new _o(e,e.contentDOM),this.updateInner([new la(0,0,0,e.state.doc.length)],null)}update(e){var n;let r=e.changedRanges;this.minWidth>0&&r.length&&(r.every(({fromA:c,toA:d})=>d<this.minWidthFrom||c>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let a=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((n=this.domChanged)===null||n===void 0)&&n.newSel?a=this.domChanged.newSel.head:!LT(e.changes,this.hasComposition)&&!e.selectionSet&&(a=e.state.selection.main.head));let s=a>-1?wT(this.view,e.changes,a):null;if(this.domChanged=null,this.hasComposition){let{from:c,to:d}=this.hasComposition;r=new la(c,d,e.changes.mapPos(c,-1),e.changes.mapPos(d,1)).addToSet(r.slice())}this.hasComposition=s?{from:s.range.fromB,to:s.range.toB}:null,(ke.ie||ke.chrome)&&!s&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let i=this.decorations,o=this.blockWrappers;this.updateDeco();let l=ST(i,this.decorations,e.changes);l.length&&(r=la.extendWithRanges(r,l));let u=CT(o,this.blockWrappers,e.changes);return u.length&&(r=la.extendWithRanges(r,u)),s&&!r.some(c=>c.fromA<=s.range.fromA&&c.toA>=s.range.toA)&&(r=s.range.addToSet(r.slice())),this.tile.flags&2&&r.length==0?!1:(this.updateInner(r,s),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,n){this.view.viewState.mustMeasureContent=!0;let{observer:r}=this.view;r.ignore(()=>{if(n||e.length){let i=this.tile,o=new om(this.view,i,this.blockWrappers,this.decorations,this.dynamicDecorationMap);n&&Yt.get(n.text)&&o.cache.reused.set(Yt.get(n.text),2),this.tile=o.run(e,n),lm(i,o.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let s=ke.chrome||ke.ios?{node:r.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(s),s&&(s.written||r.selectionRange.focusNode!=s.node||!this.tile.dom.contains(s.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let a=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let s of this.tile.children)s.isWidget()&&s.widget instanceof wu&&a.push(s.dom);r.updateGaps(a)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let n of e.transactions)for(let r of n.effects)r.is(xS)&&(this.editContextFormatting=r.value)}updateSelection(e=!1,n=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:r}=this.tile,a=this.view.root.activeElement,s=a==r,i=!s&&!(this.view.state.facet(ss)||r.tabIndex>-1)&&mu(r,this.view.observer.selectionRange)&&!(a&&r.contains(a));if(!(s||n||i))return;let o=this.forceSelection;this.forceSelection=!1;let l=this.view.state.selection.main,u,c;if(l.empty?c=u=this.inlineDOMNearPos(l.anchor,l.assoc||1):(c=this.inlineDOMNearPos(l.head,l.head==l.from?1:-1),u=this.inlineDOMNearPos(l.anchor,l.anchor==l.from?1:-1)),ke.gecko&&l.empty&&!this.hasComposition&&bT(u)){let f=document.createTextNode("");this.view.observer.ignore(()=>u.node.insertBefore(f,u.node.childNodes[u.offset]||null)),u=c=new Da(f,0),o=!0}let d=this.view.observer.selectionRange;(o||!d.focusNode||(!xu(u.node,u.offset,d.anchorNode,d.anchorOffset)||!xu(c.node,c.offset,d.focusNode,d.focusOffset))&&!this.suppressWidgetCursorChange(d,l))&&(this.view.observer.ignore(()=>{ke.android&&ke.chrome&&r.contains(d.focusNode)&&IT(d.focusNode,r)&&(r.blur(),r.focus({preventScroll:!0}));let f=Au(this.view.root);if(f)if(l.empty){if(ke.gecko){let h=vT(u.node,u.offset);if(h&&h!=3){let p=(h==1?tS:nS)(u.node,u.offset);p&&(u=new Da(p.node,p.offset))}}f.collapse(u.node,u.offset),l.bidiLevel!=null&&f.caretBidiLevel!==void 0&&(f.caretBidiLevel=l.bidiLevel)}else if(f.extend){f.collapse(u.node,u.offset);try{f.extend(c.node,c.offset)}catch{}}else{let h=document.createRange();l.anchor>l.head&&([u,c]=[c,u]),h.setEnd(c.node,c.offset),h.setStart(u.node,u.offset),f.removeAllRanges(),f.addRange(h)}i&&this.view.root.activeElement==r&&(r.blur(),a&&a.focus())}),this.view.observer.setSelectionRange(u,c)),this.impreciseAnchor=u.precise?null:new Da(d.anchorNode,d.anchorOffset),this.impreciseHead=c.precise?null:new Da(d.focusNode,d.focusOffset)}suppressWidgetCursorChange(e,n){return this.hasComposition&&n.empty&&xu(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==n.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,n=e.state.selection.main,r=Au(e.root),{anchorNode:a,anchorOffset:s}=e.observer.selectionRange;if(!r||!n.empty||!n.assoc||!r.modify)return;let i=this.lineAt(n.head,n.assoc);if(!i)return;let o=i.posAtStart;if(n.head==o||n.head==o+i.length)return;let l=this.coordsAt(n.head,-1),u=this.coordsAt(n.head,1);if(!l||!u||l.bottom>u.top)return;let c=this.domAtPos(n.head+n.assoc,n.assoc);r.collapse(c.node,c.offset),r.modify("move",n.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let d=e.observer.selectionRange;e.docView.posFromDOM(d.anchorNode,d.anchorOffset)!=n.from&&r.collapse(a,s)}posFromDOM(e,n){let r=this.tile.nearest(e);if(!r)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let a=r.posAtStart;if(r.isComposite()){let s;if(e==r.dom)s=r.dom.childNodes[n];else{let i=os(e)==0?0:n==0?-1:1;for(;;){let o=e.parentNode;if(o==r.dom)break;i==0&&o.firstChild!=o.lastChild&&(e==o.firstChild?i=-1:i=1),e=o}i<0?s=e:s=e.nextSibling}if(s==r.dom.firstChild)return a;for(;s&&!Yt.get(s);)s=s.nextSibling;if(!s)return a+r.length;for(let i=0,o=a;;i++){let l=r.children[i];if(l.dom==s)return o;o+=l.length+l.breakAfter}}else return r.isText()?e==r.dom?a+n:a+(n?r.length:0):a}domAtPos(e,n){let{tile:r,offset:a}=this.tile.resolveBlock(e,n);return r.isWidget()?r.domPosFor(a,n):r.domIn(a,n)}inlineDOMNearPos(e,n){let r,a=-1,s=!1,i,o=-1,l=!1;return this.tile.blockTiles((u,c)=>{if(u.isWidget()){if(u.flags&32&&c>=e)return!0;u.flags&16&&(s=!0)}else{let d=c+u.length;if(c<=e&&(r=u,a=e-c,s=d<e),d>=e&&!i&&(i=u,o=e-c,l=c>e),c>e&&i)return!0}}),!r&&!i?this.domAtPos(e,n):(s&&i?r=null:l&&r&&(i=null),r&&n<0||!i?r.domIn(a,n):i.domIn(o,n))}coordsAt(e,n,r){let{tile:a,offset:s}=this.tile.resolveBlock(e,n);return a.isWidget()?a.widget instanceof wu?null:a.coordsInWidget(s,n,!0):a.coordsIn(s,n,r)}lineAt(e,n){let{tile:r}=this.tile.resolveBlock(e,n);return r.isLine()?r:null}coordsForChar(e){let{tile:n,offset:r}=this.tile.resolveBlock(e,1);if(!n.isLine())return null;function a(s,i){if(s.isComposite())for(let o of s.children){if(o.length>=i){let l=a(o,i);if(l)return l}if(i-=o.length,i<0)break}else if(s.isText()&&i<s.length){let o=Pn(s.text,i);if(o==i)return null;let l=Nu(s.dom,i,o).getClientRects();for(let u=0;u<l.length;u++){let c=l[u];if(u==l.length-1||c.top<c.bottom&&c.left<c.right)return c}}return null}return a(n,r)}measureVisibleLineHeights(e){let n=[],{from:r,to:a}=e,s=this.view.contentDOM.clientWidth,i=s>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,o=-1,l=this.view.textDirection==Vt.LTR,u=0,c=(d,f,h)=>{for(let p=0;p<d.children.length&&!(f>a);p++){let g=d.children[p],m=f+g.length,x=g.dom.getBoundingClientRect(),{height:y}=x;if(h&&!p&&(u+=x.top-h.top),g instanceof is)m>r&&c(g,f,x);else if(f>=r&&(u>0&&n.push(-u),n.push(y+u),u=0,i)){let b=g.dom.lastChild,C=b?gu(b):[];if(C.length){let L=C[C.length-1],P=l?L.right-x.left:x.right-L.left;P>o&&(o=P,this.minWidth=s,this.minWidthFrom=f,this.minWidthTo=m)}}h&&p==d.children.length-1&&(u+=h.bottom-x.bottom),f=m+g.breakAfter}};return c(this.tile,0,null),n}textDirectionAt(e){let{tile:n}=this.tile.resolveBlock(e,1);return getComputedStyle(n.dom).direction=="rtl"?Vt.RTL:Vt.LTR}measureTextSize(){let e=this.tile.blockTiles(i=>{if(i.isLine()&&i.children.length&&i.length<=20){let o=0,l;for(let u of i.children){if(!u.isText()||/[^ -~]/.test(u.text))return;let c=gu(u.dom);if(c.length!=1)return;o+=c[0].width,l=c[0].height}if(o)return{lineHeight:i.dom.getBoundingClientRect().height,charWidth:o/i.length,textHeight:l}}});if(e)return e;let n=document.createElement("div"),r,a,s;return n.className="cm-line",n.style.width="99999px",n.style.position="absolute",n.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(n);let i=gu(n.firstChild)[0];r=n.getBoundingClientRect().height,a=i&&i.width?i.width/27:7,s=i&&i.height?i.height:r,n.remove()}),{lineHeight:r,charWidth:a,textHeight:s}}computeBlockGapDeco(){let e=[],n=this.view.viewState;for(let r=0,a=0;;a++){let s=a==n.viewports.length?null:n.viewports[a],i=s?s.from-1:this.view.state.doc.length;if(i>r){let o=(n.lineBlockAt(i).bottom-n.lineBlockAt(r).top)/this.view.scaleY;e.push(Ke.replace({widget:new wu(o),block:!0,inclusive:!0,isBlockGap:!0}).range(r,i))}if(!s)break;r=s.to+1}return Ke.set(e)}updateDeco(){let e=1,n=this.view.state.facet(qd).map(s=>(this.dynamicDecorationMap[e++]=typeof s=="function")?s(this.view):s),r=!1,a=this.view.state.facet(Wm).map((s,i)=>{let o=typeof s=="function";return o&&(r=!0),o?s(this.view):s});for(a.length&&(this.dynamicDecorationMap[e++]=r,n.push(wt.join(a))),this.decorations=[this.editContextFormatting,...n,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(bS).map(s=>typeof s=="function"?s(this.view):s)}scrollIntoView(e){if(e.isSnapshot){let u=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=u.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let u of this.view.state.facet(gS))try{if(u(this.view,e.range,e))return!0}catch(c){oa(this.view.state,c,"scroll handler")}let{range:n}=e,r=this.coordsAt(n.head,n.assoc||(n.head>n.anchor?-1:1)),a;if(!r)return;!n.empty&&(a=this.coordsAt(n.anchor,n.anchor>n.head?-1:1))&&(r={left:Math.min(r.left,a.left),top:Math.min(r.top,a.top),right:Math.max(r.right,a.right),bottom:Math.max(r.bottom,a.bottom)});let s=kS(this.view),i={left:r.left-s.left,top:r.top-s.top,right:r.right+s.right,bottom:r.bottom+s.bottom},{offsetWidth:o,offsetHeight:l}=this.view.scrollDOM;if(eT(this.view.scrollDOM,i,n.head<n.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,o),-o),Math.max(Math.min(e.yMargin,l),-l),this.view.textDirection==Vt.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(r.top>window.visualViewport.offsetTop+window.visualViewport.height||r.bottom<window.visualViewport.offsetTop)){let u=this.view.docView.lineAt(n.head,1);if(u){let c=Jk(u.dom);u.dom.scrollIntoView({block:"nearest"}),Zk(c,!1)}}}lineHasWidget(e){let n=r=>r.isWidget()||r.children.some(n);return n(this.tile.resolveBlock(e,1).tile)}destroy(){lm(this.tile)}};function lm(t,e){let n=e?.get(t);if(n!=1){n==null&&t.destroy();for(let r of t.children)lm(r,e)}}function bT(t){return t.node.nodeType==1&&t.node.firstChild&&(t.offset==0||t.node.childNodes[t.offset-1].contentEditable=="false")&&(t.offset==t.node.childNodes.length||t.node.childNodes[t.offset].contentEditable=="false")}function CS(t,e){let n=t.observer.selectionRange;if(!n.focusNode)return null;let r=tS(n.focusNode,n.focusOffset),a=nS(n.focusNode,n.focusOffset),s=r||a;if(a&&r&&a.node!=r.node){let o=Yt.get(a.node);if(!o||o.isText()&&o.text!=a.node.nodeValue)s=a;else if(t.docView.lastCompositionAfterCursor){let l=Yt.get(r.node);!l||l.isText()&&l.text!=r.node.nodeValue||(s=a)}}if(t.docView.lastCompositionAfterCursor=s!=r,!s)return null;let i=e-s.offset;return{from:i,to:i+s.node.nodeValue.length,node:s.node}}function wT(t,e,n){let r=CS(t,n);if(!r)return null;let{node:a,from:s,to:i}=r,o=a.nodeValue;if(/[\n\r]/.test(o)||t.state.doc.sliceString(r.from,r.to)!=o)return null;let l=e.invertedDesc;return{range:new la(l.mapPos(s),l.mapPos(i),s,i),text:a}}function vT(t,e){return t.nodeType!=1?0:(e&&t.childNodes[e-1].contentEditable=="false"?1:0)|(e<t.childNodes.length&&t.childNodes[e].contentEditable=="false"?2:0)}var kT=class{constructor(){this.changes=[]}compareRange(e,n){Eo(e,n,this.changes)}comparePoint(e,n){Eo(e,n,this.changes)}boundChange(e){Eo(e,e,this.changes)}};function ST(t,e,n){let r=new kT;return wt.compare(t,e,n,r),r.changes}var um=class{constructor(){this.changes=[]}compareRange(e,n){Eo(e,n,this.changes)}comparePoint(){}boundChange(e){Eo(e,e,this.changes)}};function CT(t,e,n){let r=new um;return wt.compare(t,e,n,r),r.changes}function IT(t,e){for(let n=t;n&&n!=e;n=n.assignedSlot||n.parentNode)if(n.nodeType==1&&n.contentEditable=="false")return!0;return!1}function LT(t,e){let n=!1;return e&&t.iterChangedRanges((r,a)=>{r<e.to&&a>e.from&&(n=!0)}),n}var wu=class extends Ir{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}};function AT(t,e,n=1){let r=t.charCategorizer(e),a=t.doc.lineAt(e),s=e-a.from;if(a.length==0)return se.cursor(e);s==0?n=1:s==a.length&&(n=-1);let i=s,o=s;n<0?i=Pn(a.text,s,!1):o=Pn(a.text,s);let l=r(a.text.slice(i,o));for(;i>0;){let u=Pn(a.text,i,!1);if(r(a.text.slice(u,i))!=l)break;i=u}for(;o<a.length;){let u=Pn(a.text,o);if(r(a.text.slice(o,u))!=l)break;o=u}return se.undirectionalRange(i+a.from,o+a.from)}function PT(t,e,n,r,a){let s=Math.round((r-e.left)*t.defaultCharacterWidth);if(t.lineWrapping&&n.height>t.defaultLineHeight*1.5){let o=t.viewState.heightOracle.textHeight,l=Math.floor((a-n.top-(t.defaultLineHeight-o)*.5)/o);s+=l*t.viewState.heightOracle.lineLength}let i=t.state.sliceDoc(n.from,n.to);return n.from+dk(i,s,t.state.tabSize)}function cm(t,e,n){let r=t.lineBlockAt(e);if(Array.isArray(r.type)){let a;for(let s of r.type){if(s.from>e)break;if(!(s.to<e)){if(s.from<e&&s.to>e)return s;(!a||s.type==On.Text&&(a.type!=s.type||(n<0?s.from<e:s.to>e)))&&(a=s)}}return a||r}return r}function NT(t,e,n,r){let a=cm(t,e.head,e.assoc||-1),s=!r||a.type!=On.Text||!(t.lineWrapping||a.widgetLineBreaks)?null:t.coordsAtPos(e.assoc<0&&e.head>a.from?e.head-1:e.head);if(s){let i=t.dom.getBoundingClientRect(),o=t.textDirectionAt(a.from),l=t.posAtCoords({x:n==(o==Vt.LTR)?i.right-1:i.left+1,y:(s.top+s.bottom)/2});if(l!=null)return se.cursor(l,n?-1:1)}return se.cursor(n?a.to:a.from,n?-1:1)}function Ik(t,e,n,r){let a=t.state.doc.lineAt(e.head),s=t.bidiSpans(a),i=t.textDirectionAt(a.from);for(let o=e,l=null;;){let u=cT(a,s,i,o,n),c=oS;if(!u){if(a.number==(n?t.state.doc.lines:1))return o;c=`
|
|
39
|
-
`,a=t.state.doc.line(a.number+(n?1:-1)),s=t.bidiSpans(a),u=n?se.cursor(a.from,-1):se.cursor(a.to,1)}if(l){if(!l(c))return o}else{if(!r)return u;l=r(c)}o=u}}function RT(t,e,n){let r=t.state.charCategorizer(e),a=r(n);return s=>{let i=r(s);return a==sa.Space&&(a=i),a==i}}function MT(t,e,n,r){let a=e.head,s=n?1:-1;if(a==(n?t.state.doc.length:0))return se.cursor(a,e.assoc);let i=e.goalColumn,o,l=t.contentDOM.getBoundingClientRect(),u=t.coordsAtPos(a,e.assoc||((e.empty?n:e.head==e.from)?1:-1)),c=t.documentTop;if(u)i==null&&(i=u.left-l.left),o=s<0?u.top:u.bottom;else{let p=t.viewState.lineBlockAt(a);i==null&&(i=Math.min(l.right-l.left,t.defaultCharacterWidth*(a-p.from))),o=(s<0?p.top:p.bottom)+c}let d=l.left+i,f=t.viewState.heightOracle.textHeight>>1,h=r??f;for(let p=0;;p+=f){let g=o+(h+p)*s,m=dm(t,{x:d,y:g},!1,s);if(n?g>l.bottom:g<l.top)return se.cursor(m.pos,m.assoc);let x=t.coordsAtPos(m.pos,m.assoc),y=x?(x.top+x.bottom)/2:0;if(!x||(n?y>o:y<o))return se.cursor(m.pos,m.assoc,void 0,i)}}function vu(t,e,n){for(;;){let r=0;for(let a of t)a.between(e-1,e+1,(s,i,o)=>{if(e>s&&e<i){let l=r||n||(e-s<i-e?-1:1);e=l<0?s:i,r=l}});if(!r)return e}}function IS(t,e){let n=null;for(let r=0;r<e.ranges.length;r++){let a=e.ranges[r],s=null;if(a.empty){let i=vu(t,a.from,0);i!=a.from&&(s=se.cursor(i,-1))}else{let i=vu(t,a.from,-1),o=vu(t,a.to,1);(i!=a.from||o!=a.to)&&(a.undirectional?s=se.undirectionalRange(a.from,a.to):s=se.range(a.from==a.anchor?i:o,a.from==a.head?i:o))}s&&(n||(n=e.ranges.slice()),n[r]=s)}return n?se.create(n,e.mainIndex):e}function zp(t,e,n){let r=vu(t.state.facet(Ru).map(a=>a(t)),n.from,e.head>n.from?-1:1);return r==n.from?n:se.cursor(r,r<n.from?1:-1)}var Gr=class{constructor(e,n){this.pos=e,this.assoc=n}};function dm(t,e,n,r){let a=t.contentDOM.getBoundingClientRect(),s=a.top+t.viewState.paddingTop,{x:i,y:o}=e,l=o-s,u;for(;;){if(l<0)return new Gr(0,1);if(l>t.viewState.docHeight)return new Gr(t.state.doc.length,-1);if(u=t.elementAtHeight(l),r==null)break;if(u.type==On.Text){if(r<0?u.to<t.viewport.from:u.from>t.viewport.to)break;let f=t.docView.coordsAt(r<0?u.from:u.to,r>0?-1:1);if(f&&(r<0?f.top<=l+s:f.bottom>=l+s))break}let d=t.viewState.heightOracle.textHeight/2;l=r>0?u.bottom+d:u.top-d}if(t.viewport.from>=u.to||t.viewport.to<=u.from){if(n)return null;if(u.type==On.Text){let d=PT(t,a,u,i,o);return new Gr(d,d==u.from?1:-1)}}if(u.type!=On.Text)return l<(u.top+u.bottom)/2?new Gr(u.from,1):new Gr(u.to,-1);let c=t.docView.lineAt(u.from,2);return(!c||c.length!=u.length)&&(c=t.docView.lineAt(u.from,-2)),new fm(t,i,o,t.textDirectionAt(u.from)).scanTile(c,u.from)}var fm=class{constructor(e,n,r,a){this.view=e,this.x=n,this.y=r,this.baseDir=a,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to<e)&&(this.line=this.view.state.doc.lineAt(e),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(e,n){let{line:r,spans:a}=this.bidiSpansAt(e);return a[Wr.find(a,e-r.from,-1,n)].level==this.baseDir}dirAt(e,n){let{line:r,spans:a}=this.bidiSpansAt(e);return a[Wr.find(a,e-r.from,-1,n)].dir}bidiIn(e,n){let{spans:r,line:a}=this.bidiSpansAt(e);return r.length>1||r.length&&(r[0].level!=this.baseDir||r[0].to+a.from<n)}scan(e,n,r=!1){let a=0,s=e.length-1,i=new Set,o=this.bidiIn(e[0],e[s]),l,u,c=-1,d=1e9,f;e:for(;a<s;){let p=s-a,g=a+s>>1;t:if(i.has(g)){for(let y=1;y<p;y++){let b=g+y;if(b>=s&&(b-=p),!i.has(b)){g=b;break t}}break e}i.add(g);let m=n(g),x=0;if(m)for(let y=0;y<m.length;y++){let b=m[y];if(!(b.width==0&&m.length>1))if(b.bottom<this.y)(!l||l.bottom<b.bottom)&&(l=b),x=1;else if(b.top>this.y)(!u||u.top>b.top)&&(u=b),x=-1;else{let C=b.left>this.x?this.x-b.left:b.right<this.x?this.x-b.right:0,L=Math.abs(C);L<d&&(c=g,d=L,f=b),C&&(x=C<0==(this.baseDir==Vt.LTR)?-1:1)}}x==-1&&(!o||this.baseDirAt(e[g],1))?s=g:x==1&&(!o||this.baseDirAt(e[g+1],-1))&&(a=g+1)}if(!f){if(!u&&!l)return{i:0,after:!1};let p=l&&(!u||this.y-l.bottom<u.top-this.y)?l:u;return this.y=(p.top+p.bottom)/2,this.scan(e,n,!0)}if(d&&!r){let{top:p,bottom:g}=f;if(l&&l.bottom>(p+p+g)/3)return this.y=l.bottom-1,this.scan(e,n,!0);if(u&&u.top<(p+g+g)/3)return this.y=u.top+1,this.scan(e,n,!0)}let h=(o?this.dirAt(e[c],1):this.baseDir)==Vt.LTR;return{i:c,after:this.x>(f.left+f.right)/2==h}}scanText(e,n){let r=[];for(let s=0;s<e.length;s=Pn(e.text,s))r.push(n+s);r.push(n+e.length);let a=this.scan(r,s=>{let i=r[s]-n,o=r[s+1]-n;return Nu(e.dom,i,o).getClientRects()});return a.after?new Gr(r[a.i+1],-1):new Gr(r[a.i],1)}scanTile(e,n){if(!e.length)return new Gr(n,1);if(e.children.length==1){let o=e.children[0];if(o.isText())return this.scanText(o,n);if(o.isComposite())return this.scanTile(o,n)}let r=[n];for(let o=0,l=n;o<e.children.length;o++)r.push(l+=e.children[o].length);let a=this.scan(r,o=>{let l=e.children[o];return l.flags&48?null:(l.dom.nodeType==1?l.dom:Nu(l.dom,0,l.length)).getClientRects()}),s=e.children[a.i],i=r[a.i];return s.isText()?this.scanText(s,i):s.isComposite()?this.scanTile(s,i):a.after?new Gr(r[a.i+1],-1):new Gr(i,1)}},Mo="\uFFFF",hm=class{constructor(e,n){this.points=e,this.view=n,this.text="",this.lineSeparator=n.state.facet(It.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=Mo}readRange(e,n){if(!e)return this;let r=e.parentNode;for(let a=e;;){this.findPointBefore(r,a);let s=this.text.length;this.readNode(a);let i=Yt.get(a),o=a.nextSibling;if(o==n){i?.breakAfter&&!o&&r!=this.view.contentDOM&&this.lineBreak();break}let l=Yt.get(o);(i&&l?i.breakAfter:(i?i.breakAfter:Dd(a))||Dd(o)&&(a.nodeName!="BR"||i?.isWidget())&&this.text.length>s)&&!DT(o,n)&&this.lineBreak(),a=o}return this.findPointBefore(r,n),this}readTextNode(e){let n=e.nodeValue;for(let r of this.points)r.node==e&&(r.pos=this.text.length+Math.min(r.offset,n.length));for(let r=0,a=this.lineSeparator?null:/\r\n?|\n/g;;){let s=-1,i=1,o;if(this.lineSeparator?(s=n.indexOf(this.lineSeparator,r),i=this.lineSeparator.length):(o=a.exec(n))&&(s=o.index,i=o[0].length),this.append(n.slice(r,s<0?n.length:s)),s<0)break;if(this.lineBreak(),i>1)for(let l of this.points)l.node==e&&l.pos>this.text.length&&(l.pos-=i-1);r=s+i}}readNode(e){let n=Yt.get(e),r=n&&n.overrideDOMText;if(r!=null){this.findPointInside(e,r.length);for(let a=r.iter();!a.next().done;)a.lineBreak?this.lineBreak():this.append(a.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,n){for(let r of this.points)r.node==e&&e.childNodes[r.offset]==n&&(r.pos=this.text.length)}findPointInside(e,n){for(let r of this.points)(e.nodeType==3?r.node==e:e.contains(r.node))&&(r.pos=this.text.length+(TT(e,r.node,r.offset)?n:0))}};function TT(t,e,n){for(;;){if(!e||n<os(e))return!1;if(e==t)return!0;n=Ws(e)+1,e=e.parentNode}}function DT(t,e){let n;for(;!(t==e||!t);t=t.nextSibling){let r=Yt.get(t);if(!r?.isWidget())return!1;r&&(n||(n=[])).push(r)}if(n)for(let r of n){let a=r.overrideDOMText;if(a?.length)return!1}return!0}var Bd=class{constructor(e,n){this.node=e,this.offset=n,this.pos=-1}},pm=class{constructor(e,n,r,a){this.typeOver=a,this.bounds=null,this.text="",this.domChanged=n>-1;let{impreciseHead:s,impreciseAnchor:i}=e.docView,o=e.state.selection;if(e.state.readOnly&&n>-1)this.newSel=null;else if(n>-1&&(this.bounds=LS(e.docView.tile,n,r,0))){let l=s||i?[]:ET(e),u=new hm(l,e);u.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=u.text,this.newSel=OT(l,this.bounds.from)}else{let l=e.observer.selectionRange,u=s&&s.node==l.focusNode&&s.offset==l.focusOffset||!Yp(e.contentDOM,l.focusNode)?o.main.head:e.docView.posFromDOM(l.focusNode,l.focusOffset),c=i&&i.node==l.anchorNode&&i.offset==l.anchorOffset||!Yp(e.contentDOM,l.anchorNode)?o.main.anchor:e.docView.posFromDOM(l.anchorNode,l.anchorOffset),d=e.viewport;if((ke.ios||ke.chrome)&&u!=c&&Math.min(u,c)<=o.main.from&&Math.max(u,c)>=o.main.to&&(d.from>0||d.to<e.state.doc.length)){let f=Math.min(u,c),h=Math.max(u,c),p=d.from-f,g=d.to-h;(p==0||p==1||f==0)&&(g==0||g==-1||h==e.state.doc.length)&&(u=0,c=e.state.doc.length)}if(e.inputState.composing>-1&&o.ranges.length>1)this.newSel=o.replaceRange(se.range(c,u));else if(e.lineWrapping&&c==u&&!(o.main.empty&&o.main.head==u)&&e.inputState.lastTouchTime>Date.now()-100){let f=e.coordsAtPos(u,-1),h=0;f&&(h=e.inputState.lastTouchY<=f.bottom?-1:1),this.newSel=se.create([se.cursor(u,h)])}else this.newSel=se.single(c,u)}}};function LS(t,e,n,r){if(t.isComposite()){let a=-1,s=-1,i=-1,o=-1;for(let l=0,u=r,c=r;l<t.children.length;l++){let d=t.children[l],f=u+d.length;if(u<e&&f>n)return LS(d,e,n,u);if(f>=e&&a==-1&&(a=l,s=u),u>n&&d.dom.parentNode==t.dom){i=l,o=c;break}c=f,u=f+d.breakAfter}return{from:s,to:o<0?r+t.length:o,startDOM:(a?t.children[a-1].dom.nextSibling:null)||t.dom.firstChild,endDOM:i<t.children.length&&i>=0?t.children[i].dom:null}}else return t.isText()?{from:r,to:r+t.length,startDOM:t.dom,endDOM:t.dom.nextSibling}:null}function AS(t,e){let n,{newSel:r}=e,{state:a}=t,s=a.selection.main,i=t.inputState.lastKeyTime>Date.now()-100?t.inputState.lastKeyCode:-1;if(e.bounds){let{from:o,to:l}=e.bounds,u=s.from,c=null;(i===8||ke.android&&e.text.length<l-o)&&(u=s.to,c="end");let d=a.doc.sliceString(o,l,Mo),f,h;!s.empty&&s.from>=o&&s.to<=l&&(e.typeOver||d!=e.text)&&d.slice(0,s.from-o)==e.text.slice(0,s.from-o)&&d.slice(s.to-o)==e.text.slice(f=e.text.length-(d.length-(s.to-o)))?n={from:s.from,to:s.to,insert:st.of(e.text.slice(s.from-o,f).split(Mo))}:(h=PS(d,e.text,u-o,c))&&(ke.chrome&&i==13&&h.toB==h.from+2&&e.text.slice(h.from,h.toB)==Mo+Mo&&h.toB--,n={from:o+h.from,to:o+h.toA,insert:st.of(e.text.slice(h.from,h.toB).split(Mo))})}else r&&(!t.hasFocus&&a.facet(ss)||_d(r,s))&&(r=null);if(!n&&!r)return!1;if((ke.mac||ke.android)&&n&&n.from==n.to&&n.from==s.head-1&&/^\. ?$/.test(n.insert.toString())&&t.contentDOM.getAttribute("autocorrect")=="off"?(r&&n.insert.length==2&&(r=se.single(r.main.anchor-1,r.main.head-1)),n={from:n.from,to:n.to,insert:st.of([n.insert.toString().replace("."," ")])}):a.doc.lineAt(s.from).to<s.to&&t.docView.lineHasWidget(s.to)&&t.inputState.insertingTextAt>Date.now()-50?n={from:s.from,to:s.to,insert:a.toText(t.inputState.insertingText)}:ke.chrome&&n&&n.from==n.to&&n.from==s.head&&n.insert.toString()==`
|
|
40
|
-
`&&t.lineWrapping&&(r&&(r=se.single(r.main.anchor-1,r.main.head-1)),n={from:s.from,to:s.to,insert:st.of([" "])}),n)return zm(t,n,r,i);if(r&&!_d(r,s)){let o=!1,l="select";return t.inputState.lastSelectionTime>Date.now()-50&&(t.inputState.lastSelectionOrigin=="select"&&(o=!0),l=t.inputState.lastSelectionOrigin,l=="select.pointer"&&(r=IS(a.facet(Ru).map(u=>u(t)),r))),t.dispatch({selection:r,scrollIntoView:o,userEvent:l}),!0}else return!1}function zm(t,e,n,r=-1){if(ke.ios&&t.inputState.flushIOSKey(e))return!0;let a=t.state.selection.main;if(ke.android&&(e.to==a.to&&(e.from==a.from||e.from==a.from-1&&t.state.sliceDoc(e.from,a.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&Oo(t.contentDOM,"Enter",13)||(e.from==a.from-1&&e.to==a.to&&e.insert.length==0||r==8&&e.insert.length<e.to-e.from&&e.to>a.head)&&Oo(t.contentDOM,"Backspace",8)||e.from==a.from&&e.to==a.to+1&&e.insert.length==0&&Oo(t.contentDOM,"Delete",46)))return!0;let s=e.insert.toString();t.inputState.composing>=0&&t.inputState.composing++;let i,o=()=>i||(i=FT(t,e,n));return t.state.facet(fS).some(l=>l(t,e.from,e.to,s,o))||t.dispatch(o()),!0}function FT(t,e,n){let r,a=t.state,s=a.selection.main,i=-1;if(e.from==e.to&&e.from<s.from||e.from>s.to){let l=e.from<s.from?-1:1,u=l<0?s.from:s.to,c=vu(a.facet(Ru).map(d=>d(t)),u,l);e.from==c&&(i=c)}if(i>-1)r={changes:e,selection:se.cursor(e.from+e.insert.length,-1)};else if(e.from>=s.from&&e.to<=s.to&&e.to-e.from>=(s.to-s.from)/3&&(!n||n.main.empty&&n.main.from==e.from+e.insert.length)&&t.inputState.composing<0){let l=s.from<e.from?a.sliceDoc(s.from,e.from):"",u=s.to>e.to?a.sliceDoc(e.to,s.to):"";r=a.replaceSelection(t.state.toText(l+e.insert.sliceString(0,void 0,t.state.lineBreak)+u))}else{let l=a.changes(e),u=n&&n.main.to<=l.newLength?n.main:void 0;if(a.selection.ranges.length>1&&(t.inputState.composing>=0||t.inputState.compositionPendingChange)&&e.to<=s.to+10&&e.to>=s.to-10){let c=t.state.sliceDoc(e.from,e.to),d,f=n&&CS(t,n.main.head);if(f){let p=e.insert.length-(e.to-e.from);d={from:f.from,to:f.to-p}}else d=t.state.doc.lineAt(s.head);let h=s.to-e.to;r=a.changeByRange(p=>{if(p.from==s.from&&p.to==s.to)return{changes:l,range:u||p.map(l)};let g=p.to-h,m=g-c.length;if(t.state.sliceDoc(m,g)!=c||g>=d.from&&m<=d.to)return{range:p};let x=a.changes({from:m,to:g,insert:e.insert}),y=p.to-s.to;return{changes:x,range:u?se.range(Math.max(0,u.anchor+y),Math.max(0,u.head+y)):p.map(x)}})}else r={changes:l,selection:u&&a.selection.replaceRange(u)}}let o="input.type";return(t.composing||t.inputState.compositionPendingChange&&t.inputState.compositionEndedAt>Date.now()-50)&&(t.inputState.compositionPendingChange=!1,o+=".compose",t.inputState.compositionFirstChange&&(o+=".start",t.inputState.compositionFirstChange=!1)),a.update(r,{userEvent:o,scrollIntoView:!0})}function PS(t,e,n,r){let a=Math.min(t.length,e.length),s=0;for(;s<a&&t.charCodeAt(s)==e.charCodeAt(s);)s++;if(s==a&&t.length==e.length)return null;let i=t.length,o=e.length;for(;i>0&&o>0&&t.charCodeAt(i-1)==e.charCodeAt(o-1);)i--,o--;if(r=="end"){let l=Math.max(0,s-Math.min(i,o));n-=i+l-s}if(i<s&&t.length<e.length){let l=n<=s&&n>=i?s-n:0;s-=l,o=s+(o-i),i=s}else if(o<s){let l=n<=s&&n>=o?s-n:0;s-=l,i=s+(i-o),o=s}return{from:s,toA:i,toB:o}}function ET(t){let e=[];if(t.root.activeElement!=t.contentDOM)return e;let{anchorNode:n,anchorOffset:r,focusNode:a,focusOffset:s}=t.observer.selectionRange;return n&&(e.push(new Bd(n,r)),(a!=n||s!=r)&&e.push(new Bd(a,s))),e}function OT(t,e){if(t.length==0)return null;let n=t[0].pos,r=t.length==2?t[1].pos:n;return n<0||r<0?null:n==r?se.create([se.cursor(r+e,-1)]):se.single(n+e,r+e)}function _d(t,e){return e.head==t.main.head&&e.anchor==t.main.anchor}var mm=class{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.touchActive=!1,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.lastIOSMomentumScroll=0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,ke.safari&&e.contentDOM.addEventListener("input",()=>null),ke.gecko&&JT(e.contentDOM.ownerDocument)}handleEvent(e){!jT(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(e.type,e)):this.runHandlers(e.type,e))}runHandlers(e,n){let r=this.handlers[e];if(r){for(let a of r.observers)a(this.view,n);for(let a of r.handlers){if(n.defaultPrevented)break;if(a(this.view,n)){n.preventDefault();break}}}}ensureHandlers(e){let n=_T(e),r=this.handlers,a=this.view.contentDOM;for(let s in n)if(s!="scroll"){let i=!n[s].handlers.length,o=r[s];o&&i!=!o.handlers.length&&(a.removeEventListener(s,this.handleEvent),o=null),o||a.addEventListener(s,this.handleEvent,{passive:i})}for(let s in r)s!="scroll"&&!n[s]&&a.removeEventListener(s,this.handleEvent);this.handlers=n}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&RS.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),ke.android&&ke.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;if(ke.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&(NS.some(n=>n.keyCode==e.keyCode)&&!e.ctrlKey||HT.indexOf(e.key)>-1&&e.ctrlKey)){let n={ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey,shiftKey:e.shiftKey};n.shiftKey&&ke.ios&&!/^(off|none)$/.test(this.view.contentDOM.autocapitalize)&&BT(this.view.win)&&(n.shiftKey=!1);let r=this.pendingIOSKey={key:e.key,keyCode:e.keyCode,mods:n};return setTimeout(()=>{this.pendingIOSKey==r&&this.flushIOSKey()},50),!0}return e.keyCode!=229&&this.view.observer.forceFlush(),!1}flushIOSKey(e){let n=this.pendingIOSKey;return!n||this.view.observer.pendingRecords().length||n.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,Oo(this.view.contentDOM,n.key,n.keyCode,n.mods))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:ke.safari&&!ke.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}};function BT(t){return t.visualViewport?t.visualViewport.height*t.visualViewport.scale/t.document.documentElement.clientHeight<.85:!1}function Lk(t,e){return(n,r)=>{try{return e.call(t,r,n)}catch(a){oa(n.state,a)}}}function _T(t){let e=Object.create(null);function n(r){return e[r]||(e[r]={observers:[],handlers:[]})}for(let r of t){let a=r.spec,s=a&&a.plugin.domEventHandlers,i=a&&a.plugin.domEventObservers;if(s)for(let o in s){let l=s[o];l&&n(o).handlers.push(Lk(r.value,l))}if(i)for(let o in i){let l=i[o];l&&n(o).observers.push(Lk(r.value,l))}}for(let r in ua)n(r).handlers.push(ua[r]);for(let r in tr)n(r).observers.push(tr[r]);return e}var NS=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],HT="dthko",RS=[16,17,18,20,91,92,224,225],kd=6;function Sd(t){return Math.max(0,t)*.7+8}function UT(t,e){return Math.max(Math.abs(t.clientX-e.clientX),Math.abs(t.clientY-e.clientY))}var gm=class{constructor(e,n,r,a){this.view=e,this.startEvent=n,this.style=r,this.mustSelect=a,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=n,this.scrollParents=Yk(e.contentDOM),this.atoms=e.state.facet(Ru).map(i=>i(e));let s=e.contentDOM.ownerDocument;s.addEventListener("mousemove",this.move=this.move.bind(this)),s.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=n.shiftKey,this.multiple=e.state.facet(It.allowMultipleSelections)&>(e,n),this.dragging=zT(e,n)&&DS(n)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&UT(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let n=0,r=0,a=0,s=0,i=this.view.win.innerWidth,o=this.view.win.innerHeight;this.scrollParents.x&&({left:a,right:i}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:s,bottom:o}=this.scrollParents.y.getBoundingClientRect());let l=kS(this.view);e.clientX-l.left<=a+kd?n=-Sd(a-e.clientX):e.clientX+l.right>=i-kd&&(n=Sd(e.clientX-i)),e.clientY-l.top<=s+kd?r=-Sd(s-e.clientY):e.clientY+l.bottom>=o-kd&&(r=Sd(e.clientY-o)),this.setScrollSpeed(n,r)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,n){this.scrollSpeed={x:e,y:n},e||n?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:n}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),n&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=n,n=0),(e||n)&&this.view.win.scrollBy(e,n),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:n}=this,r=IS(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!r.eq(n.state.selection,this.dragging===!1))&&this.view.dispatch({selection:r,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(n=>n.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}};function GT(t,e){let n=t.state.facet(lS);return n.length?n[0](e):ke.mac?e.metaKey:e.ctrlKey}function WT(t,e){let n=t.state.facet(uS);return n.length?n[0](e):ke.mac?!e.altKey:!e.ctrlKey}function zT(t,e){let{main:n}=t.state.selection;if(n.empty)return!1;let r=Au(t.root);if(!r||r.rangeCount==0)return!0;let a=r.getRangeAt(0).getClientRects();for(let s=0;s<a.length;s++){let i=a[s];if(i.left<=e.clientX&&i.right>=e.clientX&&i.top<=e.clientY&&i.bottom>=e.clientY)return!0}return!1}function jT(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let n=e.target,r;n!=t.contentDOM;n=n.parentNode)if(!n||n.nodeType==11||(r=Yt.get(n))&&r.isWidget()&&!r.isHidden&&r.widget.ignoreEvent(e))return!1;return!0}var ua=Object.create(null),tr=Object.create(null),MS=ke.ie&&ke.ie_version<15||ke.ios&&ke.webkit_version<604;function VT(t){let e=t.dom.parentNode;if(!e)return;let n=e.appendChild(document.createElement("textarea"));n.style.cssText="position: fixed; left: -10000px; top: 10px",n.focus(),setTimeout(()=>{t.focus(),n.remove(),TS(t,n.value)},50)}function $d(t,e,n){for(let r of t.facet(e))n=r(n,t);return n}function TS(t,e){e=$d(t.state,Hm,e);let{state:n}=t,r,a=1,s=n.toText(e),i=s.lines==n.selection.ranges.length;if(xm!=null&&n.selection.ranges.every(l=>l.empty)&&xm==s.toString()){let l=-1;r=n.changeByRange(u=>{let c=n.doc.lineAt(u.from);if(c.from==l)return{range:u};l=c.from;let d=n.toText((i?s.line(a++).text:e)+n.lineBreak);return{changes:{from:c.from,insert:d},range:se.cursor(u.from+d.length,-1)}})}else i?r=n.changeByRange(l=>{let u=s.line(a++);return{changes:{from:l.from,to:l.to,insert:u.text},range:se.cursor(l.from+u.length,-1)}}):r=n.replaceSelection(s);t.dispatch(r,{userEvent:"input.paste",scrollIntoView:!0})}tr.scroll=t=>{let e=t.inputState;e.lastScrollTop=t.scrollDOM.scrollTop,e.lastScrollLeft=t.scrollDOM.scrollLeft,ke.ios&&!e.touchActive&&(e.lastIOSMomentumScroll=Date.now())};tr.wheel=tr.mousewheel=t=>{t.inputState.lastWheelEvent=Date.now()};ua.keydown=(t,e)=>(t.inputState.setSelectionOrigin("select"),e.keyCode==27&&t.inputState.tabFocusMode!=0&&(t.inputState.tabFocusMode=Date.now()+2e3),!1);tr.touchstart=(t,e)=>{let n=t.inputState,r=e.targetTouches[0];n.touchActive=!0,n.lastTouchTime=Date.now(),r&&(n.lastTouchX=r.clientX,n.lastTouchY=r.clientY),n.setSelectionOrigin("select.pointer")};tr.touchmove=t=>{t.inputState.setSelectionOrigin("select.pointer")};tr.touchend=(t,e)=>{t.inputState.touchActive=!1};ua.mousedown=(t,e)=>{if(t.observer.flush(),t.inputState.lastTouchTime>Date.now()-2e3)return!1;let n=null;for(let r of t.state.facet(cS))if(n=r(t,e),n)break;if(!n&&e.button==0&&(n=$T(t,e)),n){let r=!t.hasFocus;t.inputState.startMouseSelection(new gm(t,e,n,r)),r&&t.observer.ignore(()=>{Qk(t.contentDOM);let s=t.root.activeElement;s&&!s.contains(t.contentDOM)&&s.blur()});let a=t.inputState.mouseSelection;if(a)return a.start(e),a.dragging===!1}else t.inputState.setSelectionOrigin("select.pointer");return!1};function Ak(t,e,n,r){if(r==1)return se.cursor(e,n);if(r==2)return AT(t.state,e,n);{let a=t.docView.lineAt(e,n),s=t.state.doc.lineAt(a?a.posAtEnd:e),i=a?a.posAtStart:s.from,o=a?a.posAtEnd:s.to;return o<t.state.doc.length&&o==s.to&&o++,se.undirectionalRange(i,o)}}var qT=ke.ie&&ke.ie_version<=11,Pk=null,Nk=0,Rk=0;function DS(t){if(!qT)return t.detail;let e=Pk,n=Rk;return Pk=t,Rk=Date.now(),Nk=!e||n>Date.now()-400&&Math.abs(e.clientX-t.clientX)<2&&Math.abs(e.clientY-t.clientY)<2?(Nk+1)%3:1}function $T(t,e){let n=t.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),r=DS(e),a=t.state.selection;return{update(s){s.docChanged&&(n.pos=s.changes.mapPos(n.pos),a=a.map(s.changes))},get(s,i,o){let l=t.posAndSideAtCoords({x:s.clientX,y:s.clientY},!1),u,c=Ak(t,l.pos,l.assoc,r);if(n.pos!=l.pos&&!i){let d=Ak(t,n.pos,n.assoc,r),f=Math.min(d.from,c.from),h=Math.max(d.to,c.to);c=f<c.from?se.range(f,h,c.assoc):se.range(h,f,c.assoc)}return i?a.replaceRange(a.main.extend(c.from,c.to,c.assoc)):o&&r==1&&a.ranges.length>1&&(u=KT(a,l.pos))?u:o?a.addRange(c):se.create([c])}}}function KT(t,e){for(let n=0;n<t.ranges.length;n++){let{from:r,to:a}=t.ranges[n];if(r<=e&&a>=e)return se.create(t.ranges.slice(0,n).concat(t.ranges.slice(n+1)),t.mainIndex==n?0:t.mainIndex-(t.mainIndex>n?1:0))}return null}ua.dragstart=(t,e)=>{let{selection:{main:n}}=t.state;if(e.target.draggable){let a=t.docView.tile.nearest(e.target);if(a&&a.isWidget()){let s=a.posAtStart,i=s+a.length;(s>=n.to||i<=n.from)&&(n=se.undirectionalRange(s,i))}}let{inputState:r}=t;return r.mouseSelection&&(r.mouseSelection.dragging=!0),r.draggedContent=n,e.dataTransfer&&(e.dataTransfer.setData("Text",$d(t.state,Um,t.state.sliceDoc(n.from,n.to))),e.dataTransfer.effectAllowed="copyMove"),!1};ua.dragend=t=>(t.inputState.draggedContent=null,!1);function Mk(t,e,n,r){if(n=$d(t.state,Hm,n),!n)return;let a=t.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:s}=t.inputState,i=r&&s&&WT(t,e)?{from:s.from,to:s.to}:null,o={from:a,insert:n},l=t.state.changes(i?[i,o]:o);t.focus(),t.dispatch({changes:l,selection:{anchor:l.mapPos(a,-1),head:l.mapPos(a,1)},userEvent:i?"move.drop":"input.drop"}),t.inputState.draggedContent=null}ua.drop=(t,e)=>{if(!e.dataTransfer)return!1;if(t.state.readOnly)return!0;let n=e.dataTransfer.files;if(n&&n.length){let r=Array(n.length),a=0,s=()=>{++a==n.length&&Mk(t,e,r.filter(i=>i!=null).join(t.state.lineBreak),!1)};for(let i=0;i<n.length;i++){let o=new FileReader;o.onerror=s,o.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(o.result)||(r[i]=o.result),s()},o.readAsText(n[i])}return!0}else{let r=e.dataTransfer.getData("Text");if(r)return Mk(t,e,r,!0),!0}return!1};ua.paste=(t,e)=>{if(t.state.readOnly)return!0;t.observer.flush();let n=MS?null:e.clipboardData;return n?(TS(t,n.getData("text/plain")||n.getData("text/uri-list")),!0):(VT(t),!1)};function XT(t,e){let n=t.dom.parentNode;if(!n)return;let r=n.appendChild(document.createElement("textarea"));r.style.cssText="position: fixed; left: -10000px; top: 10px",r.value=e,r.focus(),r.selectionEnd=e.length,r.selectionStart=0,setTimeout(()=>{r.remove(),t.focus()},50)}function YT(t){let e=[],n=[],r=!1;for(let a of t.selection.ranges)a.empty||(e.push(t.sliceDoc(a.from,a.to)),n.push(a));if(!e.length){let a=-1;for(let{from:s}of t.selection.ranges){let i=t.doc.lineAt(s);i.number>a&&(e.push(i.text),n.push({from:i.from,to:Math.min(t.doc.length,i.to+1)})),a=i.number}r=!0}return{text:$d(t,Um,e.join(t.lineBreak)),ranges:n,linewise:r}}var xm=null;ua.copy=ua.cut=(t,e)=>{if(!mu(t.contentDOM,t.observer.selectionRange))return!1;let{text:n,ranges:r,linewise:a}=YT(t.state);if(!n&&!a)return!1;xm=a?n:null,e.type=="cut"&&!t.state.readOnly&&t.dispatch({changes:r,scrollIntoView:!0,userEvent:"delete.cut"});let s=MS?null:e.clipboardData;return s?(s.clearData(),s.setData("text/plain",n),!0):(XT(t,n),!1)};var FS=Hr.define();function ES(t,e){let n=[];for(let r of t.facet(hS)){let a=r(t,e);a&&n.push(a)}return n.length?t.update({effects:n,annotations:FS.of(!0)}):null}function OS(t){setTimeout(()=>{let e=t.hasFocus;if(e!=t.inputState.notifiedFocused){let n=ES(t.state,e);n?t.dispatch(n):t.update([])}},10)}tr.focus=t=>{t.inputState.lastFocusTime=Date.now(),!t.scrollDOM.scrollTop&&(t.inputState.lastScrollTop||t.inputState.lastScrollLeft)&&(t.scrollDOM.scrollTop=t.inputState.lastScrollTop,t.scrollDOM.scrollLeft=t.inputState.lastScrollLeft),OS(t)};tr.blur=t=>{t.observer.clearSelectionRange(),OS(t)};tr.compositionstart=tr.compositionupdate=t=>{if(!t.observer.editContext&&(t.inputState.compositionFirstChange==null&&(t.inputState.compositionFirstChange=!0),t.inputState.composing<0)){let{main:e}=t.state.selection;!e.empty&&t.lineBlockAt(e.from).from!=t.lineBlockAt(e.to).from&&t.dispatch({changes:t.state.selection.ranges.filter(n=>!n.empty).map(n=>({from:n.from,to:n.to})),userEvent:"input"}),t.inputState.composing=0}};tr.compositionend=t=>{t.observer.editContext||(t.inputState.composing=-1,t.inputState.compositionEndedAt=Date.now(),t.inputState.compositionPendingKey=!0,t.inputState.compositionPendingChange=t.observer.pendingRecords().length>0,t.inputState.compositionFirstChange=null,ke.chrome&&ke.android?t.observer.flushSoon():t.inputState.compositionPendingChange?Promise.resolve().then(()=>t.observer.flush()):setTimeout(()=>{t.inputState.composing<0&&t.docView.hasComposition&&t.update([])},50))};tr.contextmenu=t=>{t.inputState.lastContextMenu=Date.now()};ua.beforeinput=(t,e)=>{var n,r;if((e.inputType=="insertText"||e.inputType=="insertCompositionText")&&(t.inputState.insertingText=e.data,t.inputState.insertingTextAt=Date.now()),e.inputType=="insertReplacementText"&&t.observer.editContext){let s=(n=e.dataTransfer)===null||n===void 0?void 0:n.getData("text/plain"),i=e.getTargetRanges();if(s&&i.length){let o=i[0],l=t.posAtDOM(o.startContainer,o.startOffset),u=t.posAtDOM(o.endContainer,o.endOffset);return zm(t,{from:l,to:u,insert:t.state.toText(s)},null),!0}}let a;if(ke.chrome&&ke.android&&(a=NS.find(s=>s.inputType==e.inputType))&&(t.observer.delayAndroidKey(a.key,a.keyCode),a.key=="Backspace"||a.key=="Delete")){let s=((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0;setTimeout(()=>{var i;(((i=window.visualViewport)===null||i===void 0?void 0:i.height)||0)>s+10&&t.hasFocus&&(t.contentDOM.blur(),t.focus())},100)}return ke.ios&&e.inputType=="deleteContentForward"&&t.observer.flushSoon(),ke.safari&&e.inputType=="insertText"&&t.inputState.composing>=0&&setTimeout(()=>tr.compositionend(t,e),20),!1};var Tk=new Set;function JT(t){Tk.has(t)||(Tk.add(t),t.addEventListener("copy",()=>{}),t.addEventListener("cut",()=>{}))}var Dk=["pre-wrap","normal","pre-line","break-spaces"],Go=!1;function Fk(){Go=!1}var ym=class{constructor(e){this.lineWrapping=e,this.doc=st.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,n){let r=this.doc.lineAt(n).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(r+=Math.max(0,Math.ceil((n-e-r*this.lineLength*.5)/this.lineLength))),this.lineHeight*r}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return Dk.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let n=!1;for(let r=0;r<e.length;r++){let a=e[r];a<0?r++:this.heightSamples[Math.floor(a*10)]||(n=!0,this.heightSamples[Math.floor(a*10)]=!0)}return n}refresh(e,n,r,a,s,i){let o=Dk.indexOf(e)>-1,l=Math.abs(n-this.lineHeight)>.3||this.lineWrapping!=o;if(this.lineWrapping=o,this.lineHeight=n,this.charWidth=r,this.textHeight=a,this.lineLength=s,l){this.heightSamples={};for(let u=0;u<i.length;u++){let c=i[u];c<0?u++:this.heightSamples[Math.floor(c*10)]=!0}}return l}},bm=class{constructor(e,n){this.from=e,this.heights=n,this.index=0}get more(){return this.index<this.heights.length}},ia=class t{constructor(e,n,r,a,s){this.from=e,this.length=n,this.top=r,this.height=a,this._content=s}get type(){return typeof this._content=="number"?On.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof Ri?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let n=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new t(this.from,this.length+e.length,this.top,this.height+e.height,n)}},jt=(function(t){return t[t.ByPos=0]="ByPos",t[t.ByHeight=1]="ByHeight",t[t.ByPosNoHeight=2]="ByPosNoHeight",t})(jt||(jt={})),Pd=.001,Cr=class t{constructor(e,n,r=2){this.length=e,this.height=n,this.flags=r}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>Pd&&(Go=!0),this.height=e)}replace(e,n,r){return t.of(r)}decomposeLeft(e,n){n.push(this)}decomposeRight(e,n){n.push(this)}applyChanges(e,n,r,a){let s=this,i=r.doc;for(let o=a.length-1;o>=0;o--){let{fromA:l,toA:u,fromB:c,toB:d}=a[o],f=s.lineAt(l,jt.ByPosNoHeight,r.setDoc(n),0,0),h=f.to>=u?f:s.lineAt(u,jt.ByPosNoHeight,r,0,0);for(d+=h.to-u,u=h.to;o>0&&f.from<=a[o-1].toA;)l=a[o-1].fromA,c=a[o-1].fromB,o--,l<f.from&&(f=s.lineAt(l,jt.ByPosNoHeight,r,0,0));c+=f.from-l,l=f.from;let p=vm.build(r.setDoc(i),e,c,d);s=Hd(s,s.replace(l,u,p))}return s.updateHeight(r,0)}static empty(){return new Ur(0,0,0)}static of(e){if(e.length==1)return e[0];let n=0,r=e.length,a=0,s=0;for(;;)if(n==r)if(a>s*2){let o=e[n-1];o.break?e.splice(--n,1,o.left,null,o.right):e.splice(--n,1,o.left,o.right),r+=1+o.break,a-=o.size}else if(s>a*2){let o=e[r];o.break?e.splice(r,1,o.left,null,o.right):e.splice(r,1,o.left,o.right),r+=2+o.break,s-=o.size}else break;else if(a<s){let o=e[n++];o&&(a+=o.size)}else{let o=e[--r];o&&(s+=o.size)}let i=!1;return e[n-1]==null?(i=!0,n--):e[n]==null&&(i=!0,r++),new wm(t.of(e.slice(0,n)),i,t.of(e.slice(r)))}};function Hd(t,e){return t==e?t:(t.constructor!=e.constructor&&(Go=!0),e)}Cr.prototype.size=1;var ZT=Ke.replace({}),Ud=class extends Cr{constructor(e,n,r){super(e,n),this.deco=r,this.spaceAbove=0}mainBlock(e,n){return new ia(n,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,n,r,a){return this.spaceAbove&&e<r+this.spaceAbove?new ia(a,0,r,this.spaceAbove,ZT):this.mainBlock(r,a)}lineAt(e,n,r,a,s){let i=this.mainBlock(a,s);return this.spaceAbove?this.blockAt(0,r,a,s).join(i):i}forEachLine(e,n,r,a,s,i){e<=s+this.length&&n>=s&&i(this.lineAt(0,jt.ByPos,r,a,s))}setMeasuredHeight(e){let n=e.heights[e.index++];n<0?(this.spaceAbove=-n,n=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(n)}updateHeight(e,n=0,r=!1,a){return a&&a.from<=n&&a.more&&this.setMeasuredHeight(a),this.outdated=!1,this}toString(){return`block(${this.length})`}},Ur=class t extends Ud{constructor(e,n,r){super(e,n,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=r}mainBlock(e,n){return new ia(n,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,n,r){let a=r[0];return r.length==1&&(a instanceof t||a instanceof Gs&&a.flags&4)&&Math.abs(this.length-a.length)<10?(a instanceof Gs?a=new t(a.length,this.height,this.spaceAbove):a.height=this.height,this.outdated||(a.outdated=!1),a):Cr.of(r)}updateHeight(e,n=0,r=!1,a){return a&&a.from<=n&&a.more?this.setMeasuredHeight(a):(r||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}},Gs=class t extends Cr{constructor(e){super(e,0)}heightMetrics(e,n){let r=e.doc.lineAt(n).number,a=e.doc.lineAt(n+this.length).number,s=a-r+1,i,o=0;if(e.lineWrapping){let l=Math.min(this.height,e.lineHeight*s);i=l/s,this.length>s+1&&(o=(this.height-l)/(this.length-s-1))}else i=this.height/s;return{firstLine:r,lastLine:a,perLine:i,perChar:o}}blockAt(e,n,r,a){let{firstLine:s,lastLine:i,perLine:o,perChar:l}=this.heightMetrics(n,a);if(n.lineWrapping){let u=a+(e<n.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-r)/this.height))*this.length)),c=n.doc.lineAt(u),d=o+c.length*l,f=Math.max(r,e-d/2);return new ia(c.from,c.length,f,d,0)}else{let u=Math.max(0,Math.min(i-s,Math.floor((e-r)/o))),{from:c,length:d}=n.doc.line(s+u);return new ia(c,d,r+o*u,o,0)}}lineAt(e,n,r,a,s){if(n==jt.ByHeight)return this.blockAt(e,r,a,s);if(n==jt.ByPosNoHeight){let{from:h,to:p}=r.doc.lineAt(e);return new ia(h,p-h,0,0,0)}let{firstLine:i,perLine:o,perChar:l}=this.heightMetrics(r,s),u=r.doc.lineAt(e),c=o+u.length*l,d=u.number-i,f=a+o*d+l*(u.from-s-d);return new ia(u.from,u.length,Math.max(a,Math.min(f,a+this.height-c)),c,0)}forEachLine(e,n,r,a,s,i){e=Math.max(e,s),n=Math.min(n,s+this.length);let{firstLine:o,perLine:l,perChar:u}=this.heightMetrics(r,s);for(let c=e,d=a;c<=n;){let f=r.doc.lineAt(c);if(c==e){let p=f.number-o;d+=l*p+u*(e-s-p)}let h=l+u*f.length;i(new ia(f.from,f.length,d,h,0)),d+=h,c=f.to+1}}replace(e,n,r){let a=this.length-n;if(a>0){let s=r[r.length-1];s instanceof t?r[r.length-1]=new t(s.length+a):r.push(null,new t(a-1))}if(e>0){let s=r[0];s instanceof t?r[0]=new t(e+s.length):r.unshift(new t(e-1),null)}return Cr.of(r)}decomposeLeft(e,n){n.push(new t(e-1),null)}decomposeRight(e,n){n.push(null,new t(this.length-e-1))}updateHeight(e,n=0,r=!1,a){let s=n+this.length;if(a&&a.from<=n+this.length&&a.more){let i=[],o=Math.max(n,a.from),l=-1;for(a.from>n&&i.push(new t(a.from-n-1).updateHeight(e,n));o<=s&&a.more;){let c=e.doc.lineAt(o).length;i.length&&i.push(null);let d=a.heights[a.index++],f=0;d<0&&(f=-d,d=a.heights[a.index++]),l==-1?l=d:Math.abs(d-l)>=Pd&&(l=-2);let h=new Ur(c,d,f);h.outdated=!1,i.push(h),o+=c+1}o<=s&&i.push(null,new t(s-o).updateHeight(e,o));let u=Cr.of(i);return(l<0||Math.abs(u.height-this.height)>=Pd||Math.abs(l-this.heightMetrics(e,n).perLine)>=Pd)&&(Go=!0),Hd(this,u)}else(r||this.outdated)&&(this.setHeight(e.heightForGap(n,n+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}},wm=class extends Cr{constructor(e,n,r){super(e.length+(n?1:0)+r.length,e.height+r.height,(n?1:0)|(e.outdated||r.outdated?2:0)),this.left=e,this.right=r,this.size=e.size+r.size}get break(){return this.flags&1}blockAt(e,n,r,a){let s=r+this.left.height;return e<s?this.left.blockAt(e,n,r,a):this.right.blockAt(e,n,s,a+this.left.length+this.break)}lineAt(e,n,r,a,s){let i=a+this.left.height,o=s+this.left.length+this.break,l=n==jt.ByHeight?e<i:e<o,u=l?this.left.lineAt(e,n,r,a,s):this.right.lineAt(e,n,r,i,o);if(this.break||(l?u.to<o:u.from>o))return u;let c=n==jt.ByPosNoHeight?jt.ByPosNoHeight:jt.ByPos;return l?u.join(this.right.lineAt(o,c,r,i,o)):this.left.lineAt(o,c,r,a,s).join(u)}forEachLine(e,n,r,a,s,i){let o=a+this.left.height,l=s+this.left.length+this.break;if(this.break)e<l&&this.left.forEachLine(e,n,r,a,s,i),n>=l&&this.right.forEachLine(e,n,r,o,l,i);else{let u=this.lineAt(l,jt.ByPos,r,a,s);e<u.from&&this.left.forEachLine(e,Math.min(n,u.from-1),r,a,s,i),u.to>=e&&u.from<=n&&i(u),n>u.to&&this.right.forEachLine(Math.max(e,u.to+1),n,r,o,l,i)}}replace(e,n,r){let a=this.left.length+this.break;if(n<a)return this.balanced(this.left.replace(e,n,r),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-a,n-a,r));let s=[];e>0&&this.decomposeLeft(e,s);let i=s.length;for(let o of r)s.push(o);if(e>0&&Ek(s,i-1),n<this.length){let o=s.length;this.decomposeRight(n,s),Ek(s,o)}return Cr.of(s)}decomposeLeft(e,n){let r=this.left.length;if(e<=r)return this.left.decomposeLeft(e,n);n.push(this.left),this.break&&(r++,e>=r&&n.push(null)),e>r&&this.right.decomposeLeft(e-r,n)}decomposeRight(e,n){let r=this.left.length,a=r+this.break;if(e>=a)return this.right.decomposeRight(e-a,n);e<r&&this.left.decomposeRight(e,n),this.break&&e<a&&n.push(null),n.push(this.right)}balanced(e,n){return e.size>2*n.size||n.size>2*e.size?Cr.of(this.break?[e,null,n]:[e,n]):(this.left=Hd(this.left,e),this.right=Hd(this.right,n),this.setHeight(e.height+n.height),this.outdated=e.outdated||n.outdated,this.size=e.size+n.size,this.length=e.length+this.break+n.length,this)}updateHeight(e,n=0,r=!1,a){let{left:s,right:i}=this,o=n+s.length+this.break,l=null;return a&&a.from<=n+s.length&&a.more?l=s=s.updateHeight(e,n,r,a):s.updateHeight(e,n,r),a&&a.from<=o+i.length&&a.more?l=i=i.updateHeight(e,o,r,a):i.updateHeight(e,o,r),l?this.balanced(s,i):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}};function Ek(t,e){let n,r;t[e]==null&&(n=t[e-1])instanceof Gs&&(r=t[e+1])instanceof Gs&&t.splice(e-1,3,new Gs(n.length+1+r.length))}var QT=5,vm=class t{constructor(e,n){this.pos=e,this.oracle=n,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,n){if(this.lineStart>-1){let r=Math.min(n,this.lineEnd),a=this.nodes[this.nodes.length-1];a instanceof Ur?a.length+=r-this.pos:(r>this.pos||!this.isCovered)&&this.nodes.push(new Ur(r-this.pos,-1,0)),this.writtenTo=r,n>r&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=n}point(e,n,r){if(e<n||r.heightRelevant){let a=r.widget?r.widget.estimatedHeight:0,s=r.widget?r.widget.lineBreaks:0;a<0&&(a=this.oracle.lineHeight);let i=n-e;r.block?this.addBlock(new Ud(i,a,r)):(i||s||a>=QT)&&this.addLineDeco(a,s,i)}else n>e&&this.span(e,n);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:n}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=n,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new Ur(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,n){let r=new Gs(n-e);return this.oracle.doc.lineAt(e).to==n&&(r.flags|=4),r}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof Ur)return e;let n=new Ur(0,-1,0);return this.nodes.push(n),n}addBlock(e){this.enterLine();let n=e.deco;n&&n.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,n&&n.endSide>0&&(this.covering=e)}addLineDeco(e,n,r){let a=this.ensureLine();a.length+=r,a.collapsed+=r,a.widgetHeight=Math.max(a.widgetHeight,e),a.breaks+=n,this.writtenTo=this.pos=this.pos+r}finish(e){let n=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(n instanceof Ur)&&!this.isCovered?this.nodes.push(new Ur(0,-1,0)):(this.writtenTo<this.pos||n==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let r=e;for(let a of this.nodes)a instanceof Ur&&a.updateHeight(this.oracle,r),r+=a?a.length:1;return this.nodes}static build(e,n,r,a){let s=new t(r,e);return wt.spans(n,r,a,s,0),s.finish(r)}};function eD(t,e,n){let r=new km;return wt.compare(t,e,n,r,0),r.changes}var km=class{constructor(){this.changes=[]}compareRange(){}comparePoint(e,n,r,a){(e<n||r&&r.heightRelevant||a&&a.heightRelevant)&&Eo(e,n,this.changes,5)}};function tD(t,e){let n=t.getBoundingClientRect(),r=t.ownerDocument,a=r.defaultView||window,s=Math.max(0,n.left),i=Math.min(a.innerWidth,n.right),o=Math.max(0,n.top),l=Math.min(a.innerHeight,n.bottom);for(let u=t.parentNode;u&&u!=r.body;)if(u.nodeType==1){let c=u,d=window.getComputedStyle(c);if((c.scrollHeight>c.clientHeight||c.scrollWidth>c.clientWidth)&&d.overflow!="visible"){let f=c.getBoundingClientRect();s=Math.max(s,f.left),i=Math.min(i,f.right),o=Math.max(o,f.top),l=Math.min(u==t.parentNode?a.innerHeight:l,f.bottom)}u=d.position=="absolute"||d.position=="fixed"?c.offsetParent:c.parentNode}else if(u.nodeType==11)u=u.host;else break;return{left:s-n.left,right:Math.max(s,i)-n.left,top:o-(n.top+e),bottom:Math.max(o,l)-(n.top+e)}}function nD(t){let e=t.getBoundingClientRect(),n=t.ownerDocument.defaultView||window;return e.left<n.innerWidth&&e.right>0&&e.top<n.innerHeight&&e.bottom>0}function rD(t,e){let n=t.getBoundingClientRect();return{left:0,right:n.right-n.left,top:e,bottom:n.bottom-(n.top+e)}}var ku=class{constructor(e,n,r,a){this.from=e,this.to=n,this.size=r,this.displaySize=a}static same(e,n){if(e.length!=n.length)return!1;for(let r=0;r<e.length;r++){let a=e[r],s=n[r];if(a.from!=s.from||a.to!=s.to||a.size!=s.size)return!1}return!0}draw(e,n){return Ke.replace({widget:new Sm(this.displaySize*(n?e.scaleY:e.scaleX),n)}).range(this.from,this.to)}},Sm=class extends Ir{constructor(e,n){super(),this.size=e,this.vertical=n}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}},Gd=class{constructor(e,n){this.view=e,this.state=n,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=Ok,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=Vt.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let r=n.facet(Gm).some(a=>typeof a!="function"&&a.class=="cm-lineWrapping");this.heightOracle=new ym(r),this.stateDeco=Bk(n),this.heightMap=Cr.empty().applyChanges(this.stateDeco,st.empty,this.heightOracle.setDoc(n.doc),[new la(0,0,0,n.doc.length)]);for(let a=0;a<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());a++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=Ke.set(this.lineGaps.map(a=>a.draw(this,!1))),this.scrollParent=e.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:n}=this.state.selection;for(let r=0;r<=1;r++){let a=r?n.head:n.anchor;if(!e.some(({from:s,to:i})=>a>=s&&a<=i)){let{from:s,to:i}=this.lineBlockAt(a);e.push(new Do(s,i))}}return this.viewports=e.sort((r,a)=>r.from-a.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?Ok:new Cm(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(pu(e,this.scaler))})}update(e,n=null){this.state=e.state;let r=this.stateDeco;this.stateDeco=Bk(this.state);let a=e.changedRanges,s=la.extendWithRanges(a,eD(r,this.stateDeco,e?e.changes:Nn.empty(this.state.doc.length))),i=this.heightMap.height,o=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);Fk(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),s),(this.heightMap.height!=i||Go)&&(e.flags|=2),o?(this.scrollAnchorPos=e.changes.mapPos(o.from,-1),this.scrollAnchorHeight=o.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=i);let l=s.length?this.mapViewport(this.viewport,e.changes):this.viewport;(n&&(n.range.head<l.from||n.range.head>l.to)||!this.viewportIsAppropriate(l))&&(l=this.getViewport(0,n));let u=l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,e.flags|=this.updateForViewport(),(u||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),n&&(this.scrollTarget=n),!this.mustEnforceCursorAssoc&&(e.selectionSet||e.focusChanged)&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(mS)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:e}=this,n=e.contentDOM,r=window.getComputedStyle(n),a=this.heightOracle,s=r.whiteSpace;this.defaultTextDirection=r.direction=="rtl"?Vt.RTL:Vt.LTR;let i=this.heightOracle.mustRefreshForWrapping(s)||this.mustMeasureContent==="refresh",o=n.getBoundingClientRect(),l=i||this.mustMeasureContent||this.contentDOMHeight!=o.height;this.contentDOMHeight=o.height,this.mustMeasureContent=!1;let u=0,c=0;if(o.width&&o.height){let{scaleX:L,scaleY:P}=Xk(n,o);(L>.005&&Math.abs(this.scaleX-L)>.005||P>.005&&Math.abs(this.scaleY-P)>.005)&&(this.scaleX=L,this.scaleY=P,u|=16,i=l=!0)}let d=(parseInt(r.paddingTop)||0)*this.scaleY,f=(parseInt(r.paddingBottom)||0)*this.scaleY;(this.paddingTop!=d||this.paddingBottom!=f)&&(this.paddingTop=d,this.paddingBottom=f,u|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(a.lineWrapping&&(l=!0),this.editorWidth=e.scrollDOM.clientWidth,u|=16);let h=Yk(this.view.contentDOM,!1).y;h!=this.scrollParent&&(this.scrollParent=h,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=eS(this.scrollParent||e.win);let g=(this.printing?rD:tD)(n,this.paddingTop),m=g.top-this.pixelViewport.top,x=g.bottom-this.pixelViewport.bottom;this.pixelViewport=g;let y=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(y!=this.inView&&(this.inView=y,y&&(l=!0)),!this.inView&&!this.scrollTarget&&!nD(e.dom))return 0;let b=o.width;if((this.contentDOMWidth!=b||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=o.width,this.editorHeight=e.scrollDOM.clientHeight,u|=16),l){let L=e.docView.measureVisibleLineHeights(this.viewport);if(a.mustRefreshForHeights(L)&&(i=!0),i||a.lineWrapping&&Math.abs(b-this.contentDOMWidth)>a.charWidth){let{lineHeight:P,charWidth:w,textHeight:k}=e.docView.measureTextSize();i=P>0&&a.refresh(s,P,w,k,Math.max(5,b/w),L),i&&(e.docView.minWidth=0,u|=16)}m>0&&x>0?c=Math.max(m,x):m<0&&x<0&&(c=Math.min(m,x)),Fk();for(let P of this.viewports){let w=P.from==this.viewport.from?L:e.docView.measureVisibleLineHeights(P);this.heightMap=(i?Cr.empty().applyChanges(this.stateDeco,st.empty,this.heightOracle,[new la(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(a,0,i,new bm(P.from,w))}Go&&(u|=2)}let C=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return C&&(u&2&&(u|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),u|=this.updateForViewport()),(u&2||C)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(i?[]:this.lineGaps,e)),u|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),u}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,n){let r=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),a=this.heightMap,s=this.heightOracle,{visibleTop:i,visibleBottom:o}=this,l=new Do(a.lineAt(i-r*1e3,jt.ByHeight,s,0,0).from,a.lineAt(o+(1-r)*1e3,jt.ByHeight,s,0,0).to);if(n){let{head:u}=n.range;if(u<l.from||u>l.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),d=a.lineAt(u,jt.ByPos,s,0,0),f;n.y=="center"?f=(d.top+d.bottom)/2-c/2:n.y=="start"||n.y=="nearest"&&u<l.from?f=d.top:f=d.bottom-c,l=new Do(a.lineAt(f-1e3/2,jt.ByHeight,s,0,0).from,a.lineAt(f+c+1e3/2,jt.ByHeight,s,0,0).to)}}return l}mapViewport(e,n){let r=n.mapPos(e.from,-1),a=n.mapPos(e.to,1);return new Do(this.heightMap.lineAt(r,jt.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(a,jt.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:n},r=0){if(!this.inView)return!0;let{top:a}=this.heightMap.lineAt(e,jt.ByPos,this.heightOracle,0,0),{bottom:s}=this.heightMap.lineAt(n,jt.ByPos,this.heightOracle,0,0),{visibleTop:i,visibleBottom:o}=this;return(e==0||a<=i-Math.max(10,Math.min(-r,250)))&&(n==this.state.doc.length||s>=o+Math.max(10,Math.min(r,250)))&&a>i-2*1e3&&s<o+2*1e3}mapLineGaps(e,n){if(!e.length||n.empty)return e;let r=[];for(let a of e)n.touchesRange(a.from,a.to)||r.push(new ku(n.mapPos(a.from),n.mapPos(a.to),a.size,a.displaySize));return r}ensureLineGaps(e,n){let r=this.heightOracle.lineWrapping,a=r?1e4:2e3,s=a>>1,i=a<<1;if(this.defaultTextDirection!=Vt.LTR&&!r)return[];let o=[],l=(c,d,f,h)=>{if(d-c<s)return;let p=this.state.selection.main,g=[p.from];p.empty||g.push(p.to);for(let x of g)if(x>c&&x<d){l(c,x-10,f,h),l(x+10,d,f,h);return}let m=sD(e,x=>x.from>=f.from&&x.to<=f.to&&Math.abs(x.from-c)<s&&Math.abs(x.to-d)<s&&!g.some(y=>x.from<y&&x.to>y));if(!m){if(d<f.to&&n&&r&&n.visibleRanges.some(b=>b.from<=d&&b.to>=d)){let b=n.moveToLineBoundary(se.cursor(d),!1,!0).head;b>c&&(d=b)}let x=this.gapSize(f,c,d,h),y=r||x<2e6?x:2e6;m=new ku(c,d,x,y)}o.push(m)},u=c=>{if(c.length<i||c.type!=On.Text)return;let d=aD(c.from,c.to,this.stateDeco);if(d.total<i)return;let f=this.scrollTarget?this.scrollTarget.range.head:null,h,p;if(r){let g=a/this.heightOracle.lineLength*this.heightOracle.lineHeight,m,x;if(f!=null){let y=Id(d,f),b=((this.visibleBottom-this.visibleTop)/2+g)/c.height;m=y-b,x=y+b}else m=(this.visibleTop-c.top-g)/c.height,x=(this.visibleBottom-c.top+g)/c.height;h=Cd(d,m),p=Cd(d,x)}else{let g=d.total*this.heightOracle.charWidth,m=a*this.heightOracle.charWidth,x=0;if(g>2e6)for(let P of e)P.from>=c.from&&P.from<c.to&&P.size!=P.displaySize&&P.from*this.heightOracle.charWidth+x<this.pixelViewport.left&&(x=P.size-P.displaySize);let y=this.pixelViewport.left+x,b=this.pixelViewport.right+x,C,L;if(f!=null){let P=Id(d,f),w=((b-y)/2+m)/g;C=P-w,L=P+w}else C=(y-m)/g,L=(b+m)/g;h=Cd(d,C),p=Cd(d,L)}h>c.from&&l(c.from,h,c,d),p<c.to&&l(p,c.to,c,d)};for(let c of this.viewportLines)Array.isArray(c.type)?c.type.forEach(u):u(c);return o}gapSize(e,n,r,a){let s=Id(a,r)-Id(a,n);return this.heightOracle.lineWrapping?e.height*s:a.total*this.heightOracle.charWidth*s}updateLineGaps(e){ku.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=Ke.set(e.map(n=>n.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let n=this.stateDeco;this.lineGaps.length&&(n=n.concat(this.lineGapDeco));let r=[];wt.spans(n,this.viewport.from,this.viewport.to,{span(s,i){r.push({from:s,to:i})},point(){}},20);let a=0;if(r.length!=this.visibleRanges.length)a=12;else for(let s=0;s<r.length&&!(a&8);s++){let i=this.visibleRanges[s],o=r[s];(i.from!=o.from||i.to!=o.to)&&(a|=4,e&&e.mapPos(i.from,-1)==o.from&&e.mapPos(i.to,1)==o.to||(a|=8))}return this.visibleRanges=r,a}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(n=>n.from<=e&&n.to>=e)||pu(this.heightMap.lineAt(e,jt.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(n=>n.top<=e&&n.bottom>=e)||pu(this.heightMap.lineAt(this.scaler.fromDOM(e),jt.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop*this.scaleY:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top}scrollAnchorAt(e){let n=this.lineBlockAtHeight(e+8);return n.from>=this.viewport.from||this.viewportLines[0].top-e>200?n:this.viewportLines[0]}elementAtHeight(e){return pu(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}},Do=class{constructor(e,n){this.from=e,this.to=n}};function aD(t,e,n){let r=[],a=t,s=0;return wt.spans(n,t,e,{span(){},point(i,o){i>a&&(r.push({from:a,to:i}),s+=i-a),a=o}},20),a<e&&(r.push({from:a,to:e}),s+=e-a),{total:s,ranges:r}}function Cd({total:t,ranges:e},n){if(n<=0)return e[0].from;if(n>=1)return e[e.length-1].to;let r=Math.floor(t*n);for(let a=0;;a++){let{from:s,to:i}=e[a],o=i-s;if(r<=o)return s+r;r-=o}}function Id(t,e){let n=0;for(let{from:r,to:a}of t.ranges){if(e<=a){n+=e-r;break}n+=a-r}return n/t.total}function sD(t,e){for(let n of t)if(e(n))return n}var Ok={toDOM(t){return t},fromDOM(t){return t},scale:1,eq(t){return t==this}};function Bk(t){let e=t.facet(qd).filter(r=>typeof r!="function"),n=t.facet(Wm).filter(r=>typeof r!="function");return n.length&&e.push(wt.join(n)),e}var Cm=class t{constructor(e,n,r){let a=0,s=0,i=0;this.viewports=r.map(({from:o,to:l})=>{let u=n.lineAt(o,jt.ByPos,e,0,0).top,c=n.lineAt(l,jt.ByPos,e,0,0).bottom;return a+=c-u,{from:o,to:l,top:u,bottom:c,domTop:0,domBottom:0}}),this.scale=(7e6-a)/(n.height-a);for(let o of this.viewports)o.domTop=i+(o.top-s)*this.scale,i=o.domBottom=o.domTop+(o.bottom-o.top),s=o.bottom}toDOM(e){for(let n=0,r=0,a=0;;n++){let s=n<this.viewports.length?this.viewports[n]:null;if(!s||e<s.top)return a+(e-r)*this.scale;if(e<=s.bottom)return s.domTop+(e-s.top);r=s.bottom,a=s.domBottom}}fromDOM(e){for(let n=0,r=0,a=0;;n++){let s=n<this.viewports.length?this.viewports[n]:null;if(!s||e<s.domTop)return r+(e-a)/this.scale;if(e<=s.domBottom)return s.top+(e-s.domTop);r=s.bottom,a=s.domBottom}}eq(e){return e instanceof t?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((n,r)=>n.from==e.viewports[r].from&&n.to==e.viewports[r].to):!1}};function pu(t,e){if(e.scale==1)return t;let n=e.toDOM(t.top),r=e.toDOM(t.bottom);return new ia(t.from,t.length,n,r-n,Array.isArray(t._content)?t._content.map(a=>pu(a,e)):t._content)}var Ld=Me.define({combine:t=>t.join(" ")}),Im=Me.define({combine:t=>t.indexOf(!0)>-1}),Lm=dr.newName(),BS=dr.newName(),_S=dr.newName(),HS={"&light":"."+BS,"&dark":"."+_S};function Am(t,e,n){return new dr(e,{finish(r){return/&/.test(r)?r.replace(/&\w*/,a=>{if(a=="&")return t;if(!n||!n[a])throw new RangeError(`Unsupported selector: ${a}`);return n[a]}):t+" "+r}})}var iD=Am("."+Lm,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{userSelect:"none",position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},".cm-panels-top":{top:"0"},".cm-panels-bottom":{bottom:"0"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{background:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 0) no-repeat",backgroundSize:".4em",backgroundPosition:"calc(min(50%, 0px)) center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},HS),oD={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},jp=ke.ie&&ke.ie_version<=11,Pm=class{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new Jp,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(n=>{for(let r of n)this.queue.push(r);(ke.ie&&ke.ie_version<=11||ke.ios&&e.composing)&&n.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&ke.android&&e.constructor.EDIT_CONTEXT!==!1&&!(ke.chrome&&ke.chrome_version<126)&&(this.editContext=new Nm(e),e.state.facet(ss)&&(e.contentDOM.editContext=this.editContext.editContext)),jp&&(this.onCharData=n=>{this.queue.push({target:n.target,type:"characterData",oldValue:n.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var n;((n=this.view.docView)===null||n===void 0?void 0:n.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(n=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),n.length>0&&n[n.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(n=>{n.length>0&&n[n.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type=="change"||!e.type)&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((n,r)=>n!=e[r]))){this.gapIntersection.disconnect();for(let n of e)this.gapIntersection.observe(n);this.gaps=e}}onSelectionChange(e){let n=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:r}=this,a=this.selectionRange;if(r.state.facet(ss)?r.root.activeElement!=this.dom:!mu(this.dom,a))return;let s=a.anchorNode&&r.docView.tile.nearest(a.anchorNode);if(s&&s.isWidget()&&s.widget.ignoreEvent(e)){n||(this.selectionChanged=!1);return}(ke.ie&&ke.ie_version<=11||ke.android&&ke.chrome)&&!r.state.selection.main.empty&&a.focusNode&&xu(a.focusNode,a.focusOffset,a.anchorNode,a.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,n=Au(e.root);if(!n)return!1;let r=ke.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&lD(this.view,n)||n;if(!r||this.selectionRange.eq(r))return!1;let a=mu(this.dom,r);return a&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&nT(this.dom,r)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(r),a&&(this.selectionChanged=!0),!0)}setSelectionRange(e,n){this.selectionRange.set(e.node,e.offset,n.node,n.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,n=null;for(let r=this.dom;r;)if(r.nodeType==1)!n&&e<this.scrollTargets.length&&this.scrollTargets[e]==r?e++:n||(n=this.scrollTargets.slice(0,e)),n&&n.push(r),r=r.assignedSlot||r.parentNode;else if(r.nodeType==11)r=r.host;else break;if(e<this.scrollTargets.length&&!n&&(n=this.scrollTargets.slice(0,e)),n){for(let r of this.scrollTargets)r.removeEventListener("scroll",this.onScroll);for(let r of this.scrollTargets=n)r.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,oD),jp&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),jp&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,n){var r;if(!this.delayedAndroidKey){let a=()=>{let s=this.delayedAndroidKey;s&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=s.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&s.force&&Oo(this.dom,s.key,s.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(a)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:n,force:this.lastChange<Date.now()-50||!!(!((r=this.delayedAndroidKey)===null||r===void 0)&&r.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let n=-1,r=-1,a=!1;for(let s of e){let i=this.readMutation(s);i&&(i.typeOver&&(a=!0),n==-1?{from:n,to:r}=i:(n=Math.min(i.from,n),r=Math.max(i.to,r)))}return{from:n,to:r,typeOver:a}}readChange(){let{from:e,to:n,typeOver:r}=this.processRecords(),a=this.selectionChanged&&mu(this.dom,this.selectionRange);if(e<0&&!a)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let s=new pm(this.view,e,n,r);return this.view.docView.domChanged={newSel:s.newSel?s.newSel.main:null},s}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let n=this.readChange();if(!n)return this.view.requestMeasure(),!1;let r=this.view.state,a=AS(this.view,n);return this.view.state==r&&(n.domChanged||n.newSel&&!_d(this.view.state.selection,n.newSel.main))&&this.view.update([]),a}readMutation(e){let n=this.view.docView.tile.nearest(e.target);if(!n||n.isWidget())return null;if(n.markDirty(e.type=="attributes"),e.type=="childList"){let r=_k(n,e.previousSibling||e.target.previousSibling,-1),a=_k(n,e.nextSibling||e.target.nextSibling,1);return{from:r?n.posAfter(r):n.posAtStart,to:a?n.posBefore(a):n.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(ss)!=e.state.facet(ss)&&(e.view.contentDOM.editContext=e.state.facet(ss)?this.editContext.editContext:null))}destroy(){var e,n,r;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(n=this.gapIntersection)===null||n===void 0||n.disconnect(),(r=this.resizeScroll)===null||r===void 0||r.disconnect();for(let a of this.scrollTargets)a.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}};function _k(t,e,n){for(;e;){let r=Yt.get(e);if(r&&r.parent==t)return r;let a=e.parentNode;e=a!=t.dom?a:n>0?e.nextSibling:e.previousSibling}return null}function Hk(t,e){let n=e.startContainer,r=e.startOffset,a=e.endContainer,s=e.endOffset,i=t.docView.domAtPos(t.state.selection.main.anchor,1);return xu(i.node,i.offset,a,s)&&([n,r,a,s]=[a,s,n,r]),{anchorNode:n,anchorOffset:r,focusNode:a,focusOffset:s}}function lD(t,e){if(e.getComposedRanges){let a=e.getComposedRanges(t.root)[0];if(a)return Hk(t,a)}let n=null;function r(a){a.preventDefault(),a.stopImmediatePropagation(),n=a.getTargetRanges()[0]}return t.contentDOM.addEventListener("beforeinput",r,!0),t.dom.ownerDocument.execCommand("indent"),t.contentDOM.removeEventListener("beforeinput",r,!0),n?Hk(t,n):null}var Nm=class{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let n=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=r=>{let a=e.state.selection.main,{anchor:s,head:i}=a,o=this.toEditorPos(r.updateRangeStart),l=this.toEditorPos(r.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:r.updateRangeStart,editorBase:o,drifted:!1});let u=l-o>r.text.length;o==this.from&&s<this.from?o=s:l==this.to&&s>this.to&&(l=s);let c=PS(e.state.sliceDoc(o,l),r.text,(u?a.from:a.to)-o,u?"end":null);if(!c){let f=se.single(this.toEditorPos(r.selectionStart),this.toEditorPos(r.selectionEnd));_d(f,a)||e.dispatch({selection:f,userEvent:"select"});return}let d={from:c.from+o,to:c.toA+o,insert:st.of(r.text.slice(c.from,c.toB).split(`
|
|
41
|
-
`))};if((ke.mac||ke.android)&&d.from==i-1&&/^\. ?$/.test(r.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(d={from:o,to:l,insert:st.of([r.text.replace("."," ")])}),this.pendingContextChange=d,!e.state.readOnly){let f=this.to-this.from+(d.to-d.from+d.insert.length);zm(e,d,se.single(this.toEditorPos(r.selectionStart,f),this.toEditorPos(r.selectionEnd,f)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),d.from<d.to&&!d.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(n.text.slice(Math.max(0,r.updateRangeStart-1),Math.min(n.text.length,r.updateRangeStart+1)))&&this.handlers.compositionend(r)},this.handlers.characterboundsupdate=r=>{let a=[],s=null;for(let i=this.toEditorPos(r.rangeStart),o=this.toEditorPos(r.rangeEnd);i<o;i++){let l=e.coordsForChar(i);s=l&&new DOMRect(l.left,l.top,l.right-l.left,l.bottom-l.top)||s||new DOMRect,a.push(s)}n.updateCharacterBounds(r.rangeStart,a)},this.handlers.textformatupdate=r=>{let a=[];for(let s of r.getTextFormats()){let i=s.underlineStyle,o=s.underlineThickness;if(!/none/i.test(i)&&!/none/i.test(o)){let l=this.toEditorPos(s.rangeStart),u=this.toEditorPos(s.rangeEnd);if(l<u){let c=`text-decoration: underline ${/^[a-z]/.test(i)?i+" ":i=="Dashed"?"dashed ":i=="Squiggle"?"wavy ":""}${/thin/i.test(o)?1:2}px`;a.push(Ke.mark({attributes:{style:c}}).range(l,u))}}}e.dispatch({effects:xS.of(Ke.set(a))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:r}=this.composing;this.composing=null,r&&this.reset(e.state)}};for(let r in this.handlers)n.addEventListener(r,this.handlers[r]);this.measureReq={read:r=>{let a=Au(r.root);a&&a.rangeCount&&this.editContext.updateSelectionBounds(a.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let n=0,r=!1,a=this.pendingContextChange;return e.changes.iterChanges((s,i,o,l,u)=>{if(r)return;let c=u.length-(i-s);if(a&&i>=a.to)if(a.from==s&&a.to==i&&a.insert.eq(u)){a=this.pendingContextChange=null,n+=c,this.to+=c;return}else a=null,this.revertPending(e.state);if(s+=n,i+=n,i<=this.from)this.from+=c,this.to+=c;else if(s<this.to){if(s<this.from||i>this.to||this.to-this.from+u.length>3e4){r=!0;return}this.editContext.updateText(this.toContextPos(s),this.toContextPos(i),u.toString()),this.to+=c}n+=c}),a&&!r&&this.revertPending(e.state),!r}update(e){let n=this.pendingContextChange,r=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(r.from,r.to)&&e.transactions.some(a=>!a.isUserEvent("input.type")&&a.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||n)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:n}=e.selection.main;this.from=Math.max(0,n-1e4),this.to=Math.min(e.doc.length,n+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let n=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(n.from),this.toContextPos(n.from+n.insert.length),e.doc.sliceString(n.from,n.to))}setSelection(e){let{main:n}=e.selection,r=this.toContextPos(Math.max(this.from,Math.min(this.to,n.anchor))),a=this.toContextPos(n.head);(this.editContext.selectionStart!=r||this.editContext.selectionEnd!=a)&&this.editContext.updateSelection(r,a)}rangeIsValid(e){let{head:n}=e.selection.main;return!(this.from>0&&n-this.from<500||this.to<e.doc.length&&this.to-n<500||this.to-this.from>1e4*3)}toEditorPos(e,n=this.to-this.from){e=Math.min(e,n);let r=this.composing;return r&&r.drifted?r.editorBase+(e-r.contextBase):e+this.from}toContextPos(e){let n=this.composing;return n&&n.drifted?n.contextBase+(e-n.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}},Pe=class t{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){var n;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.clearAnnouncement=-1,this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:r}=e;this.dispatchTransactions=e.dispatchTransactions||r&&(a=>a.forEach(s=>r(s,this)))||(a=>this.update(a)),this.dispatch=this.dispatch.bind(this),this._root=e.root||tT(e.parent)||document,this.viewState=new Gd(this,e.state||It.create(e)),e.scrollTo&&e.scrollTo.is(vd)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(To).map(a=>new bu(a));for(let a of this.plugins)a.update(this);this.observer=new Pm(this),this.inputState=new mm(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Od(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((n=document.fonts)===null||n===void 0)&&n.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...e){let n=e.length==1&&e[0]instanceof An?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(n,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let n=!1,r=!1,a,s=this.state;for(let f of e){if(f.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=f.state}if(this.destroyed){this.viewState.state=s;return}let i=this.hasFocus,o=0,l=null;e.some(f=>f.annotation(FS))?(this.inputState.notifiedFocused=i,o=1):i!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=i,l=ES(s,i),l||(o=1));let u=this.observer.delayedAndroidKey,c=null;if(u?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(c=null)):this.observer.clear(),s.facet(It.phrases)!=this.state.facet(It.phrases))return this.setState(s);a=Fd.create(this,s,e),a.flags|=o;let d=this.viewState.scrollTarget;try{this.updateState=2;for(let f of e){if(d&&(d=d.map(f.changes)),f.scrollIntoView){let{main:h}=f.state.selection,{x:p,y:g}=this.state.facet(t.cursorScrollMargin);d=new yu(h.empty?h:se.cursor(h.head,h.head>h.anchor?-1:1),"nearest","nearest",g,p)}for(let h of f.effects)h.is(vd)&&(d=h.value.clip(this.state))}this.viewState.update(a,d),this.bidiCache=Wd.update(this.bidiCache,a.changes),a.empty||(this.updatePlugins(a),this.inputState.update(a)),n=this.docView.update(a),this.state.facet(hu)!=this.styleModules&&this.mountStyles(),r=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(n,e.some(f=>f.isUserEvent("select.pointer")))}finally{this.updateState=0}if(a.startState.facet(Ld)!=a.state.facet(Ld)&&(this.viewState.mustMeasureContent=!0),(n||r||d||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),n&&this.docViewUpdate(),!a.empty)for(let f of this.state.facet(tm))try{f(a)}catch(h){oa(this.state,h,"update listener")}(l||c)&&Promise.resolve().then(()=>{l&&this.state==l.startState&&this.dispatch(l),c&&!AS(this,c)&&u.force&&Oo(this.contentDOM,u.key,u.keyCode)})}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let n=this.hasFocus;try{for(let r of this.plugins)r.destroy(this);this.viewState=new Gd(this,e),this.plugins=e.facet(To).map(r=>new bu(r)),this.pluginMap.clear();for(let r of this.plugins)r.update(this);this.docView.destroy(),this.docView=new Od(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}n&&this.focus(),this.requestMeasure()}updatePlugins(e){let n=e.startState.facet(To),r=e.state.facet(To);if(n!=r){let a=[];for(let s of r){let i=n.indexOf(s);if(i<0)a.push(new bu(s));else{let o=this.plugins[i];o.mustUpdate=e,a.push(o)}}for(let s of this.plugins)s.mustUpdate!=e&&s.destroy(this);this.plugins=a,this.pluginMap.clear()}else for(let a of this.plugins)a.mustUpdate=e;for(let a=0;a<this.plugins.length;a++)this.plugins[a].update(this);n!=r&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let n=e.value;if(n&&n.docViewUpdate)try{n.docViewUpdate(this)}catch(r){oa(this.state,r,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let n=null,r=this.viewState.scrollParent,a=this.viewState.getScrollOffset(),{scrollAnchorPos:s,scrollAnchorHeight:i,scaleY:o}=this.viewState;Math.abs(a-this.viewState.scrollOffset)>1&&(i=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(i<0){if(eS(r||this.win))s=-1,i=this.viewState.heightMap.height/this.viewState.scaleY;else{let p=this.viewState.scrollAnchorAt(a);s=p.from,i=p.top}o=this.viewState.scaleY}this.updateState=1;let u=this.viewState.measure();if(!u&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let c=[];u&4||([this.measureRequests,c]=[c,this.measureRequests]);let d=c.map(p=>{try{return p.read(this)}catch(g){return oa(this.state,g),Uk}}),f=Fd.create(this,this.state,[]),h=!1;f.flags|=u,n?n.flags|=u:n=f,this.updateState=2,f.empty||(this.updatePlugins(f),this.inputState.update(f),this.updateAttrs(),h=this.docView.update(f),h&&this.docViewUpdate());for(let p=0;p<c.length;p++)if(d[p]!=Uk)try{let g=c[p];g.write&&g.write(d[p],this)}catch(g){oa(this.state,g)}if(h&&this.docView.updateSelection(!0),!f.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,i=-1;continue}else{let g=(s<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(s).top)/this.viewState.scaleY-i/o;if((g>1||g<-1)&&!(ke.ios&&this.inputState.lastIOSMomentumScroll>Date.now()-100)&&(r==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){a=a+g,r?s<0?r.scrollTop=r.scrollHeight:r.scrollTop+=g:this.win.scrollBy(0,g),i=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(n&&!n.empty)for(let l of this.state.facet(tm))l(n)}get themeClasses(){return Lm+" "+(this.state.facet(Im)?_S:BS)+" "+this.state.facet(Ld)}updateAttrs(){let e=Gk(this,yS,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),n={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(ss)?"true":"false",class:"cm-content",style:`${ke.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(n["aria-readonly"]="true"),Gk(this,Gm,n);let r=this.observer.ignore(()=>{let a=bk(this.contentDOM,this.contentAttrs,n),s=bk(this.dom,this.editorAttrs,e);return a||s});return this.editorAttrs=e,this.contentAttrs=n,r}showAnnouncements(e){let n=!0;for(let r of e)for(let a of r.effects)if(a.is(t.announce)){n&&(this.announceDOM.textContent="",this.win.clearTimeout(this.clearAnnouncement),this.clearAnnouncement=this.win.setTimeout(()=>{this.announceDOM.textContent="\xA0"},200),n=!1);let s=this.announceDOM.appendChild(document.createElement("div"));s.textContent=a.value}}mountStyles(){this.styleModules=this.state.facet(hu);let e=this.state.facet(t.cspNonce);dr.mount(this.root,this.styleModules.concat(iD).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let n=0;n<this.measureRequests.length;n++)if(this.measureRequests[n].key===e.key){this.measureRequests[n]=e;return}}this.measureRequests.push(e)}}plugin(e){let n=this.pluginMap.get(e);return(n===void 0||n&&n.plugin!=e)&&this.pluginMap.set(e,n=this.plugins.find(r=>r.plugin==e)||null),n&&n.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,n,r){return zp(this,e,Ik(this,e,n,r))}moveByGroup(e,n){return zp(this,e,Ik(this,e,n,r=>RT(this,e.head,r)))}visualLineSide(e,n){return n?se.cursor(e.to,1):se.cursor(e.from,-1)}moveToLineBoundary(e,n,r=!0){return NT(this,e,n,r)}moveVertically(e,n,r){return zp(this,e,MT(this,e,n,r))}domAtPos(e,n=1){return this.docView.domAtPos(e,n)}posAtDOM(e,n=0){return this.docView.posFromDOM(e,n)}posAtCoords(e,n=!0){this.readMeasured();let r=dm(this,e,n);return r&&r.pos}posAndSideAtCoords(e,n=!0){return this.readMeasured(),dm(this,e,n)}coordsAtPos(e,n=1){this.readMeasured();let r=this.state.doc.lineAt(e),a=this.bidiSpans(r),s=a[Wr.find(a,e-r.from,-1,n)];return r.length&&(e==r.from&&n<0||e==r.to&&n>0)&&s.dir!=this.textDirectionAt(r.from)&&(e==r.to?(e=r.from+s.from,n=1):(e=r.from+s.to,n=-1)),this.docView.coordsAt(e,n,s.dir==Vt.RTL)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(pS)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>uD)return iS(e.length);let n=this.textDirectionAt(e.from),r;for(let s of this.bidiCache)if(s.from==e.from&&s.dir==n&&(s.fresh||sS(s.isolates,r=kk(this,e))))return s.order;r||(r=kk(this,e));let a=uT(e.text,n,r);return this.bidiCache.push(new Wd(e.from,e.to,n,r,!0,a)),a}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||ke.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Qk(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.win.clearTimeout(this.clearAnnouncement),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,n={}){var r,a,s,i;return vd.of(new yu(typeof e=="number"?se.cursor(e):e,(r=n.y)!==null&&r!==void 0?r:"nearest",(a=n.x)!==null&&a!==void 0?a:"nearest",(s=n.yMargin)!==null&&s!==void 0?s:5,(i=n.xMargin)!==null&&i!==void 0?i:5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:n}=this.scrollDOM,r=this.viewState.scrollAnchorAt(e);return vd.of(new yu(se.cursor(r.from),"start","start",r.top-e,n,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return hr.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return hr.define(()=>({}),{eventObservers:e})}static theme(e,n){let r=dr.newName(),a=[Ld.of(r),hu.of(Am(`.${r}`,e))];return n&&n.dark&&a.push(Im.of(!0)),a}static baseTheme(e){return Ma.lowest(hu.of(Am("."+Lm,e,HS)))}static findFromDOM(e){var n;let r=e.querySelector(".cm-content"),a=r&&Yt.get(r)||Yt.get(e);return((n=a?.root)===null||n===void 0?void 0:n.view)||null}};Pe.styleModule=hu;Pe.inputHandler=fS;Pe.clipboardInputFilter=Hm;Pe.clipboardOutputFilter=Um;Pe.scrollHandler=gS;Pe.focusChangeEffect=hS;Pe.perLineTextDirection=pS;Pe.exceptionSink=dS;Pe.updateListener=tm;Pe.editable=ss;Pe.mouseSelectionStyle=cS;Pe.dragMovesSelection=uS;Pe.clickAddsSelectionRange=lS;Pe.decorations=qd;Pe.blockWrappers=bS;Pe.outerDecorations=Wm;Pe.atomicRanges=Ru;Pe.bidiIsolatedRanges=wS;Pe.cursorScrollMargin=Me.define({combine:t=>{let e=5,n=5;for(let r of t)typeof r=="number"?e=n=r:{x:e,y:n}=r;return{x:e,y:n}}});Pe.scrollMargins=vS;Pe.darkTheme=Im;Pe.cspNonce=Me.define({combine:t=>t.length?t[0]:""});Pe.contentAttributes=Gm;Pe.editorAttributes=yS;Pe.lineWrapping=Pe.contentAttributes.of({class:"cm-lineWrapping"});Pe.announce=pt.define();var uD=4096,Uk={},Wd=class t{constructor(e,n,r,a,s,i){this.from=e,this.to=n,this.dir=r,this.isolates=a,this.fresh=s,this.order=i}static update(e,n){if(n.empty&&!e.some(s=>s.fresh))return e;let r=[],a=e.length?e[e.length-1].dir:Vt.LTR;for(let s=Math.max(0,e.length-10);s<e.length;s++){let i=e[s];i.dir==a&&!n.touchesRange(i.from,i.to)&&r.push(new t(n.mapPos(i.from,1),n.mapPos(i.to,-1),i.dir,i.isolates,!1,i.order))}return r}};function Gk(t,e,n){for(let r=t.state.facet(e),a=r.length-1;a>=0;a--){let s=r[a],i=typeof s=="function"?s(t):s;i&&Om(i,n)}return n}var cD=ke.mac?"mac":ke.windows?"win":ke.linux?"linux":"key";function dD(t,e){let n=t.split(/-(?!$)/),r=n[n.length-1];r=="Space"&&(r=" ");let a,s,i,o;for(let l=0;l<n.length-1;++l){let u=n[l];if(/^(cmd|meta|m)$/i.test(u))o=!0;else if(/^a(lt)?$/i.test(u))a=!0;else if(/^(c|ctrl|control)$/i.test(u))s=!0;else if(/^s(hift)?$/i.test(u))i=!0;else if(/^mod$/i.test(u))e=="mac"?o=!0:s=!0;else throw new Error("Unrecognized modifier name: "+u)}return a&&(r="Alt-"+r),s&&(r="Ctrl-"+r),o&&(r="Meta-"+r),i&&(r="Shift-"+r),r}function Ad(t,e,n){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),n!==!1&&e.shiftKey&&(t="Shift-"+t),t}var fD=Ma.default(Pe.domEventHandlers({keydown(t,e){return gD(hD(e.state),t,e,"editor")}})),jm=Me.define({enables:fD}),Wk=new WeakMap;function hD(t){let e=t.facet(jm),n=Wk.get(e);return n||Wk.set(e,n=mD(e.reduce((r,a)=>r.concat(a),[]))),n}var Us=null,pD=4e3;function mD(t,e=cD){let n=Object.create(null),r=Object.create(null),a=(i,o)=>{let l=r[i];if(l==null)r[i]=o;else if(l!=o)throw new Error("Key binding "+i+" is used both as a regular binding and as a multi-stroke prefix")},s=(i,o,l,u,c)=>{var d,f;let h=n[i]||(n[i]=Object.create(null)),p=o.split(/ (?!$)/).map(x=>dD(x,e));for(let x=1;x<p.length;x++){let y=p.slice(0,x).join(" ");a(y,!0),h[y]||(h[y]={preventDefault:!0,stopPropagation:!1,run:[b=>{let C=Us={view:b,prefix:y,scope:i};return setTimeout(()=>{Us==C&&(Us=null)},pD),!0}]})}let g=p.join(" ");a(g,!1);let m=h[g]||(h[g]={preventDefault:!1,stopPropagation:!1,run:((f=(d=h._any)===null||d===void 0?void 0:d.run)===null||f===void 0?void 0:f.slice())||[]});l&&m.run.push(l),u&&(m.preventDefault=!0),c&&(m.stopPropagation=!0)};for(let i of t){let o=i.scope?i.scope.split(" "):["editor"];if(i.any)for(let u of o){let c=n[u]||(n[u]=Object.create(null));c._any||(c._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:d}=i;for(let f in c)c[f].run.push(h=>d(h,Rm))}let l=i[e]||i.key;if(l)for(let u of o)s(u,l,i.run,i.preventDefault,i.stopPropagation),i.shift&&s(u,"Shift-"+l,i.shift,i.preventDefault,i.stopPropagation)}return n}var Rm=null;function gD(t,e,n,r){Rm=e;let a=mk(e),s=Q1(a,0),i=ek(s)==a.length&&a!=" ",o="",l=!1,u=!1,c=!1;Us&&Us.view==n&&Us.scope==r&&(o=Us.prefix+" ",RS.indexOf(e.keyCode)<0&&(u=!0,Us=null));let d=new Set,f=m=>{if(m){for(let x of m.run)if(!d.has(x)&&(d.add(x),x(n)))return m.stopPropagation&&(c=!0),!0;m.preventDefault&&(m.stopPropagation&&(c=!0),u=!0)}return!1},h=t[r],p,g;return h&&(f(h[o+Ad(a,e,!i)])?l=!0:i&&(e.altKey||e.metaKey||e.ctrlKey)&&!(ke.windows&&e.ctrlKey&&e.altKey)&&!(ke.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(p=as[e.keyCode])&&p!=a?(f(h[o+Ad(p,e,!0)])||e.shiftKey&&(g=Ro[e.keyCode])!=a&&g!=p&&f(h[o+Ad(g,e,!1)]))&&(l=!0):i&&e.shiftKey&&f(h[o+Ad(a,e,!0)])&&(l=!0),!l&&f(h._any)&&(l=!0)),u&&(l=!0),l&&c&&e.stopPropagation(),Rm=null,l}var Ni=class t{constructor(e,n,r,a,s){this.className=e,this.left=n,this.top=r,this.width=a,this.height=s}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,n){return n.className!=this.className?!1:(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width!=null&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,n,r){if(r.empty){let a=e.coordsAtPos(r.head,r.assoc||1);if(!a)return[];let s=US(e);return[new t(n,a.left-s.left,a.top-s.top,null,a.bottom-a.top)]}else return xD(e,n,r)}};function US(t){let e=t.scrollDOM.getBoundingClientRect();return{left:(t.textDirection==Vt.LTR?e.left:e.right-t.scrollDOM.clientWidth*t.scaleX)-t.scrollDOM.scrollLeft*t.scaleX,top:e.top-t.scrollDOM.scrollTop*t.scaleY}}function zk(t,e,n,r){let a=t.coordsAtPos(e,n*2);if(!a)return r;let s=t.dom.getBoundingClientRect(),i=(a.top+a.bottom)/2,o=t.posAtCoords({x:s.left+1,y:i}),l=t.posAtCoords({x:s.right-1,y:i});return o==null||l==null?r:{from:Math.max(r.from,Math.min(o,l)),to:Math.min(r.to,Math.max(o,l))}}function xD(t,e,n){if(n.to<=t.viewport.from||n.from>=t.viewport.to)return[];let r=Math.max(n.from,t.viewport.from),a=Math.min(n.to,t.viewport.to),s=t.textDirection==Vt.LTR,i=t.contentDOM,o=i.getBoundingClientRect(),l=US(t),u=i.querySelector(".cm-line"),c=u&&window.getComputedStyle(u),d=o.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),f=o.right-(c?parseInt(c.paddingRight):0),h=cm(t,r,1),p=cm(t,a,-1),g=h.type==On.Text?h:null,m=p.type==On.Text?p:null;if(g&&(t.lineWrapping||h.widgetLineBreaks)&&(g=zk(t,r,1,g)),m&&(t.lineWrapping||p.widgetLineBreaks)&&(m=zk(t,a,-1,m)),g&&m&&g.from==m.from&&g.to==m.to)return y(b(n.from,n.to,g));{let L=g?b(n.from,null,g):C(h,!1),P=m?b(null,n.to,m):C(p,!0),w=[];return(g||h).to<(m||p).from-(g&&m?1:0)||h.widgetLineBreaks>1&&L.bottom+t.defaultLineHeight/2<P.top?w.push(x(d,L.bottom,f,P.top)):L.bottom<P.top&&t.elementAtHeight((L.bottom+P.top)/2).type==On.Text&&(L.bottom=P.top=(L.bottom+P.top)/2),y(L).concat(w).concat(y(P))}function x(L,P,w,k){return new Ni(e,L-l.left,P-l.top,Math.max(0,w-L),k-P)}function y({top:L,bottom:P,horizontal:w}){let k=[];for(let _=0;_<w.length;_+=2)k.push(x(w[_],L,w[_+1],P));return k}function b(L,P,w){let k=1e9,_=-1e9,M=[];function R(T,V,Y,N,A){let B=t.coordsAtPos(T,T==w.to?-2:2),K=t.coordsAtPos(Y,Y==w.from?2:-2);!B||!K||(k=Math.min(B.top,K.top,k),_=Math.max(B.bottom,K.bottom,_),A==Vt.LTR?M.push(s&&V?d:B.left,s&&N?f:K.right):M.push(!s&&N?d:K.left,!s&&V?f:B.right))}let U=L??w.from,v=P??w.to;for(let T of t.visibleRanges)if(T.to>U&&T.from<v)for(let V=Math.max(T.from,U),Y=Math.min(T.to,v);;){let N=t.state.doc.lineAt(V);for(let A of t.bidiSpans(N)){let B=A.from+N.from,K=A.to+N.from;if(B>=Y)break;K>V&&R(Math.max(B,V),L==null&&B<=U,Math.min(K,Y),P==null&&K>=v,A.dir)}if(V=N.to+1,V>=Y)break}return M.length==0&&R(U,L==null,v,P==null,t.textDirection),{top:k,bottom:_,horizontal:M}}function C(L,P){let w=o.top+(P?L.top:L.bottom);return{top:w,bottom:w,horizontal:[]}}}function yD(t,e){return t.constructor==e.constructor&&t.eq(e)}var Mm=class{constructor(e,n){this.view=e,this.layer=n,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),n.above&&this.dom.classList.add("cm-layer-above"),n.class&&this.dom.classList.add(n.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),n.mount&&n.mount(this.dom,e)}update(e){e.startState.facet(Nd)!=e.state.facet(Nd)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){this.layer.updateOnDocViewUpdate!==!1&&e.requestMeasure(this.measureReq)}setOrder(e){let n=0,r=e.facet(Nd);for(;n<r.length&&r[n]!=this.layer;)n++;this.dom.style.zIndex=String((this.layer.above?150:-1)-n)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:e,scaleY:n}=this.view;(e!=this.scaleX||n!=this.scaleY)&&(this.scaleX=e,this.scaleY=n,this.dom.style.transform=`scale(${1/e}, ${1/n})`)}draw(e){if(e.length!=this.drawn.length||e.some((n,r)=>!yD(n,this.drawn[r]))){let n=this.dom.firstChild,r=0;for(let a of e)a.update&&n&&a.constructor&&this.drawn[r].constructor&&a.update(n,this.drawn[r])?(n=n.nextSibling,r++):this.dom.insertBefore(a.draw(),n);for(;n;){let a=n.nextSibling;n.remove(),n=a}this.drawn=e,ke.webkit&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}},Nd=Me.define();function GS(t){return[hr.define(e=>new Mm(e,t)),Nd.of(t)]}var Wo=Me.define({combine(t){return No(t,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(e,n)=>Math.min(e,n),drawRangeCursor:(e,n)=>e||n})}});function WS(t={}){return[Wo.of(t),bD,wD,kD,mS.of(!0)]}function zS(t){return t.startState.facet(Wo)!=t.state.facet(Wo)}var bD=GS({above:!0,markers(t){let{state:e}=t,n=e.facet(Wo),r=[];for(let a of e.selection.ranges){let s=a==e.selection.main;if(a.empty||n.drawRangeCursor&&!(s&&ke.ios&&n.iosSelectionHandles)){let i=s?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",o=a.empty?a:se.cursor(a.head,a.assoc);for(let l of Ni.forRange(t,i,o))r.push(l)}}return r},update(t,e){t.transactions.some(r=>r.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let n=zS(t);return n&&jk(t.state,e),t.docChanged||t.selectionSet||n},mount(t,e){jk(e.state,t)},class:"cm-cursorLayer"});function jk(t,e){e.style.animationDuration=t.facet(Wo).cursorBlinkRate+"ms"}var wD=GS({above:!1,markers(t){let e=[],{main:n,ranges:r}=t.state.selection;for(let a of r)if(!a.empty)for(let s of Ni.forRange(t,"cm-selectionBackground",a))e.push(s);if(ke.ios&&!n.empty&&t.state.facet(Wo).iosSelectionHandles){for(let a of Ni.forRange(t,"cm-selectionHandle cm-selectionHandle-start",se.cursor(n.from,1)))e.push(a);for(let a of Ni.forRange(t,"cm-selectionHandle cm-selectionHandle-end",se.cursor(n.to,1)))e.push(a)}return e},update(t,e){return t.docChanged||t.selectionSet||t.viewportChanged||zS(t)},class:"cm-selectionLayer"}),vD=ke.gecko&&ke.gecko_version==153?"#ffffff01":"transparent",kD=Ma.highest(Pe.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:`${vD} !important`},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}}));var Kj=/x/.unicode!=null?"gu":"g";function jS(){return CD}var SD=Ke.line({class:"cm-activeLine"}),CD=hr.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.docChanged||t.selectionSet)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=-1,n=[];for(let r of t.state.selection.ranges){let a=t.lineBlockAt(r.head);a.from>e&&(n.push(SD.range(a.from)),e=a.from)}return Ke.set(n)}},{decorations:t=>t.decorations}),Tm=class extends Ir{constructor(e){super(),this.content=e}toDOM(e){let n=document.createElement("span");return n.className="cm-placeholder",n.style.pointerEvents="none",n.appendChild(typeof this.content=="string"?document.createTextNode(this.content):typeof this.content=="function"?this.content(e):this.content.cloneNode(!0)),n.setAttribute("aria-hidden","true"),n}coordsAt(e){let n=e.firstChild?gu(e.firstChild):[];if(!n.length)return null;let r=window.getComputedStyle(e.parentNode),a=Pu(n[0],r.direction!="rtl"),s=parseInt(r.lineHeight);return a.bottom-a.top>s*1.5?{left:a.left,right:a.right,top:a.top,bottom:a.top+s}:a}ignoreEvent(){return!1}};function VS(t){let e=hr.fromClass(class{constructor(n){this.view=n,this.placeholder=t?Ke.set([Ke.widget({widget:new Tm(t),side:1}).range(0)]):Ke.none}get decorations(){return this.view.state.doc.length?Ke.none:this.placeholder}},{decorations:n=>n.decorations});return typeof t=="string"?[e,Pe.contentAttributes.of({"aria-placeholder":t})]:e}var Bn=class extends Ra{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}};Bn.prototype.elementClass="";Bn.prototype.toDOM=void 0;Bn.prototype.mapMode=cr.TrackBefore;Bn.prototype.startSide=Bn.prototype.endSide=-1;Bn.prototype.point=!0;var Rd=Me.define(),ID=Me.define(),LD={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>wt.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},Su=Me.define();function zo(t){return[qS(),Su.of({...LD,...t})]}var Dm=Me.define({combine:t=>t.some(e=>e)});function qS(t){let e=[AD];return t&&t.fixed===!1&&e.push(Dm.of(!0)),e}var AD=hr.fromClass(class{constructor(t){this.view=t,this.domAfter=null,this.prevViewport=t.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=t.state.facet(Su).map(e=>new zd(t,e)),this.fixed=!t.state.facet(Dm);for(let e of this.gutters)e.config.side=="after"?this.getDOMAfter().appendChild(e.dom):this.dom.appendChild(e.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),t.scrollDOM.insertBefore(this.dom,t.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(t){if(this.updateGutters(t)){let e=this.prevViewport,n=t.view.viewport,r=Math.min(e.to,n.to)-Math.max(e.from,n.from);this.syncGutters(r<(n.to-n.from)*.8)}if(t.geometryChanged){let e=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=e,this.domAfter&&(this.domAfter.style.minHeight=e)}this.view.state.facet(Dm)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=t.view.viewport}syncGutters(t){let e=this.dom.nextSibling;t&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let n=wt.iter(this.view.state.facet(Rd),this.view.viewport.from),r=[],a=this.gutters.map(s=>new Em(s,this.view.viewport,-this.view.documentPadding.top));for(let s of this.view.viewportLineBlocks)if(r.length&&(r=[]),Array.isArray(s.type)){let i=!0;for(let o of s.type)if(o.type==On.Text&&i){Fm(n,r,o.from);for(let l of a)l.line(this.view,o,r);i=!1}else if(o.widget)for(let l of a)l.widget(this.view,o)}else if(s.type==On.Text){Fm(n,r,s.from);for(let i of a)i.line(this.view,s,r)}else if(s.widget)for(let i of a)i.widget(this.view,s);for(let s of a)s.finish();t&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(t){let e=t.startState.facet(Su),n=t.state.facet(Su),r=t.docChanged||t.heightChanged||t.viewportChanged||!wt.eq(t.startState.facet(Rd),t.state.facet(Rd),t.view.viewport.from,t.view.viewport.to);if(e==n)for(let a of this.gutters)a.update(t)&&(r=!0);else{r=!0;let a=[];for(let s of n){let i=e.indexOf(s);i<0?a.push(new zd(this.view,s)):(this.gutters[i].update(t),a.push(this.gutters[i]))}for(let s of this.gutters)s.dom.remove(),a.indexOf(s)<0&&s.destroy();for(let s of a)s.config.side=="after"?this.getDOMAfter().appendChild(s.dom):this.dom.appendChild(s.dom);this.gutters=a}return r}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:t=>Pe.scrollMargins.of(e=>{let n=e.plugin(t);if(!n||n.gutters.length==0||!n.fixed)return null;let r=n.dom.offsetWidth*e.scaleX,a=n.domAfter?n.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==Vt.LTR?{left:r,right:a}:{right:r,left:a}})});function Vk(t){return Array.isArray(t)?t:[t]}function Fm(t,e,n){for(;t.value&&t.from<=n;)t.from==n&&e.push(t.value),t.next()}var Em=class{constructor(e,n,r){this.gutter=e,this.height=r,this.i=0,this.cursor=wt.iter(e.markers,n.from)}addElement(e,n,r){let{gutter:a}=this,s=(n.top-this.height)/e.scaleY,i=n.height/e.scaleY;if(this.i==a.elements.length){let o=new jd(e,i,s,r);a.elements.push(o),a.dom.appendChild(o.dom)}else a.elements[this.i].update(e,i,s,r);this.height=n.bottom,this.i++}line(e,n,r){let a=[];Fm(this.cursor,a,n.from),r.length&&(a=a.concat(r));let s=this.gutter.config.lineMarker(e,n,a);s&&a.unshift(s);let i=this.gutter;a.length==0&&!i.config.renderEmptyElements||this.addElement(e,n,a)}widget(e,n){let r=this.gutter.config.widgetMarker(e,n.widget,n),a=r?[r]:null;for(let s of e.state.facet(ID)){let i=s(e,n.widget,n);i&&(a||(a=[])).push(i)}a&&this.addElement(e,n,a)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let n=e.elements.pop();e.dom.removeChild(n.dom),n.destroy()}}},zd=class{constructor(e,n){this.view=e,this.config=n,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let r in n.domEventHandlers)this.dom.addEventListener(r,a=>{let s=a.target,i;if(s!=this.dom&&this.dom.contains(s)){for(;s.parentNode!=this.dom;)s=s.parentNode;let l=s.getBoundingClientRect();i=(l.top+l.bottom)/2}else i=a.clientY;let o=e.lineBlockAtHeight(i-e.documentTop);n.domEventHandlers[r](e,o,a)&&a.preventDefault()});this.markers=Vk(n.markers(e)),n.initialSpacer&&(this.spacer=new jd(e,0,0,[n.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let n=this.markers;if(this.markers=Vk(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let a=this.config.updateSpacer(this.spacer.markers[0],e);a!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[a])}let r=e.view.viewport;return!wt.eq(this.markers,n,r.from,r.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}},jd=class{constructor(e,n,r,a){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,n,r,a)}update(e,n,r,a){this.height!=n&&(this.height=n,this.dom.style.height=n+"px"),this.above!=r&&(this.dom.style.marginTop=(this.above=r)?r+"px":""),PD(this.markers,a)||this.setMarkers(e,a)}setMarkers(e,n){let r="cm-gutterElement",a=this.dom.firstChild;for(let s=0,i=0;;){let o=i,l=s<n.length?n[s++]:null,u=!1;if(l){let c=l.elementClass;c&&(r+=" "+c);for(let d=i;d<this.markers.length;d++)if(this.markers[d].compare(l)){o=d,u=!0;break}}else o=this.markers.length;for(;i<o;){let c=this.markers[i++];if(c.toDOM){c.destroy(a);let d=a.nextSibling;a.remove(),a=d}}if(!l)break;l.toDOM&&(u?a=a.nextSibling:this.dom.insertBefore(l.toDOM(e),a)),u&&i++}this.dom.className=r,this.markers=n}destroy(){this.setMarkers(null,[])}};function PD(t,e){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++)if(!t[n].compare(e[n]))return!1;return!0}var ND=Me.define(),RD=Me.define(),Fo=Me.define({combine(t){return No(t,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,n){let r=Object.assign({},e);for(let a in n){let s=r[a],i=n[a];r[a]=s?(o,l,u)=>s(o,l,u)||i(o,l,u):i}return r}})}}),Cu=class extends Bn{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}};function Vp(t,e){return t.state.facet(Fo).formatNumber(e,t.state)}var MD=Su.compute([Fo],t=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(ND)},lineMarker(e,n,r){return r.some(a=>a.toDOM)?null:new Cu(Vp(e,e.state.doc.lineAt(n.from).number))},widgetMarker:(e,n,r)=>{for(let a of e.state.facet(RD)){let s=a(e,n,r);if(s)return s}return null},lineMarkerChange:e=>e.startState.facet(Fo)!=e.state.facet(Fo),initialSpacer(e){return new Cu(Vp(e,qk(e.state.doc.lines)))},updateSpacer(e,n){let r=Vp(n.view,qk(n.view.state.doc.lines));return r==e.number?e:new Cu(r)},domEventHandlers:t.facet(Fo).domEventHandlers,side:"before"}));function Kd(t={}){return[Fo.of(t),qS(),MD]}function qk(t){let e=9;for(;e<t;)e=e*10+9;return e}var TD=new class extends Bn{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},DD=Rd.compute(["selection"],t=>{let e=[],n=-1;for(let r of t.selection.ranges){let a=t.doc.lineAt(r.head).from;a>n&&(n=a,e.push(TD.range(a)))}return wt.of(e)});function $S(){return DD}var FD=0,Mu=class{constructor(e,n){this.from=e,this.to=n}},rt=class{constructor(e={}){this.id=FD++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=Lr.match(e)),n=>{let r=e(n);return r===void 0?null:[this,r]}}};rt.closedBy=new rt({deserialize:t=>t.split(" ")});rt.openedBy=new rt({deserialize:t=>t.split(" ")});rt.group=new rt({deserialize:t=>t.split(" ")});rt.isolate=new rt({deserialize:t=>{if(t&&t!="rtl"&&t!="ltr"&&t!="auto")throw new RangeError("Invalid value for isolate: "+t);return t||"auto"}});rt.contextHash=new rt({perNode:!0});rt.lookAhead=new rt({perNode:!0});rt.mounted=new rt({perNode:!0});var Di=class{constructor(e,n,r,a=!1){this.tree=e,this.overlay=n,this.parser=r,this.bracketed=a}static get(e){return e&&e.props&&e.props[rt.mounted.id]}},ED=Object.create(null),Lr=class t{constructor(e,n,r,a=0){this.name=e,this.props=n,this.id=r,this.flags=a}static define(e){let n=e.props&&e.props.length?Object.create(null):ED,r=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),a=new t(e.name||"",n,e.id,r);if(e.props){for(let s of e.props)if(Array.isArray(s)||(s=s(a)),s){if(s[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");n[s[0].id]=s[1]}}return a}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let n=this.prop(rt.group);return n?n.indexOf(e)>-1:!1}return this.id==e}static match(e){let n=Object.create(null);for(let r in e)for(let a of r.split(" "))n[a]=e[r];return r=>{for(let a=r.prop(rt.group),s=-1;s<(a?a.length:0);s++){let i=n[s<0?r.name:a[s]];if(i)return i}}}};Lr.none=new Lr("",Object.create(null),0,8);var Xd=new WeakMap,KS=new WeakMap,an;(function(t){t[t.ExcludeBuffers=1]="ExcludeBuffers",t[t.IncludeAnonymous=2]="IncludeAnonymous",t[t.IgnoreMounts=4]="IgnoreMounts",t[t.IgnoreOverlays=8]="IgnoreOverlays",t[t.EnterBracketed=16]="EnterBracketed"})(an||(an={}));var _n=class t{constructor(e,n,r,a,s){if(this.type=e,this.children=n,this.positions=r,this.length=a,this.props=null,s&&s.length){this.props=Object.create(null);for(let[i,o]of s)this.props[typeof i=="number"?i:i.id]=o}}toString(){let e=Di.get(this);if(e&&!e.overlay)return e.tree.toString();let n="";for(let r of this.children){let a=r.toString();a&&(n&&(n+=","),n+=a)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(n.length?"("+n+")":""):n}cursor(e=0){return new Fu(this.topNode,e)}cursorAt(e,n=0,r=0){let a=Xd.get(this)||this.topNode,s=new Fu(a);return s.moveTo(e,n),Xd.set(this,s._tree),s}get topNode(){return new Fa(this,0,0,null)}resolve(e,n=0){let r=Tu(Xd.get(this)||this.topNode,e,n,!1);return Xd.set(this,r),r}resolveInner(e,n=0){let r=Tu(KS.get(this)||this.topNode,e,n,!0);return KS.set(this,r),r}resolveStack(e,n=0){return OD(this,e,n)}iterate(e){let{enter:n,leave:r,from:a=0,to:s=this.length}=e,i=e.mode||0,o=(i&an.IncludeAnonymous)>0;for(let l=this.cursor(i|an.IncludeAnonymous);;){let u=!1;if(l.from<=s&&l.to>=a&&(!o&&l.type.isAnonymous||n(l)!==!1)){if(l.firstChild())continue;u=!0}for(;u&&r&&(o||!l.type.isAnonymous)&&r(l),!l.nextSibling();){if(!l.parent())return;u=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let n in this.props)e.push([+n,this.props[n]]);return e}balance(e={}){return this.children.length<=8?this:Jm(Lr.none,this.children,this.positions,0,this.children.length,0,this.length,(n,r,a)=>new t(this.type,n,r,a,this.propValues),e.makeTree||((n,r,a)=>new t(Lr.none,n,r,a)))}static build(e){return BD(e)}};_n.empty=new _n(Lr.none,[],[],0);var Vm=class t{constructor(e,n){this.buffer=e,this.index=n}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new t(this.buffer,this.index)}},js=class t{constructor(e,n,r){this.buffer=e,this.length=n,this.set=r}get type(){return Lr.none}toString(){let e=[];for(let n=0;n<this.buffer.length;)e.push(this.childString(n)),n=this.buffer[n+3];return e.join(",")}childString(e){let n=this.buffer[e],r=this.buffer[e+3],a=this.set.types[n],s=a.name;if(/\W/.test(s)&&!a.isError&&(s=JSON.stringify(s)),e+=4,r==e)return s;let i=[];for(;e<r;)i.push(this.childString(e)),e=this.buffer[e+3];return s+"("+i.join(",")+")"}findChild(e,n,r,a,s){let{buffer:i}=this,o=-1;for(let l=e;l!=n&&!(JS(s,a,i[l+1],i[l+2])&&(o=l,r>0));l=i[l+3]);return o}slice(e,n,r){let a=this.buffer,s=new Uint16Array(n-e),i=0;for(let o=e,l=0;o<n;){s[l++]=a[o++],s[l++]=a[o++]-r;let u=s[l++]=a[o++]-r;s[l++]=a[o++]-e,i=Math.max(i,u)}return new t(s,i,this.set)}};function JS(t,e,n,r){switch(t){case-2:return n<e;case-1:return r>=e&&n<e;case 0:return n<e&&r>e;case 1:return n<=e&&r>e;case 2:return r>e;case 4:return!0}}function Tu(t,e,n,r){for(var a;t.from==t.to||(n<1?t.from>=e:t.from>e)||(n>-1?t.to<=e:t.to<e);){let i=!r&&t instanceof Fa&&t.index<0?null:t.parent;if(!i)return t;t=i}let s=r?0:an.IgnoreOverlays;if(r)for(let i=t,o=i.parent;o;i=o,o=i.parent)i instanceof Fa&&i.index<0&&((a=o.enter(e,n,s))===null||a===void 0?void 0:a.from)!=i.from&&(t=o);for(;;){let i=t.enter(e,n,s);if(!i)return t;t=i}}var Jd=class{cursor(e=0){return new Fu(this,e)}getChild(e,n=null,r=null){let a=XS(this,e,n,r);return a.length?a[0]:null}getChildren(e,n=null,r=null){return XS(this,e,n,r)}resolve(e,n=0){return Tu(this,e,n,!1)}resolveInner(e,n=0){return Tu(this,e,n,!0)}matchContext(e){return qm(this.parent,e)}enterUnfinishedNodesBefore(e){let n=this.childBefore(e),r=this;for(;n;){let a=n.lastChild;if(!a||a.to!=n.to)break;a.type.isError&&a.from==a.to?(r=n,n=a.prevSibling):n=a}return r}get node(){return this}get next(){return this.parent}},Fa=class t extends Jd{constructor(e,n,r,a){super(),this._tree=e,this.from=n,this.index=r,this._parent=a}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,n,r,a,s=0){for(let i=this;;){for(let{children:o,positions:l}=i._tree,u=n>0?o.length:-1;e!=u;e+=n){let c=o[e],d=l[e]+i.from,f;if(!(!(s&an.EnterBracketed&&c instanceof _n&&(f=Di.get(c))&&!f.overlay&&f.bracketed&&r>=d&&r<=d+c.length)&&!JS(a,r,d,d+c.length))){if(c instanceof js){if(s&an.ExcludeBuffers)continue;let h=c.findChild(0,c.buffer.length,n,r-d,a);if(h>-1)return new Du(new $m(i,c,e,d),null,h)}else if(s&an.IncludeAnonymous||!c.type.isAnonymous||Ym(c)){let h;if(!(s&an.IgnoreMounts)&&(h=Di.get(c))&&!h.overlay)return new t(h.tree,d,e,i);let p=new t(c,d,e,i);return s&an.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(n<0?c.children.length-1:0,n,r,a,s)}}}if(s&an.IncludeAnonymous||!i.type.isAnonymous||(i.index>=0?e=i.index+n:e=n<0?-1:i._parent._tree.children.length,i=i._parent,!i))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(e,n,r=0){let a;if(!(r&an.IgnoreOverlays)&&(a=Di.get(this._tree))&&a.overlay){let s=e-this.from,i=r&an.EnterBracketed&&a.bracketed;for(let{from:o,to:l}of a.overlay)if((n>0||i?o<=s:o<s)&&(n<0||i?l>=s:l>s))return new t(a.tree,a.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,n,r)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}};function XS(t,e,n,r){let a=t.cursor(),s=[];if(!a.firstChild())return s;if(n!=null){for(let i=!1;!i;)if(i=a.type.is(n),!a.nextSibling())return s}for(;;){if(r!=null&&a.type.is(r))return s;if(a.type.is(e)&&s.push(a.node),!a.nextSibling())return r==null?s:[]}}function qm(t,e,n=e.length-1){for(let r=t;n>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(e[n]&&e[n]!=r.name)return!1;n--}}return!0}var $m=class{constructor(e,n,r,a){this.parent=e,this.buffer=n,this.index=r,this.start=a}},Du=class t extends Jd{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,n,r){super(),this.context=e,this._parent=n,this.index=r,this.type=e.buffer.set.types[e.buffer.buffer[r]]}child(e,n,r){let{buffer:a}=this.context,s=a.findChild(this.index+4,a.buffer[this.index+3],e,n-this.context.start,r);return s<0?null:new t(this.context,this,s)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,n,r=0){if(r&an.ExcludeBuffers)return null;let{buffer:a}=this.context,s=a.findChild(this.index+4,a.buffer[this.index+3],n>0?1:-1,e-this.context.start,n);return s<0?null:new t(this.context,this,s)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,n=e.buffer[this.index+3];return n<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new t(this.context,this._parent,n):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,n=this._parent?this._parent.index+4:0;return this.index==n?this.externalSibling(-1):new t(this.context,this._parent,e.findChild(n,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],n=[],{buffer:r}=this.context,a=this.index+4,s=r.buffer[this.index+3];if(s>a){let i=r.buffer[this.index+1];e.push(r.slice(a,s,i)),n.push(0)}return new _n(this.type,e,n,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}};function ZS(t){if(!t.length)return null;let e=0,n=t[0];for(let s=1;s<t.length;s++){let i=t[s];(i.from>n.from||i.to<n.to)&&(n=i,e=s)}let r=n instanceof Fa&&n.index<0?null:n.parent,a=t.slice();return r?a[e]=r:a.splice(e,1),new Km(a,n)}var Km=class{constructor(e,n){this.heads=e,this.node=n}get next(){return ZS(this.heads)}};function OD(t,e,n){let r=t.resolveInner(e,n),a=null;for(let s=r instanceof Fa?r:r.context.parent;s;s=s.parent)if(s.index<0){let i=s.parent;(a||(a=[r])).push(i.resolve(e,n)),s=i}else{let i=Di.get(s.tree);if(i&&i.overlay&&i.overlay[0].from<=e&&i.overlay[i.overlay.length-1].to>=e){let o=new Fa(i.tree,i.overlay[0].from+s.from,-1,s);(a||(a=[r])).push(Tu(o,e,n,!1))}}return a?ZS(a):r}var Fu=class{get name(){return this.type.name}constructor(e,n=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=n&~an.EnterBracketed,e instanceof Fa)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let r=e._parent;r;r=r._parent)this.stack.unshift(r.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,n){this.index=e;let{start:r,buffer:a}=this.buffer;return this.type=n||a.set.types[a.buffer[e]],this.from=r+a.buffer[e+1],this.to=r+a.buffer[e+2],!0}yield(e){return e?e instanceof Fa?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,n,r){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,n,r,this.mode));let{buffer:a}=this.buffer,s=a.findChild(this.index+4,a.buffer[this.index+3],e,n-this.buffer.start,r);return s<0?!1:(this.stack.push(this.index),this.yieldBuf(s))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,n,r=this.mode){return this.buffer?r&an.ExcludeBuffers?!1:this.enterChild(1,e,n):this.yield(this._tree.enter(e,n,r))}parent(){if(!this.buffer)return this.yieldNode(this.mode&an.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&an.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:n}=this.buffer,r=this.stack.length-1;if(e<0){let a=r<0?0:this.stack[r]+4;if(this.index!=a)return this.yieldBuf(n.findChild(a,this.index,-1,0,4))}else{let a=n.buffer[this.index+3];if(a<(r<0?n.buffer.length:n.buffer[this.stack[r]+3]))return this.yieldBuf(a)}return r<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let n,r,{buffer:a}=this;if(a){if(e>0){if(this.index<a.buffer.buffer.length)return!1}else for(let s=0;s<this.index;s++)if(a.buffer.buffer[s+3]<this.index)return!1;({index:n,parent:r}=a)}else({index:n,_parent:r}=this._tree);for(;r;{index:n,_parent:r}=r)if(n>-1)for(let s=n+e,i=e<0?-1:r._tree.children.length;s!=i;s+=e){let o=r._tree.children[s];if(this.mode&an.IncludeAnonymous||o instanceof js||!o.type.isAnonymous||Ym(o))return!1}return!0}move(e,n){if(n&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,n=0){for(;(this.from==this.to||(n<1?this.from>=e:this.from>e)||(n>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,n););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,n=null,r=0;if(e&&e.context==this.buffer)e:for(let a=this.index,s=this.stack.length;s>=0;){for(let i=e;i;i=i._parent)if(i.index==a){if(a==this.index)return i;n=i,r=s+1;break e}a=this.stack[--s]}for(let a=r;a<this.stack.length;a++)n=new Du(this.buffer,n,this.stack[a]);return this.bufferNode=new Du(this.buffer,n,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,n){for(let r=0;;){let a=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){r++;continue}this.type.isAnonymous||(a=!0)}for(;;){if(a&&n&&n(this),a=this.type.isAnonymous,!r)return;if(this.nextSibling())break;this.parent(),r--,a=!0}}}matchContext(e){if(!this.buffer)return qm(this.node.parent,e);let{buffer:n}=this.buffer,{types:r}=n.set;for(let a=e.length-1,s=this.stack.length-1;a>=0;s--){if(s<0)return qm(this._tree,e,a);let i=r[n.buffer[this.stack[s]]];if(!i.isAnonymous){if(e[a]&&e[a]!=i.name)return!1;a--}}return!0}};function Ym(t){return t.children.some(e=>e instanceof js||!e.type.isAnonymous||Ym(e))}function BD(t){var e;let{buffer:n,nodeSet:r,maxBufferLength:a=1024,reused:s=[],minRepeatType:i=r.types.length}=t,o=Array.isArray(n)?new Vm(n,n.length):n,l=r.types,u=0,c=0;function d(L,P,w,k,_,M){let{id:R,start:U,end:v,size:T}=o,V=c,Y=u;if(T<0)if(o.next(),T==-1){let te=s[R];w.push(te),k.push(U-L);return}else if(T==-3){u=R;return}else if(T==-4){c=R;return}else throw new RangeError(`Unrecognized record size: ${T}`);let N=l[R],A,B,K=U-L;if(v-U<=a&&(B=m(o.pos-P,_))){let te=new Uint16Array(B.size-B.skip),ne=o.pos-B.size,pe=te.length;for(;o.pos>ne;)pe=x(B.start,te,pe);A=new js(te,v-B.start,r),K=B.start-L}else{let te=o.pos-T;o.next();let ne=[],pe=[],Se=R>=i?R:-1,le=0,re=v;for(;o.pos>te;)Se>=0&&o.id==Se&&o.size>=0?(o.end<=re-a&&(p(ne,pe,U,le,o.end,re,Se,V,Y),le=ne.length,re=o.end),o.next()):M>2500?f(U,te,ne,pe):d(U,te,ne,pe,Se,M+1);if(Se>=0&&le>0&&le<ne.length&&p(ne,pe,U,le,U,re,Se,V,Y),ne.reverse(),pe.reverse(),Se>-1&&le>0){let he=h(N,Y);A=Jm(N,ne,pe,0,ne.length,0,v-U,he,he)}else A=g(N,ne,pe,v-U,V-v,Y)}w.push(A),k.push(K)}function f(L,P,w,k){let _=[],M=0,R=-1;for(;o.pos>P;){let{id:U,start:v,end:T,size:V}=o;if(V>4)o.next();else{if(R>-1&&v<R)break;R<0&&(R=T-a),_.push(U,v,T),M++,o.next()}}if(M){let U=new Uint16Array(M*4),v=_[_.length-2];for(let T=_.length-3,V=0;T>=0;T-=3)U[V++]=_[T],U[V++]=_[T+1]-v,U[V++]=_[T+2]-v,U[V++]=V;w.push(new js(U,_[2]-v,r)),k.push(v-L)}}function h(L,P){return(w,k,_)=>{let M=0,R=w.length-1,U,v;if(R>=0&&(U=w[R])instanceof _n){if(!R&&U.type==L&&U.length==_)return U;(v=U.prop(rt.lookAhead))&&(M=k[R]+U.length+v)}return g(L,w,k,_,M,P)}}function p(L,P,w,k,_,M,R,U,v){let T=[],V=[];for(;L.length>k;)T.push(L.pop()),V.push(P.pop()+w-_);L.push(g(r.types[R],T,V,M-_,U-M,v)),P.push(_-w)}function g(L,P,w,k,_,M,R){if(M){let U=[rt.contextHash,M];R=R?[U].concat(R):[U]}if(_>25){let U=[rt.lookAhead,_];R=R?[U].concat(R):[U]}return new _n(L,P,w,k,R)}function m(L,P){let w=o.fork(),k=0,_=0,M=0,R=w.end-a,U={size:0,start:0,skip:0};e:for(let v=w.pos-L;w.pos>v;){let T=w.size;if(w.id==P&&T>=0){U.size=k,U.start=_,U.skip=M,M+=4,k+=4,w.next();continue}let V=w.pos-T;if(T<0||V<v||w.start<R)break;let Y=w.id>=i?4:0,N=w.start;for(w.next();w.pos>V;){if(w.size<0)if(w.size==-3||w.size==-4)Y+=4;else break e;else w.id>=i&&(Y+=4);w.next()}_=N,k+=T,M+=Y}return(P<0||k==L)&&(U.size=k,U.start=_,U.skip=M),U.size>4?U:void 0}function x(L,P,w){let{id:k,start:_,end:M,size:R}=o;if(o.next(),R>=0&&k<i){let U=w;if(R>4){let v=o.pos-(R-4);for(;o.pos>v;)w=x(L,P,w)}P[--w]=U,P[--w]=M-L,P[--w]=_-L,P[--w]=k}else R==-3?u=k:R==-4&&(c=k);return w}let y=[],b=[];for(;o.pos>0;)d(t.start||0,t.bufferStart||0,y,b,-1,0);let C=(e=t.length)!==null&&e!==void 0?e:y.length?b[0]+y[0].length:0;return new _n(l[t.topID],y.reverse(),b.reverse(),C)}var YS=new WeakMap;function Yd(t,e){if(!t.isAnonymous||e instanceof js||e.type!=t)return 1;let n=YS.get(e);if(n==null){n=1;for(let r of e.children){if(r.type!=t||!(r instanceof _n)){n=1;break}n+=Yd(t,r)}YS.set(e,n)}return n}function Jm(t,e,n,r,a,s,i,o,l){let u=0;for(let p=r;p<a;p++)u+=Yd(t,e[p]);let c=Math.ceil(u*1.5/8),d=[],f=[];function h(p,g,m,x,y){for(let b=m;b<x;){let C=b,L=g[b],P=Yd(t,p[b]);for(b++;b<x;b++){let w=Yd(t,p[b]);if(P+w>=c)break;P+=w}if(b==C+1){if(P>c){let w=p[C];h(w.children,w.positions,0,w.children.length,g[C]+y);continue}d.push(p[C])}else{let w=g[b-1]+p[b-1].length-L;d.push(Jm(t,p,g,C,b,L,w,null,l))}f.push(L+y-s)}}return h(e,n,r,a,0),(o||l)(d,f,i)}var Fi=class t{constructor(e,n,r,a,s=!1,i=!1){this.from=e,this.to=n,this.tree=r,this.offset=a,this.open=(s?1:0)|(i?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,n=[],r=!1){let a=[new t(0,e.length,e,0,!1,r)];for(let s of n)s.to>e.length&&a.push(s);return a}static applyChanges(e,n,r=128){if(!n.length)return e;let a=[],s=1,i=e.length?e[0]:null;for(let o=0,l=0,u=0;;o++){let c=o<n.length?n[o]:null,d=c?c.fromA:1e9;if(d-l>=r)for(;i&&i.from<d;){let f=i;if(l>=f.from||d<=f.to||u){let h=Math.max(f.from,l)-u,p=Math.min(f.to,d)-u;f=h>=p?null:new t(h,p,f.tree,f.offset+u,o>0,!!c)}if(f&&a.push(f),i.to>d)break;i=s<e.length?e[s++]:null}if(!c)break;l=c.toA,u=c.toA-c.toB}return a}},Zd=class{startParse(e,n,r){return typeof e=="string"&&(e=new Xm(e)),r=r?r.length?r.map(a=>new Mu(a.from,a.to)):[new Mu(0,0)]:[new Mu(0,e.length)],this.createParse(e,n||[],r)}parse(e,n,r){let a=this.startParse(e,n,r);for(;;){let s=a.advance();if(s)return s}}},Xm=class{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,n){return this.string.slice(e,n)}};var t6=new rt({perNode:!0});var _D=0,ca=class t{constructor(e,n,r,a){this.name=e,this.set=n,this.base=r,this.modified=a,this.id=_D++}toString(){let{name:e}=this;for(let n of this.modified)n.name&&(e=`${n.name}(${e})`);return e}static define(e,n){let r=typeof e=="string"?e:"?";if(e instanceof t&&(n=e),n?.base)throw new Error("Can not derive from a modified tag");let a=new t(r,[],null,[]);if(a.set.push(a),n)for(let s of n.set)a.set.push(s);return a}static defineModifier(e){let n=new nf(e);return r=>r.modified.indexOf(n)>-1?r:nf.get(r.base||r,r.modified.concat(n).sort((a,s)=>a.id-s.id))}},HD=0,nf=class t{constructor(e){this.name=e,this.instances=[],this.id=HD++}static get(e,n){if(!n.length)return e;let r=n[0].instances.find(o=>o.base==e&&UD(n,o.modified));if(r)return r;let a=[],s=new ca(e.name,a,e,n);for(let o of n)o.instances.push(s);let i=GD(n);for(let o of e.set)if(!o.modified.length)for(let l of i)a.push(t.get(o,l));return s}};function UD(t,e){return t.length==e.length&&t.every((n,r)=>n==e[r])}function GD(t){let e=[[]];for(let n=0;n<t.length;n++)for(let r=0,a=e.length;r<a;r++)e.push(e[r].concat(t[n]));return e.sort((n,r)=>r.length-n.length)}function tC(t){let e=Object.create(null);for(let n in t){let r=t[n];Array.isArray(r)||(r=[r]);for(let a of n.split(" "))if(a){let s=[],i=2,o=a;for(let d=0;;){if(o=="..."&&d>0&&d+3==a.length){i=1;break}let f=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(o);if(!f)throw new RangeError("Invalid path: "+a);if(s.push(f[0]=="*"?"":f[0][0]=='"'?JSON.parse(f[0]):f[0]),d+=f[0].length,d==a.length)break;let h=a[d++];if(d==a.length&&h=="!"){i=0;break}if(h!="/")throw new RangeError("Invalid path: "+a);o=a.slice(d)}let l=s.length-1,u=s[l];if(!u)throw new RangeError("Invalid path: "+a);let c=new Oi(r,i,l>0?s.slice(0,l):null);e[u]=c.sort(e[u])}}return nC.add(e)}var nC=new rt({combine(t,e){let n,r,a;for(;t||e;){if(!t||e&&t.depth<=e.depth?(a=e,e=e.next):(a=t,t=t.next),n&&n.mode==a.mode&&!a.context&&!n.context)continue;let s=new Oi(a.tags,a.mode,a.context);n?n.next=s:r=s,n=s}return r}}),Oi=class{constructor(e,n,r,a){this.tags=e,this.mode=n,this.context=r,this.next=a}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}};Oi.empty=new Oi([],2,null);function tg(t,e){let n=Object.create(null);for(let s of t)if(!Array.isArray(s.tag))n[s.tag.id]=s.class;else for(let i of s.tag)n[i.id]=s.class;let{scope:r,all:a=null}=e||{};return{style:s=>{let i=a;for(let o of s)for(let l of o.set){let u=n[l.id];if(u){i=i?i+" "+u:u;break}}return i},scope:r}}function WD(t,e){let n=null;for(let r of t){let a=r.style(e);a&&(n=n?n+" "+a:a)}return n}function ng(t,e,n,r=0,a=t.length){let s=new Qm(r,Array.isArray(e)?e:[e],n);s.highlightRange(t.cursor(),r,a,"",s.highlighters),s.flush(a)}var Qm=class{constructor(e,n,r){this.at=e,this.highlighters=n,this.span=r,this.class=""}startSpan(e,n){n!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=n)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,n,r,a,s){let{type:i,from:o,to:l}=e;if(o>=r||l<=n)return;i.isTop&&(s=this.highlighters.filter(h=>!h.scope||h.scope(i)));let u=a,c=zD(e)||Oi.empty,d=WD(s,c.tags);if(d&&(u&&(u+=" "),u+=d,c.mode==1&&(a+=(a?" ":"")+d)),this.startSpan(Math.max(n,o),u),c.opaque)return;let f=e.tree&&e.tree.prop(rt.mounted);if(f&&f.overlay){let h=e.node.enter(f.overlay[0].from+o,1),p=this.highlighters.filter(m=>!m.scope||m.scope(f.tree.type)),g=e.firstChild();for(let m=0,x=o;;m++){let y=m<f.overlay.length?f.overlay[m]:null,b=y?y.from+o:l,C=Math.max(n,x),L=Math.min(r,b);if(C<L&&g)for(;e.from<L&&(this.highlightRange(e,C,L,a,s),this.startSpan(Math.min(L,e.to),u),!(e.to>=b||!e.nextSibling())););if(!y||b>r)break;x=y.to+o,x>n&&(this.highlightRange(h.cursor(),Math.max(n,y.from+o),Math.min(r,x),"",p),this.startSpan(Math.min(r,x),u))}g&&e.parent()}else if(e.firstChild()){f&&(a="");do if(!(e.to<=n)){if(e.from>=r)break;this.highlightRange(e,n,r,a,s),this.startSpan(Math.min(r,e.to),u)}while(e.nextSibling());e.parent()}}};function zD(t){let e=t.type.prop(nC);for(;e&&e.context&&!t.matchContext(e.context);)e=e.next;return e||null}var ye=ca.define,Qd=ye(),Vs=ye(),QS=ye(Vs),eC=ye(Vs),qs=ye(),ef=ye(qs),Zm=ye(qs),Ba=ye(),Ei=ye(Ba),Ea=ye(),Oa=ye(),eg=ye(),Eu=ye(eg),tf=ye(),ve={comment:Qd,lineComment:ye(Qd),blockComment:ye(Qd),docComment:ye(Qd),name:Vs,variableName:ye(Vs),typeName:QS,tagName:ye(QS),propertyName:eC,attributeName:ye(eC),className:ye(Vs),labelName:ye(Vs),namespace:ye(Vs),macroName:ye(Vs),literal:qs,string:ef,docString:ye(ef),character:ye(ef),attributeValue:ye(ef),number:Zm,integer:ye(Zm),float:ye(Zm),bool:ye(qs),regexp:ye(qs),escape:ye(qs),color:ye(qs),url:ye(qs),keyword:Ea,self:ye(Ea),null:ye(Ea),atom:ye(Ea),unit:ye(Ea),modifier:ye(Ea),operatorKeyword:ye(Ea),controlKeyword:ye(Ea),definitionKeyword:ye(Ea),moduleKeyword:ye(Ea),operator:Oa,derefOperator:ye(Oa),arithmeticOperator:ye(Oa),logicOperator:ye(Oa),bitwiseOperator:ye(Oa),compareOperator:ye(Oa),updateOperator:ye(Oa),definitionOperator:ye(Oa),typeOperator:ye(Oa),controlOperator:ye(Oa),punctuation:eg,separator:ye(eg),bracket:Eu,angleBracket:ye(Eu),squareBracket:ye(Eu),paren:ye(Eu),brace:ye(Eu),content:Ba,heading:Ei,heading1:ye(Ei),heading2:ye(Ei),heading3:ye(Ei),heading4:ye(Ei),heading5:ye(Ei),heading6:ye(Ei),contentSeparator:ye(Ba),list:ye(Ba),quote:ye(Ba),emphasis:ye(Ba),strong:ye(Ba),link:ye(Ba),monospace:ye(Ba),strikethrough:ye(Ba),inserted:ye(),deleted:ye(),changed:ye(),invalid:ye(),meta:tf,documentMeta:ye(tf),annotation:ye(tf),processingInstruction:ye(tf),definition:ca.defineModifier("definition"),constant:ca.defineModifier("constant"),function:ca.defineModifier("function"),standard:ca.defineModifier("standard"),local:ca.defineModifier("local"),special:ca.defineModifier("special")};for(let t in ve){let e=ve[t];e instanceof ca&&(e.name=t)}var a6=tg([{tag:ve.link,class:"tok-link"},{tag:ve.heading,class:"tok-heading"},{tag:ve.emphasis,class:"tok-emphasis"},{tag:ve.strong,class:"tok-strong"},{tag:ve.keyword,class:"tok-keyword"},{tag:ve.atom,class:"tok-atom"},{tag:ve.bool,class:"tok-bool"},{tag:ve.url,class:"tok-url"},{tag:ve.labelName,class:"tok-labelName"},{tag:ve.inserted,class:"tok-inserted"},{tag:ve.deleted,class:"tok-deleted"},{tag:ve.literal,class:"tok-literal"},{tag:ve.string,class:"tok-string"},{tag:ve.number,class:"tok-number"},{tag:[ve.regexp,ve.escape,ve.special(ve.string)],class:"tok-string2"},{tag:ve.variableName,class:"tok-variableName"},{tag:ve.local(ve.variableName),class:"tok-variableName tok-local"},{tag:ve.definition(ve.variableName),class:"tok-variableName tok-definition"},{tag:ve.special(ve.variableName),class:"tok-variableName2"},{tag:ve.definition(ve.propertyName),class:"tok-propertyName tok-definition"},{tag:ve.typeName,class:"tok-typeName"},{tag:ve.namespace,class:"tok-namespace"},{tag:ve.className,class:"tok-className"},{tag:ve.macroName,class:"tok-macroName"},{tag:ve.propertyName,class:"tok-propertyName"},{tag:ve.operator,class:"tok-operator"},{tag:ve.comment,class:"tok-comment"},{tag:ve.meta,class:"tok-meta"},{tag:ve.invalid,class:"tok-invalid"},{tag:ve.punctuation,class:"tok-punctuation"}]);var rg,Bu=new rt;var jD=new rt,zr=class{constructor(e,n,r=[],a=""){this.data=e,this.name=a,It.prototype.hasOwnProperty("tree")||Object.defineProperty(It.prototype,"tree",{get(){return ls(this)}}),this.parser=n,this.extension=[$s.of(this),It.languageData.of((s,i,o)=>{let l=rC(s,i,o),u=l.type.prop(Bu);if(!u)return[];let c=s.facet(u),d=l.type.prop(jD);if(d){let f=l.resolve(i-l.from,o);for(let h of d)if(h.test(f,s)){let p=s.facet(h.facet);return h.type=="replace"?p:p.concat(c)}}return c})].concat(r)}isActiveAt(e,n,r=-1){return rC(e,n,r).type.prop(Bu)==this.data}findRegions(e){let n=e.facet($s);if(n?.data==this.data)return[{from:0,to:e.doc.length}];if(!n||!n.allowsNesting)return[];let r=[],a=(s,i)=>{if(s.prop(Bu)==this.data){r.push({from:i,to:i+s.length});return}let o=s.prop(rt.mounted);if(o){if(o.tree.prop(Bu)==this.data){if(o.overlay)for(let l of o.overlay)r.push({from:l.from+i,to:l.to+i});else r.push({from:i,to:i+s.length});return}else if(o.overlay){let l=r.length;if(a(o.tree,o.overlay[0].from+i),r.length>l)return}}for(let l=0;l<s.children.length;l++){let u=s.children[l];u instanceof _n&&a(u,s.positions[l]+i)}};return a(ls(e),0),r}get allowsNesting(){return!0}};zr.setState=pt.define();function rC(t,e,n){let r=t.facet($s),a=ls(t).topNode;if(!r||r.allowsNesting)for(let s=a;s;s=s.enter(e,n,an.ExcludeBuffers|an.EnterBracketed))s.type.isTop&&(a=s);return a}function ls(t){let e=t.field(zr.state,!1);return e?e.tree:_n.empty}var ig=class{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,n){let r=this.cursorPos-this.string.length;return e<r||n>=this.cursorPos?this.doc.sliceString(e,n):this.string.slice(e-r,n-r)}},Ou=null,og=class t{constructor(e,n,r=[],a,s,i,o,l){this.parser=e,this.state=n,this.fragments=r,this.tree=a,this.treeLen=s,this.viewport=i,this.skipped=o,this.scheduleOn=l,this.parse=null,this.tempSkipped=[]}static create(e,n,r){return new t(e,n,[],_n.empty,0,r,[],null)}startParse(){return this.parser.startParse(new ig(this.state.doc),this.fragments)}work(e,n){return n!=null&&n>=this.state.doc.length&&(n=void 0),this.tree!=_n.empty&&this.isDone(n??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var r;if(typeof e=="number"){let a=Date.now()+e;e=()=>Date.now()>a}for(this.parse||(this.parse=this.startParse()),n!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>n)&&n<this.state.doc.length&&this.parse.stopAt(n);;){let a=this.parse.advance();if(a)if(this.fragments=this.withoutTempSkipped(Fi.addTree(a,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(r=this.parse.stoppedAt)!==null&&r!==void 0?r:this.state.doc.length,this.tree=a,this.parse=null,this.treeLen<(n??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,n;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(n=this.parse.advance()););}),this.treeLen=e,this.tree=n,this.fragments=this.withoutTempSkipped(Fi.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let n=Ou;Ou=this;try{return e()}finally{Ou=n}}withoutTempSkipped(e){for(let n;n=this.tempSkipped.pop();)e=aC(e,n.from,n.to);return e}changes(e,n){let{fragments:r,tree:a,treeLen:s,viewport:i,skipped:o}=this;if(this.takeTree(),!e.empty){let l=[];if(e.iterChangedRanges((u,c,d,f)=>l.push({fromA:u,toA:c,fromB:d,toB:f})),r=Fi.applyChanges(r,l),a=_n.empty,s=0,i={from:e.mapPos(i.from,-1),to:e.mapPos(i.to,1)},this.skipped.length){o=[];for(let u of this.skipped){let c=e.mapPos(u.from,1),d=e.mapPos(u.to,-1);c<d&&o.push({from:c,to:d})}}}return new t(this.parser,n,r,a,s,i,o,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let n=this.skipped.length;for(let r=0;r<this.skipped.length;r++){let{from:a,to:s}=this.skipped[r];a<e.to&&s>e.from&&(this.fragments=aC(this.fragments,a,s),this.skipped.splice(r--,1))}return this.skipped.length>=n?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,n){this.skipped.push({from:e,to:n})}static getSkippingParser(e){return new class extends Zd{createParse(n,r,a){let s=a[0].from,i=a[a.length-1].to;return{parsedPos:s,advance(){let l=Ou;if(l){for(let u of a)l.tempSkipped.push(u);e&&(l.scheduleOn=l.scheduleOn?Promise.all([l.scheduleOn,e]):e)}return this.parsedPos=i,new _n(Lr.none,[],[],i-s)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let n=this.fragments;return this.treeLen>=e&&n.length&&n[0].from==0&&n[0].to>=e}static get(){return Ou}};function aC(t,e,n){return Fi.applyChanges(t,[{fromA:e,toA:n,fromB:e,toB:n}])}var _u=class t{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let n=this.context.changes(e.changes,e.state),r=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),n.viewport.to);return n.work(20,r)||n.takeTree(),new t(n)}static init(e){let n=Math.min(3e3,e.doc.length),r=og.create(e.facet($s).parser,e,{from:0,to:n});return r.work(20,n)||r.takeTree(),new t(r)}};zr.state=vn.define({create:_u.init,update(t,e){for(let n of e.effects)if(n.is(zr.setState))return n.value;return e.startState.facet($s)!=e.state.facet($s)?_u.init(e.state):t.apply(e)}});var lC=t=>{let e=setTimeout(()=>t(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(lC=t=>{let e=-1,n=setTimeout(()=>{e=requestIdleCallback(t,{timeout:400})},100);return()=>e<0?clearTimeout(n):cancelIdleCallback(e)});var ag=typeof navigator<"u"&&(!((rg=navigator.scheduling)===null||rg===void 0)&&rg.isInputPending)?()=>navigator.scheduling.isInputPending():null,VD=hr.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let n=this.view.state.field(zr.state).context;(n.updateViewport(e.view.viewport)||this.view.viewport.to>n.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(n)}scheduleWork(){if(this.working)return;let{state:e}=this.view,n=e.field(zr.state);(n.tree!=n.context.tree||!n.context.isDone(e.doc.length))&&(this.working=lC(this.work))}work(e){this.working=null;let n=Date.now();if(this.chunkEnd<n&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=n+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:r,viewport:{to:a}}=this.view,s=r.field(zr.state);if(s.tree==s.context.tree&&s.context.isDone(a+1e5))return;let i=Date.now()+Math.min(this.chunkBudget,100,e&&!ag?Math.max(25,e.timeRemaining()-5):1e9),o=s.context.treeLen<a&&r.doc.length>a+1e3,l=s.context.work(()=>ag&&ag()||Date.now()>i,a+(o?0:1e5));this.chunkBudget-=Date.now()-n,(l||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:zr.setState.of(new _u(s.context))})),this.chunkBudget>0&&!(l&&!o)&&this.scheduleWork(),this.checkAsyncSchedule(s.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(n=>oa(this.view.state,n)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),$s=Me.define({combine(t){return t.length?t[0]:null},enables:t=>[zr.state,VD,Pe.contentAttributes.compute([t],e=>{let n=e.facet(t);return n&&n.name?{"data-language":n.name}:{}})]});var qD=Me.define(),rf=Me.define({combine:t=>{if(!t.length)return" ";let e=t[0];if(!e||/\S/.test(e)||Array.from(e).some(n=>n!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(t[0]));return e}});function Hu(t){let e=t.facet(rf);return e.charCodeAt(0)==9?t.tabSize*e.length:e.length}function Uu(t,e){let n="",r=t.tabSize,a=t.facet(rf)[0];if(a==" "){for(;e>=r;)n+=" ",e-=r;a=" "}for(let s=0;s<e;s++)n+=a;return n}function fg(t,e){t instanceof It&&(t=new Bi(t));for(let r of t.state.facet(qD)){let a=r(t,e);if(a!==void 0)return a}let n=ls(t.state);return n.length>=e?KD(t,n,e):null}var Bi=class{constructor(e,n={}){this.state=e,this.options=n,this.unit=Hu(e)}lineAt(e,n=1){let r=this.state.doc.lineAt(e),{simulateBreak:a,simulateDoubleBreak:s}=this.options;return a!=null&&a>=r.from&&a<=r.to?s&&a==e?{text:"",from:e}:(n<0?a<e:a<=e)?{text:r.text.slice(a-r.from),from:a}:{text:r.text.slice(0,a-r.from),from:r.from}:r}textAfterPos(e,n=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:r,from:a}=this.lineAt(e,n);return r.slice(e-a,Math.min(r.length,e+100-a))}column(e,n=1){let{text:r,from:a}=this.lineAt(e,n),s=this.countColumn(r,e-a),i=this.options.overrideIndentation?this.options.overrideIndentation(a):-1;return i>-1&&(s+=i-this.countColumn(r,r.search(/\S|$/))),s}countColumn(e,n=e.length){return Li(e,this.state.tabSize,n)}lineIndent(e,n=1){let{text:r,from:a}=this.lineAt(e,n),s=this.options.overrideIndentation;if(s){let i=s(a);if(i>-1)return i}return this.countColumn(r,r.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}},$D=new rt;function KD(t,e,n){let r=e.resolveStack(n),a=e.resolveInner(n,-1).resolve(n,0).enterUnfinishedNodesBefore(n);if(a!=r.node){let s=[];for(let i=a;i&&!(i.from<r.node.from||i.to>r.node.to||i.from==r.node.from&&i.type==r.node.type);i=i.parent)s.push(i);for(let i=s.length-1;i>=0;i--)r={node:s[i],next:r}}return uC(r,t,n)}function uC(t,e,n){for(let r=t;r;r=r.next){let a=YD(r.node);if(a)return a(lg.create(e,n,r))}return 0}function XD(t){return t.pos==t.options.simulateBreak&&t.options.simulateDoubleBreak}function YD(t){let e=t.type.prop($D);if(e)return e;let n=t.firstChild,r;if(n&&(r=n.type.prop(rt.closedBy))){let a=t.lastChild,s=a&&r.indexOf(a.name)>-1;return i=>eF(i,!0,1,void 0,s&&!XD(i)?a.from:void 0)}return t.parent==null?JD:null}function JD(){return 0}var lg=class t extends Bi{constructor(e,n,r){super(e.state,e.options),this.base=e,this.pos=n,this.context=r}get node(){return this.context.node}static create(e,n,r){return new t(e,n,r)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let n=this.state.doc.lineAt(e.from);for(;;){let r=e.resolve(n.from);for(;r.parent&&r.parent.from==r.from;)r=r.parent;if(ZD(r,e))break;n=this.state.doc.lineAt(r.from)}return this.lineIndent(n.from)}continue(){return uC(this.context.next,this.base,this.pos)}};function ZD(t,e){for(let n=e;n;n=n.parent)if(t==n)return!0;return!1}function QD(t){let e=t.node,n=e.childAfter(e.from),r=e.lastChild;if(!n)return null;let a=t.options.simulateBreak,s=t.state.doc.lineAt(n.from),i=a==null||a<=s.from?s.to:Math.min(s.to,a);for(let o=n.to;;){let l=e.childAfter(o);if(!l||l==r)return null;if(!l.type.isSkipped){if(l.from>=i)return null;let u=/^ */.exec(s.text.slice(n.to-s.from))[0].length;return{from:n.from,to:n.to+u}}o=l.to}}function eF(t,e,n,r,a){let s=t.textAfter,i=s.match(/^\s*/)[0].length,o=r&&s.slice(i,i+r.length)==r||a==t.pos+i,l=e?QD(t):null;return l?o?t.column(l.from):t.column(l.to):t.baseIndent+(o?0:t.unit*n)}var ug=class t{constructor(e,n){this.specs=e;let r;function a(o){let l=dr.newName();return(r||(r=Object.create(null)))["."+l]=o,l}let s=typeof n.all=="string"?n.all:n.all?a(n.all):void 0,i=n.scope;this.scope=i instanceof zr?o=>o.prop(Bu)==i.data:i?o=>o==i:void 0,this.style=tg(e.map(o=>({tag:o.tag,class:o.class||a(Object.assign({},o,{tag:null}))})),{all:s}).style,this.module=r?new dr(r):null,this.themeType=n.themeType}static define(e,n){return new t(e,n||{})}},tF=Me.define(),nF=Me.define({combine(t){return t.length?[t[0]]:null}});function rF(t){let e=t.facet(tF);return e.length?e:t.facet(nF)}function cC(t,e,n){let r=rF(t),a=null;if(r){for(let s of r)if(!s.scope||n&&s.scope(n)){let i=s.style(e);i&&(a=a?a+" "+i:i)}}return a}var h6=ug.define([{tag:ve.meta,color:"#404740"},{tag:ve.link,textDecoration:"underline"},{tag:ve.heading,textDecoration:"underline",fontWeight:"bold"},{tag:ve.emphasis,fontStyle:"italic"},{tag:ve.strong,fontWeight:"bold"},{tag:ve.strikethrough,textDecoration:"line-through"},{tag:ve.keyword,color:"#708"},{tag:[ve.atom,ve.bool,ve.url,ve.contentSeparator,ve.labelName],color:"#219"},{tag:[ve.literal,ve.inserted],color:"#164"},{tag:[ve.string,ve.deleted],color:"#a11"},{tag:[ve.regexp,ve.escape,ve.special(ve.string)],color:"#e40"},{tag:ve.definition(ve.variableName),color:"#00f"},{tag:ve.local(ve.variableName),color:"#30a"},{tag:[ve.typeName,ve.namespace],color:"#085"},{tag:ve.className,color:"#167"},{tag:[ve.special(ve.variableName),ve.macroName],color:"#256"},{tag:ve.definition(ve.propertyName),color:"#00c"},{tag:ve.comment,color:"#940"},{tag:ve.invalid,color:"#f00"}]);var aF=1e4,sF="()[]{}";var iF=new rt;function cg(t,e,n){let r=t.prop(e<0?rt.openedBy:rt.closedBy);if(r)return r;if(t.name.length==1){let a=n.indexOf(t.name);if(a>-1&&a%2==(e<0?1:0))return[n[a+e]]}return null}function dg(t){let e=t.type.prop(iF);return e?e(t.node):t}function _i(t,e,n,r={}){let a=r.maxScanDistance||aF,s=r.brackets||sF,i=ls(t),o=i.resolveInner(e,n);for(let l=o;l;l=l.parent){let u=cg(l.type,n,s);if(u&&l.from<l.to){let c=dg(l);if(c&&(n>0?e>=c.from&&e<c.to:e>c.from&&e<=c.to))return oF(t,e,n,l,c,u,s)}}return lF(t,e,n,i,o.type,a,s)}function oF(t,e,n,r,a,s,i){let o=r.parent,l={from:a.from,to:a.to},u=0,c=o?.cursor();if(c&&(n<0?c.childBefore(r.from):c.childAfter(r.to)))do if(n<0?c.to<=r.from:c.from>=r.to){if(u==0&&s.indexOf(c.type.name)>-1&&c.from<c.to){let d=dg(c);return{start:l,end:d?{from:d.from,to:d.to}:void 0,matched:!0}}else if(cg(c.type,n,i))u++;else if(cg(c.type,-n,i)){if(u==0){let d=dg(c);return{start:l,end:d&&d.from<d.to?{from:d.from,to:d.to}:void 0,matched:!1}}u--}}while(n<0?c.prevSibling():c.nextSibling());return{start:l,matched:!1}}function lF(t,e,n,r,a,s,i){if(n<0?!e:e==t.doc.length)return null;let o=n<0?t.sliceDoc(e-1,e):t.sliceDoc(e,e+1),l=i.indexOf(o);if(l<0||l%2==0!=n>0)return null;let u={from:n<0?e-1:e,to:n>0?e+1:e},c=t.doc.iterRange(e,n>0?t.doc.length:0),d=0;for(let f=0;!c.next().done&&f<=s;){let h=c.value;n<0&&(f+=h.length);let p=e+f*n;for(let g=n>0?0:h.length-1,m=n>0?h.length:-1;g!=m;g+=n){let x=i.indexOf(h[g]);if(!(x<0||r.resolveInner(p+g,1).type!=a))if(x%2==0==n>0)d++;else{if(d==1)return{start:u,end:{from:p+g,to:p+g+1},matched:x>>1==l>>1};d--}}n>0&&(f+=h.length)}return c.done?{start:u,matched:!1}:null}var uF=Object.create(null),sC=[Lr.none];var iC=[],oC=Object.create(null),cF=Object.create(null);for(let[t,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])cF[t]=dF(uF,e);function sg(t,e){iC.indexOf(t)>-1||(iC.push(t),console.warn(e))}function dF(t,e){let n=[];for(let o of e.split(" ")){let l=[];for(let u of o.split(".")){let c=t[u]||ve[u];c?typeof c=="function"?l.length?l=l.map(c):sg(u,`Modifier ${u} used at start of tag`):l.length?sg(u,`Tag ${u} used as modifier`):l=Array.isArray(c)?c:[c]:sg(u,`Unknown highlighting tag ${u}`)}for(let u of l)n.push(u)}if(!n.length)return 0;let r=e.replace(/ /g,"_"),a=r+" "+n.map(o=>o.id),s=oC[a];if(s)return s.id;let i=oC[a]=Lr.define({id:sC.length,name:r,props:[tC({[r]:n})]});return sC.push(i),i.id}var p6={rtl:Ke.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"rtl"},bidiIsolate:Vt.RTL}),ltr:Ke.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"ltr"},bidiIsolate:Vt.LTR}),auto:Ke.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"auto"},bidiIsolate:null})};var gn=class t{constructor(e,n,r,a){this.fromA=e,this.toA=n,this.fromB=r,this.toB=a}offset(e,n=e){return new t(this.fromA+e,this.toA+e,this.fromB+n,this.toB+n)}};function Ui(t,e,n,r,a,s){if(t==r)return[];let i=kg(t,e,n,r,a,s),o=Sg(t,e+i,n,r,a+i,s);e+=i,n-=o,a+=i,s-=o;let l=n-e,u=s-a;if(!l||!u)return[new gn(e,n,a,s)];if(l>u){let d=t.slice(e,n).indexOf(r.slice(a,s));if(d>-1)return[new gn(e,e+d,a,a),new gn(e+d+u,n,s,s)]}else if(u>l){let d=r.slice(a,s).indexOf(t.slice(e,n));if(d>-1)return[new gn(e,e,a,a+d),new gn(n,n,a+d+l,s)]}if(l==1||u==1)return[new gn(e,n,a,s)];let c=MC(t,e,n,r,a,s);if(c){let[d,f,h]=c;return Ui(t,e,d,r,a,f).concat(Ui(t,d+h,n,r,f+h,s))}return fF(t,e,n,r,a,s)}var Gu=1e9,Wu=0,vg=!1;function fF(t,e,n,r,a,s){let i=n-e,o=s-a;if(Gu<1e9&&Math.min(i,o)>Gu*16||Wu>0&&Date.now()>Wu)return Math.min(i,o)>Gu*64?[new gn(e,n,a,s)]:dC(t,e,n,r,a,s);let l=Math.ceil((i+o)/2);hg.reset(l),pg.reset(l);let u=(h,p)=>t.charCodeAt(e+h)==r.charCodeAt(a+p),c=(h,p)=>t.charCodeAt(n-h-1)==r.charCodeAt(s-p-1),d=(i-o)%2!=0?pg:null,f=d?null:hg;for(let h=0;h<l;h++){if(h>Gu||Wu>0&&!(h&63)&&Date.now()>Wu)return dC(t,e,n,r,a,s);let p=hg.advance(h,i,o,l,d,!1,u)||pg.advance(h,i,o,l,f,!0,c);if(p)return hF(t,e,n,e+p[0],r,a,s,a+p[1])}return[new gn(e,n,a,s)]}var uf=class{constructor(){this.vec=[]}reset(e){this.len=e<<1;for(let n=0;n<this.len;n++)this.vec[n]=-1;this.vec[e+1]=0,this.start=this.end=0}advance(e,n,r,a,s,i,o){for(let l=-e+this.start;l<=e-this.end;l+=2){let u=a+l,c=l==-e||l!=e&&this.vec[u-1]<this.vec[u+1]?this.vec[u+1]:this.vec[u-1]+1,d=c-l;for(;c<n&&d<r&&o(c,d);)c++,d++;if(this.vec[u]=c,c>n)this.end+=2;else if(d>r)this.start+=2;else if(s){let f=a+(n-r)-l;if(f>=0&&f<this.len&&s.vec[f]!=-1)if(i){let h=s.vec[f];if(h>=n-c)return[h,a+h-f]}else{let h=n-s.vec[f];if(c>=h)return[c,d]}}}return null}},hg=new uf,pg=new uf;function hF(t,e,n,r,a,s,i,o){let l=!1;return!Vo(t,r)&&++r==n&&(l=!0),!Vo(a,o)&&++o==i&&(l=!0),l?[new gn(e,n,s,i)]:Ui(t,e,r,a,s,o).concat(Ui(t,r,n,a,o,i))}function RC(t,e){let n=1,r=Math.min(t,e);for(;n<r;)n=n<<1;return n}function kg(t,e,n,r,a,s){if(e==n||e==s||t.charCodeAt(e)!=r.charCodeAt(a))return 0;let i=RC(n-e,s-a);for(let o=e,l=a;;){let u=o+i,c=l+i;if(u>n||c>s||t.slice(o,u)!=r.slice(l,c)){if(i==1)return o-e-(Vo(t,o)?0:1);i=i>>1}else{if(u==n||c==s)return u-e;o=u,l=c}}}function Sg(t,e,n,r,a,s){if(e==n||a==s||t.charCodeAt(n-1)!=r.charCodeAt(s-1))return 0;let i=RC(n-e,s-a);for(let o=n,l=s;;){let u=o-i,c=l-i;if(u<e||c<a||t.slice(u,o)!=r.slice(c,l)){if(i==1)return n-o-(Vo(t,o)?0:1);i=i>>1}else{if(u==e||c==a)return n-u;o=u,l=c}}}function mg(t,e,n,r,a,s,i,o){let l=r.slice(a,s),u=null;for(;;){if(u||i<o)return u;for(let c=e+i;;){Vo(t,c)||c++;let d=c+i;if(Vo(t,d)||(d+=d==c+1?1:-1),d>=n)break;let f=t.slice(c,d),h=-1;for(;(h=l.indexOf(f,h+1))!=-1;){let p=kg(t,d,n,r,a+h+f.length,s),g=Sg(t,e,c,r,a,a+h),m=f.length+p+g;(!u||u[2]<m)&&(u=[c-g,a+h-g,m])}c=d}if(o<0)return u;i=i>>1}}function MC(t,e,n,r,a,s){let i=n-e,o=s-a;if(i<o){let l=MC(r,a,s,t,e,n);return l&&[l[1],l[0],l[2]]}return i<4||o*2<i?null:mg(t,e,n,r,a,s,Math.floor(i/4),-1)}function dC(t,e,n,r,a,s){vg=!0;let i=n-e,o=s-a,l;if(i<o){let f=mg(r,a,s,t,e,n,Math.floor(i/6),50);l=f&&[f[1],f[0],f[2]]}else l=mg(t,e,n,r,a,s,Math.floor(o/6),50);if(!l)return[new gn(e,n,a,s)];let[u,c,d]=l;return Ui(t,e,u,r,a,c).concat(Ui(t,u+d,n,r,c+d,s))}function TC(t,e){for(let n=1;n<t.length;n++){let r=t[n-1],a=t[n];r.toA>a.fromA-e&&r.toB>a.fromB-e&&(t[n-1]=new gn(r.fromA,a.toA,r.fromB,a.toB),t.splice(n--,1))}}function pF(t,e,n){for(;;){TC(n,1);let r=!1;for(let a=0;a<n.length;a++){let s=n[a],i,o;(i=kg(t,s.fromA,s.toA,e,s.fromB,s.toB))&&(s=n[a]=new gn(s.fromA+i,s.toA,s.fromB+i,s.toB)),(o=Sg(t,s.fromA,s.toA,e,s.fromB,s.toB))&&(s=n[a]=new gn(s.fromA,s.toA-o,s.fromB,s.toB-o));let l=s.toA-s.fromA,u=s.toB-s.fromB;if(l&&u)continue;let c=s.fromA-(a?n[a-1].toA:0),d=(a<n.length-1?n[a+1].fromA:t.length)-s.toA;if(!c||!d)continue;let f=l?t.slice(s.fromA,s.toA):e.slice(s.fromB,s.toB);c<=f.length&&t.slice(s.fromA-c,s.fromA)==f.slice(f.length-c)?(n[a]=new gn(s.fromA-c,s.toA-c,s.fromB-c,s.toB-c),r=!0):d<=f.length&&t.slice(s.toA,s.toA+d)==f.slice(0,d)&&(n[a]=new gn(s.fromA+d,s.toA+d,s.fromB+d,s.toB+d),r=!0)}if(!r)break}return n}function mF(t,e,n){for(let r=0,a=0;a<t.length;a++){let s=t[a],i=s.toA-s.fromA,o=s.toB-s.fromB;if(i&&o||i>3||o>3){let l=a==t.length-1?e.length:t[a+1].fromA,u=s.fromA-r,c=l-s.toA,d=hC(e,s.fromA,u),f=fC(e,s.toA,c),h=s.fromA-d,p=f-s.toA;if((!i||!o)&&h&&p){let g=Math.max(i,o),[m,x,y]=i?[e,s.fromA,s.toA]:[n,s.fromB,s.toB];g>h&&e.slice(d,s.fromA)==m.slice(y-h,y)?(s=t[a]=new gn(d,d+i,s.fromB-h,s.toB-h),d=s.fromA,f=fC(e,s.toA,l-s.toA)):g>p&&e.slice(s.toA,f)==m.slice(x,x+p)&&(s=t[a]=new gn(f-i,f,s.fromB+p,s.toB+p),f=s.toA,d=hC(e,s.fromA,s.fromA-r)),h=s.fromA-d,p=f-s.toA}if(h||p)s=t[a]=new gn(s.fromA-h,s.toA+p,s.fromB-h,s.toB+p);else if(i){if(!o){let g=mC(e,s.fromA,s.toA),m,x=g<0?-1:pC(e,s.toA,s.fromA);g>-1&&(m=g-s.fromA)<=c&&e.slice(s.fromA,g)==e.slice(s.toA,s.toA+m)?s=t[a]=s.offset(m):x>-1&&(m=s.toA-x)<=u&&e.slice(s.fromA-m,s.fromA)==e.slice(x,s.toA)&&(s=t[a]=s.offset(-m))}}else{let g=mC(n,s.fromB,s.toB),m,x=g<0?-1:pC(n,s.toB,s.fromB);g>-1&&(m=g-s.fromB)<=c&&n.slice(s.fromB,g)==n.slice(s.toB,s.toB+m)?s=t[a]=s.offset(m):x>-1&&(m=s.toB-x)<=u&&n.slice(s.fromB-m,s.fromB)==n.slice(x,s.toB)&&(s=t[a]=s.offset(-m))}}r=s.toA}return TC(t,3),t}var Hi;try{Hi=new RegExp("[\\p{Alphabetic}\\p{Number}]","u")}catch{}function DC(t){return t>48&&t<58||t>64&&t<91||t>96&&t<123}function FC(t,e){if(e==t.length)return 0;let n=t.charCodeAt(e);return n<192?DC(n)?1:0:Hi?!BC(n)||e==t.length-1?Hi.test(String.fromCharCode(n))?1:0:Hi.test(t.slice(e,e+2))?2:0:0}function EC(t,e){if(!e)return 0;let n=t.charCodeAt(e-1);return n<192?DC(n)?1:0:Hi?!_C(n)||e==1?Hi.test(String.fromCharCode(n))?1:0:Hi.test(t.slice(e-2,e))?2:0:0}var OC=8;function fC(t,e,n){if(e==t.length||!EC(t,e))return e;for(let r=e,a=e+n,s=0;s<OC;s++){let i=FC(t,r);if(!i||r+i>a)return r;r+=i}return e}function hC(t,e,n){if(!e||!FC(t,e))return e;for(let r=e,a=e-n,s=0;s<OC;s++){let i=EC(t,r);if(!i||r-i<a)return r;r-=i}return e}function pC(t,e,n){for(;e!=n;e--)if(t.charCodeAt(e-1)==10)return e;return-1}function mC(t,e,n){for(;e!=n;e++)if(t.charCodeAt(e)==10)return e;return-1}var BC=t=>t>=55296&&t<=56319,_C=t=>t>=56320&&t<=57343;function Vo(t,e){return!e||e==t.length||!BC(t.charCodeAt(e-1))||!_C(t.charCodeAt(e))}function gF(t,e,n){var r;let a=n?.override;return a?a(t,e):(Gu=((r=n?.scanLimit)!==null&&r!==void 0?r:1e9)>>1,Wu=n?.timeout?Date.now()+n.timeout:0,vg=!1,pF(t,e,Ui(t,0,t.length,e,0,e.length)))}function HC(){return!vg}function UC(t,e,n){return mF(gF(t,e,n),t,e)}var pr=Me.define({combine:t=>t[0]}),gg=pt.define(),GC=Me.define(),nr=vn.define({create(t){return null},update(t,e){for(let n of e.effects)n.is(gg)&&(t=n.value);for(let n of e.state.facet(GC))t=n(t,e);return t}});var us=class t{constructor(e,n,r,a,s,i=!0){this.changes=e,this.fromA=n,this.toA=r,this.fromB=a,this.toB=s,this.precise=i}offset(e,n){return e||n?new t(this.changes,this.fromA+e,this.toA+e,this.fromB+n,this.toB+n,this.precise):this}get endA(){return Math.max(this.fromA,this.toA-1)}get endB(){return Math.max(this.fromB,this.toB-1)}static build(e,n,r){let a=UC(e.toString(),n.toString(),r);return WC(a,e,n,0,0,HC())}static updateA(e,n,r,a,s){return wC(bC(e,a,!0,r.length),e,n,r,s)}static updateB(e,n,r,a,s){return wC(bC(e,a,!1,n.length),e,n,r,s)}};function gC(t,e,n,r){let a=n.lineAt(t),s=r.lineAt(e);return a.to==t&&s.to==e&&t<n.length&&e<r.length?[t+1,e+1]:[a.from,s.from]}function xC(t,e,n,r){let a=n.lineAt(t),s=r.lineAt(e);return a.from==t&&s.from==e?[t,e]:[a.to+1,s.to+1]}function WC(t,e,n,r,a,s){let i=[];for(let o=0;o<t.length;o++){let l=t[o],[u,c]=gC(l.fromA+r,l.fromB+a,e,n),[d,f]=xC(l.toA+r,l.toB+a,e,n),h=[l.offset(-u+r,-c+a)];for(;o<t.length-1;){let p=t[o+1],[g,m]=gC(p.fromA+r,p.fromB+a,e,n);if(g>d+1&&m>f+1)break;h.push(p.offset(-u+r,-c+a)),[d,f]=xC(p.toA+r,p.toB+a,e,n),o++}i.push(new us(h,u,Math.max(u,d),c,Math.max(c,f),s))}return i}var af=1e3;function yC(t,e,n,r){let a=0,s=t.length;for(;;){if(a==s){let c=0,d=0;a&&({toA:c,toB:d}=t[a-1]);let f=e-(n?c:d);return[c+f,d+f]}let i=a+s>>1,o=t[i],[l,u]=n?[o.fromA,o.toA]:[o.fromB,o.toB];if(l>e)s=i;else if(u<=e)a=i+1;else return r?[o.fromA,o.fromB]:[o.toA,o.toB]}}function bC(t,e,n,r){let a=[];return e.iterChangedRanges((s,i,o,l)=>{let u=0,c=n?e.length:r,d=0,f=n?r:e.length;s>af&&([u,d]=yC(t,s-af,n,!0)),i<e.length-af&&([c,f]=yC(t,i+af,n,!1));let h=l-o-(i-s),p,[g,m]=n?[h,0]:[0,h];a.length&&(p=a[a.length-1]).toA>=u?a[a.length-1]={fromA:p.fromA,fromB:p.fromB,toA:c,toB:f,diffA:p.diffA+g,diffB:p.diffB+m}:a.push({fromA:u,toA:c,fromB:d,toB:f,diffA:g,diffB:m})}),a}function wC(t,e,n,r,a){if(!t.length)return e;let s=[];for(let i=0,o=0,l=0,u=0;;i++){let c=i==t.length?null:t[i],d=c?c.fromA+o:n.length,f=c?c.fromB+l:r.length;for(;u<e.length;){let m=e[u];if(c&&(m.toA+o>d||m.toB+l>f))break;s.push(m.offset(o,l)),u++}if(!c)break;let h=c.toA+o+c.diffA,p=c.toB+l+c.diffB,g=UC(n.sliceString(d,h),r.sliceString(f,p),a);for(let m of WC(g,n,r,d,f,HC()))s.push(m);for(o+=c.diffA,l+=c.diffB;u<e.length;){let m=e[u];if(m.fromA+o>h&&m.fromB+l>p)break;u++}}return s}var zC={scanLimit:500},hf=hr.fromClass(class{constructor(t){({deco:this.deco,gutter:this.gutter}=SC(t))}update(t){(t.docChanged||t.viewportChanged||xF(t.startState,t.state)||yF(t.startState,t.state))&&({deco:this.deco,gutter:this.gutter}=SC(t.view))}},{decorations:t=>t.deco}),sf=Ma.low(zo({class:"cm-changeGutter",markers:t=>{var e;return((e=t.plugin(hf))===null||e===void 0?void 0:e.gutter)||wt.empty}}));function xF(t,e){return t.field(nr,!1)!=e.field(nr,!1)}function yF(t,e){return t.facet(pr)!=e.facet(pr)}var vC=Ke.line({class:"cm-changedLine"}),jC=Ke.mark({class:"cm-changedText"}),bF=Ke.mark({tagName:"ins",class:"cm-insertedLine"}),wF=Ke.mark({tagName:"del",class:"cm-deletedLine"}),kC=new class extends Bn{constructor(){super(...arguments),this.elementClass="cm-changedLineGutter"}};function vF(t,e,n,r,a,s){let i=n?t.fromA:t.fromB,o=n?t.toA:t.toB,l=0;if(i!=o){a.add(i,i,vC),a.add(i,o,n?wF:bF),s&&s.add(i,i,kC);for(let u=e.iterRange(i,o-1),c=i;!u.next().done;){if(u.lineBreak){c++,a.add(c,c,vC),s&&s.add(c,c,kC);continue}let d=c+u.value.length;if(r)for(;l<t.changes.length;){let f=t.changes[l],h=i+(n?f.fromA:f.fromB),p=i+(n?f.toA:f.toB),g=Math.max(c,h),m=Math.min(d,p);if(g<m&&a.add(g,m,jC),p<d)l++;else break}c=d}}}function SC(t){let e=t.state.field(nr),{side:n,highlightChanges:r,markGutter:a,overrideChunk:s}=t.state.facet(pr),i=n=="a",o=new qn,l=a?new qn:null,{from:u,to:c}=t.viewport;for(let d of e){if((i?d.fromA:d.fromB)>=c)break;(i?d.toA:d.toB)>u&&(!s||!s(t.state,d,o,l))&&vF(d,t.state.doc,i,r,o,l)}return{deco:o.finish(),gutter:l&&l.finish()}}var jo=class extends Ir{constructor(e){super(),this.height=e}eq(e){return this.height==e.height}toDOM(){let e=document.createElement("div");return e.className="cm-mergeSpacer",e.style.height=this.height+"px",e}updateDOM(e){return e.style.height=this.height+"px",!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}},cf=pt.define({map:(t,e)=>t.map(e)}),zu=vn.define({create:()=>Ke.none,update:(t,e)=>{for(let n of e.effects)if(n.is(cf))return n.value;return t.map(e.changes)},provide:t=>Pe.decorations.from(t)}),of=.01;function CC(t,e){if(t.size!=e.size)return!1;let n=t.iter(),r=e.iter();for(;n.value;){if(n.from!=r.from||Math.abs(n.value.spec.widget.height-r.value.spec.widget.height)>1)return!1;n.next(),r.next()}return!0}function kF(t,e,n){let r=new qn,a=new qn,s=t.state.field(zu).iter(),i=e.state.field(zu).iter(),o=0,l=0,u=0,c=0,d=t.viewport,f=e.viewport;for(let m=0;;m++){let x=m<n.length?n[m]:null,y=x?x.fromA:t.state.doc.length,b=x?x.fromB:e.state.doc.length;if(o<y){let C=t.lineBlockAt(o).top+u,L=e.lineBlockAt(l).top+c,P=C-L;P<-of?(u-=P,r.add(o,o,Ke.widget({widget:new jo(-P),block:!0,side:-1}))):P>of&&(c+=P,a.add(l,l,Ke.widget({widget:new jo(P),block:!0,side:-1})))}if(y>o+1e3&&o<d.from&&y>d.from&&l<f.from&&b>f.from){let C=Math.min(d.from-o,f.from-l);o+=C,l+=C,m--}else if(x)o=x.toA,l=x.toB;else break;for(;s.value&&s.from<o;)u-=s.value.spec.widget.height,s.next();for(;i.value&&i.from<l;)c-=i.value.spec.widget.height,i.next()}for(;s.value;)u-=s.value.spec.widget.height,s.next();for(;i.value;)c-=i.value.spec.widget.height,i.next();let h=t.contentHeight+u-(e.contentHeight+c);h<of?r.add(t.state.doc.length,t.state.doc.length,Ke.widget({widget:new jo(-h),block:!0,side:1})):h>of&&a.add(e.state.doc.length,e.state.doc.length,Ke.widget({widget:new jo(h),block:!0,side:1}));let p=r.finish(),g=a.finish();CC(p,t.state.field(zu))||t.dispatch({effects:cf.of(p)}),CC(g,e.state.field(zu))||e.dispatch({effects:cf.of(g)})}var xg=pt.define({map:(t,e)=>e.mapPos(t)});var yg=class extends Ir{constructor(e){super(),this.lines=e}eq(e){return this.lines==e.lines}toDOM(e){let n=document.createElement("div");return n.className="cm-collapsedLines",n.textContent=e.state.phrase("$ unchanged lines",this.lines),n.addEventListener("click",r=>{let a=e.posAtDOM(r.target);e.dispatch({effects:xg.of(a)});let{side:s,sibling:i}=e.state.facet(pr);i&&i().dispatch({effects:xg.of(SF(a,e.state.field(nr),s=="a"))})}),n}ignoreEvent(e){return e instanceof MouseEvent}get estimatedHeight(){return 27}get type(){return"collapsed-unchanged-code"}};function SF(t,e,n){let r=0,a=0;for(let s=0;;s++){let i=s<e.length?e[s]:null;if(!i||(n?i.fromA:i.fromB)>=t)return a+(t-r);[r,a]=n?[i.toA,i.toB]:[i.toB,i.toA]}}var CF=vn.define({create(t){return Ke.none},update(t,e){t=t.map(e.changes);for(let n of e.effects)n.is(xg)&&(t=t.update({filter:r=>r!=n.value}));if(t.size&&e.state.field(nr)!=e.startState.field(nr,!1)){let n=e.state.facet(pr).side=="a",r=[];for(let a of e.state.field(nr))t.between(n?a.fromA:a.fromB,n?a.toA:a.toB,s=>{r.push(s)});r.length&&(t=t.update({filter:a=>r.indexOf(a)<0}))}return t},provide:t=>Pe.decorations.from(t)});function bg({margin:t=3,minSize:e=4}){return CF.init(n=>IF(n,t,e))}function IF(t,e,n){let r=new qn,a=t.facet(pr).side=="a",s=t.field(nr),i=1;for(let o=0;;o++){let l=o<s.length?s[o]:null,u=o?i+e:1,c=l?t.doc.lineAt(a?l.fromA:l.fromB).number-1-e:t.doc.lines,d=c-u+1;if(d>=n&&r.add(t.doc.line(u).from,t.doc.line(c).to,Ke.replace({widget:new yg(d),block:!0})),!l)break;i=t.doc.lineAt(Math.min(t.doc.length,a?l.toA:l.toB)).number}return r.finish()}var LF=Pe.styleModule.of(new dr({".cm-mergeView":{overflowY:"auto"},".cm-mergeViewEditors":{display:"flex",alignItems:"stretch"},".cm-mergeViewEditor":{flexGrow:1,flexBasis:0,overflow:"hidden"},".cm-merge-revert":{width:"1.6em",flexGrow:0,flexShrink:0,position:"relative"},".cm-merge-revert button":{position:"absolute",display:"block",width:"100%",boxSizing:"border-box",textAlign:"center",background:"none",border:"none",font:"inherit",cursor:"pointer"}})),VC=Pe.baseTheme({".cm-mergeView & .cm-scroller, .cm-mergeView &":{height:"auto !important",overflowY:"visible !important"},"&.cm-merge-a .cm-changedLine, .cm-deletedChunk":{backgroundColor:"rgba(160, 128, 100, .08)"},"&.cm-merge-b .cm-changedLine, .cm-inlineChangedLine":{backgroundColor:"rgba(100, 160, 128, .08)"},"&light.cm-merge-a .cm-changedText, &light .cm-deletedChunk .cm-deletedText":{background:"linear-gradient(#ee443366, #ee443366) bottom/100% 2px no-repeat"},"&dark.cm-merge-a .cm-changedText, &dark .cm-deletedChunk .cm-deletedText":{background:"linear-gradient(#ffaa9966, #ffaa9966) bottom/100% 2px no-repeat"},"&light.cm-merge-b .cm-changedText":{background:"linear-gradient(#22bb22aa, #22bb22aa) bottom/100% 2px no-repeat"},"&dark.cm-merge-b .cm-changedText":{background:"linear-gradient(#88ff88aa, #88ff88aa) bottom/100% 2px no-repeat"},"&.cm-merge-b .cm-deletedText":{background:"#ff000033"},".cm-insertedLine, .cm-deletedLine, .cm-deletedLine del":{textDecoration:"none"},".cm-deletedChunk":{paddingLeft:"6px","& .cm-chunkButtons":{position:"absolute",insetInlineEnd:"5px"},"& button":{border:"none",cursor:"pointer",color:"white",margin:"0 2px",borderRadius:"3px","&[name=accept]":{background:"#2a2"},"&[name=reject]":{background:"#d43"}}},".cm-collapsedLines":{padding:"5px 5px 5px 10px",cursor:"pointer","&:before":{content:'"\u299A"',marginInlineEnd:"7px"},"&:after":{content:'"\u299A"',marginInlineStart:"7px"}},"&light .cm-collapsedLines":{color:"#444",background:"linear-gradient(to bottom, transparent 0, #f3f3f3 30%, #f3f3f3 70%, transparent 100%)"},"&dark .cm-collapsedLines":{color:"#ddd",background:"linear-gradient(to bottom, transparent 0, #222 30%, #222 70%, transparent 100%)"},".cm-changeGutter":{width:"3px",paddingLeft:"1px"},"&light.cm-merge-a .cm-changedLineGutter, &light .cm-deletedLineGutter":{background:"#e43"},"&dark.cm-merge-a .cm-changedLineGutter, &dark .cm-deletedLineGutter":{background:"#fa9"},"&light.cm-merge-b .cm-changedLineGutter":{background:"#2b2"},"&dark.cm-merge-b .cm-changedLineGutter":{background:"#8f8"},".cm-inlineChangedLineGutter":{background:"#75d"}}),IC=new _r,lf=new _r,df=class{constructor(e){this.revertDOM=null,this.revertToA=!1,this.revertToLeft=!1,this.measuring=-1,this.diffConf=e.diffConfig||zC;let n=[Ma.low(hf),VC,LF,zu,Pe.updateListener.of(d=>{this.measuring<0&&(d.heightChanged||d.viewportChanged)&&!d.transactions.some(f=>f.effects.some(h=>h.is(cf)))&&this.measure()})],r=[pr.of({side:"a",sibling:()=>this.b,highlightChanges:e.highlightChanges!==!1,markGutter:e.gutter!==!1})];e.gutter!==!1&&r.push(sf);let a=It.create({doc:e.a.doc,selection:e.a.selection,extensions:[e.a.extensions||[],Pe.editorAttributes.of({class:"cm-merge-a"}),lf.of(r),n]}),s=[pr.of({side:"b",sibling:()=>this.a,highlightChanges:e.highlightChanges!==!1,markGutter:e.gutter!==!1})];e.gutter!==!1&&s.push(sf);let i=It.create({doc:e.b.doc,selection:e.b.selection,extensions:[e.b.extensions||[],Pe.editorAttributes.of({class:"cm-merge-b"}),lf.of(s),n]});this.chunks=us.build(a.doc,i.doc,this.diffConf);let o=[nr.init(()=>this.chunks),IC.of(e.collapseUnchanged?bg(e.collapseUnchanged):[])];a=a.update({effects:pt.appendConfig.of(o)}).state,i=i.update({effects:pt.appendConfig.of(o)}).state,this.dom=document.createElement("div"),this.dom.className="cm-mergeView",this.editorDOM=this.dom.appendChild(document.createElement("div")),this.editorDOM.className="cm-mergeViewEditors";let l=e.orientation||"a-b",u=document.createElement("div");u.className="cm-mergeViewEditor";let c=document.createElement("div");c.className="cm-mergeViewEditor",this.editorDOM.appendChild(l=="a-b"?u:c),this.editorDOM.appendChild(l=="a-b"?c:u),this.a=new Pe({state:a,parent:u,root:e.root,dispatchTransactions:d=>this.dispatch(d,this.a)}),this.b=new Pe({state:i,parent:c,root:e.root,dispatchTransactions:d=>this.dispatch(d,this.b)}),this.setupRevertControls(!!e.revertControls,e.revertControls=="b-to-a",e.renderRevertControl),e.parent&&e.parent.appendChild(this.dom),this.scheduleMeasure()}dispatch(e,n){if(e.some(r=>r.docChanged)){let r=e[e.length-1],a=e.reduce((i,o)=>i.compose(o.changes),Nn.empty(e[0].startState.doc.length));this.chunks=n==this.a?us.updateA(this.chunks,r.newDoc,this.b.state.doc,a,this.diffConf):us.updateB(this.chunks,this.a.state.doc,r.newDoc,a,this.diffConf),n.update([...e,r.state.update({effects:gg.of(this.chunks)})]);let s=n==this.a?this.b:this.a;s.update([s.state.update({effects:gg.of(this.chunks)})]),this.scheduleMeasure()}else n.update(e)}reconfigure(e){if("diffConfig"in e&&(this.diffConf=e.diffConfig),"orientation"in e){let s=e.orientation!="b-a";if(s!=(this.editorDOM.firstChild==this.a.dom.parentNode)){let i=this.a.dom.parentNode,o=this.b.dom.parentNode;i.remove(),o.remove(),this.editorDOM.insertBefore(s?i:o,this.editorDOM.firstChild),this.editorDOM.appendChild(s?o:i),this.revertToLeft=!this.revertToLeft,this.revertDOM&&(this.revertDOM.textContent="")}}if("revertControls"in e||"renderRevertControl"in e){let s=!!this.revertDOM,i=this.revertToA,o=this.renderRevert;"revertControls"in e&&(s=!!e.revertControls,i=e.revertControls=="b-to-a"),"renderRevertControl"in e&&(o=e.renderRevertControl),this.setupRevertControls(s,i,o)}let n="highlightChanges"in e,r="gutter"in e,a="collapseUnchanged"in e;if(n||r||a){let s=[],i=[];if(n||r){let o=this.a.state.facet(pr),l=r?e.gutter!==!1:o.markGutter,u=n?e.highlightChanges!==!1:o.highlightChanges;s.push(lf.reconfigure([pr.of({side:"a",sibling:()=>this.b,highlightChanges:u,markGutter:l}),l?sf:[]])),i.push(lf.reconfigure([pr.of({side:"b",sibling:()=>this.a,highlightChanges:u,markGutter:l}),l?sf:[]]))}if(a){let o=IC.reconfigure(e.collapseUnchanged?bg(e.collapseUnchanged):[]);s.push(o),i.push(o)}this.a.dispatch({effects:s}),this.b.dispatch({effects:i})}this.scheduleMeasure()}setupRevertControls(e,n,r){this.revertToA=n,this.revertToLeft=this.revertToA==(this.editorDOM.firstChild==this.a.dom.parentNode),this.renderRevert=r,!e&&this.revertDOM?(this.revertDOM.remove(),this.revertDOM=null):e&&!this.revertDOM?(this.revertDOM=this.editorDOM.insertBefore(document.createElement("div"),this.editorDOM.firstChild.nextSibling),this.revertDOM.addEventListener("mousedown",a=>this.revertClicked(a)),this.revertDOM.className="cm-merge-revert"):this.revertDOM&&(this.revertDOM.textContent="")}scheduleMeasure(){if(this.measuring<0){let e=this.dom.ownerDocument.defaultView||window;this.measuring=e.requestAnimationFrame(()=>{this.measuring=-1,this.measure()})}}measure(){kF(this.a,this.b,this.chunks),this.revertDOM&&this.updateRevertButtons()}updateRevertButtons(){let e=this.revertDOM,n=e.firstChild,r=this.a.viewport,a=this.b.viewport;for(let s=0;s<this.chunks.length;s++){let i=this.chunks[s];if(i.fromA>r.to||i.fromB>a.to)break;if(i.fromA<r.from||i.fromB<a.from)continue;let o=this.a.lineBlockAt(i.fromA).top+"px";for(;n&&+n.dataset.chunk<s;)n=LC(n);n&&n.dataset.chunk==String(s)?(n.style.top!=o&&(n.style.top=o),n=n.nextSibling):e.insertBefore(this.renderRevertButton(o,s),n)}for(;n;)n=LC(n)}renderRevertButton(e,n){let r;if(this.renderRevert)r=this.renderRevert();else{r=document.createElement("button");let a=this.a.state.phrase("Revert this chunk");r.setAttribute("aria-label",a),r.setAttribute("title",a),r.textContent=this.revertToLeft?"\u21DC":"\u21DD"}return r.style.top=e,r.setAttribute("data-chunk",String(n)),r}revertClicked(e){let n=e.target,r;for(;n&&n.parentNode!=this.revertDOM;)n=n.parentNode;if(n&&(r=this.chunks[n.dataset.chunk])){let[a,s,i,o,l,u]=this.revertToA?[this.b,this.a,r.fromB,r.toB,r.fromA,r.toA]:[this.a,this.b,r.fromA,r.toA,r.fromB,r.toB],c=a.state.sliceDoc(i,Math.max(i,o-1));i!=o&&u<=s.state.doc.length&&(c+=a.state.lineBreak),s.dispatch({changes:{from:l,to:Math.min(s.state.doc.length,u),insert:c},userEvent:"revert"}),e.preventDefault()}}destroy(){this.a.destroy(),this.b.destroy(),this.measuring>-1&&(this.dom.ownerDocument.defaultView||window).cancelAnimationFrame(this.measuring),this.dom.remove()}};function LC(t){let e=t.nextSibling;return t.remove(),e}var AF=new class extends Bn{constructor(){super(...arguments),this.elementClass="cm-deletedLineGutter"}},PF=Ma.low(zo({class:"cm-changeGutter",markers:t=>{var e;return((e=t.plugin(hf))===null||e===void 0?void 0:e.gutter)||wt.empty},widgetMarker:(t,e)=>e instanceof ff?AF:null}));function qC(t){var e;let n=typeof t.original=="string"?st.of(t.original.split(/\r?\n/)):t.original,r=t.diffConfig||zC;return[Ma.low(hf),TF,VC,Pe.editorAttributes.of({class:"cm-merge-b"}),GC.of((a,s)=>{let i=s.effects.find(o=>o.is(Cg));return i&&(a=us.updateA(a,i.value.doc,s.startState.doc,i.value.changes,r)),s.docChanged&&(a=us.updateB(a,s.state.field(qo),s.newDoc,s.changes,r)),a}),pr.of({highlightChanges:t.highlightChanges!==!1,markGutter:t.gutter!==!1,syntaxHighlightDeletions:t.syntaxHighlightDeletions!==!1,syntaxHighlightDeletionsMaxLength:3e3,mergeControls:(e=t.mergeControls)!==null&&e!==void 0?e:!0,overrideChunk:t.allowInlineDiffs?EF:void 0,side:"b"}),qo.init(()=>n),t.gutter!==!1?PF:[],t.collapseUnchanged?bg(t.collapseUnchanged):[],nr.init(a=>us.build(n,a.doc,r))]}var Cg=pt.define();var qo=vn.define({create:()=>st.empty,update(t,e){for(let n of e.effects)n.is(Cg)&&(t=n.value.doc);return t}});var AC=new WeakMap,ff=class extends Ir{constructor(e){super(),this.buildDOM=e,this.dom=null}eq(e){return this.dom==e.dom}toDOM(e){return this.dom||(this.dom=this.buildDOM(e))}};function NF(t,e,n){let r=AC.get(e.changes);if(r)return r;let a=i=>{let{highlightChanges:o,syntaxHighlightDeletions:l,syntaxHighlightDeletionsMaxLength:u,mergeControls:c}=t.facet(pr),d=document.createElement("div");if(d.className="cm-deletedChunk",c){let C=d.appendChild(document.createElement("div"));C.className="cm-chunkButtons";let L=w=>{w.preventDefault(),RF(i,i.posAtDOM(d))},P=w=>{w.preventDefault(),MF(i,i.posAtDOM(d))};if(typeof c=="function")C.appendChild(c("accept",L)),C.appendChild(c("reject",P));else{let w=C.appendChild(document.createElement("button"));w.name="accept",w.textContent=t.phrase("Accept"),w.onmousedown=L;let k=C.appendChild(document.createElement("button"));k.name="reject",k.textContent=t.phrase("Reject"),k.onmousedown=P}}if(n||e.fromA>=e.toA)return d;let f=i.state.field(qo).sliceString(e.fromA,e.endA),h=l&&t.facet($s),p=y(),g=e.changes,m=0,x=!1;function y(){let C=d.appendChild(document.createElement("div"));return C.className="cm-deletedLine",C.appendChild(document.createElement("del"))}function b(C,L,P){for(let w=C;w<L;){if(f.charAt(w)==`
|
|
42
|
-
`){p.firstChild||p.appendChild(document.createElement("br")),p=
|
|
43
|
-
`,w);if(R>-1&&R<L&&(k=R),o&&m<g.length){let U=Math.max(0,x?g[m].toA:g[m].fromA);U<=k&&(k=U,x&&m++,M=!0)}if(k>w){let U=document.createTextNode(f.slice(w,k));if(_){let v=p.appendChild(document.createElement("span"));v.className=_,v.appendChild(U)}else p.appendChild(U);w=k}M&&(x=!x)}}if(h&&e.toA-e.fromA<=u){let C=h.parser.parse(f),L=0;ng(C,{style:P=>cC(t,P)},(P,w,k)=>{P>L&&b(L,P,""),b(P,w,k),L=w}),b(L,f.length,"")}else b(0,f.length,"");return p.firstChild||p.appendChild(document.createElement("br")),d},s=Ke.widget({block:!0,side:-1,widget:new ff(a)});return AC.set(e.changes,s),s}function RF(t,e){let{state:n}=t,r=e??n.selection.main.head,a=t.state.field(nr).find(l=>l.fromB<=r&&l.endB>=r);if(!a)return!1;let s=t.state.sliceDoc(a.fromB,Math.max(a.fromB,a.toB-1)),i=t.state.field(qo);a.fromB!=a.toB&&a.toA<=i.length&&(s+=t.state.lineBreak);let o=Nn.of({from:a.fromA,to:Math.min(i.length,a.toA),insert:s},i.length);return t.dispatch({effects:Cg.of({doc:o.apply(i),changes:o}),userEvent:"accept"}),!0}function MF(t,e){let{state:n}=t,r=e??n.selection.main.head,a=n.field(nr).find(o=>o.fromB<=r&&o.endB>=r);if(!a)return!1;let i=n.field(qo).sliceString(a.fromA,Math.max(a.fromA,a.toA-1));return a.fromA!=a.toA&&a.toB<=n.doc.length&&(i+=n.lineBreak),t.dispatch({changes:{from:a.fromB,to:Math.min(n.doc.length,a.toB),insert:i},userEvent:"revert"}),!0}function PC(t){let e=new qn;for(let n of t.field(nr)){let r=t.facet(pr).overrideChunk&&$C(t,n);e.add(n.fromB,n.fromB,NF(t,n,!!r))}return e.finish()}var TF=vn.define({create:t=>PC(t),update(t,e){return e.state.field(nr,!1)!=e.startState.field(nr,!1)?PC(e.state):t},provide:t=>Pe.decorations.from(t)}),NC=new WeakMap;function $C(t,e){let n=NC.get(e);if(n!==void 0)return n;n=null;let r=t.field(qo),a=t.doc,s=r.lineAt(e.endA).number-r.lineAt(e.fromA).number+1,i=a.lineAt(e.endB).number-a.lineAt(e.fromB).number+1;e:if(s==i&&s<10){let o=[],l=0,u=e.fromA,c=e.fromB;for(let d of e.changes){if(d.fromA<d.toA){l+=d.toA-d.fromA;let f=r.sliceString(u+d.fromA,u+d.toA);if(/\n/.test(f))break e;o.push(Ke.widget({widget:new wg(f),side:-1}).range(c+d.fromB))}d.fromB<d.toB&&o.push(jC.range(c+d.fromB,c+d.toB))}l<e.endA-e.fromA-s*2&&(n=o)}return NC.set(e,n),n}var wg=class extends Ir{constructor(e){super(),this.text=e}eq(e){return this.text==e.text}toDOM(e){let n=document.createElement("del");return n.className="cm-deletedText",n.textContent=this.text,n}},DF=new class extends Bn{constructor(){super(...arguments),this.elementClass="cm-inlineChangedLineGutter"}},FF=Ke.line({class:"cm-inlineChangedLine"});function EF(t,e,n,r){let a=$C(t,e),s=0;if(!a)return!1;for(let i=t.doc.lineAt(e.fromB);;){for(r&&r.add(i.from,i.from,DF),n.add(i.from,i.from,FF);s<a.length&&a[s].to<=i.to;){let o=a[s++];n.add(o.from,o.to,o.value)}if(i.to>=e.endB)break;i=t.doc.lineAt(i.to+1)}return!0}function KC(t,e){if(!t||!e)return!1;let n=t.getInternalStack(),r=e.getInternalStack();return!n||!r?!1:n.equals(r)}function OF(t,e){return{from:t,to:e,lines:null,startState:null,endState:null,final:!1,stateKnown:!1,lastUsed:0}}var pf=class{constructor(e,n,r,a,s=64,i=4096){this.hl=e;this.lang=n;this.theme=r;this.targetLines=s;this.targetChars=i;this.chunks=[];this.tick=0;this.warned=!1;this.layoutDirty=!0;this.layout(a)}pieces(e,n,r){let a=[],s=n;for(;s<=r;){let i=e.line(s),o=i,l=1,u=i.length;for(;s+l<=r&&l<this.targetLines;){let c=e.line(s+l);if(u+1+c.length>this.targetChars)break;o=c,u+=1+c.length,l+=1}a.push(OF(i.from,o.to)),s+=l}return a}layout(e){this.chunks.length=0,this.chunks.push(...this.pieces(e,1,e.lines))}chunkIndexAt(e){let n=0,r=this.chunks.length-1;for(;n<r;){let a=n+r+1>>1;this.chunks[a].from<=e?n=a:r=a-1}return n}firstLineOf(e,n){return e.lineAt(n.from).number}tokensAt(e,n){return e.lines?.[n]??null}tokensForLine(e,n){let r=e.line(n),a=this.chunks[this.chunkIndexAt(r.from)];return{chunk:a,tokens:this.tokensAt(a,n-this.firstLineOf(e,a))}}lineCountOf(e,n){return e.lineAt(n.to).number-e.lineAt(n.from).number+1}hasPendingWork(e,n){let r=this.firstNonFinal(0);return r>=0&&r<=n||this.rebalanceTarget(e)!==null}firstNonFinal(e){for(let n=Math.max(0,e);n<this.chunks.length;n++)if(!this.chunks[n].final)return n;return-1}tokenize(e,n,r=!0){let a=this.chunks[n],s=n>0?this.chunks[n-1]:null,i=s?.endState??null,o=n===0||!!(s&&s.final&&s.stateKnown),l=e.sliceString(a.from,a.to),u=a.endState,c,d;try{let f=this.hl.codeToTokensBase(l,{lang:this.lang,theme:this.theme,includeExplanation:!1,tokenizeMaxLineLength:2e4,...i?{grammarState:i}:{}});d=this.hl.getLastGrammarState(f)??null,c=f}catch(f){this.warned||(this.warned=!0,console.warn("[Filesystem] shiki chunk tokenization failed",this.lang,f)),c=[],d=null}return a.lines=c,a.startState=i,a.endState=d,a.final=o,a.stateKnown=!0,r&&(a.lastUsed=++this.tick),this.trimWindow(),o&&KC(u,d)}ensureRange(e,n,r,a=16384){let s=!1,i=0,o=this.chunkIndexAt(n),l=Math.min(this.chunks.length-1,this.chunkIndexAt(r)+1);for(let u=o;u<=l;u++){let c=this.chunks[u];if(c.lines){c.lastUsed=++this.tick;continue}if(s&&i+(c.to-c.from)>a)break;this.tokenize(e,u,!0),i+=c.to-c.from,s=!0}return s}idleStep(e,n,r,a=()=>performance.now()){let s=a(),i=null,o=u=>{i=i?{from:Math.min(i.from,u.from),to:Math.max(i.to,u.to)}:{from:u.from,to:u.to}};this.rebalanceOnce(e);let l=this.firstNonFinal(0);for(;l>=0&&l<this.chunks.length&&l<=r;){let u=this.tokenize(e,l,!1);if(o(this.chunks[l]),u){let c=l+1;for(;c<this.chunks.length;c++){let d=this.chunks[c];if(!d.final)if(d.startState&&KC(d.startState,this.chunks[c-1].endState))d.final=!0;else break}l=this.firstNonFinal(c)}else{if(l+1<this.chunks.length&&(this.chunks[l+1].final=!1),l>=r)for(let c=l+2;c<this.chunks.length;c++)this.chunks[c].final=!1;l+=1}if(a()-s>=n)break}return{more:this.hasPendingWork(e,r),touched:i}}applyChanges(e,n){let r=new Set;if(e.iterChangedRanges((o,l)=>{let u=this.chunkIndexAt(o);for(;u<this.chunks.length&&this.chunks[u].from<=l;)r.add(this.chunks[u]),u++}),n.length===0){this.layout(n);return}let a=[],s=0;for(let o=0;o<this.chunks.length;o++){let l=this.chunks[o],u=e.mapPos(l.to,1);if(u>n.length&&(u=n.length),u=n.lineAt(u).to,u<s){let c=a[a.length-1];c&&r.add(c);continue}l.from=s,l.to=u,a.push(l),s=u+1}let i=a[a.length-1];i&&i.to<n.length&&(i.to=n.length,r.add(i));for(let o of r)o.lines=null,o.startState=null,o.final=!1,o.stateKnown=!1;this.chunks.length=0,this.chunks.push(...a),this.layoutDirty=!0,this.splitOversized(n,r)}splitOversized(e,n){for(let r=0;r<this.chunks.length;r++){let a=this.chunks[r];if(!n.has(a))continue;let s=e.lineAt(a.from).number,i=e.lineAt(a.to).number;if(i-s+1<=this.targetLines*2&&a.to-a.from<=this.targetChars*2)continue;let l=this.pieces(e,s,i);if(l.length<2)continue;let u=l[l.length-1];u.endState=a.endState,this.chunks.splice(r,1,...l),r+=l.length-1}}rebalanceTarget(e){if(!this.layoutDirty)return null;let n=this.targetLines;for(let r=0;r+1<this.chunks.length;r++){let a=this.chunks[r],s=this.chunks[r+1],i=this.lineCountOf(e,a),o=a.to-a.from;if(!(i>=n/2||o>=this.targetChars/2)&&!(i+this.lineCountOf(e,s)>n*2)&&!(s.to-a.from>this.targetChars*2))return r}return this.layoutDirty=!1,null}rebalanceOnce(e){let n=this.rebalanceTarget(e);if(n===null)return!1;let r=this.chunks[n],a=this.chunks[n+1];return r.to=a.to,r.endState=a.endState,r.lines=null,r.startState=null,r.final=!1,r.stateKnown=!1,this.chunks.splice(n+1,1),this.layoutDirty=!0,!0}trimWindow(){let e=this.chunks.filter(n=>n.lines);if(!(e.length<=32)){e.sort((n,r)=>n.lastUsed-r.lastUsed);for(let n=0;n<e.length-32;n++)e[n].lines=null}}};var Ks=Me.define({combine:t=>t.length?t[t.length-1]:{theme:"dark-plus"}}),JC=pt.define(),HF=8;function XC(t){setTimeout(()=>{try{t.dispatch({effects:JC.of(null)})}catch{}},0)}function UF(t){let e=globalThis;if(typeof e.requestIdleCallback=="function"){let r=e.requestIdleCallback(t,{timeout:250});return{cancel:()=>e.cancelIdleCallback?.(r)}}let n=setTimeout(t,0);return{cancel:()=>clearTimeout(n)}}var YC=new Map;function GF(t){let e=YC.get(t);return e||(e=Ke.mark({attributes:{style:`color:${t}`}}),YC.set(t,e)),e}var Ig=class{constructor(e){this.decorations=Ke.none;this.engine=null;this.engineKey="";this.idle=null;this.disposed=!1;this.loadKicked=null;this.horizon=0;this.decorations=this.build(e)}update(e){e.docChanged&&this.engine&&this.engine.applyChanges(e.changes,e.state.doc);let n=e.startState.facet(Ks),r=e.state.facet(Ks),a=n.lang!==r.lang||n.theme!==r.theme,s=e.transactions.some(i=>i.effects.some(o=>o.is(JC)));(e.docChanged||e.viewportChanged||a||s)&&(this.decorations=this.build(e.view))}destroy(){this.disposed=!0,this.idle?.cancel(),this.idle=null,this.engine=null}build(e){let n=e.state.facet(Ks),r=So(n.lang);if(!r)return this.engine=null,Ke.none;let a=e.state.doc;if(a.length>2e6)return this.engine=null,Ke.none;let s=r1(r);if(!s)return this.loadKicked!==r&&(this.loadKicked=r,au().then(()=>nd(r)).then(c=>{c&&!this.disposed&&XC(e)})),Ke.none;let i=`${r} ${n.theme}`;(!this.engine||this.engineKey!==i)&&(this.engine=new pf(s,r,n.theme,a),this.engineKey=i);let o=this.engine,l=new qn,u=0;for(let{from:c,to:d}of e.visibleRanges){o.ensureRange(a,c,d);let f=a.lineAt(c).number,h=a.lineAt(d).number,p=o.chunkIndexAt(d);u=Math.max(u,p+4);for(let g=o.chunkIndexAt(c);g<=p;g++){let m=o.chunks[g],x=o.firstLineOf(a,m),y=a.lineAt(m.to).number;for(let b=Math.max(f,x);b<=Math.min(h,y);b++){let C=o.tokensAt(m,b-x);if(!C)continue;let L=a.line(b);for(let P of C){if(!P.content||!P.color)continue;let w=m.from+P.offset,k=w+P.content.length;w<L.from||w>=k||k>L.to||l.add(w,k,GF(P.color))}}}}return this.horizon=u,o.hasPendingWork(a,u)&&this.scheduleIdle(e),l.finish()}scheduleIdle(e){this.idle||this.disposed||(this.idle=UF(()=>{if(this.idle=null,this.disposed||!this.engine)return;let n=this.engine.idleStep(e.state.doc,HF,this.horizon),r=n.touched;!!r&&e.visibleRanges.some(s=>r.from<=s.to&&r.to>=s.from)?XC(e):n.more&&this.scheduleIdle(e)}))}},mf=hr.fromClass(Ig,{decorations:t=>t.decorations});var gf=Pe.theme({"&":{backgroundColor:"transparent",color:"#d4d4d4",height:"100%"},"&.cm-focused":{outline:"none"},".cm-scroller":{fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:"18px"},".cm-content":{padding:"6px 0",caretColor:"#e5e7eb"},".cm-gutters":{backgroundColor:"transparent",border:"none",color:"rgba(255,255,255,0.25)"},".cm-lineNumbers .cm-gutterElement":{padding:"0 10px 0 12px",minWidth:"2ch"},".cm-activeLine":{backgroundColor:"rgba(255,255,255,0.035)"},".cm-activeLineGutter":{backgroundColor:"transparent",color:"rgba(255,255,255,0.5)"},".cm-cursor, .cm-dropCursor":{borderLeftColor:"#e5e7eb"},".cm-selectionBackground, .cm-content ::selection":{backgroundColor:"rgba(96,130,255,0.28)"},"&.cm-focused .cm-selectionBackground":{backgroundColor:"rgba(96,130,255,0.34)"},".cm-placeholder":{color:"rgba(255,255,255,0.22)"}},{dark:!0}),ZC=Pe.theme({".cm-changedLine":{backgroundColor:"rgba(16,185,129,0.10)"},".cm-changedText":{background:"rgba(16,185,129,0.24)"},".cm-insertedLine":{backgroundColor:"rgba(16,185,129,0.12)"},".cm-deletedChunk":{backgroundColor:"rgba(244,63,94,0.10)"},".cm-deletedChunk .cm-deletedText, .cm-deletedText":{background:"rgba(244,63,94,0.30)"},".cm-changeGutter":{width:"3px"},".cm-changedLineGutter":{backgroundColor:"rgba(16,185,129,0.45)"},".cm-deletedLineGutter":{backgroundColor:"rgba(244,63,94,0.45)"},".cm-merge-a, .cm-merge-b":{backgroundColor:"transparent"},".cm-mergeSpacer":{backgroundColor:"rgba(255,255,255,0.02)"},".cm-merge-revert":{display:"none"}});var QC=j(ie(),1);function Lg(t,e){return[Kd(),It.readOnly.of(!0),Pe.editable.of(!1),gf,ZC,Ks.of({lang:t,theme:e}),mf]}function Ag({oldContent:t,newContent:e,language:n,viewMode:r="unified",className:a,theme:s="dark-plus"}){let i=(0,xf.useRef)(null);return(0,xf.useEffect)(()=>{let o=i.current;if(!o)return;let l;if(r==="split"){let u=new df({a:{doc:t,extensions:Lg(n,s)},b:{doc:e,extensions:Lg(n,s)},parent:o,gutter:!0,highlightChanges:!0,revertControls:void 0});l=()=>u.destroy()}else{let u=It.create({doc:e,extensions:[...Lg(n,s),qC({original:t,mergeControls:!1,gutter:!0,highlightChanges:!0,syntaxHighlightDeletions:!1})]}),c=new Pe({state:u,parent:o});l=()=>c.destroy()}return l},[t,e,n,r,s]),(0,QC.jsx)("div",{ref:i,className:a})}var Kn=j($e(),1);var WF=t=>{let{state:e}=t,n=e.doc.lineAt(e.selection.main.from),r=Fg(t.state,n.from);return r.line?zF(t):r.block?VF(t):!1};function Dg(t,e){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let a=t(e,n);return a?(r(n.update(a)),!0):!1}}var zF=Dg(KF,0);var jF=Dg(lI,0);var VF=Dg((t,e)=>lI(t,e,$F(e)),0);function Fg(t,e){let n=t.languageDataAt("commentTokens",e,1);return n.length?n[0]:{}}var ju=50;function qF(t,{open:e,close:n},r,a){let s=t.sliceDoc(r-ju,r),i=t.sliceDoc(a,a+ju),o=/\s*$/.exec(s)[0].length,l=/^\s*/.exec(i)[0].length,u=s.length-o;if(s.slice(u-e.length,u)==e&&i.slice(l,l+n.length)==n)return{open:{pos:r-o,margin:o&&1},close:{pos:a+l,margin:l&&1}};let c,d;a-r<=2*ju?c=d=t.sliceDoc(r,a):(c=t.sliceDoc(r,r+ju),d=t.sliceDoc(a-ju,a));let f=/^\s*/.exec(c)[0].length,h=/\s*$/.exec(d)[0].length,p=d.length-h-n.length;return c.slice(f,f+e.length)==e&&d.slice(p,p+n.length)==n?{open:{pos:r+f+e.length,margin:/\s/.test(c.charAt(f+e.length))?1:0},close:{pos:a-h-n.length,margin:/\s/.test(d.charAt(p-1))?1:0}}:null}function $F(t){let e=[];for(let n of t.selection.ranges){let r=t.doc.lineAt(n.from),a=n.to<=r.to?r:t.doc.lineAt(n.to);a.from>r.from&&a.from==n.to&&(a=n.to==r.to+1?r:t.doc.lineAt(n.to-1));let s=e.length-1;s>=0&&e[s].to>r.from?e[s].to=a.to:e.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:a.to})}return e}function lI(t,e,n=e.selection.ranges){let r=n.map(s=>Fg(e,s.from).block);if(!r.every(s=>s))return null;let a=n.map((s,i)=>qF(e,r[i],s.from,s.to));if(t!=2&&!a.every(s=>s))return{changes:e.changes(n.map((s,i)=>a[i]?[]:[{from:s.from,insert:r[i].open+" "},{from:s.to,insert:" "+r[i].close}]))};if(t!=1&&a.some(s=>s)){let s=[];for(let i=0,o;i<a.length;i++)if(o=a[i]){let l=r[i],{open:u,close:c}=o;s.push({from:u.pos-l.open.length,to:u.pos+u.margin},{from:c.pos-c.margin,to:c.pos+l.close.length})}return{changes:s}}return null}function KF(t,e,n=e.selection.ranges){let r=[],a=-1;e:for(let{from:s,to:i}of n){let o=r.length,l=1e9,u;for(let c=s;c<=i;){let d=e.doc.lineAt(c);if(u==null&&(u=Fg(e,d.from).line,!u))continue e;if(d.from>a&&(s==i||i>d.from)){a=d.from;let f=/^\s*/.exec(d.text)[0].length,h=f==d.length,p=d.text.slice(f,f+u.length)==u?f:-1;f<d.text.length&&f<l&&(l=f),r.push({line:d,comment:p,token:u,indent:f,empty:h,single:!1})}c=d.to+1}if(l<1e9)for(let c=o;c<r.length;c++)r[c].indent<r[c].line.text.length&&(r[c].indent=l);r.length==o+1&&(r[o].single=!0)}if(t!=2&&r.some(s=>s.comment<0&&(!s.empty||s.single))){let s=[];for(let{line:o,token:l,indent:u,empty:c,single:d}of r)(d||!c)&&s.push({from:o.from+u,insert:l+" "});let i=e.changes(s);return{changes:i,selection:e.selection.map(i,1)}}else if(t!=1&&r.some(s=>s.comment>=0)){let s=[];for(let{line:i,comment:o,token:l}of r)if(o>=0){let u=i.from+o,c=u+l.length;i.text[c-i.from]==" "&&c++,s.push({from:u,to:c})}return{changes:s}}return null}var Ng=Hr.define(),XF=Hr.define(),YF=Me.define(),uI=Me.define({combine(t){return No(t,{minDepth:100,newGroupDelay:500,joinToEvent:(e,n)=>n},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,n)=>(r,a)=>e(r,a)||n(r,a)})}}),cI=vn.define({create(){return Gi.empty},update(t,e){let n=e.state.facet(uI),r=e.annotation(Ng);if(r){let l=da.fromTransaction(e,r.selection),u=r.side,c=u==0?t.undone:t.done;return l?c=bf(c,c.length,n.minDepth,l):c=pI(c,e.startState.selection),new Gi(u==0?r.rest:c,u==0?c:r.rest)}let a=e.annotation(XF);if((a=="full"||a=="before")&&(t=t.isolate()),e.annotation(An.addToHistory)===!1)return e.changes.empty?t:t.addMapping(e.changes.desc);let s=da.fromTransaction(e),i=e.annotation(An.time),o=e.annotation(An.userEvent);return s?t=t.addChanges(s,i,o,n,e):e.selection&&(t=t.addSelection(e.startState.selection,i,o,n.newGroupDelay)),(a=="full"||a=="after")&&(t=t.isolate()),t},toJSON(t){return{done:t.done.map(e=>e.toJSON()),undone:t.undone.map(e=>e.toJSON())}},fromJSON(t){return new Gi(t.done.map(da.fromJSON),t.undone.map(da.fromJSON))}});function dI(t={}){return[cI,uI.of(t),Pe.domEventHandlers({beforeinput(e,n){let r=e.inputType=="historyUndo"?fI:e.inputType=="historyRedo"?Rg:null;return r?(e.preventDefault(),r(n)):!1}})]}function wf(t,e){return function({state:n,dispatch:r}){if(!e&&n.readOnly)return!1;let a=n.field(cI,!1);if(!a)return!1;let s=a.pop(t,n,e);return s?(r(s),!0):!1}}var fI=wf(0,!1),Rg=wf(1,!1),JF=wf(0,!0),ZF=wf(1,!0);var da=class t{constructor(e,n,r,a,s){this.changes=e,this.effects=n,this.mapped=r,this.startSelection=a,this.selectionsAfter=s}setSelAfter(e){return new t(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,n,r;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(n=this.mapped)===null||n===void 0?void 0:n.toJSON(),startSelection:(r=this.startSelection)===null||r===void 0?void 0:r.toJSON(),selectionsAfter:this.selectionsAfter.map(a=>a.toJSON())}}static fromJSON(e){return new t(e.changes&&Nn.fromJSON(e.changes),[],e.mapped&&rs.fromJSON(e.mapped),e.startSelection&&se.fromJSON(e.startSelection),e.selectionsAfter.map(se.fromJSON))}static fromTransaction(e,n){let r=jr;for(let a of e.startState.facet(YF)){let s=a(e);s.length&&(r=r.concat(s))}return!r.length&&e.changes.empty?null:new t(e.changes.invert(e.startState.doc),r,void 0,n||e.startState.selection,jr)}static selection(e){return new t(void 0,jr,void 0,void 0,e)}};function bf(t,e,n,r){let a=e+1>n+20?e-n-1:0,s=t.slice(a,e);return s.push(r),s}function QF(t,e){let n=[],r=!1;return t.iterChangedRanges((a,s)=>n.push(a,s)),e.iterChangedRanges((a,s,i,o)=>{for(let l=0;l<n.length;){let u=n[l++],c=n[l++];o>=u&&i<=c&&(r=!0)}}),r}function e5(t,e){return t.ranges.length==e.ranges.length&&t.ranges.filter((n,r)=>n.empty!=e.ranges[r].empty).length===0}function hI(t,e){return t.length?e.length?t.concat(e):t:e}var jr=[],t5=200;function pI(t,e){if(t.length){let n=t[t.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-t5));return r.length&&r[r.length-1].eq(e)?t:(r.push(e),bf(t,t.length-1,1e9,n.setSelAfter(r)))}else return[da.selection([e])]}function n5(t){let e=t[t.length-1],n=t.slice();return n[t.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),n}function Pg(t,e){if(!t.length)return t;let n=t.length,r=jr;for(;n;){let a=r5(t[n-1],e,r);if(a.changes&&!a.changes.empty||a.effects.length){let s=t.slice(0,n);return s[n-1]=a,s}else e=a.mapped,n--,r=a.selectionsAfter}return r.length?[da.selection(r)]:jr}function r5(t,e,n){let r=hI(t.selectionsAfter.length?t.selectionsAfter.map(o=>o.map(e)):jr,n);if(!t.changes)return da.selection(r);let a=t.changes.map(e),s=e.mapDesc(t.changes,!0),i=t.mapped?t.mapped.composeDesc(s):s;return new da(a,pt.mapEffects(t.effects,e),i,t.startSelection.map(s),r)}var a5=/^(input\.type|delete)($|\.)/,Gi=class t{constructor(e,n,r=0,a=void 0){this.done=e,this.undone=n,this.prevTime=r,this.prevUserEvent=a}isolate(){return this.prevTime?new t(this.done,this.undone):this}addChanges(e,n,r,a,s){let i=this.done,o=i[i.length-1];return o&&o.changes&&!o.changes.empty&&e.changes&&(!r||a5.test(r))&&(!o.selectionsAfter.length&&n-this.prevTime<a.newGroupDelay&&a.joinToEvent(s,QF(o.changes,e.changes))||r=="input.type.compose")?i=bf(i,i.length-1,a.minDepth,new da(e.changes.compose(o.changes),hI(pt.mapEffects(e.effects,o.changes),o.effects),o.mapped,o.startSelection,jr)):i=bf(i,i.length,a.minDepth,e),new t(i,jr,n,r)}addSelection(e,n,r,a){let s=this.done.length?this.done[this.done.length-1].selectionsAfter:jr;return s.length>0&&n-this.prevTime<a&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&e5(s[s.length-1],e)?this:new t(pI(this.done,e),this.undone,n,r)}addMapping(e){return new t(Pg(this.done,e),Pg(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,n,r){let a=e==0?this.done:this.undone;if(a.length==0)return null;let s=a[a.length-1],i=s.selectionsAfter[0]||(s.startSelection?s.startSelection.map(s.changes.invertedDesc,1):n.selection);if(r&&s.selectionsAfter.length)return n.update({selection:s.selectionsAfter[s.selectionsAfter.length-1],annotations:Ng.of({side:e,rest:n5(a),selection:i}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(s.changes){let o=a.length==1?jr:a.slice(0,a.length-1);return s.mapped&&(o=Pg(o,s.mapped)),n.update({changes:s.changes,selection:s.startSelection,effects:s.effects,annotations:Ng.of({side:e,rest:o,selection:i}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}};Gi.empty=new Gi(jr,jr);var mI=[{key:"Mod-z",run:fI,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Rg,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Rg,preventDefault:!0},{key:"Mod-u",run:JF,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:ZF,preventDefault:!0}];function $o(t,e){return se.create(t.ranges.map(e),t.mainIndex)}function fa(t,e){return t.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function ha({state:t,dispatch:e},n){let r=$o(t.selection,n);return r.eq(t.selection,!0)?!1:(e(fa(t,r)),!0)}function vf(t,e){return se.cursor(e?t.to:t.from)}function gI(t,e){return ha(t,n=>n.empty?t.moveByChar(n,e):vf(n,e))}function $n(t){return t.textDirectionAt(t.state.selection.main.head)==Vt.LTR}var xI=t=>gI(t,!$n(t)),yI=t=>gI(t,$n(t));function bI(t,e){return ha(t,n=>n.empty?t.moveByGroup(n,e):vf(n,e))}var s5=t=>bI(t,!$n(t)),i5=t=>bI(t,$n(t));var V6=typeof Intl<"u"&&Intl.Segmenter?new Intl.Segmenter(void 0,{granularity:"word"}):null;function o5(t,e,n){if(e.type.prop(n))return!0;let r=e.to-e.from;return r&&(r>2||/[^\s,.;:]/.test(t.sliceDoc(e.from,e.to)))||e.firstChild}function kf(t,e,n){let r=ls(t).resolveInner(e.head),a=n?rt.closedBy:rt.openedBy;for(let l=e.head;;){let u=n?r.childAfter(l):r.childBefore(l);if(!u)break;o5(t,u,a)?r=u:l=n?u.to:u.from}let s=r.type.prop(a),i,o;return s&&(i=n?_i(t,r.from,1):_i(t,r.to,-1))&&i.matched?o=n?i.end.to:i.end.from:o=n?r.to:r.from,se.cursor(o,n?-1:1)}var l5=t=>ha(t,e=>kf(t.state,e,!$n(t))),u5=t=>ha(t,e=>kf(t.state,e,$n(t)));function wI(t,e){return ha(t,n=>{if(!n.empty)return vf(n,e);let r=t.moveVertically(n,e);return r.head!=n.head?r:t.moveToLineBoundary(n,e)})}var vI=t=>wI(t,!1),kI=t=>wI(t,!0);function SI(t){let e=t.scrollDOM.clientHeight<t.scrollDOM.scrollHeight-2,n=0,r=0,a;if(e){for(let s of t.state.facet(Pe.scrollMargins)){let i=s(t);i?.top&&(n=Math.max(i?.top,n)),i?.bottom&&(r=Math.max(i?.bottom,r))}a=t.scrollDOM.clientHeight-n-r}else a=(t.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:e,height:Math.max(t.defaultLineHeight,a-5)}}function CI(t,e){let n=SI(t),{state:r}=t,a=$o(r.selection,i=>i.empty?t.moveVertically(i,e,n.height):vf(i,e));if(a.eq(r.selection))return!1;let s;if(n.selfScroll){let i=t.coordsAtPos(r.selection.main.head),o=t.scrollDOM.getBoundingClientRect(),l=o.top+n.marginTop,u=o.bottom-n.marginBottom;i&&i.top>l&&i.bottom<u&&(s=Pe.scrollIntoView(a.main.head,{y:"start",yMargin:i.top-l}))}return t.dispatch(fa(r,a),{effects:s}),!0}var eI=t=>CI(t,!1),Mg=t=>CI(t,!0);function Xs(t,e,n){let r=t.lineBlockAt(e.head),a=t.moveToLineBoundary(e,n);if(a.head==e.head&&a.head!=(n?r.to:r.from)&&(a=t.moveToLineBoundary(e,n,!1)),!n&&a.head==r.from&&r.length){let s=/^\s*/.exec(t.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;s&&e.head!=r.from+s&&(a=se.cursor(r.from+s))}return a}var c5=t=>ha(t,e=>Xs(t,e,!0)),d5=t=>ha(t,e=>Xs(t,e,!1)),f5=t=>ha(t,e=>Xs(t,e,!$n(t))),h5=t=>ha(t,e=>Xs(t,e,$n(t))),p5=t=>ha(t,e=>t.moveToLineBoundary(e,!1,!1)),m5=t=>ha(t,e=>t.moveToLineBoundary(e,!0,!1));function g5(t,e,n){let r=!1,a=$o(t.selection,s=>{let i=_i(t,s.head,-1)||_i(t,s.head,1)||s.head>0&&_i(t,s.head-1,1)||s.head<t.doc.length&&_i(t,s.head+1,-1);if(!i||!i.end)return s;r=!0;let o=i.start.from==s.head?i.end.to:i.end.from;return n?se.range(s.anchor,o):se.cursor(o)});return r?(e(fa(t,a)),!0):!1}var x5=({state:t,dispatch:e})=>g5(t,e,!1);function Vr(t,e,n){let r=$o(t.state.selection,a=>{a.undirectional&&a.head>=a.anchor!=e&&(a=se.range(a.head,a.anchor));let s=n(a);return se.range(a.anchor,s.head,s.goalColumn,s.bidiLevel||void 0,s.assoc)});return r.eq(t.state.selection)?!1:(t.dispatch(fa(t.state,r)),!0)}function II(t,e){return Vr(t,e,n=>t.moveByChar(n,e))}var LI=t=>II(t,!$n(t)),AI=t=>II(t,$n(t));function PI(t,e){return Vr(t,e,n=>t.moveByGroup(n,e))}var y5=t=>PI(t,!$n(t)),b5=t=>PI(t,$n(t));var w5=t=>{let e=!$n(t);return Vr(t,e,n=>kf(t.state,n,e))},v5=t=>{let e=$n(t);return Vr(t,e,n=>kf(t.state,n,e))};function NI(t,e){return Vr(t,e,n=>t.moveVertically(n,e))}var RI=t=>NI(t,!1),MI=t=>NI(t,!0);function TI(t,e){return Vr(t,e,n=>t.moveVertically(n,e,SI(t).height))}var tI=t=>TI(t,!1),nI=t=>TI(t,!0),k5=t=>Vr(t,!0,e=>Xs(t,e,!0)),S5=t=>Vr(t,!1,e=>Xs(t,e,!1)),C5=t=>{let e=!$n(t);return Vr(t,e,n=>Xs(t,n,e))},I5=t=>{let e=$n(t);return Vr(t,e,n=>Xs(t,n,e))},L5=t=>Vr(t,!1,e=>se.cursor(t.lineBlockAt(e.head).from)),A5=t=>Vr(t,!0,e=>se.cursor(t.lineBlockAt(e.head).to)),rI=({state:t,dispatch:e})=>(e(fa(t,{anchor:0})),!0),aI=({state:t,dispatch:e})=>(e(fa(t,{anchor:t.doc.length})),!0),sI=({state:t,dispatch:e})=>(e(fa(t,{anchor:t.selection.main.anchor,head:0})),!0),iI=({state:t,dispatch:e})=>(e(fa(t,{anchor:t.selection.main.anchor,head:t.doc.length})),!0),P5=({state:t,dispatch:e})=>(e(t.update({selection:{anchor:0,head:t.doc.length},userEvent:"select"})),!0),N5=({state:t,dispatch:e})=>{let n=Sf(t).map(({from:r,to:a})=>se.undirectionalRange(r,Math.min(a+1,t.doc.length)));return e(t.update({selection:se.create(n),userEvent:"select"})),!0},R5=({state:t,dispatch:e})=>{let n=$o(t.selection,r=>{let a=ls(t),s=a.resolveStack(r.from,1);if(r.empty){let i=a.resolveStack(r.from,-1);i.node.from>=s.node.from&&i.node.to<=s.node.to&&(s=i)}for(let i=s;i;i=i.next){let{node:o}=i;if((o.from<r.from&&o.to>=r.to||o.to>r.to&&o.from<=r.from)&&i.next)return se.undirectionalRange(o.from,o.to)}return r});return n.eq(t.selection)?!1:(e(fa(t,n)),!0)};function DI(t,e){let{state:n}=t,r=n.selection,a=n.selection.ranges.slice();for(let s of n.selection.ranges){let i=n.doc.lineAt(s.head);if(e?i.to<t.state.doc.length:i.from>0)for(let o=s;;){let l=t.moveVertically(o,e);if(l.head<i.from||l.head>i.to){a.some(u=>u.head==l.head)||a.push(l);break}else{if(l.head==o.head)break;o=l}}}return a.length==r.ranges.length?!1:(t.dispatch(fa(n,se.create(a,a.length-1))),!0)}var M5=t=>DI(t,!1),T5=t=>DI(t,!0),D5=({state:t,dispatch:e})=>{let n=t.selection,r=null;return n.ranges.length>1?r=se.create([n.main]):n.main.empty||(r=se.create([se.cursor(n.main.head)])),r?(e(fa(t,r)),!0):!1};function Vu(t,e){if(t.state.readOnly)return!1;let n="delete.selection",{state:r}=t,a=r.changeByRange(s=>{let{from:i,to:o}=s;if(i==o){let l=e(s);l<i?(n="delete.backward",l=yf(t,l,!1)):l>i&&(n="delete.forward",l=yf(t,l,!0)),i=Math.min(i,l),o=Math.max(o,l)}else i=yf(t,i,!1),o=yf(t,o,!0);return i==o?{range:s}:{changes:{from:i,to:o},range:se.cursor(i,i<s.head?-1:1)}});return a.changes.empty?!1:(t.dispatch(r.update(a,{scrollIntoView:!0,userEvent:n,effects:n=="delete.selection"?Pe.announce.of(r.phrase("Selection deleted")):void 0})),!0)}function yf(t,e,n){if(t instanceof Pe)for(let r of t.state.facet(Pe.atomicRanges).map(a=>a(t)))r.between(e,e,(a,s)=>{a<e&&s>e&&(e=n?s:a)});return e}var FI=(t,e,n)=>Vu(t,r=>{let a=r.from,{state:s}=t,i=s.doc.lineAt(a),o,l;if(n&&!e&&a>i.from&&a<i.from+200&&!/[^ \t]/.test(o=i.text.slice(0,a-i.from))){if(o[o.length-1]==" ")return a-1;let u=Li(o,s.tabSize),c=u%Hu(s)||Hu(s);for(let d=0;d<c&&o[o.length-1-d]==" ";d++)a--;l=a}else l=Pn(i.text,a-i.from,e,e)+i.from,l==a&&i.number!=(e?s.doc.lines:1)?l+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(i.text.slice(l-i.from,a-i.from))&&(l=Pn(i.text,l-i.from,!1,!1)+i.from);return l}),Tg=t=>FI(t,!1,!0);var EI=t=>FI(t,!0,!1),OI=(t,e)=>Vu(t,n=>{let r=n.head,{state:a}=t,s=a.doc.lineAt(r),i=a.charCategorizer(r);for(let o=null;;){if(r==(e?s.to:s.from)){r==n.head&&s.number!=(e?a.doc.lines:1)&&(r+=e?1:-1);break}let l=Pn(s.text,r-s.from,e)+s.from,u=s.text.slice(Math.min(r,l)-s.from,Math.max(r,l)-s.from),c=i(u);if(o!=null&&c!=o)break;(u!=" "||r!=n.head)&&(o=c),r=l}return r}),BI=t=>OI(t,!1),F5=t=>OI(t,!0);var E5=t=>Vu(t,e=>{let n=t.lineBlockAt(e.head).to;return e.head<n?n:Math.min(t.state.doc.length,e.head+1)});var O5=t=>Vu(t,e=>{let n=t.moveToLineBoundary(e,!1).head;return e.head>n?n:Math.max(0,e.head-1)}),B5=t=>Vu(t,e=>{let n=t.moveToLineBoundary(e,!0).head;return e.head<n?n:Math.min(t.state.doc.length,e.head+1)});var _5=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=t.changeByRange(r=>({changes:{from:r.from,to:r.to,insert:st.of(["",""])},range:se.cursor(r.from)}));return e(t.update(n,{scrollIntoView:!0,userEvent:"input"})),!0},H5=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=t.changeByRange(r=>{if(!r.empty||r.from==0||r.from==t.doc.length)return{range:r};let a=r.from,s=t.doc.lineAt(a),i=a==s.from?a-1:Pn(s.text,a-s.from,!1)+s.from,o=a==s.to?a+1:Pn(s.text,a-s.from,!0)+s.from;return{changes:{from:i,to:o,insert:t.doc.slice(a,o).append(t.doc.slice(i,a))},range:se.cursor(o)}});return n.changes.empty?!1:(e(t.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function Sf(t){let e=[],n=-1;for(let r of t.selection.ranges){let a=t.doc.lineAt(r.from),s=t.doc.lineAt(r.to);if(!r.empty&&r.to==s.from&&(s=t.doc.lineAt(r.to-1)),n>=a.number){let i=e[e.length-1];i.to=s.to,i.ranges.push(r)}else e.push({from:a.from,to:s.to,ranges:[r]});n=s.number+1}return e}function _I(t,e,n){if(t.readOnly)return!1;let r=[],a=[];for(let s of Sf(t)){if(n?s.to==t.doc.length:s.from==0)continue;let i=t.doc.lineAt(n?s.to+1:s.from-1),o=i.length+1;if(n){r.push({from:s.to,to:i.to},{from:s.from,insert:i.text+t.lineBreak});for(let l of s.ranges)a.push(se.range(Math.min(t.doc.length,l.anchor+o),Math.min(t.doc.length,l.head+o)))}else{r.push({from:i.from,to:s.from},{from:s.to,insert:t.lineBreak+i.text});for(let l of s.ranges)a.push(se.range(l.anchor-o,l.head-o))}}return r.length?(e(t.update({changes:r,scrollIntoView:!0,selection:se.create(a,t.selection.mainIndex),userEvent:"move.line"})),!0):!1}var U5=({state:t,dispatch:e})=>_I(t,e,!1),G5=({state:t,dispatch:e})=>_I(t,e,!0);function HI(t,e,n){if(t.readOnly)return!1;let r=[];for(let s of Sf(t))n?r.push({from:s.from,insert:t.doc.slice(s.from,s.to)+t.lineBreak}):r.push({from:s.to,insert:t.lineBreak+t.doc.slice(s.from,s.to)});let a=t.changes(r);return e(t.update({changes:a,selection:t.selection.map(a,n?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}var W5=({state:t,dispatch:e})=>HI(t,e,!1),z5=({state:t,dispatch:e})=>HI(t,e,!0),j5=t=>{if(t.state.readOnly)return!1;let{state:e}=t,n=e.changes(Sf(e).map(({from:a,to:s})=>(a>0?a--:s<e.doc.length&&s++,{from:a,to:s}))),r=$o(e.selection,a=>{let s;if(t.lineWrapping){let i=t.lineBlockAt(a.head),o=t.coordsAtPos(a.head,a.assoc||1);o&&(s=i.bottom+t.documentTop-o.bottom+t.defaultLineHeight/2)}return t.moveVertically(a,!0,s)}).map(n);return t.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:"delete.line"}),!0};function V5(t,e){if(/\(\)|\[\]|\{\}/.test(t.sliceDoc(e-1,e+1)))return{from:e,to:e};let n=ls(t).resolveInner(e),r=n.childBefore(e),a=n.childAfter(e),s;return r&&a&&r.to<=e&&a.from>=e&&(s=r.type.prop(rt.closedBy))&&s.indexOf(a.name)>-1&&t.doc.lineAt(r.to).from==t.doc.lineAt(a.from).from&&!/\S/.test(t.sliceDoc(r.to,a.from))?{from:r.to,to:a.from}:null}var oI=UI(!1),q5=UI(!0);function UI(t){return({state:e,dispatch:n})=>{if(e.readOnly)return!1;let r=e.changeByRange(a=>{let{from:s,to:i}=a,o=e.doc.lineAt(s),l=!t&&s==i&&V5(e,s);t&&(s=i=(i<=o.to?o:e.doc.lineAt(i)).to);let u=new Bi(e,{simulateBreak:s,simulateDoubleBreak:!!l}),c=fg(u,s);for(c==null&&(c=Li(/^\s*/.exec(e.doc.lineAt(s).text)[0],e.tabSize));i<o.to&&/\s/.test(o.text[i-o.from]);)i++;l?{from:s,to:i}=l:s>o.from&&s<o.from+100&&!/\S/.test(o.text.slice(0,s))&&(s=o.from);let d=["",Uu(e,c)];return l&&d.push(Uu(e,u.lineIndent(o.from,-1))),{changes:{from:s,to:i,insert:st.of(d)},range:se.cursor(s+1+d[1].length)}});return n(e.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}function Eg(t,e){let n=-1;return t.changeByRange(r=>{let a=[];for(let i=r.from;i<=r.to;){let o=t.doc.lineAt(i);o.number>n&&(r.empty||r.to>o.from)&&(e(o,a,r),n=o.number),i=o.to+1}let s=t.changes(a);return{changes:a,range:se.range(s.mapPos(r.anchor,1),s.mapPos(r.head,1))}})}var $5=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=Object.create(null),r=new Bi(t,{overrideIndentation:s=>{let i=n[s];return i??-1}}),a=Eg(t,(s,i,o)=>{let l=fg(r,s.from);if(l==null)return;/\S/.test(s.text)||(l=0);let u=/^\s*/.exec(s.text)[0],c=Uu(t,l);(u!=c||o.from<s.from+u.length)&&(n[s.from]=l,i.push({from:s.from,to:s.from+u.length,insert:c}))});return a.changes.empty||e(t.update(a,{userEvent:"indent"})),!0},GI=({state:t,dispatch:e})=>t.readOnly?!1:(e(t.update(Eg(t,(n,r)=>{r.push({from:n.from,insert:t.facet(rf)})}),{userEvent:"input.indent"})),!0),WI=({state:t,dispatch:e})=>t.readOnly?!1:(e(t.update(Eg(t,(n,r)=>{let a=/^\s*/.exec(n.text)[0];if(!a)return;let s=Li(a,t.tabSize),i=0,o=Uu(t,Math.max(0,s-Hu(t)));for(;i<a.length&&i<o.length&&a.charCodeAt(i)==o.charCodeAt(i);)i++;r.push({from:n.from+i,to:n.from+a.length,insert:o.slice(i)})}),{userEvent:"delete.dedent"})),!0),K5=t=>(t.setTabFocusMode(),!0);var X5=[{key:"Ctrl-b",run:xI,shift:LI,preventDefault:!0},{key:"Ctrl-f",run:yI,shift:AI},{key:"Ctrl-p",run:vI,shift:RI},{key:"Ctrl-n",run:kI,shift:MI},{key:"Ctrl-a",run:p5,shift:L5},{key:"Ctrl-e",run:m5,shift:A5},{key:"Ctrl-d",run:EI},{key:"Ctrl-h",run:Tg},{key:"Ctrl-k",run:E5},{key:"Ctrl-Alt-h",run:BI},{key:"Ctrl-o",run:_5},{key:"Ctrl-t",run:H5},{key:"Ctrl-v",run:Mg}],Y5=[{key:"ArrowLeft",run:xI,shift:LI,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:s5,shift:y5,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:f5,shift:C5,preventDefault:!0},{key:"ArrowRight",run:yI,shift:AI,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:i5,shift:b5,preventDefault:!0},{mac:"Cmd-ArrowRight",run:h5,shift:I5,preventDefault:!0},{key:"ArrowUp",run:vI,shift:RI,preventDefault:!0},{mac:"Cmd-ArrowUp",run:rI,shift:sI},{mac:"Ctrl-ArrowUp",run:eI,shift:tI},{key:"ArrowDown",run:kI,shift:MI,preventDefault:!0},{mac:"Cmd-ArrowDown",run:aI,shift:iI},{mac:"Ctrl-ArrowDown",run:Mg,shift:nI},{key:"PageUp",run:eI,shift:tI},{key:"PageDown",run:Mg,shift:nI},{key:"Home",run:d5,shift:S5,preventDefault:!0},{key:"Mod-Home",run:rI,shift:sI},{key:"End",run:c5,shift:k5,preventDefault:!0},{key:"Mod-End",run:aI,shift:iI},{key:"Enter",run:oI,shift:oI},{key:"Mod-a",run:P5},{key:"Backspace",run:Tg,shift:Tg,preventDefault:!0},{key:"Delete",run:EI,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:BI,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:F5,preventDefault:!0},{mac:"Mod-Backspace",run:O5,preventDefault:!0},{mac:"Mod-Delete",run:B5,preventDefault:!0}].concat(X5.map(t=>({mac:t.key,run:t.run,shift:t.shift}))),zI=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:l5,shift:w5},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:u5,shift:v5},{key:"Alt-ArrowUp",run:U5},{key:"Shift-Alt-ArrowUp",run:W5},{key:"Alt-ArrowDown",run:G5},{key:"Shift-Alt-ArrowDown",run:z5},{key:"Mod-Alt-ArrowUp",run:M5},{key:"Mod-Alt-ArrowDown",run:T5},{key:"Escape",run:D5},{key:"Mod-Enter",run:q5},{key:"Alt-l",mac:"Ctrl-l",run:N5},{key:"Mod-i",run:R5,preventDefault:!0},{key:"Mod-[",run:WI},{key:"Mod-]",run:GI},{key:"Mod-Alt-\\",run:$5},{key:"Shift-Mod-k",run:j5},{key:"Shift-Mod-\\",run:x5},{key:"Mod-/",run:WF},{key:"Alt-A",mac:"Ctrl-A",run:jF},{key:"Ctrl-m",mac:"Shift-Alt-m",run:K5}].concat(Y5),jI={key:"Tab",run:GI,shift:WI};var J5={lines:new Map,deletedBefore:new Set},VI=pt.define(),qI=vn.define({create:()=>J5,update(t,e){for(let n of e.effects)if(n.is(VI))return n.value;return t}}),qu=class extends Bn{constructor(n){super();this.kind=n}eq(n){return n.kind===this.kind}toDOM(){let n=document.createElement("div");return this.kind==="deleted"?n.style.cssText="width:0;height:0;margin-left:2px;border-left:4px solid rgba(244,63,94,0.85);border-top:3px solid transparent;border-bottom:3px solid transparent;":n.style.cssText=`width:2px;height:100%;margin-left:3px;border-radius:1px;background:${this.kind==="added"?"rgba(16,185,129,0.9)":"rgba(59,130,246,0.9)"};`,n}},Z5=new qu("added"),Q5=new qu("modified"),eE=new qu("deleted"),tE=zo({class:"nrs-cm-git-gutter",lineMarker(t,e){let n=t.state.field(qI,!1);if(!n)return null;let r=t.state.doc.lineAt(e.from).number,a=n.lines.get(r);return a==="added"?Z5:a==="modified"?Q5:n.deletedBefore.has(r)?eE:null},lineMarkerChange:t=>t.transactions.some(e=>e.effects.some(n=>n.is(VI)))});function $I(t){return[qI.init(()=>t),tE]}var KI=j(ie(),1);function Og({value:t,language:e,readOnly:n=!1,wrap:r=!1,onChange:a,className:s,placeholder:i,ariaLabel:o,theme:l="dark-plus",gitLineStatus:u}){let c=(0,Kn.useRef)(null),d=(0,Kn.useRef)(null),f=(0,Kn.useRef)(a),h=(0,Kn.useRef)(!1),p=(0,Kn.useRef)(new _r),g=(0,Kn.useRef)(new _r),m=(0,Kn.useRef)(new _r),x=(0,Kn.useRef)(new _r);return f.current=a,(0,Kn.useEffect)(()=>{let y=c.current;if(!y)return;let b=It.create({doc:t,extensions:[Kd(),jS(),$S(),WS(),dI(),jm.of([...zI,...mI,jI]),gf,p.current.of(Ks.of({lang:e,theme:l})),mf,g.current.of([It.readOnly.of(n),Pe.editable.of(!n)]),m.current.of(r?Pe.lineWrapping:[]),x.current.of([]),i?VS(i):[],Pe.updateListener.of(L=>{L.docChanged&&!h.current&&f.current?.(L.state.doc.toString())}),Pe.contentAttributes.of(o?{"aria-label":o}:{})]}),C=new Pe({state:b,parent:y});return d.current=C,()=>{C.destroy(),d.current=null}},[]),(0,Kn.useEffect)(()=>{let y=d.current;if(!y)return;let b=y.state.doc.toString();t!==b&&(h.current=!0,y.dispatch({changes:{from:0,to:b.length,insert:t}}),h.current=!1)},[t]),(0,Kn.useEffect)(()=>{let y=d.current;y&&y.dispatch({effects:p.current.reconfigure(Ks.of({lang:e,theme:l}))})},[e,l]),(0,Kn.useEffect)(()=>{let y=d.current;y&&y.dispatch({effects:g.current.reconfigure([It.readOnly.of(n),Pe.editable.of(!n)])})},[n]),(0,Kn.useEffect)(()=>{let y=d.current;y&&y.dispatch({effects:m.current.reconfigure(r?Pe.lineWrapping:[])})},[r]),(0,Kn.useEffect)(()=>{let y=d.current;if(!y)return;let b=u&&!ld(u)?$I(u):[];y.dispatch({effects:x.current.reconfigure(b)})},[u]),(0,KI.jsx)("div",{ref:c,className:s})}var Ko=j($e(),1);var XI=j(ie(),1);function Bg({target:t,agentId:e,projectId:n}){let r=H(l=>l.client),[a,s]=(0,Ko.useState)(!1),i=H(l=>l.sourceChangeRevision[t.source]??0);(0,Ko.useEffect)(()=>{let l=!0;return s(!1),e&&Ki({agentId:e,...n?{projectId:n}:{},source:t.source},r).then(u=>{l&&s(u.repos.find(c=>c.rel===(t.repo??""))?.canWrite===!0)}).catch(()=>{l&&s(!1)}),()=>{l=!1}},[e,n,t.source,t.repo,i]);let o=(0,Ko.useMemo)(()=>Xv(t),[t]);return(0,XI.jsx)(bi,{source:t.source,repo:t.repo??"",path:t.path,mode:o,agentId:e,projectId:n,variant:"tab",canWrite:a,revision:i})}var _a=j($e(),1);var lt=j(ie(),1),YI="brain://docs",_g=$("h-7 w-full rounded-md px-2 text-[10px] outline-none transition font-mono","bg-white/[0.04] border border-white/[0.08] text-white/86","focus:border-white/[0.18] focus:bg-white/[0.06]","placeholder:text-white/28"),nE=$(_g,"pr-6");function Hg(t){let{agentId:e,projectId:n}=t,r=H(w=>w.workspacePanels.upload),a=H(w=>w.setWorkspacePanelOpen),s=H(w=>w.uploading),i=H(w=>w.uploadMany),o=H(w=>w.files),l=H(w=>w.activeFolderPath),u=H(w=>w.setActiveFolderPath),[c,d]=(0,_a.useState)(""),[f,h]=(0,_a.useState)(""),[p,g]=(0,_a.useState)(!1),[m,x]=(0,_a.useState)(!1),y=(0,_a.useRef)(null),b=(0,_a.useMemo)(()=>{let w=c.trim();return w||l||YI},[l,c]),C=(0,_a.useMemo)(()=>{let w=new Set;for(let k of Object.values(o||{})){if(k?.type!=="folder")continue;let _=String(k.uri||"");_&&w.add(_)}return w.add(YI),Array.from(w).sort((k,_)=>k.localeCompare(_))},[o]),L=w=>{let k=w.trim();k&&(d(k),u(k))},P=async w=>{if(w.length!==0)try{await i({agentId:e,projectId:n,files:w,uri:b})}finally{y.current&&(y.current.value=""),g(!1),a("upload",!1)}};return r?(0,lt.jsxs)("div",{className:"w-full px-5 pt-3 pb-6 text-white/85",children:[(0,lt.jsx)("input",{ref:y,type:"file",multiple:!0,className:"hidden",onChange:async w=>{let k=Array.from(w.target.files||[]);await P(k)}}),(0,lt.jsxs)("div",{className:"flex items-center justify-between gap-2 pb-2 border-b border-white/[0.06]",children:[(0,lt.jsxs)("div",{className:"flex items-center gap-2",children:[s?(0,lt.jsx)(We,{className:"h-4 w-4 animate-spin text-cyan-300/70 shrink-0"}):(0,lt.jsx)(Ia,{className:"h-4 w-4 text-cyan-300/70 shrink-0"}),(0,lt.jsx)("span",{className:"text-sm font-semibold tracking-wide text-white/92",children:"Upload"}),(0,lt.jsx)("span",{className:"rounded px-1.5 py-0.5 text-[10px] font-medium text-white/45 bg-white/[0.04] font-mono truncate max-w-[160px]",children:b})]}),(0,lt.jsx)("button",{type:"button",onClick:()=>a("upload",!1),className:"h-7 px-2.5 rounded-md text-[10px] font-medium text-white/50 hover:text-white/80 hover:bg-white/[0.05] transition",children:"Close"})]}),(0,lt.jsx)("div",{className:$("mt-2 rounded-md border border-dashed px-4 py-5 text-center transition",p?"border-cyan-300/40 bg-cyan-400/[0.04]":"border-white/[0.10] bg-white/[0.02]",s&&"opacity-60"),onDragEnter:w=>{s||(w.preventDefault(),g(!0))},onDragOver:w=>{s||(w.preventDefault(),w.dataTransfer.dropEffect="copy",g(!0))},onDragLeave:w=>{w.currentTarget.contains(w.relatedTarget)||g(!1)},onDrop:async w=>{s||(w.preventDefault(),await P(Array.from(w.dataTransfer.files||[])))},children:(0,lt.jsxs)("div",{className:"flex items-center justify-center gap-3",children:[s?(0,lt.jsx)(We,{className:"h-4 w-4 animate-spin text-cyan-200/80"}):(0,lt.jsx)(Ia,{className:"h-4 w-4 text-cyan-200/70"}),(0,lt.jsx)("span",{className:"text-[11px] text-white/60",children:s?"Uploading...":"Drop files here"}),(0,lt.jsxs)("button",{type:"button",onClick:()=>y.current?.click(),disabled:s,className:"h-6 px-2.5 rounded-md bg-cyan-500/12 border border-cyan-400/20 text-[9px] font-semibold text-cyan-200/90 hover:bg-cyan-500/20 transition disabled:opacity-40 disabled:cursor-not-allowed inline-flex items-center gap-1",children:[(0,lt.jsx)(Ml,{className:"h-2.5 w-2.5"}),"Choose files"]})]})}),(0,lt.jsxs)("div",{className:"mt-1",children:[(0,lt.jsxs)("button",{type:"button",onClick:()=>x(w=>!w),className:"w-full flex items-center gap-2 py-1.5 text-left hover:bg-white/[0.02] rounded-md px-1 transition",children:[(0,lt.jsx)(br,{className:"h-3.5 w-3.5 text-violet-400/70 shrink-0"}),(0,lt.jsx)("span",{className:"text-[11px] font-semibold text-white/88",children:"Destination"}),(0,lt.jsx)("span",{className:"text-[9px] text-white/35 font-mono truncate",children:b}),(0,lt.jsx)(Et,{className:$("ml-auto h-3 w-3 text-white/25 shrink-0 transition-transform",m&&"rotate-180")})]}),(0,lt.jsx)("div",{className:$("overflow-hidden transition-all duration-200",m?"max-h-[300px] opacity-100":"max-h-0 opacity-0"),children:(0,lt.jsxs)("div",{className:"rounded-md bg-white/[0.02] p-2.5 ml-5 mb-1 space-y-2",children:[(0,lt.jsxs)("div",{className:"space-y-1",children:[(0,lt.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Folder"}),(0,lt.jsx)("select",{value:b,onChange:w=>L(w.target.value),disabled:s,className:nE,children:C.map(w=>(0,lt.jsx)("option",{value:w,className:"bg-[#1a1a1f]",children:w},w))})]}),(0,lt.jsxs)("div",{className:"space-y-1",children:[(0,lt.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Override"}),(0,lt.jsx)("input",{value:c,onChange:w=>d(w.target.value),placeholder:b,disabled:s,className:_g})]}),(0,lt.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,lt.jsx)("input",{value:f,onChange:w=>h(w.target.value),onKeyDown:w=>{w.key==="Enter"&&(w.preventDefault(),L(f),h(""))},placeholder:"brain://docs/new-folder",disabled:s,className:$(_g,"flex-1")}),(0,lt.jsxs)("button",{type:"button",disabled:s||!f.trim(),onClick:()=>{L(f),h("")},className:"h-7 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-white/60 hover:text-white/85 transition disabled:opacity-35 disabled:cursor-not-allowed inline-flex items-center gap-1 shrink-0",children:[(0,lt.jsx)(br,{className:"h-2.5 w-2.5"}),"Use"]})]})]})})]})]}):null}var Ie=j($e(),1);var qg=j(Wn(),1);function rE(t){let e=t?.configSchema??{};return{required:Array.isArray(e.required)?e.required:[],properties:e.properties&&typeof e.properties=="object"?e.properties:{}}}var aE=new Set(["path","container-path","host-path"]);function JI(t){let e=rE(t),n=e.properties.root,r=n?.["x-neuralis"]?.ui,a=typeof r?.control=="string"?r.control:void 0;return{needed:!!(n&&(e.required.includes("root")||a&&aE.has(a))),container:a!=="host-path",label:typeof r?.label=="string"?r.label:"Path",placeholder:typeof r?.placeholder=="string"?r.placeholder:""}}var sn=j($e(),1);var QI=j(Wn(),1);var Ce=j(ie(),1);function ZI(t){if(!t)return null;let e=`${t.missing} missing \xB7 ${t.stale} stale`;return t.enabled?t.mode!=="dense"?`Semantic: metadata only \u2014 no embedding model active (${e})`:`Semantic: dense (${e})`:`Semantic: off \u2014 text and field search only (${e} if turned on)`}var Xo={gc:{label:"GC",explainer:"Removes records marked as deleted, older than the retention window.",tooltip:"Garbage-collect deleted records past the retention threshold (default 24h). Keeps recent deletions in case you want to restore.",destructive:!0},"repair-orphans":{label:"Repair",explainer:"Removes chunks whose parent document no longer exists or is deleted.",tooltip:"Drops orphaned chunks (parent file gone / deleted). Safe to run anytime \u2014 these chunks have no path back to a real file.",destructive:!0},"repair-pending":{label:"Repair pending",explainer:"Discards your pending changes whose file is gone with nothing to restore; counts older changes that need a review in Changes.",tooltip:"Run with Dry run first to see the counts. Only your own visible pending changes are touched; older changes with an unknown original are only reported \u2014 confirm them in the Changes panel. Nothing is reindexed.",destructive:!0},deduplicate:{label:"Deduplicate",explainer:"Reports document groups with identical content hash (read-only \u2014 no delete).",tooltip:"Lists documents that share a content hash. Read-only; nothing is removed.",destructive:!1}};function eL({agentId:t,projectId:e}){let n=H(A=>A.client),r=hn(),a=Ja({grantedFeatures:[...r.grantedFeatures??[]]},"drive.write"),[s,i]=(0,sn.useState)(null),[o,l]=(0,sn.useState)(null),[u,c]=(0,sn.useState)(!1),[d,f]=(0,sn.useState)(!1),[h,p]=(0,sn.useState)(null),[g,m]=(0,sn.useState)(null),[x,y]=(0,sn.useState)(null),[b,C]=(0,sn.useState)(null),[L,P]=(0,sn.useState)(!1),[w,k]=(0,sn.useState)(!1),[_,M]=(0,sn.useState)(24),[R,U]=(0,sn.useState)(null),v=(0,sn.useRef)(null),T=(0,sn.useCallback)(async()=>{c(!0),y(null);try{let[A,B]=await Promise.all([tx({agentId:t,...e?{projectId:e}:{}},n),fx({agentId:t,...e?{projectId:e}:{}},n).catch(()=>[])]),K=new Map;for(let ne of B)K.set(ne.source,{...ne.last_sync?{last_sync:ne.last_sync}:{},sync_status:ne.sync_status});let te=A;te.perSource&&(te.perSource=te.perSource.map(ne=>{let pe=K.get(ne.source);return pe?{...ne,...pe}:ne})),i(te)}catch(A){y(A instanceof Error?A.message:"Failed to fetch health report")}finally{c(!1)}},[t,e]),V=(0,sn.useCallback)(async()=>{P(!0),y(null);try{let A=await nx({agentId:t,...e?{projectId:e}:{}},n);C({orphanChunkCount:A.orphanChunkCount??0,duplicateGroups:A.duplicateGroups??0})}catch(A){y(A instanceof Error?A.message:"Scan failed")}finally{P(!1)}},[t,e]),Y=(0,sn.useCallback)(async A=>{if(!w&&Xo[A].destructive&&R!==A){U(A),v.current&&clearTimeout(v.current),v.current=setTimeout(()=>U(null),3e3);return}v.current&&(clearTimeout(v.current),v.current=null),U(null),f(!0),p(null),m(A),y(null),l(w?null:s);try{let B=await rx({agentId:t,...e?{projectId:e}:{},action:A,dryRun:w,retentionHours:_},n);p(B),w||(T(),b&&V())}catch(B){y(B instanceof Error?B.message:"Action failed")}finally{f(!1)}},[t,e,w,_,T,R,s,b,V]);(0,sn.useEffect)(()=>{T()},[T]),(0,sn.useEffect)(()=>()=>{v.current&&clearTimeout(v.current)},[]);function N(A){if(!o||!s)return null;let B=o[A]??0,K=s[A]??0;if(B===K)return null;let te=B-K,ne=te>0?"\u2212":"+";return`${B} \u2192 ${K} (${ne}${Math.abs(te)})`}return(0,Ce.jsxs)("div",{className:"space-y-3 px-2 pb-2",children:[(0,Ce.jsxs)("div",{className:"text-[10px] text-white/40 italic leading-relaxed",children:["Cleanup tool for the vector index. Removes leftover records:"," ",(0,Ce.jsx)("span",{className:"text-white/60",children:"deleted documents past retention"}),","," ",(0,Ce.jsx)("span",{className:"text-white/60",children:"orphaned chunks (no parent file)"}),", and reports"," ",(0,Ce.jsx)("span",{className:"text-white/60",children:"duplicate documents"})," (same content hash). To clear ALL vectors of a single source, use the"," ",(0,Ce.jsx)("span",{className:"text-rose-300/80",children:"Delete"})," button on that source instead."]}),u&&(0,Ce.jsxs)("div",{className:"text-[10px] text-white/40 flex items-center gap-1.5",children:[(0,Ce.jsx)(_t,{className:"h-3 w-3 animate-spin text-blue-400"})," Loading..."]}),x&&(0,Ce.jsx)("div",{className:"rounded-md bg-red-500/8 px-2.5 py-1.5 text-[10px] text-red-200/80",children:x}),s&&(0,Ce.jsxs)(Ce.Fragment,{children:[(0,Ce.jsx)("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-1.5",children:[{label:"Documents",value:s.documentCount??0,color:"text-emerald-400",delta:null},{label:"Chunks",value:s.chunkCount??0,color:"text-cyan-400",delta:null},{label:"Deleted",value:s.deletedCount??0,color:(s.deletedCount??0)>0?"text-red-400":"text-white/60",delta:g==="gc"?N("deletedCount"):null},{label:"Orphans",value:b?b.orphanChunkCount??0:"\u2014",color:(b?.orphanChunkCount??0)>0?"text-amber-400":"text-white/60",delta:null}].map(A=>(0,Ce.jsxs)("div",{className:"bg-white/[0.04] border border-white/[0.06] rounded-lg px-2 py-1.5 text-center",children:[(0,Ce.jsx)("div",{className:$("text-sm font-semibold",A.color),children:A.value}),(0,Ce.jsx)("div",{className:"text-[9px] text-white/40",children:A.label}),A.delta&&(0,Ce.jsx)("div",{className:"text-[8px] text-emerald-300/70 mt-0.5 tabular-nums",children:A.delta})]},A.label))}),ZI(s.embedding)&&(0,Ce.jsx)("div",{className:"text-[9px] text-white/45",role:"status",children:ZI(s.embedding)}),(0,Ce.jsxs)("div",{className:"flex items-center gap-3 text-[9px] text-white/35",children:[(0,Ce.jsxs)("span",{children:["Total points: ",s.totalPoints??"-"]}),(0,Ce.jsxs)("span",{children:["Duplicate groups: ",b?b.duplicateGroups??0:"\u2014"]}),s.generatedAt&&(()=>{let A=Date.now()-new Date(s.generatedAt).getTime(),B=Math.floor(A/6e4),K=Math.floor(B/60),te=B<1?"just now":K<1?`${B}m ago`:`${K}h ${B%60}m ago`,ne=K<1?"text-emerald-400/60":"text-amber-400/60";return(0,Ce.jsxs)("span",{className:ne,children:["Generated: ",te]})})()]}),s.perSource&&s.perSource.length>0&&(0,Ce.jsx)("div",{className:"bg-white/[0.04] border border-white/[0.06] rounded-lg overflow-hidden",children:(0,Ce.jsxs)("table",{className:"w-full text-[10px]",children:[(0,Ce.jsx)("thead",{children:(0,Ce.jsxs)("tr",{className:"border-b border-white/[0.06]",children:[(0,Ce.jsx)("th",{className:"text-left px-2 py-1.5 text-white/40 font-medium",children:"Source"}),(0,Ce.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Docs"}),(0,Ce.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Chunks"}),(0,Ce.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Deleted"}),(0,Ce.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Last sync"})]})}),(0,Ce.jsx)("tbody",{children:s.perSource.map((A,B)=>{let K=A.source.includes(":")?A.source.split(":")[0]:A.source,te=K==="local"?"text-cyan-400/60":K==="github"?"text-amber-400/60":"text-violet-400/60",ne=(()=>{if(!A.last_sync)return A.sync_status==="idle"?"\u2014":A.sync_status??"\u2014";let Se=new Date(A.last_sync).getTime();if(Number.isNaN(Se))return A.last_sync;let le=Math.floor((Date.now()-Se)/6e4);if(le<1)return"just now";if(le<60)return`${le}m ago`;let re=Math.floor(le/60);return re<24?`${re}h ago`:`${Math.floor(re/24)}d ago`})(),pe=A.last_sync?A.sync_status==="error"?"text-rose-300/60":A.sync_status==="paused"?"text-amber-300/60":"text-emerald-300/60":"text-white/35";return(0,Ce.jsxs)("tr",{className:$("border-b border-white/[0.03] last:border-0",B%2===1&&"bg-white/[0.02]"),children:[(0,Ce.jsxs)("td",{className:"px-2 py-1 text-white/70 font-mono flex items-center gap-1.5",children:[(0,Ce.jsx)(zn,{className:$("h-2.5 w-2.5 shrink-0",te)}),A.source]}),(0,Ce.jsx)("td",{className:"px-2 py-1 text-right text-emerald-300/60",children:A.documents}),(0,Ce.jsx)("td",{className:"px-2 py-1 text-right text-cyan-300/60",children:A.chunks}),(0,Ce.jsx)("td",{className:$("px-2 py-1 text-right",A.deleted>0?"text-red-300/60":"text-white/40"),children:A.deleted}),(0,Ce.jsx)("td",{className:$("px-2 py-1 text-right",pe),title:A.last_sync??`status: ${A.sync_status??"unknown"}`,children:ne})]},A.source)})})]})}),(0,Ce.jsxs)("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[(0,Ce.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,Ce.jsxs)("button",{type:"button",onClick:()=>{T()},disabled:u,title:"Refresh the cheap count stats for this project.",className:"px-2 py-1 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[10px] text-white/70 transition inline-flex items-center gap-1 disabled:opacity-40",children:[(0,Ce.jsx)(_t,{className:$("h-3 w-3 text-blue-400",u&&"animate-spin")}),"Refresh"]}),(0,Ce.jsxs)("button",{type:"button",onClick:()=>{V()},disabled:L,title:"Scan the whole index for orphan chunks and duplicate documents. Expensive \u2014 walks every point, so it runs only when you ask.",className:"px-2 py-1 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[10px] text-white/70 transition inline-flex items-center gap-1 disabled:opacity-40",children:[(0,Ce.jsx)(Ya,{className:$("h-3 w-3 text-amber-400",L&&"animate-pulse")}),b?"Re-scan":"Scan for problems"]}),(0,Ce.jsx)("span",{className:"text-white/10",children:"|"}),["gc","repair-orphans",...a?["repair-pending"]:[],"deduplicate"].map(A=>{let B=Xo[A],K=A==="gc"?Nt:A==="repair-orphans"?Rl:A==="repair-pending"?ws:na,te=A==="gc"?"text-amber-400":A==="repair-orphans"?"text-cyan-400":A==="repair-pending"?"text-rose-300":"text-violet-400",ne=R===A;return(0,Ce.jsxs)("button",{type:"button",onClick:()=>{Y(A)},disabled:d,title:B.tooltip,className:$("px-2 py-1 rounded-md text-[10px] transition inline-flex items-center gap-1 disabled:opacity-40",ne?"bg-rose-500/15 hover:bg-rose-500/25 text-rose-100 border border-rose-400/40":"bg-white/[0.04] hover:bg-white/[0.08] text-white/70"),children:[(0,Ce.jsx)(K,{className:$("h-3 w-3",te)}),ne?"Click again to confirm":B.label]},A)}),(0,Ce.jsx)("span",{className:"text-white/10",children:"|"}),(0,Ce.jsx)(QI.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-sources",packageId:"@neuralis/brain-core",scripts:["scripts/sync-status.sh","scripts/reindex.sh"],label:"Inspect sync status or reindex a source with the agent",icon:"Database"})]}),(0,Ce.jsxs)("div",{className:"flex items-center gap-3",children:[(0,Ce.jsxs)("label",{className:"inline-flex items-center gap-1 text-[10px] text-white/60 cursor-pointer",title:"Preview only \u2014 nothing will be deleted.",children:[(0,Ce.jsx)("input",{type:"checkbox",checked:w,onChange:A=>k(A.target.checked),className:"accent-emerald-400 h-3 w-3"}),"Dry run"]}),(0,Ce.jsxs)("label",{className:"inline-flex items-center gap-1 text-[10px] text-white/60",title:"Records marked as deleted within this many hours are kept (GC ignores them).",children:["Retention:",(0,Ce.jsx)("input",{type:"number",min:1,value:_,onChange:A=>M(Math.max(1,Number(A.target.value)||24)),className:"w-12 h-5 rounded px-1 text-[10px] bg-white/[0.04] border border-white/[0.08] text-white/80 outline-none"}),"h"]})]})]}),(0,Ce.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-1.5 text-[9px] text-white/40 leading-snug",children:[(0,Ce.jsxs)("div",{children:[(0,Ce.jsx)("span",{className:"text-amber-300/70 font-medium",children:"GC:"})," ",Xo.gc.explainer]}),(0,Ce.jsxs)("div",{children:[(0,Ce.jsx)("span",{className:"text-cyan-300/70 font-medium",children:"Repair:"})," ",Xo["repair-orphans"].explainer]}),(0,Ce.jsxs)("div",{children:[(0,Ce.jsx)("span",{className:"text-violet-300/70 font-medium",children:"Deduplicate:"})," ",Xo.deduplicate.explainer]}),a?(0,Ce.jsxs)("div",{children:[(0,Ce.jsx)("span",{className:"text-rose-300/70 font-medium",children:"Repair pending:"})," ",Xo["repair-pending"].explainer]}):null]}),h&&(0,Ce.jsxs)("div",{className:"bg-white/[0.04] border border-white/[0.06] rounded-lg px-2.5 py-2 text-[10px] text-white/60 space-y-0.5",children:[(0,Ce.jsxs)("div",{className:"text-[10px] text-white/50 font-medium mb-1 flex items-center justify-between",children:[(0,Ce.jsx)("span",{children:"Last Action Result"}),typeof h.removed=="number"&&(0,Ce.jsxs)("span",{className:$("font-mono tabular-nums",h.dryRun?"text-amber-300/80":"text-emerald-300/85"),children:[h.dryRun?"Would remove":"Removed",": ",h.removed]})]}),Object.entries(h).map(([A,B])=>(0,Ce.jsxs)("div",{className:"flex justify-between",children:[(0,Ce.jsx)("span",{className:"text-white/40",children:A}),(0,Ce.jsx)("span",{className:"text-white/70 font-mono",children:typeof B=="object"?JSON.stringify(B):String(B)})]},A))]})]})]})}var nn=j($e(),1);var De=j(ie(),1),sE=["member","owner","admin"],Cf=["read","write","exec"];function iE(t){return{default:{...t.default},...t.byRole?{byRole:Ug(t.byRole)}:{},...t.byUser?{byUser:Ug(t.byUser)}:{},...t.byAgent?{byAgent:Ug(t.byAgent)}:{},paths:(t.paths??[]).map(e=>({...e,permissions:{...e.permissions},...e.roles?{roles:[...e.roles]}:{},...e.agents?{agents:[...e.agents]}:{},...e.users?{users:[...e.users]}:{}}))}}function Ug(t){let e={};for(let[n,r]of Object.entries(t))e[n]={...r};return e}function oE(t){return{pattern:`${t}://`,permissions:{read:!0,write:!1,exec:!1}}}function Gg({letter:t,state:e,onClick:n,disabled:r,title:a}){let s=e===!0?"bg-emerald-500/20 text-emerald-200 border-emerald-400/30":e===!1?"bg-rose-500/15 text-rose-200/80 border-rose-400/25":"bg-white/[0.04] text-white/35 border-white/[0.08]";return(0,De.jsx)("button",{type:"button",title:a??`${t} \u2014 ${e===!0?"allow":e===!1?"deny":"inherit"}`,disabled:r,onClick:n,className:$("inline-flex items-center justify-center w-5 h-5 rounded text-[9px] font-bold tabular-nums border transition disabled:cursor-default",s,!r&&"hover:brightness-125"),children:t})}function Wg(t){return t==="read"?"R":t==="write"?"W":"X"}function tL(t,e){if(!e)return!t;if(t===void 0)return!0;if(t===!0)return!1}function zg({source:t,permissions:e,mode:n,onSave:r,knownRoles:a=sE}){let[s,i]=(0,nn.useState)(()=>iE(e)),[o,l]=(0,nn.useState)(!1),[u,c]=(0,nn.useState)(null),[d,f]=(0,nn.useState)(""),[h,p]=(0,nn.useState)(""),[g,m]=(0,nn.useState)(""),x=(0,nn.useMemo)(()=>JSON.stringify(s)!==JSON.stringify(e),[s,e]),y=n==="view",b=(0,nn.useCallback)((N,A)=>{i(B=>({...B,default:{...B.default,[N]:A}}))},[]),C=N=>N,L=(0,nn.useCallback)((N,A)=>{let B=A.trim();B&&i(K=>{let te={...K[C(N)]??{}};return B in te?K:(te[B]={},{...K,[C(N)]:te})})},[]),P=(0,nn.useCallback)((N,A)=>{i(B=>{let K={...B[C(N)]??{}};return delete K[A],Object.keys(K).length===0?{...B,[C(N)]:void 0}:{...B,[C(N)]:K}})},[]),w=(0,nn.useCallback)((N,A,B)=>{i(K=>{let te={...K[C(N)]??{}},ne=te[A]??{},pe=tL(ne[B],!0),Se={...ne};return pe===void 0?delete Se[B]:Se[B]=pe,te[A]=Se,{...K,[C(N)]:te}})},[]),k=(0,nn.useCallback)((N,A)=>{i(B=>{let K=[...B.paths??[]];return K[N]={...K[N],...A},{...B,paths:K}})},[]),_=(0,nn.useCallback)((N,A)=>{i(B=>{let K=[...B.paths??[]],te=K[N],ne=tL(te.permissions[A],!0),pe={...te.permissions};return ne===void 0?delete pe[A]:pe[A]=ne,K[N]={...te,permissions:pe},{...B,paths:K}})},[]),M=(0,nn.useCallback)((N,A)=>{i(B=>{let K=[...B.paths??[]],te=K[N],ne=new Set(te.roles??[]);return ne.has(A)?ne.delete(A):ne.add(A),K[N]=ne.size>0?{...te,roles:[...ne]}:{...te,roles:void 0},{...B,paths:K}})},[]),R=(0,nn.useCallback)((N,A,B)=>{let K=B.trim();K&&i(te=>{let ne=[...te.paths??[]],pe=ne[N],Se=new Set(pe[A]??[]);return Se.add(K),ne[N]={...pe,[A]:[...Se]},{...te,paths:ne}})},[]),U=(0,nn.useCallback)((N,A,B)=>{i(K=>{let te=[...K.paths??[]],ne=te[N],pe=(ne[A]??[]).filter(Se=>Se!==B);return te[N]={...ne,[A]:pe.length>0?pe:void 0},{...K,paths:te}})},[]),v=(0,nn.useCallback)(()=>{i(N=>({...N,paths:[oE(t),...N.paths??[]]}))},[t]),T=(0,nn.useCallback)(N=>{i(A=>({...A,paths:(A.paths??[]).filter((B,K)=>K!==N)}))},[]),V=(0,nn.useCallback)(async()=>{if(r){l(!0),c(null);try{await r(s)}catch(N){c(N instanceof Error?N.message:String(N))}finally{l(!1)}}},[s,r]),Y=(N,A,B,K,te)=>{let ne=s[C(N)]??{},pe=Object.entries(ne),[Se,le]=te;return(0,De.jsxs)("div",{className:"space-y-1",children:[(0,De.jsxs)("div",{className:"flex items-center gap-2",children:[(0,De.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40",children:A}),(0,De.jsx)("span",{className:"text-[9px] text-white/30 italic flex-1 truncate",children:B})]}),pe.length===0&&y?(0,De.jsx)("div",{className:"text-[9px] text-white/25 italic",children:"No overrides."}):null,pe.map(([re,he])=>(0,De.jsxs)("div",{className:"flex items-center gap-1.5 text-[10px]",children:[(0,De.jsx)("span",{className:"font-mono text-white/70 truncate min-w-[72px]",children:re}),Cf.map(Ne=>(0,De.jsx)(Gg,{letter:Wg(Ne),state:he[Ne],onClick:y?void 0:()=>w(N,re,Ne),disabled:y},Ne)),!y&&(0,De.jsx)("button",{type:"button",onClick:()=>P(N,re),className:"ml-auto text-white/30 hover:text-rose-300 transition",title:"Remove override",children:(0,De.jsx)(Nt,{className:"w-3 h-3"})})]},re)),!y&&(0,De.jsxs)("div",{className:"flex items-center gap-1.5 pt-0.5",children:[(0,De.jsx)("input",{type:"text",value:Se,onChange:re=>le(re.target.value),onKeyDown:re=>{re.key==="Enter"&&(re.preventDefault(),L(N,Se),le(""))},placeholder:K,className:"h-6 flex-1 rounded bg-white/[0.04] border border-white/[0.08] px-2 text-[10px] text-white/80 placeholder:text-white/25 outline-none focus:border-white/20"}),(0,De.jsxs)("button",{type:"button",onClick:()=>{L(N,Se),le("")},className:"h-6 px-2 rounded bg-white/[0.05] border border-white/[0.08] text-[9px] font-semibold text-white/65 hover:text-white/90 hover:bg-white/[0.08] transition inline-flex items-center gap-1",children:[(0,De.jsx)(Fn,{className:"w-2.5 h-2.5"}),"Add"]})]})]})};return(0,De.jsxs)("div",{className:"flex flex-col gap-3 text-[10px]",children:[(0,De.jsx)("div",{className:"space-y-1",children:(0,De.jsxs)("div",{className:"flex items-center gap-2",children:[(0,De.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40",children:"Default"}),(0,De.jsxs)("span",{className:"text-[9px] text-white/30 italic flex-1 truncate",children:["Base access for ",t,"://*"]}),(0,De.jsx)("div",{className:"flex items-center gap-1",children:Cf.map(N=>(0,De.jsx)(Gg,{letter:Wg(N),state:s.default[N],onClick:y?void 0:()=>b(N,!s.default[N]),disabled:y},N))})]})}),Y("byRole","By Role","Override default for specific roles.","role (e.g. admin)",[d,f]),Y("byUser","By User","Override for specific users (highest priority after paths).","userId",[h,p]),Y("byAgent","By Agent","$self = the agent owning the file.","$self or agentId",[g,m]),(0,De.jsxs)("div",{className:"space-y-1",children:[(0,De.jsxs)("div",{className:"flex items-center gap-2",children:[(0,De.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40",children:"Path Rules"}),(0,De.jsx)("span",{className:"text-[9px] text-white/30 italic flex-1 truncate",children:"Fine-grained rules per path/glob \u2014 first match wins."}),!y&&(0,De.jsxs)("button",{type:"button",onClick:v,className:"h-6 px-2 rounded bg-white/[0.05] border border-white/[0.08] text-[9px] font-semibold text-white/65 hover:text-white/90 hover:bg-white/[0.08] transition inline-flex items-center gap-1",children:[(0,De.jsx)(Fn,{className:"w-2.5 h-2.5"}),"Rule"]})]}),(s.paths??[]).length===0?(0,De.jsx)("div",{className:"text-[9px] text-white/25 italic",children:"No rules \u2014 Default applies everywhere."}):(0,De.jsx)("ul",{className:"space-y-1",children:(s.paths??[]).map((N,A)=>(0,De.jsxs)("li",{className:"rounded bg-white/[0.02] border border-white/[0.05] px-2 py-1.5 space-y-1.5",children:[(0,De.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,De.jsx)("input",{type:"text",disabled:y,value:N.pattern,onChange:B=>k(A,{pattern:B.target.value}),placeholder:`${t}://path/**`,className:"flex-1 min-w-0 h-6 rounded bg-white/[0.04] border border-white/[0.08] px-2 text-[10px] font-mono text-white/85 outline-none focus:border-white/20 disabled:opacity-70"}),Cf.map(B=>(0,De.jsx)(Gg,{letter:Wg(B),state:N.permissions[B],onClick:y?void 0:()=>_(A,B),disabled:y},B)),(0,De.jsx)("button",{type:"button",disabled:y,onClick:()=>k(A,{override:N.override?void 0:!0}),title:"Override deny-wins precedence",className:$("h-5 px-1.5 rounded text-[8px] font-semibold border transition disabled:cursor-default",N.override?"bg-amber-500/15 text-amber-200 border-amber-400/30":"bg-white/[0.04] text-white/35 border-white/[0.08] hover:text-white/65"),children:"OVR"}),!y&&(0,De.jsx)("button",{type:"button",onClick:()=>T(A),title:"Remove rule",className:"text-white/30 hover:text-rose-300 transition",children:(0,De.jsx)(Nt,{className:"w-3 h-3"})})]}),(0,De.jsxs)("div",{className:"flex flex-wrap items-center gap-1 text-[9px] text-white/50",children:[(0,De.jsx)("span",{className:"text-white/35 mr-0.5",children:"Roles:"}),a.map(B=>{let K=(N.roles??[]).includes(B);return(0,De.jsx)("button",{type:"button",disabled:y,onClick:()=>M(A,B),className:$("h-5 px-1.5 rounded border text-[9px] font-medium capitalize transition disabled:cursor-default",K?"bg-cyan-500/15 text-cyan-200 border-cyan-400/30":"bg-white/[0.04] text-white/40 border-white/[0.08] hover:text-white/70"),children:B},B)}),(N.roles??[]).length===0&&(0,De.jsx)("span",{className:"italic text-white/30",children:"all roles"})]}),(0,De.jsx)(nL,{label:"Agents",values:N.agents??[],emptyLabel:"any agent",placeholder:"$self / agentId",readOnly:y,onAdd:B=>R(A,"agents",B),onRemove:B=>U(A,"agents",B)}),(0,De.jsx)(nL,{label:"Users",values:N.users??[],emptyLabel:"any user",placeholder:"$owner / userId",readOnly:y,onAdd:B=>R(A,"users",B),onRemove:B=>U(A,"users",B)}),(N.users??[]).length>0&&!lE(N)&&(0,De.jsx)("div",{className:"text-[9px] text-amber-200/80",children:"Users apply only to an allow rule: turn on OVR and set every bit to allow."})]},A))})]}),!y&&(0,De.jsxs)("div",{className:"flex items-center justify-between gap-2 pt-1",children:[u&&(0,De.jsx)("span",{className:"text-[9px] text-rose-300/80",children:u}),(0,De.jsxs)("button",{type:"button",onClick:V,disabled:!x||o,className:$("ml-auto inline-flex items-center gap-1 h-6 px-2.5 rounded bg-emerald-500/15 border border-emerald-400/30 text-[10px] font-semibold text-emerald-200 hover:bg-emerald-500/25 transition",(!x||o)&&"opacity-40 cursor-default"),children:[(0,De.jsx)(li,{className:"w-3 h-3"}),o?"Saving\u2026":"Save policy"]})]})]})}function lE(t){let e=Cf.map(n=>t.permissions[n]).filter(n=>n!==void 0);return t.override===!0&&e.length>0&&e.every(n=>n===!0)}function nL({label:t,values:e,emptyLabel:n,placeholder:r,readOnly:a,onAdd:s,onRemove:i}){return(0,De.jsxs)("div",{className:"flex flex-wrap items-center gap-1 text-[9px] text-white/50",children:[(0,De.jsxs)("span",{className:"text-white/35 mr-0.5",children:[t,":"]}),e.map(o=>(0,De.jsxs)("span",{className:"inline-flex items-center gap-1 h-5 px-1.5 rounded bg-violet-500/12 text-violet-200 border border-violet-400/25",children:[(0,De.jsx)("span",{className:"font-mono",children:o}),!a&&(0,De.jsx)("button",{type:"button",onClick:()=>i(o),className:"text-violet-200/60 hover:text-rose-300",title:`Remove ${o}`,children:"\xD7"})]},o)),e.length===0&&(0,De.jsx)("span",{className:"italic text-white/30",children:n}),!a&&(0,De.jsx)(uE,{placeholder:r,onAdd:s})]})}function uE({placeholder:t,onAdd:e}){let[n,r]=(0,nn.useState)("");return(0,De.jsxs)("div",{className:"inline-flex items-center gap-1",children:[(0,De.jsx)("input",{type:"text",value:n,onChange:a=>r(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),e(n),r(""))},placeholder:t,className:"h-5 rounded bg-white/[0.04] border border-white/[0.08] px-1.5 text-[9px] font-mono text-white/75 placeholder:text-white/25 outline-none focus:border-white/20 w-[120px]"}),(0,De.jsx)("button",{type:"button",onClick:()=>{e(n),r("")},className:"text-white/40 hover:text-white/80 transition",title:"Add",children:(0,De.jsx)(Fn,{className:"w-3 h-3"})})]})}var rL=j($e(),1);var Kt=j(ie(),1);function aL({source:t,vectorCount:e,isDockerMount:n,busy:r,onCancel:a,onConfirm:s}){let[i,o]=(0,rL.useState)(!1);return(0,Kt.jsxs)("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/5 p-2.5 mt-1.5 ml-5 mb-1 space-y-2",children:[(0,Kt.jsxs)("div",{className:"flex items-start gap-2",children:[(0,Kt.jsx)(ot,{className:"h-3.5 w-3.5 text-rose-300 shrink-0 mt-0.5"}),(0,Kt.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,Kt.jsxs)("div",{className:"text-[11px] font-semibold text-white/90",children:["Delete ",(0,Kt.jsx)("span",{className:"font-mono text-rose-200",children:t}),"?"]}),(0,Kt.jsxs)("div",{className:"text-[10px] text-white/55 mt-0.5",children:["The source config and connector binding are removed."," ",(0,Kt.jsx)("span",{className:"text-white/75",children:"The host folder is not touched"})," ","\u2014 your files stay where they are."]})]})]}),(0,Kt.jsxs)("label",{className:"flex items-start gap-2 cursor-pointer rounded px-1.5 py-1 hover:bg-white/[0.03]",children:[(0,Kt.jsx)("input",{type:"checkbox",checked:i,onChange:l=>o(l.target.checked),className:"accent-rose-400 h-3 w-3 mt-0.5"}),(0,Kt.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,Kt.jsxs)("div",{className:"text-[10px] font-medium text-white/80",children:["Purge vector index entries",e!==null&&(0,Kt.jsxs)("span",{className:"text-white/40 ml-1.5 tabular-nums",children:["(~",e," point",e===1?"":"s",")"]})]}),(0,Kt.jsxs)("div",{className:"text-[9px] text-white/40 leading-relaxed",children:["Removes every Qdrant point whose URI maps back to"," ",(0,Kt.jsxs)("code",{className:"font-mono text-white/55",children:[t,"://"]}),". Otherwise the vectors stay and Vector Health \u2192 Repair will mop them up later."]})]})]}),n&&(0,Kt.jsxs)("div",{className:"rounded bg-amber-500/8 border border-amber-400/20 px-2 py-1.5 text-[9px] italic text-amber-100/70 leading-relaxed",children:["Docker bind-mount source. This deletes the source config (and vectors, if checked). To also drop the underlying compose bind, run the infra-only:"," ",(0,Kt.jsxs)("code",{className:"font-mono not-italic text-amber-100/90",children:["neuralis mount remove ",t]})]}),(0,Kt.jsxs)("div",{className:"flex items-center justify-end gap-1.5 pt-0.5",children:[(0,Kt.jsxs)("button",{type:"button",onClick:a,disabled:r,className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[10px] font-medium text-white/70 transition disabled:opacity-40 inline-flex items-center gap-1",children:[(0,Kt.jsx)(Ht,{className:"h-2.5 w-2.5"}),"Cancel"]}),(0,Kt.jsxs)("button",{type:"button",onClick:()=>s({purgeVectors:i}),disabled:r,className:$("h-6 px-2.5 rounded-md text-[10px] font-semibold transition disabled:opacity-40 inline-flex items-center gap-1","bg-rose-500/20 hover:bg-rose-500/30 border border-rose-400/40 text-rose-100"),children:[r?(0,Kt.jsx)(We,{className:"h-2.5 w-2.5 animate-spin"}):(0,Kt.jsx)(Nt,{className:"h-2.5 w-2.5"}),"Delete",i?" + Purge":""]})]})]})}var S=j(ie(),1),jg={exclude:[],trigger:"manual"},cE=[{value:"manual",label:"Manual"},{value:"auto",label:"Auto (watch + reconcile)"},{value:"interval",label:"On schedule"}],dE=[{value:"s",label:"sec"},{value:"m",label:"min"},{value:"h",label:"hr"},{value:"d",label:"day"}],$g="Mounted (user-added)";function fE(t){return t&&t.trim().length>0?t:$g}function hE(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,24)||"agent"}function Pf(t){return t.toLowerCase().replace(/[^a-z0-9-]+/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"").slice(0,40)}function pE(t){return t.split(/[/\\]/).filter(Boolean).pop()??null}function mE(t){if(t?.name){let e=Pf(t.name);if(e)return e}if(t?.email){let e=Pf(t.email.split("@")[0]??"");if(e)return e}return"user"}function lL(t){let{baseName:e,meta:n,scope:r,ids:a}=t,i=(e?Pf(e):"")||(n?.urlScheme||n?.kind||"source").toLowerCase().replace(/[^a-z0-9-]+/g,"-");return r==="project"?i:r==="user"?`${i}-${a.userSlug||"user"}`:`${i}-${a.agentSlug||hE(a.agentId)}`}function gE(t){return t?.allowedScopes?.length?t.allowedScopes:["project","user","agent"]}function Kg(t){return!!t?.capabilities.includes("scanDelta")}function Xg(t){let e=t?.configSchema??{};return{required:Array.isArray(e.required)?e.required:[],properties:e.properties&&typeof e.properties=="object"?e.properties:{}}}function xE(t){let e=Xg(t),n={};for(let[r,a]of Object.entries(e.properties)){if(r==="root")continue;let s=a.default;(typeof s=="string"||typeof s=="number"||typeof s=="boolean")&&(n[r]=s)}return n}function uL(t){let e=t?.defaultPermissions?.default;return{read:typeof e?.read=="boolean"?e.read:!0,write:typeof e?.write=="boolean"?e.write:!1,exec:typeof e?.exec=="boolean"?e.exec:!1}}function $u(t,e){let n=t?.defaultScope??"project",r=uL(t);return{key:lL({baseName:null,meta:t,scope:n,ids:e}),path:"",scope:n,...r,syncEnabled:Kg(t),exclude:Lf(t?.defaultSyncExcludes??[]),include:"",trigger:"manual",description:"",config:xE(t),policies:[],recognizesPackages:!1}}function Ku(t){return t.split(/\r?\n|,/).map(e=>e.trim()).filter(Boolean)}function Lf(t){return Array.isArray(t)?t.join(`
|
|
44
|
-
`):""}function
|
|
45
|
-
`);return s(r.exclude)!==s(a.exclude)||s(r.include)!==s(a.include)||r.maxScanFiles!==a.maxScanFiles}function cL(t){if(t==="auto"||t==="on_change")return{mode:"auto",val:"5",unit:"m"};let e=/^interval:(\d+)([smhd])$/.exec(t);return e?{mode:"interval",val:e[1],unit:e[2]}:{mode:"manual",val:"5",unit:"m"}}function Af(t){return t==="s"?30:1}function Vg(t,e,n){if(t!=="interval")return t;let r=Number.parseInt(e,10);return`interval:${Number.isFinite(r)?Math.max(r,Af(n)):5}${n}`}function kE(t){let e=cL(t);return e.mode==="manual"?"Manual":e.mode==="auto"?"Auto":`Every ${e.val}${e.unit}`}function SE(t,e){let n=t.connection.config??{};for(let[r,a]of Object.entries(n)){if(typeof a=="string"&&a.length>0)return a;if(typeof a=="number")return String(a)}return e?.label??t.connection.kind}function CE(t,e){let n=t.permissions??uL(e);return{source:qe(t.uri_root),source_kind:t.source_kind,scope:{kind:"project"},createdBy:"runtime",connection:{kind:t.source_kind,config:{}},permissions:{default:n},sync_status:t.sync_status,last_updated:t.last_updated,kind_label:e?.label??t.source_kind,kind_trust:e?.trust??null,observed:!0,...t.origin_package?{origin_package:t.origin_package}:{},...t.live!==void 0?{live:t.live}:{},...t.live_reason?{live_reason:t.live_reason}:{}}}function IE(t,e){return JSON.stringify(Yo(t))!==JSON.stringify(e)}function oL(t){if(!t)return"never";let e=Date.now()-new Date(t).getTime();return e<6e4?"just now":e<36e5?`${Math.floor(e/6e4)}m ago`:e<864e5?`${Math.floor(e/36e5)}h ago`:`${Math.floor(e/864e5)}d ago`}var Wi=$("h-7 w-full rounded-md px-2 text-[10px] outline-none transition","bg-white/[0.04] border border-white/[0.08] text-white/86","focus:border-white/[0.18] focus:bg-white/[0.06]","placeholder:text-white/28"),If=$(Wi,"pr-6 font-mono"),Xu=$("w-full rounded-md px-2 py-1.5 text-[10px] font-mono outline-none resize-y transition","bg-white/[0.04] border border-white/[0.08] text-white/86","focus:border-white/[0.18] focus:bg-white/[0.06]","placeholder:text-white/28");function dL(t){let e=H(E=>E.client),{agentId:n,projectId:r,isDocker:a}=t,s=H(E=>E.workspacePanels.sources),i=H(E=>E.setWorkspacePanelOpen),o=H(E=>E.pendingSourceSuggestion),l=H(E=>E.setPendingSourceSuggestion),u=H(E=>E.refresh),c=H(E=>E.sources),d=hn(),f=d.useAgents(),h=(0,Ie.useMemo)(()=>mE(d.currentUser),[d.currentUser]),p=(d.currentRole?.priority??99)<=2,g=(0,Ie.useMemo)(()=>oo({grantedFeatures:[...d.grantedFeatures??[]]},{features:["drive.mount"]}),[d.grantedFeatures]),m=(0,Ie.useMemo)(()=>{let E=f.byId[n]?.name;return E?Pf(E):void 0},[f,n]),x=(0,Ie.useMemo)(()=>({userSlug:h,agentSlug:m,agentId:n}),[h,m,n]),[y,b]=(0,Ie.useState)([]),[C,L]=(0,Ie.useState)({}),[P,w]=(0,Ie.useState)({}),[k,_]=(0,Ie.useState)({}),[M,R]=(0,Ie.useState)(new Set),[U,v]=(0,Ie.useState)({}),[T,V]=(0,Ie.useState)(!1),[Y,N]=(0,Ie.useState)(null),[A,B]=(0,Ie.useState)(null),[K,te]=(0,Ie.useState)(null),[ne,pe]=(0,Ie.useState)(null),[Se,le]=(0,Ie.useState)(null),[re,he]=(0,Ie.useState)(null),[Ne,Ee]=(0,Ie.useState)(null),[ze,ct]=(0,Ie.useState)(null),[it,Qe]=(0,Ie.useState)(null),[Ye,Lt]=(0,Ie.useState)(null),[Le,at]=(0,Ie.useState)({}),[ft,bt]=(0,Ie.useState)(null),[At,Tt]=(0,Ie.useState)("source"),[Ue,me]=(0,Ie.useState)(""),[Ot,Jt]=(0,Ie.useState)(!0),[ue,be]=(0,Ie.useState)(null),[Ge,Re]=(0,Ie.useState)(!1),Te=(0,Ie.useRef)(0);(0,Ie.useEffect)(()=>{Te.current++,bt(null),be(null)},[n,r]);let[vt,mt]=(0,Ie.useState)(null),[Gt,je]=(0,Ie.useState)(!1),[kt,on]=(0,Ie.useState)("project"),[Oe,ee]=(0,Ie.useState)(()=>$u(null,x)),oe=(0,Ie.useRef)(Oe.key),He=(0,Ie.useRef)(!0);(0,Ie.useEffect)(()=>(He.current=!0,()=>{He.current=!1}),[]);let[Ve,Ae]=(0,Ie.useState)(!1),ce=H(E=>E.vectorHealthOpen),Pt=H(E=>E.setVectorHealthOpen),[Ft,Zt]=(0,Ie.useState)(!1),[dn,rr]=(0,Ie.useState)(!1),[qr,Mn]=(0,Ie.useState)([]),[Yn,$r]=(0,Ie.useState)("/"),[ar,Pr]=(0,Ie.useState)(!1),[Kr,ln]=(0,Ie.useState)(null),[Jn,Wt]=(0,Ie.useState)([]),[gr,Un]=(0,Ie.useState)(!1),[Nr,pa]=(0,Ie.useState)([]),[fn,Xr]=(0,Ie.useState)("local"),[ma,xn]=(0,Ie.useState)(null),[Tn,z]=(0,Ie.useState)([]);(0,Ie.useEffect)(()=>{let E=!1;return hx(e).then(Q=>{if(E)return;pa(Q.kinds??[]),xn(null);let O=Q.kinds?.find(ge=>ge.kind==="local")??Q.kinds?.[0]??null;if(O){Xr(O.kind);let ge=$u(O,x);oe.current=ge.key,ee(ge)}}).catch(Q=>{E||xn(Q instanceof Error?Q.message:"Failed to load source kinds")}),()=>{E=!0}},[n]);let I=(0,Ie.useMemo)(()=>{let E=new Map;for(let Q of Nr)E.set(Q.kind,Q);return E},[Nr]),q=I.get(fn)??null,F=Kg(q),de=JI(q),D=de.needed,xe=D&&de.container,Mt=(0,Ie.useCallback)(E=>{let Q=$u(I.get(E.suggestedKind)??null,x),O=E.suggestedConfig.root??"",ge=E.suggestedConfig.hostRoot;Xr(E.suggestedKind),oe.current=E.suggestedScheme,ee({...Q,key:E.suggestedScheme,path:O,...E.suggestedScope?{scope:E.suggestedScope}:{},...E.syncDisabled?{syncEnabled:!1}:{},...E.suggestedSync?.include?{include:Lf(E.suggestedSync.include)}:{},...E.suggestedSync?.trigger?{trigger:E.suggestedSync.trigger}:{},...E.suggestedPolicies?.length?{policies:E.suggestedPolicies}:{},...E.description?{description:E.description}:{},...E.suggestedAccess??{},config:{...Q.config,...ge&&Xg(I.get(E.suggestedKind)??null).properties.hostRoot?{hostRoot:ge}:{}}}),je(!0)},[I,x]);(0,Ie.useEffect)(()=>{o&&I.size!==0&&(l(null),Mt(o))},[o,I,Mt,l]);let zt=(0,Ie.useCallback)((E,Q)=>lL({baseName:Q?pE(Q):null,meta:q,scope:E,ids:x}),[q,x]),yn=E=>E===""||E===oe.current,Sn=(0,Ie.useCallback)(async()=>{if(r){V(!0),N(null);try{let[E,Q]=await Promise.all([P0({agentId:n,projectId:r,scope:kt},e),ic({agentId:n,projectId:r},e).catch(()=>({suggestions:[]}))]);b(E),L(Object.fromEntries(E.map(O=>[O.source,Yo(O)]))),w(O=>Object.fromEntries(E.map(ge=>[ge.source,O[ge.source]??!1]))),z(Q.suggestions??[])}catch(E){N(E instanceof Error?E.message:"Failed to load sources")}finally{V(!1)}}},[kt,n,r]);(0,Ie.useEffect)(()=>{s&&Sn()},[s,Sn]),(0,Ie.useEffect)(()=>{s&&n&&u({agentId:n,projectId:r})},[s,n,r,u]);let nc=(0,Ie.useCallback)(async E=>{if(!n||k[E])return;let Q=!1;if(R(O=>{if(O.has(E))return Q=!0,O;let ge=new Set(O);return ge.add(E),ge}),!Q)try{let O=await A0(n,r??void 0,E,e);O&&_(ge=>({...ge,[E]:O}))}catch{}finally{R(O=>{if(!O.has(E))return O;let ge=new Set(O);return ge.delete(E),ge})}},[n,r,k]),ll=(0,Ie.useCallback)(E=>{_(Q=>{if(!(E in Q))return Q;let O={...Q};return delete O[E],O})},[]),w2=(0,Ie.useCallback)(E=>{w(Q=>{let O=!Q[E];return O&&nc(E),{...Q,[E]:O}})},[nc]);(0,Ie.useEffect)(()=>{if(!Ne)return;let E=setTimeout(()=>Ee(null),4e3);return()=>clearTimeout(E)},[Ne]),(0,Ie.useEffect)(()=>{!Gt||!a||!g||(Un(!0),eh({path:"/mounts",agentId:n,...r?{projectId:r}:{}},e).then(E=>{let Q=new Set(y.map(ge=>ge.source)),O=E.entries.filter(ge=>!Q.has(ge.name));Wt(O)}).catch(()=>Wt([])).finally(()=>Un(!1)))},[Gt,a,g,n,r,y]);let rc=(0,Ie.useMemo)(()=>{let E=new Set,Q=y.map(O=>{E.add(O.source);let ge=c.find(Qt=>qe(Qt.uri_root)===O.source),qt=k[O.source]??ge;return{...O,connector_count:qt?.on_disk,connector_truncated:qt?.truncated,indexed_count:qt?.indexed_count,unindexed_count:qt?.unindexed,last_updated:ge?.last_updated??O.last_updated,sync_status:O.sync?.status??ge?.sync_status??O.sync_status,live:ge?.live,live_reason:ge?.live_reason,kind_icon:ge?.kind_icon}});if(kt==="project")for(let O of c){let ge=qe(O.uri_root);if(!ge||E.has(ge))continue;let qt=I.get(O.source_kind)??null,Qt=k[ge]??O;Q.push({...CE(O,qt),connector_count:Qt.on_disk,connector_truncated:Qt.truncated,indexed_count:Qt.indexed_count,unindexed_count:Qt.unindexed,kind_icon:O.kind_icon})}return Q},[kt,y,I,c,k]),v2=(0,Ie.useMemo)(()=>{let E=new Map;for(let Q of rc){let O=fE(Q.origin_package),ge=E.get(O);ge?ge.push(Q):E.set(O,[Q])}return[...E.entries()].sort(([Q],[O])=>Q===$g?1:O===$g?-1:Q.localeCompare(O))},[rc]),Yr=(E,Q)=>{L(O=>({...O,[E]:Q(O[E])}))},Wf=(E,Q)=>{v(O=>({...O,[E]:{...O[E]??{},[Q]:!(O[E]?.[Q]??!1)}}))},k2=async(E,Q)=>{B(E.source),N(null);try{let O=!Q.sync&&!!E.sync,ge=p&&E.connection.kind==="local",{recognizesPackages:qt,...Qt}=Q,Jr=await Zf({agentId:n,...r?{projectId:r}:{},config:{...ge?Q:Qt,...O?{clearSync:!0}:{}}},e);b(za=>za.map(ja=>ja.source===Jr.source?Jr:ja)),L(za=>({...za,[Jr.source]:Yo(Jr)})),vE(E,Q,O)?(await u({agentId:n,projectId:r,withCounts:!0}),ll(E.source)):await u({agentId:n,projectId:r})}catch(O){N(O instanceof Error?O.message:"Save failed")}finally{B(null)}},S2=(0,Ie.useCallback)(async(E,Q)=>{let O=C[E.source]??Yo(E);B(E.source),N(null);try{let ge=await Zf({agentId:n,...r?{projectId:r}:{},config:{...O,permissions:Q}},e);b(qt=>qt.map(Qt=>Qt.source===ge.source?ge:Qt)),L(qt=>({...qt,[ge.source]:Yo(ge)})),await u({agentId:n,projectId:r})}catch(ge){throw N(ge instanceof Error?ge.message:"Save failed"),ge}finally{B(null)}},[n,C,r,u]),c0=(0,Ie.useCallback)(async E=>{for(let ge=0;ge<2400;ge++){if(await new Promise(Wa=>setTimeout(Wa,1500)),!He.current)return null;let Qt=(await R0({agentId:n,...r?{projectId:r}:{},source:E},e)).job;if(!Qt)return null;if(!(Qt.status==="pending"||Qt.status==="running")){if(Qt.status==="failed")throw new Error(Qt.error??Qt.result?.error??"Sync failed");return Qt}}return null},[n,r]);if(!s)return null;let C2=async E=>{te(E),N(null);try{await N0({agentId:n,...r?{projectId:r}:{},source:E},e),await c0(E),await Sn(),await u({agentId:n,projectId:r,withCounts:!0}),ll(E)}catch(Q){N(Q instanceof Error?Q.message:"Sync failed")}finally{te(null)}},I2=async E=>{try{await dx({agentId:n,...r?{projectId:r}:{},...E?{source:E}:{}},e),te(null),pe(null)}catch(Q){N(Q instanceof Error?Q.message:"Cancel failed")}},ac=async(E,Q,O)=>{pe(E),N(null);try{await Q();let ge=await c0(E),qt=ge?.status==="paused"?ge.result?.embedding?.pausedReason??"paused":null;at(Qt=>{let{[E]:Wa,...Jr}=Qt;return qt?{...Jr,[E]:qt}:Jr}),await Sn(),await u({agentId:n,projectId:r,withCounts:!0}),ll(E)}catch(ge){N(ge instanceof Error?ge.message:O)}finally{pe(null)}},L2=E=>ac(E,()=>hc({agentId:n,...r?{projectId:r}:{},source:E},"pending",e),"Embedding failed"),A2=E=>ac(E,()=>ox({agentId:n,...r?{projectId:r}:{},source:E},e),"Rescan failed"),d0=async(E,Q)=>{let O=++Te.current,ge=At==="source"?{kind:"source"}:{kind:At,uri:Ue};Re(!0),N(null);try{let qt=await lx({agentId:n,...r?{projectId:r}:{},source:E,selector:ge,mode:Q,obsoleteOnly:Ot},e);if(O!==Te.current)return;Q==="estimate"?be(qt):(bt(null),be(null),ll(E),await Sn(),await u({agentId:n,projectId:r,withCounts:!0}))}catch(qt){O===Te.current&&N(qt instanceof Error?qt.message:"Index cleanup failed")}finally{O===Te.current&&Re(!1)}},P2=async E=>{ct(E),N(null);try{await ix({agentId:n,...r?{projectId:r}:{},source:E},e),await Sn()}catch(Q){N(Q instanceof Error?Q.message:"Reset failed")}finally{ct(null)}},N2=async(E,Q)=>{mt(E),N(null);try{await M0({agentId:n,...r?{projectId:r}:{},source:E,enabled:Q},e),await Sn()}catch(O){N(O instanceof Error?O.message:"Toggle failed")}finally{mt(null)}},R2=async(E,Q)=>{le(E),N(null);try{let O=await sx({agentId:n,...r?{projectId:r}:{},source:E,...Q.purgeVectors?{purgeVectors:!0}:{}},e);await Sn(),await u({agentId:n,projectId:r}),ll(E),Ee(Q.purgeVectors&&O?.purgeJob?`Deleted "${E}" (vector purge running in background)`:`Deleted "${E}"`),he(null)}catch(O){N(O instanceof Error?O.message:"Delete failed")}finally{le(null)}},zf=async E=>{rr(!0),Pr(!0),ln(null);try{let Q=await eh({path:E,agentId:n,...r?{projectId:r}:{}},e);Mn(Q.entries),$r(E)}catch{ln("That path is not available."),Mn([])}finally{Pr(!1)}},f0=E=>{ee(Q=>{if(!yn(Q.key))return{...Q,path:E};let O=zt(Q.scope,E);return oe.current=O,{...Q,path:E,key:O}}),rr(!1)},M2=async()=>{if(!(!Oe.key||D&&!Oe.path)){Ae(!0),N(null);try{let E={...Oe.config,...D?{root:Oe.path}:{}};await ax({agentId:n,...r?{projectId:r}:{},source:Oe.key,scope:Oe.scope,connection:{kind:fn,config:E},permissions:{default:{read:Oe.read,write:Oe.write,exec:Oe.exec},...Oe.policies.length>0?{paths:Oe.policies}:{}},...Oe.description.trim()?{description:Oe.description.trim()}:{},...F&&Oe.syncEnabled?{sync:{exclude:Ku(Oe.exclude),trigger:Oe.trigger,...Ku(Oe.include).length>0?{include:Ku(Oe.include)}:{}}}:{},...p&&fn==="local"&&Oe.recognizesPackages?{recognizesPackages:!0}:{}},e),je(!1);{let Q=$u(q,x);oe.current=Q.key,ee(Q)}await Sn(),await u({agentId:n,projectId:r})}catch(E){N(E instanceof Error?E.message:"Add source failed")}finally{Ae(!1)}}},T2=E=>E==="data"||E==="packages";return(0,S.jsxs)("div",{className:"w-full px-5 pt-3 pb-6 text-white/85",children:[(0,S.jsxs)("div",{className:"flex items-center justify-between gap-2 pb-2 border-b border-white/[0.06]",children:[(0,S.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,S.jsx)(ir,{className:"h-4 w-4 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-sm font-semibold tracking-wide text-white/92",children:"Sources"}),(0,S.jsx)("span",{className:"rounded px-1.5 py-0.5 text-[10px] font-medium text-cyan-300 bg-cyan-500/20",children:rc.length})]}),(0,S.jsxs)("div",{className:"flex items-center gap-1",children:[(0,S.jsxs)("div",{className:"inline-flex items-center gap-0.5",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>je(E=>!E),className:"h-7 px-2 rounded-l-md rounded-r-none text-cyan-300 hover:text-cyan-200 hover:bg-white/[0.05] transition inline-flex items-center gap-1 text-[10px] font-medium",title:"Add source",children:[(0,S.jsx)(Fn,{className:"h-3 w-3"}),"Source"]}),(0,S.jsx)(qg.SkillLauncher,{variant:"icon",attached:"left",skill:"manage-sources",packageId:"@neuralis/brain-core",scripts:["scripts/sync.sh","scripts/reindex.sh","scripts/set-enabled.sh"],label:"Manage sources with the agent"})]}),(0,S.jsx)("button",{type:"button",onClick:()=>{Sn()},disabled:T,className:"h-7 w-7 rounded-md text-white/35 hover:text-white/70 hover:bg-white/[0.05] transition",title:"Refresh",children:(0,S.jsx)(_t,{className:$("mx-auto h-3 w-3",T&&"animate-spin")})}),(0,S.jsx)("button",{type:"button",onClick:()=>i("sources",!1),className:"h-7 px-2.5 rounded-md text-[10px] font-medium text-white/50 hover:text-white/80 hover:bg-white/[0.05] transition",children:"Close"})]})]}),(0,S.jsxs)("div",{className:"mt-2 text-[10px] text-white/35 italic",children:["Add filesystem-style sources from Neuralis packages. A source URI such as ",(0,S.jsx)("code",{className:"font-mono",children:"neuralis://"})," or ",(0,S.jsx)("code",{className:"font-mono",children:"machine-user://"})," is the stable handle agents use with fs_* tools."]}),(0,S.jsx)("div",{className:"mt-2 flex items-center gap-1 rounded-md bg-white/[0.025] p-1",children:[{id:"project",label:"Project"},{id:"user",label:"User"},{id:"agent",label:"Agent"}].map(E=>(0,S.jsx)("button",{type:"button",onClick:()=>on(E.id),className:$("h-6 rounded px-2 text-[9px] font-semibold transition",kt===E.id?"bg-cyan-500/15 text-cyan-200 border border-cyan-400/20":"text-white/35 hover:text-white/65 hover:bg-white/[0.04]"),children:E.label},E.id))}),Y&&(0,S.jsx)("div",{className:"mt-2 rounded-md bg-red-500/8 px-3 py-2 text-[10px] text-red-200/80",children:Y}),Gt&&(0,S.jsxs)("div",{className:"mt-2 rounded-lg bg-white/[0.03] border border-white/[0.08] p-3 space-y-2",children:[(0,S.jsx)("div",{className:"text-[11px] font-semibold text-white/80",children:"Add Source"}),ma&&(0,S.jsxs)("div",{className:"text-[9px] text-rose-300/80 bg-rose-500/10 rounded px-2 py-1",children:["Could not load source kinds: ",ma,'. Falling back to "local".']}),Nr.length>1&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Kind"}),(0,S.jsx)("select",{value:fn,onChange:E=>{let Q=E.target.value,O=I.get(Q)??null;Xr(Q);let ge=$u(O,x);oe.current=ge.key,ee(ge)},className:If,children:Nr.map(E=>(0,S.jsxs)("option",{value:E.kind,children:[E.label," \u2014 ",E.trust," (",E.packageId,")"]},E.kind))}),(0,S.jsx)("div",{className:"text-[9px] text-white/30 italic",children:q?.description??""})]}),q?.scopeSelectable&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Scope"}),(0,S.jsx)("select",{value:Oe.scope,onChange:E=>{let Q=E.target.value;ee(O=>{if(!yn(O.key))return{...O,scope:Q};let ge=zt(Q,O.path);return oe.current=ge,{...O,scope:Q,key:ge}})},className:If,children:gE(q).map(E=>(0,S.jsx)("option",{value:E,children:E},E))})]}),xe&&a?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)("div",{className:"text-[10px] text-amber-300/70 bg-amber-500/8 rounded px-2 py-1.5",children:["Docker mode: host folders still need the CLI mount script:"," ",(0,S.jsx)("code",{className:"text-amber-200/90 font-mono",children:"neuralis mount add"})," ","on the host, then restart the container. Package sources like Machine do not require a host path here."]}),gr?(0,S.jsxs)("div",{className:"flex items-center gap-1.5 py-1",children:[(0,S.jsx)(We,{className:"h-3 w-3 animate-spin text-white/30"}),(0,S.jsx)("span",{className:"text-[9px] text-white/35",children:"Scanning volume mounts..."})]}):Jn.length>0?(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Available volume mounts (not yet configured)"}),Jn.map(E=>(0,S.jsxs)("div",{className:"flex items-center gap-2 rounded px-2 py-1.5 bg-white/[0.02] hover:bg-white/[0.04] transition",children:[(0,S.jsx)(Tr,{className:"h-3 w-3 text-cyan-400/70 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] text-white/75 font-medium flex-1 truncate",children:E.name}),(0,S.jsx)("span",{className:"text-[9px] text-white/30 font-mono truncate max-w-[120px]",children:E.path}),(0,S.jsx)("button",{type:"button",onClick:()=>{ee(Q=>({...Q,key:E.name,path:E.path}))},className:"px-2 py-0.5 rounded text-[8px] font-semibold text-cyan-300/80 bg-cyan-500/10 hover:bg-cyan-500/20 border border-cyan-400/20 transition shrink-0",children:"+ Add"})]},E.path))]}):(0,S.jsx)("div",{className:"text-[9px] text-white/30 italic",children:"All volume mounts are configured as sources."})]}):(0,S.jsx)("div",{className:"text-[10px] text-white/35 italic",children:D?de.container?"Mount any folder from your system. The path must be accessible to the server process.":"A path on the operator\u2019s host machine, reached through the host broker. It needs no volume mount here, and the broker ceiling still clamps what is reachable.":"This connector does not need a local path. Choose the scope and URI scheme; the package owns the runtime binding."}),(0,S.jsxs)("div",{className:"space-y-2",children:[(0,S.jsxs)("div",{className:$("grid gap-2",D?"grid-cols-2":"grid-cols-1"),children:[(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"URI scheme"}),(0,S.jsx)("input",{type:"text",value:Oe.key,onChange:E=>ee(Q=>({...Q,key:E.target.value})),placeholder:zt(Oe.scope,Oe.path),className:Wi}),(0,S.jsxs)("div",{className:"text-[8px] text-white/25 font-mono",children:[Oe.key||zt(Oe.scope,Oe.path),"://"]})]}),D&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:de.label}),(0,S.jsxs)("div",{className:"flex gap-1",children:[(0,S.jsx)("input",{type:"text",value:Oe.path,onChange:E=>ee(Q=>({...Q,path:E.target.value})),placeholder:de.placeholder,className:$(Wi,"flex-1")}),de.container&&!a&&g&&(0,S.jsx)("button",{type:"button",onClick:()=>{zf(Oe.path||"/")},className:"h-7 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] border border-white/[0.08] text-white/60 hover:text-white/90 transition shrink-0",title:"Browse directories",children:(0,S.jsx)(Is,{className:"h-3.5 w-3.5"})})]})]})]}),Object.entries(Xg(q).properties).filter(([E])=>E!=="root").map(([E,Q])=>(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:Q?.["x-neuralis"]?.ui?.label??E}),(0,S.jsx)("input",{type:Q.type==="number"||Q.type==="integer"?"number":"text",value:String(Oe.config[E]??""),onChange:O=>ee(ge=>({...ge,config:{...ge.config,[E]:O.target.value}})),placeholder:Q?.["x-neuralis"]?.ui?.placeholder??Q?.description??E,className:Wi})]},E)),xe&&!a&&dn&&(0,S.jsxs)("div",{className:"rounded-md bg-white/[0.03] border border-white/[0.1] overflow-hidden",children:[(0,S.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5 bg-white/[0.02] border-b border-white/[0.06]",children:[(0,S.jsx)(Is,{className:"h-3 w-3 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[9px] font-mono text-white/60 truncate flex-1",children:Yn}),(0,S.jsx)("button",{type:"button",onClick:()=>rr(!1),className:"text-[9px] text-white/40 hover:text-white/70 px-1",children:"Close"})]}),Kr&&(0,S.jsx)("div",{className:"px-2 py-1 text-[9px] text-red-300/80",children:Kr}),ar?(0,S.jsx)("div",{className:"flex items-center justify-center py-3",children:(0,S.jsx)(We,{className:"h-3 w-3 animate-spin text-white/30"})}):(0,S.jsxs)("div",{className:"max-h-[180px] overflow-y-auto",children:[Yn!=="/"&&(0,S.jsxs)("button",{type:"button",onClick:()=>{let E=Yn.replace(/[/\\][^/\\]+$/,"")||"/";zf(E)},className:"w-full flex items-center gap-1.5 px-2 py-1 text-left hover:bg-white/[0.04] transition",children:[(0,S.jsx)(qa,{className:"h-3 w-3 text-white/30"}),(0,S.jsx)("span",{className:"text-[10px] text-white/50",children:".."})]}),qr.length===0&&!ar&&(0,S.jsx)("div",{className:"px-2 py-2 text-[9px] text-white/30 italic",children:"No subdirectories"}),qr.map(E=>(0,S.jsxs)("div",{className:"flex items-center gap-0.5 hover:bg-white/[0.04] transition",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>{zf(E.path)},className:"flex items-center gap-1.5 px-2 py-1 flex-1 text-left min-w-0",children:[(0,S.jsx)(Tr,{className:"h-3 w-3 text-cyan-400/70 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] text-white/75 truncate",children:E.name})]}),(0,S.jsx)("button",{type:"button",onClick:()=>f0(E.path),className:"px-2 py-1 text-[8px] font-medium text-cyan-300/70 hover:text-cyan-200 shrink-0",children:"Select"})]},E.path)),(0,S.jsxs)("button",{type:"button",onClick:()=>f0(Yn),className:"w-full flex items-center gap-1.5 px-2 py-1.5 text-left bg-cyan-500/5 hover:bg-cyan-500/10 border-t border-white/[0.06] transition",children:[(0,S.jsx)(Qr,{className:"h-3 w-3 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] font-medium text-cyan-300/80",children:"Select this folder"}),(0,S.jsx)("span",{className:"text-[9px] text-white/30 font-mono truncate ml-auto",children:Yn})]})]})]})]}),(0,S.jsxs)("div",{className:"flex items-center gap-2",children:[(0,S.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35 w-16 shrink-0",children:"Access"}),[{key:"read",label:"Read",icon:Sl},{key:"write",label:"Write",icon:si},{key:"exec",label:"Exec",icon:io}].map(({key:E,label:Q,icon:O})=>(0,S.jsxs)("label",{className:$("inline-flex items-center gap-1 rounded px-2 py-1 text-[9px] cursor-pointer transition",Oe[E]?"bg-white/[0.06] text-white/85":"bg-white/[0.02] text-white/40"),children:[(0,S.jsx)("input",{type:"checkbox",className:"sr-only",checked:Oe[E],onChange:ge=>ee(qt=>({...qt,[E]:ge.target.checked}))}),(0,S.jsx)(O,{className:"h-2.5 w-2.5"}),Q,(0,S.jsx)("span",{className:$("h-1.5 w-1.5 rounded-full",Oe[E]?"bg-emerald-300/80":"bg-white/20")})]},E))]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsxs)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:["Description ",(0,S.jsx)("span",{className:"text-white/20 normal-case font-normal",children:"(optional \u2014 shown to the agent)"})]}),(0,S.jsx)("input",{value:Oe.description,onChange:E=>ee(Q=>({...Q,description:E.target.value})),className:Wi,placeholder:q?.description??"What this source is for\u2026",maxLength:200})]}),F&&(0,S.jsx)("div",{className:"flex items-center gap-2",children:(0,S.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:Oe.syncEnabled,onChange:E=>ee(Q=>({...Q,syncEnabled:E.target.checked})),className:"accent-emerald-400 h-3 w-3"}),"Enable sync"]})}),F&&Oe.syncEnabled&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Exclude patterns"}),(0,S.jsx)("textarea",{value:Oe.exclude,onChange:E=>ee(Q=>({...Q,exclude:E.target.value})),rows:2,className:Xu,placeholder:"node_modules/**"})]}),F&&Oe.syncEnabled&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Include (allowlist)"}),(0,S.jsx)("textarea",{value:Oe.include,onChange:E=>ee(Q=>({...Q,include:E.target.value})),rows:2,className:$(Xu,"font-mono"),placeholder:`# empty = everything
|
|
46
|
-
skills/**`}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Non-empty: only matching files sync. Excludes always win \u2014 an excluded path can never be re-included. This narrows the INDEX, not what the agent can read: the source root does that."})]}),fn==="local"&&p&&(0,S.jsx)("div",{className:"space-y-1",children:(0,S.jsxs)("label",{className:"inline-flex items-start gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:Oe.recognizesPackages,onChange:E=>ee(Q=>({...Q,recognizesPackages:E.target.checked})),className:"accent-emerald-400 h-3 w-3 mt-0.5"}),(0,S.jsxs)("span",{children:["Recognize packages",(0,S.jsxs)("span",{className:"block text-[9px] text-white/35 normal-case font-normal",children:["Load packages found in this folder (in addition to ",(0,S.jsx)("code",{children:"_packages/"}),") as soon as the source is added. Advertised only within this source's scope."]})]})]})}),(0,S.jsxs)("div",{className:"flex items-center gap-1.5 pt-1",children:[(0,S.jsx)("button",{type:"button",onClick:()=>je(!1),className:"h-6 px-2.5 rounded-md text-[9px] font-medium text-white/50 hover:text-white/80 hover:bg-white/[0.05] transition",children:"Cancel"}),(0,S.jsxs)("button",{type:"button",onClick:()=>{M2()},disabled:Ve||!Oe.key||D&&!Oe.path,className:"h-6 px-2.5 rounded-md bg-cyan-500/12 border border-cyan-400/25 text-[9px] font-semibold text-cyan-200/90 hover:bg-cyan-500/20 transition disabled:opacity-35 inline-flex items-center gap-1",children:[Ve?(0,S.jsx)(We,{className:"h-2.5 w-2.5 animate-spin"}):(0,S.jsx)(Fn,{className:"h-2.5 w-2.5"}),"Create source"]})]})]}),rc.length===0&&!T?(0,S.jsx)("div",{className:"mt-3 text-[10px] text-white/40",children:"No sources configured."}):null,(0,S.jsx)("div",{className:"mt-1 space-y-3",children:v2.map(([E,Q])=>(0,S.jsxs)("div",{children:[(0,S.jsxs)("div",{className:"-ml-0.5 mb-0.5 flex items-center gap-1.5 px-1",children:[(0,S.jsx)(wr,{className:"h-3 w-3 shrink-0 text-white/30"}),(0,S.jsx)("span",{className:"truncate font-mono text-[10px] font-medium text-white/40",children:E}),(0,S.jsx)("span",{className:"text-[9px] tabular-nums text-white/25",children:Q.length})]}),(0,S.jsx)("div",{className:"space-y-0.5 pl-2",children:Q.map(O=>{let ge=C[O.source]??Yo(O),qt=A===O.source,Qt=K===O.source,Wa=ne===O.source,Jr=Se===O.source,za=I.get(O.connection.kind)??null,ja=Kg(za),sc=ja&&!!ge.sync,Gn=ge.sync??jg,h0=(0,lr.resolveIconWithFallback)(O.kind_icon??za?.icon??void 0,zn),p0=Ic(O),m0=O.live===!1,D2=m0||O.enabled===!1||O.enabled==="auto"&&O.enabled_effective===!1,jf=!!P[O.source],hs=!O.observed,Vf=hs&&IE(O,ge),Rr=cL(Gn.trigger),Ys=U[O.source]??{};return(0,S.jsxs)("div",{className:"rounded-sm",children:[(0,S.jsxs)("div",{className:"w-full flex items-center gap-2 py-2 text-left group hover:bg-white/[0.02] rounded-md px-1 transition",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>w2(O.source),"aria-expanded":jf,title:m0?wh(O.live_reason):void 0,className:"min-w-0 flex-1 flex items-center gap-2",children:[O.git?.isRepo?(0,S.jsxs)("span",{className:"relative inline-flex shrink-0 items-center justify-center",children:[(0,S.jsx)(h0,{className:$("h-4 w-4",p0.iconClassName)}),(0,S.jsx)(Cn,{className:"absolute -right-1.5 -top-1.5 h-2.5 w-2.5 rounded-full bg-black/80 p-[1px] text-violet-300/90"})]}):(0,S.jsx)(h0,{className:$("h-4 w-4 shrink-0",p0.iconClassName)}),(0,S.jsx)("span",{className:$("min-w-0 flex-1 truncate text-[12.5px] font-semibold",D2?"text-white/45":"text-white/90"),children:O.source}),O.git?.isRepo&&O.git.branch?(0,S.jsxs)("span",{className:"inline-flex max-w-[96px] shrink-0 items-center gap-0.5 text-[10px] text-violet-300/70",title:`Git branch: ${O.git.branch}`,children:[(0,S.jsx)(Cn,{className:"h-2.5 w-2.5 shrink-0"}),(0,S.jsx)("span",{className:"truncate",children:O.git.branch})]}):null,O.observed&&(0,S.jsx)("span",{className:"shrink-0 rounded px-1 py-0.5 text-[8px] font-medium text-orange-200/90 bg-orange-500/5 ring-1 ring-orange-300/30",children:"observed"}),O.orphan&&(0,S.jsx)("span",{className:"shrink-0 rounded px-1 py-0.5 text-[8px] font-medium text-rose-300/80 bg-rose-500/15",title:O.orphan_hint??"Package missing",children:"orphan"}),Vf&&(0,S.jsx)("span",{className:"shrink-0 rounded px-1 py-0.5 text-[8px] font-medium text-amber-300/80 bg-amber-500/10",children:"unsaved"})]}),(()=>{let Fe=O.enabled??!0,Bt=O.enabled_effective??Fe===!0,Zn=(za?.kind??O.connection.kind)==="webtop",Js=vt===O.source,F2=()=>Zn?Fe===!0?!1:Fe===!1?"auto":!0:Fe===!1,g0=Fe==="auto"?`Auto \xB7 ${Bt?"Live":"Stopped"}`:Fe===!1?"Off":"On",E2=Fe===!1?"text-rose-300/85 bg-rose-500/10 border-rose-400/25":Fe==="auto"?"text-amber-200/85 bg-amber-500/10 border-amber-400/25":"text-emerald-300/85 bg-emerald-500/10 border-emerald-400/25";return(0,S.jsx)("button",{type:"button",title:`Source ${g0} \u2014 click to cycle`,onClick:O2=>{O2.stopPropagation(),!Js&&N2(O.source,F2())},disabled:Js||!!O.observed,className:$("shrink-0 rounded px-1 py-0.5 text-[8px] font-semibold border transition disabled:opacity-50",E2),children:Js?"\u2026":g0})})(),(0,S.jsx)("span",{className:"text-[9px] text-white/30 truncate max-w-[140px] hidden sm:inline",children:SE(O,za)}),(0,S.jsx)(Et,{className:$("h-3 w-3 text-white/25 shrink-0 transition-transform",jf&&"rotate-180")})]}),(0,S.jsx)("div",{className:$("transition-all duration-200",jf?"opacity-100":"max-h-0 opacity-0 overflow-hidden"),children:(0,S.jsxs)("div",{className:"rounded-md bg-white/[0.02] p-3 ml-5 mb-1 space-y-2.5",children:[(0,S.jsxs)("div",{className:"flex items-center gap-3 text-[9px] text-white/40",children:[M.has(O.source)&&typeof O.indexed_count!="number"&&(0,S.jsx)("span",{className:"text-white/30",children:"Loading counts\u2026"}),typeof O.connector_count=="number"&&(0,S.jsxs)("span",{children:[(0,S.jsxs)("span",{className:"text-white/60 tabular-nums",children:[O.connector_count,O.connector_truncated?"+":""]})," connector"]}),typeof O.indexed_count=="number"&&(0,S.jsxs)("span",{children:[(0,S.jsx)("span",{className:"text-cyan-300/70 tabular-nums",children:O.indexed_count})," indexed"]}),typeof O.unindexed_count=="number"&&O.unindexed_count>0&&(0,S.jsxs)("span",{children:[(0,S.jsx)("span",{className:"text-amber-300/70 tabular-nums",children:O.unindexed_count})," unindexed"]}),ja&&O.sync?.lastSync&&(0,S.jsxs)("span",{children:["Last sync: ",oL(O.sync.lastSync)]}),O.updatedAt&&(0,S.jsxs)("span",{children:["Updated: ",oL(O.updatedAt)]})]}),ja&&!O.sync?.lastSync?(0,S.jsx)("div",{className:"rounded-md border border-sky-300/15 bg-sky-500/5 px-2 py-1.5 text-[10px] text-sky-100/70",children:"Never synced \u2014 run a sync to index this source and load its packages (skills, rules, instructions) for agents."}):null,O.observed?(0,S.jsx)("div",{className:"rounded-md border border-orange-300/15 bg-orange-500/5 px-2 py-1.5 text-[10px] text-orange-100/70",children:"Runtime-observed source. Create a source config to edit permissions, sync, or persistence settings."}):null,(0,S.jsxs)("div",{children:[(0,S.jsxs)("button",{type:"button",onClick:()=>Wf(O.source,"description"),className:"flex items-center gap-1.5 py-1 w-full text-left",children:[(0,S.jsx)(va,{className:"h-3 w-3 text-violet-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] font-semibold text-white/70 flex-1",children:"Description"}),!Ys.description&&((ge.description??"").trim()||O.description_effective)&&(0,S.jsx)("span",{className:$("text-[9px] truncate max-w-[200px]",(ge.description??"").trim()?"text-white/35":"text-white/25 italic"),children:(ge.description??"").trim()||`${O.description_effective} (from the package)`}),(0,S.jsx)(un,{className:$("h-2.5 w-2.5 text-white/25 transition-transform",Ys.description&&"rotate-90")})]}),Ys.description&&(0,S.jsxs)("div",{className:"pl-5 pt-1 space-y-1",children:[(0,S.jsx)("div",{className:"text-[10px] text-white/35 italic",children:"A one-line summary shown to the agent in its runtime source list."}),hs?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("textarea",{value:ge.description??"",onChange:Fe=>Yr(O.source,Bt=>({...Bt,description:Fe.target.value})),rows:2,className:Xu,placeholder:O.description_effective??"What this source is for\u2026",maxLength:200}),!(ge.description??"").trim()&&O.description_effective&&(0,S.jsx)("div",{className:"text-[9px] text-white/25 italic",children:"Shown above from the package. Leave this empty to keep following it."})]}):(0,S.jsx)("div",{className:"text-[10px] text-white/70",children:(ge.description??"").trim()||(O.description_effective?(0,S.jsxs)("span",{className:"text-white/40 italic",children:[O.description_effective," ",(0,S.jsx)("span",{className:"text-white/25 not-italic",children:"(from the package)"})]}):(0,S.jsx)("span",{className:"text-white/30 italic",children:"No description"}))})]})]}),hs&&p&&(za?.kind??O.connection.kind)==="local"&&(0,S.jsx)("div",{className:"pl-0",children:(0,S.jsxs)("label",{className:"flex items-start gap-1.5 py-1 cursor-pointer",children:[(0,S.jsx)(wr,{className:"h-3 w-3 text-cyan-400 shrink-0 mt-0.5"}),(0,S.jsx)("input",{type:"checkbox",checked:ge.recognizesPackages??!1,onChange:Fe=>Yr(O.source,Bt=>({...Bt,recognizesPackages:Fe.target.checked})),className:"accent-cyan-400 h-3 w-3 mt-0.5"}),(0,S.jsxs)("span",{className:"text-[10px] text-white/70 leading-tight",children:["Recognize packages",(0,S.jsxs)("span",{className:"block text-[9px] text-white/35 normal-case font-normal",children:["Load packages found in this folder (in addition to ",(0,S.jsx)("code",{children:"_packages/"}),") \u2014 applied on save; advertised only within this source's scope."]})]})]})}),(0,S.jsxs)("div",{children:[(0,S.jsxs)("div",{className:"flex items-center gap-1.5 py-1",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>Wf(O.source,"perms"),className:"flex items-center gap-1.5 flex-1 text-left",children:[(0,S.jsx)(Ps,{className:"h-3 w-3 text-emerald-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] font-semibold text-white/70 flex-1",children:"Permissions"}),(0,S.jsx)(un,{className:$("h-2.5 w-2.5 text-white/25 transition-transform",Ys.perms&&"rotate-90")})]}),(0,S.jsx)(qg.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-uri-policy",packageId:"@neuralis/brain-core",scripts:["scripts/show-uri.sh","scripts/set-uri.sh","scripts/manifests.sh"],label:`Edit URI policy for "${O.source}" with the agent`,icon:"shield"})]}),Ys.perms&&(0,S.jsx)("div",{className:"pl-5 pt-1",children:(0,S.jsx)(zg,{source:O.source,permissions:O.permissions,mode:hs?"edit":"view",onSave:hs?Fe=>S2(O,Fe):void 0})})]}),ja&&(0,S.jsxs)("div",{children:[(0,S.jsxs)("button",{type:"button",onClick:()=>Wf(O.source,"sync"),className:"flex items-center gap-1.5 py-1 w-full text-left",children:[(0,S.jsx)(_t,{className:"h-3 w-3 text-blue-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] font-semibold text-white/70 flex-1",children:"Sync"}),sc&&(0,S.jsx)("span",{className:"text-[9px] text-white/35",children:kE(Gn.trigger)}),(0,S.jsx)(un,{className:$("h-2.5 w-2.5 text-white/25 transition-transform",Ys.sync&&"rotate-90")})]}),Ys.sync&&(0,S.jsxs)("div",{className:"pl-5 space-y-2 pt-1",children:[(0,S.jsx)("div",{className:"text-[10px] text-white/35 italic",children:"Sync indexes files for AI search. Excluded patterns (logs/, node_modules/) are skipped automatically."}),(0,S.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:sc,onChange:Fe=>Yr(O.source,Bt=>({...Bt,...Fe.target.checked?{sync:{...jg,exclude:[...O.defaultSyncExclude??jg.exclude]}}:{sync:void 0}})),className:"accent-emerald-400 h-3 w-3"}),"Enable sync"]}),sc&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsxs)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35 flex items-center gap-1",children:[(0,S.jsx)(wa,{className:"h-2.5 w-2.5 text-cyan-300/60"})," Trigger"]}),(0,S.jsx)("select",{value:Rr.mode,onChange:Fe=>{let Bt=Fe.target.value;Yr(O.source,Zn=>({...Zn,sync:{...Gn,trigger:Vg(Bt,Rr.val,Rr.unit)}}))},className:If,children:cE.map(Fe=>(0,S.jsx)("option",{value:Fe.value,children:Fe.label},Fe.value))}),Rr.mode==="interval"&&(0,S.jsxs)("div",{className:"flex gap-1",children:[(0,S.jsx)("input",{type:"number",min:Af(Rr.unit),value:Rr.val,onChange:Fe=>{let Bt=Fe.target.value.replace(/\D/g,"")||String(Af(Rr.unit));Yr(O.source,Zn=>({...Zn,sync:{...Gn,trigger:Vg("interval",Bt,Rr.unit)}}))},className:$(Wi,"w-16")}),(0,S.jsx)("select",{value:Rr.unit,onChange:Fe=>{let Bt=Fe.target.value,Zn=String(Math.max(Number.parseInt(Rr.val,10)||1,Af(Bt)));Yr(O.source,Js=>({...Js,sync:{...Gn,trigger:Vg("interval",Zn,Bt)}}))},className:$(If,"flex-1"),children:dE.map(Fe=>(0,S.jsx)("option",{value:Fe.value,children:Fe.label},Fe.value))})]}),(0,S.jsx)("div",{className:"text-[8px] text-white/35 italic leading-relaxed",children:Rr.mode==="manual"?"Manual: nothing triggers it automatically \u2014 indexes only when you click Sync below.":Rr.mode==="auto"?"Auto: re-indexes on file changes (host edits, git, shell \u2014 anything) + a periodic full reconcile.":"Scheduled: runs a full reconcile every interval above."})]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Exclude"}),(0,S.jsx)("textarea",{value:Lf(Gn.exclude),onChange:Fe=>{let Bt=Ku(Fe.target.value);Yr(O.source,Zn=>({...Zn,sync:{...Gn,exclude:Bt}}))},rows:5,className:$(Xu,"font-mono"),placeholder:`# .gitignore syntax
|
|
29
|
+
`}function e1(t,e){if(!t)return{files:[],truncated:e,hunkPatches:null};let n=[];try{n=yw(t)}catch{n=[]}return{files:n,truncated:e,hunkPatches:Zw(t)}}function ld(t,e){let n=Hw(t,e);return n<=0?null:{start:t?t.oldStart+t.oldLines:1,end:e.oldStart,lines:n}}function xu(t,e){if(!t)return null;let n=t.oldStart+t.oldLines;if(e===null)return{start:n,end:n,lines:null};let r=e-n+1;return r<=0?null:{start:n,end:e+1,lines:r}}function t1(t,e){let n=[];for(let a=0;a<t.length;a++){let s=ld(a===0?null:t[a-1],t[a]);s&&n.push({start:s.start,end:s.end})}let r=xu(t[t.length-1]??null,e);return r&&r.lines!==null&&n.push({start:r.start,end:r.end}),n}function nM(t){let e=t.split(`
|
|
30
|
+
`);return e.length>1&&e[e.length-1]===""&&e.pop(),e}function ud(t,e){let n=nM(e);if(t.length===0)return n.slice();let r=t[t.length-1],a=Math.max(r.oldStart+r.oldLines,1),s=Math.max(r.newStart+r.newLines,1),i=Math.max(n.length-s+1,0),o=Math.max(a-1+i,0),l=new Array(o).fill(""),u=1,c=1,d=f=>{for(let h=u,p=c;h<f;h++,p++)l[h-1]=n[p-1]??""};for(let f of t)d(f.oldStart),u=Math.max(f.oldStart+f.oldLines,1),c=Math.max(f.newStart+f.newLines,1);return d(o+1),l}function n1(t,e,n){return n.reduce((r,a)=>_w(r,e,a.start,a.end),t)}function r1(t,e){let n=t.oldStart,r=t.oldStart+t.oldLines,a=[];for(let s=0;s<e.length;s++){let i=e[s];i.oldStart>=n&&i.oldStart+i.oldLines<=r&&a.push(s)}return a}function a1(t){return"commit"in t?{kind:"commit",sha:t.commit}:"base"in t?{kind:"range",base:t.base,head:t.head}:{kind:"working",staged:t.staged}}function s1(t){return t.kind==="working"?{staged:t.staged}:t.kind==="commit"?{commit:t.sha}:{base:t.base,head:t.head}}function i1(t){return t.kind==="working"?t.staged?{type:"show",rev:"index"}:{type:"worktree"}:t.kind==="commit"?{type:"show",rev:t.sha}:{type:"show",rev:t.head}}function gn(t){return t.slice(0,7)}function o1(t){return t.kind==="working"?t.staged?"Index \u2194 HEAD":"Working \u2194 Index":t.kind==="commit"?`${gn(t.sha)}^ \u2194 ${gn(t.sha)}`:`${gn(t.base)} \u2194 ${gn(t.head)}`}function l1(t){return t.kind==="working"?t.staged?"No staged changes for this file.":"No working-tree changes for this file.":t.kind==="commit"?"No changes for this file in this commit.":"No changes for this file in this range."}function u1(t){return"commit"in t?`commit ${gn(t.commit)}`:"base"in t?`${gn(t.base)}..${gn(t.head)}`:t.staged?"staged":"working tree"}function Mi(t,e){return t?`${t} \xB7 ${e}`:e}function c1(t){return!!t&&/uri.?policy.?denied/i.test(t)}var p1=W(Je(),1);var fp={typescript:()=>import("./chunks/typescript-NEWOAB5Z.js"),tsx:()=>import("./chunks/tsx-S73GAE2L.js"),javascript:()=>import("./chunks/javascript-IH374YWG.js"),jsx:()=>import("./chunks/jsx-OTXJQD32.js"),json:()=>import("./chunks/json-WGGVVXSB.js"),markdown:()=>import("./chunks/markdown-LMWF6MQR.js"),python:()=>import("./chunks/python-CFG4FTQW.js"),bash:()=>import("./chunks/bash-KY6SAQTH.js"),yaml:()=>import("./chunks/yaml-UMWKDTK7.js"),html:()=>import("./chunks/html-F6FWTBSG.js"),css:()=>import("./chunks/css-MANZBYA4.js"),go:()=>import("./chunks/go-5UCPEC6S.js"),rust:()=>import("./chunks/rust-X7A37WU3.js"),sql:()=>import("./chunks/sql-B55MH6JJ.js"),toml:()=>import("./chunks/toml-ETQRDILP.js"),c:()=>import("./chunks/c-OBOPYVZ7.js"),cpp:()=>import("./chunks/cpp-TVWVOTEQ.js"),csharp:()=>import("./chunks/csharp-HQWR4N52.js"),java:()=>import("./chunks/java-ANIVV5H5.js"),kotlin:()=>import("./chunks/kotlin-MNR6XOEQ.js"),ruby:()=>import("./chunks/ruby-42NMJWAL.js"),php:()=>import("./chunks/php-AYGJ5WYZ.js"),swift:()=>import("./chunks/swift-PE7VNYW5.js"),scala:()=>import("./chunks/scala-OYHJSUG2.js"),r:()=>import("./chunks/r-4YFCFA4B.js"),powershell:()=>import("./chunks/powershell-7GSBBEFF.js"),ini:()=>import("./chunks/ini-BJIVD5MK.js"),xml:()=>import("./chunks/xml-UXKAGLDR.js"),scss:()=>import("./chunks/scss-XD7VU2CU.js"),less:()=>import("./chunks/less-KA5JURX6.js"),graphql:()=>import("./chunks/graphql-UGOPR3WU.js"),lua:()=>import("./chunks/lua-4CRZ64PU.js"),dart:()=>import("./chunks/dart-FO4TTVO2.js"),elm:()=>import("./chunks/elm-5WUUSTNB.js"),latex:()=>import("./chunks/latex-QCZNITGN.js"),clojure:()=>import("./chunks/clojure-4QCN4GHG.js"),elixir:()=>import("./chunks/elixir-S725Z7EH.js"),haskell:()=>import("./chunks/haskell-25PJ3OSG.js"),nix:()=>import("./chunks/nix-QGWLUUMZ.js"),perl:()=>import("./chunks/perl-BHTX7F5B.js"),proto:()=>import("./chunks/proto-7KDX5Z2U.js"),docker:()=>import("./chunks/docker-VX55HTDS.js"),mdx:()=>import("./chunks/mdx-WPMNN5BS.js"),vue:()=>import("./chunks/vue-CCDS4VZK.js"),svelte:()=>import("./chunks/svelte-WR3QPIJU.js"),astro:()=>import("./chunks/astro-B2J4AS2D.js"),diff:()=>import("./chunks/diff-SHANV4YC.js"),make:()=>import("./chunks/make-LPD5KOCO.js"),nginx:()=>import("./chunks/nginx-V4CYS7WR.js"),prisma:()=>import("./chunks/prisma-FPMPQISO.js")},rM=["typescript","tsx","javascript","jsx","json","markdown","python","bash","yaml","html","css","go","rust","sql","toml"];function _o(t){if(!t)return;let e=t.toLowerCase(),r={js:"javascript",ts:"typescript","c++":"cpp","c#":"csharp",cs:"csharp",shell:"bash",sh:"bash",zsh:"bash",yml:"yaml",protobuf:"proto",dockerfile:"docker",md:"markdown",htm:"html",py:"python",rs:"rust",kt:"kotlin",rb:"ruby"}[e]??e;return r in fp?r:void 0}var cd=null,Ti=null,d1=new Map;function bu(){return cd||(cd=Promise.all([import("./chunks/core-ZHTX3P2Q.js"),import("./chunks/dist-WSDF34DM.js"),import("./chunks/dark-plus-GYPKKZES.js"),import("./chunks/light-plus-QXH2UUWZ.js"),Promise.all(rM.map(t=>fp[t]()))]).then(([t,e,n,r,a])=>t.createHighlighterCore({themes:[n.default,r.default],langs:a.map(s=>s.default),engine:e.createJavaScriptRegexEngine()})).then(t=>(Ti=t,t),t=>{throw cd=null,t})),cd}function dd(t,e){return t.getLoadedLanguages().includes(e)}function fd(t){return!!Ti&&dd(Ti,t)}function f1(t){return Ti&&dd(Ti,t)?Ti:null}async function hd(t){let e=await bu();if(dd(e,t))return!0;let n=fp[t];if(!n)return!1;let r=d1.get(t);return r||(r=n().then(a=>e.loadLanguage(a.default)).then(()=>!0).catch(()=>!1),d1.set(t,r)),r}var Bo=null;function h1(t,e,n){let r=Ti;if(!r||!dd(r,e))return null;if(Bo&&Bo.text===t&&Bo.lang===e&&Bo.theme===n)return Bo.lines;try{let a=r.codeToTokensBase(t,{lang:e,theme:n,includeExplanation:!1});return Bo={text:t,lang:e,theme:n,lines:a},a}catch{return null}}function aM(t){return{highlight(e,n){let r=h1(e,n,t);if(!r)return[{type:"text",value:e}];let a=[];return r.forEach((s,i)=>{for(let o of s){if(!o.content)continue;let l={type:"element",tagName:"span",properties:{},color:o.color,children:[{type:"text",value:o.content}]};a.push(l)}i<r.length-1&&a.push({type:"text",value:`
|
|
31
|
+
`})}),a}}}function m1(t,e,n="dark-plus"){let r=_o(e);if(r&&fd(r))try{return Jw(t,{highlight:!0,refractor:aM(n),language:r})}catch{return}}var g1=(t,e,n)=>{let r=t.color;return t.type==="element"&&typeof r=="string"?(0,p1.createElement)("span",{key:n,style:{color:r}},t.children?.map((a,s)=>e(a,s))):e(t,n)};function pd(t){let e=It(String(t||"")).toLowerCase().trim();if(!e)return;let n=e;if(n==="dockerfile")return"docker";let r=n.includes(".")?n.split(".").pop():"";if(!r)return;let a={js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",json:"json",jsonl:"json",py:"python",rb:"ruby",php:"php",java:"java",kt:"kotlin",go:"go",rs:"rust",c:"c",h:"c",cpp:"cpp",cc:"cpp",cxx:"cpp",hpp:"cpp",cs:"csharp",swift:"swift",scala:"scala",r:"r",sql:"sql",sh:"bash",bash:"bash",zsh:"bash",fish:"bash",ps1:"powershell",yaml:"yaml",yml:"yaml",toml:"toml",ini:"ini",xml:"xml",html:"html",css:"css",scss:"scss",less:"less",graphql:"graphql",gql:"graphql",lua:"lua",dart:"dart",elm:"elm",tex:"latex",clj:"clojure",ex:"elixir",exs:"elixir",hs:"haskell",nim:"nim",pl:"perl",proto:"protobuf",md:"markdown",mdx:"mdx"};return r==="env"?"bash":a[r]??r}var x1=W(nr(),1);var md=W(ue(),1),sM=[{key:"auto",label:"Auto",Icon:js},{key:"unified",label:"Unified",Icon:Ws},{key:"split",label:"Split",Icon:Ts}];function gd({className:t}){let e=B(r=>r.diffViewMode),n=B(r=>r.setDiffViewMode);return(0,md.jsx)("div",{className:V("inline-flex items-center gap-0.5 rounded-md bg-white/5 p-0.5",t),children:sM.map(({key:r,label:a,Icon:s})=>(0,md.jsx)("button",{type:"button",onClick:()=>n(r),className:V("inline-flex items-center justify-center rounded p-1 transition",e===r?"bg-white/12 text-white/90":"text-white/40 hover:text-white/70 hover:bg-white/[0.06]"),title:`Diff layout: ${a}${r==="auto"?" (by width)":""}`,"aria-label":`Diff layout ${a}`,"aria-pressed":e===r,children:(0,md.jsx)(s,{className:"w-3 h-3"})},r))})}var tt=W(ue(),1),iM={"--diff-background-color":"transparent","--diff-text-color":"rgba(255,255,255,0.82)","--diff-font-family":"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace","--diff-selection-background-color":"rgba(139,92,246,0.35)","--diff-gutter-insert-background-color":"rgba(16,185,129,0.16)","--diff-gutter-delete-background-color":"rgba(244,63,94,0.16)","--diff-gutter-selected-background-color":"rgba(139,92,246,0.22)","--diff-code-insert-background-color":"rgba(16,185,129,0.10)","--diff-code-delete-background-color":"rgba(244,63,94,0.10)","--diff-code-insert-edit-background-color":"rgba(16,185,129,0.30)","--diff-code-delete-edit-background-color":"rgba(244,63,94,0.32)","--diff-code-selected-background-color":"rgba(139,92,246,0.16)","--diff-omit-gutter-line-color":"transparent"};function hp(t,e,n,r){let a=r.kind==="working"?{kind:r.kind,staged:r.staged}:r.kind==="commit"?{kind:r.kind,sha:r.sha}:{kind:r.kind,base:r.base,head:r.head};return`diff\0${t}\0${e}\0${n}\0${JSON.stringify(a)}`}function Di({source:t,repo:e="",path:n,mode:r,agentId:a,projectId:s,variant:i="tab",revision:o=0,canWrite:l=!1,stageRows:u=l,permissionPending:c=!1,runContent:d,peekContent:f}){let h=B(he=>he.client),[p]=(0,St.useState)(()=>f?.(`${hp(t,e,n,r)}\0${o}`,hp(t,e,n,r))),[g,m]=(0,St.useState)(()=>p===void 0?null:p&&p.ok!==!1?p.diff:""),[x,b]=(0,St.useState)(!1),[y,C]=(0,St.useState)(null),[I,L]=(0,St.useState)(()=>p!==void 0&&p.ok!==!1&&p.truncated===!0),[v,k]=(0,St.useState)(()=>p!==void 0&&p.ok===!1),[O,R]=(0,St.useState)(0),[P,H]=(0,St.useState)(null),[w,N]=(0,St.useState)(null),[j,K]=(0,St.useState)([]),[A,F]=(0,St.useState)(null),[_,X]=(0,St.useState)(!1),re=(0,St.useRef)(new Map),ae=(0,St.useRef)(0),Le=B(he=>he.loadGitStatus),ye=r.kind,q=r.kind==="working"?r.staged:!1,Q=r.kind==="commit"?r.sha:null,te=r.kind==="range"?r.base:null,ge=r.kind==="range"?r.head:null,de=(0,St.useMemo)(()=>ye==="working"?{kind:ye,staged:q}:ye==="commit"?{kind:ye,sha:Q??""}:{kind:ye,base:te??"",head:ge??""},[ye,q,Q,te,ge]),De=(0,St.useMemo)(()=>i1(de),[de]),Xe=B(he=>he.diffViewMode),Qe=(0,St.useRef)(null),rt=(0,x1.useContainerWidth)(Qe),at=Xe==="auto"?rt?"split":"unified":Xe,Ft=(0,St.useMemo)(()=>pd(n),[n]),[Ue,ut]=(0,St.useState)(!1);(0,St.useEffect)(()=>{let he=_o(Ft);if(!he){ut(!1);return}if(fd(he)){ut(!0);return}let Me=!1;return ut(!1),bu().then(()=>hd(he)).then(xe=>{Me||ut(xe)}),()=>{Me=!0}},[Ft]),(0,St.useEffect)(()=>{if(re.current.clear(),H(null),N(null),K([]),F(null),X(!1),!a||!t||!n){L(!1),k(!1),m(null),C(null),b(!1);return}let he=++ae.current;return b(!0),C(null),(async()=>{try{let Me=()=>yc({agentId:a,...s?{projectId:s}:{},source:t,...e?{repo:e}:{},path:n,...s1(de)},h),xe=hp(t,e,n,de),Fe={key:`${xe}\0${o}`,family:xe,bytes:Nt=>Nt&&Nt.ok!==!1?Nt.diff.length*2:64,fresh:O>0},ve=d?await d(Me,()=>he===ae.current,Fe):await Me();if(!ve||he!==ae.current)return;ve&&ve.ok===!1?(m(""),k(!0),L(!1)):(m(typeof ve?.diff=="string"?ve.diff:""),k(!1),L(ve?.truncated===!0)),b(!1)}catch(Me){if(he!==ae.current)return;C(Me instanceof Error?Me.message:"Diff failed"),m(null),k(!1),L(!1),b(!1)}})(),()=>{ae.current++}},[h,a,s,t,e,n,de,O,o,d]);let{files:st,truncated:yt,hunkPatches:vt}=(0,St.useMemo)(()=>e1(g,I),[g,I]),Ut=st.some(he=>he.hunks.length>0),Et=It(n)||n,me=c1(y),Ye=st.length===1?st[0]:null,cn=u&&ye==="working"&&!!a&&!!Ye&&Ye.type==="modify"&&!yt&&!!vt&&vt.hunks.length===Ye.hunks.length,fe=!!a&&!!Ye&&!yt&&Ye.hunks.length>0,Re=(0,St.useCallback)(async()=>{if(!a)return null;let he=ae.current,Me=De.type==="worktree"?"wt":De.rev,xe=`${t}\0${e}\0${n}\0${Me}`,Fe=re.current.get(xe),ve=Nt=>(re.current.set(xe,Nt),he===ae.current&&(Nt.ok?F(Nt.content):X(!0)),Nt.ok?Nt.content:null);if(Fe)return ve(Fe);try{if(De.type==="show"){let yn=()=>j0({agentId:a,...s?{projectId:s}:{},source:t,...e?{repo:e}:{},path:n,rev:De.rev},h),Nn=d?await d(yn,()=>he===ae.current):await yn();return!Nn||he!==ae.current?null:ve(Nn.ok?{ok:!0,content:Nn.content}:{ok:!1})}let Nt=()=>oo({agentId:a,...s?{projectId:s}:{},files:[`${t}://${e?`${e}/`:""}${n}`]},h),pt=d?await d(Nt,()=>he===ae.current):await Nt();if(!pt||he!==ae.current)return null;let kn=co(pt)[0];return!kn||typeof kn.error=="string"?ve({ok:!1}):ve({ok:!0,content:fo(kn)})}catch{return ve({ok:!1})}},[h,a,s,t,e,n,De,d]),Oe=(0,St.useMemo)(()=>Ye&&A!==null?ud(Ye.hunks,A):null,[Ye,A]),Pe=(0,St.useMemo)(()=>st.map(he=>he!==Ye||!Oe||j.length===0?he.hunks:n1(he.hunks,Oe,j)),[st,Ye,Oe,j]),ze=Oe?Oe.length:null,We=(0,St.useMemo)(()=>Ue?st.map((he,Me)=>m1(Pe[Me]??he.hunks,Ft)):st.map(()=>{}),[st,Pe,Ft,Ue]),nt=(0,St.useCallback)(async he=>{if(!fe)return;let Me=ae.current,xe=A??await Re();if(xe===null||Me!==ae.current||!Ye)return;let Fe;if(he.lines===null){let ve=xu(Ye.hunks[Ye.hunks.length-1]??null,ud(Ye.hunks,xe).length);if(!ve||ve.lines===null)return;Fe={start:ve.start,end:ve.end}}else Fe={start:he.start,end:he.end};K(ve=>[...ve,Fe])},[fe,A,Re,Ye]),Vt=(0,St.useCallback)(async()=>{if(!fe||!Ye)return;let he=ae.current,Me=A??await Re();if(Me===null||he!==ae.current)return;let xe=t1(Ye.hunks,ud(Ye.hunks,Me).length);xe.length>0&&K(Fe=>[...Fe,...xe])},[fe,Ye,A,Re]),et=(0,St.useMemo)(()=>{if(!fe||!Ye)return!1;let he=st.indexOf(Ye),Me=Pe[he]??Ye.hunks;for(let xe=0;xe<Me.length;xe++)if(ld(xe===0?null:Me[xe-1],Me[xe]))return!0;return xu(Me[Me.length-1]??null,ze)!==null},[fe,Ye,st,Pe,ze]),At=(0,St.useCallback)(async he=>{if(x||c||!l||!cn||!vt||!a)return;let Me=Qw(vt.header,vt.hunks[he]);if(!Me){N("Could not build a hunk patch for this change.");return}let xe=ae.current;H(he),N(null);try{if(q?await K0({agentId:a,...s?{projectId:s}:{},source:t,...e?{repo:e}:{},hunk:Me},h):await $0({agentId:a,...s?{projectId:s}:{},source:t,...e?{repo:e}:{},hunk:Me},h),xe!==ae.current)return;re.current.clear(),Le({agentId:a,projectId:s}),R(Fe=>Fe+1)}catch(Fe){xe===ae.current&&N(Fe instanceof Error?Fe.message:"Hunk apply failed")}finally{xe===ae.current&&H(null)}},[h,x,c,l,cn,vt,a,s,t,e,q,Le]),bn=he=>{let Me=he.lines===null?"Expand to end of file":`${he.lines} hidden ${he.lines===1?"line":"lines"}`;return _?he.lines===null?null:(0,tt.jsx)(od,{children:(0,tt.jsxs)("div",{className:"px-3 py-0.5 font-mono text-[10px] text-white/30",children:["\u22EF ",Me]})},`gap-${he.start}`):(0,tt.jsx)(od,{children:(0,tt.jsxs)("button",{type:"button",onClick:()=>{nt(he)},className:"block w-full px-3 py-0.5 text-left font-mono text-[10px] text-violet-300/70 transition-colors hover:bg-violet-500/10 hover:text-violet-200/90",title:"Expand this hidden region",children:["\u22EF ",Me]})},`gap-${he.start}`)},Ve=(he,Me)=>Me.length===0?null:(0,tt.jsx)(od,{children:(0,tt.jsx)("div",{className:"flex items-center justify-end gap-2 px-2 py-1",children:Me.map(xe=>(0,tt.jsxs)("button",{type:"button",onClick:()=>{At(xe)},disabled:P!==null||x||c||!l,className:V("inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-[10px] transition-colors disabled:opacity-40",q?"border-white/12 bg-white/[0.04] text-white/70 hover:bg-white/[0.09]":"border-emerald-500/25 bg-emerald-500/12 text-emerald-100/90 hover:bg-emerald-500/18"),title:q?"Unstage this hunk":"Stage this hunk",children:[P===xe?(0,tt.jsx)(pp.LiveSpinner,{className:"h-3 w-3"}):q?(0,tt.jsx)(bi,{className:"h-3 w-3"}):(0,tt.jsx)($n,{className:"h-3 w-3"}),q?"Unstage hunk":"Stage hunk",Me.length>1?(0,tt.jsxs)("span",{className:"font-mono text-white/45",children:["@",Ye?.hunks[xe]?.oldStart]}):null]},xe))})},`stage-${he.oldStart}`),Be=(0,tt.jsxs)("button",{type:"button",onClick:()=>{Vt()},className:"inline-flex shrink-0 items-center gap-1 rounded-md border border-white/10 px-1.5 py-0.5 text-[10px] text-white/55 transition-colors hover:bg-white/[0.06] hover:text-white/80",title:"Expand all hidden regions",children:[(0,tt.jsx)(nu,{className:"h-3 w-3"}),"Expand all"]}),Rt=y?me?(0,tt.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,tt.jsx)(xi,{className:"h-3.5 w-3.5 shrink-0 text-white/35"}),(0,tt.jsx)("span",{children:"You don't have permission to view this file's changes."})]}):(0,tt.jsx)("div",{className:"px-3 py-4 text-[11px] text-rose-300/70",children:y}):x&&!g?(0,tt.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,tt.jsx)(pp.LiveSpinner,{className:"h-3.5 w-3.5"}),"Loading diff\u2026"]}):v?(0,tt.jsxs)("div",{className:"flex items-center justify-center gap-1.5 px-3 py-6 text-center text-[11px] text-amber-200/70",children:[(0,tt.jsx)(gt,{className:"h-3.5 w-3.5 shrink-0"}),(0,tt.jsx)("span",{children:"Diff too large to display \u2014 the change exceeds the server output bound."})]}):Ut?(0,tt.jsx)("div",{style:iM,className:V("nrs-git-diff px-1 py-1 text-[12px] leading-[18px]"),children:st.map((he,Me)=>{let xe=he===Ye&&fe;return(0,tt.jsx)(Vw,{viewType:at,diffType:he.type,hunks:Pe[Me]??he.hunks,tokens:We[Me],renderToken:g1,children:Fe=>{let ve=[],Nt=pt=>{pt&&ve.push(pt)};if(Fe.forEach((pt,kn)=>{if(xe){let yn=ld(kn===0?null:Fe[kn-1],pt);yn&&Nt(bn(yn))}cn&&he===Ye&&Nt(Ve(pt,r1(pt,he.hunks))),ve.push((0,tt.jsx)(cp,{hunk:pt},`h-${pt.oldStart}-${pt.oldLines}`))}),xe){let pt=xu(Fe[Fe.length-1]??null,ze);pt&&Nt(bn(pt))}return ve}},`${he.oldRevision??""}-${he.newRevision??""}-${Me}`)})}):(0,tt.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:l1(de)});return(0,tt.jsxs)("div",{ref:Qe,className:V("flex w-full flex-col",i==="tab"&&"h-full min-h-0"),children:[i==="tab"?(0,tt.jsxs)("div",{className:"flex shrink-0 items-center gap-2 px-3 py-1.5 text-[11px]",style:{borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,tt.jsx)(Cr,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),(0,tt.jsx)("span",{className:"shrink-0 font-medium text-white/85",children:Et}),(0,tt.jsx)("span",{className:"truncate font-mono text-white/40",children:n}),(0,tt.jsx)("span",{className:"ml-auto shrink-0 rounded-full border border-white/10 px-2 py-0.5 text-[9px] uppercase tracking-wider text-white/45",children:o1(de)}),(0,tt.jsx)(gd,{}),et&&!_?Be:null]}):et&&!_?(0,tt.jsx)("div",{className:"flex shrink-0 items-center justify-end px-2 pt-1",children:Be}):null,yt?(0,tt.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5 px-3 py-1 text-[10px] text-amber-200/70",children:[(0,tt.jsx)(gt,{className:"h-3 w-3 shrink-0"}),(0,tt.jsx)("span",{children:"Diff truncated by the server (2 MB cap) \u2014 showing the leading hunks; hunk staging is disabled."})]}):null,w?(0,tt.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5 px-3 py-1 text-[10px] text-rose-300/75",children:[(0,tt.jsx)(gt,{className:"h-3 w-3 shrink-0"}),(0,tt.jsx)("span",{className:"truncate",children:w})]}):null,i==="tab"?(0,tt.jsx)("div",{className:"min-h-0 flex-1 overflow-auto",children:Rt}):Rt]})}var it=W(ue(),1),mp={M:"text-amber-400",A:"text-emerald-400",D:"text-rose-400",R:"text-sky-400",C:"text-sky-400",T:"text-white/60"},xd={M:"Modified",A:"Added",D:"Deleted",R:"Renamed",C:"Copied",T:"Type changed"};function oM(t){let e=new Date(t);return Number.isNaN(e.getTime())?t:e.toLocaleString()}var lM=(0,ms.memo)(function({file:e,mode:n,source:r,repo:a,agentId:s,projectId:i,defaultExpanded:o,queue:l}){let[u,c]=(0,ms.useState)(o),d=(e.status[0]??"M").toUpperCase(),f=e.path.includes("/")?e.path.slice(0,e.path.lastIndexOf("/")):"",h=e.path.includes("/")?e.path.slice(e.path.lastIndexOf("/")+1):e.path;return(0,it.jsxs)("div",{ref:p=>l.register(e.path,p),className:"overflow-hidden rounded-lg border border-white/8 bg-black/20",children:[(0,it.jsxs)("button",{type:"button",onClick:()=>c(p=>!p),className:"flex w-full items-center gap-2 px-2.5 py-1.5 text-left transition-colors hover:bg-white/[0.03]",title:e.path,"aria-expanded":u,children:[u?(0,it.jsx)(qt,{className:"h-3.5 w-3.5 shrink-0 text-white/40"}):(0,it.jsx)(Sn,{className:"h-3.5 w-3.5 shrink-0 text-white/40"}),(0,it.jsx)("span",{className:V("shrink-0 text-[10px] font-bold leading-none tabular-nums",mp[d]??"text-white/60"),title:xd[d]??"Changed","aria-label":`Status: ${xd[d]??"Changed"}`,children:d}),(0,it.jsxs)("span",{className:"min-w-0 flex-1 truncate text-xs text-white/85",children:[h,f?(0,it.jsxs)("span",{className:"ml-1.5 font-mono text-[10px] text-white/30",children:[f,"/"]}):null]}),e.renamedFrom?(0,it.jsxs)("span",{className:"shrink-0 truncate font-mono text-[10px] text-white/35",title:`Renamed from ${e.renamedFrom}`,children:["\u2190 ",e.renamedFrom]}):null,(0,it.jsx)(Ha,{added:e.added,removed:e.removed,binary:e.binary,className:"shrink-0"})]}),u&&l.visible.has(e.path)?(0,it.jsx)("div",{className:"border-t border-white/5",children:(0,it.jsx)("div",{className:"max-h-96 overflow-auto",style:{scrollbarGutter:"auto"},children:(0,it.jsx)(Di,{variant:"card",canWrite:!1,runContent:l.run,source:r,repo:a,path:e.path,mode:n,agentId:s,projectId:i})})}):null]})});function gp({target:t,agentId:e,projectId:n}){let r=B(x=>x.client),[a,s]=(0,ms.useState)(null),i=No(a),[o,l]=(0,ms.useState)({phase:"loading"}),[u,c]=(0,ms.useState)(null),{source:d}=t,f=t.repo??"",h=t.kind==="commit"?`c:${f}:${t.sha}`:`o:${f}:${t.base}..${t.head}`;(0,ms.useEffect)(()=>{if(l({phase:"loading"}),c(null),!e||!d)return;let x=!1;return(async()=>{try{if(t.kind==="commit"){let b=await wc({agentId:e,...n?{projectId:n}:{},source:d,...f?{repo:f}:{},sha:t.sha},r);if(x)return;b.ok===!1?l({phase:"unavailable"}):l({phase:"ready",files:b.files,range:null});try{let y=await vc({agentId:e,...n?{projectId:n}:{},source:d,...f?{repo:f}:{},maxCount:1,ref:t.sha},r),C=Array.isArray(y?.commits)?y.commits[0]:void 0;!x&&C&&c({author:C.author,date:C.date})}catch{}}else{let b=await Cl({agentId:e,...n?{projectId:n}:{},source:d,...f?{repo:f}:{}},r);if(x)return;!b.ok||!b.baseSha||!b.headSha?l({phase:"no-upstream"}):l({phase:"ready",files:Array.isArray(b.files)?b.files:[],range:{base:b.baseSha,head:b.headSha}})}}catch(b){if(x)return;l({phase:"error",message:b instanceof Error?b.message:"Change-set failed"})}})(),()=>{x=!0}},[e,n,d,h]);let p=t.kind==="commit"?t:null,g=p!==null,m=o.phase==="ready"&&o.range?`${gn(o.range.base)}..${gn(o.range.head)}`:t.kind==="outgoing"?`${gn(t.base)}..${gn(t.head)}`:"";return(0,it.jsxs)("div",{className:"flex h-full w-full min-h-0 flex-col",children:[(0,it.jsx)("div",{className:"flex shrink-0 items-center gap-2 px-3 py-1.5 text-[11px]",style:{borderBottom:"1px solid rgba(255,255,255,0.05)"},children:p?(0,it.jsxs)(it.Fragment,{children:[(0,it.jsx)(Kr,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),(0,it.jsx)("span",{className:"shrink-0 rounded bg-white/[0.06] px-1.5 py-0.5 font-mono text-[10px] text-violet-200/90",children:gn(p.sha)}),(0,it.jsx)("span",{className:"min-w-0 truncate font-medium text-white/85",children:p.subject}),u?(0,it.jsxs)("span",{className:"ml-auto shrink-0 text-[10px] text-white/40",children:[u.author," \xB7 ",oM(u.date)]}):null]}):(0,it.jsxs)(it.Fragment,{children:[(0,it.jsx)(Vr,{className:"h-3.5 w-3.5 shrink-0 text-blue-300/80"}),(0,it.jsx)("span",{className:"shrink-0 font-medium text-white/85",children:"Outgoing changes"}),(0,it.jsx)("span",{className:"truncate font-mono text-[10px] text-white/40",children:m}),(0,it.jsx)("span",{className:"ml-auto shrink-0 text-[10px] text-white/35",title:"Computed from local refs (last fetch) \u2014 fetching/pulling remotes lands in a later increment.",children:"Local refs only \u2014 fetch lands later"})]})}),(0,it.jsx)("div",{ref:s,className:"min-h-0 flex-1 overflow-auto px-2 py-2",children:o.phase==="loading"?(0,it.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,it.jsx)($e,{className:"h-3.5 w-3.5 animate-spin"}),"Loading changes\u2026"]}):o.phase==="error"?(0,it.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-4 text-[11px] text-rose-300/70",children:[(0,it.jsx)(gt,{className:"h-3.5 w-3.5 shrink-0"}),(0,it.jsx)("span",{className:"truncate",children:o.message})]}):o.phase==="unavailable"?(0,it.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:"Commit details unavailable \u2014 the commit may no longer exist in this repository."}):o.phase==="no-upstream"?(0,it.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:"No upstream to compare against \u2014 everything here is local."}):o.files.length===0?(0,it.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:g?"This commit changed no files.":"Nothing outgoing \u2014 the upstream is up to date."}):(0,it.jsx)("div",{className:"flex flex-col gap-1.5",children:o.files.map(x=>(0,it.jsx)(lM,{file:x,mode:p?{kind:"commit",sha:p.sha}:{kind:"range",base:o.range?.base??"",head:o.range?.head??""},source:d,repo:f,agentId:e,projectId:n,defaultExpanded:!0,queue:i},x.path))})})]})}var ie=W(ue(),1),Yr=30,S1=16,vp=14,b1=4.5,bd=["#cba6f7","#a6e3a1","#f9e2af","#f38ba8","#94e2d5","#fab387","#b4befe","#89b4fa"];function bp(t){return bd[(t%bd.length+bd.length)%bd.length]}var yp=t=>vp+t*S1;function uM(){let t=null,e=new Set;return{get:()=>t,set:n=>{let r=typeof n=="function"?n(t):n;if(r!==t){t=r;for(let a of e)a()}},subscribe:n=>(e.add(n),()=>{e.delete(n)})}}var cM=null,dM=()=>cM;function fM({store:t,commits:e,expandedShas:n}){let r=ft.default.useSyncExternalStore(t.subscribe,t.get,dM);if(!r||n.has(r.sha))return null;let a=e.find(s=>s.sha===r.sha);return a?(0,ie.jsxs)("div",{className:"pointer-events-none absolute z-30 overflow-hidden rounded-md border border-white/10 bg-[#1b1b26] px-2.5 py-2 shadow-lg shadow-black/50",style:{left:vp,right:8,maxHeight:"55%",...r.flip?{bottom:r.above}:{top:r.below}},children:[(0,ie.jsx)("div",{className:"whitespace-pre-wrap break-words text-[11px] font-medium leading-snug text-white/90",children:a.subject||"(no message)"}),a.body?(0,ie.jsx)("div",{className:"mt-1 whitespace-pre-wrap break-words text-[10px] leading-snug text-white/55",children:a.body}):null,(0,ie.jsxs)("div",{className:"mt-1.5 flex items-center gap-2 text-[10px] text-white/40",children:[(0,ie.jsx)("span",{className:"font-mono",children:gn(a.sha)}),(0,ie.jsx)("span",{className:"min-w-0 truncate",children:a.author}),(0,ie.jsx)("span",{children:_h(a.date)})]})]}):null}function y1(t){let e=yp(t.fromLane),n=yp(t.toLane),r=t.fromY==="edge"?0:Yr/2,a=t.toY==="edge"?Yr:Yr/2;if(e===n)return`M${e} ${r} L${n} ${a}`;if(t.toY==="edge"){let i=2*n-e;return`M${e} ${r} C ${e} ${(r+a)/2} ${(3*e+i)/4} ${(r+3*a)/4} ${n} ${a}`}let s=2*e-n;return`M${e} ${r} C ${(s+3*n)/4} ${(3*r+a)/4} ${n} ${(r+a)/2} ${n} ${a}`}function hM(t){return(t.split("->").pop()??t).replace(/^tag:\s*/,"").trim()}function v1(t,e){(t.key==="Enter"||t.key===" ")&&(t.preventDefault(),e())}function pM({file:t,onClick:e,showCounts:n}){let r=t.path.lastIndexOf("/"),a=r<0?t.path:t.path.slice(r+1),s=r<0?"":t.path.slice(0,r),i=(t.status[0]??"M").toUpperCase(),o=Lo(t.path);return(0,ie.jsxs)("button",{type:"button",onClick:()=>e(t),className:"flex w-full min-w-0 items-center gap-1.5 overflow-hidden rounded-md py-1 pl-2 pr-1.5 text-left transition-colors hover:bg-white/[0.05]",title:t.renamedFrom?`${t.renamedFrom} \u2192 ${t.path}`:t.path,children:[(0,ie.jsx)(o,{className:"h-4 w-4 shrink-0 text-white/55"}),(0,ie.jsx)("span",{className:"shrink-0 truncate text-xs text-white/85",children:a}),s?(0,ie.jsx)("span",{className:"min-w-0 flex-1 truncate text-[10px] text-white/35",children:s}):(0,ie.jsx)("span",{className:"flex-1"}),n?(0,ie.jsx)(Ha,{added:t.added,removed:t.removed,binary:t.binary,className:"mr-1"}):null,(0,ie.jsx)("span",{className:V("shrink-0 text-[10px] font-bold leading-none tabular-nums",mp[i]??"text-white/60"),"aria-label":`Status: ${xd[i]??"Changed"}`,children:i})]})}function w1({entry:t,emptyText:e,unavailableText:n,onFileClick:r,showCounts:a}){return t.status==="loading"?(0,ie.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[10px] text-white/40",children:[(0,ie.jsx)(k1.LiveSpinner,{className:"h-3 w-3"}),"Loading files\u2026"]}):t.status==="error"?(0,ie.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[10px] text-rose-300/70",children:[(0,ie.jsx)(gt,{className:"h-3 w-3 shrink-0"}),(0,ie.jsx)("span",{className:"truncate",children:t.message})]}):t.status==="unavailable"?(0,ie.jsx)("div",{className:"px-2 py-1 text-[10px] text-white/35",children:n}):t.files.length===0?(0,ie.jsx)("div",{className:"px-2 py-1 text-[10px] text-white/35",children:e}):(0,ie.jsx)("div",{className:"space-y-px",children:t.files.map(s=>(0,ie.jsx)(pM,{file:s,onClick:r,showCounts:a},s.path))})}function C1({source:t,repo:e="",agentId:n,projectId:r,repoName:a,showCounts:s=!0,onOutgoingStat:i}){let o=B(fe=>fe.client),[l,u]=(0,ft.useState)(Oh),[c,d]=(0,ft.useState)(!1),[f,h]=(0,ft.useState)(null),p=(0,ft.useRef)(0),g=(0,ft.useRef)(!1),m=(0,ft.useRef)(!1),x=(0,ft.useRef)(l);x.current=l;let[b,y]=(0,ft.useState)(()=>new Set),[C,I]=(0,ft.useState)(!1),[L,v]=(0,ft.useState)(()=>new Map),[k,O]=(0,ft.useState)({status:"idle"}),R=(0,ft.useRef)(null),P=(0,ft.useRef)(null);P.current===null&&(P.current=uM());let H=P.current,w=(0,ft.useRef)(0),N=(0,ft.useRef)(0),j=B(fe=>fe.gitLogNonce),K=B(fe=>fe.setGitDiffTarget),A=B(fe=>fe.setGitCommitTarget),F=B(fe=>fe.setActiveWorkspaceTab),[_,X]=(0,ft.useState)(null),[re,ae]=(0,ft.useState)(null),[Le,ye]=(0,ft.useState)({}),q=(0,ft.useRef)(s);q.current=s;let Q=(0,ft.useRef)(i);Q.current=i;let te=(0,ft.useCallback)(async(fe,Re,Oe)=>{if(!n||!t)return;let Pe=++p.current;g.current=!0,d(!0),h(null);try{let ze=await vc({agentId:n,...r?{projectId:r}:{},source:t,...e?{repo:e}:{},maxCount:Re,skip:fe},o);if(Pe!==p.current)return;let We={commits:Array.isArray(ze?.commits)?ze.commits:[],hasMore:ze?.hasMore===!0,outgoing:Array.isArray(ze?.outgoing)?ze.outgoing:void 0};u(nt=>Oe==="append"?Rv(nt,We):Nv(We)),q.current&&W0({agentId:n,...r?{projectId:r}:{},source:t,...e?{repo:e}:{},maxCount:Re,skip:fe},o).then(nt=>{Pe===p.current&&(ye(Vt=>Oe==="append"?{...Vt,...nt.stats}:{...nt.stats}),Oe==="replace"&&Q.current?.(nt.outgoingStat??null))}).catch(()=>{}),Oe==="replace"&&(N.current++,O(nt=>nt.status==="idle"?nt:{status:"idle"})),d(!1)}catch(ze){if(Pe!==p.current)return;h(ze instanceof Error?ze.message:"Git log failed"),d(!1)}finally{Pe===p.current&&(g.current=!1)}},[n,r,t,e]);(0,ft.useEffect)(()=>{if(p.current++,g.current=!1,w.current++,N.current++,u(Oh),h(null),y(new Set),I(!1),v(new Map),O({status:"idle"}),!n||!t){d(!1);return}te(0,200,"replace")},[n,r,t,te]);let ge=(0,ft.useRef)(j);(0,ft.useEffect)(()=>{j!==ge.current&&(ge.current=j,!(!n||!t)&&te(0,Bh(x.current.commits.length),"replace"))},[j,n,t,te]),(0,ft.useEffect)(()=>{if(!_||!re||(m.current=!1,typeof IntersectionObserver>"u"))return;let fe=new IntersectionObserver(Re=>{for(let Pe of Re)m.current=Pe.isIntersecting;if(!m.current)return;let Oe=x.current;!Oe.hasMore||g.current||te(Oe.nextSkip,200,"append")},{root:_,rootMargin:"120px"});return fe.observe(re),()=>fe.disconnect()},[_,re,te]),(0,ft.useEffect)(()=>{c||f!==null||!m.current||g.current||l.hasMore&&te(l.nextSkip,200,"append")},[l,c,f,te]);let de=(0,ft.useCallback)(async fe=>{if(!n||!t)return;let Re=w.current;v(Oe=>new Map(Oe).set(fe,{status:"loading"}));try{let Oe=await wc({agentId:n,...r?{projectId:r}:{},source:t,...e?{repo:e}:{},sha:fe},o);if(Re!==w.current)return;v(Pe=>new Map(Pe).set(fe,Oe.ok===!1?{status:"unavailable"}:{status:"ready",files:Array.isArray(Oe.files)?Oe.files:[]}))}catch(Oe){if(Re!==w.current)return;v(Pe=>new Map(Pe).set(fe,{status:"error",message:Oe instanceof Error?Oe.message:"Commit files failed"}))}},[n,r,t,e]),De=l.commits,Xe=Ks(t,a),Qe=(0,ft.useMemo)(()=>Lv(De),[De]),rt=Math.max(40,vp+Qe.laneCount*S1+8),at=(0,ft.useMemo)(()=>Mv(De,l.outgoing),[De,l.outgoing]),Ft=(0,ft.useMemo)(()=>new Set(l.outgoing??[]),[l.outgoing]),Ue=(0,ft.useMemo)(()=>at.some(fe=>fe.kind==="outgoing-divider"),[at]);(0,ft.useEffect)(()=>{if(!C||k.status!=="idle"||!Ue||!n||!t)return;let fe=++N.current;O({status:"loading"}),(async()=>{try{let Re=await Cl({agentId:n,...r?{projectId:r}:{},source:t,...e?{repo:e}:{}},o);if(fe!==N.current)return;!Re.ok||!Re.baseSha||!Re.headSha?O({status:"no-upstream"}):O({status:"ready",base:Re.baseSha,head:Re.headSha,files:Array.isArray(Re.files)?Re.files:[]})}catch(Re){if(fe!==N.current)return;O({status:"error",message:Re instanceof Error?Re.message:"Outgoing changes failed"})}})()},[C,k.status,Ue,n,r,t,e]);let ut=So({count:at.length,getScrollElement:()=>_,estimateSize:()=>Yr,overscan:12,getItemKey:fe=>Tv(at[fe],De)}),st=()=>{!n||!t||te(0,Bh(x.current.commits.length),"replace")},yt=(fe,Re)=>{if(b.has(fe)){ut.resizeItem(Re,Yr),y(Pe=>{let ze=new Set(Pe);return ze.delete(fe),ze});return}y(Pe=>new Set(Pe).add(fe));let Oe=L.get(fe);(!Oe||Oe.status==="error")&&de(fe)},vt=fe=>{let Re=!C;Re||ut.resizeItem(fe,Yr),Re&&k.status==="error"&&O({status:"idle"}),I(Re)},Ut=e?{repo:e}:{},Et=(fe,Re)=>{t&&(K({source:t,...Ut,path:Re.path,commit:fe}),F("git-diff"))},me=fe=>{t&&(A({source:t,...Ut,kind:"commit",sha:fe.sha,subject:fe.subject}),F("git-commit"))},Ye=fe=>{!t||k.status!=="ready"||(K({source:t,...Ut,path:fe.path,base:k.base,head:k.head}),F("git-diff"))},cn=()=>{if(!t||!n)return;if(k.status==="ready"){A({source:t,...Ut,kind:"outgoing",base:k.base,head:k.head}),F("git-commit");return}let fe=++N.current;O({status:"loading"}),(async()=>{try{let Re=await Cl({agentId:n,...r?{projectId:r}:{},source:t,...e?{repo:e}:{}},o);if(fe!==N.current)return;if(!Re.ok||!Re.baseSha||!Re.headSha){O({status:"no-upstream"});return}O({status:"ready",base:Re.baseSha,head:Re.headSha,files:Array.isArray(Re.files)?Re.files:[]}),A({source:t,...Ut,kind:"outgoing",base:Re.baseSha,head:Re.headSha}),F("git-commit")}catch(Re){if(fe!==N.current)return;O({status:"error",message:Re instanceof Error?Re.message:"Outgoing changes failed"})}})()};return(0,ie.jsxs)("div",{ref:R,className:"relative flex h-full w-full min-h-0 flex-col",children:[(0,ie.jsxs)("div",{className:"flex shrink-0 items-center gap-2 px-3 py-1.5 text-[11px]",style:{borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,ie.jsx)(Kr,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),(0,ie.jsx)("span",{className:"shrink-0 font-medium text-white/85",children:"Commit graph"}),Xe.prefix?(0,ie.jsxs)(ie.Fragment,{children:[(0,ie.jsx)("span",{className:"shrink-0 font-mono text-white/40",children:Xe.prefix}),(0,ie.jsx)("span",{className:"truncate font-medium text-white/85",children:Xe.name})]}):(0,ie.jsx)("span",{className:"truncate font-mono text-white/40",children:Xe.name}),(0,ie.jsxs)("span",{className:"ml-auto shrink-0 tabular-nums text-white/40",children:[De.length,l.hasMore?"+":""," commit",De.length===1?"":"s"]}),(0,ie.jsx)("button",{type:"button",onClick:st,className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-white/40 transition-colors hover:bg-white/[0.06] hover:text-white/70",title:"Refresh commit graph","aria-label":"Refresh commit graph",children:(0,ie.jsx)(Xt,{className:V("h-3 w-3",c&&"animate-spin")})})]}),f&&De.length>0?(0,ie.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5 border-b border-white/[0.05] px-3 py-1 text-[10px] text-rose-300/70",children:[(0,ie.jsx)(gt,{className:"h-3 w-3 shrink-0"}),(0,ie.jsx)("span",{className:"truncate",children:f})]}):null,(0,ie.jsx)("div",{ref:X,className:"min-h-0 flex-1 overflow-auto",children:f&&De.length===0?(0,ie.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-4 text-[11px] text-rose-300/70",children:[(0,ie.jsx)(gt,{className:"h-3 w-3 shrink-0"}),f]}):c&&De.length===0?(0,ie.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,ie.jsx)($e,{className:"h-3.5 w-3.5 animate-spin"}),"Loading commit graph\u2026"]}):De.length===0?(0,ie.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:"No commits yet."}):(0,ie.jsxs)(ie.Fragment,{children:[(0,ie.jsx)("div",{style:{height:ut.getTotalSize(),width:"100%",position:"relative"},children:ut.getVirtualItems().map(fe=>{let Re=at[fe.index];if(!Re)return null;if(Re.kind==="outgoing-divider"){let Be=k.status==="ready"?{status:"ready",files:k.files}:k.status==="error"?k:{status:"loading"},Rt=at[fe.index+1],he=Av(Qe.rowSegments,Rt?.kind==="commit"?Rt.row:-1);return(0,ie.jsxs)("div",{"data-index":fe.index,ref:C?ut.measureElement:void 0,className:"absolute left-0 top-0 w-full",style:{transform:`translateY(${fe.start}px)`},children:[(0,ie.jsxs)("div",{role:"button",tabIndex:0,onClick:()=>vt(fe.index),onKeyDown:Me=>v1(Me,()=>vt(fe.index)),className:V("group flex w-full min-w-0 cursor-pointer items-center gap-1.5 text-[11px] transition-colors hover:bg-white/[0.04]",he.length>0?"pr-2":"px-2"),style:{height:Yr},title:"The blue hollow dots mark commits not yet pushed to origin (local refs only, from the last known upstream). On a diverged/interleaved history this divider is an approximate boundary \u2014 the dots are the source of truth.",children:[he.length>0?(0,ie.jsx)("svg",{"data-divider-lanes":!0,width:rt,height:Yr,className:"shrink-0",style:{display:"block"},"aria-hidden":!0,children:he.map((Me,xe)=>(0,ie.jsx)("path",{d:y1(Me),fill:"none",stroke:bp(Me.colorLane),strokeWidth:1.5,strokeOpacity:.55,strokeLinecap:"round"},xe))}):null,C?(0,ie.jsx)(qt,{className:"h-3 w-3 shrink-0 text-white/40"}):(0,ie.jsx)(Sn,{className:"h-3 w-3 shrink-0 text-white/40"}),(0,ie.jsx)(Vr,{className:"h-3 w-3 shrink-0 text-blue-300/80"}),(0,ie.jsx)("span",{className:"shrink-0 text-[9px] font-bold uppercase tracking-wider text-blue-200/85",children:"Outgoing changes"}),(0,ie.jsx)("span",{className:"shrink-0 rounded bg-blue-400/15 px-1 py-0.5 text-[9px] leading-none tabular-nums text-blue-100/80",children:l.outgoing?.length??0}),(0,ie.jsx)("span",{className:"h-px min-w-0 flex-1 bg-blue-400/20","aria-hidden":!0}),(0,ie.jsx)("button",{type:"button",onClick:Me=>{Me.stopPropagation(),cn()},className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-white/40 opacity-0 transition group-hover:opacity-100 focus-visible:opacity-100 hover:bg-white/10 hover:text-white/75",title:"Open Changes (all outgoing files)","aria-label":"Open outgoing changes",children:(0,ie.jsx)(bo,{className:"h-3 w-3"})})]}),C?(0,ie.jsx)("div",{className:"border-t border-white/[0.05] pb-1.5 pl-1 pr-2 pt-1",children:k.status==="no-upstream"?(0,ie.jsx)("div",{className:"px-2 py-1 text-[10px] text-white/35",children:"No upstream to compare against."}):(0,ie.jsx)(w1,{entry:Be,emptyText:"Nothing outgoing \u2014 the upstream is up to date.",unavailableText:"Outgoing changes unavailable.",onFileClick:Ye,showCounts:s})}):null]},fe.key)}let Oe=Qe.nodes[Re.row];if(!Oe)return null;let Pe=Oe.commit,ze=Qe.rowSegments[Re.row]??[],We=yp(Oe.lane),nt=bp(Oe.lane),Vt=Pe.refs??[],et=b.has(Pe.sha),At=Fv(Oe.isMerge,Ft.has(Pe.sha)),bn=Ev(At,nt),Ve=L.get(Pe.sha);return(0,ie.jsxs)("div",{"data-index":fe.index,ref:et?ut.measureElement:void 0,className:"absolute left-0 top-0 w-full",style:{transform:`translateY(${fe.start}px)`},children:[(0,ie.jsxs)("div",{role:"button",tabIndex:0,"data-sha":Pe.sha,onClick:()=>yt(Pe.sha,fe.index),onKeyDown:Be=>v1(Be,()=>yt(Pe.sha,fe.index)),onMouseEnter:Be=>{if(et)return;let Rt=R.current;if(!Rt)return;let he=Rt.getBoundingClientRect(),Me=Be.currentTarget.getBoundingClientRect(),xe=Me.bottom-he.top,Fe=he.bottom-Me.top;H.set({sha:Pe.sha,below:xe,above:Fe,flip:xe>he.height*.55})},onMouseLeave:()=>H.set(Be=>Be&&Be.sha===Pe.sha?null:Be),className:"group/commit relative flex min-w-0 cursor-pointer items-center text-[11px] transition-colors hover:bg-white/[0.04]",style:{height:Yr},children:[(0,ie.jsxs)("svg",{width:rt,height:Yr,className:"shrink-0",style:{display:"block"},"aria-hidden":!0,children:[ze.map((Be,Rt)=>(0,ie.jsx)("path",{d:y1(Be),fill:"none",stroke:bp(Be.colorLane),strokeWidth:1.5,strokeOpacity:Be.kind==="stub"?.3:.55,strokeDasharray:Be.kind==="stub"?"2 3":void 0,strokeLinecap:"round"},Rt)),Oe.isHead?(0,ie.jsx)("circle",{cx:We,cy:Yr/2,r:b1+2.5,fill:"none",stroke:bn,strokeWidth:1.5,strokeOpacity:.7}):null,(0,ie.jsx)("circle",{cx:We,cy:Yr/2,r:b1,fill:At==="outgoing"?"transparent":At==="merge"?"rgba(0,0,0,0.35)":nt,stroke:bn,strokeWidth:At==="filled"?1:1.5,fillOpacity:At==="filled"?.9:1})]}),(0,ie.jsxs)("div",{className:"flex min-w-0 flex-1 items-center gap-2 pr-1",children:[et?(0,ie.jsx)(qt,{className:"h-3 w-3 shrink-0 text-white/35"}):(0,ie.jsx)(Sn,{className:"h-3 w-3 shrink-0 text-white/25"}),Vt.length?(0,ie.jsx)("span",{className:"flex shrink-0 items-center gap-1",children:Vt.slice(0,3).map(Be=>{let Rt=Dv(Be);return(0,ie.jsxs)("span",{className:V("flex max-w-[120px] items-center gap-0.5 rounded px-1 py-0.5 text-[9px] font-medium leading-none",Rt==="tag"?"bg-amber-400/15 text-amber-100/80":Rt==="remote"?"border border-white/20 bg-transparent text-white/55":"bg-violet-400/20 text-violet-100/90"),children:[Rt==="remote"?(0,ie.jsx)(El,{className:"h-2 w-2 shrink-0","aria-hidden":!0}):null,(0,ie.jsx)("span",{className:"truncate",children:hM(Be)})]},Be)})}):null,(0,ie.jsx)("span",{className:"min-w-0 flex-1 truncate text-white/82",children:Pe.subject||"(no message)"}),(0,ie.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/35 transition-opacity group-hover/commit:opacity-0",children:gn(Pe.sha)}),(0,ie.jsx)("span",{className:"hidden shrink-0 max-w-[120px] truncate text-[10px] text-white/40 transition-opacity group-hover/commit:opacity-0 sm:inline",children:Pe.author}),s&&Le[Pe.sha]?(0,ie.jsx)(Ha,{...Le[Pe.sha],compact:!0,className:"transition-opacity group-hover/commit:opacity-0"}):null,(0,ie.jsx)("button",{type:"button",onClick:Be=>{Be.stopPropagation(),me(Pe)},className:"absolute right-1 top-1/2 inline-flex h-5 w-5 -translate-y-1/2 items-center justify-center rounded bg-white/10 text-white/50 opacity-0 transition group-hover/commit:opacity-100 focus-visible:opacity-100 hover:bg-white/20 hover:text-white/85",title:"Open Changes (all files in this commit)","aria-label":`Open changes of commit ${gn(Pe.sha)}`,children:(0,ie.jsx)(bo,{className:"h-3 w-3"})})]})]}),et?(0,ie.jsxs)("div",{className:"pb-1.5 pl-1 pr-2 pt-0.5",children:[(0,ie.jsxs)("div",{className:"flex items-center gap-2 px-2 text-[10px] text-white/40",children:[(0,ie.jsx)("span",{className:"font-mono",children:gn(Pe.sha)}),(0,ie.jsx)("span",{className:"min-w-0 truncate",children:Pe.author}),(0,ie.jsx)("span",{title:Pe.date,children:_h(Pe.date)})]}),(0,ie.jsx)("div",{className:"mt-1 border-t border-white/[0.05] pt-1",children:(0,ie.jsx)(w1,{entry:Ve??{status:"loading"},emptyText:"This commit changed no files.",unavailableText:"Commit details unavailable \u2014 the commit may no longer exist.",onFileClick:Be=>Et(Pe.sha,Be),showCounts:s})})]}):null]},fe.key)})}),l.hasMore?(0,ie.jsxs)("div",{ref:ae,className:"flex items-center justify-center gap-1.5 px-3 py-2 text-[11px] text-white/40",children:[(0,ie.jsx)($e,{className:V("h-3 w-3",c&&"animate-spin")}),"Loading more commits\u2026"]}):null]})}),(0,ie.jsx)(fM,{store:H,commits:De,expandedShas:b})]})}var An=W(Je(),1);function yu(t){return Number.isFinite(t)?Math.min(20,Math.max(.05,t)):1}function I1(t){return t>0&&t<1?1/t:1}function L1(t){if(!t)return{};try{let e=JSON.parse(t);if(!e||typeof e!="object"||Array.isArray(e))return{};let n={};for(let[r,a]of Object.entries(e)){if(!a||typeof a!="object"||Array.isArray(a))continue;let s=a;typeof s.collapsed!="boolean"||typeof s.weight!="number"||(n[r]={collapsed:s.collapsed,weight:yu(s.weight)})}return n}catch{return{}}}function A1(t){return JSON.stringify(t)}function vu(t,e,n,r=1){return t[e]??{collapsed:n,weight:yu(r)}}function P1(t,e,n,r,a=1){let s=vu(t,e,r,a),i=!n&&s.weight<.15?yu(a):s.weight;return{...t,[e]:{collapsed:n,weight:i}}}function R1(t){let e=t.minBodyPx??72,n=t.heightAbove+t.heightBelow,r=t.weightAbove+t.weightBelow;if(!(n>0)||!(r>0)||n<e*2)return{above:t.weightAbove,below:t.weightBelow};let a=Math.min(n-e,Math.max(e,t.heightAbove+t.deltaY)),s=yu(r*(a/n)),i=yu(r-s);return{above:s,below:i}}var Jr=W(ue(),1),mM=4;function gM(t){if(typeof window>"u")return{};try{return L1(window.localStorage.getItem(t))}catch{return{}}}function N1({sections:t,storageKey:e}){let[n,r]=(0,An.useState)(()=>gM(e)),[a,s]=(0,An.useState)(!1),i=(0,An.useRef)(n);i.current=n;let o=(0,An.useRef)(new Map),l=(0,An.useRef)(null),u=(0,An.useRef)(!1),c=(0,An.useCallback)(v=>{if(typeof window<"u")try{window.localStorage.setItem(e,A1(v))}catch{}},[e]),d=(0,An.useCallback)((v,k,O)=>{r(R=>{let P=vu(R,v,k,O),H=P1(R,v,!P.collapsed,k,O);return c(H),H})},[c]),f=(0,An.useCallback)((v,k,O,R,P,H,w)=>{let N=o.current.get(k),j=o.current.get(O);H&&v.preventDefault(),l.current={aboveId:k,belowId:O,startY:v.clientY,weightAbove:R,weightBelow:P,heightAbove:N?.getBoundingClientRect().height??0,heightBelow:j?.getBoundingClientRect().height??0,engaged:H,belowCollapsed:w,expanded:!1,rebaselined:!1},u.current=!1,s(H),v.currentTarget.setPointerCapture(v.pointerId)},[]),h=(0,An.useCallback)((v,k,O,R,P,H)=>{f(v,k,O,R,P,!0,H)},[f]),p=(0,An.useCallback)((v,k,O,R,P,H)=>{v.button===0&&f(v,k,O,R,P,!1,H)},[f]),g=(0,An.useCallback)(()=>{l.current&&(l.current=null,s(!1),c(i.current))},[c]);(0,An.useEffect)(()=>{if(a)return window.addEventListener("pointerup",g),window.addEventListener("pointercancel",g),()=>{window.removeEventListener("pointerup",g),window.removeEventListener("pointercancel",g)}},[a,g]);let m=(0,An.useCallback)(v=>{let k=l.current;if(!k)return;if((v.buttons&1)===0){g();return}let O=v.clientY-k.startY;if(!k.engaged){if(Math.abs(O)<mM)return;k.engaged=!0,u.current=!0,s(!0)}if(k.belowCollapsed&&!k.expanded){k.expanded=!0,r(H=>({...H,[k.belowId]:{collapsed:!1,weight:k.weightBelow}}));return}if(k.belowCollapsed&&!k.rebaselined){let H=o.current.get(k.belowId);if(!H)return;let w=o.current.get(k.aboveId);k.heightAbove=w?.getBoundingClientRect().height??k.heightAbove,k.heightBelow=H.getBoundingClientRect().height,k.startY=v.clientY,k.weightAbove=i.current[k.aboveId]?.weight??k.weightAbove,k.weightBelow=i.current[k.belowId]?.weight??k.weightBelow,k.rebaselined=!0;return}let{above:R,below:P}=R1({weightAbove:k.weightAbove,weightBelow:k.weightBelow,heightAbove:k.heightAbove,heightBelow:k.heightBelow,deltaY:O});r(H=>({...H,[k.aboveId]:{...H[k.aboveId]??{collapsed:!1,weight:1},weight:R},[k.belowId]:{...H[k.belowId]??{collapsed:!1,weight:1},weight:P}}))},[g]),x=(0,An.useCallback)(v=>{v.currentTarget.hasPointerCapture(v.pointerId)&&v.currentTarget.releasePointerCapture(v.pointerId),g()},[g]),b=(0,An.useCallback)((v,k,O,R)=>{let P=l.current?.engaged??!1,H=l.current!=null;v.currentTarget.hasPointerCapture(v.pointerId)&&v.currentTarget.releasePointerCapture(v.pointerId),g(),H&&!P&&d(k,O,R)},[g,d]),y=t.reduce((v,k)=>{let O=vu(n,k.id,k.defaultCollapsed??!1,k.defaultWeight??1);return O.collapsed?v:v+O.weight},0),C=I1(y),I=[],L=null;for(let v of t){let k=v.defaultCollapsed??!1,O=v.defaultWeight??1,R=vu(n,v.id,k,O),P=L&&!L.collapsed?L:null,H=R.collapsed?O:R.weight;P&&I.push((0,Jr.jsx)("div",{role:"separator","aria-orientation":"horizontal",onPointerDown:w=>h(w,P.id,v.id,P.weight,H,R.collapsed),onPointerMove:m,onPointerUp:x,onPointerCancel:g,onLostPointerCapture:g,className:"relative h-1.5 shrink-0 cursor-row-resize touch-none bg-white/0 transition hover:bg-white/[0.06]",children:(0,Jr.jsx)("div",{className:"absolute inset-x-6 top-1/2 h-[2px] -translate-y-1/2 rounded-full bg-white/[0.07]"})},`h:${P.id}:${v.id}`)),I.push((0,Jr.jsxs)("div",{onPointerDown:P?w=>{w.target.closest("[data-section-actions]")||p(w,P.id,v.id,P.weight,H,R.collapsed)}:void 0,onPointerMove:P?m:void 0,onPointerUp:P?w=>b(w,v.id,k,O):void 0,onPointerCancel:P?g:void 0,onLostPointerCapture:P?g:void 0,className:V("group/section flex h-7 shrink-0 items-center gap-1.5 border-t border-white/[0.04] px-1 first:border-t-0",P&&"touch-none"),children:[(0,Jr.jsxs)("button",{type:"button",onClick:w=>{P&&w.detail!==0||d(v.id,k,O)},"aria-expanded":!R.collapsed,className:"flex h-full min-w-0 flex-1 items-center gap-1 rounded px-1 text-left transition-colors hover:bg-white/[0.04]",children:[(0,Jr.jsx)(Sn,{className:V("h-3 w-3 shrink-0 text-white/40 transition-transform",!R.collapsed&&"rotate-90")}),(0,Jr.jsx)("span",{className:"truncate text-[10px] font-bold uppercase tracking-wider text-white/40",children:v.title}),typeof v.count=="number"?(0,Jr.jsx)("span",{className:"text-[9px] tabular-nums text-white/30",children:v.count}):null,v.badge]}),v.actions?(0,Jr.jsx)("div",{"data-section-actions":!0,className:"ml-auto flex shrink-0 items-center gap-1 opacity-0 transition-opacity focus-within:opacity-100 group-hover/section:opacity-100",children:v.actions}):null]},`s:${v.id}`)),R.collapsed||I.push((0,Jr.jsx)("div",{ref:w=>{w?o.current.set(v.id,w):o.current.delete(v.id)},className:"min-h-0 overflow-auto",style:{flexGrow:R.weight*C,flexBasis:0},children:v.content},`b:${v.id}`)),L={id:v.id,collapsed:R.collapsed,weight:R.weight}}return(0,Jr.jsx)("div",{className:V("flex min-h-0 flex-1 flex-col overflow-hidden",a&&"cursor-row-resize select-none"),children:I})}var G=W(ue(),1);function wp(t,e,n){(0,ke.useEffect)(()=>{if(!t)return;let r=a=>{let s=a.target;s instanceof Node&&e.current?.contains(s)||n()};return document.addEventListener("mousedown",r,!0),()=>document.removeEventListener("mousedown",r,!0)},[t,e,n])}var xM="neuralis.filesystem.gitPanel.sections",M1="neuralis.filesystem.gitPanel.commitOpen",T1="neuralis.filesystem.gitPanel.diffCounts";function bM(t){return typeof t!="string"||!t?"":t.includes("://")?Ke(t):t}function yM(t){let e=t.lastIndexOf("/");return e<0?{name:t,dir:""}:{name:t.slice(e+1),dir:t.slice(0,e)}}function vM(t){let e={name:"",path:"",children:new Map};for(let n of t){let r=n.path.split("/").filter(Boolean),a=e,s="";for(let i=0;i<r.length;i++){let o=r[i];s=s?`${s}/${o}`:o;let l=a.children.get(o);l||(l={name:o,path:s,children:new Map},a.children.set(o,l)),a=l,i===r.length-1&&(a.change=n)}}return e}function _1(t,e){let n=[],r=[...t.children.values()].sort((a,s)=>{let i=a.children.size>0,o=s.children.size>0;return i!==o?i?-1:1:a.name.localeCompare(s.name)});for(let a of r)n.push({node:a,depth:e}),a.children.size>0&&n.push(..._1(a,e+1));return n}var D1=Object.freeze({}),F1=ke.default.memo(function({change:e,onClick:n,actions:r,busy:a,showCounts:s}){let{name:i,dir:o}=yM(e.path),l=Lo(e.path),u=d=>d.stopPropagation(),c=!!(r.onDiscard||r.onUnstage||r.onStage);return(0,G.jsxs)("div",{className:"group/row relative flex w-full items-center rounded-md pr-1.5 transition-colors hover:bg-white/[0.05]",children:[(0,G.jsxs)("button",{type:"button",onClick:()=>n(e),title:e.origPath?`${e.origPath} \u2192 ${e.path}`:e.path,className:"flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden py-1 pl-2 pr-1 text-left",children:[(0,G.jsx)(l,{className:"h-4 w-4 shrink-0 text-white/55"}),(0,G.jsx)("span",{className:"shrink-0 truncate text-xs text-white/85",children:i}),o?(0,G.jsx)("span",{className:"min-w-0 flex-1 truncate text-[10px] text-white/35",children:o}):(0,G.jsx)("span",{className:"flex-1"})]}),s?(0,G.jsx)(Ha,{added:e.added,removed:e.removed,binary:e.binary,className:"mr-1 transition-opacity group-hover/row:opacity-0"}):null,(0,G.jsx)("span",{className:"flex w-3.5 shrink-0 items-center justify-center",children:(0,G.jsx)(Hc,{code:e.code})}),c?(0,G.jsxs)("div",{className:"absolute right-6 top-1/2 flex -translate-y-1/2 items-center gap-0.5 rounded bg-gradient-to-r from-transparent via-black/30 to-black/45 pl-4 opacity-0 transition-opacity group-hover/row:opacity-100 focus-within:opacity-100",children:[r.onDiscard?(0,G.jsx)("button",{type:"button",onClick:d=>{u(d),r.onDiscard(e)},disabled:a,className:"inline-flex h-5 w-5 items-center justify-center rounded text-rose-300/70 transition-colors hover:bg-rose-500/15 hover:text-rose-200 disabled:opacity-40",title:"Discard changes (destructive)","aria-label":`Discard changes to ${i}`,children:(0,G.jsx)(_t,{className:"h-3 w-3"})}):null,r.onUnstage?(0,G.jsx)("button",{type:"button",onClick:d=>{u(d),r.onUnstage(e)},disabled:a,className:"inline-flex h-5 w-5 items-center justify-center rounded text-white/50 transition-colors hover:bg-white/10 hover:text-white/80 disabled:opacity-40",title:"Unstage","aria-label":`Unstage ${i}`,children:(0,G.jsx)(bi,{className:"h-3 w-3"})}):null,r.onStage?(0,G.jsx)("button",{type:"button",onClick:d=>{u(d),r.onStage(e)},disabled:a,className:"inline-flex h-5 w-5 items-center justify-center rounded text-emerald-300/80 transition-colors hover:bg-emerald-500/15 hover:text-emerald-200 disabled:opacity-40",title:"Stage","aria-label":`Stage ${i}`,children:(0,G.jsx)($n,{className:"h-3 w-3"})}):null]}):null]})});function E1({changes:t,viewMode:e,staged:n,onRowClick:r,actionsFor:a,busy:s,showCounts:i}){let o=(0,ke.useMemo)(()=>e==="tree"?_1(vM(t),0):[],[t,e]),l=(0,ke.useCallback)(u=>r(u,n),[r,n]);return(0,G.jsx)("div",{className:"px-1 py-0.5",children:e==="list"?(0,G.jsx)("div",{className:"space-y-px",children:t.map(u=>(0,G.jsx)(F1,{change:u,onClick:l,actions:a(u),busy:s,showCounts:i},`${u.code}:${u.path}`))}):(0,G.jsx)("div",{className:"space-y-px",children:o.map(({node:u,depth:c})=>u.change?(0,G.jsx)("div",{style:{paddingLeft:`${c*12}px`},children:(0,G.jsx)(F1,{change:u.change,onClick:l,actions:a(u.change),busy:s,showCounts:i})},`f:${u.path}`):(0,G.jsxs)("div",{style:{paddingLeft:`${c*12}px`},className:"flex items-center gap-1.5 px-2 py-1 text-[11px] text-white/45",children:[(0,G.jsx)($r,{className:"h-3.5 w-3.5 shrink-0 text-white/35"}),(0,G.jsx)("span",{className:"truncate",children:u.name})]},`d:${u.path}`))})})}function kp({tone:t,onClick:e,disabled:n,title:r,children:a}){return(0,G.jsx)("button",{type:"button",onClick:e,disabled:n,className:V("rounded px-1 py-0.5 text-[9px] transition-colors disabled:opacity-40",t==="discard"?"text-rose-300/70 hover:bg-rose-500/15 hover:text-rose-200":t==="unstage"?"text-white/55 hover:bg-white/10 hover:text-white/85":"text-emerald-300/80 hover:bg-emerald-500/15 hover:text-emerald-200"),title:r,children:a})}function H1({agentId:t}){let e=B(D=>D.client),n=B(D=>D.sources),r=B(D=>D.activeProjectId),a=B(D=>D.activeSource),s=B(D=>D.activeRepoRel),i=B(D=>D.setActiveSource),o=B(D=>D.gitStatus),l=B(D=>D.gitTotals),u=B(D=>D.gitOutgoingStat),c=B(D=>D.setGitOutgoingStat),d=B(D=>D.gitLoading),f=B(D=>D.gitError),h=B(D=>D.gitViewMode),p=B(D=>D.setGitViewMode),g=B(D=>D.gitBranches),m=B(D=>D.loadGitStatus),x=B(D=>D.loadGitBranches),b=B(D=>D.setGitDiffTarget),y=B(D=>D.setActiveWorkspaceTab),C=B(D=>D.gitLogNonce),[I,L]=(0,ke.useState)(!1),[v,k]=(0,ke.useState)(!1),O=(0,ke.useRef)(null),R=(0,ke.useRef)(null),[P,H]=(0,ke.useState)(!1),[w,N]=(0,ke.useState)(!1),[j,K]=(0,ke.useState)(null),[A,F]=(0,ke.useState)(""),[_,X]=(0,ke.useState)(!1),[re,ae]=(0,ke.useState)(()=>Hh(M1,!1)),[Le,ye]=(0,ke.useState)(()=>Hh(T1,!0)),q=(0,ke.useCallback)(()=>{ye(D=>{let we=!D;return Uh(T1,we),we})},[]),[Q,te]=(0,ke.useState)(null),[ge,de]=(0,ke.useState)(null),[De,Xe]=(0,ke.useState)(!1),Qe=(0,ke.useCallback)(()=>L(!1),[]),rt=(0,ke.useCallback)(()=>{k(!1),Xe(!1)},[]),at=(0,ke.useCallback)(()=>H(!1),[]);wp(I,O,Qe),wp(v,R,rt),wp(P,R,at);let[Ft,Ue]=(0,ke.useState)(""),[ut,st]=(0,ke.useState)(""),yt=(0,ke.useMemo)(()=>n.filter(D=>D.git?.isRepo||D.git?.containsRepos),[n]),vt=(0,ke.useMemo)(()=>yt.map(D=>D.uri_root).join("|"),[yt]),Ut=(0,ke.useMemo)(()=>bM(a),[a]),Et=(0,ke.useMemo)(()=>yt.find(D=>Ke(D.uri_root)===Ut)??yt[0]??null,[yt,Ut]),me=Et?Ke(Et.uri_root):"",Ye=yt.length>1||yt.some(D=>!D.git?.isRepo&&D.git?.containsRepos),cn=(0,ke.useRef)(new Map),[fe,Re]=(0,ke.useState)(()=>new Map),Oe=(0,ke.useCallback)(async(D,we)=>{if(!t||!D)return[];let $t=cn.current.get(D);if($t&&($t instanceof Promise||!we?.force))return $t;let Gt=(async()=>{try{let In=await lo({agentId:t,...r?{projectId:r}:{},source:D},e),Zt=Array.isArray(In?.repos)?In.repos:[];return cn.current.set(D,Zt),Re(Ls=>new Map(Ls).set(D,Zt)),Zt}catch{return cn.current.delete(D),Re(In=>In.has(D)?In:new Map(In).set(D,[])),[]}})();return cn.current.set(D,Gt),Gt},[t,r]),Pe=(0,ke.useMemo)(()=>s?fe.get(me)?.find(D=>D.rel===s)??null:null,[s,fe,me]),ze=s?Pe?.canWrite===!0:Et?.git?.canWrite===!0,We=s?Pe?.canExec===!0:Et?.git?.canExec===!0,nt=o?.staged.length??0,Vt=Ks(me,s?Pe?.name??s:Et?.git?.repoName),et=(0,ke.useMemo)(()=>Ov(o),[o]);(0,ke.useEffect)(()=>{me&&me!==Ut&&i(me)},[t,r,me,vt]),(0,ke.useEffect)(()=>{let D=Et?.git;if(!me||!D||D.isRepo||!D.containsRepos)return;let we=!1;return Oe(me).then($t=>{we||s||$t.length===0||i(me,$t[0].rel)}),()=>{we=!0}},[me,Et,s,Oe,i]);let At=(0,ke.useRef)(C);(0,ke.useEffect)(()=>{if(C===At.current)return;At.current=C;let D=Et?.git;!me||!D||D.isRepo||!D.containsRepos||Oe(me,{force:!0})},[C,me,Et,Oe]),(0,ke.useEffect)(()=>{me&&m({agentId:t,projectId:r??null,source:me,repo:s})},[t,r,me,s,vt]),(0,ke.useEffect)(()=>{if(!ge)return;let D=setTimeout(()=>de(null),9e3);return()=>clearTimeout(D)},[ge]);let bn=(0,ke.useCallback)((D,we)=>{L(!1),i(D,we)},[i]),Ve=(0,ke.useCallback)(()=>{k(!1),Xe(!1),H(!1),L(D=>{let we=!D;if(we)for(let $t of yt){let Gt=$t.git;Gt&&!Gt.isRepo&&Gt.containsRepos&&Oe(Ke($t.uri_root),{force:!0})}return we})},[yt,Oe]),Be=(0,ke.useCallback)(()=>{ae(D=>{let we=!D;return Uh(M1,we),we})},[]),he=(0,ke.useCallback)(()=>{me&&m({agentId:t,projectId:r??null,source:me,repo:s})},[t,r,me,s,m]),Me=(0,ke.useCallback)((D,we)=>{me&&(b({source:me,...s?{repo:s}:{},path:D.path,staged:we}),y("git-diff"))},[me,s,b,y]),xe=(0,ke.useCallback)(async D=>{if(me){N(!0),K(null);try{let we=await D();return m({agentId:t,projectId:r??null,source:me,repo:s}),we}catch(we){K(we instanceof Error?we.message:"Git operation failed");return}finally{N(!1)}}},[me,s,t,r,m]),Fe=(0,ke.useMemo)(()=>({...r?{projectId:r}:{},...s?{repo:s}:{}}),[r,s]),ve=(0,ke.useCallback)(D=>{D.length!==0&&xe(()=>q0({agentId:t,...Fe,source:me,paths:D},e))},[xe,t,Fe,me]),Nt=(0,ke.useCallback)(D=>{D.length!==0&&xe(()=>V0({agentId:t,...Fe,source:me,paths:D},e))},[xe,t,Fe,me]),pt=(0,ke.useCallback)(D=>{(async()=>{let we=await xe(()=>X0({agentId:t,...Fe,source:me,paths:D},e));we&&we.rescue&&de({message:`Discarded ${D.length} file${D.length===1?"":"s"} \u2014 recoverable`,rescue:we.rescue})})()},[xe,t,Fe,me]),kn=(0,ke.useCallback)(D=>{D.length!==0&&te({title:"Discard changes",message:`Overwrite the working-tree version of ${D.length} file${D.length===1?"":"s"} with the last committed/indexed content? A rescue snapshot is saved server-side so it can be recovered.`,confirmLabel:"Discard",onConfirm:()=>{te(null),pt(D)}})},[pt]),yn=(0,ke.useCallback)(D=>ve([D.path]),[ve]),Nn=(0,ke.useCallback)(D=>Nt([D.path]),[Nt]),dn=(0,ke.useCallback)(D=>kn([D.path]),[kn]),cr=(0,ke.useMemo)(()=>({onStage:yn}),[yn]),yr=(0,ke.useMemo)(()=>({onStage:yn,onDiscard:dn}),[yn,dn]),dr=(0,ke.useMemo)(()=>({onUnstage:Nn}),[Nn]),Ot=(0,ke.useCallback)(D=>ze?D.code==="??"?cr:yr:D1,[ze,cr,yr]),Dr=(0,ke.useCallback)(()=>ze?dr:D1,[ze,dr]),fr=(0,ke.useCallback)(()=>{let D=A.trim();D&&(async()=>{let we=await xe(()=>Y0({agentId:t,...Fe,source:me,message:D,amend:_},e));we&&we.ok&&(F(""),X(!1))})()},[A,_,xe,t,Fe,me]),jn=(0,ke.useCallback)(()=>{L(!1),H(!1),k(D=>{let we=!D;return we&&me&&x({agentId:t,projectId:r??null,source:me,repo:s}),we}),Xe(!1)},[me,s,t,r,x]),oa=(0,ke.useCallback)(D=>{k(!1),(async()=>await xe(()=>ch({agentId:t,...Fe,source:me,ref:D},e))&&x({agentId:t,projectId:r??null,source:me,repo:s}))()},[xe,t,Fe,me,s,x,r]),Qn=(0,ke.useCallback)(()=>{let D=Ft.trim();if(!D)return;let we=ut.trim();k(!1),Xe(!1),Ue(""),st(""),(async()=>await xe(()=>J0({agentId:t,...Fe,source:me,name:D,...we?{startPoint:we}:{}},e))&&(await xe(()=>ch({agentId:t,...Fe,source:me,ref:D},e)),x({agentId:t,projectId:r??null,source:me,repo:s})))()},[Ft,ut,xe,t,Fe,me,s,x,r]),Mn=(0,ke.useCallback)(D=>{(async()=>{let we=await xe(()=>Z0({agentId:t,...Fe,source:me,name:D},e));we&&we.rescue&&de({message:`Deleted branch "${D}" \u2014 recoverable`,rescue:we.rescue}),x({agentId:t,projectId:r??null,source:me,repo:s})})()},[xe,t,Fe,me,s,x,r]),Tn=(0,ke.useCallback)(D=>{k(!1),te({title:"Delete branch",message:`Delete the local branch "${D.name}"? A rescue ref is saved so it can be recreated (git will refuse if it has unmerged commits).`,confirmLabel:"Delete branch",onConfirm:()=>{te(null),Mn(D.name)}})},[Mn]),vr=(0,ke.useCallback)(()=>{if(!ge)return;let D=ge.rescue;de(null),xe(()=>Q0({agentId:t,...Fe,source:me,rescue:D},e))},[ge,xe,t,Fe,me]),qn=(0,ke.useCallback)(()=>{H(!1),xe(()=>ex({agentId:t,...Fe,source:me},e))},[xe,t,Fe,me]),la=(0,ke.useCallback)(()=>{H(!1),xe(()=>tx({agentId:t,...Fe,source:me},e))},[xe,t,Fe,me]),er=(0,ke.useCallback)(()=>{H(!1),xe(()=>nx({agentId:t,...Fe,source:me},e))},[xe,t,Fe,me]),hr=o?.unstaged??[],fn=o?.staged??[],wr=o?.untracked??[],E=(0,ke.useMemo)(()=>[...hr,...wr].sort((D,we)=>D.path.localeCompare(we.path)),[hr,wr]);if(yt.length===0)return(0,G.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 px-4 py-10 text-center",children:[(0,G.jsx)(Bn,{className:"h-5 w-5 text-white/25"}),(0,G.jsx)("div",{className:"text-xs text-white/40",children:"No git repositories"}),(0,G.jsx)("div",{className:"max-w-[200px] text-[10px] text-white/30",children:"Sources whose root is \u2014 or whose folders contain \u2014 a git checkout appear here."})]});let ne=ze&&A.trim().length>0&&(nt>0||_)&&!w,se=f?(0,G.jsx)("div",{className:"px-2 py-3 text-[11px] text-rose-300/70",children:f}):d&&!o?(0,G.jsx)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:"Loading git status\u2026"}):E.length===0?(0,G.jsx)("div",{className:"px-2 py-4 text-center text-[11px] text-white/35",children:"No changes"}):(0,G.jsx)(E1,{changes:E,viewMode:h,staged:!1,showCounts:Le,onRowClick:Me,actionsFor:Ot,busy:w}),_e=[{id:"changes",title:"Changes",count:E.length,badge:l?(0,G.jsx)(Ha,{...l.changes,compact:!0,className:"ml-auto pr-1"}):void 0,actions:ze&&E.length>0?(0,G.jsxs)(G.Fragment,{children:[hr.length>0?(0,G.jsx)(kp,{tone:"discard",onClick:()=>kn(hr.map(D=>D.path)),disabled:w,title:"Discard all tracked changes in this group (destructive)",children:"Discard all"}):null,(0,G.jsx)(kp,{tone:"stage",onClick:()=>ve(E.map(D=>D.path)),disabled:w,title:"Stage all",children:"Stage all"})]}):void 0,content:se},...fn.length>0?[{id:"staged",title:"Staged Changes",count:fn.length,badge:l?(0,G.jsx)(Ha,{...l.staged,compact:!0,className:"ml-auto pr-1"}):void 0,actions:ze?(0,G.jsx)(kp,{tone:"unstage",onClick:()=>Nt(fn.map(D=>D.path)),disabled:w,title:"Unstage all",children:"Unstage all"}):void 0,content:(0,G.jsx)(E1,{changes:fn,viewMode:h,staged:!0,showCounts:Le,onRowClick:Me,actionsFor:Dr,busy:w})}]:[],{id:"graph",title:"Graph",badge:u?(0,G.jsx)(Ha,{added:u.added,removed:u.removed,unknown:u.commits-u.covered,compact:!0,className:"ml-auto pr-1"}):void 0,defaultCollapsed:!0,defaultWeight:2,content:(0,G.jsx)(C1,{showCounts:Le,onOutgoingStat:c,source:me,repo:s,agentId:t,projectId:r??null,repoName:s?Pe?.name??s:Et?.git?.repoName},`${me}\0${s}`)}];return(0,G.jsxs)("div",{className:"flex h-full min-h-0 flex-col",children:[(0,G.jsxs)("div",{ref:O,className:"relative px-2 pt-1 pb-1.5",children:[(0,G.jsxs)("div",{className:"flex items-center gap-1",children:[(0,G.jsxs)("button",{type:"button",onClick:Ve,disabled:!Ye,className:V("flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-2 py-1 text-left transition-colors","bg-white/[0.03] hover:bg-white/[0.06] disabled:hover:bg-white/[0.03]"),title:me?Vt.title:"Select a repository",children:[(0,G.jsx)(Bn,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),Vt.prefix?(0,G.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:Vt.prefix}):null,(0,G.jsx)("span",{className:"min-w-0 flex-1 truncate text-xs font-medium text-white/85",children:Vt.name||"Select repository"}),Ye?(0,G.jsx)(qt,{className:"h-3 w-3 shrink-0 text-white/40"}):null]}),(0,G.jsx)("button",{type:"button",onClick:he,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-white/40 transition-colors hover:bg-white/[0.06] hover:text-white/70",title:"Refresh git status","aria-label":"Refresh git status",children:(0,G.jsx)(Xt,{className:V("h-3.5 w-3.5",d&&"animate-spin")})}),(0,G.jsx)(B1.SkillLauncher,{variant:"icon",size:"sm",skill:"git",packageId:"@neuralis/brain-core",label:"Status, diff, commit, branch, fetch or push with the agent",icon:"GitBranch"})]}),I&&Ye?(0,G.jsx)(G.Fragment,{children:(0,G.jsx)("div",{className:"absolute left-2 right-2 z-50 mt-1 max-h-56 overflow-auto rounded-md border border-white/10 bg-[rgba(var(--w-bg-rgb),0.96)] py-1 shadow-lg",children:yt.map(D=>{let we=Ke(D.uri_root);if(D.git?.isRepo){let Gt=we===me&&!s,In=Ks(we,D.git?.repoName);return(0,G.jsxs)("button",{type:"button",onClick:()=>bn(we,""),className:V("flex w-full items-center gap-1.5 px-2 py-1.5 text-left text-xs transition-colors hover:bg-white/[0.06]",Gt?"text-white/90":"text-white/65"),children:[(0,G.jsx)(Bn,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/70"}),In.prefix?(0,G.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:In.prefix}):null,(0,G.jsx)("span",{className:"min-w-0 flex-1 truncate",children:In.name}),D.git?.branch?(0,G.jsx)("span",{className:"shrink-0 truncate text-[10px] text-white/35",children:D.git.branch}):null,Gt?(0,G.jsx)(Vn,{className:"h-3 w-3 shrink-0 text-violet-300/80"}):null]},D.uri_root)}let $t=fe.get(we);return $t?$t.length===0?(0,G.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5 text-[11px] text-white/35",children:[(0,G.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:`${we}://`}),(0,G.jsx)("span",{className:"truncate",children:"No repositories found."})]},D.uri_root):$t.map(Gt=>{let In=we===me&&s===Gt.rel,Zt=Ks(we,Gt.name||Gt.rel);return(0,G.jsxs)("button",{type:"button",onClick:()=>bn(we,Gt.rel),className:V("flex w-full items-center gap-1.5 px-2 py-1.5 text-left text-xs transition-colors hover:bg-white/[0.06]",In?"text-white/90":"text-white/65"),children:[(0,G.jsx)(Bn,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/70"}),Zt.prefix?(0,G.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:Zt.prefix}):null,(0,G.jsx)("span",{className:"min-w-0 flex-1 truncate",children:Zt.name}),Gt.branch?(0,G.jsx)("span",{className:"shrink-0 truncate text-[10px] text-white/35",children:Gt.branch}):null,In?(0,G.jsx)(Vn,{className:"h-3 w-3 shrink-0 text-violet-300/80"}):null]},`${D.uri_root}\0${Gt.rel}`)}):(0,G.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5 text-[11px] text-white/35",children:[(0,G.jsx)($e,{className:"h-3 w-3 shrink-0 animate-spin"}),(0,G.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:`${we}://`}),(0,G.jsx)("span",{className:"truncate",children:"Scanning repositories\u2026"})]},D.uri_root)})})}):null]}),(0,G.jsxs)("div",{ref:R,className:"relative flex items-center justify-between gap-2 px-2 pb-1.5",children:[(0,G.jsxs)("div",{className:"flex min-w-0 items-center gap-1",children:[(0,G.jsxs)("button",{type:"button",onClick:jn,className:"flex min-w-0 items-center gap-1.5 rounded-md px-1.5 py-0.5 text-[11px] text-white/55 transition-colors hover:bg-white/[0.05] hover:text-white/80",title:"Switch or create branch","aria-haspopup":"menu","aria-expanded":v,children:[(0,G.jsx)(Bn,{className:"h-3 w-3 shrink-0 text-white/40"}),(0,G.jsx)("span",{className:"truncate",children:o?.branch??"\u2014"}),(0,G.jsx)(qt,{className:"h-3 w-3 shrink-0 text-white/30"})]}),ze?(0,G.jsx)("button",{type:"button",onClick:()=>{L(!1),k(!1),Xe(!1),H(D=>!D)},className:"flex shrink-0 items-center gap-1.5 rounded bg-white/[0.05] px-1.5 py-0.5 text-[10px] leading-none tabular-nums text-white/60 transition-colors hover:bg-white/[0.08] hover:text-white/85",title:"Fetch / pull / push","aria-haspopup":"menu","aria-expanded":P,children:et?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${et.ahead} commits ahead of ${et.upstream}`,children:[(0,G.jsx)("span",{className:"text-blue-300/60",children:"\u2191"}),(0,G.jsx)("span",{className:"text-blue-200/90",children:et.ahead})]}),(0,G.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${et.behind} commits behind ${et.upstream}`,children:[(0,G.jsx)("span",{className:"text-white/40",children:"\u2193"}),(0,G.jsx)("span",{className:"text-white/70",children:et.behind})]})]}):(0,G.jsx)(Nl,{className:"h-3 w-3 text-white/40"})}):et?(0,G.jsxs)("span",{className:"flex shrink-0 cursor-default items-center gap-1.5 rounded bg-white/[0.05] px-1 py-0.5 text-[10px] leading-none tabular-nums",title:`${et.upstream}: ahead/behind vs the tracked upstream (local refs)`,children:[(0,G.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${et.ahead} commits ahead of ${et.upstream}`,children:[(0,G.jsx)("span",{className:"text-blue-300/60",children:"\u2191"}),(0,G.jsx)("span",{className:"text-blue-200/90",children:et.ahead})]}),(0,G.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${et.behind} commits behind ${et.upstream}`,children:[(0,G.jsx)("span",{className:"text-white/40",children:"\u2193"}),(0,G.jsx)("span",{className:"text-white/70",children:et.behind})]})]}):null,ze?(0,G.jsxs)("button",{type:"button",onClick:Be,className:"flex shrink-0 items-center gap-1 rounded-md px-1.5 py-0.5 text-[11px] text-white/55 transition-colors hover:bg-white/[0.05] hover:text-white/80",title:re?"Hide the commit box":"Show the commit box","aria-expanded":re,children:[(0,G.jsx)("span",{children:"Commit"}),nt>0?(0,G.jsx)("span",{className:"rounded bg-white/[0.08] px-1 py-0.5 text-[9px] leading-none tabular-nums text-white/70",children:nt}):null,re?(0,G.jsx)(ss,{className:"h-3 w-3 shrink-0 text-white/30"}):(0,G.jsx)(qt,{className:"h-3 w-3 shrink-0 text-white/30"})]}):null]}),(0,G.jsxs)("div",{className:"flex shrink-0 items-center gap-0.5 rounded-md bg-white/[0.03] p-0.5",children:[(0,G.jsx)("button",{type:"button",onClick:()=>p("list"),className:V("inline-flex h-5 w-5 items-center justify-center rounded transition-colors",h==="list"?"bg-white/10 text-white/85":"text-white/40 hover:text-white/70"),title:"Flat list","aria-label":"Flat list view","aria-pressed":h==="list",children:(0,G.jsx)(gi,{className:"h-3 w-3"})}),(0,G.jsx)("button",{type:"button",onClick:()=>p("tree"),className:V("inline-flex h-5 w-5 items-center justify-center rounded transition-colors",h==="tree"?"bg-white/10 text-white/85":"text-white/40 hover:text-white/70"),title:"Folder tree","aria-label":"Folder tree view","aria-pressed":h==="tree",children:(0,G.jsx)(Gl,{className:"h-3 w-3"})})]}),(0,G.jsx)("button",{type:"button",onClick:q,className:V("inline-flex h-5 w-5 shrink-0 items-center justify-center rounded transition-colors",Le?"text-white/85":"text-white/35 hover:text-white/60"),title:Le?"Hide per-row diff counts":"Show per-row diff counts","aria-label":"Toggle per-row diff counts","aria-pressed":Le,children:(0,G.jsx)(Ql,{className:"h-3 w-3"})}),v?(0,G.jsx)(G.Fragment,{children:(0,G.jsxs)("div",{className:"absolute left-2 right-2 top-full z-50 mt-1 max-h-72 overflow-auto rounded-md border border-white/10 bg-[rgba(var(--w-bg-rgb),0.97)] py-1 shadow-lg",children:[(0,G.jsx)("div",{className:"px-2 py-1 text-[9px] font-bold uppercase tracking-wider text-white/35",children:"Branches"}),g.length===0?(0,G.jsx)("div",{className:"px-2 py-1.5 text-[11px] text-white/35",children:"No branches loaded."}):g.map(D=>(0,G.jsxs)("div",{className:"group flex items-center gap-1.5 pr-1",children:[(0,G.jsxs)("button",{type:"button",onClick:()=>!D.current&&oa(D.name),disabled:D.current||w,className:V("flex min-w-0 flex-1 items-center gap-1.5 px-2 py-1.5 text-left text-xs transition-colors",D.current?"text-violet-200/90":"text-white/70 hover:bg-white/[0.06]"),title:D.current?`${D.name} (current)`:`Switch to ${D.name}`,children:[(0,G.jsx)(Bn,{className:"h-3.5 w-3.5 shrink-0 text-white/40"}),(0,G.jsx)("span",{className:"min-w-0 flex-1 truncate",children:D.name}),D.current?(0,G.jsx)(Vn,{className:"h-3 w-3 shrink-0 text-violet-300/80"}):null]}),ze&&!D.current?(0,G.jsx)("button",{type:"button",onClick:()=>Tn(D),disabled:w,className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-rose-300/60 opacity-0 transition group-hover:opacity-100 hover:bg-rose-500/15 hover:text-rose-200 disabled:opacity-40",title:`Delete branch ${D.name}`,"aria-label":`Delete branch ${D.name}`,children:(0,G.jsx)(_t,{className:"h-3 w-3"})}):null]},D.name)),ze?(0,G.jsx)("div",{className:"mt-1 border-t border-white/[0.06] pt-1",children:De?(0,G.jsxs)("div",{className:"px-2 py-1.5",children:[(0,G.jsx)("input",{value:Ft,onChange:D=>Ue(D.target.value),onKeyDown:D=>{D.key==="Enter"&&Qn()},placeholder:"new-branch-name",autoFocus:!0,className:"mb-1 h-6 w-full rounded border border-white/[0.12] bg-white/[0.04] px-1.5 text-[11px] text-white/85 outline-none placeholder:text-white/25 focus:border-white/25"}),(0,G.jsx)("input",{value:ut,onChange:D=>st(D.target.value),onKeyDown:D=>{D.key==="Enter"&&Qn()},placeholder:"from (optional ref \u2014 default HEAD)",className:"mb-1.5 h-6 w-full rounded border border-white/[0.12] bg-white/[0.04] px-1.5 text-[11px] text-white/85 outline-none placeholder:text-white/25 focus:border-white/25"}),(0,G.jsxs)("div",{className:"flex items-center gap-1",children:[(0,G.jsxs)("button",{type:"button",onClick:Qn,disabled:w||Ft.trim().length===0,className:"inline-flex items-center gap-1 rounded bg-violet-500/20 px-2 py-1 text-[10px] text-violet-100/90 transition-colors hover:bg-violet-500/30 disabled:opacity-40",children:[(0,G.jsx)($n,{className:"h-3 w-3"})," Create & switch"]}),(0,G.jsx)("button",{type:"button",onClick:()=>{Xe(!1),Ue(""),st("")},className:"rounded px-2 py-1 text-[10px] text-white/50 transition-colors hover:bg-white/[0.06] hover:text-white/80",children:"Cancel"})]})]}):(0,G.jsxs)("button",{type:"button",onClick:()=>Xe(!0),className:"flex w-full items-center gap-1.5 px-2 py-1.5 text-left text-xs text-white/70 transition-colors hover:bg-white/[0.06]",children:[(0,G.jsx)($n,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/70"}),(0,G.jsx)("span",{children:"Create new branch\u2026"})]})}):null]})}):null,P?(0,G.jsx)(G.Fragment,{children:(0,G.jsxs)("div",{className:"absolute right-2 top-full z-50 mt-1 w-52 max-w-[calc(100%-1rem)] overflow-auto rounded-md border border-white/10 bg-[rgba(var(--w-bg-rgb),0.97)] py-1 shadow-lg",children:[(0,G.jsx)("div",{className:"px-2 py-1 text-[9px] font-bold uppercase tracking-wider text-white/35",children:"Remote"}),We?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)("button",{type:"button",onClick:la,disabled:w,className:"flex w-full items-center gap-2 px-2 py-1.5 text-left text-xs text-white/75 transition-colors hover:bg-white/[0.06] disabled:opacity-40",title:"Fetch + fast-forward merge (git pull, ff-only)",children:[(0,G.jsx)(Rl,{className:"h-3.5 w-3.5 shrink-0 text-white/45"}),(0,G.jsx)("span",{className:"min-w-0 flex-1",children:"Pull"}),et&&et.behind>0?(0,G.jsxs)("span",{className:"shrink-0 tabular-nums text-[10px] text-white/50",children:["\u2193",et.behind]}):null]}),(0,G.jsxs)("button",{type:"button",onClick:er,disabled:w,className:"flex w-full items-center gap-2 px-2 py-1.5 text-left text-xs text-white/75 transition-colors hover:bg-white/[0.06] disabled:opacity-40",title:"Push the current branch (git push origin HEAD)",children:[(0,G.jsx)(Ml,{className:"h-3.5 w-3.5 shrink-0 text-blue-300/60"}),(0,G.jsx)("span",{className:"min-w-0 flex-1",children:"Push"}),et&&et.ahead>0?(0,G.jsxs)("span",{className:"shrink-0 tabular-nums text-[10px] text-blue-200/80",children:["\u2191",et.ahead]}):null]}),(0,G.jsxs)("button",{type:"button",onClick:qn,disabled:w,className:"flex w-full items-center gap-2 px-2 py-1.5 text-left text-xs text-white/75 transition-colors hover:bg-white/[0.06] disabled:opacity-40",title:"Fetch remote refs (git fetch origin)",children:[(0,G.jsx)(Xt,{className:"h-3.5 w-3.5 shrink-0 text-white/45"}),(0,G.jsx)("span",{className:"min-w-0 flex-1",children:"Fetch"})]})]}):(0,G.jsxs)("div",{className:"flex items-start gap-1.5 px-2 py-2",children:[(0,G.jsx)(xi,{className:"mt-0.5 h-3 w-3 shrink-0 text-amber-300/70"}),(0,G.jsxs)("div",{className:"min-w-0 text-[11px] leading-snug text-white/55",children:["Remote git operations need ",(0,G.jsx)("span",{className:"font-medium text-white/75",children:"exec"})," permission on this source. Ask an owner to grant it."]})]})]})}):null]}),ge?(0,G.jsxs)("div",{className:"mx-2 mb-1 flex items-start gap-1.5 rounded-md border border-amber-500/20 bg-amber-500/[0.07] px-2 py-1.5",children:[(0,G.jsx)(gt,{className:"mt-0.5 h-3 w-3 shrink-0 text-amber-300/80"}),(0,G.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,G.jsx)("div",{className:"text-[11px] text-amber-100/85",children:ge.message}),(0,G.jsxs)("div",{className:"truncate font-mono text-[9px] text-amber-100/45",title:ge.rescue.ref,children:["rescue: ",ge.rescue.ref]})]}),(0,G.jsx)("button",{type:"button",onClick:vr,disabled:w,className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-semibold text-amber-100 transition-colors hover:bg-amber-500/20 disabled:opacity-40",children:"Undo"}),(0,G.jsx)("button",{type:"button",onClick:()=>de(null),className:"shrink-0 rounded p-0.5 text-amber-200/60 transition-colors hover:bg-amber-500/15 hover:text-amber-100","aria-label":"Dismiss recovery notice",children:(0,G.jsx)(Yt,{className:"h-3 w-3"})})]}):null,j?(0,G.jsxs)("div",{className:"mx-2 mb-1 flex items-start gap-1.5 rounded-md border border-rose-500/20 bg-rose-500/[0.06] px-2 py-1.5",children:[(0,G.jsx)(gt,{className:"mt-0.5 h-3 w-3 shrink-0 text-rose-300/80"}),(0,G.jsx)("div",{className:"min-w-0 flex-1 text-[11px] text-rose-200/85",children:j}),(0,G.jsx)("button",{type:"button",onClick:()=>K(null),className:"shrink-0 rounded p-0.5 text-rose-200/60 transition-colors hover:bg-rose-500/15 hover:text-rose-100","aria-label":"Dismiss error",children:(0,G.jsx)(Yt,{className:"h-3 w-3"})})]}):null,ze&&re?(0,G.jsxs)("div",{className:"mx-2 mb-1.5 rounded-md border border-white/[0.07] bg-white/[0.02] p-1",children:[(0,G.jsx)("textarea",{value:A,onChange:D=>F(D.target.value),onKeyDown:D=>{D.key==="Enter"&&(D.metaKey||D.ctrlKey)&&!D.nativeEvent.isComposing&&ne&&(D.preventDefault(),fr())},placeholder:nt>0?`Commit message (${nt} staged)`:"Commit message",rows:2,className:"w-full resize-none rounded bg-transparent px-1 text-[11px] text-white/85 outline-none placeholder:text-white/30"}),(0,G.jsxs)("div",{className:"mt-0.5 flex items-center justify-end gap-2",children:[(0,G.jsxs)("label",{className:"flex cursor-pointer select-none items-center gap-1 text-[10px] text-white/50",children:[(0,G.jsx)("input",{type:"checkbox",checked:_,onChange:D=>X(D.target.checked),className:"h-3 w-3 accent-violet-400"}),"Amend"]}),(0,G.jsxs)("button",{type:"button",onClick:fr,disabled:!ne,className:"inline-flex items-center gap-1 rounded-md bg-violet-500/20 px-2.5 py-1 text-[11px] font-medium text-violet-100/90 transition-colors hover:bg-violet-500/30 disabled:opacity-40",title:_?"Amend the last commit":"Commit the staged changes",children:[w?(0,G.jsx)($e,{className:"h-3 w-3 animate-spin"}):(0,G.jsx)(Vn,{className:"h-3 w-3"}),_?"Amend":"Commit"]})]})]}):null,(0,G.jsx)(N1,{storageKey:xM,sections:_e}),Q&&typeof document<"u"?(0,O1.createPortal)((0,G.jsxs)("div",{className:"fixed inset-0 z-[100000] flex items-center justify-center p-4",children:[(0,G.jsx)("button",{type:"button","aria-hidden":!0,tabIndex:-1,onClick:()=>te(null),className:"absolute inset-0 cursor-default bg-black/50"}),(0,G.jsxs)("div",{className:"relative z-10 w-full max-w-xs rounded-lg border border-white/10 bg-[rgba(var(--w-bg-rgb),0.98)] p-4 shadow-xl",children:[(0,G.jsxs)("div",{className:"mb-1 flex items-center gap-2",children:[(0,G.jsx)(gt,{className:"h-4 w-4 shrink-0 text-rose-300/80"}),(0,G.jsx)("span",{className:"text-sm font-semibold text-white/90",children:Q.title})]}),(0,G.jsx)("p",{className:"mb-3 text-[11px] leading-relaxed text-white/55",children:Q.message}),(0,G.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,G.jsx)("button",{type:"button",onClick:()=>te(null),className:"rounded-md px-3 py-1.5 text-[11px] text-white/60 transition-colors hover:bg-white/[0.06] hover:text-white/85",children:"Cancel"}),(0,G.jsxs)("button",{type:"button",onClick:Q.onConfirm,className:"inline-flex items-center gap-1 rounded-md border border-rose-500/30 bg-rose-500/15 px-3 py-1.5 text-[11px] font-semibold text-rose-100 transition-colors hover:bg-rose-500/25",children:[(0,G.jsx)(_t,{className:"h-3 w-3"}),Q.confirmLabel]})]})]})]}),document.body):null]})}var Tt=W(ue(),1),U1={},G1="brain://",wM=32,kM=28,SM=114;function CM(t){return t==="header"?wM:t==="empty"?SM:kM}function IM(t){return t!=="node"}function z1(t,e){return t.type===e.type?t.name.localeCompare(e.name):t.type==="folder"?-1:1}function LM(t){let e=new Map,n=new Set;for(let a of t)n.add(a.uri);for(let a of t){let s=a.parentUri??ct(a.uri);if(!s||a.uri===s)continue;let i=e.get(s);i?i.push(a):e.set(s,[a])}for(let a of e.values())a.sort(z1);let r=new Map;for(let a of t){let s=kr(a.uri);if(!s||a.uri===s)continue;let i=a.parentUri??ct(a.uri);if(!(!i||i===s||!n.has(i)))continue;let l=r.get(s);l?l.push(a):r.set(s,[a])}for(let a of r.values())a.sort(z1);return{childrenByParent:e,rootsBySource:r}}function AM(t,e,n){let r=[],a=(i,o)=>{r.push({node:i,depth:o});let l=i.storeKey||as(i);if(i.type==="folder"&&n.has(l)){let u=t.childrenByParent.get(i.uri);if(u)for(let c=0;c<u.length;c++)a(u[c],o+1)}},s=t.rootsBySource.get(e);if(s)for(let i=0;i<s.length;i++)a(s[i],0);return r}function Sp(t){let{agentId:e,sidebarView:n="tree"}=t,r=Ln(),a=mi(),s=B(E=>E.files),i=B(E=>E.folderBadges),o=B(E=>E.expandedFolders),l=B(E=>E.activeFile),u=B(E=>E.toggleFolder),c=B(E=>E.openFile),d=B(E=>E.activeProjectId),f=B(E=>E.setActiveFolderPath),h=B(E=>E.activeFolderPath),p=B(E=>E.uploadMany),g=B(E=>E.moveFileToFolder),m=B(E=>E.uploading),x=B(E=>E.sources),b=B(E=>E.sourcesLoading),y=B(E=>E.hydrationState),C=B(E=>E.dirtySources),I=B(E=>E.organizeError),L=B(E=>E.clearOrganizeError),v=B(E=>E.snapshotError),k=B(E=>E.clearSnapshotError),O=B(E=>E.loadList),R=B(E=>E.pendingReviewPaths),P=B(E=>E.renameNode),H=B(E=>E.deleteNodes),w=B(E=>E.createNode),N=B(E=>E.pasteNodes),[j,K]=(0,qe.useState)(null),[A,F]=(0,qe.useState)({}),[_,X]=(0,qe.useState)(()=>new Set),[re,ae]=(0,qe.useState)(null),[Le,ye]=(0,qe.useState)(null),[q,Q]=(0,qe.useState)(null),[te,ge]=(0,qe.useState)(null),[de,De]=(0,qe.useState)(null),[Xe,Qe]=(0,qe.useState)(null),[rt,at]=(0,qe.useState)(!1),[Ft,Ue]=(0,qe.useState)(!1),ut=B(E=>E.setPendingSourceSuggestion),st=B(E=>E.setWorkspacePanelOpen);(0,qe.useEffect)(()=>{if(!l)return;let E=`${Ke(l)}://`;F(ne=>ne[E]?ne:{...ne,[E]:!0})},[l]);let yt=r.useFileMarks(e),vt=r.useAgents(),Ut=r.usePackageIconBySlug?.()??U1,Et=(0,qe.useMemo)(()=>yt||U1,[yt]),me=(0,qe.useMemo)(()=>qs(vt),[vt]),Ye=(0,qe.useMemo)(()=>me.byId.get(e)??null,[me,e]),cn=(0,qe.useMemo)(()=>{let E={};for(let ne of R){let se=Ra(ne);for(let _e of se)E[_e]=(E[_e]||0)+1}return E},[R]),fe=x.length>0,Re=(0,qe.useMemo)(()=>Object.values(s),[s]),Oe=(0,qe.useMemo)(()=>LM(Re),[Re]),Pe=(0,qe.useMemo)(()=>{let E={uri_root:G1,source_kind:"brain",writable:!0};return fe?x.length>0?x:[E]:[E]},[fe,x]),ze=n==="search",We=(0,qe.useMemo)(()=>{let E=h?kr(h):null;return E&&Pe.some(se=>se.uri_root===E)?E:Pe.find(se=>se.source_kind!=="brain")?.uri_root??Pe[0]?.uri_root??G1},[h,Pe]),nt=(0,qe.useMemo)(()=>{if(ze)return[];let E=[];for(let ne of Pe){let se=A[ne.uri_root]??!1;if(E.push({kind:"header",key:`h:${ne.uri_root}`,info:ne,expanded:se}),!se)continue;let _e=AM(Oe,ne.uri_root,o);if(_e.length===0)E.push({kind:"empty",key:`e:${ne.uri_root}`,sourceRoot:ne.uri_root});else for(let D of _e)E.push({kind:"node",key:`n:${D.node.uri}`,node:D.node,depth:D.depth})}if(q){let ne=q.parentUri,se=-1,_e=0;if(ne.endsWith("://"))se=E.findIndex(D=>D.kind==="header"&&D.info.uri_root===ne),_e=0;else{let D=E.findIndex(we=>we.kind==="node"&&we.node.uri===ne);D>=0&&(se=D,_e=E[D].depth+1)}se>=0&&E.splice(se+1,0,{kind:"creating",key:"creating-row",parentUri:ne,createKind:q.kind,depth:_e})}return E},[Oe,o,Pe,A,ze,q]),Vt=(0,qe.useMemo)(()=>nt.filter(E=>E.kind==="node").map(E=>E.node.uri),[nt]),et=(0,qe.useCallback)(({node:E,additive:ne,range:se})=>{X(_e=>{if(se&&re){let D=Vt.indexOf(re),we=Vt.indexOf(E.uri);if(D>=0&&we>=0){let[$t,Gt]=D<=we?[D,we]:[we,D];return new Set(Vt.slice($t,Gt+1))}}if(ne){let D=new Set(_e);return D.has(E.uri)?D.delete(E.uri):D.add(E.uri),D}return new Set([E.uri])}),se||ae(E.uri)},[Vt,re]),At=(0,qe.useCallback)(({node:E,x:ne,y:se})=>{X(_e=>_e.has(E.uri)&&_e.size>1?_e:new Set([E.uri])),ae(E.uri),De({kind:"node",node:E,x:ne,y:se})},[]),bn=(0,qe.useCallback)((E,ne)=>{ne.preventDefault(),ne.stopPropagation(),F(se=>se[E]?se:{...se,[E]:!0}),De({kind:"source",sourceRoot:E,x:ne.clientX,y:ne.clientY})},[]),Ve=(0,qe.useCallback)(E=>{E.target.closest('button, input, textarea, [role="menu"]')||bn(We,E)},[We,bn]),Be=(0,qe.useMemo)(()=>de?.kind!=="node"?[]:(_.has(de.node.uri)&&_.size>0?[..._]:[de.node.uri]).map(ne=>s[ne]).filter(Boolean),[de,_,s]),Rt=(0,qe.useMemo)(()=>ko({grantedFeatures:[...r.grantedFeatures??[]]},{features:["drive.sync"]}),[r.grantedFeatures]),[he,Me]=(0,qe.useState)(null),xe=(0,qe.useMemo)(()=>{if(de?.kind==="source")return{"new-file":!0,"new-folder":Ke(de.sourceRoot)!=="brain"};let E=Be.length===1?Be[0]:null,ne=E??Be[0],se=ne?ne.type==="folder"?ne.uri:ct(ne.uri):null;return{"copy-path":!!E,"copy-relative-path":!!E,reembed:!!E&&Rt&&Ke(E.uri)!=="brain",rename:!!E,delete:Be.length>0,"new-file":!!E,"new-folder":!!E&&Ke(E.uri)!=="brain",cut:Be.length>0,copy:Be.length>0,paste:!!te&&te.uris.length>0&&!!se}},[de,Be,te,Rt]),Fe=(0,qe.useCallback)(E=>{if(de?.kind==="source"){(E==="new-file"||E==="new-folder")&&Q({parentUri:de.sourceRoot,kind:E==="new-file"?"file":"folder"});return}let ne=Be,se=ne.length===1?ne[0]:null;if(E==="copy-path"&&se)navigator.clipboard?.writeText(se.uri);else if(E==="copy-relative-path"&&se)navigator.clipboard?.writeText(se.uri.replace(/^[a-z0-9_-]+:\/\//i,""));else if(E==="reembed"&&se){let _e=Ke(se.uri);_e&&Me({source:_e,...se.type==="folder"?{folder:se.uri}:{uri:se.uri},label:se.type==="folder"?`${se.name}/`:se.name})}else if(E==="rename"&&se)ye(se.uri);else if(E==="delete")ne.length&&Qe({targets:ne.map(_e=>({uri:_e.uri,id:_e.id,name:_e.name}))});else if(E==="cut"||E==="copy")ne.length&&ge({op:E,uris:ne.map(_e=>_e.uri)});else if(E==="paste"){let _e=se??ne[0];if(_e&&te){let D=_e.type==="folder"?_e.uri:ct(_e.uri);D&&(N({agentId:e,projectId:d??null,targetFolderUri:D,op:te.op,uris:te.uris}),te.op==="cut"&&ge(null))}}else if(E==="new-file"||E==="new-folder"){let _e=E==="new-file"?"file":"folder",D=se??ne[0];if(!D)return;let we=D.type==="folder"?D.uri:ct(D.uri);if(!we)return;!we.endsWith("://")&&!o.has(we)&&(u(we),a.getState().ensureFolderLoaded({agentId:e,projectId:d,uri:we})),Q({parentUri:we,kind:_e})}},[de,Be,o,u,e,d,te,N,a]),ve=(0,qe.useCallback)(async E=>{let ne=q;if(Q(null),!ne)return;let se=(E??"").trim();se&&await w({agentId:e,projectId:d??null,parentUri:ne.parentUri,name:se,kind:ne.kind})},[q,w,e,d]),Nt=(0,qe.useCallback)(()=>Q(null),[]),pt=(0,qe.useCallback)(async({node:E,newName:ne})=>{ye(null);let se=(ne??"").trim();!se||se===E.name||await P({agentId:e,projectId:d??null,uri:E.uri,id:E.id,newName:se})},[P,e,d]),kn=(0,qe.useCallback)(()=>ye(null),[]),yn=(0,qe.useCallback)(async()=>{if(Xe){at(!0);try{await H({agentId:e,projectId:d??null,targets:Xe.targets.map(E=>({uri:E.uri,id:E.id}))}),X(new Set)}finally{at(!1),Qe(null)}}},[Xe,H,e,d]),Nn=(0,qe.useCallback)(E=>{if(!Le)if(E.key==="F2"){let ne=_.size===1?[..._][0]:null;ne&&s[ne]&&(E.preventDefault(),ye(ne))}else if(E.key==="Delete"||E.key==="Backspace"){let ne=[..._].map(se=>s[se]).filter(se=>!!se);ne.length&&(E.preventDefault(),Qe({targets:ne.map(se=>({uri:se.uri,id:se.id,name:se.name}))}))}else E.key==="Escape"&&X(new Set)},[Le,_,s]),dn=(0,qe.useCallback)(async E=>{let ne=o.has(E.key);f(E.key),u(E.key),!ne&&await a.getState().ensureFolderLoaded({agentId:e,projectId:d,uri:E.key})},[e,o,d,f,u,a]),cr=(0,qe.useCallback)(E=>{E.uri&&f(ct(E.uri)),c(E)},[f,c]),yr=(0,qe.useCallback)(E=>{r.clearFileMark(E)},[r]),dr=(0,qe.useCallback)(E=>{F(ne=>({...ne,[E]:!ne[E]}))},[]),Ot=(0,qe.useCallback)(async E=>{if(!e)return;let ne=a.getState();if(F(se=>se[E]?se:{...se,[E]:!0}),ne.loadedFolders?.[E]){let se=Ke(E);se&&await ne.reconcileSourceFolders({agentId:e,projectId:d,source:se});return}await ne.ensureFolderLoaded({agentId:e,projectId:d,uri:E,force:!0})},[e,d,a]);(0,qe.useEffect)(()=>{if(!e)return;let E=a.getState(),ne=[];for(let se of Pe)A[se.uri_root]&&ne.push(se.uri_root);for(let se of o)ne.push(se);for(let se of ne){if(E.loadedFolders?.[se])continue;let _e=E.hydrationState?.[se];_e&&_e!=="idle"||E.ensureFolderLoaded({agentId:e,projectId:d,uri:se})}},[e,d,Pe,A,o,a]);let Dr=(0,qe.useCallback)(async({fromUri:E,id:ne,toFolderUri:se})=>{await g({agentId:e,projectId:d??null,fromUri:E,toFolderUri:se,id:ne})},[e,d,g]),fr=(0,qe.useMemo)(()=>Pe.every(E=>!A[E.uri_root]),[Pe,A]),jn=(0,qe.useMemo)(()=>ko({grantedFeatures:[...r.grantedFeatures??[]]},{features:["drive.mount"]}),[r.grantedFeatures]),oa=tv({agentId:e,projectId:d??void 0,enabled:jn&&fr}),Qn=fr&&jn&&oa.length>0,Mn=(0,qe.useCallback)(E=>{ut(E),st("sources",!0)},[ut,st]),Tn=(0,qe.useCallback)(()=>Ue(E=>!E),[]),vr=(0,qe.useRef)(null),qn=(0,qe.useRef)(nt);qn.current=nt;let la=(0,qe.useCallback)(E=>CM(qn.current[E]?.kind??"node"),[]),er=(0,qe.useCallback)(E=>qn.current[E]?.key??E,[]),hr=So({count:nt.length,getScrollElement:()=>vr.current,estimateSize:la,overscan:8,getItemKey:er});if(n==="git")return(0,Tt.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:(0,Tt.jsx)(H1,{agentId:e})});if(b&&!fe&&!ze)return(0,Tt.jsx)("div",{className:"p-4 text-center text-xs text-white/40 animate-pulse",children:"Loading sources"});let fn=v&&!ze?(0,Tt.jsxs)("div",{role:"status",className:"mx-2 mb-1 mt-1 flex items-start gap-2 rounded-md border border-rose-400/30 bg-rose-500/10 px-2 py-1.5 text-[11px] text-rose-100/90",children:[(0,Tt.jsx)("span",{className:"min-w-0 flex-1 break-words",children:v}),(0,Tt.jsx)("button",{type:"button",onClick:()=>{e&&O({agentId:e,projectId:d??null})},className:"shrink-0 rounded px-1 font-medium text-rose-200/80 transition-colors hover:text-rose-100",children:"Retry"}),(0,Tt.jsx)("button",{type:"button",onClick:k,"aria-label":"Dismiss",className:"shrink-0 rounded px-1 text-rose-200/70 transition-colors hover:text-rose-100",children:"\xD7"})]}):null;if(!Re.length&&!ze&&!fe)return fn??(0,Tt.jsx)("div",{className:"p-4 text-center text-xs text-white/30",children:"Empty Drive"});let wr=(E,ne)=>{let se=E.type==="folder",_e=E.storeKey||as(E);return(0,Tt.jsx)(mv,{node:E,depth:ne,agentId:e,projectId:d,isActive:!se&&l===_e,isExpanded:se&&o.has(_e),badgeCount:se?i[_e]:void 0,isDrop:j===_e,isSelectedFolder:se&&h===_e,mark:Et[E.uri],agentIndex:me,fallbackAgent:Ye,uploading:m,packageIconBySlug:Ut,onToggleFolder:dn,onOpenFile:cr,onClearFileMark:yr,onSetDropTarget:K,onUploadMany:p,onMoveFileToFolder:Dr,pendingReviewCount:se?cn[_e]:void 0,isSelected:_.has(E.uri),isCut:te?.op==="cut"&&te.uris.includes(E.uri),renaming:Le===E.uri,onNodeClick:et,onNodeContextMenu:At,onRenameCommit:pt,onRenameCancel:kn})};return(0,Tt.jsxs)("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[(0,Tt.jsxs)("div",{ref:vr,tabIndex:0,onKeyDown:Nn,onContextMenu:Ve,className:"min-h-0 flex-1 overflow-auto pt-0 pb-2 outline-none",children:[fn,I&&!ze?(0,Tt.jsxs)("div",{role:"status",className:"mx-2 mb-1 mt-1 flex items-start gap-2 rounded-md border border-amber-400/30 bg-amber-500/10 px-2 py-1.5 text-[11px] text-amber-100/90",children:[(0,Tt.jsx)("span",{className:"min-w-0 flex-1 break-words",children:I}),(0,Tt.jsx)("button",{type:"button",onClick:L,"aria-label":"Dismiss",className:"shrink-0 rounded px-1 text-amber-200/70 transition-colors hover:text-amber-100",children:"\xD7"})]}):null,ze?(0,Tt.jsx)(Iv,{agentId:e}):null,ze?null:(0,Tt.jsx)("div",{style:{height:hr.getTotalSize(),width:"100%",position:"relative"},children:hr.getVirtualItems().map(E=>{let ne=nt[E.index];if(!ne)return null;let se=IM(ne.kind);return(0,Tt.jsx)("div",{"data-index":E.index,ref:se?hr.measureElement:void 0,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${E.start}px)`},children:ne.kind==="header"?(0,Tt.jsx)(Cv,{info:ne.info,expanded:ne.expanded,onToggle:dr,onContextMenu:bn,onRefresh:Ot,hydration:y[ne.info.uri_root]??"idle",dirty:!!C[Ke(ne.info.uri_root)],hideChevron:!0,compact:!0}):ne.kind==="empty"?(0,Tt.jsxs)("div",{className:"flex flex-col items-start gap-1.5 px-4 py-2",onContextMenu:_e=>bn(ne.sourceRoot,_e),children:[(0,Tt.jsxs)("span",{className:"text-xs text-white/35",children:["No files for ",Ke(ne.sourceRoot)]}),(0,Tt.jsx)(W1.SkillLauncher,{variant:"label",skill:"manage-files",packageId:"@neuralis/brain-core",scripts:["scripts/upload.sh","scripts/modify.sh"],label:"Populate this source with the agent"})]}):ne.kind==="creating"?(0,Tt.jsx)(PM,{kind:ne.createKind,depth:ne.depth,onCommit:ve,onCancel:Nt}):wr(ne.node,ne.depth)},E.key)})}),de?(0,Tt.jsx)(xv,{x:de.x,y:de.y,variant:de.kind==="source"?"source":"node",enabled:xe,onAction:Fe,onClose:()=>De(null)}):null,he?(0,Tt.jsx)(uu,{agentId:e,...d?{projectId:d}:{},target:he,onClose:()=>Me(null)}):null,Xe?(0,Tt.jsx)(vv,{names:Xe.targets.map(E=>E.name),busy:rt,onCancel:()=>{rt||Qe(null)},onConfirm:yn}):null]}),Qn&&!ze?(0,Tt.jsx)(ov,{suggestions:oa,expanded:Ft,onToggleExpanded:Tn,onPick:Mn,overlay:Ft}):null]})}function PM({kind:t,depth:e,onCommit:n,onCancel:r}){let a=(0,qe.useRef)(!1),s=t==="folder"?Or:_s;return(0,Tt.jsxs)("div",{className:"flex h-7 items-center gap-1.5 px-2",style:{paddingLeft:`${e*12+8}px`},children:[(0,Tt.jsx)("span",{className:"w-3.5 h-3.5 inline-block shrink-0"}),(0,Tt.jsx)(s,{className:"w-4 h-4 shrink-0 text-sky-300/80"}),(0,Tt.jsx)("input",{autoFocus:!0,spellCheck:!1,placeholder:t==="folder"?"Folder name":"File name",onClick:i=>i.stopPropagation(),onMouseDown:i=>i.stopPropagation(),onKeyDown:i=>{i.stopPropagation(),i.key==="Enter"?a.current||(a.current=!0,n(i.currentTarget.value)):i.key==="Escape"&&(a.current||(a.current=!0,r()))},onBlur:i=>{if(a.current)return;a.current=!0;let o=i.currentTarget.value.trim();o?n(o):r()},className:"min-w-0 flex-1 rounded border border-sky-400/60 bg-black/50 px-1 py-0 text-xs text-white outline-none placeholder:text-white/30"})]})}var ot=W(Je(),1);var i2=W(nr(),1);function j1(t){if(!t)return{lines:new Map,deletedBefore:new Set};let e=new Map,n=new Set,r=0,a=!1,s=0,i=0,o=()=>{s>0&&i===0&&n.add(r),s=0,i=0};for(let l of t.split(`
|
|
32
|
+
`)){if(l.startsWith("@@")){o();let u=/^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(l);r=u?parseInt(u[1],10):0,a=r>0;continue}a&&(l.startsWith("+")&&!l.startsWith("+++")?(e.set(r,s>0?"modified":"added"),i++,r++):l.startsWith("-")&&!l.startsWith("---")?s++:(o(),l.startsWith(" ")&&r++))}return o(),{lines:e,deletedBefore:n}}function yd(t){return t.lines.size===0&&t.deletedBefore.size===0}var ar=W(Je(),1),V1=W(ds(),1);var wu=W(ue(),1);function Cp({sourceType:t,className:e}){return t==="blob"?(0,wu.jsx)("span",{title:"Blob + Vector",children:(0,wu.jsx)(rr,{className:V("w-3 h-3",e)})}):(0,wu.jsx)("span",{title:"Vector only",children:(0,wu.jsx)(Sr,{className:V("w-3 h-3",e)})})}var Zr=W(ue(),1);function Ip({node:t,active:e,mark:n,isDirty:r,hasPendingReview:a,preview:s,pinned:i,onTogglePin:o}){let l=B(h=>h.setActiveFile),u=B(h=>h.closeFile),c=B(h=>h.activeAgentId),d=Ln(),f=t.status==="deleted";return(0,Zr.jsxs)("div",{className:V("group flex items-center gap-1.5 px-3 py-2 text-xs cursor-pointer min-w-[120px] max-w-[240px] rounded-lg",e?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>{l(t.storeKey||t.path),c&&n&&d.clearFileMark({agentId:c,path:t.path})},onDoubleClick:()=>o?.(),title:t.path,children:[(0,Zr.jsx)(Cp,{sourceType:t.sourceType,className:V("shrink-0",t.sourceType==="blob"?"text-sky-400/60":"text-violet-400/60")}),(0,Zr.jsxs)("span",{className:V("truncate flex-1",s&&"italic",f&&"line-through text-white/45"),children:[t.name,r?(0,Zr.jsx)("span",{className:"ml-1",style:{color:"var(--warning)"},children:"*"}):null]}),a?(0,Zr.jsx)("span",{className:"inline-flex items-center rounded-full px-1.5 py-0.5 text-[9px] font-semibold bg-amber-500/15 text-amber-200",children:"REVIEW"}):n?(0,Zr.jsx)("span",{className:V("inline-flex items-center rounded-full px-1.5 py-0.5 text-[9px] font-semibold",n==="new"?"bg-emerald-500/15 text-emerald-200":"bg-blue-500/15 text-blue-200"),children:n==="new"?"NEW":"MOD"}):null,i?(0,Zr.jsx)("button",{onClick:h=>{h.stopPropagation(),o?.()},className:"p-0.5 rounded text-amber-300/80 hover:bg-white/10",title:"Unpin tab",children:(0,Zr.jsx)(vi,{className:"w-3 h-3 fill-current"})}):(0,Zr.jsx)("button",{onClick:h=>{h.stopPropagation(),u(t.storeKey||t.path)},className:V("opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10"),title:"Close (double-click tab to pin)",children:(0,Zr.jsx)(Yt,{className:"w-3 h-3"})})]})}var Hn=W(ue(),1),vd="data-tab-scroller",q1="data-tab-active";function RM(t,e){return e.left<t.left?e.left-t.left:e.right>t.right?Math.min(e.right-t.right,e.left-t.left):0}function NM(t,e){return e.scrollWidth<=e.clientWidth||Math.abs(t.deltaX)>=Math.abs(t.deltaY)?0:t.deltaY}function $1(){let t=B(y=>y.openFiles),e=B(y=>y.activeFile),n=B(y=>y.files),r=B(y=>y.tabMeta),a=B(y=>y.fileContentByPath),s=B(y=>y.fileBaseContentByPath),i=B(y=>y.filePrevByPath),o=B(y=>y.activeAgentId),l=B(y=>y.reorderOpenFiles),u=B(y=>y.toggleTabPin),d=Ln().useFileMarks(o??void 0)||{},[f,h]=(0,ar.useState)(null),[p,g]=(0,ar.useState)(null),m=(0,ar.useRef)(null),x=t.length>0,b=(0,ar.useCallback)(()=>{let y=m.current,C=y?.closest(`[${vd}]`),I=y?.querySelector(`[${q1}="true"]`);if(!C||!I)return;let L=RM(C.getBoundingClientRect(),I.getBoundingClientRect());L!==0&&(C.scrollLeft+=L)},[]);return(0,ar.useLayoutEffect)(()=>{b()},[e,t,b]),(0,ar.useEffect)(()=>{let y=m.current?.closest(`[${vd}]`);if(!y)return;let C=L=>{let v=NM(L,y);v!==0&&(L.preventDefault(),y.scrollLeft+=v)};y.addEventListener("wheel",C,{passive:!1});let I=typeof ResizeObserver<"u"?new ResizeObserver(()=>{y.clientWidth>0&&b()}):null;return I?.observe(y),()=>{y.removeEventListener("wheel",C),I?.disconnect()}},[x,b]),t.length===0?null:(0,Hn.jsx)("div",{ref:m,className:"flex items-center",children:t.map(y=>{let C=n[y],I=r[y],L=C?.uri??y,v=C?.name??I?.name??It(y),k=C?.status??I?.status,O=a[y]??"",R=s[y],P=typeof R=="string"&&R!==O,w=!!i[y]&&k==="pending_review";return(0,Hn.jsx)("div",{draggable:!0,[q1]:e===y?"true":void 0,onDragStart:N=>{h(y),N.dataTransfer.effectAllowed="move";try{N.dataTransfer.setData("text/plain",y)}catch{}},onDragOver:N=>{N.preventDefault(),N.dataTransfer.dropEffect="move",p!==y&&g(y)},onDrop:N=>{N.preventDefault(),f&&f!==y&&l(f,y),h(null),g(null)},onDragEnd:()=>{h(null),g(null)},className:V("shrink-0 rounded-lg",p===y&&f&&f!==y?"ring-1 ring-violet-400/50":"",f===y?"opacity-50":""),children:(0,Hn.jsx)(Ip,{node:{storeKey:C?.storeKey??y,path:L,name:v,status:k,sourceAgentId:C?.sourceAgentId??I?.sourceAgentId,sourceType:C?.sourceType},active:e===y,mark:d[L]?.kind,isDirty:P,hasPendingReview:w,preview:!!I?.preview,pinned:!!I?.pinned,onTogglePin:()=>u(y)})},y)})})}function K1(){let t=B(p=>p.openFiles),e=B(p=>p.activeFile),n=B(p=>p.closeAllFiles),r=B(p=>p.closeSavedFiles),a=B(p=>p.closeOtherFiles),s=B(p=>p.previewEditorsEnabled),i=B(p=>p.setPreviewEditorsEnabled),[o,l]=(0,ar.useState)(!1),[u,c]=(0,ar.useState)(null),d=(0,ar.useRef)(null),f=(0,ar.useRef)(null);return(0,ar.useEffect)(()=>{if(!o)return;let p=x=>{let b=x.target;d.current?.contains(b)||f.current?.contains(b)||l(!1)},g=x=>{x.key==="Escape"&&l(!1)},m=()=>l(!1);return document.addEventListener("mousedown",p),document.addEventListener("keydown",g),window.addEventListener("resize",m),window.addEventListener("scroll",m,!0),()=>{document.removeEventListener("mousedown",p),document.removeEventListener("keydown",g),window.removeEventListener("resize",m),window.removeEventListener("scroll",m,!0)}},[o]),t.length===0?null:(0,Hn.jsxs)("div",{className:"flex shrink-0 items-center border-l border-white/[0.05]",children:[(0,Hn.jsx)("button",{ref:d,type:"button",onClick:()=>{if(o){l(!1);return}let p=d.current?.getBoundingClientRect();p&&c({top:p.bottom+4,right:Math.max(4,window.innerWidth-p.right)}),l(!0)},className:V("flex items-center justify-center w-6 h-6 mx-1 rounded-md transition",o?"bg-white/10 text-white/80":"text-white/40 hover:bg-white/5 hover:text-white/70"),title:"Editor actions","aria-haspopup":"menu","aria-expanded":o,children:(0,Hn.jsx)(Ds,{className:"w-4 h-4"})}),o&&u?(0,V1.createPortal)((0,Hn.jsxs)("div",{ref:f,role:"menu",style:{position:"fixed",top:u.top,right:u.right},className:"z-[1000] min-w-[190px] rounded-lg border border-white/10 bg-[#14141b] py-1 text-[11px] text-white/80 shadow-[0_18px_46px_-20px_rgba(0,0,0,0.8)]",children:[(0,Hn.jsx)(Lp,{label:"Close All",onClick:()=>{n(),l(!1)}}),(0,Hn.jsx)(Lp,{label:"Close Saved",onClick:()=>{r(),l(!1)}}),(0,Hn.jsx)(Lp,{label:"Close Others",disabled:!e,onClick:()=>{e&&a(e),l(!1)}}),(0,Hn.jsx)("div",{className:"my-1 h-px bg-white/[0.06]"}),(0,Hn.jsxs)("button",{type:"button",role:"menuitemcheckbox","aria-checked":s,onClick:()=>i(!s),className:"flex w-full items-center gap-2 px-3 py-1.5 text-left hover:bg-white/[0.06]",children:[(0,Hn.jsx)("span",{className:"w-3.5 shrink-0 text-emerald-300",children:s?(0,Hn.jsx)(Vn,{className:"w-3.5 h-3.5"}):null}),(0,Hn.jsx)("span",{children:"Enable Preview Editors"})]})]}),document.body):null]})}function Lp({label:t,onClick:e,disabled:n}){return(0,Hn.jsx)("button",{type:"button",role:"menuitem",disabled:n,onClick:e,className:"flex w-full items-center px-3 py-1.5 text-left hover:bg-white/[0.06] disabled:opacity-40 disabled:cursor-not-allowed",children:t})}var Fi=W(Je(),1);var kt=W(ue(),1);function MM(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function Ap(t){if(!t)return null;try{return new Date(t).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"})}catch{return t}}function Pp({node:t,className:e,hideVersionDiff:n=!1}){let{tags:r,category:a,createdAt:s,updatedAt:i,metadata:o,sourceAgentId:l,version:u,readSource:c}=t,d=t.uri?Ke(t.uri):void 0,h=Ln().useAgents(),p=(0,Fi.useMemo)(()=>qs(h),[h]),g=(0,Fi.useMemo)(()=>l?p.byId.get(l)??null:null,[p,l]),m=g?.name||g?.slug,x=Io(g?.id,p);if(!Rp(t))return null;let y=o&&typeof o.mimeType=="string"?o.mimeType:void 0,C=o&&typeof o.size=="number"?o.size:void 0,I=ou(t),L=u?.sync,v=Li(u?.changedAt),k=Th(u?.changedAt),O=Th(L?.syncedAt);return(0,kt.jsxs)("div",{className:V("flex flex-wrap items-center gap-1.5 px-2 py-2 text-[10px]",e),style:{background:"linear-gradient(180deg, rgba(255,255,255,0.03) 0%, rgba(255,255,255,0.01) 100%)",borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,kt.jsxs)("span",{className:V("inline-flex items-center gap-1 rounded-full border px-2 py-1",I.highlightTone,"border-white/[0.07]",I.tone),children:[(0,kt.jsx)(I.icon,{className:V("w-3 h-3",I.iconTone)}),I.label]}),d?(0,kt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/60",children:[(0,kt.jsx)(ls,{className:"w-3 h-3 text-white/35"}),(0,kt.jsx)("span",{className:"uppercase font-semibold tracking-wide",children:d})]}):null,t.os_uri?(0,kt.jsx)(TM,{value:t.os_uri}):null,m?(0,kt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/55",title:`Created by ${m}`,children:[(0,kt.jsx)(Tl,{className:"w-3 h-3 text-white/35"}),(0,kt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide",style:{color:x||"var(--icon-muted)",backgroundColor:x?`${x}20`:"rgba(255,255,255,0.04)"},children:[(0,kt.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:x||"var(--icon-muted)"}}),m]})]}):null,a?(0,kt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/55",children:[(0,kt.jsx)($r,{className:"w-3 h-3 text-white/35"}),a]}):null,r&&r.length>0?(0,kt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/55",children:[(0,kt.jsx)(tu,{className:"w-3 h-3 text-white/35"}),r.map(R=>(0,kt.jsx)("span",{className:"inline-flex rounded-full px-1.5 py-0.5 text-[9px] font-medium bg-white/[0.06] text-white/70",children:R},R))]}):null,y?(0,kt.jsx)("span",{className:"rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/40",children:y}):null,C?(0,kt.jsx)("span",{className:"rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/40",children:MM(C)}):null,s?(0,kt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/38",children:[(0,kt.jsx)(Ta,{className:"w-3 h-3"}),Ap(s)]}):null,i&&i!==s?(0,kt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/40",children:[(0,kt.jsx)(Xt,{className:"w-2.5 h-2.5"}),Ap(i)]}):null,u?.changedAt?(0,kt.jsxs)("span",{className:V("inline-flex items-center gap-1 rounded-full border px-2 py-1",v.pillClassName),children:[(0,kt.jsx)(Ta,{className:V("w-3 h-3",v.iconClassName)}),"changed ",k?`${k} ago`:Ap(u.changedAt)]}):null,!n&&u?.diff?(0,kt.jsxs)("span",{className:V("inline-flex items-center gap-1 rounded-full border px-2 py-1",v.pillClassName),children:[(0,kt.jsx)(Cr,{className:V("w-3 h-3",v.iconClassName)}),(0,kt.jsxs)("span",{className:"text-emerald-200/95",children:["+",u.diff.added]}),(0,kt.jsx)("span",{className:"text-white/25",children:"/"}),(0,kt.jsxs)("span",{className:"text-rose-200/95",children:["-",u.diff.removed]})]}):null,O?(0,kt.jsxs)("span",{className:"rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/38",children:["synced ",O," ago"]}):null]})}function TM({value:t}){let[e,n]=(0,Fi.useState)(!1),r=(0,Fi.useCallback)(()=>{navigator.clipboard.writeText(t).then(()=>{n(!0),setTimeout(()=>n(!1),1500)}).catch(()=>{})},[t]),a=t.length>60?"..."+t.slice(-57):t;return(0,kt.jsxs)("button",{type:"button",onClick:r,title:t,className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/45 hover:text-white/70 hover:bg-white/[0.06] transition-colors cursor-pointer",children:[e?(0,kt.jsx)(ga,{className:"w-3 h-3 text-emerald-300/80"}):(0,kt.jsx)(rr,{className:"w-3 h-3 text-white/35"}),(0,kt.jsx)("span",{className:"font-mono truncate max-w-[280px]",children:a})]})}function Rp(t){let{tags:e,category:n,createdAt:r,updatedAt:a,metadata:s,sourceAgentId:i,version:o}=t,l=t.uri?Ke(t.uri):void 0;return!!i||!!e?.length||!!n||!!l||!!t.os_uri||!!r||!!a||!!o||!!(s&&Object.keys(s).length>0)}var Pf=W(Je(),1);var Mp=[],Z1=[];(()=>{let t="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,1n,9,16,o,,x,1i,3,,i,,7,a,2,t,3,1k,,,7,2,2,2,3,9,,a,2,q,,2,3,1k,,,5,4,2,2,3,3,,u,2,3,,b,3,1k,,,8,,3,,3,k,2,m,6,,3,1k,,,7,2,2,2,3,7,3,a,2,u,,1n,5,3,3,,4,9,,14,5,1j,,,7,,3,,4,7,2,b,2,t,3,1k,,,7,,3,,4,7,2,b,2,f,,c,4,1j,2,,7,,3,,4,9,,a,2,t,3,1y,,4,6,,,,8,i,2,1p,,,8,c,8,2q,,,a,b,7,21,2,r,,,,,,4,2,1d,k,,2,5,b,,10,9,,2u,b,,6,n,4,4,3,g,4,d,,,3,6,,f,,jj,3,qa,4,s,3,t,2,u,2,1s,w,9,,19,3,,,39,2,y,,3a,c,4,c,63,5,1l,a,,,,,2,o,2,,1c,1a,2,c,k,5,1b,h,12,9,c,3,u,d,1k,e,1c,k,48,3,,l,4,,6,,2,3,5i,1s,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,n,5,4,,2b,2,1e,i,q,i,d,,12,8,p,d,18,4,1b,e,10,,1v,e,c,,8,2,1a,,1f,,,3,2,2,5,2,,,15,5,5,2,6k,8,,2,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,1t,5,8t,2,25,6,1y,b,1d,4,3e,3,1h,f,15,,2,2,a,4,19,b,7,,1p,3,10,e,g,2,18,,c,3,1c,e,8,4,,2,2k,c,6,,2,,4d,c,l,4,1j,2,,7,2,2,2,3,9,,a,2,2,7,3,5,1v,9,,,2,,,4,,5,,,e,2,2a,i,n,,29,k,6j,7,2,9,r,2,2a,h,2y,d,2t,3,2,a,74,f,6t,6,,2,2,4,,,,2,3x,7,2,7,3,,s,a,14,7,,4,8,,9,b,1a,g,5i,8,5j,8,,8,2a,m,,e,3e,6,3,,,2,,7,,,1u,5,,2,,5,9n,4,9,2,,,1c,7,3,5,n,,44l,,6,f,8ug,i,1xc,5,1n,7,t4,,,1j,7,4,29,,b,2,f57,2,3mp,1a,2,n,f2,5,3,6,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,2s,,4g,7,af,,1p,4,e4,4,72,2,6r,,2,,7,2,5,,d6,7,31,7,240,5".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,n=0;e<t.length;e++)(e%2?Z1:Mp).push(n=n+t[e])})();function DM(t){if(t<768)return!1;for(let e=0,n=Mp.length;;){let r=e+n>>1;if(t<Mp[r])n=r;else if(t>=Z1[r])e=r+1;else return!0;if(e==n)return!1}}function X1(t){return t>=127462&&t<=127487}var Y1=8205;function Q1(t,e,n=!0,r=!0){return(n?ek:FM)(t,e,r)}function ek(t,e,n){if(e==t.length)return e;e&&tk(t.charCodeAt(e))&&nk(t.charCodeAt(e-1))&&e--;let r=Np(t,e);for(e+=J1(r);e<t.length;){let a=Np(t,e);if(r==Y1||a==Y1||n&&DM(a))e+=J1(a),r=a;else if(X1(a)){let s=0,i=e-2;for(;i>=0&&X1(Np(t,i));)s++,i-=2;if(s%2==0)break;e+=2}else break}return e}function FM(t,e,n){for(;e>1;){let r=ek(t,e-2,n);if(r<e)return r;e--}return 0}function Np(t,e){let n=t.charCodeAt(e);if(!nk(n)||e+1==t.length)return n;let r=t.charCodeAt(e+1);return tk(r)?(n-55296<<10)+(r-56320)+65536:n}function tk(t){return t>=56320&&t<57344}function nk(t){return t>=55296&&t<56320}function J1(t){return t<65536?1:2}var mt=class t{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,n,r){[e,n]=Wo(this,e,n);let a=[];return this.decompose(0,e,a,2),r.length&&r.decompose(0,r.length,a,3),this.decompose(n,this.length,a,1),Uo.from(a,this.length-(n-e)+r.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,n=this.length){[e,n]=Wo(this,e,n);let r=[];return this.decompose(e,n,r,0),Uo.from(r,n-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let n=this.scanIdentical(e,1),r=this.length-this.scanIdentical(e,-1),a=new _i(this),s=new _i(e);for(let i=n,o=n;;){if(a.next(i),s.next(i),i=0,a.lineBreak!=s.lineBreak||a.done!=s.done||a.value!=s.value)return!1;if(o+=a.value.length,a.done||o>=r)return!0}}iter(e=1){return new _i(this,e)}iterRange(e,n=this.length){return new Id(this,e,n)}iterLines(e,n){let r;if(e==null)r=this.iter();else{n==null&&(n=this.lines+1);let a=this.line(e).from;r=this.iterRange(a,Math.max(a,n==this.lines+1?this.length:n<=1?0:this.line(n-1).to))}return new Ld(r)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?t.empty:e.length<=32?new Ur(e):Uo.from(Ur.split(e,[]))}},Ur=class t extends mt{constructor(e,n=EM(e)){super(),this.text=e,this.length=n}get lines(){return this.text.length}get children(){return null}lineInner(e,n,r,a){for(let s=0;;s++){let i=this.text[s],o=a+i.length;if((n?r:o)>=e)return new Dp(a,o,r,i);a=o+1,r++}}decompose(e,n,r,a){let s=e<=0&&n>=this.length?this:new t(rk(this.text,e,n),Math.min(n,this.length)-Math.max(0,e));if(a&1){let i=r.pop(),o=Cd(s.text,i.text.slice(),0,s.length);if(o.length<=32)r.push(new t(o,i.length+s.length));else{let l=o.length>>1;r.push(new t(o.slice(0,l)),new t(o.slice(l)))}}else r.push(s)}replace(e,n,r){if(!(r instanceof t))return super.replace(e,n,r);[e,n]=Wo(this,e,n);let a=Cd(this.text,Cd(r.text,rk(this.text,0,e)),n),s=this.length+r.length-(n-e);return a.length<=32?new t(a,s):Uo.from(t.split(a,[]),s)}sliceString(e,n=this.length,r=`
|
|
33
|
+
`){[e,n]=Wo(this,e,n);let a="";for(let s=0,i=0;s<=n&&i<this.text.length;i++){let o=this.text[i],l=s+o.length;s>e&&i&&(a+=r),e<l&&n>s&&(a+=o.slice(Math.max(0,e-s),n-s)),s=l+1}return a}flatten(e){for(let n of this.text)e.push(n)}scanIdentical(){return 0}static split(e,n){let r=[],a=-1;for(let s of e)r.push(s),a+=s.length+1,r.length==32&&(n.push(new t(r,a)),r=[],a=-1);return a>-1&&n.push(new t(r,a)),n}},Uo=class t extends mt{constructor(e,n){super(),this.children=e,this.length=n,this.lines=0;for(let r of e)this.lines+=r.lines}lineInner(e,n,r,a){for(let s=0;;s++){let i=this.children[s],o=a+i.length,l=r+i.lines-1;if((n?l:o)>=e)return i.lineInner(e,n,r,a);a=o+1,r=l+1}}decompose(e,n,r,a){for(let s=0,i=0;i<=n&&s<this.children.length;s++){let o=this.children[s],l=i+o.length;if(e<=l&&n>=i){let u=a&((i<=e?1:0)|(l>=n?2:0));i>=e&&l<=n&&!u?r.push(o):o.decompose(e-i,n-i,r,u)}i=l+1}}replace(e,n,r){if([e,n]=Wo(this,e,n),r.lines<this.lines)for(let a=0,s=0;a<this.children.length;a++){let i=this.children[a],o=s+i.length;if(e>=s&&n<=o){let l=i.replace(e-s,n-s,r),u=this.lines-i.lines+l.lines;if(l.lines<u>>4&&l.lines>u>>6){let c=this.children.slice();return c[a]=l,new t(c,this.length-(n-e)+r.length)}return super.replace(s,o,l)}s=o+1}return super.replace(e,n,r)}sliceString(e,n=this.length,r=`
|
|
34
|
+
`){[e,n]=Wo(this,e,n);let a="";for(let s=0,i=0;s<this.children.length&&i<=n;s++){let o=this.children[s],l=i+o.length;i>e&&s&&(a+=r),e<l&&n>i&&(a+=o.sliceString(e-i,n-i,r)),i=l+1}return a}flatten(e){for(let n of this.children)n.flatten(e)}scanIdentical(e,n){if(!(e instanceof t))return 0;let r=0,[a,s,i,o]=n>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;a+=n,s+=n){if(a==i||s==o)return r;let l=this.children[a],u=e.children[s];if(l!=u)return r+l.scanIdentical(u,n);r+=l.length+1}}static from(e,n=e.reduce((r,a)=>r+a.length+1,-1)){let r=0;for(let h of e)r+=h.lines;if(r<32){let h=[];for(let p of e)p.flatten(h);return new Ur(h,n)}let a=Math.max(32,r>>5),s=a<<1,i=a>>1,o=[],l=0,u=-1,c=[];function d(h){let p;if(h.lines>s&&h instanceof t)for(let g of h.children)d(g);else h.lines>i&&(l>i||!l)?(f(),o.push(h)):h instanceof Ur&&l&&(p=c[c.length-1])instanceof Ur&&h.lines+p.lines<=32?(l+=h.lines,u+=h.length+1,c[c.length-1]=new Ur(p.text.concat(h.text),p.length+1+h.length)):(l+h.lines>a&&f(),l+=h.lines,u+=h.length+1,c.push(h))}function f(){l!=0&&(o.push(c.length==1?c[0]:t.from(c,u)),u=-1,l=c.length=0)}for(let h of e)d(h);return f(),o.length==1?o[0]:new t(o,n)}};mt.empty=new Ur([""],0);function EM(t){let e=-1;for(let n of t)e+=n.length+1;return e}function Cd(t,e,n=0,r=1e9){for(let a=0,s=0,i=!0;s<t.length&&a<=r;s++){let o=t[s],l=a+o.length;l>=n&&(l>r&&(o=o.slice(0,r-a)),a<n&&(o=o.slice(n-a)),i?(e[e.length-1]+=o,i=!1):e.push(o)),a=l+1}return e}function rk(t,e,n){return Cd(t,[""],e,n)}var _i=class{constructor(e,n=1){this.dir=n,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[n>0?1:(e instanceof Ur?e.text.length:e.children.length)<<1]}nextInner(e,n){for(this.done=this.lineBreak=!1;;){let r=this.nodes.length-1,a=this.nodes[r],s=this.offsets[r],i=s>>1,o=a instanceof Ur?a.text.length:a.children.length;if(i==(n>0?o:0)){if(r==0)return this.done=!0,this.value="",this;n>0&&this.offsets[r-1]++,this.nodes.pop(),this.offsets.pop()}else if((s&1)==(n>0?0:1)){if(this.offsets[r]+=n,e==0)return this.lineBreak=!0,this.value=`
|
|
35
|
+
`,this;e--}else if(a instanceof Ur){let l=a.text[i+(n<0?-1:0)];if(this.offsets[r]+=n,l.length>Math.max(0,e))return this.value=e==0?l:n>0?l.slice(e):l.slice(0,l.length-e),this;e-=l.length}else{let l=a.children[i+(n<0?-1:0)];e>l.length?(e-=l.length,this.offsets[r]+=n):(n<0&&this.offsets[r]--,this.nodes.push(l),this.offsets.push(n>0?1:(l instanceof Ur?l.text.length:l.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}},Id=class{constructor(e,n,r){this.value="",this.done=!1,this.cursor=new _i(e,n>r?-1:1),this.pos=n>r?e.length:0,this.from=Math.min(n,r),this.to=Math.max(n,r)}nextInner(e,n){if(n<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,n<0?this.pos-this.to:this.from-this.pos);let r=n<0?this.pos-this.from:this.to-this.pos;e>r&&(e=r),r-=e;let{value:a}=this.cursor.next(e);return this.pos+=(a.length+e)*n,this.value=a.length<=r?a:n<0?a.slice(a.length-r):a.slice(0,r),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}},Ld=class{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:n,lineBreak:r,value:a}=this.inner.next(e);return n&&this.afterBreak?(this.value="",this.afterBreak=!1):n?(this.done=!0,this.value=""):r?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=a,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol<"u"&&(mt.prototype[Symbol.iterator]=function(){return this.iter()},_i.prototype[Symbol.iterator]=Id.prototype[Symbol.iterator]=Ld.prototype[Symbol.iterator]=function(){return this});var Dp=class{constructor(e,n,r,a){this.from=e,this.to=n,this.number=r,this.text=a}get length(){return this.to-this.from}};function Wo(t,e,n){return e=Math.max(0,Math.min(t.length,e)),[e,Math.max(e,Math.min(t.length,n))]}function Gn(t,e,n=!0,r=!0){return Q1(t,e,n,r)}function OM(t){return t>=56320&&t<57344}function BM(t){return t>=55296&&t<56320}function lk(t,e){let n=t.charCodeAt(e);if(!BM(n)||e+1==t.length)return n;let r=t.charCodeAt(e+1);return OM(r)?(n-55296<<10)+(r-56320)+65536:n}function uk(t){return t<65536?1:2}var Fp=/\r\n?|\n/,Ar=(function(t){return t[t.Simple=0]="Simple",t[t.TrackDel=1]="TrackDel",t[t.TrackBefore=2]="TrackBefore",t[t.TrackAfter=3]="TrackAfter",t})(Ar||(Ar={})),gs=class t{constructor(e){this.sections=e}get length(){let e=0;for(let n=0;n<this.sections.length;n+=2)e+=this.sections[n];return e}get newLength(){let e=0;for(let n=0;n<this.sections.length;n+=2){let r=this.sections[n+1];e+=r<0?this.sections[n]:r}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let n=0,r=0,a=0;n<this.sections.length;){let s=this.sections[n++],i=this.sections[n++];i<0?(e(r,a,s),a+=s):a+=i,r+=s}}iterChangedRanges(e,n=!1){Ep(this,e,n)}get invertedDesc(){let e=[];for(let n=0;n<this.sections.length;){let r=this.sections[n++],a=this.sections[n++];a<0?e.push(r,a):e.push(a,r)}return new t(e)}composeDesc(e){return this.empty?e:e.empty?this:ck(this,e)}mapDesc(e,n=!1){return e.empty?this:Op(this,e,n)}mapPos(e,n=-1,r=Ar.Simple){let a=0,s=0;for(let i=0;i<this.sections.length;){let o=this.sections[i++],l=this.sections[i++],u=a+o;if(l<0){if(u>e)return s+(e-a);s+=o}else{if(r!=Ar.Simple&&u>=e&&(r==Ar.TrackDel&&a<e&&u>e||r==Ar.TrackBefore&&a<e||r==Ar.TrackAfter&&u>e))return null;if(u>e||u==e&&n<0&&!o)return e==a||n<0?s:s+l;s+=l}a=u}if(e>a)throw new RangeError(`Position ${e} is out of range for changeset of length ${a}`);return s}touchesRange(e,n=e){for(let r=0,a=0;r<this.sections.length&&a<=n;){let s=this.sections[r++],i=this.sections[r++],o=a+s;if(i>=0&&a<=n&&o>=e)return a<e&&o>n?"cover":!0;a=o}return!1}toString(){let e="";for(let n=0;n<this.sections.length;){let r=this.sections[n++],a=this.sections[n++];e+=(e?" ":"")+r+(a>=0?":"+a:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(n=>typeof n!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new t(e)}static create(e){return new t(e)}},zn=class t extends gs{constructor(e,n){super(e),this.inserted=n}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return Ep(this,(n,r,a,s,i)=>e=e.replace(a,a+(r-n),i),!1),e}mapDesc(e,n=!1){return Op(this,e,n,!0)}invert(e){let n=this.sections.slice(),r=[];for(let a=0,s=0;a<n.length;a+=2){let i=n[a],o=n[a+1];if(o>=0){n[a]=o,n[a+1]=i;let l=a>>1;for(;r.length<l;)r.push(mt.empty);r.push(i?e.slice(s,s+i):mt.empty)}s+=i}return new t(n,r)}compose(e){return this.empty?e:e.empty?this:ck(this,e,!0)}map(e,n=!1){return e.empty?this:Op(this,e,n,!0)}iterChanges(e,n=!1){Ep(this,e,n)}get desc(){return gs.create(this.sections)}filter(e){let n=[],r=[],a=[],s=new Hi(this);e:for(let i=0,o=0;;){let l=i==e.length?1e9:e[i++];for(;o<l||o==l&&s.len==0;){if(s.done)break e;let c=Math.min(s.len,l-o);sr(a,c,-1);let d=s.ins==-1?-1:s.off==0?s.ins:0;sr(n,c,d),d>0&&Qs(r,n,s.text),s.forward(c),o+=c}let u=e[i++];for(;o<u;){if(s.done)break e;let c=Math.min(s.len,u-o);sr(n,c,-1),sr(a,c,s.ins==-1?-1:s.off==0?s.ins:0),s.forward(c),o+=c}}return{changes:new t(n,r),filtered:gs.create(a)}}toJSON(){let e=[];for(let n=0;n<this.sections.length;n+=2){let r=this.sections[n],a=this.sections[n+1];a<0?e.push(r):a==0?e.push([r]):e.push([r].concat(this.inserted[n>>1].toJSON()))}return e}static of(e,n,r){let a=[],s=[],i=0,o=null;function l(c=!1){if(!c&&!a.length)return;i<n&&sr(a,n-i,-1);let d=new t(a,s);o=o?o.compose(d.map(o)):d,a=[],s=[],i=0}function u(c){if(Array.isArray(c))for(let d of c)u(d);else if(c instanceof t){if(c.length!=n)throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${n})`);l(),o=o?o.compose(c.map(o)):c}else{let{from:d,to:f=d,insert:h}=c;if(d>f||d<0||f>n)throw new RangeError(`Invalid change range ${d} to ${f} (in doc of length ${n})`);let p=h?typeof h=="string"?mt.of(h.split(r||Fp)):h:mt.empty,g=p.length;if(d==f&&g==0)return;d<i&&l(),d>i&&sr(a,d-i,-1),sr(a,f-d,g),Qs(s,a,p),i=f}}return u(e),l(!o),o}static empty(e){return new t(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let n=[],r=[];for(let a=0;a<e.length;a++){let s=e[a];if(typeof s=="number")n.push(s,-1);else{if(!Array.isArray(s)||typeof s[0]!="number"||s.some((i,o)=>o&&typeof i!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(s.length==1)n.push(s[0],0);else{for(;r.length<a;)r.push(mt.empty);r[a]=mt.of(s.slice(1)),n.push(s[0],r[a].length)}}}return new t(n,r)}static createSet(e,n){return new t(e,n)}};function sr(t,e,n,r=!1){if(e==0&&n<=0)return;let a=t.length-2;a>=0&&n<=0&&n==t[a+1]?t[a]+=e:a>=0&&e==0&&t[a]==0?t[a+1]+=n:r?(t[a]+=e,t[a+1]+=n):t.push(e,n)}function Qs(t,e,n){if(n.length==0)return;let r=e.length-2>>1;if(r<t.length)t[t.length-1]=t[t.length-1].append(n);else{for(;t.length<r;)t.push(mt.empty);t.push(n)}}function Ep(t,e,n){let r=t.inserted;for(let a=0,s=0,i=0;i<t.sections.length;){let o=t.sections[i++],l=t.sections[i++];if(l<0)a+=o,s+=o;else{let u=a,c=s,d=mt.empty;for(;u+=o,c+=l,l&&r&&(d=d.append(r[i-2>>1])),!(n||i==t.sections.length||t.sections[i+1]<0);)o=t.sections[i++],l=t.sections[i++];e(a,u,s,c,d),a=u,s=c}}}function Op(t,e,n,r=!1){let a=[],s=r?[]:null,i=new Hi(t),o=new Hi(e);for(let l=-1;;){if(i.done&&o.len||o.done&&i.len)throw new Error("Mismatched change set lengths");if(i.ins==-1&&o.ins==-1){let u=Math.min(i.len,o.len);sr(a,u,-1),i.forward(u),o.forward(u)}else if(o.ins>=0&&(i.ins<0||l==i.i||i.off==0&&(o.len<i.len||o.len==i.len&&!n))){let u=o.len;for(sr(a,o.ins,-1);u;){let c=Math.min(i.len,u);i.ins>=0&&l<i.i&&i.len<=c&&(sr(a,0,i.ins),s&&Qs(s,a,i.text),l=i.i),i.forward(c),u-=c}o.next()}else if(i.ins>=0){let u=0,c=i.len;for(;c;)if(o.ins==-1){let d=Math.min(c,o.len);u+=d,c-=d,o.forward(d)}else if(o.ins==0&&o.len<c)c-=o.len,o.next();else break;sr(a,u,l<i.i?i.ins:0),s&&l<i.i&&Qs(s,a,i.text),l=i.i,i.forward(i.len-c)}else{if(i.done&&o.done)return s?zn.createSet(a,s):gs.create(a);throw new Error("Mismatched change set lengths")}}}function ck(t,e,n=!1){let r=[],a=n?[]:null,s=new Hi(t),i=new Hi(e);for(let o=!1;;){if(s.done&&i.done)return a?zn.createSet(r,a):gs.create(r);if(s.ins==0)sr(r,s.len,0,o),s.next();else if(i.len==0&&!i.done)sr(r,0,i.ins,o),a&&Qs(a,r,i.text),i.next();else{if(s.done||i.done)throw new Error("Mismatched change set lengths");{let l=Math.min(s.len2,i.len),u=r.length;if(s.ins==-1){let c=i.ins==-1?-1:i.off?0:i.ins;sr(r,l,c,o),a&&c&&Qs(a,r,i.text)}else i.ins==-1?(sr(r,s.off?0:s.len,l,o),a&&Qs(a,r,s.textBit(l))):(sr(r,s.off?0:s.len,i.off?0:i.ins,o),a&&!i.off&&Qs(a,r,i.text));o=(s.ins>l||i.ins>=0&&i.len>l)&&(o||r.length>u),s.forward2(l),i.forward(l)}}}}var Hi=class{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,n=this.i-2>>1;return n>=e.length?mt.empty:e[n]}textBit(e){let{inserted:n}=this.set,r=this.i-2>>1;return r>=n.length&&!e?mt.empty:n[r].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}},Ei=class t{constructor(e,n,r,a){this.from=e,this.to=n,this.flags=r,this.goalColumn=a}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get undirectional(){return(this.flags&64)>0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}map(e,n=-1){let r,a;return this.empty?r=a=e.mapPos(this.from,n):(r=e.mapPos(this.from,1),a=e.mapPos(this.to,-1)),r==this.from&&a==this.to?this:new t(r,a,this.flags,this.goalColumn)}extend(e,n=e,r=0){if(e<=this.anchor&&n>=this.anchor)return oe.range(e,n,void 0,void 0,r);let a=Math.abs(e-this.anchor)>Math.abs(n-this.anchor)?e:n;return oe.range(this.anchor,a,void 0,void 0,r)}eq(e,n=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!n||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return oe.range(e.anchor,e.head)}static create(e,n,r,a){return new t(e,n,r,a)}},oe=class t{constructor(e,n){this.ranges=e,this.mainIndex=n}map(e,n=-1){return e.empty?this:t.create(this.ranges.map(r=>r.map(e,n)),this.mainIndex)}eq(e,n=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let r=0;r<this.ranges.length;r++)if(!this.ranges[r].eq(e.ranges[r],n))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new t([this.main],0)}addRange(e,n=!0){return t.create([e].concat(this.ranges),n?0:this.mainIndex+1)}replaceRange(e,n=this.mainIndex){let r=this.ranges.slice();return r[n]=e,t.create(r,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new t(e.ranges.map(n=>Ei.fromJSON(n)),e.main)}static single(e,n=e){return new t([t.range(e,n)],0)}static create(e,n=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let r=0,a=0;a<e.length;a++){let s=e[a];if(s.empty?s.from<=r:s.from<r)return t.normalized(e.slice(),n);r=s.to}return new t(e,n)}static cursor(e,n=0,r,a){return Ei.create(e,e,(n==0?0:n<0?8:16)|(r==null?7:Math.min(6,r)),a)}static range(e,n,r,a,s){let i=a==null?7:Math.min(6,a);return!s&&e!=n&&(s=n<e?1:-1),s&&(i|=s<0?8:16),n<e?Ei.create(n,e,i|32,r):Ei.create(e,n,i,r)}static undirectionalRange(e,n){return Ei.create(e,n,64,void 0)}static normalized(e,n=0){let r=e[n];e.sort((a,s)=>a.from-s.from),n=e.indexOf(r);for(let a=1;a<e.length;a++){let s=e[a],i=e[a-1];if(s.empty?s.from<=i.to:s.from<i.to){let o=i.from,l=Math.max(s.to,i.to);a<=n&&n--,e.splice(--a,2,s.anchor>s.head?t.range(l,o):t.range(o,l))}}return new t(e,n)}};function dk(t,e){for(let n of t.ranges)if(n.to>e)throw new RangeError("Selection points outside of document")}var Vp=0,Ee=class t{constructor(e,n,r,a,s){this.combine=e,this.compareInput=n,this.compare=r,this.isStatic=a,this.id=Vp++,this.default=e([]),this.extensions=typeof s=="function"?s(this):s}get reader(){return this}static define(e={}){return new t(e.combine||(n=>n),e.compareInput||((n,r)=>n===r),e.compare||(e.combine?(n,r)=>n===r:$p),!!e.static,e.enables)}of(e){return new Go([],this,0,e)}compute(e,n){if(this.isStatic)throw new Error("Can't compute a static facet");return new Go(e,this,1,n)}computeN(e,n){if(this.isStatic)throw new Error("Can't compute a static facet");return new Go(e,this,2,n)}from(e,n){return n||(n=r=>r),this.compute([e],r=>n(r.field(e)))}};function $p(t,e){return t==e||t.length==e.length&&t.every((n,r)=>n===e[r])}var Go=class{constructor(e,n,r,a){this.dependencies=e,this.facet=n,this.type=r,this.value=a,this.id=Vp++}dynamicSlot(e){var n;let r=this.value,a=this.facet.compareInput,s=this.id,i=e[s]>>1,o=this.type==2,l=!1,u=!1,c=[];for(let d of this.dependencies)d=="doc"?l=!0:d=="selection"?u=!0:(((n=e[d.id])!==null&&n!==void 0?n:1)&1)==0&&c.push(e[d.id]);return{create(d){return d.values[i]=r(d),1},update(d,f){if(l&&f.docChanged||u&&(f.docChanged||f.selection)||Bp(d,c)){let h=r(d);if(o?!ak(h,d.values[i],a):!a(h,d.values[i]))return d.values[i]=h,1}return 0},reconfigure:(d,f)=>{let h,p=f.config.address[s];if(p!=null){let g=Rd(f,p);if(this.dependencies.every(m=>m instanceof Ee?f.facet(m)===d.facet(m):m instanceof En?f.field(m,!1)==d.field(m,!1):!0)||(o?ak(h=r(d),g,a):a(h=r(d),g)))return d.values[i]=g,0}else h=r(d);return d.values[i]=h,1}}}get extension(){return this}};function ak(t,e,n){if(t.length!=e.length)return!1;for(let r=0;r<t.length;r++)if(!n(t[r],e[r]))return!1;return!0}function Bp(t,e){let n=!1;for(let r of e)Su(t,r)&1&&(n=!0);return n}function _M(t,e,n){let r=n.map(l=>t[l.id]),a=n.map(l=>l.type),s=r.filter(l=>!(l&1)),i=t[e.id]>>1;function o(l){let u=[];for(let c=0;c<r.length;c++){let d=Rd(l,r[c]);if(a[c]==2)for(let f of d)u.push(f);else u.push(d)}return e.combine(u)}return{create(l){for(let u of r)Su(l,u);return l.values[i]=o(l),1},update(l,u){if(!Bp(l,s))return 0;let c=o(l);return e.compare(c,l.values[i])?0:(l.values[i]=c,1)},reconfigure(l,u){let c=Bp(l,r),d=u.config.facets[e.id],f=u.facet(e);if(d&&!c&&$p(n,d))return l.values[i]=f,0;let h=o(l);return e.compare(h,f)?(l.values[i]=f,0):(l.values[i]=h,1)}}}var wd=Ee.define({static:!0}),En=class t{constructor(e,n,r,a,s){this.id=e,this.createF=n,this.updateF=r,this.compareF=a,this.spec=s,this.provides=void 0}static define(e){let n=new t(Vp++,e.create,e.update,e.compare||((r,a)=>r===a),e);return e.provide&&(n.provides=e.provide(n)),n}create(e){let n=e.facet(wd).find(r=>r.field==this);return(n?.create||this.createF)(e)}slot(e){let n=e[this.id]>>1;return{create:r=>(r.values[n]=this.create(r),1),update:(r,a)=>{let s=r.values[n],i=this.updateF(s,a);return this.compareF(s,i)?0:(r.values[n]=i,1)},reconfigure:(r,a)=>{let s=r.facet(wd),i=a.facet(wd),o;return(o=s.find(l=>l.field==this))&&o!=i.find(l=>l.field==this)?(r.values[n]=o.create(r),1):a.config.address[this.id]!=null?(r.values[n]=a.field(this),0):(r.values[n]=this.create(r),1)}}}init(e){return[this,wd.of({field:this,create:e})]}get extension(){return this}},Oi={lowest:4,low:3,default:2,high:1,highest:0};function ku(t){return e=>new Ad(e,t)}var Wa={highest:ku(Oi.highest),high:ku(Oi.high),default:ku(Oi.default),low:ku(Oi.low),lowest:ku(Oi.lowest)},Ad=class{constructor(e,n){this.inner=e,this.prec=n}get extension(){return this}},Qr=class t{of(e){return new Cu(this,e)}reconfigure(e){return t.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}},Cu=class{constructor(e,n){this.compartment=e,this.inner=n}get extension(){return this}},Pd=class t{constructor(e,n,r,a,s,i){for(this.base=e,this.compartments=n,this.dynamicSlots=r,this.address=a,this.staticValues=s,this.facets=i,this.statusTemplate=[];this.statusTemplate.length<r.length;)this.statusTemplate.push(0)}staticFacet(e){let n=this.address[e.id];return n==null?e.default:this.staticValues[n>>1]}static resolve(e,n,r){let a=[],s=Object.create(null),i=new Map;for(let f of HM(e,n,i))f instanceof En?a.push(f):(s[f.facet.id]||(s[f.facet.id]=[])).push(f);let o=Object.create(null),l=[],u=[];for(let f of a)o[f.id]=u.length<<1,u.push(h=>f.slot(h));let c=r?.config.facets;for(let f in s){let h=s[f],p=h[0].facet,g=c&&c[f]||[];if(h.every(m=>m.type==0))if(o[p.id]=l.length<<1|1,$p(g,h))l.push(r.facet(p));else{let m=p.combine(h.map(x=>x.value));l.push(r&&p.compare(m,r.facet(p))?r.facet(p):m)}else{for(let m of h)m.type==0?(o[m.id]=l.length<<1|1,l.push(m.value)):(o[m.id]=u.length<<1,u.push(x=>m.dynamicSlot(x)));o[p.id]=u.length<<1,u.push(m=>_M(m,p,h))}}let d=u.map(f=>f(o));return new t(e,i,d,o,l,s)}};function HM(t,e,n){let r=[[],[],[],[],[]],a=new Map;function s(i,o){let l=a.get(i);if(l!=null){if(l<=o)return;let u=r[l].indexOf(i);u>-1&&r[l].splice(u,1),i instanceof Cu&&n.delete(i.compartment)}if(a.set(i,o),Array.isArray(i))for(let u of i)s(u,o);else if(i instanceof Cu){if(n.has(i.compartment))throw new RangeError("Duplicate use of compartment in extensions");let u=e.get(i.compartment)||i.inner;n.set(i.compartment,u),s(u,o)}else if(i instanceof Ad)s(i.inner,i.prec);else if(i instanceof En)r[o].push(i),i.provides&&s(i.provides,o);else if(i instanceof Go)r[o].push(i),i.facet.extensions&&s(i.facet.extensions,Oi.default);else{let u=i.extension;if(!u)throw new Error(`Unrecognized extension value in extension set (${i}).`);if(u==i)throw new Error(`Unrecognized extension value in extension set (${i}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);s(u,o)}}return s(t,Oi.default),r.reduce((i,o)=>i.concat(o))}function Su(t,e){if(e&1)return 2;let n=e>>1,r=t.status[n];if(r==4)throw new Error("Cyclic dependency between fields and/or facets");if(r&2)return r;t.status[n]=4;let a=t.computeSlot(t,t.config.dynamicSlots[n]);return t.status[n]=2|a}function Rd(t,e){return e&1?t.config.staticValues[e>>1]:t.values[e>>1]}var fk=Ee.define(),_p=Ee.define({combine:t=>t.some(e=>e),static:!0}),hk=Ee.define({combine:t=>t.length?t[0]:void 0,static:!0}),pk=Ee.define(),mk=Ee.define(),gk=Ee.define(),xk=Ee.define({combine:t=>t.length?t[0]:!1}),ea=class{constructor(e,n){this.type=e,this.value=n}static define(){return new Hp}},Hp=class{of(e){return new ea(this,e)}},Up=class{constructor(e){this.map=e}of(e){return new Ct(this,e)}},Ct=class t{constructor(e,n){this.type=e,this.value=n}map(e){let n=this.type.map(this.value,e);return n===void 0?void 0:n==this.value?this:new t(this.type,n)}is(e){return this.type==e}static define(e={}){return new Up(e.map||(n=>n))}static mapEffects(e,n){if(!e.length)return e;let r=[];for(let a of e){let s=a.map(n);s&&r.push(s)}return r}};Ct.reconfigure=Ct.define();Ct.appendConfig=Ct.define();var Un=class t{constructor(e,n,r,a,s,i){this.startState=e,this.changes=n,this.selection=r,this.effects=a,this.annotations=s,this.scrollIntoView=i,this._doc=null,this._state=null,r&&dk(r,n.newLength),s.some(o=>o.type==t.time)||(this.annotations=s.concat(t.time.of(Date.now())))}static create(e,n,r,a,s,i){return new t(e,n,r,a,s,i)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let n of this.annotations)if(n.type==e)return n.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let n=this.annotation(t.userEvent);return!!(n&&(n==e||n.length>e.length&&n.slice(0,e.length)==e&&n[e.length]=="."))}};Un.time=ea.define();Un.userEvent=ea.define();Un.addToHistory=ea.define();Un.remote=ea.define();function UM(t,e){let n=[];for(let r=0,a=0;;){let s,i;if(r<t.length&&(a==e.length||e[a]>=t[r]))s=t[r++],i=t[r++];else if(a<e.length)s=e[a++],i=e[a++];else return n;!n.length||n[n.length-1]<s?n.push(s,i):n[n.length-1]<i&&(n[n.length-1]=i)}}function bk(t,e,n){var r;let a,s,i;return n?(a=e.changes,s=zn.empty(e.changes.length),i=t.changes.compose(e.changes)):(a=e.changes.map(t.changes),s=t.changes.mapDesc(e.changes,!0),i=t.changes.compose(a)),{changes:i,selection:e.selection?e.selection.map(s):(r=t.selection)===null||r===void 0?void 0:r.map(a),effects:Ct.mapEffects(t.effects,a).concat(Ct.mapEffects(e.effects,s)),annotations:t.annotations.length?t.annotations.concat(e.annotations):e.annotations,scrollIntoView:t.scrollIntoView||e.scrollIntoView}}function Gp(t,e,n){let r=e.selection,a=zo(e.annotations);return e.userEvent&&(a=a.concat(Un.userEvent.of(e.userEvent))),{changes:e.changes instanceof zn?e.changes:zn.of(e.changes||[],n,t.facet(hk)),selection:r&&(r instanceof oe?r:oe.single(r.anchor,r.head)),effects:zo(e.effects),annotations:a,scrollIntoView:!!e.scrollIntoView}}function yk(t,e,n){let r=Gp(t,e.length?e[0]:{},t.doc.length);e.length&&e[0].filter===!1&&(n=!1);for(let s=1;s<e.length;s++){e[s].filter===!1&&(n=!1);let i=!!e[s].sequential;r=bk(r,Gp(t,e[s],i?r.changes.newLength:t.doc.length),i)}let a=Un.create(t,r.changes,r.selection,r.effects,r.annotations,r.scrollIntoView);return zM(n?GM(a):a)}function GM(t){let e=t.startState,n=!0;for(let a of e.facet(pk)){let s=a(t);if(s===!1){n=!1;break}Array.isArray(s)&&(n=n===!0?s:UM(n,s))}if(n!==!0){let a,s;if(n===!1)s=t.changes.invertedDesc,a=zn.empty(e.doc.length);else{let i=t.changes.filter(n);a=i.changes,s=i.filtered.mapDesc(i.changes).invertedDesc}t=Un.create(e,a,t.selection&&t.selection.map(s),Ct.mapEffects(t.effects,s),t.annotations,t.scrollIntoView)}let r=e.facet(mk);for(let a=r.length-1;a>=0;a--){let s=r[a](t);s instanceof Un?t=s:Array.isArray(s)&&s.length==1&&s[0]instanceof Un?t=s[0]:t=yk(e,zo(s),!1)}return t}function zM(t){let e=t.startState,n=e.facet(gk),r=t;for(let a=n.length-1;a>=0;a--){let s=n[a](t);s&&Object.keys(s).length&&(r=bk(r,Gp(e,s,t.changes.newLength),!0))}return r==t?t:Un.create(e,t.changes,t.selection,r.effects,r.annotations,r.scrollIntoView)}var WM=[];function zo(t){return t==null?WM:Array.isArray(t)?t:[t]}var ya=(function(t){return t[t.Word=0]="Word",t[t.Space=1]="Space",t[t.Other=2]="Other",t})(ya||(ya={})),jM=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,zp;try{zp=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function qM(t){if(zp)return zp.test(t);for(let e=0;e<t.length;e++){let n=t[e];if(/\w/.test(n)||n>"\x80"&&(n.toUpperCase()!=n.toLowerCase()||jM.test(n)))return!0}return!1}function VM(t){return e=>{if(!/\S/.test(e))return ya.Space;if(qM(e))return ya.Word;for(let n=0;n<t.length;n++)if(e.indexOf(t[n])>-1)return ya.Word;return ya.Other}}var Dt=class t{constructor(e,n,r,a,s,i){this.config=e,this.doc=n,this.selection=r,this.values=a,this.status=e.statusTemplate.slice(),this.computeSlot=s,i&&(i._state=this);for(let o=0;o<this.config.dynamicSlots.length;o++)Su(this,o<<1);this.computeSlot=null}field(e,n=!0){let r=this.config.address[e.id];if(r==null){if(n)throw new RangeError("Field is not present in this state");return}return Su(this,r),Rd(this,r)}update(...e){return yk(this,e,!0)}applyTransaction(e){let n=this.config,{base:r,compartments:a}=n;for(let o of e.effects)o.is(Qr.reconfigure)?(n&&(a=new Map,n.compartments.forEach((l,u)=>a.set(u,l)),n=null),a.set(o.value.compartment,o.value.extension)):o.is(Ct.reconfigure)?(n=null,r=o.value):o.is(Ct.appendConfig)&&(n=null,r=zo(r).concat(o.value));let s;n?s=e.startState.values.slice():(n=Pd.resolve(r,a,this),s=new t(n,this.doc,this.selection,n.dynamicSlots.map(()=>null),(l,u)=>u.reconfigure(l,this),null).values);let i=e.startState.facet(_p)?e.newSelection:e.newSelection.asSingle();new t(n,e.newDoc,i,s,(o,l)=>l.update(o,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(n=>({changes:{from:n.from,to:n.to,insert:e},range:oe.cursor(n.from+e.length,-1)}))}changeByRange(e){let n=this.selection,r=e(n.ranges[0]),a=this.changes(r.changes),s=[r.range],i=zo(r.effects);for(let o=1;o<n.ranges.length;o++){let l=e(n.ranges[o]),u=this.changes(l.changes),c=u.map(a);for(let f=0;f<o;f++)s[f]=s[f].map(c);let d=a.mapDesc(u,!0);s.push(l.range.map(d)),a=a.compose(c),i=Ct.mapEffects(i,c).concat(Ct.mapEffects(zo(l.effects),d))}return{changes:a,selection:oe.create(s,n.mainIndex),effects:i}}changes(e=[]){return e instanceof zn?e:zn.of(e,this.doc.length,this.facet(t.lineSeparator))}toText(e){return mt.of(e.split(this.facet(t.lineSeparator)||Fp))}sliceDoc(e=0,n=this.doc.length){return this.doc.sliceString(e,n,this.lineBreak)}facet(e){let n=this.config.address[e.id];return n==null?e.default:(Su(this,n),Rd(this,n))}toJSON(e){let n={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let r in e){let a=e[r];a instanceof En&&this.config.address[a.id]!=null&&(n[r]=a.spec.toJSON(this.field(e[r]),this))}return n}static fromJSON(e,n={},r){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let a=[];if(r){for(let s in r)if(Object.prototype.hasOwnProperty.call(e,s)){let i=r[s],o=e[s];a.push(i.init(l=>i.spec.fromJSON(o,l)))}}return t.create({doc:e.doc,selection:oe.fromJSON(e.selection),extensions:n.extensions?a.concat([n.extensions]):a})}static create(e={}){let n=Pd.resolve(e.extensions||[],new Map),r=e.doc instanceof mt?e.doc:mt.of((e.doc||"").split(n.staticFacet(t.lineSeparator)||Fp)),a=e.selection?e.selection instanceof oe?e.selection:oe.single(e.selection.anchor,e.selection.head):oe.single(0);return dk(a,r.length),n.staticFacet(_p)||(a=a.asSingle()),new t(n,r,a,n.dynamicSlots.map(()=>null),(s,i)=>i.create(s),null)}get tabSize(){return this.facet(t.tabSize)}get lineBreak(){return this.facet(t.lineSeparator)||`
|
|
36
|
+
`}get readOnly(){return this.facet(xk)}phrase(e,...n){for(let r of this.facet(t.phrases))if(Object.prototype.hasOwnProperty.call(r,e)){e=r[e];break}return n.length&&(e=e.replace(/\$(\$|\d*)/g,(r,a)=>{if(a=="$")return"$";let s=+(a||1);return!s||s>n.length?r:n[s-1]})),e}languageDataAt(e,n,r=-1){let a=[];for(let s of this.facet(fk))for(let i of s(this,n,r))Object.prototype.hasOwnProperty.call(i,e)&&a.push(i[e]);return a}charCategorizer(e){let n=this.languageDataAt("wordChars",e);return VM(n.length?n[0]:"")}wordAt(e){let{text:n,from:r,length:a}=this.doc.lineAt(e),s=this.charCategorizer(e),i=e-r,o=e-r;for(;i>0;){let l=Gn(n,i,!1);if(s(n.slice(l,i))!=ya.Word)break;i=l}for(;o<a;){let l=Gn(n,o);if(s(n.slice(o,l))!=ya.Word)break;o=l}return i==o?null:oe.range(i+r,o+r)}};Dt.allowMultipleSelections=_p;Dt.tabSize=Ee.define({combine:t=>t.length?t[0]:4});Dt.lineSeparator=hk;Dt.readOnly=xk;Dt.phrases=Ee.define({compare(t,e){let n=Object.keys(t),r=Object.keys(e);return n.length==r.length&&n.every(a=>t[a]==e[a])}});Dt.languageData=fk;Dt.changeFilter=pk;Dt.transactionFilter=mk;Dt.transactionExtender=gk;Qr.reconfigure=Ct.define();function jo(t,e,n={}){let r={};for(let a of t)for(let s of Object.keys(a)){let i=a[s],o=r[s];if(o===void 0)r[s]=i;else if(!(o===i||i===void 0))if(Object.hasOwnProperty.call(n,s))r[s]=n[s](o,i);else throw new Error("Config merge conflict for field "+s)}for(let a in e)r[a]===void 0&&(r[a]=e[a]);return r}var za=class{eq(e){return this==e}range(e,n=e){return Iu.create(e,n,this)}};za.prototype.startSide=za.prototype.endSide=0;za.prototype.point=!1;za.prototype.mapMode=Ar.TrackDel;function Kp(t,e){return t==e||t.constructor==e.constructor&&t.eq(e)}var Iu=class t{constructor(e,n,r){this.from=e,this.to=n,this.value=r}static create(e,n,r){return new t(e,n,r)}};function Wp(t,e){return t.from-e.from||t.value.startSide-e.value.startSide}var jp=class t{constructor(e,n,r,a){this.from=e,this.to=n,this.value=r,this.maxPoint=a}get length(){return Ho(this.to)}findIndex(e,n,r,a=0){let s=r?this.to:this.from;for(let i=a,o=s.length;;){if(i==o)return i;let l=i+o>>1,u=s[l]-e||(r?this.value[l].endSide:this.value[l].startSide)-n;if(l==i)return u>=0?i:o;u>=0?o=l:i=l+1}}between(e,n,r,a){for(let s=this.findIndex(n,-1e9,!0),i=this.findIndex(r,1e9,!1,s);s<i;s++)if(a(this.from[s]+e,this.to[s]+e,this.value[s])===!1)return!1}map(e,n,r,a,s){let i=[],o=[],l=[],u=-1,c=-1;e:for(let d=0;d<this.value.length;d++){let f=this.value[d],h=this.from[d]+e,p=this.to[d]+e,g,m;if(h==p){let x=n.mapPos(h,f.startSide,f.mapMode);if(x==null||(g=m=x,f.startSide!=f.endSide&&(m=n.mapPos(h,f.endSide),m<g)))continue}else if(g=n.mapPos(h,f.startSide),m=n.mapPos(p,f.endSide),g>m||g==m&&f.startSide>0&&f.endSide<=0)continue;if(!((m-g||f.endSide-f.startSide)<0))if(u<0&&(u=g),f.point&&(c=Math.max(c,m-g)),(g-r||f.startSide-a)>=0)i.push(f),o.push(g-u),l.push(m-u),r=m,a=f.endSide;else{if(g==m)for(let x=i.length;x>0;x--){if((g-(l[x-1]+u)||f.startSide-i[x-1].endSide)>=0){i.splice(x,0,f),o.splice(x,0,g-u),l.splice(x,0,m-u);continue e}if((g-(o[x-1]+u)||f.endSide-i[x-1].startSide)>0)break}s(g,m,f)}}return{mapped:i.length?new t(o,l,i,c):null,pos:u}}},Pt=class t{constructor(e,n,r,a){this.chunkPos=e,this.chunk=n,this.nextLayer=r,this.maxPoint=a}static create(e,n,r,a){return new t(e,n,r,a)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let n of this.chunk)e+=n.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:n=[],sort:r=!1,filterFrom:a=0,filterTo:s=this.length}=e,i=e.filter;if(n.length==0&&!i)return this;if(r&&(n=n.slice().sort(Wp)),this.isEmpty)return n.length?t.of(n):this;let o=new Nd(this,null,-1).goto(0),l=0,u=[],c=new ir;for(;o.value||l<n.length;)if(l<n.length&&(o.from-n[l].from||o.startSide-n[l].value.startSide)>=0){let d=n[l++];c.addInner(d.from,d.to,d.value,!1)||u.push(d)}else o.rangeIndex==1&&o.chunkIndex<this.chunk.length&&(l==n.length||this.chunkEnd(o.chunkIndex)<n[l].from)&&(!i||a>this.chunkEnd(o.chunkIndex)||s<this.chunkPos[o.chunkIndex])&&c.addChunk(this.chunkPos[o.chunkIndex],this.chunk[o.chunkIndex])?o.nextChunk():((!i||a>o.to||s<o.from||i(o.from,o.to,o.value))&&(c.addInner(o.from,o.to,o.value,!1)||u.push(Iu.create(o.from,o.to,o.value))),o.next());return c.finishInner(this.nextLayer.isEmpty&&!u.length?t.empty:this.nextLayer.update({add:u,filter:i,filterFrom:a,filterTo:s}))}map(e){if(e.empty||this.isEmpty)return this;let n=[],r=[],a=-1,s,i=(l,u,c)=>{s||(s=new ir),s.addRange(l,u,c,!1)};for(let l=0;l<this.chunk.length;l++){let u=this.chunkPos[l],c=this.chunk[l],d=e.touchesRange(u,u+c.length);if(d===!1)a=Math.max(a,c.maxPoint),n.push(c),r.push(e.mapPos(u));else if(d===!0){let[f,h]=n.length?[Ho(r)+Ho(n).length,Ho(Ho(n).value).endSide]:[-1,-1],{mapped:p,pos:g}=c.map(u,e,f,h,i);p&&(a=Math.max(a,p.maxPoint),n.push(p),r.push(g))}}let o=this.nextLayer.map(e);return s&&(o=s.finishInner(o)),n.length==0?o:new t(r,n,o||t.empty,a)}between(e,n,r){if(!this.isEmpty){for(let a=0;a<this.chunk.length;a++){let s=this.chunkPos[a],i=this.chunk[a];if(n>=s&&e<=s+i.length&&i.between(s,e-s,n-s,r)===!1)return}this.nextLayer.between(e,n,r)}}iter(e=0){return Lu.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,n=0){return Lu.from(e).goto(n)}static compare(e,n,r,a,s=-1){let i=e.filter(d=>d.maxPoint>0||!d.isEmpty&&d.maxPoint>=s),o=n.filter(d=>d.maxPoint>0||!d.isEmpty&&d.maxPoint>=s),l=sk(i,o,r),u=new Bi(i,l,s),c=new Bi(o,l,s);r.iterGaps((d,f,h)=>ik(u,d,c,f,h,a)),r.empty&&r.length==0&&ik(u,0,c,0,0,a)}static eq(e,n,r=0,a){a==null&&(a=999999999);let s=e.filter(c=>!c.isEmpty&&n.indexOf(c)<0),i=n.filter(c=>!c.isEmpty&&e.indexOf(c)<0);if(s.length!=i.length)return!1;if(!s.length)return!0;let o=sk(s,i),l=new Bi(s,o,0).goto(r),u=new Bi(i,o,0).goto(r);for(;;){if(l.to!=u.to||!qp(l.active,u.active)||l.point&&(!u.point||!Kp(l.point,u.point)))return!1;if(l.to>a)return!0;l.next(),u.next()}}static spans(e,n,r,a,s=-1){let i=new Bi(e,null,s).goto(n),o=n,l=i.openStart;for(;;){let u=Math.min(i.to,r);if(i.point){let c=i.activeForPoint(i.to),d=i.pointFrom<n?c.length+1:i.point.startSide<0?c.length:Math.min(c.length,l);a.point(o,u,i.point,c,d,i.pointRank),l=Math.min(i.openEnd(u),c.length)}else u>o&&(a.span(o,u,i.active,l),l=i.openEnd(u));if(i.to>r)return l+(i.point&&i.to>r?1:0);o=i.to,i.next()}}static of(e,n=!1){let r=new ir;for(let a of e instanceof Iu?[e]:n?$M(e):e)r.add(a.from,a.to,a.value);return r.finish()}static join(e){if(!e.length)return t.empty;let n=Ho(e);for(let r=e.length-2;r>=0;r--)for(let a=e[r];a!=t.empty;a=a.nextLayer)n=new t(a.chunkPos,a.chunk,n,Math.max(a.maxPoint,n.maxPoint));return n}};Pt.empty=new Pt([],[],null,-1);function Ho(t){return t[t.length-1]}function $M(t){if(t.length>1)for(let e=t[0],n=1;n<t.length;n++){let r=t[n];if(Wp(e,r)>0)return t.slice().sort(Wp);e=r}return t}Pt.empty.nextLayer=Pt.empty;var ir=class t{finishChunk(e){this.chunks.push(new jp(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(e,n,r){this.addRange(e,n,r,!0)}addRange(e,n,r,a){this.addInner(e,n,r,a)||(this.nextLayer||(this.nextLayer=new t)).addRange(e,n,r,a)}addInner(e,n,r,a){let s=e-this.lastTo||r.startSide-this.last.endSide;if(a&&s<=0&&(e-this.lastFrom||r.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return s<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(n-this.chunkStart),this.last=r,this.lastFrom=e,this.lastTo=n,this.value.push(r),r.point&&(this.maxPoint=Math.max(this.maxPoint,n-e)),!0)}addChunk(e,n){if((e-this.lastTo||n.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,n.maxPoint),this.chunks.push(n),this.chunkPos.push(e);let r=n.value.length-1;return this.last=n.value[r],this.lastFrom=n.from[r]+e,this.lastTo=n.to[r]+e,!0}finish(){return this.finishInner(Pt.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let n=Pt.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,n}};function sk(t,e,n){let r=new Map;for(let s of t)for(let i=0;i<s.chunk.length;i++)s.chunk[i].maxPoint<=0&&r.set(s.chunk[i],s.chunkPos[i]);let a=new Set;for(let s of e)for(let i=0;i<s.chunk.length;i++){let o=r.get(s.chunk[i]);o!=null&&(n?n.mapPos(o):o)==s.chunkPos[i]&&!n?.touchesRange(o,o+s.chunk[i].length)&&a.add(s.chunk[i])}return a}var Nd=class{constructor(e,n,r,a=0){this.layer=e,this.skip=n,this.minPoint=r,this.rank=a}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,n=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,n,!1),this}gotoInner(e,n,r){for(;this.chunkIndex<this.layer.chunk.length;){let a=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(a)||this.layer.chunkEnd(this.chunkIndex)<e||a.maxPoint<this.minPoint))break;this.chunkIndex++,r=!1}if(this.chunkIndex<this.layer.chunk.length){let a=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],n,!0);(!r||this.rangeIndex<a)&&this.setRangeIndex(a)}this.next()}forward(e,n){(this.to-e||this.endSide-n)<0&&this.gotoInner(e,n,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],n=this.layer.chunk[this.chunkIndex],r=e+n.from[this.rangeIndex];if(this.from=r,this.to=e+n.to[this.rangeIndex],this.value=n.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}},Lu=class t{constructor(e){this.heap=e}static from(e,n=null,r=-1){let a=[];for(let s=0;s<e.length;s++)for(let i=e[s];!i.isEmpty;i=i.nextLayer)i.maxPoint>=r&&a.push(new Nd(i,n,r,s));return a.length==1?a[0]:new t(a)}get startSide(){return this.value?this.value.startSide:0}goto(e,n=-1e9){for(let r of this.heap)r.goto(e,n);for(let r=this.heap.length>>1;r>=0;r--)Tp(this.heap,r);return this.next(),this}forward(e,n){for(let r of this.heap)r.forward(e,n);for(let r=this.heap.length>>1;r>=0;r--)Tp(this.heap,r);(this.to-e||this.value.endSide-n)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),Tp(this.heap,0)}}};function Tp(t,e){for(let n=t[e];;){let r=(e<<1)+1;if(r>=t.length)break;let a=t[r];if(r+1<t.length&&a.compare(t[r+1])>=0&&(a=t[r+1],r++),n.compare(a)<0)break;t[r]=n,t[e]=a,e=r}}var Bi=class{constructor(e,n,r){this.minPoint=r,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=Lu.from(e,n,r)}goto(e,n=-1e9){return this.cursor.goto(e,n),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=n,this.openStart=-1,this.next(),this}forward(e,n){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-n)<0;)this.removeActive(this.minActive);this.cursor.forward(e,n)}removeActive(e){kd(this.active,e),kd(this.activeTo,e),kd(this.activeRank,e),this.minActive=ok(this.active,this.activeTo)}addActive(e){let n=0,{value:r,to:a,rank:s}=this.cursor;for(;n<this.activeRank.length&&(s-this.activeRank[n]||a-this.activeTo[n])>0;)n++;Sd(this.active,n,r),Sd(this.activeTo,n,a),Sd(this.activeRank,n,s),e&&Sd(e,n,this.cursor.from),this.minActive=ok(this.active,this.activeTo)}next(){let e=this.to,n=this.point;this.point=null;let r=this.openStart<0?[]:null;for(;;){let a=this.minActive;if(a>-1&&(this.activeTo[a]-this.cursor.from||this.active[a].endSide-this.cursor.startSide)<0){if(this.activeTo[a]>e){this.to=this.activeTo[a],this.endSide=this.active[a].endSide;break}this.removeActive(a),r&&kd(r,a)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let s=this.cursor.value;if(!s.point)this.addActive(r),this.cursor.next();else if(n&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=s,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=s.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(r){this.openStart=0;for(let a=r.length-1;a>=0&&r[a]<e;a--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let n=[];for(let r=this.active.length-1;r>=0&&!(this.activeRank[r]<this.pointRank);r--)(this.activeTo[r]>e||this.activeTo[r]==e&&this.active[r].endSide>=this.point.endSide)&&n.push(this.active[r]);return n.reverse()}openEnd(e){let n=0;for(let r=this.activeTo.length-1;r>=0&&this.activeTo[r]>e;r--)n++;return n}};function ik(t,e,n,r,a,s){t.goto(e),n.goto(r);let i=r+a,o=r,l=r-e,u=!!s.boundChange;for(let c=!1;;){let d=t.to+l-n.to,f=d||t.endSide-n.endSide,h=f<0?t.to+l:n.to,p=Math.min(h,i);if(t.point||n.point?(t.point&&n.point&&Kp(t.point,n.point)&&qp(t.activeForPoint(t.to),n.activeForPoint(n.to))||s.comparePoint(o,p,t.point,n.point),c=!1):(c&&(s.boundChange(o),c=!1),p>o&&!qp(t.active,n.active)&&s.compareRange(o,p,t.active,n.active),u&&p<i&&(d||t.openEnd(h)!=n.openEnd(h))&&(c=!0)),h>i)break;o=h,f<=0&&t.next(),f>=0&&n.next()}}function qp(t,e){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!=e[n]&&!Kp(t[n],e[n]))return!1;return!0}function kd(t,e){for(let n=e,r=t.length-1;n<r;n++)t[n]=t[n+1];t.pop()}function Sd(t,e,n){for(let r=t.length-1;r>=e;r--)t[r+1]=t[r];t[e]=n}function ok(t,e){let n=-1,r=1e9;for(let a=0;a<e.length;a++)(e[a]-r||t[a].endSide-t[n].endSide)<0&&(n=a,r=e[a]);return n}function Ui(t,e,n=t.length){let r=0;for(let a=0;a<n&&a<t.length;)t.charCodeAt(a)==9?(r+=e-r%e,a++):(r++,a=Gn(t,a));return r}function vk(t,e,n,r){for(let a=0,s=0;;){if(s>=e)return a;if(a==t.length)break;s+=t.charCodeAt(a)==9?n-s%n:1,a=Gn(t,a)}return r===!0?-1:t.length}var wk=typeof Symbol>"u"?"__\u037C":Symbol.for("\u037C"),Xp=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),kk=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{},Pr=class{constructor(e,n){this.rules=[];let{finish:r}=n||{};function a(i){return/^@/.test(i)?[i]:i.split(/,\s*/)}function s(i,o,l,u){let c=[],d=/^@(\w+)\b/.exec(i[0]),f=d&&d[1]=="keyframes";if(d&&o==null)return l.push(i[0]+";");for(let h in o){let p=o[h];if(/&/.test(h))s(h.split(/,\s*/).map(g=>i.map(m=>g.replace(/&/,m))).reduce((g,m)=>g.concat(m)),p,l);else if(p&&typeof p=="object"){if(!d)throw new RangeError("The value of a property ("+h+") should be a primitive value.");s(a(h),p,c,f)}else p!=null&&c.push(h.replace(/_.*/,"").replace(/[A-Z]/g,g=>"-"+g.toLowerCase())+": "+p+";")}(c.length||f)&&l.push((r&&!d&&!u?i.map(r):i).join(", ")+" {"+c.join(" ")+"}")}for(let i in e)s(a(i),e[i],this.rules)}getRules(){return this.rules.join(`
|
|
37
|
+
`)}static newName(){let e=kk[wk]||1;return kk[wk]=e+1,"\u037C"+e.toString(36)}static mount(e,n,r){let a=e[Xp],s=r&&r.nonce;a?s&&a.setNonce(s):a=new Yp(e,s),a.mount(Array.isArray(n)?n:[n],e)}},Sk=new Map,Yp=class{constructor(e,n){let r=e.ownerDocument||e,a=r.defaultView;if(!e.head&&e.adoptedStyleSheets&&a.CSSStyleSheet){let s=Sk.get(r);if(s)return e[Xp]=s;this.sheet=new a.CSSStyleSheet,Sk.set(r,this)}else this.styleTag=r.createElement("style"),n&&this.styleTag.setAttribute("nonce",n);this.modules=[],e[Xp]=this}mount(e,n){let r=this.sheet,a=0,s=0,i=!1;for(let o=0;o<e.length;o++){let l=e[o],u=this.modules.indexOf(l);if(u<s&&u>-1&&(this.modules.splice(u,1),i=!0,s--,u=-1),u==-1){if(this.modules.splice(s++,0,l),i=!0,r)for(let c=0;c<l.rules.length;c++)r.insertRule(l.rules[c],a++)}else{for(;s<u;)a+=this.modules[s++].rules.length;a+=l.rules.length,s++}}if(r)n.adoptedStyleSheets.indexOf(this.sheet)<0&&(n.adoptedStyleSheets=[this.sheet,...n.adoptedStyleSheets]);else{if(i){let l="";for(let u=0;u<this.modules.length;u++)l+=this.modules[u].getRules()+`
|
|
38
|
+
`;this.styleTag.textContent=l}let o=n.head||n;this.styleTag.parentNode!=o&&o.insertBefore(this.styleTag,o.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}};var xs={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},qo={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},KM=typeof navigator<"u"&&/Mac/.test(navigator.platform),XM=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(Pn=0;Pn<10;Pn++)xs[48+Pn]=xs[96+Pn]=String(Pn);var Pn;for(Pn=1;Pn<=24;Pn++)xs[Pn+111]="F"+Pn;var Pn;for(Pn=65;Pn<=90;Pn++)xs[Pn]=String.fromCharCode(Pn+32),qo[Pn]=String.fromCharCode(Pn);var Pn;for(Md in xs)qo.hasOwnProperty(Md)||(qo[Md]=xs[Md]);var Md;function Ck(t){var e=KM&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||XM&&t.shiftKey&&t.key&&t.key.length==1||t.key=="Unidentified",n=!e&&t.key||(t.shiftKey?qo:xs)[t.keyCode]||t.key||"Unidentified";return n=="Esc"&&(n="Escape"),n=="Del"&&(n="Delete"),n=="Left"&&(n="ArrowLeft"),n=="Up"&&(n="ArrowUp"),n=="Right"&&(n="ArrowRight"),n=="Down"&&(n="ArrowDown"),n}var gr=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},rm=typeof document<"u"?document:{documentElement:{style:{}}},am=/Edge\/(\d+)/.exec(gr.userAgent),nS=/MSIE \d/.test(gr.userAgent),sm=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(gr.userAgent),nf=!!(nS||sm||am),Ik=!nf&&/gecko\/(\d+)/i.test(gr.userAgent),Jp=!nf&&/Chrome\/(\d+)/.exec(gr.userAgent),Lk="webkitFontSmoothing"in rm.documentElement.style,im=!nf&&/Apple Computer/.test(gr.vendor),Ak=im&&(/Mobile\/\w+/.test(gr.userAgent)||gr.maxTouchPoints>2),Ie={mac:Ak||/Mac/.test(gr.platform),windows:/Win/.test(gr.platform),linux:/Linux|X11/.test(gr.platform),ie:nf,ie_version:nS?rm.documentMode||6:sm?+sm[1]:am?+am[1]:0,gecko:Ik,gecko_version:Ik?+(/Firefox\/(\d+)/.exec(gr.userAgent)||[0,0])[1]:0,chrome:!!Jp,chrome_version:Jp?+Jp[1]:0,ios:Ak,android:/Android\b/.test(gr.userAgent),webkit:Lk,webkit_version:Lk?+(/\bAppleWebKit\/(\d+)/.exec(gr.userAgent)||[0,0])[1]:0,safari:im,safari_version:im?+(/\bVersion\/(\d+(\.\d+)?)/.exec(gr.userAgent)||[0,0])[1]:0,tabSize:rm.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function $m(t,e){for(let n in t)n=="class"&&e.class?e.class+=" "+t.class:n=="style"&&e.style?e.style+=";"+t.style:e[n]=t[n];return e}var zd=Object.create(null);function Km(t,e,n){if(t==e)return!0;t||(t=zd),e||(e=zd);let r=Object.keys(t),a=Object.keys(e);if(r.length-(n&&r.indexOf(n)>-1?1:0)!=a.length-(n&&a.indexOf(n)>-1?1:0))return!1;for(let s of r)if(s!=n&&(a.indexOf(s)==-1||t[s]!==e[s]))return!1;return!0}function YM(t,e){for(let n=t.attributes.length-1;n>=0;n--){let r=t.attributes[n].name;e[r]==null&&t.removeAttribute(r)}for(let n in e){let r=e[n];n=="style"?t.style.cssText=r:t.getAttribute(n)!=r&&t.setAttribute(n,r)}}function Pk(t,e,n){let r=!1;if(e)for(let a in e)n&&a in n||(r=!0,a=="style"?t.style.cssText="":t.removeAttribute(a));if(n)for(let a in n)e&&e[a]==n[a]||(r=!0,a=="style"?t.style.cssText=n[a]:t.setAttribute(a,n[a]));return r}function JM(t){let e=Object.create(null);for(let n=0;n<t.attributes.length;n++){let r=t.attributes[n];e[r.name]=r.value}return e}var zr=class{eq(e){return!1}updateDOM(e,n,r){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,n,r){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}},Xn=(function(t){return t[t.Text=0]="Text",t[t.WidgetBefore=1]="WidgetBefore",t[t.WidgetAfter=2]="WidgetAfter",t[t.WidgetRange=3]="WidgetRange",t})(Xn||(Xn={})),Ze=class extends za{constructor(e,n,r,a){super(),this.startSide=e,this.endSide=n,this.widget=r,this.spec=a}get heightRelevant(){return!1}static mark(e){return new Hu(e)}static widget(e){let n=Math.max(-1e4,Math.min(1e4,e.side||0)),r=!!e.block;return n+=r&&!e.inlineOrder?n>0?3e8:-4e8:n>0?1e8:-1e8,new ji(e,n,n,r,e.widget||null,!1)}static replace(e){let n=!!e.block,r,a;if(e.isBlockGap)r=-5e8,a=4e8;else{let{start:s,end:i}=rS(e,n);r=(s?n?-3e8:-1:5e8)-1,a=(i?n?2e8:1:-6e8)+1}return new ji(e,r,a,n,e.widget||null,!0)}static line(e){return new Uu(e)}static set(e,n=!1){return Pt.of(e,n)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}};Ze.none=Pt.empty;var Hu=class t extends Ze{constructor(e){let{start:n,end:r}=rS(e);super(n?-1:5e8,r?1:-6e8,null,e),this.tagName=e.tagName||"span",this.attrs=e.class&&e.attributes?$m(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||zd}eq(e){return this==e||e instanceof t&&this.tagName==e.tagName&&Km(this.attrs,e.attrs)}range(e,n=e){if(e>=n)throw new RangeError("Mark decorations may not be empty");return super.range(e,n)}};Hu.prototype.point=!1;var Uu=class t extends Ze{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof t&&this.spec.class==e.spec.class&&Km(this.spec.attributes,e.spec.attributes)}range(e,n=e){if(n!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,n)}};Uu.prototype.mapMode=Ar.TrackBefore;Uu.prototype.point=!0;var ji=class t extends Ze{constructor(e,n,r,a,s,i){super(n,r,s,e),this.block=a,this.isReplace=i,this.mapMode=a?n<=0?Ar.TrackBefore:Ar.TrackAfter:Ar.TrackDel}get type(){return this.startSide!=this.endSide?Xn.WidgetRange:this.startSide<=0?Xn.WidgetBefore:Xn.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof t&&ZM(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}range(e,n=e){if(this.isReplace&&(e>n||e==n&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&n!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,n)}};ji.prototype.point=!0;function rS(t,e=!1){let{inclusiveStart:n,inclusiveEnd:r}=t;return n==null&&(n=t.inclusive),r==null&&(r=t.inclusive),{start:n??e,end:r??e}}function ZM(t,e){return t==e||!!(t&&e&&t.compare(e))}function Yo(t,e,n,r=0){let a=n.length-1;a>=0&&n[a]+r>=t?n[a]=Math.max(n[a],e):n.push(t,e)}var Wd=class t extends za{constructor(e,n,r){super(),this.tagName=e,this.attributes=n,this.rank=r}eq(e){return e==this||e instanceof t&&this.tagName==e.tagName&&Km(this.attributes,e.attributes)}static create(e){return new t(e.tagName,e.attributes||zd,e.rank==null?50:Math.max(0,Math.min(e.rank,100)))}static set(e,n=!1){return Pt.of(e,n)}};Wd.prototype.startSide=Wd.prototype.endSide=-1;function Gu(t){let e;return t.nodeType==11?e=t.getSelection?t:t.ownerDocument:e=t,e.getSelection()}function om(t,e){return e?t==e||t.contains(e.nodeType!=1?e.parentNode:e):!1}function Ru(t,e){if(!e.anchorNode)return!1;try{return om(t,e.anchorNode)}catch{return!1}}function Nu(t){return t.nodeType==3?Wu(t,0,t.nodeValue.length).getClientRects():t.nodeType==1?t.getClientRects():[]}function Mu(t,e,n,r){return n?Rk(t,e,n,r,-1)||Rk(t,e,n,r,1):!1}function ni(t){for(var e=0;;e++)if(t=t.previousSibling,!t)return e}function jd(t){return t.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(t.nodeName)}function Rk(t,e,n,r,a){for(;;){if(t==n&&e==r)return!0;if(e==(a<0?0:vs(t))){if(t.nodeName=="DIV")return!1;let s=t.parentNode;if(!s||s.nodeType!=1)return!1;e=ni(t)+(a<0?0:1),t=s}else if(t.nodeType==1){if(t=t.childNodes[e+(a<0?-1:0)],t.nodeType==1&&t.contentEditable=="false")return!1;e=a<0?vs(t):0}else return!1}}function vs(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function zu(t,e){let{left:n,right:r}=t;if(n==r)return t;let a=e?n:r;return{left:a,right:a,top:t.top,bottom:t.bottom}}function QM(t){let e=t.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.innerWidth,top:0,bottom:t.innerHeight}}function aS(t,e){let n=e.width/t.offsetWidth,r=e.height/t.offsetHeight;return(n>.995&&n<1.005||!isFinite(n)||Math.abs(e.width-t.offsetWidth)<1)&&(n=1),(r>.995&&r<1.005||!isFinite(r)||Math.abs(e.height-t.offsetHeight)<1)&&(r=1),{scaleX:n,scaleY:r}}function eT(t,e,n,r,a,s,i,o){let l=t.ownerDocument,u=l.defaultView||window;for(let c=t,d=!1;c&&!d;)if(c.nodeType==1){let f,h=c==l.body,p=1,g=1;if(h)f=QM(u);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(d=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let b=c.getBoundingClientRect();({scaleX:p,scaleY:g}=aS(c,b)),f={left:b.left,right:b.left+c.clientWidth*p,top:b.top,bottom:b.top+c.clientHeight*g}}let m=0,x=0;if(a=="nearest")e.top<f.top+i?(x=e.top-(f.top+i),n>0&&e.bottom>f.bottom+x&&(x=e.bottom-f.bottom+i)):e.bottom>f.bottom-i&&(x=e.bottom-f.bottom+i,n<0&&e.top-x<f.top&&(x=e.top-(f.top+i)));else{let b=e.bottom-e.top,y=f.bottom-f.top;x=(a=="center"&&b<=y?e.top+b/2-y/2:a=="start"||a=="center"&&n<0?e.top-i:e.bottom-y+i)-f.top}if(r=="nearest"?e.left<f.left+s?(m=e.left-(f.left+s),n>0&&e.right>f.right+m&&(m=e.right-f.right+s)):e.right>f.right-s&&(m=e.right-f.right+s,n<0&&e.left<f.left+m&&(m=e.left-(f.left+s))):m=(r=="center"?e.left+(e.right-e.left)/2-(f.right-f.left)/2:r=="start"==o?e.left-s:e.right-(f.right-f.left)+s)-f.left,m||x)if(h)u.scrollBy(m,x);else{let b=0,y=0;if(x){let C=c.scrollTop;c.scrollTop+=x/g,y=(c.scrollTop-C)*g}if(m){let C=c.scrollLeft;c.scrollLeft+=m/p,b=(c.scrollLeft-C)*p}e={left:e.left-b,top:e.top-y,right:e.right-b,bottom:e.bottom-y},b&&Math.abs(b-m)<1&&(r="nearest"),y&&Math.abs(y-x)<1&&(a="nearest")}if(h)break;(e.top<f.top||e.bottom>f.bottom||e.left<f.left||e.right>f.right)&&(e={left:Math.max(e.left,f.left),right:Math.min(e.right,f.right),top:Math.max(e.top,f.top),bottom:Math.min(e.bottom,f.bottom)}),c=c.assignedSlot||c.parentNode}else if(c.nodeType==11)c=c.host;else break}function sS(t,e=!0){let n=t.ownerDocument,r=null,a=null;for(let s=t.parentNode;s&&!(s==n.body||(!e||r)&&a);)if(s.nodeType==1)!a&&s.scrollHeight>s.clientHeight&&(a=s),e&&!r&&s.scrollWidth>s.clientWidth&&(r=s),s=s.assignedSlot||s.parentNode;else if(s.nodeType==11)s=s.host;else break;return{x:r,y:a}}var lm=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:n,focusNode:r}=e;this.set(n,Math.min(e.anchorOffset,n?vs(n):0),r,Math.min(e.focusOffset,r?vs(r):0))}set(e,n,r,a){this.anchorNode=e,this.anchorOffset=n,this.focusNode=r,this.focusOffset=a}};function iS(t){let e=[];for(let n=t;n;n=n.nodeType==11?n.host:n.parentNode)n.nodeType==1&&e.push({node:n,left:n.scrollLeft,top:n.scrollTop});return e}function oS(t,e=!0){for(let{node:n,left:r,top:a}of t)e&&n.scrollTop!=a&&(n.scrollTop=a),n.scrollLeft!=r&&(n.scrollLeft=r)}var Gi=null;Ie.safari&&Ie.safari_version>=26&&(Gi=!1);function lS(t){if(t.setActive)return t.setActive();if(Gi)return t.focus(Gi);let e=iS(t);t.focus(Gi==null?{get preventScroll(){return Gi={preventScroll:!0},!0}}:void 0),Gi||(Gi=!1,oS(e))}var Nk;function Wu(t,e,n=e){let r=Nk||(Nk=document.createRange());return r.setEnd(t,n),r.setStart(t,e),r}function Jo(t,e,n,r){let a={key:e,code:e,keyCode:n,which:n,cancelable:!0};r&&({altKey:a.altKey,ctrlKey:a.ctrlKey,shiftKey:a.shiftKey,metaKey:a.metaKey}=r);let s=new KeyboardEvent("keydown",a);s.synthetic=!0,t.dispatchEvent(s);let i=new KeyboardEvent("keyup",a);return i.synthetic=!0,t.dispatchEvent(i),s.defaultPrevented||i.defaultPrevented}function tT(t){for(;t;){if(t&&(t.nodeType==9||t.nodeType==11&&t.host))return t;t=t.assignedSlot||t.parentNode}return null}function nT(t,e){let n=e.focusNode,r=e.focusOffset;if(!n||e.anchorNode!=n||e.anchorOffset!=r)return!1;for(r=Math.min(r,vs(n));;)if(r){if(n.nodeType!=1)return!1;let a=n.childNodes[r-1];a.contentEditable=="false"?r--:(n=a,r=vs(n))}else{if(n==t)return!0;r=ni(n),n=n.parentNode}}function uS(t){return t instanceof Window?t.pageYOffset>Math.max(0,t.document.documentElement.scrollHeight-t.innerHeight-4):t.scrollTop>Math.max(1,t.scrollHeight-t.clientHeight-4)}function cS(t,e){for(let n=t,r=e;;){if(n.nodeType==3&&r>0)return{node:n,offset:r};if(n.nodeType==1&&r>0){if(n.contentEditable=="false")return null;n=n.childNodes[r-1],r=vs(n)}else if(n.parentNode&&!jd(n))r=ni(n),n=n.parentNode;else return null}}function dS(t,e){for(let n=t,r=e;;){if(n.nodeType==3&&r<n.nodeValue.length)return{node:n,offset:r};if(n.nodeType==1&&r<n.childNodes.length){if(n.contentEditable=="false")return null;n=n.childNodes[r],r=0}else if(n.parentNode&&!jd(n))r=ni(n)+1,n=n.parentNode;else return null}}var qa=class t{constructor(e,n,r=!0){this.node=e,this.offset=n,this.precise=r}static before(e,n){return new t(e.parentNode,ni(e),n)}static after(e,n){return new t(e.parentNode,ni(e)+1,n)}},nn=(function(t){return t[t.LTR=0]="LTR",t[t.RTL=1]="RTL",t})(nn||(nn={})),qi=nn.LTR,Xm=nn.RTL;function fS(t){let e=[];for(let n=0;n<t.length;n++)e.push(1<<+t[n]);return e}var rT=fS("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),aT=fS("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),um=Object.create(null),ja=[];for(let t of["()","[]","{}"]){let e=t.charCodeAt(0),n=t.charCodeAt(1);um[e]=n,um[n]=-e}function hS(t){return t<=247?rT[t]:1424<=t&&t<=1524?2:1536<=t&&t<=1785?aT[t-1536]:1774<=t&&t<=2220?4:8192<=t&&t<=8204?256:64336<=t&&t<=65023?4:1}var sT=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/,ra=class{get dir(){return this.level%2?Xm:qi}constructor(e,n,r){this.from=e,this.to=n,this.level=r}side(e,n){return this.dir==n==e?this.to:this.from}forward(e,n){return e==(this.dir==n)}static find(e,n,r,a){let s=-1;for(let i=0;i<e.length;i++){let o=e[i];if(o.from<=n&&o.to>=n){if(o.level==r)return i;(s<0||(a!=0?a<0?o.from<n:o.to>n:e[s].level>o.level))&&(s=i)}}if(s<0)throw new RangeError("Index out of range");return s}};function pS(t,e){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++){let r=t[n],a=e[n];if(r.from!=a.from||r.to!=a.to||r.direction!=a.direction||!pS(r.inner,a.inner))return!1}return!0}var Jt=[];function iT(t,e,n,r,a){for(let s=0;s<=r.length;s++){let i=s?r[s-1].to:e,o=s<r.length?r[s].from:n,l=s?256:a;for(let u=i,c=l,d=l;u<o;u++){let f=hS(t.charCodeAt(u));f==512?f=c:f==8&&d==4&&(f=16),Jt[u]=f==4?2:f,f&7&&(d=f),c=f}for(let u=i,c=l,d=l;u<o;u++){let f=Jt[u];if(f==128)u<o-1&&c==Jt[u+1]&&c&24?f=Jt[u]=c:Jt[u]=256;else if(f==64){let h=u+1;for(;h<o&&Jt[h]==64;)h++;let p=u&&c==8||h<n&&Jt[h]==8?d==1?1:8:256;for(let g=u;g<h;g++)Jt[g]=p;u=h-1}else f==8&&d==1&&(Jt[u]=1);c=f,f&7&&(d=f)}}}function oT(t,e,n,r,a){let s=a==1?2:1;for(let i=0,o=0,l=0;i<=r.length;i++){let u=i?r[i-1].to:e,c=i<r.length?r[i].from:n;for(let d=u,f,h,p;d<c;d++)if(h=um[f=t.charCodeAt(d)])if(h<0){for(let g=o-3;g>=0;g-=3)if(ja[g+1]==-h){let m=ja[g+2],x=m&2?a:m&4?m&1?s:a:0;x&&(Jt[d]=Jt[ja[g]]=x),o=g;break}}else{if(ja.length==189)break;ja[o++]=d,ja[o++]=f,ja[o++]=l}else if((p=Jt[d])==2||p==1){let g=p==a;l=g?0:1;for(let m=o-3;m>=0;m-=3){let x=ja[m+2];if(x&2)break;if(g)ja[m+2]|=2;else{if(x&4)break;ja[m+2]|=4}}}}}function lT(t,e,n,r){for(let a=0,s=r;a<=n.length;a++){let i=a?n[a-1].to:t,o=a<n.length?n[a].from:e;for(let l=i;l<o;){let u=Jt[l];if(u==256){let c=l+1;for(;;)if(c==o){if(a==n.length)break;c=n[a++].to,o=a<n.length?n[a].from:e}else if(Jt[c]==256)c++;else break;let d=s==1,f=(c<e?Jt[c]:r)==1,h=d==f?d?1:2:r;for(let p=c,g=a,m=g?n[g-1].to:t;p>l;)p==m&&(p=n[--g].from,m=g?n[g-1].to:t),Jt[--p]=h;l=c}else s=u,l++}}}function cm(t,e,n,r,a,s,i){let o=r%2?2:1;if(r%2==a%2)for(let l=e,u=0;l<n;){let c=!0,d=!1;if(u==s.length||l<s[u].from){let g=Jt[l];g!=o&&(c=!1,d=g==16)}let f=!c&&o==1?[]:null,h=c?r:r+1,p=l;e:for(;;)if(u<s.length&&p==s[u].from){if(d)break e;let g=s[u];if(!c)for(let m=g.to,x=u+1;;){if(m==n)break e;if(x<s.length&&s[x].from==m)m=s[x++].to;else{if(Jt[m]==o)break e;break}}if(u++,f)f.push(g);else{g.from>l&&i.push(new ra(l,g.from,h));let m=g.direction==qi!=!(h%2);dm(t,m?r+1:r,a,g.inner,g.from,g.to,i),l=g.to}p=g.to}else{if(p==n||(c?Jt[p]!=o:Jt[p]==o))break;p++}f?cm(t,l,p,r+1,a,f,i):l<p&&i.push(new ra(l,p,h)),l=p}else for(let l=n,u=s.length;l>e;){let c=!0,d=!1;if(!u||l>s[u-1].to){let g=Jt[l-1];g!=o&&(c=!1,d=g==16)}let f=!c&&o==1?[]:null,h=c?r:r+1,p=l;e:for(;;)if(u&&p==s[u-1].to){if(d)break e;let g=s[--u];if(!c)for(let m=g.from,x=u;;){if(m==e)break e;if(x&&s[x-1].to==m)m=s[--x].from;else{if(Jt[m-1]==o)break e;break}}if(f)f.push(g);else{g.to<l&&i.push(new ra(g.to,l,h));let m=g.direction==qi!=!(h%2);dm(t,m?r+1:r,a,g.inner,g.from,g.to,i),l=g.from}p=g.from}else{if(p==e||(c?Jt[p-1]!=o:Jt[p-1]==o))break;p--}f?cm(t,p,l,r+1,a,f,i):p<l&&i.push(new ra(p,l,h)),l=p}}function dm(t,e,n,r,a,s,i){let o=e%2?2:1;iT(t,a,s,r,o),oT(t,a,s,r,o),lT(a,s,r,o),cm(t,a,s,e,n,r,i)}function uT(t,e,n){if(!t)return[new ra(0,0,e==Xm?1:0)];if(e==qi&&!n.length&&!sT.test(t))return mS(t.length);if(n.length)for(;t.length>Jt.length;)Jt[Jt.length]=256;let r=[],a=e==qi?0:1;return dm(t,a,a,n,0,t.length,r),r}function mS(t){return[new ra(0,t,0)]}var gS="";function cT(t,e,n,r,a){var s;if(!t.length)return null;let i=r.head-t.from,o;if(r.head==t.from&&r.assoc<0){if(!a)return null;i=e[o=0].side(!1,n)}else if(r.head==t.to&&r.assoc>0){if(a)return null;i=e[o=e.length-1].side(!0,n)}else o=ra.find(e,i,(s=r.bidiLevel)!==null&&s!==void 0?s:-1,r.assoc);let l=e[o],u=l.side(a,n);if(i==u){let f=o+=a?1:-1;if(f<0||f>=e.length)return null;l=e[o=f],i=l.side(!a,n),u=l.side(a,n)}let c=Gn(t.text,i,l.forward(a,n));(c<l.from||c>l.to)&&(c=u),gS=t.text.slice(Math.min(i,c),Math.max(i,c));let d=o==(a?e.length-1:0)?null:e[o+(a?1:-1)];if(c==u){if(!d)return a?oe.cursor(t.to,1):oe.cursor(t.from,-1);if(d.level+(a?0:1)<l.level)return oe.cursor(d.side(!a,n)+t.from,d.forward(a,n)?1:-1,d.level)}return oe.cursor(c+t.from,l.forward(a,n)?-1:1,l.level)}function dT(t,e,n){for(let r=e;r<n;r++){let a=hS(t.charCodeAt(r));if(a==1)return qi;if(a==2||a==4)return Xm}return qi}var xS=Ee.define(),bS=Ee.define(),yS=Ee.define(),vS=Ee.define(),fm=Ee.define(),wS=Ee.define(),kS=Ee.define(),Ym=Ee.define(),Jm=Ee.define(),SS=Ee.define({combine:t=>t.some(e=>e)}),CS=Ee.define({combine:t=>t.some(e=>e)}),IS=Ee.define(),Tu=class t{constructor(e,n,r,a,s,i=!1){this.range=e,this.y=n,this.x=r,this.yMargin=a,this.xMargin=s,this.isSnapshot=i}map(e){return e.empty?this:new t(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new t(oe.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}},Td=Ct.define({map:(t,e)=>t.map(e)}),LS=Ct.define();function wa(t,e,n){let r=t.facet(vS);r.length?r[0](e):window.onerror&&window.onerror(String(e),n,void 0,void 0,e)||(n?console.error(n+":",e):console.error(e))}var bs=Ee.define({combine:t=>t.length?t[0]:!0}),fT=0,$o=Ee.define({combine(t){return t.filter((e,n)=>{for(let r=0;r<n;r++)if(t[r].plugin==e.plugin)return!1;return!0})}}),Nr=class t{constructor(e,n,r,a,s){this.id=e,this.create=n,this.domEventHandlers=r,this.domEventObservers=a,this.baseExtensions=s(this),this.extension=this.baseExtensions.concat($o.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat($o.of({plugin:this,arg:e}))}static define(e,n){let{eventHandlers:r,eventObservers:a,provide:s,decorations:i}=n||{};return new t(fT++,e,r,a,o=>{let l=[];return i&&l.push(rf.of(u=>{let c=u.plugin(o);return c?i(c):Ze.none})),s&&l.push(s(o)),l})}static fromClass(e,n){return t.define((r,a)=>new e(r,a),n)}},Du=class{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(e){if(this.value){if(this.mustUpdate){let n=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(n)}catch(r){if(wa(n.state,r,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(e,this.spec.arg)}catch(n){wa(e.state,n,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var n;if(!((n=this.value)===null||n===void 0)&&n.destroy)try{this.value.destroy()}catch(r){wa(e.state,r,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}},AS=Ee.define(),Zm=Ee.define(),rf=Ee.define(),PS=Ee.define(),Qm=Ee.define(),ju=Ee.define(),RS=Ee.define();function Mk(t,e){let n=t.state.facet(RS);if(!n.length)return n;let r=n.map(s=>s instanceof Function?s(t):s),a=[];return Pt.spans(r,e.from,e.to,{point(){},span(s,i,o,l){let u=s-e.from,c=i-e.from,d=a;for(let f=o.length-1;f>=0;f--,l--){let h=o[f].spec.bidiIsolate,p;if(h==null&&(h=dT(e.text,u,c)),l>0&&d.length&&(p=d[d.length-1]).to==u&&p.direction==h)p.to=c,d=p.inner;else{let g={from:u,to:c,direction:h,inner:[]};d.push(g),d=g.inner}}}}),a}var NS=Ee.define();function MS(t){let e=0,n=0,r=0,a=0;for(let s of t.state.facet(NS)){let i=s(t);i&&(i.left!=null&&(e=Math.max(e,i.left)),i.right!=null&&(n=Math.max(n,i.right)),i.top!=null&&(r=Math.max(r,i.top)),i.bottom!=null&&(a=Math.max(a,i.bottom)))}return{left:e,right:n,top:r,bottom:a}}var Au=Ee.define(),ka=class t{constructor(e,n,r,a){this.fromA=e,this.toA=n,this.fromB=r,this.toB=a}join(e){return new t(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let n=e.length,r=this;for(;n>0;n--){let a=e[n-1];if(!(a.fromA>r.toA)){if(a.toA<r.fromA)break;r=r.join(a),e.splice(n-1,1)}}return e.splice(n,0,r),e}static extendWithRanges(e,n){if(n.length==0)return e;let r=[];for(let a=0,s=0,i=0;;){let o=a<e.length?e[a].fromB:1e9,l=s<n.length?n[s]:1e9,u=Math.min(o,l);if(u==1e9)break;let c=u+i,d=u,f=c;for(;;)if(s<n.length&&n[s]<=d){let h=n[s+1];s+=2,d=Math.max(d,h);for(let p=a;p<e.length&&e[p].fromB<=d;p++)i=e[p].toA-e[p].toB;f=Math.max(f,h+i)}else if(a<e.length&&e[a].fromB<=d){let h=e[a++];d=Math.max(d,h.toB),f=Math.max(f,h.toA),i=h.toA-h.toB}else break;r.push(new t(c,f,u,d))}return r}},qd=class t{constructor(e,n,r){this.view=e,this.state=n,this.transactions=r,this.flags=0,this.startState=e.state,this.changes=zn.empty(this.startState.doc.length);for(let s of r)this.changes=this.changes.compose(s.changes);let a=[];this.changes.iterChangedRanges((s,i,o,l)=>a.push(new ka(s,i,o,l))),this.changedRanges=a}static create(e,n,r){return new t(e,n,r)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}},hT=[],un=class{constructor(e,n,r=0){this.dom=e,this.length=n,this.flags=r,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return hT}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,this.flags&4){this.flags&=-5;let n=this.domAttrs;n&&YM(this.dom,n)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,n=this.posAtStart){let r=n;for(let a of this.children){if(a==e)return r;r+=a.length+a.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,n,r){return null}domPosFor(e,n){let r=ni(this.dom),a=this.length?e>0:n>0;return new qa(this.parent.dom,r+(a?1:0),e==0||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof Qo)return e;return null}static get(e){return e.cmTile}},Zo=class extends un{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let n=this.dom,r=null,a,s=e?.node==n?e:null,i=0;for(let o of this.children){if(o.sync(e),i+=o.length+o.breakAfter,a=r?r.nextSibling:n.firstChild,s&&a!=o.dom&&(s.written=!0),o.dom.parentNode==n)for(;a&&a!=o.dom;)a=Tk(a);else n.insertBefore(o.dom,a);r=o.dom}for(a=r?r.nextSibling:n.firstChild,s&&a&&(s.written=!0);a;)a=Tk(a);this.length=i}};function Tk(t){let e=t.nextSibling;return t.parentNode.removeChild(t),e}var Qo=class extends Zo{constructor(e,n){super(n),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let n=un.get(e);if(n&&this.owns(n))return n;e=e.parentNode}}blockTiles(e){for(let n=[],r=this,a=0,s=0;;)if(a==r.children.length){if(!n.length)return;r=r.parent,r.breakAfter&&s++,a=n.pop()}else{let i=r.children[a++];if(i instanceof ys)n.push(a),r=i,a=0;else{let o=s+i.length,l=e(i,s);if(l!==void 0)return l;s=o+i.breakAfter}}}resolveBlock(e,n){let r,a=-1,s,i=-1;if(this.blockTiles((o,l)=>{let u=l+o.length;if(e>=l&&e<=u){if(o.isWidget()&&n>=-1&&n<=1){if(o.flags&32)return!0;o.flags&16&&(r=void 0)}(l<e||e==u&&(n<-1?o.length:o.covers(1)))&&(!r||!o.isWidget()&&r.isWidget())&&(r=o,a=e-l),(u>e||e==l&&(n>1?o.length:o.covers(-1)))&&(!s||!o.isWidget()&&s.isWidget())&&(s=o,i=e-l)}}),!r&&!s)throw new Error("No tile at position "+e);return r&&n<0||!s?{tile:r,offset:a}:{tile:s,offset:i}}},ys=class t extends Zo{constructor(e,n){super(e),this.wrapper=n}isBlock(){return!0}covers(e){return this.children.length?e<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(e,n){let r=new t(n||document.createElement(e.tagName),e);return n||(r.flags|=4),r}},el=class t extends Zo{constructor(e,n){super(e),this.attrs=n}isLine(){return!0}static start(e,n,r){let a=new t(n||document.createElement("div"),e);return(!n||!r)&&(a.flags|=4),a}get domAttrs(){return this.attrs}resolveInline(e,n,r){let a=null,s=-1,i=null,o=-1;function l(c,d){for(let f=0,h=0;f<c.children.length&&h<=d;f++){let p=c.children[f],g=h+p.length;g>=d&&(p.isComposite()?l(p,d-h):(!i||i.isHidden&&(n>0&&!(i.flags&32)||r&&mT(i,p)))&&(g>d||p.flags&32&&n<=1)?(i=p,o=d-h):(h<d||p.flags&16&&!p.isHidden&&n>=-1)&&(a=p,s=d-h)),h=g}}l(this,e);let u=(n<0?a:i)||a||i;return u?{tile:u,offset:u==a?s:o}:null}coordsIn(e,n,r){let a=this.resolveInline(e,n,!0);return a?a.tile.coordsIn(Math.max(0,a.offset),n,r):pT(this)}domIn(e,n){let r=this.resolveInline(e,n);if(r){let{tile:a,offset:s}=r;if(this.dom.contains(a.dom))return a.isText()?new qa(a.dom,Math.min(a.dom.nodeValue.length,s)):a.domPosFor(s,a.flags&16?1:a.flags&32?-1:n);let i=r.tile.parent,o=!1;for(let l of i.children){if(o)return new qa(l.dom,0);l==r.tile&&(o=!0)}}return new qa(this.dom,0)}};function pT(t){let e=t.dom.lastChild;if(!e)return t.dom.getBoundingClientRect();let n=Nu(e);return n[n.length-1]||null}function mT(t,e){let n=t.coordsIn(0,1),r=e.coordsIn(0,1);return n&&r&&r.top<n.bottom}var Rr=class t extends Zo{constructor(e,n){super(e),this.mark=n}get domAttrs(){return this.mark.attrs}static of(e,n){let r=new t(n||document.createElement(e.tagName),e);return n||(r.flags|=4),r}},zi=class t extends un{constructor(e,n){super(e,n.length),this.text=n}sync(e){this.flags&2||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,n,r){let a=this.dom.nodeValue.length;e>a&&(e=a);let s=e,i=e,o=0;e==0&&n<0||e==a&&n>=0?Ie.chrome||Ie.gecko||(e?(s--,o=1):i<a&&(i++,o=-1)):n<0?s--:i<a&&i++;let l=Wu(this.dom,s,i).getClientRects();if(!l.length)return null;let u=l[(o?o<0:n>=0)?0:l.length-1];return Ie.safari&&!o&&u.width==0&&(u=Array.prototype.find.call(l,c=>c.width)||u),r==null?u:zu(u,(o?o>0:n<0)==r)}static of(e,n){let r=new t(n||document.createTextNode(e),e);return n||(r.flags|=2),r}},Vi=class t extends un{constructor(e,n,r,a){super(e,n,a),this.widget=r}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,n){return this.coordsInWidget(e,n,!1)}coordsInWidget(e,n,r){let a=this.widget.coordsAt(this.dom,e,n);if(a)return a;if(r)return zu(this.dom.getBoundingClientRect(),this.length?e==0:n<=0);{let s=this.dom.getClientRects(),i=null;if(!s.length)return null;let o=this.flags&16?!0:this.flags&32?!1:e>0;for(let l=o?s.length-1:0;i=s[l],!(e>0?l==0:l==s.length-1||i.top<i.bottom);l+=o?-1:1);return zu(i,!o)}}get overrideDOMText(){if(!this.length)return mt.empty;let{root:e}=this;if(!e)return mt.empty;let n=this.posAtStart;return e.view.state.doc.slice(n,n+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(e,n,r,a,s){return s||(s=e.toDOM(n),e.editable||(s.contentEditable="false")),new t(s,r,e,a)}},tl=class extends un{constructor(e){let n=document.createElement("img");n.className="cm-widgetBuffer",n.setAttribute("aria-hidden","true"),super(n,0,e)}get isHidden(){return!0}get overrideDOMText(){return mt.empty}coordsIn(e,n,r){let a=this.dom.getBoundingClientRect();return r==null?a:zu(a,n>0==r)}},hm=class{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,n,r){let{tile:a,index:s,beforeBreak:i,parents:o}=this;for(;e||n>0;)if(a.isComposite())if(i){if(!e)break;r&&r.break(),e--,i=!1}else if(s==a.children.length){if(!e&&!o.length)break;r&&r.leave(a),i=!!a.breakAfter,{tile:a,index:s}=o.pop(),s++}else{let l=a.children[s],u=l.breakAfter;(n>0?l.length<=e:l.length<e)&&(!r||r.skip(l,0,l.length)!==!1||!l.isComposite)?(i=!!u,s++,e-=l.length):(o.push({tile:a,index:s}),a=l,s=0,r&&l.isComposite()&&r.enter(l))}else{let l=a.length;if(s<l&&e){let u=Math.min(e,l-s);r&&r.skip(a,s,s+u),e-=u,s+=u}if(s==l)i=!!a.breakAfter,{tile:a,index:s}=o.pop(),s++;else if(!e)break}return this.tile=a,this.index=s,this.beforeBreak=i,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}},pm=class{constructor(e,n,r,a){this.from=e,this.to=n,this.wrapper=r,this.rank=a}},mm=class{constructor(e,n,r){this.cache=e,this.root=n,this.blockWrappers=r,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,n,r,a){var s;this.flushBuffer();let i=this.ensureMarks(n,r),o=i.lastChild;if(o&&o.isText()&&!(o.flags&8)&&o.length+e.length<512){this.cache.reused.set(o,2);let l=i.children[i.children.length-1]=new zi(o.dom,o.text+e);l.parent=i}else i.append(a||zi.of(e,(s=this.cache.find(zi))===null||s===void 0?void 0:s.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,n){let r=this.curLine;r.dom!=n.line.dom&&(r.setDOM(this.cache.reused.has(n.line)?Zp(n.line.dom):n.line.dom),this.cache.reused.set(n.line,2));let a=r;for(let o=n.marks.length-1;o>=0;o--){let l=n.marks[o],u=a.lastChild;if(u instanceof Rr&&u.mark.eq(l.mark))u.dom!=l.dom&&u.setDOM(Zp(l.dom)),a=u;else{let{dom:c}=l;this.cache.reused.get(l)&&un.get(l.dom)&&(c=Zp(l.dom));let d=Rr.of(l.mark,c);a.append(d),a=d}this.cache.reused.set(l,2)}let s=un.get(e.text);s&&this.cache.reused.set(s,2);let i=new zi(e.text,e.text.nodeValue);i.flags|=8,this.pos=e.range.toB,a.append(i)}addInlineWidget(e,n,r){let a=this.afterWidget&&e.flags&48&&(this.afterWidget.flags&48)==(e.flags&48);a||this.flushBuffer();let s=this.ensureMarks(n,r);!a&&!(e.flags&16)&&s.append(this.getBuffer(1)),s.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,n,r){this.flushBuffer(),this.ensureMarks(n,r).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){let n=this.afterWidget||this.lastBlock;n.length+=e,this.pos+=e}addLineStart(e,n){var r;e||(e=TS);let a=el.start(e,n||((r=this.cache.find(el))===null||r===void 0?void 0:r.dom),!!n);this.getBlockPos().append(this.lastBlock=this.curLine=a)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,n){var r;let a=this.curLine;for(let s=e.length-1;s>=0;s--){let i=e[s],o;if(n>0&&(o=a.lastChild)&&o instanceof Rr&&o.mark.eq(i))a=o,n--;else{let l=Rr.of(i,(r=this.cache.find(Rr,u=>u.mark.eq(i)))===null||r===void 0?void 0:r.dom);a.append(l),a=l,n=0}}return a}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;(!e||!Dk(this.curLine,!1)||e.dom.nodeName!="BR"&&e.isWidget()&&!(Ie.ios&&Dk(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(Qp,0,32)||new Vi(Qp.toDOM(),0,Qp,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let n=e.rank*102+e.value.rank,r=new pm(e.from,e.to,e.value,n),a=this.wrappers.length;for(;a>0&&(this.wrappers[a-1].rank-r.rank||this.wrappers[a-1].to-r.to)<0;)a--;this.wrappers.splice(a,0,r)}this.wrapperPos=this.pos}getBlockPos(){var e;this.updateBlockWrappers();let n=this.root;for(let r of this.wrappers){let a=n.lastChild;if(r.from<this.pos&&a instanceof ys&&a.wrapper.eq(r.wrapper))n=a;else{let s=ys.of(r.wrapper,(e=this.cache.find(ys,i=>i.wrapper.eq(r.wrapper)))===null||e===void 0?void 0:e.dom);n.append(s),n=s}}return n}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let n=2|(e<0?16:32),r=this.cache.find(tl,void 0,1);return r&&(r.flags=n),r||new tl(n)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}},gm=class{constructor(e){this.skipCount=0,this.text="",this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:a,lineBreak:s,done:i}=this.cursor.next(this.skipCount);if(this.skipCount=0,i)throw new Error("Ran out of text content when drawing inline views");this.text=a;let o=this.textOff=Math.min(e,a.length);return s?null:a.slice(0,o)}let n=Math.min(this.text.length,this.textOff+e),r=this.text.slice(this.textOff,n);return this.textOff=n,r}},Vd=[Vi,el,zi,Rr,tl,ys,Qo];for(let t=0;t<Vd.length;t++)Vd[t].bucket=t;var xm=class{constructor(e){this.view=e,this.buckets=Vd.map(()=>[]),this.index=Vd.map(()=>0),this.reused=new Map}add(e){let n=e.constructor.bucket,r=this.buckets[n];r.length<6?r.push(e):r[this.index[n]=(this.index[n]+1)%6]=e}find(e,n,r=2){let a=e.bucket,s=this.buckets[a],i=this.index[a];for(let o=0;o<s.length;o++){let l=(o+i)%s.length,u=s[l];if((!n||n(u))&&!this.reused.has(u))return s.splice(l,1),l<i&&this.index[a]--,this.reused.set(u,r),u}return null}findWidget(e,n,r){let a=this.buckets[0];if(a.length)for(let s=0,i=0;;s++){if(s==a.length){if(i)return null;i=1,s=0}let o=a[s];if(!this.reused.has(o)&&(i==0?o.widget.compare(e):o.widget.constructor==e.constructor&&e.updateDOM(o.dom,this.view,o.widget)))return a.splice(s,1),s<this.index[0]&&this.index[0]--,o.widget==e&&o.length==n&&(o.flags&497)==r?(this.reused.set(o,1),o):(this.reused.set(o,2),new Vi(o.dom,n,e,o.flags&-498|r))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,n=2){if(!this.reused.has(e))return this.reused.set(e,n),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}},bm=class{constructor(e,n,r,a,s){this.view=e,this.decorations=a,this.disallowBlockEffectsFor=s,this.openWidget=!1,this.openMarks=0,this.cache=new xm(e),this.text=new gm(e.state.doc),this.builder=new mm(this.cache,new Qo(e,e.contentDOM),Pt.iter(r)),this.cache.reused.set(n,2),this.old=new hm(n),this.reuseWalker={skip:(i,o,l)=>{if(this.cache.add(i),i.isComposite())return!1},enter:i=>this.cache.add(i),leave:()=>{},break:()=>{}}}run(e,n){let r=n&&this.getCompositionContext(n.text);for(let a=0,s=0,i=0;;){let o=i<e.length?e[i++]:null,l=o?o.fromA:this.old.root.length;if(l>a){let u=l-a;this.preserve(u,!i,!o),a=l,s+=u}if(!o)break;n&&o.fromA<=n.range.fromA&&o.toA>=n.range.toA?(this.forward(o.fromA,n.range.fromA,n.range.fromA<n.range.toA?1:-1),this.emit(s,n.range.fromB),this.builder.flushBuffer(),this.cache.clear(),this.builder.addComposition(n,r),this.text.skip(n.range.toB-n.range.fromB),this.forward(n.range.fromA,o.toA),this.emit(n.range.toB,o.toB)):(this.forward(o.fromA,o.toA),this.emit(s,o.toB)),s=o.toB,a=o.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,n,r){let a=bT(this.old),s=this.openMarks;this.old.advance(e,r?1:-1,{skip:(i,o,l)=>{if(i.isWidget())if(this.openWidget)this.builder.continueWidget(l-o);else{let u=l>0||o<i.length?Vi.of(i.widget,this.view,l-o,i.flags&496,this.cache.maybeReuse(i)):this.cache.reuse(i);u.flags&256?(u.flags&=-2,this.builder.addBlockWidget(u)):(this.builder.ensureLine(null),this.builder.addInlineWidget(u,a,s),s=a.length)}else if(i.isText())this.builder.ensureLine(null),!o&&l==i.length&&!this.cache.reused.has(i)?this.builder.addText(i.text,a,s,this.cache.reuse(i)):(this.cache.add(i),this.builder.addText(i.text.slice(o,l),a,s)),s=a.length;else if(i.isLine())i.flags&=-2,this.cache.reused.set(i,1),this.builder.addLine(i);else if(i instanceof tl)this.cache.add(i);else if(i instanceof Rr)this.builder.ensureLine(null),this.builder.addMark(i,a,s),this.cache.reused.set(i,1),s=a.length;else return!1;this.openWidget=!1},enter:i=>{i.isLine()?this.builder.addLineStart(i.attrs,this.cache.maybeReuse(i)):(this.cache.add(i),i instanceof Rr&&a.unshift(i.mark)),this.openWidget=!1},leave:i=>{i.isLine()?a.length&&(a.length=s=0):i instanceof Rr&&(a.shift(),s=Math.min(s,a.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,n){let r=null,a=this.builder,s=-1,i=Pt.spans(this.decorations,e,n,{point:(o,l,u,c,d,f)=>{if(u instanceof ji){if(this.disallowBlockEffectsFor[f]){if(u.block)throw new RangeError("Block decorations may not be specified via plugins");if(l>this.view.state.doc.lineAt(o).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(s=c.length,d>c.length)a.continueWidget(l-o);else{let h=u.widget||(u.block?ri.block:ri.inline),p=gT(u),g=this.cache.findWidget(h,l-o,p)||Vi.of(h,this.view,l-o,p);u.block?(u.startSide>0&&a.addLineStartIfNotCovered(r),a.addBlockWidget(g)):(a.ensureLine(r),a.addInlineWidget(g,c,d))}r=null}else r=xT(r,u);l>o&&this.text.skip(l-o)},span:(o,l,u,c)=>{for(let d=o;d<l;){let f=this.text.next(Math.min(512,l-d));f==null?(a.addLineStartIfNotCovered(r),a.addBreak(),d++):(a.ensureLine(r),a.addText(f,u,d==o?c:u.length),d+=f.length),r=null}s=u.length}});s>-1&&(this.openWidget=i>s),this.openWidget||a.addLineStartIfNotCovered(r),this.openMarks=i}forward(e,n,r=1){n-e<=10?this.old.advance(n-e,r,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(n-e-10,-1),this.old.advance(5,r,this.reuseWalker))}getCompositionContext(e){let n=[],r=null;for(let a=e.parentNode;;a=a.parentNode){let s=un.get(a);if(a==this.view.contentDOM)break;s instanceof Rr?n.push(s):s?.isLine()?r=s:s instanceof ys||(a.nodeName=="DIV"&&!r?r=new el(a,TS):r||n.push(Rr.of(new Hu({tagName:a.nodeName.toLowerCase(),attributes:JM(a)}),a)))}return r?{line:r,marks:n}:null}};function Dk(t,e){let n=r=>{for(let a of r.children)if((e?a.isText():a.length)||n(a))return!0;return!1};return n(t)}function gT(t){let e=t.isReplace?(t.startSide<0?64:0)|(t.endSide>0?128:0):t.startSide>0?32:16;return t.block&&(e|=256),e}var TS={class:"cm-line"};function xT(t,e){let n=e.spec.attributes,r=e.spec.class;return!n&&!r||(t||(t={class:"cm-line"}),n&&$m(n,t),r&&(t.class+=" "+r)),t}function bT(t){let e=[];for(let n=t.parents.length;n>1;n--){let r=n==t.parents.length?t.tile:t.parents[n].tile;r instanceof Rr&&e.push(r.mark)}return e}function Zp(t){let e=un.get(t);return e&&e.setDOM(t.cloneNode()),t}var ri=class extends zr{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}};ri.inline=new ri("span");ri.block=new ri("div");var Qp=new class extends zr{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}},$d=class{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=Ze.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new Qo(e,e.contentDOM),this.updateInner([new ka(0,0,0,e.state.doc.length)],null)}update(e){var n;let r=e.changedRanges;this.minWidth>0&&r.length&&(r.every(({fromA:c,toA:d})=>d<this.minWidthFrom||c>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let a=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((n=this.domChanged)===null||n===void 0)&&n.newSel?a=this.domChanged.newSel.head:!LT(e.changes,this.hasComposition)&&!e.selectionSet&&(a=e.state.selection.main.head));let s=a>-1?vT(this.view,e.changes,a):null;if(this.domChanged=null,this.hasComposition){let{from:c,to:d}=this.hasComposition;r=new ka(c,d,e.changes.mapPos(c,-1),e.changes.mapPos(d,1)).addToSet(r.slice())}this.hasComposition=s?{from:s.range.fromB,to:s.range.toB}:null,(Ie.ie||Ie.chrome)&&!s&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let i=this.decorations,o=this.blockWrappers;this.updateDeco();let l=ST(i,this.decorations,e.changes);l.length&&(r=ka.extendWithRanges(r,l));let u=CT(o,this.blockWrappers,e.changes);return u.length&&(r=ka.extendWithRanges(r,u)),s&&!r.some(c=>c.fromA<=s.range.fromA&&c.toA>=s.range.toA)&&(r=s.range.addToSet(r.slice())),this.tile.flags&2&&r.length==0?!1:(this.updateInner(r,s),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,n){this.view.viewState.mustMeasureContent=!0;let{observer:r}=this.view;r.ignore(()=>{if(n||e.length){let i=this.tile,o=new bm(this.view,i,this.blockWrappers,this.decorations,this.dynamicDecorationMap);n&&un.get(n.text)&&o.cache.reused.set(un.get(n.text),2),this.tile=o.run(e,n),ym(i,o.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let s=Ie.chrome||Ie.ios?{node:r.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(s),s&&(s.written||r.selectionRange.focusNode!=s.node||!this.tile.dom.contains(s.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let a=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let s of this.tile.children)s.isWidget()&&s.widget instanceof Fu&&a.push(s.dom);r.updateGaps(a)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let n of e.transactions)for(let r of n.effects)r.is(LS)&&(this.editContextFormatting=r.value)}updateSelection(e=!1,n=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:r}=this.tile,a=this.view.root.activeElement,s=a==r,i=!s&&!(this.view.state.facet(bs)||r.tabIndex>-1)&&Ru(r,this.view.observer.selectionRange)&&!(a&&r.contains(a));if(!(s||n||i))return;let o=this.forceSelection;this.forceSelection=!1;let l=this.view.state.selection.main,u,c;if(l.empty?c=u=this.inlineDOMNearPos(l.anchor,l.assoc||1):(c=this.inlineDOMNearPos(l.head,l.head==l.from?1:-1),u=this.inlineDOMNearPos(l.anchor,l.anchor==l.from?1:-1)),Ie.gecko&&l.empty&&!this.hasComposition&&yT(u)){let f=document.createTextNode("");this.view.observer.ignore(()=>u.node.insertBefore(f,u.node.childNodes[u.offset]||null)),u=c=new qa(f,0),o=!0}let d=this.view.observer.selectionRange;(o||!d.focusNode||(!Mu(u.node,u.offset,d.anchorNode,d.anchorOffset)||!Mu(c.node,c.offset,d.focusNode,d.focusOffset))&&!this.suppressWidgetCursorChange(d,l))&&(this.view.observer.ignore(()=>{Ie.android&&Ie.chrome&&r.contains(d.focusNode)&&IT(d.focusNode,r)&&(r.blur(),r.focus({preventScroll:!0}));let f=Gu(this.view.root);if(f)if(l.empty){if(Ie.gecko){let h=wT(u.node,u.offset);if(h&&h!=3){let p=(h==1?cS:dS)(u.node,u.offset);p&&(u=new qa(p.node,p.offset))}}f.collapse(u.node,u.offset),l.bidiLevel!=null&&f.caretBidiLevel!==void 0&&(f.caretBidiLevel=l.bidiLevel)}else if(f.extend){f.collapse(u.node,u.offset);try{f.extend(c.node,c.offset)}catch{}}else{let h=document.createRange();l.anchor>l.head&&([u,c]=[c,u]),h.setEnd(c.node,c.offset),h.setStart(u.node,u.offset),f.removeAllRanges(),f.addRange(h)}i&&this.view.root.activeElement==r&&(r.blur(),a&&a.focus())}),this.view.observer.setSelectionRange(u,c)),this.impreciseAnchor=u.precise?null:new qa(d.anchorNode,d.anchorOffset),this.impreciseHead=c.precise?null:new qa(d.focusNode,d.focusOffset)}suppressWidgetCursorChange(e,n){return this.hasComposition&&n.empty&&Mu(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==n.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,n=e.state.selection.main,r=Gu(e.root),{anchorNode:a,anchorOffset:s}=e.observer.selectionRange;if(!r||!n.empty||!n.assoc||!r.modify)return;let i=this.lineAt(n.head,n.assoc);if(!i)return;let o=i.posAtStart;if(n.head==o||n.head==o+i.length)return;let l=this.coordsAt(n.head,-1),u=this.coordsAt(n.head,1);if(!l||!u||l.bottom>u.top)return;let c=this.domAtPos(n.head+n.assoc,n.assoc);r.collapse(c.node,c.offset),r.modify("move",n.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let d=e.observer.selectionRange;e.docView.posFromDOM(d.anchorNode,d.anchorOffset)!=n.from&&r.collapse(a,s)}posFromDOM(e,n){let r=this.tile.nearest(e);if(!r)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let a=r.posAtStart;if(r.isComposite()){let s;if(e==r.dom)s=r.dom.childNodes[n];else{let i=vs(e)==0?0:n==0?-1:1;for(;;){let o=e.parentNode;if(o==r.dom)break;i==0&&o.firstChild!=o.lastChild&&(e==o.firstChild?i=-1:i=1),e=o}i<0?s=e:s=e.nextSibling}if(s==r.dom.firstChild)return a;for(;s&&!un.get(s);)s=s.nextSibling;if(!s)return a+r.length;for(let i=0,o=a;;i++){let l=r.children[i];if(l.dom==s)return o;o+=l.length+l.breakAfter}}else return r.isText()?e==r.dom?a+n:a+(n?r.length:0):a}domAtPos(e,n){let{tile:r,offset:a}=this.tile.resolveBlock(e,n);return r.isWidget()?r.domPosFor(a,n):r.domIn(a,n)}inlineDOMNearPos(e,n){let r,a=-1,s=!1,i,o=-1,l=!1;return this.tile.blockTiles((u,c)=>{if(u.isWidget()){if(u.flags&32&&c>=e)return!0;u.flags&16&&(s=!0)}else{let d=c+u.length;if(c<=e&&(r=u,a=e-c,s=d<e),d>=e&&!i&&(i=u,o=e-c,l=c>e),c>e&&i)return!0}}),!r&&!i?this.domAtPos(e,n):(s&&i?r=null:l&&r&&(i=null),r&&n<0||!i?r.domIn(a,n):i.domIn(o,n))}coordsAt(e,n,r){let{tile:a,offset:s}=this.tile.resolveBlock(e,n);return a.isWidget()?a.widget instanceof Fu?null:a.coordsInWidget(s,n,!0):a.coordsIn(s,n,r)}lineAt(e,n){let{tile:r}=this.tile.resolveBlock(e,n);return r.isLine()?r:null}coordsForChar(e){let{tile:n,offset:r}=this.tile.resolveBlock(e,1);if(!n.isLine())return null;function a(s,i){if(s.isComposite())for(let o of s.children){if(o.length>=i){let l=a(o,i);if(l)return l}if(i-=o.length,i<0)break}else if(s.isText()&&i<s.length){let o=Gn(s.text,i);if(o==i)return null;let l=Wu(s.dom,i,o).getClientRects();for(let u=0;u<l.length;u++){let c=l[u];if(u==l.length-1||c.top<c.bottom&&c.left<c.right)return c}}return null}return a(n,r)}measureVisibleLineHeights(e){let n=[],{from:r,to:a}=e,s=this.view.contentDOM.clientWidth,i=s>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,o=-1,l=this.view.textDirection==nn.LTR,u=0,c=(d,f,h)=>{for(let p=0;p<d.children.length&&!(f>a);p++){let g=d.children[p],m=f+g.length,x=g.dom.getBoundingClientRect(),{height:b}=x;if(h&&!p&&(u+=x.top-h.top),g instanceof ys)m>r&&c(g,f,x);else if(f>=r&&(u>0&&n.push(-u),n.push(b+u),u=0,i)){let y=g.dom.lastChild,C=y?Nu(y):[];if(C.length){let I=C[C.length-1],L=l?I.right-x.left:x.right-I.left;L>o&&(o=L,this.minWidth=s,this.minWidthFrom=f,this.minWidthTo=m)}}h&&p==d.children.length-1&&(u+=h.bottom-x.bottom),f=m+g.breakAfter}};return c(this.tile,0,null),n}textDirectionAt(e){let{tile:n}=this.tile.resolveBlock(e,1);return getComputedStyle(n.dom).direction=="rtl"?nn.RTL:nn.LTR}measureTextSize(){let e=this.tile.blockTiles(i=>{if(i.isLine()&&i.children.length&&i.length<=20){let o=0,l;for(let u of i.children){if(!u.isText()||/[^ -~]/.test(u.text))return;let c=Nu(u.dom);if(c.length!=1)return;o+=c[0].width,l=c[0].height}if(o)return{lineHeight:i.dom.getBoundingClientRect().height,charWidth:o/i.length,textHeight:l}}});if(e)return e;let n=document.createElement("div"),r,a,s;return n.className="cm-line",n.style.width="99999px",n.style.position="absolute",n.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(n);let i=Nu(n.firstChild)[0];r=n.getBoundingClientRect().height,a=i&&i.width?i.width/27:7,s=i&&i.height?i.height:r,n.remove()}),{lineHeight:r,charWidth:a,textHeight:s}}computeBlockGapDeco(){let e=[],n=this.view.viewState;for(let r=0,a=0;;a++){let s=a==n.viewports.length?null:n.viewports[a],i=s?s.from-1:this.view.state.doc.length;if(i>r){let o=(n.lineBlockAt(i).bottom-n.lineBlockAt(r).top)/this.view.scaleY;e.push(Ze.replace({widget:new Fu(o),block:!0,inclusive:!0,isBlockGap:!0}).range(r,i))}if(!s)break;r=s.to+1}return Ze.set(e)}updateDeco(){let e=1,n=this.view.state.facet(rf).map(s=>(this.dynamicDecorationMap[e++]=typeof s=="function")?s(this.view):s),r=!1,a=this.view.state.facet(Qm).map((s,i)=>{let o=typeof s=="function";return o&&(r=!0),o?s(this.view):s});for(a.length&&(this.dynamicDecorationMap[e++]=r,n.push(Pt.join(a))),this.decorations=[this.editContextFormatting,...n,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(PS).map(s=>typeof s=="function"?s(this.view):s)}scrollIntoView(e){if(e.isSnapshot){let u=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=u.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let u of this.view.state.facet(IS))try{if(u(this.view,e.range,e))return!0}catch(c){wa(this.view.state,c,"scroll handler")}let{range:n}=e,r=this.coordsAt(n.head,n.assoc||(n.head>n.anchor?-1:1)),a;if(!r)return;!n.empty&&(a=this.coordsAt(n.anchor,n.anchor>n.head?-1:1))&&(r={left:Math.min(r.left,a.left),top:Math.min(r.top,a.top),right:Math.max(r.right,a.right),bottom:Math.max(r.bottom,a.bottom)});let s=MS(this.view),i={left:r.left-s.left,top:r.top-s.top,right:r.right+s.right,bottom:r.bottom+s.bottom},{offsetWidth:o,offsetHeight:l}=this.view.scrollDOM;if(eT(this.view.scrollDOM,i,n.head<n.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,o),-o),Math.max(Math.min(e.yMargin,l),-l),this.view.textDirection==nn.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(r.top>window.visualViewport.offsetTop+window.visualViewport.height||r.bottom<window.visualViewport.offsetTop)){let u=this.view.docView.lineAt(n.head,1);if(u){let c=iS(u.dom);u.dom.scrollIntoView({block:"nearest"}),oS(c,!1)}}}lineHasWidget(e){let n=r=>r.isWidget()||r.children.some(n);return n(this.tile.resolveBlock(e,1).tile)}destroy(){ym(this.tile)}};function ym(t,e){let n=e?.get(t);if(n!=1){n==null&&t.destroy();for(let r of t.children)ym(r,e)}}function yT(t){return t.node.nodeType==1&&t.node.firstChild&&(t.offset==0||t.node.childNodes[t.offset-1].contentEditable=="false")&&(t.offset==t.node.childNodes.length||t.node.childNodes[t.offset].contentEditable=="false")}function DS(t,e){let n=t.observer.selectionRange;if(!n.focusNode)return null;let r=cS(n.focusNode,n.focusOffset),a=dS(n.focusNode,n.focusOffset),s=r||a;if(a&&r&&a.node!=r.node){let o=un.get(a.node);if(!o||o.isText()&&o.text!=a.node.nodeValue)s=a;else if(t.docView.lastCompositionAfterCursor){let l=un.get(r.node);!l||l.isText()&&l.text!=r.node.nodeValue||(s=a)}}if(t.docView.lastCompositionAfterCursor=s!=r,!s)return null;let i=e-s.offset;return{from:i,to:i+s.node.nodeValue.length,node:s.node}}function vT(t,e,n){let r=DS(t,n);if(!r)return null;let{node:a,from:s,to:i}=r,o=a.nodeValue;if(/[\n\r]/.test(o)||t.state.doc.sliceString(r.from,r.to)!=o)return null;let l=e.invertedDesc;return{range:new ka(l.mapPos(s),l.mapPos(i),s,i),text:a}}function wT(t,e){return t.nodeType!=1?0:(e&&t.childNodes[e-1].contentEditable=="false"?1:0)|(e<t.childNodes.length&&t.childNodes[e].contentEditable=="false"?2:0)}var kT=class{constructor(){this.changes=[]}compareRange(e,n){Yo(e,n,this.changes)}comparePoint(e,n){Yo(e,n,this.changes)}boundChange(e){Yo(e,e,this.changes)}};function ST(t,e,n){let r=new kT;return Pt.compare(t,e,n,r),r.changes}var vm=class{constructor(){this.changes=[]}compareRange(e,n){Yo(e,n,this.changes)}comparePoint(){}boundChange(e){Yo(e,e,this.changes)}};function CT(t,e,n){let r=new vm;return Pt.compare(t,e,n,r),r.changes}function IT(t,e){for(let n=t;n&&n!=e;n=n.assignedSlot||n.parentNode)if(n.nodeType==1&&n.contentEditable=="false")return!0;return!1}function LT(t,e){let n=!1;return e&&t.iterChangedRanges((r,a)=>{r<e.to&&a>e.from&&(n=!0)}),n}var Fu=class extends zr{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}};function AT(t,e,n=1){let r=t.charCategorizer(e),a=t.doc.lineAt(e),s=e-a.from;if(a.length==0)return oe.cursor(e);s==0?n=1:s==a.length&&(n=-1);let i=s,o=s;n<0?i=Gn(a.text,s,!1):o=Gn(a.text,s);let l=r(a.text.slice(i,o));for(;i>0;){let u=Gn(a.text,i,!1);if(r(a.text.slice(u,i))!=l)break;i=u}for(;o<a.length;){let u=Gn(a.text,o);if(r(a.text.slice(o,u))!=l)break;o=u}return oe.undirectionalRange(i+a.from,o+a.from)}function PT(t,e,n,r,a){let s=Math.round((r-e.left)*t.defaultCharacterWidth);if(t.lineWrapping&&n.height>t.defaultLineHeight*1.5){let o=t.viewState.heightOracle.textHeight,l=Math.floor((a-n.top-(t.defaultLineHeight-o)*.5)/o);s+=l*t.viewState.heightOracle.lineLength}let i=t.state.sliceDoc(n.from,n.to);return n.from+vk(i,s,t.state.tabSize)}function wm(t,e,n){let r=t.lineBlockAt(e);if(Array.isArray(r.type)){let a;for(let s of r.type){if(s.from>e)break;if(!(s.to<e)){if(s.from<e&&s.to>e)return s;(!a||s.type==Xn.Text&&(a.type!=s.type||(n<0?s.from<e:s.to>e)))&&(a=s)}}return a||r}return r}function RT(t,e,n,r){let a=wm(t,e.head,e.assoc||-1),s=!r||a.type!=Xn.Text||!(t.lineWrapping||a.widgetLineBreaks)?null:t.coordsAtPos(e.assoc<0&&e.head>a.from?e.head-1:e.head);if(s){let i=t.dom.getBoundingClientRect(),o=t.textDirectionAt(a.from),l=t.posAtCoords({x:n==(o==nn.LTR)?i.right-1:i.left+1,y:(s.top+s.bottom)/2});if(l!=null)return oe.cursor(l,n?-1:1)}return oe.cursor(n?a.to:a.from,n?-1:1)}function Fk(t,e,n,r){let a=t.state.doc.lineAt(e.head),s=t.bidiSpans(a),i=t.textDirectionAt(a.from);for(let o=e,l=null;;){let u=cT(a,s,i,o,n),c=gS;if(!u){if(a.number==(n?t.state.doc.lines:1))return o;c=`
|
|
39
|
+
`,a=t.state.doc.line(a.number+(n?1:-1)),s=t.bidiSpans(a),u=n?oe.cursor(a.from,-1):oe.cursor(a.to,1)}if(l){if(!l(c))return o}else{if(!r)return u;l=r(c)}o=u}}function NT(t,e,n){let r=t.state.charCategorizer(e),a=r(n);return s=>{let i=r(s);return a==ya.Space&&(a=i),a==i}}function MT(t,e,n,r){let a=e.head,s=n?1:-1;if(a==(n?t.state.doc.length:0))return oe.cursor(a,e.assoc);let i=e.goalColumn,o,l=t.contentDOM.getBoundingClientRect(),u=t.coordsAtPos(a,e.assoc||((e.empty?n:e.head==e.from)?1:-1)),c=t.documentTop;if(u)i==null&&(i=u.left-l.left),o=s<0?u.top:u.bottom;else{let p=t.viewState.lineBlockAt(a);i==null&&(i=Math.min(l.right-l.left,t.defaultCharacterWidth*(a-p.from))),o=(s<0?p.top:p.bottom)+c}let d=l.left+i,f=t.viewState.heightOracle.textHeight>>1,h=r??f;for(let p=0;;p+=f){let g=o+(h+p)*s,m=km(t,{x:d,y:g},!1,s);if(n?g>l.bottom:g<l.top)return oe.cursor(m.pos,m.assoc);let x=t.coordsAtPos(m.pos,m.assoc),b=x?(x.top+x.bottom)/2:0;if(!x||(n?b>o:b<o))return oe.cursor(m.pos,m.assoc,void 0,i)}}function Eu(t,e,n){for(;;){let r=0;for(let a of t)a.between(e-1,e+1,(s,i,o)=>{if(e>s&&e<i){let l=r||n||(e-s<i-e?-1:1);e=l<0?s:i,r=l}});if(!r)return e}}function FS(t,e){let n=null;for(let r=0;r<e.ranges.length;r++){let a=e.ranges[r],s=null;if(a.empty){let i=Eu(t,a.from,0);i!=a.from&&(s=oe.cursor(i,-1))}else{let i=Eu(t,a.from,-1),o=Eu(t,a.to,1);(i!=a.from||o!=a.to)&&(a.undirectional?s=oe.undirectionalRange(a.from,a.to):s=oe.range(a.from==a.anchor?i:o,a.from==a.head?i:o))}s&&(n||(n=e.ranges.slice()),n[r]=s)}return n?oe.create(n,e.mainIndex):e}function em(t,e,n){let r=Eu(t.state.facet(ju).map(a=>a(t)),n.from,e.head>n.from?-1:1);return r==n.from?n:oe.cursor(r,r<n.from?1:-1)}var na=class{constructor(e,n){this.pos=e,this.assoc=n}};function km(t,e,n,r){let a=t.contentDOM.getBoundingClientRect(),s=a.top+t.viewState.paddingTop,{x:i,y:o}=e,l=o-s,u;for(;;){if(l<0)return new na(0,1);if(l>t.viewState.docHeight)return new na(t.state.doc.length,-1);if(u=t.elementAtHeight(l),r==null)break;if(u.type==Xn.Text){if(r<0?u.to<t.viewport.from:u.from>t.viewport.to)break;let f=t.docView.coordsAt(r<0?u.from:u.to,r>0?-1:1);if(f&&(r<0?f.top<=l+s:f.bottom>=l+s))break}let d=t.viewState.heightOracle.textHeight/2;l=r>0?u.bottom+d:u.top-d}if(t.viewport.from>=u.to||t.viewport.to<=u.from){if(n)return null;if(u.type==Xn.Text){let d=PT(t,a,u,i,o);return new na(d,d==u.from?1:-1)}}if(u.type!=Xn.Text)return l<(u.top+u.bottom)/2?new na(u.from,1):new na(u.to,-1);let c=t.docView.lineAt(u.from,2);return(!c||c.length!=u.length)&&(c=t.docView.lineAt(u.from,-2)),new Sm(t,i,o,t.textDirectionAt(u.from)).scanTile(c,u.from)}var Sm=class{constructor(e,n,r,a){this.view=e,this.x=n,this.y=r,this.baseDir=a,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to<e)&&(this.line=this.view.state.doc.lineAt(e),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(e,n){let{line:r,spans:a}=this.bidiSpansAt(e);return a[ra.find(a,e-r.from,-1,n)].level==this.baseDir}dirAt(e,n){let{line:r,spans:a}=this.bidiSpansAt(e);return a[ra.find(a,e-r.from,-1,n)].dir}bidiIn(e,n){let{spans:r,line:a}=this.bidiSpansAt(e);return r.length>1||r.length&&(r[0].level!=this.baseDir||r[0].to+a.from<n)}scan(e,n,r=!1){let a=0,s=e.length-1,i=new Set,o=this.bidiIn(e[0],e[s]),l,u,c=-1,d=1e9,f;e:for(;a<s;){let p=s-a,g=a+s>>1;t:if(i.has(g)){for(let b=1;b<p;b++){let y=g+b;if(y>=s&&(y-=p),!i.has(y)){g=y;break t}}break e}i.add(g);let m=n(g),x=0;if(m)for(let b=0;b<m.length;b++){let y=m[b];if(!(y.width==0&&m.length>1))if(y.bottom<this.y)(!l||l.bottom<y.bottom)&&(l=y),x=1;else if(y.top>this.y)(!u||u.top>y.top)&&(u=y),x=-1;else{let C=y.left>this.x?this.x-y.left:y.right<this.x?this.x-y.right:0,I=Math.abs(C);I<d&&(c=g,d=I,f=y),C&&(x=C<0==(this.baseDir==nn.LTR)?-1:1)}}x==-1&&(!o||this.baseDirAt(e[g],1))?s=g:x==1&&(!o||this.baseDirAt(e[g+1],-1))&&(a=g+1)}if(!f){if(!u&&!l)return{i:0,after:!1};let p=l&&(!u||this.y-l.bottom<u.top-this.y)?l:u;return this.y=(p.top+p.bottom)/2,this.scan(e,n,!0)}if(d&&!r){let{top:p,bottom:g}=f;if(l&&l.bottom>(p+p+g)/3)return this.y=l.bottom-1,this.scan(e,n,!0);if(u&&u.top<(p+g+g)/3)return this.y=u.top+1,this.scan(e,n,!0)}let h=(o?this.dirAt(e[c],1):this.baseDir)==nn.LTR;return{i:c,after:this.x>(f.left+f.right)/2==h}}scanText(e,n){let r=[];for(let s=0;s<e.length;s=Gn(e.text,s))r.push(n+s);r.push(n+e.length);let a=this.scan(r,s=>{let i=r[s]-n,o=r[s+1]-n;return Wu(e.dom,i,o).getClientRects()});return a.after?new na(r[a.i+1],-1):new na(r[a.i],1)}scanTile(e,n){if(!e.length)return new na(n,1);if(e.children.length==1){let o=e.children[0];if(o.isText())return this.scanText(o,n);if(o.isComposite())return this.scanTile(o,n)}let r=[n];for(let o=0,l=n;o<e.children.length;o++)r.push(l+=e.children[o].length);let a=this.scan(r,o=>{let l=e.children[o];return l.flags&48?null:(l.dom.nodeType==1?l.dom:Wu(l.dom,0,l.length)).getClientRects()}),s=e.children[a.i],i=r[a.i];return s.isText()?this.scanText(s,i):s.isComposite()?this.scanTile(s,i):a.after?new na(r[a.i+1],-1):new na(i,1)}},Vo="\uFFFF",Cm=class{constructor(e,n){this.points=e,this.view=n,this.text="",this.lineSeparator=n.state.facet(Dt.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=Vo}readRange(e,n){if(!e)return this;let r=e.parentNode;for(let a=e;;){this.findPointBefore(r,a);let s=this.text.length;this.readNode(a);let i=un.get(a),o=a.nextSibling;if(o==n){i?.breakAfter&&!o&&r!=this.view.contentDOM&&this.lineBreak();break}let l=un.get(o);(i&&l?i.breakAfter:(i?i.breakAfter:jd(a))||jd(o)&&(a.nodeName!="BR"||i?.isWidget())&&this.text.length>s)&&!DT(o,n)&&this.lineBreak(),a=o}return this.findPointBefore(r,n),this}readTextNode(e){let n=e.nodeValue;for(let r of this.points)r.node==e&&(r.pos=this.text.length+Math.min(r.offset,n.length));for(let r=0,a=this.lineSeparator?null:/\r\n?|\n/g;;){let s=-1,i=1,o;if(this.lineSeparator?(s=n.indexOf(this.lineSeparator,r),i=this.lineSeparator.length):(o=a.exec(n))&&(s=o.index,i=o[0].length),this.append(n.slice(r,s<0?n.length:s)),s<0)break;if(this.lineBreak(),i>1)for(let l of this.points)l.node==e&&l.pos>this.text.length&&(l.pos-=i-1);r=s+i}}readNode(e){let n=un.get(e),r=n&&n.overrideDOMText;if(r!=null){this.findPointInside(e,r.length);for(let a=r.iter();!a.next().done;)a.lineBreak?this.lineBreak():this.append(a.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,n){for(let r of this.points)r.node==e&&e.childNodes[r.offset]==n&&(r.pos=this.text.length)}findPointInside(e,n){for(let r of this.points)(e.nodeType==3?r.node==e:e.contains(r.node))&&(r.pos=this.text.length+(TT(e,r.node,r.offset)?n:0))}};function TT(t,e,n){for(;;){if(!e||n<vs(e))return!1;if(e==t)return!0;n=ni(e)+1,e=e.parentNode}}function DT(t,e){let n;for(;!(t==e||!t);t=t.nextSibling){let r=un.get(t);if(!r?.isWidget())return!1;r&&(n||(n=[])).push(r)}if(n)for(let r of n){let a=r.overrideDOMText;if(a?.length)return!1}return!0}var Kd=class{constructor(e,n){this.node=e,this.offset=n,this.pos=-1}},Im=class{constructor(e,n,r,a){this.typeOver=a,this.bounds=null,this.text="",this.domChanged=n>-1;let{impreciseHead:s,impreciseAnchor:i}=e.docView,o=e.state.selection;if(e.state.readOnly&&n>-1)this.newSel=null;else if(n>-1&&(this.bounds=ES(e.docView.tile,n,r,0))){let l=s||i?[]:ET(e),u=new Cm(l,e);u.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=u.text,this.newSel=OT(l,this.bounds.from)}else{let l=e.observer.selectionRange,u=s&&s.node==l.focusNode&&s.offset==l.focusOffset||!om(e.contentDOM,l.focusNode)?o.main.head:e.docView.posFromDOM(l.focusNode,l.focusOffset),c=i&&i.node==l.anchorNode&&i.offset==l.anchorOffset||!om(e.contentDOM,l.anchorNode)?o.main.anchor:e.docView.posFromDOM(l.anchorNode,l.anchorOffset),d=e.viewport;if((Ie.ios||Ie.chrome)&&u!=c&&Math.min(u,c)<=o.main.from&&Math.max(u,c)>=o.main.to&&(d.from>0||d.to<e.state.doc.length)){let f=Math.min(u,c),h=Math.max(u,c),p=d.from-f,g=d.to-h;(p==0||p==1||f==0)&&(g==0||g==-1||h==e.state.doc.length)&&(u=0,c=e.state.doc.length)}if(e.inputState.composing>-1&&o.ranges.length>1)this.newSel=o.replaceRange(oe.range(c,u));else if(e.lineWrapping&&c==u&&!(o.main.empty&&o.main.head==u)&&e.inputState.lastTouchTime>Date.now()-100){let f=e.coordsAtPos(u,-1),h=0;f&&(h=e.inputState.lastTouchY<=f.bottom?-1:1),this.newSel=oe.create([oe.cursor(u,h)])}else this.newSel=oe.single(c,u)}}};function ES(t,e,n,r){if(t.isComposite()){let a=-1,s=-1,i=-1,o=-1;for(let l=0,u=r,c=r;l<t.children.length;l++){let d=t.children[l],f=u+d.length;if(u<e&&f>n)return ES(d,e,n,u);if(f>=e&&a==-1&&(a=l,s=u),u>n&&d.dom.parentNode==t.dom){i=l,o=c;break}c=f,u=f+d.breakAfter}return{from:s,to:o<0?r+t.length:o,startDOM:(a?t.children[a-1].dom.nextSibling:null)||t.dom.firstChild,endDOM:i<t.children.length&&i>=0?t.children[i].dom:null}}else return t.isText()?{from:r,to:r+t.length,startDOM:t.dom,endDOM:t.dom.nextSibling}:null}function OS(t,e){let n,{newSel:r}=e,{state:a}=t,s=a.selection.main,i=t.inputState.lastKeyTime>Date.now()-100?t.inputState.lastKeyCode:-1;if(e.bounds){let{from:o,to:l}=e.bounds,u=s.from,c=null;(i===8||Ie.android&&e.text.length<l-o)&&(u=s.to,c="end");let d=a.doc.sliceString(o,l,Vo),f,h;!s.empty&&s.from>=o&&s.to<=l&&(e.typeOver||d!=e.text)&&d.slice(0,s.from-o)==e.text.slice(0,s.from-o)&&d.slice(s.to-o)==e.text.slice(f=e.text.length-(d.length-(s.to-o)))?n={from:s.from,to:s.to,insert:mt.of(e.text.slice(s.from-o,f).split(Vo))}:(h=BS(d,e.text,u-o,c))&&(Ie.chrome&&i==13&&h.toB==h.from+2&&e.text.slice(h.from,h.toB)==Vo+Vo&&h.toB--,n={from:o+h.from,to:o+h.toA,insert:mt.of(e.text.slice(h.from,h.toB).split(Vo))})}else r&&(!t.hasFocus&&a.facet(bs)||Xd(r,s))&&(r=null);if(!n&&!r)return!1;if((Ie.mac||Ie.android)&&n&&n.from==n.to&&n.from==s.head-1&&/^\. ?$/.test(n.insert.toString())&&t.contentDOM.getAttribute("autocorrect")=="off"?(r&&n.insert.length==2&&(r=oe.single(r.main.anchor-1,r.main.head-1)),n={from:n.from,to:n.to,insert:mt.of([n.insert.toString().replace("."," ")])}):a.doc.lineAt(s.from).to<s.to&&t.docView.lineHasWidget(s.to)&&t.inputState.insertingTextAt>Date.now()-50?n={from:s.from,to:s.to,insert:a.toText(t.inputState.insertingText)}:Ie.chrome&&n&&n.from==n.to&&n.from==s.head&&n.insert.toString()==`
|
|
40
|
+
`&&t.lineWrapping&&(r&&(r=oe.single(r.main.anchor-1,r.main.head-1)),n={from:s.from,to:s.to,insert:mt.of([" "])}),n)return eg(t,n,r,i);if(r&&!Xd(r,s)){let o=!1,l="select";return t.inputState.lastSelectionTime>Date.now()-50&&(t.inputState.lastSelectionOrigin=="select"&&(o=!0),l=t.inputState.lastSelectionOrigin,l=="select.pointer"&&(r=FS(a.facet(ju).map(u=>u(t)),r))),t.dispatch({selection:r,scrollIntoView:o,userEvent:l}),!0}else return!1}function eg(t,e,n,r=-1){if(Ie.ios&&t.inputState.flushIOSKey(e))return!0;let a=t.state.selection.main;if(Ie.android&&(e.to==a.to&&(e.from==a.from||e.from==a.from-1&&t.state.sliceDoc(e.from,a.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&Jo(t.contentDOM,"Enter",13)||(e.from==a.from-1&&e.to==a.to&&e.insert.length==0||r==8&&e.insert.length<e.to-e.from&&e.to>a.head)&&Jo(t.contentDOM,"Backspace",8)||e.from==a.from&&e.to==a.to+1&&e.insert.length==0&&Jo(t.contentDOM,"Delete",46)))return!0;let s=e.insert.toString();t.inputState.composing>=0&&t.inputState.composing++;let i,o=()=>i||(i=FT(t,e,n));return t.state.facet(wS).some(l=>l(t,e.from,e.to,s,o))||t.dispatch(o()),!0}function FT(t,e,n){let r,a=t.state,s=a.selection.main,i=-1;if(e.from==e.to&&e.from<s.from||e.from>s.to){let l=e.from<s.from?-1:1,u=l<0?s.from:s.to,c=Eu(a.facet(ju).map(d=>d(t)),u,l);e.from==c&&(i=c)}if(i>-1)r={changes:e,selection:oe.cursor(e.from+e.insert.length,-1)};else if(e.from>=s.from&&e.to<=s.to&&e.to-e.from>=(s.to-s.from)/3&&(!n||n.main.empty&&n.main.from==e.from+e.insert.length)&&t.inputState.composing<0){let l=s.from<e.from?a.sliceDoc(s.from,e.from):"",u=s.to>e.to?a.sliceDoc(e.to,s.to):"";r=a.replaceSelection(t.state.toText(l+e.insert.sliceString(0,void 0,t.state.lineBreak)+u))}else{let l=a.changes(e),u=n&&n.main.to<=l.newLength?n.main:void 0;if(a.selection.ranges.length>1&&(t.inputState.composing>=0||t.inputState.compositionPendingChange)&&e.to<=s.to+10&&e.to>=s.to-10){let c=t.state.sliceDoc(e.from,e.to),d,f=n&&DS(t,n.main.head);if(f){let p=e.insert.length-(e.to-e.from);d={from:f.from,to:f.to-p}}else d=t.state.doc.lineAt(s.head);let h=s.to-e.to;r=a.changeByRange(p=>{if(p.from==s.from&&p.to==s.to)return{changes:l,range:u||p.map(l)};let g=p.to-h,m=g-c.length;if(t.state.sliceDoc(m,g)!=c||g>=d.from&&m<=d.to)return{range:p};let x=a.changes({from:m,to:g,insert:e.insert}),b=p.to-s.to;return{changes:x,range:u?oe.range(Math.max(0,u.anchor+b),Math.max(0,u.head+b)):p.map(x)}})}else r={changes:l,selection:u&&a.selection.replaceRange(u)}}let o="input.type";return(t.composing||t.inputState.compositionPendingChange&&t.inputState.compositionEndedAt>Date.now()-50)&&(t.inputState.compositionPendingChange=!1,o+=".compose",t.inputState.compositionFirstChange&&(o+=".start",t.inputState.compositionFirstChange=!1)),a.update(r,{userEvent:o,scrollIntoView:!0})}function BS(t,e,n,r){let a=Math.min(t.length,e.length),s=0;for(;s<a&&t.charCodeAt(s)==e.charCodeAt(s);)s++;if(s==a&&t.length==e.length)return null;let i=t.length,o=e.length;for(;i>0&&o>0&&t.charCodeAt(i-1)==e.charCodeAt(o-1);)i--,o--;if(r=="end"){let l=Math.max(0,s-Math.min(i,o));n-=i+l-s}if(i<s&&t.length<e.length){let l=n<=s&&n>=i?s-n:0;s-=l,o=s+(o-i),i=s}else if(o<s){let l=n<=s&&n>=o?s-n:0;s-=l,i=s+(i-o),o=s}return{from:s,toA:i,toB:o}}function ET(t){let e=[];if(t.root.activeElement!=t.contentDOM)return e;let{anchorNode:n,anchorOffset:r,focusNode:a,focusOffset:s}=t.observer.selectionRange;return n&&(e.push(new Kd(n,r)),(a!=n||s!=r)&&e.push(new Kd(a,s))),e}function OT(t,e){if(t.length==0)return null;let n=t[0].pos,r=t.length==2?t[1].pos:n;return n<0||r<0?null:n==r?oe.create([oe.cursor(r+e,-1)]):oe.single(n+e,r+e)}function Xd(t,e){return e.head==t.main.head&&e.anchor==t.main.anchor}var Lm=class{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.touchActive=!1,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.lastIOSMomentumScroll=0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,Ie.safari&&e.contentDOM.addEventListener("input",()=>null),Ie.gecko&&JT(e.contentDOM.ownerDocument)}handleEvent(e){!jT(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(e.type,e)):this.runHandlers(e.type,e))}runHandlers(e,n){let r=this.handlers[e];if(r){for(let a of r.observers)a(this.view,n);for(let a of r.handlers){if(n.defaultPrevented)break;if(a(this.view,n)){n.preventDefault();break}}}}ensureHandlers(e){let n=_T(e),r=this.handlers,a=this.view.contentDOM;for(let s in n)if(s!="scroll"){let i=!n[s].handlers.length,o=r[s];o&&i!=!o.handlers.length&&(a.removeEventListener(s,this.handleEvent),o=null),o||a.addEventListener(s,this.handleEvent,{passive:i})}for(let s in r)s!="scroll"&&!n[s]&&a.removeEventListener(s,this.handleEvent);this.handlers=n}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&HS.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),Ie.android&&Ie.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;if(Ie.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&(_S.some(n=>n.keyCode==e.keyCode)&&!e.ctrlKey||HT.indexOf(e.key)>-1&&e.ctrlKey)){let n={ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey,shiftKey:e.shiftKey};n.shiftKey&&Ie.ios&&!/^(off|none)$/.test(this.view.contentDOM.autocapitalize)&&BT(this.view.win)&&(n.shiftKey=!1);let r=this.pendingIOSKey={key:e.key,keyCode:e.keyCode,mods:n};return setTimeout(()=>{this.pendingIOSKey==r&&this.flushIOSKey()},50),!0}return e.keyCode!=229&&this.view.observer.forceFlush(),!1}flushIOSKey(e){let n=this.pendingIOSKey;return!n||this.view.observer.pendingRecords().length||n.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,Jo(this.view.contentDOM,n.key,n.keyCode,n.mods))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:Ie.safari&&!Ie.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}};function BT(t){return t.visualViewport?t.visualViewport.height*t.visualViewport.scale/t.document.documentElement.clientHeight<.85:!1}function Ek(t,e){return(n,r)=>{try{return e.call(t,r,n)}catch(a){wa(n.state,a)}}}function _T(t){let e=Object.create(null);function n(r){return e[r]||(e[r]={observers:[],handlers:[]})}for(let r of t){let a=r.spec,s=a&&a.plugin.domEventHandlers,i=a&&a.plugin.domEventObservers;if(s)for(let o in s){let l=s[o];l&&n(o).handlers.push(Ek(r.value,l))}if(i)for(let o in i){let l=i[o];l&&n(o).observers.push(Ek(r.value,l))}}for(let r in Sa)n(r).handlers.push(Sa[r]);for(let r in xr)n(r).observers.push(xr[r]);return e}var _S=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],HT="dthko",HS=[16,17,18,20,91,92,224,225],Dd=6;function Fd(t){return Math.max(0,t)*.7+8}function UT(t,e){return Math.max(Math.abs(t.clientX-e.clientX),Math.abs(t.clientY-e.clientY))}var Am=class{constructor(e,n,r,a){this.view=e,this.startEvent=n,this.style=r,this.mustSelect=a,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=n,this.scrollParents=sS(e.contentDOM),this.atoms=e.state.facet(ju).map(i=>i(e));let s=e.contentDOM.ownerDocument;s.addEventListener("mousemove",this.move=this.move.bind(this)),s.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=n.shiftKey,this.multiple=e.state.facet(Dt.allowMultipleSelections)&>(e,n),this.dragging=WT(e,n)&&zS(n)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&UT(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let n=0,r=0,a=0,s=0,i=this.view.win.innerWidth,o=this.view.win.innerHeight;this.scrollParents.x&&({left:a,right:i}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:s,bottom:o}=this.scrollParents.y.getBoundingClientRect());let l=MS(this.view);e.clientX-l.left<=a+Dd?n=-Fd(a-e.clientX):e.clientX+l.right>=i-Dd&&(n=Fd(e.clientX-i)),e.clientY-l.top<=s+Dd?r=-Fd(s-e.clientY):e.clientY+l.bottom>=o-Dd&&(r=Fd(e.clientY-o)),this.setScrollSpeed(n,r)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,n){this.scrollSpeed={x:e,y:n},e||n?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:n}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),n&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=n,n=0),(e||n)&&this.view.win.scrollBy(e,n),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:n}=this,r=FS(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!r.eq(n.state.selection,this.dragging===!1))&&this.view.dispatch({selection:r,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(n=>n.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}};function GT(t,e){let n=t.state.facet(xS);return n.length?n[0](e):Ie.mac?e.metaKey:e.ctrlKey}function zT(t,e){let n=t.state.facet(bS);return n.length?n[0](e):Ie.mac?!e.altKey:!e.ctrlKey}function WT(t,e){let{main:n}=t.state.selection;if(n.empty)return!1;let r=Gu(t.root);if(!r||r.rangeCount==0)return!0;let a=r.getRangeAt(0).getClientRects();for(let s=0;s<a.length;s++){let i=a[s];if(i.left<=e.clientX&&i.right>=e.clientX&&i.top<=e.clientY&&i.bottom>=e.clientY)return!0}return!1}function jT(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let n=e.target,r;n!=t.contentDOM;n=n.parentNode)if(!n||n.nodeType==11||(r=un.get(n))&&r.isWidget()&&!r.isHidden&&r.widget.ignoreEvent(e))return!1;return!0}var Sa=Object.create(null),xr=Object.create(null),US=Ie.ie&&Ie.ie_version<15||Ie.ios&&Ie.webkit_version<604;function qT(t){let e=t.dom.parentNode;if(!e)return;let n=e.appendChild(document.createElement("textarea"));n.style.cssText="position: fixed; left: -10000px; top: 10px",n.focus(),setTimeout(()=>{t.focus(),n.remove(),GS(t,n.value)},50)}function af(t,e,n){for(let r of t.facet(e))n=r(n,t);return n}function GS(t,e){e=af(t.state,Ym,e);let{state:n}=t,r,a=1,s=n.toText(e),i=s.lines==n.selection.ranges.length;if(Pm!=null&&n.selection.ranges.every(l=>l.empty)&&Pm==s.toString()){let l=-1;r=n.changeByRange(u=>{let c=n.doc.lineAt(u.from);if(c.from==l)return{range:u};l=c.from;let d=n.toText((i?s.line(a++).text:e)+n.lineBreak);return{changes:{from:c.from,insert:d},range:oe.cursor(u.from+d.length,-1)}})}else i?r=n.changeByRange(l=>{let u=s.line(a++);return{changes:{from:l.from,to:l.to,insert:u.text},range:oe.cursor(l.from+u.length,-1)}}):r=n.replaceSelection(s);t.dispatch(r,{userEvent:"input.paste",scrollIntoView:!0})}xr.scroll=t=>{let e=t.inputState;e.lastScrollTop=t.scrollDOM.scrollTop,e.lastScrollLeft=t.scrollDOM.scrollLeft,Ie.ios&&!e.touchActive&&(e.lastIOSMomentumScroll=Date.now())};xr.wheel=xr.mousewheel=t=>{t.inputState.lastWheelEvent=Date.now()};Sa.keydown=(t,e)=>(t.inputState.setSelectionOrigin("select"),e.keyCode==27&&t.inputState.tabFocusMode!=0&&(t.inputState.tabFocusMode=Date.now()+2e3),!1);xr.touchstart=(t,e)=>{let n=t.inputState,r=e.targetTouches[0];n.touchActive=!0,n.lastTouchTime=Date.now(),r&&(n.lastTouchX=r.clientX,n.lastTouchY=r.clientY),n.setSelectionOrigin("select.pointer")};xr.touchmove=t=>{t.inputState.setSelectionOrigin("select.pointer")};xr.touchend=(t,e)=>{t.inputState.touchActive=!1};Sa.mousedown=(t,e)=>{if(t.observer.flush(),t.inputState.lastTouchTime>Date.now()-2e3)return!1;let n=null;for(let r of t.state.facet(yS))if(n=r(t,e),n)break;if(!n&&e.button==0&&(n=$T(t,e)),n){let r=!t.hasFocus;t.inputState.startMouseSelection(new Am(t,e,n,r)),r&&t.observer.ignore(()=>{lS(t.contentDOM);let s=t.root.activeElement;s&&!s.contains(t.contentDOM)&&s.blur()});let a=t.inputState.mouseSelection;if(a)return a.start(e),a.dragging===!1}else t.inputState.setSelectionOrigin("select.pointer");return!1};function Ok(t,e,n,r){if(r==1)return oe.cursor(e,n);if(r==2)return AT(t.state,e,n);{let a=t.docView.lineAt(e,n),s=t.state.doc.lineAt(a?a.posAtEnd:e),i=a?a.posAtStart:s.from,o=a?a.posAtEnd:s.to;return o<t.state.doc.length&&o==s.to&&o++,oe.undirectionalRange(i,o)}}var VT=Ie.ie&&Ie.ie_version<=11,Bk=null,_k=0,Hk=0;function zS(t){if(!VT)return t.detail;let e=Bk,n=Hk;return Bk=t,Hk=Date.now(),_k=!e||n>Date.now()-400&&Math.abs(e.clientX-t.clientX)<2&&Math.abs(e.clientY-t.clientY)<2?(_k+1)%3:1}function $T(t,e){let n=t.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),r=zS(e),a=t.state.selection;return{update(s){s.docChanged&&(n.pos=s.changes.mapPos(n.pos),a=a.map(s.changes))},get(s,i,o){let l=t.posAndSideAtCoords({x:s.clientX,y:s.clientY},!1),u,c=Ok(t,l.pos,l.assoc,r);if(n.pos!=l.pos&&!i){let d=Ok(t,n.pos,n.assoc,r),f=Math.min(d.from,c.from),h=Math.max(d.to,c.to);c=f<c.from?oe.range(f,h,c.assoc):oe.range(h,f,c.assoc)}return i?a.replaceRange(a.main.extend(c.from,c.to,c.assoc)):o&&r==1&&a.ranges.length>1&&(u=KT(a,l.pos))?u:o?a.addRange(c):oe.create([c])}}}function KT(t,e){for(let n=0;n<t.ranges.length;n++){let{from:r,to:a}=t.ranges[n];if(r<=e&&a>=e)return oe.create(t.ranges.slice(0,n).concat(t.ranges.slice(n+1)),t.mainIndex==n?0:t.mainIndex-(t.mainIndex>n?1:0))}return null}Sa.dragstart=(t,e)=>{let{selection:{main:n}}=t.state;if(e.target.draggable){let a=t.docView.tile.nearest(e.target);if(a&&a.isWidget()){let s=a.posAtStart,i=s+a.length;(s>=n.to||i<=n.from)&&(n=oe.undirectionalRange(s,i))}}let{inputState:r}=t;return r.mouseSelection&&(r.mouseSelection.dragging=!0),r.draggedContent=n,e.dataTransfer&&(e.dataTransfer.setData("Text",af(t.state,Jm,t.state.sliceDoc(n.from,n.to))),e.dataTransfer.effectAllowed="copyMove"),!1};Sa.dragend=t=>(t.inputState.draggedContent=null,!1);function Uk(t,e,n,r){if(n=af(t.state,Ym,n),!n)return;let a=t.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:s}=t.inputState,i=r&&s&&zT(t,e)?{from:s.from,to:s.to}:null,o={from:a,insert:n},l=t.state.changes(i?[i,o]:o);t.focus(),t.dispatch({changes:l,selection:{anchor:l.mapPos(a,-1),head:l.mapPos(a,1)},userEvent:i?"move.drop":"input.drop"}),t.inputState.draggedContent=null}Sa.drop=(t,e)=>{if(!e.dataTransfer)return!1;if(t.state.readOnly)return!0;let n=e.dataTransfer.files;if(n&&n.length){let r=Array(n.length),a=0,s=()=>{++a==n.length&&Uk(t,e,r.filter(i=>i!=null).join(t.state.lineBreak),!1)};for(let i=0;i<n.length;i++){let o=new FileReader;o.onerror=s,o.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(o.result)||(r[i]=o.result),s()},o.readAsText(n[i])}return!0}else{let r=e.dataTransfer.getData("Text");if(r)return Uk(t,e,r,!0),!0}return!1};Sa.paste=(t,e)=>{if(t.state.readOnly)return!0;t.observer.flush();let n=US?null:e.clipboardData;return n?(GS(t,n.getData("text/plain")||n.getData("text/uri-list")),!0):(qT(t),!1)};function XT(t,e){let n=t.dom.parentNode;if(!n)return;let r=n.appendChild(document.createElement("textarea"));r.style.cssText="position: fixed; left: -10000px; top: 10px",r.value=e,r.focus(),r.selectionEnd=e.length,r.selectionStart=0,setTimeout(()=>{r.remove(),t.focus()},50)}function YT(t){let e=[],n=[],r=!1;for(let a of t.selection.ranges)a.empty||(e.push(t.sliceDoc(a.from,a.to)),n.push(a));if(!e.length){let a=-1;for(let{from:s}of t.selection.ranges){let i=t.doc.lineAt(s);i.number>a&&(e.push(i.text),n.push({from:i.from,to:Math.min(t.doc.length,i.to+1)})),a=i.number}r=!0}return{text:af(t,Jm,e.join(t.lineBreak)),ranges:n,linewise:r}}var Pm=null;Sa.copy=Sa.cut=(t,e)=>{if(!Ru(t.contentDOM,t.observer.selectionRange))return!1;let{text:n,ranges:r,linewise:a}=YT(t.state);if(!n&&!a)return!1;Pm=a?n:null,e.type=="cut"&&!t.state.readOnly&&t.dispatch({changes:r,scrollIntoView:!0,userEvent:"delete.cut"});let s=US?null:e.clipboardData;return s?(s.clearData(),s.setData("text/plain",n),!0):(XT(t,n),!1)};var WS=ea.define();function jS(t,e){let n=[];for(let r of t.facet(kS)){let a=r(t,e);a&&n.push(a)}return n.length?t.update({effects:n,annotations:WS.of(!0)}):null}function qS(t){setTimeout(()=>{let e=t.hasFocus;if(e!=t.inputState.notifiedFocused){let n=jS(t.state,e);n?t.dispatch(n):t.update([])}},10)}xr.focus=t=>{t.inputState.lastFocusTime=Date.now(),!t.scrollDOM.scrollTop&&(t.inputState.lastScrollTop||t.inputState.lastScrollLeft)&&(t.scrollDOM.scrollTop=t.inputState.lastScrollTop,t.scrollDOM.scrollLeft=t.inputState.lastScrollLeft),qS(t)};xr.blur=t=>{t.observer.clearSelectionRange(),qS(t)};xr.compositionstart=xr.compositionupdate=t=>{if(!t.observer.editContext&&(t.inputState.compositionFirstChange==null&&(t.inputState.compositionFirstChange=!0),t.inputState.composing<0)){let{main:e}=t.state.selection;!e.empty&&t.lineBlockAt(e.from).from!=t.lineBlockAt(e.to).from&&t.dispatch({changes:t.state.selection.ranges.filter(n=>!n.empty).map(n=>({from:n.from,to:n.to})),userEvent:"input"}),t.inputState.composing=0}};xr.compositionend=t=>{t.observer.editContext||(t.inputState.composing=-1,t.inputState.compositionEndedAt=Date.now(),t.inputState.compositionPendingKey=!0,t.inputState.compositionPendingChange=t.observer.pendingRecords().length>0,t.inputState.compositionFirstChange=null,Ie.chrome&&Ie.android?t.observer.flushSoon():t.inputState.compositionPendingChange?Promise.resolve().then(()=>t.observer.flush()):setTimeout(()=>{t.inputState.composing<0&&t.docView.hasComposition&&t.update([])},50))};xr.contextmenu=t=>{t.inputState.lastContextMenu=Date.now()};Sa.beforeinput=(t,e)=>{var n,r;if((e.inputType=="insertText"||e.inputType=="insertCompositionText")&&(t.inputState.insertingText=e.data,t.inputState.insertingTextAt=Date.now()),e.inputType=="insertReplacementText"&&t.observer.editContext){let s=(n=e.dataTransfer)===null||n===void 0?void 0:n.getData("text/plain"),i=e.getTargetRanges();if(s&&i.length){let o=i[0],l=t.posAtDOM(o.startContainer,o.startOffset),u=t.posAtDOM(o.endContainer,o.endOffset);return eg(t,{from:l,to:u,insert:t.state.toText(s)},null),!0}}let a;if(Ie.chrome&&Ie.android&&(a=_S.find(s=>s.inputType==e.inputType))&&(t.observer.delayAndroidKey(a.key,a.keyCode),a.key=="Backspace"||a.key=="Delete")){let s=((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0;setTimeout(()=>{var i;(((i=window.visualViewport)===null||i===void 0?void 0:i.height)||0)>s+10&&t.hasFocus&&(t.contentDOM.blur(),t.focus())},100)}return Ie.ios&&e.inputType=="deleteContentForward"&&t.observer.flushSoon(),Ie.safari&&e.inputType=="insertText"&&t.inputState.composing>=0&&setTimeout(()=>xr.compositionend(t,e),20),!1};var Gk=new Set;function JT(t){Gk.has(t)||(Gk.add(t),t.addEventListener("copy",()=>{}),t.addEventListener("cut",()=>{}))}var zk=["pre-wrap","normal","pre-line","break-spaces"],nl=!1;function Wk(){nl=!1}var Rm=class{constructor(e){this.lineWrapping=e,this.doc=mt.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,n){let r=this.doc.lineAt(n).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(r+=Math.max(0,Math.ceil((n-e-r*this.lineLength*.5)/this.lineLength))),this.lineHeight*r}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return zk.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let n=!1;for(let r=0;r<e.length;r++){let a=e[r];a<0?r++:this.heightSamples[Math.floor(a*10)]||(n=!0,this.heightSamples[Math.floor(a*10)]=!0)}return n}refresh(e,n,r,a,s,i){let o=zk.indexOf(e)>-1,l=Math.abs(n-this.lineHeight)>.3||this.lineWrapping!=o;if(this.lineWrapping=o,this.lineHeight=n,this.charWidth=r,this.textHeight=a,this.lineLength=s,l){this.heightSamples={};for(let u=0;u<i.length;u++){let c=i[u];c<0?u++:this.heightSamples[Math.floor(c*10)]=!0}}return l}},Nm=class{constructor(e,n){this.from=e,this.heights=n,this.index=0}get more(){return this.index<this.heights.length}},va=class t{constructor(e,n,r,a,s){this.from=e,this.length=n,this.top=r,this.height=a,this._content=s}get type(){return typeof this._content=="number"?Xn.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof ji?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let n=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new t(this.from,this.length+e.length,this.top,this.height+e.height,n)}},tn=(function(t){return t[t.ByPos=0]="ByPos",t[t.ByHeight=1]="ByHeight",t[t.ByPosNoHeight=2]="ByPosNoHeight",t})(tn||(tn={})),Hd=.001,Gr=class t{constructor(e,n,r=2){this.length=e,this.height=n,this.flags=r}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>Hd&&(nl=!0),this.height=e)}replace(e,n,r){return t.of(r)}decomposeLeft(e,n){n.push(this)}decomposeRight(e,n){n.push(this)}applyChanges(e,n,r,a){let s=this,i=r.doc;for(let o=a.length-1;o>=0;o--){let{fromA:l,toA:u,fromB:c,toB:d}=a[o],f=s.lineAt(l,tn.ByPosNoHeight,r.setDoc(n),0,0),h=f.to>=u?f:s.lineAt(u,tn.ByPosNoHeight,r,0,0);for(d+=h.to-u,u=h.to;o>0&&f.from<=a[o-1].toA;)l=a[o-1].fromA,c=a[o-1].fromB,o--,l<f.from&&(f=s.lineAt(l,tn.ByPosNoHeight,r,0,0));c+=f.from-l,l=f.from;let p=Tm.build(r.setDoc(i),e,c,d);s=Yd(s,s.replace(l,u,p))}return s.updateHeight(r,0)}static empty(){return new ta(0,0,0)}static of(e){if(e.length==1)return e[0];let n=0,r=e.length,a=0,s=0;for(;;)if(n==r)if(a>s*2){let o=e[n-1];o.break?e.splice(--n,1,o.left,null,o.right):e.splice(--n,1,o.left,o.right),r+=1+o.break,a-=o.size}else if(s>a*2){let o=e[r];o.break?e.splice(r,1,o.left,null,o.right):e.splice(r,1,o.left,o.right),r+=2+o.break,s-=o.size}else break;else if(a<s){let o=e[n++];o&&(a+=o.size)}else{let o=e[--r];o&&(s+=o.size)}let i=!1;return e[n-1]==null?(i=!0,n--):e[n]==null&&(i=!0,r++),new Mm(t.of(e.slice(0,n)),i,t.of(e.slice(r)))}};function Yd(t,e){return t==e?t:(t.constructor!=e.constructor&&(nl=!0),e)}Gr.prototype.size=1;var ZT=Ze.replace({}),Jd=class extends Gr{constructor(e,n,r){super(e,n),this.deco=r,this.spaceAbove=0}mainBlock(e,n){return new va(n,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,n,r,a){return this.spaceAbove&&e<r+this.spaceAbove?new va(a,0,r,this.spaceAbove,ZT):this.mainBlock(r,a)}lineAt(e,n,r,a,s){let i=this.mainBlock(a,s);return this.spaceAbove?this.blockAt(0,r,a,s).join(i):i}forEachLine(e,n,r,a,s,i){e<=s+this.length&&n>=s&&i(this.lineAt(0,tn.ByPos,r,a,s))}setMeasuredHeight(e){let n=e.heights[e.index++];n<0?(this.spaceAbove=-n,n=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(n)}updateHeight(e,n=0,r=!1,a){return a&&a.from<=n&&a.more&&this.setMeasuredHeight(a),this.outdated=!1,this}toString(){return`block(${this.length})`}},ta=class t extends Jd{constructor(e,n,r){super(e,n,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=r}mainBlock(e,n){return new va(n,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,n,r){let a=r[0];return r.length==1&&(a instanceof t||a instanceof ti&&a.flags&4)&&Math.abs(this.length-a.length)<10?(a instanceof ti?a=new t(a.length,this.height,this.spaceAbove):a.height=this.height,this.outdated||(a.outdated=!1),a):Gr.of(r)}updateHeight(e,n=0,r=!1,a){return a&&a.from<=n&&a.more?this.setMeasuredHeight(a):(r||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}},ti=class t extends Gr{constructor(e){super(e,0)}heightMetrics(e,n){let r=e.doc.lineAt(n).number,a=e.doc.lineAt(n+this.length).number,s=a-r+1,i,o=0;if(e.lineWrapping){let l=Math.min(this.height,e.lineHeight*s);i=l/s,this.length>s+1&&(o=(this.height-l)/(this.length-s-1))}else i=this.height/s;return{firstLine:r,lastLine:a,perLine:i,perChar:o}}blockAt(e,n,r,a){let{firstLine:s,lastLine:i,perLine:o,perChar:l}=this.heightMetrics(n,a);if(n.lineWrapping){let u=a+(e<n.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-r)/this.height))*this.length)),c=n.doc.lineAt(u),d=o+c.length*l,f=Math.max(r,e-d/2);return new va(c.from,c.length,f,d,0)}else{let u=Math.max(0,Math.min(i-s,Math.floor((e-r)/o))),{from:c,length:d}=n.doc.line(s+u);return new va(c,d,r+o*u,o,0)}}lineAt(e,n,r,a,s){if(n==tn.ByHeight)return this.blockAt(e,r,a,s);if(n==tn.ByPosNoHeight){let{from:h,to:p}=r.doc.lineAt(e);return new va(h,p-h,0,0,0)}let{firstLine:i,perLine:o,perChar:l}=this.heightMetrics(r,s),u=r.doc.lineAt(e),c=o+u.length*l,d=u.number-i,f=a+o*d+l*(u.from-s-d);return new va(u.from,u.length,Math.max(a,Math.min(f,a+this.height-c)),c,0)}forEachLine(e,n,r,a,s,i){e=Math.max(e,s),n=Math.min(n,s+this.length);let{firstLine:o,perLine:l,perChar:u}=this.heightMetrics(r,s);for(let c=e,d=a;c<=n;){let f=r.doc.lineAt(c);if(c==e){let p=f.number-o;d+=l*p+u*(e-s-p)}let h=l+u*f.length;i(new va(f.from,f.length,d,h,0)),d+=h,c=f.to+1}}replace(e,n,r){let a=this.length-n;if(a>0){let s=r[r.length-1];s instanceof t?r[r.length-1]=new t(s.length+a):r.push(null,new t(a-1))}if(e>0){let s=r[0];s instanceof t?r[0]=new t(e+s.length):r.unshift(new t(e-1),null)}return Gr.of(r)}decomposeLeft(e,n){n.push(new t(e-1),null)}decomposeRight(e,n){n.push(null,new t(this.length-e-1))}updateHeight(e,n=0,r=!1,a){let s=n+this.length;if(a&&a.from<=n+this.length&&a.more){let i=[],o=Math.max(n,a.from),l=-1;for(a.from>n&&i.push(new t(a.from-n-1).updateHeight(e,n));o<=s&&a.more;){let c=e.doc.lineAt(o).length;i.length&&i.push(null);let d=a.heights[a.index++],f=0;d<0&&(f=-d,d=a.heights[a.index++]),l==-1?l=d:Math.abs(d-l)>=Hd&&(l=-2);let h=new ta(c,d,f);h.outdated=!1,i.push(h),o+=c+1}o<=s&&i.push(null,new t(s-o).updateHeight(e,o));let u=Gr.of(i);return(l<0||Math.abs(u.height-this.height)>=Hd||Math.abs(l-this.heightMetrics(e,n).perLine)>=Hd)&&(nl=!0),Yd(this,u)}else(r||this.outdated)&&(this.setHeight(e.heightForGap(n,n+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}},Mm=class extends Gr{constructor(e,n,r){super(e.length+(n?1:0)+r.length,e.height+r.height,(n?1:0)|(e.outdated||r.outdated?2:0)),this.left=e,this.right=r,this.size=e.size+r.size}get break(){return this.flags&1}blockAt(e,n,r,a){let s=r+this.left.height;return e<s?this.left.blockAt(e,n,r,a):this.right.blockAt(e,n,s,a+this.left.length+this.break)}lineAt(e,n,r,a,s){let i=a+this.left.height,o=s+this.left.length+this.break,l=n==tn.ByHeight?e<i:e<o,u=l?this.left.lineAt(e,n,r,a,s):this.right.lineAt(e,n,r,i,o);if(this.break||(l?u.to<o:u.from>o))return u;let c=n==tn.ByPosNoHeight?tn.ByPosNoHeight:tn.ByPos;return l?u.join(this.right.lineAt(o,c,r,i,o)):this.left.lineAt(o,c,r,a,s).join(u)}forEachLine(e,n,r,a,s,i){let o=a+this.left.height,l=s+this.left.length+this.break;if(this.break)e<l&&this.left.forEachLine(e,n,r,a,s,i),n>=l&&this.right.forEachLine(e,n,r,o,l,i);else{let u=this.lineAt(l,tn.ByPos,r,a,s);e<u.from&&this.left.forEachLine(e,Math.min(n,u.from-1),r,a,s,i),u.to>=e&&u.from<=n&&i(u),n>u.to&&this.right.forEachLine(Math.max(e,u.to+1),n,r,o,l,i)}}replace(e,n,r){let a=this.left.length+this.break;if(n<a)return this.balanced(this.left.replace(e,n,r),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-a,n-a,r));let s=[];e>0&&this.decomposeLeft(e,s);let i=s.length;for(let o of r)s.push(o);if(e>0&&jk(s,i-1),n<this.length){let o=s.length;this.decomposeRight(n,s),jk(s,o)}return Gr.of(s)}decomposeLeft(e,n){let r=this.left.length;if(e<=r)return this.left.decomposeLeft(e,n);n.push(this.left),this.break&&(r++,e>=r&&n.push(null)),e>r&&this.right.decomposeLeft(e-r,n)}decomposeRight(e,n){let r=this.left.length,a=r+this.break;if(e>=a)return this.right.decomposeRight(e-a,n);e<r&&this.left.decomposeRight(e,n),this.break&&e<a&&n.push(null),n.push(this.right)}balanced(e,n){return e.size>2*n.size||n.size>2*e.size?Gr.of(this.break?[e,null,n]:[e,n]):(this.left=Yd(this.left,e),this.right=Yd(this.right,n),this.setHeight(e.height+n.height),this.outdated=e.outdated||n.outdated,this.size=e.size+n.size,this.length=e.length+this.break+n.length,this)}updateHeight(e,n=0,r=!1,a){let{left:s,right:i}=this,o=n+s.length+this.break,l=null;return a&&a.from<=n+s.length&&a.more?l=s=s.updateHeight(e,n,r,a):s.updateHeight(e,n,r),a&&a.from<=o+i.length&&a.more?l=i=i.updateHeight(e,o,r,a):i.updateHeight(e,o,r),l?this.balanced(s,i):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}};function jk(t,e){let n,r;t[e]==null&&(n=t[e-1])instanceof ti&&(r=t[e+1])instanceof ti&&t.splice(e-1,3,new ti(n.length+1+r.length))}var QT=5,Tm=class t{constructor(e,n){this.pos=e,this.oracle=n,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,n){if(this.lineStart>-1){let r=Math.min(n,this.lineEnd),a=this.nodes[this.nodes.length-1];a instanceof ta?a.length+=r-this.pos:(r>this.pos||!this.isCovered)&&this.nodes.push(new ta(r-this.pos,-1,0)),this.writtenTo=r,n>r&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=n}point(e,n,r){if(e<n||r.heightRelevant){let a=r.widget?r.widget.estimatedHeight:0,s=r.widget?r.widget.lineBreaks:0;a<0&&(a=this.oracle.lineHeight);let i=n-e;r.block?this.addBlock(new Jd(i,a,r)):(i||s||a>=QT)&&this.addLineDeco(a,s,i)}else n>e&&this.span(e,n);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:n}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=n,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new ta(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,n){let r=new ti(n-e);return this.oracle.doc.lineAt(e).to==n&&(r.flags|=4),r}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof ta)return e;let n=new ta(0,-1,0);return this.nodes.push(n),n}addBlock(e){this.enterLine();let n=e.deco;n&&n.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,n&&n.endSide>0&&(this.covering=e)}addLineDeco(e,n,r){let a=this.ensureLine();a.length+=r,a.collapsed+=r,a.widgetHeight=Math.max(a.widgetHeight,e),a.breaks+=n,this.writtenTo=this.pos=this.pos+r}finish(e){let n=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(n instanceof ta)&&!this.isCovered?this.nodes.push(new ta(0,-1,0)):(this.writtenTo<this.pos||n==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let r=e;for(let a of this.nodes)a instanceof ta&&a.updateHeight(this.oracle,r),r+=a?a.length:1;return this.nodes}static build(e,n,r,a){let s=new t(r,e);return Pt.spans(n,r,a,s,0),s.finish(r)}};function eD(t,e,n){let r=new Dm;return Pt.compare(t,e,n,r,0),r.changes}var Dm=class{constructor(){this.changes=[]}compareRange(){}comparePoint(e,n,r,a){(e<n||r&&r.heightRelevant||a&&a.heightRelevant)&&Yo(e,n,this.changes,5)}};function tD(t,e){let n=t.getBoundingClientRect(),r=t.ownerDocument,a=r.defaultView||window,s=Math.max(0,n.left),i=Math.min(a.innerWidth,n.right),o=Math.max(0,n.top),l=Math.min(a.innerHeight,n.bottom);for(let u=t.parentNode;u&&u!=r.body;)if(u.nodeType==1){let c=u,d=window.getComputedStyle(c);if((c.scrollHeight>c.clientHeight||c.scrollWidth>c.clientWidth)&&d.overflow!="visible"){let f=c.getBoundingClientRect();s=Math.max(s,f.left),i=Math.min(i,f.right),o=Math.max(o,f.top),l=Math.min(u==t.parentNode?a.innerHeight:l,f.bottom)}u=d.position=="absolute"||d.position=="fixed"?c.offsetParent:c.parentNode}else if(u.nodeType==11)u=u.host;else break;return{left:s-n.left,right:Math.max(s,i)-n.left,top:o-(n.top+e),bottom:Math.max(o,l)-(n.top+e)}}function nD(t){let e=t.getBoundingClientRect(),n=t.ownerDocument.defaultView||window;return e.left<n.innerWidth&&e.right>0&&e.top<n.innerHeight&&e.bottom>0}function rD(t,e){let n=t.getBoundingClientRect();return{left:0,right:n.right-n.left,top:e,bottom:n.bottom-(n.top+e)}}var Ou=class{constructor(e,n,r,a){this.from=e,this.to=n,this.size=r,this.displaySize=a}static same(e,n){if(e.length!=n.length)return!1;for(let r=0;r<e.length;r++){let a=e[r],s=n[r];if(a.from!=s.from||a.to!=s.to||a.size!=s.size)return!1}return!0}draw(e,n){return Ze.replace({widget:new Fm(this.displaySize*(n?e.scaleY:e.scaleX),n)}).range(this.from,this.to)}},Fm=class extends zr{constructor(e,n){super(),this.size=e,this.vertical=n}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}},Zd=class{constructor(e,n){this.view=e,this.state=n,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=qk,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=nn.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let r=n.facet(Zm).some(a=>typeof a!="function"&&a.class=="cm-lineWrapping");this.heightOracle=new Rm(r),this.stateDeco=Vk(n),this.heightMap=Gr.empty().applyChanges(this.stateDeco,mt.empty,this.heightOracle.setDoc(n.doc),[new ka(0,0,0,n.doc.length)]);for(let a=0;a<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());a++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=Ze.set(this.lineGaps.map(a=>a.draw(this,!1))),this.scrollParent=e.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:n}=this.state.selection;for(let r=0;r<=1;r++){let a=r?n.head:n.anchor;if(!e.some(({from:s,to:i})=>a>=s&&a<=i)){let{from:s,to:i}=this.lineBlockAt(a);e.push(new Ko(s,i))}}return this.viewports=e.sort((r,a)=>r.from-a.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?qk:new Em(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(Pu(e,this.scaler))})}update(e,n=null){this.state=e.state;let r=this.stateDeco;this.stateDeco=Vk(this.state);let a=e.changedRanges,s=ka.extendWithRanges(a,eD(r,this.stateDeco,e?e.changes:zn.empty(this.state.doc.length))),i=this.heightMap.height,o=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);Wk(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),s),(this.heightMap.height!=i||nl)&&(e.flags|=2),o?(this.scrollAnchorPos=e.changes.mapPos(o.from,-1),this.scrollAnchorHeight=o.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=i);let l=s.length?this.mapViewport(this.viewport,e.changes):this.viewport;(n&&(n.range.head<l.from||n.range.head>l.to)||!this.viewportIsAppropriate(l))&&(l=this.getViewport(0,n));let u=l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,e.flags|=this.updateForViewport(),(u||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),n&&(this.scrollTarget=n),!this.mustEnforceCursorAssoc&&(e.selectionSet||e.focusChanged)&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(CS)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:e}=this,n=e.contentDOM,r=window.getComputedStyle(n),a=this.heightOracle,s=r.whiteSpace;this.defaultTextDirection=r.direction=="rtl"?nn.RTL:nn.LTR;let i=this.heightOracle.mustRefreshForWrapping(s)||this.mustMeasureContent==="refresh",o=n.getBoundingClientRect(),l=i||this.mustMeasureContent||this.contentDOMHeight!=o.height;this.contentDOMHeight=o.height,this.mustMeasureContent=!1;let u=0,c=0;if(o.width&&o.height){let{scaleX:I,scaleY:L}=aS(n,o);(I>.005&&Math.abs(this.scaleX-I)>.005||L>.005&&Math.abs(this.scaleY-L)>.005)&&(this.scaleX=I,this.scaleY=L,u|=16,i=l=!0)}let d=(parseInt(r.paddingTop)||0)*this.scaleY,f=(parseInt(r.paddingBottom)||0)*this.scaleY;(this.paddingTop!=d||this.paddingBottom!=f)&&(this.paddingTop=d,this.paddingBottom=f,u|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(a.lineWrapping&&(l=!0),this.editorWidth=e.scrollDOM.clientWidth,u|=16);let h=sS(this.view.contentDOM,!1).y;h!=this.scrollParent&&(this.scrollParent=h,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=uS(this.scrollParent||e.win);let g=(this.printing?rD:tD)(n,this.paddingTop),m=g.top-this.pixelViewport.top,x=g.bottom-this.pixelViewport.bottom;this.pixelViewport=g;let b=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(b!=this.inView&&(this.inView=b,b&&(l=!0)),!this.inView&&!this.scrollTarget&&!nD(e.dom))return 0;let y=o.width;if((this.contentDOMWidth!=y||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=o.width,this.editorHeight=e.scrollDOM.clientHeight,u|=16),l){let I=e.docView.measureVisibleLineHeights(this.viewport);if(a.mustRefreshForHeights(I)&&(i=!0),i||a.lineWrapping&&Math.abs(y-this.contentDOMWidth)>a.charWidth){let{lineHeight:L,charWidth:v,textHeight:k}=e.docView.measureTextSize();i=L>0&&a.refresh(s,L,v,k,Math.max(5,y/v),I),i&&(e.docView.minWidth=0,u|=16)}m>0&&x>0?c=Math.max(m,x):m<0&&x<0&&(c=Math.min(m,x)),Wk();for(let L of this.viewports){let v=L.from==this.viewport.from?I:e.docView.measureVisibleLineHeights(L);this.heightMap=(i?Gr.empty().applyChanges(this.stateDeco,mt.empty,this.heightOracle,[new ka(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(a,0,i,new Nm(L.from,v))}nl&&(u|=2)}let C=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return C&&(u&2&&(u|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),u|=this.updateForViewport()),(u&2||C)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(i?[]:this.lineGaps,e)),u|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),u}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,n){let r=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),a=this.heightMap,s=this.heightOracle,{visibleTop:i,visibleBottom:o}=this,l=new Ko(a.lineAt(i-r*1e3,tn.ByHeight,s,0,0).from,a.lineAt(o+(1-r)*1e3,tn.ByHeight,s,0,0).to);if(n){let{head:u}=n.range;if(u<l.from||u>l.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),d=a.lineAt(u,tn.ByPos,s,0,0),f;n.y=="center"?f=(d.top+d.bottom)/2-c/2:n.y=="start"||n.y=="nearest"&&u<l.from?f=d.top:f=d.bottom-c,l=new Ko(a.lineAt(f-1e3/2,tn.ByHeight,s,0,0).from,a.lineAt(f+c+1e3/2,tn.ByHeight,s,0,0).to)}}return l}mapViewport(e,n){let r=n.mapPos(e.from,-1),a=n.mapPos(e.to,1);return new Ko(this.heightMap.lineAt(r,tn.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(a,tn.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:n},r=0){if(!this.inView)return!0;let{top:a}=this.heightMap.lineAt(e,tn.ByPos,this.heightOracle,0,0),{bottom:s}=this.heightMap.lineAt(n,tn.ByPos,this.heightOracle,0,0),{visibleTop:i,visibleBottom:o}=this;return(e==0||a<=i-Math.max(10,Math.min(-r,250)))&&(n==this.state.doc.length||s>=o+Math.max(10,Math.min(r,250)))&&a>i-2*1e3&&s<o+2*1e3}mapLineGaps(e,n){if(!e.length||n.empty)return e;let r=[];for(let a of e)n.touchesRange(a.from,a.to)||r.push(new Ou(n.mapPos(a.from),n.mapPos(a.to),a.size,a.displaySize));return r}ensureLineGaps(e,n){let r=this.heightOracle.lineWrapping,a=r?1e4:2e3,s=a>>1,i=a<<1;if(this.defaultTextDirection!=nn.LTR&&!r)return[];let o=[],l=(c,d,f,h)=>{if(d-c<s)return;let p=this.state.selection.main,g=[p.from];p.empty||g.push(p.to);for(let x of g)if(x>c&&x<d){l(c,x-10,f,h),l(x+10,d,f,h);return}let m=sD(e,x=>x.from>=f.from&&x.to<=f.to&&Math.abs(x.from-c)<s&&Math.abs(x.to-d)<s&&!g.some(b=>x.from<b&&x.to>b));if(!m){if(d<f.to&&n&&r&&n.visibleRanges.some(y=>y.from<=d&&y.to>=d)){let y=n.moveToLineBoundary(oe.cursor(d),!1,!0).head;y>c&&(d=y)}let x=this.gapSize(f,c,d,h),b=r||x<2e6?x:2e6;m=new Ou(c,d,x,b)}o.push(m)},u=c=>{if(c.length<i||c.type!=Xn.Text)return;let d=aD(c.from,c.to,this.stateDeco);if(d.total<i)return;let f=this.scrollTarget?this.scrollTarget.range.head:null,h,p;if(r){let g=a/this.heightOracle.lineLength*this.heightOracle.lineHeight,m,x;if(f!=null){let b=Od(d,f),y=((this.visibleBottom-this.visibleTop)/2+g)/c.height;m=b-y,x=b+y}else m=(this.visibleTop-c.top-g)/c.height,x=(this.visibleBottom-c.top+g)/c.height;h=Ed(d,m),p=Ed(d,x)}else{let g=d.total*this.heightOracle.charWidth,m=a*this.heightOracle.charWidth,x=0;if(g>2e6)for(let L of e)L.from>=c.from&&L.from<c.to&&L.size!=L.displaySize&&L.from*this.heightOracle.charWidth+x<this.pixelViewport.left&&(x=L.size-L.displaySize);let b=this.pixelViewport.left+x,y=this.pixelViewport.right+x,C,I;if(f!=null){let L=Od(d,f),v=((y-b)/2+m)/g;C=L-v,I=L+v}else C=(b-m)/g,I=(y+m)/g;h=Ed(d,C),p=Ed(d,I)}h>c.from&&l(c.from,h,c,d),p<c.to&&l(p,c.to,c,d)};for(let c of this.viewportLines)Array.isArray(c.type)?c.type.forEach(u):u(c);return o}gapSize(e,n,r,a){let s=Od(a,r)-Od(a,n);return this.heightOracle.lineWrapping?e.height*s:a.total*this.heightOracle.charWidth*s}updateLineGaps(e){Ou.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=Ze.set(e.map(n=>n.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let n=this.stateDeco;this.lineGaps.length&&(n=n.concat(this.lineGapDeco));let r=[];Pt.spans(n,this.viewport.from,this.viewport.to,{span(s,i){r.push({from:s,to:i})},point(){}},20);let a=0;if(r.length!=this.visibleRanges.length)a=12;else for(let s=0;s<r.length&&!(a&8);s++){let i=this.visibleRanges[s],o=r[s];(i.from!=o.from||i.to!=o.to)&&(a|=4,e&&e.mapPos(i.from,-1)==o.from&&e.mapPos(i.to,1)==o.to||(a|=8))}return this.visibleRanges=r,a}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(n=>n.from<=e&&n.to>=e)||Pu(this.heightMap.lineAt(e,tn.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(n=>n.top<=e&&n.bottom>=e)||Pu(this.heightMap.lineAt(this.scaler.fromDOM(e),tn.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop*this.scaleY:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top}scrollAnchorAt(e){let n=this.lineBlockAtHeight(e+8);return n.from>=this.viewport.from||this.viewportLines[0].top-e>200?n:this.viewportLines[0]}elementAtHeight(e){return Pu(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}},Ko=class{constructor(e,n){this.from=e,this.to=n}};function aD(t,e,n){let r=[],a=t,s=0;return Pt.spans(n,t,e,{span(){},point(i,o){i>a&&(r.push({from:a,to:i}),s+=i-a),a=o}},20),a<e&&(r.push({from:a,to:e}),s+=e-a),{total:s,ranges:r}}function Ed({total:t,ranges:e},n){if(n<=0)return e[0].from;if(n>=1)return e[e.length-1].to;let r=Math.floor(t*n);for(let a=0;;a++){let{from:s,to:i}=e[a],o=i-s;if(r<=o)return s+r;r-=o}}function Od(t,e){let n=0;for(let{from:r,to:a}of t.ranges){if(e<=a){n+=e-r;break}n+=a-r}return n/t.total}function sD(t,e){for(let n of t)if(e(n))return n}var qk={toDOM(t){return t},fromDOM(t){return t},scale:1,eq(t){return t==this}};function Vk(t){let e=t.facet(rf).filter(r=>typeof r!="function"),n=t.facet(Qm).filter(r=>typeof r!="function");return n.length&&e.push(Pt.join(n)),e}var Em=class t{constructor(e,n,r){let a=0,s=0,i=0;this.viewports=r.map(({from:o,to:l})=>{let u=n.lineAt(o,tn.ByPos,e,0,0).top,c=n.lineAt(l,tn.ByPos,e,0,0).bottom;return a+=c-u,{from:o,to:l,top:u,bottom:c,domTop:0,domBottom:0}}),this.scale=(7e6-a)/(n.height-a);for(let o of this.viewports)o.domTop=i+(o.top-s)*this.scale,i=o.domBottom=o.domTop+(o.bottom-o.top),s=o.bottom}toDOM(e){for(let n=0,r=0,a=0;;n++){let s=n<this.viewports.length?this.viewports[n]:null;if(!s||e<s.top)return a+(e-r)*this.scale;if(e<=s.bottom)return s.domTop+(e-s.top);r=s.bottom,a=s.domBottom}}fromDOM(e){for(let n=0,r=0,a=0;;n++){let s=n<this.viewports.length?this.viewports[n]:null;if(!s||e<s.domTop)return r+(e-a)/this.scale;if(e<=s.domBottom)return s.top+(e-s.domTop);r=s.bottom,a=s.domBottom}}eq(e){return e instanceof t?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((n,r)=>n.from==e.viewports[r].from&&n.to==e.viewports[r].to):!1}};function Pu(t,e){if(e.scale==1)return t;let n=e.toDOM(t.top),r=e.toDOM(t.bottom);return new va(t.from,t.length,n,r-n,Array.isArray(t._content)?t._content.map(a=>Pu(a,e)):t._content)}var Bd=Ee.define({combine:t=>t.join(" ")}),Om=Ee.define({combine:t=>t.indexOf(!0)>-1}),Bm=Pr.newName(),VS=Pr.newName(),$S=Pr.newName(),KS={"&light":"."+VS,"&dark":"."+$S};function _m(t,e,n){return new Pr(e,{finish(r){return/&/.test(r)?r.replace(/&\w*/,a=>{if(a=="&")return t;if(!n||!n[a])throw new RangeError(`Unsupported selector: ${a}`);return n[a]}):t+" "+r}})}var iD=_m("."+Bm,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{userSelect:"none",position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},".cm-panels-top":{top:"0"},".cm-panels-bottom":{bottom:"0"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{background:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 0) no-repeat",backgroundSize:".4em",backgroundPosition:"calc(min(50%, 0px)) center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},KS),oD={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},tm=Ie.ie&&Ie.ie_version<=11,Hm=class{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new lm,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(n=>{for(let r of n)this.queue.push(r);(Ie.ie&&Ie.ie_version<=11||Ie.ios&&e.composing)&&n.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&Ie.android&&e.constructor.EDIT_CONTEXT!==!1&&!(Ie.chrome&&Ie.chrome_version<126)&&(this.editContext=new Um(e),e.state.facet(bs)&&(e.contentDOM.editContext=this.editContext.editContext)),tm&&(this.onCharData=n=>{this.queue.push({target:n.target,type:"characterData",oldValue:n.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var n;((n=this.view.docView)===null||n===void 0?void 0:n.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(n=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),n.length>0&&n[n.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(n=>{n.length>0&&n[n.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type=="change"||!e.type)&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((n,r)=>n!=e[r]))){this.gapIntersection.disconnect();for(let n of e)this.gapIntersection.observe(n);this.gaps=e}}onSelectionChange(e){let n=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:r}=this,a=this.selectionRange;if(r.state.facet(bs)?r.root.activeElement!=this.dom:!Ru(this.dom,a))return;let s=a.anchorNode&&r.docView.tile.nearest(a.anchorNode);if(s&&s.isWidget()&&s.widget.ignoreEvent(e)){n||(this.selectionChanged=!1);return}(Ie.ie&&Ie.ie_version<=11||Ie.android&&Ie.chrome)&&!r.state.selection.main.empty&&a.focusNode&&Mu(a.focusNode,a.focusOffset,a.anchorNode,a.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,n=Gu(e.root);if(!n)return!1;let r=Ie.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&lD(this.view,n)||n;if(!r||this.selectionRange.eq(r))return!1;let a=Ru(this.dom,r);return a&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&nT(this.dom,r)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(r),a&&(this.selectionChanged=!0),!0)}setSelectionRange(e,n){this.selectionRange.set(e.node,e.offset,n.node,n.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,n=null;for(let r=this.dom;r;)if(r.nodeType==1)!n&&e<this.scrollTargets.length&&this.scrollTargets[e]==r?e++:n||(n=this.scrollTargets.slice(0,e)),n&&n.push(r),r=r.assignedSlot||r.parentNode;else if(r.nodeType==11)r=r.host;else break;if(e<this.scrollTargets.length&&!n&&(n=this.scrollTargets.slice(0,e)),n){for(let r of this.scrollTargets)r.removeEventListener("scroll",this.onScroll);for(let r of this.scrollTargets=n)r.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,oD),tm&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),tm&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,n){var r;if(!this.delayedAndroidKey){let a=()=>{let s=this.delayedAndroidKey;s&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=s.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&s.force&&Jo(this.dom,s.key,s.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(a)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:n,force:this.lastChange<Date.now()-50||!!(!((r=this.delayedAndroidKey)===null||r===void 0)&&r.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let n=-1,r=-1,a=!1;for(let s of e){let i=this.readMutation(s);i&&(i.typeOver&&(a=!0),n==-1?{from:n,to:r}=i:(n=Math.min(i.from,n),r=Math.max(i.to,r)))}return{from:n,to:r,typeOver:a}}readChange(){let{from:e,to:n,typeOver:r}=this.processRecords(),a=this.selectionChanged&&Ru(this.dom,this.selectionRange);if(e<0&&!a)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let s=new Im(this.view,e,n,r);return this.view.docView.domChanged={newSel:s.newSel?s.newSel.main:null},s}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let n=this.readChange();if(!n)return this.view.requestMeasure(),!1;let r=this.view.state,a=OS(this.view,n);return this.view.state==r&&(n.domChanged||n.newSel&&!Xd(this.view.state.selection,n.newSel.main))&&this.view.update([]),a}readMutation(e){let n=this.view.docView.tile.nearest(e.target);if(!n||n.isWidget())return null;if(n.markDirty(e.type=="attributes"),e.type=="childList"){let r=$k(n,e.previousSibling||e.target.previousSibling,-1),a=$k(n,e.nextSibling||e.target.nextSibling,1);return{from:r?n.posAfter(r):n.posAtStart,to:a?n.posBefore(a):n.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(bs)!=e.state.facet(bs)&&(e.view.contentDOM.editContext=e.state.facet(bs)?this.editContext.editContext:null))}destroy(){var e,n,r;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(n=this.gapIntersection)===null||n===void 0||n.disconnect(),(r=this.resizeScroll)===null||r===void 0||r.disconnect();for(let a of this.scrollTargets)a.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}};function $k(t,e,n){for(;e;){let r=un.get(e);if(r&&r.parent==t)return r;let a=e.parentNode;e=a!=t.dom?a:n>0?e.nextSibling:e.previousSibling}return null}function Kk(t,e){let n=e.startContainer,r=e.startOffset,a=e.endContainer,s=e.endOffset,i=t.docView.domAtPos(t.state.selection.main.anchor,1);return Mu(i.node,i.offset,a,s)&&([n,r,a,s]=[a,s,n,r]),{anchorNode:n,anchorOffset:r,focusNode:a,focusOffset:s}}function lD(t,e){if(e.getComposedRanges){let a=e.getComposedRanges(t.root)[0];if(a)return Kk(t,a)}let n=null;function r(a){a.preventDefault(),a.stopImmediatePropagation(),n=a.getTargetRanges()[0]}return t.contentDOM.addEventListener("beforeinput",r,!0),t.dom.ownerDocument.execCommand("indent"),t.contentDOM.removeEventListener("beforeinput",r,!0),n?Kk(t,n):null}var Um=class{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let n=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=r=>{let a=e.state.selection.main,{anchor:s,head:i}=a,o=this.toEditorPos(r.updateRangeStart),l=this.toEditorPos(r.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:r.updateRangeStart,editorBase:o,drifted:!1});let u=l-o>r.text.length;o==this.from&&s<this.from?o=s:l==this.to&&s>this.to&&(l=s);let c=BS(e.state.sliceDoc(o,l),r.text,(u?a.from:a.to)-o,u?"end":null);if(!c){let f=oe.single(this.toEditorPos(r.selectionStart),this.toEditorPos(r.selectionEnd));Xd(f,a)||e.dispatch({selection:f,userEvent:"select"});return}let d={from:c.from+o,to:c.toA+o,insert:mt.of(r.text.slice(c.from,c.toB).split(`
|
|
41
|
+
`))};if((Ie.mac||Ie.android)&&d.from==i-1&&/^\. ?$/.test(r.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(d={from:o,to:l,insert:mt.of([r.text.replace("."," ")])}),this.pendingContextChange=d,!e.state.readOnly){let f=this.to-this.from+(d.to-d.from+d.insert.length);eg(e,d,oe.single(this.toEditorPos(r.selectionStart,f),this.toEditorPos(r.selectionEnd,f)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),d.from<d.to&&!d.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(n.text.slice(Math.max(0,r.updateRangeStart-1),Math.min(n.text.length,r.updateRangeStart+1)))&&this.handlers.compositionend(r)},this.handlers.characterboundsupdate=r=>{let a=[],s=null;for(let i=this.toEditorPos(r.rangeStart),o=this.toEditorPos(r.rangeEnd);i<o;i++){let l=e.coordsForChar(i);s=l&&new DOMRect(l.left,l.top,l.right-l.left,l.bottom-l.top)||s||new DOMRect,a.push(s)}n.updateCharacterBounds(r.rangeStart,a)},this.handlers.textformatupdate=r=>{let a=[];for(let s of r.getTextFormats()){let i=s.underlineStyle,o=s.underlineThickness;if(!/none/i.test(i)&&!/none/i.test(o)){let l=this.toEditorPos(s.rangeStart),u=this.toEditorPos(s.rangeEnd);if(l<u){let c=`text-decoration: underline ${/^[a-z]/.test(i)?i+" ":i=="Dashed"?"dashed ":i=="Squiggle"?"wavy ":""}${/thin/i.test(o)?1:2}px`;a.push(Ze.mark({attributes:{style:c}}).range(l,u))}}}e.dispatch({effects:LS.of(Ze.set(a))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:r}=this.composing;this.composing=null,r&&this.reset(e.state)}};for(let r in this.handlers)n.addEventListener(r,this.handlers[r]);this.measureReq={read:r=>{let a=Gu(r.root);a&&a.rangeCount&&this.editContext.updateSelectionBounds(a.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let n=0,r=!1,a=this.pendingContextChange;return e.changes.iterChanges((s,i,o,l,u)=>{if(r)return;let c=u.length-(i-s);if(a&&i>=a.to)if(a.from==s&&a.to==i&&a.insert.eq(u)){a=this.pendingContextChange=null,n+=c,this.to+=c;return}else a=null,this.revertPending(e.state);if(s+=n,i+=n,i<=this.from)this.from+=c,this.to+=c;else if(s<this.to){if(s<this.from||i>this.to||this.to-this.from+u.length>3e4){r=!0;return}this.editContext.updateText(this.toContextPos(s),this.toContextPos(i),u.toString()),this.to+=c}n+=c}),a&&!r&&this.revertPending(e.state),!r}update(e){let n=this.pendingContextChange,r=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(r.from,r.to)&&e.transactions.some(a=>!a.isUserEvent("input.type")&&a.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||n)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:n}=e.selection.main;this.from=Math.max(0,n-1e4),this.to=Math.min(e.doc.length,n+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let n=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(n.from),this.toContextPos(n.from+n.insert.length),e.doc.sliceString(n.from,n.to))}setSelection(e){let{main:n}=e.selection,r=this.toContextPos(Math.max(this.from,Math.min(this.to,n.anchor))),a=this.toContextPos(n.head);(this.editContext.selectionStart!=r||this.editContext.selectionEnd!=a)&&this.editContext.updateSelection(r,a)}rangeIsValid(e){let{head:n}=e.selection.main;return!(this.from>0&&n-this.from<500||this.to<e.doc.length&&this.to-n<500||this.to-this.from>1e4*3)}toEditorPos(e,n=this.to-this.from){e=Math.min(e,n);let r=this.composing;return r&&r.drifted?r.editorBase+(e-r.contextBase):e+this.from}toContextPos(e){let n=this.composing;return n&&n.drifted?n.contextBase+(e-n.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}},Ne=class t{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){var n;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.clearAnnouncement=-1,this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:r}=e;this.dispatchTransactions=e.dispatchTransactions||r&&(a=>a.forEach(s=>r(s,this)))||(a=>this.update(a)),this.dispatch=this.dispatch.bind(this),this._root=e.root||tT(e.parent)||document,this.viewState=new Zd(this,e.state||Dt.create(e)),e.scrollTo&&e.scrollTo.is(Td)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet($o).map(a=>new Du(a));for(let a of this.plugins)a.update(this);this.observer=new Hm(this),this.inputState=new Lm(this),this.inputState.ensureHandlers(this.plugins),this.docView=new $d(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((n=document.fonts)===null||n===void 0)&&n.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...e){let n=e.length==1&&e[0]instanceof Un?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(n,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let n=!1,r=!1,a,s=this.state;for(let f of e){if(f.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=f.state}if(this.destroyed){this.viewState.state=s;return}let i=this.hasFocus,o=0,l=null;e.some(f=>f.annotation(WS))?(this.inputState.notifiedFocused=i,o=1):i!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=i,l=jS(s,i),l||(o=1));let u=this.observer.delayedAndroidKey,c=null;if(u?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(c=null)):this.observer.clear(),s.facet(Dt.phrases)!=this.state.facet(Dt.phrases))return this.setState(s);a=qd.create(this,s,e),a.flags|=o;let d=this.viewState.scrollTarget;try{this.updateState=2;for(let f of e){if(d&&(d=d.map(f.changes)),f.scrollIntoView){let{main:h}=f.state.selection,{x:p,y:g}=this.state.facet(t.cursorScrollMargin);d=new Tu(h.empty?h:oe.cursor(h.head,h.head>h.anchor?-1:1),"nearest","nearest",g,p)}for(let h of f.effects)h.is(Td)&&(d=h.value.clip(this.state))}this.viewState.update(a,d),this.bidiCache=Qd.update(this.bidiCache,a.changes),a.empty||(this.updatePlugins(a),this.inputState.update(a)),n=this.docView.update(a),this.state.facet(Au)!=this.styleModules&&this.mountStyles(),r=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(n,e.some(f=>f.isUserEvent("select.pointer")))}finally{this.updateState=0}if(a.startState.facet(Bd)!=a.state.facet(Bd)&&(this.viewState.mustMeasureContent=!0),(n||r||d||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),n&&this.docViewUpdate(),!a.empty)for(let f of this.state.facet(fm))try{f(a)}catch(h){wa(this.state,h,"update listener")}(l||c)&&Promise.resolve().then(()=>{l&&this.state==l.startState&&this.dispatch(l),c&&!OS(this,c)&&u.force&&Jo(this.contentDOM,u.key,u.keyCode)})}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let n=this.hasFocus;try{for(let r of this.plugins)r.destroy(this);this.viewState=new Zd(this,e),this.plugins=e.facet($o).map(r=>new Du(r)),this.pluginMap.clear();for(let r of this.plugins)r.update(this);this.docView.destroy(),this.docView=new $d(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}n&&this.focus(),this.requestMeasure()}updatePlugins(e){let n=e.startState.facet($o),r=e.state.facet($o);if(n!=r){let a=[];for(let s of r){let i=n.indexOf(s);if(i<0)a.push(new Du(s));else{let o=this.plugins[i];o.mustUpdate=e,a.push(o)}}for(let s of this.plugins)s.mustUpdate!=e&&s.destroy(this);this.plugins=a,this.pluginMap.clear()}else for(let a of this.plugins)a.mustUpdate=e;for(let a=0;a<this.plugins.length;a++)this.plugins[a].update(this);n!=r&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let n=e.value;if(n&&n.docViewUpdate)try{n.docViewUpdate(this)}catch(r){wa(this.state,r,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let n=null,r=this.viewState.scrollParent,a=this.viewState.getScrollOffset(),{scrollAnchorPos:s,scrollAnchorHeight:i,scaleY:o}=this.viewState;Math.abs(a-this.viewState.scrollOffset)>1&&(i=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(i<0){if(uS(r||this.win))s=-1,i=this.viewState.heightMap.height/this.viewState.scaleY;else{let p=this.viewState.scrollAnchorAt(a);s=p.from,i=p.top}o=this.viewState.scaleY}this.updateState=1;let u=this.viewState.measure();if(!u&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let c=[];u&4||([this.measureRequests,c]=[c,this.measureRequests]);let d=c.map(p=>{try{return p.read(this)}catch(g){return wa(this.state,g),Xk}}),f=qd.create(this,this.state,[]),h=!1;f.flags|=u,n?n.flags|=u:n=f,this.updateState=2,f.empty||(this.updatePlugins(f),this.inputState.update(f),this.updateAttrs(),h=this.docView.update(f),h&&this.docViewUpdate());for(let p=0;p<c.length;p++)if(d[p]!=Xk)try{let g=c[p];g.write&&g.write(d[p],this)}catch(g){wa(this.state,g)}if(h&&this.docView.updateSelection(!0),!f.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,i=-1;continue}else{let g=(s<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(s).top)/this.viewState.scaleY-i/o;if((g>1||g<-1)&&!(Ie.ios&&this.inputState.lastIOSMomentumScroll>Date.now()-100)&&(r==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){a=a+g,r?s<0?r.scrollTop=r.scrollHeight:r.scrollTop+=g:this.win.scrollBy(0,g),i=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(n&&!n.empty)for(let l of this.state.facet(fm))l(n)}get themeClasses(){return Bm+" "+(this.state.facet(Om)?$S:VS)+" "+this.state.facet(Bd)}updateAttrs(){let e=Yk(this,AS,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),n={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(bs)?"true":"false",class:"cm-content",style:`${Ie.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(n["aria-readonly"]="true"),Yk(this,Zm,n);let r=this.observer.ignore(()=>{let a=Pk(this.contentDOM,this.contentAttrs,n),s=Pk(this.dom,this.editorAttrs,e);return a||s});return this.editorAttrs=e,this.contentAttrs=n,r}showAnnouncements(e){let n=!0;for(let r of e)for(let a of r.effects)if(a.is(t.announce)){n&&(this.announceDOM.textContent="",this.win.clearTimeout(this.clearAnnouncement),this.clearAnnouncement=this.win.setTimeout(()=>{this.announceDOM.textContent="\xA0"},200),n=!1);let s=this.announceDOM.appendChild(document.createElement("div"));s.textContent=a.value}}mountStyles(){this.styleModules=this.state.facet(Au);let e=this.state.facet(t.cspNonce);Pr.mount(this.root,this.styleModules.concat(iD).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let n=0;n<this.measureRequests.length;n++)if(this.measureRequests[n].key===e.key){this.measureRequests[n]=e;return}}this.measureRequests.push(e)}}plugin(e){let n=this.pluginMap.get(e);return(n===void 0||n&&n.plugin!=e)&&this.pluginMap.set(e,n=this.plugins.find(r=>r.plugin==e)||null),n&&n.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,n,r){return em(this,e,Fk(this,e,n,r))}moveByGroup(e,n){return em(this,e,Fk(this,e,n,r=>NT(this,e.head,r)))}visualLineSide(e,n){return n?oe.cursor(e.to,1):oe.cursor(e.from,-1)}moveToLineBoundary(e,n,r=!0){return RT(this,e,n,r)}moveVertically(e,n,r){return em(this,e,MT(this,e,n,r))}domAtPos(e,n=1){return this.docView.domAtPos(e,n)}posAtDOM(e,n=0){return this.docView.posFromDOM(e,n)}posAtCoords(e,n=!0){this.readMeasured();let r=km(this,e,n);return r&&r.pos}posAndSideAtCoords(e,n=!0){return this.readMeasured(),km(this,e,n)}coordsAtPos(e,n=1){this.readMeasured();let r=this.state.doc.lineAt(e),a=this.bidiSpans(r),s=a[ra.find(a,e-r.from,-1,n)];return r.length&&(e==r.from&&n<0||e==r.to&&n>0)&&s.dir!=this.textDirectionAt(r.from)&&(e==r.to?(e=r.from+s.from,n=1):(e=r.from+s.to,n=-1)),this.docView.coordsAt(e,n,s.dir==nn.RTL)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(SS)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>uD)return mS(e.length);let n=this.textDirectionAt(e.from),r;for(let s of this.bidiCache)if(s.from==e.from&&s.dir==n&&(s.fresh||pS(s.isolates,r=Mk(this,e))))return s.order;r||(r=Mk(this,e));let a=uT(e.text,n,r);return this.bidiCache.push(new Qd(e.from,e.to,n,r,!0,a)),a}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||Ie.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{lS(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.win.clearTimeout(this.clearAnnouncement),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,n={}){var r,a,s,i;return Td.of(new Tu(typeof e=="number"?oe.cursor(e):e,(r=n.y)!==null&&r!==void 0?r:"nearest",(a=n.x)!==null&&a!==void 0?a:"nearest",(s=n.yMargin)!==null&&s!==void 0?s:5,(i=n.xMargin)!==null&&i!==void 0?i:5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:n}=this.scrollDOM,r=this.viewState.scrollAnchorAt(e);return Td.of(new Tu(oe.cursor(r.from),"start","start",r.top-e,n,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return Nr.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return Nr.define(()=>({}),{eventObservers:e})}static theme(e,n){let r=Pr.newName(),a=[Bd.of(r),Au.of(_m(`.${r}`,e))];return n&&n.dark&&a.push(Om.of(!0)),a}static baseTheme(e){return Wa.lowest(Au.of(_m("."+Bm,e,KS)))}static findFromDOM(e){var n;let r=e.querySelector(".cm-content"),a=r&&un.get(r)||un.get(e);return((n=a?.root)===null||n===void 0?void 0:n.view)||null}};Ne.styleModule=Au;Ne.inputHandler=wS;Ne.clipboardInputFilter=Ym;Ne.clipboardOutputFilter=Jm;Ne.scrollHandler=IS;Ne.focusChangeEffect=kS;Ne.perLineTextDirection=SS;Ne.exceptionSink=vS;Ne.updateListener=fm;Ne.editable=bs;Ne.mouseSelectionStyle=yS;Ne.dragMovesSelection=bS;Ne.clickAddsSelectionRange=xS;Ne.decorations=rf;Ne.blockWrappers=PS;Ne.outerDecorations=Qm;Ne.atomicRanges=ju;Ne.bidiIsolatedRanges=RS;Ne.cursorScrollMargin=Ee.define({combine:t=>{let e=5,n=5;for(let r of t)typeof r=="number"?e=n=r:{x:e,y:n}=r;return{x:e,y:n}}});Ne.scrollMargins=NS;Ne.darkTheme=Om;Ne.cspNonce=Ee.define({combine:t=>t.length?t[0]:""});Ne.contentAttributes=Zm;Ne.editorAttributes=AS;Ne.lineWrapping=Ne.contentAttributes.of({class:"cm-lineWrapping"});Ne.announce=Ct.define();var uD=4096,Xk={},Qd=class t{constructor(e,n,r,a,s,i){this.from=e,this.to=n,this.dir=r,this.isolates=a,this.fresh=s,this.order=i}static update(e,n){if(n.empty&&!e.some(s=>s.fresh))return e;let r=[],a=e.length?e[e.length-1].dir:nn.LTR;for(let s=Math.max(0,e.length-10);s<e.length;s++){let i=e[s];i.dir==a&&!n.touchesRange(i.from,i.to)&&r.push(new t(n.mapPos(i.from,1),n.mapPos(i.to,-1),i.dir,i.isolates,!1,i.order))}return r}};function Yk(t,e,n){for(let r=t.state.facet(e),a=r.length-1;a>=0;a--){let s=r[a],i=typeof s=="function"?s(t):s;i&&$m(i,n)}return n}var cD=Ie.mac?"mac":Ie.windows?"win":Ie.linux?"linux":"key";function dD(t,e){let n=t.split(/-(?!$)/),r=n[n.length-1];r=="Space"&&(r=" ");let a,s,i,o;for(let l=0;l<n.length-1;++l){let u=n[l];if(/^(cmd|meta|m)$/i.test(u))o=!0;else if(/^a(lt)?$/i.test(u))a=!0;else if(/^(c|ctrl|control)$/i.test(u))s=!0;else if(/^s(hift)?$/i.test(u))i=!0;else if(/^mod$/i.test(u))e=="mac"?o=!0:s=!0;else throw new Error("Unrecognized modifier name: "+u)}return a&&(r="Alt-"+r),s&&(r="Ctrl-"+r),o&&(r="Meta-"+r),i&&(r="Shift-"+r),r}function _d(t,e,n){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),n!==!1&&e.shiftKey&&(t="Shift-"+t),t}var fD=Wa.default(Ne.domEventHandlers({keydown(t,e){return gD(hD(e.state),t,e,"editor")}})),tg=Ee.define({enables:fD}),Jk=new WeakMap;function hD(t){let e=t.facet(tg),n=Jk.get(e);return n||Jk.set(e,n=mD(e.reduce((r,a)=>r.concat(a),[]))),n}var ei=null,pD=4e3;function mD(t,e=cD){let n=Object.create(null),r=Object.create(null),a=(i,o)=>{let l=r[i];if(l==null)r[i]=o;else if(l!=o)throw new Error("Key binding "+i+" is used both as a regular binding and as a multi-stroke prefix")},s=(i,o,l,u,c)=>{var d,f;let h=n[i]||(n[i]=Object.create(null)),p=o.split(/ (?!$)/).map(x=>dD(x,e));for(let x=1;x<p.length;x++){let b=p.slice(0,x).join(" ");a(b,!0),h[b]||(h[b]={preventDefault:!0,stopPropagation:!1,run:[y=>{let C=ei={view:y,prefix:b,scope:i};return setTimeout(()=>{ei==C&&(ei=null)},pD),!0}]})}let g=p.join(" ");a(g,!1);let m=h[g]||(h[g]={preventDefault:!1,stopPropagation:!1,run:((f=(d=h._any)===null||d===void 0?void 0:d.run)===null||f===void 0?void 0:f.slice())||[]});l&&m.run.push(l),u&&(m.preventDefault=!0),c&&(m.stopPropagation=!0)};for(let i of t){let o=i.scope?i.scope.split(" "):["editor"];if(i.any)for(let u of o){let c=n[u]||(n[u]=Object.create(null));c._any||(c._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:d}=i;for(let f in c)c[f].run.push(h=>d(h,Gm))}let l=i[e]||i.key;if(l)for(let u of o)s(u,l,i.run,i.preventDefault,i.stopPropagation),i.shift&&s(u,"Shift-"+l,i.shift,i.preventDefault,i.stopPropagation)}return n}var Gm=null;function gD(t,e,n,r){Gm=e;let a=Ck(e),s=lk(a,0),i=uk(s)==a.length&&a!=" ",o="",l=!1,u=!1,c=!1;ei&&ei.view==n&&ei.scope==r&&(o=ei.prefix+" ",HS.indexOf(e.keyCode)<0&&(u=!0,ei=null));let d=new Set,f=m=>{if(m){for(let x of m.run)if(!d.has(x)&&(d.add(x),x(n)))return m.stopPropagation&&(c=!0),!0;m.preventDefault&&(m.stopPropagation&&(c=!0),u=!0)}return!1},h=t[r],p,g;return h&&(f(h[o+_d(a,e,!i)])?l=!0:i&&(e.altKey||e.metaKey||e.ctrlKey)&&!(Ie.windows&&e.ctrlKey&&e.altKey)&&!(Ie.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(p=xs[e.keyCode])&&p!=a?(f(h[o+_d(p,e,!0)])||e.shiftKey&&(g=qo[e.keyCode])!=a&&g!=p&&f(h[o+_d(g,e,!1)]))&&(l=!0):i&&e.shiftKey&&f(h[o+_d(a,e,!0)])&&(l=!0),!l&&f(h._any)&&(l=!0)),u&&(l=!0),l&&c&&e.stopPropagation(),Gm=null,l}var Wi=class t{constructor(e,n,r,a,s){this.className=e,this.left=n,this.top=r,this.width=a,this.height=s}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,n){return n.className!=this.className?!1:(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width!=null&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,n,r){if(r.empty){let a=e.coordsAtPos(r.head,r.assoc||1);if(!a)return[];let s=XS(e);return[new t(n,a.left-s.left,a.top-s.top,null,a.bottom-a.top)]}else return xD(e,n,r)}};function XS(t){let e=t.scrollDOM.getBoundingClientRect();return{left:(t.textDirection==nn.LTR?e.left:e.right-t.scrollDOM.clientWidth*t.scaleX)-t.scrollDOM.scrollLeft*t.scaleX,top:e.top-t.scrollDOM.scrollTop*t.scaleY}}function Zk(t,e,n,r){let a=t.coordsAtPos(e,n*2);if(!a)return r;let s=t.dom.getBoundingClientRect(),i=(a.top+a.bottom)/2,o=t.posAtCoords({x:s.left+1,y:i}),l=t.posAtCoords({x:s.right-1,y:i});return o==null||l==null?r:{from:Math.max(r.from,Math.min(o,l)),to:Math.min(r.to,Math.max(o,l))}}function xD(t,e,n){if(n.to<=t.viewport.from||n.from>=t.viewport.to)return[];let r=Math.max(n.from,t.viewport.from),a=Math.min(n.to,t.viewport.to),s=t.textDirection==nn.LTR,i=t.contentDOM,o=i.getBoundingClientRect(),l=XS(t),u=i.querySelector(".cm-line"),c=u&&window.getComputedStyle(u),d=o.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),f=o.right-(c?parseInt(c.paddingRight):0),h=wm(t,r,1),p=wm(t,a,-1),g=h.type==Xn.Text?h:null,m=p.type==Xn.Text?p:null;if(g&&(t.lineWrapping||h.widgetLineBreaks)&&(g=Zk(t,r,1,g)),m&&(t.lineWrapping||p.widgetLineBreaks)&&(m=Zk(t,a,-1,m)),g&&m&&g.from==m.from&&g.to==m.to)return b(y(n.from,n.to,g));{let I=g?y(n.from,null,g):C(h,!1),L=m?y(null,n.to,m):C(p,!0),v=[];return(g||h).to<(m||p).from-(g&&m?1:0)||h.widgetLineBreaks>1&&I.bottom+t.defaultLineHeight/2<L.top?v.push(x(d,I.bottom,f,L.top)):I.bottom<L.top&&t.elementAtHeight((I.bottom+L.top)/2).type==Xn.Text&&(I.bottom=L.top=(I.bottom+L.top)/2),b(I).concat(v).concat(b(L))}function x(I,L,v,k){return new Wi(e,I-l.left,L-l.top,Math.max(0,v-I),k-L)}function b({top:I,bottom:L,horizontal:v}){let k=[];for(let O=0;O<v.length;O+=2)k.push(x(v[O],I,v[O+1],L));return k}function y(I,L,v){let k=1e9,O=-1e9,R=[];function P(N,j,K,A,F){let _=t.coordsAtPos(N,N==v.to?-2:2),X=t.coordsAtPos(K,K==v.from?2:-2);!_||!X||(k=Math.min(_.top,X.top,k),O=Math.max(_.bottom,X.bottom,O),F==nn.LTR?R.push(s&&j?d:_.left,s&&A?f:X.right):R.push(!s&&A?d:X.left,!s&&j?f:_.right))}let H=I??v.from,w=L??v.to;for(let N of t.visibleRanges)if(N.to>H&&N.from<w)for(let j=Math.max(N.from,H),K=Math.min(N.to,w);;){let A=t.state.doc.lineAt(j);for(let F of t.bidiSpans(A)){let _=F.from+A.from,X=F.to+A.from;if(_>=K)break;X>j&&P(Math.max(_,j),I==null&&_<=H,Math.min(X,K),L==null&&X>=w,F.dir)}if(j=A.to+1,j>=K)break}return R.length==0&&P(H,I==null,w,L==null,t.textDirection),{top:k,bottom:O,horizontal:R}}function C(I,L){let v=o.top+(L?I.top:I.bottom);return{top:v,bottom:v,horizontal:[]}}}function bD(t,e){return t.constructor==e.constructor&&t.eq(e)}var zm=class{constructor(e,n){this.view=e,this.layer=n,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),n.above&&this.dom.classList.add("cm-layer-above"),n.class&&this.dom.classList.add(n.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),n.mount&&n.mount(this.dom,e)}update(e){e.startState.facet(Ud)!=e.state.facet(Ud)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){this.layer.updateOnDocViewUpdate!==!1&&e.requestMeasure(this.measureReq)}setOrder(e){let n=0,r=e.facet(Ud);for(;n<r.length&&r[n]!=this.layer;)n++;this.dom.style.zIndex=String((this.layer.above?150:-1)-n)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:e,scaleY:n}=this.view;(e!=this.scaleX||n!=this.scaleY)&&(this.scaleX=e,this.scaleY=n,this.dom.style.transform=`scale(${1/e}, ${1/n})`)}draw(e){if(e.length!=this.drawn.length||e.some((n,r)=>!bD(n,this.drawn[r]))){let n=this.dom.firstChild,r=0;for(let a of e)a.update&&n&&a.constructor&&this.drawn[r].constructor&&a.update(n,this.drawn[r])?(n=n.nextSibling,r++):this.dom.insertBefore(a.draw(),n);for(;n;){let a=n.nextSibling;n.remove(),n=a}this.drawn=e,Ie.webkit&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}},Ud=Ee.define();function YS(t){return[Nr.define(e=>new zm(e,t)),Ud.of(t)]}var rl=Ee.define({combine(t){return jo(t,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(e,n)=>Math.min(e,n),drawRangeCursor:(e,n)=>e||n})}});function JS(t={}){return[rl.of(t),yD,vD,kD,CS.of(!0)]}function ZS(t){return t.startState.facet(rl)!=t.state.facet(rl)}var yD=YS({above:!0,markers(t){let{state:e}=t,n=e.facet(rl),r=[];for(let a of e.selection.ranges){let s=a==e.selection.main;if(a.empty||n.drawRangeCursor&&!(s&&Ie.ios&&n.iosSelectionHandles)){let i=s?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",o=a.empty?a:oe.cursor(a.head,a.assoc);for(let l of Wi.forRange(t,i,o))r.push(l)}}return r},update(t,e){t.transactions.some(r=>r.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let n=ZS(t);return n&&Qk(t.state,e),t.docChanged||t.selectionSet||n},mount(t,e){Qk(e.state,t)},class:"cm-cursorLayer"});function Qk(t,e){e.style.animationDuration=t.facet(rl).cursorBlinkRate+"ms"}var vD=YS({above:!1,markers(t){let e=[],{main:n,ranges:r}=t.state.selection;for(let a of r)if(!a.empty)for(let s of Wi.forRange(t,"cm-selectionBackground",a))e.push(s);if(Ie.ios&&!n.empty&&t.state.facet(rl).iosSelectionHandles){for(let a of Wi.forRange(t,"cm-selectionHandle cm-selectionHandle-start",oe.cursor(n.from,1)))e.push(a);for(let a of Wi.forRange(t,"cm-selectionHandle cm-selectionHandle-end",oe.cursor(n.to,1)))e.push(a)}return e},update(t,e){return t.docChanged||t.selectionSet||t.viewportChanged||ZS(t)},class:"cm-selectionLayer"}),wD=Ie.gecko&&Ie.gecko_version==153?"#ffffff01":"transparent",kD=Wa.highest(Ne.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:`${wD} !important`},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}}));var Kj=/x/.unicode!=null?"gu":"g";function QS(){return CD}var SD=Ze.line({class:"cm-activeLine"}),CD=Nr.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.docChanged||t.selectionSet)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=-1,n=[];for(let r of t.state.selection.ranges){let a=t.lineBlockAt(r.head);a.from>e&&(n.push(SD.range(a.from)),e=a.from)}return Ze.set(n)}},{decorations:t=>t.decorations}),Wm=class extends zr{constructor(e){super(),this.content=e}toDOM(e){let n=document.createElement("span");return n.className="cm-placeholder",n.style.pointerEvents="none",n.appendChild(typeof this.content=="string"?document.createTextNode(this.content):typeof this.content=="function"?this.content(e):this.content.cloneNode(!0)),n.setAttribute("aria-hidden","true"),n}coordsAt(e){let n=e.firstChild?Nu(e.firstChild):[];if(!n.length)return null;let r=window.getComputedStyle(e.parentNode),a=zu(n[0],r.direction!="rtl"),s=parseInt(r.lineHeight);return a.bottom-a.top>s*1.5?{left:a.left,right:a.right,top:a.top,bottom:a.top+s}:a}ignoreEvent(){return!1}};function eC(t){let e=Nr.fromClass(class{constructor(n){this.view=n,this.placeholder=t?Ze.set([Ze.widget({widget:new Wm(t),side:1}).range(0)]):Ze.none}get decorations(){return this.view.state.doc.length?Ze.none:this.placeholder}},{decorations:n=>n.decorations});return typeof t=="string"?[e,Ne.contentAttributes.of({"aria-placeholder":t})]:e}var Yn=class extends za{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}};Yn.prototype.elementClass="";Yn.prototype.toDOM=void 0;Yn.prototype.mapMode=Ar.TrackBefore;Yn.prototype.startSide=Yn.prototype.endSide=-1;Yn.prototype.point=!0;var Gd=Ee.define(),ID=Ee.define(),LD={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>Pt.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},Bu=Ee.define();function al(t){return[tC(),Bu.of({...LD,...t})]}var jm=Ee.define({combine:t=>t.some(e=>e)});function tC(t){let e=[AD];return t&&t.fixed===!1&&e.push(jm.of(!0)),e}var AD=Nr.fromClass(class{constructor(t){this.view=t,this.domAfter=null,this.prevViewport=t.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=t.state.facet(Bu).map(e=>new ef(t,e)),this.fixed=!t.state.facet(jm);for(let e of this.gutters)e.config.side=="after"?this.getDOMAfter().appendChild(e.dom):this.dom.appendChild(e.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),t.scrollDOM.insertBefore(this.dom,t.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(t){if(this.updateGutters(t)){let e=this.prevViewport,n=t.view.viewport,r=Math.min(e.to,n.to)-Math.max(e.from,n.from);this.syncGutters(r<(n.to-n.from)*.8)}if(t.geometryChanged){let e=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=e,this.domAfter&&(this.domAfter.style.minHeight=e)}this.view.state.facet(jm)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=t.view.viewport}syncGutters(t){let e=this.dom.nextSibling;t&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let n=Pt.iter(this.view.state.facet(Gd),this.view.viewport.from),r=[],a=this.gutters.map(s=>new Vm(s,this.view.viewport,-this.view.documentPadding.top));for(let s of this.view.viewportLineBlocks)if(r.length&&(r=[]),Array.isArray(s.type)){let i=!0;for(let o of s.type)if(o.type==Xn.Text&&i){qm(n,r,o.from);for(let l of a)l.line(this.view,o,r);i=!1}else if(o.widget)for(let l of a)l.widget(this.view,o)}else if(s.type==Xn.Text){qm(n,r,s.from);for(let i of a)i.line(this.view,s,r)}else if(s.widget)for(let i of a)i.widget(this.view,s);for(let s of a)s.finish();t&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(t){let e=t.startState.facet(Bu),n=t.state.facet(Bu),r=t.docChanged||t.heightChanged||t.viewportChanged||!Pt.eq(t.startState.facet(Gd),t.state.facet(Gd),t.view.viewport.from,t.view.viewport.to);if(e==n)for(let a of this.gutters)a.update(t)&&(r=!0);else{r=!0;let a=[];for(let s of n){let i=e.indexOf(s);i<0?a.push(new ef(this.view,s)):(this.gutters[i].update(t),a.push(this.gutters[i]))}for(let s of this.gutters)s.dom.remove(),a.indexOf(s)<0&&s.destroy();for(let s of a)s.config.side=="after"?this.getDOMAfter().appendChild(s.dom):this.dom.appendChild(s.dom);this.gutters=a}return r}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:t=>Ne.scrollMargins.of(e=>{let n=e.plugin(t);if(!n||n.gutters.length==0||!n.fixed)return null;let r=n.dom.offsetWidth*e.scaleX,a=n.domAfter?n.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==nn.LTR?{left:r,right:a}:{right:r,left:a}})});function eS(t){return Array.isArray(t)?t:[t]}function qm(t,e,n){for(;t.value&&t.from<=n;)t.from==n&&e.push(t.value),t.next()}var Vm=class{constructor(e,n,r){this.gutter=e,this.height=r,this.i=0,this.cursor=Pt.iter(e.markers,n.from)}addElement(e,n,r){let{gutter:a}=this,s=(n.top-this.height)/e.scaleY,i=n.height/e.scaleY;if(this.i==a.elements.length){let o=new tf(e,i,s,r);a.elements.push(o),a.dom.appendChild(o.dom)}else a.elements[this.i].update(e,i,s,r);this.height=n.bottom,this.i++}line(e,n,r){let a=[];qm(this.cursor,a,n.from),r.length&&(a=a.concat(r));let s=this.gutter.config.lineMarker(e,n,a);s&&a.unshift(s);let i=this.gutter;a.length==0&&!i.config.renderEmptyElements||this.addElement(e,n,a)}widget(e,n){let r=this.gutter.config.widgetMarker(e,n.widget,n),a=r?[r]:null;for(let s of e.state.facet(ID)){let i=s(e,n.widget,n);i&&(a||(a=[])).push(i)}a&&this.addElement(e,n,a)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let n=e.elements.pop();e.dom.removeChild(n.dom),n.destroy()}}},ef=class{constructor(e,n){this.view=e,this.config=n,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let r in n.domEventHandlers)this.dom.addEventListener(r,a=>{let s=a.target,i;if(s!=this.dom&&this.dom.contains(s)){for(;s.parentNode!=this.dom;)s=s.parentNode;let l=s.getBoundingClientRect();i=(l.top+l.bottom)/2}else i=a.clientY;let o=e.lineBlockAtHeight(i-e.documentTop);n.domEventHandlers[r](e,o,a)&&a.preventDefault()});this.markers=eS(n.markers(e)),n.initialSpacer&&(this.spacer=new tf(e,0,0,[n.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let n=this.markers;if(this.markers=eS(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let a=this.config.updateSpacer(this.spacer.markers[0],e);a!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[a])}let r=e.view.viewport;return!Pt.eq(this.markers,n,r.from,r.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}},tf=class{constructor(e,n,r,a){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,n,r,a)}update(e,n,r,a){this.height!=n&&(this.height=n,this.dom.style.height=n+"px"),this.above!=r&&(this.dom.style.marginTop=(this.above=r)?r+"px":""),PD(this.markers,a)||this.setMarkers(e,a)}setMarkers(e,n){let r="cm-gutterElement",a=this.dom.firstChild;for(let s=0,i=0;;){let o=i,l=s<n.length?n[s++]:null,u=!1;if(l){let c=l.elementClass;c&&(r+=" "+c);for(let d=i;d<this.markers.length;d++)if(this.markers[d].compare(l)){o=d,u=!0;break}}else o=this.markers.length;for(;i<o;){let c=this.markers[i++];if(c.toDOM){c.destroy(a);let d=a.nextSibling;a.remove(),a=d}}if(!l)break;l.toDOM&&(u?a=a.nextSibling:this.dom.insertBefore(l.toDOM(e),a)),u&&i++}this.dom.className=r,this.markers=n}destroy(){this.setMarkers(null,[])}};function PD(t,e){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++)if(!t[n].compare(e[n]))return!1;return!0}var RD=Ee.define(),ND=Ee.define(),Xo=Ee.define({combine(t){return jo(t,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,n){let r=Object.assign({},e);for(let a in n){let s=r[a],i=n[a];r[a]=s?(o,l,u)=>s(o,l,u)||i(o,l,u):i}return r}})}}),_u=class extends Yn{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}};function nm(t,e){return t.state.facet(Xo).formatNumber(e,t.state)}var MD=Bu.compute([Xo],t=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(RD)},lineMarker(e,n,r){return r.some(a=>a.toDOM)?null:new _u(nm(e,e.state.doc.lineAt(n.from).number))},widgetMarker:(e,n,r)=>{for(let a of e.state.facet(ND)){let s=a(e,n,r);if(s)return s}return null},lineMarkerChange:e=>e.startState.facet(Xo)!=e.state.facet(Xo),initialSpacer(e){return new _u(nm(e,tS(e.state.doc.lines)))},updateSpacer(e,n){let r=nm(n.view,tS(n.view.state.doc.lines));return r==e.number?e:new _u(r)},domEventHandlers:t.facet(Xo).domEventHandlers,side:"before"}));function sf(t={}){return[Xo.of(t),tC(),MD]}function tS(t){let e=9;for(;e<t;)e=e*10+9;return e}var TD=new class extends Yn{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},DD=Gd.compute(["selection"],t=>{let e=[],n=-1;for(let r of t.selection.ranges){let a=t.doc.lineAt(r.head).from;a>n&&(n=a,e.push(TD.range(a)))}return Pt.of(e)});function nC(){return DD}var FD=0,qu=class{constructor(e,n){this.from=e,this.to=n}},ht=class{constructor(e={}){this.id=FD++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=Wr.match(e)),n=>{let r=e(n);return r===void 0?null:[this,r]}}};ht.closedBy=new ht({deserialize:t=>t.split(" ")});ht.openedBy=new ht({deserialize:t=>t.split(" ")});ht.group=new ht({deserialize:t=>t.split(" ")});ht.isolate=new ht({deserialize:t=>{if(t&&t!="rtl"&&t!="ltr"&&t!="auto")throw new RangeError("Invalid value for isolate: "+t);return t||"auto"}});ht.contextHash=new ht({perNode:!0});ht.lookAhead=new ht({perNode:!0});ht.mounted=new ht({perNode:!0});var $i=class{constructor(e,n,r,a=!1){this.tree=e,this.overlay=n,this.parser=r,this.bracketed=a}static get(e){return e&&e.props&&e.props[ht.mounted.id]}},ED=Object.create(null),Wr=class t{constructor(e,n,r,a=0){this.name=e,this.props=n,this.id=r,this.flags=a}static define(e){let n=e.props&&e.props.length?Object.create(null):ED,r=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),a=new t(e.name||"",n,e.id,r);if(e.props){for(let s of e.props)if(Array.isArray(s)||(s=s(a)),s){if(s[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");n[s[0].id]=s[1]}}return a}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let n=this.prop(ht.group);return n?n.indexOf(e)>-1:!1}return this.id==e}static match(e){let n=Object.create(null);for(let r in e)for(let a of r.split(" "))n[a]=e[r];return r=>{for(let a=r.prop(ht.group),s=-1;s<(a?a.length:0);s++){let i=n[s<0?r.name:a[s]];if(i)return i}}}};Wr.none=new Wr("",Object.create(null),0,8);var of=new WeakMap,rC=new WeakMap,wn;(function(t){t[t.ExcludeBuffers=1]="ExcludeBuffers",t[t.IncludeAnonymous=2]="IncludeAnonymous",t[t.IgnoreMounts=4]="IgnoreMounts",t[t.IgnoreOverlays=8]="IgnoreOverlays",t[t.EnterBracketed=16]="EnterBracketed"})(wn||(wn={}));var Jn=class t{constructor(e,n,r,a,s){if(this.type=e,this.children=n,this.positions=r,this.length=a,this.props=null,s&&s.length){this.props=Object.create(null);for(let[i,o]of s)this.props[typeof i=="number"?i:i.id]=o}}toString(){let e=$i.get(this);if(e&&!e.overlay)return e.tree.toString();let n="";for(let r of this.children){let a=r.toString();a&&(n&&(n+=","),n+=a)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(n.length?"("+n+")":""):n}cursor(e=0){return new Ku(this.topNode,e)}cursorAt(e,n=0,r=0){let a=of.get(this)||this.topNode,s=new Ku(a);return s.moveTo(e,n),of.set(this,s._tree),s}get topNode(){return new Va(this,0,0,null)}resolve(e,n=0){let r=Vu(of.get(this)||this.topNode,e,n,!1);return of.set(this,r),r}resolveInner(e,n=0){let r=Vu(rC.get(this)||this.topNode,e,n,!0);return rC.set(this,r),r}resolveStack(e,n=0){return OD(this,e,n)}iterate(e){let{enter:n,leave:r,from:a=0,to:s=this.length}=e,i=e.mode||0,o=(i&wn.IncludeAnonymous)>0;for(let l=this.cursor(i|wn.IncludeAnonymous);;){let u=!1;if(l.from<=s&&l.to>=a&&(!o&&l.type.isAnonymous||n(l)!==!1)){if(l.firstChild())continue;u=!0}for(;u&&r&&(o||!l.type.isAnonymous)&&r(l),!l.nextSibling();){if(!l.parent())return;u=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let n in this.props)e.push([+n,this.props[n]]);return e}balance(e={}){return this.children.length<=8?this:lg(Wr.none,this.children,this.positions,0,this.children.length,0,this.length,(n,r,a)=>new t(this.type,n,r,a,this.propValues),e.makeTree||((n,r,a)=>new t(Wr.none,n,r,a)))}static build(e){return BD(e)}};Jn.empty=new Jn(Wr.none,[],[],0);var ng=class t{constructor(e,n){this.buffer=e,this.index=n}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new t(this.buffer,this.index)}},ai=class t{constructor(e,n,r){this.buffer=e,this.length=n,this.set=r}get type(){return Wr.none}toString(){let e=[];for(let n=0;n<this.buffer.length;)e.push(this.childString(n)),n=this.buffer[n+3];return e.join(",")}childString(e){let n=this.buffer[e],r=this.buffer[e+3],a=this.set.types[n],s=a.name;if(/\W/.test(s)&&!a.isError&&(s=JSON.stringify(s)),e+=4,r==e)return s;let i=[];for(;e<r;)i.push(this.childString(e)),e=this.buffer[e+3];return s+"("+i.join(",")+")"}findChild(e,n,r,a,s){let{buffer:i}=this,o=-1;for(let l=e;l!=n&&!(iC(s,a,i[l+1],i[l+2])&&(o=l,r>0));l=i[l+3]);return o}slice(e,n,r){let a=this.buffer,s=new Uint16Array(n-e),i=0;for(let o=e,l=0;o<n;){s[l++]=a[o++],s[l++]=a[o++]-r;let u=s[l++]=a[o++]-r;s[l++]=a[o++]-e,i=Math.max(i,u)}return new t(s,i,this.set)}};function iC(t,e,n,r){switch(t){case-2:return n<e;case-1:return r>=e&&n<e;case 0:return n<e&&r>e;case 1:return n<=e&&r>e;case 2:return r>e;case 4:return!0}}function Vu(t,e,n,r){for(var a;t.from==t.to||(n<1?t.from>=e:t.from>e)||(n>-1?t.to<=e:t.to<e);){let i=!r&&t instanceof Va&&t.index<0?null:t.parent;if(!i)return t;t=i}let s=r?0:wn.IgnoreOverlays;if(r)for(let i=t,o=i.parent;o;i=o,o=i.parent)i instanceof Va&&i.index<0&&((a=o.enter(e,n,s))===null||a===void 0?void 0:a.from)!=i.from&&(t=o);for(;;){let i=t.enter(e,n,s);if(!i)return t;t=i}}var uf=class{cursor(e=0){return new Ku(this,e)}getChild(e,n=null,r=null){let a=aC(this,e,n,r);return a.length?a[0]:null}getChildren(e,n=null,r=null){return aC(this,e,n,r)}resolve(e,n=0){return Vu(this,e,n,!1)}resolveInner(e,n=0){return Vu(this,e,n,!0)}matchContext(e){return rg(this.parent,e)}enterUnfinishedNodesBefore(e){let n=this.childBefore(e),r=this;for(;n;){let a=n.lastChild;if(!a||a.to!=n.to)break;a.type.isError&&a.from==a.to?(r=n,n=a.prevSibling):n=a}return r}get node(){return this}get next(){return this.parent}},Va=class t extends uf{constructor(e,n,r,a){super(),this._tree=e,this.from=n,this.index=r,this._parent=a}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,n,r,a,s=0){for(let i=this;;){for(let{children:o,positions:l}=i._tree,u=n>0?o.length:-1;e!=u;e+=n){let c=o[e],d=l[e]+i.from,f;if(!(!(s&wn.EnterBracketed&&c instanceof Jn&&(f=$i.get(c))&&!f.overlay&&f.bracketed&&r>=d&&r<=d+c.length)&&!iC(a,r,d,d+c.length))){if(c instanceof ai){if(s&wn.ExcludeBuffers)continue;let h=c.findChild(0,c.buffer.length,n,r-d,a);if(h>-1)return new $u(new ag(i,c,e,d),null,h)}else if(s&wn.IncludeAnonymous||!c.type.isAnonymous||og(c)){let h;if(!(s&wn.IgnoreMounts)&&(h=$i.get(c))&&!h.overlay)return new t(h.tree,d,e,i);let p=new t(c,d,e,i);return s&wn.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(n<0?c.children.length-1:0,n,r,a,s)}}}if(s&wn.IncludeAnonymous||!i.type.isAnonymous||(i.index>=0?e=i.index+n:e=n<0?-1:i._parent._tree.children.length,i=i._parent,!i))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(e,n,r=0){let a;if(!(r&wn.IgnoreOverlays)&&(a=$i.get(this._tree))&&a.overlay){let s=e-this.from,i=r&wn.EnterBracketed&&a.bracketed;for(let{from:o,to:l}of a.overlay)if((n>0||i?o<=s:o<s)&&(n<0||i?l>=s:l>s))return new t(a.tree,a.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,n,r)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}};function aC(t,e,n,r){let a=t.cursor(),s=[];if(!a.firstChild())return s;if(n!=null){for(let i=!1;!i;)if(i=a.type.is(n),!a.nextSibling())return s}for(;;){if(r!=null&&a.type.is(r))return s;if(a.type.is(e)&&s.push(a.node),!a.nextSibling())return r==null?s:[]}}function rg(t,e,n=e.length-1){for(let r=t;n>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(e[n]&&e[n]!=r.name)return!1;n--}}return!0}var ag=class{constructor(e,n,r,a){this.parent=e,this.buffer=n,this.index=r,this.start=a}},$u=class t extends uf{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,n,r){super(),this.context=e,this._parent=n,this.index=r,this.type=e.buffer.set.types[e.buffer.buffer[r]]}child(e,n,r){let{buffer:a}=this.context,s=a.findChild(this.index+4,a.buffer[this.index+3],e,n-this.context.start,r);return s<0?null:new t(this.context,this,s)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,n,r=0){if(r&wn.ExcludeBuffers)return null;let{buffer:a}=this.context,s=a.findChild(this.index+4,a.buffer[this.index+3],n>0?1:-1,e-this.context.start,n);return s<0?null:new t(this.context,this,s)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,n=e.buffer[this.index+3];return n<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new t(this.context,this._parent,n):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,n=this._parent?this._parent.index+4:0;return this.index==n?this.externalSibling(-1):new t(this.context,this._parent,e.findChild(n,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],n=[],{buffer:r}=this.context,a=this.index+4,s=r.buffer[this.index+3];if(s>a){let i=r.buffer[this.index+1];e.push(r.slice(a,s,i)),n.push(0)}return new Jn(this.type,e,n,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}};function oC(t){if(!t.length)return null;let e=0,n=t[0];for(let s=1;s<t.length;s++){let i=t[s];(i.from>n.from||i.to<n.to)&&(n=i,e=s)}let r=n instanceof Va&&n.index<0?null:n.parent,a=t.slice();return r?a[e]=r:a.splice(e,1),new sg(a,n)}var sg=class{constructor(e,n){this.heads=e,this.node=n}get next(){return oC(this.heads)}};function OD(t,e,n){let r=t.resolveInner(e,n),a=null;for(let s=r instanceof Va?r:r.context.parent;s;s=s.parent)if(s.index<0){let i=s.parent;(a||(a=[r])).push(i.resolve(e,n)),s=i}else{let i=$i.get(s.tree);if(i&&i.overlay&&i.overlay[0].from<=e&&i.overlay[i.overlay.length-1].to>=e){let o=new Va(i.tree,i.overlay[0].from+s.from,-1,s);(a||(a=[r])).push(Vu(o,e,n,!1))}}return a?oC(a):r}var Ku=class{get name(){return this.type.name}constructor(e,n=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=n&~wn.EnterBracketed,e instanceof Va)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let r=e._parent;r;r=r._parent)this.stack.unshift(r.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,n){this.index=e;let{start:r,buffer:a}=this.buffer;return this.type=n||a.set.types[a.buffer[e]],this.from=r+a.buffer[e+1],this.to=r+a.buffer[e+2],!0}yield(e){return e?e instanceof Va?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,n,r){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,n,r,this.mode));let{buffer:a}=this.buffer,s=a.findChild(this.index+4,a.buffer[this.index+3],e,n-this.buffer.start,r);return s<0?!1:(this.stack.push(this.index),this.yieldBuf(s))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,n,r=this.mode){return this.buffer?r&wn.ExcludeBuffers?!1:this.enterChild(1,e,n):this.yield(this._tree.enter(e,n,r))}parent(){if(!this.buffer)return this.yieldNode(this.mode&wn.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&wn.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:n}=this.buffer,r=this.stack.length-1;if(e<0){let a=r<0?0:this.stack[r]+4;if(this.index!=a)return this.yieldBuf(n.findChild(a,this.index,-1,0,4))}else{let a=n.buffer[this.index+3];if(a<(r<0?n.buffer.length:n.buffer[this.stack[r]+3]))return this.yieldBuf(a)}return r<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let n,r,{buffer:a}=this;if(a){if(e>0){if(this.index<a.buffer.buffer.length)return!1}else for(let s=0;s<this.index;s++)if(a.buffer.buffer[s+3]<this.index)return!1;({index:n,parent:r}=a)}else({index:n,_parent:r}=this._tree);for(;r;{index:n,_parent:r}=r)if(n>-1)for(let s=n+e,i=e<0?-1:r._tree.children.length;s!=i;s+=e){let o=r._tree.children[s];if(this.mode&wn.IncludeAnonymous||o instanceof ai||!o.type.isAnonymous||og(o))return!1}return!0}move(e,n){if(n&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,n=0){for(;(this.from==this.to||(n<1?this.from>=e:this.from>e)||(n>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,n););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,n=null,r=0;if(e&&e.context==this.buffer)e:for(let a=this.index,s=this.stack.length;s>=0;){for(let i=e;i;i=i._parent)if(i.index==a){if(a==this.index)return i;n=i,r=s+1;break e}a=this.stack[--s]}for(let a=r;a<this.stack.length;a++)n=new $u(this.buffer,n,this.stack[a]);return this.bufferNode=new $u(this.buffer,n,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,n){for(let r=0;;){let a=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){r++;continue}this.type.isAnonymous||(a=!0)}for(;;){if(a&&n&&n(this),a=this.type.isAnonymous,!r)return;if(this.nextSibling())break;this.parent(),r--,a=!0}}}matchContext(e){if(!this.buffer)return rg(this.node.parent,e);let{buffer:n}=this.buffer,{types:r}=n.set;for(let a=e.length-1,s=this.stack.length-1;a>=0;s--){if(s<0)return rg(this._tree,e,a);let i=r[n.buffer[this.stack[s]]];if(!i.isAnonymous){if(e[a]&&e[a]!=i.name)return!1;a--}}return!0}};function og(t){return t.children.some(e=>e instanceof ai||!e.type.isAnonymous||og(e))}function BD(t){var e;let{buffer:n,nodeSet:r,maxBufferLength:a=1024,reused:s=[],minRepeatType:i=r.types.length}=t,o=Array.isArray(n)?new ng(n,n.length):n,l=r.types,u=0,c=0;function d(I,L,v,k,O,R){let{id:P,start:H,end:w,size:N}=o,j=c,K=u;if(N<0)if(o.next(),N==-1){let re=s[P];v.push(re),k.push(H-I);return}else if(N==-3){u=P;return}else if(N==-4){c=P;return}else throw new RangeError(`Unrecognized record size: ${N}`);let A=l[P],F,_,X=H-I;if(w-H<=a&&(_=m(o.pos-L,O))){let re=new Uint16Array(_.size-_.skip),ae=o.pos-_.size,Le=re.length;for(;o.pos>ae;)Le=x(_.start,re,Le);F=new ai(re,w-_.start,r),X=_.start-I}else{let re=o.pos-N;o.next();let ae=[],Le=[],ye=P>=i?P:-1,q=0,Q=w;for(;o.pos>re;)ye>=0&&o.id==ye&&o.size>=0?(o.end<=Q-a&&(p(ae,Le,H,q,o.end,Q,ye,j,K),q=ae.length,Q=o.end),o.next()):R>2500?f(H,re,ae,Le):d(H,re,ae,Le,ye,R+1);if(ye>=0&&q>0&&q<ae.length&&p(ae,Le,H,q,H,Q,ye,j,K),ae.reverse(),Le.reverse(),ye>-1&&q>0){let te=h(A,K);F=lg(A,ae,Le,0,ae.length,0,w-H,te,te)}else F=g(A,ae,Le,w-H,j-w,K)}v.push(F),k.push(X)}function f(I,L,v,k){let O=[],R=0,P=-1;for(;o.pos>L;){let{id:H,start:w,end:N,size:j}=o;if(j>4)o.next();else{if(P>-1&&w<P)break;P<0&&(P=N-a),O.push(H,w,N),R++,o.next()}}if(R){let H=new Uint16Array(R*4),w=O[O.length-2];for(let N=O.length-3,j=0;N>=0;N-=3)H[j++]=O[N],H[j++]=O[N+1]-w,H[j++]=O[N+2]-w,H[j++]=j;v.push(new ai(H,O[2]-w,r)),k.push(w-I)}}function h(I,L){return(v,k,O)=>{let R=0,P=v.length-1,H,w;if(P>=0&&(H=v[P])instanceof Jn){if(!P&&H.type==I&&H.length==O)return H;(w=H.prop(ht.lookAhead))&&(R=k[P]+H.length+w)}return g(I,v,k,O,R,L)}}function p(I,L,v,k,O,R,P,H,w){let N=[],j=[];for(;I.length>k;)N.push(I.pop()),j.push(L.pop()+v-O);I.push(g(r.types[P],N,j,R-O,H-R,w)),L.push(O-v)}function g(I,L,v,k,O,R,P){if(R){let H=[ht.contextHash,R];P=P?[H].concat(P):[H]}if(O>25){let H=[ht.lookAhead,O];P=P?[H].concat(P):[H]}return new Jn(I,L,v,k,P)}function m(I,L){let v=o.fork(),k=0,O=0,R=0,P=v.end-a,H={size:0,start:0,skip:0};e:for(let w=v.pos-I;v.pos>w;){let N=v.size;if(v.id==L&&N>=0){H.size=k,H.start=O,H.skip=R,R+=4,k+=4,v.next();continue}let j=v.pos-N;if(N<0||j<w||v.start<P)break;let K=v.id>=i?4:0,A=v.start;for(v.next();v.pos>j;){if(v.size<0)if(v.size==-3||v.size==-4)K+=4;else break e;else v.id>=i&&(K+=4);v.next()}O=A,k+=N,R+=K}return(L<0||k==I)&&(H.size=k,H.start=O,H.skip=R),H.size>4?H:void 0}function x(I,L,v){let{id:k,start:O,end:R,size:P}=o;if(o.next(),P>=0&&k<i){let H=v;if(P>4){let w=o.pos-(P-4);for(;o.pos>w;)v=x(I,L,v)}L[--v]=H,L[--v]=R-I,L[--v]=O-I,L[--v]=k}else P==-3?u=k:P==-4&&(c=k);return v}let b=[],y=[];for(;o.pos>0;)d(t.start||0,t.bufferStart||0,b,y,-1,0);let C=(e=t.length)!==null&&e!==void 0?e:b.length?y[0]+b[0].length:0;return new Jn(l[t.topID],b.reverse(),y.reverse(),C)}var sC=new WeakMap;function lf(t,e){if(!t.isAnonymous||e instanceof ai||e.type!=t)return 1;let n=sC.get(e);if(n==null){n=1;for(let r of e.children){if(r.type!=t||!(r instanceof Jn)){n=1;break}n+=lf(t,r)}sC.set(e,n)}return n}function lg(t,e,n,r,a,s,i,o,l){let u=0;for(let p=r;p<a;p++)u+=lf(t,e[p]);let c=Math.ceil(u*1.5/8),d=[],f=[];function h(p,g,m,x,b){for(let y=m;y<x;){let C=y,I=g[y],L=lf(t,p[y]);for(y++;y<x;y++){let v=lf(t,p[y]);if(L+v>=c)break;L+=v}if(y==C+1){if(L>c){let v=p[C];h(v.children,v.positions,0,v.children.length,g[C]+b);continue}d.push(p[C])}else{let v=g[y-1]+p[y-1].length-I;d.push(lg(t,p,g,C,y,I,v,null,l))}f.push(I+b-s)}}return h(e,n,r,a,0),(o||l)(d,f,i)}var Ki=class t{constructor(e,n,r,a,s=!1,i=!1){this.from=e,this.to=n,this.tree=r,this.offset=a,this.open=(s?1:0)|(i?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,n=[],r=!1){let a=[new t(0,e.length,e,0,!1,r)];for(let s of n)s.to>e.length&&a.push(s);return a}static applyChanges(e,n,r=128){if(!n.length)return e;let a=[],s=1,i=e.length?e[0]:null;for(let o=0,l=0,u=0;;o++){let c=o<n.length?n[o]:null,d=c?c.fromA:1e9;if(d-l>=r)for(;i&&i.from<d;){let f=i;if(l>=f.from||d<=f.to||u){let h=Math.max(f.from,l)-u,p=Math.min(f.to,d)-u;f=h>=p?null:new t(h,p,f.tree,f.offset+u,o>0,!!c)}if(f&&a.push(f),i.to>d)break;i=s<e.length?e[s++]:null}if(!c)break;l=c.toA,u=c.toA-c.toB}return a}},cf=class{startParse(e,n,r){return typeof e=="string"&&(e=new ig(e)),r=r?r.length?r.map(a=>new qu(a.from,a.to)):[new qu(0,0)]:[new qu(0,e.length)],this.createParse(e,n||[],r)}parse(e,n,r){let a=this.startParse(e,n,r);for(;;){let s=a.advance();if(s)return s}}},ig=class{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,n){return this.string.slice(e,n)}};var tq=new ht({perNode:!0});var _D=0,Ca=class t{constructor(e,n,r,a){this.name=e,this.set=n,this.base=r,this.modified=a,this.id=_D++}toString(){let{name:e}=this;for(let n of this.modified)n.name&&(e=`${n.name}(${e})`);return e}static define(e,n){let r=typeof e=="string"?e:"?";if(e instanceof t&&(n=e),n?.base)throw new Error("Can not derive from a modified tag");let a=new t(r,[],null,[]);if(a.set.push(a),n)for(let s of n.set)a.set.push(s);return a}static defineModifier(e){let n=new pf(e);return r=>r.modified.indexOf(n)>-1?r:pf.get(r.base||r,r.modified.concat(n).sort((a,s)=>a.id-s.id))}},HD=0,pf=class t{constructor(e){this.name=e,this.instances=[],this.id=HD++}static get(e,n){if(!n.length)return e;let r=n[0].instances.find(o=>o.base==e&&UD(n,o.modified));if(r)return r;let a=[],s=new Ca(e.name,a,e,n);for(let o of n)o.instances.push(s);let i=GD(n);for(let o of e.set)if(!o.modified.length)for(let l of i)a.push(t.get(o,l));return s}};function UD(t,e){return t.length==e.length&&t.every((n,r)=>n==e[r])}function GD(t){let e=[[]];for(let n=0;n<t.length;n++)for(let r=0,a=e.length;r<a;r++)e.push(e[r].concat(t[n]));return e.sort((n,r)=>r.length-n.length)}function cC(t){let e=Object.create(null);for(let n in t){let r=t[n];Array.isArray(r)||(r=[r]);for(let a of n.split(" "))if(a){let s=[],i=2,o=a;for(let d=0;;){if(o=="..."&&d>0&&d+3==a.length){i=1;break}let f=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(o);if(!f)throw new RangeError("Invalid path: "+a);if(s.push(f[0]=="*"?"":f[0][0]=='"'?JSON.parse(f[0]):f[0]),d+=f[0].length,d==a.length)break;let h=a[d++];if(d==a.length&&h=="!"){i=0;break}if(h!="/")throw new RangeError("Invalid path: "+a);o=a.slice(d)}let l=s.length-1,u=s[l];if(!u)throw new RangeError("Invalid path: "+a);let c=new Yi(r,i,l>0?s.slice(0,l):null);e[u]=c.sort(e[u])}}return dC.add(e)}var dC=new ht({combine(t,e){let n,r,a;for(;t||e;){if(!t||e&&t.depth<=e.depth?(a=e,e=e.next):(a=t,t=t.next),n&&n.mode==a.mode&&!a.context&&!n.context)continue;let s=new Yi(a.tags,a.mode,a.context);n?n.next=s:r=s,n=s}return r}}),Yi=class{constructor(e,n,r,a){this.tags=e,this.mode=n,this.context=r,this.next=a}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}};Yi.empty=new Yi([],2,null);function fg(t,e){let n=Object.create(null);for(let s of t)if(!Array.isArray(s.tag))n[s.tag.id]=s.class;else for(let i of s.tag)n[i.id]=s.class;let{scope:r,all:a=null}=e||{};return{style:s=>{let i=a;for(let o of s)for(let l of o.set){let u=n[l.id];if(u){i=i?i+" "+u:u;break}}return i},scope:r}}function zD(t,e){let n=null;for(let r of t){let a=r.style(e);a&&(n=n?n+" "+a:a)}return n}function hg(t,e,n,r=0,a=t.length){let s=new cg(r,Array.isArray(e)?e:[e],n);s.highlightRange(t.cursor(),r,a,"",s.highlighters),s.flush(a)}var cg=class{constructor(e,n,r){this.at=e,this.highlighters=n,this.span=r,this.class=""}startSpan(e,n){n!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=n)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,n,r,a,s){let{type:i,from:o,to:l}=e;if(o>=r||l<=n)return;i.isTop&&(s=this.highlighters.filter(h=>!h.scope||h.scope(i)));let u=a,c=WD(e)||Yi.empty,d=zD(s,c.tags);if(d&&(u&&(u+=" "),u+=d,c.mode==1&&(a+=(a?" ":"")+d)),this.startSpan(Math.max(n,o),u),c.opaque)return;let f=e.tree&&e.tree.prop(ht.mounted);if(f&&f.overlay){let h=e.node.enter(f.overlay[0].from+o,1),p=this.highlighters.filter(m=>!m.scope||m.scope(f.tree.type)),g=e.firstChild();for(let m=0,x=o;;m++){let b=m<f.overlay.length?f.overlay[m]:null,y=b?b.from+o:l,C=Math.max(n,x),I=Math.min(r,y);if(C<I&&g)for(;e.from<I&&(this.highlightRange(e,C,I,a,s),this.startSpan(Math.min(I,e.to),u),!(e.to>=y||!e.nextSibling())););if(!b||y>r)break;x=b.to+o,x>n&&(this.highlightRange(h.cursor(),Math.max(n,b.from+o),Math.min(r,x),"",p),this.startSpan(Math.min(r,x),u))}g&&e.parent()}else if(e.firstChild()){f&&(a="");do if(!(e.to<=n)){if(e.from>=r)break;this.highlightRange(e,n,r,a,s),this.startSpan(Math.min(r,e.to),u)}while(e.nextSibling());e.parent()}}};function WD(t){let e=t.type.prop(dC);for(;e&&e.context&&!t.matchContext(e.context);)e=e.next;return e||null}var be=Ca.define,df=be(),si=be(),lC=be(si),uC=be(si),ii=be(),ff=be(ii),ug=be(ii),Xa=be(),Xi=be(Xa),$a=be(),Ka=be(),dg=be(),Xu=be(dg),hf=be(),Se={comment:df,lineComment:be(df),blockComment:be(df),docComment:be(df),name:si,variableName:be(si),typeName:lC,tagName:be(lC),propertyName:uC,attributeName:be(uC),className:be(si),labelName:be(si),namespace:be(si),macroName:be(si),literal:ii,string:ff,docString:be(ff),character:be(ff),attributeValue:be(ff),number:ug,integer:be(ug),float:be(ug),bool:be(ii),regexp:be(ii),escape:be(ii),color:be(ii),url:be(ii),keyword:$a,self:be($a),null:be($a),atom:be($a),unit:be($a),modifier:be($a),operatorKeyword:be($a),controlKeyword:be($a),definitionKeyword:be($a),moduleKeyword:be($a),operator:Ka,derefOperator:be(Ka),arithmeticOperator:be(Ka),logicOperator:be(Ka),bitwiseOperator:be(Ka),compareOperator:be(Ka),updateOperator:be(Ka),definitionOperator:be(Ka),typeOperator:be(Ka),controlOperator:be(Ka),punctuation:dg,separator:be(dg),bracket:Xu,angleBracket:be(Xu),squareBracket:be(Xu),paren:be(Xu),brace:be(Xu),content:Xa,heading:Xi,heading1:be(Xi),heading2:be(Xi),heading3:be(Xi),heading4:be(Xi),heading5:be(Xi),heading6:be(Xi),contentSeparator:be(Xa),list:be(Xa),quote:be(Xa),emphasis:be(Xa),strong:be(Xa),link:be(Xa),monospace:be(Xa),strikethrough:be(Xa),inserted:be(),deleted:be(),changed:be(),invalid:be(),meta:hf,documentMeta:be(hf),annotation:be(hf),processingInstruction:be(hf),definition:Ca.defineModifier("definition"),constant:Ca.defineModifier("constant"),function:Ca.defineModifier("function"),standard:Ca.defineModifier("standard"),local:Ca.defineModifier("local"),special:Ca.defineModifier("special")};for(let t in Se){let e=Se[t];e instanceof Ca&&(e.name=t)}var aq=fg([{tag:Se.link,class:"tok-link"},{tag:Se.heading,class:"tok-heading"},{tag:Se.emphasis,class:"tok-emphasis"},{tag:Se.strong,class:"tok-strong"},{tag:Se.keyword,class:"tok-keyword"},{tag:Se.atom,class:"tok-atom"},{tag:Se.bool,class:"tok-bool"},{tag:Se.url,class:"tok-url"},{tag:Se.labelName,class:"tok-labelName"},{tag:Se.inserted,class:"tok-inserted"},{tag:Se.deleted,class:"tok-deleted"},{tag:Se.literal,class:"tok-literal"},{tag:Se.string,class:"tok-string"},{tag:Se.number,class:"tok-number"},{tag:[Se.regexp,Se.escape,Se.special(Se.string)],class:"tok-string2"},{tag:Se.variableName,class:"tok-variableName"},{tag:Se.local(Se.variableName),class:"tok-variableName tok-local"},{tag:Se.definition(Se.variableName),class:"tok-variableName tok-definition"},{tag:Se.special(Se.variableName),class:"tok-variableName2"},{tag:Se.definition(Se.propertyName),class:"tok-propertyName tok-definition"},{tag:Se.typeName,class:"tok-typeName"},{tag:Se.namespace,class:"tok-namespace"},{tag:Se.className,class:"tok-className"},{tag:Se.macroName,class:"tok-macroName"},{tag:Se.propertyName,class:"tok-propertyName"},{tag:Se.operator,class:"tok-operator"},{tag:Se.comment,class:"tok-comment"},{tag:Se.meta,class:"tok-meta"},{tag:Se.invalid,class:"tok-invalid"},{tag:Se.punctuation,class:"tok-punctuation"}]);var pg,Ju=new ht;var jD=new ht,aa=class{constructor(e,n,r=[],a=""){this.data=e,this.name=a,Dt.prototype.hasOwnProperty("tree")||Object.defineProperty(Dt.prototype,"tree",{get(){return ws(this)}}),this.parser=n,this.extension=[oi.of(this),Dt.languageData.of((s,i,o)=>{let l=fC(s,i,o),u=l.type.prop(Ju);if(!u)return[];let c=s.facet(u),d=l.type.prop(jD);if(d){let f=l.resolve(i-l.from,o);for(let h of d)if(h.test(f,s)){let p=s.facet(h.facet);return h.type=="replace"?p:p.concat(c)}}return c})].concat(r)}isActiveAt(e,n,r=-1){return fC(e,n,r).type.prop(Ju)==this.data}findRegions(e){let n=e.facet(oi);if(n?.data==this.data)return[{from:0,to:e.doc.length}];if(!n||!n.allowsNesting)return[];let r=[],a=(s,i)=>{if(s.prop(Ju)==this.data){r.push({from:i,to:i+s.length});return}let o=s.prop(ht.mounted);if(o){if(o.tree.prop(Ju)==this.data){if(o.overlay)for(let l of o.overlay)r.push({from:l.from+i,to:l.to+i});else r.push({from:i,to:i+s.length});return}else if(o.overlay){let l=r.length;if(a(o.tree,o.overlay[0].from+i),r.length>l)return}}for(let l=0;l<s.children.length;l++){let u=s.children[l];u instanceof Jn&&a(u,s.positions[l]+i)}};return a(ws(e),0),r}get allowsNesting(){return!0}};aa.setState=Ct.define();function fC(t,e,n){let r=t.facet(oi),a=ws(t).topNode;if(!r||r.allowsNesting)for(let s=a;s;s=s.enter(e,n,wn.ExcludeBuffers|wn.EnterBracketed))s.type.isTop&&(a=s);return a}function ws(t){let e=t.field(aa.state,!1);return e?e.tree:Jn.empty}var xg=class{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,n){let r=this.cursorPos-this.string.length;return e<r||n>=this.cursorPos?this.doc.sliceString(e,n):this.string.slice(e-r,n-r)}},Yu=null,bg=class t{constructor(e,n,r=[],a,s,i,o,l){this.parser=e,this.state=n,this.fragments=r,this.tree=a,this.treeLen=s,this.viewport=i,this.skipped=o,this.scheduleOn=l,this.parse=null,this.tempSkipped=[]}static create(e,n,r){return new t(e,n,[],Jn.empty,0,r,[],null)}startParse(){return this.parser.startParse(new xg(this.state.doc),this.fragments)}work(e,n){return n!=null&&n>=this.state.doc.length&&(n=void 0),this.tree!=Jn.empty&&this.isDone(n??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var r;if(typeof e=="number"){let a=Date.now()+e;e=()=>Date.now()>a}for(this.parse||(this.parse=this.startParse()),n!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>n)&&n<this.state.doc.length&&this.parse.stopAt(n);;){let a=this.parse.advance();if(a)if(this.fragments=this.withoutTempSkipped(Ki.addTree(a,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(r=this.parse.stoppedAt)!==null&&r!==void 0?r:this.state.doc.length,this.tree=a,this.parse=null,this.treeLen<(n??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,n;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(n=this.parse.advance()););}),this.treeLen=e,this.tree=n,this.fragments=this.withoutTempSkipped(Ki.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let n=Yu;Yu=this;try{return e()}finally{Yu=n}}withoutTempSkipped(e){for(let n;n=this.tempSkipped.pop();)e=hC(e,n.from,n.to);return e}changes(e,n){let{fragments:r,tree:a,treeLen:s,viewport:i,skipped:o}=this;if(this.takeTree(),!e.empty){let l=[];if(e.iterChangedRanges((u,c,d,f)=>l.push({fromA:u,toA:c,fromB:d,toB:f})),r=Ki.applyChanges(r,l),a=Jn.empty,s=0,i={from:e.mapPos(i.from,-1),to:e.mapPos(i.to,1)},this.skipped.length){o=[];for(let u of this.skipped){let c=e.mapPos(u.from,1),d=e.mapPos(u.to,-1);c<d&&o.push({from:c,to:d})}}}return new t(this.parser,n,r,a,s,i,o,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let n=this.skipped.length;for(let r=0;r<this.skipped.length;r++){let{from:a,to:s}=this.skipped[r];a<e.to&&s>e.from&&(this.fragments=hC(this.fragments,a,s),this.skipped.splice(r--,1))}return this.skipped.length>=n?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,n){this.skipped.push({from:e,to:n})}static getSkippingParser(e){return new class extends cf{createParse(n,r,a){let s=a[0].from,i=a[a.length-1].to;return{parsedPos:s,advance(){let l=Yu;if(l){for(let u of a)l.tempSkipped.push(u);e&&(l.scheduleOn=l.scheduleOn?Promise.all([l.scheduleOn,e]):e)}return this.parsedPos=i,new Jn(Wr.none,[],[],i-s)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let n=this.fragments;return this.treeLen>=e&&n.length&&n[0].from==0&&n[0].to>=e}static get(){return Yu}};function hC(t,e,n){return Ki.applyChanges(t,[{fromA:e,toA:n,fromB:e,toB:n}])}var Zu=class t{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let n=this.context.changes(e.changes,e.state),r=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),n.viewport.to);return n.work(20,r)||n.takeTree(),new t(n)}static init(e){let n=Math.min(3e3,e.doc.length),r=bg.create(e.facet(oi).parser,e,{from:0,to:n});return r.work(20,n)||r.takeTree(),new t(r)}};aa.state=En.define({create:Zu.init,update(t,e){for(let n of e.effects)if(n.is(aa.setState))return n.value;return e.startState.facet(oi)!=e.state.facet(oi)?Zu.init(e.state):t.apply(e)}});var xC=t=>{let e=setTimeout(()=>t(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(xC=t=>{let e=-1,n=setTimeout(()=>{e=requestIdleCallback(t,{timeout:400})},100);return()=>e<0?clearTimeout(n):cancelIdleCallback(e)});var mg=typeof navigator<"u"&&(!((pg=navigator.scheduling)===null||pg===void 0)&&pg.isInputPending)?()=>navigator.scheduling.isInputPending():null,qD=Nr.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let n=this.view.state.field(aa.state).context;(n.updateViewport(e.view.viewport)||this.view.viewport.to>n.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(n)}scheduleWork(){if(this.working)return;let{state:e}=this.view,n=e.field(aa.state);(n.tree!=n.context.tree||!n.context.isDone(e.doc.length))&&(this.working=xC(this.work))}work(e){this.working=null;let n=Date.now();if(this.chunkEnd<n&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=n+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:r,viewport:{to:a}}=this.view,s=r.field(aa.state);if(s.tree==s.context.tree&&s.context.isDone(a+1e5))return;let i=Date.now()+Math.min(this.chunkBudget,100,e&&!mg?Math.max(25,e.timeRemaining()-5):1e9),o=s.context.treeLen<a&&r.doc.length>a+1e3,l=s.context.work(()=>mg&&mg()||Date.now()>i,a+(o?0:1e5));this.chunkBudget-=Date.now()-n,(l||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:aa.setState.of(new Zu(s.context))})),this.chunkBudget>0&&!(l&&!o)&&this.scheduleWork(),this.checkAsyncSchedule(s.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(n=>wa(this.view.state,n)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),oi=Ee.define({combine(t){return t.length?t[0]:null},enables:t=>[aa.state,qD,Ne.contentAttributes.compute([t],e=>{let n=e.facet(t);return n&&n.name?{"data-language":n.name}:{}})]});var VD=Ee.define(),mf=Ee.define({combine:t=>{if(!t.length)return" ";let e=t[0];if(!e||/\S/.test(e)||Array.from(e).some(n=>n!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(t[0]));return e}});function Qu(t){let e=t.facet(mf);return e.charCodeAt(0)==9?t.tabSize*e.length:e.length}function ec(t,e){let n="",r=t.tabSize,a=t.facet(mf)[0];if(a==" "){for(;e>=r;)n+=" ",e-=r;a=" "}for(let s=0;s<e;s++)n+=a;return n}function Sg(t,e){t instanceof Dt&&(t=new Ji(t));for(let r of t.state.facet(VD)){let a=r(t,e);if(a!==void 0)return a}let n=ws(t.state);return n.length>=e?KD(t,n,e):null}var Ji=class{constructor(e,n={}){this.state=e,this.options=n,this.unit=Qu(e)}lineAt(e,n=1){let r=this.state.doc.lineAt(e),{simulateBreak:a,simulateDoubleBreak:s}=this.options;return a!=null&&a>=r.from&&a<=r.to?s&&a==e?{text:"",from:e}:(n<0?a<e:a<=e)?{text:r.text.slice(a-r.from),from:a}:{text:r.text.slice(0,a-r.from),from:r.from}:r}textAfterPos(e,n=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:r,from:a}=this.lineAt(e,n);return r.slice(e-a,Math.min(r.length,e+100-a))}column(e,n=1){let{text:r,from:a}=this.lineAt(e,n),s=this.countColumn(r,e-a),i=this.options.overrideIndentation?this.options.overrideIndentation(a):-1;return i>-1&&(s+=i-this.countColumn(r,r.search(/\S|$/))),s}countColumn(e,n=e.length){return Ui(e,this.state.tabSize,n)}lineIndent(e,n=1){let{text:r,from:a}=this.lineAt(e,n),s=this.options.overrideIndentation;if(s){let i=s(a);if(i>-1)return i}return this.countColumn(r,r.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}},$D=new ht;function KD(t,e,n){let r=e.resolveStack(n),a=e.resolveInner(n,-1).resolve(n,0).enterUnfinishedNodesBefore(n);if(a!=r.node){let s=[];for(let i=a;i&&!(i.from<r.node.from||i.to>r.node.to||i.from==r.node.from&&i.type==r.node.type);i=i.parent)s.push(i);for(let i=s.length-1;i>=0;i--)r={node:s[i],next:r}}return bC(r,t,n)}function bC(t,e,n){for(let r=t;r;r=r.next){let a=YD(r.node);if(a)return a(yg.create(e,n,r))}return 0}function XD(t){return t.pos==t.options.simulateBreak&&t.options.simulateDoubleBreak}function YD(t){let e=t.type.prop($D);if(e)return e;let n=t.firstChild,r;if(n&&(r=n.type.prop(ht.closedBy))){let a=t.lastChild,s=a&&r.indexOf(a.name)>-1;return i=>eF(i,!0,1,void 0,s&&!XD(i)?a.from:void 0)}return t.parent==null?JD:null}function JD(){return 0}var yg=class t extends Ji{constructor(e,n,r){super(e.state,e.options),this.base=e,this.pos=n,this.context=r}get node(){return this.context.node}static create(e,n,r){return new t(e,n,r)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let n=this.state.doc.lineAt(e.from);for(;;){let r=e.resolve(n.from);for(;r.parent&&r.parent.from==r.from;)r=r.parent;if(ZD(r,e))break;n=this.state.doc.lineAt(r.from)}return this.lineIndent(n.from)}continue(){return bC(this.context.next,this.base,this.pos)}};function ZD(t,e){for(let n=e;n;n=n.parent)if(t==n)return!0;return!1}function QD(t){let e=t.node,n=e.childAfter(e.from),r=e.lastChild;if(!n)return null;let a=t.options.simulateBreak,s=t.state.doc.lineAt(n.from),i=a==null||a<=s.from?s.to:Math.min(s.to,a);for(let o=n.to;;){let l=e.childAfter(o);if(!l||l==r)return null;if(!l.type.isSkipped){if(l.from>=i)return null;let u=/^ */.exec(s.text.slice(n.to-s.from))[0].length;return{from:n.from,to:n.to+u}}o=l.to}}function eF(t,e,n,r,a){let s=t.textAfter,i=s.match(/^\s*/)[0].length,o=r&&s.slice(i,i+r.length)==r||a==t.pos+i,l=e?QD(t):null;return l?o?t.column(l.from):t.column(l.to):t.baseIndent+(o?0:t.unit*n)}var vg=class t{constructor(e,n){this.specs=e;let r;function a(o){let l=Pr.newName();return(r||(r=Object.create(null)))["."+l]=o,l}let s=typeof n.all=="string"?n.all:n.all?a(n.all):void 0,i=n.scope;this.scope=i instanceof aa?o=>o.prop(Ju)==i.data:i?o=>o==i:void 0,this.style=fg(e.map(o=>({tag:o.tag,class:o.class||a(Object.assign({},o,{tag:null}))})),{all:s}).style,this.module=r?new Pr(r):null,this.themeType=n.themeType}static define(e,n){return new t(e,n||{})}},tF=Ee.define(),nF=Ee.define({combine(t){return t.length?[t[0]]:null}});function rF(t){let e=t.facet(tF);return e.length?e:t.facet(nF)}function yC(t,e,n){let r=rF(t),a=null;if(r){for(let s of r)if(!s.scope||n&&s.scope(n)){let i=s.style(e);i&&(a=a?a+" "+i:i)}}return a}var hq=vg.define([{tag:Se.meta,color:"#404740"},{tag:Se.link,textDecoration:"underline"},{tag:Se.heading,textDecoration:"underline",fontWeight:"bold"},{tag:Se.emphasis,fontStyle:"italic"},{tag:Se.strong,fontWeight:"bold"},{tag:Se.strikethrough,textDecoration:"line-through"},{tag:Se.keyword,color:"#708"},{tag:[Se.atom,Se.bool,Se.url,Se.contentSeparator,Se.labelName],color:"#219"},{tag:[Se.literal,Se.inserted],color:"#164"},{tag:[Se.string,Se.deleted],color:"#a11"},{tag:[Se.regexp,Se.escape,Se.special(Se.string)],color:"#e40"},{tag:Se.definition(Se.variableName),color:"#00f"},{tag:Se.local(Se.variableName),color:"#30a"},{tag:[Se.typeName,Se.namespace],color:"#085"},{tag:Se.className,color:"#167"},{tag:[Se.special(Se.variableName),Se.macroName],color:"#256"},{tag:Se.definition(Se.propertyName),color:"#00c"},{tag:Se.comment,color:"#940"},{tag:Se.invalid,color:"#f00"}]);var aF=1e4,sF="()[]{}";var iF=new ht;function wg(t,e,n){let r=t.prop(e<0?ht.openedBy:ht.closedBy);if(r)return r;if(t.name.length==1){let a=n.indexOf(t.name);if(a>-1&&a%2==(e<0?1:0))return[n[a+e]]}return null}function kg(t){let e=t.type.prop(iF);return e?e(t.node):t}function Zi(t,e,n,r={}){let a=r.maxScanDistance||aF,s=r.brackets||sF,i=ws(t),o=i.resolveInner(e,n);for(let l=o;l;l=l.parent){let u=wg(l.type,n,s);if(u&&l.from<l.to){let c=kg(l);if(c&&(n>0?e>=c.from&&e<c.to:e>c.from&&e<=c.to))return oF(t,e,n,l,c,u,s)}}return lF(t,e,n,i,o.type,a,s)}function oF(t,e,n,r,a,s,i){let o=r.parent,l={from:a.from,to:a.to},u=0,c=o?.cursor();if(c&&(n<0?c.childBefore(r.from):c.childAfter(r.to)))do if(n<0?c.to<=r.from:c.from>=r.to){if(u==0&&s.indexOf(c.type.name)>-1&&c.from<c.to){let d=kg(c);return{start:l,end:d?{from:d.from,to:d.to}:void 0,matched:!0}}else if(wg(c.type,n,i))u++;else if(wg(c.type,-n,i)){if(u==0){let d=kg(c);return{start:l,end:d&&d.from<d.to?{from:d.from,to:d.to}:void 0,matched:!1}}u--}}while(n<0?c.prevSibling():c.nextSibling());return{start:l,matched:!1}}function lF(t,e,n,r,a,s,i){if(n<0?!e:e==t.doc.length)return null;let o=n<0?t.sliceDoc(e-1,e):t.sliceDoc(e,e+1),l=i.indexOf(o);if(l<0||l%2==0!=n>0)return null;let u={from:n<0?e-1:e,to:n>0?e+1:e},c=t.doc.iterRange(e,n>0?t.doc.length:0),d=0;for(let f=0;!c.next().done&&f<=s;){let h=c.value;n<0&&(f+=h.length);let p=e+f*n;for(let g=n>0?0:h.length-1,m=n>0?h.length:-1;g!=m;g+=n){let x=i.indexOf(h[g]);if(!(x<0||r.resolveInner(p+g,1).type!=a))if(x%2==0==n>0)d++;else{if(d==1)return{start:u,end:{from:p+g,to:p+g+1},matched:x>>1==l>>1};d--}}n>0&&(f+=h.length)}return c.done?{start:u,matched:!1}:null}var uF=Object.create(null),pC=[Wr.none];var mC=[],gC=Object.create(null),cF=Object.create(null);for(let[t,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])cF[t]=dF(uF,e);function gg(t,e){mC.indexOf(t)>-1||(mC.push(t),console.warn(e))}function dF(t,e){let n=[];for(let o of e.split(" ")){let l=[];for(let u of o.split(".")){let c=t[u]||Se[u];c?typeof c=="function"?l.length?l=l.map(c):gg(u,`Modifier ${u} used at start of tag`):l.length?gg(u,`Tag ${u} used as modifier`):l=Array.isArray(c)?c:[c]:gg(u,`Unknown highlighting tag ${u}`)}for(let u of l)n.push(u)}if(!n.length)return 0;let r=e.replace(/ /g,"_"),a=r+" "+n.map(o=>o.id),s=gC[a];if(s)return s.id;let i=gC[a]=Wr.define({id:pC.length,name:r,props:[cC({[r]:n})]});return pC.push(i),i.id}var pq={rtl:Ze.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"rtl"},bidiIsolate:nn.RTL}),ltr:Ze.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"ltr"},bidiIsolate:nn.LTR}),auto:Ze.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"auto"},bidiIsolate:null})};var Rn=class t{constructor(e,n,r,a){this.fromA=e,this.toA=n,this.fromB=r,this.toB=a}offset(e,n=e){return new t(this.fromA+e,this.toA+e,this.fromB+n,this.toB+n)}};function eo(t,e,n,r,a,s){if(t==r)return[];let i=Dg(t,e,n,r,a,s),o=Fg(t,e+i,n,r,a+i,s);e+=i,n-=o,a+=i,s-=o;let l=n-e,u=s-a;if(!l||!u)return[new Rn(e,n,a,s)];if(l>u){let d=t.slice(e,n).indexOf(r.slice(a,s));if(d>-1)return[new Rn(e,e+d,a,a),new Rn(e+d+u,n,s,s)]}else if(u>l){let d=r.slice(a,s).indexOf(t.slice(e,n));if(d>-1)return[new Rn(e,e,a,a+d),new Rn(n,n,a+d+l,s)]}if(l==1||u==1)return[new Rn(e,n,a,s)];let c=UC(t,e,n,r,a,s);if(c){let[d,f,h]=c;return eo(t,e,d,r,a,f).concat(eo(t,d+h,n,r,f+h,s))}return fF(t,e,n,r,a,s)}var tc=1e9,nc=0,Tg=!1;function fF(t,e,n,r,a,s){let i=n-e,o=s-a;if(tc<1e9&&Math.min(i,o)>tc*16||nc>0&&Date.now()>nc)return Math.min(i,o)>tc*64?[new Rn(e,n,a,s)]:vC(t,e,n,r,a,s);let l=Math.ceil((i+o)/2);Cg.reset(l),Ig.reset(l);let u=(h,p)=>t.charCodeAt(e+h)==r.charCodeAt(a+p),c=(h,p)=>t.charCodeAt(n-h-1)==r.charCodeAt(s-p-1),d=(i-o)%2!=0?Ig:null,f=d?null:Cg;for(let h=0;h<l;h++){if(h>tc||nc>0&&!(h&63)&&Date.now()>nc)return vC(t,e,n,r,a,s);let p=Cg.advance(h,i,o,l,d,!1,u)||Ig.advance(h,i,o,l,f,!0,c);if(p)return hF(t,e,n,e+p[0],r,a,s,a+p[1])}return[new Rn(e,n,a,s)]}var vf=class{constructor(){this.vec=[]}reset(e){this.len=e<<1;for(let n=0;n<this.len;n++)this.vec[n]=-1;this.vec[e+1]=0,this.start=this.end=0}advance(e,n,r,a,s,i,o){for(let l=-e+this.start;l<=e-this.end;l+=2){let u=a+l,c=l==-e||l!=e&&this.vec[u-1]<this.vec[u+1]?this.vec[u+1]:this.vec[u-1]+1,d=c-l;for(;c<n&&d<r&&o(c,d);)c++,d++;if(this.vec[u]=c,c>n)this.end+=2;else if(d>r)this.start+=2;else if(s){let f=a+(n-r)-l;if(f>=0&&f<this.len&&s.vec[f]!=-1)if(i){let h=s.vec[f];if(h>=n-c)return[h,a+h-f]}else{let h=n-s.vec[f];if(c>=h)return[c,d]}}}return null}},Cg=new vf,Ig=new vf;function hF(t,e,n,r,a,s,i,o){let l=!1;return!il(t,r)&&++r==n&&(l=!0),!il(a,o)&&++o==i&&(l=!0),l?[new Rn(e,n,s,i)]:eo(t,e,r,a,s,o).concat(eo(t,r,n,a,o,i))}function HC(t,e){let n=1,r=Math.min(t,e);for(;n<r;)n=n<<1;return n}function Dg(t,e,n,r,a,s){if(e==n||e==s||t.charCodeAt(e)!=r.charCodeAt(a))return 0;let i=HC(n-e,s-a);for(let o=e,l=a;;){let u=o+i,c=l+i;if(u>n||c>s||t.slice(o,u)!=r.slice(l,c)){if(i==1)return o-e-(il(t,o)?0:1);i=i>>1}else{if(u==n||c==s)return u-e;o=u,l=c}}}function Fg(t,e,n,r,a,s){if(e==n||a==s||t.charCodeAt(n-1)!=r.charCodeAt(s-1))return 0;let i=HC(n-e,s-a);for(let o=n,l=s;;){let u=o-i,c=l-i;if(u<e||c<a||t.slice(u,o)!=r.slice(c,l)){if(i==1)return n-o-(il(t,o)?0:1);i=i>>1}else{if(u==e||c==a)return n-u;o=u,l=c}}}function Lg(t,e,n,r,a,s,i,o){let l=r.slice(a,s),u=null;for(;;){if(u||i<o)return u;for(let c=e+i;;){il(t,c)||c++;let d=c+i;if(il(t,d)||(d+=d==c+1?1:-1),d>=n)break;let f=t.slice(c,d),h=-1;for(;(h=l.indexOf(f,h+1))!=-1;){let p=Dg(t,d,n,r,a+h+f.length,s),g=Fg(t,e,c,r,a,a+h),m=f.length+p+g;(!u||u[2]<m)&&(u=[c-g,a+h-g,m])}c=d}if(o<0)return u;i=i>>1}}function UC(t,e,n,r,a,s){let i=n-e,o=s-a;if(i<o){let l=UC(r,a,s,t,e,n);return l&&[l[1],l[0],l[2]]}return i<4||o*2<i?null:Lg(t,e,n,r,a,s,Math.floor(i/4),-1)}function vC(t,e,n,r,a,s){Tg=!0;let i=n-e,o=s-a,l;if(i<o){let f=Lg(r,a,s,t,e,n,Math.floor(i/6),50);l=f&&[f[1],f[0],f[2]]}else l=Lg(t,e,n,r,a,s,Math.floor(o/6),50);if(!l)return[new Rn(e,n,a,s)];let[u,c,d]=l;return eo(t,e,u,r,a,c).concat(eo(t,u+d,n,r,c+d,s))}function GC(t,e){for(let n=1;n<t.length;n++){let r=t[n-1],a=t[n];r.toA>a.fromA-e&&r.toB>a.fromB-e&&(t[n-1]=new Rn(r.fromA,a.toA,r.fromB,a.toB),t.splice(n--,1))}}function pF(t,e,n){for(;;){GC(n,1);let r=!1;for(let a=0;a<n.length;a++){let s=n[a],i,o;(i=Dg(t,s.fromA,s.toA,e,s.fromB,s.toB))&&(s=n[a]=new Rn(s.fromA+i,s.toA,s.fromB+i,s.toB)),(o=Fg(t,s.fromA,s.toA,e,s.fromB,s.toB))&&(s=n[a]=new Rn(s.fromA,s.toA-o,s.fromB,s.toB-o));let l=s.toA-s.fromA,u=s.toB-s.fromB;if(l&&u)continue;let c=s.fromA-(a?n[a-1].toA:0),d=(a<n.length-1?n[a+1].fromA:t.length)-s.toA;if(!c||!d)continue;let f=l?t.slice(s.fromA,s.toA):e.slice(s.fromB,s.toB);c<=f.length&&t.slice(s.fromA-c,s.fromA)==f.slice(f.length-c)?(n[a]=new Rn(s.fromA-c,s.toA-c,s.fromB-c,s.toB-c),r=!0):d<=f.length&&t.slice(s.toA,s.toA+d)==f.slice(0,d)&&(n[a]=new Rn(s.fromA+d,s.toA+d,s.fromB+d,s.toB+d),r=!0)}if(!r)break}return n}function mF(t,e,n){for(let r=0,a=0;a<t.length;a++){let s=t[a],i=s.toA-s.fromA,o=s.toB-s.fromB;if(i&&o||i>3||o>3){let l=a==t.length-1?e.length:t[a+1].fromA,u=s.fromA-r,c=l-s.toA,d=kC(e,s.fromA,u),f=wC(e,s.toA,c),h=s.fromA-d,p=f-s.toA;if((!i||!o)&&h&&p){let g=Math.max(i,o),[m,x,b]=i?[e,s.fromA,s.toA]:[n,s.fromB,s.toB];g>h&&e.slice(d,s.fromA)==m.slice(b-h,b)?(s=t[a]=new Rn(d,d+i,s.fromB-h,s.toB-h),d=s.fromA,f=wC(e,s.toA,l-s.toA)):g>p&&e.slice(s.toA,f)==m.slice(x,x+p)&&(s=t[a]=new Rn(f-i,f,s.fromB+p,s.toB+p),f=s.toA,d=kC(e,s.fromA,s.fromA-r)),h=s.fromA-d,p=f-s.toA}if(h||p)s=t[a]=new Rn(s.fromA-h,s.toA+p,s.fromB-h,s.toB+p);else if(i){if(!o){let g=CC(e,s.fromA,s.toA),m,x=g<0?-1:SC(e,s.toA,s.fromA);g>-1&&(m=g-s.fromA)<=c&&e.slice(s.fromA,g)==e.slice(s.toA,s.toA+m)?s=t[a]=s.offset(m):x>-1&&(m=s.toA-x)<=u&&e.slice(s.fromA-m,s.fromA)==e.slice(x,s.toA)&&(s=t[a]=s.offset(-m))}}else{let g=CC(n,s.fromB,s.toB),m,x=g<0?-1:SC(n,s.toB,s.fromB);g>-1&&(m=g-s.fromB)<=c&&n.slice(s.fromB,g)==n.slice(s.toB,s.toB+m)?s=t[a]=s.offset(m):x>-1&&(m=s.toB-x)<=u&&n.slice(s.fromB-m,s.fromB)==n.slice(x,s.toB)&&(s=t[a]=s.offset(-m))}}r=s.toA}return GC(t,3),t}var Qi;try{Qi=new RegExp("[\\p{Alphabetic}\\p{Number}]","u")}catch{}function zC(t){return t>48&&t<58||t>64&&t<91||t>96&&t<123}function WC(t,e){if(e==t.length)return 0;let n=t.charCodeAt(e);return n<192?zC(n)?1:0:Qi?!VC(n)||e==t.length-1?Qi.test(String.fromCharCode(n))?1:0:Qi.test(t.slice(e,e+2))?2:0:0}function jC(t,e){if(!e)return 0;let n=t.charCodeAt(e-1);return n<192?zC(n)?1:0:Qi?!$C(n)||e==1?Qi.test(String.fromCharCode(n))?1:0:Qi.test(t.slice(e-2,e))?2:0:0}var qC=8;function wC(t,e,n){if(e==t.length||!jC(t,e))return e;for(let r=e,a=e+n,s=0;s<qC;s++){let i=WC(t,r);if(!i||r+i>a)return r;r+=i}return e}function kC(t,e,n){if(!e||!WC(t,e))return e;for(let r=e,a=e-n,s=0;s<qC;s++){let i=jC(t,r);if(!i||r-i<a)return r;r-=i}return e}function SC(t,e,n){for(;e!=n;e--)if(t.charCodeAt(e-1)==10)return e;return-1}function CC(t,e,n){for(;e!=n;e++)if(t.charCodeAt(e)==10)return e;return-1}var VC=t=>t>=55296&&t<=56319,$C=t=>t>=56320&&t<=57343;function il(t,e){return!e||e==t.length||!VC(t.charCodeAt(e-1))||!$C(t.charCodeAt(e))}function gF(t,e,n){var r;let a=n?.override;return a?a(t,e):(tc=((r=n?.scanLimit)!==null&&r!==void 0?r:1e9)>>1,nc=n?.timeout?Date.now()+n.timeout:0,Tg=!1,pF(t,e,eo(t,0,t.length,e,0,e.length)))}function KC(){return!Tg}function XC(t,e,n){return mF(gF(t,e,n),t,e)}var Mr=Ee.define({combine:t=>t[0]}),Ag=Ct.define(),YC=Ee.define(),br=En.define({create(t){return null},update(t,e){for(let n of e.effects)n.is(Ag)&&(t=n.value);for(let n of e.state.facet(YC))t=n(t,e);return t}});var ks=class t{constructor(e,n,r,a,s,i=!0){this.changes=e,this.fromA=n,this.toA=r,this.fromB=a,this.toB=s,this.precise=i}offset(e,n){return e||n?new t(this.changes,this.fromA+e,this.toA+e,this.fromB+n,this.toB+n,this.precise):this}get endA(){return Math.max(this.fromA,this.toA-1)}get endB(){return Math.max(this.fromB,this.toB-1)}static build(e,n,r){let a=XC(e.toString(),n.toString(),r);return JC(a,e,n,0,0,KC())}static updateA(e,n,r,a,s){return RC(PC(e,a,!0,r.length),e,n,r,s)}static updateB(e,n,r,a,s){return RC(PC(e,a,!1,n.length),e,n,r,s)}};function IC(t,e,n,r){let a=n.lineAt(t),s=r.lineAt(e);return a.to==t&&s.to==e&&t<n.length&&e<r.length?[t+1,e+1]:[a.from,s.from]}function LC(t,e,n,r){let a=n.lineAt(t),s=r.lineAt(e);return a.from==t&&s.from==e?[t,e]:[a.to+1,s.to+1]}function JC(t,e,n,r,a,s){let i=[];for(let o=0;o<t.length;o++){let l=t[o],[u,c]=IC(l.fromA+r,l.fromB+a,e,n),[d,f]=LC(l.toA+r,l.toB+a,e,n),h=[l.offset(-u+r,-c+a)];for(;o<t.length-1;){let p=t[o+1],[g,m]=IC(p.fromA+r,p.fromB+a,e,n);if(g>d+1&&m>f+1)break;h.push(p.offset(-u+r,-c+a)),[d,f]=LC(p.toA+r,p.toB+a,e,n),o++}i.push(new ks(h,u,Math.max(u,d),c,Math.max(c,f),s))}return i}var gf=1e3;function AC(t,e,n,r){let a=0,s=t.length;for(;;){if(a==s){let c=0,d=0;a&&({toA:c,toB:d}=t[a-1]);let f=e-(n?c:d);return[c+f,d+f]}let i=a+s>>1,o=t[i],[l,u]=n?[o.fromA,o.toA]:[o.fromB,o.toB];if(l>e)s=i;else if(u<=e)a=i+1;else return r?[o.fromA,o.fromB]:[o.toA,o.toB]}}function PC(t,e,n,r){let a=[];return e.iterChangedRanges((s,i,o,l)=>{let u=0,c=n?e.length:r,d=0,f=n?r:e.length;s>gf&&([u,d]=AC(t,s-gf,n,!0)),i<e.length-gf&&([c,f]=AC(t,i+gf,n,!1));let h=l-o-(i-s),p,[g,m]=n?[h,0]:[0,h];a.length&&(p=a[a.length-1]).toA>=u?a[a.length-1]={fromA:p.fromA,fromB:p.fromB,toA:c,toB:f,diffA:p.diffA+g,diffB:p.diffB+m}:a.push({fromA:u,toA:c,fromB:d,toB:f,diffA:g,diffB:m})}),a}function RC(t,e,n,r,a){if(!t.length)return e;let s=[];for(let i=0,o=0,l=0,u=0;;i++){let c=i==t.length?null:t[i],d=c?c.fromA+o:n.length,f=c?c.fromB+l:r.length;for(;u<e.length;){let m=e[u];if(c&&(m.toA+o>d||m.toB+l>f))break;s.push(m.offset(o,l)),u++}if(!c)break;let h=c.toA+o+c.diffA,p=c.toB+l+c.diffB,g=XC(n.sliceString(d,h),r.sliceString(f,p),a);for(let m of JC(g,n,r,d,f,KC()))s.push(m);for(o+=c.diffA,l+=c.diffB;u<e.length;){let m=e[u];if(m.fromA+o>h&&m.fromB+l>p)break;u++}}return s}var ZC={scanLimit:500},Cf=Nr.fromClass(class{constructor(t){({deco:this.deco,gutter:this.gutter}=TC(t))}update(t){(t.docChanged||t.viewportChanged||xF(t.startState,t.state)||bF(t.startState,t.state))&&({deco:this.deco,gutter:this.gutter}=TC(t.view))}},{decorations:t=>t.deco}),xf=Wa.low(al({class:"cm-changeGutter",markers:t=>{var e;return((e=t.plugin(Cf))===null||e===void 0?void 0:e.gutter)||Pt.empty}}));function xF(t,e){return t.field(br,!1)!=e.field(br,!1)}function bF(t,e){return t.facet(Mr)!=e.facet(Mr)}var NC=Ze.line({class:"cm-changedLine"}),QC=Ze.mark({class:"cm-changedText"}),yF=Ze.mark({tagName:"ins",class:"cm-insertedLine"}),vF=Ze.mark({tagName:"del",class:"cm-deletedLine"}),MC=new class extends Yn{constructor(){super(...arguments),this.elementClass="cm-changedLineGutter"}};function wF(t,e,n,r,a,s){let i=n?t.fromA:t.fromB,o=n?t.toA:t.toB,l=0;if(i!=o){a.add(i,i,NC),a.add(i,o,n?vF:yF),s&&s.add(i,i,MC);for(let u=e.iterRange(i,o-1),c=i;!u.next().done;){if(u.lineBreak){c++,a.add(c,c,NC),s&&s.add(c,c,MC);continue}let d=c+u.value.length;if(r)for(;l<t.changes.length;){let f=t.changes[l],h=i+(n?f.fromA:f.fromB),p=i+(n?f.toA:f.toB),g=Math.max(c,h),m=Math.min(d,p);if(g<m&&a.add(g,m,QC),p<d)l++;else break}c=d}}}function TC(t){let e=t.state.field(br),{side:n,highlightChanges:r,markGutter:a,overrideChunk:s}=t.state.facet(Mr),i=n=="a",o=new ir,l=a?new ir:null,{from:u,to:c}=t.viewport;for(let d of e){if((i?d.fromA:d.fromB)>=c)break;(i?d.toA:d.toB)>u&&(!s||!s(t.state,d,o,l))&&wF(d,t.state.doc,i,r,o,l)}return{deco:o.finish(),gutter:l&&l.finish()}}var sl=class extends zr{constructor(e){super(),this.height=e}eq(e){return this.height==e.height}toDOM(){let e=document.createElement("div");return e.className="cm-mergeSpacer",e.style.height=this.height+"px",e}updateDOM(e){return e.style.height=this.height+"px",!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}},wf=Ct.define({map:(t,e)=>t.map(e)}),rc=En.define({create:()=>Ze.none,update:(t,e)=>{for(let n of e.effects)if(n.is(wf))return n.value;return t.map(e.changes)},provide:t=>Ne.decorations.from(t)}),bf=.01;function DC(t,e){if(t.size!=e.size)return!1;let n=t.iter(),r=e.iter();for(;n.value;){if(n.from!=r.from||Math.abs(n.value.spec.widget.height-r.value.spec.widget.height)>1)return!1;n.next(),r.next()}return!0}function kF(t,e,n){let r=new ir,a=new ir,s=t.state.field(rc).iter(),i=e.state.field(rc).iter(),o=0,l=0,u=0,c=0,d=t.viewport,f=e.viewport;for(let m=0;;m++){let x=m<n.length?n[m]:null,b=x?x.fromA:t.state.doc.length,y=x?x.fromB:e.state.doc.length;if(o<b){let C=t.lineBlockAt(o).top+u,I=e.lineBlockAt(l).top+c,L=C-I;L<-bf?(u-=L,r.add(o,o,Ze.widget({widget:new sl(-L),block:!0,side:-1}))):L>bf&&(c+=L,a.add(l,l,Ze.widget({widget:new sl(L),block:!0,side:-1})))}if(b>o+1e3&&o<d.from&&b>d.from&&l<f.from&&y>f.from){let C=Math.min(d.from-o,f.from-l);o+=C,l+=C,m--}else if(x)o=x.toA,l=x.toB;else break;for(;s.value&&s.from<o;)u-=s.value.spec.widget.height,s.next();for(;i.value&&i.from<l;)c-=i.value.spec.widget.height,i.next()}for(;s.value;)u-=s.value.spec.widget.height,s.next();for(;i.value;)c-=i.value.spec.widget.height,i.next();let h=t.contentHeight+u-(e.contentHeight+c);h<bf?r.add(t.state.doc.length,t.state.doc.length,Ze.widget({widget:new sl(-h),block:!0,side:1})):h>bf&&a.add(e.state.doc.length,e.state.doc.length,Ze.widget({widget:new sl(h),block:!0,side:1}));let p=r.finish(),g=a.finish();DC(p,t.state.field(rc))||t.dispatch({effects:wf.of(p)}),DC(g,e.state.field(rc))||e.dispatch({effects:wf.of(g)})}var Pg=Ct.define({map:(t,e)=>e.mapPos(t)});var Rg=class extends zr{constructor(e){super(),this.lines=e}eq(e){return this.lines==e.lines}toDOM(e){let n=document.createElement("div");return n.className="cm-collapsedLines",n.textContent=e.state.phrase("$ unchanged lines",this.lines),n.addEventListener("click",r=>{let a=e.posAtDOM(r.target);e.dispatch({effects:Pg.of(a)});let{side:s,sibling:i}=e.state.facet(Mr);i&&i().dispatch({effects:Pg.of(SF(a,e.state.field(br),s=="a"))})}),n}ignoreEvent(e){return e instanceof MouseEvent}get estimatedHeight(){return 27}get type(){return"collapsed-unchanged-code"}};function SF(t,e,n){let r=0,a=0;for(let s=0;;s++){let i=s<e.length?e[s]:null;if(!i||(n?i.fromA:i.fromB)>=t)return a+(t-r);[r,a]=n?[i.toA,i.toB]:[i.toB,i.toA]}}var CF=En.define({create(t){return Ze.none},update(t,e){t=t.map(e.changes);for(let n of e.effects)n.is(Pg)&&(t=t.update({filter:r=>r!=n.value}));if(t.size&&e.state.field(br)!=e.startState.field(br,!1)){let n=e.state.facet(Mr).side=="a",r=[];for(let a of e.state.field(br))t.between(n?a.fromA:a.fromB,n?a.toA:a.toB,s=>{r.push(s)});r.length&&(t=t.update({filter:a=>r.indexOf(a)<0}))}return t},provide:t=>Ne.decorations.from(t)});function Ng({margin:t=3,minSize:e=4}){return CF.init(n=>IF(n,t,e))}function IF(t,e,n){let r=new ir,a=t.facet(Mr).side=="a",s=t.field(br),i=1;for(let o=0;;o++){let l=o<s.length?s[o]:null,u=o?i+e:1,c=l?t.doc.lineAt(a?l.fromA:l.fromB).number-1-e:t.doc.lines,d=c-u+1;if(d>=n&&r.add(t.doc.line(u).from,t.doc.line(c).to,Ze.replace({widget:new Rg(d),block:!0})),!l)break;i=t.doc.lineAt(Math.min(t.doc.length,a?l.toA:l.toB)).number}return r.finish()}var LF=Ne.styleModule.of(new Pr({".cm-mergeView":{overflowY:"auto"},".cm-mergeViewEditors":{display:"flex",alignItems:"stretch"},".cm-mergeViewEditor":{flexGrow:1,flexBasis:0,overflow:"hidden"},".cm-merge-revert":{width:"1.6em",flexGrow:0,flexShrink:0,position:"relative"},".cm-merge-revert button":{position:"absolute",display:"block",width:"100%",boxSizing:"border-box",textAlign:"center",background:"none",border:"none",font:"inherit",cursor:"pointer"}})),eI=Ne.baseTheme({".cm-mergeView & .cm-scroller, .cm-mergeView &":{height:"auto !important",overflowY:"visible !important"},"&.cm-merge-a .cm-changedLine, .cm-deletedChunk":{backgroundColor:"rgba(160, 128, 100, .08)"},"&.cm-merge-b .cm-changedLine, .cm-inlineChangedLine":{backgroundColor:"rgba(100, 160, 128, .08)"},"&light.cm-merge-a .cm-changedText, &light .cm-deletedChunk .cm-deletedText":{background:"linear-gradient(#ee443366, #ee443366) bottom/100% 2px no-repeat"},"&dark.cm-merge-a .cm-changedText, &dark .cm-deletedChunk .cm-deletedText":{background:"linear-gradient(#ffaa9966, #ffaa9966) bottom/100% 2px no-repeat"},"&light.cm-merge-b .cm-changedText":{background:"linear-gradient(#22bb22aa, #22bb22aa) bottom/100% 2px no-repeat"},"&dark.cm-merge-b .cm-changedText":{background:"linear-gradient(#88ff88aa, #88ff88aa) bottom/100% 2px no-repeat"},"&.cm-merge-b .cm-deletedText":{background:"#ff000033"},".cm-insertedLine, .cm-deletedLine, .cm-deletedLine del":{textDecoration:"none"},".cm-deletedChunk":{paddingLeft:"6px","& .cm-chunkButtons":{position:"absolute",insetInlineEnd:"5px"},"& button":{border:"none",cursor:"pointer",color:"white",margin:"0 2px",borderRadius:"3px","&[name=accept]":{background:"#2a2"},"&[name=reject]":{background:"#d43"}}},".cm-collapsedLines":{padding:"5px 5px 5px 10px",cursor:"pointer","&:before":{content:'"\u299A"',marginInlineEnd:"7px"},"&:after":{content:'"\u299A"',marginInlineStart:"7px"}},"&light .cm-collapsedLines":{color:"#444",background:"linear-gradient(to bottom, transparent 0, #f3f3f3 30%, #f3f3f3 70%, transparent 100%)"},"&dark .cm-collapsedLines":{color:"#ddd",background:"linear-gradient(to bottom, transparent 0, #222 30%, #222 70%, transparent 100%)"},".cm-changeGutter":{width:"3px",paddingLeft:"1px"},"&light.cm-merge-a .cm-changedLineGutter, &light .cm-deletedLineGutter":{background:"#e43"},"&dark.cm-merge-a .cm-changedLineGutter, &dark .cm-deletedLineGutter":{background:"#fa9"},"&light.cm-merge-b .cm-changedLineGutter":{background:"#2b2"},"&dark.cm-merge-b .cm-changedLineGutter":{background:"#8f8"},".cm-inlineChangedLineGutter":{background:"#75d"}}),FC=new Qr,yf=new Qr,kf=class{constructor(e){this.revertDOM=null,this.revertToA=!1,this.revertToLeft=!1,this.measuring=-1,this.diffConf=e.diffConfig||ZC;let n=[Wa.low(Cf),eI,LF,rc,Ne.updateListener.of(d=>{this.measuring<0&&(d.heightChanged||d.viewportChanged)&&!d.transactions.some(f=>f.effects.some(h=>h.is(wf)))&&this.measure()})],r=[Mr.of({side:"a",sibling:()=>this.b,highlightChanges:e.highlightChanges!==!1,markGutter:e.gutter!==!1})];e.gutter!==!1&&r.push(xf);let a=Dt.create({doc:e.a.doc,selection:e.a.selection,extensions:[e.a.extensions||[],Ne.editorAttributes.of({class:"cm-merge-a"}),yf.of(r),n]}),s=[Mr.of({side:"b",sibling:()=>this.a,highlightChanges:e.highlightChanges!==!1,markGutter:e.gutter!==!1})];e.gutter!==!1&&s.push(xf);let i=Dt.create({doc:e.b.doc,selection:e.b.selection,extensions:[e.b.extensions||[],Ne.editorAttributes.of({class:"cm-merge-b"}),yf.of(s),n]});this.chunks=ks.build(a.doc,i.doc,this.diffConf);let o=[br.init(()=>this.chunks),FC.of(e.collapseUnchanged?Ng(e.collapseUnchanged):[])];a=a.update({effects:Ct.appendConfig.of(o)}).state,i=i.update({effects:Ct.appendConfig.of(o)}).state,this.dom=document.createElement("div"),this.dom.className="cm-mergeView",this.editorDOM=this.dom.appendChild(document.createElement("div")),this.editorDOM.className="cm-mergeViewEditors";let l=e.orientation||"a-b",u=document.createElement("div");u.className="cm-mergeViewEditor";let c=document.createElement("div");c.className="cm-mergeViewEditor",this.editorDOM.appendChild(l=="a-b"?u:c),this.editorDOM.appendChild(l=="a-b"?c:u),this.a=new Ne({state:a,parent:u,root:e.root,dispatchTransactions:d=>this.dispatch(d,this.a)}),this.b=new Ne({state:i,parent:c,root:e.root,dispatchTransactions:d=>this.dispatch(d,this.b)}),this.setupRevertControls(!!e.revertControls,e.revertControls=="b-to-a",e.renderRevertControl),e.parent&&e.parent.appendChild(this.dom),this.scheduleMeasure()}dispatch(e,n){if(e.some(r=>r.docChanged)){let r=e[e.length-1],a=e.reduce((i,o)=>i.compose(o.changes),zn.empty(e[0].startState.doc.length));this.chunks=n==this.a?ks.updateA(this.chunks,r.newDoc,this.b.state.doc,a,this.diffConf):ks.updateB(this.chunks,this.a.state.doc,r.newDoc,a,this.diffConf),n.update([...e,r.state.update({effects:Ag.of(this.chunks)})]);let s=n==this.a?this.b:this.a;s.update([s.state.update({effects:Ag.of(this.chunks)})]),this.scheduleMeasure()}else n.update(e)}reconfigure(e){if("diffConfig"in e&&(this.diffConf=e.diffConfig),"orientation"in e){let s=e.orientation!="b-a";if(s!=(this.editorDOM.firstChild==this.a.dom.parentNode)){let i=this.a.dom.parentNode,o=this.b.dom.parentNode;i.remove(),o.remove(),this.editorDOM.insertBefore(s?i:o,this.editorDOM.firstChild),this.editorDOM.appendChild(s?o:i),this.revertToLeft=!this.revertToLeft,this.revertDOM&&(this.revertDOM.textContent="")}}if("revertControls"in e||"renderRevertControl"in e){let s=!!this.revertDOM,i=this.revertToA,o=this.renderRevert;"revertControls"in e&&(s=!!e.revertControls,i=e.revertControls=="b-to-a"),"renderRevertControl"in e&&(o=e.renderRevertControl),this.setupRevertControls(s,i,o)}let n="highlightChanges"in e,r="gutter"in e,a="collapseUnchanged"in e;if(n||r||a){let s=[],i=[];if(n||r){let o=this.a.state.facet(Mr),l=r?e.gutter!==!1:o.markGutter,u=n?e.highlightChanges!==!1:o.highlightChanges;s.push(yf.reconfigure([Mr.of({side:"a",sibling:()=>this.b,highlightChanges:u,markGutter:l}),l?xf:[]])),i.push(yf.reconfigure([Mr.of({side:"b",sibling:()=>this.a,highlightChanges:u,markGutter:l}),l?xf:[]]))}if(a){let o=FC.reconfigure(e.collapseUnchanged?Ng(e.collapseUnchanged):[]);s.push(o),i.push(o)}this.a.dispatch({effects:s}),this.b.dispatch({effects:i})}this.scheduleMeasure()}setupRevertControls(e,n,r){this.revertToA=n,this.revertToLeft=this.revertToA==(this.editorDOM.firstChild==this.a.dom.parentNode),this.renderRevert=r,!e&&this.revertDOM?(this.revertDOM.remove(),this.revertDOM=null):e&&!this.revertDOM?(this.revertDOM=this.editorDOM.insertBefore(document.createElement("div"),this.editorDOM.firstChild.nextSibling),this.revertDOM.addEventListener("mousedown",a=>this.revertClicked(a)),this.revertDOM.className="cm-merge-revert"):this.revertDOM&&(this.revertDOM.textContent="")}scheduleMeasure(){if(this.measuring<0){let e=this.dom.ownerDocument.defaultView||window;this.measuring=e.requestAnimationFrame(()=>{this.measuring=-1,this.measure()})}}measure(){kF(this.a,this.b,this.chunks),this.revertDOM&&this.updateRevertButtons()}updateRevertButtons(){let e=this.revertDOM,n=e.firstChild,r=this.a.viewport,a=this.b.viewport;for(let s=0;s<this.chunks.length;s++){let i=this.chunks[s];if(i.fromA>r.to||i.fromB>a.to)break;if(i.fromA<r.from||i.fromB<a.from)continue;let o=this.a.lineBlockAt(i.fromA).top+"px";for(;n&&+n.dataset.chunk<s;)n=EC(n);n&&n.dataset.chunk==String(s)?(n.style.top!=o&&(n.style.top=o),n=n.nextSibling):e.insertBefore(this.renderRevertButton(o,s),n)}for(;n;)n=EC(n)}renderRevertButton(e,n){let r;if(this.renderRevert)r=this.renderRevert();else{r=document.createElement("button");let a=this.a.state.phrase("Revert this chunk");r.setAttribute("aria-label",a),r.setAttribute("title",a),r.textContent=this.revertToLeft?"\u21DC":"\u21DD"}return r.style.top=e,r.setAttribute("data-chunk",String(n)),r}revertClicked(e){let n=e.target,r;for(;n&&n.parentNode!=this.revertDOM;)n=n.parentNode;if(n&&(r=this.chunks[n.dataset.chunk])){let[a,s,i,o,l,u]=this.revertToA?[this.b,this.a,r.fromB,r.toB,r.fromA,r.toA]:[this.a,this.b,r.fromA,r.toA,r.fromB,r.toB],c=a.state.sliceDoc(i,Math.max(i,o-1));i!=o&&u<=s.state.doc.length&&(c+=a.state.lineBreak),s.dispatch({changes:{from:l,to:Math.min(s.state.doc.length,u),insert:c},userEvent:"revert"}),e.preventDefault()}}destroy(){this.a.destroy(),this.b.destroy(),this.measuring>-1&&(this.dom.ownerDocument.defaultView||window).cancelAnimationFrame(this.measuring),this.dom.remove()}};function EC(t){let e=t.nextSibling;return t.remove(),e}var AF=new class extends Yn{constructor(){super(...arguments),this.elementClass="cm-deletedLineGutter"}},PF=Wa.low(al({class:"cm-changeGutter",markers:t=>{var e;return((e=t.plugin(Cf))===null||e===void 0?void 0:e.gutter)||Pt.empty},widgetMarker:(t,e)=>e instanceof Sf?AF:null}));function tI(t){var e;let n=typeof t.original=="string"?mt.of(t.original.split(/\r?\n/)):t.original,r=t.diffConfig||ZC;return[Wa.low(Cf),TF,eI,Ne.editorAttributes.of({class:"cm-merge-b"}),YC.of((a,s)=>{let i=s.effects.find(o=>o.is(Eg));return i&&(a=ks.updateA(a,i.value.doc,s.startState.doc,i.value.changes,r)),s.docChanged&&(a=ks.updateB(a,s.state.field(ol),s.newDoc,s.changes,r)),a}),Mr.of({highlightChanges:t.highlightChanges!==!1,markGutter:t.gutter!==!1,syntaxHighlightDeletions:t.syntaxHighlightDeletions!==!1,syntaxHighlightDeletionsMaxLength:3e3,mergeControls:(e=t.mergeControls)!==null&&e!==void 0?e:!0,overrideChunk:t.allowInlineDiffs?EF:void 0,side:"b"}),ol.init(()=>n),t.gutter!==!1?PF:[],t.collapseUnchanged?Ng(t.collapseUnchanged):[],br.init(a=>ks.build(n,a.doc,r))]}var Eg=Ct.define();var ol=En.define({create:()=>mt.empty,update(t,e){for(let n of e.effects)n.is(Eg)&&(t=n.value.doc);return t}});var OC=new WeakMap,Sf=class extends zr{constructor(e){super(),this.buildDOM=e,this.dom=null}eq(e){return this.dom==e.dom}toDOM(e){return this.dom||(this.dom=this.buildDOM(e))}};function RF(t,e,n){let r=OC.get(e.changes);if(r)return r;let a=i=>{let{highlightChanges:o,syntaxHighlightDeletions:l,syntaxHighlightDeletionsMaxLength:u,mergeControls:c}=t.facet(Mr),d=document.createElement("div");if(d.className="cm-deletedChunk",c){let C=d.appendChild(document.createElement("div"));C.className="cm-chunkButtons";let I=v=>{v.preventDefault(),NF(i,i.posAtDOM(d))},L=v=>{v.preventDefault(),MF(i,i.posAtDOM(d))};if(typeof c=="function")C.appendChild(c("accept",I)),C.appendChild(c("reject",L));else{let v=C.appendChild(document.createElement("button"));v.name="accept",v.textContent=t.phrase("Accept"),v.onmousedown=I;let k=C.appendChild(document.createElement("button"));k.name="reject",k.textContent=t.phrase("Reject"),k.onmousedown=L}}if(n||e.fromA>=e.toA)return d;let f=i.state.field(ol).sliceString(e.fromA,e.endA),h=l&&t.facet(oi),p=b(),g=e.changes,m=0,x=!1;function b(){let C=d.appendChild(document.createElement("div"));return C.className="cm-deletedLine",C.appendChild(document.createElement("del"))}function y(C,I,L){for(let v=C;v<I;){if(f.charAt(v)==`
|
|
42
|
+
`){p.firstChild||p.appendChild(document.createElement("br")),p=b(),v++;continue}let k=I,O=L+(x?" cm-deletedText":""),R=!1,P=f.indexOf(`
|
|
43
|
+
`,v);if(P>-1&&P<I&&(k=P),o&&m<g.length){let H=Math.max(0,x?g[m].toA:g[m].fromA);H<=k&&(k=H,x&&m++,R=!0)}if(k>v){let H=document.createTextNode(f.slice(v,k));if(O){let w=p.appendChild(document.createElement("span"));w.className=O,w.appendChild(H)}else p.appendChild(H);v=k}R&&(x=!x)}}if(h&&e.toA-e.fromA<=u){let C=h.parser.parse(f),I=0;hg(C,{style:L=>yC(t,L)},(L,v,k)=>{L>I&&y(I,L,""),y(L,v,k),I=v}),y(I,f.length,"")}else y(0,f.length,"");return p.firstChild||p.appendChild(document.createElement("br")),d},s=Ze.widget({block:!0,side:-1,widget:new Sf(a)});return OC.set(e.changes,s),s}function NF(t,e){let{state:n}=t,r=e??n.selection.main.head,a=t.state.field(br).find(l=>l.fromB<=r&&l.endB>=r);if(!a)return!1;let s=t.state.sliceDoc(a.fromB,Math.max(a.fromB,a.toB-1)),i=t.state.field(ol);a.fromB!=a.toB&&a.toA<=i.length&&(s+=t.state.lineBreak);let o=zn.of({from:a.fromA,to:Math.min(i.length,a.toA),insert:s},i.length);return t.dispatch({effects:Eg.of({doc:o.apply(i),changes:o}),userEvent:"accept"}),!0}function MF(t,e){let{state:n}=t,r=e??n.selection.main.head,a=n.field(br).find(o=>o.fromB<=r&&o.endB>=r);if(!a)return!1;let i=n.field(ol).sliceString(a.fromA,Math.max(a.fromA,a.toA-1));return a.fromA!=a.toA&&a.toB<=n.doc.length&&(i+=n.lineBreak),t.dispatch({changes:{from:a.fromB,to:Math.min(n.doc.length,a.toB),insert:i},userEvent:"revert"}),!0}function BC(t){let e=new ir;for(let n of t.field(br)){let r=t.facet(Mr).overrideChunk&&nI(t,n);e.add(n.fromB,n.fromB,RF(t,n,!!r))}return e.finish()}var TF=En.define({create:t=>BC(t),update(t,e){return e.state.field(br,!1)!=e.startState.field(br,!1)?BC(e.state):t},provide:t=>Ne.decorations.from(t)}),_C=new WeakMap;function nI(t,e){let n=_C.get(e);if(n!==void 0)return n;n=null;let r=t.field(ol),a=t.doc,s=r.lineAt(e.endA).number-r.lineAt(e.fromA).number+1,i=a.lineAt(e.endB).number-a.lineAt(e.fromB).number+1;e:if(s==i&&s<10){let o=[],l=0,u=e.fromA,c=e.fromB;for(let d of e.changes){if(d.fromA<d.toA){l+=d.toA-d.fromA;let f=r.sliceString(u+d.fromA,u+d.toA);if(/\n/.test(f))break e;o.push(Ze.widget({widget:new Mg(f),side:-1}).range(c+d.fromB))}d.fromB<d.toB&&o.push(QC.range(c+d.fromB,c+d.toB))}l<e.endA-e.fromA-s*2&&(n=o)}return _C.set(e,n),n}var Mg=class extends zr{constructor(e){super(),this.text=e}eq(e){return this.text==e.text}toDOM(e){let n=document.createElement("del");return n.className="cm-deletedText",n.textContent=this.text,n}},DF=new class extends Yn{constructor(){super(...arguments),this.elementClass="cm-inlineChangedLineGutter"}},FF=Ze.line({class:"cm-inlineChangedLine"});function EF(t,e,n,r){let a=nI(t,e),s=0;if(!a)return!1;for(let i=t.doc.lineAt(e.fromB);;){for(r&&r.add(i.from,i.from,DF),n.add(i.from,i.from,FF);s<a.length&&a[s].to<=i.to;){let o=a[s++];n.add(o.from,o.to,o.value)}if(i.to>=e.endB)break;i=t.doc.lineAt(i.to+1)}return!0}function rI(t,e){if(!t||!e)return!1;let n=t.getInternalStack(),r=e.getInternalStack();return!n||!r?!1:n.equals(r)}function OF(t,e){return{from:t,to:e,lines:null,startState:null,endState:null,final:!1,stateKnown:!1,lastUsed:0}}var If=class{constructor(e,n,r,a,s=64,i=4096){this.hl=e;this.lang=n;this.theme=r;this.targetLines=s;this.targetChars=i;this.chunks=[];this.tick=0;this.warned=!1;this.layoutDirty=!0;this.layout(a)}pieces(e,n,r){let a=[],s=n;for(;s<=r;){let i=e.line(s),o=i,l=1,u=i.length;for(;s+l<=r&&l<this.targetLines;){let c=e.line(s+l);if(u+1+c.length>this.targetChars)break;o=c,u+=1+c.length,l+=1}a.push(OF(i.from,o.to)),s+=l}return a}layout(e){this.chunks.length=0,this.chunks.push(...this.pieces(e,1,e.lines))}chunkIndexAt(e){let n=0,r=this.chunks.length-1;for(;n<r;){let a=n+r+1>>1;this.chunks[a].from<=e?n=a:r=a-1}return n}firstLineOf(e,n){return e.lineAt(n.from).number}tokensAt(e,n){return e.lines?.[n]??null}tokensForLine(e,n){let r=e.line(n),a=this.chunks[this.chunkIndexAt(r.from)];return{chunk:a,tokens:this.tokensAt(a,n-this.firstLineOf(e,a))}}lineCountOf(e,n){return e.lineAt(n.to).number-e.lineAt(n.from).number+1}hasPendingWork(e,n){let r=this.firstNonFinal(0);return r>=0&&r<=n||this.rebalanceTarget(e)!==null}firstNonFinal(e){for(let n=Math.max(0,e);n<this.chunks.length;n++)if(!this.chunks[n].final)return n;return-1}tokenize(e,n,r=!0){let a=this.chunks[n],s=n>0?this.chunks[n-1]:null,i=s?.endState??null,o=n===0||!!(s&&s.final&&s.stateKnown),l=e.sliceString(a.from,a.to),u=a.endState,c,d;try{let f=this.hl.codeToTokensBase(l,{lang:this.lang,theme:this.theme,includeExplanation:!1,tokenizeMaxLineLength:2e4,...i?{grammarState:i}:{}});d=this.hl.getLastGrammarState(f)??null,c=f}catch(f){this.warned||(this.warned=!0,console.warn("[Filesystem] shiki chunk tokenization failed",this.lang,f)),c=[],d=null}return a.lines=c,a.startState=i,a.endState=d,a.final=o,a.stateKnown=!0,r&&(a.lastUsed=++this.tick),this.trimWindow(),o&&rI(u,d)}ensureRange(e,n,r,a=16384){let s=!1,i=0,o=this.chunkIndexAt(n),l=Math.min(this.chunks.length-1,this.chunkIndexAt(r)+1);for(let u=o;u<=l;u++){let c=this.chunks[u];if(c.lines){c.lastUsed=++this.tick;continue}if(s&&i+(c.to-c.from)>a)break;this.tokenize(e,u,!0),i+=c.to-c.from,s=!0}return s}idleStep(e,n,r,a=()=>performance.now()){let s=a(),i=null,o=u=>{i=i?{from:Math.min(i.from,u.from),to:Math.max(i.to,u.to)}:{from:u.from,to:u.to}};this.rebalanceOnce(e);let l=this.firstNonFinal(0);for(;l>=0&&l<this.chunks.length&&l<=r;){let u=this.tokenize(e,l,!1);if(o(this.chunks[l]),u){let c=l+1;for(;c<this.chunks.length;c++){let d=this.chunks[c];if(!d.final)if(d.startState&&rI(d.startState,this.chunks[c-1].endState))d.final=!0;else break}l=this.firstNonFinal(c)}else{if(l+1<this.chunks.length&&(this.chunks[l+1].final=!1),l>=r)for(let c=l+2;c<this.chunks.length;c++)this.chunks[c].final=!1;l+=1}if(a()-s>=n)break}return{more:this.hasPendingWork(e,r),touched:i}}applyChanges(e,n){let r=new Set;if(e.iterChangedRanges((o,l)=>{let u=this.chunkIndexAt(o);for(;u<this.chunks.length&&this.chunks[u].from<=l;)r.add(this.chunks[u]),u++}),n.length===0){this.layout(n);return}let a=[],s=0;for(let o=0;o<this.chunks.length;o++){let l=this.chunks[o],u=e.mapPos(l.to,1);if(u>n.length&&(u=n.length),u=n.lineAt(u).to,u<s){let c=a[a.length-1];c&&r.add(c);continue}l.from=s,l.to=u,a.push(l),s=u+1}let i=a[a.length-1];i&&i.to<n.length&&(i.to=n.length,r.add(i));for(let o of r)o.lines=null,o.startState=null,o.final=!1,o.stateKnown=!1;this.chunks.length=0,this.chunks.push(...a),this.layoutDirty=!0,this.splitOversized(n,r)}splitOversized(e,n){for(let r=0;r<this.chunks.length;r++){let a=this.chunks[r];if(!n.has(a))continue;let s=e.lineAt(a.from).number,i=e.lineAt(a.to).number;if(i-s+1<=this.targetLines*2&&a.to-a.from<=this.targetChars*2)continue;let l=this.pieces(e,s,i);if(l.length<2)continue;let u=l[l.length-1];u.endState=a.endState,this.chunks.splice(r,1,...l),r+=l.length-1}}rebalanceTarget(e){if(!this.layoutDirty)return null;let n=this.targetLines;for(let r=0;r+1<this.chunks.length;r++){let a=this.chunks[r],s=this.chunks[r+1],i=this.lineCountOf(e,a),o=a.to-a.from;if(!(i>=n/2||o>=this.targetChars/2)&&!(i+this.lineCountOf(e,s)>n*2)&&!(s.to-a.from>this.targetChars*2))return r}return this.layoutDirty=!1,null}rebalanceOnce(e){let n=this.rebalanceTarget(e);if(n===null)return!1;let r=this.chunks[n],a=this.chunks[n+1];return r.to=a.to,r.endState=a.endState,r.lines=null,r.startState=null,r.final=!1,r.stateKnown=!1,this.chunks.splice(n+1,1),this.layoutDirty=!0,!0}trimWindow(){let e=this.chunks.filter(n=>n.lines);if(!(e.length<=32)){e.sort((n,r)=>n.lastUsed-r.lastUsed);for(let n=0;n<e.length-32;n++)e[n].lines=null}}};var li=Ee.define({combine:t=>t.length?t[t.length-1]:{theme:"dark-plus"}}),iI=Ct.define(),HF=8;function aI(t){setTimeout(()=>{try{t.dispatch({effects:iI.of(null)})}catch{}},0)}function UF(t){let e=globalThis;if(typeof e.requestIdleCallback=="function"){let r=e.requestIdleCallback(t,{timeout:250});return{cancel:()=>e.cancelIdleCallback?.(r)}}let n=setTimeout(t,0);return{cancel:()=>clearTimeout(n)}}var sI=new Map;function GF(t){let e=sI.get(t);return e||(e=Ze.mark({attributes:{style:`color:${t}`}}),sI.set(t,e)),e}var Og=class{constructor(e){this.decorations=Ze.none;this.engine=null;this.engineKey="";this.idle=null;this.disposed=!1;this.loadKicked=null;this.horizon=0;this.decorations=this.build(e)}update(e){e.docChanged&&this.engine&&this.engine.applyChanges(e.changes,e.state.doc);let n=e.startState.facet(li),r=e.state.facet(li),a=n.lang!==r.lang||n.theme!==r.theme,s=e.transactions.some(i=>i.effects.some(o=>o.is(iI)));(e.docChanged||e.viewportChanged||a||s)&&(this.decorations=this.build(e.view))}destroy(){this.disposed=!0,this.idle?.cancel(),this.idle=null,this.engine=null}build(e){let n=e.state.facet(li),r=_o(n.lang);if(!r)return this.engine=null,Ze.none;let a=e.state.doc;if(a.length>2e6)return this.engine=null,Ze.none;let s=f1(r);if(!s)return this.loadKicked!==r&&(this.loadKicked=r,bu().then(()=>hd(r)).then(c=>{c&&!this.disposed&&aI(e)})),Ze.none;let i=`${r} ${n.theme}`;(!this.engine||this.engineKey!==i)&&(this.engine=new If(s,r,n.theme,a),this.engineKey=i);let o=this.engine,l=new ir,u=0;for(let{from:c,to:d}of e.visibleRanges){o.ensureRange(a,c,d);let f=a.lineAt(c).number,h=a.lineAt(d).number,p=o.chunkIndexAt(d);u=Math.max(u,p+4);for(let g=o.chunkIndexAt(c);g<=p;g++){let m=o.chunks[g],x=o.firstLineOf(a,m),b=a.lineAt(m.to).number;for(let y=Math.max(f,x);y<=Math.min(h,b);y++){let C=o.tokensAt(m,y-x);if(!C)continue;let I=a.line(y);for(let L of C){if(!L.content||!L.color)continue;let v=m.from+L.offset,k=v+L.content.length;v<I.from||v>=k||k>I.to||l.add(v,k,GF(L.color))}}}}return this.horizon=u,o.hasPendingWork(a,u)&&this.scheduleIdle(e),l.finish()}scheduleIdle(e){this.idle||this.disposed||(this.idle=UF(()=>{if(this.idle=null,this.disposed||!this.engine)return;let n=this.engine.idleStep(e.state.doc,HF,this.horizon),r=n.touched;!!r&&e.visibleRanges.some(s=>r.from<=s.to&&r.to>=s.from)?aI(e):n.more&&this.scheduleIdle(e)}))}},Lf=Nr.fromClass(Og,{decorations:t=>t.decorations});var Af=Ne.theme({"&":{backgroundColor:"transparent",color:"#d4d4d4",height:"100%"},"&.cm-focused":{outline:"none"},".cm-scroller":{fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:"18px"},".cm-content":{padding:"6px 0",caretColor:"#e5e7eb"},".cm-gutters":{backgroundColor:"transparent",border:"none",color:"rgba(255,255,255,0.25)"},".cm-lineNumbers .cm-gutterElement":{padding:"0 10px 0 12px",minWidth:"2ch"},".cm-activeLine":{backgroundColor:"rgba(255,255,255,0.035)"},".cm-activeLineGutter":{backgroundColor:"transparent",color:"rgba(255,255,255,0.5)"},".cm-cursor, .cm-dropCursor":{borderLeftColor:"#e5e7eb"},".cm-selectionBackground, .cm-content ::selection":{backgroundColor:"rgba(96,130,255,0.28)"},"&.cm-focused .cm-selectionBackground":{backgroundColor:"rgba(96,130,255,0.34)"},".cm-placeholder":{color:"rgba(255,255,255,0.22)"}},{dark:!0}),oI=Ne.theme({".cm-changedLine":{backgroundColor:"rgba(16,185,129,0.10)"},".cm-changedText":{background:"rgba(16,185,129,0.24)"},".cm-insertedLine":{backgroundColor:"rgba(16,185,129,0.12)"},".cm-deletedChunk":{backgroundColor:"rgba(244,63,94,0.10)"},".cm-deletedChunk .cm-deletedText, .cm-deletedText":{background:"rgba(244,63,94,0.30)"},".cm-changeGutter":{width:"3px"},".cm-changedLineGutter":{backgroundColor:"rgba(16,185,129,0.45)"},".cm-deletedLineGutter":{backgroundColor:"rgba(244,63,94,0.45)"},".cm-merge-a, .cm-merge-b":{backgroundColor:"transparent"},".cm-mergeSpacer":{backgroundColor:"rgba(255,255,255,0.02)"},".cm-merge-revert":{display:"none"}});var lI=W(ue(),1);function Bg(t,e){return[sf(),Dt.readOnly.of(!0),Ne.editable.of(!1),Af,oI,li.of({lang:t,theme:e}),Lf]}function _g({oldContent:t,newContent:e,language:n,viewMode:r="unified",className:a,theme:s="dark-plus"}){let i=(0,Pf.useRef)(null);return(0,Pf.useEffect)(()=>{let o=i.current;if(!o)return;let l;if(r==="split"){let u=new kf({a:{doc:t,extensions:Bg(n,s)},b:{doc:e,extensions:Bg(n,s)},parent:o,gutter:!0,highlightChanges:!0,revertControls:void 0});l=()=>u.destroy()}else{let u=Dt.create({doc:e,extensions:[...Bg(n,s),tI({original:t,mergeControls:!1,gutter:!0,highlightChanges:!0,syntaxHighlightDeletions:!1})]}),c=new Ne({state:u,parent:o});l=()=>c.destroy()}return l},[t,e,n,r,s]),(0,lI.jsx)("div",{ref:i,className:a})}var lr=W(Je(),1);var zF=t=>{let{state:e}=t,n=e.doc.lineAt(e.selection.main.from),r=qg(t.state,n.from);return r.line?WF(t):r.block?qF(t):!1};function jg(t,e){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let a=t(e,n);return a?(r(n.update(a)),!0):!1}}var WF=jg(KF,0);var jF=jg(xI,0);var qF=jg((t,e)=>xI(t,e,$F(e)),0);function qg(t,e){let n=t.languageDataAt("commentTokens",e,1);return n.length?n[0]:{}}var ac=50;function VF(t,{open:e,close:n},r,a){let s=t.sliceDoc(r-ac,r),i=t.sliceDoc(a,a+ac),o=/\s*$/.exec(s)[0].length,l=/^\s*/.exec(i)[0].length,u=s.length-o;if(s.slice(u-e.length,u)==e&&i.slice(l,l+n.length)==n)return{open:{pos:r-o,margin:o&&1},close:{pos:a+l,margin:l&&1}};let c,d;a-r<=2*ac?c=d=t.sliceDoc(r,a):(c=t.sliceDoc(r,r+ac),d=t.sliceDoc(a-ac,a));let f=/^\s*/.exec(c)[0].length,h=/\s*$/.exec(d)[0].length,p=d.length-h-n.length;return c.slice(f,f+e.length)==e&&d.slice(p,p+n.length)==n?{open:{pos:r+f+e.length,margin:/\s/.test(c.charAt(f+e.length))?1:0},close:{pos:a-h-n.length,margin:/\s/.test(d.charAt(p-1))?1:0}}:null}function $F(t){let e=[];for(let n of t.selection.ranges){let r=t.doc.lineAt(n.from),a=n.to<=r.to?r:t.doc.lineAt(n.to);a.from>r.from&&a.from==n.to&&(a=n.to==r.to+1?r:t.doc.lineAt(n.to-1));let s=e.length-1;s>=0&&e[s].to>r.from?e[s].to=a.to:e.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:a.to})}return e}function xI(t,e,n=e.selection.ranges){let r=n.map(s=>qg(e,s.from).block);if(!r.every(s=>s))return null;let a=n.map((s,i)=>VF(e,r[i],s.from,s.to));if(t!=2&&!a.every(s=>s))return{changes:e.changes(n.map((s,i)=>a[i]?[]:[{from:s.from,insert:r[i].open+" "},{from:s.to,insert:" "+r[i].close}]))};if(t!=1&&a.some(s=>s)){let s=[];for(let i=0,o;i<a.length;i++)if(o=a[i]){let l=r[i],{open:u,close:c}=o;s.push({from:u.pos-l.open.length,to:u.pos+u.margin},{from:c.pos-c.margin,to:c.pos+l.close.length})}return{changes:s}}return null}function KF(t,e,n=e.selection.ranges){let r=[],a=-1;e:for(let{from:s,to:i}of n){let o=r.length,l=1e9,u;for(let c=s;c<=i;){let d=e.doc.lineAt(c);if(u==null&&(u=qg(e,d.from).line,!u))continue e;if(d.from>a&&(s==i||i>d.from)){a=d.from;let f=/^\s*/.exec(d.text)[0].length,h=f==d.length,p=d.text.slice(f,f+u.length)==u?f:-1;f<d.text.length&&f<l&&(l=f),r.push({line:d,comment:p,token:u,indent:f,empty:h,single:!1})}c=d.to+1}if(l<1e9)for(let c=o;c<r.length;c++)r[c].indent<r[c].line.text.length&&(r[c].indent=l);r.length==o+1&&(r[o].single=!0)}if(t!=2&&r.some(s=>s.comment<0&&(!s.empty||s.single))){let s=[];for(let{line:o,token:l,indent:u,empty:c,single:d}of r)(d||!c)&&s.push({from:o.from+u,insert:l+" "});let i=e.changes(s);return{changes:i,selection:e.selection.map(i,1)}}else if(t!=1&&r.some(s=>s.comment>=0)){let s=[];for(let{line:i,comment:o,token:l}of r)if(o>=0){let u=i.from+o,c=u+l.length;i.text[c-i.from]==" "&&c++,s.push({from:u,to:c})}return{changes:s}}return null}var Ug=ea.define(),XF=ea.define(),YF=Ee.define(),bI=Ee.define({combine(t){return jo(t,{minDepth:100,newGroupDelay:500,joinToEvent:(e,n)=>n},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,n)=>(r,a)=>e(r,a)||n(r,a)})}}),yI=En.define({create(){return to.empty},update(t,e){let n=e.state.facet(bI),r=e.annotation(Ug);if(r){let l=Ia.fromTransaction(e,r.selection),u=r.side,c=u==0?t.undone:t.done;return l?c=Nf(c,c.length,n.minDepth,l):c=SI(c,e.startState.selection),new to(u==0?r.rest:c,u==0?c:r.rest)}let a=e.annotation(XF);if((a=="full"||a=="before")&&(t=t.isolate()),e.annotation(Un.addToHistory)===!1)return e.changes.empty?t:t.addMapping(e.changes.desc);let s=Ia.fromTransaction(e),i=e.annotation(Un.time),o=e.annotation(Un.userEvent);return s?t=t.addChanges(s,i,o,n,e):e.selection&&(t=t.addSelection(e.startState.selection,i,o,n.newGroupDelay)),(a=="full"||a=="after")&&(t=t.isolate()),t},toJSON(t){return{done:t.done.map(e=>e.toJSON()),undone:t.undone.map(e=>e.toJSON())}},fromJSON(t){return new to(t.done.map(Ia.fromJSON),t.undone.map(Ia.fromJSON))}});function vI(t={}){return[yI,bI.of(t),Ne.domEventHandlers({beforeinput(e,n){let r=e.inputType=="historyUndo"?wI:e.inputType=="historyRedo"?Gg:null;return r?(e.preventDefault(),r(n)):!1}})]}function Mf(t,e){return function({state:n,dispatch:r}){if(!e&&n.readOnly)return!1;let a=n.field(yI,!1);if(!a)return!1;let s=a.pop(t,n,e);return s?(r(s),!0):!1}}var wI=Mf(0,!1),Gg=Mf(1,!1),JF=Mf(0,!0),ZF=Mf(1,!0);var Ia=class t{constructor(e,n,r,a,s){this.changes=e,this.effects=n,this.mapped=r,this.startSelection=a,this.selectionsAfter=s}setSelAfter(e){return new t(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,n,r;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(n=this.mapped)===null||n===void 0?void 0:n.toJSON(),startSelection:(r=this.startSelection)===null||r===void 0?void 0:r.toJSON(),selectionsAfter:this.selectionsAfter.map(a=>a.toJSON())}}static fromJSON(e){return new t(e.changes&&zn.fromJSON(e.changes),[],e.mapped&&gs.fromJSON(e.mapped),e.startSelection&&oe.fromJSON(e.startSelection),e.selectionsAfter.map(oe.fromJSON))}static fromTransaction(e,n){let r=sa;for(let a of e.startState.facet(YF)){let s=a(e);s.length&&(r=r.concat(s))}return!r.length&&e.changes.empty?null:new t(e.changes.invert(e.startState.doc),r,void 0,n||e.startState.selection,sa)}static selection(e){return new t(void 0,sa,void 0,void 0,e)}};function Nf(t,e,n,r){let a=e+1>n+20?e-n-1:0,s=t.slice(a,e);return s.push(r),s}function QF(t,e){let n=[],r=!1;return t.iterChangedRanges((a,s)=>n.push(a,s)),e.iterChangedRanges((a,s,i,o)=>{for(let l=0;l<n.length;){let u=n[l++],c=n[l++];o>=u&&i<=c&&(r=!0)}}),r}function e5(t,e){return t.ranges.length==e.ranges.length&&t.ranges.filter((n,r)=>n.empty!=e.ranges[r].empty).length===0}function kI(t,e){return t.length?e.length?t.concat(e):t:e}var sa=[],t5=200;function SI(t,e){if(t.length){let n=t[t.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-t5));return r.length&&r[r.length-1].eq(e)?t:(r.push(e),Nf(t,t.length-1,1e9,n.setSelAfter(r)))}else return[Ia.selection([e])]}function n5(t){let e=t[t.length-1],n=t.slice();return n[t.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),n}function Hg(t,e){if(!t.length)return t;let n=t.length,r=sa;for(;n;){let a=r5(t[n-1],e,r);if(a.changes&&!a.changes.empty||a.effects.length){let s=t.slice(0,n);return s[n-1]=a,s}else e=a.mapped,n--,r=a.selectionsAfter}return r.length?[Ia.selection(r)]:sa}function r5(t,e,n){let r=kI(t.selectionsAfter.length?t.selectionsAfter.map(o=>o.map(e)):sa,n);if(!t.changes)return Ia.selection(r);let a=t.changes.map(e),s=e.mapDesc(t.changes,!0),i=t.mapped?t.mapped.composeDesc(s):s;return new Ia(a,Ct.mapEffects(t.effects,e),i,t.startSelection.map(s),r)}var a5=/^(input\.type|delete)($|\.)/,to=class t{constructor(e,n,r=0,a=void 0){this.done=e,this.undone=n,this.prevTime=r,this.prevUserEvent=a}isolate(){return this.prevTime?new t(this.done,this.undone):this}addChanges(e,n,r,a,s){let i=this.done,o=i[i.length-1];return o&&o.changes&&!o.changes.empty&&e.changes&&(!r||a5.test(r))&&(!o.selectionsAfter.length&&n-this.prevTime<a.newGroupDelay&&a.joinToEvent(s,QF(o.changes,e.changes))||r=="input.type.compose")?i=Nf(i,i.length-1,a.minDepth,new Ia(e.changes.compose(o.changes),kI(Ct.mapEffects(e.effects,o.changes),o.effects),o.mapped,o.startSelection,sa)):i=Nf(i,i.length,a.minDepth,e),new t(i,sa,n,r)}addSelection(e,n,r,a){let s=this.done.length?this.done[this.done.length-1].selectionsAfter:sa;return s.length>0&&n-this.prevTime<a&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&e5(s[s.length-1],e)?this:new t(SI(this.done,e),this.undone,n,r)}addMapping(e){return new t(Hg(this.done,e),Hg(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,n,r){let a=e==0?this.done:this.undone;if(a.length==0)return null;let s=a[a.length-1],i=s.selectionsAfter[0]||(s.startSelection?s.startSelection.map(s.changes.invertedDesc,1):n.selection);if(r&&s.selectionsAfter.length)return n.update({selection:s.selectionsAfter[s.selectionsAfter.length-1],annotations:Ug.of({side:e,rest:n5(a),selection:i}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(s.changes){let o=a.length==1?sa:a.slice(0,a.length-1);return s.mapped&&(o=Hg(o,s.mapped)),n.update({changes:s.changes,selection:s.startSelection,effects:s.effects,annotations:Ug.of({side:e,rest:o,selection:i}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}};to.empty=new to(sa,sa);var CI=[{key:"Mod-z",run:wI,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Gg,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Gg,preventDefault:!0},{key:"Mod-u",run:JF,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:ZF,preventDefault:!0}];function ll(t,e){return oe.create(t.ranges.map(e),t.mainIndex)}function La(t,e){return t.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function Aa({state:t,dispatch:e},n){let r=ll(t.selection,n);return r.eq(t.selection,!0)?!1:(e(La(t,r)),!0)}function Tf(t,e){return oe.cursor(e?t.to:t.from)}function II(t,e){return Aa(t,n=>n.empty?t.moveByChar(n,e):Tf(n,e))}function or(t){return t.textDirectionAt(t.state.selection.main.head)==nn.LTR}var LI=t=>II(t,!or(t)),AI=t=>II(t,or(t));function PI(t,e){return Aa(t,n=>n.empty?t.moveByGroup(n,e):Tf(n,e))}var s5=t=>PI(t,!or(t)),i5=t=>PI(t,or(t));var qq=typeof Intl<"u"&&Intl.Segmenter?new Intl.Segmenter(void 0,{granularity:"word"}):null;function o5(t,e,n){if(e.type.prop(n))return!0;let r=e.to-e.from;return r&&(r>2||/[^\s,.;:]/.test(t.sliceDoc(e.from,e.to)))||e.firstChild}function Df(t,e,n){let r=ws(t).resolveInner(e.head),a=n?ht.closedBy:ht.openedBy;for(let l=e.head;;){let u=n?r.childAfter(l):r.childBefore(l);if(!u)break;o5(t,u,a)?r=u:l=n?u.to:u.from}let s=r.type.prop(a),i,o;return s&&(i=n?Zi(t,r.from,1):Zi(t,r.to,-1))&&i.matched?o=n?i.end.to:i.end.from:o=n?r.to:r.from,oe.cursor(o,n?-1:1)}var l5=t=>Aa(t,e=>Df(t.state,e,!or(t))),u5=t=>Aa(t,e=>Df(t.state,e,or(t)));function RI(t,e){return Aa(t,n=>{if(!n.empty)return Tf(n,e);let r=t.moveVertically(n,e);return r.head!=n.head?r:t.moveToLineBoundary(n,e)})}var NI=t=>RI(t,!1),MI=t=>RI(t,!0);function TI(t){let e=t.scrollDOM.clientHeight<t.scrollDOM.scrollHeight-2,n=0,r=0,a;if(e){for(let s of t.state.facet(Ne.scrollMargins)){let i=s(t);i?.top&&(n=Math.max(i?.top,n)),i?.bottom&&(r=Math.max(i?.bottom,r))}a=t.scrollDOM.clientHeight-n-r}else a=(t.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:e,height:Math.max(t.defaultLineHeight,a-5)}}function DI(t,e){let n=TI(t),{state:r}=t,a=ll(r.selection,i=>i.empty?t.moveVertically(i,e,n.height):Tf(i,e));if(a.eq(r.selection))return!1;let s;if(n.selfScroll){let i=t.coordsAtPos(r.selection.main.head),o=t.scrollDOM.getBoundingClientRect(),l=o.top+n.marginTop,u=o.bottom-n.marginBottom;i&&i.top>l&&i.bottom<u&&(s=Ne.scrollIntoView(a.main.head,{y:"start",yMargin:i.top-l}))}return t.dispatch(La(r,a),{effects:s}),!0}var uI=t=>DI(t,!1),zg=t=>DI(t,!0);function ui(t,e,n){let r=t.lineBlockAt(e.head),a=t.moveToLineBoundary(e,n);if(a.head==e.head&&a.head!=(n?r.to:r.from)&&(a=t.moveToLineBoundary(e,n,!1)),!n&&a.head==r.from&&r.length){let s=/^\s*/.exec(t.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;s&&e.head!=r.from+s&&(a=oe.cursor(r.from+s))}return a}var c5=t=>Aa(t,e=>ui(t,e,!0)),d5=t=>Aa(t,e=>ui(t,e,!1)),f5=t=>Aa(t,e=>ui(t,e,!or(t))),h5=t=>Aa(t,e=>ui(t,e,or(t))),p5=t=>Aa(t,e=>t.moveToLineBoundary(e,!1,!1)),m5=t=>Aa(t,e=>t.moveToLineBoundary(e,!0,!1));function g5(t,e,n){let r=!1,a=ll(t.selection,s=>{let i=Zi(t,s.head,-1)||Zi(t,s.head,1)||s.head>0&&Zi(t,s.head-1,1)||s.head<t.doc.length&&Zi(t,s.head+1,-1);if(!i||!i.end)return s;r=!0;let o=i.start.from==s.head?i.end.to:i.end.from;return n?oe.range(s.anchor,o):oe.cursor(o)});return r?(e(La(t,a)),!0):!1}var x5=({state:t,dispatch:e})=>g5(t,e,!1);function ia(t,e,n){let r=ll(t.state.selection,a=>{a.undirectional&&a.head>=a.anchor!=e&&(a=oe.range(a.head,a.anchor));let s=n(a);return oe.range(a.anchor,s.head,s.goalColumn,s.bidiLevel||void 0,s.assoc)});return r.eq(t.state.selection)?!1:(t.dispatch(La(t.state,r)),!0)}function FI(t,e){return ia(t,e,n=>t.moveByChar(n,e))}var EI=t=>FI(t,!or(t)),OI=t=>FI(t,or(t));function BI(t,e){return ia(t,e,n=>t.moveByGroup(n,e))}var b5=t=>BI(t,!or(t)),y5=t=>BI(t,or(t));var v5=t=>{let e=!or(t);return ia(t,e,n=>Df(t.state,n,e))},w5=t=>{let e=or(t);return ia(t,e,n=>Df(t.state,n,e))};function _I(t,e){return ia(t,e,n=>t.moveVertically(n,e))}var HI=t=>_I(t,!1),UI=t=>_I(t,!0);function GI(t,e){return ia(t,e,n=>t.moveVertically(n,e,TI(t).height))}var cI=t=>GI(t,!1),dI=t=>GI(t,!0),k5=t=>ia(t,!0,e=>ui(t,e,!0)),S5=t=>ia(t,!1,e=>ui(t,e,!1)),C5=t=>{let e=!or(t);return ia(t,e,n=>ui(t,n,e))},I5=t=>{let e=or(t);return ia(t,e,n=>ui(t,n,e))},L5=t=>ia(t,!1,e=>oe.cursor(t.lineBlockAt(e.head).from)),A5=t=>ia(t,!0,e=>oe.cursor(t.lineBlockAt(e.head).to)),fI=({state:t,dispatch:e})=>(e(La(t,{anchor:0})),!0),hI=({state:t,dispatch:e})=>(e(La(t,{anchor:t.doc.length})),!0),pI=({state:t,dispatch:e})=>(e(La(t,{anchor:t.selection.main.anchor,head:0})),!0),mI=({state:t,dispatch:e})=>(e(La(t,{anchor:t.selection.main.anchor,head:t.doc.length})),!0),P5=({state:t,dispatch:e})=>(e(t.update({selection:{anchor:0,head:t.doc.length},userEvent:"select"})),!0),R5=({state:t,dispatch:e})=>{let n=Ff(t).map(({from:r,to:a})=>oe.undirectionalRange(r,Math.min(a+1,t.doc.length)));return e(t.update({selection:oe.create(n),userEvent:"select"})),!0},N5=({state:t,dispatch:e})=>{let n=ll(t.selection,r=>{let a=ws(t),s=a.resolveStack(r.from,1);if(r.empty){let i=a.resolveStack(r.from,-1);i.node.from>=s.node.from&&i.node.to<=s.node.to&&(s=i)}for(let i=s;i;i=i.next){let{node:o}=i;if((o.from<r.from&&o.to>=r.to||o.to>r.to&&o.from<=r.from)&&i.next)return oe.undirectionalRange(o.from,o.to)}return r});return n.eq(t.selection)?!1:(e(La(t,n)),!0)};function zI(t,e){let{state:n}=t,r=n.selection,a=n.selection.ranges.slice();for(let s of n.selection.ranges){let i=n.doc.lineAt(s.head);if(e?i.to<t.state.doc.length:i.from>0)for(let o=s;;){let l=t.moveVertically(o,e);if(l.head<i.from||l.head>i.to){a.some(u=>u.head==l.head)||a.push(l);break}else{if(l.head==o.head)break;o=l}}}return a.length==r.ranges.length?!1:(t.dispatch(La(n,oe.create(a,a.length-1))),!0)}var M5=t=>zI(t,!1),T5=t=>zI(t,!0),D5=({state:t,dispatch:e})=>{let n=t.selection,r=null;return n.ranges.length>1?r=oe.create([n.main]):n.main.empty||(r=oe.create([oe.cursor(n.main.head)])),r?(e(La(t,r)),!0):!1};function sc(t,e){if(t.state.readOnly)return!1;let n="delete.selection",{state:r}=t,a=r.changeByRange(s=>{let{from:i,to:o}=s;if(i==o){let l=e(s);l<i?(n="delete.backward",l=Rf(t,l,!1)):l>i&&(n="delete.forward",l=Rf(t,l,!0)),i=Math.min(i,l),o=Math.max(o,l)}else i=Rf(t,i,!1),o=Rf(t,o,!0);return i==o?{range:s}:{changes:{from:i,to:o},range:oe.cursor(i,i<s.head?-1:1)}});return a.changes.empty?!1:(t.dispatch(r.update(a,{scrollIntoView:!0,userEvent:n,effects:n=="delete.selection"?Ne.announce.of(r.phrase("Selection deleted")):void 0})),!0)}function Rf(t,e,n){if(t instanceof Ne)for(let r of t.state.facet(Ne.atomicRanges).map(a=>a(t)))r.between(e,e,(a,s)=>{a<e&&s>e&&(e=n?s:a)});return e}var WI=(t,e,n)=>sc(t,r=>{let a=r.from,{state:s}=t,i=s.doc.lineAt(a),o,l;if(n&&!e&&a>i.from&&a<i.from+200&&!/[^ \t]/.test(o=i.text.slice(0,a-i.from))){if(o[o.length-1]==" ")return a-1;let u=Ui(o,s.tabSize),c=u%Qu(s)||Qu(s);for(let d=0;d<c&&o[o.length-1-d]==" ";d++)a--;l=a}else l=Gn(i.text,a-i.from,e,e)+i.from,l==a&&i.number!=(e?s.doc.lines:1)?l+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(i.text.slice(l-i.from,a-i.from))&&(l=Gn(i.text,l-i.from,!1,!1)+i.from);return l}),Wg=t=>WI(t,!1,!0);var jI=t=>WI(t,!0,!1),qI=(t,e)=>sc(t,n=>{let r=n.head,{state:a}=t,s=a.doc.lineAt(r),i=a.charCategorizer(r);for(let o=null;;){if(r==(e?s.to:s.from)){r==n.head&&s.number!=(e?a.doc.lines:1)&&(r+=e?1:-1);break}let l=Gn(s.text,r-s.from,e)+s.from,u=s.text.slice(Math.min(r,l)-s.from,Math.max(r,l)-s.from),c=i(u);if(o!=null&&c!=o)break;(u!=" "||r!=n.head)&&(o=c),r=l}return r}),VI=t=>qI(t,!1),F5=t=>qI(t,!0);var E5=t=>sc(t,e=>{let n=t.lineBlockAt(e.head).to;return e.head<n?n:Math.min(t.state.doc.length,e.head+1)});var O5=t=>sc(t,e=>{let n=t.moveToLineBoundary(e,!1).head;return e.head>n?n:Math.max(0,e.head-1)}),B5=t=>sc(t,e=>{let n=t.moveToLineBoundary(e,!0).head;return e.head<n?n:Math.min(t.state.doc.length,e.head+1)});var _5=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=t.changeByRange(r=>({changes:{from:r.from,to:r.to,insert:mt.of(["",""])},range:oe.cursor(r.from)}));return e(t.update(n,{scrollIntoView:!0,userEvent:"input"})),!0},H5=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=t.changeByRange(r=>{if(!r.empty||r.from==0||r.from==t.doc.length)return{range:r};let a=r.from,s=t.doc.lineAt(a),i=a==s.from?a-1:Gn(s.text,a-s.from,!1)+s.from,o=a==s.to?a+1:Gn(s.text,a-s.from,!0)+s.from;return{changes:{from:i,to:o,insert:t.doc.slice(a,o).append(t.doc.slice(i,a))},range:oe.cursor(o)}});return n.changes.empty?!1:(e(t.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function Ff(t){let e=[],n=-1;for(let r of t.selection.ranges){let a=t.doc.lineAt(r.from),s=t.doc.lineAt(r.to);if(!r.empty&&r.to==s.from&&(s=t.doc.lineAt(r.to-1)),n>=a.number){let i=e[e.length-1];i.to=s.to,i.ranges.push(r)}else e.push({from:a.from,to:s.to,ranges:[r]});n=s.number+1}return e}function $I(t,e,n){if(t.readOnly)return!1;let r=[],a=[];for(let s of Ff(t)){if(n?s.to==t.doc.length:s.from==0)continue;let i=t.doc.lineAt(n?s.to+1:s.from-1),o=i.length+1;if(n){r.push({from:s.to,to:i.to},{from:s.from,insert:i.text+t.lineBreak});for(let l of s.ranges)a.push(oe.range(Math.min(t.doc.length,l.anchor+o),Math.min(t.doc.length,l.head+o)))}else{r.push({from:i.from,to:s.from},{from:s.to,insert:t.lineBreak+i.text});for(let l of s.ranges)a.push(oe.range(l.anchor-o,l.head-o))}}return r.length?(e(t.update({changes:r,scrollIntoView:!0,selection:oe.create(a,t.selection.mainIndex),userEvent:"move.line"})),!0):!1}var U5=({state:t,dispatch:e})=>$I(t,e,!1),G5=({state:t,dispatch:e})=>$I(t,e,!0);function KI(t,e,n){if(t.readOnly)return!1;let r=[];for(let s of Ff(t))n?r.push({from:s.from,insert:t.doc.slice(s.from,s.to)+t.lineBreak}):r.push({from:s.to,insert:t.lineBreak+t.doc.slice(s.from,s.to)});let a=t.changes(r);return e(t.update({changes:a,selection:t.selection.map(a,n?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}var z5=({state:t,dispatch:e})=>KI(t,e,!1),W5=({state:t,dispatch:e})=>KI(t,e,!0),j5=t=>{if(t.state.readOnly)return!1;let{state:e}=t,n=e.changes(Ff(e).map(({from:a,to:s})=>(a>0?a--:s<e.doc.length&&s++,{from:a,to:s}))),r=ll(e.selection,a=>{let s;if(t.lineWrapping){let i=t.lineBlockAt(a.head),o=t.coordsAtPos(a.head,a.assoc||1);o&&(s=i.bottom+t.documentTop-o.bottom+t.defaultLineHeight/2)}return t.moveVertically(a,!0,s)}).map(n);return t.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:"delete.line"}),!0};function q5(t,e){if(/\(\)|\[\]|\{\}/.test(t.sliceDoc(e-1,e+1)))return{from:e,to:e};let n=ws(t).resolveInner(e),r=n.childBefore(e),a=n.childAfter(e),s;return r&&a&&r.to<=e&&a.from>=e&&(s=r.type.prop(ht.closedBy))&&s.indexOf(a.name)>-1&&t.doc.lineAt(r.to).from==t.doc.lineAt(a.from).from&&!/\S/.test(t.sliceDoc(r.to,a.from))?{from:r.to,to:a.from}:null}var gI=XI(!1),V5=XI(!0);function XI(t){return({state:e,dispatch:n})=>{if(e.readOnly)return!1;let r=e.changeByRange(a=>{let{from:s,to:i}=a,o=e.doc.lineAt(s),l=!t&&s==i&&q5(e,s);t&&(s=i=(i<=o.to?o:e.doc.lineAt(i)).to);let u=new Ji(e,{simulateBreak:s,simulateDoubleBreak:!!l}),c=Sg(u,s);for(c==null&&(c=Ui(/^\s*/.exec(e.doc.lineAt(s).text)[0],e.tabSize));i<o.to&&/\s/.test(o.text[i-o.from]);)i++;l?{from:s,to:i}=l:s>o.from&&s<o.from+100&&!/\S/.test(o.text.slice(0,s))&&(s=o.from);let d=["",ec(e,c)];return l&&d.push(ec(e,u.lineIndent(o.from,-1))),{changes:{from:s,to:i,insert:mt.of(d)},range:oe.cursor(s+1+d[1].length)}});return n(e.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}function Vg(t,e){let n=-1;return t.changeByRange(r=>{let a=[];for(let i=r.from;i<=r.to;){let o=t.doc.lineAt(i);o.number>n&&(r.empty||r.to>o.from)&&(e(o,a,r),n=o.number),i=o.to+1}let s=t.changes(a);return{changes:a,range:oe.range(s.mapPos(r.anchor,1),s.mapPos(r.head,1))}})}var $5=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=Object.create(null),r=new Ji(t,{overrideIndentation:s=>{let i=n[s];return i??-1}}),a=Vg(t,(s,i,o)=>{let l=Sg(r,s.from);if(l==null)return;/\S/.test(s.text)||(l=0);let u=/^\s*/.exec(s.text)[0],c=ec(t,l);(u!=c||o.from<s.from+u.length)&&(n[s.from]=l,i.push({from:s.from,to:s.from+u.length,insert:c}))});return a.changes.empty||e(t.update(a,{userEvent:"indent"})),!0},YI=({state:t,dispatch:e})=>t.readOnly?!1:(e(t.update(Vg(t,(n,r)=>{r.push({from:n.from,insert:t.facet(mf)})}),{userEvent:"input.indent"})),!0),JI=({state:t,dispatch:e})=>t.readOnly?!1:(e(t.update(Vg(t,(n,r)=>{let a=/^\s*/.exec(n.text)[0];if(!a)return;let s=Ui(a,t.tabSize),i=0,o=ec(t,Math.max(0,s-Qu(t)));for(;i<a.length&&i<o.length&&a.charCodeAt(i)==o.charCodeAt(i);)i++;r.push({from:n.from+i,to:n.from+a.length,insert:o.slice(i)})}),{userEvent:"delete.dedent"})),!0),K5=t=>(t.setTabFocusMode(),!0);var X5=[{key:"Ctrl-b",run:LI,shift:EI,preventDefault:!0},{key:"Ctrl-f",run:AI,shift:OI},{key:"Ctrl-p",run:NI,shift:HI},{key:"Ctrl-n",run:MI,shift:UI},{key:"Ctrl-a",run:p5,shift:L5},{key:"Ctrl-e",run:m5,shift:A5},{key:"Ctrl-d",run:jI},{key:"Ctrl-h",run:Wg},{key:"Ctrl-k",run:E5},{key:"Ctrl-Alt-h",run:VI},{key:"Ctrl-o",run:_5},{key:"Ctrl-t",run:H5},{key:"Ctrl-v",run:zg}],Y5=[{key:"ArrowLeft",run:LI,shift:EI,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:s5,shift:b5,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:f5,shift:C5,preventDefault:!0},{key:"ArrowRight",run:AI,shift:OI,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:i5,shift:y5,preventDefault:!0},{mac:"Cmd-ArrowRight",run:h5,shift:I5,preventDefault:!0},{key:"ArrowUp",run:NI,shift:HI,preventDefault:!0},{mac:"Cmd-ArrowUp",run:fI,shift:pI},{mac:"Ctrl-ArrowUp",run:uI,shift:cI},{key:"ArrowDown",run:MI,shift:UI,preventDefault:!0},{mac:"Cmd-ArrowDown",run:hI,shift:mI},{mac:"Ctrl-ArrowDown",run:zg,shift:dI},{key:"PageUp",run:uI,shift:cI},{key:"PageDown",run:zg,shift:dI},{key:"Home",run:d5,shift:S5,preventDefault:!0},{key:"Mod-Home",run:fI,shift:pI},{key:"End",run:c5,shift:k5,preventDefault:!0},{key:"Mod-End",run:hI,shift:mI},{key:"Enter",run:gI,shift:gI},{key:"Mod-a",run:P5},{key:"Backspace",run:Wg,shift:Wg,preventDefault:!0},{key:"Delete",run:jI,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:VI,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:F5,preventDefault:!0},{mac:"Mod-Backspace",run:O5,preventDefault:!0},{mac:"Mod-Delete",run:B5,preventDefault:!0}].concat(X5.map(t=>({mac:t.key,run:t.run,shift:t.shift}))),ZI=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:l5,shift:v5},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:u5,shift:w5},{key:"Alt-ArrowUp",run:U5},{key:"Shift-Alt-ArrowUp",run:z5},{key:"Alt-ArrowDown",run:G5},{key:"Shift-Alt-ArrowDown",run:W5},{key:"Mod-Alt-ArrowUp",run:M5},{key:"Mod-Alt-ArrowDown",run:T5},{key:"Escape",run:D5},{key:"Mod-Enter",run:V5},{key:"Alt-l",mac:"Ctrl-l",run:R5},{key:"Mod-i",run:N5,preventDefault:!0},{key:"Mod-[",run:JI},{key:"Mod-]",run:YI},{key:"Mod-Alt-\\",run:$5},{key:"Shift-Mod-k",run:j5},{key:"Shift-Mod-\\",run:x5},{key:"Mod-/",run:zF},{key:"Alt-A",mac:"Ctrl-A",run:jF},{key:"Ctrl-m",mac:"Shift-Alt-m",run:K5}].concat(Y5),QI={key:"Tab",run:YI,shift:JI};var J5={lines:new Map,deletedBefore:new Set},eL=Ct.define(),tL=En.define({create:()=>J5,update(t,e){for(let n of e.effects)if(n.is(eL))return n.value;return t}}),ic=class extends Yn{constructor(n){super();this.kind=n}eq(n){return n.kind===this.kind}toDOM(){let n=document.createElement("div");return this.kind==="deleted"?n.style.cssText="width:0;height:0;margin-left:2px;border-left:4px solid rgba(244,63,94,0.85);border-top:3px solid transparent;border-bottom:3px solid transparent;":n.style.cssText=`width:2px;height:100%;margin-left:3px;border-radius:1px;background:${this.kind==="added"?"rgba(16,185,129,0.9)":"rgba(59,130,246,0.9)"};`,n}},Z5=new ic("added"),Q5=new ic("modified"),eE=new ic("deleted"),tE=al({class:"nrs-cm-git-gutter",lineMarker(t,e){let n=t.state.field(tL,!1);if(!n)return null;let r=t.state.doc.lineAt(e.from).number,a=n.lines.get(r);return a==="added"?Z5:a==="modified"?Q5:n.deletedBefore.has(r)?eE:null},lineMarkerChange:t=>t.transactions.some(e=>e.effects.some(n=>n.is(eL)))});function nL(t){return[tL.init(()=>t),tE]}var rL=W(ue(),1);function $g({value:t,language:e,readOnly:n=!1,wrap:r=!1,onChange:a,className:s,placeholder:i,ariaLabel:o,theme:l="dark-plus",gitLineStatus:u}){let c=(0,lr.useRef)(null),d=(0,lr.useRef)(null),f=(0,lr.useRef)(a),h=(0,lr.useRef)(!1),p=(0,lr.useRef)(new Qr),g=(0,lr.useRef)(new Qr),m=(0,lr.useRef)(new Qr),x=(0,lr.useRef)(new Qr);return f.current=a,(0,lr.useEffect)(()=>{let b=c.current;if(!b)return;let y=Dt.create({doc:t,extensions:[sf(),QS(),nC(),JS(),vI(),tg.of([...ZI,...CI,QI]),Af,p.current.of(li.of({lang:e,theme:l})),Lf,g.current.of([Dt.readOnly.of(n),Ne.editable.of(!n)]),m.current.of(r?Ne.lineWrapping:[]),x.current.of([]),i?eC(i):[],Ne.updateListener.of(I=>{I.docChanged&&!h.current&&f.current?.(I.state.doc.toString())}),Ne.contentAttributes.of(o?{"aria-label":o}:{})]}),C=new Ne({state:y,parent:b});return d.current=C,()=>{C.destroy(),d.current=null}},[]),(0,lr.useEffect)(()=>{let b=d.current;if(!b)return;let y=b.state.doc.toString();t!==y&&(h.current=!0,b.dispatch({changes:{from:0,to:y.length,insert:t}}),h.current=!1)},[t]),(0,lr.useEffect)(()=>{let b=d.current;b&&b.dispatch({effects:p.current.reconfigure(li.of({lang:e,theme:l}))})},[e,l]),(0,lr.useEffect)(()=>{let b=d.current;b&&b.dispatch({effects:g.current.reconfigure([Dt.readOnly.of(n),Ne.editable.of(!n)])})},[n]),(0,lr.useEffect)(()=>{let b=d.current;b&&b.dispatch({effects:m.current.reconfigure(r?Ne.lineWrapping:[])})},[r]),(0,lr.useEffect)(()=>{let b=d.current;if(!b)return;let y=u&&!yd(u)?nL(u):[];b.dispatch({effects:x.current.reconfigure(y)})},[u]),(0,rL.jsx)("div",{ref:c,className:s})}var ul=W(Je(),1);var aL=W(ue(),1);function Kg({target:t,agentId:e,projectId:n}){let r=B(f=>f.client),a=B(f=>f.sourceChangeRevision[t.source]??0),s=`${e??""}\0${n??""}\0${t.source}\0${t.repo??""}`,[i,o]=(0,ul.useState)(null),l=i?.client===r&&i.context===s,u=l&&!i.pending&&i.revision===a&&i.allowed,c=l&&i.allowed;(0,ul.useEffect)(()=>{let f=!0;return o(h=>({client:r,context:s,revision:a,pending:!0,allowed:h?.client===r&&h.context===s&&h.allowed})),e&&lo({agentId:e,...n?{projectId:n}:{},source:t.source},r).then(h=>{f&&o({client:r,context:s,revision:a,pending:!1,allowed:h.repos.find(p=>p.rel===(t.repo??""))?.canWrite===!0})}).catch(()=>{f&&o({client:r,context:s,revision:a,pending:!1,allowed:!1})}),()=>{f=!1}},[r,s,e,n,t.source,t.repo,a]);let d=(0,ul.useMemo)(()=>a1(t),[t]);return(0,aL.jsx)(Di,{source:t.source,repo:t.repo??"",path:t.path,mode:d,agentId:e,projectId:n,variant:"tab",canWrite:u,stageRows:c,permissionPending:!l||i.pending||i.revision!==a,revision:a})}var Ya=W(Je(),1);var xt=W(ue(),1),sL="brain://docs",Xg=V("h-7 w-full rounded-md px-2 text-[10px] outline-none transition font-mono","bg-white/[0.04] border border-white/[0.08] text-white/86","focus:border-white/[0.18] focus:bg-white/[0.06]","placeholder:text-white/28"),nE=V(Xg,"pr-6");function Yg(t){let{agentId:e,projectId:n}=t,r=B(v=>v.workspacePanels.upload),a=B(v=>v.setWorkspacePanelOpen),s=B(v=>v.uploading),i=B(v=>v.uploadMany),o=B(v=>v.files),l=B(v=>v.activeFolderPath),u=B(v=>v.setActiveFolderPath),[c,d]=(0,Ya.useState)(""),[f,h]=(0,Ya.useState)(""),[p,g]=(0,Ya.useState)(!1),[m,x]=(0,Ya.useState)(!1),b=(0,Ya.useRef)(null),y=(0,Ya.useMemo)(()=>{let v=c.trim();return v||l||sL},[l,c]),C=(0,Ya.useMemo)(()=>{let v=new Set;for(let k of Object.values(o||{})){if(k?.type!=="folder")continue;let O=String(k.uri||"");O&&v.add(O)}return v.add(sL),Array.from(v).sort((k,O)=>k.localeCompare(O))},[o]),I=v=>{let k=v.trim();k&&(d(k),u(k))},L=async v=>{if(v.length!==0)try{await i({agentId:e,projectId:n,files:v,uri:y})}finally{b.current&&(b.current.value=""),g(!1),a("upload",!1)}};return r?(0,xt.jsxs)("div",{className:"w-full px-5 pt-3 pb-6 text-white/85",children:[(0,xt.jsx)("input",{ref:b,type:"file",multiple:!0,className:"hidden",onChange:async v=>{let k=Array.from(v.target.files||[]);await L(k)}}),(0,xt.jsxs)("div",{className:"flex items-center justify-between gap-2 pb-2 border-b border-white/[0.06]",children:[(0,xt.jsxs)("div",{className:"flex items-center gap-2",children:[s?(0,xt.jsx)($e,{className:"h-4 w-4 animate-spin text-cyan-300/70 shrink-0"}):(0,xt.jsx)(Ba,{className:"h-4 w-4 text-cyan-300/70 shrink-0"}),(0,xt.jsx)("span",{className:"text-sm font-semibold tracking-wide text-white/92",children:"Upload"}),(0,xt.jsx)("span",{className:"rounded px-1.5 py-0.5 text-[10px] font-medium text-white/45 bg-white/[0.04] font-mono truncate max-w-[160px]",children:y})]}),(0,xt.jsx)("button",{type:"button",onClick:()=>a("upload",!1),className:"h-7 px-2.5 rounded-md text-[10px] font-medium text-white/50 hover:text-white/80 hover:bg-white/[0.05] transition",children:"Close"})]}),(0,xt.jsx)("div",{className:V("mt-2 rounded-md border border-dashed px-4 py-5 text-center transition",p?"border-cyan-300/40 bg-cyan-400/[0.04]":"border-white/[0.10] bg-white/[0.02]",s&&"opacity-60"),onDragEnter:v=>{s||(v.preventDefault(),g(!0))},onDragOver:v=>{s||(v.preventDefault(),v.dataTransfer.dropEffect="copy",g(!0))},onDragLeave:v=>{v.currentTarget.contains(v.relatedTarget)||g(!1)},onDrop:async v=>{s||(v.preventDefault(),await L(Array.from(v.dataTransfer.files||[])))},children:(0,xt.jsxs)("div",{className:"flex items-center justify-center gap-3",children:[s?(0,xt.jsx)($e,{className:"h-4 w-4 animate-spin text-cyan-200/80"}):(0,xt.jsx)(Ba,{className:"h-4 w-4 text-cyan-200/70"}),(0,xt.jsx)("span",{className:"text-[11px] text-white/60",children:s?"Uploading...":"Drop files here"}),(0,xt.jsxs)("button",{type:"button",onClick:()=>b.current?.click(),disabled:s,className:"h-6 px-2.5 rounded-md bg-cyan-500/12 border border-cyan-400/20 text-[9px] font-semibold text-cyan-200/90 hover:bg-cyan-500/20 transition disabled:opacity-40 disabled:cursor-not-allowed inline-flex items-center gap-1",children:[(0,xt.jsx)(ql,{className:"h-2.5 w-2.5"}),"Choose files"]})]})}),(0,xt.jsxs)("div",{className:"mt-1",children:[(0,xt.jsxs)("button",{type:"button",onClick:()=>x(v=>!v),className:"w-full flex items-center gap-2 py-1.5 text-left hover:bg-white/[0.02] rounded-md px-1 transition",children:[(0,xt.jsx)(Or,{className:"h-3.5 w-3.5 text-violet-400/70 shrink-0"}),(0,xt.jsx)("span",{className:"text-[11px] font-semibold text-white/88",children:"Destination"}),(0,xt.jsx)("span",{className:"text-[9px] text-white/35 font-mono truncate",children:y}),(0,xt.jsx)(qt,{className:V("ml-auto h-3 w-3 text-white/25 shrink-0 transition-transform",m&&"rotate-180")})]}),(0,xt.jsx)("div",{className:V("overflow-hidden transition-all duration-200",m?"max-h-[300px] opacity-100":"max-h-0 opacity-0"),children:(0,xt.jsxs)("div",{className:"rounded-md bg-white/[0.02] p-2.5 ml-5 mb-1 space-y-2",children:[(0,xt.jsxs)("div",{className:"space-y-1",children:[(0,xt.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Folder"}),(0,xt.jsx)("select",{value:y,onChange:v=>I(v.target.value),disabled:s,className:nE,children:C.map(v=>(0,xt.jsx)("option",{value:v,className:"bg-[#1a1a1f]",children:v},v))})]}),(0,xt.jsxs)("div",{className:"space-y-1",children:[(0,xt.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Override"}),(0,xt.jsx)("input",{value:c,onChange:v=>d(v.target.value),placeholder:y,disabled:s,className:Xg})]}),(0,xt.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,xt.jsx)("input",{value:f,onChange:v=>h(v.target.value),onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),I(f),h(""))},placeholder:"brain://docs/new-folder",disabled:s,className:V(Xg,"flex-1")}),(0,xt.jsxs)("button",{type:"button",disabled:s||!f.trim(),onClick:()=>{I(f),h("")},className:"h-7 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-white/60 hover:text-white/85 transition disabled:opacity-35 disabled:cursor-not-allowed inline-flex items-center gap-1 shrink-0",children:[(0,xt.jsx)(Or,{className:"h-2.5 w-2.5"}),"Use"]})]})]})})]})]}):null}var Ae=W(Je(),1);var r0=W(nr(),1);function rE(t){let e=t?.configSchema??{};return{required:Array.isArray(e.required)?e.required:[],properties:e.properties&&typeof e.properties=="object"?e.properties:{}}}var aE=new Set(["path","container-path","host-path"]);function iL(t){let e=rE(t),n=e.properties.root,r=n?.["x-neuralis"]?.ui,a=typeof r?.control=="string"?r.control:void 0;return{needed:!!(n&&(e.required.includes("root")||a&&aE.has(a))),container:a!=="host-path",label:typeof r?.label=="string"?r.label:"Path",placeholder:typeof r?.placeholder=="string"?r.placeholder:""}}var Wt=W(Je(),1);var lL=W(nr(),1);var Ce=W(ue(),1);function oL(t){if(!t)return null;let e=`${t.missing} missing \xB7 ${t.stale} stale`;return t.enabled?t.mode!=="dense"?`Semantic: metadata only \u2014 no embedding model active (${e})`:`Semantic: dense (${e})`:`Semantic: off \u2014 text and field search only (${e} if turned on)`}var cl={gc:{label:"GC",explainer:"Removes records marked as deleted, older than the retention window.",tooltip:"Garbage-collect deleted records past the retention threshold (default 24h). Keeps recent deletions in case you want to restore.",destructive:!0},"repair-orphans":{label:"Repair",explainer:"Removes chunks whose parent document no longer exists or is deleted.",tooltip:"Drops orphaned chunks (parent file gone / deleted). Safe to run anytime \u2014 these chunks have no path back to a real file.",destructive:!0},"repair-pending":{label:"Repair pending",explainer:"Discards your pending changes whose file is gone with nothing to restore; counts older changes that need a review in Changes.",tooltip:"Run with Dry run first to see the counts. Only your own visible pending changes are touched; older changes with an unknown original are only reported \u2014 confirm them in the Changes panel. Nothing is reindexed.",destructive:!0},deduplicate:{label:"Deduplicate",explainer:"Reports document groups with identical content hash (read-only \u2014 no delete).",tooltip:"Lists documents that share a content hash. Read-only; nothing is removed.",destructive:!1}};function uL({agentId:t,projectId:e}){let n=B(q=>q.client),r=Ln(),a=cs({grantedFeatures:[...r.grantedFeatures??[]]},"drive.write"),[s,i]=(0,Wt.useState)(null),[o,l]=(0,Wt.useState)(null),[u,c]=(0,Wt.useState)(!1),[d,f]=(0,Wt.useState)(!1),[h,p]=(0,Wt.useState)(null),[g,m]=(0,Wt.useState)(null),[x,b]=(0,Wt.useState)(null),[y,C]=(0,Wt.useState)(null),[I,L]=(0,Wt.useState)(!1),[v,k]=(0,Wt.useState)(!1),[O,R]=(0,Wt.useState)(24),[P,H]=(0,Wt.useState)(null),w=(0,Wt.useRef)(0),N=(0,Wt.useRef)(0),j=(0,Wt.useRef)(0),K=(0,Wt.useRef)(!1),A=(0,Wt.useRef)(void 0),[F,_]=(0,Wt.useState)(!1);(0,Wt.useEffect)(()=>{A.current=void 0,_(!1)},[v,O]);let X=(0,Wt.useRef)(null),re=(0,Wt.useCallback)(async()=>{let q=w.current,Q=++N.current;c(!0),b(null);try{let[te,ge]=await Promise.all([cx({agentId:t,...e?{projectId:e}:{}},n),wx({agentId:t,...e?{projectId:e}:{}},n).catch(()=>[])]),de=new Map;for(let Xe of ge)de.set(Xe.source,{...Xe.last_sync?{last_sync:Xe.last_sync}:{},sync_status:Xe.sync_status});let De=te;if(De.perSource&&(De.perSource=De.perSource.map(Xe=>{let Qe=de.get(Xe.source);return Qe?{...Xe,...Qe}:Xe})),q!==w.current||Q!==N.current)return;i(De)}catch(te){q===w.current&&Q===N.current&&b(te instanceof Error?te.message:"Failed to fetch health report")}finally{q===w.current&&Q===N.current&&c(!1)}},[n,t,e]),ae=(0,Wt.useCallback)(async()=>{let q=w.current,Q=++j.current;L(!0),b(null);try{let te=await dx({agentId:t,...e?{projectId:e}:{}},n);if(q!==w.current||Q!==j.current)return;C({orphanChunkCount:te.orphanChunkCount??0,duplicateGroups:te.duplicateGroups??0})}catch(te){q===w.current&&Q===j.current&&b(te instanceof Error?te.message:"Scan failed")}finally{q===w.current&&Q===j.current&&L(!1)}},[n,t,e]),Le=(0,Wt.useCallback)(async q=>{if(!v&&cl[q].destructive&&P!==q){H(q),X.current&&clearTimeout(X.current),X.current=setTimeout(()=>H(null),3e3);return}X.current&&(clearTimeout(X.current),X.current=null),H(null);let Q=w.current;K.current=!1,f(!0),p(null),m(q),b(null),l(v?null:s);try{let te=q==="repair-pending"?A.current:void 0;_(!1);let ge={};do{let de=await fx({agentId:t,...e?{projectId:e}:{},action:q,dryRun:v,retentionHours:O,...te?{cursor:te}:{}},n);if(Q!==w.current)return;for(let De of["scannedVisible","orphaned","attempted","discarded","refused","failed","legacyUnknownDraft"])typeof de[De]=="number"&&(ge[De]=(ge[De]??0)+de[De]);if(p({...de,...ge}),te=q==="repair-pending"&&!de.restartRequired&&typeof de.nextCursor=="string"?de.nextCursor:void 0,q==="repair-pending"&&(A.current=te),de.partial===!0){_(!0),b("Repair paused; part of the inventory or orphan checks are unavailable.");break}de.restartRequired&&(A.current=void 0,_(!0),b("Changes moved. Refresh before continuing repair.")),typeof de.failed=="number"&&de.failed>0&&(te=void 0,_(!0),b("Repair paused after a failed change. Refresh before continuing."))}while(te&&!K.current);te&&_(!0),v||(re(),y&&ae())}catch(te){Q===w.current&&(q==="repair-pending"&&_(!0),b(te instanceof Error?te.message:"Action failed"))}finally{Q===w.current&&f(!1)}},[n,t,e,v,O,re,P,s,y,ae]);(0,Wt.useEffect)(()=>(w.current++,K.current=!0,A.current=void 0,_(!1),f(!1),p(null),i(null),C(null),b(null),re(),()=>{w.current++,K.current=!0}),[re]),(0,Wt.useEffect)(()=>()=>{X.current&&clearTimeout(X.current)},[]);function ye(q){if(!o||!s)return null;let Q=o[q]??0,te=s[q]??0;if(Q===te)return null;let ge=Q-te,de=ge>0?"\u2212":"+";return`${Q} \u2192 ${te} (${de}${Math.abs(ge)})`}return(0,Ce.jsxs)("div",{className:"space-y-3 px-2 pb-2",children:[d&&g==="repair-pending"?(0,Ce.jsx)("button",{type:"button",onClick:()=>{K.current=!0},className:"text-xs text-amber-200",children:"Stop after this batch"}):null,a&&F&&!d?(0,Ce.jsx)("button",{type:"button",onClick:()=>{Le("repair-pending")},className:"text-xs text-amber-200",children:A.current?"Continue available repair":"Retry repair"}):null,(0,Ce.jsxs)("div",{className:"text-[10px] text-white/40 italic leading-relaxed",children:["Cleanup tool for the vector index. Removes leftover records:"," ",(0,Ce.jsx)("span",{className:"text-white/60",children:"deleted documents past retention"}),","," ",(0,Ce.jsx)("span",{className:"text-white/60",children:"orphaned chunks (no parent file)"}),", and reports"," ",(0,Ce.jsx)("span",{className:"text-white/60",children:"duplicate documents"})," (same content hash). To clear ALL vectors of a single source, use the"," ",(0,Ce.jsx)("span",{className:"text-rose-300/80",children:"Delete"})," button on that source instead."]}),u&&(0,Ce.jsxs)("div",{className:"text-[10px] text-white/40 flex items-center gap-1.5",children:[(0,Ce.jsx)(Xt,{className:"h-3 w-3 animate-spin text-blue-400"})," Loading..."]}),x&&(0,Ce.jsx)("div",{className:"rounded-md bg-red-500/8 px-2.5 py-1.5 text-[10px] text-red-200/80",children:x}),s&&(0,Ce.jsxs)(Ce.Fragment,{children:[(0,Ce.jsx)("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-1.5",children:[{label:"Documents",value:s.documentCount??0,color:"text-emerald-400",delta:null},{label:"Chunks",value:s.chunkCount??0,color:"text-cyan-400",delta:null},{label:"Deleted",value:s.deletedCount??0,color:(s.deletedCount??0)>0?"text-red-400":"text-white/60",delta:g==="gc"?ye("deletedCount"):null},{label:"Orphans",value:y?y.orphanChunkCount??0:"\u2014",color:(y?.orphanChunkCount??0)>0?"text-amber-400":"text-white/60",delta:null}].map(q=>(0,Ce.jsxs)("div",{className:"bg-white/[0.04] border border-white/[0.06] rounded-lg px-2 py-1.5 text-center",children:[(0,Ce.jsx)("div",{className:V("text-sm font-semibold",q.color),children:q.value}),(0,Ce.jsx)("div",{className:"text-[9px] text-white/40",children:q.label}),q.delta&&(0,Ce.jsx)("div",{className:"text-[8px] text-emerald-300/70 mt-0.5 tabular-nums",children:q.delta})]},q.label))}),oL(s.embedding)&&(0,Ce.jsx)("div",{className:"text-[9px] text-white/45",role:"status",children:oL(s.embedding)}),(0,Ce.jsxs)("div",{className:"flex items-center gap-3 text-[9px] text-white/35",children:[(0,Ce.jsxs)("span",{children:["Total points: ",s.totalPoints??"-"]}),(0,Ce.jsxs)("span",{children:["Duplicate groups: ",y?y.duplicateGroups??0:"\u2014"]}),s.generatedAt&&(()=>{let q=Date.now()-new Date(s.generatedAt).getTime(),Q=Math.floor(q/6e4),te=Math.floor(Q/60),ge=Q<1?"just now":te<1?`${Q}m ago`:`${te}h ${Q%60}m ago`,de=te<1?"text-emerald-400/60":"text-amber-400/60";return(0,Ce.jsxs)("span",{className:de,children:["Generated: ",ge]})})()]}),s.perSource&&s.perSource.length>0&&(0,Ce.jsx)("div",{className:"bg-white/[0.04] border border-white/[0.06] rounded-lg overflow-hidden",children:(0,Ce.jsxs)("table",{className:"w-full text-[10px]",children:[(0,Ce.jsx)("thead",{children:(0,Ce.jsxs)("tr",{className:"border-b border-white/[0.06]",children:[(0,Ce.jsx)("th",{className:"text-left px-2 py-1.5 text-white/40 font-medium",children:"Source"}),(0,Ce.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Docs"}),(0,Ce.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Chunks"}),(0,Ce.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Deleted"}),(0,Ce.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Last sync"})]})}),(0,Ce.jsx)("tbody",{children:s.perSource.map((q,Q)=>{let te=q.source.includes(":")?q.source.split(":")[0]:q.source,ge=te==="local"?"text-cyan-400/60":te==="github"?"text-amber-400/60":"text-violet-400/60",de=(()=>{if(!q.last_sync)return q.sync_status==="idle"?"\u2014":q.sync_status??"\u2014";let Xe=new Date(q.last_sync).getTime();if(Number.isNaN(Xe))return q.last_sync;let Qe=Math.floor((Date.now()-Xe)/6e4);if(Qe<1)return"just now";if(Qe<60)return`${Qe}m ago`;let rt=Math.floor(Qe/60);return rt<24?`${rt}h ago`:`${Math.floor(rt/24)}d ago`})(),De=q.last_sync?q.sync_status==="error"?"text-rose-300/60":q.sync_status==="paused"?"text-amber-300/60":"text-emerald-300/60":"text-white/35";return(0,Ce.jsxs)("tr",{className:V("border-b border-white/[0.03] last:border-0",Q%2===1&&"bg-white/[0.02]"),children:[(0,Ce.jsxs)("td",{className:"px-2 py-1 text-white/70 font-mono flex items-center gap-1.5",children:[(0,Ce.jsx)(rr,{className:V("h-2.5 w-2.5 shrink-0",ge)}),q.source]}),(0,Ce.jsx)("td",{className:"px-2 py-1 text-right text-emerald-300/60",children:q.documents}),(0,Ce.jsx)("td",{className:"px-2 py-1 text-right text-cyan-300/60",children:q.chunks}),(0,Ce.jsx)("td",{className:V("px-2 py-1 text-right",q.deleted>0?"text-red-300/60":"text-white/40"),children:q.deleted}),(0,Ce.jsx)("td",{className:V("px-2 py-1 text-right",De),title:q.last_sync??`status: ${q.sync_status??"unknown"}`,children:de})]},q.source)})})]})}),(0,Ce.jsxs)("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[(0,Ce.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,Ce.jsxs)("button",{type:"button",onClick:()=>{re()},disabled:u,title:"Refresh the cheap count stats for this project.",className:"px-2 py-1 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[10px] text-white/70 transition inline-flex items-center gap-1 disabled:opacity-40",children:[(0,Ce.jsx)(Xt,{className:V("h-3 w-3 text-blue-400",u&&"animate-spin")}),"Refresh"]}),(0,Ce.jsxs)("button",{type:"button",onClick:()=>{ae()},disabled:I,title:"Scan the whole index for orphan chunks and duplicate documents. Expensive \u2014 walks every point, so it runs only when you ask.",className:"px-2 py-1 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[10px] text-white/70 transition inline-flex items-center gap-1 disabled:opacity-40",children:[(0,Ce.jsx)(us,{className:V("h-3 w-3 text-amber-400",I&&"animate-pulse")}),y?"Re-scan":"Scan for problems"]}),(0,Ce.jsx)("span",{className:"text-white/10",children:"|"}),["gc","repair-orphans",...a?["repair-pending"]:[],"deduplicate"].map(q=>{let Q=cl[q],te=q==="gc"?_t:q==="repair-orphans"?jl:q==="repair-pending"?Fs:ga,ge=q==="gc"?"text-amber-400":q==="repair-orphans"?"text-cyan-400":q==="repair-pending"?"text-rose-300":"text-violet-400",de=P===q;return(0,Ce.jsxs)("button",{type:"button",onClick:()=>{Le(q)},disabled:d,title:Q.tooltip,className:V("px-2 py-1 rounded-md text-[10px] transition inline-flex items-center gap-1 disabled:opacity-40",de?"bg-rose-500/15 hover:bg-rose-500/25 text-rose-100 border border-rose-400/40":"bg-white/[0.04] hover:bg-white/[0.08] text-white/70"),children:[(0,Ce.jsx)(te,{className:V("h-3 w-3",ge)}),de?"Click again to confirm":Q.label]},q)}),(0,Ce.jsx)("span",{className:"text-white/10",children:"|"}),(0,Ce.jsx)(lL.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-sources",packageId:"@neuralis/brain-core",label:"Inspect sync status or reindex a source with the agent",icon:"Database"})]}),(0,Ce.jsxs)("div",{className:"flex items-center gap-3",children:[(0,Ce.jsxs)("label",{className:"inline-flex items-center gap-1 text-[10px] text-white/60 cursor-pointer",title:"Preview only \u2014 nothing will be deleted.",children:[(0,Ce.jsx)("input",{type:"checkbox",disabled:d,checked:v,onChange:q=>k(q.target.checked),className:"accent-emerald-400 h-3 w-3"}),"Dry run"]}),(0,Ce.jsxs)("label",{className:"inline-flex items-center gap-1 text-[10px] text-white/60",title:"Records marked as deleted within this many hours are kept (GC ignores them).",children:["Retention:",(0,Ce.jsx)("input",{type:"number",disabled:d,min:1,value:O,onChange:q=>R(Math.max(1,Number(q.target.value)||24)),className:"w-12 h-5 rounded px-1 text-[10px] bg-white/[0.04] border border-white/[0.08] text-white/80 outline-none"}),"h"]})]})]}),(0,Ce.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-1.5 text-[9px] text-white/40 leading-snug",children:[(0,Ce.jsxs)("div",{children:[(0,Ce.jsx)("span",{className:"text-amber-300/70 font-medium",children:"GC:"})," ",cl.gc.explainer]}),(0,Ce.jsxs)("div",{children:[(0,Ce.jsx)("span",{className:"text-cyan-300/70 font-medium",children:"Repair:"})," ",cl["repair-orphans"].explainer]}),(0,Ce.jsxs)("div",{children:[(0,Ce.jsx)("span",{className:"text-violet-300/70 font-medium",children:"Deduplicate:"})," ",cl.deduplicate.explainer]}),a?(0,Ce.jsxs)("div",{children:[(0,Ce.jsx)("span",{className:"text-rose-300/70 font-medium",children:"Repair pending:"})," ",cl["repair-pending"].explainer]}):null]}),h&&(0,Ce.jsxs)("div",{className:"bg-white/[0.04] border border-white/[0.06] rounded-lg px-2.5 py-2 text-[10px] text-white/60 space-y-0.5",children:[(0,Ce.jsxs)("div",{className:"text-[10px] text-white/50 font-medium mb-1 flex items-center justify-between",children:[(0,Ce.jsx)("span",{children:"Last Action Result"}),typeof h.removed=="number"&&(0,Ce.jsxs)("span",{className:V("font-mono tabular-nums",h.dryRun?"text-amber-300/80":"text-emerald-300/85"),children:[h.dryRun?"Would remove":"Removed",": ",h.removed]})]}),Object.entries(h).map(([q,Q])=>(0,Ce.jsxs)("div",{className:"flex justify-between",children:[(0,Ce.jsx)("span",{className:"text-white/40",children:q}),(0,Ce.jsx)("span",{className:"text-white/70 font-mono",children:typeof Q=="object"?JSON.stringify(Q):String(Q)})]},q))]})]})]})}var xn=W(Je(),1);var He=W(ue(),1),sE=["member","owner","admin"],Ef=["read","write","exec"];function iE(t){return{default:{...t.default},...t.byRole?{byRole:Jg(t.byRole)}:{},...t.byUser?{byUser:Jg(t.byUser)}:{},...t.byAgent?{byAgent:Jg(t.byAgent)}:{},paths:(t.paths??[]).map(e=>({...e,permissions:{...e.permissions},...e.roles?{roles:[...e.roles]}:{},...e.agents?{agents:[...e.agents]}:{},...e.users?{users:[...e.users]}:{}}))}}function Jg(t){let e={};for(let[n,r]of Object.entries(t))e[n]={...r};return e}function oE(t){return{pattern:`${t}://`,permissions:{read:!0,write:!1,exec:!1}}}function Zg({letter:t,state:e,onClick:n,disabled:r,title:a}){let s=e===!0?"bg-emerald-500/20 text-emerald-200 border-emerald-400/30":e===!1?"bg-rose-500/15 text-rose-200/80 border-rose-400/25":"bg-white/[0.04] text-white/35 border-white/[0.08]";return(0,He.jsx)("button",{type:"button",title:a??`${t} \u2014 ${e===!0?"allow":e===!1?"deny":"inherit"}`,disabled:r,onClick:n,className:V("inline-flex items-center justify-center w-5 h-5 rounded text-[9px] font-bold tabular-nums border transition disabled:cursor-default",s,!r&&"hover:brightness-125"),children:t})}function Qg(t){return t==="read"?"R":t==="write"?"W":"X"}function cL(t,e){if(!e)return!t;if(t===void 0)return!0;if(t===!0)return!1}function e0({source:t,permissions:e,mode:n,onSave:r,knownRoles:a=sE}){let[s,i]=(0,xn.useState)(()=>iE(e)),[o,l]=(0,xn.useState)(!1),[u,c]=(0,xn.useState)(null),[d,f]=(0,xn.useState)(""),[h,p]=(0,xn.useState)(""),[g,m]=(0,xn.useState)(""),x=(0,xn.useMemo)(()=>JSON.stringify(s)!==JSON.stringify(e),[s,e]),b=n==="view",y=(0,xn.useCallback)((A,F)=>{i(_=>({..._,default:{..._.default,[A]:F}}))},[]),C=A=>A,I=(0,xn.useCallback)((A,F)=>{let _=F.trim();_&&i(X=>{let re={...X[C(A)]??{}};return _ in re?X:(re[_]={},{...X,[C(A)]:re})})},[]),L=(0,xn.useCallback)((A,F)=>{i(_=>{let X={..._[C(A)]??{}};return delete X[F],Object.keys(X).length===0?{..._,[C(A)]:void 0}:{..._,[C(A)]:X}})},[]),v=(0,xn.useCallback)((A,F,_)=>{i(X=>{let re={...X[C(A)]??{}},ae=re[F]??{},Le=cL(ae[_],!0),ye={...ae};return Le===void 0?delete ye[_]:ye[_]=Le,re[F]=ye,{...X,[C(A)]:re}})},[]),k=(0,xn.useCallback)((A,F)=>{i(_=>{let X=[..._.paths??[]];return X[A]={...X[A],...F},{..._,paths:X}})},[]),O=(0,xn.useCallback)((A,F)=>{i(_=>{let X=[..._.paths??[]],re=X[A],ae=cL(re.permissions[F],!0),Le={...re.permissions};return ae===void 0?delete Le[F]:Le[F]=ae,X[A]={...re,permissions:Le},{..._,paths:X}})},[]),R=(0,xn.useCallback)((A,F)=>{i(_=>{let X=[..._.paths??[]],re=X[A],ae=new Set(re.roles??[]);return ae.has(F)?ae.delete(F):ae.add(F),X[A]=ae.size>0?{...re,roles:[...ae]}:{...re,roles:void 0},{..._,paths:X}})},[]),P=(0,xn.useCallback)((A,F,_)=>{let X=_.trim();X&&i(re=>{let ae=[...re.paths??[]],Le=ae[A],ye=new Set(Le[F]??[]);return ye.add(X),ae[A]={...Le,[F]:[...ye]},{...re,paths:ae}})},[]),H=(0,xn.useCallback)((A,F,_)=>{i(X=>{let re=[...X.paths??[]],ae=re[A],Le=(ae[F]??[]).filter(ye=>ye!==_);return re[A]={...ae,[F]:Le.length>0?Le:void 0},{...X,paths:re}})},[]),w=(0,xn.useCallback)(()=>{i(A=>({...A,paths:[oE(t),...A.paths??[]]}))},[t]),N=(0,xn.useCallback)(A=>{i(F=>({...F,paths:(F.paths??[]).filter((_,X)=>X!==A)}))},[]),j=(0,xn.useCallback)(async()=>{if(r){l(!0),c(null);try{await r(s)}catch(A){c(A instanceof Error?A.message:String(A))}finally{l(!1)}}},[s,r]),K=(A,F,_,X,re)=>{let ae=s[C(A)]??{},Le=Object.entries(ae),[ye,q]=re;return(0,He.jsxs)("div",{className:"space-y-1",children:[(0,He.jsxs)("div",{className:"flex items-center gap-2",children:[(0,He.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40",children:F}),(0,He.jsx)("span",{className:"text-[9px] text-white/30 italic flex-1 truncate",children:_})]}),Le.length===0&&b?(0,He.jsx)("div",{className:"text-[9px] text-white/25 italic",children:"No overrides."}):null,Le.map(([Q,te])=>(0,He.jsxs)("div",{className:"flex items-center gap-1.5 text-[10px]",children:[(0,He.jsx)("span",{className:"font-mono text-white/70 truncate min-w-[72px]",children:Q}),Ef.map(ge=>(0,He.jsx)(Zg,{letter:Qg(ge),state:te[ge],onClick:b?void 0:()=>v(A,Q,ge),disabled:b},ge)),!b&&(0,He.jsx)("button",{type:"button",onClick:()=>L(A,Q),className:"ml-auto text-white/30 hover:text-rose-300 transition",title:"Remove override",children:(0,He.jsx)(_t,{className:"w-3 h-3"})})]},Q)),!b&&(0,He.jsxs)("div",{className:"flex items-center gap-1.5 pt-0.5",children:[(0,He.jsx)("input",{type:"text",value:ye,onChange:Q=>q(Q.target.value),onKeyDown:Q=>{Q.key==="Enter"&&(Q.preventDefault(),I(A,ye),q(""))},placeholder:X,className:"h-6 flex-1 rounded bg-white/[0.04] border border-white/[0.08] px-2 text-[10px] text-white/80 placeholder:text-white/25 outline-none focus:border-white/20"}),(0,He.jsxs)("button",{type:"button",onClick:()=>{I(A,ye),q("")},className:"h-6 px-2 rounded bg-white/[0.05] border border-white/[0.08] text-[9px] font-semibold text-white/65 hover:text-white/90 hover:bg-white/[0.08] transition inline-flex items-center gap-1",children:[(0,He.jsx)($n,{className:"w-2.5 h-2.5"}),"Add"]})]})]})};return(0,He.jsxs)("div",{className:"flex flex-col gap-3 text-[10px]",children:[(0,He.jsx)("div",{className:"space-y-1",children:(0,He.jsxs)("div",{className:"flex items-center gap-2",children:[(0,He.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40",children:"Default"}),(0,He.jsxs)("span",{className:"text-[9px] text-white/30 italic flex-1 truncate",children:["Base access for ",t,"://*"]}),(0,He.jsx)("div",{className:"flex items-center gap-1",children:Ef.map(A=>(0,He.jsx)(Zg,{letter:Qg(A),state:s.default[A],onClick:b?void 0:()=>y(A,!s.default[A]),disabled:b},A))})]})}),K("byRole","By Role","Override default for specific roles.","role (e.g. admin)",[d,f]),K("byUser","By User","Override for specific users (highest priority after paths).","userId",[h,p]),K("byAgent","By Agent","$self = the agent owning the file.","$self or agentId",[g,m]),(0,He.jsxs)("div",{className:"space-y-1",children:[(0,He.jsxs)("div",{className:"flex items-center gap-2",children:[(0,He.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40",children:"Path Rules"}),(0,He.jsx)("span",{className:"text-[9px] text-white/30 italic flex-1 truncate",children:"Fine-grained rules per path/glob \u2014 first match wins."}),!b&&(0,He.jsxs)("button",{type:"button",onClick:w,className:"h-6 px-2 rounded bg-white/[0.05] border border-white/[0.08] text-[9px] font-semibold text-white/65 hover:text-white/90 hover:bg-white/[0.08] transition inline-flex items-center gap-1",children:[(0,He.jsx)($n,{className:"w-2.5 h-2.5"}),"Rule"]})]}),(s.paths??[]).length===0?(0,He.jsx)("div",{className:"text-[9px] text-white/25 italic",children:"No rules \u2014 Default applies everywhere."}):(0,He.jsx)("ul",{className:"space-y-1",children:(s.paths??[]).map((A,F)=>(0,He.jsxs)("li",{className:"rounded bg-white/[0.02] border border-white/[0.05] px-2 py-1.5 space-y-1.5",children:[(0,He.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,He.jsx)("input",{type:"text",disabled:b,value:A.pattern,onChange:_=>k(F,{pattern:_.target.value}),placeholder:`${t}://path/**`,className:"flex-1 min-w-0 h-6 rounded bg-white/[0.04] border border-white/[0.08] px-2 text-[10px] font-mono text-white/85 outline-none focus:border-white/20 disabled:opacity-70"}),Ef.map(_=>(0,He.jsx)(Zg,{letter:Qg(_),state:A.permissions[_],onClick:b?void 0:()=>O(F,_),disabled:b},_)),(0,He.jsx)("button",{type:"button",disabled:b,onClick:()=>k(F,{override:A.override?void 0:!0}),title:"Override deny-wins precedence",className:V("h-5 px-1.5 rounded text-[8px] font-semibold border transition disabled:cursor-default",A.override?"bg-amber-500/15 text-amber-200 border-amber-400/30":"bg-white/[0.04] text-white/35 border-white/[0.08] hover:text-white/65"),children:"OVR"}),!b&&(0,He.jsx)("button",{type:"button",onClick:()=>N(F),title:"Remove rule",className:"text-white/30 hover:text-rose-300 transition",children:(0,He.jsx)(_t,{className:"w-3 h-3"})})]}),(0,He.jsxs)("div",{className:"flex flex-wrap items-center gap-1 text-[9px] text-white/50",children:[(0,He.jsx)("span",{className:"text-white/35 mr-0.5",children:"Roles:"}),a.map(_=>{let X=(A.roles??[]).includes(_);return(0,He.jsx)("button",{type:"button",disabled:b,onClick:()=>R(F,_),className:V("h-5 px-1.5 rounded border text-[9px] font-medium capitalize transition disabled:cursor-default",X?"bg-cyan-500/15 text-cyan-200 border-cyan-400/30":"bg-white/[0.04] text-white/40 border-white/[0.08] hover:text-white/70"),children:_},_)}),(A.roles??[]).length===0&&(0,He.jsx)("span",{className:"italic text-white/30",children:"all roles"})]}),(0,He.jsx)(dL,{label:"Agents",values:A.agents??[],emptyLabel:"any agent",placeholder:"$self / agentId",readOnly:b,onAdd:_=>P(F,"agents",_),onRemove:_=>H(F,"agents",_)}),(0,He.jsx)(dL,{label:"Users",values:A.users??[],emptyLabel:"any user",placeholder:"$owner / userId",readOnly:b,onAdd:_=>P(F,"users",_),onRemove:_=>H(F,"users",_)}),(A.users??[]).length>0&&!lE(A)&&(0,He.jsx)("div",{className:"text-[9px] text-amber-200/80",children:"Users apply only to an allow rule: turn on OVR and set every bit to allow."})]},F))})]}),!b&&(0,He.jsxs)("div",{className:"flex items-center justify-between gap-2 pt-1",children:[u&&(0,He.jsx)("span",{className:"text-[9px] text-rose-300/80",children:u}),(0,He.jsxs)("button",{type:"button",onClick:j,disabled:!x||o,className:V("ml-auto inline-flex items-center gap-1 h-6 px-2.5 rounded bg-emerald-500/15 border border-emerald-400/30 text-[10px] font-semibold text-emerald-200 hover:bg-emerald-500/25 transition",(!x||o)&&"opacity-40 cursor-default"),children:[(0,He.jsx)(ki,{className:"w-3 h-3"}),o?"Saving\u2026":"Save policy"]})]})]})}function lE(t){let e=Ef.map(n=>t.permissions[n]).filter(n=>n!==void 0);return t.override===!0&&e.length>0&&e.every(n=>n===!0)}function dL({label:t,values:e,emptyLabel:n,placeholder:r,readOnly:a,onAdd:s,onRemove:i}){return(0,He.jsxs)("div",{className:"flex flex-wrap items-center gap-1 text-[9px] text-white/50",children:[(0,He.jsxs)("span",{className:"text-white/35 mr-0.5",children:[t,":"]}),e.map(o=>(0,He.jsxs)("span",{className:"inline-flex items-center gap-1 h-5 px-1.5 rounded bg-violet-500/12 text-violet-200 border border-violet-400/25",children:[(0,He.jsx)("span",{className:"font-mono",children:o}),!a&&(0,He.jsx)("button",{type:"button",onClick:()=>i(o),className:"text-violet-200/60 hover:text-rose-300",title:`Remove ${o}`,children:"\xD7"})]},o)),e.length===0&&(0,He.jsx)("span",{className:"italic text-white/30",children:n}),!a&&(0,He.jsx)(uE,{placeholder:r,onAdd:s})]})}function uE({placeholder:t,onAdd:e}){let[n,r]=(0,xn.useState)("");return(0,He.jsxs)("div",{className:"inline-flex items-center gap-1",children:[(0,He.jsx)("input",{type:"text",value:n,onChange:a=>r(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),e(n),r(""))},placeholder:t,className:"h-5 rounded bg-white/[0.04] border border-white/[0.08] px-1.5 text-[9px] font-mono text-white/75 placeholder:text-white/25 outline-none focus:border-white/20 w-[120px]"}),(0,He.jsx)("button",{type:"button",onClick:()=>{e(n),r("")},className:"text-white/40 hover:text-white/80 transition",title:"Add",children:(0,He.jsx)($n,{className:"w-3 h-3"})})]})}var fL=W(Je(),1);var on=W(ue(),1);function hL({source:t,vectorCount:e,isDockerMount:n,busy:r,onCancel:a,onConfirm:s}){let[i,o]=(0,fL.useState)(!1);return(0,on.jsxs)("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/5 p-2.5 mt-1.5 ml-5 mb-1 space-y-2",children:[(0,on.jsxs)("div",{className:"flex items-start gap-2",children:[(0,on.jsx)(gt,{className:"h-3.5 w-3.5 text-rose-300 shrink-0 mt-0.5"}),(0,on.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,on.jsxs)("div",{className:"text-[11px] font-semibold text-white/90",children:["Delete ",(0,on.jsx)("span",{className:"font-mono text-rose-200",children:t}),"?"]}),(0,on.jsxs)("div",{className:"text-[10px] text-white/55 mt-0.5",children:["The source config and connector binding are removed."," ",(0,on.jsx)("span",{className:"text-white/75",children:"The host folder is not touched"})," ","\u2014 your files stay where they are."]})]})]}),(0,on.jsxs)("label",{className:"flex items-start gap-2 cursor-pointer rounded px-1.5 py-1 hover:bg-white/[0.03]",children:[(0,on.jsx)("input",{type:"checkbox",checked:i,onChange:l=>o(l.target.checked),className:"accent-rose-400 h-3 w-3 mt-0.5"}),(0,on.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,on.jsxs)("div",{className:"text-[10px] font-medium text-white/80",children:["Purge vector index entries",e!==null&&(0,on.jsxs)("span",{className:"text-white/40 ml-1.5 tabular-nums",children:["(~",e," point",e===1?"":"s",")"]})]}),(0,on.jsxs)("div",{className:"text-[9px] text-white/40 leading-relaxed",children:["Removes every Qdrant point whose URI maps back to"," ",(0,on.jsxs)("code",{className:"font-mono text-white/55",children:[t,"://"]}),". Otherwise the vectors stay and Vector Health \u2192 Repair will mop them up later."]})]})]}),n&&(0,on.jsxs)("div",{className:"rounded bg-amber-500/8 border border-amber-400/20 px-2 py-1.5 text-[9px] italic text-amber-100/70 leading-relaxed",children:["Docker bind-mount source. This deletes the source config (and vectors, if checked). To also drop the underlying compose bind, run the infra-only:"," ",(0,on.jsxs)("code",{className:"font-mono not-italic text-amber-100/90",children:["neuralis mount remove ",t]})]}),(0,on.jsxs)("div",{className:"flex items-center justify-end gap-1.5 pt-0.5",children:[(0,on.jsxs)("button",{type:"button",onClick:a,disabled:r,className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[10px] font-medium text-white/70 transition disabled:opacity-40 inline-flex items-center gap-1",children:[(0,on.jsx)(Yt,{className:"h-2.5 w-2.5"}),"Cancel"]}),(0,on.jsxs)("button",{type:"button",onClick:()=>s({purgeVectors:i}),disabled:r,className:V("h-6 px-2.5 rounded-md text-[10px] font-semibold transition disabled:opacity-40 inline-flex items-center gap-1","bg-rose-500/20 hover:bg-rose-500/30 border border-rose-400/40 text-rose-100"),children:[r?(0,on.jsx)($e,{className:"h-2.5 w-2.5 animate-spin"}):(0,on.jsx)(_t,{className:"h-2.5 w-2.5"}),"Delete",i?" + Purge":""]})]})]})}var S=W(ue(),1),t0={exclude:[],trigger:"manual"},cE=[{value:"manual",label:"Manual"},{value:"auto",label:"Auto (watch + reconcile)"},{value:"interval",label:"On schedule"}],dE=[{value:"s",label:"sec"},{value:"m",label:"min"},{value:"h",label:"hr"},{value:"d",label:"day"}],a0="Mounted (user-added)";function fE(t){return t&&t.trim().length>0?t:a0}function hE(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,24)||"agent"}function Hf(t){return t.toLowerCase().replace(/[^a-z0-9-]+/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"").slice(0,40)}function pE(t){return t.split(/[/\\]/).filter(Boolean).pop()??null}function mE(t){if(t?.name){let e=Hf(t.name);if(e)return e}if(t?.email){let e=Hf(t.email.split("@")[0]??"");if(e)return e}return"user"}function xL(t){let{baseName:e,meta:n,scope:r,ids:a}=t,i=(e?Hf(e):"")||(n?.urlScheme||n?.kind||"source").toLowerCase().replace(/[^a-z0-9-]+/g,"-");return r==="project"?i:r==="user"?`${i}-${a.userSlug||"user"}`:`${i}-${a.agentSlug||hE(a.agentId)}`}function gE(t){return t?.allowedScopes?.length?t.allowedScopes:["project","user","agent"]}function s0(t){return!!t?.capabilities.includes("scanDelta")}function i0(t){let e=t?.configSchema??{};return{required:Array.isArray(e.required)?e.required:[],properties:e.properties&&typeof e.properties=="object"?e.properties:{}}}function xE(t){let e=i0(t),n={};for(let[r,a]of Object.entries(e.properties)){if(r==="root")continue;let s=a.default;(typeof s=="string"||typeof s=="number"||typeof s=="boolean")&&(n[r]=s)}return n}function bL(t){let e=t?.defaultPermissions?.default;return{read:typeof e?.read=="boolean"?e.read:!0,write:typeof e?.write=="boolean"?e.write:!1,exec:typeof e?.exec=="boolean"?e.exec:!1}}function oc(t,e){let n=t?.defaultScope??"project",r=bL(t);return{key:xL({baseName:null,meta:t,scope:n,ids:e}),path:"",scope:n,...r,syncEnabled:s0(t),exclude:Bf(t?.defaultSyncExcludes??[]),include:"",trigger:"manual",description:"",config:xE(t),policies:[],recognizesPackages:!1}}function lc(t){return t.split(/\r?\n|,/).map(e=>e.trim()).filter(Boolean)}function Bf(t){return Array.isArray(t)?t.join(`
|
|
44
|
+
`):""}function bE(t){return t&&t.default&&typeof t.default=="object"?t:t&&typeof t.read=="boolean"?{default:{read:t.read,write:t.write??!1,exec:t.exec??!1}}:{default:{read:!0,write:!1,exec:!1}}}function dl(t){return{source:t.source,permissions:bE(t.permissions),description:t.description??"",recognizesPackages:t.recognizesPackages??!1,...t.sync?{sync:{exclude:[...t.sync.exclude??[]],trigger:t.sync.trigger??"manual",...t.sync.include&&t.sync.include.length>0?{include:[...t.sync.include]}:{},...t.sync.alwaysActive!==void 0?{alwaysActive:t.sync.alwaysActive}:{},...t.sync.maxScanFiles!==void 0?{maxScanFiles:t.sync.maxScanFiles}:{},...t.sync.media?{media:{...t.sync.media}}:{}}}:{}}}var yE=[{key:"images",label:"Images",on:!0},{key:"pdf",label:"PDF pages",on:!0},{key:"video",label:"Video",on:!1},{key:"audio",label:"Audio",on:!1}];function pL(t){if(!t)return null;let e=[];return t.textOnlyModel>0&&e.push(`${t.textOnlyModel} media file${t.textOnlyModel===1?"":"s"} not embedded \u2014 the active embedding model is text-only`),t.off>0&&e.push(`${t.off} off in media settings`),t.tooLarge>0&&e.push(`${t.tooLarge} over the media size limit`),t.invalid>0&&e.push(`${t.invalid} structurally invalid PNG file${t.invalid===1?"":"s"}`),t.unavailable>0&&e.push(`${t.unavailable} unreadable as media`),e.length>0?e.join(" \xB7 "):null}function vE(t,e){if(e===!1)return{text:"Semantic embedding off \u2014 text and field search only",attention:!1};let n=(t??[]).filter(r=>r!=="disabled");return n.length===0?null:{text:`Semantic embedding pending: ${n.join(", ")} \u2014 files are indexed and text-searchable`,attention:!0}}function mL(t){return t?`${t} binary file${t===1?"":"s"} not indexed`:null}function wE(t,e,n){if(n)return!0;let r=t.sync,a=e.sync;if(!r||!a)return!!r!=!!a;let s=i=>(i??[]).join(`
|
|
45
|
+
`);return s(r.exclude)!==s(a.exclude)||s(r.include)!==s(a.include)||r.maxScanFiles!==a.maxScanFiles}function yL(t){if(t==="auto"||t==="on_change")return{mode:"auto",val:"5",unit:"m"};let e=/^interval:(\d+)([smhd])$/.exec(t);return e?{mode:"interval",val:e[1],unit:e[2]}:{mode:"manual",val:"5",unit:"m"}}function _f(t){return t==="s"?30:1}function n0(t,e,n){if(t!=="interval")return t;let r=Number.parseInt(e,10);return`interval:${Number.isFinite(r)?Math.max(r,_f(n)):5}${n}`}function kE(t){let e=yL(t);return e.mode==="manual"?"Manual":e.mode==="auto"?"Auto":`Every ${e.val}${e.unit}`}function SE(t,e){let n=t.connection.config??{};for(let[r,a]of Object.entries(n)){if(typeof a=="string"&&a.length>0)return a;if(typeof a=="number")return String(a)}return e?.label??t.connection.kind}function CE(t,e){let n=t.permissions??bL(e);return{source:Ke(t.uri_root),source_kind:t.source_kind,scope:{kind:"project"},createdBy:"runtime",connection:{kind:t.source_kind,config:{}},permissions:{default:n},sync_status:t.sync_status,last_updated:t.last_updated,kind_label:e?.label??t.source_kind,kind_trust:e?.trust??null,observed:!0,...t.origin_package?{origin_package:t.origin_package}:{},...t.live!==void 0?{live:t.live}:{},...t.live_reason?{live_reason:t.live_reason}:{}}}function IE(t,e){return JSON.stringify(dl(t))!==JSON.stringify(e)}function gL(t){if(!t)return"never";let e=Date.now()-new Date(t).getTime();return e<6e4?"just now":e<36e5?`${Math.floor(e/6e4)}m ago`:e<864e5?`${Math.floor(e/36e5)}h ago`:`${Math.floor(e/864e5)}d ago`}var no=V("h-7 w-full rounded-md px-2 text-[10px] outline-none transition","bg-white/[0.04] border border-white/[0.08] text-white/86","focus:border-white/[0.18] focus:bg-white/[0.06]","placeholder:text-white/28"),Of=V(no,"pr-6 font-mono"),uc=V("w-full rounded-md px-2 py-1.5 text-[10px] font-mono outline-none resize-y transition","bg-white/[0.04] border border-white/[0.08] text-white/86","focus:border-white/[0.18] focus:bg-white/[0.06]","placeholder:text-white/28");function vL(t){let e=B(M=>M.client),{agentId:n,projectId:r,isDocker:a}=t,s=B(M=>M.workspacePanels.sources),i=B(M=>M.setWorkspacePanelOpen),o=B(M=>M.pendingSourceSuggestion),l=B(M=>M.setPendingSourceSuggestion),u=B(M=>M.refresh),c=B(M=>M.sources),d=Ln(),f=d.useAgents(),h=(0,Ae.useMemo)(()=>mE(d.currentUser),[d.currentUser]),p=(d.currentRole?.priority??99)<=2,g=(0,Ae.useMemo)(()=>ko({grantedFeatures:[...d.grantedFeatures??[]]},{features:["drive.mount"]}),[d.grantedFeatures]),m=(0,Ae.useMemo)(()=>{let M=f.byId[n]?.name;return M?Hf(M):void 0},[f,n]),x=(0,Ae.useMemo)(()=>({userSlug:h,agentSlug:m,agentId:n}),[h,m,n]),[b,y]=(0,Ae.useState)([]),[C,I]=(0,Ae.useState)({}),[L,v]=(0,Ae.useState)({}),[k,O]=(0,Ae.useState)({}),[R,P]=(0,Ae.useState)(new Set),[H,w]=(0,Ae.useState)({}),[N,j]=(0,Ae.useState)(!1),[K,A]=(0,Ae.useState)(null),[F,_]=(0,Ae.useState)(null),[X,re]=(0,Ae.useState)(null),[ae,Le]=(0,Ae.useState)(null),[ye,q]=(0,Ae.useState)(null),[Q,te]=(0,Ae.useState)(null),[ge,de]=(0,Ae.useState)(null),[De,Xe]=(0,Ae.useState)(null),[Qe,rt]=(0,Ae.useState)(null),[at,Ft]=(0,Ae.useState)(null),[Ue,ut]=(0,Ae.useState)({}),[st,yt]=(0,Ae.useState)(null),[vt,Ut]=(0,Ae.useState)("source"),[Et,me]=(0,Ae.useState)(""),[Ye,cn]=(0,Ae.useState)(!0),[fe,Re]=(0,Ae.useState)(null),[Oe,Pe]=(0,Ae.useState)(!1),ze=(0,Ae.useRef)(0);(0,Ae.useEffect)(()=>{ze.current++,yt(null),Re(null)},[n,r]);let[We,nt]=(0,Ae.useState)(null),[Vt,et]=(0,Ae.useState)(!1),[At,bn]=(0,Ae.useState)("project"),[Ve,Be]=(0,Ae.useState)(()=>oc(null,x)),Rt=(0,Ae.useRef)(Ve.key),he=(0,Ae.useRef)(!0);(0,Ae.useEffect)(()=>(he.current=!0,()=>{he.current=!1}),[]);let[Me,xe]=(0,Ae.useState)(!1),Fe=B(M=>M.vectorHealthOpen),ve=B(M=>M.setVectorHealthOpen),[Nt,pt]=(0,Ae.useState)(!1),[kn,yn]=(0,Ae.useState)(!1),[Nn,dn]=(0,Ae.useState)([]),[cr,yr]=(0,Ae.useState)("/"),[dr,Ot]=(0,Ae.useState)(!1),[Dr,fr]=(0,Ae.useState)(null),[jn,oa]=(0,Ae.useState)([]),[Qn,Mn]=(0,Ae.useState)(!1),[Tn,vr]=(0,Ae.useState)([]),[qn,la]=(0,Ae.useState)("local"),[er,hr]=(0,Ae.useState)(null),[fn,wr]=(0,Ae.useState)([]);(0,Ae.useEffect)(()=>{let M=!1;return kx(e).then(ee=>{if(M)return;vr(ee.kinds??[]),hr(null);let T=ee.kinds?.find(pe=>pe.kind==="local")??ee.kinds?.[0]??null;if(T){la(T.kind);let pe=oc(T,x);Rt.current=pe.key,Be(pe)}}).catch(ee=>{M||hr(ee instanceof Error?ee.message:"Failed to load source kinds")}),()=>{M=!0}},[n]);let E=(0,Ae.useMemo)(()=>{let M=new Map;for(let ee of Tn)M.set(ee.kind,ee);return M},[Tn]),ne=E.get(qn)??null,se=s0(ne),_e=iL(ne),D=_e.needed,we=D&&_e.container,$t=(0,Ae.useCallback)(M=>{let ee=oc(E.get(M.suggestedKind)??null,x),T=M.suggestedConfig.root??"",pe=M.suggestedConfig.hostRoot;la(M.suggestedKind),Rt.current=M.suggestedScheme,Be({...ee,key:M.suggestedScheme,path:T,...M.suggestedScope?{scope:M.suggestedScope}:{},...M.syncDisabled?{syncEnabled:!1}:{},...M.suggestedSync?.include?{include:Bf(M.suggestedSync.include)}:{},...M.suggestedSync?.trigger?{trigger:M.suggestedSync.trigger}:{},...M.suggestedPolicies?.length?{policies:M.suggestedPolicies}:{},...M.description?{description:M.description}:{},...M.suggestedAccess??{},config:{...ee.config,...pe&&i0(E.get(M.suggestedKind)??null).properties.hostRoot?{hostRoot:pe}:{}}}),et(!0)},[E,x]);(0,Ae.useEffect)(()=>{o&&E.size!==0&&(l(null),$t(o))},[o,E,$t,l]);let Gt=(0,Ae.useCallback)((M,ee)=>xL({baseName:ee?pE(ee):null,meta:ne,scope:M,ids:x}),[ne,x]),In=M=>M===""||M===Rt.current,Zt=(0,Ae.useCallback)(async()=>{if(r){j(!0),A(null);try{let[M,ee]=await Promise.all([_0({agentId:n,projectId:r,scope:At},e),xc({agentId:n,projectId:r},e).catch(()=>({suggestions:[]}))]);y(M),I(Object.fromEntries(M.map(T=>[T.source,dl(T)]))),v(T=>Object.fromEntries(M.map(pe=>[pe.source,T[pe.source]??!1]))),wr(ee.suggestions??[])}catch(M){A(M instanceof Error?M.message:"Failed to load sources")}finally{j(!1)}}},[At,n,r]);(0,Ae.useEffect)(()=>{s&&Zt()},[s,Zt]),(0,Ae.useEffect)(()=>{s&&n&&u({agentId:n,projectId:r})},[s,n,r,u]);let Ls=(0,Ae.useCallback)(async M=>{if(!n||k[M])return;let ee=!1;if(P(T=>{if(T.has(M))return ee=!0,T;let pe=new Set(T);return pe.add(M),pe}),!ee)try{let T=await B0(n,r??void 0,M,e);T&&O(pe=>({...pe,[M]:T}))}catch{}finally{P(T=>{if(!T.has(M))return T;let pe=new Set(T);return pe.delete(M),pe})}},[n,r,k]),Z=(0,Ae.useCallback)(M=>{O(ee=>{if(!(M in ee))return ee;let T={...ee};return delete T[M],T})},[]),rn=(0,Ae.useCallback)(M=>{v(ee=>{let T=!ee[M];return T&&Ls(M),{...ee,[M]:T}})},[Ls]);(0,Ae.useEffect)(()=>{if(!ge)return;let M=setTimeout(()=>de(null),4e3);return()=>clearTimeout(M)},[ge]),(0,Ae.useEffect)(()=>{!Vt||!a||!g||(Mn(!0),dh({path:"/mounts",agentId:n,...r?{projectId:r}:{}},e).then(M=>{let ee=new Set(b.map(pe=>pe.source)),T=M.entries.filter(pe=>!ee.has(pe.name));oa(T)}).catch(()=>oa([])).finally(()=>Mn(!1)))},[Vt,a,g,n,r,b]);let hn=(0,Ae.useMemo)(()=>{let M=new Set,ee=b.map(T=>{M.add(T.source);let pe=c.find(pn=>Ke(pn.uri_root)===T.source),an=k[T.source]??pe;return{...T,connector_count:an?.on_disk,connector_truncated:an?.truncated,indexed_count:an?.indexed_count,unindexed_count:an?.unindexed,last_updated:pe?.last_updated??T.last_updated,sync_status:T.sync?.status??pe?.sync_status??T.sync_status,live:pe?.live,live_reason:pe?.live_reason,kind_icon:pe?.kind_icon}});if(At==="project")for(let T of c){let pe=Ke(T.uri_root);if(!pe||M.has(pe))continue;let an=E.get(T.source_kind)??null,pn=k[pe]??T;ee.push({...CE(T,an),connector_count:pn.on_disk,connector_truncated:pn.truncated,indexed_count:pn.indexed_count,unindexed_count:pn.unindexed,kind_icon:T.kind_icon})}return ee},[At,b,E,c,k]),ua=(0,Ae.useMemo)(()=>{let M=new Map;for(let ee of hn){let T=fE(ee.origin_package),pe=M.get(T);pe?pe.push(ee):M.set(T,[ee])}return[...M.entries()].sort(([ee],[T])=>ee===a0?1:T===a0?-1:ee.localeCompare(T))},[hn]),U=(M,ee)=>{I(T=>({...T,[M]:ee(T[M])}))},ce=(M,ee)=>{w(T=>({...T,[M]:{...T[M]??{},[ee]:!(T[M]?.[ee]??!1)}}))},Te=async(M,ee)=>{_(M.source),A(null);try{let T=!ee.sync&&!!M.sync,pe=p&&M.connection.kind==="local",{recognizesPackages:an,...pn}=ee,da=await uh({agentId:n,...r?{projectId:r}:{},config:{...pe?ee:pn,...T?{clearSync:!0}:{}}},e);y(ns=>ns.map(rs=>rs.source===da.source?da:rs)),I(ns=>({...ns,[da.source]:dl(da)})),wE(M,ee,T)?(await u({agentId:n,projectId:r,withCounts:!0}),Z(M.source)):await u({agentId:n,projectId:r})}catch(T){A(T instanceof Error?T.message:"Save failed")}finally{_(null)}},zt=(0,Ae.useCallback)(async(M,ee)=>{let T=C[M.source]??dl(M);_(M.source),A(null);try{let pe=await uh({agentId:n,...r?{projectId:r}:{},config:{...T,permissions:ee}},e);y(an=>an.map(pn=>pn.source===pe.source?pe:pn)),I(an=>({...an,[pe.source]:dl(pe)})),await u({agentId:n,projectId:r})}catch(pe){throw A(pe instanceof Error?pe.message:"Save failed"),pe}finally{_(null)}},[n,C,r,u]),wt=(0,Ae.useCallback)(async M=>{for(let pe=0;pe<2400;pe++){if(await new Promise(ts=>setTimeout(ts,1500)),!he.current)return null;let pn=(await U0({agentId:n,...r?{projectId:r}:{},source:M},e)).job;if(!pn)return null;if(!(pn.status==="pending"||pn.status==="running")){if(pn.status==="failed")throw new Error(pn.error??pn.result?.error??"Sync failed");return pn}}return null},[n,r]);if(!s)return null;let Bt=async M=>{re(M),A(null);try{await H0({agentId:n,...r?{projectId:r}:{},source:M},e),await wt(M),await Zt(),await u({agentId:n,projectId:r,withCounts:!0}),Z(M)}catch(ee){A(ee instanceof Error?ee.message:"Sync failed")}finally{re(null)}},Qt=async M=>{try{await vx({agentId:n,...r?{projectId:r}:{},...M?{source:M}:{}},e),re(null),Le(null)}catch(ee){A(ee instanceof Error?ee.message:"Cancel failed")}},ca=async(M,ee,T)=>{Le(M),A(null);try{await ee();let pe=await wt(M),an=pe?.status==="paused"?pe.result?.embedding?.pausedReason??"paused":null;ut(pn=>{let{[M]:ts,...da}=pn;return an?{...da,[M]:an}:da}),await Zt(),await u({agentId:n,projectId:r,withCounts:!0}),Z(M)}catch(pe){A(pe instanceof Error?pe.message:T)}finally{Le(null)}},ao=M=>ca(M,()=>Ic({agentId:n,...r?{projectId:r}:{},source:M},"pending",e),"Embedding failed"),en=M=>ca(M,()=>gx({agentId:n,...r?{projectId:r}:{},source:M},e),"Rescan failed"),w0=async(M,ee)=>{let T=++ze.current,pe=vt==="source"?{kind:"source"}:{kind:vt,uri:Et};Pe(!0),A(null);try{let an=await xx({agentId:n,...r?{projectId:r}:{},source:M,selector:pe,mode:ee,obsoleteOnly:Ye},e);if(T!==ze.current)return;ee==="estimate"?Re(an):(yt(null),Re(null),Z(M),await Zt(),await u({agentId:n,projectId:r,withCounts:!0}))}catch(an){T===ze.current&&A(an instanceof Error?an.message:"Index cleanup failed")}finally{T===ze.current&&Pe(!1)}},P2=async M=>{Xe(M),A(null);try{await mx({agentId:n,...r?{projectId:r}:{},source:M},e),await Zt()}catch(ee){A(ee instanceof Error?ee.message:"Reset failed")}finally{Xe(null)}},R2=async(M,ee)=>{nt(M),A(null);try{await G0({agentId:n,...r?{projectId:r}:{},source:M,enabled:ee},e),await Zt()}catch(T){A(T instanceof Error?T.message:"Toggle failed")}finally{nt(null)}},N2=async(M,ee)=>{q(M),A(null);try{let T=await px({agentId:n,...r?{projectId:r}:{},source:M,...ee.purgeVectors?{purgeVectors:!0}:{}},e);await Zt(),await u({agentId:n,projectId:r}),Z(M),de(ee.purgeVectors&&T?.purgeJob?`Deleted "${M}" (vector purge running in background)`:`Deleted "${M}"`),te(null)}catch(T){A(T instanceof Error?T.message:"Delete failed")}finally{q(null)}},eh=async M=>{yn(!0),Ot(!0),fr(null);try{let ee=await dh({path:M,agentId:n,...r?{projectId:r}:{}},e);dn(ee.entries),yr(M)}catch{fr("That path is not available."),dn([])}finally{Ot(!1)}},k0=M=>{Be(ee=>{if(!In(ee.key))return{...ee,path:M};let T=Gt(ee.scope,M);return Rt.current=T,{...ee,path:M,key:T}}),yn(!1)},M2=async()=>{if(!(!Ve.key||D&&!Ve.path)){xe(!0),A(null);try{let M={...Ve.config,...D?{root:Ve.path}:{}};await hx({agentId:n,...r?{projectId:r}:{},source:Ve.key,scope:Ve.scope,connection:{kind:qn,config:M},permissions:{default:{read:Ve.read,write:Ve.write,exec:Ve.exec},...Ve.policies.length>0?{paths:Ve.policies}:{}},...Ve.description.trim()?{description:Ve.description.trim()}:{},...se&&Ve.syncEnabled?{sync:{exclude:lc(Ve.exclude),trigger:Ve.trigger,...lc(Ve.include).length>0?{include:lc(Ve.include)}:{}}}:{},...p&&qn==="local"&&Ve.recognizesPackages?{recognizesPackages:!0}:{}},e),et(!1);{let ee=oc(ne,x);Rt.current=ee.key,Be(ee)}await Zt(),await u({agentId:n,projectId:r})}catch(M){A(M instanceof Error?M.message:"Add source failed")}finally{xe(!1)}}},T2=M=>M==="data"||M==="packages";return(0,S.jsxs)("div",{className:"w-full px-5 pt-3 pb-6 text-white/85",children:[(0,S.jsxs)("div",{className:"flex items-center justify-between gap-2 pb-2 border-b border-white/[0.06]",children:[(0,S.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,S.jsx)(Sr,{className:"h-4 w-4 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-sm font-semibold tracking-wide text-white/92",children:"Sources"}),(0,S.jsx)("span",{className:"rounded px-1.5 py-0.5 text-[10px] font-medium text-cyan-300 bg-cyan-500/20",children:hn.length})]}),(0,S.jsxs)("div",{className:"flex items-center gap-1",children:[(0,S.jsxs)("div",{className:"inline-flex items-center gap-0.5",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>et(M=>!M),className:"h-7 px-2 rounded-l-md rounded-r-none text-cyan-300 hover:text-cyan-200 hover:bg-white/[0.05] transition inline-flex items-center gap-1 text-[10px] font-medium",title:"Add source",children:[(0,S.jsx)($n,{className:"h-3 w-3"}),"Source"]}),(0,S.jsx)(r0.SkillLauncher,{variant:"icon",attached:"left",skill:"manage-sources",packageId:"@neuralis/brain-core",label:"Manage sources with the agent"})]}),(0,S.jsx)("button",{type:"button",onClick:()=>{Zt()},disabled:N,className:"h-7 w-7 rounded-md text-white/35 hover:text-white/70 hover:bg-white/[0.05] transition",title:"Refresh",children:(0,S.jsx)(Xt,{className:V("mx-auto h-3 w-3",N&&"animate-spin")})}),(0,S.jsx)("button",{type:"button",onClick:()=>i("sources",!1),className:"h-7 px-2.5 rounded-md text-[10px] font-medium text-white/50 hover:text-white/80 hover:bg-white/[0.05] transition",children:"Close"})]})]}),(0,S.jsxs)("div",{className:"mt-2 text-[10px] text-white/35 italic",children:["Add filesystem-style sources from Neuralis packages. A source URI such as ",(0,S.jsx)("code",{className:"font-mono",children:"neuralis://"})," or ",(0,S.jsx)("code",{className:"font-mono",children:"machine-user://"})," is the stable handle agents use with fs_* tools."]}),(0,S.jsx)("div",{className:"mt-2 flex items-center gap-1 rounded-md bg-white/[0.025] p-1",children:[{id:"project",label:"Project"},{id:"user",label:"User"},{id:"agent",label:"Agent"}].map(M=>(0,S.jsx)("button",{type:"button",onClick:()=>bn(M.id),className:V("h-6 rounded px-2 text-[9px] font-semibold transition",At===M.id?"bg-cyan-500/15 text-cyan-200 border border-cyan-400/20":"text-white/35 hover:text-white/65 hover:bg-white/[0.04]"),children:M.label},M.id))}),K&&(0,S.jsx)("div",{className:"mt-2 rounded-md bg-red-500/8 px-3 py-2 text-[10px] text-red-200/80",children:K}),Vt&&(0,S.jsxs)("div",{className:"mt-2 rounded-lg bg-white/[0.03] border border-white/[0.08] p-3 space-y-2",children:[(0,S.jsx)("div",{className:"text-[11px] font-semibold text-white/80",children:"Add Source"}),er&&(0,S.jsxs)("div",{className:"text-[9px] text-rose-300/80 bg-rose-500/10 rounded px-2 py-1",children:["Could not load source kinds: ",er,'. Falling back to "local".']}),Tn.length>1&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Kind"}),(0,S.jsx)("select",{value:qn,onChange:M=>{let ee=M.target.value,T=E.get(ee)??null;la(ee);let pe=oc(T,x);Rt.current=pe.key,Be(pe)},className:Of,children:Tn.map(M=>(0,S.jsxs)("option",{value:M.kind,children:[M.label," \u2014 ",M.trust," (",M.packageId,")"]},M.kind))}),(0,S.jsx)("div",{className:"text-[9px] text-white/30 italic",children:ne?.description??""})]}),ne?.scopeSelectable&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Scope"}),(0,S.jsx)("select",{value:Ve.scope,onChange:M=>{let ee=M.target.value;Be(T=>{if(!In(T.key))return{...T,scope:ee};let pe=Gt(ee,T.path);return Rt.current=pe,{...T,scope:ee,key:pe}})},className:Of,children:gE(ne).map(M=>(0,S.jsx)("option",{value:M,children:M},M))})]}),we&&a?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)("div",{className:"text-[10px] text-amber-300/70 bg-amber-500/8 rounded px-2 py-1.5",children:["Docker mode: host folders still need the CLI mount script:"," ",(0,S.jsx)("code",{className:"text-amber-200/90 font-mono",children:"neuralis mount add"})," ","on the host, then restart the container. Package sources like Machine do not require a host path here."]}),Qn?(0,S.jsxs)("div",{className:"flex items-center gap-1.5 py-1",children:[(0,S.jsx)($e,{className:"h-3 w-3 animate-spin text-white/30"}),(0,S.jsx)("span",{className:"text-[9px] text-white/35",children:"Scanning volume mounts..."})]}):jn.length>0?(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Available volume mounts (not yet configured)"}),jn.map(M=>(0,S.jsxs)("div",{className:"flex items-center gap-2 rounded px-2 py-1.5 bg-white/[0.02] hover:bg-white/[0.04] transition",children:[(0,S.jsx)($r,{className:"h-3 w-3 text-cyan-400/70 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] text-white/75 font-medium flex-1 truncate",children:M.name}),(0,S.jsx)("span",{className:"text-[9px] text-white/30 font-mono truncate max-w-[120px]",children:M.path}),(0,S.jsx)("button",{type:"button",onClick:()=>{Be(ee=>({...ee,key:M.name,path:M.path}))},className:"px-2 py-0.5 rounded text-[8px] font-semibold text-cyan-300/80 bg-cyan-500/10 hover:bg-cyan-500/20 border border-cyan-400/20 transition shrink-0",children:"+ Add"})]},M.path))]}):(0,S.jsx)("div",{className:"text-[9px] text-white/30 italic",children:"All volume mounts are configured as sources."})]}):(0,S.jsx)("div",{className:"text-[10px] text-white/35 italic",children:D?_e.container?"Mount any folder from your system. The path must be accessible to the server process.":"A path on the operator\u2019s host machine, reached through the host broker. It needs no volume mount here, and the broker ceiling still clamps what is reachable.":"This connector does not need a local path. Choose the scope and URI scheme; the package owns the runtime binding."}),(0,S.jsxs)("div",{className:"space-y-2",children:[(0,S.jsxs)("div",{className:V("grid gap-2",D?"grid-cols-2":"grid-cols-1"),children:[(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"URI scheme"}),(0,S.jsx)("input",{type:"text",value:Ve.key,onChange:M=>Be(ee=>({...ee,key:M.target.value})),placeholder:Gt(Ve.scope,Ve.path),className:no}),(0,S.jsxs)("div",{className:"text-[8px] text-white/25 font-mono",children:[Ve.key||Gt(Ve.scope,Ve.path),"://"]})]}),D&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:_e.label}),(0,S.jsxs)("div",{className:"flex gap-1",children:[(0,S.jsx)("input",{type:"text",value:Ve.path,onChange:M=>Be(ee=>({...ee,path:M.target.value})),placeholder:_e.placeholder,className:V(no,"flex-1")}),_e.container&&!a&&g&&(0,S.jsx)("button",{type:"button",onClick:()=>{eh(Ve.path||"/")},className:"h-7 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] border border-white/[0.08] text-white/60 hover:text-white/90 transition shrink-0",title:"Browse directories",children:(0,S.jsx)(Hs,{className:"h-3.5 w-3.5"})})]})]})]}),Object.entries(i0(ne).properties).filter(([M])=>M!=="root").map(([M,ee])=>(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:ee?.["x-neuralis"]?.ui?.label??M}),(0,S.jsx)("input",{type:ee.type==="number"||ee.type==="integer"?"number":"text",value:String(Ve.config[M]??""),onChange:T=>Be(pe=>({...pe,config:{...pe.config,[M]:T.target.value}})),placeholder:ee?.["x-neuralis"]?.ui?.placeholder??ee?.description??M,className:no})]},M)),we&&!a&&kn&&(0,S.jsxs)("div",{className:"rounded-md bg-white/[0.03] border border-white/[0.1] overflow-hidden",children:[(0,S.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5 bg-white/[0.02] border-b border-white/[0.06]",children:[(0,S.jsx)(Hs,{className:"h-3 w-3 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[9px] font-mono text-white/60 truncate flex-1",children:cr}),(0,S.jsx)("button",{type:"button",onClick:()=>yn(!1),className:"text-[9px] text-white/40 hover:text-white/70 px-1",children:"Close"})]}),Dr&&(0,S.jsx)("div",{className:"px-2 py-1 text-[9px] text-red-300/80",children:Dr}),dr?(0,S.jsx)("div",{className:"flex items-center justify-center py-3",children:(0,S.jsx)($e,{className:"h-3 w-3 animate-spin text-white/30"})}):(0,S.jsxs)("div",{className:"max-h-[180px] overflow-y-auto",children:[cr!=="/"&&(0,S.jsxs)("button",{type:"button",onClick:()=>{let M=cr.replace(/[/\\][^/\\]+$/,"")||"/";eh(M)},className:"w-full flex items-center gap-1.5 px-2 py-1 text-left hover:bg-white/[0.04] transition",children:[(0,S.jsx)(ss,{className:"h-3 w-3 text-white/30"}),(0,S.jsx)("span",{className:"text-[10px] text-white/50",children:".."})]}),Nn.length===0&&!dr&&(0,S.jsx)("div",{className:"px-2 py-2 text-[9px] text-white/30 italic",children:"No subdirectories"}),Nn.map(M=>(0,S.jsxs)("div",{className:"flex items-center gap-0.5 hover:bg-white/[0.04] transition",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>{eh(M.path)},className:"flex items-center gap-1.5 px-2 py-1 flex-1 text-left min-w-0",children:[(0,S.jsx)($r,{className:"h-3 w-3 text-cyan-400/70 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] text-white/75 truncate",children:M.name})]}),(0,S.jsx)("button",{type:"button",onClick:()=>k0(M.path),className:"px-2 py-1 text-[8px] font-medium text-cyan-300/70 hover:text-cyan-200 shrink-0",children:"Select"})]},M.path)),(0,S.jsxs)("button",{type:"button",onClick:()=>k0(cr),className:"w-full flex items-center gap-1.5 px-2 py-1.5 text-left bg-cyan-500/5 hover:bg-cyan-500/10 border-t border-white/[0.06] transition",children:[(0,S.jsx)(ha,{className:"h-3 w-3 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] font-medium text-cyan-300/80",children:"Select this folder"}),(0,S.jsx)("span",{className:"text-[9px] text-white/30 font-mono truncate ml-auto",children:cr})]})]})]})]}),(0,S.jsxs)("div",{className:"flex items-center gap-2",children:[(0,S.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35 w-16 shrink-0",children:"Access"}),[{key:"read",label:"Read",icon:Bl},{key:"write",label:"Write",icon:yi},{key:"exec",label:"Exec",icon:wo}].map(({key:M,label:ee,icon:T})=>(0,S.jsxs)("label",{className:V("inline-flex items-center gap-1 rounded px-2 py-1 text-[9px] cursor-pointer transition",Ve[M]?"bg-white/[0.06] text-white/85":"bg-white/[0.02] text-white/40"),children:[(0,S.jsx)("input",{type:"checkbox",className:"sr-only",checked:Ve[M],onChange:pe=>Be(an=>({...an,[M]:pe.target.checked}))}),(0,S.jsx)(T,{className:"h-2.5 w-2.5"}),ee,(0,S.jsx)("span",{className:V("h-1.5 w-1.5 rounded-full",Ve[M]?"bg-emerald-300/80":"bg-white/20")})]},M))]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsxs)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:["Description ",(0,S.jsx)("span",{className:"text-white/20 normal-case font-normal",children:"(optional \u2014 shown to the agent)"})]}),(0,S.jsx)("input",{value:Ve.description,onChange:M=>Be(ee=>({...ee,description:M.target.value})),className:no,placeholder:ne?.description??"What this source is for\u2026",maxLength:200})]}),se&&(0,S.jsx)("div",{className:"flex items-center gap-2",children:(0,S.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:Ve.syncEnabled,onChange:M=>Be(ee=>({...ee,syncEnabled:M.target.checked})),className:"accent-emerald-400 h-3 w-3"}),"Enable sync"]})}),se&&Ve.syncEnabled&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Exclude patterns"}),(0,S.jsx)("textarea",{value:Ve.exclude,onChange:M=>Be(ee=>({...ee,exclude:M.target.value})),rows:2,className:uc,placeholder:"node_modules/**"})]}),se&&Ve.syncEnabled&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Include (allowlist)"}),(0,S.jsx)("textarea",{value:Ve.include,onChange:M=>Be(ee=>({...ee,include:M.target.value})),rows:2,className:V(uc,"font-mono"),placeholder:`# empty = everything
|
|
46
|
+
skills/**`}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Non-empty: only matching files sync. Excludes always win \u2014 an excluded path can never be re-included. This narrows the INDEX, not what the agent can read: the source root does that."})]}),qn==="local"&&p&&(0,S.jsx)("div",{className:"space-y-1",children:(0,S.jsxs)("label",{className:"inline-flex items-start gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:Ve.recognizesPackages,onChange:M=>Be(ee=>({...ee,recognizesPackages:M.target.checked})),className:"accent-emerald-400 h-3 w-3 mt-0.5"}),(0,S.jsxs)("span",{children:["Recognize packages",(0,S.jsxs)("span",{className:"block text-[9px] text-white/35 normal-case font-normal",children:["Load packages found in this folder (in addition to ",(0,S.jsx)("code",{children:"_packages/"}),") as soon as the source is added. Advertised only within this source's scope."]})]})]})}),(0,S.jsxs)("div",{className:"flex items-center gap-1.5 pt-1",children:[(0,S.jsx)("button",{type:"button",onClick:()=>et(!1),className:"h-6 px-2.5 rounded-md text-[9px] font-medium text-white/50 hover:text-white/80 hover:bg-white/[0.05] transition",children:"Cancel"}),(0,S.jsxs)("button",{type:"button",onClick:()=>{M2()},disabled:Me||!Ve.key||D&&!Ve.path,className:"h-6 px-2.5 rounded-md bg-cyan-500/12 border border-cyan-400/25 text-[9px] font-semibold text-cyan-200/90 hover:bg-cyan-500/20 transition disabled:opacity-35 inline-flex items-center gap-1",children:[Me?(0,S.jsx)($e,{className:"h-2.5 w-2.5 animate-spin"}):(0,S.jsx)($n,{className:"h-2.5 w-2.5"}),"Create source"]})]})]}),hn.length===0&&!N?(0,S.jsx)("div",{className:"mt-3 text-[10px] text-white/40",children:"No sources configured."}):null,(0,S.jsx)("div",{className:"mt-1 space-y-3",children:ua.map(([M,ee])=>(0,S.jsxs)("div",{children:[(0,S.jsxs)("div",{className:"-ml-0.5 mb-0.5 flex items-center gap-1.5 px-1",children:[(0,S.jsx)(Br,{className:"h-3 w-3 shrink-0 text-white/30"}),(0,S.jsx)("span",{className:"truncate font-mono text-[10px] font-medium text-white/40",children:M}),(0,S.jsx)("span",{className:"text-[9px] tabular-nums text-white/25",children:ee.length})]}),(0,S.jsx)("div",{className:"space-y-0.5 pl-2",children:ee.map(T=>{let pe=C[T.source]??dl(T),an=F===T.source,pn=X===T.source,ts=ae===T.source,da=ye===T.source,ns=E.get(T.connection.kind)??null,rs=s0(ns),gc=rs&&!!pe.sync,tr=pe.sync??t0,S0=(0,Ir.resolveIconWithFallback)(T.kind_icon??ns?.icon??void 0,rr),C0=Bc(T),I0=T.live===!1,D2=I0||T.enabled===!1||T.enabled==="auto"&&T.enabled_effective===!1,th=!!L[T.source],As=!T.observed,nh=As&&IE(T,pe),qr=yL(tr.trigger),ci=H[T.source]??{};return(0,S.jsxs)("div",{className:"rounded-sm",children:[(0,S.jsxs)("div",{className:"w-full flex items-center gap-2 py-2 text-left group hover:bg-white/[0.02] rounded-md px-1 transition",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>rn(T.source),"aria-expanded":th,title:I0?Mh(T.live_reason):void 0,className:"min-w-0 flex-1 flex items-center gap-2 text-left",children:[T.git?.isRepo?(0,S.jsxs)("span",{className:"relative inline-flex shrink-0 items-center justify-center",children:[(0,S.jsx)(S0,{className:V("h-4 w-4",C0.iconClassName)}),(0,S.jsx)(Bn,{className:"absolute -right-1.5 -top-1.5 h-2.5 w-2.5 rounded-full bg-black/80 p-[1px] text-violet-300/90"})]}):(0,S.jsx)(S0,{className:V("h-4 w-4 shrink-0",C0.iconClassName)}),(0,S.jsx)("span",{className:V("min-w-0 flex-1 truncate text-[12.5px] font-semibold",D2?"text-white/45":"text-white/90"),children:T.source}),T.git?.isRepo&&T.git.branch?(0,S.jsxs)("span",{className:"inline-flex max-w-[96px] shrink-0 items-center gap-0.5 text-[10px] text-violet-300/70",title:`Git branch: ${T.git.branch}`,children:[(0,S.jsx)(Bn,{className:"h-2.5 w-2.5 shrink-0"}),(0,S.jsx)("span",{className:"truncate",children:T.git.branch})]}):null,T.observed&&(0,S.jsx)("span",{className:"shrink-0 rounded px-1 py-0.5 text-[8px] font-medium text-orange-200/90 bg-orange-500/5 ring-1 ring-orange-300/30",children:"observed"}),T.orphan&&(0,S.jsx)("span",{className:"shrink-0 rounded px-1 py-0.5 text-[8px] font-medium text-rose-300/80 bg-rose-500/15",title:T.orphan_hint??"Package missing",children:"orphan"}),nh&&(0,S.jsx)("span",{className:"shrink-0 rounded px-1 py-0.5 text-[8px] font-medium text-amber-300/80 bg-amber-500/10",children:"unsaved"})]}),(()=>{let Ge=T.enabled??!0,Kt=T.enabled_effective??Ge===!0,pr=(ns?.kind??T.connection.kind)==="webtop",di=We===T.source,F2=()=>pr?Ge===!0?!1:Ge===!1?"auto":!0:Ge===!1,L0=Ge==="auto"?`Auto \xB7 ${Kt?"Live":"Stopped"}`:Ge===!1?"Off":"On",E2=Ge===!1?"text-rose-300/85 bg-rose-500/10 border-rose-400/25":Ge==="auto"?"text-amber-200/85 bg-amber-500/10 border-amber-400/25":"text-emerald-300/85 bg-emerald-500/10 border-emerald-400/25";return(0,S.jsx)("button",{type:"button",title:`Source ${L0} \u2014 click to cycle`,onClick:O2=>{O2.stopPropagation(),!di&&R2(T.source,F2())},disabled:di||!!T.observed,className:V("shrink-0 rounded px-1 py-0.5 text-[8px] font-semibold border transition disabled:opacity-50",E2),children:di?"\u2026":L0})})(),(0,S.jsx)("span",{className:"text-[9px] text-white/30 truncate max-w-[140px] hidden sm:inline",children:SE(T,ns)}),(0,S.jsx)(qt,{className:V("h-3 w-3 text-white/25 shrink-0 transition-transform",th&&"rotate-180")})]}),(0,S.jsx)("div",{className:V("transition-all duration-200",th?"opacity-100":"max-h-0 opacity-0 overflow-hidden"),children:(0,S.jsxs)("div",{className:"rounded-md bg-white/[0.02] p-3 ml-5 mb-1 space-y-2.5",children:[(0,S.jsxs)("div",{className:"flex items-center gap-3 text-[9px] text-white/40",children:[R.has(T.source)&&typeof T.indexed_count!="number"&&(0,S.jsx)("span",{className:"text-white/30",children:"Loading counts\u2026"}),typeof T.connector_count=="number"&&(0,S.jsxs)("span",{children:[(0,S.jsxs)("span",{className:"text-white/60 tabular-nums",children:[T.connector_count,T.connector_truncated?"+":""]})," connector"]}),typeof T.indexed_count=="number"&&(0,S.jsxs)("span",{children:[(0,S.jsx)("span",{className:"text-cyan-300/70 tabular-nums",children:T.indexed_count})," indexed"]}),typeof T.unindexed_count=="number"&&T.unindexed_count>0&&(0,S.jsxs)("span",{children:[(0,S.jsx)("span",{className:"text-amber-300/70 tabular-nums",children:T.unindexed_count})," unindexed"]}),rs&&T.sync?.lastSync&&(0,S.jsxs)("span",{children:["Last sync: ",gL(T.sync.lastSync)]}),T.updatedAt&&(0,S.jsxs)("span",{children:["Updated: ",gL(T.updatedAt)]})]}),rs&&!T.sync?.lastSync?(0,S.jsx)("div",{className:"rounded-md border border-sky-300/15 bg-sky-500/5 px-2 py-1.5 text-[10px] text-sky-100/70",children:"Never synced \u2014 run a sync to index this source and load its packages (skills, rules, instructions) for agents."}):null,T.observed?(0,S.jsx)("div",{className:"rounded-md border border-orange-300/15 bg-orange-500/5 px-2 py-1.5 text-[10px] text-orange-100/70",children:"Runtime-observed source. Create a source config to edit permissions, sync, or persistence settings."}):null,(0,S.jsxs)("div",{children:[(0,S.jsxs)("button",{type:"button",onClick:()=>ce(T.source,"description"),className:"flex items-center gap-1.5 py-1 w-full text-left",children:[(0,S.jsx)(Da,{className:"h-3 w-3 text-violet-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] font-semibold text-white/70 flex-1",children:"Description"}),!ci.description&&((pe.description??"").trim()||T.description_effective)&&(0,S.jsx)("span",{className:V("text-[9px] truncate max-w-[200px]",(pe.description??"").trim()?"text-white/35":"text-white/25 italic"),children:(pe.description??"").trim()||`${T.description_effective} (from the package)`}),(0,S.jsx)(Sn,{className:V("h-2.5 w-2.5 text-white/25 transition-transform",ci.description&&"rotate-90")})]}),ci.description&&(0,S.jsxs)("div",{className:"pl-5 pt-1 space-y-1",children:[(0,S.jsx)("div",{className:"text-[10px] text-white/35 italic",children:"A one-line summary shown to the agent in its runtime source list."}),As?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("textarea",{value:pe.description??"",onChange:Ge=>U(T.source,Kt=>({...Kt,description:Ge.target.value})),rows:2,className:uc,placeholder:T.description_effective??"What this source is for\u2026",maxLength:200}),!(pe.description??"").trim()&&T.description_effective&&(0,S.jsx)("div",{className:"text-[9px] text-white/25 italic",children:"Shown above from the package. Leave this empty to keep following it."})]}):(0,S.jsx)("div",{className:"text-[10px] text-white/70",children:(pe.description??"").trim()||(T.description_effective?(0,S.jsxs)("span",{className:"text-white/40 italic",children:[T.description_effective," ",(0,S.jsx)("span",{className:"text-white/25 not-italic",children:"(from the package)"})]}):(0,S.jsx)("span",{className:"text-white/30 italic",children:"No description"}))})]})]}),As&&p&&(ns?.kind??T.connection.kind)==="local"&&(0,S.jsx)("div",{className:"pl-0",children:(0,S.jsxs)("label",{className:"flex items-start gap-1.5 py-1 cursor-pointer",children:[(0,S.jsx)(Br,{className:"h-3 w-3 text-cyan-400 shrink-0 mt-0.5"}),(0,S.jsx)("input",{type:"checkbox",checked:pe.recognizesPackages??!1,onChange:Ge=>U(T.source,Kt=>({...Kt,recognizesPackages:Ge.target.checked})),className:"accent-cyan-400 h-3 w-3 mt-0.5"}),(0,S.jsxs)("span",{className:"text-[10px] text-white/70 leading-tight",children:["Recognize packages",(0,S.jsxs)("span",{className:"block text-[9px] text-white/35 normal-case font-normal",children:["Load packages found in this folder (in addition to ",(0,S.jsx)("code",{children:"_packages/"}),") \u2014 applied on save; advertised only within this source's scope."]})]})]})}),(0,S.jsxs)("div",{children:[(0,S.jsxs)("div",{className:"flex items-center gap-1.5 py-1",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>ce(T.source,"perms"),className:"flex items-center gap-1.5 flex-1 text-left",children:[(0,S.jsx)(zs,{className:"h-3 w-3 text-emerald-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] font-semibold text-white/70 flex-1",children:"Permissions"}),(0,S.jsx)(Sn,{className:V("h-2.5 w-2.5 text-white/25 transition-transform",ci.perms&&"rotate-90")})]}),(0,S.jsx)(r0.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-uri-policy",packageId:"@neuralis/brain-core",label:`Edit URI policy for "${T.source}" with the agent`,icon:"shield"})]}),ci.perms&&(0,S.jsx)("div",{className:"pl-5 pt-1",children:(0,S.jsx)(e0,{source:T.source,permissions:T.permissions,mode:As?"edit":"view",onSave:As?Ge=>zt(T,Ge):void 0})})]}),rs&&(0,S.jsxs)("div",{children:[(0,S.jsxs)("button",{type:"button",onClick:()=>ce(T.source,"sync"),className:"flex items-center gap-1.5 py-1 w-full text-left",children:[(0,S.jsx)(Xt,{className:"h-3 w-3 text-blue-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] font-semibold text-white/70 flex-1",children:"Sync"}),gc&&(0,S.jsx)("span",{className:"text-[9px] text-white/35",children:kE(tr.trigger)}),(0,S.jsx)(Sn,{className:V("h-2.5 w-2.5 text-white/25 transition-transform",ci.sync&&"rotate-90")})]}),ci.sync&&(0,S.jsxs)("div",{className:"pl-5 space-y-2 pt-1",children:[(0,S.jsx)("div",{className:"text-[10px] text-white/35 italic",children:"Sync indexes files for AI search. Excluded patterns (logs/, node_modules/) are skipped automatically."}),(0,S.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:gc,onChange:Ge=>U(T.source,Kt=>({...Kt,...Ge.target.checked?{sync:{...t0,exclude:[...T.defaultSyncExclude??t0.exclude]}}:{sync:void 0}})),className:"accent-emerald-400 h-3 w-3"}),"Enable sync"]}),gc&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsxs)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35 flex items-center gap-1",children:[(0,S.jsx)(Ta,{className:"h-2.5 w-2.5 text-cyan-300/60"})," Trigger"]}),(0,S.jsx)("select",{value:qr.mode,onChange:Ge=>{let Kt=Ge.target.value;U(T.source,pr=>({...pr,sync:{...tr,trigger:n0(Kt,qr.val,qr.unit)}}))},className:Of,children:cE.map(Ge=>(0,S.jsx)("option",{value:Ge.value,children:Ge.label},Ge.value))}),qr.mode==="interval"&&(0,S.jsxs)("div",{className:"flex gap-1",children:[(0,S.jsx)("input",{type:"number",min:_f(qr.unit),value:qr.val,onChange:Ge=>{let Kt=Ge.target.value.replace(/\D/g,"")||String(_f(qr.unit));U(T.source,pr=>({...pr,sync:{...tr,trigger:n0("interval",Kt,qr.unit)}}))},className:V(no,"w-16")}),(0,S.jsx)("select",{value:qr.unit,onChange:Ge=>{let Kt=Ge.target.value,pr=String(Math.max(Number.parseInt(qr.val,10)||1,_f(Kt)));U(T.source,di=>({...di,sync:{...tr,trigger:n0("interval",pr,Kt)}}))},className:V(Of,"flex-1"),children:dE.map(Ge=>(0,S.jsx)("option",{value:Ge.value,children:Ge.label},Ge.value))})]}),(0,S.jsx)("div",{className:"text-[8px] text-white/35 italic leading-relaxed",children:qr.mode==="manual"?"Manual: nothing triggers it automatically \u2014 indexes only when you click Sync below.":qr.mode==="auto"?"Auto: re-indexes on file changes (host edits, git, shell \u2014 anything) + a periodic full reconcile.":"Scheduled: runs a full reconcile every interval above."})]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Exclude"}),(0,S.jsx)("textarea",{value:Bf(tr.exclude),onChange:Ge=>{let Kt=lc(Ge.target.value);U(T.source,pr=>({...pr,sync:{...tr,exclude:Kt}}))},rows:5,className:V(uc,"font-mono"),placeholder:`# .gitignore syntax
|
|
47
47
|
node_modules/**
|
|
48
48
|
.git/**
|
|
49
|
-
dist/**`}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Uses .gitignore syntax. Lines starting with # are comments."})]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Include (allowlist)"}),(0,S.jsx)("textarea",{value:
|
|
49
|
+
dist/**`}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Uses .gitignore syntax. Lines starting with # are comments."})]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Include (allowlist)"}),(0,S.jsx)("textarea",{value:Bf(tr.include??[]),onChange:Ge=>{let Kt=lc(Ge.target.value);U(T.source,pr=>({...pr,sync:{...tr,...Kt.length>0?{include:Kt}:{include:void 0}}}))},rows:3,className:V(uc,"font-mono"),placeholder:`# empty = everything
|
|
50
50
|
docs/**
|
|
51
|
-
packages/*/skills/**`}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Non-empty: only matching files sync. Excludes always win \u2014 an excluded path can never be re-included."})]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Max scan files"}),(0,S.jsx)("input",{type:"number",min:1,step:1e3,value:Gn.maxScanFiles??"",onChange:Fe=>{let Bt=Number(Fe.target.value),Zn=Number.isFinite(Bt)&&Bt>0?Math.floor(Bt):void 0;Yr(O.source,Js=>({...Js,sync:{...Gn,maxScanFiles:Zn}}))},className:$(Wi,"w-28 font-mono"),placeholder:"200000"}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Per-source cap on files walked during sync/count. Empty = inherit the platform default. When a walk hits the cap the count shows N+."})]}),(0,S.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:Gn.alwaysActive??(O.source==="data"||O.source==="packages"),onChange:Fe=>Yr(O.source,Bt=>({...Bt,sync:{...Gn,alwaysActive:Fe.target.checked}})),className:"accent-cyan-400 h-3 w-3"}),"Always active",(0,S.jsx)("span",{className:"text-[8px] text-white/30 normal-case",children:'(pins this source in the auto-sync pool even when the platform Auto-Sync Mode is "packages-only"; no effect with the Manual trigger)'})]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Media"}),(0,S.jsx)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:bE.map(Fe=>(0,S.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:Gn.media?.[Fe.key]??Fe.on,onChange:Bt=>Yr(O.source,Zn=>({...Zn,sync:{...Gn,media:{...Gn.media??{},[Fe.key]:Bt.target.checked}}})),className:"accent-cyan-400 h-3 w-3"}),Fe.label]},Fe.key))}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Embeds these files from their bytes \u2014 only while the active embedding model is multimodal (a text-only model skips them and the last-sync line says so). Each image or PDF page is one provider call; video and audio cost the most. Unticking a kind clears its searchable cache at the next full sync while preserving recovery content."})]}),O.sync?.lastSyncResult&&(0,S.jsxs)("div",{className:"text-[9px] text-white/40 flex items-center gap-2",children:[(0,S.jsxs)("span",{children:["Last sync: +",O.sync.lastSyncResult.filesAdded," -",O.sync.lastSyncResult.filesRemoved," ~",O.sync.lastSyncResult.filesUpdated]}),(0,S.jsxs)("span",{children:["(",(O.sync.lastSyncResult.durationMs/1e3).toFixed(1),"s)"]}),O.sync.lastSyncResult.error&&(0,S.jsx)("span",{className:"text-rose-300/80 truncate max-w-[200px]",title:O.sync.lastSyncResult.error,children:"err"})]}),sL(O.sync?.lastSyncResult?.mediaSkipped)&&(0,S.jsx)("div",{className:"text-[9px] text-amber-200/70",role:"status",children:sL(O.sync?.lastSyncResult?.mediaSkipped)}),iL(O.sync?.lastSyncResult?.binarySkipped)&&(0,S.jsx)("div",{className:"text-[9px] text-white/40",role:"status",children:iL(O.sync?.lastSyncResult?.binarySkipped)}),(()=>{let Fe=wE(O.sync?.lastSyncResult?.embeddingDegraded,O.embedding_enabled);return Fe?(0,S.jsx)("div",{className:Fe.attention?"text-[9px] text-amber-200/70":"text-[9px] text-white/40",role:"status",children:Fe.text}):null})(),Le[O.source]&&(0,S.jsxs)("div",{className:"text-[9px] text-amber-200/70 flex items-center gap-2",role:"status",children:[(0,S.jsxs)("span",{children:["Embedding paused: ",Le[O.source]]}),(0,S.jsx)("button",{type:"button",disabled:Wa,onClick:()=>{L2(O.source)},className:"h-5 px-1.5 rounded bg-white/[0.04] hover:bg-white/[0.08] text-amber-200/90 disabled:opacity-35",children:"Resume"})]})]})]})]}),(0,S.jsxs)("div",{className:"flex items-center justify-between gap-2 pt-1.5 border-t border-white/[0.06]",children:[(0,S.jsx)("span",{className:"text-[9px] text-white/30",children:O.observed?"Observed runtime source":Vf?"Unsaved changes":"No pending changes"}),(0,S.jsxs)("div",{className:"flex items-center gap-1.5",children:[hs&&ja&&(Qt||Wa)?(0,S.jsxs)("button",{type:"button",onClick:()=>{I2(O.source)},className:"h-6 px-2 rounded-md bg-rose-500/10 hover:bg-rose-500/20 border border-rose-400/25 text-[9px] font-medium text-rose-300/80 hover:text-rose-200 transition inline-flex items-center gap-1",children:[(0,S.jsx)(Ul,{className:"h-2.5 w-2.5"}),"Cancel"]}):hs&&ja?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)("button",{type:"button",disabled:!sc,onClick:()=>{C2(O.source)},className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-blue-300/80 hover:text-blue-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,S.jsx)(El,{className:"h-2.5 w-2.5"}),"Sync"]}),(0,S.jsxs)("button",{type:"button",disabled:Wa,onClick:()=>{A2(O.source)},className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-cyan-300/80 hover:text-cyan-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,S.jsx)(ir,{className:"h-2.5 w-2.5"}),"Rescan changes"]}),(0,S.jsxs)("button",{type:"button",disabled:Wa||O.embedding_enabled===!1,onClick:()=>Qe(O.source),title:O.embedding_enabled===!1?"Semantic embedding is off \u2014 turn it on in the platform settings first":"Embed every file of this source again with the active model \u2014 shows the estimated cost first",className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-cyan-300/80 hover:text-cyan-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,S.jsx)(ka,{className:"h-2.5 w-2.5"}),"Re-embed\u2026"]}),(()=>{let Fe=O.embedding_enabled===!1;return(0,S.jsxs)("button",{type:"button",disabled:Wa||Fe,onClick:()=>Lt(O.source),title:Fe?"Semantic embedding is off \u2014 turn it on in the platform settings first":"Embed only the files whose semantic embedding is missing or stale \u2014 shows the estimate first",className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-cyan-300/80 hover:text-cyan-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,S.jsx)(ir,{className:"h-2.5 w-2.5"}),"Embed pending\u2026"]})})(),(0,S.jsxs)("button",{type:"button",disabled:ze===O.source,onClick:()=>{P2(O.source)},title:"Forgets what the last sync saw \u2014 the next sync compares every file again. Deletes no file and no vector.",className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-amber-300/80 hover:text-amber-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[ze===O.source?(0,S.jsx)(We,{className:"h-2.5 w-2.5 animate-spin"}):(0,S.jsx)(oi,{className:"h-2.5 w-2.5"}),"Forget sync state"]})]}):null,O.canMaintain===!0&&(0,S.jsx)("button",{type:"button",onClick:()=>{Te.current++,bt(O.source),Tt("source"),me(""),Jt(!0),be(null),Re(!1)},className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] text-amber-300/80",children:"Clean index\u2026"}),hs&&!T2(O.source)&&(0,S.jsxs)("button",{type:"button",disabled:Jr,onClick:()=>he(O.source),className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-red-300/80 hover:text-red-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[Jr?(0,S.jsx)(We,{className:"h-2.5 w-2.5 animate-spin"}):(0,S.jsx)(Nt,{className:"h-2.5 w-2.5"}),"Delete"]}),(0,S.jsxs)("button",{type:"button",disabled:qt||!Vf,onClick:()=>{k2(O,ge)},className:"h-6 px-2.5 rounded-md bg-emerald-500/12 border border-emerald-400/25 text-[9px] font-semibold text-emerald-200/90 hover:bg-emerald-500/20 transition disabled:opacity-35 inline-flex items-center gap-1",children:[qt?(0,S.jsx)(We,{className:"h-2.5 w-2.5 animate-spin"}):(0,S.jsx)(li,{className:"h-2.5 w-2.5"}),"Save"]})]})]})]})}),ft===O.source&&O.canMaintain===!0&&(0,S.jsxs)("fieldset",{disabled:Ge,className:"ml-5 mb-2 rounded-md border border-amber-400/20 p-3 space-y-2 text-[10px] text-white/70",children:[(0,S.jsxs)("legend",{children:["Clean index for ",O.source]}),(0,S.jsx)("p",{children:"The source, files, pending changes and recovery history stay available. Cleanup makes no embedding calls."}),(0,S.jsxs)("label",{children:["Selection ",(0,S.jsxs)("select",{"aria-label":"Index cleanup selection",value:At,onChange:Fe=>{Te.current++,Tt(Fe.target.value),be(null)},className:"bg-[#15151d]",children:[(0,S.jsx)("option",{value:"source",children:"Whole source"}),(0,S.jsx)("option",{value:"folder",children:"Folder"}),(0,S.jsx)("option",{value:"file",children:"File"})]})]}),At!=="source"&&(0,S.jsx)("input",{"aria-label":"Index cleanup URI",placeholder:`${O.source}://path`,value:Ue,onChange:Fe=>{Te.current++,me(Fe.target.value),be(null)},className:"block w-full bg-white/5 rounded px-2 py-1"}),(0,S.jsxs)("label",{className:"block",children:[(0,S.jsx)("input",{type:"checkbox",checked:Ot,onChange:Fe=>{Te.current++,Jt(Fe.target.checked),be(null)}})," Only excluded files and disabled media lanes"]}),!Ot&&(0,S.jsx)("p",{children:"All selected searchable cache will be cleared. A later sync can rebuild it."}),ue&&(0,S.jsxs)("p",{children:[ue.removedParents," parents removed \xB7 ",ue.removedChunks," chunks removed \xB7 ",ue.retained," recovery payloads retained \xB7 ",ue.unresolved," unresolved points kept"]}),(0,S.jsxs)("div",{className:"flex gap-2",children:[(0,S.jsx)("button",{type:"button",onClick:()=>{Te.current++,bt(null),be(null)},children:"Cancel"}),(0,S.jsx)("button",{type:"button",onClick:()=>{d0(O.source,"estimate")},children:Ge?"Working\u2026":"Preview counts"}),ue?.canMaintain&&(0,S.jsx)("button",{type:"button",onClick:()=>{d0(O.source,"apply")},children:"Confirm cleanup"})]})]}),re===O.source&&(0,S.jsx)(aL,{source:O.source,vectorCount:typeof O.indexed_count=="number"?O.indexed_count:null,isDockerMount:!!O.connection?.config?.hostRoot,busy:Jr,onCancel:()=>he(null),onConfirm:Fe=>{R2(O.source,Fe)}}),Ye===O.source&&(0,S.jsx)(Xl,{kind:"pending",agentId:n,...r?{projectId:r}:{},target:{source:O.source,label:O.source},onClose:()=>Lt(null),onStarted:()=>{ac(O.source,()=>Promise.resolve(),"Embedding failed")}}),it===O.source&&(0,S.jsx)(Xl,{agentId:n,...r?{projectId:r}:{},target:{source:O.source,label:O.source},onClose:()=>Qe(null),onStarted:()=>{ac(O.source,()=>Promise.resolve(),"Re-embed failed")}})]},px(sr(O.source)))})})]},E))}),Ne&&(0,S.jsx)("div",{className:"mt-2 rounded-md bg-emerald-500/10 border border-emerald-400/25 px-2.5 py-1.5 text-[10px] text-emerald-200/85",children:Ne}),(0,S.jsxs)("div",{className:"border-t border-white/[0.06] pt-2 mt-3",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>Pt(!ce),className:"flex items-center gap-2 py-1.5 w-full text-left",children:[(0,S.jsx)(ir,{className:"h-4 w-4 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-sm font-semibold text-white/92 flex-1",children:"Vector Health"}),(0,S.jsx)(Et,{className:$("h-3 w-3 text-white/25 transition-transform",ce&&"rotate-180")})]}),(0,S.jsx)("div",{className:$("overflow-hidden transition-all duration-200",ce?"max-h-[1600px] opacity-100":"max-h-0 opacity-0"),children:ce&&(0,S.jsx)(eL,{agentId:n,projectId:r})})]}),(0,S.jsxs)("div",{className:"border-t border-white/[0.06] pt-2 mt-3",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>Zt(E=>!E),className:"flex items-center gap-2 py-1.5 w-full text-left",children:[(0,S.jsx)(io,{className:"h-4 w-4 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-sm font-semibold text-white/92 flex-1",children:"Mount & Discover"}),(0,S.jsx)(Et,{className:$("h-3 w-3 text-white/25 transition-transform",Ft&&"rotate-180")})]}),(0,S.jsx)("div",{className:$("overflow-hidden transition-all duration-200",Ft?"max-h-[1600px] opacity-100":"max-h-0 opacity-0"),children:(0,S.jsxs)("div",{className:"mt-3 rounded-md bg-white/[0.02] border border-white/[0.06] p-3 space-y-2",children:[(0,S.jsx)("p",{className:"text-[10px] leading-relaxed text-white/55",children:"CLI helper for exposing host folders to the brain. Run it with no arguments to print usage:"}),(0,S.jsx)("div",{className:"rounded bg-black/30 border border-white/[0.05] p-2",children:(0,S.jsx)("pre",{className:"text-[11px] font-mono text-white/85 whitespace-pre-wrap break-all",children:"neuralis mount"})}),(0,S.jsxs)("div",{className:"rounded bg-black/30 border border-white/[0.05] p-2 space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] uppercase tracking-wider text-white/40 font-semibold",children:"Example \u2014 expose a host folder as a mount"}),(0,S.jsx)("pre",{className:"text-[10px] font-mono text-white/80 whitespace-pre-wrap break-all",children:"neuralis mount add <host-path> --slug <name>"}),(0,S.jsx)("div",{className:"text-[9px] text-white/35 italic",children:"The CLI is infra-only: it registers the bind mount + host-pair env in the machine-local compose override, never a source. After the container restarts, the mount appears in the Discoverable list below \u2014 click it to attach the source with a chosen scope (the host path resolves automatically)."})]}),Tn.length>0?(0,S.jsxs)("div",{className:"pt-1.5",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40 mb-1",children:"Discoverable"}),(0,S.jsx)("ul",{className:"space-y-1",children:Tn.map(E=>{let Q=Cc("unattached"),O=(0,lr.resolveLucideIcon)(E.icon??null)||zn;return(0,S.jsx)("li",{children:(0,S.jsxs)("button",{type:"button",onClick:()=>Mt(E),className:$("flex items-start gap-2 w-full text-left px-2 py-1.5 rounded-md hover:bg-white/[0.04] transition",Q.containerClassName),title:Q.title,children:[(0,S.jsx)(O,{className:$("h-3.5 w-3.5 mt-0.5 shrink-0",Q.iconClassName)}),(0,S.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,S.jsxs)("div",{className:$("text-[11px] font-semibold truncate",Q.labelClassName),children:[E.label,(0,S.jsxs)("span",{className:"text-[9px] text-white/30 font-mono ml-1.5",children:[E.suggestedScheme,"://"]})]}),(0,S.jsx)("div",{className:$("text-[9px] truncate",Q.detailClassName),children:E.description}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 font-mono truncate",children:E.root})]}),(0,S.jsx)(Fn,{className:"h-3 w-3 text-white/40 shrink-0 mt-1"})]})},E.id)})})]}):(0,S.jsx)("div",{className:"pt-1 text-[9px] italic text-white/35",children:"No discoverable mounts at the moment."})]})})]})]})}var Dt=j($e(),1),Zg=j(Za(),1);var yL=j(Wn(),1);async function Jo(t){let e=await t.text();try{return JSON.parse(e)}catch{throw new Error(`Invalid JSON response (HTTP ${t.status}): ${e.slice(0,200)}`)}}async function fL(t){let e=await fetch("/api/packages/runtime",{method:"GET",headers:{"x-project-id":t},credentials:"same-origin"});if(!e.ok)throw new Error(`Failed to load packages snapshot: HTTP ${e.status}`);let n=await Jo(e),r=[...n.skills,...n.instructions,...n.rules,...n.agents,...n.docs],a=Yg(n.tools,o=>o.packageId),s=Yg(r,o=>o.packageId),i=Yg(n.commands,o=>o.packageId);return n.packages.map(o=>({slug:o.id,packageId:o.id,name:o.name,version:o.version,description:o.description,source:o.source,runtime:o.runtime,access:o.access,status:o.status,partialReason:o.partialReason,toolCount:a.get(o.id)??0,fileCount:s.get(o.id)??0,commandCount:i.get(o.id)??0,...o.accessFeature?{accessFeature:o.accessFeature,accessFeatureSource:o.accessFeatureSource}:{}}))}async function hL(t,e){let n=await fetch(`/api/projects/${encodeURIComponent(t)}/packages/${encodeURIComponent(e)}/build`,{method:"POST",credentials:"same-origin"});return Jo(n)}async function pL(t,e,n){let r=await fetch(`/api/projects/${encodeURIComponent(t)}/packages/${encodeURIComponent(e)}/trust`,{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({trust:n})});if(!r.ok){let a=await r.text();throw new Error(`Failed to set trust (HTTP ${r.status}): ${a.slice(0,200)}`)}return Jo(r)}async function mL(t,e,n){let r=await fetch(`/api/projects/${encodeURIComponent(t)}/packages/${encodeURIComponent(e)}/access-feature`,{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({featureId:n})});if(!r.ok){let a=await r.text();throw new Error(`Failed to set access feature (HTTP ${r.status}): ${a.slice(0,200)}`)}return Jo(r)}async function gL(t){let e=await fetch("/api/admin/feature-catalog",{method:"GET",headers:{"x-project-id":t},credentials:"same-origin"});if(!e.ok)throw new Error(`Failed to load feature catalog: HTTP ${e.status}`);let n=await Jo(e),r=new Set;for(let a of n.groups??[])for(let s of a.features??[])r.add(s);return Array.from(r).sort()}async function xL(t){let e=await fetch("/api/packages/agent-core/packages/diagnostics",{method:"GET",headers:{"x-project-id":t},credentials:"same-origin"});if(!e.ok)throw new Error(`Failed to load packages diagnostics: HTTP ${e.status}`);return Jo(e)}function Yg(t,e){let n=new Map;for(let r of t){let a=e(r);n.set(a,(n.get(a)??0)+1)}return n}var Z=j(ie(),1),LE={"build-missing":{label:"Needs build",hint:"The package has server-side code (src/) but the WASM binary is missing. Click Build to compile it."},"runtime-unavailable":{label:"Runtime unavailable",hint:"MCP subprocess failed to spawn or the code runtime crashed. Check host logs."},"untrusted-node":{label:"Declarative only",hint:'Untrusted packages cannot execute in-process code. Declare `runtime.type: "wasm"` in the manifest to enable handlers.'},"untrusted-mcp":{label:"Declarative only",hint:'The "mcp" runtime spawns a subprocess as the host user and needs first-party trust, so no subprocess was started. Declare `runtime.type: "wasm"` in the manifest to enable handlers.'}};function bL({projectId:t}){let n=(hn().currentRole?.priority??99)<=2,[r,a]=(0,Dt.useState)([]),[s,i]=(0,Dt.useState)(!0),[o,l]=(0,Dt.useState)(null),[u,c]=(0,Dt.useState)({}),[d,f]=(0,Dt.useState)({}),[h,p]=(0,Dt.useState)(null),[g,m]=(0,Dt.useState)(!1);(0,Dt.useEffect)(()=>{m(!0)},[]);let[x,y]=(0,Dt.useState)(null),[b,C]=(0,Dt.useState)([]),[L,P]=(0,Dt.useState)(null),[w,k]=(0,Dt.useState)([]),_=(0,Dt.useCallback)(async()=>{i(!0),l(null);try{let N=await fL(t);a(N)}catch(N){l(N instanceof Error?N.message:String(N))}finally{i(!1)}try{let N=await xL(t);C(N.entries),P(null)}catch(N){C([]),P(N instanceof Error?N.message:String(N))}},[t]);(0,Dt.useEffect)(()=>{_()},[_]),(0,Dt.useEffect)(()=>{if(!n)return;let N=!1;return gL(t).then(A=>{N||k(A)}).catch(()=>{}),()=>{N=!0}},[t,n]);let M=(0,Dt.useCallback)(N=>{c(A=>({...A,[N]:!A[N]}))},[]),R=(0,Dt.useCallback)(async N=>{let A=N.access?.trust??"untrusted";if(A==="first-party")return;let B=A==="trusted"?"untrusted":"trusted";f(K=>({...K,[N.slug]:"trust"}));try{await pL(t,N.slug,B),p(`Trust: ${N.slug} \u2192 ${B}`),await _()}catch(K){p(K instanceof Error?K.message:"Failed to set trust")}finally{f(K=>({...K,[N.slug]:"none"}))}},[t,_]),U=(0,Dt.useCallback)(async(N,A)=>{f(B=>({...B,[N.slug]:"access-feature"}));try{await mL(t,N.packageId,A),p(A?`Access feature: ${N.slug} \u2192 ${A}`:`Access feature cleared: ${N.slug}`),await _()}catch(B){p(B instanceof Error?B.message:"Failed to set access feature")}finally{f(B=>({...B,[N.slug]:"none"}))}},[t,_]),v=(0,Dt.useCallback)(async N=>{f(B=>({...B,[N.slug]:"build"})),y({slug:N.slug,logs:["Starting build\u2026"]});let A=null;try{A=await hL(t,N.slug),y({slug:N.slug,logs:A.logs,ok:A.ok,error:A.error,durationMs:A.durationMs}),A.ok?(p(`Build complete: ${N.slug} (${A.durationMs}ms)`),await _()):p(`Build failed: ${A.error??"unknown"}`)}catch(B){let K=B instanceof Error?B.message:String(B);y({slug:N.slug,logs:[`Request failed: ${K}`],ok:!1,error:K}),p(`Build request failed: ${K}`)}finally{f(B=>({...B,[N.slug]:"none"}))}},[t,_]),T=(0,Dt.useMemo)(()=>[...r].sort((N,A)=>N.name.localeCompare(A.name)),[r]),V=(0,Dt.useMemo)(()=>{let N=new Set(r.map(A=>A.packageId));return b.filter(A=>!N.has(A.packageId)||A.status==="missing"||A.status==="error")},[b,r]),Y=(0,Dt.useMemo)(()=>{let N=new Map;for(let A of b)N.set(A.packageId,A);return N},[b]);return s?(0,Z.jsxs)("div",{className:"h-full flex items-center justify-center text-white/50 text-sm",children:[(0,Z.jsx)(We,{className:"w-4 h-4 animate-spin mr-2"})," Loading packages\u2026"]}):o?(0,Z.jsx)("div",{className:"p-4",children:(0,Z.jsxs)("div",{className:"rounded-lg border border-red-500/25 bg-red-500/10 p-3 text-xs text-red-100/85",children:[(0,Z.jsx)("div",{className:"font-semibold mb-1",children:"Failed to load packages"}),(0,Z.jsx)("div",{className:"font-mono opacity-80",children:o}),(0,Z.jsxs)("button",{className:"mt-2 inline-flex items-center gap-1 rounded-md bg-white/10 px-2 py-1 text-[11px] text-white/80 hover:bg-white/15",onClick:()=>{_()},children:[(0,Z.jsx)(_t,{className:"w-3 h-3"})," Retry"]})]})}):(0,Z.jsxs)("div",{className:"p-3 space-y-2",children:[(0,Z.jsxs)("div",{className:"flex items-center justify-between px-1 pb-2",children:[(0,Z.jsxs)("div",{className:"flex items-center gap-2",children:[(0,Z.jsx)(wr,{className:"w-4 h-4 text-violet-300"}),(0,Z.jsx)("h2",{className:"text-sm font-semibold text-white/85",children:"Packages"}),(0,Z.jsxs)("span",{className:"text-[10px] text-white/45",children:[T.length," installed"]})]}),(0,Z.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,Z.jsx)(yL.SkillLauncher,{variant:"label",size:"sm",skill:"create-package",packageId:"@neuralis/brain-core",alsoRequires:["packages.author"],label:"Scaffold a package with the agent",icon:"package"}),(0,Z.jsxs)("button",{className:"inline-flex items-center gap-1 rounded-md bg-white/5 px-2 py-1 text-[11px] text-white/60 hover:bg-white/10 hover:text-white/85",onClick:()=>{_()},children:[(0,Z.jsx)(_t,{className:"w-3 h-3"}),"Refresh"]})]})]}),(0,Z.jsxs)("div",{className:"mx-1 rounded-lg border border-violet-500/15 bg-violet-500/5 px-3 py-2 text-[11px] text-violet-100/80 flex items-start gap-2",children:[(0,Z.jsx)(Pl,{className:"w-3.5 h-3.5 shrink-0 mt-0.5 text-violet-300/80"}),(0,Z.jsxs)("div",{className:"space-y-1",children:[(0,Z.jsx)("div",{children:"Untrusted packages register their declarative content (skills, tool schemas, commands) but cannot execute in-process code or call other packages."}),(0,Z.jsxs)("div",{className:"text-violet-100/60",children:["Flip trust when you know the author. Run Build only for packages with server-side code in ",(0,Z.jsx)("span",{className:"font-mono",children:"src/"}),"."]})]})]}),V.length>0&&(0,Z.jsxs)("div",{className:"mx-1 rounded-lg border border-rose-500/25 bg-rose-500/[0.06] px-3 py-2 text-[11px] text-rose-100/85 space-y-1",children:[(0,Z.jsxs)("div",{className:"flex items-center gap-1.5 text-rose-200/95 font-semibold",children:[(0,Z.jsx)(ot,{className:"w-3 h-3"}),V.length," package",V.length===1?"":"s"," failed to load"]}),V.map(N=>(0,Z.jsxs)("div",{className:"rounded border border-rose-500/15 bg-rose-500/[0.04] px-2 py-1",children:[(0,Z.jsxs)("div",{className:"font-mono text-[10px] text-rose-200/95",children:[N.packageId," ",(0,Z.jsxs)("span",{className:"text-rose-300/80",children:["\xB7 ",N.status]}),N.reason&&(0,Z.jsxs)("span",{className:"text-rose-300/55",children:[" (",N.reason,")"]})]}),N.error&&(0,Z.jsx)("div",{className:"mt-0.5 font-mono text-[10px] text-rose-100/70 whitespace-pre-wrap break-all",children:N.error}),N.sourceRoot&&(0,Z.jsx)("div",{className:"mt-0.5 text-[9px] text-rose-200/50",children:(0,Z.jsx)("span",{className:"font-mono",children:N.sourceRoot})})]},N.packageId))]}),L&&(0,Z.jsxs)("div",{className:"mx-1 rounded-md border border-amber-500/25 bg-amber-500/[0.06] px-2 py-1 text-[10px] text-amber-100/80",children:[(0,Z.jsx)("span",{className:"font-mono",children:"/packages/diagnostics"})," unreachable: ",L]}),T.length===0?(0,Z.jsxs)("div",{className:"mx-1 mt-6 rounded-lg border border-white/10 bg-white/[0.02] p-6 text-center text-white/50 text-sm",children:["No packages installed yet. Drop packages into"," ",(0,Z.jsx)("span",{className:"font-mono text-white/70",children:"_packages/"})," to see them here."]}):(0,Z.jsx)("div",{className:"space-y-1",children:T.map(N=>(0,Z.jsx)(AE,{row:N,expanded:!!u[N.slug],pending:d[N.slug]??"none",canGovern:n,featureIds:w,onToggle:()=>M(N.slug),onFlipTrust:()=>{R(N)},onBuild:()=>{v(N)},onSetAccessFeature:A=>{U(N,A)}},N.slug))}),h&&g?(0,Zg.createPortal)((0,Z.jsx)("div",{className:"fixed bottom-4 right-4 z-[100000] rounded-lg border border-white/15 bg-neutral-900/95 px-3 py-2 text-[11px] text-white/85 shadow-lg",onClick:()=>p(null),children:h}),document.body):null,x&&g?(0,Zg.createPortal)((0,Z.jsx)("div",{className:"fixed inset-0 z-[100000] flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>y(null),children:(0,Z.jsxs)("div",{className:"w-full max-w-xl rounded-lg border border-white/15 bg-neutral-900/95 p-4 shadow-xl",onClick:N=>N.stopPropagation(),children:[(0,Z.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,Z.jsxs)("div",{className:"flex items-center gap-2",children:[x.ok===void 0?(0,Z.jsx)(We,{className:"w-4 h-4 animate-spin text-white/60"}):x.ok?(0,Z.jsx)(Qr,{className:"w-4 h-4 text-emerald-400"}):(0,Z.jsx)(ot,{className:"w-4 h-4 text-amber-300"}),(0,Z.jsxs)("span",{className:"text-sm font-semibold text-white/85",children:["Build \u2014 ",x.slug]}),x.durationMs!==void 0?(0,Z.jsxs)("span",{className:"text-[10px] text-white/45",children:[x.durationMs,"ms"]}):null]}),(0,Z.jsx)("button",{className:"text-white/50 hover:text-white/80 text-xs",onClick:()=>y(null),children:"Close"})]}),(0,Z.jsx)("pre",{className:"max-h-80 overflow-y-auto rounded-md bg-black/40 border border-white/10 p-2 text-[11px] font-mono text-white/75 whitespace-pre-wrap",children:x.logs.join(`
|
|
52
|
-
`)})]})}),document.body):null]})}function AE(t){let{row:e,expanded:n,pending:r,canGovern:a,featureIds:s,onToggle:i,onFlipTrust:o,onBuild:l,onSetAccessFeature:u}=t,c=e.access?.trust??"untrusted",d=e.runtime?.type??"node",f=e.partialReason,h=f?LE[f]:void 0,p=d==="wasm"&&e.status==="partial"&&f==="build-missing",g=c==="first-party";return(0,Z.jsxs)("div",{className:"rounded-lg border border-white/10 bg-white/[0.02] hover:bg-white/[0.035] transition-colors",children:[(0,Z.jsxs)("button",{type:"button",className:"w-full flex items-start gap-2 px-3 py-2 text-left",onClick:i,children:[n?(0,Z.jsx)(Et,{className:"mt-0.5 w-3.5 h-3.5 shrink-0 text-white/50"}):(0,Z.jsx)(un,{className:"mt-0.5 w-3.5 h-3.5 shrink-0 text-white/50"}),(0,Z.jsx)(wr,{className:"mt-0.5 w-4 h-4 shrink-0 text-violet-300/80"}),(0,Z.jsxs)("div",{className:"min-w-0 flex-1 space-y-1",children:[(0,Z.jsxs)("div",{className:"flex items-baseline gap-1.5",children:[(0,Z.jsx)("span",{className:"min-w-0 flex-1 text-sm font-semibold text-white/90 truncate",children:e.name}),e.version?(0,Z.jsxs)("span",{className:"text-[10px] font-mono text-white/40 shrink-0",children:["v",e.version]}):null]}),e.description?(0,Z.jsx)("div",{className:"text-[10px] text-white/45 truncate",children:e.description}):null,(0,Z.jsxs)("div",{className:"flex flex-wrap items-center gap-1 pt-0.5",children:[(0,Z.jsx)(NE,{status:e.status,partialLabel:h?.label}),(0,Z.jsx)(RE,{trust:c}),(0,Z.jsx)(ME,{type:d})]})]})]}),n?(0,Z.jsxs)("div",{className:"px-3 pb-3 pt-1 border-t border-white/5 space-y-3",children:[f&&h?(0,Z.jsxs)("div",{className:"rounded-md border border-amber-500/20 bg-amber-500/5 p-2 text-[11px] text-amber-100/80 flex items-start gap-2",children:[(0,Z.jsx)(ot,{className:"w-3.5 h-3.5 shrink-0 mt-0.5 text-amber-300/80"}),(0,Z.jsxs)("div",{children:[(0,Z.jsx)("div",{className:"font-semibold",children:h.label}),(0,Z.jsx)("div",{className:"text-amber-100/60",children:h.hint})]})]}):null,(0,Z.jsxs)("div",{className:"grid grid-cols-3 gap-2 text-[10px]",children:[(0,Z.jsx)(Jg,{label:"Tools",value:e.toolCount}),(0,Z.jsx)(Jg,{label:"Skills / files",value:e.fileCount}),(0,Z.jsx)(Jg,{label:"Commands",value:e.commandCount})]}),(0,Z.jsxs)("div",{className:"text-[10px] text-white/50 font-mono",children:[e.source?.kind?`source: ${e.source.kind}`:"",e.source?.kind&&d?" \xB7 ":"",`runtime: ${d}`]}),(0,Z.jsxs)("div",{className:"flex items-center gap-2 pt-1",children:[(0,Z.jsxs)("button",{type:"button",className:["inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] transition",g?"bg-white/5 text-white/35 cursor-not-allowed":c==="trusted"?"bg-emerald-500/15 border border-emerald-500/25 text-emerald-100 hover:bg-emerald-500/20":"bg-white/5 border border-white/10 text-white/70 hover:bg-white/10"].join(" "),disabled:g||r!=="none",onClick:o,title:g?"First-party packages are trust-locked":void 0,children:[r==="trust"?(0,Z.jsx)(We,{className:"w-3 h-3 animate-spin"}):c==="trusted"?(0,Z.jsx)(so,{className:"w-3 h-3"}):(0,Z.jsx)(_l,{className:"w-3 h-3"}),c==="trusted"?"Revert to untrusted":"Mark as trusted"]}),(0,Z.jsxs)("button",{type:"button",className:["inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] transition",p?"bg-violet-500/15 border border-violet-500/25 text-violet-100 hover:bg-violet-500/20":"bg-white/5 text-white/35 cursor-not-allowed"].join(" "),disabled:!p||r!=="none",onClick:l,title:p?"Compile src/ \u2192 dist/package.wasm on the server":d!=="wasm"?'Build is only required for runtime.type: "wasm" packages':"Build is only needed when status is partial / build-missing",children:[r==="build"?(0,Z.jsx)(We,{className:"w-3 h-3 animate-spin"}):(0,Z.jsx)(ci,{className:"w-3 h-3"}),"Build"]}),(0,Z.jsx)(TE,{trust:c})]}),a?(0,Z.jsx)(PE,{row:e,featureIds:s,pending:r==="access-feature",disabled:r!=="none",onSetAccessFeature:u}):e.accessFeature?(0,Z.jsxs)("div",{className:"mt-2 text-[10px] text-white/45",children:["Access feature: ",(0,Z.jsx)("span",{className:"font-mono text-white/65",children:e.accessFeature}),(0,Z.jsxs)("span",{className:"text-white/30",children:[" (",e.accessFeatureSource,")"]})]}):null]}):null]})}function PE(t){let{row:e,featureIds:n,pending:r,disabled:a,onSetAccessFeature:s}=t,[i,o]=(0,Dt.useState)(e.accessFeature??""),l=`af-${e.slug}`;(0,Dt.useEffect)(()=>{o(e.accessFeature??"")},[e.accessFeature]);let u=e.accessFeatureSource==="manifest",c=i.trim(),d=e.accessFeatureSource==="override"?e.accessFeature??"":"",f=c!==d;return(0,Z.jsxs)("div",{className:"mt-2 rounded-md border border-white/10 bg-white/[0.02] px-2.5 py-2 space-y-1.5",children:[(0,Z.jsxs)("div",{className:"flex items-center gap-1.5 text-[10px] font-semibold text-white/60",children:[(0,Z.jsx)(Ps,{className:"w-3 h-3 text-cyan-300/80"}),"Base-access feature",e.accessFeature?(0,Z.jsxs)("span",{className:"ml-auto font-mono text-[9px] text-white/45",children:[e.accessFeature," ",(0,Z.jsxs)("span",{className:"text-white/30",children:["(",e.accessFeatureSource,")"]})]}):null]}),(0,Z.jsx)("div",{className:"text-[9px] text-white/40 leading-snug",children:u?"Declared in the manifest (requires.accessFeature) \u2014 not editable here. An override below adds an ADDITIONAL required feature.":"Pick a feature to hide this package from anyone who lacks it (restrict-only), then grant that feature to a role in Admin \u2192 Roles. Clear to remove."}),(0,Z.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,Z.jsx)("input",{list:l,value:i,onChange:h=>o(h.target.value),placeholder:"feature.id (e.g. labs.access)",disabled:a,className:"flex-1 min-w-0 rounded bg-black/30 border border-white/10 px-2 py-1 text-[10px] font-mono text-white/80 placeholder:text-white/25 focus:outline-none focus:border-cyan-400/40"}),(0,Z.jsx)("datalist",{id:l,children:n.map(h=>(0,Z.jsx)("option",{value:h},h))}),(0,Z.jsxs)("button",{type:"button",disabled:a||!f||c.length===0,onClick:()=>s(c),className:"inline-flex items-center gap-1 rounded-md bg-cyan-500/15 border border-cyan-400/25 px-2 py-1 text-[10px] text-cyan-100 hover:bg-cyan-500/20 transition disabled:opacity-35",children:[r?(0,Z.jsx)(We,{className:"w-3 h-3 animate-spin"}):null,"Set"]}),(0,Z.jsx)("button",{type:"button",disabled:a||e.accessFeatureSource!=="override",onClick:()=>s(null),title:e.accessFeatureSource==="manifest"?"Manifest-declared features cannot be cleared here":"Clear the override",className:"inline-flex items-center gap-1 rounded-md bg-white/5 border border-white/10 px-2 py-1 text-[10px] text-white/65 hover:bg-white/10 transition disabled:opacity-35",children:"Clear"})]})]})}function NE(t){let{status:e,partialLabel:n}=t;return e==="partial"?(0,Z.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-amber-500/25 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-100/85",children:[(0,Z.jsx)(ot,{className:"w-2.5 h-2.5"})," ",n??"Partial"]}):e==="error"?(0,Z.jsx)("span",{className:"inline-flex items-center gap-1 rounded-full border border-red-500/25 bg-red-500/10 px-2 py-0.5 text-[10px] text-red-100/85",children:"Error"}):e==="disabled"?(0,Z.jsx)("span",{className:"rounded-full bg-white/10 px-2 py-0.5 text-[10px] text-white/55",children:"Disabled"}):(0,Z.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-emerald-500/25 bg-emerald-500/10 px-2 py-0.5 text-[10px] text-emerald-100/85",children:[(0,Z.jsx)(Qr,{className:"w-2.5 h-2.5"})," Active"]})}function RE(t){let{trust:e}=t;return e==="first-party"?(0,Z.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-sky-500/25 bg-sky-500/10 px-2 py-0.5 text-[10px] text-sky-100/85",children:[(0,Z.jsx)(Ps,{className:"w-2.5 h-2.5"})," First-party"]}):e==="trusted"?(0,Z.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-emerald-500/25 bg-emerald-500/10 px-2 py-0.5 text-[10px] text-emerald-100/85",children:[(0,Z.jsx)(so,{className:"w-2.5 h-2.5"})," Trusted"]}):(0,Z.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/15 bg-white/5 px-2 py-0.5 text-[10px] text-white/60",children:[(0,Z.jsx)(Sa,{className:"w-2.5 h-2.5"})," Untrusted"]})}function ME(t){let{type:e}=t;return(0,Z.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full bg-white/5 px-2 py-0.5 text-[10px] font-mono text-white/55 border border-white/10",children:[(0,Z.jsx)(jl,{className:"w-2.5 h-2.5 text-violet-300/70"}),e]})}function Jg(t){return(0,Z.jsxs)("div",{className:"rounded-md bg-white/[0.03] border border-white/5 px-2 py-1.5",children:[(0,Z.jsx)("div",{className:"text-white/45",children:t.label}),(0,Z.jsx)("div",{className:"text-white/85 font-mono mt-0.5",children:t.value})]})}function TE(t){let[e,n]=(0,Dt.useState)(!1);return(0,Z.jsxs)("div",{className:"relative",children:[(0,Z.jsx)("button",{type:"button",className:"inline-flex items-center rounded-md bg-white/5 p-1 text-white/40 hover:text-white/70 hover:bg-white/10",onClick:()=>n(r=>!r),children:(0,Z.jsx)(ea,{className:"w-3 h-3"})}),e?(0,Z.jsxs)("div",{className:"absolute right-0 bottom-full mb-2 w-64 rounded-lg border border-white/15 bg-neutral-900/95 p-2.5 text-[11px] text-white/75 shadow-xl z-10",children:[(0,Z.jsx)("div",{className:"font-semibold text-white/85 mb-1",children:t.trust==="trusted"?"Trusted":t.trust==="first-party"?"First-party":"Untrusted"}),(0,Z.jsx)("div",{className:"text-white/60",children:t.trust==="first-party"?"Built-in package, full access \u2014 trust is locked.":t.trust==="trusted"?"Full fs / network / cross-package API. Only flip this when you trust the author.":"Data-only filesystem, no network, no cross-package API. Safe default for unknown packages."})]}):null]})}function zi(t){let e=t.trim();if(!e)return"";let n=e.indexOf("://"),r=n>=1?e.slice(0,n+3):"",a=n>=1?e.slice(n+3):e,s=a.length>0&&a.endsWith("/"),i=[];for(let l of a.split("/"))if(!(l===""||l===".")){if(l===".."){i.pop();continue}i.push(l)}let o=i.join("/");return o?`${r}${o}${s?"/":""}`:r}var Of=j(Zr(),1);var mr=j($e(),1);function wL(t){let e=H(x=>x.client),{agentId:n,projectId:r,sources:a,revisions:s,resetKey:i}=t,[o,l]=(0,mr.useState)([]),[u,c]=(0,mr.useState)(!1),d=(0,mr.useRef)(Promise.resolve()),f=(0,mr.useRef)(0),h=(0,mr.useRef)([]),p=(0,mr.useRef)({}),g=(0,mr.useRef)(!0),m=(0,mr.useCallback)(async x=>{if(!n)return;x&&(g.current=!0);let y=++f.current,b=r?{projectId:r}:{},C=d.current.then(async()=>{if(y!==f.current)return;let L=[...h.current],P=g.current;g.current=!1;let w=()=>{h.current=[...L],l([...L])};c(!0);try{for(let k of a){if(!k.git?.isRepo&&!k.git?.containsRepos)continue;let _=k.uri_root.replace("://",""),M=s[_]??0;if(!(!P&&p.current[_]===M))try{let R=await Ki({agentId:n,...b,source:_},e);if(y!==f.current)return;for(let U=L.length-1;U>=0;U--)L[U].source===_&&!R.repos.some(v=>v.rel===L[U].repo.rel)&&L.splice(U,1);for(let U of R.repos){let v={source:_,repo:U};try{let V=await oc({agentId:n,...b,source:_,repo:U.rel},e);if(y!==f.current)return;V.ok===!1?v.error="Git status unavailable":v.status=V.status}catch(V){v.error=V instanceof Error?V.message:"Git status failed"}let T=L.findIndex(V=>V.source===_&&V.repo.rel===U.rel);T<0?L.push(v):L[T]=v,w()}p.current[_]=M}catch(R){if(y!==f.current)return;let U={source:_,repo:{rel:"",name:_},error:R instanceof Error?R.message:"Repository discovery failed"},v=L.findIndex(T=>T.source===_&&T.repo.rel==="");v>=0?L[v]=U:L.push(U),p.current[_]=M,w()}}y===f.current&&w()}finally{y===f.current&&c(!1)}});d.current=C.catch(()=>{}),await C},[n,r,a,s]);return(0,mr.useEffect)(()=>{f.current++,h.current=[],p.current={},g.current=!0,l([])},[i]),(0,mr.useEffect)(()=>(m(!1),()=>{f.current++}),[m]),{groups:o,loading:u,refresh:m}}var fe=j($e(),1);var zL=j(Wn(),1);var Nf=j($e(),1);var vL=j($e(),1),Yu=j(ie(),1),DE={add:"bg-emerald-500/12",remove:"bg-red-500/18",context:""},kL=(0,vL.memo)(function({lineNo:e,type:n,content:r}){return(0,Yu.jsxs)("div",{className:`flex h-[18px] w-full ${DE[n]}`,children:[(0,Yu.jsx)("span",{className:"shrink-0 w-10 text-right pr-2 select-none text-white/25 tabular-nums",children:e??""}),(0,Yu.jsx)("span",{className:"shrink-0 whitespace-pre pr-3 text-white/78",children:r||" "})]})});var cs=j(ie(),1),Zo=(0,Nf.memo)(function({hunks:e,isStreaming:n,maxLines:r=200}){let{elements:a,truncated:s}=(0,Nf.useMemo)(()=>{let i=[],o=0,l=0,u=!1,c=1,d=1;for(let f of e){if(f.skippedBefore!==0){let h=f.skippedBefore>0?`\xB7\xB7\xB7 ${f.skippedBefore} lines skipped \xB7\xB7\xB7`:"\xB7\xB7\xB7 \xB7\xB7\xB7 \xB7\xB7\xB7";i.push((0,cs.jsx)(FE,{label:h},`skip-${o}`)),f.skippedBefore>0&&(c+=f.skippedBefore,d+=f.skippedBefore)}for(let h of f.lines){if(l>=r){u=!0;break}let p=n?"add":h.type,g=p==="remove"?c:d;p==="remove"?c++:(p==="add"||c++,d++),i.push((0,cs.jsx)(kL,{lineNo:g,type:p,content:h.content},`line-${o}`)),o++,l++}if(u)break}return{elements:i,truncated:u}},[e,n,r]);return a.length===0?(0,cs.jsx)("div",{className:"px-3 py-2 text-[11px] text-white/40 italic",children:"No content"}):(0,cs.jsx)("div",{className:"font-mono text-[11px] leading-[18px] overflow-x-auto overflow-y-clip",children:(0,cs.jsxs)("div",{className:"min-w-full w-max",children:[a,s&&(0,cs.jsxs)("div",{className:"w-full text-[10px] text-white/40 bg-white/4 px-3 py-1 text-center",children:["\xB7\xB7\xB7 ",e.reduce((i,o)=>i+o.lines.length,0)-r," more lines \xB7\xB7\xB7"]})]})})},(t,e)=>{if(t.isStreaming!==e.isStreaming||t.maxLines!==e.maxLines||t.language!==e.language)return!1;if(t.hunks===e.hunks)return!0;if(t.hunks.length!==e.hunks.length)return!1;for(let n=0;n<t.hunks.length;n++){let r=t.hunks[n],a=e.hunks[n];if(r===a)continue;if(r.skippedBefore!==a.skippedBefore||r.lines.length!==a.lines.length)return!1;let s=r.lines[0],i=a.lines[0];if(s?.type!==i?.type||s?.content!==i?.content)return!1;let o=r.lines[r.lines.length-1],l=a.lines[a.lines.length-1];if(o?.type!==l?.type||o?.content!==l?.content)return!1}return!0});function FE({label:t}){return(0,cs.jsx)("div",{className:"w-full text-[10px] text-white/35 bg-white/[0.03] px-3 py-0.5 text-center border-y border-white/6 select-none",children:t})}var Mf=j(Zr(),1);function SL(t){return t.snapshotHash?null:"originalDraftUnknown"}function Qg(t,e){return t.op!=="delete"&&t.op!=="create"&&!t.baselineMissing&&e.current.state==="missing"&&e.baselineProvenance==="journal-latest-write"&&(e.baseline.state==="text"||e.baseline.state==="binary"||e.baseline.state==="too-large")}function e0(t){return String(t||"").replace(/\r\n/g,`
|
|
51
|
+
packages/*/skills/**`}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Non-empty: only matching files sync. Excludes always win \u2014 an excluded path can never be re-included."})]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Max scan files"}),(0,S.jsx)("input",{type:"number",min:1,step:1e3,value:tr.maxScanFiles??"",onChange:Ge=>{let Kt=Number(Ge.target.value),pr=Number.isFinite(Kt)&&Kt>0?Math.floor(Kt):void 0;U(T.source,di=>({...di,sync:{...tr,maxScanFiles:pr}}))},className:V(no,"w-28 font-mono"),placeholder:"200000"}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Per-source cap on files walked during sync/count. Empty = inherit the platform default. When a walk hits the cap the count shows N+."})]}),(0,S.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:tr.alwaysActive??(T.source==="data"||T.source==="packages"),onChange:Ge=>U(T.source,Kt=>({...Kt,sync:{...tr,alwaysActive:Ge.target.checked}})),className:"accent-cyan-400 h-3 w-3"}),"Always active",(0,S.jsx)("span",{className:"text-[8px] text-white/30 normal-case",children:'(pins this source in the auto-sync pool even when the platform Auto-Sync Mode is "packages-only"; no effect with the Manual trigger)'})]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Media"}),(0,S.jsx)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:yE.map(Ge=>(0,S.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:tr.media?.[Ge.key]??Ge.on,onChange:Kt=>U(T.source,pr=>({...pr,sync:{...tr,media:{...tr.media??{},[Ge.key]:Kt.target.checked}}})),className:"accent-cyan-400 h-3 w-3"}),Ge.label]},Ge.key))}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Embeds these files from their bytes \u2014 only while the active embedding model is multimodal (a text-only model skips them and the last-sync line says so). Each image or PDF page is one provider call; video and audio cost the most. Unticking a kind clears its searchable cache at the next full sync while preserving recovery content."})]}),T.sync?.lastSyncResult&&(0,S.jsxs)("div",{className:"text-[9px] text-white/40 flex items-center gap-2",children:[(0,S.jsxs)("span",{children:["Last sync: +",T.sync.lastSyncResult.filesAdded," -",T.sync.lastSyncResult.filesRemoved," ~",T.sync.lastSyncResult.filesUpdated]}),(0,S.jsxs)("span",{children:["(",(T.sync.lastSyncResult.durationMs/1e3).toFixed(1),"s)"]}),T.sync.lastSyncResult.error&&(0,S.jsx)("span",{className:"text-rose-300/80 truncate max-w-[200px]",title:T.sync.lastSyncResult.error,children:"err"})]}),pL(T.sync?.lastSyncResult?.mediaSkipped)&&(0,S.jsx)("div",{className:"text-[9px] text-amber-200/70",role:"status",children:pL(T.sync?.lastSyncResult?.mediaSkipped)}),mL(T.sync?.lastSyncResult?.binarySkipped)&&(0,S.jsx)("div",{className:"text-[9px] text-white/40",role:"status",children:mL(T.sync?.lastSyncResult?.binarySkipped)}),(()=>{let Ge=vE(T.sync?.lastSyncResult?.embeddingDegraded,T.embedding_enabled);return Ge?(0,S.jsx)("div",{className:Ge.attention?"text-[9px] text-amber-200/70":"text-[9px] text-white/40",role:"status",children:Ge.text}):null})(),Ue[T.source]&&(0,S.jsxs)("div",{className:"text-[9px] text-amber-200/70 flex items-center gap-2",role:"status",children:[(0,S.jsxs)("span",{children:["Embedding paused: ",Ue[T.source]]}),(0,S.jsx)("button",{type:"button",disabled:ts,onClick:()=>{ao(T.source)},className:"h-5 px-1.5 rounded bg-white/[0.04] hover:bg-white/[0.08] text-amber-200/90 disabled:opacity-35",children:"Resume"})]})]})]})]}),(0,S.jsxs)("div",{className:"flex items-center justify-between gap-2 pt-1.5 border-t border-white/[0.06]",children:[(0,S.jsx)("span",{className:"text-[9px] text-white/30",children:T.observed?"Observed runtime source":nh?"Unsaved changes":"No pending changes"}),(0,S.jsxs)("div",{className:"flex items-center gap-1.5",children:[As&&rs&&(pn||ts)?(0,S.jsxs)("button",{type:"button",onClick:()=>{Qt(T.source)},className:"h-6 px-2 rounded-md bg-rose-500/10 hover:bg-rose-500/20 border border-rose-400/25 text-[9px] font-medium text-rose-300/80 hover:text-rose-200 transition inline-flex items-center gap-1",children:[(0,S.jsx)(eu,{className:"h-2.5 w-2.5"}),"Cancel"]}):As&&rs?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)("button",{type:"button",disabled:!gc,onClick:()=>{Bt(T.source)},className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-blue-300/80 hover:text-blue-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,S.jsx)(Xl,{className:"h-2.5 w-2.5"}),"Sync"]}),(0,S.jsxs)("button",{type:"button",disabled:ts,onClick:()=>{en(T.source)},className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-cyan-300/80 hover:text-cyan-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,S.jsx)(Sr,{className:"h-2.5 w-2.5"}),"Rescan changes"]}),(0,S.jsxs)("button",{type:"button",disabled:ts||T.embedding_enabled===!1,onClick:()=>rt(T.source),title:T.embedding_enabled===!1?"Semantic embedding is off \u2014 turn it on in the platform settings first":"Embed every file of this source again with the active model \u2014 shows the estimated cost first",className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-cyan-300/80 hover:text-cyan-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,S.jsx)(Fa,{className:"h-2.5 w-2.5"}),"Re-embed\u2026"]}),(()=>{let Ge=T.embedding_enabled===!1;return(0,S.jsxs)("button",{type:"button",disabled:ts||Ge,onClick:()=>Ft(T.source),title:Ge?"Semantic embedding is off \u2014 turn it on in the platform settings first":"Embed only the files whose semantic embedding is missing or stale \u2014 shows the estimate first",className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-cyan-300/80 hover:text-cyan-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,S.jsx)(Sr,{className:"h-2.5 w-2.5"}),"Embed pending\u2026"]})})(),(0,S.jsxs)("button",{type:"button",disabled:De===T.source,onClick:()=>{P2(T.source)},title:"Forgets what the last sync saw \u2014 the next sync compares every file again. Deletes no file and no vector.",className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-amber-300/80 hover:text-amber-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[De===T.source?(0,S.jsx)($e,{className:"h-2.5 w-2.5 animate-spin"}):(0,S.jsx)(wi,{className:"h-2.5 w-2.5"}),"Forget sync state"]})]}):null,T.canMaintain===!0&&(0,S.jsx)("button",{type:"button",onClick:()=>{ze.current++,yt(T.source),Ut("source"),me(""),cn(!0),Re(null),Pe(!1)},className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] text-amber-300/80",children:"Clean index\u2026"}),As&&!T2(T.source)&&(0,S.jsxs)("button",{type:"button",disabled:da,onClick:()=>te(T.source),className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-red-300/80 hover:text-red-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[da?(0,S.jsx)($e,{className:"h-2.5 w-2.5 animate-spin"}):(0,S.jsx)(_t,{className:"h-2.5 w-2.5"}),"Delete"]}),(0,S.jsxs)("button",{type:"button",disabled:an||!nh,onClick:()=>{Te(T,pe)},className:"h-6 px-2.5 rounded-md bg-emerald-500/12 border border-emerald-400/25 text-[9px] font-semibold text-emerald-200/90 hover:bg-emerald-500/20 transition disabled:opacity-35 inline-flex items-center gap-1",children:[an?(0,S.jsx)($e,{className:"h-2.5 w-2.5 animate-spin"}):(0,S.jsx)(ki,{className:"h-2.5 w-2.5"}),"Save"]})]})]})]})}),st===T.source&&T.canMaintain===!0&&(0,S.jsxs)("fieldset",{disabled:Oe,className:"ml-5 mb-2 rounded-md border border-amber-400/20 p-3 space-y-2 text-[10px] text-white/70",children:[(0,S.jsxs)("legend",{children:["Clean index for ",T.source]}),(0,S.jsx)("p",{children:"The source, files, pending changes and recovery history stay available. Cleanup makes no embedding calls."}),(0,S.jsxs)("label",{children:["Selection ",(0,S.jsxs)("select",{"aria-label":"Index cleanup selection",value:vt,onChange:Ge=>{ze.current++,Ut(Ge.target.value),Re(null)},className:"bg-[#15151d]",children:[(0,S.jsx)("option",{value:"source",children:"Whole source"}),(0,S.jsx)("option",{value:"folder",children:"Folder"}),(0,S.jsx)("option",{value:"file",children:"File"})]})]}),vt!=="source"&&(0,S.jsx)("input",{"aria-label":"Index cleanup URI",placeholder:`${T.source}://path`,value:Et,onChange:Ge=>{ze.current++,me(Ge.target.value),Re(null)},className:"block w-full bg-white/5 rounded px-2 py-1"}),(0,S.jsxs)("label",{className:"block",children:[(0,S.jsx)("input",{type:"checkbox",checked:Ye,onChange:Ge=>{ze.current++,cn(Ge.target.checked),Re(null)}})," Only excluded files and disabled media lanes"]}),!Ye&&(0,S.jsx)("p",{children:"All selected searchable cache will be cleared. A later sync can rebuild it."}),fe&&(0,S.jsxs)("p",{children:[fe.removedParents," parents removed \xB7 ",fe.removedChunks," chunks removed \xB7 ",fe.retained," recovery payloads retained \xB7 ",fe.unresolved," unresolved points kept"]}),(0,S.jsxs)("div",{className:"flex gap-2",children:[(0,S.jsx)("button",{type:"button",onClick:()=>{ze.current++,yt(null),Re(null)},children:"Cancel"}),(0,S.jsx)("button",{type:"button",onClick:()=>{w0(T.source,"estimate")},children:Oe?"Working\u2026":"Preview counts"}),fe?.canMaintain&&(0,S.jsx)("button",{type:"button",onClick:()=>{w0(T.source,"apply")},children:"Confirm cleanup"})]})]}),Q===T.source&&(0,S.jsx)(hL,{source:T.source,vectorCount:typeof T.indexed_count=="number"?T.indexed_count:null,isDockerMount:!!T.connection?.config?.hostRoot,busy:da,onCancel:()=>te(null),onConfirm:Ge=>{N2(T.source,Ge)}}),at===T.source&&(0,S.jsx)(uu,{kind:"pending",agentId:n,...r?{projectId:r}:{},target:{source:T.source,label:T.source},onClose:()=>Ft(null),onStarted:()=>{ca(T.source,()=>Promise.resolve(),"Embedding failed")}}),Qe===T.source&&(0,S.jsx)(uu,{agentId:n,...r?{projectId:r}:{},target:{source:T.source,label:T.source},onClose:()=>rt(null),onStarted:()=>{ca(T.source,()=>Promise.resolve(),"Re-embed failed")}})]},Sx(kr(T.source)))})})]},M))}),ge&&(0,S.jsx)("div",{className:"mt-2 rounded-md bg-emerald-500/10 border border-emerald-400/25 px-2.5 py-1.5 text-[10px] text-emerald-200/85",children:ge}),(0,S.jsxs)("div",{className:"border-t border-white/[0.06] pt-2 mt-3",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>ve(!Fe),className:"flex items-center gap-2 py-1.5 w-full text-left",children:[(0,S.jsx)(Sr,{className:"h-4 w-4 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-sm font-semibold text-white/92 flex-1",children:"Vector Health"}),(0,S.jsx)(qt,{className:V("h-3 w-3 text-white/25 transition-transform",Fe&&"rotate-180")})]}),(0,S.jsx)("div",{className:V("overflow-hidden transition-all duration-200",Fe?"max-h-[1600px] opacity-100":"max-h-0 opacity-0"),children:Fe&&(0,S.jsx)(uL,{agentId:n,projectId:r})})]}),(0,S.jsxs)("div",{className:"border-t border-white/[0.06] pt-2 mt-3",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>pt(M=>!M),className:"flex items-center gap-2 py-1.5 w-full text-left",children:[(0,S.jsx)(wo,{className:"h-4 w-4 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-sm font-semibold text-white/92 flex-1",children:"Mount & Discover"}),(0,S.jsx)(qt,{className:V("h-3 w-3 text-white/25 transition-transform",Nt&&"rotate-180")})]}),(0,S.jsx)("div",{className:V("overflow-hidden transition-all duration-200",Nt?"max-h-[1600px] opacity-100":"max-h-0 opacity-0"),children:(0,S.jsxs)("div",{className:"mt-3 rounded-md bg-white/[0.02] border border-white/[0.06] p-3 space-y-2",children:[(0,S.jsx)("p",{className:"text-[10px] leading-relaxed text-white/55",children:"CLI helper for exposing host folders to the brain. Run it with no arguments to print usage:"}),(0,S.jsx)("div",{className:"rounded bg-black/30 border border-white/[0.05] p-2",children:(0,S.jsx)("pre",{className:"text-[11px] font-mono text-white/85 whitespace-pre-wrap break-all",children:"neuralis mount"})}),(0,S.jsxs)("div",{className:"rounded bg-black/30 border border-white/[0.05] p-2 space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] uppercase tracking-wider text-white/40 font-semibold",children:"Example \u2014 expose a host folder as a mount"}),(0,S.jsx)("pre",{className:"text-[10px] font-mono text-white/80 whitespace-pre-wrap break-all",children:"neuralis mount add <host-path> --slug <name>"}),(0,S.jsx)("div",{className:"text-[9px] text-white/35 italic",children:"The CLI is infra-only: it registers the bind mount + host-pair env in the machine-local compose override, never a source. After the container restarts, the mount appears in the Discoverable list below \u2014 click it to attach the source with a chosen scope (the host path resolves automatically)."})]}),fn.length>0?(0,S.jsxs)("div",{className:"pt-1.5",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40 mb-1",children:"Discoverable"}),(0,S.jsx)("ul",{className:"space-y-1",children:fn.map(M=>{let ee=Oc("unattached"),T=(0,Ir.resolveLucideIcon)(M.icon??null)||rr;return(0,S.jsx)("li",{children:(0,S.jsxs)("button",{type:"button",onClick:()=>$t(M),className:V("flex items-start gap-2 w-full text-left px-2 py-1.5 rounded-md hover:bg-white/[0.04] transition",ee.containerClassName),title:ee.title,children:[(0,S.jsx)(T,{className:V("h-3.5 w-3.5 mt-0.5 shrink-0",ee.iconClassName)}),(0,S.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,S.jsxs)("div",{className:V("text-[11px] font-semibold truncate",ee.labelClassName),children:[M.label,(0,S.jsxs)("span",{className:"text-[9px] text-white/30 font-mono ml-1.5",children:[M.suggestedScheme,"://"]})]}),(0,S.jsx)("div",{className:V("text-[9px] truncate",ee.detailClassName),children:M.description}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 font-mono truncate",children:M.root})]}),(0,S.jsx)($n,{className:"h-3 w-3 text-white/40 shrink-0 mt-1"})]})},M.id)})})]}):(0,S.jsx)("div",{className:"pt-1 text-[9px] italic text-white/35",children:"No discoverable mounts at the moment."})]})})]})]})}var jt=W(Je(),1),u0=W(ds(),1);var AL=W(nr(),1);async function fl(t){let e=await t.text();try{return JSON.parse(e)}catch{throw new Error(`Invalid JSON response (HTTP ${t.status}): ${e.slice(0,200)}`)}}async function wL(t){let e=await fetch("/api/packages/runtime",{method:"GET",headers:{"x-project-id":t},credentials:"same-origin"});if(!e.ok)throw new Error(`Failed to load packages snapshot: HTTP ${e.status}`);let n=await fl(e),r=[...n.skills,...n.instructions,...n.rules,...n.agents,...n.docs],a=o0(n.tools,o=>o.packageId),s=o0(r,o=>o.packageId),i=o0(n.commands,o=>o.packageId);return n.packages.map(o=>({slug:o.id,packageId:o.id,name:o.name,version:o.version,description:o.description,source:o.source,runtime:o.runtime,access:o.access,status:o.status,partialReason:o.partialReason,toolCount:a.get(o.id)??0,fileCount:s.get(o.id)??0,commandCount:i.get(o.id)??0,...o.accessFeature?{accessFeature:o.accessFeature,accessFeatureSource:o.accessFeatureSource}:{}}))}async function kL(t,e){let n=await fetch(`/api/projects/${encodeURIComponent(t)}/packages/${encodeURIComponent(e)}/build`,{method:"POST",credentials:"same-origin"});return fl(n)}async function SL(t,e,n){let r=await fetch(`/api/projects/${encodeURIComponent(t)}/packages/${encodeURIComponent(e)}/trust`,{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({trust:n})});if(!r.ok){let a=await r.text();throw new Error(`Failed to set trust (HTTP ${r.status}): ${a.slice(0,200)}`)}return fl(r)}async function CL(t,e,n){let r=await fetch(`/api/projects/${encodeURIComponent(t)}/packages/${encodeURIComponent(e)}/access-feature`,{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({featureId:n})});if(!r.ok){let a=await r.text();throw new Error(`Failed to set access feature (HTTP ${r.status}): ${a.slice(0,200)}`)}return fl(r)}async function IL(t){let e=await fetch("/api/admin/feature-catalog",{method:"GET",headers:{"x-project-id":t},credentials:"same-origin"});if(!e.ok)throw new Error(`Failed to load feature catalog: HTTP ${e.status}`);let n=await fl(e),r=new Set;for(let a of n.groups??[])for(let s of a.features??[])r.add(s);return Array.from(r).sort()}async function LL(t){let e=await fetch("/api/packages/agent-core/packages/diagnostics",{method:"GET",headers:{"x-project-id":t},credentials:"same-origin"});if(!e.ok)throw new Error(`Failed to load packages diagnostics: HTTP ${e.status}`);return fl(e)}function o0(t,e){let n=new Map;for(let r of t){let a=e(r);n.set(a,(n.get(a)??0)+1)}return n}var J=W(ue(),1),LE={"build-missing":{label:"Needs build",hint:"The package has server-side code (src/) but the WASM binary is missing. Click Build to compile it."},"runtime-unavailable":{label:"Runtime unavailable",hint:"MCP subprocess failed to spawn or the code runtime crashed. Check host logs."},"untrusted-node":{label:"Declarative only",hint:'Untrusted packages cannot execute in-process code. Declare `runtime.type: "wasm"` in the manifest to enable handlers.'},"untrusted-mcp":{label:"Declarative only",hint:'The "mcp" runtime spawns a subprocess as the host user and needs first-party trust, so no subprocess was started. Declare `runtime.type: "wasm"` in the manifest to enable handlers.'}};function PL({projectId:t}){let n=(Ln().currentRole?.priority??99)<=2,[r,a]=(0,jt.useState)([]),[s,i]=(0,jt.useState)(!0),[o,l]=(0,jt.useState)(null),[u,c]=(0,jt.useState)({}),[d,f]=(0,jt.useState)({}),[h,p]=(0,jt.useState)(null),[g,m]=(0,jt.useState)(!1);(0,jt.useEffect)(()=>{m(!0)},[]);let[x,b]=(0,jt.useState)(null),[y,C]=(0,jt.useState)([]),[I,L]=(0,jt.useState)(null),[v,k]=(0,jt.useState)([]),O=(0,jt.useCallback)(async()=>{i(!0),l(null);try{let A=await wL(t);a(A)}catch(A){l(A instanceof Error?A.message:String(A))}finally{i(!1)}try{let A=await LL(t);C(A.entries),L(null)}catch(A){C([]),L(A instanceof Error?A.message:String(A))}},[t]);(0,jt.useEffect)(()=>{O()},[O]),(0,jt.useEffect)(()=>{if(!n)return;let A=!1;return IL(t).then(F=>{A||k(F)}).catch(()=>{}),()=>{A=!0}},[t,n]);let R=(0,jt.useCallback)(A=>{c(F=>({...F,[A]:!F[A]}))},[]),P=(0,jt.useCallback)(async A=>{let F=A.access?.trust??"untrusted";if(F==="first-party")return;let _=F==="trusted"?"untrusted":"trusted";f(X=>({...X,[A.slug]:"trust"}));try{await SL(t,A.slug,_),p(`Trust: ${A.slug} \u2192 ${_}`),await O()}catch(X){p(X instanceof Error?X.message:"Failed to set trust")}finally{f(X=>({...X,[A.slug]:"none"}))}},[t,O]),H=(0,jt.useCallback)(async(A,F)=>{f(_=>({..._,[A.slug]:"access-feature"}));try{await CL(t,A.packageId,F),p(F?`Access feature: ${A.slug} \u2192 ${F}`:`Access feature cleared: ${A.slug}`),await O()}catch(_){p(_ instanceof Error?_.message:"Failed to set access feature")}finally{f(_=>({..._,[A.slug]:"none"}))}},[t,O]),w=(0,jt.useCallback)(async A=>{f(_=>({..._,[A.slug]:"build"})),b({slug:A.slug,logs:["Starting build\u2026"]});let F=null;try{F=await kL(t,A.slug),b({slug:A.slug,logs:F.logs,ok:F.ok,error:F.error,durationMs:F.durationMs}),F.ok?(p(`Build complete: ${A.slug} (${F.durationMs}ms)`),await O()):p(`Build failed: ${F.error??"unknown"}`)}catch(_){let X=_ instanceof Error?_.message:String(_);b({slug:A.slug,logs:[`Request failed: ${X}`],ok:!1,error:X}),p(`Build request failed: ${X}`)}finally{f(_=>({..._,[A.slug]:"none"}))}},[t,O]),N=(0,jt.useMemo)(()=>[...r].sort((A,F)=>A.name.localeCompare(F.name)),[r]),j=(0,jt.useMemo)(()=>{let A=new Set(r.map(F=>F.packageId));return y.filter(F=>!A.has(F.packageId)||F.status==="missing"||F.status==="error")},[y,r]),K=(0,jt.useMemo)(()=>{let A=new Map;for(let F of y)A.set(F.packageId,F);return A},[y]);return s?(0,J.jsxs)("div",{className:"h-full flex items-center justify-center text-white/50 text-sm",children:[(0,J.jsx)($e,{className:"w-4 h-4 animate-spin mr-2"})," Loading packages\u2026"]}):o?(0,J.jsx)("div",{className:"p-4",children:(0,J.jsxs)("div",{className:"rounded-lg border border-red-500/25 bg-red-500/10 p-3 text-xs text-red-100/85",children:[(0,J.jsx)("div",{className:"font-semibold mb-1",children:"Failed to load packages"}),(0,J.jsx)("div",{className:"font-mono opacity-80",children:o}),(0,J.jsxs)("button",{className:"mt-2 inline-flex items-center gap-1 rounded-md bg-white/10 px-2 py-1 text-[11px] text-white/80 hover:bg-white/15",onClick:()=>{O()},children:[(0,J.jsx)(Xt,{className:"w-3 h-3"})," Retry"]})]})}):(0,J.jsxs)("div",{className:"p-3 space-y-2",children:[(0,J.jsxs)("div",{className:"flex items-center justify-between px-1 pb-2",children:[(0,J.jsxs)("div",{className:"flex items-center gap-2",children:[(0,J.jsx)(Br,{className:"w-4 h-4 text-violet-300"}),(0,J.jsx)("h2",{className:"text-sm font-semibold text-white/85",children:"Packages"}),(0,J.jsxs)("span",{className:"text-[10px] text-white/45",children:[N.length," installed"]})]}),(0,J.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,J.jsx)(AL.SkillLauncher,{variant:"label",size:"sm",skill:"create-package",packageId:"@neuralis/brain-core",alsoRequires:["packages.author"],label:"Scaffold a package with the agent",icon:"package"}),(0,J.jsxs)("button",{className:"inline-flex items-center gap-1 rounded-md bg-white/5 px-2 py-1 text-[11px] text-white/60 hover:bg-white/10 hover:text-white/85",onClick:()=>{O()},children:[(0,J.jsx)(Xt,{className:"w-3 h-3"}),"Refresh"]})]})]}),(0,J.jsxs)("div",{className:"mx-1 rounded-lg border border-violet-500/15 bg-violet-500/5 px-3 py-2 text-[11px] text-violet-100/80 flex items-start gap-2",children:[(0,J.jsx)(zl,{className:"w-3.5 h-3.5 shrink-0 mt-0.5 text-violet-300/80"}),(0,J.jsxs)("div",{className:"space-y-1",children:[(0,J.jsx)("div",{children:"Untrusted packages register their declarative content (skills, tool schemas, commands) but cannot execute in-process code or call other packages."}),(0,J.jsxs)("div",{className:"text-violet-100/60",children:["Flip trust when you know the author. Run Build only for packages with server-side code in ",(0,J.jsx)("span",{className:"font-mono",children:"src/"}),"."]})]})]}),j.length>0&&(0,J.jsxs)("div",{className:"mx-1 rounded-lg border border-rose-500/25 bg-rose-500/[0.06] px-3 py-2 text-[11px] text-rose-100/85 space-y-1",children:[(0,J.jsxs)("div",{className:"flex items-center gap-1.5 text-rose-200/95 font-semibold",children:[(0,J.jsx)(gt,{className:"w-3 h-3"}),j.length," package",j.length===1?"":"s"," failed to load"]}),j.map(A=>(0,J.jsxs)("div",{className:"rounded border border-rose-500/15 bg-rose-500/[0.04] px-2 py-1",children:[(0,J.jsxs)("div",{className:"font-mono text-[10px] text-rose-200/95",children:[A.packageId," ",(0,J.jsxs)("span",{className:"text-rose-300/80",children:["\xB7 ",A.status]}),A.reason&&(0,J.jsxs)("span",{className:"text-rose-300/55",children:[" (",A.reason,")"]})]}),A.error&&(0,J.jsx)("div",{className:"mt-0.5 font-mono text-[10px] text-rose-100/70 whitespace-pre-wrap break-all",children:A.error}),A.sourceRoot&&(0,J.jsx)("div",{className:"mt-0.5 text-[9px] text-rose-200/50",children:(0,J.jsx)("span",{className:"font-mono",children:A.sourceRoot})})]},A.packageId))]}),I&&(0,J.jsxs)("div",{className:"mx-1 rounded-md border border-amber-500/25 bg-amber-500/[0.06] px-2 py-1 text-[10px] text-amber-100/80",children:[(0,J.jsx)("span",{className:"font-mono",children:"/packages/diagnostics"})," unreachable: ",I]}),N.length===0?(0,J.jsxs)("div",{className:"mx-1 mt-6 rounded-lg border border-white/10 bg-white/[0.02] p-6 text-center text-white/50 text-sm",children:["No packages installed yet. Drop packages into"," ",(0,J.jsx)("span",{className:"font-mono text-white/70",children:"_packages/"})," to see them here."]}):(0,J.jsx)("div",{className:"space-y-1",children:N.map(A=>(0,J.jsx)(AE,{row:A,expanded:!!u[A.slug],pending:d[A.slug]??"none",canGovern:n,featureIds:v,onToggle:()=>R(A.slug),onFlipTrust:()=>{P(A)},onBuild:()=>{w(A)},onSetAccessFeature:F=>{H(A,F)}},A.slug))}),h&&g?(0,u0.createPortal)((0,J.jsx)("div",{className:"fixed bottom-4 right-4 z-[100000] rounded-lg border border-white/15 bg-neutral-900/95 px-3 py-2 text-[11px] text-white/85 shadow-lg",onClick:()=>p(null),children:h}),document.body):null,x&&g?(0,u0.createPortal)((0,J.jsx)("div",{className:"fixed inset-0 z-[100000] flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>b(null),children:(0,J.jsxs)("div",{className:"w-full max-w-xl rounded-lg border border-white/15 bg-neutral-900/95 p-4 shadow-xl",onClick:A=>A.stopPropagation(),children:[(0,J.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,J.jsxs)("div",{className:"flex items-center gap-2",children:[x.ok===void 0?(0,J.jsx)($e,{className:"w-4 h-4 animate-spin text-white/60"}):x.ok?(0,J.jsx)(ha,{className:"w-4 h-4 text-emerald-400"}):(0,J.jsx)(gt,{className:"w-4 h-4 text-amber-300"}),(0,J.jsxs)("span",{className:"text-sm font-semibold text-white/85",children:["Build \u2014 ",x.slug]}),x.durationMs!==void 0?(0,J.jsxs)("span",{className:"text-[10px] text-white/45",children:[x.durationMs,"ms"]}):null]}),(0,J.jsx)("button",{className:"text-white/50 hover:text-white/80 text-xs",onClick:()=>b(null),children:"Close"})]}),(0,J.jsx)("pre",{className:"max-h-80 overflow-y-auto rounded-md bg-black/40 border border-white/10 p-2 text-[11px] font-mono text-white/75 whitespace-pre-wrap",children:x.logs.join(`
|
|
52
|
+
`)})]})}),document.body):null]})}function AE(t){let{row:e,expanded:n,pending:r,canGovern:a,featureIds:s,onToggle:i,onFlipTrust:o,onBuild:l,onSetAccessFeature:u}=t,c=e.access?.trust??"untrusted",d=e.runtime?.type??"node",f=e.partialReason,h=f?LE[f]:void 0,p=d==="wasm"&&e.status==="partial"&&f==="build-missing",g=c==="first-party";return(0,J.jsxs)("div",{className:"rounded-lg border border-white/10 bg-white/[0.02] hover:bg-white/[0.035] transition-colors",children:[(0,J.jsxs)("button",{type:"button",className:"w-full flex items-start gap-2 px-3 py-2 text-left",onClick:i,children:[n?(0,J.jsx)(qt,{className:"mt-0.5 w-3.5 h-3.5 shrink-0 text-white/50"}):(0,J.jsx)(Sn,{className:"mt-0.5 w-3.5 h-3.5 shrink-0 text-white/50"}),(0,J.jsx)(Br,{className:"mt-0.5 w-4 h-4 shrink-0 text-violet-300/80"}),(0,J.jsxs)("div",{className:"min-w-0 flex-1 space-y-1",children:[(0,J.jsxs)("div",{className:"flex items-baseline gap-1.5",children:[(0,J.jsx)("span",{className:"min-w-0 flex-1 text-sm font-semibold text-white/90 truncate",children:e.name}),e.version?(0,J.jsxs)("span",{className:"text-[10px] font-mono text-white/40 shrink-0",children:["v",e.version]}):null]}),e.description?(0,J.jsx)("div",{className:"text-[10px] text-white/45 truncate",children:e.description}):null,(0,J.jsxs)("div",{className:"flex flex-wrap items-center gap-1 pt-0.5",children:[(0,J.jsx)(RE,{status:e.status,partialLabel:h?.label}),(0,J.jsx)(NE,{trust:c}),(0,J.jsx)(ME,{type:d})]})]})]}),n?(0,J.jsxs)("div",{className:"px-3 pb-3 pt-1 border-t border-white/5 space-y-3",children:[f&&h?(0,J.jsxs)("div",{className:"rounded-md border border-amber-500/20 bg-amber-500/5 p-2 text-[11px] text-amber-100/80 flex items-start gap-2",children:[(0,J.jsx)(gt,{className:"w-3.5 h-3.5 shrink-0 mt-0.5 text-amber-300/80"}),(0,J.jsxs)("div",{children:[(0,J.jsx)("div",{className:"font-semibold",children:h.label}),(0,J.jsx)("div",{className:"text-amber-100/60",children:h.hint})]})]}):null,(0,J.jsxs)("div",{className:"grid grid-cols-3 gap-2 text-[10px]",children:[(0,J.jsx)(l0,{label:"Tools",value:e.toolCount}),(0,J.jsx)(l0,{label:"Skills / files",value:e.fileCount}),(0,J.jsx)(l0,{label:"Commands",value:e.commandCount})]}),(0,J.jsxs)("div",{className:"text-[10px] text-white/50 font-mono",children:[e.source?.kind?`source: ${e.source.kind}`:"",e.source?.kind&&d?" \xB7 ":"",`runtime: ${d}`]}),(0,J.jsxs)("div",{className:"flex items-center gap-2 pt-1",children:[(0,J.jsxs)("button",{type:"button",className:["inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] transition",g?"bg-white/5 text-white/35 cursor-not-allowed":c==="trusted"?"bg-emerald-500/15 border border-emerald-500/25 text-emerald-100 hover:bg-emerald-500/20":"bg-white/5 border border-white/10 text-white/70 hover:bg-white/10"].join(" "),disabled:g||r!=="none",onClick:o,title:g?"First-party packages are trust-locked":void 0,children:[r==="trust"?(0,J.jsx)($e,{className:"w-3 h-3 animate-spin"}):c==="trusted"?(0,J.jsx)(vo,{className:"w-3 h-3"}):(0,J.jsx)(Zl,{className:"w-3 h-3"}),c==="trusted"?"Revert to untrusted":"Mark as trusted"]}),(0,J.jsxs)("button",{type:"button",className:["inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] transition",p?"bg-violet-500/15 border border-violet-500/25 text-violet-100 hover:bg-violet-500/20":"bg-white/5 text-white/35 cursor-not-allowed"].join(" "),disabled:!p||r!=="none",onClick:l,title:p?"Compile src/ \u2192 dist/package.wasm on the server":d!=="wasm"?'Build is only required for runtime.type: "wasm" packages':"Build is only needed when status is partial / build-missing",children:[r==="build"?(0,J.jsx)($e,{className:"w-3 h-3 animate-spin"}):(0,J.jsx)(Ci,{className:"w-3 h-3"}),"Build"]}),(0,J.jsx)(TE,{trust:c})]}),a?(0,J.jsx)(PE,{row:e,featureIds:s,pending:r==="access-feature",disabled:r!=="none",onSetAccessFeature:u}):e.accessFeature?(0,J.jsxs)("div",{className:"mt-2 text-[10px] text-white/45",children:["Access feature: ",(0,J.jsx)("span",{className:"font-mono text-white/65",children:e.accessFeature}),(0,J.jsxs)("span",{className:"text-white/30",children:[" (",e.accessFeatureSource,")"]})]}):null]}):null]})}function PE(t){let{row:e,featureIds:n,pending:r,disabled:a,onSetAccessFeature:s}=t,[i,o]=(0,jt.useState)(e.accessFeature??""),l=`af-${e.slug}`;(0,jt.useEffect)(()=>{o(e.accessFeature??"")},[e.accessFeature]);let u=e.accessFeatureSource==="manifest",c=i.trim(),d=e.accessFeatureSource==="override"?e.accessFeature??"":"",f=c!==d;return(0,J.jsxs)("div",{className:"mt-2 rounded-md border border-white/10 bg-white/[0.02] px-2.5 py-2 space-y-1.5",children:[(0,J.jsxs)("div",{className:"flex items-center gap-1.5 text-[10px] font-semibold text-white/60",children:[(0,J.jsx)(zs,{className:"w-3 h-3 text-cyan-300/80"}),"Base-access feature",e.accessFeature?(0,J.jsxs)("span",{className:"ml-auto font-mono text-[9px] text-white/45",children:[e.accessFeature," ",(0,J.jsxs)("span",{className:"text-white/30",children:["(",e.accessFeatureSource,")"]})]}):null]}),(0,J.jsx)("div",{className:"text-[9px] text-white/40 leading-snug",children:u?"Declared in the manifest (requires.accessFeature) \u2014 not editable here. An override below adds an ADDITIONAL required feature.":"Pick a feature to hide this package from anyone who lacks it (restrict-only), then grant that feature to a role in Admin \u2192 Roles. Clear to remove."}),(0,J.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,J.jsx)("input",{list:l,value:i,onChange:h=>o(h.target.value),placeholder:"feature.id (e.g. labs.access)",disabled:a,className:"flex-1 min-w-0 rounded bg-black/30 border border-white/10 px-2 py-1 text-[10px] font-mono text-white/80 placeholder:text-white/25 focus:outline-none focus:border-cyan-400/40"}),(0,J.jsx)("datalist",{id:l,children:n.map(h=>(0,J.jsx)("option",{value:h},h))}),(0,J.jsxs)("button",{type:"button",disabled:a||!f||c.length===0,onClick:()=>s(c),className:"inline-flex items-center gap-1 rounded-md bg-cyan-500/15 border border-cyan-400/25 px-2 py-1 text-[10px] text-cyan-100 hover:bg-cyan-500/20 transition disabled:opacity-35",children:[r?(0,J.jsx)($e,{className:"w-3 h-3 animate-spin"}):null,"Set"]}),(0,J.jsx)("button",{type:"button",disabled:a||e.accessFeatureSource!=="override",onClick:()=>s(null),title:e.accessFeatureSource==="manifest"?"Manifest-declared features cannot be cleared here":"Clear the override",className:"inline-flex items-center gap-1 rounded-md bg-white/5 border border-white/10 px-2 py-1 text-[10px] text-white/65 hover:bg-white/10 transition disabled:opacity-35",children:"Clear"})]})]})}function RE(t){let{status:e,partialLabel:n}=t;return e==="partial"?(0,J.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-amber-500/25 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-100/85",children:[(0,J.jsx)(gt,{className:"w-2.5 h-2.5"})," ",n??"Partial"]}):e==="error"?(0,J.jsx)("span",{className:"inline-flex items-center gap-1 rounded-full border border-red-500/25 bg-red-500/10 px-2 py-0.5 text-[10px] text-red-100/85",children:"Error"}):e==="disabled"?(0,J.jsx)("span",{className:"rounded-full bg-white/10 px-2 py-0.5 text-[10px] text-white/55",children:"Disabled"}):(0,J.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-emerald-500/25 bg-emerald-500/10 px-2 py-0.5 text-[10px] text-emerald-100/85",children:[(0,J.jsx)(ha,{className:"w-2.5 h-2.5"})," Active"]})}function NE(t){let{trust:e}=t;return e==="first-party"?(0,J.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-sky-500/25 bg-sky-500/10 px-2 py-0.5 text-[10px] text-sky-100/85",children:[(0,J.jsx)(zs,{className:"w-2.5 h-2.5"})," First-party"]}):e==="trusted"?(0,J.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-emerald-500/25 bg-emerald-500/10 px-2 py-0.5 text-[10px] text-emerald-100/85",children:[(0,J.jsx)(vo,{className:"w-2.5 h-2.5"})," Trusted"]}):(0,J.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/15 bg-white/5 px-2 py-0.5 text-[10px] text-white/60",children:[(0,J.jsx)(Ea,{className:"w-2.5 h-2.5"})," Untrusted"]})}function ME(t){let{type:e}=t;return(0,J.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full bg-white/5 px-2 py-0.5 text-[10px] font-mono text-white/55 border border-white/10",children:[(0,J.jsx)(au,{className:"w-2.5 h-2.5 text-violet-300/70"}),e]})}function l0(t){return(0,J.jsxs)("div",{className:"rounded-md bg-white/[0.03] border border-white/5 px-2 py-1.5",children:[(0,J.jsx)("div",{className:"text-white/45",children:t.label}),(0,J.jsx)("div",{className:"text-white/85 font-mono mt-0.5",children:t.value})]})}function TE(t){let[e,n]=(0,jt.useState)(!1);return(0,J.jsxs)("div",{className:"relative",children:[(0,J.jsx)("button",{type:"button",className:"inline-flex items-center rounded-md bg-white/5 p-1 text-white/40 hover:text-white/70 hover:bg-white/10",onClick:()=>n(r=>!r),children:(0,J.jsx)(pa,{className:"w-3 h-3"})}),e?(0,J.jsxs)("div",{className:"absolute right-0 bottom-full mb-2 w-64 rounded-lg border border-white/15 bg-neutral-900/95 p-2.5 text-[11px] text-white/75 shadow-xl z-10",children:[(0,J.jsx)("div",{className:"font-semibold text-white/85 mb-1",children:t.trust==="trusted"?"Trusted":t.trust==="first-party"?"First-party":"Untrusted"}),(0,J.jsx)("div",{className:"text-white/60",children:t.trust==="first-party"?"Built-in package, full access \u2014 trust is locked.":t.trust==="trusted"?"Full fs / network / cross-package API. Only flip this when you trust the author.":"Data-only filesystem, no network, no cross-package API. Safe default for unknown packages."})]}):null]})}var Zn=W(Je(),1),KL=W(ds(),1);var Uf=W(Je(),1);var RL=W(Je(),1),cc=W(ue(),1),DE={add:"bg-emerald-500/12",remove:"bg-red-500/18",context:""},NL=(0,RL.memo)(function({lineNo:e,type:n,content:r}){return(0,cc.jsxs)("div",{className:`flex h-[18px] w-full ${DE[n]}`,children:[(0,cc.jsx)("span",{className:"shrink-0 w-10 text-right pr-2 select-none text-white/25 tabular-nums",children:e??""}),(0,cc.jsx)("span",{className:"shrink-0 whitespace-pre pr-3 text-white/78",children:r||" "})]})});var Ss=W(ue(),1),hl=(0,Uf.memo)(function({hunks:e,isStreaming:n,maxLines:r=200}){let{elements:a,truncated:s}=(0,Uf.useMemo)(()=>{let i=[],o=0,l=0,u=!1,c=1,d=1;for(let f of e){if(f.skippedBefore!==0){let h=f.skippedBefore>0?`\xB7\xB7\xB7 ${f.skippedBefore} lines skipped \xB7\xB7\xB7`:"\xB7\xB7\xB7 \xB7\xB7\xB7 \xB7\xB7\xB7";i.push((0,Ss.jsx)(FE,{label:h},`skip-${o}`)),f.skippedBefore>0&&(c+=f.skippedBefore,d+=f.skippedBefore)}for(let h of f.lines){if(l>=r){u=!0;break}let p=n?"add":h.type,g=p==="remove"?c:d;p==="remove"?c++:(p==="add"||c++,d++),i.push((0,Ss.jsx)(NL,{lineNo:g,type:p,content:h.content},`line-${o}`)),o++,l++}if(u)break}return{elements:i,truncated:u}},[e,n,r]);return a.length===0?(0,Ss.jsx)("div",{className:"px-3 py-2 text-[11px] text-white/40 italic",children:"No content"}):(0,Ss.jsx)("div",{className:"font-mono text-[11px] leading-[18px] overflow-x-auto overflow-y-clip",children:(0,Ss.jsxs)("div",{className:"min-w-full w-max",children:[a,s&&(0,Ss.jsxs)("div",{className:"w-full text-[10px] text-white/40 bg-white/4 px-3 py-1 text-center",children:["\xB7\xB7\xB7 ",e.reduce((i,o)=>i+o.lines.length,0)-r," more lines \xB7\xB7\xB7"]})]})})},(t,e)=>{if(t.isStreaming!==e.isStreaming||t.maxLines!==e.maxLines||t.language!==e.language)return!1;if(t.hunks===e.hunks)return!0;if(t.hunks.length!==e.hunks.length)return!1;for(let n=0;n<t.hunks.length;n++){let r=t.hunks[n],a=e.hunks[n];if(r===a)continue;if(r.skippedBefore!==a.skippedBefore||r.lines.length!==a.lines.length)return!1;let s=r.lines[0],i=a.lines[0];if(s?.type!==i?.type||s?.content!==i?.content)return!1;let o=r.lines[r.lines.length-1],l=a.lines[a.lines.length-1];if(o?.type!==l?.type||o?.content!==l?.content)return!1}return!0});function FE({label:t}){return(0,Ss.jsx)("div",{className:"w-full text-[10px] text-white/35 bg-white/[0.03] px-3 py-0.5 text-center border-y border-white/6 select-none",children:t})}var zf=W(fa(),1);function ML(t){return t.snapshotHash?null:"originalDraftUnknown"}function c0(t,e){return t.op!=="delete"&&t.op!=="create"&&!t.baselineMissing&&e.current.state==="missing"&&e.baselineProvenance==="journal-latest-write"&&(e.baseline.state==="text"||e.baseline.state==="binary"||e.baseline.state==="too-large")}function d0(t){return String(t||"").replace(/\r\n/g,`
|
|
53
53
|
`).split(`
|
|
54
|
-
`)}function
|
|
55
|
-
`):[]}function tl(t){return _E((0,Mf.parseSettledObject)(t))}function Tf(t,e){let n=e0(t),r=e0(e),a=n.length,s=r.length,i=Array.from({length:a+1},()=>new Array(s+1).fill(0));for(let c=a-1;c>=0;c--)for(let d=s-1;d>=0;d--)i[c][d]=n[c]===r[d]?i[c+1][d+1]+1:Math.max(i[c+1][d],i[c][d+1]);let o=[],l=0,u=0;for(;l<a&&u<s;)n[l]===r[u]?(o.push({type:"context",content:n[l]}),l++,u++):i[l+1][u]>=i[l][u+1]?(o.push({type:"remove",content:n[l]}),l++):(o.push({type:"add",content:r[u]}),u++);for(;l<a;)o.push({type:"remove",content:n[l++]});for(;u<s;)o.push({type:"add",content:r[u++]});return[{skippedBefore:0,lines:o}]}function Df(t){let e=0,n=0;for(let r of t)for(let a of r.lines)a.type==="add"?e++:a.type==="remove"&&n++;return{added:e,removed:n}}function Ju(t){for(let e of["content","file_content","text"]){let n=t[e];if(typeof n=="string")return n}if(typeof t.content=="object"&&t.content!==null)try{return JSON.stringify(t.content,null,2)}catch{}return null}function n0(t){if(!t||typeof t!="object"||Array.isArray(t))return null;let e=t;if(e.ok===!1)return null;let n=e.version;if(!n||typeof n!="object"||Array.isArray(n))return null;let r=n.diff;if(!r||typeof r!="object"||Array.isArray(r))return null;let a=r,s=typeof a.added=="number"?a.added:null,i=typeof a.removed=="number"?a.removed:null;return s==null||i==null?null:{added:s,removed:i}}function BE(t){let e=(0,Mf.extractPathsFromToolCall)(t);if(e.length===0){let r=tl(t.input),a=typeof r?.uri=="string"&&r.uri||typeof r?.path=="string"&&r.path||"";if(!a)return[];e=[a]}let n=n0(t.structuredContent);return e.map((r,a)=>a===0&&n?{path:r,diff:n}:{path:r})}var PL={tab:"changes",changes:BE},NL=["fs_write","fs_create","fs_modify"];function _E(t){if(!t||typeof t.action=="string"||!UE(t))return t;let e={};if(typeof t.uri=="string"&&(e.uri=t.uri),typeof t.id=="string"&&(e.id=t.id),typeof t.move=="string")return{...e,action:"move",destination:t.move};if(typeof t.copy=="string")return{...e,action:"copy",destination:t.copy};if(t.mkdir!==void 0)return{...e,action:"create_folder"};if(t.revert!==void 0)return{...e,action:"revert"};if(t.delete!==void 0)return{...e,action:"delete"};let n=Array.isArray(t.edit)?t.edit.filter(o=>!!o&&typeof o=="object").map(o=>({find:typeof o.old_string=="string"?o.old_string:"",replace:typeof o.new_string=="string"?o.new_string:""})).filter(o=>o.find.length>0):[];if(n.length>0)return{...e,action:"replace_text",edits:n};let r=Rf(t.lines);if(r&&typeof r.content=="string")return{...e,action:"replace_lines",content:r.content};let a=Rf(t.insert);if(a&&typeof a.insert_text=="string")return{...e,action:"insert",text:a.insert_text};let s=Rf(t.overwrite);if(s&&s.content!==void 0)return{...e,action:"update",content:s.content};let i=Rf(t.create);return i&&i.content!==void 0?{...e,content:i.content}:t.fields!==void 0?{...e,action:"set_fields",fields:t.fields}:t}var HE=["create","overwrite","edit","insert","lines","fields","move","copy","mkdir","revert","delete"];function UE(t){return HE.some(e=>t[e]!==void 0)}function Rf(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function ML(t){let e=new Map;for(let n of t)if(n.status)for(let[r,a]of[[!0,n.status.staged],[!1,[...n.status.unstaged,...n.status.untracked]]])for(let s of a){let i=`${n.source}://${[n.repo.rel,s.path].filter(Boolean).join("/")}`,o=e.get(i)??new Map,l=JSON.stringify([n.source,n.repo.rel,s.path]),u=o.get(l);u?(u.staged||=r,u.unstaged||=!r):o.set(l,{group:n,path:s.path,staged:r,unstaged:!r}),e.set(i,o)}return e}function Qu(t){return`${t.source}://${t.repo.rel}`}function r0(t){let e=Fs(t.source,t.repo.name);return e.prefix?`${e.prefix} ${e.name}`:e.name}function TL(t,e){return e.kind==="pending"?[]:t.filter(n=>(!e.source||n.source===e.source)&&(!e.repo||Qu(n)===e.repo)&&(!e.branch||n.status?.branch===e.branch))}function DL(t,e,n){return n.kind==="git"?[]:t.filter(r=>!(n.source&&r.sourceSlug!==n.source||n.agent&&r.agentId!==n.agent||n.origin&&r.origin!==n.origin||(n.repo||n.branch)&&!e.some(s=>r.sourceSlug===s.source&&zi(r.uri).startsWith(`${s.source}://${s.repo.rel?`${s.repo.rel}/`:""}`)&&(!n.repo||Qu(s)===n.repo)&&(!n.branch||s.status?.branch===n.branch)))).sort((r,a)=>r.createdAt<a.createdAt?-1:r.createdAt>a.createdAt?1:0)}function FL(t,e,n,r){let a=new Set(t.map(i=>zi(i.uri))),s=[];for(let i of e.keys())(n==="git"||!a.has(i))&&s.push({kind:"git",key:`git:${i}`,uri:i});return t.forEach((i,o)=>s.push({kind:r==="cards"?"pending-card":"pending-row",key:i.id,rec:i,index:o})),s}var GE=32,WE=346;function EL(t){return t==="pending-row"?GE:WE}function OL(t){return t!=="pending-row"}function BL(t,e,n=100,r){let a=[],s=[];for(let i of t)e.has(i.id)||(SL(i)||r?.(i.id)?.requiresAcknowledgement.length?s.push(i):a.length<n&&a.push(i));return{approvable:a,needsAck:s}}function a0(t){let e=t instanceof Error?t.message:String(t??"");return e.includes("PENDING_STATE_CHANGED")||e.includes("PENDING_GENERATION_CHANGED")?"changed":e.includes("CURRENT_STATE_ACKNOWLEDGEMENT_REQUIRED")?"needs-ack":"error"}var RL=new WeakMap;function Ff(t){if(t.diffState!=="readable")return null;let e=RL.get(t);return e||(e=Tf(t.baseline.state==="text"?t.baseline.text:"",t.current.state==="text"?t.current.text:""),RL.set(t,e)),e}var Hn=j($e(),1),UL=j(Za(),1);var ut=j(ie(),1),_L={originalDraftUnknown:{label:"Older change \u2014 original draft unknown",chip:"bg-amber-500/15 text-amber-200 border-amber-400/30"},externalChanged:{label:"Changed outside the review",chip:"bg-rose-500/15 text-rose-200 border-rose-400/30"},unreviewable:{label:"Diff not readable",chip:"bg-sky-500/15 text-sky-200 border-sky-400/30"},fresh:{label:"No confirmation needed now",chip:"bg-emerald-500/15 text-emerald-200 border-emerald-400/30"}},HL={ok:{label:"Done",tone:"text-emerald-300"},changed:{label:"Changed since the preview \u2014 check the fresh state and confirm again",tone:"text-amber-300"},"needs-ack":{label:"Still needs a confirmation",tone:"text-amber-300"},error:{label:"Refused",tone:"text-rose-300"}};async function Ef(t,e,n,r,a){let s={agentId:t.agentId,...t.projectId?{projectId:t.projectId}:{},id:e.id,expectedFingerprint:n.expectedFingerprint,...a?{acknowledgeCurrentState:!0}:{}};try{let i=r==="approve"?await fc({...s,uri:e.uri},t.client):r==="revert"?await Y0(s,t.client):await Z0(s,t.client);if(i&&i.ok===!1){let o="error"in i&&i.error?String(i.error):"Review refused";return{id:e.id,uri:e.uri,action:r,outcome:a0(o),detail:o}}return{id:e.id,uri:e.uri,action:r,outcome:"ok"}}catch(i){return{id:e.id,uri:e.uri,action:r,outcome:a0(i),detail:i instanceof Error?i.message:"Review refused"}}}function zE({rec:t,preview:e}){let n=(0,Hn.useMemo)(()=>Ff(e),[e]);return Qg(t,e)?(0,ut.jsx)("div",{className:"px-2.5 py-2 text-[10.5px] text-white/60 leading-relaxed",children:"The file is gone. Approving or dismissing accepts that it stays gone \u2014 nothing is recreated and the saved earlier version stays in history. Revert restores that version."}):n?(0,ut.jsx)("div",{className:"max-h-56 overflow-auto overlay-scroll",style:{scrollbarGutter:"auto"},children:(0,ut.jsx)(Zo,{hunks:n,language:Qo(t.uri),maxLines:400})}):(0,ut.jsxs)("div",{className:"px-2.5 py-2 text-[10.5px] text-white/50",children:["Diff ",e.diffState,": current ",e.current.state,", baseline ",e.baseline.state," (",e.baselineProvenance,")."]})}var ec="h-7 px-2.5 rounded-md text-[11px] font-medium transition disabled:opacity-40 inline-flex items-center gap-1.5";function GL({request:t,agentId:e,projectId:n,run:r,onClose:a,onDone:s,next:i=0,onNext:o,refetch:l,onBatchStart:u}){let c=H(R=>R.client),d=(0,Hn.useMemo)(()=>t.kind==="single"?[t.rec]:t.records,[t]),[f,h]=(0,Hn.useState)(()=>t.kind==="single"&&t.preview?{[t.rec.id]:t.preview}:{}),[p,g]=(0,Hn.useState)(!1),[m,x]=(0,Hn.useState)({}),y=(0,Hn.useRef)(!0),b=(0,Hn.useRef)(new Map);(0,Hn.useEffect)(()=>(y.current=!0,()=>{y.current=!1}),[]);let C=(0,Hn.useCallback)((R,U=!1)=>{let v=(b.current.get(R.id)??0)+1;b.current.set(R.id,v);let T=()=>y.current&&b.current.get(R.id)===v;(U&&l?l(R):r(()=>Xi({agentId:e,...n?{projectId:n}:{},id:R.id},c),T)).then(Y=>{T()&&Y&&h(N=>({...N,[R.id]:Y}))},Y=>{T()&&h(N=>({...N,[R.id]:Y instanceof Error?Y:new Error("Preview failed")}))})},[e,n,r,l]);(0,Hn.useEffect)(()=>{for(let R of d)!f[R.id]&&!b.current.has(R.id)&&C(R)},[d,C]);let L=(0,Hn.useMemo)(()=>{let R=new Map;for(let U of d){let v=f[U.id];if(!v||v instanceof Error)continue;let T=v.requiresAcknowledgement[0]??"fresh";R.set(T,[...R.get(T)??[],U])}return R},[d,f]),P=d.filter(R=>!f[R.id]).length,w=R=>m[R.id]!==void 0&&m[R.id].outcome!=="changed",k=t.kind==="group"&&P===0&&!p&&d.every(R=>w(R)||f[R.id]instanceof Error),_=(0,Hn.useCallback)(async(R,U)=>{g(!0),u?.();let v=[];for(let T of R){let V=f[T.id];if(!V||V instanceof Error||m[T.id]?.outcome==="ok")continue;let Y=await Ef({agentId:e,projectId:n,client:c},T,V,U,V.requiresAcknowledgement.length>0);v.push(Y),x(N=>({...N,[T.id]:Y})),Y.outcome==="changed"&&(h(N=>{let{[T.id]:A,...B}=N;return B}),C(T,!0))}g(!1),s(v)},[f,m,e,n,s,C,u]);if(typeof document>"u")return null;let M=t.kind==="single"?t:null;return(0,UL.createPortal)((0,ut.jsx)("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/40 backdrop-blur-[1px]",onMouseDown:p?void 0:a,children:(0,ut.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":"Review pending changes",onMouseDown:R=>R.stopPropagation(),className:"w-[min(640px,92vw)] max-h-[82vh] flex flex-col rounded-xl border border-amber-400/25 bg-[#15151d] shadow-[0_30px_80px_-24px_rgba(0,0,0,0.85)]",children:[(0,ut.jsxs)("div",{className:"flex items-start gap-2.5 p-4 pb-2 shrink-0",children:[(0,ut.jsx)(Sa,{className:"h-4 w-4 text-amber-300 shrink-0 mt-0.5"}),(0,ut.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,ut.jsx)("div",{className:"text-[12px] font-semibold text-white/90",children:M?`Review the current state \u2014 ${M.action}`:t.kind==="group"&&t.total>d.length?`${d.length} of ${t.total} changes need your confirmation`:`${d.length} changes need your confirmation`}),(0,ut.jsx)("div",{className:"mt-1 text-[10.5px] text-white/55 leading-relaxed",children:"Each change is checked against its own fresh preview. Confirming accepts the state shown here; a change that moves again before you confirm is refused and stays in the list."}),P>0?(0,ut.jsxs)("div",{className:"mt-1.5 inline-flex items-center gap-1.5 text-[10.5px] text-white/45",children:[(0,ut.jsx)(We,{className:"h-3 w-3 animate-spin"})," Loading ",P," preview",P>1?"s":"","\u2026"]}):null]})]}),(0,ut.jsxs)("div",{className:"min-h-0 flex-1 overflow-auto overlay-scroll px-4 space-y-3",children:[[...L].map(([R,U])=>(0,ut.jsxs)("section",{className:"rounded-lg border border-white/8 bg-black/20",children:[(0,ut.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1.5 border-b border-white/5",children:[(0,ut.jsxs)("span",{className:`inline-flex items-center rounded-full border px-2 py-0.5 text-[10px] font-semibold ${_L[R].chip}`,children:[_L[R].label," \xB7 ",U.length]}),M?null:(0,ut.jsxs)("div",{className:"ml-auto flex items-center gap-1.5",children:[(0,ut.jsxs)("button",{type:"button",disabled:p||U.every(w),onClick:()=>{_(U,"dismiss")},className:`${ec} bg-white/[0.04] hover:bg-white/[0.08] text-white/70`,children:[(0,ut.jsx)(ta,{className:"h-3 w-3"})," Confirm & dismiss ",U.length]}),(0,ut.jsxs)("button",{type:"button",disabled:p||U.every(w),onClick:()=>{_(U,"approve")},className:`${ec} bg-emerald-500/20 hover:bg-emerald-500/30 border border-emerald-400/40 text-emerald-100 font-semibold`,children:[(0,ut.jsx)(gs,{className:"h-3 w-3"})," Confirm & approve ",U.length]})]})]}),U.map(v=>{let T=f[v.id],V=m[v.id];return(0,ut.jsxs)("div",{className:"border-b border-white/5 last:border-0",children:[(0,ut.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1 text-[10.5px]",children:[(0,ut.jsx)("span",{className:"min-w-0 flex-1 truncate font-mono text-white/70",title:v.uri,children:v.uri}),V?(0,ut.jsx)("span",{className:HL[V.outcome].tone,title:V.detail,children:HL[V.outcome].label}):null]}),(0,ut.jsx)(zE,{rec:v,preview:T})]},v.id)})]},R)),d.filter(R=>f[R.id]instanceof Error).map(R=>(0,ut.jsxs)("div",{className:"rounded-md bg-rose-500/10 px-2.5 py-1.5 text-[10.5px] text-rose-200/90",children:[R.uri,": ",f[R.id].message]},R.id))]}),(0,ut.jsxs)("div",{className:"flex items-center justify-end gap-2 p-4 pt-3 shrink-0",children:[(0,ut.jsxs)("button",{type:"button",onClick:a,disabled:p,className:`${ec} bg-white/[0.04] hover:bg-white/[0.08] text-white/70`,children:[(0,ut.jsx)(Ht,{className:"h-3 w-3"})," ",Object.keys(m).length?"Close":"Cancel"]}),k&&o&&i>0?(0,ut.jsxs)("button",{type:"button",onClick:()=>o(d.map(R=>R.id)),className:`${ec} border border-amber-400/40 bg-amber-500/15 hover:bg-amber-500/25 text-amber-100 font-semibold`,children:[(0,ut.jsx)(Sa,{className:"h-3 w-3"})," Next batch (",i," left)"]}):null,M?["revert","dismiss","approve"].map(R=>{let U=R===M.action,v=R==="approve"?Dn:R==="revert"?Ca:ta,T=R==="revert"?"border border-rose-400/40 bg-rose-500/15 hover:bg-rose-500/25 text-rose-100":U?"border border-emerald-400/40 bg-emerald-500/20 hover:bg-emerald-500/30 text-emerald-100 font-semibold":"bg-white/[0.04] hover:bg-white/[0.08] text-white/70";return(0,ut.jsxs)("button",{type:"button",disabled:p||P>0||m[M.rec.id]?.outcome==="ok",onClick:()=>{_([M.rec],R)},className:`${ec} ${T}`,children:[(0,ut.jsx)(v,{className:"h-3 w-3"})," ",U?`Confirm & ${R}`:R[0].toUpperCase()+R.slice(1)]},R)}):null]})]})}),document.body)}var J=j(ie(),1),jL={create:(0,J.jsx)(Ss,{className:"w-3.5 h-3.5 text-emerald-300/80"}),modify:(0,J.jsx)(vs,{className:"w-3.5 h-3.5 text-sky-300/80"}),delete:(0,J.jsx)(Nt,{className:"w-3.5 h-3.5 text-red-300/80"}),move:(0,J.jsx)(Tl,{className:"w-3.5 h-3.5 text-violet-300/80"})},VL=t=>t==="approved"?"bg-emerald-400":t==="reverted"?"bg-white/30":"bg-amber-400";function qL({diff:t}){return!t||t.added===0&&t.removed===0?null:(0,J.jsxs)("span",{className:"font-mono text-[10px] shrink-0",children:[t.added>0?(0,J.jsxs)("span",{className:"text-emerald-300",children:["+",t.added]}):null,t.added>0&&t.removed>0?" ":null,t.removed>0?(0,J.jsxs)("span",{className:"text-red-300",children:["\u2212",t.removed]}):null]})}var $L=(0,J.jsxs)("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-rose-500/15 text-rose-200/90 text-[10px] shrink-0",title:"The backing file no longer exists \u2014 this change can only be discarded.",children:[(0,J.jsx)(zl,{className:"w-3 h-3"})," Orphaned"]});function KL({orphaned:t,busy:e,onApprove:n,onRevert:r,onDiscard:a,onDismiss:s,className:i}){let o=(0,J.jsx)(Of.LiveSpinner,{className:"w-3.5 h-3.5"});return(0,J.jsx)("div",{className:i,children:t?(0,J.jsx)("button",{type:"button",onClick:a,disabled:e,title:"Discard (remove this un-actionable change)",className:"p-1 rounded hover:bg-rose-500/15 text-rose-300/80 disabled:opacity-40",children:e?o:(0,J.jsx)(Nt,{className:"w-3.5 h-3.5"})}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)("button",{type:"button",onClick:n,disabled:e,title:"Approve",className:"p-1 rounded hover:bg-emerald-500/15 text-emerald-300/80 disabled:opacity-40",children:e?o:(0,J.jsx)(Dn,{className:"w-3.5 h-3.5"})}),(0,J.jsx)("button",{type:"button",onClick:r,disabled:e,title:"Revert",className:"p-1 rounded hover:bg-red-500/15 text-red-300/80 disabled:opacity-40",children:(0,J.jsx)(Ca,{className:"w-3.5 h-3.5"})}),(0,J.jsx)("button",{type:"button",onClick:s,disabled:e,title:"Dismiss (stop reviewing \u2014 keep the change, no revert)",className:"p-1 rounded hover:bg-white/10 text-white/50 hover:text-white/80 disabled:opacity-40",children:(0,J.jsx)(ta,{className:"w-3.5 h-3.5"})})]})})}function WL({uri:t,rows:e,agentId:n,projectId:r,canWrite:a,revisions:s,queue:i}){let o=e.get(zi(t));return o?(0,J.jsx)(J.Fragment,{children:[...o.values()].map(l=>(0,J.jsx)(fe.default.Fragment,{children:[!0,!1].filter(u=>u?l.staged:l.unstaged).map(u=>(0,J.jsxs)("div",{children:[(0,J.jsxs)("div",{className:"px-3 py-1 text-[10px] text-white/40",children:[l.group.repo.name," (",l.group.repo.rel||"root",") \xB7 ",u?"Git HEAD \u2192 index (staged)":"Git index \u2192 working file (unstaged/untracked)"]}),(0,J.jsx)("div",{className:"max-h-72 overflow-auto overlay-scroll",style:{scrollbarGutter:"auto"},children:(0,J.jsx)(bi,{source:l.group.source,repo:l.group.repo.rel,path:l.path,mode:{kind:"working",staged:u},agentId:n,projectId:r,variant:"card",canWrite:a&&l.group.repo.canWrite===!0,revision:s[l.group.source]??0,runContent:i.run,peekContent:i.peek})})]},String(u)))},`${l.group.source}/${l.group.repo.rel}/${l.path}`))}):null}var XL=(t,e)=>`preview\0${t.id}\0${t.updatedAt}\0${e}`,jE=t=>2*((t.baseline.state==="text"?t.baseline.text.length:0)+(t.current.state==="text"?t.current.text.length:0))+256,VE=(0,fe.memo)(function({rec:e,agentId:n,projectId:r,focused:a,orphaned:s,onOpen:i,onApprove:o,onRevert:l,onDiscard:u,onDismiss:c,onFocus:d,busy:f,queue:h,revision:p,canWrite:g,onPreview:m,peekPreview:x,takeRefetch:y,extra:b}){let C=H(re=>re.client),[L,P]=(0,fe.useState)(!0),[w,k]=(0,fe.useState)(()=>x(e.id)??null),[_,M]=(0,fe.useState)(!1),[R,U]=(0,fe.useState)(null),[v,T]=(0,fe.useState)(""),V=(0,fe.useRef)(0),Y=h.visible.has(e.id),N=(0,fe.useRef)(!1);N.current=L&&Y;let A=XL(e,p),B=(0,fe.useRef)("");(0,fe.useEffect)(()=>{let re=++V.current;if(!L||!Y||B.current===A){M(!1);return}let he=y(e.id,A);if(he==="wait"){M(!0);return}if(he){k(he),U(null),T(A),B.current=A,M(!1);return}return M(!0),h.run(()=>Xi({agentId:n,...r?{projectId:r}:{},id:e.id},C),()=>re===V.current&&N.current,{key:A,bytes:jE}).then(Ne=>{!Ne||re!==V.current||!N.current||(m(Ne),k(Ne),U(null),T(A),B.current=A,M(!1))}).catch(Ne=>{re===V.current&&(U(Ne instanceof Error?Ne.message:"Failed to load review"),M(!1))}),()=>{V.current++}},[n,r,e.id,A,L,Y,h.run]);let K=(0,fe.useMemo)(()=>w?Ff(w):null,[w]),te=(0,fe.useMemo)(()=>K?Df(K):null,[K]),ne=v===A?w?.indexState??null:null,pe=R??(w&&w.diffState!=="readable"?`Review diff unavailable: ${w.diffState}; current ${w.current.state}, baseline ${w.baseline.state}.`:null),Se=(0,fe.useCallback)(()=>P(re=>!re),[]),le=e.diff&&(e.diff.added>0||e.diff.removed>0)?e.diff:te??void 0;return(0,J.jsxs)("div",{ref:re=>h.register(e.id,re),onMouseDown:d,className:`rounded-lg border overflow-hidden transition-colors ${s?"border-rose-400/30 bg-rose-500/[0.04]":a?"border-amber-400/40 ring-1 ring-amber-400/25 bg-amber-400/[0.03]":"border-white/8 bg-black/20"}`,children:[(0,J.jsxs)("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 px-2.5 py-1.5",children:[(0,J.jsx)("button",{type:"button",onClick:Se,"aria-expanded":L,className:"text-white/40 hover:text-white/80 shrink-0",children:L?(0,J.jsx)(Et,{className:"w-3.5 h-3.5"}):(0,J.jsx)(un,{className:"w-3.5 h-3.5"})}),jL[e.op],(0,J.jsxs)("button",{type:"button",onClick:()=>i(e.uri),className:"min-w-[6rem] flex-1 text-left truncate text-xs text-white/85 hover:text-white",title:e.uri,children:[gt(e.uri)||e.uri,(0,J.jsxs)("span",{className:"ml-1.5 text-[10px] text-white/30 font-mono",children:[et(e.uri),"/"]})]}),(0,J.jsx)(qL,{diff:le}),ne&&ne!=="stored"?(0,J.jsx)("span",{className:"text-[10px] text-amber-200/80 shrink-0",children:ne==="missing"?"Index missing":ne==="stale"?"Index stale":"Recovery only"}):null,s?$L:e.status==="approved"||e.status==="reverted"?(0,J.jsx)("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${VL(e.status)}`,title:e.status}):null,g?(0,J.jsx)(KL,{orphaned:s,busy:f,onApprove:o,onRevert:l,onDiscard:u,onDismiss:c,className:"ml-auto flex items-center gap-1 shrink-0"}):null]}),L?(0,J.jsxs)("div",{className:"border-t border-white/5",children:[(0,J.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1 text-[10px] text-white/40",children:["Review baseline \u2192 current file",_&&w?(0,J.jsx)(Of.LiveSpinner,{className:"w-3 h-3"}):null]}),(0,J.jsx)("div",{className:"max-h-72 overflow-auto overlay-scroll",style:{scrollbarGutter:"auto"},children:_&&!w?(0,J.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-xs text-white/40",children:[(0,J.jsx)(Of.LiveSpinner,{className:"w-3.5 h-3.5"})," Loading diff\u2026"]}):pe?(0,J.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-xs text-red-300/80",children:[(0,J.jsx)(ot,{className:"w-3.5 h-3.5"})," ",pe]}):K?(0,J.jsx)(Zo,{hunks:K,language:Qo(e.uri),maxLines:600}):null})]}):null,L?b:null]})}),nl="bg-transparent border border-white/8 rounded px-1.5 py-0.5 text-white/70",rl={background:"var(--w-composer-bg-rgb, rgba(20,20,28,1))"},qE={kind:"all",source:"",repo:"",branch:"",agent:"",origin:""},tc=100;function YL({agentId:t,projectId:e}){let n=H(z=>z.client),r=hn(),a=Ja({grantedFeatures:[...r.grantedFeatures??[]]},"drive.write"),s=ti(),i=H(z=>z.sources),o=H(z=>z.sourceChangeRevision),[l,u]=(0,fe.useState)(null),c=l??o,d=(0,fe.useRef)(o);d.current=o;let f=(0,fe.useRef)(o),h=(0,fe.useCallback)(()=>u(z=>z??d.current),[]),p=H(z=>z.pendingPanelFilter),g=H(z=>z.setPendingPanelFilter),m=H(z=>z.openFile),x=H(z=>z.removeFilePath),y=H(z=>z.setActiveWorkspaceTab),b=H(z=>z.refreshPendingCount),C=p.conversationId??"",[L,P]=(0,fe.useState)(null),w=Pc(L),k=(0,fe.useRef)(new Map),_=(0,fe.useCallback)(z=>k.current.get(z),[]),M=(0,fe.useRef)(new Map),R=(0,fe.useRef)(Promise.withResolvers()),U=(0,fe.useCallback)((z,I)=>{let q=M.current.get(z);return q===null?"wait":(q&&M.current.delete(z),q?.key===I?q.preview:void 0)},[]),[v,T]=(0,fe.useState)(qE),V=z=>I=>T(q=>({...q,[z]:I.target.value})),[Y,N]=(0,fe.useState)("cards"),[A,B]=(0,fe.useState)([]),[K,te]=(0,fe.useState)(new Set),[ne,pe]=(0,fe.useState)(!1),[Se,le]=(0,fe.useState)(null),[re,he]=(0,fe.useState)(null),[Ne,Ee]=(0,fe.useState)({}),ze=(0,fe.useRef)({nonces:Ne,revisions:c});ze.current={nonces:Ne,revisions:c};let ct=(0,fe.useCallback)(async z=>{M.current.set(z.id,null);try{let I=(await R.current.promise)?.find(de=>de.id===z.id)??z,q=await Xi({agentId:t,...e?{projectId:e}:{},id:z.id},n),F=(ze.current.nonces[z.id]??0)+1+(ze.current.revisions[I.sourceSlug]??0);return M.current.set(z.id,{key:XL(I,F),preview:q}),k.current.set(z.id,q),q}catch(I){throw M.current.delete(z.id),I}finally{Ee(I=>({...I,[z.id]:(I[z.id]??0)+1}))}},[t,e]),[it,Qe]=(0,fe.useState)(0),[Ye,Lt]=(0,fe.useState)(null),[Le,at]=(0,fe.useState)([]),[ft,bt]=(0,fe.useState)(!1),[At,Tt]=(0,fe.useState)(!1),[Ue,me]=(0,fe.useState)(!1),[Ot,Jt]=(0,fe.useState)(!1),[ue,be]=(0,fe.useState)(new Set),Ge=(0,fe.useRef)(null),Re=(0,fe.useRef)(0),Te=wL({agentId:t,projectId:e,sources:i,revisions:c,resetKey:`${t}\0${e}\0${C}`}),vt=(0,fe.useCallback)(async z=>{if(!t)return;let I=++Re.current;pe(!0),le(null);try{let q=await K0({agentId:t,...e?{projectId:e}:{},...C?{conversationId:C}:{},...z?{include_orphans:!0}:{}},n);if(I!==Re.current)return;let F=new Set(q.changes.map(de=>de.id));return B(q.changes),te(de=>z?new Set(q.orphanIds):new Set([...de].filter(D=>F.has(D)))),q.changes}catch(q){I===Re.current&&le(q instanceof Error?q.message:"Failed to load changes");return}finally{I===Re.current&&pe(!1)}},[t,e,C]),mt=(0,fe.useCallback)(async()=>{await Promise.all([vt(!0),Te.refresh(!0)]),b({agentId:t,projectId:e})},[vt,Te.refresh,b,t,e]);(0,fe.useEffect)(()=>(k.current.clear(),Lt(null),B([]),te(new Set),at([]),vt(!0),()=>{Re.current++,k.current.clear()}),[vt]);let Gt=(0,fe.useRef)(vt);Gt.current=vt;let je=(0,fe.useRef)(!0);(0,fe.useEffect)(()=>{if(je.current){je.current=!1;return}c!==f.current&&Gt.current(!1)},[c]);let kt=Te.groups,on=(0,fe.useMemo)(()=>Array.from(new Set([...A.map(z=>z.sourceSlug),...kt.map(z=>z.source)])).sort(),[A,kt]),Oe=(0,fe.useMemo)(()=>Array.from(new Set(A.map(z=>z.agentId).filter(Boolean))).sort(),[A]),ee=(0,fe.useMemo)(()=>Array.from(new Set(A.map(z=>z.origin).filter(Boolean))).sort(),[A]),oe=(0,fe.useMemo)(()=>DL(A,kt,v),[A,kt,v]),He=(0,fe.useMemo)(()=>TL(kt,v),[kt,v]),Ve=(0,fe.useMemo)(()=>ML(He),[He]),Ae=(0,fe.useMemo)(()=>FL(oe,Ve,v.kind,Y),[oe,Ve,v.kind,Y]),[ce,Pt]=(0,fe.useState)(0),{approvable:Ft,needsAck:Zt}=(0,fe.useMemo)(()=>BL(oe,K,tc,_),[oe,K,_,ce]),dn=(0,fe.useRef)(new Set),rr=Zt.filter(z=>!dn.current.has(z.id)),qr=(0,fe.useCallback)(z=>{for(let q of z)dn.current.add(q);let I=Zt.filter(q=>!dn.current.has(q.id));Lt({kind:"group",records:I.slice(0,tc),total:I.length})},[Zt]),Mn=(0,fe.useRef)(Ae);Mn.current=Ae;let Yn=(0,fe.useCallback)(z=>EL(Mn.current[z]?.kind??"pending-card"),[]),$r=(0,fe.useCallback)(z=>Mn.current[z]?.key??z,[]),ar=lo({count:Ae.length,getScrollElement:()=>L,estimateSize:Yn,getItemKey:$r,overscan:4});ar.shouldAdjustScrollPositionOnItemSizeChange=$E,(0,fe.useEffect)(()=>{Qe(z=>oe.length===0?0:Math.min(z,oe.length-1))},[oe.length]);let Pr=Ae.length-oe.length;(0,fe.useEffect)(()=>{oe.length>0&&ar.scrollToIndex(Pr+it,{align:"auto"})},[it,Y]);let Kr=(0,fe.useCallback)(z=>{m({agentId:t,projectId:e,uri:z}),y("file")},[t,e,m,y]),ln=(0,fe.useCallback)(z=>{if(z.op!=="delete"||!z.uri)return;let I=s.getState().files[z.uri];(!I||I.status==="deleted")&&x(z.uri)},[x,s]),Jn=(0,fe.useCallback)(async z=>{for(let F of z){let de=A.find(D=>D.id===F.id);de&&F.outcome==="ok"&&F.action!=="revert"&&ln(de),F.outcome!=="ok"&&F.outcome!=="needs-ack"&&!M.current.has(F.id)&&k.current.delete(F.id)}let I=z.filter(F=>F.outcome!=="ok"&&F.outcome!=="needs-ack"&&!M.current.has(F.id));I.length&&Ee(F=>{let de={...F};for(let D of I)de[D.id]=(de[D.id]??0)+1;return de}),at(z);let q=await vt(!1);f.current=s.getState().sourceChangeRevision,u(null),R.current.resolve(q),R.current=Promise.withResolvers(),b({agentId:t,projectId:e})},[A,ln,vt,b,t,e,s]),Wt=(0,fe.useCallback)(async(z,I)=>{if(!a)return;let q=k.current.get(z.id);if(!q||q.requiresAcknowledgement.length){Lt({kind:"single",rec:z,action:I,...q?{preview:q}:{}});return}he(z.id);try{await Jn([await Ef({agentId:t,projectId:e,client:n},z,q,I,!1)])}finally{he(null)}},[a,t,e,Jn]),gr=(0,fe.useCallback)(async z=>{he(z.id);try{let I=await J0({agentId:t,...e?{projectId:e}:{},id:z.id},n);I.ok?ln(z):le(I.error||"Discard failed"),await vt(!1),b({agentId:t,projectId:e})}catch(I){le(I instanceof Error?I.message:"Discard failed")}finally{he(null)}},[t,e,vt,ln,b]),Un=(0,fe.useCallback)(async()=>{Ge.current&&(clearTimeout(Ge.current),Ge.current=null),Jt(!0),me(!1),le(null);try{await Q0({agentId:t,...e?{projectId:e}:{},...C?{conversationId:C}:{}},n);let z=A.filter(q=>K.has(q.id)),I=await vt(!0);if(I){let q=new Set(I.map(F=>F.id));for(let F of z)q.has(F.id)||ln(F)}b({agentId:t,projectId:e})}catch(z){le(z instanceof Error?z.message:"Repair failed")}finally{Jt(!1)}},[t,e,C,vt,A,K,ln,b]),Nr=(0,fe.useCallback)(()=>{if(Ue){Un();return}me(!0),Ge.current&&clearTimeout(Ge.current),Ge.current=setTimeout(()=>me(!1),3e3)},[Ue,Un]);(0,fe.useEffect)(()=>()=>{Ge.current&&clearTimeout(Ge.current)},[]);let pa=(0,fe.useCallback)(async()=>{bt(!0),Tt(!1),le(null),h();let z=[];try{for(let I of Ft){let q=k.current.get(I.id);if(!q){try{q=await Xi({agentId:t,...e?{projectId:e}:{},id:I.id},n)}catch(F){z.push({id:I.id,uri:I.uri,action:"approve",outcome:"error",detail:F instanceof Error?F.message:"Preview failed"});continue}k.current.set(I.id,q)}if(q.requiresAcknowledgement.length){z.push({id:I.id,uri:I.uri,action:"approve",outcome:"needs-ack"});continue}z.push(await Ef({agentId:t,projectId:e,client:n},I,q,"approve",!1))}}finally{bt(!1);let I=Ft.filter(q=>z.some(F=>F.id===q.id&&F.outcome==="needs-ack"));I.length&&Pt(q=>q+1),await Jn(z),I.length&&a&&(dn.current.clear(),Lt({kind:"group",records:I.slice(0,tc),total:I.length}))}},[Ft,t,e,Jn,a]),fn=(0,fe.useCallback)(z=>Qe(I=>oe.length===0?0:Math.max(0,Math.min(oe.length-1,I+z))),[oe.length]),Xr=(0,fe.useCallback)(z=>{if(re||ft||!a||Ye)return;let I=oe[it],q=I?K.has(I.id):!1;z.key==="ArrowDown"||z.key==="ArrowRight"?(z.preventDefault(),fn(1)):z.key==="ArrowUp"||z.key==="ArrowLeft"?(z.preventDefault(),fn(-1)):q&&I&&(z.key==="d"||z.key==="r"||z.key==="Enter")?(z.preventDefault(),gr(I)):(z.key==="a"||z.key==="Enter")&&I?(z.preventDefault(),Wt(I,"approve")):z.key==="r"&&I?(z.preventDefault(),Wt(I,"revert")):z.key==="x"&&!q&&I&&(z.preventDefault(),Wt(I,"dismiss"))},[re,ft,a,Ye,oe,it,K,fn,gr,Wt]),ma=z=>{if(z.kind==="git"){let D=!ue.has(z.uri);return(0,J.jsxs)("div",{ref:xe=>w.register(z.uri,xe),className:"rounded-lg border border-white/8 bg-black/20",children:[(0,J.jsx)("button",{type:"button","aria-expanded":D,className:"px-3 py-2 text-xs text-white/85",onClick:()=>be(xe=>{let Mt=new Set(xe);return Mt.has(z.uri)?Mt.delete(z.uri):Mt.add(z.uri),Mt}),children:z.uri}),D?(0,J.jsx)(WL,{uri:z.uri,rows:Ve,agentId:t,projectId:e,canWrite:a,revisions:c,queue:w}):null]})}let{rec:I,index:q}=z,F=K.has(I.id),de={onApprove:()=>{Wt(I,"approve")},onRevert:()=>{Wt(I,"revert")},onDiscard:()=>{gr(I)},onDismiss:()=>{Wt(I,"dismiss")}};return z.kind==="pending-card"?(0,J.jsx)(VE,{rec:I,agentId:t,projectId:e,focused:q===it,orphaned:F,onOpen:Kr,...de,onFocus:()=>Qe(q),busy:re===I.id,queue:w,revision:(Ne[I.id]??0)+(c[I.sourceSlug]??0),canWrite:a,onPreview:D=>{k.current.set(I.id,D),D.requiresAcknowledgement.length&&Pt(xe=>xe+1)},peekPreview:_,takeRefetch:U,extra:v.kind==="all"?(0,J.jsx)(WL,{uri:I.uri,rows:Ve,agentId:t,projectId:e,canWrite:a,revisions:c,queue:w}):null}):(0,J.jsxs)("div",{onMouseDown:()=>Qe(q),className:`group h-8 flex items-center gap-2 px-2 rounded-lg ${q===it?"bg-amber-400/[0.06] ring-1 ring-amber-400/20":"hover:bg-white/5"}`,children:[jL[I.op],(0,J.jsxs)("button",{type:"button",onClick:()=>Kr(I.uri),className:"min-w-0 flex-1 text-left truncate text-xs text-white/85 hover:text-white",title:I.uri,children:[gt(I.uri)||I.uri,(0,J.jsxs)("span",{className:"ml-1.5 text-[10px] text-white/30 font-mono",children:[et(I.uri),"/"]})]}),(0,J.jsx)(qL,{diff:I.diff}),F?$L:(0,J.jsx)("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${VL(I.status)}`,title:I.status}),a?(0,J.jsx)(KL,{orphaned:F,busy:re===I.id,...de,className:"hidden group-hover:flex items-center gap-0.5 shrink-0"}):null]})},xn=Le.filter(z=>z.outcome!=="ok"),Tn=ne||Te.loading;return(0,J.jsxs)("div",{className:"w-full h-full flex flex-col min-h-0 outline-none",tabIndex:0,onKeyDown:Xr,children:[a&&Ye?(0,J.jsx)(GL,{request:Ye,agentId:t,projectId:e,run:w.run,onClose:()=>Lt(null),next:Ye.kind==="group"?rr.filter(z=>!Ye.records.some(I=>I.id===z.id)).length:0,onNext:qr,refetch:ct,onBatchStart:h,onDone:z=>{for(let I of z)dn.current.add(I.id);Jn(z)}},Ye.kind==="group"?`group\0${Ye.records[0]?.id??""}`:`single\0${Ye.rec.id}`):null,(0,J.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5 px-3 py-2 border-b border-white/5 shrink-0",children:[(0,J.jsx)("span",{className:"text-xs font-semibold text-white/80",children:"Changes"}),(0,J.jsx)("span",{className:"text-[10px] text-white/35",children:oe.length>0?`${Math.min(it+1,oe.length)}/${oe.length}`:"0"}),(0,J.jsxs)("div",{className:"ml-auto flex flex-wrap items-center justify-end gap-1",children:[(0,J.jsxs)("div",{className:"flex items-center rounded-lg border border-white/8 overflow-hidden",children:[(0,J.jsx)("button",{type:"button",onClick:()=>fn(-1),disabled:oe.length===0||it===0,className:"p-1.5 text-white/45 hover:text-white/80 disabled:opacity-30",title:"Previous (\u2191)",children:(0,J.jsx)(bl,{className:"w-3.5 h-3.5"})}),(0,J.jsx)("button",{type:"button",onClick:()=>fn(1),disabled:oe.length===0||it>=oe.length-1,className:"p-1.5 text-white/45 hover:text-white/80 disabled:opacity-30",title:"Next (\u2193)",children:(0,J.jsx)(un,{className:"w-3.5 h-3.5"})})]}),a?At?(0,J.jsxs)("button",{type:"button",onClick:()=>{pa()},disabled:ft||Ft.length===0,className:"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-emerald-500/30 bg-emerald-500/15 px-2 py-1 text-[10px] text-emerald-100 hover:bg-emerald-500/20 disabled:opacity-40",title:`Approve ${Ft.length} visible change(s) that need no confirmation`,children:[ft?(0,J.jsx)(We,{className:"w-3 h-3 animate-spin"}):(0,J.jsx)(gs,{className:"w-3 h-3"})," Approve ",Ft.length,"?"]}):(0,J.jsxs)("button",{type:"button",onClick:()=>Tt(!0),disabled:Ft.length===0,className:"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-white/8 px-2 py-1 text-[10px] text-white/55 hover:text-white/85 hover:bg-white/5 disabled:opacity-30",title:"Approve every visible change that needs no confirmation",children:[(0,J.jsx)(gs,{className:"w-3 h-3"})," Approve ",Ft.length]}):null,a&&Zt.length>0?(0,J.jsxs)("button",{type:"button",onClick:()=>{dn.current.clear(),Lt({kind:"group",records:Zt.slice(0,tc),total:Zt.length})},className:"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-amber-400/30 px-2 py-1 text-[10px] text-amber-200/90 hover:bg-amber-500/10",title:`Review the changes that need your confirmation, grouped by reason (up to ${tc} at a time)`,children:[(0,J.jsx)(Sa,{className:"w-3 h-3"})," ",Zt.length," need confirmation"]}):null,(0,J.jsxs)("div",{className:"flex items-center rounded-lg border border-white/8 overflow-hidden",children:[(0,J.jsx)("button",{type:"button",onClick:()=>N("list"),title:"Compact list",className:`p-1.5 ${Y==="list"?"bg-white/10 text-white":"text-white/45 hover:text-white/80"}`,children:(0,J.jsx)(ni,{className:"w-3.5 h-3.5"})}),(0,J.jsx)("button",{type:"button",onClick:()=>N("cards"),title:"Diff cards",className:`p-1.5 ${Y==="cards"?"bg-white/10 text-white":"text-white/45 hover:text-white/80"}`,children:(0,J.jsx)(Ka,{className:"w-3.5 h-3.5"})})]}),a&&K.size>0?(0,J.jsxs)("button",{type:"button",onClick:Nr,disabled:Ot,className:Ue?"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-rose-500/40 bg-rose-500/15 px-2 py-1 text-[10px] text-rose-100 hover:bg-rose-500/25 disabled:opacity-40":"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-rose-400/25 px-2 py-1 text-[10px] text-rose-200/80 hover:text-rose-100 hover:bg-rose-500/10 disabled:opacity-40",title:Ue?`Discard all ${K.size} orphaned change(s)`:"Repair \u2014 discard orphaned changes whose backing file no longer exists",children:[Ot?(0,J.jsx)(We,{className:"w-3 h-3 animate-spin"}):Ue?(0,J.jsx)(Nt,{className:"w-3 h-3"}):(0,J.jsx)(ci,{className:"w-3 h-3"}),Ue?`Discard ${K.size}?`:`Repair ${K.size}`]}):null,(0,J.jsx)("button",{type:"button",onClick:()=>{mt()},disabled:Tn,title:"Refresh",className:"p-1.5 rounded-lg text-white/45 hover:text-white/80 hover:bg-white/5 disabled:opacity-40",children:(0,J.jsx)(_t,{className:`w-3.5 h-3.5 ${Tn?"animate-spin":""}`})}),(0,J.jsx)(zL.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-files",packageId:"@neuralis/brain-core",scripts:["scripts/pending.sh","scripts/approve.sh"],label:"Review or approve pending changes with the agent",icon:"FileText"})]})]}),(0,J.jsxs)("div",{className:"flex flex-wrap items-center gap-2 px-3 py-1.5 border-b border-white/5 shrink-0 text-[11px]",children:[C?(0,J.jsxs)("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-violet-500/15 text-violet-200/90",title:C,children:["conversation ",(0,J.jsx)("button",{type:"button",onClick:()=>g({}),className:"rounded hover:bg-violet-400/20 -mr-0.5",title:"Clear conversation filter",children:(0,J.jsx)(Ht,{className:"w-3 h-3"})})]}):null,(0,J.jsxs)("select",{"aria-label":"Change type",value:v.kind,onChange:V("kind"),className:nl,style:rl,children:[(0,J.jsx)("option",{value:"all",children:"All changes"}),(0,J.jsx)("option",{value:"pending",children:"Pending review"}),(0,J.jsx)("option",{value:"git",children:"Git"})]}),(0,J.jsxs)("select",{"aria-label":"Source",value:v.source,onChange:V("source"),className:nl,style:rl,children:[(0,J.jsx)("option",{value:"",children:"All sources"}),on.map(z=>(0,J.jsx)("option",{value:z,children:z},z))]}),(0,J.jsxs)("select",{"aria-label":"Repository",value:v.repo,onChange:V("repo"),className:nl,style:rl,children:[(0,J.jsx)("option",{value:"",children:"All repositories"}),kt.map(z=>(0,J.jsx)("option",{value:Qu(z),children:r0(z)},Qu(z)))]}),(0,J.jsxs)("select",{"aria-label":"Checked-out branch",value:v.branch,onChange:V("branch"),className:nl,style:rl,children:[(0,J.jsx)("option",{value:"",children:"All checked-out branches"}),[...new Set(kt.map(z=>z.status?.branch).filter(Boolean))].map(z=>(0,J.jsx)("option",{value:z,children:z},z))]}),Oe.length>1?(0,J.jsxs)("select",{"aria-label":"Agent",value:v.agent,onChange:V("agent"),className:nl,style:rl,children:[(0,J.jsx)("option",{value:"",children:"All agents"}),Oe.map(z=>(0,J.jsx)("option",{value:z,children:z},z))]}):null,ee.length>1?(0,J.jsxs)("select",{"aria-label":"Origin",value:v.origin,onChange:V("origin"),className:nl,style:rl,children:[(0,J.jsx)("option",{value:"",children:"All origins"}),ee.map(z=>(0,J.jsx)("option",{value:z,children:z},z))]}):null]}),He.filter(z=>z.error).map(z=>(0,J.jsxs)("div",{className:"px-3 py-2 text-xs text-red-300 shrink-0",children:[r0(z),": ",z.error]},`${z.source}/${z.repo.rel}`)),Se?(0,J.jsxs)("div",{className:"mx-3 mt-2 flex items-center gap-2 rounded-lg border border-red-500/25 bg-red-500/10 px-2.5 py-1.5 text-[11px] text-red-200/85 shrink-0",children:[(0,J.jsx)(ot,{className:"w-3.5 h-3.5"})," ",Se]}):null,xn.length?(0,J.jsxs)("div",{className:"mx-3 mt-2 max-h-28 overflow-auto overlay-scroll rounded-lg border border-amber-500/25 bg-amber-500/[0.06] px-2.5 py-1.5 text-[10.5px] text-amber-100/85 shrink-0",children:[(0,J.jsxs)("div",{className:"flex items-center gap-2 font-semibold",children:[Le.length-xn.length," done \xB7 ",xn.length," not done",(0,J.jsx)("button",{type:"button",onClick:()=>at([]),className:"ml-auto rounded hover:bg-white/10",title:"Dismiss",children:(0,J.jsx)(Ht,{className:"w-3 h-3"})})]}),xn.map(z=>(0,J.jsxs)("div",{className:"truncate font-mono",title:z.detail,children:[z.action," ",z.uri,": ",z.outcome==="changed"?"changed since the preview (409)":z.outcome==="needs-ack"?"needs confirmation \u2014 opened in the review dialog":z.detail??"refused"]},z.id))]}):null,(0,J.jsx)("div",{ref:P,className:"flex-1 min-h-0 overflow-auto overlay-scroll px-2 py-2",style:{overflowAnchor:"none"},children:Tn&&Ae.length===0?(0,J.jsxs)("div",{className:"flex items-center gap-2 px-3 py-6 text-xs text-white/40",children:[(0,J.jsx)(We,{className:"w-3.5 h-3.5 animate-spin"})," Loading\u2026"]}):Ae.length===0?(0,J.jsx)("div",{className:"px-3 py-8 text-center text-xs text-white/35",children:"No pending review changes."}):(0,J.jsx)("div",{style:{height:ar.getTotalSize(),width:"100%",position:"relative"},children:ar.getVirtualItems().map(z=>{let I=Ae[z.index];return I?(0,J.jsx)("div",{"data-index":z.index,ref:OL(I.kind)?ar.measureElement:void 0,className:I.kind==="pending-row"?"":"pb-1.5",style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${z.start}px)`},children:ma(I)},z.key):null})})})]})}var $E=(t,e,n)=>t.end<=(n.scrollOffset??0);var X=j(ie(),1),KE=2e5,XE=2500,YE=12e3;function JL(t,e){let n=String(t||"").trim().replace(/\\/g,"/");if(!n)return e;if(n.includes("://")){let s=n.indexOf("://"),i=n.slice(0,s),o=n.slice(s+3).replace(/\/+/g,"/").replace(/^\/+/,"");return`${i}://${o}`}let r=sr(e),a=n.replace(/\/+/g,"/").replace(/^\/+/,"");return a?`${r}${a}`:e}function s0(){let t=H(F=>F.client),e=H(F=>F.openFiles),n=H(F=>F.activeFile),r=H(F=>F.files),a=H(F=>F.fileContentByPath),s=H(F=>F.fileBaseContentByPath),i=H(F=>F.fileErrorByPath),o=H(F=>F.openFile),l=H(F=>F.patchFileNode),u=H(F=>F.saveFileInPlace),c=H(F=>F.markFileDeleted),d=H(F=>F.clearFilePrev),f=H(F=>F.refresh),h=H(F=>F.activeProjectId),p=H(F=>F.workspacePanels),g=H(F=>F.setWorkspacePanelOpen),m=H(F=>F.activeWorkspaceTab),x=H(F=>F.setActiveWorkspaceTab),y=H(F=>F.gitDiffTarget),b=H(F=>F.setGitDiffTarget),C=H(F=>F.gitCommitTarget),L=H(F=>F.setGitCommitTarget),P=H(F=>F.diffViewMode),w=H(F=>F.activeAgentId),k=hn(),_=k.useAgents(),M=(0,yt.useMemo)(()=>Ms(_),[_]),R=w?M.byId.get(w)??null:null,U=k.MarkdownRenderer,v=n?r[n]:null,T=n?a[n]??"":"",V=v?.uri??"",Y=v?JE(V):!1,N=v?ZE(V):!1,A=v?QE(V):!1,B=v?eO(V):!1,K=v?nO(V):!1,te=v?rd(V):void 0,ne=v?tO(V):"Binary file",pe=Y,[Se,le]=(0,yt.useState)(!1),[re,he]=(0,yt.useState)(""),[Ne,Ee]=(0,yt.useState)(""),[ze,ct]=(0,yt.useState)(!1),[it,Qe]=(0,yt.useState)(null),[Ye,Lt]=(0,yt.useState)(!1),[Le,at]=(0,yt.useState)(!1),[ft,bt]=(0,yt.useState)(!1),[At,Tt]=(0,yt.useState)(!1),[Ue,me]=(0,yt.useState)(!0),[Ot,Jt]=(0,yt.useState)(!1),ue=H(F=>F.filePrevByPath),be=n?ue[n]:void 0,Ge=!!be&&v?.status==="pending_review",Re=!!be,Te=(0,yt.useMemo)(()=>v?v.sourceAgentId?M.byId.get(v.sourceAgentId)??null:R:null,[v,M,R]),vt=n?i[n]:void 0,mt=!!n&&!mc({fileBaseContentByPath:s,fileErrorByPath:i},n),Gt=vt?`Read failed: ${vt}`:mt?"Loading\u2026":"Empty file",je=v?.status==="deleted",kt=p.upload&&m==="upload",on=p.sources&&m==="sources",Oe=p.packages&&m==="packages",ee=p.pending&&m==="pending",oe=m==="git-diff"&&!!y,He=m==="git-commit"&&!!C,Ve=!kt&&!on&&!Oe&&!ee&&!oe&&!He,Ae=v?.sourceAgentId??w??void 0,ce=v?.sourceAgentId??w??null,Pt=(0,yt.useMemo)(()=>!v?.uri||!Ae?null:ex(Ae,v.uri,h??void 0),[v?.uri,Ae,h]),Ft=(0,yt.useRef)(null),Zt=(0,yt.useRef)(null),dn=(0,ZL.useContainerWidth)(Zt),rr=P==="auto"?dn?"split":"unified":P,[qr,Mn]=(0,yt.useState)(void 0),Yn=v?.git;(0,yt.useEffect)(()=>{let F=!1;if(!ce||!V||!Yn||N||A||B){Mn(void 0);return}let de=qe(V),D=V.indexOf("://"),xe=D>=0?V.slice(D+3):"";if(!de||!xe){Mn(void 0);return}return(async()=>{try{let Mt=await lc({agentId:ce,...h?{projectId:h}:{},source:de,path:xe,staged:!1},t);if(F)return;if(Mt&&Mt.ok===!1){Mn(void 0);return}let zt=typeof Mt?.diff=="string"?Mt.diff:"",yn=E1(zt);Mn(ld(yn)?void 0:yn)}catch{F||Mn(void 0)}})(),()=>{F=!0}},[ce,h,V,Yn,N,A,B]);let $r=fi(v?.version?.changedAt),ar=v?.version?.sync,Pr=!0,Kr=!!v&&Se&&(Ne!==T||JL(re,v.uri)!==v.uri),ln=v?.version?.diff,Jn=!!ln&&(ln.added>0||ln.removed>0),Wt=!!v&&yp(v),gr=(0,yt.useMemo)(()=>{if(!v)return"/";if(v.parentUri&&v.parentUri!==v.uri)return v.parentUri;let F=et(v.uri);return F===v.uri?sr(v.uri):F},[v]),Un=(0,yt.useMemo)(()=>rO(T),[T]),Nr=v?.readSource==="live",pa=!!v&&!Se&&!N&&!A&&(K||Un.charCount>=KE||Un.lineCount>=XE||Nr&&Un.charCount>=YE),fn=(0,yt.useCallback)(async()=>{if(!(!ce||!v||Ye)){Lt(!0),Qe(null);try{await c({agentId:ce,projectId:h??null,node:v})}catch(F){console.error("[Filesystem] delete failed",F),Qe(F instanceof Error?F.message:"Delete failed")}finally{Lt(!1)}}},[ce,v,Ye,h,c]),Xr=(0,yt.useCallback)(async()=>{if(!(!ce||!v||Le)){at(!0);try{let F=await yr({agentId:ce,...h?{projectId:h}:{},id:v.id,uri:v.uri,fields:{status:"active"}},t);if(F&&F.ok===!1){Qe(ga(F,"Restore failed"));return}f({agentId:ce,projectId:h??null}),o({agentId:ce,projectId:h??null,uri:v.uri,readAgentId:Te?.id,force:!0})}catch(F){console.error("[Filesystem] restore failed",F)}finally{at(!1)}}},[ce,v,Le,h,f,o,Te?.id]),ma=(0,yt.useCallback)(async()=>{if(!(!ce||!v||ft)){if(v.status==="pending_review"){g("pending",!0),x("pending");return}bt(!0);try{let F=await fc({agentId:ce,...h?{projectId:h}:{},id:v.id,uri:v.uri},t);if(F&&F.ok){let de=v.storeKey||n||Va(v);de&&(l(de,{status:"active"}),d(de)),o({agentId:ce,projectId:h??null,uri:v.uri,readAgentId:Te?.id,force:!0})}}catch(F){console.error("[Filesystem] approve failed",F)}finally{bt(!1)}}},[ce,v,ft,h,o,Te?.id,n,l,d]),xn=(0,yt.useCallback)(async()=>{if(!(!ce||!v||At)){if(v.status==="pending_review"){g("pending",!0),x("pending");return}Tt(!0);try{let F=await yr({agentId:ce,...h?{projectId:h}:{},id:v.id,uri:v.uri,revert:!0},t);if(F&&F.ok===!1){Qe(ga(F,"Revert failed"));return}if(F&&F.ok){let de=v.storeKey||n||Va(v);de&&(l(de,{status:be?.status||"active"}),d(de)),o({agentId:ce,projectId:h??null,uri:v.uri,readAgentId:Te?.id,force:!0})}}catch(F){console.error("[Filesystem] revert failed",F)}finally{Tt(!1)}}},[ce,v,At,h,o,Te?.id,n,be,l,d]);(0,yt.useEffect)(()=>{if(!v){Ft.current=null,le(!1),Jt(!1),he(""),Ee(""),Qe(null);return}let F=v.storeKey||n||Va(v),de=Ft.current!==F;if(Ft.current=F,de){le(!1),Jt(!1),me(!0),he(v.uri),Ee(T),Qe(null);return}Se||(he(v.uri),Ee(T),Qe(null))},[v?.storeKey,v?.uri,T,n,Se]);let Tn=(0,yt.useCallback)(()=>{Wt&&Jt(F=>!F)},[Wt]),z=(0,yt.useCallback)(()=>{!v||je||(he(v.uri),Ee(T),Qe(null),le(!0))},[v,T,je]),I=(0,yt.useCallback)(()=>{v&&(he(v.uri),Ee(T),Qe(null),le(!1))},[v,T]),q=(0,yt.useCallback)(async()=>{if(!v||!ce||ze)return;let F=v.uri,de=JL(re,F);if(!de){Qe("Invalid target URI");return}ct(!0),Qe(null);try{await u({agentId:ce,projectId:h??null,readAgentId:Te?.id,node:v,targetUri:de,content:Ne,currentContent:T}),me(!0),le(!1)}catch(D){Qe(D instanceof Error?D.message:"Save failed")}finally{ct(!1)}},[v,ce,ze,re,Ne,T,h,Te?.id,u]);return(0,X.jsxs)("div",{className:"h-full w-full flex flex-col min-w-0 min-h-0",children:[e.length>0||p.upload||Pr&&p.sources||p.packages||p.pending||y||C?(0,X.jsxs)("div",{className:"flex shrink-0 items-stretch",style:{backgroundColor:"transparent",borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,X.jsxs)("div",{[ud]:"",className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden",children:[(0,X.jsx)(_1,{}),p.upload?(0,X.jsxs)("div",{className:"group flex shrink-0 items-center",children:[(0,X.jsxs)("button",{type:"button",className:$("flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",kt?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>x("upload"),children:[(0,X.jsx)(Ia,{className:"w-3.5 h-3.5 shrink-0"}),(0,X.jsx)("span",{className:"truncate flex-1",children:"Upload"})]}),(0,X.jsx)("button",{type:"button","aria-label":"Close Upload",className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:F=>{F.stopPropagation(),g("upload",!1)},children:(0,X.jsx)(Ht,{className:"w-3 h-3"})})]}):null,Pr&&p.sources?(0,X.jsxs)("div",{className:"group flex shrink-0 items-center",children:[(0,X.jsxs)("button",{type:"button",className:$("flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",on?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>x("sources"),children:[(0,X.jsx)(ui,{className:"w-3.5 h-3.5 shrink-0"}),(0,X.jsx)("span",{className:"truncate flex-1",children:"Sources"})]}),(0,X.jsx)("button",{type:"button","aria-label":"Close Sources",className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:F=>{F.stopPropagation(),g("sources",!1)},children:(0,X.jsx)(Ht,{className:"w-3 h-3"})})]}):null,p.packages?(0,X.jsxs)("div",{className:"group flex shrink-0 items-center",children:[(0,X.jsxs)("button",{type:"button",className:$("flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",Oe?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>x("packages"),children:[(0,X.jsx)(wr,{className:"w-3.5 h-3.5 shrink-0"}),(0,X.jsx)("span",{className:"truncate flex-1",children:"Packages"})]}),(0,X.jsx)("button",{type:"button","aria-label":"Close Packages",className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:F=>{F.stopPropagation(),g("packages",!1)},children:(0,X.jsx)(Ht,{className:"w-3 h-3"})})]}):null,p.pending?(0,X.jsxs)("div",{className:"group flex shrink-0 items-center",children:[(0,X.jsxs)("button",{type:"button",className:$("flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",ee?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>x("pending"),children:[(0,X.jsx)(Ka,{className:"w-3.5 h-3.5 shrink-0"}),(0,X.jsx)("span",{className:"truncate flex-1",children:"Changes"})]}),(0,X.jsx)("button",{type:"button","aria-label":"Close Changes",className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:F=>{F.stopPropagation(),g("pending",!1)},children:(0,X.jsx)(Ht,{className:"w-3 h-3"})})]}):null,y?(0,X.jsxs)("div",{className:"group flex shrink-0 items-center",children:[(0,X.jsxs)("button",{type:"button",className:$("flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",oe?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>x("git-diff"),title:`Diff: ${xi(y.repo,y.path)} (${e1(y)})`,children:[(0,X.jsx)(or,{className:"w-3.5 h-3.5 shrink-0 text-violet-300/80"}),(0,X.jsx)("span",{className:"truncate flex-1",children:xi(y.repo,gt(y.path)||y.path)})]}),(0,X.jsx)("button",{type:"button","aria-label":"Close Git diff",className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:F=>{F.stopPropagation(),b(null),oe&&x("file")},children:(0,X.jsx)(Ht,{className:"w-3 h-3"})})]}):null,C?(0,X.jsxs)("div",{className:"group flex shrink-0 items-center",children:[(0,X.jsxs)("button",{type:"button",className:$("flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",He?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>x("git-commit"),title:C.kind==="commit"?xi(C.repo,`Commit ${tn(C.sha)}: ${C.subject}`):xi(C.repo,`Outgoing changes (${tn(C.base)}..${tn(C.head)})`),children:[C.kind==="commit"?(0,X.jsx)(Dr,{className:"w-3.5 h-3.5 shrink-0 text-violet-300/80"}):(0,X.jsx)(Mr,{className:"w-3.5 h-3.5 shrink-0 text-blue-300/80"}),(0,X.jsx)("span",{className:"truncate flex-1",children:C.kind==="commit"?xi(C.repo,`${tn(C.sha)} ${C.subject}`):xi(C.repo,"Outgoing changes")})]}),(0,X.jsx)("button",{type:"button","aria-label":"Close Git commit",className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:F=>{F.stopPropagation(),L(null)},children:(0,X.jsx)(Ht,{className:"w-3 h-3"})})]}):null]}),(0,X.jsx)(H1,{})]}):null,Ve&&v?(0,X.jsxs)("div",{className:"flex items-center justify-between gap-2 px-2 py-1.5 text-[11px]",style:{backgroundColor:"transparent",borderBottom:!Ot||!Wt?"1px solid rgba(255,255,255,0.05)":"none"},children:[(0,X.jsxs)("div",{className:$("min-w-0 flex-1 flex items-center gap-2 rounded-lg px-1.5 py-1 transition",Wt?"cursor-pointer hover:bg-white/[0.04]":""),role:Wt?"button":void 0,tabIndex:Wt?0:void 0,"aria-expanded":Wt?Ot:void 0,onClick:Tn,onKeyDown:F=>{Wt&&(F.key==="Enter"||F.key===" ")&&(F.preventDefault(),Tn())},children:[Jn?(0,X.jsxs)("span",{className:$("inline-flex shrink-0 items-center gap-1 rounded-full border px-2 py-1 text-[10px]",$r.pillClassName),children:[(0,X.jsx)(or,{className:$("w-3 h-3",$r.iconClassName)}),(0,X.jsxs)("span",{className:"text-emerald-200/95",children:["+",ln.added]}),(0,X.jsx)("span",{className:"text-white/25",children:"/"}),(0,X.jsxs)("span",{className:"text-rose-200/95",children:["-",ln.removed]})]}):null,(0,X.jsxs)("div",{className:"min-w-0 flex-1",children:[Se?(0,X.jsx)("input",{value:re,onChange:F=>he(F.target.value),onClick:F=>F.stopPropagation(),onKeyDown:F=>F.stopPropagation(),className:"h-7 w-full rounded-md bg-white/[0.04] border border-white/[0.12] px-2 text-[11px] font-mono text-white/85 outline-none focus:border-white/[0.2]",disabled:ze}):(0,X.jsxs)("div",{className:"min-w-0 flex items-center gap-2",title:`${qe(v.uri)} \xB7 ${v.uri}`,children:[(0,X.jsx)("span",{className:$("shrink-0 text-white/88 font-medium",v.status==="deleted"?"line-through text-red-200/70":""),children:v.name}),(0,X.jsx)("span",{className:"truncate font-mono text-white/42",children:gr})]}),vt?(0,X.jsx)("div",{className:"text-[10px] text-red-300/80 truncate",title:vt,children:"Read failed"}):null,it?(0,X.jsx)("div",{className:"text-[10px] text-red-300/80 truncate",title:it,children:it}):null]}),Wt?(0,X.jsx)(Et,{className:$("w-3.5 h-3.5 shrink-0 text-white/35 transition-transform",Ot&&"rotate-180")}):null]}),(0,X.jsxs)("div",{className:"flex items-center gap-2",children:[Se?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-emerald-500/15 border border-emerald-500/25 p-1.5 text-emerald-100 hover:bg-emerald-500/20 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:q,disabled:ze||!ce,"aria-label":"Save changes",children:ze?(0,X.jsx)(We,{className:"w-3 h-3 animate-spin"}):(0,X.jsx)(Dn,{className:"w-3 h-3"})}),(0,X.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/70 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:I,disabled:ze,"aria-label":"Cancel edit",children:(0,X.jsx)(Ht,{className:"w-3 h-3"})})]}):(0,X.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/60 hover:text-white/80 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:z,disabled:!ce||je||B,title:B?"Binary files cannot be edited in-place":"Edit in-place","aria-label":"Edit in-place",children:(0,X.jsx)(si,{className:"w-3 h-3"})}),(0,X.jsx)("button",{type:"button",className:$("inline-flex items-center justify-center rounded-md p-1.5 transition","border border-red-500/15 bg-red-500/10 text-red-300/70 hover:text-red-200 hover:bg-red-500/15","disabled:opacity-40 disabled:cursor-not-allowed"),onClick:fn,disabled:!ce||Ye||Le,title:"Mark as deleted","aria-label":"Mark as deleted",children:Ye?(0,X.jsx)(We,{className:"w-3 h-3 animate-spin"}):(0,X.jsx)(Nt,{className:"w-3 h-3"})}),(0,X.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/60 hover:text-white/80 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>{!ce||!v||o({agentId:ce,projectId:h??null,uri:v.uri,readAgentId:Te?.id,force:!0})},title:"Reload file","aria-label":"Reload file",children:(0,X.jsx)(_t,{className:"w-3 h-3"})}),!Se&&Re&&v?.status!=="pending_review"?(0,X.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/60 hover:text-white/80 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:xn,disabled:At||ft||!ce,title:"Undo to previous version","aria-label":"Undo to previous version",children:At?(0,X.jsx)(We,{className:"w-3 h-3 animate-spin"}):(0,X.jsx)(Ca,{className:"w-3 h-3"})}):null]})]}):null,Ve&&v&&Ot&&Wt?(0,X.jsx)(xp,{node:v,hideVersionDiff:!0}):null,Ve&&v&&Kr?(0,X.jsxs)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(56,189,248,0.08) 0%, rgba(56,189,248,0.02) 100%)",borderBottom:"1px solid rgba(56,189,248,0.16)"},children:[(0,X.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-sky-100/85",children:[(0,X.jsx)(Xa,{className:"w-3.5 h-3.5 text-sky-300/75"}),(0,X.jsx)("span",{children:"Local draft in progress"})]}),(0,X.jsx)("div",{className:"text-[10px] text-sky-100/55",children:"Save or cancel to resolve the draft state"})]}):null,Ve&&v&&Ge&&!Se?(0,X.jsxs)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(251,191,36,0.08) 0%, rgba(244,63,94,0.03) 100%)",borderBottom:"1px solid rgba(251,191,36,0.18)"},children:[(0,X.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-amber-200/80",children:[(0,X.jsx)(or,{className:"w-3.5 h-3.5 text-amber-400/70"}),(0,X.jsx)("span",{children:"Pending changes \u2014 review and approve or revert"})]}),(0,X.jsxs)("div",{className:"flex items-center gap-2",children:[(0,X.jsxs)("button",{type:"button",className:$("inline-flex items-center gap-1 rounded-md px-2 py-1 text-[11px] transition",Ue?"bg-amber-500/15 border border-amber-500/25 text-amber-100":"bg-white/5 text-white/50 hover:bg-white/10 hover:text-white/70"),onClick:()=>me(!Ue),children:[(0,X.jsx)(or,{className:"w-3 h-3"}),"Diff"]}),Ue?(0,X.jsx)(sd,{}):null,(0,X.jsxs)("button",{type:"button",className:"inline-flex items-center gap-1 rounded-md bg-emerald-500/15 border border-emerald-500/25 px-2 py-1 text-[11px] text-emerald-100 hover:bg-emerald-500/20 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:ma,disabled:ft||At||!ce,title:"Accept current state",children:[ft?(0,X.jsx)(We,{className:"w-3 h-3 animate-spin"}):(0,X.jsx)(Dn,{className:"w-3 h-3"}),"Approve"]}),(0,X.jsxs)("button",{type:"button",className:"inline-flex items-center gap-1 rounded-md bg-red-500/10 border border-red-500/20 px-2 py-1 text-[11px] text-red-200/80 hover:bg-red-500/15 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:xn,disabled:ft||At||!ce,title:"Revert to previous version",children:[At?(0,X.jsx)(We,{className:"w-3 h-3 animate-spin"}):(0,X.jsx)(Ca,{className:"w-3 h-3"}),"Revert"]})]})]}):null,Ve&&v&&!Se&&v.presence==="stale_indexed"?(0,X.jsxs)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(244,114,182,0.08) 0%, rgba(251,191,36,0.03) 100%)",borderBottom:"1px solid rgba(244,114,182,0.15)"},children:[(0,X.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-rose-100/85",children:[(0,X.jsx)(Ya,{className:"w-3.5 h-3.5 text-rose-300/75"}),(0,X.jsx)("span",{children:"This indexed node is missing from the live source"})]}),(0,X.jsx)("div",{className:"text-[10px] text-rose-100/55",children:"Useful for spotting sync drift"})]}):null,Ve&&v&&!Se&&v.presence==="unindexed"?(0,X.jsx)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(251,191,36,0.07) 0%, rgba(255,255,255,0.02) 100%)",borderBottom:"1px solid rgba(251,191,36,0.15)"},children:(0,X.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-amber-100/82",children:[(0,X.jsx)(ot,{className:"w-3.5 h-3.5 text-amber-300/75"}),(0,X.jsx)("span",{children:"Unindexed \u2014 file exists on the connector but is not yet vector-indexed"})]})}):null,(0,X.jsxs)("div",{ref:Zt,className:"flex-1 min-h-0 relative",children:[kt&&w?(0,X.jsx)("div",{className:"w-full h-full overflow-y-auto",children:(0,X.jsx)(Hg,{agentId:w,projectId:h??null})}):null,Pr&&on&&w?(0,X.jsx)("div",{className:"w-full h-full overflow-y-auto",children:(0,X.jsx)(dL,{agentId:w,projectId:h??null,isDocker:k.isDocker})}):null,Oe&&h?(0,X.jsx)("div",{className:"w-full h-full overflow-y-auto",children:(0,X.jsx)(bL,{projectId:h})}):null,ee&&w?(0,X.jsx)("div",{className:"w-full h-full min-h-0",children:(0,X.jsx)(YL,{agentId:w,projectId:h??null})}):null,oe&&y?(0,X.jsx)("div",{className:"w-full h-full min-h-0",children:(0,X.jsx)(Bg,{target:y,agentId:w,projectId:h??null})}):null,He&&C?(0,X.jsx)("div",{className:"w-full h-full min-h-0",children:(0,X.jsx)(sp,{target:C,agentId:w,projectId:h??null})}):null,Ve&&je?(0,X.jsxs)("div",{className:"absolute inset-x-4 top-4 z-10 rounded-xl border border-red-500/25 bg-black/70 p-3 backdrop-blur-sm",children:[(0,X.jsx)("div",{className:"text-[11px] text-red-200/85 mb-2",children:"This file is marked as deleted."}),(0,X.jsxs)("div",{className:"flex items-center gap-2",children:[(0,X.jsxs)("button",{type:"button",className:"h-8 px-3 rounded-lg text-xs font-semibold border border-emerald-500/30 bg-emerald-500/15 text-emerald-100 hover:bg-emerald-500/20 disabled:opacity-50 disabled:cursor-not-allowed",onClick:Xr,disabled:!ce||Le||Ye,children:[Le?(0,X.jsx)(We,{className:"w-3 h-3 animate-spin inline mr-1"}):null,"Restore"]}),(0,X.jsxs)("button",{type:"button",className:"h-8 px-3 rounded-lg text-xs font-semibold border border-red-500/30 bg-red-500/15 text-red-100 hover:bg-red-500/20 disabled:opacity-50 disabled:cursor-not-allowed",onClick:fn,disabled:!ce||Ye||Le,children:[Ye?(0,X.jsx)(We,{className:"w-3 h-3 animate-spin inline mr-1"}):null,"Delete"]})]})]}):null,Ve&&v?Ge&&Ue&&be&&!Se?(0,X.jsx)(Ag,{oldContent:be.content,newContent:T,language:te,viewMode:rr,className:"w-full h-full min-h-0"}):B&&!N&&!A&&!Se?(0,X.jsx)("div",{className:$("w-full h-full min-h-0 flex items-center justify-center px-6 text-center",je&&"blur-[2px] opacity-65"),children:(0,X.jsxs)("div",{className:"max-w-md rounded-2xl border border-white/10 bg-white/[0.035] px-5 py-4 shadow-[0_18px_46px_-26px_rgba(0,0,0,0.65)]",children:[(0,X.jsx)(ot,{className:"w-6 h-6 mx-auto mb-3 text-amber-300/75"}),(0,X.jsxs)("div",{className:"text-sm font-semibold text-white/82",children:[ne," preview disabled"]}),(0,X.jsx)("div",{className:"mt-2 text-xs leading-5 text-white/45",children:"This file is treated as binary, so Neuralis will not decode it into the text editor."})]})}):N&&Pt&&!Se?(0,X.jsx)("div",{className:"w-full h-full min-h-0 overflow-auto px-2 py-1.5",children:(0,X.jsxs)("div",{className:$(je&&"blur-[2px] opacity-65"),children:[(0,X.jsx)("div",{className:"text-[11px] text-white/45 mb-3",children:"Image preview"}),(0,X.jsx)("img",{src:Pt,alt:v.name,className:"max-w-full max-h-[calc(100vh-220px)] rounded-xl bg-black/20 shadow-[0_18px_46px_-26px_rgba(0,0,0,0.65),inset_0_1px_0_rgba(255,255,255,0.06)]"})]})}):A&&Pt&&!Se?(0,X.jsx)("div",{className:"w-full h-full min-h-0 overflow-auto px-2 py-1.5",children:(0,X.jsxs)("div",{className:$(je&&"blur-[2px] opacity-65"),children:[(0,X.jsx)("div",{className:"text-[11px] text-white/45 mb-3",children:"Video preview"}),(0,X.jsx)("video",{src:Pt,controls:!0,className:"w-full max-w-[1100px] rounded-xl bg-black/20 shadow-[0_18px_46px_-26px_rgba(0,0,0,0.65),inset_0_1px_0_rgba(255,255,255,0.06)]"})]})}):Y&&U&&!pa&&!Se?(0,X.jsx)("div",{className:$("w-full h-full min-h-0 overflow-auto px-1 py-1 text-white/80",je&&"blur-[2px] opacity-65"),children:T?(0,X.jsx)("div",{className:"min-h-full min-w-0",children:(0,X.jsx)(U,{content:T})}):(0,X.jsx)("div",{className:"px-2 py-1.5 text-sm text-white/30",children:Gt})}):(0,X.jsx)(Og,{value:Se?Ne:T,language:te,readOnly:!Se||je||ze,wrap:pe,onChange:Se?Ee:void 0,className:$("w-full h-full min-h-0",je&&"opacity-65"),placeholder:Gt,ariaLabel:Se?"File content editor":"File content viewer",gitLineStatus:qr}):Ve?(0,X.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center text-white/20",children:[(0,X.jsx)(Cl,{className:"w-12 h-12 mb-2 opacity-50"}),(0,X.jsx)("div",{className:"text-sm",children:kt?"Upload files using this tab":"No file open"})]}):null,Ve&&v?(0,X.jsxs)("div",{className:"pointer-events-none absolute bottom-2 right-3 z-10 text-[10px] text-white/42",children:[(0,X.jsxs)("span",{children:[Un.lineCount.toLocaleString()," lines"]}),(0,X.jsxs)("span",{className:"ml-3",children:[Un.charCount.toLocaleString()," chars"]})]}):null]})]})}function JE(t){let e=gt(t).toLowerCase();return e.endsWith(".md")||e.endsWith(".mdx")||e.endsWith(".markdown")}function ZE(t){let e=gt(String(t||"")).toLowerCase();return e.endsWith(".png")||e.endsWith(".jpg")||e.endsWith(".jpeg")||e.endsWith(".webp")||e.endsWith(".gif")}function QE(t){let e=gt(String(t||"")).toLowerCase();return e.endsWith(".mp4")||e.endsWith(".webm")||e.endsWith(".mov")||e.endsWith(".m4v")}function eO(t){let e=gt(String(t||"")).toLowerCase();return/\.(wasm|png|jpe?g|gif|webp|ico|bmp|mp4|webm|avi|mov|m4v|mkv|mp3|wav|ogg|flac|aac|zip|tar|gz|bz2|7z|rar|pdf|docx?|xlsx?|pptx?|exe|dll|so|dylib|ttf|otf|woff2?|eot)$/.test(e)}function tO(t){let e=gt(String(t||"")).toLowerCase();return e.endsWith(".wasm")?"WebAssembly binary":e.endsWith(".pdf")?"PDF":"Binary file"}function nO(t){let e=gt(String(t||"")).toLowerCase();return e.endsWith(".jsonl")||e.endsWith(".ndjson")||e.endsWith(".log")}function rO(t){if(!t)return{charCount:0,lineCount:0};let e=1;for(let n=0;n<t.length;n++)t.charCodeAt(n)===10&&(e+=1);return{charCount:t.length,lineCount:e}}var ds="brain://project-info",z$=[{kind:"docs",label:"Upload Docs",folderUri:`${ds}/docs`,accept:".md,.txt,.pdf,.doc,.docx"},{kind:"requirements",label:"Upload Requirements",folderUri:`${ds}/requirements`,accept:".md,.txt,.pdf"},{kind:"architecture",label:"Upload Architecture",folderUri:`${ds}/architecture`,accept:".md,.txt,.pdf,.drawio,.json,.yaml,.yml"},{kind:"design",label:"Upload Design",folderUri:`${ds}/design`,accept:".md,.txt,.pdf,.fig,.png,.jpg,.jpeg,.webp"},{kind:"assets",label:"Upload Assets",folderUri:`${ds}/assets`,accept:".png,.jpg,.jpeg,.webp,.svg,.gif"},{kind:"datasets",label:"Upload Datasets",folderUri:`${ds}/datasets`,accept:".csv,.json,.jsonl,.parquet,.txt,.zip"},{kind:"other",label:"Upload File",folderUri:`${ds}/misc`}];var cn=j($e(),1);var QL=250,aO=1e3,sO=2e3,iO=6e3,oO=1e3,lO=5e3,uO=["filesystem:created","filesystem:updated","filesystem:deleted","filesystem:reverted","sync:completed","pending:changed"],cO=new Set(uO),dO=["filesAdded","filesUpdated","filesRemoved","filesMoved","chunksRemoved"];function fO(t){return t.mode==="purge"?!1:dO.every(e=>t[e]===0)}function e2(t,e){let n=ti(),r=H(T=>T.refreshTree),a=H(T=>T.refresh),s=H(T=>T.ensureFolderLoaded),i=H(T=>T.reconcileSourceFolders),o=H(T=>T.reconcileFolders),l=H(T=>T.setSourceDirty),u=H(T=>T.upsertFileNodeFromEvent),c=H(T=>T.incrementFolderBadges),d=H(T=>T.replaceFilePath),f=H(T=>T.clearFilePrev),h=H(T=>T.autoExpandToFile),p=H(T=>T.loadGitStatus),g=H(T=>T.notifyGitLogChanged),m=H(T=>T.refreshPendingCount),x=(0,cn.useRef)(0),y=(0,cn.useRef)(new Map),b=(0,cn.useRef)(new Map),C=(0,cn.useRef)(new Map);(0,cn.useEffect)(()=>{let T=y.current,V=C.current;return()=>{for(let Y of T.values())clearTimeout(Y);T.clear();for(let Y of V.values())clearTimeout(Y);V.clear()}},[t,e,n]),(0,cn.useEffect)(()=>{let T=b.current;return()=>{x.current+=1;for(let V of T.values())clearTimeout(V.timer);T.clear()}},[t,e,n]);let L=(0,cn.useRef)(null),P=(0,cn.useCallback)(()=>{if(!t||!e)return;let T=Date.now(),V=L.current,Y=V?V.deadline:T+lO;V&&clearTimeout(V.timer);let N=setTimeout(()=>{L.current=null,!(typeof document<"u"&&document.visibilityState==="hidden")&&m({agentId:t,projectId:e})},Math.max(0,Math.min(oO,Y-T)));L.current={timer:N,deadline:Y}},[t,e,m]),w=(0,cn.useRef)(P);w.current=P;let k=H(T=>T.activeAgentId===t&&T.activeProjectId===e);(0,cn.useEffect)(()=>{t&&e&&k&&m({agentId:t,projectId:e})},[t,e,k,m]),(0,cn.useEffect)(()=>{if(!t||!e)return;let T=()=>{document.visibilityState!=="hidden"&&w.current()},V=()=>w.current();return document.addEventListener("visibilitychange",T),window.addEventListener("focus",V),()=>{document.removeEventListener("visibilitychange",T),window.removeEventListener("focus",V),L.current&&clearTimeout(L.current.timer),L.current=null}},[t,e,m]);let _=(0,cn.useCallback)(T=>{let{type:V,payload:Y}=T,N=le=>{if(!t||!le)return;let re=n.getState().activeSource,he=typeof re=="string"&&re?re.includes("://")?qe(re):re:"",Ne=C.current,Ee=Ne.get(le);Ee&&clearTimeout(Ee),Ne.set(le,setTimeout(()=>{Ne.delete(le),n.setState(ze=>({sourceChangeRevision:{...ze.sourceChangeRevision,[le]:(ze.sourceChangeRevision[le]??0)+1}})),he===le&&p({agentId:t,projectId:e,source:le})},QL))},A=le=>{if(!t)return;let re=b.current,he=Date.now(),Ne=re.get(le),Ee=Ne?Ne.deadline:he+iO;Ne&&clearTimeout(Ne.timer);let ze=setTimeout(()=>{re.delete(le),i({agentId:t,projectId:e,source:le})},Math.max(0,Math.min(sO,Ee-he)));re.set(le,{timer:ze,deadline:Ee})};if(V==="sync:completed"){if(!t)return;let le=typeof Y.source=="string"?Y.source:void 0;if(le&&fO(Y)){N(le);return}le?(n.getState().loadedFolders?.[`${le}://`]?A(le):l(le,!0),N(le)):r({agentId:t,projectId:e});return}if(Y.changeType==="badge"){if(!t)return;let le=n.getState().activeAgentId;if(le&&le!==t)return;let re=typeof Y.source=="string"&&Y.source?Y.source:qe(typeof Y.uri=="string"?Y.uri:"");if(!re)return;let he=y.current,Ne=he.get(re);Ne&&clearTimeout(Ne),he.set(re,setTimeout(()=>{he.delete(re),n.setState(ct=>({sourceChangeRevision:{...ct.sourceChangeRevision,[re]:(ct.sourceChangeRevision[re]??0)+1}})),s({agentId:t,projectId:e,uri:`${re}://`,force:!0}),a({agentId:t,projectId:e});let Ee=n.getState().activeSource;(typeof Ee=="string"&&Ee?Ee.includes("://")?qe(Ee):Ee:"")===re&&p({agentId:t,projectId:e,source:re}),g(re)},QL));return}if(Y.external===!0){if(!t)return;let le=n.getState().activeAgentId;if(le&&le!==t)return;let re=typeof Y.source=="string"&&Y.source?Y.source:qe(typeof Y.uri=="string"?Y.uri:"");if(!re)return;if(N(re),!n.getState().loadedFolders?.[`${re}://`]){l(re,!0);return}A(re);return}let B=Y.uri;if(!B)return;let K=Y.changeType,te=Array.isArray(Y.folder_ancestors)&&Y.folder_ancestors.length>0?Y.folder_ancestors:xa(B);te.length>0&&c(te),Array.isArray(Y.new_folder_ancestors)&&Y.new_folder_ancestors.length>0&&c(Y.new_folder_ancestors);let ne=typeof Y.action=="string"?Y.action:void 0,pe={id:Y.id,uri:B,folder_ancestors:te,sourceAgentId:T.agentId,sourceProjectId:T.projectId},Se=le=>{if(!t)return;let re=Array.from(new Set(le.filter(he=>typeof he=="string"&&!!he).map(he=>et(he))));re.length>0&&o({agentId:t,projectId:e,folders:re})};switch(V){case"filesystem:created":case"filesystem:updated":u({...pe,status:Y.status}),Y.status==="pending_review"&&h(B),Y.newUri&&(d(B,Y.newUri),u({...pe,uri:Y.newUri,folder_ancestors:Y.new_folder_ancestors,status:Y.status})),ne==="review_approved"&&Y.status==="active"&&f(B),K==="structure"&&Se([B,Y.newUri]);break;case"filesystem:deleted":u({...pe,status:"deleted"}),K==="structure"&&Se([B]);break;case"filesystem:reverted":u({...pe,status:Y.status||"active"}),f(B),Se([B]);break}N(qe(B))},[t,e,n,r,a,s,i,o,l,u,c,d,f,h,p,g]),M=(0,cn.useRef)(_);M.current=_;let R=(0,cn.useRef)(null),U=(0,cn.useCallback)(()=>{if(!t)return;let T=x.current;R.current&&clearTimeout(R.current),R.current=setTimeout(()=>{R.current=null,T===x.current&&(async()=>{try{await a({agentId:t,projectId:e})}catch{return}if(T!==x.current)return;w.current();let V=n.getState();n.setState(N=>({sourceChangeRevision:Object.fromEntries(N.sources.map(A=>[qe(A.uri_root),(N.sourceChangeRevision[qe(A.uri_root)]??0)+1]))}));let Y=new Set;for(let[N,A]of Object.entries(V.loadedFolders||{})){if(!A)continue;let B=qe(N);B&&Y.add(B)}await Promise.all(Array.from(Y).map(N=>i({agentId:t,projectId:e,source:N})))})()},aO)},[t,e,n,a,i]),v=(0,cn.useRef)(U);v.current=U,(0,cn.useEffect)(()=>{let T=R;return()=>{T.current&&clearTimeout(T.current)}},[t,e,n]),(0,cn.useEffect)(()=>{if(!t||!e)return;let T=ew();if(!T?.subscribeFilesystemEvents)return;let V=!0,Y=T.subscribeFilesystemEvents(t,e,N=>{if(!V)return;let A=N;if(!A||typeof A!="object"||!cO.has(A.type)||!A.payload||typeof A.payload!="object")return;if(A.type==="pending:changed"){w.current();return}let B=A.payload.changeType==="badge",K=A.payload.external===!0;!B&&!K&&A.agentId!==t||M.current(A)},()=>{V&&v.current()});return()=>{V=!1,Y()}},[t,e,n])}var Bf=j(Wn(),1);var kn=j(ie(),1);function i0(t){let e=H(A=>A.sidebarOpen),n=H(A=>A.sidebarWidth),r=H(A=>A.setSidebarWidth),a=H(A=>A.loadList),s=H(A=>A.refreshTree),i=H(A=>A.applyNav),o=H(A=>A.searchQuery),l=H(A=>A.setSearchQuery),u=H(A=>A.clearSearch),c=H(A=>A.sidebarView),d=H(A=>A.setSidebarView),f=(0,Rn.useRef)(null),h=(0,Rn.useRef)(null),p=(0,Rn.useRef)(null),[g,m]=(0,Rn.useState)(!1),x=hn(),y=(0,Bf.useWorkspaceHostPort)(),b=H(A=>A.activeProjectId),C=t.projectId??b,L=x.useFileMarks(t.agentId),P=x.useAgents(),w=(0,Rn.useMemo)(()=>Ms(P),[P]),k=t.agentId?w.byId.get(t.agentId):null,_=k?.name||k?.slug,M=k?.config?.appearance?.icon,R=co(k?.id,w),U=(0,Rn.useMemo)(()=>{let A=L||{},B=0;for(let K of Object.keys(A)){let te=A[K]?.ts??0;te>B&&(B=te)}return B},[L]);e2(t.agentId,C),(0,Rn.useEffect)(()=>{t.agentId&&a({agentId:t.agentId,projectId:C,userId:t.userId??null})},[t.agentId,C,t.userId]),(0,Rn.useEffect)(()=>{if(!t.agentId)return;let A=t.state?.nav;if(!A)return;let B=JSON.stringify(A);f.current!==B&&(f.current=B,y&&t.widgetId&&(0,Bf.consumeWidgetNav)(y,{agentId:t.agentId,widgetId:t.widgetId}),i({agentId:t.agentId,projectId:C,nav:A,readAgentId:t.agentId}))},[i,t.agentId,C,t.state,y,t.widgetId]);let v=(0,Rn.useRef)(!1);(0,Rn.useEffect)(()=>{if(!t.agentId||!U||v.current)return;let A=setTimeout(()=>{v.current=!0,s({agentId:t.agentId,projectId:C}).finally(()=>{v.current=!1})},1500);return()=>clearTimeout(A)},[U,C,t.agentId,s]);let T=8,V=(0,Rn.useCallback)(A=>{A.preventDefault(),p.current={startX:A.clientX,startWidth:n},m(!0),A.currentTarget.setPointerCapture(A.pointerId)},[n]),Y=(0,Rn.useCallback)(A=>{let B=p.current;if(!B)return;let K=h.current,te=K?Math.max(fl,K.clientWidth-T):B.startWidth,ne=Math.min(te,Math.max(fl,B.startWidth+(A.clientX-B.startX)));r(ne)},[r]),N=(0,Rn.useCallback)(A=>{p.current&&(p.current=null,m(!1),A.currentTarget.releasePointerCapture(A.pointerId))},[]);return(0,kn.jsxs)("div",{className:"flex flex-col w-full h-full overflow-hidden transition-colors duration-300",children:[(0,kn.jsx)(hh,{agentId:t.agentId,agentName:_,agentIcon:M,agentAccent:R,supportsSources:!0,onOpenProjectFiles:()=>{i({agentId:t.agentId,projectId:C,nav:{kind:"filesystem",action:"list",uri:ds}})}}),(0,kn.jsxs)("div",{ref:h,className:`flex-1 min-h-0 flex flex-row ${g?"select-none cursor-col-resize":""}`,children:[(0,kn.jsxs)("div",{className:"h-full flex flex-col min-h-0 shrink-0 overflow-hidden",style:{width:e?n:0,backgroundColor:"transparent",borderRight:e?"1px solid rgba(255,255,255,0.05)":"none"},children:[(0,kn.jsxs)("div",{className:"px-2 pt-2 pb-1 flex items-center justify-between",children:[(0,kn.jsx)("div",{className:"text-[10px] text-white/40 font-bold uppercase tracking-wider shrink-0",children:c==="git"?"Git Control":c==="search"?"Search":"Explorer"}),c==="search"?(0,kn.jsx)("input",{type:"text",value:o,onChange:A=>l(A.target.value),onKeyDown:A=>{A.key==="Escape"&&(u(),d("tree"))},placeholder:"Search\u2026",autoFocus:!0,"aria-label":"Search query",className:"flex-1 min-w-0 mx-2 h-6 bg-transparent border-0 text-xs text-white/85 placeholder:text-white/30 outline-none"}):null,(0,kn.jsxs)("div",{className:"flex items-center gap-0.5 shrink-0",children:[(0,kn.jsx)("button",{type:"button",onClick:()=>{c==="search"?(u(),d("tree")):d("search")},className:`h-6 w-6 rounded-md inline-flex items-center justify-center transition-colors ${c==="search"?"text-white/85":"text-white/40 hover:text-white/70"}`,title:"Search in explorer","aria-label":"Toggle explorer search","aria-pressed":c==="search",children:(0,kn.jsx)(Bl,{className:"w-3.5 h-3.5"})}),(0,kn.jsx)("button",{type:"button",onClick:()=>d(c==="git"?"tree":"git"),className:`h-6 w-6 rounded-md inline-flex items-center justify-center transition-colors ${c==="git"?"text-violet-300/90":"text-white/40 hover:text-white/70"}`,title:"Git Control","aria-label":"Toggle Git Control panel","aria-pressed":c==="git",children:(0,kn.jsx)(Cn,{className:"w-3.5 h-3.5"})})]})]}),(0,kn.jsx)(fp,{agentId:t.agentId,sidebarView:c})]}),e&&(0,kn.jsx)("div",{role:"separator","aria-orientation":"vertical",onPointerDown:V,onPointerMove:Y,onPointerUp:N,className:"w-2 shrink-0 cursor-col-resize bg-white/0 hover:bg-white/[0.06] transition relative touch-none",children:(0,kn.jsx)("div",{className:"absolute inset-y-6 left-1/2 -translate-x-1/2 w-[2px] rounded-full bg-white/[0.07]"})}),(0,kn.jsx)("div",{className:"flex-1 min-w-0 min-h-0",children:(0,kn.jsx)(s0,{})})]})]})}var Xn=j($e(),1),Uf=j(Zr(),1),il=j(Zr(),1),f2=j(r2(),1);var ji=j($e(),1);var _f=j(Zr(),1);var Ha=j(ie(),1),hO=27,u0=90,pO=17,mO=12,gO=1.4,xO=18,l0=32,a2=new WeakMap;function s2(t,e){let n=a2.get(t);if(n&&n.status===e)return n;let r={status:e};return a2.set(t,r),r}function yO(t,e){let n=s2(t,e);if(n.compact!==void 0)return n.compact;let r=String(e??"").toLowerCase(),a=r==="pending"||r.includes("pending"),s;if(a)s=l0;else{let i=tl(t.input),o=i&&typeof i.action=="string"?i.action:void 0;if(o&&!el(o))s=l0;else if(el(o))s=u0;else{let l=0;try{let u=i?Zu(i):null;l=u?u.added+u.removed:0}catch{l=0}s=l<=0?l0:Math.min(u0,l*xO)}}return n.compact=s,s}function bO(t,e){let n=s2(t,e);if(n.expanded!==void 0)return n.expanded;let r=tl(t.input)??{},a=0;try{let i=Zu(r);a=i?i.added+i.removed:0}catch{a=0}let s=Math.max(u0,mO+Math.ceil(a*gO)*pO);return n.expanded=s,s}function i2(t){let e=t.disclosure===!0?bO(t.tool,t.status):yO(t.tool,t.status);return hO+e}var Hf=(0,ji.memo)(function({uri:e,lineCounts:n,isPending:r,reviewPending:a,isError:s,isInterrupted:i,onUriClick:o,children:l}){let u=(0,ji.useMemo)(()=>r?"pending":i?"interrupted":s?"error":"committed",[r,s,i]),c=a&&u==="committed"?"pending review":u,d=(0,ji.useCallback)(()=>{e&&o&&o(e)},[e,o]),f=(0,ji.useCallback)(()=>(0,Ha.jsxs)("div",{className:`px-3 py-1 flex items-center gap-2 min-w-0 ${e&&o?"cursor-pointer hover:bg-white/[0.04] transition":""}`,onClick:d,role:e&&o?"button":void 0,title:e||void 0,children:[(0,Ha.jsx)(va,{className:"w-3 h-3 text-white/40 shrink-0"}),(0,Ha.jsx)("span",{className:"flex-1 min-w-0 text-[11px] text-white/60 font-mono truncate",children:e||"file"}),n&&(0,Ha.jsxs)("span",{className:"shrink-0 flex items-center gap-1.5 text-[10px] font-mono",children:[n.added>0&&(0,Ha.jsxs)("span",{className:"text-emerald-400",children:["+",n.added]}),n.removed>0&&(0,Ha.jsxs)("span",{className:"text-red-400",children:["-",n.removed]})]}),(0,Ha.jsx)(_f.ToolStatusIcon,{isPending:r,isError:s,isInterrupted:i,statusLabel:c})]}),[e,o,d,n,r,s,i,c]);return(0,Ha.jsx)(_f.CardShell,{label:e||"file",status:u,defaultMode:"compact",compactHeight:90,renderHeader:f,children:l})});var l2=j($e(),1);var Ze=j(ie(),1),u2=(0,l2.memo)(function({action:e,input:n}){switch(e){case"set_fields":return(0,Ze.jsx)(wO,{fields:n.fields});case"move":return(0,Ze.jsx)(vO,{uri:al(n,"uri")||al(n,"id"),destination:al(n,"destination")});case"copy":return(0,Ze.jsx)(kO,{uri:al(n,"uri"),destination:al(n,"destination")});case"create_folder":return(0,Ze.jsx)(SO,{uri:al(n,"uri")});case"delete":return(0,Ze.jsx)(CO,{});case"revert":return(0,Ze.jsx)(IO,{});default:return(0,Ze.jsx)(LO,{action:e,input:n})}});function wO({fields:t}){if(!t||typeof t!="object")return(0,Ze.jsx)(o2,{icon:(0,Ze.jsx)(ao,{className:"w-3 h-3"}),text:"Updated fields"});let e=[];for(let[n,r]of Object.entries(t))if(r!==void 0)if(n==="tags"&&r&&typeof r=="object"){let a=r,s=[];Array.isArray(a.add)&&a.add.length&&s.push(a.add.map(i=>`+${i}`).join(" ")),Array.isArray(a.remove)&&a.remove.length&&s.push(a.remove.map(i=>`-${i}`).join(" ")),Array.isArray(a.set)&&s.push(a.set.join(", ")),e.push({key:"tags",value:s.join(" ")||"(cleared)"})}else if(n==="metadata"&&r&&typeof r=="object"){let a=Object.entries(r).map(([s,i])=>i===null?`${s}: (removed)`:`${s}: ${String(i)}`).join(", ");e.push({key:"metadata",value:a||"(empty)"})}else e.push({key:n,value:r===null?"(cleared)":String(r)});return(0,Ze.jsxs)("div",{className:"px-3 py-2 space-y-0.5",children:[e.map(n=>(0,Ze.jsxs)("div",{className:"flex gap-2 text-[11px]",children:[(0,Ze.jsxs)("span",{className:"text-white/45 shrink-0",children:[n.key,":"]}),(0,Ze.jsx)("span",{className:"text-white/75 break-all",children:n.value})]},n.key)),e.length===0&&(0,Ze.jsx)(o2,{icon:(0,Ze.jsx)(ao,{className:"w-3 h-3"}),text:"Updated fields"})]})}function vO({uri:t,destination:e}){return(0,Ze.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] font-mono",children:[(0,Ze.jsx)("span",{className:"text-white/50 truncate",children:t||"?"}),(0,Ze.jsx)(no,{className:"w-3 h-3 text-white/35 shrink-0"}),(0,Ze.jsx)("span",{className:"text-white/75 truncate",children:e||"?"})]})}function kO({uri:t,destination:e}){return(0,Ze.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] font-mono",children:[(0,Ze.jsx)(na,{className:"w-3 h-3 text-sky-400/60 shrink-0"}),(0,Ze.jsx)("span",{className:"text-white/50 truncate",children:t||"?"}),(0,Ze.jsx)(no,{className:"w-3 h-3 text-white/35 shrink-0"}),(0,Ze.jsx)("span",{className:"text-white/75 truncate",children:e||"?"})]})}function SO({uri:t}){return(0,Ze.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] font-mono",children:[(0,Ze.jsx)(br,{className:"w-3 h-3 text-sky-300/70 shrink-0"}),(0,Ze.jsx)("span",{className:"text-white/75 truncate",children:t||"?"})]})}function CO(){return(0,Ze.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2",children:[(0,Ze.jsx)(Nt,{className:"w-3 h-3 text-rose-400/70"}),(0,Ze.jsx)("span",{className:"text-[11px] text-rose-300/80",children:"Deleted"})]})}function IO(){return(0,Ze.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2",children:[(0,Ze.jsx)(oi,{className:"w-3 h-3 text-amber-400/70"}),(0,Ze.jsx)("span",{className:"text-[11px] text-white/70",children:"Reverted to previous version"})]})}function LO({action:t,input:e}){let n=Object.entries(e).filter(([r])=>r!=="action"&&r!=="id"&&r!=="uri").slice(0,5).map(([r,a])=>`${r}: ${typeof a=="string"?a.slice(0,60):JSON.stringify(a)?.slice(0,60)??"?"}`).join(", ");return(0,Ze.jsxs)("div",{className:"px-3 py-2 text-[11px] text-white/60",children:[(0,Ze.jsx)("span",{className:"text-white/45 mr-1",children:t}),n&&(0,Ze.jsx)("span",{className:"text-white/50",children:n})]})}function o2({icon:t,text:e}){return(0,Ze.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] text-white/60",children:[t,(0,Ze.jsx)("span",{children:e})]})}function al(t,e){let n=t[e];return typeof n=="string"?n:void 0}var Ua=j(ie(),1),AO=200,sl=new Map;function c2(t,e){if(sl.size>=AO){let n=sl.keys().next().value;n!==void 0&&sl.delete(n)}sl.set(t,e)}var PO=8,NO=200,h2=(0,Xn.memo)(function({tool:e,status:n,conversationId:r}){let a=(0,il.useChatHost)(),s=(0,f2.useWorkspaceChatStore)(v=>r?v.conversationsById?.[r]?.agentId:void 0),i=(0,il.useHasRowIdentity)(),o=(0,il.useRowDisclosureValue)("card"),u=i&&o!==!0?PO:NO,c=(0,Xn.useMemo)(()=>tl(e.input),[e.input]),d=(0,Xn.useMemo)(()=>(0,Uf.extractPathsFromToolCall)(e)[0]||(c?d2(c,"uri")||d2(c,"path"):void 0),[e,c]),f=String(n||"").toLowerCase(),h=f==="pending"||f.includes("pending"),p=f==="interrupted",g=!p&&(f==="error"||f.includes("error")||f.includes("fail")),m=c?.action,x=d?Qo(d):void 0,y=(0,Xn.useMemo)(()=>n0(e.structuredContent),[e.structuredContent]),b=(0,Xn.useMemo)(()=>{let v=e.structuredContent,T=v&&typeof v=="object"?String(v.status||"").toLowerCase():"";return T==="pending_review"||T.includes("pending")},[e.structuredContent]),C=(0,Xn.useMemo)(()=>y??(c&&!h?Zu(c):null),[y,c,h]),L=(0,Xn.useMemo)(()=>c?h?[]:RO(m,c):[],[m,c,h]),P=(0,Xn.useCallback)(v=>{let T=s||void 0;!T||!v||a.openFilesystemWidget?.(T,v)},[s,a]),w=(0,Xn.useMemo)(()=>{if(h)return(0,Uf.previewInput)(e.input,!0)},[h,e.input]),k=!h&&!g&&!!m&&el(m),[_,M]=(0,Xn.useState)(()=>k&&d&&s?sl.get(`${s}|${e.id}`)??null:null);(0,Xn.useEffect)(()=>{if(!k||!d||!s){M(null);return}let v=`${s}|${e.id}`,T=sl.get(v);if(T!==void 0){M(T);return}let V=!1,Y=()=>{V||(async()=>{try{let K=await $i({agentId:s,files:[d]});if(V)return;let te=Yi(K)[0],ne=pc(te?.version?.baseline);if(!ne?.content){c2(v,null);return}let pe=Tf(ne.content,Ji(te));c2(v,pe),V||M(pe)}catch{}})()},N=globalThis,A=null,B=null;return typeof N.requestIdleCallback=="function"?A=N.requestIdleCallback(Y,{timeout:1500}):B=setTimeout(Y,200),()=>{V=!0,A!==null&&N.cancelIdleCallback?.(A),B!==null&&clearTimeout(B)}},[k,d,s,e.id]);let R=_??L,U=_?Df(_):C;return h?(0,Ua.jsx)(Hf,{uri:d,lineCounts:null,isPending:!0,reviewPending:!1,isError:!1,isInterrupted:!1,onUriClick:d?P:void 0,children:(0,Ua.jsx)(MO,{content:w})}):m&&!el(m)?(0,Ua.jsx)(Hf,{uri:d,lineCounts:null,isPending:!1,reviewPending:b,isError:g,isInterrupted:p,onUriClick:d?P:void 0,children:(0,Ua.jsx)(u2,{action:m,input:c||{}})}):(0,Ua.jsx)(Hf,{uri:d,lineCounts:U,isPending:!1,reviewPending:b,isError:g,isInterrupted:p,onUriClick:d?P:void 0,children:R.length>0?(0,Ua.jsx)(Zo,{hunks:R,language:x,maxLines:u}):(0,Ua.jsx)("div",{className:"px-3 py-2 text-[11px] text-white/40 italic",children:g?"Operation failed":"Done"})})});function RO(t,e){if(!t){let n=Ju(e);return n?t0(n):[]}if(t==="replace_text"){let n=e.edits;if(Array.isArray(n)&&n.length>0)return IL(n.filter(s=>!!s&&typeof s=="object"&&typeof s.find=="string"));let r=typeof e.find=="string"?e.find:"",a=typeof e.replace=="string"?e.replace:"";return CL(r,a)}if(t==="update"||t==="replace_lines"){let n=Ju(e);return n?LL(n):[]}if(t==="append_text"||t==="prepend_text"||t==="insert"){let n=typeof e.text=="string"?e.text:"";return n?AL(n):[]}return[]}function MO({content:t}){return t?(0,Ua.jsx)("pre",{className:"px-3 py-1.5 text-[11px] leading-[18px] whitespace-pre overflow-x-auto overflow-y-clip bg-emerald-500/8 text-white/70 font-mono",children:t}):(0,Ua.jsx)("div",{className:"px-3 py-2 text-[11px] text-white/40 italic",children:"Running..."})}function d2(t,e){let n=t[e];return typeof n=="string"?n:void 0}var Ga=j($e(),1);function p2({port:t}){let e=t.useCurrentUser(),n=e?.name,r=e?.email,a=e?.role,s=e?.priority,i=(0,Ga.useMemo)(()=>n||r?{name:n,email:r}:void 0,[n,r]),o=(0,Ga.useMemo)(()=>a!==void 0||s!==void 0?{role:a,priority:s}:void 0,[a,s]),l=t.useProjectId(),u=t.useUserId(),c=t.getGrantedFeatures(l,u).join(","),d=(0,Ga.useMemo)(()=>c.split(",").filter(Boolean),[c]);return(0,Ga.useMemo)(()=>({currentUser:i,currentRole:o,grantedFeatures:d,useAgents(){let f=t.useAgentIds(),h=t.useAgentsById();return(0,Ga.useMemo)(()=>{let p={};for(let g of f){let m=h[g];m&&(p[g]={id:m.id,slug:m.slug,name:m.name,config:m.config})}return{ids:f,byId:p}},[f,h])},useFileMarks:f=>t.useFileMarks(f),clearFileMark:f=>t.clearFileMark(f),getStreamUrl(f,h,p){return t.buildEventStreamUrl({packageSlug:"brain-core",agentId:f,projectId:h,types:p})},subscribeFilesystemEvents(f,h,p,g){return t.subscribeRealtime({channel:"filesystem",projectId:h,agentId:f,onEvent:(m,x)=>p(x),...g?{onConnChange:g}:{}})},isDocker:t.isDocker,usePackageIconBySlug(){let f=t.useProjectId(),[h,p]=(0,Ga.useState)({});return(0,Ga.useEffect)(()=>{if(!f)return;let g=!1,m=`/api/packages/agent-core/packages/overview?projectId=${encodeURIComponent(f)}`;return fetch(m,{credentials:"include"}).then(x=>x.ok?x.json():null).then(x=>{if(g||!x?.packages)return;let y={};for(let b of x.packages){if(!b.id)continue;let C=(0,lr.resolveLucideIcon)(b.icon);if(!C)continue;let L=b.id.replace(/^@[^/]+\//,"");y[L]=C,y[b.id]=C}p(y)}).catch(()=>{}),()=>{g=!0}},[f]),h}}),[t,i,o,d])}var g2=j(ie(),1);function m2({port:t,children:e}){let n=p2({port:t});return(0,g2.jsx)(tw,{value:n,children:e})}var fs=j(ie(),1),TO="workspace.provider:@neuralis/brain-core",x2=(0,fs.jsx)("div",{className:"flex h-full items-center justify-center text-xs text-white/30",children:"Loading..."}),y2=!1;function DO(t){let{registry:e,port:n}=t;!y2&&n.onClientStateReset&&(y2=!0,n.onClientStateReset(Tx));function r({children:i}){let o=n.useUserId();return(0,ol.useEffect)(()=>{Mx(o)},[o]),(0,fs.jsx)(m2,{port:n,children:i})}e.register({packageSlug:"@neuralis/brain-core",componentImport:TO,Component:r});function a({agentId:i,widgetId:o,state:l}){let u=n.useProjectId(),c=n.useUserId(),d=Dx(o,c,u,i);return d?(0,fs.jsx)(Gf.WorkspaceHostPortProvider,{port:n,children:(0,fs.jsx)(Gf.PackageApiProvider,{slug:"brain-core",projectId:u,agentId:i,userId:c,children:(0,fs.jsx)(Ex,{store:d,children:(0,fs.jsx)(i0,{agentId:i,projectId:u,userId:c,widgetId:o,state:l})},`${o}\0${c}\0${u}\0${i}`)})}):x2}let s=ol.default.lazy(()=>Promise.resolve({default:a}));e.register({packageSlug:"@neuralis/brain-core",componentImport:"@neuralis/brain-core/app/filesystem",Component:i=>(0,fs.jsx)(ol.Suspense,{fallback:x2,children:(0,fs.jsx)(s,{...i})})}),(0,b2.registerCardComponent)("filesystem.change",h2,{owner:{kind:"package-direct",packageId:"@neuralis/brain-core"},renderer:"direct",mountPolicy:"virtualized",estimateHeight:i2,composer:PL,matchTools:NL})}export{DO as installFilesystemHostComponents};
|
|
54
|
+
`)}function f0(t){let e=jr(t);return e.length===0?[]:[{skippedBefore:0,lines:e.map(n=>({type:"add",content:n}))}]}function TL(t,e){let n=jr(t).map(a=>({type:"remove",content:a})),r=jr(e).map(a=>({type:"add",content:a}));return[{skippedBefore:0,lines:[...n,...r]}]}function DL(t){return t.map((e,n)=>{let r=jr(e.find).map(s=>({type:"remove",content:s})),a=jr(e.replace??"").map(s=>({type:"add",content:s}));return{skippedBefore:n>0?-1:0,lines:[...r,...a]}}).filter(e=>e.lines.length>0)}function FL(t){return f0(t)}function EL(t){let e=jr(t);return e.length===0?[]:[{skippedBefore:0,lines:e.map(n=>({type:"add",content:n}))}]}function fc(t){let e=t.action;if(!e){let n=dc(t);return n!=null?{added:jr(n).length,removed:0}:null}if(e==="replace_text"){let n=t.edits;if(Array.isArray(n)){let s=0,i=0;for(let o of n){if(!o||typeof o!="object")continue;let l=o;typeof l.find=="string"&&(i+=jr(l.find).length),typeof l.replace=="string"&&(s+=jr(l.replace).length)}return{added:s,removed:i}}let r=typeof t.find=="string"?t.find:"",a=typeof t.replace=="string"?t.replace:"";return{added:jr(a).length,removed:jr(r).length}}if(e==="update"||e==="replace_lines"){let n=dc(t);return n!=null?{added:jr(n).length,removed:0}:null}if(e==="append_text"||e==="prepend_text"||e==="insert"){let n=typeof t.text=="string"?t.text:"";return{added:jr(n).length,removed:0}}return null}var EE={".ts":"typescript",".tsx":"tsx",".js":"javascript",".jsx":"jsx",".json":"json",".md":"markdown",".py":"python",".css":"css",".html":"html",".yaml":"yaml",".yml":"yaml",".sh":"bash",".sql":"sql",".rs":"rust",".go":"go",".java":"java",".xml":"xml",".toml":"toml",".env":"bash",".scss":"scss",".less":"less",".graphql":"graphql",".vue":"markup",".svelte":"markup",".txt":"text"};function pl(t){let e=t.match(/(\.[a-zA-Z0-9]+)$/)?.[1]?.toLowerCase();return e?EE[e]:void 0}var OE=new Set(["update","replace_text","append_text","prepend_text","insert","replace_lines"]);function ml(t){return!!t&&OE.has(t)}function jr(t){return t?t.split(`
|
|
55
|
+
`):[]}function gl(t){return _E((0,zf.parseSettledObject)(t))}function Wf(t,e){let n=d0(t),r=d0(e),a=n.length,s=r.length,i=Array.from({length:a+1},()=>new Array(s+1).fill(0));for(let c=a-1;c>=0;c--)for(let d=s-1;d>=0;d--)i[c][d]=n[c]===r[d]?i[c+1][d+1]+1:Math.max(i[c+1][d],i[c][d+1]);let o=[],l=0,u=0;for(;l<a&&u<s;)n[l]===r[u]?(o.push({type:"context",content:n[l]}),l++,u++):i[l+1][u]>=i[l][u+1]?(o.push({type:"remove",content:n[l]}),l++):(o.push({type:"add",content:r[u]}),u++);for(;l<a;)o.push({type:"remove",content:n[l++]});for(;u<s;)o.push({type:"add",content:r[u++]});return[{skippedBefore:0,lines:o}]}function jf(t){let e=0,n=0;for(let r of t)for(let a of r.lines)a.type==="add"?e++:a.type==="remove"&&n++;return{added:e,removed:n}}function dc(t){for(let e of["content","file_content","text"]){let n=t[e];if(typeof n=="string")return n}if(typeof t.content=="object"&&t.content!==null)try{return JSON.stringify(t.content,null,2)}catch{}return null}function h0(t){if(!t||typeof t!="object"||Array.isArray(t))return null;let e=t;if(e.ok===!1)return null;let n=e.version;if(!n||typeof n!="object"||Array.isArray(n))return null;let r=n.diff;if(!r||typeof r!="object"||Array.isArray(r))return null;let a=r,s=typeof a.added=="number"?a.added:null,i=typeof a.removed=="number"?a.removed:null;return s==null||i==null?null:{added:s,removed:i}}function BE(t){let e=(0,zf.extractPathsFromToolCall)(t);if(e.length===0){let r=gl(t.input),a=typeof r?.uri=="string"&&r.uri||typeof r?.path=="string"&&r.path||"";if(!a)return[];e=[a]}let n=h0(t.structuredContent);return e.map((r,a)=>a===0&&n?{path:r,diff:n}:{path:r})}var OL={tab:"changes",changes:BE},BL=["fs_write","fs_create","fs_modify"];function _E(t){if(!t||typeof t.action=="string"||!UE(t))return t;let e={};if(typeof t.uri=="string"&&(e.uri=t.uri),typeof t.id=="string"&&(e.id=t.id),typeof t.move=="string")return{...e,action:"move",destination:t.move};if(typeof t.copy=="string")return{...e,action:"copy",destination:t.copy};if(t.mkdir!==void 0)return{...e,action:"create_folder"};if(t.revert!==void 0)return{...e,action:"revert"};if(t.delete!==void 0)return{...e,action:"delete"};let n=Array.isArray(t.edit)?t.edit.filter(o=>!!o&&typeof o=="object").map(o=>({find:typeof o.old_string=="string"?o.old_string:"",replace:typeof o.new_string=="string"?o.new_string:""})).filter(o=>o.find.length>0):[];if(n.length>0)return{...e,action:"replace_text",edits:n};let r=Gf(t.lines);if(r&&typeof r.content=="string")return{...e,action:"replace_lines",content:r.content};let a=Gf(t.insert);if(a&&typeof a.insert_text=="string")return{...e,action:"insert",text:a.insert_text};let s=Gf(t.overwrite);if(s&&s.content!==void 0)return{...e,action:"update",content:s.content};let i=Gf(t.create);return i&&i.content!==void 0?{...e,content:i.content}:t.fields!==void 0?{...e,action:"set_fields",fields:t.fields}:t}var HE=["create","overwrite","edit","insert","lines","fields","move","copy","mkdir","revert","delete"];function UE(t){return HE.some(e=>t[e]!==void 0)}function Gf(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function Ja(t){let e=t.trim();if(!e)return"";let n=e.indexOf("://"),r=n>=1?e.slice(0,n+3):"",a=n>=1?e.slice(n+3):e,s=a.length>0&&a.endsWith("/"),i=[];for(let l of a.split("/"))if(!(l===""||l===".")){if(l===".."){i.pop();continue}i.push(l)}let o=i.join("/");return o?`${r}${o}${s?"/":""}`:r}function HL(t){let e=new Map;for(let n of t)if(n.status)for(let[r,a]of[[!0,n.status.staged],[!1,[...n.status.unstaged,...n.status.untracked]]])for(let s of a){let i=`${n.source}://${[n.repo.rel,s.path].filter(Boolean).join("/")}`,o=e.get(i)??new Map,l=JSON.stringify([n.source,n.repo.rel,s.path]),u=o.get(l);u?(u.staged||=r,u.unstaged||=!r):o.set(l,{group:n,path:s.path,staged:r,unstaged:!r}),e.set(i,o)}return e}function hc(t){return`${t.source}://${t.repo.rel}`}function p0(t){let e=Ks(t.source,t.repo.name);return e.prefix?`${e.prefix} ${e.name}`:e.name}function UL(t,e){return e.kind==="pending"?[]:t.filter(n=>(!e.source||n.source===e.source)&&(!e.repo||hc(n)===e.repo)&&(!e.branch||n.status?.branch===e.branch))}function GL(t,e,n){return n.kind==="git"?[]:t.filter(r=>!(n.source&&r.sourceSlug!==n.source||n.agent&&r.agentId!==n.agent||n.origin&&r.origin!==n.origin||(n.repo||n.branch)&&!e.some(s=>r.sourceSlug===s.source&&Ja(r.uri).startsWith(`${s.source}://${s.repo.rel?`${s.repo.rel}/`:""}`)&&(!n.repo||hc(s)===n.repo)&&(!n.branch||s.status?.branch===n.branch)))).sort((r,a)=>r.createdAt<a.createdAt?-1:r.createdAt>a.createdAt?1:0)}function zL(t,e,n,r){let a=new Set(t.map(i=>Ja(i.uri))),s=[];for(let i of e.keys())(n==="git"||!a.has(i))&&s.push({kind:"git",key:`git:${i}`,uri:i});return t.forEach((i,o)=>s.push({kind:r==="cards"?"pending-card":"pending-row",key:i.id,rec:i,index:o})),s}var GE=32,zE=346;function WL(t){return t==="pending-row"?GE:zE}function jL(t){return t!=="pending-row"}function qL(t,e,n=100,r){let a=[],s=[];for(let i of t)e.has(i.id)||(ML(i)||r?.(i.id)?.requiresAcknowledgement.length?s.push(i):a.length<n&&a.push(i));return{approvable:a,needsAck:s}}function m0(t){let e=t instanceof Error?t.message:String(t??"");return e.includes("PENDING_STATE_CHANGED")||e.includes("PENDING_GENERATION_CHANGED")?"changed":e.includes("CURRENT_STATE_ACKNOWLEDGEMENT_REQUIRED")?"needs-ack":"error"}var _L=new WeakMap;function qf(t){if(t.diffState!=="readable")return null;let e=_L.get(t);return e||(e=Wf(t.baseline.state==="text"?t.baseline.text:"",t.current.state==="text"?t.current.text:""),_L.set(t,e)),e}var bt=W(ue(),1),VL={originalDraftUnknown:{label:"Older change \u2014 original draft unknown",chip:"bg-amber-500/15 text-amber-200 border-amber-400/30"},externalChanged:{label:"Changed outside the review",chip:"bg-rose-500/15 text-rose-200 border-rose-400/30"},unreviewable:{label:"Diff not readable",chip:"bg-sky-500/15 text-sky-200 border-sky-400/30"},fresh:{label:"No confirmation needed now",chip:"bg-emerald-500/15 text-emerald-200 border-emerald-400/30"}},$L={ok:{label:"Done",tone:"text-emerald-300"},changed:{label:"Changed since the preview \u2014 check the fresh state and confirm again",tone:"text-amber-300"},"needs-ack":{label:"Still needs a confirmation",tone:"text-amber-300"},error:{label:"Refused",tone:"text-rose-300"}};async function Vf(t,e,n,r,a){let s={agentId:t.agentId,...t.projectId?{projectId:t.projectId}:{},id:e.id,expectedFingerprint:n.expectedFingerprint,...a?{acknowledgeCurrentState:!0}:{}};try{let i=r==="approve"?await Sc({...s,uri:e.uri},t.client):r==="revert"?await sx(s,t.client):await ox(s,t.client);if(i&&i.ok===!1){let o="error"in i&&i.error?String(i.error):"Review refused";return{id:e.id,uri:e.uri,action:r,outcome:m0(o),detail:o}}return{id:e.id,uri:e.uri,action:r,outcome:"ok"}}catch(i){return{id:e.id,uri:e.uri,action:r,outcome:m0(i),detail:i instanceof Error?i.message:"Review refused"}}}function WE({rec:t,preview:e}){let n=(0,Zn.useMemo)(()=>qf(e),[e]);return c0(t,e)?(0,bt.jsx)("div",{className:"px-2.5 py-2 text-[10.5px] text-white/60 leading-relaxed",children:"The file is gone. Approving or dismissing accepts that it stays gone \u2014 nothing is recreated and the saved earlier version stays in history. Revert restores that version."}):n?(0,bt.jsx)("div",{className:"max-h-56 overflow-auto overlay-scroll",style:{scrollbarGutter:"auto"},children:(0,bt.jsx)(hl,{hunks:n,language:pl(t.uri),maxLines:400})}):(0,bt.jsxs)("div",{className:"px-2.5 py-2 text-[10.5px] text-white/50",children:["Diff ",e.diffState,": current ",e.current.state,", baseline ",e.baseline.state," (",e.baselineProvenance,")."]})}var pc="h-7 px-2.5 rounded-md text-[11px] font-medium transition disabled:opacity-40 inline-flex items-center gap-1.5";function $f({request:t,agentId:e,projectId:n,run:r,onClose:a,onDone:s,next:i=0,onNext:o,refetch:l,onBatchStart:u}){let c=B(P=>P.client),d=(0,Zn.useMemo)(()=>t.kind==="single"?[t.rec]:t.records,[t]),[f,h]=(0,Zn.useState)(()=>t.kind==="single"&&t.preview?{[t.rec.id]:t.preview}:{}),[p,g]=(0,Zn.useState)(!1),[m,x]=(0,Zn.useState)({}),b=(0,Zn.useRef)(!0),y=(0,Zn.useRef)(new Map);(0,Zn.useEffect)(()=>(b.current=!0,()=>{b.current=!1}),[]);let C=(0,Zn.useCallback)((P,H=!1)=>{let w=(y.current.get(P.id)??0)+1;y.current.set(P.id,w);let N=()=>b.current&&y.current.get(P.id)===w;(H&&l?l(P):r(()=>uo({agentId:e,...n?{projectId:n}:{},id:P.id},c),N)).then(K=>{N()&&K&&h(A=>({...A,[P.id]:K}))},K=>{N()&&h(A=>({...A,[P.id]:K instanceof Error?K:new Error("Preview failed")}))})},[e,n,r,l]);(0,Zn.useEffect)(()=>{for(let P of d)!f[P.id]&&!y.current.has(P.id)&&C(P)},[d,C]);let I=(0,Zn.useMemo)(()=>{let P=new Map;for(let H of d){let w=f[H.id];if(!w||w instanceof Error)continue;let N=w.requiresAcknowledgement[0]??"fresh";P.set(N,[...P.get(N)??[],H])}return P},[d,f]),L=d.filter(P=>!f[P.id]).length,v=P=>m[P.id]!==void 0&&m[P.id].outcome!=="changed",k=t.kind==="group"&&L===0&&!p&&d.every(P=>v(P)||f[P.id]instanceof Error),O=(0,Zn.useCallback)(async(P,H)=>{g(!0),u?.();let w=[];for(let N of P){let j=f[N.id];if(!j||j instanceof Error||m[N.id]?.outcome==="ok")continue;let K=await Vf({agentId:e,projectId:n,client:c},N,j,H,j.requiresAcknowledgement.length>0);w.push(K),x(A=>({...A,[N.id]:K})),K.outcome==="changed"&&(h(A=>{let{[N.id]:F,..._}=A;return _}),C(N,!0))}g(!1),s(w)},[f,m,e,n,s,C,u]);if(typeof document>"u")return null;let R=t.kind==="single"?t:null;return(0,KL.createPortal)((0,bt.jsx)("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/40 backdrop-blur-[1px]",onMouseDown:p?void 0:a,children:(0,bt.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":"Review pending changes",onMouseDown:P=>P.stopPropagation(),className:"w-[min(640px,92vw)] max-h-[82vh] flex flex-col rounded-xl border border-amber-400/25 bg-[#15151d] shadow-[0_30px_80px_-24px_rgba(0,0,0,0.85)]",children:[(0,bt.jsxs)("div",{className:"flex items-start gap-2.5 p-4 pb-2 shrink-0",children:[(0,bt.jsx)(Ea,{className:"h-4 w-4 text-amber-300 shrink-0 mt-0.5"}),(0,bt.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,bt.jsx)("div",{className:"text-[12px] font-semibold text-white/90",children:R?`Review the current state \u2014 ${R.action}`:t.kind==="group"&&t.total>d.length?`${d.length} of ${t.total} changes need your confirmation`:`${d.length} changes need your confirmation`}),(0,bt.jsx)("div",{className:"mt-1 text-[10.5px] text-white/55 leading-relaxed",children:"Each change is checked against its own fresh preview. Confirming accepts the state shown here; a change that moves again before you confirm is refused and stays in the list."}),L>0?(0,bt.jsxs)("div",{className:"mt-1.5 inline-flex items-center gap-1.5 text-[10.5px] text-white/45",children:[(0,bt.jsx)($e,{className:"h-3 w-3 animate-spin"})," Loading ",L," preview",L>1?"s":"","\u2026"]}):null]})]}),(0,bt.jsxs)("div",{className:"min-h-0 flex-1 overflow-auto overlay-scroll px-4 space-y-3",children:[[...I].map(([P,H])=>(0,bt.jsxs)("section",{className:"rounded-lg border border-white/8 bg-black/20",children:[(0,bt.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1.5 border-b border-white/5",children:[(0,bt.jsxs)("span",{className:`inline-flex items-center rounded-full border px-2 py-0.5 text-[10px] font-semibold ${VL[P].chip}`,children:[VL[P].label," \xB7 ",H.length]}),R?null:(0,bt.jsxs)("div",{className:"ml-auto flex items-center gap-1.5",children:[(0,bt.jsxs)("button",{type:"button",disabled:p||H.every(v),onClick:()=>{O(H,"dismiss")},className:`${pc} bg-white/[0.04] hover:bg-white/[0.08] text-white/70`,children:[(0,bt.jsx)(ma,{className:"h-3 w-3"})," Confirm & dismiss ",H.length]}),(0,bt.jsxs)("button",{type:"button",disabled:p||H.every(v),onClick:()=>{O(H,"approve")},className:`${pc} bg-emerald-500/20 hover:bg-emerald-500/30 border border-emerald-400/40 text-emerald-100 font-semibold`,children:[(0,bt.jsx)(Ns,{className:"h-3 w-3"})," Confirm & approve ",H.length]})]})]}),H.map(w=>{let N=f[w.id],j=m[w.id];return(0,bt.jsxs)("div",{className:"border-b border-white/5 last:border-0",children:[(0,bt.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1 text-[10.5px]",children:[(0,bt.jsx)("span",{className:"min-w-0 flex-1 truncate font-mono text-white/70",title:w.uri,children:w.uri}),j?(0,bt.jsx)("span",{className:$L[j.outcome].tone,title:j.detail,children:$L[j.outcome].label}):null]}),(0,bt.jsx)(WE,{rec:w,preview:N})]},w.id)})]},P)),d.filter(P=>f[P.id]instanceof Error).map(P=>(0,bt.jsxs)("div",{className:"rounded-md bg-rose-500/10 px-2.5 py-1.5 text-[10.5px] text-rose-200/90",children:[P.uri,": ",f[P.id].message]},P.id))]}),(0,bt.jsxs)("div",{className:"flex items-center justify-end gap-2 p-4 pt-3 shrink-0",children:[(0,bt.jsxs)("button",{type:"button",onClick:a,disabled:p,className:`${pc} bg-white/[0.04] hover:bg-white/[0.08] text-white/70`,children:[(0,bt.jsx)(Yt,{className:"h-3 w-3"})," ",Object.keys(m).length?"Close":"Cancel"]}),k&&o&&i>0?(0,bt.jsxs)("button",{type:"button",onClick:()=>o(d.map(P=>P.id)),className:`${pc} border border-amber-400/40 bg-amber-500/15 hover:bg-amber-500/25 text-amber-100 font-semibold`,children:[(0,bt.jsx)(Ea,{className:"h-3 w-3"})," Next batch (",i," left)"]}):null,R?["revert","dismiss","approve"].map(P=>{let H=P===R.action,w=P==="approve"?Vn:P==="revert"?Oa:ma,N=P==="revert"?"border border-rose-400/40 bg-rose-500/15 hover:bg-rose-500/25 text-rose-100":H?"border border-emerald-400/40 bg-emerald-500/20 hover:bg-emerald-500/30 text-emerald-100 font-semibold":"bg-white/[0.04] hover:bg-white/[0.08] text-white/70";return(0,bt.jsxs)("button",{type:"button",disabled:p||L>0||m[R.rec.id]?.outcome==="ok",onClick:()=>{O([R.rec],P)},className:`${pc} ${N}`,children:[(0,bt.jsx)(w,{className:"h-3 w-3"})," ",H?`Confirm & ${P}`:P[0].toUpperCase()+P.slice(1)]},P)}):null]})]})}),document.body)}var Kf=W(fa(),1);var Tr=W(Je(),1);function XL(t){let e=B(x=>x.client),{agentId:n,projectId:r,sources:a,revisions:s,resetKey:i}=t,[o,l]=(0,Tr.useState)([]),[u,c]=(0,Tr.useState)(!1),d=(0,Tr.useRef)(Promise.resolve()),f=(0,Tr.useRef)(0),h=(0,Tr.useRef)([]),p=(0,Tr.useRef)({}),g=(0,Tr.useRef)(!0),m=(0,Tr.useCallback)(async x=>{if(!n)return;x&&(g.current=!0);let b=++f.current,y=r?{projectId:r}:{},C=d.current.then(async()=>{if(b!==f.current)return;let I=[...h.current],L=g.current;g.current=!1;let v=()=>{h.current=[...I],l([...I])};c(!0);try{for(let k of a){if(!k.git?.isRepo&&!k.git?.containsRepos)continue;let O=k.uri_root.replace("://",""),R=s[O]??0;if(!(!L&&p.current[O]===R))try{let P=await lo({agentId:n,...y,source:O},e);if(b!==f.current)return;for(let H=I.length-1;H>=0;H--)I[H].source===O&&!P.repos.some(w=>w.rel===I[H].repo.rel)&&I.splice(H,1);for(let H of P.repos){let w={source:O,repo:H};try{let j=await bc({agentId:n,...y,source:O,repo:H.rel},e);if(b!==f.current)return;j.ok===!1?w.error="Git status unavailable":w.status=j.status}catch(j){w.error=j instanceof Error?j.message:"Git status failed"}let N=I.findIndex(j=>j.source===O&&j.repo.rel===H.rel);N<0?I.push(w):I[N]=w,v()}p.current[O]=R}catch(P){if(b!==f.current)return;let H={source:O,repo:{rel:"",name:O},error:P instanceof Error?P.message:"Repository discovery failed"},w=I.findIndex(N=>N.source===O&&N.repo.rel==="");w>=0?I[w]=H:I.push(H),p.current[O]=R,v()}}b===f.current&&v()}finally{b===f.current&&c(!1)}});d.current=C.catch(()=>{}),await C},[n,r,a,s]);return(0,Tr.useEffect)(()=>{f.current++,h.current=[],p.current={},g.current=!0,l([])},[i]),(0,Tr.useEffect)(()=>(m(!1),()=>{f.current++}),[m]),{groups:o,loading:u,refresh:m}}var le=W(Je(),1);var JL=W(nr(),1);var Y=W(ue(),1),ZL={create:(0,Y.jsx)(Bs,{className:"w-3.5 h-3.5 text-emerald-300/80"}),modify:(0,Y.jsx)(Es,{className:"w-3.5 h-3.5 text-sky-300/80"}),delete:(0,Y.jsx)(_t,{className:"w-3.5 h-3.5 text-red-300/80"}),move:(0,Y.jsx)(Vl,{className:"w-3.5 h-3.5 text-violet-300/80"})},QL=t=>t==="approved"?"bg-emerald-400":t==="reverted"?"bg-white/30":"bg-amber-400";function e2({diff:t}){return!t||t.added===0&&t.removed===0?null:(0,Y.jsxs)("span",{className:"font-mono text-[10px] shrink-0",children:[t.added>0?(0,Y.jsxs)("span",{className:"text-emerald-300",children:["+",t.added]}):null,t.added>0&&t.removed>0?" ":null,t.removed>0?(0,Y.jsxs)("span",{className:"text-red-300",children:["\u2212",t.removed]}):null]})}var t2=(0,Y.jsxs)("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-rose-500/15 text-rose-200/90 text-[10px] shrink-0",title:"The backing file no longer exists \u2014 this change can only be discarded.",children:[(0,Y.jsx)(ru,{className:"w-3 h-3"})," Orphaned"]});function n2({orphaned:t,busy:e,onApprove:n,onRevert:r,onDiscard:a,onDismiss:s,className:i}){let o=(0,Y.jsx)(Kf.LiveSpinner,{className:"w-3.5 h-3.5"});return(0,Y.jsx)("div",{className:i,children:t?(0,Y.jsx)("button",{type:"button",onClick:a,disabled:e,title:"Discard (remove this un-actionable change)",className:"p-1 rounded hover:bg-rose-500/15 text-rose-300/80 disabled:opacity-40",children:e?o:(0,Y.jsx)(_t,{className:"w-3.5 h-3.5"})}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)("button",{type:"button",onClick:n,disabled:e,title:"Approve",className:"p-1 rounded hover:bg-emerald-500/15 text-emerald-300/80 disabled:opacity-40",children:e?o:(0,Y.jsx)(Vn,{className:"w-3.5 h-3.5"})}),(0,Y.jsx)("button",{type:"button",onClick:r,disabled:e,title:"Revert",className:"p-1 rounded hover:bg-red-500/15 text-red-300/80 disabled:opacity-40",children:(0,Y.jsx)(Oa,{className:"w-3.5 h-3.5"})}),(0,Y.jsx)("button",{type:"button",onClick:s,disabled:e,title:"Dismiss (stop reviewing \u2014 keep the change, no revert)",className:"p-1 rounded hover:bg-white/10 text-white/50 hover:text-white/80 disabled:opacity-40",children:(0,Y.jsx)(ma,{className:"w-3.5 h-3.5"})})]})})}function YL({uri:t,rows:e,agentId:n,projectId:r,canWrite:a,revisions:s,queue:i}){let o=e.get(Ja(t));return o?(0,Y.jsx)(Y.Fragment,{children:[...o.values()].map(l=>(0,Y.jsx)(le.default.Fragment,{children:[!0,!1].filter(u=>u?l.staged:l.unstaged).map(u=>(0,Y.jsxs)("div",{children:[(0,Y.jsxs)("div",{className:"px-3 py-1 text-[10px] text-white/40",children:[l.group.repo.name," (",l.group.repo.rel||"root",") \xB7 ",u?"Git HEAD \u2192 index (staged)":"Git index \u2192 working file (unstaged/untracked)"]}),(0,Y.jsx)("div",{className:"max-h-72 overflow-auto overlay-scroll",style:{scrollbarGutter:"auto"},children:(0,Y.jsx)(Di,{source:l.group.source,repo:l.group.repo.rel,path:l.path,mode:{kind:"working",staged:u},agentId:n,projectId:r,variant:"card",canWrite:a&&l.group.repo.canWrite===!0,revision:s[l.group.source]??0,runContent:i.run,peekContent:i.peek})})]},String(u)))},`${l.group.source}/${l.group.repo.rel}/${l.path}`))}):null}var r2=(t,e)=>`preview\0${t.id}\0${t.updatedAt}\0${e}`,jE=t=>2*((t.baseline.state==="text"?t.baseline.text.length:0)+(t.current.state==="text"?t.current.text.length:0))+256,qE=(0,le.memo)(function({rec:e,agentId:n,projectId:r,focused:a,orphaned:s,onOpen:i,onApprove:o,onRevert:l,onDiscard:u,onDismiss:c,onFocus:d,busy:f,queue:h,revision:p,canWrite:g,onPreview:m,peekPreview:x,takeRefetch:b,extra:y}){let C=B(Q=>Q.client),[I,L]=(0,le.useState)(!0),[v,k]=(0,le.useState)(()=>x(e.id)??null),[O,R]=(0,le.useState)(!1),[P,H]=(0,le.useState)(null),[w,N]=(0,le.useState)(""),j=(0,le.useRef)(0),K=h.visible.has(e.id),A=(0,le.useRef)(!1);A.current=I&&K;let F=r2(e,p),_=(0,le.useRef)("");(0,le.useEffect)(()=>{let Q=++j.current;if(!I||!K||_.current===F){R(!1);return}let te=b(e.id,F);if(te==="wait"){R(!0);return}if(te){k(te),H(null),N(F),_.current=F,R(!1);return}return R(!0),h.run(()=>uo({agentId:n,...r?{projectId:r}:{},id:e.id},C),()=>Q===j.current&&A.current,{key:F,bytes:jE}).then(ge=>{!ge||Q!==j.current||!A.current||(m(ge),k(ge),H(null),N(F),_.current=F,R(!1))}).catch(ge=>{Q===j.current&&(H(ge instanceof Error?ge.message:"Failed to load review"),R(!1))}),()=>{j.current++}},[C,n,r,e.id,F,I,K,h.run]);let X=(0,le.useMemo)(()=>v?qf(v):null,[v]),re=(0,le.useMemo)(()=>X?jf(X):null,[X]),ae=w===F?v?.indexState??null:null,Le=P??(v&&v.diffState!=="readable"?`Review diff unavailable: ${v.diffState}; current ${v.current.state}, baseline ${v.baseline.state}.`:null),ye=(0,le.useCallback)(()=>L(Q=>!Q),[]),q=e.diff&&(e.diff.added>0||e.diff.removed>0)?e.diff:re??void 0;return(0,Y.jsxs)("div",{ref:Q=>h.register(e.id,Q),onMouseDown:d,className:`rounded-lg border overflow-hidden transition-colors ${s?"border-rose-400/30 bg-rose-500/[0.04]":a?"border-amber-400/40 ring-1 ring-amber-400/25 bg-amber-400/[0.03]":"border-white/8 bg-black/20"}`,children:[(0,Y.jsxs)("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 px-2.5 py-1.5",children:[(0,Y.jsx)("button",{type:"button",onClick:ye,"aria-expanded":I,className:"text-white/40 hover:text-white/80 shrink-0",children:I?(0,Y.jsx)(qt,{className:"w-3.5 h-3.5"}):(0,Y.jsx)(Sn,{className:"w-3.5 h-3.5"})}),ZL[e.op],(0,Y.jsxs)("button",{type:"button",onClick:()=>i(e.uri),className:"min-w-[6rem] flex-1 text-left truncate text-xs text-white/85 hover:text-white",title:e.uri,children:[It(e.uri)||e.uri,(0,Y.jsxs)("span",{className:"ml-1.5 text-[10px] text-white/30 font-mono",children:[ct(e.uri),"/"]})]}),(0,Y.jsx)(e2,{diff:q}),ae&&ae!=="stored"?(0,Y.jsx)("span",{className:"text-[10px] text-amber-200/80 shrink-0",children:ae==="missing"?"Index missing":ae==="stale"?"Index stale":"Recovery only"}):null,e.conflict==="PENDING_GENERATION_CHANGED"?(0,Y.jsx)("span",{className:"text-[10px] text-amber-200/80 shrink-0",title:"Pending generation changed; this record cannot be repaired automatically.",children:"Pending generation changed"}):null,s?t2:e.status==="approved"||e.status==="reverted"?(0,Y.jsx)("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${QL(e.status)}`,title:e.status}):null,g?(0,Y.jsx)(n2,{orphaned:s,busy:f,onApprove:o,onRevert:l,onDiscard:u,onDismiss:c,className:"ml-auto flex items-center gap-1 shrink-0"}):null]}),I?(0,Y.jsxs)("div",{className:"border-t border-white/5",children:[(0,Y.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1 text-[10px] text-white/40",children:["Review baseline \u2192 current file",O&&v?(0,Y.jsx)(Kf.LiveSpinner,{className:"w-3 h-3"}):null]}),(0,Y.jsx)("div",{className:"max-h-72 overflow-auto overlay-scroll",style:{scrollbarGutter:"auto"},children:O&&!v?(0,Y.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-xs text-white/40",children:[(0,Y.jsx)(Kf.LiveSpinner,{className:"w-3.5 h-3.5"})," Loading diff\u2026"]}):Le?(0,Y.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-xs text-red-300/80",children:[(0,Y.jsx)(gt,{className:"w-3.5 h-3.5"})," ",Le]}):X?(0,Y.jsx)(hl,{hunks:X,language:pl(e.uri),maxLines:600}):null})]}):null,I?y:null]})}),xl="bg-transparent border border-white/8 rounded px-1.5 py-0.5 text-white/70",bl={background:"var(--w-composer-bg-rgb, rgba(20,20,28,1))"},VE={kind:"all",source:"",repo:"",branch:"",agent:"",origin:""},mc=100;function a2({agentId:t,projectId:e}){let n=B(U=>U.client),r=Ln(),a=cs({grantedFeatures:[...r.grantedFeatures??[]]},"drive.write"),s=mi(),i=B(U=>U.sources),o=B(U=>U.sourceChangeRevision),[l,u]=(0,le.useState)(null),c=l??o,d=(0,le.useRef)(o);d.current=o;let f=(0,le.useRef)(o),h=(0,le.useCallback)(()=>u(U=>U??d.current),[]),p=B(U=>U.pendingPanelFilter),g=B(U=>U.setPendingPanelFilter),m=B(U=>U.openFile),x=B(U=>U.removeFilePath),b=B(U=>U.setActiveWorkspaceTab),y=B(U=>U.refreshPendingCount),C=p.conversationId??"",[I,L]=(0,le.useState)(null),v=No(I),k=(0,le.useRef)(new Map),O=(0,le.useCallback)(U=>k.current.get(U),[]),R=(0,le.useRef)(new Map),P=(0,le.useRef)(Promise.withResolvers()),H=(0,le.useCallback)((U,ce)=>{let Te=R.current.get(U);return Te===null?"wait":(Te&&R.current.delete(U),Te?.key===ce?Te.preview:void 0)},[]),[w,N]=(0,le.useState)(VE),j=U=>ce=>N(Te=>({...Te,[U]:ce.target.value})),[K,A]=(0,le.useState)("cards"),[F,_]=(0,le.useState)([]),[X,re]=(0,le.useState)(new Set),[ae,Le]=(0,le.useState)(!1),[ye,q]=(0,le.useState)(null),[Q,te]=(0,le.useState)(null),[ge,de]=(0,le.useState)({}),De=(0,le.useRef)({nonces:ge,revisions:c});De.current={nonces:ge,revisions:c};let Xe=(0,le.useCallback)(async U=>{let ce=We.current;R.current.set(U.id,null);try{let Te=(await P.current.promise)?.find(Bt=>Bt.id===U.id)??U;if(ce!==We.current)throw new Error("Review context changed");let zt=await uo({agentId:t,...e?{projectId:e}:{},id:U.id},n);if(ce!==We.current)throw new Error("Review context changed");let wt=(De.current.nonces[U.id]??0)+1+(De.current.revisions[Te.sourceSlug]??0);return R.current.set(U.id,{key:r2(Te,wt),preview:zt}),k.current.set(U.id,zt),zt}catch(Te){throw ce===We.current&&R.current.delete(U.id),Te}finally{ce===We.current&&de(Te=>({...Te,[U.id]:(Te[U.id]??0)+1}))}},[n,t,e]),[Qe,rt]=(0,le.useState)(0),[at,Ft]=(0,le.useState)(null),[Ue,ut]=(0,le.useState)([]),[st,yt]=(0,le.useState)(!1),[vt,Ut]=(0,le.useState)(!1),[Et,me]=(0,le.useState)(!1),[Ye,cn]=(0,le.useState)(!1),[fe,Re]=(0,le.useState)(new Set),Oe=(0,le.useRef)(null),Pe=(0,le.useRef)(0),ze=(0,le.useRef)(0),We=(0,le.useRef)(0),nt=(0,le.useRef)(F);nt.current=F;let Vt=(0,le.useRef)(new Map),[et,At]=(0,le.useState)(),[bn,Ve]=(0,le.useState)(!1),[Be,Rt]=(0,le.useState)(""),he=(0,le.useRef)(!1),Me=(0,le.useRef)(void 0),[xe,Fe]=(0,le.useState)(!1),ve=U=>JSON.stringify([U.id,U.updatedAt,U.snapshotHash,U.status]),Nt=XL({agentId:t,projectId:e,sources:i,revisions:c,resetKey:`${t}\0${e}\0${C}`}),pt=(0,le.useCallback)(async(U,ce=!1)=>{if(!t)return;let Te=++Pe.current,zt=U?++ze.current:ze.current,wt=We.current;Le(!0),q(null);try{let Bt=await Cc({agentId:t,...e?{projectId:e}:{},...C?{conversationId:C}:{},...U?{include_orphans:!0}:{},...ce&&et?{cursor:et}:{}},n);if(wt!==We.current)return;if(U&&zt===ze.current){for(let en of Bt.changes)Vt.current.set(en.id,`${ve(en)}:${Bt.orphanIds?.includes(en.id)===!0}`);re(new Set(nt.current.filter(en=>Vt.current.get(en.id)===`${ve(en)}:true`).map(en=>en.id)))}if(Te!==Pe.current)return;if(Bt.restartRequired){At(void 0),q("Changes moved. Refresh to restart the list.");return}let Qt=new Map(nt.current.map(en=>[en.id,en])),ca=new Map(Bt.changes.map(en=>[en.id,en])),ao=ce?[...nt.current.map(en=>ca.get(en.id)??en),...Bt.changes.filter(en=>!Qt.has(en.id))]:Bt.changes;return nt.current=ao,_(ao),re(new Set(ao.filter(en=>Vt.current.get(en.id)===`${ve(en)}:true`).map(en=>en.id))),At(Bt.nextCursor),Ve(Bt.partial),ao}catch(Bt){wt===We.current&&Te===Pe.current&&q(Bt instanceof Error?Bt.message:"Failed to load changes");return}finally{wt===We.current&&Te===Pe.current&&Le(!1)}},[n,t,e,C,et]),kn=(0,le.useCallback)(async()=>{await Promise.all([pt(!0),Nt.refresh(!0)]),y({agentId:t,projectId:e})},[pt,Nt.refresh,y,t,e]);(0,le.useEffect)(()=>(We.current++,he.current=!0,Me.current=void 0,Fe(!1),P.current.resolve(void 0),P.current=Promise.withResolvers(),R.current.clear(),cn(!1),te(null),yt(!1),Ut(!1),me(!1),Vt.current.clear(),k.current.clear(),Ft(null),nt.current=[],_([]),re(new Set),ut([]),At(void 0),Ve(!1),u(null),pt(!0),()=>{We.current++,Pe.current++,ze.current++,he.current=!0,k.current.clear()}),[n,t,e,C]);let yn=(0,le.useRef)(pt);yn.current=pt;let Nn=(0,le.useRef)(!0);(0,le.useEffect)(()=>{if(Nn.current){Nn.current=!1;return}c!==f.current&&yn.current(!1)},[c]);let dn=Nt.groups,cr=(0,le.useMemo)(()=>Array.from(new Set([...F.map(U=>U.sourceSlug),...dn.map(U=>U.source)])).sort(),[F,dn]),yr=(0,le.useMemo)(()=>Array.from(new Set(F.map(U=>U.agentId).filter(Boolean))).sort(),[F]),dr=(0,le.useMemo)(()=>Array.from(new Set(F.map(U=>U.origin).filter(Boolean))).sort(),[F]),Ot=(0,le.useMemo)(()=>GL(F,dn,w),[F,dn,w]),Dr=(0,le.useMemo)(()=>UL(dn,w),[dn,w]),fr=(0,le.useMemo)(()=>HL(Dr),[Dr]),jn=(0,le.useMemo)(()=>zL(Ot,fr,w.kind,K),[Ot,fr,w.kind,K]),[oa,Qn]=(0,le.useState)(0),{approvable:Mn,needsAck:Tn}=(0,le.useMemo)(()=>qL(Ot,X,mc,O),[Ot,X,O,oa]),vr=(0,le.useRef)(new Set),qn=Tn.filter(U=>!vr.current.has(U.id)),la=(0,le.useCallback)(U=>{for(let Te of U)vr.current.add(Te);let ce=Tn.filter(Te=>!vr.current.has(Te.id));Ft({kind:"group",records:ce.slice(0,mc),total:ce.length})},[Tn]),er=(0,le.useRef)(jn);er.current=jn;let hr=(0,le.useCallback)(U=>WL(er.current[U]?.kind??"pending-card"),[]),fn=(0,le.useCallback)(U=>er.current[U]?.key??U,[]),wr=So({count:jn.length,getScrollElement:()=>I,estimateSize:hr,getItemKey:fn,overscan:4});wr.shouldAdjustScrollPositionOnItemSizeChange=$E,(0,le.useEffect)(()=>{rt(U=>Ot.length===0?0:Math.min(U,Ot.length-1))},[Ot.length]);let E=jn.length-Ot.length;(0,le.useEffect)(()=>{Ot.length>0&&wr.scrollToIndex(E+Qe,{align:"auto"})},[Qe,K]);let ne=(0,le.useCallback)(U=>{m({agentId:t,projectId:e,uri:U}),b("file")},[t,e,m,b]),se=(0,le.useCallback)(U=>{if(U.op!=="delete"||!U.uri)return;let ce=s.getState().files[U.uri];(!ce||ce.status==="deleted")&&x(U.uri)},[x,s]),_e=(0,le.useCallback)(async U=>{let ce=We.current;for(let wt of U){let Bt=F.find(Qt=>Qt.id===wt.id);Bt&&wt.outcome==="ok"&&wt.action!=="revert"&&se(Bt),wt.outcome!=="ok"&&wt.outcome!=="needs-ack"&&!R.current.has(wt.id)&&k.current.delete(wt.id)}let Te=U.filter(wt=>wt.outcome!=="ok"&&wt.outcome!=="needs-ack"&&!R.current.has(wt.id));Te.length&&de(wt=>{let Bt={...wt};for(let Qt of Te)Bt[Qt.id]=(Bt[Qt.id]??0)+1;return Bt}),ut(U);let zt=await pt(!1);ce===We.current&&(f.current=s.getState().sourceChangeRevision,u(null),P.current.resolve(zt),P.current=Promise.withResolvers(),y({agentId:t,projectId:e}))},[F,se,pt,y,t,e,s]),D=(0,le.useCallback)(async(U,ce)=>{if(!a)return;let Te=k.current.get(U.id);if(!Te||Te.requiresAcknowledgement.length){Ft({kind:"single",rec:U,action:ce,...Te?{preview:Te}:{}});return}let zt=We.current;te(U.id);try{let wt=await Vf({agentId:t,projectId:e,client:n},U,Te,ce,!1);zt===We.current&&await _e([wt])}finally{zt===We.current&&te(null)}},[n,a,t,e,_e]),we=(0,le.useCallback)(async U=>{let ce=We.current;te(U.id);try{let Te=await ix({agentId:t,...e?{projectId:e}:{},id:U.id},n);if(ce!==We.current)return;Te.ok?se(U):q(Te.error||"Discard failed"),await pt(!1),y({agentId:t,projectId:e})}catch(Te){ce===We.current&&q(Te instanceof Error?Te.message:"Discard failed")}finally{ce===We.current&&te(null)}},[n,t,e,pt,se,y]),$t=(0,le.useCallback)(async()=>{Oe.current&&(clearTimeout(Oe.current),Oe.current=null);let U=We.current;he.current=!1,h(),cn(!0),me(!1),q(null);let ce=Me.current;Fe(!1);let Te=0,zt=0,wt=0,Bt=0;try{do{let Qt=await lx({agentId:t,...e?{projectId:e}:{},...C?{conversationId:C}:{},...ce?{cursor:ce}:{}},n);if(U!==We.current)return;if(Te+=Qt.scannedVisible,zt+=Qt.discarded,wt+=Qt.refused,Bt+=Qt.failed,Rt(`${Te} scanned \xB7 ${zt} discarded \xB7 ${wt} refused \xB7 ${Bt} failed`),ce=Qt.nextCursor,Me.current=ce,Qt.restartRequired){Me.current=void 0,Fe(!0),q("Changes moved. Refresh before continuing repair.");break}if(Qt.failed>0){Fe(!0),q("Repair paused after a failed change. Refresh before continuing.");break}if(Qt.partial){Fe(!0),q("Repair paused; part of the inventory or orphan checks are unavailable.");break}}while(ce&&!he.current);if(ce&&Fe(!0),U!==We.current||(await pt(!0),U!==We.current))return;f.current=s.getState().sourceChangeRevision,u(null),y({agentId:t,projectId:e})}catch(Qt){U===We.current&&(Fe(!0),q(Qt instanceof Error?Qt.message:"Repair failed"))}finally{U===We.current&&(cn(!1),u(null))}},[n,t,e,C,pt,y,h,s]),Gt=(0,le.useCallback)(()=>{if(Et){$t();return}me(!0),Oe.current&&clearTimeout(Oe.current),Oe.current=setTimeout(()=>me(!1),3e3)},[Et,$t]);(0,le.useEffect)(()=>()=>{Oe.current&&clearTimeout(Oe.current)},[]);let In=(0,le.useCallback)(async()=>{let U=We.current;yt(!0),Ut(!1),q(null),h();let ce=[];try{for(let Te of Mn){if(U!==We.current)break;let zt=k.current.get(Te.id);if(!zt){try{zt=await uo({agentId:t,...e?{projectId:e}:{},id:Te.id},n)}catch(wt){ce.push({id:Te.id,uri:Te.uri,action:"approve",outcome:"error",detail:wt instanceof Error?wt.message:"Preview failed"});continue}if(U!==We.current)break;k.current.set(Te.id,zt)}if(zt.requiresAcknowledgement.length){ce.push({id:Te.id,uri:Te.uri,action:"approve",outcome:"needs-ack"});continue}ce.push(await Vf({agentId:t,projectId:e,client:n},Te,zt,"approve",!1))}}finally{if(U!==We.current)return;yt(!1);let Te=Mn.filter(zt=>ce.some(wt=>wt.id===zt.id&&wt.outcome==="needs-ack"));if(Te.length&&Qn(zt=>zt+1),await _e(ce),U!==We.current)return;Te.length&&a&&(vr.current.clear(),Ft({kind:"group",records:Te.slice(0,mc),total:Te.length}))}},[Mn,t,e,n,_e,a]),Zt=(0,le.useCallback)(U=>rt(ce=>Ot.length===0?0:Math.max(0,Math.min(Ot.length-1,ce+U))),[Ot.length]),Ls=(0,le.useCallback)(U=>{if(Q||st||!a||at)return;let ce=Ot[Qe],Te=ce?X.has(ce.id):!1;U.key==="ArrowDown"||U.key==="ArrowRight"?(U.preventDefault(),Zt(1)):U.key==="ArrowUp"||U.key==="ArrowLeft"?(U.preventDefault(),Zt(-1)):Te&&ce&&(U.key==="d"||U.key==="r"||U.key==="Enter")?(U.preventDefault(),we(ce)):(U.key==="a"||U.key==="Enter")&&ce?(U.preventDefault(),D(ce,"approve")):U.key==="r"&&ce?(U.preventDefault(),D(ce,"revert")):U.key==="x"&&!Te&&ce&&(U.preventDefault(),D(ce,"dismiss"))},[Q,st,a,at,Ot,Qe,X,Zt,we,D]),Z=U=>{if(U.kind==="git"){let Bt=!fe.has(U.uri);return(0,Y.jsxs)("div",{ref:Qt=>v.register(U.uri,Qt),className:"rounded-lg border border-white/8 bg-black/20",children:[(0,Y.jsx)("button",{type:"button","aria-expanded":Bt,className:"px-3 py-2 text-xs text-white/85",onClick:()=>Re(Qt=>{let ca=new Set(Qt);return ca.has(U.uri)?ca.delete(U.uri):ca.add(U.uri),ca}),children:U.uri}),Bt?(0,Y.jsx)(YL,{uri:U.uri,rows:fr,agentId:t,projectId:e,canWrite:a,revisions:c,queue:v}):null]})}let{rec:ce,index:Te}=U,zt=X.has(ce.id),wt={onApprove:()=>{D(ce,"approve")},onRevert:()=>{D(ce,"revert")},onDiscard:()=>{we(ce)},onDismiss:()=>{D(ce,"dismiss")}};return U.kind==="pending-card"?(0,Y.jsx)(qE,{rec:ce,agentId:t,projectId:e,focused:Te===Qe,orphaned:zt,onOpen:ne,...wt,onFocus:()=>rt(Te),busy:Q===ce.id,queue:v,revision:(ge[ce.id]??0)+(c[ce.sourceSlug]??0),canWrite:a,onPreview:Bt=>{k.current.set(ce.id,Bt),Bt.requiresAcknowledgement.length&&Qn(Qt=>Qt+1)},peekPreview:O,takeRefetch:H,extra:w.kind==="all"?(0,Y.jsx)(YL,{uri:ce.uri,rows:fr,agentId:t,projectId:e,canWrite:a,revisions:c,queue:v}):null}):(0,Y.jsxs)("div",{onMouseDown:()=>rt(Te),className:`group h-8 flex items-center gap-2 px-2 rounded-lg ${Te===Qe?"bg-amber-400/[0.06] ring-1 ring-amber-400/20":"hover:bg-white/5"}`,children:[ZL[ce.op],(0,Y.jsxs)("button",{type:"button",onClick:()=>ne(ce.uri),className:"min-w-0 flex-1 text-left truncate text-xs text-white/85 hover:text-white",title:ce.uri,children:[It(ce.uri)||ce.uri,(0,Y.jsxs)("span",{className:"ml-1.5 text-[10px] text-white/30 font-mono",children:[ct(ce.uri),"/"]})]}),(0,Y.jsx)(e2,{diff:ce.diff}),zt?t2:(0,Y.jsx)("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${QL(ce.status)}`,title:ce.status}),a?(0,Y.jsx)(n2,{orphaned:zt,busy:Q===ce.id,...wt,className:"hidden group-hover:flex items-center gap-0.5 shrink-0"}):null]})},rn=We.current,hn=Ue.filter(U=>U.outcome!=="ok"),ua=ae||Nt.loading;return(0,Y.jsxs)("div",{className:"w-full h-full flex flex-col min-h-0 outline-none",tabIndex:0,onKeyDown:Ls,children:[a&&at?(0,Y.jsx)($f,{request:at,agentId:t,projectId:e,run:v.run,onClose:()=>Ft(null),next:at.kind==="group"?qn.filter(U=>!at.records.some(ce=>ce.id===U.id)).length:0,onNext:la,refetch:Xe,onBatchStart:h,onDone:U=>{if(rn===We.current){for(let ce of U)vr.current.add(ce.id);_e(U)}}},at.kind==="group"?`group\0${at.records[0]?.id??""}`:`single\0${at.rec.id}`):null,(0,Y.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5 px-3 py-2 border-b border-white/5 shrink-0",children:[(0,Y.jsx)("span",{className:"text-xs font-semibold text-white/80",children:"Changes"}),(0,Y.jsx)("span",{className:"text-[10px] text-white/35",children:Ot.length>0?`${Math.min(Qe+1,Ot.length)}/${Ot.length}`:"0"}),(0,Y.jsxs)("div",{className:"ml-auto flex flex-wrap items-center justify-end gap-1",children:[(0,Y.jsxs)("div",{className:"flex items-center rounded-lg border border-white/8 overflow-hidden",children:[(0,Y.jsx)("button",{type:"button",onClick:()=>Zt(-1),disabled:Ot.length===0||Qe===0,className:"p-1.5 text-white/45 hover:text-white/80 disabled:opacity-30",title:"Previous (\u2191)",children:(0,Y.jsx)(Dl,{className:"w-3.5 h-3.5"})}),(0,Y.jsx)("button",{type:"button",onClick:()=>Zt(1),disabled:Ot.length===0||Qe>=Ot.length-1,className:"p-1.5 text-white/45 hover:text-white/80 disabled:opacity-30",title:"Next (\u2193)",children:(0,Y.jsx)(Sn,{className:"w-3.5 h-3.5"})})]}),a?vt?(0,Y.jsxs)("button",{type:"button",onClick:()=>{In()},disabled:st||Mn.length===0,className:"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-emerald-500/30 bg-emerald-500/15 px-2 py-1 text-[10px] text-emerald-100 hover:bg-emerald-500/20 disabled:opacity-40",title:`Approve ${Mn.length} visible change(s) that need no confirmation`,children:[st?(0,Y.jsx)($e,{className:"w-3 h-3 animate-spin"}):(0,Y.jsx)(Ns,{className:"w-3 h-3"})," Approve ",Mn.length,"?"]}):(0,Y.jsxs)("button",{type:"button",onClick:()=>Ut(!0),disabled:Mn.length===0,className:"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-white/8 px-2 py-1 text-[10px] text-white/55 hover:text-white/85 hover:bg-white/5 disabled:opacity-30",title:"Approve every visible change that needs no confirmation",children:[(0,Y.jsx)(Ns,{className:"w-3 h-3"})," Approve ",Mn.length]}):null,a&&Tn.length>0?(0,Y.jsxs)("button",{type:"button",onClick:()=>{vr.current.clear(),Ft({kind:"group",records:Tn.slice(0,mc),total:Tn.length})},className:"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-amber-400/30 px-2 py-1 text-[10px] text-amber-200/90 hover:bg-amber-500/10",title:`Review the changes that need your confirmation, grouped by reason (up to ${mc} at a time)`,children:[(0,Y.jsx)(Ea,{className:"w-3 h-3"})," ",Tn.length," need confirmation"]}):null,(0,Y.jsxs)("div",{className:"flex items-center rounded-lg border border-white/8 overflow-hidden",children:[(0,Y.jsx)("button",{type:"button",onClick:()=>A("list"),title:"Compact list",className:`p-1.5 ${K==="list"?"bg-white/10 text-white":"text-white/45 hover:text-white/80"}`,children:(0,Y.jsx)(gi,{className:"w-3.5 h-3.5"})}),(0,Y.jsx)("button",{type:"button",onClick:()=>A("cards"),title:"Diff cards",className:`p-1.5 ${K==="cards"?"bg-white/10 text-white":"text-white/45 hover:text-white/80"}`,children:(0,Y.jsx)(os,{className:"w-3.5 h-3.5"})})]}),a&&X.size>0?(0,Y.jsxs)("button",{type:"button",onClick:Gt,disabled:Ye,className:Et?"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-rose-500/40 bg-rose-500/15 px-2 py-1 text-[10px] text-rose-100 hover:bg-rose-500/25 disabled:opacity-40":"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-rose-400/25 px-2 py-1 text-[10px] text-rose-200/80 hover:text-rose-100 hover:bg-rose-500/10 disabled:opacity-40",title:Et?`Discard all ${X.size} orphaned change(s)`:"Repair \u2014 discard orphaned changes whose backing file no longer exists",children:[Ye?(0,Y.jsx)($e,{className:"w-3 h-3 animate-spin"}):Et?(0,Y.jsx)(_t,{className:"w-3 h-3"}):(0,Y.jsx)(Ci,{className:"w-3 h-3"}),Et?`Discard ${X.size}?`:`Repair ${X.size}`]}):null,(0,Y.jsx)("button",{type:"button",onClick:()=>{kn()},disabled:ua,title:"Refresh",className:"p-1.5 rounded-lg text-white/45 hover:text-white/80 hover:bg-white/5 disabled:opacity-40",children:(0,Y.jsx)(Xt,{className:`w-3.5 h-3.5 ${ua?"animate-spin":""}`})}),(0,Y.jsx)(JL.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-files",packageId:"@neuralis/brain-core",label:"Review or approve pending changes with the agent",icon:"FileText"})]})]}),Ye?(0,Y.jsx)("button",{type:"button",onClick:()=>{he.current=!0},className:"px-3 py-1 text-xs text-amber-200",children:"Stop after this batch"}):null,Be?(0,Y.jsx)("div",{role:"status",className:"px-3 py-1 text-xs text-white/60",children:Be}):null,a&&xe&&!Ye?(0,Y.jsx)("button",{type:"button",onClick:()=>{$t()},className:"px-3 py-1 text-xs text-amber-200",children:Me.current?"Continue available repair":"Retry repair"}):null,bn?(0,Y.jsx)("div",{role:"status",className:"px-3 py-1 text-xs text-amber-200",children:"Showing available changes; some inventory or orphan checks are unavailable."}):null,et?(0,Y.jsx)("button",{type:"button",disabled:ae||Ye,onClick:()=>{pt(!0,!0)},className:"px-3 py-1 text-xs text-violet-200 disabled:opacity-40",children:"Load more"}):null,(0,Y.jsxs)("div",{className:"flex flex-wrap items-center gap-2 px-3 py-1.5 border-b border-white/5 shrink-0 text-[11px]",children:[C?(0,Y.jsxs)("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-violet-500/15 text-violet-200/90",title:C,children:["conversation ",(0,Y.jsx)("button",{type:"button",onClick:()=>g({}),className:"rounded hover:bg-violet-400/20 -mr-0.5",title:"Clear conversation filter",children:(0,Y.jsx)(Yt,{className:"w-3 h-3"})})]}):null,(0,Y.jsxs)("select",{"aria-label":"Change type",value:w.kind,onChange:j("kind"),className:xl,style:bl,children:[(0,Y.jsx)("option",{value:"all",children:"All changes"}),(0,Y.jsx)("option",{value:"pending",children:"Pending review"}),(0,Y.jsx)("option",{value:"git",children:"Git"})]}),(0,Y.jsxs)("select",{"aria-label":"Source",value:w.source,onChange:j("source"),className:xl,style:bl,children:[(0,Y.jsx)("option",{value:"",children:"All sources"}),cr.map(U=>(0,Y.jsx)("option",{value:U,children:U},U))]}),(0,Y.jsxs)("select",{"aria-label":"Repository",value:w.repo,onChange:j("repo"),className:xl,style:bl,children:[(0,Y.jsx)("option",{value:"",children:"All repositories"}),dn.map(U=>(0,Y.jsx)("option",{value:hc(U),children:p0(U)},hc(U)))]}),(0,Y.jsxs)("select",{"aria-label":"Checked-out branch",value:w.branch,onChange:j("branch"),className:xl,style:bl,children:[(0,Y.jsx)("option",{value:"",children:"All checked-out branches"}),[...new Set(dn.map(U=>U.status?.branch).filter(Boolean))].map(U=>(0,Y.jsx)("option",{value:U,children:U},U))]}),yr.length>1?(0,Y.jsxs)("select",{"aria-label":"Agent",value:w.agent,onChange:j("agent"),className:xl,style:bl,children:[(0,Y.jsx)("option",{value:"",children:"All agents"}),yr.map(U=>(0,Y.jsx)("option",{value:U,children:U},U))]}):null,dr.length>1?(0,Y.jsxs)("select",{"aria-label":"Origin",value:w.origin,onChange:j("origin"),className:xl,style:bl,children:[(0,Y.jsx)("option",{value:"",children:"All origins"}),dr.map(U=>(0,Y.jsx)("option",{value:U,children:U},U))]}):null]}),Dr.filter(U=>U.error).map(U=>(0,Y.jsxs)("div",{className:"px-3 py-2 text-xs text-red-300 shrink-0",children:[p0(U),": ",U.error]},`${U.source}/${U.repo.rel}`)),ye?(0,Y.jsxs)("div",{className:"mx-3 mt-2 flex items-center gap-2 rounded-lg border border-red-500/25 bg-red-500/10 px-2.5 py-1.5 text-[11px] text-red-200/85 shrink-0",children:[(0,Y.jsx)(gt,{className:"w-3.5 h-3.5"})," ",ye]}):null,hn.length?(0,Y.jsxs)("div",{className:"mx-3 mt-2 max-h-28 overflow-auto overlay-scroll rounded-lg border border-amber-500/25 bg-amber-500/[0.06] px-2.5 py-1.5 text-[10.5px] text-amber-100/85 shrink-0",children:[(0,Y.jsxs)("div",{className:"flex items-center gap-2 font-semibold",children:[Ue.length-hn.length," done \xB7 ",hn.length," not done",(0,Y.jsx)("button",{type:"button",onClick:()=>ut([]),className:"ml-auto rounded hover:bg-white/10",title:"Dismiss",children:(0,Y.jsx)(Yt,{className:"w-3 h-3"})})]}),hn.map(U=>(0,Y.jsxs)("div",{className:"truncate font-mono",title:U.detail,children:[U.action," ",U.uri,": ",U.outcome==="changed"?"changed since the preview (409)":U.outcome==="needs-ack"?"needs confirmation \u2014 opened in the review dialog":U.detail??"refused"]},U.id))]}):null,(0,Y.jsx)("div",{ref:L,className:"flex-1 min-h-0 overflow-auto overlay-scroll px-2 py-2",style:{overflowAnchor:"none"},children:ua&&jn.length===0?(0,Y.jsxs)("div",{className:"flex items-center gap-2 px-3 py-6 text-xs text-white/40",children:[(0,Y.jsx)($e,{className:"w-3.5 h-3.5 animate-spin"})," Loading\u2026"]}):jn.length===0?(0,Y.jsx)("div",{className:"px-3 py-8 text-center text-xs text-white/35",children:"No pending review changes."}):(0,Y.jsx)("div",{style:{height:wr.getTotalSize(),width:"100%",position:"relative"},children:wr.getVirtualItems().map(U=>{let ce=jn[U.index];return ce?(0,Y.jsx)("div",{"data-index":U.index,ref:jL(ce.kind)?wr.measureElement:void 0,className:ce.kind==="pending-row"?"":"pb-1.5",style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${U.start}px)`},children:Z(ce)},U.key):null})})})]})}var $E=(t,e,n)=>t.end<=(n.scrollOffset??0);var $=W(ue(),1),KE=2e5,XE=2500,YE=12e3;function s2(t,e){let n=String(t||"").trim().replace(/\\/g,"/");if(!n)return e;if(n.includes("://")){let s=n.indexOf("://"),i=n.slice(0,s),o=n.slice(s+3).replace(/\/+/g,"/").replace(/^\/+/,"");return`${i}://${o}`}let r=kr(e),a=n.replace(/\/+/g,"/").replace(/^\/+/,"");return a?`${r}${a}`:e}function g0(){let t=B(Z=>Z.client),e=B(Z=>Z.openFiles),n=B(Z=>Z.activeFile),r=B(Z=>Z.files),a=B(Z=>Z.fileContentByPath),s=B(Z=>Z.fileBaseContentByPath),i=B(Z=>Z.fileErrorByPath),o=B(Z=>Z.openFile),l=B(Z=>Z.patchFileNode),u=B(Z=>Z.saveFileInPlace),c=B(Z=>Z.markFileDeleted),d=B(Z=>Z.clearFilePrev),f=B(Z=>Z.refresh),h=B(Z=>Z.activeProjectId),p=B(Z=>Z.workspacePanels),g=B(Z=>Z.setWorkspacePanelOpen),m=B(Z=>Z.activeWorkspaceTab),x=B(Z=>Z.setActiveWorkspaceTab),b=B(Z=>Z.gitDiffTarget),y=B(Z=>Z.setGitDiffTarget),C=B(Z=>Z.gitCommitTarget),I=B(Z=>Z.setGitCommitTarget),L=B(Z=>Z.diffViewMode),v=B(Z=>Z.activeAgentId),k=Ln(),O=k.useAgents(),R=(0,ot.useMemo)(()=>qs(O),[O]),P=v?R.byId.get(v)??null:null,H=k.MarkdownRenderer,w=n?r[n]:null,N=n?a[n]??"":"",j=w?.uri??"",K=w?JE(j):!1,A=w?ZE(j):!1,F=w?QE(j):!1,_=w?eO(j):!1,X=w?nO(j):!1,re=w?pd(j):void 0,ae=w?tO(j):"Binary file",Le=K,[ye,q]=(0,ot.useState)(!1),[Q,te]=(0,ot.useState)(""),[ge,de]=(0,ot.useState)(""),[De,Xe]=(0,ot.useState)(!1),[Qe,rt]=(0,ot.useState)(null),[at,Ft]=(0,ot.useState)(!1),[Ue,ut]=(0,ot.useState)(!1),[st,yt]=(0,ot.useState)(!1),[vt,Ut]=(0,ot.useState)(!1),[Et,me]=(0,ot.useState)(!0),[Ye,cn]=(0,ot.useState)(!1),fe=B(Z=>Z.refreshPendingCount),Re=B(Z=>Z.filePrevByPath),Oe=n?Re[n]:void 0,Pe=!!Oe&&w?.status==="pending_review",ze=!!Oe,We=(0,ot.useMemo)(()=>w?w.sourceAgentId?R.byId.get(w.sourceAgentId)??null:P:null,[w,R,P]),nt=n?i[n]:void 0,Vt=!!n&&!Ac({fileBaseContentByPath:s,fileErrorByPath:i},n),et=nt?`Read failed: ${nt}`:Vt?"Loading\u2026":"Empty file",At=w?.status==="deleted",bn=p.upload&&m==="upload",Ve=p.sources&&m==="sources",Be=p.packages&&m==="packages",Rt=p.pending&&m==="pending",he=m==="git-diff"&&!!b,Me=m==="git-commit"&&!!C,xe=!bn&&!Ve&&!Be&&!Rt&&!he&&!Me,Fe=w?.sourceAgentId??v??void 0,ve=w?.sourceAgentId??v??null,Nt=No(null),[pt,kn]=(0,ot.useState)(null),[yn,Nn]=(0,ot.useState)(null),dn=(0,ot.useRef)(0),cr=(0,ot.useRef)(0);(0,ot.useEffect)(()=>(dn.current++,kn(null),Nn(null),()=>{dn.current++}),[t,ve,h,j,n]);let yr=(0,ot.useCallback)(async Z=>{if(!ve||!j)return;let rn=dn.current;Nn(null);try{let hn=await Cc({agentId:ve,...h?{projectId:h}:{},uri:j},t);if(rn!==dn.current)return;let ua=hn.changes.filter(U=>Ja(U.uri)===Ja(j));if(hn.partial||hn.complete===!1||hn.restartRequired||ua.length!==1){Nn("The pending change is unavailable or ambiguous. Refresh and try again.");return}cr.current=rn,kn({kind:"single",rec:ua[0],action:Z})}catch(hn){rn===dn.current&&Nn(hn instanceof Error?hn.message:"Could not load the pending change.")}},[t,ve,h,j]),dr=(0,ot.useMemo)(()=>!w?.uri||!Fe?null:ux(Fe,w.uri,h??void 0),[w?.uri,Fe,h]),Ot=(0,ot.useRef)(null),Dr=(0,ot.useRef)(null),fr=(0,i2.useContainerWidth)(Dr),jn=L==="auto"?fr?"split":"unified":L,[oa,Qn]=(0,ot.useState)(void 0),Mn=w?.git;(0,ot.useEffect)(()=>{let Z=!1;if(!ve||!j||!Mn||A||F||_){Qn(void 0);return}let rn=Ke(j),hn=j.indexOf("://"),ua=hn>=0?j.slice(hn+3):"";if(!rn||!ua){Qn(void 0);return}return(async()=>{try{let U=await yc({agentId:ve,...h?{projectId:h}:{},source:rn,path:ua,staged:!1},t);if(Z)return;if(U&&U.ok===!1){Qn(void 0);return}let ce=typeof U?.diff=="string"?U.diff:"",Te=j1(ce);Qn(yd(Te)?void 0:Te)}catch{Z||Qn(void 0)}})(),()=>{Z=!0}},[ve,h,j,Mn,A,F,_]);let Tn=Li(w?.version?.changedAt),vr=w?.version?.sync,qn=!0,la=!!w&&ye&&(ge!==N||s2(Q,w.uri)!==w.uri),er=w?.version?.diff,hr=!!er&&(er.added>0||er.removed>0),fn=!!w&&Rp(w),wr=(0,ot.useMemo)(()=>{if(!w)return"/";if(w.parentUri&&w.parentUri!==w.uri)return w.parentUri;let Z=ct(w.uri);return Z===w.uri?kr(w.uri):Z},[w]),E=(0,ot.useMemo)(()=>rO(N),[N]),ne=w?.readSource==="live",se=!!w&&!ye&&!A&&!F&&(X||E.charCount>=KE||E.lineCount>=XE||ne&&E.charCount>=YE),_e=(0,ot.useCallback)(async()=>{if(!(!ve||!w||at)){Ft(!0),rt(null);try{await c({agentId:ve,projectId:h??null,node:w})}catch(Z){console.error("[Filesystem] delete failed",Z),rt(Z instanceof Error?Z.message:"Delete failed")}finally{Ft(!1)}}},[ve,w,at,h,c]),D=(0,ot.useCallback)(async()=>{if(!(!ve||!w||Ue)){ut(!0);try{let Z=await Er({agentId:ve,...h?{projectId:h}:{},id:w.id,uri:w.uri,fields:{status:"active"}},t);if(Z&&Z.ok===!1){rt(Pa(Z,"Restore failed"));return}f({agentId:ve,projectId:h??null}),o({agentId:ve,projectId:h??null,uri:w.uri,readAgentId:We?.id,force:!0})}catch(Z){console.error("[Filesystem] restore failed",Z)}finally{ut(!1)}}},[ve,w,Ue,h,f,o,We?.id]),we=(0,ot.useCallback)(async()=>{if(!(!ve||!w||st)){if(w.status==="pending_review"){await yr("approve");return}yt(!0);try{let Z=await Sc({agentId:ve,...h?{projectId:h}:{},id:w.id,uri:w.uri},t);if(Z&&Z.ok){let rn=w.storeKey||n||as(w);rn&&(l(rn,{status:"active"}),d(rn)),o({agentId:ve,projectId:h??null,uri:w.uri,readAgentId:We?.id,force:!0})}}catch(Z){console.error("[Filesystem] approve failed",Z)}finally{yt(!1)}}},[yr,t,ve,w,st,h,o,We?.id,n,l,d]),$t=(0,ot.useCallback)(async()=>{if(!(!ve||!w||vt)){if(w.status==="pending_review"){await yr("revert");return}Ut(!0);try{let Z=await Er({agentId:ve,...h?{projectId:h}:{},id:w.id,uri:w.uri,revert:!0},t);if(Z&&Z.ok===!1){rt(Pa(Z,"Revert failed"));return}if(Z&&Z.ok){let rn=w.storeKey||n||as(w);rn&&(l(rn,{status:Oe?.status||"active"}),d(rn)),o({agentId:ve,projectId:h??null,uri:w.uri,readAgentId:We?.id,force:!0})}}catch(Z){console.error("[Filesystem] revert failed",Z)}finally{Ut(!1)}}},[yr,t,ve,w,vt,h,o,We?.id,n,Oe,l,d]);(0,ot.useEffect)(()=>{if(!w){Ot.current=null,q(!1),cn(!1),te(""),de(""),rt(null);return}let Z=w.storeKey||n||as(w),rn=Ot.current!==Z;if(Ot.current=Z,rn){q(!1),cn(!1),me(!0),te(w.uri),de(N),rt(null);return}ye||(te(w.uri),de(N),rt(null))},[w?.storeKey,w?.uri,N,n,ye]);let Gt=(0,ot.useCallback)(()=>{fn&&cn(Z=>!Z)},[fn]),In=(0,ot.useCallback)(()=>{!w||At||(te(w.uri),de(N),rt(null),q(!0))},[w,N,At]),Zt=(0,ot.useCallback)(()=>{w&&(te(w.uri),de(N),rt(null),q(!1))},[w,N]),Ls=(0,ot.useCallback)(async()=>{if(!w||!ve||De)return;let Z=w.uri,rn=s2(Q,Z);if(!rn){rt("Invalid target URI");return}Xe(!0),rt(null);try{await u({agentId:ve,projectId:h??null,readAgentId:We?.id,node:w,targetUri:rn,content:ge,currentContent:N}),me(!0),q(!1)}catch(hn){rt(hn instanceof Error?hn.message:"Save failed")}finally{Xe(!1)}},[w,ve,De,Q,ge,N,h,We?.id,u]);return(0,$.jsxs)("div",{className:"h-full w-full flex flex-col min-w-0 min-h-0",children:[yn?(0,$.jsx)("div",{role:"alert",className:"px-3 py-2 text-xs text-red-300",children:yn}):null,pt&&ve?(0,$.jsx)($f,{request:pt,agentId:ve,projectId:h,run:Nt.run,onClose:()=>kn(null),onDone:Z=>{cr.current!==dn.current||!Z.some(rn=>rn.outcome==="ok")||(kn(null),fe({agentId:ve,projectId:h}),o({agentId:ve,projectId:h??null,uri:j,force:!0}))}}):null,e.length>0||p.upload||qn&&p.sources||p.packages||p.pending||b||C?(0,$.jsxs)("div",{className:"flex shrink-0 items-stretch",style:{backgroundColor:"transparent",borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,$.jsxs)("div",{[vd]:"",className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden",children:[(0,$.jsx)($1,{}),p.upload?(0,$.jsxs)("div",{className:"group flex shrink-0 items-center",children:[(0,$.jsxs)("button",{type:"button",className:V("flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",bn?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>x("upload"),children:[(0,$.jsx)(Ba,{className:"w-3.5 h-3.5 shrink-0"}),(0,$.jsx)("span",{className:"truncate flex-1",children:"Upload"})]}),(0,$.jsx)("button",{type:"button","aria-label":"Close Upload",className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:Z=>{Z.stopPropagation(),g("upload",!1)},children:(0,$.jsx)(Yt,{className:"w-3 h-3"})})]}):null,qn&&p.sources?(0,$.jsxs)("div",{className:"group flex shrink-0 items-center",children:[(0,$.jsxs)("button",{type:"button",className:V("flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",Ve?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>x("sources"),children:[(0,$.jsx)(Si,{className:"w-3.5 h-3.5 shrink-0"}),(0,$.jsx)("span",{className:"truncate flex-1",children:"Sources"})]}),(0,$.jsx)("button",{type:"button","aria-label":"Close Sources",className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:Z=>{Z.stopPropagation(),g("sources",!1)},children:(0,$.jsx)(Yt,{className:"w-3 h-3"})})]}):null,p.packages?(0,$.jsxs)("div",{className:"group flex shrink-0 items-center",children:[(0,$.jsxs)("button",{type:"button",className:V("flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",Be?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>x("packages"),children:[(0,$.jsx)(Br,{className:"w-3.5 h-3.5 shrink-0"}),(0,$.jsx)("span",{className:"truncate flex-1",children:"Packages"})]}),(0,$.jsx)("button",{type:"button","aria-label":"Close Packages",className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:Z=>{Z.stopPropagation(),g("packages",!1)},children:(0,$.jsx)(Yt,{className:"w-3 h-3"})})]}):null,p.pending?(0,$.jsxs)("div",{className:"group flex shrink-0 items-center",children:[(0,$.jsxs)("button",{type:"button",className:V("flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",Rt?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>x("pending"),children:[(0,$.jsx)(os,{className:"w-3.5 h-3.5 shrink-0"}),(0,$.jsx)("span",{className:"truncate flex-1",children:"Changes"})]}),(0,$.jsx)("button",{type:"button","aria-label":"Close Changes",className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:Z=>{Z.stopPropagation(),g("pending",!1)},children:(0,$.jsx)(Yt,{className:"w-3 h-3"})})]}):null,b?(0,$.jsxs)("div",{className:"group flex shrink-0 items-center",children:[(0,$.jsxs)("button",{type:"button",className:V("flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",he?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>x("git-diff"),title:`Diff: ${Mi(b.repo,b.path)} (${u1(b)})`,children:[(0,$.jsx)(Cr,{className:"w-3.5 h-3.5 shrink-0 text-violet-300/80"}),(0,$.jsx)("span",{className:"truncate flex-1",children:Mi(b.repo,It(b.path)||b.path)})]}),(0,$.jsx)("button",{type:"button","aria-label":"Close Git diff",className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:Z=>{Z.stopPropagation(),y(null),he&&x("file")},children:(0,$.jsx)(Yt,{className:"w-3 h-3"})})]}):null,C?(0,$.jsxs)("div",{className:"group flex shrink-0 items-center",children:[(0,$.jsxs)("button",{type:"button",className:V("flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",Me?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>x("git-commit"),title:C.kind==="commit"?Mi(C.repo,`Commit ${gn(C.sha)}: ${C.subject}`):Mi(C.repo,`Outgoing changes (${gn(C.base)}..${gn(C.head)})`),children:[C.kind==="commit"?(0,$.jsx)(Kr,{className:"w-3.5 h-3.5 shrink-0 text-violet-300/80"}):(0,$.jsx)(Vr,{className:"w-3.5 h-3.5 shrink-0 text-blue-300/80"}),(0,$.jsx)("span",{className:"truncate flex-1",children:C.kind==="commit"?Mi(C.repo,`${gn(C.sha)} ${C.subject}`):Mi(C.repo,"Outgoing changes")})]}),(0,$.jsx)("button",{type:"button","aria-label":"Close Git commit",className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:Z=>{Z.stopPropagation(),I(null)},children:(0,$.jsx)(Yt,{className:"w-3 h-3"})})]}):null]}),(0,$.jsx)(K1,{})]}):null,xe&&w?(0,$.jsxs)("div",{className:"flex items-center justify-between gap-2 px-2 py-1.5 text-[11px]",style:{backgroundColor:"transparent",borderBottom:!Ye||!fn?"1px solid rgba(255,255,255,0.05)":"none"},children:[(0,$.jsxs)("div",{className:V("min-w-0 flex-1 flex items-center gap-2 rounded-lg px-1.5 py-1 transition",fn?"cursor-pointer hover:bg-white/[0.04]":""),role:fn?"button":void 0,tabIndex:fn?0:void 0,"aria-expanded":fn?Ye:void 0,onClick:Gt,onKeyDown:Z=>{fn&&(Z.key==="Enter"||Z.key===" ")&&(Z.preventDefault(),Gt())},children:[hr?(0,$.jsxs)("span",{className:V("inline-flex shrink-0 items-center gap-1 rounded-full border px-2 py-1 text-[10px]",Tn.pillClassName),children:[(0,$.jsx)(Cr,{className:V("w-3 h-3",Tn.iconClassName)}),(0,$.jsxs)("span",{className:"text-emerald-200/95",children:["+",er.added]}),(0,$.jsx)("span",{className:"text-white/25",children:"/"}),(0,$.jsxs)("span",{className:"text-rose-200/95",children:["-",er.removed]})]}):null,(0,$.jsxs)("div",{className:"min-w-0 flex-1",children:[ye?(0,$.jsx)("input",{value:Q,onChange:Z=>te(Z.target.value),onClick:Z=>Z.stopPropagation(),onKeyDown:Z=>Z.stopPropagation(),className:"h-7 w-full rounded-md bg-white/[0.04] border border-white/[0.12] px-2 text-[11px] font-mono text-white/85 outline-none focus:border-white/[0.2]",disabled:De}):(0,$.jsxs)("div",{className:"min-w-0 flex items-center gap-2",title:`${Ke(w.uri)} \xB7 ${w.uri}`,children:[(0,$.jsx)("span",{className:V("shrink-0 text-white/88 font-medium",w.status==="deleted"?"line-through text-red-200/70":""),children:w.name}),(0,$.jsx)("span",{className:"truncate font-mono text-white/42",children:wr})]}),nt?(0,$.jsx)("div",{className:"text-[10px] text-red-300/80 truncate",title:nt,children:"Read failed"}):null,Qe?(0,$.jsx)("div",{className:"text-[10px] text-red-300/80 truncate",title:Qe,children:Qe}):null]}),fn?(0,$.jsx)(qt,{className:V("w-3.5 h-3.5 shrink-0 text-white/35 transition-transform",Ye&&"rotate-180")}):null]}),(0,$.jsxs)("div",{className:"flex items-center gap-2",children:[ye?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-emerald-500/15 border border-emerald-500/25 p-1.5 text-emerald-100 hover:bg-emerald-500/20 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:Ls,disabled:De||!ve,"aria-label":"Save changes",children:De?(0,$.jsx)($e,{className:"w-3 h-3 animate-spin"}):(0,$.jsx)(Vn,{className:"w-3 h-3"})}),(0,$.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/70 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:Zt,disabled:De,"aria-label":"Cancel edit",children:(0,$.jsx)(Yt,{className:"w-3 h-3"})})]}):(0,$.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/60 hover:text-white/80 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:In,disabled:!ve||At||_,title:_?"Binary files cannot be edited in-place":"Edit in-place","aria-label":"Edit in-place",children:(0,$.jsx)(yi,{className:"w-3 h-3"})}),(0,$.jsx)("button",{type:"button",className:V("inline-flex items-center justify-center rounded-md p-1.5 transition","border border-red-500/15 bg-red-500/10 text-red-300/70 hover:text-red-200 hover:bg-red-500/15","disabled:opacity-40 disabled:cursor-not-allowed"),onClick:_e,disabled:!ve||at||Ue,title:"Mark as deleted","aria-label":"Mark as deleted",children:at?(0,$.jsx)($e,{className:"w-3 h-3 animate-spin"}):(0,$.jsx)(_t,{className:"w-3 h-3"})}),(0,$.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/60 hover:text-white/80 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>{!ve||!w||o({agentId:ve,projectId:h??null,uri:w.uri,readAgentId:We?.id,force:!0})},title:"Reload file","aria-label":"Reload file",children:(0,$.jsx)(Xt,{className:"w-3 h-3"})}),!ye&&ze&&w?.status!=="pending_review"?(0,$.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/60 hover:text-white/80 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:$t,disabled:vt||st||!ve,title:"Undo to previous version","aria-label":"Undo to previous version",children:vt?(0,$.jsx)($e,{className:"w-3 h-3 animate-spin"}):(0,$.jsx)(Oa,{className:"w-3 h-3"})}):null]})]}):null,xe&&w&&Ye&&fn?(0,$.jsx)(Pp,{node:w,hideVersionDiff:!0}):null,xe&&w&&la?(0,$.jsxs)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(56,189,248,0.08) 0%, rgba(56,189,248,0.02) 100%)",borderBottom:"1px solid rgba(56,189,248,0.16)"},children:[(0,$.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-sky-100/85",children:[(0,$.jsx)(ls,{className:"w-3.5 h-3.5 text-sky-300/75"}),(0,$.jsx)("span",{children:"Local draft in progress"})]}),(0,$.jsx)("div",{className:"text-[10px] text-sky-100/55",children:"Save or cancel to resolve the draft state"})]}):null,xe&&w&&Pe&&!ye?(0,$.jsxs)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(251,191,36,0.08) 0%, rgba(244,63,94,0.03) 100%)",borderBottom:"1px solid rgba(251,191,36,0.18)"},children:[(0,$.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-amber-200/80",children:[(0,$.jsx)(Cr,{className:"w-3.5 h-3.5 text-amber-400/70"}),(0,$.jsx)("span",{children:"Pending changes \u2014 review and approve or revert"})]}),(0,$.jsxs)("div",{className:"flex items-center gap-2",children:[(0,$.jsxs)("button",{type:"button",className:V("inline-flex items-center gap-1 rounded-md px-2 py-1 text-[11px] transition",Et?"bg-amber-500/15 border border-amber-500/25 text-amber-100":"bg-white/5 text-white/50 hover:bg-white/10 hover:text-white/70"),onClick:()=>me(!Et),children:[(0,$.jsx)(Cr,{className:"w-3 h-3"}),"Diff"]}),Et?(0,$.jsx)(gd,{}):null,(0,$.jsxs)("button",{type:"button",className:"inline-flex items-center gap-1 rounded-md bg-emerald-500/15 border border-emerald-500/25 px-2 py-1 text-[11px] text-emerald-100 hover:bg-emerald-500/20 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:we,disabled:st||vt||!ve,title:"Accept current state",children:[st?(0,$.jsx)($e,{className:"w-3 h-3 animate-spin"}):(0,$.jsx)(Vn,{className:"w-3 h-3"}),"Approve"]}),(0,$.jsxs)("button",{type:"button",className:"inline-flex items-center gap-1 rounded-md bg-red-500/10 border border-red-500/20 px-2 py-1 text-[11px] text-red-200/80 hover:bg-red-500/15 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:$t,disabled:st||vt||!ve,title:"Revert to previous version",children:[vt?(0,$.jsx)($e,{className:"w-3 h-3 animate-spin"}):(0,$.jsx)(Oa,{className:"w-3 h-3"}),"Revert"]})]})]}):null,xe&&w&&!ye&&w.presence==="stale_indexed"?(0,$.jsxs)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(244,114,182,0.08) 0%, rgba(251,191,36,0.03) 100%)",borderBottom:"1px solid rgba(244,114,182,0.15)"},children:[(0,$.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-rose-100/85",children:[(0,$.jsx)(us,{className:"w-3.5 h-3.5 text-rose-300/75"}),(0,$.jsx)("span",{children:"This indexed node is missing from the live source"})]}),(0,$.jsx)("div",{className:"text-[10px] text-rose-100/55",children:"Useful for spotting sync drift"})]}):null,xe&&w&&!ye&&w.presence==="unindexed"?(0,$.jsx)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(251,191,36,0.07) 0%, rgba(255,255,255,0.02) 100%)",borderBottom:"1px solid rgba(251,191,36,0.15)"},children:(0,$.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-amber-100/82",children:[(0,$.jsx)(gt,{className:"w-3.5 h-3.5 text-amber-300/75"}),(0,$.jsx)("span",{children:"Unindexed \u2014 file exists on the connector but is not yet vector-indexed"})]})}):null,(0,$.jsxs)("div",{ref:Dr,className:"flex-1 min-h-0 relative",children:[bn&&v?(0,$.jsx)("div",{className:"w-full h-full overflow-y-auto",children:(0,$.jsx)(Yg,{agentId:v,projectId:h??null})}):null,qn&&Ve&&v?(0,$.jsx)("div",{className:"w-full h-full overflow-y-auto",children:(0,$.jsx)(vL,{agentId:v,projectId:h??null,isDocker:k.isDocker})}):null,Be&&h?(0,$.jsx)("div",{className:"w-full h-full overflow-y-auto",children:(0,$.jsx)(PL,{projectId:h})}):null,Rt&&v?(0,$.jsx)("div",{className:"w-full h-full min-h-0",children:(0,$.jsx)(a2,{agentId:v,projectId:h??null})}):null,he&&b?(0,$.jsx)("div",{className:"w-full h-full min-h-0",children:(0,$.jsx)(Kg,{target:b,agentId:v,projectId:h??null})}):null,Me&&C?(0,$.jsx)("div",{className:"w-full h-full min-h-0",children:(0,$.jsx)(gp,{target:C,agentId:v,projectId:h??null})}):null,xe&&At?(0,$.jsxs)("div",{className:"absolute inset-x-4 top-4 z-10 rounded-xl border border-red-500/25 bg-black/70 p-3 backdrop-blur-sm",children:[(0,$.jsx)("div",{className:"text-[11px] text-red-200/85 mb-2",children:"This file is marked as deleted."}),(0,$.jsxs)("div",{className:"flex items-center gap-2",children:[(0,$.jsxs)("button",{type:"button",className:"h-8 px-3 rounded-lg text-xs font-semibold border border-emerald-500/30 bg-emerald-500/15 text-emerald-100 hover:bg-emerald-500/20 disabled:opacity-50 disabled:cursor-not-allowed",onClick:D,disabled:!ve||Ue||at,children:[Ue?(0,$.jsx)($e,{className:"w-3 h-3 animate-spin inline mr-1"}):null,"Restore"]}),(0,$.jsxs)("button",{type:"button",className:"h-8 px-3 rounded-lg text-xs font-semibold border border-red-500/30 bg-red-500/15 text-red-100 hover:bg-red-500/20 disabled:opacity-50 disabled:cursor-not-allowed",onClick:_e,disabled:!ve||at||Ue,children:[at?(0,$.jsx)($e,{className:"w-3 h-3 animate-spin inline mr-1"}):null,"Delete"]})]})]}):null,xe&&w?Pe&&Et&&Oe&&!ye?(0,$.jsx)(_g,{oldContent:Oe.content,newContent:N,language:re,viewMode:jn,className:"w-full h-full min-h-0"}):_&&!A&&!F&&!ye?(0,$.jsx)("div",{className:V("w-full h-full min-h-0 flex items-center justify-center px-6 text-center",At&&"blur-[2px] opacity-65"),children:(0,$.jsxs)("div",{className:"max-w-md rounded-2xl border border-white/10 bg-white/[0.035] px-5 py-4 shadow-[0_18px_46px_-26px_rgba(0,0,0,0.65)]",children:[(0,$.jsx)(gt,{className:"w-6 h-6 mx-auto mb-3 text-amber-300/75"}),(0,$.jsxs)("div",{className:"text-sm font-semibold text-white/82",children:[ae," preview disabled"]}),(0,$.jsx)("div",{className:"mt-2 text-xs leading-5 text-white/45",children:"This file is treated as binary, so Neuralis will not decode it into the text editor."})]})}):A&&dr&&!ye?(0,$.jsx)("div",{className:"w-full h-full min-h-0 overflow-auto px-2 py-1.5",children:(0,$.jsxs)("div",{className:V(At&&"blur-[2px] opacity-65"),children:[(0,$.jsx)("div",{className:"text-[11px] text-white/45 mb-3",children:"Image preview"}),(0,$.jsx)("img",{src:dr,alt:w.name,className:"max-w-full max-h-[calc(100vh-220px)] rounded-xl bg-black/20 shadow-[0_18px_46px_-26px_rgba(0,0,0,0.65),inset_0_1px_0_rgba(255,255,255,0.06)]"})]})}):F&&dr&&!ye?(0,$.jsx)("div",{className:"w-full h-full min-h-0 overflow-auto px-2 py-1.5",children:(0,$.jsxs)("div",{className:V(At&&"blur-[2px] opacity-65"),children:[(0,$.jsx)("div",{className:"text-[11px] text-white/45 mb-3",children:"Video preview"}),(0,$.jsx)("video",{src:dr,controls:!0,className:"w-full max-w-[1100px] rounded-xl bg-black/20 shadow-[0_18px_46px_-26px_rgba(0,0,0,0.65),inset_0_1px_0_rgba(255,255,255,0.06)]"})]})}):K&&H&&!se&&!ye?(0,$.jsx)("div",{className:V("w-full h-full min-h-0 overflow-auto px-1 py-1 text-white/80",At&&"blur-[2px] opacity-65"),children:N?(0,$.jsx)("div",{className:"min-h-full min-w-0",children:(0,$.jsx)(H,{content:N})}):(0,$.jsx)("div",{className:"px-2 py-1.5 text-sm text-white/30",children:et})}):(0,$.jsx)($g,{value:ye?ge:N,language:re,readOnly:!ye||At||De,wrap:Le,onChange:ye?de:void 0,className:V("w-full h-full min-h-0",At&&"opacity-65"),placeholder:et,ariaLabel:ye?"File content editor":"File content viewer",gitLineStatus:oa}):xe?(0,$.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center text-white/20",children:[(0,$.jsx)(_l,{className:"w-12 h-12 mb-2 opacity-50"}),(0,$.jsx)("div",{className:"text-sm",children:bn?"Upload files using this tab":"No file open"})]}):null,xe&&w?(0,$.jsxs)("div",{className:"pointer-events-none absolute bottom-2 right-3 z-10 text-[10px] text-white/42",children:[(0,$.jsxs)("span",{children:[E.lineCount.toLocaleString()," lines"]}),(0,$.jsxs)("span",{className:"ml-3",children:[E.charCount.toLocaleString()," chars"]})]}):null]})]})}function JE(t){let e=It(t).toLowerCase();return e.endsWith(".md")||e.endsWith(".mdx")||e.endsWith(".markdown")}function ZE(t){let e=It(String(t||"")).toLowerCase();return e.endsWith(".png")||e.endsWith(".jpg")||e.endsWith(".jpeg")||e.endsWith(".webp")||e.endsWith(".gif")}function QE(t){let e=It(String(t||"")).toLowerCase();return e.endsWith(".mp4")||e.endsWith(".webm")||e.endsWith(".mov")||e.endsWith(".m4v")}function eO(t){let e=It(String(t||"")).toLowerCase();return/\.(wasm|png|jpe?g|gif|webp|ico|bmp|mp4|webm|avi|mov|m4v|mkv|mp3|wav|ogg|flac|aac|zip|tar|gz|bz2|7z|rar|pdf|docx?|xlsx?|pptx?|exe|dll|so|dylib|ttf|otf|woff2?|eot)$/.test(e)}function tO(t){let e=It(String(t||"")).toLowerCase();return e.endsWith(".wasm")?"WebAssembly binary":e.endsWith(".pdf")?"PDF":"Binary file"}function nO(t){let e=It(String(t||"")).toLowerCase();return e.endsWith(".jsonl")||e.endsWith(".ndjson")||e.endsWith(".log")}function rO(t){if(!t)return{charCount:0,lineCount:0};let e=1;for(let n=0;n<t.length;n++)t.charCodeAt(n)===10&&(e+=1);return{charCount:t.length,lineCount:e}}var Cs="brain://project-info",$$=[{kind:"docs",label:"Upload Docs",folderUri:`${Cs}/docs`,accept:".md,.txt,.pdf,.doc,.docx"},{kind:"requirements",label:"Upload Requirements",folderUri:`${Cs}/requirements`,accept:".md,.txt,.pdf"},{kind:"architecture",label:"Upload Architecture",folderUri:`${Cs}/architecture`,accept:".md,.txt,.pdf,.drawio,.json,.yaml,.yml"},{kind:"design",label:"Upload Design",folderUri:`${Cs}/design`,accept:".md,.txt,.pdf,.fig,.png,.jpg,.jpeg,.webp"},{kind:"assets",label:"Upload Assets",folderUri:`${Cs}/assets`,accept:".png,.jpg,.jpeg,.webp,.svg,.gif"},{kind:"datasets",label:"Upload Datasets",folderUri:`${Cs}/datasets`,accept:".csv,.json,.jsonl,.parquet,.txt,.zip"},{kind:"other",label:"Upload File",folderUri:`${Cs}/misc`}];var Cn=W(Je(),1);var o2=250,aO=1e3,sO=2e3,iO=6e3,oO=1e3,lO=5e3,uO=["filesystem:created","filesystem:updated","filesystem:deleted","filesystem:reverted","sync:completed","pending:changed"],cO=new Set(uO),dO=["filesAdded","filesUpdated","filesRemoved","filesMoved","chunksRemoved"];function fO(t){return t.mode==="purge"?!1:dO.every(e=>t[e]===0)}function l2(t,e){let n=mi(),r=B(N=>N.refreshTree),a=B(N=>N.refresh),s=B(N=>N.ensureFolderLoaded),i=B(N=>N.reconcileSourceFolders),o=B(N=>N.reconcileFolders),l=B(N=>N.setSourceDirty),u=B(N=>N.upsertFileNodeFromEvent),c=B(N=>N.incrementFolderBadges),d=B(N=>N.replaceFilePath),f=B(N=>N.clearFilePrev),h=B(N=>N.autoExpandToFile),p=B(N=>N.loadGitStatus),g=B(N=>N.notifyGitLogChanged),m=B(N=>N.refreshPendingCount),x=(0,Cn.useRef)(0),b=(0,Cn.useRef)(new Map),y=(0,Cn.useRef)(new Map),C=(0,Cn.useRef)(new Map);(0,Cn.useEffect)(()=>{let N=b.current,j=C.current;return()=>{for(let K of N.values())clearTimeout(K);N.clear();for(let K of j.values())clearTimeout(K);j.clear()}},[t,e,n]),(0,Cn.useEffect)(()=>{let N=y.current;return()=>{x.current+=1;for(let j of N.values())clearTimeout(j.timer);N.clear()}},[t,e,n]);let I=(0,Cn.useRef)(null),L=(0,Cn.useCallback)(()=>{if(!t||!e)return;let N=Date.now(),j=I.current,K=j?j.deadline:N+lO;j&&clearTimeout(j.timer);let A=setTimeout(()=>{I.current=null,!(typeof document<"u"&&document.visibilityState==="hidden")&&m({agentId:t,projectId:e})},Math.max(0,Math.min(oO,K-N)));I.current={timer:A,deadline:K}},[t,e,m]),v=(0,Cn.useRef)(L);v.current=L;let k=B(N=>N.activeAgentId===t&&N.activeProjectId===e);(0,Cn.useEffect)(()=>{t&&e&&k&&m({agentId:t,projectId:e})},[t,e,k,m]),(0,Cn.useEffect)(()=>{if(!t||!e)return;let N=()=>{document.visibilityState!=="hidden"&&v.current()},j=()=>v.current();return document.addEventListener("visibilitychange",N),window.addEventListener("focus",j),()=>{document.removeEventListener("visibilitychange",N),window.removeEventListener("focus",j),I.current&&clearTimeout(I.current.timer),I.current=null}},[t,e,m]);let O=(0,Cn.useCallback)(N=>{let{type:j,payload:K}=N,A=q=>{if(!t||!q)return;let Q=n.getState().activeSource,te=typeof Q=="string"&&Q?Q.includes("://")?Ke(Q):Q:"",ge=C.current,de=ge.get(q);de&&clearTimeout(de),ge.set(q,setTimeout(()=>{ge.delete(q),n.setState(De=>({sourceChangeRevision:{...De.sourceChangeRevision,[q]:(De.sourceChangeRevision[q]??0)+1}})),te===q&&p({agentId:t,projectId:e,source:q})},o2))},F=q=>{if(!t)return;let Q=y.current,te=Date.now(),ge=Q.get(q),de=ge?ge.deadline:te+iO;ge&&clearTimeout(ge.timer);let De=setTimeout(()=>{Q.delete(q),i({agentId:t,projectId:e,source:q})},Math.max(0,Math.min(sO,de-te)));Q.set(q,{timer:De,deadline:de})};if(j==="sync:completed"){if(!t)return;let q=typeof K.source=="string"?K.source:void 0;if(q&&fO(K)){A(q);return}q?(n.getState().loadedFolders?.[`${q}://`]?F(q):l(q,!0),A(q)):r({agentId:t,projectId:e});return}if(K.changeType==="badge"){if(!t)return;let q=n.getState().activeAgentId;if(q&&q!==t)return;let Q=typeof K.source=="string"&&K.source?K.source:Ke(typeof K.uri=="string"?K.uri:"");if(!Q)return;let te=b.current,ge=te.get(Q);ge&&clearTimeout(ge),te.set(Q,setTimeout(()=>{te.delete(Q),n.setState(Xe=>({sourceChangeRevision:{...Xe.sourceChangeRevision,[Q]:(Xe.sourceChangeRevision[Q]??0)+1}})),s({agentId:t,projectId:e,uri:`${Q}://`,force:!0}),a({agentId:t,projectId:e});let de=n.getState().activeSource;(typeof de=="string"&&de?de.includes("://")?Ke(de):de:"")===Q&&p({agentId:t,projectId:e,source:Q}),g(Q)},o2));return}if(K.external===!0){if(!t)return;let q=n.getState().activeAgentId;if(q&&q!==t)return;let Q=typeof K.source=="string"&&K.source?K.source:Ke(typeof K.uri=="string"?K.uri:"");if(!Q)return;if(A(Q),!n.getState().loadedFolders?.[`${Q}://`]){l(Q,!0);return}F(Q);return}let _=K.uri;if(!_)return;let X=K.changeType,re=Array.isArray(K.folder_ancestors)&&K.folder_ancestors.length>0?K.folder_ancestors:Ra(_);re.length>0&&c(re),Array.isArray(K.new_folder_ancestors)&&K.new_folder_ancestors.length>0&&c(K.new_folder_ancestors);let ae=typeof K.action=="string"?K.action:void 0,Le={id:K.id,uri:_,folder_ancestors:re,sourceAgentId:N.agentId,sourceProjectId:N.projectId},ye=q=>{if(!t)return;let Q=Array.from(new Set(q.filter(te=>typeof te=="string"&&!!te).map(te=>ct(te))));Q.length>0&&o({agentId:t,projectId:e,folders:Q})};switch(j){case"filesystem:created":case"filesystem:updated":u({...Le,status:K.status}),K.status==="pending_review"&&h(_),K.newUri&&(d(_,K.newUri),u({...Le,uri:K.newUri,folder_ancestors:K.new_folder_ancestors,status:K.status})),ae==="review_approved"&&K.status==="active"&&f(_),X==="structure"&&ye([_,K.newUri]);break;case"filesystem:deleted":u({...Le,status:"deleted"}),X==="structure"&&ye([_]);break;case"filesystem:reverted":u({...Le,status:K.status||"active"}),f(_),ye([_]);break}A(Ke(_))},[t,e,n,r,a,s,i,o,l,u,c,d,f,h,p,g]),R=(0,Cn.useRef)(O);R.current=O;let P=(0,Cn.useRef)(null),H=(0,Cn.useCallback)(()=>{if(!t)return;let N=x.current;P.current&&clearTimeout(P.current),P.current=setTimeout(()=>{P.current=null,N===x.current&&(async()=>{try{await a({agentId:t,projectId:e})}catch{return}if(N!==x.current)return;v.current();let j=n.getState();n.setState(A=>({sourceChangeRevision:Object.fromEntries(A.sources.map(F=>[Ke(F.uri_root),(A.sourceChangeRevision[Ke(F.uri_root)]??0)+1]))}));let K=new Set;for(let[A,F]of Object.entries(j.loadedFolders||{})){if(!F)continue;let _=Ke(A);_&&K.add(_)}await Promise.all(Array.from(K).map(A=>i({agentId:t,projectId:e,source:A})))})()},aO)},[t,e,n,a,i]),w=(0,Cn.useRef)(H);w.current=H,(0,Cn.useEffect)(()=>{let N=P;return()=>{N.current&&clearTimeout(N.current)}},[t,e,n]),(0,Cn.useEffect)(()=>{if(!t||!e)return;let N=uv();if(!N?.subscribeFilesystemEvents)return;let j=!0,K=N.subscribeFilesystemEvents(t,e,A=>{if(!j)return;let F=A;if(!F||typeof F!="object"||!cO.has(F.type)||!F.payload||typeof F.payload!="object")return;if(F.type==="pending:changed"){v.current();return}let _=F.payload.changeType==="badge",X=F.payload.external===!0;!_&&!X&&F.agentId!==t||R.current(F)},()=>{j&&w.current()});return()=>{j=!1,K()}},[t,e,n])}var Xf=W(nr(),1);var On=W(ue(),1);function x0(t){let e=B(F=>F.sidebarOpen),n=B(F=>F.sidebarWidth),r=B(F=>F.setSidebarWidth),a=B(F=>F.loadList),s=B(F=>F.refreshTree),i=B(F=>F.applyNav),o=B(F=>F.searchQuery),l=B(F=>F.setSearchQuery),u=B(F=>F.clearSearch),c=B(F=>F.sidebarView),d=B(F=>F.setSidebarView),f=(0,Wn.useRef)(null),h=(0,Wn.useRef)(null),p=(0,Wn.useRef)(null),[g,m]=(0,Wn.useState)(!1),x=Ln(),b=(0,Xf.useWorkspaceHostPort)(),y=B(F=>F.activeProjectId),C=t.projectId??y,I=x.useFileMarks(t.agentId),L=x.useAgents(),v=(0,Wn.useMemo)(()=>qs(L),[L]),k=t.agentId?v.byId.get(t.agentId):null,O=k?.name||k?.slug,R=k?.config?.appearance?.icon,P=Io(k?.id,v),H=(0,Wn.useMemo)(()=>{let F=I||{},_=0;for(let X of Object.keys(F)){let re=F[X]?.ts??0;re>_&&(_=re)}return _},[I]);l2(t.agentId,C),(0,Wn.useEffect)(()=>{t.agentId&&a({agentId:t.agentId,projectId:C,userId:t.userId??null})},[t.agentId,C,t.userId]),(0,Wn.useEffect)(()=>{if(!t.agentId)return;let F=t.state?.nav;if(!F)return;let _=JSON.stringify(F);f.current!==_&&(f.current=_,b&&t.widgetId&&(0,Xf.consumeWidgetNav)(b,{agentId:t.agentId,widgetId:t.widgetId}),i({agentId:t.agentId,projectId:C,nav:F,readAgentId:t.agentId}))},[i,t.agentId,C,t.state,b,t.widgetId]);let w=(0,Wn.useRef)(!1);(0,Wn.useEffect)(()=>{if(!t.agentId||!H||w.current)return;let F=setTimeout(()=>{w.current=!0,s({agentId:t.agentId,projectId:C}).finally(()=>{w.current=!1})},1500);return()=>clearTimeout(F)},[H,C,t.agentId,s]);let N=8,j=(0,Wn.useCallback)(F=>{F.preventDefault(),p.current={startX:F.clientX,startWidth:n},m(!0),F.currentTarget.setPointerCapture(F.pointerId)},[n]),K=(0,Wn.useCallback)(F=>{let _=p.current;if(!_)return;let X=h.current,re=X?Math.max(Ll,X.clientWidth-N):_.startWidth,ae=Math.min(re,Math.max(Ll,_.startWidth+(F.clientX-_.startX)));r(ae)},[r]),A=(0,Wn.useCallback)(F=>{p.current&&(p.current=null,m(!1),F.currentTarget.releasePointerCapture(F.pointerId))},[]);return(0,On.jsxs)("div",{className:"flex flex-col w-full h-full overflow-hidden transition-colors duration-300",children:[(0,On.jsx)(Ch,{agentId:t.agentId,agentName:O,agentIcon:R,agentAccent:P,supportsSources:!0,onOpenProjectFiles:()=>{i({agentId:t.agentId,projectId:C,nav:{kind:"filesystem",action:"list",uri:Cs}})}}),(0,On.jsxs)("div",{ref:h,className:`flex-1 min-h-0 flex flex-row ${g?"select-none cursor-col-resize":""}`,children:[(0,On.jsxs)("div",{className:"h-full flex flex-col min-h-0 shrink-0 overflow-hidden",style:{width:e?n:0,backgroundColor:"transparent",borderRight:e?"1px solid rgba(255,255,255,0.05)":"none"},children:[(0,On.jsxs)("div",{className:"px-2 pt-2 pb-1 flex items-center justify-between",children:[(0,On.jsx)("div",{className:"text-[10px] text-white/40 font-bold uppercase tracking-wider shrink-0",children:c==="git"?"Git Control":c==="search"?"Search":"Explorer"}),c==="search"?(0,On.jsx)("input",{type:"text",value:o,onChange:F=>l(F.target.value),onKeyDown:F=>{F.key==="Escape"&&(u(),d("tree"))},placeholder:"Search\u2026",autoFocus:!0,"aria-label":"Search query",className:"flex-1 min-w-0 mx-2 h-6 bg-transparent border-0 text-xs text-white/85 placeholder:text-white/30 outline-none"}):null,(0,On.jsxs)("div",{className:"flex items-center gap-0.5 shrink-0",children:[(0,On.jsx)("button",{type:"button",onClick:()=>{c==="search"?(u(),d("tree")):d("search")},className:`h-6 w-6 rounded-md inline-flex items-center justify-center transition-colors ${c==="search"?"text-white/85":"text-white/40 hover:text-white/70"}`,title:"Search in explorer","aria-label":"Toggle explorer search","aria-pressed":c==="search",children:(0,On.jsx)(Jl,{className:"w-3.5 h-3.5"})}),(0,On.jsx)("button",{type:"button",onClick:()=>d(c==="git"?"tree":"git"),className:`h-6 w-6 rounded-md inline-flex items-center justify-center transition-colors ${c==="git"?"text-violet-300/90":"text-white/40 hover:text-white/70"}`,title:"Git Control","aria-label":"Toggle Git Control panel","aria-pressed":c==="git",children:(0,On.jsx)(Bn,{className:"w-3.5 h-3.5"})})]})]}),(0,On.jsx)(Sp,{agentId:t.agentId,sidebarView:c})]}),e&&(0,On.jsx)("div",{role:"separator","aria-orientation":"vertical",onPointerDown:j,onPointerMove:K,onPointerUp:A,className:"w-2 shrink-0 cursor-col-resize bg-white/0 hover:bg-white/[0.06] transition relative touch-none",children:(0,On.jsx)("div",{className:"absolute inset-y-6 left-1/2 -translate-x-1/2 w-[2px] rounded-full bg-white/[0.07]"})}),(0,On.jsx)("div",{className:"flex-1 min-w-0 min-h-0",children:(0,On.jsx)(g0,{})})]})]})}var ur=W(Je(),1),Zf=W(fa(),1),wl=W(fa(),1),v2=W(d2(),1);var ro=W(Je(),1);var Yf=W(fa(),1);var Za=W(ue(),1),hO=27,v0=90,pO=17,mO=12,gO=1.4,xO=18,y0=32,f2=new WeakMap;function h2(t,e){let n=f2.get(t);if(n&&n.status===e)return n;let r={status:e};return f2.set(t,r),r}function bO(t,e){let n=h2(t,e);if(n.compact!==void 0)return n.compact;let r=String(e??"").toLowerCase(),a=r==="pending"||r.includes("pending"),s;if(a)s=y0;else{let i=gl(t.input),o=i&&typeof i.action=="string"?i.action:void 0;if(o&&!ml(o))s=y0;else if(ml(o))s=v0;else{let l=0;try{let u=i?fc(i):null;l=u?u.added+u.removed:0}catch{l=0}s=l<=0?y0:Math.min(v0,l*xO)}}return n.compact=s,s}function yO(t,e){let n=h2(t,e);if(n.expanded!==void 0)return n.expanded;let r=gl(t.input)??{},a=0;try{let i=fc(r);a=i?i.added+i.removed:0}catch{a=0}let s=Math.max(v0,mO+Math.ceil(a*gO)*pO);return n.expanded=s,s}function p2(t){let e=t.disclosure===!0?yO(t.tool,t.status):bO(t.tool,t.status);return hO+e}var Jf=(0,ro.memo)(function({uri:e,lineCounts:n,isPending:r,reviewPending:a,isError:s,isInterrupted:i,onUriClick:o,children:l}){let u=(0,ro.useMemo)(()=>r?"pending":i?"interrupted":s?"error":"committed",[r,s,i]),c=a&&u==="committed"?"pending review":u,d=(0,ro.useCallback)(()=>{e&&o&&o(e)},[e,o]),f=(0,ro.useCallback)(()=>(0,Za.jsxs)("div",{className:`px-3 py-1 flex items-center gap-2 min-w-0 ${e&&o?"cursor-pointer hover:bg-white/[0.04] transition":""}`,onClick:d,role:e&&o?"button":void 0,title:e||void 0,children:[(0,Za.jsx)(Da,{className:"w-3 h-3 text-white/40 shrink-0"}),(0,Za.jsx)("span",{className:"flex-1 min-w-0 text-[11px] text-white/60 font-mono truncate",children:e||"file"}),n&&(0,Za.jsxs)("span",{className:"shrink-0 flex items-center gap-1.5 text-[10px] font-mono",children:[n.added>0&&(0,Za.jsxs)("span",{className:"text-emerald-400",children:["+",n.added]}),n.removed>0&&(0,Za.jsxs)("span",{className:"text-red-400",children:["-",n.removed]})]}),(0,Za.jsx)(Yf.ToolStatusIcon,{isPending:r,isError:s,isInterrupted:i,statusLabel:c})]}),[e,o,d,n,r,s,i,c]);return(0,Za.jsx)(Yf.CardShell,{label:e||"file",status:u,defaultMode:"compact",compactHeight:90,renderHeader:f,children:l})});var g2=W(Je(),1);var lt=W(ue(),1),x2=(0,g2.memo)(function({action:e,input:n}){switch(e){case"set_fields":return(0,lt.jsx)(vO,{fields:n.fields});case"move":return(0,lt.jsx)(wO,{uri:yl(n,"uri")||yl(n,"id"),destination:yl(n,"destination")});case"copy":return(0,lt.jsx)(kO,{uri:yl(n,"uri"),destination:yl(n,"destination")});case"create_folder":return(0,lt.jsx)(SO,{uri:yl(n,"uri")});case"delete":return(0,lt.jsx)(CO,{});case"revert":return(0,lt.jsx)(IO,{});default:return(0,lt.jsx)(LO,{action:e,input:n})}});function vO({fields:t}){if(!t||typeof t!="object")return(0,lt.jsx)(m2,{icon:(0,lt.jsx)(yo,{className:"w-3 h-3"}),text:"Updated fields"});let e=[];for(let[n,r]of Object.entries(t))if(r!==void 0)if(n==="tags"&&r&&typeof r=="object"){let a=r,s=[];Array.isArray(a.add)&&a.add.length&&s.push(a.add.map(i=>`+${i}`).join(" ")),Array.isArray(a.remove)&&a.remove.length&&s.push(a.remove.map(i=>`-${i}`).join(" ")),Array.isArray(a.set)&&s.push(a.set.join(", ")),e.push({key:"tags",value:s.join(" ")||"(cleared)"})}else if(n==="metadata"&&r&&typeof r=="object"){let a=Object.entries(r).map(([s,i])=>i===null?`${s}: (removed)`:`${s}: ${String(i)}`).join(", ");e.push({key:"metadata",value:a||"(empty)"})}else e.push({key:n,value:r===null?"(cleared)":String(r)});return(0,lt.jsxs)("div",{className:"px-3 py-2 space-y-0.5",children:[e.map(n=>(0,lt.jsxs)("div",{className:"flex gap-2 text-[11px]",children:[(0,lt.jsxs)("span",{className:"text-white/45 shrink-0",children:[n.key,":"]}),(0,lt.jsx)("span",{className:"text-white/75 break-all",children:n.value})]},n.key)),e.length===0&&(0,lt.jsx)(m2,{icon:(0,lt.jsx)(yo,{className:"w-3 h-3"}),text:"Updated fields"})]})}function wO({uri:t,destination:e}){return(0,lt.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] font-mono",children:[(0,lt.jsx)("span",{className:"text-white/50 truncate",children:t||"?"}),(0,lt.jsx)(xo,{className:"w-3 h-3 text-white/35 shrink-0"}),(0,lt.jsx)("span",{className:"text-white/75 truncate",children:e||"?"})]})}function kO({uri:t,destination:e}){return(0,lt.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] font-mono",children:[(0,lt.jsx)(ga,{className:"w-3 h-3 text-sky-400/60 shrink-0"}),(0,lt.jsx)("span",{className:"text-white/50 truncate",children:t||"?"}),(0,lt.jsx)(xo,{className:"w-3 h-3 text-white/35 shrink-0"}),(0,lt.jsx)("span",{className:"text-white/75 truncate",children:e||"?"})]})}function SO({uri:t}){return(0,lt.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] font-mono",children:[(0,lt.jsx)(Or,{className:"w-3 h-3 text-sky-300/70 shrink-0"}),(0,lt.jsx)("span",{className:"text-white/75 truncate",children:t||"?"})]})}function CO(){return(0,lt.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2",children:[(0,lt.jsx)(_t,{className:"w-3 h-3 text-rose-400/70"}),(0,lt.jsx)("span",{className:"text-[11px] text-rose-300/80",children:"Deleted"})]})}function IO(){return(0,lt.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2",children:[(0,lt.jsx)(wi,{className:"w-3 h-3 text-amber-400/70"}),(0,lt.jsx)("span",{className:"text-[11px] text-white/70",children:"Reverted to previous version"})]})}function LO({action:t,input:e}){let n=Object.entries(e).filter(([r])=>r!=="action"&&r!=="id"&&r!=="uri").slice(0,5).map(([r,a])=>`${r}: ${typeof a=="string"?a.slice(0,60):JSON.stringify(a)?.slice(0,60)??"?"}`).join(", ");return(0,lt.jsxs)("div",{className:"px-3 py-2 text-[11px] text-white/60",children:[(0,lt.jsx)("span",{className:"text-white/45 mr-1",children:t}),n&&(0,lt.jsx)("span",{className:"text-white/50",children:n})]})}function m2({icon:t,text:e}){return(0,lt.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] text-white/60",children:[t,(0,lt.jsx)("span",{children:e})]})}function yl(t,e){let n=t[e];return typeof n=="string"?n:void 0}var Qa=W(ue(),1),AO=200,vl=new Map;function b2(t,e){if(vl.size>=AO){let n=vl.keys().next().value;n!==void 0&&vl.delete(n)}vl.set(t,e)}var PO=8,RO=200,w2=(0,ur.memo)(function({tool:e,status:n,conversationId:r}){let a=(0,wl.useChatHost)(),s=(0,v2.useWorkspaceChatStore)(w=>r?w.conversationsById?.[r]?.agentId:void 0),i=(0,wl.useHasRowIdentity)(),o=(0,wl.useRowDisclosureValue)("card"),u=i&&o!==!0?PO:RO,c=(0,ur.useMemo)(()=>gl(e.input),[e.input]),d=(0,ur.useMemo)(()=>(0,Zf.extractPathsFromToolCall)(e)[0]||(c?y2(c,"uri")||y2(c,"path"):void 0),[e,c]),f=String(n||"").toLowerCase(),h=f==="pending"||f.includes("pending"),p=f==="interrupted",g=!p&&(f==="error"||f.includes("error")||f.includes("fail")),m=c?.action,x=d?pl(d):void 0,b=(0,ur.useMemo)(()=>h0(e.structuredContent),[e.structuredContent]),y=(0,ur.useMemo)(()=>{let w=e.structuredContent,N=w&&typeof w=="object"?String(w.status||"").toLowerCase():"";return N==="pending_review"||N.includes("pending")},[e.structuredContent]),C=(0,ur.useMemo)(()=>b??(c&&!h?fc(c):null),[b,c,h]),I=(0,ur.useMemo)(()=>c?h?[]:NO(m,c):[],[m,c,h]),L=(0,ur.useCallback)(w=>{let N=s||void 0;!N||!w||a.openFilesystemWidget?.(N,w)},[s,a]),v=(0,ur.useMemo)(()=>{if(h)return(0,Zf.previewInput)(e.input,!0)},[h,e.input]),k=!h&&!g&&!!m&&ml(m),[O,R]=(0,ur.useState)(()=>k&&d&&s?vl.get(`${s}|${e.id}`)??null:null);(0,ur.useEffect)(()=>{if(!k||!d||!s){R(null);return}let w=`${s}|${e.id}`,N=vl.get(w);if(N!==void 0){R(N);return}let j=!1,K=()=>{j||(async()=>{try{let X=await oo({agentId:s,files:[d]});if(j)return;let re=co(X)[0],ae=Lc(re?.version?.baseline);if(!ae?.content){b2(w,null);return}let Le=Wf(ae.content,fo(re));b2(w,Le),j||R(Le)}catch{}})()},A=globalThis,F=null,_=null;return typeof A.requestIdleCallback=="function"?F=A.requestIdleCallback(K,{timeout:1500}):_=setTimeout(K,200),()=>{j=!0,F!==null&&A.cancelIdleCallback?.(F),_!==null&&clearTimeout(_)}},[k,d,s,e.id]);let P=O??I,H=O?jf(O):C;return h?(0,Qa.jsx)(Jf,{uri:d,lineCounts:null,isPending:!0,reviewPending:!1,isError:!1,isInterrupted:!1,onUriClick:d?L:void 0,children:(0,Qa.jsx)(MO,{content:v})}):m&&!ml(m)?(0,Qa.jsx)(Jf,{uri:d,lineCounts:null,isPending:!1,reviewPending:y,isError:g,isInterrupted:p,onUriClick:d?L:void 0,children:(0,Qa.jsx)(x2,{action:m,input:c||{}})}):(0,Qa.jsx)(Jf,{uri:d,lineCounts:H,isPending:!1,reviewPending:y,isError:g,isInterrupted:p,onUriClick:d?L:void 0,children:P.length>0?(0,Qa.jsx)(hl,{hunks:P,language:x,maxLines:u}):(0,Qa.jsx)("div",{className:"px-3 py-2 text-[11px] text-white/40 italic",children:g?"Operation failed":"Done"})})});function NO(t,e){if(!t){let n=dc(e);return n?f0(n):[]}if(t==="replace_text"){let n=e.edits;if(Array.isArray(n)&&n.length>0)return DL(n.filter(s=>!!s&&typeof s=="object"&&typeof s.find=="string"));let r=typeof e.find=="string"?e.find:"",a=typeof e.replace=="string"?e.replace:"";return TL(r,a)}if(t==="update"||t==="replace_lines"){let n=dc(e);return n?FL(n):[]}if(t==="append_text"||t==="prepend_text"||t==="insert"){let n=typeof e.text=="string"?e.text:"";return n?EL(n):[]}return[]}function MO({content:t}){return t?(0,Qa.jsx)("pre",{className:"px-3 py-1.5 text-[11px] leading-[18px] whitespace-pre overflow-x-auto overflow-y-clip bg-emerald-500/8 text-white/70 font-mono",children:t}):(0,Qa.jsx)("div",{className:"px-3 py-2 text-[11px] text-white/40 italic",children:"Running..."})}function y2(t,e){let n=t[e];return typeof n=="string"?n:void 0}var es=W(Je(),1);function k2({port:t}){let e=t.useCurrentUser(),n=e?.name,r=e?.email,a=e?.role,s=e?.priority,i=(0,es.useMemo)(()=>n||r?{name:n,email:r}:void 0,[n,r]),o=(0,es.useMemo)(()=>a!==void 0||s!==void 0?{role:a,priority:s}:void 0,[a,s]),l=t.useProjectId(),u=t.useUserId(),c=t.getGrantedFeatures(l,u).join(","),d=(0,es.useMemo)(()=>c.split(",").filter(Boolean),[c]);return(0,es.useMemo)(()=>({currentUser:i,currentRole:o,grantedFeatures:d,useAgents(){let f=t.useAgentIds(),h=t.useAgentsById();return(0,es.useMemo)(()=>{let p={};for(let g of f){let m=h[g];m&&(p[g]={id:m.id,slug:m.slug,name:m.name,config:m.config})}return{ids:f,byId:p}},[f,h])},useFileMarks:f=>t.useFileMarks(f),clearFileMark:f=>t.clearFileMark(f),getStreamUrl(f,h,p){return t.buildEventStreamUrl({packageSlug:"brain-core",agentId:f,projectId:h,types:p})},subscribeFilesystemEvents(f,h,p,g){return t.subscribeRealtime({channel:"filesystem",projectId:h,agentId:f,onEvent:(m,x)=>p(x),...g?{onConnChange:g}:{}})},isDocker:t.isDocker,usePackageIconBySlug(){let f=t.useProjectId(),[h,p]=(0,es.useState)({});return(0,es.useEffect)(()=>{if(!f)return;let g=!1,m=`/api/packages/agent-core/packages/overview?projectId=${encodeURIComponent(f)}`;return fetch(m,{credentials:"include"}).then(x=>x.ok?x.json():null).then(x=>{if(g||!x?.packages)return;let b={};for(let y of x.packages){if(!y.id)continue;let C=(0,Ir.resolveLucideIcon)(y.icon);if(!C)continue;let I=y.id.replace(/^@[^/]+\//,"");b[I]=C,b[y.id]=C}p(b)}).catch(()=>{}),()=>{g=!0}},[f]),h}}),[t,i,o,d])}var C2=W(ue(),1);function S2({port:t,children:e}){let n=k2({port:t});return(0,C2.jsx)(cv,{value:n,children:e})}var Is=W(ue(),1),TO="workspace.provider:@neuralis/brain-core",I2=(0,Is.jsx)("div",{className:"flex h-full items-center justify-center text-xs text-white/30",children:"Loading..."}),L2=!1;function DO(t){let{registry:e,port:n}=t;!L2&&n.onClientStateReset&&(L2=!0,n.onClientStateReset(Gx));function r({children:i}){let o=n.useUserId();return(0,kl.useEffect)(()=>{Ux(o)},[o]),(0,Is.jsx)(S2,{port:n,children:i})}e.register({packageSlug:"@neuralis/brain-core",componentImport:TO,Component:r});function a({agentId:i,widgetId:o,state:l}){let u=n.useProjectId(),c=n.useUserId(),d=zx(o,c,u,i);return d?(0,Is.jsx)(Qf.WorkspaceHostPortProvider,{port:n,children:(0,Is.jsx)(Qf.PackageApiProvider,{slug:"brain-core",projectId:u,agentId:i,userId:c,children:(0,Is.jsx)(jx,{store:d,children:(0,Is.jsx)(x0,{agentId:i,projectId:u,userId:c,widgetId:o,state:l})},`${o}\0${c}\0${u}\0${i}`)})}):I2}let s=kl.default.lazy(()=>Promise.resolve({default:a}));e.register({packageSlug:"@neuralis/brain-core",componentImport:"@neuralis/brain-core/app/filesystem",Component:i=>(0,Is.jsx)(kl.Suspense,{fallback:I2,children:(0,Is.jsx)(s,{...i})})}),(0,A2.registerCardComponent)("filesystem.change",w2,{owner:{kind:"package-direct",packageId:"@neuralis/brain-core"},renderer:"direct",mountPolicy:"virtualized",estimateHeight:p2,composer:OL,matchTools:BL})}export{DO as installFilesystemHostComponents};
|