@krapht/ork 1.0.0-alpha.5 → 1.0.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/{__build_info__-Dl8yTEu-.mjs → __build_info__-CxH89h1r.mjs} +2 -2
  2. package/dist/bin.mjs +28 -28
  3. package/dist/{clean-DYVmLkd4.mjs → clean-BbrkMQQi.mjs} +1 -1
  4. package/dist/{completion-BVx917Yr.mjs → completion-BeS2NCgO.mjs} +5 -5
  5. package/dist/{context-CepHRoj9.mjs → context-CHV6aTs7.mjs} +3 -3
  6. package/dist/{decide-CK_-lI5V.mjs → decide-Cnt7o3ya.mjs} +1 -1
  7. package/dist/{find-DWiDJ5Lc.mjs → find-Dy2H5IvT.mjs} +1 -1
  8. package/dist/{format-yBEAXZhk.mjs → format-OL0E1AjA.mjs} +2 -2
  9. package/dist/{in-a-run-CKFIeMpU.mjs → in-a-run-emTc-kZI.mjs} +1 -1
  10. package/dist/{limits-CwzPe9wZ.mjs → limits-TxTnWxix.mjs} +1 -1
  11. package/dist/{list-BE02pCZ9.mjs → list-P5CfcoWx.mjs} +1 -1
  12. package/dist/{mcp-DMuBbUHU.mjs → mcp-qUwFT9yi.mjs} +6 -6
  13. package/dist/{output-BhYkshYq.mjs → output-CjOPL8W0.mjs} +1 -1
  14. package/dist/{pause-C_Q0W6iX.mjs → pause-CBSAxtTp.mjs} +4 -4
  15. package/dist/{relay-COCvG-0I.mjs → relay-UgK1Cp9a.mjs} +2 -2
  16. package/dist/{remove-RVcX1KqP.mjs → remove-ccycC3vI.mjs} +3 -3
  17. package/dist/{send-OVpRei_5.mjs → send-B39-Xeo7.mjs} +3 -3
  18. package/dist/{src-CxZr4Bp2.mjs → src-5-sCA7cY.mjs} +50 -19
  19. package/dist/{src-HxtJOMRr.mjs → src-8nec4uoe.mjs} +1 -1
  20. package/dist/{src-Do_MhwiV.mjs → src-DG4dyBqm.mjs} +7 -0
  21. package/dist/{src-QEycKJWk.mjs → src-jyCJE1kd.mjs} +7 -7
  22. package/dist/ui/assets/{app-DzI77WV9.js → app-C1DAgdU2.js} +7 -7
  23. package/dist/ui/assets/app-Dt_tjFj6.css +1 -0
  24. package/dist/ui/assets/{index-2G_6XIIv.js → index-BZKXPhht.js} +2 -2
  25. package/dist/ui/index.html +1 -1
  26. package/dist/{ui-Dz_qfUOz.mjs → ui-DmJWLgxL.mjs} +4 -4
  27. package/dist/{usage-BcLUZ1xw.mjs → usage-Bh1lVioA.mjs} +5 -5
  28. package/dist/{watch-Buyn0Mhz.mjs → watch-C_vcsn_g.mjs} +6 -6
  29. package/dist/{workflows-1sntXqSd.mjs → workflows-lpexsAYt.mjs} +3 -3
  30. package/dist/{worktrees-B_Go_A9w.mjs → worktrees-D4bVVKfY.mjs} +10 -4
  31. package/package.json +1 -1
  32. package/dist/ui/assets/app-pTYGrAbI.css +0 -1
@@ -64,12 +64,12 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
64
64
  `).find(e=>e.trim()!==``)??``)}},jI=e=>e===``?0:e.replace(/\n+$/u,``).split(`
65
65
  `).length,MI={markdown:`_markdown_q1zph_9`,inline:`_inline_q1zph_94`,target:`_target_q1zph_103`,link:`_link_q1zph_108`,image:`_image_q1zph_113`,note:`_note_q1zph_117`,written:`_written_q1zph_122`},NI=[`h1`,`h2`,`h3`,`h4`,`h5`,`h6`],PI=(e,t)=>t===1?`Copy code`:`Copy code block ${e} of ${t}`,FI=e=>String(e.position?.start.offset),II=(e,t)=>{let n=0;return e.split(`
66
66
  `).flatMap((e,r)=>{let i=`${t}:${n}`;return n+=e.length+1,r===0?[e]:[(0,G.jsx)(`br`,{},i),e]})},LI=e=>e.map(e=>(0,G.jsx)(V.Fragment,{children:RI(e)},FI(e))),RI=e=>e.type===`text`?II(e.value,FI(e)):e.type===`emphasis`?(0,G.jsx)(`em`,{children:LI(e.children)}):e.type===`strong`?(0,G.jsx)(`strong`,{children:LI(e.children)}):e.type===`delete`||e.type===`linkReference`?LI(e.children):e.type===`inlineCode`?(0,G.jsx)(`code`,{className:MI.inline,children:e.value}):e.type===`break`?(0,G.jsx)(`br`,{}):e.type===`html`?e.value:e.type===`link`?zI(e.url,e.children):e.type===`image`||e.type===`imageReference`?(0,G.jsx)(`span`,{className:MI.image,children:e.alt===void 0||e.alt===null||e.alt===``?`image`:`image: ${e.alt}`}):null,zI=(e,t)=>{if(CI(e))return(0,G.jsxs)(`a`,{className:MI.link,href:e,rel:`noopener noreferrer`,target:`_blank`,children:[LI(t),(0,G.jsx)(zw,{children:` (opens in a new tab)`})]});let n=t.map(e=>DI(e)).join(``);return n===e||n===``?(0,G.jsx)(`code`,{className:MI.target,children:e}):(0,G.jsxs)(G.Fragment,{children:[LI(t),` (`,(0,G.jsx)(`code`,{className:MI.target,children:e}),`)`]})},BI=(e,t,n)=>{let r=FI(e);if(e.type===`paragraph`)return(0,G.jsx)(`p`,{children:LI(e.children)},r);if(e.type===`heading`){let t=NI[Math.min(6,n.startLevel+e.depth-1)-1]??`h6`;return(0,G.jsx)(t,{children:LI(e.children)},r)}if(e.type===`thematicBreak`)return(0,G.jsx)(`hr`,{},r);if(e.type===`blockquote`)return(0,G.jsx)(`blockquote`,{children:HI(e,n)},r);if(e.type===`list`){let t=e.children.map(e=>(0,G.jsx)(`li`,{children:HI(e,n)},FI(e)));return e.ordered===!0?(0,G.jsx)(`ol`,{start:e.start??1,children:t},r):(0,G.jsx)(`ul`,{children:t},r)}return e.type===`definition`?(0,G.jsxs)(`p`,{children:[`[`,e.label??e.identifier,`]:`,` `,(0,G.jsx)(`code`,{className:MI.target,children:e.url})]},r):e.type===`code`?VI(e.value,e.lang,n,r):e.type===`html`?OI.includes(t.type)?VI(e.value,void 0,n,r):(0,G.jsx)(V.Fragment,{children:e.value},r):null},VI=(e,t,n,r)=>(0,G.jsx)(YS,{caption:t??void 0,command:e,label:n.copyLabel(n.next(),n.blocks)},r),HI=(e,t)=>e.children.map(n=>BI(n,e,t)),UI=e=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:MI.note,children:`Could not render this as Markdown: showing the text as written.`}),(0,G.jsx)(`pre`,{className:MI.written,children:e})]}),WI=({text:e,startLevel:t,lead:n=!1,muted:r=!1,copyLabel:i=PI})=>{let a;try{let n=EI(e),r=0;a=HI(n,{startLevel:t,blocks:kI(n),next:()=>++r,copyLabel:i})}catch{a=UI(e)}return(0,G.jsx)(`div`,{className:MI.markdown,"data-lead":n?``:void 0,"data-muted":r?``:void 0,children:a})},GI=e=>{let t=jI(e);return t===1?`1 line`:`${t} lines`},KI=({decision:e,document:t})=>{let[n,r]=(0,V.useState)(!1),i=(0,V.useRef)(null),{id:a,node:o,runId:s}=e;return(0,G.jsxs)(`div`,{className:hN.read,children:[(0,G.jsx)(q,{cli:aN(e),onClick:()=>{r(!0)},variant:`ghost`,children:`Read document`}),(0,G.jsx)(`span`,{className:hN.length,children:GI(t)}),(0,G.jsxs)(bC,{description:`Document for run ${s}. Read-only.`,initialFocus:i,onOpenChange:r,open:n,size:`wide`,title:`\`${o}\` · \`${a}\``,children:[(0,G.jsx)(`div`,{"aria-label":`Document`,className:hN.document,ref:i,role:`region`,tabIndex:0,children:(0,G.jsx)(WI,{copyLabel:iN(`${o} document`),startLevel:3,text:t})}),(0,G.jsx)(xC,{children:(0,G.jsx)(q,{onClick:()=>{r(!1)},children:`Close`})})]})]})},qI={region:`_region_1w5dd_7`,more:`_more_1w5dd_23`},JI=e=>{let t=Number(getComputedStyle(e).lineHeight.replace(`px`,``));return e.scrollHeight>0&&t>0?Math.round(e.scrollHeight/t):null},YI=({source:e,children:t})=>{let n=(0,V.useRef)(null),r=(0,V.useId)(),[i,a]=(0,V.useState)(!1),[o,s]=(0,V.useState)(()=>jI(e)),c=(0,V.useCallback)(()=>{let t=n.current;s((t===null?null:JI(t))??jI(e))},[e]);(0,V.useEffect)(()=>{c();let e=typeof ResizeObserver>`u`?null:new ResizeObserver(c);return n.current!==null&&e?.observe(n.current),()=>{e?.disconnect()}},[c]);let l=o>20;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:qI.region,"data-folded":l&&!i?``:void 0,id:r,onFocus:()=>{a(!0)},ref:n,children:t}),l?(0,G.jsx)(`div`,{className:qI.more,children:(0,G.jsx)(q,{"aria-controls":r,"aria-expanded":i,onClick:()=>{i&&n.current?.closest(`section`)?.scrollIntoView?.({block:`nearest`}),a(!i)},variant:`ghost`,children:i?`Show less`:`Show all (${o} lines)`})}):null]})},XI=({decision:{kind:e,node:t,question:n,context:r},nameId:i})=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{hidden:!0,id:i,children:AI(n)}),(0,G.jsx)(YI,{source:n,children:(0,G.jsx)(WI,{copyLabel:iN(t),lead:!0,startLevel:4,text:n})}),r===void 0?null:e===`permission`?(0,G.jsx)(YS,{caption:oN(r)?`json`:void 0,command:r,label:`Copy command (${t})`}):(0,G.jsx)(YI,{source:r,children:(0,G.jsx)(WI,{copyLabel:iN(t),muted:!0,startLevel:4,text:r})})]}),ZI=e=>e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLButtonElement&&!(`option`in e.dataset),QI=({decision:e,workflow:t,onAnswer:n,onOpenRun:r})=>{let{id:i,runId:a,node:o,document:s,options:c,recommended:l,owner:u}=e,d=(0,V.useId)(),f=(0,V.useId)(),[p,m]=(0,V.useState)(!1),[h,g]=(0,V.useState)(null),[_,v]=(0,V.useState)(``),y=async e=>{if(p)return;m(!0),g(null);let t=await n(i,e.id,_);m(!1),t.ok||g(t.error)};return(0,G.jsxs)(`section`,{"aria-labelledby":`${f} ${d}`,className:hN.card,"data-decision":i,onKeyDown:e=>{if(!(e.target instanceof Node)||!e.currentTarget.contains(e.target)||e.metaKey||e.ctrlKey||e.altKey||ZI(e.target))return;let t=e.target===e.currentTarget,n=e.key===`Enter`&&t?c.find(e=>e.id===l):rN(c,e.key);n!==void 0&&(e.preventDefault(),y(n))},tabIndex:0,children:[(0,G.jsxs)(`div`,{className:hN.from,children:[(0,G.jsxs)(`h3`,{className:hN.fromText,id:f,children:[t===void 0?``:`${t} · `,a,` · `,o,u===void 0?``:`, passed on by ${u}`]}),(0,G.jsx)(q,{onClick:()=>{r(a,o)},variant:`ghost`,children:`Open run`})]}),(0,G.jsx)(XI,{decision:e,nameId:d}),s===void 0?null:(0,G.jsx)(KI,{decision:e,document:s}),(0,G.jsx)(gN,{decision:e,note:_,onChoose:e=>{y(e)},onNote:v,sending:p}),h===null?null:(0,G.jsxs)(`p`,{className:hN.refusal,role:`alert`,children:[`Could not answer: `,(0,G.jsx)(Wg,{text:h})]})]})},$I=({view:e,open:t,onChange:n})=>{let{workflow:r,run:i}=e.active;return(0,G.jsxs)(`div`,{className:hN.filter,children:[(0,G.jsxs)(`div`,{className:hN.filterFields,children:[(0,G.jsx)(Bw,{label:`Workflow`,onChange:e=>{n(e===` all`?{}:{workflow:e})},options:e.workflows,value:r??` all`}),(0,G.jsx)(Bw,{label:`Run`,onChange:e=>{n({...r===void 0?{}:{workflow:r},...e===` all`?{}:{run:e}})},options:e.runs,value:i??` all`})]}),(0,G.jsxs)(`div`,{className:hN.counts,children:[(0,G.jsx)(`output`,{children:fN(t,e.shown.length)}),pN(e.active)?(0,G.jsx)(q,{onClick:()=>{n({})},variant:`ghost`,children:`Clear filter`}):null]})]})},eL=({filter:e,open:t,onClear:n})=>t===0?(0,G.jsx)(CC,{cli:`ork decide`,title:`No decisions waiting.`,children:`Questions from your runs land here. In a terminal:`}):(0,G.jsxs)(CC,{cli:mN(e),title:`No decisions match the filter.`,children:[(0,G.jsxs)(`p`,{children:[t===1?`1 open decision is`:`${t} open decisions are`,` `,`hidden by it. Clear the filter to see `,t===1?`it`:`them`,`.`]}),(0,G.jsx)(q,{onClick:n,variant:`ghost`,children:`Clear filter`})]}),tL=({settled:e})=>e.length===0?null:(0,G.jsxs)(`section`,{"aria-label":`Settled decisions`,className:hN.settled,children:[(0,G.jsx)(`h3`,{className:hN.settledTitle,children:`Settled`}),(0,G.jsx)(`ul`,{className:hN.settledList,children:e.map(e=>(0,G.jsxs)(`li`,{children:[(0,G.jsx)(`span`,{className:hN.settledQuestion,children:e.question}),(0,G.jsxs)(`span`,{className:hN.settledEnding,children:[(0,G.jsx)(`code`,{children:e.runId}),` · `,(0,G.jsx)(`code`,{children:e.node}),`.`,` `,(0,G.jsx)(Wg,{text:tN(e)})]}),nN(e)===void 0?null:(0,G.jsx)(`span`,{className:hN.settledNote,children:nN(e)})]},e.id))})]}),nL=e=>e.tabIndex>=0?e:e.querySelector(`button`),rL=(e,t)=>{let n=(0,V.useRef)(null),r=(0,V.useRef)(null),i=(0,V.useRef)(e),a=(0,V.useRef)(null);return(0,V.useEffect)(()=>{if(e===i.current)return;i.current=e;let a=r.current;if(a===null||document.activeElement!==document.body)return;let o=n.current?.querySelectorAll(t),s=o?.[Math.min(a,(o.length||1)-1)];((s===void 0?null:nL(s))??n.current)?.focus()},[e,t]),(0,V.useEffect)(()=>{let e=a.current;e instanceof Node&&!e.isConnected&&(a.current=null,document.activeElement===document.body&&n.current?.focus())}),{panel:n,onFocus:e=>{let{target:n,currentTarget:i}=e;a.current=n;let o=n instanceof Element?n.closest(t):null;r.current=o===null?null:[...i.querySelectorAll(t)].indexOf(o)}}},iL=()=>{let e=qy(),t=(0,V.use)(ZM),n=ab(e.decisions),r=ab(e.settledDecisions),i=ab(e.runs),a=(0,V.useRef)(r[0]?.id),{value:o,update:s}=e.preferences,c=ab(o).decisionFilter,l=(0,V.useMemo)(()=>n??[],[n]),u=(0,V.useCallback)(e=>i?.find(({id:t})=>t===e)?.workflow,[i]),d=n!==null&&i!==null,[f,p]=(0,V.useState)(!1),m=dN(l,!d||f?c:lN(l,c,u),u),h=new Set(l.map(({runId:e})=>e)).size>1,{panel:g,onFocus:_}=rL(m.shown.map(({id:e})=>e).join(`
67
- `),`[data-decision]`),v=e=>{s({decisionFilter:e})};return(0,V.useEffect)(()=>{if(f||!d)return;let e=lN(l,c,u);(e.workflow!==c.workflow||e.run!==c.run)&&s({decisionFilter:e}),p(!0)},[d,f,l,c,s,u]),(0,V.useEffect)(()=>{let e=r[0];e!==void 0&&e.id!==a.current&&(a.current=e.id,t?.announce(`${e.question} ${tN(e)}`))},[r,t]),(0,G.jsxs)(`div`,{"aria-label":`Decisions`,className:hN.panel,onFocus:_,ref:g,role:`group`,tabIndex:-1,children:[pN(m.active)||h?(0,G.jsx)($I,{onChange:v,open:l.length,view:m}):null,m.shown.length===0?(0,G.jsx)(eL,{filter:m.active,onClear:()=>{v({})},open:l.length}):(0,G.jsx)(`div`,{className:hN.list,children:m.shown.map(t=>(0,G.jsx)(QI,{decision:t,onAnswer:e.answerDecision,onOpenRun:(t,n)=>{e.selectRun(t),e.selectNode(n)},workflow:u(t.runId)},t.id))}),(0,G.jsx)(tL,{settled:r})]})},aL={panel:`_panel_1h85d_8`,tools:`_tools_1h85d_24`,main:`_main_1h85d_39`,status:`_status_1h85d_52`,counts:`_counts_1h85d_65`,error:`_error_1h85d_82`,list:`_list_1h85d_91`,item:`_item_1h85d_106`,row:`_row_1h85d_113`,time:`_time_1h85d_152`,type:`_type_1h85d_153`,node:`_node_1h85d_159`,line:`_line_1h85d_161`,detail:`_detail_1h85d_186`},oL=e=>e.map(e=>({value:e,label:e})),sL=({events:e,node:t,type:n,text:r,onNode:i,onType:a,onText:o})=>(0,G.jsxs)(`div`,{className:aL.tools,children:[(0,G.jsx)(KS,{empty:`No node matches.`,label:`Node`,onChange:i,options:oL(BM(e,t)),placeholder:`All nodes`,value:t}),(0,G.jsx)(KS,{empty:`No event type matches.`,label:`Event`,onChange:a,options:oL(VM(e)),placeholder:`All events`,value:n}),(0,G.jsx)(Uw,{label:`Text`,onChange:o,value:r})]}),cL=(0,V.memo)(({stored:e,open:t,tabbable:n,onToggle:r})=>{let{seq:i,at:a,event:o}=e;return(0,G.jsxs)(`li`,{className:aL.item,children:[(0,G.jsxs)(`button`,{"aria-expanded":t,className:aL.row,"data-log-row":i,onClick:()=>{r(i)},tabIndex:n?0:-1,type:`button`,children:[(0,G.jsx)(`span`,{className:aL.time,children:WM(a)}),(0,G.jsx)(`span`,{className:aL.node,children:kM(o)??`run`}),(0,G.jsx)(`span`,{className:aL.type,children:o.type}),(0,G.jsx)(`span`,{className:aL.line,children:FM(o)})]}),t?(0,G.jsx)(`pre`,{"aria-label":`Event ${String(i)} in full`,className:aL.detail,role:`group`,tabIndex:0,children:JSON.stringify(o,null,2)}):null]})});cL.displayName=`LogRow`;var lL=({shown:e,listRef:t,onScroll:n,label:r,reading:i})=>{let[a,o]=(0,V.useState)(new Set),[s,c]=(0,V.useState)(null),l=e.some(({seq:e})=>e===s)?s:e.at(-1)?.seq??null,u=(0,V.useCallback)(e=>{c(e),o(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n})},[]);return e.length===0?(0,G.jsx)(CC,{title:i?`Reading the run…`:`No event matches.`,children:`Only loaded events are filtered. Load older ones to look further.`}):(0,G.jsx)(`ol`,{"aria-label":r,className:aL.list,onKeyDown:e=>{let t=[...e.currentTarget.querySelectorAll(`[data-log-row]`)],n=t.findIndex(t=>t===e.target);if(n===-1)return;let r={ArrowDown:t[n+1],ArrowUp:t[n-1],Home:t[0],End:t.at(-1)};if(!(e.key in r))return;e.preventDefault();let i=r[e.key];i!==void 0&&(c(Number(i.dataset.logRow)),i.focus())},onScroll:n,ref:t,children:e.map(e=>(0,G.jsx)(cL,{onToggle:u,open:a.has(e.seq),stored:e,tabbable:e.seq===l},e.seq))})},uL=2e3,dL={events:[],latest:0,following:!0},fL=e=>e.events[0]?.seq??1,pL=e=>e.events.at(-1)?.seq??0,mL=e=>fL(e)>1,hL=e=>pL(e)<e.latest,gL=e=>e.slice(-2e3),_L=(e,t)=>Math.max(e.latest,t.at(-1)?.seq??0),vL=(e,t)=>{let n=pL(e);return t.filter(e=>e.seq>n)},yL=(e,t)=>{let n=_L(e,t);return e.following&&!hL(e)?{...e,latest:n,events:gL([...e.events,...vL(e,t)])}:{...e,latest:n}},bL=(e,t)=>({events:gL(t),latest:_L(e,t),following:!0}),xL=(e,t)=>({...e,latest:_L(e,t),events:gL([...e.events,...vL(e,t)])}),SL=(e,t)=>{let n=fL(e),r=[...t.filter(e=>e.seq<n),...e.events].slice(0,uL),i={...e,events:r};return{...i,following:e.following&&!hL(i)}},CL=e=>{let t=fL(e)-1,n=Math.max(0,t-500);return{after:n,limit:t-n}},wL=({events:e,shown:t,feed:n,cli:r})=>{let i=e.events.length,a=e.latest-pL(e);return(0,G.jsxs)(`div`,{className:aL.status,children:[(0,G.jsx)(`span`,{className:aL.counts,children:HM(t,i,e.latest)}),(0,G.jsx)(q,{disabled:!mL(e)||e.paging,focusableWhenDisabled:!0,onClick:()=>{n.loadOlder()},variant:`ghost`,children:`Load older`}),(0,G.jsxs)(q,{"aria-pressed":e.following,cli:r,onClick:()=>{e.following?n.hold():n.follow()},variant:`ghost`,children:[e.following?(0,G.jsx)(Yv,{}):null,`Follow`,a>0?` (${String(a)} new)`:``]})]})},TL=({error:e})=>(0,G.jsx)(`p`,{className:aL.error,role:`alert`,children:(0,G.jsx)(Wg,{text:e})}),EL=32,DL=e=>e.scrollHeight-e.scrollTop-e.clientHeight<EL,OL=(e,t)=>{let n=(0,V.useRef)(null),{following:r}=t,i=t.events[0]?.seq,a=(0,V.useRef)({firstSeq:i,height:0});return(0,V.useLayoutEffect)(()=>{let e=n.current;e!==null&&(r?e.scrollTop=e.scrollHeight:a.current.firstSeq!==i&&a.current.height>0&&(e.scrollTop+=e.scrollHeight-a.current.height),a.current={firstSeq:i,height:e.scrollHeight})}),(0,V.useEffect)(()=>{let t=n.current,r=new ResizeObserver(()=>{t!==null&&e.state.getValue().following&&(t.scrollTop=t.scrollHeight)});return t!==null&&r.observe(t),()=>{r.disconnect()}}),{listRef:n,onScroll:()=>{let t=n.current;if(t===null)return;let r=DL(t),i=e.state.getValue();i.following&&!r?e.hold():!i.following&&r&&!hL(i)&&e.follow()}}},kL=500,AL=({runId:e,node:t})=>{let n=qy(),r=(0,V.useMemo)(()=>n.feedOf(e),[n,e]);(0,V.useEffect)(()=>n.retainRun(e),[n,e]);let i=ab(r.state),[a,o]=(0,V.useState)(null),[s,c]=(0,V.useState)(``),l=(0,V.useMemo)(()=>RM(i.events,{node:t,type:a,text:s}),[i.events,t,a,s]),{listRef:u,onScroll:d}=OL(r,i),f=(0,V.use)(ZM),p=JSON.stringify([t,a,s]),m=(0,V.useRef)(p),h=HM(l.length,i.events.length,i.latest);return(0,V.useEffect)(()=>{let e=setTimeout(()=>{p!==m.current&&(m.current=p,f?.announce(h))},kL);return()=>{clearTimeout(e)}},[p,h,f]),(0,G.jsxs)(`div`,{className:aL.panel,children:[(0,G.jsx)(sL,{events:i.events,node:t,onNode:n.selectNode,onText:c,onType:o,text:s,type:a}),(0,G.jsxs)(`div`,{className:aL.main,children:[(0,G.jsx)(wL,{cli:UM(e,t),events:i,feed:r,shown:l.length}),i.error===null?null:(0,G.jsx)(TL,{error:i.error}),(0,G.jsx)(lL,{label:`Events of run ${e}`,listRef:u,onScroll:d,reading:i.link===`loading`&&i.events.length===0,shown:l})]})]})},jL=()=>{let{run:e,node:t}=ab(qy().selection);return e===null?(0,G.jsx)(CC,{cli:`ork logs <run>`,title:`No run chosen.`,children:`Choose one in the Runs panel, or in a terminal:`}):(0,G.jsx)(AL,{node:t,runId:e},e)},ML=(e,t=new Set)=>{let n=(e,r,i)=>e.flatMap(e=>[{node:e,depth:r,parent:i},...t.has(e.id)?[]:n(e.children,r+1,e.id)]);return n(e,1)},NL={waiting:`queued`,running:`running`,ok:`succeeded`,failed:`failed`,skipped:`skipped`},PL={waiting:`skipped`,running:`interrupted`},FL=(e,t,n=!1)=>{let r=n?PL[e.state]:void 0;return r===void 0?e.held===!0?`paused`:t?`waiting`:NL[e.state]:r},IL=(e,t)=>new Set((e??[]).filter(e=>e.runId===t).map(e=>e.node)),LL=(e,t,n,r=!1)=>new Map(ML(e).map(({node:e})=>{let i=e.inputTokens+e.outputTokens;return[e.id,{status:FL(e,t.has(e.id),r),model:e.model,tokens:i===0?void 0:i,costUsd:e.costUsd===0?void 0:e.costUsd,cli:`ork logs ${n} --node ${e.id}`}]})),RL=(e,t)=>({run:e,nodes:new Map([...t].map(([e,{status:t}])=>[e,t]))}),zL=new Set([`failed`,`paused`]),BL=(e,t,n)=>[...n.run===t.run||n.run!==`running`?[]:[`Run ${e} ${_D(n.run)}.`],...[...n.nodes].filter(([e,r])=>r!==t.nodes.get(e)&&zL.has(r)&&(r!==`paused`||n.run!==`paused`)).map(([e,t])=>`${e} ${_D(t)}.`)],VL=({live:e},t)=>e===`running`&&t?`waiting`:e,HL=(e,t)=>{let n=new Set(e.nodes.map(e=>e.id)),r=ML(t).map(({node:e})=>e).filter(e=>!n.has(e.id)).map(({id:e,type:t,parent:n})=>({id:e,type:t,parent:n}));return{...e,nodes:[...e.nodes,...r]}},UL={enabled:!0},WL=e=>({enabled:!1,why:e}),GL=({live:e})=>e===`running`||e===`paused`,KL=e=>e.id.startsWith(`node-`)?WL(`it ran one node; run that node again instead`):UL,qL=e=>{if(!GL(e)){let t=`the run has ended (${e.live})`,n={pause:WL(t),proceed:WL(t),stop:WL(t)};return e.live===`succeeded`?n:{...n,resume:KL(e)}}let t=e.live===`paused`;return{pause:t?WL(`the run is paused`):UL,proceed:t?UL:WL(`the run is not paused`),stop:UL}},JL=(e,t)=>{if(!GL(e)){let t=`the run has ended (${e.live})`;return{pause:WL(t),proceed:WL(t),stop:WL(t)}}if(t.state!==`running`&&t.state!==`waiting`){let e=`${t.id} has finished`;return{pause:WL(e),proceed:WL(e),stop:WL(e)}}let n=t.held===!0||e.paused.nodes.includes(t.id),r=t.state===`running`?UL:WL(`${t.id} is not running`);if(e.live===`paused`){let e=`the whole run is paused; continue the run`;return{pause:WL(e),proceed:WL(e),stop:r}}return{pause:n?WL(`${t.id} is paused`):UL,proceed:n?UL:WL(`${t.id} is not paused`),stop:r}},YL=e=>e.state===`waiting`||e.state===`skipped`?WL(`it hasn't run`):UL,XL={reason:`_reason_sb9l9_7`},J={panel:`_panel_150du_9`,tools:`_tools_150du_28`,card:`_card_150du_29`,body:`_body_150du_58`,toolsEnd:`_toolsEnd_150du_74`,count:`_count_150du_85`,updating:`_updating_150du_86`,list:`_list_150du_96`,row:`_row_150du_107`,rowTop:`_rowTop_150du_148`,rowTitle:`_rowTitle_150du_158`,rowMeta:`_rowMeta_150du_172`,high:`_high_150du_189`,detail:`_detail_150du_197`,head:`_head_150du_206`,title:`_title_150du_215`,facts:`_facts_150du_228`,fact:`_fact_150du_228`,factName:`_factName_150du_245`,caption:`_caption_150du_246`,factValue:`_factValue_150du_263`,actions:`_actions_150du_278`,line:`_line_150du_279`,note:`_note_150du_288`,message:`_message_150du_289`,lineIcon:`_lineIcon_150du_299`,alert:`_alert_150du_308`,section:`_section_150du_326`,records:`_records_150du_339`,record:`_record_150du_339`,recordMeta:`_recordMeta_150du_362`,recordTitle:`_recordTitle_150du_380`,recordBody:`_recordBody_150du_390`,evidence:`_evidence_150du_399`,form:`_form_150du_409`,pair:`_pair_150du_417`,place:`_place_150du_425`,wellHead:`_wellHead_150du_435`,wellCopy:`_wellCopy_150du_444`,preview:`_preview_150du_452`,link:`_link_150du_499`,result:`_result_150du_510`,dialogFoot:`_dialogFoot_150du_519`},ZL=`Meta+Enter Control+Enter`,QL=({onSend:e,children:t})=>(0,G.jsx)(`form`,{className:J.form,onKeyDown:t=>{t.key===`Enter`&&(t.metaKey||t.ctrlKey)&&(t.preventDefault(),e())},onSubmit:t=>{t.preventDefault(),e()},children:t}),$L=({why:e,id:t})=>(0,G.jsx)(`output`,{className:XL.reason,id:t,children:(0,G.jsx)(Wg,{text:e??``})}),eR=({text:e})=>e===null?null:(0,G.jsx)(`p`,{className:J.alert,role:`alert`,children:(0,G.jsx)(Wg,{text:e})}),tR=[`friction`,`bug`,`context-gap`,`skill`,`workflow`,`idea`],nR=[`low`,`medium`,`high`],rR=[{value:``,label:`No rating`},{value:`good`,label:`good`},{value:`bad`,label:`bad`}],iR={text:``,rating:``,kind:`friction`,severity:null},aR=({rating:e,severity:t})=>t??(e===`bad`?`high`:`medium`),oR=e=>e.severity===null&&e.rating===`bad`,sR=e=>e.text.trim()===``?`Write the note first.`:null,cR=(e,t)=>({text:t.text,...e===void 0?{}:{node:e},kind:t.kind,severity:aR(t),...t.rating===``?{}:{rating:t.rating}}),lR=(e,t,n)=>{let r=aR({...n,severity:null}),i=aR(n);return[`ork feedback note`,e,...t===void 0?[]:[sT(t)],`-m`,n.text.trim()===``?`<text>`:sT(n.text),...n.kind===`friction`?[]:[`--kind ${n.kind}`],...i===r?[]:[`--severity ${i}`],...n.rating===``?[]:[`--rating ${n.rating}`]].join(` `)},uR=(e,t,n)=>({title:t===void 0?`Noted on run \`${e}\``:`Noted on \`${t}\``,description:`It joined item \`${n.slice(0,12)}\`.`}),dR=e=>e.map(e=>({value:e,label:e})),fR=({runId:e,node:t,onSend:n,onDone:r})=>{let[i,a]=(0,V.useState)(iR),[o,s]=(0,V.useState)(!1),[c,l]=(0,V.useState)(null),u=(0,V.useId)(),d=(0,V.useId)(),f=sR(i),p=e=>{a(t=>({...t,...e}))},m=async()=>{if(f!==null||o)return;s(!0),l(null);let e=await n(cR(t,i));s(!1),l(e),e===null&&r()};return(0,G.jsxs)(QL,{onSend:()=>{m()},children:[(0,G.jsx)(Uw,{description:`Its first line is the title.`,label:`Note`,multiline:!0,onChange:e=>{p({text:e})},required:!0,value:i.text}),(0,G.jsx)(Bw,{label:`Rating`,onChange:e=>{p({rating:e})},options:rR,value:i.rating}),(0,G.jsx)(Bw,{label:`Kind`,onChange:e=>{p({kind:e})},options:dR(tR),value:i.kind}),(0,G.jsx)(Bw,{label:`Severity`,onChange:e=>{p({severity:e})},describedBy:d,options:dR(nR),value:aR(i)}),(0,G.jsx)($L,{id:d,why:oR(i)?`Severity: high, from the bad rating.`:null}),(0,G.jsx)(YS,{command:lR(e,t,i)}),(0,G.jsx)($L,{id:u,why:f}),(0,G.jsx)(eR,{text:c}),(0,G.jsxs)(xC,{children:[(0,G.jsx)(q,{disabled:o,onClick:r,type:`button`,variant:`ghost`,children:`Cancel`}),(0,G.jsx)(q,{"aria-describedby":u,"aria-keyshortcuts":ZL,disabled:f!==null||o,focusableWhenDisabled:!0,type:`submit`,variant:`primary`,children:o?`Adding…`:`Add note`})]})]})},pR={enabled:!0},mR=({runId:e,node:t,check:n=pR,onSend:r})=>{let[i,a]=(0,V.useState)(!1),o=t??`run ${e}`,s=n.enabled?`Note on ${o}`:`Note on ${o}: ${n.why}`,c=`ork feedback note ${e}${t===void 0?``:` ${t}`} -m <text>`,l=()=>{a(!0)};return(0,G.jsxs)(G.Fragment,{children:[t===void 0?(0,G.jsx)(cb,{cli:c,label:s,onClick:l,children:(0,G.jsx)(xy,{})}):(0,G.jsxs)(q,{"aria-label":s,cli:c,disabled:!n.enabled,focusableWhenDisabled:!0,onClick:l,tip:n.enabled?void 0:s,children:[(0,G.jsx)(xy,{}),`Note…`]}),(0,G.jsx)(bC,{description:`It joins run ${e}'s feedback as yours, and groups into an item like any record.`,onOpenChange:a,open:i,title:t===void 0?`Note on run \`${e}\``:`Note on \`${t}\``,children:(0,G.jsx)(fR,{node:t,onDone:()=>{a(!1)},onSend:r,runId:e})})]})},hR={monitor:`_monitor_1rkzd_8`,header:`_header_1rkzd_25`,stats:`_stats_1rkzd_43`,stat:`_stat_1rkzd_43`,statName:`_statName_1rkzd_58`,statValue:`_statValue_1rkzd_74`,title:`_title_1rkzd_90`,runId:`_runId_1rkzd_101`,controls:`_controls_1rkzd_111`,error:`_error_1rkzd_119`,canvas:`_canvas_1rkzd_133`,table:`_table_1rkzd_144`,tableHead:`_tableHead_1rkzd_162`,tree:`_tree_1rkzd_185`,treeRow:`_treeRow_1rkzd_190`,treeNode:`_treeNode_1rkzd_233`,treeToggle:`_treeToggle_1rkzd_239`,treeId:`_treeId_1rkzd_259`,treeType:`_treeType_1rkzd_269`,treeStatus:`_treeStatus_1rkzd_285`,treeNow:`_treeNow_1rkzd_291`,treeTime:`_treeTime_1rkzd_301`,treeCost:`_treeCost_1rkzd_314`,sideTitle:`_sideTitle_1rkzd_337`,node:`_node_1rkzd_346`,nodeFacts:`_nodeFacts_1rkzd_362`,watching:`_watching_1rkzd_363`,links:`_links_1rkzd_415`,linkList:`_linkList_1rkzd_430`,link:`_link_1rkzd_415`,linkEnds:`_linkEnds_1rkzd_450`,linkCount:`_linkCount_1rkzd_461`},gR={enabled:!0},_R=(e,t,n)=>n.enabled?`${e} ${t}`:`${e} ${t}: ${n.why}`,vR=`It goes on in the background with the inputs and flags it started with. Nodes that finished keep their results and don't run again; the one that failed or was cut off runs again, and so does everything after it. It's a paid run, like any you start.`,yR=({runId:e,action:t})=>{let n=qy(),[r,i]=(0,V.useState)(!1),a=(0,V.useRef)(!1),o=`ork resume ${e} --detach`;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(q,{"aria-label":_R(`Resume`,`run`,t),cli:o,disabled:!t.enabled,focusableWhenDisabled:!0,onClick:()=>{i(!0)},tip:t.enabled?void 0:t.why,variant:`ghost`,children:[(0,G.jsx)(By,{}),`Resume…`]}),(0,G.jsx)(SC,{cli:o,confirm:`Resume run`,description:vR,finalFocus:()=>{let t=a.current;return a.current=!1,(t?document.querySelector(`[data-run-heading="${e}"]`):null)??!0},onConfirm:async()=>{let t=await n.client.call(`resume`,{params:{id:e},body:{}});return a.current=t.ok,t.ok?null:`Could not resume the run: ${t.error}`},onOpenChange:i,open:r,pending:`Resuming…`,title:`Resume run ${e}?`,variant:`primary`})]})},bR=({runId:e,node:t,actions:n,note:r=gR})=>{let i=qy(),[a,o]=(0,V.useState)(!1),s=t??`run`,c=t===void 0?``:` --node ${t}`,l=n=>{i.control(n,e,t).then(e=>(e.ok||Hy.add({title:`Could not ${n} ${s}`,description:e.error}),e))},u=(0,G.jsx)(mR,{check:r,node:t,onSend:async n=>{let r=await i.client.call(`note`,{params:{id:e},body:n});return r.ok?(Hy.add(uR(e,t,r.data.item)),null):`Could not add the note: ${r.error}`},runId:e});return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{"aria-label":t===void 0?`Run controls`:`Controls for ${t}`,className:hR.controls,role:`group`,children:[(0,G.jsx)(cb,{cli:`ork pause ${e}${c}`,disabled:!n.pause.enabled,focusableWhenDisabled:!0,label:_R(`Pause`,s,n.pause),onClick:()=>{l(`pause`)},children:(0,G.jsx)(Kv,{})}),(0,G.jsx)(cb,{cli:`ork continue ${e}${c}`,disabled:!n.proceed.enabled,focusableWhenDisabled:!0,label:_R(`Continue`,s,n.proceed),onClick:()=>{l(`continue`)},children:(0,G.jsx)(Gv,{})}),(0,G.jsx)(cb,{cli:`ork stop ${e}${c}`,disabled:!n.stop.enabled,focusableWhenDisabled:!0,label:_R(`Stop`,s,n.stop),onClick:()=>{o(!0)},children:(0,G.jsx)(qv,{})}),(0,G.jsx)(SC,{cli:`ork stop ${e}${c}`,confirm:t===void 0?`Stop run`:`Stop ${t}`,description:t===void 0?`Running nodes are interrupted, and runs it called stop too. It can be resumed later, from here or a terminal.`:`Its session is interrupted and \`${t}\` fails with \`stopped by the user\`. The workflow's failure rules then apply.`,onConfirm:()=>{o(!1),l(`stop`)},onOpenChange:o,open:a,title:t===void 0?`Stop run ${e}?`:`Stop ${t}?`}),n.resume===void 0?null:(0,G.jsx)(yR,{action:n.resume,runId:e}),t===void 0?u:null]}),t===void 0?null:u]})},xR={s:1e3,m:6e4,h:36e5},SR=e=>{let t=/^(\d+)([smh])$/u.exec(e);return Number(t?.[1]??0)*(xR[t?.[2]??`s`]??1e3)},CR=e=>{let t=Math.ceil(e/1e3);if(t<60)return`${String(t)} s`;let n=Math.ceil(t/60);return n<60?`${String(n)} min`:`${String(Math.ceil(n/60))} h`},wR=e=>e===`running`||e===`paused`,TR=(e,t)=>{let n=SR(e.every),r=Math.max(0,t-Date.parse(e.at)),i=n===0?0:Math.floor(r/n),a=e.looks+i;return{until:e.until,every:`every ${e.every}`,looks:`${i===0?``:`about `}${String(a)}`,next:`in about ${CR(n===0?0:n-r%n)}`,said:e.said}},ER=5e3,DR=({watching:e})=>{let[t,n]=(0,V.useState)(Date.now);(0,V.useEffect)(()=>{let e=setInterval(()=>{n(Date.now())},ER);return()=>{clearInterval(e)}},[]);let r=TR(e,t);return(0,G.jsxs)(`dl`,{className:hR.watching,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Waiting until`}),(0,G.jsx)(`dd`,{children:(0,G.jsx)(`code`,{children:r.until})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Looks`}),(0,G.jsxs)(`dd`,{children:[r.looks,`, `,r.every]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Next look`}),(0,G.jsx)(`dd`,{children:r.next})]}),r.said===void 0?null:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Last said`}),(0,G.jsx)(`dd`,{children:(0,G.jsx)(`code`,{children:r.said})})]})]})},OR=({run:e,node:t,sectionRef:n,onLeave:r,onOpenRun:i})=>{let{calledRun:a}=t;return(0,G.jsxs)(`section`,{"aria-label":`Node ${t.id}`,className:hR.node,onKeyDown:e=>{let t=document.querySelector(`[data-modal]`)!==null;e.key===`Escape`&&!t&&r()},ref:n,children:[(0,G.jsx)(`h3`,{className:hR.sideTitle,children:t.id}),(0,G.jsxs)(`dl`,{className:hR.nodeFacts,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Type`}),(0,G.jsx)(`dd`,{children:ED(t.type)})]}),t.model===void 0?null:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Model`}),(0,G.jsx)(`dd`,{children:t.model})]}),t.inputTokens+t.outputTokens===0?null:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Tokens`}),(0,G.jsxs)(`dd`,{children:[kD(t.inputTokens),` in ·`,` `,kD(t.outputTokens),` out`]})]})]}),(0,G.jsx)(bR,{actions:JL(e,t),node:t.id,note:YL(t),runId:e.id}),t.watching===void 0||!wR(e.status)?null:(0,G.jsx)(DR,{watching:t.watching}),a===void 0?null:(0,G.jsxs)(q,{onClick:()=>{i(a)},variant:`ghost`,children:[`Open run `,a]})]})},kR=({error:e})=>(0,G.jsx)(`p`,{className:hR.error,role:`alert`,children:(0,G.jsx)(Wg,{text:e})}),AR=new Set([`succeeded`,`failed`,`skipped`,`interrupted`]),jR=e=>e.length<2?e.join(``):`${e.slice(0,-1).join(`, `)} and ${e.at(-1)??``}`,MR=(e,t,n)=>{let r=t.filter(({to:t,from:r})=>{let i=t===e?n(r):void 0;return t===e&&(i===void 0||!AR.has(i))}).map(({from:e})=>e);return r.length===0?``:`After ${jR([...new Set(r)])}`},NR=e=>`${e.charAt(0).toUpperCase()}${e.slice(1)}`,PR=(e,t,n,r,i)=>{if(t===`queued`)return MR(e.id,n,r);if(e.watching!==void 0&&!AR.has(t)){let{looks:t,next:n}=TR(e.watching,i);return NR(`${t} ${t===`1`?`look`:`looks`}, next ${n}`)}return e.now??``},FR=({startedAt:e,finishedAt:t},n,r)=>{if(e===void 0)return`–`;let i=t??n;return jD((i===void 0?r:Date.parse(i))-Date.parse(e))},IR=e=>{let t=[...e];return`${String(t.filter(e=>AR.has(e)).length)} / ${String(t.length)}`},LR=({skipped:e=0,failuresHandled:t=0})=>{let n=[...e===0?[]:[`${String(e)} skipped`],...t===0?[]:[`${String(t)} ${t===1?`failure`:`failures`} handled`]];return n.length===0?null:n.join(` · `)},RR={status:`queued`},zR=({roots:e,facts:t,connections:n,selected:r,edges:i,hovered:a,now:o,runFinishedAt:s,onHover:c,onSelect:l,onNodeMenu:u})=>{let[d,f]=(0,V.useState)(new Set),[p,m]=(0,V.useState)(r),[h,g]=(0,V.useState)(r);r!==h&&(g(r),r!==null&&m(r));let _=(0,V.useMemo)(()=>ML(e,d),[e,d]),v=_.some(({node:e})=>e.id===p)?p:_[0]?.node.id??null,y=(e,t)=>{let n=new Set(d);t?n.delete(e):n.add(e),f(n)},b=(e,t)=>{m(t),[...e.currentTarget.parentElement?.querySelectorAll(`[data-tree-row]`)??[]].find(e=>e.dataset.treeRow===t)?.focus()},x=(e,t)=>{let n=_[t];if(n===void 0)return;let{node:r,parent:i}=n,a=r.children.length>0,o=a&&!d.has(r.id),s={ArrowDown:()=>{let n=_[t+1];n!==void 0&&b(e,n.node.id)},ArrowUp:()=>{let n=_[t-1];n!==void 0&&b(e,n.node.id)},ArrowRight:()=>{a&&(o?b(e,r.children[0]?.id??r.id):y(r.id,!0))},ArrowLeft:()=>{o?y(r.id,!1):i!==void 0&&b(e,i)},Home:()=>{b(e,_[0]?.node.id??r.id)},End:()=>{b(e,_.at(-1)?.node.id??r.id)},Enter:()=>{l(r.id)}," ":()=>{l(r.id)},ContextMenu:()=>{u(r.id)}}[e.key===`F10`&&e.shiftKey?`ContextMenu`:e.key];s!==void 0&&(e.preventDefault(),s())},S=e=>t.get(e)?.status,C=_.some(({node:e})=>e.children.length>0);return(0,G.jsxs)(`div`,{className:hR.table,children:[(0,G.jsxs)(`div`,{"aria-hidden":`true`,className:hR.tableHead,children:[(0,G.jsx)(`span`,{children:`Node`}),(0,G.jsx)(`span`,{className:hR.treeType,children:`Type`}),(0,G.jsx)(`span`,{children:`Status`}),(0,G.jsx)(`span`,{children:`Now`}),(0,G.jsx)(`span`,{className:hR.treeTime,children:`Time`}),(0,G.jsx)(`span`,{className:hR.treeCost,children:`Cost`})]}),(0,G.jsx)(`div`,{"aria-label":`Ownership tree`,className:hR.tree,role:`tree`,children:_.map(({node:e,depth:f},p)=>{let h=t.get(e.id)??RR,g=e.children.length>0,_=g&&!d.has(e.id),b=PR(e,h.status,i,S,o);return(0,V.createElement)(`div`,{...Xg(void 0,n.get(e.id)),"aria-expanded":g?_:void 0,"aria-label":[MD(e.id,e.type,h),...b===``?[]:[b]].join(`, `),"aria-level":f,"aria-selected":e.id===r,className:hR.treeRow,"data-dim":a!==null&&a!==e.id?``:void 0,"data-selected":e.id===r?``:void 0,"data-tree-row":e.id,key:e.id,onClick:()=>{m(e.id),l(e.id)},onContextMenu:t=>{t.preventDefault(),u(e.id)},onKeyDown:e=>{x(e,p)},onMouseEnter:()=>{c(e.id)},onMouseLeave:()=>{c(null)},role:`treeitem`,tabIndex:e.id===v?0:-1},(0,G.jsxs)(`span`,{className:hR.treeNode,style:{paddingInlineStart:`${String((f-1)*.75)}rem`},children:[C?(0,G.jsxs)(`span`,{"aria-hidden":`true`,className:hR.treeToggle,onClick:g?t=>{t.stopPropagation(),y(e.id,!_)}:void 0,children:[g&&_?(0,G.jsx)(Xv,{}):null,g&&!_?(0,G.jsx)(Zv,{}):null]}):null,(0,G.jsx)(`span`,{className:hR.treeId,children:e.id})]}),(0,G.jsx)(`span`,{className:hR.treeType,children:e.type}),(0,G.jsx)(`span`,{className:hR.treeStatus,children:(0,G.jsx)(bD,{status:h.status})}),(0,G.jsx)(`span`,{className:hR.treeNow,children:b}),(0,G.jsx)(`span`,{className:hR.treeTime,children:FR(e,s,o)}),(0,G.jsx)(`span`,{className:hR.treeCost,children:h.costUsd===void 0?`–`:OD(h.costUsd)}))})})]})},BR=new Map;function VR(e,t){let n=JSON.stringify({locale:ox(e),options:t}),r=BR.get(n);if(r)return r;let i=new Intl.NumberFormat(e,t);return BR.set(n,i),i}function HR(e,t,n){return e==null?``:VR(t,n).format(e)}var UR=V.createContext(void 0);function WR(){let e=V.useContext(UR);if(e===void 0)throw Error(rc(38));return e}function GR(e,t,n){return(e-t)*100/(n-t)}var KR=V.forwardRef(function(e,t){let{format:n,getAriaValueText:r,locale:i,max:a=100,min:o=0,value:s,render:c,className:l,children:u,style:d,...f}=e,[p,m]=V.useState(),h=GR(s,o,a),g=p_(Number.isNaN(h)?0:h,0,100),_=p_(Number.isNaN(s)?o:s,o,a),v=n?HR(_,i,n):HR(g/100,i,{style:`percent`}),y=v;r&&(y=r(v,s));let b={"aria-labelledby":p,"aria-valuemax":a,"aria-valuemin":o,"aria-valuenow":_,"aria-valuetext":y,role:`meter`,children:(0,G.jsxs)(V.Fragment,{children:[u,(0,G.jsx)(`span`,{role:`presentation`,style:Iu,children:`x`})]})},x=V.useMemo(()=>({formattedValue:v,percentageValue:g,setLabelId:m,value:s}),[v,g,m,s]),S=Pf(`div`,e,{ref:t,props:[b,f]});return(0,G.jsx)(UR.Provider,{value:x,children:S})}),qR=V.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,{setLabelId:s}=WR();return Pf(`span`,e,{ref:t,props:[{id:yx(a,s),role:`presentation`},o]})}),JR={meter:`_meter_1pby1_6`,label:`_label_1pby1_15`,value:`_value_1pby1_31`,track:`_track_1pby1_39`,block:`_block_1pby1_47`},YR=.8,XR=20,ZR=(e,t,n=XR)=>e>=t?n:e<=0?0:Math.min(Math.max(Math.round(e/t*n),1),n-1),QR=(e,t)=>e>=t?`full`:e>=t*YR?`high`:`normal`,$R=({value:e,max:t,blocks:n=XR})=>{let r=ZR(e,t,n);return(0,G.jsx)(`span`,{"aria-hidden":`true`,className:JR.track,"data-level":QR(e,t),children:Array.from({length:n},(e,t)=>(0,G.jsx)(`span`,{className:JR.block,"data-on":t<r?``:void 0},t))})},ez=({label:e,value:t,max:n,text:r})=>(0,G.jsxs)(KR,{"aria-valuetext":r,className:JR.meter,"data-level":QR(t,n),max:n,value:Math.min(t,n),children:[(0,G.jsx)(qR,{className:JR.label,children:e}),(0,G.jsx)(`span`,{className:JR.value,children:r}),(0,G.jsx)($R,{max:n,value:t})]}),tz=16,nz=({run:e,facts:t,budgetUsd:n,now:r})=>{let i=LR(e);return(0,G.jsxs)(`dl`,{className:hR.stats,children:[(0,G.jsxs)(`div`,{className:hR.stat,children:[(0,G.jsxs)(`dt`,{className:hR.statName,children:[`Spent`,n===void 0?``:` · cap ${OD(n,[])}`]}),(0,G.jsxs)(`dd`,{className:hR.statValue,children:[OD(e.costUsd),n===void 0?null:(0,G.jsx)($R,{blocks:tz,max:n,value:e.costUsd})]})]}),(0,G.jsxs)(`div`,{className:hR.stat,children:[(0,G.jsx)(`dt`,{className:hR.statName,children:`Nodes`}),(0,G.jsxs)(`dd`,{className:hR.statValue,children:[IR([...t.values()].map(({status:e})=>e)),i===null?null:` · ${i}`]})]}),(0,G.jsxs)(`div`,{className:hR.stat,children:[(0,G.jsx)(`dt`,{className:hR.statName,children:`Elapsed`}),(0,G.jsx)(`dd`,{className:hR.statValue,children:jD((e.finishedAt===void 0?r:Date.parse(e.finishedAt))-Date.parse(e.startedAt))})]})]})},rz=({run:e,waiting:t})=>{let n=qy(),r=(0,V.use)(ZM),i=ab(n.decisions)?.filter(({runId:t})=>t===e.id).length;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(bD,{pill:!0,status:VL(e,t)}),i===void 0||i===0?null:(0,G.jsxs)(q,{cli:`ork decide ${e.id} --list`,onClick:()=>{n.preferences.update({decisionFilter:{run:e.id}}),r?.goTo(`decisions`)},tip:`Open Decisions, filtered to this run.`,variant:`ghost`,children:[(0,G.jsx)(yy,{}),i===1?`1 decision`:`${i} decisions`,` waiting`]})]})},iz=({run:e,waiting:t,facts:n,budgetUsd:r,now:i})=>{let a=qy(),o=(0,V.useRef)(null),{parent:s}=e;return(0,V.useEffect)(()=>{a.takeArrival(e.id)&&o.current?.focus()},[a,e.id]),(0,G.jsxs)(`header`,{className:hR.header,children:[(0,G.jsxs)(`div`,{className:hR.stat,children:[(0,G.jsx)(`span`,{className:hR.statName,children:`Run`}),(0,G.jsxs)(`span`,{className:hR.statValue,children:[(0,G.jsx)(`h2`,{className:hR.title,"data-run-heading":e.id,ref:o,tabIndex:-1,children:e.workflow}),(0,G.jsx)(`code`,{className:hR.runId,children:e.id})]})]}),(0,G.jsx)(nz,{budgetUsd:r,facts:n,now:i,run:e}),(0,G.jsx)(rz,{run:e,waiting:t}),s===void 0?null:(0,G.jsxs)(q,{onClick:()=>{a.arriveAt(s)},variant:`ghost`,children:[`Called by `,s]}),(0,G.jsx)(bR,{actions:qL(e),runId:e.id})]})},az=({links:e,runId:t,onOpen:n})=>e.length===0?null:(0,G.jsxs)(`section`,{"aria-label":`Links to other runs`,className:hR.links,children:[(0,G.jsx)(`h3`,{className:hR.sideTitle,children:`Links`}),(0,G.jsx)(`ul`,{className:hR.linkList,children:e.map(e=>{let[r,i]=e.a.run===t?[e.a,e.b]:[e.b,e.a];return(0,G.jsxs)(`li`,{className:hR.link,children:[(0,G.jsxs)(`span`,{className:hR.linkEnds,children:[r.node,` ↔ `,i.run,`/`,i.node]}),(0,G.jsxs)(`span`,{className:hR.linkCount,children:[e.messages,`/`,e.maxMessages,e.endedAt===void 0?``:` · ended`]}),(0,G.jsx)(q,{onClick:()=>{n(i.run)},variant:`ghost`,children:`Open`})]},e.id)})})]}),oz=1e3,sz=e=>{let[t,n]=(0,V.useState)(Date.now);return(0,V.useEffect)(()=>{let t=e?setInterval(()=>{n(Date.now())},oz):void 0;return()=>{clearInterval(t)}},[e]),t},cz=1e3,lz=(e,t)=>{let n=(0,V.use)(ZM),r=(0,V.useRef)(null),i=(0,V.useRef)([]),a=(0,V.useRef)(void 0),{id:o,live:s}=e;(0,V.useEffect)(()=>{if(t.size===0)return;let e=RL(s,t),c=r.current===null?[]:BL(o,r.current,e);r.current=e,i.current.push(...c),i.current.length!==0&&a.current===void 0&&(a.current=setTimeout(()=>{a.current=void 0,n?.announce(i.current.splice(0).join(` `))},cz))},[t,o,s,n]),(0,V.useEffect)(()=>()=>{clearTimeout(a.current)},[])},uz=e=>{let t=qy(),n=e.id,r=(0,V.useMemo)(()=>t.watchRun(n),[t,n]);(0,V.useEffect)(()=>{let e=t.retainRun(n),i=r.start();return()=>{i(),e()}},[t,r,n]);let{graph:i,tree:a,links:o,error:s}=ab(r.state),c=ab(t.decisions),{node:l}=ab(t.selection),u=(0,V.useRef)(null),d=(0,V.useRef)(null),f=(0,V.useMemo)(()=>a??[],[a]),p=e.live!==`running`&&e.live!==`paused`,m=(0,V.useMemo)(()=>IL(c,n),[c,n]),h=(0,V.useMemo)(()=>LL(f,m,n,p),[f,m,n,p]),g=ML(f).map(({node:e})=>e.id).join(`
67
+ `),`[data-decision]`),v=e=>{s({decisionFilter:e})};return(0,V.useEffect)(()=>{if(f||!d)return;let e=lN(l,c,u);(e.workflow!==c.workflow||e.run!==c.run)&&s({decisionFilter:e}),p(!0)},[d,f,l,c,s,u]),(0,V.useEffect)(()=>{let e=r[0];e!==void 0&&e.id!==a.current&&(a.current=e.id,t?.announce(`${e.question} ${tN(e)}`))},[r,t]),(0,G.jsxs)(`div`,{"aria-label":`Decisions`,className:hN.panel,onFocus:_,ref:g,role:`group`,tabIndex:-1,children:[pN(m.active)||h?(0,G.jsx)($I,{onChange:v,open:l.length,view:m}):null,m.shown.length===0?(0,G.jsx)(eL,{filter:m.active,onClear:()=>{v({})},open:l.length}):(0,G.jsx)(`div`,{className:hN.list,children:m.shown.map(t=>(0,G.jsx)(QI,{decision:t,onAnswer:e.answerDecision,onOpenRun:(t,n)=>{e.selectRun(t),e.selectNode(n)},workflow:u(t.runId)},t.id))}),(0,G.jsx)(tL,{settled:r})]})},aL={panel:`_panel_ndh3j_8`,tools:`_tools_ndh3j_24`,main:`_main_ndh3j_39`,status:`_status_ndh3j_52`,counts:`_counts_ndh3j_65`,error:`_error_ndh3j_82`,list:`_list_ndh3j_91`,item:`_item_ndh3j_106`,row:`_row_ndh3j_113`,time:`_time_ndh3j_152`,type:`_type_ndh3j_153`,node:`_node_ndh3j_159`,line:`_line_ndh3j_161`,detail:`_detail_ndh3j_186`},oL=e=>e.map(e=>({value:e,label:e})),sL=({events:e,node:t,type:n,text:r,onNode:i,onType:a,onText:o})=>(0,G.jsxs)(`div`,{className:aL.tools,children:[(0,G.jsx)(KS,{empty:`No node matches.`,label:`Node`,onChange:i,options:oL(BM(e,t)),placeholder:`All nodes`,value:t}),(0,G.jsx)(KS,{empty:`No event type matches.`,label:`Event`,onChange:a,options:oL(VM(e)),placeholder:`All events`,value:n}),(0,G.jsx)(Uw,{label:`Text`,onChange:o,value:r})]}),cL=(0,V.memo)(({stored:e,open:t,tabbable:n,onToggle:r})=>{let{seq:i,at:a,event:o}=e;return(0,G.jsxs)(`li`,{className:aL.item,children:[(0,G.jsxs)(`button`,{"aria-expanded":t,className:aL.row,"data-log-row":i,onClick:()=>{r(i)},tabIndex:n?0:-1,type:`button`,children:[(0,G.jsx)(`span`,{className:aL.time,children:WM(a)}),(0,G.jsx)(`span`,{className:aL.node,children:kM(o)??`run`}),(0,G.jsx)(`span`,{className:aL.type,children:o.type}),(0,G.jsx)(`span`,{className:aL.line,children:FM(o)})]}),t?(0,G.jsx)(`pre`,{"aria-label":`Event ${String(i)} in full`,className:aL.detail,role:`group`,tabIndex:0,children:JSON.stringify(o,null,2)}):null]})});cL.displayName=`LogRow`;var lL=({shown:e,listRef:t,onScroll:n,label:r,reading:i})=>{let[a,o]=(0,V.useState)(new Set),[s,c]=(0,V.useState)(null),l=e.some(({seq:e})=>e===s)?s:e.at(-1)?.seq??null,u=(0,V.useCallback)(e=>{c(e),o(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n})},[]);return e.length===0?(0,G.jsx)(CC,{title:i?`Reading the run…`:`No event matches.`,children:`Only loaded events are filtered. Load older ones to look further.`}):(0,G.jsx)(`ol`,{"aria-label":r,className:aL.list,onKeyDown:e=>{let t=[...e.currentTarget.querySelectorAll(`[data-log-row]`)],n=t.findIndex(t=>t===e.target);if(n===-1)return;let r={ArrowDown:t[n+1],ArrowUp:t[n-1],Home:t[0],End:t.at(-1)};if(!(e.key in r))return;e.preventDefault();let i=r[e.key];i!==void 0&&(c(Number(i.dataset.logRow)),i.focus())},onScroll:n,ref:t,children:e.map(e=>(0,G.jsx)(cL,{onToggle:u,open:a.has(e.seq),stored:e,tabbable:e.seq===l},e.seq))})},uL=2e3,dL={events:[],latest:0,following:!0},fL=e=>e.events[0]?.seq??1,pL=e=>e.events.at(-1)?.seq??0,mL=e=>fL(e)>1,hL=e=>pL(e)<e.latest,gL=e=>e.slice(-2e3),_L=(e,t)=>Math.max(e.latest,t.at(-1)?.seq??0),vL=(e,t)=>{let n=pL(e);return t.filter(e=>e.seq>n)},yL=(e,t)=>{let n=_L(e,t);return e.following&&!hL(e)?{...e,latest:n,events:gL([...e.events,...vL(e,t)])}:{...e,latest:n}},bL=(e,t)=>({events:gL(t),latest:_L(e,t),following:!0}),xL=(e,t)=>({...e,latest:_L(e,t),events:gL([...e.events,...vL(e,t)])}),SL=(e,t)=>{let n=fL(e),r=[...t.filter(e=>e.seq<n),...e.events].slice(0,uL),i={...e,events:r};return{...i,following:e.following&&!hL(i)}},CL=e=>{let t=fL(e)-1,n=Math.max(0,t-500);return{after:n,limit:t-n}},wL=({events:e,shown:t,feed:n,cli:r})=>{let i=e.events.length,a=e.latest-pL(e);return(0,G.jsxs)(`div`,{className:aL.status,children:[(0,G.jsx)(`span`,{className:aL.counts,children:HM(t,i,e.latest)}),(0,G.jsx)(q,{disabled:!mL(e)||e.paging,focusableWhenDisabled:!0,onClick:()=>{n.loadOlder()},variant:`ghost`,children:`Load older`}),(0,G.jsxs)(q,{"aria-pressed":e.following,cli:r,onClick:()=>{e.following?n.hold():n.follow()},variant:`ghost`,children:[e.following?(0,G.jsx)(Yv,{}):null,`Follow`,a>0?` (${String(a)} new)`:``]})]})},TL=({error:e})=>(0,G.jsx)(`p`,{className:aL.error,role:`alert`,children:(0,G.jsx)(Wg,{text:e})}),EL=32,DL=e=>e.scrollHeight-e.scrollTop-e.clientHeight<EL,OL=(e,t)=>{let n=(0,V.useRef)(null),{following:r}=t,i=t.events[0]?.seq,a=(0,V.useRef)({firstSeq:i,height:0});return(0,V.useLayoutEffect)(()=>{let e=n.current;e!==null&&(r?e.scrollTop=e.scrollHeight:a.current.firstSeq!==i&&a.current.height>0&&(e.scrollTop+=e.scrollHeight-a.current.height),a.current={firstSeq:i,height:e.scrollHeight})}),(0,V.useEffect)(()=>{let t=n.current,r=new ResizeObserver(()=>{t!==null&&e.state.getValue().following&&(t.scrollTop=t.scrollHeight)});return t!==null&&r.observe(t),()=>{r.disconnect()}}),{listRef:n,onScroll:()=>{let t=n.current;if(t===null)return;let r=DL(t),i=e.state.getValue();i.following&&!r?e.hold():!i.following&&r&&!hL(i)&&e.follow()}}},kL=500,AL=({runId:e,node:t})=>{let n=qy(),r=(0,V.useMemo)(()=>n.feedOf(e),[n,e]);(0,V.useEffect)(()=>n.retainRun(e),[n,e]);let i=ab(r.state),[a,o]=(0,V.useState)(null),[s,c]=(0,V.useState)(``),l=(0,V.useMemo)(()=>RM(i.events,{node:t,type:a,text:s}),[i.events,t,a,s]),{listRef:u,onScroll:d}=OL(r,i),f=(0,V.use)(ZM),p=JSON.stringify([t,a,s]),m=(0,V.useRef)(p),h=HM(l.length,i.events.length,i.latest);return(0,V.useEffect)(()=>{let e=setTimeout(()=>{p!==m.current&&(m.current=p,f?.announce(h))},kL);return()=>{clearTimeout(e)}},[p,h,f]),(0,G.jsxs)(`div`,{className:aL.panel,children:[(0,G.jsx)(sL,{events:i.events,node:t,onNode:n.selectNode,onText:c,onType:o,text:s,type:a}),(0,G.jsxs)(`div`,{className:aL.main,children:[(0,G.jsx)(wL,{cli:UM(e,t),events:i,feed:r,shown:l.length}),i.error===null?null:(0,G.jsx)(TL,{error:i.error}),(0,G.jsx)(lL,{label:`Events of run ${e}`,listRef:u,onScroll:d,reading:i.link===`loading`&&i.events.length===0,shown:l})]})]})},jL=()=>{let{run:e,node:t}=ab(qy().selection);return e===null?(0,G.jsx)(CC,{cli:`ork logs <run>`,title:`No run chosen.`,children:`Choose one in the Runs panel, or in a terminal:`}):(0,G.jsx)(AL,{node:t,runId:e},e)},ML=(e,t=new Set)=>{let n=(e,r,i)=>e.flatMap(e=>[{node:e,depth:r,parent:i},...t.has(e.id)?[]:n(e.children,r+1,e.id)]);return n(e,1)},NL={waiting:`queued`,running:`running`,ok:`succeeded`,failed:`failed`,skipped:`skipped`},PL={waiting:`skipped`,running:`interrupted`},FL=(e,t,n=!1)=>{let r=n?PL[e.state]:void 0;return r===void 0?e.held===!0?`paused`:t?`waiting`:NL[e.state]:r},IL=(e,t)=>new Set((e??[]).filter(e=>e.runId===t).map(e=>e.node)),LL=(e,t,n,r=!1)=>new Map(ML(e).map(({node:e})=>{let i=e.inputTokens+e.outputTokens;return[e.id,{status:FL(e,t.has(e.id),r),model:e.model,tokens:i===0?void 0:i,costUsd:e.costUsd===0?void 0:e.costUsd,cli:`ork logs ${n} --node ${e.id}`}]})),RL=(e,t)=>({run:e,nodes:new Map([...t].map(([e,{status:t}])=>[e,t]))}),zL=new Set([`failed`,`paused`]),BL=(e,t,n)=>[...n.run===t.run||n.run!==`running`?[]:[`Run ${e} ${_D(n.run)}.`],...[...n.nodes].filter(([e,r])=>r!==t.nodes.get(e)&&zL.has(r)&&(r!==`paused`||n.run!==`paused`)).map(([e,t])=>`${e} ${_D(t)}.`)],VL=({live:e},t)=>e===`running`&&t?`waiting`:e,HL=(e,t)=>{let n=new Set(e.nodes.map(e=>e.id)),r=ML(t).map(({node:e})=>e).filter(e=>!n.has(e.id)).map(({id:e,type:t,parent:n})=>({id:e,type:t,parent:n}));return{...e,nodes:[...e.nodes,...r]}},UL={enabled:!0},WL=e=>({enabled:!1,why:e}),GL=({live:e})=>e===`running`||e===`paused`,KL=e=>e.id.startsWith(`node-`)?WL(`it ran one node; run that node again instead`):UL,qL=e=>{if(!GL(e)){let t=`the run has ended (${e.live})`,n={pause:WL(t),proceed:WL(t),stop:WL(t)};return e.live===`succeeded`?n:{...n,resume:KL(e)}}let t=e.live===`paused`;return{pause:t?WL(`the run is paused`):UL,proceed:t?UL:WL(`the run is not paused`),stop:UL}},JL=(e,t)=>{if(!GL(e)){let t=`the run has ended (${e.live})`;return{pause:WL(t),proceed:WL(t),stop:WL(t)}}if(t.state!==`running`&&t.state!==`waiting`){let e=`${t.id} has finished`;return{pause:WL(e),proceed:WL(e),stop:WL(e)}}let n=t.held===!0||e.paused.nodes.includes(t.id),r=t.state===`running`?UL:WL(`${t.id} is not running`);if(e.live===`paused`){let e=`the whole run is paused; continue the run`;return{pause:WL(e),proceed:WL(e),stop:r}}return{pause:n?WL(`${t.id} is paused`):UL,proceed:n?UL:WL(`${t.id} is not paused`),stop:r}},YL=e=>e.state===`waiting`||e.state===`skipped`?WL(`it hasn't run`):UL,XL={reason:`_reason_sb9l9_7`},J={panel:`_panel_150du_9`,tools:`_tools_150du_28`,card:`_card_150du_29`,body:`_body_150du_58`,toolsEnd:`_toolsEnd_150du_74`,count:`_count_150du_85`,updating:`_updating_150du_86`,list:`_list_150du_96`,row:`_row_150du_107`,rowTop:`_rowTop_150du_148`,rowTitle:`_rowTitle_150du_158`,rowMeta:`_rowMeta_150du_172`,high:`_high_150du_189`,detail:`_detail_150du_197`,head:`_head_150du_206`,title:`_title_150du_215`,facts:`_facts_150du_228`,fact:`_fact_150du_228`,factName:`_factName_150du_245`,caption:`_caption_150du_246`,factValue:`_factValue_150du_263`,actions:`_actions_150du_278`,line:`_line_150du_279`,note:`_note_150du_288`,message:`_message_150du_289`,lineIcon:`_lineIcon_150du_299`,alert:`_alert_150du_308`,section:`_section_150du_326`,records:`_records_150du_339`,record:`_record_150du_339`,recordMeta:`_recordMeta_150du_362`,recordTitle:`_recordTitle_150du_380`,recordBody:`_recordBody_150du_390`,evidence:`_evidence_150du_399`,form:`_form_150du_409`,pair:`_pair_150du_417`,place:`_place_150du_425`,wellHead:`_wellHead_150du_435`,wellCopy:`_wellCopy_150du_444`,preview:`_preview_150du_452`,link:`_link_150du_499`,result:`_result_150du_510`,dialogFoot:`_dialogFoot_150du_519`},ZL=`Meta+Enter Control+Enter`,QL=({onSend:e,children:t})=>(0,G.jsx)(`form`,{className:J.form,onKeyDown:t=>{t.key===`Enter`&&(t.metaKey||t.ctrlKey)&&(t.preventDefault(),e())},onSubmit:t=>{t.preventDefault(),e()},children:t}),$L=({why:e,id:t})=>(0,G.jsx)(`output`,{className:XL.reason,id:t,children:(0,G.jsx)(Wg,{text:e??``})}),eR=({text:e})=>e===null?null:(0,G.jsx)(`p`,{className:J.alert,role:`alert`,children:(0,G.jsx)(Wg,{text:e})}),tR=[`friction`,`bug`,`context-gap`,`skill`,`workflow`,`idea`],nR=[`low`,`medium`,`high`],rR=[{value:``,label:`No rating`},{value:`good`,label:`good`},{value:`bad`,label:`bad`}],iR={text:``,rating:``,kind:`friction`,severity:null},aR=({rating:e,severity:t})=>t??(e===`bad`?`high`:`medium`),oR=e=>e.severity===null&&e.rating===`bad`,sR=e=>e.text.trim()===``?`Write the note first.`:null,cR=(e,t)=>({text:t.text,...e===void 0?{}:{node:e},kind:t.kind,severity:aR(t),...t.rating===``?{}:{rating:t.rating}}),lR=(e,t,n)=>{let r=aR({...n,severity:null}),i=aR(n);return[`ork feedback note`,e,...t===void 0?[]:[sT(t)],`-m`,n.text.trim()===``?`<text>`:sT(n.text),...n.kind===`friction`?[]:[`--kind ${n.kind}`],...i===r?[]:[`--severity ${i}`],...n.rating===``?[]:[`--rating ${n.rating}`]].join(` `)},uR=(e,t,n)=>({title:t===void 0?`Noted on run \`${e}\``:`Noted on \`${t}\``,description:`It joined item \`${n.slice(0,12)}\`.`}),dR=e=>e.map(e=>({value:e,label:e})),fR=({runId:e,node:t,onSend:n,onDone:r})=>{let[i,a]=(0,V.useState)(iR),[o,s]=(0,V.useState)(!1),[c,l]=(0,V.useState)(null),u=(0,V.useId)(),d=(0,V.useId)(),f=sR(i),p=e=>{a(t=>({...t,...e}))},m=async()=>{if(f!==null||o)return;s(!0),l(null);let e=await n(cR(t,i));s(!1),l(e),e===null&&r()};return(0,G.jsxs)(QL,{onSend:()=>{m()},children:[(0,G.jsx)(Uw,{description:`Its first line is the title.`,label:`Note`,multiline:!0,onChange:e=>{p({text:e})},required:!0,value:i.text}),(0,G.jsx)(Bw,{label:`Rating`,onChange:e=>{p({rating:e})},options:rR,value:i.rating}),(0,G.jsx)(Bw,{label:`Kind`,onChange:e=>{p({kind:e})},options:dR(tR),value:i.kind}),(0,G.jsx)(Bw,{label:`Severity`,onChange:e=>{p({severity:e})},describedBy:d,options:dR(nR),value:aR(i)}),(0,G.jsx)($L,{id:d,why:oR(i)?`Severity: high, from the bad rating.`:null}),(0,G.jsx)(YS,{command:lR(e,t,i)}),(0,G.jsx)($L,{id:u,why:f}),(0,G.jsx)(eR,{text:c}),(0,G.jsxs)(xC,{children:[(0,G.jsx)(q,{disabled:o,onClick:r,type:`button`,variant:`ghost`,children:`Cancel`}),(0,G.jsx)(q,{"aria-describedby":u,"aria-keyshortcuts":ZL,disabled:f!==null||o,focusableWhenDisabled:!0,type:`submit`,variant:`primary`,children:o?`Adding…`:`Add note`})]})]})},pR={enabled:!0},mR=({runId:e,node:t,check:n=pR,onSend:r})=>{let[i,a]=(0,V.useState)(!1),o=t??`run ${e}`,s=n.enabled?`Note on ${o}`:`Note on ${o}: ${n.why}`,c=`ork feedback note ${e}${t===void 0?``:` ${t}`} -m <text>`,l=()=>{a(!0)};return(0,G.jsxs)(G.Fragment,{children:[t===void 0?(0,G.jsx)(cb,{cli:c,label:s,onClick:l,children:(0,G.jsx)(xy,{})}):(0,G.jsxs)(q,{"aria-label":s,cli:c,disabled:!n.enabled,focusableWhenDisabled:!0,onClick:l,tip:n.enabled?void 0:s,children:[(0,G.jsx)(xy,{}),`Note…`]}),(0,G.jsx)(bC,{description:`It joins run ${e}'s feedback as yours, and groups into an item like any record.`,onOpenChange:a,open:i,title:t===void 0?`Note on run \`${e}\``:`Note on \`${t}\``,children:(0,G.jsx)(fR,{node:t,onDone:()=>{a(!1)},onSend:r,runId:e})})]})},hR={monitor:`_monitor_1rkzd_8`,header:`_header_1rkzd_25`,stats:`_stats_1rkzd_43`,stat:`_stat_1rkzd_43`,statName:`_statName_1rkzd_58`,statValue:`_statValue_1rkzd_74`,title:`_title_1rkzd_90`,runId:`_runId_1rkzd_101`,controls:`_controls_1rkzd_111`,error:`_error_1rkzd_119`,canvas:`_canvas_1rkzd_133`,table:`_table_1rkzd_144`,tableHead:`_tableHead_1rkzd_162`,tree:`_tree_1rkzd_185`,treeRow:`_treeRow_1rkzd_190`,treeNode:`_treeNode_1rkzd_233`,treeToggle:`_treeToggle_1rkzd_239`,treeId:`_treeId_1rkzd_259`,treeType:`_treeType_1rkzd_269`,treeStatus:`_treeStatus_1rkzd_285`,treeNow:`_treeNow_1rkzd_291`,treeTime:`_treeTime_1rkzd_301`,treeCost:`_treeCost_1rkzd_314`,sideTitle:`_sideTitle_1rkzd_337`,node:`_node_1rkzd_346`,nodeFacts:`_nodeFacts_1rkzd_362`,watching:`_watching_1rkzd_363`,links:`_links_1rkzd_415`,linkList:`_linkList_1rkzd_430`,link:`_link_1rkzd_415`,linkEnds:`_linkEnds_1rkzd_450`,linkCount:`_linkCount_1rkzd_461`},gR={enabled:!0},_R=(e,t,n)=>n.enabled?`${e} ${t}`:`${e} ${t}: ${n.why}`,vR=`It goes on in the background with the inputs and flags it started with. Nodes that finished keep their results and don't run again; the one that failed or was cut off runs again, and so does everything after it. It's a paid run, like any you start.`,yR=({runId:e,action:t})=>{let n=qy(),[r,i]=(0,V.useState)(!1),a=(0,V.useRef)(!1),o=`ork resume ${e} --detach`;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(q,{"aria-label":_R(`Resume`,`run`,t),cli:o,disabled:!t.enabled,focusableWhenDisabled:!0,onClick:()=>{i(!0)},tip:t.enabled?void 0:t.why,variant:`ghost`,children:[(0,G.jsx)(By,{}),`Resume…`]}),(0,G.jsx)(SC,{cli:o,confirm:`Resume run`,description:vR,finalFocus:()=>{let t=a.current;return a.current=!1,(t?document.querySelector(`[data-run-heading="${e}"]`):null)??!0},onConfirm:async()=>{let t=await n.client.call(`resume`,{params:{id:e},body:{}});return a.current=t.ok,t.ok?null:`Could not resume the run: ${t.error}`},onOpenChange:i,open:r,pending:`Resuming…`,title:`Resume run ${e}?`,variant:`primary`})]})},bR=({runId:e,node:t,actions:n,note:r=gR})=>{let i=qy(),[a,o]=(0,V.useState)(!1),s=t??`run`,c=t===void 0?``:` --node ${t}`,l=n=>{i.control(n,e,t).then(e=>(e.ok||Hy.add({title:`Could not ${n} ${s}`,description:e.error}),e))},u=(0,G.jsx)(mR,{check:r,node:t,onSend:async n=>{let r=await i.client.call(`note`,{params:{id:e},body:n});return r.ok?(Hy.add(uR(e,t,r.data.item)),null):`Could not add the note: ${r.error}`},runId:e});return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{"aria-label":t===void 0?`Run controls`:`Controls for ${t}`,className:hR.controls,role:`group`,children:[(0,G.jsx)(cb,{cli:`ork pause ${e}${c}`,disabled:!n.pause.enabled,focusableWhenDisabled:!0,label:_R(`Pause`,s,n.pause),onClick:()=>{l(`pause`)},children:(0,G.jsx)(Kv,{})}),(0,G.jsx)(cb,{cli:`ork continue ${e}${c}`,disabled:!n.proceed.enabled,focusableWhenDisabled:!0,label:_R(`Continue`,s,n.proceed),onClick:()=>{l(`continue`)},children:(0,G.jsx)(Gv,{})}),(0,G.jsx)(cb,{cli:`ork stop ${e}${c}`,disabled:!n.stop.enabled,focusableWhenDisabled:!0,label:_R(`Stop`,s,n.stop),onClick:()=>{o(!0)},children:(0,G.jsx)(qv,{})}),(0,G.jsx)(SC,{cli:`ork stop ${e}${c}`,confirm:t===void 0?`Stop run`:`Stop ${t}`,description:t===void 0?`Running nodes are interrupted, and runs it called stop too. It can be resumed later, from here or a terminal.`:`Its session is interrupted and \`${t}\` fails with \`stopped by the user\`. The workflow's failure rules then apply.`,onConfirm:()=>{o(!1),l(`stop`)},onOpenChange:o,open:a,title:t===void 0?`Stop run ${e}?`:`Stop ${t}?`}),n.resume===void 0?null:(0,G.jsx)(yR,{action:n.resume,runId:e}),t===void 0?u:null]}),t===void 0?null:u]})},xR={s:1e3,m:6e4,h:36e5},SR=e=>{let t=/^(\d+)([smh])$/u.exec(e);return Number(t?.[1]??0)*(xR[t?.[2]??`s`]??1e3)},CR=e=>{let t=Math.ceil(e/1e3);if(t<60)return`${String(t)} s`;let n=Math.ceil(t/60);return n<60?`${String(n)} min`:`${String(Math.ceil(n/60))} h`},wR=e=>e===`running`||e===`paused`,TR=(e,t)=>{let n=SR(e.every),r=Math.max(0,t-Date.parse(e.at)),i=n===0?0:Math.floor(r/n),a=e.looks+i;return{until:e.until,every:`every ${e.every}`,looks:`${i===0?``:`about `}${String(a)}`,next:`in about ${CR(n===0?0:n-r%n)}`,said:e.said}},ER=5e3,DR=({watching:e})=>{let[t,n]=(0,V.useState)(Date.now);(0,V.useEffect)(()=>{let e=setInterval(()=>{n(Date.now())},ER);return()=>{clearInterval(e)}},[]);let r=TR(e,t);return(0,G.jsxs)(`dl`,{className:hR.watching,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Waiting until`}),(0,G.jsx)(`dd`,{children:(0,G.jsx)(`code`,{children:r.until})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Looks`}),(0,G.jsxs)(`dd`,{children:[r.looks,`, `,r.every]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Next look`}),(0,G.jsx)(`dd`,{children:r.next})]}),r.said===void 0?null:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Last said`}),(0,G.jsx)(`dd`,{children:(0,G.jsx)(`code`,{children:r.said})})]})]})},OR=({run:e,node:t,sectionRef:n,onLeave:r,onOpenRun:i})=>{let{calledRun:a}=t;return(0,G.jsxs)(`section`,{"aria-label":`Node ${t.id}`,className:hR.node,onKeyDown:e=>{let t=document.querySelector(`[data-modal]`)!==null;e.key===`Escape`&&!t&&r()},ref:n,children:[(0,G.jsx)(`h3`,{className:hR.sideTitle,children:t.id}),(0,G.jsxs)(`dl`,{className:hR.nodeFacts,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Type`}),(0,G.jsx)(`dd`,{children:ED(t.type)})]}),t.model===void 0?null:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Model`}),(0,G.jsx)(`dd`,{children:t.model})]}),t.inputTokens+t.outputTokens===0?null:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Tokens`}),(0,G.jsxs)(`dd`,{children:[kD(t.inputTokens),` in ·`,` `,kD(t.outputTokens),` out`]})]})]}),(0,G.jsx)(bR,{actions:JL(e,t),node:t.id,note:YL(t),runId:e.id}),t.watching===void 0||!wR(e.status)?null:(0,G.jsx)(DR,{watching:t.watching}),a===void 0?null:(0,G.jsxs)(q,{onClick:()=>{i(a)},variant:`ghost`,children:[`Open run `,a]})]})},kR=({error:e})=>(0,G.jsx)(`p`,{className:hR.error,role:`alert`,children:(0,G.jsx)(Wg,{text:e})}),AR=new Set([`succeeded`,`failed`,`skipped`,`interrupted`]),jR=e=>e.length<2?e.join(``):`${e.slice(0,-1).join(`, `)} and ${e.at(-1)??``}`,MR=(e,t,n)=>{let r=t.filter(({to:t,from:r})=>{let i=t===e?n(r):void 0;return t===e&&(i===void 0||!AR.has(i))}).map(({from:e})=>e);return r.length===0?``:`After ${jR([...new Set(r)])}`},NR=e=>`${e.charAt(0).toUpperCase()}${e.slice(1)}`,PR=(e,t,n,r,i)=>{if(t===`queued`)return MR(e.id,n,r);if(e.watching!==void 0&&!AR.has(t)){let{looks:t,next:n}=TR(e.watching,i);return NR(`${t} ${t===`1`?`look`:`looks`}, next ${n}`)}return e.now??``},FR=({startedAt:e,finishedAt:t},n,r)=>{if(e===void 0)return`–`;let i=t??n;return jD((i===void 0?r:Date.parse(i))-Date.parse(e))},IR=e=>{let t=[...e];return`${String(t.filter(e=>AR.has(e)).length)} / ${String(t.length)}`},LR=({skipped:e=0,failuresHandled:t=0})=>{let n=[...e===0?[]:[`${String(e)} skipped`],...t===0?[]:[`${String(t)} ${t===1?`failure`:`failures`} handled`]];return n.length===0?null:n.join(` · `)},RR={status:`queued`},zR=({roots:e,facts:t,connections:n,selected:r,edges:i,hovered:a,now:o,runFinishedAt:s,onHover:c,onSelect:l,onNodeMenu:u})=>{let[d,f]=(0,V.useState)(new Set),[p,m]=(0,V.useState)(r),[h,g]=(0,V.useState)(r);r!==h&&(g(r),r!==null&&m(r));let _=(0,V.useMemo)(()=>ML(e,d),[e,d]),v=_.some(({node:e})=>e.id===p)?p:_[0]?.node.id??null,y=(e,t)=>{let n=new Set(d);t?n.delete(e):n.add(e),f(n)},b=(e,t)=>{m(t),[...e.currentTarget.parentElement?.querySelectorAll(`[data-tree-row]`)??[]].find(e=>e.dataset.treeRow===t)?.focus()},x=(e,t)=>{let n=_[t];if(n===void 0)return;let{node:r,parent:i}=n,a=r.children.length>0,o=a&&!d.has(r.id),s={ArrowDown:()=>{let n=_[t+1];n!==void 0&&b(e,n.node.id)},ArrowUp:()=>{let n=_[t-1];n!==void 0&&b(e,n.node.id)},ArrowRight:()=>{a&&(o?b(e,r.children[0]?.id??r.id):y(r.id,!0))},ArrowLeft:()=>{o?y(r.id,!1):i!==void 0&&b(e,i)},Home:()=>{b(e,_[0]?.node.id??r.id)},End:()=>{b(e,_.at(-1)?.node.id??r.id)},Enter:()=>{l(r.id)}," ":()=>{l(r.id)},ContextMenu:()=>{u(r.id)}}[e.key===`F10`&&e.shiftKey?`ContextMenu`:e.key];s!==void 0&&(e.preventDefault(),s())},S=e=>t.get(e)?.status,C=_.some(({node:e})=>e.children.length>0);return(0,G.jsxs)(`div`,{className:hR.table,children:[(0,G.jsxs)(`div`,{"aria-hidden":`true`,className:hR.tableHead,children:[(0,G.jsx)(`span`,{children:`Node`}),(0,G.jsx)(`span`,{className:hR.treeType,children:`Type`}),(0,G.jsx)(`span`,{children:`Status`}),(0,G.jsx)(`span`,{children:`Now`}),(0,G.jsx)(`span`,{className:hR.treeTime,children:`Time`}),(0,G.jsx)(`span`,{className:hR.treeCost,children:`Cost`})]}),(0,G.jsx)(`div`,{"aria-label":`Ownership tree`,className:hR.tree,role:`tree`,children:_.map(({node:e,depth:f},p)=>{let h=t.get(e.id)??RR,g=e.children.length>0,_=g&&!d.has(e.id),b=PR(e,h.status,i,S,o);return(0,V.createElement)(`div`,{...Xg(void 0,n.get(e.id)),"aria-expanded":g?_:void 0,"aria-label":[MD(e.id,e.type,h),...b===``?[]:[b]].join(`, `),"aria-level":f,"aria-selected":e.id===r,className:hR.treeRow,"data-dim":a!==null&&a!==e.id?``:void 0,"data-selected":e.id===r?``:void 0,"data-tree-row":e.id,key:e.id,onClick:()=>{m(e.id),l(e.id)},onContextMenu:t=>{t.preventDefault(),u(e.id)},onKeyDown:e=>{x(e,p)},onMouseEnter:()=>{c(e.id)},onMouseLeave:()=>{c(null)},role:`treeitem`,tabIndex:e.id===v?0:-1},(0,G.jsxs)(`span`,{className:hR.treeNode,style:{paddingInlineStart:`${String((f-1)*.75)}rem`},children:[C?(0,G.jsxs)(`span`,{"aria-hidden":`true`,className:hR.treeToggle,onClick:g?t=>{t.stopPropagation(),y(e.id,!_)}:void 0,children:[g&&_?(0,G.jsx)(Xv,{}):null,g&&!_?(0,G.jsx)(Zv,{}):null]}):null,(0,G.jsx)(`span`,{className:hR.treeId,children:e.id})]}),(0,G.jsx)(`span`,{className:hR.treeType,children:e.type}),(0,G.jsx)(`span`,{className:hR.treeStatus,children:(0,G.jsx)(bD,{status:h.status})}),(0,G.jsx)(`span`,{className:hR.treeNow,children:b}),(0,G.jsx)(`span`,{className:hR.treeTime,children:FR(e,s,o)}),(0,G.jsx)(`span`,{className:hR.treeCost,children:h.costUsd===void 0?`–`:OD(h.costUsd)}))})})]})},BR=new Map;function VR(e,t){let n=JSON.stringify({locale:ox(e),options:t}),r=BR.get(n);if(r)return r;let i=new Intl.NumberFormat(e,t);return BR.set(n,i),i}function HR(e,t,n){return e==null?``:VR(t,n).format(e)}var UR=V.createContext(void 0);function WR(){let e=V.useContext(UR);if(e===void 0)throw Error(rc(38));return e}function GR(e,t,n){return(e-t)*100/(n-t)}var KR=V.forwardRef(function(e,t){let{format:n,getAriaValueText:r,locale:i,max:a=100,min:o=0,value:s,render:c,className:l,children:u,style:d,...f}=e,[p,m]=V.useState(),h=GR(s,o,a),g=p_(Number.isNaN(h)?0:h,0,100),_=p_(Number.isNaN(s)?o:s,o,a),v=n?HR(_,i,n):HR(g/100,i,{style:`percent`}),y=v;r&&(y=r(v,s));let b={"aria-labelledby":p,"aria-valuemax":a,"aria-valuemin":o,"aria-valuenow":_,"aria-valuetext":y,role:`meter`,children:(0,G.jsxs)(V.Fragment,{children:[u,(0,G.jsx)(`span`,{role:`presentation`,style:Iu,children:`x`})]})},x=V.useMemo(()=>({formattedValue:v,percentageValue:g,setLabelId:m,value:s}),[v,g,m,s]),S=Pf(`div`,e,{ref:t,props:[b,f]});return(0,G.jsx)(UR.Provider,{value:x,children:S})}),qR=V.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,{setLabelId:s}=WR();return Pf(`span`,e,{ref:t,props:[{id:yx(a,s),role:`presentation`},o]})}),JR={meter:`_meter_1pby1_6`,label:`_label_1pby1_15`,value:`_value_1pby1_31`,track:`_track_1pby1_39`,block:`_block_1pby1_47`},YR=.8,XR=20,ZR=(e,t,n=XR)=>e>=t?n:e<=0?0:Math.min(Math.max(Math.round(e/t*n),1),n-1),QR=(e,t)=>e>=t?`full`:e>=t*YR?`high`:`normal`,$R=({value:e,max:t,blocks:n=XR})=>{let r=ZR(e,t,n);return(0,G.jsx)(`span`,{"aria-hidden":`true`,className:JR.track,"data-level":QR(e,t),children:Array.from({length:n},(e,t)=>(0,G.jsx)(`span`,{className:JR.block,"data-on":t<r?``:void 0},t))})},ez=({label:e,value:t,max:n,text:r})=>(0,G.jsxs)(KR,{"aria-valuetext":r,className:JR.meter,"data-level":QR(t,n),max:n,value:Math.min(t,n),children:[(0,G.jsx)(qR,{className:JR.label,children:e}),(0,G.jsx)(`span`,{className:JR.value,children:r}),(0,G.jsx)($R,{max:n,value:t})]}),tz=16,nz=({run:e,facts:t,budgetUsd:n,now:r})=>{let i=LR(e);return(0,G.jsxs)(`dl`,{className:hR.stats,children:[(0,G.jsxs)(`div`,{className:hR.stat,children:[(0,G.jsxs)(`dt`,{className:hR.statName,children:[`Spent`,n===void 0?``:` · cap ${OD(n,[])}`]}),(0,G.jsxs)(`dd`,{className:hR.statValue,children:[OD(e.costUsd),n===void 0?null:(0,G.jsx)($R,{blocks:tz,max:n,value:e.costUsd})]})]}),(0,G.jsxs)(`div`,{className:hR.stat,children:[(0,G.jsx)(`dt`,{className:hR.statName,children:`Nodes`}),(0,G.jsxs)(`dd`,{className:hR.statValue,children:[IR([...t.values()].map(({status:e})=>e)),i===null?null:` · ${i}`]})]}),(0,G.jsxs)(`div`,{className:hR.stat,children:[(0,G.jsx)(`dt`,{className:hR.statName,children:`Elapsed`}),(0,G.jsx)(`dd`,{className:hR.statValue,children:jD((e.finishedAt===void 0?r:Date.parse(e.finishedAt))-Date.parse(e.startedAt))})]})]})},rz=({run:e,waiting:t})=>{let n=qy(),r=(0,V.use)(ZM),i=ab(n.decisions)?.filter(({runId:t})=>t===e.id).length;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(bD,{pill:!0,status:VL(e,t)}),i===void 0||i===0?null:(0,G.jsxs)(q,{cli:`ork decide ${e.id} --list`,onClick:()=>{n.preferences.update({decisionFilter:{run:e.id}}),r?.goTo(`decisions`)},tip:`Open Decisions, filtered to this run.`,variant:`ghost`,children:[(0,G.jsx)(yy,{}),i===1?`1 decision`:`${i} decisions`,` waiting`]})]})},iz=({run:e,waiting:t,facts:n,budgetUsd:r,now:i})=>{let a=qy(),o=(0,V.useRef)(null),{parent:s}=e;return(0,V.useEffect)(()=>{a.takeArrival(e.id)&&o.current?.focus()},[a,e.id]),(0,G.jsxs)(`header`,{className:hR.header,children:[(0,G.jsxs)(`div`,{className:hR.stat,children:[(0,G.jsx)(`span`,{className:hR.statName,children:`Run`}),(0,G.jsxs)(`span`,{className:hR.statValue,children:[(0,G.jsx)(`h2`,{className:hR.title,"data-run-heading":e.id,ref:o,tabIndex:-1,children:e.workflow}),(0,G.jsx)(`code`,{className:hR.runId,children:e.id})]})]}),(0,G.jsx)(nz,{budgetUsd:r,facts:n,now:i,run:e}),(0,G.jsx)(rz,{run:e,waiting:t}),s===void 0?null:(0,G.jsxs)(q,{onClick:()=>{a.arriveAt(s)},variant:`ghost`,children:[`Called by `,s]}),(0,G.jsx)(bR,{actions:qL(e),runId:e.id})]})},az=({links:e,runId:t,onOpen:n})=>e.length===0?null:(0,G.jsxs)(`section`,{"aria-label":`Links to other runs`,className:hR.links,children:[(0,G.jsx)(`h3`,{className:hR.sideTitle,children:`Links`}),(0,G.jsx)(`ul`,{className:hR.linkList,children:e.map(e=>{let[r,i]=e.a.run===t?[e.a,e.b]:[e.b,e.a];return(0,G.jsxs)(`li`,{className:hR.link,children:[(0,G.jsxs)(`span`,{className:hR.linkEnds,children:[r.node,` ↔ `,i.run,`/`,i.node]}),(0,G.jsxs)(`span`,{className:hR.linkCount,children:[e.messages,`/`,e.maxMessages,e.endedAt===void 0?``:` · ended`]}),(0,G.jsx)(q,{onClick:()=>{n(i.run)},variant:`ghost`,children:`Open`})]},e.id)})})]}),oz=1e3,sz=e=>{let[t,n]=(0,V.useState)(Date.now);return(0,V.useEffect)(()=>{let t=e?setInterval(()=>{n(Date.now())},oz):void 0;return()=>{clearInterval(t)}},[e]),t},cz=1e3,lz=(e,t)=>{let n=(0,V.use)(ZM),r=(0,V.useRef)(null),i=(0,V.useRef)([]),a=(0,V.useRef)(void 0),{id:o,live:s}=e;(0,V.useEffect)(()=>{if(t.size===0)return;let e=RL(s,t),c=r.current===null?[]:BL(o,r.current,e);r.current=e,i.current.push(...c),i.current.length!==0&&a.current===void 0&&(a.current=setTimeout(()=>{a.current=void 0,n?.announce(i.current.splice(0).join(` `))},cz))},[t,o,s,n]),(0,V.useEffect)(()=>()=>{clearTimeout(a.current)},[])},uz=e=>{let t=qy(),n=e.id,r=(0,V.useMemo)(()=>t.watchRun(n),[t,n]);(0,V.useEffect)(()=>{let e=t.retainRun(n),i=r.start();return()=>{i(),e()}},[t,r,n]);let{graph:i,tree:a,links:o,error:s}=ab(r.state),c=ab(t.decisions),{node:l}=ab(t.selection),u=(0,V.useRef)(null),d=(0,V.useRef)(null),f=(0,V.useMemo)(()=>a??[],[a]),p=e.live!==`running`&&e.live!==`paused`,m=(0,V.useMemo)(()=>IL(c,n),[c,n]),h=(0,V.useMemo)(()=>LL(f,m,n,p),[f,m,n,p]),g=ML(f).map(({node:e})=>e.id).join(`
68
68
  `),_=(0,V.useMemo)(()=>i===null?null:bk(HL(i,f)),[i,g]),v=(0,V.useMemo)(()=>NE(_?.edges??[]),[_]),y=ML(f).find(({node:e})=>e.id===l)?.node;lz(e,h);let b=(0,V.useCallback)(e=>{let{activeElement:n}=document;d.current=n instanceof HTMLElement?n:null,t.selectNode(e),requestAnimationFrame(()=>{u.current?.querySelector(`button`)?.focus()})},[t]),x=(0,V.useCallback)(()=>{d.current?.focus({preventScroll:!0}),d.current=null},[]);return{state:t,graph:i,layout:_,facts:h,waiting:m.size>0,connections:v,roots:f,links:o,error:s,selected:l,chosen:y,nodeControls:u,openControls:b,closeControls:x}},dz=({run:e})=>{let{state:t,graph:n,layout:r,facts:i,waiting:a,connections:o,roots:s,links:c,error:l,selected:u,chosen:d,nodeControls:f,openControls:p,closeControls:m}=uz(e),[h,g]=(0,V.useState)(null),_=sz(e.live===`running`||e.live===`paused`);return(0,G.jsxs)(`div`,{className:hR.monitor,children:[(0,G.jsx)(iz,{budgetUsd:n?.budgetUsd,facts:i,now:_,run:e,waiting:a}),l===null?null:(0,G.jsx)(kR,{error:l}),(0,G.jsx)(`div`,{className:hR.canvas,children:r===null?(0,G.jsx)(CC,{cli:`ork tree ${e.id}`,title:`Reading the run…`,children:`For now:`}):(0,G.jsx)(MO,{facts:i,hovered:h,label:`Graph of run ${e.id}, ${e.workflow}`,layout:r,live:!0,onHover:g,onNodeMenu:p,onSelect:t.selectNode,selected:u??void 0})}),(0,G.jsx)(zR,{connections:o,edges:n?.edges??[],facts:i,hovered:h,now:_,onHover:g,onNodeMenu:p,onSelect:t.selectNode,roots:s,runFinishedAt:e.finishedAt,selected:u}),d===void 0?null:(0,G.jsx)(OR,{node:d,onLeave:m,onOpenRun:t.arriveAt,run:e,sectionRef:f}),(0,G.jsx)(az,{links:c,onOpen:t.arriveAt,runId:e.id})]})},fz=()=>{let e=qy(),{run:t}=ab(e.selection),n=ab(e.runs)?.find(({id:e})=>e===t);return n===void 0?(0,G.jsx)(CC,{cli:`ork tree <run>`,title:`No run chosen.`,children:`Choose one in the Runs panel, or in a terminal:`}):(0,G.jsx)(dz,{run:n},n.id)},pz=()=>`Notification`in globalThis,mz=async()=>pz()?await Notification.requestPermission()===`granted`?`granted`:`denied`:`unsupported`,hz=(e,t,n)=>{if(!pz()||Notification.permission!==`granted`||document.visibilityState===`visible`)return;let r=new Notification(`Ork`,{body:e,tag:t});r.addEventListener(`click`,()=>{window.focus(),n(),r.close()})},gz=(e,t)=>e.live===`running`&&t?`waiting`:e.live,_z=e=>{let t=new Date(e),n=t.toDateString()===new Date().toDateString();return t.toLocaleString(void 0,n?{hour:`2-digit`,minute:`2-digit`,second:`2-digit`}:{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})},vz=({paused:e,live:t})=>{let n=e.nodes.length;return t!==`running`||n===0?null:n===1?`1 node paused`:`${String(n)} nodes paused`},yz=(0,V.memo)(({run:e,selected:t,tabStop:n,waiting:r,onSelect:i})=>{let a=vz(e);return(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{"aria-current":t?`true`:void 0,className:Ww.row,"data-run-row":e.id,onClick:()=>{i(e.id)},tabIndex:n?0:-1,type:`button`,children:[(0,G.jsxs)(`span`,{className:Ww.rowTop,children:[(0,G.jsx)(`span`,{className:Ww.workflow,children:e.workflow}),(0,G.jsx)(bD,{status:gz(e,r)})]}),(0,G.jsxs)(`span`,{className:Ww.rowMeta,children:[(0,G.jsx)(`span`,{children:e.id}),(0,G.jsx)(`time`,{dateTime:e.startedAt,children:_z(e.startedAt)}),(0,G.jsx)(`span`,{children:OD(e.costUsd)}),a===null?null:(0,G.jsx)(`span`,{children:a})]})]})})});yz.displayName=`RunRow`;var bz=({onClick:e})=>(0,G.jsxs)(q,{cli:`ork run <workflow>`,"data-run-workflow":``,onClick:e,variant:`primary`,children:[(0,G.jsx)(Gv,{}),`Run workflow`]}),xz=({filtered:e})=>e?(0,G.jsx)(CC,{cli:`ork ps`,title:`No runs in this project.`,children:`Among the newest 50. For older ones:`}):(0,G.jsx)(CC,{cli:`ork run <workflow>`,title:`No runs yet.`,children:`Start one with Run workflow, or in a terminal:`}),Sz={panel:`_panel_1mlu0_7`,tools:`_tools_1mlu0_22`,main:`_main_1mlu0_38`,refused:`_refused_1mlu0_50`,list:`_list_1mlu0_60`,item:`_item_1mlu0_66`,title:`_title_1mlu0_90`,meta:`_meta_1mlu0_103`,unread:`_unread_1mlu0_121`,actions:`_actions_1mlu0_127`},Cz=({item:e})=>{let t=qy(),n=(0,V.use)(ZM);return(0,G.jsxs)(`li`,{className:Sz.item,"data-notification":e.id,"data-unread":e.unread?``:void 0,children:[(0,G.jsx)(`p`,{className:Sz.title,children:e.title}),(0,G.jsxs)(`p`,{className:Sz.meta,children:[(0,G.jsx)(bD,{status:e.status}),(0,G.jsx)(`span`,{children:_z(e.at)}),e.unread?(0,G.jsx)(`span`,{className:Sz.unread,children:`unread`}):null]}),(0,G.jsxs)(`p`,{className:Sz.actions,children:[(0,G.jsx)(q,{"aria-label":`Open: ${e.title}`,onClick:()=>{t.notifications.markRead(e.id),t.selectRun(e.runId),e.node!==void 0&&t.selectNode(e.node),n?.goTo(e.kind===`decision`?`decisions`:`monitor`)},variant:`ghost`,children:`Open`}),(0,G.jsx)(q,{"aria-label":`Mark read: ${e.title}`,disabled:!e.unread,focusableWhenDisabled:!0,onClick:()=>{t.notifications.markRead(e.id)},variant:`ghost`,children:`Mark read`})]})]})},wz={denied:`The browser refused. Allow notifications for this page in its settings.`,unsupported:`This browser has no desktop notifications.`},Tz=()=>{let{notifications:e,preferences:t}=qy(),{items:n,unread:r}=ab(e.view),{desktopNotifications:i}=ab(t.value),[a,o]=(0,V.useState)(null),{panel:s,onFocus:c}=rL(n.map(({id:e})=>e).join(`
69
69
  `),`[data-notification]`),l=async e=>{if(o(null),!e){t.update({desktopNotifications:!1});return}let n=await mz();n===`granted`?t.update({desktopNotifications:!0}):o(wz[n])};return(0,G.jsxs)(`div`,{"aria-label":`Notifications`,className:Sz.panel,onFocus:c,ref:s,role:`group`,tabIndex:-1,children:[(0,G.jsxs)(`div`,{className:Sz.tools,children:[(0,G.jsx)(JC,{checked:i,label:`Desktop notifications`,onChange:e=>{l(e)}}),(0,G.jsx)(q,{disabled:r===0,focusableWhenDisabled:!0,onClick:e.markAllRead,variant:`ghost`,children:`Mark all read`})]}),(0,G.jsxs)(`div`,{className:Sz.main,children:[a===null?null:(0,G.jsx)(`p`,{className:Sz.refused,role:`alert`,children:a}),n.length===0?(0,G.jsx)(CC,{title:`Nothing yet.`,children:`Decisions, and runs that end, crash or pause, land here.`}):(0,G.jsx)(`ul`,{className:Sz.list,children:n.map(e=>(0,G.jsx)(Cz,{item:e},e.id))})]})]})},Ez=e=>e.split(`/`).at(-1)??e,Dz=e=>e.split(`/`).slice(-2).join(`/`),Oz=(e,t)=>{let n=new Map(e.map(({root:e,id:t})=>[e,t]));for(let{project:e}of t)n.has(e)||n.set(e,Ez(e));let r=[...n.values()],i=e=>r.indexOf(e)!==r.lastIndexOf(e);return[{value:`all`,label:`All projects`},...[...n].map(([e,t])=>({value:e,label:i(t)?Dz(e):t})).toSorted((e,t)=>e.label.localeCompare(t.label))]},kz=e=>e.status===`ready`?{data:e.data,arg:e.arg}:e.status===`idle`?void 0:e.shown,Az=e=>{let t=Yy.create({status:`idle`}),n=0;return{state:t,load:async r=>{n+=1;let i=n,a=kz(t.getValue());t.setValue({status:`loading`,arg:r,...a===void 0?{}:{shown:a}});let o=await e(r);i===n&&t.setValue(o.ok?{status:`ready`,arg:r,data:o.data}:{status:`failed`,arg:r,error:o.error,...a===void 0?{}:{shown:a}})}}},jz=3e4,Mz={live:`Live`,new:`Off: new, not accepted yet`,changed:`Off: changed since it was accepted`,invalid:`Off: it has an error`},Nz={new:`ork watch --accept`,changed:`ork watch --accept`,invalid:`ork validate`},Pz=e=>new Date(e).toLocaleTimeString(void 0,{timeStyle:`short`}),Fz=e=>[Mz[e.standing],...e.lookedAt===void 0?[]:[`Last looked ${Pz(e.lookedAt)}`],...e.error===void 0?[]:[`Last look failed: ${e.error}`],...e.held===void 0?[]:[`Waiting: ${e.held}`]],Iz=()=>{let{triggers:e}=qy(),t=ab(e.state);(0,V.useEffect)(()=>{e.load();let t=setInterval(()=>{e.load()},jz);return()=>{clearInterval(t)}},[e]);let n=kz(t)?.data;return n===void 0||n.triggers.length===0?null:(0,G.jsxs)(`section`,{"aria-label":`Triggers`,className:Ww.triggers,children:[(0,G.jsx)(`h3`,{className:Ww.triggersTitle,children:`Triggers`}),n.pid===void 0?(0,G.jsxs)(`p`,{className:Ww.note,children:[(0,G.jsx)(`code`,{children:`ork watch`}),` isn't running, so nothing is looking.`]}):null,(0,G.jsx)(`ul`,{className:Ww.triggerList,children:n.triggers.map(e=>(0,G.jsxs)(`li`,{children:[(0,G.jsx)(`span`,{className:Ww.triggerName,children:e.trigger}),` starts `,(0,G.jsx)(`code`,{children:e.run}),`, every ${e.every}`,Fz(e).map(e=>(0,G.jsx)(`span`,{className:Ww.triggerLine,children:(0,G.jsx)(Wg,{text:e})},e)),Nz[e.standing]===void 0?null:(0,G.jsx)(`span`,{className:Ww.triggerCommand,children:(0,G.jsx)(YS,{command:Nz[e.standing]??``})})]},`${e.project}/${e.trigger}`))})]})},Lz=e=>ib(e.decisions,e=>new Set((e??[]).map(({runId:e})=>e))),Rz=e=>{let t=ab(e.projects.state);return(0,V.useEffect)(()=>{e.projects.load()},[e]),t.status===`ready`?t.data:[]},zz=e=>{let t=[...e.currentTarget.querySelectorAll(`button`)],n=t.findIndex(e=>e===document.activeElement),r=t.length-1,i={ArrowDown:Math.min(n+1,r),ArrowUp:Math.max(n-1,0),Home:0,End:r}[e.key];i!==void 0&&(e.preventDefault(),t[i]?.focus())},Bz=()=>{let e=qy(),t=ab(e.runs),n=ab(e.runFilter),r=ib(e.selection,({run:e})=>e),i=Lz(e),a=Rz(e),o=(0,V.useMemo)(()=>t??[],[t]),s=(0,V.useMemo)(()=>Oz(a,o),[a,o]),c=(0,V.useMemo)(()=>n===`all`?o:o.filter(e=>e.project===n),[o,n]),l=c.some(({id:e})=>e===r)?r:c[0]?.id;return(0,G.jsxs)(`div`,{className:Ww.panel,children:[(0,G.jsxs)(`div`,{className:Ww.tools,children:[(0,G.jsx)(Bw,{label:`Project`,onChange:t=>{e.runFilter.setValue(t)},options:s,value:n}),(0,G.jsx)(bz,{onClick:()=>{e.runDialog.setValue(!0)}})]}),(0,G.jsx)(`div`,{className:Ww.main,children:t===null?(0,G.jsx)(`p`,{className:Ww.note,children:`Reading runs…`}):c.length===0?(0,G.jsx)(xz,{filtered:n!==`all`}):(0,G.jsx)(`ul`,{"aria-label":`Runs`,className:Ww.list,onKeyDown:zz,children:c.map(t=>(0,G.jsx)(yz,{onSelect:e.selectRun,run:t,selected:t.id===r,tabStop:t.id===l,waiting:i.has(t.id)},t.id))})}),(0,G.jsx)(Iz,{})]})},Vz=e=>e.toLocaleString(`en`),Hz=e=>`≈${Vz(e)}`,Uz=e=>{let t=e.trim(),n=/^[a-z]+\s/u.test(t)?`${t.charAt(0).toUpperCase()}${t.slice(1)}`:t;return n===``||/[.!?…]$/u.test(n)?n:`${n}.`},Wz=e=>e.reduce((e,t)=>e+(t.tokens??0),0),Gz=e=>{let t=e.filter(e=>e.state===`live`).length,n=e.length-t;return n===0?`${Vz(t)} live`:`${Vz(t)} live, ${Vz(n)} off`},Kz=(e,t,n=0)=>{let r=`${t(e.length)} · ${Hz(Wz(e))}`;return n===0?r:`${r}, ${Vz(n)} off`},qz=e=>`${Vz(e)} ${e===1?`file`:`files`}`,Jz=e=>`${Vz(e)} live`,Yz=e=>{let t=e.agent===void 0?[]:[{key:`agent/${e.agent.name}`,name:e.agent.name,source:e.agent.where,tokens:e.agent.tokens,text:e.agent.text??``,place:e.agent.where}],n=(e.instructionFiles??[]).map(e=>({key:`instructions/${e.name}`,name:e.name,tokens:e.tokens,text:e.text,place:e.name})),r=e.skills.map(e=>({key:`skill/${e.layer}/${e.name}`,name:e.name,state:e.state,layer:e.layer,source:e.source,tokens:e.tokens,...e.why===void 0?{}:{why:e.why},text:e.text??``,place:e.source===`built-in`?`built-in`:`${e.source}/SKILL.md`})),i=e.files.map((e,t)=>({key:`file/${e.layer}/${e.name}/${String(t)}`,name:e.name,layer:e.layer,tokens:e.tokens,text:e.text??``,place:e.name,...e.cutFrom===void 0?{}:{why:`cut at the lessons cap a session loads; the whole file is about ${Vz(e.cutFrom)} tokens`}})),a=[...e.practices.map(e=>({key:`practice/${e.name}`,name:e.name,state:`live`,tokens:e.tokens,text:e.text??``,place:`practice: ${e.name}`})),...e.skippedPractices.map(e=>({key:`practice/${e}`,name:e,state:`off`,why:`The project's own skill wins.`}))];return[{id:`agent`,title:`Agent`,meta:Hz(Wz(t)),empty:`No agent fills this node.`,pieces:t},{id:`instructions`,title:`Project instructions`,meta:Hz(Wz(n)),description:`Claude Code reads these itself; they aren't appended.`,empty:Uz(e.instructions),pieces:n},{id:`skills`,title:`Skills`,meta:r.length===0?`none`:Gz(r),description:`A skill's SKILL.md loads only when the session uses it.`,empty:`No skills.`,pieces:r},{id:`files`,title:`Context files`,meta:Kz(i,qz),empty:`No context files.`,pieces:i},{id:`practices`,title:`Practices`,meta:Kz(a.filter(e=>e.state===`live`),Jz,e.skippedPractices.length),empty:`No practices.`,pieces:a},{id:`appended`,title:`Appended system prompt`,meta:Hz(e.appendedTokens),description:"Everything Ork adds to Claude Code's system prompt, in the order the session reads it: the agent's role, the context files and practices above, Ork's own instructions to the node, and the node's `instructions`.",empty:`Nothing is appended.`,pieces:[{key:`appended`,name:`The whole prompt`,tokens:e.appendedTokens,text:e.appended??``,place:`system prompt, appended`}]}]},Xz=(e,t)=>t?`Couldn't update: ${Uz(e)} This is the answer from before.`:`Couldn't read the context: ${Uz(e)}`,Zz=e=>e===``?0:e.replace(/\n$/u,``).split(`
70
- `).length,Qz=(e,t)=>{let n=t.endsWith(`/`)?t:`${t}/`;return e.startsWith(n)?e.slice(n.length):e},$z=(e,t)=>`ork context explain ${e} ${t}`,eB={host:`_host_tnhom_9`,panel:`_panel_tnhom_17`,header:`_header_tnhom_36`,card:`_card_tnhom_37`,foot:`_foot_tnhom_38`,facts:`_facts_tnhom_54`,fact:`_fact_tnhom_54`,factName:`_factName_tnhom_71`,factValue:`_factValue_tnhom_85`,title:`_title_tnhom_95`,plannedLine:`_plannedLine_tnhom_107`,planned:`_planned_tnhom_107`,description:`_description_tnhom_117`,why:`_why_tnhom_118`,emptyText:`_emptyText_tnhom_119`,updating:`_updating_tnhom_132`,cardTitle:`_cardTitle_tnhom_142`,notice:`_notice_tnhom_151`,noticeIcon:`_noticeIcon_tnhom_174`,noticeWords:`_noticeWords_tnhom_190`,stack:`_stack_tnhom_194`,section:`_section_tnhom_203`,sectionHead:`_sectionHead_tnhom_219`,sectionNote:`_sectionNote_tnhom_230`,heading:`_heading_tnhom_241`,meta:`_meta_tnhom_251`,layer:`_layer_tnhom_252`,source:`_source_tnhom_253`,tokens:`_tokens_tnhom_254`,state:`_state_tnhom_255`,list:`_list_tnhom_266`,item:`_item_tnhom_272`,row:`_row_tnhom_281`,details:`_details_tnhom_318`,toggle:`_toggle_tnhom_341`,mark:`_mark_tnhom_342`,name:`_name_tnhom_365`,visuallyHidden:`_visuallyHidden_tnhom_426`,well:`_well_tnhom_437`,wellBar:`_wellBar_tnhom_449`,wellPlace:`_wellPlace_tnhom_466`,wellCopy:`_wellCopy_tnhom_473`,copied:`_copied_tnhom_482`,text:`_text_tnhom_488`},tB=({text:e})=>e.split(`≈`).map((e,t)=>t===0?e:(0,G.jsxs)(`span`,{children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,children:`≈`}),(0,G.jsx)(`span`,{className:eB.visuallyHidden,children:`about `}),e]},t)),nB=({name:e,value:t})=>(0,G.jsxs)(`div`,{className:eB.fact,children:[(0,G.jsx)(`dt`,{className:eB.factName,children:e}),(0,G.jsx)(`dd`,{className:eB.factValue,children:(0,G.jsx)(tB,{text:t})})]}),rB=({node:e,type:t,from:n,appendedTokens:r,planned:i,reload:a,updating:o,cli:s,onReload:c,titleRef:l,children:u})=>(0,G.jsxs)(`header`,{className:eB.header,children:[(0,G.jsxs)(`dl`,{className:eB.facts,children:[(0,G.jsxs)(`div`,{className:eB.fact,children:[(0,G.jsx)(`dt`,{className:eB.factName,children:`Node`}),(0,G.jsx)(`dd`,{className:eB.factValue,children:(0,G.jsx)(`h2`,{className:eB.title,ref:l,tabIndex:-1,children:e})})]}),t===void 0?null:(0,G.jsx)(nB,{name:`Type`,value:t}),(0,G.jsx)(nB,{name:`From`,value:n}),r===void 0?null:(0,G.jsx)(nB,{name:`Appended`,value:`${Hz(r)} tokens`})]}),(0,G.jsxs)(`div`,{className:eB.plannedLine,children:[i===null?null:(0,G.jsx)(`p`,{className:eB.planned,children:i}),o?(0,G.jsx)(`span`,{className:eB.updating,children:`Updating…`}):null,(0,G.jsx)(q,{cli:s,onClick:c,variant:`ghost`,children:a})]}),u]}),iB=e=>`Changed after this run started: ${e.map(e=>`\`${e}\``).join(`, `)}. The run may have read ${e.length===1?`an older version`:`older versions`}.`,aB=({answer:e,error:t})=>{let n=e?.changedSinceStart??[],r=e?.planned===!0?e.explanation:null;return(0,G.jsxs)(G.Fragment,{children:[n.length===0?null:(0,G.jsxs)(`p`,{className:eB.notice,"data-note":`changed`,children:[(0,G.jsx)(`span`,{className:eB.noticeIcon,children:(0,G.jsx)(yy,{})}),(0,G.jsx)(`span`,{className:eB.noticeWords,children:(0,G.jsx)(Wg,{text:iB(n)})})]}),r?.template===void 0?null:(0,G.jsx)(`p`,{className:eB.notice,"data-note":`spawned`,children:(0,G.jsx)(`span`,{className:eB.noticeWords,children:(0,G.jsx)(Wg,{text:`\`${r.node}\` was spawned during the run, so it's planned as \`${r.template}\`, the node it was spawned from.`})})}),t===null?null:(0,G.jsxs)(`p`,{className:eB.notice,"data-note":`failed`,children:[(0,G.jsx)(`span`,{className:eB.noticeIcon,children:(0,G.jsx)(cD,{})}),(0,G.jsx)(`span`,{className:eB.noticeWords,children:(0,G.jsx)(Wg,{text:Xz(t,e!==null)})})]})]})},oB=({why:e})=>(0,G.jsxs)(`div`,{className:eB.card,children:[(0,G.jsx)(`p`,{className:eB.cardTitle,children:`No context to show.`}),(0,G.jsx)(`p`,{className:eB.description,children:(0,G.jsx)(Wg,{text:Uz(e)})})]}),sB=({cli:e,draft:t,sized:n})=>(0,G.jsxs)(`footer`,{className:eB.foot,children:[t?(0,G.jsx)(`p`,{className:eB.description,children:`The CLI reads the saved file, not the draft.`}):null,(0,G.jsx)(YS,{command:e}),n?(0,G.jsx)(`p`,{className:eB.description,children:`Tokens are estimates, about four characters each.`}):null]}),cB=({target:e})=>e?.kind===`run`?(0,G.jsx)(CC,{title:`No node chosen in this run.`,children:`Choose one in the Monitor, Logs or Chats.`}):e?.kind===`builder`?(0,G.jsx)(CC,{title:`No node selected in the Builder.`,children:`Select a card to see what its session loads.`}):(0,G.jsx)(CC,{cli:`ork context explain <workflow> <node>`,title:`No node chosen.`,children:`Choose one in the Monitor or the Builder, or in a terminal:`}),lB=({words:e,more:t})=>{let n=`${e}${t?`, `:``}`;return n===``?null:(0,G.jsx)(`span`,{className:eB.visuallyHidden,children:n})},uB=({piece:e})=>{let t=[e.state,e.layer,e.source,e.tokens],n=e=>t.slice(e).some(e=>e!==void 0),r=e.state!==void 0||e.layer!==void 0||e.source!==void 0;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:eB.mark,"data-state":e.state,children:e.state===void 0?null:e.state===`live`?(0,G.jsx)(Yv,{}):(0,G.jsx)(Iy,{})}),(0,G.jsxs)(`span`,{className:eB.name,children:[e.name,(0,G.jsx)(lB,{more:n(0),words:``})]}),r?(0,G.jsxs)(`span`,{className:eB.details,children:[e.state===void 0?null:(0,G.jsxs)(`span`,{className:eB.state,children:[e.state,(0,G.jsx)(lB,{more:n(1),words:``})]}),e.layer===void 0?null:(0,G.jsxs)(`span`,{className:eB.layer,children:[e.layer,(0,G.jsx)(lB,{more:n(2),words:` layer`})]}),e.source===void 0?null:(0,G.jsxs)(`span`,{className:eB.source,children:[e.source,(0,G.jsx)(lB,{more:n(3),words:``})]})]}):null,e.tokens===void 0?null:(0,G.jsxs)(`span`,{className:eB.tokens,children:[(0,G.jsx)(tB,{text:Hz(e.tokens)}),(0,G.jsx)(lB,{more:!1,words:` tokens`})]})]})},dB=({piece:e,id:t})=>{let n=e.text??``,r=Zz(n);return(0,G.jsxs)(`div`,{className:eB.well,id:t,children:[(0,G.jsxs)(`div`,{className:eB.wellBar,children:[(0,G.jsx)(`span`,{className:eB.wellPlace,children:e.place}),(0,G.jsx)(`span`,{children:(0,G.jsx)(tB,{text:`${r.toLocaleString(`en`)} ${r===1?`line`:`lines`}${e.tokens===void 0?``:` · ${Hz(e.tokens)} tokens`}`})}),(0,G.jsx)(`span`,{className:eB.wellCopy,children:(0,G.jsx)(qS,{label:`Copy the text of ${e.name}`,resultClass:eB.copied,text:n})})]}),n===``?(0,G.jsx)(`p`,{className:eB.emptyText,children:e.key===`appended`?`Nothing is appended.`:`This file is empty.`}):(0,G.jsx)(`pre`,{className:eB.text,children:n})]})},fB=({piece:e,open:t,onToggle:n})=>{let r=(0,V.useId)(),i=`${r}-why`,a=`${r}-text`,o=e.state??`live`,s=e.why===void 0?null:(0,G.jsx)(`p`,{className:eB.why,id:i,children:(0,G.jsx)(Wg,{text:Uz(e.why)})});return e.text===void 0?(0,G.jsxs)(`li`,{className:eB.item,children:[(0,G.jsxs)(`div`,{className:eB.row,"data-state":o,children:[(0,G.jsx)(`span`,{className:eB.toggle}),(0,G.jsx)(uB,{piece:e})]}),s]}):(0,G.jsxs)(`li`,{className:eB.item,children:[(0,G.jsxs)(`button`,{"aria-controls":t?a:void 0,"aria-describedby":e.why===void 0?void 0:i,"aria-expanded":t,className:eB.row,"data-piece":e.key,"data-state":o,onClick:()=>{n(e.key)},type:`button`,children:[(0,G.jsx)(`span`,{className:eB.toggle,children:t?(0,G.jsx)(Xv,{}):(0,G.jsx)(Zv,{})}),(0,G.jsx)(uB,{piece:e})]}),s,t?(0,G.jsx)(dB,{id:a,piece:e}):null]})},pB=({sections:e,opened:t,onToggle:n,busy:r})=>(0,G.jsx)(`div`,{"aria-busy":r,className:eB.stack,children:e.map(e=>(0,G.jsxs)(`section`,{className:eB.section,children:[(0,G.jsxs)(`div`,{className:eB.sectionHead,children:[(0,G.jsx)(`h3`,{className:eB.heading,children:e.title}),(0,G.jsx)(`span`,{className:eB.meta,children:(0,G.jsx)(tB,{text:e.meta})})]}),e.description===void 0?null:(0,G.jsx)(`p`,{className:eB.sectionNote,children:(0,G.jsx)(Wg,{text:e.description})}),e.pieces.length===0?(0,G.jsx)(`p`,{className:eB.sectionNote,children:(0,G.jsx)(Wg,{text:e.empty})}):(0,G.jsx)(`ul`,{className:eB.list,children:e.pieces.map(e=>(0,G.jsx)(fB,{onToggle:n,open:t.has(e.key),piece:e},e.key))})]},e.id))}),mB=e=>e.kind===`run`?`run/${e.run}/${e.node}`:`builder/${e.project}/${e.workflow}/${e.node}`,hB={answer:null,error:null,loading:!0},gB=e=>{let{client:t}=qy(),n=(0,V.use)(ZM),[r,i]=(0,V.useState)(hB),a=(0,V.useRef)(!1);a.current=r.answer!==null;let[o,s]=(0,V.useState)(0),c=e.kind===`builder`?e.revision:0,l=mB(e);(0,V.useEffect)(()=>{let r=!0;i(e=>({...e,loading:!0}));let o=e.kind===`run`?t.call(`runContext`,{params:{id:e.run,node:e.node}}):t.call(`builderContext`,{params:{id:e.project,name:e.workflow,node:e.node}});return(async()=>{let e=await o;r&&(e.ok||n?.announce(Xz(e.error,a.current)),i(t=>e.ok?{answer:e.data,error:null,loading:!1}:{answer:t.answer,error:e.error,loading:!1}))})(),()=>{r=!1}},[t,n,l,c,o]);let u=(0,V.useCallback)(()=>{s(e=>e+1)},[]);return{...r,reload:u}},_B=e=>{let t=ab(qy().runs);if(e.kind===`builder`)return{from:`Builder · ${e.workflow}${e.draft?` · draft`:``}`,cli:$z(e.workflow,e.node),planned:e.draft?`Planned from the unsaved draft. It updates after each edit.`:`Planned from the saved file.`};let n=t?.find(({id:t})=>t===e.run);return{from:n===void 0?e.run:`${n.workflow} · ${e.run}`,cli:$z(n===void 0?`<workflow>`:Qz(n.file,n.project),e.node),planned:`Planned from the project's files as they are now.`}},vB=({target:e,hadFocus:t})=>{let{answer:n,error:r,loading:i,reload:a}=gB(e),o=_B(e),[s,c]=(0,V.useState)(new Set),l=(0,V.useRef)(null),u=(0,V.useRef)(null),d=(0,V.useCallback)(e=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),f=n?.planned===!0?n.explanation:null,p=(0,V.useMemo)(()=>f===null?[]:Yz(f),[f]),m=n===null?r===null?`loading`:`failed`:`shown`,h=(0,V.useRef)(null);return(0,V.useEffect)(()=>{let e=document.activeElement,n=e!==null&&l.current?.contains(e)===!0,r=(e===null||e===document.body)&&t.current,i=h.current!==m;h.current=m,(r||i&&n)&&u.current?.focus()},[m,n]),(0,G.jsxs)(`div`,{className:eB.panel,ref:l,children:[(0,G.jsx)(rB,{appendedTokens:f?.appendedTokens,cli:o.cli,from:o.from,node:e.node,onReload:a,planned:n?.planned===!1?null:o.planned,reload:r===null?`Reload`:`Try again`,titleRef:u,type:f?.type,updating:i&&n!==null,children:(0,G.jsx)(aB,{answer:n,error:r})}),n?.planned===!1?(0,G.jsx)(oB,{why:n.why}):null,f===null?null:(0,G.jsx)(pB,{busy:i,onToggle:d,opened:s,sections:p}),n===null&&r===null?(0,G.jsx)(`p`,{"aria-busy":`true`,className:eB.card,children:(0,G.jsx)(`span`,{className:eB.description,children:`Planning ${e.node}…`})}):null,m===`loading`?null:(0,G.jsx)(sB,{cli:o.cli,draft:e.kind===`builder`&&e.draft,sized:f!==null})]})},yB=({target:e,hadFocus:t})=>{let n=(0,V.useRef)(null);return(0,V.useEffect)(()=>{let e=document.activeElement;(e===null||e===document.body)&&t.current&&n.current?.focus()},[t]),(0,G.jsx)(`div`,{ref:n,tabIndex:-1,children:(0,G.jsx)(cB,{target:e})})},bB=({target:e,hadFocus:t})=>{if(e===null||e.node===null)return(0,G.jsx)(yB,{hadFocus:t,target:e});let n={...e,node:e.node};return(0,G.jsx)(vB,{hadFocus:t,target:n},mB(n))},xB=()=>{let e=ab(qy().contextTarget),t=(0,V.useRef)(!1);return(0,G.jsx)(`div`,{className:eB.host,onBlur:e=>{let n=e.relatedTarget;(n instanceof Node?!e.currentTarget.contains(n):e.target.isConnected)&&(t.current=!1)},onFocus:()=>{t.current=!0},children:(0,G.jsx)(bB,{hadFocus:t,target:e})})},SB=e=>e.slice(0,12),CB=[[`open`,`Not dismissed`],[`all`,`All`],[`new`,`New`],[`triaged`,`Triaged`],[`accepted`,`Accepted`],[`resolved`,`Resolved`],[`published`,`Published`],[`dismissed`,`Dismissed`]],wB=[{value:`all`,label:`All`},{value:`ork`,label:`ork`},{value:`workflow`,label:`workflow`},{value:`project`,label:`project`}],TB=(e,t)=>t===`all`?!0:t===`open`?e.status!==`dismissed`:e.status===t,EB=e=>CB.map(([t,n])=>({value:t,label:`${n} · ${String(e.filter(e=>TB(e,t)).length)}`})),DB=(e,{status:t,about:n})=>e.filter(e=>TB(e,t)&&(n===`all`||e.target===n)),OB=(e,t,n)=>e===1?`1 ${t}`:`${e.toLocaleString(`en`)} ${n}`,kB=e=>OB(e,`item`,`items`),AB=e=>OB(e,`time`,`times`),jB=e=>OB(e,`run`,`runs`),MB={open:`No items`,all:`No items`,new:`No new items`,triaged:`No triaged items`,accepted:`No accepted items`,resolved:`Nothing resolved`,published:`Nothing published`,dismissed:`Nothing dismissed`},NB=({status:e,about:t})=>{let n=MB[e]??`No items`,r=e===`open`&&t===`all`?`Every item is dismissed.`:`${n}${t===`all`?``:` about ${t}`}.`,i=[e===`all`?[]:[`Status: All`],t===`all`?[]:[`About: All`]].flat();return{title:r,body:`${i.join(` and `)} ${i.length>1?`show`:`shows`} every item.`}},PB=(e,t,n)=>{let r=e.findIndex(({id:e})=>e===n),i=t.filter(({id:e})=>e!==n);return i[Math.min(Math.max(r,0),i.length-1)]},FB=(e,t)=>e.find(e=>e.merged.includes(t)),IB={ok:!1,why:`reading what it allows`},LB=(e,...t)=>{if(!e.ok)return{ok:!1,why:e.why};let n=t.find(e=>e!==void 0);return n===void 0?{ok:!0}:{ok:!1,why:n}},RB=e=>{let t=e.lessons,[n]=t;return t.every(e=>!e.ok)&&n!==void 0&&!n.ok?n.error:void 0},zB=(e,t)=>{let n=SB(e.id),r=e=>{if(t===null)return IB;let{actions:n,project:r}=t;return e===`lesson`?LB(n.lesson,RB(t)):e===`apply`?LB(n.apply,r.ok?void 0:r.error):LB(n[e])},i={key:`accept`,word:`Accept`,cli:`ork feedback accept ${n}`,variant:`default`,check:r(`accept`)};return e.target===`ork`?[i,{key:`publish`,word:`Publish…`,cli:`ork feedback publish ${n}`,variant:`primary`,check:r(`publish`)}]:[i,{key:`lesson`,word:`Add lesson…`,cli:`ork feedback accept ${n} --lesson`,variant:`default`,check:r(`lesson`)},{key:`apply`,word:`Propose fix…`,cli:`ork feedback apply ${n}`,variant:`primary`,check:r(`apply`)}]},BB=(e,t)=>t.ok?e:`${e}: ${t.why}`,VB=e=>`Starts a run of \`ork:feedback-apply\` in \`${e}\`. It's a paid run, like any you start. A worker reads this item and that project's records of it, and Ork commits the smallest change that would stop it on a branch of its own, in a worktree. The worker reads and edits files and runs no commands. Then you're asked to keep or discard the branch, in Decisions.`,HB=({item:e,id:t,root:n,acts:r,open:i,onOpenChange:a})=>{let[o,s]=(0,V.useState)(``),c=(0,V.useRef)(!1);return(0,G.jsx)(SC,{cli:`ork feedback apply ${t}${o===``?``:` --driver ${o}`}`,confirm:`Start run`,description:VB(n??`its project`),finalFocus:()=>{let e=c.current;return c.current=!1,!e},onConfirm:async()=>{let t=await r.apply(e,o);return c.current=t===null,t},onOpenChange:a,open:i,pending:`Starting…`,title:`Propose a fix for ${t}?`,variant:`primary`,children:(0,G.jsx)(qw,{onChange:s,value:o})})},UB=(e,t)=>`about ${e.toLocaleString(`en`)} of ${t.toLocaleString(`en`)} tokens`,WB=(e,t,n)=>[`ork feedback accept ${SB(e.id)} --lesson`,...t===null||e.workflows.length<2?[]:[`--workflow ${sT(t)}`],...n===e.title||n.trim()===``?[]:[`-m ${sT(n)}`]].join(` `),GB=(e,t,n)=>e===null?`Choose a workflow.`:t.trim()===``?`Write the lesson first.`:n!==void 0&&!n.ok?n.error:null,KB=({place:e,cap:t})=>e.ok?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`p`,{className:J.place,children:[(0,G.jsx)(`span`,{className:J.caption,children:`Goes to `}),(0,G.jsx)(Wg,{text:`\`${e.file}\` in \`${e.root}\``})]}),(0,G.jsx)(ez,{label:`Now`,max:t,text:e.exists?UB(e.tokens,t):`no lessons file yet; this starts it`,value:e.tokens})]}):(0,G.jsx)(`p`,{className:J.note,children:(0,G.jsx)(Wg,{text:e.error})}),qB=({open:e,onOpenChange:t,item:n,detail:r,onAdd:i})=>{let a=n.workflows.length>1,[o,s]=(0,V.useState)(a?null:n.workflows[0]??null),[c,l]=(0,V.useState)(n.title),[u,d]=(0,V.useState)(!1),[f,p]=(0,V.useState)(null),m=(0,V.useId)(),h=r.lessons.find(e=>e.workflow===o),g=GB(o,c,h),_=async()=>{if(g!==null||u)return;d(!0),p(null);let e=await i({lesson:!0,...c===n.title?{}:{text:c},...a&&o!==null?{workflow:o}:{}});d(!1),p(e),e===null&&t(!1)};return(0,G.jsx)(bC,{description:o===null?`Every later session of the workflow you choose reads it, in the workflow layer of its context.`:`Every later session of \`${o}\` reads it, in the workflow layer of its context.`,onOpenChange:e=>{u||t(e)},open:e,title:o===null?`Add a lesson`:`Add a lesson for \`${o}\``,children:(0,G.jsxs)(QL,{onSend:()=>{_()},children:[a?(0,G.jsx)(Bw,{label:`Workflow (required)`,onChange:e=>{s(e===``?null:e)},options:[{value:``,label:`Choose one`},...n.workflows.map(e=>({value:e,label:e}))],value:o??``}):null,(0,G.jsx)(Uw,{description:`Its first line is the entry; later lines sit under it.`,label:`Lesson`,multiline:!0,onChange:l,required:!0,value:c}),h===void 0?null:(0,G.jsx)(KB,{cap:r.lessonCap,place:h}),(0,G.jsx)(YS,{command:WB(n,o,c)}),(0,G.jsx)($L,{id:m,why:g}),(0,G.jsx)(eR,{text:f}),(0,G.jsxs)(xC,{children:[(0,G.jsx)(q,{disabled:u,onClick:()=>{t(!1)},type:`button`,variant:`ghost`,children:`Cancel`}),(0,G.jsx)(q,{"aria-describedby":m,"aria-keyshortcuts":ZL,disabled:g!==null||u,focusableWhenDisabled:!0,type:`submit`,variant:`primary`,children:u?`Adding…`:`Add lesson`})]})]})})},JB={slot:`_slot_17gek_6`,alert:`_alert_17gek_17`},YB=({id:e,words:t,takeFocus:n,onTryAgain:r})=>{let i=(0,V.useRef)(null);return(0,V.useEffect)(()=>{if(t===null)return;let e=document.activeElement,r=e===null||e===document.body||e.getAttribute(`aria-disabled`)===`true`;(n===`always`||r)&&i.current?.querySelector(`button`)?.focus()},[t,n]),(0,G.jsxs)(`div`,{className:JB.slot,ref:i,children:[(0,G.jsx)(`p`,{className:JB.alert,id:e,role:`alert`,children:t===null?null:(0,G.jsx)(Wg,{text:t})}),t===null||r===void 0?null:(0,G.jsx)(q,{onClick:r,variant:`ghost`,children:`Try again`})]})},XB=({url:e})=>(0,G.jsxs)(`a`,{className:J.link,href:e,rel:`noreferrer`,target:`_blank`,children:[e,(0,G.jsx)(Sy,{}),(0,G.jsx)(zw,{children:` (opens in a new tab)`})]}),ZB=({preview:e})=>e.plan.kind===`create`?(0,G.jsx)(`p`,{className:J.message,children:(0,G.jsx)(Wg,{text:`A new thread in the Agent feedback category of \`${e.repo}\`.`})}):(0,G.jsxs)(`p`,{className:J.message,children:[`A thread for this exists, so this goes on it as a +1 comment:`,` `,(0,G.jsx)(XB,{url:e.plan.url})]}),QB="Reading Ork's Discussions with your `gh`…",$B=`Nothing to show: the preview couldn't be read.`,eV=({id:e})=>(0,G.jsx)(`span`,{className:J.note,id:e,children:`From the last read`}),tV=({preview:e,reading:t,region:n,stale:r,staleId:i})=>{let a=e?.plan.kind!==`comment`,o=e===void 0?``:a?e.post.body:e.post.comment,s=a?`Body`:`Comment`,c=r&&e!==void 0;return(0,G.jsxs)(G.Fragment,{children:[e===void 0||!a?null:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:J.line,children:[(0,G.jsx)(`p`,{className:J.caption,children:`Title`}),c?(0,G.jsx)(eV,{}):null]}),(0,G.jsx)(`p`,{className:J.preview,"data-stale":r?``:void 0,children:e.post.title})]}),(0,G.jsxs)(`div`,{className:J.wellHead,children:[(0,G.jsxs)(`div`,{className:J.line,children:[(0,G.jsx)(`p`,{className:J.caption,children:s}),c?(0,G.jsx)(eV,{id:i}):null]}),o===``?null:(0,G.jsx)(`span`,{className:J.wellCopy,children:(0,G.jsx)(qS,{label:`Copy the ${s.toLowerCase()}`,text:o})})]}),(0,G.jsx)(`section`,{"aria-busy":t,"aria-describedby":c?i:void 0,"aria-label":`Text to post`,className:J.preview,"data-scrolls":``,"data-stale":r?``:void 0,ref:n,tabIndex:0,children:o===``?(0,G.jsx)(Wg,{text:t?QB:$B}):o}),(0,G.jsx)(`p`,{className:J.note,children:`This is the Markdown that is sent, as it is. Secrets, your projects' paths, your home folder, emails, host names and IP addresses are taken out.`})]})},nV=({children:e})=>(0,G.jsxs)(`div`,{className:J.dialogFoot,children:[(0,G.jsx)(`p`,{className:J.note,children:(0,G.jsx)(Wg,{text:"It posts with your own `gh` login."})}),(0,G.jsx)(`div`,{className:J.actions,children:e})]}),rV=({id:e})=>(0,G.jsx)(`p`,{className:J.note,id:e,children:(0,G.jsx)(Wg,{text:"Your workflows' and projects' folders' names become `<name>`."})}),iV=({id:e,url:t,kind:n,onClose:r})=>{let i=(0,V.useRef)(null);return(0,V.useEffect)(()=>{i.current?.focus()},[]),(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`h3`,{className:J.result,ref:i,tabIndex:-1,children:n===`created`?`Posted`:`Added a +1`}),(0,G.jsx)(`p`,{className:J.message,children:(0,G.jsx)(XB,{url:t})}),(0,G.jsx)(`p`,{className:J.message,children:`${e} is published.`}),(0,G.jsx)(`div`,{className:J.actions,children:(0,G.jsx)(q,{onClick:r,children:`Close`})})]})},aV=e=>e.step===`reading`||e.step===`readFailed`?e.shown:`preview`in e?e.preview:void 0,oV=e=>e.step===`reading`||e.step===`readFailed`,sV=e=>/[.!?]$/u.test(e.trim())?e.trim():`${e.trim()}.`,cV=(e,t,n)=>{let[r,i]=(0,V.useState)(!1),[a,o]=(0,V.useState)({step:`reading`}),s=(0,V.useRef)(0),c=(0,V.useCallback)(async n=>{s.current+=1;let r=s.current,i=await e.call(`publishPreview`,{params:{id:t},body:{hideNames:n}});r===s.current&&o(e=>{if(i.ok)return{step:`preview`,preview:i.data,changed:!1};let t=aV(e);return t===void 0?{step:`readFailed`,error:i.error}:{step:`readFailed`,error:i.error,shown:t}})},[e,t]);(0,V.useEffect)(()=>{c(!1)},[c]);let l=(e,t)=>{o(t===void 0?{step:`reading`}:{step:`reading`,shown:t}),c(e)},u=async i=>{o({step:`posting`,preview:i});let a=await e.call(`publish`,{params:{id:t},body:{hideNames:r,digest:i.digest}});if(a.ok){o({step:`posted`,url:a.data.url,kind:a.data.kind}),n();return}if(a.status!==409){o({step:`postFailed`,preview:i,error:a.error});return}let s=await e.call(`publishPreview`,{params:{id:t},body:{hideNames:r}});s.ok?s.data.digest===i.digest?o({step:`postFailed`,preview:i,error:a.error}):o({step:`preview`,preview:s.data,changed:!0}):o({step:`readFailed`,error:s.error,shown:i})};return{step:a,hideNames:r,setHideNames:e=>{i(e),l(e,aV(a))},tryAgain:()=>{a.step===`postFailed`?u(a.preview):l(r)},post:()=>{a.step===`preview`&&u(a.preview)}}},lV=`The text to post changed since you read it. Read it again before posting.`,uV=e=>e.step===`readFailed`?`Could not read Ork's Discussions: ${sV(e.error)} Nothing was sent.`:e.step===`postFailed`?`Could not post: ${sV(e.error)}`:null,dV=()=>{let e=document.activeElement;return e===null||e===document.body||e.getAttribute(`role`)===`dialog`},fV=e=>e.step===`reading`?`Reading the preview…`:null,pV=({client:e,item:t,id:n,region:r,onStep:i,onClose:a,onPosted:o})=>{let s=cV(e,t,o),{step:c,hideNames:l}=s,u=(0,V.useId)(),d=(0,V.useId)(),f=(0,V.useId)(),p=(0,V.useId)();if((0,V.useEffect)(()=>{i(c),c.step!==`posted`&&dV()&&r.current?.focus()},[c,i,r]),c.step===`posted`)return(0,G.jsx)(iV,{id:n,kind:c.kind,onClose:a,url:c.url});let m=aV(c),h=c.step===`posting`,g=m?.plan.kind===`comment`;return(0,G.jsxs)(G.Fragment,{children:[c.step===`preview`&&c.changed?(0,G.jsx)(`p`,{role:`alert`,children:lV}):null,m===void 0?null:(0,G.jsx)(ZB,{preview:m}),(0,G.jsx)(tV,{preview:m,reading:c.step===`reading`,region:r,stale:oV(c),staleId:p}),(0,G.jsx)(qC,{checked:l,describedBy:u,disabled:h,label:`Hide repository and workflow names`,onChange:s.setHideNames}),(0,G.jsx)(rV,{id:u}),(0,G.jsx)(YS,{command:`ork feedback publish ${n}${l?` --hide-names`:``}`}),(0,G.jsx)(YB,{id:f,onTryAgain:s.tryAgain,takeFocus:c.step===`postFailed`?`always`:`ifLost`,words:uV(c)}),(0,G.jsx)($L,{id:d,why:fV(c)}),(0,G.jsxs)(nV,{children:[(0,G.jsx)(q,{disabled:h,focusableWhenDisabled:!0,onClick:a,variant:`ghost`,children:`Cancel`}),(0,G.jsx)(q,{"aria-describedby":`${d} ${f}`,disabled:c.step!==`preview`,focusableWhenDisabled:!0,onClick:s.post,type:`button`,variant:`primary`,children:h?`Posting…`:g?`Post +1 comment`:`Post thread`})]})]})},mV=({open:e,onOpenChange:t,client:n,item:r,id:i,onPosted:a,onCancelled:o})=>{let s=(0,V.useRef)(null),c=(0,V.useRef)({busy:!1,tried:!1}),l=(0,V.useCallback)(e=>{let t=e.step===`posting`;c.current={busy:t,tried:c.current.tried||t||e.step===`posted`}},[]),u=()=>{c.current.busy||(c.current.tried||o(),c.current={busy:!1,tried:!1},t(!1))};return(0,G.jsx)(bC,{initialFocus:s,onOpenChange:e=>{e?t(!0):u()},open:e,size:`wide`,title:`Publish ${i} to Ork's Discussions`,children:(0,G.jsx)(pV,{client:n,id:i,item:r,onClose:u,onPosted:a,onStep:l,region:s})})},hV=({item:e,detail:t,acts:n})=>{let r=qy(),[i,a]=(0,V.useState)(null),[o,s]=(0,V.useState)(0),c=SB(e.id),l=e.status===`dismissed`,u=e=>{s(e=>e+1),a(e)},d=e=>{e||a(null)},f=t=>{t===`accept`?n.accept(e):u(t===`lesson`?`lesson`:t===`apply`?`apply`:`publish`)};return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{"aria-label":`Actions on ${c}`,className:J.actions,role:`group`,children:[zB(e,t).map(({key:e,word:t,cli:n,variant:r,check:i})=>(0,G.jsx)(q,{"aria-label":BB(t,i),cli:n,disabled:!i.ok,focusableWhenDisabled:!0,onClick:()=>{f(e)},tip:i.ok?void 0:i.why,variant:r,children:t},e)),(0,G.jsx)(q,{cli:`ork feedback ${l?`restore`:`dismiss`} ${c}`,onClick:()=>{n.setStatus(e,l?`new`:`dismissed`)},variant:`ghost`,children:l?`Restore`:`Dismiss`},`status`)]}),e.target===`ork`?(0,G.jsx)(`p`,{className:J.note,children:`About Ork itself: it has no lesson or fix in your projects. Publish shares it with Ork's maintainers.`}):null,t===null?null:(0,G.jsx)(qB,{detail:t,item:e,onAdd:r=>n.addLesson(e,r,t.lessonCap),onOpenChange:d,open:i===`lesson`},`lesson-${String(o)}`),(0,G.jsx)(HB,{acts:n,id:c,item:e,onOpenChange:d,open:i===`apply`,root:t?.project.ok===!0?t.project.root:null},`fix-${String(o)}`),e.target===`ork`?(0,G.jsx)(mV,{client:r.client,id:c,item:e.id,onCancelled:()=>{n.announce(`Nothing was sent.`)},onOpenChange:d,onPosted:()=>{n.reloadAll()},open:i===`publish`},`publish-${String(o)}`):null]})},gV=({name:e,children:t})=>(0,G.jsxs)(`div`,{className:J.fact,children:[(0,G.jsx)(`dt`,{className:J.factName,children:e}),(0,G.jsx)(`dd`,{className:J.factValue,children:t})]}),_V=({name:e,values:t})=>t.length===0?null:(0,G.jsx)(gV,{name:e,children:t.join(`, `)}),vV=({item:e,onSplit:t})=>{let n=SB(e.id);return(0,G.jsxs)(`dl`,{className:J.facts,children:[(0,G.jsx)(gV,{name:`Item`,children:n}),(0,G.jsx)(gV,{name:`About`,children:e.target}),(0,G.jsx)(gV,{name:`Kind`,children:e.kind}),(0,G.jsx)(gV,{name:`Severity`,children:e.severity}),(0,G.jsx)(gV,{name:`Seen`,children:(0,G.jsxs)(`span`,{children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,children:`${String(e.count)}×`}),(0,G.jsx)(zw,{children:AB(e.count)}),` in ${jB(e.runs.length)}`]})}),(0,G.jsx)(gV,{name:`First seen`,children:(0,G.jsx)(`time`,{dateTime:e.firstSeen,children:_z(e.firstSeen)})}),(0,G.jsx)(gV,{name:`Last seen`,children:(0,G.jsx)(`time`,{dateTime:e.lastSeen,children:_z(e.lastSeen)})}),(0,G.jsx)(_V,{name:`Workflows`,values:e.workflows}),(0,G.jsx)(_V,{name:`Models`,values:e.models}),(0,G.jsx)(_V,{name:`Sources`,values:e.sources}),e.merged.length===0?null:(0,G.jsxs)(gV,{name:`Merged`,children:[e.merged.map(SB).join(`, `),(0,G.jsx)(q,{cli:`ork feedback split ${n}`,onClick:t,variant:`ghost`,children:`Split`})]})]})},yV=({onBack:e})=>(0,G.jsxs)(q,{onClick:e,variant:`ghost`,children:[(0,G.jsx)(Qv,{}),`Back to items`]}),bV=({run:e,onOpen:t})=>(0,G.jsxs)(`p`,{className:J.line,children:[(0,G.jsx)(`span`,{className:J.lineIcon,children:(0,G.jsx)(Gv,{})}),(0,G.jsxs)(`span`,{className:J.message,children:[`Run `,(0,G.jsx)(`code`,{children:e}),` is proposing a fix.`]}),(0,G.jsx)(q,{"aria-label":`Open run ${e}`,onClick:()=>{t(e)},variant:`ghost`,children:`Open run`})]}),xV=e=>[_z(e.at),e.feedback.source,...e.feedback.code===void 0?[]:[e.feedback.code],`run ${e.runId}`,...e.node===void 0?[]:[e.node]].join(` · `),SV=({record:e,title:t,onOpenRun:n})=>{let{feedback:r,runId:i,node:a}=e;return(0,G.jsxs)(`li`,{className:J.record,children:[(0,G.jsxs)(`p`,{className:J.recordMeta,children:[(0,G.jsx)(`span`,{children:xV(e)}),(0,G.jsxs)(q,{onClick:()=>{n(i,a)},variant:`ghost`,children:[`Open run`,(0,G.jsx)(zw,{children:` ${i}${a===void 0?``:` at ${a}`}, ${_z(e.at)}`})]})]}),r.title===t?null:(0,G.jsx)(`h4`,{className:J.recordTitle,children:r.title}),r.body===``?null:(0,G.jsx)(`p`,{className:J.recordBody,children:r.body}),r.evidence.length===0?null:(0,G.jsxs)(`p`,{className:J.evidence,children:[(0,G.jsx)(`span`,{className:J.caption,children:`Evidence `}),r.evidence.join(`, `)]})]})},CV=({item:e,read:t,onOpenRun:n})=>{let r=SB(e.id),i=t.detail?.records;return(0,G.jsxs)(`div`,{className:J.section,children:[(0,G.jsx)(`h3`,{className:J.caption,children:i===void 0?`Records`:`Records · ${String(i.length)}, newest first`}),i===void 0&&t.error!==null?(0,G.jsxs)(`div`,{className:J.line,children:[(0,G.jsx)(`p`,{className:J.alert,role:`alert`,children:(0,G.jsx)(`span`,{children:(0,G.jsx)(Wg,{text:`Could not read the records: ${t.error}`})})}),(0,G.jsx)(q,{onClick:t.reload,variant:`ghost`,children:`Try again`})]}):null,i===void 0&&t.error===null?(0,G.jsx)(`p`,{"aria-busy":`true`,className:J.message,children:`Reading records…`}):null,i===void 0?null:(0,G.jsx)(`ol`,{"aria-label":`Records of ${r}, newest first`,className:J.records,role:`list`,children:i.toReversed().map(t=>(0,G.jsx)(SV,{onOpenRun:n,record:t,title:e.title},t.id))})]})},wV=({item:e,read:t,acts:n,narrow:r,onBack:i,onLeave:a})=>{let o=(0,V.useId)(),s=t.detail?.fixRun;return(0,G.jsxs)(`section`,{"aria-labelledby":o,className:J.detail,onKeyDown:e=>{let t=document.querySelector(`[data-modal]`)!==null;e.key===`Escape`&&!t&&a()},children:[r?(0,G.jsx)(yV,{onBack:i}):null,(0,G.jsxs)(`div`,{className:J.head,children:[(0,G.jsx)(`h2`,{className:J.title,"data-feedback-heading":``,id:o,tabIndex:-1,children:e.title}),(0,G.jsx)(SD,{pill:!0,status:e.status})]}),(0,G.jsx)(vV,{item:e,onSplit:()=>{n.split(e)}}),s===void 0?null:(0,G.jsx)(bV,{onOpen:n.openRun,run:s}),(0,G.jsx)(hV,{acts:n,detail:t.detail,item:e}),(0,G.jsx)(CV,{item:e,onOpenRun:n.openRun,read:t}),(0,G.jsx)(YS,{command:`ork feedback show ${e.id.slice(0,12)}`})]})},TV=e=>{let t=[...e.currentTarget.querySelectorAll(`button`)],n=t.findIndex(e=>e===document.activeElement),r=t.length-1,i={ArrowDown:Math.min(n+1,r),ArrowUp:Math.max(n-1,0),Home:0,End:r}[e.key];i!==void 0&&(e.preventDefault(),t[i]?.focus())},EV=()=>(0,G.jsx)(zw,{children:`, `}),DV=(0,V.memo)(({item:e,chosen:t,tabStop:n,onChoose:r})=>(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{"aria-current":t?`true`:void 0,className:J.row,"data-item":e.id,onClick:()=>{r(e.id)},tabIndex:n?0:-1,type:`button`,children:[(0,G.jsxs)(`span`,{className:J.rowTop,children:[(0,G.jsx)(`span`,{className:J.rowTitle,children:e.title}),(0,G.jsx)(EV,{}),(0,G.jsx)(SD,{status:e.status})]}),(0,G.jsx)(EV,{}),(0,G.jsxs)(`span`,{className:J.rowMeta,children:[(0,G.jsx)(`span`,{children:SB(e.id)}),(0,G.jsx)(EV,{}),(0,G.jsxs)(`span`,{children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,children:`${String(e.count)}×`}),(0,G.jsx)(zw,{children:AB(e.count)})]}),(0,G.jsx)(EV,{}),(0,G.jsx)(`span`,{children:`${e.target} · ${e.kind}`}),e.severity===`high`?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(EV,{}),(0,G.jsx)(`span`,{className:J.high,children:`high`})]}):null,e.merged.length===0?null:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(EV,{}),(0,G.jsx)(`span`,{children:`+${String(e.merged.length)} merged`})]}),(0,G.jsx)(EV,{}),(0,G.jsxs)(`span`,{children:[(0,G.jsx)(zw,{children:`last seen `}),(0,G.jsx)(`time`,{dateTime:e.lastSeen,children:_z(e.lastSeen)})]})]})]})}));DV.displayName=`FeedbackRow`;var OV=({items:e,chosen:t,onChoose:n})=>{let r=e.some(({id:e})=>e===t)?t:e[0]?.id;return(0,G.jsx)(`ul`,{"aria-label":`Feedback items`,className:J.list,onKeyDown:TV,role:`list`,children:e.map(e=>(0,G.jsx)(DV,{chosen:e.id===t,item:e,onChoose:n,tabStop:e.id===r},e.id))})},kV=({filter:e,items:t,count:n,updating:r,failed:i,onFilter:a,onReload:o})=>(0,G.jsxs)(`div`,{className:J.tools,children:[(0,G.jsx)(Bw,{label:`Status`,onChange:t=>{a({...e,status:t})},options:EB(t??[]),value:e.status}),(0,G.jsx)(Bw,{label:`About`,onChange:t=>{a({...e,about:t})},options:wB,value:e.about}),(0,G.jsxs)(`div`,{className:J.toolsEnd,children:[t===null?null:(0,G.jsx)(`span`,{className:J.count,children:kB(n)}),r?(0,G.jsx)(`span`,{className:J.updating,children:`Updating…`}):null,(0,G.jsx)(q,{cli:e.status===`all`||e.status===`dismissed`?`ork feedback list --all`:`ork feedback list`,onClick:o,variant:`ghost`,children:i?`Try again`:`Reload`})]})]}),AV=({error:e})=>(0,G.jsxs)(`p`,{className:J.alert,"data-tone":`failed`,role:`alert`,children:[(0,G.jsx)(`span`,{className:J.lineIcon,children:(0,G.jsx)(yy,{})}),(0,G.jsx)(`span`,{children:(0,G.jsx)(Wg,{text:`Could not read feedback: ${e}`})})]}),jV=({anything:e,filter:t})=>{if(!e)return(0,G.jsx)(CC,{cli:`ork feedback list`,title:`No feedback yet.`,children:`What gets in your runs' way lands here: Ork's own signals, the agents' reports and your notes. In a terminal:`});let{title:n,body:r}=NB(t);return(0,G.jsx)(CC,{title:n,children:r})},MV=(e,t,n,r)=>{e.arriveAt(n),r!==void 0&&e.selectNode(r),t?.goTo(`monitor`),requestAnimationFrame(()=>{let t=document.querySelector(`[data-run-heading="${n}"]`);t!==null&&(e.takeArrival(n),t.focus())})},NV=e=>{let{state:t,workspace:n,filter:r,narrow:i,choose:a,focus:o}=e,s=(0,V.useRef)(!1),c=()=>kz(t.feedback.state.getValue())?.data??[],l=(e,r)=>{MV(t,n,e,r)},u=async()=>{await t.feedback.load(),e.reloadDetail()};return{moving:s,setStatus:async(e,l)=>{let d=SB(e.id),f=DB(c(),r),p=await t.client.call(`feedbackStatus`,{params:{id:e.id},body:{status:l}});if(!p.ok){let e=l===`new`?`restore`:`dismiss`;Hy.add({title:`Could not ${e} ${d}`,description:p.error});return}s.current=!0,await u();let m=DB(c(),r);if(!m.some(({id:t})=>t===e.id)){let t=PB(f,m,e.id);a(t?.id??null),o(t===void 0?`list`:i?`heading`:{row:t.id})}s.current=!1,n?.announce(l===`dismissed`?`Dismissed ${d}. It's listed under All and Dismissed.`:`Restored ${d} as new.`)},accept:async e=>{let r=SB(e.id),i=await t.client.call(`accept`,{params:{id:e.id},body:{lesson:!1}});i.ok?(n?.announce(`Accepted ${r}.`),await u()):Hy.add({title:`Could not accept ${r}`,description:i.error})},addLesson:async(e,n,r)=>{let i=await t.client.call(`accept`,{params:{id:e.id},body:n});if(!i.ok)return`Could not add the lesson: ${i.error}`;let{lesson:a}=i.data;return Hy.add({title:`Lesson added`,description:a===void 0?`${SB(e.id)} is accepted.`:`\`${a.file}\` in \`${a.root}\`, ${UB(a.tokens,r)}. Every session of \`${a.workflow}\` reads it from now on.`}),u(),null},apply:async(e,n=``)=>{let r=await t.client.call(`apply`,{params:{id:e.id},body:n===``?{}:{driver:n}});if(!r.ok)return`Could not start the run: ${r.error}`;let{runId:i}=r.data;return Hy.add({title:`Run ${i} started`,description:`\`ork:feedback-apply\` is proposing a fix for ${SB(e.id)}. Its question comes to Decisions.`}),l(i),u(),null},split:async e=>{let r=SB(e.id),i=await t.client.call(`split`,{params:{id:e.id}});i.ok?(o(`heading`),n?.announce(`Split ${kB(i.data.moved)} back out of ${r}.`),await u()):Hy.add({title:`Could not split ${r}`,description:i.error})},openRun:(e,t)=>{l(e,t)},reloadAll:u,announce:e=>{n?.announce(e)}}},PV=5e3,FV=48,IV=16,LV=e=>{let t=ab(e.feedback.state),n=ab(e.runs),r=(0,V.useRef)(0),i=(0,V.useRef)(null),a=(0,V.useRef)(n),o=(0,V.useCallback)(async()=>{r.current=Date.now(),await e.feedback.load()},[e]);return(0,V.useEffect)(()=>(o(),()=>{i.current!==null&&clearTimeout(i.current),i.current=null}),[o]),(0,V.useEffect)(()=>{if(a.current===n||(a.current=n,i.current!==null))return;let e=Math.max(0,r.current+PV-Date.now());i.current=setTimeout(()=>{i.current=null,o()},e)},[n,o]),{read:t,load:o}},RV=(e,t,n)=>{let[r,i]=(0,V.useState)(null),[a,o]=(0,V.useState)(null),[s,c]=(0,V.useState)(``),[l,u]=(0,V.useState)(0),d=`${t??``}|${n}|${String(l)}`;(0,V.useEffect)(()=>{if(t===null)return()=>{};let n=!0;return e.call(`feedbackItem`,{params:{id:t}}).then(e=>(n&&(c(d),e.ok?(i({id:t,value:e.data}),o(null)):o({id:t,value:e.error})),e)),()=>{n=!1}},[e,t,d]);let f=(0,V.useCallback)(()=>{u(e=>e+1)},[]);return{detail:r?.id===t?r.value:null,error:a?.id===t?a.value:null,loading:t!==null&&s!==d,reload:f}},zV=e=>{let[t,n]=(0,V.useState)(!1);return(0,V.useEffect)(()=>{let t=e.current;if(t===null)return()=>{};let r=new ResizeObserver(([e])=>{let t=e?.contentRect.width??0;if(t===0)return;let r=getComputedStyle(document.documentElement).fontSize,i=Number(r.replace(`px`,``))||IV;n(t<FV*i)});return r.observe(t),()=>{r.disconnect()}},[e]),t},BV=e=>e===void 0?``:[e.status,e.count,e.lastSeen,...e.merged].join(`|`),VV={heading:`[data-feedback-heading]`,list:`[data-feedback-list]`},HV=(e,t)=>e?.querySelector(typeof t==`string`?VV[t]:`[data-item="${t.row}"]`)??null,UV=e=>{let t=(0,V.useRef)(null),[,n]=(0,V.useState)(0);return(0,V.useEffect)(()=>{let n=t.current;if(n===null)return;let r=HV(e.current,n);r!==null&&(t.current=null,r.focus())}),(0,V.useCallback)(e=>{t.current=e,n(e=>e+1)},[])},WV=()=>{let e=(0,V.useRef)(!1);return{had:e,onFocus:()=>{e.current=!0},onBlur:t=>{let n=t.relatedTarget;(n instanceof Node?!t.currentTarget.contains(n):t.target.isConnected)&&(e.current=!1)}}},GV=()=>{let e=qy(),t=(0,V.use)(ZM),n=ab(e.feedbackFilter),{read:r,load:i}=LV(e),a=(0,V.useRef)(null),o=zV(a),[s,c]=(0,V.useState)(null),[l,u]=(0,V.useState)(`list`),d=kz(r)?.data??null,f=(0,V.useMemo)(()=>d??[],[d]),p=(0,V.useMemo)(()=>DB(f,n),[f,n]),m=p.find(({id:e})=>e===s),h=RV(e.client,m?.id??null,BV(m)),g=UV(a),_=WV(),v=(0,V.useCallback)(e=>{c(e),u(e===null?`list`:`detail`)},[]),y=NV({state:e,workspace:t,filter:n,narrow:o,choose:v,focus:g,reloadDetail:h.reload}),{moving:b}=y;return(0,V.useEffect)(()=>{if(s===null||d===null||b.current||p.some(({id:e})=>e===s))return;let e=FB(f,s);e!==void 0&&p.some(({id:t})=>t===e.id)?(c(e.id),t?.announce(`${SB(s)} was merged into ${SB(e.id)}.`)):o||(c(null),document.activeElement===document.body&&_.had.current&&g(`list`))},[s,d,f,p,o,t,g,b]),{root:a,narrow:o,read:r,all:d,items:f,shown:p,filter:n,chosen:s,item:m,detail:h,acts:y,focusWatch:_,showing:o?l:`both`,back:()=>{u(`list`);let e=s!==null&&p.some(({id:e})=>e===s);g(e?{row:s}:`list`)},choose:e=>{v(e),o&&g(`heading`)},setFilter:n=>{e.feedbackFilter.setValue(n),t?.announce(`${kB(DB(f,n).length)}.`)},reload:()=>{i(),h.reload()}}},KV=({view:e})=>{let{read:t,all:n,items:r,shown:i,filter:a,chosen:o}=e;return(0,G.jsxs)(`div`,{"aria-label":`Items`,className:J.card,"data-feedback-list":``,role:`group`,tabIndex:-1,children:[t.status===`failed`?(0,G.jsx)(AV,{error:t.error}):null,n===null&&t.status!==`failed`?(0,G.jsx)(`p`,{className:J.message,children:`Reading feedback…`}):null,n!==null&&i.length===0?(0,G.jsx)(jV,{anything:r.length>0,filter:a}):null,i.length===0?null:(0,G.jsx)(OV,{chosen:o,items:i,onChoose:e.choose})]})},qV=({view:e})=>{let{item:t,chosen:n,narrow:r}=e;return(0,G.jsxs)(`div`,{className:J.card,"data-feedback-detail":``,children:[t===void 0?null:(0,G.jsx)(wV,{acts:e.acts,item:t,narrow:r,onBack:e.back,onLeave:e.back,read:e.detail}),t===void 0&&r&&n!==null?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(yV,{onBack:e.back}),(0,G.jsx)(`p`,{className:J.message,children:`${SB(n)} isn't in this list any more.`})]}):null,t===void 0&&!r?(0,G.jsx)(`p`,{className:J.message,children:`Choose an item to read its records.`}):null]})},JV=()=>{let e=GV(),{read:t,all:n,filter:r,shown:i,showing:a,focusWatch:o,root:s}=e;return(0,G.jsxs)(`div`,{"aria-label":`Feedback`,className:J.panel,"data-layout":e.narrow?`narrow`:`wide`,onBlur:o.onBlur,onFocus:o.onFocus,ref:s,role:`group`,tabIndex:-1,children:[(0,G.jsx)(kV,{count:i.length,failed:t.status===`failed`,filter:r,items:n,onFilter:e.setFilter,onReload:e.reload,updating:t.status===`loading`&&n!==null}),(0,G.jsxs)(`div`,{className:J.body,children:[a===`detail`?null:(0,G.jsx)(KV,{view:e}),a===`list`?null:(0,G.jsx)(qV,{view:e})]})]})},YV=`all`,XV=[{value:`7`,label:`Last 7 days`},{value:`30`,label:`Last 30 days`},{value:`90`,label:`Last 90 days`},{value:YV,label:`All time`}],ZV=e=>e===YV,QV=(e,t)=>{if(ZV(e))return;let n=new Date(t);return new Date(n.getFullYear(),n.getMonth(),n.getDate()-(Number(e)-1)).toISOString()},$V=(e,t,n)=>[`ork usage`,...e?[`--all`]:[],`--since ${ZV(t)?`all`:`${t}d`}`,...n===void 0?[]:[`--by ${n}`]].join(` `),eH=92,tH=e=>String(e).padStart(2,`0`),nH=e=>`${String(e.getFullYear())}-${tH(e.getMonth()+1)}-${tH(e.getDate())}`,rH=e=>{let[t=0,n=1,r=1]=e.split(`-`).map(Number);return new Date(t,n-1,r)},iH=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()-(e.getDay()+6)%7),aH=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),oH=(e,t,n,r)=>{let i=new Map(e.map(e=>[e.key,e])),a=[];for(let e=n;e<=r;e=new Date(e.getFullYear(),e.getMonth(),e.getDate()+t)){let t=nH(e);a.push(i.get(t)??{key:t,costUsd:0,sessions:0})}return a},sH=(e,t,n)=>{let r=e.groups.day,i=t===void 0?r[0]?.key:void 0;if(t===void 0&&i===void 0)return{unit:`day`,bars:[],maxUsd:0};let a=t===void 0?rH(i??``):aH(new Date(t)),o=aH(new Date(n)),s=oH(r,1,a,o),c=s.length>eH?`week`:`day`,l=c===`day`?s:oH(e.groups.week,7,iH(a),o);return{unit:c,bars:l,maxUsd:Math.max(0,...l.map(e=>e.costUsd))}},cH=e=>OD(e),lH=e=>{let t=[...e];return e=>OD(e,t)},uH=e=>e<1e3?String(e):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`,dH=e=>`${String(Math.round(e*100))}%`,fH={panel:`_panel_18mjp_9`,tools:`_tools_18mjp_35`,projectFilter:`_projectFilter_18mjp_51`,body:`_body_18mjp_58`,overview:`_overview_18mjp_81`,breakdowns:`_breakdowns_18mjp_94`,totals:`_totals_18mjp_108`,total:`_total_18mjp_108`,section:`_section_18mjp_147`,heading:`_heading_18mjp_156`,hintsSection:`_hintsSection_18mjp_165`,chartArea:`_chartArea_18mjp_174`,hints:`_hints_18mjp_165`,chartHead:`_chartHead_18mjp_190`,readout:`_readout_18mjp_202`,chart:`_chart_18mjp_174`,column:`_column_18mjp_229`,bar:`_bar_18mjp_244`,axis:`_axis_18mjp_273`,axisEvery:`_axisEvery_18mjp_274`,details:`_details_18mjp_315`,table:`_table_18mjp_323`,number:`_number_18mjp_369`,name:`_name_18mjp_381`,path:`_path_18mjp_396`,retry:`_retry_18mjp_406`,note:`_note_18mjp_410`,refused:`_refused_18mjp_417`,limits:`_limits_18mjp_484`},pH=e=>e.toSorted((e,t)=>t.costUsd-e.costUsd)[0],mH=e=>`${String(e)} session${e===1?``:`s`}`,hH=2,gH=6,_H=14,vH=e=>e<=gH?`always`:e<=_H?`wide`:`never`,yH=({bars:e})=>{let t=vH(e.length);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{"aria-hidden":!0,className:fH.axis,"data-labelled":t,children:[(0,G.jsx)(`span`,{children:e[0]?.key}),(0,G.jsx)(`span`,{children:e.at(-1)?.key})]}),(0,G.jsx)(`div`,{"aria-hidden":!0,className:fH.axisEvery,"data-labelled":t,children:e.map(e=>(0,G.jsx)(`span`,{children:e.key.slice(5)},e.key))})]})},bH=({series:e})=>{let{bars:t,unit:n}=e,r=t.filter(e=>e.costUsd>0||e.sessions>0).toReversed(),i=t.length-r.length,a=lH(r.map(e=>e.costUsd));return(0,G.jsxs)(`details`,{className:fH.details,children:[(0,G.jsx)(`summary`,{children:`Show as a table`}),(0,G.jsxs)(`table`,{className:fH.table,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{scope:`col`,children:n===`day`?`Day`:`Week of`}),(0,G.jsx)(`th`,{className:fH.number,scope:`col`,children:`Cost`}),(0,G.jsx)(`th`,{className:fH.number,scope:`col`,children:`Sessions`})]})}),(0,G.jsx)(`tbody`,{children:r.map(e=>(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:fH.name,scope:`row`,children:e.key}),(0,G.jsx)(`td`,{className:fH.number,children:a(e.costUsd)}),(0,G.jsx)(`td`,{className:fH.number,children:e.sessions})]},e.key))})]}),i===0?null:(0,G.jsxs)(`p`,{className:fH.note,children:[String(i),` `,n,i===1?``:`s`,` with no spend.`]})]})},xH=({series:e})=>{let[t,n]=(0,V.useState)(null),{bars:r,maxUsd:i,unit:a}=e,o=r.find(e=>e.key===t)??null,s=pH(r),c=o??s,l=r.at(-1)?.key,u=a===`day`?`Spend per day`:`Spend per week`,d=a===`day`?``:`week of `,f=s===void 0?u:`${u}, ${String(r.length)} ${a}s. The peak was ${cH(s.costUsd)} ${a===`day`?`on`:`in the week of`} ${s.key}.`;return(0,G.jsxs)(`section`,{"aria-label":u,className:fH.section,children:[(0,G.jsxs)(`div`,{className:fH.chartHead,children:[(0,G.jsx)(`h3`,{className:fH.heading,children:u}),c===void 0?null:(0,G.jsxs)(`p`,{className:fH.readout,children:[o===null?`Peak: `:``,d,c.key,c.key===l?` so far`:``,` · `,cH(c.costUsd),` ·`,` `,mH(c.sessions)]})]}),(0,G.jsx)(`div`,{"aria-label":f,className:fH.chart,onPointerLeave:()=>{n(null)},role:`img`,children:r.map(e=>(0,G.jsx)(`div`,{className:fH.column,"data-partial":e.key===l?``:void 0,"data-pointed":e.key===o?.key?``:void 0,onPointerEnter:()=>{n(e.key)},children:e.costUsd===0?null:(0,G.jsx)(`div`,{className:fH.bar,style:{height:`${String(Math.max(hH,e.costUsd/i*100))}%`}})},e.key))}),(0,G.jsx)(yH,{bars:r}),(0,G.jsx)(bH,{series:e})]})},SH=e=>e===void 0?`All projects`:`This project`,CH=e=>`$${e.toFixed(2)}`,wH=e=>new Date(e).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}),TH=({limits:e})=>e.problems.length===0&&e.caps.length===0&&e.plan.length===0?null:(0,G.jsxs)(`section`,{"aria-label":`Limits`,className:fH.limits,children:[e.problems.map(e=>(0,G.jsx)(`p`,{className:fH.note,children:(0,G.jsx)(Wg,{text:e})},e)),e.caps.map(e=>(0,G.jsx)(ez,{label:`${SH(e.project)}, this ${e.window}`,max:e.capUsd,text:`${CH(e.spentUsd)} of ${CH(e.capUsd)}, resets ${wH(e.resetsAt)}`,value:Math.min(e.spentUsd,e.capUsd)},`${e.project??`all`}-${e.window}`)),e.plan.map(e=>(0,G.jsx)(`p`,{className:fH.note,children:`Your Claude plan's ${e.window.replaceAll(`_`,` `)} limit ${e.status===`rejected`?`was reached`:`is close`}${e.resetsAt===void 0?``:`; it resets ${wH(e.resetsAt)}`}.`},e.window))]}),EH=10,DH=({title:e,label:t,groups:n,total:r,nameOf:i,moreCommand:a})=>{let o=n.length-EH,s=n.slice(0,EH),c=lH(s.map(e=>e.costUsd));return(0,G.jsxs)(`section`,{"aria-label":e,className:fH.section,children:[(0,G.jsx)(`h3`,{className:fH.heading,children:e}),(0,G.jsxs)(`table`,{className:fH.table,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{scope:`col`,children:t}),(0,G.jsx)(`th`,{className:fH.number,scope:`col`,children:`Cost`}),(0,G.jsx)(`th`,{className:fH.number,scope:`col`,children:`Share`}),(0,G.jsx)(`th`,{className:fH.number,scope:`col`,children:`Sessions`}),(0,G.jsx)(`th`,{className:fH.number,scope:`col`,children:`From cache`})]})}),(0,G.jsx)(`tbody`,{children:s.map(e=>(0,G.jsxs)(`tr`,{children:[(0,G.jsxs)(`th`,{className:fH.name,scope:`row`,title:e.key,children:[i?.(e.key)??e.key,i===void 0?null:(0,G.jsx)(`span`,{className:fH.path,children:e.key})]}),(0,G.jsx)(`td`,{className:fH.number,children:c(e.costUsd)}),(0,G.jsx)(`td`,{className:fH.number,children:dH(r===0?0:e.costUsd/r)}),(0,G.jsx)(`td`,{className:fH.number,children:e.sessions}),(0,G.jsx)(`td`,{className:fH.number,children:dH(e.cacheHitRate)})]},e.key))})]}),o>0?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`p`,{className:fH.note,children:[`And `,o,` more that cost less. This lists them all:`]}),(0,G.jsx)(YS,{command:a})]}):null]})},OH=({error:e,command:t,retry:n})=>(0,G.jsxs)(`div`,{className:fH.section,children:[(0,G.jsxs)(`p`,{className:fH.refused,role:`alert`,children:[`Cannot read usage: `,(0,G.jsx)(Wg,{text:e})]}),(0,G.jsx)(`div`,{className:fH.retry,children:(0,G.jsx)(q,{onClick:n,children:`Try again`})}),(0,G.jsx)(`p`,{className:fH.note,children:`On a terminal, the same report:`}),(0,G.jsx)(YS,{command:t})]}),kH=({period:e,limits:t})=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(TH,{limits:t}),(0,G.jsx)(CC,{cli:`ork run <workflow>`,title:ZV(e)?`Nothing spent yet.`:`Nothing spent in this period.`,children:`Claude sessions show here once they finish. Start one with Run workflow, or in a terminal:`})]}),AH=({report:e})=>{let{totals:t}=e,n=t.inputTokens+t.cacheReadTokens+t.cacheWriteTokens,r=[[`Spend`,cH(t.costUsd)],[`Runs with sessions`,String(t.runs)],[`Sessions`,String(t.sessions)],[`Tokens in`,uH(n)],[`Tokens out`,uH(t.outputTokens)],[`From cache`,dH(t.cacheHitRate)]];return(0,G.jsx)(`dl`,{className:fH.totals,children:r.map(([e,t])=>(0,G.jsxs)(`div`,{className:fH.total,children:[(0,G.jsx)(`dt`,{children:e}),(0,G.jsx)(`dd`,{children:t})]},e))})},jH=({report:e,since:t,now:n,period:r,everyProject:i,projectName:a})=>{let o=(0,V.useMemo)(()=>sH(e,t,n),[e,t,n]),s=e.totals.costUsd,c=e=>$V(i,r,e);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(TH,{limits:e.limits}),(0,G.jsxs)(`div`,{className:fH.overview,children:[(0,G.jsx)(AH,{report:e}),e.hints.length===0?null:(0,G.jsxs)(`section`,{"aria-label":`Worth a look`,className:fH.hintsSection,children:[(0,G.jsx)(`h3`,{className:fH.heading,children:`Worth a look`}),(0,G.jsx)(`ul`,{className:fH.hints,children:e.hints.map(e=>(0,G.jsx)(`li`,{children:(0,G.jsx)(Wg,{text:e.message})},e.code))})]}),(0,G.jsx)(`div`,{className:fH.chartArea,children:(0,G.jsx)(xH,{series:o})})]}),(0,G.jsxs)(`div`,{className:fH.breakdowns,children:[i?(0,G.jsx)(DH,{groups:e.groups.project,label:`Project`,moreCommand:c(`project`),nameOf:a,title:`By project`,total:s}):null,(0,G.jsx)(DH,{groups:e.groups.workflow,label:`Workflow`,moreCommand:c(`workflow`),title:`By workflow`,total:s}),(0,G.jsx)(DH,{groups:e.groups.model,label:`Model`,moreCommand:c(`model`),title:`By model`,total:s}),(0,G.jsx)(DH,{groups:e.groups.node,label:`Node`,moreCommand:c(`node`),title:`Costliest nodes`,total:s})]}),(0,G.jsx)(`p`,{className:fH.note,children:`Costs are Claude Code's own estimates. On a subscription they are not what you are billed. On a terminal:`}),(0,G.jsx)(YS,{command:c()})]})},MH=()=>{let e=qy(),t=ab(e.usage.state),n=ab(e.runs),r=ab(e.projects.state),i=ab(e.usageFilter),{project:a,period:o}=i,[s,c]=(0,V.useState)(0),l=kz(t),u=(0,V.useRef)(null),d=ib(e.runs,e=>e?.filter(e=>e.live!==`running`&&e.live!==`paused`).length??0);(0,V.useEffect)(()=>{e.projects.load()},[e]),(0,V.useEffect)(()=>{let t=Date.now(),n=QV(o,t);e.usage.load({now:t,period:o,query:{...a===`all`?{}:{project:a},...n===void 0?{}:{since:n}}})},[e,a,o,d,s]);let f=(0,V.useMemo)(()=>Oz(r.status===`ready`?r.data:[],n??[]),[r,n]),p=a===`all`;return(0,G.jsxs)(`div`,{className:fH.panel,children:[(0,G.jsxs)(`div`,{className:fH.tools,children:[(0,G.jsx)(`div`,{className:fH.projectFilter,children:(0,G.jsx)(Bw,{label:`Project`,onChange:t=>{e.usageFilter.setValue({...i,project:t})},options:f,value:a})}),(0,G.jsx)(Bw,{label:`Period`,onChange:t=>{e.usageFilter.setValue({...i,period:t})},options:XV,value:o})]}),(0,G.jsxs)(`section`,{"aria-busy":t.status===`loading`,"aria-label":`Usage report`,className:fH.body,ref:u,tabIndex:0,children:[t.status===`failed`?(0,G.jsx)(OH,{command:$V(p,o),error:t.error,retry:()=>{u.current?.focus(),c(s+1)}}):null,l===void 0?t.status===`failed`?null:(0,G.jsx)(`p`,{className:fH.note,children:`Reading usage…`}):l.data.totals.sessions===0?(0,G.jsx)(kH,{limits:l.data.limits,period:l.arg.period}):(0,G.jsx)(jH,{everyProject:l.arg.query.project===void 0,now:l.arg.now,period:l.arg.period,projectName:e=>f.find(t=>t.value===e)?.label??Ez(e),report:l.data,since:l.arg.query.since})]})]})},NH=(e,t)=>`${String(e)} ${t}${e===1?``:t.endsWith(`h`)?`es`:`s`}`,PH=e=>({worktrees:e.filter(e=>e.path!==null).length,branches:e.filter(e=>e.path===null).length}),FH=e=>{let{worktrees:t,branches:n}=PH(e);return[...t>0||n===0?[NH(t,`worktree`)]:[],...n>0?[NH(n,`branch`)]:[]].join(` · `)},IH=(e,t)=>{let n=e.flatMap(e=>e.items),{worktrees:r,branches:i}=PH(n),a=t??NH(e.filter(e=>e.items.length>0).length,`project`);return n.length===0?`No Ork worktrees or branches in ${a}.`:`${[...r>0?[NH(r,`worktree`)]:[],...i>0?[NH(i,`branch`)]:[]].join(` and `)} in ${a}.`},LH=(e,t,n)=>e===null?n?`the worktrees couldn't be read`:`reading worktrees`:e.some(e=>e.items.some(e=>e.state===`merged`))?null:t?`nothing merged into the current branch`:`nothing merged in these projects`,RH=e=>[e.root,...e.error===void 0?[e.head===null?`detached HEAD`:`current branch ${e.head}`]:[],...e.items.length===0?[]:[FH(e.items)]],zH=e=>[{text:`run ${e.runId}`,risk:!1},{text:e.nodeId,risk:!1},...e.path===null?[]:[{text:e.path,risk:!1}],...e.parts,...e.cleanKeeps===void 0?[]:[{text:`clean keeps it: ${e.cleanKeeps}`,risk:!1}]],BH=e=>e.run.known?`Open run ${e.runId} at ${e.nodeId}`:`Open run ${e.runId}: it isn't in Ork's records`,VH=e=>{let t=`${e.remove.label.replace(`…`,``)} ${e.label}…`;return e.remove.refusal===void 0?t:`${t}: ${e.remove.refusal}`},HH=(e,t,n,r)=>`cd ${sT(e)} && ork worktrees remove ${sT(t)}${n?` --branch`:``}${r?` --force`:``}`,UH=e=>e.path===null?`branch`:e.state===`detached`||e.branch===void 0?`detached`:`worktree`,WH=e=>({branch:`Delete branch \`${e.label}\``,detached:`Remove the worktree of \`${e.label}\``,worktree:`Remove \`${e.label}\``})[UH(e)],GH=(e,t)=>{let n=UH(e),r=n===`branch`?`It has no worktree. Deletes the branch from \`${t}\`.`:n===`detached`?`Removes the detached worktree. It has no branch of Ork's.`:e.missing?`Its folder is gone. Removing it drops git's record of the worktree. The branch stays unless you delete it too.`:`Removes its worktree. The branch stays unless you delete it too.`;return e.checkedOut===void 0?r:`${r} It's on \`${e.checkedOut}\`, the workflow's own branch, which Ork never deletes; removing the worktree loses nothing committed.`},KH=(e,t)=>e.merged?`It's merged into \`${t}\`.`:`It has ${NH(e.ahead,`commit`)} not merged into \`${t}\`; deleting it loses them.`,qH=e=>e.force?`Continue…`:e.removeWorktree&&e.deleteBranch?`Remove worktree and branch`:e.deleteBranch?`Delete branch`:e.prunes?`Prune`:`Remove worktree`,JH=e=>{if(!e.force)return null;let{losing:t}=e;if(t.changes.length>0)return`It has uncommitted changes; the next step shows what's lost.`;let n=NH(t.commits.length+t.more.commits,`commit`);return t.commitsOn===`no branch`?`It holds ${n} on no branch; the next step shows them.`:`Deleting the branch loses ${n}; the next step shows them.`},YH=(e,t)=>t.removeWorktree&&t.deleteBranch?`Removed ${e.label}'s worktree and deleted its branch.`:t.deleteBranch?`Deleted branch ${e.label}.`:t.prunes?`Pruned ${e.label}'s missing worktree.`:`Removed ${e.label}'s worktree.`,XH=e=>[...e.losing.changes.length>0?[`Uncommitted changes can't be recovered.`]:[],...e.losing.commits.length>0?[`Deleted commits stay only in git's reflog, until it expires.`]:[]].join(` `),ZH=(e,t)=>`cd ${sT(e)} && ork worktrees clean${t?` --branches`:``}`,QH=`[data-worktree-row]`,$H=(e,t)=>[...e?.querySelectorAll(QH)??[]].findIndex(e=>e.dataset.worktreeRow===t),eU=(e,t)=>{let n=qy(),r=(0,V.use)(ZM),[i,a]=(0,V.useState)(null),[o,s]=(0,V.useState)(!1),[c,l]=(0,V.useState)(new Set),u=(0,V.useRef)(`back`),d=(0,V.useRef)(null),f=(0,V.useRef)(0),p=(0,V.useMemo)(()=>({openRun:e=>{MV(n,r,e.runId,e.nodeId)},remove:(t,n)=>{u.current=`back`,a({kind:`remove`,row:t,project:n,target:{project:n.root,key:t.key},index:$H(e.current,t.key),id:f.current+1}),f.current+=1,s(!0)}}),[n,r,e]),m=t=>{let n=e.current?.querySelectorAll(QH)??[];return n[Math.min(t,n.length-1)]?.querySelector(`[data-act="remove"]`)??e.current?.querySelector(`[data-empty-title]`)??e.current??!1};return{opened:i,open:o,gone:c,rowActs:p,cleanButton:d,openClean:()=>{f.current+=1,a({kind:`clean`,id:f.current}),s(!0)},close:()=>{s(!1)},removed:(e,n,i,a)=>{r?.announce(YH(e,i)),u.current=a,l(t=>new Set([...t,`${n.root}|${e.key}`])),s(!1),t().finally(()=>{l(new Set)})},removeFocus:()=>typeof u.current==`number`?m(u.current):u.current===`back`,cleanClosed:e=>{e||r?.announce(`Nothing was removed.`),s(!1)},cleanFocus:()=>d.current??!0,openRemovedRun:e=>{u.current=`run`,s(!1),MV(n,r,e.runId,e.nodeId)}}},tU=(e,t)=>t===`all`?[...e]:e.filter(e=>e.root===t),nU=(e,t)=>({...e,name:t}),rU=()=>{let e=qy(),t=(0,V.use)(ZM),n=ab(e.worktrees.state),r=ab(e.worktreesFilter),i=ab(e.runs),a=ab(e.projects.state),o=(0,V.useRef)(0),s=(0,V.useRef)(null),c=(0,V.useRef)(null),l=(0,V.useRef)(i),u=(0,V.useCallback)(()=>{if(s.current!==null)return s.current;o.current=Date.now();let t=e.worktrees.load().finally(()=>{s.current=null});return s.current=t,t},[e]);(0,V.useEffect)(()=>(u(),e.projects.state.getValue().status===`idle`&&e.projects.load(),()=>{c.current!==null&&clearTimeout(c.current),c.current=null}),[u,e]),(0,V.useEffect)(()=>{if(l.current===i||(l.current=i,c.current!==null))return;let e=Math.max(0,o.current+PV-Date.now());c.current=setTimeout(()=>{c.current=null,u()},e)},[i,u]);let d=kz(n)?.data.projects??null,f=Oz(kz(a)?.data??[],[...i??[],...(d??[]).map(e=>({project:e.root}))]),p=e=>f.find(t=>t.value===e)?.label??e,m=(d??[]).map(e=>nU(e,p(e.root))),h=f.flatMap(e=>m.filter(t=>t.root===e.value)),g=d===null?null:tU(h,r);return{read:n,all:d===null?null:h,shown:g,filter:r,options:f,load:u,setFilter:n=>{e.worktreesFilter.setValue(n);let r=n===`all`?null:p(n);t?.announce(IH(tU(h,n),r))}}},iU={panel:`_panel_jg5qy_10`,tools:`_tools_jg5qy_31`,card:`_card_jg5qy_32`,toolsEnd:`_toolsEnd_jg5qy_56`,count:`_count_jg5qy_66`,head:`_head_jg5qy_76`,name:`_name_jg5qy_85`,headMeta:`_headMeta_jg5qy_94`,list:`_list_jg5qy_106`,row:`_row_jg5qy_112`,rowName:`_rowName_jg5qy_143`,badge:`_badge_jg5qy_155`,meta:`_meta_jg5qy_159`,risk:`_risk_jg5qy_177`,actions:`_actions_jg5qy_185`,note:`_note_jg5qy_195`,message:`_message_jg5qy_196`,alert:`_alert_jg5qy_205`,alertIcon:`_alertIcon_jg5qy_218`,facts:`_facts_jg5qy_225`,factName:`_factName_jg5qy_239`,caption:`_caption_jg5qy_240`,factValue:`_factValue_jg5qy_261`,step:`_step_jg5qy_277`,reason:`_reason_jg5qy_287`,section:`_section_jg5qy_293`,title:`_title_jg5qy_303`,result:`_result_jg5qy_312`,resultLine:`_resultLine_jg5qy_323`,foot:`_foot_jg5qy_335`},aU={ArrowDown:e=>e+1,ArrowUp:e=>e-1,Home:()=>0,End:(e,t)=>t},oU=e=>{let t=aU[e.key],{target:n}=e;if(t===void 0||!(n instanceof HTMLElement))return;let r=n.dataset.act;if(r===void 0)return;let i=[...e.currentTarget.querySelectorAll(`[data-worktree-row] [data-act="${r}"]`)],a=i.length-1,o=i[Math.max(0,Math.min(a,t(i.indexOf(n),a)))];o!==void 0&&(e.preventDefault(),o.focus())},sU=(0,V.memo)(({row:e,project:t,acts:n})=>{let r=(0,V.useId)(),i=(0,V.useId)(),a=HH(t.root,e.key,e.path===null,!1),o=zH(e),{refusal:s}=e.remove;return(0,G.jsxs)(`li`,{className:iU.row,"data-worktree-row":e.key,children:[(0,G.jsxs)(`p`,{className:iU.rowName,children:[e.label,(0,G.jsx)(zw,{children:`, `})]}),(0,G.jsx)(`span`,{className:iU.badge,children:(0,G.jsx)(wD,{state:e.state})}),(0,G.jsx)(`p`,{className:iU.meta,id:r,children:o.map((e,t)=>(0,G.jsxs)(`span`,{className:e.risk?iU.risk:void 0,children:[e.text,t<o.length-1?` ·`:``]},t))}),(0,G.jsx)(`span`,{hidden:!0,id:i,children:`CLI: ${a}`}),(0,G.jsxs)(`div`,{className:iU.actions,children:[(0,G.jsx)(q,{"aria-label":BH(e),"data-act":`open`,disabled:!e.run.known,focusableWhenDisabled:!0,onClick:()=>{n.openRun(e)},tip:e.run.known?void 0:`It isn't in Ork's records.`,variant:`ghost`,children:`Open run`}),(0,G.jsx)(q,{"aria-describedby":`${r} ${i}`,"aria-label":VH(e),cli:a,"data-act":`remove`,disabled:s!==void 0,focusableWhenDisabled:!0,onClick:()=>{n.remove(e,t)},tip:s===void 0?void 0:`${s[0]?.toUpperCase()??``}${s.slice(1)}.`,children:e.remove.label})]})]})},(e,t)=>e.acts===t.acts&&e.project.root===t.project.root&&e.project.head===t.project.head&&JSON.stringify(e.row)===JSON.stringify(t.row)),cU=({project:e,acts:t})=>{let n=(0,V.useId)();return(0,G.jsxs)(`section`,{"aria-labelledby":n,className:iU.card,children:[(0,G.jsxs)(`div`,{className:iU.head,children:[(0,G.jsx)(`h3`,{className:iU.name,id:n,children:e.name}),(0,G.jsx)(`p`,{className:iU.headMeta,children:RH(e).join(` · `)})]}),e.error===void 0?(0,G.jsx)(`ul`,{"aria-label":`Worktrees in ${e.name}`,className:iU.list,children:e.items.map(n=>(0,G.jsx)(sU,{acts:t,project:e,row:n},n.key))}):(0,G.jsxs)(`p`,{className:iU.alert,children:[(0,G.jsx)(`span`,{className:iU.alertIcon,children:(0,G.jsx)(cD,{})}),(0,G.jsx)(`span`,{children:(0,G.jsx)(Wg,{text:`Could not read ${e.name}'s worktrees: ${e.error}`})})]}),e.fix===void 0?null:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:iU.note,children:`If it moved, this points Ork at its new place:`}),(0,G.jsx)(YS,{command:e.fix})]})]})},lU=e=>e.filter(e=>e.steps.length>0),uU=e=>({worktrees:e.filter(e=>e.removeWorktree||e.prunes).length,branches:e.filter(e=>e.deleteBranch).length}),dU=e=>e.removeWorktree||e.deleteBranch||e.prunes,fU=e=>e.skip??`no worktree, branch kept`,pU=e=>{let[t]=e;return e.length===1&&t!==void 0?`Clean merged worktrees in ${t.name}`:`Clean merged worktrees in ${NH(e.length,`project`)}`},mU=e=>`Removes the worktrees of branches merged into ${e?`the project's current branch`:`each project's current branch`}, as the command below does. One with uncommitted changes, or checked out in the main checkout, is kept. Nothing is forced.`,hU=e=>{let{worktrees:t,branches:n}=uU(e),r=[...t>0?[`removes ${NH(t,`worktree`)}`]:[],...n>0?[`deletes ${NH(n,`branch`)}`]:[]].join(` and `),i=e.filter(e=>!dU(e)||e.skip!==void 0),a=new Map;for(let e of i)a.set(fU(e),(a.get(fU(e))??0)+1);let o=i.length===0?``:`Keeps ${String(i.length)}: ${[...a].map(([e,t])=>`${e} (${String(t)})`).join(`; `)}.`;return[r===``?`Nothing to clean.`:`${r.charAt(0).toUpperCase()}${r.slice(1)}.`,o].filter(e=>e!==``).join(` `)},gU=e=>{let{worktrees:t,branches:n}=uU(e.flatMap(e=>e.steps));return t===0&&n===0?null:t===0?`Delete ${NH(n,`branch`)}`:n===0?`Remove ${NH(t,`worktree`)}`:`Remove ${NH(t,`worktree`)} and ${NH(n,`branch`)}`},_U=e=>e.some(e=>e.error!==void 0)?`Cleaned in part`:`Cleaned`,vU={well:`_well_18f8h_7`},yU=({label:e,reading:t,describedBy:n,ref:r,steady:i=!1,short:a=!1,children:o})=>(0,G.jsx)(`section`,{"aria-busy":t!==void 0,"aria-describedby":n,"aria-label":e,className:vU.well,"data-short":a?``:void 0,"data-steady":i?``:void 0,ref:r,tabIndex:0,children:t===void 0?o:(0,G.jsx)(Wg,{text:t})}),bU=`Reading the plan…`,xU=`Nothing to show: the plan couldn't be read.`,SU=({reading:e,failed:t,well:n})=>(0,G.jsx)(yU,{label:`Plan`,reading:e?bU:void 0,ref:n,steady:!0,children:t?xU:`Nothing to clean.`}),CU=({checked:e,disabled:t,onChange:n})=>{let r=(0,V.useId)();return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(qC,{checked:e,describedBy:r,disabled:t,label:`Also delete the merged branches`,onChange:n}),(0,G.jsx)(`p`,{className:iU.note,id:r,children:`Only branches merged into the current branch, which git deletes without losing a commit.`})]})},wU=({project:e,branches:t,reading:n,failed:r,well:i})=>{let a=(0,V.useId)(),o=e.head??`its detached HEAD`;return(0,G.jsxs)(`section`,{"aria-label":e.name,className:iU.section,children:[(0,G.jsx)(`h3`,{className:iU.name,children:e.name}),(0,G.jsx)(`p`,{className:iU.headMeta,children:(0,G.jsx)(Wg,{text:`\`${e.root}\` · into \`${o}\``})}),(0,G.jsx)(`p`,{className:iU.message,id:a,children:n||r?``:hU(e.steps)}),(0,G.jsx)(`p`,{className:iU.caption,children:`Plan`}),(0,G.jsxs)(yU,{describedBy:a,label:`Plan for ${e.name}`,reading:n?bU:void 0,ref:i,steady:!0,children:[r?xU:null,e.steps.map(e=>(0,G.jsxs)(`span`,{children:[e.line.text,e.line.reason===void 0?null:(0,G.jsx)(`span`,{className:iU.reason,children:` (${e.line.reason})`}),`
71
- `]},e.key))]}),(0,G.jsx)(`p`,{className:iU.note,children:(0,G.jsx)(Wg,{text:`In \`${e.root}\`:`})}),(0,G.jsx)(YS,{command:ZH(e.root,t)})]})},TU=({lines:e})=>(0,G.jsx)(`ul`,{className:iU.result,children:e.map(e=>(0,G.jsxs)(`li`,{className:iU.resultLine,children:[(0,G.jsx)(aD,{}),e]},e))}),EU=({results:e})=>{let t=(0,V.useRef)(null);return(0,V.useEffect)(()=>{t.current?.focus()},[]),(0,G.jsxs)(`div`,{className:iU.step,children:[(0,G.jsx)(`h3`,{className:iU.title,ref:t,tabIndex:-1,children:_U(e)}),e.filter(e=>e.done.length>0||e.error!==void 0).map(e=>(0,G.jsxs)(`section`,{"aria-label":e.name,className:iU.section,children:[(0,G.jsx)(`h4`,{className:iU.name,children:e.name}),e.error===void 0?null:(0,G.jsxs)(`p`,{className:iU.alert,children:[(0,G.jsx)(`span`,{className:iU.alertIcon,children:(0,G.jsx)(cD,{})}),(0,G.jsx)(`span`,{children:(0,G.jsx)(Wg,{text:`Stopped in ${e.name}: ${e.error}`})})]}),e.error===void 0||e.done.length===0?null:(0,G.jsx)(`p`,{className:iU.note,children:`Done before it stopped:`}),(0,G.jsx)(TU,{lines:e.done})]},e.root))]})},DU=e=>{if(e.step!==`done`)return`plan`in e?e.plan:e.shown},OU=(e,t,n)=>{let[r,i]=(0,V.useState)(!1),[a,o]=(0,V.useState)({step:`reading`}),s=(0,V.useRef)(0),c=(0,V.useCallback)(async n=>{s.current+=1;let r=s.current,i=await e.call(`worktreesCleanPlan`,{body:{...t===void 0?{}:{project:t},branches:n}});return r===s.current?i:null},[e,t]),l=(0,V.useCallback)(async(n,r)=>{s.current+=1;let i=s.current,a=await e.call(`worktreesCleanPlan`,{body:{...t===void 0?{}:{project:t},branches:n}});i===s.current&&o(a.ok?{step:`plan`,plan:a.data,changed:!1}:{step:`readFailed`,error:a.error,...r===void 0?{}:{shown:r}})},[e,t]);(0,V.useEffect)(()=>{l(!1)},[l]);let u=(e,t)=>{o(t===void 0?{step:`reading`}:{step:`reading`,shown:t}),l(e,t)},d=async i=>{o({step:`cleaning`,plan:i});let a=await e.call(`worktreesClean`,{body:{...t===void 0?{}:{project:t},branches:r,digest:i.digest}});if(a.ok){o({step:`done`,results:a.data.projects}),n();return}if(a.status!==409){o({step:`cleanFailed`,plan:i,error:a.error});return}let s=await c(r);s!==null&&(s.ok&&s.data.digest!==i.digest?o({step:`plan`,plan:s.data,changed:!0}):o({step:`cleanFailed`,plan:i,error:a.error}))};return{step:a,branches:r,setBranches:e=>{i(e),u(e,DU(a))},clean:()=>{a.step===`plan`&&d(a.plan)},tryAgain:()=>{a.step===`cleanFailed`?d(a.plan):u(r,DU(a))}}},kU=e=>e.step===`readFailed`?`Could not read the plan: ${e.error}`:e.step===`cleanFailed`?`Could not clean: ${e.error}`:null,AU=e=>e.step===`reading`?`Reading the plan…`:e.step===`readFailed`?`The plan couldn't be read; Try again reads it.`:null,jU=e=>{let t=OU(e.client,e.project,e.onCleaned),{step:n}=t,r=(0,V.useRef)(null),i=(0,V.useId)(),a=(0,V.useId)(),o=n.step===`cleaning`,s=n.step===`reading`,c=DU(n),l=c===void 0?e.scope:lU(c.projects),u=gU(l),d=n.step===`plan`&&n.changed,f=c!==void 0&&!s&&u===null,p=n.step===`readFailed`&&c===void 0;(0,V.useEffect)(()=>{d&&r.current?.focus()},[d]),(0,V.useEffect)(()=>{if(s)return;let e=document.activeElement;(e===null||e===document.body||e.getAttribute(`role`)===`dialog`)&&r.current?.focus()},[s]);let m=()=>{o||e.onClose(n.step===`done`)};return(0,G.jsx)(bC,{description:mU(e.project!==void 0),finalFocus:e.finalFocus,initialFocus:r,onOpenChange:e=>{e||m()},open:e.open,size:`wide`,title:pU(l.length===0?e.scope:l),children:n.step===`done`?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(EU,{results:n.results}),(0,G.jsx)(xC,{children:(0,G.jsx)(q,{onClick:m,children:`Close`})})]}):(0,G.jsxs)(G.Fragment,{children:[d?(0,G.jsx)(`p`,{role:`alert`,children:`The plan changed since you read it. Read it again before cleaning.`}):null,l.length===0?(0,G.jsx)(SU,{failed:p,reading:s,well:r}):null,l.map((e,n)=>(0,G.jsx)(wU,{branches:t.branches,failed:p,project:e,reading:s,well:n===0?r:void 0},e.root)),(0,G.jsx)(CU,{checked:t.branches,disabled:o,onChange:t.setBranches}),(0,G.jsx)(YB,{id:a,onTryAgain:t.tryAgain,takeFocus:n.step===`cleanFailed`?`always`:`ifLost`,words:kU(n)}),(0,G.jsx)($L,{id:i,why:AU(n)}),(0,G.jsxs)(xC,{children:[(0,G.jsx)(q,{disabled:o,focusableWhenDisabled:!0,onClick:m,variant:`ghost`,children:f?`Close`:`Cancel`}),f?null:(0,G.jsx)(q,{"aria-describedby":`${i} ${a}`,disabled:n.step!==`plan`,focusableWhenDisabled:!0,onClick:t.clean,variant:`primary`,children:o?`Removing…`:u??`Remove worktrees`})]})]})})},MU=(e,t,n)=>{let r=t?.parts.map(e=>e.text)??e.parts.map(e=>e.text.replace(/ not merged$/u,` not merged into ${n}`)),i=t?.merged??e.merged;return r.join(` · `)||(i?`merged into ${n}`:``)},NU=`Nothing to show: its state couldn't be read.`,PU=({name:e,children:t})=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`dt`,{className:iU.factName,children:e}),(0,G.jsx)(`dd`,{className:iU.factValue,children:t})]}),FU=({plan:e,label:t,reading:n})=>(0,G.jsx)(yU,{label:t,reading:n,steady:!0,children:e===void 0?NU:(0,G.jsxs)(G.Fragment,{children:[e.line.text,e.line.reason===void 0?null:(0,G.jsx)(`span`,{className:iU.reason,children:` (${e.line.reason})`})]})}),IU=e=>{let{row:t,project:n,plan:r}=e,i=(0,V.useId)(),a=n.head??`the current branch`;return(0,G.jsxs)(`div`,{className:iU.step,children:[(0,G.jsxs)(`dl`,{className:iU.facts,children:[(0,G.jsx)(PU,{name:`Project`,children:`${n.name} ${n.root}`}),(0,G.jsxs)(PU,{name:`Run`,children:[`${t.runId} · ${t.nodeId}`,(0,G.jsx)(q,{"aria-label":BH(t),disabled:!t.run.known||e.busy,focusableWhenDisabled:!0,onClick:e.onOpenRun,tip:t.run.known?void 0:`It isn't in Ork's records.`,variant:`ghost`,children:`Open run`})]}),t.path===null?null:(0,G.jsx)(PU,{name:`Path`,children:t.path}),(0,G.jsx)(PU,{name:`State`,children:MU(t,r,a)})]}),UH(t)===`worktree`&&t.branch!==void 0?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(qC,{checked:e.deleteBranch,describedBy:i,disabled:e.busy,label:`Also delete the branch ${t.branch}`,onChange:e.onDeleteBranch}),(0,G.jsx)(`p`,{className:iU.note,id:i,children:(0,G.jsx)(Wg,{text:KH(r??t,a)})})]}):null,(0,G.jsx)(`p`,{className:iU.caption,children:`Plan`}),(0,G.jsx)(FU,{label:`Plan`,plan:r,reading:e.reading?`Reading its state…`:void 0}),(0,G.jsx)(YS,{command:HH(n.root,t.key,r?.deleteBranch??e.deleteBranch,r?.force??!1)})]})},LU=({title:e,label:t,lines:n,more:r})=>(0,G.jsxs)(`div`,{className:iU.section,children:[(0,G.jsx)(`p`,{className:iU.caption,children:(0,G.jsx)(Wg,{text:`${e} · ${String(n.length+r)}`})}),(0,G.jsx)(yU,{label:t,short:!0,children:n.join(`
72
- `)}),r>0?(0,G.jsx)(`p`,{className:iU.note,children:`and ${String(r)} more`}):null]}),RU=({row:e,plan:t,head:n,root:r})=>{let i=(0,V.useRef)(null);(0,V.useEffect)(()=>{i.current?.focus()},[]);let{losing:a}=t,o=`Commits not merged into ${n}`;return(0,G.jsxs)(`div`,{className:iU.step,children:[(0,G.jsx)(`h3`,{className:iU.title,ref:i,tabIndex:-1,children:`What's lost`}),a.changes.length===0?null:(0,G.jsx)(LU,{label:`Uncommitted changes`,lines:a.changes,more:a.more.changes,title:`Uncommitted changes`}),a.commits.length===0?null:(0,G.jsx)(LU,{label:a.commitsOn===`no branch`?`Commits on no branch`:o,lines:a.commits,more:a.more.commits,title:a.commitsOn===`no branch`?`Commits on no branch`:`Commits not merged into \`${n}\``}),(0,G.jsx)(`p`,{className:iU.note,children:XH(t)}),(0,G.jsx)(YS,{command:HH(r,e.key,t.deleteBranch,!0)})]})},zU=e=>`plan`in e?e.plan:e.shown,BU=e=>e.step===`lost`||(e.step===`removing`||e.step===`removeFailed`)&&e.from===`lost`,VU=(e,t,n)=>{let[r,i]=(0,V.useState)(!1),[a,o]=(0,V.useState)({step:`reading`}),s=(0,V.useRef)(0),c=(0,V.useCallback)(async n=>{s.current+=1;let r=s.current,i=await e.call(`worktreeRemovePlan`,{body:{...t,deleteBranch:n}});return r===s.current?i:null},[e,t]),l=(0,V.useCallback)(async(n,r)=>{s.current+=1;let i=s.current,a=await e.call(`worktreeRemovePlan`,{body:{...t,deleteBranch:n}});i===s.current&&o(a.ok?{step:`choice`,plan:a.data,changed:!1}:{step:`readFailed`,error:a.error,...r===void 0?{}:{shown:r}})},[e,t]);(0,V.useEffect)(()=>{l(!1)},[l]);let u=(e,t)=>{o(t===void 0?{step:`reading`}:{step:`reading`,shown:t}),l(e,t)},d=async(i,a)=>{o({step:`removing`,plan:i,from:a});let s=await e.call(`worktreeRemove`,{body:{...t,deleteBranch:r,force:i.force,digest:i.digest}});if(s.ok){n(i);return}if(s.status!==409){o({step:`removeFailed`,plan:i,from:a,error:s.error});return}let l=await c(r);l!==null&&(l.ok&&l.data.digest!==i.digest?o({step:`choice`,plan:l.data,changed:!0}):o({step:`removeFailed`,plan:i,from:a,error:s.error}))};return{step:a,deleteBranch:r,setDeleteBranch:e=>{i(e),u(e,zU(a))},goOn:()=>{a.step===`choice`&&a.plan.force?o({step:`lost`,plan:a.plan}):a.step===`choice`&&d(a.plan,`choice`)},back:()=>{a.step===`lost`&&o({step:`choice`,plan:a.plan,changed:!1})},loseIt:()=>{a.step===`lost`&&d(a.plan,`lost`)},tryAgain:()=>{a.step===`removeFailed`?d(a.plan,a.from):u(r,zU(a))}}},HU=`It changed since you read it. Read it again before removing.`,UU=(e,t)=>e.step===`readFailed`?`Could not read its state: ${e.error}`:e.step===`removeFailed`?`Could not remove ${t}: ${e.error}`:e.step===`choice`&&e.changed?HU:null,WU=e=>e.step===`reading`?`Reading its state…`:e.step===`readFailed`?`Its state couldn't be read; Try again reads it.`:e.step===`choice`?JH(e.plan):null,GU=({client:e,row:t,project:n,target:r,cancel:i,onBusy:a,onRemoved:o,onOpenRun:s,onClose:c})=>{let l=VU(e,r,o),{step:u}=l,d=(0,V.useId)(),f=(0,V.useId)(),p=(0,V.useRef)(null),m=u.step===`removing`,h=zU(u),g=BU(u),_=u.step===`choice`&&u.changed;(0,V.useEffect)(()=>{a(m)},[m,a]);let v=(0,V.useRef)(!1);(0,V.useEffect)(()=>{let e=v.current&&!g;v.current=g,(_||e)&&p.current?.focus()},[_,g]);let y=UU(u,t.label);return(0,G.jsxs)(G.Fragment,{children:[g&&h!==void 0?(0,G.jsx)(RU,{head:n.head??`the current branch`,plan:h,root:n.root,row:t}):(0,G.jsx)(IU,{busy:m,deleteBranch:l.deleteBranch,onDeleteBranch:l.setDeleteBranch,onOpenRun:s,plan:h,project:n,reading:u.step===`reading`,row:t}),(0,G.jsx)(YB,{id:f,onTryAgain:_?void 0:l.tryAgain,takeFocus:u.step===`removeFailed`?`always`:`ifLost`,words:y}),(0,G.jsx)($L,{id:d,why:WU(u)}),(0,G.jsxs)(`div`,{className:iU.foot,children:[g?(0,G.jsx)(q,{disabled:m,focusableWhenDisabled:!0,onClick:l.back,variant:`ghost`,children:`Back`}):null,(0,G.jsx)(q,{disabled:m,focusableWhenDisabled:!0,onClick:c,ref:i,variant:`ghost`,children:`Cancel`}),g?(0,G.jsx)(q,{"aria-describedby":f,disabled:u.step!==`lost`,focusableWhenDisabled:!0,onClick:l.loseIt,variant:`danger`,children:m?`Removing…`:`Remove and lose this work`}):(0,G.jsx)(q,{"aria-describedby":`${d} ${f}`,disabled:u.step!==`choice`,focusableWhenDisabled:!0,onClick:l.goOn,ref:p,variant:h?.force===!0?`default`:`primary`,children:m?`Removing…`:h===void 0?`Remove worktree`:qH(h)})]})]})},KU=({open:e,client:t,row:n,project:r,target:i,finalFocus:a,onRemoved:o,onOpenRun:s,onClose:c})=>{let l=(0,V.useRef)(null),u=(0,V.useRef)(!1),d=()=>{u.current||c()};return(0,G.jsx)(bC,{description:GH(n,r.root),finalFocus:a,initialFocus:l,onOpenChange:e=>{e||d()},open:e,size:`wide`,title:WH(n),children:(0,G.jsx)(GU,{cancel:l,client:t,onBusy:e=>{u.current=e},onClose:d,onOpenRun:s,onRemoved:o,project:r,row:n,target:i})})},qU=({acts:e,project:t,merged:n,load:r})=>{let{client:i}=qy(),{opened:a,open:o}=e;return a?.kind===`remove`?(0,G.jsx)(KU,{client:i,finalFocus:e.removeFocus,onClose:e.close,onOpenRun:()=>{e.openRemovedRun(a.row)},onRemoved:t=>{e.removed(a.row,a.project,t,a.index)},open:o,project:a.project,row:a.row,target:a.target},a.id):a?.kind===`clean`?(0,G.jsx)(jU,{client:i,finalFocus:e.cleanFocus,onCleaned:()=>void r(),onClose:e.cleanClosed,open:o,project:t,scope:n.map(({root:e,name:t,head:n})=>({root:e,name:t,head:n,steps:[]}))},a.id):null},JU=({filter:e,options:t,items:n,updating:r,cleanBlocked:i,cleanButton:a,onFilter:o,onClean:s,onReload:c})=>(0,G.jsxs)(`div`,{className:iU.tools,children:[(0,G.jsx)(Bw,{label:`Project`,onChange:o,options:t,value:e}),(0,G.jsxs)(`div`,{className:iU.toolsEnd,children:[n===null?null:(0,G.jsx)(`span`,{className:iU.count,children:FH(n)}),(0,G.jsx)(`output`,{className:iU.count,children:r?`Updating…`:``}),(0,G.jsx)(q,{"aria-label":i===null?void 0:`Clean merged…: ${i}`,cli:`ork worktrees clean`,disabled:i!==null,focusableWhenDisabled:!0,onClick:s,ref:a,tip:i===null?void 0:`Clean merged…: ${i}`,children:`Clean merged…`}),(0,G.jsx)(q,{cli:`ork worktrees`,onClick:c,tip:`In the project's folder.`,variant:`ghost`,children:`Reload`})]})]}),YU=({error:e})=>(0,G.jsxs)(`p`,{className:iU.alert,role:`alert`,children:[(0,G.jsx)(`span`,{className:iU.alertIcon,children:(0,G.jsx)(yy,{})}),(0,G.jsx)(`span`,{children:(0,G.jsx)(Wg,{text:`Could not read worktrees: ${e}`})})]}),XU=({projects:e,one:t})=>e===0?(0,G.jsxs)(CC,{cli:`ork register <path>`,focusable:!0,title:`No projects registered yet.`,children:[(0,G.jsx)(`p`,{children:`In a repository:`}),(0,G.jsx)(YS,{command:`ork init`}),(0,G.jsx)(`p`,{children:`Or from outside it:`})]}):t===null?(0,G.jsx)(CC,{cli:`ork worktrees`,focusable:!0,title:`No Ork worktrees or branches.`,children:(0,G.jsx)(Wg,{text:"A run with `worktree` nodes leaves a worktree and an `ork/` branch for each; they wait here until you remove them. In a terminal, in a project's folder:"})}):(0,G.jsx)(CC,{focusable:!0,title:`No Ork worktrees or branches in ${t}.`,children:`Project: All projects shows every project's.`}),ZU=(e,t)=>({...e,items:e.items.filter(n=>!t.has(`${e.root}|${n.key}`))}),QU={usage:{title:`Usage`,Icon:gy,Body:MH},context:{title:`Context`,Icon:vy,Body:xB},feedback:{title:`Feedback`,Icon:by,Body:JV},worktrees:{title:`Worktrees`,Icon:Cy,Body:()=>{let e=rU(),{read:t,shown:n,filter:r}=e,i=r===`all`?null:r,{panel:a,onFocus:o}=rL((n??[]).flatMap(e=>e.items.map(t=>`${e.root}|${t.key}`)).join(`
73
- `),`[data-worktree-row]`),s=eU(a,e.load),c=(n??[]).map(e=>ZU(e,s.gone)),l=c.filter(e=>e.items.length>0||e.error!==void 0),u=c.length-l.length,d=c.filter(e=>e.items.some(e=>e.state===`merged`));return(0,G.jsxs)(`div`,{"aria-label":`Worktrees`,className:iU.panel,onFocus:o,onKeyDown:oU,ref:a,role:`group`,tabIndex:-1,children:[(0,G.jsx)(JU,{cleanBlocked:LH(n===null?null:c,i!==null,t.status===`failed`),cleanButton:s.cleanButton,filter:r,items:n===null?null:c.flatMap(e=>e.items),onClean:s.openClean,onFilter:e.setFilter,onReload:()=>void e.load(),options:e.options,updating:t.status===`loading`&&n!==null}),t.status===`failed`?(0,G.jsx)(YU,{error:t.error}):null,n===null&&t.status!==`failed`?(0,G.jsx)(`p`,{className:iU.message,children:`Reading worktrees…`}):null,n!==null&&l.length===0?(0,G.jsx)(XU,{one:i===null?null:c[0]?.name??i,projects:e.all?.length??0}):null,l.map(e=>(0,G.jsx)(cU,{acts:s.rowActs,project:e},e.root)),i===null&&l.length>0&&u>0?(0,G.jsx)(`p`,{className:iU.note,children:`Nothing left in ${NH(u,`other project`)}.`}):null,(0,G.jsx)(qU,{acts:s,load:e.load,merged:d,project:i??void 0})]})}}},$U={runs:{id:`runs`,title:`Runs`,Icon:uy,Body:Bz},monitor:{id:`monitor`,title:`Monitor`,Icon:dy,Body:fz},logs:{id:`logs`,title:`Logs`,Icon:fy,Body:jL},decisions:{id:`decisions`,title:`Decisions`,Icon:py,Body:iL},chats:{id:`chats`,title:`Chats`,Icon:my,Body:XM},notifications:{id:`notifications`,title:`Notifications`,Icon:hy,Body:Tz},usage:{id:`usage`,...QU.usage},builder:{id:`builder`,title:`Builder`,Icon:_y,Body:hM},context:{id:`context`,...QU.context},feedback:{id:`feedback`,...QU.feedback},worktrees:{id:`worktrees`,...QU.worktrees}},eW=Object.values($U),tW=e=>e in $U,nW=e=>$U[e],rW=(e,t)=>e===void 0?void 0:yT(e,t).join(t?``:`+`),iW=(e,t)=>{if(e.wide&&!e.open.includes(t))return e.minimized.includes(t)?`minimized`:`closed`},aW=({workspace:e})=>{let t=ab(e.view),n=ET(),r=[...eW.map(({id:r,title:i},a)=>({label:i,detail:iW(t,r),hint:rW(TT(a+1),n),onSelect:()=>{e.goTo(r)}})),`separator`,{label:`Reset layout`,onSelect:()=>{e.resetLayout()}}];return(0,G.jsx)(AE,{entries:r,trigger:(0,G.jsxs)(q,{variant:`ghost`,children:[`Window`,(0,G.jsx)(Xv,{})]})})},oW=({workspace:e})=>(0,G.jsxs)(`header`,{className:kT.bar,children:[(0,G.jsxs)(`h1`,{className:kT.name,children:[(0,G.jsx)(`img`,{alt:`Ork`,className:kT.logoOnDark,src:`/ork-wordmark-small.svg`}),(0,G.jsx)(`img`,{alt:`Ork`,className:kT.logoOnLight,src:`/ork-wordmark-small-on-light.svg`})]}),(0,G.jsx)(aW,{workspace:e}),(0,G.jsx)(`div`,{className:kT.spacer}),(0,G.jsx)(AT,{workspace:e}),(0,G.jsxs)(q,{onClick:()=>{e.palette.setValue(!0)},variant:`ghost`,children:[(0,G.jsx)(ry,{}),`Commands`,(0,G.jsx)(Kg,{keys:yT(CT.palette,ET())})]})]}),sW,cW=class{constructor(){}},lW=class extends cW{constructor(e,t,n,r){super(),this.viewId=e,this.groupId=t,this.panelId=n,this.tabGroupId=r}},uW=class extends cW{constructor(e,t){super(),this.viewId=e,this.paneId=t}},dW=class e{constructor(){}static getInstance(){return e.INSTANCE}hasData(e){return e&&e===this.proto}clearData(e){this.hasData(e)&&(this.proto=void 0,this.data=void 0)}getData(e){if(this.hasData(e))return this.data}setData(e,t){t&&(this.data=e,this.proto=t)}};sW=dW,dW.INSTANCE=new sW;function fW(){let e=dW.getInstance();if(e.hasData(lW.prototype))return e.getData(lW.prototype)[0]}function pW(){let e=dW.getInstance();if(e.hasData(uW.prototype))return e.getData(uW.prototype)[0]}var mW;(function(e){e.NONE={dispose:()=>{}};function t(e){return{dispose:()=>{e()}}}e.from=t})(mW||={});var Y=class{get isDisposed(){return this._isDisposed}constructor(...e){this._isDisposed=!1,this._disposables=new Set(e)}addDisposables(...e){e.forEach(e=>this._disposables.add(e))}removeDisposable(e){this._disposables.delete(e)}dispose(){this._isDisposed||(this._isDisposed=!0,this._disposables.forEach(e=>e.dispose()),this._disposables.clear())}},hW=class{constructor(){this._disposable=mW.NONE}get value(){return this._disposable===mW.NONE?void 0:this._disposable}set value(e){this._disposable&&this._disposable.dispose(),this._disposable=e}dispose(){this._disposable&&=(this._disposable.dispose(),mW.NONE)}},gW;(function(e){e.map=(e,t)=>n=>e(e=>n(t(e))),e.any=(...e)=>t=>{let n=e.map(e=>e(t));return{dispose:()=>{n.forEach(e=>{e.dispose()})}}}})(gW||={});var _W=class{constructor(){this._defaultPrevented=!1}get defaultPrevented(){return this._defaultPrevented}preventDefault(){this._defaultPrevented=!0}},vW=class{constructor(){this._isAccepted=!1}get isAccepted(){return this._isAccepted}accept(){this._isAccepted=!0}},yW=class{constructor(){this.events=new Map}get size(){return this.events.size}add(e,t){this.events.set(e,t)}delete(e){this.events.delete(e)}clear(){this.events.clear()}},bW=class e{static create(){return new e(Error(`listener stacktrace`).stack??``)}constructor(e){this.value=e}print(){console.warn(`dockview: stacktrace`,this.value)}},xW=class{constructor(e,t){this.callback=e,this.stacktrace=t}},X=class e{static setLeakageMonitorEnabled(t){t!==e.ENABLE_TRACKING&&e.MEMORY_LEAK_WATCHER.clear(),e.ENABLE_TRACKING=t}get value(){return this._last}constructor(e){this.options=e,this._listeners=[],this._disposed=!1}get event(){return this._event||(this._event=t=>{this.options?.replay&&this._last!==void 0&&t(this._last);let n=new xW(t,e.ENABLE_TRACKING?bW.create():void 0);return this._listeners.push(n),{dispose:()=>{let t=this._listeners.indexOf(n);t>-1?this._listeners.splice(t,1):e.ENABLE_TRACKING}}},e.ENABLE_TRACKING&&e.MEMORY_LEAK_WATCHER.add(this._event,bW.create())),this._event}fire(e){if(this._pauseTokens!==void 0&&this._pauseTokens.size>0)return;this.options?.replay&&(this._last=e);let t=this._listeners,n=t.length;if(n!==0){if(n===1)t[0].callback(e);else for(let n of t.slice())n.callback(e)}}pause(){let e={};return this._pauseTokens??=new Set,this._pauseTokens.add(e),mW.from(()=>this._pauseTokens?.delete(e))}dispose(){this._disposed||(this._disposed=!0,this._listeners.length>0&&(e.ENABLE_TRACKING?queueMicrotask(()=>{for(let e of this._listeners)console.warn(`dockview: stacktrace`,e.stacktrace?.print());this._listeners=[]}):this._listeners=[]),e.ENABLE_TRACKING&&this._event&&e.MEMORY_LEAK_WATCHER.delete(this._event))}};X.ENABLE_TRACKING=!1,X.MEMORY_LEAK_WATCHER=new yW;function Z(e,t,n,r){return e.addEventListener(t,n,r),{dispose:()=>{e.removeEventListener(t,n,r)}}}var SW=class{constructor(){this._onFired=new X,this._currentFireCount=0,this._pending=new Set,this._queued=!1,this.onEvent=e=>{let t=this._currentFireCount;return this._onFired.event(n=>{this._currentFireCount>t&&e(n)})}}fire(e){this._currentFireCount++,this._pending.add(e),!this._queued&&(this._queued=!0,queueMicrotask(()=>{this._queued=!1;let e=this._pending;this._pending=new Set,this._onFired.fire(e)}))}dispose(){this._onFired.dispose()}},CW=class extends Y{constructor(e){super(),this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this._value=null,this.addDisposables(this._onDidChange,wW(e,e=>{let t=e.target.scrollWidth>e.target.clientWidth,n=e.target.scrollHeight>e.target.clientHeight;this._value={hasScrollX:t,hasScrollY:n},this._onDidChange.fire(this._value)}))}};function wW(e,t){let n=new Set,r=new ResizeObserver(e=>{let r=!1,i;i=requestAnimationFrame(()=>{r=!0,i!==void 0&&n.delete(i);let a=e[0];t(a)}),r||n.add(i)});return r.observe(e),{dispose:()=>{r.unobserve(e),r.disconnect();for(let e of n)cancelAnimationFrame(e);n.clear()}}}var TW=(e,...t)=>{for(let n of t)e.classList.contains(n)&&e.classList.remove(n)},EW=(e,...t)=>{for(let n of t)e.classList.contains(n)||e.classList.add(n)},Q=(e,t,n)=>{let r=e.classList.contains(t);n&&!r&&e.classList.add(t),!n&&r&&e.classList.remove(t)};function DW(e,t){for(;e;){if(e===t)return!0;e=e.parentNode}return!1}function OW(e){return new kW(e)}var kW=class extends Y{constructor(e){super(),this._onDidFocus=new X,this.onDidFocus=this._onDidFocus.event,this._onDidBlur=new X,this.onDidBlur=this._onDidBlur.event,this.addDisposables(this._onDidFocus,this._onDidBlur);let t=DW($W(e),e),n=!1,r=()=>{n=!1,t||(t=!0,this._onDidFocus.fire())},i=()=>{t&&(n=!0,globalThis.setTimeout(()=>{n&&(n=!1,t=!1,this._onDidBlur.fire())},0))};this._refreshStateHandler=()=>{DW($W(e),e)!==t&&(t?i():r())},this.addDisposables(Z(e,`focus`,r,!0)),this.addDisposables(Z(e,`blur`,i,!0))}refreshState(){this._refreshStateHandler()}},AW=`dv-quasiPreventDefault`;function jW(e){e[AW]=!0}function MW(e){return e[AW]}function NW(e,t){let n=e.composedPath?.call(e)??[];if(n.length>0)return t.some(e=>n.includes(e));let r=e.target;return r instanceof Node&&t.some(e=>e.contains(r))}function PW(e){let t=[],n=e.getRootNode();for(;zW(n);)t.push(n),n=n.host.getRootNode();return t}function FW(e,t){let n=t?.getRootNode(),r=e,i=r.getRootNode();for(;i!==n&&zW(i);)r=i.host,i=r.getRootNode();return r}function IW(e,t,n={}){let r=Array.from(t),{nonce:i}=n,a=typeof i==`function`?i(e):i;for(let t of r){if(t.href){let n=e.createElement(`link`);n.href=t.href,n.type=t.type,n.rel=`stylesheet`,a&&n.setAttribute(`nonce`,a),e.head.appendChild(n);continue}let n=[];try{t.cssRules&&(n=Array.from(t.cssRules).map(e=>e.cssText))}catch(e){console.warn(`dockview: failed to access stylesheet rules due to security restrictions`,e)}let r=e.createDocumentFragment();for(let t of n){let n=e.createElement(`style`);a&&n.setAttribute(`nonce`,a),n.appendChild(e.createTextNode(t)),r.appendChild(n)}e.head.appendChild(r)}}function LW(e){let{left:t,top:n,width:r,height:i}=e.getBoundingClientRect();return{left:t+window.scrollX,top:n+window.scrollY,width:r,height:i}}function RW(e){let t=e;for(;t?.parentNode;)if(t.parentNode===document)return!0;else t=t.parentNode instanceof DocumentFragment?t.parentNode.host:t.parentNode;return!1}function zW(e){return!!e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&`host`in e&&!!e.host}function BW(e){let t=e.getRootNode();return t!==e&&typeof t.elementsFromPoint==`function`?t:e.ownerDocument??document}function VW(e,t){e.dataset.testid=t}function HW(e,t){let n=[];function r(t){if(t.nodeType===Node.ELEMENT_NODE){e.includes(t.tagName)&&n.push(t),t.shadowRoot&&r(t.shadowRoot);for(let e of t.children)r(e)}}return r(t instanceof Document?t.documentElement:t),n}function UW(e=document){let t=HW([`IFRAME`,`WEBVIEW`],e),n=new WeakMap;for(let e of t)n.set(e,e.style.pointerEvents),e.style.pointerEvents=`none`;return{release:()=>{for(let e of t)e.style.pointerEvents=n.get(e)??`auto`;t.splice(0,t.length)}}}function WW(e=document){let t=e instanceof Document?e:e.ownerDocument,n=t?.documentElement;if(!t||!n)return{release:()=>void 0};let r=[`user-select`,`-webkit-user-select`],i=r.map(e=>[e,n.style.getPropertyValue(e)]);for(let e of r)n.style.setProperty(e,`none`);let a=e=>e.preventDefault();return t.addEventListener(`selectstart`,a),{release:()=>{t.removeEventListener(`selectstart`,a);for(let[e,t]of i)t?n.style.setProperty(e,t):n.style.removeProperty(e)}}}function GW(e){function t(e){let t=[];for(let n=0;n<e.classList.length;n++)t.push(e.classList.item(n));return t}let n,r=e;for(;r!==null&&(n=t(r).find(e=>e.startsWith(`dockview-theme-`)),typeof n!=`string`);)if(r.parentElement===null){let e=r.getRootNode();r=zW(e)?e.host:null}else r=r.parentElement;return n}var KW=class{constructor(e){this.element=e,this._classNames=[]}setClassNames(e){for(let e of this._classNames)Q(this.element,e,!1);this._classNames=e.split(` `).filter(e=>e.trim().length>0);for(let e of this._classNames)Q(this.element,e,!0)}},qW=100;function JW(e,t){let n=LW(e),r=LW(t);return!(n.left<r.left||n.left+n.width>r.left+r.width||n.top<r.top||n.top+n.height>r.top+r.height)}function YW(e){let t=new X,n=e.screenX,r=e.screenY,i,a=0,o=!1,s=()=>{if(o||e.closed)return;let c=e.screenX,l=e.screenY;(c!==n||l!==r)&&(clearTimeout(i),i=setTimeout(()=>{t.fire()},qW),n=c,r=l),a=requestAnimationFrame(s)};s();let c=t.dispose.bind(t);return t.dispose=()=>{o||(o=!0,cancelAnimationFrame(a),clearTimeout(i)),c()},t}function XW(e,t){let n;return new Y(Z(e,`resize`,()=>{clearTimeout(n),n=setTimeout(()=>{t()},qW)}),mW.from(()=>clearTimeout(n)))}function ZW(e,t,n){let r=n?.buffer??10,i=e.getBoundingClientRect(),a=t.getBoundingClientRect(),o=0,s=0,c=i.left-a.left,l=i.top-a.top,u=i.bottom-a.bottom,d=i.right-a.right;c<r?o=r-c:d>r&&(o=-r-d),l<r?s=r-l:u>r&&(s=-u-r),(o!==0||s!==0)&&(e.style.transform=`translate(${o}px, ${s}px)`)}function QW(e){let t=e;for(;t&&(t.style.zIndex===`auto`||t.style.zIndex===``);)t=t.parentElement;return t}function $W(e){let t=e.getRootNode(),n=t.nodeType===Node.DOCUMENT_NODE?t:e.ownerDocument;return n&&typeof n.hasFocus==`function`&&!n.hasFocus()?null:t.activeElement??null}function eG(e){let t=e.getRootNode();return zW(t)?t:(e.ownerDocument??document).body}function tG(e,t,n,r,i,a,o){try{var s=e[a](o),c=s.value}catch(e){n(e);return}s.done?t(c):Promise.resolve(c).then(r,i)}function nG(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var a=e.apply(t,n);function o(e){tG(a,r,i,o,s,`next`,e)}function s(e){tG(a,r,i,o,s,`throw`,e)}o(void 0)})}}function rG(e){let t=oG(e);if(t)throw t}var iG=new Set([`javascript:`,`data:`,`blob:`,`vbscript:`,`file:`]),aG=250;function oG(e,t=globalThis.location){let n;try{n=new URL(e,t.href)}catch{return Error(`dockview: invalid popout URL: ${e}`)}if(iG.has(n.protocol))return Error(`dockview: popout URL must not use the "${n.protocol}" protocol, which would run in the opener's context; got: ${e}`);if(n.protocol!==t.protocol||n.host!==t.host)return Error(`dockview: popout URL must be same-origin with the page (${t.protocol}//${t.host}); got: ${e}`)}var sG=class extends Y{get window(){return this._window?.value??null}get failure(){return this._failure}constructor(e,t,n){super(),this.target=e,this.className=t,this.options=n,this._onWillClose=new X,this.onWillClose=this._onWillClose.event,this._onDidClose=new X,this.onDidClose=this._onDidClose.event,this._window=null,this.addDisposables(this._onWillClose,this._onDidClose)}dispose(){this.close(),super.dispose()}dimensions(){if(!this._window)return null;let e=this._window.value.screenX;return{top:this._window.value.screenY,left:e,width:this._window.value.innerWidth,height:this._window.value.innerHeight}}close(){var e,t;let n=this._window;n&&(this._window=null,this._onWillClose.fire(),(e=(t=this.options).onWillClose)==null||e.call(t,{id:this.target,window:n.value}),n.disposable.dispose(),this._onDidClose.fire())}open(){var e=this;return nG(function*(){var t,n;if(e._window)throw Error(`instance of popout window is already open`);let r=`${e.options.url}`;rG(r);let i=Object.entries({top:e.options.top,left:e.options.left,width:e.options.width,height:e.options.height}).map(([e,t])=>`${e}=${t}`).join(`,`),a=window.open(r,e.target,i);if(!a)return e._failure={reason:`blocked`},null;let o=new Y;e._window={value:a,disposable:o},o.addDisposables(mW.from(()=>{a.close()}),e.watchForClose(a),Z(globalThis.window,`beforeunload`,()=>{e.close()}));let s=e.createPopoutWindowContainer();return e.className&&s.classList.add(e.className),(t=(n=e.options).onDidOpen)==null||t.call(n,{id:e.target,window:a}),new Promise(t=>{let n=n=>{e._failure={reason:`unscriptable`,error:n instanceof Error?n:Error(String(n))},e.close(),t(null)};try{a.addEventListener(`unload`,()=>{})}catch(e){n(e);return}o.addDisposables(e.onWillClose(()=>{e._failure??={reason:`closed`},t(null)})),a.addEventListener(`load`,()=>{try{var r;let n=a.document;n.title=document.title,n.body.appendChild(s),IW(n,[...Array.from(globalThis.document.styleSheets),...globalThis.document.adoptedStyleSheets??[]],{nonce:e.options.nonce});let i=[];for(let t=(r=e.options).styleRoot?.call(r);zW(t);t=t.host.getRootNode())i.push(...Array.from(t.styleSheets??[]),...t.adoptedStyleSheets??[]);i.length>0&&IW(n,i,{nonce:e.options.nonce}),Z(a,`beforeunload`,()=>{e.close()}),t(s)}catch(e){n(e)}})})})()}watchForClose(e){if(typeof e.closed!=`boolean`)return mW.NONE;let t=setInterval(()=>{e.closed&&this.close()},aG);return mW.from(()=>{clearInterval(t)})}createPopoutWindowContainer(){let e=document.createElement(`div`);return e.classList.add(`dv-popout-window`),e.id=`dv-popout-window`,e.style.position=`absolute`,e.style.width=`100%`,e.style.height=`100%`,e.style.top=`0px`,e.style.left=`0px`,e}};function cG(e){if(e.length===0)throw Error(`Invalid tail call`);return[e.slice(0,e.length-1),e[e.length-1]]}function lG(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function uG(e,t){let n=e.indexOf(t);n>-1&&(e.splice(n,1),e.unshift(t))}function dG(e,t){let n=e.indexOf(t);n>-1&&(e.splice(n,1),e.push(t))}function fG(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(t(r))return n}return-1}function pG(e,t){let n=e.indexOf(t);return n>-1&&(e.splice(n,1),!0)}var mG=(e,t,n)=>t>n?t:Math.min(n,Math.max(e,t)),hG=()=>{let e=1;return{next:()=>(e++).toString()}},gG=(e,t)=>{let n=[];if(typeof t!=`number`&&(t=e,e=0),e<=t)for(let r=e;r<t;r++)n.push(r);else for(let r=e;r>t;r--)n.push(r);return n},_G=class{set size(e){this._size=e}setContainerGeometry(e,t){this._appliedStyles[e]!==t&&(this._appliedStyles[e]=t,this.container.style[e]=t)}get size(){return this._size}get cachedVisibleSize(){return this._cachedVisibleSize}get visible(){return this._cachedVisibleSize===void 0}get minimumSize(){return this.visible?this.view.minimumSize:0}get viewMinimumSize(){return this.view.minimumSize}get maximumSize(){return this.visible?this.view.maximumSize:0}get viewMaximumSize(){return this.view.maximumSize}get priority(){return this.view.priority}get snap(){return!!this.view.snap}set enabled(e){this.container.style.pointerEvents=e?``:`none`}constructor(e,t,n,r){this.container=e,this.view=t,this.disposable=r,this._cachedVisibleSize=void 0,this._appliedStyles={},typeof n==`number`?(this._size=n,this._cachedVisibleSize=void 0,e.classList.add(`visible`)):(this._size=0,this._cachedVisibleSize=n.cachedVisibleSize)}setVisible(e,t){if(e!==this.visible){if(e){let e=this._cachedVisibleSize??0;this._cachedVisibleSize=void 0,this.size=mG(e,this.viewMinimumSize,this.viewMaximumSize)}else this._cachedVisibleSize=typeof t==`number`?t:this.size,this.size=0;this.container.classList.toggle(`visible`,e),this.view.setVisible&&this.view.setVisible(e)}}scale(e){this._cachedVisibleSize===void 0?this.size=mG(Math.round(this.size*e),this.minimumSize,this.maximumSize):this._cachedVisibleSize=Math.round(this._cachedVisibleSize*e)}dispose(){return this.disposable.dispose(),this.view}},vG=function(e){return e.HORIZONTAL=`HORIZONTAL`,e.VERTICAL=`VERTICAL`,e}({});function yG(e,t,n){e.appliedLeft!==t&&(e.appliedLeft=t,e.container.style.left=t),e.appliedTop!==n&&(e.appliedTop=n,e.container.style.top=n)}var bG;(function(e){e.Distribute={type:`distribute`};function t(e){return{type:`split`,index:e}}e.Split=t;function n(e){return{type:`invisible`,cachedVisibleSize:e}}e.Invisible=n})(bG||={});var xG=class{get contentSize(){return this._contentSize}get size(){return this._size}set size(e){this._size=e}get orthogonalSize(){return this._orthogonalSize}set orthogonalSize(e){this._orthogonalSize=e}get length(){return this.viewItems.length}get proportions(){return this._proportions?[...this._proportions]:void 0}get proportionalLayout(){return this._proportionalLayout}set proportionalLayout(e){this._proportionalLayout!==e&&(this._proportionalLayout=e,e?this.saveProportions():this._proportions=void 0)}get orientation(){return this._orientation}set orientation(e){if(this._orientation===e)return;this._orientation=e;let t=this.size;this.size=this.orthogonalSize,this.orthogonalSize=t,this.rescaleViews(this.size),TW(this.element,`dv-horizontal`,`dv-vertical`),this.element.classList.add(this.orientation==`HORIZONTAL`?`dv-horizontal`:`dv-vertical`)}get minimumSize(){return this.viewItems.reduce((e,t)=>e+t.minimumSize,0)}get maximumSize(){return this.length===0?1/0:this.viewItems.reduce((e,t)=>e+t.maximumSize,0)}get startSnappingEnabled(){return this._startSnappingEnabled}set startSnappingEnabled(e){this._startSnappingEnabled!==e&&(this._startSnappingEnabled=e,this.updateSashEnablement())}get endSnappingEnabled(){return this._endSnappingEnabled}set endSnappingEnabled(e){this._endSnappingEnabled!==e&&(this._endSnappingEnabled=e,this.updateSashEnablement())}get disabled(){return this._disabled}set disabled(e){this._disabled=e,Q(this.element,`dv-splitview-disabled`,e)}get margin(){return this._margin}get marginShare(){let e=0;for(let t of this.viewItems)t.visible&&e++;return this.marginShareFor(e)}set margin(e){this._margin=e,Q(this.element,`dv-splitview-has-margin`,e!==0)}constructor(e,t){this.container=e,this.viewItems=[],this.sashes=[],this._size=0,this._orthogonalSize=0,this._contentSize=0,this._proportions=void 0,this._startSnappingEnabled=!0,this._endSnappingEnabled=!0,this._disabled=!1,this._margin=0,this._onDidSashEnd=new X,this.onDidSashEnd=this._onDidSashEnd.event,this._onDidAddView=new X,this.onDidAddView=this._onDidAddView.event,this._onDidRemoveView=new X,this.onDidRemoveView=this._onDidRemoveView.event,this.resize=(e,t,n=this.viewItems.map(e=>e.size),r,i,a=-1/0,o=1/0,s,c)=>{if(e<0||e>this.viewItems.length)return 0;let l=gG(e,-1),u=gG(e+1,this.viewItems.length);if(i)for(let e of i)uG(l,e),uG(u,e);if(r)for(let e of r)dG(l,e),dG(u,e);let d=l.reduce((e,t)=>e+this.viewItems[t].minimumSize-n[t],0),f=l.reduce((e,t)=>e+this.viewItems[t].maximumSize-n[t],0),p=u.length===0?1/0:u.reduce((e,t)=>e+n[t]-this.viewItems[t].minimumSize,0),m=u.length===0?-1/0:u.reduce((e,t)=>e+n[t]-this.viewItems[t].maximumSize,0),h=Math.max(d,m),g=Math.min(p,f),_=!1;if(s){let e=this.viewItems[s.index],n=t>=s.limitDelta;_=n!==e.visible,e.setVisible(n,s.size)}if(!_&&c){let e=this.viewItems[c.index],n=t<c.limitDelta;_=n!==e.visible,e.setVisible(n,c.size)}if(_)return this.resize(e,t,n,r,i,a,o);let v=mG(t,h,g),y=0,b=v;for(let e of l){let t=this.viewItems[e],r=n[e],i=mG(r+b,t.minimumSize,t.maximumSize),a=i-r;y+=a,b-=a,t.size=i}let x=y;for(let e of u){let t=this.viewItems[e],r=n[e],i=mG(r-x,t.minimumSize,t.maximumSize),a=i-r;x+=a,t.size=i}return t},this._orientation=t.orientation??`VERTICAL`,this.element=this.createContainer(),this.margin=t.margin??0,this._proportionalLayout=t.proportionalLayout===void 0||!!t.proportionalLayout,this.viewContainer=this.createViewContainer(),this.sashContainer=this.createSashContainer(),this.element.appendChild(this.sashContainer),this.element.appendChild(this.viewContainer),this.container.appendChild(this.element),this.style(t.styles),t.descriptor&&(this._size=t.descriptor.size,t.descriptor.views.forEach((e,t)=>{let n=e.visible===void 0||e.visible?e.size:{type:`invisible`,cachedVisibleSize:e.size},r=e.view;this.addView(r,n,t,!0)}),this._contentSize=this.viewItems.reduce((e,t)=>e+t.size,0),this.saveProportions())}style(e){e?.separatorBorder===`transparent`?(TW(this.element,`dv-separator-border`),this.element.style.removeProperty(`--dv-separator-border`)):(EW(this.element,`dv-separator-border`),e?.separatorBorder&&this.element.style.setProperty(`--dv-separator-border`,e.separatorBorder))}isViewVisible(e){if(e<0||e>=this.viewItems.length)throw Error(`Index out of bounds`);return this.viewItems[e].visible}setViewVisible(e,t){if(e<0||e>=this.viewItems.length)throw Error(`Index out of bounds`);let n=this.viewItems[e];n.setVisible(t,n.size),this.distributeEmptySpace(e),this.layoutViews(),this.saveProportions()}getViewSize(e){return e<0||e>=this.viewItems.length?-1:this.viewItems[e].size}resizeView(e,t){if(e<0||e>=this.viewItems.length)return;let n=gG(this.viewItems.length).filter(t=>t!==e),r=[...n.filter(e=>this.viewItems[e].priority===`low`),e],i=n.filter(e=>this.viewItems[e].priority===`high`),a=this.viewItems[e];t=Math.round(t),t=mG(t,a.minimumSize,Math.min(a.maximumSize,this._size)),a.size=t,this.relayout(r,i)}getViews(){return this.viewItems.map(e=>e.view)}onDidChange(e,t){let n=this.viewItems.indexOf(e);if(n<0||n>=this.viewItems.length)return;t=typeof t==`number`?t:e.size,t=mG(t,e.minimumSize,e.maximumSize),e.size=t;let r=gG(this.viewItems.length).filter(e=>e!==n),i=[...r.filter(e=>this.viewItems[e].priority===`low`),n],a=r.filter(e=>this.viewItems[e].priority===`high`);this.relayout([...i,n],a)}addView(e,t=bG.Distribute,n=this.viewItems.length,r){let i=document.createElement(`div`);i.className=`dv-view`,i.appendChild(e.element);let a;if(typeof t==`number`)a=t;else if(t.type===`split`){let e=this.viewItems[t.index];if(e){let t=Math.floor(e.size/2);a=e.size-t,e.size=t}else a=this.getViewSize(t.index)/2}else a=t.type===`invisible`?{cachedVisibleSize:t.cachedVisibleSize}:e.minimumSize;let o=e.onDidChange(e=>this.onDidChange(s,e.size)),s=new _G(i,e,a,{dispose:()=>{o.dispose(),i.remove()}});if(n===this.viewItems.length?this.viewContainer.appendChild(i):this.viewContainer.insertBefore(i,this.viewContainer.children.item(n)),this.viewItems.splice(n,0,s),this.viewItems.length>1){let e=document.createElement(`div`);e.className=`dv-sash`;let t=t=>{for(let e of this.viewItems)e.enabled=!1;let n=e.ownerDocument??document,r=UW(n),i=this._orientation===`HORIZONTAL`?t.clientX:t.clientY,a=fG(this.sashes,t=>t.container===e),o=this.viewItems.map(e=>e.size),s,c,l=gG(a,-1),u=gG(a+1,this.viewItems.length),d=l.reduce((e,t)=>e+(this.viewItems[t].minimumSize-o[t]),0),f=l.reduce((e,t)=>e+(this.viewItems[t].viewMaximumSize-o[t]),0),p=u.length===0?1/0:u.reduce((e,t)=>e+(o[t]-this.viewItems[t].minimumSize),0),m=u.length===0?-1/0:u.reduce((e,t)=>e+(o[t]-this.viewItems[t].viewMaximumSize),0),h=Math.max(d,m),g=Math.min(p,f),_=this.findFirstSnapIndex(l),v=this.findFirstSnapIndex(u);if(typeof _==`number`){let e=this.viewItems[_],t=Math.floor(e.viewMinimumSize/2);s={index:_,limitDelta:e.visible?h-t:h+t,size:e.size}}if(typeof v==`number`){let e=this.viewItems[v],t=Math.floor(e.viewMinimumSize/2);c={index:v,limitDelta:e.visible?g+t:g-t,size:e.size}}let y=e=>{let t=(this._orientation===`HORIZONTAL`?e.clientX:e.clientY)-i;this.resize(a,t,o,void 0,void 0,h,g,s,c),this.distributeEmptySpace(),this.layoutViews()},b=()=>{for(let e of this.viewItems)e.enabled=!0;r.release(),this.saveProportions(),n.removeEventListener(`pointermove`,y),n.removeEventListener(`pointerup`,b),n.removeEventListener(`pointercancel`,b),n.removeEventListener(`contextmenu`,b),this._onDidSashEnd.fire(void 0)};n.addEventListener(`pointermove`,y),n.addEventListener(`pointerup`,b),n.addEventListener(`pointercancel`,b),n.addEventListener(`contextmenu`,b)};e.addEventListener(`pointerdown`,t);let n={container:e,disposable:()=>{e.removeEventListener(`pointerdown`,t),e.remove()}};this.sashContainer.appendChild(e),this.sashes.push(n)}r||this.relayout([n]),!r&&typeof t!=`number`&&t.type===`distribute`&&this.distributeViewSizes(),this._onDidAddView.fire(e)}distributeViewSizes(){let e=[],t=0;for(let n of this.viewItems)n.maximumSize-n.minimumSize>0&&(e.push(n),t+=n.size);let n=Math.floor(t/e.length);for(let t of e)t.size=mG(n,t.minimumSize,t.maximumSize);let r=gG(this.viewItems.length),i=r.filter(e=>this.viewItems[e].priority===`low`),a=r.filter(e=>this.viewItems[e].priority===`high`);this.relayout(i,a)}removeView(e,t,n=!1){let r=this.viewItems.splice(e,1)[0];if(r.dispose(),this.viewItems.length>=1){let t=Math.max(e-1,0);this.sashes.splice(t,1)[0].disposable()}return n||this.relayout(),t?.type===`distribute`&&this.distributeViewSizes(),this._onDidRemoveView.fire(r.view),r.view}getViewCachedVisibleSize(e){if(e<0||e>=this.viewItems.length)throw Error(`Index out of bounds`);return this.viewItems[e].cachedVisibleSize}moveView(e,t){let n=this.getViewCachedVisibleSize(e),r=n===void 0?this.getViewSize(e):bG.Invisible(n),i=this.removeView(e,void 0,!0);this.addView(i,r,t)}layout(e,t){let n=Math.max(this.size,this._contentSize);if(this.size=e,this.orthogonalSize=t,this._proportions||this.saveProportions(),this.proportions){let t=0;for(let n=0;n<this.viewItems.length;n++){let r=this.viewItems[n],i=this.proportions[n];typeof i==`number`?t+=i:e-=r.size}for(let n=0;n<this.viewItems.length;n++){let r=this.viewItems[n],i=this.proportions[n];typeof i==`number`&&t>0&&(r.size=mG(Math.round(i*e/t),r.minimumSize,r.maximumSize))}}else{let t=gG(this.viewItems.length),r=t.filter(e=>this.viewItems[e].priority===`low`),i=t.filter(e=>this.viewItems[e].priority===`high`);this.resize(this.viewItems.length-1,e-n,void 0,r,i)}this.distributeEmptySpace(),this.layoutViews()}relayout(e,t){let n=this.viewItems.reduce((e,t)=>e+t.size,0);this.resize(this.viewItems.length-1,this._size-n,void 0,e,t),this.distributeEmptySpace(),this.layoutViews(),this.saveProportions()}distributeEmptySpace(e){let t=0;for(let e of this.viewItems)t+=e.size;let n=this.size-t;if(n===0)return;let r=gG(this.viewItems.length-1,-1),i=!1;for(let e of this.viewItems)if(e.priority===`low`||e.priority===`high`){i=!0;break}if(i){let e=r.filter(e=>this.viewItems[e].priority===`low`),t=r.filter(e=>this.viewItems[e].priority===`high`);for(let e of t)uG(r,e);for(let t of e)dG(r,t)}typeof e==`number`&&dG(r,e);for(let e=0;n!==0&&e<r.length;e++){let t=this.viewItems[r[e]],i=mG(t.size+n,t.minimumSize,t.maximumSize),a=i-t.size;n-=a,t.size=i}}rescaleViews(e){let t=0;for(let e of this.viewItems)t+=e.size;if(e<=0||t<=0)return;let n=e/t,r=0;for(let e of this.viewItems)e.scale(n),r+=e.size;this._contentSize=r}saveProportions(){if(!this.proportionalLayout)return;let e=0;for(let t of this.viewItems)e+=t.size;e>0&&(this._proportions=this.viewItems.map(t=>t.visible?t.size/e:void 0))}layoutViews(){let e=0,t=0;for(let n of this.viewItems)e+=n.size,n.visible&&t++;if(this._contentSize=e,this.updateSashEnablement(),this.viewItems.length===0)return;let n=Math.max(0,t-1),r=this.marginShareFor(t),i=0,a=[],o=0;this.viewItems.forEach((e,t)=>{i+=this.viewItems[t].size,a.push(i),o+=+!!e.visible;let s=e.visible?e.size-r:0,c=Math.max(0,o-1),l=t===0||c===0?0:a[t-1]+c/n*r;if(t<this.viewItems.length-1){let n=e.visible?l+s-2+this.margin/2:l,r=this.sashes[t];this._orientation===`HORIZONTAL`&&yG(r,`${n}px`,`0px`),this._orientation===`VERTICAL`&&yG(r,`0px`,`${n}px`)}this._orientation===`HORIZONTAL`&&(e.setContainerGeometry(`width`,`${s}px`),e.setContainerGeometry(`left`,`${l}px`),e.setContainerGeometry(`top`,``),e.setContainerGeometry(`height`,``)),this._orientation===`VERTICAL`&&(e.setContainerGeometry(`height`,`${s}px`),e.setContainerGeometry(`top`,`${l}px`),e.setContainerGeometry(`width`,``),e.setContainerGeometry(`left`,``)),e.view.layout(s,this._orthogonalSize)})}marginShareFor(e){let t=Math.max(0,e-1);return this._margin*t/Math.max(1,e)}findFirstSnapIndex(e){for(let t of e){let e=this.viewItems[t];if(e.visible&&e.snap)return t}for(let t of e){let e=this.viewItems[t];if(e.visible&&e.maximumSize-e.minimumSize>0)return;if(!e.visible&&e.snap)return t}}updateSashEnablement(){if(this.sashes.length===0)return;let e=!1,t=this.viewItems.map(t=>e=t.size-t.minimumSize>0||e);e=!1;let n=this.viewItems.map(t=>e=t.maximumSize-t.size>0||e),r=[...this.viewItems].reverse();e=!1;let i=r.map(t=>e=t.size-t.minimumSize>0||e).reverse();e=!1;let a=r.map(t=>e=t.maximumSize-t.size>0||e).reverse(),o=0;for(let e=0;e<this.sashes.length;e++){let r=this.sashes[e],s=this.viewItems[e];o+=s.size;let c=!(t[e]&&a[e+1]),l=!(n[e]&&i[e+1]);if(c&&l){let n=gG(e,-1),a=gG(e+1,this.viewItems.length),s=this.findFirstSnapIndex(n),c=this.findFirstSnapIndex(a),l=typeof s==`number`&&!this.viewItems[s].visible,u=typeof c==`number`&&!this.viewItems[c].visible;l&&i[e]&&(o>0||this.startSnappingEnabled)?this.updateSash(r,1):u&&t[e]&&(o<this._contentSize||this.endSnappingEnabled)?this.updateSash(r,0):this.updateSash(r,2)}else c&&!l?this.updateSash(r,1):!c&&l?this.updateSash(r,0):this.updateSash(r,3)}}updateSash(e,t){Q(e.container,`dv-disabled`,t===2),Q(e.container,`dv-enabled`,t===3),Q(e.container,`dv-maximum`,t===0),Q(e.container,`dv-minimum`,t===1)}createViewContainer(){let e=document.createElement(`div`);return e.className=`dv-view-container`,e}createSashContainer(){let e=document.createElement(`div`);return e.className=`dv-sash-container`,e}createContainer(){let e=document.createElement(`div`);return e.className=`dv-split-view-container ${this._orientation===`HORIZONTAL`?`dv-horizontal`:`dv-vertical`}`,e}dispose(){this._onDidSashEnd.dispose(),this._onDidAddView.dispose(),this._onDidRemoveView.dispose();for(let e=0;e<this.element.children.length;e++)if(this.element.children.item(e)===this.element){this.element.remove();break}for(let e of this.viewItems)e.dispose();this.element.remove()}},SG=Object.keys({orientation:void 0,descriptor:void 0,proportionalLayout:void 0,styles:void 0,margin:void 0,disableAutoResizing:void 0,className:void 0}),CG=class extends Y{get onDidAddView(){return this.splitview.onDidAddView}get onDidRemoveView(){return this.splitview.onDidRemoveView}get minimumSize(){return this.splitview.minimumSize}get maximumSize(){return this.splitview.maximumSize}get orientation(){return this.splitview.orientation}get size(){return this.splitview.size}get orthogonalSize(){return this.splitview.orthogonalSize}constructor(e,t){super(),this.paneItems=[],this.skipAnimation=!1,this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this._orientation=t.orientation??`VERTICAL`,this.element=document.createElement(`div`),this.element.className=`dv-pane-container`,e.appendChild(this.element),this.splitview=new xG(this.element,{orientation:this._orientation,proportionalLayout:!1,descriptor:t.descriptor}),this.getPanes().forEach(e=>{let t=new Y(e.onDidChangeExpansionState(()=>{this.setupAnimation(),this._onDidChange.fire(void 0)})),n={pane:e,disposable:{dispose:()=>{t.dispose()}}};this.paneItems.push(n),e.orthogonalSize=this.splitview.orthogonalSize}),this.addDisposables(this._onDidChange,this.splitview.onDidSashEnd(()=>{this._onDidChange.fire(void 0)}),this.splitview.onDidAddView(()=>{this._onDidChange.fire()}),this.splitview.onDidRemoveView(()=>{this._onDidChange.fire()}))}setViewVisible(e,t){this.splitview.setViewVisible(e,t)}addPane(e,t,n=this.splitview.length,r=!1){let i=e.onDidChangeExpansionState(()=>{this.setupAnimation(),this._onDidChange.fire(void 0)}),a={pane:e,disposable:{dispose:()=>{i.dispose()}}};this.paneItems.splice(n,0,a),e.orthogonalSize=this.splitview.orthogonalSize,this.splitview.addView(e,t,n,r)}getViewSize(e){return this.splitview.getViewSize(e)}getViewCachedVisibleSize(e){return this.splitview.getViewCachedVisibleSize(e)}getPanes(){return this.splitview.getViews()}removePane(e,t){if(e<0||e>=this.paneItems.length)throw Error(`Index out of bounds`);let n=this.paneItems.splice(e,1)[0];return this.splitview.removeView(e),t?.skipDispose||(n.disposable.dispose(),n.pane.dispose()),n}moveView(e,t){if(e===t)return;let n=this.getViewCachedVisibleSize(e),r=this.removePane(e,{skipDispose:!0}),i=n===void 0?r.pane.size:bG.Invisible(n);r.disposable.dispose(),this.skipAnimation=!0;try{this.addPane(r.pane,i,t,!1)}finally{this.skipAnimation=!1}}layout(e,t){this.splitview.layout(e,t)}setupAnimation(){this.skipAnimation||(this.animationTimer&&=(clearTimeout(this.animationTimer),void 0),EW(this.element,`dv-animated`),this.animationTimer=setTimeout(()=>{this.animationTimer=void 0,TW(this.element,`dv-animated`)},200))}dispose(){super.dispose(),this.animationTimer&&=(clearTimeout(this.animationTimer),void 0),this.paneItems.forEach(e=>{e.disposable.dispose(),e.pane.dispose()}),this.paneItems=[],this.splitview.dispose(),this.element.remove()}},wG=class{get minimumWidth(){return this.view.minimumWidth}get maximumWidth(){return this.view.maximumWidth}get minimumHeight(){return this.view.minimumHeight}get maximumHeight(){return this.view.maximumHeight}get priority(){return this.view.priority}get snap(){return this.view.snap}get minimumSize(){return this.orientation===`HORIZONTAL`?this.minimumHeight:this.minimumWidth}get maximumSize(){return this.orientation===`HORIZONTAL`?this.maximumHeight:this.maximumWidth}get minimumOrthogonalSize(){return this.orientation===`HORIZONTAL`?this.minimumWidth:this.minimumHeight}get maximumOrthogonalSize(){return this.orientation===`HORIZONTAL`?this.maximumWidth:this.maximumHeight}get orthogonalSize(){return this._orthogonalSize}get size(){return this._size}get element(){return this.view.element}get width(){return this.orientation===`HORIZONTAL`?this.orthogonalSize:this.size}get height(){return this.orientation===`HORIZONTAL`?this.size:this.orthogonalSize}constructor(e,t,n,r=0){this.view=e,this.orientation=t,this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this._orthogonalSize=n,this._size=r,this._disposable=this.view.onDidChange(e=>{e?this._onDidChange.fire({size:this.orientation===`VERTICAL`?e.width:e.height,orthogonalSize:this.orientation===`VERTICAL`?e.height:e.width}):this._onDidChange.fire({})})}setVisible(e){this.view.setVisible&&this.view.setVisible(e)}layout(e,t){this._size=e,this._orthogonalSize=t,this.view.layout(this.width,this.height)}dispose(){this._onDidChange.dispose(),this._disposable.dispose()}},TG=class e extends Y{get width(){return this.orientation===`HORIZONTAL`?this.size:this.orthogonalSize}get height(){return this.orientation===`HORIZONTAL`?this.orthogonalSize:this.size}get minimumSize(){if(this._cachedMinimumSize===void 0){let e=0;for(let t=0;t<this.children.length;t++)this.splitview.isViewVisible(t)&&(e=Math.max(e,this.children[t].minimumOrthogonalSize));this._cachedMinimumSize=e}return this._cachedMinimumSize}get maximumSize(){if(this._cachedMaximumSize===void 0){let e=1/0;for(let t=0;t<this.children.length;t++)this.splitview.isViewVisible(t)&&(e=Math.min(e,this.children[t].maximumOrthogonalSize));this._cachedMaximumSize=e}return this._cachedMaximumSize}get minimumOrthogonalSize(){return this.splitview.minimumSize}get maximumOrthogonalSize(){return this.splitview.maximumSize}get orthogonalSize(){return this._orthogonalSize}get size(){return this._size}get minimumWidth(){return this.orientation===`HORIZONTAL`?this.minimumOrthogonalSize:this.minimumSize}get minimumHeight(){return this.orientation===`HORIZONTAL`?this.minimumSize:this.minimumOrthogonalSize}get maximumWidth(){return this.orientation===`HORIZONTAL`?this.maximumOrthogonalSize:this.maximumSize}get maximumHeight(){return this.orientation===`HORIZONTAL`?this.maximumSize:this.maximumOrthogonalSize}get priority(){return this._cachedPriority??=this.computePriority(),this._cachedPriority}computePriority(){if(this.children.length===0)return`normal`;let e=!1,t=!1;for(let n of this.children){let r=n.priority??`normal`;r===`high`?e=!0:r===`low`&&(t=!0)}return e?`high`:t?`low`:`normal`}invalidateCachedSizes(){this._cachedMinimumSize=void 0,this._cachedMaximumSize=void 0,this._cachedPriority=void 0,this._onDidInvalidateSizes.fire()}get disabled(){return this.splitview.disabled}set disabled(e){this.splitview.disabled=e}get margin(){return this.splitview.margin}set margin(t){this.splitview.margin=t,this.children.forEach(n=>{n instanceof e&&(n.margin=t)})}get proportionalLayout(){return this.splitview.proportionalLayout}set proportionalLayout(t){this.splitview.proportionalLayout=t,this.children.forEach(n=>{n instanceof e&&(n.proportionalLayout=t)})}constructor(e,t,n,r,i,a,o,s){if(super(),this.orientation=e,this.styles=n,this._childrenDisposable=mW.NONE,this.children=[],this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this._onDidVisibilityChange=new X,this.onDidVisibilityChange=this._onDidVisibilityChange.event,this._onDidInvalidateSizes=new X,this.onDidInvalidateSizes=this._onDidInvalidateSizes.event,this._orthogonalSize=i,this._size=r,this.element=document.createElement(`div`),this.element.className=`dv-branch-node`,s){let e={views:s.map(e=>({view:e.node,size:e.node.size,visible:e.visible??!0})),size:this.orthogonalSize};this.children=s.map(e=>e.node),this.splitview=new xG(this.element,{orientation:this.orientation,descriptor:e,proportionalLayout:t,styles:n,margin:o})}else this.splitview=new xG(this.element,{orientation:this.orientation,proportionalLayout:t,styles:n,margin:o}),this.splitview.layout(this.size,this.orthogonalSize);this.disabled=a,this.addDisposables(this._onDidChange,this._onDidVisibilityChange,this._onDidInvalidateSizes,this.splitview.onDidSashEnd(()=>{this._onDidChange.fire({})})),this.setupChildrenEvents()}setVisible(e){}isChildVisible(e){if(e<0||e>=this.children.length)throw Error(`Invalid index`);return this.splitview.isViewVisible(e)}setChildVisible(e,t){if(e<0||e>=this.children.length)throw Error(`Invalid index`);if(this.splitview.isViewVisible(e)===t)return;let n=this.splitview.contentSize===0;this.splitview.setViewVisible(e,t),this.invalidateCachedSizes();let r=this.splitview.contentSize===0;(t&&n||!t&&r)&&this._onDidVisibilityChange.fire({visible:t})}moveChild(e,t){if(e===t)return;if(e<0||e>=this.children.length)throw Error(`Invalid from index`);e<t&&t--,this.splitview.moveView(e,t);let n=this._removeChild(e);this._addChild(n,t)}getChildSize(e){if(e<0||e>=this.children.length)throw Error(`Invalid index`);return this.splitview.getViewSize(e)}resizeChild(e,t){if(e<0||e>=this.children.length)throw Error(`Invalid index`);this.splitview.resizeView(e,t)}layout(e,t){this._size=t,this._orthogonalSize=e,this.splitview.layout(t,e)}addChild(e,t,n,r){if(n<0||n>this.children.length)throw Error(`Invalid index`);this.splitview.addView(e,t,n,r),this._addChild(e,n)}getChildCachedVisibleSize(e){if(e<0||e>=this.children.length)throw Error(`Invalid index`);return this.splitview.getViewCachedVisibleSize(e)}removeChild(e,t){if(e<0||e>=this.children.length)throw Error(`Invalid index`);return this.splitview.removeView(e,t),this._removeChild(e)}_addChild(e,t){this.children.splice(t,0,e),this.setupChildrenEvents()}_removeChild(e){let[t]=this.children.splice(e,1);return this.setupChildrenEvents(),t}setupChildrenEvents(){this.invalidateCachedSizes(),this._childrenDisposable.dispose(),this._childrenDisposable=new Y(gW.any(...this.children.map(e=>e.onDidChange))(e=>{this.invalidateCachedSizes(),this._onDidChange.fire({size:e.orthogonalSize})}),...this.children.map((t,n)=>t instanceof e?new Y(t.onDidVisibilityChange(({visible:e})=>{this.setChildVisible(n,e)}),t.onDidInvalidateSizes(()=>{this.invalidateCachedSizes()})):mW.NONE))}dispose(){this._childrenDisposable.dispose(),this.splitview.dispose(),this.children.forEach(e=>e.dispose()),super.dispose()}};function EG(e,t){if(e instanceof wG)return e;if(e instanceof TG)return EG(e.children[t?e.children.length-1:0],t);throw Error(`invalid node`)}function DG(e,t,n,r=1){let i=e.getChildCachedVisibleSize(t);return i===void 0?n:bG.Invisible(Math.round(i*r))}function OG(e,t,n){if(e instanceof TG){let r=new TG(e.orientation,e.proportionalLayout,e.styles,t,n,e.disabled,e.margin);for(let t=e.children.length-1;t>=0;t--){let n=e.children[t],i=n instanceof TG?n.orthogonalSize:n.size;r.addChild(OG(n,n.size,n.orthogonalSize),DG(e,t,i),0,!0)}return r}return new wG(e.view,e.orientation,n)}function kG(e,t,n){if(e instanceof TG){let r=new TG(FG(e.orientation),e.proportionalLayout,e.styles,t,n,e.disabled,e.margin),i=0,a=e.size===0?1:t/e.size;for(let o=e.children.length-1;o>=0;o--){let s=e.children[o],c=s instanceof TG?s.orthogonalSize:s.size,l=e.size===0?0:Math.round(t*c/e.size);i+=l,o===0&&(l+=t-i),r.addChild(kG(s,n,l),DG(e,o,l,a),0,!0)}return r}return new wG(e.view,FG(e.orientation),n)}function AG(e){let t=e.parentElement;if(!t)throw Error(`Invalid grid element`);let n=t.firstElementChild,r=0;for(;n!==e&&n!==t.lastElementChild&&n;)n=n.nextElementSibling,r++;return r}function jG(e){let t=e.parentElement;if(!t)throw Error(`Invalid grid element`);if(/\bdv-grid-view\b/.test(t.className))return[];let n=AG(t),r=t.parentElement.parentElement.parentElement;return[...jG(r),n]}function MG(e,t,n){if(PG(e,t)===NG(n)){let[e,r]=cG(t),i=r;return(n===`right`||n===`bottom`)&&(i+=1),[...e,i]}{let e=+(n===`right`||n===`bottom`);return[...t,e]}}function NG(e){return e===`top`||e===`bottom`?`VERTICAL`:`HORIZONTAL`}function PG(e,t){return t.length%2==0?FG(e):e}var FG=e=>e===`HORIZONTAL`?`VERTICAL`:`HORIZONTAL`;function IG(e){return!!e.children}var LG=(e,t)=>{let n=t===`VERTICAL`?e.box.width:e.box.height;if(!IG(e))return typeof e.cachedVisibleSize==`number`?{type:`leaf`,data:e.view.toJSON(),size:e.cachedVisibleSize,visible:!1}:{type:`leaf`,data:e.view.toJSON(),size:n};let r=e.children.map(e=>LG(e,FG(t)));return typeof e.cachedVisibleSize==`number`?{type:`branch`,data:r,size:e.cachedVisibleSize,visible:!1}:{type:`branch`,data:r,size:n}},RG=class{get length(){return this._root?this._root.children.length:0}get orientation(){return this.root.orientation}set orientation(e){if(this.root.orientation===e)return;let{size:t,orthogonalSize:n}=this.root;this.root=kG(this.root,n,t),this.root.layout(t,n)}get width(){return this.root.width}get height(){return this.root.height}get minimumWidth(){return this.root.minimumWidth}get minimumHeight(){return this.root.minimumHeight}get maximumWidth(){return this.root.maximumWidth}get maximumHeight(){return this.root.maximumHeight}get locked(){return this._locked}set locked(e){this._locked=e;let t=[this.root];for(;t.length>0;){let n=t.pop();n instanceof TG&&(n.disabled=e,t.push(...n.children))}}get margin(){return this._margin}set margin(e){this._margin=e,this.root.margin=e}maximizedView(){return this._maximizedNode?.leaf.view}hasMaximizedView(){return this._maximizedNode!==void 0}maximizeView(e){let t=jG(e.element),[n,r]=this.getNode(t);if(!(r instanceof wG)||this._maximizedNode?.leaf===r)return;this.hasMaximizedView()&&this.exitMaximizedView(),LG(this.getView(),this.orientation);let i=[];function a(e,t){for(let n=0;n<e.children.length;n++){let r=e.children[n];r instanceof wG?r!==t&&(e.isChildVisible(n)?e.setChildVisible(n,!1):i.push(r)):a(r,t)}}a(this.root,r),this._maximizedNode={leaf:r,hiddenOnMaximize:i},this._onDidMaximizedNodeChange.fire({view:r.view,isMaximized:!0})}exitMaximizedView(){if(!this._maximizedNode)return;let e=this._maximizedNode.hiddenOnMaximize;function t(n){for(let r=n.children.length-1;r>=0;r--){let i=n.children[r];i instanceof wG?e.includes(i)||n.setChildVisible(r,!0):t(i)}}t(this.root);let n=this._maximizedNode.leaf;this._maximizedNode=void 0,this._onDidMaximizedNodeChange.fire({view:n.view,isMaximized:!1})}serialize(){let e=this.maximizedView(),t;e&&(t=jG(e.element));let n=this._onDidMaximizedNodeChange.pause();try{this.hasMaximizedView()&&this.exitMaximizedView();let n={root:LG(this.getView(),this.orientation),width:this.width,height:this.height,orientation:this.orientation};return t&&(n.maximizedNode={location:t}),e&&this.maximizeView(e),n}finally{n.dispose()}}dispose(){this.disposable.dispose(),this._onDidChange.dispose(),this._onDidMaximizedNodeChange.dispose(),this._onDidViewVisibilityChange.dispose(),this.root.dispose(),this._maximizedNode=void 0,this.element.remove()}clear(){let e=this.root.orientation;this.root=new TG(e,this.proportionalLayout,this.styles,this.root.size,this.root.orthogonalSize,this.locked,this.margin)}deserialize(e,t){let n=e.orientation,r=n===`VERTICAL`?e.height:e.width;if(this._deserialize(e.root,n,t,r),this.layout(e.width,e.height),e.maximizedNode){let t=e.maximizedNode.location,[n,r]=this.getNode(t);if(!(r instanceof wG))return;this.maximizeView(r.view)}}_deserialize(e,t,n,r){this.root=this._deserializeNode(e,t,n,r)}_deserializeNode(e,t,n,r){let i;if(e.type===`branch`){let a=e.data.map(r=>({node:this._deserializeNode(r,FG(t),n,e.size),visible:r.visible}));i=new TG(t,this.proportionalLayout,this.styles,e.size,r,this.locked,this.margin,a)}else{let o=n.fromJSON(e);if(typeof e.visible==`boolean`){var a;(a=o.setVisible)==null||a.call(o,e.visible)}i=new wG(o,t,r,e.size)}return i}get root(){return this._root}set root(e){let t=this._root;t&&(t.dispose(),this._maximizedNode=void 0,t.element.remove()),this._root=e,this.element.appendChild(this._root.element),this.disposable.value=this._root.onDidChange(e=>{this._onDidChange.fire(e)})}normalize(){if(!this._root||this._root.children.length!==1)return;let e=this.root,t=e.children[0];if(t instanceof wG)return;e.element.remove();let n=e.removeChild(0);e.dispose(),n.dispose(),this._root=OG(t,t.size,t.orthogonalSize),this.element.appendChild(this._root.element),this.disposable.value=this._root.onDidChange(e=>{this._onDidChange.fire(e)})}insertOrthogonalSplitviewAtRoot(){if(!this._root)return;let e=this.root;if(e.element.remove(),this._root=new TG(FG(e.orientation),this.proportionalLayout,this.styles,this.root.orthogonalSize,this.root.size,this.locked,this.margin),e.children.length!==0){if(e.children.length===1){let t=e.children[0];e.removeChild(0).dispose(),e.dispose(),this._root.addChild(kG(t,t.orthogonalSize,t.size),bG.Distribute,0)}else this._root.addChild(e,bG.Distribute,0)}this.element.appendChild(this._root.element),this.disposable.value=this._root.onDidChange(e=>{this._onDidChange.fire(e)})}next(e){return this.progmaticSelect(e)}previous(e){return this.progmaticSelect(e,!0)}getView(e){let t=e?this.getNode(e)[1]:this.root;return this._getViews(t,this.orientation)}_getViews(e,t,n){let r={height:e.height,width:e.width};if(e instanceof wG)return{box:r,view:e.view,cachedVisibleSize:n};let i=[];for(let n=0;n<e.children.length;n++){let r=e.children[n],a=e.getChildCachedVisibleSize(n);i.push(this._getViews(r,FG(t),a))}return{box:r,children:i,cachedVisibleSize:n}}progmaticSelect(e,t=!1){let[n,r]=this.getNode(e);if(!(r instanceof wG))throw TypeError(`invalid location`);for(let r=n.length-1;r>-1;r--){let i=n[r],a=e[r]||0;if(t?a-1>-1:a+1<i.children.length)return EG(i.children[t?a-1:a+1],t)}return EG(this.root,t)}get proportionalLayout(){return this.root.proportionalLayout}set proportionalLayout(e){this.root.proportionalLayout=e}constructor(e,t,n,r,i){this.styles=t,this._locked=!1,this._margin=0,this._maximizedNode=void 0,this.disposable=new hW,this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this._onDidViewVisibilityChange=new X,this.onDidViewVisibilityChange=this._onDidViewVisibilityChange.event,this._onDidMaximizedNodeChange=new X,this.onDidMaximizedNodeChange=this._onDidMaximizedNodeChange.event,this.element=document.createElement(`div`),this.element.className=`dv-grid-view`,this._locked=r??!1,this._margin=i??0,this.root=new TG(n,e,t,0,0,this.locked,this.margin)}isViewVisible(e){let[t,n]=cG(e),[,r]=this.getNode(t);if(!(r instanceof TG))throw TypeError(`Invalid from location`);return r.isChildVisible(n)}setViewVisible(e,t){this.hasMaximizedView()&&this.exitMaximizedView();let[n,r]=cG(e),[,i]=this.getNode(n);if(!(i instanceof TG))throw TypeError(`Invalid from location`);this._onDidViewVisibilityChange.fire(),i.setChildVisible(r,t)}moveView(e,t,n){this.hasMaximizedView()&&this.exitMaximizedView();let[,r]=this.getNode(e);if(!(r instanceof TG))throw TypeError(`Invalid location`);r.moveChild(t,n)}addView(e,t,n){this.hasMaximizedView()&&this.exitMaximizedView();let[r,i]=cG(n),[a,o]=this.getNode(r);if(o instanceof TG){let n=new wG(e,FG(o.orientation),o.orthogonalSize);o.addChild(n,t,i)}else{let[n,...s]=[...a].reverse(),[c,...l]=[...r].reverse(),u=0,d=n.getChildCachedVisibleSize(c);typeof d==`number`&&(u=bG.Invisible(d)),n.removeChild(c).dispose();let f=new TG(o.orientation,this.proportionalLayout,this.styles,o.size,o.orthogonalSize,this.locked,this.margin);n.addChild(f,o.size,c);let p=new wG(o.view,n.orientation,o.size);f.addChild(p,u,0),typeof t!=`number`&&t.type===`split`&&(t={type:`split`,index:0});let m=new wG(e,n.orientation,o.size);f.addChild(m,t,i)}}remove(e,t){let n=jG(e.element);return this.removeView(n,t)}removeView(e,t){this.hasMaximizedView()&&this.exitMaximizedView();let[n,r]=cG(e),[i,a]=this.getNode(n);if(!(a instanceof TG))throw TypeError(`Invalid location`);let o=a.children[r];if(!(o instanceof wG))throw TypeError(`Invalid location`);if(a.removeChild(r,t),o.dispose(),a.children.length!==1)return o.view;let s=a.children[0];if(i.length===0)return s instanceof wG||(a.removeChild(0,t),this.root=s),o.view;let[c,...l]=[...i].reverse(),[u,...d]=[...n].reverse(),f=a.isChildVisible(0);a.removeChild(0,t);let p=c.children.map((e,t)=>c.getChildSize(t));if(c.removeChild(u,t).dispose(),s instanceof TG){let e=s.children.map(e=>e instanceof TG?e.orthogonalSize:e.size);p.splice(u,1,...e);for(let t=0;t<s.children.length;t++){let n=s.children[t],r=DG(s,t,e[t]);c.addChild(n,!f&&typeof r==`number`?bG.Invisible(r):r,u+t)}for(;s.children.length>0;)s.removeChild(0)}else{let e=new wG(s.view,FG(s.orientation),s.size),t=f?s.orthogonalSize:bG.Invisible(s.orthogonalSize);c.addChild(e,t,u)}s.dispose();for(let e=0;e<p.length;e++)c.resizeChild(e,p[e]);return o.view}layout(e,t){let[n,r]=this.root.orientation===`HORIZONTAL`?[t,e]:[e,t];this.root.layout(n,r)}getNode(e,t=this.root,n=[]){if(e.length===0)return[n,t];if(!(t instanceof TG))throw TypeError(`Invalid location`);let[r,...i]=e;if(r<0||r>=t.children.length)throw Error(`Invalid location`);let a=t.children[r];return n.push(t),this.getNode(i,a,n)}},zG=Object.keys({disableAutoResizing:void 0,proportionalLayout:void 0,orientation:void 0,hideBorders:void 0,className:void 0}),BG=class extends Y{get element(){return this._element}get disableResizing(){return this._disableResizing}set disableResizing(e){this._disableResizing=e}constructor(e,t=!1){super(),this._lastWidth=-1,this._lastHeight=-1,this._disableResizing=t,this._element=e,this.addDisposables(wW(this._element,e=>{if(this.isDisposed||this.disableResizing||!this._element.offsetParent||!RW(this._element))return;let t=Math.round(e.contentRect.width),n=Math.round(e.contentRect.height);(t!==this._lastWidth||n!==this._lastHeight)&&(this._lastWidth=t,this._lastHeight=n,this.layout(t,n))}))}layoutFromElement(){if(this.disableResizing||!this._element.offsetParent||!RW(this._element))return;let e=Math.round(this._element.clientWidth),t=Math.round(this._element.clientHeight);e!==0&&t!==0&&this.layout(e,t)}},VG=hG();function HG(e){switch(e){case`left`:return`left`;case`right`:return`right`;case`above`:return`top`;case`below`:return`bottom`;default:return`center`}}var UG=class extends BG{get id(){return this._id}get size(){return this._groups.size}get groups(){return Array.from(this._groups.values()).map(e=>e.value)}get width(){return this.gridview.width}get height(){return this.gridview.height}get minimumHeight(){return this.gridview.minimumHeight}get maximumHeight(){return this.gridview.maximumHeight}get minimumWidth(){return this.gridview.minimumWidth}get maximumWidth(){return this.gridview.maximumWidth}get activeGroup(){return this._activeGroup}get locked(){return this.gridview.locked}set locked(e){this.gridview.locked=e}constructor(e,t){super(document.createElement(`div`),t.disableAutoResizing),this._id=VG.next(),this._groups=new Map,this._onDidRemove=new X,this.onDidRemove=this._onDidRemove.event,this._onDidAdd=new X,this.onDidAdd=this._onDidAdd.event,this._onDidMaximizedChange=new X,this.onDidMaximizedChange=this._onDidMaximizedChange.event,this._onDidActiveChange=new X,this.onDidActiveChange=this._onDidActiveChange.event,this._bufferOnDidLayoutChange=new SW,this.onDidLayoutChange=gW.map(this._bufferOnDidLayoutChange.onEvent,e=>({reasons:e})),this._onDidViewVisibilityChangeMicroTaskQueue=new SW,this.onDidViewVisibilityChangeMicroTaskQueue=this._onDidViewVisibilityChangeMicroTaskQueue.onEvent,this.element.style.height=`100%`,this.element.style.width=`100%`,this._classNames=new KW(this.element),this._classNames.setClassNames(t.className??``),e.appendChild(this.element),this.gridview=new RG(!!t.proportionalLayout,t.styles,t.orientation,t.locked,t.margin),this.gridview.locked=!!t.locked,this.element.appendChild(this.gridview.element),this.layout(0,0,!0),this.addDisposables(this.gridview.onDidMaximizedNodeChange(e=>{this._onDidMaximizedChange.fire({panel:e.view,isMaximized:e.isMaximized})}),this.gridview.onDidViewVisibilityChange(()=>this._onDidViewVisibilityChangeMicroTaskQueue.fire()),this.onDidViewVisibilityChangeMicroTaskQueue(()=>{this.forceRelayout()}),mW.from(()=>{this.element.remove()}),this.gridview.onDidChange(()=>{this._bufferOnDidLayoutChange.fire(`geometry`)}),gW.any(this.onDidAdd,this.onDidRemove)(()=>{this._bufferOnDidLayoutChange.fire(`structure`)}),this.onDidActiveChange(()=>{this._bufferOnDidLayoutChange.fire(`activePanel`)}),this.onDidMaximizedChange(()=>{this._bufferOnDidLayoutChange.fire(`geometry`)}),this._onDidMaximizedChange,this._onDidViewVisibilityChangeMicroTaskQueue,this._bufferOnDidLayoutChange)}setVisible(e,t){this.gridview.setViewVisible(jG(e.element),t),this._bufferOnDidLayoutChange.fire(`geometry`)}isVisible(e){return this.gridview.isViewVisible(jG(e.element))}updateOptions(e){`proportionalLayout`in e&&(this.gridview.proportionalLayout=e.proportionalLayout??!0),e.orientation&&(this.gridview.orientation=e.orientation),`styles`in e,`disableAutoResizing`in e&&(this.disableResizing=e.disableAutoResizing??!1),`locked`in e&&(this.locked=e.locked??!1),`margin`in e&&(this.gridview.margin=e.margin??0),`className`in e&&this._classNames.setClassNames(e.className??``)}maximizeGroup(e){this.gridview.maximizeView(e),this.doSetGroupActive(e)}isMaximizedGroup(e){return this.gridview.maximizedView()===e}exitMaximizedGroup(){this.gridview.exitMaximizedView()}hasMaximizedGroup(){return this.gridview.hasMaximizedView()}doAddGroup(e,t=[0],n,r=this.gridview){r.addView(e,n??bG.Distribute,t),this._onDidAdd.fire(e)}doRemoveGroup(e,t){if(!this._groups.has(e.id))throw Error(`invalid operation`);let n=this._groups.get(e.id),r=this.gridview.remove(e,bG.Distribute);if(n&&!t?.skipDispose&&(n.disposable.dispose(),n.value.dispose(),this._groups.delete(e.id),this._onDidRemove.fire(e)),!t?.skipActive&&this._activeGroup===e){let e=Array.from(this._groups.values());this.doSetGroupActive(e.length>0?e[0].value:void 0)}return r}getPanel(e){return this._groups.get(e)?.value}doSetGroupActive(e){this._activeGroup!==e&&(this._activeGroup&&this._activeGroup.setActive(!1),e&&e.setActive(!0),this._activeGroup=e,this._onDidActiveChange.fire(e))}removeGroup(e){this.doRemoveGroup(e)}activateNext(e){if(e??={},!e.group){if(!this.activeGroup)return;e.group=this.activeGroup}let t=jG(e.group.element),n=this.gridview.next(t)?.view;this.doSetGroupActive(n)}activatePrevious(e){if(e??={},!e.group){if(!this.activeGroup)return;e.group=this.activeGroup}let t=jG(e.group.element),n=this.gridview.previous(t)?.view;this.doSetGroupActive(n)}forceRelayout(){this.layout(this.width,this.height,!0)}layout(e,t,n){(n||e!==this.width||t!==this.height)&&(this.gridview.element.style.height=`${t}px`,this.gridview.element.style.width=`${e}px`,this.gridview.layout(e,t))}dispose(){this._onDidActiveChange.dispose(),this._onDidAdd.dispose(),this._onDidRemove.dispose();for(let e of this.groups)e.dispose();this.gridview.dispose(),super.dispose()}};function WG(e){"@babel/helpers - typeof";return WG=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},WG(e)}function GG(e,t){if(WG(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(WG(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function KG(e){var t=GG(e,`string`);return WG(t)==`symbol`?t:t+``}function qG(e,t,n){return(t=KG(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function JG(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function $(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?JG(Object(n),!0).forEach(function(t){qG(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):JG(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function YG(e,t){return e===`center`?`Tab into ${t}`:`Split ${e} of ${t}`}function XG(e,t){return e===`center`?`docked into ${t}`:`split ${e} of ${t}`}var ZG={panelOpened:e=>`${e} opened`,panelClosed:e=>`${e} closed`,groupMaximized:e=>`${e} maximized`,groupRestored:e=>`${e} restored`,groupFloated:e=>`${e} floated`,groupDocked:e=>`${e} docked`,groupPoppedOut:e=>`${e} opened in a new window`,closeTab:e=>`Close ${e}`,closeTabPlain:()=>`Close`,movePickTarget:(e,t,n,r)=>`Moving ${e}. Target ${t}, ${n} of ${r}. Enter to choose where, Escape to cancel.`,movePickEdge:(e,t)=>`${YG(e,t)}. Arrows to change, Enter to confirm, Escape to go back.`,moveCommitted:(e,t,n)=>`${e} ${XG(n,t)}.`,moveCancelled:()=>`Move cancelled.`,moveNotAllowed:()=>`That move is not allowed.`,moveFloated:e=>`${e} floated.`};function QG(e){return e?$($({},ZG),e):ZG}var $G=class{get minimumSize(){return this.component.minimumSize}get maximumSize(){return this.component.maximumSize}get width(){return this.component.width}get height(){return this.component.height}get length(){return this.component.length}get orientation(){return this.component.orientation}get panels(){return this.component.panels}get onDidLayoutFromJSON(){return this.component.onDidLayoutFromJSON}get onDidLayoutChange(){return this.component.onDidLayoutChange}get onDidAddView(){return this.component.onDidAddView}get onDidRemoveView(){return this.component.onDidRemoveView}constructor(e){this.component=e}removePanel(e,t){this.component.removePanel(e,t)}focus(){this.component.focus()}getPanel(e){return this.component.getPanel(e)}layout(e,t){return this.component.layout(e,t)}addPanel(e){return this.component.addPanel(e)}movePanel(e,t){this.component.movePanel(e,t)}fromJSON(e){this.component.fromJSON(e)}toJSON(){return this.component.toJSON()}clear(){this.component.clear()}updateOptions(e){this.component.updateOptions(e)}dispose(){this.component.dispose()}},eK=class{get minimumSize(){return this.component.minimumSize}get maximumSize(){return this.component.maximumSize}get width(){return this.component.width}get height(){return this.component.height}get panels(){return this.component.panels}get onDidLayoutChange(){return this.component.onDidLayoutChange}get onDidLayoutFromJSON(){return this.component.onDidLayoutFromJSON}get onDidAddView(){return this.component.onDidAddView}get onDidRemoveView(){return this.component.onDidRemoveView}get onDidDrop(){return this.component.onDidDrop}get onUnhandledDragOver(){return this.component.onUnhandledDragOver}constructor(e){this.component=e}removePanel(e){this.component.removePanel(e)}getPanel(e){return this.component.getPanel(e)}movePanel(e,t){this.component.movePanel(e,t)}focus(){this.component.focus()}layout(e,t){this.component.layout(e,t)}addPanel(e){return this.component.addPanel(e)}fromJSON(e){this.component.fromJSON(e)}toJSON(){return this.component.toJSON()}clear(){this.component.clear()}updateOptions(e){this.component.updateOptions(e)}dispose(){this.component.dispose()}},tK=class{get width(){return this.component.width}get height(){return this.component.height}get minimumHeight(){return this.component.minimumHeight}get maximumHeight(){return this.component.maximumHeight}get minimumWidth(){return this.component.minimumWidth}get maximumWidth(){return this.component.maximumWidth}get onDidLayoutChange(){return this.component.onDidLayoutChange}get onDidAddPanel(){return this.component.onDidAddGroup}get onDidRemovePanel(){return this.component.onDidRemoveGroup}get onDidActivePanelChange(){return this.component.onDidActiveGroupChange}get onDidLayoutFromJSON(){return this.component.onDidLayoutFromJSON}get panels(){return this.component.groups}get orientation(){return this.component.orientation}set orientation(e){this.component.updateOptions({orientation:e})}constructor(e){this.component=e}focus(){this.component.focus()}layout(e,t,n=!1){this.component.layout(e,t,n)}addPanel(e){return this.component.addPanel(e)}removePanel(e,t){this.component.removePanel(e,t)}movePanel(e,t){this.component.movePanel(e,t)}getPanel(e){return this.component.getPanel(e)}fromJSON(e){return this.component.fromJSON(e)}toJSON(){return this.component.toJSON()}clear(){this.component.clear()}updateOptions(e){this.component.updateOptions(e)}dispose(){this.component.dispose()}},nK=class{get id(){return this.component.id}get width(){return this.component.width}get height(){return this.component.height}get minimumHeight(){return this.component.minimumHeight}get maximumHeight(){return this.component.maximumHeight}get minimumWidth(){return this.component.minimumWidth}get maximumWidth(){return this.component.maximumWidth}get size(){return this.component.size}get tabGroupColors(){return this.component.tabGroupColorPalette.entries()}get totalPanels(){return this.component.totalPanels}get onDidActiveGroupChange(){return this.component.onDidActiveGroupChange}get onDidAddGroup(){return this.component.onDidAddGroup}get onDidRemoveGroup(){return this.component.onDidRemoveGroup}get onDidActivePanelChange(){return this.component.onDidActivePanelChange}get onDidPanelPinnedChange(){return this.component.onDidPanelPinnedChange}get onDidAddPanel(){return this.component.onDidAddPanel}get onDidRemovePanel(){return this.component.onDidRemovePanel}get onDidMovePanel(){return this.component.onDidMovePanel}get onDidLayoutFromJSON(){return this.component.onDidLayoutFromJSON}get onDidLayoutChange(){return this.component.onDidLayoutChange}get onDidDrop(){return this.component.onDidDrop}get onWillDrop(){return this.component.onWillDrop}get onWillMutateLayout(){return this.component.onWillMutateLayout}get onDidMutateLayout(){return this.component.onDidMutateLayout}get onWillShowOverlay(){return this.component.onWillShowOverlay}get onWillDragGroup(){return this.component.onWillDragGroup}get onWillDragPanel(){return this.component.onWillDragPanel}get onUnhandledDragOver(){return this.component.onUnhandledDragOver}get dndCapabilities(){return this.component.dndCapabilities}get onDidPopoutGroupSizeChange(){return this.component.onDidPopoutGroupSizeChange}get onDidPopoutGroupPositionChange(){return this.component.onDidPopoutGroupPositionChange}get onDidAddPopoutGroup(){return this.component.onDidAddPopoutGroup}get onDidRemovePopoutGroup(){return this.component.onDidRemovePopoutGroup}get onDidOpenPopoutWindowFail(){return this.component.onDidOpenPopoutWindowFail}get onWillClosePopoutWindow(){return this.component.onWillClosePopoutWindow}getPopouts(){return this.component.getPopouts()}get onDidCreateTabGroup(){return this.component.onDidCreateTabGroup}get onDidDestroyTabGroup(){return this.component.onDidDestroyTabGroup}get onDidAddPanelToTabGroup(){return this.component.onDidAddPanelToTabGroup}get onDidRemovePanelFromTabGroup(){return this.component.onDidRemovePanelFromTabGroup}get onDidTabGroupChange(){return this.component.onDidTabGroupChange}get onDidTabGroupCollapsedChange(){return this.component.onDidTabGroupCollapsedChange}get panels(){return this.component.panels}get groups(){return this.component.groups}adjacentGroupInDirection(e,t){return this.component.adjacentGroupInDirection(e,t)}get activePanel(){return this.component.activePanel}get activeGroup(){return this.component.activeGroup}get messages(){return QG(this.component.options.messages)}constructor(e){this.component=e}focus(){this.component.focus()}getPanel(e){return this.component.getGroupPanel(e)}layout(e,t,n=!1){this.component.layout(e,t,n)}addPanel(e){return this.component.withOrigin(`api`,()=>this.component.addPanel(e))}removePanel(e,t){this.component.withOrigin(`api`,()=>this.component.removePanel(e,t))}addGroup(e){return this.component.withOrigin(`api`,()=>this.component.addGroup(e))}serializeGroup(e){return this.component.serializeGroup(e)}addGroupFromJSON(e,t){return this.component.withOrigin(`api`,()=>this.component.addGroupFromJSON(e,t))}addPanelFromJSON(e,t){return this.component.withOrigin(`api`,()=>this.component.addPanelFromJSON(e,t))}closeAllGroups(){return this.component.withOrigin(`api`,()=>this.component.closeAllGroups())}removeGroup(e){this.component.withOrigin(`api`,()=>this.component.removeGroup(e))}getGroup(e){return this.component.getPanel(e)}addFloatingGroup(e,t){return this.component.withOrigin(`api`,()=>this.component.addFloatingGroup(e,t))}fromJSON(e,t){this.component.withOrigin(`api`,()=>this.component.fromJSON(e,t))}toJSON(){return this.component.toJSON()}clear(){this.component.withOrigin(`api`,()=>this.component.clear())}undo(){this.component.undo()}redo(){this.component.redo()}get canUndo(){return this.component.canUndo}get canRedo(){return this.component.canRedo}clearHistory(){this.component.clearHistory()}get onDidChangeHistory(){return this.component.onDidChangeHistory}get smartGuidesEnabled(){return this.component.smartGuidesEnabled}setSmartGuidesEnabled(e){this.component.setSmartGuidesEnabled(e)}updateSmartGuidesOptions(e){this.component.updateSmartGuidesOptions(e)}get onDidSnapFloat(){return this.component.onDidSnapFloat}get onDidSnapTogether(){return this.component.onDidSnapTogether}get popoutRestorationPromise(){return this.component.popoutRestorationPromise}activateNext(e){this.component.activateNext(e)}activatePrevious(e){this.component.activatePrevious(e)}moveToNext(e){this.activateNext(e)}moveToPrevious(e){this.activatePrevious(e)}maximizeGroup(e){this.component.withOrigin(`api`,()=>this.component.maximizeGroup(e.group))}hasMaximizedGroup(){return this.component.hasMaximizedGroup()}exitMaximizedGroup(){this.component.withOrigin(`api`,()=>this.component.exitMaximizedGroup())}get onDidMaximizedGroupChange(){return this.component.onDidMaximizedGroupChange}addPopoutGroup(e,t){return this.component.withOrigin(`api`,()=>this.component.addPopoutGroup(e,t))}addEdgeGroup(e,t){return this.component.addEdgeGroup(e,t)}revealEdgeGroupWithData(e,t,n){this.component.revealEdgeGroupWithData(e,t,n)}getEdgeGroup(e){return this.component.getEdgeGroup(e)}setEdgeGroupVisible(e,t){this.component.setEdgeGroupVisible(e,t)}isEdgeGroupVisible(e){return this.component.isEdgeGroupVisible(e)}removeEdgeGroup(e){this.component.removeEdgeGroup(e)}pinEdgeGroup(e){this.component.pinEdgeGroup(e)}autoHideEdgeGroup(e){this.component.autoHideEdgeGroup(e)}peekEdgeGroup(e,t){this.component.peekEdgeGroup(e,t)}updateOptions(e){this.component.updateOptions(e)}_getGroupModel(e){let t=this.component.getPanel(e);if(!t)throw Error(`dockview: group '${e}' not found`);return t.model}createTabGroup(e){let t=this._getGroupModel(e.groupId);return this.component.withOrigin(`api`,()=>t.createTabGroup({label:e.label,color:e.color,componentParams:e.componentParams}))}dissolveTabGroup(e){let t=this._getGroupModel(e.groupId);this.component.withOrigin(`api`,()=>t.dissolveTabGroup(e.tabGroupId))}addPanelToTabGroup(e){let t=this._getGroupModel(e.groupId);this.component.withOrigin(`api`,()=>t.addPanelToTabGroup(e.tabGroupId,e.panelId,e.index))}removePanelFromTabGroup(e){let t=this._getGroupModel(e.groupId);this.component.withOrigin(`api`,()=>t.removePanelFromTabGroup(e.panelId))}getTabGroups(e){return this._getGroupModel(e.groupId).getTabGroups()}getTabGroupForPanel(e){return this._getGroupModel(e.groupId).getTabGroupForPanel(e.panelId)}moveTabGroup(e){this._getGroupModel(e.groupId).moveTabGroup(e.tabGroupId,e.index)}dispose(){this.component.dispose()}},rK=class extends Y{constructor(e,t){super(),this.element=e,this.callbacks=t,this.target=null,this.registerListeners()}onDragEnter(e){this.target=e.target,this.callbacks.onDragEnter(e)}onDragOver(e){e.preventDefault(),this.callbacks.onDragOver&&this.callbacks.onDragOver(e)}onDragLeave(e){this.target===e.target&&(this.target=null,this.callbacks.onDragLeave(e))}onDragEnd(e){this.target=null,this.callbacks.onDragEnd(e)}onDrop(e){this.callbacks.onDrop(e)}registerListeners(){this.addDisposables(Z(this.element,`dragenter`,e=>{this.onDragEnter(e)},!0)),this.addDisposables(Z(this.element,`dragover`,e=>{this.onDragOver(e)},!0)),this.addDisposables(Z(this.element,`dragleave`,e=>{this.onDragLeave(e)})),this.addDisposables(Z(this.element,`dragend`,e=>{this.onDragEnd(e)})),this.addDisposables(Z(this.element,`drop`,e=>{this.onDrop(e)}))}},iK={value:50,type:`percentage`},aK=100,oK=100;function sK(){let e=document.createElement(`div`);e.className=`dv-drop-target-dropzone`;let t=document.createElement(`div`);return t.className=`dv-drop-target-selection`,e.appendChild(t),{dropzone:e,selection:t}}function cK(e,t,n,r){let i=r?.smallWidthBoundary??aK,a=r?.smallHeightBoundary??oK,o=t<i,s=n<a,c=e===`left`,l=e===`right`,u=e===`top`,d=e===`bottom`,f=!o&&l,p=!o&&c,m=!s&&u,h=!s&&d,g=1,_=r?.size??iK;return _.type===`percentage`?g=mG(_.value,0,100)/100:((f||p)&&(g=mG(_.value,0,t)/t),(m||h)&&(g=mG(_.value,0,n)/n)),{isSmallX:o,isSmallY:s,isLeft:c,isRight:l,isTop:u,isBottom:d,rightClass:f,leftClass:p,topClass:m,bottomClass:h,size:g}}function lK(e,t,n,r,i){let a=cK(t,n,r,i),{rightClass:o,leftClass:s,topClass:c,bottomClass:l,size:u}=a,d={top:`0px`,left:`0px`,width:`100%`,height:`100%`};o?(d.left=`${100*(1-u)}%`,d.width=`${100*u}%`):s?d.width=`${100*u}%`:c?d.height=`${100*u}%`:l&&(d.top=`${100*(1-u)}%`,d.height=`${100*u}%`),a.isSmallX&&a.isLeft&&(d.width=`4px`),a.isSmallX&&a.isRight&&(d.left=`${n-4}px`,d.width=`4px`),a.isSmallY&&a.isTop&&(d.height=`4px`),a.isSmallY&&a.isBottom&&(d.top=`${r-4}px`,d.height=`4px`),e.style.top=d.top,e.style.left=d.left,e.style.width=d.width,e.style.height=d.height,e.style.visibility=`visible`,e.style.transform&&e.style.transform!==``||(e.style.transform=`translate3d(0, 0, 0)`);let f=a.isSmallX&&(a.isLeft||a.isRight)||a.isSmallY&&(a.isTop||a.isBottom);Q(e,`dv-drop-target-small-vertical`,a.isSmallY),Q(e,`dv-drop-target-small-horizontal`,a.isSmallX),Q(e,`dv-drop-target-selection-line`,f),Q(e,`dv-drop-target-left`,a.isLeft),Q(e,`dv-drop-target-right`,a.isRight),Q(e,`dv-drop-target-top`,a.isTop),Q(e,`dv-drop-target-bottom`,a.isBottom),Q(e,`dv-drop-target-center`,t===`center`)}function uK(e,t){let n=`${Math.round(t.top)}px`,r=`${Math.round(t.left)}px`,i=`${Math.round(t.width)}px`,a=`${Math.round(t.height)}px`;return e.style.top!==n||e.style.left!==r||e.style.width!==i||e.style.height!==a}function dK(e,t){e.style.top=`${Math.round(t.top)}px`,e.style.left=`${Math.round(t.left)}px`,e.style.width=`${Math.round(t.width)}px`,e.style.height=`${Math.round(t.height)}px`,e.style.visibility=`visible`,e.style.transform&&e.style.transform!==``||(e.style.transform=`translate3d(0, 0, 0)`)}function fK(e){let t=cK(e.quadrant,e.width,e.height,e.overlayModel),{rightClass:n,leftClass:r,topClass:i,bottomClass:a,size:o}=t,s=e.outlineElement.getBoundingClientRect(),c=e.targetModel.getElements(void 0,e.outlineElement),l=c.root,u=c.overlay,d=l.getBoundingClientRect(),f=s.top-d.top,p=s.left-d.left,m={top:f,left:p,width:e.width,height:e.height};return n?(m.left=p+e.width*(1-o),m.width=e.width*o):r?m.width=e.width*o:i?m.height=e.height*o:a&&(m.top=f+e.height*(1-o),m.height=e.height*o),t.isSmallX&&t.isLeft&&(m.width=4),t.isSmallX&&t.isRight&&(m.left=p+e.width-4,m.width=4),t.isSmallY&&t.isTop&&(m.height=4),t.isSmallY&&t.isBottom&&(m.top=f+e.height-4,m.height=4),uK(u,m)?(dK(u,m),u.className=`dv-drop-target-anchor${e.className?` ${e.className}`:``}`,Q(u,`dv-drop-target-left`,t.isLeft),Q(u,`dv-drop-target-right`,t.isRight),Q(u,`dv-drop-target-top`,t.isTop),Q(u,`dv-drop-target-bottom`,t.isBottom),Q(u,`dv-drop-target-anchor-line`,t.isSmallX&&(t.isLeft||t.isRight)||t.isSmallY&&(t.isTop||t.isBottom)),Q(u,`dv-drop-target-center`,e.quadrant===`center`),c.changed&&(Q(u,`dv-drop-target-anchor-container-changed`,!0),setTimeout(()=>{Q(u,`dv-drop-target-anchor-container-changed`,!1)},10)),{boundsChanged:!0,targetChanged:c.changed}):{boundsChanged:!1,targetChanged:c.changed}}var pK=class extends _W{get nativeEvent(){return this.options.nativeEvent}get position(){return this.options.position}get edge(){return!!this.options.edge}get edgeGroup(){return!!this.options.edgeGroup}constructor(e){super(),this.options=e}};function mK(e){switch(e){case`above`:return`top`;case`below`:return`bottom`;case`left`:return`left`;case`right`:return`right`;case`within`:return`center`;default:throw Error(`invalid direction '${e}'`)}}function hK(e){switch(e){case`top`:return`above`;case`bottom`:return`below`;case`left`:return`left`;case`right`:return`right`;case`center`:return`within`;default:throw Error(`invalid position '${e}'`)}}var gK={value:20,type:`percentage`},_K=class e extends Y{get disabled(){return this._disabled}set disabled(e){this._disabled=e}get state(){return this._state}constructor(t,n){super(),this.element=t,this.options=n,this._edge=!1,this._onDrop=new X,this.onDrop=this._onDrop.event,this._onWillShowOverlay=new X,this.onWillShowOverlay=this._onWillShowOverlay.event,this._disabled=!1,this._acceptedTargetZonesSet=new Set(this.options.acceptedTargetZones),this.dnd=new rK(this.element,{onDragEnter:()=>{var e,t;(e=(t=this.options).getOverrideTarget)==null||(e=e.call(t))==null||e.getElements()},onDragOver:t=>{var n,r;if(this._disabled){this.clearOwnOverlay();return}e.ACTUAL_TARGET=this;let i=(n=this.options).getOverrideTarget?.call(n);if(this._acceptedTargetZonesSet.size===0){this.clearOwnOverlay();return}let a=(r=this.options).getOverlayOutline?.call(r)??this.element,o=a.offsetWidth,s=a.offsetHeight;if(o===0||s===0)return;let c=a.getBoundingClientRect(),l=(t.clientX??0)-c.left,u=(t.clientY??0)-c.top,d=this.resolvePosition(l,u,o,s,t);if(this.isAlreadyUsed(t)){this.removeDropTarget();return}if(d===null){this.clearOwnOverlay();return}let f=d.position;if(!this.options.canDisplayOverlay(t,f)){this.clearOwnOverlay();return}let p=new pK({nativeEvent:t,position:f,edge:d.edge,edgeGroup:d.edgeGroup});if(this._onWillShowOverlay.fire(p),p.defaultPrevented)this.clearOwnOverlay();else if(this.markAsUsed(t),d.edge)this.clearOwnOverlay(),this._state=f,this._edge=!0;else{if(this._edge=!1,!i&&!this.targetElement){let e=sK();this.targetElement=e.dropzone,this.overlayElement=e.selection,this._state=`center`,a.classList.add(`dv-drop-target`),a.append(this.targetElement)}this.toggleClasses(f,o,s),this._state=f}},onDragLeave:()=>{var e;let t=(e=this.options).getOverrideTarget?.call(e);if(t){var n;this._state=void 0,this._edge=!1,(n=t.scheduleClear)==null||n.call(t)}else this.removeDropTarget()},onDragEnd:t=>{var n;let r=(n=this.options).getOverrideTarget?.call(n);r&&e.ACTUAL_TARGET===this&&this._state&&(t.stopPropagation(),this._onDrop.fire({position:this._state,nativeEvent:t,edge:this._edge})),this.removeDropTarget(),r?.clear()},onDrop:e=>{var t,n;e.preventDefault();let r=this._state,i=this._edge;this.removeDropTarget(),(t=(n=this.options).getOverrideTarget)==null||(t=t.call(n))==null||t.clear(),r&&(e.stopPropagation(),this._onDrop.fire({position:r,nativeEvent:e,edge:i}))}}),this.addDisposables(this._onDrop,this._onWillShowOverlay,this.dnd)}setTargetZones(e){this._acceptedTargetZonesSet=new Set(e)}setOverlayModel(e){this.options.overlayModel=e}dispose(){this.removeDropTarget(),super.dispose()}markAsUsed(t){t[e.USED_EVENT_ID]=!0}isAlreadyUsed(t){let n=t[e.USED_EVENT_ID];return typeof n==`boolean`&&n}toggleClasses(e,t,n){var r;let i=(r=this.options).getOverrideTarget?.call(r);if(i){var a;fK({outlineElement:(a=this.options).getOverlayOutline?.call(a)??this.element,targetModel:i,quadrant:e,width:t,height:n,overlayModel:this.options.overlayModel,className:this.options.className})}else this.overlayElement&&lK(this.overlayElement,e,t,n,this.options.overlayModel)}resolvePosition(e,t,n,r,i){var a;let o=(a=this.options).getPositionResolver?.call(a);if(o){let a=o.resolve({x:e,y:t,width:n,height:r,zones:this._acceptedTargetZonesSet,event:i});return a?{position:a.position,edge:!!a.edge,edgeGroup:!!a.edgeGroup}:null}let s=this.calculateQuadrant(this._acceptedTargetZonesSet,e,t,n,r);return s?{position:s,edge:!1,edgeGroup:!1}:null}calculateQuadrant(e,t,n,r,i){let a=this.options.overlayModel?.activationSize??gK;return a.type===`percentage`?vK(e,t,n,r,i,a.value):yK(e,t,n,r,i,a.value)}clearOwnOverlay(){let e=this._state!==void 0;if(this.removeDropTarget(),e){var t,n;(t=(n=this.options).getOverrideTarget)==null||(t=t.call(n))==null||t.clear()}}removeDropTarget(){if(this._state=void 0,this._edge=!1,this.targetElement){var e;(e=this.targetElement.parentElement)==null||e.classList.remove(`dv-drop-target`),this.targetElement.remove(),this.targetElement=void 0,this.overlayElement=void 0}}showOverlay(e){var t,n;let r=(t=this.options).getOverrideTarget?.call(t),i=(n=this.options).getOverlayOutline?.call(n)??this.element,a=i.offsetWidth,o=i.offsetHeight;if(!r&&!this.targetElement){let e=sK();this.targetElement=e.dropzone,this.overlayElement=e.selection,i.classList.add(`dv-drop-target`),i.append(this.targetElement)}this.toggleClasses(e,a,o),this._state=e}clearOverlay(){var e,t;this.removeDropTarget(),(e=(t=this.options).getOverrideTarget)==null||(e=e.call(t))==null||e.clear(),this._state=void 0}};_K.USED_EVENT_ID=`__dockview_droptarget_event_is_used__`;function vK(e,t,n,r,i,a){let o=100*t/r,s=100*n/i;return e.has(`left`)&&o<a?`left`:e.has(`right`)&&o>100-a?`right`:e.has(`top`)&&s<a?`top`:e.has(`bottom`)&&s>100-a?`bottom`:e.has(`center`)?`center`:null}function yK(e,t,n,r,i,a){return e.has(`left`)&&t<a?`left`:e.has(`right`)&&t>r-a?`right`:e.has(`top`)&&n<a?`top`:e.has(`bottom`)&&n>i-a?`bottom`:e.has(`center`)?`center`:null}function bK(e,t,n){EW(t,`dv-dragged`),t.style.top=`-9999px`,t.style.position=`absolute`,(n?.owner?eG(n.owner):(n?.ownerDocument??document).body).appendChild(t),e.setDragImage(t,n?.x??0,n?.y??0),setTimeout(()=>{TW(t,`dv-dragged`),t.remove()},0)}var xK=class e extends Y{static getInstance(){return e._instance??=new e,e._instance}constructor(){super(),this._targets=new Set,this._targetByElement=new Map,this._onDragStart=new X,this.onDragStart=this._onDragStart.event,this._onDragMove=new X,this.onDragMove=this._onDragMove.event,this._onDragEnd=new X,this.onDragEnd=this._onDragEnd.event,this.addDisposables(this._onDragStart,this._onDragMove,this._onDragEnd)}get active(){return this._active}registerTarget(e){return this._targets.add(e),this._targetByElement.set(e.element,e),{dispose:()=>{this._targets.delete(e),this._targetByElement.get(e.element)===e&&this._targetByElement.delete(e.element),this._currentTarget===e&&(this._currentTarget=void 0)}}}beginDrag(e){this._active&&this.cancel();let{pointerEvent:t,source:n}=e,r=e.getData();this._active={pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,source:n},this._lastPointerEvent=t,this._onDragMoveCallback=e.onDragMove,this._onDragEndCallback=e.onDragEnd,this._dataDisposable=r,this._ghost=e.ghost,this._iframeShield=UW(n.ownerDocument??document),this._selectionShield=WW(n.ownerDocument??document);let i={clientX:t.clientX,clientY:t.clientY,pointerEvent:t};this._onDragStart.fire(i);let a=n.ownerDocument?.defaultView??globalThis.window;this._moveListener=Z(a,`pointermove`,e=>{e.pointerId===this._active?.pointerId&&this._handleMove(e)}),this._upListener=Z(a,`pointerup`,e=>{e.pointerId===this._active?.pointerId&&this._handleEnd(e,!0)}),this._cancelListener=Z(a,`pointercancel`,e=>{e.pointerId===this._active?.pointerId&&this._handleEnd(e,!1)})}cancel(){var e,t;if(!this._active)return;let n=this._onDragEndCallback,r=this._lastPointerEvent;if((e=this._currentTarget)==null||e.handleDragLeave(),this._teardown(),(t=this._dataDisposable)==null||t.dispose(),this._dataDisposable=void 0,r){let e={clientX:r.clientX,clientY:r.clientY,pointerEvent:r};n?.(e,!1),this._onDragEnd.fire(e)}}_findTargetUnder(e,t){let n=(this._active?BW(this._active.source):document).elementsFromPoint(e,t);for(let e of n){let t=e;for(;t;){let e=this._targetByElement.get(t);if(e&&!e.isHitTestTransparent?.call(e))return e;t=t.parentElement}}}_handleMove(e){var t,n;this._lastPointerEvent=e,(t=this._ghost)==null||t.update(e.clientX,e.clientY);let r={clientX:e.clientX,clientY:e.clientY,pointerEvent:e},i=this._findTargetUnder(e.clientX,e.clientY);if(i!==this._currentTarget){var a;(a=this._currentTarget)==null||a.handleDragLeave(),this._currentTarget=i}i&&i.handleDragOver(r),(n=this._onDragMoveCallback)==null||n.call(this,r),this._onDragMove.fire(r)}_handleEnd(e,t){let n={clientX:e.clientX,clientY:e.clientY,pointerEvent:e};try{if(t&&this._currentTarget)this._currentTarget.handleDrop(n);else{var r;(r=this._currentTarget)==null||r.handleDragLeave()}}finally{let e=this._onDragEndCallback,r=this._dataDisposable;this._teardown(),this._dataDisposable=void 0,setTimeout(()=>r?.dispose(),0),e?.(n,t),this._onDragEnd.fire(n)}}_teardown(){var e,t,n,r,i,a;this._currentTarget=void 0,this._active=void 0,this._lastPointerEvent=void 0,this._onDragMoveCallback=void 0,this._onDragEndCallback=void 0,(e=this._ghost)==null||e.dispose(),this._ghost=void 0,(t=this._iframeShield)==null||t.release(),this._iframeShield=void 0,(n=this._selectionShield)==null||n.release(),this._selectionShield=void 0,(r=this._moveListener)==null||r.dispose(),(i=this._upListener)==null||i.dispose(),(a=this._cancelListener)==null||a.dispose(),this._moveListener=void 0,this._upListener=void 0,this._cancelListener=void 0}},SK={value:20,type:`percentage`},CK=class extends Y{get disabled(){return this._disabled}set disabled(e){this._disabled=e,e&&this._removeOverlay()}get state(){return this._state}constructor(e,t){super(),this.element=e,this.options=t,this._edge=!1,this._onDrop=new X,this.onDrop=this._onDrop.event,this._onWillShowOverlay=new X,this.onWillShowOverlay=this._onWillShowOverlay.event,this._disabled=!1,this._acceptedTargetZonesSet=new Set(t.acceptedTargetZones);let n={element:this.element,handleDragOver:e=>this._onDragOver(e),handleDragLeave:()=>this._onDragLeave(),handleDrop:e=>this._onDropEvent(e),isHitTestTransparent:t.isHitTestTransparent};this.addDisposables(this._onDrop,this._onWillShowOverlay,xK.getInstance().registerTarget(n))}clearOverlay(){this._clearOwnOverlay()}setTargetZones(e){this._acceptedTargetZonesSet=new Set(e)}setOverlayModel(e){this.options.overlayModel=e}dispose(){this._removeOverlay(),super.dispose()}_onDragOver(e){var t,n;if(this._disabled){this._clearOwnOverlay();return}let r=(t=this.options).getOverrideTarget?.call(t);if(this._acceptedTargetZonesSet.size===0){this._clearOwnOverlay();return}let i=(n=this.options).getOverlayOutline?.call(n)??this.element,a=i.offsetWidth,o=i.offsetHeight;if(a===0||o===0)return;let s=i.getBoundingClientRect(),c=e.clientX-s.left,l=e.clientY-s.top,u=this._resolvePosition(c,l,a,o,e.pointerEvent);if(u===null){this._clearOwnOverlay();return}let d=u.position;if(!this.options.canDisplayOverlay(e.pointerEvent,d)){this._clearOwnOverlay();return}let f=new pK({nativeEvent:e.pointerEvent,position:d,edge:u.edge,edgeGroup:u.edgeGroup});if(this._onWillShowOverlay.fire(f),f.defaultPrevented)this._clearOwnOverlay();else if(u.edge)this._clearOwnOverlay(),this._state=d,this._edge=!0;else if(this._edge=!1,r)fK({outlineElement:i,targetModel:r,quadrant:d,width:a,height:o,overlayModel:this.options.overlayModel,className:this.options.className}),this._state=d;else{if(!this._targetElement){let e=sK();this._targetElement=e.dropzone,this._overlayElement=e.selection,this._state=`center`,this.element.classList.add(`dv-drop-target`),this.element.append(this._targetElement)}this._overlayElement&&lK(this._overlayElement,d,a,o,this.options.overlayModel),this._state=d}}_onDragLeave(){var e;let t=(e=this.options).getOverrideTarget?.call(e);t?(this._state=void 0,t.clear()):this._removeOverlay()}_onDropEvent(e){var t;let n=this._state,r=this._edge,i=(t=this.options).getOverrideTarget?.call(t);this._removeOverlay(),i?.clear(),n&&this._onDrop.fire({position:n,nativeEvent:e.pointerEvent,edge:r})}_resolvePosition(e,t,n,r,i){var a;let o=(a=this.options).getPositionResolver?.call(a);if(o){let a=o.resolve({x:e,y:t,width:n,height:r,zones:this._acceptedTargetZonesSet,event:i});return a?{position:a.position,edge:!!a.edge,edgeGroup:!!a.edgeGroup}:null}let s=this._calculateQuadrant(e,t,n,r);return s?{position:s,edge:!1,edgeGroup:!1}:null}_calculateQuadrant(e,t,n,r){let i=this.options.overlayModel?.activationSize??SK;return i.type===`percentage`?vK(this._acceptedTargetZonesSet,e,t,n,r,i.value):yK(this._acceptedTargetZonesSet,e,t,n,r,i.value)}_clearOwnOverlay(){let e=this._state!==void 0;if(this._removeOverlay(),e){var t,n;(t=(n=this.options).getOverrideTarget)==null||(t=t.call(n))==null||t.clear()}}_removeOverlay(){if(this._edge=!1,this._targetElement){var e;this._state=void 0,(e=this._targetElement.parentElement)==null||e.classList.remove(`dv-drop-target`),this._targetElement.remove(),this._targetElement=void 0,this._overlayElement=void 0}else this._state=void 0}},wK=5,TK=250,EK=8,DK=class extends Y{constructor(e,t){super(),this.element=e,this.options=t,this._disabled=!1,this._armed=!1,this._startX=0,this._startY=0,this._touchOnly=t.touchOnly??!0,this.addDisposables(Z(this.element,`pointerdown`,e=>{this._onPointerDown(e)}))}setDisabled(e){this._disabled=e,e&&this._cancelPending()}setTouchOnly(e){this._touchOnly!==e&&(this._touchOnly=e,e&&this._cancelPending())}_shouldHandle(e){var t;return!(this._disabled||this._touchOnly&&e.pointerType!==`touch`&&e.pointerType!==`pen`||e.pointerType===`mouse`&&e.button!==0||(t=this.options).isCancelled?.call(t,e))}_onPointerDown(e){if(!this._shouldHandle(e))return;this._cancelPending(),this._selectionShield=WW(this.element.ownerDocument??document),this._pendingPointerId=e.pointerId,this._startX=e.clientX,this._startY=e.clientY,this._startEvent=e;let t=e.pointerType===`touch`||e.pointerType===`pen`,n=this.options.touchInitiationDelay,r=(typeof n==`function`?n():n)??TK;this._armed=!t||r<=0,t&&r>0&&Number.isFinite(r)&&(this._armTimer=setTimeout(()=>{this._armTimer=void 0,this._armed=!0},r));let i=this.options.threshold??wK,a=this.options.pressTolerance,o=(typeof a==`function`?a():a)??EK,s=this.element.ownerDocument?.defaultView??globalThis.window;this._pendingMoveListener=Z(s,`pointermove`,e=>{if(e.pointerId!==this._pendingPointerId)return;let t=e.clientX-this._startX,n=e.clientY-this._startY,r=Math.hypot(t,n);this._armed?r>=i&&this._beginDrag(e):r>o&&this._beginDrag(e)}),this._pendingUpListener=Z(s,`pointerup`,e=>{e.pointerId===this._pendingPointerId&&this._cancelPending()}),this._pendingCancelListener=Z(s,`pointercancel`,e=>{e.pointerId===this._pendingPointerId&&this._cancelPending()})}cancelPending(){this._cancelPending()}_cancelPending(){var e,t,n,r;(e=this._selectionShield)==null||e.release(),this._selectionShield=void 0,this._pendingPointerId=void 0,this._armTimer!==void 0&&(clearTimeout(this._armTimer),this._armTimer=void 0),this._armed=!1,(t=this._pendingMoveListener)==null||t.dispose(),(n=this._pendingUpListener)==null||n.dispose(),(r=this._pendingCancelListener)==null||r.dispose(),this._pendingMoveListener=void 0,this._pendingUpListener=void 0,this._pendingCancelListener=void 0,this._startEvent=void 0}_beginDrag(e){var t,n,r;let i=this._startEvent??e;this._cancelPending();let a=i.defaultPrevented;if((t=(n=this.options).onDragStart)==null||t.call(n,i),i.defaultPrevented&&!a)return;let o=(r=this.options).createGhost?.call(r,i);xK.getInstance().beginDrag({pointerEvent:e,source:this.element,getData:()=>this.options.getData(i),ghost:o,onDragMove:this.options.onDragMove,onDragEnd:this.options.onDragEnd})}dispose(){this._cancelPending(),super.dispose()}},OK=class{constructor(e){this._disposed=!1,this.element=e.element,this.offsetX=e.offsetX??0,this.offsetY=e.offsetY??0;let t=e.owner?eG(e.owner):document.body,n;zW(t)&&typeof this.element.showPopover==`function`&&(n=this.element.ownerDocument.createElement(`div`),n.popover=`manual`,Object.assign(n.style,{inset:`auto`,margin:`0`,padding:`0`,border:`0`,background:`transparent`,color:`inherit`,overflow:`visible`}),n.appendChild(this.element),this.element.style.pointerEvents=`none`,this.element.style.transform=`none`),this.container=n??this.element;let r=this.container.style;r.position=`fixed`,r.left=`0px`,r.top=`0px`,r.pointerEvents=`none`,r.zIndex=`99999`,r.opacity=String(e.opacity??.8),r.willChange=`transform`,r.transform=`translate3d(${e.initialX-this.offsetX}px, ${e.initialY-this.offsetY}px, 0)`,t.appendChild(this.container),n?.showPopover()}update(e,t){this._disposed||(this.container.style.transform=`translate3d(${e-this.offsetX}px, ${t-this.offsetY}px, 0)`)}dispose(){this._disposed||(this._disposed=!0,this.element.remove(),this.container!==this.element&&this.container.remove())}},kK=class extends Y{constructor(e,t){super(),this.el=e,this.opts=t,this._dataDisposable=new hW,this._pointerEventsDisposable=new hW,this._disabled=!!t.disabled,this.addDisposables(this._dataDisposable,this._pointerEventsDisposable,Z(this.el,`dragstart`,e=>{var t,n,r,i;if(e.defaultPrevented||this._disabled||(t=this.opts).isCancelled?.call(t,e)){e.preventDefault();return}if((n=(r=this.opts).onDragStart)==null||n.call(r,e),e.defaultPrevented)return;let a=UW(this.el.ownerDocument??document);this._pointerEventsDisposable.value={dispose:()=>a.release()},this.el.classList.add(`dv-dragged`),setTimeout(()=>this.el.classList.remove(`dv-dragged`),0),this._dataDisposable.value=this.opts.getData(e);let o=(i=this.opts).createGhost?.call(i,e);if(o&&e.dataTransfer&&(bK(e.dataTransfer,o.element,{x:o.offsetX??0,y:o.offsetY??0,ownerDocument:this.el.ownerDocument??void 0,owner:this.el}),o.dispose)){let e=o.dispose;setTimeout(()=>e(),0)}e.dataTransfer&&(e.dataTransfer.effectAllowed=`move`,e.dataTransfer.items.length===0&&e.dataTransfer.setData(`text/plain`,``))}),Z(this.el,`dragend`,e=>{var t,n;this._pointerEventsDisposable.dispose(),setTimeout(()=>this._dataDisposable.dispose(),0),(t=(n=this.opts).onDragEnd)==null||t.call(n,e)}))}setDisabled(e){this._disabled=e}setTouchOnly(e){}cancelPending(){}},AK=class{constructor(){this.kind=`html5`}createDropTarget(e,t){return new _K(e,t)}createDragSource(e,t){return new kK(e,t)}},jK=class{constructor(){this.kind=`pointer`}createDropTarget(e,t){return new CK(e,t)}createDragSource(e,t){let n=t.createGhost?n=>{let r=t.createGhost(n);if(!r)return;let i=new OK({element:r.element,initialX:n.clientX,initialY:n.clientY,offsetX:r.offsetX,offsetY:r.offsetY,owner:e});if(r.dispose){let e=i.dispose.bind(i),t=r.dispose;i.dispose=()=>{e(),t()}}return i}:void 0,r=new DK(e,{getData:t.getData,isCancelled:t.isCancelled,onDragStart:t.onDragStart,onDragEnd:t.onDragEnd?e=>t.onDragEnd(e.pointerEvent):void 0,createGhost:n,touchOnly:t.touchOnly,touchInitiationDelay:t.touchInitiationDelay,pressTolerance:t.pressTolerance,threshold:t.threshold});return t.disabled&&r.setDisabled(!0),r}},MK=new AK,NK=new jK,PK=Object.keys({disableAutoResizing:void 0,disableDnd:void 0,className:void 0}),FK=class extends vW{constructor(e,t,n,r){super(),this.nativeEvent=e,this.position=t,this.getData=n,this.panel=r}},IK=class extends _W{constructor(){super()}},LK=class extends Y{get isFocused(){return this._isFocused}get isActive(){return this._isActive}get isVisible(){return this._isVisible}get width(){return this._width}get height(){return this._height}constructor(e,t){super(),this.id=e,this.component=t,this._isFocused=!1,this._isActive=!1,this._isVisible=!0,this._width=0,this._height=0,this._parameters={},this.panelUpdatesDisposable=new hW,this._onDidDimensionChange=new X,this.onDidDimensionsChange=this._onDidDimensionChange.event,this._onDidChangeFocus=new X,this.onDidFocusChange=this._onDidChangeFocus.event,this._onWillFocus=new X,this.onWillFocus=this._onWillFocus.event,this._onDidVisibilityChange=new X,this.onDidVisibilityChange=this._onDidVisibilityChange.event,this._onWillVisibilityChange=new X,this.onWillVisibilityChange=this._onWillVisibilityChange.event,this._onDidActiveChange=new X,this.onDidActiveChange=this._onDidActiveChange.event,this._onActiveChange=new X,this.onActiveChange=this._onActiveChange.event,this._onDidParametersChange=new X,this.onDidParametersChange=this._onDidParametersChange.event,this.addDisposables(this.onDidFocusChange(e=>{this._isFocused=e.isFocused}),this.onDidActiveChange(e=>{this._isActive=e.isActive}),this.onDidVisibilityChange(e=>{this._isVisible=e.isVisible}),this.onDidDimensionsChange(e=>{this._width=e.width,this._height=e.height}),this.panelUpdatesDisposable,this._onDidDimensionChange,this._onDidChangeFocus,this._onDidVisibilityChange,this._onDidActiveChange,this._onWillFocus,this._onActiveChange,this._onWillFocus,this._onWillVisibilityChange,this._onDidParametersChange)}getParameters(){return this._parameters}initialize(e){this.panelUpdatesDisposable.value=this._onDidParametersChange.event(t=>{this._parameters=t,e.update({params:t})})}setVisible(e){this._onWillVisibilityChange.fire({isVisible:e})}setActive(){this._onActiveChange.fire()}updateParameters(e){this._onDidParametersChange.fire(e)}},RK=class extends LK{constructor(e,t){super(e,t),this._onDidConstraintsChangeInternal=new X,this.onDidConstraintsChangeInternal=this._onDidConstraintsChangeInternal.event,this._onDidConstraintsChange=new X({replay:!0}),this.onDidConstraintsChange=this._onDidConstraintsChange.event,this._onDidSizeChange=new X,this.onDidSizeChange=this._onDidSizeChange.event,this.addDisposables(this._onDidConstraintsChangeInternal,this._onDidConstraintsChange,this._onDidSizeChange)}setConstraints(e){this._onDidConstraintsChangeInternal.fire(e)}setSize(e){this._onDidSizeChange.fire(e)}},zK=class extends RK{set pane(e){this._pane=e}constructor(e,t){super(e,t),this._onDidExpansionChange=new X({replay:!0}),this.onDidExpansionChange=this._onDidExpansionChange.event,this._onMouseEnter=new X({}),this.onMouseEnter=this._onMouseEnter.event,this._onMouseLeave=new X({}),this.onMouseLeave=this._onMouseLeave.event,this.addDisposables(this._onDidExpansionChange,this._onMouseEnter,this._onMouseLeave)}setExpanded(e){var t;(t=this._pane)==null||t.setExpanded(e)}get isExpanded(){return!!this._pane?.isExpanded()}},BK=class extends Y{get element(){return this._element}get width(){return this._width}get height(){return this._height}get params(){return this._params?.params}constructor(e,t,n){super(),this.id=e,this.component=t,this.api=n,this._height=0,this._width=0,this._element=document.createElement(`div`),this._element.tabIndex=-1,this._element.style.outline=`none`,this._element.style.height=`100%`,this._element.style.width=`100%`,this._element.style.overflow=`hidden`;let r=OW(this._element);this.addDisposables(this.api,r.onDidFocus(()=>{this.api._onDidChangeFocus.fire({isFocused:!0})}),r.onDidBlur(()=>{this.api._onDidChangeFocus.fire({isFocused:!1})}),r)}focus(){let e=new IK;this.api._onWillFocus.fire(e),!e.defaultPrevented&&this._element.focus()}layout(e,t){this._width=e,this._height=t,this.api._onDidDimensionChange.fire({width:e,height:t}),this.part&&this._params&&this.part.update({params:this._params.params})}init(e){this._params=e,this.part=this.getComponent()}update(e){var t;this._params=$($({},this._params),{},{params:$($({},this._params?.params),e.params)});for(let t of Object.keys(e.params))e.params[t]===void 0&&delete this._params.params[t];(t=this.part)==null||t.update({params:this._params.params})}toJSON(){let e=this._params?.params??{};return{id:this.id,component:this.component,params:Object.keys(e).length>0?e:void 0}}dispose(){var e;this.api.dispose(),(e=this.part)==null||e.dispose(),super.dispose()}},VK=class extends BK{set orientation(e){this._orientation=e}get orientation(){return this._orientation}get minimumSize(){return this.headerSize+(this.isExpanded()?this._minimumBodySize:0)}get maximumSize(){return this.headerSize+(this.isExpanded()?this._maximumBodySize:0)}get size(){return this._size}get orthogonalSize(){return this._orthogonalSize}set orthogonalSize(e){this._orthogonalSize=e}get minimumBodySize(){return this._minimumBodySize}set minimumBodySize(e){this._minimumBodySize=typeof e==`number`?e:0}get maximumBodySize(){return this._maximumBodySize}set maximumBodySize(e){this._maximumBodySize=typeof e==`number`?e:1/0}get headerVisible(){return this._headerVisible}set headerVisible(e){this._headerVisible=e,this.header.style.display=e?``:`none`}constructor(e){super(e.id,e.component,new zK(e.id,e.component)),this._onDidChangeExpansionState=new X({replay:!0}),this.onDidChangeExpansionState=this._onDidChangeExpansionState.event,this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this._orthogonalSize=0,this._size=0,this._isExpanded=!1,this.api.pane=this,this.api.initialize(this),this.headerSize=e.headerSize,this.headerComponent=e.headerComponent,this._minimumBodySize=e.minimumBodySize,this._maximumBodySize=e.maximumBodySize,this._isExpanded=e.isExpanded,this._headerVisible=e.isHeaderVisible,this._onDidChangeExpansionState.fire(this.isExpanded()),this._orientation=e.orientation,this.element.classList.add(`dv-pane`),this.addDisposables(this.api.onWillVisibilityChange(e=>{let{isVisible:t}=e,{accessor:n}=this._params;n.setVisible(this,t)}),this.api.onDidSizeChange(e=>{this._onDidChange.fire({size:e.size})}),Z(this.element,`mouseenter`,e=>{this.api._onMouseEnter.fire(e)}),Z(this.element,`mouseleave`,e=>{this.api._onMouseLeave.fire(e)})),this.addDisposables(this._onDidChangeExpansionState,this.onDidChangeExpansionState(e=>{this.api._onDidExpansionChange.fire({isExpanded:e})}),this.api.onDidFocusChange(e=>{this.header&&(e.isFocused?EW(this.header,`focused`):TW(this.header,`focused`))})),this.renderOnce()}setVisible(e){this.api._onDidVisibilityChange.fire({isVisible:e})}setActive(e){this.api._onDidActiveChange.fire({isActive:e})}isExpanded(){return this._isExpanded}setExpanded(e){this._isExpanded!==e&&(this._isExpanded=e,e?(this.animationTimer&&clearTimeout(this.animationTimer),this.body&&this.element.appendChild(this.body)):(this._expandedSize=this._size,this.animationTimer=setTimeout(()=>{var e;(e=this.body)==null||e.remove()},200)),this._onDidChange.fire(e?{size:this._expandedSize??this.width}:{}),this._onDidChangeExpansionState.fire(e))}layout(e,t){this._size=e,this._orthogonalSize=t;let[n,r]=this.orientation===`HORIZONTAL`?[e,t]:[t,e];super.layout(n,r)}init(e){var t,n;super.init(e),typeof e.minimumBodySize==`number`&&(this.minimumBodySize=e.minimumBodySize),typeof e.maximumBodySize==`number`&&(this.maximumBodySize=e.maximumBodySize),this.bodyPart=this.getBodyComponent(),this.headerPart=this.getHeaderComponent(),this.bodyPart.init($($({},e),{},{api:this.api})),this.headerPart.init($($({},e),{},{api:this.api})),(t=this.body)==null||t.append(this.bodyPart.element),(n=this.header)==null||n.append(this.headerPart.element),typeof e.isExpanded==`boolean`&&this.setExpanded(e.isExpanded)}toJSON(){let e=this._params;return $($({},super.toJSON()),{},{headerComponent:this.headerComponent,title:e.title})}renderOnce(){this.header=document.createElement(`div`),this.header.tabIndex=0,this.header.className=`dv-pane-header`,this.header.style.height=`${this.headerSize}px`,this.header.style.lineHeight=`${this.headerSize}px`,this.header.style.minHeight=`${this.headerSize}px`,this.header.style.maxHeight=`${this.headerSize}px`,this.element.appendChild(this.header),this.body=document.createElement(`div`),this.body.className=`dv-pane-body`,this.element.appendChild(this.body)}getComponent(){return{update:e=>{var t,n;(t=this.bodyPart)==null||t.update(e),(n=this.headerPart)==null||n.update(e)},dispose:()=>{var e,t;(e=this.bodyPart)==null||e.dispose(),(t=this.headerPart)==null||t.dispose()}}}},HK=class extends VK{constructor(e){super({id:e.id,component:e.component,headerComponent:e.headerComponent,orientation:e.orientation,isExpanded:e.isExpanded,isHeaderVisible:!0,headerSize:e.headerSize,minimumBodySize:e.minimumBodySize,maximumBodySize:e.maximumBodySize}),this._onDidDrop=new X,this.onDidDrop=this._onDidDrop.event,this._onUnhandledDragOver=new X,this.onUnhandledDragOver=this._onUnhandledDragOver.event,this.accessor=e.accessor,this.addDisposables(this._onDidDrop,this._onUnhandledDragOver),e.disableDnd||this.initDragFeatures()}initDragFeatures(){if(!this.header)return;let e=this.id,t=this.accessor.id;this.header.draggable=!0;let n={getData:()=>(dW.getInstance().setData([new uW(t,e)],uW.prototype),{dispose:()=>{dW.getInstance().clearData(uW.prototype)}})};this.html5DragSource=MK.createDragSource(this.header,n),this.pointerDragSource=NK.createDragSource(this.header,n);let r={acceptedTargetZones:[`top`,`bottom`],overlayModel:{activationSize:{type:`percentage`,value:50}},canDisplayOverlay:(e,t)=>{let n=pW();if(n&&n.paneId!==this.id&&n.viewId===this.accessor.id)return!0;let r=new FK(e,t,pW,this);return this._onUnhandledDragOver.fire(r),r.isAccepted}};this.target=MK.createDropTarget(this.element,r),this.pointerTarget=NK.createDropTarget(this.element,r),this.addDisposables(this._onDidDrop,this.html5DragSource,this.pointerDragSource,this.target,this.pointerTarget,this.target.onDrop(e=>{this.onDrop(e)}),this.pointerTarget.onDrop(e=>{this.onDrop(e)}))}onDrop(e){let t=pW();if(t?.viewId!==this.accessor.id){this._onDidDrop.fire($($({},e),{},{panel:this,api:new eK(this.accessor),getData:pW}));return}let n=this._params.containerApi,r=t.paneId,i=n.getPanel(r);if(!i){this._onDidDrop.fire($($({},e),{},{panel:this,getData:pW,api:new eK(this.accessor)}));return}let a=n.panels,o=a.indexOf(i),s=n.panels.indexOf(this);(e.position===`left`||e.position===`top`)&&o<s&&s--,(e.position===`right`||e.position===`bottom`)&&(o>s&&s++,s=Math.min(a.length-1,s)),n.movePanel(o,s)}},UK=0,WK=()=>`dv-tabpanel-${UK++}`,GK=class extends Y{get element(){return this._element}get dimensions(){return this._dimensions}constructor(e,t){var n,r,i;super(),this.accessor=e,this.group=t,this.disposable=new hW,this._onDidFocus=new X,this.onDidFocus=this._onDidFocus.event,this._onDidBlur=new X,this.onDidBlur=this._onDidBlur.event,this._onDidDimensionsChange=new X,this.onDidDimensionsChange=this._onDidDimensionsChange.event,this._element=document.createElement(`div`),this._element.className=`dv-content-container`,this._element.tabIndex=-1,this._element.id=WK(),this._element.setAttribute(`role`,`tabpanel`),this.addDisposables(this._onDidFocus,this._onDidBlur,this._onDidDimensionsChange);let a=()=>t.dropTargetContainer?.model,o=(e,t)=>this.group.canDisplayContentOverlay(e,t);this.dropTarget=new _K(this.element,{getOverlayOutline:()=>e.options.theme?.dndPanelOverlay===`group`?this.element.parentElement:null,className:`dv-drop-target-content`,acceptedTargetZones:[`top`,`bottom`,`left`,`right`,`center`],canDisplayOverlay:o,getOverrideTarget:a,overlayModel:(n=this.accessor).resolveDropOverlayModel?.call(n,`content`),getPositionResolver:()=>e.getDropPositionResolver?.call(e)}),this.pointerDropTarget=NK.createDropTarget(this.element,{acceptedTargetZones:[`top`,`bottom`,`left`,`right`,`center`],canDisplayOverlay:o,getOverlayOutline:()=>e.options.theme?.dndPanelOverlay===`group`?this.element.parentElement:null,className:`dv-drop-target-content`,getOverrideTarget:a,overlayModel:(r=this.accessor).resolveDropOverlayModel?.call(r,`content`),getPositionResolver:()=>e.getDropPositionResolver?.call(e)}),this.addDisposables(this.dropTarget,this.pointerDropTarget,(i=this.accessor).onDidOptionsChange?.call(i,()=>{var e;let t=(e=this.accessor).resolveDropOverlayModel?.call(e,`content`)??{};this.dropTarget.setOverlayModel(t),this.pointerDropTarget.setOverlayModel(t)})??mW.NONE)}show(){this.element.style.display=``}hide(){this.element.style.display=`none`}setLabelledBy(e){e?this._element.setAttribute(`aria-labelledby`,e):this._element.removeAttribute(`aria-labelledby`)}renderPanel(e,t){let n=(t?.asActive??!0)||this.group.isPanelActive(e);if(n||this.panel===e){if(this.panel?.view.content.element.parentElement===this._element){var r,i;this.panel.view.content.element.remove(),(r=(i=this.panel.view.content).onHide)==null||r.call(i)}this.panel=e}let a;switch(e.api.renderer){case`onlyWhenVisible`:if(this.group.renderContainer.detatch(e),n){var o,s;this._element.appendChild(e.view.content.element),(o=(s=e.view.content).onShow)==null||o.call(s)}a=this._element;break;case`always`:e.view.content.element.parentElement===this._element&&e.view.content.element.remove(),a=this.group.renderContainer.attach({panel:e,referenceContainer:this});break;default:throw Error(`dockview: invalid renderer type '${e.api.renderer}'`)}if(n){let e=OW(a);this.focusTracker=e;let t=new Y;t.addDisposables(e,e.onDidFocus(()=>this._onDidFocus.fire()),e.onDidBlur(()=>this._onDidBlur.fire())),this.disposable.value=t}}openPanel(e){this.panel!==e&&this.renderPanel(e)}layout(e,t){(this._dimensions?.width!==e||this._dimensions.height!==t)&&(this._dimensions={width:e,height:t},this._onDidDimensionsChange.fire(this._dimensions))}closePanel(){if(this.panel&&this.panel.api.renderer===`onlyWhenVisible`){var e,t;this.panel.view.content.element.remove(),(e=(t=this.panel.view.content).onHide)==null||e.call(t)}this.panel=void 0}dispose(){this.disposable.dispose(),super.dispose()}refreshFocusState(){this.focusTracker?.refreshState&&this.focusTracker.refreshState()}},KK=e=>{let t=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);t.setAttributeNS(null,`height`,e.height),t.setAttributeNS(null,`width`,e.width),t.setAttributeNS(null,`viewBox`,e.viewbox),t.setAttributeNS(null,`aria-hidden`,`false`),t.setAttributeNS(null,`focusable`,`false`),t.classList.add(`dv-svg`);let n=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return n.setAttributeNS(null,`d`,e.path),t.appendChild(n),t},qK=()=>KK({width:`11`,height:`11`,viewbox:`0 0 28 28`,path:`M2.1 27.3L0 25.2L11.55 13.65L0 2.1L2.1 0L13.65 11.55L25.2 0L27.3 2.1L15.75 13.65L27.3 25.2L25.2 27.3L13.65 15.75L2.1 27.3Z`}),JK=()=>KK({width:`11`,height:`11`,viewbox:`0 0 24 24`,path:`M16 9V4h1c.55 0 1-.45 1-1s-.45-1-1-1H6c-.55 0-1 .45-1 1s.45 1 1 1h1v5c0 1.66-1.34 3-3 3v2h5.97v7l1 1 1-1v-7H19v-2c-1.66 0-3-1.34-3-3z`}),YK=()=>KK({width:`11`,height:`11`,viewbox:`0 0 24 15`,path:`M12 14.15L0 2.15L2.15 0L12 9.9L21.85 0.0499992L24 2.2L12 14.15Z`}),XK=()=>KK({width:`11`,height:`11`,viewbox:`0 0 15 25`,path:`M2.15 24.1L0 21.95L9.9 12.05L0 2.15L2.15 0L14.2 12.05L2.15 24.1Z`}),ZK=500,QK=8,$K=class extends Y{constructor(e,t){super(),this.element=e,this.options=t,this._startX=0,this._startY=0,this.addDisposables(Z(this.element,`pointerdown`,e=>{this._onPointerDown(e)}))}_onPointerDown(e){if((this.options.touchOnly??!0)&&e.pointerType!==`touch`&&e.pointerType!==`pen`)return;this._cancelPending(),this._pointerId=e.pointerId,this._startX=e.clientX,this._startY=e.clientY;let t=this.options.delay??ZK,n=this.options.tolerance??QK,r=this.element.ownerDocument?.defaultView??globalThis.window;this._timer=setTimeout(()=>{this._timer=void 0,this._cancelPending(),this._installContextMenuGuard(r),this._installClickGuard(r),this.options.onLongPress(e)},t),this._moveListener=Z(r,`pointermove`,e=>{if(e.pointerId!==this._pointerId)return;let t=e.clientX-this._startX,r=e.clientY-this._startY;Math.hypot(t,r)>n&&this._cancelPending()}),this._upListener=Z(r,`pointerup`,e=>{e.pointerId===this._pointerId&&this._cancelPending()}),this._cancelListener=Z(r,`pointercancel`,e=>{e.pointerId===this._pointerId&&this._cancelPending()})}_installContextMenuGuard(e){let t,n=setTimeout(()=>t?.dispose(),500);t=Z(e,`contextmenu`,e=>{e.preventDefault(),clearTimeout(n),t?.dispose()},{capture:!0})}_installClickGuard(e){let t,n=setTimeout(()=>t?.dispose(),500);t=Z(e,`click`,e=>{NW(e,[this.element])&&(e.preventDefault(),e.stopPropagation()),clearTimeout(n),t?.dispose()},{capture:!0})}_cancelPending(){var e,t,n;this._timer!==void 0&&(clearTimeout(this._timer),this._timer=void 0),this._pointerId=void 0,(e=this._moveListener)==null||e.dispose(),(t=this._upListener)==null||t.dispose(),(n=this._cancelListener)==null||n.dispose(),this._moveListener=void 0,this._upListener=void 0,this._cancelListener=void 0}dispose(){this._cancelPending(),super.dispose()}};function eq(e){if(e.disableDnd)return{html5:!1,pointer:!1,pointerHandlesMouse:!1};switch(e.dndStrategy){case`pointer`:return{html5:!1,pointer:!0,pointerHandlesMouse:!0};case`html5`:return{html5:!0,pointer:!1,pointerHandlesMouse:!1};case`auto`:case void 0:default:return tq()?{html5:!1,pointer:!0,pointerHandlesMouse:!0}:{html5:!0,pointer:!0,pointerHandlesMouse:!1}}}function tq(){if(globalThis.window===void 0||!globalThis.matchMedia)return!1;let e=globalThis.matchMedia(`(pointer: coarse)`).matches,t=globalThis.matchMedia(`(pointer: fine)`).matches;return e&&!t}var nq=0,rq=()=>`dv-tab-${nq++}`,iq=class extends Y{get element(){return this._element}constructor(e,t,n){var r,i,a,o,s;super(),this.panel=e,this.accessor=t,this.group=n,this.content=void 0,this.panelTransfer=dW.getInstance(),this._direction=`horizontal`,this._pinIndicator=void 0,this._onPointDown=new X,this.onPointerDown=this._onPointDown.event,this._onTabClick=new X,this.onTabClick=this._onTabClick.event,this._onDropped=new X,this.onDrop=this._onDropped.event,this._onDragStart=new X,this.onDragStart=this._onDragStart.event,this._onDragEnd=new X,this.onDragEnd=this._onDragEnd.event;let c=eq(this.accessor.options);this._element=document.createElement(`div`),this._element.className=`dv-tab`,this._element.tabIndex=-1,this._element.draggable=c.html5,this._element.id=rq(),this._element.setAttribute(`role`,`tab`),this._element.setAttribute(`aria-selected`,`false`),this._element.setAttribute(`aria-label`,this.panel.title??this.panel.id),this._element.dataset.tabPanelId=this.panel.id;let l=(r=this.group)==null||(r=r.model)==null?void 0:r.contentContainerId;l&&this._element.setAttribute(`aria-controls`,l),Q(this.element,`dv-inactive-tab`,!0),this._updatePinnedClasses();let u=(e,t)=>{if(this.group.locked)return!1;let n=fW();return this.accessor.id===n?.viewId?!(this.accessor.options.theme?.tabAnimation===`smooth`||n.tabGroupId&&n.groupId===this.group.id&&this.group.model.getTabGroupForPanel(this.panel.id)):this.group.model.canDisplayOverlay(e,t,`tab`)};this.dropTarget=MK.createDropTarget(this._element,{acceptedTargetZones:[`left`,`right`],overlayModel:this._buildOverlayModel(),canDisplayOverlay:u,getOverrideTarget:()=>n.model.dropTargetContainer?.model}),this.pointerDropTarget=NK.createDropTarget(this._element,{acceptedTargetZones:[`left`,`right`],overlayModel:this._buildOverlayModel(),canDisplayOverlay:u,getOverrideTarget:()=>n.model.dropTargetContainer?.model});let d={getData:()=>(this.panelTransfer.setData([new lW(this.accessor.id,this.group.id,this.panel.id)],lW.prototype),{dispose:()=>{this.panelTransfer.clearData(lW.prototype)}}),createGhost:()=>({element:this._buildGhostElement(),offsetX:30,offsetY:-10}),onDragStart:e=>{this._onDragStart.fire(e),!e.defaultPrevented&&!(e instanceof PointerEvent)&&this.accessor.options.theme?.tabAnimation===`smooth`&&requestAnimationFrame(()=>{Q(this.element,`dv-tab--dragging`,!0)})},onDragEnd:e=>{this._onDragEnd.fire(e)}};this.html5DragSource=MK.createDragSource(this._element,$($({},d),{},{disabled:!c.html5})),this.pointerDragSource=NK.createDragSource(this._element,$($({},d),{},{disabled:!c.pointer,touchOnly:!c.pointerHandlesMouse,isCancelled:()=>!eq(this.accessor.options).pointer})),this.onWillShowOverlay=gW.any(this.dropTarget.onWillShowOverlay,this.pointerDropTarget.onWillShowOverlay),this.addDisposables(this._onPointDown,this._onTabClick,this._onDropped,this._onDragStart,this._onDragEnd,this.accessor.onDidOptionsChange(()=>{let e=this._buildOverlayModel();this.dropTarget.setOverlayModel(e),this.pointerDropTarget.setOverlayModel(e),this._updatePinnedClasses()}),((i=this.panel.api)==null||(a=i.onDidChangePinned)==null?void 0:a.call(i,()=>{this._updatePinnedClasses()}))??{dispose:()=>{}},((o=this.panel.api)==null||(s=o.onDidTitleChange)==null?void 0:s.call(o,e=>{this._element.setAttribute(`aria-label`,e.title??this.panel.id)}))??{dispose:()=>{}},Z(this._element,`dragend`,()=>{Q(this.element,`dv-tab--dragging`,!1)}),this.html5DragSource,Z(this._element,`pointerdown`,e=>{this._onPointDown.fire(e)}),Z(this._element,`click`,e=>{this._onTabClick.fire(e)}),Z(this._element,`contextmenu`,e=>{var t;(t=this.accessor.contextMenuService)==null||t.show(this.panel,this.group,e)}),new $K(this._element,{onLongPress:e=>{var t;this.pointerDragSource.cancelPending(),(t=this.accessor.contextMenuService)==null||t.show(this.panel,this.group,e)}}),this.dropTarget.onDrop(e=>{this._onDropped.fire(e)}),this.pointerDropTarget.onDrop(e=>{this._onDropped.fire(e)}),this.dropTarget,this.pointerDropTarget,this.pointerDragSource)}_updatePinnedClasses(){let e=this.panel.api?.isPinned??!1,t=e&&this.accessor.options.pinnedTabs?.compact===!0;Q(this.element,`dv-tab--pinned`,e),Q(this.element,`dv-tab--pinned-compact`,t);let n=e&&!this.panel.api?.tabComponent;if(n&&!this._pinIndicator){let e=document.createElement(`div`);e.className=`dv-tab-pin`,e.appendChild(JK()),this._element.insertBefore(e,this._element.firstChild),this._pinIndicator=e}else!n&&this._pinIndicator&&(this._pinIndicator.remove(),this._pinIndicator=void 0)}setActive(e){Q(this.element,`dv-active-tab`,e),Q(this.element,`dv-inactive-tab`,!e),this._element.setAttribute(`aria-selected`,e?`true`:`false`),this._element.tabIndex=e?0:-1}setContent(e){this.content&&this.content.element.remove(),this.content=e,this._element.appendChild(this.content.element)}_buildOverlayModel(){var e;let t=(e=this.accessor).resolveDropOverlayModel?.call(e,`tab`,this.group);if(t)return t;let n=this.accessor.options.theme?.dndTabIndicator===`line`?1/0:0;return{activationSize:{value:50,type:`percentage`},smallWidthBoundary:n,smallHeightBoundary:n}}setDirection(e){this._direction=e;let t=e===`vertical`?[`top`,`bottom`]:[`left`,`right`];this.dropTarget.setTargetZones(t),this.pointerDropTarget.setTargetZones(t)}updateDragAndDropState(){let e=eq(this.accessor.options);this._element.draggable=e.html5,this.html5DragSource.setDisabled(!e.html5),this.pointerDragSource.setDisabled(!e.pointer),this.pointerDragSource.setTouchOnly(!e.pointerHandlesMouse)}_buildGhostElement(){let e=getComputedStyle(this.element),t=this.element.cloneNode(!0),n=this._direction===`vertical`,r=new Set([`writing-mode`,`inline-size`,`block-size`,`min-inline-size`,`min-block-size`,`max-inline-size`,`max-block-size`,`margin-inline`,`margin-inline-start`,`margin-inline-end`,`margin-block`,`margin-block-start`,`margin-block-end`,`padding-inline`,`padding-inline-start`,`padding-inline-end`,`padding-block`,`padding-block-start`,`padding-block-end`]);return Array.from(e).forEach(i=>{n&&r.has(i)||t.style.setProperty(i,e.getPropertyValue(i),e.getPropertyPriority(i))}),n&&(t.style.setProperty(`writing-mode`,`horizontal-tb`),t.style.setProperty(`width`,e.height),t.style.setProperty(`height`,e.width)),t.style.position=`absolute`,t.classList.add(`dv-tab-ghost-drag`),t}},aq=class{get kind(){return this.options.kind}get nativeEvent(){return this.event.nativeEvent}get position(){return this.event.position}get edge(){return this.event.edge}get edgeGroup(){return this.event.edgeGroup}get defaultPrevented(){return this.event.defaultPrevented}get panel(){return this.options.panel}get api(){return this.options.api}get group(){return this.options.group}preventDefault(){this.event.preventDefault()}getData(){return this.options.getData()}constructor(e,t){this.event=e,this.options=t}},oq=class extends Y{get group(){return this.groupAccessor()}constructor(e){var t;super(),this.panelTransfer=dW.getInstance(),this._onDragStart=new X,this.onDragStart=this._onDragStart.event,this._element=e.element,this.accessor=e.accessor;let n=e.group;this.groupAccessor=typeof n==`function`?n:()=>n,this.isFloatingMoveHandle=e.isFloatingMoveHandle??(()=>!0);let r=eq(this.accessor.options);this._element.draggable=r.html5,Q(this._element,`dv-draggable`,r.html5||r.pointer),this.addDisposables(this._onDragStart);let i=()=>{let e=document.createElement(`div`),t=globalThis.getComputedStyle(this._element),n=t.getPropertyValue(`--dv-activegroup-visiblepanel-tab-background-color`),r=t.getPropertyValue(`--dv-activegroup-visiblepanel-tab-color`);return e.style.backgroundColor=n,e.style.color=r,e.style.padding=`2px 8px`,e.style.height=`24px`,e.style.fontSize=`11px`,e.style.lineHeight=`20px`,e.style.borderRadius=`12px`,e.style.whiteSpace=`nowrap`,e.style.boxSizing=`border-box`,e.style.display=`inline-block`,e.textContent=`Multiple Panels (${this.group.size})`,e},a={getData:()=>(this.panelTransfer.setData([new lW(this.accessor.id,this.group.id,null)],lW.prototype),{dispose:()=>{this.panelTransfer.clearData(lW.prototype)}}),createGhost:()=>{var e;return(e=this.accessor).buildGroupDragGhost?.call(e,this.group)||{element:i(),offsetX:30,offsetY:-10}},onDragStart:e=>{this._onDragStart.fire(e)}};this.html5DragSource=MK.createDragSource(this._element,$($({},a),{},{disabled:!r.html5,isCancelled:e=>!!(this.group.api.location.type===`floating`&&this.isFloatingMoveHandle()&&!e.shiftKey||this.group.api.location.type===`edge`&&this.group.size===0)}));let o=()=>{var e;return((e=this.group)==null||(e=e.api)==null||(e=e.location)==null?void 0:e.type)===`floating`&&this.isFloatingMoveHandle()};this.pointerDragSource=NK.createDragSource(this._element,$($({},a),{},{disabled:!r.pointer,touchOnly:!r.pointerHandlesMouse,touchInitiationDelay:()=>o()?500:250,pressTolerance:()=>o()?1/0:8,isCancelled:()=>!eq(this.accessor.options).pointer||this.group.api.location.type===`edge`&&this.group.size===0,onDragStart:e=>{var t;let n=e.defaultPrevented;this._onDragStart.fire(e),e.defaultPrevented&&!n||(t=this.getFloatingOverlay())==null||t.cancelPendingDrag()}}));let s=new hW,c=()=>{let e=this.getFloatingOverlay();s.value=e?e.onDidStartMoving(()=>{this.pointerDragSource.cancelPending()}):mW.NONE};c(),this.addDisposables(s);let l=(t=this.group)==null||(t=t.api)==null?void 0:t.onDidLocationChange;l&&this.addDisposables(l(c)),this.addDisposables(this.html5DragSource,this.pointerDragSource)}updateDragAndDropState(){let e=eq(this.accessor.options);this._element.draggable=e.html5,Q(this._element,`dv-draggable`,e.html5||e.pointer),this.html5DragSource.setDisabled(!e.html5),this.pointerDragSource.setDisabled(!e.pointer),this.pointerDragSource.setTouchOnly(!e.pointerHandlesMouse)}getFloatingOverlay(){var e;if(this.group)return(e=this.accessor.floatingGroups)==null||(e=e.find(e=>e.group===this.group))==null?void 0:e.overlay}},sq=class extends Y{get element(){return this._element}constructor(e,t){var n,r,i;super(),this.accessor=e,this.group=t,this._onDrop=new X,this.onDrop=this._onDrop.event,this._onDragStart=new X,this.onDragStart=this._onDragStart.event,this._element=document.createElement(`div`),this._element.className=`dv-void-container`,this.addDisposables(this._onDrop,this._onDragStart,Z(this._element,`pointerdown`,()=>{this.accessor.doSetGroupActive(this.group)}),Z(this._element,`pointerdown`,e=>{e.shiftKey&&jW(e)},!0)),this.dragSource=new oq({element:this._element,accessor:this.accessor,group:this.group,isFloatingMoveHandle:()=>!this._element.closest(`.dv-resize-container-with-titlebar`)});let a=(e,n)=>{if(this.group.api.locked)return!1;let r=fW();return this.accessor.id===r?.viewId||t.model.canDisplayOverlay(e,n,`header_space`)};this.dropTarget=MK.createDropTarget(this._element,{acceptedTargetZones:[`center`],canDisplayOverlay:a,getOverrideTarget:()=>t.model.dropTargetContainer?.model,overlayModel:(n=this.accessor).resolveDropOverlayModel?.call(n,`header_space`,this.group)}),this.pointerDropTarget=NK.createDropTarget(this._element,{acceptedTargetZones:[`center`],canDisplayOverlay:a,getOverrideTarget:()=>t.model.dropTargetContainer?.model,overlayModel:(r=this.accessor).resolveDropOverlayModel?.call(r,`header_space`,this.group)}),this.onWillShowOverlay=gW.any(this.dropTarget.onWillShowOverlay,this.pointerDropTarget.onWillShowOverlay),this.addDisposables(this.dragSource,this.dragSource.onDragStart(e=>{this._onDragStart.fire(e)}),this.dropTarget.onDrop(e=>{this._onDrop.fire(e)}),this.pointerDropTarget.onDrop(e=>{this._onDrop.fire(e)}),this.dropTarget,this.pointerDropTarget,(i=this.accessor).onDidOptionsChange?.call(i,()=>{var e;let t=(e=this.accessor).resolveDropOverlayModel?.call(e,`header_space`,this.group)??{};this.dropTarget.setOverlayModel(t),this.pointerDropTarget.setOverlayModel(t)})??mW.NONE)}updateDragAndDropState(){this.dragSource.updateDragAndDropState()}},cq=class e extends Y{get element(){return this._element}get orientation(){return this._orientation}set orientation(e){this._orientation!==e&&(this._scrollOffset=0,this._orientation=e,TW(this._scrollbar,`dv-scrollbar-vertical`,`dv-scrollbar-horizontal`),e===`vertical`?EW(this._scrollbar,`dv-scrollbar-vertical`):EW(this._scrollbar,`dv-scrollbar-horizontal`))}constructor(t){super(),this.scrollableElement=t,this._scrollOffset=0,this._orientation=`horizontal`,this._element=document.createElement(`div`),this._element.className=`dv-scrollable`,this._scrollbar=document.createElement(`div`),this._scrollbar.className=`dv-scrollbar dv-scrollbar-horizontal`,this.element.appendChild(t),this.element.appendChild(this._scrollbar),this.addDisposables(Z(this.element,`wheel`,t=>{this._scrollOffset+=t.deltaY*e.MouseWheelSpeed,this.scheduleStyleUpdate()}),Z(this._scrollbar,`pointerdown`,e=>{e.preventDefault();let t=this._scrollbar.ownerDocument??document;Q(this.element,`dv-scrollable-scrolling`,!0);let n=this._orientation===`horizontal`?e.clientX:e.clientY,r=this._scrollOffset,i=e=>{let t=this._orientation===`horizontal`?e.clientX-n:e.clientY-n,i=(this._orientation===`horizontal`?this.element.clientWidth:this.element.clientHeight)/(this._orientation===`horizontal`?this.scrollableElement.scrollWidth:this.scrollableElement.scrollHeight);this._scrollOffset=r+t/i,this.scheduleStyleUpdate()},a=()=>{Q(this.element,`dv-scrollable-scrolling`,!1),t.removeEventListener(`pointermove`,i),t.removeEventListener(`pointerup`,a),t.removeEventListener(`pointercancel`,a)};t.addEventListener(`pointermove`,i),t.addEventListener(`pointerup`,a),t.addEventListener(`pointercancel`,a)}),Z(this.element,`scroll`,()=>{this.scheduleStyleUpdate()}),Z(this.scrollableElement,`scroll`,()=>{this._scrollOffset=this._orientation===`horizontal`?this.scrollableElement.scrollLeft:this.scrollableElement.scrollTop,this.scheduleStyleUpdate()}),wW(this.element,()=>{Q(this.element,`dv-scrollable-resizing`,!0),this._animationTimer&&clearTimeout(this._animationTimer),this._animationTimer=setTimeout(()=>{clearTimeout(this._animationTimer),Q(this.element,`dv-scrollable-resizing`,!1)},500),this.scheduleStyleUpdate()}),mW.from(()=>{this._pendingStyleFrame!==void 0&&(cancelAnimationFrame(this._pendingStyleFrame),this._pendingStyleFrame=void 0)}))}scheduleStyleUpdate(){this._pendingStyleFrame===void 0&&(this._pendingStyleFrame=requestAnimationFrame(()=>{this._pendingStyleFrame=void 0,this.calculateScrollbarStyles()}))}calculateScrollbarStyles(){let e=this._orientation===`horizontal`?this.element.clientWidth:this.element.clientHeight,t=this._orientation===`horizontal`?this.scrollableElement.scrollWidth:this.scrollableElement.scrollHeight;if(t>e){let n=e/t*e;this._orientation===`horizontal`?(this._scrollbar.style.width=`${n}px`,this._scrollbar.style.height=``):(this._scrollbar.style.height=`${n}px`,this._scrollbar.style.width=``),this._scrollOffset=mG(this._scrollOffset,0,t-e),this._orientation===`horizontal`?this.scrollableElement.scrollLeft=this._scrollOffset:this.scrollableElement.scrollTop=this._scrollOffset;let r=this._scrollOffset/(t-e);this._orientation===`horizontal`?(this._scrollbar.style.left=`${(e-n)*r}px`,this._scrollbar.style.top=``):(this._scrollbar.style.top=`${(e-n)*r}px`,this._scrollbar.style.left=``)}else this._orientation===`horizontal`?(this._scrollbar.style.width=`0px`,this._scrollbar.style.left=`0px`):(this._scrollbar.style.height=`0px`,this._scrollbar.style.top=`0px`),this._scrollOffset=0}};cq.MouseWheelSpeed=1;var lq=`dv-tabs-container--wrap`;function uq(e,t){return typeof e==`boolean`?e:!!e?.[t]}function dq(e){return typeof e==`boolean`?e:e?Object.values(e).some(Boolean):!1}var fq=class extends vW{constructor(e,t,n,r,i){super(),this.nativeEvent=e,this.target=t,this.position=n,this.getData=r,this.group=i}},pq=Object.keys({disableAutoResizing:void 0,proportionalLayout:void 0,hideBorders:void 0,singleTabMode:void 0,disableFloatingGroups:void 0,floatingGroupBounds:void 0,transformFloatingGroupDrag:void 0,smartGuides:void 0,floatingGroupDragHandle:void 0,popoutUrl:void 0,nonce:void 0,defaultRenderer:void 0,defaultHeaderPosition:void 0,debug:void 0,locked:void 0,disableDnd:void 0,dndStrategy:void 0,className:void 0,noPanelsOverlay:void 0,closeEmptyGroups:void 0,groupIdGenerator:void 0,dndEdges:void 0,dropPositionResolver:void 0,dndCompass:void 0,dropSizing:void 0,theme:void 0,disableTabsOverflowList:void 0,overflow:void 0,scrollbars:void 0,getTabContextMenuItems:void 0,getTabGroupChipContextMenuItems:void 0,createTabGroupChipComponent:void 0,createGroupDragGhostComponent:void 0,dropOverlayModel:void 0,announcements:void 0,getAnnouncement:void 0,announcer:void 0,messages:void 0,keyboardNavigation:void 0,layoutHistory:void 0,autoHideEdgeGroups:void 0,dockToEdgeGroups:void 0,edgeGroupPeek:void 0,tabGroupColors:void 0,tabGroupAccent:void 0,pinnedTabs:void 0});function mq(e){return!!e.referencePanel}function hq(e){return!!e.referenceGroup}function gq(e){return!!e.referencePanel}function _q(e){return!!e.referenceGroup}var vq=[{id:`grey`,value:`var(--dv-tab-group-color-grey)`,label:`Grey`},{id:`blue`,value:`var(--dv-tab-group-color-blue)`,label:`Blue`},{id:`red`,value:`var(--dv-tab-group-color-red)`,label:`Red`},{id:`yellow`,value:`var(--dv-tab-group-color-yellow)`,label:`Yellow`},{id:`green`,value:`var(--dv-tab-group-color-green)`,label:`Green`},{id:`pink`,value:`var(--dv-tab-group-color-pink)`,label:`Pink`},{id:`purple`,value:`var(--dv-tab-group-color-purple)`,label:`Purple`},{id:`cyan`,value:`var(--dv-tab-group-color-cyan)`,label:`Cyan`},{id:`orange`,value:`var(--dv-tab-group-color-orange)`,label:`Orange`}],yq=class{constructor(e,t=!0){this._entries=e.slice(),this._byId=new Map(e.map(e=>[e.id,e])),this._enabled=t}get enabled(){return this._enabled}set enabled(e){this._enabled=e}setEntries(e){this._entries=e.slice(),this._byId=new Map(e.map(e=>[e.id,e]))}entries(){return this._entries}has(e){return this._byId.has(e)}get(e){return this._byId.get(e)}defaultId(){return this._entries[0]?.id}resolveValue(e){if(!this._enabled||!e)return;let t=this._byId.get(e);return t?t.value:e}},bq;function xq(){return bq??=new yq(vq,!0),bq}function Sq(e,t,n){let r=(n??xq()).resolveValue(t);r===void 0?e.style.removeProperty(`--dv-tab-group-color`):e.style.setProperty(`--dv-tab-group-color`,r)}function Cq(e,t){return(t??xq()).resolveValue(e)}var wq=class extends Y{get element(){return this._element}constructor(e){super(),this._palette=e,this._onClick=new X,this.onClick=this._onClick.event,this._onContextMenu=new X,this.onContextMenu=this._onContextMenu.event,this._element=document.createElement(`div`),this._element.className=`dv-tab-group-chip`,this._element.tabIndex=0,this._label=document.createElement(`span`),this._label.className=`dv-tab-group-chip-label`,this._element.appendChild(this._label),this.addDisposables(this._onClick,this._onContextMenu,new $K(this._element,{onLongPress:e=>{this._onContextMenu.fire(e)}}),Z(this._element,`click`,e=>{this._onClick.fire(e)}),Z(this._element,`contextmenu`,e=>{this._onContextMenu.fire(e)}))}init(e){this._tabGroup=e.tabGroup,this.updateColor(e.tabGroup.color),this.updateLabel(e.tabGroup.label),this.updateCollapsed(e.tabGroup.collapsed),this.addDisposables(e.tabGroup.onDidChange(()=>{this._tabGroup&&(this.updateColor(this._tabGroup.color),this.updateLabel(this._tabGroup.label))}),e.tabGroup.onDidCollapseChange(e=>{this.updateCollapsed(e)}),this._onClick.event(()=>{var e;(e=this._tabGroup)==null||e.toggle()}))}update(e){this._tabGroup=e.tabGroup,this.updateColor(e.tabGroup.color),this.updateLabel(e.tabGroup.label),this.updateCollapsed(e.tabGroup.collapsed)}updateColor(e){Sq(this._element,e,this._palette),Q(this._element,`dv-tab-group-chip--accent-off`,this._palette?.enabled===!1)}updateLabel(e){this._label.textContent=e,Q(this._label,`dv-tab-group-chip-label--empty`,!e)}updateCollapsed(e){Q(this._element,`dv-tab-group-chip--collapsed`,e)}},Tq=`dv-tab-group-chip-continuation`,Eq=8,Dq=class{get underlines(){return this._underlines}constructor(e){this._ctx=e,this._underlines=new Map,this._continuationMarkers=new Map,this._rafId=null}positionUnderlines(){requestAnimationFrame(()=>{this._positionUnderlinesSync()})}trackUnderlines(){this._rafId!==null&&cancelAnimationFrame(this._rafId);let e=performance.now(),t=()=>{this._positionUnderlinesSync(),this._rafId=performance.now()-e<250?requestAnimationFrame(t):null};this._rafId=requestAnimationFrame(t)}syncUnderlineElements(e){for(let t of e)if(!this._underlines.has(t)){let e=document.createElement(`div`);e.className=`dv-tab-group-underline`,this._ctx.tabsList.appendChild(e),this._underlines.set(t,e)}for(let[t,n]of this._underlines)e.has(t)||(n.remove(),this._underlines.delete(t),this._clearContinuationMarkers(t))}getUnderline(e){return this._underlines.get(e)}dispose(){this._rafId!==null&&(cancelAnimationFrame(this._rafId),this._rafId=null);for(let[,e]of this._underlines)e.remove();this._underlines.clear(),this._clearContinuationMarkers()}_syncContinuationMarkers(e,t){let n=this._continuationMarkers.get(e);for(n||(n=[],this._continuationMarkers.set(e,n));n.length<t;){let e=document.createElement(`div`);e.className=Tq,this._ctx.tabsList.appendChild(e),n.push(e)}for(;n.length>t;)n.pop()?.remove();return n}_clearContinuationMarkers(e){if(e===void 0){for(let[,e]of this._continuationMarkers)for(let t of e)t.remove();this._continuationMarkers.clear();return}let t=this._continuationMarkers.get(e);if(t){for(let e of t)e.remove();this._continuationMarkers.delete(e)}}_positionUnderlinesSync(){let e=this._ctx.tabsList.getBoundingClientRect(),t=this._ctx.getTabGroups(),n=this._ctx.getDirection()===`vertical`,r=this._ctx.tabsList.classList.contains(lq);r||this._clearContinuationMarkers();let i=n?e.width:e.height,a=this._ctx.getActivePanelId(),o=this._ctx.getTabMap();for(let s of t){let t=this._underlines.get(s.id);if(!t)continue;let c=s.panelIds;if(c.length===0){t.style.display=`none`;continue}if(t.style.display=``,r){this._positionWrappedUnderline(t,s,e,o,n);continue}let l=this._ctx.getChipElement(s.id),u;if(l){let t=l.getBoundingClientRect(),r=getComputedStyle(l),i=n?Number.parseFloat(r.marginTop)||0:Number.parseFloat(r.marginLeft)||0;u=n?t.top-e.top-i:t.left-e.left-i}else{let t=c[0],r=o.get(t);if(r){let t=r.value.element.getBoundingClientRect();u=n?t.top-e.top:t.left-e.left}else u=0}let d=c[c.length-1],f=o.get(d);if(!f){n?(t.style.top=`${u}px`,t.style.height=`0px`,t.style.left=``,t.style.width=``):(t.style.left=`${u}px`,t.style.width=`0px`,t.style.top=``,t.style.height=``);continue}let p=f.value.element.getBoundingClientRect(),m=n?p.bottom-e.top:p.right-e.left,h=m-u;if((s.collapsed||s.panelIds.some(e=>o.get(e)?.value.element.classList.contains(`dv-tab--group-expanding`)))&&l){let t=l.getBoundingClientRect(),r=n?t.top+t.height/2-e.top:t.left+t.width/2-e.left,i=0,a=0;for(let e of s.panelIds){let t=o.get(e);if(!t)continue;let r=t.value.element;n?(i+=r.getBoundingClientRect().height,a+=r.scrollHeight):(i+=r.getBoundingClientRect().width,a+=r.scrollWidth)}let c=a>0?Math.min(1,i/a):0;u=r+(u-r)*c,m=r+(m-r)*c,h=Math.max(0,m-u)}n?(t.style.top=`${u}px`,t.style.height=`${Math.max(0,h)}px`,t.style.left=``,t.style.width=``,t.style.bottom=``):(t.style.left=`${u}px`,t.style.width=`${Math.max(0,h)}px`,t.style.top=``,t.style.height=``,t.style.bottom=``),this.applyShape(t,s,u,h,i,a,e,n)}}_positionWrappedUnderline(e,t,n,r,i){let a=Cq(t.color,this._ctx.getColorPalette());if(a===void 0){e.style.display=`none`,this._clearContinuationMarkers(t.id);return}let{runs:o,firstRun:s}=this._computeWrappedRuns(t,n,r,i);if(o.length===0){e.style.display=`none`,this._clearContinuationMarkers(t.id);return}this._positionContinuationMarkers(t.id,o,s,a,i);let c=Math.min(...o.map(e=>e.left)),l=Math.max(...o.map(e=>e.right)),u=Math.min(...o.map(e=>e.top)),d=Math.max(...o.map(e=>e.bottom)),f=i?Math.max(0,l-c):n.width,p=i?n.height:Math.max(0,d-u);e.style.left=i?`${c}px`:`0px`,e.style.top=i?`0px`:`${u}px`,e.style.bottom=`auto`,e.style.width=`${f}px`,e.style.height=`${p}px`,e.style.backgroundColor=``;let{svg:m,path:h}=this.ensureSvgPath(e);m.setAttribute(`width`,String(f)),m.setAttribute(`height`,String(p)),h.setAttribute(`stroke`,a),h.setAttribute(`stroke-width`,`2`);let g=this._ctx.getHeaderPosition(),_=i?g===`right`:g===`bottom`;h.setAttribute(`d`,this._wrappedPathData(o,i,_,c,u,2))}_computeWrappedRuns(e,t,n,r){let i=[],a;for(let o of e.panelIds){let e=n.get(o);if(!e)continue;let s=e.value.element.getBoundingClientRect();if(s.width===0&&s.height===0)continue;let c=s.top-t.top,l=s.bottom-t.top,u=s.left-t.left,d=s.right-t.left,f=r?u:c,p=i.find(e=>Math.abs((r?e.left:e.top)-f)<=2);p?(p.top=Math.min(p.top,c),p.bottom=Math.max(p.bottom,l),p.left=Math.min(p.left,u),p.right=Math.max(p.right,d)):(p={top:c,bottom:l,left:u,right:d},i.push(p)),a??=p}return{runs:i,firstRun:a}}_wrappedPathData(e,t,n,r,i,a){let o=``;for(let s of e)if(t){let e=n?s.right-r-a/2:s.left-r+a/2;o+=`M ${e},${s.top} L ${e},${s.bottom} `}else{let e=n?s.top-i+a/2:s.bottom-i-a/2;o+=`M ${s.left},${e} L ${s.right},${e} `}return o.trim()}_positionContinuationMarkers(e,t,n,r,i){let a=t.filter(e=>e!==n),o=this._syncContinuationMarkers(e,a.length);a.forEach((e,t)=>{let n=o[t];if(n.style.backgroundColor=r,i){let t=(e.left+e.right)/2;n.style.left=`${t-Eq/2}px`,n.style.top=`${e.top}px`}else{let t=(e.top+e.bottom)/2;n.style.left=`${e.left}px`,n.style.top=`${t-Eq/2}px`}})}ensureSvgPath(e){let t=e.firstElementChild;if(t?.tagName===`svg`)return{svg:t,path:t.firstElementChild};e.replaceChildren();let n=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);n.style.display=`block`;let r=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return r.setAttribute(`fill`,`none`),n.appendChild(r),e.appendChild(n),{svg:n,path:r}}},Oq=class extends Dq{_applyStraightLine(e,t,n,r,i,a,o){let s=o?i:r,c=o?r:i;e.setAttribute(`width`,String(s)),e.setAttribute(`height`,String(c)),n.style.width=`${s}px`,n.style.height=`${c}px`,t.setAttribute(`d`,o?`M ${a},0 L ${a},${r}`:`M 0,${a} L ${r},${a}`)}applyShape(e,t,n,r,i,a,o,s){let c=i,l=r,u=Cq(t.color,this._ctx.getColorPalette());if(l<=0||c<=0||u===void 0){e.style.display=`none`;return}e.style.display=``;let d;a&&t.panelIds.includes(a)&&(d=this._ctx.getTabMap().get(a));let{svg:f,path:p}=this.ensureSvgPath(e);p.setAttribute(`stroke`,u),p.setAttribute(`stroke-width`,`2`);let m=this._ctx.getHeaderPosition(),h=!s&&m===`bottom`,g=s&&m===`right`,_,v;if(s?(_=g?c-2:2,v=g?2:c-2):(_=h?2:c-2,v=h?c-2:2),!d){this._applyStraightLine(f,p,e,l,c,_,s);return}let y=d.value.element.getBoundingClientRect(),b,x;if(s?(b=Math.max(0,y.top-o.top-n),x=Math.min(l,y.bottom-o.top-n)):(b=Math.max(0,y.left-o.left-n),x=Math.min(l,y.right-o.left-n)),x<=b){this._applyStraightLine(f,p,e,l,c,_,s);return}let S=v>_?1:-1;if(s){let t=c,n=l;f.setAttribute(`width`,String(t)),f.setAttribute(`height`,String(n)),e.style.width=`${t}px`,e.style.height=`${n}px`;let r=[`M ${_},0`,`L ${_},${b-6}`,`Q ${_},${b} ${_+S*6},${b}`,`L ${v-S*6},${b}`,`Q ${v},${b} ${v},${b+6}`,`L ${v},${x-6}`,`Q ${v},${x} ${v-S*6},${x}`,`L ${_+S*6},${x}`,`Q ${_},${x} ${_},${x+6}`,`L ${_},${n}`].join(` `);p.setAttribute(`d`,r)}else{let t=l,n=c;f.setAttribute(`width`,String(t)),f.setAttribute(`height`,String(n)),e.style.width=`${t}px`,e.style.height=`${n}px`;let r=[`M 0,${_}`,`L ${b-6},${_}`,`Q ${b},${_} ${b},${_+S*6}`,`L ${b},${v-S*6}`,`Q ${b},${v} ${b+6},${v}`,`L ${x-6},${v}`,`Q ${x},${v} ${x},${v-S*6}`,`L ${x},${_+S*6}`,`Q ${x},${_} ${x+6},${_}`,`L ${t},${_}`].join(` `);p.setAttribute(`d`,r)}}},kq=class extends Dq{applyShape(e,t,n,r,i,a,o,s){let c=Cq(t.color,this._ctx.getColorPalette());r<=0||c===void 0?e.style.display=`none`:(e.style.display=``,e.firstElementChild&&e.replaceChildren(),e.style.backgroundColor=c,s?(e.style.width=`2px`,e.style.height=`${r}px`):(e.style.width=`${r}px`,e.style.height=`2px`))}},Aq=new Map,jq=class{get chipRenderers(){return this._chipRenderers}get groupUnderlines(){return this._indicator?.underlines??Aq}get skipNextCollapseAnimation(){return this._skipNextCollapseAnimation}set skipNextCollapseAnimation(e){this._skipNextCollapseAnimation=e}constructor(e,t){this._ctx=e,this._callbacks=t,this._chipRenderers=new Map,this._indicator=null,this._skipNextCollapseAnimation=!1,this._pendingTransitionCleanups=new Map}update(){let e=this._ctx.group.model.getTabGroups(),t=new Set;for(let n of e)t.add(n.id),this._ensureChipForGroup(n),this._positionChipForGroup(n);for(let[e,r]of this._chipRenderers)if(!t.has(e)){var n;r.chip.element.remove(),r.chip.dispose(),(n=r.dragSourcesDisposable)==null||n.dispose(),r.disposable.dispose(),this._chipRenderers.delete(e)}this._updateTabGroupClasses()}refreshAccents(){for(let n of this._ctx.group.model.getTabGroups()){var e,t;let r=this._chipRenderers.get(n.id);r==null||(t=(e=r.chip).update)==null||t.call(e,{tabGroup:n})}this._updateTabGroupClasses()}positionAllChips(){if(this._chipRenderers.size!==0)for(let e of this._ctx.group.model.getTabGroups())this._positionChipForGroup(e)}updateDirection(){let e=this._ctx.getDirection()===`vertical`;for(let[,t]of this._chipRenderers){let n=e?[`top`]:[`left`];t.dropTarget.setTargetZones(n),t.pointerDropTarget.setTargetZones(n)}}clearChipDropOverlays(){for(let[,n]of this._chipRenderers){var e,t;(e=n.dropTarget)==null||e.clearOverlay(),(t=n.pointerDropTarget)==null||t.clearOverlay()}}snapshotChipSizes(){let e=this._ctx.getDirection()===`vertical`,t=new Map;for(let[n,r]of this._chipRenderers){let i=r.chip.element.getBoundingClientRect();t.set(n,e?i.height:i.width)}return t}positionUnderlines(){var e;(e=this._indicator)==null||e.positionUnderlines()}trackUnderlines(){var e;(e=this._indicator)==null||e.trackUnderlines()}setGroupDragImage(e,t,n){if(!e.dataTransfer)return;let r=this._ctx.getDirection()===`vertical`,i=this._ctx.tabsList.cloneNode(!0);r?(i.classList.remove(`dv-tabs-container-vertical`,`dv-vertical`),i.classList.add(`dv-horizontal`),i.style.writingMode=`horizontal-tb`,i.style.height=`${this._ctx.tabsList.offsetWidth}px`):i.style.height=`${this._ctx.tabsList.offsetHeight}px`,i.style.width=`auto`,i.style.overflow=`visible`,i.style.pointerEvents=`none`;let a=Array.from(i.children),o=Array.from(this._ctx.tabsList.children);for(let e=a.length-1;e>=0;e--)o[e]!==n&&a[e].remove();let s=document.createElement(`div`);s.className=`dv-groupview dv-active-group`,s.style.position=`fixed`,s.style.top=`-10000px`,s.style.left=`0px`,s.style.height=`auto`,s.style.width=`auto`,s.style.pointerEvents=`none`;let c=document.createElement(`div`);c.className=`dv-tabs-and-actions-container`,c.style.height=`auto`,c.style.width=`auto`,s.appendChild(c),c.appendChild(i),this._ctx.accessor.element.appendChild(s);let l=i.querySelector(`.dv-tab-group-chip`),u=n.getBoundingClientRect(),d=e.clientX-u.left,f=e.clientY-u.top;if(l){let t=l.getBoundingClientRect(),n=s.getBoundingClientRect(),r=t.left-n.left+d,i=t.top-n.top+f;e.dataTransfer.setDragImage(s,r,i)}else e.dataTransfer.setDragImage(s,d,f);requestAnimationFrame(()=>{s.remove()})}cleanupTransition(e){var t;(t=this._pendingTransitionCleanups.get(e))==null||t(),this._pendingTransitionCleanups.delete(e)}updateDragAndDropState(){let e=eq(this._ctx.accessor.options);for(let i of this._chipRenderers.values()){var t,n,r;i.chip.element.draggable=e.html5,(t=i.html5DragSource)==null||t.setDisabled(!e.html5),(n=i.pointerDragSource)==null||n.setDisabled(!e.pointer),(r=i.pointerDragSource)==null||r.setTouchOnly(!e.pointerHandlesMouse)}}disposeChipDrag(e){var t;let n=this._chipRenderers.get(e);n&&((t=n.dragSourcesDisposable)==null||t.dispose(),n.html5DragSource=void 0,n.pointerDragSource=void 0,n.dragSourcesDisposable=void 0)}_buildChipGhostElement(e){let t=getComputedStyle(e),n=e.cloneNode(!0);return Array.from(t).forEach(e=>{n.style.setProperty(e,t.getPropertyValue(e),t.getPropertyPriority(e))}),n.style.position=`absolute`,n}disposeAll(){var e;(e=this._indicator)==null||e.dispose(),this._indicator=null;for(let[,e]of this._pendingTransitionCleanups)e();this._pendingTransitionCleanups.clear();for(let[,e]of this._chipRenderers){var t;e.chip.element.remove(),e.chip.dispose(),(t=e.dragSourcesDisposable)==null||t.dispose(),e.disposable.dispose()}this._chipRenderers.clear()}_ensureIndicator(){let e=(this._ctx.accessor.options.theme?.tabGroupIndicator??`wrap`)===`none`?kq:Oq;this._indicator&&!(this._indicator instanceof e)&&(this._indicator.dispose(),this._indicator=null),this._indicator??=new e({tabsList:this._ctx.tabsList,getTabGroups:()=>this._ctx.group.model.getTabGroups(),getActivePanelId:()=>this._ctx.group.activePanel?.id,getTabMap:()=>this._ctx.getTabMap(),getChipElement:e=>this._chipRenderers.get(e)?.chip.element,getDirection:()=>this._ctx.getDirection(),getHeaderPosition:()=>this._ctx.group.model.headerPosition,getColorPalette:()=>this._ctx.accessor.tabGroupColorPalette})}_createChipDragSources(e,t){let n=eq(this._ctx.accessor.options);e.element.draggable=n.html5;let r=dW.getInstance(),i=()=>(r.setData([new lW(this._ctx.accessor.id,this._ctx.group.id,null,t.id)],lW.prototype),{dispose:()=>{r.clearData(lW.prototype)}}),a=MK.createDragSource(e.element,{getData:i,disabled:!n.html5,isCancelled:()=>!eq(this._ctx.accessor.options).html5,onDragStart:n=>{`dataTransfer`in n&&n.dataTransfer&&this.setGroupDragImage(n,t,e.element),this._callbacks.onChipDragStart(t,e,n)},onDragEnd:n=>{var r,i;(r=(i=this._callbacks).onChipDragEnd)==null||r.call(i,t,e,n)}}),o=()=>{r.clearData(lW.prototype)};e.element.addEventListener(`dragend`,o,{once:!0});let s=NK.createDragSource(e.element,{getData:i,disabled:!n.pointer,touchOnly:!n.pointerHandlesMouse,isCancelled:()=>!eq(this._ctx.accessor.options).pointer,createGhost:()=>({element:this._buildChipGhostElement(e.element),offsetX:8,offsetY:8}),onDragStart:n=>{this._callbacks.onChipDragStart(t,e,n)}});return{html5DragSource:a,pointerDragSource:s,disposable:{dispose:()=>{a.dispose(),s.dispose(),e.element.removeEventListener(`dragend`,o)}}}}_ensureChipForGroup(e){let t=this._chipRenderers.get(e.id);if(t){if(!t.html5DragSource){let n=this._createChipDragSources(t.chip,e);t.html5DragSource=n.html5DragSource,t.pointerDragSource=n.pointerDragSource,t.dragSourcesDisposable=n.disposable}return}let n=this._ctx.accessor.options.createTabGroupChipComponent,r=n?n(e):new wq(this._ctx.accessor.tabGroupColorPalette);r.init({tabGroup:e,api:this._ctx.accessor.api});let i=this._createChipDragSources(r,e),a=[e.onDidChange(()=>{var t;(t=r.update)==null||t.call(r,{tabGroup:e}),this._updateTabGroupClasses()}),e.onDidPanelChange(()=>{this._positionChipForGroup(e),this._updateTabGroupClasses()}),e.onDidCollapseChange(()=>{this._updateTabGroupClasses()})],o=t=>{var n;(n=this._chipRenderers.get(e.id))==null||(n=n.pointerDragSource)==null||n.cancelPending(),this._callbacks.onChipContextMenu(e,t)};r instanceof wq?a.push(r.onContextMenu(o)):a.push(new $K(r.element,{onLongPress:o}),Z(r.element,`contextmenu`,o));let s={acceptedTargetZones:this._ctx.getDirection()===`vertical`?[`top`]:[`left`],overlayModel:{activationSize:{value:100,type:`percentage`}},canDisplayOverlay:(e,t)=>{if(this._ctx.group.locked||this._ctx.accessor.options.disableDnd)return!1;let n=fW();return this._ctx.accessor.id===n?.viewId?!(this._ctx.accessor.options.theme?.tabAnimation===`smooth`&&!n.tabGroupId):this._ctx.group.model.canDisplayOverlay(e,t,`tab`)}},c=MK.createDropTarget(r.element,s),l=NK.createDropTarget(r.element,s),u=t=>{this._callbacks.onChipDrop(e,t)};a.push(c,c.onDrop(u),l,l.onDrop(u));let d=new Y(...a);this._chipRenderers.set(e.id,{chip:r,html5DragSource:i.html5DragSource,pointerDragSource:i.pointerDragSource,dragSourcesDisposable:i.disposable,disposable:d,dropTarget:c,pointerDropTarget:l}),e.collapsed&&(this._skipNextCollapseAnimation=!0)}_positionChipForGroup(e){let t=this._chipRenderers.get(e.id);if(!t)return;let n=t.chip.element,r=e.panelIds;if(r.length===0){n.remove();return}let i=r[0],a=this._ctx.getTabMap().get(i);if(!a){n.remove();return}let o=a.value.element;n.nextSibling!==o&&this._ctx.tabsList.insertBefore(n,o)}_updateTabGroupClasses(){let e=this._ctx.group.model.getTabGroups(),t=this._ctx.getTabs(),n=this._ctx.getTabMap(),r=!1,i=new Map;for(let t of e)for(let e of t.panelIds)i.set(e,t);for(let e of t){let t=e.value,n=t.panel.id,o=i.get(n),s=!!o;if(Q(t.element,`dv-tab--grouped`,s),o){let e=o.panelIds,i=e[0]===n,s=e[e.length-1]===n;Q(t.element,`dv-tab--group-first`,i),Q(t.element,`dv-tab--group-last`,s),Sq(t.element,o.color,this._ctx.accessor.tabGroupColorPalette);let c=t.element.classList.contains(`dv-tab--group-collapsed`);if(!o.collapsed&&c){var a;r=!0,t.element.classList.remove(`dv-tab--group-collapsed`),t.element.classList.add(`dv-tab--group-expanding`),(a=this._pendingTransitionCleanups.get(n))==null||a();let e=()=>{t.element.classList.remove(`dv-tab--group-expanding`),t.element.style.removeProperty(`width`),t.element.removeEventListener(`transitionend`,e),clearTimeout(i),this._pendingTransitionCleanups.delete(n)},i=setTimeout(e,300);this._pendingTransitionCleanups.set(n,e),t.element.addEventListener(`transitionend`,e)}}else Q(t.element,`dv-tab--group-first`,!1),Q(t.element,`dv-tab--group-last`,!1),t.element.classList.remove(`dv-tab--group-collapsed`,`dv-tab--group-expanding`),t.element.style.removeProperty(`width`),t.element.style.removeProperty(`--dv-tab-group-color`)}let o=new Set;for(let t of e)if(o.add(t.id),t.collapsed&&t.panelIds.some(e=>{let t=n.get(e);return t&&!t.value.element.classList.contains(`dv-tab--group-collapsed`)})){if(this._skipNextCollapseAnimation){let e=[];for(let r of t.panelIds){let t=n.get(r);t&&(t.value.element.style.transition=`none`,t.value.element.classList.add(`dv-tab--group-collapsed`),e.push(t.value.element))}if(e.length>0){e[0].offsetHeight;for(let t of e)t.style.removeProperty(`transition`)}}else{r=!0;let e=this._ctx.getDirection()===`vertical`;for(let r of t.panelIds){let t=n.get(r);if(t&&!t.value.element.classList.contains(`dv-tab--group-collapsed`)){let n=t.value.element.getBoundingClientRect();e?t.value.element.style.height=`${n.height}px`:t.value.element.style.width=`${n.width}px`,t.value.element.offsetHeight,t.value.element.classList.add(`dv-tab--group-collapsed`)}}}}this._skipNextCollapseAnimation=!1,this._ensureIndicator(),this._indicator&&(this._indicator.syncUnderlineElements(o),r?this._indicator.trackUnderlines():this._indicator.positionUnderlines())}};function Mq(e,t){return t===`vertical`?e.height:e.width}function Nq(e,t){return t===`vertical`?e.top:e.left}function Pq(e,t){return t===`vertical`?e.clientY:e.clientX}var Fq=class extends Y{get _tabs(){return this.host.tabItems}get _tabMap(){return this.host.tabMap}get _tabsList(){return this.host.tabsList}get _direction(){return this.host.direction}get group(){return this.host.groupPanel}get accessor(){return this.host.component}get _tabGroupManager(){return this.host.tabGroupManager}get _wrapMode(){return this._tabsList.classList.contains(lq)}get animState(){return this._animState}set animState(e){this._animState=e}get pendingCollapse(){return this._pendingCollapse}set pendingCollapse(e){this._pendingCollapse=e}set voidContainerElement(e){this._voidContainer=e}constructor(e){super(),this.host=e,this._animState=null,this._pendingMarginCleanups=new Map,this._pendingCollapse=!1,this._flipTransitionCleanup=null,this._voidContainer=null,this._extendedDropZone=null,this._pointerInsideTabsList=!1,this._wrapIndicatorEl=null,this.addDisposables({dispose:()=>{var e;(e=this._flipTransitionCleanup)==null||e.call(this)}})}setExtendedDropZone(e){this._extendedDropZone=e}setExternalInsertionIndex(e){this._animState&&e!==this._animState.currentInsertionIndex&&(this._animState.currentInsertionIndex=e,this.applyDragOverTransforms())}clearExternalAnimState(){this._animState&&(this.resetTabTransforms(),this._animState.sourceIndex===-1?this._animState=null:this._animState.currentInsertionIndex=null)}snapshotTabPositions(){let e=new Map;for(let t of this._tabs)e.set(t.value.panel.id,t.value.element.getBoundingClientRect());return e}_mainAxisSize(e){return Mq(e,this._direction)}_mainAxisStart(e){return Nq(e,this._direction)}_mainAxisCoord(e,t){return Pq({clientX:e,clientY:t},this._direction)}get _gapMarginProperty(){return this._direction===`vertical`?`margin-top`:`margin-left`}getAverageTabSize(){if(this._tabs.length===0)return 0;let e=0;for(let t of this._tabs)e+=this._mainAxisSize(t.value.element.getBoundingClientRect());return e/this._tabs.length}handlePointerDragMove(e,t){let n=BW(this._tabsList).elementFromPoint(e,t);n&&(this._tabsList.contains(n)||this._extendedDropZone&&this._extendedDropZone.contains(n))?(this._pointerInsideTabsList=!0,this.processDragOver(e,t)):this._pointerInsideTabsList&&(this._pointerInsideTabsList=!1,this.processDragLeave(n))}handlePointerDragEnd(e){if(e&&this._animState&&this._animState.sourceIndex!==-1&&this._animState.currentInsertionIndex!==null&&this.isPointInsideTabsList(e.clientX,e.clientY)){let t=this._animState.sourceTabGroupId;if(t){let e=this._animState.currentInsertionIndex;this._animState=null,this.commitGroupMove(t,e)}else this.commitPointerReorder(e.pointerEvent)}this._pointerInsideTabsList=!1,this.resetDragAnimation()}isPointInsideTabsList(e,t){let n=BW(this._tabsList).elementFromPoint(e,t);return!!n&&this._tabsList.contains(n)}resolveTabDrop(e){let t=e.currentInsertionIndex;if(t===null)return null;let{sourceIndex:n,targetTabGroupId:r}=e,i=t-+(n!==-1&&n<t);return i===n&&r===(this.group.model.getTabGroupForPanel(e.sourceTabId)?.id??null)?null:{index:i,targetTabGroupId:r}}commitPointerReorder(e){let t=this._animState;if(t?.currentInsertionIndex==null)return;let n=this.resolveTabDrop(t);this._animState=null,this.clearWrapDropIndicator(),this.uncollapseSourceTab(t.sourceTabId),n&&this.host.fireDrop($({event:e},n))}processDragOver(e,t){if(this.accessor.options.disableDnd||(this._dropStaleAnimState(),!this._animState&&!this._initAnimStateForExternalDrag()))return!1;if(this._animState.sourceIndex!==-1){var n;(n=this.group.model.dropTargetContainer)==null||(n=n.model)==null||n.clear()}return this.handleDragOver({clientX:e,clientY:t}),!0}_dropStaleAnimState(){if(!this._animState)return;let e=fW();e?.tabGroupId&&e.groupId!==this.group.id&&this._animState.sourceTabGroupId!==e.tabGroupId&&(this._animState=null)}_initAnimStateForExternalDrag(){let e=fW();if(this.accessor.options.theme?.tabAnimation==="default"&&!e?.tabGroupId||!e||!(e.panelId||e.tabGroupId)||e.groupId===this.group.id)return!1;let t=this.getAverageTabSize();return this._animState=e.tabGroupId?this._makeGroupDragAnimState(e,t):this._makeTabDragAnimState(e,t),!0}_makeGroupDragAnimState(e,t){let n=this.accessor.getPanel(e.groupId)?.model.getTabGroups().find(t=>t.id===e.tabGroupId),r=t*(n?.panelIds.length??1)+t;return{sourceTabId:``,sourceIndex:-1,tabPositions:this.snapshotTabPositions(),chipSizes:this._tabGroupManager.snapshotChipSizes(),currentInsertionIndex:null,targetTabGroupId:null,sourceTabGroupId:e.tabGroupId,sourceGroupPanelIds:n?new Set(n.panelIds):new Set,sourceChipSize:t,cursorOffsetFromDragStart:r/2,sourceGapSize:r,containerStart:this._mainAxisStart(this._tabsList.getBoundingClientRect())}}_makeTabDragAnimState(e,t){return{sourceTabId:e.panelId,sourceIndex:-1,tabPositions:this.snapshotTabPositions(),chipSizes:this._tabGroupManager.snapshotChipSizes(),currentInsertionIndex:null,targetTabGroupId:null,sourceTabGroupId:null,sourceGroupPanelIds:null,sourceChipSize:0,cursorOffsetFromDragStart:t/2,sourceGapSize:t,containerStart:this._mainAxisStart(this._tabsList.getBoundingClientRect())}}processDragLeave(e){this._animState&&(e&&this._tabsList.contains(e)||(e&&this._extendedDropZone?.contains(e)?(this.resetTabTransforms(),this._animState.currentInsertionIndex=null):this._voidContainer&&e&&(e===this._voidContainer||this._voidContainer.contains(e))||(this.resetTabTransforms(),this._animState.sourceIndex===-1?(this.clearHeaderAnchorOverlay(),this._animState=null):this._animState.currentInsertionIndex=null)))}clearHeaderAnchorOverlay(){var e;let t=this.group.model.dropTargetContainer,n=t?.renderedOutline;n&&![this._tabsList,this._voidContainer,this._extendedDropZone].some(e=>e?.contains(n))||t==null||(e=t.model)==null||e.clear()}handleDragOver(e){if(!this._animState)return;if(this._wrapMode&&!this._animState.sourceTabGroupId){this.handleWrappedDragOver(e.clientX,e.clientY??0);return}let t=this._mainAxisCoord(e.clientX,e.clientY??0),n=this._buildFirstPanelToGroupMap(),r=this._computeDragOverInsertionIndex(t,n),i=null;if(r!==null&&this._tabGroupManager.chipRenderers.size>0){let e=this._resolveInsertionAgainstTabGroups(t,r,n);r=e.insertionIndex,i=e.targetTabGroupId}(r!==this._animState.currentInsertionIndex||i!==this._animState.targetTabGroupId)&&(this._animState.currentInsertionIndex=r,this._animState.targetTabGroupId=i,this.accessor.options.theme?.tabAnimation===`smooth`&&this.applyDragOverTransforms())}_buildFirstPanelToGroupMap(){let e=new Map;if(this._tabGroupManager.chipRenderers.size===0)return e;for(let t of this.group.model.getTabGroups())t.id!==this._animState.sourceTabGroupId&&t.panelIds.length>0&&e.set(t.panelIds[0],t.id);return e}_computeDragOverInsertionIndex(e,t){let n=this._animState,r=n.sourceGroupPanelIds,i=e-n.cursorOffsetFromDragStart-n.containerStart,a=0,o=null;for(let e=0;e<this._tabs.length;e++){let s=this._tabs[e].value;if(s.panel.id===n.sourceTabId||r?.has(s.panel.id))continue;let c=t.get(s.panel.id);if(c){let t=n.chipSizes.get(c)??0;if(a+t>i){o??=e;break}a+=t}let l=n.tabPositions.get(s.panel.id),u=this._mainAxisSize(l??s.element.getBoundingClientRect());if(a+u/2<=i)a+=u,o=e+1;else{o??=e;break}}return o}_accumulatedSizeUpTo(e,t){let n=this._animState,r=n.sourceGroupPanelIds,i=0;for(let a=0;a<this._tabs.length;a++){let o=this._tabs[a].value;if(o.panel.id===n.sourceTabId||r?.has(o.panel.id))continue;if(a>=e)break;let s=t.get(o.panel.id);s&&(i+=n.chipSizes.get(s)??0);let c=n.tabPositions.get(o.panel.id);i+=this._mainAxisSize(c??o.element.getBoundingClientRect())}return i}_resolveInsertionAgainstTabGroups(e,t,n){let r=!!this._animState.sourceTabGroupId,i=this._accumulatedSizeUpTo(t,n);for(let n of this.group.model.getTabGroups()){let a=this._evaluateTabGroupForInsertion(n,e,t,i,r);if(a)return a.targetTabGroupId?a:this._keepSourceGroupAtOwnSlot(e,a.insertionIndex,i)??a}return this._keepSourceGroupAtOwnSlot(e,t,i)??{insertionIndex:t,targetTabGroupId:null}}_keepSourceGroupAtOwnSlot(e,t,n){let r=this._animState,i=r.sourceIndex;if(r.sourceGroupPanelIds||i===-1||t!==i&&t!==i+1)return null;let a=this.group.model.getTabGroups().find(e=>e.panelIds.includes(r.sourceTabId));if(!a)return null;if(a.panelIds[0]===r.sourceTabId){let t=r.chipSizes.get(a.id)??0;if(e<r.containerStart+n+t)return null}return{insertionIndex:t,targetTabGroupId:a.id}}_evaluateTabGroupForInsertion(e,t,n,r,i){let a=this._resolveGroupRange(e);if(!a)return null;let{firstIdx:o,lastIdx:s}=a,c=n>=o&&n<=s,l=!c&&n===o-1;return!c&&!l?null:i?this._resolveGroupDragTarget(n,o,s,c):this._resolveTabDragTarget(e,t,n,r,o,l)}_resolveGroupRange(e){let t=this._animState,n=t.sourceGroupPanelIds,r=e.panelIds.filter(e=>e!==t.sourceTabId&&!n?.has(e));if(r.length===0)return null;let i=this._tabs.findIndex(e=>e.value.panel.id===r[0]),a=this._tabs.findIndex(e=>e.value.panel.id===r[r.length-1]);return i===-1||a===-1?null:{firstIdx:i,lastIdx:a}}_resolveGroupDragTarget(e,t,n,r){return r?{insertionIndex:e<(t+n+1)/2?t:n+1,targetTabGroupId:null}:{insertionIndex:e,targetTabGroupId:null}}_resolveTabDragTarget(e,t,n,r,i,a){let o=this._animState,s=o.chipSizes.get(e.id)??0;if(a)return this._onlySourceBetween(n,i)?t>=(e.collapsed?o.containerStart+r+s/2:o.containerStart+r+s)?{insertionIndex:i,targetTabGroupId:e.id}:{insertionIndex:n,targetTabGroupId:null}:null;let c=o.containerStart+r+s;return n===i?{insertionIndex:n,targetTabGroupId:t>=c?e.id:null}:{insertionIndex:n,targetTabGroupId:e.id}}_onlySourceBetween(e,t){let n=this._animState;for(let r=e;r<t;r++){let e=this._tabs[r].value.panel.id;if(e!==n.sourceTabId&&!n.sourceGroupPanelIds?.has(e))return!1}return!0}handleWrappedDragOver(e,t){if(!this._animState)return;let n=this.computeWrappedInsertionIndex(e,t);(n!==this._animState.currentInsertionIndex||this._animState.targetTabGroupId!==null)&&(this._animState.currentInsertionIndex=n,this._animState.targetTabGroupId=null,this.updateWrapDropIndicator(n))}computeWrappedInsertionIndex(e,t){let n=this._direction===`vertical`,r=this._wrappedDragEntries();if(r.length===0)return this._tabs.length;let i=n?e:t,a=n?t:e,o=e=>n?e.left:e.top,s=e=>n?e.right:e.bottom,c=e=>n?e.top:e.left,l=e=>n?e.height:e.width,u=this._bucketWrappedLines(r,o,s),d=[...(u.find(e=>i>=e.start&&i<=e.end)??this._nearestWrappedLine(u,i)).items].sort((e,t)=>c(e.rect)-c(t.rect));for(let e of d)if(a<c(e.rect)+l(e.rect)/2)return e.index;return d[d.length-1].index+1}_wrappedDragEntries(){let e=this._animState?.sourceTabId,t=this._animState?.sourceGroupPanelIds,n=[];for(let r=0;r<this._tabs.length;r++){let i=this._tabs[r].value;i.panel.id!==e&&(t?.has(i.panel.id)||n.push({index:r,rect:i.element.getBoundingClientRect()}))}return n}_bucketWrappedLines(e,t,n){let r=[];for(let i of e){let e=t(i.rect),a=r.find(t=>Math.abs(t.start-e)<=2);a?(a.items.push(i),a.end=Math.max(a.end,n(i.rect))):r.push({start:e,end:n(i.rect),items:[i]})}return r.sort((e,t)=>e.start-t.start),r}_nearestWrappedLine(e,t){let n=e=>t<e.start?e.start-t:t-e.end;return e.reduce((e,t)=>n(t)<n(e)?t:e,e[0])}updateWrapDropIndicator(e){this.clearWrapDropIndicator();let t=this._tabs.length;if(t===0)return;let n=this._animState?.sourceTabId;if(e<t){let t=this._tabs[e].value.element;if(this._tabs[e].value.panel.id===n)return;t.classList.add(`dv-tab--reorder-before`),this._wrapIndicatorEl=t}else{let e=this._tabs[t-1].value.element;e.classList.add(`dv-tab--reorder-after`),this._wrapIndicatorEl=e}}clearWrapDropIndicator(){var e;(e=this._wrapIndicatorEl)==null||e.classList.remove(`dv-tab--reorder-before`,`dv-tab--reorder-after`),this._wrapIndicatorEl=null}_removeClassInstantlyBatch(e,t){let n=[];for(let r of e)r.classList.contains(t)&&(r.style.transition=`none`,Q(r,t,!1),n.push(r));if(n.length>0){n[0].getBoundingClientRect();for(let e of n)e.style.removeProperty(`transition`)}}uncollapseSourceTab(e){let t=this._tabMap.get(e);t&&this._removeClassInstantlyBatch([t.value.element],`dv-tab--dragging`)}applyDragOverTransforms(e=!1){if(this._wrapMode)return;if(this._animState?.currentInsertionIndex==null){this.resetTabTransforms();return}if(this._pendingCollapse)return;let t=this._animState.currentInsertionIndex,n=this._computeGapSize(),r=this._computeChipToShift(t);this._applyGapMargins(t,n,r,e)}_computeGapSize(){let e=this._animState;if(e.sourceTabGroupId&&e.sourceGroupPanelIds)return e.sourceGapSize;let t=e.tabPositions.get(e.sourceTabId);return t?this._mainAxisSize(t):this.getAverageTabSize()}_computeChipToShift(e){if(this._tabGroupManager.chipRenderers.size===0)return null;for(let t of this.group.model.getTabGroups()){let n=this._chipToShiftForGroup(t,e);if(n!==void 0)return n}return null}_chipToShiftForGroup(e,t){let n=this._animState;if(e.id===n.sourceTabGroupId||e.panelIds.includes(n.sourceTabId))return;let r=e.panelIds.filter(e=>e!==n.sourceTabId&&!n.sourceGroupPanelIds?.has(e));if(r.length===0)return;let i=this._tabs.findIndex(e=>e.value.panel.id===r[0]);if((!n.targetTabGroupId||n.targetTabGroupId===e.id&&e.collapsed)&&!(i<t)){if(this._onlySourceBetween(t,i)){let t=this._tabGroupManager.chipRenderers.get(e.id);if(t)return t.chip.element}return null}}_applyGapMargins(e,t,n,r){let i=this._animState,a=i.sourceGroupPanelIds,o=!1;for(let[e,t]of this._tabGroupManager.chipRenderers)e!==i.sourceTabGroupId&&this._clearMargin(t.chip.element,r);n&&(this._setMargin(n,`${t}px`,r),o=!0);for(let n=0;n<this._tabs.length;n++){let s=this._tabs[n].value;s.panel.id!==i.sourceTabId&&(a?.has(s.panel.id)||(!o&&n>=e?(this._setMargin(s.element,`${t}px`,r),o=!0):this._clearMargin(s.element,r)))}this._tabGroupManager.trackUnderlines()}_shiftingClass(e){return e.classList.contains(`dv-tab-group-chip`)?`dv-tab-group-chip--shifting`:`dv-tab--shifting`}_setMargin(e,t,n){let r=this._gapMarginProperty;n?(e.style.transition=`none`,e.style.setProperty(r,t),e.getBoundingClientRect(),e.style.removeProperty(`transition`)):e.style.setProperty(r,t),Q(e,this._shiftingClass(e),!0)}_clearMargin(e,t){let n=this._shiftingClass(e),r=this._gapMarginProperty,i=this._pendingMarginCleanups.get(e);if(i&&i(),t||!e.style.getPropertyValue(r))e.style.removeProperty(r),Q(e,n,!1);else{e.style.setProperty(r,`0px`),Q(e,n,!0);let t=()=>{e.style.removeProperty(r),Q(e,n,!1),e.removeEventListener(`transitionend`,t),clearTimeout(i),this._pendingMarginCleanups.delete(e)},i=setTimeout(t,300);this._pendingMarginCleanups.set(e,t),e.addEventListener(`transitionend`,t)}}resetTabTransforms(){this.clearWrapDropIndicator();for(let[,e]of this._pendingMarginCleanups)e();this._pendingMarginCleanups.clear();for(let e of this._tabs)e.value.element.style.removeProperty(`margin-left`),e.value.element.style.removeProperty(`margin-right`),e.value.element.style.removeProperty(`margin-top`),e.value.element.style.removeProperty(`margin-bottom`),e.value.element.style.removeProperty(`transform`),Q(e.value.element,`dv-tab--shifting`,!1);for(let[,e]of this._tabGroupManager.chipRenderers)e.chip.element.style.removeProperty(`margin-left`),e.chip.element.style.removeProperty(`margin-top`),Q(e.chip.element,`dv-tab-group-chip--shifting`,!1);this._tabGroupManager.positionUnderlines()}commitGroupMove(e,t){let n=fW();if(this._tabGroupManager.disposeChipDrag(e),this._tabGroupManager.clearChipDropOverlays(),this.group.model.getTabGroups().some(t=>t.id===e)){if(this.accessor.options.theme?.tabAnimation===`smooth`){this._clearGroupDragClasses(e);let n=this.snapshotTabPositions();this.resetTabTransforms(),this.group.model.moveTabGroup(e,t),this.runFlipAnimation(n,``,!1)}else this._tabGroupManager.skipNextCollapseAnimation=!0,this.group.model.moveTabGroup(e,t)}else n&&(this.resetTabTransforms(),this.accessor.moveGroupOrPanel({from:{groupId:n.groupId,tabGroupId:n.tabGroupId??e},to:{group:this.group,position:`center`,index:t}}))}_clearGroupDragClasses(e){let t=this._tabGroupManager.chipRenderers.get(e);t&&this._removeClassInstantlyBatch([t.chip.element],`dv-tab-group-chip--dragging`),this._removeClassInstantlyBatch(this._tabs.map(e=>e.value.element),`dv-tab--dragging`);let n=this._tabGroupManager.groupUnderlines.get(e);n&&n.style.removeProperty(`display`),this._tabGroupManager.skipNextCollapseAnimation=!0}resetDragAnimation(){if(this._pendingCollapse=!1,this._animState){this.resetTabTransforms(),this._animState.sourceTabGroupId?this._clearGroupDragClasses(this._animState.sourceTabGroupId):this._removeClassInstantlyBatch(this._tabs.map(e=>e.value.element),`dv-tab--dragging`),this._animState=null;for(let[,e]of this._tabGroupManager.groupUnderlines)e.style.removeProperty(`display`)}}runFlipAnimation(e,t,n=!1,r){if(this._wrapMode)return;let i=!1;for(let a=0;a<this._tabs.length;a++)this._applyFlipTransform(this._tabs[a],a,t,n,e,r)&&(i=!0);i&&this._scheduleFlipReset()}_applyFlipTransform(e,t,n,r,i,a){let o=this._direction===`vertical`,s=e.value.panel.id;if(s===n){if(!r)return!1;let t=e.value.element.getBoundingClientRect();return e.value.element.style.transform=o?`translateY(${t.height}px)`:`translateX(${t.width}px)`,Q(e.value.element,`dv-tab--shifting`,!0),!0}if(a!==void 0&&(t<a.from||t>a.to))return!1;let c=i.get(s);if(!c)return!1;let l=e.value.element.getBoundingClientRect(),u=o?c.top-l.top:c.left-l.left;return Math.abs(u)<1?!1:(e.value.element.style.transform=o?`translateY(${u}px)`:`translateX(${u}px)`,Q(e.value.element,`dv-tab--shifting`,!0),!0)}_scheduleFlipReset(){requestAnimationFrame(()=>{var e;for(let e of this._tabs)e.value.element.style.transform&&(e.value.element.style.transform=``);this._tabGroupManager.trackUnderlines(),(e=this._flipTransitionCleanup)==null||e.call(this);let t=e=>{if(e.propertyName===`transform`){n();for(let e of this._tabs)Q(e.value.element,`dv-tab--shifting`,!1);this._tabGroupManager.positionUnderlines()}},n=()=>{this._tabsList.removeEventListener(`transitionend`,t),this._flipTransitionCleanup=null};this._flipTransitionCleanup=n,this._tabsList.addEventListener(`transitionend`,t)})}},Iq=class extends Y{get _animState(){return this._reorder.animState}set _animState(e){this._reorder.animState=e}get _pendingCollapse(){return this._reorder.pendingCollapse}set _pendingCollapse(e){this._reorder.pendingCollapse=e}get tabItems(){return this._tabs}get tabMap(){return this._tabMap}get tabsList(){return this._tabsList}get groupPanel(){return this.group}get component(){return this.accessor}get tabGroupManager(){return this._tabGroupManager}fireDrop(e){this._onDrop.fire(e)}setOverflowExclude(e){this._overflowExclude=e,this.refreshOverflow()}setForcedOverflow(e){this._forcedOverflow=e,this.refreshOverflow()}refreshOverflow(){this._showTabsOverflowControl&&this.toggleDropdown({reset:!1}),this._applyPinnedSticky()}setPinnedSticky(e){this._pinnedSticky!==e&&(this._pinnedSticky=e,this._applyPinnedSticky())}_applyPinnedSticky(){let e=this._pinnedSticky?this._tabs.filter(e=>this._overflowExclude(e.value.panel.id)):[];if(e.length===0&&!this._hasPinnedStickyStyling)return;for(let e of this._tabs){let t=e.value.element;t.classList.contains(`dv-tab--pinned-sticky`)&&(t.classList.remove(`dv-tab--pinned-sticky`),t.style.removeProperty(`--dv-pinned-sticky-left`))}if(e.length===0){this._hasPinnedStickyStyling=!1;return}let t=e.map(e=>e.value.element.offsetLeft);e.forEach((e,n)=>{let r=e.value.element;r.classList.add(`dv-tab--pinned-sticky`),r.style.setProperty(`--dv-pinned-sticky-left`,`${t[n]}px`)}),this._hasPinnedStickyStyling=!0}get showTabsOverflowControl(){return this._showTabsOverflowControl}set showTabsOverflowControl(e){if(this._showTabsOverflowControl!=e){if(this._showTabsOverflowControl=e,e){let e=new CW(this._tabsList);this._observerDisposable.value=new Y(e,e.onDidChange(e=>{let t=e.hasScrollX||e.hasScrollY;this.toggleDropdown({reset:!t}),this._applyPinnedSticky(),this._tabGroupManager.groupUnderlines.size>0&&this._tabGroupManager.positionUnderlines()}),Z(this._tabsList,`scroll`,()=>{this.toggleDropdown({reset:!1}),this._applyPinnedSticky(),this._tabGroupManager.groupUnderlines.size>0&&this._tabGroupManager.positionUnderlines()}))}else this._observerDisposable.value=mW.NONE}}get element(){return this._element}get tabsListElement(){return this._tabsList}set voidContainer(e){var t;(t=this._voidContainerListeners)==null||t.dispose(),this._voidContainerListeners=null,this._reorder.voidContainerElement=e,e&&(this._voidContainerListeners=new Y(Z(e,`dragover`,e=>{this._animState&&e.preventDefault()}),Z(e,`drop`,e=>{this._animState?.sourceTabGroupId&&this._animState.currentInsertionIndex!==null&&(e.preventDefault(),e.stopPropagation(),this.handleVoidDrop())})))}handleVoidDrop(){if(!this._animState?.sourceTabGroupId)return!1;let e=this._animState.sourceTabGroupId,t=this._animState.currentInsertionIndex??this._tabs.length;return this._animState=null,this._commitGroupMove(e,t),!0}get panels(){return this._tabs.map(e=>e.value.panel.id)}get size(){return this._tabs.length}get tabs(){return this._tabs.map(e=>e.value)}get direction(){return this._direction}set direction(e){if(this._direction!==e){this._direction=e,this._tabsList.setAttribute(`aria-orientation`,e===`vertical`?`vertical`:`horizontal`),this._scrollbar&&(this._scrollbar.orientation=e),TW(this._tabsList,`dv-horizontal`,`dv-vertical`),e===`vertical`?EW(this._tabsList,`dv-tabs-container-vertical`,`dv-vertical`):(TW(this._tabsList,`dv-tabs-container-vertical`),EW(this._tabsList,`dv-horizontal`));for(let t of this._tabs)t.value.setDirection(e);this._tabGroupManager.updateDirection()}}constructor(e,t,n){super(),this.group=e,this.accessor=t,this._observerDisposable=new hW,this._pointerActivation=new hW,this._scrollbar=null,this._tabs=[],this._overflowRefreshPending=!1,this._tabMap=new Map,this.selectedIndex=-1,this._showTabsOverflowControl=!1,this._overflowExclude=()=>!1,this._forcedOverflow=()=>!1,this._pinnedSticky=!1,this._hasPinnedStickyStyling=!1,this._direction=`horizontal`,this._voidContainerListeners=null,this._onTabDragStart=new X,this.onTabDragStart=this._onTabDragStart.event,this._onDrop=new X,this.onDrop=this._onDrop.event,this._onWillShowOverlay=new X,this.onWillShowOverlay=this._onWillShowOverlay.event,this._onOverflowTabsChange=new X,this.onOverflowTabsChange=this._onOverflowTabsChange.event,this._tabsList=document.createElement(`div`),this._tabsList.className=`dv-tabs-container`,this._tabsList.setAttribute(`role`,`tablist`),this._tabsList.setAttribute(`aria-orientation`,this._direction===`vertical`?`vertical`:`horizontal`),this.showTabsOverflowControl=n.showTabsOverflowControl,t.options.scrollbars===`native`?this._element=this._tabsList:(this._scrollbar=new cq(this._tabsList),this._scrollbar.orientation=this.direction,this._element=this._scrollbar.element,this.addDisposables(this._scrollbar)),this._tabGroupManager=new jq({group:this.group,accessor:this.accessor,tabsList:this._tabsList,getTabs:()=>this._tabs,getTabMap:()=>this._tabMap,getDirection:()=>this._direction},{onChipContextMenu:(e,t)=>{var n;(n=this.accessor.contextMenuService)==null||n.showForChip(e,this.group,t)},onChipDragStart:(e,t,n)=>{this._handleChipDragStart(e,t,n)},onChipDragEnd:()=>{this._reorder.resetDragAnimation()},onChipDrop:(e,t)=>{this._handleChipDrop(e,t)}}),this._reorder=new Fq(this);let r=NK.createDropTarget(this._tabsList,{acceptedTargetZones:[`center`],canDisplayOverlay:()=>!1,isHitTestTransparent:()=>{let e=fW();return e?.viewId!==this.accessor.id||e.groupId!==this.group.id||e.panelId===null&&!e.tabGroupId}});this.addDisposables(r,this._onOverflowTabsChange,this._observerDisposable,this._pointerActivation,this._onWillShowOverlay,this._onDrop,this._onTabDragStart,this._reorder,xK.getInstance().onDragEnd(e=>{this._reorder.handlePointerDragEnd(e)}),xK.getInstance().onDragMove(e=>{this._reorder.handlePointerDragMove(e.clientX,e.clientY)}),Z(this.element,`pointerdown`,e=>{e.defaultPrevented||e.button===0&&this.accessor.doSetGroupActive(this.group)}),Z(this._tabsList,`wheel`,e=>{let t=this._direction===`vertical`,n=t?e.deltaY||e.deltaX:e.deltaX||e.deltaY;if(n===0)return;let r=t?this._tabsList.scrollHeight-this._tabsList.clientHeight:this._tabsList.scrollWidth-this._tabsList.clientWidth;if(r<=0)return;let i=t?this._tabsList.scrollTop:this._tabsList.scrollLeft;n<0&&i<=0||n>0&&i>=r||(e.preventDefault(),e.stopPropagation(),t?this._tabsList.scrollTop=i+n:this._tabsList.scrollLeft=i+n)},{passive:!1}),Z(this._tabsList,`keydown`,e=>{this._onKeyDown(e)}),Z(this._tabsList,`dragover`,e=>{this._reorder.processDragOver(e.clientX,e.clientY)&&e.preventDefault()},!0),Z(this._tabsList,`dragleave`,e=>{this._reorder.processDragLeave(e.relatedTarget)},!0),Z(this._tabsList,`dragend`,()=>{this._reorder.resetDragAnimation()}),Z(this._tabsList,`drop`,e=>{var t;if(this._animState?.currentInsertionIndex==null||this.accessor.options.theme?.tabAnimation!==`smooth`&&!this._animState.sourceTabGroupId)return;e.stopPropagation(),e.preventDefault(),(t=this.group.model.dropTargetContainer)==null||(t=t.model)==null||t.clear();let n=this._animState;if(this._animState=null,this._pendingCollapse=!1,n.sourceTabGroupId){this._commitGroupMove(n.sourceTabGroupId,n.currentInsertionIndex);return}let r=this._reorder.resolveTabDrop(n);if(this._reorder.uncollapseSourceTab(n.sourceTabId),!r){this.resetTabTransforms();return}let i=n.sourceIndex,a=this.snapshotTabPositions();this.resetTabTransforms(),this._onDrop.fire($({event:e},r)),this.runFlipAnimation(a,n.sourceTabId,i===-1,{from:Math.min(i,r.index),to:Math.max(i,r.index)})},!0),mW.from(()=>{var e;(e=this._voidContainerListeners)==null||e.dispose(),this._reorder.resetDragAnimation(),this._tabGroupManager.disposeAll();for(let{value:e,disposable:t}of this._tabs)t.dispose(),e.dispose();this._tabs=[],this._tabMap.clear()}))}indexOf(e){return this._tabs.findIndex(t=>t.value.panel.id===e)}getTabId(e){return this._tabMap.get(e)?.value.element.id}getPanelForTab(e){for(let{value:t}of this._tabs)if(t.element===e||t.element.contains(e))return t.panel}isActive(e){return this.selectedIndex>-1&&this._tabs[this.selectedIndex].value===e}_onKeyDown(e){let t=this._tabs.findIndex(t=>t.value.element===e.target);if(t===-1)return;let n=this._direction===`vertical`,r=n?`ArrowDown`:`ArrowRight`,i=n?`ArrowUp`:`ArrowLeft`,a=this._tabs.length-1;switch(e.key){case r:e.preventDefault(),this._focusTab(Math.min(t+1,a));break;case i:e.preventDefault(),this._focusTab(Math.max(t-1,0));break;case`Home`:e.preventDefault(),this._focusTab(0);break;case`End`:e.preventDefault(),this._focusTab(a);break;case`Enter`:case` `:e.preventDefault(),this.accessor.withOrigin(`user`,()=>this._tabs[t].value.panel.api.setActive());break;case`Delete`:case`Backspace`:e.preventDefault(),this._closeTab(t)}}_closeTab(e){let t=this._tabs[e]?.value;if(!t)return;let n=(this._tabs[e+1]?.value??this._tabs[e-1]?.value)?.panel.id;if(t.panel.api.close(),n!==void 0){let e=this._tabs.findIndex(e=>e.value.panel.id===n);e>-1&&this._focusTab(e)}}_focusTab(e){for(let t=0;t<this._tabs.length;t++)this._tabs[t].value.element.tabIndex=t===e?0:-1;this._tabs[e].value.element.focus()}focusActiveTab(){if(this._tabs.length===0)return;let e=this.group.activePanel?.id,t=e?this._tabs.findIndex(t=>t.value.panel.id===e):-1;this._focusTab(t>-1?t:0)}setActivePanel(e){let t=this._direction===`vertical`;for(let n of this._tabs){let r=e.id===n.value.panel.id;n.value.setActive(r),r&&this._scrollTabIntoView(n.value.element,t)}this._tabGroupManager.groupUnderlines.size>0&&this._tabGroupManager.positionUnderlines()}_scrollTabIntoView(e,t){let n=e.parentElement;if(!n)return;let r=t?e.offsetTop:e.offsetLeft,i=t?e.offsetHeight:e.offsetWidth,a=t?n.scrollTop:n.scrollLeft,o=t?n.clientHeight:n.clientWidth;(r<a||r+i>a+o)&&(t?n.scrollTop=r:n.scrollLeft=r)}_activateOnPointerDown(e){if(!eq(this.accessor.options).html5){this.group.model.openPanel(e);return}let t=requestAnimationFrame(()=>{this._tabMap.has(e.id)&&this.group.model.openPanel(e)});this._pointerActivation.value={dispose:()=>cancelAnimationFrame(t)}}openPanel(e,t=this._tabs.length){if(this._tabMap.has(e.id))return;let n=new iq(e,this.accessor,this.group);n.setContent(e.view.tab),this._direction!==`horizontal`&&n.setDirection(this._direction);let r={value:n,disposable:new Y(n.onDragStart(t=>{let r=t.defaultPrevented;if(this._onTabDragStart.fire({nativeEvent:t,panel:e}),(!t.defaultPrevented||r)&&this.accessor.options.theme?.tabAnimation===`smooth`){let t=Mq(n.element.getBoundingClientRect(),this._direction),r=this._tabs.findIndex(e=>e.value===n);this._animState={sourceTabId:e.id,sourceIndex:r,tabPositions:this.snapshotTabPositions(),chipSizes:this._tabGroupManager.snapshotChipSizes(),currentInsertionIndex:null,targetTabGroupId:null,sourceTabGroupId:null,sourceGroupPanelIds:null,sourceChipSize:0,cursorOffsetFromDragStart:t/2,sourceGapSize:t,containerStart:Nq(this._tabsList.getBoundingClientRect(),this._direction)},this._pendingCollapse=!0,requestAnimationFrame(()=>{var e;this._pendingCollapse=!1,this._animState&&(this._tabsList.classList.contains(`dv-tabs-container--wrap`)||(n.element.style.transition=`none`,Q(n.element,`dv-tab--dragging`,!0),n.element.offsetHeight),(e=this._animState).currentInsertionIndex??(e.currentInsertionIndex=r),this.applyDragOverTransforms(!0),n.element.style.removeProperty(`transition`))})}}),n.onTabClick(t=>{t.defaultPrevented||this.group.api.location.type===`edge`&&(this.group.activePanel===e?this.group.api.isCollapsed()?this.group.api.expand():this.group.api.collapse():(this.group.model.openPanel(e),this.group.api.isCollapsed()&&this.group.api.expand()))}),n.onPointerDown(t=>{if(t.defaultPrevented)return;let r=!this.accessor.options.disableFloatingGroups,i=this.group.api.location.type===`floating`&&this.size===1;if(r&&!i&&t.shiftKey){t.preventDefault();let e=this.accessor.getGroupPanel(n.panel.id),{top:r,left:i}=n.element.getBoundingClientRect(),{top:a,left:o}=this.accessor.element.getBoundingClientRect();this.accessor.addFloatingGroup(e,{x:i-o,y:r-a,inDragMode:!0})}else t.button===0&&this.group.api.location.type!==`edge`&&this.group.activePanel!==e&&this._activateOnPointerDown(e)}),n.onDrop(e=>{let t=this._animState;this._animState=null,this._pendingCollapse=!1;let r=this._tabs.findIndex(e=>e.value===n);if(t){let n=e.position===`right`?r+1:r;if(t.sourceTabGroupId){this._commitGroupMove(t.sourceTabGroupId,t.currentInsertionIndex??n);return}this._reorder.uncollapseSourceTab(t.sourceTabId);let i=this.snapshotTabPositions();this.resetTabTransforms(),this._onDrop.fire({event:e.nativeEvent,index:n,targetTabGroupId:t.targetTabGroupId}),this.accessor.options.theme?.tabAnimation===`smooth`&&this.runFlipAnimation(i,t.sourceTabId,t.sourceIndex===-1,t.sourceIndex===-1?void 0:{from:Math.min(t.sourceIndex,n),to:Math.max(t.sourceIndex,n)})}else{let t=this._direction===`vertical`?`bottom`:`right`,i=e.position===t?r+1:r,a=fW(),o=a?this._tabs.findIndex(e=>e.value.panel.id===a.panelId):-1,s=i-+(o!==-1&&o<i),c=this.group.model.getTabGroupForPanel(n.panel.id)?.id??null;this._onDrop.fire({event:e.nativeEvent,index:s,targetTabGroupId:c})}}),n.onWillShowOverlay(e=>{this._onWillShowOverlay.fire(new aq(e,{kind:`tab`,panel:this.group.activePanel,api:this.accessor.api,group:this.group,getData:fW}))}))};this.addTab(r,t),this._scheduleOverflowRefresh(),this._tabGroupManager.positionAllChips(),this._animState&&(this._animState.tabPositions=this.snapshotTabPositions(),this._animState.chipSizes=this._tabGroupManager.snapshotChipSizes(),this.applyDragOverTransforms())}delete(e){let t=this.indexOf(e);if(t===-1)return;this._animState?.sourceTabId===e&&(this.resetTabTransforms(),this._animState=null),this._tabGroupManager.cleanupTransition(e);let{value:n,disposable:r}=this._tabs.splice(t,1)[0];this._tabMap.delete(e),r.dispose(),n.dispose(),n.element.remove(),this._scheduleOverflowRefresh(),this._animState&&(this._animState.tabPositions=this.snapshotTabPositions(),this._animState.chipSizes=this._tabGroupManager.snapshotChipSizes(),this.applyDragOverTransforms())}addTab(e,t=this._tabs.length){if(t<0||t>this._tabs.length)throw Error(`invalid location`);let n=t<this._tabs.length?this._tabs[t].value.element:null;this._tabsList.insertBefore(e.value.element,n),this._tabs=[...this._tabs.slice(0,t),e,...this._tabs.slice(t)],this._tabMap.set(e.value.panel.id,e),this.selectedIndex<0&&(this.selectedIndex=t)}_scheduleOverflowRefresh(){!this._overflowRefreshPending&&this._showTabsOverflowControl&&(this._overflowRefreshPending=!0,queueMicrotask(()=>{if(this._overflowRefreshPending=!1,this.isDisposed||!this._showTabsOverflowControl)return;let e=this._tabsList,t=e.scrollWidth>e.clientWidth||e.scrollHeight>e.clientHeight;this.toggleDropdown({reset:!t})}))}toggleDropdown(e){let t=this._tabs.some(e=>!this._overflowExclude(e.value.panel.id)&&this._forcedOverflow(e.value.panel.id));if(e.reset&&!t){this._onOverflowTabsChange.fire({tabs:[],tabGroups:[],pinnedTabs:[],reset:!0});return}let n=this._tabs.filter(t=>!this._overflowExclude(t.value.panel.id)&&(this._forcedOverflow(t.value.panel.id)||!e.reset&&!JW(t.value.element,this._tabsList))).map(e=>e.value.panel.id),r=e.reset?[]:this._tabs.filter(e=>this._overflowExclude(e.value.panel.id)&&e.value.element.getBoundingClientRect().width>0&&!JW(e.value.element,this._tabsList)).map(e=>e.value.panel.id),i=new Set(n),a=[];for(let e of this.group.model.getTabGroups()){let t=this._tabGroupManager.chipRenderers.get(e.id),r=t&&!JW(t.chip.element,this._tabsList),o=e.panelIds.length>0&&e.panelIds.every(e=>i.has(e));if((r||o)&&(a.push(e.id),e.collapsed))for(let t of e.panelIds)i.has(t)||(i.add(t),n.push(t))}this._onOverflowTabsChange.fire({tabs:n,tabGroups:a,pinnedTabs:r,reset:!1})}updateDragAndDropState(){for(let e of this._tabs)e.value.updateDragAndDropState();this._tabGroupManager.updateDragAndDropState()}updateTabGroups(){this._tabGroupManager.update()}refreshTabGroupAccent(){this._tabGroupManager.refreshAccents()}_handleChipDragStart(e,t,n){let r=e.panelIds[0],i=r?this._tabs.findIndex(e=>e.value.panel.id===r):-1,a=t.element.getBoundingClientRect(),o=Mq(a,this._direction);for(let t of e.panelIds){let e=this._tabMap.get(t);e&&(o+=Mq(e.value.element.getBoundingClientRect(),this._direction))}if(this._animState={sourceTabId:``,sourceIndex:i,tabPositions:this.snapshotTabPositions(),chipSizes:this._tabGroupManager.snapshotChipSizes(),currentInsertionIndex:null,targetTabGroupId:null,sourceTabGroupId:e.id,sourceGroupPanelIds:new Set(e.panelIds),sourceChipSize:Mq(a,this._direction),cursorOffsetFromDragStart:Pq(n,this._direction)-Nq(a,this._direction),sourceGapSize:o,containerStart:Nq(this._tabsList.getBoundingClientRect(),this._direction)},this.accessor.options.theme?.tabAnimation!==`smooth`)return;let s=new Set(e.panelIds);this._pendingCollapse=!0,requestAnimationFrame(()=>{var t;if(this._pendingCollapse=!1,!this._animState)return;for(let e of this._tabs)s.has(e.value.panel.id)&&(e.value.element.style.transition=`none`,Q(e.value.element,`dv-tab--dragging`,!0));let n=this._tabGroupManager.chipRenderers.get(e.id);n&&(n.chip.element.style.transition=`none`,Q(n.chip.element,`dv-tab-group-chip--dragging`,!0)),this._tabsList.offsetHeight;let r=this._tabGroupManager.groupUnderlines.get(e.id);r&&(r.style.display=`none`),(t=this._animState).currentInsertionIndex??(t.currentInsertionIndex=i),this.applyDragOverTransforms(!0);for(let e of this._tabs)s.has(e.value.panel.id)&&e.value.element.style.removeProperty(`transition`);n&&n.chip.element.style.removeProperty(`transition`)})}_handleChipDrop(e,t){let n=e.panelIds[0];if(!n)return;let r=this._tabs.findIndex(e=>e.value.panel.id===n);if(r===-1)return;let i=fW();if(i?.tabGroupId){let e=this._animState;this._animState=null,this._pendingCollapse=!1,this._commitGroupMove(i.tabGroupId,e?.currentInsertionIndex??r);return}let a=i?.groupId===this.group.id&&i?.panelId?this._tabs.findIndex(e=>e.value.panel.id===i.panelId):-1,o=r-+(a!==-1&&a<r);this._onDrop.fire({event:t.nativeEvent,index:o,targetTabGroupId:null})}setExtendedDropZone(e){this._reorder.setExtendedDropZone(e)}setExternalInsertionIndex(e){this._reorder.setExternalInsertionIndex(e)}clearExternalAnimState(){this._reorder.clearExternalAnimState()}snapshotTabPositions(){return this._reorder.snapshotTabPositions()}handleDragOver(e){this._reorder.handleDragOver(e)}applyDragOverTransforms(e=!1){this._reorder.applyDragOverTransforms(e)}resetTabTransforms(){this._reorder.resetTabTransforms()}_commitGroupMove(e,t){this._reorder.commitGroupMove(e,t)}runFlipAnimation(e,t,n=!1,r){this._reorder.runFlipAnimation(e,t,n,r)}};function Lq(){let e=document.createElement(`div`);e.className=`dv-tabs-overflow-dropdown-default`;let t=document.createElement(`span`);t.textContent=``;let n=XK();return e.appendChild(n),e.appendChild(t),{element:e,update:e=>{t.textContent=`${e.tabs}`}}}var Rq=class extends Y{get onTabDragStart(){return this.tabs.onTabDragStart}get panels(){return this.tabs.panels}get size(){return this.tabs.size}get hidden(){return this._hidden}set hidden(e){this._hidden=e,this.element.style.display=e?`none`:``}get direction(){return this._direction}set direction(e){this._direction=e,e===`vertical`?(EW(this._element,`dv-groupview-header-vertical`),EW(this.rightActionsContainer,`dv-right-actions-container-vertical`),this.tabs.direction=e):(TW(this._element,`dv-groupview-header-vertical`),TW(this.rightActionsContainer,`dv-right-actions-container-vertical`),this.tabs.direction=e)}get element(){return this._element}get tabsListElement(){return this.tabs.tabsListElement}constructor(e,t){super(),this.accessor=e,this.group=t,this._hidden=!1,this._direction=`horizontal`,this._dropIndexResolver=(e,t)=>t,this._pinnedRow=void 0,this.dropdownPart=null,this._overflowTabs=[],this._overflowTabGroups=[],this._overflowPinnedTabs=[],this._dropdownDisposable=new hW,this._onDrop=new X,this.onDrop=this._onDrop.event,this._onGroupDragStart=new X,this.onGroupDragStart=this._onGroupDragStart.event,this._onWillShowOverlay=new X,this.onWillShowOverlay=this._onWillShowOverlay.event,this._element=document.createElement(`div`),this._element.className=`dv-tabs-and-actions-container`,Q(this._element,`dv-full-width-single-tab`,this.accessor.options.singleTabMode===`fullwidth`),this.rightActionsContainer=document.createElement(`div`),this.rightActionsContainer.className=`dv-right-actions-container`,this.leftActionsContainer=document.createElement(`div`),this.leftActionsContainer.className=`dv-left-actions-container`,this.preActionsContainer=document.createElement(`div`),this.preActionsContainer.className=`dv-pre-actions-container`,this.tabs=new Iq(t,e,{showTabsOverflowControl:!e.options.disableTabsOverflowList}),this.voidContainer=new sq(this.accessor,this.group),this.tabs.voidContainer=this.voidContainer.element,this._element.appendChild(this.preActionsContainer),this._element.appendChild(this.tabs.element),this._element.appendChild(this.leftActionsContainer),this._element.appendChild(this.voidContainer.element),this._element.appendChild(this.rightActionsContainer),this.tabs.setExtendedDropZone(this._element),this.addDisposables(this.tabs.onDrop(e=>this._onDrop.fire(e)),this.tabs.onWillShowOverlay(e=>this._onWillShowOverlay.fire(e)),e.onDidOptionsChange(()=>{this.tabs.showTabsOverflowControl=!e.options.disableTabsOverflowList}),this.tabs.onOverflowTabsChange(e=>{this.toggleDropdown(e)}),this.tabs,this._onWillShowOverlay,this._onDrop,this._onGroupDragStart,this.voidContainer,this.voidContainer.onDragStart(e=>{this._onGroupDragStart.fire({nativeEvent:e,group:this.group})}),this.voidContainer.onDrop(e=>{this.tabs.handleVoidDrop()||this._onDrop.fire({event:e.nativeEvent,index:this.tabs.size})}),this.voidContainer.onWillShowOverlay(e=>{this._onWillShowOverlay.fire(new aq(e,{kind:`header_space`,panel:this.group.activePanel,api:this.accessor.api,group:this.group,getData:fW}))}),Z(this.leftActionsContainer,`dragleave`,e=>{let t=e.relatedTarget;!this.leftActionsContainer.contains(t)&&!this._element.contains(t)&&this.tabs.clearExternalAnimState()}),Z(this.voidContainer.element,`dragleave`,e=>{let t=e.relatedTarget;this.voidContainer.element.contains(t)||(this._element.contains(t)?this.tabs.setExternalInsertionIndex(null):this.tabs.clearExternalAnimState())}),Z(this.voidContainer.element,`pointerdown`,e=>{if(!e.defaultPrevented&&!this.accessor.options.disableFloatingGroups&&e.shiftKey&&this.group.api.location.type!==`floating`&&this.group.api.location.type!==`edge`){e.preventDefault();let{top:t,left:n}=this.element.getBoundingClientRect(),{top:r,left:i}=this.accessor.element.getBoundingClientRect();this.accessor.addFloatingGroup(this.group,{x:n-i+20,y:t-r+20,inDragMode:!0})}}))}show(){this.hidden||(this.element.style.display=``)}hide(){this._element.style.display=`none`}setRightActionsElement(e){this.rightActions!==e&&(this.rightActions&&=(this.rightActions.remove(),void 0),e&&(this.rightActionsContainer.appendChild(e),this.rightActions=e))}setLeftActionsElement(e){this.leftActions!==e&&(this.leftActions&&=(this.leftActions.remove(),void 0),e&&(this.leftActionsContainer.appendChild(e),this.leftActions=e))}setPrefixActionsElement(e){this.preActions!==e&&(this.preActions&&=(this.preActions.remove(),void 0),e&&(this.preActionsContainer.appendChild(e),this.preActions=e))}isActive(e){return this.tabs.isActive(e)}indexOf(e){return this.tabs.indexOf(e)}getTabId(e){return this.tabs.getTabId(e)}getPanelForTab(e){return this.tabs.getPanelForTab(e)}setActive(e){}delete(e){this.tabs.delete(e),this.updateClassnames()}setActivePanel(e){this.tabs.setActivePanel(e)}focusActiveTab(){this.tabs.focusActiveTab()}openPanel(e,t=this.tabs.size){this.tabs.openPanel(e,t),this.updateClassnames()}closePanel(e){this.delete(e.id)}setOverflowExclude(e){this.tabs.setOverflowExclude(e)}setForcedOverflow(e){this.tabs.setForcedOverflow(e)}setPinnedSticky(e){this.tabs.setPinnedSticky(e)}refreshOverflow(){this.tabs.refreshOverflow()}setPinnedRow(e){this._pinnedRow!==e&&(this._pinnedRow&&this._pinnedRow.remove(),this._pinnedRow=e,e&&(e.classList.add(`dv-pinned-row`),this._element.insertBefore(e,this._element.firstChild)),Q(this._element,`dv-tabs-and-actions-container--pinned-row`,!!e))}setDropIndexResolver(e){this._dropIndexResolver=e}resolveDropIndex(e,t){return this._dropIndexResolver(e,t)}updateClassnames(){Q(this._element,`dv-single-tab`,this.size===1)}toggleDropdown(e){let t=e.reset?[]:e.tabs,n=e.reset?[]:e.tabGroups,r=e.reset?[]:e.pinnedTabs;this._overflowTabs=t,this._overflowTabGroups=n,this._overflowPinnedTabs=r;let i=this._overflowTabs.length+this._overflowPinnedTabs.length;if(i>0&&this.dropdownPart){this.dropdownPart.update({tabs:i});return}if(i===0){this._dropdownDisposable.dispose();return}let a=document.createElement(`div`);a.className=`dv-tabs-overflow-dropdown-root`;let o=Lq();o.update({tabs:i}),this.dropdownPart=o,a.appendChild(o.element),this.rightActionsContainer.prepend(a),this._dropdownDisposable.value=new Y(mW.from(()=>{var e,t;a.remove(),(e=this.dropdownPart)==null||(t=e.dispose)==null||t.call(e),this.dropdownPart=null}),Z(a,`pointerdown`,e=>{e.preventDefault()},{capture:!0}),Z(a,`click`,e=>{let t=QW(a),n={x:e.clientX,y:e.clientY,zIndex:t?.style.zIndex?`calc(${t.style.zIndex} * 2)`:void 0},{context:r,rowRenderers:i}=this.createOverflowRenderContext(a,n),o=this.accessor.advancedOverflowService;try{o?o.renderOverflow({group:this.group,overflowTabs:[...this._overflowTabs],overflowTabGroups:[...this._overflowTabGroups],pinnedOverflowTabs:[...this._overflowPinnedTabs],context:r}):r.open(this.renderFreeOverflowList(r))}catch(e){throw i.dispose(),e}}))}createOverflowRenderContext(e,t){let n=new Set(this._overflowTabGroups),r=this.group.model.getTabGroups(),i=new Map,a=new Map;for(let e of r)if(a.set(e.id,e),n.has(e.id))for(let t of e.panelIds)i.set(t,e);let o=()=>this.accessor.getPopupServiceForGroup(this.group),s=new Y,c=e=>{let t=document.createElement(`div`);t.className=`dv-tabs-overflow-group-header`;let n=document.createElement(`span`);n.className=`dv-tabs-overflow-group-color`,Sq(n,e.color,this.accessor.tabGroupColorPalette),t.appendChild(n);let r=document.createElement(`span`);if(r.className=`dv-tabs-overflow-group-label`,r.textContent=e.label||e.id,t.appendChild(r),e.collapsed){let n=document.createElement(`span`);n.className=`dv-tabs-overflow-group-collapsed-badge`,n.textContent=`${e.panelIds.length}`,t.appendChild(n)}return t.addEventListener(`click`,()=>{o().close(),e.collapsed&&e.expand();let t=e.panelIds[0];if(t){let e=this.group.panels.find(e=>e.id===t);this.accessor.withOrigin(`user`,()=>e?.api.setActive())}}),t};return{context:{overflowGroupIdForPanel:e=>i.get(e)?.id,buildGroupHeader:e=>{let t=a.get(e);if(t&&n.has(t.id))return c(t)},buildPinnedHeader:()=>{let e=document.createElement(`div`);e.className=`dv-tabs-overflow-group-header dv-tabs-overflow-pinned-header`;let t=JK();t.classList.add(`dv-tabs-overflow-pinned-icon`),e.appendChild(t);let n=document.createElement(`span`);return n.className=`dv-tabs-overflow-group-label`,n.textContent=`Pinned`,e.appendChild(n),e},buildRow:e=>{let t=this.group.panels.find(t=>t.id===e);if(!t)return;let n=this.tabs.tabs.find(t=>t.panel.id===e),r=i.get(e),a=t.view.createTabRenderer(`headerOverflow`),c=!1,l=mW.from(()=>{if(!c){var e;c=!0,(e=a.dispose)==null||e.call(a)}});s.isDisposed?l.dispose():s.addDisposables(l);let u=a.element,d=document.createElement(`div`);Q(d,`dv-tab`,!0),Q(d,`dv-active-tab`,t.api.isActive),Q(d,`dv-inactive-tab`,!t.api.isActive),r&&Q(d,`dv-tab--grouped`,!0);let f=()=>{r?.collapsed&&r.expand(),n?.element.scrollIntoView({block:`nearest`,inline:`nearest`}),this.accessor.withOrigin(`user`,()=>t.api.setActive())};return d.addEventListener(`click`,e=>{o().close(),!e.defaultPrevented&&f()}),d.appendChild(u),{element:d,panel:t,activate:()=>{o().close(),f()},dispose:()=>{s.removeDisposable(l),l.dispose()}}},open:e=>{o().openPopover(e,t,{onClose:()=>s.dispose()})},close:()=>o().close(),focusTrigger:()=>{e.tabIndex=-1,e.focus()}},rowRenderers:s}}renderFreeOverflowList(e){let t=document.createElement(`div`);t.style.overflow=`auto`,t.className=`dv-tabs-overflow-container`;let n=this._overflowPinnedTabs.map(t=>e.buildRow(t)).filter(e=>e!=null);if(n.length>0){t.appendChild(e.buildPinnedHeader());for(let e of n)t.appendChild(e.element)}let r=new Set;for(let n of this.tabs.tabs.filter(e=>this._overflowTabs.includes(e.panel.id))){let i=e.overflowGroupIdForPanel(n.panel.id);if(i&&!r.has(i)){r.add(i);let n=e.buildGroupHeader(i);n&&t.appendChild(n)}let a=e.buildRow(n.panel.id);a&&t.appendChild(a.element)}return t}updateDragAndDropState(){this.tabs.updateDragAndDropState(),this.voidContainer.updateDragAndDropState()}updateTabGroups(){this.tabs.updateTabGroups()}refreshTabGroupAccent(){this.tabs.refreshTabGroupAccent()}},zq=class extends Y{get label(){return this._label}get color(){return this._color}get componentParams(){return this._componentParams}setLabel(e){this.isDisposed||this._label===e||(this._label=e,this._onDidChange.fire())}setColor(e){if(this.isDisposed)return;let t=e===``?void 0:e;this._color!==t&&(this._color=t,this._onDidChange.fire())}setComponentParams(e){this.isDisposed||(this._componentParams=e,this._onDidChange.fire())}get collapsed(){return this._collapsed}get panelIds(){return this._panelIds}get size(){return this._panelIds.length}get isEmpty(){return this._panelIds.length===0}constructor(e,t){super(),this.id=e,this._collapsed=!1,this._panelIds=[],this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this._onDidPanelChange=new X,this.onDidPanelChange=this._onDidPanelChange.event,this._onDidCollapseChange=new X,this.onDidCollapseChange=this._onDidCollapseChange.event,this._onDidDestroy=new X,this.onDidDestroy=this._onDidDestroy.event,this._label=t?.label??``,this._color=t?.color===``?void 0:t?.color,this._collapsed=t?.collapsed??!1,this._componentParams=t?.componentParams,this.addDisposables(this._onDidChange,this._onDidPanelChange,this._onDidCollapseChange,this._onDidDestroy)}addPanel(e,t){if(this.isDisposed||this._panelIds.includes(e))return;let n=t===void 0?this._panelIds.length:Math.max(0,Math.min(t,this._panelIds.length));this._panelIds.splice(n,0,e),this._onDidPanelChange.fire({panelId:e,type:`add`})}removePanel(e){if(this.isDisposed)return!1;let t=this._panelIds.indexOf(e);return t!==-1&&(this._panelIds.splice(t,1),this._onDidPanelChange.fire({panelId:e,type:`remove`}),!0)}indexOfPanel(e){return this._panelIds.indexOf(e)}containsPanel(e){return this._panelIds.includes(e)}collapse(){this.isDisposed||this._collapsed||(this._collapsed=!0,this._onDidCollapseChange.fire(!0))}expand(){!this.isDisposed&&this._collapsed&&(this._collapsed=!1,this._onDidCollapseChange.fire(!1))}toggle(){this._collapsed?this.expand():this.collapse()}toJSON(){let e={id:this.id,collapsed:this._collapsed,panelIds:[...this._panelIds]};return this._label&&(e.label=this._label),this._color!==void 0&&(e.color=this._color),this._componentParams!==void 0&&(e.componentParams=this._componentParams),e}dispose(){this._onDidDestroy.fire(),super.dispose()}},Bq=class extends _W{get nativeEvent(){return this.options.nativeEvent}get position(){return this.options.position}get panel(){return this.options.panel}get index(){return this.options.index}get group(){return this.options.group}get api(){return this.options.api}constructor(e){super(),this.options=e}getData(){return this.options.getData()}},Vq=class extends Bq{get kind(){return this._kind}constructor(e){super(e),this._kind=e.kind}},Hq=class extends Y{get tabGroups(){return this._tabGroups}get element(){throw Error(`dockview: not supported`)}get activePanel(){return this._activePanel}get contentContainerId(){return this.contentContainer.element.id}get contentDropTarget(){return this.contentContainer.dropTarget}get locked(){return this._locked}set locked(e){this._locked=e,Q(this.container,`dv-locked-groupview`,e===`no-drop-target`||e)}get isActive(){return this._isGroupActive}get panels(){return this._panels}get size(){return this._panels.length}get isEmpty(){return this._panels.length===0}get hasWatermark(){return!!(this.watermark&&this.container.contains(this.watermark.element))}get header(){return this.tabsContainer}get tabsListElement(){return this.tabsContainer.tabsListElement}getPanelForTab(e){return this.tabsContainer.getPanelForTab(e)}get isContentFocused(){let e=this.contentContainer.element,t=$W(e);return t?DW(t,e):!1}get headerPosition(){return this._headerPosition??`top`}set headerPosition(e){this._headerPosition=e,this.invalidateHeaderSize(),TW(this.container,`dv-groupview-header-top`,`dv-groupview-header-bottom`,`dv-groupview-header-left`,`dv-groupview-header-right`),EW(this.container,`dv-groupview-header-${e}`);let t=e===`top`||e===`bottom`?`horizontal`:`vertical`,n=this._headerDirection;if(this._headerDirection=t,this.tabsContainer.direction=t,this.header.direction=t,this.panels.length>0&&this.layoutContent(),this.updateHeaderActions(),n!==void 0&&n!==t){var r;(r=this.groupPanel)==null||r.api._onDidHeaderDirectionChange.fire({direction:t,position:e})}}get location(){return this._location}set location(e){this._location=e,Q(this.container,`dv-groupview-floating`,!1),Q(this.container,`dv-groupview-popout`,!1),Q(this.container,`dv-groupview-edge`,!1);let t=e=>{this.contentContainer.dropTarget.setTargetZones(e),this.contentContainer.pointerDropTarget.setTargetZones(e)};switch(e.type){case`grid`:t([`top`,`bottom`,`left`,`right`,`center`]);break;case`floating`:t([`top`,`bottom`,`left`,`right`,`center`]),Q(this.container,`dv-groupview-floating`,!0);break;case`popout`:t([`top`,`bottom`,`left`,`right`,`center`]),Q(this.container,`dv-groupview-popout`,!0);break;case`edge`:t([`center`]),Q(this.container,`dv-groupview-edge`,!0)}this.groupPanel.api._onDidLocationChange.fire({location:this.location})}constructor(e,t,n,r,i){super(),this.container=e,this.accessor=t,this.id=n,this.options=r,this.groupPanel=i,this._isGroupActive=!1,this._locked=!1,this._location={type:`grid`},this.mostRecentlyUsed=[],this._overwriteRenderContainer=null,this._overwriteDropTargetContainer=null,this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this._width=0,this._height=0,this._panels=[],this._panelDisposables=new Map,this._tabGroupDisposables=new Map,this._pendingMicrotaskDisposables=new Set,this._onMove=new X,this.onMove=this._onMove.event,this._onDidDrop=new X,this.onDidDrop=this._onDidDrop.event,this._onWillDrop=new X,this.onWillDrop=this._onWillDrop.event,this._onWillShowOverlay=new X,this.onWillShowOverlay=this._onWillShowOverlay.event,this._onTabDragStart=new X,this.onTabDragStart=this._onTabDragStart.event,this._onGroupDragStart=new X,this.onGroupDragStart=this._onGroupDragStart.event,this._onDidAddPanel=new X,this.onDidAddPanel=this._onDidAddPanel.event,this._onDidPanelTitleChange=new X,this.onDidPanelTitleChange=this._onDidPanelTitleChange.event,this._onDidPanelParametersChange=new X,this.onDidPanelParametersChange=this._onDidPanelParametersChange.event,this._onDidRemovePanel=new X,this.onDidRemovePanel=this._onDidRemovePanel.event,this._onDidActivePanelChange=new X,this.onDidActivePanelChange=this._onDidActivePanelChange.event,this._onUnhandledDragOver=new X,this.onUnhandledDragOver=this._onUnhandledDragOver.event,this._tabGroups=[],this._tabGroupMap=new Map,this._panelToTabGroup=new Map,this._tabGroupIdCounter=0,this._pendingTabGroupUpdate=!1,this._onDidCreateTabGroup=new X,this.onDidCreateTabGroup=this._onDidCreateTabGroup.event,this._onDidDestroyTabGroup=new X,this.onDidDestroyTabGroup=this._onDidDestroyTabGroup.event,this._onDidAddPanelToTabGroup=new X,this.onDidAddPanelToTabGroup=this._onDidAddPanelToTabGroup.event,this._onDidRemovePanelFromTabGroup=new X,this.onDidRemovePanelFromTabGroup=this._onDidRemovePanelFromTabGroup.event,this._onDidTabGroupChange=new X,this.onDidTabGroupChange=this._onDidTabGroupChange.event,this._onDidTabGroupCollapsedChange=new X,this.onDidTabGroupCollapsedChange=this._onDidTabGroupCollapsedChange.event,Q(this.container,`dv-groupview`,!0),this.container.setAttribute(`role`,`region`),this._api=new nK(this.accessor),this.tabsContainer=new Rq(this.accessor,this.groupPanel),this.contentContainer=new GK(this.accessor,this),e.append(this.tabsContainer.element,this.contentContainer.element),this.header.hidden=!!r.hideHeader,this.locked=r.locked??!1,this.headerPosition=r.headerPosition??t.defaultHeaderPosition,this.addDisposables(wW(this.tabsContainer.element,()=>{if(this.isDisposed)return;let e=this.measureHeaderSize();e!==this._cachedHeaderSize&&(this._cachedHeaderSize=e,this.layout(this._width,this._height))}),this._onDidPanelTitleChange.event(()=>this.updateAccessibleLabel()),this._onTabDragStart,this._onGroupDragStart,this._onWillShowOverlay,this.tabsContainer.onTabDragStart(e=>{this._onTabDragStart.fire(e)}),this.tabsContainer.onGroupDragStart(e=>{this._onGroupDragStart.fire(e)}),this.tabsContainer.onDrop(e=>{let t=fW()?.panelId??null,n=t?this.tabsContainer.resolveDropIndex(t,e.index):e.index;if(this.handleDropEvent(`header`,e.event,`center`,n),t&&e.targetTabGroupId){let n=this._tabGroupMap.get(e.targetTabGroupId),r;if(n){let e=this._panels.findIndex(e=>e.id===t);if(e!==-1){r=0;for(let t of n.panelIds)this._panels.findIndex(e=>e.id===t)<e&&r++}}this.addPanelToTabGroup(e.targetTabGroupId,t,r)}else t&&e.targetTabGroupId===null&&this.removePanelFromTabGroup(t)}),this.contentContainer.onDidFocus(()=>{this.accessor.doSetGroupActive(this.groupPanel)}),this.contentContainer.onDidBlur(()=>{}),this.contentContainer.dropTarget.onDrop(e=>{this.handleDropEvent(`content`,e.nativeEvent,e.position,void 0,e.edge)}),this.contentContainer.pointerDropTarget.onDrop(e=>{this.handleDropEvent(`content`,e.nativeEvent,e.position,void 0,e.edge)}),this.tabsContainer.onWillShowOverlay(e=>{this._onWillShowOverlay.fire(e)}),this.contentContainer.dropTarget.onWillShowOverlay(e=>{this._onWillShowOverlay.fire(new aq(e,{kind:`content`,panel:this.activePanel,api:this._api,group:this.groupPanel,getData:fW}))}),this.contentContainer.pointerDropTarget.onWillShowOverlay(e=>{this._onWillShowOverlay.fire(new aq(e,{kind:`content`,panel:this.activePanel,api:this._api,group:this.groupPanel,getData:fW}))}),this._onMove,this._onDidChange,this._onDidDrop,this._onWillDrop,this._onDidAddPanel,this._onDidRemovePanel,this._onDidActivePanelChange,this._onUnhandledDragOver,this._onDidPanelTitleChange,this._onDidPanelParametersChange,this._onDidCreateTabGroup,this._onDidDestroyTabGroup,this._onDidAddPanelToTabGroup,this._onDidRemovePanelFromTabGroup,this._onDidTabGroupChange,this._onDidTabGroupCollapsedChange,this._onDidCreateTabGroup.event(()=>{this._scheduleTabGroupUpdate()}),this._onDidDestroyTabGroup.event(()=>{this._scheduleTabGroupUpdate()}),this._onDidAddPanelToTabGroup.event(()=>{this._scheduleTabGroupUpdate()}),this._onDidRemovePanelFromTabGroup.event(()=>{this._scheduleTabGroupUpdate()}),this._onDidTabGroupChange.event(()=>{this._scheduleTabGroupUpdate()}),this._onDidTabGroupCollapsedChange.event(()=>{this._scheduleTabGroupUpdate()}))}_scheduleTabGroupUpdate(){this._pendingTabGroupUpdate||(this._pendingTabGroupUpdate=!0,queueMicrotask(()=>{this._pendingTabGroupUpdate=!1,this.isDisposed||this.tabsContainer.updateTabGroups()}))}_bracketTabGroupMutation(e){return this.accessor.mutation?this.accessor.mutation(`tab-group`,e):e()}createTabGroup(e){return this._bracketTabGroupMutation(()=>this._doCreateTabGroup(e))}_doCreateTabGroup(e){let t=e?.id??`tg-${this.id}-${this._tabGroupIdCounter++}`,n=new zq(t,{label:e?.label,color:e?.color,collapsed:e?.collapsed,componentParams:e?.componentParams});return this._tabGroups.push(n),this._tabGroupMap.set(t,n),this._tabGroupDisposables.set(t,new Y(n.onDidChange(()=>{this._onDidTabGroupChange.fire({tabGroup:n})}),n.onDidCollapseChange(e=>{e?this._handleGroupCollapse(n):this._handleGroupExpand(n),this._onDidTabGroupCollapsedChange.fire({tabGroup:n})}),n.onDidDestroy(()=>{this._removeTabGroupInternal(n)}))),this._onDidCreateTabGroup.fire({tabGroup:n}),n}dissolveTabGroup(e){let t=this._tabGroupMap.get(e);t&&this._bracketTabGroupMutation(()=>{let e=[...t.panelIds];for(let n of e)t.removePanel(n),this._panelToTabGroup.delete(n),this._onDidRemovePanelFromTabGroup.fire({tabGroup:t,panelId:n});t.dispose()})}addPanelToTabGroup(e,t,n){let r=this._tabGroupMap.get(e);if(!r||!this._panels.some(e=>e.id===t))return;let i=this.getTabGroupForPanel(t);i?.id!==e&&this._bracketTabGroupMutation(()=>{i&&this.removePanelFromTabGroup(t),r.addPanel(t,n),this._panelToTabGroup.set(t,r),this._enforceContiguity(r,t),this._onDidAddPanelToTabGroup.fire({tabGroup:r,panelId:t})})}movePanelWithinGroup(e,t,n){let r=this._tabGroupMap.get(e);r?.containsPanel(t)&&(r.removePanel(t),r.addPanel(t,n),this._enforceContiguity(r,t),this.tabsContainer.updateTabGroups())}movePanelBetweenGroups(e,t,n){let r=this._findTabGroupForPanel(e),i=this._tabGroupMap.get(t);i&&(r&&(r.removePanel(e),this._panelToTabGroup.delete(e),this._moveOutOfGroupSpan(r,e),this._onDidRemovePanelFromTabGroup.fire({tabGroup:r,panelId:e}),r.isEmpty&&r.dispose()),i.addPanel(e,n),this._panelToTabGroup.set(e,i),this._enforceContiguity(i,e),this._onDidAddPanelToTabGroup.fire({tabGroup:i,panelId:e}))}moveTabGroup(e,t){let n=this._tabGroupMap.get(e);if(!n||n.panelIds.length===0)return;let r=new Set(n.panelIds),i=n.panelIds.map(e=>this._panels.find(t=>t.id===e)).filter(e=>e!==void 0);if(i.length===0)return;let a=0;for(let e=0;e<Math.min(t,this._panels.length);e++)r.has(this._panels[e].id)&&a++;for(let e of i){let t=this._panels.indexOf(e);t!==-1&&this._panels.splice(t,1)}let o=t-a,s=Math.max(0,Math.min(o,this._panels.length));this._panels.splice(s,0,...i);for(let e of this._panels)this.tabsContainer.delete(e.id);for(let e=0;e<this._panels.length;e++)this.tabsContainer.openPanel(this._panels[e],e);this._syncActiveTab(),this.tabsContainer.updateTabGroups()}_enforceContiguity(e,t){let n=this._panels.find(e=>e.id===t);if(!n)return;let r=e.indexOfPanel(t),i=this._computeGlobalIndex(e,r),a=this._panels.indexOf(n);if(a===i)return;this._panels.splice(a,1);let o=i>a?i-1:i;this._panels.splice(o,0,n),this._reinsertTab(n,o)}_reinsertTab(e,t){this.tabsContainer.delete(e.id),this.tabsContainer.openPanel(e,t),e===this._activePanel&&this._syncActiveTab()}_syncActiveTab(){this._activePanel&&(this.tabsContainer.setActivePanel(this._activePanel),this.contentContainer.setLabelledBy(this.tabsContainer.getTabId(this._activePanel.id)))}_computeGlobalIndex(e,t){let n=e.panelIds;if(n.length<=1){let e=this._panels.find(e=>e.id===n[0]);return e?this._panels.indexOf(e):this._panels.length}for(let e=0;e<n.length;e++){if(e===t)continue;let r=this._panels.find(t=>t.id===n[e]);if(r){let n=this._panels.indexOf(r);return Math.max(0,n+(t-e))}}return this._panels.length}removePanelFromTabGroup(e){let t=this._findTabGroupForPanel(e);t&&this._bracketTabGroupMutation(()=>{t.removePanel(e),this._panelToTabGroup.delete(e),this._moveOutOfGroupSpan(t,e),this._onDidRemovePanelFromTabGroup.fire({tabGroup:t,panelId:e}),t.isEmpty&&t.dispose()})}_moveOutOfGroupSpan(e,t){let n=this._panels.findIndex(e=>e.id===t);if(n===-1||e.isEmpty)return;let r=e.panelIds,i=this._panels.findIndex(e=>e.id===r[0]),a=this._panels.findIndex(e=>e.id===r[r.length-1]);if(i===-1||a===-1||n<i||n>a)return;let[o]=this._panels.splice(n,1);this._panels.splice(a,0,o),this._reinsertTab(o,a)}getTabGroups(){return this._tabGroups}updateTabGroups(){this.tabsContainer.updateTabGroups()}refreshTabGroupAccent(){this.tabsContainer.refreshTabGroupAccent()}refreshWatermark(){if(this.watermark){var e,t;this.watermark.element.remove(),(e=(t=this.watermark).dispose)==null||e.call(t),this.watermark=void 0}this.updateContainer()}getTabGroupForPanel(e){return this._findTabGroupForPanel(e)}_findTabGroupForPanel(e){return this._panelToTabGroup.get(e)}_removeTabGroupInternal(e){let t=this._tabGroups.indexOf(e);if(t!==-1){this._tabGroups.splice(t,1),this._tabGroupMap.delete(e.id);for(let t of e.panelIds)this._panelToTabGroup.delete(t);this._onDidDestroyTabGroup.fire({tabGroup:e});let n=this._tabGroupDisposables.get(e.id);this._tabGroupDisposables.delete(e.id),n&&(this._pendingMicrotaskDisposables.add(n),queueMicrotask(()=>{this._pendingMicrotaskDisposables.delete(n),n.dispose()}))}}_handleGroupCollapse(e){if(!this._activePanel||!e.containsPanel(this._activePanel.id))return;let t=this._panels.indexOf(this._activePanel);for(let e=t+1;e<this._panels.length;e++){let t=this._panels[e];if(!this._findTabGroupForPanel(t.id)?.collapsed){this.doSetActivePanel(t),this.updateContainer();return}}for(let e=t-1;e>=0;e--){let t=this._panels[e];if(!this._findTabGroupForPanel(t.id)?.collapsed){this.doSetActivePanel(t),this.updateContainer();return}}this.contentContainer.closePanel(),this.doSetActivePanel(void 0),this.updateContainer()}_handleGroupExpand(e){if(this._activePanel)return;let t=e.panelIds[0];if(t){let e=this._panels.find(e=>e.id===t);e&&(this.doSetActivePanel(e),this.updateContainer())}}restoreTabGroups(e){for(let t of e){let e=/-(\d+)$/.exec(t.id);if(e){let t=Number.parseInt(e[1],10)+1;t>this._tabGroupIdCounter&&(this._tabGroupIdCounter=t)}}for(let t of e){let e=this.createTabGroup({id:t.id,label:t.label,color:t.color,componentParams:t.componentParams}),n=this._tabGroupMap.get(e.id);for(let r of t.panelIds)this._panels.some(e=>e.id===r)&&(e.addPanel(r),this._panelToTabGroup.set(r,n),this._enforceContiguity(n,r));t.collapsed&&e.collapse(),e.isEmpty&&e.dispose()}}focusContent(){this.contentContainer.element.focus()}focusActiveTab(){this.tabsContainer.focusActiveTab()}set renderContainer(e){this.panels.forEach(e=>{this.renderContainer.detatch(e)}),this._overwriteRenderContainer=e,this.panels.forEach(e=>{this.rerender(e)}),this.panels.length>0&&this.layoutContent()}get renderContainer(){return this._overwriteRenderContainer??this.accessor.overlayRenderContainer}set dropTargetContainer(e){this._overwriteDropTargetContainer=e}get dropTargetContainer(){return this._location.type===`floating`&&this.accessor.rootDropTargetContainer.disabled?this.accessor.floatingDropTargetContainer:this._overwriteDropTargetContainer??this.accessor.rootDropTargetContainer}initialize(){this.options.panels&&this.options.panels.forEach(e=>{this.doAddPanel(e)}),this.options.activePanel&&this.openPanel(this.options.activePanel),this.setActive(this.isActive,!0),this.updateContainer(),this.updateHeaderActions()}updateHeaderActions(){var e;(e=this.accessor.headerActionsService)==null||e.refresh(this.groupPanel)}attachHeaderAction(e,t){switch(e){case`left`:this.tabsContainer.setLeftActionsElement(t);break;case`right`:this.tabsContainer.setRightActionsElement(t);break;case`prefix`:this.tabsContainer.setPrefixActionsElement(t)}}rerender(e){this.contentContainer.renderPanel(e,{asActive:!1})}indexOf(e){return this.tabsContainer.indexOf(e.id)}toJSON(){let e={views:this.tabsContainer.panels,activeView:this._activePanel?.id,id:this.id};return this.locked!==!1&&(e.locked=this.locked),this.header.hidden&&(e.hideHeader=!0),this.headerPosition!==`top`&&(e.headerPosition=this.headerPosition),this._tabGroups.length>0&&(e.tabGroups=this._tabGroups.map(e=>e.toJSON())),e}moveToNext(e){var t;e??={},(t=e).panel??(t.panel=this.activePanel);let n=e.panel?this.panels.indexOf(e.panel):-1,r;if(n<this.panels.length-1)r=n+1;else if(e.suppressRoll)return;else r=0;this.openPanel(this.panels[r])}moveToPrevious(e){var t;if(e??={},(t=e).panel??(t.panel=this.activePanel),!e.panel)return;let n=this.panels.indexOf(e.panel),r;if(n>0)r=n-1;else if(e.suppressRoll)return;else r=this.panels.length-1;this.openPanel(this.panels[r])}containsPanel(e){return this.panels.includes(e)}init(e){}update(e){}focus(){var e;(e=this._activePanel)==null||e.focus()}openPanel(e,t={}){typeof t.index!=`number`||t.index>this.panels.length?t.index=this.panels.length:t.index<0&&(t.index=0);let n=!!t.skipSetActive;e.updateParentGroup(this.groupPanel,{skipSetActive:t.skipSetActive}),this.doAddPanel(e,t.index,{skipSetActive:n}),this.invalidateHeaderSize(),this._activePanel===e?this.contentContainer.openPanel(e):(n||this.doSetActivePanel(e),t.skipSetGroupActive||this.accessor.doSetGroupActive(this.groupPanel),t.skipSetActive?e.runEvents():this.updateContainer())}removePanel(e,t){let n=typeof e==`string`?e:e.id,r=this._panels.find(e=>e.id===n);if(!r)throw Error(`invalid operation`);return this._removePanel(r,t)}closeAllPanels(){if(this.panels.length>0){let e=[...this.panels];for(let t of e)this.doClose(t)}else this.accessor.removeGroup(this.groupPanel)}closePanel(e){this.doClose(e)}doClose(e){let t=this.panels.length===1&&this.accessor.isLastGridGroup(this.groupPanel);this.accessor.removePanel(e,t&&this.accessor.options.noPanelsOverlay===`emptyGroup`?{removeEmptyGroup:!1}:void 0)}isPanelActive(e){return this._activePanel===e}updateActions(e){this.tabsContainer.setRightActionsElement(e)}setActive(e,t=!1){if(!this.isDisposed&&(t||this.isActive!==e)){if(this._isGroupActive=e,Q(this.container,`dv-active-group`,e),Q(this.container,`dv-inactive-group`,!e),this.tabsContainer.setActive(this.isActive),!this._activePanel&&this.panels.length>0){let e=this._panels.find(e=>!this._findTabGroupForPanel(e.id)?.collapsed);e&&this.doSetActivePanel(e)}this.updateContainer()}}layout(e,t){this._width=e,this._height=t,this.layoutContent()}layoutContent(){let{width:e,height:t}=this.contentDimensions();this.contentContainer.layout(e,t),this._activePanel?.layout&&this._activePanel.layout(e,t)}relayout(){this.invalidateHeaderSize(),this.layout(this._width,this._height)}measureHeaderSize(){let e=this.tabsContainer.element;return this.headerPosition===`top`||this.headerPosition===`bottom`?e.offsetHeight:e.offsetWidth}invalidateHeaderSize(){this._cachedHeaderSize=void 0}contentDimensions(){let e=this.headerPosition===`top`||this.headerPosition===`bottom`,t=this._cachedHeaderSize??=this.measureHeaderSize();return{width:e?this._width:Math.max(0,this._width-t),height:e?Math.max(0,this._height-t):this._height}}_removePanel(e,t){let n=this._activePanel===e;if(this.doRemovePanel(e),this.invalidateHeaderSize(),n&&this.panels.length>0){let e=this.mostRecentlyUsed[0];this.openPanel(e,{skipSetActive:t?.skipSetActive,skipSetGroupActive:t?.skipSetActiveGroup})}return this._activePanel&&this.panels.length===0&&this.doSetActivePanel(void 0),t?.skipSetActive||this.updateContainer(),e}doRemovePanel(e){let t=this.panels.indexOf(e);if(this._activePanel===e&&this.contentContainer.closePanel(),this.tabsContainer.delete(e.id),this._panels.splice(t,1),this.mostRecentlyUsed.includes(e)){let t=this.mostRecentlyUsed.indexOf(e);this.mostRecentlyUsed.splice(t,1)}let n=this._panelDisposables.get(e.id);n&&(n.dispose(),this._panelDisposables.delete(e.id)),this.removePanelFromTabGroup(e.id),this._onDidRemovePanel.fire({panel:e})}doAddPanel(e,t=this.panels.length,n){let r=this._panels.indexOf(e)>-1;this.tabsContainer.show(),this.contentContainer.show(),this.tabsContainer.openPanel(e,t),n?.skipSetActive?e.api.renderer===`always`&&this.contentContainer.renderPanel(e,{asActive:!1}):this.contentContainer.openPanel(e),!r&&(this.updateMru(e),this.panels.splice(t,0,e),this._panelDisposables.set(e.id,new Y(e.api.onDidTitleChange(e=>this._onDidPanelTitleChange.fire(e)),e.api.onDidParametersChange(e=>this._onDidPanelParametersChange.fire(e)))),this._onDidAddPanel.fire({panel:e}))}doSetActivePanel(e){if(this._activePanel!==e){if(this._activePanel=e,e){var t;this._syncActiveTab(),this.contentContainer.openPanel(e),this.layoutContent(),this.updateMru(e),this.contentContainer.refreshFocusState(),this._onDidActivePanelChange.fire({panel:e,origin:(t=this.accessor).currentOrigin?.call(t)??`user`})}this.updateAccessibleLabel()}}updateAccessibleLabel(){let e=this._activePanel?.title;e?this.container.setAttribute(`aria-label`,e):this.container.removeAttribute(`aria-label`)}updateMru(e){this.mostRecentlyUsed.includes(e)&&this.mostRecentlyUsed.splice(this.mostRecentlyUsed.indexOf(e),1),this.mostRecentlyUsed=[e,...this.mostRecentlyUsed]}updateContainer(){this.panels.forEach(e=>e.runEvents());let e=this.isEmpty||!this._activePanel;if(e&&!this.watermark){let e=this.accessor.createWatermarkComponent();e.init({containerApi:this._api,group:this.groupPanel}),this.watermark=e,Z(this.watermark.element,`pointerdown`,()=>{this.isActive||this.accessor.doSetGroupActive(this.groupPanel)}),this.contentContainer.element.appendChild(this.watermark.element)}if(!e&&this.watermark){var t,n;this.watermark.element.remove(),(t=(n=this.watermark).dispose)==null||t.call(n),this.watermark=void 0}}canDisplayOverlay(e,t,n){let r=new fq(e,n,t,fW,this.accessor.getPanel(this.id));return this._onUnhandledDragOver.fire(r),r.isAccepted}canDisplayContentOverlay(e,t){if(this.locked===`no-drop-target`||this.locked&&t===`center`)return!1;let n=fW();return!n&&e.shiftKey&&this.location.type!==`floating`?!1:n?.viewId===this.accessor.id||this.canDisplayOverlay(e,t,`content`)}handleDropEvent(e,t,n,r,i){if(this.locked===`no-drop-target`)return;if(e===`content`&&i){this.accessor.dockToLayoutEdge(t,n);return}function a(){switch(e){case`header`:return typeof r==`number`?`tab`:`header_space`;case`content`:return`content`}}let o=typeof r==`number`?this.panels[r]:void 0,s=new Vq({nativeEvent:t,position:n,panel:o,index:r,getData:()=>fW(),kind:a(),group:this.groupPanel,api:this._api});if(this._onWillDrop.fire(s),s.defaultPrevented)return;let c=fW();if(c?.viewId===this.accessor.id){if(e===`content`&&c.groupId===this.id&&(n===`center`||c.panelId===null&&!c.tabGroupId)||e===`header`&&c.groupId===this.id&&c.panelId===null&&!c.tabGroupId)return;if(c.panelId===null){let{groupId:e}=c;this._onMove.fire({target:n,groupId:e,index:r,tabGroupId:c.tabGroupId});return}if(this.tabsContainer.indexOf(c.panelId)!==-1&&this.tabsContainer.size===1&&this.accessor.options.closeEmptyGroups!==!1)return;let{groupId:t,panelId:i}=c;if(this.id===t&&!n&&this.tabsContainer.indexOf(i)===r)return;this._onMove.fire({target:n,groupId:c.groupId,itemId:c.panelId,index:r})}else this._onDidDrop.fire(new Bq({nativeEvent:t,position:n,panel:o,index:r,getData:()=>fW(),group:this.groupPanel,api:this._api}))}updateDragAndDropState(){this.tabsContainer.updateDragAndDropState()}dispose(){var e,t,n;super.dispose(),(e=this.watermark)==null||e.element.remove(),(t=this.watermark)==null||(n=t.dispose)==null||n.call(t),this.watermark=void 0;for(let e of[...this._tabGroups])e.dispose();for(let e of this._tabGroupDisposables.values())e.dispose();this._tabGroupDisposables.clear();for(let e of this._pendingMicrotaskDisposables)e.dispose();this._pendingMicrotaskDisposables.clear();for(let e of this.panels)e.dispose();this.tabsContainer.dispose(),this.contentContainer.dispose()}},Uq=class extends LK{constructor(e,t,n){super(e,t),this._onDidConstraintsChangeInternal=new X,this.onDidConstraintsChangeInternal=this._onDidConstraintsChangeInternal.event,this._onDidConstraintsChange=new X,this.onDidConstraintsChange=this._onDidConstraintsChange.event,this._onDidSizeChange=new X,this.onDidSizeChange=this._onDidSizeChange.event,this.addDisposables(this._onDidConstraintsChangeInternal,this._onDidConstraintsChange,this._onDidSizeChange),n&&this.initialize(n)}setConstraints(e){this._onDidConstraintsChangeInternal.fire(e)}setSize(e){this._onDidSizeChange.fire(e)}},Wq=class extends BK{get priority(){return this._priority}get snap(){return this._snap}get minimumWidth(){return this.__minimumWidth()}get minimumHeight(){return this.__minimumHeight()}get maximumHeight(){return this.__maximumHeight()}get maximumWidth(){return this.__maximumWidth()}__minimumWidth(){let e=typeof this._minimumWidth==`function`?this._minimumWidth():this._minimumWidth;return e!==this._evaluatedMinimumWidth&&(this._evaluatedMinimumWidth=e,this.updateConstraints()),e}__maximumWidth(){let e=typeof this._maximumWidth==`function`?this._maximumWidth():this._maximumWidth;return e!==this._evaluatedMaximumWidth&&(this._evaluatedMaximumWidth=e,this.updateConstraints()),e}__minimumHeight(){let e=typeof this._minimumHeight==`function`?this._minimumHeight():this._minimumHeight;return e!==this._evaluatedMinimumHeight&&(this._evaluatedMinimumHeight=e,this.updateConstraints()),e}__maximumHeight(){let e=typeof this._maximumHeight==`function`?this._maximumHeight():this._maximumHeight;return e!==this._evaluatedMaximumHeight&&(this._evaluatedMaximumHeight=e,this.updateConstraints()),e}get isActive(){return this.api.isActive}get isVisible(){return this.api.isVisible}constructor(e,t,n,r){super(e,t,r??new Uq(e,t)),this._evaluatedMinimumWidth=0,this._evaluatedMaximumWidth=2**53-1,this._evaluatedMinimumHeight=0,this._evaluatedMaximumHeight=2**53-1,this._minimumWidth=0,this._minimumHeight=0,this._maximumWidth=2**53-1,this._maximumHeight=2**53-1,this._snap=!1,this._onDidChange=new X,this.onDidChange=this._onDidChange.event,typeof n?.minimumWidth==`number`&&(this._minimumWidth=n.minimumWidth),typeof n?.maximumWidth==`number`&&(this._maximumWidth=n.maximumWidth),typeof n?.minimumHeight==`number`&&(this._minimumHeight=n.minimumHeight),typeof n?.maximumHeight==`number`&&(this._maximumHeight=n.maximumHeight),this.api.initialize(this),this.addDisposables(this.api.onWillVisibilityChange(e=>{let{isVisible:t}=e,{accessor:n}=this._params;n.setVisible(this,t)}),this.api.onActiveChange(()=>{let{accessor:e}=this._params;e.doSetGroupActive(this)}),this.api.onDidConstraintsChangeInternal(e=>this.applyConstraints(e)),this.api.onDidSizeChange(e=>{this._onDidChange.fire({height:e.height,width:e.width})}),this._onDidChange)}setVisible(e){this.api._onDidVisibilityChange.fire({isVisible:e})}setActive(e){this.api._onDidActiveChange.fire({isActive:e})}init(e){e.maximumHeight&&(this._maximumHeight=e.maximumHeight),e.minimumHeight&&(this._minimumHeight=e.minimumHeight),e.maximumWidth&&(this._maximumWidth=e.maximumWidth),e.minimumWidth&&(this._minimumWidth=e.minimumWidth),this._priority=e.priority,this._snap=!!e.snap,super.init(e),typeof e.isVisible==`boolean`&&this.setVisible(e.isVisible)}applyConstraints(e){(typeof e.minimumWidth==`number`||typeof e.minimumWidth==`function`)&&(this._minimumWidth=e.minimumWidth),(typeof e.minimumHeight==`number`||typeof e.minimumHeight==`function`)&&(this._minimumHeight=e.minimumHeight),(typeof e.maximumWidth==`number`||typeof e.maximumWidth==`function`)&&(this._maximumWidth=e.maximumWidth),(typeof e.maximumHeight==`number`||typeof e.maximumHeight==`function`)&&(this._maximumHeight=e.maximumHeight),this.notifyConstraintsChanged()}notifyConstraintsChanged(){this._onDidChange.fire(void 0)}updateConstraints(){this.api._onDidConstraintsChange.fire({minimumWidth:this._evaluatedMinimumWidth,maximumWidth:this._evaluatedMaximumWidth,minimumHeight:this._evaluatedMinimumHeight,maximumHeight:this._evaluatedMaximumHeight})}toJSON(){let e=super.toJSON(),t=e=>e===2**53-1?void 0:e,n=e=>e<=0?void 0:e;return $($({},e),{},{minimumHeight:n(this.minimumHeight),maximumHeight:t(this.maximumHeight),minimumWidth:n(this.minimumWidth),maximumWidth:t(this.maximumWidth),snap:this.snap,priority:this.priority})}},Gq=`dockview: DockviewGroupPanelApiImpl not initialized`,Kq=class extends Uq{get location(){if(!this._group)throw Error(Gq);return this._group.model.location}get boundingBox(){if(!this._group||this._group.model.location.type===`popout`)return;let e=this.accessor.element.getBoundingClientRect(),t=this._group.element.getBoundingClientRect();return{left:t.left-e.left,top:t.top-e.top,width:t.width,height:t.height}}get locked(){if(!this._group)throw Error(Gq);return this._group.locked}set locked(e){if(!this._group)throw Error(Gq);this._group.locked=e}constructor(e,t){super(e,`__dockviewgroup__`),this.accessor=t,this._isApplyingSize=!1,this._onDidLocationChange=new X,this.onDidLocationChange=this._onDidLocationChange.event,this._onDidActivePanelChange=new X,this.onDidActivePanelChange=this._onDidActivePanelChange.event,this._onDidCollapsedChange=new X,this.onDidCollapsedChange=this._onDidCollapsedChange.event,this._onDidPeekChange=new X,this.onDidPeekChange=this._onDidPeekChange.event,this._onDidHeaderDirectionChange=new X,this.onDidHeaderDirectionChange=this._onDidHeaderDirectionChange.event,this.addDisposables(this._onDidLocationChange,this._onDidActivePanelChange,this._onDidCollapsedChange,this._onDidPeekChange,this._onDidHeaderDirectionChange,this._onDidVisibilityChange.event(e=>{if(e.isVisible&&this._pendingSize){let e=this._pendingSize;this._pendingSize=void 0,super.setSize(e)}}),this.onDidDimensionsChange(e=>{let t=e.width!==this._reportedSize?.width||e.height!==this._reportedSize?.height;this._reportedSize={width:e.width,height:e.height},t&&this.isVisible&&!this._isApplyingSize&&(this._pendingSize=void 0)}))}setSize(e){(typeof e.width==`number`||typeof e.height==`number`)&&(this._pendingSize=$({},e));let t=this._isApplyingSize;this._isApplyingSize=!0;try{super.setSize(e)}finally{this._isApplyingSize=t}}close(){if(this._group)return this.accessor.removeGroup(this._group)}getWindow(){return this.location.type===`popout`?this.location.getWindow():globalThis.window}setHeaderPosition(e){if(!this._group)throw Error(Gq);this._group.model.headerPosition=e}getHeaderPosition(){if(!this._group)throw Error(Gq);return this._group.model.headerPosition}moveTo(e){if(!this._group)throw Error(Gq);this.accessor.withOrigin(`api`,()=>{let t=e.group??this.accessor.addGroup({direction:hK(e.position??`right`),skipSetActive:e.skipSetActive??!1});this.accessor.moveGroupOrPanel({from:{groupId:this._group.id},to:{group:t,position:e.group?e.position??`center`:`center`,index:e.index},skipSetActive:e.skipSetActive})})}maximize(){if(!this._group)throw Error(Gq);this.location.type===`grid`&&this.accessor.maximizeGroup(this._group)}isMaximized(){if(!this._group)throw Error(Gq);return this.accessor.isMaximizedGroup(this._group)}exitMaximized(){if(!this._group)throw Error(Gq);this.isMaximized()&&this.accessor.exitMaximizedGroup()}collapse(){this._group&&this.accessor.setEdgeGroupCollapsed(this._group,!0)}expand(){this._group&&this.accessor.setEdgeGroupCollapsed(this._group,!1)}isCollapsed(){return this._group?this.accessor.isEdgeGroupCollapsed(this._group):!1}isPeeking(){return this._group?this.accessor.isEdgeGroupPeeking(this._group):!1}setAutoHide(e){this._group&&this.accessor.setEdgeGroupAutoHide(this._group,e)}isAutoHide(){return this._group?this.accessor.isEdgeGroupAutoHide(this._group):!1}initialize(e){this._group=e}},qq=100,Jq=100,Yq=class extends Wq{get minimumWidth(){if(typeof this._explicitConstraints.minimumWidth==`number`)return this._explicitConstraints.minimumWidth;let e=this.activePanel?.minimumWidth;return typeof e==`number`?e:super.__minimumWidth()}get minimumHeight(){if(typeof this._explicitConstraints.minimumHeight==`number`)return this._explicitConstraints.minimumHeight;let e=this.activePanel?.minimumHeight;return typeof e==`number`?e:super.__minimumHeight()}get maximumWidth(){if(typeof this._explicitConstraints.maximumWidth==`number`)return this._explicitConstraints.maximumWidth;let e=this.activePanel?.maximumWidth;return typeof e==`number`?e:super.__maximumWidth()}get maximumHeight(){if(typeof this._explicitConstraints.maximumHeight==`number`)return this._explicitConstraints.maximumHeight;let e=this.activePanel?.maximumHeight;return typeof e==`number`?e:super.__maximumHeight()}get panels(){return this._model.panels}get activePanel(){return this._model.activePanel}get size(){return this._model.size}get model(){return this._model}get locked(){return this._model.locked}set locked(e){this._model.locked=e}get header(){return this._model.header}constructor(e,t,n){super(t,`groupview_default`,{minimumHeight:n.constraints?.minimumHeight??Jq,minimumWidth:n.constraints?.minimumWidth??qq,maximumHeight:n.constraints?.maximumHeight,maximumWidth:n.constraints?.maximumWidth},new Kq(t,e)),this._explicitConstraints={},this.api.initialize(this),this._model=new Hq(this.element,e,t,n,this),this._lastConstraints=this.currentConstraints(),this.addDisposables(this.model.onDidActivePanelChange(e=>{this.api._onDidActivePanelChange.fire(e),this.notifyIfConstraintsChanged()}))}applyConstraints(e){e.minimumWidth!==void 0&&(this._explicitConstraints.minimumWidth=typeof e.minimumWidth==`function`?e.minimumWidth():e.minimumWidth),e.minimumHeight!==void 0&&(this._explicitConstraints.minimumHeight=typeof e.minimumHeight==`function`?e.minimumHeight():e.minimumHeight),e.maximumWidth!==void 0&&(this._explicitConstraints.maximumWidth=typeof e.maximumWidth==`function`?e.maximumWidth():e.maximumWidth),e.maximumHeight!==void 0&&(this._explicitConstraints.maximumHeight=typeof e.maximumHeight==`function`?e.maximumHeight():e.maximumHeight),super.applyConstraints(e),this._lastConstraints=this.currentConstraints()}currentConstraints(){return{minimumWidth:this.minimumWidth,maximumWidth:this.maximumWidth,minimumHeight:this.minimumHeight,maximumHeight:this.maximumHeight}}notifyIfConstraintsChanged(){let e=this._lastConstraints,t=this.currentConstraints();(e.minimumWidth!==t.minimumWidth||e.maximumWidth!==t.maximumWidth||e.minimumHeight!==t.minimumHeight||e.maximumHeight!==t.maximumHeight)&&(this._lastConstraints=t,this.notifyConstraintsChanged())}focus(){this.api.isActive||this.api.setActive(),super.focus()}initialize(){this._model.initialize()}setActive(e){super.setActive(e),this.model.setActive(e)}layout(e,t){super.layout(e,t),this.model.layout(e,t)}relayout(){this.model.relayout()}getComponent(){return this._model}toJSON(){return this.model.toJSON()}},Xq={name:`abyss`,className:`dockview-theme-abyss`,colorScheme:`dark`,tabGroupIndicator:`none`},Zq=class extends Uq{get location(){return this.group.api.location}get title(){return this.panel.title}get isPinned(){return this.panel.isPinned}get isGroupActive(){return this.group.isActive}get renderer(){return this.panel.renderer}set group(e){if(this._group!==e){let t=this._group.isActive;this._group=e,this._onDidGroupChange.fire({}),this.setupGroupEventListeners(),t!==this.isGroupActive&&this._onDidActiveGroupChange.fire({isActive:this.isGroupActive}),this.fireLocationChange()}}get group(){return this._group}get tabComponent(){return this._tabComponent}constructor(e,t,n,r,i){super(e.id,r),this.panel=e,this.accessor=n,this._onDidTitleChange=new X,this.onDidTitleChange=this._onDidTitleChange.event,this._onDidChangePinned=new X,this.onDidChangePinned=this._onDidChangePinned.event,this._onDidActiveGroupChange=new X,this.onDidActiveGroupChange=this._onDidActiveGroupChange.event,this._onDidGroupChange=new X,this.onDidGroupChange=this._onDidGroupChange.event,this._onDidRendererChange=new X,this.onDidRendererChange=this._onDidRendererChange.event,this._onDidLocationChange=new X,this.onDidLocationChange=this._onDidLocationChange.event,this.groupEventsDisposable=new hW,this._tabComponent=i,this.initialize(e),this._group=t,this.setupGroupEventListeners(),this.addDisposables(this.groupEventsDisposable,this._onDidRendererChange,this._onDidTitleChange,this._onDidChangePinned,this._onDidGroupChange,this._onDidActiveGroupChange,this._onDidLocationChange)}getWindow(){return this.group.api.getWindow()}setActive(){this.accessor.withOrigin(`api`,()=>super.setActive())}moveTo(e){this.accessor.withOrigin(`api`,()=>this.accessor.moveGroupOrPanel({from:{groupId:this._group.id,panelId:this.panel.id},to:{group:e.group??this._group,position:e.group?e.position??`center`:`center`,index:e.index},skipSetActive:e.skipSetActive}))}setTitle(e){this.panel.setTitle(e)}setPinned(e){this.accessor.setPanelPinned(this.panel,e)}setRenderer(e){this.panel.setRenderer(e)}close(){this.group.model.closePanel(this.panel)}maximize(){this.group.api.maximize()}isMaximized(){return this.group.api.isMaximized()}exitMaximized(){this.group.api.exitMaximized()}fireLocationChange(){this.accessor.deferLocationChange(this,()=>{this.isDisposed||this._onDidLocationChange.fire({location:this.location})})}setupGroupEventListeners(){let e=this.isGroupActive;this.groupEventsDisposable.value=new Y(this.group.api.onDidVisibilityChange(e=>{let t=!e.isVisible&&this.isVisible,n=e.isVisible&&!this.isVisible,r=this.group.model.isPanelActive(this.panel);(t||n&&r)&&this._onDidVisibilityChange.fire(e)}),this.group.api.onDidLocationChange(()=>{this.group===this.panel.group&&this.fireLocationChange()}),this.group.api.onDidActiveChange(()=>{this.group===this.panel.group&&e!==this.isGroupActive&&(e=this.isGroupActive,this._onDidActiveGroupChange.fire({isActive:this.isGroupActive}))}))}},Qq=class extends Y{get params(){return this._params}get title(){return this._title}get isPinned(){return this._pinned}get group(){return this._group}get renderer(){return this._renderer??this.accessor.renderer}get minimumWidth(){return this._minimumWidth}get minimumHeight(){return this._minimumHeight}get maximumWidth(){return this._maximumWidth}get maximumHeight(){return this._maximumHeight}constructor(e,t,n,r,i,a,o,s){super(),this.id=e,this.accessor=r,this.containerApi=i,this.view=o,this._pinned=!1,this._renderer=s.renderer,this._group=a,this._minimumWidth=s.minimumWidth,this._minimumHeight=s.minimumHeight,this._maximumWidth=s.maximumWidth,this._maximumHeight=s.maximumHeight,this.api=new Zq(this,this._group,r,t,n),this.addDisposables(this.api.onActiveChange(()=>{r.setActivePanel(this)}),this.api.onDidSizeChange(e=>{this.group.api.setSize(e)}),this.api.onDidRendererChange(()=>{this.group.model.rerender(this)}))}init(e){this._params=e.params,this.view.init($($({},e),{},{api:this.api,containerApi:this.containerApi})),this.setTitle(e.title)}focus(){let e=new IK;this.api._onWillFocus.fire(e),e.defaultPrevented||this.api.isActive||this.api.setActive()}toJSON(){return{id:this.id,contentComponent:this.view.contentComponent,tabComponent:this.view.tabComponent,params:Object.keys(this._params||{}).length>0?this._params:void 0,title:this.title,renderer:this._renderer,minimumHeight:this._minimumHeight,maximumHeight:this._maximumHeight,minimumWidth:this._minimumWidth,maximumWidth:this._maximumWidth,pinned:this._pinned?!0:void 0}}setTitle(e){e!==this.title&&(this._title=e,this.view.setTitle(e),this.api._onDidTitleChange.fire({title:e}))}setPinned(e){this._pinned!==e&&(this._pinned=e,this.api._onDidChangePinned.fire({isPinned:e}))}setRenderer(e){e!==this.renderer&&(this._renderer=e,this.api._onDidRendererChange.fire({renderer:e}))}update(e){this._params=$($({},this._params),e.params);for(let t of Object.keys(e.params))e.params[t]===void 0&&delete this._params[t];this.view.update({params:this._params})}updateFromStateModel(e){this._maximumHeight=e.maximumHeight,this._minimumHeight=e.minimumHeight,this._maximumWidth=e.maximumWidth,this._minimumWidth=e.minimumWidth,this._params=e.params??{},this.view.update({params:this._params}),this.setTitle(e.title??this.id),this.setRenderer(e.renderer??this.accessor.renderer),this.setPinned((e.pinned??!1)&&!!this.accessor.options.pinnedTabs?.enabled)}updateParentGroup(e,t){this._group=e,this.api.group=this._group;let n=this._group.model.isPanelActive(this),r=this.group.api.isActive&&n;t?.skipSetActive||this.api.isActive!==r&&this.api._onDidActiveChange.fire({isActive:this.group.api.isActive&&n}),this.api.isVisible!==n&&this.api._onDidVisibilityChange.fire({isVisible:n})}runEvents(){let e=this._group.model.isPanelActive(this),t=this.group.api.isActive&&e;this.api.isActive!==t&&this.api._onDidActiveChange.fire({isActive:this.group.api.isActive&&e}),this.api.isVisible!==e&&this.api._onDidVisibilityChange.fire({isVisible:e})}layout(e,t){this.api._onDidDimensionChange.fire({width:e,height:t}),this.view.layout(e,t)}dispose(){this.api.dispose(),this.view.dispose()}},$q=class extends Y{get element(){return this._element}constructor(){super(),this._messages=ZG,this._element=document.createElement(`div`),this._element.className=`dv-default-tab`,this._content=document.createElement(`div`),this._content.className=`dv-default-tab-content`,this.action=document.createElement(`div`),this.action.className=`dv-default-tab-action`,this.action.setAttribute(`role`,`button`),this.action.setAttribute(`tabindex`,`-1`);let e=qK();e.setAttribute(`aria-hidden`,`true`),this.action.appendChild(e),this._element.appendChild(this._content),this._element.appendChild(this.action),this.render()}init(e){this._title=e.title,this._messages=e.containerApi.messages??ZG,this.addDisposables(e.api.onDidTitleChange(e=>{this._title=e.title,this.render()}),Z(this.action,`pointerdown`,e=>{e.preventDefault()}),Z(this.action,`click`,t=>{t.defaultPrevented||(t.preventDefault(),e.api.close())})),this.render()}render(){this._content.textContent!==this._title&&(this._content.textContent=this._title??``),this.action.setAttribute(`aria-label`,this._title?this._messages.closeTab(this._title):this._messages.closeTabPlain())}},eJ=class{get content(){return this._content}get tab(){return this._tab}constructor(e,t,n,r){this.accessor=e,this.id=t,this.contentComponent=n,this.tabComponent=r,this._content=this.createContentComponent(this.id,n),this._tab=this.createTabComponent(this.id,r)}createTabRenderer(e){let t=this.createTabComponent(this.id,this.tabComponent);if(this._params&&t.init($($({},this._params),{},{tabLocation:e})),this._updateEvent){var n;(n=t.update)==null||n.call(t,this._updateEvent)}return t}init(e){this._params=e,this.content.init(e),this.tab.init($($({},e),{},{tabLocation:`header`}))}setTitle(e){this._params&&(this._params.title=e)}layout(e,t){var n,r;(n=(r=this.content).layout)==null||n.call(r,e,t)}update(e){var t,n,r,i;this._updateEvent=e,(t=(n=this.content).update)==null||t.call(n,e),(r=(i=this.tab).update)==null||r.call(i,e)}dispose(){var e,t,n,r;(e=(t=this.content).dispose)==null||e.call(t),(n=(r=this.tab).dispose)==null||n.call(r)}createContentComponent(e,t){return this.accessor.options.createComponent({id:e,name:t})}createTabComponent(e,t){let n=t??this.accessor.options.defaultTabComponent;if(n){if(this.accessor.options.createTabComponent)return this.accessor.options.createTabComponent({id:e,name:n})||new $q;console.warn(`dockview: tabComponent '${t}' was not found. falling back to the default tab.`)}return new $q}},tJ=class{constructor(e){this.accessor=e}fromJSON(e,t){let n=e.id,r=e.params,i=e.title,a=e.view,o=a?a.content.id:e.contentComponent??`unknown`,s=a?a.tab?.id:e.tabComponent,c=new eJ(this.accessor,n,o,s),l=new Qq(n,o,s,this.accessor,new nK(this.accessor),t,c,{renderer:e.renderer,minimumWidth:e.minimumWidth,minimumHeight:e.minimumHeight,maximumWidth:e.maximumWidth,maximumHeight:e.maximumHeight});return l.init({title:i??n,params:r??{}}),e.pinned&&this.accessor.options.pinnedTabs?.enabled&&l.setPinned(!0),l}},nJ=class extends Y{get element(){return this._element}constructor(){super(),this._element=document.createElement(`div`),this._element.className=`dv-watermark`}init(e){}},rJ=new class{constructor(){this._orderedList=[]}push(e){this._orderedList=[...this._orderedList.filter(t=>t!==e),e],this.update()}destroy(e){this._orderedList=this._orderedList.filter(t=>t!==e),this.update()}update(){for(let e=0;e<this._orderedList.length;e++)this._orderedList[e].setAttribute(`aria-level`,`${e}`),this._orderedList[e].style.zIndex=`calc(var(--dv-overlay-z-index, 999) + ${e*2})`}};function iJ(e){return e.width>0&&e.height>0}var aJ=class e extends Y{set minimumInViewportWidth(e){this.options.minimumInViewportWidth=e}set minimumInViewportHeight(e){this.options.minimumInViewportHeight=e}get element(){return this._element}get isVisible(){return this._isVisible}get headerHeight(){return this.options.header?.offsetHeight??0}constructor(e){super(),this.options=e,this._element=document.createElement(`div`),this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this._onDidChangeEnd=new X,this.onDidChangeEnd=this._onDidChangeEnd.event,this._onDidStartMoving=new X,this.onDidStartMoving=this._onDidStartMoving.event,this._dragMove=new hW,this._dragCancelled=!1,this.addDisposables(this._onDidChange,this._onDidChangeEnd,this._onDidStartMoving,this._dragMove),this._element.className=`dv-resize-container`,this._element.setAttribute(`role`,`dialog`),this._element.setAttribute(`aria-modal`,`false`),this._isVisible=!0,this.setupResize(`top`),this.setupResize(`bottom`),this.setupResize(`left`),this.setupResize(`right`),this.setupResize(`topleft`),this.setupResize(`topright`),this.setupResize(`bottomleft`),this.setupResize(`bottomright`),this.options.header&&(Q(this._element,`dv-resize-container-with-titlebar`,!0),this._element.appendChild(this.options.header)),this._element.appendChild(this.options.content),this.options.container.appendChild(this._element),this.setBounds($($($($({height:this.options.height,width:this.options.width},`top`in this.options&&{top:this.options.top}),`bottom`in this.options&&{bottom:this.options.bottom}),`left`in this.options&&{left:this.options.left}),`right`in this.options&&{right:this.options.right})),rJ.push(this._element)}setVisible(e){e!==this.isVisible&&(this._isVisible=e,Q(this.element,`dv-hidden`,!this.isVisible))}bringToFront(){rJ.push(this._element)}setBounds(e={}){typeof e.height==`number`&&(this._element.style.height=`${e.height}px`),typeof e.width==`number`&&(this._element.style.width=`${e.width}px`),`top`in e&&typeof e.top==`number`&&(this._element.style.top=`${e.top}px`,this._element.style.bottom=`auto`,this.verticalAlignment=`top`),`bottom`in e&&typeof e.bottom==`number`&&(this._element.style.bottom=`${e.bottom}px`,this._element.style.top=`auto`,this.verticalAlignment=`bottom`),`left`in e&&typeof e.left==`number`&&(this._element.style.left=`${e.left}px`,this._element.style.right=`auto`,this.horiziontalAlignment=`left`),`right`in e&&typeof e.right==`number`&&(this._element.style.right=`${e.right}px`,this._element.style.left=`auto`,this.horiziontalAlignment=`right`);let t=this.options.container.getBoundingClientRect(),n=this._element.getBoundingClientRect();if(!iJ(t)||!iJ(n)){this._onDidChange.fire();return}let r=Math.max(0,this.getMinimumWidth(n.width)),i=Math.max(0,this.getMinimumHeight(n.height));if(this.verticalAlignment===`top`){let e=mG(n.top-t.top,-i,Math.max(0,t.height-n.height+i));this._element.style.top=`${e}px`,this._element.style.bottom=`auto`}if(this.verticalAlignment===`bottom`){let e=mG(t.bottom-n.bottom,-i,Math.max(0,t.height-n.height+i));this._element.style.bottom=`${e}px`,this._element.style.top=`auto`}if(this.horiziontalAlignment===`left`){let e=mG(n.left-t.left,-r,Math.max(0,t.width-n.width+r));this._element.style.left=`${e}px`,this._element.style.right=`auto`}if(this.horiziontalAlignment===`right`){let e=mG(t.right-n.right,-r,Math.max(0,t.width-n.width+r));this._element.style.right=`${e}px`,this._element.style.left=`auto`}this._onDidChange.fire()}toJSON(){let e=this.options.container.getBoundingClientRect(),t=this._element.getBoundingClientRect(),n={};return this.verticalAlignment===`top`?n.top=Number.parseFloat(this._element.style.top):this.verticalAlignment===`bottom`?n.bottom=Number.parseFloat(this._element.style.bottom):n.top=t.top-e.top,this.horiziontalAlignment===`left`?n.left=Number.parseFloat(this._element.style.left):this.horiziontalAlignment===`right`?n.right=Number.parseFloat(this._element.style.right):n.left=t.left-e.left,iJ(t)?(n.width=t.width,n.height=t.height):(n.width=Number.parseFloat(this._element.style.width)||0,n.height=Number.parseFloat(this._element.style.height)||0),n}cancelPendingDrag(){this._dragMove.value&&(this._dragCancelled=!0,Q(this._element,`dv-resize-container-dragging`,!1),this._dragMove.value=mW.NONE)}setupDrag(e,t){let n=(e,t)=>{var n;let r=null,i=!1;this._dragCancelled=!1;let a=this.options.transformDragPosition?(n=this.options).getSiblingBoxes?.call(n)??[]:[],o=UW();if(e&&typeof t==`number`&&typeof e.setPointerCapture==`function`)try{e.setPointerCapture(t)}catch{}let s=()=>{Q(this._element,`dv-resize-container-dragging`,!1),this._dragMove.value=mW.NONE,this._onDidChangeEnd.fire()};this._dragMove.value=new Y({dispose:()=>{if(o.release(),e&&typeof t==`number`&&typeof e.releasePointerCapture==`function`)try{e.releasePointerCapture(t)}catch{}}},Z(globalThis.window,`pointermove`,e=>{if(this._dragCancelled)return;let t=this.options.container.getBoundingClientRect(),n=e.clientX-t.left,o=e.clientY-t.top;Q(this._element,`dv-resize-container-dragging`,!0);let s=this._element.getBoundingClientRect();r??={x:e.clientX-s.left,y:e.clientY-s.top};let c=Math.max(0,this.getMinimumWidth(s.width)),l=Math.max(0,this.getMinimumHeight(s.height)),u=o-r.y,d=n-r.x;if(this.options.transformDragPosition){let n=this.options.transformDragPosition({proposed:{top:u,left:d,width:s.width,height:s.height},container:{width:t.width,height:t.height},others:a,modifiers:{altKey:e.altKey,ctrlKey:e.ctrlKey,metaKey:e.metaKey,shiftKey:e.shiftKey}});n&&(u=n.top,d=n.left)}let f=Math.max(0,t.height-s.height+l),p=Math.max(0,t.width-s.width+c),m=mG(u,-l,f),h=mG(t.height-s.height-u,-l,f),g=mG(d,-c,p),_=mG(t.width-s.width-d,-c,p),v={};m<=h?v.top=m:v.bottom=h,g<=_?v.left=g:v.right=_,this.setBounds(v),i||(i=!0,this._onDidStartMoving.fire())}),Z(globalThis.window,`pointerup`,s),Z(globalThis.window,`pointercancel`,s))};this.addDisposables(Z(e,`pointerdown`,t=>{t.defaultPrevented?t.preventDefault():MW(t)||n(e,t.pointerId)}),Z(this.options.content,`pointerdown`,e=>{e.defaultPrevented||MW(e)||e.shiftKey&&n(this.options.content,e.pointerId)}),Z(this.options.content,`pointerdown`,()=>{rJ.push(this._element)},!0)),t?.inDragMode&&n()}setupResize(t){let n=document.createElement(`div`);n.className=`dv-resize-handle-${t}`,this._element.appendChild(n);let r=new hW;this.addDisposables(r,Z(n,`pointerdown`,i=>{i.preventDefault();let a=null,o=UW(),s=i.pointerId;if(typeof n.setPointerCapture==`function`)try{n.setPointerCapture(s)}catch{}let c=()=>{r.dispose(),this._onDidChangeEnd.fire()};r.value=new Y(Z(globalThis.window,`pointermove`,n=>{let r=this.options.container.getBoundingClientRect(),i=this._element.getBoundingClientRect(),o=n.clientY-r.top,s=n.clientX-r.left;a??={originalY:o,originalHeight:i.height,originalX:s,originalWidth:i.width};let c,l,u,d,f,p,m=()=>{let t=a.originalY+a.originalHeight>r.height?Math.max(0,r.height-e.MINIMUM_HEIGHT):Math.max(0,a.originalY+a.originalHeight-e.MINIMUM_HEIGHT);c=mG(o,0,t),u=a.originalY+a.originalHeight-c,l=r.height-c-u},h=()=>{c=a.originalY-a.originalHeight;let t=c<0&&typeof this.options.minimumInViewportHeight==`number`?-c+this.options.minimumInViewportHeight:e.MINIMUM_HEIGHT,n=r.height-Math.max(0,c);u=mG(o-c,t,n),l=r.height-c-u},g=()=>{let t=a.originalX+a.originalWidth>r.width?Math.max(0,r.width-e.MINIMUM_WIDTH):Math.max(0,a.originalX+a.originalWidth-e.MINIMUM_WIDTH);d=mG(s,0,t),p=a.originalX+a.originalWidth-d,f=r.width-d-p},_=()=>{d=a.originalX-a.originalWidth;let t=d<0&&typeof this.options.minimumInViewportWidth==`number`?-d+this.options.minimumInViewportWidth:e.MINIMUM_WIDTH,n=r.width-Math.max(0,d);p=mG(s-d,t,n),f=r.width-d-p};switch(t){case`top`:m();break;case`bottom`:h();break;case`left`:g();break;case`right`:_();break;case`topleft`:m(),g();break;case`topright`:m(),_();break;case`bottomleft`:h(),g();break;case`bottomright`:h(),_()}let v={};c<=l?v.top=c:v.bottom=l,d<=f?v.left=d:v.right=f,v.height=u,v.width=p,this.setBounds(v)}),{dispose:()=>{if(o.release(),typeof n.releasePointerCapture==`function`)try{n.releasePointerCapture(s)}catch{}}},Z(globalThis.window,`pointerup`,c),Z(globalThis.window,`pointercancel`,c))}))}getMinimumWidth(e){return typeof this.options.minimumInViewportWidth==`number`?e-this.options.minimumInViewportWidth:0}getMinimumHeight(e){return typeof this.options.minimumInViewportHeight==`number`?e-this.options.minimumInViewportHeight:0}dispose(){rJ.destroy(this._element),this._element.remove(),super.dispose()}};aJ.MINIMUM_HEIGHT=20,aJ.MINIMUM_WIDTH=20;var oJ=class extends Y{get element(){return this._element}get group(){return this._group}setGroup(e){this._group=e}constructor(e,t){super(),this.accessor=e,this._onDragStart=new X,this.onDragStart=this._onDragStart.event,this._group=t,this._element=document.createElement(`div`),this._element.className=`dv-floating-titlebar`,this.addDisposables(this._onDragStart,Z(this._element,`pointerdown`,()=>{this.accessor.doSetGroupActive(this._group)}),Z(this._element,`pointerdown`,e=>{e.shiftKey&&jW(e)},!0)),this.dragSource=new oq({element:this._element,accessor:this.accessor,group:()=>this._group}),this.addDisposables(this.dragSource,this.dragSource.onDragStart(e=>{this._onDragStart.fire(e)}))}updateDragAndDropState(){this.dragSource.updateDragAndDropState()}};function sJ(e){return{moduleName:e.name,options:e.options,services:{[e.serviceKey]:e.create},init:e.init?(t,n)=>e.init(t,n[e.serviceKey]):void 0,dependsOn:e.dependsOn}}var cJ=new Set([`AdvancedOverflow`,`AutoEdgeGroup`,`AutoHideEdgeGroup`,`DndCompass`,`KeyboardDocking`,`KeyboardNavigation`,`LayoutHistory`,`License`,`MultiRowTabs`,`PinnedTabs`,`SmartGuides`]),lJ=new Set;function uJ(e,t){let n=t===void 0?[]:[].concat(t),r=n.map(e=>`\`${e}\``).join(`, `),i=n.length>1?`require`:`requires`,a=n.length?`${r} ${i} the "${e}" module`:`The "${e}" module is required`;return cJ.has(e)?`dockview: ${a}, which ships in dockview-enterprise.\n\n npm install dockview-enterprise\n import 'dockview-enterprise'; // self-registers every enterprise module\n`:`dockview: ${a}, but it is not registered.`}function dJ(e,t){let n=`${e}|${(t===void 0?[]:[].concat(t)).join(`|`)}`;lJ.has(n)||(lJ.add(n),console.error(uJ(e,t)))}function fJ(e,t,n){if(e!==void 0)return e;dJ(t,n)}var pJ=class{constructor(){this._modules=new Map,this._services={},this._initDisposables=[]}get services(){return this._services}register(e){if(!this._modules.has(e.moduleName)){if(e.dependsOn)for(let t of e.dependsOn)this.register(t);this._modules.set(e.moduleName,e)}}initialize(e){for(let t of this._modules.values())if(t.services)for(let[n,r]of Object.entries(t.services))this._services[n]=r(e)}postConstruct(e){for(let t of this._modules.values())t.init&&this._initDisposables.push(t.init(e,this._services))}has(e){return this._modules.has(e)}dispose(){for(let e of this._initDisposables)e.dispose();this._initDisposables.length=0;for(let e of Object.values(this._services))e!==void 0&&typeof e.dispose==`function`&&e.dispose()}},mJ=[];function hJ(){return[...mJ]}var gJ=[{optionKey:`smartGuides`,reason:`smartGuides`,moduleName:`SmartGuides`,when:e=>!!e.smartGuides&&e.smartGuides.enabled!==!1},{optionKey:`layoutHistory`,reason:`layoutHistory.enabled: true`,moduleName:`LayoutHistory`,when:e=>e.layoutHistory?.enabled===!0},{optionKey:`pinnedTabs`,reason:`pinnedTabs.enabled: true`,moduleName:`PinnedTabs`,when:e=>e.pinnedTabs?.enabled===!0},{optionKey:`overflow`,reason:`overflow.mode: 'wrap'`,moduleName:`MultiRowTabs`,when:e=>e.overflow?.mode===`wrap`},{optionKey:`overflow`,reason:`overflow.maxRows`,moduleName:`MultiRowTabs`,when:e=>e.overflow?.maxRows!=null},{optionKey:`overflow`,reason:`overflow.search`,moduleName:`AdvancedOverflow`,when:e=>!!e.overflow?.search},{optionKey:`overflow`,reason:`overflow.mru`,moduleName:`AdvancedOverflow`,when:e=>!!e.overflow?.mru},{optionKey:`autoHideEdgeGroups`,reason:`autoHideEdgeGroups`,moduleName:`AutoHideEdgeGroup`,when:e=>dq(e.autoHideEdgeGroups)},{optionKey:`dockToEdgeGroups`,reason:`dockToEdgeGroups`,moduleName:`AutoEdgeGroup`,when:e=>dq(e.dockToEdgeGroups)},{optionKey:`dndCompass`,reason:`dndCompass`,moduleName:`DndCompass`,when:e=>!!e.dndCompass},{optionKey:`keyboardNavigation`,reason:`keyboardNavigation`,moduleName:`KeyboardNavigation`,when:e=>!!e.keyboardNavigation}];function _J(e,t){let n=new Map;for(let r of gJ){if(!r.when(e)||t(r.moduleName))continue;let i=n.get(r.moduleName);i?i.push(r.reason):n.set(r.moduleName,[r.reason])}for(let[e,t]of n)dJ(e,t)}var vJ={left:100,top:100,width:300,height:300},yJ=class extends Y{get group(){return this._group}setTitleBar(e){this._titleBar=e}setAnchorGroup(e){var t;this._group=e,(t=this._titleBar)==null||t.setGroup(e),this._onDidChangeAnchorGroup.fire(e)}constructor(e,t,n){super(),this.overlay=t,this.gridview=n,this._onDidChangeAnchorGroup=new X,this.onDidChangeAnchorGroup=this._onDidChangeAnchorGroup.event,this._group=e,this.addDisposables(this._onDidChangeAnchorGroup,t,{dispose:()=>this.gridview.dispose()})}position(e){this.overlay.setBounds(e)}},bJ=class{get floatingGroups(){return this._floatingGroups}constructor(e){this._floatingGroups=[],this._host=e}add(e,t,n){let r=new yJ(e,t,n),i=new Y((()=>{let e=-1,t=-1;return wW(n.element,r=>{let i=Math.round(r.contentRect.width),a=Math.round(r.contentRect.height);(i!==e||a!==t)&&(e=i,t=a,n.layout(i,a))})})()),a=e=>{let n=e.activePanel?.title;n?t.element.setAttribute(`aria-label`,n):t.element.removeAttribute(`aria-label`)},o=new hW,s=e=>{a(e),o.value=new Y(e.api.onDidActiveChange(e=>{e.isActive&&t.bringToFront()}),e.api.onDidActivePanelChange(()=>a(e)),e.onDidChange(e=>{t.setBounds({height:typeof e?.height==`number`?e.height+t.headerHeight:e?.height,width:e?.width})}))};return s(e),r.addDisposables(o,r.onDidChangeAnchorGroup(e=>s(e)),t.onDidChange(()=>{n.layout(n.width,n.height)}),t.onDidChangeEnd(()=>{this._host.fireLayoutChange(`geometry`)}),{dispose:()=>{i.dispose(),pG(this._floatingGroups,r),e.model.location={type:`grid`}}}),this._floatingGroups.push(r),r}findByGroup(e){return this._floatingGroups.find(t=>t.group===e||t.gridview.element.contains(e.element))}serialize(){return this._floatingGroups.map(e=>{let t=e.gridview.serialize(),n=e.overlay.toJSON(),r=t.root;return r.type===`branch`&&r.data.length===1&&r.data[0].type===`leaf`?{data:r.data[0].data,position:n}:{grid:t,position:n}})}constrainBounds(){for(let e of this._floatingGroups)e.overlay.setBounds()}updateBounds(e){if(`floatingGroupBounds`in e)for(let t of this._floatingGroups){switch(e.floatingGroupBounds){case`boundedWithinViewport`:t.overlay.minimumInViewportHeight=void 0,t.overlay.minimumInViewportWidth=void 0;break;case void 0:t.overlay.minimumInViewportHeight=100,t.overlay.minimumInViewportWidth=100;break;default:t.overlay.minimumInViewportHeight=e.floatingGroupBounds?.minimumHeightWithinViewport,t.overlay.minimumInViewportWidth=e.floatingGroupBounds?.minimumWidthWithinViewport}t.overlay.setBounds()}}disposeAll(){for(let e of[...this._floatingGroups])e.dispose()}dispose(){this.disposeAll()}},xJ=sJ({name:`FloatingGroup`,serviceKey:`floatingGroupService`,create:e=>new bJ(e)}),SJ=class{constructor(e){this._entries=[],this._restorationCleanups=new Set,this._restorationPromise=Promise.resolve(),this._onDidRemove=new X,this.onDidRemove=this._onDidRemove.event,this._host=e}get entries(){return this._entries}get restorationPromise(){return this._restorationPromise}add(e){this._entries.push(e)}remove(e){pG(this._entries,e)&&!this._host.isDisposed&&this._onDidRemove.fire(e)}findByGroup(e){return this._entries.find(t=>t.popoutGroup===e||t.gridview.element.contains(e.element))}findReferenceGroupId(e){return this._entries.find(t=>t.popoutGroup===e)?.referenceGroup}observeGridviewSize(e,t,n){let r=e.window?.ResizeObserver;if(!r)return;let i=-1,a=-1,o=()=>{let r=e.window;if(this._host.isDisposed||!r||r.closed)return;let o=Math.round(t.element.clientWidth),s=Math.round(t.element.clientHeight);(o!==i||s!==a)&&(i=o,a=s,o>0&&s>0&&t.layout(o,s),n.updateAllPositions())},s=new r(()=>{let t=e.window?.requestAnimationFrame;t?t.call(e.window,o):o()});return s.observe(t.element),{dispose:()=>s.disconnect()}}scheduleRestoration(e,t,n){return new Promise(r=>{let i=()=>{this._restorationCleanups.delete(i),clearTimeout(a),n?.(),r()},a=setTimeout(()=>{this._restorationCleanups.delete(i),this._host.isDisposed?r():Promise.resolve(t()).then(()=>r(),()=>r())},e);this._restorationCleanups.add(i)})}finishRestoration(e){this._restorationPromise=Promise.all(e).then(()=>void 0)}cancelPendingRestorations(){for(let e of[...this._restorationCleanups])e();this._restorationCleanups.clear()}serialize(){return this._entries.map(e=>{let t=e.gridview.serialize(),n=t.root,r=e.popoutGroup.api.location.type===`popout`?e.popoutGroup.api.location.popoutUrl:void 0,i={gridReferenceGroup:e.referenceGroup,position:e.window.dimensions(),url:r};return n.type===`branch`&&n.data.length===1&&n.data[0].type===`leaf`?$($({},i),{},{data:n.data[0].data}):$($({},i),{},{grid:t})})}disposeAll(){for(let e of[...this._entries])e.disposable.dispose()}dispose(){this.cancelPendingRestorations(),this.disposeAll(),this._onDidRemove.dispose()}},CJ=sJ({name:`PopoutWindow`,serviceKey:`popoutWindowService`,create:e=>new SJ(e)}),wJ=class{constructor(e){this._watermark=null,this._host=e}update(){if(this._host.hasVisibleGridGroup()){this._unmount();return}if(this._watermark)return;this._watermark=this._host.createWatermarkComponent(),this._watermark.init({containerApi:this._host.api});let e=document.createElement(`div`);e.className=`dv-watermark-container`,VW(e,`watermark-component`),e.appendChild(this._watermark.element),this._host.mountElement.appendChild(e)}refresh(){this._unmount(),this.update()}_unmount(){var e,t;this._watermark&&=(this._watermark.element.parentElement.remove(),(e=(t=this._watermark).dispose)==null||e.call(t),null)}dispose(){this._unmount()}},TJ=sJ({name:`Watermark`,serviceKey:`watermarkService`,create:e=>new wJ(e),init:(e,t)=>(t.update(),new Y(gW.any(e.onDidAdd,e.onDidRemove)(()=>{t.update()}),e.onDidViewVisibilityChangeMicroTaskQueue(()=>{t.update()})))}),EJ=class{constructor(){this._edgeGroups=new Map,this._edgeGroupDisposables=new Map,this._autoHide=new WeakMap,this._autoReveal=new WeakMap}add(e,t,n){this._edgeGroups.set(e,t),this._edgeGroupDisposables.set(e,n)}remove(e){var t;(t=this._edgeGroupDisposables.get(e))==null||t.dispose(),this._edgeGroupDisposables.delete(e),this._edgeGroups.delete(e)}get(e){return this._edgeGroups.get(e)}has(e){return this._edgeGroups.has(e)}hasAny(){return this._edgeGroups.size>0}entries(){return this._edgeGroups.entries()}includes(e){for(let t of this._edgeGroups.values())if(t===e)return!0;return!1}findPositionOf(e){for(let[t,n]of this._edgeGroups)if(n===e)return t}setAutoHide(e,t){t===void 0?this._autoHide.delete(e):this._autoHide.set(e,t)}isAutoHide(e){return this._autoHide.get(e)}setAutoReveal(e,t){this._autoReveal.set(e,t)}isAutoReveal(e){return this._autoReveal.get(e)??!1}disposeAll(){for(let e of this._edgeGroupDisposables.values())e.dispose();this._edgeGroupDisposables.clear(),this._edgeGroups.clear()}dispose(){this.disposeAll()}},DJ=sJ({name:`EdgeGroup`,serviceKey:`edgeGroupService`,create:()=>new EJ}),OJ={activationSize:{type:`pixels`,value:10},size:{type:`pixels`,value:20}},kJ={activationSize:{type:`pixels`,value:32},size:{type:`pixels`,value:20}};function AJ(e,t){return typeof e.dndEdges==`object`&&e.dndEdges!==null?e.dndEdges:t&&dq(e.dockToEdgeGroups)?kJ:OJ}var jJ=class{constructor(e){this._host=e;let t=(t,n)=>{let r=fW();return r?r.viewId===e.id?n!==`center`||e.isGridEmpty():!1:n===`center`&&!e.isGridEmpty()?!1:e.dispatchUnhandledDragOver(t,n)},n=AJ(e.options,!1);this._html5Target=MK.createDropTarget(e.element,{className:`dv-drop-target-edge`,canDisplayOverlay:t,acceptedTargetZones:[`top`,`bottom`,`left`,`right`,`center`],overlayModel:n,getOverrideTarget:()=>e.rootDropTargetOverrideTarget(),getPositionResolver:()=>e.options.dropPositionResolver}),this._pointerTarget=NK.createDropTarget(e.element,{className:`dv-drop-target-edge`,canDisplayOverlay:t,acceptedTargetZones:[`top`,`bottom`,`left`,`right`,`center`],overlayModel:n,getOverrideTarget:()=>e.rootDropTargetOverrideTarget(),getPositionResolver:()=>e.options.dropPositionResolver}),this.onWillShowOverlay=gW.any(this._html5Target.onWillShowOverlay,this._pointerTarget.onWillShowOverlay),this.onDrop=gW.any(this._html5Target.onDrop,this._pointerTarget.onDrop),this.setOptions(e.options)}setOptions(e){if(`dndEdges`in e){let t=typeof e.dndEdges==`boolean`&&e.dndEdges===!1;this._html5Target.disabled=t,this._pointerTarget.disabled=t}if(`dndEdges`in e||`dockToEdgeGroups`in e){let t=AJ({dndEdges:`dndEdges`in e?e.dndEdges:this._host.options.dndEdges,dockToEdgeGroups:`dockToEdgeGroups`in e?e.dockToEdgeGroups:this._host.options.dockToEdgeGroups},this._host.hasEdgeDragReveal);this._html5Target.setOverlayModel(t),this._pointerTarget.setOverlayModel(t)}}dispose(){this._html5Target.dispose(),this._pointerTarget.dispose()}},MJ=sJ({name:`RootDropTarget`,serviceKey:`rootDropTargetService`,create:e=>new jJ(e),init:(e,t)=>(t.setOptions(e.options),mW.NONE)}),NJ={left:`createLeftHeaderActionComponent`,right:`createRightHeaderActionComponent`,prefix:`createPrefixHeaderActionComponent`},PJ=class{constructor(e){this._perGroup=new Map,this._host=e}refresh(e){if(!e?.model)return;let t=this._ensureState(e);this._refreshSlot(`left`,e,t.left),this._refreshSlot(`right`,e,t.right),this._refreshSlot(`prefix`,e,t.prefix)}refreshAll(){for(let e of this._host.groups)this.refresh(e)}disposeGroup(e){let t=this._perGroup.get(e);t&&(t.left.dispose(),t.right.dispose(),t.prefix.dispose(),this._perGroup.delete(e))}dispose(){for(let e of[...this._perGroup.keys()])this.disposeGroup(e)}_ensureState(e){let t=this._perGroup.get(e);return t||(t={left:new hW,right:new hW,prefix:new hW},this._perGroup.set(e,t)),t}_refreshSlot(e,t,n){let r=this._host.options[NJ[e]];if(r){let i=r(t);n.value=i,i.init({containerApi:this._host.api,api:t.api,group:t}),t.model.attachHeaderAction(e,i.element)}else n.dispose(),t.model.attachHeaderAction(e,void 0)}},FJ=sJ({name:`HeaderActions`,serviceKey:`headerActionsService`,create:e=>new PJ(e),init:(e,t)=>new Y(e.onDidRemoveGroup(e=>{t.disposeGroup(e)}))}),IJ=e=>e===`load`||e===`clear`;function LJ(e,t){let n=e.createElement(`div`);return n.className=t===`assertive`?`dv-live-region-assertive`:`dv-live-region`,n.setAttribute(`role`,t===`assertive`?`alert`:`status`),n.setAttribute(`aria-live`,t),n.setAttribute(`aria-atomic`,`true`),Object.assign(n.style,{position:`absolute`,width:`1px`,height:`1px`,margin:`-1px`,padding:`0`,overflow:`hidden`,clip:`rect(0 0 0 0)`,clipPath:`inset(50%)`,whiteSpace:`nowrap`,border:`0`}),n}var RJ=class extends Y{constructor(e){super(),this._regions=new Map,this._suppressDepth=0,this._locationSubs=new Map,this._host=e;let t=e.element.ownerDocument;this._mainWindow=t.defaultView??window;let n={polite:LJ(t,`polite`),assertive:LJ(t,`assertive`)};e.element.appendChild(n.polite),e.element.appendChild(n.assertive),this._regions.set(this._mainWindow,n),this._syncPopoutRegions(),this.addDisposables({dispose:()=>this._disposeRegions()},e.onDidChangePopouts(()=>this._syncPopoutRegions()),e.onDidAddPanel(e=>this._announce(e,`open`)),e.onDidRemovePanel(e=>this._announce(e,`close`)),e.onWillMutateLayout(e=>{IJ(e.kind)&&this._suppressDepth++}),e.onDidMutateLayout(e=>{IJ(e.kind)&&(this._suppressDepth=Math.max(0,this._suppressDepth-1))}),e.onDidMaximizedGroupChange(e=>{let t=e.group.activePanel;t&&this._announce(t,e.isMaximized?`maximize`:`restore`)}),e.onDidAddGroup(e=>this._trackLocation(e)),e.onDidRemoveGroup(e=>{var t;(t=this._locationSubs.get(e.id))==null||t.dispose(),this._locationSubs.delete(e.id)}),{dispose:()=>{this._locationSubs.forEach(e=>e.dispose()),this._locationSubs.clear()}})}_syncPopoutRegions(){let e=this._host.element.ownerDocument,t=new Set([this._mainWindow]);for(let n of this._host.getPopoutWindows()){if(n.document===e||(t.add(n),this._regions.has(n)))continue;let r=n.document,i=r.body??r.documentElement,a={polite:LJ(r,`polite`),assertive:LJ(r,`assertive`)};i.appendChild(a.polite),i.appendChild(a.assertive),this._regions.set(n,a)}for(let[e,n]of this._regions)t.has(e)||(n.polite.remove(),n.assertive.remove(),this._regions.delete(e))}_disposeRegions(){for(let e of this._regions.values())e.polite.remove(),e.assertive.remove();this._regions.clear()}_focusedRegions(){for(let[e,t]of this._regions)if(e!==this._mainWindow)try{if(e.document.hasFocus())return t}catch{}return this._regions.get(this._mainWindow)}_trackLocation(e){let t=e.api.location.type,n=e.api.onDidLocationChange(n=>{let r=n.location.type;if(r===t)return;t=r;let i=e.activePanel;if(!i)return;let a;switch(r){case`floating`:a=`float`;break;case`popout`:a=`popout`;break;default:a=`dock`}this._announce(i,a)});this._locationSubs.set(e.id,n)}announce(e,t=`polite`){if(this._host.options.announcements===!1||this._suppressDepth>0||!e)return;let n=this._host.options.announcer;if(n){n({message:e,politeness:t});return}let r=this._focusedRegions(),i=t===`assertive`?r.assertive:r.polite;i.textContent=``,i.textContent=e}_announce(e,t){var n;let r=(n=this._host.options).getAnnouncement?.call(n,{kind:t,panel:e});r!==null&&r!==``&&this.announce(r??this._defaultMessage(e,t))}_defaultMessage(e,t){let n=QG(this._host.options.messages),r=e.title??e.id;switch(t){case`open`:return n.panelOpened(r);case`close`:return n.panelClosed(r);case`maximize`:return n.groupMaximized(r);case`restore`:return n.groupRestored(r);case`float`:return n.groupFloated(r);case`dock`:return n.groupDocked(r);case`popout`:return n.groupPoppedOut(r)}}},zJ=sJ({name:`LiveRegion`,serviceKey:`liveRegionService`,create:e=>new RJ(e)}),BJ=30,VJ=-10,HJ=class{constructor(e){this.host=e}dispatchWillDragPanel(e){this.host.fireWillDragPanel(e)}dispatchWillDragGroup(e){this.host.fireWillDragGroup(e)}dispatchWillDrop(e){this.host.fireWillDrop(e)}dispatchWillShowOverlay(e){this.host.fireWillShowOverlay(e)}buildGroupDragGhost(e){let t=this.host.options.createGroupDragGhostComponent;if(!t)return;let n=t(e);return n.init({group:e,api:this.host.api}),{element:n.element,offsetX:BJ,offsetY:VJ,dispose:n.dispose?()=>n.dispose?.call(n):void 0}}resolveOverlayModel(e,t){var n;return(n=this.host.options).dropOverlayModel?.call(n,{location:e,group:t})}showPreviewOverlay(e,t){let n=e.model.contentDropTarget;return n.showOverlay(t),mW.from(()=>n.clearOverlay())}dispose(){}},UJ=sJ({name:`AdvancedDnD`,serviceKey:`advancedDnDService`,create:e=>new HJ(e)}),WJ=class{constructor(e){this._host=e}attachToGroup(e){return new Y(e.model.onDidCreateTabGroup(e=>{this._host.fireDidCreateTabGroup(e)}),e.model.onDidDestroyTabGroup(e=>{this._host.fireDidDestroyTabGroup(e)}),e.model.onDidAddPanelToTabGroup(e=>{this._host.fireDidAddPanelToTabGroup(e)}),e.model.onDidRemovePanelFromTabGroup(e=>{this._host.fireDidRemovePanelFromTabGroup(e)}),e.model.onDidTabGroupChange(e=>{this._host.fireDidTabGroupChange(e)}),e.model.onDidTabGroupCollapsedChange(e=>{this._host.fireDidTabGroupCollapsedChange(e)}))}dispose(){}},GJ=sJ({name:`TabGroupChips`,serviceKey:`tabGroupChipsService`,create:e=>new WJ(e),init:(e,t)=>{let n=new Map;return new Y(e.onDidAddGroup(e=>{n.set(e,t.attachToGroup(e))}),e.onDidRemoveGroup(e=>{var t;(t=n.get(e))==null||t.dispose(),n.delete(e)}),{dispose:()=>{for(let e of n.values())e.dispose();n.clear()}})}});function KJ(e,t){var n,r;if((n=t.api)!=null&&(r=n.isPeeking)!=null&&r.call(n))return`calc(var(--dv-overlay-z-index, 999) + 100)`;if(!(e instanceof HTMLElement))return;let i=QW(e);return i?.style.zIndex?`calc(${i.style.zIndex} * 2)`:void 0}var qJ=0,JJ=()=>`dv-ctx-menu-item-${qJ++}`;function YJ(e){return typeof e==`object`}function XJ(e,t,n,r){let i=document.createElement(`div`);return i.className=`dv-context-menu-item`,i.setAttribute(`role`,`menuitem`),r&&(i.classList.add(`dv-context-menu-item--disabled`),i.setAttribute(`aria-disabled`,`true`)),i.textContent=e,r||i.addEventListener(`click`,()=>{n(),t()}),i}function ZJ(){let e=document.createElement(`div`);return e.className=`dv-context-menu-separator`,e.setAttribute(`role`,`separator`),e}function QJ(){if(globalThis.window===void 0||!globalThis.matchMedia)return!1;let e=globalThis.matchMedia(`(pointer: coarse)`).matches,t=globalThis.matchMedia(`(pointer: fine)`).matches;return e&&!t}function $J(e){let t=document.createElement(`div`);t.className=`dv-context-menu-rename`;let n=document.createElement(`input`);return n.className=`dv-context-menu-rename-input`,n.type=`text`,n.placeholder=`Name This Group`,n.value=e.label,n.addEventListener(`input`,()=>{e.setLabel(n.value)}),n.addEventListener(`keydown`,e=>{e.key!==`Escape`&&e.key!==`Enter`&&e.stopPropagation()}),n.addEventListener(`click`,e=>{e.stopPropagation()}),t.appendChild(n),QJ()||requestAnimationFrame(()=>{n.focus(),n.select()}),t}function eY(e,t){let n=document.createElement(`div`);if(n.className=`dv-context-menu-color-picker`,!t.enabled)return n;for(let r of t.entries()){let t=document.createElement(`div`);t.className=`dv-context-menu-color-swatch`,t.style.setProperty(`--dv-tab-group-color`,r.value),r.label&&(t.title=r.label),e.color===r.id&&t.classList.add(`dv-context-menu-color-swatch--selected`),t.addEventListener(`click`,()=>{e.setColor(r.id)}),n.appendChild(t)}return n}var tY=class{constructor(e){this.accessor=e}buildMaximizeItem(e,t){let n=e.api.isMaximized();return XJ(n?`Restore`:`Maximize`,t,n?()=>e.api.exitMaximized():()=>e.api.maximize(),!n&&e.api.location.type!==`grid`)}buildCollapseItem(e,t){return XJ(e.collapsed?`Expand`:`Collapse`,t,()=>e.toggle())}_shouldInjectPin(){let e=this.accessor.options.pinnedTabs;return!!this.accessor.pinnedTabsService&&!!e?.enabled&&e.contextMenuItem!==!1}_resolveTabItems(e,t,n){var r;let i=(r=this.accessor.options).getTabContextMenuItems?.call(r,{panel:e,group:t,api:this.accessor.api,event:n})??[];return this._shouldInjectPin()?[`pin`,...i]:i}appendComponentItem(e,t,n,r,i,a){var o;let s=(o=this.accessor.options).createContextMenuItemComponent?.call(o,{id:JJ(),component:t.component});s&&(a.addDisposables(s),s.init($($({},n),{},{group:r,api:this.accessor.api,close:i,componentProps:t.componentProps})),e.appendChild(s.element))}buildBuiltInTabItem(e,t,n,r){switch(e){case`separator`:return ZJ();case`close`:return XJ(`Close`,r,()=>t.api.close());case`closeOthers`:return XJ(`Close Others`,r,()=>{n.panels.filter(e=>e!==t).forEach(e=>e.api.close())});case`closeAll`:return XJ(`Close All`,r,()=>{[...n.panels].forEach(e=>e.api.close())});case`closeLeft`:{let e=n.panels.indexOf(t);return XJ(`Close to the Left`,r,()=>{n.panels.filter((t,n)=>n<e).forEach(e=>e.api.close())},e<=0)}case`closeRight`:{let e=n.panels.indexOf(t);return XJ(`Close to the Right`,r,()=>{n.panels.filter((t,n)=>n>e).forEach(e=>e.api.close())},e===-1||e>=n.panels.length-1)}case`maximize`:return this.buildMaximizeItem(t,r);case`float`:return XJ(`Float`,r,()=>this.accessor.api.addFloatingGroup(t),t.api.location.type===`floating`);case`popout`:return XJ(`Open in New Window`,r,()=>{this.accessor.api.addPopoutGroup(t)},t.api.location.type===`popout`);case`pin`:return XJ(t.api.isPinned?`Unpin tab`:`Pin tab`,r,()=>t.api.setPinned(!t.api.isPinned));default:return}}appendConfigItem(e,t,n,r,i,a){t.element?e.appendChild(t.element):t.component?this.appendComponentItem(e,t,n,r,i,a):t.label&&e.appendChild(XJ(t.label,i,()=>t.action?.call(t),t.disabled))}show(e,t,n){let r=this._resolveTabItems(e,t,n);if(r.length===0)return;n.preventDefault();let i=this.accessor.getPopupServiceForGroup(t),a=()=>i.close(),o=new Y,s=document.createElement(`div`);s.className=`dv-context-menu`,s.setAttribute(`role`,`menu`);try{for(let n of r){if(YJ(n)){this.appendConfigItem(s,n,{panel:e},t,a,o);continue}let r=this.buildBuiltInTabItem(n,e,t,a);r&&s.appendChild(r)}}catch(e){throw o.dispose(),e}i.openPopover(s,{x:n.clientX,y:n.clientY,zIndex:KJ(n.target,t)},{onClose:()=>o.dispose()})}showForChip(e,t,n){if(!this.accessor.options.getTabGroupChipContextMenuItems)return;let r=this.accessor.options.getTabGroupChipContextMenuItems({tabGroup:e,group:t,api:this.accessor.api,event:n});if(r.length===0)return;n.preventDefault();let i=this.accessor.getPopupServiceForGroup(t),a=()=>i.close(),o=new Y,s=document.createElement(`div`);s.className=`dv-context-menu`,s.setAttribute(`role`,`menu`);try{for(let n of r)n===`separator`?s.appendChild(ZJ()):n===`rename`?s.appendChild($J(e)):n===`colorPicker`?s.appendChild(eY(e,this.accessor.tabGroupColorPalette)):n===`collapse`?s.appendChild(this.buildCollapseItem(e,a)):n===`close`?s.appendChild(XJ(`Close All`,a,()=>{t.panels.filter(t=>e.containsPanel(t.id)).forEach(e=>e.api.close())})):YJ(n)&&this.appendConfigItem(s,n,{tabGroup:e},t,a,o)}catch(e){throw o.dispose(),e}i.openPopover(s,{x:n.clientX,y:n.clientY,zIndex:KJ(n.target,t)},{onClose:()=>o.dispose()})}},nY=[xJ,CJ,TJ,DJ,MJ,FJ,zJ,UJ,GJ,sJ({name:`ContextMenu`,serviceKey:`contextMenuService`,create:e=>new tY(e)})],rY=class{constructor(){this.cache=new WeakMap,this.currentFrameId=0,this.rafId=null}getPosition(e){let t=this.cache.get(e);if(t?.frameId===this.currentFrameId)return t.rect;this.scheduleFrameUpdate();let n=LW(e);return this.cache.set(e,{rect:n,frameId:this.currentFrameId}),n}invalidate(){this.currentFrameId++}scheduleFrameUpdate(){this.rafId||=requestAnimationFrame(()=>{this.currentFrameId++,this.rafId=null})}},iY=-1;function aY(e){let t=e.group.api;return t.location.type===`edge`&&t.isCollapsed()}function oY(){let e=document.createElement(`div`);return e.tabIndex=-1,e}function sY(e,t,n){let r=`${n}px`;e[t]!==r&&(e[t]=r)}var cY=class extends Y{constructor(e,t){super(),this.element=e,this.accessor=t,this.map={},this._disposed=!1,this._generation=0,this.positionCache=new rY,this.addDisposables(mW.from(()=>{for(let e of Object.values(this.map))e.disposable.dispose(),e.destroy.dispose(),this.cancelPendingUpdate(e);this._disposed=!0}))}updateAllPositions(){if(!this._disposed){this.positionCache.invalidate();for(let e of Object.values(this.map))e.panel.api.isVisible&&e.resize&&e.resize()}}repositionPanelOverlay(e,t=!1,n){var r;if(this._disposed)return;let i=this.map[e];i&&(i.forceVisible=t,i.clip=n,this.positionCache.invalidate(),(r=i.resize)==null||r.call(i))}cancelPendingUpdate(e){e.pendingUpdate!==void 0&&(cancelAnimationFrame(e.pendingUpdate),e.pendingUpdate=void 0)}detatch(e){if(this.map[e.api.id]){let t=this.map[e.api.id];return t.disposable.dispose(),t.destroy.dispose(),this.cancelPendingUpdate(t),delete this.map[e.api.id],!0}return!1}attach(e){var t;let{panel:n,referenceContainer:r}=e;if(!this.map[n.api.id]){let e=oY();e.className=`dv-render-overlay`,e.style.visibility=`hidden`,this.map[n.api.id]={panel:n,disposable:mW.NONE,destroy:mW.NONE,element:e,retainPreviousGeometry:!1,positioned:!1,generation:++this._generation}}let i=this.map[n.api.id];if(i.referenceContainer!==r){i.generation=++this._generation,this.cancelPendingUpdate(i),i.referenceContainer=r;let e=aY(n);i.retainPreviousGeometry=i.positioned&&!e,e&&!i.forceVisible&&(i.element.style.visibility=`hidden`,i.element.style.pointerEvents=`none`)}let a=i.generation,o=i.element,s=n.view.content.element,c=e=>{if(!e||e.width<=0||e.height<=0)return;let t=this.map[n.api.id];!t||t.forceVisible||t.positioned&&n.api.isVisible||(sY(o.style,`width`,e.width),sY(o.style,`height`,e.height))};c(r.dimensions),s.parentElement!==o&&o.appendChild(s),o.parentElement!==this.element&&this.element.appendChild(o);let l=()=>{let e=n.api.id,t=this.map[e];if(t?.generation!==a||t.pendingUpdate!==void 0)return;t.pendingUpdate=iY;let i=requestAnimationFrame(()=>{let t=this.map[e];if(t&&(t.pendingUpdate=void 0),this.isDisposed||t?.generation!==a)return;let i=t.forceVisible??!1,s=t.clip,c=aY(n),l=!i&&(!n.api.isVisible||c),u=this.positionCache.getPosition(r.element),d=this.positionCache.getPosition(this.element),f=u.left-d.left,p=u.top-d.top,m=u.width,h=u.height;if(m===0||h===0){if(c&&!i){t.retainPreviousGeometry=!1,o.style.visibility=`hidden`,o.style.pointerEvents=`none`,o.style.clipPath=``,o.style.zIndex=``;return}if(t.retainPreviousGeometry){l&&(o.style.visibility=`hidden`,o.style.pointerEvents=`none`);return}}if(t.retainPreviousGeometry=!1,t.positioned=!0,sY(o.style,`left`,f),sY(o.style,`top`,p),sY(o.style,`width`,m),sY(o.style,`height`,h),l?(o.style.visibility=`hidden`,o.style.pointerEvents=`none`):(o.style.visibility=``,o.style.pointerEvents=``),i?o.style.zIndex=`1000`:n.api.location.type!==`floating`&&(o.style.zIndex=``),s){let e=this.element.ownerDocument.defaultView,t=e?.scrollX??0,n=e?.scrollY??0,r=s.top+n,i=s.left+t,a=Math.max(0,r-u.top),c=Math.max(0,i-u.left),l=Math.max(0,u.left+m-(s.right+t)),d=Math.max(0,u.top+h-(s.bottom+n));o.style.clipPath=`inset(${a}px ${l}px ${d}px ${c}px)`}else o.style.clipPath=``;Q(o,`dv-render-overlay-float`,n.group.api.location.type===`floating`)});t.pendingUpdate===iY&&(t.pendingUpdate=i)},u=()=>{let e=!this.map[n.api.id]?.forceVisible&&aY(n);n.api.isVisible&&!e?(this.positionCache.invalidate(),l(),this.map[n.api.id]?.retainPreviousGeometry&&(o.style.visibility=``),o.style.pointerEvents=``):(o.style.visibility=`hidden`,o.style.pointerEvents=`none`)},d=new hW,f=()=>{n.api.location.type===`floating`?queueMicrotask(()=>{if(p.isDisposed)return;let e=this.accessor.getFloatingWindowForGroup(n.api.group);if(!e)return;let t=e.overlay.element,r=()=>{let e=Number(t.getAttribute(`aria-level`));o.style.zIndex=`calc(var(--dv-overlay-z-index, 999) + ${e*2+1})`},i=new MutationObserver(()=>{r()});d.value=mW.from(()=>i.disconnect()),i.observe(t,{attributeFilter:[`aria-level`],attributes:!0}),r()}):o.style.zIndex=``},p=new Y(d,new rK(o,{onDragEnd:e=>{r.dropTarget.dnd.onDragEnd(e)},onDragEnter:e=>{r.dropTarget.dnd.onDragEnter(e)},onDragLeave:e=>{r.dropTarget.dnd.onDragLeave(e)},onDrop:e=>{r.dropTarget.dnd.onDrop(e)},onDragOver:e=>{r.dropTarget.dnd.onDragOver(e)}}),n.api.onDidVisibilityChange(()=>{u()}),n.api.onDidDimensionsChange(()=>{n.api.isVisible&&l()}),(t=n.group.api).onDidCollapsedChange?.call(t,()=>{this.positionCache.invalidate(),l()})??mW.NONE,r.onDidDimensionsChange(e=>{c(e)}),n.api.onDidLocationChange(()=>{f()}));return this.map[n.api.id].destroy=mW.from(()=>{s.parentElement===o&&s.remove(),o.remove()}),f(),queueMicrotask(()=>{this.isDisposed||u()}),this.map[n.api.id].disposable.dispose(),this.map[n.api.id].disposable=p,this.map[n.api.id].resize=l,o}},lY=class extends Y{constructor(e){super(),this.accessor=e,this.init()}init(){let e=new Set,t=new Set;this.addDisposables(this.accessor.onDidAddPanel(t=>{if(e.has(t.api.id))throw Error(`dockview: Invalid event sequence. [onDidAddPanel] called for panel ${t.api.id} but panel already exists`);e.add(t.api.id)}),this.accessor.onDidRemovePanel(t=>{if(e.has(t.api.id))e.delete(t.api.id);else throw Error(`dockview: Invalid event sequence. [onDidRemovePanel] called for panel ${t.api.id} but panel does not exists`)}),this.accessor.onDidAddGroup(e=>{if(t.has(e.api.id))throw Error(`dockview: Invalid event sequence. [onDidAddGroup] called for group ${e.api.id} but group already exists`);t.add(e.api.id)}),this.accessor.onDidRemoveGroup(e=>{if(t.has(e.api.id))t.delete(e.api.id);else throw Error(`dockview: Invalid event sequence. [onDidRemoveGroup] called for group ${e.api.id} but group does not exists`)}))}};function uY(e){if(!e.matchMedia)return!1;let t=e.matchMedia(`(pointer: coarse)`).matches,n=e.matchMedia(`(pointer: fine)`).matches;return t&&!n}function dY(e){let t=e.window??window,n=e.capture??!1,r=e.escape??!0,i=e.keys??[],a=e.outsidePointerDown??!0,o=e.pointerDownGraceMs??0,s=e.now??Date.now,c=s(),l=new Y,u=t=>e.isInside?e.isInside(t):NW(t,e.elements?.call(e)??[]);if((r||i.length>0)&&l.addDisposables(Z(t,`keydown`,t=>{(r&&t.key===`Escape`||i.includes(t.key))&&e.onDismiss()},n)),(a||e.onInsidePointerDown)&&l.addDisposables(Z(t,`pointerdown`,t=>{if(u(t)){var n;(n=e.onInsidePointerDown)==null||n.call(e,t)}else!a||s()-c<o||e.onDismiss()},n)),e.resize&&l.addDisposables(Z(t,`resize`,()=>{uY(t)||e.onDismiss()})),e.focusOut){let r=()=>e.anchor?.call(e)??e.elements?.call(e)[0],i=new WeakSet,a=t=>{if(i.has(t))return;i.add(t);let n=t.target;n instanceof Element&&((e.isFocusInside?e.isFocusInside(FW(n,r())):NW(t,e.elements?.call(e)??[]))||e.onDismiss())},o=new Map,s=()=>{let t=new Set,r=e.anchor?.call(e),i=[...e.elements?.call(e)??[],...r?[r]:[]];for(let e of i)for(let n of PW(e))t.add(n);for(let[e,n]of o)t.has(e)||(n.dispose(),o.delete(e));for(let e of t)o.has(e)||o.set(e,Z(e,`focusin`,a,n))};l.addDisposables(Z(t,`focusin`,e=>{s(),a(e)},n),{dispose:()=>{for(let[,e]of o)e.dispose();o.clear()}}),s()}return l}var fY=class extends Y{constructor(e,t=globalThis.window){super(),this._active=null,this._activeDisposable=new hW,this._root=e,this._window=t,this._element=t.document.createElement(`div`),this._element.className=`dv-popover-anchor`,this._element.style.position=`relative`,this._root.prepend(this._element),this.addDisposables(mW.from(()=>{this.close()}),this._activeDisposable)}updateRoot(e){e.prepend(this._element),this._root=e}openPopover(e,t,n){this.close();let r=this._window.document.createElement(`div`);r.style.position=`absolute`,r.style.zIndex=t.zIndex??`var(--dv-overlay-z-index)`,r.appendChild(e);let i=this._element.getBoundingClientRect(),a=i.left,o=i.top;r.style.top=`${t.y-o}px`,r.style.left=`${t.x-a}px`,this._element.appendChild(r),this._active=r,this._activeDisposable.value=new Y(dY({window:this._window,onDismiss:()=>this.close(),elements:()=>this._active?[this._active]:[],keys:[`Enter`],pointerDownGraceMs:200,resize:!0}),n?.onClose?mW.from(n.onClose):mW.NONE),this._window.requestAnimationFrame(()=>{ZW(r,this._root)})}close(){this._active&&=(this._active.remove(),this._activeDisposable.dispose(),null)}},pY=class extends Y{get renderedOutline(){return this._model?this._outline:void 0}get disabled(){return this._disabled}set disabled(e){this.disabled!==e&&(this._disabled=e,e&&this._clearNow())}_cancelPendingClear(){this._pendingClear!==void 0&&(clearTimeout(this._pendingClear),this._pendingClear=void 0)}_clearNow(){this._cancelPendingClear(),this._model&&this._model.root.remove(),this._model=void 0}get model(){if(!this.disabled)return{clear:()=>{this._clearNow()},scheduleClear:()=>{this._pendingClear===void 0&&this._model&&(this._pendingClear=setTimeout(()=>{this._pendingClear=void 0,this._clearNow()},0))},exists:()=>!!this._model,getElements:(e,t)=>{this._cancelPendingClear();let n=this._outline!==t;if(this._outline=t,this._model)return this._model.changed=n,this._model;let r=this.createContainer(),i=this.createAnchor();if(this._model={root:r,overlay:i,changed:n},r.appendChild(i),this.element.appendChild(r),e?.target instanceof HTMLElement){let t=e.target.getBoundingClientRect(),n=this.element.getBoundingClientRect();i.style.left=`${t.left-n.left}px`,i.style.top=`${t.top-n.top}px`}return this._model}}}constructor(e,t){super(),this.element=e,this._disabled=!1,this._disabled=t.disabled,this.addDisposables(mW.from(()=>{var e;(e=this.model)==null||e.clear()}))}createContainer(){let e=document.createElement(`div`);return e.className=`dv-drop-target-container`,e}createAnchor(){let e=document.createElement(`div`);return e.className=`dv-drop-target-anchor`,e.style.visibility=`hidden`,e}},mY=[`left`,`right`,`top`,`bottom`];function hY(e){return e===`left`||e===`right`}var gY={marginShare:0,size:1/0},_Y=class{get _effectiveBaseCollapsed(){return this._measuredTabSize??this._baseCollapsedSize}get minimumSize(){return this._isCollapsed?this.collapsedSize:this._baseMinimumSize===void 0?this._effectiveBaseCollapsed+50+this._axis.marginShare:this._baseMinimumSize+this._axis.marginShare}get maximumSize(){return this._isCollapsed?this.collapsedSize:this._expandedMaximumSize}get element(){return this._group.element}get isCollapsed(){return this._isCollapsed}get lastExpandedSize(){return this._lastExpandedSize}get lastExpandedContentSize(){return this._lastExpandedSize-this._axis.marginShare}get collapsedSize(){return this._effectiveBaseCollapsed+this._axis.marginShare}get configuredMinimumSize(){return this._baseMinimumSize}get configuredMaximumSize(){return this._expandedMaximumSize}get configuredCollapsedSize(){return this._baseCollapsedSize}constructor(e,t,n,r=gY){this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this.snap=!1,this.priority=`low`,this._isCollapsed=!1,this._isVisible=!0,this._tabSizeDisposables=new Y,this._group=t,this._orientation=n,t.element.classList.add(`dv-edge-group`),t.element.dataset.testid=`dv-edge-group-${e.id}`,this._baseCollapsedSize=e.collapsedSize??35,this._baseMinimumSize=e.minimumSize,this._axis=r,this._expandedMaximumSize=e.maximumSize??1/0,this._lastExpandedSize=e.initialSize??200,e.collapsed&&(this._isCollapsed=!0,t.element.classList.add(`dv-edge-collapsed`)),this._observeTabStrip()}_observeTabStrip(){let e=this._group.element.querySelector(`.dv-tabs-and-actions-container`);e&&this._tabSizeDisposables.addDisposables(wW(e,()=>{let{headerPosition:t}=this._group;(t===`left`||t===`right`)==(this._orientation===`horizontal`)&&this._applyMeasuredTabSize(this._orientation===`vertical`?e.offsetHeight:e.offsetWidth)}))}_applyMeasuredTabSize(e){e<=0||e===this._measuredTabSize||(this._measuredTabSize=e,this._isCollapsed&&this._onDidChange.fire({size:this.collapsedSize}))}layout(e,t){!this._isCollapsed&&this._isVisible&&this._axis.size>0&&(this._lastExpandedSize=e+this._axis.marginShare),this._orientation===`horizontal`?this._group.layout(e,t):this._group.layout(t,e)}setCollapsed(e){this._isCollapsed!==e&&(this._isCollapsed=e,this._group.element.classList.toggle(`dv-edge-collapsed`,e))}setVisible(e){this._isVisible=e}restoreExpandedSize(e){this._lastExpandedSize=e}updateSizing(e,t){this._baseCollapsedSize=e,this._baseMinimumSize=t}dispose(){this._tabSizeDisposables.dispose(),this._onDidChange.dispose()}},vY=class{get element(){return this._dockviewElement}constructor(e,t){this._dockviewElement=e,this._layoutDockview=t,this.priority=`high`,this.minimumSize=100,this.maximumSize=1/0,this._onDidChange=new X,this.onDidChange=this._onDidChange.event}layout(e,t){this._layoutDockview(t,e)}setVisible(e){}dispose(){this._onDidChange.dispose()}},yY=class{get element(){return this._element}constructor(e,t=0){this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this.minimumSize=100,this.maximumSize=1/0,this.priority=`high`,this._element=document.createElement(`div`),this._element.className=`dv-shell-middle-column`,this._element.style.height=`100%`,this._element.style.width=`100%`,this._splitview=new xG(this._element,{orientation:`VERTICAL`,proportionalLayout:!1,margin:t}),this._centerIndex=0,this._splitview.addView(e,{type:`distribute`},0)}addTopView(e,t){this._splitview.addView(e,t,0),this._topIndex=0,this._centerIndex+=1,this._bottomIndex!==void 0&&(this._bottomIndex+=1)}addBottomView(e,t){let n=this._splitview.length;this._splitview.addView(e,t,n),this._bottomIndex=n}removeView(e){let t=e===`top`?this._topIndex:this._bottomIndex;t!==void 0&&(this._splitview.removeView(t),e===`top`?(this._topIndex=void 0,--this._centerIndex,this._bottomIndex!==void 0&&--this._bottomIndex):this._bottomIndex=void 0)}layout(e,t){this._splitview.layout(t,e)}setVisible(e){}setViewVisible(e,t){let n=e===`top`?this._topIndex:this._bottomIndex;n!==void 0&&this._splitview.setViewVisible(n,t)}isViewVisible(e){let t=e===`top`?this._topIndex:this._bottomIndex;return t!==void 0&&this._splitview.isViewVisible(t)}getViewSize(e){let t=e===`top`?this._topIndex:this._bottomIndex;return t===void 0?0:this._splitview.getViewSize(t)}getViewCachedVisibleSize(e){let t=e===`top`?this._topIndex:this._bottomIndex;if(t!==void 0)return this._splitview.getViewCachedVisibleSize(t)}resizeView(e,t){let n=e===`top`?this._topIndex:this._bottomIndex;n!==void 0&&this._splitview.resizeView(n,t)}get axis(){return this._splitview}updateMargin(e){this._splitview.margin=e}get disabled(){return this._splitview.disabled}set disabled(e){this._splitview.disabled=e}dispose(){this._onDidChange.dispose(),this._splitview.dispose()}},bY=class{constructor(e,t,n,r=0,i=35){this._disposables=new Y,this._viewConfigs=new Map,this._pendingSizes=new Map,this._currentWidth=0,this._currentHeight=0,this._gap=r,this._defaultCollapsedSize=i,this._shellElement=document.createElement(`div`),this._shellElement.className=`dv-shell`,this._shellElement.style.height=`100%`,this._shellElement.style.width=`100%`,this._shellElement.style.position=`relative`,e.appendChild(this._shellElement);let a=new vY(t,n);this._middleColumn=new yY(a,r),this._outerSplitview=new xG(this._shellElement,{orientation:`HORIZONTAL`,proportionalLayout:!1,margin:r}),this._middleIndex=0,this._outerSplitview.addView(this._middleColumn,{type:`distribute`},0),this._disposables.addDisposables(wW(this._shellElement,e=>{if(!this._shellElement.offsetParent||!RW(this._shellElement))return;let t=Math.round(e.contentRect.width),n=Math.round(e.contentRect.height);(t!==this._currentWidth||n!==this._currentHeight)&&this.layout(t,n)}),this._outerSplitview,this._middleColumn,a)}get element(){return this._shellElement}get locked(){return this._outerSplitview.disabled}set locked(e){this._outerSplitview.disabled=e,this._middleColumn.disabled=e}addEdgeView(e,t,n){if(this.hasEdgeGroup(e))throw Error(`dockview: edge group already registered at position '${e}'`);this._viewConfigs.set(e,t);let r=new _Y($($({},t),{},{collapsedSize:t.collapsedSize??this._defaultCollapsedSize}),n,hY(e)?`horizontal`:`vertical`,this._axisFor(e)),i=r.isCollapsed?r.collapsedSize:r.lastExpandedSize;switch(e){case`left`:this._outerSplitview.addView(r,i,0),this._leftIndex=0,this._middleIndex+=1,this._rightIndex!==void 0&&(this._rightIndex+=1),this._leftView=r;break;case`right`:{let e=this._outerSplitview.length;this._outerSplitview.addView(r,i,e),this._rightIndex=e,this._rightView=r}break;case`top`:this._middleColumn.addTopView(r,i),this._topView=r;break;case`bottom`:this._middleColumn.addBottomView(r,i),this._bottomView=r}return this._disposables.addDisposables(r),!r.isCollapsed&&!this._canResize(e)&&this._pendingSizes.set(e,i),this._relayout(),r}layoutFromElement(){if(!this._shellElement.offsetParent||!RW(this._shellElement))return;let e=Math.round(this._shellElement.clientWidth),t=Math.round(this._shellElement.clientHeight);e!==0&&t!==0&&this.layout(e,t)}layout(e,t){this._currentWidth=e,this._currentHeight=t,this._outerSplitview.layout(e,t),this._flushPendingSizes()}updateTheme(e,t){this._gap=e,this._defaultCollapsedSize=t,this._outerSplitview.margin=e,this._middleColumn.updateMargin(e),this._applyThemeSizing(),this._relayout()}_hasSiblingOn(e){return hY(e)?this._leftView!==void 0&&this._rightView!==void 0:this._topView!==void 0&&this._bottomView!==void 0}_axisFor(e){return hY(e)?this._outerSplitview:this._middleColumn.axis}_applyThemeSizing(){for(let e of mY){let t=this._getView(e),n=this._viewConfigs.get(e);t&&n&&t.updateSizing(n.collapsedSize??this._defaultCollapsedSize,n.minimumSize)}}_relayout(){this._currentWidth>0&&this._currentHeight>0&&this.layout(this._currentWidth,this._currentHeight)}_slotSize(e){switch(e){case`left`:return this._leftIndex===void 0?0:this._outerSplitview.getViewSize(this._leftIndex);case`right`:return this._rightIndex===void 0?0:this._outerSplitview.getViewSize(this._rightIndex);case`top`:case`bottom`:return this._middleColumn.getViewSize(e)}}removeEdgeView(e){let t=this._getView(e);if(t){switch(e){case`left`:this._outerSplitview.removeView(this._leftIndex),this._leftIndex=void 0,this._leftView=void 0,--this._middleIndex,this._rightIndex!==void 0&&--this._rightIndex;break;case`right`:this._outerSplitview.removeView(this._rightIndex),this._rightIndex=void 0,this._rightView=void 0;break;case`top`:this._middleColumn.removeView(`top`),this._topView=void 0;break;case`bottom`:this._middleColumn.removeView(`bottom`),this._bottomView=void 0}this._disposables.removeDisposable(t),t.dispose(),this._viewConfigs.delete(e),this._pendingSizes.delete(e),this._relayout()}}hasEdgeGroup(e){switch(e){case`top`:return this._topView!==void 0;case`bottom`:return this._bottomView!==void 0;case`left`:return this._leftView!==void 0;case`right`:return this._rightView!==void 0}}setEdgeGroupVisible(e,t){let n=this._getView(e)!==void 0&&t!==this.isEdgeGroupVisible(e);switch(e){case`left`:this._leftIndex!==void 0&&this._outerSplitview.setViewVisible(this._leftIndex,t);break;case`right`:this._rightIndex!==void 0&&this._outerSplitview.setViewVisible(this._rightIndex,t);break;case`top`:case`bottom`:this._middleColumn.setViewVisible(e,t)}n&&this._gap>0&&this._hasSiblingOn(e)&&this._relayout(),t&&this._flushPendingSizes()}isEdgeGroupVisible(e){switch(e){case`left`:return this._leftIndex!==void 0&&this._outerSplitview.isViewVisible(this._leftIndex);case`right`:return this._rightIndex!==void 0&&this._outerSplitview.isViewVisible(this._rightIndex);case`top`:case`bottom`:return this._middleColumn.isViewVisible(e)}}setEdgeGroupCollapsed(e,t){let n=this._getView(e);n&&(n.setCollapsed(t),t?(this._pendingSizes.delete(e),this._resizeView(e,n.collapsedSize)):this.resizeEdgeGroup(e,n.lastExpandedSize))}resizeEdgeGroup(e,t){let n=this._getView(e);if(!n||!Number.isFinite(t))return;let r=Math.round(t);r<=0||(n.restoreExpandedSize(r),n.isCollapsed?this._pendingSizes.delete(e):this._canResize(e)?(this._pendingSizes.delete(e),this._resizeView(e,r)):this._pendingSizes.set(e,r))}_canResize(e){return this.isEdgeGroupVisible(e)&&this._axisFor(e).size>0}_resizeView(e,t){switch(e){case`left`:this._leftIndex!==void 0&&this._outerSplitview.resizeView(this._leftIndex,t);break;case`right`:this._rightIndex!==void 0&&this._outerSplitview.resizeView(this._rightIndex,t);break;case`top`:case`bottom`:this._middleColumn.resizeView(e,t)}}_flushPendingSizes(){if(this._pendingSizes.size!==0)for(let[e,t]of this._pendingSizes){let n=this._getView(e);n&&!n.isCollapsed&&this._canResize(e)&&(this._pendingSizes.delete(e),this._resizeView(e,t))}}isEdgeGroupCollapsed(e){return this._getView(e)?.isCollapsed??!1}getEdgeGroupExpandedSize(e){return this._getView(e)?.lastExpandedContentSize??0}_getView(e){switch(e){case`top`:return this._topView;case`bottom`:return this._bottomView;case`left`:return this._leftView;case`right`:return this._rightView}}toJSON(){let e={};for(let t of mY){let n=this._getView(t);if(!n)continue;let r=this.isEdgeGroupVisible(t);e[t]={size:this._expandedSize(n,t,r),visible:r,collapsed:n.isCollapsed||void 0,minimumSize:n.configuredMinimumSize,maximumSize:Number.isFinite(n.configuredMaximumSize)?n.configuredMaximumSize:void 0,collapsedSize:n.configuredCollapsedSize}}return e}_expandedSize(e,t,n){if(e.isCollapsed)return e.lastExpandedSize;let r=this._pendingSizes.get(t);return r===void 0?n?this._slotSize(t):this._cachedVisibleSize(t)??e.lastExpandedSize:r}_cachedVisibleSize(e){switch(e){case`left`:return this._leftIndex===void 0?void 0:this._outerSplitview.getViewCachedVisibleSize(this._leftIndex);case`right`:return this._rightIndex===void 0?void 0:this._outerSplitview.getViewCachedVisibleSize(this._rightIndex);case`top`:case`bottom`:return this._middleColumn.getViewCachedVisibleSize(e)}}fromJSON(e){for(let t of mY){let n=e[t],r=this._getView(t);n&&r&&(r.restoreExpandedSize(n.size),r.setCollapsed(n.collapsed??!1),n.collapsed?(this._pendingSizes.delete(t),this._resizeView(t,r.collapsedSize)):this.resizeEdgeGroup(t,n.size),this.setEdgeGroupVisible(t,!!n.visible))}}dispose(){this._disposables.dispose(),this._shellElement.remove()}};function xY(e){e.error?console.error(`dockview: failed to create popout.`,e.error):e.reason===`blocked`?console.error(`dockview: failed to create popout. perhaps you need to allow pop-ups for this website`):console.error(`dockview: failed to create popout (${e.reason}).`)}function SY(e){return new yq(e.tabGroupColors??vq,e.tabGroupAccent!==`off`)}function CY(e){let t=e.from.activePanel;[...e.from.panels].map(t=>{let n=e.from.model.removePanel(t);return e.from.model.renderContainer.detatch(t),n}).forEach(n=>{e.to.model.openPanel(n,{skipSetActive:t!==n,skipSetGroupActive:!0})})}var wY=()=>({dispose:()=>{}}),TY=wY,EY=100,DY=class extends UG{fireDidCreateTabGroup(e){this._onDidCreateTabGroup.fire(e)}fireDidDestroyTabGroup(e){this._onDidDestroyTabGroup.fire(e)}fireDidAddPanelToTabGroup(e){this._onDidAddPanelToTabGroup.fire(e)}fireDidRemovePanelFromTabGroup(e){this._onDidRemovePanelFromTabGroup.fire(e)}fireDidTabGroupChange(e){this._onDidTabGroupChange.fire(e)}fireDidTabGroupCollapsedChange(e){this._onDidTabGroupCollapsedChange.fire(e)}get orientation(){return this.gridview.orientation}get totalPanels(){return this.panels.length}get panels(){return this.groups.flatMap(e=>e.panels)}get dndCapabilities(){return eq(this.options)}get options(){return this._options}get tabGroupColorPalette(){return this._tabGroupColorPalette}get activePanel(){let e=this.activeGroup;if(e)return e.activePanel}get renderer(){return this.options.defaultRenderer??`onlyWhenVisible`}get defaultHeaderPosition(){return this.options.defaultHeaderPosition??`top`}get api(){return this._api}get floatingGroups(){var e;return((e=this._moduleRegistry)==null||(e=e.services.floatingGroupService)==null?void 0:e.floatingGroups)??[]}getFloatingWindowForGroup(e){return this._floatingGroupService?.findByGroup(e)}_gatherFloatingGroupBoxes(e){return this.getFloatingGroupSnapshots(e).map(e=>e.box)}getFloatingContainer(){return this._floatingOverlayHost??this.gridview.element}getFloatingGroupSnapshots(e){let t=this.getFloatingContainer().getBoundingClientRect();return this.floatingGroups.filter(t=>t.group!==e).map(e=>{let n=e.overlay.element.getBoundingClientRect();return{group:e.group,box:{left:n.left-t.left,top:n.top-t.top,width:n.width,height:n.height}}})}mergeFloatInto(e,t,n){e!==t&&this.getPanel(t.id)&&this.moveGroupOrPanel({from:{groupId:e.id},to:{group:t,position:n}})}getGridSplitterRects(){let e=this.getFloatingContainer().getBoundingClientRect(),t=[];return this.gridview.element.querySelectorAll(`.dv-sash`).forEach(n=>{let r=n.getBoundingClientRect();t.push({left:r.left-e.left,top:r.top-e.top,width:r.width,height:r.height})}),t}get _smartGuidesService(){return this._moduleRegistry.services.smartGuidesService}get smartGuidesEnabled(){return this._smartGuidesService?.enabled??!1}setSmartGuidesEnabled(e){var t;(t=fJ(this._smartGuidesService,`SmartGuides`,`api.setSmartGuidesEnabled`))==null||t.setEnabled(e)}updateSmartGuidesOptions(e){var t;(t=fJ(this._smartGuidesService,`SmartGuides`,`api.updateSmartGuidesOptions`))==null||t.updateOptions(e)}get onDidSnapFloat(){return this._smartGuidesService?.onDidSnapFloat??wY}get onDidSnapTogether(){return this._smartGuidesService?.onDidSnapTogether??wY}_buildFloatingDragTransform(e,t){let n=this.options.transformFloatingGroupDrag,r=!t;if(n||r&&this._smartGuidesService)return t=>{let i=n?.({group:e,proposed:t.proposed,container:t.container,others:t.others,modifiers:t.modifiers}),a=i?$($({},t.proposed),i):t.proposed;return(r?this._smartGuidesService?.transformFloatingGroupDrag({group:e,proposed:a,container:t.container,others:t.others,modifiers:t.modifiers}):void 0)??i??void 0}}get _floatingGroupService(){return this._moduleRegistry.services.floatingGroupService}get _popoutWindowService(){return this._moduleRegistry.services.popoutWindowService}get _watermarkService(){return this._moduleRegistry.services.watermarkService}get _edgeGroupService(){return this._moduleRegistry.services.edgeGroupService}get _rootDropTargetService(){return this._moduleRegistry.services.rootDropTargetService}get _advancedDnDService(){return this._moduleRegistry.services.advancedDnDService}get _dndCompassService(){return this._moduleRegistry.services.dndCompassService}canDropOnGroup(e,t,n){return e.model.canDisplayContentOverlay(n,t)}getDropOverlayElement(e){let t=e.element.querySelector(`.dv-content-container`);if(t)return this.options.theme?.dndPanelOverlay===`group`?t.parentElement??t:t}getTabsListElement(e){return e.model.header.hidden?void 0:e.model.tabsListElement}relayoutGroup(e){e.relayout()}setForcedOverflow(e,t){e.model.header.setForcedOverflow(t)}getLayoutElement(){return this.gridview.element}getDropPositionResolver(){if(this.options.dropPositionResolver)return this.options.dropPositionResolver;let e=this._dndCompassService?.resolver,t=this._moduleRegistry.services.autoEdgeGroupService;return e&&t?{resolve:n=>t.resolveEdge(n)??e.resolve(n)}:e??t?.resolver}dockToLayoutEdge(e,t){let n=new Vq({nativeEvent:e,position:t,panel:void 0,api:this._api,group:void 0,getData:fW,kind:`edge`});if(this._onWillDrop.fire(n),n.defaultPrevented)return;let r=fW();r?this.moveGroupOrPanel({from:{groupId:r.groupId,panelId:r.panelId??void 0},to:{group:this.orthogonalize(t),position:`center`}}):this._onDidDrop.fire(new Bq({nativeEvent:e,position:t,panel:void 0,api:this._api,group:void 0,getData:fW}))}get headerActionsService(){return this._moduleRegistry.services.headerActionsService}get _layoutHistoryService(){return this._moduleRegistry.services.layoutHistoryService}undo(){var e;(e=fJ(this._layoutHistoryService,`LayoutHistory`,`api.undo`))==null||e.undo()}redo(){var e;(e=fJ(this._layoutHistoryService,`LayoutHistory`,`api.redo`))==null||e.redo()}get canUndo(){return this._layoutHistoryService?.canUndo??!1}get canRedo(){return this._layoutHistoryService?.canRedo??!1}clearHistory(){var e;(e=this._layoutHistoryService)==null||e.clear()}get onDidChangeHistory(){return this._layoutHistoryService?.onDidChangeHistory??TY}get hasEdgeDragReveal(){return!!this._moduleRegistry.services.autoEdgeGroupService}isGridEmpty(){return this.gridview.length===0}rootDropTargetOverrideTarget(){return this.rootDropTargetContainer?.model}dispatchUnhandledDragOver(e,t){let n=new fq(e,`edge`,t,fW);return this._onUnhandledDragOver.fire(n),n.isAccepted}fireWillDragPanel(e){this._onWillDragPanel.fire(e)}fireWillDragGroup(e){this._onWillDragGroup.fire(e)}fireWillDrop(e){this._onWillDrop.fire(e)}fireWillShowOverlay(e){this._onWillShowOverlay.fire(e)}buildGroupDragGhost(e){return this._advancedDnDService?.buildGroupDragGhost(e)}resolveDropOverlayModel(e,t){return this._advancedDnDService?.resolveOverlayModel(e,t)}get rootElement(){return this._shellManager?.element??this.element}ownsElement(e){if(this.rootElement.contains(e))return!0;let t=this.rootElement.ownerDocument,n=e.ownerDocument;return!n||n===t?!1:this.getPopoutWindows().some(e=>e.document===n)}adjacentGroup(e,t){let n=this.getGridviewForGroup(e);if(!n.element.contains(e.element))return;let r=jG(e.element),i=(t?n.previous(r):n.next(r)).view;if(n===this.gridview||i!==e)return i}adjacentGroupInDirection(e,t){if(e.api.location.type!==`grid`)return;let n=e.element.getBoundingClientRect(),r=n.left+n.width/2,i=n.top+n.height/2,a,o=1/0;for(let n of this.groups){if(n===e||n.api.location.type!==`grid`)continue;let s=n.element.getBoundingClientRect(),c=s.left+s.width/2-r,l=s.top+s.height/2-i,u;switch(t){case`left`:u=c<0&&Math.abs(c)>=Math.abs(l);break;case`right`:u=c>0&&Math.abs(c)>=Math.abs(l);break;case`up`:u=l<0&&Math.abs(l)>=Math.abs(c);break;default:u=l>0&&Math.abs(l)>=Math.abs(c)}if(!u)continue;let d=c*c+l*l;d<o&&(o=d,a=n)}return a}showDropPreview(e,t){return this._advancedDnDService?.showPreviewOverlay(e,t)??mW.NONE}announce(e){var t;(t=this._moduleRegistry.services.liveRegionService)==null||t.announce(e)}dockPanel(e,t,n){this.moveGroupOrPanel({from:{groupId:e.group.id,panelId:e.id},to:{group:t,position:n}})}floatPanel(e){this.addFloatingGroup(e)}get contextMenuService(){return this._moduleRegistry.services.contextMenuService}get pinnedTabsService(){return this._moduleRegistry.services.pinnedTabsService}get advancedOverflowService(){return this._moduleRegistry.services.advancedOverflowService}setPanelPinned(e,t){e.isPinned!==t&&this.options.pinnedTabs?.enabled&&this.pinnedTabsService&&(e.setPinned(t),this._onDidPanelPinnedChange.fire({panel:e,isPinned:t}))}get mountElement(){return this.gridview.element}hasVisibleGridGroup(){return this.groups.some(e=>e.api.location.type===`grid`&&e.api.isVisible)}isLastGridGroup(e){return e.api.location.type===`grid`&&!this.groups.some(t=>t!==e&&t.api.location.type===`grid`)}fireLayoutChange(e){this._bufferOnDidLayoutChange.fire(e)}get popoutRestorationPromise(){return this._popoutWindowService?.restorationPromise??Promise.resolve()}constructor(e,t){super(e,{proportionalLayout:t.proportionalLayout??!0,orientation:`HORIZONTAL`,styles:t.hideBorders?{separatorBorder:`transparent`}:void 0,disableAutoResizing:t.disableAutoResizing,locked:t.locked,margin:t.theme?.gap??0,className:t.className}),this.nextGroupId=hG(),this._deserializer=new tJ(this),this._moduleRegistry=new pJ,this._onWillDragPanel=new X,this.onWillDragPanel=this._onWillDragPanel.event,this._onWillDragGroup=new X,this.onWillDragGroup=this._onWillDragGroup.event,this._onDidDrop=new X,this.onDidDrop=this._onDidDrop.event,this._onWillDrop=new X,this.onWillDrop=this._onWillDrop.event,this._mutationDepth=0,this._syncMutationDepth=0,this._pendingLocationChanges=new Map,this._openingPopoutWindows=new Set,this._origin=`user`,this._originDepth=0,this._onWillMutateLayout=new X,this.onWillMutateLayout=this._onWillMutateLayout.event,this._onDidMutateLayout=new X,this.onDidMutateLayout=this._onDidMutateLayout.event,this._onWillShowOverlay=new X,this.onWillShowOverlay=this._onWillShowOverlay.event,this._onUnhandledDragOver=new X,this.onUnhandledDragOver=this._onUnhandledDragOver.event,this._onDidRemovePanel=new X,this.onDidRemovePanel=this._onDidRemovePanel.event,this._onDidAddPanel=new X,this.onDidAddPanel=this._onDidAddPanel.event,this._onDidPopoutGroupSizeChange=new X,this.onDidPopoutGroupSizeChange=this._onDidPopoutGroupSizeChange.event,this._onDidPopoutGroupPositionChange=new X,this.onDidPopoutGroupPositionChange=this._onDidPopoutGroupPositionChange.event,this._onDidAddPopoutGroup=new X,this.onDidAddPopoutGroup=this._onDidAddPopoutGroup.event,this._onDidRemovePopoutGroup=new X,this.onDidRemovePopoutGroup=this._onDidRemovePopoutGroup.event,this._onDidChangePopouts=new X,this.onDidChangePopouts=this._onDidChangePopouts.event,this._onDidOpenPopoutWindowFail=new X,this.onDidOpenPopoutWindowFail=this._onDidOpenPopoutWindowFail.event,this._onWillClosePopoutWindow=new X,this.onWillClosePopoutWindow=this._onWillClosePopoutWindow.event,this._onDidStartFloatingGroupDrag=new X,this.onDidStartFloatingGroupDrag=this._onDidStartFloatingGroupDrag.event,this._onDidEndFloatingGroupDrag=new X,this.onDidEndFloatingGroupDrag=this._onDidEndFloatingGroupDrag.event,this._onDidLayoutFromJSON=new X,this.onDidLayoutFromJSON=this._onDidLayoutFromJSON.event,this._onDidActivePanelChange=new X({replay:!0}),this.onDidActivePanelChange=this._onDidActivePanelChange.event,this._onDidPanelPinnedChange=new X,this.onDidPanelPinnedChange=this._onDidPanelPinnedChange.event,this._onDidMovePanel=new X,this.onDidMovePanel=this._onDidMovePanel.event,this._onDidCreateTabGroup=new X,this.onDidCreateTabGroup=this._onDidCreateTabGroup.event,this._onDidDestroyTabGroup=new X,this.onDidDestroyTabGroup=this._onDidDestroyTabGroup.event,this._onDidAddPanelToTabGroup=new X,this.onDidAddPanelToTabGroup=this._onDidAddPanelToTabGroup.event,this._onDidRemovePanelFromTabGroup=new X,this.onDidRemovePanelFromTabGroup=this._onDidRemovePanelFromTabGroup.event,this._onDidTabGroupChange=new X,this.onDidTabGroupChange=this._onDidTabGroupChange.event,this._onDidTabGroupCollapsedChange=new X,this.onDidTabGroupCollapsedChange=this._onDidTabGroupCollapsedChange.event,this._onDidMaximizedGroupChange=new X,this.onDidMaximizedGroupChange=this._onDidMaximizedGroupChange.event,this._inShellLayout=!1,this._onDidRemoveGroup=new X,this.onDidRemoveGroup=this._onDidRemoveGroup.event,this._onDidEdgeGroupAutoHideChange=new X,this.onDidEdgeGroupAutoHideChange=this._onDidEdgeGroupAutoHideChange.event,this._onDidAddGroup=new X,this.onDidAddGroup=this._onDidAddGroup.event,this._onDidOptionsChange=new X,this.onDidOptionsChange=this._onDidOptionsChange.event,this._onDidActiveGroupChange=new X,this.onDidActiveGroupChange=this._onDidActiveGroupChange.event,this._peekingGroups=new Set,this._moving=!1,this._options=t,this._tabGroupColorPalette=SY(t);let n=t.modules??[...nY,...hJ()];for(let e of n)this._moduleRegistry.register(e);this._moduleRegistry.initialize(this),this.reportMissingOptionModules(t);let r=this._popoutWindowService;r&&this.addDisposables(r.onDidRemove(e=>{this._onDidRemovePopoutGroup.fire({id:e.popoutGroup.id,group:e.popoutGroup,window:e.getWindow()})})),this.popupService=new fY(this.element),this.addDisposables(this.popupService,mW.from(()=>{for(let e of this._openingPopoutWindows)e.dispose();this._openingPopoutWindows.clear()})),this._api=new nK(this),this.disableResizing=!0,this.element.remove(),this._shellManager=new bY(e,this.element,(e,t)=>this._layoutFromShell(e,t),t.theme?.gap??0,t.theme?.edgeGroupCollapsedSize),this._shellManager.locked=!!t.locked,this.popupService.updateRoot(this._shellManager.element),this._shellThemeClassnames=new KW(this._shellManager.element),this.rootDropTargetContainer=new pY(this._shellManager.element,{disabled:!0}),this.floatingDropTargetContainer=new pY(this._shellManager.element,{disabled:!1}),this.overlayRenderContainer=new cY(this._shellManager.element,this),this._floatingOverlayHost=document.createElement(`div`),this._floatingOverlayHost.className=`dv-floating-overlay-host`,this._shellManager.element.appendChild(this._floatingOverlayHost),Q(this.gridview.element,`dv-dockview`,!0),Q(this.element,`dv-debug`,!!t.debug),this.updateTheme(),t.debug&&this.addDisposables(new lY(this)),this.addDisposables(mW.from(()=>this._pendingLocationChanges.clear()),this.rootDropTargetContainer,this.floatingDropTargetContainer,Z(this._shellManager.element,`dragend`,()=>{var e,t;(e=this.rootDropTargetContainer.model)==null||e.clear(),(t=this.floatingDropTargetContainer.model)==null||t.clear()},!0),this.overlayRenderContainer,this._onWillDragPanel,this._onWillDragGroup,this._onWillShowOverlay,this._onDidActivePanelChange,this._onDidPanelPinnedChange,this._onDidAddPanel,this._onDidRemovePanel,this._onDidLayoutFromJSON,this._onDidDrop,this._onWillDrop,this._onWillMutateLayout,this._onDidMutateLayout,this._onDidMovePanel,this._onDidMovePanel.event(()=>{this.debouncedUpdateAllPositions()}),this._onDidAddGroup,this._onDidRemoveGroup,this._onDidEdgeGroupAutoHideChange,this._onDidActiveGroupChange,this._onUnhandledDragOver,this._onDidMaximizedGroupChange,this._onDidPopoutGroupSizeChange,this._onDidPopoutGroupPositionChange,this._onDidAddPopoutGroup,this._onDidRemovePopoutGroup,this._onDidChangePopouts,this._onDidAddPopoutGroup.event(()=>this._onDidChangePopouts.fire()),this._onDidRemovePopoutGroup.event(()=>this._onDidChangePopouts.fire()),this._onDidOpenPopoutWindowFail,this._onDidStartFloatingGroupDrag,this._onDidEndFloatingGroupDrag,this._onDidCreateTabGroup,this._onDidDestroyTabGroup,this._onDidAddPanelToTabGroup,this._onDidRemovePanelFromTabGroup,this._onDidTabGroupChange,this._onDidTabGroupCollapsedChange,gW.any(this.onDidPopoutGroupSizeChange,this.onDidPopoutGroupPositionChange)(()=>{this.fireLayoutChange(`geometry`)}),gW.any(this.onDidCreateTabGroup,this.onDidDestroyTabGroup,this.onDidAddPanelToTabGroup,this.onDidRemovePanelFromTabGroup,this.onDidTabGroupChange,this.onDidTabGroupCollapsedChange)(()=>{this.fireLayoutChange(`structure`)}),this._onDidOptionsChange,this.onDidAdd(e=>{this._moving||this._onDidAddGroup.fire(e)}),this.onDidRemove(e=>{this._moving||this._onDidRemoveGroup.fire(e)}),this.onDidActiveChange(e=>{this._moving||this._onDidActiveGroupChange.fire(e)}),this.onDidMaximizedChange(e=>{this._onDidMaximizedGroupChange.fire({group:e.panel,isMaximized:e.isMaximized})}),gW.any(this.onDidAddPanel,this.onDidRemovePanel,this.onDidAddGroup,this.onDidRemove,this.onDidRemoveGroup,this.onDidMovePanel)(()=>{this._bufferOnDidLayoutChange.fire(`structure`)}),this.onDidActivePanelChange(()=>{this._bufferOnDidLayoutChange.fire(`activePanel`)}),mW.from(()=>{var e;this._moduleRegistry.dispose(),(e=this._shellManager)==null||e.dispose()}),this._onWillClosePopoutWindow);let i=this._rootDropTargetService;i&&this.addDisposables(i.onWillShowOverlay(e=>{this.gridview.length>0&&e.position===`center`||this._onWillShowOverlay.fire(new aq(e,{kind:`edge`,panel:void 0,api:this._api,group:void 0,getData:fW}))}),i.onDrop(e=>this.dockToLayoutEdge(e.nativeEvent,e.position))),this._moduleRegistry.postConstruct(this),this._shellManager.layoutFromElement()}setVisible(e,t){switch(e.api.location.type){case`grid`:super.setVisible(e,t);break;case`floating`:{let n=this.floatingGroups.find(t=>t.group===e);n&&(n.overlay.setVisible(t),e.api._onDidVisibilityChange.fire({isVisible:t}));break}case`popout`:console.warn(`dockview: You cannot hide a group that is in a popout window`)}}getPopupServiceForGroup(e){var t;return((t=this._popoutWindowService)==null||(t=t.findByGroup(e))==null?void 0:t.popupService)??this.popupService}addPopoutGroup(e,t){return this.mutationAsync(`popout`,()=>this._doAddPopoutGroup(e,t))}getPopouts(){return this._popoutWindowService?.entries.map(e=>({id:e.popoutGroup.id,group:e.popoutGroup,window:e.getWindow()}))??[]}getPopoutWindows(){return this.getPopouts().map(e=>e.window)}_doAddPopoutGroup(e,t){var n;let r=fJ(this._popoutWindowService,`PopoutWindow`,`api.addPopoutGroup`);if(!r||e instanceof Yq&&e.model.location.type===`edge`)return Promise.resolve(!1);if(e instanceof Qq&&e.group.size===1&&this.closeEmptyGroups)return this.addPopoutGroup(e.group,t);let i=GW(this.gridview.element),a=this.element;function o(){if(t?.position)return t.position;let n=(e instanceof Yq?e.element:e.group?.element??a).getBoundingClientRect();return{left:window.screenX+n.left,top:window.screenY+n.top,width:n.width,height:n.height}}let s=o(),c=(t==null||(n=t.overridePopoutGroup)==null?void 0:n.id)??this.getNextGroupId(),l=t?.popoutUrl??this.options?.popoutUrl,u=l??`/popout.html`,d=new sG(`${this.id}-${c}`,i??``,{url:u,left:s.left,top:s.top,width:s.width,height:s.height,onDidOpen:t?.onDidOpen,onWillClose:e=>{var n;t==null||(n=t.onWillClose)==null||n.call(t,e),this._onWillClosePopoutWindow.fire(e)},nonce:this.options?.nonce,styleRoot:()=>this.element.getRootNode()}),f=new Y(d,d.onDidClose(()=>{f.dispose()}));this._openingPopoutWindows.add(f);let p=oG(u);return(p?Promise.resolve(null):d.open()).then(n=>{if(this._openingPopoutWindows.delete(f),this.isDisposed)return f.dispose(),!1;if(d.isDisposed){let e=d.failure;return e&&!this.isDisposed&&(xY(e),this._onDidOpenPopoutWindowFail.fire(e)),!1}let i=t?.referenceGroup??(e instanceof Qq?e.group:e),a=e.api.location.type,o=i.element.parentElement!==null,s;if(t?.overridePopoutGridview?s=t.overridePopoutGroup??i:o?t?.overridePopoutGroup?s=t.overridePopoutGroup:(s=this.createGroup({id:c}),n&&this._onDidAddGroup.fire(s)):s=i,n===null)return this.handleBlockedPopout({group:s,referenceGroup:i,options:t,popoutWindowDisposable:f,failure:p?{reason:`url-refused`,error:p}:d.failure??{reason:`blocked`}}),!1;let u=document.createElement(`div`);u.className=`dv-overlay-render-container`;let m=new cY(u,this);s.model.renderContainer=m;let h=t?.overridePopoutGridview??this.createNestedGridview();t?.overridePopoutGridview?h.locked=this.gridview.locked:h.addView(s,bG.Distribute,[0]),h.element.style.width=`100%`,h.element.style.height=`100%`,h.layout(d.window.innerWidth,d.window.innerHeight);let g=!1,_=()=>{g||(g=!0,h.dispose())},v,y=[];if(!t?.overridePopoutGroup&&!t?.overridePopoutGridview&&o){if(e instanceof Qq){let t=e.group;this.movingLock(()=>{let t=i.model.removePanel(e);s.model.openPanel(t)}),y=[{panel:e,from:t}]}else switch(this.movingLock(()=>CY({from:i,to:s})),y=s.panels.map(e=>({panel:e,from:i})),a){case`grid`:i.api.setVisible(!1);break;case`floating`:case`popout`:v=this.floatingGroups.find(t=>t.group.api.id===e.api.id)?.overlay.toJSON(),this.removeGroup(i)}}n.classList.add(`dv-dockview`),n.style.overflow=`hidden`,n.appendChild(u),n.appendChild(h.element);let b=document.createElement(`div`),x=new pY(b,{disabled:this.rootDropTargetContainer.disabled});n.appendChild(b),s.model.dropTargetContainer=x;let S=new fY(n,d.window);if(f.addDisposables(S),s.model.location={type:`popout`,getWindow:()=>d.window,popoutUrl:l},t?.overridePopoutGridview){let e=this.groups.filter(e=>h.element.contains(e.element));for(let t of e)t.model.renderContainer=m,t.model.dropTargetContainer=x,t.model.location={type:`popout`,getWindow:()=>d.window,popoutUrl:l}}o&&e.api.location.type===`grid`&&e.api.setVisible(!1),this.doSetGroupAndPanelActive(s);let C=r.observeGridviewSize(d,h,m);C&&f.addDisposables(C);let w=new hW;f.addDisposables(w);let T=e=>{w.value=new Y(e.api.onDidActiveChange(e=>{if(e.isActive){var t;(t=d.window)==null||t.focus()}}),e.api.onWillFocus(()=>{var e;(e=d.window)==null||e.focus()}))};T(s);let E={},D=o&&i&&this.getPanel(i.id),O={window:d,popoutGroup:s,gridview:h,overlayRenderContainer:m,dropTargetContainer:x,getWindow:()=>d.window,popoutUrl:l,referenceGroup:D?i.id:void 0,popupService:S,setAnchorGroup:e=>{O.popoutGroup=e,T(e)},disposable:{dispose:()=>(f.dispose(),E.returnedGroup)}},k=YW(d.window);f.addDisposables(k,XW(d.window,()=>{this._onDidPopoutGroupSizeChange.fire({width:d.window.innerWidth,height:d.window.innerHeight,group:O.popoutGroup})}),k.event(()=>{this._onDidPopoutGroupPositionChange.fire({screenX:d.window.screenX,screenY:d.window.screenY,group:O.popoutGroup})}),Z(d.window,`resize`,()=>{h.layout(d.window.innerWidth,d.window.innerHeight)}),m,mW.from(()=>this.disposePopoutWindow({group:s,referenceGroup:i,popoutGridview:h,isGroupAddedToDom:o,floatingBox:v,disposePopoutGridview:_,closeResult:E}))),r.add(O),this._onDidAddPopoutGroup.fire({id:O.popoutGroup.id,group:O.popoutGroup,window:O.getWindow()});for(let{panel:e,from:t}of y)this.fireDidMovePanel(e,t);return!0}).catch(e=>(this._openingPopoutWindows.delete(f),console.error(`dockview: failed to create popout.`,e),!1))}handleBlockedPopout(e){let{group:t,referenceGroup:n,options:r,popoutWindowDisposable:i,failure:a}=e;if(xY(a),i.dispose(),this._onDidOpenPopoutWindowFail.fire(a),r?.overridePopoutGridview){let e=r.overridePopoutGridview,t=this.groups.filter(t=>e.element.contains(t.element));for(let n of t)this.movingLock(()=>{e.remove(n),this.redockGroupToMainGrid(n)});e.dispose(),n&&!n.api.isVisible&&n.api.setVisible(!0)}else t===n?this.gridview.element.contains(t.element)||(this.movingLock(()=>this.doAddGroup(t,[0])),t.model.location={type:`grid`}):(this.movingLock(()=>CY({from:t,to:n})),t.model.size===0&&this._groups.has(t.id)&&(t.dispose(),this._groups.delete(t.id),this._onDidRemoveGroup.fire(t))),n.api.isVisible||n.api.setVisible(!0)}redockGroupToMainGrid(e){e.model.renderContainer=this.overlayRenderContainer,e.model.dropTargetContainer=this.rootDropTargetContainer,e.model.location={type:`grid`},this.doAddGroup(e,[0])}disposePopoutWindow(e){let{group:t,referenceGroup:n,popoutGridview:r,isGroupAddedToDom:i,floatingBox:a,disposePopoutGridview:o,closeResult:s}=e;if(this.isDisposed){o();return}let c=!!this._popoutWindowService?.entries.find(e=>e.gridview===r),l=this.groups.filter(e=>r.element.contains(e.element)),u=l.includes(t),d=u&&l.length===1;if(!c){u&&this.getPanel(t.id)&&(t.model.renderContainer=this.overlayRenderContainer,t.model.dropTargetContainer=this.rootDropTargetContainer,s.returnedGroup=t),o();return}let f=[];for(let e of l)if(e!==t){this.movingLock(()=>{this.doRemoveGroup(e,{skipDispose:!0,skipActive:!0,skipPopoutReturn:!0}),this.redockGroupToMainGrid(e)});for(let t of e.panels)f.push({panel:t,from:e})}if(u&&i&&this.getPanel(n.id)){let e=[...t.panels];this.movingLock(()=>CY({from:t,to:n}));for(let n of e)f.push({panel:n,from:t});n.api.isVisible||n.api.setVisible(!0),this.getPanel(t.id)&&this.doRemoveGroup(t,{skipPopoutAssociated:!0})}else if(u&&this.getPanel(t.id)){if(t.model.renderContainer=this.overlayRenderContainer,t.model.dropTargetContainer=this.rootDropTargetContainer,s.returnedGroup=t,a&&d)this.addFloatingGroup(t,{height:a.height,width:a.width,position:a});else{this.doRemoveGroup(t,{skipDispose:!0,skipActive:!0,skipPopoutReturn:!0}),t.model.location={type:`grid`},this.movingLock(()=>{this.doAddGroup(t,[0])});for(let e of t.panels)f.push({panel:e,from:t})}this.doSetGroupAndPanelActive(t)}o();for(let{panel:e,from:t}of f)this.fireDidMovePanel(e,t)}addFloatingGroup(e,t){this.mutation(`float`,()=>this._doAddFloatingGroup(e,t))}_doAddFloatingGroup(e,t){if(!fJ(this._floatingGroupService,`FloatingGroup`,`api.addFloatingGroup`)||e instanceof Yq&&e.model.location.type===`edge`)return;let n,r=[];if(e instanceof Qq){let t=e.group;n=this.createGroup(),this._onDidAddGroup.fire(n),this.movingLock(()=>this.removePanel(e,{removeEmptyGroup:!1,skipDispose:!0,skipSetActiveGroup:!0})),this.removeGroupIfEmpty(t),this.movingLock(()=>n.model.openPanel(e,{skipSetGroupActive:!0})),r=[{panel:e,from:t}]}else{n=e;let i=this._popoutWindowService?.findReferenceGroupId(n),a=i?this.getPanel(i):void 0;typeof t?.skipRemoveGroup==`boolean`&&t.skipRemoveGroup||(a?(this.movingLock(()=>CY({from:e,to:a})),this.doRemoveGroup(e,{skipPopoutReturn:!0,skipPopoutAssociated:!0}),this.doRemoveGroup(a,{skipDispose:!0}),n=a,r=n.panels.map(t=>({panel:t,from:e}))):(this.doRemoveGroup(e,{skipDispose:!0,skipPopoutReturn:!0,skipPopoutAssociated:!1}),r=n.panels.map(e=>({panel:e,from:n}))))}function i(){if(t?.position){let e={};return`left`in t.position?e.left=Math.max(t.position.left,0):`right`in t.position?e.right=Math.max(t.position.right,0):e.left=vJ.left,`top`in t.position?e.top=Math.max(t.position.top,0):`bottom`in t.position?e.bottom=Math.max(t.position.bottom,0):e.top=vJ.top,e.width=typeof t.width==`number`?Math.max(t.width,0):vJ.width,e.height=typeof t.height==`number`?Math.max(t.height,0):vJ.height,e}return{left:typeof t?.x==`number`?Math.max(t.x,0):vJ.left,top:typeof t?.y==`number`?Math.max(t.y,0):vJ.top,width:typeof t?.width==`number`?Math.max(t.width,0):vJ.width,height:typeof t?.height==`number`?Math.max(t.height,0):vJ.height}}let a=i(),o=this.createNestedGridview();o.addView(n,bG.Distribute,[0]),this.mountFloatingWindow(o,n,[n],a,{dragHandle:t?.dragHandle,inDragMode:t?.inDragMode,skipActiveGroup:t?.skipActiveGroup,disableSmartGuides:t?.disableSmartGuides});for(let{panel:e,from:t}of r)this.fireDidMovePanel(e,t)}get closeEmptyGroups(){return this.options.closeEmptyGroups!==!1}keepEmptyGroups(e){return e.keepEmptyGroups??!this.closeEmptyGroups}removeGroupIfEmpty(e){e.model.size===0&&this.closeEmptyGroups&&this.doRemoveGroup(e,{skipActive:!0})}get locked(){return this.gridview.locked}set locked(e){this.gridview.locked=e,this._shellManager&&(this._shellManager.locked=e);for(let t of this.nestedGridviews())t.locked=e}nestedGridviews(){return[...this.floatingGroups.map(e=>e.gridview),...(this._popoutWindowService?.entries??[]).map(e=>e.gridview)]}createNestedGridview(e=`HORIZONTAL`){return new RG(this.gridview.proportionalLayout,this.options.hideBorders?{separatorBorder:`transparent`}:void 0,e,this.gridview.locked,this.options.theme?.gap??0)}mountFloatingWindow(e,t,n,r,i){let a=fJ(this._floatingGroupService,`FloatingGroup`,`api.addFloatingGroup`);if(!a)return;let o=(i?.dragHandle??this.options.floatingGroupDragHandle??`titlebar`)===`titlebar`?new oJ(this,t):void 0,s=new aJ($($({container:this._floatingOverlayHost??this.gridview.element,content:e.element,header:o?.element},r),{},{minimumInViewportWidth:this.options.floatingGroupBounds===`boundedWithinViewport`?void 0:this.options.floatingGroupBounds?.minimumWidthWithinViewport??100,minimumInViewportHeight:this.options.floatingGroupBounds===`boundedWithinViewport`?void 0:this.options.floatingGroupBounds?.minimumHeightWithinViewport??100,transformDragPosition:this._buildFloatingDragTransform(t,i?.disableSmartGuides??!1),getSiblingBoxes:()=>this._gatherFloatingGroupBoxes(t)})),c=o?.element??t.element.querySelector(`.dv-void-container`);if(!c)throw Error(`dockview: failed to find drag handle`);s.setupDrag(c,{inDragMode:typeof i?.inDragMode==`boolean`&&i.inDragMode});let l=a.add(t,s,e);l.addDisposables(s.onDidStartMoving(()=>this._onDidStartFloatingGroupDrag.fire(t)),s.onDidChangeEnd(()=>this._onDidEndFloatingGroupDrag.fire(t))),o&&(l.setTitleBar(o),l.addDisposables(o,mW.from(()=>l.setTitleBar(void 0)),o.onDragStart(e=>{this._onWillDragGroup.fire({nativeEvent:e,group:l.group})})));for(let e of n)e.model.location={type:`floating`};i?.skipActiveGroup||this.doSetGroupAndPanelActive(t)}orthogonalize(e,t){switch(this.gridview.normalize(),e){case`top`:case`bottom`:this.gridview.orientation===`HORIZONTAL`&&this.gridview.insertOrthogonalSplitviewAtRoot();break;case`left`:case`right`:this.gridview.orientation===`VERTICAL`&&this.gridview.insertOrthogonalSplitviewAtRoot()}switch(e){case`top`:case`left`:case`center`:return this.createGroupAtLocation([0],void 0,t);case`bottom`:case`right`:return this.createGroupAtLocation([this.gridview.length],void 0,t);default:throw Error(`dockview: unsupported position ${e}`)}}updateOptions(e){var t,n;super.updateOptions(e),this.reportMissingOptionModules(e),(t=this._floatingGroupService)==null||t.updateBounds(e),(n=this._rootDropTargetService)==null||n.setOptions(e);let r=this.options.disableDnd,i=this.options.dndStrategy;this._options=$($({},this.options),e);let a=this.options.disableDnd,o=this.options.dndStrategy;if((r!==a||i!==o)&&this.updateDragAndDropState(),`proportionalLayout`in e){let e=this.gridview.proportionalLayout;for(let t of this.nestedGridviews())t.proportionalLayout=e}if(`theme`in e&&this.updateTheme(),`createRightHeaderActionComponent`in e||`createLeftHeaderActionComponent`in e||`createPrefixHeaderActionComponent`in e){var s;(s=this.headerActionsService)==null||s.refreshAll()}if(`createWatermarkComponent`in e){var c;(c=this._watermarkService)==null||c.refresh();for(let e of this.groups)e.model.refreshWatermark()}if(`tabGroupColors`in e||`tabGroupAccent`in e){this._tabGroupColorPalette.setEntries(this._options.tabGroupColors??vq),this._tabGroupColorPalette.enabled=this._options.tabGroupAccent!==`off`;for(let e of this.groups)e.model.refreshTabGroupAccent()}this._onDidOptionsChange.fire(),this._layoutFromShell(this.gridview.width,this.gridview.height)}reportMissingOptionModules(e){_J(e,e=>this._moduleRegistry.has(e))}layout(e,t,n){var r;this._shellManager&&!this._inShellLayout?this._shellManager.layout(e,t):super.layout(e,t,n),this._syncFloatingOverlayHost(),(r=this._moduleRegistry)==null||(r=r.services.floatingGroupService)==null||r.constrainBounds()}_syncFloatingOverlayHost(){if(!this._floatingOverlayHost||!this._shellManager)return;let e=this._shellManager.element.getBoundingClientRect(),t=this.element.getBoundingClientRect(),n=this._floatingOverlayHost;n.style.left=`${t.left-e.left}px`,n.style.top=`${t.top-e.top}px`,n.style.width=`${t.width}px`,n.style.height=`${t.height}px`}_layoutFromShell(e,t){this._inShellLayout=!0,this.layout(e,t,!0),this._inShellLayout=!1}forceRelayout(){this._shellManager?this._layoutFromShell(this.width,this.height):super.forceRelayout()}addEdgeGroup(e,t){let n=this._edgeGroupService;if(!n)throw Error(uJ(`EdgeGroup`,`api.addEdgeGroup`));if(n.has(e))throw Error(`dockview: edge group already exists at position '${e}'`);return this.mutation(`add`,()=>{let r=this.createGroup({id:t.id});r.model.location={type:`edge`,position:e},r.model.headerPosition=e;let i=r.onDidChange(t=>{var n;if(!t)return;let r=hY(e)?t.width:t.height;typeof r==`number`&&((n=this._shellManager)==null||n.resizeEdgeGroup(e,r))}),a=r.model.onDidRemovePanel(()=>{r.model.isEmpty&&(n.isAutoReveal(r)?queueMicrotask(()=>{r.model.isEmpty&&this._edgeGroupService?.includes(r)&&this.removeEdgeGroup(e)}):this.setEdgeGroupCollapsed(r,!0))});n.add(e,r,new Y(a,i)),t.autoHide!==void 0&&n.setAutoHide(r,t.autoHide),t.autoReveal!==void 0&&n.setAutoReveal(r,t.autoReveal),this._onDidAddGroup.fire(r);let o={element:r.element,get headerPosition(){return r.model.headerPosition},layout:(e,t)=>r.layout(e,t)};return this._shellManager.addEdgeView(e,t,o),r.api})}revealEdgeGroupWithData(e,t,n){let r=this._edgeGroupService;r&&this.mutation(`add`,()=>{let i=r.get(e);i||=(this.addEdgeGroup(e,{id:this.getNextGroupId(),autoReveal:!0,autoHide:n?.autoHide,collapsed:!0}),r.get(e)),i&&this.moveGroupOrPanel({from:{groupId:t.groupId,panelId:t.panelId??void 0},to:{group:i,position:`center`}})})}getEdgeGroup(e){var t;return(t=this._edgeGroupService)==null||(t=t.get(e))==null?void 0:t.api}getEdgeGroupPanel(e){return this._edgeGroupService?.get(e)}pinEdgeGroup(e){var t;(t=fJ(this._moduleRegistry.services.autoHideEdgeGroupService,`AutoHideEdgeGroup`,`api.pinEdgeGroup`))==null||t.pin(e)}autoHideEdgeGroup(e){var t;(t=fJ(this._moduleRegistry.services.autoHideEdgeGroupService,`AutoHideEdgeGroup`,`api.autoHideEdgeGroup`))==null||t.autoHide(e)}peekEdgeGroup(e,t){var n;(n=fJ(this._moduleRegistry.services.autoHideEdgeGroupService,`AutoHideEdgeGroup`,`api.peekEdgeGroup`))==null||n.peek(e,t)}get overlayRoot(){return this.rootElement}getDropZoneRect(){return this.element.getBoundingClientRect()}getEdgeGroupExpandedSize(e){return this._shellManager?.getEdgeGroupExpandedSize(e)??0}repositionPanelOverlay(e,t,n){this.overlayRenderContainer.repositionPanelOverlay(e.api.id,t,n)}setEdgeGroupVisible(e,t){this._shellManager.setEdgeGroupVisible(e,t)}isEdgeGroupVisible(e){return this._shellManager.isEdgeGroupVisible(e)}removeEdgeGroup(e){let t=fJ(this._edgeGroupService,`EdgeGroup`,`api.removeEdgeGroup`);if(!t)return;let n=t.get(e);if(!n)throw Error(`dockview: no edge group exists at position '${e}'`);this.mutation(`remove`,()=>{for(let e of[...n.panels])this.removePanel(e,{removeEmptyGroup:!1,skipDispose:!1});this._shellManager.removeEdgeView(e),t.remove(e),n.dispose(),this._groups.delete(n.id),this._onDidRemoveGroup.fire(n),this.activateFallbackGroupIfRemoved(n)})}setEdgeGroupCollapsed(e,t){let n=this._edgeGroupService?.findPositionOf(e);n&&this._shellManager.isEdgeGroupCollapsed(n)!==t&&(this._shellManager.setEdgeGroupCollapsed(n,t),e.api._onDidCollapsedChange.fire({isCollapsed:t}))}isEdgeGroupCollapsed(e){let t=this._edgeGroupService?.findPositionOf(e);return t?this._shellManager.isEdgeGroupCollapsed(t):!1}isEdgeGroupPeeking(e){return this._peekingGroups.has(e)}setEdgeGroupPeeking(e,t){this._peekingGroups.has(e)!==t&&(t?this._peekingGroups.add(e):this._peekingGroups.delete(e),e.api._onDidPeekChange.fire({isPeeking:t}))}isEdgeGroupAutoHide(e){let t=this._edgeGroupService?.isAutoHide(e);if(t!==void 0)return t;let n=this._edgeGroupService?.findPositionOf(e);return n!==void 0&&uq(this.options.autoHideEdgeGroups,n)}setEdgeGroupAutoHide(e,t){let n=this._edgeGroupService;n?.includes(e)&&(n.setAutoHide(e,t),this._onDidEdgeGroupAutoHideChange.fire(e))}updateDragAndDropState(){for(let e of this.groups)e.model.updateDragAndDropState()}focus(){var e;(e=this.activeGroup)==null||e.focus()}getGroupPanel(e){return this.panels.find(t=>t.id===e)}setActivePanel(e){e.group.model.openPanel(e),this.doSetGroupAndPanelActive(e.group)}activateNext(e={}){if(!e.group){if(!this.activeGroup)return;e.group=this.activeGroup}if(e.includePanel&&e.group&&e.group.activePanel!==e.group.panels[e.group.panels.length-1]){e.group.model.moveToNext({suppressRoll:!0});return}let t=this.activationTarget(e.group,!1);t&&this.doSetGroupAndPanelActive(t)}activatePrevious(e={}){if(!e.group){if(!this.activeGroup)return;e.group=this.activeGroup}if(e.includePanel&&e.group&&e.group.activePanel!==e.group.panels[0]){e.group.model.moveToPrevious({suppressRoll:!0});return}let t=this.activationTarget(e.group,!0);t&&this.doSetGroupAndPanelActive(t)}activationTarget(e,t){let n=this.getGridviewForGroup(e);if(n.element.contains(e.element)){let r=jG(e.element),i=(t?n.previous(r):n.next(r)).view;if(n===this.gridview||i!==e)return i}let r=[],i=e=>{IG(e)?e.children.forEach(i):r.push(e.view)};i(this.gridview.getView());let a=r.filter(e=>e.api.isVisible);return a[t?a.length-1:0]}toJSON(){let e=this.gridview.serialize(),t=this.panels.reduce((e,t)=>(e[t.id]=t.toJSON(),e),{}),n=this._floatingGroupService?.serialize()??[],r=this._popoutWindowService?.serialize()??[],i={grid:e,panels:t,activeGroup:this.activeGroup?.id};n.length>0&&(i.floatingGroups=n),r.length>0&&(i.popoutGroups=r);let a=this._serializeEdgeGroups();return a&&(i.edgeGroups=a),i}_serializeEdgeGroups(){if(!this._edgeGroupService?.hasAny())return;let e=this._shellManager.toJSON();for(let[t,n]of this._edgeGroupService.entries()){let r=e[t];if(!r)continue;if(this._edgeGroupService.isAutoReveal(n)&&n.model.isEmpty){delete e[t];continue}r.group=n.toJSON(),this._edgeGroupService.isAutoReveal(n)&&(r.autoReveal=!0);let i=this._edgeGroupService.isAutoHide(n);i!==void 0&&(r.autoHide=i)}return e}fromJSON(e,t){this.mutation(`load`,()=>this._doFromJSON(e,t))}_doFromJSON(e,t){var n;if((n=this._popoutWindowService)==null||n.cancelPendingRestorations(),typeof e!=`object`||!e)throw Error(`dockview: serialized layout must be a non-null object`);if(!e.grid||e.grid.root?.type!==`branch`||!Array.isArray(e.grid.root.data))throw Error(`dockview: root must be of type branch`);let r=new Map,i=new Map,a=[],o=[],s=()=>{for(let e of o)try{e.dispose()}catch(e){console.error(`dockview: failed to dispose a temporary group created for reuseExistingPanels`,e)}o.length=0};if(t?.reuseExistingPanels){let t=Object.keys(e.panels),n,c=()=>{let e=this.createGroup(),t=this._groups.get(e.api.id);return this._groups.delete(e.api.id),o.push(mW.from(()=>{var n;this.movingLock(()=>{for(let t of e.panels.slice())e.model.removePanel(t)}),t?.disposable.dispose(),(n=this.headerActionsService)==null||n.disposeGroup(e),e.dispose()})),e};try{for(let e of this.panels)if(t.includes(e.api.id)){r.set(e.api.id,e);let t;e.api.renderer===`always`&&e.api.isVisible?t=c():(n??=c(),t=n),i.set(e.api.id,t),a.push({panel:e,temporaryGroup:t})}this.movingLock(()=>{a.forEach(({panel:e,temporaryGroup:t})=>{this.moveGroupOrPanel({from:{groupId:e.api.group.api.id,panelId:e.api.id},to:{group:t,position:`center`},keepEmptyGroups:!0})})}),this.clear()}catch(e){throw s(),e}}else this.clear();let{grid:c,panels:l,activeGroup:u}=e;try{var d,f,p;let t=this.width,n=this.height,a=e=>{let{id:t,locked:n,hideHeader:a,headerPosition:o,views:s,activeView:c}=e;if(typeof t!=`string`)throw TypeError(`dockview: group id must be of type string`);let u=this.createGroup({id:t,locked:n??!1,hideHeader:!!a,headerPosition:o});this._onDidAddGroup.fire(u);let d=[],f=s.filter(e=>l[e]);for(let e of f){let t=r.get(e),n=i.get(e);if(n&&t)this.movingLock(()=>{n.model.removePanel(t)}),d.push(t),t.updateFromStateModel(l[e]);else{let t=this._deserializer.fromJSON(l[e],u);d.push(t)}}for(let e of d){let t=typeof c==`string`&&c===e.id;r.has(e.api.id)?this.movingLock(()=>{u.model.openPanel(e,{skipSetActive:!t,skipSetGroupActive:!0})}):u.model.openPanel(e,{skipSetActive:!t,skipSetGroupActive:!0})}return e.tabGroups&&e.tabGroups.length>0&&u.model.restoreTabGroups(e.tabGroups),!u.activePanel&&u.panels.length>0&&u.model.openPanel(u.panels[u.panels.length-1],{skipSetGroupActive:!0}),u};this.gridview.deserialize(c,{fromJSON:e=>a(e.data)}),this._layoutFromShell(t,n),e.edgeGroups&&this.deserializeEdgeGroups(e.edgeGroups,l,r,i),this.deserializeFloatingWindows(e.floatingGroups??[],a);let o=this.deserializePopoutWindows(e.popoutGroups??[],a);if((d=this._popoutWindowService)==null||d.finishRestoration(o),(f=this._floatingGroupService)==null||f.constrainBounds(),typeof u==`string`){let e=this.getPanel(u);e&&this.doSetGroupAndPanelActive(e)}(p=this._watermarkService)==null||p.update()}catch(e){var m;console.error(`dockview: failed to deserialize layout. Reverting changes`,e);for(let e of this.groups)for(let t of e.panels.slice())this.removePanel(t,{removeEmptyGroup:!1,skipDispose:!1});for(let e of this.groups)this._edgeGroupService?.includes(e)||(e.dispose(),this._groups.delete(e.id),this._onDidRemoveGroup.fire(e));throw(m=this._floatingGroupService)==null||m.disposeAll(),this.clear(),e}finally{s()}this.debouncedUpdateAllPositions(),this._onDidLayoutFromJSON.fire()}deserializeNestedGridview(e,t){let n=this.createNestedGridview(e.orientation),r=[];return n.deserialize(e,{fromJSON:e=>{let n=t(e.data);return r.push(n),n}}),{gridview:n,members:r}}deserializeEdgeGroups(e,t,n,r){let i=fJ(this._edgeGroupService,`EdgeGroup`,`fromJSON edge restoration`);if(i){for(let t of[`top`,`bottom`,`left`,`right`]){let n=e[t];if(n&&!i.has(t)){let e=n.group?.id??`${t}-group`;this.addEdgeGroup(t,{id:e,autoReveal:n.autoReveal,autoHide:n.autoHide,minimumSize:n.minimumSize,maximumSize:n.maximumSize,collapsedSize:n.collapsedSize})}}for(let[a,o]of i.entries()){let i=e[a]?.group;if(i){let{views:e,activeView:a,locked:s,hideHeader:c}=i;o.locked=s??!1,o.header.hidden=!!c;let l=[];for(let i of e){if(!t[i])continue;let e=n.get(i),a=r.get(i);if(a&&e)this.movingLock(()=>{a.model.removePanel(e)}),l.push(e),e.updateFromStateModel(t[i]);else{let e=this._deserializer.fromJSON(t[i],o);l.push(e)}}for(let e of l){let t=a===e.id;n.has(e.api.id)?this.movingLock(()=>{o.model.openPanel(e,{skipSetActive:!t,skipSetGroupActive:!0})}):o.model.openPanel(e,{skipSetActive:!t,skipSetGroupActive:!0})}i.tabGroups&&i.tabGroups.length>0&&o.model.restoreTabGroups(i.tabGroups),!o.activePanel&&o.panels.length>0&&o.model.openPanel(o.panels[o.panels.length-1],{skipSetGroupActive:!0})}}this._shellManager.fromJSON(e)}}deserializeFloatingWindows(e,t){for(let n of e){let{data:e,grid:r,position:i}=n;if(r){let{gridview:e,members:n}=this.deserializeNestedGridview(r,t);if(n.length===0)continue;this.mountFloatingWindow(e,n[0],n,i,{inDragMode:!1})}else if(e){let n=t(e);this.addFloatingGroup(n,{position:i,width:i.width,height:i.height,skipRemoveGroup:!0,inDragMode:!1})}}}deserializePopoutWindows(e,t){let n=e.length>0?fJ(this._popoutWindowService,`PopoutWindow`,`fromJSON popout restoration`):this._popoutWindowService;return n?e.flatMap((e,r)=>{let{data:i,grid:a,position:o,gridReferenceGroup:s,url:c}=e,l,u=[];if(a){let e=this.deserializeNestedGridview(a,t);if(l=e.gridview,u=e.members,u.length===0)return l.dispose(),[]}let d=a?u[0]:t(i);return n.scheduleRestoration(r*100,()=>this.addPopoutGroup(d,{position:o??void 0,overridePopoutGroup:s?d:void 0,overridePopoutGridview:l,referenceGroup:s?this.getPanel(s):void 0,popoutUrl:c}),()=>{for(let e of u.length>0?u:[d])if(!this.isDisposed&&this._groups.has(e.id)&&e.element.parentElement===null){for(let t of[...e.panels])this.removePanel(t,{removeEmptyGroup:!1});e.dispose(),this._groups.delete(e.id),this._onDidRemoveGroup.fire(e)}})}):[]}clear(){this.mutation(`clear`,()=>this._doClear())}_doClear(){let e=Array.from(this._groups.values()).map(e=>e.value),t=!!this.activeGroup;for(let t of e)if(this._edgeGroupService?.includes(t)){let e=[...t.panels];for(let t of e)this.removePanel(t,{removeEmptyGroup:!1})}else this.removeGroup(t,{skipActive:!0});t&&this.doSetGroupAndPanelActive(void 0),this.gridview.clear()}closeAllGroups(){this.mutation(`remove`,()=>{let e=Array.from(this._groups.values()).map(e=>e.value);for(let t of e){if(!this._groups.has(t.id))continue;t.model.closeAllPanels();let e=this.options.noPanelsOverlay===`emptyGroup`&&this.isLastGridGroup(t);!this.closeEmptyGroups&&!e&&this._groups.has(t.id)&&t.model.size===0&&this.removeGroup(t,{skipActive:!0})}})}addPanel(e){return this.mutation(`add`,()=>this._doAddPanel(e))}addPanelFromJSON(e,t){if(!e.contentComponent)throw Error(`dockview: serialized panel ${e.id} has no contentComponent`);return this.mutation(`add`,()=>{let n=this._doAddPanel($($({},t),{},{id:e.id,component:e.contentComponent,tabComponent:e.tabComponent,title:e.title,renderer:e.renderer,params:e.params,minimumWidth:e.minimumWidth,minimumHeight:e.minimumHeight,maximumWidth:e.maximumWidth,maximumHeight:e.maximumHeight}));return e.pinned&&this.setPanelPinned(n,!0),n})}_doAddPanel(e){if(this.panels.some(t=>t.id===e.id))throw Error(`dockview: panel with id ${e.id} already exists`);let t;if(e.position&&e.floating)throw Error(`dockview: you can only provide one of: position, floating as arguments to .addPanel(...)`);let n={width:e.initialWidth,height:e.initialHeight},r,i=t=>!!e.inactive&&t.model.size>0;if(e.position){if(mq(e.position)){let n=typeof e.position.referencePanel==`string`?this.getGroupPanel(e.position.referencePanel):e.position.referencePanel;if(r=e.position.index,!n){let t=typeof e.position.referencePanel==`string`?e.position.referencePanel:e.position.referencePanel?.id;throw Error(`dockview: referencePanel '${t}' does not exist`)}t=this.findGroup(n)}else if(hq(e.position)){if(t=typeof e.position.referenceGroup==`string`?this._groups.get(e.position.referenceGroup)?.value:e.position.referenceGroup,r=e.position.index,!t){let t=typeof e.position.referenceGroup==`string`?e.position.referenceGroup:e.position.referenceGroup?.id;throw Error(`dockview: referenceGroup '${t}' does not exist`)}}else{let t=this.orthogonalize(mK(e.position.direction)),a=this.createPanel(e,t);return t.model.openPanel(a,{skipSetActive:i(t),skipSetGroupActive:e.inactive,index:r}),e.inactive||this.doSetGroupAndPanelActive(t),t.api.setSize({height:n?.height,width:n?.width}),a}}else t=this.activeGroup;let a;if(t){let o=HG(e.position?.direction||`within`);if(e.floating){let t=this.createGroup();this._onDidAddGroup.fire(t);let n=typeof e.floating==`object`&&e.floating!==null?e.floating:{};this.addFloatingGroup(t,$($({},n),{},{inDragMode:!1,skipRemoveGroup:!0,skipActiveGroup:!0})),a=this.createPanel(e,t),t.model.openPanel(a,{skipSetActive:i(t),skipSetGroupActive:e.inactive,index:r})}else if(t.api.location.type===`edge`||o===`center`)a=this.createPanel(e,t),t.model.openPanel(a,{skipSetActive:i(t),skipSetGroupActive:e.inactive,index:r}),t.api.setSize({width:n?.width,height:n?.height}),e.inactive||this.doSetGroupAndPanelActive(t);else{let s=this.getGridviewForGroup(t),c=jG(t.element),l=MG(s.orientation,c,o),u=this.createGroupAtLocation(l,this.orientationAtLocation(l,s)===`VERTICAL`?n?.height:n?.width,void 0,s);a=this.createPanel(e,u),u.model.openPanel(a,{skipSetActive:i(u),skipSetGroupActive:e.inactive,index:r}),e.inactive||this.doSetGroupAndPanelActive(u)}}else if(e.floating){let t=this.createGroup();this._onDidAddGroup.fire(t);let n=typeof e.floating==`object`&&e.floating!==null?e.floating:{};this.addFloatingGroup(t,$($({},n),{},{inDragMode:!1,skipRemoveGroup:!0,skipActiveGroup:!0})),a=this.createPanel(e,t),t.model.openPanel(a,{skipSetActive:i(t),skipSetGroupActive:e.inactive,index:r})}else{let t=this.createGroupAtLocation([0],this.gridview.orientation===`VERTICAL`?n?.height:n?.width);a=this.createPanel(e,t),t.model.openPanel(a,{skipSetActive:i(t),skipSetGroupActive:e.inactive,index:r}),e.inactive||this.doSetGroupAndPanelActive(t)}return a}removePanel(e,t){this.mutation(`remove`,()=>this._doRemovePanel(e,{removeEmptyGroup:t?.removeEmptyGroup??this.closeEmptyGroups,skipDispose:t?.skipDispose,skipSetActiveGroup:t?.skipSetActiveGroup}))}_doRemovePanel(e,t){let n=e.group;if(!n)throw Error(`dockview: cannot remove panel ${e.id}. it's missing a group.`);n.model.removePanel(e,{skipSetActiveGroup:t.skipSetActiveGroup}),t.skipDispose||(e.group.model.renderContainer.detatch(e),e.dispose()),n.size===0&&t.removeEmptyGroup&&this.removeGroup(n,{skipActive:t.skipSetActiveGroup})}createWatermarkComponent(){return this.options.createWatermarkComponent?this.options.createWatermarkComponent():new nJ}addGroup(e){return this.mutation(`add`,()=>this._doAddGroup(e))}serializeGroup(e){let t={};for(let n of e.panels)t[n.id]=n.toJSON();return{group:e.model.toJSON(),panels:t}}addGroupFromJSON(e,t){return this.validateSerializedGroup(e),this.mutation(`add`,()=>this._doAddGroupFromJSON(e,t))}validateSerializedGroup(e){let t=e?.group;if(typeof t?.id!=`string`)throw TypeError(`dockview: group id must be of type string`);if(!Array.isArray(t.views))throw TypeError(`dockview: serialized group ${t.id} has no views`);for(let n of t.views){if(!e.panels?.[n])throw Error(`dockview: serialized group ${t.id} is missing panel state for ${n}`);if(this.panels.some(e=>e.id===n))throw Error(`dockview: panel with id ${n} already exists`)}}_doAddGroupFromJSON(e,t){let{id:n,locked:r,hideHeader:i,headerPosition:a,constraints:o,activeView:s,tabGroups:c}=e.group;if(t&&(t.direction??`within`)===`within`){let n=this.resolveReferenceGroup(t);if(n)return this.mergeGroupFromJSON(e,n,t)}let l={id:n,locked:r??!1,hideHeader:!!i,headerPosition:a,constraints:o,initialWidth:t?.initialWidth,initialHeight:t?.initialHeight,skipSetActive:!0},u=this.addEmptyGroupAt(l,t),d;try{d=this.deserializePanels(e,u)}catch(e){throw this.doRemoveGroup(u,{skipActive:!0}),e}for(let e of d)u.model.openPanel(e,{skipSetActive:e.id!==s,skipSetGroupActive:!0});return c&&c.length>0&&u.model.restoreTabGroups(c),!u.activePanel&&u.panels.length>0&&u.model.openPanel(u.panels[u.panels.length-1],{skipSetGroupActive:!0}),t?.skipSetActive||this.doSetGroupAndPanelActive(u),u}addEmptyGroupAt(e,t){if(t!==void 0&&(gq(t)||_q(t)||typeof t.direction==`string`))return this._doAddGroup($($({},t),e));let n=this.createGroup(e);return this.doAddGroup(n),n}deserializePanels(e,t){let n=[];try{for(let r of e.group.views)n.push(this._deserializer.fromJSON(e.panels[r],t))}catch(e){for(let e of n)e.dispose();throw e}return n}resolveReferenceGroup(e){if(gq(e)){let t=typeof e.referencePanel==`string`?e.referencePanel:e.referencePanel.id,n=this.getGroupPanel(t);if(!n)throw Error(`dockview: reference panel ${t} does not exist`);return n.group}if(_q(e)){let t=typeof e.referenceGroup==`string`?e.referenceGroup:e.referenceGroup.id,n=this.getPanel(t);if(!n)throw Error(`dockview: reference group ${t} does not exist`);return n}}mergeGroupFromJSON(e,t,n){let{activeView:r}=e.group,i=n.index;return this.deserializePanels(e,t).forEach((e,n)=>{t.model.openPanel(e,{index:i===void 0?void 0:i+n,skipSetActive:e.id!==r,skipSetGroupActive:!0})}),n.skipSetActive||this.doSetGroupAndPanelActive(t),t}_doAddGroup(e){if(e){let t;if(gq(e)){let n=typeof e.referencePanel==`string`?this.panels.find(t=>t.id===e.referencePanel):e.referencePanel,r=typeof e.referencePanel==`string`?e.referencePanel:e.referencePanel?.id;if(!n)throw Error(`dockview: reference panel ${r} does not exist`);if(t=this.findGroup(n),!t)throw Error(`dockview: reference group for reference panel ${r} does not exist`)}else if(_q(e)){if(t=typeof e.referenceGroup==`string`?this._groups.get(e.referenceGroup)?.value:e.referenceGroup,!t){let t=typeof e.referenceGroup==`string`?e.referenceGroup:e.referenceGroup?.id;throw Error(`dockview: reference group ${t} does not exist`)}}else{let t=this.orthogonalize(mK(e.direction),e);return e.skipSetActive||this.doSetGroupAndPanelActive(t),t}let n=HG(e.direction||`within`),r=this.getGridviewForGroup(t),i=jG(t.element),a=MG(r.orientation,i,n),o=this.orientationAtLocation(a,r)===`VERTICAL`?e.initialHeight:e.initialWidth,s=this.createGroupAtLocation(a,o,e,r);return e.skipSetActive||this.doSetGroupAndPanelActive(s),s}{let t=this.createGroup(e);return this.doAddGroup(t),this.doSetGroupAndPanelActive(t),t}}removeGroup(e,t){this.mutation(`remove`,()=>this.doRemoveGroup(e,t))}detachFromNestedWindow(e){let t=this._floatingGroupService?.findByGroup(e);if(t){let n=this.nestedWindowMembers(e);return n.length<=1?!1:(t.gridview.remove(e),t.group===e&&t.setAnchorGroup(n.find(t=>t!==e)),!0)}let n=this._popoutWindowService?.findByGroup(e);if(n){let t=this.nestedWindowMembers(e);return t.length<=1?!1:(n.gridview.remove(e),n.popoutGroup===e&&n.setAnchorGroup(t.find(t=>t!==e)),!0)}return!1}disposeGroupRecord(e){e.dispose(),this._groups.delete(e.id),this._onDidRemoveGroup.fire(e)}activateFallbackGroupIfRemoved(e,t){if(!t&&this._activeGroup===e){let e=Array.from(this._groups.values());this.doSetGroupAndPanelActive(e.length>0?e[0].value:void 0)}}doRemoveGroup(e,t){if(this._edgeGroupService?.includes(e))return e;let n=[...e.panels];if(!t?.skipDispose)for(let e of n)this.removePanel(e,{removeEmptyGroup:!1,skipDispose:t?.skipDispose??!1});let r=this.activePanel;if(e.api.location.type===`floating`){let n=this._floatingGroupService?.findByGroup(e);if(!n)throw Error(`dockview: failed to find floating group`);return this.detachFromNestedWindow(e)?(t?.skipDispose?e.model.location={type:`grid`}:this.disposeGroupRecord(e),this.activateFallbackGroupIfRemoved(e,t?.skipActive),e):(t?.skipDispose||this.disposeGroupRecord(e),n.dispose(),this.activateFallbackGroupIfRemoved(e,t?.skipActive),e)}if(e.api.location.type===`popout`){var i;let n=this._popoutWindowService?.findByGroup(e);if(!n)throw Error(`dockview: failed to find popout group`);if(this.detachFromNestedWindow(e))return t?.skipDispose?e.model.location={type:`grid`}:this.disposeGroupRecord(e),this.activateFallbackGroupIfRemoved(e,t?.skipActive),e;if(!t?.skipDispose){if(!t?.skipPopoutAssociated){let e=n.referenceGroup?this.getPanel(n.referenceGroup):void 0;e?.panels.length===0&&(this.closeEmptyGroups||!e.api.isVisible)&&this.removeGroup(e)}n.popoutGroup.dispose(),this._groups.delete(e.id),this._onDidRemoveGroup.fire(e)}(i=this._popoutWindowService)==null||i.remove(n);let r=n.disposable.dispose();return!t?.skipPopoutReturn&&r&&(this.doAddGroup(r,[0]),this.doSetGroupAndPanelActive(r)),this.activateFallbackGroupIfRemoved(e,t?.skipActive),n.popoutGroup}if(!this.gridview.element.contains(e.element))return t?.skipDispose||(this._groups.get(e.id)?.disposable.dispose(),this.disposeGroupRecord(e)),this.activateFallbackGroupIfRemoved(e,t?.skipActive),e;let a=super.doRemoveGroup(e,t);return t?.skipActive||this.activePanel!==r&&this.fireActivePanelChange(this.activePanel),a}debouncedUpdateAllPositions(){this._updatePositionsFrameId!==void 0&&cancelAnimationFrame(this._updatePositionsFrameId),this._updatePositionsFrameId=requestAnimationFrame(()=>{this._updatePositionsFrameId=void 0,this.overlayRenderContainer.updateAllPositions();for(let e of this._popoutWindowService?.entries??[])e.overlayRenderContainer.updateAllPositions()})}movingLock(e){let t=this._moving;try{return this._moving=!0,e()}finally{this._moving=t}}mutation(e,t){let n=this.openMutation(e);this._syncMutationDepth++;try{return t()}finally{this._syncMutationDepth--,this._syncMutationDepth===0&&this.releaseDisposedActiveGroup(),n()}}mutationAsync(e,t){var n=this;return nG(function*(){let r=n.openMutation(e);try{return yield t()}finally{r()}})()}openMutation(e){let t=this._origin;return this._mutationDepth===0&&this._onWillMutateLayout.fire({kind:e,origin:t}),this._mutationDepth++,()=>{this._mutationDepth--,this._mutationDepth===0&&(this.releaseDisposedActiveGroup(),this.flushLocationChanges(),this._onDidMutateLayout.fire({kind:e,origin:t}))}}releaseDisposedActiveGroup(){!this.isDisposed&&this._activeGroup?.model.isDisposed&&this.activateFallbackGroupIfRemoved(this._activeGroup)}deferLocationChange(e,t){this._mutationDepth===0?t():this._pendingLocationChanges.set(e,t)}flushLocationChanges(){if(this._pendingLocationChanges.size===0)return;let e=Array.from(this._pendingLocationChanges.values());this._pendingLocationChanges.clear();for(let t of e)t()}currentOrigin(){return this._origin}withOrigin(e,t){if(this._originDepth>0||this._mutationDepth>0)return t();let n=this._origin;this._origin=e,this._originDepth++;try{return t()}finally{this._originDepth--,this._origin=n}}fireActivePanelChange(e){this._onDidActivePanelChange.fire({panel:e,origin:this._origin})}fireDidMovePanel(e,t){this._onDidMovePanel.fire({panel:e,from:t,to:e.group})}moveGroupOrPanel(e){this.mutation(`move`,()=>this._doMoveGroupOrPanel(e))}_doMoveGroupOrPanel(e){let t=e.to.group,n=e.from.groupId,r=e.from.panelId,i=e.to.position,a=e.to.index,o=n?this._groups.get(n)?.value:void 0;if(!o)throw Error(`dockview: Failed to find group id ${n}`);if(r===void 0)e.from.tabGroupId?this.moveTabGroupToGroup({sourceGroup:o,tabGroupId:e.from.tabGroupId,destinationGroup:t,destinationTarget:i,destinationIndex:a,skipSetActive:e.skipSetActive,keepEmptyGroups:e.keepEmptyGroups}):this.moveGroup({from:{group:o},to:{group:t,position:i},skipSetActive:e.skipSetActive});else if(!i||i===`center`){let n=this.movingLock(()=>o.model.removePanel(r,{skipSetActive:!1,skipSetActiveGroup:!0}));if(!n)throw Error(`dockview: No panel with id ${r}`);!this.keepEmptyGroups(e)&&o.model.size===0&&o!==t&&this.doRemoveGroup(o,{skipActive:!0});let i=t.model.size===0;this.movingLock(()=>t.model.openPanel(n,{index:a,skipSetActive:(e.skipSetActive??!1)&&!i,skipSetGroupActive:!0})),e.skipSetActive||this.doSetGroupAndPanelActive(t),this.fireDidMovePanel(n,o)}else{let n=this.getGridviewForGroup(t),a=jG(t.element),s=MG(n.orientation,a,i);if(o.size<2&&!this.keepEmptyGroups(e)){if(o===t)return;let[e,c]=cG(s);if(o.api.location.type===`grid`&&n===this.gridview){let[n,i]=cG(jG(o.element));if((this.options.dropSizing!==`distribute`||o===t)&&lG(n,e)){this.gridview.moveView(n,i,c),this.fireDidMovePanel(this.getGroupPanel(r),o);return}}if(o.api.location.type===`popout`&&this.nestedWindowMembers(o).length<=1){let e=this._popoutWindowService?.findByGroup(o);if(!e)return;let a=this.movingLock(()=>e.popoutGroup.model.removePanel(e.popoutGroup.panels[0],{skipSetActive:!0,skipSetActiveGroup:!0}));this.doRemoveGroup(o,{skipActive:!0});let s=MG(n.orientation,jG(t.element),i),c=this.createGroupAtLocation(s,this.sizingForDrop(jG(t.element)),void 0,n);this.movingLock(()=>c.model.openPanel(a,{skipSetActive:!0})),this.doSetGroupAndPanelActive(c),this.fireDidMovePanel(this.getGroupPanel(r),o);return}if(o.api.location.type===`edge`){let e=this.movingLock(()=>o.model.removePanel(r,{skipSetActive:!1,skipSetActiveGroup:!0}));if(!e)throw Error(`dockview: No panel with id ${r}`);let t=this.createGroupAtLocation(s,this.sizingForDrop(a),void 0,n);this.movingLock(()=>t.model.openPanel(e,{skipSetGroupActive:!0})),this.doSetGroupAndPanelActive(t),this.fireDidMovePanel(e,o);return}let l=this.movingLock(()=>this.doRemoveGroup(o,{skipActive:!0,skipDispose:!0})),u=jG(t.element),d=MG(n.orientation,u,i);this.movingLock(()=>this.doAddGroup(l,d,this.sizingForDrop(u),n)),this.setGroupLocationForRoot(l,n),this.doSetGroupAndPanelActive(l),this.fireDidMovePanel(this.getGroupPanel(r),o)}else{let e=this.movingLock(()=>o.model.removePanel(r,{skipSetActive:!1,skipSetActiveGroup:!0}));if(!e)throw Error(`dockview: No panel with id ${r}`);let t=MG(n.orientation,a,i),s=this.createGroupAtLocation(t,this.sizingForDrop(a),void 0,n);this.movingLock(()=>s.model.openPanel(e,{skipSetGroupActive:!0})),this.doSetGroupAndPanelActive(s),this.fireDidMovePanel(e,o)}}}moveTabGroupToGroup(e){let{sourceGroup:t,tabGroupId:n,destinationGroup:r,destinationTarget:i,destinationIndex:a}=e,o=t.model.getTabGroups().find(e=>e.id===n);if(!o||o.panelIds.length===0)return;let s=o.label,c=o.color,l=o.collapsed,u=o.componentParams,d=[...o.panelIds],f=i&&i!==`center`?jG(r.element):void 0,p=this.movingLock(()=>d.map(e=>t.model.removePanel(e,{skipSetActive:!1,skipSetActiveGroup:!0})).filter(e=>e!==void 0));if(p.length===0)return;let m=n=>{this.movingLock(()=>{for(let e of p)n.model.openPanel(e,{index:a,skipSetActive:!0,skipSetGroupActive:!0})});let r=n.model.createTabGroup({label:s,color:c,collapsed:l,componentParams:u});for(let e of p)n.model.addPanelToTabGroup(r.id,e.id);e.skipSetActive||this.doSetGroupAndPanelActive(n);for(let e of p)this.fireDidMovePanel(e,t)},h;if(!i||i===`center`||!f)h=r;else{let e=this.getGridviewForGroup(r),t=MG(e.orientation,f,i);h=this.createGroupAtLocation(t,this.sizingForDrop(f),void 0,e)}!this.keepEmptyGroups(e)&&t.model.size===0&&t!==h&&this.doRemoveGroup(t,{skipActive:!0}),m(h)}moveGroup(e){this.mutation(`move`,()=>this._doMoveGroup(e))}maximizeGroup(e){this.mutation(`maximize`,()=>super.maximizeGroup(e))}exitMaximizedGroup(){this.mutation(`maximize`,()=>super.exitMaximizedGroup())}_doMoveGroup(e){let t=e.from.group,n=e.to.group,r=e.to.position;if(r===`center`&&t===n)return;let i=t,a;if(r===`center`){let r=t.activePanel,i=t.model.getTabGroups().map(e=>({label:e.label,color:e.color,collapsed:e.collapsed,componentParams:e.componentParams,panelIds:[...e.panelIds]})),o=this.movingLock(()=>[...t.panels].map(e=>t.model.removePanel(e.id,{skipSetActive:!0})));t?.model.size===0&&this.doRemoveGroup(t,{skipActive:!0}),this.movingLock(()=>{for(let e of o)n.model.openPanel(e,{skipSetActive:e!==r,skipSetGroupActive:!0})}),a=o;for(let e of i){let t=n.model.createTabGroup({label:e.label,color:e.color,collapsed:e.collapsed,componentParams:e.componentParams});for(let r of e.panelIds)n.model.addPanelToTabGroup(t.id,r)}e.skipSetActive===!0&&this.activePanel||this.doSetGroupAndPanelActive(n)}else{let e=(()=>{if(t.api.location.type===`edge`||n.api.location.type===`edge`)return!1;let e=this.getGridviewForGroup(t);if(e!==this.getGridviewForGroup(n))return!1;let i,a;try{i=jG(t.element),a=jG(n.element)}catch{return!1}return i.length===0||a.length===0?!1:lG(cG(i)[0],cG(a)[0])&&PG(e.orientation,a)===NG(r)})();if(t.api.location.type===`edge`){let e=t.activePanel,n=t.model.getTabGroups().map(e=>({label:e.label,color:e.color,collapsed:e.collapsed,componentParams:e.componentParams,panelIds:[...e.panelIds]})),r=this.movingLock(()=>[...t.panels].map(e=>t.model.removePanel(e.id,{skipSetActive:!0})));i=this.createGroup(),this._onDidAddGroup.fire(i),this.movingLock(()=>{for(let t of r)i.model.openPanel(t,{skipSetActive:t!==e,skipSetGroupActive:!0})});for(let e of n){let t=i.model.createTabGroup({label:e.label,color:e.color,collapsed:e.collapsed,componentParams:e.componentParams});for(let n of e.panelIds)i.model.addPanelToTabGroup(t.id,n)}}else switch(t.api.location.type){case`grid`:this.gridview.removeView(jG(t.element));break;case`floating`:{let e=this._floatingGroupService?.findByGroup(t);if(!e)throw Error(`dockview: failed to find floating group`);this.detachFromNestedWindow(t)||e.dispose();break}case`popout`:{var o;let e=this._popoutWindowService?.findByGroup(t);if(!e)throw Error(`dockview: failed to find popout group`);if(this.detachFromNestedWindow(t))break;if((o=this._popoutWindowService)==null||o.remove(e),e.referenceGroup){let t=this.getPanel(e.referenceGroup);t&&!t.api.isVisible&&this.doRemoveGroup(t,{skipActive:!0})}e.window.dispose();break}}if(n.api.location.type===`grid`||n.api.location.type===`floating`||n.api.location.type===`popout`){let a=this.getGridviewForGroup(n),o=jG(n.element),s=MG(a.orientation,o,r),c;c=e&&this.options.dropSizing!==`distribute`?NG(r)===`HORIZONTAL`?t.api.width:t.api.height:this.sizingForDrop(o),a.addView(i,c,s),this.setGroupLocationForRoot(i,a)}}if((a??i.panels).forEach(e=>{this.fireDidMovePanel(e,t)}),this.debouncedUpdateAllPositions(),e.skipSetActive===!1){let e=n??t;this.doSetGroupAndPanelActive(e)}else i!==t&&e.skipSetActive!==!0&&this.doSetGroupAndPanelActive(i)}doSetGroupActive(e){super.doSetGroupActive(e);let t=this.activePanel;!this._moving&&t!==this._onDidActivePanelChange.value?.panel&&this.fireActivePanelChange(t)}doSetGroupAndPanelActive(e){super.doSetGroupActive(e);let t=this.activePanel;e&&this.hasMaximizedGroup()&&!this.isMaximizedGroup(e)&&this.exitMaximizedGroup(),!this._moving&&t!==this._onDidActivePanelChange.value?.panel&&this.fireActivePanelChange(t)}getNextGroupId(){let e=this.options.groupIdGenerator;if(!e){let e=this.nextGroupId.next();for(;this._groups.has(e);)e=this.nextGroupId.next();return e}for(let t=0;t<EY;t++){let t=e();if(typeof t!=`string`||t.length===0)throw TypeError(`dockview: groupIdGenerator must return a non-empty string`);if(!this._groups.has(t))return t}throw Error(`dockview: groupIdGenerator returned an id already in use ${EY} times in a row`)}createGroup(e){e??={};let t=e?.id;t&&this._groups.has(e.id)&&(console.warn(`dockview: Duplicate group id ${e?.id}. reassigning group id to avoid errors`),t=void 0),t||=this.getNextGroupId();let n=new Yq(this,t,e);if(n.init({params:{},accessor:this}),!this._groups.has(n.id)){let e=new Y(n.model.onTabDragStart(e=>{var t;(t=this._advancedDnDService)==null||t.dispatchWillDragPanel(e)}),n.model.onGroupDragStart(e=>{var t;(t=this._advancedDnDService)==null||t.dispatchWillDragGroup(e)}),n.model.onMove(e=>{let{groupId:t,itemId:r,target:i,index:a,tabGroupId:o}=e;this.moveGroupOrPanel({from:{groupId:t,panelId:r,tabGroupId:o},to:{group:n,position:i,index:a}})}),n.model.onDidDrop(e=>{this._onDidDrop.fire(e)}),n.model.onWillDrop(e=>{var t;(t=this._advancedDnDService)==null||t.dispatchWillDrop(e)}),n.model.onWillShowOverlay(e=>{var t;this.options.disableDnd?e.preventDefault():(t=this._advancedDnDService)==null||t.dispatchWillShowOverlay(e)}),n.model.onUnhandledDragOver(e=>{this._onUnhandledDragOver.fire(e)}),n.model.onDidAddPanel(e=>{this._moving||this._onDidAddPanel.fire(e.panel)}),n.model.onDidRemovePanel(e=>{this._moving||this._onDidRemovePanel.fire(e.panel)}),n.model.onDidActivePanelChange(e=>{this._moving||e.panel===this.activePanel&&this._onDidActivePanelChange.value?.panel!==e.panel&&this.fireActivePanelChange(e.panel)}),n.model.onDidPanelTitleChange(()=>{this._bufferOnDidLayoutChange.fire(`panelTitle`)}),n.model.onDidPanelParametersChange(()=>{this._bufferOnDidLayoutChange.fire(`panelParameters`)}));this._groups.set(n.id,{value:n,disposable:e})}return n.initialize(),n}createPanel(e,t){let n=e.component,r=e.tabComponent??this.options.defaultTabComponent,i=new eJ(this,e.id,n,r),a=new Qq(e.id,n,r,this,this._api,t,i,{renderer:e.renderer,minimumWidth:e.minimumWidth,minimumHeight:e.minimumHeight,maximumWidth:e.maximumWidth,maximumHeight:e.maximumHeight});return a.init({title:e.title??e.id,params:e?.params??{}}),a}sizingForDrop(e){return this.options.dropSizing===`distribute`?bG.Distribute:bG.Split(e.length===0?0:e[e.length-1])}createGroupAtLocation(e,t,n,r=this.gridview){let i=this.createGroup(n);return this.doAddGroup(i,e,t,r),this.setGroupLocationForRoot(i,r),i}setGroupLocationForRoot(e,t){let n=this._popoutWindowService?.entries.find(e=>e.gridview===t);n?(e.model.renderContainer!==n.overlayRenderContainer&&(e.model.renderContainer=n.overlayRenderContainer),e.model.dropTargetContainer=n.dropTargetContainer,e.model.location={type:`popout`,getWindow:n.getWindow,popoutUrl:n.popoutUrl}):(e.model.renderContainer!==this.overlayRenderContainer&&(e.model.renderContainer=this.overlayRenderContainer),e.model.dropTargetContainer=this.rootDropTargetContainer,e.model.location=t===this.gridview?{type:`grid`}:{type:`floating`})}getGridviewForGroup(e){let t=this._floatingGroupService?.findByGroup(e);if(t)return t.gridview;let n=this._popoutWindowService?.findByGroup(e);return n?n.gridview:this.gridview}nestedWindowMembers(e){let t=this.getGridviewForGroup(e);return t===this.gridview?[]:this.groups.filter(e=>t.element.contains(e.element))}findGroup(e){return Array.from(this._groups.values()).find(t=>t.value.model.containsPanel(e))?.value}orientationAtLocation(e,t=this.gridview){let n=t.orientation;return e.length%2==1?n:FG(n)}updateTheme(){var e,t;let n=this._options.theme??Xq;(e=this._shellThemeClassnames)==null||e.setClassNames(n.className);let r=n.gap??0;this.gridview.margin=r;for(let e of this.nestedGridviews())e.margin=r;if((t=this._shellManager)==null||t.updateTheme(r,n.edgeGroupCollapsedSize??35),n.dndOverlayBorder===void 0){var i;this.element.style.removeProperty(`--dv-drag-over-border`),(i=this._shellManager)==null||i.element.style.removeProperty(`--dv-drag-over-border`)}else{var a;this.element.style.setProperty(`--dv-drag-over-border`,n.dndOverlayBorder),(a=this._shellManager)==null||a.element.style.setProperty(`--dv-drag-over-border`,n.dndOverlayBorder)}switch(n.dndOverlayMounting){case`absolute`:this.rootDropTargetContainer.disabled=!1;break;default:this.rootDropTargetContainer.disabled=!0}let o=(n.tabGroupIndicator??`wrap`)===`none`;Q(this.element,`dv-tab-group-indicator-none`,o),this._shellManager&&Q(this._shellManager.element,`dv-tab-group-indicator-none`,o);for(let e of this.groups)e.model.updateTabGroups()}},OY=class extends UG{get orientation(){return this.gridview.orientation}set orientation(e){this.gridview.orientation=e}get options(){return this._options}get deserializer(){return this._deserializer}set deserializer(e){this._deserializer=e}constructor(e,t){super(e,{proportionalLayout:t.proportionalLayout??!0,orientation:t.orientation,styles:t.hideBorders?{separatorBorder:`transparent`}:void 0,disableAutoResizing:t.disableAutoResizing,className:t.className}),this._onDidLayoutfromJSON=new X,this.onDidLayoutFromJSON=this._onDidLayoutfromJSON.event,this._onDidRemoveGroup=new X,this.onDidRemoveGroup=this._onDidRemoveGroup.event,this._onDidAddGroup=new X,this.onDidAddGroup=this._onDidAddGroup.event,this._onDidActiveGroupChange=new X,this.onDidActiveGroupChange=this._onDidActiveGroupChange.event,this._options=t,this.addDisposables(this._onDidAddGroup,this._onDidRemoveGroup,this._onDidActiveGroupChange,this.onDidAdd(e=>{this._onDidAddGroup.fire(e)}),this.onDidRemove(e=>{this._onDidRemoveGroup.fire(e)}),this.onDidActiveChange(e=>{this._onDidActiveGroupChange.fire(e)})),this.layoutFromElement()}updateOptions(e){super.updateOptions(e);let t=typeof e.orientation==`string`&&this.gridview.orientation!==e.orientation;this._options=$($({},this.options),e),t&&(this.gridview.orientation=e.orientation),this.layout(this.gridview.width,this.gridview.height,!0)}removePanel(e){this.removeGroup(e)}toJSON(){return{grid:this.gridview.serialize(),activePanel:this.activeGroup?.id}}setVisible(e,t){this.gridview.setViewVisible(jG(e.element),t)}setActive(e){this._groups.forEach((t,n)=>{t.value.setActive(e===t.value)})}focus(){var e;(e=this.activeGroup)==null||e.focus()}fromJSON(e){this.clear();let{grid:t,activePanel:n}=e;try{let e=[],r=this.width,i=this.height;if(this.gridview.deserialize(t,{fromJSON:t=>{let{data:n}=t,r=this.options.createComponent({id:n.id,name:n.component});return e.push(()=>r.init({params:n.params,minimumWidth:n.minimumWidth,maximumWidth:n.maximumWidth,minimumHeight:n.minimumHeight,maximumHeight:n.maximumHeight,priority:n.priority,snap:!!n.snap,accessor:this,isVisible:t.visible})),this._onDidAddGroup.fire(r),this.registerPanel(r),r}}),this.layout(r,i,!0),e.forEach(e=>e()),typeof n==`string`){let e=this.getPanel(n);e&&this.doSetGroupActive(e)}}catch(e){for(let e of this.groups)e.dispose(),this._groups.delete(e.id),this._onDidRemoveGroup.fire(e);throw this.clear(),e}this._onDidLayoutfromJSON.fire()}clear(){let e=this.activeGroup,t=Array.from(this._groups.values());for(let e of t)e.disposable.dispose(),this.doRemoveGroup(e.value,{skipActive:!0});e&&this.doSetGroupActive(void 0),this.gridview.clear()}movePanel(e,t){let n=this._groups.get(t.reference)?.value;if(!n)throw Error(`reference group ${t.reference} does not exist`);let r=HG(t.direction);if(r===`center`)throw Error(`${r} not supported as an option`);let i=jG(n.element),a=MG(this.gridview.orientation,i,r),o=this.gridview.remove(e);this.doAddGroup(o,a,t.size)}addPanel(e){let t=e.location??[0];if(e.position?.referencePanel){let n=this._groups.get(e.position.referencePanel)?.value;if(!n)throw Error(`reference group ${e.position.referencePanel} does not exist`);let r=HG(e.position.direction);if(r===`center`)throw Error(`${r} not supported as an option`);{let e=jG(n.element);t=MG(this.gridview.orientation,e,r)}}let n=this.options.createComponent({id:e.id,name:e.component});return n.init({params:e.params??{},minimumWidth:e.minimumWidth,maximumWidth:e.maximumWidth,minimumHeight:e.minimumHeight,maximumHeight:e.maximumHeight,priority:e.priority,snap:!!e.snap,accessor:this,isVisible:!0}),this.doAddGroup(n,t,e.size),this.registerPanel(n),this.doSetGroupActive(n),n}registerPanel(e){let t=new Y(e.api.onDidFocusChange(t=>{t.isFocused&&this._groups.forEach(t=>{let n=t.value;n.setActive(n===e)})}));this._groups.set(e.id,{value:e,disposable:t})}moveGroup(e,t,n){let r=this.getPanel(t);if(!r)throw Error(`invalid operation`);let i=jG(e.element),[a,o]=cG(MG(this.gridview.orientation,i,n)),[s,c]=cG(jG(r.element));if(lG(s,a)){this.gridview.moveView(s,c,o);return}let l=this.doRemoveGroup(r,{skipActive:!0,skipDispose:!0}),u=jG(e.element),d=MG(this.gridview.orientation,u,n);this.doAddGroup(l,d)}removeGroup(e){super.removeGroup(e)}dispose(){super.dispose(),this._onDidLayoutfromJSON.dispose()}},kY=class extends BG{get panels(){return this.splitview.getViews()}get options(){return this._options}get length(){return this._panels.size}get orientation(){return this.splitview.orientation}get splitview(){return this._splitview}set splitview(e){this._splitview&&this._splitview.dispose(),this._splitview=e,this._splitviewChangeDisposable.value=new Y(this._splitview.onDidSashEnd(()=>{this._onDidLayoutChange.fire({reasons:new Set([`geometry`])})}),this._splitview.onDidAddView(e=>this._onDidAddView.fire(e)),this._splitview.onDidRemoveView(e=>this._onDidRemoveView.fire(e)))}get minimumSize(){return this.splitview.minimumSize}get maximumSize(){return this.splitview.maximumSize}get height(){return this.splitview.orientation===`HORIZONTAL`?this.splitview.orthogonalSize:this.splitview.size}get width(){return this.splitview.orientation===`HORIZONTAL`?this.splitview.size:this.splitview.orthogonalSize}constructor(e,t){super(document.createElement(`div`),t.disableAutoResizing),this._splitviewChangeDisposable=new hW,this._panels=new Map,this._onDidLayoutfromJSON=new X,this.onDidLayoutFromJSON=this._onDidLayoutfromJSON.event,this._onDidAddView=new X,this.onDidAddView=this._onDidAddView.event,this._onDidRemoveView=new X,this.onDidRemoveView=this._onDidRemoveView.event,this._onDidLayoutChange=new X,this.onDidLayoutChange=this._onDidLayoutChange.event,this.element.style.height=`100%`,this.element.style.width=`100%`,this._classNames=new KW(this.element),this._classNames.setClassNames(t.className??``),e.appendChild(this.element),this._options=t,this.splitview=new xG(this.element,t),this.addDisposables(this._onDidAddView,this._onDidLayoutfromJSON,this._onDidRemoveView,this._onDidLayoutChange),this.layoutFromElement()}updateOptions(e){if(`className`in e&&this._classNames.setClassNames(e.className??``),`disableAutoResizing`in e&&(this.disableResizing=e.disableAutoResizing??!1),typeof e.orientation==`string`&&e.orientation!==this.splitview.orientation){this.splitview.orientation=e.orientation;for(let t of this.panels)t.orientation=e.orientation}this._options=$($({},this.options),e),this.splitview.layout(this.splitview.size,this.splitview.orthogonalSize)}focus(){var e;(e=this._activePanel)==null||e.focus()}movePanel(e,t){this.splitview.moveView(e,t)}setVisible(e,t){let n=this.panels.indexOf(e);this.splitview.setViewVisible(n,t)}setActive(e,t){this._activePanel=e,this.panels.filter(t=>t!==e).forEach(e=>{e.api._onDidActiveChange.fire({isActive:!1}),t||e.focus()}),e.api._onDidActiveChange.fire({isActive:!0}),t||e.focus()}removePanel(e,t){let n=this._panels.get(e.id);if(!n)throw Error(`unknown splitview panel ${e.id}`);n.dispose(),this._panels.delete(e.id);let r=this.panels.indexOf(e);this.splitview.removeView(r,t).dispose();let i=this.panels;i.length>0&&this.setActive(i[i.length-1])}getPanel(e){return this.panels.find(t=>t.id===e)}addPanel(e){if(this._panels.has(e.id))throw Error(`panel ${e.id} already exists`);let t=this.options.createComponent({id:e.id,name:e.component});t.orientation=this.splitview.orientation,t.init({params:e.params??{},minimumSize:e.minimumSize,maximumSize:e.maximumSize,snap:e.snap,priority:e.priority,accessor:this});let n=typeof e.size==`number`?e.size:bG.Distribute,r=typeof e.index==`number`?e.index:void 0;return this.splitview.addView(t,n,r),this.doAddView(t),this.setActive(t),t}layout(e,t){let[n,r]=this.splitview.orientation===`HORIZONTAL`?[e,t]:[t,e];this.splitview.layout(n,r)}doAddView(e){let t=e.api.onDidFocusChange(t=>{t.isFocused&&this.setActive(e,!0)});this._panels.set(e.id,t)}toJSON(){return{views:this.splitview.getViews().map((e,t)=>{let n=this.splitview.getViewCachedVisibleSize(t),r=typeof n==`number`;return $({size:r?n:this.splitview.getViewSize(t),data:e.toJSON(),snap:!!e.snap,priority:e.priority},r?{visible:!1}:{})}),activeView:this._activePanel?.id,size:this.splitview.size,orientation:this.splitview.orientation}}fromJSON(e){this.clear();let{views:t,orientation:n,size:r,activeView:i}=e,a=[],o=this.width,s=this.height;if(this.splitview=new xG(this.element,{orientation:n,proportionalLayout:this.options.proportionalLayout,descriptor:{size:r,views:t.map(e=>{let t=e.data;if(this._panels.has(t.id))throw Error(`panel ${t.id} already exists`);let r=this.options.createComponent({id:t.id,name:t.component});return a.push(()=>{r.init({params:t.params??{},minimumSize:t.minimumSize,maximumSize:t.maximumSize,snap:e.snap,priority:e.priority,accessor:this}),e.visible===!1&&r.setVisible(!1)}),r.orientation=n,this.doAddView(r),setTimeout(()=>{this._onDidAddView.fire(r)},0),{size:e.size,view:r,visible:e.visible}})}}),this.layout(o,s),a.forEach(e=>e()),typeof i==`string`){let e=this.getPanel(i);e&&this.setActive(e)}this._onDidLayoutfromJSON.fire()}clear(){for(let e of this._panels.values())e.dispose();for(this._panels.clear();this.splitview.length>0;)this.splitview.removeView(0,bG.Distribute,!0).dispose()}dispose(){for(let e of this._panels.values())e.dispose();this._panels.clear();let e=this.splitview.getViews();this._splitviewChangeDisposable.dispose(),this.splitview.dispose();for(let t of e)t.dispose();this.element.remove(),super.dispose()}},AY=class extends Y{get element(){return this._element}constructor(){super(),this._expandedIcon=YK(),this._collapsedIcon=XK(),this.disposable=new hW,this.apiRef={api:null},this._element=document.createElement(`div`),this.element.className=`dv-default-header`,this._content=document.createElement(`span`),this._expander=document.createElement(`div`),this._expander.className=`dv-pane-header-icon`,this.element.appendChild(this._expander),this.element.appendChild(this._content),this.addDisposables(Z(this._element,`click`,()=>{var e;(e=this.apiRef.api)==null||e.setExpanded(!this.apiRef.api.isExpanded)}))}init(e){this.apiRef.api=e.api,this._content.textContent=e.title,this.updateIcon(),this.disposable.value=e.api.onDidExpansionChange(()=>{this.updateIcon()})}updateIcon(){let e=!!this.apiRef.api?.isExpanded;Q(this._expander,`collapsed`,!e),e?(this._expander.contains(this._collapsedIcon)&&this._collapsedIcon.remove(),this._expander.contains(this._expandedIcon)||this._expander.appendChild(this._expandedIcon)):(this._expander.contains(this._expandedIcon)&&this._expandedIcon.remove(),this._expander.contains(this._collapsedIcon)||this._expander.appendChild(this._collapsedIcon))}update(e){}dispose(){this.disposable.dispose(),super.dispose()}},jY=hG(),MY=22,NY=0,PY=2**53-1,FY=class extends HK{constructor(e){super({accessor:e.accessor,id:e.id,component:e.component,headerComponent:e.headerComponent,orientation:e.orientation,isExpanded:e.isExpanded,disableDnd:e.disableDnd,headerSize:e.headerSize,minimumBodySize:e.minimumBodySize,maximumBodySize:e.maximumBodySize}),this.options=e}getBodyComponent(){return this.options.body}getHeaderComponent(){return this.options.header}},IY=class extends BG{get id(){return this._id}get panels(){return this.paneview.getPanes()}set paneview(e){this._paneview=e,this._disposable.value=new Y(this._paneview.onDidChange(()=>{this._onDidLayoutChange.fire({reasons:new Set([`geometry`])})}),this._paneview.onDidAddView(e=>this._onDidAddView.fire(e)),this._paneview.onDidRemoveView(e=>this._onDidRemoveView.fire(e)))}get paneview(){return this._paneview}get minimumSize(){return this.paneview.minimumSize}get maximumSize(){return this.paneview.maximumSize}get height(){return this.paneview.orientation===`HORIZONTAL`?this.paneview.orthogonalSize:this.paneview.size}get width(){return this.paneview.orientation===`HORIZONTAL`?this.paneview.size:this.paneview.orthogonalSize}get options(){return this._options}constructor(e,t){super(document.createElement(`div`),t.disableAutoResizing),this._id=jY.next(),this._disposable=new hW,this._viewDisposables=new Map,this._onDidLayoutfromJSON=new X,this.onDidLayoutFromJSON=this._onDidLayoutfromJSON.event,this._onDidLayoutChange=new X,this.onDidLayoutChange=this._onDidLayoutChange.event,this._onDidDrop=new X,this.onDidDrop=this._onDidDrop.event,this._onDidAddView=new X,this.onDidAddView=this._onDidAddView.event,this._onDidRemoveView=new X,this.onDidRemoveView=this._onDidRemoveView.event,this._onUnhandledDragOver=new X,this.onUnhandledDragOver=this._onUnhandledDragOver.event,this.element.style.height=`100%`,this.element.style.width=`100%`,this.addDisposables(this._onDidLayoutChange,this._onDidLayoutfromJSON,this._onDidDrop,this._onDidAddView,this._onDidRemoveView,this._onUnhandledDragOver),this._classNames=new KW(this.element),this._classNames.setClassNames(t.className??``),e.appendChild(this.element),this._options=t,this.paneview=new CG(this.element,{orientation:`VERTICAL`}),this.addDisposables(this._disposable)}setVisible(e,t){let n=this.panels.indexOf(e);this.paneview.setViewVisible(n,t)}focus(){}updateOptions(e){`className`in e&&this._classNames.setClassNames(e.className??``),`disableAutoResizing`in e&&(this.disableResizing=e.disableAutoResizing??!1),this._options=$($({},this.options),e)}addPanel(e){let t=this.options.createComponent({id:e.id,name:e.component}),n;e.headerComponent&&this.options.createHeaderComponent&&(n=this.options.createHeaderComponent({id:e.id,name:e.headerComponent})),n??=new AY;let r=new FY({id:e.id,component:e.component,headerComponent:e.headerComponent,header:n,body:t,orientation:`VERTICAL`,isExpanded:!!e.isExpanded,disableDnd:!!this.options.disableDnd,accessor:this,headerSize:e.headerSize??MY,minimumBodySize:NY,maximumBodySize:PY});this.doAddPanel(r);let i=typeof e.size==`number`?e.size:bG.Distribute,a=typeof e.index==`number`?e.index:void 0;return r.init({params:e.params??{},minimumBodySize:e.minimumBodySize,maximumBodySize:e.maximumBodySize,isExpanded:e.isExpanded,title:e.title,containerApi:new eK(this),accessor:this}),this.paneview.addPane(r,i,a),r.orientation=this.paneview.orientation,r}removePanel(e){let t=this.panels.indexOf(e);if(t<0)throw Error(`unknown paneview panel ${e.id}`);this.paneview.removePane(t),this.doRemovePanel(e)}movePanel(e,t){this.paneview.moveView(e,t)}getPanel(e){return this.panels.find(t=>t.id===e)}layout(e,t){let[n,r]=this.paneview.orientation===`HORIZONTAL`?[e,t]:[t,e];this.paneview.layout(n,r)}toJSON(){let e=e=>e===2**53-1||e===1/0?void 0:e,t=e=>e<=0?void 0:e;return{views:this.paneview.getPanes().map((n,r)=>{let i=this.paneview.getViewCachedVisibleSize(r),a=typeof i==`number`;return $({size:a?i:this.paneview.getViewSize(r),data:n.toJSON(),minimumSize:t(n.minimumBodySize),maximumSize:e(n.maximumBodySize),headerSize:n.headerSize,expanded:n.isExpanded()},a?{visible:!1}:{})}),size:this.paneview.size}}fromJSON(e){this.clear();let{views:t,size:n}=e,r=[],i=this.width,a=this.height;this.paneview.dispose(),this.paneview=new CG(this.element,{orientation:`VERTICAL`,descriptor:{size:n,views:t.map(e=>{let t=e.data,n=this.options.createComponent({id:t.id,name:t.component}),i;t.headerComponent&&this.options.createHeaderComponent&&(i=this.options.createHeaderComponent({id:t.id,name:t.headerComponent})),i??=new AY;let a=new FY({id:t.id,component:t.component,headerComponent:t.headerComponent,header:i,body:n,orientation:`VERTICAL`,isExpanded:!!e.expanded,disableDnd:!!this.options.disableDnd,accessor:this,headerSize:e.headerSize??MY,minimumBodySize:e.minimumSize??NY,maximumBodySize:e.maximumSize??PY});return this.doAddPanel(a),r.push(()=>{a.init({params:t.params??{},minimumBodySize:e.minimumSize,maximumBodySize:e.maximumSize,title:t.title,isExpanded:!!e.expanded,containerApi:new eK(this),accessor:this}),a.orientation=this.paneview.orientation,e.visible===!1&&a.setVisible(!1)}),setTimeout(()=>{this._onDidAddView.fire(a)},0),{size:e.size,view:a,visible:e.visible}})}}),this.layout(i,a),r.forEach(e=>e()),this._onDidLayoutfromJSON.fire()}clear(){for(let[e,t]of this._viewDisposables.entries())t.dispose();this._viewDisposables.clear();let e=this.width,t=this.height;this.paneview.dispose(),this.paneview=new CG(this.element,{orientation:`VERTICAL`}),this.layout(e,t)}doAddPanel(e){let t=new Y(e.onDidDrop(e=>{this._onDidDrop.fire(e)}),e.onUnhandledDragOver(e=>{this._onUnhandledDragOver.fire(e)}));this._viewDisposables.set(e.id,t)}doRemovePanel(e){let t=this._viewDisposables.get(e.id);t&&(t.dispose(),this._viewDisposables.delete(e.id))}dispose(){super.dispose();for(let[e,t]of this._viewDisposables.entries())t.dispose();this._viewDisposables.clear(),this.element.remove(),this.paneview.dispose()}},LY=class extends BK{get priority(){return this._priority}set orientation(e){this._orientation=e}get orientation(){return this._orientation}get minimumSize(){let e=typeof this._minimumSize==`function`?this._minimumSize():this._minimumSize;return e!==this._evaluatedMinimumSize&&(this._evaluatedMinimumSize=e,this.updateConstraints()),e}get maximumSize(){let e=typeof this._maximumSize==`function`?this._maximumSize():this._maximumSize;return e!==this._evaluatedMaximumSize&&(this._evaluatedMaximumSize=e,this.updateConstraints()),e}get snap(){return this._snap}constructor(e,t){super(e,t,new RK(e,t)),this._evaluatedMinimumSize=0,this._evaluatedMaximumSize=1/0,this._minimumSize=0,this._maximumSize=1/0,this._snap=!1,this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this.api.initialize(this),this.addDisposables(this._onDidChange,this.api.onWillVisibilityChange(e=>{let{isVisible:t}=e,{accessor:n}=this._params;n.setVisible(this,t)}),this.api.onActiveChange(()=>{let{accessor:e}=this._params;e.setActive(this)}),this.api.onDidConstraintsChangeInternal(e=>{(typeof e.minimumSize==`number`||typeof e.minimumSize==`function`)&&(this._minimumSize=e.minimumSize),(typeof e.maximumSize==`number`||typeof e.maximumSize==`function`)&&(this._maximumSize=e.maximumSize),this.updateConstraints()}),this.api.onDidSizeChange(e=>{this._onDidChange.fire({size:e.size})}))}setVisible(e){this.api._onDidVisibilityChange.fire({isVisible:e})}setActive(e){this.api._onDidActiveChange.fire({isActive:e})}layout(e,t){let[n,r]=this.orientation===`HORIZONTAL`?[e,t]:[t,e];super.layout(n,r)}init(e){super.init(e),this._priority=e.priority,e.minimumSize&&(this._minimumSize=e.minimumSize),e.maximumSize&&(this._maximumSize=e.maximumSize),e.snap&&(this._snap=e.snap)}toJSON(){return $($({},super.toJSON()),{},{minimumSize:(e=>e<=0?void 0:e)(this.minimumSize),maximumSize:(e=>e===2**53-1||e===1/0?void 0:e)(this.maximumSize)})}updateConstraints(){this.api._onDidConstraintsChange.fire({maximumSize:this._evaluatedMaximumSize,minimumSize:this._evaluatedMinimumSize})}};function RY(e,t){return new DY(e,t).api}function zY(e,t){return new $G(new kY(e,t))}function BY(e,t){return new tK(new OY(e,t))}function VY(e,t){return new eK(new IY(e,t))}function HY(e){"@babel/helpers - typeof";return HY=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},HY(e)}function UY(e,t){if(HY(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(HY(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function WY(e){var t=UY(e,`string`);return HY(t)==`symbol`?t:t+``}function GY(e,t,n){return(t=WY(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function KY(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function qY(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?KY(Object(n),!0).forEach(function(t){GY(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):KY(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var JY=(e,t)=>{let[,n]=V.useState(0),r=V.useRef(e.componentProps);return V.useImperativeHandle(t,()=>({update:e=>{r.current=qY(qY({},r.current),e),n(e=>e+1)}}),[]),V.createElement(e.component,r.current)};JY.displayName=`DockviewReactJsBridge`;var YY=(()=>{let e=1;return{next:()=>`dockview_react_portal_key_${(e++).toString()}`}})(),XY=V.createContext({}),ZY=class{constructor(e,t,n,r,i){this.parent=e,this.portalStore=t,this.component=n,this.parameters=r,this.context=i,this._initialProps={},this.disposed=!1,this.createPortal()}update(e){if(this.disposed)throw Error(`invalid operation: resource is already disposed`);this.componentInstance?this.componentInstance.update(e):this._initialProps=qY(qY({},this._initialProps),e)}createPortal(){if(this.disposed)throw Error(`invalid operation: resource is already disposed`);if(!$Y(this.component))throw Error(`Dockview: Only React.memo(...), React.ForwardRef(...) and functional components are accepted as components`);let e=V.createElement(V.forwardRef(JY),{component:this.component,componentProps:this.parameters,ref:e=>{this.componentInstance=e,Object.keys(this._initialProps).length>0&&(this.componentInstance.update(this._initialProps),this._initialProps={})}}),t=this.context?V.createElement(XY.Provider,{value:this.context},e):e,n=Xf.createPortal(t,this.parent,YY.next());this.ref={portal:n,disposable:this.portalStore.addPortal(n)}}dispose(){var e;(e=this.ref)==null||e.disposable.dispose(),this.disposed=!0}},QY=()=>{let[e,t]=V.useState([]);return V.useDebugValue(`Portal count: ${e.length}`),[e,V.useCallback(e=>{t(t=>[...t,e]);let n=!1;return mW.from(()=>{if(n)throw Error(`invalid operation: resource already disposed`);n=!0,t(t=>t.filter(t=>t!==e))})},[])]};function $Y(e){return typeof e==`function`||!!e?.$$typeof}function eX(e,t){let n=e=>e instanceof ShadowRoot?e.host:e.parentNode,r=new Set,i=new MutationObserver(n=>{if(!e.isConnected)i.disconnect(),t();else for(let e of n)for(let t of e.removedNodes)if(r.has(t)){a();return}}),a=()=>{i.disconnect(),r.clear();for(let t=n(e);t;t=n(t))r.add(t),i.observe(t,{childList:!0})};return a(),mW.from(()=>i.disconnect())}var tX=Number.parseInt(`19.3.1`,10)>=18;function nX(e,t,n){let r=V.useRef(void 0);V.useEffect(()=>{var i;let a=e.current;if(!a)return;(i=r.current)==null||i.dispose(),r.current=void 0;let o=t.current??n(a);return t.current=o,()=>{let e=()=>{r.current=void 0,t.current=void 0,o.dispose()};tX&&a.isConnected&&typeof MutationObserver<`u`?r.current=eX(a,e):e()}},[])}function rX(e){let t=V.useRef({instance:void 0,values:new Map});return V.useCallback(n=>{t.current.instance!==e.current&&(t.current={instance:e.current,values:new Map});let r=t.current.values,i=!0;for(let[e,t]of Object.entries(n))r.has(e)&&r.get(e)!==t&&(i=!1),r.set(e,t);return i},[e])}var iX=class{get element(){return this._element}constructor(e,t,n){this.id=e,this.component=t,this.reactPortalStore=n,this._onDidFocus=new X,this.onDidFocus=this._onDidFocus.event,this._onDidBlur=new X,this.onDidBlur=this._onDidBlur.event,this._element=document.createElement(`div`),this._element.className=`dv-react-part`,this._element.style.height=`100%`,this._element.style.width=`100%`}focus(){}init(e){this.part=new ZY(this.element,this.reactPortalStore,this.component,{params:e.params,api:e.api,containerApi:e.containerApi})}update(e){var t;(t=this.part)==null||t.update({params:e.params})}layout(e,t){}dispose(){var e;this._onDidFocus.dispose(),this._onDidBlur.dispose(),(e=this.part)==null||e.dispose()}},aX=class{get element(){return this._element}constructor(e,t,n){this.id=e,this.component=t,this.reactPortalStore=n,this._element=document.createElement(`div`),this._element.className=`dv-react-part`,this._element.style.height=`100%`,this._element.style.width=`100%`}focus(){}init(e){this.part=new ZY(this.element,this.reactPortalStore,this.component,{params:e.params,api:e.api,containerApi:e.containerApi,tabLocation:e.tabLocation})}update(e){var t;(t=this.part)==null||t.update({params:e.params})}layout(e,t){}dispose(){var e;(e=this.part)==null||e.dispose()}},oX=class{get element(){return this._element}constructor(e,t,n){this.id=e,this.component=t,this.reactPortalStore=n,this._element=document.createElement(`div`),this._element.className=`dv-react-part`,this._element.style.height=`100%`,this._element.style.width=`100%`}init(e){this.part=new ZY(this.element,this.reactPortalStore,this.component,{group:e.group,containerApi:e.containerApi})}focus(){}update(e){var t;this.parameters&&(this.parameters.params=e.params),(t=this.part)==null||t.update({params:this.parameters?.params??{}})}layout(e,t){}dispose(){var e;(e=this.part)==null||e.dispose()}},sX=class{get element(){return this._element}get part(){return this._part}constructor(e,t,n){this.component=e,this.reactPortalStore=t,this._group=n,this.mutableDisposable=new hW,this._element=document.createElement(`div`),this._element.className=`dv-react-part`,this._element.style.height=`100%`,this._element.style.width=`100%`}init(e){this.mutableDisposable.value=new Y(this._group.model.onDidAddPanel(()=>{this.updatePanels()}),this._group.model.onDidRemovePanel(()=>{this.updatePanels()}),this._group.model.onDidActivePanelChange(()=>{this.updateActivePanel()}),e.api.onDidActiveChange(()=>{this.updateGroupActive()}),e.api.onDidLocationChange(e=>{this.updateLocation(e.location)})),this._part=new ZY(this.element,this.reactPortalStore,this.component,{api:e.api,containerApi:e.containerApi,panels:this._group.model.panels,activePanel:this._group.model.activePanel,isGroupActive:this._group.api.isActive,group:this._group,headerPosition:this._group.model.headerPosition,location:e.api.location})}dispose(){var e;this.mutableDisposable.dispose(),(e=this._part)==null||e.dispose()}update(e){var t;(t=this._part)==null||t.update(e.params)}updatePanels(){this.update({params:{panels:this._group.model.panels}})}updateActivePanel(){this.update({params:{activePanel:this._group.model.activePanel}})}updateGroupActive(){this.update({params:{isGroupActive:this._group.api.isActive}})}updateLocation(e){this.update({params:{location:e}})}},cX=class{get element(){return this._element}constructor(e,t,n){this.id=e,this.component=t,this.reactPortalStore=n,this._element=document.createElement(`div`),this._element.className=`dv-react-part`,this._element.style.height=`100%`,this._element.style.width=`100%`}init(e){this.part=new ZY(this._element,this.reactPortalStore,this.component,e)}dispose(){var e;(e=this.part)==null||e.dispose()}},lX=class{get element(){return this._element}constructor(e,t){this.component=e,this.reactPortalStore=t,this._element=document.createElement(`div`),this._element.className=`dv-react-part`,this._element.style.display=`inline-flex`}init(e){this.part=new ZY(this._element,this.reactPortalStore,this.component,{tabGroup:e.tabGroup,api:e.api})}update(e){var t;(t=this.part)==null||t.update({tabGroup:e.tabGroup})}dispose(){var e;(e=this.part)==null||e.dispose()}},uX=class{get element(){return this._element}constructor(e,t){this.component=e,this.reactPortalStore=t,this._element=document.createElement(`div`),this._element.className=`dv-react-part`,this._element.style.display=`inline-flex`}init(e){this.part=new ZY(this._element,this.reactPortalStore,this.component,{group:e.group,api:e.api})}dispose(){var e;(e=this.part)==null||e.dispose()}};function dX(e,t){return e?n=>new sX(e,t,n):void 0}var fX=`props.defaultTabComponent`;function pX(e){return pq.reduce((t,n)=>(n in e&&(t[n]=e[n]),t),{})}var mX=V.forwardRef((e,t)=>{let n=V.useRef(null),r=V.useRef(void 0),[i,a]=QY(),o=rX(r);V.useImperativeHandle(t,()=>n.current,[]);let s=V.useRef({});return V.useEffect(()=>{let t={};pq.forEach(n=>{let r=n,i=e[r];r in e&&i!==s.current[r]&&(t[r]=i)}),r.current&&Object.keys(t).length>0&&r.current.updateOptions(t),s.current=e},pq.map(t=>e[t])),nX(n,r,t=>{let n=qY({},e.tabComponents);e.defaultTabComponent&&(n[fX]=e.defaultTabComponent);let r={createLeftHeaderActionComponent:dX(e.leftHeaderActionsComponent,{addPortal:a}),createRightHeaderActionComponent:dX(e.rightHeaderActionsComponent,{addPortal:a}),createPrefixHeaderActionComponent:dX(e.prefixHeaderActionsComponent,{addPortal:a}),createComponent:t=>new iX(t.id,e.components[t.name],{addPortal:a}),createTabComponent(e){return new aX(e.id,n[e.name],{addPortal:a})},createWatermarkComponent:e.watermarkComponent?()=>new oX(`watermark`,e.watermarkComponent,{addPortal:a}):void 0,defaultTabComponent:e.defaultTabComponent?fX:void 0,createContextMenuItemComponent:e=>{if(e.component)return new cX(e.id,e.component,{addPortal:a})}},i=pX(e);if(e.tabGroupChipComponent){let t=e.tabGroupChipComponent;i.createTabGroupChipComponent=()=>new lX(t,{addPortal:a})}if(e.groupDragGhostComponent){let t=e.groupDragGhostComponent;i.createGroupDragGhostComponent=()=>new uX(t,{addPortal:a})}let o=RY(t,qY(qY({},i),r)),{clientWidth:s,clientHeight:c}=t;return o.layout(s,c),e.onReady&&e.onReady({api:o}),o}),V.useEffect(()=>{if(!r.current)return()=>{};let t=r.current.onDidDrop(t=>{e.onDidDrop&&e.onDidDrop(t)});return()=>{t.dispose()}},[e.onDidDrop]),V.useEffect(()=>{if(!r.current)return()=>{};let t=r.current.onWillDrop(t=>{e.onWillDrop&&e.onWillDrop(t)});return()=>{t.dispose()}},[e.onWillDrop]),V.useEffect(()=>{r.current&&!o({tabGroupChipComponent:e.tabGroupChipComponent})&&r.current.updateOptions({createTabGroupChipComponent:e.tabGroupChipComponent?()=>new lX(e.tabGroupChipComponent,{addPortal:a}):void 0})},[e.tabGroupChipComponent]),V.useEffect(()=>{r.current&&!o({groupDragGhostComponent:e.groupDragGhostComponent})&&r.current.updateOptions({createGroupDragGhostComponent:e.groupDragGhostComponent?()=>new uX(e.groupDragGhostComponent,{addPortal:a}):void 0})},[e.groupDragGhostComponent]),V.useEffect(()=>{r.current&&!o({components:e.components})&&r.current.updateOptions({createComponent:t=>new iX(t.id,e.components[t.name],{addPortal:a})})},[e.components]),V.useEffect(()=>{if(!r.current||o({tabComponents:e.tabComponents,defaultTabComponent:e.defaultTabComponent}))return;let t=qY({},e.tabComponents);e.defaultTabComponent&&(t[fX]=e.defaultTabComponent),r.current.updateOptions({defaultTabComponent:e.defaultTabComponent?fX:void 0,createTabComponent(e){return new aX(e.id,t[e.name],{addPortal:a})}})},[e.tabComponents,e.defaultTabComponent]),V.useEffect(()=>{r.current&&!o({watermarkComponent:e.watermarkComponent})&&r.current.updateOptions({createWatermarkComponent:e.watermarkComponent?()=>new oX(`watermark`,e.watermarkComponent,{addPortal:a}):void 0})},[e.watermarkComponent]),V.useEffect(()=>{r.current&&!o({rightHeaderActionsComponent:e.rightHeaderActionsComponent})&&r.current.updateOptions({createRightHeaderActionComponent:dX(e.rightHeaderActionsComponent,{addPortal:a})})},[e.rightHeaderActionsComponent]),V.useEffect(()=>{r.current&&!o({leftHeaderActionsComponent:e.leftHeaderActionsComponent})&&r.current.updateOptions({createLeftHeaderActionComponent:dX(e.leftHeaderActionsComponent,{addPortal:a})})},[e.leftHeaderActionsComponent]),V.useEffect(()=>{r.current&&!o({prefixHeaderActionsComponent:e.prefixHeaderActionsComponent})&&r.current.updateOptions({createPrefixHeaderActionComponent:dX(e.prefixHeaderActionsComponent,{addPortal:a})})},[e.prefixHeaderActionsComponent]),V.createElement(`div`,{style:{height:`100%`,width:`100%`},ref:n},i)});mX.displayName=`DockviewComponent`;var hX=class extends LY{constructor(e,t,n,r){super(e,t),this.reactComponent=n,this.reactPortalStore=r}getComponent(){return new ZY(this.element,this.reactPortalStore,this.reactComponent,{params:this._params?.params??{},api:this.api,containerApi:new $G(this._params.accessor)})}};function gX(e){return SG.reduce((t,n)=>(n in e&&(t[n]=e[n]),t),{})}var _X=V.forwardRef((e,t)=>{let n=V.useRef(null),r=V.useRef(void 0),[i,a]=QY(),o=rX(r);V.useImperativeHandle(t,()=>n.current,[]);let s=V.useRef({});return V.useEffect(()=>{let t={};SG.forEach(n=>{let r=n,i=e[r];r in e&&i!==s.current[r]&&(t[r]=i)}),r.current&&Object.keys(t).length>0&&r.current.updateOptions(t),s.current=e},SG.map(t=>e[t])),nX(n,r,t=>{let n=zY(t,qY(qY({},gX(e)),{createComponent:t=>new hX(t.id,t.name,e.components[t.name],{addPortal:a})})),{clientWidth:r,clientHeight:i}=t;return n.layout(r,i),e.onReady&&e.onReady({api:n}),n}),V.useEffect(()=>{r.current&&!o({components:e.components})&&r.current.updateOptions({createComponent:t=>new hX(t.id,t.name,e.components[t.name],{addPortal:a})})},[e.components]),V.createElement(`div`,{style:{height:`100%`,width:`100%`},ref:n},i)});_X.displayName=`SplitviewComponent`;var vX=class extends Wq{constructor(e,t,n,r){super(e,t),this.reactComponent=n,this.reactPortalStore=r}getComponent(){return new ZY(this.element,this.reactPortalStore,this.reactComponent,{params:this._params?.params??{},api:this.api,containerApi:new tK(this._params.accessor)})}};function yX(e){return zG.reduce((t,n)=>(n in e&&(t[n]=e[n]),t),{})}var bX=V.forwardRef((e,t)=>{let n=V.useRef(null),r=V.useRef(void 0),[i,a]=QY(),o=rX(r);V.useImperativeHandle(t,()=>n.current,[]);let s=V.useRef({});return V.useEffect(()=>{let t={};zG.forEach(n=>{let r=n,i=e[r];r in e&&i!==s.current[r]&&(t[r]=i)}),r.current&&Object.keys(t).length>0&&r.current.updateOptions(t),s.current=e},zG.map(t=>e[t])),nX(n,r,t=>{let n=BY(t,qY(qY({},yX(e)),{createComponent:t=>new vX(t.id,t.name,e.components[t.name],{addPortal:a})})),{clientWidth:r,clientHeight:i}=t;return n.layout(r,i),e.onReady&&e.onReady({api:n}),n}),V.useEffect(()=>{r.current&&!o({components:e.components})&&r.current.updateOptions({createComponent:t=>new vX(t.id,t.name,e.components[t.name],{addPortal:a})})},[e.components]),V.createElement(`div`,{style:{height:`100%`,width:`100%`},ref:n},i)});bX.displayName=`GridviewComponent`;var xX=class{get element(){return this._element}constructor(e,t,n){this.id=e,this.component=t,this.reactPortalStore=n,this._element=document.createElement(`div`),this._element.style.height=`100%`,this._element.style.width=`100%`}init(e){this.part=new ZY(this.element,this.reactPortalStore,this.component,{params:e.params,api:e.api,title:e.title,containerApi:e.containerApi})}toJSON(){return{id:this.id}}update(e){var t;(t=this.part)==null||t.update({params:e.params})}dispose(){var e;(e=this.part)==null||e.dispose()}};function SX(e){return PK.reduce((t,n)=>(n in e&&(t[n]=e[n]),t),{})}var CX=V.forwardRef((e,t)=>{let n=V.useRef(null),r=V.useRef(void 0),[i,a]=QY(),o=rX(r);V.useImperativeHandle(t,()=>n.current,[]);let s=V.useRef({});return V.useEffect(()=>{let t={};PK.forEach(n=>{let r=n,i=e[r];r in e&&i!==s.current[r]&&(t[r]=i)}),r.current&&Object.keys(t).length>0&&r.current.updateOptions(t),s.current=e},PK.map(t=>e[t])),nX(n,r,t=>{let n=e.headerComponents??{},r=VY(t,qY(qY({},SX(e)),{createComponent:t=>new xX(t.id,e.components[t.name],{addPortal:a}),createHeaderComponent:e=>new xX(e.id,n[e.name],{addPortal:a})})),{clientWidth:i,clientHeight:o}=t;return r.layout(i,o),e.onReady&&e.onReady({api:r}),r}),V.useEffect(()=>{r.current&&!o({components:e.components})&&r.current.updateOptions({createComponent:t=>new xX(t.id,e.components[t.name],{addPortal:a})})},[e.components]),V.useEffect(()=>{if(!r.current||o({headerComponents:e.headerComponents}))return;let t=e.headerComponents??{};r.current.updateOptions({createHeaderComponent:e=>new xX(e.id,t[e.name],{addPortal:a})})},[e.headerComponents]),V.useEffect(()=>{if(!r.current)return()=>{};let t=r.current.onDidDrop(t=>{e.onDidDrop&&e.onDidDrop(t)});return()=>{t.dispose()}},[e.onDidDrop]),V.createElement(`div`,{style:{height:`100%`,width:`100%`},ref:n},i)});CX.displayName=`PaneviewComponent`;var wX={dock:`_dock_psx21_10`,tab:`_tab_psx21_155`,buttons:`_buttons_psx21_178`,body:`_body_psx21_189`,heading:`_heading_psx21_197`,none:`_none_psx21_209`},TX=({label:e,shortcut:t,onClick:n,children:r})=>{let i=ET();return(0,G.jsx)(cb,{"aria-keyshortcuts":bT(t,i),keys:yT(t,i),label:e,onClick:n,children:r})},EX=({group:e,activePanel:t,workspace:n})=>{ab(n.view);let r=t?.title??`panel`,i=t!==void 0&&tW(t.id)?t.id:void 0,a=e.api.location.type===`floating`,o=e.api.isMaximized();return(0,G.jsxs)(`div`,{className:wX.buttons,children:[(0,G.jsx)(TX,{label:`Minimize ${r}`,onClick:()=>{n.minimize(i)},shortcut:CT.minimize,children:(0,G.jsx)(ay,{})}),a?null:(0,G.jsx)(TX,{label:o?`Restore ${r}`:`Maximize ${r}`,onClick:()=>{n.toggleMaximize(e)},shortcut:CT.maximize,children:o?(0,G.jsx)(sy,{}):(0,G.jsx)(oy,{})}),(0,G.jsx)(TX,{label:a?`Dock ${r}`:`Float ${r}`,onClick:()=>{n.toggleFloat(e)},shortcut:CT.float,children:a?(0,G.jsx)(ly,{}):(0,G.jsx)(cy,{})}),(0,G.jsx)(TX,{label:`Close ${r}`,onClick:()=>{n.close(i)},shortcut:CT.close,children:(0,G.jsx)(Jv,{})})]})},DX=e=>{let t=(0,V.use)(ZM);return t===null?null:(0,G.jsx)(EX,{...e,workspace:t})},OX=6,kX=({api:e})=>{let t=tW(e.id)?nW(e.id).Icon:null;return(0,G.jsxs)(`span`,{className:wX.tab,children:[t===null?null:(0,G.jsx)(t,{}),e.title]})},AX=()=>(0,G.jsx)(`div`,{className:wX.none,children:(0,G.jsx)(CC,{title:`No panels open.`,children:`Reopen one from Window, or press the command palette's keys.`})}),jX=Object.fromEntries(eW.map(({id:e,title:t,Body:n})=>[e,()=>(0,G.jsxs)(`div`,{className:wX.body,children:[(0,G.jsx)(`h2`,{className:wX.heading,children:t}),(0,G.jsx)(n,{})]})])),MX={name:`ork`,className:wX.dock??``,gap:OX,dndOverlayMounting:`relative`,dndPanelOverlay:`group`,dndTabIndicator:`line`},NX=({workspace:e})=>{let t=(0,V.useCallback)(({api:t})=>{e.attach(t)},[e]);return(0,V.useEffect)(()=>()=>{e.detach()},[e]),(0,G.jsx)(mX,{announcer:({message:t})=>{e.announceFromDock(t)},components:jX,defaultTabComponent:kX,disableTabsOverflowList:!0,onReady:t,rightHeaderActionsComponent:DX,theme:MX,watermarkComponent:AX})},PX=`(min-width: 64rem)`,FX=(e,t,n)=>{let r=e?.panels??[],i=e?.activePanel?.id;return{wide:n,open:eW.map(e=>e.id).filter(e=>r.some(t=>t.id===e)),minimized:t.minimized.map(e=>e.id),folded:t.folded,active:i!==void 0&&tW(i)?i:null,floating:e?.activePanel?.group.api.location.type===`floating`,maximized:e?.hasMaximizedGroup()??!1}},IX=(e,t)=>JSON.stringify(e)===JSON.stringify(t),LX=e=>`stack-${e}`,RX=e=>`rail-${e}`,zX=e=>{document.querySelector(`#${e}`)?.focus()},BX=({workspace:e})=>{let{minimized:t}=ab(e.view);return t.length===0?null:(0,G.jsx)(`nav`,{"aria-label":`Minimized panels`,className:kT.rail,children:t.map(t=>{let{title:n,Icon:r}=nW(t);return(0,G.jsx)(cb,{id:RX(t),label:`Restore ${n}`,onClick:()=>{e.restore(t)},children:(0,G.jsx)(r,{})},t)})})},VX=({workspace:e})=>{let{folded:t}=ab(e.view);return(0,G.jsx)(`div`,{className:kT.stack,children:eW.map(({id:n,title:r,Icon:i,Body:a})=>{let o=!t.includes(n),s=`${LX(n)}-body`;return(0,G.jsxs)(`section`,{"aria-labelledby":LX(n),className:kT.stacked,children:[(0,G.jsx)(`h2`,{className:kT.stackedHeading,children:(0,G.jsxs)(`button`,{"aria-controls":o?s:void 0,"aria-expanded":o,className:kT.stackedButton,id:LX(n),onClick:()=>{e.toggleFold(n)},type:`button`,children:[o?(0,G.jsx)(Xv,{}):(0,G.jsx)(Zv,{}),(0,G.jsx)(i,{}),r]})}),o?(0,G.jsx)(`div`,{className:kT.stackedBody,id:s,children:(0,G.jsx)(a,{})}):null]},n)})})},HX=e=>{(0,V.useEffect)(()=>{let t=window.matchMedia(PX),n=()=>{e.setWide(t.matches)};return n(),t.addEventListener(`change`,n),()=>{t.removeEventListener(`change`,n)}},[e])},UX=({workspace:e})=>{let{wide:t}=ab(e.view);return HX(e),(0,G.jsx)(`main`,{className:kT.middle,children:t?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(BX,{workspace:e}),(0,G.jsx)(`div`,{className:kT.dockArea,children:(0,G.jsx)(NX,{workspace:e})})]}):(0,G.jsx)(VX,{workspace:e})})},WX=`ork-new-version-action`,GX=(e,t,n)=>e?.version===t&&n-Date.parse(e.at)<864e5,KX=(e,t,n)=>{let{job:r}=e;if(r!==null)return r.state===`running`?{kind:`running`,latest:r.latest}:GX(t,r.latest,n)?null:r.state===`succeeded`?{kind:`installed`,latest:r.latest,current:e.current}:{kind:`failed`,latest:r.latest,code:r.code??1}},qX=({info:e,connection:t,pageVersion:n,dismissed:r,now:i})=>{let{server:a}=t;if(t.link!==`open`||a===null||`error`in a)return null;if(n!==null&&a.version!==n)return{kind:`pageOlder`,page:n,server:a.version};if(e===null)return null;let o=KX(e,r,i);if(o!==void 0)return o;let{newer:s,releaseNotes:c}=e;return s===null||c===null||GX(r,s,i)?null:{kind:`newer`,newer:s,current:e.current,releaseNotes:c}},JX=e=>e===null?`none`:`${e.kind}:${`newer`in e?e.newer:`latest`in e?e.latest:e.server}`,YX=e=>e?.kind===`newer`?`Ork ${e.newer} is out. Upgrade… is above the panels.`:e?.kind===`installed`?`Ork ${e.latest} is installed; restart \`ork ui\` to use it.`:e?.kind===`pageOlder`?`This page is from an older Ork. Reload to use ${e.server}.`:null,XX=e=>e.kind===`newer`?e.newer:e.kind===`installed`||e.kind===`failed`?e.latest:null,ZX={slot:`_slot_s34lg_8`,banner:`_banner_s34lg_14`,icon:`_icon_s34lg_43`,line:`_line_s34lg_52`,version:`_version_s34lg_59`,link:`_link_s34lg_71`,spacer:`_spacer_s34lg_82`,facts:`_facts_s34lg_86`,factName:`_factName_s34lg_99`,factValue:`_factValue_s34lg_114`,adviceWords:`_adviceWords_s34lg_125`,note:`_note_s34lg_131`,message:`_message_s34lg_142`,alert:`_alert_s34lg_149`,alertIcon:`_alertIcon_s34lg_168`,heading:`_heading_s34lg_175`,glyph:`_glyph_s34lg_189`,clock:`_clock_s34lg_200`,foot:`_foot_s34lg_210`,actions:`_actions_s34lg_220`},QX=({latest:e,current:t})=>(0,G.jsxs)(`p`,{className:ZX.line,children:[`Ork`,` `,(0,G.jsx)(`span`,{className:ZX.version,"data-new":``,children:e}),` `,`is out (you have `,(0,G.jsx)(`span`,{className:ZX.version,children:t}),`).`]}),$X=({url:e,version:t,children:n})=>(0,G.jsxs)(`a`,{className:ZX.link,href:e,rel:`noreferrer`,target:`_blank`,children:[n,t===void 0?null:(0,G.jsx)(zw,{children:` in ${t}`}),(0,G.jsx)(Sy,{}),(0,G.jsx)(zw,{children:` (opens in a new tab)`})]}),eZ=8,tZ=({ids:e})=>{if(e.length===0)return null;let t=e.slice(0,eZ).map(e=>`\`${e.slice(0,8)}\``),n=e.length-eZ,r=n>0?`${t.join(`, `)} and ${String(n)} more`:t.join(`, `);return(0,G.jsxs)(`p`,{className:ZX.alert,"data-tone":`note`,children:[(0,G.jsx)(`span`,{className:ZX.alertIcon,children:(0,G.jsx)(yy,{})}),(0,G.jsx)(`span`,{children:(0,G.jsx)(Wg,{text:`Running now: ${r}. Their next sessions would start from the new install; upgrading after they finish is safer.`})})]})},nZ=()=>{let e=document.activeElement;return e===null||e===document.body||e.getAttribute(`role`)===`dialog`},rZ=({tone:e,text:t,ref:n})=>{let r=(0,V.useRef)(null),i=n??r;return(0,V.useLayoutEffect)(()=>{i.current?.focus()},[i]),(0,V.useEffect)(()=>{let e=requestAnimationFrame(()=>{e=requestAnimationFrame(()=>{nZ()&&i.current?.focus()})});return()=>{cancelAnimationFrame(e)}},[i]),(0,G.jsxs)(`h3`,{className:ZX.heading,ref:i,tabIndex:-1,children:[e===void 0?null:(0,G.jsx)(`span`,{className:ZX.glyph,"data-tone":e,children:e===`succeeded`?(0,G.jsx)(aD,{}):(0,G.jsx)(cD,{})}),(0,G.jsx)(`span`,{children:(0,G.jsx)(Wg,{text:t})})]})},iZ=({since:e})=>{let t=sz(!0),n=Math.max(0,Math.floor((t-e)/1e3));return(0,G.jsx)(`span`,{"aria-hidden":`true`,className:ZX.clock,children:`${String(n)} s`})},aZ=({text:e,icon:t=!1})=>e===null?null:(0,G.jsxs)(`p`,{className:ZX.alert,role:`alert`,children:[t?(0,G.jsx)(yy,{}):null,(0,G.jsx)(`span`,{children:(0,G.jsx)(Wg,{text:e})})]}),oZ=({why:e,id:t})=>(0,G.jsx)(`output`,{className:ZX.note,id:t,children:(0,G.jsx)(Wg,{text:e??``})}),sZ=({note:e,children:t})=>(0,G.jsxs)(`div`,{className:ZX.foot,children:[e===void 0?null:(0,G.jsx)(`p`,{className:ZX.note,children:(0,G.jsx)(Wg,{text:e})}),(0,G.jsx)(`div`,{className:ZX.actions,children:t})]}),cZ=`Dismissed for a day. Upgrade Ork… is in Commands.`,lZ=(e,t,n,r)=>{let i=(0,V.useRef)(null),a=JX(e);(0,V.useEffect)(()=>{if(!t)return;let o=i.current;if(i.current=a,o===null||o===a||n)return;let s=YX(e);s!==null&&r.announce(s)},[e,a,t,n,r])},uZ=()=>{let[e,t]=(0,V.useState)(Date.now);return(0,V.useEffect)(()=>{let e=setInterval(()=>{t(Date.now())},6e4);return()=>{clearInterval(e)}},[]),e},dZ=()=>{window.location.reload()},fZ={newer:{label:`Upgrade…`,primary:!0,opens:`ask`},running:{label:`Show output`,primary:!1,opens:`job`},failed:{label:`Show output`,primary:!1,opens:`job`},installed:{label:`Restart…`,primary:!0,opens:`job`},pageOlder:{label:`Reload`,primary:!0,opens:null}},pZ=e=>e.kind===`running`?`Upgrading Ork to ${e.latest}…`:e.kind===`failed`?`The upgrade to ${e.latest} did not finish: exit ${String(e.code)}.`:e.kind===`installed`?`Ork ${e.latest} is installed. \`ork ui\` still runs ${e.current} until it restarts.`:`This page is from Ork ${e.page}; \`ork ui\` now runs ${e.server}.`,mZ=({banner:e,onOpen:t})=>{let n=fZ[e.kind];return(0,G.jsxs)(G.Fragment,{children:[e.kind===`newer`?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(QX,{current:e.current,latest:e.newer}),(0,G.jsx)($X,{url:e.releaseNotes,version:e.newer,children:`What changed`})]}):(0,G.jsx)(`p`,{className:ZX.line,children:(0,G.jsx)(Wg,{text:pZ(e)})}),(0,G.jsx)(`span`,{className:ZX.spacer}),(0,G.jsx)(q,{cli:e.kind===`newer`?`ork upgrade`:void 0,id:WX,onClick:()=>{n.opens===null?dZ():t(n.opens)},variant:n.primary?`primary`:`default`,children:n.label})]})},hZ=({workspace:e})=>{let{version:t,connection:n,preferences:r}=qy(),i=ab(t.info),a=ab(n),o=ab(r.value),s=ab(t.dialog),c=uZ(),l=qX({info:i,connection:a,pageVersion:t.pageVersion,dismissed:o.updateDismissed,now:c});lZ(l,i!==null&&a.server!==null,s!==null,e);let u=l===null?null:XX(l);return(0,G.jsx)(`div`,{className:ZX.slot,children:l===null?null:(0,G.jsxs)(`section`,{"aria-label":`New version`,className:ZX.banner,children:[(0,G.jsx)(`span`,{className:ZX.icon,children:(0,G.jsx)(zy,{})}),(0,G.jsx)(mZ,{banner:l,onOpen:t.openDialog}),u===null?null:(0,G.jsx)(cb,{label:`Dismiss for a day`,onClick:()=>{r.update({updateDismissed:{version:u,at:new Date().toISOString()}}),e.announce(cZ),e.focusPanels()},children:(0,G.jsx)(Jv,{})})]})})},gZ=e=>e===null?`Asking the npm registry for the latest version…`:`Asking the registry at \`${e}\` for the latest version…`,_Z=({plan:e})=>(0,G.jsxs)(`dl`,{className:ZX.facts,children:[(0,G.jsx)(`dt`,{className:ZX.factName,children:`Installed with`}),(0,G.jsx)(`dd`,{className:ZX.factValue,children:e.installer?.label??`Ork couldn't tell`}),e.kind===`command`?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`dt`,{className:ZX.factName,children:`Command`}),(0,G.jsx)(`dd`,{className:ZX.factValue,children:(0,G.jsx)(`section`,{"aria-label":`Command to run`,children:(0,G.jsx)(YS,{command:e.command.join(` `)})})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`dt`,{className:ZX.factName,children:`What to do`}),(0,G.jsxs)(`dd`,{className:ZX.factValue,children:[(0,G.jsx)(`p`,{className:ZX.adviceWords,children:(0,G.jsx)(Wg,{text:e.words})}),e.commands.map(e=>(0,G.jsx)(YS,{command:e},e))]})]})]}),vZ=({plan:e})=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(QX,{current:e.current,latest:e.latest}),(0,G.jsxs)(`p`,{className:ZX.message,children:[`What changed:`,` `,(0,G.jsx)($X,{url:e.releaseNotes,children:e.releaseNotes})]}),(0,G.jsx)(_Z,{plan:e}),e.kind===`advice`?(0,G.jsx)(`p`,{className:ZX.note,children:`Ork runs only a package manager's own command from here; this one is yours to run.`}):null,(0,G.jsx)(tZ,{ids:e.running}),(0,G.jsx)(`p`,{className:ZX.note,children:`The same, in a terminal:`}),(0,G.jsx)(YS,{command:`ork upgrade`})]}),yZ=({step:e,registry:t})=>e.step===`plan`?(0,G.jsx)(vZ,{plan:e.plan}):e.step===`latest`?(0,G.jsx)(rZ,{text:`Ork ${e.current} is the latest version.`,tone:`succeeded`}):e.step===`unreachable`?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(aZ,{icon:!0,text:e.words}),(0,G.jsx)(`p`,{className:ZX.message,children:`Nothing was changed.`})]}):(0,G.jsx)(`section`,{"aria-busy":`true`,"aria-label":`Asking`,className:ZX.message,children:(0,G.jsx)(Wg,{text:gZ(t)})}),bZ=({step:e,registry:t,first:n,onClose:r,onAsk:i,onUpgrade:a})=>{let o=(0,V.useId)();(0,V.useEffect)(()=>{nZ()&&n.current?.focus()},[n]);let s=e.step===`plan`&&e.plan.kind===`command`,c=e.step===`checking`||s,l=e.step===`plan`&&e.starting;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(yZ,{registry:t,step:e}),(0,G.jsx)(aZ,{text:e.step===`plan`?e.refusal:null}),(0,G.jsx)(oZ,{id:o,why:e.step===`checking`?`Asking the registry…`:null}),(0,G.jsxs)(sZ,{note:c?`It runs on this machine as you.`:void 0,children:[e.step===`unreachable`?(0,G.jsx)(q,{onClick:()=>{n.current?.focus(),i()},variant:`ghost`,children:`Try again`},`again`):null,(0,G.jsx)(q,{disabled:l,focusableWhenDisabled:!0,onClick:r,ref:n,variant:c?`ghost`:`default`,children:c?`Cancel`:`Close`},`close`),c?(0,G.jsx)(q,{"aria-describedby":o,disabled:!s||l,focusableWhenDisabled:!0,onClick:a,variant:`primary`,children:e.step===`plan`?`Upgrade to ${e.plan.latest}`:`Upgrade`},`upgrade`):null]})]})},xZ=({step:e,port:t})=>{let n=(0,V.useId)();return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(rZ,{text:"Restarting `ork ui`…"}),(0,G.jsx)(`p`,{className:ZX.message,children:e.step===`back`?`Ork ${e.version} is up. Reloading…`:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Wg,{text:`Waiting for \`ork ui\` to come back on port ${t}. Runs keep running.`}),` `,(0,G.jsx)(iZ,{since:e.since})]})}),(0,G.jsx)(oZ,{id:n,why:"It closes once `ork ui` is back."}),(0,G.jsx)(sZ,{children:(0,G.jsx)(q,{"aria-describedby":n,disabled:!0,focusableWhenDisabled:!0,children:`Close`})})]})},SZ=({step:e,port:t,onClose:n,onKeepWaiting:r,onReload:i})=>{if(e.step===`restarting`||e.step===`back`)return(0,G.jsx)(xZ,{port:t,step:e});let a=CZ(e,t);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(rZ,{text:a.heading,tone:`failed`}),(0,G.jsx)(aZ,{text:a.words}),(0,G.jsx)(YS,{command:a.command}),(0,G.jsxs)(sZ,{children:[e.step===`gaveUp`?(0,G.jsx)(q,{onClick:r,children:`Keep waiting`}):(0,G.jsx)(q,{onClick:n,children:`Close`}),e.step===`signedOut`?null:(0,G.jsx)(q,{onClick:i,variant:`primary`,children:`Reload`})]})]})},CZ=(e,t)=>e.step===`gaveUp`?{heading:"`ork ui` didn't come back",words:`It wasn't back on port ${t} after 60 seconds. Its terminal says why. Start it again there:`,command:`ork ui --port ${t}`}:e.step===`oldVersion`?{heading:`\`ork ui\` is back on ${e.version}`,words:`\`ork ui\` is back, but it runs ${e.version}: the \`ork\` it started is not the one that was upgraded. Another \`ork\` may come first on your PATH.`,command:`ork upgrade`}:{heading:`This page isn't signed in`,words:"`ork ui` is back, but this page isn't signed in to it. Open it again from a terminal:",command:`ork ui`},wZ={well:`_well_14iu2_8`},TZ=32,EZ=({label:e,text:t,ref:n})=>{let r=(0,V.useRef)(null),i=n??r,a=(0,V.useRef)(!0);return(0,V.useLayoutEffect)(()=>{let e=i.current;e!==null&&a.current&&(e.scrollTop=e.scrollHeight)}),(0,G.jsx)(`section`,{"aria-label":e,className:wZ.well,onScroll:()=>{let e=i.current;e!==null&&(a.current=e.scrollHeight-e.scrollTop-e.clientHeight<TZ)},ref:i,tabIndex:0,children:t})},DZ="Lost the output from `ork ui`. The command may still be running; reconnecting…",OZ=e=>e.command[0]??`it`,kZ=(e,t)=>{let n=t.split(`
74
- `).findLast(e=>e.startsWith(`Could not run`));return e.code===127&&n!==void 0?n:`\`${OZ(e)}\` failed (exit ${String(e.code??1)}); the upgrade did not finish.`},AZ=({job:e,lost:t,output:n})=>{let r=(0,V.useId)();(0,V.useEffect)(()=>{n.current?.focus()},[n]);let i=OZ(e);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`p`,{className:ZX.message,children:[(0,G.jsx)(Wg,{text:`Running \`${i}\`…`}),` `,(0,G.jsx)(iZ,{since:Date.parse(e.startedAt)})]}),(0,G.jsx)(YS,{command:e.command.join(` `)}),t?(0,G.jsx)(aZ,{text:DZ}):null,(0,G.jsx)(oZ,{id:r,why:`It closes when ${i} ends; closing now would hide how it ended.`}),(0,G.jsx)(sZ,{children:(0,G.jsx)(q,{"aria-describedby":r,disabled:!0,focusableWhenDisabled:!0,children:`Close`})})]})},jZ=({step:e,text:t,lost:n,current:r,port:i,output:a,heading:o,onClose:s,onAsk:c,onRestart:l})=>{let{job:u}=e,d=`Output of ${OZ(u)}`;if(e.step===`running`)return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(EZ,{label:d,ref:a,text:t}),(0,G.jsx)(AZ,{job:u,lost:n,output:a})]});let f=(0,G.jsx)(EZ,{label:d,text:t});return e.step===`failed`?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(rZ,{ref:o,text:`The upgrade did not finish`,tone:`failed`}),(0,G.jsx)(aZ,{text:`${kZ(u,t)} Nothing was restarted; \`ork ui\` still runs ${r}.`}),f,(0,G.jsx)(`p`,{className:ZX.note,children:`To run it in a terminal yourself:`}),(0,G.jsx)(YS,{command:u.command.join(` `)}),(0,G.jsxs)(sZ,{children:[(0,G.jsx)(q,{onClick:s,children:`Close`}),(0,G.jsx)(q,{onClick:c,variant:`ghost`,children:`Try again`})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(rZ,{ref:o,text:`Upgraded to ${u.latest}`,tone:`succeeded`}),(0,G.jsx)(`p`,{className:ZX.message,children:(0,G.jsx)(Wg,{text:`Ork ${u.latest} is installed. This page and \`ork ui\` still run ${r} until \`ork ui\` restarts. Restart stops it and starts it again on port ${i} with the same options; runs keep running, and the page reloads itself when it's back.`})}),f,(0,G.jsx)(aZ,{text:e.refusal}),(0,G.jsxs)(sZ,{children:[(0,G.jsx)(q,{onClick:s,variant:`ghost`,children:`Later`}),(0,G.jsxs)(q,{cli:`ork ui --port ${i}`,disabled:e.asking,focusableWhenDisabled:!0,onClick:l,tip:"Stops `ork ui` and starts the new one",variant:`primary`,children:[(0,G.jsx)(By,{}),`Restart`]})]})]})},MZ={pollMs:1e3,waitMs:6e4,reloadMs:1500},NZ=async(e,t,n)=>{let{job:r,port:i,pid:a,since:o}=t,s=await e.call(`health`);if(s.ok&&s.data.pid!==a){let{version:e}=s.data;return e===r.latest?{step:`back`,version:e}:{step:`oldVersion`,job:r,version:e}}return!s.ok&&s.status===401?{step:`signedOut`}:Date.now()-o>=n?{step:`gaveUp`,job:r,port:i,pid:a}:null},PZ=({client:e,step:t,setStep:n,announce:r,reload:i,timing:a})=>{let o=(0,V.useRef)({announce:r,reload:i});(0,V.useEffect)(()=>{o.current={announce:r,reload:i}}),(0,V.useEffect)(()=>{let r=t.step===`restarting`?t:null,i=!1,s=async t=>{let r=await NZ(e,t,a.waitMs);i||r===null||(i=!0,n(r),r.step===`gaveUp`&&o.current.announce("`ork ui` didn't come back."),r.step===`back`&&(o.current.announce(`Ork ${r.version} is up. Reloading…`),setTimeout(()=>{o.current.reload()},a.reloadMs)))},c=r===null?void 0:setInterval(()=>{s(r)},a.pollMs);return()=>{i=!0,clearInterval(c)}},[e,t,n,a])},FZ=e=>new EventSource(e),IZ=2,LZ=1e3,RZ=15e3,zZ=e=>{try{return JSON.parse(e)}catch{return}},BZ=({url:e,open:t,on:n,onStatus:r,onFailure:i})=>{let a=null,o=null,s=LZ,c=null,l=e=>{e!==c&&(c=e,r(e))},u=()=>{let r=t(e());a=r,r.addEventListener(`open`,()=>{s=LZ,l(`open`)}),r.addEventListener(`error`,()=>{l(`lost`),i?.(),r.readyState===IZ&&(r.close(),o=setTimeout(u,s),s=Math.min(s*2,RZ))});let c=Object.entries(n);for(let[e,t]of c)r.addEventListener(e,e=>{let n=zZ(e.data);n!==void 0&&t(n)})};return l(`connecting`),u(),{close:()=>{o!==null&&clearTimeout(o),o=null,a?.close(),a=null}}},VZ=e=>e===null?`Could not reach the npm registry to look for a new version.`:`Could not reach the registry at \`${e}\` to look for a new version.`,HZ=(e,t)=>e.kind===`unreachable`?{step:`unreachable`,words:VZ(t)}:e.kind===`latest`?{step:`latest`,current:e.current}:{step:`plan`,plan:e,refusal:null,starting:!1},UZ=e=>e.kind===`command`?`Ork ${e.latest} is out. The plan is below.`:`Ork ${e.latest} is out. Ork can't run this upgrade from here; what to do is below.`,WZ=e=>e.state===`running`?{step:`running`,job:e}:e.state===`succeeded`?{step:`done`,job:e,refusal:null,asking:!1}:{step:`failed`,job:e},GZ=({client:e,open:t,job:n,registry:r,announce:i,onAsked:a})=>{let[o,s]=(0,V.useState)(()=>n===null?{step:`checking`}:WZ(n)),[c,l]=(0,V.useState)([]),[u,d]=(0,V.useState)(!1),f=(0,V.useRef)(null),p=(0,V.useRef)(0),m=(0,V.useRef)({announce:i,onAsked:a,registry:r});(0,V.useEffect)(()=>{m.current={announce:i,onAsked:a,registry:r}});let h=(0,V.useCallback)(e=>{f.current?.close(),p.current=0,l([]);let n=BZ({url:()=>`${UA.upgrade}?after=${String(p.current)}`,open:t,on:{output:e=>{e.seq<=p.current||(p.current=e.seq,l(t=>[...t,e]))},end:t=>{n.close(),d(!1),s(WZ({...e,state:t.state,code:t.code})),t.state===`succeeded`&&m.current.announce(`Upgraded to ${e.latest}.`)}},onStatus:e=>{d(e===`lost`)}});f.current=n},[t]),g=(0,V.useCallback)(async()=>{s({step:`checking`});let t=await e.call(`upgradePlan`);m.current.onAsked();let n=t.ok?HZ(t.data,m.current.registry):{step:`unreachable`,words:t.error};s(n),n.step===`plan`&&m.current.announce(UZ(n.plan))},[e]),_=(0,V.useRef)(n);(0,V.useEffect)(()=>{let e=_.current;return e===null?g():h(e),()=>{f.current?.close()}},[g,h]);let v=async(t,n)=>{let r=await e.call(`version`),i=r.ok?r.data.job:null;if(i?.state===`running`){m.current.announce(n),s({step:`running`,job:i}),h(i);return}let a=await e.call(`upgradePlan`);if(m.current.onAsked(),!a.ok){s({step:`plan`,plan:t,refusal:n,starting:!1});return}let o=HZ(a.data,m.current.registry);s(o.step===`plan`?{...o,refusal:n}:o)},y=async t=>{s({step:`plan`,plan:t,refusal:null,starting:!0});let n=await e.call(`upgrade`,{body:{planId:t.planId}});n.ok?(m.current.announce(`Upgrading Ork to ${t.latest}.`),s({step:`running`,job:n.data.job}),h(n.data.job)):n.status===409?await v(t,n.error):s({step:`plan`,plan:t,refusal:n.error,starting:!1})},b=async t=>{s({step:`done`,job:t,refusal:null,asking:!0});let n=await e.call(`restart`);s(n.ok?{step:`restarting`,job:t,port:n.data.port,pid:n.data.pid,since:Date.now()}:{step:`done`,job:t,refusal:n.error,asking:!1})};return{step:o,setStep:s,text:c.map(e=>e.text).join(`
75
- `),lost:u,ask:()=>{g()},upgrade:()=>{o.step===`plan`&&o.plan.kind===`command`&&y(o.plan)},restart:()=>{o.step===`done`&&b(o.job)},keepWaiting:()=>{o.step===`gaveUp`&&s({...o,step:`restarting`,since:Date.now()})}}},KZ=e=>[`checking`,`unreachable`,`latest`,`plan`].includes(e.step),qZ=e=>[`running`,`done`,`failed`].includes(e.step),JZ=e=>!KZ(e)&&!qZ(e),YZ=({starts:e,timing:t,reload:n,onStep:r,onClose:i})=>{let{version:a,client:o}=qy(),s=(0,V.use)(ZM),c=ab(a.info),l=ab(a.dialog),u=(0,V.useCallback)(e=>s?.announce(e),[s]),d=GZ({client:o,open:a.open,job:l===`job`?c?.job??null:null,registry:c?.registry??null,announce:u,onAsked:()=>void a.refresh()}),{step:f,setStep:p}=d;PZ({client:o,step:f,setStep:p,announce:u,reload:n,timing:t}),(0,V.useEffect)(()=>{r(f)},[f,r]);let m=f.step===`restarting`||f.step===`back`;(0,V.useEffect)(()=>(a.restarting.setValue(m),()=>{a.restarting.setValue(!1)}),[a,m]);let h=window.location.port;return KZ(f)?(0,G.jsx)(bZ,{first:e.first,onAsk:d.ask,onClose:i,onUpgrade:d.upgrade,registry:c?.registry??null,step:f}):qZ(f)?(0,G.jsx)(jZ,{current:c?.current??``,heading:e.heading,lost:d.lost,onAsk:d.ask,onClose:i,onRestart:d.restart,output:e.output,port:h,step:f,text:d.text}):JZ(f)?(0,G.jsx)(SZ,{onClose:i,onKeepWaiting:d.keepWaiting,onReload:n,port:h,step:f}):null},XZ=()=>{window.location.reload()},ZZ=e=>![`running`,`restarting`,`back`].includes(e.step)&&!(e.step===`plan`&&e.starting)&&!(e.step===`done`&&e.asking),QZ=`Upgrade Ork`,$Z=({timing:e=MZ,reload:t=XZ})=>{let{version:n}=qy(),r=(0,V.use)(ZM),i=ab(n.dialog),a=ab(n.info),o=(0,V.useRef)(null),s=(0,V.useRef)(null),c=(0,V.useRef)(null),l=i===`job`&&a?.job?.state!==`running`,u=i===`job`?l?c:s:o,[d,f]=(0,V.useState)(QZ),p=(0,V.useRef)({closable:!0,ran:!1}),m=(0,V.useCallback)(e=>{p.current={closable:ZZ(e),ran:p.current.ran||`job`in e},f(t=>KZ(e)?QZ:`job`in e?`Upgrading Ork to ${e.job.latest}`:t)},[]),h=()=>{p.current.closable&&(p.current.ran||r?.announce(`Nothing was changed.`),p.current={closable:!0,ran:!1},f(QZ),n.closeDialog())};return(0,G.jsx)(bC,{finalFocus:()=>{let e=document.querySelector(`#${WX}`);return e===null?(r?.focusPanels(),!1):e},initialFocus:u,onOpenChange:e=>{e||h()},open:i!==null,size:`wide`,title:d,children:(0,G.jsx)(YZ,{onClose:h,onStep:m,reload:t,starts:{first:o,output:s,heading:c},timing:e})})},eQ=({workspace:e})=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(hZ,{workspace:e}),(0,G.jsx)($Z,{})]});function tQ(e){let{openOnInputClick:t=!1,value:n,defaultValue:r,onValueChange:i,mode:a=`list`,itemToStringValue:o,...s}=e,c=(a===`inline`||a===`both`)&&!e.readOnly,l=a===`inline`||a===`none`,u=n!==void 0,[d,f]=V.useState(r??``),[p,m]=V.useState(``);V.useEffect(()=>{(u||!c)&&m(``)},[n,u,c]);let h;h=c&&p!==``?p:u?n??``:d;let g=lx({locale:s.locale}),_=String((u?n:d)??``).trim(),v=l||s.filter===null?null:s.filter??g.contains;function y(e,t){m(``),u||f(e),i?.(e,t)}function b(t,n){e.onItemHighlighted?.(t,n),n.reason!==`pointer`&&m(c&&t!=null?Rb(t,o):``)}return(0,G.jsx)(_x,{...s,itemToStringLabel:o,openOnInputClick:t,selectionMode:`none`,fillInputOnItemPress:!0,filter:v,filterQuery:a===`both`?_:void 0,autoComplete:a,inputValue:h,defaultInputValue:r,onInputValueChange:y,onItemHighlighted:b})}var nQ=zS,rQ=[`Panels`,`Runs`,`Window`,`Layout`,`View`,`Ork`],iQ=`Needs a wider window.`,aQ=`No panel is active.`,oQ=[`left`,`right`,`up`,`down`],sQ={left:`narrower`,right:`wider`,up:`shorter`,down:`taller`},cQ=e=>e.wide?e.active===null?aQ:void 0:iQ,lQ=e=>eW.map((t,n)=>{let r={id:`go-${t.id}`,title:`Go to ${t.title}`,group:`Panels`,run:()=>{e.goTo(t.id)}},i=TT(n+1);return i!==void 0&&(r.shortcut=i),r}),uQ=e=>[{id:`run-workflow`,title:`Run workflow…`,group:`Runs`,run:()=>{e.runDialog.setValue(!0)}}],dQ=(e,t)=>{let n=cQ(t),r=t.active===null?`panel`:nW(t.active).title,i=n??(t.floating?`A floating panel cannot be maximized.`:void 0),a=n??(t.maximized?`Restore the panel first.`:void 0);return[{id:`minimize`,title:`Minimize ${r}`,group:`Window`,shortcut:CT.minimize,run:()=>{e.minimize()},disabled:n},{id:`maximize`,title:t.maximized?`Restore ${r}`:`Maximize ${r}`,group:`Window`,shortcut:CT.maximize,run:()=>{e.toggleMaximize()},disabled:i},{id:`float`,title:t.floating?`Dock ${r}`:`Float ${r}`,group:`Window`,shortcut:CT.float,run:()=>{e.toggleFloat()},disabled:n},{id:`close`,title:`Close ${r}`,group:`Window`,shortcut:CT.close,run:()=>{e.close()},disabled:n},...oQ.map(t=>({id:`resize-${t}`,title:`Make ${r} ${sQ[t]}`,group:`Window`,shortcut:CT.resize(t),run:()=>{e.resize(t)},disabled:a})),...oQ.map(t=>({id:`move-${t}`,title:`Move ${r} ${t}`,group:`Window`,shortcut:CT.move(t),run:()=>{e.move(t)},disabled:n}))]},fQ=(e,t)=>{let n=t.wide?void 0:iQ;return[{id:`next-group`,title:`Focus next panel group`,group:`Layout`,shortcut:CT.nextGroup,run:()=>{e.cycleGroup(1)},disabled:n},{id:`previous-group`,title:`Focus previous panel group`,group:`Layout`,shortcut:CT.previousGroup,run:()=>{e.cycleGroup(-1)},disabled:n},{id:`reset-layout`,title:`Reset layout`,group:`Layout`,run:()=>{e.resetLayout()}}]},pQ=[{theme:`system`,title:`Follow the system`},{theme:`dark`,title:`Dark`},{theme:`light`,title:`Light`}],mQ=[{density:`compact`,title:`Compact`},{density:`comfortable`,title:`Comfortable`}],hQ=(e,t,n)=>[...pQ.map(({theme:r,title:i})=>({id:`theme-${r}`,title:`Theme: ${i}`,group:`View`,run:()=>{t.update({theme:r}),e.announce(`Theme: ${i}.`)},disabled:n.theme===r?`This is the theme now.`:void 0})),...mQ.map(({density:r,title:i})=>({id:`density-${r}`,title:`Density: ${i}`,group:`View`,run:()=>{t.update({density:r}),e.announce(`Density: ${i}.`)},disabled:n.density===r?`This is the density now.`:void 0}))],gQ=e=>[{id:`upgrade-ork`,title:`Upgrade Ork…`,group:`Ork`,detail:`Asks the registry for a new version now.`,run:()=>{e.version.openDialog(`ask`)}}],_Q=(e,t,n,r)=>[...lQ(e),...uQ(n),...dQ(e,t),...fQ(e,t),...hQ(e,n.preferences,r),...gQ(n)],vQ={palette:`_palette_p3ocp_6`,input:`_input_p3ocp_45`,list:`_list_p3ocp_78`,group:`_group_p3ocp_88`,empty:`_empty_p3ocp_106`},yQ=e=>rQ.map(t=>({value:t,items:e.filter(e=>e.group===t).map(e=>({label:e.title,command:e}))})),bQ=({commands:e,onChoose:t})=>{let n=(0,V.useMemo)(()=>yQ(e),[e]),r=ET();return(0,G.jsxs)(tQ,{autoHighlight:`always`,inline:!0,items:n,keepHighlight:!0,open:!0,children:[(0,G.jsx)(Rx,{"aria-label":`Search commands`,className:vQ.input,placeholder:`Type a command`}),(0,G.jsx)(HS,{children:(0,G.jsx)(`p`,{className:vQ.empty,children:`No command matches.`})}),(0,G.jsx)(iS,{className:vQ.list,children:e=>(0,G.jsxs)(AS,{items:e.items,children:[(0,G.jsx)(jS,{className:vQ.group,children:e.value}),(0,G.jsx)(Jx,{children:e=>(0,G.jsxs)(nQ,{className:qg.item,disabled:e.command.disabled!==void 0,onClick:()=>{t(e.command)},value:e,children:[(0,G.jsx)(`span`,{children:e.label}),(e.command.disabled??e.command.detail)===void 0?null:(0,G.jsx)(`span`,{className:qg.itemDetail,children:e.command.disabled??e.command.detail}),e.command.shortcut===void 0?null:(0,G.jsx)(Kg,{keys:yT(e.command.shortcut,r)})]},e.command.id)})]},e.value)})]})},xQ=()=>(document.activeElement===null||document.activeElement===document.body)&&document.querySelector(`[data-modal]`)===null,SQ=e=>{requestAnimationFrame(()=>{requestAnimationFrame(e)})},CQ=({workspace:e,commands:t})=>{let n=ab(e.palette),r=(0,V.useRef)(null),i=(0,V.useRef)(!1),a=(0,V.useRef)(null);(0,V.useLayoutEffect)(()=>{n&&(i.current=!1,a.current=document.activeElement)},[n]);let o=t=>{e.palette.setValue(t)},s=()=>{if(!xQ())return;let t=a.current;t instanceof HTMLElement&&t.isConnected?t.focus():e.focusPanels()};return(0,G.jsx)(_C,{onOpenChange:o,onOpenChangeComplete:e=>{if(e)return;let t=r.current;r.current=null,t!==null&&(t.run(),SQ(s))},open:n,children:(0,G.jsxs)(hC,{children:[(0,G.jsx)(aC,{className:vC.backdrop}),(0,G.jsx)(mC,{"aria-label":`Command palette`,"aria-modal":`true`,className:vQ.palette,finalFocus:()=>!i.current,children:(0,G.jsx)(bQ,{commands:t,onChoose:e=>{r.current=e,i.current=!0,o(!1)}})})]})})},wQ=e=>{let t=Yy.create(null),n=Yy.create(null),r=Yy.create(null),i=Yy.create(null),a=Yy.create([]),o=Promise.resolve(),s=(t,n)=>{e.chooseBuilder({project:t.project,workflow:t.name,node:n,draft:r.getValue()?.draft??!1})};return{project:t,opened:n,view:r,selected:i,history:a,inTurn:e=>{let t=o.then(e,e);return o=t.catch(()=>null),t},show:(t,o)=>{let c=n.getValue();n.setValue(t),r.setValue(o),i.setValue(null),a.setValue([]),t===null?e.builderClosed():(t!==c&&s(t,null),o!==null&&e.builderChanged(t.project,t.name,o.draft))},update:t=>{r.setValue(t);let i=n.getValue();i!==null&&e.builderChanged(i.project,i.name,t.draft)},select:e=>{i.setValue(e);let t=n.getValue();t!==null&&s(t,e)}}},TQ=(e,t,n)=>e?.kind===`builder`&&e.project===t&&e.workflow===n,EQ=()=>{let e=Yy.create(null),t=t=>{e.setValue(t)},n=n=>{let r=e.getValue();t({kind:`builder`,...n,revision:TQ(r,n.project,n.workflow)?r.revision:0})},r=(n,r,i)=>{let a=e.getValue();TQ(a,n,r)&&t({...a,draft:i,revision:a.revision+1})},i=()=>{e.getValue()?.kind===`builder`&&t(null)};return{target:e,chooseBuilder:n,builderChanged:r,builderClosed:i,builder:wQ({chooseBuilder:n,builderChanged:r,builderClosed:i}),chooseRun:(e,n)=>{t(e===null?null:{kind:`run`,run:e,node:n})}}},DQ=e=>{let t=Yy.create([]),n=new Map,r=async n=>{let r=await e.call(`decision`,{params:{id:n.id}}),i=r.ok?r.data:n;t.setValue([i,...t.getValue()].slice(0,20))};return{settled:t,saw:e=>{let t=new Map((e??[]).map(e=>[e.id,e]));for(let[e,i]of n)t.has(e)||r(i);n=t}}},OQ=1e3,kQ=({runId:e,client:t,open:n})=>{let r=Yy.create({...dL,tail:[],link:`idle`,ended:null,paging:!1,error:null}),i=null,a=!1,o=!1,s=0,c=[],l=null,u=null,d=e=>{r.setValue({...r.getValue(),...e})},f=()=>c.at(-1)?.seq??r.getValue().latest,p=async(n,i)=>{d({paging:!0});let a=await t.call(`events`,{params:{id:e},query:n});return a.ok?(d({...i(r.getValue(),a.data),...n.last===void 0?{}:{tail:a.data},paging:!1,error:null}),!0):(d({paging:!1,error:a.error}),!1)},m=async()=>{let e=r.getValue();e.following&&hL(e)&&!e.paging&&await p({after:pL(e),limit:500},xL)&&await m()},h=()=>{if(l!==null&&clearTimeout(l),l=null,c.length===0)return;let e=c;c=[];let t=r.getValue(),n=t.tail.at(-1)?.seq??0;d({...yL(t,e),tail:[...t.tail,...e.filter(e=>e.seq>n)].slice(-500)}),m()},g=()=>{i?.close(),i=null},_=()=>{i=BZ({url:()=>`${WA(UA.run,{id:e})}?after=${String(f())}`,open:n,on:{"run-event":e=>{e.seq<=f()||(c.push(e),l??=setTimeout(h,50))},end:({reason:e})=>{h(),g(),o=!1,d({link:`ended`,ended:e})}},onStatus:e=>{d({link:e===`open`?`live`:e===`lost`?`lost`:`loading`})}})},v=async()=>{let e=s;d({link:`loading`});let t=await p({last:500},bL);e===s&&(t?(a=!0,_()):(d({link:`lost`}),u=setTimeout(()=>void v(),OQ)))};return{state:r,start:()=>{o||(o=!0,s+=1,d({ended:null}),a?_():v())},stop:()=>{o=!1,s+=1,u!==null&&clearTimeout(u),u=null,h(),g(),r.getValue().link!==`ended`&&d({link:`idle`})},loadOlder:async()=>{let e=r.getValue();mL(e)&&!e.paging&&await p(CL(e),SL)},loadNewer:async()=>{let e=r.getValue();hL(e)&&!e.paging&&await p({after:pL(e),limit:500},xL)},hold:()=>{d({following:!1})},follow:async()=>{let e=r.getValue();e.paging||(hL(e)?await p({last:500},bL):d({following:!0}),await m())}}},AQ=({runId:e,client:t,feed:n})=>{let r=Yy.create({graph:null,tree:null,links:[],error:null}),i=e=>{r.setValue({...r.getValue(),...e})},a=0,o=async()=>{a+=1;let n=a,[o,s]=await Promise.all([t.call(`tree`,{params:{id:e}}),t.call(`links`,{query:{run:e}})]);n===a&&(o.ok?i({tree:o.data,links:s.ok?s.data:r.getValue().links,error:null}):i({error:o.error}))},s=async()=>{let n=await t.call(`graph`,{params:{id:e}});n.ok?i({graph:n.data}):i({error:n.error})};return{state:r,start:()=>{let e=null,t=n.state.getValue().latest;s(),o();let r=n.state.subscribe(({latest:n})=>{n!==t&&(t=n,e??=setTimeout(()=>{e=null,o()},250))});return()=>{r(),e!==null&&clearTimeout(e),a+=1}}}},jQ=e=>e.live===`running`||e.live===`paused`,MQ=({client:e,open:t})=>{let n=new Map,r=r=>{let i=n.get(r)??{feed:kQ({runId:r,client:e,open:t}),retained:0};return n.set(r,i),i},i=()=>{let e=[...n].filter(([,e])=>e.retained===0);for(let[t]of e.slice(0,-4))n.delete(t)};return{reopenResumed:e=>{for(let t of e??[]){let e=n.get(t.id);e!==void 0&&e.retained>0&&jQ(t)&&e.feed.state.getValue().link===`ended`&&e.feed.start()}},feedOf:e=>r(e).feed,retainRun:e=>{let t=r(e);return t.retained+=1,t.feed.start(),()=>{--t.retained,t.retained===0&&(t.feed.stop(),n.delete(e),n.set(e,t),i())}},watchRun:t=>AQ({runId:t,client:e,feed:r(t).feed})}},NQ=`ork.notifications.read`,PQ=ss({before:Co().nullable(),ids:as(Co())}),FQ=e=>{if(e.live===`running`)return null;let t=e.live===`paused`||e.live===`crashed`;return{id:`run:${e.id}:${e.live}`,kind:`run`,runId:e.id,status:e.live,title:`Run ${e.id} of ${e.workflow} ${_D(e.live)}.`,at:e.finishedAt??e.startedAt,pending:t}},IQ=e=>({id:`decision:${e.id}`,kind:`decision`,runId:e.runId,node:e.node,status:`waiting`,title:`${e.node} in run ${e.runId} asks: ${e.question}`,at:e.openedAt,pending:!0}),LQ=(e,t)=>[...t.map(e=>IQ(e)),...e.flatMap(e=>FQ(e)??[])].toSorted((e,t)=>t.at.localeCompare(e.at)),RQ=(e,t)=>t.ids.includes(e.id)||!e.pending&&t.before!==null&&e.at<=t.before,zQ=({runs:e,decisions:t,storage:n,now:r=()=>new Date().toISOString()})=>{let i=new Zy({before:null,ids:[]},{key:NQ,storage:n});PQ.safeParse(i.getValue()).success||i.reset();let a=Yy.create({items:[],unread:0}),o=null,s=new Set,c=[],l=()=>{let e=i.getValue(),t=c.map(t=>({...t,unread:!RQ(t,e)}));a.setValue({items:t,unread:t.filter(({unread:e})=>e).length})},u=()=>{let n=e.getValue(),a=t.getValue();if(n===null||a===null)return;c=LQ(n,a),i.getValue().before===null&&i.setValue({...i.getValue(),before:r()});let u=o,d=u===null?[]:c.filter(({id:e})=>!u.has(e));if(o=new Set(c.map(({id:e})=>e)),l(),d.length>0)for(let e of s)e(d)};return{view:a,start:()=>{let n=e.subscribe(u),r=t.subscribe(u);return u(),()=>{n(),r()}},onNew:e=>(s.add(e),()=>{s.delete(e)}),markRead:e=>{let t=i.getValue();i.setValue({...t,ids:[...t.ids,e].slice(-200)}),l()},markAllRead:()=>{i.setValue({before:r(),ids:c.filter(({pending:e})=>e).map(({id:e})=>e).slice(-200)}),l()}}},BQ=(e,t)=>JSON.stringify(e)===JSON.stringify(t),VQ=(e,t)=>{if(e===null)return t;let n=new Map(e.map(e=>[e.id,e])),r=t.map(e=>{let t=n.get(e.id);return t!==void 0&&BQ(t,e)?t:e});return r.length===e.length&&r.every((t,n)=>t===e[n])?e:r},HQ=({client:e,open:t,pageVersion:n})=>{let r=Yy.create(null),i=Yy.create(null);return{info:r,open:t,pageVersion:n,dialog:i,restarting:Yy.create(!1),receive:e=>{r.setValue(e)},refresh:async()=>{let t=await e.call(`version`);t.ok&&r.setValue(t.data)},openDialog:e=>{i.setValue(e)},closeDialog:()=>{i.setValue(null)}}},UQ=({client:e,open:t,pageVersion:n,runs:r,decisions:i})=>{let a=HQ({client:e,open:t,pageVersion:n});return{version:a,follow:e=>BZ({url:()=>UA.overview,open:t,on:{runs:e=>{r.setValue(VQ(r.getValue(),e))},decisions:e=>{i.setValue(VQ(i.getValue(),e))},version:a.receive},...e})}},WQ=({link:e,server:t})=>t!==null&&`error`in t?`Cannot reach \`ork ui\`: ${t.error}`:e===`lost`?"Lost the stream from `ork ui`. Retrying…":e===`open`&&t!==null?`Ork ${t.version}`:"Connecting to `ork ui`…",GQ=e=>e===null?null:e.filter(e=>jQ(e)).length,KQ=({client:e,open:t,storage:n,pageVersion:r=null})=>{let i=Yy.create(null),a=Yy.create(null),o=Yy.create({link:`connecting`,server:null}),s=Yy.create({run:null,node:null}),c=EQ(),l=null,u=e=>{e.run!==l&&(l=null),s.setValue(e),c.chooseRun(e.run,e.node)},d=tb(n),f=Yy.create(`all`),p=Yy.create(!1),m=Yy.create(null),h=Az(()=>e.call(`projects`)),g=Az(()=>e.call(`triggers`)),_=Az(t=>e.call(`workflows`,{params:{id:t}})),v=Yy.create({project:`all`,period:`30`}),y=Az(({query:t})=>e.call(`usage`,{query:t})),b=Yy.create({status:`open`,about:`all`}),x=Az(()=>e.call(`feedbackItems`)),S=Yy.create(`all`),C=Az(()=>e.call(`worktrees`)),w=MQ({client:e,open:t}),T=DQ(e),E=zQ({runs:i,decisions:a,storage:n}),D=UQ({client:e,open:t,pageVersion:r,runs:i,decisions:a}),{version:O}=D,k=async()=>{let t=await e.call(`health`);o.setValue({...o.getValue(),server:t.ok?t.data:{error:t.error}})};return{runs:i,decisions:a,connection:o,selection:s,contextTarget:c.target,builder:c.builder,preferences:d,runFilter:f,runDialog:p,runPreset:m,client:e,settledDecisions:T.settled,notifications:E,projects:h,workflows:_,usage:y,usageFilter:v,feedback:x,feedbackFilter:b,worktrees:C,worktreesFilter:S,triggers:g,version:O,startRun:t=>e.call(`start`,{body:t}),start:()=>{let e=i.subscribe(w.reopenResumed),t=a.subscribe(T.saw),n=E.start(),r=D.follow({onStatus:e=>{o.setValue({...o.getValue(),link:e}),e!==`lost`&&k()},onFailure:()=>void k()});return()=>{e(),t(),n(),r.close()}},feedOf:w.feedOf,retainRun:w.retainRun,control:(t,n,r)=>e.call(t,{params:{id:n},body:r===void 0?{}:{node:r}}),sendMessage:(t,n,r)=>e.call(`message`,{params:{id:t},body:{node:n,body:r}}),answerDecision:(t,n,r=``)=>e.call(`answer`,{params:{id:t},body:r.trim()===``?{choose:n}:{choose:n,note:r}}),watchRun:w.watchRun,selectRun:e=>{l=null,u({run:e,node:null})},arriveAt:e=>{l=e,u({run:e,node:null})},takeArrival:e=>{let t=l===e;return t&&(l=null),t},selectNode:e=>{u({...s.getValue(),node:e})}}},qQ=(e,t,n)=>`${String(e)} ${e===1?t:n}`,JQ=()=>{let{runs:e,decisions:t,connection:n}=qy(),r=ib(e,GQ),i=ib(t,e=>e?.length??null);return ib(n,({link:e})=>e===`open`)&&r!==null&&i!==null?(0,G.jsxs)(`span`,{className:kT.status,children:[qQ(r,`run live`,`runs live`),`,`,` `,qQ(i,`decision open`,`decisions open`)]}):null},YQ=({workspace:e})=>{let t=ab(e.announcement),{connection:n,version:r}=qy(),i=ib(n,WQ),a=ab(r.restarting);return(0,G.jsxs)(`footer`,{className:kT.bar,children:[(0,G.jsx)(`output`,{"aria-live":a?`off`:void 0,className:kT.status,children:(0,G.jsx)(Wg,{text:i})}),(0,G.jsx)(JQ,{}),(0,G.jsx)(`output`,{"aria-atomic":`true`,"aria-live":`polite`,className:kT.visuallyHidden,children:t})]})},XQ=e=>{let t=qy(),{preferences:n}=t,r=ab(e.view),i=ab(n.value),a=(0,V.useMemo)(()=>_Q(e,r,t,i),[e,r,t,i]);return OT(e,a),a},ZQ=e=>{let t=qy();(0,V.useEffect)(()=>t.notifications.onNew(n=>{if(e.announce(n.map(({title:e})=>e).join(` `)),t.preferences.value.getValue().desktopNotifications)for(let r of n)hz(r.title,r.id,()=>{t.selectRun(r.runId),e.goTo(`notifications`)})}),[t,e])},QQ=({workspace:e})=>{let t=XQ(e);return ZQ(e),(0,G.jsx)(ZM,{value:e,children:(0,G.jsxs)(`div`,{className:kT.shell,children:[(0,G.jsx)(oW,{workspace:e}),(0,G.jsx)(eQ,{workspace:e}),(0,G.jsx)(UX,{workspace:e}),(0,G.jsx)(YQ,{workspace:e}),(0,G.jsx)(CQ,{commands:t,workspace:e}),(0,G.jsx)(gT,{})]})})},$Q=()=>{let e=new Map;return{get length(){return e.size},clear:()=>{e.clear()},getItem:t=>e.get(t)??null,key:t=>[...e.keys()][t]??null,removeItem:t=>{e.delete(t)},setItem:(t,n)=>{e.set(t,n)}}},e$=()=>{try{return window.localStorage}catch{return $Q()}},t$=1e3,n$=e=>{let t=[],n=!1,r=i=>{n=!0,e.setValue(``),setTimeout(()=>{e.setValue(i)},0),setTimeout(()=>{n=!1,t.length>0&&r(t.splice(0).join(` `))},t$)};return e=>{let i=Ug(e);n?t.push(i):r(i)}},r$=280,i$=340,a$=240,o$={minimumWidth:240,minimumHeight:120},s$=e=>{e.api.setConstraints(o$)},c$=(e,t,n)=>[e.onDidAddGroup(s$),e.onDidLayoutChange(()=>{n(),t()}),e.onDidAddPanel(t),e.onDidRemovePanel(t),e.onDidActivePanelChange(t),e.onDidMaximizedGroupChange(t)],l$=(e,t)=>{try{return e.fromJSON(t),!0}catch{return e.clear(),!1}},u$=(e,t,n)=>e.addPanel({id:t,component:t,title:nW(t).title,...n}),d$=e=>{let t=u$(e,`monitor`,{});u$(e,`builder`,{position:{referencePanel:`monitor`,direction:`within`},inactive:!0}),u$(e,`runs`,{position:{referencePanel:`monitor`,direction:`left`},initialWidth:r$,inactive:!0}),u$(e,`decisions`,{position:{referencePanel:`monitor`,direction:`right`},initialWidth:i$,inactive:!0}),u$(e,`notifications`,{position:{referencePanel:`decisions`,direction:`within`},inactive:!0}),u$(e,`context`,{position:{referencePanel:`decisions`,direction:`below`}}),u$(e,`logs`,{position:{referencePanel:`monitor`,direction:`below`},initialHeight:a$,inactive:!0}),u$(e,`chats`,{position:{referencePanel:`logs`,direction:`within`},inactive:!0}),u$(e,`usage`,{position:{referencePanel:`logs`,direction:`within`},inactive:!0}),u$(e,`feedback`,{position:{referencePanel:`usage`,direction:`within`},inactive:!0}),u$(e,`worktrees`,{position:{referencePanel:`feedback`,direction:`within`},inactive:!0}),t.api.setActive()},f$=(e,t,n)=>{if(!Array.isArray(e.data))return;let r=e.data,i=r.findIndex(e=>!Array.isArray(e.data)&&e.data.id===t);if(i!==-1)return{siblings:r,index:i,along:n};for(let e of r){let r=f$(e,t,!n);if(r!==void 0)return r}},p$={horizontal:`left`,vertical:`above`},m$={horizontal:`right`,vertical:`below`},h$=(e,t)=>{let{root:n,orientation:r}=e.toJSON().grid,i=r===vG.HORIZONTAL,a=f$(n,t.id,!0);if(a===void 0)return;let{siblings:o,index:s,along:c}=a,l=c===i?`horizontal`:`vertical`,u=o[s+1],d=u??o[s-1];if(d===void 0)return;let f={width:t.api.width,height:t.api.height},p=u===void 0?m$[l]:p$[l];return Array.isArray(d.data)?c?{group:null,direction:p,...f}:void 0:{group:d.data.id,direction:p,...f}},g$=(e,t)=>{if(t.api.location.type!==`floating`)return;let n=e.toJSON().floatingGroups?.find(e=>e.data?.id===t.id);if(n===void 0)return;let{position:r}=n,{width:i,height:a}=r;return{left:`left`in r?r.left:e.width-r.right-i,top:`top`in r?r.top:e.height-r.bottom-a,width:i,height:a}},_$=(e,t)=>{let{group:n}=t,r=g$(e,n),i=h$(e,n);return{group:n.id,index:n.panels.indexOf(t),...r===void 0?{}:{floating:r},...i===void 0?{}:{beside:i}}},v$=(e,t)=>{if(t!==void 0){if(e.getGroup(t.group)!==void 0)return{position:{referenceGroup:t.group,direction:`within`,index:t.index}};if(t.floating!==void 0){let{left:e,top:n,width:r,height:i}=t.floating;return{floating:{x:e,y:n,width:r,height:i}}}if(t.beside!==void 0){let{group:n,direction:r,width:i,height:a}=t.beside,o=r===`left`||r===`right`?{initialWidth:i}:{initialHeight:a};if(n===null)return{position:{direction:r},...o};if(e.getGroup(n)!==void 0)return{position:{referenceGroup:n,direction:r},...o}}}let n=e.activeGroup;return n===void 0?{}:{position:{referenceGroup:n.id,direction:`within`}}},y$=(e,t,n)=>u$(e,t,v$(e,n)),b$=(e,t)=>e.groups.find(e=>e.id===t),x$=e=>{let t=e.element.querySelector(`[role="tab"][aria-selected="true"]`);return t?.focus(),t!==null},S$=e=>{e.api.setActive(),requestAnimationFrame(()=>{x$(e.group)})},C$=e=>e.map(e=>({group:e,box:e.element.getBoundingClientRect()})).toSorted((e,t)=>e.box.left-t.box.left||e.box.top-t.box.top).map(({group:e})=>e),w$=(e,t)=>{let n=C$(e.groups),{activeGroup:r}=e;if(n.length===0)return;let i=n[((r===void 0?0:n.indexOf(r))+t+n.length)%n.length];i!==void 0&&(i.activePanel?.api.setActive(),x$(i))},T$=e=>{e.api.location.type===`grid`&&(e.api.isMaximized()?e.api.exitMaximized():e.api.maximize(),x$(e))},E$={right:{axis:`width`,delta:32},left:{axis:`width`,delta:-32},down:{axis:`height`,delta:32},up:{axis:`height`,delta:-32}},D$=(e,t)=>{let{axis:n,delta:r}=E$[t];e.api.setSize({[n]:e.api[n]+r})},O$=e=>{let t=String(Math.round(e.group.api.width)),n=String(Math.round(e.group.api.height));return`${e.title??e.id}: ${t} by ${n}.`},k$={right:{x:32,y:0},left:{x:-32,y:0},down:{x:0,y:32},up:{x:0,y:-32}},A$={left:`left`,right:`right`,up:`above`,down:`below`},j$=(e,t,n)=>{let{group:r}=t,i=g$(e,r);if(i!==void 0){let{x:t,y:a}=k$[n];e.addFloatingGroup(r,{x:Math.max(0,i.left+t),y:Math.max(0,i.top+a),width:i.width,height:i.height});return}let a=e.adjacentGroupInDirection(r,n),o=a===void 0?void 0:b$(e,a.id);o===void 0?(r.panels.length!==1||e.groups.length!==1)&&t.api.moveTo({group:e.addGroup({direction:A$[n]}),position:`center`}):t.api.moveTo({group:o,position:`center`})},M$={left:`left`,right:`right`,above:`top`,below:`bottom`},N$=(e,t,n)=>{let r=t.activePanel;if(r===void 0)return;if(t.api.location.type!==`floating`){let{beside:i}=_$(e,r);e.addFloatingGroup(t);let a=e.getPanel(r.id)?.group;a!==void 0&&i!==void 0&&n.set(a.id,i);return}let i=n.get(t.id);n.delete(t.id);let a=i?.group===void 0||i.group===null?void 0:b$(e,i.group),o=i?.direction??`right`;t.api.moveTo(a===void 0?{position:M$[o]}:{group:a,position:M$[o]}),i!==void 0&&t.api.setSize(o===`left`||o===`right`?{width:i.width}:{height:i.height})},P$=`ork.layout.v1`,F$=zs(e=>typeof e==`string`&&tW(e)),I$=ss({left:Yo(),top:Yo(),width:Yo(),height:Yo()}),L$=ss({id:F$,anchor:ss({group:Co(),index:Yo(),floating:I$.optional(),beside:ss({group:Co().nullable(),direction:_s([`left`,`right`,`above`,`below`]),width:Yo(),height:Yo()}).optional()})}),R$=ls({grid:ls({root:ls({})}),panels:hs(Co(),ls({contentComponent:F$}))}),z$=ss({dock:ts(),minimized:as(L$),folded:as(F$)}),B$=(e,t,n)=>[...e.filter(e=>e!==t),...n?[t]:[]],V$={dock:null,minimized:[],folded:[]},H$=e=>R$.safeParse(e).success,U$=e=>{let t=z$.safeParse(e);if(!t.success)return null;let{dock:n,minimized:r,folded:i}=t.data;if(n==null)return{dock:null,minimized:[],folded:i};if(!H$(n))return null;let a=new Set(Object.values(n.panels).map(e=>e.contentComponent));return{dock:n,minimized:r.filter(e=>!a.has(e.id)),folded:i}},W$=e=>new Zy(V$,{key:P$,storage:e}),G$=({dock:e,targetPanel:t,commit:n,refocus:r,announce:i,quietly:a})=>{let o=new Map,s=()=>{let t=e();t?.hasMaximizedGroup()===!0&&t.exitMaximizedGroup()};return{close:e=>{let i=t(e);i!==void 0&&(s(),i.api.close(),n(),r())},toggleMaximize:t=>{let r=t??e()?.activeGroup;r!==void 0&&T$(r),n()},toggleFloat:t=>{let i=e(),a=t??i?.activeGroup;i!==null&&a!==void 0&&(s(),N$(i,a,o),n(),r())},resize:t=>{let n=e(),r=n?.activeGroup,a=n?.activePanel;r!==void 0&&a!==void 0&&n?.hasMaximizedGroup()!==!0&&(D$(r,t),i(O$(a)))},move:t=>{let o=e(),c=o?.activePanel;o!==null&&c!==void 0&&(a(()=>{s(),j$(o,c,t)}),n(),r(),i(`${c.title??c.id} moved ${t}.`))},cycleGroup:t=>{let n=e();n!==null&&w$(n,t)}}},K$=({storage:e,wide:t,onLayoutDropped:n})=>{let r=W$(e),i=U$(r.getValue()),a=i===null;a&&r.reset();let o=Yy.create(FX(null,i??V$,t)),s=Yy.create(!1),c=Yy.create(``),l=null,u=!1,d=[],f=n$(c),p=e=>{u||f(e)},m=e=>{u=!0,e(),u=!1},h=()=>{let e=o.getValue(),t=FX(l,r.getValue(),e.wide);IX(e,t)||o.setValue(t)},g=()=>{l!==null&&r.setValue({...r.getValue(),dock:l.toJSON()})},_=()=>{g(),h()},v=()=>{for(let e of d)e.dispose();d=[],l=null,h()},y=e=>{v(),u=!0,l=e;let{dock:t,folded:i}=r.getValue();t!==null&&l$(e,t)||(a||=t!==null,r.setValue({...V$,folded:i}),d$(e)),a&&n?.(),a=!1,e.groups.forEach(s$),d=c$(e,h,g),h(),u=!1},b=e=>e===void 0?l?.activePanel:l?.getPanel(e),x=()=>{l?.hasMaximizedGroup()===!0&&l.exitMaximizedGroup()},S=e=>{let t=r.getValue();r.setValue({...t,minimized:e(t.minimized)})},C=e=>{requestAnimationFrame(()=>{let t=l?.activeGroup;!(t!==void 0&&x$(t))&&e!==void 0&&zX(RX(e))})},w=()=>{let[e]=eW;o.getValue().wide?C():e!==void 0&&zX(LX(e.id))},T=e=>{let t=b(e);if(l===null||t===void 0)return;let n=t.id;if(!tW(n))return;m(x);let r=_$(l,t);S(e=>[...e,{id:n,anchor:r}]),m(()=>{t.api.close()}),f(`${nW(n).title} minimized.`),_(),C(n)},E=e=>{if(l===null)return;let t=r.getValue().minimized.find(t=>t.id===e);S(t=>t.filter(t=>t.id!==e));let n=l;m(()=>{x(),S$(y$(n,e,t?.anchor))}),f(`${nW(e).title} restored.`),_()},D=(e,t)=>{let n=r.getValue();r.setValue({...n,folded:B$(n.folded,e,t)}),_()},O=e=>{D(e,!r.getValue().folded.includes(e))},k=e=>{if(!o.getValue().wide){D(e,!1),zX(LX(e));return}if(l===null)return;let t=l.getPanel(e);if(t!==void 0)t.api.isMaximized()||x(),S$(t);else if(o.getValue().minimized.includes(e))E(e);else{let t=l;m(()=>{x(),S$(y$(t,e))}),f(`${nW(e).title} opened.`)}},A=G$({dock:()=>l,targetPanel:b,commit:_,refocus:C,announce:f,quietly:m}),j=()=>{if(r.setValue(V$),l!==null){let e=l;m(()=>{e.clear(),d$(e)}),l.groups.forEach(s$),g(),C()}_(),f(`Layout reset.`)},M=e=>{let t=o.getValue();t.wide!==e&&o.setValue({...t,wide:e})};return{view:o,layout:r,palette:s,announcement:c,announce:f,announceFromDock:p,attach:y,detach:v,goTo:k,minimize:T,restore:E,toggleFold:O,resetLayout:j,focusPanels:w,...A,setWide:M}},q$=JA(),J$=`1.0.0-alpha.5`,Y$=()=>KQ({client:q$,open:FZ,storage:e$(),pageVersion:J$}),X$=()=>K$({storage:e$(),wide:window.matchMedia(PX).matches,onLayoutDropped:()=>{Hy.add({title:`Layout reset`,description:`The saved layout could not be read.`})}}),Z$=()=>{let[e]=(0,V.useState)(Y$),[t]=(0,V.useState)(X$);return(0,V.useLayoutEffect)(()=>nb(window,e.preferences),[e]),(0,V.useEffect)(()=>e.start(),[e]),(0,G.jsx)(Ky,{value:e,children:(0,G.jsx)(Yg,{children:(0,G.jsx)(Wy,{children:(0,G.jsx)(QQ,{workspace:t})})})})};export{Z$ as App};
70
+ `).length,Qz=(e,t)=>{let n=t.endsWith(`/`)?t:`${t}/`;return e.startsWith(n)?e.slice(n.length):e},$z=(e,t)=>`ork context explain ${e} ${t}`,eB={host:`_host_tnhom_9`,panel:`_panel_tnhom_17`,header:`_header_tnhom_36`,card:`_card_tnhom_37`,foot:`_foot_tnhom_38`,facts:`_facts_tnhom_54`,fact:`_fact_tnhom_54`,factName:`_factName_tnhom_71`,factValue:`_factValue_tnhom_85`,title:`_title_tnhom_95`,plannedLine:`_plannedLine_tnhom_107`,planned:`_planned_tnhom_107`,description:`_description_tnhom_117`,why:`_why_tnhom_118`,emptyText:`_emptyText_tnhom_119`,updating:`_updating_tnhom_132`,cardTitle:`_cardTitle_tnhom_142`,notice:`_notice_tnhom_151`,noticeIcon:`_noticeIcon_tnhom_174`,noticeWords:`_noticeWords_tnhom_190`,stack:`_stack_tnhom_194`,section:`_section_tnhom_203`,sectionHead:`_sectionHead_tnhom_219`,sectionNote:`_sectionNote_tnhom_230`,heading:`_heading_tnhom_241`,meta:`_meta_tnhom_251`,layer:`_layer_tnhom_252`,source:`_source_tnhom_253`,tokens:`_tokens_tnhom_254`,state:`_state_tnhom_255`,list:`_list_tnhom_266`,item:`_item_tnhom_272`,row:`_row_tnhom_281`,details:`_details_tnhom_318`,toggle:`_toggle_tnhom_341`,mark:`_mark_tnhom_342`,name:`_name_tnhom_365`,visuallyHidden:`_visuallyHidden_tnhom_426`,well:`_well_tnhom_437`,wellBar:`_wellBar_tnhom_449`,wellPlace:`_wellPlace_tnhom_466`,wellCopy:`_wellCopy_tnhom_473`,copied:`_copied_tnhom_482`,text:`_text_tnhom_488`},tB=({text:e})=>e.split(`≈`).map((e,t)=>t===0?e:(0,G.jsxs)(`span`,{children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,children:`≈`}),(0,G.jsx)(`span`,{className:eB.visuallyHidden,children:`about `}),e]},t)),nB=({name:e,value:t})=>(0,G.jsxs)(`div`,{className:eB.fact,children:[(0,G.jsx)(`dt`,{className:eB.factName,children:e}),(0,G.jsx)(`dd`,{className:eB.factValue,children:(0,G.jsx)(tB,{text:t})})]}),rB=({node:e,type:t,from:n,appendedTokens:r,planned:i,reload:a,updating:o,cli:s,onReload:c,titleRef:l,children:u})=>(0,G.jsxs)(`header`,{className:eB.header,children:[(0,G.jsxs)(`dl`,{className:eB.facts,children:[(0,G.jsxs)(`div`,{className:eB.fact,children:[(0,G.jsx)(`dt`,{className:eB.factName,children:`Node`}),(0,G.jsx)(`dd`,{className:eB.factValue,children:(0,G.jsx)(`h2`,{className:eB.title,ref:l,tabIndex:-1,children:e})})]}),t===void 0?null:(0,G.jsx)(nB,{name:`Type`,value:t}),(0,G.jsx)(nB,{name:`From`,value:n}),r===void 0?null:(0,G.jsx)(nB,{name:`Appended`,value:`${Hz(r)} tokens`})]}),(0,G.jsxs)(`div`,{className:eB.plannedLine,children:[i===null?null:(0,G.jsx)(`p`,{className:eB.planned,children:i}),o?(0,G.jsx)(`span`,{className:eB.updating,children:`Updating…`}):null,(0,G.jsx)(q,{cli:s,onClick:c,variant:`ghost`,children:a})]}),u]}),iB=e=>`Changed after this run started: ${e.map(e=>`\`${e}\``).join(`, `)}. The run may have read ${e.length===1?`an older version`:`older versions`}.`,aB=({answer:e,error:t})=>{let n=e?.changedSinceStart??[],r=e?.planned===!0?e.explanation:null;return(0,G.jsxs)(G.Fragment,{children:[n.length===0?null:(0,G.jsxs)(`p`,{className:eB.notice,"data-note":`changed`,children:[(0,G.jsx)(`span`,{className:eB.noticeIcon,children:(0,G.jsx)(yy,{})}),(0,G.jsx)(`span`,{className:eB.noticeWords,children:(0,G.jsx)(Wg,{text:iB(n)})})]}),r?.template===void 0?null:(0,G.jsx)(`p`,{className:eB.notice,"data-note":`spawned`,children:(0,G.jsx)(`span`,{className:eB.noticeWords,children:(0,G.jsx)(Wg,{text:`\`${r.node}\` was spawned during the run, so it's planned as \`${r.template}\`, the node it was spawned from.`})})}),t===null?null:(0,G.jsxs)(`p`,{className:eB.notice,"data-note":`failed`,children:[(0,G.jsx)(`span`,{className:eB.noticeIcon,children:(0,G.jsx)(cD,{})}),(0,G.jsx)(`span`,{className:eB.noticeWords,children:(0,G.jsx)(Wg,{text:Xz(t,e!==null)})})]})]})},oB=({why:e})=>(0,G.jsxs)(`div`,{className:eB.card,children:[(0,G.jsx)(`p`,{className:eB.cardTitle,children:`No context to show.`}),(0,G.jsx)(`p`,{className:eB.description,children:(0,G.jsx)(Wg,{text:Uz(e)})})]}),sB=({cli:e,draft:t,sized:n})=>(0,G.jsxs)(`footer`,{className:eB.foot,children:[t?(0,G.jsx)(`p`,{className:eB.description,children:`The CLI reads the saved file, not the draft.`}):null,(0,G.jsx)(YS,{command:e}),n?(0,G.jsx)(`p`,{className:eB.description,children:`Tokens are estimates, about four characters each.`}):null]}),cB=({target:e})=>e?.kind===`run`?(0,G.jsx)(CC,{title:`No node chosen in this run.`,children:`Choose one in the Monitor, Logs or Chats.`}):e?.kind===`builder`?(0,G.jsx)(CC,{title:`No node selected in the Builder.`,children:`Select a card to see what its session loads.`}):(0,G.jsx)(CC,{cli:`ork context explain <workflow> <node>`,title:`No node chosen.`,children:`Choose one in the Monitor or the Builder, or in a terminal:`}),lB=({words:e,more:t})=>{let n=`${e}${t?`, `:``}`;return n===``?null:(0,G.jsx)(`span`,{className:eB.visuallyHidden,children:n})},uB=({piece:e})=>{let t=[e.state,e.layer,e.source,e.tokens],n=e=>t.slice(e).some(e=>e!==void 0),r=e.state!==void 0||e.layer!==void 0||e.source!==void 0;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:eB.mark,"data-state":e.state,children:e.state===void 0?null:e.state===`live`?(0,G.jsx)(Yv,{}):(0,G.jsx)(Iy,{})}),(0,G.jsxs)(`span`,{className:eB.name,children:[e.name,(0,G.jsx)(lB,{more:n(0),words:``})]}),r?(0,G.jsxs)(`span`,{className:eB.details,children:[e.state===void 0?null:(0,G.jsxs)(`span`,{className:eB.state,children:[e.state,(0,G.jsx)(lB,{more:n(1),words:``})]}),e.layer===void 0?null:(0,G.jsxs)(`span`,{className:eB.layer,children:[e.layer,(0,G.jsx)(lB,{more:n(2),words:` layer`})]}),e.source===void 0?null:(0,G.jsxs)(`span`,{className:eB.source,children:[e.source,(0,G.jsx)(lB,{more:n(3),words:``})]})]}):null,e.tokens===void 0?null:(0,G.jsxs)(`span`,{className:eB.tokens,children:[(0,G.jsx)(tB,{text:Hz(e.tokens)}),(0,G.jsx)(lB,{more:!1,words:` tokens`})]})]})},dB=({piece:e,id:t})=>{let n=e.text??``,r=Zz(n);return(0,G.jsxs)(`div`,{className:eB.well,id:t,children:[(0,G.jsxs)(`div`,{className:eB.wellBar,children:[(0,G.jsx)(`span`,{className:eB.wellPlace,children:e.place}),(0,G.jsx)(`span`,{children:(0,G.jsx)(tB,{text:`${r.toLocaleString(`en`)} ${r===1?`line`:`lines`}${e.tokens===void 0?``:` · ${Hz(e.tokens)} tokens`}`})}),(0,G.jsx)(`span`,{className:eB.wellCopy,children:(0,G.jsx)(qS,{label:`Copy the text of ${e.name}`,resultClass:eB.copied,text:n})})]}),n===``?(0,G.jsx)(`p`,{className:eB.emptyText,children:e.key===`appended`?`Nothing is appended.`:`This file is empty.`}):(0,G.jsx)(`pre`,{className:eB.text,children:n})]})},fB=({piece:e,open:t,onToggle:n})=>{let r=(0,V.useId)(),i=`${r}-why`,a=`${r}-text`,o=e.state??`live`,s=e.why===void 0?null:(0,G.jsx)(`p`,{className:eB.why,id:i,children:(0,G.jsx)(Wg,{text:Uz(e.why)})});return e.text===void 0?(0,G.jsxs)(`li`,{className:eB.item,children:[(0,G.jsxs)(`div`,{className:eB.row,"data-state":o,children:[(0,G.jsx)(`span`,{className:eB.toggle}),(0,G.jsx)(uB,{piece:e})]}),s]}):(0,G.jsxs)(`li`,{className:eB.item,children:[(0,G.jsxs)(`button`,{"aria-controls":t?a:void 0,"aria-describedby":e.why===void 0?void 0:i,"aria-expanded":t,className:eB.row,"data-piece":e.key,"data-state":o,onClick:()=>{n(e.key)},type:`button`,children:[(0,G.jsx)(`span`,{className:eB.toggle,children:t?(0,G.jsx)(Xv,{}):(0,G.jsx)(Zv,{})}),(0,G.jsx)(uB,{piece:e})]}),s,t?(0,G.jsx)(dB,{id:a,piece:e}):null]})},pB=({sections:e,opened:t,onToggle:n,busy:r})=>(0,G.jsx)(`div`,{"aria-busy":r,className:eB.stack,children:e.map(e=>(0,G.jsxs)(`section`,{className:eB.section,children:[(0,G.jsxs)(`div`,{className:eB.sectionHead,children:[(0,G.jsx)(`h3`,{className:eB.heading,children:e.title}),(0,G.jsx)(`span`,{className:eB.meta,children:(0,G.jsx)(tB,{text:e.meta})})]}),e.description===void 0?null:(0,G.jsx)(`p`,{className:eB.sectionNote,children:(0,G.jsx)(Wg,{text:e.description})}),e.pieces.length===0?(0,G.jsx)(`p`,{className:eB.sectionNote,children:(0,G.jsx)(Wg,{text:e.empty})}):(0,G.jsx)(`ul`,{className:eB.list,children:e.pieces.map(e=>(0,G.jsx)(fB,{onToggle:n,open:t.has(e.key),piece:e},e.key))})]},e.id))}),mB=e=>e.kind===`run`?`run/${e.run}/${e.node}`:`builder/${e.project}/${e.workflow}/${e.node}`,hB={answer:null,error:null,loading:!0},gB=e=>{let{client:t}=qy(),n=(0,V.use)(ZM),[r,i]=(0,V.useState)(hB),a=(0,V.useRef)(!1);a.current=r.answer!==null;let[o,s]=(0,V.useState)(0),c=e.kind===`builder`?e.revision:0,l=mB(e);(0,V.useEffect)(()=>{let r=!0;i(e=>({...e,loading:!0}));let o=e.kind===`run`?t.call(`runContext`,{params:{id:e.run,node:e.node}}):t.call(`builderContext`,{params:{id:e.project,name:e.workflow,node:e.node}});return(async()=>{let e=await o;r&&(e.ok||n?.announce(Xz(e.error,a.current)),i(t=>e.ok?{answer:e.data,error:null,loading:!1}:{answer:t.answer,error:e.error,loading:!1}))})(),()=>{r=!1}},[t,n,l,c,o]);let u=(0,V.useCallback)(()=>{s(e=>e+1)},[]);return{...r,reload:u}},_B=e=>{let t=ab(qy().runs);if(e.kind===`builder`)return{from:`Builder · ${e.workflow}${e.draft?` · draft`:``}`,cli:$z(e.workflow,e.node),planned:e.draft?`Planned from the unsaved draft. It updates after each edit.`:`Planned from the saved file.`};let n=t?.find(({id:t})=>t===e.run);return{from:n===void 0?e.run:`${n.workflow} · ${e.run}`,cli:$z(n===void 0?`<workflow>`:Qz(n.file,n.project),e.node),planned:`Planned from the project's files as they are now.`}},vB=({target:e,hadFocus:t})=>{let{answer:n,error:r,loading:i,reload:a}=gB(e),o=_B(e),[s,c]=(0,V.useState)(new Set),l=(0,V.useRef)(null),u=(0,V.useRef)(null),d=(0,V.useCallback)(e=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),f=n?.planned===!0?n.explanation:null,p=(0,V.useMemo)(()=>f===null?[]:Yz(f),[f]),m=n===null?r===null?`loading`:`failed`:`shown`,h=(0,V.useRef)(null);return(0,V.useEffect)(()=>{let e=document.activeElement,n=e!==null&&l.current?.contains(e)===!0,r=(e===null||e===document.body)&&t.current,i=h.current!==m;h.current=m,(r||i&&n)&&u.current?.focus()},[m,n]),(0,G.jsxs)(`div`,{className:eB.panel,ref:l,children:[(0,G.jsx)(rB,{appendedTokens:f?.appendedTokens,cli:o.cli,from:o.from,node:e.node,onReload:a,planned:n?.planned===!1?null:o.planned,reload:r===null?`Reload`:`Try again`,titleRef:u,type:f?.type,updating:i&&n!==null,children:(0,G.jsx)(aB,{answer:n,error:r})}),n?.planned===!1?(0,G.jsx)(oB,{why:n.why}):null,f===null?null:(0,G.jsx)(pB,{busy:i,onToggle:d,opened:s,sections:p}),n===null&&r===null?(0,G.jsx)(`p`,{"aria-busy":`true`,className:eB.card,children:(0,G.jsx)(`span`,{className:eB.description,children:`Planning ${e.node}…`})}):null,m===`loading`?null:(0,G.jsx)(sB,{cli:o.cli,draft:e.kind===`builder`&&e.draft,sized:f!==null})]})},yB=({target:e,hadFocus:t})=>{let n=(0,V.useRef)(null);return(0,V.useEffect)(()=>{let e=document.activeElement;(e===null||e===document.body)&&t.current&&n.current?.focus()},[t]),(0,G.jsx)(`div`,{ref:n,tabIndex:-1,children:(0,G.jsx)(cB,{target:e})})},bB=({target:e,hadFocus:t})=>{if(e===null||e.node===null)return(0,G.jsx)(yB,{hadFocus:t,target:e});let n={...e,node:e.node};return(0,G.jsx)(vB,{hadFocus:t,target:n},mB(n))},xB=()=>{let e=ab(qy().contextTarget),t=(0,V.useRef)(!1);return(0,G.jsx)(`div`,{className:eB.host,onBlur:e=>{let n=e.relatedTarget;(n instanceof Node?!e.currentTarget.contains(n):e.target.isConnected)&&(t.current=!1)},onFocus:()=>{t.current=!0},children:(0,G.jsx)(bB,{hadFocus:t,target:e})})},SB=e=>e.slice(0,12),CB=[[`open`,`Not dismissed`],[`all`,`All`],[`new`,`New`],[`triaged`,`Triaged`],[`accepted`,`Accepted`],[`resolved`,`Resolved`],[`published`,`Published`],[`dismissed`,`Dismissed`]],wB=[{value:`all`,label:`All`},{value:`ork`,label:`ork`},{value:`workflow`,label:`workflow`},{value:`project`,label:`project`}],TB=(e,t)=>t===`all`?!0:t===`open`?e.status!==`dismissed`:e.status===t,EB=e=>CB.map(([t,n])=>({value:t,label:`${n} · ${String(e.filter(e=>TB(e,t)).length)}`})),DB=(e,t,n)=>e?n===null?`list`:t:`both`,OB=(e,{status:t,about:n})=>e.filter(e=>TB(e,t)&&(n===`all`||e.target===n)),kB=(e,t,n)=>e===1?`1 ${t}`:`${e.toLocaleString(`en`)} ${n}`,AB=e=>kB(e,`item`,`items`),jB=e=>kB(e,`time`,`times`),MB=e=>kB(e,`run`,`runs`),NB={open:`No items`,all:`No items`,new:`No new items`,triaged:`No triaged items`,accepted:`No accepted items`,resolved:`Nothing resolved`,published:`Nothing published`,dismissed:`Nothing dismissed`},PB=({status:e,about:t})=>{let n=NB[e]??`No items`,r=e===`open`&&t===`all`?`Every item is dismissed.`:`${n}${t===`all`?``:` about ${t}`}.`,i=[e===`all`?[]:[`Status: All`],t===`all`?[]:[`About: All`]].flat();return{title:r,body:`${i.join(` and `)} ${i.length>1?`show`:`shows`} every item.`}},FB=(e,t,n)=>{let r=e.findIndex(({id:e})=>e===n),i=t.filter(({id:e})=>e!==n);return i[Math.min(Math.max(r,0),i.length-1)]},IB=(e,t)=>e.find(e=>e.merged.includes(t)),LB={ok:!1,why:`reading what it allows`},RB=(e,...t)=>{if(!e.ok)return{ok:!1,why:e.why};let n=t.find(e=>e!==void 0);return n===void 0?{ok:!0}:{ok:!1,why:n}},zB=e=>{let t=e.lessons,[n]=t;return t.every(e=>!e.ok)&&n!==void 0&&!n.ok?n.error:void 0},BB=(e,t)=>{let n=SB(e.id),r=e=>{if(t===null)return LB;let{actions:n,project:r}=t;return e===`lesson`?RB(n.lesson,zB(t)):e===`apply`?RB(n.apply,r.ok?void 0:r.error):RB(n[e])},i={key:`accept`,word:`Accept`,cli:`ork feedback accept ${n}`,variant:`default`,check:r(`accept`)};return e.target===`ork`?[i,{key:`publish`,word:`Publish…`,cli:`ork feedback publish ${n}`,variant:`primary`,check:r(`publish`)}]:[i,{key:`lesson`,word:`Add lesson…`,cli:`ork feedback accept ${n} --lesson`,variant:`default`,check:r(`lesson`)},{key:`apply`,word:`Propose fix…`,cli:`ork feedback apply ${n}`,variant:`primary`,check:r(`apply`)}]},VB=(e,t)=>t.ok?e:`${e}: ${t.why}`,HB=e=>`Starts a run of \`ork:feedback-apply\` in \`${e}\`. It's a paid run, like any you start. A worker reads this item and that project's records of it, and Ork commits the smallest change that would stop it on a branch of its own, in a worktree. The worker reads and edits files and runs no commands. Then you're asked to keep or discard the branch, in Decisions.`,UB=({item:e,id:t,root:n,acts:r,open:i,onOpenChange:a})=>{let[o,s]=(0,V.useState)(``),c=(0,V.useRef)(!1);return(0,G.jsx)(SC,{cli:`ork feedback apply ${t}${o===``?``:` --driver ${o}`}`,confirm:`Start run`,description:HB(n??`its project`),finalFocus:()=>{let e=c.current;return c.current=!1,!e},onConfirm:async()=>{let t=await r.apply(e,o);return c.current=t===null,t},onOpenChange:a,open:i,pending:`Starting…`,title:`Propose a fix for ${t}?`,variant:`primary`,children:(0,G.jsx)(qw,{onChange:s,value:o})})},WB=(e,t)=>`about ${e.toLocaleString(`en`)} of ${t.toLocaleString(`en`)} tokens`,GB=(e,t,n)=>[`ork feedback accept ${SB(e.id)} --lesson`,...t===null||e.workflows.length<2?[]:[`--workflow ${sT(t)}`],...n===e.title||n.trim()===``?[]:[`-m ${sT(n)}`]].join(` `),KB=(e,t,n)=>e===null?`Choose a workflow.`:t.trim()===``?`Write the lesson first.`:n!==void 0&&!n.ok?n.error:null,qB=({place:e,cap:t})=>e.ok?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`p`,{className:J.place,children:[(0,G.jsx)(`span`,{className:J.caption,children:`Goes to `}),(0,G.jsx)(Wg,{text:`\`${e.file}\` in \`${e.root}\``})]}),(0,G.jsx)(ez,{label:`Now`,max:t,text:e.exists?WB(e.tokens,t):`no lessons file yet; this starts it`,value:e.tokens})]}):(0,G.jsx)(`p`,{className:J.note,children:(0,G.jsx)(Wg,{text:e.error})}),JB=({open:e,onOpenChange:t,item:n,detail:r,onAdd:i})=>{let a=n.workflows.length>1,[o,s]=(0,V.useState)(a?null:n.workflows[0]??null),[c,l]=(0,V.useState)(n.title),[u,d]=(0,V.useState)(!1),[f,p]=(0,V.useState)(null),m=(0,V.useId)(),h=r.lessons.find(e=>e.workflow===o),g=KB(o,c,h),_=async()=>{if(g!==null||u)return;d(!0),p(null);let e=await i({lesson:!0,...c===n.title?{}:{text:c},...a&&o!==null?{workflow:o}:{}});d(!1),p(e),e===null&&t(!1)};return(0,G.jsx)(bC,{description:o===null?`Every later session of the workflow you choose reads it, in the workflow layer of its context.`:`Every later session of \`${o}\` reads it, in the workflow layer of its context.`,onOpenChange:e=>{u||t(e)},open:e,title:o===null?`Add a lesson`:`Add a lesson for \`${o}\``,children:(0,G.jsxs)(QL,{onSend:()=>{_()},children:[a?(0,G.jsx)(Bw,{label:`Workflow (required)`,onChange:e=>{s(e===``?null:e)},options:[{value:``,label:`Choose one`},...n.workflows.map(e=>({value:e,label:e}))],value:o??``}):null,(0,G.jsx)(Uw,{description:`Its first line is the entry; later lines sit under it.`,label:`Lesson`,multiline:!0,onChange:l,required:!0,value:c}),h===void 0?null:(0,G.jsx)(qB,{cap:r.lessonCap,place:h}),(0,G.jsx)(YS,{command:GB(n,o,c)}),(0,G.jsx)($L,{id:m,why:g}),(0,G.jsx)(eR,{text:f}),(0,G.jsxs)(xC,{children:[(0,G.jsx)(q,{disabled:u,onClick:()=>{t(!1)},type:`button`,variant:`ghost`,children:`Cancel`}),(0,G.jsx)(q,{"aria-describedby":m,"aria-keyshortcuts":ZL,disabled:g!==null||u,focusableWhenDisabled:!0,type:`submit`,variant:`primary`,children:u?`Adding…`:`Add lesson`})]})]})})},YB={slot:`_slot_17gek_6`,alert:`_alert_17gek_17`},XB=({id:e,words:t,takeFocus:n,onTryAgain:r})=>{let i=(0,V.useRef)(null);return(0,V.useEffect)(()=>{if(t===null)return;let e=document.activeElement,r=e===null||e===document.body||e.getAttribute(`aria-disabled`)===`true`;(n===`always`||r)&&i.current?.querySelector(`button`)?.focus()},[t,n]),(0,G.jsxs)(`div`,{className:YB.slot,ref:i,children:[(0,G.jsx)(`p`,{className:YB.alert,id:e,role:`alert`,children:t===null?null:(0,G.jsx)(Wg,{text:t})}),t===null||r===void 0?null:(0,G.jsx)(q,{onClick:r,variant:`ghost`,children:`Try again`})]})},ZB=({url:e})=>(0,G.jsxs)(`a`,{className:J.link,href:e,rel:`noreferrer`,target:`_blank`,children:[e,(0,G.jsx)(Sy,{}),(0,G.jsx)(zw,{children:` (opens in a new tab)`})]}),QB=({preview:e})=>e.plan.kind===`create`?(0,G.jsx)(`p`,{className:J.message,children:(0,G.jsx)(Wg,{text:`A new thread in the Agent feedback category of \`${e.repo}\`.`})}):(0,G.jsxs)(`p`,{className:J.message,children:[`A thread for this exists, so this goes on it as a +1 comment:`,` `,(0,G.jsx)(ZB,{url:e.plan.url})]}),$B="Reading Ork's Discussions with your `gh`…",eV=`Nothing to show: the preview couldn't be read.`,tV=({id:e})=>(0,G.jsx)(`span`,{className:J.note,id:e,children:`From the last read`}),nV=({preview:e,reading:t,region:n,stale:r,staleId:i})=>{let a=e?.plan.kind!==`comment`,o=e===void 0?``:a?e.post.body:e.post.comment,s=a?`Body`:`Comment`,c=r&&e!==void 0;return(0,G.jsxs)(G.Fragment,{children:[e===void 0||!a?null:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:J.line,children:[(0,G.jsx)(`p`,{className:J.caption,children:`Title`}),c?(0,G.jsx)(tV,{}):null]}),(0,G.jsx)(`p`,{className:J.preview,"data-stale":r?``:void 0,children:e.post.title})]}),(0,G.jsxs)(`div`,{className:J.wellHead,children:[(0,G.jsxs)(`div`,{className:J.line,children:[(0,G.jsx)(`p`,{className:J.caption,children:s}),c?(0,G.jsx)(tV,{id:i}):null]}),o===``?null:(0,G.jsx)(`span`,{className:J.wellCopy,children:(0,G.jsx)(qS,{label:`Copy the ${s.toLowerCase()}`,text:o})})]}),(0,G.jsx)(`section`,{"aria-busy":t,"aria-describedby":c?i:void 0,"aria-label":`Text to post`,className:J.preview,"data-scrolls":``,"data-stale":r?``:void 0,ref:n,tabIndex:0,children:o===``?(0,G.jsx)(Wg,{text:t?$B:eV}):o}),(0,G.jsx)(`p`,{className:J.note,children:`This is the Markdown that is sent, as it is. Secrets, your projects' paths, your home folder, emails, host names and IP addresses are taken out.`})]})},rV=({children:e})=>(0,G.jsxs)(`div`,{className:J.dialogFoot,children:[(0,G.jsx)(`p`,{className:J.note,children:(0,G.jsx)(Wg,{text:"It posts with your own `gh` login."})}),(0,G.jsx)(`div`,{className:J.actions,children:e})]}),iV=({id:e})=>(0,G.jsx)(`p`,{className:J.note,id:e,children:(0,G.jsx)(Wg,{text:"Your workflows' and projects' folders' names become `<name>`."})}),aV=({id:e,url:t,kind:n,onClose:r})=>{let i=(0,V.useRef)(null);return(0,V.useEffect)(()=>{i.current?.focus()},[]),(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`h3`,{className:J.result,ref:i,tabIndex:-1,children:n===`created`?`Posted`:`Added a +1`}),(0,G.jsx)(`p`,{className:J.message,children:(0,G.jsx)(ZB,{url:t})}),(0,G.jsx)(`p`,{className:J.message,children:`${e} is published.`}),(0,G.jsx)(`div`,{className:J.actions,children:(0,G.jsx)(q,{onClick:r,children:`Close`})})]})},oV=e=>e.step===`reading`||e.step===`readFailed`?e.shown:`preview`in e?e.preview:void 0,sV=e=>e.step===`reading`||e.step===`readFailed`,cV=e=>/[.!?]$/u.test(e.trim())?e.trim():`${e.trim()}.`,lV=(e,t,n)=>{let[r,i]=(0,V.useState)(!1),[a,o]=(0,V.useState)({step:`reading`}),s=(0,V.useRef)(0),c=(0,V.useCallback)(async n=>{s.current+=1;let r=s.current,i=await e.call(`publishPreview`,{params:{id:t},body:{hideNames:n}});r===s.current&&o(e=>{if(i.ok)return{step:`preview`,preview:i.data,changed:!1};let t=oV(e);return t===void 0?{step:`readFailed`,error:i.error}:{step:`readFailed`,error:i.error,shown:t}})},[e,t]);(0,V.useEffect)(()=>{c(!1)},[c]);let l=(e,t)=>{o(t===void 0?{step:`reading`}:{step:`reading`,shown:t}),c(e)},u=async i=>{o({step:`posting`,preview:i});let a=await e.call(`publish`,{params:{id:t},body:{hideNames:r,digest:i.digest}});if(a.ok){o({step:`posted`,url:a.data.url,kind:a.data.kind}),n();return}if(a.status!==409){o({step:`postFailed`,preview:i,error:a.error});return}let s=await e.call(`publishPreview`,{params:{id:t},body:{hideNames:r}});s.ok?s.data.digest===i.digest?o({step:`postFailed`,preview:i,error:a.error}):o({step:`preview`,preview:s.data,changed:!0}):o({step:`readFailed`,error:s.error,shown:i})};return{step:a,hideNames:r,setHideNames:e=>{i(e),l(e,oV(a))},tryAgain:()=>{a.step===`postFailed`?u(a.preview):l(r)},post:()=>{a.step===`preview`&&u(a.preview)}}},uV=`The text to post changed since you read it. Read it again before posting.`,dV=e=>e.step===`readFailed`?`Could not read Ork's Discussions: ${cV(e.error)} Nothing was sent.`:e.step===`postFailed`?`Could not post: ${cV(e.error)}`:null,fV=()=>{let e=document.activeElement;return e===null||e===document.body||e.getAttribute(`role`)===`dialog`},pV=e=>e.step===`reading`?`Reading the preview…`:null,mV=({client:e,item:t,id:n,region:r,onStep:i,onClose:a,onPosted:o})=>{let s=lV(e,t,o),{step:c,hideNames:l}=s,u=(0,V.useId)(),d=(0,V.useId)(),f=(0,V.useId)(),p=(0,V.useId)();if((0,V.useEffect)(()=>{i(c),c.step!==`posted`&&fV()&&r.current?.focus()},[c,i,r]),c.step===`posted`)return(0,G.jsx)(aV,{id:n,kind:c.kind,onClose:a,url:c.url});let m=oV(c),h=c.step===`posting`,g=m?.plan.kind===`comment`;return(0,G.jsxs)(G.Fragment,{children:[c.step===`preview`&&c.changed?(0,G.jsx)(`p`,{role:`alert`,children:uV}):null,m===void 0?null:(0,G.jsx)(QB,{preview:m}),(0,G.jsx)(nV,{preview:m,reading:c.step===`reading`,region:r,stale:sV(c),staleId:p}),(0,G.jsx)(qC,{checked:l,describedBy:u,disabled:h,label:`Hide repository and workflow names`,onChange:s.setHideNames}),(0,G.jsx)(iV,{id:u}),(0,G.jsx)(YS,{command:`ork feedback publish ${n}${l?` --hide-names`:``}`}),(0,G.jsx)(XB,{id:f,onTryAgain:s.tryAgain,takeFocus:c.step===`postFailed`?`always`:`ifLost`,words:dV(c)}),(0,G.jsx)($L,{id:d,why:pV(c)}),(0,G.jsxs)(rV,{children:[(0,G.jsx)(q,{disabled:h,focusableWhenDisabled:!0,onClick:a,variant:`ghost`,children:`Cancel`}),(0,G.jsx)(q,{"aria-describedby":`${d} ${f}`,disabled:c.step!==`preview`,focusableWhenDisabled:!0,onClick:s.post,type:`button`,variant:`primary`,children:h?`Posting…`:g?`Post +1 comment`:`Post thread`})]})]})},hV=({open:e,onOpenChange:t,client:n,item:r,id:i,onPosted:a,onCancelled:o})=>{let s=(0,V.useRef)(null),c=(0,V.useRef)({busy:!1,tried:!1}),l=(0,V.useCallback)(e=>{let t=e.step===`posting`;c.current={busy:t,tried:c.current.tried||t||e.step===`posted`}},[]),u=()=>{c.current.busy||(c.current.tried||o(),c.current={busy:!1,tried:!1},t(!1))};return(0,G.jsx)(bC,{initialFocus:s,onOpenChange:e=>{e?t(!0):u()},open:e,size:`wide`,title:`Publish ${i} to Ork's Discussions`,children:(0,G.jsx)(mV,{client:n,id:i,item:r,onClose:u,onPosted:a,onStep:l,region:s})})},gV=({item:e,detail:t,acts:n})=>{let r=qy(),[i,a]=(0,V.useState)(null),[o,s]=(0,V.useState)(0),c=SB(e.id),l=e.status===`dismissed`,u=e=>{s(e=>e+1),a(e)},d=e=>{e||a(null)},f=t=>{t===`accept`?n.accept(e):u(t===`lesson`?`lesson`:t===`apply`?`apply`:`publish`)};return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{"aria-label":`Actions on ${c}`,className:J.actions,role:`group`,children:[BB(e,t).map(({key:e,word:t,cli:n,variant:r,check:i})=>(0,G.jsx)(q,{"aria-label":VB(t,i),cli:n,disabled:!i.ok,focusableWhenDisabled:!0,onClick:()=>{f(e)},tip:i.ok?void 0:i.why,variant:r,children:t},e)),(0,G.jsx)(q,{cli:`ork feedback ${l?`restore`:`dismiss`} ${c}`,onClick:()=>{n.setStatus(e,l?`new`:`dismissed`)},variant:`ghost`,children:l?`Restore`:`Dismiss`},`status`)]}),e.target===`ork`?(0,G.jsx)(`p`,{className:J.note,children:`About Ork itself: it has no lesson or fix in your projects. Publish shares it with Ork's maintainers.`}):null,t===null?null:(0,G.jsx)(JB,{detail:t,item:e,onAdd:r=>n.addLesson(e,r,t.lessonCap),onOpenChange:d,open:i===`lesson`},`lesson-${String(o)}`),(0,G.jsx)(UB,{acts:n,id:c,item:e,onOpenChange:d,open:i===`apply`,root:t?.project.ok===!0?t.project.root:null},`fix-${String(o)}`),e.target===`ork`?(0,G.jsx)(hV,{client:r.client,id:c,item:e.id,onCancelled:()=>{n.announce(`Nothing was sent.`)},onOpenChange:d,onPosted:()=>{n.reloadAll()},open:i===`publish`},`publish-${String(o)}`):null]})},_V=({name:e,children:t})=>(0,G.jsxs)(`div`,{className:J.fact,children:[(0,G.jsx)(`dt`,{className:J.factName,children:e}),(0,G.jsx)(`dd`,{className:J.factValue,children:t})]}),vV=({name:e,values:t})=>t.length===0?null:(0,G.jsx)(_V,{name:e,children:t.join(`, `)}),yV=({item:e,onSplit:t})=>{let n=SB(e.id);return(0,G.jsxs)(`dl`,{className:J.facts,children:[(0,G.jsx)(_V,{name:`Item`,children:n}),(0,G.jsx)(_V,{name:`About`,children:e.target}),(0,G.jsx)(_V,{name:`Kind`,children:e.kind}),(0,G.jsx)(_V,{name:`Severity`,children:e.severity}),(0,G.jsx)(_V,{name:`Seen`,children:(0,G.jsxs)(`span`,{children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,children:`${String(e.count)}×`}),(0,G.jsx)(zw,{children:jB(e.count)}),` in ${MB(e.runs.length)}`]})}),(0,G.jsx)(_V,{name:`First seen`,children:(0,G.jsx)(`time`,{dateTime:e.firstSeen,children:_z(e.firstSeen)})}),(0,G.jsx)(_V,{name:`Last seen`,children:(0,G.jsx)(`time`,{dateTime:e.lastSeen,children:_z(e.lastSeen)})}),(0,G.jsx)(vV,{name:`Workflows`,values:e.workflows}),(0,G.jsx)(vV,{name:`Models`,values:e.models}),(0,G.jsx)(vV,{name:`Sources`,values:e.sources}),e.merged.length===0?null:(0,G.jsxs)(_V,{name:`Merged`,children:[e.merged.map(SB).join(`, `),(0,G.jsx)(q,{cli:`ork feedback split ${n}`,onClick:t,variant:`ghost`,children:`Split`})]})]})},bV=({onBack:e})=>(0,G.jsxs)(q,{onClick:e,variant:`ghost`,children:[(0,G.jsx)(Qv,{}),`Back to items`]}),xV=({run:e,onOpen:t})=>(0,G.jsxs)(`p`,{className:J.line,children:[(0,G.jsx)(`span`,{className:J.lineIcon,children:(0,G.jsx)(Gv,{})}),(0,G.jsxs)(`span`,{className:J.message,children:[`Run `,(0,G.jsx)(`code`,{children:e}),` is proposing a fix.`]}),(0,G.jsx)(q,{"aria-label":`Open run ${e}`,onClick:()=>{t(e)},variant:`ghost`,children:`Open run`})]}),SV=e=>[_z(e.at),e.feedback.source,...e.feedback.code===void 0?[]:[e.feedback.code],`run ${e.runId}`,...e.node===void 0?[]:[e.node]].join(` · `),CV=({record:e,title:t,onOpenRun:n})=>{let{feedback:r,runId:i,node:a}=e;return(0,G.jsxs)(`li`,{className:J.record,children:[(0,G.jsxs)(`p`,{className:J.recordMeta,children:[(0,G.jsx)(`span`,{children:SV(e)}),(0,G.jsxs)(q,{onClick:()=>{n(i,a)},variant:`ghost`,children:[`Open run`,(0,G.jsx)(zw,{children:` ${i}${a===void 0?``:` at ${a}`}, ${_z(e.at)}`})]})]}),r.title===t?null:(0,G.jsx)(`h4`,{className:J.recordTitle,children:r.title}),r.body===``?null:(0,G.jsx)(`p`,{className:J.recordBody,children:r.body}),r.evidence.length===0?null:(0,G.jsxs)(`p`,{className:J.evidence,children:[(0,G.jsx)(`span`,{className:J.caption,children:`Evidence `}),r.evidence.join(`, `)]})]})},wV=({item:e,read:t,onOpenRun:n})=>{let r=SB(e.id),i=t.detail?.records;return(0,G.jsxs)(`div`,{className:J.section,children:[(0,G.jsx)(`h3`,{className:J.caption,children:i===void 0?`Records`:`Records · ${String(i.length)}, newest first`}),i===void 0&&t.error!==null?(0,G.jsxs)(`div`,{className:J.line,children:[(0,G.jsx)(`p`,{className:J.alert,role:`alert`,children:(0,G.jsx)(`span`,{children:(0,G.jsx)(Wg,{text:`Could not read the records: ${t.error}`})})}),(0,G.jsx)(q,{onClick:t.reload,variant:`ghost`,children:`Try again`})]}):null,i===void 0&&t.error===null?(0,G.jsx)(`p`,{"aria-busy":`true`,className:J.message,children:`Reading records…`}):null,i===void 0?null:(0,G.jsx)(`ol`,{"aria-label":`Records of ${r}, newest first`,className:J.records,role:`list`,children:i.toReversed().map(t=>(0,G.jsx)(CV,{onOpenRun:n,record:t,title:e.title},t.id))})]})},TV=({item:e,read:t,acts:n,narrow:r,onBack:i,onLeave:a})=>{let o=(0,V.useId)(),s=t.detail?.fixRun;return(0,G.jsxs)(`section`,{"aria-labelledby":o,className:J.detail,onKeyDown:e=>{let t=document.querySelector(`[data-modal]`)!==null;e.key===`Escape`&&!t&&a()},children:[r?(0,G.jsx)(bV,{onBack:i}):null,(0,G.jsxs)(`div`,{className:J.head,children:[(0,G.jsx)(`h2`,{className:J.title,"data-feedback-heading":``,id:o,tabIndex:-1,children:e.title}),(0,G.jsx)(SD,{pill:!0,status:e.status})]}),(0,G.jsx)(yV,{item:e,onSplit:()=>{n.split(e)}}),s===void 0?null:(0,G.jsx)(xV,{onOpen:n.openRun,run:s}),(0,G.jsx)(gV,{acts:n,detail:t.detail,item:e}),(0,G.jsx)(wV,{item:e,onOpenRun:n.openRun,read:t}),(0,G.jsx)(YS,{command:`ork feedback show ${e.id.slice(0,12)}`})]})},EV=e=>{let t=[...e.currentTarget.querySelectorAll(`button`)],n=t.findIndex(e=>e===document.activeElement),r=t.length-1,i={ArrowDown:Math.min(n+1,r),ArrowUp:Math.max(n-1,0),Home:0,End:r}[e.key];i!==void 0&&(e.preventDefault(),t[i]?.focus())},DV=()=>(0,G.jsx)(zw,{children:`, `}),OV=(0,V.memo)(({item:e,chosen:t,tabStop:n,onChoose:r})=>(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{"aria-current":t?`true`:void 0,className:J.row,"data-item":e.id,onClick:()=>{r(e.id)},tabIndex:n?0:-1,type:`button`,children:[(0,G.jsxs)(`span`,{className:J.rowTop,children:[(0,G.jsx)(`span`,{className:J.rowTitle,children:e.title}),(0,G.jsx)(DV,{}),(0,G.jsx)(SD,{status:e.status})]}),(0,G.jsx)(DV,{}),(0,G.jsxs)(`span`,{className:J.rowMeta,children:[(0,G.jsx)(`span`,{children:SB(e.id)}),(0,G.jsx)(DV,{}),(0,G.jsxs)(`span`,{children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,children:`${String(e.count)}×`}),(0,G.jsx)(zw,{children:jB(e.count)})]}),(0,G.jsx)(DV,{}),(0,G.jsx)(`span`,{children:`${e.target} · ${e.kind}`}),e.severity===`high`?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(DV,{}),(0,G.jsx)(`span`,{className:J.high,children:`high`})]}):null,e.merged.length===0?null:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(DV,{}),(0,G.jsx)(`span`,{children:`+${String(e.merged.length)} merged`})]}),(0,G.jsx)(DV,{}),(0,G.jsxs)(`span`,{children:[(0,G.jsx)(zw,{children:`last seen `}),(0,G.jsx)(`time`,{dateTime:e.lastSeen,children:_z(e.lastSeen)})]})]})]})}));OV.displayName=`FeedbackRow`;var kV=({items:e,chosen:t,onChoose:n})=>{let r=e.some(({id:e})=>e===t)?t:e[0]?.id;return(0,G.jsx)(`ul`,{"aria-label":`Feedback items`,className:J.list,onKeyDown:EV,role:`list`,children:e.map(e=>(0,G.jsx)(OV,{chosen:e.id===t,item:e,onChoose:n,tabStop:e.id===r},e.id))})},AV=({filter:e,items:t,count:n,updating:r,failed:i,onFilter:a,onReload:o})=>(0,G.jsxs)(`div`,{className:J.tools,children:[(0,G.jsx)(Bw,{label:`Status`,onChange:t=>{a({...e,status:t})},options:EB(t??[]),value:e.status}),(0,G.jsx)(Bw,{label:`About`,onChange:t=>{a({...e,about:t})},options:wB,value:e.about}),(0,G.jsxs)(`div`,{className:J.toolsEnd,children:[t===null?null:(0,G.jsx)(`span`,{className:J.count,children:AB(n)}),r?(0,G.jsx)(`span`,{className:J.updating,children:`Updating…`}):null,(0,G.jsx)(q,{cli:e.status===`all`||e.status===`dismissed`?`ork feedback list --all`:`ork feedback list`,onClick:o,variant:`ghost`,children:i?`Try again`:`Reload`})]})]}),jV=({error:e})=>(0,G.jsxs)(`p`,{className:J.alert,"data-tone":`failed`,role:`alert`,children:[(0,G.jsx)(`span`,{className:J.lineIcon,children:(0,G.jsx)(yy,{})}),(0,G.jsx)(`span`,{children:(0,G.jsx)(Wg,{text:`Could not read feedback: ${e}`})})]}),MV=({anything:e,filter:t})=>{if(!e)return(0,G.jsx)(CC,{cli:`ork feedback list`,title:`No feedback yet.`,children:`What gets in your runs' way lands here: Ork's own signals, the agents' reports and your notes. In a terminal:`});let{title:n,body:r}=PB(t);return(0,G.jsx)(CC,{title:n,children:r})},NV=(e,t,n,r)=>{e.arriveAt(n),r!==void 0&&e.selectNode(r),t?.goTo(`monitor`),requestAnimationFrame(()=>{let t=document.querySelector(`[data-run-heading="${n}"]`);t!==null&&(e.takeArrival(n),t.focus())})},PV=e=>{let{state:t,workspace:n,filter:r,narrow:i,choose:a,focus:o}=e,s=(0,V.useRef)(!1),c=()=>kz(t.feedback.state.getValue())?.data??[],l=(e,r)=>{NV(t,n,e,r)},u=async()=>{await t.feedback.load(),e.reloadDetail()};return{moving:s,setStatus:async(e,l)=>{let d=SB(e.id),f=OB(c(),r),p=await t.client.call(`feedbackStatus`,{params:{id:e.id},body:{status:l}});if(!p.ok){let e=l===`new`?`restore`:`dismiss`;Hy.add({title:`Could not ${e} ${d}`,description:p.error});return}s.current=!0,await u();let m=OB(c(),r);if(!m.some(({id:t})=>t===e.id)){let t=FB(f,m,e.id);a(t?.id??null),o(t===void 0?`list`:i?`heading`:{row:t.id})}s.current=!1,n?.announce(l===`dismissed`?`Dismissed ${d}. It's listed under All and Dismissed.`:`Restored ${d} as new.`)},accept:async e=>{let r=SB(e.id),i=await t.client.call(`accept`,{params:{id:e.id},body:{lesson:!1}});i.ok?(n?.announce(`Accepted ${r}.`),await u()):Hy.add({title:`Could not accept ${r}`,description:i.error})},addLesson:async(e,n,r)=>{let i=await t.client.call(`accept`,{params:{id:e.id},body:n});if(!i.ok)return`Could not add the lesson: ${i.error}`;let{lesson:a}=i.data;return Hy.add({title:`Lesson added`,description:a===void 0?`${SB(e.id)} is accepted.`:`\`${a.file}\` in \`${a.root}\`, ${WB(a.tokens,r)}. Every session of \`${a.workflow}\` reads it from now on.`}),u(),null},apply:async(e,n=``)=>{let r=await t.client.call(`apply`,{params:{id:e.id},body:n===``?{}:{driver:n}});if(!r.ok)return`Could not start the run: ${r.error}`;let{runId:i}=r.data;return Hy.add({title:`Run ${i} started`,description:`\`ork:feedback-apply\` is proposing a fix for ${SB(e.id)}. Its question comes to Decisions.`}),l(i),u(),null},split:async e=>{let r=SB(e.id),i=await t.client.call(`split`,{params:{id:e.id}});i.ok?(o(`heading`),n?.announce(`Split ${AB(i.data.moved)} back out of ${r}.`),await u()):Hy.add({title:`Could not split ${r}`,description:i.error})},openRun:(e,t)=>{l(e,t)},reloadAll:u,announce:e=>{n?.announce(e)}}},FV=5e3,IV=48,LV=16,RV=e=>{let t=ab(e.feedback.state),n=ab(e.runs),r=(0,V.useRef)(0),i=(0,V.useRef)(null),a=(0,V.useRef)(n),o=(0,V.useCallback)(async()=>{r.current=Date.now(),await e.feedback.load()},[e]);return(0,V.useEffect)(()=>(o(),()=>{i.current!==null&&clearTimeout(i.current),i.current=null}),[o]),(0,V.useEffect)(()=>{if(a.current===n||(a.current=n,i.current!==null))return;let e=Math.max(0,r.current+FV-Date.now());i.current=setTimeout(()=>{i.current=null,o()},e)},[n,o]),{read:t,load:o}},zV=(e,t,n)=>{let[r,i]=(0,V.useState)(null),[a,o]=(0,V.useState)(null),[s,c]=(0,V.useState)(``),[l,u]=(0,V.useState)(0),d=`${t??``}|${n}|${String(l)}`;(0,V.useEffect)(()=>{if(t===null)return()=>{};let n=!0;return e.call(`feedbackItem`,{params:{id:t}}).then(e=>(n&&(c(d),e.ok?(i({id:t,value:e.data}),o(null)):o({id:t,value:e.error})),e)),()=>{n=!1}},[e,t,d]);let f=(0,V.useCallback)(()=>{u(e=>e+1)},[]);return{detail:r?.id===t?r.value:null,error:a?.id===t?a.value:null,loading:t!==null&&s!==d,reload:f}},BV=e=>{let[t,n]=(0,V.useState)(!1);return(0,V.useEffect)(()=>{let t=e.current;if(t===null)return()=>{};let r=new ResizeObserver(([e])=>{let t=e?.contentRect.width??0;if(t===0)return;let r=getComputedStyle(document.documentElement).fontSize,i=Number(r.replace(`px`,``))||LV;n(t<IV*i)});return r.observe(t),()=>{r.disconnect()}},[e]),t},VV=e=>e===void 0?``:[e.status,e.count,e.lastSeen,...e.merged].join(`|`),HV={heading:`[data-feedback-heading]`,list:`[data-feedback-list]`},UV=(e,t)=>e?.querySelector(typeof t==`string`?HV[t]:`[data-item="${t.row}"]`)??null,WV=e=>{let t=(0,V.useRef)(null),[,n]=(0,V.useState)(0);return(0,V.useEffect)(()=>{let n=t.current;if(n===null)return;let r=UV(e.current,n);r!==null&&(t.current=null,r.focus())}),(0,V.useCallback)(e=>{t.current=e,n(e=>e+1)},[])},GV=()=>{let e=(0,V.useRef)(!1);return{had:e,onFocus:()=>{e.current=!0},onBlur:t=>{let n=t.relatedTarget;(n instanceof Node?!t.currentTarget.contains(n):t.target.isConnected)&&(e.current=!1)}}},KV=()=>{let e=qy(),t=(0,V.use)(ZM),n=ab(e.feedbackFilter),{read:r,load:i}=RV(e),a=(0,V.useRef)(null),o=BV(a),[s,c]=(0,V.useState)(null),[l,u]=(0,V.useState)(`list`),d=kz(r)?.data??null,f=(0,V.useMemo)(()=>d??[],[d]),p=(0,V.useMemo)(()=>OB(f,n),[f,n]),m=p.find(({id:e})=>e===s),h=zV(e.client,m?.id??null,VV(m)),g=WV(a),_=GV(),v=(0,V.useCallback)(e=>{c(e),u(e===null?`list`:`detail`)},[]),y=PV({state:e,workspace:t,filter:n,narrow:o,choose:v,focus:g,reloadDetail:h.reload}),{moving:b}=y;return(0,V.useEffect)(()=>{if(s===null||d===null||b.current||p.some(({id:e})=>e===s))return;let e=IB(f,s);e!==void 0&&p.some(({id:t})=>t===e.id)?(c(e.id),t?.announce(`${SB(s)} was merged into ${SB(e.id)}.`)):o||(c(null),document.activeElement===document.body&&_.had.current&&g(`list`))},[s,d,f,p,o,t,g,b]),{root:a,narrow:o,read:r,all:d,items:f,shown:p,filter:n,chosen:s,item:m,detail:h,acts:y,focusWatch:_,showing:DB(o,l,s),back:()=>{u(`list`);let e=s!==null&&p.some(({id:e})=>e===s);g(e?{row:s}:`list`)},choose:e=>{v(e),o&&g(`heading`)},setFilter:n=>{e.feedbackFilter.setValue(n),t?.announce(`${AB(OB(f,n).length)}.`)},reload:()=>{i(),h.reload()}}},qV=({view:e})=>{let{read:t,all:n,items:r,shown:i,filter:a,chosen:o}=e;return(0,G.jsxs)(`div`,{"aria-label":`Items`,className:J.card,"data-feedback-list":``,role:`group`,tabIndex:-1,children:[t.status===`failed`?(0,G.jsx)(jV,{error:t.error}):null,n===null&&t.status!==`failed`?(0,G.jsx)(`p`,{className:J.message,children:`Reading feedback…`}):null,n!==null&&i.length===0?(0,G.jsx)(MV,{anything:r.length>0,filter:a}):null,i.length===0?null:(0,G.jsx)(kV,{chosen:o,items:i,onChoose:e.choose})]})},JV=({view:e})=>{let{item:t,chosen:n,narrow:r}=e;return(0,G.jsxs)(`div`,{className:J.card,"data-feedback-detail":``,children:[t===void 0?null:(0,G.jsx)(TV,{acts:e.acts,item:t,narrow:r,onBack:e.back,onLeave:e.back,read:e.detail}),t===void 0&&r&&n!==null?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(bV,{onBack:e.back}),(0,G.jsx)(`p`,{className:J.message,children:`${SB(n)} isn't in this list any more.`})]}):null,t===void 0&&!r?(0,G.jsx)(`p`,{className:J.message,children:`Choose an item to read its records.`}):null]})},YV=()=>{let e=KV(),{read:t,all:n,filter:r,shown:i,showing:a,focusWatch:o,root:s}=e;return(0,G.jsxs)(`div`,{"aria-label":`Feedback`,className:J.panel,"data-layout":e.narrow?`narrow`:`wide`,onBlur:o.onBlur,onFocus:o.onFocus,ref:s,role:`group`,tabIndex:-1,children:[(0,G.jsx)(AV,{count:i.length,failed:t.status===`failed`,filter:r,items:n,onFilter:e.setFilter,onReload:e.reload,updating:t.status===`loading`&&n!==null}),(0,G.jsxs)(`div`,{className:J.body,children:[a===`detail`?null:(0,G.jsx)(qV,{view:e}),a===`list`?null:(0,G.jsx)(JV,{view:e})]})]})},XV=`all`,ZV=[{value:`7`,label:`Last 7 days`},{value:`30`,label:`Last 30 days`},{value:`90`,label:`Last 90 days`},{value:XV,label:`All time`}],QV=e=>e===XV,$V=(e,t)=>{if(QV(e))return;let n=new Date(t);return new Date(n.getFullYear(),n.getMonth(),n.getDate()-(Number(e)-1)).toISOString()},eH=(e,t,n)=>[`ork usage`,...e?[`--all`]:[],`--since ${QV(t)?`all`:`${t}d`}`,...n===void 0?[]:[`--by ${n}`]].join(` `),tH=92,nH=e=>String(e).padStart(2,`0`),rH=e=>`${String(e.getFullYear())}-${nH(e.getMonth()+1)}-${nH(e.getDate())}`,iH=e=>{let[t=0,n=1,r=1]=e.split(`-`).map(Number);return new Date(t,n-1,r)},aH=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()-(e.getDay()+6)%7),oH=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),sH=(e,t,n,r)=>{let i=new Map(e.map(e=>[e.key,e])),a=[];for(let e=n;e<=r;e=new Date(e.getFullYear(),e.getMonth(),e.getDate()+t)){let t=rH(e);a.push(i.get(t)??{key:t,costUsd:0,sessions:0})}return a},cH=(e,t,n)=>{let r=e.groups.day,i=t===void 0?r[0]?.key:void 0;if(t===void 0&&i===void 0)return{unit:`day`,bars:[],maxUsd:0};let a=t===void 0?iH(i??``):oH(new Date(t)),o=oH(new Date(n)),s=sH(r,1,a,o),c=s.length>tH?`week`:`day`,l=c===`day`?s:sH(e.groups.week,7,aH(a),o);return{unit:c,bars:l,maxUsd:Math.max(0,...l.map(e=>e.costUsd))}},lH=e=>OD(e),uH=e=>{let t=[...e];return e=>OD(e,t)},dH=e=>e<1e3?String(e):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`,fH=e=>`${String(Math.round(e*100))}%`,pH={panel:`_panel_18mjp_9`,tools:`_tools_18mjp_35`,projectFilter:`_projectFilter_18mjp_51`,body:`_body_18mjp_58`,overview:`_overview_18mjp_81`,breakdowns:`_breakdowns_18mjp_94`,totals:`_totals_18mjp_108`,total:`_total_18mjp_108`,section:`_section_18mjp_147`,heading:`_heading_18mjp_156`,hintsSection:`_hintsSection_18mjp_165`,chartArea:`_chartArea_18mjp_174`,hints:`_hints_18mjp_165`,chartHead:`_chartHead_18mjp_190`,readout:`_readout_18mjp_202`,chart:`_chart_18mjp_174`,column:`_column_18mjp_229`,bar:`_bar_18mjp_244`,axis:`_axis_18mjp_273`,axisEvery:`_axisEvery_18mjp_274`,details:`_details_18mjp_315`,table:`_table_18mjp_323`,number:`_number_18mjp_369`,name:`_name_18mjp_381`,path:`_path_18mjp_396`,retry:`_retry_18mjp_406`,note:`_note_18mjp_410`,refused:`_refused_18mjp_417`,limits:`_limits_18mjp_484`},mH=e=>e.toSorted((e,t)=>t.costUsd-e.costUsd)[0],hH=e=>`${String(e)} session${e===1?``:`s`}`,gH=2,_H=6,vH=14,yH=e=>e<=_H?`always`:e<=vH?`wide`:`never`,bH=({bars:e})=>{let t=yH(e.length);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{"aria-hidden":!0,className:pH.axis,"data-labelled":t,children:[(0,G.jsx)(`span`,{children:e[0]?.key}),(0,G.jsx)(`span`,{children:e.at(-1)?.key})]}),(0,G.jsx)(`div`,{"aria-hidden":!0,className:pH.axisEvery,"data-labelled":t,children:e.map(e=>(0,G.jsx)(`span`,{children:e.key.slice(5)},e.key))})]})},xH=({series:e})=>{let{bars:t,unit:n}=e,r=t.filter(e=>e.costUsd>0||e.sessions>0).toReversed(),i=t.length-r.length,a=uH(r.map(e=>e.costUsd));return(0,G.jsxs)(`details`,{className:pH.details,children:[(0,G.jsx)(`summary`,{children:`Show as a table`}),(0,G.jsxs)(`table`,{className:pH.table,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{scope:`col`,children:n===`day`?`Day`:`Week of`}),(0,G.jsx)(`th`,{className:pH.number,scope:`col`,children:`Cost`}),(0,G.jsx)(`th`,{className:pH.number,scope:`col`,children:`Sessions`})]})}),(0,G.jsx)(`tbody`,{children:r.map(e=>(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:pH.name,scope:`row`,children:e.key}),(0,G.jsx)(`td`,{className:pH.number,children:a(e.costUsd)}),(0,G.jsx)(`td`,{className:pH.number,children:e.sessions})]},e.key))})]}),i===0?null:(0,G.jsxs)(`p`,{className:pH.note,children:[String(i),` `,n,i===1?``:`s`,` with no spend.`]})]})},SH=({series:e})=>{let[t,n]=(0,V.useState)(null),{bars:r,maxUsd:i,unit:a}=e,o=r.find(e=>e.key===t)??null,s=mH(r),c=o??s,l=r.at(-1)?.key,u=a===`day`?`Spend per day`:`Spend per week`,d=a===`day`?``:`week of `,f=s===void 0?u:`${u}, ${String(r.length)} ${a}s. The peak was ${lH(s.costUsd)} ${a===`day`?`on`:`in the week of`} ${s.key}.`;return(0,G.jsxs)(`section`,{"aria-label":u,className:pH.section,children:[(0,G.jsxs)(`div`,{className:pH.chartHead,children:[(0,G.jsx)(`h3`,{className:pH.heading,children:u}),c===void 0?null:(0,G.jsxs)(`p`,{className:pH.readout,children:[o===null?`Peak: `:``,d,c.key,c.key===l?` so far`:``,` · `,lH(c.costUsd),` ·`,` `,hH(c.sessions)]})]}),(0,G.jsx)(`div`,{"aria-label":f,className:pH.chart,onPointerLeave:()=>{n(null)},role:`img`,children:r.map(e=>(0,G.jsx)(`div`,{className:pH.column,"data-partial":e.key===l?``:void 0,"data-pointed":e.key===o?.key?``:void 0,onPointerEnter:()=>{n(e.key)},children:e.costUsd===0?null:(0,G.jsx)(`div`,{className:pH.bar,style:{height:`${String(Math.max(gH,e.costUsd/i*100))}%`}})},e.key))}),(0,G.jsx)(bH,{bars:r}),(0,G.jsx)(xH,{series:e})]})},CH=e=>e===void 0?`All projects`:`This project`,wH=e=>`$${e.toFixed(2)}`,TH=e=>new Date(e).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}),EH=({limits:e})=>e.problems.length===0&&e.caps.length===0&&e.plan.length===0?null:(0,G.jsxs)(`section`,{"aria-label":`Limits`,className:pH.limits,children:[e.problems.map(e=>(0,G.jsx)(`p`,{className:pH.note,children:(0,G.jsx)(Wg,{text:e})},e)),e.caps.map(e=>(0,G.jsx)(ez,{label:`${CH(e.project)}, this ${e.window}`,max:e.capUsd,text:`${wH(e.spentUsd)} of ${wH(e.capUsd)}, resets ${TH(e.resetsAt)}`,value:Math.min(e.spentUsd,e.capUsd)},`${e.project??`all`}-${e.window}`)),e.plan.map(e=>(0,G.jsx)(`p`,{className:pH.note,children:`Your Claude plan's ${e.window.replaceAll(`_`,` `)} limit ${e.status===`rejected`?`was reached`:`is close`}${e.resetsAt===void 0?``:`; it resets ${TH(e.resetsAt)}`}.`},e.window))]}),DH=10,OH=({title:e,label:t,groups:n,total:r,nameOf:i,moreCommand:a})=>{let o=n.length-DH,s=n.slice(0,DH),c=uH(s.map(e=>e.costUsd));return(0,G.jsxs)(`section`,{"aria-label":e,className:pH.section,children:[(0,G.jsx)(`h3`,{className:pH.heading,children:e}),(0,G.jsxs)(`table`,{className:pH.table,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{scope:`col`,children:t}),(0,G.jsx)(`th`,{className:pH.number,scope:`col`,children:`Cost`}),(0,G.jsx)(`th`,{className:pH.number,scope:`col`,children:`Share`}),(0,G.jsx)(`th`,{className:pH.number,scope:`col`,children:`Sessions`}),(0,G.jsx)(`th`,{className:pH.number,scope:`col`,children:`From cache`})]})}),(0,G.jsx)(`tbody`,{children:s.map(e=>(0,G.jsxs)(`tr`,{children:[(0,G.jsxs)(`th`,{className:pH.name,scope:`row`,title:e.key,children:[i?.(e.key)??e.key,i===void 0?null:(0,G.jsx)(`span`,{className:pH.path,children:e.key})]}),(0,G.jsx)(`td`,{className:pH.number,children:c(e.costUsd)}),(0,G.jsx)(`td`,{className:pH.number,children:fH(r===0?0:e.costUsd/r)}),(0,G.jsx)(`td`,{className:pH.number,children:e.sessions}),(0,G.jsx)(`td`,{className:pH.number,children:fH(e.cacheHitRate)})]},e.key))})]}),o>0?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`p`,{className:pH.note,children:[`And `,o,` more that cost less. This lists them all:`]}),(0,G.jsx)(YS,{command:a})]}):null]})},kH=({error:e,command:t,retry:n})=>(0,G.jsxs)(`div`,{className:pH.section,children:[(0,G.jsxs)(`p`,{className:pH.refused,role:`alert`,children:[`Cannot read usage: `,(0,G.jsx)(Wg,{text:e})]}),(0,G.jsx)(`div`,{className:pH.retry,children:(0,G.jsx)(q,{onClick:n,children:`Try again`})}),(0,G.jsx)(`p`,{className:pH.note,children:`On a terminal, the same report:`}),(0,G.jsx)(YS,{command:t})]}),AH=({period:e,limits:t})=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(EH,{limits:t}),(0,G.jsx)(CC,{cli:`ork run <workflow>`,title:QV(e)?`Nothing spent yet.`:`Nothing spent in this period.`,children:`Claude sessions show here once they finish. Start one with Run workflow, or in a terminal:`})]}),jH=({report:e})=>{let{totals:t}=e,n=t.inputTokens+t.cacheReadTokens+t.cacheWriteTokens,r=[[`Spend`,lH(t.costUsd)],[`Runs with sessions`,String(t.runs)],[`Sessions`,String(t.sessions)],[`Tokens in`,dH(n)],[`Tokens out`,dH(t.outputTokens)],[`From cache`,fH(t.cacheHitRate)]];return(0,G.jsx)(`dl`,{className:pH.totals,children:r.map(([e,t])=>(0,G.jsxs)(`div`,{className:pH.total,children:[(0,G.jsx)(`dt`,{children:e}),(0,G.jsx)(`dd`,{children:t})]},e))})},MH=({report:e,since:t,now:n,period:r,everyProject:i,projectName:a})=>{let o=(0,V.useMemo)(()=>cH(e,t,n),[e,t,n]),s=e.totals.costUsd,c=e=>eH(i,r,e);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(EH,{limits:e.limits}),(0,G.jsxs)(`div`,{className:pH.overview,children:[(0,G.jsx)(jH,{report:e}),e.hints.length===0?null:(0,G.jsxs)(`section`,{"aria-label":`Worth a look`,className:pH.hintsSection,children:[(0,G.jsx)(`h3`,{className:pH.heading,children:`Worth a look`}),(0,G.jsx)(`ul`,{className:pH.hints,children:e.hints.map(e=>(0,G.jsx)(`li`,{children:(0,G.jsx)(Wg,{text:e.message})},e.code))})]}),(0,G.jsx)(`div`,{className:pH.chartArea,children:(0,G.jsx)(SH,{series:o})})]}),(0,G.jsxs)(`div`,{className:pH.breakdowns,children:[i?(0,G.jsx)(OH,{groups:e.groups.project,label:`Project`,moreCommand:c(`project`),nameOf:a,title:`By project`,total:s}):null,(0,G.jsx)(OH,{groups:e.groups.workflow,label:`Workflow`,moreCommand:c(`workflow`),title:`By workflow`,total:s}),(0,G.jsx)(OH,{groups:e.groups.model,label:`Model`,moreCommand:c(`model`),title:`By model`,total:s}),(0,G.jsx)(OH,{groups:e.groups.node,label:`Node`,moreCommand:c(`node`),title:`Costliest nodes`,total:s})]}),(0,G.jsx)(`p`,{className:pH.note,children:`Costs are Claude Code's own estimates. On a subscription they are not what you are billed. On a terminal:`}),(0,G.jsx)(YS,{command:c()})]})},NH=()=>{let e=qy(),t=ab(e.usage.state),n=ab(e.runs),r=ab(e.projects.state),i=ab(e.usageFilter),{project:a,period:o}=i,[s,c]=(0,V.useState)(0),l=kz(t),u=(0,V.useRef)(null),d=ib(e.runs,e=>e?.filter(e=>e.live!==`running`&&e.live!==`paused`).length??0);(0,V.useEffect)(()=>{e.projects.load()},[e]),(0,V.useEffect)(()=>{let t=Date.now(),n=$V(o,t);e.usage.load({now:t,period:o,query:{...a===`all`?{}:{project:a},...n===void 0?{}:{since:n}}})},[e,a,o,d,s]);let f=(0,V.useMemo)(()=>Oz(r.status===`ready`?r.data:[],n??[]),[r,n]),p=a===`all`;return(0,G.jsxs)(`div`,{className:pH.panel,children:[(0,G.jsxs)(`div`,{className:pH.tools,children:[(0,G.jsx)(`div`,{className:pH.projectFilter,children:(0,G.jsx)(Bw,{label:`Project`,onChange:t=>{e.usageFilter.setValue({...i,project:t})},options:f,value:a})}),(0,G.jsx)(Bw,{label:`Period`,onChange:t=>{e.usageFilter.setValue({...i,period:t})},options:ZV,value:o})]}),(0,G.jsxs)(`section`,{"aria-busy":t.status===`loading`,"aria-label":`Usage report`,className:pH.body,ref:u,tabIndex:0,children:[t.status===`failed`?(0,G.jsx)(kH,{command:eH(p,o),error:t.error,retry:()=>{u.current?.focus(),c(s+1)}}):null,l===void 0?t.status===`failed`?null:(0,G.jsx)(`p`,{className:pH.note,children:`Reading usage…`}):l.data.totals.sessions===0?(0,G.jsx)(AH,{limits:l.data.limits,period:l.arg.period}):(0,G.jsx)(MH,{everyProject:l.arg.query.project===void 0,now:l.arg.now,period:l.arg.period,projectName:e=>f.find(t=>t.value===e)?.label??Ez(e),report:l.data,since:l.arg.query.since})]})]})},PH=(e,t)=>`${String(e)} ${t}${e===1?``:t.endsWith(`h`)?`es`:`s`}`,FH=e=>({worktrees:e.filter(e=>e.path!==null).length,branches:e.filter(e=>e.path===null).length}),IH=e=>{let{worktrees:t,branches:n}=FH(e);return[...t>0||n===0?[PH(t,`worktree`)]:[],...n>0?[PH(n,`branch`)]:[]].join(` · `)},LH=(e,t)=>{let n=e.flatMap(e=>e.items),{worktrees:r,branches:i}=FH(n),a=t??PH(e.filter(e=>e.items.length>0).length,`project`);return n.length===0?`No Ork worktrees or branches in ${a}.`:`${[...r>0?[PH(r,`worktree`)]:[],...i>0?[PH(i,`branch`)]:[]].join(` and `)} in ${a}.`},RH=(e,t,n)=>e===null?n?`the worktrees couldn't be read`:`reading worktrees`:e.some(e=>e.items.some(e=>e.state===`merged`))?null:t?`nothing merged into the current branch`:`nothing merged in these projects`,zH=e=>[e.root,...e.error===void 0?[e.head===null?`detached HEAD`:`current branch ${e.head}`]:[],...e.items.length===0?[]:[IH(e.items)]],BH=e=>[{text:`run ${e.runId}`,risk:!1},{text:e.nodeId,risk:!1},...e.path===null?[]:[{text:e.path,risk:!1}],...e.parts,...e.cleanKeeps===void 0?[]:[{text:`clean keeps it: ${e.cleanKeeps}`,risk:!1}]],VH=e=>e.run.known?`Open run ${e.runId} at ${e.nodeId}`:`Open run ${e.runId}: it isn't in Ork's records`,HH=e=>{let t=`${e.remove.label.replace(`…`,``)} ${e.label}…`;return e.remove.refusal===void 0?t:`${t}: ${e.remove.refusal}`},UH=(e,t,n,r)=>`cd ${sT(e)} && ork worktrees remove ${sT(t)}${n?` --branch`:``}${r?` --force`:``}`,WH=e=>e.path===null?`branch`:e.state===`detached`||e.branch===void 0?`detached`:`worktree`,GH=e=>({branch:`Delete branch \`${e.label}\``,detached:`Remove the worktree of \`${e.label}\``,worktree:`Remove \`${e.label}\``})[WH(e)],KH=(e,t)=>{let n=WH(e),r=n===`branch`?`It has no worktree. Deletes the branch from \`${t}\`.`:n===`detached`?`Removes the detached worktree. It has no branch of Ork's.`:e.missing?`Its folder is gone. Removing it drops git's record of the worktree. The branch stays unless you delete it too.`:`Removes its worktree. The branch stays unless you delete it too.`;return e.checkedOut===void 0?r:`${r} It's on \`${e.checkedOut}\`, the workflow's own branch, which Ork never deletes; removing the worktree loses nothing committed.`},qH=(e,t)=>e.merged?`It's merged into \`${t}\`.`:`It has ${PH(e.ahead,`commit`)} not merged into \`${t}\`; deleting it loses them.`,JH=e=>e.force?`Continue…`:e.removeWorktree&&e.deleteBranch?`Remove worktree and branch`:e.deleteBranch?`Delete branch`:e.prunes?`Prune`:`Remove worktree`,YH=e=>{if(!e.force)return null;let{losing:t}=e;if(t.changes.length>0)return`It has uncommitted changes; the next step shows what's lost.`;let n=PH(t.commits.length+t.more.commits,`commit`);return t.commitsOn===`no branch`?`It holds ${n} on no branch; the next step shows them.`:`Deleting the branch loses ${n}; the next step shows them.`},XH=(e,t)=>t.removeWorktree&&t.deleteBranch?`Removed ${e.label}'s worktree and deleted its branch.`:t.deleteBranch?`Deleted branch ${e.label}.`:t.prunes?`Pruned ${e.label}'s missing worktree.`:`Removed ${e.label}'s worktree.`,ZH=e=>[...e.losing.changes.length>0?[`Uncommitted changes can't be recovered.`]:[],...e.losing.commits.length>0?[`Deleted commits stay only in git's reflog, until it expires.`]:[]].join(` `),QH=(e,t)=>`cd ${sT(e)} && ork worktrees clean${t?` --branches`:``}`,$H=`[data-worktree-row]`,eU=(e,t)=>[...e?.querySelectorAll($H)??[]].findIndex(e=>e.dataset.worktreeRow===t),tU=(e,t)=>{let n=qy(),r=(0,V.use)(ZM),[i,a]=(0,V.useState)(null),[o,s]=(0,V.useState)(!1),[c,l]=(0,V.useState)(new Set),u=(0,V.useRef)(`back`),d=(0,V.useRef)(null),f=(0,V.useRef)(0),p=(0,V.useMemo)(()=>({openRun:e=>{NV(n,r,e.runId,e.nodeId)},remove:(t,n)=>{u.current=`back`,a({kind:`remove`,row:t,project:n,target:{project:n.root,key:t.key},index:eU(e.current,t.key),id:f.current+1}),f.current+=1,s(!0)}}),[n,r,e]),m=t=>{let n=e.current?.querySelectorAll($H)??[];return n[Math.min(t,n.length-1)]?.querySelector(`[data-act="remove"]`)??e.current?.querySelector(`[data-empty-title]`)??e.current??!1};return{opened:i,open:o,gone:c,rowActs:p,cleanButton:d,openClean:()=>{f.current+=1,a({kind:`clean`,id:f.current}),s(!0)},close:()=>{s(!1)},removed:(e,n,i,a)=>{r?.announce(XH(e,i)),u.current=a,l(t=>new Set([...t,`${n.root}|${e.key}`])),s(!1),t().finally(()=>{l(new Set)})},removeFocus:()=>typeof u.current==`number`?m(u.current):u.current===`back`,cleanClosed:e=>{e||r?.announce(`Nothing was removed.`),s(!1)},cleanFocus:()=>d.current??!0,openRemovedRun:e=>{u.current=`run`,s(!1),NV(n,r,e.runId,e.nodeId)}}},nU=(e,t)=>t===`all`?[...e]:e.filter(e=>e.root===t),rU=(e,t)=>({...e,name:t}),iU=()=>{let e=qy(),t=(0,V.use)(ZM),n=ab(e.worktrees.state),r=ab(e.worktreesFilter),i=ab(e.runs),a=ab(e.projects.state),o=(0,V.useRef)(0),s=(0,V.useRef)(null),c=(0,V.useRef)(null),l=(0,V.useRef)(i),u=(0,V.useCallback)(()=>{if(s.current!==null)return s.current;o.current=Date.now();let t=e.worktrees.load().finally(()=>{s.current=null});return s.current=t,t},[e]);(0,V.useEffect)(()=>(u(),e.projects.state.getValue().status===`idle`&&e.projects.load(),()=>{c.current!==null&&clearTimeout(c.current),c.current=null}),[u,e]),(0,V.useEffect)(()=>{if(l.current===i||(l.current=i,c.current!==null))return;let e=Math.max(0,o.current+FV-Date.now());c.current=setTimeout(()=>{c.current=null,u()},e)},[i,u]);let d=kz(n)?.data.projects??null,f=Oz(kz(a)?.data??[],[...i??[],...(d??[]).map(e=>({project:e.root}))]),p=e=>f.find(t=>t.value===e)?.label??e,m=(d??[]).map(e=>rU(e,p(e.root))),h=f.flatMap(e=>m.filter(t=>t.root===e.value)),g=d===null?null:nU(h,r);return{read:n,all:d===null?null:h,shown:g,filter:r,options:f,load:u,setFilter:n=>{e.worktreesFilter.setValue(n);let r=n===`all`?null:p(n);t?.announce(LH(nU(h,n),r))}}},aU={panel:`_panel_jg5qy_10`,tools:`_tools_jg5qy_31`,card:`_card_jg5qy_32`,toolsEnd:`_toolsEnd_jg5qy_56`,count:`_count_jg5qy_66`,head:`_head_jg5qy_76`,name:`_name_jg5qy_85`,headMeta:`_headMeta_jg5qy_94`,list:`_list_jg5qy_106`,row:`_row_jg5qy_112`,rowName:`_rowName_jg5qy_143`,badge:`_badge_jg5qy_155`,meta:`_meta_jg5qy_159`,risk:`_risk_jg5qy_177`,actions:`_actions_jg5qy_185`,note:`_note_jg5qy_195`,message:`_message_jg5qy_196`,alert:`_alert_jg5qy_205`,alertIcon:`_alertIcon_jg5qy_218`,facts:`_facts_jg5qy_225`,factName:`_factName_jg5qy_239`,caption:`_caption_jg5qy_240`,factValue:`_factValue_jg5qy_261`,step:`_step_jg5qy_277`,reason:`_reason_jg5qy_287`,section:`_section_jg5qy_293`,title:`_title_jg5qy_303`,result:`_result_jg5qy_312`,resultLine:`_resultLine_jg5qy_323`,foot:`_foot_jg5qy_335`},oU={ArrowDown:e=>e+1,ArrowUp:e=>e-1,Home:()=>0,End:(e,t)=>t},sU=e=>{let t=oU[e.key],{target:n}=e;if(t===void 0||!(n instanceof HTMLElement))return;let r=n.dataset.act;if(r===void 0)return;let i=[...e.currentTarget.querySelectorAll(`[data-worktree-row] [data-act="${r}"]`)],a=i.length-1,o=i[Math.max(0,Math.min(a,t(i.indexOf(n),a)))];o!==void 0&&(e.preventDefault(),o.focus())},cU=(0,V.memo)(({row:e,project:t,acts:n})=>{let r=(0,V.useId)(),i=(0,V.useId)(),a=UH(t.root,e.key,e.path===null,!1),o=BH(e),{refusal:s}=e.remove;return(0,G.jsxs)(`li`,{className:aU.row,"data-worktree-row":e.key,children:[(0,G.jsxs)(`p`,{className:aU.rowName,children:[e.label,(0,G.jsx)(zw,{children:`, `})]}),(0,G.jsx)(`span`,{className:aU.badge,children:(0,G.jsx)(wD,{state:e.state})}),(0,G.jsx)(`p`,{className:aU.meta,id:r,children:o.map((e,t)=>(0,G.jsxs)(`span`,{className:e.risk?aU.risk:void 0,children:[e.text,t<o.length-1?` ·`:``]},t))}),(0,G.jsx)(`span`,{hidden:!0,id:i,children:`CLI: ${a}`}),(0,G.jsxs)(`div`,{className:aU.actions,children:[(0,G.jsx)(q,{"aria-label":VH(e),"data-act":`open`,disabled:!e.run.known,focusableWhenDisabled:!0,onClick:()=>{n.openRun(e)},tip:e.run.known?void 0:`It isn't in Ork's records.`,variant:`ghost`,children:`Open run`}),(0,G.jsx)(q,{"aria-describedby":`${r} ${i}`,"aria-label":HH(e),cli:a,"data-act":`remove`,disabled:s!==void 0,focusableWhenDisabled:!0,onClick:()=>{n.remove(e,t)},tip:s===void 0?void 0:`${s[0]?.toUpperCase()??``}${s.slice(1)}.`,children:e.remove.label})]})]})},(e,t)=>e.acts===t.acts&&e.project.root===t.project.root&&e.project.head===t.project.head&&JSON.stringify(e.row)===JSON.stringify(t.row)),lU=({project:e,acts:t})=>{let n=(0,V.useId)();return(0,G.jsxs)(`section`,{"aria-labelledby":n,className:aU.card,children:[(0,G.jsxs)(`div`,{className:aU.head,children:[(0,G.jsx)(`h3`,{className:aU.name,id:n,children:e.name}),(0,G.jsx)(`p`,{className:aU.headMeta,children:zH(e).join(` · `)})]}),e.error===void 0?(0,G.jsx)(`ul`,{"aria-label":`Worktrees in ${e.name}`,className:aU.list,children:e.items.map(n=>(0,G.jsx)(cU,{acts:t,project:e,row:n},n.key))}):(0,G.jsxs)(`p`,{className:aU.alert,children:[(0,G.jsx)(`span`,{className:aU.alertIcon,children:(0,G.jsx)(cD,{})}),(0,G.jsx)(`span`,{children:(0,G.jsx)(Wg,{text:`Could not read ${e.name}'s worktrees: ${e.error}`})})]}),e.fix===void 0?null:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:aU.note,children:`If it moved, this points Ork at its new place:`}),(0,G.jsx)(YS,{command:e.fix})]})]})},uU=e=>e.filter(e=>e.steps.length>0),dU=e=>({worktrees:e.filter(e=>e.removeWorktree||e.prunes).length,branches:e.filter(e=>e.deleteBranch).length}),fU=e=>e.removeWorktree||e.deleteBranch||e.prunes,pU=e=>e.skip??`no worktree, branch kept`,mU=e=>{let[t]=e;return e.length===1&&t!==void 0?`Clean merged worktrees in ${t.name}`:`Clean merged worktrees in ${PH(e.length,`project`)}`},hU=e=>`Removes the worktrees of branches merged into ${e?`the project's current branch`:`each project's current branch`}, as the command below does. One with uncommitted changes, or checked out in the main checkout, is kept. Nothing is forced.`,gU=e=>{let{worktrees:t,branches:n}=dU(e),r=[...t>0?[`removes ${PH(t,`worktree`)}`]:[],...n>0?[`deletes ${PH(n,`branch`)}`]:[]].join(` and `),i=e.filter(e=>!fU(e)||e.skip!==void 0),a=new Map;for(let e of i)a.set(pU(e),(a.get(pU(e))??0)+1);let o=i.length===0?``:`Keeps ${String(i.length)}: ${[...a].map(([e,t])=>`${e} (${String(t)})`).join(`; `)}.`;return[r===``?`Nothing to clean.`:`${r.charAt(0).toUpperCase()}${r.slice(1)}.`,o].filter(e=>e!==``).join(` `)},_U=e=>{let{worktrees:t,branches:n}=dU(e.flatMap(e=>e.steps));return t===0&&n===0?null:t===0?`Delete ${PH(n,`branch`)}`:n===0?`Remove ${PH(t,`worktree`)}`:`Remove ${PH(t,`worktree`)} and ${PH(n,`branch`)}`},vU=e=>e.some(e=>e.error!==void 0)?`Cleaned in part`:`Cleaned`,yU={well:`_well_18f8h_7`},bU=({label:e,reading:t,describedBy:n,ref:r,steady:i=!1,short:a=!1,children:o})=>(0,G.jsx)(`section`,{"aria-busy":t!==void 0,"aria-describedby":n,"aria-label":e,className:yU.well,"data-short":a?``:void 0,"data-steady":i?``:void 0,ref:r,tabIndex:0,children:t===void 0?o:(0,G.jsx)(Wg,{text:t})}),xU=`Reading the plan…`,SU=`Nothing to show: the plan couldn't be read.`,CU=({reading:e,failed:t,well:n})=>(0,G.jsx)(bU,{label:`Plan`,reading:e?xU:void 0,ref:n,steady:!0,children:t?SU:`Nothing to clean.`}),wU=({checked:e,disabled:t,onChange:n})=>{let r=(0,V.useId)();return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(qC,{checked:e,describedBy:r,disabled:t,label:`Also delete the merged branches`,onChange:n}),(0,G.jsx)(`p`,{className:aU.note,id:r,children:`Only branches merged into the current branch, which git deletes without losing a commit.`})]})},TU=({project:e,branches:t,reading:n,failed:r,well:i})=>{let a=(0,V.useId)(),o=e.head??`its detached HEAD`;return(0,G.jsxs)(`section`,{"aria-label":e.name,className:aU.section,children:[(0,G.jsx)(`h3`,{className:aU.name,children:e.name}),(0,G.jsx)(`p`,{className:aU.headMeta,children:(0,G.jsx)(Wg,{text:`\`${e.root}\` · into \`${o}\``})}),(0,G.jsx)(`p`,{className:aU.message,id:a,children:n||r?``:gU(e.steps)}),(0,G.jsx)(`p`,{className:aU.caption,children:`Plan`}),(0,G.jsxs)(bU,{describedBy:a,label:`Plan for ${e.name}`,reading:n?xU:void 0,ref:i,steady:!0,children:[r?SU:null,e.steps.map(e=>(0,G.jsxs)(`span`,{children:[e.line.text,e.line.reason===void 0?null:(0,G.jsx)(`span`,{className:aU.reason,children:` (${e.line.reason})`}),`
71
+ `]},e.key))]}),(0,G.jsx)(`p`,{className:aU.note,children:(0,G.jsx)(Wg,{text:`In \`${e.root}\`:`})}),(0,G.jsx)(YS,{command:QH(e.root,t)})]})},EU=({lines:e})=>(0,G.jsx)(`ul`,{className:aU.result,children:e.map(e=>(0,G.jsxs)(`li`,{className:aU.resultLine,children:[(0,G.jsx)(aD,{}),e]},e))}),DU=({results:e})=>{let t=(0,V.useRef)(null);return(0,V.useEffect)(()=>{t.current?.focus()},[]),(0,G.jsxs)(`div`,{className:aU.step,children:[(0,G.jsx)(`h3`,{className:aU.title,ref:t,tabIndex:-1,children:vU(e)}),e.filter(e=>e.done.length>0||e.error!==void 0).map(e=>(0,G.jsxs)(`section`,{"aria-label":e.name,className:aU.section,children:[(0,G.jsx)(`h4`,{className:aU.name,children:e.name}),e.error===void 0?null:(0,G.jsxs)(`p`,{className:aU.alert,children:[(0,G.jsx)(`span`,{className:aU.alertIcon,children:(0,G.jsx)(cD,{})}),(0,G.jsx)(`span`,{children:(0,G.jsx)(Wg,{text:`Stopped in ${e.name}: ${e.error}`})})]}),e.error===void 0||e.done.length===0?null:(0,G.jsx)(`p`,{className:aU.note,children:`Done before it stopped:`}),(0,G.jsx)(EU,{lines:e.done})]},e.root))]})},OU=e=>{if(e.step!==`done`)return`plan`in e?e.plan:e.shown},kU=(e,t,n)=>{let[r,i]=(0,V.useState)(!1),[a,o]=(0,V.useState)({step:`reading`}),s=(0,V.useRef)(0),c=(0,V.useCallback)(async n=>{s.current+=1;let r=s.current,i=await e.call(`worktreesCleanPlan`,{body:{...t===void 0?{}:{project:t},branches:n}});return r===s.current?i:null},[e,t]),l=(0,V.useCallback)(async(n,r)=>{s.current+=1;let i=s.current,a=await e.call(`worktreesCleanPlan`,{body:{...t===void 0?{}:{project:t},branches:n}});i===s.current&&o(a.ok?{step:`plan`,plan:a.data,changed:!1}:{step:`readFailed`,error:a.error,...r===void 0?{}:{shown:r}})},[e,t]);(0,V.useEffect)(()=>{l(!1)},[l]);let u=(e,t)=>{o(t===void 0?{step:`reading`}:{step:`reading`,shown:t}),l(e,t)},d=async i=>{o({step:`cleaning`,plan:i});let a=await e.call(`worktreesClean`,{body:{...t===void 0?{}:{project:t},branches:r,digest:i.digest}});if(a.ok){o({step:`done`,results:a.data.projects}),n();return}if(a.status!==409){o({step:`cleanFailed`,plan:i,error:a.error});return}let s=await c(r);s!==null&&(s.ok&&s.data.digest!==i.digest?o({step:`plan`,plan:s.data,changed:!0}):o({step:`cleanFailed`,plan:i,error:a.error}))};return{step:a,branches:r,setBranches:e=>{i(e),u(e,OU(a))},clean:()=>{a.step===`plan`&&d(a.plan)},tryAgain:()=>{a.step===`cleanFailed`?d(a.plan):u(r,OU(a))}}},AU=e=>e.step===`readFailed`?`Could not read the plan: ${e.error}`:e.step===`cleanFailed`?`Could not clean: ${e.error}`:null,jU=e=>e.step===`reading`?`Reading the plan…`:e.step===`readFailed`?`The plan couldn't be read; Try again reads it.`:null,MU=e=>{let t=kU(e.client,e.project,e.onCleaned),{step:n}=t,r=(0,V.useRef)(null),i=(0,V.useId)(),a=(0,V.useId)(),o=n.step===`cleaning`,s=n.step===`reading`,c=OU(n),l=c===void 0?e.scope:uU(c.projects),u=_U(l),d=n.step===`plan`&&n.changed,f=c!==void 0&&!s&&u===null,p=n.step===`readFailed`&&c===void 0;(0,V.useEffect)(()=>{d&&r.current?.focus()},[d]),(0,V.useEffect)(()=>{if(s)return;let e=document.activeElement;(e===null||e===document.body||e.getAttribute(`role`)===`dialog`)&&r.current?.focus()},[s]);let m=()=>{o||e.onClose(n.step===`done`)};return(0,G.jsx)(bC,{description:hU(e.project!==void 0),finalFocus:e.finalFocus,initialFocus:r,onOpenChange:e=>{e||m()},open:e.open,size:`wide`,title:mU(l.length===0?e.scope:l),children:n.step===`done`?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(DU,{results:n.results}),(0,G.jsx)(xC,{children:(0,G.jsx)(q,{onClick:m,children:`Close`})})]}):(0,G.jsxs)(G.Fragment,{children:[d?(0,G.jsx)(`p`,{role:`alert`,children:`The plan changed since you read it. Read it again before cleaning.`}):null,l.length===0?(0,G.jsx)(CU,{failed:p,reading:s,well:r}):null,l.map((e,n)=>(0,G.jsx)(TU,{branches:t.branches,failed:p,project:e,reading:s,well:n===0?r:void 0},e.root)),(0,G.jsx)(wU,{checked:t.branches,disabled:o,onChange:t.setBranches}),(0,G.jsx)(XB,{id:a,onTryAgain:t.tryAgain,takeFocus:n.step===`cleanFailed`?`always`:`ifLost`,words:AU(n)}),(0,G.jsx)($L,{id:i,why:jU(n)}),(0,G.jsxs)(xC,{children:[(0,G.jsx)(q,{disabled:o,focusableWhenDisabled:!0,onClick:m,variant:`ghost`,children:f?`Close`:`Cancel`}),f?null:(0,G.jsx)(q,{"aria-describedby":`${i} ${a}`,disabled:n.step!==`plan`,focusableWhenDisabled:!0,onClick:t.clean,variant:`primary`,children:o?`Removing…`:u??`Remove worktrees`})]})]})})},NU=(e,t,n)=>{let r=t?.parts.map(e=>e.text)??e.parts.map(e=>e.text.replace(/ not merged$/u,` not merged into ${n}`)),i=t?.merged??e.merged;return r.join(` · `)||(i?`merged into ${n}`:``)},PU=`Nothing to show: its state couldn't be read.`,FU=({name:e,children:t})=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`dt`,{className:aU.factName,children:e}),(0,G.jsx)(`dd`,{className:aU.factValue,children:t})]}),IU=({plan:e,label:t,reading:n})=>(0,G.jsx)(bU,{label:t,reading:n,steady:!0,children:e===void 0?PU:(0,G.jsxs)(G.Fragment,{children:[e.line.text,e.line.reason===void 0?null:(0,G.jsx)(`span`,{className:aU.reason,children:` (${e.line.reason})`})]})}),LU=e=>{let{row:t,project:n,plan:r}=e,i=(0,V.useId)(),a=n.head??`the current branch`;return(0,G.jsxs)(`div`,{className:aU.step,children:[(0,G.jsxs)(`dl`,{className:aU.facts,children:[(0,G.jsx)(FU,{name:`Project`,children:`${n.name} ${n.root}`}),(0,G.jsxs)(FU,{name:`Run`,children:[`${t.runId} · ${t.nodeId}`,(0,G.jsx)(q,{"aria-label":VH(t),disabled:!t.run.known||e.busy,focusableWhenDisabled:!0,onClick:e.onOpenRun,tip:t.run.known?void 0:`It isn't in Ork's records.`,variant:`ghost`,children:`Open run`})]}),t.path===null?null:(0,G.jsx)(FU,{name:`Path`,children:t.path}),(0,G.jsx)(FU,{name:`State`,children:NU(t,r,a)})]}),WH(t)===`worktree`&&t.branch!==void 0?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(qC,{checked:e.deleteBranch,describedBy:i,disabled:e.busy,label:`Also delete the branch ${t.branch}`,onChange:e.onDeleteBranch}),(0,G.jsx)(`p`,{className:aU.note,id:i,children:(0,G.jsx)(Wg,{text:qH(r??t,a)})})]}):null,(0,G.jsx)(`p`,{className:aU.caption,children:`Plan`}),(0,G.jsx)(IU,{label:`Plan`,plan:r,reading:e.reading?`Reading its state…`:void 0}),(0,G.jsx)(YS,{command:UH(n.root,t.key,r?.deleteBranch??e.deleteBranch,r?.force??!1)})]})},RU=({title:e,label:t,lines:n,more:r})=>(0,G.jsxs)(`div`,{className:aU.section,children:[(0,G.jsx)(`p`,{className:aU.caption,children:(0,G.jsx)(Wg,{text:`${e} · ${String(n.length+r)}`})}),(0,G.jsx)(bU,{label:t,short:!0,children:n.join(`
72
+ `)}),r>0?(0,G.jsx)(`p`,{className:aU.note,children:`and ${String(r)} more`}):null]}),zU=({row:e,plan:t,head:n,root:r})=>{let i=(0,V.useRef)(null);(0,V.useEffect)(()=>{i.current?.focus()},[]);let{losing:a}=t,o=`Commits not merged into ${n}`;return(0,G.jsxs)(`div`,{className:aU.step,children:[(0,G.jsx)(`h3`,{className:aU.title,ref:i,tabIndex:-1,children:`What's lost`}),a.changes.length===0?null:(0,G.jsx)(RU,{label:`Uncommitted changes`,lines:a.changes,more:a.more.changes,title:`Uncommitted changes`}),a.commits.length===0?null:(0,G.jsx)(RU,{label:a.commitsOn===`no branch`?`Commits on no branch`:o,lines:a.commits,more:a.more.commits,title:a.commitsOn===`no branch`?`Commits on no branch`:`Commits not merged into \`${n}\``}),(0,G.jsx)(`p`,{className:aU.note,children:ZH(t)}),(0,G.jsx)(YS,{command:UH(r,e.key,t.deleteBranch,!0)})]})},BU=e=>`plan`in e?e.plan:e.shown,VU=e=>e.step===`lost`||(e.step===`removing`||e.step===`removeFailed`)&&e.from===`lost`,HU=(e,t,n)=>{let[r,i]=(0,V.useState)(!1),[a,o]=(0,V.useState)({step:`reading`}),s=(0,V.useRef)(0),c=(0,V.useCallback)(async n=>{s.current+=1;let r=s.current,i=await e.call(`worktreeRemovePlan`,{body:{...t,deleteBranch:n}});return r===s.current?i:null},[e,t]),l=(0,V.useCallback)(async(n,r)=>{s.current+=1;let i=s.current,a=await e.call(`worktreeRemovePlan`,{body:{...t,deleteBranch:n}});i===s.current&&o(a.ok?{step:`choice`,plan:a.data,changed:!1}:{step:`readFailed`,error:a.error,...r===void 0?{}:{shown:r}})},[e,t]);(0,V.useEffect)(()=>{l(!1)},[l]);let u=(e,t)=>{o(t===void 0?{step:`reading`}:{step:`reading`,shown:t}),l(e,t)},d=async(i,a)=>{o({step:`removing`,plan:i,from:a});let s=await e.call(`worktreeRemove`,{body:{...t,deleteBranch:r,force:i.force,digest:i.digest}});if(s.ok){n(i);return}if(s.status!==409){o({step:`removeFailed`,plan:i,from:a,error:s.error});return}let l=await c(r);l!==null&&(l.ok&&l.data.digest!==i.digest?o({step:`choice`,plan:l.data,changed:!0}):o({step:`removeFailed`,plan:i,from:a,error:s.error}))};return{step:a,deleteBranch:r,setDeleteBranch:e=>{i(e),u(e,BU(a))},goOn:()=>{a.step===`choice`&&a.plan.force?o({step:`lost`,plan:a.plan}):a.step===`choice`&&d(a.plan,`choice`)},back:()=>{a.step===`lost`&&o({step:`choice`,plan:a.plan,changed:!1})},loseIt:()=>{a.step===`lost`&&d(a.plan,`lost`)},tryAgain:()=>{a.step===`removeFailed`?d(a.plan,a.from):u(r,BU(a))}}},UU=`It changed since you read it. Read it again before removing.`,WU=(e,t)=>e.step===`readFailed`?`Could not read its state: ${e.error}`:e.step===`removeFailed`?`Could not remove ${t}: ${e.error}`:e.step===`choice`&&e.changed?UU:null,GU=e=>e.step===`reading`?`Reading its state…`:e.step===`readFailed`?`Its state couldn't be read; Try again reads it.`:e.step===`choice`?YH(e.plan):null,KU=({client:e,row:t,project:n,target:r,cancel:i,onBusy:a,onRemoved:o,onOpenRun:s,onClose:c})=>{let l=HU(e,r,o),{step:u}=l,d=(0,V.useId)(),f=(0,V.useId)(),p=(0,V.useRef)(null),m=u.step===`removing`,h=BU(u),g=VU(u),_=u.step===`choice`&&u.changed;(0,V.useEffect)(()=>{a(m)},[m,a]);let v=(0,V.useRef)(!1);(0,V.useEffect)(()=>{let e=v.current&&!g;v.current=g,(_||e)&&p.current?.focus()},[_,g]);let y=WU(u,t.label);return(0,G.jsxs)(G.Fragment,{children:[g&&h!==void 0?(0,G.jsx)(zU,{head:n.head??`the current branch`,plan:h,root:n.root,row:t}):(0,G.jsx)(LU,{busy:m,deleteBranch:l.deleteBranch,onDeleteBranch:l.setDeleteBranch,onOpenRun:s,plan:h,project:n,reading:u.step===`reading`,row:t}),(0,G.jsx)(XB,{id:f,onTryAgain:_?void 0:l.tryAgain,takeFocus:u.step===`removeFailed`?`always`:`ifLost`,words:y}),(0,G.jsx)($L,{id:d,why:GU(u)}),(0,G.jsxs)(`div`,{className:aU.foot,children:[g?(0,G.jsx)(q,{disabled:m,focusableWhenDisabled:!0,onClick:l.back,variant:`ghost`,children:`Back`}):null,(0,G.jsx)(q,{disabled:m,focusableWhenDisabled:!0,onClick:c,ref:i,variant:`ghost`,children:`Cancel`}),g?(0,G.jsx)(q,{"aria-describedby":f,disabled:u.step!==`lost`,focusableWhenDisabled:!0,onClick:l.loseIt,variant:`danger`,children:m?`Removing…`:`Remove and lose this work`}):(0,G.jsx)(q,{"aria-describedby":`${d} ${f}`,disabled:u.step!==`choice`,focusableWhenDisabled:!0,onClick:l.goOn,ref:p,variant:h?.force===!0?`default`:`primary`,children:m?`Removing…`:h===void 0?`Remove worktree`:JH(h)})]})]})},qU=({open:e,client:t,row:n,project:r,target:i,finalFocus:a,onRemoved:o,onOpenRun:s,onClose:c})=>{let l=(0,V.useRef)(null),u=(0,V.useRef)(!1),d=()=>{u.current||c()};return(0,G.jsx)(bC,{description:KH(n,r.root),finalFocus:a,initialFocus:l,onOpenChange:e=>{e||d()},open:e,size:`wide`,title:GH(n),children:(0,G.jsx)(KU,{cancel:l,client:t,onBusy:e=>{u.current=e},onClose:d,onOpenRun:s,onRemoved:o,project:r,row:n,target:i})})},JU=({acts:e,project:t,merged:n,load:r})=>{let{client:i}=qy(),{opened:a,open:o}=e;return a?.kind===`remove`?(0,G.jsx)(qU,{client:i,finalFocus:e.removeFocus,onClose:e.close,onOpenRun:()=>{e.openRemovedRun(a.row)},onRemoved:t=>{e.removed(a.row,a.project,t,a.index)},open:o,project:a.project,row:a.row,target:a.target},a.id):a?.kind===`clean`?(0,G.jsx)(MU,{client:i,finalFocus:e.cleanFocus,onCleaned:()=>void r(),onClose:e.cleanClosed,open:o,project:t,scope:n.map(({root:e,name:t,head:n})=>({root:e,name:t,head:n,steps:[]}))},a.id):null},YU=({filter:e,options:t,items:n,updating:r,cleanBlocked:i,cleanButton:a,onFilter:o,onClean:s,onReload:c})=>(0,G.jsxs)(`div`,{className:aU.tools,children:[(0,G.jsx)(Bw,{label:`Project`,onChange:o,options:t,value:e}),(0,G.jsxs)(`div`,{className:aU.toolsEnd,children:[n===null?null:(0,G.jsx)(`span`,{className:aU.count,children:IH(n)}),(0,G.jsx)(`output`,{className:aU.count,children:r?`Updating…`:``}),(0,G.jsx)(q,{"aria-label":i===null?void 0:`Clean merged…: ${i}`,cli:`ork worktrees clean`,disabled:i!==null,focusableWhenDisabled:!0,onClick:s,ref:a,tip:i===null?void 0:`Clean merged…: ${i}`,children:`Clean merged…`}),(0,G.jsx)(q,{cli:`ork worktrees`,onClick:c,tip:`In the project's folder.`,variant:`ghost`,children:`Reload`})]})]}),XU=({error:e})=>(0,G.jsxs)(`p`,{className:aU.alert,role:`alert`,children:[(0,G.jsx)(`span`,{className:aU.alertIcon,children:(0,G.jsx)(yy,{})}),(0,G.jsx)(`span`,{children:(0,G.jsx)(Wg,{text:`Could not read worktrees: ${e}`})})]}),ZU=({projects:e,one:t})=>e===0?(0,G.jsxs)(CC,{cli:`ork register <path>`,focusable:!0,title:`No projects registered yet.`,children:[(0,G.jsx)(`p`,{children:`In a repository:`}),(0,G.jsx)(YS,{command:`ork init`}),(0,G.jsx)(`p`,{children:`Or from outside it:`})]}):t===null?(0,G.jsx)(CC,{cli:`ork worktrees`,focusable:!0,title:`No Ork worktrees or branches.`,children:(0,G.jsx)(Wg,{text:"A run with `worktree` nodes leaves a worktree and an `ork/` branch for each; they wait here until you remove them. In a terminal, in a project's folder:"})}):(0,G.jsx)(CC,{focusable:!0,title:`No Ork worktrees or branches in ${t}.`,children:`Project: All projects shows every project's.`}),QU=(e,t)=>({...e,items:e.items.filter(n=>!t.has(`${e.root}|${n.key}`))}),$U={usage:{title:`Usage`,Icon:gy,Body:NH},context:{title:`Context`,Icon:vy,Body:xB},feedback:{title:`Feedback`,Icon:by,Body:YV},worktrees:{title:`Worktrees`,Icon:Cy,Body:()=>{let e=iU(),{read:t,shown:n,filter:r}=e,i=r===`all`?null:r,{panel:a,onFocus:o}=rL((n??[]).flatMap(e=>e.items.map(t=>`${e.root}|${t.key}`)).join(`
73
+ `),`[data-worktree-row]`),s=tU(a,e.load),c=(n??[]).map(e=>QU(e,s.gone)),l=c.filter(e=>e.items.length>0||e.error!==void 0),u=c.length-l.length,d=c.filter(e=>e.items.some(e=>e.state===`merged`));return(0,G.jsxs)(`div`,{"aria-label":`Worktrees`,className:aU.panel,onFocus:o,onKeyDown:sU,ref:a,role:`group`,tabIndex:-1,children:[(0,G.jsx)(YU,{cleanBlocked:RH(n===null?null:c,i!==null,t.status===`failed`),cleanButton:s.cleanButton,filter:r,items:n===null?null:c.flatMap(e=>e.items),onClean:s.openClean,onFilter:e.setFilter,onReload:()=>void e.load(),options:e.options,updating:t.status===`loading`&&n!==null}),t.status===`failed`?(0,G.jsx)(XU,{error:t.error}):null,n===null&&t.status!==`failed`?(0,G.jsx)(`p`,{className:aU.message,children:`Reading worktrees…`}):null,n!==null&&l.length===0?(0,G.jsx)(ZU,{one:i===null?null:c[0]?.name??i,projects:e.all?.length??0}):null,l.map(e=>(0,G.jsx)(lU,{acts:s.rowActs,project:e},e.root)),i===null&&l.length>0&&u>0?(0,G.jsx)(`p`,{className:aU.note,children:`Nothing left in ${PH(u,`other project`)}.`}):null,(0,G.jsx)(JU,{acts:s,load:e.load,merged:d,project:i??void 0})]})}}},eW={runs:{id:`runs`,title:`Runs`,Icon:uy,Body:Bz},monitor:{id:`monitor`,title:`Monitor`,Icon:dy,Body:fz},logs:{id:`logs`,title:`Logs`,Icon:fy,Body:jL},decisions:{id:`decisions`,title:`Decisions`,Icon:py,Body:iL},chats:{id:`chats`,title:`Chats`,Icon:my,Body:XM},notifications:{id:`notifications`,title:`Notifications`,Icon:hy,Body:Tz},usage:{id:`usage`,...$U.usage},builder:{id:`builder`,title:`Builder`,Icon:_y,Body:hM},context:{id:`context`,...$U.context},feedback:{id:`feedback`,...$U.feedback},worktrees:{id:`worktrees`,...$U.worktrees}},tW=Object.values(eW),nW=e=>e in eW,rW=e=>eW[e],iW=(e,t)=>e===void 0?void 0:yT(e,t).join(t?``:`+`),aW=(e,t)=>{if(e.wide&&!e.open.includes(t))return e.minimized.includes(t)?`minimized`:`closed`},oW=({workspace:e})=>{let t=ab(e.view),n=ET(),r=[...tW.map(({id:r,title:i},a)=>({label:i,detail:aW(t,r),hint:iW(TT(a+1),n),onSelect:()=>{e.goTo(r)}})),`separator`,{label:`Reset layout`,onSelect:()=>{e.resetLayout()}}];return(0,G.jsx)(AE,{entries:r,trigger:(0,G.jsxs)(q,{variant:`ghost`,children:[`Window`,(0,G.jsx)(Xv,{})]})})},sW=({workspace:e})=>(0,G.jsxs)(`header`,{className:kT.bar,children:[(0,G.jsxs)(`h1`,{className:kT.name,children:[(0,G.jsx)(`img`,{alt:`Ork`,className:kT.logoOnDark,src:`/ork-wordmark-small.svg`}),(0,G.jsx)(`img`,{alt:`Ork`,className:kT.logoOnLight,src:`/ork-wordmark-small-on-light.svg`})]}),(0,G.jsx)(oW,{workspace:e}),(0,G.jsx)(`div`,{className:kT.spacer}),(0,G.jsx)(AT,{workspace:e}),(0,G.jsxs)(q,{onClick:()=>{e.palette.setValue(!0)},variant:`ghost`,children:[(0,G.jsx)(ry,{}),`Commands`,(0,G.jsx)(Kg,{keys:yT(CT.palette,ET())})]})]}),cW,lW=class{constructor(){}},uW=class extends lW{constructor(e,t,n,r){super(),this.viewId=e,this.groupId=t,this.panelId=n,this.tabGroupId=r}},dW=class extends lW{constructor(e,t){super(),this.viewId=e,this.paneId=t}},fW=class e{constructor(){}static getInstance(){return e.INSTANCE}hasData(e){return e&&e===this.proto}clearData(e){this.hasData(e)&&(this.proto=void 0,this.data=void 0)}getData(e){if(this.hasData(e))return this.data}setData(e,t){t&&(this.data=e,this.proto=t)}};cW=fW,fW.INSTANCE=new cW;function pW(){let e=fW.getInstance();if(e.hasData(uW.prototype))return e.getData(uW.prototype)[0]}function mW(){let e=fW.getInstance();if(e.hasData(dW.prototype))return e.getData(dW.prototype)[0]}var hW;(function(e){e.NONE={dispose:()=>{}};function t(e){return{dispose:()=>{e()}}}e.from=t})(hW||={});var Y=class{get isDisposed(){return this._isDisposed}constructor(...e){this._isDisposed=!1,this._disposables=new Set(e)}addDisposables(...e){e.forEach(e=>this._disposables.add(e))}removeDisposable(e){this._disposables.delete(e)}dispose(){this._isDisposed||(this._isDisposed=!0,this._disposables.forEach(e=>e.dispose()),this._disposables.clear())}},gW=class{constructor(){this._disposable=hW.NONE}get value(){return this._disposable===hW.NONE?void 0:this._disposable}set value(e){this._disposable&&this._disposable.dispose(),this._disposable=e}dispose(){this._disposable&&=(this._disposable.dispose(),hW.NONE)}},_W;(function(e){e.map=(e,t)=>n=>e(e=>n(t(e))),e.any=(...e)=>t=>{let n=e.map(e=>e(t));return{dispose:()=>{n.forEach(e=>{e.dispose()})}}}})(_W||={});var vW=class{constructor(){this._defaultPrevented=!1}get defaultPrevented(){return this._defaultPrevented}preventDefault(){this._defaultPrevented=!0}},yW=class{constructor(){this._isAccepted=!1}get isAccepted(){return this._isAccepted}accept(){this._isAccepted=!0}},bW=class{constructor(){this.events=new Map}get size(){return this.events.size}add(e,t){this.events.set(e,t)}delete(e){this.events.delete(e)}clear(){this.events.clear()}},xW=class e{static create(){return new e(Error(`listener stacktrace`).stack??``)}constructor(e){this.value=e}print(){console.warn(`dockview: stacktrace`,this.value)}},SW=class{constructor(e,t){this.callback=e,this.stacktrace=t}},X=class e{static setLeakageMonitorEnabled(t){t!==e.ENABLE_TRACKING&&e.MEMORY_LEAK_WATCHER.clear(),e.ENABLE_TRACKING=t}get value(){return this._last}constructor(e){this.options=e,this._listeners=[],this._disposed=!1}get event(){return this._event||(this._event=t=>{this.options?.replay&&this._last!==void 0&&t(this._last);let n=new SW(t,e.ENABLE_TRACKING?xW.create():void 0);return this._listeners.push(n),{dispose:()=>{let t=this._listeners.indexOf(n);t>-1?this._listeners.splice(t,1):e.ENABLE_TRACKING}}},e.ENABLE_TRACKING&&e.MEMORY_LEAK_WATCHER.add(this._event,xW.create())),this._event}fire(e){if(this._pauseTokens!==void 0&&this._pauseTokens.size>0)return;this.options?.replay&&(this._last=e);let t=this._listeners,n=t.length;if(n!==0){if(n===1)t[0].callback(e);else for(let n of t.slice())n.callback(e)}}pause(){let e={};return this._pauseTokens??=new Set,this._pauseTokens.add(e),hW.from(()=>this._pauseTokens?.delete(e))}dispose(){this._disposed||(this._disposed=!0,this._listeners.length>0&&(e.ENABLE_TRACKING?queueMicrotask(()=>{for(let e of this._listeners)console.warn(`dockview: stacktrace`,e.stacktrace?.print());this._listeners=[]}):this._listeners=[]),e.ENABLE_TRACKING&&this._event&&e.MEMORY_LEAK_WATCHER.delete(this._event))}};X.ENABLE_TRACKING=!1,X.MEMORY_LEAK_WATCHER=new bW;function Z(e,t,n,r){return e.addEventListener(t,n,r),{dispose:()=>{e.removeEventListener(t,n,r)}}}var CW=class{constructor(){this._onFired=new X,this._currentFireCount=0,this._pending=new Set,this._queued=!1,this.onEvent=e=>{let t=this._currentFireCount;return this._onFired.event(n=>{this._currentFireCount>t&&e(n)})}}fire(e){this._currentFireCount++,this._pending.add(e),!this._queued&&(this._queued=!0,queueMicrotask(()=>{this._queued=!1;let e=this._pending;this._pending=new Set,this._onFired.fire(e)}))}dispose(){this._onFired.dispose()}},wW=class extends Y{constructor(e){super(),this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this._value=null,this.addDisposables(this._onDidChange,TW(e,e=>{let t=e.target.scrollWidth>e.target.clientWidth,n=e.target.scrollHeight>e.target.clientHeight;this._value={hasScrollX:t,hasScrollY:n},this._onDidChange.fire(this._value)}))}};function TW(e,t){let n=new Set,r=new ResizeObserver(e=>{let r=!1,i;i=requestAnimationFrame(()=>{r=!0,i!==void 0&&n.delete(i);let a=e[0];t(a)}),r||n.add(i)});return r.observe(e),{dispose:()=>{r.unobserve(e),r.disconnect();for(let e of n)cancelAnimationFrame(e);n.clear()}}}var EW=(e,...t)=>{for(let n of t)e.classList.contains(n)&&e.classList.remove(n)},DW=(e,...t)=>{for(let n of t)e.classList.contains(n)||e.classList.add(n)},Q=(e,t,n)=>{let r=e.classList.contains(t);n&&!r&&e.classList.add(t),!n&&r&&e.classList.remove(t)};function OW(e,t){for(;e;){if(e===t)return!0;e=e.parentNode}return!1}function kW(e){return new AW(e)}var AW=class extends Y{constructor(e){super(),this._onDidFocus=new X,this.onDidFocus=this._onDidFocus.event,this._onDidBlur=new X,this.onDidBlur=this._onDidBlur.event,this.addDisposables(this._onDidFocus,this._onDidBlur);let t=OW(eG(e),e),n=!1,r=()=>{n=!1,t||(t=!0,this._onDidFocus.fire())},i=()=>{t&&(n=!0,globalThis.setTimeout(()=>{n&&(n=!1,t=!1,this._onDidBlur.fire())},0))};this._refreshStateHandler=()=>{OW(eG(e),e)!==t&&(t?i():r())},this.addDisposables(Z(e,`focus`,r,!0)),this.addDisposables(Z(e,`blur`,i,!0))}refreshState(){this._refreshStateHandler()}},jW=`dv-quasiPreventDefault`;function MW(e){e[jW]=!0}function NW(e){return e[jW]}function PW(e,t){let n=e.composedPath?.call(e)??[];if(n.length>0)return t.some(e=>n.includes(e));let r=e.target;return r instanceof Node&&t.some(e=>e.contains(r))}function FW(e){let t=[],n=e.getRootNode();for(;BW(n);)t.push(n),n=n.host.getRootNode();return t}function IW(e,t){let n=t?.getRootNode(),r=e,i=r.getRootNode();for(;i!==n&&BW(i);)r=i.host,i=r.getRootNode();return r}function LW(e,t,n={}){let r=Array.from(t),{nonce:i}=n,a=typeof i==`function`?i(e):i;for(let t of r){if(t.href){let n=e.createElement(`link`);n.href=t.href,n.type=t.type,n.rel=`stylesheet`,a&&n.setAttribute(`nonce`,a),e.head.appendChild(n);continue}let n=[];try{t.cssRules&&(n=Array.from(t.cssRules).map(e=>e.cssText))}catch(e){console.warn(`dockview: failed to access stylesheet rules due to security restrictions`,e)}let r=e.createDocumentFragment();for(let t of n){let n=e.createElement(`style`);a&&n.setAttribute(`nonce`,a),n.appendChild(e.createTextNode(t)),r.appendChild(n)}e.head.appendChild(r)}}function RW(e){let{left:t,top:n,width:r,height:i}=e.getBoundingClientRect();return{left:t+window.scrollX,top:n+window.scrollY,width:r,height:i}}function zW(e){let t=e;for(;t?.parentNode;)if(t.parentNode===document)return!0;else t=t.parentNode instanceof DocumentFragment?t.parentNode.host:t.parentNode;return!1}function BW(e){return!!e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&`host`in e&&!!e.host}function VW(e){let t=e.getRootNode();return t!==e&&typeof t.elementsFromPoint==`function`?t:e.ownerDocument??document}function HW(e,t){e.dataset.testid=t}function UW(e,t){let n=[];function r(t){if(t.nodeType===Node.ELEMENT_NODE){e.includes(t.tagName)&&n.push(t),t.shadowRoot&&r(t.shadowRoot);for(let e of t.children)r(e)}}return r(t instanceof Document?t.documentElement:t),n}function WW(e=document){let t=UW([`IFRAME`,`WEBVIEW`],e),n=new WeakMap;for(let e of t)n.set(e,e.style.pointerEvents),e.style.pointerEvents=`none`;return{release:()=>{for(let e of t)e.style.pointerEvents=n.get(e)??`auto`;t.splice(0,t.length)}}}function GW(e=document){let t=e instanceof Document?e:e.ownerDocument,n=t?.documentElement;if(!t||!n)return{release:()=>void 0};let r=[`user-select`,`-webkit-user-select`],i=r.map(e=>[e,n.style.getPropertyValue(e)]);for(let e of r)n.style.setProperty(e,`none`);let a=e=>e.preventDefault();return t.addEventListener(`selectstart`,a),{release:()=>{t.removeEventListener(`selectstart`,a);for(let[e,t]of i)t?n.style.setProperty(e,t):n.style.removeProperty(e)}}}function KW(e){function t(e){let t=[];for(let n=0;n<e.classList.length;n++)t.push(e.classList.item(n));return t}let n,r=e;for(;r!==null&&(n=t(r).find(e=>e.startsWith(`dockview-theme-`)),typeof n!=`string`);)if(r.parentElement===null){let e=r.getRootNode();r=BW(e)?e.host:null}else r=r.parentElement;return n}var qW=class{constructor(e){this.element=e,this._classNames=[]}setClassNames(e){for(let e of this._classNames)Q(this.element,e,!1);this._classNames=e.split(` `).filter(e=>e.trim().length>0);for(let e of this._classNames)Q(this.element,e,!0)}},JW=100;function YW(e,t){let n=RW(e),r=RW(t);return!(n.left<r.left||n.left+n.width>r.left+r.width||n.top<r.top||n.top+n.height>r.top+r.height)}function XW(e){let t=new X,n=e.screenX,r=e.screenY,i,a=0,o=!1,s=()=>{if(o||e.closed)return;let c=e.screenX,l=e.screenY;(c!==n||l!==r)&&(clearTimeout(i),i=setTimeout(()=>{t.fire()},JW),n=c,r=l),a=requestAnimationFrame(s)};s();let c=t.dispose.bind(t);return t.dispose=()=>{o||(o=!0,cancelAnimationFrame(a),clearTimeout(i)),c()},t}function ZW(e,t){let n;return new Y(Z(e,`resize`,()=>{clearTimeout(n),n=setTimeout(()=>{t()},JW)}),hW.from(()=>clearTimeout(n)))}function QW(e,t,n){let r=n?.buffer??10,i=e.getBoundingClientRect(),a=t.getBoundingClientRect(),o=0,s=0,c=i.left-a.left,l=i.top-a.top,u=i.bottom-a.bottom,d=i.right-a.right;c<r?o=r-c:d>r&&(o=-r-d),l<r?s=r-l:u>r&&(s=-u-r),(o!==0||s!==0)&&(e.style.transform=`translate(${o}px, ${s}px)`)}function $W(e){let t=e;for(;t&&(t.style.zIndex===`auto`||t.style.zIndex===``);)t=t.parentElement;return t}function eG(e){let t=e.getRootNode(),n=t.nodeType===Node.DOCUMENT_NODE?t:e.ownerDocument;return n&&typeof n.hasFocus==`function`&&!n.hasFocus()?null:t.activeElement??null}function tG(e){let t=e.getRootNode();return BW(t)?t:(e.ownerDocument??document).body}function nG(e,t,n,r,i,a,o){try{var s=e[a](o),c=s.value}catch(e){n(e);return}s.done?t(c):Promise.resolve(c).then(r,i)}function rG(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var a=e.apply(t,n);function o(e){nG(a,r,i,o,s,`next`,e)}function s(e){nG(a,r,i,o,s,`throw`,e)}o(void 0)})}}function iG(e){let t=sG(e);if(t)throw t}var aG=new Set([`javascript:`,`data:`,`blob:`,`vbscript:`,`file:`]),oG=250;function sG(e,t=globalThis.location){let n;try{n=new URL(e,t.href)}catch{return Error(`dockview: invalid popout URL: ${e}`)}if(aG.has(n.protocol))return Error(`dockview: popout URL must not use the "${n.protocol}" protocol, which would run in the opener's context; got: ${e}`);if(n.protocol!==t.protocol||n.host!==t.host)return Error(`dockview: popout URL must be same-origin with the page (${t.protocol}//${t.host}); got: ${e}`)}var cG=class extends Y{get window(){return this._window?.value??null}get failure(){return this._failure}constructor(e,t,n){super(),this.target=e,this.className=t,this.options=n,this._onWillClose=new X,this.onWillClose=this._onWillClose.event,this._onDidClose=new X,this.onDidClose=this._onDidClose.event,this._window=null,this.addDisposables(this._onWillClose,this._onDidClose)}dispose(){this.close(),super.dispose()}dimensions(){if(!this._window)return null;let e=this._window.value.screenX;return{top:this._window.value.screenY,left:e,width:this._window.value.innerWidth,height:this._window.value.innerHeight}}close(){var e,t;let n=this._window;n&&(this._window=null,this._onWillClose.fire(),(e=(t=this.options).onWillClose)==null||e.call(t,{id:this.target,window:n.value}),n.disposable.dispose(),this._onDidClose.fire())}open(){var e=this;return rG(function*(){var t,n;if(e._window)throw Error(`instance of popout window is already open`);let r=`${e.options.url}`;iG(r);let i=Object.entries({top:e.options.top,left:e.options.left,width:e.options.width,height:e.options.height}).map(([e,t])=>`${e}=${t}`).join(`,`),a=window.open(r,e.target,i);if(!a)return e._failure={reason:`blocked`},null;let o=new Y;e._window={value:a,disposable:o},o.addDisposables(hW.from(()=>{a.close()}),e.watchForClose(a),Z(globalThis.window,`beforeunload`,()=>{e.close()}));let s=e.createPopoutWindowContainer();return e.className&&s.classList.add(e.className),(t=(n=e.options).onDidOpen)==null||t.call(n,{id:e.target,window:a}),new Promise(t=>{let n=n=>{e._failure={reason:`unscriptable`,error:n instanceof Error?n:Error(String(n))},e.close(),t(null)};try{a.addEventListener(`unload`,()=>{})}catch(e){n(e);return}o.addDisposables(e.onWillClose(()=>{e._failure??={reason:`closed`},t(null)})),a.addEventListener(`load`,()=>{try{var r;let n=a.document;n.title=document.title,n.body.appendChild(s),LW(n,[...Array.from(globalThis.document.styleSheets),...globalThis.document.adoptedStyleSheets??[]],{nonce:e.options.nonce});let i=[];for(let t=(r=e.options).styleRoot?.call(r);BW(t);t=t.host.getRootNode())i.push(...Array.from(t.styleSheets??[]),...t.adoptedStyleSheets??[]);i.length>0&&LW(n,i,{nonce:e.options.nonce}),Z(a,`beforeunload`,()=>{e.close()}),t(s)}catch(e){n(e)}})})})()}watchForClose(e){if(typeof e.closed!=`boolean`)return hW.NONE;let t=setInterval(()=>{e.closed&&this.close()},oG);return hW.from(()=>{clearInterval(t)})}createPopoutWindowContainer(){let e=document.createElement(`div`);return e.classList.add(`dv-popout-window`),e.id=`dv-popout-window`,e.style.position=`absolute`,e.style.width=`100%`,e.style.height=`100%`,e.style.top=`0px`,e.style.left=`0px`,e}};function lG(e){if(e.length===0)throw Error(`Invalid tail call`);return[e.slice(0,e.length-1),e[e.length-1]]}function uG(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function dG(e,t){let n=e.indexOf(t);n>-1&&(e.splice(n,1),e.unshift(t))}function fG(e,t){let n=e.indexOf(t);n>-1&&(e.splice(n,1),e.push(t))}function pG(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(t(r))return n}return-1}function mG(e,t){let n=e.indexOf(t);return n>-1&&(e.splice(n,1),!0)}var hG=(e,t,n)=>t>n?t:Math.min(n,Math.max(e,t)),gG=()=>{let e=1;return{next:()=>(e++).toString()}},_G=(e,t)=>{let n=[];if(typeof t!=`number`&&(t=e,e=0),e<=t)for(let r=e;r<t;r++)n.push(r);else for(let r=e;r>t;r--)n.push(r);return n},vG=class{set size(e){this._size=e}setContainerGeometry(e,t){this._appliedStyles[e]!==t&&(this._appliedStyles[e]=t,this.container.style[e]=t)}get size(){return this._size}get cachedVisibleSize(){return this._cachedVisibleSize}get visible(){return this._cachedVisibleSize===void 0}get minimumSize(){return this.visible?this.view.minimumSize:0}get viewMinimumSize(){return this.view.minimumSize}get maximumSize(){return this.visible?this.view.maximumSize:0}get viewMaximumSize(){return this.view.maximumSize}get priority(){return this.view.priority}get snap(){return!!this.view.snap}set enabled(e){this.container.style.pointerEvents=e?``:`none`}constructor(e,t,n,r){this.container=e,this.view=t,this.disposable=r,this._cachedVisibleSize=void 0,this._appliedStyles={},typeof n==`number`?(this._size=n,this._cachedVisibleSize=void 0,e.classList.add(`visible`)):(this._size=0,this._cachedVisibleSize=n.cachedVisibleSize)}setVisible(e,t){if(e!==this.visible){if(e){let e=this._cachedVisibleSize??0;this._cachedVisibleSize=void 0,this.size=hG(e,this.viewMinimumSize,this.viewMaximumSize)}else this._cachedVisibleSize=typeof t==`number`?t:this.size,this.size=0;this.container.classList.toggle(`visible`,e),this.view.setVisible&&this.view.setVisible(e)}}scale(e){this._cachedVisibleSize===void 0?this.size=hG(Math.round(this.size*e),this.minimumSize,this.maximumSize):this._cachedVisibleSize=Math.round(this._cachedVisibleSize*e)}dispose(){return this.disposable.dispose(),this.view}},yG=function(e){return e.HORIZONTAL=`HORIZONTAL`,e.VERTICAL=`VERTICAL`,e}({});function bG(e,t,n){e.appliedLeft!==t&&(e.appliedLeft=t,e.container.style.left=t),e.appliedTop!==n&&(e.appliedTop=n,e.container.style.top=n)}var xG;(function(e){e.Distribute={type:`distribute`};function t(e){return{type:`split`,index:e}}e.Split=t;function n(e){return{type:`invisible`,cachedVisibleSize:e}}e.Invisible=n})(xG||={});var SG=class{get contentSize(){return this._contentSize}get size(){return this._size}set size(e){this._size=e}get orthogonalSize(){return this._orthogonalSize}set orthogonalSize(e){this._orthogonalSize=e}get length(){return this.viewItems.length}get proportions(){return this._proportions?[...this._proportions]:void 0}get proportionalLayout(){return this._proportionalLayout}set proportionalLayout(e){this._proportionalLayout!==e&&(this._proportionalLayout=e,e?this.saveProportions():this._proportions=void 0)}get orientation(){return this._orientation}set orientation(e){if(this._orientation===e)return;this._orientation=e;let t=this.size;this.size=this.orthogonalSize,this.orthogonalSize=t,this.rescaleViews(this.size),EW(this.element,`dv-horizontal`,`dv-vertical`),this.element.classList.add(this.orientation==`HORIZONTAL`?`dv-horizontal`:`dv-vertical`)}get minimumSize(){return this.viewItems.reduce((e,t)=>e+t.minimumSize,0)}get maximumSize(){return this.length===0?1/0:this.viewItems.reduce((e,t)=>e+t.maximumSize,0)}get startSnappingEnabled(){return this._startSnappingEnabled}set startSnappingEnabled(e){this._startSnappingEnabled!==e&&(this._startSnappingEnabled=e,this.updateSashEnablement())}get endSnappingEnabled(){return this._endSnappingEnabled}set endSnappingEnabled(e){this._endSnappingEnabled!==e&&(this._endSnappingEnabled=e,this.updateSashEnablement())}get disabled(){return this._disabled}set disabled(e){this._disabled=e,Q(this.element,`dv-splitview-disabled`,e)}get margin(){return this._margin}get marginShare(){let e=0;for(let t of this.viewItems)t.visible&&e++;return this.marginShareFor(e)}set margin(e){this._margin=e,Q(this.element,`dv-splitview-has-margin`,e!==0)}constructor(e,t){this.container=e,this.viewItems=[],this.sashes=[],this._size=0,this._orthogonalSize=0,this._contentSize=0,this._proportions=void 0,this._startSnappingEnabled=!0,this._endSnappingEnabled=!0,this._disabled=!1,this._margin=0,this._onDidSashEnd=new X,this.onDidSashEnd=this._onDidSashEnd.event,this._onDidAddView=new X,this.onDidAddView=this._onDidAddView.event,this._onDidRemoveView=new X,this.onDidRemoveView=this._onDidRemoveView.event,this.resize=(e,t,n=this.viewItems.map(e=>e.size),r,i,a=-1/0,o=1/0,s,c)=>{if(e<0||e>this.viewItems.length)return 0;let l=_G(e,-1),u=_G(e+1,this.viewItems.length);if(i)for(let e of i)dG(l,e),dG(u,e);if(r)for(let e of r)fG(l,e),fG(u,e);let d=l.reduce((e,t)=>e+this.viewItems[t].minimumSize-n[t],0),f=l.reduce((e,t)=>e+this.viewItems[t].maximumSize-n[t],0),p=u.length===0?1/0:u.reduce((e,t)=>e+n[t]-this.viewItems[t].minimumSize,0),m=u.length===0?-1/0:u.reduce((e,t)=>e+n[t]-this.viewItems[t].maximumSize,0),h=Math.max(d,m),g=Math.min(p,f),_=!1;if(s){let e=this.viewItems[s.index],n=t>=s.limitDelta;_=n!==e.visible,e.setVisible(n,s.size)}if(!_&&c){let e=this.viewItems[c.index],n=t<c.limitDelta;_=n!==e.visible,e.setVisible(n,c.size)}if(_)return this.resize(e,t,n,r,i,a,o);let v=hG(t,h,g),y=0,b=v;for(let e of l){let t=this.viewItems[e],r=n[e],i=hG(r+b,t.minimumSize,t.maximumSize),a=i-r;y+=a,b-=a,t.size=i}let x=y;for(let e of u){let t=this.viewItems[e],r=n[e],i=hG(r-x,t.minimumSize,t.maximumSize),a=i-r;x+=a,t.size=i}return t},this._orientation=t.orientation??`VERTICAL`,this.element=this.createContainer(),this.margin=t.margin??0,this._proportionalLayout=t.proportionalLayout===void 0||!!t.proportionalLayout,this.viewContainer=this.createViewContainer(),this.sashContainer=this.createSashContainer(),this.element.appendChild(this.sashContainer),this.element.appendChild(this.viewContainer),this.container.appendChild(this.element),this.style(t.styles),t.descriptor&&(this._size=t.descriptor.size,t.descriptor.views.forEach((e,t)=>{let n=e.visible===void 0||e.visible?e.size:{type:`invisible`,cachedVisibleSize:e.size},r=e.view;this.addView(r,n,t,!0)}),this._contentSize=this.viewItems.reduce((e,t)=>e+t.size,0),this.saveProportions())}style(e){e?.separatorBorder===`transparent`?(EW(this.element,`dv-separator-border`),this.element.style.removeProperty(`--dv-separator-border`)):(DW(this.element,`dv-separator-border`),e?.separatorBorder&&this.element.style.setProperty(`--dv-separator-border`,e.separatorBorder))}isViewVisible(e){if(e<0||e>=this.viewItems.length)throw Error(`Index out of bounds`);return this.viewItems[e].visible}setViewVisible(e,t){if(e<0||e>=this.viewItems.length)throw Error(`Index out of bounds`);let n=this.viewItems[e];n.setVisible(t,n.size),this.distributeEmptySpace(e),this.layoutViews(),this.saveProportions()}getViewSize(e){return e<0||e>=this.viewItems.length?-1:this.viewItems[e].size}resizeView(e,t){if(e<0||e>=this.viewItems.length)return;let n=_G(this.viewItems.length).filter(t=>t!==e),r=[...n.filter(e=>this.viewItems[e].priority===`low`),e],i=n.filter(e=>this.viewItems[e].priority===`high`),a=this.viewItems[e];t=Math.round(t),t=hG(t,a.minimumSize,Math.min(a.maximumSize,this._size)),a.size=t,this.relayout(r,i)}getViews(){return this.viewItems.map(e=>e.view)}onDidChange(e,t){let n=this.viewItems.indexOf(e);if(n<0||n>=this.viewItems.length)return;t=typeof t==`number`?t:e.size,t=hG(t,e.minimumSize,e.maximumSize),e.size=t;let r=_G(this.viewItems.length).filter(e=>e!==n),i=[...r.filter(e=>this.viewItems[e].priority===`low`),n],a=r.filter(e=>this.viewItems[e].priority===`high`);this.relayout([...i,n],a)}addView(e,t=xG.Distribute,n=this.viewItems.length,r){let i=document.createElement(`div`);i.className=`dv-view`,i.appendChild(e.element);let a;if(typeof t==`number`)a=t;else if(t.type===`split`){let e=this.viewItems[t.index];if(e){let t=Math.floor(e.size/2);a=e.size-t,e.size=t}else a=this.getViewSize(t.index)/2}else a=t.type===`invisible`?{cachedVisibleSize:t.cachedVisibleSize}:e.minimumSize;let o=e.onDidChange(e=>this.onDidChange(s,e.size)),s=new vG(i,e,a,{dispose:()=>{o.dispose(),i.remove()}});if(n===this.viewItems.length?this.viewContainer.appendChild(i):this.viewContainer.insertBefore(i,this.viewContainer.children.item(n)),this.viewItems.splice(n,0,s),this.viewItems.length>1){let e=document.createElement(`div`);e.className=`dv-sash`;let t=t=>{for(let e of this.viewItems)e.enabled=!1;let n=e.ownerDocument??document,r=WW(n),i=this._orientation===`HORIZONTAL`?t.clientX:t.clientY,a=pG(this.sashes,t=>t.container===e),o=this.viewItems.map(e=>e.size),s,c,l=_G(a,-1),u=_G(a+1,this.viewItems.length),d=l.reduce((e,t)=>e+(this.viewItems[t].minimumSize-o[t]),0),f=l.reduce((e,t)=>e+(this.viewItems[t].viewMaximumSize-o[t]),0),p=u.length===0?1/0:u.reduce((e,t)=>e+(o[t]-this.viewItems[t].minimumSize),0),m=u.length===0?-1/0:u.reduce((e,t)=>e+(o[t]-this.viewItems[t].viewMaximumSize),0),h=Math.max(d,m),g=Math.min(p,f),_=this.findFirstSnapIndex(l),v=this.findFirstSnapIndex(u);if(typeof _==`number`){let e=this.viewItems[_],t=Math.floor(e.viewMinimumSize/2);s={index:_,limitDelta:e.visible?h-t:h+t,size:e.size}}if(typeof v==`number`){let e=this.viewItems[v],t=Math.floor(e.viewMinimumSize/2);c={index:v,limitDelta:e.visible?g+t:g-t,size:e.size}}let y=e=>{let t=(this._orientation===`HORIZONTAL`?e.clientX:e.clientY)-i;this.resize(a,t,o,void 0,void 0,h,g,s,c),this.distributeEmptySpace(),this.layoutViews()},b=()=>{for(let e of this.viewItems)e.enabled=!0;r.release(),this.saveProportions(),n.removeEventListener(`pointermove`,y),n.removeEventListener(`pointerup`,b),n.removeEventListener(`pointercancel`,b),n.removeEventListener(`contextmenu`,b),this._onDidSashEnd.fire(void 0)};n.addEventListener(`pointermove`,y),n.addEventListener(`pointerup`,b),n.addEventListener(`pointercancel`,b),n.addEventListener(`contextmenu`,b)};e.addEventListener(`pointerdown`,t);let n={container:e,disposable:()=>{e.removeEventListener(`pointerdown`,t),e.remove()}};this.sashContainer.appendChild(e),this.sashes.push(n)}r||this.relayout([n]),!r&&typeof t!=`number`&&t.type===`distribute`&&this.distributeViewSizes(),this._onDidAddView.fire(e)}distributeViewSizes(){let e=[],t=0;for(let n of this.viewItems)n.maximumSize-n.minimumSize>0&&(e.push(n),t+=n.size);let n=Math.floor(t/e.length);for(let t of e)t.size=hG(n,t.minimumSize,t.maximumSize);let r=_G(this.viewItems.length),i=r.filter(e=>this.viewItems[e].priority===`low`),a=r.filter(e=>this.viewItems[e].priority===`high`);this.relayout(i,a)}removeView(e,t,n=!1){let r=this.viewItems.splice(e,1)[0];if(r.dispose(),this.viewItems.length>=1){let t=Math.max(e-1,0);this.sashes.splice(t,1)[0].disposable()}return n||this.relayout(),t?.type===`distribute`&&this.distributeViewSizes(),this._onDidRemoveView.fire(r.view),r.view}getViewCachedVisibleSize(e){if(e<0||e>=this.viewItems.length)throw Error(`Index out of bounds`);return this.viewItems[e].cachedVisibleSize}moveView(e,t){let n=this.getViewCachedVisibleSize(e),r=n===void 0?this.getViewSize(e):xG.Invisible(n),i=this.removeView(e,void 0,!0);this.addView(i,r,t)}layout(e,t){let n=Math.max(this.size,this._contentSize);if(this.size=e,this.orthogonalSize=t,this._proportions||this.saveProportions(),this.proportions){let t=0;for(let n=0;n<this.viewItems.length;n++){let r=this.viewItems[n],i=this.proportions[n];typeof i==`number`?t+=i:e-=r.size}for(let n=0;n<this.viewItems.length;n++){let r=this.viewItems[n],i=this.proportions[n];typeof i==`number`&&t>0&&(r.size=hG(Math.round(i*e/t),r.minimumSize,r.maximumSize))}}else{let t=_G(this.viewItems.length),r=t.filter(e=>this.viewItems[e].priority===`low`),i=t.filter(e=>this.viewItems[e].priority===`high`);this.resize(this.viewItems.length-1,e-n,void 0,r,i)}this.distributeEmptySpace(),this.layoutViews()}relayout(e,t){let n=this.viewItems.reduce((e,t)=>e+t.size,0);this.resize(this.viewItems.length-1,this._size-n,void 0,e,t),this.distributeEmptySpace(),this.layoutViews(),this.saveProportions()}distributeEmptySpace(e){let t=0;for(let e of this.viewItems)t+=e.size;let n=this.size-t;if(n===0)return;let r=_G(this.viewItems.length-1,-1),i=!1;for(let e of this.viewItems)if(e.priority===`low`||e.priority===`high`){i=!0;break}if(i){let e=r.filter(e=>this.viewItems[e].priority===`low`),t=r.filter(e=>this.viewItems[e].priority===`high`);for(let e of t)dG(r,e);for(let t of e)fG(r,t)}typeof e==`number`&&fG(r,e);for(let e=0;n!==0&&e<r.length;e++){let t=this.viewItems[r[e]],i=hG(t.size+n,t.minimumSize,t.maximumSize),a=i-t.size;n-=a,t.size=i}}rescaleViews(e){let t=0;for(let e of this.viewItems)t+=e.size;if(e<=0||t<=0)return;let n=e/t,r=0;for(let e of this.viewItems)e.scale(n),r+=e.size;this._contentSize=r}saveProportions(){if(!this.proportionalLayout)return;let e=0;for(let t of this.viewItems)e+=t.size;e>0&&(this._proportions=this.viewItems.map(t=>t.visible?t.size/e:void 0))}layoutViews(){let e=0,t=0;for(let n of this.viewItems)e+=n.size,n.visible&&t++;if(this._contentSize=e,this.updateSashEnablement(),this.viewItems.length===0)return;let n=Math.max(0,t-1),r=this.marginShareFor(t),i=0,a=[],o=0;this.viewItems.forEach((e,t)=>{i+=this.viewItems[t].size,a.push(i),o+=+!!e.visible;let s=e.visible?e.size-r:0,c=Math.max(0,o-1),l=t===0||c===0?0:a[t-1]+c/n*r;if(t<this.viewItems.length-1){let n=e.visible?l+s-2+this.margin/2:l,r=this.sashes[t];this._orientation===`HORIZONTAL`&&bG(r,`${n}px`,`0px`),this._orientation===`VERTICAL`&&bG(r,`0px`,`${n}px`)}this._orientation===`HORIZONTAL`&&(e.setContainerGeometry(`width`,`${s}px`),e.setContainerGeometry(`left`,`${l}px`),e.setContainerGeometry(`top`,``),e.setContainerGeometry(`height`,``)),this._orientation===`VERTICAL`&&(e.setContainerGeometry(`height`,`${s}px`),e.setContainerGeometry(`top`,`${l}px`),e.setContainerGeometry(`width`,``),e.setContainerGeometry(`left`,``)),e.view.layout(s,this._orthogonalSize)})}marginShareFor(e){let t=Math.max(0,e-1);return this._margin*t/Math.max(1,e)}findFirstSnapIndex(e){for(let t of e){let e=this.viewItems[t];if(e.visible&&e.snap)return t}for(let t of e){let e=this.viewItems[t];if(e.visible&&e.maximumSize-e.minimumSize>0)return;if(!e.visible&&e.snap)return t}}updateSashEnablement(){if(this.sashes.length===0)return;let e=!1,t=this.viewItems.map(t=>e=t.size-t.minimumSize>0||e);e=!1;let n=this.viewItems.map(t=>e=t.maximumSize-t.size>0||e),r=[...this.viewItems].reverse();e=!1;let i=r.map(t=>e=t.size-t.minimumSize>0||e).reverse();e=!1;let a=r.map(t=>e=t.maximumSize-t.size>0||e).reverse(),o=0;for(let e=0;e<this.sashes.length;e++){let r=this.sashes[e],s=this.viewItems[e];o+=s.size;let c=!(t[e]&&a[e+1]),l=!(n[e]&&i[e+1]);if(c&&l){let n=_G(e,-1),a=_G(e+1,this.viewItems.length),s=this.findFirstSnapIndex(n),c=this.findFirstSnapIndex(a),l=typeof s==`number`&&!this.viewItems[s].visible,u=typeof c==`number`&&!this.viewItems[c].visible;l&&i[e]&&(o>0||this.startSnappingEnabled)?this.updateSash(r,1):u&&t[e]&&(o<this._contentSize||this.endSnappingEnabled)?this.updateSash(r,0):this.updateSash(r,2)}else c&&!l?this.updateSash(r,1):!c&&l?this.updateSash(r,0):this.updateSash(r,3)}}updateSash(e,t){Q(e.container,`dv-disabled`,t===2),Q(e.container,`dv-enabled`,t===3),Q(e.container,`dv-maximum`,t===0),Q(e.container,`dv-minimum`,t===1)}createViewContainer(){let e=document.createElement(`div`);return e.className=`dv-view-container`,e}createSashContainer(){let e=document.createElement(`div`);return e.className=`dv-sash-container`,e}createContainer(){let e=document.createElement(`div`);return e.className=`dv-split-view-container ${this._orientation===`HORIZONTAL`?`dv-horizontal`:`dv-vertical`}`,e}dispose(){this._onDidSashEnd.dispose(),this._onDidAddView.dispose(),this._onDidRemoveView.dispose();for(let e=0;e<this.element.children.length;e++)if(this.element.children.item(e)===this.element){this.element.remove();break}for(let e of this.viewItems)e.dispose();this.element.remove()}},CG=Object.keys({orientation:void 0,descriptor:void 0,proportionalLayout:void 0,styles:void 0,margin:void 0,disableAutoResizing:void 0,className:void 0}),wG=class extends Y{get onDidAddView(){return this.splitview.onDidAddView}get onDidRemoveView(){return this.splitview.onDidRemoveView}get minimumSize(){return this.splitview.minimumSize}get maximumSize(){return this.splitview.maximumSize}get orientation(){return this.splitview.orientation}get size(){return this.splitview.size}get orthogonalSize(){return this.splitview.orthogonalSize}constructor(e,t){super(),this.paneItems=[],this.skipAnimation=!1,this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this._orientation=t.orientation??`VERTICAL`,this.element=document.createElement(`div`),this.element.className=`dv-pane-container`,e.appendChild(this.element),this.splitview=new SG(this.element,{orientation:this._orientation,proportionalLayout:!1,descriptor:t.descriptor}),this.getPanes().forEach(e=>{let t=new Y(e.onDidChangeExpansionState(()=>{this.setupAnimation(),this._onDidChange.fire(void 0)})),n={pane:e,disposable:{dispose:()=>{t.dispose()}}};this.paneItems.push(n),e.orthogonalSize=this.splitview.orthogonalSize}),this.addDisposables(this._onDidChange,this.splitview.onDidSashEnd(()=>{this._onDidChange.fire(void 0)}),this.splitview.onDidAddView(()=>{this._onDidChange.fire()}),this.splitview.onDidRemoveView(()=>{this._onDidChange.fire()}))}setViewVisible(e,t){this.splitview.setViewVisible(e,t)}addPane(e,t,n=this.splitview.length,r=!1){let i=e.onDidChangeExpansionState(()=>{this.setupAnimation(),this._onDidChange.fire(void 0)}),a={pane:e,disposable:{dispose:()=>{i.dispose()}}};this.paneItems.splice(n,0,a),e.orthogonalSize=this.splitview.orthogonalSize,this.splitview.addView(e,t,n,r)}getViewSize(e){return this.splitview.getViewSize(e)}getViewCachedVisibleSize(e){return this.splitview.getViewCachedVisibleSize(e)}getPanes(){return this.splitview.getViews()}removePane(e,t){if(e<0||e>=this.paneItems.length)throw Error(`Index out of bounds`);let n=this.paneItems.splice(e,1)[0];return this.splitview.removeView(e),t?.skipDispose||(n.disposable.dispose(),n.pane.dispose()),n}moveView(e,t){if(e===t)return;let n=this.getViewCachedVisibleSize(e),r=this.removePane(e,{skipDispose:!0}),i=n===void 0?r.pane.size:xG.Invisible(n);r.disposable.dispose(),this.skipAnimation=!0;try{this.addPane(r.pane,i,t,!1)}finally{this.skipAnimation=!1}}layout(e,t){this.splitview.layout(e,t)}setupAnimation(){this.skipAnimation||(this.animationTimer&&=(clearTimeout(this.animationTimer),void 0),DW(this.element,`dv-animated`),this.animationTimer=setTimeout(()=>{this.animationTimer=void 0,EW(this.element,`dv-animated`)},200))}dispose(){super.dispose(),this.animationTimer&&=(clearTimeout(this.animationTimer),void 0),this.paneItems.forEach(e=>{e.disposable.dispose(),e.pane.dispose()}),this.paneItems=[],this.splitview.dispose(),this.element.remove()}},TG=class{get minimumWidth(){return this.view.minimumWidth}get maximumWidth(){return this.view.maximumWidth}get minimumHeight(){return this.view.minimumHeight}get maximumHeight(){return this.view.maximumHeight}get priority(){return this.view.priority}get snap(){return this.view.snap}get minimumSize(){return this.orientation===`HORIZONTAL`?this.minimumHeight:this.minimumWidth}get maximumSize(){return this.orientation===`HORIZONTAL`?this.maximumHeight:this.maximumWidth}get minimumOrthogonalSize(){return this.orientation===`HORIZONTAL`?this.minimumWidth:this.minimumHeight}get maximumOrthogonalSize(){return this.orientation===`HORIZONTAL`?this.maximumWidth:this.maximumHeight}get orthogonalSize(){return this._orthogonalSize}get size(){return this._size}get element(){return this.view.element}get width(){return this.orientation===`HORIZONTAL`?this.orthogonalSize:this.size}get height(){return this.orientation===`HORIZONTAL`?this.size:this.orthogonalSize}constructor(e,t,n,r=0){this.view=e,this.orientation=t,this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this._orthogonalSize=n,this._size=r,this._disposable=this.view.onDidChange(e=>{e?this._onDidChange.fire({size:this.orientation===`VERTICAL`?e.width:e.height,orthogonalSize:this.orientation===`VERTICAL`?e.height:e.width}):this._onDidChange.fire({})})}setVisible(e){this.view.setVisible&&this.view.setVisible(e)}layout(e,t){this._size=e,this._orthogonalSize=t,this.view.layout(this.width,this.height)}dispose(){this._onDidChange.dispose(),this._disposable.dispose()}},EG=class e extends Y{get width(){return this.orientation===`HORIZONTAL`?this.size:this.orthogonalSize}get height(){return this.orientation===`HORIZONTAL`?this.orthogonalSize:this.size}get minimumSize(){if(this._cachedMinimumSize===void 0){let e=0;for(let t=0;t<this.children.length;t++)this.splitview.isViewVisible(t)&&(e=Math.max(e,this.children[t].minimumOrthogonalSize));this._cachedMinimumSize=e}return this._cachedMinimumSize}get maximumSize(){if(this._cachedMaximumSize===void 0){let e=1/0;for(let t=0;t<this.children.length;t++)this.splitview.isViewVisible(t)&&(e=Math.min(e,this.children[t].maximumOrthogonalSize));this._cachedMaximumSize=e}return this._cachedMaximumSize}get minimumOrthogonalSize(){return this.splitview.minimumSize}get maximumOrthogonalSize(){return this.splitview.maximumSize}get orthogonalSize(){return this._orthogonalSize}get size(){return this._size}get minimumWidth(){return this.orientation===`HORIZONTAL`?this.minimumOrthogonalSize:this.minimumSize}get minimumHeight(){return this.orientation===`HORIZONTAL`?this.minimumSize:this.minimumOrthogonalSize}get maximumWidth(){return this.orientation===`HORIZONTAL`?this.maximumOrthogonalSize:this.maximumSize}get maximumHeight(){return this.orientation===`HORIZONTAL`?this.maximumSize:this.maximumOrthogonalSize}get priority(){return this._cachedPriority??=this.computePriority(),this._cachedPriority}computePriority(){if(this.children.length===0)return`normal`;let e=!1,t=!1;for(let n of this.children){let r=n.priority??`normal`;r===`high`?e=!0:r===`low`&&(t=!0)}return e?`high`:t?`low`:`normal`}invalidateCachedSizes(){this._cachedMinimumSize=void 0,this._cachedMaximumSize=void 0,this._cachedPriority=void 0,this._onDidInvalidateSizes.fire()}get disabled(){return this.splitview.disabled}set disabled(e){this.splitview.disabled=e}get margin(){return this.splitview.margin}set margin(t){this.splitview.margin=t,this.children.forEach(n=>{n instanceof e&&(n.margin=t)})}get proportionalLayout(){return this.splitview.proportionalLayout}set proportionalLayout(t){this.splitview.proportionalLayout=t,this.children.forEach(n=>{n instanceof e&&(n.proportionalLayout=t)})}constructor(e,t,n,r,i,a,o,s){if(super(),this.orientation=e,this.styles=n,this._childrenDisposable=hW.NONE,this.children=[],this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this._onDidVisibilityChange=new X,this.onDidVisibilityChange=this._onDidVisibilityChange.event,this._onDidInvalidateSizes=new X,this.onDidInvalidateSizes=this._onDidInvalidateSizes.event,this._orthogonalSize=i,this._size=r,this.element=document.createElement(`div`),this.element.className=`dv-branch-node`,s){let e={views:s.map(e=>({view:e.node,size:e.node.size,visible:e.visible??!0})),size:this.orthogonalSize};this.children=s.map(e=>e.node),this.splitview=new SG(this.element,{orientation:this.orientation,descriptor:e,proportionalLayout:t,styles:n,margin:o})}else this.splitview=new SG(this.element,{orientation:this.orientation,proportionalLayout:t,styles:n,margin:o}),this.splitview.layout(this.size,this.orthogonalSize);this.disabled=a,this.addDisposables(this._onDidChange,this._onDidVisibilityChange,this._onDidInvalidateSizes,this.splitview.onDidSashEnd(()=>{this._onDidChange.fire({})})),this.setupChildrenEvents()}setVisible(e){}isChildVisible(e){if(e<0||e>=this.children.length)throw Error(`Invalid index`);return this.splitview.isViewVisible(e)}setChildVisible(e,t){if(e<0||e>=this.children.length)throw Error(`Invalid index`);if(this.splitview.isViewVisible(e)===t)return;let n=this.splitview.contentSize===0;this.splitview.setViewVisible(e,t),this.invalidateCachedSizes();let r=this.splitview.contentSize===0;(t&&n||!t&&r)&&this._onDidVisibilityChange.fire({visible:t})}moveChild(e,t){if(e===t)return;if(e<0||e>=this.children.length)throw Error(`Invalid from index`);e<t&&t--,this.splitview.moveView(e,t);let n=this._removeChild(e);this._addChild(n,t)}getChildSize(e){if(e<0||e>=this.children.length)throw Error(`Invalid index`);return this.splitview.getViewSize(e)}resizeChild(e,t){if(e<0||e>=this.children.length)throw Error(`Invalid index`);this.splitview.resizeView(e,t)}layout(e,t){this._size=t,this._orthogonalSize=e,this.splitview.layout(t,e)}addChild(e,t,n,r){if(n<0||n>this.children.length)throw Error(`Invalid index`);this.splitview.addView(e,t,n,r),this._addChild(e,n)}getChildCachedVisibleSize(e){if(e<0||e>=this.children.length)throw Error(`Invalid index`);return this.splitview.getViewCachedVisibleSize(e)}removeChild(e,t){if(e<0||e>=this.children.length)throw Error(`Invalid index`);return this.splitview.removeView(e,t),this._removeChild(e)}_addChild(e,t){this.children.splice(t,0,e),this.setupChildrenEvents()}_removeChild(e){let[t]=this.children.splice(e,1);return this.setupChildrenEvents(),t}setupChildrenEvents(){this.invalidateCachedSizes(),this._childrenDisposable.dispose(),this._childrenDisposable=new Y(_W.any(...this.children.map(e=>e.onDidChange))(e=>{this.invalidateCachedSizes(),this._onDidChange.fire({size:e.orthogonalSize})}),...this.children.map((t,n)=>t instanceof e?new Y(t.onDidVisibilityChange(({visible:e})=>{this.setChildVisible(n,e)}),t.onDidInvalidateSizes(()=>{this.invalidateCachedSizes()})):hW.NONE))}dispose(){this._childrenDisposable.dispose(),this.splitview.dispose(),this.children.forEach(e=>e.dispose()),super.dispose()}};function DG(e,t){if(e instanceof TG)return e;if(e instanceof EG)return DG(e.children[t?e.children.length-1:0],t);throw Error(`invalid node`)}function OG(e,t,n,r=1){let i=e.getChildCachedVisibleSize(t);return i===void 0?n:xG.Invisible(Math.round(i*r))}function kG(e,t,n){if(e instanceof EG){let r=new EG(e.orientation,e.proportionalLayout,e.styles,t,n,e.disabled,e.margin);for(let t=e.children.length-1;t>=0;t--){let n=e.children[t],i=n instanceof EG?n.orthogonalSize:n.size;r.addChild(kG(n,n.size,n.orthogonalSize),OG(e,t,i),0,!0)}return r}return new TG(e.view,e.orientation,n)}function AG(e,t,n){if(e instanceof EG){let r=new EG(IG(e.orientation),e.proportionalLayout,e.styles,t,n,e.disabled,e.margin),i=0,a=e.size===0?1:t/e.size;for(let o=e.children.length-1;o>=0;o--){let s=e.children[o],c=s instanceof EG?s.orthogonalSize:s.size,l=e.size===0?0:Math.round(t*c/e.size);i+=l,o===0&&(l+=t-i),r.addChild(AG(s,n,l),OG(e,o,l,a),0,!0)}return r}return new TG(e.view,IG(e.orientation),n)}function jG(e){let t=e.parentElement;if(!t)throw Error(`Invalid grid element`);let n=t.firstElementChild,r=0;for(;n!==e&&n!==t.lastElementChild&&n;)n=n.nextElementSibling,r++;return r}function MG(e){let t=e.parentElement;if(!t)throw Error(`Invalid grid element`);if(/\bdv-grid-view\b/.test(t.className))return[];let n=jG(t),r=t.parentElement.parentElement.parentElement;return[...MG(r),n]}function NG(e,t,n){if(FG(e,t)===PG(n)){let[e,r]=lG(t),i=r;return(n===`right`||n===`bottom`)&&(i+=1),[...e,i]}{let e=+(n===`right`||n===`bottom`);return[...t,e]}}function PG(e){return e===`top`||e===`bottom`?`VERTICAL`:`HORIZONTAL`}function FG(e,t){return t.length%2==0?IG(e):e}var IG=e=>e===`HORIZONTAL`?`VERTICAL`:`HORIZONTAL`;function LG(e){return!!e.children}var RG=(e,t)=>{let n=t===`VERTICAL`?e.box.width:e.box.height;if(!LG(e))return typeof e.cachedVisibleSize==`number`?{type:`leaf`,data:e.view.toJSON(),size:e.cachedVisibleSize,visible:!1}:{type:`leaf`,data:e.view.toJSON(),size:n};let r=e.children.map(e=>RG(e,IG(t)));return typeof e.cachedVisibleSize==`number`?{type:`branch`,data:r,size:e.cachedVisibleSize,visible:!1}:{type:`branch`,data:r,size:n}},zG=class{get length(){return this._root?this._root.children.length:0}get orientation(){return this.root.orientation}set orientation(e){if(this.root.orientation===e)return;let{size:t,orthogonalSize:n}=this.root;this.root=AG(this.root,n,t),this.root.layout(t,n)}get width(){return this.root.width}get height(){return this.root.height}get minimumWidth(){return this.root.minimumWidth}get minimumHeight(){return this.root.minimumHeight}get maximumWidth(){return this.root.maximumWidth}get maximumHeight(){return this.root.maximumHeight}get locked(){return this._locked}set locked(e){this._locked=e;let t=[this.root];for(;t.length>0;){let n=t.pop();n instanceof EG&&(n.disabled=e,t.push(...n.children))}}get margin(){return this._margin}set margin(e){this._margin=e,this.root.margin=e}maximizedView(){return this._maximizedNode?.leaf.view}hasMaximizedView(){return this._maximizedNode!==void 0}maximizeView(e){let t=MG(e.element),[n,r]=this.getNode(t);if(!(r instanceof TG)||this._maximizedNode?.leaf===r)return;this.hasMaximizedView()&&this.exitMaximizedView(),RG(this.getView(),this.orientation);let i=[];function a(e,t){for(let n=0;n<e.children.length;n++){let r=e.children[n];r instanceof TG?r!==t&&(e.isChildVisible(n)?e.setChildVisible(n,!1):i.push(r)):a(r,t)}}a(this.root,r),this._maximizedNode={leaf:r,hiddenOnMaximize:i},this._onDidMaximizedNodeChange.fire({view:r.view,isMaximized:!0})}exitMaximizedView(){if(!this._maximizedNode)return;let e=this._maximizedNode.hiddenOnMaximize;function t(n){for(let r=n.children.length-1;r>=0;r--){let i=n.children[r];i instanceof TG?e.includes(i)||n.setChildVisible(r,!0):t(i)}}t(this.root);let n=this._maximizedNode.leaf;this._maximizedNode=void 0,this._onDidMaximizedNodeChange.fire({view:n.view,isMaximized:!1})}serialize(){let e=this.maximizedView(),t;e&&(t=MG(e.element));let n=this._onDidMaximizedNodeChange.pause();try{this.hasMaximizedView()&&this.exitMaximizedView();let n={root:RG(this.getView(),this.orientation),width:this.width,height:this.height,orientation:this.orientation};return t&&(n.maximizedNode={location:t}),e&&this.maximizeView(e),n}finally{n.dispose()}}dispose(){this.disposable.dispose(),this._onDidChange.dispose(),this._onDidMaximizedNodeChange.dispose(),this._onDidViewVisibilityChange.dispose(),this.root.dispose(),this._maximizedNode=void 0,this.element.remove()}clear(){let e=this.root.orientation;this.root=new EG(e,this.proportionalLayout,this.styles,this.root.size,this.root.orthogonalSize,this.locked,this.margin)}deserialize(e,t){let n=e.orientation,r=n===`VERTICAL`?e.height:e.width;if(this._deserialize(e.root,n,t,r),this.layout(e.width,e.height),e.maximizedNode){let t=e.maximizedNode.location,[n,r]=this.getNode(t);if(!(r instanceof TG))return;this.maximizeView(r.view)}}_deserialize(e,t,n,r){this.root=this._deserializeNode(e,t,n,r)}_deserializeNode(e,t,n,r){let i;if(e.type===`branch`){let a=e.data.map(r=>({node:this._deserializeNode(r,IG(t),n,e.size),visible:r.visible}));i=new EG(t,this.proportionalLayout,this.styles,e.size,r,this.locked,this.margin,a)}else{let o=n.fromJSON(e);if(typeof e.visible==`boolean`){var a;(a=o.setVisible)==null||a.call(o,e.visible)}i=new TG(o,t,r,e.size)}return i}get root(){return this._root}set root(e){let t=this._root;t&&(t.dispose(),this._maximizedNode=void 0,t.element.remove()),this._root=e,this.element.appendChild(this._root.element),this.disposable.value=this._root.onDidChange(e=>{this._onDidChange.fire(e)})}normalize(){if(!this._root||this._root.children.length!==1)return;let e=this.root,t=e.children[0];if(t instanceof TG)return;e.element.remove();let n=e.removeChild(0);e.dispose(),n.dispose(),this._root=kG(t,t.size,t.orthogonalSize),this.element.appendChild(this._root.element),this.disposable.value=this._root.onDidChange(e=>{this._onDidChange.fire(e)})}insertOrthogonalSplitviewAtRoot(){if(!this._root)return;let e=this.root;if(e.element.remove(),this._root=new EG(IG(e.orientation),this.proportionalLayout,this.styles,this.root.orthogonalSize,this.root.size,this.locked,this.margin),e.children.length!==0){if(e.children.length===1){let t=e.children[0];e.removeChild(0).dispose(),e.dispose(),this._root.addChild(AG(t,t.orthogonalSize,t.size),xG.Distribute,0)}else this._root.addChild(e,xG.Distribute,0)}this.element.appendChild(this._root.element),this.disposable.value=this._root.onDidChange(e=>{this._onDidChange.fire(e)})}next(e){return this.progmaticSelect(e)}previous(e){return this.progmaticSelect(e,!0)}getView(e){let t=e?this.getNode(e)[1]:this.root;return this._getViews(t,this.orientation)}_getViews(e,t,n){let r={height:e.height,width:e.width};if(e instanceof TG)return{box:r,view:e.view,cachedVisibleSize:n};let i=[];for(let n=0;n<e.children.length;n++){let r=e.children[n],a=e.getChildCachedVisibleSize(n);i.push(this._getViews(r,IG(t),a))}return{box:r,children:i,cachedVisibleSize:n}}progmaticSelect(e,t=!1){let[n,r]=this.getNode(e);if(!(r instanceof TG))throw TypeError(`invalid location`);for(let r=n.length-1;r>-1;r--){let i=n[r],a=e[r]||0;if(t?a-1>-1:a+1<i.children.length)return DG(i.children[t?a-1:a+1],t)}return DG(this.root,t)}get proportionalLayout(){return this.root.proportionalLayout}set proportionalLayout(e){this.root.proportionalLayout=e}constructor(e,t,n,r,i){this.styles=t,this._locked=!1,this._margin=0,this._maximizedNode=void 0,this.disposable=new gW,this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this._onDidViewVisibilityChange=new X,this.onDidViewVisibilityChange=this._onDidViewVisibilityChange.event,this._onDidMaximizedNodeChange=new X,this.onDidMaximizedNodeChange=this._onDidMaximizedNodeChange.event,this.element=document.createElement(`div`),this.element.className=`dv-grid-view`,this._locked=r??!1,this._margin=i??0,this.root=new EG(n,e,t,0,0,this.locked,this.margin)}isViewVisible(e){let[t,n]=lG(e),[,r]=this.getNode(t);if(!(r instanceof EG))throw TypeError(`Invalid from location`);return r.isChildVisible(n)}setViewVisible(e,t){this.hasMaximizedView()&&this.exitMaximizedView();let[n,r]=lG(e),[,i]=this.getNode(n);if(!(i instanceof EG))throw TypeError(`Invalid from location`);this._onDidViewVisibilityChange.fire(),i.setChildVisible(r,t)}moveView(e,t,n){this.hasMaximizedView()&&this.exitMaximizedView();let[,r]=this.getNode(e);if(!(r instanceof EG))throw TypeError(`Invalid location`);r.moveChild(t,n)}addView(e,t,n){this.hasMaximizedView()&&this.exitMaximizedView();let[r,i]=lG(n),[a,o]=this.getNode(r);if(o instanceof EG){let n=new TG(e,IG(o.orientation),o.orthogonalSize);o.addChild(n,t,i)}else{let[n,...s]=[...a].reverse(),[c,...l]=[...r].reverse(),u=0,d=n.getChildCachedVisibleSize(c);typeof d==`number`&&(u=xG.Invisible(d)),n.removeChild(c).dispose();let f=new EG(o.orientation,this.proportionalLayout,this.styles,o.size,o.orthogonalSize,this.locked,this.margin);n.addChild(f,o.size,c);let p=new TG(o.view,n.orientation,o.size);f.addChild(p,u,0),typeof t!=`number`&&t.type===`split`&&(t={type:`split`,index:0});let m=new TG(e,n.orientation,o.size);f.addChild(m,t,i)}}remove(e,t){let n=MG(e.element);return this.removeView(n,t)}removeView(e,t){this.hasMaximizedView()&&this.exitMaximizedView();let[n,r]=lG(e),[i,a]=this.getNode(n);if(!(a instanceof EG))throw TypeError(`Invalid location`);let o=a.children[r];if(!(o instanceof TG))throw TypeError(`Invalid location`);if(a.removeChild(r,t),o.dispose(),a.children.length!==1)return o.view;let s=a.children[0];if(i.length===0)return s instanceof TG||(a.removeChild(0,t),this.root=s),o.view;let[c,...l]=[...i].reverse(),[u,...d]=[...n].reverse(),f=a.isChildVisible(0);a.removeChild(0,t);let p=c.children.map((e,t)=>c.getChildSize(t));if(c.removeChild(u,t).dispose(),s instanceof EG){let e=s.children.map(e=>e instanceof EG?e.orthogonalSize:e.size);p.splice(u,1,...e);for(let t=0;t<s.children.length;t++){let n=s.children[t],r=OG(s,t,e[t]);c.addChild(n,!f&&typeof r==`number`?xG.Invisible(r):r,u+t)}for(;s.children.length>0;)s.removeChild(0)}else{let e=new TG(s.view,IG(s.orientation),s.size),t=f?s.orthogonalSize:xG.Invisible(s.orthogonalSize);c.addChild(e,t,u)}s.dispose();for(let e=0;e<p.length;e++)c.resizeChild(e,p[e]);return o.view}layout(e,t){let[n,r]=this.root.orientation===`HORIZONTAL`?[t,e]:[e,t];this.root.layout(n,r)}getNode(e,t=this.root,n=[]){if(e.length===0)return[n,t];if(!(t instanceof EG))throw TypeError(`Invalid location`);let[r,...i]=e;if(r<0||r>=t.children.length)throw Error(`Invalid location`);let a=t.children[r];return n.push(t),this.getNode(i,a,n)}},BG=Object.keys({disableAutoResizing:void 0,proportionalLayout:void 0,orientation:void 0,hideBorders:void 0,className:void 0}),VG=class extends Y{get element(){return this._element}get disableResizing(){return this._disableResizing}set disableResizing(e){this._disableResizing=e}constructor(e,t=!1){super(),this._lastWidth=-1,this._lastHeight=-1,this._disableResizing=t,this._element=e,this.addDisposables(TW(this._element,e=>{if(this.isDisposed||this.disableResizing||!this._element.offsetParent||!zW(this._element))return;let t=Math.round(e.contentRect.width),n=Math.round(e.contentRect.height);(t!==this._lastWidth||n!==this._lastHeight)&&(this._lastWidth=t,this._lastHeight=n,this.layout(t,n))}))}layoutFromElement(){if(this.disableResizing||!this._element.offsetParent||!zW(this._element))return;let e=Math.round(this._element.clientWidth),t=Math.round(this._element.clientHeight);e!==0&&t!==0&&this.layout(e,t)}},HG=gG();function UG(e){switch(e){case`left`:return`left`;case`right`:return`right`;case`above`:return`top`;case`below`:return`bottom`;default:return`center`}}var WG=class extends VG{get id(){return this._id}get size(){return this._groups.size}get groups(){return Array.from(this._groups.values()).map(e=>e.value)}get width(){return this.gridview.width}get height(){return this.gridview.height}get minimumHeight(){return this.gridview.minimumHeight}get maximumHeight(){return this.gridview.maximumHeight}get minimumWidth(){return this.gridview.minimumWidth}get maximumWidth(){return this.gridview.maximumWidth}get activeGroup(){return this._activeGroup}get locked(){return this.gridview.locked}set locked(e){this.gridview.locked=e}constructor(e,t){super(document.createElement(`div`),t.disableAutoResizing),this._id=HG.next(),this._groups=new Map,this._onDidRemove=new X,this.onDidRemove=this._onDidRemove.event,this._onDidAdd=new X,this.onDidAdd=this._onDidAdd.event,this._onDidMaximizedChange=new X,this.onDidMaximizedChange=this._onDidMaximizedChange.event,this._onDidActiveChange=new X,this.onDidActiveChange=this._onDidActiveChange.event,this._bufferOnDidLayoutChange=new CW,this.onDidLayoutChange=_W.map(this._bufferOnDidLayoutChange.onEvent,e=>({reasons:e})),this._onDidViewVisibilityChangeMicroTaskQueue=new CW,this.onDidViewVisibilityChangeMicroTaskQueue=this._onDidViewVisibilityChangeMicroTaskQueue.onEvent,this.element.style.height=`100%`,this.element.style.width=`100%`,this._classNames=new qW(this.element),this._classNames.setClassNames(t.className??``),e.appendChild(this.element),this.gridview=new zG(!!t.proportionalLayout,t.styles,t.orientation,t.locked,t.margin),this.gridview.locked=!!t.locked,this.element.appendChild(this.gridview.element),this.layout(0,0,!0),this.addDisposables(this.gridview.onDidMaximizedNodeChange(e=>{this._onDidMaximizedChange.fire({panel:e.view,isMaximized:e.isMaximized})}),this.gridview.onDidViewVisibilityChange(()=>this._onDidViewVisibilityChangeMicroTaskQueue.fire()),this.onDidViewVisibilityChangeMicroTaskQueue(()=>{this.forceRelayout()}),hW.from(()=>{this.element.remove()}),this.gridview.onDidChange(()=>{this._bufferOnDidLayoutChange.fire(`geometry`)}),_W.any(this.onDidAdd,this.onDidRemove)(()=>{this._bufferOnDidLayoutChange.fire(`structure`)}),this.onDidActiveChange(()=>{this._bufferOnDidLayoutChange.fire(`activePanel`)}),this.onDidMaximizedChange(()=>{this._bufferOnDidLayoutChange.fire(`geometry`)}),this._onDidMaximizedChange,this._onDidViewVisibilityChangeMicroTaskQueue,this._bufferOnDidLayoutChange)}setVisible(e,t){this.gridview.setViewVisible(MG(e.element),t),this._bufferOnDidLayoutChange.fire(`geometry`)}isVisible(e){return this.gridview.isViewVisible(MG(e.element))}updateOptions(e){`proportionalLayout`in e&&(this.gridview.proportionalLayout=e.proportionalLayout??!0),e.orientation&&(this.gridview.orientation=e.orientation),`styles`in e,`disableAutoResizing`in e&&(this.disableResizing=e.disableAutoResizing??!1),`locked`in e&&(this.locked=e.locked??!1),`margin`in e&&(this.gridview.margin=e.margin??0),`className`in e&&this._classNames.setClassNames(e.className??``)}maximizeGroup(e){this.gridview.maximizeView(e),this.doSetGroupActive(e)}isMaximizedGroup(e){return this.gridview.maximizedView()===e}exitMaximizedGroup(){this.gridview.exitMaximizedView()}hasMaximizedGroup(){return this.gridview.hasMaximizedView()}doAddGroup(e,t=[0],n,r=this.gridview){r.addView(e,n??xG.Distribute,t),this._onDidAdd.fire(e)}doRemoveGroup(e,t){if(!this._groups.has(e.id))throw Error(`invalid operation`);let n=this._groups.get(e.id),r=this.gridview.remove(e,xG.Distribute);if(n&&!t?.skipDispose&&(n.disposable.dispose(),n.value.dispose(),this._groups.delete(e.id),this._onDidRemove.fire(e)),!t?.skipActive&&this._activeGroup===e){let e=Array.from(this._groups.values());this.doSetGroupActive(e.length>0?e[0].value:void 0)}return r}getPanel(e){return this._groups.get(e)?.value}doSetGroupActive(e){this._activeGroup!==e&&(this._activeGroup&&this._activeGroup.setActive(!1),e&&e.setActive(!0),this._activeGroup=e,this._onDidActiveChange.fire(e))}removeGroup(e){this.doRemoveGroup(e)}activateNext(e){if(e??={},!e.group){if(!this.activeGroup)return;e.group=this.activeGroup}let t=MG(e.group.element),n=this.gridview.next(t)?.view;this.doSetGroupActive(n)}activatePrevious(e){if(e??={},!e.group){if(!this.activeGroup)return;e.group=this.activeGroup}let t=MG(e.group.element),n=this.gridview.previous(t)?.view;this.doSetGroupActive(n)}forceRelayout(){this.layout(this.width,this.height,!0)}layout(e,t,n){(n||e!==this.width||t!==this.height)&&(this.gridview.element.style.height=`${t}px`,this.gridview.element.style.width=`${e}px`,this.gridview.layout(e,t))}dispose(){this._onDidActiveChange.dispose(),this._onDidAdd.dispose(),this._onDidRemove.dispose();for(let e of this.groups)e.dispose();this.gridview.dispose(),super.dispose()}};function GG(e){"@babel/helpers - typeof";return GG=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},GG(e)}function KG(e,t){if(GG(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(GG(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function qG(e){var t=KG(e,`string`);return GG(t)==`symbol`?t:t+``}function JG(e,t,n){return(t=qG(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function YG(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function $(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?YG(Object(n),!0).forEach(function(t){JG(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):YG(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function XG(e,t){return e===`center`?`Tab into ${t}`:`Split ${e} of ${t}`}function ZG(e,t){return e===`center`?`docked into ${t}`:`split ${e} of ${t}`}var QG={panelOpened:e=>`${e} opened`,panelClosed:e=>`${e} closed`,groupMaximized:e=>`${e} maximized`,groupRestored:e=>`${e} restored`,groupFloated:e=>`${e} floated`,groupDocked:e=>`${e} docked`,groupPoppedOut:e=>`${e} opened in a new window`,closeTab:e=>`Close ${e}`,closeTabPlain:()=>`Close`,movePickTarget:(e,t,n,r)=>`Moving ${e}. Target ${t}, ${n} of ${r}. Enter to choose where, Escape to cancel.`,movePickEdge:(e,t)=>`${XG(e,t)}. Arrows to change, Enter to confirm, Escape to go back.`,moveCommitted:(e,t,n)=>`${e} ${ZG(n,t)}.`,moveCancelled:()=>`Move cancelled.`,moveNotAllowed:()=>`That move is not allowed.`,moveFloated:e=>`${e} floated.`};function $G(e){return e?$($({},QG),e):QG}var eK=class{get minimumSize(){return this.component.minimumSize}get maximumSize(){return this.component.maximumSize}get width(){return this.component.width}get height(){return this.component.height}get length(){return this.component.length}get orientation(){return this.component.orientation}get panels(){return this.component.panels}get onDidLayoutFromJSON(){return this.component.onDidLayoutFromJSON}get onDidLayoutChange(){return this.component.onDidLayoutChange}get onDidAddView(){return this.component.onDidAddView}get onDidRemoveView(){return this.component.onDidRemoveView}constructor(e){this.component=e}removePanel(e,t){this.component.removePanel(e,t)}focus(){this.component.focus()}getPanel(e){return this.component.getPanel(e)}layout(e,t){return this.component.layout(e,t)}addPanel(e){return this.component.addPanel(e)}movePanel(e,t){this.component.movePanel(e,t)}fromJSON(e){this.component.fromJSON(e)}toJSON(){return this.component.toJSON()}clear(){this.component.clear()}updateOptions(e){this.component.updateOptions(e)}dispose(){this.component.dispose()}},tK=class{get minimumSize(){return this.component.minimumSize}get maximumSize(){return this.component.maximumSize}get width(){return this.component.width}get height(){return this.component.height}get panels(){return this.component.panels}get onDidLayoutChange(){return this.component.onDidLayoutChange}get onDidLayoutFromJSON(){return this.component.onDidLayoutFromJSON}get onDidAddView(){return this.component.onDidAddView}get onDidRemoveView(){return this.component.onDidRemoveView}get onDidDrop(){return this.component.onDidDrop}get onUnhandledDragOver(){return this.component.onUnhandledDragOver}constructor(e){this.component=e}removePanel(e){this.component.removePanel(e)}getPanel(e){return this.component.getPanel(e)}movePanel(e,t){this.component.movePanel(e,t)}focus(){this.component.focus()}layout(e,t){this.component.layout(e,t)}addPanel(e){return this.component.addPanel(e)}fromJSON(e){this.component.fromJSON(e)}toJSON(){return this.component.toJSON()}clear(){this.component.clear()}updateOptions(e){this.component.updateOptions(e)}dispose(){this.component.dispose()}},nK=class{get width(){return this.component.width}get height(){return this.component.height}get minimumHeight(){return this.component.minimumHeight}get maximumHeight(){return this.component.maximumHeight}get minimumWidth(){return this.component.minimumWidth}get maximumWidth(){return this.component.maximumWidth}get onDidLayoutChange(){return this.component.onDidLayoutChange}get onDidAddPanel(){return this.component.onDidAddGroup}get onDidRemovePanel(){return this.component.onDidRemoveGroup}get onDidActivePanelChange(){return this.component.onDidActiveGroupChange}get onDidLayoutFromJSON(){return this.component.onDidLayoutFromJSON}get panels(){return this.component.groups}get orientation(){return this.component.orientation}set orientation(e){this.component.updateOptions({orientation:e})}constructor(e){this.component=e}focus(){this.component.focus()}layout(e,t,n=!1){this.component.layout(e,t,n)}addPanel(e){return this.component.addPanel(e)}removePanel(e,t){this.component.removePanel(e,t)}movePanel(e,t){this.component.movePanel(e,t)}getPanel(e){return this.component.getPanel(e)}fromJSON(e){return this.component.fromJSON(e)}toJSON(){return this.component.toJSON()}clear(){this.component.clear()}updateOptions(e){this.component.updateOptions(e)}dispose(){this.component.dispose()}},rK=class{get id(){return this.component.id}get width(){return this.component.width}get height(){return this.component.height}get minimumHeight(){return this.component.minimumHeight}get maximumHeight(){return this.component.maximumHeight}get minimumWidth(){return this.component.minimumWidth}get maximumWidth(){return this.component.maximumWidth}get size(){return this.component.size}get tabGroupColors(){return this.component.tabGroupColorPalette.entries()}get totalPanels(){return this.component.totalPanels}get onDidActiveGroupChange(){return this.component.onDidActiveGroupChange}get onDidAddGroup(){return this.component.onDidAddGroup}get onDidRemoveGroup(){return this.component.onDidRemoveGroup}get onDidActivePanelChange(){return this.component.onDidActivePanelChange}get onDidPanelPinnedChange(){return this.component.onDidPanelPinnedChange}get onDidAddPanel(){return this.component.onDidAddPanel}get onDidRemovePanel(){return this.component.onDidRemovePanel}get onDidMovePanel(){return this.component.onDidMovePanel}get onDidLayoutFromJSON(){return this.component.onDidLayoutFromJSON}get onDidLayoutChange(){return this.component.onDidLayoutChange}get onDidDrop(){return this.component.onDidDrop}get onWillDrop(){return this.component.onWillDrop}get onWillMutateLayout(){return this.component.onWillMutateLayout}get onDidMutateLayout(){return this.component.onDidMutateLayout}get onWillShowOverlay(){return this.component.onWillShowOverlay}get onWillDragGroup(){return this.component.onWillDragGroup}get onWillDragPanel(){return this.component.onWillDragPanel}get onUnhandledDragOver(){return this.component.onUnhandledDragOver}get dndCapabilities(){return this.component.dndCapabilities}get onDidPopoutGroupSizeChange(){return this.component.onDidPopoutGroupSizeChange}get onDidPopoutGroupPositionChange(){return this.component.onDidPopoutGroupPositionChange}get onDidAddPopoutGroup(){return this.component.onDidAddPopoutGroup}get onDidRemovePopoutGroup(){return this.component.onDidRemovePopoutGroup}get onDidOpenPopoutWindowFail(){return this.component.onDidOpenPopoutWindowFail}get onWillClosePopoutWindow(){return this.component.onWillClosePopoutWindow}getPopouts(){return this.component.getPopouts()}get onDidCreateTabGroup(){return this.component.onDidCreateTabGroup}get onDidDestroyTabGroup(){return this.component.onDidDestroyTabGroup}get onDidAddPanelToTabGroup(){return this.component.onDidAddPanelToTabGroup}get onDidRemovePanelFromTabGroup(){return this.component.onDidRemovePanelFromTabGroup}get onDidTabGroupChange(){return this.component.onDidTabGroupChange}get onDidTabGroupCollapsedChange(){return this.component.onDidTabGroupCollapsedChange}get panels(){return this.component.panels}get groups(){return this.component.groups}adjacentGroupInDirection(e,t){return this.component.adjacentGroupInDirection(e,t)}get activePanel(){return this.component.activePanel}get activeGroup(){return this.component.activeGroup}get messages(){return $G(this.component.options.messages)}constructor(e){this.component=e}focus(){this.component.focus()}getPanel(e){return this.component.getGroupPanel(e)}layout(e,t,n=!1){this.component.layout(e,t,n)}addPanel(e){return this.component.withOrigin(`api`,()=>this.component.addPanel(e))}removePanel(e,t){this.component.withOrigin(`api`,()=>this.component.removePanel(e,t))}addGroup(e){return this.component.withOrigin(`api`,()=>this.component.addGroup(e))}serializeGroup(e){return this.component.serializeGroup(e)}addGroupFromJSON(e,t){return this.component.withOrigin(`api`,()=>this.component.addGroupFromJSON(e,t))}addPanelFromJSON(e,t){return this.component.withOrigin(`api`,()=>this.component.addPanelFromJSON(e,t))}closeAllGroups(){return this.component.withOrigin(`api`,()=>this.component.closeAllGroups())}removeGroup(e){this.component.withOrigin(`api`,()=>this.component.removeGroup(e))}getGroup(e){return this.component.getPanel(e)}addFloatingGroup(e,t){return this.component.withOrigin(`api`,()=>this.component.addFloatingGroup(e,t))}fromJSON(e,t){this.component.withOrigin(`api`,()=>this.component.fromJSON(e,t))}toJSON(){return this.component.toJSON()}clear(){this.component.withOrigin(`api`,()=>this.component.clear())}undo(){this.component.undo()}redo(){this.component.redo()}get canUndo(){return this.component.canUndo}get canRedo(){return this.component.canRedo}clearHistory(){this.component.clearHistory()}get onDidChangeHistory(){return this.component.onDidChangeHistory}get smartGuidesEnabled(){return this.component.smartGuidesEnabled}setSmartGuidesEnabled(e){this.component.setSmartGuidesEnabled(e)}updateSmartGuidesOptions(e){this.component.updateSmartGuidesOptions(e)}get onDidSnapFloat(){return this.component.onDidSnapFloat}get onDidSnapTogether(){return this.component.onDidSnapTogether}get popoutRestorationPromise(){return this.component.popoutRestorationPromise}activateNext(e){this.component.activateNext(e)}activatePrevious(e){this.component.activatePrevious(e)}moveToNext(e){this.activateNext(e)}moveToPrevious(e){this.activatePrevious(e)}maximizeGroup(e){this.component.withOrigin(`api`,()=>this.component.maximizeGroup(e.group))}hasMaximizedGroup(){return this.component.hasMaximizedGroup()}exitMaximizedGroup(){this.component.withOrigin(`api`,()=>this.component.exitMaximizedGroup())}get onDidMaximizedGroupChange(){return this.component.onDidMaximizedGroupChange}addPopoutGroup(e,t){return this.component.withOrigin(`api`,()=>this.component.addPopoutGroup(e,t))}addEdgeGroup(e,t){return this.component.addEdgeGroup(e,t)}revealEdgeGroupWithData(e,t,n){this.component.revealEdgeGroupWithData(e,t,n)}getEdgeGroup(e){return this.component.getEdgeGroup(e)}setEdgeGroupVisible(e,t){this.component.setEdgeGroupVisible(e,t)}isEdgeGroupVisible(e){return this.component.isEdgeGroupVisible(e)}removeEdgeGroup(e){this.component.removeEdgeGroup(e)}pinEdgeGroup(e){this.component.pinEdgeGroup(e)}autoHideEdgeGroup(e){this.component.autoHideEdgeGroup(e)}peekEdgeGroup(e,t){this.component.peekEdgeGroup(e,t)}updateOptions(e){this.component.updateOptions(e)}_getGroupModel(e){let t=this.component.getPanel(e);if(!t)throw Error(`dockview: group '${e}' not found`);return t.model}createTabGroup(e){let t=this._getGroupModel(e.groupId);return this.component.withOrigin(`api`,()=>t.createTabGroup({label:e.label,color:e.color,componentParams:e.componentParams}))}dissolveTabGroup(e){let t=this._getGroupModel(e.groupId);this.component.withOrigin(`api`,()=>t.dissolveTabGroup(e.tabGroupId))}addPanelToTabGroup(e){let t=this._getGroupModel(e.groupId);this.component.withOrigin(`api`,()=>t.addPanelToTabGroup(e.tabGroupId,e.panelId,e.index))}removePanelFromTabGroup(e){let t=this._getGroupModel(e.groupId);this.component.withOrigin(`api`,()=>t.removePanelFromTabGroup(e.panelId))}getTabGroups(e){return this._getGroupModel(e.groupId).getTabGroups()}getTabGroupForPanel(e){return this._getGroupModel(e.groupId).getTabGroupForPanel(e.panelId)}moveTabGroup(e){this._getGroupModel(e.groupId).moveTabGroup(e.tabGroupId,e.index)}dispose(){this.component.dispose()}},iK=class extends Y{constructor(e,t){super(),this.element=e,this.callbacks=t,this.target=null,this.registerListeners()}onDragEnter(e){this.target=e.target,this.callbacks.onDragEnter(e)}onDragOver(e){e.preventDefault(),this.callbacks.onDragOver&&this.callbacks.onDragOver(e)}onDragLeave(e){this.target===e.target&&(this.target=null,this.callbacks.onDragLeave(e))}onDragEnd(e){this.target=null,this.callbacks.onDragEnd(e)}onDrop(e){this.callbacks.onDrop(e)}registerListeners(){this.addDisposables(Z(this.element,`dragenter`,e=>{this.onDragEnter(e)},!0)),this.addDisposables(Z(this.element,`dragover`,e=>{this.onDragOver(e)},!0)),this.addDisposables(Z(this.element,`dragleave`,e=>{this.onDragLeave(e)})),this.addDisposables(Z(this.element,`dragend`,e=>{this.onDragEnd(e)})),this.addDisposables(Z(this.element,`drop`,e=>{this.onDrop(e)}))}},aK={value:50,type:`percentage`},oK=100,sK=100;function cK(){let e=document.createElement(`div`);e.className=`dv-drop-target-dropzone`;let t=document.createElement(`div`);return t.className=`dv-drop-target-selection`,e.appendChild(t),{dropzone:e,selection:t}}function lK(e,t,n,r){let i=r?.smallWidthBoundary??oK,a=r?.smallHeightBoundary??sK,o=t<i,s=n<a,c=e===`left`,l=e===`right`,u=e===`top`,d=e===`bottom`,f=!o&&l,p=!o&&c,m=!s&&u,h=!s&&d,g=1,_=r?.size??aK;return _.type===`percentage`?g=hG(_.value,0,100)/100:((f||p)&&(g=hG(_.value,0,t)/t),(m||h)&&(g=hG(_.value,0,n)/n)),{isSmallX:o,isSmallY:s,isLeft:c,isRight:l,isTop:u,isBottom:d,rightClass:f,leftClass:p,topClass:m,bottomClass:h,size:g}}function uK(e,t,n,r,i){let a=lK(t,n,r,i),{rightClass:o,leftClass:s,topClass:c,bottomClass:l,size:u}=a,d={top:`0px`,left:`0px`,width:`100%`,height:`100%`};o?(d.left=`${100*(1-u)}%`,d.width=`${100*u}%`):s?d.width=`${100*u}%`:c?d.height=`${100*u}%`:l&&(d.top=`${100*(1-u)}%`,d.height=`${100*u}%`),a.isSmallX&&a.isLeft&&(d.width=`4px`),a.isSmallX&&a.isRight&&(d.left=`${n-4}px`,d.width=`4px`),a.isSmallY&&a.isTop&&(d.height=`4px`),a.isSmallY&&a.isBottom&&(d.top=`${r-4}px`,d.height=`4px`),e.style.top=d.top,e.style.left=d.left,e.style.width=d.width,e.style.height=d.height,e.style.visibility=`visible`,e.style.transform&&e.style.transform!==``||(e.style.transform=`translate3d(0, 0, 0)`);let f=a.isSmallX&&(a.isLeft||a.isRight)||a.isSmallY&&(a.isTop||a.isBottom);Q(e,`dv-drop-target-small-vertical`,a.isSmallY),Q(e,`dv-drop-target-small-horizontal`,a.isSmallX),Q(e,`dv-drop-target-selection-line`,f),Q(e,`dv-drop-target-left`,a.isLeft),Q(e,`dv-drop-target-right`,a.isRight),Q(e,`dv-drop-target-top`,a.isTop),Q(e,`dv-drop-target-bottom`,a.isBottom),Q(e,`dv-drop-target-center`,t===`center`)}function dK(e,t){let n=`${Math.round(t.top)}px`,r=`${Math.round(t.left)}px`,i=`${Math.round(t.width)}px`,a=`${Math.round(t.height)}px`;return e.style.top!==n||e.style.left!==r||e.style.width!==i||e.style.height!==a}function fK(e,t){e.style.top=`${Math.round(t.top)}px`,e.style.left=`${Math.round(t.left)}px`,e.style.width=`${Math.round(t.width)}px`,e.style.height=`${Math.round(t.height)}px`,e.style.visibility=`visible`,e.style.transform&&e.style.transform!==``||(e.style.transform=`translate3d(0, 0, 0)`)}function pK(e){let t=lK(e.quadrant,e.width,e.height,e.overlayModel),{rightClass:n,leftClass:r,topClass:i,bottomClass:a,size:o}=t,s=e.outlineElement.getBoundingClientRect(),c=e.targetModel.getElements(void 0,e.outlineElement),l=c.root,u=c.overlay,d=l.getBoundingClientRect(),f=s.top-d.top,p=s.left-d.left,m={top:f,left:p,width:e.width,height:e.height};return n?(m.left=p+e.width*(1-o),m.width=e.width*o):r?m.width=e.width*o:i?m.height=e.height*o:a&&(m.top=f+e.height*(1-o),m.height=e.height*o),t.isSmallX&&t.isLeft&&(m.width=4),t.isSmallX&&t.isRight&&(m.left=p+e.width-4,m.width=4),t.isSmallY&&t.isTop&&(m.height=4),t.isSmallY&&t.isBottom&&(m.top=f+e.height-4,m.height=4),dK(u,m)?(fK(u,m),u.className=`dv-drop-target-anchor${e.className?` ${e.className}`:``}`,Q(u,`dv-drop-target-left`,t.isLeft),Q(u,`dv-drop-target-right`,t.isRight),Q(u,`dv-drop-target-top`,t.isTop),Q(u,`dv-drop-target-bottom`,t.isBottom),Q(u,`dv-drop-target-anchor-line`,t.isSmallX&&(t.isLeft||t.isRight)||t.isSmallY&&(t.isTop||t.isBottom)),Q(u,`dv-drop-target-center`,e.quadrant===`center`),c.changed&&(Q(u,`dv-drop-target-anchor-container-changed`,!0),setTimeout(()=>{Q(u,`dv-drop-target-anchor-container-changed`,!1)},10)),{boundsChanged:!0,targetChanged:c.changed}):{boundsChanged:!1,targetChanged:c.changed}}var mK=class extends vW{get nativeEvent(){return this.options.nativeEvent}get position(){return this.options.position}get edge(){return!!this.options.edge}get edgeGroup(){return!!this.options.edgeGroup}constructor(e){super(),this.options=e}};function hK(e){switch(e){case`above`:return`top`;case`below`:return`bottom`;case`left`:return`left`;case`right`:return`right`;case`within`:return`center`;default:throw Error(`invalid direction '${e}'`)}}function gK(e){switch(e){case`top`:return`above`;case`bottom`:return`below`;case`left`:return`left`;case`right`:return`right`;case`center`:return`within`;default:throw Error(`invalid position '${e}'`)}}var _K={value:20,type:`percentage`},vK=class e extends Y{get disabled(){return this._disabled}set disabled(e){this._disabled=e}get state(){return this._state}constructor(t,n){super(),this.element=t,this.options=n,this._edge=!1,this._onDrop=new X,this.onDrop=this._onDrop.event,this._onWillShowOverlay=new X,this.onWillShowOverlay=this._onWillShowOverlay.event,this._disabled=!1,this._acceptedTargetZonesSet=new Set(this.options.acceptedTargetZones),this.dnd=new iK(this.element,{onDragEnter:()=>{var e,t;(e=(t=this.options).getOverrideTarget)==null||(e=e.call(t))==null||e.getElements()},onDragOver:t=>{var n,r;if(this._disabled){this.clearOwnOverlay();return}e.ACTUAL_TARGET=this;let i=(n=this.options).getOverrideTarget?.call(n);if(this._acceptedTargetZonesSet.size===0){this.clearOwnOverlay();return}let a=(r=this.options).getOverlayOutline?.call(r)??this.element,o=a.offsetWidth,s=a.offsetHeight;if(o===0||s===0)return;let c=a.getBoundingClientRect(),l=(t.clientX??0)-c.left,u=(t.clientY??0)-c.top,d=this.resolvePosition(l,u,o,s,t);if(this.isAlreadyUsed(t)){this.removeDropTarget();return}if(d===null){this.clearOwnOverlay();return}let f=d.position;if(!this.options.canDisplayOverlay(t,f)){this.clearOwnOverlay();return}let p=new mK({nativeEvent:t,position:f,edge:d.edge,edgeGroup:d.edgeGroup});if(this._onWillShowOverlay.fire(p),p.defaultPrevented)this.clearOwnOverlay();else if(this.markAsUsed(t),d.edge)this.clearOwnOverlay(),this._state=f,this._edge=!0;else{if(this._edge=!1,!i&&!this.targetElement){let e=cK();this.targetElement=e.dropzone,this.overlayElement=e.selection,this._state=`center`,a.classList.add(`dv-drop-target`),a.append(this.targetElement)}this.toggleClasses(f,o,s),this._state=f}},onDragLeave:()=>{var e;let t=(e=this.options).getOverrideTarget?.call(e);if(t){var n;this._state=void 0,this._edge=!1,(n=t.scheduleClear)==null||n.call(t)}else this.removeDropTarget()},onDragEnd:t=>{var n;let r=(n=this.options).getOverrideTarget?.call(n);r&&e.ACTUAL_TARGET===this&&this._state&&(t.stopPropagation(),this._onDrop.fire({position:this._state,nativeEvent:t,edge:this._edge})),this.removeDropTarget(),r?.clear()},onDrop:e=>{var t,n;e.preventDefault();let r=this._state,i=this._edge;this.removeDropTarget(),(t=(n=this.options).getOverrideTarget)==null||(t=t.call(n))==null||t.clear(),r&&(e.stopPropagation(),this._onDrop.fire({position:r,nativeEvent:e,edge:i}))}}),this.addDisposables(this._onDrop,this._onWillShowOverlay,this.dnd)}setTargetZones(e){this._acceptedTargetZonesSet=new Set(e)}setOverlayModel(e){this.options.overlayModel=e}dispose(){this.removeDropTarget(),super.dispose()}markAsUsed(t){t[e.USED_EVENT_ID]=!0}isAlreadyUsed(t){let n=t[e.USED_EVENT_ID];return typeof n==`boolean`&&n}toggleClasses(e,t,n){var r;let i=(r=this.options).getOverrideTarget?.call(r);if(i){var a;pK({outlineElement:(a=this.options).getOverlayOutline?.call(a)??this.element,targetModel:i,quadrant:e,width:t,height:n,overlayModel:this.options.overlayModel,className:this.options.className})}else this.overlayElement&&uK(this.overlayElement,e,t,n,this.options.overlayModel)}resolvePosition(e,t,n,r,i){var a;let o=(a=this.options).getPositionResolver?.call(a);if(o){let a=o.resolve({x:e,y:t,width:n,height:r,zones:this._acceptedTargetZonesSet,event:i});return a?{position:a.position,edge:!!a.edge,edgeGroup:!!a.edgeGroup}:null}let s=this.calculateQuadrant(this._acceptedTargetZonesSet,e,t,n,r);return s?{position:s,edge:!1,edgeGroup:!1}:null}calculateQuadrant(e,t,n,r,i){let a=this.options.overlayModel?.activationSize??_K;return a.type===`percentage`?yK(e,t,n,r,i,a.value):bK(e,t,n,r,i,a.value)}clearOwnOverlay(){let e=this._state!==void 0;if(this.removeDropTarget(),e){var t,n;(t=(n=this.options).getOverrideTarget)==null||(t=t.call(n))==null||t.clear()}}removeDropTarget(){if(this._state=void 0,this._edge=!1,this.targetElement){var e;(e=this.targetElement.parentElement)==null||e.classList.remove(`dv-drop-target`),this.targetElement.remove(),this.targetElement=void 0,this.overlayElement=void 0}}showOverlay(e){var t,n;let r=(t=this.options).getOverrideTarget?.call(t),i=(n=this.options).getOverlayOutline?.call(n)??this.element,a=i.offsetWidth,o=i.offsetHeight;if(!r&&!this.targetElement){let e=cK();this.targetElement=e.dropzone,this.overlayElement=e.selection,i.classList.add(`dv-drop-target`),i.append(this.targetElement)}this.toggleClasses(e,a,o),this._state=e}clearOverlay(){var e,t;this.removeDropTarget(),(e=(t=this.options).getOverrideTarget)==null||(e=e.call(t))==null||e.clear(),this._state=void 0}};vK.USED_EVENT_ID=`__dockview_droptarget_event_is_used__`;function yK(e,t,n,r,i,a){let o=100*t/r,s=100*n/i;return e.has(`left`)&&o<a?`left`:e.has(`right`)&&o>100-a?`right`:e.has(`top`)&&s<a?`top`:e.has(`bottom`)&&s>100-a?`bottom`:e.has(`center`)?`center`:null}function bK(e,t,n,r,i,a){return e.has(`left`)&&t<a?`left`:e.has(`right`)&&t>r-a?`right`:e.has(`top`)&&n<a?`top`:e.has(`bottom`)&&n>i-a?`bottom`:e.has(`center`)?`center`:null}function xK(e,t,n){DW(t,`dv-dragged`),t.style.top=`-9999px`,t.style.position=`absolute`,(n?.owner?tG(n.owner):(n?.ownerDocument??document).body).appendChild(t),e.setDragImage(t,n?.x??0,n?.y??0),setTimeout(()=>{EW(t,`dv-dragged`),t.remove()},0)}var SK=class e extends Y{static getInstance(){return e._instance??=new e,e._instance}constructor(){super(),this._targets=new Set,this._targetByElement=new Map,this._onDragStart=new X,this.onDragStart=this._onDragStart.event,this._onDragMove=new X,this.onDragMove=this._onDragMove.event,this._onDragEnd=new X,this.onDragEnd=this._onDragEnd.event,this.addDisposables(this._onDragStart,this._onDragMove,this._onDragEnd)}get active(){return this._active}registerTarget(e){return this._targets.add(e),this._targetByElement.set(e.element,e),{dispose:()=>{this._targets.delete(e),this._targetByElement.get(e.element)===e&&this._targetByElement.delete(e.element),this._currentTarget===e&&(this._currentTarget=void 0)}}}beginDrag(e){this._active&&this.cancel();let{pointerEvent:t,source:n}=e,r=e.getData();this._active={pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,source:n},this._lastPointerEvent=t,this._onDragMoveCallback=e.onDragMove,this._onDragEndCallback=e.onDragEnd,this._dataDisposable=r,this._ghost=e.ghost,this._iframeShield=WW(n.ownerDocument??document),this._selectionShield=GW(n.ownerDocument??document);let i={clientX:t.clientX,clientY:t.clientY,pointerEvent:t};this._onDragStart.fire(i);let a=n.ownerDocument?.defaultView??globalThis.window;this._moveListener=Z(a,`pointermove`,e=>{e.pointerId===this._active?.pointerId&&this._handleMove(e)}),this._upListener=Z(a,`pointerup`,e=>{e.pointerId===this._active?.pointerId&&this._handleEnd(e,!0)}),this._cancelListener=Z(a,`pointercancel`,e=>{e.pointerId===this._active?.pointerId&&this._handleEnd(e,!1)})}cancel(){var e,t;if(!this._active)return;let n=this._onDragEndCallback,r=this._lastPointerEvent;if((e=this._currentTarget)==null||e.handleDragLeave(),this._teardown(),(t=this._dataDisposable)==null||t.dispose(),this._dataDisposable=void 0,r){let e={clientX:r.clientX,clientY:r.clientY,pointerEvent:r};n?.(e,!1),this._onDragEnd.fire(e)}}_findTargetUnder(e,t){let n=(this._active?VW(this._active.source):document).elementsFromPoint(e,t);for(let e of n){let t=e;for(;t;){let e=this._targetByElement.get(t);if(e&&!e.isHitTestTransparent?.call(e))return e;t=t.parentElement}}}_handleMove(e){var t,n;this._lastPointerEvent=e,(t=this._ghost)==null||t.update(e.clientX,e.clientY);let r={clientX:e.clientX,clientY:e.clientY,pointerEvent:e},i=this._findTargetUnder(e.clientX,e.clientY);if(i!==this._currentTarget){var a;(a=this._currentTarget)==null||a.handleDragLeave(),this._currentTarget=i}i&&i.handleDragOver(r),(n=this._onDragMoveCallback)==null||n.call(this,r),this._onDragMove.fire(r)}_handleEnd(e,t){let n={clientX:e.clientX,clientY:e.clientY,pointerEvent:e};try{if(t&&this._currentTarget)this._currentTarget.handleDrop(n);else{var r;(r=this._currentTarget)==null||r.handleDragLeave()}}finally{let e=this._onDragEndCallback,r=this._dataDisposable;this._teardown(),this._dataDisposable=void 0,setTimeout(()=>r?.dispose(),0),e?.(n,t),this._onDragEnd.fire(n)}}_teardown(){var e,t,n,r,i,a;this._currentTarget=void 0,this._active=void 0,this._lastPointerEvent=void 0,this._onDragMoveCallback=void 0,this._onDragEndCallback=void 0,(e=this._ghost)==null||e.dispose(),this._ghost=void 0,(t=this._iframeShield)==null||t.release(),this._iframeShield=void 0,(n=this._selectionShield)==null||n.release(),this._selectionShield=void 0,(r=this._moveListener)==null||r.dispose(),(i=this._upListener)==null||i.dispose(),(a=this._cancelListener)==null||a.dispose(),this._moveListener=void 0,this._upListener=void 0,this._cancelListener=void 0}},CK={value:20,type:`percentage`},wK=class extends Y{get disabled(){return this._disabled}set disabled(e){this._disabled=e,e&&this._removeOverlay()}get state(){return this._state}constructor(e,t){super(),this.element=e,this.options=t,this._edge=!1,this._onDrop=new X,this.onDrop=this._onDrop.event,this._onWillShowOverlay=new X,this.onWillShowOverlay=this._onWillShowOverlay.event,this._disabled=!1,this._acceptedTargetZonesSet=new Set(t.acceptedTargetZones);let n={element:this.element,handleDragOver:e=>this._onDragOver(e),handleDragLeave:()=>this._onDragLeave(),handleDrop:e=>this._onDropEvent(e),isHitTestTransparent:t.isHitTestTransparent};this.addDisposables(this._onDrop,this._onWillShowOverlay,SK.getInstance().registerTarget(n))}clearOverlay(){this._clearOwnOverlay()}setTargetZones(e){this._acceptedTargetZonesSet=new Set(e)}setOverlayModel(e){this.options.overlayModel=e}dispose(){this._removeOverlay(),super.dispose()}_onDragOver(e){var t,n;if(this._disabled){this._clearOwnOverlay();return}let r=(t=this.options).getOverrideTarget?.call(t);if(this._acceptedTargetZonesSet.size===0){this._clearOwnOverlay();return}let i=(n=this.options).getOverlayOutline?.call(n)??this.element,a=i.offsetWidth,o=i.offsetHeight;if(a===0||o===0)return;let s=i.getBoundingClientRect(),c=e.clientX-s.left,l=e.clientY-s.top,u=this._resolvePosition(c,l,a,o,e.pointerEvent);if(u===null){this._clearOwnOverlay();return}let d=u.position;if(!this.options.canDisplayOverlay(e.pointerEvent,d)){this._clearOwnOverlay();return}let f=new mK({nativeEvent:e.pointerEvent,position:d,edge:u.edge,edgeGroup:u.edgeGroup});if(this._onWillShowOverlay.fire(f),f.defaultPrevented)this._clearOwnOverlay();else if(u.edge)this._clearOwnOverlay(),this._state=d,this._edge=!0;else if(this._edge=!1,r)pK({outlineElement:i,targetModel:r,quadrant:d,width:a,height:o,overlayModel:this.options.overlayModel,className:this.options.className}),this._state=d;else{if(!this._targetElement){let e=cK();this._targetElement=e.dropzone,this._overlayElement=e.selection,this._state=`center`,this.element.classList.add(`dv-drop-target`),this.element.append(this._targetElement)}this._overlayElement&&uK(this._overlayElement,d,a,o,this.options.overlayModel),this._state=d}}_onDragLeave(){var e;let t=(e=this.options).getOverrideTarget?.call(e);t?(this._state=void 0,t.clear()):this._removeOverlay()}_onDropEvent(e){var t;let n=this._state,r=this._edge,i=(t=this.options).getOverrideTarget?.call(t);this._removeOverlay(),i?.clear(),n&&this._onDrop.fire({position:n,nativeEvent:e.pointerEvent,edge:r})}_resolvePosition(e,t,n,r,i){var a;let o=(a=this.options).getPositionResolver?.call(a);if(o){let a=o.resolve({x:e,y:t,width:n,height:r,zones:this._acceptedTargetZonesSet,event:i});return a?{position:a.position,edge:!!a.edge,edgeGroup:!!a.edgeGroup}:null}let s=this._calculateQuadrant(e,t,n,r);return s?{position:s,edge:!1,edgeGroup:!1}:null}_calculateQuadrant(e,t,n,r){let i=this.options.overlayModel?.activationSize??CK;return i.type===`percentage`?yK(this._acceptedTargetZonesSet,e,t,n,r,i.value):bK(this._acceptedTargetZonesSet,e,t,n,r,i.value)}_clearOwnOverlay(){let e=this._state!==void 0;if(this._removeOverlay(),e){var t,n;(t=(n=this.options).getOverrideTarget)==null||(t=t.call(n))==null||t.clear()}}_removeOverlay(){if(this._edge=!1,this._targetElement){var e;this._state=void 0,(e=this._targetElement.parentElement)==null||e.classList.remove(`dv-drop-target`),this._targetElement.remove(),this._targetElement=void 0,this._overlayElement=void 0}else this._state=void 0}},TK=5,EK=250,DK=8,OK=class extends Y{constructor(e,t){super(),this.element=e,this.options=t,this._disabled=!1,this._armed=!1,this._startX=0,this._startY=0,this._touchOnly=t.touchOnly??!0,this.addDisposables(Z(this.element,`pointerdown`,e=>{this._onPointerDown(e)}))}setDisabled(e){this._disabled=e,e&&this._cancelPending()}setTouchOnly(e){this._touchOnly!==e&&(this._touchOnly=e,e&&this._cancelPending())}_shouldHandle(e){var t;return!(this._disabled||this._touchOnly&&e.pointerType!==`touch`&&e.pointerType!==`pen`||e.pointerType===`mouse`&&e.button!==0||(t=this.options).isCancelled?.call(t,e))}_onPointerDown(e){if(!this._shouldHandle(e))return;this._cancelPending(),this._selectionShield=GW(this.element.ownerDocument??document),this._pendingPointerId=e.pointerId,this._startX=e.clientX,this._startY=e.clientY,this._startEvent=e;let t=e.pointerType===`touch`||e.pointerType===`pen`,n=this.options.touchInitiationDelay,r=(typeof n==`function`?n():n)??EK;this._armed=!t||r<=0,t&&r>0&&Number.isFinite(r)&&(this._armTimer=setTimeout(()=>{this._armTimer=void 0,this._armed=!0},r));let i=this.options.threshold??TK,a=this.options.pressTolerance,o=(typeof a==`function`?a():a)??DK,s=this.element.ownerDocument?.defaultView??globalThis.window;this._pendingMoveListener=Z(s,`pointermove`,e=>{if(e.pointerId!==this._pendingPointerId)return;let t=e.clientX-this._startX,n=e.clientY-this._startY,r=Math.hypot(t,n);this._armed?r>=i&&this._beginDrag(e):r>o&&this._beginDrag(e)}),this._pendingUpListener=Z(s,`pointerup`,e=>{e.pointerId===this._pendingPointerId&&this._cancelPending()}),this._pendingCancelListener=Z(s,`pointercancel`,e=>{e.pointerId===this._pendingPointerId&&this._cancelPending()})}cancelPending(){this._cancelPending()}_cancelPending(){var e,t,n,r;(e=this._selectionShield)==null||e.release(),this._selectionShield=void 0,this._pendingPointerId=void 0,this._armTimer!==void 0&&(clearTimeout(this._armTimer),this._armTimer=void 0),this._armed=!1,(t=this._pendingMoveListener)==null||t.dispose(),(n=this._pendingUpListener)==null||n.dispose(),(r=this._pendingCancelListener)==null||r.dispose(),this._pendingMoveListener=void 0,this._pendingUpListener=void 0,this._pendingCancelListener=void 0,this._startEvent=void 0}_beginDrag(e){var t,n,r;let i=this._startEvent??e;this._cancelPending();let a=i.defaultPrevented;if((t=(n=this.options).onDragStart)==null||t.call(n,i),i.defaultPrevented&&!a)return;let o=(r=this.options).createGhost?.call(r,i);SK.getInstance().beginDrag({pointerEvent:e,source:this.element,getData:()=>this.options.getData(i),ghost:o,onDragMove:this.options.onDragMove,onDragEnd:this.options.onDragEnd})}dispose(){this._cancelPending(),super.dispose()}},kK=class{constructor(e){this._disposed=!1,this.element=e.element,this.offsetX=e.offsetX??0,this.offsetY=e.offsetY??0;let t=e.owner?tG(e.owner):document.body,n;BW(t)&&typeof this.element.showPopover==`function`&&(n=this.element.ownerDocument.createElement(`div`),n.popover=`manual`,Object.assign(n.style,{inset:`auto`,margin:`0`,padding:`0`,border:`0`,background:`transparent`,color:`inherit`,overflow:`visible`}),n.appendChild(this.element),this.element.style.pointerEvents=`none`,this.element.style.transform=`none`),this.container=n??this.element;let r=this.container.style;r.position=`fixed`,r.left=`0px`,r.top=`0px`,r.pointerEvents=`none`,r.zIndex=`99999`,r.opacity=String(e.opacity??.8),r.willChange=`transform`,r.transform=`translate3d(${e.initialX-this.offsetX}px, ${e.initialY-this.offsetY}px, 0)`,t.appendChild(this.container),n?.showPopover()}update(e,t){this._disposed||(this.container.style.transform=`translate3d(${e-this.offsetX}px, ${t-this.offsetY}px, 0)`)}dispose(){this._disposed||(this._disposed=!0,this.element.remove(),this.container!==this.element&&this.container.remove())}},AK=class extends Y{constructor(e,t){super(),this.el=e,this.opts=t,this._dataDisposable=new gW,this._pointerEventsDisposable=new gW,this._disabled=!!t.disabled,this.addDisposables(this._dataDisposable,this._pointerEventsDisposable,Z(this.el,`dragstart`,e=>{var t,n,r,i;if(e.defaultPrevented||this._disabled||(t=this.opts).isCancelled?.call(t,e)){e.preventDefault();return}if((n=(r=this.opts).onDragStart)==null||n.call(r,e),e.defaultPrevented)return;let a=WW(this.el.ownerDocument??document);this._pointerEventsDisposable.value={dispose:()=>a.release()},this.el.classList.add(`dv-dragged`),setTimeout(()=>this.el.classList.remove(`dv-dragged`),0),this._dataDisposable.value=this.opts.getData(e);let o=(i=this.opts).createGhost?.call(i,e);if(o&&e.dataTransfer&&(xK(e.dataTransfer,o.element,{x:o.offsetX??0,y:o.offsetY??0,ownerDocument:this.el.ownerDocument??void 0,owner:this.el}),o.dispose)){let e=o.dispose;setTimeout(()=>e(),0)}e.dataTransfer&&(e.dataTransfer.effectAllowed=`move`,e.dataTransfer.items.length===0&&e.dataTransfer.setData(`text/plain`,``))}),Z(this.el,`dragend`,e=>{var t,n;this._pointerEventsDisposable.dispose(),setTimeout(()=>this._dataDisposable.dispose(),0),(t=(n=this.opts).onDragEnd)==null||t.call(n,e)}))}setDisabled(e){this._disabled=e}setTouchOnly(e){}cancelPending(){}},jK=class{constructor(){this.kind=`html5`}createDropTarget(e,t){return new vK(e,t)}createDragSource(e,t){return new AK(e,t)}},MK=class{constructor(){this.kind=`pointer`}createDropTarget(e,t){return new wK(e,t)}createDragSource(e,t){let n=t.createGhost?n=>{let r=t.createGhost(n);if(!r)return;let i=new kK({element:r.element,initialX:n.clientX,initialY:n.clientY,offsetX:r.offsetX,offsetY:r.offsetY,owner:e});if(r.dispose){let e=i.dispose.bind(i),t=r.dispose;i.dispose=()=>{e(),t()}}return i}:void 0,r=new OK(e,{getData:t.getData,isCancelled:t.isCancelled,onDragStart:t.onDragStart,onDragEnd:t.onDragEnd?e=>t.onDragEnd(e.pointerEvent):void 0,createGhost:n,touchOnly:t.touchOnly,touchInitiationDelay:t.touchInitiationDelay,pressTolerance:t.pressTolerance,threshold:t.threshold});return t.disabled&&r.setDisabled(!0),r}},NK=new jK,PK=new MK,FK=Object.keys({disableAutoResizing:void 0,disableDnd:void 0,className:void 0}),IK=class extends yW{constructor(e,t,n,r){super(),this.nativeEvent=e,this.position=t,this.getData=n,this.panel=r}},LK=class extends vW{constructor(){super()}},RK=class extends Y{get isFocused(){return this._isFocused}get isActive(){return this._isActive}get isVisible(){return this._isVisible}get width(){return this._width}get height(){return this._height}constructor(e,t){super(),this.id=e,this.component=t,this._isFocused=!1,this._isActive=!1,this._isVisible=!0,this._width=0,this._height=0,this._parameters={},this.panelUpdatesDisposable=new gW,this._onDidDimensionChange=new X,this.onDidDimensionsChange=this._onDidDimensionChange.event,this._onDidChangeFocus=new X,this.onDidFocusChange=this._onDidChangeFocus.event,this._onWillFocus=new X,this.onWillFocus=this._onWillFocus.event,this._onDidVisibilityChange=new X,this.onDidVisibilityChange=this._onDidVisibilityChange.event,this._onWillVisibilityChange=new X,this.onWillVisibilityChange=this._onWillVisibilityChange.event,this._onDidActiveChange=new X,this.onDidActiveChange=this._onDidActiveChange.event,this._onActiveChange=new X,this.onActiveChange=this._onActiveChange.event,this._onDidParametersChange=new X,this.onDidParametersChange=this._onDidParametersChange.event,this.addDisposables(this.onDidFocusChange(e=>{this._isFocused=e.isFocused}),this.onDidActiveChange(e=>{this._isActive=e.isActive}),this.onDidVisibilityChange(e=>{this._isVisible=e.isVisible}),this.onDidDimensionsChange(e=>{this._width=e.width,this._height=e.height}),this.panelUpdatesDisposable,this._onDidDimensionChange,this._onDidChangeFocus,this._onDidVisibilityChange,this._onDidActiveChange,this._onWillFocus,this._onActiveChange,this._onWillFocus,this._onWillVisibilityChange,this._onDidParametersChange)}getParameters(){return this._parameters}initialize(e){this.panelUpdatesDisposable.value=this._onDidParametersChange.event(t=>{this._parameters=t,e.update({params:t})})}setVisible(e){this._onWillVisibilityChange.fire({isVisible:e})}setActive(){this._onActiveChange.fire()}updateParameters(e){this._onDidParametersChange.fire(e)}},zK=class extends RK{constructor(e,t){super(e,t),this._onDidConstraintsChangeInternal=new X,this.onDidConstraintsChangeInternal=this._onDidConstraintsChangeInternal.event,this._onDidConstraintsChange=new X({replay:!0}),this.onDidConstraintsChange=this._onDidConstraintsChange.event,this._onDidSizeChange=new X,this.onDidSizeChange=this._onDidSizeChange.event,this.addDisposables(this._onDidConstraintsChangeInternal,this._onDidConstraintsChange,this._onDidSizeChange)}setConstraints(e){this._onDidConstraintsChangeInternal.fire(e)}setSize(e){this._onDidSizeChange.fire(e)}},BK=class extends zK{set pane(e){this._pane=e}constructor(e,t){super(e,t),this._onDidExpansionChange=new X({replay:!0}),this.onDidExpansionChange=this._onDidExpansionChange.event,this._onMouseEnter=new X({}),this.onMouseEnter=this._onMouseEnter.event,this._onMouseLeave=new X({}),this.onMouseLeave=this._onMouseLeave.event,this.addDisposables(this._onDidExpansionChange,this._onMouseEnter,this._onMouseLeave)}setExpanded(e){var t;(t=this._pane)==null||t.setExpanded(e)}get isExpanded(){return!!this._pane?.isExpanded()}},VK=class extends Y{get element(){return this._element}get width(){return this._width}get height(){return this._height}get params(){return this._params?.params}constructor(e,t,n){super(),this.id=e,this.component=t,this.api=n,this._height=0,this._width=0,this._element=document.createElement(`div`),this._element.tabIndex=-1,this._element.style.outline=`none`,this._element.style.height=`100%`,this._element.style.width=`100%`,this._element.style.overflow=`hidden`;let r=kW(this._element);this.addDisposables(this.api,r.onDidFocus(()=>{this.api._onDidChangeFocus.fire({isFocused:!0})}),r.onDidBlur(()=>{this.api._onDidChangeFocus.fire({isFocused:!1})}),r)}focus(){let e=new LK;this.api._onWillFocus.fire(e),!e.defaultPrevented&&this._element.focus()}layout(e,t){this._width=e,this._height=t,this.api._onDidDimensionChange.fire({width:e,height:t}),this.part&&this._params&&this.part.update({params:this._params.params})}init(e){this._params=e,this.part=this.getComponent()}update(e){var t;this._params=$($({},this._params),{},{params:$($({},this._params?.params),e.params)});for(let t of Object.keys(e.params))e.params[t]===void 0&&delete this._params.params[t];(t=this.part)==null||t.update({params:this._params.params})}toJSON(){let e=this._params?.params??{};return{id:this.id,component:this.component,params:Object.keys(e).length>0?e:void 0}}dispose(){var e;this.api.dispose(),(e=this.part)==null||e.dispose(),super.dispose()}},HK=class extends VK{set orientation(e){this._orientation=e}get orientation(){return this._orientation}get minimumSize(){return this.headerSize+(this.isExpanded()?this._minimumBodySize:0)}get maximumSize(){return this.headerSize+(this.isExpanded()?this._maximumBodySize:0)}get size(){return this._size}get orthogonalSize(){return this._orthogonalSize}set orthogonalSize(e){this._orthogonalSize=e}get minimumBodySize(){return this._minimumBodySize}set minimumBodySize(e){this._minimumBodySize=typeof e==`number`?e:0}get maximumBodySize(){return this._maximumBodySize}set maximumBodySize(e){this._maximumBodySize=typeof e==`number`?e:1/0}get headerVisible(){return this._headerVisible}set headerVisible(e){this._headerVisible=e,this.header.style.display=e?``:`none`}constructor(e){super(e.id,e.component,new BK(e.id,e.component)),this._onDidChangeExpansionState=new X({replay:!0}),this.onDidChangeExpansionState=this._onDidChangeExpansionState.event,this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this._orthogonalSize=0,this._size=0,this._isExpanded=!1,this.api.pane=this,this.api.initialize(this),this.headerSize=e.headerSize,this.headerComponent=e.headerComponent,this._minimumBodySize=e.minimumBodySize,this._maximumBodySize=e.maximumBodySize,this._isExpanded=e.isExpanded,this._headerVisible=e.isHeaderVisible,this._onDidChangeExpansionState.fire(this.isExpanded()),this._orientation=e.orientation,this.element.classList.add(`dv-pane`),this.addDisposables(this.api.onWillVisibilityChange(e=>{let{isVisible:t}=e,{accessor:n}=this._params;n.setVisible(this,t)}),this.api.onDidSizeChange(e=>{this._onDidChange.fire({size:e.size})}),Z(this.element,`mouseenter`,e=>{this.api._onMouseEnter.fire(e)}),Z(this.element,`mouseleave`,e=>{this.api._onMouseLeave.fire(e)})),this.addDisposables(this._onDidChangeExpansionState,this.onDidChangeExpansionState(e=>{this.api._onDidExpansionChange.fire({isExpanded:e})}),this.api.onDidFocusChange(e=>{this.header&&(e.isFocused?DW(this.header,`focused`):EW(this.header,`focused`))})),this.renderOnce()}setVisible(e){this.api._onDidVisibilityChange.fire({isVisible:e})}setActive(e){this.api._onDidActiveChange.fire({isActive:e})}isExpanded(){return this._isExpanded}setExpanded(e){this._isExpanded!==e&&(this._isExpanded=e,e?(this.animationTimer&&clearTimeout(this.animationTimer),this.body&&this.element.appendChild(this.body)):(this._expandedSize=this._size,this.animationTimer=setTimeout(()=>{var e;(e=this.body)==null||e.remove()},200)),this._onDidChange.fire(e?{size:this._expandedSize??this.width}:{}),this._onDidChangeExpansionState.fire(e))}layout(e,t){this._size=e,this._orthogonalSize=t;let[n,r]=this.orientation===`HORIZONTAL`?[e,t]:[t,e];super.layout(n,r)}init(e){var t,n;super.init(e),typeof e.minimumBodySize==`number`&&(this.minimumBodySize=e.minimumBodySize),typeof e.maximumBodySize==`number`&&(this.maximumBodySize=e.maximumBodySize),this.bodyPart=this.getBodyComponent(),this.headerPart=this.getHeaderComponent(),this.bodyPart.init($($({},e),{},{api:this.api})),this.headerPart.init($($({},e),{},{api:this.api})),(t=this.body)==null||t.append(this.bodyPart.element),(n=this.header)==null||n.append(this.headerPart.element),typeof e.isExpanded==`boolean`&&this.setExpanded(e.isExpanded)}toJSON(){let e=this._params;return $($({},super.toJSON()),{},{headerComponent:this.headerComponent,title:e.title})}renderOnce(){this.header=document.createElement(`div`),this.header.tabIndex=0,this.header.className=`dv-pane-header`,this.header.style.height=`${this.headerSize}px`,this.header.style.lineHeight=`${this.headerSize}px`,this.header.style.minHeight=`${this.headerSize}px`,this.header.style.maxHeight=`${this.headerSize}px`,this.element.appendChild(this.header),this.body=document.createElement(`div`),this.body.className=`dv-pane-body`,this.element.appendChild(this.body)}getComponent(){return{update:e=>{var t,n;(t=this.bodyPart)==null||t.update(e),(n=this.headerPart)==null||n.update(e)},dispose:()=>{var e,t;(e=this.bodyPart)==null||e.dispose(),(t=this.headerPart)==null||t.dispose()}}}},UK=class extends HK{constructor(e){super({id:e.id,component:e.component,headerComponent:e.headerComponent,orientation:e.orientation,isExpanded:e.isExpanded,isHeaderVisible:!0,headerSize:e.headerSize,minimumBodySize:e.minimumBodySize,maximumBodySize:e.maximumBodySize}),this._onDidDrop=new X,this.onDidDrop=this._onDidDrop.event,this._onUnhandledDragOver=new X,this.onUnhandledDragOver=this._onUnhandledDragOver.event,this.accessor=e.accessor,this.addDisposables(this._onDidDrop,this._onUnhandledDragOver),e.disableDnd||this.initDragFeatures()}initDragFeatures(){if(!this.header)return;let e=this.id,t=this.accessor.id;this.header.draggable=!0;let n={getData:()=>(fW.getInstance().setData([new dW(t,e)],dW.prototype),{dispose:()=>{fW.getInstance().clearData(dW.prototype)}})};this.html5DragSource=NK.createDragSource(this.header,n),this.pointerDragSource=PK.createDragSource(this.header,n);let r={acceptedTargetZones:[`top`,`bottom`],overlayModel:{activationSize:{type:`percentage`,value:50}},canDisplayOverlay:(e,t)=>{let n=mW();if(n&&n.paneId!==this.id&&n.viewId===this.accessor.id)return!0;let r=new IK(e,t,mW,this);return this._onUnhandledDragOver.fire(r),r.isAccepted}};this.target=NK.createDropTarget(this.element,r),this.pointerTarget=PK.createDropTarget(this.element,r),this.addDisposables(this._onDidDrop,this.html5DragSource,this.pointerDragSource,this.target,this.pointerTarget,this.target.onDrop(e=>{this.onDrop(e)}),this.pointerTarget.onDrop(e=>{this.onDrop(e)}))}onDrop(e){let t=mW();if(t?.viewId!==this.accessor.id){this._onDidDrop.fire($($({},e),{},{panel:this,api:new tK(this.accessor),getData:mW}));return}let n=this._params.containerApi,r=t.paneId,i=n.getPanel(r);if(!i){this._onDidDrop.fire($($({},e),{},{panel:this,getData:mW,api:new tK(this.accessor)}));return}let a=n.panels,o=a.indexOf(i),s=n.panels.indexOf(this);(e.position===`left`||e.position===`top`)&&o<s&&s--,(e.position===`right`||e.position===`bottom`)&&(o>s&&s++,s=Math.min(a.length-1,s)),n.movePanel(o,s)}},WK=0,GK=()=>`dv-tabpanel-${WK++}`,KK=class extends Y{get element(){return this._element}get dimensions(){return this._dimensions}constructor(e,t){var n,r,i;super(),this.accessor=e,this.group=t,this.disposable=new gW,this._onDidFocus=new X,this.onDidFocus=this._onDidFocus.event,this._onDidBlur=new X,this.onDidBlur=this._onDidBlur.event,this._onDidDimensionsChange=new X,this.onDidDimensionsChange=this._onDidDimensionsChange.event,this._element=document.createElement(`div`),this._element.className=`dv-content-container`,this._element.tabIndex=-1,this._element.id=GK(),this._element.setAttribute(`role`,`tabpanel`),this.addDisposables(this._onDidFocus,this._onDidBlur,this._onDidDimensionsChange);let a=()=>t.dropTargetContainer?.model,o=(e,t)=>this.group.canDisplayContentOverlay(e,t);this.dropTarget=new vK(this.element,{getOverlayOutline:()=>e.options.theme?.dndPanelOverlay===`group`?this.element.parentElement:null,className:`dv-drop-target-content`,acceptedTargetZones:[`top`,`bottom`,`left`,`right`,`center`],canDisplayOverlay:o,getOverrideTarget:a,overlayModel:(n=this.accessor).resolveDropOverlayModel?.call(n,`content`),getPositionResolver:()=>e.getDropPositionResolver?.call(e)}),this.pointerDropTarget=PK.createDropTarget(this.element,{acceptedTargetZones:[`top`,`bottom`,`left`,`right`,`center`],canDisplayOverlay:o,getOverlayOutline:()=>e.options.theme?.dndPanelOverlay===`group`?this.element.parentElement:null,className:`dv-drop-target-content`,getOverrideTarget:a,overlayModel:(r=this.accessor).resolveDropOverlayModel?.call(r,`content`),getPositionResolver:()=>e.getDropPositionResolver?.call(e)}),this.addDisposables(this.dropTarget,this.pointerDropTarget,(i=this.accessor).onDidOptionsChange?.call(i,()=>{var e;let t=(e=this.accessor).resolveDropOverlayModel?.call(e,`content`)??{};this.dropTarget.setOverlayModel(t),this.pointerDropTarget.setOverlayModel(t)})??hW.NONE)}show(){this.element.style.display=``}hide(){this.element.style.display=`none`}setLabelledBy(e){e?this._element.setAttribute(`aria-labelledby`,e):this._element.removeAttribute(`aria-labelledby`)}renderPanel(e,t){let n=(t?.asActive??!0)||this.group.isPanelActive(e);if(n||this.panel===e){if(this.panel?.view.content.element.parentElement===this._element){var r,i;this.panel.view.content.element.remove(),(r=(i=this.panel.view.content).onHide)==null||r.call(i)}this.panel=e}let a;switch(e.api.renderer){case`onlyWhenVisible`:if(this.group.renderContainer.detatch(e),n){var o,s;this._element.appendChild(e.view.content.element),(o=(s=e.view.content).onShow)==null||o.call(s)}a=this._element;break;case`always`:e.view.content.element.parentElement===this._element&&e.view.content.element.remove(),a=this.group.renderContainer.attach({panel:e,referenceContainer:this});break;default:throw Error(`dockview: invalid renderer type '${e.api.renderer}'`)}if(n){let e=kW(a);this.focusTracker=e;let t=new Y;t.addDisposables(e,e.onDidFocus(()=>this._onDidFocus.fire()),e.onDidBlur(()=>this._onDidBlur.fire())),this.disposable.value=t}}openPanel(e){this.panel!==e&&this.renderPanel(e)}layout(e,t){(this._dimensions?.width!==e||this._dimensions.height!==t)&&(this._dimensions={width:e,height:t},this._onDidDimensionsChange.fire(this._dimensions))}closePanel(){if(this.panel&&this.panel.api.renderer===`onlyWhenVisible`){var e,t;this.panel.view.content.element.remove(),(e=(t=this.panel.view.content).onHide)==null||e.call(t)}this.panel=void 0}dispose(){this.disposable.dispose(),super.dispose()}refreshFocusState(){this.focusTracker?.refreshState&&this.focusTracker.refreshState()}},qK=e=>{let t=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);t.setAttributeNS(null,`height`,e.height),t.setAttributeNS(null,`width`,e.width),t.setAttributeNS(null,`viewBox`,e.viewbox),t.setAttributeNS(null,`aria-hidden`,`false`),t.setAttributeNS(null,`focusable`,`false`),t.classList.add(`dv-svg`);let n=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return n.setAttributeNS(null,`d`,e.path),t.appendChild(n),t},JK=()=>qK({width:`11`,height:`11`,viewbox:`0 0 28 28`,path:`M2.1 27.3L0 25.2L11.55 13.65L0 2.1L2.1 0L13.65 11.55L25.2 0L27.3 2.1L15.75 13.65L27.3 25.2L25.2 27.3L13.65 15.75L2.1 27.3Z`}),YK=()=>qK({width:`11`,height:`11`,viewbox:`0 0 24 24`,path:`M16 9V4h1c.55 0 1-.45 1-1s-.45-1-1-1H6c-.55 0-1 .45-1 1s.45 1 1 1h1v5c0 1.66-1.34 3-3 3v2h5.97v7l1 1 1-1v-7H19v-2c-1.66 0-3-1.34-3-3z`}),XK=()=>qK({width:`11`,height:`11`,viewbox:`0 0 24 15`,path:`M12 14.15L0 2.15L2.15 0L12 9.9L21.85 0.0499992L24 2.2L12 14.15Z`}),ZK=()=>qK({width:`11`,height:`11`,viewbox:`0 0 15 25`,path:`M2.15 24.1L0 21.95L9.9 12.05L0 2.15L2.15 0L14.2 12.05L2.15 24.1Z`}),QK=500,$K=8,eq=class extends Y{constructor(e,t){super(),this.element=e,this.options=t,this._startX=0,this._startY=0,this.addDisposables(Z(this.element,`pointerdown`,e=>{this._onPointerDown(e)}))}_onPointerDown(e){if((this.options.touchOnly??!0)&&e.pointerType!==`touch`&&e.pointerType!==`pen`)return;this._cancelPending(),this._pointerId=e.pointerId,this._startX=e.clientX,this._startY=e.clientY;let t=this.options.delay??QK,n=this.options.tolerance??$K,r=this.element.ownerDocument?.defaultView??globalThis.window;this._timer=setTimeout(()=>{this._timer=void 0,this._cancelPending(),this._installContextMenuGuard(r),this._installClickGuard(r),this.options.onLongPress(e)},t),this._moveListener=Z(r,`pointermove`,e=>{if(e.pointerId!==this._pointerId)return;let t=e.clientX-this._startX,r=e.clientY-this._startY;Math.hypot(t,r)>n&&this._cancelPending()}),this._upListener=Z(r,`pointerup`,e=>{e.pointerId===this._pointerId&&this._cancelPending()}),this._cancelListener=Z(r,`pointercancel`,e=>{e.pointerId===this._pointerId&&this._cancelPending()})}_installContextMenuGuard(e){let t,n=setTimeout(()=>t?.dispose(),500);t=Z(e,`contextmenu`,e=>{e.preventDefault(),clearTimeout(n),t?.dispose()},{capture:!0})}_installClickGuard(e){let t,n=setTimeout(()=>t?.dispose(),500);t=Z(e,`click`,e=>{PW(e,[this.element])&&(e.preventDefault(),e.stopPropagation()),clearTimeout(n),t?.dispose()},{capture:!0})}_cancelPending(){var e,t,n;this._timer!==void 0&&(clearTimeout(this._timer),this._timer=void 0),this._pointerId=void 0,(e=this._moveListener)==null||e.dispose(),(t=this._upListener)==null||t.dispose(),(n=this._cancelListener)==null||n.dispose(),this._moveListener=void 0,this._upListener=void 0,this._cancelListener=void 0}dispose(){this._cancelPending(),super.dispose()}};function tq(e){if(e.disableDnd)return{html5:!1,pointer:!1,pointerHandlesMouse:!1};switch(e.dndStrategy){case`pointer`:return{html5:!1,pointer:!0,pointerHandlesMouse:!0};case`html5`:return{html5:!0,pointer:!1,pointerHandlesMouse:!1};case`auto`:case void 0:default:return nq()?{html5:!1,pointer:!0,pointerHandlesMouse:!0}:{html5:!0,pointer:!0,pointerHandlesMouse:!1}}}function nq(){if(globalThis.window===void 0||!globalThis.matchMedia)return!1;let e=globalThis.matchMedia(`(pointer: coarse)`).matches,t=globalThis.matchMedia(`(pointer: fine)`).matches;return e&&!t}var rq=0,iq=()=>`dv-tab-${rq++}`,aq=class extends Y{get element(){return this._element}constructor(e,t,n){var r,i,a,o,s;super(),this.panel=e,this.accessor=t,this.group=n,this.content=void 0,this.panelTransfer=fW.getInstance(),this._direction=`horizontal`,this._pinIndicator=void 0,this._onPointDown=new X,this.onPointerDown=this._onPointDown.event,this._onTabClick=new X,this.onTabClick=this._onTabClick.event,this._onDropped=new X,this.onDrop=this._onDropped.event,this._onDragStart=new X,this.onDragStart=this._onDragStart.event,this._onDragEnd=new X,this.onDragEnd=this._onDragEnd.event;let c=tq(this.accessor.options);this._element=document.createElement(`div`),this._element.className=`dv-tab`,this._element.tabIndex=-1,this._element.draggable=c.html5,this._element.id=iq(),this._element.setAttribute(`role`,`tab`),this._element.setAttribute(`aria-selected`,`false`),this._element.setAttribute(`aria-label`,this.panel.title??this.panel.id),this._element.dataset.tabPanelId=this.panel.id;let l=(r=this.group)==null||(r=r.model)==null?void 0:r.contentContainerId;l&&this._element.setAttribute(`aria-controls`,l),Q(this.element,`dv-inactive-tab`,!0),this._updatePinnedClasses();let u=(e,t)=>{if(this.group.locked)return!1;let n=pW();return this.accessor.id===n?.viewId?!(this.accessor.options.theme?.tabAnimation===`smooth`||n.tabGroupId&&n.groupId===this.group.id&&this.group.model.getTabGroupForPanel(this.panel.id)):this.group.model.canDisplayOverlay(e,t,`tab`)};this.dropTarget=NK.createDropTarget(this._element,{acceptedTargetZones:[`left`,`right`],overlayModel:this._buildOverlayModel(),canDisplayOverlay:u,getOverrideTarget:()=>n.model.dropTargetContainer?.model}),this.pointerDropTarget=PK.createDropTarget(this._element,{acceptedTargetZones:[`left`,`right`],overlayModel:this._buildOverlayModel(),canDisplayOverlay:u,getOverrideTarget:()=>n.model.dropTargetContainer?.model});let d={getData:()=>(this.panelTransfer.setData([new uW(this.accessor.id,this.group.id,this.panel.id)],uW.prototype),{dispose:()=>{this.panelTransfer.clearData(uW.prototype)}}),createGhost:()=>({element:this._buildGhostElement(),offsetX:30,offsetY:-10}),onDragStart:e=>{this._onDragStart.fire(e),!e.defaultPrevented&&!(e instanceof PointerEvent)&&this.accessor.options.theme?.tabAnimation===`smooth`&&requestAnimationFrame(()=>{Q(this.element,`dv-tab--dragging`,!0)})},onDragEnd:e=>{this._onDragEnd.fire(e)}};this.html5DragSource=NK.createDragSource(this._element,$($({},d),{},{disabled:!c.html5})),this.pointerDragSource=PK.createDragSource(this._element,$($({},d),{},{disabled:!c.pointer,touchOnly:!c.pointerHandlesMouse,isCancelled:()=>!tq(this.accessor.options).pointer})),this.onWillShowOverlay=_W.any(this.dropTarget.onWillShowOverlay,this.pointerDropTarget.onWillShowOverlay),this.addDisposables(this._onPointDown,this._onTabClick,this._onDropped,this._onDragStart,this._onDragEnd,this.accessor.onDidOptionsChange(()=>{let e=this._buildOverlayModel();this.dropTarget.setOverlayModel(e),this.pointerDropTarget.setOverlayModel(e),this._updatePinnedClasses()}),((i=this.panel.api)==null||(a=i.onDidChangePinned)==null?void 0:a.call(i,()=>{this._updatePinnedClasses()}))??{dispose:()=>{}},((o=this.panel.api)==null||(s=o.onDidTitleChange)==null?void 0:s.call(o,e=>{this._element.setAttribute(`aria-label`,e.title??this.panel.id)}))??{dispose:()=>{}},Z(this._element,`dragend`,()=>{Q(this.element,`dv-tab--dragging`,!1)}),this.html5DragSource,Z(this._element,`pointerdown`,e=>{this._onPointDown.fire(e)}),Z(this._element,`click`,e=>{this._onTabClick.fire(e)}),Z(this._element,`contextmenu`,e=>{var t;(t=this.accessor.contextMenuService)==null||t.show(this.panel,this.group,e)}),new eq(this._element,{onLongPress:e=>{var t;this.pointerDragSource.cancelPending(),(t=this.accessor.contextMenuService)==null||t.show(this.panel,this.group,e)}}),this.dropTarget.onDrop(e=>{this._onDropped.fire(e)}),this.pointerDropTarget.onDrop(e=>{this._onDropped.fire(e)}),this.dropTarget,this.pointerDropTarget,this.pointerDragSource)}_updatePinnedClasses(){let e=this.panel.api?.isPinned??!1,t=e&&this.accessor.options.pinnedTabs?.compact===!0;Q(this.element,`dv-tab--pinned`,e),Q(this.element,`dv-tab--pinned-compact`,t);let n=e&&!this.panel.api?.tabComponent;if(n&&!this._pinIndicator){let e=document.createElement(`div`);e.className=`dv-tab-pin`,e.appendChild(YK()),this._element.insertBefore(e,this._element.firstChild),this._pinIndicator=e}else!n&&this._pinIndicator&&(this._pinIndicator.remove(),this._pinIndicator=void 0)}setActive(e){Q(this.element,`dv-active-tab`,e),Q(this.element,`dv-inactive-tab`,!e),this._element.setAttribute(`aria-selected`,e?`true`:`false`),this._element.tabIndex=e?0:-1}setContent(e){this.content&&this.content.element.remove(),this.content=e,this._element.appendChild(this.content.element)}_buildOverlayModel(){var e;let t=(e=this.accessor).resolveDropOverlayModel?.call(e,`tab`,this.group);if(t)return t;let n=this.accessor.options.theme?.dndTabIndicator===`line`?1/0:0;return{activationSize:{value:50,type:`percentage`},smallWidthBoundary:n,smallHeightBoundary:n}}setDirection(e){this._direction=e;let t=e===`vertical`?[`top`,`bottom`]:[`left`,`right`];this.dropTarget.setTargetZones(t),this.pointerDropTarget.setTargetZones(t)}updateDragAndDropState(){let e=tq(this.accessor.options);this._element.draggable=e.html5,this.html5DragSource.setDisabled(!e.html5),this.pointerDragSource.setDisabled(!e.pointer),this.pointerDragSource.setTouchOnly(!e.pointerHandlesMouse)}_buildGhostElement(){let e=getComputedStyle(this.element),t=this.element.cloneNode(!0),n=this._direction===`vertical`,r=new Set([`writing-mode`,`inline-size`,`block-size`,`min-inline-size`,`min-block-size`,`max-inline-size`,`max-block-size`,`margin-inline`,`margin-inline-start`,`margin-inline-end`,`margin-block`,`margin-block-start`,`margin-block-end`,`padding-inline`,`padding-inline-start`,`padding-inline-end`,`padding-block`,`padding-block-start`,`padding-block-end`]);return Array.from(e).forEach(i=>{n&&r.has(i)||t.style.setProperty(i,e.getPropertyValue(i),e.getPropertyPriority(i))}),n&&(t.style.setProperty(`writing-mode`,`horizontal-tb`),t.style.setProperty(`width`,e.height),t.style.setProperty(`height`,e.width)),t.style.position=`absolute`,t.classList.add(`dv-tab-ghost-drag`),t}},oq=class{get kind(){return this.options.kind}get nativeEvent(){return this.event.nativeEvent}get position(){return this.event.position}get edge(){return this.event.edge}get edgeGroup(){return this.event.edgeGroup}get defaultPrevented(){return this.event.defaultPrevented}get panel(){return this.options.panel}get api(){return this.options.api}get group(){return this.options.group}preventDefault(){this.event.preventDefault()}getData(){return this.options.getData()}constructor(e,t){this.event=e,this.options=t}},sq=class extends Y{get group(){return this.groupAccessor()}constructor(e){var t;super(),this.panelTransfer=fW.getInstance(),this._onDragStart=new X,this.onDragStart=this._onDragStart.event,this._element=e.element,this.accessor=e.accessor;let n=e.group;this.groupAccessor=typeof n==`function`?n:()=>n,this.isFloatingMoveHandle=e.isFloatingMoveHandle??(()=>!0);let r=tq(this.accessor.options);this._element.draggable=r.html5,Q(this._element,`dv-draggable`,r.html5||r.pointer),this.addDisposables(this._onDragStart);let i=()=>{let e=document.createElement(`div`),t=globalThis.getComputedStyle(this._element),n=t.getPropertyValue(`--dv-activegroup-visiblepanel-tab-background-color`),r=t.getPropertyValue(`--dv-activegroup-visiblepanel-tab-color`);return e.style.backgroundColor=n,e.style.color=r,e.style.padding=`2px 8px`,e.style.height=`24px`,e.style.fontSize=`11px`,e.style.lineHeight=`20px`,e.style.borderRadius=`12px`,e.style.whiteSpace=`nowrap`,e.style.boxSizing=`border-box`,e.style.display=`inline-block`,e.textContent=`Multiple Panels (${this.group.size})`,e},a={getData:()=>(this.panelTransfer.setData([new uW(this.accessor.id,this.group.id,null)],uW.prototype),{dispose:()=>{this.panelTransfer.clearData(uW.prototype)}}),createGhost:()=>{var e;return(e=this.accessor).buildGroupDragGhost?.call(e,this.group)||{element:i(),offsetX:30,offsetY:-10}},onDragStart:e=>{this._onDragStart.fire(e)}};this.html5DragSource=NK.createDragSource(this._element,$($({},a),{},{disabled:!r.html5,isCancelled:e=>!!(this.group.api.location.type===`floating`&&this.isFloatingMoveHandle()&&!e.shiftKey||this.group.api.location.type===`edge`&&this.group.size===0)}));let o=()=>{var e;return((e=this.group)==null||(e=e.api)==null||(e=e.location)==null?void 0:e.type)===`floating`&&this.isFloatingMoveHandle()};this.pointerDragSource=PK.createDragSource(this._element,$($({},a),{},{disabled:!r.pointer,touchOnly:!r.pointerHandlesMouse,touchInitiationDelay:()=>o()?500:250,pressTolerance:()=>o()?1/0:8,isCancelled:()=>!tq(this.accessor.options).pointer||this.group.api.location.type===`edge`&&this.group.size===0,onDragStart:e=>{var t;let n=e.defaultPrevented;this._onDragStart.fire(e),e.defaultPrevented&&!n||(t=this.getFloatingOverlay())==null||t.cancelPendingDrag()}}));let s=new gW,c=()=>{let e=this.getFloatingOverlay();s.value=e?e.onDidStartMoving(()=>{this.pointerDragSource.cancelPending()}):hW.NONE};c(),this.addDisposables(s);let l=(t=this.group)==null||(t=t.api)==null?void 0:t.onDidLocationChange;l&&this.addDisposables(l(c)),this.addDisposables(this.html5DragSource,this.pointerDragSource)}updateDragAndDropState(){let e=tq(this.accessor.options);this._element.draggable=e.html5,Q(this._element,`dv-draggable`,e.html5||e.pointer),this.html5DragSource.setDisabled(!e.html5),this.pointerDragSource.setDisabled(!e.pointer),this.pointerDragSource.setTouchOnly(!e.pointerHandlesMouse)}getFloatingOverlay(){var e;if(this.group)return(e=this.accessor.floatingGroups)==null||(e=e.find(e=>e.group===this.group))==null?void 0:e.overlay}},cq=class extends Y{get element(){return this._element}constructor(e,t){var n,r,i;super(),this.accessor=e,this.group=t,this._onDrop=new X,this.onDrop=this._onDrop.event,this._onDragStart=new X,this.onDragStart=this._onDragStart.event,this._element=document.createElement(`div`),this._element.className=`dv-void-container`,this.addDisposables(this._onDrop,this._onDragStart,Z(this._element,`pointerdown`,()=>{this.accessor.doSetGroupActive(this.group)}),Z(this._element,`pointerdown`,e=>{e.shiftKey&&MW(e)},!0)),this.dragSource=new sq({element:this._element,accessor:this.accessor,group:this.group,isFloatingMoveHandle:()=>!this._element.closest(`.dv-resize-container-with-titlebar`)});let a=(e,n)=>{if(this.group.api.locked)return!1;let r=pW();return this.accessor.id===r?.viewId||t.model.canDisplayOverlay(e,n,`header_space`)};this.dropTarget=NK.createDropTarget(this._element,{acceptedTargetZones:[`center`],canDisplayOverlay:a,getOverrideTarget:()=>t.model.dropTargetContainer?.model,overlayModel:(n=this.accessor).resolveDropOverlayModel?.call(n,`header_space`,this.group)}),this.pointerDropTarget=PK.createDropTarget(this._element,{acceptedTargetZones:[`center`],canDisplayOverlay:a,getOverrideTarget:()=>t.model.dropTargetContainer?.model,overlayModel:(r=this.accessor).resolveDropOverlayModel?.call(r,`header_space`,this.group)}),this.onWillShowOverlay=_W.any(this.dropTarget.onWillShowOverlay,this.pointerDropTarget.onWillShowOverlay),this.addDisposables(this.dragSource,this.dragSource.onDragStart(e=>{this._onDragStart.fire(e)}),this.dropTarget.onDrop(e=>{this._onDrop.fire(e)}),this.pointerDropTarget.onDrop(e=>{this._onDrop.fire(e)}),this.dropTarget,this.pointerDropTarget,(i=this.accessor).onDidOptionsChange?.call(i,()=>{var e;let t=(e=this.accessor).resolveDropOverlayModel?.call(e,`header_space`,this.group)??{};this.dropTarget.setOverlayModel(t),this.pointerDropTarget.setOverlayModel(t)})??hW.NONE)}updateDragAndDropState(){this.dragSource.updateDragAndDropState()}},lq=class e extends Y{get element(){return this._element}get orientation(){return this._orientation}set orientation(e){this._orientation!==e&&(this._scrollOffset=0,this._orientation=e,EW(this._scrollbar,`dv-scrollbar-vertical`,`dv-scrollbar-horizontal`),e===`vertical`?DW(this._scrollbar,`dv-scrollbar-vertical`):DW(this._scrollbar,`dv-scrollbar-horizontal`))}constructor(t){super(),this.scrollableElement=t,this._scrollOffset=0,this._orientation=`horizontal`,this._element=document.createElement(`div`),this._element.className=`dv-scrollable`,this._scrollbar=document.createElement(`div`),this._scrollbar.className=`dv-scrollbar dv-scrollbar-horizontal`,this.element.appendChild(t),this.element.appendChild(this._scrollbar),this.addDisposables(Z(this.element,`wheel`,t=>{this._scrollOffset+=t.deltaY*e.MouseWheelSpeed,this.scheduleStyleUpdate()}),Z(this._scrollbar,`pointerdown`,e=>{e.preventDefault();let t=this._scrollbar.ownerDocument??document;Q(this.element,`dv-scrollable-scrolling`,!0);let n=this._orientation===`horizontal`?e.clientX:e.clientY,r=this._scrollOffset,i=e=>{let t=this._orientation===`horizontal`?e.clientX-n:e.clientY-n,i=(this._orientation===`horizontal`?this.element.clientWidth:this.element.clientHeight)/(this._orientation===`horizontal`?this.scrollableElement.scrollWidth:this.scrollableElement.scrollHeight);this._scrollOffset=r+t/i,this.scheduleStyleUpdate()},a=()=>{Q(this.element,`dv-scrollable-scrolling`,!1),t.removeEventListener(`pointermove`,i),t.removeEventListener(`pointerup`,a),t.removeEventListener(`pointercancel`,a)};t.addEventListener(`pointermove`,i),t.addEventListener(`pointerup`,a),t.addEventListener(`pointercancel`,a)}),Z(this.element,`scroll`,()=>{this.scheduleStyleUpdate()}),Z(this.scrollableElement,`scroll`,()=>{this._scrollOffset=this._orientation===`horizontal`?this.scrollableElement.scrollLeft:this.scrollableElement.scrollTop,this.scheduleStyleUpdate()}),TW(this.element,()=>{Q(this.element,`dv-scrollable-resizing`,!0),this._animationTimer&&clearTimeout(this._animationTimer),this._animationTimer=setTimeout(()=>{clearTimeout(this._animationTimer),Q(this.element,`dv-scrollable-resizing`,!1)},500),this.scheduleStyleUpdate()}),hW.from(()=>{this._pendingStyleFrame!==void 0&&(cancelAnimationFrame(this._pendingStyleFrame),this._pendingStyleFrame=void 0)}))}scheduleStyleUpdate(){this._pendingStyleFrame===void 0&&(this._pendingStyleFrame=requestAnimationFrame(()=>{this._pendingStyleFrame=void 0,this.calculateScrollbarStyles()}))}calculateScrollbarStyles(){let e=this._orientation===`horizontal`?this.element.clientWidth:this.element.clientHeight,t=this._orientation===`horizontal`?this.scrollableElement.scrollWidth:this.scrollableElement.scrollHeight;if(t>e){let n=e/t*e;this._orientation===`horizontal`?(this._scrollbar.style.width=`${n}px`,this._scrollbar.style.height=``):(this._scrollbar.style.height=`${n}px`,this._scrollbar.style.width=``),this._scrollOffset=hG(this._scrollOffset,0,t-e),this._orientation===`horizontal`?this.scrollableElement.scrollLeft=this._scrollOffset:this.scrollableElement.scrollTop=this._scrollOffset;let r=this._scrollOffset/(t-e);this._orientation===`horizontal`?(this._scrollbar.style.left=`${(e-n)*r}px`,this._scrollbar.style.top=``):(this._scrollbar.style.top=`${(e-n)*r}px`,this._scrollbar.style.left=``)}else this._orientation===`horizontal`?(this._scrollbar.style.width=`0px`,this._scrollbar.style.left=`0px`):(this._scrollbar.style.height=`0px`,this._scrollbar.style.top=`0px`),this._scrollOffset=0}};lq.MouseWheelSpeed=1;var uq=`dv-tabs-container--wrap`;function dq(e,t){return typeof e==`boolean`?e:!!e?.[t]}function fq(e){return typeof e==`boolean`?e:e?Object.values(e).some(Boolean):!1}var pq=class extends yW{constructor(e,t,n,r,i){super(),this.nativeEvent=e,this.target=t,this.position=n,this.getData=r,this.group=i}},mq=Object.keys({disableAutoResizing:void 0,proportionalLayout:void 0,hideBorders:void 0,singleTabMode:void 0,disableFloatingGroups:void 0,floatingGroupBounds:void 0,transformFloatingGroupDrag:void 0,smartGuides:void 0,floatingGroupDragHandle:void 0,popoutUrl:void 0,nonce:void 0,defaultRenderer:void 0,defaultHeaderPosition:void 0,debug:void 0,locked:void 0,disableDnd:void 0,dndStrategy:void 0,className:void 0,noPanelsOverlay:void 0,closeEmptyGroups:void 0,groupIdGenerator:void 0,dndEdges:void 0,dropPositionResolver:void 0,dndCompass:void 0,dropSizing:void 0,theme:void 0,disableTabsOverflowList:void 0,overflow:void 0,scrollbars:void 0,getTabContextMenuItems:void 0,getTabGroupChipContextMenuItems:void 0,createTabGroupChipComponent:void 0,createGroupDragGhostComponent:void 0,dropOverlayModel:void 0,announcements:void 0,getAnnouncement:void 0,announcer:void 0,messages:void 0,keyboardNavigation:void 0,layoutHistory:void 0,autoHideEdgeGroups:void 0,dockToEdgeGroups:void 0,edgeGroupPeek:void 0,tabGroupColors:void 0,tabGroupAccent:void 0,pinnedTabs:void 0});function hq(e){return!!e.referencePanel}function gq(e){return!!e.referenceGroup}function _q(e){return!!e.referencePanel}function vq(e){return!!e.referenceGroup}var yq=[{id:`grey`,value:`var(--dv-tab-group-color-grey)`,label:`Grey`},{id:`blue`,value:`var(--dv-tab-group-color-blue)`,label:`Blue`},{id:`red`,value:`var(--dv-tab-group-color-red)`,label:`Red`},{id:`yellow`,value:`var(--dv-tab-group-color-yellow)`,label:`Yellow`},{id:`green`,value:`var(--dv-tab-group-color-green)`,label:`Green`},{id:`pink`,value:`var(--dv-tab-group-color-pink)`,label:`Pink`},{id:`purple`,value:`var(--dv-tab-group-color-purple)`,label:`Purple`},{id:`cyan`,value:`var(--dv-tab-group-color-cyan)`,label:`Cyan`},{id:`orange`,value:`var(--dv-tab-group-color-orange)`,label:`Orange`}],bq=class{constructor(e,t=!0){this._entries=e.slice(),this._byId=new Map(e.map(e=>[e.id,e])),this._enabled=t}get enabled(){return this._enabled}set enabled(e){this._enabled=e}setEntries(e){this._entries=e.slice(),this._byId=new Map(e.map(e=>[e.id,e]))}entries(){return this._entries}has(e){return this._byId.has(e)}get(e){return this._byId.get(e)}defaultId(){return this._entries[0]?.id}resolveValue(e){if(!this._enabled||!e)return;let t=this._byId.get(e);return t?t.value:e}},xq;function Sq(){return xq??=new bq(yq,!0),xq}function Cq(e,t,n){let r=(n??Sq()).resolveValue(t);r===void 0?e.style.removeProperty(`--dv-tab-group-color`):e.style.setProperty(`--dv-tab-group-color`,r)}function wq(e,t){return(t??Sq()).resolveValue(e)}var Tq=class extends Y{get element(){return this._element}constructor(e){super(),this._palette=e,this._onClick=new X,this.onClick=this._onClick.event,this._onContextMenu=new X,this.onContextMenu=this._onContextMenu.event,this._element=document.createElement(`div`),this._element.className=`dv-tab-group-chip`,this._element.tabIndex=0,this._label=document.createElement(`span`),this._label.className=`dv-tab-group-chip-label`,this._element.appendChild(this._label),this.addDisposables(this._onClick,this._onContextMenu,new eq(this._element,{onLongPress:e=>{this._onContextMenu.fire(e)}}),Z(this._element,`click`,e=>{this._onClick.fire(e)}),Z(this._element,`contextmenu`,e=>{this._onContextMenu.fire(e)}))}init(e){this._tabGroup=e.tabGroup,this.updateColor(e.tabGroup.color),this.updateLabel(e.tabGroup.label),this.updateCollapsed(e.tabGroup.collapsed),this.addDisposables(e.tabGroup.onDidChange(()=>{this._tabGroup&&(this.updateColor(this._tabGroup.color),this.updateLabel(this._tabGroup.label))}),e.tabGroup.onDidCollapseChange(e=>{this.updateCollapsed(e)}),this._onClick.event(()=>{var e;(e=this._tabGroup)==null||e.toggle()}))}update(e){this._tabGroup=e.tabGroup,this.updateColor(e.tabGroup.color),this.updateLabel(e.tabGroup.label),this.updateCollapsed(e.tabGroup.collapsed)}updateColor(e){Cq(this._element,e,this._palette),Q(this._element,`dv-tab-group-chip--accent-off`,this._palette?.enabled===!1)}updateLabel(e){this._label.textContent=e,Q(this._label,`dv-tab-group-chip-label--empty`,!e)}updateCollapsed(e){Q(this._element,`dv-tab-group-chip--collapsed`,e)}},Eq=`dv-tab-group-chip-continuation`,Dq=8,Oq=class{get underlines(){return this._underlines}constructor(e){this._ctx=e,this._underlines=new Map,this._continuationMarkers=new Map,this._rafId=null}positionUnderlines(){requestAnimationFrame(()=>{this._positionUnderlinesSync()})}trackUnderlines(){this._rafId!==null&&cancelAnimationFrame(this._rafId);let e=performance.now(),t=()=>{this._positionUnderlinesSync(),this._rafId=performance.now()-e<250?requestAnimationFrame(t):null};this._rafId=requestAnimationFrame(t)}syncUnderlineElements(e){for(let t of e)if(!this._underlines.has(t)){let e=document.createElement(`div`);e.className=`dv-tab-group-underline`,this._ctx.tabsList.appendChild(e),this._underlines.set(t,e)}for(let[t,n]of this._underlines)e.has(t)||(n.remove(),this._underlines.delete(t),this._clearContinuationMarkers(t))}getUnderline(e){return this._underlines.get(e)}dispose(){this._rafId!==null&&(cancelAnimationFrame(this._rafId),this._rafId=null);for(let[,e]of this._underlines)e.remove();this._underlines.clear(),this._clearContinuationMarkers()}_syncContinuationMarkers(e,t){let n=this._continuationMarkers.get(e);for(n||(n=[],this._continuationMarkers.set(e,n));n.length<t;){let e=document.createElement(`div`);e.className=Eq,this._ctx.tabsList.appendChild(e),n.push(e)}for(;n.length>t;)n.pop()?.remove();return n}_clearContinuationMarkers(e){if(e===void 0){for(let[,e]of this._continuationMarkers)for(let t of e)t.remove();this._continuationMarkers.clear();return}let t=this._continuationMarkers.get(e);if(t){for(let e of t)e.remove();this._continuationMarkers.delete(e)}}_positionUnderlinesSync(){let e=this._ctx.tabsList.getBoundingClientRect(),t=this._ctx.getTabGroups(),n=this._ctx.getDirection()===`vertical`,r=this._ctx.tabsList.classList.contains(uq);r||this._clearContinuationMarkers();let i=n?e.width:e.height,a=this._ctx.getActivePanelId(),o=this._ctx.getTabMap();for(let s of t){let t=this._underlines.get(s.id);if(!t)continue;let c=s.panelIds;if(c.length===0){t.style.display=`none`;continue}if(t.style.display=``,r){this._positionWrappedUnderline(t,s,e,o,n);continue}let l=this._ctx.getChipElement(s.id),u;if(l){let t=l.getBoundingClientRect(),r=getComputedStyle(l),i=n?Number.parseFloat(r.marginTop)||0:Number.parseFloat(r.marginLeft)||0;u=n?t.top-e.top-i:t.left-e.left-i}else{let t=c[0],r=o.get(t);if(r){let t=r.value.element.getBoundingClientRect();u=n?t.top-e.top:t.left-e.left}else u=0}let d=c[c.length-1],f=o.get(d);if(!f){n?(t.style.top=`${u}px`,t.style.height=`0px`,t.style.left=``,t.style.width=``):(t.style.left=`${u}px`,t.style.width=`0px`,t.style.top=``,t.style.height=``);continue}let p=f.value.element.getBoundingClientRect(),m=n?p.bottom-e.top:p.right-e.left,h=m-u;if((s.collapsed||s.panelIds.some(e=>o.get(e)?.value.element.classList.contains(`dv-tab--group-expanding`)))&&l){let t=l.getBoundingClientRect(),r=n?t.top+t.height/2-e.top:t.left+t.width/2-e.left,i=0,a=0;for(let e of s.panelIds){let t=o.get(e);if(!t)continue;let r=t.value.element;n?(i+=r.getBoundingClientRect().height,a+=r.scrollHeight):(i+=r.getBoundingClientRect().width,a+=r.scrollWidth)}let c=a>0?Math.min(1,i/a):0;u=r+(u-r)*c,m=r+(m-r)*c,h=Math.max(0,m-u)}n?(t.style.top=`${u}px`,t.style.height=`${Math.max(0,h)}px`,t.style.left=``,t.style.width=``,t.style.bottom=``):(t.style.left=`${u}px`,t.style.width=`${Math.max(0,h)}px`,t.style.top=``,t.style.height=``,t.style.bottom=``),this.applyShape(t,s,u,h,i,a,e,n)}}_positionWrappedUnderline(e,t,n,r,i){let a=wq(t.color,this._ctx.getColorPalette());if(a===void 0){e.style.display=`none`,this._clearContinuationMarkers(t.id);return}let{runs:o,firstRun:s}=this._computeWrappedRuns(t,n,r,i);if(o.length===0){e.style.display=`none`,this._clearContinuationMarkers(t.id);return}this._positionContinuationMarkers(t.id,o,s,a,i);let c=Math.min(...o.map(e=>e.left)),l=Math.max(...o.map(e=>e.right)),u=Math.min(...o.map(e=>e.top)),d=Math.max(...o.map(e=>e.bottom)),f=i?Math.max(0,l-c):n.width,p=i?n.height:Math.max(0,d-u);e.style.left=i?`${c}px`:`0px`,e.style.top=i?`0px`:`${u}px`,e.style.bottom=`auto`,e.style.width=`${f}px`,e.style.height=`${p}px`,e.style.backgroundColor=``;let{svg:m,path:h}=this.ensureSvgPath(e);m.setAttribute(`width`,String(f)),m.setAttribute(`height`,String(p)),h.setAttribute(`stroke`,a),h.setAttribute(`stroke-width`,`2`);let g=this._ctx.getHeaderPosition(),_=i?g===`right`:g===`bottom`;h.setAttribute(`d`,this._wrappedPathData(o,i,_,c,u,2))}_computeWrappedRuns(e,t,n,r){let i=[],a;for(let o of e.panelIds){let e=n.get(o);if(!e)continue;let s=e.value.element.getBoundingClientRect();if(s.width===0&&s.height===0)continue;let c=s.top-t.top,l=s.bottom-t.top,u=s.left-t.left,d=s.right-t.left,f=r?u:c,p=i.find(e=>Math.abs((r?e.left:e.top)-f)<=2);p?(p.top=Math.min(p.top,c),p.bottom=Math.max(p.bottom,l),p.left=Math.min(p.left,u),p.right=Math.max(p.right,d)):(p={top:c,bottom:l,left:u,right:d},i.push(p)),a??=p}return{runs:i,firstRun:a}}_wrappedPathData(e,t,n,r,i,a){let o=``;for(let s of e)if(t){let e=n?s.right-r-a/2:s.left-r+a/2;o+=`M ${e},${s.top} L ${e},${s.bottom} `}else{let e=n?s.top-i+a/2:s.bottom-i-a/2;o+=`M ${s.left},${e} L ${s.right},${e} `}return o.trim()}_positionContinuationMarkers(e,t,n,r,i){let a=t.filter(e=>e!==n),o=this._syncContinuationMarkers(e,a.length);a.forEach((e,t)=>{let n=o[t];if(n.style.backgroundColor=r,i){let t=(e.left+e.right)/2;n.style.left=`${t-Dq/2}px`,n.style.top=`${e.top}px`}else{let t=(e.top+e.bottom)/2;n.style.left=`${e.left}px`,n.style.top=`${t-Dq/2}px`}})}ensureSvgPath(e){let t=e.firstElementChild;if(t?.tagName===`svg`)return{svg:t,path:t.firstElementChild};e.replaceChildren();let n=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);n.style.display=`block`;let r=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return r.setAttribute(`fill`,`none`),n.appendChild(r),e.appendChild(n),{svg:n,path:r}}},kq=class extends Oq{_applyStraightLine(e,t,n,r,i,a,o){let s=o?i:r,c=o?r:i;e.setAttribute(`width`,String(s)),e.setAttribute(`height`,String(c)),n.style.width=`${s}px`,n.style.height=`${c}px`,t.setAttribute(`d`,o?`M ${a},0 L ${a},${r}`:`M 0,${a} L ${r},${a}`)}applyShape(e,t,n,r,i,a,o,s){let c=i,l=r,u=wq(t.color,this._ctx.getColorPalette());if(l<=0||c<=0||u===void 0){e.style.display=`none`;return}e.style.display=``;let d;a&&t.panelIds.includes(a)&&(d=this._ctx.getTabMap().get(a));let{svg:f,path:p}=this.ensureSvgPath(e);p.setAttribute(`stroke`,u),p.setAttribute(`stroke-width`,`2`);let m=this._ctx.getHeaderPosition(),h=!s&&m===`bottom`,g=s&&m===`right`,_,v;if(s?(_=g?c-2:2,v=g?2:c-2):(_=h?2:c-2,v=h?c-2:2),!d){this._applyStraightLine(f,p,e,l,c,_,s);return}let y=d.value.element.getBoundingClientRect(),b,x;if(s?(b=Math.max(0,y.top-o.top-n),x=Math.min(l,y.bottom-o.top-n)):(b=Math.max(0,y.left-o.left-n),x=Math.min(l,y.right-o.left-n)),x<=b){this._applyStraightLine(f,p,e,l,c,_,s);return}let S=v>_?1:-1;if(s){let t=c,n=l;f.setAttribute(`width`,String(t)),f.setAttribute(`height`,String(n)),e.style.width=`${t}px`,e.style.height=`${n}px`;let r=[`M ${_},0`,`L ${_},${b-6}`,`Q ${_},${b} ${_+S*6},${b}`,`L ${v-S*6},${b}`,`Q ${v},${b} ${v},${b+6}`,`L ${v},${x-6}`,`Q ${v},${x} ${v-S*6},${x}`,`L ${_+S*6},${x}`,`Q ${_},${x} ${_},${x+6}`,`L ${_},${n}`].join(` `);p.setAttribute(`d`,r)}else{let t=l,n=c;f.setAttribute(`width`,String(t)),f.setAttribute(`height`,String(n)),e.style.width=`${t}px`,e.style.height=`${n}px`;let r=[`M 0,${_}`,`L ${b-6},${_}`,`Q ${b},${_} ${b},${_+S*6}`,`L ${b},${v-S*6}`,`Q ${b},${v} ${b+6},${v}`,`L ${x-6},${v}`,`Q ${x},${v} ${x},${v-S*6}`,`L ${x},${_+S*6}`,`Q ${x},${_} ${x+6},${_}`,`L ${t},${_}`].join(` `);p.setAttribute(`d`,r)}}},Aq=class extends Oq{applyShape(e,t,n,r,i,a,o,s){let c=wq(t.color,this._ctx.getColorPalette());r<=0||c===void 0?e.style.display=`none`:(e.style.display=``,e.firstElementChild&&e.replaceChildren(),e.style.backgroundColor=c,s?(e.style.width=`2px`,e.style.height=`${r}px`):(e.style.width=`${r}px`,e.style.height=`2px`))}},jq=new Map,Mq=class{get chipRenderers(){return this._chipRenderers}get groupUnderlines(){return this._indicator?.underlines??jq}get skipNextCollapseAnimation(){return this._skipNextCollapseAnimation}set skipNextCollapseAnimation(e){this._skipNextCollapseAnimation=e}constructor(e,t){this._ctx=e,this._callbacks=t,this._chipRenderers=new Map,this._indicator=null,this._skipNextCollapseAnimation=!1,this._pendingTransitionCleanups=new Map}update(){let e=this._ctx.group.model.getTabGroups(),t=new Set;for(let n of e)t.add(n.id),this._ensureChipForGroup(n),this._positionChipForGroup(n);for(let[e,r]of this._chipRenderers)if(!t.has(e)){var n;r.chip.element.remove(),r.chip.dispose(),(n=r.dragSourcesDisposable)==null||n.dispose(),r.disposable.dispose(),this._chipRenderers.delete(e)}this._updateTabGroupClasses()}refreshAccents(){for(let n of this._ctx.group.model.getTabGroups()){var e,t;let r=this._chipRenderers.get(n.id);r==null||(t=(e=r.chip).update)==null||t.call(e,{tabGroup:n})}this._updateTabGroupClasses()}positionAllChips(){if(this._chipRenderers.size!==0)for(let e of this._ctx.group.model.getTabGroups())this._positionChipForGroup(e)}updateDirection(){let e=this._ctx.getDirection()===`vertical`;for(let[,t]of this._chipRenderers){let n=e?[`top`]:[`left`];t.dropTarget.setTargetZones(n),t.pointerDropTarget.setTargetZones(n)}}clearChipDropOverlays(){for(let[,n]of this._chipRenderers){var e,t;(e=n.dropTarget)==null||e.clearOverlay(),(t=n.pointerDropTarget)==null||t.clearOverlay()}}snapshotChipSizes(){let e=this._ctx.getDirection()===`vertical`,t=new Map;for(let[n,r]of this._chipRenderers){let i=r.chip.element.getBoundingClientRect();t.set(n,e?i.height:i.width)}return t}positionUnderlines(){var e;(e=this._indicator)==null||e.positionUnderlines()}trackUnderlines(){var e;(e=this._indicator)==null||e.trackUnderlines()}setGroupDragImage(e,t,n){if(!e.dataTransfer)return;let r=this._ctx.getDirection()===`vertical`,i=this._ctx.tabsList.cloneNode(!0);r?(i.classList.remove(`dv-tabs-container-vertical`,`dv-vertical`),i.classList.add(`dv-horizontal`),i.style.writingMode=`horizontal-tb`,i.style.height=`${this._ctx.tabsList.offsetWidth}px`):i.style.height=`${this._ctx.tabsList.offsetHeight}px`,i.style.width=`auto`,i.style.overflow=`visible`,i.style.pointerEvents=`none`;let a=Array.from(i.children),o=Array.from(this._ctx.tabsList.children);for(let e=a.length-1;e>=0;e--)o[e]!==n&&a[e].remove();let s=document.createElement(`div`);s.className=`dv-groupview dv-active-group`,s.style.position=`fixed`,s.style.top=`-10000px`,s.style.left=`0px`,s.style.height=`auto`,s.style.width=`auto`,s.style.pointerEvents=`none`;let c=document.createElement(`div`);c.className=`dv-tabs-and-actions-container`,c.style.height=`auto`,c.style.width=`auto`,s.appendChild(c),c.appendChild(i),this._ctx.accessor.element.appendChild(s);let l=i.querySelector(`.dv-tab-group-chip`),u=n.getBoundingClientRect(),d=e.clientX-u.left,f=e.clientY-u.top;if(l){let t=l.getBoundingClientRect(),n=s.getBoundingClientRect(),r=t.left-n.left+d,i=t.top-n.top+f;e.dataTransfer.setDragImage(s,r,i)}else e.dataTransfer.setDragImage(s,d,f);requestAnimationFrame(()=>{s.remove()})}cleanupTransition(e){var t;(t=this._pendingTransitionCleanups.get(e))==null||t(),this._pendingTransitionCleanups.delete(e)}updateDragAndDropState(){let e=tq(this._ctx.accessor.options);for(let i of this._chipRenderers.values()){var t,n,r;i.chip.element.draggable=e.html5,(t=i.html5DragSource)==null||t.setDisabled(!e.html5),(n=i.pointerDragSource)==null||n.setDisabled(!e.pointer),(r=i.pointerDragSource)==null||r.setTouchOnly(!e.pointerHandlesMouse)}}disposeChipDrag(e){var t;let n=this._chipRenderers.get(e);n&&((t=n.dragSourcesDisposable)==null||t.dispose(),n.html5DragSource=void 0,n.pointerDragSource=void 0,n.dragSourcesDisposable=void 0)}_buildChipGhostElement(e){let t=getComputedStyle(e),n=e.cloneNode(!0);return Array.from(t).forEach(e=>{n.style.setProperty(e,t.getPropertyValue(e),t.getPropertyPriority(e))}),n.style.position=`absolute`,n}disposeAll(){var e;(e=this._indicator)==null||e.dispose(),this._indicator=null;for(let[,e]of this._pendingTransitionCleanups)e();this._pendingTransitionCleanups.clear();for(let[,e]of this._chipRenderers){var t;e.chip.element.remove(),e.chip.dispose(),(t=e.dragSourcesDisposable)==null||t.dispose(),e.disposable.dispose()}this._chipRenderers.clear()}_ensureIndicator(){let e=(this._ctx.accessor.options.theme?.tabGroupIndicator??`wrap`)===`none`?Aq:kq;this._indicator&&!(this._indicator instanceof e)&&(this._indicator.dispose(),this._indicator=null),this._indicator??=new e({tabsList:this._ctx.tabsList,getTabGroups:()=>this._ctx.group.model.getTabGroups(),getActivePanelId:()=>this._ctx.group.activePanel?.id,getTabMap:()=>this._ctx.getTabMap(),getChipElement:e=>this._chipRenderers.get(e)?.chip.element,getDirection:()=>this._ctx.getDirection(),getHeaderPosition:()=>this._ctx.group.model.headerPosition,getColorPalette:()=>this._ctx.accessor.tabGroupColorPalette})}_createChipDragSources(e,t){let n=tq(this._ctx.accessor.options);e.element.draggable=n.html5;let r=fW.getInstance(),i=()=>(r.setData([new uW(this._ctx.accessor.id,this._ctx.group.id,null,t.id)],uW.prototype),{dispose:()=>{r.clearData(uW.prototype)}}),a=NK.createDragSource(e.element,{getData:i,disabled:!n.html5,isCancelled:()=>!tq(this._ctx.accessor.options).html5,onDragStart:n=>{`dataTransfer`in n&&n.dataTransfer&&this.setGroupDragImage(n,t,e.element),this._callbacks.onChipDragStart(t,e,n)},onDragEnd:n=>{var r,i;(r=(i=this._callbacks).onChipDragEnd)==null||r.call(i,t,e,n)}}),o=()=>{r.clearData(uW.prototype)};e.element.addEventListener(`dragend`,o,{once:!0});let s=PK.createDragSource(e.element,{getData:i,disabled:!n.pointer,touchOnly:!n.pointerHandlesMouse,isCancelled:()=>!tq(this._ctx.accessor.options).pointer,createGhost:()=>({element:this._buildChipGhostElement(e.element),offsetX:8,offsetY:8}),onDragStart:n=>{this._callbacks.onChipDragStart(t,e,n)}});return{html5DragSource:a,pointerDragSource:s,disposable:{dispose:()=>{a.dispose(),s.dispose(),e.element.removeEventListener(`dragend`,o)}}}}_ensureChipForGroup(e){let t=this._chipRenderers.get(e.id);if(t){if(!t.html5DragSource){let n=this._createChipDragSources(t.chip,e);t.html5DragSource=n.html5DragSource,t.pointerDragSource=n.pointerDragSource,t.dragSourcesDisposable=n.disposable}return}let n=this._ctx.accessor.options.createTabGroupChipComponent,r=n?n(e):new Tq(this._ctx.accessor.tabGroupColorPalette);r.init({tabGroup:e,api:this._ctx.accessor.api});let i=this._createChipDragSources(r,e),a=[e.onDidChange(()=>{var t;(t=r.update)==null||t.call(r,{tabGroup:e}),this._updateTabGroupClasses()}),e.onDidPanelChange(()=>{this._positionChipForGroup(e),this._updateTabGroupClasses()}),e.onDidCollapseChange(()=>{this._updateTabGroupClasses()})],o=t=>{var n;(n=this._chipRenderers.get(e.id))==null||(n=n.pointerDragSource)==null||n.cancelPending(),this._callbacks.onChipContextMenu(e,t)};r instanceof Tq?a.push(r.onContextMenu(o)):a.push(new eq(r.element,{onLongPress:o}),Z(r.element,`contextmenu`,o));let s={acceptedTargetZones:this._ctx.getDirection()===`vertical`?[`top`]:[`left`],overlayModel:{activationSize:{value:100,type:`percentage`}},canDisplayOverlay:(e,t)=>{if(this._ctx.group.locked||this._ctx.accessor.options.disableDnd)return!1;let n=pW();return this._ctx.accessor.id===n?.viewId?!(this._ctx.accessor.options.theme?.tabAnimation===`smooth`&&!n.tabGroupId):this._ctx.group.model.canDisplayOverlay(e,t,`tab`)}},c=NK.createDropTarget(r.element,s),l=PK.createDropTarget(r.element,s),u=t=>{this._callbacks.onChipDrop(e,t)};a.push(c,c.onDrop(u),l,l.onDrop(u));let d=new Y(...a);this._chipRenderers.set(e.id,{chip:r,html5DragSource:i.html5DragSource,pointerDragSource:i.pointerDragSource,dragSourcesDisposable:i.disposable,disposable:d,dropTarget:c,pointerDropTarget:l}),e.collapsed&&(this._skipNextCollapseAnimation=!0)}_positionChipForGroup(e){let t=this._chipRenderers.get(e.id);if(!t)return;let n=t.chip.element,r=e.panelIds;if(r.length===0){n.remove();return}let i=r[0],a=this._ctx.getTabMap().get(i);if(!a){n.remove();return}let o=a.value.element;n.nextSibling!==o&&this._ctx.tabsList.insertBefore(n,o)}_updateTabGroupClasses(){let e=this._ctx.group.model.getTabGroups(),t=this._ctx.getTabs(),n=this._ctx.getTabMap(),r=!1,i=new Map;for(let t of e)for(let e of t.panelIds)i.set(e,t);for(let e of t){let t=e.value,n=t.panel.id,o=i.get(n),s=!!o;if(Q(t.element,`dv-tab--grouped`,s),o){let e=o.panelIds,i=e[0]===n,s=e[e.length-1]===n;Q(t.element,`dv-tab--group-first`,i),Q(t.element,`dv-tab--group-last`,s),Cq(t.element,o.color,this._ctx.accessor.tabGroupColorPalette);let c=t.element.classList.contains(`dv-tab--group-collapsed`);if(!o.collapsed&&c){var a;r=!0,t.element.classList.remove(`dv-tab--group-collapsed`),t.element.classList.add(`dv-tab--group-expanding`),(a=this._pendingTransitionCleanups.get(n))==null||a();let e=()=>{t.element.classList.remove(`dv-tab--group-expanding`),t.element.style.removeProperty(`width`),t.element.removeEventListener(`transitionend`,e),clearTimeout(i),this._pendingTransitionCleanups.delete(n)},i=setTimeout(e,300);this._pendingTransitionCleanups.set(n,e),t.element.addEventListener(`transitionend`,e)}}else Q(t.element,`dv-tab--group-first`,!1),Q(t.element,`dv-tab--group-last`,!1),t.element.classList.remove(`dv-tab--group-collapsed`,`dv-tab--group-expanding`),t.element.style.removeProperty(`width`),t.element.style.removeProperty(`--dv-tab-group-color`)}let o=new Set;for(let t of e)if(o.add(t.id),t.collapsed&&t.panelIds.some(e=>{let t=n.get(e);return t&&!t.value.element.classList.contains(`dv-tab--group-collapsed`)})){if(this._skipNextCollapseAnimation){let e=[];for(let r of t.panelIds){let t=n.get(r);t&&(t.value.element.style.transition=`none`,t.value.element.classList.add(`dv-tab--group-collapsed`),e.push(t.value.element))}if(e.length>0){e[0].offsetHeight;for(let t of e)t.style.removeProperty(`transition`)}}else{r=!0;let e=this._ctx.getDirection()===`vertical`;for(let r of t.panelIds){let t=n.get(r);if(t&&!t.value.element.classList.contains(`dv-tab--group-collapsed`)){let n=t.value.element.getBoundingClientRect();e?t.value.element.style.height=`${n.height}px`:t.value.element.style.width=`${n.width}px`,t.value.element.offsetHeight,t.value.element.classList.add(`dv-tab--group-collapsed`)}}}}this._skipNextCollapseAnimation=!1,this._ensureIndicator(),this._indicator&&(this._indicator.syncUnderlineElements(o),r?this._indicator.trackUnderlines():this._indicator.positionUnderlines())}};function Nq(e,t){return t===`vertical`?e.height:e.width}function Pq(e,t){return t===`vertical`?e.top:e.left}function Fq(e,t){return t===`vertical`?e.clientY:e.clientX}var Iq=class extends Y{get _tabs(){return this.host.tabItems}get _tabMap(){return this.host.tabMap}get _tabsList(){return this.host.tabsList}get _direction(){return this.host.direction}get group(){return this.host.groupPanel}get accessor(){return this.host.component}get _tabGroupManager(){return this.host.tabGroupManager}get _wrapMode(){return this._tabsList.classList.contains(uq)}get animState(){return this._animState}set animState(e){this._animState=e}get pendingCollapse(){return this._pendingCollapse}set pendingCollapse(e){this._pendingCollapse=e}set voidContainerElement(e){this._voidContainer=e}constructor(e){super(),this.host=e,this._animState=null,this._pendingMarginCleanups=new Map,this._pendingCollapse=!1,this._flipTransitionCleanup=null,this._voidContainer=null,this._extendedDropZone=null,this._pointerInsideTabsList=!1,this._wrapIndicatorEl=null,this.addDisposables({dispose:()=>{var e;(e=this._flipTransitionCleanup)==null||e.call(this)}})}setExtendedDropZone(e){this._extendedDropZone=e}setExternalInsertionIndex(e){this._animState&&e!==this._animState.currentInsertionIndex&&(this._animState.currentInsertionIndex=e,this.applyDragOverTransforms())}clearExternalAnimState(){this._animState&&(this.resetTabTransforms(),this._animState.sourceIndex===-1?this._animState=null:this._animState.currentInsertionIndex=null)}snapshotTabPositions(){let e=new Map;for(let t of this._tabs)e.set(t.value.panel.id,t.value.element.getBoundingClientRect());return e}_mainAxisSize(e){return Nq(e,this._direction)}_mainAxisStart(e){return Pq(e,this._direction)}_mainAxisCoord(e,t){return Fq({clientX:e,clientY:t},this._direction)}get _gapMarginProperty(){return this._direction===`vertical`?`margin-top`:`margin-left`}getAverageTabSize(){if(this._tabs.length===0)return 0;let e=0;for(let t of this._tabs)e+=this._mainAxisSize(t.value.element.getBoundingClientRect());return e/this._tabs.length}handlePointerDragMove(e,t){let n=VW(this._tabsList).elementFromPoint(e,t);n&&(this._tabsList.contains(n)||this._extendedDropZone&&this._extendedDropZone.contains(n))?(this._pointerInsideTabsList=!0,this.processDragOver(e,t)):this._pointerInsideTabsList&&(this._pointerInsideTabsList=!1,this.processDragLeave(n))}handlePointerDragEnd(e){if(e&&this._animState&&this._animState.sourceIndex!==-1&&this._animState.currentInsertionIndex!==null&&this.isPointInsideTabsList(e.clientX,e.clientY)){let t=this._animState.sourceTabGroupId;if(t){let e=this._animState.currentInsertionIndex;this._animState=null,this.commitGroupMove(t,e)}else this.commitPointerReorder(e.pointerEvent)}this._pointerInsideTabsList=!1,this.resetDragAnimation()}isPointInsideTabsList(e,t){let n=VW(this._tabsList).elementFromPoint(e,t);return!!n&&this._tabsList.contains(n)}resolveTabDrop(e){let t=e.currentInsertionIndex;if(t===null)return null;let{sourceIndex:n,targetTabGroupId:r}=e,i=t-+(n!==-1&&n<t);return i===n&&r===(this.group.model.getTabGroupForPanel(e.sourceTabId)?.id??null)?null:{index:i,targetTabGroupId:r}}commitPointerReorder(e){let t=this._animState;if(t?.currentInsertionIndex==null)return;let n=this.resolveTabDrop(t);this._animState=null,this.clearWrapDropIndicator(),this.uncollapseSourceTab(t.sourceTabId),n&&this.host.fireDrop($({event:e},n))}processDragOver(e,t){if(this.accessor.options.disableDnd||(this._dropStaleAnimState(),!this._animState&&!this._initAnimStateForExternalDrag()))return!1;if(this._animState.sourceIndex!==-1){var n;(n=this.group.model.dropTargetContainer)==null||(n=n.model)==null||n.clear()}return this.handleDragOver({clientX:e,clientY:t}),!0}_dropStaleAnimState(){if(!this._animState)return;let e=pW();e?.tabGroupId&&e.groupId!==this.group.id&&this._animState.sourceTabGroupId!==e.tabGroupId&&(this._animState=null)}_initAnimStateForExternalDrag(){let e=pW();if(this.accessor.options.theme?.tabAnimation==="default"&&!e?.tabGroupId||!e||!(e.panelId||e.tabGroupId)||e.groupId===this.group.id)return!1;let t=this.getAverageTabSize();return this._animState=e.tabGroupId?this._makeGroupDragAnimState(e,t):this._makeTabDragAnimState(e,t),!0}_makeGroupDragAnimState(e,t){let n=this.accessor.getPanel(e.groupId)?.model.getTabGroups().find(t=>t.id===e.tabGroupId),r=t*(n?.panelIds.length??1)+t;return{sourceTabId:``,sourceIndex:-1,tabPositions:this.snapshotTabPositions(),chipSizes:this._tabGroupManager.snapshotChipSizes(),currentInsertionIndex:null,targetTabGroupId:null,sourceTabGroupId:e.tabGroupId,sourceGroupPanelIds:n?new Set(n.panelIds):new Set,sourceChipSize:t,cursorOffsetFromDragStart:r/2,sourceGapSize:r,containerStart:this._mainAxisStart(this._tabsList.getBoundingClientRect())}}_makeTabDragAnimState(e,t){return{sourceTabId:e.panelId,sourceIndex:-1,tabPositions:this.snapshotTabPositions(),chipSizes:this._tabGroupManager.snapshotChipSizes(),currentInsertionIndex:null,targetTabGroupId:null,sourceTabGroupId:null,sourceGroupPanelIds:null,sourceChipSize:0,cursorOffsetFromDragStart:t/2,sourceGapSize:t,containerStart:this._mainAxisStart(this._tabsList.getBoundingClientRect())}}processDragLeave(e){this._animState&&(e&&this._tabsList.contains(e)||(e&&this._extendedDropZone?.contains(e)?(this.resetTabTransforms(),this._animState.currentInsertionIndex=null):this._voidContainer&&e&&(e===this._voidContainer||this._voidContainer.contains(e))||(this.resetTabTransforms(),this._animState.sourceIndex===-1?(this.clearHeaderAnchorOverlay(),this._animState=null):this._animState.currentInsertionIndex=null)))}clearHeaderAnchorOverlay(){var e;let t=this.group.model.dropTargetContainer,n=t?.renderedOutline;n&&![this._tabsList,this._voidContainer,this._extendedDropZone].some(e=>e?.contains(n))||t==null||(e=t.model)==null||e.clear()}handleDragOver(e){if(!this._animState)return;if(this._wrapMode&&!this._animState.sourceTabGroupId){this.handleWrappedDragOver(e.clientX,e.clientY??0);return}let t=this._mainAxisCoord(e.clientX,e.clientY??0),n=this._buildFirstPanelToGroupMap(),r=this._computeDragOverInsertionIndex(t,n),i=null;if(r!==null&&this._tabGroupManager.chipRenderers.size>0){let e=this._resolveInsertionAgainstTabGroups(t,r,n);r=e.insertionIndex,i=e.targetTabGroupId}(r!==this._animState.currentInsertionIndex||i!==this._animState.targetTabGroupId)&&(this._animState.currentInsertionIndex=r,this._animState.targetTabGroupId=i,this.accessor.options.theme?.tabAnimation===`smooth`&&this.applyDragOverTransforms())}_buildFirstPanelToGroupMap(){let e=new Map;if(this._tabGroupManager.chipRenderers.size===0)return e;for(let t of this.group.model.getTabGroups())t.id!==this._animState.sourceTabGroupId&&t.panelIds.length>0&&e.set(t.panelIds[0],t.id);return e}_computeDragOverInsertionIndex(e,t){let n=this._animState,r=n.sourceGroupPanelIds,i=e-n.cursorOffsetFromDragStart-n.containerStart,a=0,o=null;for(let e=0;e<this._tabs.length;e++){let s=this._tabs[e].value;if(s.panel.id===n.sourceTabId||r?.has(s.panel.id))continue;let c=t.get(s.panel.id);if(c){let t=n.chipSizes.get(c)??0;if(a+t>i){o??=e;break}a+=t}let l=n.tabPositions.get(s.panel.id),u=this._mainAxisSize(l??s.element.getBoundingClientRect());if(a+u/2<=i)a+=u,o=e+1;else{o??=e;break}}return o}_accumulatedSizeUpTo(e,t){let n=this._animState,r=n.sourceGroupPanelIds,i=0;for(let a=0;a<this._tabs.length;a++){let o=this._tabs[a].value;if(o.panel.id===n.sourceTabId||r?.has(o.panel.id))continue;if(a>=e)break;let s=t.get(o.panel.id);s&&(i+=n.chipSizes.get(s)??0);let c=n.tabPositions.get(o.panel.id);i+=this._mainAxisSize(c??o.element.getBoundingClientRect())}return i}_resolveInsertionAgainstTabGroups(e,t,n){let r=!!this._animState.sourceTabGroupId,i=this._accumulatedSizeUpTo(t,n);for(let n of this.group.model.getTabGroups()){let a=this._evaluateTabGroupForInsertion(n,e,t,i,r);if(a)return a.targetTabGroupId?a:this._keepSourceGroupAtOwnSlot(e,a.insertionIndex,i)??a}return this._keepSourceGroupAtOwnSlot(e,t,i)??{insertionIndex:t,targetTabGroupId:null}}_keepSourceGroupAtOwnSlot(e,t,n){let r=this._animState,i=r.sourceIndex;if(r.sourceGroupPanelIds||i===-1||t!==i&&t!==i+1)return null;let a=this.group.model.getTabGroups().find(e=>e.panelIds.includes(r.sourceTabId));if(!a)return null;if(a.panelIds[0]===r.sourceTabId){let t=r.chipSizes.get(a.id)??0;if(e<r.containerStart+n+t)return null}return{insertionIndex:t,targetTabGroupId:a.id}}_evaluateTabGroupForInsertion(e,t,n,r,i){let a=this._resolveGroupRange(e);if(!a)return null;let{firstIdx:o,lastIdx:s}=a,c=n>=o&&n<=s,l=!c&&n===o-1;return!c&&!l?null:i?this._resolveGroupDragTarget(n,o,s,c):this._resolveTabDragTarget(e,t,n,r,o,l)}_resolveGroupRange(e){let t=this._animState,n=t.sourceGroupPanelIds,r=e.panelIds.filter(e=>e!==t.sourceTabId&&!n?.has(e));if(r.length===0)return null;let i=this._tabs.findIndex(e=>e.value.panel.id===r[0]),a=this._tabs.findIndex(e=>e.value.panel.id===r[r.length-1]);return i===-1||a===-1?null:{firstIdx:i,lastIdx:a}}_resolveGroupDragTarget(e,t,n,r){return r?{insertionIndex:e<(t+n+1)/2?t:n+1,targetTabGroupId:null}:{insertionIndex:e,targetTabGroupId:null}}_resolveTabDragTarget(e,t,n,r,i,a){let o=this._animState,s=o.chipSizes.get(e.id)??0;if(a)return this._onlySourceBetween(n,i)?t>=(e.collapsed?o.containerStart+r+s/2:o.containerStart+r+s)?{insertionIndex:i,targetTabGroupId:e.id}:{insertionIndex:n,targetTabGroupId:null}:null;let c=o.containerStart+r+s;return n===i?{insertionIndex:n,targetTabGroupId:t>=c?e.id:null}:{insertionIndex:n,targetTabGroupId:e.id}}_onlySourceBetween(e,t){let n=this._animState;for(let r=e;r<t;r++){let e=this._tabs[r].value.panel.id;if(e!==n.sourceTabId&&!n.sourceGroupPanelIds?.has(e))return!1}return!0}handleWrappedDragOver(e,t){if(!this._animState)return;let n=this.computeWrappedInsertionIndex(e,t);(n!==this._animState.currentInsertionIndex||this._animState.targetTabGroupId!==null)&&(this._animState.currentInsertionIndex=n,this._animState.targetTabGroupId=null,this.updateWrapDropIndicator(n))}computeWrappedInsertionIndex(e,t){let n=this._direction===`vertical`,r=this._wrappedDragEntries();if(r.length===0)return this._tabs.length;let i=n?e:t,a=n?t:e,o=e=>n?e.left:e.top,s=e=>n?e.right:e.bottom,c=e=>n?e.top:e.left,l=e=>n?e.height:e.width,u=this._bucketWrappedLines(r,o,s),d=[...(u.find(e=>i>=e.start&&i<=e.end)??this._nearestWrappedLine(u,i)).items].sort((e,t)=>c(e.rect)-c(t.rect));for(let e of d)if(a<c(e.rect)+l(e.rect)/2)return e.index;return d[d.length-1].index+1}_wrappedDragEntries(){let e=this._animState?.sourceTabId,t=this._animState?.sourceGroupPanelIds,n=[];for(let r=0;r<this._tabs.length;r++){let i=this._tabs[r].value;i.panel.id!==e&&(t?.has(i.panel.id)||n.push({index:r,rect:i.element.getBoundingClientRect()}))}return n}_bucketWrappedLines(e,t,n){let r=[];for(let i of e){let e=t(i.rect),a=r.find(t=>Math.abs(t.start-e)<=2);a?(a.items.push(i),a.end=Math.max(a.end,n(i.rect))):r.push({start:e,end:n(i.rect),items:[i]})}return r.sort((e,t)=>e.start-t.start),r}_nearestWrappedLine(e,t){let n=e=>t<e.start?e.start-t:t-e.end;return e.reduce((e,t)=>n(t)<n(e)?t:e,e[0])}updateWrapDropIndicator(e){this.clearWrapDropIndicator();let t=this._tabs.length;if(t===0)return;let n=this._animState?.sourceTabId;if(e<t){let t=this._tabs[e].value.element;if(this._tabs[e].value.panel.id===n)return;t.classList.add(`dv-tab--reorder-before`),this._wrapIndicatorEl=t}else{let e=this._tabs[t-1].value.element;e.classList.add(`dv-tab--reorder-after`),this._wrapIndicatorEl=e}}clearWrapDropIndicator(){var e;(e=this._wrapIndicatorEl)==null||e.classList.remove(`dv-tab--reorder-before`,`dv-tab--reorder-after`),this._wrapIndicatorEl=null}_removeClassInstantlyBatch(e,t){let n=[];for(let r of e)r.classList.contains(t)&&(r.style.transition=`none`,Q(r,t,!1),n.push(r));if(n.length>0){n[0].getBoundingClientRect();for(let e of n)e.style.removeProperty(`transition`)}}uncollapseSourceTab(e){let t=this._tabMap.get(e);t&&this._removeClassInstantlyBatch([t.value.element],`dv-tab--dragging`)}applyDragOverTransforms(e=!1){if(this._wrapMode)return;if(this._animState?.currentInsertionIndex==null){this.resetTabTransforms();return}if(this._pendingCollapse)return;let t=this._animState.currentInsertionIndex,n=this._computeGapSize(),r=this._computeChipToShift(t);this._applyGapMargins(t,n,r,e)}_computeGapSize(){let e=this._animState;if(e.sourceTabGroupId&&e.sourceGroupPanelIds)return e.sourceGapSize;let t=e.tabPositions.get(e.sourceTabId);return t?this._mainAxisSize(t):this.getAverageTabSize()}_computeChipToShift(e){if(this._tabGroupManager.chipRenderers.size===0)return null;for(let t of this.group.model.getTabGroups()){let n=this._chipToShiftForGroup(t,e);if(n!==void 0)return n}return null}_chipToShiftForGroup(e,t){let n=this._animState;if(e.id===n.sourceTabGroupId||e.panelIds.includes(n.sourceTabId))return;let r=e.panelIds.filter(e=>e!==n.sourceTabId&&!n.sourceGroupPanelIds?.has(e));if(r.length===0)return;let i=this._tabs.findIndex(e=>e.value.panel.id===r[0]);if((!n.targetTabGroupId||n.targetTabGroupId===e.id&&e.collapsed)&&!(i<t)){if(this._onlySourceBetween(t,i)){let t=this._tabGroupManager.chipRenderers.get(e.id);if(t)return t.chip.element}return null}}_applyGapMargins(e,t,n,r){let i=this._animState,a=i.sourceGroupPanelIds,o=!1;for(let[e,t]of this._tabGroupManager.chipRenderers)e!==i.sourceTabGroupId&&this._clearMargin(t.chip.element,r);n&&(this._setMargin(n,`${t}px`,r),o=!0);for(let n=0;n<this._tabs.length;n++){let s=this._tabs[n].value;s.panel.id!==i.sourceTabId&&(a?.has(s.panel.id)||(!o&&n>=e?(this._setMargin(s.element,`${t}px`,r),o=!0):this._clearMargin(s.element,r)))}this._tabGroupManager.trackUnderlines()}_shiftingClass(e){return e.classList.contains(`dv-tab-group-chip`)?`dv-tab-group-chip--shifting`:`dv-tab--shifting`}_setMargin(e,t,n){let r=this._gapMarginProperty;n?(e.style.transition=`none`,e.style.setProperty(r,t),e.getBoundingClientRect(),e.style.removeProperty(`transition`)):e.style.setProperty(r,t),Q(e,this._shiftingClass(e),!0)}_clearMargin(e,t){let n=this._shiftingClass(e),r=this._gapMarginProperty,i=this._pendingMarginCleanups.get(e);if(i&&i(),t||!e.style.getPropertyValue(r))e.style.removeProperty(r),Q(e,n,!1);else{e.style.setProperty(r,`0px`),Q(e,n,!0);let t=()=>{e.style.removeProperty(r),Q(e,n,!1),e.removeEventListener(`transitionend`,t),clearTimeout(i),this._pendingMarginCleanups.delete(e)},i=setTimeout(t,300);this._pendingMarginCleanups.set(e,t),e.addEventListener(`transitionend`,t)}}resetTabTransforms(){this.clearWrapDropIndicator();for(let[,e]of this._pendingMarginCleanups)e();this._pendingMarginCleanups.clear();for(let e of this._tabs)e.value.element.style.removeProperty(`margin-left`),e.value.element.style.removeProperty(`margin-right`),e.value.element.style.removeProperty(`margin-top`),e.value.element.style.removeProperty(`margin-bottom`),e.value.element.style.removeProperty(`transform`),Q(e.value.element,`dv-tab--shifting`,!1);for(let[,e]of this._tabGroupManager.chipRenderers)e.chip.element.style.removeProperty(`margin-left`),e.chip.element.style.removeProperty(`margin-top`),Q(e.chip.element,`dv-tab-group-chip--shifting`,!1);this._tabGroupManager.positionUnderlines()}commitGroupMove(e,t){let n=pW();if(this._tabGroupManager.disposeChipDrag(e),this._tabGroupManager.clearChipDropOverlays(),this.group.model.getTabGroups().some(t=>t.id===e)){if(this.accessor.options.theme?.tabAnimation===`smooth`){this._clearGroupDragClasses(e);let n=this.snapshotTabPositions();this.resetTabTransforms(),this.group.model.moveTabGroup(e,t),this.runFlipAnimation(n,``,!1)}else this._tabGroupManager.skipNextCollapseAnimation=!0,this.group.model.moveTabGroup(e,t)}else n&&(this.resetTabTransforms(),this.accessor.moveGroupOrPanel({from:{groupId:n.groupId,tabGroupId:n.tabGroupId??e},to:{group:this.group,position:`center`,index:t}}))}_clearGroupDragClasses(e){let t=this._tabGroupManager.chipRenderers.get(e);t&&this._removeClassInstantlyBatch([t.chip.element],`dv-tab-group-chip--dragging`),this._removeClassInstantlyBatch(this._tabs.map(e=>e.value.element),`dv-tab--dragging`);let n=this._tabGroupManager.groupUnderlines.get(e);n&&n.style.removeProperty(`display`),this._tabGroupManager.skipNextCollapseAnimation=!0}resetDragAnimation(){if(this._pendingCollapse=!1,this._animState){this.resetTabTransforms(),this._animState.sourceTabGroupId?this._clearGroupDragClasses(this._animState.sourceTabGroupId):this._removeClassInstantlyBatch(this._tabs.map(e=>e.value.element),`dv-tab--dragging`),this._animState=null;for(let[,e]of this._tabGroupManager.groupUnderlines)e.style.removeProperty(`display`)}}runFlipAnimation(e,t,n=!1,r){if(this._wrapMode)return;let i=!1;for(let a=0;a<this._tabs.length;a++)this._applyFlipTransform(this._tabs[a],a,t,n,e,r)&&(i=!0);i&&this._scheduleFlipReset()}_applyFlipTransform(e,t,n,r,i,a){let o=this._direction===`vertical`,s=e.value.panel.id;if(s===n){if(!r)return!1;let t=e.value.element.getBoundingClientRect();return e.value.element.style.transform=o?`translateY(${t.height}px)`:`translateX(${t.width}px)`,Q(e.value.element,`dv-tab--shifting`,!0),!0}if(a!==void 0&&(t<a.from||t>a.to))return!1;let c=i.get(s);if(!c)return!1;let l=e.value.element.getBoundingClientRect(),u=o?c.top-l.top:c.left-l.left;return Math.abs(u)<1?!1:(e.value.element.style.transform=o?`translateY(${u}px)`:`translateX(${u}px)`,Q(e.value.element,`dv-tab--shifting`,!0),!0)}_scheduleFlipReset(){requestAnimationFrame(()=>{var e;for(let e of this._tabs)e.value.element.style.transform&&(e.value.element.style.transform=``);this._tabGroupManager.trackUnderlines(),(e=this._flipTransitionCleanup)==null||e.call(this);let t=e=>{if(e.propertyName===`transform`){n();for(let e of this._tabs)Q(e.value.element,`dv-tab--shifting`,!1);this._tabGroupManager.positionUnderlines()}},n=()=>{this._tabsList.removeEventListener(`transitionend`,t),this._flipTransitionCleanup=null};this._flipTransitionCleanup=n,this._tabsList.addEventListener(`transitionend`,t)})}},Lq=class extends Y{get _animState(){return this._reorder.animState}set _animState(e){this._reorder.animState=e}get _pendingCollapse(){return this._reorder.pendingCollapse}set _pendingCollapse(e){this._reorder.pendingCollapse=e}get tabItems(){return this._tabs}get tabMap(){return this._tabMap}get tabsList(){return this._tabsList}get groupPanel(){return this.group}get component(){return this.accessor}get tabGroupManager(){return this._tabGroupManager}fireDrop(e){this._onDrop.fire(e)}setOverflowExclude(e){this._overflowExclude=e,this.refreshOverflow()}setForcedOverflow(e){this._forcedOverflow=e,this.refreshOverflow()}refreshOverflow(){this._showTabsOverflowControl&&this.toggleDropdown({reset:!1}),this._applyPinnedSticky()}setPinnedSticky(e){this._pinnedSticky!==e&&(this._pinnedSticky=e,this._applyPinnedSticky())}_applyPinnedSticky(){let e=this._pinnedSticky?this._tabs.filter(e=>this._overflowExclude(e.value.panel.id)):[];if(e.length===0&&!this._hasPinnedStickyStyling)return;for(let e of this._tabs){let t=e.value.element;t.classList.contains(`dv-tab--pinned-sticky`)&&(t.classList.remove(`dv-tab--pinned-sticky`),t.style.removeProperty(`--dv-pinned-sticky-left`))}if(e.length===0){this._hasPinnedStickyStyling=!1;return}let t=e.map(e=>e.value.element.offsetLeft);e.forEach((e,n)=>{let r=e.value.element;r.classList.add(`dv-tab--pinned-sticky`),r.style.setProperty(`--dv-pinned-sticky-left`,`${t[n]}px`)}),this._hasPinnedStickyStyling=!0}get showTabsOverflowControl(){return this._showTabsOverflowControl}set showTabsOverflowControl(e){if(this._showTabsOverflowControl!=e){if(this._showTabsOverflowControl=e,e){let e=new wW(this._tabsList);this._observerDisposable.value=new Y(e,e.onDidChange(e=>{let t=e.hasScrollX||e.hasScrollY;this.toggleDropdown({reset:!t}),this._applyPinnedSticky(),this._tabGroupManager.groupUnderlines.size>0&&this._tabGroupManager.positionUnderlines()}),Z(this._tabsList,`scroll`,()=>{this.toggleDropdown({reset:!1}),this._applyPinnedSticky(),this._tabGroupManager.groupUnderlines.size>0&&this._tabGroupManager.positionUnderlines()}))}else this._observerDisposable.value=hW.NONE}}get element(){return this._element}get tabsListElement(){return this._tabsList}set voidContainer(e){var t;(t=this._voidContainerListeners)==null||t.dispose(),this._voidContainerListeners=null,this._reorder.voidContainerElement=e,e&&(this._voidContainerListeners=new Y(Z(e,`dragover`,e=>{this._animState&&e.preventDefault()}),Z(e,`drop`,e=>{this._animState?.sourceTabGroupId&&this._animState.currentInsertionIndex!==null&&(e.preventDefault(),e.stopPropagation(),this.handleVoidDrop())})))}handleVoidDrop(){if(!this._animState?.sourceTabGroupId)return!1;let e=this._animState.sourceTabGroupId,t=this._animState.currentInsertionIndex??this._tabs.length;return this._animState=null,this._commitGroupMove(e,t),!0}get panels(){return this._tabs.map(e=>e.value.panel.id)}get size(){return this._tabs.length}get tabs(){return this._tabs.map(e=>e.value)}get direction(){return this._direction}set direction(e){if(this._direction!==e){this._direction=e,this._tabsList.setAttribute(`aria-orientation`,e===`vertical`?`vertical`:`horizontal`),this._scrollbar&&(this._scrollbar.orientation=e),EW(this._tabsList,`dv-horizontal`,`dv-vertical`),e===`vertical`?DW(this._tabsList,`dv-tabs-container-vertical`,`dv-vertical`):(EW(this._tabsList,`dv-tabs-container-vertical`),DW(this._tabsList,`dv-horizontal`));for(let t of this._tabs)t.value.setDirection(e);this._tabGroupManager.updateDirection()}}constructor(e,t,n){super(),this.group=e,this.accessor=t,this._observerDisposable=new gW,this._pointerActivation=new gW,this._scrollbar=null,this._tabs=[],this._overflowRefreshPending=!1,this._tabMap=new Map,this.selectedIndex=-1,this._showTabsOverflowControl=!1,this._overflowExclude=()=>!1,this._forcedOverflow=()=>!1,this._pinnedSticky=!1,this._hasPinnedStickyStyling=!1,this._direction=`horizontal`,this._voidContainerListeners=null,this._onTabDragStart=new X,this.onTabDragStart=this._onTabDragStart.event,this._onDrop=new X,this.onDrop=this._onDrop.event,this._onWillShowOverlay=new X,this.onWillShowOverlay=this._onWillShowOverlay.event,this._onOverflowTabsChange=new X,this.onOverflowTabsChange=this._onOverflowTabsChange.event,this._tabsList=document.createElement(`div`),this._tabsList.className=`dv-tabs-container`,this._tabsList.setAttribute(`role`,`tablist`),this._tabsList.setAttribute(`aria-orientation`,this._direction===`vertical`?`vertical`:`horizontal`),this.showTabsOverflowControl=n.showTabsOverflowControl,t.options.scrollbars===`native`?this._element=this._tabsList:(this._scrollbar=new lq(this._tabsList),this._scrollbar.orientation=this.direction,this._element=this._scrollbar.element,this.addDisposables(this._scrollbar)),this._tabGroupManager=new Mq({group:this.group,accessor:this.accessor,tabsList:this._tabsList,getTabs:()=>this._tabs,getTabMap:()=>this._tabMap,getDirection:()=>this._direction},{onChipContextMenu:(e,t)=>{var n;(n=this.accessor.contextMenuService)==null||n.showForChip(e,this.group,t)},onChipDragStart:(e,t,n)=>{this._handleChipDragStart(e,t,n)},onChipDragEnd:()=>{this._reorder.resetDragAnimation()},onChipDrop:(e,t)=>{this._handleChipDrop(e,t)}}),this._reorder=new Iq(this);let r=PK.createDropTarget(this._tabsList,{acceptedTargetZones:[`center`],canDisplayOverlay:()=>!1,isHitTestTransparent:()=>{let e=pW();return e?.viewId!==this.accessor.id||e.groupId!==this.group.id||e.panelId===null&&!e.tabGroupId}});this.addDisposables(r,this._onOverflowTabsChange,this._observerDisposable,this._pointerActivation,this._onWillShowOverlay,this._onDrop,this._onTabDragStart,this._reorder,SK.getInstance().onDragEnd(e=>{this._reorder.handlePointerDragEnd(e)}),SK.getInstance().onDragMove(e=>{this._reorder.handlePointerDragMove(e.clientX,e.clientY)}),Z(this.element,`pointerdown`,e=>{e.defaultPrevented||e.button===0&&this.accessor.doSetGroupActive(this.group)}),Z(this._tabsList,`wheel`,e=>{let t=this._direction===`vertical`,n=t?e.deltaY||e.deltaX:e.deltaX||e.deltaY;if(n===0)return;let r=t?this._tabsList.scrollHeight-this._tabsList.clientHeight:this._tabsList.scrollWidth-this._tabsList.clientWidth;if(r<=0)return;let i=t?this._tabsList.scrollTop:this._tabsList.scrollLeft;n<0&&i<=0||n>0&&i>=r||(e.preventDefault(),e.stopPropagation(),t?this._tabsList.scrollTop=i+n:this._tabsList.scrollLeft=i+n)},{passive:!1}),Z(this._tabsList,`keydown`,e=>{this._onKeyDown(e)}),Z(this._tabsList,`dragover`,e=>{this._reorder.processDragOver(e.clientX,e.clientY)&&e.preventDefault()},!0),Z(this._tabsList,`dragleave`,e=>{this._reorder.processDragLeave(e.relatedTarget)},!0),Z(this._tabsList,`dragend`,()=>{this._reorder.resetDragAnimation()}),Z(this._tabsList,`drop`,e=>{var t;if(this._animState?.currentInsertionIndex==null||this.accessor.options.theme?.tabAnimation!==`smooth`&&!this._animState.sourceTabGroupId)return;e.stopPropagation(),e.preventDefault(),(t=this.group.model.dropTargetContainer)==null||(t=t.model)==null||t.clear();let n=this._animState;if(this._animState=null,this._pendingCollapse=!1,n.sourceTabGroupId){this._commitGroupMove(n.sourceTabGroupId,n.currentInsertionIndex);return}let r=this._reorder.resolveTabDrop(n);if(this._reorder.uncollapseSourceTab(n.sourceTabId),!r){this.resetTabTransforms();return}let i=n.sourceIndex,a=this.snapshotTabPositions();this.resetTabTransforms(),this._onDrop.fire($({event:e},r)),this.runFlipAnimation(a,n.sourceTabId,i===-1,{from:Math.min(i,r.index),to:Math.max(i,r.index)})},!0),hW.from(()=>{var e;(e=this._voidContainerListeners)==null||e.dispose(),this._reorder.resetDragAnimation(),this._tabGroupManager.disposeAll();for(let{value:e,disposable:t}of this._tabs)t.dispose(),e.dispose();this._tabs=[],this._tabMap.clear()}))}indexOf(e){return this._tabs.findIndex(t=>t.value.panel.id===e)}getTabId(e){return this._tabMap.get(e)?.value.element.id}getPanelForTab(e){for(let{value:t}of this._tabs)if(t.element===e||t.element.contains(e))return t.panel}isActive(e){return this.selectedIndex>-1&&this._tabs[this.selectedIndex].value===e}_onKeyDown(e){let t=this._tabs.findIndex(t=>t.value.element===e.target);if(t===-1)return;let n=this._direction===`vertical`,r=n?`ArrowDown`:`ArrowRight`,i=n?`ArrowUp`:`ArrowLeft`,a=this._tabs.length-1;switch(e.key){case r:e.preventDefault(),this._focusTab(Math.min(t+1,a));break;case i:e.preventDefault(),this._focusTab(Math.max(t-1,0));break;case`Home`:e.preventDefault(),this._focusTab(0);break;case`End`:e.preventDefault(),this._focusTab(a);break;case`Enter`:case` `:e.preventDefault(),this.accessor.withOrigin(`user`,()=>this._tabs[t].value.panel.api.setActive());break;case`Delete`:case`Backspace`:e.preventDefault(),this._closeTab(t)}}_closeTab(e){let t=this._tabs[e]?.value;if(!t)return;let n=(this._tabs[e+1]?.value??this._tabs[e-1]?.value)?.panel.id;if(t.panel.api.close(),n!==void 0){let e=this._tabs.findIndex(e=>e.value.panel.id===n);e>-1&&this._focusTab(e)}}_focusTab(e){for(let t=0;t<this._tabs.length;t++)this._tabs[t].value.element.tabIndex=t===e?0:-1;this._tabs[e].value.element.focus()}focusActiveTab(){if(this._tabs.length===0)return;let e=this.group.activePanel?.id,t=e?this._tabs.findIndex(t=>t.value.panel.id===e):-1;this._focusTab(t>-1?t:0)}setActivePanel(e){let t=this._direction===`vertical`;for(let n of this._tabs){let r=e.id===n.value.panel.id;n.value.setActive(r),r&&this._scrollTabIntoView(n.value.element,t)}this._tabGroupManager.groupUnderlines.size>0&&this._tabGroupManager.positionUnderlines()}_scrollTabIntoView(e,t){let n=e.parentElement;if(!n)return;let r=t?e.offsetTop:e.offsetLeft,i=t?e.offsetHeight:e.offsetWidth,a=t?n.scrollTop:n.scrollLeft,o=t?n.clientHeight:n.clientWidth;(r<a||r+i>a+o)&&(t?n.scrollTop=r:n.scrollLeft=r)}_activateOnPointerDown(e){if(!tq(this.accessor.options).html5){this.group.model.openPanel(e);return}let t=requestAnimationFrame(()=>{this._tabMap.has(e.id)&&this.group.model.openPanel(e)});this._pointerActivation.value={dispose:()=>cancelAnimationFrame(t)}}openPanel(e,t=this._tabs.length){if(this._tabMap.has(e.id))return;let n=new aq(e,this.accessor,this.group);n.setContent(e.view.tab),this._direction!==`horizontal`&&n.setDirection(this._direction);let r={value:n,disposable:new Y(n.onDragStart(t=>{let r=t.defaultPrevented;if(this._onTabDragStart.fire({nativeEvent:t,panel:e}),(!t.defaultPrevented||r)&&this.accessor.options.theme?.tabAnimation===`smooth`){let t=Nq(n.element.getBoundingClientRect(),this._direction),r=this._tabs.findIndex(e=>e.value===n);this._animState={sourceTabId:e.id,sourceIndex:r,tabPositions:this.snapshotTabPositions(),chipSizes:this._tabGroupManager.snapshotChipSizes(),currentInsertionIndex:null,targetTabGroupId:null,sourceTabGroupId:null,sourceGroupPanelIds:null,sourceChipSize:0,cursorOffsetFromDragStart:t/2,sourceGapSize:t,containerStart:Pq(this._tabsList.getBoundingClientRect(),this._direction)},this._pendingCollapse=!0,requestAnimationFrame(()=>{var e;this._pendingCollapse=!1,this._animState&&(this._tabsList.classList.contains(`dv-tabs-container--wrap`)||(n.element.style.transition=`none`,Q(n.element,`dv-tab--dragging`,!0),n.element.offsetHeight),(e=this._animState).currentInsertionIndex??(e.currentInsertionIndex=r),this.applyDragOverTransforms(!0),n.element.style.removeProperty(`transition`))})}}),n.onTabClick(t=>{t.defaultPrevented||this.group.api.location.type===`edge`&&(this.group.activePanel===e?this.group.api.isCollapsed()?this.group.api.expand():this.group.api.collapse():(this.group.model.openPanel(e),this.group.api.isCollapsed()&&this.group.api.expand()))}),n.onPointerDown(t=>{if(t.defaultPrevented)return;let r=!this.accessor.options.disableFloatingGroups,i=this.group.api.location.type===`floating`&&this.size===1;if(r&&!i&&t.shiftKey){t.preventDefault();let e=this.accessor.getGroupPanel(n.panel.id),{top:r,left:i}=n.element.getBoundingClientRect(),{top:a,left:o}=this.accessor.element.getBoundingClientRect();this.accessor.addFloatingGroup(e,{x:i-o,y:r-a,inDragMode:!0})}else t.button===0&&this.group.api.location.type!==`edge`&&this.group.activePanel!==e&&this._activateOnPointerDown(e)}),n.onDrop(e=>{let t=this._animState;this._animState=null,this._pendingCollapse=!1;let r=this._tabs.findIndex(e=>e.value===n);if(t){let n=e.position===`right`?r+1:r;if(t.sourceTabGroupId){this._commitGroupMove(t.sourceTabGroupId,t.currentInsertionIndex??n);return}this._reorder.uncollapseSourceTab(t.sourceTabId);let i=this.snapshotTabPositions();this.resetTabTransforms(),this._onDrop.fire({event:e.nativeEvent,index:n,targetTabGroupId:t.targetTabGroupId}),this.accessor.options.theme?.tabAnimation===`smooth`&&this.runFlipAnimation(i,t.sourceTabId,t.sourceIndex===-1,t.sourceIndex===-1?void 0:{from:Math.min(t.sourceIndex,n),to:Math.max(t.sourceIndex,n)})}else{let t=this._direction===`vertical`?`bottom`:`right`,i=e.position===t?r+1:r,a=pW(),o=a?this._tabs.findIndex(e=>e.value.panel.id===a.panelId):-1,s=i-+(o!==-1&&o<i),c=this.group.model.getTabGroupForPanel(n.panel.id)?.id??null;this._onDrop.fire({event:e.nativeEvent,index:s,targetTabGroupId:c})}}),n.onWillShowOverlay(e=>{this._onWillShowOverlay.fire(new oq(e,{kind:`tab`,panel:this.group.activePanel,api:this.accessor.api,group:this.group,getData:pW}))}))};this.addTab(r,t),this._scheduleOverflowRefresh(),this._tabGroupManager.positionAllChips(),this._animState&&(this._animState.tabPositions=this.snapshotTabPositions(),this._animState.chipSizes=this._tabGroupManager.snapshotChipSizes(),this.applyDragOverTransforms())}delete(e){let t=this.indexOf(e);if(t===-1)return;this._animState?.sourceTabId===e&&(this.resetTabTransforms(),this._animState=null),this._tabGroupManager.cleanupTransition(e);let{value:n,disposable:r}=this._tabs.splice(t,1)[0];this._tabMap.delete(e),r.dispose(),n.dispose(),n.element.remove(),this._scheduleOverflowRefresh(),this._animState&&(this._animState.tabPositions=this.snapshotTabPositions(),this._animState.chipSizes=this._tabGroupManager.snapshotChipSizes(),this.applyDragOverTransforms())}addTab(e,t=this._tabs.length){if(t<0||t>this._tabs.length)throw Error(`invalid location`);let n=t<this._tabs.length?this._tabs[t].value.element:null;this._tabsList.insertBefore(e.value.element,n),this._tabs=[...this._tabs.slice(0,t),e,...this._tabs.slice(t)],this._tabMap.set(e.value.panel.id,e),this.selectedIndex<0&&(this.selectedIndex=t)}_scheduleOverflowRefresh(){!this._overflowRefreshPending&&this._showTabsOverflowControl&&(this._overflowRefreshPending=!0,queueMicrotask(()=>{if(this._overflowRefreshPending=!1,this.isDisposed||!this._showTabsOverflowControl)return;let e=this._tabsList,t=e.scrollWidth>e.clientWidth||e.scrollHeight>e.clientHeight;this.toggleDropdown({reset:!t})}))}toggleDropdown(e){let t=this._tabs.some(e=>!this._overflowExclude(e.value.panel.id)&&this._forcedOverflow(e.value.panel.id));if(e.reset&&!t){this._onOverflowTabsChange.fire({tabs:[],tabGroups:[],pinnedTabs:[],reset:!0});return}let n=this._tabs.filter(t=>!this._overflowExclude(t.value.panel.id)&&(this._forcedOverflow(t.value.panel.id)||!e.reset&&!YW(t.value.element,this._tabsList))).map(e=>e.value.panel.id),r=e.reset?[]:this._tabs.filter(e=>this._overflowExclude(e.value.panel.id)&&e.value.element.getBoundingClientRect().width>0&&!YW(e.value.element,this._tabsList)).map(e=>e.value.panel.id),i=new Set(n),a=[];for(let e of this.group.model.getTabGroups()){let t=this._tabGroupManager.chipRenderers.get(e.id),r=t&&!YW(t.chip.element,this._tabsList),o=e.panelIds.length>0&&e.panelIds.every(e=>i.has(e));if((r||o)&&(a.push(e.id),e.collapsed))for(let t of e.panelIds)i.has(t)||(i.add(t),n.push(t))}this._onOverflowTabsChange.fire({tabs:n,tabGroups:a,pinnedTabs:r,reset:!1})}updateDragAndDropState(){for(let e of this._tabs)e.value.updateDragAndDropState();this._tabGroupManager.updateDragAndDropState()}updateTabGroups(){this._tabGroupManager.update()}refreshTabGroupAccent(){this._tabGroupManager.refreshAccents()}_handleChipDragStart(e,t,n){let r=e.panelIds[0],i=r?this._tabs.findIndex(e=>e.value.panel.id===r):-1,a=t.element.getBoundingClientRect(),o=Nq(a,this._direction);for(let t of e.panelIds){let e=this._tabMap.get(t);e&&(o+=Nq(e.value.element.getBoundingClientRect(),this._direction))}if(this._animState={sourceTabId:``,sourceIndex:i,tabPositions:this.snapshotTabPositions(),chipSizes:this._tabGroupManager.snapshotChipSizes(),currentInsertionIndex:null,targetTabGroupId:null,sourceTabGroupId:e.id,sourceGroupPanelIds:new Set(e.panelIds),sourceChipSize:Nq(a,this._direction),cursorOffsetFromDragStart:Fq(n,this._direction)-Pq(a,this._direction),sourceGapSize:o,containerStart:Pq(this._tabsList.getBoundingClientRect(),this._direction)},this.accessor.options.theme?.tabAnimation!==`smooth`)return;let s=new Set(e.panelIds);this._pendingCollapse=!0,requestAnimationFrame(()=>{var t;if(this._pendingCollapse=!1,!this._animState)return;for(let e of this._tabs)s.has(e.value.panel.id)&&(e.value.element.style.transition=`none`,Q(e.value.element,`dv-tab--dragging`,!0));let n=this._tabGroupManager.chipRenderers.get(e.id);n&&(n.chip.element.style.transition=`none`,Q(n.chip.element,`dv-tab-group-chip--dragging`,!0)),this._tabsList.offsetHeight;let r=this._tabGroupManager.groupUnderlines.get(e.id);r&&(r.style.display=`none`),(t=this._animState).currentInsertionIndex??(t.currentInsertionIndex=i),this.applyDragOverTransforms(!0);for(let e of this._tabs)s.has(e.value.panel.id)&&e.value.element.style.removeProperty(`transition`);n&&n.chip.element.style.removeProperty(`transition`)})}_handleChipDrop(e,t){let n=e.panelIds[0];if(!n)return;let r=this._tabs.findIndex(e=>e.value.panel.id===n);if(r===-1)return;let i=pW();if(i?.tabGroupId){let e=this._animState;this._animState=null,this._pendingCollapse=!1,this._commitGroupMove(i.tabGroupId,e?.currentInsertionIndex??r);return}let a=i?.groupId===this.group.id&&i?.panelId?this._tabs.findIndex(e=>e.value.panel.id===i.panelId):-1,o=r-+(a!==-1&&a<r);this._onDrop.fire({event:t.nativeEvent,index:o,targetTabGroupId:null})}setExtendedDropZone(e){this._reorder.setExtendedDropZone(e)}setExternalInsertionIndex(e){this._reorder.setExternalInsertionIndex(e)}clearExternalAnimState(){this._reorder.clearExternalAnimState()}snapshotTabPositions(){return this._reorder.snapshotTabPositions()}handleDragOver(e){this._reorder.handleDragOver(e)}applyDragOverTransforms(e=!1){this._reorder.applyDragOverTransforms(e)}resetTabTransforms(){this._reorder.resetTabTransforms()}_commitGroupMove(e,t){this._reorder.commitGroupMove(e,t)}runFlipAnimation(e,t,n=!1,r){this._reorder.runFlipAnimation(e,t,n,r)}};function Rq(){let e=document.createElement(`div`);e.className=`dv-tabs-overflow-dropdown-default`;let t=document.createElement(`span`);t.textContent=``;let n=ZK();return e.appendChild(n),e.appendChild(t),{element:e,update:e=>{t.textContent=`${e.tabs}`}}}var zq=class extends Y{get onTabDragStart(){return this.tabs.onTabDragStart}get panels(){return this.tabs.panels}get size(){return this.tabs.size}get hidden(){return this._hidden}set hidden(e){this._hidden=e,this.element.style.display=e?`none`:``}get direction(){return this._direction}set direction(e){this._direction=e,e===`vertical`?(DW(this._element,`dv-groupview-header-vertical`),DW(this.rightActionsContainer,`dv-right-actions-container-vertical`),this.tabs.direction=e):(EW(this._element,`dv-groupview-header-vertical`),EW(this.rightActionsContainer,`dv-right-actions-container-vertical`),this.tabs.direction=e)}get element(){return this._element}get tabsListElement(){return this.tabs.tabsListElement}constructor(e,t){super(),this.accessor=e,this.group=t,this._hidden=!1,this._direction=`horizontal`,this._dropIndexResolver=(e,t)=>t,this._pinnedRow=void 0,this.dropdownPart=null,this._overflowTabs=[],this._overflowTabGroups=[],this._overflowPinnedTabs=[],this._dropdownDisposable=new gW,this._onDrop=new X,this.onDrop=this._onDrop.event,this._onGroupDragStart=new X,this.onGroupDragStart=this._onGroupDragStart.event,this._onWillShowOverlay=new X,this.onWillShowOverlay=this._onWillShowOverlay.event,this._element=document.createElement(`div`),this._element.className=`dv-tabs-and-actions-container`,Q(this._element,`dv-full-width-single-tab`,this.accessor.options.singleTabMode===`fullwidth`),this.rightActionsContainer=document.createElement(`div`),this.rightActionsContainer.className=`dv-right-actions-container`,this.leftActionsContainer=document.createElement(`div`),this.leftActionsContainer.className=`dv-left-actions-container`,this.preActionsContainer=document.createElement(`div`),this.preActionsContainer.className=`dv-pre-actions-container`,this.tabs=new Lq(t,e,{showTabsOverflowControl:!e.options.disableTabsOverflowList}),this.voidContainer=new cq(this.accessor,this.group),this.tabs.voidContainer=this.voidContainer.element,this._element.appendChild(this.preActionsContainer),this._element.appendChild(this.tabs.element),this._element.appendChild(this.leftActionsContainer),this._element.appendChild(this.voidContainer.element),this._element.appendChild(this.rightActionsContainer),this.tabs.setExtendedDropZone(this._element),this.addDisposables(this.tabs.onDrop(e=>this._onDrop.fire(e)),this.tabs.onWillShowOverlay(e=>this._onWillShowOverlay.fire(e)),e.onDidOptionsChange(()=>{this.tabs.showTabsOverflowControl=!e.options.disableTabsOverflowList}),this.tabs.onOverflowTabsChange(e=>{this.toggleDropdown(e)}),this.tabs,this._onWillShowOverlay,this._onDrop,this._onGroupDragStart,this.voidContainer,this.voidContainer.onDragStart(e=>{this._onGroupDragStart.fire({nativeEvent:e,group:this.group})}),this.voidContainer.onDrop(e=>{this.tabs.handleVoidDrop()||this._onDrop.fire({event:e.nativeEvent,index:this.tabs.size})}),this.voidContainer.onWillShowOverlay(e=>{this._onWillShowOverlay.fire(new oq(e,{kind:`header_space`,panel:this.group.activePanel,api:this.accessor.api,group:this.group,getData:pW}))}),Z(this.leftActionsContainer,`dragleave`,e=>{let t=e.relatedTarget;!this.leftActionsContainer.contains(t)&&!this._element.contains(t)&&this.tabs.clearExternalAnimState()}),Z(this.voidContainer.element,`dragleave`,e=>{let t=e.relatedTarget;this.voidContainer.element.contains(t)||(this._element.contains(t)?this.tabs.setExternalInsertionIndex(null):this.tabs.clearExternalAnimState())}),Z(this.voidContainer.element,`pointerdown`,e=>{if(!e.defaultPrevented&&!this.accessor.options.disableFloatingGroups&&e.shiftKey&&this.group.api.location.type!==`floating`&&this.group.api.location.type!==`edge`){e.preventDefault();let{top:t,left:n}=this.element.getBoundingClientRect(),{top:r,left:i}=this.accessor.element.getBoundingClientRect();this.accessor.addFloatingGroup(this.group,{x:n-i+20,y:t-r+20,inDragMode:!0})}}))}show(){this.hidden||(this.element.style.display=``)}hide(){this._element.style.display=`none`}setRightActionsElement(e){this.rightActions!==e&&(this.rightActions&&=(this.rightActions.remove(),void 0),e&&(this.rightActionsContainer.appendChild(e),this.rightActions=e))}setLeftActionsElement(e){this.leftActions!==e&&(this.leftActions&&=(this.leftActions.remove(),void 0),e&&(this.leftActionsContainer.appendChild(e),this.leftActions=e))}setPrefixActionsElement(e){this.preActions!==e&&(this.preActions&&=(this.preActions.remove(),void 0),e&&(this.preActionsContainer.appendChild(e),this.preActions=e))}isActive(e){return this.tabs.isActive(e)}indexOf(e){return this.tabs.indexOf(e)}getTabId(e){return this.tabs.getTabId(e)}getPanelForTab(e){return this.tabs.getPanelForTab(e)}setActive(e){}delete(e){this.tabs.delete(e),this.updateClassnames()}setActivePanel(e){this.tabs.setActivePanel(e)}focusActiveTab(){this.tabs.focusActiveTab()}openPanel(e,t=this.tabs.size){this.tabs.openPanel(e,t),this.updateClassnames()}closePanel(e){this.delete(e.id)}setOverflowExclude(e){this.tabs.setOverflowExclude(e)}setForcedOverflow(e){this.tabs.setForcedOverflow(e)}setPinnedSticky(e){this.tabs.setPinnedSticky(e)}refreshOverflow(){this.tabs.refreshOverflow()}setPinnedRow(e){this._pinnedRow!==e&&(this._pinnedRow&&this._pinnedRow.remove(),this._pinnedRow=e,e&&(e.classList.add(`dv-pinned-row`),this._element.insertBefore(e,this._element.firstChild)),Q(this._element,`dv-tabs-and-actions-container--pinned-row`,!!e))}setDropIndexResolver(e){this._dropIndexResolver=e}resolveDropIndex(e,t){return this._dropIndexResolver(e,t)}updateClassnames(){Q(this._element,`dv-single-tab`,this.size===1)}toggleDropdown(e){let t=e.reset?[]:e.tabs,n=e.reset?[]:e.tabGroups,r=e.reset?[]:e.pinnedTabs;this._overflowTabs=t,this._overflowTabGroups=n,this._overflowPinnedTabs=r;let i=this._overflowTabs.length+this._overflowPinnedTabs.length;if(i>0&&this.dropdownPart){this.dropdownPart.update({tabs:i});return}if(i===0){this._dropdownDisposable.dispose();return}let a=document.createElement(`div`);a.className=`dv-tabs-overflow-dropdown-root`;let o=Rq();o.update({tabs:i}),this.dropdownPart=o,a.appendChild(o.element),this.rightActionsContainer.prepend(a),this._dropdownDisposable.value=new Y(hW.from(()=>{var e,t;a.remove(),(e=this.dropdownPart)==null||(t=e.dispose)==null||t.call(e),this.dropdownPart=null}),Z(a,`pointerdown`,e=>{e.preventDefault()},{capture:!0}),Z(a,`click`,e=>{let t=$W(a),n={x:e.clientX,y:e.clientY,zIndex:t?.style.zIndex?`calc(${t.style.zIndex} * 2)`:void 0},{context:r,rowRenderers:i}=this.createOverflowRenderContext(a,n),o=this.accessor.advancedOverflowService;try{o?o.renderOverflow({group:this.group,overflowTabs:[...this._overflowTabs],overflowTabGroups:[...this._overflowTabGroups],pinnedOverflowTabs:[...this._overflowPinnedTabs],context:r}):r.open(this.renderFreeOverflowList(r))}catch(e){throw i.dispose(),e}}))}createOverflowRenderContext(e,t){let n=new Set(this._overflowTabGroups),r=this.group.model.getTabGroups(),i=new Map,a=new Map;for(let e of r)if(a.set(e.id,e),n.has(e.id))for(let t of e.panelIds)i.set(t,e);let o=()=>this.accessor.getPopupServiceForGroup(this.group),s=new Y,c=e=>{let t=document.createElement(`div`);t.className=`dv-tabs-overflow-group-header`;let n=document.createElement(`span`);n.className=`dv-tabs-overflow-group-color`,Cq(n,e.color,this.accessor.tabGroupColorPalette),t.appendChild(n);let r=document.createElement(`span`);if(r.className=`dv-tabs-overflow-group-label`,r.textContent=e.label||e.id,t.appendChild(r),e.collapsed){let n=document.createElement(`span`);n.className=`dv-tabs-overflow-group-collapsed-badge`,n.textContent=`${e.panelIds.length}`,t.appendChild(n)}return t.addEventListener(`click`,()=>{o().close(),e.collapsed&&e.expand();let t=e.panelIds[0];if(t){let e=this.group.panels.find(e=>e.id===t);this.accessor.withOrigin(`user`,()=>e?.api.setActive())}}),t};return{context:{overflowGroupIdForPanel:e=>i.get(e)?.id,buildGroupHeader:e=>{let t=a.get(e);if(t&&n.has(t.id))return c(t)},buildPinnedHeader:()=>{let e=document.createElement(`div`);e.className=`dv-tabs-overflow-group-header dv-tabs-overflow-pinned-header`;let t=YK();t.classList.add(`dv-tabs-overflow-pinned-icon`),e.appendChild(t);let n=document.createElement(`span`);return n.className=`dv-tabs-overflow-group-label`,n.textContent=`Pinned`,e.appendChild(n),e},buildRow:e=>{let t=this.group.panels.find(t=>t.id===e);if(!t)return;let n=this.tabs.tabs.find(t=>t.panel.id===e),r=i.get(e),a=t.view.createTabRenderer(`headerOverflow`),c=!1,l=hW.from(()=>{if(!c){var e;c=!0,(e=a.dispose)==null||e.call(a)}});s.isDisposed?l.dispose():s.addDisposables(l);let u=a.element,d=document.createElement(`div`);Q(d,`dv-tab`,!0),Q(d,`dv-active-tab`,t.api.isActive),Q(d,`dv-inactive-tab`,!t.api.isActive),r&&Q(d,`dv-tab--grouped`,!0);let f=()=>{r?.collapsed&&r.expand(),n?.element.scrollIntoView({block:`nearest`,inline:`nearest`}),this.accessor.withOrigin(`user`,()=>t.api.setActive())};return d.addEventListener(`click`,e=>{o().close(),!e.defaultPrevented&&f()}),d.appendChild(u),{element:d,panel:t,activate:()=>{o().close(),f()},dispose:()=>{s.removeDisposable(l),l.dispose()}}},open:e=>{o().openPopover(e,t,{onClose:()=>s.dispose()})},close:()=>o().close(),focusTrigger:()=>{e.tabIndex=-1,e.focus()}},rowRenderers:s}}renderFreeOverflowList(e){let t=document.createElement(`div`);t.style.overflow=`auto`,t.className=`dv-tabs-overflow-container`;let n=this._overflowPinnedTabs.map(t=>e.buildRow(t)).filter(e=>e!=null);if(n.length>0){t.appendChild(e.buildPinnedHeader());for(let e of n)t.appendChild(e.element)}let r=new Set;for(let n of this.tabs.tabs.filter(e=>this._overflowTabs.includes(e.panel.id))){let i=e.overflowGroupIdForPanel(n.panel.id);if(i&&!r.has(i)){r.add(i);let n=e.buildGroupHeader(i);n&&t.appendChild(n)}let a=e.buildRow(n.panel.id);a&&t.appendChild(a.element)}return t}updateDragAndDropState(){this.tabs.updateDragAndDropState(),this.voidContainer.updateDragAndDropState()}updateTabGroups(){this.tabs.updateTabGroups()}refreshTabGroupAccent(){this.tabs.refreshTabGroupAccent()}},Bq=class extends Y{get label(){return this._label}get color(){return this._color}get componentParams(){return this._componentParams}setLabel(e){this.isDisposed||this._label===e||(this._label=e,this._onDidChange.fire())}setColor(e){if(this.isDisposed)return;let t=e===``?void 0:e;this._color!==t&&(this._color=t,this._onDidChange.fire())}setComponentParams(e){this.isDisposed||(this._componentParams=e,this._onDidChange.fire())}get collapsed(){return this._collapsed}get panelIds(){return this._panelIds}get size(){return this._panelIds.length}get isEmpty(){return this._panelIds.length===0}constructor(e,t){super(),this.id=e,this._collapsed=!1,this._panelIds=[],this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this._onDidPanelChange=new X,this.onDidPanelChange=this._onDidPanelChange.event,this._onDidCollapseChange=new X,this.onDidCollapseChange=this._onDidCollapseChange.event,this._onDidDestroy=new X,this.onDidDestroy=this._onDidDestroy.event,this._label=t?.label??``,this._color=t?.color===``?void 0:t?.color,this._collapsed=t?.collapsed??!1,this._componentParams=t?.componentParams,this.addDisposables(this._onDidChange,this._onDidPanelChange,this._onDidCollapseChange,this._onDidDestroy)}addPanel(e,t){if(this.isDisposed||this._panelIds.includes(e))return;let n=t===void 0?this._panelIds.length:Math.max(0,Math.min(t,this._panelIds.length));this._panelIds.splice(n,0,e),this._onDidPanelChange.fire({panelId:e,type:`add`})}removePanel(e){if(this.isDisposed)return!1;let t=this._panelIds.indexOf(e);return t!==-1&&(this._panelIds.splice(t,1),this._onDidPanelChange.fire({panelId:e,type:`remove`}),!0)}indexOfPanel(e){return this._panelIds.indexOf(e)}containsPanel(e){return this._panelIds.includes(e)}collapse(){this.isDisposed||this._collapsed||(this._collapsed=!0,this._onDidCollapseChange.fire(!0))}expand(){!this.isDisposed&&this._collapsed&&(this._collapsed=!1,this._onDidCollapseChange.fire(!1))}toggle(){this._collapsed?this.expand():this.collapse()}toJSON(){let e={id:this.id,collapsed:this._collapsed,panelIds:[...this._panelIds]};return this._label&&(e.label=this._label),this._color!==void 0&&(e.color=this._color),this._componentParams!==void 0&&(e.componentParams=this._componentParams),e}dispose(){this._onDidDestroy.fire(),super.dispose()}},Vq=class extends vW{get nativeEvent(){return this.options.nativeEvent}get position(){return this.options.position}get panel(){return this.options.panel}get index(){return this.options.index}get group(){return this.options.group}get api(){return this.options.api}constructor(e){super(),this.options=e}getData(){return this.options.getData()}},Hq=class extends Vq{get kind(){return this._kind}constructor(e){super(e),this._kind=e.kind}},Uq=class extends Y{get tabGroups(){return this._tabGroups}get element(){throw Error(`dockview: not supported`)}get activePanel(){return this._activePanel}get contentContainerId(){return this.contentContainer.element.id}get contentDropTarget(){return this.contentContainer.dropTarget}get locked(){return this._locked}set locked(e){this._locked=e,Q(this.container,`dv-locked-groupview`,e===`no-drop-target`||e)}get isActive(){return this._isGroupActive}get panels(){return this._panels}get size(){return this._panels.length}get isEmpty(){return this._panels.length===0}get hasWatermark(){return!!(this.watermark&&this.container.contains(this.watermark.element))}get header(){return this.tabsContainer}get tabsListElement(){return this.tabsContainer.tabsListElement}getPanelForTab(e){return this.tabsContainer.getPanelForTab(e)}get isContentFocused(){let e=this.contentContainer.element,t=eG(e);return t?OW(t,e):!1}get headerPosition(){return this._headerPosition??`top`}set headerPosition(e){this._headerPosition=e,this.invalidateHeaderSize(),EW(this.container,`dv-groupview-header-top`,`dv-groupview-header-bottom`,`dv-groupview-header-left`,`dv-groupview-header-right`),DW(this.container,`dv-groupview-header-${e}`);let t=e===`top`||e===`bottom`?`horizontal`:`vertical`,n=this._headerDirection;if(this._headerDirection=t,this.tabsContainer.direction=t,this.header.direction=t,this.panels.length>0&&this.layoutContent(),this.updateHeaderActions(),n!==void 0&&n!==t){var r;(r=this.groupPanel)==null||r.api._onDidHeaderDirectionChange.fire({direction:t,position:e})}}get location(){return this._location}set location(e){this._location=e,Q(this.container,`dv-groupview-floating`,!1),Q(this.container,`dv-groupview-popout`,!1),Q(this.container,`dv-groupview-edge`,!1);let t=e=>{this.contentContainer.dropTarget.setTargetZones(e),this.contentContainer.pointerDropTarget.setTargetZones(e)};switch(e.type){case`grid`:t([`top`,`bottom`,`left`,`right`,`center`]);break;case`floating`:t([`top`,`bottom`,`left`,`right`,`center`]),Q(this.container,`dv-groupview-floating`,!0);break;case`popout`:t([`top`,`bottom`,`left`,`right`,`center`]),Q(this.container,`dv-groupview-popout`,!0);break;case`edge`:t([`center`]),Q(this.container,`dv-groupview-edge`,!0)}this.groupPanel.api._onDidLocationChange.fire({location:this.location})}constructor(e,t,n,r,i){super(),this.container=e,this.accessor=t,this.id=n,this.options=r,this.groupPanel=i,this._isGroupActive=!1,this._locked=!1,this._location={type:`grid`},this.mostRecentlyUsed=[],this._overwriteRenderContainer=null,this._overwriteDropTargetContainer=null,this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this._width=0,this._height=0,this._panels=[],this._panelDisposables=new Map,this._tabGroupDisposables=new Map,this._pendingMicrotaskDisposables=new Set,this._onMove=new X,this.onMove=this._onMove.event,this._onDidDrop=new X,this.onDidDrop=this._onDidDrop.event,this._onWillDrop=new X,this.onWillDrop=this._onWillDrop.event,this._onWillShowOverlay=new X,this.onWillShowOverlay=this._onWillShowOverlay.event,this._onTabDragStart=new X,this.onTabDragStart=this._onTabDragStart.event,this._onGroupDragStart=new X,this.onGroupDragStart=this._onGroupDragStart.event,this._onDidAddPanel=new X,this.onDidAddPanel=this._onDidAddPanel.event,this._onDidPanelTitleChange=new X,this.onDidPanelTitleChange=this._onDidPanelTitleChange.event,this._onDidPanelParametersChange=new X,this.onDidPanelParametersChange=this._onDidPanelParametersChange.event,this._onDidRemovePanel=new X,this.onDidRemovePanel=this._onDidRemovePanel.event,this._onDidActivePanelChange=new X,this.onDidActivePanelChange=this._onDidActivePanelChange.event,this._onUnhandledDragOver=new X,this.onUnhandledDragOver=this._onUnhandledDragOver.event,this._tabGroups=[],this._tabGroupMap=new Map,this._panelToTabGroup=new Map,this._tabGroupIdCounter=0,this._pendingTabGroupUpdate=!1,this._onDidCreateTabGroup=new X,this.onDidCreateTabGroup=this._onDidCreateTabGroup.event,this._onDidDestroyTabGroup=new X,this.onDidDestroyTabGroup=this._onDidDestroyTabGroup.event,this._onDidAddPanelToTabGroup=new X,this.onDidAddPanelToTabGroup=this._onDidAddPanelToTabGroup.event,this._onDidRemovePanelFromTabGroup=new X,this.onDidRemovePanelFromTabGroup=this._onDidRemovePanelFromTabGroup.event,this._onDidTabGroupChange=new X,this.onDidTabGroupChange=this._onDidTabGroupChange.event,this._onDidTabGroupCollapsedChange=new X,this.onDidTabGroupCollapsedChange=this._onDidTabGroupCollapsedChange.event,Q(this.container,`dv-groupview`,!0),this.container.setAttribute(`role`,`region`),this._api=new rK(this.accessor),this.tabsContainer=new zq(this.accessor,this.groupPanel),this.contentContainer=new KK(this.accessor,this),e.append(this.tabsContainer.element,this.contentContainer.element),this.header.hidden=!!r.hideHeader,this.locked=r.locked??!1,this.headerPosition=r.headerPosition??t.defaultHeaderPosition,this.addDisposables(TW(this.tabsContainer.element,()=>{if(this.isDisposed)return;let e=this.measureHeaderSize();e!==this._cachedHeaderSize&&(this._cachedHeaderSize=e,this.layout(this._width,this._height))}),this._onDidPanelTitleChange.event(()=>this.updateAccessibleLabel()),this._onTabDragStart,this._onGroupDragStart,this._onWillShowOverlay,this.tabsContainer.onTabDragStart(e=>{this._onTabDragStart.fire(e)}),this.tabsContainer.onGroupDragStart(e=>{this._onGroupDragStart.fire(e)}),this.tabsContainer.onDrop(e=>{let t=pW()?.panelId??null,n=t?this.tabsContainer.resolveDropIndex(t,e.index):e.index;if(this.handleDropEvent(`header`,e.event,`center`,n),t&&e.targetTabGroupId){let n=this._tabGroupMap.get(e.targetTabGroupId),r;if(n){let e=this._panels.findIndex(e=>e.id===t);if(e!==-1){r=0;for(let t of n.panelIds)this._panels.findIndex(e=>e.id===t)<e&&r++}}this.addPanelToTabGroup(e.targetTabGroupId,t,r)}else t&&e.targetTabGroupId===null&&this.removePanelFromTabGroup(t)}),this.contentContainer.onDidFocus(()=>{this.accessor.doSetGroupActive(this.groupPanel)}),this.contentContainer.onDidBlur(()=>{}),this.contentContainer.dropTarget.onDrop(e=>{this.handleDropEvent(`content`,e.nativeEvent,e.position,void 0,e.edge)}),this.contentContainer.pointerDropTarget.onDrop(e=>{this.handleDropEvent(`content`,e.nativeEvent,e.position,void 0,e.edge)}),this.tabsContainer.onWillShowOverlay(e=>{this._onWillShowOverlay.fire(e)}),this.contentContainer.dropTarget.onWillShowOverlay(e=>{this._onWillShowOverlay.fire(new oq(e,{kind:`content`,panel:this.activePanel,api:this._api,group:this.groupPanel,getData:pW}))}),this.contentContainer.pointerDropTarget.onWillShowOverlay(e=>{this._onWillShowOverlay.fire(new oq(e,{kind:`content`,panel:this.activePanel,api:this._api,group:this.groupPanel,getData:pW}))}),this._onMove,this._onDidChange,this._onDidDrop,this._onWillDrop,this._onDidAddPanel,this._onDidRemovePanel,this._onDidActivePanelChange,this._onUnhandledDragOver,this._onDidPanelTitleChange,this._onDidPanelParametersChange,this._onDidCreateTabGroup,this._onDidDestroyTabGroup,this._onDidAddPanelToTabGroup,this._onDidRemovePanelFromTabGroup,this._onDidTabGroupChange,this._onDidTabGroupCollapsedChange,this._onDidCreateTabGroup.event(()=>{this._scheduleTabGroupUpdate()}),this._onDidDestroyTabGroup.event(()=>{this._scheduleTabGroupUpdate()}),this._onDidAddPanelToTabGroup.event(()=>{this._scheduleTabGroupUpdate()}),this._onDidRemovePanelFromTabGroup.event(()=>{this._scheduleTabGroupUpdate()}),this._onDidTabGroupChange.event(()=>{this._scheduleTabGroupUpdate()}),this._onDidTabGroupCollapsedChange.event(()=>{this._scheduleTabGroupUpdate()}))}_scheduleTabGroupUpdate(){this._pendingTabGroupUpdate||(this._pendingTabGroupUpdate=!0,queueMicrotask(()=>{this._pendingTabGroupUpdate=!1,this.isDisposed||this.tabsContainer.updateTabGroups()}))}_bracketTabGroupMutation(e){return this.accessor.mutation?this.accessor.mutation(`tab-group`,e):e()}createTabGroup(e){return this._bracketTabGroupMutation(()=>this._doCreateTabGroup(e))}_doCreateTabGroup(e){let t=e?.id??`tg-${this.id}-${this._tabGroupIdCounter++}`,n=new Bq(t,{label:e?.label,color:e?.color,collapsed:e?.collapsed,componentParams:e?.componentParams});return this._tabGroups.push(n),this._tabGroupMap.set(t,n),this._tabGroupDisposables.set(t,new Y(n.onDidChange(()=>{this._onDidTabGroupChange.fire({tabGroup:n})}),n.onDidCollapseChange(e=>{e?this._handleGroupCollapse(n):this._handleGroupExpand(n),this._onDidTabGroupCollapsedChange.fire({tabGroup:n})}),n.onDidDestroy(()=>{this._removeTabGroupInternal(n)}))),this._onDidCreateTabGroup.fire({tabGroup:n}),n}dissolveTabGroup(e){let t=this._tabGroupMap.get(e);t&&this._bracketTabGroupMutation(()=>{let e=[...t.panelIds];for(let n of e)t.removePanel(n),this._panelToTabGroup.delete(n),this._onDidRemovePanelFromTabGroup.fire({tabGroup:t,panelId:n});t.dispose()})}addPanelToTabGroup(e,t,n){let r=this._tabGroupMap.get(e);if(!r||!this._panels.some(e=>e.id===t))return;let i=this.getTabGroupForPanel(t);i?.id!==e&&this._bracketTabGroupMutation(()=>{i&&this.removePanelFromTabGroup(t),r.addPanel(t,n),this._panelToTabGroup.set(t,r),this._enforceContiguity(r,t),this._onDidAddPanelToTabGroup.fire({tabGroup:r,panelId:t})})}movePanelWithinGroup(e,t,n){let r=this._tabGroupMap.get(e);r?.containsPanel(t)&&(r.removePanel(t),r.addPanel(t,n),this._enforceContiguity(r,t),this.tabsContainer.updateTabGroups())}movePanelBetweenGroups(e,t,n){let r=this._findTabGroupForPanel(e),i=this._tabGroupMap.get(t);i&&(r&&(r.removePanel(e),this._panelToTabGroup.delete(e),this._moveOutOfGroupSpan(r,e),this._onDidRemovePanelFromTabGroup.fire({tabGroup:r,panelId:e}),r.isEmpty&&r.dispose()),i.addPanel(e,n),this._panelToTabGroup.set(e,i),this._enforceContiguity(i,e),this._onDidAddPanelToTabGroup.fire({tabGroup:i,panelId:e}))}moveTabGroup(e,t){let n=this._tabGroupMap.get(e);if(!n||n.panelIds.length===0)return;let r=new Set(n.panelIds),i=n.panelIds.map(e=>this._panels.find(t=>t.id===e)).filter(e=>e!==void 0);if(i.length===0)return;let a=0;for(let e=0;e<Math.min(t,this._panels.length);e++)r.has(this._panels[e].id)&&a++;for(let e of i){let t=this._panels.indexOf(e);t!==-1&&this._panels.splice(t,1)}let o=t-a,s=Math.max(0,Math.min(o,this._panels.length));this._panels.splice(s,0,...i);for(let e of this._panels)this.tabsContainer.delete(e.id);for(let e=0;e<this._panels.length;e++)this.tabsContainer.openPanel(this._panels[e],e);this._syncActiveTab(),this.tabsContainer.updateTabGroups()}_enforceContiguity(e,t){let n=this._panels.find(e=>e.id===t);if(!n)return;let r=e.indexOfPanel(t),i=this._computeGlobalIndex(e,r),a=this._panels.indexOf(n);if(a===i)return;this._panels.splice(a,1);let o=i>a?i-1:i;this._panels.splice(o,0,n),this._reinsertTab(n,o)}_reinsertTab(e,t){this.tabsContainer.delete(e.id),this.tabsContainer.openPanel(e,t),e===this._activePanel&&this._syncActiveTab()}_syncActiveTab(){this._activePanel&&(this.tabsContainer.setActivePanel(this._activePanel),this.contentContainer.setLabelledBy(this.tabsContainer.getTabId(this._activePanel.id)))}_computeGlobalIndex(e,t){let n=e.panelIds;if(n.length<=1){let e=this._panels.find(e=>e.id===n[0]);return e?this._panels.indexOf(e):this._panels.length}for(let e=0;e<n.length;e++){if(e===t)continue;let r=this._panels.find(t=>t.id===n[e]);if(r){let n=this._panels.indexOf(r);return Math.max(0,n+(t-e))}}return this._panels.length}removePanelFromTabGroup(e){let t=this._findTabGroupForPanel(e);t&&this._bracketTabGroupMutation(()=>{t.removePanel(e),this._panelToTabGroup.delete(e),this._moveOutOfGroupSpan(t,e),this._onDidRemovePanelFromTabGroup.fire({tabGroup:t,panelId:e}),t.isEmpty&&t.dispose()})}_moveOutOfGroupSpan(e,t){let n=this._panels.findIndex(e=>e.id===t);if(n===-1||e.isEmpty)return;let r=e.panelIds,i=this._panels.findIndex(e=>e.id===r[0]),a=this._panels.findIndex(e=>e.id===r[r.length-1]);if(i===-1||a===-1||n<i||n>a)return;let[o]=this._panels.splice(n,1);this._panels.splice(a,0,o),this._reinsertTab(o,a)}getTabGroups(){return this._tabGroups}updateTabGroups(){this.tabsContainer.updateTabGroups()}refreshTabGroupAccent(){this.tabsContainer.refreshTabGroupAccent()}refreshWatermark(){if(this.watermark){var e,t;this.watermark.element.remove(),(e=(t=this.watermark).dispose)==null||e.call(t),this.watermark=void 0}this.updateContainer()}getTabGroupForPanel(e){return this._findTabGroupForPanel(e)}_findTabGroupForPanel(e){return this._panelToTabGroup.get(e)}_removeTabGroupInternal(e){let t=this._tabGroups.indexOf(e);if(t!==-1){this._tabGroups.splice(t,1),this._tabGroupMap.delete(e.id);for(let t of e.panelIds)this._panelToTabGroup.delete(t);this._onDidDestroyTabGroup.fire({tabGroup:e});let n=this._tabGroupDisposables.get(e.id);this._tabGroupDisposables.delete(e.id),n&&(this._pendingMicrotaskDisposables.add(n),queueMicrotask(()=>{this._pendingMicrotaskDisposables.delete(n),n.dispose()}))}}_handleGroupCollapse(e){if(!this._activePanel||!e.containsPanel(this._activePanel.id))return;let t=this._panels.indexOf(this._activePanel);for(let e=t+1;e<this._panels.length;e++){let t=this._panels[e];if(!this._findTabGroupForPanel(t.id)?.collapsed){this.doSetActivePanel(t),this.updateContainer();return}}for(let e=t-1;e>=0;e--){let t=this._panels[e];if(!this._findTabGroupForPanel(t.id)?.collapsed){this.doSetActivePanel(t),this.updateContainer();return}}this.contentContainer.closePanel(),this.doSetActivePanel(void 0),this.updateContainer()}_handleGroupExpand(e){if(this._activePanel)return;let t=e.panelIds[0];if(t){let e=this._panels.find(e=>e.id===t);e&&(this.doSetActivePanel(e),this.updateContainer())}}restoreTabGroups(e){for(let t of e){let e=/-(\d+)$/.exec(t.id);if(e){let t=Number.parseInt(e[1],10)+1;t>this._tabGroupIdCounter&&(this._tabGroupIdCounter=t)}}for(let t of e){let e=this.createTabGroup({id:t.id,label:t.label,color:t.color,componentParams:t.componentParams}),n=this._tabGroupMap.get(e.id);for(let r of t.panelIds)this._panels.some(e=>e.id===r)&&(e.addPanel(r),this._panelToTabGroup.set(r,n),this._enforceContiguity(n,r));t.collapsed&&e.collapse(),e.isEmpty&&e.dispose()}}focusContent(){this.contentContainer.element.focus()}focusActiveTab(){this.tabsContainer.focusActiveTab()}set renderContainer(e){this.panels.forEach(e=>{this.renderContainer.detatch(e)}),this._overwriteRenderContainer=e,this.panels.forEach(e=>{this.rerender(e)}),this.panels.length>0&&this.layoutContent()}get renderContainer(){return this._overwriteRenderContainer??this.accessor.overlayRenderContainer}set dropTargetContainer(e){this._overwriteDropTargetContainer=e}get dropTargetContainer(){return this._location.type===`floating`&&this.accessor.rootDropTargetContainer.disabled?this.accessor.floatingDropTargetContainer:this._overwriteDropTargetContainer??this.accessor.rootDropTargetContainer}initialize(){this.options.panels&&this.options.panels.forEach(e=>{this.doAddPanel(e)}),this.options.activePanel&&this.openPanel(this.options.activePanel),this.setActive(this.isActive,!0),this.updateContainer(),this.updateHeaderActions()}updateHeaderActions(){var e;(e=this.accessor.headerActionsService)==null||e.refresh(this.groupPanel)}attachHeaderAction(e,t){switch(e){case`left`:this.tabsContainer.setLeftActionsElement(t);break;case`right`:this.tabsContainer.setRightActionsElement(t);break;case`prefix`:this.tabsContainer.setPrefixActionsElement(t)}}rerender(e){this.contentContainer.renderPanel(e,{asActive:!1})}indexOf(e){return this.tabsContainer.indexOf(e.id)}toJSON(){let e={views:this.tabsContainer.panels,activeView:this._activePanel?.id,id:this.id};return this.locked!==!1&&(e.locked=this.locked),this.header.hidden&&(e.hideHeader=!0),this.headerPosition!==`top`&&(e.headerPosition=this.headerPosition),this._tabGroups.length>0&&(e.tabGroups=this._tabGroups.map(e=>e.toJSON())),e}moveToNext(e){var t;e??={},(t=e).panel??(t.panel=this.activePanel);let n=e.panel?this.panels.indexOf(e.panel):-1,r;if(n<this.panels.length-1)r=n+1;else if(e.suppressRoll)return;else r=0;this.openPanel(this.panels[r])}moveToPrevious(e){var t;if(e??={},(t=e).panel??(t.panel=this.activePanel),!e.panel)return;let n=this.panels.indexOf(e.panel),r;if(n>0)r=n-1;else if(e.suppressRoll)return;else r=this.panels.length-1;this.openPanel(this.panels[r])}containsPanel(e){return this.panels.includes(e)}init(e){}update(e){}focus(){var e;(e=this._activePanel)==null||e.focus()}openPanel(e,t={}){typeof t.index!=`number`||t.index>this.panels.length?t.index=this.panels.length:t.index<0&&(t.index=0);let n=!!t.skipSetActive;e.updateParentGroup(this.groupPanel,{skipSetActive:t.skipSetActive}),this.doAddPanel(e,t.index,{skipSetActive:n}),this.invalidateHeaderSize(),this._activePanel===e?this.contentContainer.openPanel(e):(n||this.doSetActivePanel(e),t.skipSetGroupActive||this.accessor.doSetGroupActive(this.groupPanel),t.skipSetActive?e.runEvents():this.updateContainer())}removePanel(e,t){let n=typeof e==`string`?e:e.id,r=this._panels.find(e=>e.id===n);if(!r)throw Error(`invalid operation`);return this._removePanel(r,t)}closeAllPanels(){if(this.panels.length>0){let e=[...this.panels];for(let t of e)this.doClose(t)}else this.accessor.removeGroup(this.groupPanel)}closePanel(e){this.doClose(e)}doClose(e){let t=this.panels.length===1&&this.accessor.isLastGridGroup(this.groupPanel);this.accessor.removePanel(e,t&&this.accessor.options.noPanelsOverlay===`emptyGroup`?{removeEmptyGroup:!1}:void 0)}isPanelActive(e){return this._activePanel===e}updateActions(e){this.tabsContainer.setRightActionsElement(e)}setActive(e,t=!1){if(!this.isDisposed&&(t||this.isActive!==e)){if(this._isGroupActive=e,Q(this.container,`dv-active-group`,e),Q(this.container,`dv-inactive-group`,!e),this.tabsContainer.setActive(this.isActive),!this._activePanel&&this.panels.length>0){let e=this._panels.find(e=>!this._findTabGroupForPanel(e.id)?.collapsed);e&&this.doSetActivePanel(e)}this.updateContainer()}}layout(e,t){this._width=e,this._height=t,this.layoutContent()}layoutContent(){let{width:e,height:t}=this.contentDimensions();this.contentContainer.layout(e,t),this._activePanel?.layout&&this._activePanel.layout(e,t)}relayout(){this.invalidateHeaderSize(),this.layout(this._width,this._height)}measureHeaderSize(){let e=this.tabsContainer.element;return this.headerPosition===`top`||this.headerPosition===`bottom`?e.offsetHeight:e.offsetWidth}invalidateHeaderSize(){this._cachedHeaderSize=void 0}contentDimensions(){let e=this.headerPosition===`top`||this.headerPosition===`bottom`,t=this._cachedHeaderSize??=this.measureHeaderSize();return{width:e?this._width:Math.max(0,this._width-t),height:e?Math.max(0,this._height-t):this._height}}_removePanel(e,t){let n=this._activePanel===e;if(this.doRemovePanel(e),this.invalidateHeaderSize(),n&&this.panels.length>0){let e=this.mostRecentlyUsed[0];this.openPanel(e,{skipSetActive:t?.skipSetActive,skipSetGroupActive:t?.skipSetActiveGroup})}return this._activePanel&&this.panels.length===0&&this.doSetActivePanel(void 0),t?.skipSetActive||this.updateContainer(),e}doRemovePanel(e){let t=this.panels.indexOf(e);if(this._activePanel===e&&this.contentContainer.closePanel(),this.tabsContainer.delete(e.id),this._panels.splice(t,1),this.mostRecentlyUsed.includes(e)){let t=this.mostRecentlyUsed.indexOf(e);this.mostRecentlyUsed.splice(t,1)}let n=this._panelDisposables.get(e.id);n&&(n.dispose(),this._panelDisposables.delete(e.id)),this.removePanelFromTabGroup(e.id),this._onDidRemovePanel.fire({panel:e})}doAddPanel(e,t=this.panels.length,n){let r=this._panels.indexOf(e)>-1;this.tabsContainer.show(),this.contentContainer.show(),this.tabsContainer.openPanel(e,t),n?.skipSetActive?e.api.renderer===`always`&&this.contentContainer.renderPanel(e,{asActive:!1}):this.contentContainer.openPanel(e),!r&&(this.updateMru(e),this.panels.splice(t,0,e),this._panelDisposables.set(e.id,new Y(e.api.onDidTitleChange(e=>this._onDidPanelTitleChange.fire(e)),e.api.onDidParametersChange(e=>this._onDidPanelParametersChange.fire(e)))),this._onDidAddPanel.fire({panel:e}))}doSetActivePanel(e){if(this._activePanel!==e){if(this._activePanel=e,e){var t;this._syncActiveTab(),this.contentContainer.openPanel(e),this.layoutContent(),this.updateMru(e),this.contentContainer.refreshFocusState(),this._onDidActivePanelChange.fire({panel:e,origin:(t=this.accessor).currentOrigin?.call(t)??`user`})}this.updateAccessibleLabel()}}updateAccessibleLabel(){let e=this._activePanel?.title;e?this.container.setAttribute(`aria-label`,e):this.container.removeAttribute(`aria-label`)}updateMru(e){this.mostRecentlyUsed.includes(e)&&this.mostRecentlyUsed.splice(this.mostRecentlyUsed.indexOf(e),1),this.mostRecentlyUsed=[e,...this.mostRecentlyUsed]}updateContainer(){this.panels.forEach(e=>e.runEvents());let e=this.isEmpty||!this._activePanel;if(e&&!this.watermark){let e=this.accessor.createWatermarkComponent();e.init({containerApi:this._api,group:this.groupPanel}),this.watermark=e,Z(this.watermark.element,`pointerdown`,()=>{this.isActive||this.accessor.doSetGroupActive(this.groupPanel)}),this.contentContainer.element.appendChild(this.watermark.element)}if(!e&&this.watermark){var t,n;this.watermark.element.remove(),(t=(n=this.watermark).dispose)==null||t.call(n),this.watermark=void 0}}canDisplayOverlay(e,t,n){let r=new pq(e,n,t,pW,this.accessor.getPanel(this.id));return this._onUnhandledDragOver.fire(r),r.isAccepted}canDisplayContentOverlay(e,t){if(this.locked===`no-drop-target`||this.locked&&t===`center`)return!1;let n=pW();return!n&&e.shiftKey&&this.location.type!==`floating`?!1:n?.viewId===this.accessor.id||this.canDisplayOverlay(e,t,`content`)}handleDropEvent(e,t,n,r,i){if(this.locked===`no-drop-target`)return;if(e===`content`&&i){this.accessor.dockToLayoutEdge(t,n);return}function a(){switch(e){case`header`:return typeof r==`number`?`tab`:`header_space`;case`content`:return`content`}}let o=typeof r==`number`?this.panels[r]:void 0,s=new Hq({nativeEvent:t,position:n,panel:o,index:r,getData:()=>pW(),kind:a(),group:this.groupPanel,api:this._api});if(this._onWillDrop.fire(s),s.defaultPrevented)return;let c=pW();if(c?.viewId===this.accessor.id){if(e===`content`&&c.groupId===this.id&&(n===`center`||c.panelId===null&&!c.tabGroupId)||e===`header`&&c.groupId===this.id&&c.panelId===null&&!c.tabGroupId)return;if(c.panelId===null){let{groupId:e}=c;this._onMove.fire({target:n,groupId:e,index:r,tabGroupId:c.tabGroupId});return}if(this.tabsContainer.indexOf(c.panelId)!==-1&&this.tabsContainer.size===1&&this.accessor.options.closeEmptyGroups!==!1)return;let{groupId:t,panelId:i}=c;if(this.id===t&&!n&&this.tabsContainer.indexOf(i)===r)return;this._onMove.fire({target:n,groupId:c.groupId,itemId:c.panelId,index:r})}else this._onDidDrop.fire(new Vq({nativeEvent:t,position:n,panel:o,index:r,getData:()=>pW(),group:this.groupPanel,api:this._api}))}updateDragAndDropState(){this.tabsContainer.updateDragAndDropState()}dispose(){var e,t,n;super.dispose(),(e=this.watermark)==null||e.element.remove(),(t=this.watermark)==null||(n=t.dispose)==null||n.call(t),this.watermark=void 0;for(let e of[...this._tabGroups])e.dispose();for(let e of this._tabGroupDisposables.values())e.dispose();this._tabGroupDisposables.clear();for(let e of this._pendingMicrotaskDisposables)e.dispose();this._pendingMicrotaskDisposables.clear();for(let e of this.panels)e.dispose();this.tabsContainer.dispose(),this.contentContainer.dispose()}},Wq=class extends RK{constructor(e,t,n){super(e,t),this._onDidConstraintsChangeInternal=new X,this.onDidConstraintsChangeInternal=this._onDidConstraintsChangeInternal.event,this._onDidConstraintsChange=new X,this.onDidConstraintsChange=this._onDidConstraintsChange.event,this._onDidSizeChange=new X,this.onDidSizeChange=this._onDidSizeChange.event,this.addDisposables(this._onDidConstraintsChangeInternal,this._onDidConstraintsChange,this._onDidSizeChange),n&&this.initialize(n)}setConstraints(e){this._onDidConstraintsChangeInternal.fire(e)}setSize(e){this._onDidSizeChange.fire(e)}},Gq=class extends VK{get priority(){return this._priority}get snap(){return this._snap}get minimumWidth(){return this.__minimumWidth()}get minimumHeight(){return this.__minimumHeight()}get maximumHeight(){return this.__maximumHeight()}get maximumWidth(){return this.__maximumWidth()}__minimumWidth(){let e=typeof this._minimumWidth==`function`?this._minimumWidth():this._minimumWidth;return e!==this._evaluatedMinimumWidth&&(this._evaluatedMinimumWidth=e,this.updateConstraints()),e}__maximumWidth(){let e=typeof this._maximumWidth==`function`?this._maximumWidth():this._maximumWidth;return e!==this._evaluatedMaximumWidth&&(this._evaluatedMaximumWidth=e,this.updateConstraints()),e}__minimumHeight(){let e=typeof this._minimumHeight==`function`?this._minimumHeight():this._minimumHeight;return e!==this._evaluatedMinimumHeight&&(this._evaluatedMinimumHeight=e,this.updateConstraints()),e}__maximumHeight(){let e=typeof this._maximumHeight==`function`?this._maximumHeight():this._maximumHeight;return e!==this._evaluatedMaximumHeight&&(this._evaluatedMaximumHeight=e,this.updateConstraints()),e}get isActive(){return this.api.isActive}get isVisible(){return this.api.isVisible}constructor(e,t,n,r){super(e,t,r??new Wq(e,t)),this._evaluatedMinimumWidth=0,this._evaluatedMaximumWidth=2**53-1,this._evaluatedMinimumHeight=0,this._evaluatedMaximumHeight=2**53-1,this._minimumWidth=0,this._minimumHeight=0,this._maximumWidth=2**53-1,this._maximumHeight=2**53-1,this._snap=!1,this._onDidChange=new X,this.onDidChange=this._onDidChange.event,typeof n?.minimumWidth==`number`&&(this._minimumWidth=n.minimumWidth),typeof n?.maximumWidth==`number`&&(this._maximumWidth=n.maximumWidth),typeof n?.minimumHeight==`number`&&(this._minimumHeight=n.minimumHeight),typeof n?.maximumHeight==`number`&&(this._maximumHeight=n.maximumHeight),this.api.initialize(this),this.addDisposables(this.api.onWillVisibilityChange(e=>{let{isVisible:t}=e,{accessor:n}=this._params;n.setVisible(this,t)}),this.api.onActiveChange(()=>{let{accessor:e}=this._params;e.doSetGroupActive(this)}),this.api.onDidConstraintsChangeInternal(e=>this.applyConstraints(e)),this.api.onDidSizeChange(e=>{this._onDidChange.fire({height:e.height,width:e.width})}),this._onDidChange)}setVisible(e){this.api._onDidVisibilityChange.fire({isVisible:e})}setActive(e){this.api._onDidActiveChange.fire({isActive:e})}init(e){e.maximumHeight&&(this._maximumHeight=e.maximumHeight),e.minimumHeight&&(this._minimumHeight=e.minimumHeight),e.maximumWidth&&(this._maximumWidth=e.maximumWidth),e.minimumWidth&&(this._minimumWidth=e.minimumWidth),this._priority=e.priority,this._snap=!!e.snap,super.init(e),typeof e.isVisible==`boolean`&&this.setVisible(e.isVisible)}applyConstraints(e){(typeof e.minimumWidth==`number`||typeof e.minimumWidth==`function`)&&(this._minimumWidth=e.minimumWidth),(typeof e.minimumHeight==`number`||typeof e.minimumHeight==`function`)&&(this._minimumHeight=e.minimumHeight),(typeof e.maximumWidth==`number`||typeof e.maximumWidth==`function`)&&(this._maximumWidth=e.maximumWidth),(typeof e.maximumHeight==`number`||typeof e.maximumHeight==`function`)&&(this._maximumHeight=e.maximumHeight),this.notifyConstraintsChanged()}notifyConstraintsChanged(){this._onDidChange.fire(void 0)}updateConstraints(){this.api._onDidConstraintsChange.fire({minimumWidth:this._evaluatedMinimumWidth,maximumWidth:this._evaluatedMaximumWidth,minimumHeight:this._evaluatedMinimumHeight,maximumHeight:this._evaluatedMaximumHeight})}toJSON(){let e=super.toJSON(),t=e=>e===2**53-1?void 0:e,n=e=>e<=0?void 0:e;return $($({},e),{},{minimumHeight:n(this.minimumHeight),maximumHeight:t(this.maximumHeight),minimumWidth:n(this.minimumWidth),maximumWidth:t(this.maximumWidth),snap:this.snap,priority:this.priority})}},Kq=`dockview: DockviewGroupPanelApiImpl not initialized`,qq=class extends Wq{get location(){if(!this._group)throw Error(Kq);return this._group.model.location}get boundingBox(){if(!this._group||this._group.model.location.type===`popout`)return;let e=this.accessor.element.getBoundingClientRect(),t=this._group.element.getBoundingClientRect();return{left:t.left-e.left,top:t.top-e.top,width:t.width,height:t.height}}get locked(){if(!this._group)throw Error(Kq);return this._group.locked}set locked(e){if(!this._group)throw Error(Kq);this._group.locked=e}constructor(e,t){super(e,`__dockviewgroup__`),this.accessor=t,this._isApplyingSize=!1,this._onDidLocationChange=new X,this.onDidLocationChange=this._onDidLocationChange.event,this._onDidActivePanelChange=new X,this.onDidActivePanelChange=this._onDidActivePanelChange.event,this._onDidCollapsedChange=new X,this.onDidCollapsedChange=this._onDidCollapsedChange.event,this._onDidPeekChange=new X,this.onDidPeekChange=this._onDidPeekChange.event,this._onDidHeaderDirectionChange=new X,this.onDidHeaderDirectionChange=this._onDidHeaderDirectionChange.event,this.addDisposables(this._onDidLocationChange,this._onDidActivePanelChange,this._onDidCollapsedChange,this._onDidPeekChange,this._onDidHeaderDirectionChange,this._onDidVisibilityChange.event(e=>{if(e.isVisible&&this._pendingSize){let e=this._pendingSize;this._pendingSize=void 0,super.setSize(e)}}),this.onDidDimensionsChange(e=>{let t=e.width!==this._reportedSize?.width||e.height!==this._reportedSize?.height;this._reportedSize={width:e.width,height:e.height},t&&this.isVisible&&!this._isApplyingSize&&(this._pendingSize=void 0)}))}setSize(e){(typeof e.width==`number`||typeof e.height==`number`)&&(this._pendingSize=$({},e));let t=this._isApplyingSize;this._isApplyingSize=!0;try{super.setSize(e)}finally{this._isApplyingSize=t}}close(){if(this._group)return this.accessor.removeGroup(this._group)}getWindow(){return this.location.type===`popout`?this.location.getWindow():globalThis.window}setHeaderPosition(e){if(!this._group)throw Error(Kq);this._group.model.headerPosition=e}getHeaderPosition(){if(!this._group)throw Error(Kq);return this._group.model.headerPosition}moveTo(e){if(!this._group)throw Error(Kq);this.accessor.withOrigin(`api`,()=>{let t=e.group??this.accessor.addGroup({direction:gK(e.position??`right`),skipSetActive:e.skipSetActive??!1});this.accessor.moveGroupOrPanel({from:{groupId:this._group.id},to:{group:t,position:e.group?e.position??`center`:`center`,index:e.index},skipSetActive:e.skipSetActive})})}maximize(){if(!this._group)throw Error(Kq);this.location.type===`grid`&&this.accessor.maximizeGroup(this._group)}isMaximized(){if(!this._group)throw Error(Kq);return this.accessor.isMaximizedGroup(this._group)}exitMaximized(){if(!this._group)throw Error(Kq);this.isMaximized()&&this.accessor.exitMaximizedGroup()}collapse(){this._group&&this.accessor.setEdgeGroupCollapsed(this._group,!0)}expand(){this._group&&this.accessor.setEdgeGroupCollapsed(this._group,!1)}isCollapsed(){return this._group?this.accessor.isEdgeGroupCollapsed(this._group):!1}isPeeking(){return this._group?this.accessor.isEdgeGroupPeeking(this._group):!1}setAutoHide(e){this._group&&this.accessor.setEdgeGroupAutoHide(this._group,e)}isAutoHide(){return this._group?this.accessor.isEdgeGroupAutoHide(this._group):!1}initialize(e){this._group=e}},Jq=100,Yq=100,Xq=class extends Gq{get minimumWidth(){if(typeof this._explicitConstraints.minimumWidth==`number`)return this._explicitConstraints.minimumWidth;let e=this.activePanel?.minimumWidth;return typeof e==`number`?e:super.__minimumWidth()}get minimumHeight(){if(typeof this._explicitConstraints.minimumHeight==`number`)return this._explicitConstraints.minimumHeight;let e=this.activePanel?.minimumHeight;return typeof e==`number`?e:super.__minimumHeight()}get maximumWidth(){if(typeof this._explicitConstraints.maximumWidth==`number`)return this._explicitConstraints.maximumWidth;let e=this.activePanel?.maximumWidth;return typeof e==`number`?e:super.__maximumWidth()}get maximumHeight(){if(typeof this._explicitConstraints.maximumHeight==`number`)return this._explicitConstraints.maximumHeight;let e=this.activePanel?.maximumHeight;return typeof e==`number`?e:super.__maximumHeight()}get panels(){return this._model.panels}get activePanel(){return this._model.activePanel}get size(){return this._model.size}get model(){return this._model}get locked(){return this._model.locked}set locked(e){this._model.locked=e}get header(){return this._model.header}constructor(e,t,n){super(t,`groupview_default`,{minimumHeight:n.constraints?.minimumHeight??Yq,minimumWidth:n.constraints?.minimumWidth??Jq,maximumHeight:n.constraints?.maximumHeight,maximumWidth:n.constraints?.maximumWidth},new qq(t,e)),this._explicitConstraints={},this.api.initialize(this),this._model=new Uq(this.element,e,t,n,this),this._lastConstraints=this.currentConstraints(),this.addDisposables(this.model.onDidActivePanelChange(e=>{this.api._onDidActivePanelChange.fire(e),this.notifyIfConstraintsChanged()}))}applyConstraints(e){e.minimumWidth!==void 0&&(this._explicitConstraints.minimumWidth=typeof e.minimumWidth==`function`?e.minimumWidth():e.minimumWidth),e.minimumHeight!==void 0&&(this._explicitConstraints.minimumHeight=typeof e.minimumHeight==`function`?e.minimumHeight():e.minimumHeight),e.maximumWidth!==void 0&&(this._explicitConstraints.maximumWidth=typeof e.maximumWidth==`function`?e.maximumWidth():e.maximumWidth),e.maximumHeight!==void 0&&(this._explicitConstraints.maximumHeight=typeof e.maximumHeight==`function`?e.maximumHeight():e.maximumHeight),super.applyConstraints(e),this._lastConstraints=this.currentConstraints()}currentConstraints(){return{minimumWidth:this.minimumWidth,maximumWidth:this.maximumWidth,minimumHeight:this.minimumHeight,maximumHeight:this.maximumHeight}}notifyIfConstraintsChanged(){let e=this._lastConstraints,t=this.currentConstraints();(e.minimumWidth!==t.minimumWidth||e.maximumWidth!==t.maximumWidth||e.minimumHeight!==t.minimumHeight||e.maximumHeight!==t.maximumHeight)&&(this._lastConstraints=t,this.notifyConstraintsChanged())}focus(){this.api.isActive||this.api.setActive(),super.focus()}initialize(){this._model.initialize()}setActive(e){super.setActive(e),this.model.setActive(e)}layout(e,t){super.layout(e,t),this.model.layout(e,t)}relayout(){this.model.relayout()}getComponent(){return this._model}toJSON(){return this.model.toJSON()}},Zq={name:`abyss`,className:`dockview-theme-abyss`,colorScheme:`dark`,tabGroupIndicator:`none`},Qq=class extends Wq{get location(){return this.group.api.location}get title(){return this.panel.title}get isPinned(){return this.panel.isPinned}get isGroupActive(){return this.group.isActive}get renderer(){return this.panel.renderer}set group(e){if(this._group!==e){let t=this._group.isActive;this._group=e,this._onDidGroupChange.fire({}),this.setupGroupEventListeners(),t!==this.isGroupActive&&this._onDidActiveGroupChange.fire({isActive:this.isGroupActive}),this.fireLocationChange()}}get group(){return this._group}get tabComponent(){return this._tabComponent}constructor(e,t,n,r,i){super(e.id,r),this.panel=e,this.accessor=n,this._onDidTitleChange=new X,this.onDidTitleChange=this._onDidTitleChange.event,this._onDidChangePinned=new X,this.onDidChangePinned=this._onDidChangePinned.event,this._onDidActiveGroupChange=new X,this.onDidActiveGroupChange=this._onDidActiveGroupChange.event,this._onDidGroupChange=new X,this.onDidGroupChange=this._onDidGroupChange.event,this._onDidRendererChange=new X,this.onDidRendererChange=this._onDidRendererChange.event,this._onDidLocationChange=new X,this.onDidLocationChange=this._onDidLocationChange.event,this.groupEventsDisposable=new gW,this._tabComponent=i,this.initialize(e),this._group=t,this.setupGroupEventListeners(),this.addDisposables(this.groupEventsDisposable,this._onDidRendererChange,this._onDidTitleChange,this._onDidChangePinned,this._onDidGroupChange,this._onDidActiveGroupChange,this._onDidLocationChange)}getWindow(){return this.group.api.getWindow()}setActive(){this.accessor.withOrigin(`api`,()=>super.setActive())}moveTo(e){this.accessor.withOrigin(`api`,()=>this.accessor.moveGroupOrPanel({from:{groupId:this._group.id,panelId:this.panel.id},to:{group:e.group??this._group,position:e.group?e.position??`center`:`center`,index:e.index},skipSetActive:e.skipSetActive}))}setTitle(e){this.panel.setTitle(e)}setPinned(e){this.accessor.setPanelPinned(this.panel,e)}setRenderer(e){this.panel.setRenderer(e)}close(){this.group.model.closePanel(this.panel)}maximize(){this.group.api.maximize()}isMaximized(){return this.group.api.isMaximized()}exitMaximized(){this.group.api.exitMaximized()}fireLocationChange(){this.accessor.deferLocationChange(this,()=>{this.isDisposed||this._onDidLocationChange.fire({location:this.location})})}setupGroupEventListeners(){let e=this.isGroupActive;this.groupEventsDisposable.value=new Y(this.group.api.onDidVisibilityChange(e=>{let t=!e.isVisible&&this.isVisible,n=e.isVisible&&!this.isVisible,r=this.group.model.isPanelActive(this.panel);(t||n&&r)&&this._onDidVisibilityChange.fire(e)}),this.group.api.onDidLocationChange(()=>{this.group===this.panel.group&&this.fireLocationChange()}),this.group.api.onDidActiveChange(()=>{this.group===this.panel.group&&e!==this.isGroupActive&&(e=this.isGroupActive,this._onDidActiveGroupChange.fire({isActive:this.isGroupActive}))}))}},$q=class extends Y{get params(){return this._params}get title(){return this._title}get isPinned(){return this._pinned}get group(){return this._group}get renderer(){return this._renderer??this.accessor.renderer}get minimumWidth(){return this._minimumWidth}get minimumHeight(){return this._minimumHeight}get maximumWidth(){return this._maximumWidth}get maximumHeight(){return this._maximumHeight}constructor(e,t,n,r,i,a,o,s){super(),this.id=e,this.accessor=r,this.containerApi=i,this.view=o,this._pinned=!1,this._renderer=s.renderer,this._group=a,this._minimumWidth=s.minimumWidth,this._minimumHeight=s.minimumHeight,this._maximumWidth=s.maximumWidth,this._maximumHeight=s.maximumHeight,this.api=new Qq(this,this._group,r,t,n),this.addDisposables(this.api.onActiveChange(()=>{r.setActivePanel(this)}),this.api.onDidSizeChange(e=>{this.group.api.setSize(e)}),this.api.onDidRendererChange(()=>{this.group.model.rerender(this)}))}init(e){this._params=e.params,this.view.init($($({},e),{},{api:this.api,containerApi:this.containerApi})),this.setTitle(e.title)}focus(){let e=new LK;this.api._onWillFocus.fire(e),e.defaultPrevented||this.api.isActive||this.api.setActive()}toJSON(){return{id:this.id,contentComponent:this.view.contentComponent,tabComponent:this.view.tabComponent,params:Object.keys(this._params||{}).length>0?this._params:void 0,title:this.title,renderer:this._renderer,minimumHeight:this._minimumHeight,maximumHeight:this._maximumHeight,minimumWidth:this._minimumWidth,maximumWidth:this._maximumWidth,pinned:this._pinned?!0:void 0}}setTitle(e){e!==this.title&&(this._title=e,this.view.setTitle(e),this.api._onDidTitleChange.fire({title:e}))}setPinned(e){this._pinned!==e&&(this._pinned=e,this.api._onDidChangePinned.fire({isPinned:e}))}setRenderer(e){e!==this.renderer&&(this._renderer=e,this.api._onDidRendererChange.fire({renderer:e}))}update(e){this._params=$($({},this._params),e.params);for(let t of Object.keys(e.params))e.params[t]===void 0&&delete this._params[t];this.view.update({params:this._params})}updateFromStateModel(e){this._maximumHeight=e.maximumHeight,this._minimumHeight=e.minimumHeight,this._maximumWidth=e.maximumWidth,this._minimumWidth=e.minimumWidth,this._params=e.params??{},this.view.update({params:this._params}),this.setTitle(e.title??this.id),this.setRenderer(e.renderer??this.accessor.renderer),this.setPinned((e.pinned??!1)&&!!this.accessor.options.pinnedTabs?.enabled)}updateParentGroup(e,t){this._group=e,this.api.group=this._group;let n=this._group.model.isPanelActive(this),r=this.group.api.isActive&&n;t?.skipSetActive||this.api.isActive!==r&&this.api._onDidActiveChange.fire({isActive:this.group.api.isActive&&n}),this.api.isVisible!==n&&this.api._onDidVisibilityChange.fire({isVisible:n})}runEvents(){let e=this._group.model.isPanelActive(this),t=this.group.api.isActive&&e;this.api.isActive!==t&&this.api._onDidActiveChange.fire({isActive:this.group.api.isActive&&e}),this.api.isVisible!==e&&this.api._onDidVisibilityChange.fire({isVisible:e})}layout(e,t){this.api._onDidDimensionChange.fire({width:e,height:t}),this.view.layout(e,t)}dispose(){this.api.dispose(),this.view.dispose()}},eJ=class extends Y{get element(){return this._element}constructor(){super(),this._messages=QG,this._element=document.createElement(`div`),this._element.className=`dv-default-tab`,this._content=document.createElement(`div`),this._content.className=`dv-default-tab-content`,this.action=document.createElement(`div`),this.action.className=`dv-default-tab-action`,this.action.setAttribute(`role`,`button`),this.action.setAttribute(`tabindex`,`-1`);let e=JK();e.setAttribute(`aria-hidden`,`true`),this.action.appendChild(e),this._element.appendChild(this._content),this._element.appendChild(this.action),this.render()}init(e){this._title=e.title,this._messages=e.containerApi.messages??QG,this.addDisposables(e.api.onDidTitleChange(e=>{this._title=e.title,this.render()}),Z(this.action,`pointerdown`,e=>{e.preventDefault()}),Z(this.action,`click`,t=>{t.defaultPrevented||(t.preventDefault(),e.api.close())})),this.render()}render(){this._content.textContent!==this._title&&(this._content.textContent=this._title??``),this.action.setAttribute(`aria-label`,this._title?this._messages.closeTab(this._title):this._messages.closeTabPlain())}},tJ=class{get content(){return this._content}get tab(){return this._tab}constructor(e,t,n,r){this.accessor=e,this.id=t,this.contentComponent=n,this.tabComponent=r,this._content=this.createContentComponent(this.id,n),this._tab=this.createTabComponent(this.id,r)}createTabRenderer(e){let t=this.createTabComponent(this.id,this.tabComponent);if(this._params&&t.init($($({},this._params),{},{tabLocation:e})),this._updateEvent){var n;(n=t.update)==null||n.call(t,this._updateEvent)}return t}init(e){this._params=e,this.content.init(e),this.tab.init($($({},e),{},{tabLocation:`header`}))}setTitle(e){this._params&&(this._params.title=e)}layout(e,t){var n,r;(n=(r=this.content).layout)==null||n.call(r,e,t)}update(e){var t,n,r,i;this._updateEvent=e,(t=(n=this.content).update)==null||t.call(n,e),(r=(i=this.tab).update)==null||r.call(i,e)}dispose(){var e,t,n,r;(e=(t=this.content).dispose)==null||e.call(t),(n=(r=this.tab).dispose)==null||n.call(r)}createContentComponent(e,t){return this.accessor.options.createComponent({id:e,name:t})}createTabComponent(e,t){let n=t??this.accessor.options.defaultTabComponent;if(n){if(this.accessor.options.createTabComponent)return this.accessor.options.createTabComponent({id:e,name:n})||new eJ;console.warn(`dockview: tabComponent '${t}' was not found. falling back to the default tab.`)}return new eJ}},nJ=class{constructor(e){this.accessor=e}fromJSON(e,t){let n=e.id,r=e.params,i=e.title,a=e.view,o=a?a.content.id:e.contentComponent??`unknown`,s=a?a.tab?.id:e.tabComponent,c=new tJ(this.accessor,n,o,s),l=new $q(n,o,s,this.accessor,new rK(this.accessor),t,c,{renderer:e.renderer,minimumWidth:e.minimumWidth,minimumHeight:e.minimumHeight,maximumWidth:e.maximumWidth,maximumHeight:e.maximumHeight});return l.init({title:i??n,params:r??{}}),e.pinned&&this.accessor.options.pinnedTabs?.enabled&&l.setPinned(!0),l}},rJ=class extends Y{get element(){return this._element}constructor(){super(),this._element=document.createElement(`div`),this._element.className=`dv-watermark`}init(e){}},iJ=new class{constructor(){this._orderedList=[]}push(e){this._orderedList=[...this._orderedList.filter(t=>t!==e),e],this.update()}destroy(e){this._orderedList=this._orderedList.filter(t=>t!==e),this.update()}update(){for(let e=0;e<this._orderedList.length;e++)this._orderedList[e].setAttribute(`aria-level`,`${e}`),this._orderedList[e].style.zIndex=`calc(var(--dv-overlay-z-index, 999) + ${e*2})`}};function aJ(e){return e.width>0&&e.height>0}var oJ=class e extends Y{set minimumInViewportWidth(e){this.options.minimumInViewportWidth=e}set minimumInViewportHeight(e){this.options.minimumInViewportHeight=e}get element(){return this._element}get isVisible(){return this._isVisible}get headerHeight(){return this.options.header?.offsetHeight??0}constructor(e){super(),this.options=e,this._element=document.createElement(`div`),this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this._onDidChangeEnd=new X,this.onDidChangeEnd=this._onDidChangeEnd.event,this._onDidStartMoving=new X,this.onDidStartMoving=this._onDidStartMoving.event,this._dragMove=new gW,this._dragCancelled=!1,this.addDisposables(this._onDidChange,this._onDidChangeEnd,this._onDidStartMoving,this._dragMove),this._element.className=`dv-resize-container`,this._element.setAttribute(`role`,`dialog`),this._element.setAttribute(`aria-modal`,`false`),this._isVisible=!0,this.setupResize(`top`),this.setupResize(`bottom`),this.setupResize(`left`),this.setupResize(`right`),this.setupResize(`topleft`),this.setupResize(`topright`),this.setupResize(`bottomleft`),this.setupResize(`bottomright`),this.options.header&&(Q(this._element,`dv-resize-container-with-titlebar`,!0),this._element.appendChild(this.options.header)),this._element.appendChild(this.options.content),this.options.container.appendChild(this._element),this.setBounds($($($($({height:this.options.height,width:this.options.width},`top`in this.options&&{top:this.options.top}),`bottom`in this.options&&{bottom:this.options.bottom}),`left`in this.options&&{left:this.options.left}),`right`in this.options&&{right:this.options.right})),iJ.push(this._element)}setVisible(e){e!==this.isVisible&&(this._isVisible=e,Q(this.element,`dv-hidden`,!this.isVisible))}bringToFront(){iJ.push(this._element)}setBounds(e={}){typeof e.height==`number`&&(this._element.style.height=`${e.height}px`),typeof e.width==`number`&&(this._element.style.width=`${e.width}px`),`top`in e&&typeof e.top==`number`&&(this._element.style.top=`${e.top}px`,this._element.style.bottom=`auto`,this.verticalAlignment=`top`),`bottom`in e&&typeof e.bottom==`number`&&(this._element.style.bottom=`${e.bottom}px`,this._element.style.top=`auto`,this.verticalAlignment=`bottom`),`left`in e&&typeof e.left==`number`&&(this._element.style.left=`${e.left}px`,this._element.style.right=`auto`,this.horiziontalAlignment=`left`),`right`in e&&typeof e.right==`number`&&(this._element.style.right=`${e.right}px`,this._element.style.left=`auto`,this.horiziontalAlignment=`right`);let t=this.options.container.getBoundingClientRect(),n=this._element.getBoundingClientRect();if(!aJ(t)||!aJ(n)){this._onDidChange.fire();return}let r=Math.max(0,this.getMinimumWidth(n.width)),i=Math.max(0,this.getMinimumHeight(n.height));if(this.verticalAlignment===`top`){let e=hG(n.top-t.top,-i,Math.max(0,t.height-n.height+i));this._element.style.top=`${e}px`,this._element.style.bottom=`auto`}if(this.verticalAlignment===`bottom`){let e=hG(t.bottom-n.bottom,-i,Math.max(0,t.height-n.height+i));this._element.style.bottom=`${e}px`,this._element.style.top=`auto`}if(this.horiziontalAlignment===`left`){let e=hG(n.left-t.left,-r,Math.max(0,t.width-n.width+r));this._element.style.left=`${e}px`,this._element.style.right=`auto`}if(this.horiziontalAlignment===`right`){let e=hG(t.right-n.right,-r,Math.max(0,t.width-n.width+r));this._element.style.right=`${e}px`,this._element.style.left=`auto`}this._onDidChange.fire()}toJSON(){let e=this.options.container.getBoundingClientRect(),t=this._element.getBoundingClientRect(),n={};return this.verticalAlignment===`top`?n.top=Number.parseFloat(this._element.style.top):this.verticalAlignment===`bottom`?n.bottom=Number.parseFloat(this._element.style.bottom):n.top=t.top-e.top,this.horiziontalAlignment===`left`?n.left=Number.parseFloat(this._element.style.left):this.horiziontalAlignment===`right`?n.right=Number.parseFloat(this._element.style.right):n.left=t.left-e.left,aJ(t)?(n.width=t.width,n.height=t.height):(n.width=Number.parseFloat(this._element.style.width)||0,n.height=Number.parseFloat(this._element.style.height)||0),n}cancelPendingDrag(){this._dragMove.value&&(this._dragCancelled=!0,Q(this._element,`dv-resize-container-dragging`,!1),this._dragMove.value=hW.NONE)}setupDrag(e,t){let n=(e,t)=>{var n;let r=null,i=!1;this._dragCancelled=!1;let a=this.options.transformDragPosition?(n=this.options).getSiblingBoxes?.call(n)??[]:[],o=WW();if(e&&typeof t==`number`&&typeof e.setPointerCapture==`function`)try{e.setPointerCapture(t)}catch{}let s=()=>{Q(this._element,`dv-resize-container-dragging`,!1),this._dragMove.value=hW.NONE,this._onDidChangeEnd.fire()};this._dragMove.value=new Y({dispose:()=>{if(o.release(),e&&typeof t==`number`&&typeof e.releasePointerCapture==`function`)try{e.releasePointerCapture(t)}catch{}}},Z(globalThis.window,`pointermove`,e=>{if(this._dragCancelled)return;let t=this.options.container.getBoundingClientRect(),n=e.clientX-t.left,o=e.clientY-t.top;Q(this._element,`dv-resize-container-dragging`,!0);let s=this._element.getBoundingClientRect();r??={x:e.clientX-s.left,y:e.clientY-s.top};let c=Math.max(0,this.getMinimumWidth(s.width)),l=Math.max(0,this.getMinimumHeight(s.height)),u=o-r.y,d=n-r.x;if(this.options.transformDragPosition){let n=this.options.transformDragPosition({proposed:{top:u,left:d,width:s.width,height:s.height},container:{width:t.width,height:t.height},others:a,modifiers:{altKey:e.altKey,ctrlKey:e.ctrlKey,metaKey:e.metaKey,shiftKey:e.shiftKey}});n&&(u=n.top,d=n.left)}let f=Math.max(0,t.height-s.height+l),p=Math.max(0,t.width-s.width+c),m=hG(u,-l,f),h=hG(t.height-s.height-u,-l,f),g=hG(d,-c,p),_=hG(t.width-s.width-d,-c,p),v={};m<=h?v.top=m:v.bottom=h,g<=_?v.left=g:v.right=_,this.setBounds(v),i||(i=!0,this._onDidStartMoving.fire())}),Z(globalThis.window,`pointerup`,s),Z(globalThis.window,`pointercancel`,s))};this.addDisposables(Z(e,`pointerdown`,t=>{t.defaultPrevented?t.preventDefault():NW(t)||n(e,t.pointerId)}),Z(this.options.content,`pointerdown`,e=>{e.defaultPrevented||NW(e)||e.shiftKey&&n(this.options.content,e.pointerId)}),Z(this.options.content,`pointerdown`,()=>{iJ.push(this._element)},!0)),t?.inDragMode&&n()}setupResize(t){let n=document.createElement(`div`);n.className=`dv-resize-handle-${t}`,this._element.appendChild(n);let r=new gW;this.addDisposables(r,Z(n,`pointerdown`,i=>{i.preventDefault();let a=null,o=WW(),s=i.pointerId;if(typeof n.setPointerCapture==`function`)try{n.setPointerCapture(s)}catch{}let c=()=>{r.dispose(),this._onDidChangeEnd.fire()};r.value=new Y(Z(globalThis.window,`pointermove`,n=>{let r=this.options.container.getBoundingClientRect(),i=this._element.getBoundingClientRect(),o=n.clientY-r.top,s=n.clientX-r.left;a??={originalY:o,originalHeight:i.height,originalX:s,originalWidth:i.width};let c,l,u,d,f,p,m=()=>{let t=a.originalY+a.originalHeight>r.height?Math.max(0,r.height-e.MINIMUM_HEIGHT):Math.max(0,a.originalY+a.originalHeight-e.MINIMUM_HEIGHT);c=hG(o,0,t),u=a.originalY+a.originalHeight-c,l=r.height-c-u},h=()=>{c=a.originalY-a.originalHeight;let t=c<0&&typeof this.options.minimumInViewportHeight==`number`?-c+this.options.minimumInViewportHeight:e.MINIMUM_HEIGHT,n=r.height-Math.max(0,c);u=hG(o-c,t,n),l=r.height-c-u},g=()=>{let t=a.originalX+a.originalWidth>r.width?Math.max(0,r.width-e.MINIMUM_WIDTH):Math.max(0,a.originalX+a.originalWidth-e.MINIMUM_WIDTH);d=hG(s,0,t),p=a.originalX+a.originalWidth-d,f=r.width-d-p},_=()=>{d=a.originalX-a.originalWidth;let t=d<0&&typeof this.options.minimumInViewportWidth==`number`?-d+this.options.minimumInViewportWidth:e.MINIMUM_WIDTH,n=r.width-Math.max(0,d);p=hG(s-d,t,n),f=r.width-d-p};switch(t){case`top`:m();break;case`bottom`:h();break;case`left`:g();break;case`right`:_();break;case`topleft`:m(),g();break;case`topright`:m(),_();break;case`bottomleft`:h(),g();break;case`bottomright`:h(),_()}let v={};c<=l?v.top=c:v.bottom=l,d<=f?v.left=d:v.right=f,v.height=u,v.width=p,this.setBounds(v)}),{dispose:()=>{if(o.release(),typeof n.releasePointerCapture==`function`)try{n.releasePointerCapture(s)}catch{}}},Z(globalThis.window,`pointerup`,c),Z(globalThis.window,`pointercancel`,c))}))}getMinimumWidth(e){return typeof this.options.minimumInViewportWidth==`number`?e-this.options.minimumInViewportWidth:0}getMinimumHeight(e){return typeof this.options.minimumInViewportHeight==`number`?e-this.options.minimumInViewportHeight:0}dispose(){iJ.destroy(this._element),this._element.remove(),super.dispose()}};oJ.MINIMUM_HEIGHT=20,oJ.MINIMUM_WIDTH=20;var sJ=class extends Y{get element(){return this._element}get group(){return this._group}setGroup(e){this._group=e}constructor(e,t){super(),this.accessor=e,this._onDragStart=new X,this.onDragStart=this._onDragStart.event,this._group=t,this._element=document.createElement(`div`),this._element.className=`dv-floating-titlebar`,this.addDisposables(this._onDragStart,Z(this._element,`pointerdown`,()=>{this.accessor.doSetGroupActive(this._group)}),Z(this._element,`pointerdown`,e=>{e.shiftKey&&MW(e)},!0)),this.dragSource=new sq({element:this._element,accessor:this.accessor,group:()=>this._group}),this.addDisposables(this.dragSource,this.dragSource.onDragStart(e=>{this._onDragStart.fire(e)}))}updateDragAndDropState(){this.dragSource.updateDragAndDropState()}};function cJ(e){return{moduleName:e.name,options:e.options,services:{[e.serviceKey]:e.create},init:e.init?(t,n)=>e.init(t,n[e.serviceKey]):void 0,dependsOn:e.dependsOn}}var lJ=new Set([`AdvancedOverflow`,`AutoEdgeGroup`,`AutoHideEdgeGroup`,`DndCompass`,`KeyboardDocking`,`KeyboardNavigation`,`LayoutHistory`,`License`,`MultiRowTabs`,`PinnedTabs`,`SmartGuides`]),uJ=new Set;function dJ(e,t){let n=t===void 0?[]:[].concat(t),r=n.map(e=>`\`${e}\``).join(`, `),i=n.length>1?`require`:`requires`,a=n.length?`${r} ${i} the "${e}" module`:`The "${e}" module is required`;return lJ.has(e)?`dockview: ${a}, which ships in dockview-enterprise.\n\n npm install dockview-enterprise\n import 'dockview-enterprise'; // self-registers every enterprise module\n`:`dockview: ${a}, but it is not registered.`}function fJ(e,t){let n=`${e}|${(t===void 0?[]:[].concat(t)).join(`|`)}`;uJ.has(n)||(uJ.add(n),console.error(dJ(e,t)))}function pJ(e,t,n){if(e!==void 0)return e;fJ(t,n)}var mJ=class{constructor(){this._modules=new Map,this._services={},this._initDisposables=[]}get services(){return this._services}register(e){if(!this._modules.has(e.moduleName)){if(e.dependsOn)for(let t of e.dependsOn)this.register(t);this._modules.set(e.moduleName,e)}}initialize(e){for(let t of this._modules.values())if(t.services)for(let[n,r]of Object.entries(t.services))this._services[n]=r(e)}postConstruct(e){for(let t of this._modules.values())t.init&&this._initDisposables.push(t.init(e,this._services))}has(e){return this._modules.has(e)}dispose(){for(let e of this._initDisposables)e.dispose();this._initDisposables.length=0;for(let e of Object.values(this._services))e!==void 0&&typeof e.dispose==`function`&&e.dispose()}},hJ=[];function gJ(){return[...hJ]}var _J=[{optionKey:`smartGuides`,reason:`smartGuides`,moduleName:`SmartGuides`,when:e=>!!e.smartGuides&&e.smartGuides.enabled!==!1},{optionKey:`layoutHistory`,reason:`layoutHistory.enabled: true`,moduleName:`LayoutHistory`,when:e=>e.layoutHistory?.enabled===!0},{optionKey:`pinnedTabs`,reason:`pinnedTabs.enabled: true`,moduleName:`PinnedTabs`,when:e=>e.pinnedTabs?.enabled===!0},{optionKey:`overflow`,reason:`overflow.mode: 'wrap'`,moduleName:`MultiRowTabs`,when:e=>e.overflow?.mode===`wrap`},{optionKey:`overflow`,reason:`overflow.maxRows`,moduleName:`MultiRowTabs`,when:e=>e.overflow?.maxRows!=null},{optionKey:`overflow`,reason:`overflow.search`,moduleName:`AdvancedOverflow`,when:e=>!!e.overflow?.search},{optionKey:`overflow`,reason:`overflow.mru`,moduleName:`AdvancedOverflow`,when:e=>!!e.overflow?.mru},{optionKey:`autoHideEdgeGroups`,reason:`autoHideEdgeGroups`,moduleName:`AutoHideEdgeGroup`,when:e=>fq(e.autoHideEdgeGroups)},{optionKey:`dockToEdgeGroups`,reason:`dockToEdgeGroups`,moduleName:`AutoEdgeGroup`,when:e=>fq(e.dockToEdgeGroups)},{optionKey:`dndCompass`,reason:`dndCompass`,moduleName:`DndCompass`,when:e=>!!e.dndCompass},{optionKey:`keyboardNavigation`,reason:`keyboardNavigation`,moduleName:`KeyboardNavigation`,when:e=>!!e.keyboardNavigation}];function vJ(e,t){let n=new Map;for(let r of _J){if(!r.when(e)||t(r.moduleName))continue;let i=n.get(r.moduleName);i?i.push(r.reason):n.set(r.moduleName,[r.reason])}for(let[e,t]of n)fJ(e,t)}var yJ={left:100,top:100,width:300,height:300},bJ=class extends Y{get group(){return this._group}setTitleBar(e){this._titleBar=e}setAnchorGroup(e){var t;this._group=e,(t=this._titleBar)==null||t.setGroup(e),this._onDidChangeAnchorGroup.fire(e)}constructor(e,t,n){super(),this.overlay=t,this.gridview=n,this._onDidChangeAnchorGroup=new X,this.onDidChangeAnchorGroup=this._onDidChangeAnchorGroup.event,this._group=e,this.addDisposables(this._onDidChangeAnchorGroup,t,{dispose:()=>this.gridview.dispose()})}position(e){this.overlay.setBounds(e)}},xJ=class{get floatingGroups(){return this._floatingGroups}constructor(e){this._floatingGroups=[],this._host=e}add(e,t,n){let r=new bJ(e,t,n),i=new Y((()=>{let e=-1,t=-1;return TW(n.element,r=>{let i=Math.round(r.contentRect.width),a=Math.round(r.contentRect.height);(i!==e||a!==t)&&(e=i,t=a,n.layout(i,a))})})()),a=e=>{let n=e.activePanel?.title;n?t.element.setAttribute(`aria-label`,n):t.element.removeAttribute(`aria-label`)},o=new gW,s=e=>{a(e),o.value=new Y(e.api.onDidActiveChange(e=>{e.isActive&&t.bringToFront()}),e.api.onDidActivePanelChange(()=>a(e)),e.onDidChange(e=>{t.setBounds({height:typeof e?.height==`number`?e.height+t.headerHeight:e?.height,width:e?.width})}))};return s(e),r.addDisposables(o,r.onDidChangeAnchorGroup(e=>s(e)),t.onDidChange(()=>{n.layout(n.width,n.height)}),t.onDidChangeEnd(()=>{this._host.fireLayoutChange(`geometry`)}),{dispose:()=>{i.dispose(),mG(this._floatingGroups,r),e.model.location={type:`grid`}}}),this._floatingGroups.push(r),r}findByGroup(e){return this._floatingGroups.find(t=>t.group===e||t.gridview.element.contains(e.element))}serialize(){return this._floatingGroups.map(e=>{let t=e.gridview.serialize(),n=e.overlay.toJSON(),r=t.root;return r.type===`branch`&&r.data.length===1&&r.data[0].type===`leaf`?{data:r.data[0].data,position:n}:{grid:t,position:n}})}constrainBounds(){for(let e of this._floatingGroups)e.overlay.setBounds()}updateBounds(e){if(`floatingGroupBounds`in e)for(let t of this._floatingGroups){switch(e.floatingGroupBounds){case`boundedWithinViewport`:t.overlay.minimumInViewportHeight=void 0,t.overlay.minimumInViewportWidth=void 0;break;case void 0:t.overlay.minimumInViewportHeight=100,t.overlay.minimumInViewportWidth=100;break;default:t.overlay.minimumInViewportHeight=e.floatingGroupBounds?.minimumHeightWithinViewport,t.overlay.minimumInViewportWidth=e.floatingGroupBounds?.minimumWidthWithinViewport}t.overlay.setBounds()}}disposeAll(){for(let e of[...this._floatingGroups])e.dispose()}dispose(){this.disposeAll()}},SJ=cJ({name:`FloatingGroup`,serviceKey:`floatingGroupService`,create:e=>new xJ(e)}),CJ=class{constructor(e){this._entries=[],this._restorationCleanups=new Set,this._restorationPromise=Promise.resolve(),this._onDidRemove=new X,this.onDidRemove=this._onDidRemove.event,this._host=e}get entries(){return this._entries}get restorationPromise(){return this._restorationPromise}add(e){this._entries.push(e)}remove(e){mG(this._entries,e)&&!this._host.isDisposed&&this._onDidRemove.fire(e)}findByGroup(e){return this._entries.find(t=>t.popoutGroup===e||t.gridview.element.contains(e.element))}findReferenceGroupId(e){return this._entries.find(t=>t.popoutGroup===e)?.referenceGroup}observeGridviewSize(e,t,n){let r=e.window?.ResizeObserver;if(!r)return;let i=-1,a=-1,o=()=>{let r=e.window;if(this._host.isDisposed||!r||r.closed)return;let o=Math.round(t.element.clientWidth),s=Math.round(t.element.clientHeight);(o!==i||s!==a)&&(i=o,a=s,o>0&&s>0&&t.layout(o,s),n.updateAllPositions())},s=new r(()=>{let t=e.window?.requestAnimationFrame;t?t.call(e.window,o):o()});return s.observe(t.element),{dispose:()=>s.disconnect()}}scheduleRestoration(e,t,n){return new Promise(r=>{let i=()=>{this._restorationCleanups.delete(i),clearTimeout(a),n?.(),r()},a=setTimeout(()=>{this._restorationCleanups.delete(i),this._host.isDisposed?r():Promise.resolve(t()).then(()=>r(),()=>r())},e);this._restorationCleanups.add(i)})}finishRestoration(e){this._restorationPromise=Promise.all(e).then(()=>void 0)}cancelPendingRestorations(){for(let e of[...this._restorationCleanups])e();this._restorationCleanups.clear()}serialize(){return this._entries.map(e=>{let t=e.gridview.serialize(),n=t.root,r=e.popoutGroup.api.location.type===`popout`?e.popoutGroup.api.location.popoutUrl:void 0,i={gridReferenceGroup:e.referenceGroup,position:e.window.dimensions(),url:r};return n.type===`branch`&&n.data.length===1&&n.data[0].type===`leaf`?$($({},i),{},{data:n.data[0].data}):$($({},i),{},{grid:t})})}disposeAll(){for(let e of[...this._entries])e.disposable.dispose()}dispose(){this.cancelPendingRestorations(),this.disposeAll(),this._onDidRemove.dispose()}},wJ=cJ({name:`PopoutWindow`,serviceKey:`popoutWindowService`,create:e=>new CJ(e)}),TJ=class{constructor(e){this._watermark=null,this._host=e}update(){if(this._host.hasVisibleGridGroup()){this._unmount();return}if(this._watermark)return;this._watermark=this._host.createWatermarkComponent(),this._watermark.init({containerApi:this._host.api});let e=document.createElement(`div`);e.className=`dv-watermark-container`,HW(e,`watermark-component`),e.appendChild(this._watermark.element),this._host.mountElement.appendChild(e)}refresh(){this._unmount(),this.update()}_unmount(){var e,t;this._watermark&&=(this._watermark.element.parentElement.remove(),(e=(t=this._watermark).dispose)==null||e.call(t),null)}dispose(){this._unmount()}},EJ=cJ({name:`Watermark`,serviceKey:`watermarkService`,create:e=>new TJ(e),init:(e,t)=>(t.update(),new Y(_W.any(e.onDidAdd,e.onDidRemove)(()=>{t.update()}),e.onDidViewVisibilityChangeMicroTaskQueue(()=>{t.update()})))}),DJ=class{constructor(){this._edgeGroups=new Map,this._edgeGroupDisposables=new Map,this._autoHide=new WeakMap,this._autoReveal=new WeakMap}add(e,t,n){this._edgeGroups.set(e,t),this._edgeGroupDisposables.set(e,n)}remove(e){var t;(t=this._edgeGroupDisposables.get(e))==null||t.dispose(),this._edgeGroupDisposables.delete(e),this._edgeGroups.delete(e)}get(e){return this._edgeGroups.get(e)}has(e){return this._edgeGroups.has(e)}hasAny(){return this._edgeGroups.size>0}entries(){return this._edgeGroups.entries()}includes(e){for(let t of this._edgeGroups.values())if(t===e)return!0;return!1}findPositionOf(e){for(let[t,n]of this._edgeGroups)if(n===e)return t}setAutoHide(e,t){t===void 0?this._autoHide.delete(e):this._autoHide.set(e,t)}isAutoHide(e){return this._autoHide.get(e)}setAutoReveal(e,t){this._autoReveal.set(e,t)}isAutoReveal(e){return this._autoReveal.get(e)??!1}disposeAll(){for(let e of this._edgeGroupDisposables.values())e.dispose();this._edgeGroupDisposables.clear(),this._edgeGroups.clear()}dispose(){this.disposeAll()}},OJ=cJ({name:`EdgeGroup`,serviceKey:`edgeGroupService`,create:()=>new DJ}),kJ={activationSize:{type:`pixels`,value:10},size:{type:`pixels`,value:20}},AJ={activationSize:{type:`pixels`,value:32},size:{type:`pixels`,value:20}};function jJ(e,t){return typeof e.dndEdges==`object`&&e.dndEdges!==null?e.dndEdges:t&&fq(e.dockToEdgeGroups)?AJ:kJ}var MJ=class{constructor(e){this._host=e;let t=(t,n)=>{let r=pW();return r?r.viewId===e.id?n!==`center`||e.isGridEmpty():!1:n===`center`&&!e.isGridEmpty()?!1:e.dispatchUnhandledDragOver(t,n)},n=jJ(e.options,!1);this._html5Target=NK.createDropTarget(e.element,{className:`dv-drop-target-edge`,canDisplayOverlay:t,acceptedTargetZones:[`top`,`bottom`,`left`,`right`,`center`],overlayModel:n,getOverrideTarget:()=>e.rootDropTargetOverrideTarget(),getPositionResolver:()=>e.options.dropPositionResolver}),this._pointerTarget=PK.createDropTarget(e.element,{className:`dv-drop-target-edge`,canDisplayOverlay:t,acceptedTargetZones:[`top`,`bottom`,`left`,`right`,`center`],overlayModel:n,getOverrideTarget:()=>e.rootDropTargetOverrideTarget(),getPositionResolver:()=>e.options.dropPositionResolver}),this.onWillShowOverlay=_W.any(this._html5Target.onWillShowOverlay,this._pointerTarget.onWillShowOverlay),this.onDrop=_W.any(this._html5Target.onDrop,this._pointerTarget.onDrop),this.setOptions(e.options)}setOptions(e){if(`dndEdges`in e){let t=typeof e.dndEdges==`boolean`&&e.dndEdges===!1;this._html5Target.disabled=t,this._pointerTarget.disabled=t}if(`dndEdges`in e||`dockToEdgeGroups`in e){let t=jJ({dndEdges:`dndEdges`in e?e.dndEdges:this._host.options.dndEdges,dockToEdgeGroups:`dockToEdgeGroups`in e?e.dockToEdgeGroups:this._host.options.dockToEdgeGroups},this._host.hasEdgeDragReveal);this._html5Target.setOverlayModel(t),this._pointerTarget.setOverlayModel(t)}}dispose(){this._html5Target.dispose(),this._pointerTarget.dispose()}},NJ=cJ({name:`RootDropTarget`,serviceKey:`rootDropTargetService`,create:e=>new MJ(e),init:(e,t)=>(t.setOptions(e.options),hW.NONE)}),PJ={left:`createLeftHeaderActionComponent`,right:`createRightHeaderActionComponent`,prefix:`createPrefixHeaderActionComponent`},FJ=class{constructor(e){this._perGroup=new Map,this._host=e}refresh(e){if(!e?.model)return;let t=this._ensureState(e);this._refreshSlot(`left`,e,t.left),this._refreshSlot(`right`,e,t.right),this._refreshSlot(`prefix`,e,t.prefix)}refreshAll(){for(let e of this._host.groups)this.refresh(e)}disposeGroup(e){let t=this._perGroup.get(e);t&&(t.left.dispose(),t.right.dispose(),t.prefix.dispose(),this._perGroup.delete(e))}dispose(){for(let e of[...this._perGroup.keys()])this.disposeGroup(e)}_ensureState(e){let t=this._perGroup.get(e);return t||(t={left:new gW,right:new gW,prefix:new gW},this._perGroup.set(e,t)),t}_refreshSlot(e,t,n){let r=this._host.options[PJ[e]];if(r){let i=r(t);n.value=i,i.init({containerApi:this._host.api,api:t.api,group:t}),t.model.attachHeaderAction(e,i.element)}else n.dispose(),t.model.attachHeaderAction(e,void 0)}},IJ=cJ({name:`HeaderActions`,serviceKey:`headerActionsService`,create:e=>new FJ(e),init:(e,t)=>new Y(e.onDidRemoveGroup(e=>{t.disposeGroup(e)}))}),LJ=e=>e===`load`||e===`clear`;function RJ(e,t){let n=e.createElement(`div`);return n.className=t===`assertive`?`dv-live-region-assertive`:`dv-live-region`,n.setAttribute(`role`,t===`assertive`?`alert`:`status`),n.setAttribute(`aria-live`,t),n.setAttribute(`aria-atomic`,`true`),Object.assign(n.style,{position:`absolute`,width:`1px`,height:`1px`,margin:`-1px`,padding:`0`,overflow:`hidden`,clip:`rect(0 0 0 0)`,clipPath:`inset(50%)`,whiteSpace:`nowrap`,border:`0`}),n}var zJ=class extends Y{constructor(e){super(),this._regions=new Map,this._suppressDepth=0,this._locationSubs=new Map,this._host=e;let t=e.element.ownerDocument;this._mainWindow=t.defaultView??window;let n={polite:RJ(t,`polite`),assertive:RJ(t,`assertive`)};e.element.appendChild(n.polite),e.element.appendChild(n.assertive),this._regions.set(this._mainWindow,n),this._syncPopoutRegions(),this.addDisposables({dispose:()=>this._disposeRegions()},e.onDidChangePopouts(()=>this._syncPopoutRegions()),e.onDidAddPanel(e=>this._announce(e,`open`)),e.onDidRemovePanel(e=>this._announce(e,`close`)),e.onWillMutateLayout(e=>{LJ(e.kind)&&this._suppressDepth++}),e.onDidMutateLayout(e=>{LJ(e.kind)&&(this._suppressDepth=Math.max(0,this._suppressDepth-1))}),e.onDidMaximizedGroupChange(e=>{let t=e.group.activePanel;t&&this._announce(t,e.isMaximized?`maximize`:`restore`)}),e.onDidAddGroup(e=>this._trackLocation(e)),e.onDidRemoveGroup(e=>{var t;(t=this._locationSubs.get(e.id))==null||t.dispose(),this._locationSubs.delete(e.id)}),{dispose:()=>{this._locationSubs.forEach(e=>e.dispose()),this._locationSubs.clear()}})}_syncPopoutRegions(){let e=this._host.element.ownerDocument,t=new Set([this._mainWindow]);for(let n of this._host.getPopoutWindows()){if(n.document===e||(t.add(n),this._regions.has(n)))continue;let r=n.document,i=r.body??r.documentElement,a={polite:RJ(r,`polite`),assertive:RJ(r,`assertive`)};i.appendChild(a.polite),i.appendChild(a.assertive),this._regions.set(n,a)}for(let[e,n]of this._regions)t.has(e)||(n.polite.remove(),n.assertive.remove(),this._regions.delete(e))}_disposeRegions(){for(let e of this._regions.values())e.polite.remove(),e.assertive.remove();this._regions.clear()}_focusedRegions(){for(let[e,t]of this._regions)if(e!==this._mainWindow)try{if(e.document.hasFocus())return t}catch{}return this._regions.get(this._mainWindow)}_trackLocation(e){let t=e.api.location.type,n=e.api.onDidLocationChange(n=>{let r=n.location.type;if(r===t)return;t=r;let i=e.activePanel;if(!i)return;let a;switch(r){case`floating`:a=`float`;break;case`popout`:a=`popout`;break;default:a=`dock`}this._announce(i,a)});this._locationSubs.set(e.id,n)}announce(e,t=`polite`){if(this._host.options.announcements===!1||this._suppressDepth>0||!e)return;let n=this._host.options.announcer;if(n){n({message:e,politeness:t});return}let r=this._focusedRegions(),i=t===`assertive`?r.assertive:r.polite;i.textContent=``,i.textContent=e}_announce(e,t){var n;let r=(n=this._host.options).getAnnouncement?.call(n,{kind:t,panel:e});r!==null&&r!==``&&this.announce(r??this._defaultMessage(e,t))}_defaultMessage(e,t){let n=$G(this._host.options.messages),r=e.title??e.id;switch(t){case`open`:return n.panelOpened(r);case`close`:return n.panelClosed(r);case`maximize`:return n.groupMaximized(r);case`restore`:return n.groupRestored(r);case`float`:return n.groupFloated(r);case`dock`:return n.groupDocked(r);case`popout`:return n.groupPoppedOut(r)}}},BJ=cJ({name:`LiveRegion`,serviceKey:`liveRegionService`,create:e=>new zJ(e)}),VJ=30,HJ=-10,UJ=class{constructor(e){this.host=e}dispatchWillDragPanel(e){this.host.fireWillDragPanel(e)}dispatchWillDragGroup(e){this.host.fireWillDragGroup(e)}dispatchWillDrop(e){this.host.fireWillDrop(e)}dispatchWillShowOverlay(e){this.host.fireWillShowOverlay(e)}buildGroupDragGhost(e){let t=this.host.options.createGroupDragGhostComponent;if(!t)return;let n=t(e);return n.init({group:e,api:this.host.api}),{element:n.element,offsetX:VJ,offsetY:HJ,dispose:n.dispose?()=>n.dispose?.call(n):void 0}}resolveOverlayModel(e,t){var n;return(n=this.host.options).dropOverlayModel?.call(n,{location:e,group:t})}showPreviewOverlay(e,t){let n=e.model.contentDropTarget;return n.showOverlay(t),hW.from(()=>n.clearOverlay())}dispose(){}},WJ=cJ({name:`AdvancedDnD`,serviceKey:`advancedDnDService`,create:e=>new UJ(e)}),GJ=class{constructor(e){this._host=e}attachToGroup(e){return new Y(e.model.onDidCreateTabGroup(e=>{this._host.fireDidCreateTabGroup(e)}),e.model.onDidDestroyTabGroup(e=>{this._host.fireDidDestroyTabGroup(e)}),e.model.onDidAddPanelToTabGroup(e=>{this._host.fireDidAddPanelToTabGroup(e)}),e.model.onDidRemovePanelFromTabGroup(e=>{this._host.fireDidRemovePanelFromTabGroup(e)}),e.model.onDidTabGroupChange(e=>{this._host.fireDidTabGroupChange(e)}),e.model.onDidTabGroupCollapsedChange(e=>{this._host.fireDidTabGroupCollapsedChange(e)}))}dispose(){}},KJ=cJ({name:`TabGroupChips`,serviceKey:`tabGroupChipsService`,create:e=>new GJ(e),init:(e,t)=>{let n=new Map;return new Y(e.onDidAddGroup(e=>{n.set(e,t.attachToGroup(e))}),e.onDidRemoveGroup(e=>{var t;(t=n.get(e))==null||t.dispose(),n.delete(e)}),{dispose:()=>{for(let e of n.values())e.dispose();n.clear()}})}});function qJ(e,t){var n,r;if((n=t.api)!=null&&(r=n.isPeeking)!=null&&r.call(n))return`calc(var(--dv-overlay-z-index, 999) + 100)`;if(!(e instanceof HTMLElement))return;let i=$W(e);return i?.style.zIndex?`calc(${i.style.zIndex} * 2)`:void 0}var JJ=0,YJ=()=>`dv-ctx-menu-item-${JJ++}`;function XJ(e){return typeof e==`object`}function ZJ(e,t,n,r){let i=document.createElement(`div`);return i.className=`dv-context-menu-item`,i.setAttribute(`role`,`menuitem`),r&&(i.classList.add(`dv-context-menu-item--disabled`),i.setAttribute(`aria-disabled`,`true`)),i.textContent=e,r||i.addEventListener(`click`,()=>{n(),t()}),i}function QJ(){let e=document.createElement(`div`);return e.className=`dv-context-menu-separator`,e.setAttribute(`role`,`separator`),e}function $J(){if(globalThis.window===void 0||!globalThis.matchMedia)return!1;let e=globalThis.matchMedia(`(pointer: coarse)`).matches,t=globalThis.matchMedia(`(pointer: fine)`).matches;return e&&!t}function eY(e){let t=document.createElement(`div`);t.className=`dv-context-menu-rename`;let n=document.createElement(`input`);return n.className=`dv-context-menu-rename-input`,n.type=`text`,n.placeholder=`Name This Group`,n.value=e.label,n.addEventListener(`input`,()=>{e.setLabel(n.value)}),n.addEventListener(`keydown`,e=>{e.key!==`Escape`&&e.key!==`Enter`&&e.stopPropagation()}),n.addEventListener(`click`,e=>{e.stopPropagation()}),t.appendChild(n),$J()||requestAnimationFrame(()=>{n.focus(),n.select()}),t}function tY(e,t){let n=document.createElement(`div`);if(n.className=`dv-context-menu-color-picker`,!t.enabled)return n;for(let r of t.entries()){let t=document.createElement(`div`);t.className=`dv-context-menu-color-swatch`,t.style.setProperty(`--dv-tab-group-color`,r.value),r.label&&(t.title=r.label),e.color===r.id&&t.classList.add(`dv-context-menu-color-swatch--selected`),t.addEventListener(`click`,()=>{e.setColor(r.id)}),n.appendChild(t)}return n}var nY=class{constructor(e){this.accessor=e}buildMaximizeItem(e,t){let n=e.api.isMaximized();return ZJ(n?`Restore`:`Maximize`,t,n?()=>e.api.exitMaximized():()=>e.api.maximize(),!n&&e.api.location.type!==`grid`)}buildCollapseItem(e,t){return ZJ(e.collapsed?`Expand`:`Collapse`,t,()=>e.toggle())}_shouldInjectPin(){let e=this.accessor.options.pinnedTabs;return!!this.accessor.pinnedTabsService&&!!e?.enabled&&e.contextMenuItem!==!1}_resolveTabItems(e,t,n){var r;let i=(r=this.accessor.options).getTabContextMenuItems?.call(r,{panel:e,group:t,api:this.accessor.api,event:n})??[];return this._shouldInjectPin()?[`pin`,...i]:i}appendComponentItem(e,t,n,r,i,a){var o;let s=(o=this.accessor.options).createContextMenuItemComponent?.call(o,{id:YJ(),component:t.component});s&&(a.addDisposables(s),s.init($($({},n),{},{group:r,api:this.accessor.api,close:i,componentProps:t.componentProps})),e.appendChild(s.element))}buildBuiltInTabItem(e,t,n,r){switch(e){case`separator`:return QJ();case`close`:return ZJ(`Close`,r,()=>t.api.close());case`closeOthers`:return ZJ(`Close Others`,r,()=>{n.panels.filter(e=>e!==t).forEach(e=>e.api.close())});case`closeAll`:return ZJ(`Close All`,r,()=>{[...n.panels].forEach(e=>e.api.close())});case`closeLeft`:{let e=n.panels.indexOf(t);return ZJ(`Close to the Left`,r,()=>{n.panels.filter((t,n)=>n<e).forEach(e=>e.api.close())},e<=0)}case`closeRight`:{let e=n.panels.indexOf(t);return ZJ(`Close to the Right`,r,()=>{n.panels.filter((t,n)=>n>e).forEach(e=>e.api.close())},e===-1||e>=n.panels.length-1)}case`maximize`:return this.buildMaximizeItem(t,r);case`float`:return ZJ(`Float`,r,()=>this.accessor.api.addFloatingGroup(t),t.api.location.type===`floating`);case`popout`:return ZJ(`Open in New Window`,r,()=>{this.accessor.api.addPopoutGroup(t)},t.api.location.type===`popout`);case`pin`:return ZJ(t.api.isPinned?`Unpin tab`:`Pin tab`,r,()=>t.api.setPinned(!t.api.isPinned));default:return}}appendConfigItem(e,t,n,r,i,a){t.element?e.appendChild(t.element):t.component?this.appendComponentItem(e,t,n,r,i,a):t.label&&e.appendChild(ZJ(t.label,i,()=>t.action?.call(t),t.disabled))}show(e,t,n){let r=this._resolveTabItems(e,t,n);if(r.length===0)return;n.preventDefault();let i=this.accessor.getPopupServiceForGroup(t),a=()=>i.close(),o=new Y,s=document.createElement(`div`);s.className=`dv-context-menu`,s.setAttribute(`role`,`menu`);try{for(let n of r){if(XJ(n)){this.appendConfigItem(s,n,{panel:e},t,a,o);continue}let r=this.buildBuiltInTabItem(n,e,t,a);r&&s.appendChild(r)}}catch(e){throw o.dispose(),e}i.openPopover(s,{x:n.clientX,y:n.clientY,zIndex:qJ(n.target,t)},{onClose:()=>o.dispose()})}showForChip(e,t,n){if(!this.accessor.options.getTabGroupChipContextMenuItems)return;let r=this.accessor.options.getTabGroupChipContextMenuItems({tabGroup:e,group:t,api:this.accessor.api,event:n});if(r.length===0)return;n.preventDefault();let i=this.accessor.getPopupServiceForGroup(t),a=()=>i.close(),o=new Y,s=document.createElement(`div`);s.className=`dv-context-menu`,s.setAttribute(`role`,`menu`);try{for(let n of r)n===`separator`?s.appendChild(QJ()):n===`rename`?s.appendChild(eY(e)):n===`colorPicker`?s.appendChild(tY(e,this.accessor.tabGroupColorPalette)):n===`collapse`?s.appendChild(this.buildCollapseItem(e,a)):n===`close`?s.appendChild(ZJ(`Close All`,a,()=>{t.panels.filter(t=>e.containsPanel(t.id)).forEach(e=>e.api.close())})):XJ(n)&&this.appendConfigItem(s,n,{tabGroup:e},t,a,o)}catch(e){throw o.dispose(),e}i.openPopover(s,{x:n.clientX,y:n.clientY,zIndex:qJ(n.target,t)},{onClose:()=>o.dispose()})}},rY=[SJ,wJ,EJ,OJ,NJ,IJ,BJ,WJ,KJ,cJ({name:`ContextMenu`,serviceKey:`contextMenuService`,create:e=>new nY(e)})],iY=class{constructor(){this.cache=new WeakMap,this.currentFrameId=0,this.rafId=null}getPosition(e){let t=this.cache.get(e);if(t?.frameId===this.currentFrameId)return t.rect;this.scheduleFrameUpdate();let n=RW(e);return this.cache.set(e,{rect:n,frameId:this.currentFrameId}),n}invalidate(){this.currentFrameId++}scheduleFrameUpdate(){this.rafId||=requestAnimationFrame(()=>{this.currentFrameId++,this.rafId=null})}},aY=-1;function oY(e){let t=e.group.api;return t.location.type===`edge`&&t.isCollapsed()}function sY(){let e=document.createElement(`div`);return e.tabIndex=-1,e}function cY(e,t,n){let r=`${n}px`;e[t]!==r&&(e[t]=r)}var lY=class extends Y{constructor(e,t){super(),this.element=e,this.accessor=t,this.map={},this._disposed=!1,this._generation=0,this.positionCache=new iY,this.addDisposables(hW.from(()=>{for(let e of Object.values(this.map))e.disposable.dispose(),e.destroy.dispose(),this.cancelPendingUpdate(e);this._disposed=!0}))}updateAllPositions(){if(!this._disposed){this.positionCache.invalidate();for(let e of Object.values(this.map))e.panel.api.isVisible&&e.resize&&e.resize()}}repositionPanelOverlay(e,t=!1,n){var r;if(this._disposed)return;let i=this.map[e];i&&(i.forceVisible=t,i.clip=n,this.positionCache.invalidate(),(r=i.resize)==null||r.call(i))}cancelPendingUpdate(e){e.pendingUpdate!==void 0&&(cancelAnimationFrame(e.pendingUpdate),e.pendingUpdate=void 0)}detatch(e){if(this.map[e.api.id]){let t=this.map[e.api.id];return t.disposable.dispose(),t.destroy.dispose(),this.cancelPendingUpdate(t),delete this.map[e.api.id],!0}return!1}attach(e){var t;let{panel:n,referenceContainer:r}=e;if(!this.map[n.api.id]){let e=sY();e.className=`dv-render-overlay`,e.style.visibility=`hidden`,this.map[n.api.id]={panel:n,disposable:hW.NONE,destroy:hW.NONE,element:e,retainPreviousGeometry:!1,positioned:!1,generation:++this._generation}}let i=this.map[n.api.id];if(i.referenceContainer!==r){i.generation=++this._generation,this.cancelPendingUpdate(i),i.referenceContainer=r;let e=oY(n);i.retainPreviousGeometry=i.positioned&&!e,e&&!i.forceVisible&&(i.element.style.visibility=`hidden`,i.element.style.pointerEvents=`none`)}let a=i.generation,o=i.element,s=n.view.content.element,c=e=>{if(!e||e.width<=0||e.height<=0)return;let t=this.map[n.api.id];!t||t.forceVisible||t.positioned&&n.api.isVisible||(cY(o.style,`width`,e.width),cY(o.style,`height`,e.height))};c(r.dimensions),s.parentElement!==o&&o.appendChild(s),o.parentElement!==this.element&&this.element.appendChild(o);let l=()=>{let e=n.api.id,t=this.map[e];if(t?.generation!==a||t.pendingUpdate!==void 0)return;t.pendingUpdate=aY;let i=requestAnimationFrame(()=>{let t=this.map[e];if(t&&(t.pendingUpdate=void 0),this.isDisposed||t?.generation!==a)return;let i=t.forceVisible??!1,s=t.clip,c=oY(n),l=!i&&(!n.api.isVisible||c),u=this.positionCache.getPosition(r.element),d=this.positionCache.getPosition(this.element),f=u.left-d.left,p=u.top-d.top,m=u.width,h=u.height;if(m===0||h===0){if(c&&!i){t.retainPreviousGeometry=!1,o.style.visibility=`hidden`,o.style.pointerEvents=`none`,o.style.clipPath=``,o.style.zIndex=``;return}if(t.retainPreviousGeometry){l&&(o.style.visibility=`hidden`,o.style.pointerEvents=`none`);return}}if(t.retainPreviousGeometry=!1,t.positioned=!0,cY(o.style,`left`,f),cY(o.style,`top`,p),cY(o.style,`width`,m),cY(o.style,`height`,h),l?(o.style.visibility=`hidden`,o.style.pointerEvents=`none`):(o.style.visibility=``,o.style.pointerEvents=``),i?o.style.zIndex=`1000`:n.api.location.type!==`floating`&&(o.style.zIndex=``),s){let e=this.element.ownerDocument.defaultView,t=e?.scrollX??0,n=e?.scrollY??0,r=s.top+n,i=s.left+t,a=Math.max(0,r-u.top),c=Math.max(0,i-u.left),l=Math.max(0,u.left+m-(s.right+t)),d=Math.max(0,u.top+h-(s.bottom+n));o.style.clipPath=`inset(${a}px ${l}px ${d}px ${c}px)`}else o.style.clipPath=``;Q(o,`dv-render-overlay-float`,n.group.api.location.type===`floating`)});t.pendingUpdate===aY&&(t.pendingUpdate=i)},u=()=>{let e=!this.map[n.api.id]?.forceVisible&&oY(n);n.api.isVisible&&!e?(this.positionCache.invalidate(),l(),this.map[n.api.id]?.retainPreviousGeometry&&(o.style.visibility=``),o.style.pointerEvents=``):(o.style.visibility=`hidden`,o.style.pointerEvents=`none`)},d=new gW,f=()=>{n.api.location.type===`floating`?queueMicrotask(()=>{if(p.isDisposed)return;let e=this.accessor.getFloatingWindowForGroup(n.api.group);if(!e)return;let t=e.overlay.element,r=()=>{let e=Number(t.getAttribute(`aria-level`));o.style.zIndex=`calc(var(--dv-overlay-z-index, 999) + ${e*2+1})`},i=new MutationObserver(()=>{r()});d.value=hW.from(()=>i.disconnect()),i.observe(t,{attributeFilter:[`aria-level`],attributes:!0}),r()}):o.style.zIndex=``},p=new Y(d,new iK(o,{onDragEnd:e=>{r.dropTarget.dnd.onDragEnd(e)},onDragEnter:e=>{r.dropTarget.dnd.onDragEnter(e)},onDragLeave:e=>{r.dropTarget.dnd.onDragLeave(e)},onDrop:e=>{r.dropTarget.dnd.onDrop(e)},onDragOver:e=>{r.dropTarget.dnd.onDragOver(e)}}),n.api.onDidVisibilityChange(()=>{u()}),n.api.onDidDimensionsChange(()=>{n.api.isVisible&&l()}),(t=n.group.api).onDidCollapsedChange?.call(t,()=>{this.positionCache.invalidate(),l()})??hW.NONE,r.onDidDimensionsChange(e=>{c(e)}),n.api.onDidLocationChange(()=>{f()}));return this.map[n.api.id].destroy=hW.from(()=>{s.parentElement===o&&s.remove(),o.remove()}),f(),queueMicrotask(()=>{this.isDisposed||u()}),this.map[n.api.id].disposable.dispose(),this.map[n.api.id].disposable=p,this.map[n.api.id].resize=l,o}},uY=class extends Y{constructor(e){super(),this.accessor=e,this.init()}init(){let e=new Set,t=new Set;this.addDisposables(this.accessor.onDidAddPanel(t=>{if(e.has(t.api.id))throw Error(`dockview: Invalid event sequence. [onDidAddPanel] called for panel ${t.api.id} but panel already exists`);e.add(t.api.id)}),this.accessor.onDidRemovePanel(t=>{if(e.has(t.api.id))e.delete(t.api.id);else throw Error(`dockview: Invalid event sequence. [onDidRemovePanel] called for panel ${t.api.id} but panel does not exists`)}),this.accessor.onDidAddGroup(e=>{if(t.has(e.api.id))throw Error(`dockview: Invalid event sequence. [onDidAddGroup] called for group ${e.api.id} but group already exists`);t.add(e.api.id)}),this.accessor.onDidRemoveGroup(e=>{if(t.has(e.api.id))t.delete(e.api.id);else throw Error(`dockview: Invalid event sequence. [onDidRemoveGroup] called for group ${e.api.id} but group does not exists`)}))}};function dY(e){if(!e.matchMedia)return!1;let t=e.matchMedia(`(pointer: coarse)`).matches,n=e.matchMedia(`(pointer: fine)`).matches;return t&&!n}function fY(e){let t=e.window??window,n=e.capture??!1,r=e.escape??!0,i=e.keys??[],a=e.outsidePointerDown??!0,o=e.pointerDownGraceMs??0,s=e.now??Date.now,c=s(),l=new Y,u=t=>e.isInside?e.isInside(t):PW(t,e.elements?.call(e)??[]);if((r||i.length>0)&&l.addDisposables(Z(t,`keydown`,t=>{(r&&t.key===`Escape`||i.includes(t.key))&&e.onDismiss()},n)),(a||e.onInsidePointerDown)&&l.addDisposables(Z(t,`pointerdown`,t=>{if(u(t)){var n;(n=e.onInsidePointerDown)==null||n.call(e,t)}else!a||s()-c<o||e.onDismiss()},n)),e.resize&&l.addDisposables(Z(t,`resize`,()=>{dY(t)||e.onDismiss()})),e.focusOut){let r=()=>e.anchor?.call(e)??e.elements?.call(e)[0],i=new WeakSet,a=t=>{if(i.has(t))return;i.add(t);let n=t.target;n instanceof Element&&((e.isFocusInside?e.isFocusInside(IW(n,r())):PW(t,e.elements?.call(e)??[]))||e.onDismiss())},o=new Map,s=()=>{let t=new Set,r=e.anchor?.call(e),i=[...e.elements?.call(e)??[],...r?[r]:[]];for(let e of i)for(let n of FW(e))t.add(n);for(let[e,n]of o)t.has(e)||(n.dispose(),o.delete(e));for(let e of t)o.has(e)||o.set(e,Z(e,`focusin`,a,n))};l.addDisposables(Z(t,`focusin`,e=>{s(),a(e)},n),{dispose:()=>{for(let[,e]of o)e.dispose();o.clear()}}),s()}return l}var pY=class extends Y{constructor(e,t=globalThis.window){super(),this._active=null,this._activeDisposable=new gW,this._root=e,this._window=t,this._element=t.document.createElement(`div`),this._element.className=`dv-popover-anchor`,this._element.style.position=`relative`,this._root.prepend(this._element),this.addDisposables(hW.from(()=>{this.close()}),this._activeDisposable)}updateRoot(e){e.prepend(this._element),this._root=e}openPopover(e,t,n){this.close();let r=this._window.document.createElement(`div`);r.style.position=`absolute`,r.style.zIndex=t.zIndex??`var(--dv-overlay-z-index)`,r.appendChild(e);let i=this._element.getBoundingClientRect(),a=i.left,o=i.top;r.style.top=`${t.y-o}px`,r.style.left=`${t.x-a}px`,this._element.appendChild(r),this._active=r,this._activeDisposable.value=new Y(fY({window:this._window,onDismiss:()=>this.close(),elements:()=>this._active?[this._active]:[],keys:[`Enter`],pointerDownGraceMs:200,resize:!0}),n?.onClose?hW.from(n.onClose):hW.NONE),this._window.requestAnimationFrame(()=>{QW(r,this._root)})}close(){this._active&&=(this._active.remove(),this._activeDisposable.dispose(),null)}},mY=class extends Y{get renderedOutline(){return this._model?this._outline:void 0}get disabled(){return this._disabled}set disabled(e){this.disabled!==e&&(this._disabled=e,e&&this._clearNow())}_cancelPendingClear(){this._pendingClear!==void 0&&(clearTimeout(this._pendingClear),this._pendingClear=void 0)}_clearNow(){this._cancelPendingClear(),this._model&&this._model.root.remove(),this._model=void 0}get model(){if(!this.disabled)return{clear:()=>{this._clearNow()},scheduleClear:()=>{this._pendingClear===void 0&&this._model&&(this._pendingClear=setTimeout(()=>{this._pendingClear=void 0,this._clearNow()},0))},exists:()=>!!this._model,getElements:(e,t)=>{this._cancelPendingClear();let n=this._outline!==t;if(this._outline=t,this._model)return this._model.changed=n,this._model;let r=this.createContainer(),i=this.createAnchor();if(this._model={root:r,overlay:i,changed:n},r.appendChild(i),this.element.appendChild(r),e?.target instanceof HTMLElement){let t=e.target.getBoundingClientRect(),n=this.element.getBoundingClientRect();i.style.left=`${t.left-n.left}px`,i.style.top=`${t.top-n.top}px`}return this._model}}}constructor(e,t){super(),this.element=e,this._disabled=!1,this._disabled=t.disabled,this.addDisposables(hW.from(()=>{var e;(e=this.model)==null||e.clear()}))}createContainer(){let e=document.createElement(`div`);return e.className=`dv-drop-target-container`,e}createAnchor(){let e=document.createElement(`div`);return e.className=`dv-drop-target-anchor`,e.style.visibility=`hidden`,e}},hY=[`left`,`right`,`top`,`bottom`];function gY(e){return e===`left`||e===`right`}var _Y={marginShare:0,size:1/0},vY=class{get _effectiveBaseCollapsed(){return this._measuredTabSize??this._baseCollapsedSize}get minimumSize(){return this._isCollapsed?this.collapsedSize:this._baseMinimumSize===void 0?this._effectiveBaseCollapsed+50+this._axis.marginShare:this._baseMinimumSize+this._axis.marginShare}get maximumSize(){return this._isCollapsed?this.collapsedSize:this._expandedMaximumSize}get element(){return this._group.element}get isCollapsed(){return this._isCollapsed}get lastExpandedSize(){return this._lastExpandedSize}get lastExpandedContentSize(){return this._lastExpandedSize-this._axis.marginShare}get collapsedSize(){return this._effectiveBaseCollapsed+this._axis.marginShare}get configuredMinimumSize(){return this._baseMinimumSize}get configuredMaximumSize(){return this._expandedMaximumSize}get configuredCollapsedSize(){return this._baseCollapsedSize}constructor(e,t,n,r=_Y){this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this.snap=!1,this.priority=`low`,this._isCollapsed=!1,this._isVisible=!0,this._tabSizeDisposables=new Y,this._group=t,this._orientation=n,t.element.classList.add(`dv-edge-group`),t.element.dataset.testid=`dv-edge-group-${e.id}`,this._baseCollapsedSize=e.collapsedSize??35,this._baseMinimumSize=e.minimumSize,this._axis=r,this._expandedMaximumSize=e.maximumSize??1/0,this._lastExpandedSize=e.initialSize??200,e.collapsed&&(this._isCollapsed=!0,t.element.classList.add(`dv-edge-collapsed`)),this._observeTabStrip()}_observeTabStrip(){let e=this._group.element.querySelector(`.dv-tabs-and-actions-container`);e&&this._tabSizeDisposables.addDisposables(TW(e,()=>{let{headerPosition:t}=this._group;(t===`left`||t===`right`)==(this._orientation===`horizontal`)&&this._applyMeasuredTabSize(this._orientation===`vertical`?e.offsetHeight:e.offsetWidth)}))}_applyMeasuredTabSize(e){e<=0||e===this._measuredTabSize||(this._measuredTabSize=e,this._isCollapsed&&this._onDidChange.fire({size:this.collapsedSize}))}layout(e,t){!this._isCollapsed&&this._isVisible&&this._axis.size>0&&(this._lastExpandedSize=e+this._axis.marginShare),this._orientation===`horizontal`?this._group.layout(e,t):this._group.layout(t,e)}setCollapsed(e){this._isCollapsed!==e&&(this._isCollapsed=e,this._group.element.classList.toggle(`dv-edge-collapsed`,e))}setVisible(e){this._isVisible=e}restoreExpandedSize(e){this._lastExpandedSize=e}updateSizing(e,t){this._baseCollapsedSize=e,this._baseMinimumSize=t}dispose(){this._tabSizeDisposables.dispose(),this._onDidChange.dispose()}},yY=class{get element(){return this._dockviewElement}constructor(e,t){this._dockviewElement=e,this._layoutDockview=t,this.priority=`high`,this.minimumSize=100,this.maximumSize=1/0,this._onDidChange=new X,this.onDidChange=this._onDidChange.event}layout(e,t){this._layoutDockview(t,e)}setVisible(e){}dispose(){this._onDidChange.dispose()}},bY=class{get element(){return this._element}constructor(e,t=0){this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this.minimumSize=100,this.maximumSize=1/0,this.priority=`high`,this._element=document.createElement(`div`),this._element.className=`dv-shell-middle-column`,this._element.style.height=`100%`,this._element.style.width=`100%`,this._splitview=new SG(this._element,{orientation:`VERTICAL`,proportionalLayout:!1,margin:t}),this._centerIndex=0,this._splitview.addView(e,{type:`distribute`},0)}addTopView(e,t){this._splitview.addView(e,t,0),this._topIndex=0,this._centerIndex+=1,this._bottomIndex!==void 0&&(this._bottomIndex+=1)}addBottomView(e,t){let n=this._splitview.length;this._splitview.addView(e,t,n),this._bottomIndex=n}removeView(e){let t=e===`top`?this._topIndex:this._bottomIndex;t!==void 0&&(this._splitview.removeView(t),e===`top`?(this._topIndex=void 0,--this._centerIndex,this._bottomIndex!==void 0&&--this._bottomIndex):this._bottomIndex=void 0)}layout(e,t){this._splitview.layout(t,e)}setVisible(e){}setViewVisible(e,t){let n=e===`top`?this._topIndex:this._bottomIndex;n!==void 0&&this._splitview.setViewVisible(n,t)}isViewVisible(e){let t=e===`top`?this._topIndex:this._bottomIndex;return t!==void 0&&this._splitview.isViewVisible(t)}getViewSize(e){let t=e===`top`?this._topIndex:this._bottomIndex;return t===void 0?0:this._splitview.getViewSize(t)}getViewCachedVisibleSize(e){let t=e===`top`?this._topIndex:this._bottomIndex;if(t!==void 0)return this._splitview.getViewCachedVisibleSize(t)}resizeView(e,t){let n=e===`top`?this._topIndex:this._bottomIndex;n!==void 0&&this._splitview.resizeView(n,t)}get axis(){return this._splitview}updateMargin(e){this._splitview.margin=e}get disabled(){return this._splitview.disabled}set disabled(e){this._splitview.disabled=e}dispose(){this._onDidChange.dispose(),this._splitview.dispose()}},xY=class{constructor(e,t,n,r=0,i=35){this._disposables=new Y,this._viewConfigs=new Map,this._pendingSizes=new Map,this._currentWidth=0,this._currentHeight=0,this._gap=r,this._defaultCollapsedSize=i,this._shellElement=document.createElement(`div`),this._shellElement.className=`dv-shell`,this._shellElement.style.height=`100%`,this._shellElement.style.width=`100%`,this._shellElement.style.position=`relative`,e.appendChild(this._shellElement);let a=new yY(t,n);this._middleColumn=new bY(a,r),this._outerSplitview=new SG(this._shellElement,{orientation:`HORIZONTAL`,proportionalLayout:!1,margin:r}),this._middleIndex=0,this._outerSplitview.addView(this._middleColumn,{type:`distribute`},0),this._disposables.addDisposables(TW(this._shellElement,e=>{if(!this._shellElement.offsetParent||!zW(this._shellElement))return;let t=Math.round(e.contentRect.width),n=Math.round(e.contentRect.height);(t!==this._currentWidth||n!==this._currentHeight)&&this.layout(t,n)}),this._outerSplitview,this._middleColumn,a)}get element(){return this._shellElement}get locked(){return this._outerSplitview.disabled}set locked(e){this._outerSplitview.disabled=e,this._middleColumn.disabled=e}addEdgeView(e,t,n){if(this.hasEdgeGroup(e))throw Error(`dockview: edge group already registered at position '${e}'`);this._viewConfigs.set(e,t);let r=new vY($($({},t),{},{collapsedSize:t.collapsedSize??this._defaultCollapsedSize}),n,gY(e)?`horizontal`:`vertical`,this._axisFor(e)),i=r.isCollapsed?r.collapsedSize:r.lastExpandedSize;switch(e){case`left`:this._outerSplitview.addView(r,i,0),this._leftIndex=0,this._middleIndex+=1,this._rightIndex!==void 0&&(this._rightIndex+=1),this._leftView=r;break;case`right`:{let e=this._outerSplitview.length;this._outerSplitview.addView(r,i,e),this._rightIndex=e,this._rightView=r}break;case`top`:this._middleColumn.addTopView(r,i),this._topView=r;break;case`bottom`:this._middleColumn.addBottomView(r,i),this._bottomView=r}return this._disposables.addDisposables(r),!r.isCollapsed&&!this._canResize(e)&&this._pendingSizes.set(e,i),this._relayout(),r}layoutFromElement(){if(!this._shellElement.offsetParent||!zW(this._shellElement))return;let e=Math.round(this._shellElement.clientWidth),t=Math.round(this._shellElement.clientHeight);e!==0&&t!==0&&this.layout(e,t)}layout(e,t){this._currentWidth=e,this._currentHeight=t,this._outerSplitview.layout(e,t),this._flushPendingSizes()}updateTheme(e,t){this._gap=e,this._defaultCollapsedSize=t,this._outerSplitview.margin=e,this._middleColumn.updateMargin(e),this._applyThemeSizing(),this._relayout()}_hasSiblingOn(e){return gY(e)?this._leftView!==void 0&&this._rightView!==void 0:this._topView!==void 0&&this._bottomView!==void 0}_axisFor(e){return gY(e)?this._outerSplitview:this._middleColumn.axis}_applyThemeSizing(){for(let e of hY){let t=this._getView(e),n=this._viewConfigs.get(e);t&&n&&t.updateSizing(n.collapsedSize??this._defaultCollapsedSize,n.minimumSize)}}_relayout(){this._currentWidth>0&&this._currentHeight>0&&this.layout(this._currentWidth,this._currentHeight)}_slotSize(e){switch(e){case`left`:return this._leftIndex===void 0?0:this._outerSplitview.getViewSize(this._leftIndex);case`right`:return this._rightIndex===void 0?0:this._outerSplitview.getViewSize(this._rightIndex);case`top`:case`bottom`:return this._middleColumn.getViewSize(e)}}removeEdgeView(e){let t=this._getView(e);if(t){switch(e){case`left`:this._outerSplitview.removeView(this._leftIndex),this._leftIndex=void 0,this._leftView=void 0,--this._middleIndex,this._rightIndex!==void 0&&--this._rightIndex;break;case`right`:this._outerSplitview.removeView(this._rightIndex),this._rightIndex=void 0,this._rightView=void 0;break;case`top`:this._middleColumn.removeView(`top`),this._topView=void 0;break;case`bottom`:this._middleColumn.removeView(`bottom`),this._bottomView=void 0}this._disposables.removeDisposable(t),t.dispose(),this._viewConfigs.delete(e),this._pendingSizes.delete(e),this._relayout()}}hasEdgeGroup(e){switch(e){case`top`:return this._topView!==void 0;case`bottom`:return this._bottomView!==void 0;case`left`:return this._leftView!==void 0;case`right`:return this._rightView!==void 0}}setEdgeGroupVisible(e,t){let n=this._getView(e)!==void 0&&t!==this.isEdgeGroupVisible(e);switch(e){case`left`:this._leftIndex!==void 0&&this._outerSplitview.setViewVisible(this._leftIndex,t);break;case`right`:this._rightIndex!==void 0&&this._outerSplitview.setViewVisible(this._rightIndex,t);break;case`top`:case`bottom`:this._middleColumn.setViewVisible(e,t)}n&&this._gap>0&&this._hasSiblingOn(e)&&this._relayout(),t&&this._flushPendingSizes()}isEdgeGroupVisible(e){switch(e){case`left`:return this._leftIndex!==void 0&&this._outerSplitview.isViewVisible(this._leftIndex);case`right`:return this._rightIndex!==void 0&&this._outerSplitview.isViewVisible(this._rightIndex);case`top`:case`bottom`:return this._middleColumn.isViewVisible(e)}}setEdgeGroupCollapsed(e,t){let n=this._getView(e);n&&(n.setCollapsed(t),t?(this._pendingSizes.delete(e),this._resizeView(e,n.collapsedSize)):this.resizeEdgeGroup(e,n.lastExpandedSize))}resizeEdgeGroup(e,t){let n=this._getView(e);if(!n||!Number.isFinite(t))return;let r=Math.round(t);r<=0||(n.restoreExpandedSize(r),n.isCollapsed?this._pendingSizes.delete(e):this._canResize(e)?(this._pendingSizes.delete(e),this._resizeView(e,r)):this._pendingSizes.set(e,r))}_canResize(e){return this.isEdgeGroupVisible(e)&&this._axisFor(e).size>0}_resizeView(e,t){switch(e){case`left`:this._leftIndex!==void 0&&this._outerSplitview.resizeView(this._leftIndex,t);break;case`right`:this._rightIndex!==void 0&&this._outerSplitview.resizeView(this._rightIndex,t);break;case`top`:case`bottom`:this._middleColumn.resizeView(e,t)}}_flushPendingSizes(){if(this._pendingSizes.size!==0)for(let[e,t]of this._pendingSizes){let n=this._getView(e);n&&!n.isCollapsed&&this._canResize(e)&&(this._pendingSizes.delete(e),this._resizeView(e,t))}}isEdgeGroupCollapsed(e){return this._getView(e)?.isCollapsed??!1}getEdgeGroupExpandedSize(e){return this._getView(e)?.lastExpandedContentSize??0}_getView(e){switch(e){case`top`:return this._topView;case`bottom`:return this._bottomView;case`left`:return this._leftView;case`right`:return this._rightView}}toJSON(){let e={};for(let t of hY){let n=this._getView(t);if(!n)continue;let r=this.isEdgeGroupVisible(t);e[t]={size:this._expandedSize(n,t,r),visible:r,collapsed:n.isCollapsed||void 0,minimumSize:n.configuredMinimumSize,maximumSize:Number.isFinite(n.configuredMaximumSize)?n.configuredMaximumSize:void 0,collapsedSize:n.configuredCollapsedSize}}return e}_expandedSize(e,t,n){if(e.isCollapsed)return e.lastExpandedSize;let r=this._pendingSizes.get(t);return r===void 0?n?this._slotSize(t):this._cachedVisibleSize(t)??e.lastExpandedSize:r}_cachedVisibleSize(e){switch(e){case`left`:return this._leftIndex===void 0?void 0:this._outerSplitview.getViewCachedVisibleSize(this._leftIndex);case`right`:return this._rightIndex===void 0?void 0:this._outerSplitview.getViewCachedVisibleSize(this._rightIndex);case`top`:case`bottom`:return this._middleColumn.getViewCachedVisibleSize(e)}}fromJSON(e){for(let t of hY){let n=e[t],r=this._getView(t);n&&r&&(r.restoreExpandedSize(n.size),r.setCollapsed(n.collapsed??!1),n.collapsed?(this._pendingSizes.delete(t),this._resizeView(t,r.collapsedSize)):this.resizeEdgeGroup(t,n.size),this.setEdgeGroupVisible(t,!!n.visible))}}dispose(){this._disposables.dispose(),this._shellElement.remove()}};function SY(e){e.error?console.error(`dockview: failed to create popout.`,e.error):e.reason===`blocked`?console.error(`dockview: failed to create popout. perhaps you need to allow pop-ups for this website`):console.error(`dockview: failed to create popout (${e.reason}).`)}function CY(e){return new bq(e.tabGroupColors??yq,e.tabGroupAccent!==`off`)}function wY(e){let t=e.from.activePanel;[...e.from.panels].map(t=>{let n=e.from.model.removePanel(t);return e.from.model.renderContainer.detatch(t),n}).forEach(n=>{e.to.model.openPanel(n,{skipSetActive:t!==n,skipSetGroupActive:!0})})}var TY=()=>({dispose:()=>{}}),EY=TY,DY=100,OY=class extends WG{fireDidCreateTabGroup(e){this._onDidCreateTabGroup.fire(e)}fireDidDestroyTabGroup(e){this._onDidDestroyTabGroup.fire(e)}fireDidAddPanelToTabGroup(e){this._onDidAddPanelToTabGroup.fire(e)}fireDidRemovePanelFromTabGroup(e){this._onDidRemovePanelFromTabGroup.fire(e)}fireDidTabGroupChange(e){this._onDidTabGroupChange.fire(e)}fireDidTabGroupCollapsedChange(e){this._onDidTabGroupCollapsedChange.fire(e)}get orientation(){return this.gridview.orientation}get totalPanels(){return this.panels.length}get panels(){return this.groups.flatMap(e=>e.panels)}get dndCapabilities(){return tq(this.options)}get options(){return this._options}get tabGroupColorPalette(){return this._tabGroupColorPalette}get activePanel(){let e=this.activeGroup;if(e)return e.activePanel}get renderer(){return this.options.defaultRenderer??`onlyWhenVisible`}get defaultHeaderPosition(){return this.options.defaultHeaderPosition??`top`}get api(){return this._api}get floatingGroups(){var e;return((e=this._moduleRegistry)==null||(e=e.services.floatingGroupService)==null?void 0:e.floatingGroups)??[]}getFloatingWindowForGroup(e){return this._floatingGroupService?.findByGroup(e)}_gatherFloatingGroupBoxes(e){return this.getFloatingGroupSnapshots(e).map(e=>e.box)}getFloatingContainer(){return this._floatingOverlayHost??this.gridview.element}getFloatingGroupSnapshots(e){let t=this.getFloatingContainer().getBoundingClientRect();return this.floatingGroups.filter(t=>t.group!==e).map(e=>{let n=e.overlay.element.getBoundingClientRect();return{group:e.group,box:{left:n.left-t.left,top:n.top-t.top,width:n.width,height:n.height}}})}mergeFloatInto(e,t,n){e!==t&&this.getPanel(t.id)&&this.moveGroupOrPanel({from:{groupId:e.id},to:{group:t,position:n}})}getGridSplitterRects(){let e=this.getFloatingContainer().getBoundingClientRect(),t=[];return this.gridview.element.querySelectorAll(`.dv-sash`).forEach(n=>{let r=n.getBoundingClientRect();t.push({left:r.left-e.left,top:r.top-e.top,width:r.width,height:r.height})}),t}get _smartGuidesService(){return this._moduleRegistry.services.smartGuidesService}get smartGuidesEnabled(){return this._smartGuidesService?.enabled??!1}setSmartGuidesEnabled(e){var t;(t=pJ(this._smartGuidesService,`SmartGuides`,`api.setSmartGuidesEnabled`))==null||t.setEnabled(e)}updateSmartGuidesOptions(e){var t;(t=pJ(this._smartGuidesService,`SmartGuides`,`api.updateSmartGuidesOptions`))==null||t.updateOptions(e)}get onDidSnapFloat(){return this._smartGuidesService?.onDidSnapFloat??TY}get onDidSnapTogether(){return this._smartGuidesService?.onDidSnapTogether??TY}_buildFloatingDragTransform(e,t){let n=this.options.transformFloatingGroupDrag,r=!t;if(n||r&&this._smartGuidesService)return t=>{let i=n?.({group:e,proposed:t.proposed,container:t.container,others:t.others,modifiers:t.modifiers}),a=i?$($({},t.proposed),i):t.proposed;return(r?this._smartGuidesService?.transformFloatingGroupDrag({group:e,proposed:a,container:t.container,others:t.others,modifiers:t.modifiers}):void 0)??i??void 0}}get _floatingGroupService(){return this._moduleRegistry.services.floatingGroupService}get _popoutWindowService(){return this._moduleRegistry.services.popoutWindowService}get _watermarkService(){return this._moduleRegistry.services.watermarkService}get _edgeGroupService(){return this._moduleRegistry.services.edgeGroupService}get _rootDropTargetService(){return this._moduleRegistry.services.rootDropTargetService}get _advancedDnDService(){return this._moduleRegistry.services.advancedDnDService}get _dndCompassService(){return this._moduleRegistry.services.dndCompassService}canDropOnGroup(e,t,n){return e.model.canDisplayContentOverlay(n,t)}getDropOverlayElement(e){let t=e.element.querySelector(`.dv-content-container`);if(t)return this.options.theme?.dndPanelOverlay===`group`?t.parentElement??t:t}getTabsListElement(e){return e.model.header.hidden?void 0:e.model.tabsListElement}relayoutGroup(e){e.relayout()}setForcedOverflow(e,t){e.model.header.setForcedOverflow(t)}getLayoutElement(){return this.gridview.element}getDropPositionResolver(){if(this.options.dropPositionResolver)return this.options.dropPositionResolver;let e=this._dndCompassService?.resolver,t=this._moduleRegistry.services.autoEdgeGroupService;return e&&t?{resolve:n=>t.resolveEdge(n)??e.resolve(n)}:e??t?.resolver}dockToLayoutEdge(e,t){let n=new Hq({nativeEvent:e,position:t,panel:void 0,api:this._api,group:void 0,getData:pW,kind:`edge`});if(this._onWillDrop.fire(n),n.defaultPrevented)return;let r=pW();r?this.moveGroupOrPanel({from:{groupId:r.groupId,panelId:r.panelId??void 0},to:{group:this.orthogonalize(t),position:`center`}}):this._onDidDrop.fire(new Vq({nativeEvent:e,position:t,panel:void 0,api:this._api,group:void 0,getData:pW}))}get headerActionsService(){return this._moduleRegistry.services.headerActionsService}get _layoutHistoryService(){return this._moduleRegistry.services.layoutHistoryService}undo(){var e;(e=pJ(this._layoutHistoryService,`LayoutHistory`,`api.undo`))==null||e.undo()}redo(){var e;(e=pJ(this._layoutHistoryService,`LayoutHistory`,`api.redo`))==null||e.redo()}get canUndo(){return this._layoutHistoryService?.canUndo??!1}get canRedo(){return this._layoutHistoryService?.canRedo??!1}clearHistory(){var e;(e=this._layoutHistoryService)==null||e.clear()}get onDidChangeHistory(){return this._layoutHistoryService?.onDidChangeHistory??EY}get hasEdgeDragReveal(){return!!this._moduleRegistry.services.autoEdgeGroupService}isGridEmpty(){return this.gridview.length===0}rootDropTargetOverrideTarget(){return this.rootDropTargetContainer?.model}dispatchUnhandledDragOver(e,t){let n=new pq(e,`edge`,t,pW);return this._onUnhandledDragOver.fire(n),n.isAccepted}fireWillDragPanel(e){this._onWillDragPanel.fire(e)}fireWillDragGroup(e){this._onWillDragGroup.fire(e)}fireWillDrop(e){this._onWillDrop.fire(e)}fireWillShowOverlay(e){this._onWillShowOverlay.fire(e)}buildGroupDragGhost(e){return this._advancedDnDService?.buildGroupDragGhost(e)}resolveDropOverlayModel(e,t){return this._advancedDnDService?.resolveOverlayModel(e,t)}get rootElement(){return this._shellManager?.element??this.element}ownsElement(e){if(this.rootElement.contains(e))return!0;let t=this.rootElement.ownerDocument,n=e.ownerDocument;return!n||n===t?!1:this.getPopoutWindows().some(e=>e.document===n)}adjacentGroup(e,t){let n=this.getGridviewForGroup(e);if(!n.element.contains(e.element))return;let r=MG(e.element),i=(t?n.previous(r):n.next(r)).view;if(n===this.gridview||i!==e)return i}adjacentGroupInDirection(e,t){if(e.api.location.type!==`grid`)return;let n=e.element.getBoundingClientRect(),r=n.left+n.width/2,i=n.top+n.height/2,a,o=1/0;for(let n of this.groups){if(n===e||n.api.location.type!==`grid`)continue;let s=n.element.getBoundingClientRect(),c=s.left+s.width/2-r,l=s.top+s.height/2-i,u;switch(t){case`left`:u=c<0&&Math.abs(c)>=Math.abs(l);break;case`right`:u=c>0&&Math.abs(c)>=Math.abs(l);break;case`up`:u=l<0&&Math.abs(l)>=Math.abs(c);break;default:u=l>0&&Math.abs(l)>=Math.abs(c)}if(!u)continue;let d=c*c+l*l;d<o&&(o=d,a=n)}return a}showDropPreview(e,t){return this._advancedDnDService?.showPreviewOverlay(e,t)??hW.NONE}announce(e){var t;(t=this._moduleRegistry.services.liveRegionService)==null||t.announce(e)}dockPanel(e,t,n){this.moveGroupOrPanel({from:{groupId:e.group.id,panelId:e.id},to:{group:t,position:n}})}floatPanel(e){this.addFloatingGroup(e)}get contextMenuService(){return this._moduleRegistry.services.contextMenuService}get pinnedTabsService(){return this._moduleRegistry.services.pinnedTabsService}get advancedOverflowService(){return this._moduleRegistry.services.advancedOverflowService}setPanelPinned(e,t){e.isPinned!==t&&this.options.pinnedTabs?.enabled&&this.pinnedTabsService&&(e.setPinned(t),this._onDidPanelPinnedChange.fire({panel:e,isPinned:t}))}get mountElement(){return this.gridview.element}hasVisibleGridGroup(){return this.groups.some(e=>e.api.location.type===`grid`&&e.api.isVisible)}isLastGridGroup(e){return e.api.location.type===`grid`&&!this.groups.some(t=>t!==e&&t.api.location.type===`grid`)}fireLayoutChange(e){this._bufferOnDidLayoutChange.fire(e)}get popoutRestorationPromise(){return this._popoutWindowService?.restorationPromise??Promise.resolve()}constructor(e,t){super(e,{proportionalLayout:t.proportionalLayout??!0,orientation:`HORIZONTAL`,styles:t.hideBorders?{separatorBorder:`transparent`}:void 0,disableAutoResizing:t.disableAutoResizing,locked:t.locked,margin:t.theme?.gap??0,className:t.className}),this.nextGroupId=gG(),this._deserializer=new nJ(this),this._moduleRegistry=new mJ,this._onWillDragPanel=new X,this.onWillDragPanel=this._onWillDragPanel.event,this._onWillDragGroup=new X,this.onWillDragGroup=this._onWillDragGroup.event,this._onDidDrop=new X,this.onDidDrop=this._onDidDrop.event,this._onWillDrop=new X,this.onWillDrop=this._onWillDrop.event,this._mutationDepth=0,this._syncMutationDepth=0,this._pendingLocationChanges=new Map,this._openingPopoutWindows=new Set,this._origin=`user`,this._originDepth=0,this._onWillMutateLayout=new X,this.onWillMutateLayout=this._onWillMutateLayout.event,this._onDidMutateLayout=new X,this.onDidMutateLayout=this._onDidMutateLayout.event,this._onWillShowOverlay=new X,this.onWillShowOverlay=this._onWillShowOverlay.event,this._onUnhandledDragOver=new X,this.onUnhandledDragOver=this._onUnhandledDragOver.event,this._onDidRemovePanel=new X,this.onDidRemovePanel=this._onDidRemovePanel.event,this._onDidAddPanel=new X,this.onDidAddPanel=this._onDidAddPanel.event,this._onDidPopoutGroupSizeChange=new X,this.onDidPopoutGroupSizeChange=this._onDidPopoutGroupSizeChange.event,this._onDidPopoutGroupPositionChange=new X,this.onDidPopoutGroupPositionChange=this._onDidPopoutGroupPositionChange.event,this._onDidAddPopoutGroup=new X,this.onDidAddPopoutGroup=this._onDidAddPopoutGroup.event,this._onDidRemovePopoutGroup=new X,this.onDidRemovePopoutGroup=this._onDidRemovePopoutGroup.event,this._onDidChangePopouts=new X,this.onDidChangePopouts=this._onDidChangePopouts.event,this._onDidOpenPopoutWindowFail=new X,this.onDidOpenPopoutWindowFail=this._onDidOpenPopoutWindowFail.event,this._onWillClosePopoutWindow=new X,this.onWillClosePopoutWindow=this._onWillClosePopoutWindow.event,this._onDidStartFloatingGroupDrag=new X,this.onDidStartFloatingGroupDrag=this._onDidStartFloatingGroupDrag.event,this._onDidEndFloatingGroupDrag=new X,this.onDidEndFloatingGroupDrag=this._onDidEndFloatingGroupDrag.event,this._onDidLayoutFromJSON=new X,this.onDidLayoutFromJSON=this._onDidLayoutFromJSON.event,this._onDidActivePanelChange=new X({replay:!0}),this.onDidActivePanelChange=this._onDidActivePanelChange.event,this._onDidPanelPinnedChange=new X,this.onDidPanelPinnedChange=this._onDidPanelPinnedChange.event,this._onDidMovePanel=new X,this.onDidMovePanel=this._onDidMovePanel.event,this._onDidCreateTabGroup=new X,this.onDidCreateTabGroup=this._onDidCreateTabGroup.event,this._onDidDestroyTabGroup=new X,this.onDidDestroyTabGroup=this._onDidDestroyTabGroup.event,this._onDidAddPanelToTabGroup=new X,this.onDidAddPanelToTabGroup=this._onDidAddPanelToTabGroup.event,this._onDidRemovePanelFromTabGroup=new X,this.onDidRemovePanelFromTabGroup=this._onDidRemovePanelFromTabGroup.event,this._onDidTabGroupChange=new X,this.onDidTabGroupChange=this._onDidTabGroupChange.event,this._onDidTabGroupCollapsedChange=new X,this.onDidTabGroupCollapsedChange=this._onDidTabGroupCollapsedChange.event,this._onDidMaximizedGroupChange=new X,this.onDidMaximizedGroupChange=this._onDidMaximizedGroupChange.event,this._inShellLayout=!1,this._onDidRemoveGroup=new X,this.onDidRemoveGroup=this._onDidRemoveGroup.event,this._onDidEdgeGroupAutoHideChange=new X,this.onDidEdgeGroupAutoHideChange=this._onDidEdgeGroupAutoHideChange.event,this._onDidAddGroup=new X,this.onDidAddGroup=this._onDidAddGroup.event,this._onDidOptionsChange=new X,this.onDidOptionsChange=this._onDidOptionsChange.event,this._onDidActiveGroupChange=new X,this.onDidActiveGroupChange=this._onDidActiveGroupChange.event,this._peekingGroups=new Set,this._moving=!1,this._options=t,this._tabGroupColorPalette=CY(t);let n=t.modules??[...rY,...gJ()];for(let e of n)this._moduleRegistry.register(e);this._moduleRegistry.initialize(this),this.reportMissingOptionModules(t);let r=this._popoutWindowService;r&&this.addDisposables(r.onDidRemove(e=>{this._onDidRemovePopoutGroup.fire({id:e.popoutGroup.id,group:e.popoutGroup,window:e.getWindow()})})),this.popupService=new pY(this.element),this.addDisposables(this.popupService,hW.from(()=>{for(let e of this._openingPopoutWindows)e.dispose();this._openingPopoutWindows.clear()})),this._api=new rK(this),this.disableResizing=!0,this.element.remove(),this._shellManager=new xY(e,this.element,(e,t)=>this._layoutFromShell(e,t),t.theme?.gap??0,t.theme?.edgeGroupCollapsedSize),this._shellManager.locked=!!t.locked,this.popupService.updateRoot(this._shellManager.element),this._shellThemeClassnames=new qW(this._shellManager.element),this.rootDropTargetContainer=new mY(this._shellManager.element,{disabled:!0}),this.floatingDropTargetContainer=new mY(this._shellManager.element,{disabled:!1}),this.overlayRenderContainer=new lY(this._shellManager.element,this),this._floatingOverlayHost=document.createElement(`div`),this._floatingOverlayHost.className=`dv-floating-overlay-host`,this._shellManager.element.appendChild(this._floatingOverlayHost),Q(this.gridview.element,`dv-dockview`,!0),Q(this.element,`dv-debug`,!!t.debug),this.updateTheme(),t.debug&&this.addDisposables(new uY(this)),this.addDisposables(hW.from(()=>this._pendingLocationChanges.clear()),this.rootDropTargetContainer,this.floatingDropTargetContainer,Z(this._shellManager.element,`dragend`,()=>{var e,t;(e=this.rootDropTargetContainer.model)==null||e.clear(),(t=this.floatingDropTargetContainer.model)==null||t.clear()},!0),this.overlayRenderContainer,this._onWillDragPanel,this._onWillDragGroup,this._onWillShowOverlay,this._onDidActivePanelChange,this._onDidPanelPinnedChange,this._onDidAddPanel,this._onDidRemovePanel,this._onDidLayoutFromJSON,this._onDidDrop,this._onWillDrop,this._onWillMutateLayout,this._onDidMutateLayout,this._onDidMovePanel,this._onDidMovePanel.event(()=>{this.debouncedUpdateAllPositions()}),this._onDidAddGroup,this._onDidRemoveGroup,this._onDidEdgeGroupAutoHideChange,this._onDidActiveGroupChange,this._onUnhandledDragOver,this._onDidMaximizedGroupChange,this._onDidPopoutGroupSizeChange,this._onDidPopoutGroupPositionChange,this._onDidAddPopoutGroup,this._onDidRemovePopoutGroup,this._onDidChangePopouts,this._onDidAddPopoutGroup.event(()=>this._onDidChangePopouts.fire()),this._onDidRemovePopoutGroup.event(()=>this._onDidChangePopouts.fire()),this._onDidOpenPopoutWindowFail,this._onDidStartFloatingGroupDrag,this._onDidEndFloatingGroupDrag,this._onDidCreateTabGroup,this._onDidDestroyTabGroup,this._onDidAddPanelToTabGroup,this._onDidRemovePanelFromTabGroup,this._onDidTabGroupChange,this._onDidTabGroupCollapsedChange,_W.any(this.onDidPopoutGroupSizeChange,this.onDidPopoutGroupPositionChange)(()=>{this.fireLayoutChange(`geometry`)}),_W.any(this.onDidCreateTabGroup,this.onDidDestroyTabGroup,this.onDidAddPanelToTabGroup,this.onDidRemovePanelFromTabGroup,this.onDidTabGroupChange,this.onDidTabGroupCollapsedChange)(()=>{this.fireLayoutChange(`structure`)}),this._onDidOptionsChange,this.onDidAdd(e=>{this._moving||this._onDidAddGroup.fire(e)}),this.onDidRemove(e=>{this._moving||this._onDidRemoveGroup.fire(e)}),this.onDidActiveChange(e=>{this._moving||this._onDidActiveGroupChange.fire(e)}),this.onDidMaximizedChange(e=>{this._onDidMaximizedGroupChange.fire({group:e.panel,isMaximized:e.isMaximized})}),_W.any(this.onDidAddPanel,this.onDidRemovePanel,this.onDidAddGroup,this.onDidRemove,this.onDidRemoveGroup,this.onDidMovePanel)(()=>{this._bufferOnDidLayoutChange.fire(`structure`)}),this.onDidActivePanelChange(()=>{this._bufferOnDidLayoutChange.fire(`activePanel`)}),hW.from(()=>{var e;this._moduleRegistry.dispose(),(e=this._shellManager)==null||e.dispose()}),this._onWillClosePopoutWindow);let i=this._rootDropTargetService;i&&this.addDisposables(i.onWillShowOverlay(e=>{this.gridview.length>0&&e.position===`center`||this._onWillShowOverlay.fire(new oq(e,{kind:`edge`,panel:void 0,api:this._api,group:void 0,getData:pW}))}),i.onDrop(e=>this.dockToLayoutEdge(e.nativeEvent,e.position))),this._moduleRegistry.postConstruct(this),this._shellManager.layoutFromElement()}setVisible(e,t){switch(e.api.location.type){case`grid`:super.setVisible(e,t);break;case`floating`:{let n=this.floatingGroups.find(t=>t.group===e);n&&(n.overlay.setVisible(t),e.api._onDidVisibilityChange.fire({isVisible:t}));break}case`popout`:console.warn(`dockview: You cannot hide a group that is in a popout window`)}}getPopupServiceForGroup(e){var t;return((t=this._popoutWindowService)==null||(t=t.findByGroup(e))==null?void 0:t.popupService)??this.popupService}addPopoutGroup(e,t){return this.mutationAsync(`popout`,()=>this._doAddPopoutGroup(e,t))}getPopouts(){return this._popoutWindowService?.entries.map(e=>({id:e.popoutGroup.id,group:e.popoutGroup,window:e.getWindow()}))??[]}getPopoutWindows(){return this.getPopouts().map(e=>e.window)}_doAddPopoutGroup(e,t){var n;let r=pJ(this._popoutWindowService,`PopoutWindow`,`api.addPopoutGroup`);if(!r||e instanceof Xq&&e.model.location.type===`edge`)return Promise.resolve(!1);if(e instanceof $q&&e.group.size===1&&this.closeEmptyGroups)return this.addPopoutGroup(e.group,t);let i=KW(this.gridview.element),a=this.element;function o(){if(t?.position)return t.position;let n=(e instanceof Xq?e.element:e.group?.element??a).getBoundingClientRect();return{left:window.screenX+n.left,top:window.screenY+n.top,width:n.width,height:n.height}}let s=o(),c=(t==null||(n=t.overridePopoutGroup)==null?void 0:n.id)??this.getNextGroupId(),l=t?.popoutUrl??this.options?.popoutUrl,u=l??`/popout.html`,d=new cG(`${this.id}-${c}`,i??``,{url:u,left:s.left,top:s.top,width:s.width,height:s.height,onDidOpen:t?.onDidOpen,onWillClose:e=>{var n;t==null||(n=t.onWillClose)==null||n.call(t,e),this._onWillClosePopoutWindow.fire(e)},nonce:this.options?.nonce,styleRoot:()=>this.element.getRootNode()}),f=new Y(d,d.onDidClose(()=>{f.dispose()}));this._openingPopoutWindows.add(f);let p=sG(u);return(p?Promise.resolve(null):d.open()).then(n=>{if(this._openingPopoutWindows.delete(f),this.isDisposed)return f.dispose(),!1;if(d.isDisposed){let e=d.failure;return e&&!this.isDisposed&&(SY(e),this._onDidOpenPopoutWindowFail.fire(e)),!1}let i=t?.referenceGroup??(e instanceof $q?e.group:e),a=e.api.location.type,o=i.element.parentElement!==null,s;if(t?.overridePopoutGridview?s=t.overridePopoutGroup??i:o?t?.overridePopoutGroup?s=t.overridePopoutGroup:(s=this.createGroup({id:c}),n&&this._onDidAddGroup.fire(s)):s=i,n===null)return this.handleBlockedPopout({group:s,referenceGroup:i,options:t,popoutWindowDisposable:f,failure:p?{reason:`url-refused`,error:p}:d.failure??{reason:`blocked`}}),!1;let u=document.createElement(`div`);u.className=`dv-overlay-render-container`;let m=new lY(u,this);s.model.renderContainer=m;let h=t?.overridePopoutGridview??this.createNestedGridview();t?.overridePopoutGridview?h.locked=this.gridview.locked:h.addView(s,xG.Distribute,[0]),h.element.style.width=`100%`,h.element.style.height=`100%`,h.layout(d.window.innerWidth,d.window.innerHeight);let g=!1,_=()=>{g||(g=!0,h.dispose())},v,y=[];if(!t?.overridePopoutGroup&&!t?.overridePopoutGridview&&o){if(e instanceof $q){let t=e.group;this.movingLock(()=>{let t=i.model.removePanel(e);s.model.openPanel(t)}),y=[{panel:e,from:t}]}else switch(this.movingLock(()=>wY({from:i,to:s})),y=s.panels.map(e=>({panel:e,from:i})),a){case`grid`:i.api.setVisible(!1);break;case`floating`:case`popout`:v=this.floatingGroups.find(t=>t.group.api.id===e.api.id)?.overlay.toJSON(),this.removeGroup(i)}}n.classList.add(`dv-dockview`),n.style.overflow=`hidden`,n.appendChild(u),n.appendChild(h.element);let b=document.createElement(`div`),x=new mY(b,{disabled:this.rootDropTargetContainer.disabled});n.appendChild(b),s.model.dropTargetContainer=x;let S=new pY(n,d.window);if(f.addDisposables(S),s.model.location={type:`popout`,getWindow:()=>d.window,popoutUrl:l},t?.overridePopoutGridview){let e=this.groups.filter(e=>h.element.contains(e.element));for(let t of e)t.model.renderContainer=m,t.model.dropTargetContainer=x,t.model.location={type:`popout`,getWindow:()=>d.window,popoutUrl:l}}o&&e.api.location.type===`grid`&&e.api.setVisible(!1),this.doSetGroupAndPanelActive(s);let C=r.observeGridviewSize(d,h,m);C&&f.addDisposables(C);let w=new gW;f.addDisposables(w);let T=e=>{w.value=new Y(e.api.onDidActiveChange(e=>{if(e.isActive){var t;(t=d.window)==null||t.focus()}}),e.api.onWillFocus(()=>{var e;(e=d.window)==null||e.focus()}))};T(s);let E={},D=o&&i&&this.getPanel(i.id),O={window:d,popoutGroup:s,gridview:h,overlayRenderContainer:m,dropTargetContainer:x,getWindow:()=>d.window,popoutUrl:l,referenceGroup:D?i.id:void 0,popupService:S,setAnchorGroup:e=>{O.popoutGroup=e,T(e)},disposable:{dispose:()=>(f.dispose(),E.returnedGroup)}},k=XW(d.window);f.addDisposables(k,ZW(d.window,()=>{this._onDidPopoutGroupSizeChange.fire({width:d.window.innerWidth,height:d.window.innerHeight,group:O.popoutGroup})}),k.event(()=>{this._onDidPopoutGroupPositionChange.fire({screenX:d.window.screenX,screenY:d.window.screenY,group:O.popoutGroup})}),Z(d.window,`resize`,()=>{h.layout(d.window.innerWidth,d.window.innerHeight)}),m,hW.from(()=>this.disposePopoutWindow({group:s,referenceGroup:i,popoutGridview:h,isGroupAddedToDom:o,floatingBox:v,disposePopoutGridview:_,closeResult:E}))),r.add(O),this._onDidAddPopoutGroup.fire({id:O.popoutGroup.id,group:O.popoutGroup,window:O.getWindow()});for(let{panel:e,from:t}of y)this.fireDidMovePanel(e,t);return!0}).catch(e=>(this._openingPopoutWindows.delete(f),console.error(`dockview: failed to create popout.`,e),!1))}handleBlockedPopout(e){let{group:t,referenceGroup:n,options:r,popoutWindowDisposable:i,failure:a}=e;if(SY(a),i.dispose(),this._onDidOpenPopoutWindowFail.fire(a),r?.overridePopoutGridview){let e=r.overridePopoutGridview,t=this.groups.filter(t=>e.element.contains(t.element));for(let n of t)this.movingLock(()=>{e.remove(n),this.redockGroupToMainGrid(n)});e.dispose(),n&&!n.api.isVisible&&n.api.setVisible(!0)}else t===n?this.gridview.element.contains(t.element)||(this.movingLock(()=>this.doAddGroup(t,[0])),t.model.location={type:`grid`}):(this.movingLock(()=>wY({from:t,to:n})),t.model.size===0&&this._groups.has(t.id)&&(t.dispose(),this._groups.delete(t.id),this._onDidRemoveGroup.fire(t))),n.api.isVisible||n.api.setVisible(!0)}redockGroupToMainGrid(e){e.model.renderContainer=this.overlayRenderContainer,e.model.dropTargetContainer=this.rootDropTargetContainer,e.model.location={type:`grid`},this.doAddGroup(e,[0])}disposePopoutWindow(e){let{group:t,referenceGroup:n,popoutGridview:r,isGroupAddedToDom:i,floatingBox:a,disposePopoutGridview:o,closeResult:s}=e;if(this.isDisposed){o();return}let c=!!this._popoutWindowService?.entries.find(e=>e.gridview===r),l=this.groups.filter(e=>r.element.contains(e.element)),u=l.includes(t),d=u&&l.length===1;if(!c){u&&this.getPanel(t.id)&&(t.model.renderContainer=this.overlayRenderContainer,t.model.dropTargetContainer=this.rootDropTargetContainer,s.returnedGroup=t),o();return}let f=[];for(let e of l)if(e!==t){this.movingLock(()=>{this.doRemoveGroup(e,{skipDispose:!0,skipActive:!0,skipPopoutReturn:!0}),this.redockGroupToMainGrid(e)});for(let t of e.panels)f.push({panel:t,from:e})}if(u&&i&&this.getPanel(n.id)){let e=[...t.panels];this.movingLock(()=>wY({from:t,to:n}));for(let n of e)f.push({panel:n,from:t});n.api.isVisible||n.api.setVisible(!0),this.getPanel(t.id)&&this.doRemoveGroup(t,{skipPopoutAssociated:!0})}else if(u&&this.getPanel(t.id)){if(t.model.renderContainer=this.overlayRenderContainer,t.model.dropTargetContainer=this.rootDropTargetContainer,s.returnedGroup=t,a&&d)this.addFloatingGroup(t,{height:a.height,width:a.width,position:a});else{this.doRemoveGroup(t,{skipDispose:!0,skipActive:!0,skipPopoutReturn:!0}),t.model.location={type:`grid`},this.movingLock(()=>{this.doAddGroup(t,[0])});for(let e of t.panels)f.push({panel:e,from:t})}this.doSetGroupAndPanelActive(t)}o();for(let{panel:e,from:t}of f)this.fireDidMovePanel(e,t)}addFloatingGroup(e,t){this.mutation(`float`,()=>this._doAddFloatingGroup(e,t))}_doAddFloatingGroup(e,t){if(!pJ(this._floatingGroupService,`FloatingGroup`,`api.addFloatingGroup`)||e instanceof Xq&&e.model.location.type===`edge`)return;let n,r=[];if(e instanceof $q){let t=e.group;n=this.createGroup(),this._onDidAddGroup.fire(n),this.movingLock(()=>this.removePanel(e,{removeEmptyGroup:!1,skipDispose:!0,skipSetActiveGroup:!0})),this.removeGroupIfEmpty(t),this.movingLock(()=>n.model.openPanel(e,{skipSetGroupActive:!0})),r=[{panel:e,from:t}]}else{n=e;let i=this._popoutWindowService?.findReferenceGroupId(n),a=i?this.getPanel(i):void 0;typeof t?.skipRemoveGroup==`boolean`&&t.skipRemoveGroup||(a?(this.movingLock(()=>wY({from:e,to:a})),this.doRemoveGroup(e,{skipPopoutReturn:!0,skipPopoutAssociated:!0}),this.doRemoveGroup(a,{skipDispose:!0}),n=a,r=n.panels.map(t=>({panel:t,from:e}))):(this.doRemoveGroup(e,{skipDispose:!0,skipPopoutReturn:!0,skipPopoutAssociated:!1}),r=n.panels.map(e=>({panel:e,from:n}))))}function i(){if(t?.position){let e={};return`left`in t.position?e.left=Math.max(t.position.left,0):`right`in t.position?e.right=Math.max(t.position.right,0):e.left=yJ.left,`top`in t.position?e.top=Math.max(t.position.top,0):`bottom`in t.position?e.bottom=Math.max(t.position.bottom,0):e.top=yJ.top,e.width=typeof t.width==`number`?Math.max(t.width,0):yJ.width,e.height=typeof t.height==`number`?Math.max(t.height,0):yJ.height,e}return{left:typeof t?.x==`number`?Math.max(t.x,0):yJ.left,top:typeof t?.y==`number`?Math.max(t.y,0):yJ.top,width:typeof t?.width==`number`?Math.max(t.width,0):yJ.width,height:typeof t?.height==`number`?Math.max(t.height,0):yJ.height}}let a=i(),o=this.createNestedGridview();o.addView(n,xG.Distribute,[0]),this.mountFloatingWindow(o,n,[n],a,{dragHandle:t?.dragHandle,inDragMode:t?.inDragMode,skipActiveGroup:t?.skipActiveGroup,disableSmartGuides:t?.disableSmartGuides});for(let{panel:e,from:t}of r)this.fireDidMovePanel(e,t)}get closeEmptyGroups(){return this.options.closeEmptyGroups!==!1}keepEmptyGroups(e){return e.keepEmptyGroups??!this.closeEmptyGroups}removeGroupIfEmpty(e){e.model.size===0&&this.closeEmptyGroups&&this.doRemoveGroup(e,{skipActive:!0})}get locked(){return this.gridview.locked}set locked(e){this.gridview.locked=e,this._shellManager&&(this._shellManager.locked=e);for(let t of this.nestedGridviews())t.locked=e}nestedGridviews(){return[...this.floatingGroups.map(e=>e.gridview),...(this._popoutWindowService?.entries??[]).map(e=>e.gridview)]}createNestedGridview(e=`HORIZONTAL`){return new zG(this.gridview.proportionalLayout,this.options.hideBorders?{separatorBorder:`transparent`}:void 0,e,this.gridview.locked,this.options.theme?.gap??0)}mountFloatingWindow(e,t,n,r,i){let a=pJ(this._floatingGroupService,`FloatingGroup`,`api.addFloatingGroup`);if(!a)return;let o=(i?.dragHandle??this.options.floatingGroupDragHandle??`titlebar`)===`titlebar`?new sJ(this,t):void 0,s=new oJ($($({container:this._floatingOverlayHost??this.gridview.element,content:e.element,header:o?.element},r),{},{minimumInViewportWidth:this.options.floatingGroupBounds===`boundedWithinViewport`?void 0:this.options.floatingGroupBounds?.minimumWidthWithinViewport??100,minimumInViewportHeight:this.options.floatingGroupBounds===`boundedWithinViewport`?void 0:this.options.floatingGroupBounds?.minimumHeightWithinViewport??100,transformDragPosition:this._buildFloatingDragTransform(t,i?.disableSmartGuides??!1),getSiblingBoxes:()=>this._gatherFloatingGroupBoxes(t)})),c=o?.element??t.element.querySelector(`.dv-void-container`);if(!c)throw Error(`dockview: failed to find drag handle`);s.setupDrag(c,{inDragMode:typeof i?.inDragMode==`boolean`&&i.inDragMode});let l=a.add(t,s,e);l.addDisposables(s.onDidStartMoving(()=>this._onDidStartFloatingGroupDrag.fire(t)),s.onDidChangeEnd(()=>this._onDidEndFloatingGroupDrag.fire(t))),o&&(l.setTitleBar(o),l.addDisposables(o,hW.from(()=>l.setTitleBar(void 0)),o.onDragStart(e=>{this._onWillDragGroup.fire({nativeEvent:e,group:l.group})})));for(let e of n)e.model.location={type:`floating`};i?.skipActiveGroup||this.doSetGroupAndPanelActive(t)}orthogonalize(e,t){switch(this.gridview.normalize(),e){case`top`:case`bottom`:this.gridview.orientation===`HORIZONTAL`&&this.gridview.insertOrthogonalSplitviewAtRoot();break;case`left`:case`right`:this.gridview.orientation===`VERTICAL`&&this.gridview.insertOrthogonalSplitviewAtRoot()}switch(e){case`top`:case`left`:case`center`:return this.createGroupAtLocation([0],void 0,t);case`bottom`:case`right`:return this.createGroupAtLocation([this.gridview.length],void 0,t);default:throw Error(`dockview: unsupported position ${e}`)}}updateOptions(e){var t,n;super.updateOptions(e),this.reportMissingOptionModules(e),(t=this._floatingGroupService)==null||t.updateBounds(e),(n=this._rootDropTargetService)==null||n.setOptions(e);let r=this.options.disableDnd,i=this.options.dndStrategy;this._options=$($({},this.options),e);let a=this.options.disableDnd,o=this.options.dndStrategy;if((r!==a||i!==o)&&this.updateDragAndDropState(),`proportionalLayout`in e){let e=this.gridview.proportionalLayout;for(let t of this.nestedGridviews())t.proportionalLayout=e}if(`theme`in e&&this.updateTheme(),`createRightHeaderActionComponent`in e||`createLeftHeaderActionComponent`in e||`createPrefixHeaderActionComponent`in e){var s;(s=this.headerActionsService)==null||s.refreshAll()}if(`createWatermarkComponent`in e){var c;(c=this._watermarkService)==null||c.refresh();for(let e of this.groups)e.model.refreshWatermark()}if(`tabGroupColors`in e||`tabGroupAccent`in e){this._tabGroupColorPalette.setEntries(this._options.tabGroupColors??yq),this._tabGroupColorPalette.enabled=this._options.tabGroupAccent!==`off`;for(let e of this.groups)e.model.refreshTabGroupAccent()}this._onDidOptionsChange.fire(),this._layoutFromShell(this.gridview.width,this.gridview.height)}reportMissingOptionModules(e){vJ(e,e=>this._moduleRegistry.has(e))}layout(e,t,n){var r;this._shellManager&&!this._inShellLayout?this._shellManager.layout(e,t):super.layout(e,t,n),this._syncFloatingOverlayHost(),(r=this._moduleRegistry)==null||(r=r.services.floatingGroupService)==null||r.constrainBounds()}_syncFloatingOverlayHost(){if(!this._floatingOverlayHost||!this._shellManager)return;let e=this._shellManager.element.getBoundingClientRect(),t=this.element.getBoundingClientRect(),n=this._floatingOverlayHost;n.style.left=`${t.left-e.left}px`,n.style.top=`${t.top-e.top}px`,n.style.width=`${t.width}px`,n.style.height=`${t.height}px`}_layoutFromShell(e,t){this._inShellLayout=!0,this.layout(e,t,!0),this._inShellLayout=!1}forceRelayout(){this._shellManager?this._layoutFromShell(this.width,this.height):super.forceRelayout()}addEdgeGroup(e,t){let n=this._edgeGroupService;if(!n)throw Error(dJ(`EdgeGroup`,`api.addEdgeGroup`));if(n.has(e))throw Error(`dockview: edge group already exists at position '${e}'`);return this.mutation(`add`,()=>{let r=this.createGroup({id:t.id});r.model.location={type:`edge`,position:e},r.model.headerPosition=e;let i=r.onDidChange(t=>{var n;if(!t)return;let r=gY(e)?t.width:t.height;typeof r==`number`&&((n=this._shellManager)==null||n.resizeEdgeGroup(e,r))}),a=r.model.onDidRemovePanel(()=>{r.model.isEmpty&&(n.isAutoReveal(r)?queueMicrotask(()=>{r.model.isEmpty&&this._edgeGroupService?.includes(r)&&this.removeEdgeGroup(e)}):this.setEdgeGroupCollapsed(r,!0))});n.add(e,r,new Y(a,i)),t.autoHide!==void 0&&n.setAutoHide(r,t.autoHide),t.autoReveal!==void 0&&n.setAutoReveal(r,t.autoReveal),this._onDidAddGroup.fire(r);let o={element:r.element,get headerPosition(){return r.model.headerPosition},layout:(e,t)=>r.layout(e,t)};return this._shellManager.addEdgeView(e,t,o),r.api})}revealEdgeGroupWithData(e,t,n){let r=this._edgeGroupService;r&&this.mutation(`add`,()=>{let i=r.get(e);i||=(this.addEdgeGroup(e,{id:this.getNextGroupId(),autoReveal:!0,autoHide:n?.autoHide,collapsed:!0}),r.get(e)),i&&this.moveGroupOrPanel({from:{groupId:t.groupId,panelId:t.panelId??void 0},to:{group:i,position:`center`}})})}getEdgeGroup(e){var t;return(t=this._edgeGroupService)==null||(t=t.get(e))==null?void 0:t.api}getEdgeGroupPanel(e){return this._edgeGroupService?.get(e)}pinEdgeGroup(e){var t;(t=pJ(this._moduleRegistry.services.autoHideEdgeGroupService,`AutoHideEdgeGroup`,`api.pinEdgeGroup`))==null||t.pin(e)}autoHideEdgeGroup(e){var t;(t=pJ(this._moduleRegistry.services.autoHideEdgeGroupService,`AutoHideEdgeGroup`,`api.autoHideEdgeGroup`))==null||t.autoHide(e)}peekEdgeGroup(e,t){var n;(n=pJ(this._moduleRegistry.services.autoHideEdgeGroupService,`AutoHideEdgeGroup`,`api.peekEdgeGroup`))==null||n.peek(e,t)}get overlayRoot(){return this.rootElement}getDropZoneRect(){return this.element.getBoundingClientRect()}getEdgeGroupExpandedSize(e){return this._shellManager?.getEdgeGroupExpandedSize(e)??0}repositionPanelOverlay(e,t,n){this.overlayRenderContainer.repositionPanelOverlay(e.api.id,t,n)}setEdgeGroupVisible(e,t){this._shellManager.setEdgeGroupVisible(e,t)}isEdgeGroupVisible(e){return this._shellManager.isEdgeGroupVisible(e)}removeEdgeGroup(e){let t=pJ(this._edgeGroupService,`EdgeGroup`,`api.removeEdgeGroup`);if(!t)return;let n=t.get(e);if(!n)throw Error(`dockview: no edge group exists at position '${e}'`);this.mutation(`remove`,()=>{for(let e of[...n.panels])this.removePanel(e,{removeEmptyGroup:!1,skipDispose:!1});this._shellManager.removeEdgeView(e),t.remove(e),n.dispose(),this._groups.delete(n.id),this._onDidRemoveGroup.fire(n),this.activateFallbackGroupIfRemoved(n)})}setEdgeGroupCollapsed(e,t){let n=this._edgeGroupService?.findPositionOf(e);n&&this._shellManager.isEdgeGroupCollapsed(n)!==t&&(this._shellManager.setEdgeGroupCollapsed(n,t),e.api._onDidCollapsedChange.fire({isCollapsed:t}))}isEdgeGroupCollapsed(e){let t=this._edgeGroupService?.findPositionOf(e);return t?this._shellManager.isEdgeGroupCollapsed(t):!1}isEdgeGroupPeeking(e){return this._peekingGroups.has(e)}setEdgeGroupPeeking(e,t){this._peekingGroups.has(e)!==t&&(t?this._peekingGroups.add(e):this._peekingGroups.delete(e),e.api._onDidPeekChange.fire({isPeeking:t}))}isEdgeGroupAutoHide(e){let t=this._edgeGroupService?.isAutoHide(e);if(t!==void 0)return t;let n=this._edgeGroupService?.findPositionOf(e);return n!==void 0&&dq(this.options.autoHideEdgeGroups,n)}setEdgeGroupAutoHide(e,t){let n=this._edgeGroupService;n?.includes(e)&&(n.setAutoHide(e,t),this._onDidEdgeGroupAutoHideChange.fire(e))}updateDragAndDropState(){for(let e of this.groups)e.model.updateDragAndDropState()}focus(){var e;(e=this.activeGroup)==null||e.focus()}getGroupPanel(e){return this.panels.find(t=>t.id===e)}setActivePanel(e){e.group.model.openPanel(e),this.doSetGroupAndPanelActive(e.group)}activateNext(e={}){if(!e.group){if(!this.activeGroup)return;e.group=this.activeGroup}if(e.includePanel&&e.group&&e.group.activePanel!==e.group.panels[e.group.panels.length-1]){e.group.model.moveToNext({suppressRoll:!0});return}let t=this.activationTarget(e.group,!1);t&&this.doSetGroupAndPanelActive(t)}activatePrevious(e={}){if(!e.group){if(!this.activeGroup)return;e.group=this.activeGroup}if(e.includePanel&&e.group&&e.group.activePanel!==e.group.panels[0]){e.group.model.moveToPrevious({suppressRoll:!0});return}let t=this.activationTarget(e.group,!0);t&&this.doSetGroupAndPanelActive(t)}activationTarget(e,t){let n=this.getGridviewForGroup(e);if(n.element.contains(e.element)){let r=MG(e.element),i=(t?n.previous(r):n.next(r)).view;if(n===this.gridview||i!==e)return i}let r=[],i=e=>{LG(e)?e.children.forEach(i):r.push(e.view)};i(this.gridview.getView());let a=r.filter(e=>e.api.isVisible);return a[t?a.length-1:0]}toJSON(){let e=this.gridview.serialize(),t=this.panels.reduce((e,t)=>(e[t.id]=t.toJSON(),e),{}),n=this._floatingGroupService?.serialize()??[],r=this._popoutWindowService?.serialize()??[],i={grid:e,panels:t,activeGroup:this.activeGroup?.id};n.length>0&&(i.floatingGroups=n),r.length>0&&(i.popoutGroups=r);let a=this._serializeEdgeGroups();return a&&(i.edgeGroups=a),i}_serializeEdgeGroups(){if(!this._edgeGroupService?.hasAny())return;let e=this._shellManager.toJSON();for(let[t,n]of this._edgeGroupService.entries()){let r=e[t];if(!r)continue;if(this._edgeGroupService.isAutoReveal(n)&&n.model.isEmpty){delete e[t];continue}r.group=n.toJSON(),this._edgeGroupService.isAutoReveal(n)&&(r.autoReveal=!0);let i=this._edgeGroupService.isAutoHide(n);i!==void 0&&(r.autoHide=i)}return e}fromJSON(e,t){this.mutation(`load`,()=>this._doFromJSON(e,t))}_doFromJSON(e,t){var n;if((n=this._popoutWindowService)==null||n.cancelPendingRestorations(),typeof e!=`object`||!e)throw Error(`dockview: serialized layout must be a non-null object`);if(!e.grid||e.grid.root?.type!==`branch`||!Array.isArray(e.grid.root.data))throw Error(`dockview: root must be of type branch`);let r=new Map,i=new Map,a=[],o=[],s=()=>{for(let e of o)try{e.dispose()}catch(e){console.error(`dockview: failed to dispose a temporary group created for reuseExistingPanels`,e)}o.length=0};if(t?.reuseExistingPanels){let t=Object.keys(e.panels),n,c=()=>{let e=this.createGroup(),t=this._groups.get(e.api.id);return this._groups.delete(e.api.id),o.push(hW.from(()=>{var n;this.movingLock(()=>{for(let t of e.panels.slice())e.model.removePanel(t)}),t?.disposable.dispose(),(n=this.headerActionsService)==null||n.disposeGroup(e),e.dispose()})),e};try{for(let e of this.panels)if(t.includes(e.api.id)){r.set(e.api.id,e);let t;e.api.renderer===`always`&&e.api.isVisible?t=c():(n??=c(),t=n),i.set(e.api.id,t),a.push({panel:e,temporaryGroup:t})}this.movingLock(()=>{a.forEach(({panel:e,temporaryGroup:t})=>{this.moveGroupOrPanel({from:{groupId:e.api.group.api.id,panelId:e.api.id},to:{group:t,position:`center`},keepEmptyGroups:!0})})}),this.clear()}catch(e){throw s(),e}}else this.clear();let{grid:c,panels:l,activeGroup:u}=e;try{var d,f,p;let t=this.width,n=this.height,a=e=>{let{id:t,locked:n,hideHeader:a,headerPosition:o,views:s,activeView:c}=e;if(typeof t!=`string`)throw TypeError(`dockview: group id must be of type string`);let u=this.createGroup({id:t,locked:n??!1,hideHeader:!!a,headerPosition:o});this._onDidAddGroup.fire(u);let d=[],f=s.filter(e=>l[e]);for(let e of f){let t=r.get(e),n=i.get(e);if(n&&t)this.movingLock(()=>{n.model.removePanel(t)}),d.push(t),t.updateFromStateModel(l[e]);else{let t=this._deserializer.fromJSON(l[e],u);d.push(t)}}for(let e of d){let t=typeof c==`string`&&c===e.id;r.has(e.api.id)?this.movingLock(()=>{u.model.openPanel(e,{skipSetActive:!t,skipSetGroupActive:!0})}):u.model.openPanel(e,{skipSetActive:!t,skipSetGroupActive:!0})}return e.tabGroups&&e.tabGroups.length>0&&u.model.restoreTabGroups(e.tabGroups),!u.activePanel&&u.panels.length>0&&u.model.openPanel(u.panels[u.panels.length-1],{skipSetGroupActive:!0}),u};this.gridview.deserialize(c,{fromJSON:e=>a(e.data)}),this._layoutFromShell(t,n),e.edgeGroups&&this.deserializeEdgeGroups(e.edgeGroups,l,r,i),this.deserializeFloatingWindows(e.floatingGroups??[],a);let o=this.deserializePopoutWindows(e.popoutGroups??[],a);if((d=this._popoutWindowService)==null||d.finishRestoration(o),(f=this._floatingGroupService)==null||f.constrainBounds(),typeof u==`string`){let e=this.getPanel(u);e&&this.doSetGroupAndPanelActive(e)}(p=this._watermarkService)==null||p.update()}catch(e){var m;console.error(`dockview: failed to deserialize layout. Reverting changes`,e);for(let e of this.groups)for(let t of e.panels.slice())this.removePanel(t,{removeEmptyGroup:!1,skipDispose:!1});for(let e of this.groups)this._edgeGroupService?.includes(e)||(e.dispose(),this._groups.delete(e.id),this._onDidRemoveGroup.fire(e));throw(m=this._floatingGroupService)==null||m.disposeAll(),this.clear(),e}finally{s()}this.debouncedUpdateAllPositions(),this._onDidLayoutFromJSON.fire()}deserializeNestedGridview(e,t){let n=this.createNestedGridview(e.orientation),r=[];return n.deserialize(e,{fromJSON:e=>{let n=t(e.data);return r.push(n),n}}),{gridview:n,members:r}}deserializeEdgeGroups(e,t,n,r){let i=pJ(this._edgeGroupService,`EdgeGroup`,`fromJSON edge restoration`);if(i){for(let t of[`top`,`bottom`,`left`,`right`]){let n=e[t];if(n&&!i.has(t)){let e=n.group?.id??`${t}-group`;this.addEdgeGroup(t,{id:e,autoReveal:n.autoReveal,autoHide:n.autoHide,minimumSize:n.minimumSize,maximumSize:n.maximumSize,collapsedSize:n.collapsedSize})}}for(let[a,o]of i.entries()){let i=e[a]?.group;if(i){let{views:e,activeView:a,locked:s,hideHeader:c}=i;o.locked=s??!1,o.header.hidden=!!c;let l=[];for(let i of e){if(!t[i])continue;let e=n.get(i),a=r.get(i);if(a&&e)this.movingLock(()=>{a.model.removePanel(e)}),l.push(e),e.updateFromStateModel(t[i]);else{let e=this._deserializer.fromJSON(t[i],o);l.push(e)}}for(let e of l){let t=a===e.id;n.has(e.api.id)?this.movingLock(()=>{o.model.openPanel(e,{skipSetActive:!t,skipSetGroupActive:!0})}):o.model.openPanel(e,{skipSetActive:!t,skipSetGroupActive:!0})}i.tabGroups&&i.tabGroups.length>0&&o.model.restoreTabGroups(i.tabGroups),!o.activePanel&&o.panels.length>0&&o.model.openPanel(o.panels[o.panels.length-1],{skipSetGroupActive:!0})}}this._shellManager.fromJSON(e)}}deserializeFloatingWindows(e,t){for(let n of e){let{data:e,grid:r,position:i}=n;if(r){let{gridview:e,members:n}=this.deserializeNestedGridview(r,t);if(n.length===0)continue;this.mountFloatingWindow(e,n[0],n,i,{inDragMode:!1})}else if(e){let n=t(e);this.addFloatingGroup(n,{position:i,width:i.width,height:i.height,skipRemoveGroup:!0,inDragMode:!1})}}}deserializePopoutWindows(e,t){let n=e.length>0?pJ(this._popoutWindowService,`PopoutWindow`,`fromJSON popout restoration`):this._popoutWindowService;return n?e.flatMap((e,r)=>{let{data:i,grid:a,position:o,gridReferenceGroup:s,url:c}=e,l,u=[];if(a){let e=this.deserializeNestedGridview(a,t);if(l=e.gridview,u=e.members,u.length===0)return l.dispose(),[]}let d=a?u[0]:t(i);return n.scheduleRestoration(r*100,()=>this.addPopoutGroup(d,{position:o??void 0,overridePopoutGroup:s?d:void 0,overridePopoutGridview:l,referenceGroup:s?this.getPanel(s):void 0,popoutUrl:c}),()=>{for(let e of u.length>0?u:[d])if(!this.isDisposed&&this._groups.has(e.id)&&e.element.parentElement===null){for(let t of[...e.panels])this.removePanel(t,{removeEmptyGroup:!1});e.dispose(),this._groups.delete(e.id),this._onDidRemoveGroup.fire(e)}})}):[]}clear(){this.mutation(`clear`,()=>this._doClear())}_doClear(){let e=Array.from(this._groups.values()).map(e=>e.value),t=!!this.activeGroup;for(let t of e)if(this._edgeGroupService?.includes(t)){let e=[...t.panels];for(let t of e)this.removePanel(t,{removeEmptyGroup:!1})}else this.removeGroup(t,{skipActive:!0});t&&this.doSetGroupAndPanelActive(void 0),this.gridview.clear()}closeAllGroups(){this.mutation(`remove`,()=>{let e=Array.from(this._groups.values()).map(e=>e.value);for(let t of e){if(!this._groups.has(t.id))continue;t.model.closeAllPanels();let e=this.options.noPanelsOverlay===`emptyGroup`&&this.isLastGridGroup(t);!this.closeEmptyGroups&&!e&&this._groups.has(t.id)&&t.model.size===0&&this.removeGroup(t,{skipActive:!0})}})}addPanel(e){return this.mutation(`add`,()=>this._doAddPanel(e))}addPanelFromJSON(e,t){if(!e.contentComponent)throw Error(`dockview: serialized panel ${e.id} has no contentComponent`);return this.mutation(`add`,()=>{let n=this._doAddPanel($($({},t),{},{id:e.id,component:e.contentComponent,tabComponent:e.tabComponent,title:e.title,renderer:e.renderer,params:e.params,minimumWidth:e.minimumWidth,minimumHeight:e.minimumHeight,maximumWidth:e.maximumWidth,maximumHeight:e.maximumHeight}));return e.pinned&&this.setPanelPinned(n,!0),n})}_doAddPanel(e){if(this.panels.some(t=>t.id===e.id))throw Error(`dockview: panel with id ${e.id} already exists`);let t;if(e.position&&e.floating)throw Error(`dockview: you can only provide one of: position, floating as arguments to .addPanel(...)`);let n={width:e.initialWidth,height:e.initialHeight},r,i=t=>!!e.inactive&&t.model.size>0;if(e.position){if(hq(e.position)){let n=typeof e.position.referencePanel==`string`?this.getGroupPanel(e.position.referencePanel):e.position.referencePanel;if(r=e.position.index,!n){let t=typeof e.position.referencePanel==`string`?e.position.referencePanel:e.position.referencePanel?.id;throw Error(`dockview: referencePanel '${t}' does not exist`)}t=this.findGroup(n)}else if(gq(e.position)){if(t=typeof e.position.referenceGroup==`string`?this._groups.get(e.position.referenceGroup)?.value:e.position.referenceGroup,r=e.position.index,!t){let t=typeof e.position.referenceGroup==`string`?e.position.referenceGroup:e.position.referenceGroup?.id;throw Error(`dockview: referenceGroup '${t}' does not exist`)}}else{let t=this.orthogonalize(hK(e.position.direction)),a=this.createPanel(e,t);return t.model.openPanel(a,{skipSetActive:i(t),skipSetGroupActive:e.inactive,index:r}),e.inactive||this.doSetGroupAndPanelActive(t),t.api.setSize({height:n?.height,width:n?.width}),a}}else t=this.activeGroup;let a;if(t){let o=UG(e.position?.direction||`within`);if(e.floating){let t=this.createGroup();this._onDidAddGroup.fire(t);let n=typeof e.floating==`object`&&e.floating!==null?e.floating:{};this.addFloatingGroup(t,$($({},n),{},{inDragMode:!1,skipRemoveGroup:!0,skipActiveGroup:!0})),a=this.createPanel(e,t),t.model.openPanel(a,{skipSetActive:i(t),skipSetGroupActive:e.inactive,index:r})}else if(t.api.location.type===`edge`||o===`center`)a=this.createPanel(e,t),t.model.openPanel(a,{skipSetActive:i(t),skipSetGroupActive:e.inactive,index:r}),t.api.setSize({width:n?.width,height:n?.height}),e.inactive||this.doSetGroupAndPanelActive(t);else{let s=this.getGridviewForGroup(t),c=MG(t.element),l=NG(s.orientation,c,o),u=this.createGroupAtLocation(l,this.orientationAtLocation(l,s)===`VERTICAL`?n?.height:n?.width,void 0,s);a=this.createPanel(e,u),u.model.openPanel(a,{skipSetActive:i(u),skipSetGroupActive:e.inactive,index:r}),e.inactive||this.doSetGroupAndPanelActive(u)}}else if(e.floating){let t=this.createGroup();this._onDidAddGroup.fire(t);let n=typeof e.floating==`object`&&e.floating!==null?e.floating:{};this.addFloatingGroup(t,$($({},n),{},{inDragMode:!1,skipRemoveGroup:!0,skipActiveGroup:!0})),a=this.createPanel(e,t),t.model.openPanel(a,{skipSetActive:i(t),skipSetGroupActive:e.inactive,index:r})}else{let t=this.createGroupAtLocation([0],this.gridview.orientation===`VERTICAL`?n?.height:n?.width);a=this.createPanel(e,t),t.model.openPanel(a,{skipSetActive:i(t),skipSetGroupActive:e.inactive,index:r}),e.inactive||this.doSetGroupAndPanelActive(t)}return a}removePanel(e,t){this.mutation(`remove`,()=>this._doRemovePanel(e,{removeEmptyGroup:t?.removeEmptyGroup??this.closeEmptyGroups,skipDispose:t?.skipDispose,skipSetActiveGroup:t?.skipSetActiveGroup}))}_doRemovePanel(e,t){let n=e.group;if(!n)throw Error(`dockview: cannot remove panel ${e.id}. it's missing a group.`);n.model.removePanel(e,{skipSetActiveGroup:t.skipSetActiveGroup}),t.skipDispose||(e.group.model.renderContainer.detatch(e),e.dispose()),n.size===0&&t.removeEmptyGroup&&this.removeGroup(n,{skipActive:t.skipSetActiveGroup})}createWatermarkComponent(){return this.options.createWatermarkComponent?this.options.createWatermarkComponent():new rJ}addGroup(e){return this.mutation(`add`,()=>this._doAddGroup(e))}serializeGroup(e){let t={};for(let n of e.panels)t[n.id]=n.toJSON();return{group:e.model.toJSON(),panels:t}}addGroupFromJSON(e,t){return this.validateSerializedGroup(e),this.mutation(`add`,()=>this._doAddGroupFromJSON(e,t))}validateSerializedGroup(e){let t=e?.group;if(typeof t?.id!=`string`)throw TypeError(`dockview: group id must be of type string`);if(!Array.isArray(t.views))throw TypeError(`dockview: serialized group ${t.id} has no views`);for(let n of t.views){if(!e.panels?.[n])throw Error(`dockview: serialized group ${t.id} is missing panel state for ${n}`);if(this.panels.some(e=>e.id===n))throw Error(`dockview: panel with id ${n} already exists`)}}_doAddGroupFromJSON(e,t){let{id:n,locked:r,hideHeader:i,headerPosition:a,constraints:o,activeView:s,tabGroups:c}=e.group;if(t&&(t.direction??`within`)===`within`){let n=this.resolveReferenceGroup(t);if(n)return this.mergeGroupFromJSON(e,n,t)}let l={id:n,locked:r??!1,hideHeader:!!i,headerPosition:a,constraints:o,initialWidth:t?.initialWidth,initialHeight:t?.initialHeight,skipSetActive:!0},u=this.addEmptyGroupAt(l,t),d;try{d=this.deserializePanels(e,u)}catch(e){throw this.doRemoveGroup(u,{skipActive:!0}),e}for(let e of d)u.model.openPanel(e,{skipSetActive:e.id!==s,skipSetGroupActive:!0});return c&&c.length>0&&u.model.restoreTabGroups(c),!u.activePanel&&u.panels.length>0&&u.model.openPanel(u.panels[u.panels.length-1],{skipSetGroupActive:!0}),t?.skipSetActive||this.doSetGroupAndPanelActive(u),u}addEmptyGroupAt(e,t){if(t!==void 0&&(_q(t)||vq(t)||typeof t.direction==`string`))return this._doAddGroup($($({},t),e));let n=this.createGroup(e);return this.doAddGroup(n),n}deserializePanels(e,t){let n=[];try{for(let r of e.group.views)n.push(this._deserializer.fromJSON(e.panels[r],t))}catch(e){for(let e of n)e.dispose();throw e}return n}resolveReferenceGroup(e){if(_q(e)){let t=typeof e.referencePanel==`string`?e.referencePanel:e.referencePanel.id,n=this.getGroupPanel(t);if(!n)throw Error(`dockview: reference panel ${t} does not exist`);return n.group}if(vq(e)){let t=typeof e.referenceGroup==`string`?e.referenceGroup:e.referenceGroup.id,n=this.getPanel(t);if(!n)throw Error(`dockview: reference group ${t} does not exist`);return n}}mergeGroupFromJSON(e,t,n){let{activeView:r}=e.group,i=n.index;return this.deserializePanels(e,t).forEach((e,n)=>{t.model.openPanel(e,{index:i===void 0?void 0:i+n,skipSetActive:e.id!==r,skipSetGroupActive:!0})}),n.skipSetActive||this.doSetGroupAndPanelActive(t),t}_doAddGroup(e){if(e){let t;if(_q(e)){let n=typeof e.referencePanel==`string`?this.panels.find(t=>t.id===e.referencePanel):e.referencePanel,r=typeof e.referencePanel==`string`?e.referencePanel:e.referencePanel?.id;if(!n)throw Error(`dockview: reference panel ${r} does not exist`);if(t=this.findGroup(n),!t)throw Error(`dockview: reference group for reference panel ${r} does not exist`)}else if(vq(e)){if(t=typeof e.referenceGroup==`string`?this._groups.get(e.referenceGroup)?.value:e.referenceGroup,!t){let t=typeof e.referenceGroup==`string`?e.referenceGroup:e.referenceGroup?.id;throw Error(`dockview: reference group ${t} does not exist`)}}else{let t=this.orthogonalize(hK(e.direction),e);return e.skipSetActive||this.doSetGroupAndPanelActive(t),t}let n=UG(e.direction||`within`),r=this.getGridviewForGroup(t),i=MG(t.element),a=NG(r.orientation,i,n),o=this.orientationAtLocation(a,r)===`VERTICAL`?e.initialHeight:e.initialWidth,s=this.createGroupAtLocation(a,o,e,r);return e.skipSetActive||this.doSetGroupAndPanelActive(s),s}{let t=this.createGroup(e);return this.doAddGroup(t),this.doSetGroupAndPanelActive(t),t}}removeGroup(e,t){this.mutation(`remove`,()=>this.doRemoveGroup(e,t))}detachFromNestedWindow(e){let t=this._floatingGroupService?.findByGroup(e);if(t){let n=this.nestedWindowMembers(e);return n.length<=1?!1:(t.gridview.remove(e),t.group===e&&t.setAnchorGroup(n.find(t=>t!==e)),!0)}let n=this._popoutWindowService?.findByGroup(e);if(n){let t=this.nestedWindowMembers(e);return t.length<=1?!1:(n.gridview.remove(e),n.popoutGroup===e&&n.setAnchorGroup(t.find(t=>t!==e)),!0)}return!1}disposeGroupRecord(e){e.dispose(),this._groups.delete(e.id),this._onDidRemoveGroup.fire(e)}activateFallbackGroupIfRemoved(e,t){if(!t&&this._activeGroup===e){let e=Array.from(this._groups.values());this.doSetGroupAndPanelActive(e.length>0?e[0].value:void 0)}}doRemoveGroup(e,t){if(this._edgeGroupService?.includes(e))return e;let n=[...e.panels];if(!t?.skipDispose)for(let e of n)this.removePanel(e,{removeEmptyGroup:!1,skipDispose:t?.skipDispose??!1});let r=this.activePanel;if(e.api.location.type===`floating`){let n=this._floatingGroupService?.findByGroup(e);if(!n)throw Error(`dockview: failed to find floating group`);return this.detachFromNestedWindow(e)?(t?.skipDispose?e.model.location={type:`grid`}:this.disposeGroupRecord(e),this.activateFallbackGroupIfRemoved(e,t?.skipActive),e):(t?.skipDispose||this.disposeGroupRecord(e),n.dispose(),this.activateFallbackGroupIfRemoved(e,t?.skipActive),e)}if(e.api.location.type===`popout`){var i;let n=this._popoutWindowService?.findByGroup(e);if(!n)throw Error(`dockview: failed to find popout group`);if(this.detachFromNestedWindow(e))return t?.skipDispose?e.model.location={type:`grid`}:this.disposeGroupRecord(e),this.activateFallbackGroupIfRemoved(e,t?.skipActive),e;if(!t?.skipDispose){if(!t?.skipPopoutAssociated){let e=n.referenceGroup?this.getPanel(n.referenceGroup):void 0;e?.panels.length===0&&(this.closeEmptyGroups||!e.api.isVisible)&&this.removeGroup(e)}n.popoutGroup.dispose(),this._groups.delete(e.id),this._onDidRemoveGroup.fire(e)}(i=this._popoutWindowService)==null||i.remove(n);let r=n.disposable.dispose();return!t?.skipPopoutReturn&&r&&(this.doAddGroup(r,[0]),this.doSetGroupAndPanelActive(r)),this.activateFallbackGroupIfRemoved(e,t?.skipActive),n.popoutGroup}if(!this.gridview.element.contains(e.element))return t?.skipDispose||(this._groups.get(e.id)?.disposable.dispose(),this.disposeGroupRecord(e)),this.activateFallbackGroupIfRemoved(e,t?.skipActive),e;let a=super.doRemoveGroup(e,t);return t?.skipActive||this.activePanel!==r&&this.fireActivePanelChange(this.activePanel),a}debouncedUpdateAllPositions(){this._updatePositionsFrameId!==void 0&&cancelAnimationFrame(this._updatePositionsFrameId),this._updatePositionsFrameId=requestAnimationFrame(()=>{this._updatePositionsFrameId=void 0,this.overlayRenderContainer.updateAllPositions();for(let e of this._popoutWindowService?.entries??[])e.overlayRenderContainer.updateAllPositions()})}movingLock(e){let t=this._moving;try{return this._moving=!0,e()}finally{this._moving=t}}mutation(e,t){let n=this.openMutation(e);this._syncMutationDepth++;try{return t()}finally{this._syncMutationDepth--,this._syncMutationDepth===0&&this.releaseDisposedActiveGroup(),n()}}mutationAsync(e,t){var n=this;return rG(function*(){let r=n.openMutation(e);try{return yield t()}finally{r()}})()}openMutation(e){let t=this._origin;return this._mutationDepth===0&&this._onWillMutateLayout.fire({kind:e,origin:t}),this._mutationDepth++,()=>{this._mutationDepth--,this._mutationDepth===0&&(this.releaseDisposedActiveGroup(),this.flushLocationChanges(),this._onDidMutateLayout.fire({kind:e,origin:t}))}}releaseDisposedActiveGroup(){!this.isDisposed&&this._activeGroup?.model.isDisposed&&this.activateFallbackGroupIfRemoved(this._activeGroup)}deferLocationChange(e,t){this._mutationDepth===0?t():this._pendingLocationChanges.set(e,t)}flushLocationChanges(){if(this._pendingLocationChanges.size===0)return;let e=Array.from(this._pendingLocationChanges.values());this._pendingLocationChanges.clear();for(let t of e)t()}currentOrigin(){return this._origin}withOrigin(e,t){if(this._originDepth>0||this._mutationDepth>0)return t();let n=this._origin;this._origin=e,this._originDepth++;try{return t()}finally{this._originDepth--,this._origin=n}}fireActivePanelChange(e){this._onDidActivePanelChange.fire({panel:e,origin:this._origin})}fireDidMovePanel(e,t){this._onDidMovePanel.fire({panel:e,from:t,to:e.group})}moveGroupOrPanel(e){this.mutation(`move`,()=>this._doMoveGroupOrPanel(e))}_doMoveGroupOrPanel(e){let t=e.to.group,n=e.from.groupId,r=e.from.panelId,i=e.to.position,a=e.to.index,o=n?this._groups.get(n)?.value:void 0;if(!o)throw Error(`dockview: Failed to find group id ${n}`);if(r===void 0)e.from.tabGroupId?this.moveTabGroupToGroup({sourceGroup:o,tabGroupId:e.from.tabGroupId,destinationGroup:t,destinationTarget:i,destinationIndex:a,skipSetActive:e.skipSetActive,keepEmptyGroups:e.keepEmptyGroups}):this.moveGroup({from:{group:o},to:{group:t,position:i},skipSetActive:e.skipSetActive});else if(!i||i===`center`){let n=this.movingLock(()=>o.model.removePanel(r,{skipSetActive:!1,skipSetActiveGroup:!0}));if(!n)throw Error(`dockview: No panel with id ${r}`);!this.keepEmptyGroups(e)&&o.model.size===0&&o!==t&&this.doRemoveGroup(o,{skipActive:!0});let i=t.model.size===0;this.movingLock(()=>t.model.openPanel(n,{index:a,skipSetActive:(e.skipSetActive??!1)&&!i,skipSetGroupActive:!0})),e.skipSetActive||this.doSetGroupAndPanelActive(t),this.fireDidMovePanel(n,o)}else{let n=this.getGridviewForGroup(t),a=MG(t.element),s=NG(n.orientation,a,i);if(o.size<2&&!this.keepEmptyGroups(e)){if(o===t)return;let[e,c]=lG(s);if(o.api.location.type===`grid`&&n===this.gridview){let[n,i]=lG(MG(o.element));if((this.options.dropSizing!==`distribute`||o===t)&&uG(n,e)){this.gridview.moveView(n,i,c),this.fireDidMovePanel(this.getGroupPanel(r),o);return}}if(o.api.location.type===`popout`&&this.nestedWindowMembers(o).length<=1){let e=this._popoutWindowService?.findByGroup(o);if(!e)return;let a=this.movingLock(()=>e.popoutGroup.model.removePanel(e.popoutGroup.panels[0],{skipSetActive:!0,skipSetActiveGroup:!0}));this.doRemoveGroup(o,{skipActive:!0});let s=NG(n.orientation,MG(t.element),i),c=this.createGroupAtLocation(s,this.sizingForDrop(MG(t.element)),void 0,n);this.movingLock(()=>c.model.openPanel(a,{skipSetActive:!0})),this.doSetGroupAndPanelActive(c),this.fireDidMovePanel(this.getGroupPanel(r),o);return}if(o.api.location.type===`edge`){let e=this.movingLock(()=>o.model.removePanel(r,{skipSetActive:!1,skipSetActiveGroup:!0}));if(!e)throw Error(`dockview: No panel with id ${r}`);let t=this.createGroupAtLocation(s,this.sizingForDrop(a),void 0,n);this.movingLock(()=>t.model.openPanel(e,{skipSetGroupActive:!0})),this.doSetGroupAndPanelActive(t),this.fireDidMovePanel(e,o);return}let l=this.movingLock(()=>this.doRemoveGroup(o,{skipActive:!0,skipDispose:!0})),u=MG(t.element),d=NG(n.orientation,u,i);this.movingLock(()=>this.doAddGroup(l,d,this.sizingForDrop(u),n)),this.setGroupLocationForRoot(l,n),this.doSetGroupAndPanelActive(l),this.fireDidMovePanel(this.getGroupPanel(r),o)}else{let e=this.movingLock(()=>o.model.removePanel(r,{skipSetActive:!1,skipSetActiveGroup:!0}));if(!e)throw Error(`dockview: No panel with id ${r}`);let t=NG(n.orientation,a,i),s=this.createGroupAtLocation(t,this.sizingForDrop(a),void 0,n);this.movingLock(()=>s.model.openPanel(e,{skipSetGroupActive:!0})),this.doSetGroupAndPanelActive(s),this.fireDidMovePanel(e,o)}}}moveTabGroupToGroup(e){let{sourceGroup:t,tabGroupId:n,destinationGroup:r,destinationTarget:i,destinationIndex:a}=e,o=t.model.getTabGroups().find(e=>e.id===n);if(!o||o.panelIds.length===0)return;let s=o.label,c=o.color,l=o.collapsed,u=o.componentParams,d=[...o.panelIds],f=i&&i!==`center`?MG(r.element):void 0,p=this.movingLock(()=>d.map(e=>t.model.removePanel(e,{skipSetActive:!1,skipSetActiveGroup:!0})).filter(e=>e!==void 0));if(p.length===0)return;let m=n=>{this.movingLock(()=>{for(let e of p)n.model.openPanel(e,{index:a,skipSetActive:!0,skipSetGroupActive:!0})});let r=n.model.createTabGroup({label:s,color:c,collapsed:l,componentParams:u});for(let e of p)n.model.addPanelToTabGroup(r.id,e.id);e.skipSetActive||this.doSetGroupAndPanelActive(n);for(let e of p)this.fireDidMovePanel(e,t)},h;if(!i||i===`center`||!f)h=r;else{let e=this.getGridviewForGroup(r),t=NG(e.orientation,f,i);h=this.createGroupAtLocation(t,this.sizingForDrop(f),void 0,e)}!this.keepEmptyGroups(e)&&t.model.size===0&&t!==h&&this.doRemoveGroup(t,{skipActive:!0}),m(h)}moveGroup(e){this.mutation(`move`,()=>this._doMoveGroup(e))}maximizeGroup(e){this.mutation(`maximize`,()=>super.maximizeGroup(e))}exitMaximizedGroup(){this.mutation(`maximize`,()=>super.exitMaximizedGroup())}_doMoveGroup(e){let t=e.from.group,n=e.to.group,r=e.to.position;if(r===`center`&&t===n)return;let i=t,a;if(r===`center`){let r=t.activePanel,i=t.model.getTabGroups().map(e=>({label:e.label,color:e.color,collapsed:e.collapsed,componentParams:e.componentParams,panelIds:[...e.panelIds]})),o=this.movingLock(()=>[...t.panels].map(e=>t.model.removePanel(e.id,{skipSetActive:!0})));t?.model.size===0&&this.doRemoveGroup(t,{skipActive:!0}),this.movingLock(()=>{for(let e of o)n.model.openPanel(e,{skipSetActive:e!==r,skipSetGroupActive:!0})}),a=o;for(let e of i){let t=n.model.createTabGroup({label:e.label,color:e.color,collapsed:e.collapsed,componentParams:e.componentParams});for(let r of e.panelIds)n.model.addPanelToTabGroup(t.id,r)}e.skipSetActive===!0&&this.activePanel||this.doSetGroupAndPanelActive(n)}else{let e=(()=>{if(t.api.location.type===`edge`||n.api.location.type===`edge`)return!1;let e=this.getGridviewForGroup(t);if(e!==this.getGridviewForGroup(n))return!1;let i,a;try{i=MG(t.element),a=MG(n.element)}catch{return!1}return i.length===0||a.length===0?!1:uG(lG(i)[0],lG(a)[0])&&FG(e.orientation,a)===PG(r)})();if(t.api.location.type===`edge`){let e=t.activePanel,n=t.model.getTabGroups().map(e=>({label:e.label,color:e.color,collapsed:e.collapsed,componentParams:e.componentParams,panelIds:[...e.panelIds]})),r=this.movingLock(()=>[...t.panels].map(e=>t.model.removePanel(e.id,{skipSetActive:!0})));i=this.createGroup(),this._onDidAddGroup.fire(i),this.movingLock(()=>{for(let t of r)i.model.openPanel(t,{skipSetActive:t!==e,skipSetGroupActive:!0})});for(let e of n){let t=i.model.createTabGroup({label:e.label,color:e.color,collapsed:e.collapsed,componentParams:e.componentParams});for(let n of e.panelIds)i.model.addPanelToTabGroup(t.id,n)}}else switch(t.api.location.type){case`grid`:this.gridview.removeView(MG(t.element));break;case`floating`:{let e=this._floatingGroupService?.findByGroup(t);if(!e)throw Error(`dockview: failed to find floating group`);this.detachFromNestedWindow(t)||e.dispose();break}case`popout`:{var o;let e=this._popoutWindowService?.findByGroup(t);if(!e)throw Error(`dockview: failed to find popout group`);if(this.detachFromNestedWindow(t))break;if((o=this._popoutWindowService)==null||o.remove(e),e.referenceGroup){let t=this.getPanel(e.referenceGroup);t&&!t.api.isVisible&&this.doRemoveGroup(t,{skipActive:!0})}e.window.dispose();break}}if(n.api.location.type===`grid`||n.api.location.type===`floating`||n.api.location.type===`popout`){let a=this.getGridviewForGroup(n),o=MG(n.element),s=NG(a.orientation,o,r),c;c=e&&this.options.dropSizing!==`distribute`?PG(r)===`HORIZONTAL`?t.api.width:t.api.height:this.sizingForDrop(o),a.addView(i,c,s),this.setGroupLocationForRoot(i,a)}}if((a??i.panels).forEach(e=>{this.fireDidMovePanel(e,t)}),this.debouncedUpdateAllPositions(),e.skipSetActive===!1){let e=n??t;this.doSetGroupAndPanelActive(e)}else i!==t&&e.skipSetActive!==!0&&this.doSetGroupAndPanelActive(i)}doSetGroupActive(e){super.doSetGroupActive(e);let t=this.activePanel;!this._moving&&t!==this._onDidActivePanelChange.value?.panel&&this.fireActivePanelChange(t)}doSetGroupAndPanelActive(e){super.doSetGroupActive(e);let t=this.activePanel;e&&this.hasMaximizedGroup()&&!this.isMaximizedGroup(e)&&this.exitMaximizedGroup(),!this._moving&&t!==this._onDidActivePanelChange.value?.panel&&this.fireActivePanelChange(t)}getNextGroupId(){let e=this.options.groupIdGenerator;if(!e){let e=this.nextGroupId.next();for(;this._groups.has(e);)e=this.nextGroupId.next();return e}for(let t=0;t<DY;t++){let t=e();if(typeof t!=`string`||t.length===0)throw TypeError(`dockview: groupIdGenerator must return a non-empty string`);if(!this._groups.has(t))return t}throw Error(`dockview: groupIdGenerator returned an id already in use ${DY} times in a row`)}createGroup(e){e??={};let t=e?.id;t&&this._groups.has(e.id)&&(console.warn(`dockview: Duplicate group id ${e?.id}. reassigning group id to avoid errors`),t=void 0),t||=this.getNextGroupId();let n=new Xq(this,t,e);if(n.init({params:{},accessor:this}),!this._groups.has(n.id)){let e=new Y(n.model.onTabDragStart(e=>{var t;(t=this._advancedDnDService)==null||t.dispatchWillDragPanel(e)}),n.model.onGroupDragStart(e=>{var t;(t=this._advancedDnDService)==null||t.dispatchWillDragGroup(e)}),n.model.onMove(e=>{let{groupId:t,itemId:r,target:i,index:a,tabGroupId:o}=e;this.moveGroupOrPanel({from:{groupId:t,panelId:r,tabGroupId:o},to:{group:n,position:i,index:a}})}),n.model.onDidDrop(e=>{this._onDidDrop.fire(e)}),n.model.onWillDrop(e=>{var t;(t=this._advancedDnDService)==null||t.dispatchWillDrop(e)}),n.model.onWillShowOverlay(e=>{var t;this.options.disableDnd?e.preventDefault():(t=this._advancedDnDService)==null||t.dispatchWillShowOverlay(e)}),n.model.onUnhandledDragOver(e=>{this._onUnhandledDragOver.fire(e)}),n.model.onDidAddPanel(e=>{this._moving||this._onDidAddPanel.fire(e.panel)}),n.model.onDidRemovePanel(e=>{this._moving||this._onDidRemovePanel.fire(e.panel)}),n.model.onDidActivePanelChange(e=>{this._moving||e.panel===this.activePanel&&this._onDidActivePanelChange.value?.panel!==e.panel&&this.fireActivePanelChange(e.panel)}),n.model.onDidPanelTitleChange(()=>{this._bufferOnDidLayoutChange.fire(`panelTitle`)}),n.model.onDidPanelParametersChange(()=>{this._bufferOnDidLayoutChange.fire(`panelParameters`)}));this._groups.set(n.id,{value:n,disposable:e})}return n.initialize(),n}createPanel(e,t){let n=e.component,r=e.tabComponent??this.options.defaultTabComponent,i=new tJ(this,e.id,n,r),a=new $q(e.id,n,r,this,this._api,t,i,{renderer:e.renderer,minimumWidth:e.minimumWidth,minimumHeight:e.minimumHeight,maximumWidth:e.maximumWidth,maximumHeight:e.maximumHeight});return a.init({title:e.title??e.id,params:e?.params??{}}),a}sizingForDrop(e){return this.options.dropSizing===`distribute`?xG.Distribute:xG.Split(e.length===0?0:e[e.length-1])}createGroupAtLocation(e,t,n,r=this.gridview){let i=this.createGroup(n);return this.doAddGroup(i,e,t,r),this.setGroupLocationForRoot(i,r),i}setGroupLocationForRoot(e,t){let n=this._popoutWindowService?.entries.find(e=>e.gridview===t);n?(e.model.renderContainer!==n.overlayRenderContainer&&(e.model.renderContainer=n.overlayRenderContainer),e.model.dropTargetContainer=n.dropTargetContainer,e.model.location={type:`popout`,getWindow:n.getWindow,popoutUrl:n.popoutUrl}):(e.model.renderContainer!==this.overlayRenderContainer&&(e.model.renderContainer=this.overlayRenderContainer),e.model.dropTargetContainer=this.rootDropTargetContainer,e.model.location=t===this.gridview?{type:`grid`}:{type:`floating`})}getGridviewForGroup(e){let t=this._floatingGroupService?.findByGroup(e);if(t)return t.gridview;let n=this._popoutWindowService?.findByGroup(e);return n?n.gridview:this.gridview}nestedWindowMembers(e){let t=this.getGridviewForGroup(e);return t===this.gridview?[]:this.groups.filter(e=>t.element.contains(e.element))}findGroup(e){return Array.from(this._groups.values()).find(t=>t.value.model.containsPanel(e))?.value}orientationAtLocation(e,t=this.gridview){let n=t.orientation;return e.length%2==1?n:IG(n)}updateTheme(){var e,t;let n=this._options.theme??Zq;(e=this._shellThemeClassnames)==null||e.setClassNames(n.className);let r=n.gap??0;this.gridview.margin=r;for(let e of this.nestedGridviews())e.margin=r;if((t=this._shellManager)==null||t.updateTheme(r,n.edgeGroupCollapsedSize??35),n.dndOverlayBorder===void 0){var i;this.element.style.removeProperty(`--dv-drag-over-border`),(i=this._shellManager)==null||i.element.style.removeProperty(`--dv-drag-over-border`)}else{var a;this.element.style.setProperty(`--dv-drag-over-border`,n.dndOverlayBorder),(a=this._shellManager)==null||a.element.style.setProperty(`--dv-drag-over-border`,n.dndOverlayBorder)}switch(n.dndOverlayMounting){case`absolute`:this.rootDropTargetContainer.disabled=!1;break;default:this.rootDropTargetContainer.disabled=!0}let o=(n.tabGroupIndicator??`wrap`)===`none`;Q(this.element,`dv-tab-group-indicator-none`,o),this._shellManager&&Q(this._shellManager.element,`dv-tab-group-indicator-none`,o);for(let e of this.groups)e.model.updateTabGroups()}},kY=class extends WG{get orientation(){return this.gridview.orientation}set orientation(e){this.gridview.orientation=e}get options(){return this._options}get deserializer(){return this._deserializer}set deserializer(e){this._deserializer=e}constructor(e,t){super(e,{proportionalLayout:t.proportionalLayout??!0,orientation:t.orientation,styles:t.hideBorders?{separatorBorder:`transparent`}:void 0,disableAutoResizing:t.disableAutoResizing,className:t.className}),this._onDidLayoutfromJSON=new X,this.onDidLayoutFromJSON=this._onDidLayoutfromJSON.event,this._onDidRemoveGroup=new X,this.onDidRemoveGroup=this._onDidRemoveGroup.event,this._onDidAddGroup=new X,this.onDidAddGroup=this._onDidAddGroup.event,this._onDidActiveGroupChange=new X,this.onDidActiveGroupChange=this._onDidActiveGroupChange.event,this._options=t,this.addDisposables(this._onDidAddGroup,this._onDidRemoveGroup,this._onDidActiveGroupChange,this.onDidAdd(e=>{this._onDidAddGroup.fire(e)}),this.onDidRemove(e=>{this._onDidRemoveGroup.fire(e)}),this.onDidActiveChange(e=>{this._onDidActiveGroupChange.fire(e)})),this.layoutFromElement()}updateOptions(e){super.updateOptions(e);let t=typeof e.orientation==`string`&&this.gridview.orientation!==e.orientation;this._options=$($({},this.options),e),t&&(this.gridview.orientation=e.orientation),this.layout(this.gridview.width,this.gridview.height,!0)}removePanel(e){this.removeGroup(e)}toJSON(){return{grid:this.gridview.serialize(),activePanel:this.activeGroup?.id}}setVisible(e,t){this.gridview.setViewVisible(MG(e.element),t)}setActive(e){this._groups.forEach((t,n)=>{t.value.setActive(e===t.value)})}focus(){var e;(e=this.activeGroup)==null||e.focus()}fromJSON(e){this.clear();let{grid:t,activePanel:n}=e;try{let e=[],r=this.width,i=this.height;if(this.gridview.deserialize(t,{fromJSON:t=>{let{data:n}=t,r=this.options.createComponent({id:n.id,name:n.component});return e.push(()=>r.init({params:n.params,minimumWidth:n.minimumWidth,maximumWidth:n.maximumWidth,minimumHeight:n.minimumHeight,maximumHeight:n.maximumHeight,priority:n.priority,snap:!!n.snap,accessor:this,isVisible:t.visible})),this._onDidAddGroup.fire(r),this.registerPanel(r),r}}),this.layout(r,i,!0),e.forEach(e=>e()),typeof n==`string`){let e=this.getPanel(n);e&&this.doSetGroupActive(e)}}catch(e){for(let e of this.groups)e.dispose(),this._groups.delete(e.id),this._onDidRemoveGroup.fire(e);throw this.clear(),e}this._onDidLayoutfromJSON.fire()}clear(){let e=this.activeGroup,t=Array.from(this._groups.values());for(let e of t)e.disposable.dispose(),this.doRemoveGroup(e.value,{skipActive:!0});e&&this.doSetGroupActive(void 0),this.gridview.clear()}movePanel(e,t){let n=this._groups.get(t.reference)?.value;if(!n)throw Error(`reference group ${t.reference} does not exist`);let r=UG(t.direction);if(r===`center`)throw Error(`${r} not supported as an option`);let i=MG(n.element),a=NG(this.gridview.orientation,i,r),o=this.gridview.remove(e);this.doAddGroup(o,a,t.size)}addPanel(e){let t=e.location??[0];if(e.position?.referencePanel){let n=this._groups.get(e.position.referencePanel)?.value;if(!n)throw Error(`reference group ${e.position.referencePanel} does not exist`);let r=UG(e.position.direction);if(r===`center`)throw Error(`${r} not supported as an option`);{let e=MG(n.element);t=NG(this.gridview.orientation,e,r)}}let n=this.options.createComponent({id:e.id,name:e.component});return n.init({params:e.params??{},minimumWidth:e.minimumWidth,maximumWidth:e.maximumWidth,minimumHeight:e.minimumHeight,maximumHeight:e.maximumHeight,priority:e.priority,snap:!!e.snap,accessor:this,isVisible:!0}),this.doAddGroup(n,t,e.size),this.registerPanel(n),this.doSetGroupActive(n),n}registerPanel(e){let t=new Y(e.api.onDidFocusChange(t=>{t.isFocused&&this._groups.forEach(t=>{let n=t.value;n.setActive(n===e)})}));this._groups.set(e.id,{value:e,disposable:t})}moveGroup(e,t,n){let r=this.getPanel(t);if(!r)throw Error(`invalid operation`);let i=MG(e.element),[a,o]=lG(NG(this.gridview.orientation,i,n)),[s,c]=lG(MG(r.element));if(uG(s,a)){this.gridview.moveView(s,c,o);return}let l=this.doRemoveGroup(r,{skipActive:!0,skipDispose:!0}),u=MG(e.element),d=NG(this.gridview.orientation,u,n);this.doAddGroup(l,d)}removeGroup(e){super.removeGroup(e)}dispose(){super.dispose(),this._onDidLayoutfromJSON.dispose()}},AY=class extends VG{get panels(){return this.splitview.getViews()}get options(){return this._options}get length(){return this._panels.size}get orientation(){return this.splitview.orientation}get splitview(){return this._splitview}set splitview(e){this._splitview&&this._splitview.dispose(),this._splitview=e,this._splitviewChangeDisposable.value=new Y(this._splitview.onDidSashEnd(()=>{this._onDidLayoutChange.fire({reasons:new Set([`geometry`])})}),this._splitview.onDidAddView(e=>this._onDidAddView.fire(e)),this._splitview.onDidRemoveView(e=>this._onDidRemoveView.fire(e)))}get minimumSize(){return this.splitview.minimumSize}get maximumSize(){return this.splitview.maximumSize}get height(){return this.splitview.orientation===`HORIZONTAL`?this.splitview.orthogonalSize:this.splitview.size}get width(){return this.splitview.orientation===`HORIZONTAL`?this.splitview.size:this.splitview.orthogonalSize}constructor(e,t){super(document.createElement(`div`),t.disableAutoResizing),this._splitviewChangeDisposable=new gW,this._panels=new Map,this._onDidLayoutfromJSON=new X,this.onDidLayoutFromJSON=this._onDidLayoutfromJSON.event,this._onDidAddView=new X,this.onDidAddView=this._onDidAddView.event,this._onDidRemoveView=new X,this.onDidRemoveView=this._onDidRemoveView.event,this._onDidLayoutChange=new X,this.onDidLayoutChange=this._onDidLayoutChange.event,this.element.style.height=`100%`,this.element.style.width=`100%`,this._classNames=new qW(this.element),this._classNames.setClassNames(t.className??``),e.appendChild(this.element),this._options=t,this.splitview=new SG(this.element,t),this.addDisposables(this._onDidAddView,this._onDidLayoutfromJSON,this._onDidRemoveView,this._onDidLayoutChange),this.layoutFromElement()}updateOptions(e){if(`className`in e&&this._classNames.setClassNames(e.className??``),`disableAutoResizing`in e&&(this.disableResizing=e.disableAutoResizing??!1),typeof e.orientation==`string`&&e.orientation!==this.splitview.orientation){this.splitview.orientation=e.orientation;for(let t of this.panels)t.orientation=e.orientation}this._options=$($({},this.options),e),this.splitview.layout(this.splitview.size,this.splitview.orthogonalSize)}focus(){var e;(e=this._activePanel)==null||e.focus()}movePanel(e,t){this.splitview.moveView(e,t)}setVisible(e,t){let n=this.panels.indexOf(e);this.splitview.setViewVisible(n,t)}setActive(e,t){this._activePanel=e,this.panels.filter(t=>t!==e).forEach(e=>{e.api._onDidActiveChange.fire({isActive:!1}),t||e.focus()}),e.api._onDidActiveChange.fire({isActive:!0}),t||e.focus()}removePanel(e,t){let n=this._panels.get(e.id);if(!n)throw Error(`unknown splitview panel ${e.id}`);n.dispose(),this._panels.delete(e.id);let r=this.panels.indexOf(e);this.splitview.removeView(r,t).dispose();let i=this.panels;i.length>0&&this.setActive(i[i.length-1])}getPanel(e){return this.panels.find(t=>t.id===e)}addPanel(e){if(this._panels.has(e.id))throw Error(`panel ${e.id} already exists`);let t=this.options.createComponent({id:e.id,name:e.component});t.orientation=this.splitview.orientation,t.init({params:e.params??{},minimumSize:e.minimumSize,maximumSize:e.maximumSize,snap:e.snap,priority:e.priority,accessor:this});let n=typeof e.size==`number`?e.size:xG.Distribute,r=typeof e.index==`number`?e.index:void 0;return this.splitview.addView(t,n,r),this.doAddView(t),this.setActive(t),t}layout(e,t){let[n,r]=this.splitview.orientation===`HORIZONTAL`?[e,t]:[t,e];this.splitview.layout(n,r)}doAddView(e){let t=e.api.onDidFocusChange(t=>{t.isFocused&&this.setActive(e,!0)});this._panels.set(e.id,t)}toJSON(){return{views:this.splitview.getViews().map((e,t)=>{let n=this.splitview.getViewCachedVisibleSize(t),r=typeof n==`number`;return $({size:r?n:this.splitview.getViewSize(t),data:e.toJSON(),snap:!!e.snap,priority:e.priority},r?{visible:!1}:{})}),activeView:this._activePanel?.id,size:this.splitview.size,orientation:this.splitview.orientation}}fromJSON(e){this.clear();let{views:t,orientation:n,size:r,activeView:i}=e,a=[],o=this.width,s=this.height;if(this.splitview=new SG(this.element,{orientation:n,proportionalLayout:this.options.proportionalLayout,descriptor:{size:r,views:t.map(e=>{let t=e.data;if(this._panels.has(t.id))throw Error(`panel ${t.id} already exists`);let r=this.options.createComponent({id:t.id,name:t.component});return a.push(()=>{r.init({params:t.params??{},minimumSize:t.minimumSize,maximumSize:t.maximumSize,snap:e.snap,priority:e.priority,accessor:this}),e.visible===!1&&r.setVisible(!1)}),r.orientation=n,this.doAddView(r),setTimeout(()=>{this._onDidAddView.fire(r)},0),{size:e.size,view:r,visible:e.visible}})}}),this.layout(o,s),a.forEach(e=>e()),typeof i==`string`){let e=this.getPanel(i);e&&this.setActive(e)}this._onDidLayoutfromJSON.fire()}clear(){for(let e of this._panels.values())e.dispose();for(this._panels.clear();this.splitview.length>0;)this.splitview.removeView(0,xG.Distribute,!0).dispose()}dispose(){for(let e of this._panels.values())e.dispose();this._panels.clear();let e=this.splitview.getViews();this._splitviewChangeDisposable.dispose(),this.splitview.dispose();for(let t of e)t.dispose();this.element.remove(),super.dispose()}},jY=class extends Y{get element(){return this._element}constructor(){super(),this._expandedIcon=XK(),this._collapsedIcon=ZK(),this.disposable=new gW,this.apiRef={api:null},this._element=document.createElement(`div`),this.element.className=`dv-default-header`,this._content=document.createElement(`span`),this._expander=document.createElement(`div`),this._expander.className=`dv-pane-header-icon`,this.element.appendChild(this._expander),this.element.appendChild(this._content),this.addDisposables(Z(this._element,`click`,()=>{var e;(e=this.apiRef.api)==null||e.setExpanded(!this.apiRef.api.isExpanded)}))}init(e){this.apiRef.api=e.api,this._content.textContent=e.title,this.updateIcon(),this.disposable.value=e.api.onDidExpansionChange(()=>{this.updateIcon()})}updateIcon(){let e=!!this.apiRef.api?.isExpanded;Q(this._expander,`collapsed`,!e),e?(this._expander.contains(this._collapsedIcon)&&this._collapsedIcon.remove(),this._expander.contains(this._expandedIcon)||this._expander.appendChild(this._expandedIcon)):(this._expander.contains(this._expandedIcon)&&this._expandedIcon.remove(),this._expander.contains(this._collapsedIcon)||this._expander.appendChild(this._collapsedIcon))}update(e){}dispose(){this.disposable.dispose(),super.dispose()}},MY=gG(),NY=22,PY=0,FY=2**53-1,IY=class extends UK{constructor(e){super({accessor:e.accessor,id:e.id,component:e.component,headerComponent:e.headerComponent,orientation:e.orientation,isExpanded:e.isExpanded,disableDnd:e.disableDnd,headerSize:e.headerSize,minimumBodySize:e.minimumBodySize,maximumBodySize:e.maximumBodySize}),this.options=e}getBodyComponent(){return this.options.body}getHeaderComponent(){return this.options.header}},LY=class extends VG{get id(){return this._id}get panels(){return this.paneview.getPanes()}set paneview(e){this._paneview=e,this._disposable.value=new Y(this._paneview.onDidChange(()=>{this._onDidLayoutChange.fire({reasons:new Set([`geometry`])})}),this._paneview.onDidAddView(e=>this._onDidAddView.fire(e)),this._paneview.onDidRemoveView(e=>this._onDidRemoveView.fire(e)))}get paneview(){return this._paneview}get minimumSize(){return this.paneview.minimumSize}get maximumSize(){return this.paneview.maximumSize}get height(){return this.paneview.orientation===`HORIZONTAL`?this.paneview.orthogonalSize:this.paneview.size}get width(){return this.paneview.orientation===`HORIZONTAL`?this.paneview.size:this.paneview.orthogonalSize}get options(){return this._options}constructor(e,t){super(document.createElement(`div`),t.disableAutoResizing),this._id=MY.next(),this._disposable=new gW,this._viewDisposables=new Map,this._onDidLayoutfromJSON=new X,this.onDidLayoutFromJSON=this._onDidLayoutfromJSON.event,this._onDidLayoutChange=new X,this.onDidLayoutChange=this._onDidLayoutChange.event,this._onDidDrop=new X,this.onDidDrop=this._onDidDrop.event,this._onDidAddView=new X,this.onDidAddView=this._onDidAddView.event,this._onDidRemoveView=new X,this.onDidRemoveView=this._onDidRemoveView.event,this._onUnhandledDragOver=new X,this.onUnhandledDragOver=this._onUnhandledDragOver.event,this.element.style.height=`100%`,this.element.style.width=`100%`,this.addDisposables(this._onDidLayoutChange,this._onDidLayoutfromJSON,this._onDidDrop,this._onDidAddView,this._onDidRemoveView,this._onUnhandledDragOver),this._classNames=new qW(this.element),this._classNames.setClassNames(t.className??``),e.appendChild(this.element),this._options=t,this.paneview=new wG(this.element,{orientation:`VERTICAL`}),this.addDisposables(this._disposable)}setVisible(e,t){let n=this.panels.indexOf(e);this.paneview.setViewVisible(n,t)}focus(){}updateOptions(e){`className`in e&&this._classNames.setClassNames(e.className??``),`disableAutoResizing`in e&&(this.disableResizing=e.disableAutoResizing??!1),this._options=$($({},this.options),e)}addPanel(e){let t=this.options.createComponent({id:e.id,name:e.component}),n;e.headerComponent&&this.options.createHeaderComponent&&(n=this.options.createHeaderComponent({id:e.id,name:e.headerComponent})),n??=new jY;let r=new IY({id:e.id,component:e.component,headerComponent:e.headerComponent,header:n,body:t,orientation:`VERTICAL`,isExpanded:!!e.isExpanded,disableDnd:!!this.options.disableDnd,accessor:this,headerSize:e.headerSize??NY,minimumBodySize:PY,maximumBodySize:FY});this.doAddPanel(r);let i=typeof e.size==`number`?e.size:xG.Distribute,a=typeof e.index==`number`?e.index:void 0;return r.init({params:e.params??{},minimumBodySize:e.minimumBodySize,maximumBodySize:e.maximumBodySize,isExpanded:e.isExpanded,title:e.title,containerApi:new tK(this),accessor:this}),this.paneview.addPane(r,i,a),r.orientation=this.paneview.orientation,r}removePanel(e){let t=this.panels.indexOf(e);if(t<0)throw Error(`unknown paneview panel ${e.id}`);this.paneview.removePane(t),this.doRemovePanel(e)}movePanel(e,t){this.paneview.moveView(e,t)}getPanel(e){return this.panels.find(t=>t.id===e)}layout(e,t){let[n,r]=this.paneview.orientation===`HORIZONTAL`?[e,t]:[t,e];this.paneview.layout(n,r)}toJSON(){let e=e=>e===2**53-1||e===1/0?void 0:e,t=e=>e<=0?void 0:e;return{views:this.paneview.getPanes().map((n,r)=>{let i=this.paneview.getViewCachedVisibleSize(r),a=typeof i==`number`;return $({size:a?i:this.paneview.getViewSize(r),data:n.toJSON(),minimumSize:t(n.minimumBodySize),maximumSize:e(n.maximumBodySize),headerSize:n.headerSize,expanded:n.isExpanded()},a?{visible:!1}:{})}),size:this.paneview.size}}fromJSON(e){this.clear();let{views:t,size:n}=e,r=[],i=this.width,a=this.height;this.paneview.dispose(),this.paneview=new wG(this.element,{orientation:`VERTICAL`,descriptor:{size:n,views:t.map(e=>{let t=e.data,n=this.options.createComponent({id:t.id,name:t.component}),i;t.headerComponent&&this.options.createHeaderComponent&&(i=this.options.createHeaderComponent({id:t.id,name:t.headerComponent})),i??=new jY;let a=new IY({id:t.id,component:t.component,headerComponent:t.headerComponent,header:i,body:n,orientation:`VERTICAL`,isExpanded:!!e.expanded,disableDnd:!!this.options.disableDnd,accessor:this,headerSize:e.headerSize??NY,minimumBodySize:e.minimumSize??PY,maximumBodySize:e.maximumSize??FY});return this.doAddPanel(a),r.push(()=>{a.init({params:t.params??{},minimumBodySize:e.minimumSize,maximumBodySize:e.maximumSize,title:t.title,isExpanded:!!e.expanded,containerApi:new tK(this),accessor:this}),a.orientation=this.paneview.orientation,e.visible===!1&&a.setVisible(!1)}),setTimeout(()=>{this._onDidAddView.fire(a)},0),{size:e.size,view:a,visible:e.visible}})}}),this.layout(i,a),r.forEach(e=>e()),this._onDidLayoutfromJSON.fire()}clear(){for(let[e,t]of this._viewDisposables.entries())t.dispose();this._viewDisposables.clear();let e=this.width,t=this.height;this.paneview.dispose(),this.paneview=new wG(this.element,{orientation:`VERTICAL`}),this.layout(e,t)}doAddPanel(e){let t=new Y(e.onDidDrop(e=>{this._onDidDrop.fire(e)}),e.onUnhandledDragOver(e=>{this._onUnhandledDragOver.fire(e)}));this._viewDisposables.set(e.id,t)}doRemovePanel(e){let t=this._viewDisposables.get(e.id);t&&(t.dispose(),this._viewDisposables.delete(e.id))}dispose(){super.dispose();for(let[e,t]of this._viewDisposables.entries())t.dispose();this._viewDisposables.clear(),this.element.remove(),this.paneview.dispose()}},RY=class extends VK{get priority(){return this._priority}set orientation(e){this._orientation=e}get orientation(){return this._orientation}get minimumSize(){let e=typeof this._minimumSize==`function`?this._minimumSize():this._minimumSize;return e!==this._evaluatedMinimumSize&&(this._evaluatedMinimumSize=e,this.updateConstraints()),e}get maximumSize(){let e=typeof this._maximumSize==`function`?this._maximumSize():this._maximumSize;return e!==this._evaluatedMaximumSize&&(this._evaluatedMaximumSize=e,this.updateConstraints()),e}get snap(){return this._snap}constructor(e,t){super(e,t,new zK(e,t)),this._evaluatedMinimumSize=0,this._evaluatedMaximumSize=1/0,this._minimumSize=0,this._maximumSize=1/0,this._snap=!1,this._onDidChange=new X,this.onDidChange=this._onDidChange.event,this.api.initialize(this),this.addDisposables(this._onDidChange,this.api.onWillVisibilityChange(e=>{let{isVisible:t}=e,{accessor:n}=this._params;n.setVisible(this,t)}),this.api.onActiveChange(()=>{let{accessor:e}=this._params;e.setActive(this)}),this.api.onDidConstraintsChangeInternal(e=>{(typeof e.minimumSize==`number`||typeof e.minimumSize==`function`)&&(this._minimumSize=e.minimumSize),(typeof e.maximumSize==`number`||typeof e.maximumSize==`function`)&&(this._maximumSize=e.maximumSize),this.updateConstraints()}),this.api.onDidSizeChange(e=>{this._onDidChange.fire({size:e.size})}))}setVisible(e){this.api._onDidVisibilityChange.fire({isVisible:e})}setActive(e){this.api._onDidActiveChange.fire({isActive:e})}layout(e,t){let[n,r]=this.orientation===`HORIZONTAL`?[e,t]:[t,e];super.layout(n,r)}init(e){super.init(e),this._priority=e.priority,e.minimumSize&&(this._minimumSize=e.minimumSize),e.maximumSize&&(this._maximumSize=e.maximumSize),e.snap&&(this._snap=e.snap)}toJSON(){return $($({},super.toJSON()),{},{minimumSize:(e=>e<=0?void 0:e)(this.minimumSize),maximumSize:(e=>e===2**53-1||e===1/0?void 0:e)(this.maximumSize)})}updateConstraints(){this.api._onDidConstraintsChange.fire({maximumSize:this._evaluatedMaximumSize,minimumSize:this._evaluatedMinimumSize})}};function zY(e,t){return new OY(e,t).api}function BY(e,t){return new eK(new AY(e,t))}function VY(e,t){return new nK(new kY(e,t))}function HY(e,t){return new tK(new LY(e,t))}function UY(e){"@babel/helpers - typeof";return UY=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},UY(e)}function WY(e,t){if(UY(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(UY(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function GY(e){var t=WY(e,`string`);return UY(t)==`symbol`?t:t+``}function KY(e,t,n){return(t=GY(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function qY(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function JY(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?qY(Object(n),!0).forEach(function(t){KY(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):qY(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var YY=(e,t)=>{let[,n]=V.useState(0),r=V.useRef(e.componentProps);return V.useImperativeHandle(t,()=>({update:e=>{r.current=JY(JY({},r.current),e),n(e=>e+1)}}),[]),V.createElement(e.component,r.current)};YY.displayName=`DockviewReactJsBridge`;var XY=(()=>{let e=1;return{next:()=>`dockview_react_portal_key_${(e++).toString()}`}})(),ZY=V.createContext({}),QY=class{constructor(e,t,n,r,i){this.parent=e,this.portalStore=t,this.component=n,this.parameters=r,this.context=i,this._initialProps={},this.disposed=!1,this.createPortal()}update(e){if(this.disposed)throw Error(`invalid operation: resource is already disposed`);this.componentInstance?this.componentInstance.update(e):this._initialProps=JY(JY({},this._initialProps),e)}createPortal(){if(this.disposed)throw Error(`invalid operation: resource is already disposed`);if(!eX(this.component))throw Error(`Dockview: Only React.memo(...), React.ForwardRef(...) and functional components are accepted as components`);let e=V.createElement(V.forwardRef(YY),{component:this.component,componentProps:this.parameters,ref:e=>{this.componentInstance=e,Object.keys(this._initialProps).length>0&&(this.componentInstance.update(this._initialProps),this._initialProps={})}}),t=this.context?V.createElement(ZY.Provider,{value:this.context},e):e,n=Xf.createPortal(t,this.parent,XY.next());this.ref={portal:n,disposable:this.portalStore.addPortal(n)}}dispose(){var e;(e=this.ref)==null||e.disposable.dispose(),this.disposed=!0}},$Y=()=>{let[e,t]=V.useState([]);return V.useDebugValue(`Portal count: ${e.length}`),[e,V.useCallback(e=>{t(t=>[...t,e]);let n=!1;return hW.from(()=>{if(n)throw Error(`invalid operation: resource already disposed`);n=!0,t(t=>t.filter(t=>t!==e))})},[])]};function eX(e){return typeof e==`function`||!!e?.$$typeof}function tX(e,t){let n=e=>e instanceof ShadowRoot?e.host:e.parentNode,r=new Set,i=new MutationObserver(n=>{if(!e.isConnected)i.disconnect(),t();else for(let e of n)for(let t of e.removedNodes)if(r.has(t)){a();return}}),a=()=>{i.disconnect(),r.clear();for(let t=n(e);t;t=n(t))r.add(t),i.observe(t,{childList:!0})};return a(),hW.from(()=>i.disconnect())}var nX=Number.parseInt(`19.3.1`,10)>=18;function rX(e,t,n){let r=V.useRef(void 0);V.useEffect(()=>{var i;let a=e.current;if(!a)return;(i=r.current)==null||i.dispose(),r.current=void 0;let o=t.current??n(a);return t.current=o,()=>{let e=()=>{r.current=void 0,t.current=void 0,o.dispose()};nX&&a.isConnected&&typeof MutationObserver<`u`?r.current=tX(a,e):e()}},[])}function iX(e){let t=V.useRef({instance:void 0,values:new Map});return V.useCallback(n=>{t.current.instance!==e.current&&(t.current={instance:e.current,values:new Map});let r=t.current.values,i=!0;for(let[e,t]of Object.entries(n))r.has(e)&&r.get(e)!==t&&(i=!1),r.set(e,t);return i},[e])}var aX=class{get element(){return this._element}constructor(e,t,n){this.id=e,this.component=t,this.reactPortalStore=n,this._onDidFocus=new X,this.onDidFocus=this._onDidFocus.event,this._onDidBlur=new X,this.onDidBlur=this._onDidBlur.event,this._element=document.createElement(`div`),this._element.className=`dv-react-part`,this._element.style.height=`100%`,this._element.style.width=`100%`}focus(){}init(e){this.part=new QY(this.element,this.reactPortalStore,this.component,{params:e.params,api:e.api,containerApi:e.containerApi})}update(e){var t;(t=this.part)==null||t.update({params:e.params})}layout(e,t){}dispose(){var e;this._onDidFocus.dispose(),this._onDidBlur.dispose(),(e=this.part)==null||e.dispose()}},oX=class{get element(){return this._element}constructor(e,t,n){this.id=e,this.component=t,this.reactPortalStore=n,this._element=document.createElement(`div`),this._element.className=`dv-react-part`,this._element.style.height=`100%`,this._element.style.width=`100%`}focus(){}init(e){this.part=new QY(this.element,this.reactPortalStore,this.component,{params:e.params,api:e.api,containerApi:e.containerApi,tabLocation:e.tabLocation})}update(e){var t;(t=this.part)==null||t.update({params:e.params})}layout(e,t){}dispose(){var e;(e=this.part)==null||e.dispose()}},sX=class{get element(){return this._element}constructor(e,t,n){this.id=e,this.component=t,this.reactPortalStore=n,this._element=document.createElement(`div`),this._element.className=`dv-react-part`,this._element.style.height=`100%`,this._element.style.width=`100%`}init(e){this.part=new QY(this.element,this.reactPortalStore,this.component,{group:e.group,containerApi:e.containerApi})}focus(){}update(e){var t;this.parameters&&(this.parameters.params=e.params),(t=this.part)==null||t.update({params:this.parameters?.params??{}})}layout(e,t){}dispose(){var e;(e=this.part)==null||e.dispose()}},cX=class{get element(){return this._element}get part(){return this._part}constructor(e,t,n){this.component=e,this.reactPortalStore=t,this._group=n,this.mutableDisposable=new gW,this._element=document.createElement(`div`),this._element.className=`dv-react-part`,this._element.style.height=`100%`,this._element.style.width=`100%`}init(e){this.mutableDisposable.value=new Y(this._group.model.onDidAddPanel(()=>{this.updatePanels()}),this._group.model.onDidRemovePanel(()=>{this.updatePanels()}),this._group.model.onDidActivePanelChange(()=>{this.updateActivePanel()}),e.api.onDidActiveChange(()=>{this.updateGroupActive()}),e.api.onDidLocationChange(e=>{this.updateLocation(e.location)})),this._part=new QY(this.element,this.reactPortalStore,this.component,{api:e.api,containerApi:e.containerApi,panels:this._group.model.panels,activePanel:this._group.model.activePanel,isGroupActive:this._group.api.isActive,group:this._group,headerPosition:this._group.model.headerPosition,location:e.api.location})}dispose(){var e;this.mutableDisposable.dispose(),(e=this._part)==null||e.dispose()}update(e){var t;(t=this._part)==null||t.update(e.params)}updatePanels(){this.update({params:{panels:this._group.model.panels}})}updateActivePanel(){this.update({params:{activePanel:this._group.model.activePanel}})}updateGroupActive(){this.update({params:{isGroupActive:this._group.api.isActive}})}updateLocation(e){this.update({params:{location:e}})}},lX=class{get element(){return this._element}constructor(e,t,n){this.id=e,this.component=t,this.reactPortalStore=n,this._element=document.createElement(`div`),this._element.className=`dv-react-part`,this._element.style.height=`100%`,this._element.style.width=`100%`}init(e){this.part=new QY(this._element,this.reactPortalStore,this.component,e)}dispose(){var e;(e=this.part)==null||e.dispose()}},uX=class{get element(){return this._element}constructor(e,t){this.component=e,this.reactPortalStore=t,this._element=document.createElement(`div`),this._element.className=`dv-react-part`,this._element.style.display=`inline-flex`}init(e){this.part=new QY(this._element,this.reactPortalStore,this.component,{tabGroup:e.tabGroup,api:e.api})}update(e){var t;(t=this.part)==null||t.update({tabGroup:e.tabGroup})}dispose(){var e;(e=this.part)==null||e.dispose()}},dX=class{get element(){return this._element}constructor(e,t){this.component=e,this.reactPortalStore=t,this._element=document.createElement(`div`),this._element.className=`dv-react-part`,this._element.style.display=`inline-flex`}init(e){this.part=new QY(this._element,this.reactPortalStore,this.component,{group:e.group,api:e.api})}dispose(){var e;(e=this.part)==null||e.dispose()}};function fX(e,t){return e?n=>new cX(e,t,n):void 0}var pX=`props.defaultTabComponent`;function mX(e){return mq.reduce((t,n)=>(n in e&&(t[n]=e[n]),t),{})}var hX=V.forwardRef((e,t)=>{let n=V.useRef(null),r=V.useRef(void 0),[i,a]=$Y(),o=iX(r);V.useImperativeHandle(t,()=>n.current,[]);let s=V.useRef({});return V.useEffect(()=>{let t={};mq.forEach(n=>{let r=n,i=e[r];r in e&&i!==s.current[r]&&(t[r]=i)}),r.current&&Object.keys(t).length>0&&r.current.updateOptions(t),s.current=e},mq.map(t=>e[t])),rX(n,r,t=>{let n=JY({},e.tabComponents);e.defaultTabComponent&&(n[pX]=e.defaultTabComponent);let r={createLeftHeaderActionComponent:fX(e.leftHeaderActionsComponent,{addPortal:a}),createRightHeaderActionComponent:fX(e.rightHeaderActionsComponent,{addPortal:a}),createPrefixHeaderActionComponent:fX(e.prefixHeaderActionsComponent,{addPortal:a}),createComponent:t=>new aX(t.id,e.components[t.name],{addPortal:a}),createTabComponent(e){return new oX(e.id,n[e.name],{addPortal:a})},createWatermarkComponent:e.watermarkComponent?()=>new sX(`watermark`,e.watermarkComponent,{addPortal:a}):void 0,defaultTabComponent:e.defaultTabComponent?pX:void 0,createContextMenuItemComponent:e=>{if(e.component)return new lX(e.id,e.component,{addPortal:a})}},i=mX(e);if(e.tabGroupChipComponent){let t=e.tabGroupChipComponent;i.createTabGroupChipComponent=()=>new uX(t,{addPortal:a})}if(e.groupDragGhostComponent){let t=e.groupDragGhostComponent;i.createGroupDragGhostComponent=()=>new dX(t,{addPortal:a})}let o=zY(t,JY(JY({},i),r)),{clientWidth:s,clientHeight:c}=t;return o.layout(s,c),e.onReady&&e.onReady({api:o}),o}),V.useEffect(()=>{if(!r.current)return()=>{};let t=r.current.onDidDrop(t=>{e.onDidDrop&&e.onDidDrop(t)});return()=>{t.dispose()}},[e.onDidDrop]),V.useEffect(()=>{if(!r.current)return()=>{};let t=r.current.onWillDrop(t=>{e.onWillDrop&&e.onWillDrop(t)});return()=>{t.dispose()}},[e.onWillDrop]),V.useEffect(()=>{r.current&&!o({tabGroupChipComponent:e.tabGroupChipComponent})&&r.current.updateOptions({createTabGroupChipComponent:e.tabGroupChipComponent?()=>new uX(e.tabGroupChipComponent,{addPortal:a}):void 0})},[e.tabGroupChipComponent]),V.useEffect(()=>{r.current&&!o({groupDragGhostComponent:e.groupDragGhostComponent})&&r.current.updateOptions({createGroupDragGhostComponent:e.groupDragGhostComponent?()=>new dX(e.groupDragGhostComponent,{addPortal:a}):void 0})},[e.groupDragGhostComponent]),V.useEffect(()=>{r.current&&!o({components:e.components})&&r.current.updateOptions({createComponent:t=>new aX(t.id,e.components[t.name],{addPortal:a})})},[e.components]),V.useEffect(()=>{if(!r.current||o({tabComponents:e.tabComponents,defaultTabComponent:e.defaultTabComponent}))return;let t=JY({},e.tabComponents);e.defaultTabComponent&&(t[pX]=e.defaultTabComponent),r.current.updateOptions({defaultTabComponent:e.defaultTabComponent?pX:void 0,createTabComponent(e){return new oX(e.id,t[e.name],{addPortal:a})}})},[e.tabComponents,e.defaultTabComponent]),V.useEffect(()=>{r.current&&!o({watermarkComponent:e.watermarkComponent})&&r.current.updateOptions({createWatermarkComponent:e.watermarkComponent?()=>new sX(`watermark`,e.watermarkComponent,{addPortal:a}):void 0})},[e.watermarkComponent]),V.useEffect(()=>{r.current&&!o({rightHeaderActionsComponent:e.rightHeaderActionsComponent})&&r.current.updateOptions({createRightHeaderActionComponent:fX(e.rightHeaderActionsComponent,{addPortal:a})})},[e.rightHeaderActionsComponent]),V.useEffect(()=>{r.current&&!o({leftHeaderActionsComponent:e.leftHeaderActionsComponent})&&r.current.updateOptions({createLeftHeaderActionComponent:fX(e.leftHeaderActionsComponent,{addPortal:a})})},[e.leftHeaderActionsComponent]),V.useEffect(()=>{r.current&&!o({prefixHeaderActionsComponent:e.prefixHeaderActionsComponent})&&r.current.updateOptions({createPrefixHeaderActionComponent:fX(e.prefixHeaderActionsComponent,{addPortal:a})})},[e.prefixHeaderActionsComponent]),V.createElement(`div`,{style:{height:`100%`,width:`100%`},ref:n},i)});hX.displayName=`DockviewComponent`;var gX=class extends RY{constructor(e,t,n,r){super(e,t),this.reactComponent=n,this.reactPortalStore=r}getComponent(){return new QY(this.element,this.reactPortalStore,this.reactComponent,{params:this._params?.params??{},api:this.api,containerApi:new eK(this._params.accessor)})}};function _X(e){return CG.reduce((t,n)=>(n in e&&(t[n]=e[n]),t),{})}var vX=V.forwardRef((e,t)=>{let n=V.useRef(null),r=V.useRef(void 0),[i,a]=$Y(),o=iX(r);V.useImperativeHandle(t,()=>n.current,[]);let s=V.useRef({});return V.useEffect(()=>{let t={};CG.forEach(n=>{let r=n,i=e[r];r in e&&i!==s.current[r]&&(t[r]=i)}),r.current&&Object.keys(t).length>0&&r.current.updateOptions(t),s.current=e},CG.map(t=>e[t])),rX(n,r,t=>{let n=BY(t,JY(JY({},_X(e)),{createComponent:t=>new gX(t.id,t.name,e.components[t.name],{addPortal:a})})),{clientWidth:r,clientHeight:i}=t;return n.layout(r,i),e.onReady&&e.onReady({api:n}),n}),V.useEffect(()=>{r.current&&!o({components:e.components})&&r.current.updateOptions({createComponent:t=>new gX(t.id,t.name,e.components[t.name],{addPortal:a})})},[e.components]),V.createElement(`div`,{style:{height:`100%`,width:`100%`},ref:n},i)});vX.displayName=`SplitviewComponent`;var yX=class extends Gq{constructor(e,t,n,r){super(e,t),this.reactComponent=n,this.reactPortalStore=r}getComponent(){return new QY(this.element,this.reactPortalStore,this.reactComponent,{params:this._params?.params??{},api:this.api,containerApi:new nK(this._params.accessor)})}};function bX(e){return BG.reduce((t,n)=>(n in e&&(t[n]=e[n]),t),{})}var xX=V.forwardRef((e,t)=>{let n=V.useRef(null),r=V.useRef(void 0),[i,a]=$Y(),o=iX(r);V.useImperativeHandle(t,()=>n.current,[]);let s=V.useRef({});return V.useEffect(()=>{let t={};BG.forEach(n=>{let r=n,i=e[r];r in e&&i!==s.current[r]&&(t[r]=i)}),r.current&&Object.keys(t).length>0&&r.current.updateOptions(t),s.current=e},BG.map(t=>e[t])),rX(n,r,t=>{let n=VY(t,JY(JY({},bX(e)),{createComponent:t=>new yX(t.id,t.name,e.components[t.name],{addPortal:a})})),{clientWidth:r,clientHeight:i}=t;return n.layout(r,i),e.onReady&&e.onReady({api:n}),n}),V.useEffect(()=>{r.current&&!o({components:e.components})&&r.current.updateOptions({createComponent:t=>new yX(t.id,t.name,e.components[t.name],{addPortal:a})})},[e.components]),V.createElement(`div`,{style:{height:`100%`,width:`100%`},ref:n},i)});xX.displayName=`GridviewComponent`;var SX=class{get element(){return this._element}constructor(e,t,n){this.id=e,this.component=t,this.reactPortalStore=n,this._element=document.createElement(`div`),this._element.style.height=`100%`,this._element.style.width=`100%`}init(e){this.part=new QY(this.element,this.reactPortalStore,this.component,{params:e.params,api:e.api,title:e.title,containerApi:e.containerApi})}toJSON(){return{id:this.id}}update(e){var t;(t=this.part)==null||t.update({params:e.params})}dispose(){var e;(e=this.part)==null||e.dispose()}};function CX(e){return FK.reduce((t,n)=>(n in e&&(t[n]=e[n]),t),{})}var wX=V.forwardRef((e,t)=>{let n=V.useRef(null),r=V.useRef(void 0),[i,a]=$Y(),o=iX(r);V.useImperativeHandle(t,()=>n.current,[]);let s=V.useRef({});return V.useEffect(()=>{let t={};FK.forEach(n=>{let r=n,i=e[r];r in e&&i!==s.current[r]&&(t[r]=i)}),r.current&&Object.keys(t).length>0&&r.current.updateOptions(t),s.current=e},FK.map(t=>e[t])),rX(n,r,t=>{let n=e.headerComponents??{},r=HY(t,JY(JY({},CX(e)),{createComponent:t=>new SX(t.id,e.components[t.name],{addPortal:a}),createHeaderComponent:e=>new SX(e.id,n[e.name],{addPortal:a})})),{clientWidth:i,clientHeight:o}=t;return r.layout(i,o),e.onReady&&e.onReady({api:r}),r}),V.useEffect(()=>{r.current&&!o({components:e.components})&&r.current.updateOptions({createComponent:t=>new SX(t.id,e.components[t.name],{addPortal:a})})},[e.components]),V.useEffect(()=>{if(!r.current||o({headerComponents:e.headerComponents}))return;let t=e.headerComponents??{};r.current.updateOptions({createHeaderComponent:e=>new SX(e.id,t[e.name],{addPortal:a})})},[e.headerComponents]),V.useEffect(()=>{if(!r.current)return()=>{};let t=r.current.onDidDrop(t=>{e.onDidDrop&&e.onDidDrop(t)});return()=>{t.dispose()}},[e.onDidDrop]),V.createElement(`div`,{style:{height:`100%`,width:`100%`},ref:n},i)});wX.displayName=`PaneviewComponent`;var TX={dock:`_dock_psx21_10`,tab:`_tab_psx21_155`,buttons:`_buttons_psx21_178`,body:`_body_psx21_189`,heading:`_heading_psx21_197`,none:`_none_psx21_209`},EX=({label:e,shortcut:t,onClick:n,children:r})=>{let i=ET();return(0,G.jsx)(cb,{"aria-keyshortcuts":bT(t,i),keys:yT(t,i),label:e,onClick:n,children:r})},DX=({group:e,activePanel:t,workspace:n})=>{ab(n.view);let r=t?.title??`panel`,i=t!==void 0&&nW(t.id)?t.id:void 0,a=e.api.location.type===`floating`,o=e.api.isMaximized();return(0,G.jsxs)(`div`,{className:TX.buttons,children:[(0,G.jsx)(EX,{label:`Minimize ${r}`,onClick:()=>{n.minimize(i)},shortcut:CT.minimize,children:(0,G.jsx)(ay,{})}),a?null:(0,G.jsx)(EX,{label:o?`Restore ${r}`:`Maximize ${r}`,onClick:()=>{n.toggleMaximize(e)},shortcut:CT.maximize,children:o?(0,G.jsx)(sy,{}):(0,G.jsx)(oy,{})}),(0,G.jsx)(EX,{label:a?`Dock ${r}`:`Float ${r}`,onClick:()=>{n.toggleFloat(e)},shortcut:CT.float,children:a?(0,G.jsx)(ly,{}):(0,G.jsx)(cy,{})}),(0,G.jsx)(EX,{label:`Close ${r}`,onClick:()=>{n.close(i)},shortcut:CT.close,children:(0,G.jsx)(Jv,{})})]})},OX=e=>{let t=(0,V.use)(ZM);return t===null?null:(0,G.jsx)(DX,{...e,workspace:t})},kX=6,AX=({api:e})=>{let t=nW(e.id)?rW(e.id).Icon:null;return(0,G.jsxs)(`span`,{className:TX.tab,children:[t===null?null:(0,G.jsx)(t,{}),e.title]})},jX=()=>(0,G.jsx)(`div`,{className:TX.none,children:(0,G.jsx)(CC,{title:`No panels open.`,children:`Reopen one from Window, or press the command palette's keys.`})}),MX=Object.fromEntries(tW.map(({id:e,title:t,Body:n})=>[e,()=>(0,G.jsxs)(`div`,{className:TX.body,children:[(0,G.jsx)(`h2`,{className:TX.heading,children:t}),(0,G.jsx)(n,{})]})])),NX={name:`ork`,className:TX.dock??``,gap:kX,dndOverlayMounting:`relative`,dndPanelOverlay:`group`,dndTabIndicator:`line`},PX=({workspace:e})=>{let t=(0,V.useCallback)(({api:t})=>{e.attach(t)},[e]);return(0,V.useEffect)(()=>()=>{e.detach()},[e]),(0,G.jsx)(hX,{announcer:({message:t})=>{e.announceFromDock(t)},components:MX,defaultTabComponent:AX,disableTabsOverflowList:!0,onReady:t,rightHeaderActionsComponent:OX,theme:NX,watermarkComponent:jX})},FX=`(min-width: 64rem)`,IX=(e,t,n)=>{let r=e?.panels??[],i=e?.activePanel?.id;return{wide:n,open:tW.map(e=>e.id).filter(e=>r.some(t=>t.id===e)),minimized:t.minimized.map(e=>e.id),folded:t.folded,active:i!==void 0&&nW(i)?i:null,floating:e?.activePanel?.group.api.location.type===`floating`,maximized:e?.hasMaximizedGroup()??!1}},LX=(e,t)=>JSON.stringify(e)===JSON.stringify(t),RX=e=>`stack-${e}`,zX=e=>`rail-${e}`,BX=e=>{document.querySelector(`#${e}`)?.focus()},VX=({workspace:e})=>{let{minimized:t}=ab(e.view);return t.length===0?null:(0,G.jsx)(`nav`,{"aria-label":`Minimized panels`,className:kT.rail,children:t.map(t=>{let{title:n,Icon:r}=rW(t);return(0,G.jsx)(cb,{id:zX(t),label:`Restore ${n}`,onClick:()=>{e.restore(t)},children:(0,G.jsx)(r,{})},t)})})},HX=({workspace:e})=>{let{folded:t}=ab(e.view);return(0,G.jsx)(`div`,{className:kT.stack,children:tW.map(({id:n,title:r,Icon:i,Body:a})=>{let o=!t.includes(n),s=`${RX(n)}-body`;return(0,G.jsxs)(`section`,{"aria-labelledby":RX(n),className:kT.stacked,children:[(0,G.jsx)(`h2`,{className:kT.stackedHeading,children:(0,G.jsxs)(`button`,{"aria-controls":o?s:void 0,"aria-expanded":o,className:kT.stackedButton,id:RX(n),onClick:()=>{e.toggleFold(n)},type:`button`,children:[o?(0,G.jsx)(Xv,{}):(0,G.jsx)(Zv,{}),(0,G.jsx)(i,{}),r]})}),o?(0,G.jsx)(`div`,{className:kT.stackedBody,id:s,children:(0,G.jsx)(a,{})}):null]},n)})})},UX=e=>{(0,V.useEffect)(()=>{let t=window.matchMedia(FX),n=()=>{e.setWide(t.matches)};return n(),t.addEventListener(`change`,n),()=>{t.removeEventListener(`change`,n)}},[e])},WX=({workspace:e})=>{let{wide:t}=ab(e.view);return UX(e),(0,G.jsx)(`main`,{className:kT.middle,children:t?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(VX,{workspace:e}),(0,G.jsx)(`div`,{className:kT.dockArea,children:(0,G.jsx)(PX,{workspace:e})})]}):(0,G.jsx)(HX,{workspace:e})})},GX=`ork-new-version-action`,KX=(e,t,n)=>e?.version===t&&n-Date.parse(e.at)<864e5,qX=(e,t,n)=>{let{job:r}=e;if(r!==null)return r.state===`running`?{kind:`running`,latest:r.latest}:KX(t,r.latest,n)?null:r.state===`succeeded`?{kind:`installed`,latest:r.latest,current:e.current}:{kind:`failed`,latest:r.latest,code:r.code??1}},JX=({info:e,connection:t,pageVersion:n,dismissed:r,now:i})=>{let{server:a}=t;if(t.link!==`open`||a===null||`error`in a)return null;if(n!==null&&a.version!==n)return{kind:`pageOlder`,page:n,server:a.version};if(e===null)return null;let o=qX(e,r,i);if(o!==void 0)return o;let{newer:s,releaseNotes:c}=e;return s===null||c===null||KX(r,s,i)?null:{kind:`newer`,newer:s,current:e.current,releaseNotes:c}},YX=e=>e===null?`none`:`${e.kind}:${`newer`in e?e.newer:`latest`in e?e.latest:e.server}`,XX=e=>e?.kind===`newer`?`Ork ${e.newer} is out. Upgrade… is above the panels.`:e?.kind===`installed`?`Ork ${e.latest} is installed; restart \`ork ui\` to use it.`:e?.kind===`pageOlder`?`This page is from an older Ork. Reload to use ${e.server}.`:null,ZX=e=>e.kind===`newer`?e.newer:e.kind===`installed`||e.kind===`failed`?e.latest:null,QX={slot:`_slot_s34lg_8`,banner:`_banner_s34lg_14`,icon:`_icon_s34lg_43`,line:`_line_s34lg_52`,version:`_version_s34lg_59`,link:`_link_s34lg_71`,spacer:`_spacer_s34lg_82`,facts:`_facts_s34lg_86`,factName:`_factName_s34lg_99`,factValue:`_factValue_s34lg_114`,adviceWords:`_adviceWords_s34lg_125`,note:`_note_s34lg_131`,message:`_message_s34lg_142`,alert:`_alert_s34lg_149`,alertIcon:`_alertIcon_s34lg_168`,heading:`_heading_s34lg_175`,glyph:`_glyph_s34lg_189`,clock:`_clock_s34lg_200`,foot:`_foot_s34lg_210`,actions:`_actions_s34lg_220`},$X=({latest:e,current:t})=>(0,G.jsxs)(`p`,{className:QX.line,children:[`Ork`,` `,(0,G.jsx)(`span`,{className:QX.version,"data-new":``,children:e}),` `,`is out (you have `,(0,G.jsx)(`span`,{className:QX.version,children:t}),`).`]}),eZ=({url:e,version:t,children:n})=>(0,G.jsxs)(`a`,{className:QX.link,href:e,rel:`noreferrer`,target:`_blank`,children:[n,t===void 0?null:(0,G.jsx)(zw,{children:` in ${t}`}),(0,G.jsx)(Sy,{}),(0,G.jsx)(zw,{children:` (opens in a new tab)`})]}),tZ=8,nZ=({ids:e})=>{if(e.length===0)return null;let t=e.slice(0,tZ).map(e=>`\`${e.slice(0,8)}\``),n=e.length-tZ,r=n>0?`${t.join(`, `)} and ${String(n)} more`:t.join(`, `);return(0,G.jsxs)(`p`,{className:QX.alert,"data-tone":`note`,children:[(0,G.jsx)(`span`,{className:QX.alertIcon,children:(0,G.jsx)(yy,{})}),(0,G.jsx)(`span`,{children:(0,G.jsx)(Wg,{text:`Running now: ${r}. Their next sessions would start from the new install; upgrading after they finish is safer.`})})]})},rZ=()=>{let e=document.activeElement;return e===null||e===document.body||e.getAttribute(`role`)===`dialog`},iZ=({tone:e,text:t,ref:n})=>{let r=(0,V.useRef)(null),i=n??r;return(0,V.useLayoutEffect)(()=>{i.current?.focus()},[i]),(0,V.useEffect)(()=>{let e=requestAnimationFrame(()=>{e=requestAnimationFrame(()=>{rZ()&&i.current?.focus()})});return()=>{cancelAnimationFrame(e)}},[i]),(0,G.jsxs)(`h3`,{className:QX.heading,ref:i,tabIndex:-1,children:[e===void 0?null:(0,G.jsx)(`span`,{className:QX.glyph,"data-tone":e,children:e===`succeeded`?(0,G.jsx)(aD,{}):(0,G.jsx)(cD,{})}),(0,G.jsx)(`span`,{children:(0,G.jsx)(Wg,{text:t})})]})},aZ=({since:e})=>{let t=sz(!0),n=Math.max(0,Math.floor((t-e)/1e3));return(0,G.jsx)(`span`,{"aria-hidden":`true`,className:QX.clock,children:`${String(n)} s`})},oZ=({text:e,icon:t=!1})=>e===null?null:(0,G.jsxs)(`p`,{className:QX.alert,role:`alert`,children:[t?(0,G.jsx)(yy,{}):null,(0,G.jsx)(`span`,{children:(0,G.jsx)(Wg,{text:e})})]}),sZ=({why:e,id:t})=>(0,G.jsx)(`output`,{className:QX.note,id:t,children:(0,G.jsx)(Wg,{text:e??``})}),cZ=({note:e,children:t})=>(0,G.jsxs)(`div`,{className:QX.foot,children:[e===void 0?null:(0,G.jsx)(`p`,{className:QX.note,children:(0,G.jsx)(Wg,{text:e})}),(0,G.jsx)(`div`,{className:QX.actions,children:t})]}),lZ=`Dismissed for a day. Upgrade Ork… is in Commands.`,uZ=(e,t,n,r)=>{let i=(0,V.useRef)(null),a=YX(e);(0,V.useEffect)(()=>{if(!t)return;let o=i.current;if(i.current=a,o===null||o===a||n)return;let s=XX(e);s!==null&&r.announce(s)},[e,a,t,n,r])},dZ=()=>{let[e,t]=(0,V.useState)(Date.now);return(0,V.useEffect)(()=>{let e=setInterval(()=>{t(Date.now())},6e4);return()=>{clearInterval(e)}},[]),e},fZ=()=>{window.location.reload()},pZ={newer:{label:`Upgrade…`,primary:!0,opens:`ask`},running:{label:`Show output`,primary:!1,opens:`job`},failed:{label:`Show output`,primary:!1,opens:`job`},installed:{label:`Restart…`,primary:!0,opens:`job`},pageOlder:{label:`Reload`,primary:!0,opens:null}},mZ=e=>e.kind===`running`?`Upgrading Ork to ${e.latest}…`:e.kind===`failed`?`The upgrade to ${e.latest} did not finish: exit ${String(e.code)}.`:e.kind===`installed`?`Ork ${e.latest} is installed. \`ork ui\` still runs ${e.current} until it restarts.`:`This page is from Ork ${e.page}; \`ork ui\` now runs ${e.server}.`,hZ=({banner:e,onOpen:t})=>{let n=pZ[e.kind];return(0,G.jsxs)(G.Fragment,{children:[e.kind===`newer`?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)($X,{current:e.current,latest:e.newer}),(0,G.jsx)(eZ,{url:e.releaseNotes,version:e.newer,children:`What changed`})]}):(0,G.jsx)(`p`,{className:QX.line,children:(0,G.jsx)(Wg,{text:mZ(e)})}),(0,G.jsx)(`span`,{className:QX.spacer}),(0,G.jsx)(q,{cli:e.kind===`newer`?`ork upgrade`:void 0,id:GX,onClick:()=>{n.opens===null?fZ():t(n.opens)},variant:n.primary?`primary`:`default`,children:n.label})]})},gZ=({workspace:e})=>{let{version:t,connection:n,preferences:r}=qy(),i=ab(t.info),a=ab(n),o=ab(r.value),s=ab(t.dialog),c=dZ(),l=JX({info:i,connection:a,pageVersion:t.pageVersion,dismissed:o.updateDismissed,now:c});uZ(l,i!==null&&a.server!==null,s!==null,e);let u=l===null?null:ZX(l);return(0,G.jsx)(`div`,{className:QX.slot,children:l===null?null:(0,G.jsxs)(`section`,{"aria-label":`New version`,className:QX.banner,children:[(0,G.jsx)(`span`,{className:QX.icon,children:(0,G.jsx)(zy,{})}),(0,G.jsx)(hZ,{banner:l,onOpen:t.openDialog}),u===null?null:(0,G.jsx)(cb,{label:`Dismiss for a day`,onClick:()=>{r.update({updateDismissed:{version:u,at:new Date().toISOString()}}),e.announce(lZ),e.focusPanels()},children:(0,G.jsx)(Jv,{})})]})})},_Z=e=>e===null?`Asking the npm registry for the latest version…`:`Asking the registry at \`${e}\` for the latest version…`,vZ=({plan:e})=>(0,G.jsxs)(`dl`,{className:QX.facts,children:[(0,G.jsx)(`dt`,{className:QX.factName,children:`Installed with`}),(0,G.jsx)(`dd`,{className:QX.factValue,children:e.installer?.label??`Ork couldn't tell`}),e.kind===`command`?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`dt`,{className:QX.factName,children:`Command`}),(0,G.jsx)(`dd`,{className:QX.factValue,children:(0,G.jsx)(`section`,{"aria-label":`Command to run`,children:(0,G.jsx)(YS,{command:e.command.join(` `)})})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`dt`,{className:QX.factName,children:`What to do`}),(0,G.jsxs)(`dd`,{className:QX.factValue,children:[(0,G.jsx)(`p`,{className:QX.adviceWords,children:(0,G.jsx)(Wg,{text:e.words})}),e.commands.map(e=>(0,G.jsx)(YS,{command:e},e))]})]})]}),yZ=({plan:e})=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)($X,{current:e.current,latest:e.latest}),(0,G.jsxs)(`p`,{className:QX.message,children:[`What changed:`,` `,(0,G.jsx)(eZ,{url:e.releaseNotes,children:e.releaseNotes})]}),(0,G.jsx)(vZ,{plan:e}),e.kind===`advice`?(0,G.jsx)(`p`,{className:QX.note,children:`Ork runs only a package manager's own command from here; this one is yours to run.`}):null,(0,G.jsx)(nZ,{ids:e.running}),(0,G.jsx)(`p`,{className:QX.note,children:`The same, in a terminal:`}),(0,G.jsx)(YS,{command:`ork upgrade`})]}),bZ=({step:e,registry:t})=>e.step===`plan`?(0,G.jsx)(yZ,{plan:e.plan}):e.step===`latest`?(0,G.jsx)(iZ,{text:`Ork ${e.current} is the latest version.`,tone:`succeeded`}):e.step===`unreachable`?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(oZ,{icon:!0,text:e.words}),(0,G.jsx)(`p`,{className:QX.message,children:`Nothing was changed.`})]}):(0,G.jsx)(`section`,{"aria-busy":`true`,"aria-label":`Asking`,className:QX.message,children:(0,G.jsx)(Wg,{text:_Z(t)})}),xZ=({step:e,registry:t,first:n,onClose:r,onAsk:i,onUpgrade:a})=>{let o=(0,V.useId)();(0,V.useEffect)(()=>{rZ()&&n.current?.focus()},[n]);let s=e.step===`plan`&&e.plan.kind===`command`,c=e.step===`checking`||s,l=e.step===`plan`&&e.starting;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(bZ,{registry:t,step:e}),(0,G.jsx)(oZ,{text:e.step===`plan`?e.refusal:null}),(0,G.jsx)(sZ,{id:o,why:e.step===`checking`?`Asking the registry…`:null}),(0,G.jsxs)(cZ,{note:c?`It runs on this machine as you.`:void 0,children:[e.step===`unreachable`?(0,G.jsx)(q,{onClick:()=>{n.current?.focus(),i()},variant:`ghost`,children:`Try again`},`again`):null,(0,G.jsx)(q,{disabled:l,focusableWhenDisabled:!0,onClick:r,ref:n,variant:c?`ghost`:`default`,children:c?`Cancel`:`Close`},`close`),c?(0,G.jsx)(q,{"aria-describedby":o,disabled:!s||l,focusableWhenDisabled:!0,onClick:a,variant:`primary`,children:e.step===`plan`?`Upgrade to ${e.plan.latest}`:`Upgrade`},`upgrade`):null]})]})},SZ=({step:e,port:t})=>{let n=(0,V.useId)();return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(iZ,{text:"Restarting `ork ui`…"}),(0,G.jsx)(`p`,{className:QX.message,children:e.step===`back`?`Ork ${e.version} is up. Reloading…`:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Wg,{text:`Waiting for \`ork ui\` to come back on port ${t}. Runs keep running.`}),` `,(0,G.jsx)(aZ,{since:e.since})]})}),(0,G.jsx)(sZ,{id:n,why:"It closes once `ork ui` is back."}),(0,G.jsx)(cZ,{children:(0,G.jsx)(q,{"aria-describedby":n,disabled:!0,focusableWhenDisabled:!0,children:`Close`})})]})},CZ=({step:e,port:t,onClose:n,onKeepWaiting:r,onReload:i})=>{if(e.step===`restarting`||e.step===`back`)return(0,G.jsx)(SZ,{port:t,step:e});let a=wZ(e,t);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(iZ,{text:a.heading,tone:`failed`}),(0,G.jsx)(oZ,{text:a.words}),(0,G.jsx)(YS,{command:a.command}),(0,G.jsxs)(cZ,{children:[e.step===`gaveUp`?(0,G.jsx)(q,{onClick:r,children:`Keep waiting`}):(0,G.jsx)(q,{onClick:n,children:`Close`}),e.step===`signedOut`?null:(0,G.jsx)(q,{onClick:i,variant:`primary`,children:`Reload`})]})]})},wZ=(e,t)=>e.step===`gaveUp`?{heading:"`ork ui` didn't come back",words:`It wasn't back on port ${t} after 60 seconds. Its terminal says why. Start it again there:`,command:`ork ui --port ${t}`}:e.step===`oldVersion`?{heading:`\`ork ui\` is back on ${e.version}`,words:`\`ork ui\` is back, but it runs ${e.version}: the \`ork\` it started is not the one that was upgraded. Another \`ork\` may come first on your PATH.`,command:`ork upgrade`}:{heading:`This page isn't signed in`,words:"`ork ui` is back, but this page isn't signed in to it. Open it again from a terminal:",command:`ork ui`},TZ={well:`_well_14iu2_8`},EZ=32,DZ=({label:e,text:t,ref:n})=>{let r=(0,V.useRef)(null),i=n??r,a=(0,V.useRef)(!0);return(0,V.useLayoutEffect)(()=>{let e=i.current;e!==null&&a.current&&(e.scrollTop=e.scrollHeight)}),(0,G.jsx)(`section`,{"aria-label":e,className:TZ.well,onScroll:()=>{let e=i.current;e!==null&&(a.current=e.scrollHeight-e.scrollTop-e.clientHeight<EZ)},ref:i,tabIndex:0,children:t})},OZ="Lost the output from `ork ui`. The command may still be running; reconnecting…",kZ=e=>e.command[0]??`it`,AZ=(e,t)=>{let n=t.split(`
74
+ `).findLast(e=>e.startsWith(`Could not run`));return e.code===127&&n!==void 0?n:`\`${kZ(e)}\` failed (exit ${String(e.code??1)}); the upgrade did not finish.`},jZ=({job:e,lost:t,output:n})=>{let r=(0,V.useId)();(0,V.useEffect)(()=>{n.current?.focus()},[n]);let i=kZ(e);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`p`,{className:QX.message,children:[(0,G.jsx)(Wg,{text:`Running \`${i}\`…`}),` `,(0,G.jsx)(aZ,{since:Date.parse(e.startedAt)})]}),(0,G.jsx)(YS,{command:e.command.join(` `)}),t?(0,G.jsx)(oZ,{text:OZ}):null,(0,G.jsx)(sZ,{id:r,why:`It closes when ${i} ends; closing now would hide how it ended.`}),(0,G.jsx)(cZ,{children:(0,G.jsx)(q,{"aria-describedby":r,disabled:!0,focusableWhenDisabled:!0,children:`Close`})})]})},MZ=({step:e,text:t,lost:n,current:r,port:i,output:a,heading:o,onClose:s,onAsk:c,onRestart:l})=>{let{job:u}=e,d=`Output of ${kZ(u)}`;if(e.step===`running`)return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(DZ,{label:d,ref:a,text:t}),(0,G.jsx)(jZ,{job:u,lost:n,output:a})]});let f=(0,G.jsx)(DZ,{label:d,text:t});return e.step===`failed`?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(iZ,{ref:o,text:`The upgrade did not finish`,tone:`failed`}),(0,G.jsx)(oZ,{text:`${AZ(u,t)} Nothing was restarted; \`ork ui\` still runs ${r}.`}),f,(0,G.jsx)(`p`,{className:QX.note,children:`To run it in a terminal yourself:`}),(0,G.jsx)(YS,{command:u.command.join(` `)}),(0,G.jsxs)(cZ,{children:[(0,G.jsx)(q,{onClick:s,children:`Close`}),(0,G.jsx)(q,{onClick:c,variant:`ghost`,children:`Try again`})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(iZ,{ref:o,text:`Upgraded to ${u.latest}`,tone:`succeeded`}),(0,G.jsx)(`p`,{className:QX.message,children:(0,G.jsx)(Wg,{text:`Ork ${u.latest} is installed. This page and \`ork ui\` still run ${r} until \`ork ui\` restarts. Restart stops it and starts it again on port ${i} with the same options; runs keep running, and the page reloads itself when it's back.`})}),f,(0,G.jsx)(oZ,{text:e.refusal}),(0,G.jsxs)(cZ,{children:[(0,G.jsx)(q,{onClick:s,variant:`ghost`,children:`Later`}),(0,G.jsxs)(q,{cli:`ork ui --port ${i}`,disabled:e.asking,focusableWhenDisabled:!0,onClick:l,tip:"Stops `ork ui` and starts the new one",variant:`primary`,children:[(0,G.jsx)(By,{}),`Restart`]})]})]})},NZ={pollMs:1e3,waitMs:6e4,reloadMs:1500},PZ=async(e,t,n)=>{let{job:r,port:i,pid:a,since:o}=t,s=await e.call(`health`);if(s.ok&&s.data.pid!==a){let{version:e}=s.data;return e===r.latest?{step:`back`,version:e}:{step:`oldVersion`,job:r,version:e}}return!s.ok&&s.status===401?{step:`signedOut`}:Date.now()-o>=n?{step:`gaveUp`,job:r,port:i,pid:a}:null},FZ=({client:e,step:t,setStep:n,announce:r,reload:i,timing:a})=>{let o=(0,V.useRef)({announce:r,reload:i});(0,V.useEffect)(()=>{o.current={announce:r,reload:i}}),(0,V.useEffect)(()=>{let r=t.step===`restarting`?t:null,i=!1,s=async t=>{let r=await PZ(e,t,a.waitMs);i||r===null||(i=!0,n(r),r.step===`gaveUp`&&o.current.announce("`ork ui` didn't come back."),r.step===`back`&&(o.current.announce(`Ork ${r.version} is up. Reloading…`),setTimeout(()=>{o.current.reload()},a.reloadMs)))},c=r===null?void 0:setInterval(()=>{s(r)},a.pollMs);return()=>{i=!0,clearInterval(c)}},[e,t,n,a])},IZ=e=>new EventSource(e),LZ=2,RZ=1e3,zZ=15e3,BZ=e=>{try{return JSON.parse(e)}catch{return}},VZ=({url:e,open:t,on:n,onStatus:r,onFailure:i})=>{let a=null,o=null,s=RZ,c=null,l=e=>{e!==c&&(c=e,r(e))},u=()=>{let r=t(e());a=r,r.addEventListener(`open`,()=>{s=RZ,l(`open`)}),r.addEventListener(`error`,()=>{l(`lost`),i?.(),r.readyState===LZ&&(r.close(),o=setTimeout(u,s),s=Math.min(s*2,zZ))});let c=Object.entries(n);for(let[e,t]of c)r.addEventListener(e,e=>{let n=BZ(e.data);n!==void 0&&t(n)})};return l(`connecting`),u(),{close:()=>{o!==null&&clearTimeout(o),o=null,a?.close(),a=null}}},HZ=e=>e===null?`Could not reach the npm registry to look for a new version.`:`Could not reach the registry at \`${e}\` to look for a new version.`,UZ=(e,t)=>e.kind===`unreachable`?{step:`unreachable`,words:HZ(t)}:e.kind===`latest`?{step:`latest`,current:e.current}:{step:`plan`,plan:e,refusal:null,starting:!1},WZ=e=>e.kind===`command`?`Ork ${e.latest} is out. The plan is below.`:`Ork ${e.latest} is out. Ork can't run this upgrade from here; what to do is below.`,GZ=e=>e.state===`running`?{step:`running`,job:e}:e.state===`succeeded`?{step:`done`,job:e,refusal:null,asking:!1}:{step:`failed`,job:e},KZ=({client:e,open:t,job:n,registry:r,announce:i,onAsked:a})=>{let[o,s]=(0,V.useState)(()=>n===null?{step:`checking`}:GZ(n)),[c,l]=(0,V.useState)([]),[u,d]=(0,V.useState)(!1),f=(0,V.useRef)(null),p=(0,V.useRef)(0),m=(0,V.useRef)({announce:i,onAsked:a,registry:r});(0,V.useEffect)(()=>{m.current={announce:i,onAsked:a,registry:r}});let h=(0,V.useCallback)(e=>{f.current?.close(),p.current=0,l([]);let n=VZ({url:()=>`${UA.upgrade}?after=${String(p.current)}`,open:t,on:{output:e=>{e.seq<=p.current||(p.current=e.seq,l(t=>[...t,e]))},end:t=>{n.close(),d(!1),s(GZ({...e,state:t.state,code:t.code})),t.state===`succeeded`&&m.current.announce(`Upgraded to ${e.latest}.`)}},onStatus:e=>{d(e===`lost`)}});f.current=n},[t]),g=(0,V.useCallback)(async()=>{s({step:`checking`});let t=await e.call(`upgradePlan`);m.current.onAsked();let n=t.ok?UZ(t.data,m.current.registry):{step:`unreachable`,words:t.error};s(n),n.step===`plan`&&m.current.announce(WZ(n.plan))},[e]),_=(0,V.useRef)(n);(0,V.useEffect)(()=>{let e=_.current;return e===null?g():h(e),()=>{f.current?.close()}},[g,h]);let v=async(t,n)=>{let r=await e.call(`version`),i=r.ok?r.data.job:null;if(i?.state===`running`){m.current.announce(n),s({step:`running`,job:i}),h(i);return}let a=await e.call(`upgradePlan`);if(m.current.onAsked(),!a.ok){s({step:`plan`,plan:t,refusal:n,starting:!1});return}let o=UZ(a.data,m.current.registry);s(o.step===`plan`?{...o,refusal:n}:o)},y=async t=>{s({step:`plan`,plan:t,refusal:null,starting:!0});let n=await e.call(`upgrade`,{body:{planId:t.planId}});n.ok?(m.current.announce(`Upgrading Ork to ${t.latest}.`),s({step:`running`,job:n.data.job}),h(n.data.job)):n.status===409?await v(t,n.error):s({step:`plan`,plan:t,refusal:n.error,starting:!1})},b=async t=>{s({step:`done`,job:t,refusal:null,asking:!0});let n=await e.call(`restart`);s(n.ok?{step:`restarting`,job:t,port:n.data.port,pid:n.data.pid,since:Date.now()}:{step:`done`,job:t,refusal:n.error,asking:!1})};return{step:o,setStep:s,text:c.map(e=>e.text).join(`
75
+ `),lost:u,ask:()=>{g()},upgrade:()=>{o.step===`plan`&&o.plan.kind===`command`&&y(o.plan)},restart:()=>{o.step===`done`&&b(o.job)},keepWaiting:()=>{o.step===`gaveUp`&&s({...o,step:`restarting`,since:Date.now()})}}},qZ=e=>[`checking`,`unreachable`,`latest`,`plan`].includes(e.step),JZ=e=>[`running`,`done`,`failed`].includes(e.step),YZ=e=>!qZ(e)&&!JZ(e),XZ=({starts:e,timing:t,reload:n,onStep:r,onClose:i})=>{let{version:a,client:o}=qy(),s=(0,V.use)(ZM),c=ab(a.info),l=ab(a.dialog),u=(0,V.useCallback)(e=>s?.announce(e),[s]),d=KZ({client:o,open:a.open,job:l===`job`?c?.job??null:null,registry:c?.registry??null,announce:u,onAsked:()=>void a.refresh()}),{step:f,setStep:p}=d;FZ({client:o,step:f,setStep:p,announce:u,reload:n,timing:t}),(0,V.useEffect)(()=>{r(f)},[f,r]);let m=f.step===`restarting`||f.step===`back`;(0,V.useEffect)(()=>(a.restarting.setValue(m),()=>{a.restarting.setValue(!1)}),[a,m]);let h=window.location.port;return qZ(f)?(0,G.jsx)(xZ,{first:e.first,onAsk:d.ask,onClose:i,onUpgrade:d.upgrade,registry:c?.registry??null,step:f}):JZ(f)?(0,G.jsx)(MZ,{current:c?.current??``,heading:e.heading,lost:d.lost,onAsk:d.ask,onClose:i,onRestart:d.restart,output:e.output,port:h,step:f,text:d.text}):YZ(f)?(0,G.jsx)(CZ,{onClose:i,onKeepWaiting:d.keepWaiting,onReload:n,port:h,step:f}):null},ZZ=()=>{window.location.reload()},QZ=e=>![`running`,`restarting`,`back`].includes(e.step)&&!(e.step===`plan`&&e.starting)&&!(e.step===`done`&&e.asking),$Z=`Upgrade Ork`,eQ=({timing:e=NZ,reload:t=ZZ})=>{let{version:n}=qy(),r=(0,V.use)(ZM),i=ab(n.dialog),a=ab(n.info),o=(0,V.useRef)(null),s=(0,V.useRef)(null),c=(0,V.useRef)(null),l=i===`job`&&a?.job?.state!==`running`,u=i===`job`?l?c:s:o,[d,f]=(0,V.useState)($Z),p=(0,V.useRef)({closable:!0,ran:!1}),m=(0,V.useCallback)(e=>{p.current={closable:QZ(e),ran:p.current.ran||`job`in e},f(t=>qZ(e)?$Z:`job`in e?`Upgrading Ork to ${e.job.latest}`:t)},[]),h=()=>{p.current.closable&&(p.current.ran||r?.announce(`Nothing was changed.`),p.current={closable:!0,ran:!1},f($Z),n.closeDialog())};return(0,G.jsx)(bC,{finalFocus:()=>{let e=document.querySelector(`#${GX}`);return e===null?(r?.focusPanels(),!1):e},initialFocus:u,onOpenChange:e=>{e||h()},open:i!==null,size:`wide`,title:d,children:(0,G.jsx)(XZ,{onClose:h,onStep:m,reload:t,starts:{first:o,output:s,heading:c},timing:e})})},tQ=({workspace:e})=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(gZ,{workspace:e}),(0,G.jsx)(eQ,{})]});function nQ(e){let{openOnInputClick:t=!1,value:n,defaultValue:r,onValueChange:i,mode:a=`list`,itemToStringValue:o,...s}=e,c=(a===`inline`||a===`both`)&&!e.readOnly,l=a===`inline`||a===`none`,u=n!==void 0,[d,f]=V.useState(r??``),[p,m]=V.useState(``);V.useEffect(()=>{(u||!c)&&m(``)},[n,u,c]);let h;h=c&&p!==``?p:u?n??``:d;let g=lx({locale:s.locale}),_=String((u?n:d)??``).trim(),v=l||s.filter===null?null:s.filter??g.contains;function y(e,t){m(``),u||f(e),i?.(e,t)}function b(t,n){e.onItemHighlighted?.(t,n),n.reason!==`pointer`&&m(c&&t!=null?Rb(t,o):``)}return(0,G.jsx)(_x,{...s,itemToStringLabel:o,openOnInputClick:t,selectionMode:`none`,fillInputOnItemPress:!0,filter:v,filterQuery:a===`both`?_:void 0,autoComplete:a,inputValue:h,defaultInputValue:r,onInputValueChange:y,onItemHighlighted:b})}var rQ=zS,iQ=[`Panels`,`Runs`,`Window`,`Layout`,`View`,`Ork`],aQ=`Needs a wider window.`,oQ=`No panel is active.`,sQ=[`left`,`right`,`up`,`down`],cQ={left:`narrower`,right:`wider`,up:`shorter`,down:`taller`},lQ=e=>e.wide?e.active===null?oQ:void 0:aQ,uQ=e=>tW.map((t,n)=>{let r={id:`go-${t.id}`,title:`Go to ${t.title}`,group:`Panels`,run:()=>{e.goTo(t.id)}},i=TT(n+1);return i!==void 0&&(r.shortcut=i),r}),dQ=e=>[{id:`run-workflow`,title:`Run workflow…`,group:`Runs`,run:()=>{e.runDialog.setValue(!0)}}],fQ=(e,t)=>{let n=lQ(t),r=t.active===null?`panel`:rW(t.active).title,i=n??(t.floating?`A floating panel cannot be maximized.`:void 0),a=n??(t.maximized?`Restore the panel first.`:void 0);return[{id:`minimize`,title:`Minimize ${r}`,group:`Window`,shortcut:CT.minimize,run:()=>{e.minimize()},disabled:n},{id:`maximize`,title:t.maximized?`Restore ${r}`:`Maximize ${r}`,group:`Window`,shortcut:CT.maximize,run:()=>{e.toggleMaximize()},disabled:i},{id:`float`,title:t.floating?`Dock ${r}`:`Float ${r}`,group:`Window`,shortcut:CT.float,run:()=>{e.toggleFloat()},disabled:n},{id:`close`,title:`Close ${r}`,group:`Window`,shortcut:CT.close,run:()=>{e.close()},disabled:n},...sQ.map(t=>({id:`resize-${t}`,title:`Make ${r} ${cQ[t]}`,group:`Window`,shortcut:CT.resize(t),run:()=>{e.resize(t)},disabled:a})),...sQ.map(t=>({id:`move-${t}`,title:`Move ${r} ${t}`,group:`Window`,shortcut:CT.move(t),run:()=>{e.move(t)},disabled:n}))]},pQ=(e,t)=>{let n=t.wide?void 0:aQ;return[{id:`next-group`,title:`Focus next panel group`,group:`Layout`,shortcut:CT.nextGroup,run:()=>{e.cycleGroup(1)},disabled:n},{id:`previous-group`,title:`Focus previous panel group`,group:`Layout`,shortcut:CT.previousGroup,run:()=>{e.cycleGroup(-1)},disabled:n},{id:`reset-layout`,title:`Reset layout`,group:`Layout`,run:()=>{e.resetLayout()}}]},mQ=[{theme:`system`,title:`Follow the system`},{theme:`dark`,title:`Dark`},{theme:`light`,title:`Light`}],hQ=[{density:`compact`,title:`Compact`},{density:`comfortable`,title:`Comfortable`}],gQ=(e,t,n)=>[...mQ.map(({theme:r,title:i})=>({id:`theme-${r}`,title:`Theme: ${i}`,group:`View`,run:()=>{t.update({theme:r}),e.announce(`Theme: ${i}.`)},disabled:n.theme===r?`This is the theme now.`:void 0})),...hQ.map(({density:r,title:i})=>({id:`density-${r}`,title:`Density: ${i}`,group:`View`,run:()=>{t.update({density:r}),e.announce(`Density: ${i}.`)},disabled:n.density===r?`This is the density now.`:void 0}))],_Q=e=>[{id:`upgrade-ork`,title:`Upgrade Ork…`,group:`Ork`,detail:`Asks the registry for a new version now.`,run:()=>{e.version.openDialog(`ask`)}}],vQ=(e,t,n,r)=>[...uQ(e),...dQ(n),...fQ(e,t),...pQ(e,t),...gQ(e,n.preferences,r),..._Q(n)],yQ={palette:`_palette_p3ocp_6`,input:`_input_p3ocp_45`,list:`_list_p3ocp_78`,group:`_group_p3ocp_88`,empty:`_empty_p3ocp_106`},bQ=e=>iQ.map(t=>({value:t,items:e.filter(e=>e.group===t).map(e=>({label:e.title,command:e}))})),xQ=({commands:e,onChoose:t})=>{let n=(0,V.useMemo)(()=>bQ(e),[e]),r=ET();return(0,G.jsxs)(nQ,{autoHighlight:`always`,inline:!0,items:n,keepHighlight:!0,open:!0,children:[(0,G.jsx)(Rx,{"aria-label":`Search commands`,className:yQ.input,placeholder:`Type a command`}),(0,G.jsx)(HS,{children:(0,G.jsx)(`p`,{className:yQ.empty,children:`No command matches.`})}),(0,G.jsx)(iS,{className:yQ.list,children:e=>(0,G.jsxs)(AS,{items:e.items,children:[(0,G.jsx)(jS,{className:yQ.group,children:e.value}),(0,G.jsx)(Jx,{children:e=>(0,G.jsxs)(rQ,{className:qg.item,disabled:e.command.disabled!==void 0,onClick:()=>{t(e.command)},value:e,children:[(0,G.jsx)(`span`,{children:e.label}),(e.command.disabled??e.command.detail)===void 0?null:(0,G.jsx)(`span`,{className:qg.itemDetail,children:e.command.disabled??e.command.detail}),e.command.shortcut===void 0?null:(0,G.jsx)(Kg,{keys:yT(e.command.shortcut,r)})]},e.command.id)})]},e.value)})]})},SQ=()=>(document.activeElement===null||document.activeElement===document.body)&&document.querySelector(`[data-modal]`)===null,CQ=e=>{requestAnimationFrame(()=>{requestAnimationFrame(e)})},wQ=({workspace:e,commands:t})=>{let n=ab(e.palette),r=(0,V.useRef)(null),i=(0,V.useRef)(!1),a=(0,V.useRef)(null);(0,V.useLayoutEffect)(()=>{n&&(i.current=!1,a.current=document.activeElement)},[n]);let o=t=>{e.palette.setValue(t)},s=()=>{if(!SQ())return;let t=a.current;t instanceof HTMLElement&&t.isConnected?t.focus():e.focusPanels()};return(0,G.jsx)(_C,{onOpenChange:o,onOpenChangeComplete:e=>{if(e)return;let t=r.current;r.current=null,t!==null&&(t.run(),CQ(s))},open:n,children:(0,G.jsxs)(hC,{children:[(0,G.jsx)(aC,{className:vC.backdrop}),(0,G.jsx)(mC,{"aria-label":`Command palette`,"aria-modal":`true`,className:yQ.palette,finalFocus:()=>!i.current,children:(0,G.jsx)(xQ,{commands:t,onChoose:e=>{r.current=e,i.current=!0,o(!1)}})})]})})},TQ=e=>{let t=Yy.create(null),n=Yy.create(null),r=Yy.create(null),i=Yy.create(null),a=Yy.create([]),o=Promise.resolve(),s=(t,n)=>{e.chooseBuilder({project:t.project,workflow:t.name,node:n,draft:r.getValue()?.draft??!1})};return{project:t,opened:n,view:r,selected:i,history:a,inTurn:e=>{let t=o.then(e,e);return o=t.catch(()=>null),t},show:(t,o)=>{let c=n.getValue();n.setValue(t),r.setValue(o),i.setValue(null),a.setValue([]),t===null?e.builderClosed():(t!==c&&s(t,null),o!==null&&e.builderChanged(t.project,t.name,o.draft))},update:t=>{r.setValue(t);let i=n.getValue();i!==null&&e.builderChanged(i.project,i.name,t.draft)},select:e=>{i.setValue(e);let t=n.getValue();t!==null&&s(t,e)}}},EQ=(e,t,n)=>e?.kind===`builder`&&e.project===t&&e.workflow===n,DQ=()=>{let e=Yy.create(null),t=t=>{e.setValue(t)},n=n=>{let r=e.getValue();t({kind:`builder`,...n,revision:EQ(r,n.project,n.workflow)?r.revision:0})},r=(n,r,i)=>{let a=e.getValue();EQ(a,n,r)&&t({...a,draft:i,revision:a.revision+1})},i=()=>{e.getValue()?.kind===`builder`&&t(null)};return{target:e,chooseBuilder:n,builderChanged:r,builderClosed:i,builder:TQ({chooseBuilder:n,builderChanged:r,builderClosed:i}),chooseRun:(e,n)=>{t(e===null?null:{kind:`run`,run:e,node:n})}}},OQ=e=>{let t=Yy.create([]),n=new Map,r=async n=>{let r=await e.call(`decision`,{params:{id:n.id}}),i=r.ok?r.data:n;t.setValue([i,...t.getValue()].slice(0,20))};return{settled:t,saw:e=>{let t=new Map((e??[]).map(e=>[e.id,e]));for(let[e,i]of n)t.has(e)||r(i);n=t}}},kQ=1e3,AQ=({runId:e,client:t,open:n})=>{let r=Yy.create({...dL,tail:[],link:`idle`,ended:null,paging:!1,error:null}),i=null,a=!1,o=!1,s=0,c=[],l=null,u=null,d=e=>{r.setValue({...r.getValue(),...e})},f=()=>c.at(-1)?.seq??r.getValue().latest,p=async(n,i)=>{d({paging:!0});let a=await t.call(`events`,{params:{id:e},query:n});return a.ok?(d({...i(r.getValue(),a.data),...n.last===void 0?{}:{tail:a.data},paging:!1,error:null}),!0):(d({paging:!1,error:a.error}),!1)},m=async()=>{let e=r.getValue();e.following&&hL(e)&&!e.paging&&await p({after:pL(e),limit:500},xL)&&await m()},h=()=>{if(l!==null&&clearTimeout(l),l=null,c.length===0)return;let e=c;c=[];let t=r.getValue(),n=t.tail.at(-1)?.seq??0;d({...yL(t,e),tail:[...t.tail,...e.filter(e=>e.seq>n)].slice(-500)}),m()},g=()=>{i?.close(),i=null},_=()=>{i=VZ({url:()=>`${WA(UA.run,{id:e})}?after=${String(f())}`,open:n,on:{"run-event":e=>{e.seq<=f()||(c.push(e),l??=setTimeout(h,50))},end:({reason:e})=>{h(),g(),o=!1,d({link:`ended`,ended:e})}},onStatus:e=>{d({link:e===`open`?`live`:e===`lost`?`lost`:`loading`})}})},v=async()=>{let e=s;d({link:`loading`});let t=await p({last:500},bL);e===s&&(t?(a=!0,_()):(d({link:`lost`}),u=setTimeout(()=>void v(),kQ)))};return{state:r,start:()=>{o||(o=!0,s+=1,d({ended:null}),a?_():v())},stop:()=>{o=!1,s+=1,u!==null&&clearTimeout(u),u=null,h(),g(),r.getValue().link!==`ended`&&d({link:`idle`})},loadOlder:async()=>{let e=r.getValue();mL(e)&&!e.paging&&await p(CL(e),SL)},loadNewer:async()=>{let e=r.getValue();hL(e)&&!e.paging&&await p({after:pL(e),limit:500},xL)},hold:()=>{d({following:!1})},follow:async()=>{let e=r.getValue();e.paging||(hL(e)?await p({last:500},bL):d({following:!0}),await m())}}},jQ=({runId:e,client:t,feed:n})=>{let r=Yy.create({graph:null,tree:null,links:[],error:null}),i=e=>{r.setValue({...r.getValue(),...e})},a=0,o=async()=>{a+=1;let n=a,[o,s]=await Promise.all([t.call(`tree`,{params:{id:e}}),t.call(`links`,{query:{run:e}})]);n===a&&(o.ok?i({tree:o.data,links:s.ok?s.data:r.getValue().links,error:null}):i({error:o.error}))},s=async()=>{let n=await t.call(`graph`,{params:{id:e}});n.ok?i({graph:n.data}):i({error:n.error})};return{state:r,start:()=>{let e=null,t=n.state.getValue().latest;s(),o();let r=n.state.subscribe(({latest:n})=>{n!==t&&(t=n,e??=setTimeout(()=>{e=null,o()},250))});return()=>{r(),e!==null&&clearTimeout(e),a+=1}}}},MQ=e=>e.live===`running`||e.live===`paused`,NQ=({client:e,open:t})=>{let n=new Map,r=r=>{let i=n.get(r)??{feed:AQ({runId:r,client:e,open:t}),retained:0};return n.set(r,i),i},i=()=>{let e=[...n].filter(([,e])=>e.retained===0);for(let[t]of e.slice(0,-4))n.delete(t)};return{reopenResumed:e=>{for(let t of e??[]){let e=n.get(t.id);e!==void 0&&e.retained>0&&MQ(t)&&e.feed.state.getValue().link===`ended`&&e.feed.start()}},feedOf:e=>r(e).feed,retainRun:e=>{let t=r(e);return t.retained+=1,t.feed.start(),()=>{--t.retained,t.retained===0&&(t.feed.stop(),n.delete(e),n.set(e,t),i())}},watchRun:t=>jQ({runId:t,client:e,feed:r(t).feed})}},PQ=`ork.notifications.read`,FQ=ss({before:Co().nullable(),ids:as(Co())}),IQ=e=>{if(e.live===`running`)return null;let t=e.live===`paused`||e.live===`crashed`;return{id:`run:${e.id}:${e.live}`,kind:`run`,runId:e.id,status:e.live,title:`Run ${e.id} of ${e.workflow} ${_D(e.live)}.`,at:e.finishedAt??e.startedAt,pending:t}},LQ=e=>({id:`decision:${e.id}`,kind:`decision`,runId:e.runId,node:e.node,status:`waiting`,title:`${e.node} in run ${e.runId} asks: ${e.question}`,at:e.openedAt,pending:!0}),RQ=(e,t)=>[...t.map(e=>LQ(e)),...e.flatMap(e=>IQ(e)??[])].toSorted((e,t)=>t.at.localeCompare(e.at)),zQ=(e,t)=>t.ids.includes(e.id)||!e.pending&&t.before!==null&&e.at<=t.before,BQ=({runs:e,decisions:t,storage:n,now:r=()=>new Date().toISOString()})=>{let i=new Zy({before:null,ids:[]},{key:PQ,storage:n});FQ.safeParse(i.getValue()).success||i.reset();let a=Yy.create({items:[],unread:0}),o=null,s=new Set,c=[],l=()=>{let e=i.getValue(),t=c.map(t=>({...t,unread:!zQ(t,e)}));a.setValue({items:t,unread:t.filter(({unread:e})=>e).length})},u=()=>{let n=e.getValue(),a=t.getValue();if(n===null||a===null)return;c=RQ(n,a),i.getValue().before===null&&i.setValue({...i.getValue(),before:r()});let u=o,d=u===null?[]:c.filter(({id:e})=>!u.has(e));if(o=new Set(c.map(({id:e})=>e)),l(),d.length>0)for(let e of s)e(d)};return{view:a,start:()=>{let n=e.subscribe(u),r=t.subscribe(u);return u(),()=>{n(),r()}},onNew:e=>(s.add(e),()=>{s.delete(e)}),markRead:e=>{let t=i.getValue();i.setValue({...t,ids:[...t.ids,e].slice(-200)}),l()},markAllRead:()=>{i.setValue({before:r(),ids:c.filter(({pending:e})=>e).map(({id:e})=>e).slice(-200)}),l()}}},VQ=(e,t)=>JSON.stringify(e)===JSON.stringify(t),HQ=(e,t)=>{if(e===null)return t;let n=new Map(e.map(e=>[e.id,e])),r=t.map(e=>{let t=n.get(e.id);return t!==void 0&&VQ(t,e)?t:e});return r.length===e.length&&r.every((t,n)=>t===e[n])?e:r},UQ=({client:e,open:t,pageVersion:n})=>{let r=Yy.create(null),i=Yy.create(null);return{info:r,open:t,pageVersion:n,dialog:i,restarting:Yy.create(!1),receive:e=>{r.setValue(e)},refresh:async()=>{let t=await e.call(`version`);t.ok&&r.setValue(t.data)},openDialog:e=>{i.setValue(e)},closeDialog:()=>{i.setValue(null)}}},WQ=({client:e,open:t,pageVersion:n,runs:r,decisions:i})=>{let a=UQ({client:e,open:t,pageVersion:n});return{version:a,follow:e=>VZ({url:()=>UA.overview,open:t,on:{runs:e=>{r.setValue(HQ(r.getValue(),e))},decisions:e=>{i.setValue(HQ(i.getValue(),e))},version:a.receive},...e})}},GQ=({link:e,server:t})=>t!==null&&`error`in t?`Cannot reach \`ork ui\`: ${t.error}`:e===`lost`?"Lost the stream from `ork ui`. Retrying…":e===`open`&&t!==null?`Ork ${t.version}`:"Connecting to `ork ui`…",KQ=e=>e===null?null:e.filter(e=>MQ(e)).length,qQ=({client:e,open:t,storage:n,pageVersion:r=null})=>{let i=Yy.create(null),a=Yy.create(null),o=Yy.create({link:`connecting`,server:null}),s=Yy.create({run:null,node:null}),c=DQ(),l=null,u=e=>{e.run!==l&&(l=null),s.setValue(e),c.chooseRun(e.run,e.node)},d=tb(n),f=Yy.create(`all`),p=Yy.create(!1),m=Yy.create(null),h=Az(()=>e.call(`projects`)),g=Az(()=>e.call(`triggers`)),_=Az(t=>e.call(`workflows`,{params:{id:t}})),v=Yy.create({project:`all`,period:`30`}),y=Az(({query:t})=>e.call(`usage`,{query:t})),b=Yy.create({status:`open`,about:`all`}),x=Az(()=>e.call(`feedbackItems`)),S=Yy.create(`all`),C=Az(()=>e.call(`worktrees`)),w=NQ({client:e,open:t}),T=OQ(e),E=BQ({runs:i,decisions:a,storage:n}),D=WQ({client:e,open:t,pageVersion:r,runs:i,decisions:a}),{version:O}=D,k=async()=>{let t=await e.call(`health`);o.setValue({...o.getValue(),server:t.ok?t.data:{error:t.error}})};return{runs:i,decisions:a,connection:o,selection:s,contextTarget:c.target,builder:c.builder,preferences:d,runFilter:f,runDialog:p,runPreset:m,client:e,settledDecisions:T.settled,notifications:E,projects:h,workflows:_,usage:y,usageFilter:v,feedback:x,feedbackFilter:b,worktrees:C,worktreesFilter:S,triggers:g,version:O,startRun:t=>e.call(`start`,{body:t}),start:()=>{let e=i.subscribe(w.reopenResumed),t=a.subscribe(T.saw),n=E.start(),r=D.follow({onStatus:e=>{o.setValue({...o.getValue(),link:e}),e!==`lost`&&k()},onFailure:()=>void k()});return()=>{e(),t(),n(),r.close()}},feedOf:w.feedOf,retainRun:w.retainRun,control:(t,n,r)=>e.call(t,{params:{id:n},body:r===void 0?{}:{node:r}}),sendMessage:(t,n,r)=>e.call(`message`,{params:{id:t},body:{node:n,body:r}}),answerDecision:(t,n,r=``)=>e.call(`answer`,{params:{id:t},body:r.trim()===``?{choose:n}:{choose:n,note:r}}),watchRun:w.watchRun,selectRun:e=>{l=null,u({run:e,node:null})},arriveAt:e=>{l=e,u({run:e,node:null})},takeArrival:e=>{let t=l===e;return t&&(l=null),t},selectNode:e=>{u({...s.getValue(),node:e})}}},JQ=(e,t,n)=>`${String(e)} ${e===1?t:n}`,YQ=()=>{let{runs:e,decisions:t,connection:n}=qy(),r=ib(e,KQ),i=ib(t,e=>e?.length??null);return ib(n,({link:e})=>e===`open`)&&r!==null&&i!==null?(0,G.jsxs)(`span`,{className:kT.status,children:[JQ(r,`run live`,`runs live`),`,`,` `,JQ(i,`decision open`,`decisions open`)]}):null},XQ=({workspace:e})=>{let t=ab(e.announcement),{connection:n,version:r}=qy(),i=ib(n,GQ),a=ab(r.restarting);return(0,G.jsxs)(`footer`,{className:kT.bar,children:[(0,G.jsx)(`output`,{"aria-live":a?`off`:void 0,className:kT.status,children:(0,G.jsx)(Wg,{text:i})}),(0,G.jsx)(YQ,{}),(0,G.jsx)(`output`,{"aria-atomic":`true`,"aria-live":`polite`,className:kT.visuallyHidden,children:t})]})},ZQ=e=>{let t=qy(),{preferences:n}=t,r=ab(e.view),i=ab(n.value),a=(0,V.useMemo)(()=>vQ(e,r,t,i),[e,r,t,i]);return OT(e,a),a},QQ=e=>{let t=qy();(0,V.useEffect)(()=>t.notifications.onNew(n=>{if(e.announce(n.map(({title:e})=>e).join(` `)),t.preferences.value.getValue().desktopNotifications)for(let r of n)hz(r.title,r.id,()=>{t.selectRun(r.runId),e.goTo(`notifications`)})}),[t,e])},$Q=({workspace:e})=>{let t=ZQ(e);return QQ(e),(0,G.jsx)(ZM,{value:e,children:(0,G.jsxs)(`div`,{className:kT.shell,children:[(0,G.jsx)(sW,{workspace:e}),(0,G.jsx)(tQ,{workspace:e}),(0,G.jsx)(WX,{workspace:e}),(0,G.jsx)(XQ,{workspace:e}),(0,G.jsx)(wQ,{commands:t,workspace:e}),(0,G.jsx)(gT,{})]})})},e$=()=>{let e=new Map;return{get length(){return e.size},clear:()=>{e.clear()},getItem:t=>e.get(t)??null,key:t=>[...e.keys()][t]??null,removeItem:t=>{e.delete(t)},setItem:(t,n)=>{e.set(t,n)}}},t$=()=>{try{return window.localStorage}catch{return e$()}},n$=1e3,r$=e=>{let t=[],n=!1,r=i=>{n=!0,e.setValue(``),setTimeout(()=>{e.setValue(i)},0),setTimeout(()=>{n=!1,t.length>0&&r(t.splice(0).join(` `))},n$)};return e=>{let i=Ug(e);n?t.push(i):r(i)}},i$=280,a$=340,o$=240,s$={minimumWidth:240,minimumHeight:120},c$=e=>{e.api.setConstraints(s$)},l$=(e,t,n)=>[e.onDidAddGroup(c$),e.onDidLayoutChange(()=>{n(),t()}),e.onDidAddPanel(t),e.onDidRemovePanel(t),e.onDidActivePanelChange(t),e.onDidMaximizedGroupChange(t)],u$=(e,t)=>{try{return e.fromJSON(t),!0}catch{return e.clear(),!1}},d$=(e,t,n)=>e.addPanel({id:t,component:t,title:rW(t).title,...n}),f$=e=>{let t=d$(e,`monitor`,{});d$(e,`builder`,{position:{referencePanel:`monitor`,direction:`within`},inactive:!0}),d$(e,`runs`,{position:{referencePanel:`monitor`,direction:`left`},initialWidth:i$,inactive:!0}),d$(e,`decisions`,{position:{referencePanel:`monitor`,direction:`right`},initialWidth:a$,inactive:!0}),d$(e,`notifications`,{position:{referencePanel:`decisions`,direction:`within`},inactive:!0}),d$(e,`context`,{position:{referencePanel:`decisions`,direction:`below`}}),d$(e,`logs`,{position:{referencePanel:`monitor`,direction:`below`},initialHeight:o$,inactive:!0}),d$(e,`chats`,{position:{referencePanel:`logs`,direction:`within`},inactive:!0}),d$(e,`usage`,{position:{referencePanel:`logs`,direction:`within`},inactive:!0}),d$(e,`feedback`,{position:{referencePanel:`usage`,direction:`within`},inactive:!0}),d$(e,`worktrees`,{position:{referencePanel:`feedback`,direction:`within`},inactive:!0}),t.api.setActive()},p$=(e,t,n)=>{if(!Array.isArray(e.data))return;let r=e.data,i=r.findIndex(e=>!Array.isArray(e.data)&&e.data.id===t);if(i!==-1)return{siblings:r,index:i,along:n};for(let e of r){let r=p$(e,t,!n);if(r!==void 0)return r}},m$={horizontal:`left`,vertical:`above`},h$={horizontal:`right`,vertical:`below`},g$=(e,t)=>{let{root:n,orientation:r}=e.toJSON().grid,i=r===yG.HORIZONTAL,a=p$(n,t.id,!0);if(a===void 0)return;let{siblings:o,index:s,along:c}=a,l=c===i?`horizontal`:`vertical`,u=o[s+1],d=u??o[s-1];if(d===void 0)return;let f={width:t.api.width,height:t.api.height},p=u===void 0?h$[l]:m$[l];return Array.isArray(d.data)?c?{group:null,direction:p,...f}:void 0:{group:d.data.id,direction:p,...f}},_$=(e,t)=>{if(t.api.location.type!==`floating`)return;let n=e.toJSON().floatingGroups?.find(e=>e.data?.id===t.id);if(n===void 0)return;let{position:r}=n,{width:i,height:a}=r;return{left:`left`in r?r.left:e.width-r.right-i,top:`top`in r?r.top:e.height-r.bottom-a,width:i,height:a}},v$=(e,t)=>{let{group:n}=t,r=_$(e,n),i=g$(e,n);return{group:n.id,index:n.panels.indexOf(t),...r===void 0?{}:{floating:r},...i===void 0?{}:{beside:i}}},y$=(e,t)=>{if(t!==void 0){if(e.getGroup(t.group)!==void 0)return{position:{referenceGroup:t.group,direction:`within`,index:t.index}};if(t.floating!==void 0){let{left:e,top:n,width:r,height:i}=t.floating;return{floating:{x:e,y:n,width:r,height:i}}}if(t.beside!==void 0){let{group:n,direction:r,width:i,height:a}=t.beside,o=r===`left`||r===`right`?{initialWidth:i}:{initialHeight:a};if(n===null)return{position:{direction:r},...o};if(e.getGroup(n)!==void 0)return{position:{referenceGroup:n,direction:r},...o}}}let n=e.activeGroup;return n===void 0?{}:{position:{referenceGroup:n.id,direction:`within`}}},b$=(e,t,n)=>d$(e,t,y$(e,n)),x$=(e,t)=>e.groups.find(e=>e.id===t),S$=e=>{let t=e.element.querySelector(`[role="tab"][aria-selected="true"]`);return t?.focus(),t!==null},C$=e=>{e.api.setActive(),requestAnimationFrame(()=>{S$(e.group)})},w$=e=>e.map(e=>({group:e,box:e.element.getBoundingClientRect()})).toSorted((e,t)=>e.box.left-t.box.left||e.box.top-t.box.top).map(({group:e})=>e),T$=(e,t)=>{let n=w$(e.groups),{activeGroup:r}=e;if(n.length===0)return;let i=n[((r===void 0?0:n.indexOf(r))+t+n.length)%n.length];i!==void 0&&(i.activePanel?.api.setActive(),S$(i))},E$=e=>{e.api.location.type===`grid`&&(e.api.isMaximized()?e.api.exitMaximized():e.api.maximize(),S$(e))},D$={right:{axis:`width`,delta:32},left:{axis:`width`,delta:-32},down:{axis:`height`,delta:32},up:{axis:`height`,delta:-32}},O$=(e,t)=>{let{axis:n,delta:r}=D$[t];e.api.setSize({[n]:e.api[n]+r})},k$=e=>{let t=String(Math.round(e.group.api.width)),n=String(Math.round(e.group.api.height));return`${e.title??e.id}: ${t} by ${n}.`},A$={right:{x:32,y:0},left:{x:-32,y:0},down:{x:0,y:32},up:{x:0,y:-32}},j$={left:`left`,right:`right`,up:`above`,down:`below`},M$=(e,t,n)=>{let{group:r}=t,i=_$(e,r);if(i!==void 0){let{x:t,y:a}=A$[n];e.addFloatingGroup(r,{x:Math.max(0,i.left+t),y:Math.max(0,i.top+a),width:i.width,height:i.height});return}let a=e.adjacentGroupInDirection(r,n),o=a===void 0?void 0:x$(e,a.id);o===void 0?(r.panels.length!==1||e.groups.length!==1)&&t.api.moveTo({group:e.addGroup({direction:j$[n]}),position:`center`}):t.api.moveTo({group:o,position:`center`})},N$={left:`left`,right:`right`,above:`top`,below:`bottom`},P$=(e,t,n)=>{let r=t.activePanel;if(r===void 0)return;if(t.api.location.type!==`floating`){let{beside:i}=v$(e,r);e.addFloatingGroup(t);let a=e.getPanel(r.id)?.group;a!==void 0&&i!==void 0&&n.set(a.id,i);return}let i=n.get(t.id);n.delete(t.id);let a=i?.group===void 0||i.group===null?void 0:x$(e,i.group),o=i?.direction??`right`;t.api.moveTo(a===void 0?{position:N$[o]}:{group:a,position:N$[o]}),i!==void 0&&t.api.setSize(o===`left`||o===`right`?{width:i.width}:{height:i.height})},F$=`ork.layout.v1`,I$=zs(e=>typeof e==`string`&&nW(e)),L$=ss({left:Yo(),top:Yo(),width:Yo(),height:Yo()}),R$=ss({id:I$,anchor:ss({group:Co(),index:Yo(),floating:L$.optional(),beside:ss({group:Co().nullable(),direction:_s([`left`,`right`,`above`,`below`]),width:Yo(),height:Yo()}).optional()})}),z$=ls({grid:ls({root:ls({})}),panels:hs(Co(),ls({contentComponent:I$}))}),B$=ss({dock:ts(),minimized:as(R$),folded:as(I$)}),V$=(e,t,n)=>[...e.filter(e=>e!==t),...n?[t]:[]],H$={dock:null,minimized:[],folded:[]},U$=e=>z$.safeParse(e).success,W$=e=>{let t=B$.safeParse(e);if(!t.success)return null;let{dock:n,minimized:r,folded:i}=t.data;if(n==null)return{dock:null,minimized:[],folded:i};if(!U$(n))return null;let a=new Set(Object.values(n.panels).map(e=>e.contentComponent));return{dock:n,minimized:r.filter(e=>!a.has(e.id)),folded:i}},G$=e=>new Zy(H$,{key:F$,storage:e}),K$=({dock:e,targetPanel:t,commit:n,refocus:r,announce:i,quietly:a})=>{let o=new Map,s=()=>{let t=e();t?.hasMaximizedGroup()===!0&&t.exitMaximizedGroup()};return{close:e=>{let i=t(e);i!==void 0&&(s(),i.api.close(),n(),r())},toggleMaximize:t=>{let r=t??e()?.activeGroup;r!==void 0&&E$(r),n()},toggleFloat:t=>{let i=e(),a=t??i?.activeGroup;i!==null&&a!==void 0&&(s(),P$(i,a,o),n(),r())},resize:t=>{let n=e(),r=n?.activeGroup,a=n?.activePanel;r!==void 0&&a!==void 0&&n?.hasMaximizedGroup()!==!0&&(O$(r,t),i(k$(a)))},move:t=>{let o=e(),c=o?.activePanel;o!==null&&c!==void 0&&(a(()=>{s(),M$(o,c,t)}),n(),r(),i(`${c.title??c.id} moved ${t}.`))},cycleGroup:t=>{let n=e();n!==null&&T$(n,t)}}},q$=({storage:e,wide:t,onLayoutDropped:n})=>{let r=G$(e),i=W$(r.getValue()),a=i===null;a&&r.reset();let o=Yy.create(IX(null,i??H$,t)),s=Yy.create(!1),c=Yy.create(``),l=null,u=!1,d=[],f=r$(c),p=e=>{u||f(e)},m=e=>{u=!0,e(),u=!1},h=()=>{let e=o.getValue(),t=IX(l,r.getValue(),e.wide);LX(e,t)||o.setValue(t)},g=()=>{l!==null&&r.setValue({...r.getValue(),dock:l.toJSON()})},_=()=>{g(),h()},v=()=>{for(let e of d)e.dispose();d=[],l=null,h()},y=e=>{v(),u=!0,l=e;let{dock:t,folded:i}=r.getValue();t!==null&&u$(e,t)||(a||=t!==null,r.setValue({...H$,folded:i}),f$(e)),a&&n?.(),a=!1,e.groups.forEach(c$),d=l$(e,h,g),h(),u=!1},b=e=>e===void 0?l?.activePanel:l?.getPanel(e),x=()=>{l?.hasMaximizedGroup()===!0&&l.exitMaximizedGroup()},S=e=>{let t=r.getValue();r.setValue({...t,minimized:e(t.minimized)})},C=e=>{requestAnimationFrame(()=>{let t=l?.activeGroup;!(t!==void 0&&S$(t))&&e!==void 0&&BX(zX(e))})},w=()=>{let[e]=tW;o.getValue().wide?C():e!==void 0&&BX(RX(e.id))},T=e=>{let t=b(e);if(l===null||t===void 0)return;let n=t.id;if(!nW(n))return;m(x);let r=v$(l,t);S(e=>[...e,{id:n,anchor:r}]),m(()=>{t.api.close()}),f(`${rW(n).title} minimized.`),_(),C(n)},E=e=>{if(l===null)return;let t=r.getValue().minimized.find(t=>t.id===e);S(t=>t.filter(t=>t.id!==e));let n=l;m(()=>{x(),C$(b$(n,e,t?.anchor))}),f(`${rW(e).title} restored.`),_()},D=(e,t)=>{let n=r.getValue();r.setValue({...n,folded:V$(n.folded,e,t)}),_()},O=e=>{D(e,!r.getValue().folded.includes(e))},k=e=>{if(!o.getValue().wide){D(e,!1),BX(RX(e));return}if(l===null)return;let t=l.getPanel(e);if(t!==void 0)t.api.isMaximized()||x(),C$(t);else if(o.getValue().minimized.includes(e))E(e);else{let t=l;m(()=>{x(),C$(b$(t,e))}),f(`${rW(e).title} opened.`)}},A=K$({dock:()=>l,targetPanel:b,commit:_,refocus:C,announce:f,quietly:m}),j=()=>{if(r.setValue(H$),l!==null){let e=l;m(()=>{e.clear(),f$(e)}),l.groups.forEach(c$),g(),C()}_(),f(`Layout reset.`)},M=e=>{let t=o.getValue();t.wide!==e&&o.setValue({...t,wide:e})};return{view:o,layout:r,palette:s,announcement:c,announce:f,announceFromDock:p,attach:y,detach:v,goTo:k,minimize:T,restore:E,toggleFold:O,resetLayout:j,focusPanels:w,...A,setWide:M}},J$=JA(),Y$=`1.0.0-alpha.6`,X$=()=>qQ({client:J$,open:IZ,storage:t$(),pageVersion:Y$}),Z$=()=>q$({storage:t$(),wide:window.matchMedia(FX).matches,onLayoutDropped:()=>{Hy.add({title:`Layout reset`,description:`The saved layout could not be read.`})}}),Q$=()=>{let[e]=(0,V.useState)(X$),[t]=(0,V.useState)(Z$);return(0,V.useLayoutEffect)(()=>nb(window,e.preferences),[e]),(0,V.useEffect)(()=>e.start(),[e]),(0,G.jsx)(Ky,{value:e,children:(0,G.jsx)(Yg,{children:(0,G.jsx)(Wy,{children:(0,G.jsx)($Q,{workspace:t})})})})};export{Q$ as App};