@krapht/ork 1.0.0-alpha.13 → 1.0.0-alpha.14

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 (42) hide show
  1. package/dist/{__build_info__-Da73_nBs.mjs → __build_info__-B82-dGJY.mjs} +2 -2
  2. package/dist/{attach-E6NNyA3T.mjs → attach-CdtGX9se.mjs} +5 -5
  3. package/dist/bin.mjs +194 -215
  4. package/dist/{builtin-files-n6o6oWpB.mjs → builtin-files-Bdq23IIi.mjs} +1 -1
  5. package/dist/{chips-CyeB_rhR.mjs → chips-BqcT58qr.mjs} +1 -1
  6. package/dist/{completion-SNNNxnv9.mjs → completion--ywde-56.mjs} +52 -11
  7. package/dist/{context-DHudLA5e.mjs → context-Y_I4Mofq.mjs} +17 -7
  8. package/dist/{find-CjsNYAAf.mjs → find-BVX-bL4u.mjs} +1 -1
  9. package/dist/{format-C60TFpRe.mjs → format-CvTE5CZQ.mjs} +12 -12
  10. package/dist/{help-groups-CyfPWlST.mjs → help-groups-CpR2UzSn.mjs} +16 -6
  11. package/dist/{in-a-run-BYjTXaST.mjs → in-a-run-cL5N9gpH.mjs} +1 -1
  12. package/dist/{limits-C5QKZNLT.mjs → limits-Dhe--wmX.mjs} +1 -1
  13. package/dist/{mcp-bcctR-wc.mjs → mcp-CsmboyXv.mjs} +6 -6
  14. package/dist/{once-DPQu5Q3H.mjs → once-CrwI-ZdN.mjs} +4 -4
  15. package/dist/{output-CnRzrbUM.mjs → output-B1kwo0YU.mjs} +17 -1
  16. package/dist/{pause-BPvlDIvz.mjs → pause-DssrYcda.mjs} +4 -4
  17. package/dist/{relay-C8W0t_zc.mjs → relay-DASRgsTQ.mjs} +2 -2
  18. package/dist/{run-CQIfq918.mjs → run-D8divGCs.mjs} +1 -1
  19. package/dist/send-CXv8bx0i.mjs +105 -0
  20. package/dist/{src-CGJGL1sZ.mjs → src-8Mul0695.mjs} +8 -10
  21. package/dist/{src-D93tHZ5B.mjs → src-C7z_6fhn.mjs} +92 -39
  22. package/dist/{src-CqRqsb2t.mjs → src-njdtejgZ.mjs} +98 -33
  23. package/dist/{src-BeR6f70A.mjs → src-tsuZRu0H.mjs} +2353 -918
  24. package/dist/{store-CM3cERGl.mjs → store-CleF7KeS.mjs} +21 -73
  25. package/dist/ui/assets/app-D_nAPnHM.css +1 -0
  26. package/dist/ui/assets/{app-DYRC0V4p.js → app-DqBAtXSZ.js} +19 -19
  27. package/dist/ui/assets/{index-CWwm8HTG.js → index-D-_uPI2v.js} +2 -2
  28. package/dist/ui/index.html +1 -1
  29. package/dist/{ui-D2Ydofq0.mjs → ui-CNO1M0qT.mjs} +4 -4
  30. package/dist/{usage-6WIowblz.mjs → usage-BVXi0iFY.mjs} +13 -141
  31. package/dist/{verdict-CIy8tAyX.mjs → verdict-CMvPCpWC.mjs} +2 -2
  32. package/dist/{watch-uOU_WeBI.mjs → watch-DVNIciHp.mjs} +10 -8
  33. package/dist/{workflows-7tQdMnrA.mjs → workflows-B30QkwTk.mjs} +3 -3
  34. package/dist/{worktrees-ZCII298F.mjs → worktrees-DD4_TpkH.mjs} +3 -5
  35. package/package.json +2 -2
  36. package/dist/clean-Bh4KZgzc.mjs +0 -91
  37. package/dist/decide-DuIHACvH.mjs +0 -50
  38. package/dist/list-BUb5Uc3H.mjs +0 -117
  39. package/dist/remove-BkFWGVYo.mjs +0 -201
  40. package/dist/report-CEN8VoUb.mjs +0 -140
  41. package/dist/send-CaZlGG5a.mjs +0 -163
  42. package/dist/ui/assets/app-QoHVi-mb.css +0 -1
@@ -88,24 +88,24 @@ $&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,`$1$2`).replace(/\
88
88
  `+yT(l(e),c),s&&s()):d&&o&&o(),p}function eE({items:e},t,{flowChars:n,itemIndent:r}){let{indent:i,indentStep:a,flowCollectionPadding:o,options:{commentString:s}}=t;r+=a;let c=Object.assign({},t,{indent:r,inFlow:!0,type:null}),l=!1,u=0,d=[];for(let n=0;n<e.length;++n){let i=e[n],a=null;if(Jw(i))i.spaceBefore&&d.push(``),tE(t,d,i.commentBefore,!1),i.comment&&(a=i.comment);else if(Ww(i)){let e=Jw(i.key)?i.key:null;e&&(e.spaceBefore&&d.push(``),tE(t,d,e.commentBefore,!1),e.comment&&(l=!0));let n=Jw(i.value)?i.value:null;n?(n.comment&&(a=n.comment),n.commentBefore&&(l=!0)):i.value==null&&e?.comment&&(a=e.comment)}a&&(l=!0);let o=zT(i,c,()=>a=null);l||=d.length>u||o.includes(`
89
89
  `),n<e.length-1?o+=`,`:t.options.trailingComma&&(t.options.lineWidth>0&&(l||=d.reduce((e,t)=>e+t.length+2,2)+(o.length+2)>t.options.lineWidth),l&&(o+=`,`)),a&&(o+=bT(o,r,s(a))),d.push(o),u=d.length}let{start:f,end:p}=n;if(d.length===0)return f+p;if(!l){let e=d.reduce((e,t)=>e+t.length+2,2);l=t.options.lineWidth>0&&e>t.options.lineWidth}if(l){let e=f;for(let t of d)e+=t?`\n${a}${i}${t}`:`
90
90
  `;return`${e}\n${i}${p}`}return`${f}${o}${d.join(` `)}${o}${p}`}function tE({indent:e,options:{commentString:t}},n,r,i){if(r&&i&&(r=r.replace(/^\n+/,``)),r){let i=yT(t(r),e);n.push(i.trimStart())}}function nE(e,t){let n=Gw(t)?t.value:t;for(let r of e)if(Ww(r)&&(r.key===t||r.key===n||Gw(r.key)&&r.key.value===n))return r}var rE=class extends _T{static get tagName(){return`tag:yaml.org,2002:map`}constructor(e){super(Iw,e),this.items=[]}static from(e,t,n){let{keepUndefined:r,replacer:i}=n,a=new this(e),o=(e,o)=>{if(typeof i==`function`)o=i.call(t,e,o);else if(Array.isArray(i)&&!i.includes(e))return;(o!==void 0||r)&&a.items.push(XT(e,o,n))};if(t instanceof Map)for(let[e,n]of t)o(e,n);else if(t&&typeof t==`object`)for(let e of Object.keys(t))o(e,t[e]);return typeof e.sortMapEntries==`function`&&a.items.sort(e.sortMapEntries),a}add(e,t){let n;n=Ww(e)?e:!e||typeof e!=`object`||!(`key`in e)?new ZT(e,e?.value):new ZT(e.key,e.value);let r=nE(this.items,n.key),i=this.schema?.sortMapEntries;if(r){if(!t)throw Error(`Key ${n.key} already set`);Gw(r.value)&&uT(n.value)?r.value.value=n.value:r.value=n.value}else if(i){let e=this.items.findIndex(e=>i(n,e)<0);e===-1?this.items.push(n):this.items.splice(e,0,n)}else this.items.push(n)}delete(e){let t=nE(this.items,e);return t?this.items.splice(this.items.indexOf(t),1).length>0:!1}get(e,t){let n=nE(this.items,e)?.value;return(!t&&Gw(n)?n.value:n)??void 0}has(e){return!!nE(this.items,e)}set(e,t){this.add(new ZT(e,t),!0)}toJSON(e,t,n){let r=n?new n:t?.mapAsMap?new Map:{};t?.onCreate&&t.onCreate(r);for(let e of this.items)JT(t,r,e);return r}toString(e,t,n){if(!e)return JSON.stringify(this);for(let e of this.items)if(!Ww(e))throw Error(`Map items must all be pairs; found ${JSON.stringify(e)} instead`);return!e.allNullValues&&this.hasAllNullValues(!1)&&(e=Object.assign({},e,{allNullValues:!0})),QT(this,e,{blockItemPrefix:``,flowChars:{start:`{`,end:`}`},itemIndent:e.indent||``,onChompKeep:n,onComment:t})}},iE={collection:`map`,default:!0,nodeClass:rE,tag:`tag:yaml.org,2002:map`,resolve(e,t){return Uw(e)||t(`Expected a mapping for this tag`),e},createNode:(e,t,n)=>rE.from(e,t,n)},aE=class extends _T{static get tagName(){return`tag:yaml.org,2002:seq`}constructor(e){super(zw,e),this.items=[]}add(e){this.items.push(e)}delete(e){let t=oE(e);return typeof t==`number`&&this.items.splice(t,1).length>0}get(e,t){let n=oE(e);if(typeof n!=`number`)return;let r=this.items[n];return!t&&Gw(r)?r.value:r}has(e){let t=oE(e);return typeof t==`number`&&t<this.items.length}set(e,t){let n=oE(e);if(typeof n!=`number`)throw Error(`Expected a valid index, not ${e}.`);let r=this.items[n];Gw(r)&&uT(t)?r.value=t:this.items[n]=t}toJSON(e,t){let n=[];t?.onCreate&&t.onCreate(n);let r=0;for(let e of this.items)n.push(oT(e,String(r++),t));return n}toString(e,t,n){return e?QT(this,e,{blockItemPrefix:`- `,flowChars:{start:`[`,end:`]`},itemIndent:(e.indent||``)+` `,onChompKeep:n,onComment:t}):JSON.stringify(this)}static from(e,t,n){let{replacer:r}=n,i=new this(e);if(t&&Symbol.iterator in Object(t)){let e=0;for(let a of t){if(typeof r==`function`){let n=t instanceof Set?a:String(e++);a=r.call(t,n,a)}i.items.push(mT(a,void 0,n))}}return i}};function oE(e){let t=Gw(e)?e.value:e;return t&&typeof t==`string`&&(t=Number(t)),typeof t==`number`&&Number.isInteger(t)&&t>=0?t:null}var sE={collection:`seq`,default:!0,nodeClass:aE,tag:`tag:yaml.org,2002:seq`,resolve(e,t){return Kw(e)||t(`Expected a sequence for this tag`),e},createNode:(e,t,n)=>aE.from(e,t,n)};function cE(e){return typeof e==`bigint`||Number.isInteger(e)}var lE=({value:e})=>JSON.stringify(e),uE=[{identify:e=>typeof e==`string`,default:!0,tag:`tag:yaml.org,2002:str`,resolve:e=>e,stringify:lE},{identify:e=>e==null,createNode:()=>new dT(null),default:!0,tag:`tag:yaml.org,2002:null`,test:/^null$/,resolve:()=>null,stringify:lE},{identify:e=>typeof e==`boolean`,default:!0,tag:`tag:yaml.org,2002:bool`,test:/^true$|^false$/,resolve:e=>e===`true`,stringify:lE},{identify:cE,default:!0,tag:`tag:yaml.org,2002:int`,test:/^-?(?:0|[1-9][0-9]*)$/,resolve:(e,t,{intAsBigInt:n})=>n?BigInt(e):parseInt(e,10),stringify:({value:e})=>cE(e)?e.toString():JSON.stringify(e)},{identify:e=>typeof e==`number`,default:!0,tag:`tag:yaml.org,2002:float`,test:/^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,resolve:e=>parseFloat(e),stringify:lE}];[iE,sE].concat(uE,{default:!0,tag:``,test:/^/,resolve(e,t){return t(`Unresolved plain scalar ${JSON.stringify(e)}`),e}});function dE(e,t,n){let{replacer:r}=n,i=new aE(e);i.tag=`tag:yaml.org,2002:pairs`;let a=0;if(t&&Symbol.iterator in Object(t))for(let e of t){typeof r==`function`&&(e=r.call(t,String(a++),e));let o,s;if(Array.isArray(e)){if(e.length===2)o=e[0],s=e[1];else throw TypeError(`Expected [key, value] tuple: ${e}`)}else if(e&&e instanceof Object){let t=Object.keys(e);if(t.length===1)o=t[0],s=e[o];else throw TypeError(`Expected tuple with one key, not ${t.length} keys`)}else o=e;i.items.push(XT(o,s,n))}return i}var fE=class e extends aE{constructor(){super(),this.add=rE.prototype.add.bind(this),this.delete=rE.prototype.delete.bind(this),this.get=rE.prototype.get.bind(this),this.has=rE.prototype.has.bind(this),this.set=rE.prototype.set.bind(this),this.tag=e.tag}toJSON(e,t){if(!t)return super.toJSON(e);let n=new Map;t?.onCreate&&t.onCreate(n);for(let e of this.items){let r,i;if(Ww(e)?(r=oT(e.key,``,t),i=oT(e.value,r,t)):r=oT(e,``,t),n.has(r))throw Error(`Ordered maps must not include duplicate keys`);n.set(r,i)}return n}static from(e,t,n){let r=dE(e,t,n),i=new this;return i.items=r.items,i}};fE.tag=`tag:yaml.org,2002:omap`;var pE=class e extends rE{constructor(t){super(t),this.tag=e.tag}add(e){let t;t=Ww(e)?e:e&&typeof e==`object`&&`key`in e&&`value`in e&&e.value===null?new ZT(e.key,null):new ZT(e,null),nE(this.items,t.key)||this.items.push(t)}get(e,t){let n=nE(this.items,e);return!t&&Ww(n)?Gw(n.key)?n.key.value:n.key:n}set(e,t){if(typeof t!=`boolean`)throw Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof t}`);let n=nE(this.items,e);n&&!t?this.items.splice(this.items.indexOf(n),1):!n&&t&&this.items.push(new ZT(e))}toJSON(e,t){return super.toJSON(e,t,Set)}toString(e,t,n){if(!e)return JSON.stringify(this);if(this.hasAllNullValues(!0))return super.toString(Object.assign({},e,{allNullValues:!0}),t,n);throw Error(`Set items must all have null values`)}static from(e,t,n){let{replacer:r}=n,i=new this(e);if(t&&Symbol.iterator in Object(t))for(let e of t)typeof r==`function`&&(e=r.call(t,e,e)),i.items.push(XT(e,null,n));return i}};pE.tag=`tag:yaml.org,2002:set`;var mE=Symbol(`break visit`),hE=Symbol(`skip children`),gE=Symbol(`remove item`);function _E(e,t){`type`in e&&e.type===`document`&&(e={start:e.start,value:e.value}),vE(Object.freeze([]),e,t)}_E.BREAK=mE,_E.SKIP=hE,_E.REMOVE=gE,_E.itemAtPath=(e,t)=>{let n=e;for(let[e,r]of t){let t=n?.[e];if(t&&`items`in t)n=t.items[r];else return}return n},_E.parentCollection=(e,t)=>{let n=_E.itemAtPath(e,t.slice(0,-1)),r=t[t.length-1][0],i=n?.[r];if(i&&`items`in i)return i;throw Error(`Parent collection not found`)};function vE(e,t,n){let r=n(t,e);if(typeof r==`symbol`)return r;for(let i of[`key`,`value`]){let a=t[i];if(a&&`items`in a){for(let t=0;t<a.items.length;++t){let r=vE(Object.freeze(e.concat([[i,t]])),a.items[t],n);if(typeof r==`number`)t=r-1;else if(r===mE)return mE;else r===gE&&(a.items.splice(t,1),--t)}typeof r==`function`&&i===`key`&&(r=r(t,e))}}return typeof r==`function`?r(t,e):r}var yE=e=>e,bE=yE({id:`aws`,label:`AWS CLI`,program:`aws`,options:{profile:V().optional(),region:V().optional()},args:({profile:e,region:t})=>[...e===void 0?[]:[`--profile`,e],...t===void 0?[]:[`--region`,t]],signedOut:({stderr:e})=>/Unable to locate credentials|ExpiredToken|InvalidClientTokenId|Token has expired|aws sso login|SSO session .* expired/iu.test(e),doctor:async(e,t)=>{if(!(await e(`aws`,[`--version`])).ok)return{name:`aws`,status:`skip`,detail:`optional, not installed (needed only for tool.aws nodes)`};let n=t.AWS_PROFILE,r=n===void 0?``:` (profile ${n})`;return(await e(`aws`,[`sts`,`get-caller-identity`,`--output`,`json`])).ok?{name:`aws`,status:`ok`,detail:`signed in${r}`}:{name:`aws`,status:`warn`,detail:`no valid credentials${r}`,hint:"Run `aws sso login` (or set AWS_PROFILE) yourself to use tool.aws nodes."}}}),xE=e=>{try{return JSON.parse(e)}catch{return}},SE=(e,t)=>typeof e==`object`&&e&&Object.hasOwn(e,t)?Reflect.get(e,t):void 0,CE=e=>e.trim().split(`
91
- `)[0]??``,wE=(e,t,n,r)=>({id:e,...r,doctor:async i=>{let a=`${t} (${e} driver)`,o=await i(t,[`--version`]),s=r.proven?``:`, unproven: not yet proven on a real session`;return o.ok?{name:a,status:r.proven?`ok`:`skip`,detail:`${CE(o.stdout)}${s}; sign in with \`${n}\` if a session asks`}:{name:a,status:`skip`,detail:`${t} CLI not found${s}`,...r.proven?{hint:`Install ${t} to use the ${e} driver.`}:{}}}});wE(`open-code`,`opencode`,`opencode auth login`,{label:"the `opencode` CLI",proven:!0,onePerCheckout:!1,capabilities:{questions:!0,permissionPrompt:!1,price:!0,midTurnMessages:!1,reportSchema:!1,turnLimit:!0,mcpServers:!0,subagents:!1}}),wE(`command-code`,`cmd`,`cmd login`,{label:"the `cmd` CLI of Command Code",proven:!0,onePerCheckout:!0,capabilities:{questions:!0,permissionPrompt:!1,price:!1,midTurnMessages:!1,reportSchema:!1,turnLimit:!0,mcpServers:!1,subagents:!1}});var TE=[`claude-code`,`open-code`,`command-code`],EE={sdk:`claude-code`,cli:`claude-code`},DE=[yE({id:`gh`,label:`GitHub CLI`,program:`gh`,options:{},args:()=>[],signedOut:({exitCode:e,stderr:t})=>e===4||/\bgh auth login\b/u.test(t),doctor:async e=>{if(!(await e(`gh`,[`--version`])).ok)return{name:`gh`,status:`skip`,detail:`optional, not installed (needed only for tool.gh nodes)`};let t=SE(SE(xE((await e(`gh`,[`auth`,`status`,`--json`,`hosts`])).stdout),`hosts`),`github.com`),n=(Array.isArray(t)?t:[]).find(e=>SE(e,`active`)===!0),r=SE(n,`login`);return SE(n,`state`)!==`success`||typeof r!=`string`?{name:`gh`,status:`warn`,detail:`not logged in to github.com`,hint:"Run `gh auth login` yourself to use tool.gh nodes."}:{name:`gh`,status:`ok`,detail:`logged in as ${r}`}}}),bE,yE({id:`git`,label:`Git`,program:`git`,options:{},args:()=>[],allow:[`add`,`commit`],observe:{fields:[`staged`,`diff`,`head`],read:async e=>{let t=await e([`diff`,`--cached`,`--stat`]),n=await e([`diff`,`--cached`]),r=await e([`rev-parse`,`--verify`,`--quiet`,`HEAD`]);return{staged:t.ok?t.stdout.trimEnd():``,diff:n.ok?n.stdout:``,head:r.ok?r.stdout.trim():``}}},doctor:async e=>{let t=await e(`git`,[`config`,`user.name`]),n=await e(`git`,[`config`,`user.email`]);return t.stdout.trim()===``||n.stdout.trim()===``?{name:`git identity`,status:`warn`,detail:`user.name or user.email is not set (needed only to commit with tool.git)`,hint:"Set them yourself (`git config --global user.name …`) before a tool.git node commits."}:{name:`git identity`,status:`ok`,detail:`user.name and user.email are set`}}}),yE({id:`shell`,label:`Any program`,program:null,options:{},args:()=>[]})],OE=`tool.`,kE={maxParallel:rs().int().positive().optional().describe(`Most items running at once. Default: limits.concurrency.`),onFailure:Os([`finish`,`stop`]).optional().describe("When an item fails: `finish` runs every item (default), `stop` starts no more.")},AE={forEach:vs([H({items:ps(ls()).min(1).describe(`The list, written here. Each entry is one item.`),...kE}),H({from:V().describe(`Where the list comes from: one path, e.g. {{nodes.plan.output.tasks}}.`),maxItems:rs().int().positive().describe(`Most items allowed. A longer list asks whether to stop, run this many, or run all.`),...kE})]).optional().describe("Run this node once per item of a list, with no model turn to fan out or gather. Items are `<id>.0`, `<id>.1`, ….")},jE=V().regex(/^[A-Za-z_][A-Za-z0-9_]*$/u),ME=vs([ps(vs([V(),rs(),ss()])).min(1),Os([`string`,`number`,`integer`,`boolean`])]),NE="`list` takes a map of each item's fields, e.g. `list: { title: string }` (`list: {}` for items of any shape)",PE=H({list:Es(V(),ME).describe(`The fields each item has, e.g. { title: string }; { } for no shape.`)}).describe(`A list of items, such as a plan's tasks.`),FE=Es(V(),vs([ME,PE])),IE={env:Es(jE,V()).optional().describe(`Environment variables for the program. Values are templates, and may read the user's own variables as {{env.NAME}}.`),plainEnv:ps(jE).optional().describe(`Variables read as {{env.NAME}} that are not secret, such as a region: their values are not masked in what programs print.`),output:H({format:As(`json`).describe(`The program's result is JSON, read as output.json: the file at $ORK_OUTPUT if it wrote one, otherwise its stdout.`),schema:FE.optional().describe(`The fields of that JSON a later node relies on, e.g. { state: [OPEN, CLOSED] }. A value outside these fails the node.`)}).optional().describe(`Structured output from the program.`)},LE=V().regex(/^[a-z][a-z0-9_-]*$/u,`node ids are lowercase: letters, digits, '-' and '_'`),RE=e=>{let t=typeof e==`string`&&Object.hasOwn(EE,e)?EE[e]:void 0;return t===void 0?void 0:`driver \`${String(e)}\` was retired; use \`${t}\``},zE=Os(TE,{error:e=>RE(e.input)}),BE=V().min(1),VE=Os([`low`,`medium`,`high`,`xhigh`,`max`]).describe(`Reasoning effort. Default: Claude Code's for the model.`),HE=Os([`worktree`,`continue`,`shared`,`readonly`]),UE=rs().positive(),WE=H({dayUsd:UE.optional().describe(`Most to spend in a calendar day.`),weekUsd:UE.optional().describe(`Most to spend in a calendar week, from Monday.`),monthUsd:UE.optional().describe(`Most to spend in a calendar month.`)}),GE={s:1e3,m:6e4,h:36e5},KE=e=>{let t=/^(\d+)([smh])$/u.exec(e??``);if(t===null)return;let[,n=`0`,r=`s`]=t;return Number(n)*(GE[r]??1e3)},qE=2**31-1,JE=V().regex(/^\d+[smh]$/u,`use e.g. 30s, 15m, 2h`).refine(e=>(KE(e)??0)<=qE,`the longest this can be is 596h`),YE=JE.refine(e=>!/^0+[smh]$/u.test(e),`a timeout must be longer than zero`),XE=e=>JE.refine(t=>(KE(t)??0)>=(KE(e)??0),`look no more often than every ${e}`),ZE=H({every:XE(`5s`).describe(`How long to wait between looks, e.g. 30s. At least 5s.`),until:V().min(1).describe(`Stop looking when this holds. It reads what an edge's when: does.`),timeout:YE.describe(`How long to go on looking, e.g. 2h; then the node fails. Time between looks doesn't count against limits.timeout.`),misses:rs().int().positive().optional().describe(`How many failed looks in a row end the wait, such as a network error. Default: 3.`)}).refine(({every:e,timeout:t})=>(KE(t)??0)>(KE(e)??0),`watch.timeout must be longer than watch.every`),QE=H({caveman:ss().optional().describe(`Terse voice in chat, reports and messages. Default: on.`),ponytail:vs([ss(),Os([`lite`,`full`,`ultra`])]).optional().describe("Smallest complete change. `true` is `full`. Default: `full`.")}),$E=rs().int().positive(),eD=ps(V().min(1)).optional().describe("MCP servers from the project's `.mcp.json` this node's sessions load, beside Ork's own. Default: none."),tD=H({allow:ps(V()).optional(),deny:ps(V()).optional(),only:ps(V()).optional().describe(`The only built-in tools the session has; Ork's tools stay.`)}),nD=V().regex(/^[a-z][a-z0-9_-]*$/u,`agent names are lowercase: letters, digits, '-' and '_'`),rD={parent:LE.optional().describe(`Owner of this node in the ownership tree.`),label:V().optional(),description:V().optional()},iD={notify:ps(H({to:LE.describe("The `agent.leader` or `agent.worker` to write to."),when:V().optional().describe(`Send only when this holds. It reads what an edge's when: does, plus ok and error. Default: every finish.`),body:V().optional().describe(`The message, a template. Default: Ork's one line on the result.`)})).optional().describe(`Messages to send when this node finishes, with no model turn. Each starts no session.`)},aD=H({type:As(`mcp.call`),...rD,server:V().describe("The server's name in the project's `.mcp.json`."),tool:V().describe(`The tool to call on it.`),arguments:Es(V(),ls()).optional().describe(`The tool's arguments. Strings are templates; one that is only {{ … }} keeps its value's type.`),output:H({schema:FE.optional().describe(`The fields of the tool's JSON result a later node relies on, e.g. { state: [open, closed] }. A value outside these fails the node.`)}).optional().describe(`What the tool's result says.`),env:IE.env,plainEnv:IE.plainEnv,timeout:YE.optional().describe(`How long the call may take, e.g. 5m; then the node fails. With watch:, how long one look may take.`),watch:ZE.optional().describe(`Call the tool again and again until a condition holds, with no model turn.`),...iD,...AE}),oD={command:V().optional().describe(`Program and arguments (no shell), or script: instead. Supports templates.`),script:V().optional().describe(`The text of a short program, instead of command. It takes no templates: values arrive through env:, as $NAME, so a value cannot become code.`),interpreter:V().optional().describe("What runs `script:`: a program and arguments. Default: `sh -eu`.")},sD=ss().optional().describe(`Skip the command when the same check already passed on identical files (a hash of the working tree, the command, Node's version); a pass is recorded. Default: false.`),cD=H({...oD,...IE,timeout:YE.optional().describe(`How long the program may run, e.g. 5m; then it is killed and the step fails.`)}),lD=cD.extend({attempts:rs().int().min(0).max(5).optional().describe(`How many times a failed check resumes the session to fix it before the node fails. Default: 1.`),once:sD}).describe(`A program that must pass before the node's report is accepted. It runs in the node's checkout.`),uD={before:cD.optional().describe(`A program to run in the node's checkout before its session starts: if it fails, the node fails and no model turn is spent. Its prompt can read {{before.stdout}}, {{before.json.*}}.`),verify:lD.optional()},dD={...rD,...oD,allow:ps(V()).optional().describe("Allowed subcommand prefixes, e.g. `pr view`, `pr merge`."),cwd:V().optional(),timeout:YE.optional().describe(`How long the command may run, e.g. 5m; then it is killed and the node fails. With watch:, how long one look may take.`),watch:ZE.optional().describe(`Run the command again and again until a condition holds, with no model turn.`),once:sD,...IE,...iD,...AE},fD=e=>H({type:As(e),...dD}),pD=e=>{let t=fD(`${OE}${e.id}`);return e.program===null?t.extend(e.options):t.omit({script:!0,interpreter:!0}).extend({command:V().describe(`Arguments for the CLI (no shell). Supports templates.`),...e.options})},mD=DE.map(e=>pD(e)),hD=rD,gD=ls().refine(e=>typeof e!=`object`||!e||!(`list`in e),{message:NE}),_D=`expected low, medium, high, xhigh or max, or {{item.<field>}}`,vD=vs([VE,V().regex(/\{\{.*\}\}/su,{error:_D})],{error:_D}).describe(`Reasoning effort, or {{item.<field>}} on a forEach node. Default: Claude Code's for the model.`),yD={model:BE.optional(),effort:vD.optional(),driver:zE.optional(),skills:ps(V()).optional().describe(`Node-layer skills (highest precedence).`),context:ps(V()).optional().describe(`Node-layer context files.`),isolation:HE.optional(),budgetUsd:UE.optional(),maxTurns:$E.optional(),timeout:YE.optional().describe(`How long the node may work, e.g. 30m; time waiting on the user does not count.`),practices:QE.optional(),tools:tD.optional(),session:Os([`fresh`,`resume`]).optional().describe(`When the node runs again (a loop, another delegation): resume its session, or start a fresh one with the new input. Default: resume for a leader, fresh for a worker.`),output:H({schema:Es(V(),vs([PE,gD])).optional().describe(`Extra structured fields the node must report, e.g. { verdict: [approve, escalate] }.`),gather:ps(V().min(1)).min(1).optional().describe(`List fields kept across rounds: each round's entries are added to the earlier rounds' instead of replacing them, e.g. [decisions].`)}).optional()},bD={...hD,agent:nD.optional().describe(`The agent that fills this node; its settings apply where the node sets none, and the prompt is its task.`),prompt:V().optional().describe(`Task brief. Supports {{inputs.*}} and {{nodes.<id>.output.*}} templates.`),instructions:V().optional().describe(`Node-layer instructions appended to the system prompt.`),...yD},xD=H({type:As(`agent.leader`),...bD,mcp:eD,...iD,...uD,maxWorkers:rs().int().nonnegative().optional().describe(`Cap on dynamically spawned workers.`),questions:Os([`owner`,`user`]).optional().describe("Who a child's ask_user goes to first: `owner` asks a fork of this leader's session, which answers when what it was given settles it or passes it on; `user` (the default) asks the person.")}),SD=H({type:As(`agent.worker`),...bD,mcp:eD,...iD,...AE,...uD}),CD=H({type:As(`agent.subagent`),...bD,parent:LE.describe(`The Claude node whose session hosts this sub-agent.`),description:V().describe(`When the parent should use this sub-agent.`)}),wD=H({type:As(`control.split`),...hD}),TD=H({type:As(`control.join`),...hD,mode:Os([`all`,`any`,`n`]).optional().describe(`Default: all.`),n:rs().int().positive().optional()}),ED=H({type:As(`control.router`),...hD,mode:Os([`first`,`all`]).optional().describe(`Follow the first matching edge (default), or every match.`)}),DD=vs([V(),H({id:V(),label:V().optional(),description:V().optional()})]),OD=H({type:As(`human.gate`),...hD,...iD,question:V(),document:V().optional(),options:ps(DD).min(2),recommended:V().optional(),timeout:JE.optional(),default:V().optional().describe(`Option chosen when the timeout expires.`)}),kD=H({type:As(`workflow.call`),...hD,...iD,...AE,workflow:V().describe(`The workflow's name, as in its project's workflows folder.`),project:V().optional().describe(`A registered project's id. Default: this project.`),node:LE.optional().describe(`A leader or worker of the called workflow to talk to and wait on; the call then keeps one run as a conversation.`),inputs:Es(V(),V()).optional().describe(`The called workflow's inputs. Supports templates.`),wait:Os([`run`,`node`,`none`]).optional().describe("When this node finishes: the run has ended (default without `node`), the node has reported (default with `node`), or as soon as the run has started."),ref:V().optional().describe(`What the called run's worktrees start from, e.g. {{nodes.build.output.branch}}.`),timeout:YE.optional().describe(`How long the call may take, e.g. 30m; then the called run is stopped and the node fails.`),maxMessages:rs().int().positive().optional().describe(`Ask the user whether to go on after this many messages.`)}),AD=bs(`type`,[xD,SD,CD,...mD,wD,TD,ED,OD,kD,aD]);H(yD);var jD=H({description:V().optional().describe(`When to use this agent; tools show it when choosing one.`),instructions:V().optional().describe(`The agent's role, appended to the system prompt of its nodes.`),...yD}),MD=H({driver:zE.optional(),model:BE.optional(),effort:VE.optional(),isolation:HE.optional(),budgetUsd:UE.optional(),maxTurns:$E.optional(),timeout:YE.optional().describe(`For tool and Claude nodes that set none; a gate's own timeout is separate.`),practices:QE.optional(),mcp:eD,before:uD.before}),ND=H({git:H({commit:Os([`auto`,`never`]).optional().describe(`Default: auto, Ork commits a node's work on its branch. never: Ork runs no git commit; worktrees are detached and work stays uncommitted.`),merge:Os([`auto`,`patch`,`never`]).optional().describe(`How a passing child's work reaches its owner. auto: a --no-ff merge (needs commits). patch: its changes are applied, uncommitted. never: left in its own worktree. Default: auto, or patch under commit: never.`),base:V().min(1).optional().describe(`The commit worktrees without an owner start from, e.g. origin/main. Default: HEAD. Ork never fetches.`),branch:V().min(1).optional().describe(`Branch name template over {run}, {node}, {clone} and {inputs.<name>}. Default: ork/{run}/{node}.`),worktrees:V().min(1).optional().describe(`Worktree folder template, relative to the clone, beside it. Default: ../{clone}-worktrees/ork-{run}-{node}.`)}).optional(),permissions:tD.optional().describe(`Tool rules every Claude node gets on top of its own, e.g. deny: ['Bash(git push *)'].`),links:Os([`on`,`off`]).optional().describe(`Default: on, the user can link a running node to a node of another run. off: its nodes get no message tools unless they have someone to write to, and cannot be linked.`)}),PD=Os([`low`,`normal`]);H({schemaVersion:As(1),...ND.shape,defaults:MD.optional().describe(`Defaults for every workflow in the project; a workflow's own win.`),quotas:WE.optional().describe(`Most this project may spend on this machine. The user's own caps apply too.`),calls:H({accept:ps(V()).describe(`The registered projects whose workflows may call this one's.`)}).optional().describe(`Default: any registered project may call this one's workflows.`),context:ps(V()).optional().describe(`Context files every node reads, relative to the project root; they come before the workflow's.`),experimental:ps(V()).optional().describe(`Experimental features this project turns on.`),heavy:ps(V().min(1)).optional().describe(`The project's full-suite commands, as Bash permission patterns without Bash(…), e.g. pnpm check. A node with verify: may not run them in its session; vitest run does not cover vitest run <files>.`),priority:PD.optional().describe(`Default: low, sessions and tool commands start at a lower OS priority. normal: as the ork process.`)}),H({schemaVersion:As(1),quotas:WE.optional().describe(`Most to spend across every project on this machine.`)});var FD=bs(`type`,[aD,...mD]),ID=H({every:XE(`1m`).describe(`How long to wait between looks, e.g. 5m. At least 1m.`),check:FD.optional().describe(`What to look at; it reports { "events": [{ "key": "...", "inputs": { ... } }] }. Without one, the trigger starts a run every time.`),run:V().regex(/^[A-Za-z0-9][A-Za-z0-9._-]*$/u,`the name of a workflow in this project, not a path or a flag`).describe(`The workflow to start, by its name in this project.`),inputs:Es(V(),V()).optional().describe(`Inputs every run gets. They win over what a check reports, and aren't marked untrusted.`),maxRunsPerDay:rs().int().positive().optional().describe(`Most runs to start in a calendar day. Default: 10.`),concurrency:rs().int().positive().optional().describe(`How many of its runs may be going at once. A new key waits for the next look. Default: 1.`)});H({schemaVersion:As(1),triggers:Es(LE,ID)}),hs({events:ps(hs({key:V().min(1),inputs:Es(V(),vs([V(),rs(),ss()])).optional()}))});var LD=vs([LE,ps(LE).min(1)]),RD=vs([V(),H({from:LD,to:LD,when:V().optional(),maxRounds:rs().int().positive().optional()})]),zD=H({between:ws([LE,LE])}),BD=H({type:Os([`string`,`number`,`boolean`]).optional().describe(`Default: string.`),required:ss().optional(),default:vs([V(),rs(),ss()]).optional(),description:V().optional()}),VD=H({instructions:Os([`inherit`,`ignore`]).optional().describe(`Default: inherit.`),skills:vs([Os([`inherit`,`ignore`]),H({allow:ps(V())})]).optional().describe(`Default: inherit.`)}),HD=H({schemaVersion:As(1),name:V().regex(/^[a-z0-9][a-z0-9._-]*$/u,`workflow names are lowercase slugs`),description:V().optional(),inputs:Es(V(),BD).optional(),layers:H({skills:ps(V()).optional(),context:ps(V()).optional(),project:VD.optional()}).optional(),defaults:MD.optional(),rules:ND.optional().describe(`Rules for what Ork does on its own (git, permissions); they win over the project's .ork/project.yaml.`),agents:Es(nD,jD).optional().describe(`Agents defined in this workflow; they win over the project's and the user's of the same name.`),limits:H({budgetUsd:UE.optional().describe(`Hard cap for the whole run.`),concurrency:rs().int().positive().optional().describe(`Max sessions running at once.`),timeout:YE.optional().describe(`How long the whole run may work, e.g. 2h; time waiting on the user does not count.`)}).optional(),nodes:Es(LE,AD).refine(e=>Object.keys(e).length>0,`a workflow needs nodes`),edges:ps(RD).optional(),messages:ps(zD).optional(),outputs:Es(V(),V()).optional().describe(`What a workflow.call of this workflow can read, as templates over its nodes, rendered when the run ends.`)});AD.options.map(e=>e.shape.type.value),Object.keys(HD.shape),Object.keys(jD.shape),new Map(AD.options.map(e=>[e.shape.type.value,Object.keys(e.shape)]));var UD=(e,t)=>{let n=e.indexOf(`.`);if(n<=0)return{model:e};let r=e.slice(0,n);return t.includes(r)?{driver:r,model:e.slice(n+1)}:{model:e}},WD=ps(vs([V(),rs().int().min(0)])).min(1),GD={when:V().optional(),maxRounds:rs().int().positive().optional()},KD={whenWas:V().optional()};bs(`op`,[H({op:As(`set`),path:WD,value:ls()}),H({op:As(`delete`),path:WD}),H({op:As(`addNode`),id:V(),node:Es(V(),ls())}),H({op:As(`removeNode`),id:V()}),H({op:As(`renameNode`),from:V(),to:V()}),H({op:As(`connect`),from:V(),to:V(),...GD}),H({op:As(`disconnect`),from:V(),to:V(),...KD}),H({op:As(`setEdge`),from:V(),to:V(),...GD,...KD})]);var qD=({title:e,children:t,cli:n,focusable:r=!1})=>(0,q.jsxs)(`div`,{className:i_.empty,children:[(0,q.jsx)(`p`,{className:i_.emptyTitle,"data-empty-title":r?``:void 0,tabIndex:r?-1:void 0,children:e}),(0,q.jsx)(`div`,{className:i_.emptyBody,children:t}),n===void 0?null:(0,q.jsx)(`div`,{className:i_.emptyCommand,children:(0,q.jsx)(cC,{command:n})})]});function JD(e){if(!e)return null;for(let t of e.elements){let e=t.tagName;if(e===`BUTTON`||e===`INPUT`){let e=t;if(e.type===`submit`)return e}}return null}var YD=`data-checked`,XD=`data-unchecked`;function ZD(e){return{checked(t){return e.indeterminate?{}:t?{[YD]:``}:{[XD]:``}},...sx}}var QD=U.createContext({disabled:!1});function $D(){return U.useContext(QD)}function eO(e,t,n,r=!0,i,a){let[o,s]=U.useState(),c=hg(i?`${i}-label`:void 0),l=!!a?.trim(),u=e??(l?void 0:t)??o;return W(()=>{let i=e||t||l||!r?void 0:tO(n.current,c);o!==i&&s(i)}),u}function tO(e,t){let n=nO(e);if(n)return!n.id&&t&&(n.id=t),n.id||void 0}function nO(e){if(!e)return;let t=e.parentElement;if(t&&t.tagName===`LABEL`)return t;let n=e.id;if(n){let t=e.nextElementSibling;if(t&&t.htmlFor===n)return t}let r=e.labels;return r&&r[0]}var rO=U.createContext(void 0);function iO(){return U.useContext(rO)}var aO=U.createContext(void 0);function oO(){let e=U.useContext(aO);if(e===void 0)throw Error(gc(14));return e}var sO=`data-parent`,cO=U.forwardRef(function(e,t){let{checked:n,className:r,defaultChecked:i=!1,"aria-labelledby":a,disabled:o=!1,form:s,id:c,indeterminate:l=!1,inputRef:u,name:d,onCheckedChange:f,parent:p=!1,readOnly:m=!1,render:h,required:g=!1,uncheckedValue:_,value:v,nativeButton:y=!1,style:b,...x}=e,{clearErrors:S}=px(),{disabled:C,name:w,setDirty:T,setFilled:E,setTouched:D,state:O,validationMode:k,validityData:A,validation:j}=ux(),M=$D(),{labelId:N,registerControlId:P,getDescriptionProps:F}=hx(),I=iO(),L=I?.allValues===void 0?void 0:I.parent,R=L!==void 0,ee=C||M.disabled||I?.disabled||o,z=w??d,te=v??z,ne=hg(),re=I?.registerControlId!==P,ie=gx({id:c||void 0,enabled:re}),ae=y?ie:ne,oe={};R&&(p?oe=L.getParentProps():te!==void 0&&(oe=L.getChildProps(te)));let{checked:se=n,indeterminate:ce=l,onCheckedChange:le,...ue}=oe,de=I?.value,fe=U.useRef(null),pe=Vx(ee,fe),{getButtonProps:me,buttonRef:he}=ev({disabled:ee,native:y}),ge=I?.validation??j,[_e,ve]=Sb({controlled:te!==void 0&&de!==void 0&&!p?de.includes(te):se,default:i,name:`Checkbox`,state:`checked`}),ye=R?!!se:_e,be=R&&ce||l;dx(fe,ne,_e,void 0,!I&&!ee,d);let B=L?.registerChildId,xe=U.useRef(null),Se=ge.registerInput,Ce=I?te:void 0,we=U.useCallback(e=>Se(e,{controlRef:fe,value:Ce}),[Se,Ce]),Te=Au(u,xe,p?void 0:we),Ee=eO(a,N,xe,!y,ie,x[`aria-label`]);W(()=>{xe.current&&(xe.current.indeterminate=be),I||E(_e)},[_e,be,I,E]),wx(_e,()=>{I||(S(z),T(_e!==A.initialValue),ge.change(_e))});let De=Pf({checked:_e,disabled:ee,form:s,name:p?void 0:z,id:y?void 0:ie,required:g,ref:Te,style:z?Xu:Yu,tabIndex:-1,type:`checkbox`,"aria-hidden":!0,onChange(e){if(e.nativeEvent.defaultPrevented)return;if(m){e.preventDefault();return}let t=e.currentTarget.checked,n=K(iu,e.nativeEvent);if(f?.(t,n),!n.isCanceled&&(le?.(t,n),!n.isCanceled&&(ve(t),te!==void 0&&I!==void 0&&!p&&!R))){let e=t?[...I.value,te]:I.value.filter(e=>e!==te);I.setValue(e,n)}},onClick(e){e.stopPropagation()},onFocus(){fe.current?.focus()}},v===void 0?mc:{value:(I?_e&&v:v)||``},F,e=>ge.getValidationProps(ee,e));U.useEffect(()=>{if(!L||te===void 0)return;let e=L.disabledStatesRef.current;return e.set(te,ee),()=>{e.delete(te)}},[L,ee,te]);let Oe=U.useMemo(()=>({...O,checked:ye,disabled:ee,readOnly:m,required:g,indeterminate:be}),[O,ye,ee,m,g,be]),ke=ZD(Oe),Ae=qf(`span`,e,{state:Oe,ref:[he,fe,t],props:[{id:ae,role:`checkbox`,"aria-checked":be?`mixed`:ye,"aria-readonly":m||void 0,"aria-required":g||void 0,"aria-labelledby":Ee,[sO]:p?``:void 0,onFocus(){pe(!0)},onBlur(){let e=xe.current;e&&(D(!0),pe(!1),k===`onBlur`&&ge.commit(I?de:e.checked))},onKeyDown(e){if(e.key!==`Enter`||(e.preventBaseUIHandler(),e.defaultPrevented))return;let t=xe.current?.form??null,n=e.currentTarget,r=e.nativeEvent,i=e.preventDefault,a=r.preventDefault,o=!1;e.preventDefault=()=>{o=!0,i.call(e)},r.preventDefault=()=>{o=!0,a.call(r)},a.call(r),Kc(n).queueMicrotask(()=>{e.preventDefault=i,r.preventDefault=a,o||JD(t)?.click()})},onClick(e){if(m||ee)return;e.preventDefault();let t=xe.current;t&&$_(t,e)}},x,ue,me,F,e=>ge.getValidationProps(ee,e)],stateAttributesMapping:ke}),je=Ae.props.id;return W(()=>{if(B&&!p&&te!==void 0&&je!==void 0)return B(te,je)},[B,p,te,je]),(0,q.jsxs)(aO.Provider,{value:Oe,children:[Ae,!_e&&!I&&z&&!p&&_!==void 0&&(0,q.jsx)(`input`,{type:`hidden`,form:s,name:z,value:_,disabled:ee}),(0,q.jsx)(`input`,{...De,suppressHydrationWarning:!0})]})}),lO=U.forwardRef(function(e,t){let{render:n,className:r,style:i,keepMounted:a=!1,...o}=e,s=oO(),c=s.checked||s.indeterminate,{mounted:l,transitionStatus:u,setMounted:d}=Hp(c),f=U.useRef(null),p={...s,transitionStatus:u};qp({batch:!0,enabled:!c,open:c,ref:f,onComplete(){c||d(!1)}});let m={...ZD(s),...Ol},h=a||l,g=qf(`span`,e,{ref:[t,f],state:p,stateAttributesMapping:m,props:o});return h?g:null}),uO=U.createContext(void 0);function dO(){let e=U.useContext(uO);if(e===void 0)throw Error(gc(63));return e}var fO=`data-checked`,pO=`data-unchecked`,mO={...sx,checked(e){return e?{[fO]:``}:{[pO]:``}}},hO=U.forwardRef(function(e,t){let{checked:n,className:r,defaultChecked:i,"aria-labelledby":a,form:o,id:s,inputRef:c,name:l,nativeButton:u=!1,onCheckedChange:d,readOnly:f=!1,required:p=!1,disabled:m=!1,render:h,uncheckedValue:g,value:_,style:v,...y}=e,{clearErrors:b}=px(),{state:x,setTouched:S,setDirty:C,validityData:w,setFilled:T,validationMode:E,disabled:D,name:O,validation:k}=ux(),{labelId:A}=hx(),j=D||m,M=O??l,N=U.useRef(null),P=Au(N,c,k.inputRef),F=U.useRef(null),I=Vx(j,F),L=hg(),R=gx({id:s}),ee=u?void 0:R,[z,te]=Sb({controlled:n,default:!!i,name:`Switch`,state:`checked`});dx(F,L,z,void 0,!j,l),W(()=>{T(z)},[z,T]),wx(z,()=>{b(M),C(z!==w.initialValue),k.change(z)});let{getButtonProps:ne,buttonRef:re}=ev({disabled:j,native:u}),ie=eO(a,A,N,!u,ee,y[`aria-label`]),ae={id:u?R:L,role:`switch`,"aria-checked":z,"aria-readonly":f||void 0,"aria-required":p||void 0,"aria-labelledby":ie,onFocus(){I(!0)},onBlur(){let e=N.current;e&&!j&&(S(!0),I(!1),E===`onBlur`&&k.commit(e.checked))},onClick(e){if(f||j)return;e.preventDefault();let t=N.current;t&&$_(t,e)}},oe={...k.getValidationProps(j),checked:z,disabled:j,form:o,id:ee,name:M,required:p,style:M?Xu:Yu,tabIndex:-1,type:`checkbox`,"aria-hidden":!0,ref:P,onChange(e){if(e.nativeEvent.defaultPrevented)return;if(f){e.preventDefault();return}let t=e.currentTarget.checked,n=K(iu,e.nativeEvent);d?.(t,n),!n.isCanceled&&te(t)},onClick(e){e.stopPropagation()},onFocus(){F.current?.focus()},..._===void 0?mc:{value:_}},se=U.useMemo(()=>({...x,checked:z,disabled:j,readOnly:f,required:p}),[x,z,j,f,p]),ce=qf(`span`,e,{state:se,ref:[t,F,re],props:[ae,y,ne,e=>k.getValidationProps(j,e)],stateAttributesMapping:mO});return(0,q.jsxs)(uO.Provider,{value:se,children:[ce,!z&&M&&g!==void 0&&(0,q.jsx)(`input`,{type:`hidden`,form:o,name:M,value:g,disabled:j}),(0,q.jsx)(`input`,{...oe,suppressHydrationWarning:!0})]})}),gO=U.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e;return qf(`span`,e,{state:dO(),ref:t,stateAttributesMapping:mO,props:a})}),_O=({label:e,checked:t,onChange:n,disabled:r=!1,describedBy:i})=>(0,q.jsxs)(`label`,{className:nC.toggle,children:[(0,q.jsx)(cO,{"aria-describedby":i,checked:t,className:nC.box,disabled:r,onCheckedChange:e=>{n(e)},children:(0,q.jsx)(lO,{className:nC.mark,children:(0,q.jsx)(cy,{})})}),e]}),vO=({label:e,checked:t,onChange:n,disabled:r=!1})=>(0,q.jsxs)(`label`,{className:nC.toggle,children:[(0,q.jsx)(hO,{checked:t,className:nC.switch,disabled:r,onCheckedChange:e=>{n(e)},children:(0,q.jsx)(gO,{className:nC.thumb})}),e]});function yO(e){return e==null||e.hasAttribute(`disabled`)||e.getAttribute(`aria-disabled`)===`true`}var bO=U.createContext(void 0),xO=U.createContext(void 0);function SO(){let e=U.useContext(bO);if(e===void 0)throw Error(gc(60));return e}function CO(){let e=U.useContext(xO);if(e===void 0)throw Error(gc(61));return e}var wO={id:e=>e.id,labelId:e=>e.labelId,modal:e=>e.modal,multiple:e=>e.multiple,disabled:e=>e.disabled,readOnly:e=>e.readOnly,required:e=>e.required,highlightItemOnHover:e=>e.highlightItemOnHover,items:e=>e.items,itemToStringLabel:e=>e.itemToStringLabel,isItemEqualToValue:e=>e.isItemEqualToValue,value:e=>e.value,hasSelectedValue:e=>{let{value:t,multiple:n,itemToStringValue:r}=e;return t==null?!1:n&&Array.isArray(t)?t.length>0:Qb(t,r)!==``},hasNullItemLabel:(e,t)=>t?Xb(e.items):!1,open:e=>e.open,mounted:e=>e.mounted,forceMount:e=>e.forceMount,transitionStatus:e=>e.transitionStatus,openMethod:e=>e.openMethod,activeIndex:e=>e.activeIndex,selectedIndex:e=>e.selectedIndex,isActive:(e,t)=>e.activeIndex===t,isSelected:(e,t)=>{let n=e.isItemEqualToValue,r=e.value;return e.multiple?Array.isArray(r)&&r.some(e=>Rb(t,e,n)):Rb(t,r,n)},isSelectedByFocus:(e,t)=>e.selectedIndex===t,popupProps:e=>e.popupProps,triggerProps:e=>e.triggerProps,itemRoot:e=>e.itemRoot,triggerElement:e=>e.triggerElement,positionerElement:e=>e.positionerElement,listElement:e=>e.listElement,popupSide:e=>e.popupSide,scrollUpArrowVisible:e=>e.scrollUpArrowVisible,scrollDownArrowVisible:e=>e.scrollDownArrowVisible,hasScrollArrows:e=>e.hasScrollArrows};function TO(e,t){return Math.max(0,e-t)}function EO(e,t){if(t<=0)return 0;let n=E_(e,0,t),r=n,i=t-n,a=r<=1,o=i<=1;return a&&o?r<=i?0:t:a?0:o?t:n}function DO(e){let{id:t,value:n,defaultValue:r=null,onValueChange:i,open:a,defaultOpen:o=!1,onOpenChange:s,name:c,form:l,autoComplete:u,disabled:d=!1,readOnly:f=!1,required:p=!1,modal:m=!0,actionsRef:h,inputRef:g,onOpenChangeComplete:_,items:v,multiple:y=!1,itemToStringLabel:b,itemToStringValue:x,isItemEqualToValue:S=Lb,highlightItemOnHover:C=!0,children:w}=e,{clearErrors:T}=px(),{setDirty:E,setTouched:D,setFocused:O,validityData:k,setFilled:A,name:j,disabled:M,validation:N,validationMode:P}=ux(),F=gx({id:t}),I=M||d,L=j??c,[R,ee]=Sb({controlled:n,default:y?r??pc:r,name:`Select`,state:`value`}),[z,te]=Sb({controlled:a,default:o,name:`Select`,state:`open`}),ne=U.useRef([]),re=U.useRef([]),ie=U.useRef(null),ae=U.useRef(null),oe=U.useRef(0),se=U.useRef(null),ce=U.useRef([]),le=U.useRef(!1),ue=U.useRef(null),de=U.useRef(null),fe=U.useRef({allowSelectedMouseUp:!1,allowUnselectedMouseUp:!1,dragY:0}),pe=U.useRef(!1),me=U.useRef(R),{openMethod:he,triggerProps:ge}=Ex(z),_e=ic(()=>new Sm({id:F,labelId:void 0,modal:m,multiple:y,disabled:I,readOnly:f,required:p,highlightItemOnHover:C,itemToStringLabel:b,itemToStringValue:x,isItemEqualToValue:S,value:R,open:z,mounted:z,transitionStatus:void 0,items:v,forceMount:!1,openMethod:null,activeIndex:null,selectedIndex:null,popupProps:mc,triggerProps:mc,itemRoot:{props:mc,multiple:y,disabled:I,readOnly:f,isItemEqualToValue:S},triggerElement:null,positionerElement:null,listElement:null,popupSide:null,scrollUpArrowVisible:!1,scrollDownArrowVisible:!1,hasScrollArrows:!1},{setValue:fc,setOpen:fc,handleScrollArrowVisibility:fc,onOpenChangeComplete:fc,listRef:ne,popupRef:ie,scrollHandlerRef:ae,scrollArrowsMountedCountRef:oe,valueRef:se,valuesRef:ce,labelsRef:re,typingRef:le,selectionRef:fe,firstItemTextRef:ue,selectedItemTextRef:de,alignItemWithTriggerActiveRef:pe,initialValueRef:me},wO)).current,[ve,ye]=U.useState(!1),{mounted:be,transitionStatus:B,forceUnmount:xe}=Jp({open:z,ref:ie,preventUnmountOnClose:ve,setPreventUnmountOnClose:ye,onUnmount(){_e.update({activeIndex:null,openMethod:null,scrollUpArrowVisible:!1,scrollDownArrowVisible:!1}),_?.(!1)}}),Se=_e.useState(`activeIndex`),Ce=_e.useState(`selectedIndex`),we=_e.useState(`triggerElement`),Te=_e.useState(`positionerElement`),Ee=Qg(he),De=he??Ee,Oe=U.useMemo(()=>y?``:Qb(R,x),[y,R,x]),ke=U.useMemo(()=>y&&Array.isArray(R)?R.map(e=>Qb(e,x)):Qb(R,x),[y,R,x]);dx(Iu(we),F,R,J(()=>ke),!I,c);let Ae=y?Array.isArray(R)&&R.length>0:R!=null&&Oe!==``;W(()=>{A(Ae)},[Ae,A]),W(function(){let e=Ub(ce.current,R,S,y);e===null&&(de.current=null),!z&&_e.set(`selectedIndex`,e)},[y,z,R,S,_e]),wx(R,()=>{T(L),E(zb(R,k.initialValue,S)),N.change(R)});let je=J((e,t)=>{let n=t,r=nm(n);s?.(e,n),!t.isCanceled&&(e||ye(r()),te(e),e||t.reason!==`focus-out`&&t.reason!==`outside-press`||(D(!0),O(!1),P===`onBlur`&&N.commit(R)))});U.useImperativeHandle(h,()=>({unmount:xe,close:()=>{_e.state.open&&je(!1,K(Su))}}),[xe,je,_e]);let Me=J((e,t)=>{i?.(e,t),!t.isCanceled&&ee(e)}),Ne=J(e=>{let t=TO(e.scrollHeight,e.clientHeight),n=EO(e.scrollTop,t),r=n>0,i=n<t;_e.set(`scrollUpArrowVisible`,r),_e.set(`scrollDownArrowVisible`,i)}),Pe=Nm({open:z,onOpenChange:je,elements:{reference:we,floating:Te}}),Fe=Pp(Pe,{enabled:!I,event:`mousedown`}),Ie=Bp(Pe),Le=Xm(Pe,{enabled:!I,listRef:ne,activeIndex:Se,selectedIndex:Ce,disabledIndices:pc,onNavigate(e){(e!==null||z)&&_e.set(`activeIndex`,e)},focusItemOnHover:C}),Re=Zm(Pe,{enabled:!I&&(z||!f&&!y),listRef:re,activeIndex:Se,selectedIndex:Ce,disabledIndices:e=>yO(ne.current[e]),onMatch(e){z?_e.set(`activeIndex`,e):Me(ce.current[e],K(iu))},onTyping(e){le.current=e}}),ze=U.useMemo(()=>Pf(Re.reference,Le.reference,Ie.reference,Fe.reference,ge),[Fe.reference,Re.reference,Le.reference,Ie.reference,ge]),Be=U.useMemo(()=>Pf(Yp,Re.floating,Le.floating,Ie.floating),[Re.floating,Le.floating,Ie.floating]),Ve=Le.item??mc,He=U.useMemo(()=>({props:Ve,multiple:y,disabled:I,readOnly:f,isItemEqualToValue:S}),[Ve,y,I,f,S]);_e.useContextCallback(`setValue`,Me),_e.useContextCallback(`setOpen`,je),_e.useContextCallback(`handleScrollArrowVisibility`,Ne),_e.useContextCallback(`onOpenChangeComplete`,_),Cb(()=>{_e.update({popupProps:Be,triggerProps:ze,itemRoot:He})}),_e.useSyncedValues({id:F,modal:m,multiple:y,disabled:I,readOnly:f,required:p,highlightItemOnHover:C,value:R,open:z,mounted:be,transitionStatus:B,popupProps:Be,triggerProps:ze,itemRoot:He,items:v,itemToStringLabel:b,itemToStringValue:x,isItemEqualToValue:S,openMethod:De});let Ue=Au(g,N.inputRef),We=y?void 0:L,Ge=U.useMemo(()=>!y||!Array.isArray(R)||!L?null:R.map(e=>{let t=Qb(e,x);return(0,q.jsx)(`input`,{type:`hidden`,form:l,name:L,value:t,disabled:I},t)}),[y,R,l,L,x,I]);return(0,q.jsxs)(bO.Provider,{value:_e,children:[(0,q.jsx)(xO.Provider,{value:Pe,children:w}),(0,q.jsx)(`input`,{...N.getValidationProps(I,{onFocus(){_e.state.triggerElement?.focus({focusVisible:!0})},onChange(e){if(e.nativeEvent.defaultPrevented||I||f)return;let t=e.currentTarget.value,n=K(iu,e.nativeEvent);function r(){if(y)return;let e=t.toLowerCase(),r=ce.current.findIndex(t=>Qb(t,x).toLowerCase()===e||Zb(t,b).toLowerCase()===e);r===-1&&(r=ce.current.findIndex((t,n)=>{let r=re.current[n];return r!=null&&r.toLowerCase()===e}));let i=ce.current[r];i!=null&&Me(i,n)}_e.set(`forceMount`,!0),queueMicrotask(r)}}),id:F&&We==null?`${F}-hidden-input`:void 0,form:l,name:We,autoComplete:u,value:Oe,disabled:I,required:p&&!(y&&Ae),readOnly:f,ref:Ue,style:L?Xu:Yu,tabIndex:-1,"aria-hidden":!0,suppressHydrationWarning:!0}),Ge]})}var OO=U.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,o=a;delete o.id;let s=ux(),c=SO(),l=c.useState(`triggerElement`),u=c.useState(`id`),d=Nx({id:Ix(u),fallbackControlId:l?.id??u,setLabelId(e){let t=typeof e==`function`?e(c.state.labelId):e;c.set(`labelId`,t)}});return qf(`div`,e,{ref:t,state:s.state,props:[d,a],stateAttributesMapping:sx})}),kO=`data-popup-side`,AO=400,jO={...Bl,...sx,popupSide:e=>e?{[kO]:e}:null,value:()=>null},MO=U.forwardRef(function(e,t){let{render:n,className:r,id:i,disabled:a=!1,nativeButton:o=!0,style:s,...c}=e,{setTouched:l,validationMode:u,validation:d,state:f,disabled:p}=ux(),{labelId:m}=hx(),h=SO(),g=h.useState(`readOnly`),_=h.useState(`required`),v=h.useState(`disabled`),y=p||v||a,b=h.useState(`open`),x=h.useState(`mounted`),S=h.useState(`value`),C=h.useState(`triggerProps`),w=h.useState(`positionerElement`),T=h.useState(`listElement`),E=h.useState(`popupSide`),D=h.useState(`id`),O=h.useState(`labelId`),k=h.useState(`hasSelectedValue`),A=x&&w?E:null,j=i??D,M=Lx(m,O);gx({id:i});let N=Iu(w),P=U.useRef(null),F=Vx(y,P),{getButtonProps:I,buttonRef:L}=ev({disabled:y,native:o}),R=h.useStateSetter(`triggerElement`),ee=Sc(),z=Sc(),te=Sc();U.useEffect(()=>{if(b)return te.start(AO,()=>{h.context.selectionRef.current.allowUnselectedMouseUp=!0,h.context.selectionRef.current.allowSelectedMouseUp=!0}),()=>{te.clear()};h.context.selectionRef.current={allowSelectedMouseUp:!1,allowUnselectedMouseUp:!1,dragY:0},z.clear()},[b,h,z,te]);let ne=Pf(C,{id:j,role:`combobox`,"aria-expanded":b,"aria-haspopup":`listbox`,"aria-controls":b?T?.id??Zl(w)?.id:void 0,"aria-labelledby":M,"aria-readonly":g||void 0,"aria-required":_||void 0,tabIndex:y?-1:0,onFocus(e){F(!0),b&&h.context.alignItemWithTriggerActiveRef.current&&h.context.setOpen(!1,K(iu,e.nativeEvent)),ee.start(0,()=>{h.set(`forceMount`,!0)})},onBlur(e){G(w,e.relatedTarget)||(l(!0),F(!1),u===`onBlur`&&d.commit(S))},onMouseDown(e){if(b)return;let t=qu(e.currentTarget);function n(e){if(!P.current)return;let t=e.target;G(P.current,t)||G(N.current,t)||tS(e,P.current)||h.context.setOpen(!1,K(yu,e))}z.start(0,()=>{t.addEventListener(`mouseup`,n,{once:!0})})}},c,I),re=d.getValidationProps(y,ne);re.role=`combobox`;let ie={...f,open:b,disabled:y,value:S,readOnly:g,popupSide:A,placeholder:!k};return qf(`button`,e,{ref:[t,P,L,R],state:ie,stateAttributesMapping:jO,props:re})}),NO={value:()=>null},PO=U.forwardRef(function(e,t){let{className:n,render:r,children:i,placeholder:a,style:o,...s}=e,c=SO(),l=c.useState(`value`),u=c.useState(`items`),d=c.useState(`itemToStringLabel`),f=c.useState(`hasSelectedValue`),p=!f&&a!=null&&i==null,m=c.useState(`hasNullItemLabel`,p),h={value:l,placeholder:!f},g=null;return g=typeof i==`function`?i(l):i??(p&&!m?a:Array.isArray(l)?ex(l,u,d):$b(l,u,d)),qf(`span`,e,{state:h,ref:[t,c.context.valueRef],props:[{children:g},s],stateAttributesMapping:NO})}),FO=U.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e;return qf(`span`,e,{state:{open:SO().useState(`open`)},ref:t,props:[{"aria-hidden":!0,children:`▼`},a],stateAttributesMapping:zl})}),IO=U.forwardRef(function(e,t){let n=SO(),r=n.useState(`mounted`),i=n.useState(`forceMount`);return r||i?(0,q.jsx)(mp,{ref:t,...e}):null}),LO=U.createContext(void 0);function RO(){let e=U.useContext(LO);if(!e)throw Error(gc(59));return e}function zO(e,t){e&&Object.assign(e.style,t)}var BO={position:`relative`,maxHeight:`100%`,overflowX:`hidden`,overflowY:`auto`},VO={position:`fixed`},HO=U.forwardRef(function(e,t){let{anchor:n,className:r,render:i,positionMethod:a,side:o,align:s,sideOffset:c,alignOffset:l,collisionBoundary:u=`clipping-ancestors`,collisionPadding:d,arrowPadding:f,sticky:p,disableAnchorTracking:m,alignItemWithTrigger:h=!0,collisionAvoidance:g=op,style:_,...v}=e,y=SO(),b=CO(),x=y.useState(`open`),S=y.useState(`mounted`),C=y.useState(`modal`),w=y.useState(`value`),T=y.useState(`openMethod`),E=y.useState(`positionerElement`),D=y.useState(`triggerElement`),O=y.useState(`isItemEqualToValue`),k=y.useState(`transitionStatus`),A=U.useRef(null),j=U.useRef(null),[M,N]=U.useState(h),P=S&&M&&T!==`touch`;!S&&M!==h&&N(h),U.useImperativeHandle(y.context.alignItemWithTriggerActiveRef,()=>P),LS((P||C)&&x,T===`touch`,E,D);let F=Ug({anchor:n,floatingRootContext:b,positionMethod:a,mounted:S,side:o,sideOffset:c,align:s,alignOffset:l,arrowPadding:f,collisionBoundary:u,collisionPadding:d,sticky:p,disableAnchorTracking:m??P,collisionAvoidance:g,keepMounted:!0}),I=P?`none`:F.side,L=P?VO:F.positionerStyles,R={open:x,side:I,align:F.align,anchorHidden:F.anchorHidden};W(()=>{y.set(`popupSide`,F.side)},[y,F.side]);let ee=qg(e,R,{styles:L,transitionStatus:k,props:v,refs:[t,y.useStateSetter(`positionerElement`)],hidden:!S,inert:!x}),z=U.useRef(0),te=J(e=>{if(y.context.valuesRef.current.length===0)return;let t=z.current;z.current=e.size;let n=K(iu);if(t!==0&&!y.state.multiple&&w!==null&&Vb(y.context.valuesRef.current,w,O)===-1){let e=y.context.initialValueRef.current,t=e!=null&&Vb(y.context.valuesRef.current,e,O)!==-1?e:null;y.context.setValue(t,n),t===null&&(y.set(`selectedIndex`,null),y.context.selectedItemTextRef.current=null)}if(t!==0&&y.state.multiple&&Array.isArray(w)){let e=w.filter(e=>Vb(y.context.valuesRef.current,e,O)!==-1);e.length!==w.length&&(y.context.setValue(e,n),e.length===0&&(y.set(`selectedIndex`,null),y.context.selectedItemTextRef.current=null))}if(x&&P){y.update({scrollUpArrowVisible:!1,scrollDownArrowVisible:!1});let e={height:``};zO(E,e),zO(y.context.popupRef.current,e)}}),ne=U.useMemo(()=>({...F,side:I,alignItemWithTriggerActive:P,setControlledAlignItemWithTrigger:N,scrollUpArrowRef:A,scrollDownArrowRef:j}),[F,I,P,N]);return(0,q.jsx)(uS,{elementsRef:y.context.listRef,labelsRef:y.context.labelsRef,onMapChange:te,children:(0,q.jsxs)(LO.Provider,{value:ne,children:[S&&C&&(0,q.jsx)(wS,{inert:Zg(!x),cutout:D}),ee]})})}),UO=`base-ui-disable-scrollbar`,WO={className:UO,getElement(e){return(0,q.jsx)(`style`,{nonce:e,href:UO,precedence:`base-ui:low`,children:`.${UO}{scrollbar-width:none}.${UO}::-webkit-scrollbar{display:none}`})}},GO=U.createContext(void 0);function KO(e){let t=U.useContext(GO);if(t===void 0&&!e)throw Error(gc(69));return t}var qO=`--transform-origin`,JO={...Vl,...Ol},YO=U.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,...o}=e,s=SO(),c=s.useState(`multiple`),l=s.useState(`readOnly`),u=s.useState(`highlightItemOnHover`),d=CO(),{side:f,align:p,alignItemWithTriggerActive:m,isPositioned:h,setControlledAlignItemWithTrigger:g}=RO(),_=KO(!0)!=null,v=kg(),{nonce:y,disableStyleElements:b}=k(),x=s.useState(`id`),S=s.useState(`open`),C=s.useState(`openMethod`),w=s.useState(`mounted`),T=s.useState(`popupProps`),E=s.useState(`transitionStatus`),D=s.useState(`triggerElement`),O=s.useState(`positionerElement`),A=s.useState(`listElement`),j=U.useRef(!1),M=U.useRef(!1),N=U.useRef({}),P=Ku(),F=J(e=>{if(!O||!s.context.popupRef.current||!M.current)return;let t=O.style.top===`0px`,n=O.style.bottom===`0px`;if(j.current||!m||!t&&!n){s.context.handleScrollArrowVisibility(e);return}let r=QO(O),i=$O(O.getBoundingClientRect().height,`y`,r),a=qu(O),o=Kc(O),c=o.getComputedStyle(O),l=parseFloat(c.marginTop),u=parseFloat(c.marginBottom),d=XO(o.getComputedStyle(s.context.popupRef.current)),f=Math.min(a.documentElement.clientHeight-l-u,d),p=e.scrollTop,h=ZO(e),g=null,_=e=>{O.style.height=`${e}px`},v=t?h-p:p,y=Math.min(i+v,f);if(v<=1){let n=E_(v,0,f-i);n>0&&_(i+n),e.scrollTop=t?h:0,f-(i+n)<=1&&(j.current=!0),s.context.handleScrollArrowVisibility(e);return}f-y>1?g=t?1/0:0:n&&p<h&&(g=p-(v-(i+v-f)));let b=Math.ceil(y);if(b!==0&&_(b),g!=null){let t=E_(g,0,ZO(e));Math.abs(e.scrollTop-t)>1&&(e.scrollTop=t)}b>=f-1&&(j.current=!0),s.context.handleScrollArrowVisibility(e)});U.useImperativeHandle(s.context.scrollHandlerRef,()=>F,[F]),qp({open:S,ref:s.context.popupRef,onComplete(){S&&s.context.onOpenChangeComplete(!0)}});let I={open:S,transitionStatus:E,side:f,align:p};W(()=>{O&&s.context.popupRef.current&&!Object.keys(N.current).length&&(N.current={top:O.style.top||`0`,left:O.style.left||`0`,right:O.style.right,height:O.style.height,bottom:O.style.bottom,minHeight:O.style.minHeight,maxHeight:O.style.maxHeight,marginTop:O.style.marginTop,marginBottom:O.style.marginBottom})},[s,O]),W(()=>{S||m||(M.current=!1,j.current=!1,zO(O,N.current))},[S,m,O]),W(()=>{let e=s.context.popupRef.current;if(!S||!D||!O||!e||m&&!h||s.state.transitionStatus===`ending`)return;if(M.current=!0,e.style.removeProperty(qO),!m){P.request(()=>s.context.handleScrollArrowVisibility(A||e));return}let t=nk(e);try{let t=s.context.selectedItemTextRef.current;t?.isConnected||(t=!s.select(`hasSelectedValue`)&&s.context.firstItemTextRef.current?.isConnected?s.context.firstItemTextRef.current:null);let n=s.context.valueRef.current,r=Kc(O),i=r.getComputedStyle(O),a=r.getComputedStyle(e),o=qu(D),c=QO(D),l=ek(D.getBoundingClientRect(),c),d=ek(O.getBoundingClientRect(),c),f=l.height,p=A||e,m=p.scrollHeight,h=parseFloat(a.borderBottomWidth),_=parseFloat(i.marginTop)||10,y=parseFloat(i.marginBottom)||10,b=parseFloat(i.minHeight)||100,x=XO(a),S=o.documentElement.clientHeight-_-y,C=o.documentElement.clientWidth,w=S-l.bottom+f,T,E=v===`rtl`?l.right-d.width:l.left,k=0;if(t&&n){let e=ek(n.getBoundingClientRect(),c);T=ek(t.getBoundingClientRect(),c),E=d.left+(v===`rtl`?e.right-T.right:e.left-T.left);let r=e.top-l.top+e.height/2;k=T.top-d.top+T.height/2-r}let M=w+k+y+h,P=Math.min(S,M),F=S-_-y,I=M-P,L=C-5;O.style.left=`${E_(E,5,L-d.width)}px`,O.style.height=`${P}px`,O.style.maxHeight=`none`,O.style.marginTop=`${_}px`,O.style.marginBottom=`${y}px`,e.style.height=`100%`;let R=ZO(p),ee=I>=R-1;ee&&(P=Math.min(S,d.height)-(I-R));let z=l.top<20||l.bottom>S-20||Math.ceil(P)+1<Math.min(m,b),te=(r.visualViewport?.scale??1)!==1&&Pc;if(z||te){zO(O,N.current),g(!1);return}let ne=Math.max(b,P);if(ee){let e=Math.max(0,S-M);O.style.top=d.height>=F?`0`:`${e}px`,O.style.height=`${P}px`,p.scrollTop=ZO(p)}else O.style.bottom=`0`,p.scrollTop=I;if(T){let t=d.top,n=d.height,r=T.top+T.height/2,i=E_(n>0?(r-t)/n*100:50,0,100);e.style.setProperty(qO,`50% ${i}%`)}(ne===S||P>=x)&&(j.current=!0),s.context.handleScrollArrowVisibility(p),u&&s.state.selectedIndex===null&&s.state.activeIndex===null&&s.context.listRef.current[0]!=null&&s.set(`activeIndex`,0)}finally{t()}},[s,S,O,D,m,g,P,A,u,v,h]),U.useEffect(()=>{if(!m||!O||!S)return;let e=Kc(O);function t(e){s.context.setOpen(!1,K(Cu,e))}return Ou(e,`resize`,t)},[s,m,O,S]);let L={...A?{role:`presentation`}:{role:`listbox`,"aria-multiselectable":c||void 0,"aria-readonly":l||void 0,id:`${x}-list`},onKeyDown(e){_&&CC.has(e.key)&&e.stopPropagation()},onScroll(e){A||F(e.currentTarget)},...m&&{style:A?{height:`100%`}:BO},className:!A&&m?WO.className:void 0},R=qf(`div`,e,{ref:[t,s.context.popupRef],state:I,stateAttributesMapping:JO,props:[T,L,Kg(E),o]});return(0,q.jsxs)(U.Fragment,{children:[!b&&WO.getElement(y),(0,q.jsx)(Np,{context:d,modal:!1,disabled:!w,openInteractionType:C,returnFocus:a,restoreFocus:!0,children:R})]})});function XO(e){let t=e.maxHeight;return t.endsWith(`px`)&&parseFloat(t)||1/0}function ZO(e){return TO(e.scrollHeight,e.clientHeight)}function QO(e){return Hh.getScale(e)}function $O(e,t,n){return e/n[t]}function ek(e,t){return wd({x:$O(e.x,`x`,t),y:$O(e.y,`y`,t),width:$O(e.width,`x`,t),height:$O(e.height,`y`,t)})}var tk=[[`transform`,`none`],[`scale`,`1`],[`translate`,`0 0`]];function nk(e){let{style:t}=e,n={};for(let[e,r]of tk)n[e]=t.getPropertyValue(e),t.setProperty(e,r,`important`);return()=>{for(let[e]of tk){let r=n[e];r?t.setProperty(e,r):t.removeProperty(e)}}}var rk=U.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,o=SO(),s=o.useState(`multiple`),c=o.useState(`readOnly`),{alignItemWithTriggerActive:l}=RO(),u=o.useState(`hasScrollArrows`),d=o.useState(`openMethod`),f={id:`${o.useState(`id`)}-list`,role:`listbox`,"aria-multiselectable":s||void 0,"aria-readonly":c||void 0,onScroll(e){o.context.scrollHandlerRef.current?.(e.currentTarget)},...l&&{style:BO},className:u&&d!==`touch`?WO.className:void 0};return qf(`div`,e,{ref:[t,o.useStateSetter(`listElement`)],props:[f,a]})}),ik=U.createContext(void 0);function ak(){let e=U.useContext(ik);if(!e)throw Error(gc(57));return e}var ok=U.memo(U.forwardRef(function(e,t){let{render:n,className:r,style:i,value:a=null,label:o,disabled:s=!1,nativeButton:c=!1,...l}=e,u=U.useRef(null),d=GS({guess:!0,label:o,textRef:u}),f=SO(),{props:p,multiple:m,disabled:h,readOnly:g,isItemEqualToValue:_}=f.useState(`itemRoot`),v=h||s,y=f.useState(`isActive`,d.index),b=f.useState(`open`),x=f.useState(`isSelected`,a),S=f.useState(`isSelectedByFocus`,d.index),C=d.index,w=U.useRef(null);W(()=>{let e=f.context.valuesRef.current;return e[C]=a,()=>{delete e[C]}},[C,a,f]),W(()=>{let e=f.state.value,t=f.state.selectedIndex,n=t,r;m&&Array.isArray(e)?(n=Wb(C,a,f.context.valuesRef.current,e,_,t),r=n===C,C===t&&!r&&(f.context.selectedItemTextRef.current=null)):(r=e!==void 0&&Rb(a,e,_),r&&(n=C)),f.set(`selectedIndex`,n),r&&u.current&&(f.context.selectedItemTextRef.current=u.current)},[C,m,_,f,a]);let T=U.useRef(`mouse`),E=U.useRef(!1),{getButtonProps:D,buttonRef:O}=ev({disabled:v,focusableWhenDisabled:!0,native:c,composite:!0}),k={disabled:v,selected:x,highlighted:y};function A(e){if(h||g)return;let t=f.state.value;if(m){let n=Array.isArray(t)?t:[],r=x?Gb(n,a,_):[...n,a];f.context.setValue(r,K(lu,e))}else f.context.setValue(a,K(lu,e)),f.context.setOpen(!1,K(lu,e))}function j(){f.context.selectionRef.current.dragY=0}let M={role:`option`,"aria-selected":x,tabIndex:b&&y?0:-1,onKeyDown(e){f.set(`activeIndex`,C),e.key===` `&&f.context.typingRef.current&&e.preventDefault()},onClick(e){let t=T.current!==`touch`,n=e.nativeEvent.pointerType,r=t&&Bc(e.nativeEvent)&&(n!==void 0||y),i=t&&!r&&!E.current;E.current=!1,!(v||i)&&A(e.nativeEvent)},onPointerEnter(e){T.current=e.pointerType},onPointerMove(e){if(e.pointerType===`mouse`&&e.buttons===1){let t=f.context.selectionRef.current;t.dragY+=e.movementY,t.dragY**2>=64&&(t.allowUnselectedMouseUp=!0)}},onPointerDown(e){T.current=e.pointerType,E.current=!0,j()},onMouseUp(){if(j(),v||T.current===`touch`||E.current)return;let e=!f.context.selectionRef.current.allowSelectedMouseUp&&x,t=!f.context.selectionRef.current.allowUnselectedMouseUp&&!x;e||t||(E.current=!0,w.current?.click(),E.current=!1)}},N=qf(`div`,e,{ref:[O,t,d.ref,w],state:k,props:[p,M,l,D]}),P=U.useMemo(()=>({selected:x,index:C,textRef:u,selectedByFocus:S}),[x,C,u,S]);return(0,q.jsx)(ik.Provider,{value:P,children:N})})),sk=U.forwardRef(function(e,t){let{selected:n}=ak();return e.keepMounted||n?(0,q.jsx)($S,{...e,selected:n,ref:t}):null}),ck=U.memo(U.forwardRef(function(e,t){let{index:n,textRef:r,selectedByFocus:i}=ak(),a=SO(),{render:o,className:s,style:c,...l}=e;return qf(`div`,e,{ref:[U.useCallback(e=>{e&&(n===0&&(a.context.firstItemTextRef.current=e),i&&(a.context.selectedItemTextRef.current=e))},[a,n,i]),t,r],props:l})})),lk=({children:e})=>(0,q.jsx)(`span`,{className:nC.visuallyHidden,children:e}),uk=({label:e,unseen:t,options:n,value:r,onChange:i,describedBy:a})=>(0,q.jsxs)(DO,{items:n,onValueChange:e=>{e!==null&&i(e)},value:r,children:[(0,q.jsxs)(`div`,{className:nC.field,children:[(0,q.jsxs)(OO,{className:nC.label,children:[e,t===void 0?null:(0,q.jsx)(lk,{children:t})]}),(0,q.jsxs)(MO,{"aria-describedby":a,className:nC.control,children:[(0,q.jsx)(PO,{}),(0,q.jsx)(FO,{className:nC.icon,children:(0,q.jsx)(ly,{})})]})]}),(0,q.jsx)(IO,{children:(0,q.jsx)(HO,{align:`start`,alignItemWithTrigger:!1,className:o_.positioner,sideOffset:4,children:(0,q.jsx)(YO,{className:o_.popup,children:(0,q.jsx)(rk,{"aria-label":e,children:n.map(e=>(0,q.jsxs)(ok,{className:o_.item,value:e.value,children:[(0,q.jsx)(ck,{children:e.label}),(0,q.jsx)(sk,{className:nC.icon,children:(0,q.jsx)(cy,{})})]},e.value))})})})})]}),dk=U.forwardRef(function(e,t){let{render:n,className:r,id:i,name:a,value:o,disabled:s=!1,onValueChange:c,defaultValue:l,autoFocus:u=!1,style:d,...f}=e,{state:p,name:m,disabled:h,setTouched:g,setDirty:_,validityData:v,setFilled:y,validationMode:b,validation:x}=ux(),{clearErrors:S,elementRef:C,submitCountRef:w}=px(),T=h||s,E=m??a,D={...p,disabled:T},{labelId:O}=hx(),k=gx({id:i}),A=o!==void 0,j=o==null?void 0:String(o),M=J(()=>x.inputRef.current?.value);dx(x.inputRef,k,j,M,!T,a),W(()=>{let e=j??x.inputRef.current?.value;e!==void 0&&y(e!==``)},[j,l,x.inputRef,y]),wx(j,()=>{j!==void 0&&(S(E),_(j!==(v.initialValue??``)),x.change(j))});let N=U.useRef(null),P=Vx(T,N),F=Sc();return qf(`input`,e,{ref:[t,N],state:D,props:[{id:k,disabled:T,name:E,ref:x.inputRef,"aria-labelledby":O,autoFocus:u,...A?{value:o}:{defaultValue:l},onChange(e){let t=e.currentTarget.value,n=K(iu,e.nativeEvent);c?.(t,n),!A&&(_(t!==(v.initialValue??``)),y(t!==``),!e.nativeEvent.defaultPrevented&&!n.isCanceled&&(S(E),x.change(t)))},onFocus(){P(!0)},onBlur(e){if(g(!0),P(!1),b===`onBlur`){let t=e.currentTarget.value;x.commit(t),A&&queueMicrotask(()=>{let e=x.inputRef.current?.value;e!==void 0&&e!==t&&e!==(v.initialValue??``)&&x.commit(e)})}},onKeyDown(e){if(e.currentTarget.tagName===`INPUT`&&e.key===`Enter`){g(!0);let t=e.currentTarget.value,n=e.currentTarget.form;if(n&&n===C.current&&!e.defaultPrevented){let t=e.currentTarget,n=w.current;F.start(0,()=>{w.current===n&&x.commit(t.value)})}else x.commit(t)}}},f,e=>x.getValidationProps(T,e)],stateAttributesMapping:sx})}),fk=U.forwardRef(function(e,t){return(0,q.jsx)(dk,{ref:t,...e})}),pk=({label:e,unseen:t,value:n,onChange:r,onCommit:i,multiline:a=!1,rows:o=4,description:s,required:c=!1,type:l=`text`})=>{let u=(0,U.useId)(),d=`${u}-description`;return(0,q.jsxs)(`div`,{className:nC.field,children:[(0,q.jsxs)(`label`,{className:nC.label,htmlFor:u,children:[e,t===void 0?null:(0,q.jsx)(lk,{children:t}),c?` (required)`:``]}),(0,q.jsx)(`div`,{className:nC.group,children:(0,q.jsx)(fk,{"aria-describedby":s===void 0?void 0:d,className:nC.input,id:u,onBlur:i,onKeyDown:e=>{e.key===`Enter`&&!a&&i?.()},onValueChange:e=>{r(e)},render:a?(0,q.jsx)(`textarea`,{rows:o}):void 0,required:c,type:a?void 0:l,value:n})}),s===void 0?null:(0,q.jsx)(`p`,{className:nC.hint,id:d,children:(0,q.jsx)(r_,{text:s})})]})},mk={panel:`_panel_1pbue_7`,tools:`_tools_1pbue_19`,main:`_main_1pbue_35`,list:`_list_1pbue_47`,row:`_row_1pbue_60`,rowTop:`_rowTop_1pbue_97`,rowMeta:`_rowMeta_1pbue_98`,workflow:`_workflow_1pbue_130`,note:`_note_1pbue_137`,form:`_form_1pbue_146`,group:`_group_1pbue_154`,legend:`_legend_1pbue_166`,reason:`_reason_1pbue_185`,error:`_error_1pbue_186`,triggers:`_triggers_1pbue_218`,triggersTitle:`_triggersTitle_1pbue_236`,triggerList:`_triggerList_1pbue_253`,triggerName:`_triggerName_1pbue_264`,triggerLine:`_triggerLine_1pbue_272`,triggerCommand:`_triggerCommand_1pbue_281`},hk=[{value:``,label:`The workflow's, else the one ready`},...KC.map(e=>({value:e,label:e}))],gk=({workflow:e,values:t,onChange:n})=>(0,q.jsx)(q.Fragment,{children:Object.entries(e.inputs).map(([e,r])=>r.type===`boolean`?(0,q.jsx)(_O,{checked:t[e]===`true`,label:e,onChange:t=>{n(e,String(t))}},e):(0,q.jsx)(pk,{description:r.description,label:e,onChange:t=>{n(e,t)},required:r.required===!0,type:r.type===`number`?`number`:`text`,value:t[e]??``},e))}),_k=({value:e,onChange:t})=>(0,q.jsx)(uk,{label:`Driver`,onChange:e=>{let n=hk.find(t=>t.value===e);n!==void 0&&t(n.value)},options:hk,value:e}),vk=({flags:e,onChange:t})=>(0,q.jsxs)(`fieldset`,{className:mk.group,children:[(0,q.jsx)(`legend`,{className:mk.legend,children:`Flags`}),(0,q.jsx)(_k,{onChange:e=>{t({driver:e})},value:e.driver}),(0,q.jsx)(_O,{checked:e.inPlace,label:`--in-place: run worktree nodes in this checkout`,onChange:e=>{t({inPlace:e})}}),(0,q.jsx)(_O,{checked:e.allowDirty,label:`--allow-dirty: run with uncommitted instructions or skills`,onChange:e=>{t({allowDirty:e})}}),(0,q.jsx)(bk,{checked:e.machineClaude,onChange:e=>{t({machineClaude:e})}})]}),yk=`Your MCP servers and Claude's memory`,bk=({checked:e,onChange:t})=>{let n=(0,U.useId)();return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(_O,{checked:e,describedBy:n,label:`Use this machine's Claude setup`,onChange:t}),(0,q.jsx)(`p`,{className:nC.hint,id:n,children:yk})]})},xk=()=>(0,q.jsx)(qD,{cli:`ork init`,title:`No projects yet.`,children:`Run this in a repository:`}),Sk=({error:e})=>(0,q.jsx)(`p`,{className:mk.error,role:`alert`,children:(0,q.jsx)(r_,{text:e})}),Ck={driver:``,inPlace:!1,allowDirty:!1,machineClaude:!1},wk=({default:e,type:t})=>e===void 0?t===`boolean`?`false`:``:String(e),Tk=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,wk(t)])),Ek=(e,t,n)=>e===null?null:t.status===`failed`?`Cannot read the workflows of ${e}: ${t.error??`unknown error`}`:t.status===`ready`&&n===0?`${e} has no workflows. Add one to its .ork/workflows folder.`:null,Dk=(e,t,n)=>e===null?`Choose a project first`:t?`Reading workflows…`:n===0?`No workflows here`:`Type to find a workflow`,Ok=(e,t,n)=>{if(e===null)return`Pick a project.`;if(t===null)return`Pick a workflow.`;if(t.error!==void 0)return`This workflow does not parse: ${t.error}`;for(let[e,r]of Object.entries(t.inputs)){let t=n[e]??``;if(r.required===!0&&t===``)return`Fill in ${e}.`;if(r.type===`number`&&t!==``&&!Number.isFinite(Number(t)))return`${e} must be a number.`}return null},kk=(e,t)=>Object.fromEntries(Object.entries(e).flatMap(([e,n])=>{let r=t[e]??``;return r===``||r===wk(n)?[]:[[e,r]]})),Ak=/^[\w./:=@%+,-]+$/u,jk=e=>Ak.test(e)?e:`'${e.replaceAll(`'`,String.raw`'\''`)}'`,Mk=(e,t,n)=>[`ork run`,jk(e.name),`--detach`,...Object.entries(kk(e.inputs,t)).map(([e,t])=>`--input ${jk(`${e}=${t}`)}`),...n.driver===``?[]:[`--driver ${n.driver}`],...n.inPlace?[`--in-place`]:[],...n.allowDirty?[`--allow-dirty`]:[],...n.machineClaude?[`--machine-claude`]:[]].join(` `),Nk=[],Pk=e=>{let t=ob(),n=vb(t.workflows.state);(0,U.useEffect)(()=>{e!==null&&t.workflows.load(e)},[t,e]);let r=n.status!==`idle`&&n.arg===e,i=r&&n.status===`ready`?n.data:Nk;return{list:i,reading:!r||n.status===`loading`,problem:Ek(e,r?n:{status:`idle`},i.length)}},Fk=(e,t)=>[...document.querySelectorAll(`[${e}]`)].find(n=>n.getAttribute(e)===t)??null,Ik=e=>Fk(`data-run-heading`,e)??Fk(`data-run-row`,e)??document.querySelector(`[data-run-workflow]`)??!0,Lk=()=>{let e=(0,U.useRef)(null);return{onStarted:t=>{e.current=t},finalFocus:()=>{let t=e.current;return e.current=null,t===null||Ik(t)}}},Rk=(e,t)=>{let n=ob(),r=vb(n.projects.state),i=(0,U.useMemo)(()=>r.status===`ready`?r.data:[],[r]),[a]=(0,U.useState)(()=>n.runPreset.getValue()),[o,s]=(0,U.useState)(a?.project??null),[c,l]=(0,U.useState)(a?.workflow??null),[u,d]=(0,U.useState)({}),[f,p]=(0,U.useState)(Ck),[m,h]=(0,U.useState)(null),[g,_]=(0,U.useState)(!1),v=o??(i.length===1?i[0]?.id??null:null),{list:y,reading:b,problem:x}=Pk(v),S=c??(y.length===1?y[0]?.name:null),C=y.find(({name:e})=>e===S)??null,w=(0,U.useMemo)(()=>({...Tk(C?.inputs??{}),...u}),[C,u]),T=x??Ok(v,C,w);return(0,U.useEffect)(()=>{n.projects.load()},[n]),{projectsRead:r,projects:i,project:v,workflows:y,readingWorkflows:b,workflow:C,values:w,flags:f,blocked:T,refusal:m,starting:g,start:async()=>{if(T!==null||g||v===null||C===null)return;_(!0),h(null);let r=await n.startRun({project:v,workflow:C.name,inputs:kk(C.inputs,w),...f.driver===``?{}:{driver:f.driver},...f.inPlace?{inPlace:!0}:{},...f.allowDirty?{allowDirty:!0}:{},...f.machineClaude?{machineClaude:!0}:{}});_(!1),r.ok?(n.arriveAt(r.data.runId),tb.add({title:`Run ${r.data.runId} started`}),t(r.data.runId),e()):h(r.error)},setFlags:p,chooseProject:e=>{s(e),l(null),d({})},chooseWorkflow:e=>{l(e),d({})},setInput:(e,t)=>{d(n=>({...n,[e]:t}))}}},zk=({onDone:e,onStarted:t})=>{let n=Rk(e,t),{projectsRead:r,projects:i,project:a,workflows:o,workflow:s}=n,{readingWorkflows:c}=n,{values:l,flags:u,blocked:d,refusal:f,starting:p}=n,m=(0,q.jsx)(PC,{children:(0,q.jsx)(Y,{onClick:e,variant:`ghost`,children:`Close`})});return r.status===`failed`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Sk,{error:`Cannot read the projects: ${r.error}`}),m]}):r.status===`ready`&&i.length===0?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(xk,{}),m]}):(0,q.jsxs)(`form`,{className:mk.form,onSubmit:e=>{e.preventDefault(),n.start()},children:[(0,q.jsx)(aC,{empty:`No project matches.`,label:`Project`,onChange:n.chooseProject,options:i.map(({id:e})=>({value:e,label:e})),placeholder:`Type to find a project`,value:a}),(0,q.jsx)(aC,{disabled:a===null||o.length===0,empty:`No workflow matches.`,label:`Workflow`,onChange:n.chooseWorkflow,options:o.map(({name:e})=>({value:e,label:e})),placeholder:Dk(a,c,o.length),value:s?.name??null}),s===null?null:(0,q.jsx)(gk,{onChange:n.setInput,values:l,workflow:s}),(0,q.jsx)(vk,{flags:u,onChange:e=>{n.setFlags(t=>({...t,...e}))}}),s===null?null:(0,q.jsx)(cC,{command:Mk(s,l,u)}),(0,q.jsx)(`output`,{className:mk.reason,children:d}),f===null?null:(0,q.jsx)(Sk,{error:f}),(0,q.jsxs)(PC,{children:[(0,q.jsx)(Y,{onClick:e,type:`button`,variant:`ghost`,children:`Cancel`}),(0,q.jsx)(Y,{disabled:d!==null||p,focusableWhenDisabled:!0,type:`submit`,variant:`primary`,children:p?`Starting…`:`Start run`})]})]})},Bk=()=>{let{runDialog:e,runPreset:t}=ob(),n=vb(e),{finalFocus:r,onStarted:i}=Lk();return(0,q.jsx)(NC,{description:`Starts in the background, from the project's root.`,finalFocus:r,onOpenChange:n=>{n||t.setValue(null),e.setValue(n)},open:n,title:`Run workflow`,children:(0,q.jsx)(zk,{onDone:()=>{t.setValue(null),e.setValue(!1)},onStarted:i})})},Vk=e=>/mac|iphone|ipad/iu.test(e),Hk=(e,t,n)=>{let r=t.mod===!0;return e.code===t.code&&e.altKey===(t.alt===!0)&&e.shiftKey===(t.shift===!0)&&e.metaKey===(r&&n)&&e.ctrlKey===(t.ctrl===!0||r&&!n)},Uk=(e,t)=>{let n=e.glyph??e.key;return[...e.ctrl===!0?[t?`⌃`:`Ctrl`]:[],...e.mod===!0?[t?`⌘`:`Ctrl`]:[],...e.alt===!0?[t?`⌥`:`Alt`]:[],...e.shift===!0?[t?`⇧`:`Shift`]:[],n]},Wk=(e,t)=>[...e.ctrl===!0?[`Control`]:[],...e.mod===!0?[t?`Meta`:`Control`]:[],...e.alt===!0?[`Alt`]:[],...e.shift===!0?[`Shift`]:[],e.key].join(`+`),Gk=(e,t,n)=>({code:e,key:t,...n===void 0?{}:{glyph:n},alt:!0,shift:!0}),Kk={left:[`ArrowLeft`,`←`],right:[`ArrowRight`,`→`],up:[`ArrowUp`,`↑`],down:[`ArrowDown`,`↓`]},qk={palette:{code:`KeyK`,key:`K`,mod:!0},minimize:Gk(`KeyM`,`M`),maximize:Gk(`KeyX`,`X`),float:Gk(`KeyF`,`F`),close:Gk(`KeyW`,`W`),nextGroup:Gk(`BracketRight`,`]`),previousGroup:Gk(`BracketLeft`,`[`),goTo:e=>Gk(`Digit${String(e)}`,String(e)),resize:e=>{let[t,n]=Kk[e];return Gk(t,t,n)},move:e=>{let[t,n]=Kk[e];return{...Gk(t,t,n),ctrl:!0}}},Jk=9,Yk=e=>e<=Jk?qk.goTo(e):void 0,Xk=()=>Vk(navigator.platform),Zk=()=>document.querySelector(`[data-modal]`)!==null,Qk=(e,t)=>{(0,U.useEffect)(()=>{let n=Xk(),r=r=>{let i=e.palette.getValue();if(!i&&Zk())return;if(Hk(r,qk.palette,n)){r.preventDefault(),e.palette.setValue(!i);return}if(i)return;let a=t.find(({shortcut:e})=>e!==void 0&&Hk(r,e,n));a!==void 0&&(r.preventDefault(),a.disabled===void 0?a.run():e.announce(a.disabled))};return window.addEventListener(`keydown`,r),()=>{window.removeEventListener(`keydown`,r)}},[e,t])},$k={shell:`_shell_aupfr_7`,bar:`_bar_aupfr_15`,name:`_name_aupfr_34`,logoOnDark:`_logoOnDark_aupfr_44`,logoOnLight:`_logoOnLight_aupfr_45`,spacer:`_spacer_aupfr_60`,status:`_status_aupfr_64`,middle:`_middle_aupfr_80`,dockArea:`_dockArea_aupfr_90`,rail:`_rail_aupfr_95`,stack:`_stack_aupfr_117`,stacked:`_stacked_aupfr_130`,stackedHeading:`_stackedHeading_aupfr_149`,stackedButton:`_stackedButton_aupfr_158`,stackedBody:`_stackedBody_aupfr_184`,visuallyHidden:`_visuallyHidden_aupfr_196`,count:`_count_aupfr_209`},eA=({workspace:e})=>{let{notifications:t}=ob(),n=_b(t.view,e=>e.unread);return(0,q.jsxs)(xb,{label:n===0?`Notifications`:`Notifications, ${String(n)} unread`,onClick:()=>{e.goTo(`notifications`)},children:[(0,q.jsx)(Oy,{}),n===0?null:(0,q.jsx)(`span`,{className:$k.count,children:n>99?`99+`:n})]})},tA=U.createContext(void 0);function nA(e){let t=U.useContext(tA);if(t===void 0&&!e)throw Error(gc(33));return t}var rA=U.createContext(void 0);function iA(e){let t=U.useContext(rA);if(t===void 0&&!e)throw Error(gc(36));return t}var aA=U.createContext(void 0);function oA(e=!0){let t=U.useContext(aA);if(t===void 0&&!e)throw Error(gc(25));return t}var sA=U.createContext(null);function cA(e=`root`){let t=U.useContext(sA),n=U.useContext(rA);return t===null||n===void 0?null:(e===`submenu-trigger`?n.virtualFocus||n.parentVirtualFocus:n.virtualFocus)?t:null}var lA={visible:!0,ref:null};function uA(){return lA}function dA(e,t,n=`root`){let r=cA(n),i=((n===`submenu-trigger`?r?.useSubmenuTrigger:r?.useItem)??uA)({label:e.label,children:e.children,render:e.render}),a=Au(t,i.ref);return{visible:i.visible,ref:a,props:i.props}}function fA(e){e.preventDefault()}function pA(e){let{closeOnClick:t,highlighted:n,id:r,nodeId:i,store:a,typingRef:o,itemRef:s,itemMetadata:c}=e,l=iA(),u=oA(!0),d=c.type===`submenu-trigger`,f=d?l.parentVirtualFocus:l.virtualFocus,p=(d&&l.parent.type===`menu`?l.parent.store:l.store).useState(`webkitAriaSelected`,n),{events:m}=a.useState(`floatingTreeRoot`),h=a.useState(`open`),g=u!==void 0,_=!f&&h&&n?0:-1;return U.useMemo(()=>({id:r,role:`menuitem`,tabIndex:_,"aria-selected":p,onMouseDown:f?fA:void 0,onKeyDown(e){e.key===` `&&o?.current&&e.preventDefault()},onMouseMove(e){i&&m.emit(`itemhover`,{nodeId:i,target:e.currentTarget})},onClick(e){t&&m.emit(`close`,{domEvent:e.nativeEvent,reason:lu})},onMouseUp(e){if(u){let t=u.initialCursorPointRef.current;if(u.initialCursorPointRef.current=null,g&&t&&Math.abs(e.clientX-t.x)<=1&&Math.abs(e.clientY-t.y)<=1||g&&!Mc&&e.button===2)return}s.current&&a.context.allowMouseUpTriggerRef.current&&(!g||e.button===2)&&c.type===`regular-item`&&$_(s.current,e,{detail:1,pointerType:`mouse`})}}),[t,_,r,m,i,a.context.allowMouseUpTriggerRef,o,s,u,g,c.type,p,f])}var mA={type:`regular-item`};function hA(e){let{closeOnClick:t,disabled:n,highlighted:r,id:i,store:a,typingRef:o=a.context.typingRef,nativeButton:s,itemMetadata:c,nodeId:l}=e,u=U.useRef(null),{getButtonProps:d,buttonRef:f}=ev({disabled:n,focusableWhenDisabled:!0,native:s,composite:!0}),p=pA({closeOnClick:t,highlighted:r,id:i,nodeId:l,store:a,typingRef:o,itemRef:u,itemMetadata:c}),m=U.useCallback(e=>Pf(p,{onMouseEnter(e){c.type===`submenu-trigger`&&c.setActive(e.nativeEvent)}},e,d),[p,d,c]),h=Au(u,f);return U.useMemo(()=>({getItemProps:m,itemRef:h}),[m,h])}var gA=U.forwardRef(function(e,t){let{render:n,className:r,id:i,label:a,nativeButton:o=!1,disabled:s=!1,closeOnClick:c=!0,style:l,...u}=e,{store:d}=iA(),f=GS({guess:!0,label:a}),p=hg(i),m=d.useState(`disabled`),h=d.useState(`isActive`,f.index),g=d.useState(`floatingNodeId`),_=d.useState(`itemProps`),v=s||m,{getItemProps:y,itemRef:b}=hA({closeOnClick:c,disabled:v,highlighted:h,id:p,store:d,nativeButton:o,nodeId:g,itemMetadata:mA});return qf(`div`,e,{state:{disabled:v,highlighted:h},props:[_,u,y],ref:[b,t,f.ref]})}),_A=U.forwardRef(function(e,t){let n=dA(e,t);return n.visible?(0,q.jsx)(gA,{...e,ref:n.ref}):null}),vA=U.createContext(void 0);function yA(){return U.useContext(vA)}function bA(e,t){let n=Zf(e.render);if(U.isValidElement(n)){let e=n.props;if(Object.hasOwn(e,`id`))return e.id??``}return e.id??t}function xA(e,t,n){let r=bA(e,t),i=r===t?void 0:r;return[r,U.useCallback(e=>n?.(e?i:void 0),[i,n])]}function SA(e,t,n){let r=Zf(e.render),i=U.isValidElement(r)?r.props:void 0,a=e[`aria-label`]??i?.[`aria-label`],o=e[`aria-labelledby`]??i?.[`aria-labelledby`];return o==null&&!a&&(o=t?t.id||void 0:n||void 0),o}var CA=U.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,id:o,initialFocus:s,...c}=e,{store:l,defaultFloatingId:u,setRenderedFloatingId:d,virtualFocus:f,orientation:p}=iA(),m=yA(),{side:h,align:g}=nA(),_=KO(!0)!=null,v=l.useState(`open`),y=l.useState(`transitionStatus`),b=l.useState(`popupProps`),x=l.useState(`mounted`),S=l.useState(`instantType`),C=l.useState(`activeTriggerElement`),w=l.useState(`parent`),T=l.useState(`lastOpenChangeReason`),E=l.useState(`rootId`),D=l.useState(`floatingRootContext`),O=l.useState(`floatingTreeRoot`),k=l.useState(`closeDelay`),A=l.useState(`hoverEnabled`),j=l.useState(`disabled`),M=l.useState(`openMethod`),N=l.useState(`activeTriggerId`),P=l.useState(`listElement`),[F,I]=xA(e,u,d),L=SA(e,C,N),R=w.type===`menu`?m:void 0,ee=w.type===`context-menu`,z=s??w.type!==`menu`;s===void 0&&P&&w.type!==`menu`&&(z=()=>l.state.activeIndex===null&&P),qp({open:v,ref:l.context.popupRef,onComplete(){v&&l.context.onOpenChangeComplete?.(!0)}}),U.useEffect(()=>{function e(e){l.setOpen(!1,K(e.reason,e.domEvent))}return O.events.on(`close`,e),()=>{O.events.off(`close`,e)}},[O.events,l]),Vm(D,{enabled:A&&!j&&!ee&&w.type!==`menubar`,closeDelay:k});let te=l.useStateSetter(`popupElement`),{parentVirtualFocusRef:ne,handleFocus:re}=(U.useContext(sA)?.useParentHandoff??TA)(l,w,v,f),ie=qf(`div`,e,{state:{transitionStatus:y,side:h,align:g,open:v,nested:w.type===`menu`,instant:S},ref:[t,l.context.popupRef,te,I],stateAttributesMapping:Hl,props:[b,{id:F,...P?{role:`presentation`}:{role:`menu`,"aria-orientation":p===`horizontal`?`horizontal`:void 0,"aria-labelledby":L},onKeyDown(e){R?.onPopupKeyDown?.(e),_&&CC.has(e.key)&&e.stopPropagation()},onFocus:re},Kg(y),c,{"data-rootownerid":E}]}),ae=w.type===void 0||ee;(C||w.type===`menubar`&&T!==`outside-press`)&&(ae=!0);let oe=R?.getReturnElement??ne;return(0,q.jsx)(Np,{context:D,openInteractionType:M,modal:ee,disabled:!x,returnFocus:a??oe??ae,explicitReturnFocus:a===void 0&&oe?!1:void 0,initialFocus:z,restoreFocus:!0,getInsideElements:w.type===void 0?()=>[l.context.beforeTriggerFocusGuardRef.current]:void 0,externalTree:w.type===`menubar`?void 0:O,previousFocusableElement:C,nextFocusableElement:w.type===void 0?l.context.triggerFocusTargetRef:void 0,beforeContentFocusGuardRef:l.context.beforeContentFocusGuardRef,children:ie})}),wA={parentVirtualFocusRef:void 0,handleFocus:void 0};function TA(){return wA}var EA=U.forwardRef(function(e,t){let n=cA()?.Popup??CA;return(0,q.jsx)(n,{...e,ref:t})}),DA=U.createContext(void 0);function OA(){let e=U.useContext(DA);if(e===void 0)throw Error(gc(32));return e}var kA=U.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,{store:i,parent:a}=iA();if(!(i.useState(`mounted`)||n))return null;let o=a.type===`menu`||a.type===`menubar`?`group`:void 0;return(0,q.jsx)(DA.Provider,{value:n,children:(0,q.jsx)(mp,{ref:t,...r,portalOwnerRole:o})})});function AA(e){let{store:t,domReference:n,positionerElement:r,open:i}=e,a=U.useRef(null),o=U.useRef(null),s=Kp(r);W(()=>{i||(o.current?.abort(),o.current=null,t.state.instantType===`trigger-change`&&t.set(`instantType`,void 0))},[i,t]),W(()=>{let e=n,r=a.current;if(e&&(a.current=e),!r||!e||e===r||!t.select(`open`))return;t.set(`instantType`,void 0);let i=new AbortController;return o.current=i,s(()=>{t.select(`open`)&&t.set(`instantType`,`trigger-change`)},i.signal),()=>{i.abort()}},[n,s,t])}var jA=U.forwardRef(function(e,t){let{anchor:n,positionMethod:r=`absolute`,className:i,render:a,side:o,align:s,sideOffset:c=0,alignOffset:l=0,collisionBoundary:u=`clipping-ancestors`,collisionPadding:d=5,arrowPadding:f=5,sticky:p=!1,disableAnchorTracking:m=!1,collisionAvoidance:h=op,style:g,..._}=e,{store:v,virtualFocus:y,syncHighlightedItem:b}=iA(),x=OA(),S=oA(!0),C=v.useState(`parent`),w=v.useState(`floatingRootContext`),T=v.useState(`floatingTreeRoot`),E=v.useState(`mounted`),D=v.useState(`open`),O=v.useState(`modal`),k=v.useState(`openMethod`),A=v.useState(`activeTriggerElement`),j=v.useState(`transitionStatus`),M=v.useState(`positionerElement`),N=v.useState(`instantType`),P=v.useState(`adaptiveOrigin`),F=v.useState(`lastOpenChangeReason`),I=v.useState(`floatingNodeId`),L=v.useState(`floatingParentNodeId`),R=w.useState(`domReferenceElement`),ee=n,z=c,te=l,ne=s,re=h;C.type===`context-menu`&&(ee=n??C.context?.anchor,ne??=`start`,!o&&ne!==`center`&&(te=e.alignOffset??2,z=e.sideOffset??-5));let ie=o,ae=ne;C.type===`menu`?(ie??=`inline-end`,ae??=`start`,re=e.collisionAvoidance??sp):C.type===`menubar`&&(ie??=C.context.orientation===`vertical`?`inline-end`:`bottom`,ae??=`start`);let oe=C.type===`context-menu`,se=Ug({anchor:ee,floatingRootContext:w,positionMethod:S?`fixed`:r,mounted:E,side:ie,sideOffset:z,align:ae,alignOffset:te,arrowPadding:oe?0:f,collisionBoundary:u,collisionPadding:d,sticky:p,nodeId:I,keepMounted:x,disableAnchorTracking:m,collisionAvoidance:re,shift:oe?{crossAxis:!(`side`in re&&re.side===`flip`),rootBoundary:`layoutViewport`}:void 0,externalTree:T,adaptiveOrigin:P,lazyFlip:y?`placement`:!1});U.useEffect(()=>{function e(e){e.open&&(e.parentNodeId===I&&v.set(`hoverEnabled`,!1),e.nodeId!==I&&e.parentNodeId===v.select(`floatingParentNodeId`)&&v.setOpen(!1,K(bu)))}return T.events.on(`menuopenchange`,e),()=>{T.events.off(`menuopenchange`,e)}},[v,T.events,I]),U.useEffect(()=>{if(v.select(`floatingParentNodeId`)==null)return;function e(e){if(e.open||e.nodeId!==v.select(`floatingParentNodeId`))return;let t=e.reason??`sibling-open`;v.setOpen(!1,K(t))}return T.events.on(`menuopenchange`,e),()=>{T.events.off(`menuopenchange`,e)}},[T.events,v]);let ce=Sc();U.useEffect(()=>{D||ce.clear()},[D,ce]),U.useEffect(()=>{function e(e){if(D&&e.nodeId===v.select(`floatingParentNodeId`)){if(e.target&&A&&A!==e.target){let e=v.select(`closeDelay`);e>0?ce.isStarted()||ce.start(e,()=>{v.setOpen(!1,K(bu))}):v.setOpen(!1,K(bu))}else ce.clear()}}return T.events.on(`itemhover`,e),()=>{T.events.off(`itemhover`,e)}},[T.events,D,A,v,ce]),U.useEffect(()=>{let e={open:D,nodeId:I,parentNodeId:L,reason:v.select(`lastOpenChangeReason`)};T.events.emit(`menuopenchange`,e)},[T.events,D,v,I,L]),AA({store:v,domReference:R,positionerElement:M,open:D});let le={open:D,side:se.side,align:se.align,anchorHidden:se.anchorHidden,nested:C.type===`menu`,instant:N},ue=C.type===`menubar`&&C.context.modal;LS(D&&(ue||O&&F!==`trigger-hover`),k===`touch`,M,A);let de=qg(e,le,{styles:se.positionerStyles,transitionStatus:j,props:_,refs:[t,v.useStateSetter(`positionerElement`)],hidden:!E,inert:!D}),fe=E&&C.type!==`menu`&&(C.type!==`menubar`&&O&&F!==`trigger-hover`||C.type===`menubar`&&C.context.modal),pe=null;return C.type===`menubar`?pe=C.context.contentElement:C.type===void 0&&(pe=A),(0,q.jsxs)(tA.Provider,{value:se,children:[fe&&(0,q.jsx)(wS,{ref:C.type===`context-menu`||C.type===`nested-context-menu`?C.context.internalBackdropRef:null,inert:Zg(!D),cutout:pe}),(0,q.jsx)(Sp,{id:I,children:(0,q.jsx)(uS,{elementsRef:v.context.itemDomElements,labelsRef:v.context.itemLabels,onMapChange:b,children:de})})]})}),MA=U.createContext(null);function NA(e){let t=U.useContext(MA);if(t===null&&!e)throw Error(gc(5));return t}var PA={...jm,disabled:e=>e.parent.type===`menubar`&&e.parent.context.disabled||e.disabled,modal:e=>(e.parent.type===void 0||e.parent.type===`context-menu`)&&(e.modal??!0),openMethod:e=>e.openMethod,keyboardOpen:e=>e.keyboardOpen,allowMouseEnter:e=>e.allowMouseEnter,highlightItemOnHover:e=>e.highlightItemOnHover,parent:e=>e.parent,rootId:e=>e.parent.type===`menu`?e.parent.store.select(`rootId`):e.parent.type===void 0?e.rootId:e.parent.context.rootId,activeIndex:e=>e.activeIndex,listElement:e=>e.listElement,triggerControlsId:(e,t)=>{let n=jm.triggerPopupId(e,t);return n?e.listElement?.id||n:void 0},filterTriggerProps:e=>e.filterTriggerProps,inputProps:e=>e.inputProps,webkitAriaSelected:(e,t)=>Pc&&e.inputFocused&&t?!0:void 0,highlightedItemId:e=>e.highlightedItem?.id||void 0,isActive:(e,t)=>e.activeIndex===t,hoverEnabled:e=>e.hoverEnabled,instantType:e=>e.instantType===`trigger-change`&&!jm.open(e)?void 0:e.instantType,lastOpenChangeReason:e=>e.openChangeReason,floatingTreeRoot:e=>e.parent.type===`menu`?e.parent.store.select(`floatingTreeRoot`):e.floatingTreeRoot,floatingNodeId:e=>e.floatingNodeId,floatingParentNodeId:e=>e.floatingParentNodeId,itemProps:e=>e.itemProps,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin,keyboardEventRelay:e=>{if(e.keyboardEventRelay)return e.keyboardEventRelay;if(e.parent.type===`menu`)return e.parent.store.select(`keyboardEventRelay`)}},FA=class extends Sm{constructor(e,t,n=!1){let r=new lm,i=LA(r,t,n,e);super(i,IA(r),PA),this.observe(`parent`,e=>{e.type===`menu`?this.context.allowMouseUpTriggerRef=e.store.context.allowMouseUpTriggerRef:e.type!==void 0&&(this.context.allowMouseUpTriggerRef=e.context.allowMouseUpTriggerRef)})}subscribeToParentMenu(){let e=this.state.parent;if(e.type!==`menu`)return;let t=e.store.select(`rootId`),n=e.store.select(`floatingTreeRoot`),r=e.store.select(`keyboardEventRelay`);return e.store.subscribe(()=>{let i=e.store.select(`rootId`),a=e.store.select(`floatingTreeRoot`),o=e.store.select(`keyboardEventRelay`);(t!==i||n!==a||r!==o)&&(t=i,n=a,r=o,this.notifyAll())})}setOpen(e,t){this.state.floatingRootContext.context.events.emit(`setOpen`,{open:e,eventDetails:t})}setActiveIndex(e,t,n){if(this.state.activeIndex!==e){let r=(e===null?void 0:this.context.itemDomElements.current[e])===this.context.reportedItem;this.context.highlightReason=r?`none`:t,this.context.highlightEvent=r?void 0:n}this.set(`activeIndex`,e)}highlightItem(e,t,n){let r=this.context.itemDomElements.current.indexOf(e);r>-1&&this.setActiveIndex(r,t,n)}};function IA(e){return{positionerRef:U.createRef(),popupRef:U.createRef(),typingRef:{current:!1},itemDomElements:{current:[]},itemLabels:{current:[]},highlightReason:`none`,highlightEvent:void 0,reportedItem:void 0,allowMouseUpTriggerRef:{current:!1},virtualFocusRef:void 0,triggerFocusTargetRef:U.createRef(),beforeTriggerFocusGuardRef:U.createRef(),beforeContentFocusGuardRef:U.createRef(),onOpenChangeComplete:void 0,triggerElements:e}}function LA(e,t,n=!1,r){return{...Tm(e,t,n),disabled:!1,modal:!0,openMethod:null,keyboardOpen:!1,allowMouseEnter:!1,highlightItemOnHover:!0,parent:{type:void 0},rootId:void 0,activeIndex:null,listElement:null,filterTriggerProps:mc,inputProps:mc,inputFocused:!1,highlightedItem:void 0,hoverEnabled:!0,instantType:void 0,openChangeReason:null,floatingTreeRoot:new gp,floatingNodeId:void 0,floatingParentNodeId:null,itemProps:mc,keyboardEventRelay:void 0,closeDelay:0,adaptiveOrigin:void 0,...r}}var RA=U.createContext(null);function zA(e,t){return(e===`trigger-press`||e===`item-press`)&&t?.detail===0}function BA(e,t){return e===`list-navigation`||zA(e,t)}var VA=lc(function(e){let{children:t,open:n,onOpenChange:r,onOpenChangeComplete:i,onItemHighlighted:a,defaultOpen:o=!1,disabled:s=!1,modal:c,loopFocus:l=!0,orientation:u=`vertical`,actionsRef:d,closeParentOnEsc:f=!1,handle:p,triggerId:m,defaultTriggerId:h=null,highlightItemOnHover:g=!0,isSubmenu:_=!1,virtualFocus:v=!1,virtualFocusRef:y,allowEscape:b=!0,resetOnPointerLeave:x=!0}=e,S=oA(!0),C=iA(!0),w=NA(!0),T=C?.store,E=C?.virtualFocus??!1,D=U.useMemo(()=>_&&T?{type:`menu`,store:T}:w?{type:`menubar`,context:w}:S&&!T?{type:`context-menu`,context:S}:{type:void 0},[S,T,w,_]),O=hg(),k=hg(),[A,j]=U.useState(void 0),M=(A??k)||void 0,N=yp(),P=D.type===`menu`?D.store:void 0,F=(n??o)&&P?.state.transitionStatus===`starting`,I=ic(()=>F?P?.state.instantType:void 0).current,L=ic(()=>{let e=new FA({open:o,openProp:n,activeTriggerId:h,triggerIdProp:m,parent:D,disabled:s,highlightItemOnHover:g,modal:D.type===void 0?c:void 0,rootId:O,instantType:I},M,N!=null);return e.context.virtualFocusRef=y,e}).current;L.useControlledProp(`openProp`,n),L.useControlledProp(`triggerIdProp`,m),L.useContextCallback(`onOpenChangeComplete`,i);let R=L.useState(`floatingTreeRoot`),ee=xp(R),z=L.useState(`open`),te=L.useState(`activeTriggerElement`),ne=L.useState(`positionerElement`),re=L.useState(`hoverEnabled`),ie=L.useState(`disabled`),ae=L.useState(`lastOpenChangeReason`),oe=L.useState(`parent`),se=L.useState(`activeIndex`),ce=L.useState(`keyboardOpen`),le=L.useState(`payload`),ue=L.useState(`floatingParentNodeId`),de=U.useRef(null),fe=U.useRef(oe.type!==`context-menu`),pe=Sc(),me=U.useRef(!0),he=Sc(),ge=ue!=null,{openMethod:_e,triggerProps:ve}=Ex(z);L.useSyncedValues({disabled:s,highlightItemOnHover:g,modal:oe.type===void 0?c:void 0,openMethod:_e,rootId:O}),am(L);let{forceUnmount:ye,transitionStatus:be}=om(z,L,()=>{L.set(`allowMouseEnter`,!1)},F),B=Kp(L.context.popupRef);U.useEffect(()=>{if(I===void 0)return;let e=()=>{L.state.instantType===I&&L.set(`instantType`,void 0)};if(!z){e();return}if(be!==void 0)return;if(L.context.popupRef.current==null){e();return}let t=new AbortController;return B(e,t.signal),()=>{t.abort()}},[I,z,be,B,L]),W(()=>{S&&!C?L.update({parent:{type:`context-menu`,context:S},floatingNodeId:ee,floatingParentNodeId:N}):(C||!L.select(`activeTriggerElement`))&&L.update({floatingNodeId:ee,floatingParentNodeId:N})},[S,C,ee,N,te,L]),U.useEffect(()=>{z||(de.current=null),oe.type===`context-menu`&&(z?pe.start(500,()=>{fe.current=!0}):(pe.clear(),fe.current=!1))},[pe,z,oe.type]),W(()=>{!z&&!re&&L.set(`hoverEnabled`,!0)},[z,re,L]);let xe=J((e,t)=>{let n=t.reason;if(!e&&!L.select(`open`)||z===e&&t.trigger===te&&ae===n)return;let i=nm(t);if(!e&&t.trigger==null&&(t.trigger=te??void 0),r?.(e,t),t.isCanceled)return;L.state.floatingRootContext.dispatchOpenChange(e,t);let a=t.event;if(e===!1&&n!==`item-press`&&a?.type===`click`&&a.pointerType===`touch`&&!me.current)return;e&&n===`trigger-focus`?(me.current=!1,he.start(300,()=>{me.current=!0})):(me.current=!0,he.clear());let o=!e&&(n===`escape-key`||n==null);de.current=t.event;let s=tm(L.state,e,t.trigger,i());s.openChangeReason=n,s.keyboardOpen=e&&BA(n,a),s.instantType=oe.type===`menubar`&&(n===`trigger-focus`||n===`focus-out`||n===`trigger-hover`||n===`list-navigation`||n===`sibling-open`)?`group`:zA(n,a)?`click`:o?`dismiss`:void 0,L.update(s)}),Se=Vp({popupStore:L,floatingRootContext:L.state.floatingRootContext,floatingId:M,nested:N!=null,onOpenChange:xe}),Ce=Se.context.events;W(()=>{let e=({open:e,eventDetails:t})=>xe(e,t);return Ce.on(`setOpen`,e),()=>{Ce?.off(`setOpen`,e)}},[Ce,xe]),W(()=>L.subscribeToParentMenu(),[L]);let we=U.useCallback(()=>{L.setOpen(!1,K(Su))},[L]);U.useImperativeHandle(d,()=>({unmount:ye,close:we}),[ye,we]);let Te;oe.type===`context-menu`&&(Te=oe.context),U.useImperativeHandle(Te?.positionerRef,()=>ne,[ne]),U.useImperativeHandle(Te?.actionsRef,()=>({setOpen:xe}),[xe]);let Ee=Bp(Se,{enabled:!ie,bubbles:{escapeKey:f&&oe.type===`menu`},outsidePress(){return oe.type!==`context-menu`||de.current?.type===`contextmenu`||fe.current},externalTree:ge?R:void 0}),De=kg(),Oe=Xm(Se,{enabled:!ie,listRef:L.context.itemDomElements,activeIndex:se,virtual:v,nested:oe.type===`menubar`||!v&&oe.type!==void 0,parentOrientation:oe.type===`menubar`?oe.context.orientation:void 0,loopFocus:l,focusItemOnOpen:v?ce:void 0,allowEscape:v&&l&&b,orientation:u,triggerOrientation:v?`vertical`:u,rtl:De===`rtl`,disabledIndices:pc,onNavigate(e,t){L.setActiveIndex(e,Tb(t),t?.nativeEvent)},openOnArrowKeyDown:oe.type!==`context-menu`&&!(v&&_),externalTree:!v&&ge?R:void 0,nestedReturnFocusRef:P?.context.virtualFocusRef,focusItemOnHover:g,resetOnPointerLeave:x}),ke=U.useCallback(e=>{L.context.typingRef.current=e},[L]),Ae=Zm(Se,{enabled:!ie&&!v,listRef:L.context.itemLabels,elementsRef:L.context.itemDomElements,activeIndex:se,resetMs:500,onMatch:(e,t)=>{z&&e!==se&&L.setActiveIndex(e,_u,t.nativeEvent)},onTyping:ke}),je=J(a),Me=U.useRef(-1),Ne=J(()=>{let e=L.state.activeIndex,t=e===null?void 0:L.context.itemDomElements.current[e]??void 0;if(t?.isConnected===!1)return;let n=t===void 0?-1:e;if(Me.current===n&&L.context.reportedItem===t)return;Me.current=n,L.context.reportedItem=t,v&&L.set(`highlightedItem`,t);let{highlightReason:r,highlightEvent:i}=L.context;L.context.highlightReason=iu,L.context.highlightEvent=void 0,a&&je(t,ru(r,i,{label:t===void 0?void 0:L.context.itemLabels.current[n]??void 0}))});W(()=>{Ne()},[se,Ne]);let Pe=U.useMemo(()=>{if(!v)return Oe.reference;if(!Oe.trigger)return mc;let{onFocus:e,...t}=Oe.trigger;return t},[v,Oe.reference,Oe.trigger]);L.useSyncedValue(`inputProps`,v?Oe.reference??mc:mc);let Fe=U.useMemo(()=>{let e=Pf(Ae.reference,Pe,Ee.reference,{onMouseMove(){L.set(`allowMouseEnter`,!0)}},ve);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=z,e},[L,Ae.reference,Pe,Ee.reference,ve,z]),Ie=U.useMemo(()=>{let e=Pf(Oe.trigger,Ee.trigger,ve);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=!1,e},[Oe.trigger,Ee.trigger,ve]);ic(()=>(L.update({inactiveTriggerProps:Ie}),null)),sm(L,{floatingRootContext:Se,activeTriggerProps:Fe,inactiveTriggerProps:Ie,popupProps:U.useMemo(()=>Pf(Yp,{onMouseMove(){L.set(`allowMouseEnter`,!0),oe.type===`menu`&&L.set(`hoverEnabled`,!1)},onClick(){L.select(`hoverEnabled`)&&L.set(`hoverEnabled`,!1)},onKeyDown(e){let t=L.select(`keyboardEventRelay`);t&&!e.isPropagationStopped()&&t(e)}},Ae.floating,Oe.floating,Ee.floating),[oe.type,L,Ae.floating,Oe.floating,Ee.floating]),itemProps:Oe.item??mc});let Le=U.useMemo(()=>({store:L,parent:D,orientation:u,loopFocus:l,allowEscape:b,defaultFloatingId:k,setRenderedFloatingId:j,virtualFocus:v,parentVirtualFocus:E,syncHighlightedItem:Ne}),[L,D,u,l,b,k,v,E,Ne]),Re=typeof t==`function`?t({payload:le}):t,ze=(0,q.jsxs)(rA.Provider,{value:Le,children:[p&&(0,q.jsx)(Qp,{handle:p,store:L}),Re]});return(oe.type===void 0||oe.type===`context-menu`)&&(ze=(0,q.jsx)(Cp,{externalTree:R,children:ze})),ze});function HA(e){let t=U.useContext(RA);if(t===null)return(0,q.jsx)(VA,{...e});let n=t.Root;return(0,q.jsx)(RA.Provider,{value:null,children:(0,q.jsx)(n,{...t.options,...e})})}function UA(e={}){let{highlightItemOnHover:t,highlightedIndex:n,onHighlightedIndexChange:r}=Z_(),{ref:i,index:a}=GS(e),o=n===a,s=U.useRef(null),c=Au(i,s);return{compositeProps:{tabIndex:o?0:-1,onFocus(){r(a)},onMouseMove(){let e=s.current;if(!t||!e)return;let n=e.hasAttribute(`disabled`)||e.ariaDisabled===`true`;!o&&!n&&e.focus()}},compositeRef:c,index:a}}function WA(e){let{render:t,className:n,style:r,state:i=mc,props:a=pc,refs:o=pc,metadata:s,stateAttributesMapping:c,tag:l=`div`,...u}=e,{compositeProps:d,compositeRef:f}=UA({metadata:s});return qf(l,e,{state:i,ref:[f,...o],props:[d,...a,u],stateAttributesMapping:c})}function GA(e){if(Xc(e)&&e.hasAttribute(`data-rootownerid`))return e.getAttribute(`data-rootownerid`);if(!cl(e))return GA(dl(e))}function KA(e,t){function n(n,r,i){let a=n.currentTarget;lp.flushSync(()=>{e.setOpen(!1,K(mu,n.nativeEvent,a))}),ef(a.isConnected?a:t.current,r,i)?.focus()}function r(t){n(t,-1,e.select(`positionerElement`))}function i(t){let r=e.select(`positionerElement`);r&&tf(t,r)?e.context.beforeContentFocusGuardRef.current?.focus():n(t,1,r)}return{handlePreFocusGuardFocus:r,handleFocusTargetFocus:i}}function qA(e){let{enabled:t=!0,mouseDownAction:n,open:r}=e,i=U.useRef(!1);return U.useMemo(()=>t?{onMouseDown:e=>{(n===`open`&&!r||n===`close`&&r)&&(i.current=!0,qu(e.currentTarget).addEventListener(`click`,()=>{i.current=!1},{once:!0}))},onClick:e=>{i.current&&(i.current=!1,e.preventBaseUIHandler())}}:mc,[t,n,r])}var JA=uc(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,id:s,openOnHover:c,delay:l=100,closeDelay:u=0,handle:d,payload:f,...p}=e,m=iA(!0),h=Mm(d)??m?.store;if(!h)throw Error(gc(85));let g=hg(s),_=h.useState(`isTriggerActive`,g),v=h.useState(`floatingRootContext`),y=h.useState(`isOpenedByTrigger`,g),b=h.useState(`triggerControlsId`,g),x=U.useRef(null),S=XA(),C=Z_(!0),w=bp(),T=U.useMemo(()=>w??new gp,[w]),{registerTrigger:E,isMountedByThisTrigger:D}=im(g,x,h,{payload:f,closeDelay:u,parent:S,floatingTreeRoot:T,floatingNodeId:xp(T),floatingParentNodeId:yp(),keyboardEventRelay:C?.relayKeyboardEvent}),O=S.type===`menubar`,k=h.useState(`disabled`),A=a||k||O&&S.context.disabled,{getButtonProps:j,buttonRef:M}=ev({disabled:A,native:o});U.useEffect(()=>{!y&&S.type===void 0&&(h.context.allowMouseUpTriggerRef.current=!1)},[h,y,S.type]);let N=U.useRef(null),P=Sc(),F=J(e=>{if(!N.current)return;P.clear(),h.context.allowMouseUpTriggerRef.current=!1;let t=e.target;G(N.current,t)||G(h.select(`positionerElement`),t)||t===N.current||t!=null&&GA(t)===h.select(`rootId`)||tS(e,N.current)||T.events.emit(`close`,{domEvent:e,reason:yu})});U.useEffect(()=>{let e=qu(N.current);if(y&&h.select(`lastOpenChangeReason`)===`trigger-hover`)return e.addEventListener(`mouseup`,F,{once:!0}),()=>{e.removeEventListener(`mouseup`,F)}},[y,F,h]);let I=O&&S.context.hasSubmenuOpen,L=Um(v,{enabled:(c??I)&&!A&&(!O||I&&!D),handleClose:ah({blockPointerEvents:!O}),mouseOnly:!0,move:!1,restMs:S.type===void 0?l:void 0,delay:{close:u},triggerElementRef:x,externalTree:T,isActiveTrigger:_,isClosing:()=>h.select(`transitionStatus`)===`ending`}),R=YA(y,h.select(`lastOpenChangeReason`)),ee=Pp(v,{enabled:!A,event:y&&O?`click`:`mousedown`,toggle:!0,ignoreMouse:!1,stickIfOpen:S.type===void 0&&R}),z=Fm(v,{enabled:!A&&I}),te=qA({open:y,enabled:O,mouseDownAction:`open`}),ne=U.useMemo(()=>Pf(z.reference,ee.reference),[z.reference,ee.reference]),re=h.useState(`triggerProps`,D),ie=h.useState(`filterTriggerProps`),{handlePreFocusGuardFocus:ae,handleFocusTargetFocus:oe}=KA(h,x),se={disabled:A,open:y},ce=[N,t,M,E,x],le=[ne,L??mc,re,{"aria-haspopup":`menu`,"aria-controls":b,id:g,onMouseDown:e=>{h.select(`open`)||(P.start(200,()=>{h.context.allowMouseUpTriggerRef.current=!0}),qu(e.currentTarget).addEventListener(`mouseup`,F,{once:!0}))}},ie,O?{role:`menuitem`}:{},te,p,j],ue=qf(`button`,e,{enabled:!O,stateAttributesMapping:Bl,state:se,ref:ce,props:le});return O?(0,q.jsx)(WA,{tag:`button`,render:n,className:r,style:i,state:se,refs:ce,props:le,stateAttributesMapping:Bl}):y?(0,q.jsxs)(U.Fragment,{children:[(0,q.jsx)(Zu,{ref:h.context.beforeTriggerFocusGuardRef,onFocus:ae},`${g}-pre-focus-guard`),(0,q.jsx)(U.Fragment,{children:ue},g),(0,q.jsx)(Zu,{ref:h.context.triggerFocusTargetRef,onFocus:oe},`${g}-post-focus-guard`)]}):(0,q.jsx)(U.Fragment,{children:ue},g)});function YA(e,t){let n=Sc(),[r,i]=U.useState(!1);return W(()=>{e&&t===`trigger-hover`?(i(!0),n.start(500,()=>{i(!1)})):e||(n.clear(),i(!1))},[e,t,n]),r}function XA(){let e=NA(!0);return U.useMemo(()=>e?{type:`menubar`,context:e}:{type:void 0},[e])}var ZA=U.forwardRef(function(e,t){let{className:n,render:r,orientation:i=`horizontal`,style:a,...o}=e;return qf(`div`,e,{state:{orientation:i},ref:t,props:[{role:`separator`,"aria-orientation":i},o]})}),QA=(e,t)=>e===`separator`?`separator-${String(t)}`:e.label,$A=({entry:e})=>e===`separator`?(0,q.jsx)(ZA,{className:o_.separator}):(0,q.jsxs)(_A,{className:o_.item,"data-variant":e.danger===!0?`danger`:`default`,disabled:e.disabled??!1,onClick:e.onSelect,children:[(0,q.jsx)(`span`,{children:e.label}),e.detail===void 0?null:(0,q.jsx)(`span`,{className:o_.itemDetail,children:e.detail}),e.hint===void 0?null:(0,q.jsx)(`kbd`,{children:e.hint})]}),ej=({trigger:e,entries:t})=>(0,q.jsxs)(HA,{children:[(0,q.jsx)(JA,{render:e}),(0,q.jsx)(kA,{children:(0,q.jsx)(jA,{align:`start`,className:o_.positioner,sideOffset:4,children:(0,q.jsx)(EA,{className:o_.popup,children:t.map((e,t)=>(0,q.jsx)($A,{entry:e},QA(e,t)))})})})]}),tj=(e,{label:t})=>t===void 0?e:`${e} if ${t}`,nj={flow:e=>({from:[`leads to`,tj(e.to,e)],to:[`after`,tj(e.from,e)]}),back:e=>({from:[`goes back to`,tj(e.to,e)],to:[`comes back from`,tj(e.from,e)]}),owner:e=>({from:[`owns`,e.to],to:[`owned by`,e.from]}),message:e=>({from:[`can message`,e.to],to:[`can message`,e.from]})},rj=e=>{let t=new Map,n=(e,[n,r])=>{let i=t.get(e)??new Map;i.set(n,[...i.get(n)??[],r]),t.set(e,i)};for(let t of e){let{from:e,to:r}=nj[t.kind](t);n(t.from,e),n(t.to,r)}return new Map([...t].map(([e,t])=>[e,[...t].map(([e,t])=>`${e} ${t.join(`, `)}`).join(`; `)]))},ij=12,aj=(e,t,n)=>{let r=Math.abs(t.x-e.x)+Math.abs(t.y-e.y),i=r===0?0:n/r;return{x:e.x+(t.x-e.x)*i,y:e.y+(t.y-e.y)*i}},oj=({x:e,y:t})=>`${String(e)} ${String(t)}`,sj=(e,t)=>Math.abs(e.x-t.x)+Math.abs(e.y-t.y),cj=e=>{let[t,...n]=e;if(t===void 0)return``;let r=[`M ${oj(t)}`];for(let[i,a]of n.entries()){let o=e[i]??t,s=n[i+1];if(s===void 0)r.push(`L ${oj(a)}`);else{let e=Math.min(ij,sj(o,a)/2,sj(a,s)/2);r.push(`L ${oj(aj(a,o,e))}`,`Q ${oj(a)} ${oj(aj(a,s,e))}`)}}return r.join(` `)},lj=({shape:e,points:t})=>{let[n,r,i,a]=t;return e===`curve`&&n!==void 0&&r!==void 0&&i!==void 0&&a!==void 0?`M ${oj(n)} C ${oj(r)} ${oj(i)} ${oj(a)}`:cj(t)},uj=(e,t)=>Array.from({length:Math.ceil(e.length/t)},(n,r)=>e.slice(r*t,(r+1)*t)),dj=(e,t=28)=>{let n=[];for(let r of e.split(` `).flatMap(e=>uj(e,t))){let e=n.at(-1);e!==void 0&&e.length+1+r.length<=t?n[n.length-1]=`${e} ${r}`:n.push(r)}return n},fj=e=>e*14+2,pj=e=>{let t=e===void 0?[]:dj(e,21);return Math.ceil(90/4+fj(t.length)/2+mj)},mj=6,hj=6.6;Math.floor(144/hj);var gj={graph:`_graph_1nobd_7`,canvas:`_canvas_1nobd_15`,hint:`_hint_1nobd_45`,layer:`_layer_1nobd_58`,edges:`_edges_1nobd_67`,edgeLine:`_edgeLine_1nobd_82`,edgeHead:`_edgeHead_1nobd_95`,packet:`_packet_1nobd_136`,edgeLabel:`_edgeLabel_1nobd_160`,edgeLabelBack:`_edgeLabelBack_1nobd_174`,card:`_card_1nobd_180`,cardHead:`_cardHead_1nobd_264`,cardIcon:`_cardIcon_1nobd_273`,cardId:`_cardId_1nobd_284`,cardCost:`_cardCost_1nobd_295`,controls:`_controls_1nobd_306`,keyList:`_keyList_1nobd_331`,keyRow:`_keyRow_1nobd_342`,keyNames:`_keyNames_1nobd_346`,keyDoes:`_keyDoes_1nobd_355`},_j=6,vj=(e,t)=>{if(!(t===void 0||e!==`flow`&&e!==`owner`))return t.status===`running`?`flowing`:t.status===`queued`||t.status===`skipped`?`pending`:`taken`},yj=e=>e.reduce((t,n,r)=>{let i=e[r-1];return i===void 0?t:t+Math.hypot(n.x-i.x,n.y-i.y)},0),bj=({path:e,length:t})=>{let n=6/t;return(0,q.jsx)(`path`,{className:gj.packet,d:e,"data-packet":``,pathLength:2,strokeDasharray:`${String(n)} ${String(1-n)}`})},xj=e=>{let t=e.at(-1),n=e.at(-2);if(t===void 0||n===void 0)return``;let r=Math.sign(t.x-n.x),i=Math.sign(t.y-n.y),a={x:t.x-r*_j,y:t.y-i*_j},o={x:-i*(_j/2),y:_j/2*r};return[t,{x:a.x+o.x,y:a.y+o.y},{x:a.x-o.x,y:a.y-o.y}].map(({x:e,y:t})=>`${String(e)},${String(t)}`).join(` `)},Sj=({label:e,at:t,limit:n})=>{let r=dj(e,n),i=Math.max(...r.map(e=>e.length))*hj+8,a=fj(r.length),o=t.y-(r.length-1)*14/2;return(0,q.jsxs)(`g`,{children:[(0,q.jsx)(`rect`,{className:gj.edgeLabelBack,height:a,rx:2,width:i,x:t.x-i/2,y:t.y-a/2}),(0,q.jsx)(`text`,{className:gj.edgeLabel,children:r.map((e,n)=>(0,q.jsx)(`tspan`,{x:t.x,y:o+n*14,children:e},`${String(n)}:${e}`))})]})},Cj=(0,U.memo)(({edges:e,facts:t,quiet:n,width:r,height:i})=>(0,q.jsx)(`svg`,{"aria-hidden":`true`,className:gj.edges,"data-quiet":n?``:void 0,focusable:`false`,height:i,width:r,children:e.map(e=>{let n=vj(e.kind,t?.get(e.to)),r=lj(e);return(0,q.jsxs)(`g`,{"data-kind":e.kind,"data-state":n,children:[(0,q.jsx)(`path`,{className:gj.edgeLine,d:r}),e.kind===`message`?null:(0,q.jsx)(`polygon`,{className:gj.edgeHead,points:xj(e.points)}),n===`flowing`?(0,q.jsx)(bj,{length:yj(e.points),path:r}):null,e.label===void 0||e.labelAt===void 0?null:(0,q.jsx)(Sj,{at:e.labelAt,label:e.label,limit:e.labelLimit})]},`${e.from}\n${e.to}\n${e.kind}`)})}));Cj.displayName=`EdgePaths`;var wj=e=>({x:e.x+e.width/2,y:e.y+e.height/2}),Tj=(e,t,n)=>{let r=wj(t),i=wj(n);return e===`left`?i.x<r.x:e===`right`?i.x>r.x:e===`up`?i.y<r.y:i.y>r.y},Ej=(e,t,n)=>{let r=wj(t),i=e===`left`||e===`right`,a=e=>{let t=wj(e);return Math.abs(i?t.x-r.x:t.y-r.y)+Math.abs(i?t.y-r.y:t.x-r.x)*2};return n.toSorted((e,t)=>a(e)-a(t))[0]},Dj=(e,t,n)=>{let r=e.nodes.find(e=>e.id===t);if(r===void 0)return;let i=new Set(e.edges.flatMap(e=>e.from===t?[e.to]:e.to===t?[e.from]:[])),a=e.nodes.filter(e=>e.id!==t),o=a.filter(e=>i.has(e.id)&&Tj(n,r,e));return(Ej(n,r,n===`left`||n===`right`?[]:a.filter(e=>e.x===r.x&&Tj(n,r,e)))??Ej(n,r,o))?.id},Oj=5,kj=e=>e.flatMap((e,t)=>e.split(``).flatMap((e,n)=>e===`#`?[`M${String(n)} ${String(t)}h1v1h-1z`]:[])).join(``),Aj=e=>()=>(0,q.jsx)(`svg`,{"aria-hidden":`true`,fill:`currentColor`,focusable:`false`,height:`1em`,shapeRendering:`crispEdges`,viewBox:`0 0 ${String(Oj)} ${String(Oj)}`,width:`1em`,children:(0,q.jsx)(`path`,{d:kj(e)})}),jj=Aj([`.....`,`.###.`,`.###.`,`.###.`,`.....`]),Mj=Aj([`....#`,`...#.`,`#.#..`,`.#...`,`.....`]),Nj=Aj([`..#..`,`.#.#.`,`#...#`,`.#.#.`,`..#..`]),Pj=Aj([`.#.#.`,`.#.#.`,`.#.#.`,`.#.#.`,`.#.#.`]),Fj=Aj([`#...#`,`.#.#.`,`..#..`,`.#.#.`,`#...#`]),Ij=Aj([`#.#.#`,`.....`,`#...#`,`.....`,`#.#.#`]),Lj=Aj([`.....`,`.....`,`#####`,`.....`,`.....`]),Rj=Aj([`#####`,`#...#`,`#...#`,`#...#`,`#####`]),zj=Aj([`..#..`,`..#..`,`#####`,`..#..`,`..#..`]),Bj=Aj([`#....`,`.#...`,`..#..`,`.#...`,`#....`]),Vj=Aj([`..#..`,`.###.`,`#.#.#`,`..#..`,`..#..`]),Hj={badge:`_badge_derh1_8`,word:`_word_derh1_38`,icon:`_icon_derh1_50`,blink:`_blink_derh1_1`},Uj={running:{Icon:jj,word:`running`,tone:`running`},succeeded:{Icon:Mj,word:`succeeded`,tone:`succeeded`},waiting:{Icon:Nj,word:`waiting on you`,tone:`waiting`},paused:{Icon:Pj,word:`paused`,tone:`paused`},failed:{Icon:Fj,word:`failed`,tone:`failed`},crashed:{Icon:Fj,word:`crashed`,tone:`failed`},queued:{Icon:Ij,word:`queued`,tone:`queued`},skipped:{Icon:Lj,word:`skipped`,tone:`skipped`},interrupted:{Icon:Rj,word:`interrupted`,tone:`interrupted`},budget_exhausted:{Icon:Rj,word:`budget exhausted`,tone:`interrupted`},quota_exhausted:{Icon:Rj,word:`quota spent`,tone:`interrupted`},timed_out:{Icon:Rj,word:`timed out`,tone:`interrupted`}},Wj=e=>Uj[e].word,Gj=e=>Uj[e].tone,Kj=({look:e,pill:t})=>{let{Icon:n,word:r,tone:i}=e;return(0,q.jsxs)(`span`,{className:Hj.badge,"data-look":t?`pill`:`bare`,"data-tone":i,children:[(0,q.jsx)(`span`,{className:Hj.icon,children:(0,q.jsx)(n,{})}),(0,q.jsx)(`span`,{className:Hj.word,children:r})]})},qj=({status:e,word:t,pill:n=!1})=>{let r=Uj[e];return(0,q.jsx)(Kj,{look:{...r,word:t??r.word},pill:n})},Jj={new:{Icon:zj,word:`new`,tone:`waiting`},triaged:{Icon:Ij,word:`triaged`,tone:`queued`},accepted:{Icon:Bj,word:`accepted`,tone:`queued`},resolved:{Icon:Mj,word:`resolved`,tone:`succeeded`},published:{Icon:Vj,word:`published`,tone:`succeeded`},dismissed:{Icon:Lj,word:`dismissed`,tone:`skipped`}},Yj=({status:e,pill:t=!1})=>(0,q.jsx)(Kj,{look:Jj[e],pill:t}),Xj={merged:{Icon:Mj,word:`merged`,tone:`succeeded`},unmerged:{Icon:Bj,word:`not merged`,tone:`queued`},detached:{Icon:Lj,word:`detached`,tone:`skipped`}},Zj=({state:e})=>(0,q.jsx)(Kj,{look:Xj[e],pill:!1}),Qj={"agent.leader":`leader`,"agent.worker":`worker`,"agent.subagent":`sub-agent`,"control.split":`split`,"control.join":`join`,"control.router":`router`,"human.gate":`gate`,"workflow.call":`workflow call`,"mcp.call":`MCP call`},$j=e=>Qj[e]??(e.startsWith(`tool.`)?`${e.slice(5)} tool`:e),eM=5e-5,tM=(e,t=[e])=>{if(!Number.isFinite(e))return`–`;let n=Math.abs(e);if(n!==0&&n<eM)return e>0?`<$0.0001`:`$0.00`;let r=t.some(e=>{let t=Math.abs(Number(e.toFixed(4)));return t!==0&&t<10});return`${e<0?`-`:``}$${n.toFixed(r?4:2)}`},nM=e=>e<1e3?String(e):`${(e/1e3).toFixed(1)}k`,rM=e=>String(e).padStart(2,`0`),iM=e=>{let t=Math.max(Math.floor(e/1e3),0),n=Math.floor(t/60),r=`${rM(n%60)}:${rM(t%60)}`;return n<60?`${String(n)}:${rM(t%60)}`:`${String(Math.floor(n/60))}:${r}`},aM=(e,t,n)=>[e,n.word??Wj(n.status),...n.progress===void 0?[]:[n.progress],...n.costUsd===void 0?[]:[tM(n.costUsd)],...n.tokens===void 0?[]:[`${nM(n.tokens)} tokens`],...n.model===void 0?[]:[n.model],$j(t)].join(`, `),oM=new Map([[`agent.leader`,(0,q.jsx)(Ly,{},`leader`)],[`agent.worker`,(0,q.jsx)(Ry,{},`worker`)],[`agent.subagent`,(0,q.jsx)(zy,{},`subagent`)],[`control.split`,(0,q.jsx)(By,{},`split`)],[`control.join`,(0,q.jsx)(Vy,{},`join`)],[`control.router`,(0,q.jsx)(Hy,{},`router`)],[`human.gate`,(0,q.jsx)(Uy,{},`gate`)],[`workflow.call`,(0,q.jsx)(Wy,{},`call`)],[`mcp.call`,(0,q.jsx)(Wy,{},`mcp`)],[`tool.gh`,(0,q.jsx)(Gy,{},`gh`)],[`tool.aws`,(0,q.jsx)(Ky,{},`aws`)],[`tool.git`,(0,q.jsx)(qy,{},`git`)]]),sM=({type:e})=>oM.get(e)??(0,q.jsx)(_y,{}),cM=(0,U.memo)(({node:e,facts:t,connections:n,selected:r,holding:i=!1,dimmed:a,tabbable:o,bind:s,onSelect:c,onFocused:l,onKey:u,onMenu:d,onHover:f})=>{let{id:p,type:m,x:h,y:g,width:_,height:v}=e,y=(0,q.jsxs)(`button`,{...l_(t.cli,n),"aria-current":r?`true`:void 0,"aria-label":aM(p,m,t),className:gj.card,"data-graph-node":``,"data-dim":a?``:void 0,"data-holding":i?``:void 0,"data-selected":r?``:void 0,"data-tone":Gj(t.status),onMouseEnter:()=>f?.(p),onMouseLeave:()=>f?.(null),onClick:()=>{c(p)},onContextMenu:d===void 0?void 0:e=>{e.preventDefault(),d(p)},onFocus:()=>{l(p)},onKeyDown:e=>{u(p,e)},ref:e=>{s(p,e)},style:{height:v,transform:`translate(${h}px, ${g}px)`,width:_},tabIndex:o?0:-1,type:`button`,children:[(0,q.jsxs)(`span`,{className:gj.cardHead,children:[(0,q.jsx)(`span`,{className:gj.cardIcon,children:(0,q.jsx)(sM,{type:m})}),(0,q.jsx)(`span`,{className:gj.cardId,children:p}),t.costUsd===void 0?null:(0,q.jsx)(`span`,{className:gj.cardCost,children:tM(t.costUsd)})]}),(0,q.jsx)(qj,{status:t.status,word:t.word??t.progress})]});return t.cli===void 0?y:(0,q.jsx)(u_,{cli:t.cli,label:t.progress===void 0?void 0:`${t.word??Wj(t.status)} · ${t.progress}`,children:y})});cM.displayName=`NodeCard`;var lM=(e,t)=>{let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},uM=(e,t)=>{let n=e=>{e.preventDefault(),e instanceof WheelEvent&&t(e)};return e.addEventListener(`wheel`,n,{passive:!1}),()=>{e.removeEventListener(`wheel`,n)}},dM=(e,t)=>{let n=e.current?.getBoundingClientRect(),r=t.current?.getBoundingClientRect();return n===void 0||r===void 0?void 0:{x:n.x-r.x,y:n.y-r.y,width:n.width,height:n.height}},fM=.2,pM=e=>Math.min(2,Math.max(fM,e)),mM=(e,t)=>{if(e.width<=0||e.height<=0)return{x:0,y:0,k:1};let n=pM(Math.min(1,t.width/e.width,t.height/e.height));return{x:(t.width-e.width*n)/2,y:(t.height-e.height*n)/2,k:n}},hM=(e,t,n)=>{let r=pM(e.k*t),i=r/e.k;return{k:r,x:n.x-(n.x-e.x)*i,y:n.y-(n.y-e.y)*i}},gM=(e,t,n)=>({...e,x:e.x+t,y:e.y+n}),_M=(e,t,n,r)=>{let i={x:t.x*e.k+e.x,y:t.y*e.k+e.y,width:t.width*e.k,height:t.height*e.k};if(!bM(i,n))return e;let a=n.y-r-(i.y+i.height);return i.y+a>=r?gM(e,0,a):gM(e,n.x-r-(i.x+i.width),0)},vM=(e,t,n,r,i=24)=>{let a=(e,t,n)=>{let r=e+t;return t+i*2>=n?(n-t)/2-e:e<i?i-e:r>n-i?n-i-r:0},o=a(t.x*e.k+e.x,t.width*e.k,n.width),s=a(t.y*e.k+e.y,t.height*e.k,n.height),c=o===0&&s===0?e:gM(e,o,s);return r===void 0?c:_M(c,t,r,i)},yM=(e,t,n=160)=>({x:(-n-e.x)/e.k,y:(-n-e.y)/e.k,width:(t.width+n*2)/e.k,height:(t.height+n*2)/e.k}),bM=(e,t)=>e.x<t.x+t.width&&t.x<e.x+e.width&&e.y<t.y+t.height&&t.y<e.y+e.height,xM=16,SM=12,CM=e=>{let t=xM*e;for(;t<SM;)t*=2;return t},wM=e=>{let t=e.map(e=>e.x),n=e.map(e=>e.y),r=Math.min(...t),i=Math.min(...n);return{x:r,y:i,width:Math.max(...t)-r,height:Math.max(...n)-i}},TM=.01,EM=e=>({nodes:new Set(e.nodes.map(e=>e.id)),edges:new Set(e.edges.keys())}),DM=()=>{},OM=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y),kM=e=>{let t=(0,U.useRef)(null),n=(0,U.useRef)(null),r=(0,U.useRef)(null),i=(0,U.useRef)({x:0,y:0,k:1}),a=(0,U.useRef)(!1),o=(0,U.useRef)(0),s=(0,U.useRef)(new Map),[c,l]=(0,U.useState)(()=>EM(e)),u=(0,U.useRef)(``),[d,f]=(0,U.useState)(e);e!==d&&(f(e),l(EM(e)));let p=(0,U.useMemo)(()=>e.edges.map(e=>wM(e.points)),[e]),m=(0,U.useCallback)(()=>{let e=t.current?.getBoundingClientRect();return{width:e?.width??0,height:e?.height??0}},[]),h=(0,U.useCallback)(()=>{o.current=0;let{x:r,y:a,k:s}=i.current,c=n.current;c!==null&&(c.style.transform=`translate(${String(r)}px, ${String(a)}px) scale(${String(s)})`);let d=t.current;if(d!==null){let e=`${String(CM(s))}px`;d.style.backgroundSize=`${e} ${e}`,d.style.backgroundPosition=`${String(r)}px ${String(a)}px`,d.style.setProperty(`--graph-zoom`,String(s))}let f=m();if(f.width===0||f.height===0)return;let h=yM(i.current,f),g=e.nodes.filter(e=>bM(h,e)).map(e=>e.id),_=[...p.keys()].filter(e=>{let t=p[e];return t!==void 0&&bM(h,t)}),v=`${g.join(`
92
- `)}\n\n${_.join(`,`)}`;v!==u.current&&(u.current=v,l({nodes:new Set(g),edges:new Set(_)}))},[p,e,m]),g=(0,U.useCallback)(()=>{o.current===0&&(o.current=requestAnimationFrame(h))},[h]),_=(0,U.useCallback)(()=>{a.current=!1,i.current=mM(e,m()),g()},[e,g,m]),v=(0,U.useCallback)(e=>{a.current=!0,i.current=e,g()},[g]),y=(0,U.useCallback)(e=>{let{width:t,height:n}=m();v(hM(i.current,e,{x:t/2,y:n/2}))},[v,m]),b=(0,U.useCallback)((e,t)=>{v(gM(i.current,e,t))},[v]),x=(0,U.useCallback)(e=>{let n=m();if(n.width===0||n.height===0)return;let a=vM(i.current,e,n,dM(r,t));a!==i.current&&v(a)},[v,m]);return(0,U.useEffect)(()=>{u.current=``,a.current?g():_()},[_,g]),(0,U.useEffect)(()=>{let e=t.current;return e===null?DM:lM(e,()=>{a.current?g():_()})},[_,g]),(0,U.useEffect)(()=>()=>{cancelAnimationFrame(o.current),o.current=0},[]),(0,U.useEffect)(()=>{let e=t.current;return e===null?DM:uM(e,t=>{if(t.ctrlKey||t.metaKey){let n=e.getBoundingClientRect();v(hM(i.current,Math.exp(-t.deltaY*TM),{x:t.clientX-n.left,y:t.clientY-n.top}))}else v(gM(i.current,-t.deltaX,-t.deltaY))})},[v]),{canvasRef:t,layerRef:n,controlsRef:r,shown:c,fit:_,zoom:y,pan:b,show:x,pointer:(0,U.useMemo)(()=>{let e=e=>{let t=e.currentTarget.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}},t=e=>{s.current.delete(e.pointerId)};return{onPointerDown:t=>{t.target instanceof Element&&t.target.closest(`button`)!==null||(t.currentTarget.setPointerCapture?.(t.pointerId),s.current.set(t.pointerId,e(t)))},onPointerMove:t=>{let n=s.current.get(t.pointerId);if(n===void 0)return;let r=e(t),a=[...s.current].find(([e])=>e!==t.pointerId)?.[1];if(a===void 0)v(gM(i.current,r.x-n.x,r.y-n.y));else{let e=OM(n,a);e>0&&v(hM(i.current,OM(r,a)/e,a))}s.current.set(t.pointerId,r)},onPointerUp:t,onPointerCancel:t}},[v])}},AM=U.createContext(void 0);function jM(e){let t=U.useContext(AM);if(t===void 0&&!e)throw Error(gc(47));return t}var MM={...jm,disabled:e=>e.disabled,instantType:e=>e.instantType===`trigger-change`&&!jm.open(e)?void 0:e.instantType,openMethod:e=>e.openMethod,openChangeReason:e=>e.openChangeReason,isPressOpenedByTrigger:(e,t)=>e.openChangeReason===`trigger-press`&&jm.isOpenedByTrigger(e,t),isTouchPressOpen:(e,t)=>t&&e.openMethod===`touch`&&e.openChangeReason===`trigger-press`,hasTriggerFocusGuards:(e,t)=>jm.isOpenedByTrigger(e,t)&&!e.focusManagerModal,modal:e=>e.modal,titleElementId:e=>e.titleElementId,descriptionElementId:e=>e.descriptionElementId,openOnHover:e=>e.openOnHover,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin},NM=class extends Sm{constructor(e,t,n){let r=new lm;super(PM(e,r,t,n),FM(r),MM)}setOpen=(e,t)=>{let n=t.reason===ou,r=t.reason===`trigger-press`&&t.event.detail===0,i=!e&&(t.reason===`escape-key`||t.reason==null),a=nm(t),o=this.select(`activeTriggerId`);if(!e&&t.reason===`close-press`&&t.trigger==null&&o!=null&&(t.trigger=this.context.triggerElements.getById(o)??this.select(`activeTriggerElement`)??void 0),this.context.onOpenChange?.(e,t),t.isCanceled)return;this.state.floatingRootContext.dispatchOpenChange(e,t);let s=()=>{let n=tm(this.state,e,t.trigger,a());n.openChangeReason=t.reason,this.update(n)};n?(this.context.stickIfOpen=!0,this.context.stickIfOpenTimeout.start(500,()=>{this.context.stickIfOpen=!1}),lp.flushSync(s)):s();let c;r?c=`click`:i?c=`dismiss`:t.reason===`focus-out`&&(c=`focus`),this.set(`instantType`,c)}};function PM(e,t,n,r=!1){let i={...Tm(t,n,r),disabled:!1,modal:!1,focusManagerModal:!1,instantType:void 0,openMethod:null,openChangeReason:null,titleElementId:void 0,descriptionElementId:void 0,openOnHover:!1,closeDelay:0,adaptiveOrigin:void 0,...e};return i.open&&e?.mounted===void 0&&(i.mounted=!0),i}function FM(e){return{popupRef:U.createRef(),onOpenChange:void 0,onOpenChangeComplete:void 0,triggerFocusTargetRef:U.createRef(),beforeTriggerFocusGuardRef:U.createRef(),beforeContentFocusGuardRef:U.createRef(),stickIfOpenTimeout:new xc,stickIfOpen:!0,triggerElements:e}}var IM=lc(function({props:e}){let{children:t,open:n,defaultOpen:r=!1,onOpenChange:i,onOpenChangeComplete:a,modal:o=!1,handle:s,triggerId:c,defaultTriggerId:l=null}=e,u=RM(s,{modal:o,open:r,openProp:n,activeTriggerId:l,triggerIdProp:c});u.useControlledProp(`openProp`,n),u.useControlledProp(`triggerIdProp`,c);let d=u.useState(`open`),f=u.useState(`mounted`),p=u.useState(`payload`);u.useContextCallback(`onOpenChange`,i),u.useContextCallback(`onOpenChangeComplete`,a),cm(u,d),am(u);let{forceUnmount:m}=om(d,u,()=>{u.context.stickIfOpen=!0,u.set(`openChangeReason`,null)});u.useSyncedValues({modal:o}),U.useEffect(()=>{d||u.context.stickIfOpenTimeout.clear()},[u,d]),U.useImperativeHandle(e.actionsRef,()=>({unmount:m,close:()=>u.setOpen(!1,K(Su))}),[m,u]);let h=d||f||s!=null;return(0,q.jsxs)(AM.Provider,{value:u,children:[s&&(0,q.jsx)(Qp,{handle:s,store:u}),h&&(0,q.jsx)(zM,{store:u,modal:o}),typeof t==`function`?t({payload:p}):t]})});function LM(e){return jM(!0)?(0,q.jsx)(IM,{props:e}):(0,q.jsx)(Cp,{children:(0,q.jsx)(IM,{props:e})})}function RM(e,t){let n=Zp((e,n)=>new NM(t,e,n));return U.useEffect(()=>n.context.stickIfOpenTimeout.disposeEffect(),[n]),n}function zM({store:e,modal:t}){let n=Bp(e.useState(`floatingRootContext`),{outsidePressEvent:{mouse:t===`trap-focus`?`sloppy`:`intentional`,touch:`sloppy`}}),r=n.reference,i=n.floating;return sm(e,{activeTriggerProps:r,inactiveTriggerProps:r,popupProps:i}),null}var BM=uc(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,handle:s,payload:c,openOnHover:l=!1,delay:u=300,closeDelay:d=0,id:f,...p}=e,m=jM(!0),h=Mm(s)??m;if(!h)throw Error(gc(74));let g=hg(f),_=h.useState(`isTriggerActive`,g),v=h.useState(`floatingRootContext`),y=h.useState(`isOpenedByTrigger`,g),b=h.useState(`triggerPopupId`,g),x=U.useRef(null),{registerTrigger:S,isMountedByThisTrigger:C}=im(g,x,h,{payload:c,disabled:a,openOnHover:l,closeDelay:d}),w=h.useState(`isPressOpenedByTrigger`,g),T=h.useState(`isTouchPressOpen`,l),E=h.useState(`hasTriggerFocusGuards`,g),D=Um(v,{enabled:!a&&l&&!T,mouseOnly:!0,move:!1,handleClose:ah(),restMs:u,delay:{close:d},triggerElementRef:x,isActiveTrigger:_,isClosing:()=>h.select(`transitionStatus`)===`ending`}),O=Pp(v,{stickIfOpen:J(()=>h.context.stickIfOpen)}),k=Tx(()=>h.select(`open`),e=>{h.set(`openMethod`,e)}),A=h.useState(`triggerProps`,C),{getButtonProps:j,buttonRef:M}=ev({disabled:a,native:o}),N={open(e){return w?Bl.open(e):zl.open(e)}},{handlePreFocusGuardFocus:P,handleFocusTargetFocus:F}=KA(h,x),I=qf(`button`,e,{state:{disabled:a,open:y},ref:[M,t,S,x],props:[O.reference,D,A,k,{[tp]:``,id:g,"aria-haspopup":`dialog`,"aria-expanded":y,"aria-controls":b},p,j],stateAttributesMapping:N}),L=(0,q.jsx)(U.Fragment,{children:I},g);return E?(0,q.jsxs)(U.Fragment,{children:[(0,q.jsx)(Zu,{ref:h.context.beforeTriggerFocusGuardRef,onFocus:P}),L,(0,q.jsx)(Zu,{ref:h.context.triggerFocusTargetRef,onFocus:F})]}):L}),VM=U.createContext(void 0);function HM(){let e=U.useContext(VM);if(e===void 0)throw Error(gc(45));return e}var UM=U.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e;return jM().useState(`mounted`)||n?(0,q.jsx)(VM.Provider,{value:n,children:(0,q.jsx)(mp,{ref:t,...r})}):null}),WM=U.createContext(void 0);function GM(){let e=U.useContext(WM);if(!e)throw Error(gc(46));return e}var KM=U.forwardRef(function(e,t){let{render:n,className:r,style:i,anchor:a,positionMethod:o,side:s,align:c,sideOffset:l,alignOffset:u,collisionBoundary:d=`clipping-ancestors`,collisionPadding:f,arrowPadding:p,sticky:m,disableAnchorTracking:h=!1,collisionAvoidance:g=sp,..._}=e,v=jM(),y=HM(),b=xp(),x=v.useState(`floatingRootContext`),S=v.useState(`mounted`),C=v.useState(`open`),w=v.useState(`openChangeReason`),T=v.useState(`activeTriggerElement`),E=v.useState(`modal`),D=v.useState(`openMethod`),O=v.useState(`positionerElement`),k=v.useState(`instantType`),A=v.useState(`transitionStatus`),j=Ug({anchor:a,floatingRootContext:x,positionMethod:o,mounted:S,side:s,sideOffset:l,align:c,alignOffset:u,arrowPadding:p,collisionBoundary:d,collisionPadding:f,sticky:m,disableAnchorTracking:h,keepMounted:y,nodeId:b,collisionAvoidance:g,adaptiveOrigin:v.useState(`adaptiveOrigin`)});AA({store:v,domReference:x.useState(`domReferenceElement`),positionerElement:O,open:C});let M=E===!0&&w!==`trigger-hover`;LS(C&&M,D===`touch`,O,T);let N=v.useStateSetter(`positionerElement`),P=qg(e,{open:C,side:j.side,align:j.align,anchorHidden:j.anchorHidden,instant:k},{styles:j.positionerStyles,transitionStatus:A,props:_,refs:[t,N],hidden:!S,inert:!C});return(0,q.jsxs)(WM.Provider,{value:j,children:[S&&M&&(0,q.jsx)(wS,{inert:Zg(!C),cutout:T}),(0,q.jsx)(Sp,{id:b,children:P})]})}),qM=U.createContext(void 0);function JM(){let[e,t]=U.useState(0),n=J(()=>(t(e=>e+1),()=>{t(e=>Math.max(0,e-1))}));return{context:U.useMemo(()=>({register:n}),[n]),hasClosePart:e>0}}var YM=U.forwardRef(function(e,t){let{render:n,className:r,style:i,initialFocus:a,finalFocus:o,...s}=e,c=jM(),l=GM(),u=KO(!0)!=null,{context:d,hasClosePart:f}=JM(),p=c.useState(`open`),m=c.useState(`openMethod`),h=c.useState(`instantType`),g=c.useState(`transitionStatus`),_=c.useState(`popupProps`),v=c.useState(`titleElementId`),y=c.useState(`descriptionElementId`),b=c.useState(`modal`),x=c.useState(`mounted`),S=c.useState(`openChangeReason`),C=c.useState(`activeTriggerElement`),w=c.useState(`floatingRootContext`),T=w.useState(`floatingId`),E=c.useState(`disabled`),D=c.useState(`openOnHover`),O=c.useState(`closeDelay`);qp({open:p,ref:c.context.popupRef,onComplete(){p&&c.context.onOpenChangeComplete?.(!0)}}),Vm(w,{enabled:D&&!E,closeDelay:O});let k=a===void 0?Xp(c.context.popupRef):a,A=b!==!1&&f;c.useSyncedValue(`focusManagerModal`,A);let j=c.useStateSetter(`popupElement`),M=qf(`div`,e,{state:{open:p,side:l.side,align:l.align,instant:h,transitionStatus:g},ref:[t,c.context.popupRef,j],props:[_,{id:T,role:`dialog`,...Yp,"aria-labelledby":v,"aria-describedby":y,onKeyDown(e){u&&CC.has(e.key)&&e.stopPropagation()}},Kg(g),s],stateAttributesMapping:Hl});return(0,q.jsx)(Np,{context:w,openInteractionType:m,modal:A,disabled:!x||S===`trigger-hover`,initialFocus:k,returnFocus:o,restoreFocus:`popup`,getInsideElements:()=>[c.context.beforeTriggerFocusGuardRef.current],previousFocusableElement:Xc(C)?C:void 0,nextFocusableElement:c.context.triggerFocusTargetRef,beforeContentFocusGuardRef:c.context.beforeContentFocusGuardRef,children:(0,q.jsx)(qM.Provider,{value:d,children:M})})}),XM=U.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,o=jM(),s=hg(a.id);return o.useSyncedValueWithCleanup(`titleElementId`,s),qf(`h2`,e,{ref:t,props:[{id:s},a]})}),ZM=({trigger:e,title:t,children:n})=>(0,q.jsxs)(LM,{children:[(0,q.jsx)(BM,{render:e}),(0,q.jsx)(UM,{children:(0,q.jsx)(KM,{className:o_.positioner,sideOffset:4,children:(0,q.jsxs)(YM,{className:o_.panel,children:[(0,q.jsx)(XM,{className:o_.title,children:t}),n]})})})]}),QM=1.25,$M=[{keys:[[`←`],[`→`],[`↑`],[`↓`]],does:`Move the view; on a node, follow its edges`},{keys:[[`Enter`],[`Space`]],does:`Select the node`},{keys:[[`Shift`,`F10`]],does:`The node's controls`},{keys:[[`Escape`]],does:`Back to the view`},{keys:[[`+`],[`-`]],does:`Zoom in or out`},{keys:[[`0`]],does:`Fit the graph`}],eN=()=>(0,q.jsx)(ZM,{title:`Keys on the graph`,trigger:(0,q.jsx)(xb,{label:`Keys on the graph`,children:(0,q.jsx)(Zy,{})}),children:(0,q.jsx)(`dl`,{className:gj.keyList,children:$M.map(({keys:e,does:t})=>(0,q.jsxs)(`div`,{className:gj.keyRow,children:[(0,q.jsx)(`dt`,{className:gj.keyNames,children:e.map(e=>(0,q.jsx)(a_,{keys:e},e.join(`+`)))}),(0,q.jsx)(`dd`,{className:gj.keyDoes,children:t})]},t))})}),tN=({controlsRef:e,zoom:t,fit:n,pan:r})=>(0,q.jsxs)(`div`,{className:gj.controls,ref:e,children:[(0,q.jsx)(xb,{keys:[`+`],label:`Zoom in`,onClick:()=>{t(QM)},children:(0,q.jsx)(Jy,{})}),(0,q.jsx)(xb,{keys:[`-`],label:`Zoom out`,onClick:()=>{t(1/QM)},children:(0,q.jsx)(Yy,{})}),(0,q.jsx)(xb,{keys:[`0`],label:`Fit the graph`,onClick:n,children:(0,q.jsx)(Xy,{})}),(0,q.jsx)(xb,{keys:[`←`],label:`Pan left`,onClick:()=>{r(48,0)},children:(0,q.jsx)(dy,{})}),(0,q.jsx)(xb,{keys:[`→`],label:`Pan right`,onClick:()=>{r(-48,0)},children:(0,q.jsx)(fy,{})}),(0,q.jsx)(xb,{keys:[`↑`],label:`Pan up`,onClick:()=>{r(0,48)},children:(0,q.jsx)(py,{})}),(0,q.jsx)(xb,{keys:[`↓`],label:`Pan down`,onClick:()=>{r(0,-48)},children:(0,q.jsx)(my,{})}),(0,q.jsx)(eN,{})]}),nN={status:`queued`},rN={ArrowLeft:`left`,ArrowRight:`right`,ArrowUp:`up`,ArrowDown:`down`},iN=()=>{},aN=(0,U.memo)(({layout:e,label:t,facts:n,selected:r,holding:i,onSelect:a=iN,onNodeMenu:o,live:s=!1,hovered:c=null,onHover:l})=>{let u=(0,U.useId)(),{canvasRef:d,layerRef:f,controlsRef:p,shown:m,fit:h,zoom:g,pan:_,show:v,pointer:y}=kM(e),[b,x]=(0,U.useState)(r),[S,C]=(0,U.useState)(r);r!==S&&(C(r),r!==void 0&&x(r));let w=(0,U.useRef)(new Map),T=(0,U.useRef)(null),E=(0,U.useMemo)(()=>new Map(e.nodes.map(e=>[e.id,e])),[e]),D=(0,U.useMemo)(()=>rj(e.edges),[e]),O=E.has(b??``)?b:e.nodes[0]?.id,k=i??r,A=(0,U.useRef)(k);(0,U.useEffect)(()=>{if(k===A.current)return;A.current=k;let e=E.get(k??``);e!==void 0&&v(e)},[E,k,v]),(0,U.useEffect)(()=>{let e=T.current;if(e===null)return;let t=w.current.get(e);t!==void 0&&(T.current=null,t.focus({preventScroll:!0}))});let j=(0,U.useCallback)((e,t)=>{t===null?w.current.delete(e):w.current.set(e,t)},[]),M=(0,U.useCallback)(e=>{x(e);let t=E.get(e);t!==void 0&&v(t)},[E,v]),N=(0,U.useCallback)((t,n)=>{let r=rN[n.key];if(r!==void 0){n.preventDefault(),n.stopPropagation();let i=Dj(e,t,r);if(i===void 0)return;let a=E.get(i);a!==void 0&&v(a),T.current=i,x(i)}else n.key===`Escape`?d.current?.focus({preventScroll:!0}):(n.key===`ContextMenu`||n.key===`F10`&&n.shiftKey)&&o!==void 0&&(n.preventDefault(),o(t))},[E,d,e,o,v]),P=e=>{if(e.metaKey||e.ctrlKey||e.altKey)return;let t=e.target===e.currentTarget,n={"+":()=>{g(QM)},"=":()=>{g(QM)},"-":()=>{g(1/QM)},0:h,...t?{ArrowLeft:()=>{_(48,0)},ArrowRight:()=>{_(-48,0)},ArrowUp:()=>{_(0,48)},ArrowDown:()=>{_(0,-48)}}:{}}[e.key];n!==void 0&&(e.preventDefault(),n())},F=e.nodes.filter(e=>m.nodes.has(e.id)||e.id===O),I=(0,U.useMemo)(()=>e.edges.filter((e,t)=>m.edges.has(t)),[e,m]);return(0,q.jsxs)(`div`,{className:gj.graph,children:[(0,q.jsxs)(`div`,{...y,"aria-describedby":u,"aria-label":t,"aria-roledescription":`graph`,className:gj.canvas,onKeyDown:P,ref:d,role:`application`,tabIndex:0,children:[(0,q.jsx)(`p`,{className:gj.hint,id:u,children:`Arrow keys move the view; on a node, they move along its edges, Enter selects it, Shift+F10 asks for its controls, and Escape goes back to the view. Plus and minus zoom, and 0 fits the graph.`}),(0,q.jsxs)(`div`,{className:gj.layer,ref:f,children:[(0,q.jsx)(Cj,{edges:I,facts:s?n:void 0,height:e.height,quiet:c!==null,width:e.width}),F.map(e=>(0,q.jsx)(cM,{bind:j,connections:D.get(e.id),dimmed:c!==null&&c!==e.id,facts:n?.get(e.id)??nN,holding:e.id===i,node:e,onFocused:M,onHover:l,onKey:N,onMenu:o,onSelect:a,selected:e.id===r,tabbable:e.id===O},e.id))]})]}),(0,q.jsx)(tN,{controlsRef:p,fit:h,pan:_,zoom:g})]})});aN.displayName=`GraphView`;var oN=8,sN=e=>new Map(e.map((e,t)=>[e,t])),cN=(e,t,n)=>{let r=sN(e),i=sN(t),a=n.flatMap(([e,t])=>{let n=r.get(e),a=i.get(t);return n===void 0||a===void 0?[]:[[n,a]]}),o=0;for(let[e,[t=0,n=0]=[]]of a.entries())for(let[r=0,i=0]of a.slice(e+1))(t-r)*(n-i)<0&&(o+=1);return o},lN=(e,t)=>e.slice(1).reduce((n,r,i)=>n+cN(e[i]??[],r,t),0),uN=(e,t,n)=>{let r=(e,r)=>{let i=(t.get(e)??[]).flatMap(e=>{let t=n.get(e);return t===void 0?[]:[t]});return i.length===0?r:i.reduce((e,t)=>e+t,0)/i.length};return e.map((e,t)=>({id:e,index:t,weight:r(e,t)})).toSorted((e,t)=>e.weight-t.weight||e.index-t.index).map(({id:e})=>e)},dN=(e,t)=>{let n=new Map,r=new Map;for(let[e,i]of t)n.set(i,[...n.get(i)??[],e]),r.set(e,[...r.get(e)??[],i]);let i=e.map(e=>[...e]),a=i,o=lN(i,t);for(let e=0;e<oN&&o>0;e+=1){let s=e%2==0,c=i.map(e=>[...e]),l=c.map((e,t)=>t);for(let e of s?l.slice(1):l.slice(0,-1).toReversed()){let t=sN(c[e+(s?-1:1)]??[]);c[e]=uN(c[e]??[],s?n:r,t)}i=c;let u=lN(i,t);u<o&&(o=u,a=i)}return a},fN=12,pN=(e,t)=>{let n=[],r=0;for(let[i]of e.entries())i>0&&(r+=t[i-1]??0),n.push(r);let i=[];for(let[t,r]of e.entries())for(i.push({sum:r-(n[t]??0),size:1});;){let e=i.at(-1),t=i.at(-2);if(e===void 0||t===void 0||t.sum/t.size<=e.sum/e.size)break;i.splice(-2,2,{sum:t.sum+e.sum,size:t.size+e.size})}return i.flatMap(({sum:e,size:t})=>Array.from({length:t},()=>e/t)).map((e,t)=>e+(n[t]??0))},mN=(e,t,n)=>{let r=new Map,i=new Map;for(let[e,n]of t)r.set(n,[...r.get(n)??[],e]),i.set(e,[...i.get(e)??[],n]);let a=new Map,o=(e,t)=>{let r=pN(t,e.slice(1).map((t,r)=>n(e[r]??``,t)));for(let[t,n]of e.entries())a.set(n,r[t]??0)};for(let t of e)o(t,t.map(()=>0));let s=(e,t)=>{let n=e.map(e=>{let n=t.flatMap(t=>t.get(e)??[]).map(e=>a.get(e)??0);return n.length===0?a.get(e)??0:n.reduce((e,t)=>e+t,0)/n.length});o(e,n)};for(let t=0;t<fN;t+=1){let n=t%2==0;for(let a of n?e:e.toReversed())s(a,t===11?[r,i]:[n?r:i])}return a},hN=e=>{let t=new Set(e.nodes.map(e=>e.id)),n=[],r=(e,t,r,i)=>{n.push({index:n.length,from:e,to:t,kind:r,label:i})},i=new Set;for(let{from:n,to:a,when:o,maxRounds:s}of e.edges)t.has(n)&&t.has(a)&&(i.add(`${n}\n${a}`),r(n,a,s!==void 0||n===a?`back`:`flow`,o));for(let{id:n,parent:a}of e.nodes)a!==void 0&&t.has(a)&&!i.has(`${a}\n${n}`)&&r(a,n,`owner`);for(let[n,i]of e.channels??[])t.has(n)&&t.has(i)&&n!==i&&r(n,i,`message`);return n},gN=(e,t)=>{let n=new Map;for(let e of t)n.set(e.from,[...n.get(e.from)??[],e]);let r=new Map,i=e=>{r.set(e,`open`);for(let t of n.get(e)??[]){let e=r.get(t.to);e===`open`?t.kind=`back`:e===void 0&&i(t.to)}r.set(e,`done`)};for(let t of e)r.has(t)||i(t)},_N=(e,t)=>{let n=new Set(t.filter(e=>e.kind===`flow`).map(e=>e.to)),r=t.filter(e=>e.kind===`flow`||e.kind===`owner`&&!n.has(e.to));gN(e,r);let i=r.filter(e=>e.kind!==`back`),a=new Map(e.map(e=>[e,0])),o=!0;for(let t=0;o&&t<=e.length;t+=1){o=!1;for(let{from:e,to:t}of i){let n=(a.get(e)??0)+1;n>(a.get(t)??0)&&(a.set(t,n),o=!0)}}return a},vN=12,yN=(e,t)=>{let n=new Map,r=(e,t,r)=>{n.set(e,[...n.get(e)??[],{top:t,bottom:r}])};for(let n of e.values())r(t(n.id),n.y-vN,n.y+n.height+vN);return(e,t)=>{let i=t=>e.every(e=>(n.get(e)??[]).every(({top:e,bottom:n})=>t<=e||t>=n)),a=e.flatMap(e=>(n.get(e)??[]).flatMap(({top:e,bottom:t})=>[e,t])),o=t[0]??0,s=t.find(e=>i(e))??a.filter(e=>i(e)).toSorted((e,t)=>Math.abs(e-o)-Math.abs(t-o)||e-t)[0]??o;for(let t of e)r(t,s-vN,s+vN);return s}},bN=48,xN=36,SN=16,CN={flow:0,owner:0,back:14,message:-14},wN=(e,t)=>e.y+e.height/2+CN[t],TN=e=>e?.x??0,EN=e=>e?.y??0,DN=([e,t,n,r])=>({x:(TN(e)+3*TN(t)+3*TN(n)+TN(r))/8,y:(EN(e)+3*EN(t)+3*EN(n)+EN(r))/8}),ON=(e,t)=>({from:e.from,to:e.to,kind:e.kind,shape:`curve`,points:t,...e.label===void 0?{}:{label:e.label,labelAt:DN(t)}}),kN=(e,t,n)=>{let r=Math.max(xN,Math.abs(n.x-t.x)/2),i=n.x>=t.x?1:-1;return ON(e,[t,{x:t.x+r*i,y:t.y},{x:n.x-r*i,y:n.y},n])},AN=(e,t)=>{let n=Math.max(e.y,t.y),r=Math.min(e.y+e.height,t.y+t.height);return r-n<SN?void 0:(n+r)/2},jN=(e,t)=>{let n=t.x+t.width*.3,r=t.x+t.width*.7,i=t.y-30,a=ON(e,[{x:r,y:t.y},{x:r,y:i},{x:n,y:i},{x:n,y:t.y}]);return e.label===void 0?a:{...a,labelLimit:21}},MN=(e,t,n)=>{let r={x:t.x+t.width,y:wN(t,e.kind)},i={x:n.x+n.width,y:wN(n,e.kind)};return ON(e,[r,{x:r.x+bN,y:r.y},{x:i.x+bN,y:i.y},i])},NN=e=>{let t=[];for(let n of e){let e=t.at(-1),r=t.at(-2);(e?.x!==n.x||e.y!==n.y)&&(e!==void 0&&r!==void 0&&(r.x===e.x&&e.x===n.x||r.y===e.y&&e.y===n.y)&&t.pop(),t.push(n))}return t},PN=e=>{let t=e[0]??{x:0,y:0},n=-1;for(let[r,i]of e.slice(1).entries()){let a=e[r]??i,o=Math.abs(i.x-a.x)+Math.abs(i.y-a.y);o>n&&(n=o,t={x:(a.x+i.x)/2,y:(a.y+i.y)/2})}return t},FN=(e,t)=>{let n=NN(t);return{from:e.from,to:e.to,kind:e.kind,shape:`lines`,points:n,...e.label===void 0?{}:{label:e.label,labelAt:PN(n)}}},IN=e=>{let{chains:t,nodes:n,stopY:r,rankOf:i,columnX:a,columnWidth:o,gapWidth:s}=e,c=e=>a(e)+o,l=yN(n,i),u=t.filter(({stops:e})=>e.length>2),d=new Map,f=new Map;for(let{edge:e,stops:t}of u){let a=n.get(e.from),o=n.get(e.to);if(a!==void 0&&o!==void 0){let n=wN(a,e.kind),s=wN(o,e.kind),c=l(t.slice(1,-1).map(e=>{let[,t=``]=e.split(`:`);return Number(t)}),[n,s,...t.slice(1,-1).map(e=>r.get(e)??n)]);d.set(e.index,c);let u=Math.min(i(e.from),i(e.to)),p=Math.max(i(e.from),i(e.to));for(let t of[u,p-1])f.set(t,[...f.get(t)??[],e.index])}}let p=(e,t)=>{let n=f.get(e)??[];return c(e)+s(e)*(n.indexOf(t)+1)/(n.length+1)};return t.flatMap(({edge:e})=>{let t=n.get(e.from),r=n.get(e.to);if(t===void 0||r===void 0)return[];if(e.from===e.to)return[jN(e,t)];let a=i(e.from),o=i(e.to);if(a===o)return[MN(e,t,r)];let s=o>a,c={x:s?t.x+t.width:t.x,y:wN(t,e.kind)},l={x:s?r.x:r.x+r.width,y:wN(r,e.kind)},u=d.get(e.index);if(u===void 0){let n=AN(t,r);return[n===void 0?kN(e,c,l):kN(e,{...c,y:n},{...l,y:n})]}let f=Math.min(a,o),m=Math.max(a,o),h=p(s?f:m-1,e.index),g=p(s?m-1:f,e.index);return[FN(e,[c,{x:h,y:c.y},{x:h,y:u},{x:g,y:u},{x:g,y:l.y},l])]})},LN=({layers:e,chains:t,centers:n,space:r,reach:i})=>{let a=e=>n.get(e)??0,o=(e,t,o,s)=>{let c=a(e),l=t.map(e=>a(e)).toSorted((e,t)=>Math.abs(e-c)-Math.abs(t-c))[0];l!==void 0&&Math.abs(l-c)<i&&(o===void 0||a(o)+r(o,e)<=l)&&(s===void 0||l<=a(s)-r(e,s))&&n.set(e,l)},s=new Map,c=new Map;for(let{edge:e,stops:n}of t)e.kind===`flow`&&n.length===2&&(s.set(e.to,[...s.get(e.to)??[],e.from]),c.set(e.from,[...c.get(e.from)??[],e.to]));for(let t of e)for(let[e,n]of t.entries())o(n,s.get(n)??[],t[e-1],t[e+1]);for(let t of e)for(let[e,n]of t.entries())s.has(n)||o(n,c.get(n)??[],t[e-1],t[e+1])},RN=14,zN=(e,t)=>`\0${String(e.index)}:${String(t)}`,BN=e=>e.startsWith(`\0`),VN=e=>(t,n)=>{let r=e=>BN(e)?0:23,i=BN(t)||BN(n)?RN:20;return r(t)+r(n)+Math.max(i,e.get(n)??0)},HN=e=>{let t=new Map;for(let{from:n,to:r,label:i}of e)n===r&&t.set(n,Math.max(t.get(n)??0,pj(i)));return t},UN=(e,t)=>e.map(e=>{let n=t.get(e.from)??0,r=t.get(e.to)??0,i=r>n?1:-1,a=Array.from({length:Math.max(Math.abs(r-n)-1,0)},(t,r)=>zN(e,n+i*(r+1)));return{edge:e,stops:[e.from,...a,e.to]}}),WN=(e,t)=>e.flatMap(({stops:e})=>e.slice(1).flatMap((n,r)=>{let i=e[r]??n,a=t(i),o=t(n);return a===o?[]:a<o?[[i,n]]:[[n,i]]})),GN=(e,t)=>{let n=[...e.flatMap(e=>[e.x,e.x+e.width]),...t.flatMap(e=>e.points.map(e=>e.x))],r=[...e.flatMap(e=>[e.y,e.y+e.height]),...t.flatMap(e=>e.points.map(e=>e.y)),...t.flatMap(({label:e,labelAt:t,labelLimit:n})=>{if(e===void 0||t===void 0)return[];let r=fj(dj(e,n).length)/2;return[t.y-r,t.y+r]})];return{minX:Math.min(...n),minY:Math.min(...r),maxX:Math.max(...n),maxY:Math.max(...r)}},KN=(e,t)=>{let{minX:n,minY:r,maxX:i,maxY:a}=GN(e,t),o=16-n,s=16-r,c=({x:e,y:t})=>({x:e+o,y:t+s});return{nodes:e.map(e=>({...e,...c(e)})),edges:t.map(e=>({...e,points:e.points.map(c),...e.labelAt===void 0?{}:{labelAt:c(e.labelAt)}})),width:i-n+32,height:a-r+32}},qN=e=>{let t=e.nodes.map(e=>e.id),n=hN(e),r=_N(t,n),i=UN(n,r),a=new Map;for(let{edge:e,stops:t}of i){let n=r.get(e.from)??0,i=(r.get(e.to)??0)>n?1:-1;for(let[e,r]of t.slice(1,-1).entries())a.set(r,n+i*(e+1))}let o=e=>r.get(e)??a.get(e)??0,s=Math.max(0,...r.values()),c=Array.from({length:s+1},()=>[]);for(let e of[...t,...a.keys()])c[o(e)]?.push(e);let l=WN(i,o),u=VN(HN(n)),d=dN(c,l),f=mN(d,l,u);LN({layers:d,chains:i,centers:f,space:u,reach:20});let p=new Map;for(let{edge:e,stops:t}of i)if(e.label!==void 0&&e.from!==e.to&&t.length===2&&o(e.from)!==o(e.to)){let t=Math.min(o(e.from),o(e.to)),n=Math.max(...dj(e.label).map(e=>e.length))*hj+32;p.set(t,Math.max(p.get(t)??48,n))}let m=e=>p.get(e)??48,h=[0];for(let e=0;e<s;e+=1)h.push((h[e]??0)+152+m(e));let g=e=>h[e]??0,_=new Map(e.nodes.map(({id:e,type:t})=>{let n=o(e);return[e,{id:e,type:t,x:g(n),y:(f.get(e)??0)-23,width:152,height:46,rank:n}]})),v=IN({chains:i,nodes:_,stopY:f,rankOf:o,columnX:g,columnWidth:152,gapWidth:m});return KN([..._.values()],v)},JN=e=>typeof e==`object`&&!!e&&!Array.isArray(e),YN=e=>Array.isArray(e)?e.filter(e=>JN(e)):[],XN=e=>typeof e.description==`string`?e.description:void 0,ZN=e=>e===!0?`On`:e===!1?`Off`:typeof e==`string`||typeof e==`number`?String(e):``,QN=e=>(Array.isArray(e.enum)?e.enum:`const`in e?[e.const]:e.type===`boolean`?[!0,!1]:void 0)?.map(e=>({value:e,label:ZN(e)})),$N=e=>[...YN(e.anyOf),...YN(e.oneOf)],eP=e=>{let t=$N(e);if(t.length>0){let e=t.map(e=>QN(e));if(e.every(e=>e!==void 0))return{kind:`choice`,options:e.flat()};let[n]=t;return t.length===1&&n!==void 0?eP(n):{kind:`variants`,variants:t}}let n=QN(e);if(n!==void 0)return{kind:`choice`,options:n};if(e.type===`string`)return{kind:`text`,pattern:typeof e.pattern==`string`?e.pattern:void 0};if(e.type===`number`||e.type===`integer`)return{kind:`number`,integer:e.type===`integer`};if(e.type===`array`){let t=YN(e.prefixItems),[n]=t;return n===void 0?{kind:`list`,item:JN(e.items)?e.items:{}}:{kind:`list`,item:n,fixed:t.length}}if(e.type===`object`){if(JN(e.properties)){let t=Array.isArray(e.required)?e.required:[];return{kind:`object`,fields:Object.entries(e.properties).flatMap(([e,n])=>JN(n)?[{key:e,schema:n,required:t.includes(e)}]:[])}}return{kind:`record`,value:JN(e.additionalProperties)?e.additionalProperties:{}}}return{kind:`free`}},tP=(e,t)=>{let n=eP(e);switch(n.kind){case`text`:return typeof t==`string`;case`number`:return typeof t==`number`;case`choice`:return n.options.some(e=>e.value===t);case`list`:return Array.isArray(t);case`object`:case`record`:return JN(t);case`variants`:return n.variants.some(e=>tP(e,t));case`free`:return!0;default:return!1}},nP=(e,t)=>{let n=e.findIndex(e=>tP(e,t));return n===-1?0:n},rP=[[`text`,`Text`],[`number`,`Number`],[`choice`,`Choice`],[`list`,`List`],[`object`,`Details`],[`record`,`Named values`],[`variants`,`Other`],[`free`,`Anything`]],iP=e=>{let{kind:t}=eP(e);return rP.find(([e])=>e===t)?.[1]??t},aP=e=>{let t=eP(e);switch(t.kind){case`number`:return 0;case`choice`:return t.options[0]?.value;case`list`:return[];case`object`:case`record`:return{};case`text`:case`variants`:case`free`:return``;default:return t}},oP=e=>typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):``,sP={budgetUsd:`Budget (USD)`,plainEnv:`Plain environment`,env:`Environment`,cwd:`Working folder`,maxRounds:`Max rounds`,maxTurns:`Max turns`,maxMessages:`Max messages`,dayUsd:`Per day (USD)`,weekUsd:`Per week (USD)`,monthUsd:`Per month (USD)`},cP=e=>{let t=sP[e];if(t!==void 0)return t;let n=e.replaceAll(/([a-z0-9])([A-Z])/gu,`$1 $2`).toLowerCase();return`${n.charAt(0).toUpperCase()}${n.slice(1)}`},lP=new Set([`prompt`,`instructions`,`question`,`script`,`body`,`command`]),uP=(e,t)=>lP.has(e)||typeof t==`string`&&t.includes(`
93
- `),dP=e=>Number.isFinite(Number(e))&&String(Number(e))===e,fP=e=>{let t=e.trim();if(t!==``){if(t===`true`)return!0;if(t===`false`)return!1;if(t===`null`)return null;if(dP(t))return Number(t);if(!/^[[{"]/u.test(t))return e;try{return JSON.parse(t)}catch{return e}}},pP=e=>e===void 0?``:typeof e==`string`&&fP(e)===e?e:JSON.stringify(e),mP=(e,t)=>{let n=JN(e.properties)?e.properties.nodes:void 0,r=JN(n)?n.additionalProperties:void 0;return JN(r)?$N(r).find(e=>{let n=e.properties,r=JN(n)?n.type:void 0;return JN(r)&&r.const===t}):void 0},hP=e=>{let t=JN(e.properties)?e.properties.nodes:void 0,n=JN(t)?t.additionalProperties:void 0;return JN(n)?$N(n).flatMap(e=>{let t=e.properties,n=JN(t)?t.type:void 0;return JN(n)&&typeof n.const==`string`?[n.const]:[]}):[]},gP=e=>{let[t,n]=e.path;return t===`nodes`&&typeof n==`string`?n:void 0},_P=e=>{let t=e.path.at(-1);return e.message.endsWith(`received undefined`)&&typeof t==`string`?`${cP(t)} is required.`:e.message},vP=e=>{let t=new Map;for(let n of e){let e=gP(n);e!==void 0&&t.set(e,[...t.get(e)??[],n])}return t},yP=(e,t)=>`${String(e)} ${t}${e===1?``:`s`}`,bP=(e,t)=>{let n=vP(t),r=!t.some(({code:e})=>/^(schema|yaml)\./u.test(e));return new Map(e.nodes.map(({id:e})=>{let t=n.get(e)??[],i=t.filter(e=>e.severity===`error`).length,a=t.length-i;return i>0?[e,{status:`failed`,word:yP(i,`error`)}]:a>0?[e,{status:`waiting`,word:yP(a,`warning`)}]:[e,{status:`queued`,word:r?`no problems`:`not checked yet`}]}))},xP=(e,t)=>e.filter(e=>e.path.length===t.length&&e.path.every((e,n)=>e===t[n])),SP=(e,t)=>{let n=e;for(let e of t)if(Array.isArray(n)&&typeof e==`number`)n=n[e];else if(typeof n==`object`&&n&&!Array.isArray(n))n=Object.entries(n).find(([t])=>t===e)?.[1];else return;return n},CP=(e,t)=>e===t||e!==void 0&&t!==void 0&&JSON.stringify(e)===JSON.stringify(t),wP=e=>e.filter(e=>e.severity===`error`).length,TP=(e,t)=>{let n=(e.split(`.`).at(-1)??`node`).toLowerCase();if(!t.includes(n))return n;let r=2;for(;t.includes(`${n}-${String(r)}`);)r+=1;return`${n}-${String(r)}`},EP=new Set([`tool.gh`,`tool.aws`,`mcp.call`,`workflow.call`]),DP=e=>e.nodes.filter(({type:e})=>EP.has(e)).map(({id:e,type:t})=>`${e} (${t})`),OP=e=>e.nodes.filter(({type:e})=>e===`agent.leader`||e===`agent.worker`).map(({id:e})=>e),kP={panel:`_panel_16yrr_8`,tools:`_tools_16yrr_21`,chooser:`_chooser_16yrr_37`,create:`_create_16yrr_38`,actions:`_actions_16yrr_39`,connect:`_connect_16yrr_40`,notices:`_notices_16yrr_53`,status:`_status_16yrr_73`,error:`_error_16yrr_79`,empty:`_empty_16yrr_89`,body:`_body_16yrr_99`,palette:`_palette_16yrr_118`,inspector:`_inspector_16yrr_119`,middle:`_middle_16yrr_146`,canvas:`_canvas_16yrr_160`,problems:`_problems_16yrr_174`,clean:`_clean_16yrr_175`,problemsHead:`_problemsHead_16yrr_203`,walk:`_walk_16yrr_215`,problemList:`_problemList_16yrr_224`,types:`_types_16yrr_225`,edges:`_edges_16yrr_226`,problemLink:`_problemLink_16yrr_250`,heading:`_heading_16yrr_266`,subheading:`_subheading_16yrr_283`,type:`_type_16yrr_225`,fields:`_fields_16yrr_321`,edge:`_edge_16yrr_226`,testRow:`_testRow_16yrr_338`,field:`_field_16yrr_321`,choice:`_choice_16yrr_345`,problem:`_problem_16yrr_174`,problemIcon:`_problemIcon_16yrr_376`,problemWords:`_problemWords_16yrr_386`,hint:`_hint_16yrr_390`,group:`_group_16yrr_404`,summary:`_summary_16yrr_424`,row:`_row_16yrr_435`,rowName:`_rowName_16yrr_449`,edgeName:`_edgeName_16yrr_480`},AP=({builder:e})=>{let t=e.schema===null?[]:hP(e.schema),n=e.view?.graph.nodes.map(({id:e})=>e)??[],r=async t=>{let r=TP(t,n);await e.edit({op:`addNode`,id:r,node:{type:t}})&&e.select(r)};return(0,q.jsxs)(`nav`,{"aria-label":`Add a node`,className:kP.palette,children:[(0,q.jsx)(`h2`,{className:kP.heading,children:`Add a node`}),(0,q.jsx)(`ul`,{className:kP.types,children:t.map(e=>(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{className:kP.type,onClick:()=>{r(e)},type:`button`,children:[(0,q.jsx)(sM,{type:e}),$j(e)]})},e))})]})},jP=({problems:e,walk:t,onChoose:n})=>e.length===0?(0,q.jsxs)(`output`,{className:kP.clean,children:[`No problems found.`,t===null?``:` ${t}`]}):(0,q.jsxs)(`section`,{"aria-label":`Problems`,className:kP.problems,children:[(0,q.jsxs)(`div`,{className:kP.problemsHead,children:[(0,q.jsx)(`h2`,{className:kP.heading,children:wP(e)>0?`Fix these before saving`:`Warnings`}),t===null?null:(0,q.jsx)(`p`,{className:kP.walk,children:t})]}),(0,q.jsx)(`ul`,{className:kP.problemList,children:e.map(e=>{let t=gP(e),r=`${e.code} ${e.path.join(`.`)} ${e.message}`;return(0,q.jsx)(`li`,{children:t===void 0?(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:_P(e)})}):(0,q.jsxs)(`button`,{className:kP.problemLink,onClick:()=>{n(t)},type:`button`,children:[_P(e).startsWith(`\`${t}\``)?null:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`code`,{children:t}),`:`,` `]}),(0,q.jsx)(r_,{text:_P(e)})]})},r)})})]}),MP={fields:[],canFail:!1,canDeclare:!1},NP=3,PP=(e,t)=>e.says?.[t]??MP,FP={is:`is`,isnt:`isn't`,above:`is above`,atLeast:`is at least`,below:`is below`,atMost:`is at most`,contains:`contains`,anyIs:`any is`,allAre:`all are`,isTrue:`is true`,isFalse:`is false`},IP={values:[`is`,`isnt`],statuses:[`anyIs`,`allAre`],number:[`above`,`atLeast`,`below`,`atMost`,`is`,`isnt`],boolean:[`isTrue`,`isFalse`],text:[`contains`,`is`,`isnt`]},LP=e=>IP[e.kind],RP=e=>e!==`isTrue`&&e!==`isFalse`,zP=e=>e.filter(({items:e})=>e===void 0),BP=(e,t)=>{let n=zP(t).find(({field:t})=>t===e.field);return n===void 0||!LP(n).includes(e.test)?!1:n.values===void 0||e.value===void 0||n.values.includes(e.value)},VP=({condition:e,when:t},n)=>{let r=e??{mode:`succeeds`};return r.mode===`test`&&!r.rows.every(e=>BP(e,n.fields))?{mode:`hand`,text:t??``}:r},HP=(e,t)=>{let n=LP(e)[0]??`is`;if(!RP(n))return{field:e.field,test:n};let r=e.values?.[0]??(e.kind===`number`?0:``);return{field:e.field,test:n,value:t??r}},UP=(e,t)=>{let n=zP(e.fields),r=n.find(({values:e})=>(e??[]).length>0)??n[0];return r===void 0?void 0:HP(r,r.values?.includes(t??``)===!0?t:void 0)},WP=e=>e.fields.flatMap(({field:e,values:t})=>e===`choice`?(t??[]).map(String):[]),GP=({condition:e},t)=>e===void 0||e.mode===`succeeds`||e.mode===`test`&&e.rows.some(({test:e,value:n})=>e===`is`&&n===t),KP=(e,t)=>{let n=e.edges.filter(({from:e})=>e===t);return n.length===0?[]:WP(PP(e,t)).filter(e=>!n.some(t=>GP(t,e)))},qP=(e,t,n)=>{let r=new Set([t]),i=[t];for(let t of i)for(let n of e.edges)n.from===t&&!r.has(n.to)&&(r.add(n.to),i.push(n.to));return r.has(n)},JP=e=>e===void 0?void 0:jw({mode:`test`,join:`all`,rows:[e]}),YP=(e,t,n)=>{let r=PP(e,t);if(qP(e,n,t))return JP(UP(r,`changes_requested`));let i=e.edges.filter(e=>e.from===t),a=WP(r);if(a.length>0){let[n]=i.length===0?a:KP(e,t);return n===void 0?void 0:JP({field:`choice`,test:`is`,value:n})}let o=i.find(({maxRounds:e})=>e!==void 0);return o?.condition===void 0?e.nodes.find(({id:e})=>e===t)?.type===`control.router`?JP(UP(r))??`true`:void 0:Nw(o.condition)},XP=(e,t,n)=>{let r=YP(e,t,n);return{op:`connect`,from:t,to:n,...r===void 0?{}:{when:r},...qP(e,n,t)?{maxRounds:NP}:{}}},ZP=e=>typeof e==`object`&&!!e&&!Array.isArray(e),QP=(e,t)=>{let n=new Set,r=[t];for(let t of r)for(let i of e.edges)i.to===t&&i.maxRounds===void 0&&!n.has(i.from)&&(n.add(i.from),r.push(i.from));return n.delete(t),n},$P=(e,t)=>{let n=QP(e,t);return e.nodes.filter(e=>n.has(e.id)).flatMap(t=>PP(e,t.id).fields.flatMap(({field:e,items:n})=>n===void 0?[]:[{node:t.id,field:e,items:n,template:`{{nodes.${t.id}.output.${e}}}`}]))},eF=e=>ZP(e)?`from`in e?`from`:`items`in e?`items`:`once`:`once`,tF=10,nF=(e,t)=>{if(t===`once`)return;let n=ZP(e)?e:{},r=Object.fromEntries(Object.entries(n).filter(([e])=>e===`maxParallel`||e===`onFailure`));return t===`items`?{items:[``],...r}:{from:``,maxItems:tF,...r}},rF=e=>{let t=Number(e.trim());return e.trim()!==``&&Number.isSafeInteger(t)&&t>0?t:void 0},iF=/^[A-Za-z_][A-Za-z0-9_-]*$/u,aF=[`string`,`number`,`integer`,`boolean`],oF=e=>{let t=new Map,n=[];for(let r of e.split(`,`)){let e=r.trim();if(e===``)continue;let[i=``,a=`string`,...o]=e.split(`:`).map(e=>e.trim());!iF.test(i)||o.length>0?n.push(`\`${e}\` isn't a field name. Use letters, digits, _ or -, then an optional :type.`):aF.some(e=>e===a)?t.has(i)?n.push(`\`${i}\` is listed twice.`):t.set(i,a):n.push(`\`${e}\` isn't a type. Use string, number, integer or boolean.`)}return{shape:Object.fromEntries(t),problems:n}},sF=e=>iF.test(e),cF=(e,t,n)=>n&&(t||e.startsWith(`agent.`)),lF=(e,t)=>e.startsWith(`agent.`)?t:`json.${t}`,uF=e=>{let t=(Array.isArray(e)?e:[]).map(e=>ZP(e)?Object.keys(e):[]),[n=[]]=t;return n.filter(e=>t.every(t=>t.includes(e)))},dF=(e,t)=>{if(!ZP(t))return[];if(`items`in t)return uF(t.items);let n=t.from;if(typeof n!=`string`)return[];let r=/^\{\{\s*nodes\.([^.\s]+)\.output\.(.+?)\s*\}\}$/u.exec(n);return PP(e,r?.[1]??``).fields.find(({field:e})=>e===r?.[2])?.items?.map(e=>e.field)??[]},fF=new Set([`prompt`,`command`,`arguments`,`inputs`,`env`,`ref`]),pF=(e,t,n,r)=>{let[i,,a]=t;if(i!==`nodes`||typeof a!=`string`||!fF.has(a)||!ZP(n))return r;let o=dF(e,n);return[r,`Reads ${["`{{item}}` and `{{index}}`",...o.length===0?[]:[o.map(e=>`\`{{item.${e}}}\``).join(`, `)]].join(`, and `)}.`].filter(Boolean).join(` `)},mF=e=>{let t=eP(e),n=t.kind===`variants`?t.variants[0]:void 0,r=n===void 0?void 0:n.properties,i=ZP(r)?r.items:void 0;return ZP(i)?i:{}},hF=(e,t,n)=>{let r=QP(e,n);return e.nodes.flatMap(({id:n,type:i})=>{let a=PP(e,n),o=t===null?void 0:mP(t,i),s=o===void 0?void 0:o.properties;return r.has(n)&&!a.fields.some(({kind:e})=>e===`statuses`)&&cF(i,a.canDeclare,ZP(s)&&`output`in s)?[{id:n,type:i,fields:a.fields.map(({field:e})=>e.replace(/^json\./u,``))}]:[]})},gF=(e,t)=>{e.context.change(e.path,()=>t)},_F=e=>typeof e==`object`&&!!e&&!Array.isArray(e),vF=({lines:e})=>e.map(e=>(0,q.jsxs)(`p`,{className:kP.problem,children:[(0,q.jsx)(`span`,{className:kP.problemIcon,children:(0,q.jsx)(Fj,{})}),(0,q.jsx)(`span`,{className:kP.problemWords,children:(0,q.jsx)(r_,{text:e})})]},e)),yF=({label:e,unseen:t,shown:n,commit:r,description:i,required:a=!1,multiline:o=!1,number:s=!1})=>{let[c,l]=(0,U.useState)(n),[u,d]=(0,U.useState)(n),[f,p]=(0,U.useState)(null);return u!==n&&(d(n),p(null),n!==f&&l(n)),(0,q.jsx)(pk,{description:i,label:e,unseen:t,multiline:o,onChange:l,onCommit:()=>{c!==n&&c!==f&&(p(c),r(c))},required:a,type:s?`number`:`text`,value:c})},bF=`__not_set__`,xF=({options:e,...t})=>{let{name:n,schema:r,value:i,required:a}=t,o=[...a&&i!==void 0?[]:[{value:bF,label:a?`Choose one`:`Default`}],...e.map(e=>({value:oP(e.value),label:e.label}))],s=XN(r);return(0,q.jsxs)(`div`,{className:kP.choice,children:[(0,q.jsx)(uk,{label:cP(n),onChange:n=>{gF(t,n===bF?void 0:e.find(e=>oP(e.value)===n)?.value)},options:o,value:i===void 0?o[0]?.value??``:oP(i)}),s===void 0?null:(0,q.jsx)(`p`,{className:kP.hint,children:(0,q.jsx)(r_,{text:s})})]})},SF=({name:e,description:t,open:n,children:r})=>(0,q.jsxs)(`details`,{className:kP.group,open:n,children:[(0,q.jsx)(`summary`,{className:kP.summary,children:cP(e)}),t===void 0?null:(0,q.jsx)(`p`,{className:kP.hint,children:(0,q.jsx)(r_,{text:t})}),(0,q.jsx)(`div`,{className:kP.fields,children:r})]}),CF=/^[A-Za-z_][A-Za-z0-9_-]*$/u,wF=e=>e.split(`,`).map(e=>e.trim()).filter(e=>e!==``).map(e=>e===`true`?!0:e===`false`?!1:Number.isFinite(Number(e))?Number(e):e),TF=({to:e,onDeclare:t})=>{let[n,r]=(0,U.useState)(!1),[i,a]=(0,U.useState)(``),[o,s]=(0,U.useState)(``);if(!n)return(0,q.jsxs)(Y,{onClick:()=>{r(!0)},children:[`Add a field`,(0,q.jsxs)(lk,{children:[`, to `,e]})]});let c=wF(o);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(pk,{description:`A field of the JSON this node gives, such as state.`,label:`New field`,unseen:`, to ${e}`,onChange:a,value:i}),(0,q.jsx)(pk,{description:`Separated by commas. A run fails this node on anything else.`,label:`Its values`,unseen:`, to ${e}`,onChange:s,value:o}),(0,q.jsxs)(Y,{disabled:!CF.test(i)||c.length===0,onClick:()=>{t(i,c),r(!1),a(``),s(``)},children:[`Add `,i===``?`field`:i]})]})},EF=(e,t)=>{e?.querySelector(t)?.focus()},DF=({to:e,holders:t,onDeclare:n})=>{let r=(0,U.useRef)(null),[i,a]=(0,U.useState)(!1),[o,s]=(0,U.useState)(null),[c,l]=(0,U.useState)(``),[u,d]=(0,U.useState)(``),f=t.find(({id:e})=>e===o)??t[0];if(f===void 0)return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(Y,{disabled:!0,children:[`Add a list`,(0,q.jsxs)(lk,{children:[`, for `,e]})]}),(0,q.jsx)(`p`,{className:kP.hint,children:`No earlier node can declare a list. A list comes from a Claude node, tool or MCP call that runs before this one.`})]});if(!i)return(0,q.jsx)(`div`,{ref:r,children:(0,q.jsxs)(Y,{onClick:()=>{a(!0),queueMicrotask(()=>{EF(r.current,`input, [role=combobox]`)})},children:[`Add a list`,(0,q.jsxs)(lk,{children:[`, for `,e]})]})});let p=oF(u),m=f.fields.includes(c),h=c!==``&&!sF(c)?[`\`${c}\` isn't a name. Use letters, digits, _ or -.`]:m?[`\`${c}\` is already a field of \`${f.id}\`.`]:[],g=()=>{a(!1),l(``),d(``),queueMicrotask(()=>{EF(r.current,`button`)})};return(0,q.jsxs)(`div`,{className:kP.fields,ref:r,children:[t.length<2?null:(0,q.jsx)(uk,{label:`On node`,onChange:s,options:t.map(({id:e})=>({value:e,label:e})),value:f.id}),(0,q.jsx)(pk,{description:`A field of the JSON that node gives, such as tasks.`,label:`New list`,onChange:l,value:c}),(0,q.jsx)(vF,{lines:h}),(0,q.jsx)(pk,{description:`Separated by commas: a name, or name:type. Types: string, number, integer, boolean. Empty for items with no fields.`,label:`Item fields`,onChange:d,value:u}),(0,q.jsx)(vF,{lines:p.problems}),(0,q.jsxs)(Y,{disabled:!sF(c)||m||p.problems.length>0,onClick:()=>{n(f.id,c,p.shape),g()},children:[`Add `,c===``?`list`:c]}),(0,q.jsx)(Y,{onClick:g,children:`Cancel`})]})},OF=(e,t)=>t&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):e,kF=({row:e,fields:t,to:n,index:r,onChange:i})=>{let a=t.find(({field:t})=>t===e.field),o=`${r===0?``:`${String(r+1)} `}to ${n}`;if(a===void 0)return null;let s=a.values??[];return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(uk,{label:`Field`,unseen:`, ${o}`,onChange:e=>{let n=t.find(t=>t.field===e);n!==void 0&&i(HP(n))},options:t.map(({field:e})=>({value:e,label:e})),value:e.field}),(0,q.jsx)(uk,{label:`Test`,unseen:`, ${o}`,onChange:t=>{let n=t,{value:r}=HP(a);i({field:e.field,test:n,...RP(n)?{value:e.value??r??``}:{}})},options:LP(a).map(e=>({value:e,label:FP[e]})),value:e.test}),RP(e.test)&&s.length>0?(0,q.jsx)(uk,{label:`Value`,unseen:`, ${o}`,onChange:t=>{i({...e,value:s.find(e=>String(e)===t)??t})},options:s.map(e=>({value:String(e),label:String(e)})),value:String(e.value)}):null,RP(e.test)&&s.length===0?(0,q.jsx)(yF,{commit:t=>{i({...e,value:OF(t,a.kind===`number`)})},label:`Value`,unseen:`, ${o}`,number:a.kind===`number`,shown:String(e.value??``)}):null]})},AF=e=>`row ${String(e)}`,jF=({condition:e,says:t,to:n,onChange:r})=>{let{rows:i,join:a}=e,o=e=>{r({mode:`test`,join:a,rows:e})},s=UP(t);return(0,q.jsxs)(q.Fragment,{children:[i.length<2?null:(0,q.jsx)(uk,{label:`Which tests`,unseen:`, to ${n}`,onChange:e=>{r({mode:`test`,join:e===`any`?`any`:`all`,rows:i})},options:[{value:`all`,label:`All of these`},{value:`any`,label:`Any of these`}],value:a}),i.map((e,r)=>(0,q.jsxs)(`div`,{className:kP.testRow,children:[(0,q.jsx)(kF,{fields:zP(t.fields),index:r,onChange:e=>{o(i.map((t,n)=>n===r?e:t))},row:e,to:n}),i.length<2?null:(0,q.jsxs)(Y,{onClick:()=>{o(i.filter((e,t)=>t!==r))},children:[`Remove test `,String(r+1),(0,q.jsxs)(lk,{children:[`, to `,n]})]})]},AF(r))),s===void 0?null:(0,q.jsxs)(Y,{onClick:()=>{o([...i,s])},children:[`Add a test`,(0,q.jsxs)(lk,{children:[`, to `,n]})]})]})},MF=({to:e,says:t,condition:n,when:r,loop:i,gate:a,canBeOtherwise:o,onChange:s,onDeclare:c})=>{let[l,u]=(0,U.useState)(!1),d=UP(t),f=l?`hand`:n.mode,p=e=>{u(e===`hand`),e!==`hand`&&(e===`fails`?s(`!ok`):e===`otherwise`?s(`true`):e===`succeeds`?s():d!==void 0&&s(jw({mode:`test`,join:`all`,rows:[d]})))},m=[{value:`succeeds`,label:i?`Every round`:a?`Whatever the answer`:`When it succeeds`},...t.canFail?[{value:`fails`,label:`When it fails`}]:[],...d===void 0?[]:[{value:`test`,label:`When a test holds`}],...o?[{value:`otherwise`,label:`Otherwise`}]:[],{value:`hand`,label:`Written by hand`}];return(0,q.jsxs)(`div`,{className:kP.fields,children:[(0,q.jsx)(uk,{label:`Follow this edge`,unseen:`, to ${e}`,onChange:p,options:m,value:f}),f===`test`&&n.mode===`test`?(0,q.jsx)(jF,{condition:n,onChange:e=>{s(jw(e))},says:t,to:e}):null,f===`hand`?(0,q.jsx)(yF,{commit:e=>{s(e===``?void 0:e)},description:`An expression, such as status == 'pass'. It's kept as you write it.`,label:`Condition`,unseen:`, to ${e}`,shown:r??``}):null,t.canDeclare?(0,q.jsx)(TF,{onDeclare:c,to:e}):null]})},NF=e=>e.when===void 0?{}:{whenWas:e.when},PF=({edge:e,last:t,builder:n})=>{let{from:r,to:i}=e,a=n.view?.graph;if(a===void 0)return null;let o=a.nodes.find(({id:e})=>e===r)?.type,s=PP(a,r),c=e.maxRounds===void 0?{}:{maxRounds:e.maxRounds},l=t=>({op:`setEdge`,from:r,to:i,...t===void 0?{}:{when:t},...c,...NF(e)}),u=e.maxRounds!==void 0;return(0,q.jsxs)(`li`,{className:kP.edge,children:[(0,q.jsxs)(`p`,{className:kP.edgeName,children:[`To `,i]}),(0,q.jsx)(MF,{canBeOtherwise:o===`control.router`&&t,condition:VP(e,s),gate:o===`human.gate`,loop:u,onChange:e=>{n.edit(l(e))},onDeclare:(e,t)=>{let[i]=t;n.edit({op:`set`,path:[`nodes`,r,`output`,`schema`,e],value:t},l(jw({mode:`test`,join:`all`,rows:[{field:`json.${e}`,test:`is`,...i===void 0?{}:{value:i}}]})))},says:s,to:i,when:e.when}),(0,q.jsx)(yF,{commit:t=>{n.edit({op:`setEdge`,from:r,to:i,...e.when===void 0?{}:{when:e.when},...t===``?{}:{maxRounds:Number(t)},...NF(e)})},description:`Needed on an edge that closes a loop.`,label:`Max rounds`,unseen:`, to ${i}`,number:!0,shown:e.maxRounds===void 0?``:String(e.maxRounds)}),(0,q.jsxs)(Y,{onClick:()=>{n.edit({op:`disconnect`,from:r,to:i,...NF(e)})},children:[`Remove edge`,(0,q.jsxs)(lk,{children:[` to `,i]})]})]})},FF=({id:e,builder:t})=>{let n=t.view?.graph,[r,i]=(0,U.useState)(``);if(n===void 0)return null;let a=n.edges.filter(({from:t})=>t===e),o=n.edges.filter(({to:t})=>t===e),s=n.nodes.map(e=>e.id).filter(e=>!a.some(({to:t})=>t===e)).toSorted((t,n)=>Number(t===e)-Number(n===e)),c=s.includes(r)?r:s[0]??``,l=KP(n,e);return(0,q.jsxs)(`section`,{"aria-label":`Edges of ${e}`,className:kP.fields,children:[(0,q.jsx)(`h3`,{className:kP.subheading,children:`Edges`}),o.length===0?null:(0,q.jsxs)(`p`,{className:kP.hint,children:[`From `,o.map(({from:e})=>e).join(`, `)]}),a.length===0?(0,q.jsx)(`p`,{className:kP.hint,children:`Nothing follows this node yet.`}):(0,q.jsx)(`ul`,{className:kP.edges,children:a.map((e,n)=>(0,q.jsx)(PF,{builder:t,edge:e,last:n===a.length-1},`${e.to} ${String(a.slice(0,n).filter(({to:t})=>t===e.to).length)}`))}),l.length===0?null:(0,q.jsxs)(`p`,{className:kP.hint,children:[`Answering `,l.join(` or `),` ends the run here.`]}),s.length===0?null:(0,q.jsxs)(`div`,{className:kP.connect,children:[(0,q.jsx)(uk,{label:`Connect to`,onChange:i,options:s.map(e=>({value:e,label:e})),value:c}),(0,q.jsx)(Y,{onClick:()=>{t.edit(XP(n,e,c))},children:`Connect`}),(0,q.jsx)(Y,{"aria-pressed":t.connecting,onClick:()=>{t.setConnecting(!t.connecting)},children:t.connecting?`Cancel picking`:`Pick a card`})]})]})},IF=()=>{},LF=e=>Array.isArray(e)?e:[],RF=({name:e,path:t,schema:n,value:r,context:i,item:a,fixed:o,minRows:s=0,draw:c})=>{let l=Array.isArray(r)?r:[];return(0,q.jsxs)(SF,{description:XN(n),name:e,open:l.length>0,children:[l.map((n,r)=>(0,q.jsxs)(`div`,{className:kP.row,children:[c({context:i,name:`${e} ${String(r+1)}`,path:[...t,r],required:!0,schema:a,value:n}),o===void 0&&l.length>s?(0,q.jsxs)(Y,{onClick:()=>{i.change(t,e=>{let t=LF(e).filter((e,t)=>t!==r);return t.length===0?void 0:t})},children:[`Remove `,cP(e).toLowerCase(),` `,r+1]}):null]},r)),o!==void 0&&l.length>=o?null:(0,q.jsxs)(Y,{onClick:()=>{i.change(t,e=>[...LF(e),aP(a)])},children:[`Add to `,cP(e).toLowerCase()]})]})},zF=({name:e,path:t,schema:n,value:r,context:i,valueSchema:a,draw:o})=>{let s=_F(r)?Object.entries(r):[],[c,l]=(0,U.useState)(``),u=c.trim(),d=s.some(([e])=>e===u);return(0,q.jsxs)(SF,{description:XN(n),name:e,open:s.length>0,children:[s.map(([e,n])=>(0,q.jsxs)(`div`,{className:kP.row,children:[o({context:i,name:e,path:[...t,e],required:!0,schema:a,value:n}),(0,q.jsxs)(Y,{onClick:()=>{i.change([...t,e],IF)},children:[`Remove `,e]})]},e)),(0,q.jsx)(pk,{description:d?`${u} is already here.`:void 0,label:`New name in ${cP(e).toLowerCase()}`,onChange:l,value:c}),(0,q.jsxs)(Y,{disabled:u===``||d,focusableWhenDisabled:!0,onClick:()=>{i.change([...t,u],e=>e===void 0?aP(a):e),l(``)},children:[`Add to `,cP(e).toLowerCase()]})]})},BF=e=>{let{name:t,value:n,variants:r,draw:i}=e,a=nP(r,n),o=r[a]??{};return(0,q.jsxs)(`div`,{className:kP.fields,children:[(0,q.jsx)(uk,{label:`${cP(t)} as`,onChange:t=>{gF(e,aP(r[Number(t)]??{}))},options:r.map((e,t)=>({value:String(t),label:iP(e)})),value:String(a)}),i({...e,schema:o})]})},VF=e=>(0,q.jsx)(WF,{...e}),HF=({fields:e,value:t,path:n,context:r})=>{let i=_F(t)?t:{};return(0,q.jsx)(q.Fragment,{children:e.map(({key:e,schema:t,required:a})=>(0,q.jsx)(WF,{context:r,name:e,path:[...n,e],required:a,schema:t,value:i[e]},e))})},UF=e=>{let{name:t,path:n,schema:r,value:i,required:a,context:o}=e,s=eP(r),c=XN(r);switch(s.kind){case`text`:return(0,q.jsx)(yF,{commit:t=>{gF(e,t===``&&!a?void 0:t)},description:c,label:cP(t),multiline:uP(t,i),required:a,shown:typeof i==`string`?i:``});case`number`:return(0,q.jsx)(yF,{commit:t=>{gF(e,t===``?void 0:Number(t))},description:c,label:cP(t),number:!0,required:a,shown:typeof i==`number`?String(i):``});case`choice`:return(0,q.jsx)(xF,{...e,options:s.options});case`object`:return(0,q.jsx)(SF,{description:c,name:t,open:_F(i)&&Object.keys(i).length>0,children:(0,q.jsx)(HF,{context:o,fields:s.fields,path:n,value:i})});case`list`:return(0,q.jsx)(RF,{...e,draw:VF,fixed:s.fixed,item:s.item,minRows:typeof r.minItems==`number`?r.minItems:0});case`record`:return(0,q.jsx)(zF,{...e,draw:VF,valueSchema:s.value});case`variants`:return(0,q.jsx)(BF,{...e,draw:VF,variants:s.variants});case`free`:return(0,q.jsx)(yF,{commit:t=>{gF(e,fP(t))},description:c??`Text, or JSON for a number or a list. Quote text that looks like either, such as "5".`,label:cP(t),multiline:typeof i==`string`&&i.includes(`
94
- `),shown:pP(i)});default:return s}},WF=e=>{let{path:t,context:n,schema:r}=e,i=n.problems(t),a=t.length===3?n.hint?.(t,XN(r)):void 0,o=a===void 0?e:{...e,schema:{...r,description:a}};return(0,q.jsxs)(`div`,{className:kP.field,"data-problem":i.length>0?``:void 0,children:[n.custom?.(e)??UF(o),(0,q.jsx)(vF,{lines:i})]})},GF=e=>Array.isArray(e)?e:[],KF=({field:e,catalog:t})=>{let n=Array.isArray(e.value)?e.value.filter(e=>typeof e==`string`):[],[r,i]=(0,U.useState)(``),a=t=>{e.context.change(e.path,e=>GF(e).includes(t)?e:[...GF(e),t])},o=t.skills.filter(({name:e})=>!n.includes(e));return(0,q.jsxs)(`div`,{className:kP.fields,children:[(0,q.jsx)(`h3`,{className:kP.subheading,children:`Skills`}),n.length===0?(0,q.jsx)(`p`,{className:kP.hint,children:`It gets what the workflow and the project give it.`}):(0,q.jsx)(`ul`,{className:kP.edges,children:n.map(t=>(0,q.jsxs)(`li`,{className:kP.row,children:[(0,q.jsx)(`span`,{className:kP.rowName,children:t}),(0,q.jsxs)(Y,{onClick:()=>{e.context.change(e.path,e=>{let n=GF(e).filter(e=>e!==t);return n.length===0?void 0:n})},children:[`Remove `,t]})]},t))}),(0,q.jsx)(aC,{empty:`No skill matches.`,label:`Add a skill`,onChange:e=>{e!==null&&a(e)},options:o.map(({name:e,layer:t})=>({value:e,label:`${e} (${t})`})),placeholder:o.length===0?`No skills found`:`Type to find a skill`,value:null}),(0,q.jsx)(pk,{description:`Or a path to one, such as ./skills/checklist.`,label:`Skill by path`,onChange:i,onCommit:()=>{r.trim()!==``&&a(r.trim()),i(``)},value:r})]})},qF=(e,t)=>eP(t.schema).kind===`list`?(0,q.jsx)(KF,{catalog:e.catalog,field:t}):null,JF=`stop looking`,YF=({says:e,condition:t,until:n,onChange:r,onDeclare:i})=>{let[a,o]=(0,U.useState)(!1),s=VP({condition:t,when:n},e),c=UP(e),l=!a&&s.mode===`test`,u=n===void 0&&!a,d=u?`unset`:l?`test`:`hand`;return(0,q.jsxs)(`div`,{className:kP.fields,children:[(0,q.jsx)(uk,{label:`Look until`,onChange:e=>{o(e===`hand`),e===`test`&&c!==void 0&&r(jw({mode:`test`,join:`all`,rows:[c]}))},options:[...u?[{value:`unset`,label:`Choose one`}]:[],...c===void 0?[]:[{value:`test`,label:`A test holds`}],{value:`hand`,label:`Written by hand`}],value:d}),l?(0,q.jsx)(jF,{condition:s,onChange:e=>{r(jw(e))},says:e,to:JF}):null,d===`hand`?(0,q.jsx)(yF,{commit:e=>{r(e===``?void 0:e)},description:`An expression, such as json.state != 'pending'. It's kept as you write it.`,label:`Condition`,shown:n??``,unseen:`, to ${JF}`}):null,e.canDeclare?(0,q.jsx)(TF,{onDeclare:i,to:JF}):null]})},XF=({builder:e,id:t,field:n})=>{let r=e.view?.graph;return r===void 0?null:(0,q.jsx)(YF,{condition:r.untils?.[t],onChange:e=>{gF(n,e)},onDeclare:(n,r)=>{let[i]=r;e.edit({op:`set`,path:[`nodes`,t,`output`,`schema`,n],value:r},{op:`set`,path:[`nodes`,t,`watch`,`until`],value:`json.${n} == ${JSON.stringify(i)}`})},says:PP(r,t),until:typeof n.value==`string`?n.value:void 0})},ZF=`__none__`,QF=(e,t)=>{let{document:n}=e.view??{},r=_F(n)?n.inputs:void 0,i=_F(r)?r[String(t.path[1])]:void 0,a=_F(i)?i.type:void 0,o=typeof a==`string`?a:`string`;return t.value===void 0||typeof t.value===o?UF({...t,schema:{...t.schema,type:o}}):null},$F=(e,t,n)=>{let r=e.view?.graph;if(r===void 0)return null;let i=n.path.at(-1),a=typeof n.value==`string`?n.value:void 0;if(i===`parent`&&t!==null){let e=r.nodes.map(e=>e.id).filter(e=>e!==t);return(0,q.jsx)(uk,{label:`Owner`,onChange:e=>{gF(n,e===ZF?void 0:e)},options:[...n.required?[]:[{value:ZF,label:`None`}],...e.map(e=>({value:e,label:e}))],value:a??ZF})}if(i===`n`&&t!==null&&n.path.length===3){let e=r.edges.filter(({to:e})=>e===t).length,i=typeof n.value==`number`?n.value:1,a=Array.from({length:Math.max(e,i,1)},(e,t)=>String(t+1));return(0,q.jsx)(uk,{label:`How many inputs to wait for`,onChange:e=>{gF(n,Number(e))},options:a.map(e=>({value:e,label:e})),value:String(i)})}if((i===`recommended`||i==="default")&&t!==null&&n.path.length===3){let e=PP(r,t).fields.find(({field:e})=>e===`choice`)?.values??[];if(e.length>0)return(0,q.jsx)(uk,{label:i==="default"?`If it times out`:`Recommended`,onChange:e=>{gF(n,e===ZF?void 0:e)},options:[{value:ZF,label:`None`},...e.map(e=>({value:String(e),label:String(e)}))],value:a??ZF})}return i===`until`&&t!==null&&n.path.includes(`watch`)?(0,q.jsx)(XF,{builder:e,field:n,id:t}):i===`to`&&n.path.includes(`notify`)?(0,q.jsx)(uk,{label:`To`,onChange:e=>{gF(n,e)},options:OP(r).map(e=>({value:e,label:e})),value:a??``}):i===`agent`?(0,q.jsx)(aC,{empty:`No agent matches.`,label:`Agent`,onChange:e=>{gF(n,e??void 0)},options:e.catalog.agents.map(({name:e,source:t})=>({value:e,label:`${e} (${t})`})),placeholder:`Type to find an agent`,value:a??null}):i==="default"&&n.path[0]===`inputs`?QF(e,n):i===`skills`?qF(e,n):null},eI=`__not_chosen__`,tI=[{value:`once`,label:`Once`},{value:`items`,label:`Once per item, listed here`},{value:`from`,label:`Once per item of a list from an earlier node`}],nI=({field:e,label:t,description:n,required:r,bad:i,onBad:a})=>(0,q.jsxs)(`div`,{className:kP.field,children:[(0,q.jsx)(yF,{commit:t=>{let n=rF(t),i=t.trim()===``&&!r;a(n===void 0&&!i),(n!==void 0||i)&&gF(e,n)},description:n,label:t,number:!0,required:r,shown:typeof e.value==`number`?String(e.value):``}),(0,q.jsx)(`div`,{role:`alert`,children:(0,q.jsx)(vF,{lines:i?[`${t} needs a whole number above 0.`]:[]})})]}),rI=({builder:e,id:t,field:n})=>{let r=e.view?.graph,i=(0,U.useRef)(null),[a,o]=(0,U.useState)(!1),[s,c]=(0,U.useState)(!1),l=eF(n.value),[u,d]=(0,U.useState)(l!==`once`);if(l!==`once`&&!u&&d(!0),r===void 0)return null;let{value:f,context:p,path:m}=n,h=_F(f)?f:{},g=typeof h.from==`string`?h.from:``,_=$P(r,t),v=_.find(({template:e})=>e===g),y=hF(r,e.schema,t),b=async(t,n,r)=>{let a=`{{nodes.${t}.output.${lF(y.find(e=>e.id===t)?.type??``,n)}}}`;await e.edit({op:`set`,path:[`nodes`,t,`output`,`schema`,n],value:{list:r}},{op:`set`,path:[...m,`from`],value:a}),i.current?.querySelectorAll(`[role=combobox]`)[1]?.focus()},x=e=>({...n,name:e,path:[...m,e],value:h[e]});return(0,q.jsx)(SF,{description:XN(n.schema),name:`forEach`,open:u,children:(0,q.jsxs)(`div`,{className:kP.fields,ref:i,children:[(0,q.jsx)(uk,{label:`Run this node`,onChange:e=>{gF(n,nF(f,e))},options:tI,value:l}),l===`once`?null:(0,q.jsx)(`p`,{className:kP.hint,children:(0,q.jsx)(r_,{text:`Items are \`${t}.0\` to \`${t}.n\`. Their results gather into \`results\`, \`statuses\` and \`count\`.`})}),l===`items`?(0,q.jsx)(WF,{...x(`items`),required:!0,schema:mF(n.schema)}):null,l===`from`?(0,q.jsxs)(`div`,{className:kP.field,children:[(0,q.jsx)(uk,{label:`List from`,onChange:e=>{let t=_.find(({template:t})=>t===e);t!==void 0&&p.change([...m,`from`],()=>t.template)},options:[...g===``?[{value:eI,label:`Choose a list`}]:[],...g===``||v!==void 0?[]:[{value:g,label:`${g} (not offered)`}],..._.map(({node:e,field:t,template:n})=>({value:n,label:`${t} (from ${e})`}))],value:g===``?eI:g}),(0,q.jsx)(vF,{lines:p.problems([...m,`from`])}),v===void 0?null:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`p`,{className:kP.hint,children:(0,q.jsx)(r_,{text:`Writes \`${v.template}\``})}),(0,q.jsx)(`p`,{className:kP.hint,children:(0,q.jsx)(r_,{text:v.items.length===0?`Items have no declared fields.`:`Each item has ${v.items.map(e=>`\`${e.field}\``).join(`, `)}.`})})]}),_.length===0?(0,q.jsx)(`p`,{className:kP.hint,children:`No earlier node declares a list. Add one below, or connect this node after one that does.`}):null,(0,q.jsx)(DF,{holders:y,onDeclare:(e,t,n)=>{b(e,t,n)},to:t})]}):null,l===`from`?(0,q.jsx)(nI,{bad:a,description:`A longer list asks whether to stop, run this many, or run all.`,field:x(`maxItems`),label:`Most items`,onBad:o,required:!0}):null,l===`once`?null:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(nI,{bad:s,description:"Default: the run's `limits.concurrency`.",field:x(`maxParallel`),label:`Most at once`,onBad:c,required:!1}),(0,q.jsx)(uk,{label:`When an item fails`,onChange:e=>{p.change([...m,`onFailure`],()=>e===`stop`?`stop`:void 0)},options:[{value:`finish`,label:`Run every item`},{value:`stop`,label:`Start no more items`}],value:h.onFailure===`stop`?`stop`:`finish`})]})]})})},iI=(e,t,n)=>n.path.at(-1)===`forEach`&&t!==null&&n.path.length===3?(0,q.jsx)(rI,{builder:e,field:n,id:t}):null,aI=e=>typeof e!=`string`||e.includes(`{{`)?void 0:UD(e,KC).driver,oI="A model for the run's driver, or `<driver>.<model>`, such as `claude-code.sonnet`.",sI=(e,t)=>{let n=aI(e);return[t??oI,...n===void 0?[]:[`Runs on ${n}.`]].join(` `)},cI=(e,t)=>{let n=aI(e);return n===void 0||typeof t!=`string`||t===n?void 0:`Model names ${n}, but this node's driver is ${t}. Make them match, or drop the prefix.`},lI=e=>e.at(-1)===`model`&&(e[0]===`nodes`&&e.length===3||e[0]===`defaults`&&e.length===2),uI=(e,t,n)=>({custom:n=>iI(e,t,n)??$F(e,t,n),hint:(t,n)=>{let r=e.view?.graph,i=e.view?.document,a=_F(i)?i.nodes:void 0,o=_F(a)?a[String(t[1])]:void 0,s=r===void 0||!_F(o)?n:pF(r,t,o.forEach,n);return lI(t)&&_F(o)?sI(o.model,s):s},change:(t,n)=>{e.change(t,n)},problems:t=>{let r=xP(n,t).map(e=>_P(e)),i=e.view?.document,a=lI(t)&&r.length===0?cI(SP(i,t),SP(i,[...t.slice(0,-1),`driver`])):void 0;return a===void 0?r:[...r,a]}}),dI=({schema:e,value:t,path:n,hide:r,context:i})=>{let a=eP(e);if(a.kind!==`object`)return null;let o=_F(t)?t:{};return(0,q.jsx)(q.Fragment,{children:a.fields.filter(({key:e})=>!r.includes(e)).map(e=>(0,q.jsx)(WF,{context:i,name:e.key,path:[...n,e.key],required:e.required,schema:e.schema,value:o[e.key]},e.key))})},fI=e=>_F(e)&&typeof e.type==`string`?e.type:``,pI=({id:e,builder:t})=>{let{view:n,schema:r}=t,[i,a]=(0,U.useState)(e),o=(0,U.useRef)(e),s=n?.document,c=_F(s)?s.nodes:void 0,l=_F(c)?c[e]:void 0,u=fI(l),d=r===null?void 0:mP(r,u),f=async()=>{i!==o.current&&(o.current=i,await t.edit({op:`renameNode`,from:e,to:i})?t.select(i):(o.current=e,a(e)))},p=async()=>{await t.edit({op:`removeNode`,id:e})&&t.select(null)};return(0,q.jsxs)(`div`,{className:kP.fields,children:[(0,q.jsx)(`h2`,{className:kP.heading,children:$j(u)}),(0,q.jsx)(pk,{description:`Lowercase, and read by other nodes. A new name follows every reference.`,label:`Name`,onChange:a,onCommit:()=>{f()},value:i}),d===void 0?(0,q.jsx)(`p`,{className:kP.hint,children:`This node has no known type, so there are no fields to show.`}):(0,q.jsx)(dI,{context:uI(t,e,n?.diagnostics??[]),hide:[`type`],path:[`nodes`,e],schema:d,value:l}),(0,q.jsx)(FF,{builder:t,id:e}),(0,q.jsxs)(Y,{onClick:()=>{p()},children:[`Remove `,e]})]})},mI=({builder:e})=>{let{view:t,schema:n}=e;return n===null?null:(0,q.jsxs)(`div`,{className:kP.fields,children:[(0,q.jsx)(`h2`,{className:kP.heading,children:`Workflow`}),(0,q.jsx)(dI,{context:uI(e,null,t?.diagnostics??[]),hide:[`schemaVersion`,`nodes`,`edges`],path:[],schema:n,value:t?.document})]})},hI=({builder:e})=>{let{selected:t,view:n}=e,r=n?.graph.nodes.some(({id:e})=>e===t)===!0;return t!==null&&r?(0,q.jsx)(pI,{builder:e,id:t},t):(0,q.jsx)(mI,{builder:e})},gI=({builder:e})=>{let t=e.view?.graph,n=e.view?.diagnostics,r=(0,U.useMemo)(()=>t===void 0?null:qN(t),[t]),i=(0,U.useMemo)(()=>t===void 0||n===void 0?void 0:bP(t,n),[t,n]);if(t===void 0||r===null)return null;if(t.nodes.length===0)return(0,q.jsx)(qD,{title:`No nodes yet.`,children:`Add one from the list beside this.`});let{selected:a,connecting:o}=e;return(0,q.jsx)(aN,{facts:i,label:`Workflow ${e.opened?.name??``}`,layout:r,onSelect:n=>{o&&a!==null?(e.setConnecting(!1),e.edit(XP(t,a,n))):e.select(n)},selected:a??void 0})},_I=({builder:e})=>{let{view:t}=e;return t===null?(0,q.jsx)(`div`,{className:kP.empty,children:(0,q.jsxs)(qD,{title:`No workflow open.`,children:[`Choose one above, or name a new one. A workflow you make here is the same file you could write by hand, and works with every`,` `,(0,q.jsx)(`code`,{children:`ork`}),` command.`]})}):(0,q.jsxs)(`div`,{className:kP.body,children:[(0,q.jsx)(AP,{builder:e}),(0,q.jsxs)(`div`,{className:kP.middle,children:[(0,q.jsx)(`div`,{className:kP.canvas,children:(0,q.jsx)(gI,{builder:e})}),(0,q.jsx)(jP,{onChoose:e.select,problems:t.diagnostics,walk:t.walk})]}),(0,q.jsx)(`aside`,{"aria-label":`Inspector`,className:kP.inspector,children:(0,q.jsx)(hI,{builder:e})})]})},vI=({builder:e})=>{let t=ob(),n=vb(t.projects.state),r=vb(t.workflows.state),i=n.status===`ready`?n.data:[],a=vb(t.builder.project),[o,s]=(0,U.useState)(``),c=a??(i.length===1?i[0]?.id:null)??null,{chooseProject:l}=e;(0,U.useEffect)(()=>{t.projects.load()},[t]),(0,U.useEffect)(()=>{c!==null&&(t.workflows.load(c),l(c))},[t,c,l]);let u=r.status===`ready`&&r.arg===c?r.data.map(({name:e})=>e):[],d=[...new Set([...u,...e.drafts])].toSorted(),f=async()=>{c!==null&&o!==``&&await e.create(c,o)&&s(``)};return(0,q.jsxs)(`div`,{className:kP.chooser,children:[(0,q.jsx)(aC,{empty:`No project matches.`,label:`Project`,onChange:e=>{t.builder.project.setValue(e)},options:i.map(({id:e})=>({value:e,label:e})),placeholder:`Type to find a project`,value:c}),(0,q.jsx)(aC,{disabled:c===null||d.length===0,empty:`No workflow matches.`,label:`Workflow`,onChange:t=>{c!==null&&t!==null&&e.open(c,t)},options:d.map(t=>({value:t,label:e.drafts.includes(t)?`${t} (draft)`:t})),placeholder:d.length===0?`None yet`:`Type to find one`,value:e.opened?.name??null}),(0,q.jsxs)(`form`,{className:kP.create,onSubmit:e=>{e.preventDefault(),f()},children:[(0,q.jsx)(pk,{label:`New workflow`,onChange:s,value:o}),(0,q.jsx)(Y,{disabled:c===null||o===``,focusableWhenDisabled:!0,type:`submit`,children:`Create`})]})]})},yI={agents:[],skills:[]},bI=e=>typeof e==`object`&&!!e&&!Array.isArray(e),xI=e=>{let[t,n]=(0,U.useState)(null),[r,i]=(0,U.useState)(yI),[a,o]=(0,U.useState)([]),s=(0,U.useRef)(null);(0,U.useEffect)(()=>{(async()=>{let t=await e.call(`builderSchema`);t.ok&&bI(t.data)&&n(t.data)})()},[e]);let c=(0,U.useCallback)(async t=>{let n={id:t},[r,a]=await Promise.all([e.call(`builderDrafts`,{params:n}),e.call(`builderCatalog`,{params:n})]);s.current===t&&(r.ok&&o(r.data),a.ok&&i(a.data))},[e]);return{schema:t,catalog:r,drafts:a,setDrafts:o,forProject:(0,U.useCallback)(e=>{s.current!==e&&o([]),s.current=e,c(e)},[c]),refreshDrafts:(0,U.useCallback)(()=>{s.current!==null&&c(s.current)},[c])}},SI=({project:e,name:t})=>({id:e,name:t}),CI=()=>{let{client:e,builder:t}=ob(),{inTurn:n,history:r,view:i,opened:a}=t,o=vb(a),s=vb(i),c=vb(t.selected),l=vb(r).length>0,[u,d]=(0,U.useState)(!1),[f,p]=(0,U.useState)(null),[m,h]=(0,U.useState)(null),{schema:g,catalog:_,drafts:v,setDrafts:y,refreshDrafts:b,forProject:x}=xI(e),S=(0,U.useCallback)(e=>{r.setValue(e)},[r]),C=(0,U.useCallback)(e=>{let t=a.getValue();return t?.project===e.project&&t.name===e.name},[a]),w=(0,U.useCallback)((e,n)=>{t.show(e,n),d(!1),p(null),h(null)},[t]),T=(0,U.useCallback)(e=>{x(e);let t=a.getValue();t!==null&&t.project!==e&&w(null,null)},[x,a,w]),E=(0,U.useCallback)((e,n)=>C(e)?n.ok?(t.update(n.data),p(null),!0):(p(n.error),!1):n.ok,[C,t]),D=(0,U.useCallback)((t,r)=>n(async()=>{let n={project:t,name:r},i=await e.call(`builderView`,{params:SI(n)});i.ok?w(n,i.data):p(i.error)}),[e,n,w]),O=(0,U.useCallback)((t,r)=>n(async()=>{let n=await e.call(`builderCreate`,{params:{id:t},body:{name:r}});return n.ok?(w({project:t,name:r},n.data),y(e=>[...e,r]),!0):(p(n.error),!1)}),[e,n,y,w]),k=(0,U.useCallback)(async(t,n)=>{let i=await e.call(`builderEdit`,{params:SI(t),body:{edits:n}}),a=E(t,i);return i.ok&&C(t)&&i.data.text!==i.data.previous.text&&S([...r.getValue(),i.data.previous]),a},[e,r,C,E,S]);return{opened:o,view:s,selected:c,connecting:u,refusal:f,canUndo:l,replaceAsked:m,schema:g,catalog:_,drafts:v,chooseProject:T,open:D,create:O,edit:(0,U.useCallback)((...e)=>o===null?Promise.resolve(!1):n(()=>k(o,e)),[n,o,k]),change:(0,U.useCallback)((e,t)=>o===null?Promise.resolve(!1):n(()=>{if(!C(o))return Promise.resolve(!1);let n=SP(i.getValue()?.document,e),r=t(n);if(CP(n,r))return Promise.resolve(!0);let a=[...e];return k(o,[r===void 0?{op:`delete`,path:a}:{op:`set`,path:a,value:r}])}),[n,C,o,k,i]),undo:(0,U.useCallback)(()=>o===null?Promise.resolve():n(async()=>{let t=r.getValue().at(-1);if(t===void 0||!C(o))return;let n=await e.call(`builderRestore`,{params:SI(o),body:t});E(o,n)&&S(r.getValue().slice(0,-1))}),[e,r,n,C,o,E,S]),discard:(0,U.useCallback)(()=>o===null?Promise.resolve():n(async()=>{let t=await e.call(`builderDiscard`,{params:SI(o)});b(),C(o)&&(t.ok?`gone`in t.data?w(null,null):w(o,t.data):p(t.error))}),[e,n,C,o,b,w]),save:(0,U.useCallback)((t=!1)=>{if(o===null)return Promise.resolve(!1);let r=SI(o);return n(async()=>{let n=await e.call(`builderSave`,{params:r,body:t?{force:!0}:{}});return n.ok?n.data.saved?(p(null),b(),C(o)&&S([]),E(o,await e.call(`builderView`,{params:r})),tb.add({title:`Saved ${o.name}`}),!0):(n.data.why===`changed`?h(n.data.message):p(n.data.message),!1):(p(n.error),!1)})},[e,n,C,o,b,E,S]),select:t.select,setConnecting:d,setReplaceAsked:h}},wI=()=>{let e=ob(),t=CI(),{view:n,opened:r,refusal:i,connecting:a,selected:o}=t,[s,c]=(0,U.useState)(!1),[l,u]=(0,U.useState)(!1),d=n===null?0:wP(n.diagnostics),f=n===null?[]:DP(n.graph),p=async()=>{await t.save()&&c(!0)},m=()=>{r!==null&&(e.workflows.load(r.project),e.runPreset.setValue({project:r.project,workflow:r.name}),e.runDialog.setValue(!0))};return(0,q.jsxs)(`div`,{className:kP.panel,children:[(0,q.jsxs)(`header`,{className:kP.tools,children:[(0,q.jsx)(vI,{builder:t}),n===null?null:(0,q.jsxs)(`div`,{className:kP.actions,children:[(0,q.jsx)(Y,{disabled:!t.canUndo,focusableWhenDisabled:!0,onClick:()=>{t.undo()},children:`Undo`}),(0,q.jsx)(Y,{disabled:!n.draft,focusableWhenDisabled:!0,onClick:()=>{u(!0)},children:`Discard`}),(0,q.jsx)(Y,{disabled:d>0||!n.draft,focusableWhenDisabled:!0,onClick:()=>{t.save()},variant:`primary`,children:`Save`}),(0,q.jsx)(Y,{disabled:d>0,focusableWhenDisabled:!0,onClick:()=>{p()},children:`Run…`})]})]}),n===null?null:(0,q.jsxs)(`div`,{className:kP.notices,children:[i===null?null:(0,q.jsx)(`p`,{className:kP.error,role:`alert`,children:(0,q.jsx)(r_,{text:i})}),(0,q.jsx)(`output`,{className:kP.status,children:a&&o!==null?`Choose the card ${o} leads to.`:n.changedOnDisk?`The file changed since this draft began. Saving will ask before replacing it.`:n.draft?`Unsaved changes are kept as a draft.`:``})]}),(0,q.jsx)(_I,{builder:t}),(0,q.jsx)(FC,{confirm:`Discard the draft`,description:`This throws away every unsaved change, and it can't be undone.`,onConfirm:()=>{u(!1),t.discard()},onOpenChange:u,open:l,title:`Discard the draft of ${r?.name??``}?`}),(0,q.jsx)(FC,{confirm:`Replace the file`,description:`${t.replaceAsked??``} Replacing it loses what changed there.`,onConfirm:()=>{t.setReplaceAsked(null),t.save(!0)},onOpenChange:e=>{e||t.setReplaceAsked(null)},open:t.replaceAsked!==null,title:`The file changed`}),(0,q.jsx)(FC,{confirm:`Choose how to run it`,description:`This starts a real run, which can spend money and commit work.${f.length===0?``:` These nodes act outside its worktree: ${f.join(`, `)}.`}`,onConfirm:()=>{c(!1),m()},onOpenChange:c,open:s,title:`Run ${r?.name??``}?`})]})},TI=new Set([`agent.leader`,`agent.worker`]),EI=e=>{let t=new Set;for(let{event:n}of e)if(n.type===`run.started`)for(let{id:e,type:r}of n.nodes)TI.has(r)&&t.add(e);else n.type===`node.started`&&TI.has(n.nodeType)&&t.add(n.id);return[...t]},DI={now:`delivered to its session`,queued:`waits for its next session`,resumed:`resumed its session`},OI=e=>e===void 0?{}:{note:e===`script`?`a script`:`a rule`},kI=/^mcp__ork__/u,AI=new Set([`StructuredOutput`]),jI=(e,t)=>e.type===`assistant.text`?{...t,kind:`node`,text:e.text}:e.type===`tool.called`?AI.has(e.name)?void 0:{...t,kind:`activity`,text:`Used ${e.name.replace(kI,``)}`}:e.type===`session.started`?{...t,kind:`activity`,text:`Session on ${e.model}`}:void 0,MI=({seq:e,at:t,event:n},r)=>{let i={seq:e,at:t},a=e=>({...i,kind:`activity`,text:e});if(n.type===`node.event`)return n.id===r?n.event.fork===!0?n.event.type===`session.started`?a(`A fork took a child's question`):void 0:jI(n.event,i):void 0;if(n.type===`node.finished`){if(n.id!==r)return;let{summary:e}=n.output;if(n.ok&&typeof e==`string`)return{...i,kind:`node`,text:e,note:`its report`};let t=n.error===void 0?``:`: ${n.error}`;return a(n.ok?`Finished.`:`Failed${t}`)}if(n.type===`message.sent`&&n.to===r)return{...i,kind:`peer`,from:n.node,text:n.body,...OI(n.via)};if(`node`in n&&n.node===r){if(n.type===`user.message`)return{...i,kind:`you`,text:n.body,note:DI[n.delivered]};if(n.type===`message.sent`)return a(n.via===`rule`?`A rule wrote to ${n.to}: ${n.body}`:`Wrote to ${n.to}: ${n.body}`);if(n.type===`message.received`)return{...i,kind:`peer`,from:n.from,text:n.body,...OI(n.via)};if(n.type===`decision.opened`)return a(`Asked you: ${n.question}`);if(n.type===`decision.answered`)return a(n.note===void 0?`You answered: ${n.answer}`:`You answered: ${n.answer}. You said: ${n.note}`)}},NI=(e,t)=>e.flatMap(e=>MI(e,t)??[]),PI=({live:e})=>e===`running`?null:e===`paused`?`The run is paused. Continue it to write to this node.`:`The run has ended (${e}). To resume this node's session, use:`,FI=(e,t)=>`ork chat ${e} ${t}`,II={panel:`_panel_s0gbu_7`,tools:`_tools_s0gbu_23`,main:`_main_s0gbu_33`,thread:`_thread_s0gbu_46`,items:`_items_s0gbu_62`,message:`_message_s0gbu_73`,meta:`_meta_s0gbu_81`,speaker:`_speaker_s0gbu_91`,time:`_time_s0gbu_101`,note:`_note_s0gbu_102`,text:`_text_s0gbu_112`,activity:`_activity_s0gbu_118`,activityText:`_activityText_s0gbu_131`,composer:`_composer_s0gbu_136`,box:`_box_s0gbu_156`,labelRow:`_labelRow_s0gbu_179`,send:`_send_s0gbu_189`,hint:`_hint_s0gbu_197`,why:`_why_s0gbu_198`,refusal:`_refusal_s0gbu_207`},LI=({run:e,node:t})=>{let n=ob(),r=(0,U.useId)(),i=(0,U.useId)(),[a,o]=(0,U.useState)(``),[s,c]=(0,U.useState)(!1),[l,u]=(0,U.useState)(null),d=PI(e),f=FI(e.id,t),p=(0,U.useRef)(!1),m=(0,U.useRef)(null);(0,U.useEffect)(()=>{d!==null&&p.current&&(p.current=!1,m.current?.focus())},[d]);let h=async()=>{if(s||a.trim()===``)return;c(!0),u(null);let r=await n.sendMessage(e.id,t,a);c(!1),r.ok?o(``):u(r.error)};return d===null?(0,q.jsxs)(`form`,{className:II.composer,onSubmit:e=>{e.preventDefault(),h()},children:[(0,q.jsxs)(`div`,{className:II.labelRow,children:[(0,q.jsxs)(`label`,{className:nC.label,htmlFor:r,children:[`Message to `,t]}),(0,q.jsx)(`span`,{className:II.hint,id:i,children:`Enter sends, Shift+Enter starts a new line.`})]}),(0,q.jsxs)(`div`,{className:II.send,children:[(0,q.jsx)(`textarea`,{"aria-describedby":i,className:II.box,id:r,onBlur:()=>{p.current=!1},onChange:e=>{o(e.target.value)},onFocus:()=>{p.current=!0},onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),h())},rows:1,value:a}),(0,q.jsx)(Y,{cli:`${f} -m …`,disabled:s||a.trim()===``,focusableWhenDisabled:!0,type:`submit`,variant:`primary`,children:s?`Sending…`:`Send`})]}),l===null?null:(0,q.jsx)(`p`,{className:II.refusal,role:`alert`,children:(0,q.jsx)(r_,{text:l})})]}):(0,q.jsxs)(`div`,{"aria-describedby":r,"aria-label":`Message to ${t}`,className:II.composer,ref:m,role:`group`,tabIndex:-1,children:[(0,q.jsx)(`p`,{className:II.why,id:r,children:(0,q.jsx)(r_,{text:d})}),e.live===`paused`?null:(0,q.jsx)(cC,{command:f})]})},RI=e=>`id`in e?e.id:`node`in e?e.node:`from`in e?e.from:void 0,zI=e=>e.replaceAll(/\s+/gu,` `).trim(),BI=e=>e===void 0?``:` (${e})`,VI=({event:e})=>{switch(e.type){case`session.started`:return`session on ${e.model}`;case`assistant.text`:return zI(e.text);case`session.waiting`:return zI(e.reason);case`tool.called`:return`${e.name} ${zI(JSON.stringify(e.input))}`;case`tool.result`:return e.isError?`tool failed`:`tool done`;case`plan.limit`:return e.status===`allowed`?``:`plan: ${e.window.replaceAll(`_`,` `)} limit ${e.status===`rejected`?`reached`:`is close`}`;case`session.finished`:return`session finished`;default:return``}},HI=e=>{let t=VI(e);return e.event.fork===!0&&t!==``?`fork: ${t}`:t},UI=e=>e.type===`node.finished`&&e.end.actor!==null?e:void 0,WI=(e,t)=>e>1?`round ${String(e)}: ${t}`:t,GI=({round:e,end:t})=>WI(e,t.message),KI=e=>{let{output:t,round:n,end:r}=e;if(r.actor!==null)return WI(n,`${r.label}: ${r.message}`);let{summary:i}=t;return WI(n,`ok${typeof i==`string`?`: ${zI(i)}`:``}`)},qI=e=>{switch(e.type){case`run.started`:return`${e.workflow}, ${String(e.nodes.length)} nodes`;case`run.resumed`:return`keeps ${String(e.kept.length)} nodes`;case`run.command`:return e.node===void 0?e.command:`${e.command} ${e.node}`;case`run.finished`:return e.result.status;case`node.started`:return e.round>1?`${e.nodeType}, round ${String(e.round)}`:e.nodeType;case`node.event`:return HI(e);case`node.finished`:return KI(e);case`each.listed`:return`${String(e.count)} items`;case`each.exceeded`:return`${String(e.count)} items, over ${String(e.maxItems)}`;case`edge.taken`:return`${e.from} -> ${e.to}`;case`loop.exhausted`:return`${e.from} -> ${e.to} after ${String(e.maxRounds)} rounds`;case`watch.started`:return`until ${e.until}, every ${e.every}`;case`watch.changed`:return`look ${String(e.looks)}: ${e.said}`;case`watch.ended`:return`${e.outcome} after ${String(e.looks)} looks`;case`worktree`:return`${e.action} ${e.branch??e.path}`;case`decision.opened`:return zI(e.question);case`decision.answered`:{let t=e.note===void 0?``:`; said: ${zI(e.note)}`;return`${e.answer}, by ${e.by}${t}`}case`message.sent`:return`to ${e.to}${BI(e.via)}: ${zI(e.body)}`;case`message.received`:return`from ${e.from}${BI(e.via)}: ${zI(e.body)}`;case`call.started`:return`${e.workflow} as ${e.run}`;case`link.notice`:return zI(e.text);case`owner.asked`:return`about ${e.about}: ${zI(e.text)}`;case`owner.answered`:return e.answer;case`user.message`:return`${e.delivered}: ${zI(e.body)}`;case`claim.taken`:return e.resource;case`claim.refused`:return`${e.resource}: ${e.holder} holds ${e.held}`;case`claim.released`:return`${e.resource}, ${e.reason}`;case`feedback.recorded`:return zI(e.feedback.title);case`slot.waiting`:return`held by ${e.holders.join(`, `)}`;case`verify.skipped`:return zI(`${e.check}: already passed on these files · ${e.at} · ${e.who}`);case`message.read`:return`${String(e.ids.length)} messages`;case`decision.withdrawn`:case`slot.taken`:case`node.held`:case`node.released`:case`node.skipped`:case`owner.unanswered`:return``;default:return``}},JI=new WeakMap,YI=e=>{let t=JI.get(e);if(t!==void 0)return t;let n=JSON.stringify(e.event).toLowerCase();return JI.set(e,n),n},XI=e=>/^(.+)\.\d+$/u.exec(e)?.[1],ZI=(e,t)=>e!==void 0&&(e===t||XI(e)===t),QI=(e,{node:t,type:n,text:r})=>{let i=r.trim().toLowerCase();return t===null&&n===null&&i===``?e:e.filter(e=>(t===null||ZI(RI(e.event),t))&&(n===null||e.event.type===n)&&(i===``||YI(e).includes(i)))},$I=e=>[...new Set(e)].toSorted((e,t)=>e.localeCompare(t,void 0,{numeric:!0})),eL=(e,t)=>({value:e,label:t.some(t=>XI(t)===e)?`${e} and its items`:e}),tL=(e,t)=>$I([...e.flatMap(({event:e})=>RI(e)??[]),...t===null?[]:[t]]),nL=e=>$I(e.map(({event:e})=>e.type)),rL=(e,t,n)=>`${e===t?`${String(e)} events`:`${String(e)} of ${String(t)} loaded`}${n>t?`, ${String(n)} in the run`:``}`,iL=(e,t)=>`ork logs ${e}${t===null?``:` --node ${t}`} --follow`,aL=e=>new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1}),oL=32,sL=({kind:e,from:t},n)=>e===`you`?`You`:e===`node`?n:t??``,cL=(0,U.memo)(({item:e,node:t})=>e.kind===`activity`?(0,q.jsxs)(`li`,{className:II.activity,children:[(0,q.jsx)(`span`,{className:II.activityText,children:e.text}),(0,q.jsx)(`span`,{className:II.time,children:aL(e.at)})]}):(0,q.jsxs)(`li`,{className:II.message,"data-kind":e.kind,children:[(0,q.jsxs)(`p`,{className:II.meta,children:[(0,q.jsx)(`span`,{className:II.speaker,children:sL(e,t)}),(0,q.jsx)(`span`,{className:II.time,children:aL(e.at)}),e.note===void 0?null:(0,q.jsx)(`span`,{className:II.note,children:e.note})]}),(0,q.jsx)(`p`,{className:II.text,children:e.text})]}));cL.displayName=`ThreadRow`;var lL=({items:e,node:t})=>{let n=(0,U.useRef)(null),r=(0,U.useRef)(!0);return(0,U.useLayoutEffect)(()=>{let e=n.current;e!==null&&r.current&&(e.scrollTop=e.scrollHeight)}),(0,U.useEffect)(()=>{let e=n.current,t=new ResizeObserver(()=>{e!==null&&r.current&&(e.scrollTop=e.scrollHeight)});return e!==null&&t.observe(e),()=>{t.disconnect()}},[]),(0,q.jsx)(`div`,{"aria-label":`Conversation with ${t}`,className:II.thread,onScroll:e=>{let{scrollHeight:t,scrollTop:n,clientHeight:i}=e.currentTarget;r.current=t-n-i<oL},ref:n,role:`log`,tabIndex:0,children:(0,q.jsx)(`ol`,{className:II.items,children:e.map(e=>(0,q.jsx)(cL,{item:e,node:t},e.seq))})})},uL=({run:e,selected:t})=>{let n=ob(),r=(0,U.useMemo)(()=>n.feedOf(e.id),[n,e.id]);(0,U.useEffect)(()=>n.retainRun(e.id),[n,e.id]);let{events:i,tail:a,following:o,link:s}=vb(r.state),c=o?i:a,l=(0,U.useMemo)(()=>EI(i),[i]),u=t!==null&&l.includes(t)?t:l[0]??null,d=(0,U.useMemo)(()=>u===null?[]:NI(c,u),[c,u]);return u===null?(0,q.jsx)(qD,{title:s===`loading`&&i.length===0?`Reading the run…`:`This run has no one to talk to.`,children:`Only leaders and workers have sessions.`}):(0,q.jsxs)(`div`,{className:II.panel,children:[(0,q.jsx)(`div`,{className:II.tools,children:(0,q.jsx)(aC,{empty:`No node matches.`,label:`Node`,onChange:n.selectNode,options:l.map(e=>({value:e,label:e})),value:u})}),(0,q.jsx)(`div`,{className:II.main,children:d.length===0?(0,q.jsx)(qD,{title:`Nothing from ${u} yet.`,children:`What it says and what you write show here.`}):(0,q.jsx)(lL,{items:d,node:u},u)}),(0,q.jsx)(LI,{node:u,run:e},`${e.id}/${u}`)]})},dL=()=>{let e=ob(),{run:t,node:n}=vb(e.selection),r=vb(e.runs)?.find(({id:e})=>e===t);return r===void 0?(0,q.jsx)(qD,{cli:`ork chat <run> <node>`,title:`No run chosen.`,children:`Choose one in the Runs panel, or in a terminal:`}):(0,q.jsx)(uL,{run:r,selected:n},r.id)},fL=(0,U.createContext)(null),pL=({id:e,label:t})=>t??e,mL=({id:e,runId:t},n,r=``)=>{let i=r.trim()===``?``:` --say ${jk(r.trim())}`;return`ork decide ${t} --id ${e} --choose ${n?.id??`<option>`}${i}`},hL={terminal:`in the run's terminal`,decide:"with `ork decide`",ui:"in `ork ui`",owner:`by its owner`},gL=({status:e,options:t,answer:n,answeredBy:r,owner:i})=>{if(e===`withdrawn`)return`Withdrawn: it no longer needs an answer.`;if(e===`open`)return`Its run ended before it was answered.`;let a=t.find(({id:e})=>e===n),o=a===void 0?n??``:pL(a);if(r===`owner`&&i!==void 0)return`Answered ${o} by \`${i}\`, its owner.`;let s=i===void 0?``:`, after \`${i}\` passed it on`;return r===void 0?`Answered ${o}${s}.`:`Answered ${o} ${hL[r]}${s}.`},_L=({note:e})=>e===void 0?void 0:`They said: ${e}`,vL=(e,t)=>/^[1-9]$/u.test(t)?e[Number(t)-1]:void 0,yL=e=>(t,n)=>`${n===1?`Copy code`:`Copy code block ${t} of ${n}`} (${e})`,bL=({runId:e,id:t})=>`ork decide ${e} --id ${t} --document`,xL=e=>e.startsWith(`{
95
- `),SL={value:` all`,label:``},CL=(e,t,n,r)=>{let i=new Map;for(let n of e){let e=t(n);e!==void 0&&i.set(e,(i.get(e)??0)+1)}let a=[...i];return(r?a.toSorted(([e],[t])=>e.localeCompare(t)):a).map(([e,t])=>({value:e,label:n(e,t)}))},wL=(e,{workflow:t,run:n},r)=>({...e.some(({runId:e})=>r(e)===t)&&t!==void 0?{workflow:t}:{},...e.some(({runId:e})=>e===n)&&n!==void 0?{run:n}:{}}),TL=(e,t)=>t===void 0||e.some(({value:e})=>e===t)?e:[...e,{value:t,label:`${t} (0)`}],EL=(e,{workflow:t,run:n},r)=>{let i=e.filter(({runId:e})=>t===void 0||r(e)===t);return{workflows:[{...SL,label:`All (${e.length})`},...TL(CL(e,({runId:e})=>r(e),(e,t)=>`${e} (${t})`,!0),t)],runs:[{...SL,label:`All (${i.length})`},...TL(CL(i,({runId:e})=>e,(e,t)=>{let n=r(e);return`${e}${n===void 0?``:` · ${n}`} (${t})`},!1),n)],shown:i.filter(({runId:e})=>n===void 0||e===n),active:{...t===void 0?{}:{workflow:t},...n===void 0?{}:{run:n}}}},DL=(e,t)=>t===e?e===1?`1 open decision.`:`${e} open decisions.`:`${t} of ${e} open decisions shown; ${e-t} hidden by the filter.`,OL=({workflow:e,run:t})=>e!==void 0||t!==void 0,kL=({workflow:e,run:t})=>t===void 0?`ork decide --list${e===void 0?``:` --workflow ${e}`}`:`ork decide ${t} --list`,AL={panel:`_panel_1qd3f_6`,list:`_list_1qd3f_22`,card:`_card_1qd3f_27`,fromText:`_fromText_1qd3f_43`,from:`_from_1qd3f_43`,read:`_read_1qd3f_69`,length:`_length_1qd3f_79`,document:`_document_1qd3f_90`,filter:`_filter_1qd3f_120`,filterFields:`_filterFields_1qd3f_134`,counts:`_counts_1qd3f_145`,options:`_options_1qd3f_154`,option:`_option_1qd3f_154`,optionMark:`_optionMark_1qd3f_217`,optionCommand:`_optionCommand_1qd3f_227`,unreachable:`_unreachable_1qd3f_239`,optionText:`_optionText_1qd3f_264`,optionLabel:`_optionLabel_1qd3f_288`,optionDescription:`_optionDescription_1qd3f_295`,refusal:`_refusal_1qd3f_304`,settled:`_settled_1qd3f_312`,settledTitle:`_settledTitle_1qd3f_322`,settledList:`_settledList_1qd3f_339`,settledQuestion:`_settledQuestion_1qd3f_360`,settledEnding:`_settledEnding_1qd3f_364`,settledNote:`_settledNote_1qd3f_374`},jL="Cannot answer here: `ork ui` is not reachable.",ML=`Cannot answer here: ork ui is not reachable`,NL=({decision:e,note:t,onNote:n,sending:r,unreachable:i,onChoose:a})=>(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(pk,{description:`It goes with the option you choose; a gate passes it on as its note.`,label:`Note for the run (optional)`,multiline:!0,onChange:n,rows:2,value:t}),t.trim()===``?null:(0,q.jsx)(cC,{command:mL(e,void 0,t)}),(0,q.jsx)(`ul`,{className:AL.options,children:e.options.map((n,o)=>{let s=n.id===e.recommended,c=mL(e,n,t),l=o<9?String(o+1):void 0;return(0,q.jsx)(`li`,{children:(0,q.jsx)(u_,{cli:c,label:i?jL:void 0,children:(0,q.jsxs)(`button`,{...l_(c,i?ML:void 0),"aria-disabled":r||i?`true`:void 0,"aria-keyshortcuts":l,className:AL.option,"data-option":``,"data-recommended":s?``:void 0,"data-unreachable":i?``:void 0,onClick:()=>{a(n)},type:`button`,children:[l===void 0?null:(0,q.jsx)(a_,{keys:[l]}),(0,q.jsxs)(`span`,{className:AL.optionText,children:[(0,q.jsx)(`span`,{className:AL.optionLabel,children:pL(n)}),n.description===void 0?null:(0,q.jsx)(`span`,{className:AL.optionDescription,children:n.description}),i?(0,q.jsx)(`code`,{className:AL.optionCommand,children:c}):null]}),s?(0,q.jsx)(`span`,{className:AL.optionMark,children:`recommended`}):null]})})},n.id)})})]}),PL={};function FL(e,t){let n=t||PL;return IL(e,typeof n.includeImageAlt!=`boolean`||n.includeImageAlt,typeof n.includeHtml!=`boolean`||n.includeHtml)}function IL(e,t,n){if(RL(e)){if(`value`in e)return e.type===`html`&&!n?``:e.value;if(t&&`alt`in e&&e.alt)return e.alt;if(`children`in e)return LL(e.children,t,n)}return Array.isArray(e)?LL(e,t,n):``}function LL(e,t,n){let r=[],i=-1;for(;++i<e.length;)r[i]=IL(e[i],t,n);return r.join(``)}function RL(e){return!!(e&&typeof e==`object`)}var zL=document.createElement(`i`);function BL(e){let t=`&`+e+`;`;zL.innerHTML=t;let n=zL.textContent;return n.charCodeAt(n.length-1)===59&&e!==`semi`?!1:n!==t&&n}function VL(e,t,n,r){let i=e.length,a=0,o;if(t=t<0?-t>i?0:i+t:t>i?i:t,n=n>0?n:0,r.length<1e4)o=Array.from(r),o.unshift(t,n),e.splice(...o);else for(n&&e.splice(t,n);a<r.length;)o=r.slice(a,a+1e4),o.unshift(t,0),e.splice(...o),a+=1e4,t+=1e4}function HL(e,t){return e.length>0?(VL(e,e.length,0,t),e):t}var UL={}.hasOwnProperty;function WL(e){let t={},n=-1;for(;++n<e.length;)GL(t,e[n]);return t}function GL(e,t){let n;for(n in t){let r=(UL.call(e,n)?e[n]:void 0)||(e[n]={}),i=t[n],a;if(i)for(a in i){UL.call(r,a)||(r[a]=[]);let e=i[a];KL(r[a],Array.isArray(e)?e:e?[e]:[])}}}function KL(e,t){let n=-1,r=[];for(;++n<t.length;)(t[n].add===`after`?e:r).push(t[n]);VL(e,0,0,r)}function qL(e,t){let n=Number.parseInt(e,t);return n<9||n===11||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)==65535||(n&65535)==65534||n>1114111?`�`:String.fromCodePoint(n)}function JL(e){return e.replace(/[\t\n\r ]+/g,` `).replace(/^ | $/g,``).toLowerCase().toUpperCase()}var YL=sR(/[A-Za-z]/),XL=sR(/[\dA-Za-z]/),ZL=sR(/[#-'*+\--9=?A-Z^-~]/);function QL(e){return e!==null&&(e<32||e===127)}var $L=sR(/\d/),eR=sR(/[\dA-Fa-f]/),tR=sR(/[!-/:-@[-`{-~]/);function nR(e){return e!==null&&e<-2}function rR(e){return e!==null&&(e<0||e===32)}function iR(e){return e===-2||e===-1||e===32}var aR=sR(/\p{P}|\p{S}/u),oR=sR(/\s/);function sR(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}function cR(e,t,n,r){let i=r?r-1:1/0,a=0;return o;function o(r){return iR(r)?(e.enter(n),s(r)):t(r)}function s(r){return iR(r)&&a++<i?(e.consume(r),s):(e.exit(n),t(r))}}function lR(e,t,n,r,i,a){let o=0;return s;function s(t){return a>0&&iR(t)?(e.enter(r),c(t)):l(t)}function c(t){return iR(t)&&o<a?(e.consume(t),o++,c):(e.exit(r),l(t))}function l(e){return o>=i?t(e):n(e)}}var uR={tokenize:dR};function dR(e){let t=e.attempt(this.parser.constructs.contentInitial,r,i),n;return t;function r(n){if(n===null)e.consume(n);else return e.enter(`lineEnding`),e.consume(n),e.exit(`lineEnding`),cR(e,t,`linePrefix`)}function i(t){return e.enter(`paragraph`),a(t)}function a(t){let r=e.enter(`chunkText`,{contentType:`text`,previous:n});return n&&(n.next=r),n=r,o(t)}function o(t){if(t===null)e.exit(`chunkText`),e.exit(`paragraph`),e.consume(t);else return nR(t)?(e.consume(t),e.exit(`chunkText`),a):(e.consume(t),o)}}var fR=class{constructor(){this.index=new Map,this.map=[]}add(e,t,n){pR(this,e,t,n,!1)}addBefore(e,t,n){pR(this,e,t,n,!0)}consume(e){if(this.map.sort(function(e,t){return e[0]-t[0]}),this.map.length===0)return;let t=this.map.length,n=[];for(;t>0;)--t,n.push(e.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),e.length=this.map[t][0];n.push(e.slice()),e.length=0;let r=n.pop();for(;r;){for(let t of r)e.push(t);r=n.pop()}this.map.length=0,this.index.clear()}};function pR(e,t,n,r,i){if(n===0&&r.length===0)return;let a=e.index.get(t);if(a){a[1]+=n,i?(r.push(...a[2]),a[2]=r):a[2].push(...r);return}let o=[t,n,r];e.map.push(o),e.index.set(t,o)}var mR={tokenize:gR},hR={tokenize:_R};function gR(e){let t=this,n=[],r=0,i,a,o;return s;function s(i){if(r<n.length){let a=n[r];return t.containerState=a[1],e.attempt(a[0].continuation,c,l)(i)}return l(i)}function c(e){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,i&&v();let n=t.events.length,a=n,o;for(;a--;)if(t.events[a][0]===`exit`&&t.events[a][1].type===`chunkFlow`){o=t.events[a][1].end;break}_(r);let s=n;for(;s<t.events.length;)t.events[s][1].end={...o},s++;let c=new fR;return c.add(a+1,0,t.events.slice(n)),c.add(n,s-n,[]),c.consume(t.events),l(e)}return s(e)}function l(a){if(r===n.length){if(!i)return f(a);if(i.currentConstruct&&i.currentConstruct.concrete)return m(a);t.interrupt=!(!i.currentConstruct||i._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(hR,u,d)(a)}function u(e){return i&&v(),_(r),f(e)}function d(e){return t.parser.lazy[t.now().line]=r!==n.length,o=t.now().offset,m(e)}function f(n){return t.containerState={},e.attempt(hR,p,m)(n)}function p(e){return r++,n.push([t.currentConstruct,t.containerState]),f(e)}function m(n){if(n===null)i&&v(),_(0),e.consume(n);else return i||=t.parser.flow(t.now()),e.enter(`chunkFlow`,{_tokenizer:i,contentType:`flow`,previous:a}),h(n)}function h(n){if(n===null)g(e.exit(`chunkFlow`),!0),_(0),e.consume(n);else return nR(n)?(e.consume(n),g(e.exit(`chunkFlow`)),r=0,t.interrupt=void 0,s):(e.consume(n),h)}function g(e,n){let s=t.sliceStream(e);if(n&&s.push(null),e.previous=a,a&&(a.next=e),a=e,i.defineSkip(e.start),i.write(s),t.parser.lazy[e.start.line]){let e=i.events.length;for(;e--;)if(i.events[e][1].start.offset<o&&(!i.events[e][1].end||i.events[e][1].end.offset>o))return;let n=t.events.length,a=n,s,c;for(;a--;)if(t.events[a][0]===`exit`&&t.events[a][1].type===`chunkFlow`){if(s){c=t.events[a][1].end;break}s=!0}for(_(r),e=n;e<t.events.length;)t.events[e][1].end={...c},e++;let l=new fR;l.add(a+1,0,t.events.slice(n)),l.add(n,e-n,[]),l.consume(t.events)}}function _(r){let i=n.length;for(;i-->r;){let r=n[i];t.containerState=r[1],r[0].exit.call(t,e)}n.length=r}function v(){i.write([null]),a=void 0,i=void 0,t.containerState._closeFlow=void 0}}function _R(e,t,n){return cR(e,e.attempt(this.parser.constructs.document,t,n),`linePrefix`,this.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)}function vR(e){if(e===null||rR(e)||oR(e))return 1;if(aR(e))return 2}function yR(e,t,n){let r=[],i=-1;for(;++i<e.length;){let a=e[i].resolveAll;a&&!r.includes(a)&&(t=a(t,n),r.push(a))}return t}var bR={name:`attention`,resolveAll:xR,tokenize:SR};function xR(e,t){let n=-1,r;for(;++n<e.length;)if(e[n][0]===`enter`&&e[n][1].type===`attentionSequence`&&e[n][1]._close){let i=n;for(;i--;)if(e[i][0]===`exit`&&e[i][1].type===`attentionSequence`&&e[i][1]._open&&t.sliceSerialize(e[i][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[i][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[i][1].end.offset-e[i][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;let a=e[i][1].end.offset-e[i][1].start.offset>1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1,o={...e[i][1].end},s={...e[n][1].start};CR(o,-a),CR(s,a);let c={type:a>1?`strongSequence`:`emphasisSequence`,start:o,end:{...e[i][1].end}},l={type:a>1?`strongSequence`:`emphasisSequence`,start:{...e[n][1].start},end:s},u={type:a>1?`strongText`:`emphasisText`,start:{...e[i][1].end},end:{...e[n][1].start}},d={type:a>1?`strong`:`emphasis`,start:{...c.start},end:{...l.end}};e[i][1].end={...c.start},e[n][1].start={...l.end},r=[],e[i][1].end.offset-e[i][1].start.offset&&(r=HL(r,[[`enter`,e[i][1],t],[`exit`,e[i][1],t]])),r=HL(r,[[`enter`,d,t],[`enter`,c,t],[`exit`,c,t],[`enter`,u,t]]),r=HL(r,yR(t.parser.constructs.insideSpan.null,e.slice(i+1,n),t)),r=HL(r,[[`exit`,u,t],[`enter`,l,t],[`exit`,l,t],[`exit`,d,t]]);let f=0;e[n][1].end.offset-e[n][1].start.offset&&(f=2,r=HL(r,[[`enter`,e[n][1],t],[`exit`,e[n][1],t]])),VL(e,i-1,n-i+3,r),n=i+r.length-f-2;break}}for(n=-1;++n<e.length;)e[n][1].type===`attentionSequence`&&(e[n][1].type=`data`);return e}function SR(e,t){let n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=vR(r),a;return o;function o(t){return a=t,e.enter(`attentionSequence`),s(t)}function s(o){if(o===a)return e.consume(o),s;let c=e.exit(`attentionSequence`),l=vR(o),u=!l||l===2&&i||n.includes(o)&&o!==42&&o!==95,d=!i||i===2&&l||n.includes(r)&&r!==42&&r!==95;return c._open=!!(a===42?u:u&&(i||!d)),c._close=!!(a===42?d:d&&(l||!u)),t(o)}}function CR(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}var wR={name:`autolink`,tokenize:TR};function TR(e,t,n){let r=0;return i;function i(t){return e.enter(`autolink`),e.enter(`autolinkMarker`),e.consume(t),e.exit(`autolinkMarker`),e.enter(`autolinkProtocol`),a}function a(t){return YL(t)?(e.consume(t),o):t===64?n(t):l(t)}function o(e){return e===43||e===45||e===46||XL(e)?(r=1,s(e)):l(e)}function s(t){return t===58?(e.consume(t),r=0,c):(t===43||t===45||t===46||XL(t))&&r++<32?(e.consume(t),s):(r=0,l(t))}function c(r){return r===62?(e.exit(`autolinkProtocol`),e.enter(`autolinkMarker`),e.consume(r),e.exit(`autolinkMarker`),e.exit(`autolink`),t):r===null||r===32||r===60||QL(r)?n(r):(e.consume(r),c)}function l(t){return t===64?(e.consume(t),u):ZL(t)?(e.consume(t),l):n(t)}function u(e){return XL(e)?d(e):n(e)}function d(n){return n===46?(e.consume(n),r=0,u):n===62?(e.exit(`autolinkProtocol`).type=`autolinkEmail`,e.enter(`autolinkMarker`),e.consume(n),e.exit(`autolinkMarker`),e.exit(`autolink`),t):f(n)}function f(t){if((t===45||XL(t))&&r++<63){let n=t===45?f:d;return e.consume(t),n}return n(t)}}var ER={partial:!0,tokenize:DR};function DR(e,t,n){return r;function r(t){return iR(t)?cR(e,i,`linePrefix`)(t):i(t)}function i(e){return e===null||nR(e)?t(e):n(e)}}var OR={continuation:{tokenize:AR},exit:jR,name:`blockQuote`,tokenize:kR};function kR(e,t,n){let r=this;return i;function i(t){if(t===62){let n=r.containerState;return n.open||=(e.enter(`blockQuote`,{_container:!0}),!0),e.enter(`blockQuotePrefix`),e.enter(`blockQuoteMarker`),e.consume(t),e.exit(`blockQuoteMarker`),a}return n(t)}function a(n){return iR(n)?(e.enter(`blockQuotePrefixWhitespace`),e.consume(n),e.exit(`blockQuotePrefixWhitespace`),e.exit(`blockQuotePrefix`),t):(e.exit(`blockQuotePrefix`),t(n))}}function AR(e,t,n){let r=this;return i;function i(t){return iR(t)?cR(e,a,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):a(t)}function a(r){return e.attempt(OR,t,n)(r)}}function jR(e){e.exit(`blockQuote`)}var MR={name:`characterEscape`,tokenize:NR};function NR(e,t,n){return r;function r(t){return e.enter(`characterEscape`),e.enter(`escapeMarker`),e.consume(t),e.exit(`escapeMarker`),i}function i(r){return tR(r)?(e.enter(`characterEscapeValue`),e.consume(r),e.exit(`characterEscapeValue`),e.exit(`characterEscape`),t):n(r)}}var PR={name:`characterReference`,tokenize:FR};function FR(e,t,n){let r=this,i=0,a,o;return s;function s(t){return e.enter(`characterReference`),e.enter(`characterReferenceMarker`),e.consume(t),e.exit(`characterReferenceMarker`),c}function c(t){return t===35?(e.enter(`characterReferenceMarkerNumeric`),e.consume(t),e.exit(`characterReferenceMarkerNumeric`),l):(e.enter(`characterReferenceValue`),a=31,o=XL,u(t))}function l(t){return t===88||t===120?(e.enter(`characterReferenceMarkerHexadecimal`),e.consume(t),e.exit(`characterReferenceMarkerHexadecimal`),e.enter(`characterReferenceValue`),a=6,o=eR,u):(e.enter(`characterReferenceValue`),a=7,o=$L,u(t))}function u(s){if(s===59&&i){let i=e.exit(`characterReferenceValue`);return o===XL&&!BL(r.sliceSerialize(i))?n(s):(e.enter(`characterReferenceMarker`),e.consume(s),e.exit(`characterReferenceMarker`),e.exit(`characterReference`),t)}return o(s)&&i++<a?(e.consume(s),u):n(s)}}var IR={partial:!0,tokenize:LR};function LR(e,t,n){let r=this;return i;function i(t){return t===null?n(t):(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),a)}function a(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}var RR={concrete:!0,name:`codeFenced`,tokenize:zR};function zR(e,t,n){let r=this,i={partial:!0,tokenize:x},a=0,o=0,s;return c;function c(e){return l(e)}function l(t){let n=r.events[r.events.length-1];return a=n&&n[1].type===`linePrefix`?n[2].sliceSerialize(n[1],!0).length:0,s=t,e.enter(`codeFenced`),e.enter(`codeFencedFence`),e.enter(`codeFencedFenceSequence`),u(t)}function u(t){return t===s?(o++,e.consume(t),u):o<3?n(t):(e.exit(`codeFencedFenceSequence`),iR(t)?cR(e,d,`whitespace`)(t):d(t))}function d(n){return n===null||nR(n)?(e.exit(`codeFencedFence`),r.interrupt?t(n):e.check(IR,h,b)(n)):(e.enter(`codeFencedFenceInfo`),e.enter(`chunkString`,{contentType:`string`}),f(n))}function f(t){return t===null||nR(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceInfo`),d(t)):iR(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceInfo`),cR(e,p,`whitespace`)(t)):t===96&&t===s?n(t):(e.consume(t),f)}function p(t){return t===null||nR(t)?d(t):(e.enter(`codeFencedFenceMeta`),e.enter(`chunkString`,{contentType:`string`}),m(t))}function m(t){return t===null||nR(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceMeta`),d(t)):t===96&&t===s?n(t):(e.consume(t),m)}function h(t){return e.attempt(i,b,g)(t)}function g(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),_}function _(t){return a>0&&iR(t)?cR(e,v,`linePrefix`,a+1)(t):v(t)}function v(t){return t===null||nR(t)?e.check(IR,h,b)(t):(e.enter(`codeFlowValue`),y(t))}function y(t){return t===null||nR(t)?(e.exit(`codeFlowValue`),v(t)):(e.consume(t),y)}function b(n){return e.exit(`codeFenced`),t(n)}function x(e,t,n){let i=0;return a;function a(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),c}function c(t){return e.enter(`codeFencedFence`),iR(t)?cR(e,l,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):l(t)}function l(t){return t===s?(e.enter(`codeFencedFenceSequence`),u(t)):n(t)}function u(t){return t===s?(i++,e.consume(t),u):i>=o?(e.exit(`codeFencedFenceSequence`),iR(t)?cR(e,d,`whitespace`)(t):d(t)):n(t)}function d(r){return r===null||nR(r)?(e.exit(`codeFencedFence`),t(r)):n(r)}}}var BR={name:`codeIndented`,tokenize:HR},VR={partial:!0,tokenize:UR};function HR(e,t,n){return r;function r(t){return e.enter(`codeIndented`),lR(e,i,n,`linePrefix`,4,4)(t)}function i(t){return t===null?o(t):nR(t)?e.attempt(VR,i,o)(t):(e.enter(`codeFlowValue`),a(t))}function a(t){return t===null||nR(t)?(e.exit(`codeFlowValue`),i(t)):(e.consume(t),a)}function o(n){return e.exit(`codeIndented`),t(n)}}function UR(e,t,n){let r=this;return i;function i(o){return r.parser.lazy[r.now().line]?n(o):nR(o)?(e.enter(`lineEnding`),e.consume(o),e.exit(`lineEnding`),i):lR(e,t,a,`linePrefix`,4,4)(o)}function a(e){return nR(e)?i(e):n(e)}}var WR={name:`codeText`,previous:KR,resolve:GR,tokenize:qR};function GR(e){let t=e.length-4,n=3,r,i;if((e[n][1].type===`lineEnding`||e[n][1].type===`space`)&&(e[t][1].type===`lineEnding`||e[t][1].type===`space`)){for(r=n;++r<t;)if(e[r][1].type===`codeTextData`){e[n][1].type=`codeTextPadding`,e[t][1].type=`codeTextPadding`,n+=2,t-=2;break}}for(r=n-1,t++;++r<=t;)i===void 0?r!==t&&e[r][1].type!==`lineEnding`&&(i=r):(r===t||e[r][1].type===`lineEnding`)&&(e[i][1].type=`codeTextData`,r!==i+2&&(e[i][1].end=e[r-1][1].end,e.splice(i+2,r-i-2),t-=r-i-2,r=i+2),i=void 0);return e}function KR(e){return e!==96||this.events[this.events.length-1][1].type===`characterEscape`}function qR(e,t,n){let r=0,i,a;return o;function o(t){return e.enter(`codeText`),e.enter(`codeTextSequence`),s(t)}function s(t){return t===96?(e.consume(t),r++,s):(e.exit(`codeTextSequence`),c(t))}function c(t){return t===null?n(t):t===32?(e.enter(`space`),e.consume(t),e.exit(`space`),c):t===96?(a=e.enter(`codeTextSequence`),i=0,u(t)):nR(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),c):(e.enter(`codeTextData`),l(t))}function l(t){return t===null||t===32||t===96||nR(t)?(e.exit(`codeTextData`),c(t)):(e.consume(t),l)}function u(n){return n===96?(e.consume(n),i++,u):i===r?(e.exit(`codeTextSequence`),e.exit(`codeText`),t(n)):(a.type=`codeTextData`,l(n))}}var JR=class{constructor(e){this.left=e?[...e]:[],this.right=[]}get(e){if(e<0||e>=this.left.length+this.right.length)throw RangeError("Cannot access index `"+e+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return e<this.left.length?this.left[e]:this.right[this.right.length-e+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(e,t){let n=t??1/0;return n<this.left.length?this.left.slice(e,n):e>this.left.length?this.right.slice(this.right.length-n+this.left.length,this.right.length-e+this.left.length).reverse():this.left.slice(e).concat(this.right.slice(this.right.length-n+this.left.length).reverse())}splice(e,t,n){let r=t||0;this.setCursor(Math.trunc(e));let i=this.right.splice(this.right.length-r,1/0);return n&&YR(this.left,n),i.reverse()}pop(){return this.setCursor(1/0),this.left.pop()}push(e){this.setCursor(1/0),this.left.push(e)}pushMany(e){this.setCursor(1/0),YR(this.left,e)}unshift(e){this.setCursor(0),this.right.push(e)}unshiftMany(e){this.setCursor(0),YR(this.right,e.reverse())}setCursor(e){if(!(e===this.left.length||e>this.left.length&&this.right.length===0||e<0&&this.left.length===0)){if(e<this.left.length){let t=this.left.splice(e,1/0);YR(this.right,t.reverse())}else{let t=this.right.splice(this.left.length+this.right.length-e,1/0);YR(this.left,t.reverse())}}}};function YR(e,t){let n=0;if(t.length<1e4)e.push(...t);else for(;n<t.length;)e.push(...t.slice(n,n+1e4)),n+=1e4}function XR(e){let t={},n=-1,r,i,a,o,s,c,l,u=new JR(e);for(;++n<u.length;){for(;n in t;)n=t[n];if(r=u.get(n),n&&r[1].type===`chunkFlow`&&u.get(n-1)[1].type===`listItemPrefix`&&(c=r[1]._tokenizer.events,a=0,a<c.length&&c[a][1].type===`lineEndingBlank`&&(a+=2),a<c.length&&c[a][1].type===`content`))for(;++a<c.length&&c[a][1].type!==`content`;)c[a][1].type===`chunkText`&&(c[a][1]._isInFirstContentOfListItem=!0,a++);if(r[0]===`enter`)r[1].contentType&&(Object.assign(t,ZR(u,n)),n=t[n],l=!0);else if(r[1]._container){for(a=n,i=void 0;a--;)if(o=u.get(a),o[1].type===`lineEnding`||o[1].type===`lineEndingBlank`)o[0]===`enter`&&(i&&(u.get(i)[1].type=`lineEndingBlank`),o[1].type=`lineEnding`,i=a);else if(o[1].type!==`linePrefix`&&o[1].type!==`listItemIndent`)break;i&&(r[1].end={...u.get(i)[1].start},s=u.slice(i,n),s.unshift(r),u.splice(i,n-i+1,s))}}return VL(e,0,1/0,u.slice(0)),!l}function ZR(e,t){let n=e.get(t)[1],r=e.get(t)[2],i=t-1,a=[],o=n._tokenizer;o||(o=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(o._contentTypeTextTrailing=!0));let s=o.events,c=[],l={},u,d,f=-1,p=n,m=0,h=0,g=[h];for(;p;){for(;e.get(++i)[1]!==p;);a.push(i),p._tokenizer||(u=r.sliceStream(p),p.next||u.push(null),d&&o.defineSkip(p.start),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=!0),o.write(u),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=void 0)),d=p,p=p.next}for(p=n;++f<s.length;)s[f][0]===`exit`&&s[f-1][0]===`enter`&&s[f][1].type===s[f-1][1].type&&s[f][1].start.line!==s[f][1].end.line&&(h=f+1,g.push(h),p._tokenizer=void 0,p.previous=void 0,p=p.next);for(o.events=[],p?(p._tokenizer=void 0,p.previous=void 0):g.pop(),f=g.length;f--;){let t=s.slice(g[f],g[f+1]),n=a.pop();c.push([n,n+t.length-1]),e.splice(n,2,t)}for(c.reverse(),f=-1;++f<c.length;)l[m+c[f][0]]=m+c[f][1],m+=c[f][1]-c[f][0]-1;return l}var QR={resolve:ez,tokenize:tz},$R={partial:!0,tokenize:nz};function ez(e){return XR(e),e}function tz(e,t){let n;return r;function r(t){return e.enter(`content`),n=e.enter(`chunkContent`,{contentType:`content`}),i(t)}function i(t){return t===null?a(t):nR(t)?e.check($R,o,a)(t):(e.consume(t),i)}function a(n){return e.exit(`chunkContent`),e.exit(`content`),t(n)}function o(t){return e.consume(t),e.exit(`chunkContent`),n.next=e.enter(`chunkContent`,{contentType:`content`,previous:n}),n=n.next,i}}function nz(e,t,n){let r=this;return i;function i(t){return e.exit(`chunkContent`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),cR(e,a,`linePrefix`)}function a(i){if(i===null||nR(i))return n(i);let a=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes(`codeIndented`)&&a&&a[1].type===`linePrefix`&&a[2].sliceSerialize(a[1],!0).length>=4?t(i):e.interrupt(r.parser.constructs.flow,n,t)(i)}}function rz(e,t,n,r,i,a,o,s,c){let l=c||1/0,u=0;return d;function d(t){return t===60?(e.enter(r),e.enter(i),e.enter(a),e.consume(t),e.exit(a),f):t===null||t===32||t===41||QL(t)?n(t):(e.enter(r),e.enter(o),e.enter(s),e.enter(`chunkString`,{contentType:`string`}),h(t))}function f(n){return n===62?(e.enter(a),e.consume(n),e.exit(a),e.exit(i),e.exit(r),t):(e.enter(s),e.enter(`chunkString`,{contentType:`string`}),p(n))}function p(t){return t===62?(e.exit(`chunkString`),e.exit(s),f(t)):t===null||t===60||nR(t)?n(t):(e.consume(t),t===92?m:p)}function m(t){return t===60||t===62||t===92?(e.consume(t),p):p(t)}function h(i){return!u&&(i===null||i===41||rR(i))?(e.exit(`chunkString`),e.exit(s),e.exit(o),e.exit(r),t(i)):u<l&&i===40?(e.consume(i),u++,h):i===41?(e.consume(i),u--,h):i===null||i===32||i===40||QL(i)?n(i):(e.consume(i),i===92?g:h)}function g(t){return t===40||t===41||t===92?(e.consume(t),h):h(t)}}function iz(e,t,n,r,i,a){let o=this,s=0,c;return l;function l(t){return e.enter(r),e.enter(i),e.consume(t),e.exit(i),e.enter(a),u}function u(l){return s>999||l===null||l===91||l===93&&!c||l===94&&!s&&`_hiddenFootnoteSupport`in o.parser.constructs?n(l):l===93?(e.exit(a),e.enter(i),e.consume(l),e.exit(i),e.exit(r),t):nR(l)?(e.enter(`lineEnding`),e.consume(l),e.exit(`lineEnding`),u):(e.enter(`chunkString`,{contentType:`string`}),d(l))}function d(t){return t===null||t===91||t===93||nR(t)||s++>999?(e.exit(`chunkString`),u(t)):(e.consume(t),c||=!iR(t),t===92?f:d)}function f(t){return t===91||t===92||t===93?(e.consume(t),s++,d):d(t)}}function az(e,t,n,r,i,a){let o;return s;function s(t){return t===34||t===39||t===40?(e.enter(r),e.enter(i),e.consume(t),e.exit(i),o=t===40?41:t,c):n(t)}function c(n){return n===o?(e.enter(i),e.consume(n),e.exit(i),e.exit(r),t):(e.enter(a),l(n))}function l(t){return t===o?(e.exit(a),c(o)):t===null?n(t):nR(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),cR(e,l,`linePrefix`)):(e.enter(`chunkString`,{contentType:`string`}),u(t))}function u(t){return t===o||t===null||nR(t)?(e.exit(`chunkString`),l(t)):(e.consume(t),t===92?d:u)}function d(t){return t===o||t===92?(e.consume(t),u):u(t)}}function oz(e,t){let n;return r;function r(i){return nR(i)?(e.enter(`lineEnding`),e.consume(i),e.exit(`lineEnding`),n=!0,r):iR(i)?cR(e,r,n?`linePrefix`:`lineSuffix`)(i):t(i)}}var sz={name:`definition`,tokenize:lz},cz={partial:!0,tokenize:uz};function lz(e,t,n){let r=this,i;return a;function a(t){return e.enter(`definition`),o(t)}function o(t){return iz.call(r,e,s,n,`definitionLabel`,`definitionLabelMarker`,`definitionLabelString`)(t)}function s(t){return i=JL(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),c):n(t)}function c(t){return rR(t)?oz(e,l)(t):l(t)}function l(t){return rz(e,u,n,`definitionDestination`,`definitionDestinationLiteral`,`definitionDestinationLiteralMarker`,`definitionDestinationRaw`,`definitionDestinationString`)(t)}function u(t){return e.attempt(cz,d,d)(t)}function d(t){return iR(t)?cR(e,f,`whitespace`)(t):f(t)}function f(a){return a===null||nR(a)?(e.exit(`definition`),r.parser.defined.push(i),t(a)):n(a)}}function uz(e,t,n){return r;function r(t){return rR(t)?oz(e,i)(t):n(t)}function i(t){return az(e,a,n,`definitionTitle`,`definitionTitleMarker`,`definitionTitleString`)(t)}function a(t){return iR(t)?cR(e,o,`whitespace`)(t):o(t)}function o(e){return e===null||nR(e)?t(e):n(e)}}var dz={name:`hardBreakEscape`,tokenize:fz};function fz(e,t,n){return r;function r(t){return e.enter(`hardBreakEscape`),e.consume(t),i}function i(r){return nR(r)?(e.exit(`hardBreakEscape`),t(r)):n(r)}}var pz={name:`headingAtx`,resolve:mz,tokenize:hz};function mz(e,t){let n=e.length-2,r=3;if(e[r][1].type===`whitespace`&&(r+=2),n-2>r&&e[n][1].type===`whitespace`&&(n-=2),e[n][1].type===`atxHeadingSequence`&&(r===n-1||n-4>r&&e[n-2][1].type===`whitespace`)&&(n-=r+1===n?2:4),n>r){let i={type:`atxHeadingText`,start:e[r][1].start,end:e[n][1].end},a={type:`chunkText`,start:e[r][1].start,end:e[n][1].end,contentType:`text`};VL(e,r,n-r+1,[[`enter`,i,t],[`enter`,a,t],[`exit`,a,t],[`exit`,i,t]])}return e}function hz(e,t,n){let r=0;return i;function i(t){return e.enter(`atxHeading`),a(t)}function a(t){return e.enter(`atxHeadingSequence`),o(t)}function o(t){return t===35&&r++<6?(e.consume(t),o):t===null||rR(t)?(e.exit(`atxHeadingSequence`),s(t)):n(t)}function s(n){return n===35?(e.enter(`atxHeadingSequence`),c(n)):n===null||nR(n)?(e.exit(`atxHeading`),t(n)):iR(n)?cR(e,s,`whitespace`)(n):(e.enter(`atxHeadingText`),l(n))}function c(t){return t===35?(e.consume(t),c):(e.exit(`atxHeadingSequence`),s(t))}function l(t){return t===null||t===35||rR(t)?(e.exit(`atxHeadingText`),s(t)):(e.consume(t),l)}}var gz=`address.article.aside.base.basefont.blockquote.body.caption.center.col.colgroup.dd.details.dialog.dir.div.dl.dt.fieldset.figcaption.figure.footer.form.frame.frameset.h1.h2.h3.h4.h5.h6.head.header.hr.html.iframe.legend.li.link.main.menu.menuitem.nav.noframes.ol.optgroup.option.p.param.search.section.summary.table.tbody.td.tfoot.th.thead.title.tr.track.ul`.split(`.`),_z=[`pre`,`script`,`style`,`textarea`],vz={concrete:!0,name:`htmlFlow`,resolveTo:bz,tokenize:xz},yz={partial:!0,tokenize:Sz};function bz(e){let t=e.length;for(;t--&&(e[t][0]!==`enter`||e[t][1].type!==`htmlFlow`););return t>1&&e[t-2][1].type===`linePrefix`&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function xz(e,t,n){let r=this,i,a,o,s,c;return l;function l(e){return u(e)}function u(t){return e.enter(`htmlFlow`),e.enter(`htmlFlowData`),e.consume(t),d}function d(s){return s===33?(e.consume(s),f):s===47?(e.consume(s),a=!0,h):s===63?(e.consume(s),i=3,r.interrupt?t:I):YL(s)?(e.consume(s),o=String.fromCharCode(s),g):n(s)}function f(a){return a===45?(e.consume(a),i=2,p):a===91?(e.consume(a),i=5,s=0,m):YL(a)?(e.consume(a),i=4,r.interrupt?t:I):n(a)}function p(i){return i===45?(e.consume(i),r.interrupt?t:I):n(i)}function m(i){return i===`CDATA[`.charCodeAt(s++)?(e.consume(i),s===6?r.interrupt?t:O:m):n(i)}function h(t){return YL(t)?(e.consume(t),o=String.fromCharCode(t),g):n(t)}function g(s){if(s===null||s===47||s===62||rR(s)){let c=s===47,l=o.toLowerCase();return!c&&!a&&_z.includes(l)?(i=1,r.interrupt?t(s):O(s)):gz.includes(o.toLowerCase())?(i=6,c?(e.consume(s),_):r.interrupt?t(s):O(s)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(s):a?v(s):y(s))}return s===45||XL(s)?(e.consume(s),o+=String.fromCharCode(s),g):n(s)}function _(i){return i===62?(e.consume(i),r.interrupt?t:O):n(i)}function v(t){return iR(t)?(e.consume(t),v):E(t)}function y(t){return t===47?(e.consume(t),E):t===58||t===95||YL(t)?(e.consume(t),b):iR(t)?(e.consume(t),y):E(t)}function b(t){return t===45||t===46||t===58||t===95||XL(t)?(e.consume(t),b):x(t)}function x(t){return t===61?(e.consume(t),S):iR(t)?(e.consume(t),x):y(t)}function S(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),c=t,C):iR(t)?(e.consume(t),S):w(t)}function C(t){return t===c?(e.consume(t),c=null,T):t===null||nR(t)?n(t):(e.consume(t),C)}function w(t){return t===null||t===34||t===39||t===47||t===60||t===61||t===62||t===96||rR(t)?x(t):(e.consume(t),w)}function T(e){return e===47||e===62||iR(e)?y(e):n(e)}function E(t){return t===62?(e.consume(t),D):n(t)}function D(t){return t===null||nR(t)?O(t):iR(t)?(e.consume(t),D):n(t)}function O(t){return t===45&&i===2?(e.consume(t),M):t===60&&i===1?(e.consume(t),N):t===62&&i===4?(e.consume(t),L):t===63&&i===3?(e.consume(t),I):t===93&&i===5?(e.consume(t),F):nR(t)&&(i===6||i===7)?(e.exit(`htmlFlowData`),e.check(yz,R,k)(t)):t===null||nR(t)?(e.exit(`htmlFlowData`),k(t)):(e.consume(t),O)}function k(t){return e.check(IR,A,R)(t)}function A(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),j}function j(t){return t===null||nR(t)?k(t):(e.enter(`htmlFlowData`),O(t))}function M(t){return t===45?(e.consume(t),I):O(t)}function N(t){return t===47?(e.consume(t),o=``,P):O(t)}function P(t){if(t===62){let n=o.toLowerCase();return _z.includes(n)?(e.consume(t),L):O(t)}return YL(t)&&o.length<8?(e.consume(t),o+=String.fromCharCode(t),P):O(t)}function F(t){return t===93?(e.consume(t),I):O(t)}function I(t){return t===62?(e.consume(t),L):t===45&&i===2?(e.consume(t),I):O(t)}function L(t){return t===null||nR(t)?(e.exit(`htmlFlowData`),R(t)):(e.consume(t),L)}function R(n){return e.exit(`htmlFlow`),t(n)}}function Sz(e,t,n){return r;function r(r){return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),e.attempt(ER,t,n)}}var Cz={name:`htmlText`,tokenize:wz};function wz(e,t,n){let r=this,i,a,o;return s;function s(t){return e.enter(`htmlText`),e.enter(`htmlTextData`),e.consume(t),c}function c(t){return t===33?(e.consume(t),l):t===47?(e.consume(t),x):t===63?(e.consume(t),y):YL(t)?(e.consume(t),w):n(t)}function l(t){return t===45?(e.consume(t),u):t===91?(e.consume(t),a=0,m):YL(t)?(e.consume(t),v):n(t)}function u(t){return t===45?(e.consume(t),p):n(t)}function d(t){return t===null?n(t):t===45?(e.consume(t),f):nR(t)?(o=d,N(t)):(e.consume(t),d)}function f(t){return t===45?(e.consume(t),p):d(t)}function p(e){return e===62?M(e):e===45?f(e):d(e)}function m(t){return t===`CDATA[`.charCodeAt(a++)?(e.consume(t),a===6?h:m):n(t)}function h(t){return t===null?n(t):t===93?(e.consume(t),g):nR(t)?(o=h,N(t)):(e.consume(t),h)}function g(t){return t===93?(e.consume(t),_):h(t)}function _(t){return t===62?M(t):t===93?(e.consume(t),_):h(t)}function v(t){return t===null||t===62?M(t):nR(t)?(o=v,N(t)):(e.consume(t),v)}function y(t){return t===null?n(t):t===63?(e.consume(t),b):nR(t)?(o=y,N(t)):(e.consume(t),y)}function b(e){return e===62?M(e):y(e)}function x(t){return YL(t)?(e.consume(t),S):n(t)}function S(t){return t===45||XL(t)?(e.consume(t),S):C(t)}function C(t){return nR(t)?(o=C,N(t)):iR(t)?(e.consume(t),C):M(t)}function w(t){return t===45||XL(t)?(e.consume(t),w):t===47||t===62||rR(t)?T(t):n(t)}function T(t){return t===47?(e.consume(t),M):t===58||t===95||YL(t)?(e.consume(t),E):nR(t)?(o=T,N(t)):iR(t)?(e.consume(t),T):M(t)}function E(t){return t===45||t===46||t===58||t===95||XL(t)?(e.consume(t),E):D(t)}function D(t){return t===61?(e.consume(t),O):nR(t)?(o=D,N(t)):iR(t)?(e.consume(t),D):T(t)}function O(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),i=t,k):nR(t)?(o=O,N(t)):iR(t)?(e.consume(t),O):(e.consume(t),A)}function k(t){return t===i?(e.consume(t),i=void 0,j):t===null?n(t):nR(t)?(o=k,N(t)):(e.consume(t),k)}function A(t){return t===null||t===34||t===39||t===60||t===61||t===96?n(t):t===47||t===62||rR(t)?T(t):(e.consume(t),A)}function j(e){return e===47||e===62||rR(e)?T(e):n(e)}function M(r){return r===62?(e.consume(r),e.exit(`htmlTextData`),e.exit(`htmlText`),t):n(r)}function N(t){return e.exit(`htmlTextData`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),P}function P(t){return iR(t)?cR(e,F,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):F(t)}function F(t){return e.enter(`htmlTextData`),o(t)}}var Tz={name:`labelEnd`,resolveAll:kz,resolveTo:Az,tokenize:jz},Ez={tokenize:Mz},Dz={tokenize:Nz},Oz={tokenize:Pz};function kz(e){let t=-1,n=[];for(;++t<e.length;){let r=e[t][1];if(n.push(e[t]),r.type===`labelImage`||r.type===`labelLink`||r.type===`labelEnd`){let e=r.type===`labelImage`?4:2;r.type=`data`,t+=e}}return e.length!==n.length&&VL(e,0,e.length,n),e}function Az(e,t){let n=e.length,r=0,i,a,o;for(;n--;){let t=e[n][1];if(i){if(t.type===`link`||t.type===`labelLink`&&t._inactive)break;e[n][0]===`enter`&&t.type===`labelLink`&&(t._inactive=!0)}else if(a){if(e[n][0]===`enter`&&(t.type===`labelImage`||t.type===`labelLink`)&&!t._balanced&&(i=n,t.type!==`labelLink`)){r=2;break}}else t.type===`labelEnd`&&(a=n)}let s={type:e[i][1].type===`labelLink`?`link`:`image`,start:{...e[i][1].start},end:{...e[e.length-1][1].end}},c={type:`label`,start:{...e[i][1].start},end:{...e[a][1].end}},l={type:`labelText`,start:{...e[i+r+2][1].end},end:{...e[a-2][1].start}};return o=[[`enter`,s,t],[`enter`,c,t]],o=HL(o,e.slice(i+1,i+r+3)),o=HL(o,[[`enter`,l,t]]),o=HL(o,yR(t.parser.constructs.insideSpan.null,e.slice(i+r+4,a-3),t)),o=HL(o,[[`exit`,l,t],e[a-2],e[a-1],[`exit`,c,t]]),o=HL(o,e.slice(a+1)),o=HL(o,[[`exit`,s,t]]),VL(e,i,e.length,o),e}function jz(e,t,n){let r=this,i=r._labelStarts,a,o;if(i){for(;i.length>0&&i[i.length-1]._balanced;)i.pop();a=i[i.length-1]}return s;function s(t){return a?a._inactive?d(t):(o=r.parser.defined.includes(JL(r.sliceSerialize({start:a.end,end:r.now()}))),e.enter(`labelEnd`),e.enter(`labelMarker`),e.consume(t),e.exit(`labelMarker`),e.exit(`labelEnd`),c):n(t)}function c(t){return t===40?e.attempt(Ez,u,o?u:d)(t):t===91?e.attempt(Dz,u,o?l:d)(t):o?u(t):d(t)}function l(t){return e.attempt(Oz,u,d)(t)}function u(e){return i.pop(),t(e)}function d(e){return a._balanced=!0,n(e)}}function Mz(e,t,n){return r;function r(t){return e.enter(`resource`),e.enter(`resourceMarker`),e.consume(t),e.exit(`resourceMarker`),i}function i(t){return rR(t)?oz(e,a)(t):a(t)}function a(t){return t===41?u(t):rz(e,o,s,`resourceDestination`,`resourceDestinationLiteral`,`resourceDestinationLiteralMarker`,`resourceDestinationRaw`,`resourceDestinationString`,32)(t)}function o(t){return rR(t)?oz(e,c)(t):u(t)}function s(e){return n(e)}function c(t){return t===34||t===39||t===40?az(e,l,n,`resourceTitle`,`resourceTitleMarker`,`resourceTitleString`)(t):u(t)}function l(t){return rR(t)?oz(e,u)(t):u(t)}function u(r){return r===41?(e.enter(`resourceMarker`),e.consume(r),e.exit(`resourceMarker`),e.exit(`resource`),t):n(r)}}function Nz(e,t,n){let r=this;return i;function i(t){return iz.call(r,e,a,o,`reference`,`referenceMarker`,`referenceString`)(t)}function a(e){return r.parser.defined.includes(JL(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(e):n(e)}function o(e){return n(e)}}function Pz(e,t,n){return r;function r(t){return e.enter(`reference`),e.enter(`referenceMarker`),e.consume(t),e.exit(`referenceMarker`),i}function i(r){return r===93?(e.enter(`referenceMarker`),e.consume(r),e.exit(`referenceMarker`),e.exit(`reference`),t):n(r)}}var Fz={name:`labelStartImage`,resolveAll:Tz.resolveAll,tokenize:Iz};function Iz(e,t,n){let r=this,i;return a;function a(t){return e.enter(`labelImage`),e.enter(`labelImageMarker`),e.consume(t),e.exit(`labelImageMarker`),o}function o(t){return t===91?(e.enter(`labelMarker`),e.consume(t),e.exit(`labelMarker`),i=e.exit(`labelImage`),s):n(t)}function s(e){return e===94&&`_hiddenFootnoteSupport`in r.parser.constructs?n(e):(r._labelStarts=r._labelStarts||[],r._labelStarts.push(i),t(e))}}var Lz={name:`labelStartLink`,resolveAll:Tz.resolveAll,tokenize:Rz};function Rz(e,t,n){let r=this,i;return a;function a(t){return e.enter(`labelLink`),e.enter(`labelMarker`),e.consume(t),e.exit(`labelMarker`),i=e.exit(`labelLink`),o}function o(e){return e===94&&`_hiddenFootnoteSupport`in r.parser.constructs?n(e):(r._labelStarts=r._labelStarts||[],r._labelStarts.push(i),t(e))}}var zz={name:`lineEnding`,tokenize:Bz};function Bz(e,t){return n;function n(n){return e.enter(`lineEnding`),e.consume(n),e.exit(`lineEnding`),cR(e,t,`linePrefix`)}}var Vz={name:`thematicBreak`,tokenize:Hz};function Hz(e,t,n){let r=0,i;return a;function a(t){return e.enter(`thematicBreak`),o(t)}function o(e){return i=e,s(e)}function s(a){return a===i?(e.enter(`thematicBreakSequence`),c(a)):r>=3&&(a===null||nR(a))?(e.exit(`thematicBreak`),t(a)):n(a)}function c(t){return t===i?(e.consume(t),r++,c):(e.exit(`thematicBreakSequence`),iR(t)?cR(e,s,`whitespace`)(t):s(t))}}var Uz={continuation:{tokenize:qz},exit:Yz,name:`list`,tokenize:Kz},Wz={partial:!0,tokenize:Xz},Gz={partial:!0,tokenize:Jz};function Kz(e,t,n){let r=this,i=r.events[r.events.length-1],a=i&&i[1].type===`linePrefix`?i[2].sliceSerialize(i[1],!0).length:0,o=0;return s;function s(t){let i=r.containerState.type||(t===42||t===43||t===45?`listUnordered`:`listOrdered`);if(i===`listUnordered`?!r.containerState.marker||t===r.containerState.marker:$L(t)){if(r.containerState.type||(r.containerState.type=i,e.enter(i,{_container:!0})),i===`listUnordered`)return e.enter(`listItemPrefix`),t===42||t===45?e.check(Vz,n,l)(t):l(t);if(!r.interrupt||t===49)return e.enter(`listItemPrefix`),e.enter(`listItemValue`),c(t)}return n(t)}function c(t){return $L(t)&&++o<10?(e.consume(t),c):(!r.interrupt||o<2)&&(r.containerState.marker?t===r.containerState.marker:t===41||t===46)?(e.exit(`listItemValue`),l(t)):n(t)}function l(t){return e.enter(`listItemMarker`),e.consume(t),e.exit(`listItemMarker`),r.containerState.marker=r.containerState.marker||t,e.check(ER,r.interrupt?n:u,e.attempt(Wz,f,d))}function u(e){return r.containerState.initialBlankLine=!0,a++,f(e)}function d(t){return iR(t)?(e.enter(`listItemPrefixWhitespace`),e.consume(t),e.exit(`listItemPrefixWhitespace`),f):n(t)}function f(n){return r.containerState.size=a+r.sliceSerialize(e.exit(`listItemPrefix`),!0).length,t(n)}}function qz(e,t,n){let r=this;return r.containerState._closeFlow=void 0,e.check(ER,i,a);function i(n){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,cR(e,t,`listItemIndent`,r.containerState.size+1)(n)}function a(n){return r.containerState.furtherBlankLines||!iR(n)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,o(n)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(Gz,t,o)(n))}function o(i){return r.containerState._closeFlow=!0,r.interrupt=void 0,cR(e,e.attempt(Uz,t,n),`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(i)}}function Jz(e,t,n){let r=this;return cR(e,i,`listItemIndent`,r.containerState.size+1);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`listItemIndent`&&i[2].sliceSerialize(i[1],!0).length===r.containerState.size?t(e):n(e)}}function Yz(e){e.exit(this.containerState.type)}function Xz(e,t,n){let r=this;return cR(e,i,`listItemPrefixWhitespace`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:5);function i(e){let i=r.events[r.events.length-1];return!iR(e)&&i&&i[1].type===`listItemPrefixWhitespace`?t(e):n(e)}}var Zz={name:`setextUnderline`,resolveTo:Qz,tokenize:$z};function Qz(e,t){let n=new fR,r=e.length,i,a,o;for(;r--;)if(e[r][0]===`enter`){if(e[r][1].type===`content`){i=r;break}e[r][1].type===`paragraph`&&(a=r)}else e[r][1].type===`content`&&n.add(r,1,[]),!o&&e[r][1].type===`definition`&&(o=r);let s={type:`setextHeading`,start:{...e[i][1].start},end:{...e[e.length-1][1].end}};return e[a][1].type=`setextHeadingText`,o?(n.add(a,0,[[`enter`,s,t]]),n.add(o+1,0,[[`exit`,e[i][1],t]]),e[i][1].end={...e[o][1].end}):e[i][1]=s,n.add(e.length,0,[[`exit`,s,t]]),n.consume(e),e}function $z(e,t,n){let r=this,i;return a;function a(t){let a=r.events.length,s;for(;a--;)if(r.events[a][1].type!==`lineEnding`&&r.events[a][1].type!==`linePrefix`&&r.events[a][1].type!==`content`){s=r.events[a][1].type===`paragraph`;break}return!r.parser.lazy[r.now().line]&&(r.interrupt||s)?(e.enter(`setextHeadingLine`),i=t,o(t)):n(t)}function o(t){return e.enter(`setextHeadingLineSequence`),s(t)}function s(t){return t===i?(e.consume(t),s):(e.exit(`setextHeadingLineSequence`),iR(t)?cR(e,c,`lineSuffix`)(t):c(t))}function c(r){return r===null||nR(r)?(e.exit(`setextHeadingLine`),t(r)):n(r)}}var eB={tokenize:tB};function tB(e){let t=this,n=e.attempt(ER,r,e.attempt(this.parser.constructs.flowInitial,i,cR(e,e.attempt(this.parser.constructs.flow,i,e.attempt(QR,i)),`linePrefix`)));return n;function r(r){if(r===null)e.consume(r);else return e.enter(`lineEndingBlank`),e.consume(r),e.exit(`lineEndingBlank`),t.currentConstruct=void 0,n}function i(r){if(r===null)e.consume(r);else return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),t.currentConstruct=void 0,n}}var nB={resolveAll:oB()},rB=aB(`string`),iB=aB(`text`);function aB(e){return{resolveAll:oB(e===`text`?sB:void 0),tokenize:t};function t(t){let n=this,r=this.parser.constructs[e],i=t.attempt(r,a,o);return a;function a(e){return c(e)?i(e):o(e)}function o(e){if(e===null)t.consume(e);else return t.enter(`data`),t.consume(e),s}function s(e){return c(e)?(t.exit(`data`),i(e)):(t.consume(e),s)}function c(e){if(e===null)return!0;let t=r[e],i=-1;if(t)for(;++i<t.length;){let e=t[i];if(!e.previous||e.previous.call(n,n.previous))return!0}return!1}}}function oB(e){return t;function t(t,n){let r=-1,i;for(;++r<=t.length;)i===void 0?t[r]&&t[r][1].type===`data`&&(i=r,r++):t[r]&&t[r][1].type===`data`||(r!==i+2&&(t[i][1].end=t[r-1][1].end,t.splice(i+2,r-i-2),r=i+2),i=void 0);return e?e(t,n):t}}function sB(e,t){let n=new fR,r=0;for(;++r<=e.length;)if((r===e.length||e[r][1].type===`lineEnding`)&&e[r-1][1].type===`data`){let i=e[r-1][1],a=t.sliceStream(i),o=a.length,s=-1,c=0,l;for(;o--;){let e=a[o];if(typeof e==`string`){for(s=e.length;e.charCodeAt(s-1)===32;)c++,s--;if(s)break;s=-1}else if(e===-2)l=!0,c++;else if(e!==-1){o++;break}}if(t._contentTypeTextTrailing&&r===e.length&&(c=0),c){let a={type:r===e.length||l||c<2?`lineSuffix`:`hardBreakTrailing`,start:{_bufferIndex:o?s:i.start._bufferIndex+s,_index:i.start._index+o,line:i.end.line,column:i.end.column-c,offset:i.end.offset-c},end:{...i.end}};i.end={...a.start},i.start.offset===i.end.offset?Object.assign(i,a):n.add(r,0,[[`enter`,a,t],[`exit`,a,t]])}r++}return n.consume(e),e}var cB=M({attentionMarkers:()=>gB,contentInitial:()=>uB,disable:()=>_B,document:()=>lB,flow:()=>fB,flowInitial:()=>dB,insideSpan:()=>hB,string:()=>pB,text:()=>mB}),lB={42:Uz,43:Uz,45:Uz,48:Uz,49:Uz,50:Uz,51:Uz,52:Uz,53:Uz,54:Uz,55:Uz,56:Uz,57:Uz,62:OR},uB={91:sz},dB={[-2]:BR,[-1]:BR,32:BR},fB={35:pz,42:Vz,45:[Zz,Vz],60:vz,61:Zz,95:Vz,96:RR,126:RR},pB={38:PR,92:MR},mB={[-5]:zz,[-4]:zz,[-3]:zz,33:Fz,38:PR,42:bR,60:[wR,Cz],91:Lz,92:[dz,MR],93:Tz,95:bR,96:WR},hB={null:[bR,nB]},gB={null:[42,95]},_B={null:[]};function vB(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0},i={},a=[],o=[],s=[],c={attempt:C(x),check:C(S),consume:v,enter:y,exit:b,interrupt:C(S,{interrupt:!0})},l={code:null,containerState:{},defineSkip:h,events:[],now:m,parser:e,previous:null,sliceSerialize:f,sliceStream:p,write:d},u=t.tokenize.call(l,c);return t.resolveAll&&a.push(t),l;function d(e){return o=HL(o,e),g(),o[o.length-1]===null?(w(t,0),l.events=yR(a,l.events,l),l.events):[]}function f(e,t){return bB(p(e),t)}function p(e){return yB(o,e)}function m(){let{_bufferIndex:e,_index:t,line:n,column:i,offset:a}=r;return{_bufferIndex:e,_index:t,line:n,column:i,offset:a}}function h(e){i[e.line]=e.column,E()}function g(){for(;r._index<o.length;){let e=o[r._index];if(typeof e==`string`){let t=r._index;for(r._bufferIndex<0&&(r._bufferIndex=0);r._index===t&&r._bufferIndex<e.length;)_(e.charCodeAt(r._bufferIndex))}else _(e)}}function _(e){u=u(e)}function v(e){nR(e)?(r.line++,r.column=1,r.offset+=e===-3?2:1,E()):e!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===o[r._index].length&&(r._bufferIndex=-1,r._index++)),l.previous=e}function y(e,t){let n=t||{};return n.type=e,n.start=m(),l.events.push([`enter`,n,l]),s.push(n),n}function b(e){let t=s.pop();return t.end=m(),l.events.push([`exit`,t,l]),t}function x(e,t){w(e,t.from)}function S(e,t){t.restore()}function C(e,t){return n;function n(n,r,i){let a,o,s,u;return Array.isArray(n)?f(n):`tokenize`in n?f([n]):d(n);function d(e){return t;function t(t){let n=t!==null&&e[t],r=t!==null&&e.null;return f([...Array.isArray(n)?n:n?[n]:[],...Array.isArray(r)?r:r?[r]:[]])(t)}}function f(e){return a=e,o=0,e.length===0?i:p(e[o])}function p(e){return n;function n(n){return u=T(),s=e,e.partial||(l.currentConstruct=e),e.name&&l.parser.constructs.disable.null.includes(e.name)?h(n):e.tokenize.call(t?Object.assign(Object.create(l),t):l,c,m,h)(n)}}function m(t){return e(s,u),r}function h(e){return u.restore(),++o<a.length?p(a[o]):i}}}function w(e,t){e.resolveAll&&!a.includes(e)&&a.push(e),e.resolve&&VL(l.events,t,l.events.length-t,e.resolve(l.events.slice(t),l)),e.resolveTo&&(l.events=e.resolveTo(l.events,l))}function T(){let e=m(),t=l.previous,n=l.currentConstruct,i=l.events.length,a=Array.from(s);return{from:i,restore:o};function o(){r=e,l.previous=t,l.currentConstruct=n,l.events.length=i,s=a,E()}}function E(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function yB(e,t){let n=t.start._index,r=t.start._bufferIndex,i=t.end._index,a=t.end._bufferIndex,o;if(n===i)o=[e[n].slice(r,a)];else{if(o=e.slice(n,i),r>-1){let e=o[0];typeof e==`string`?o[0]=e.slice(r):o.shift()}a>0&&o.push(e[i].slice(0,a))}return o}function bB(e,t){let n=-1,r=[],i;for(;++n<e.length;){let a=e[n],o;if(typeof a==`string`)o=a;else switch(a){case-5:o=`\r`;break;case-4:o=`
91
+ `)[0]??``,wE=(e,t,n,r)=>({id:e,...r,doctor:async i=>{let a=`${t} (${e} driver)`,o=await i(t,[`--version`]),s=r.proven?``:`, unproven: not yet proven on a real session`;return o.ok?{name:a,status:r.proven?`ok`:`skip`,detail:`${CE(o.stdout)}${s}; sign in with \`${n}\` if a session asks`}:{name:a,status:`skip`,detail:`${t} CLI not found${s}`,...r.proven?{hint:`Install ${t} to use the ${e} driver.`}:{}}}});wE(`open-code`,`opencode`,`opencode auth login`,{label:"the `opencode` CLI",proven:!0,onePerCheckout:!1,capabilities:{questions:!0,permissionPrompt:!1,price:!0,midTurnMessages:!1,reportSchema:!1,turnLimit:!0,mcpServers:!0,subagents:!1}}),wE(`command-code`,`cmd`,`cmd login`,{label:"the `cmd` CLI of Command Code",proven:!0,onePerCheckout:!0,capabilities:{questions:!0,permissionPrompt:!1,price:!1,midTurnMessages:!1,reportSchema:!1,turnLimit:!0,mcpServers:!1,subagents:!1}});var TE=[`claude-code`,`open-code`,`command-code`],EE={sdk:`claude-code`,cli:`claude-code`},DE=[yE({id:`gh`,label:`GitHub CLI`,program:`gh`,options:{},args:()=>[],signedOut:({exitCode:e,stderr:t})=>e===4||/\bgh auth login\b/u.test(t),doctor:async e=>{if(!(await e(`gh`,[`--version`])).ok)return{name:`gh`,status:`skip`,detail:`optional, not installed (needed only for tool.gh nodes)`};let t=SE(SE(xE((await e(`gh`,[`auth`,`status`,`--json`,`hosts`])).stdout),`hosts`),`github.com`),n=(Array.isArray(t)?t:[]).find(e=>SE(e,`active`)===!0),r=SE(n,`login`);return SE(n,`state`)!==`success`||typeof r!=`string`?{name:`gh`,status:`warn`,detail:`not logged in to github.com`,hint:"Run `gh auth login` yourself to use tool.gh nodes."}:{name:`gh`,status:`ok`,detail:`logged in as ${r}`}}}),bE,yE({id:`git`,label:`Git`,program:`git`,options:{},args:()=>[],allow:[`add`,`commit`],observe:{fields:[`staged`,`diff`,`head`],read:async e=>{let t=await e([`diff`,`--cached`,`--stat`]),n=await e([`diff`,`--cached`]),r=await e([`rev-parse`,`--verify`,`--quiet`,`HEAD`]);return{staged:t.ok?t.stdout.trimEnd():``,diff:n.ok?n.stdout:``,head:r.ok?r.stdout.trim():``}}},doctor:async e=>{let t=await e(`git`,[`config`,`user.name`]),n=await e(`git`,[`config`,`user.email`]);return t.stdout.trim()===``||n.stdout.trim()===``?{name:`git identity`,status:`warn`,detail:`user.name or user.email is not set (needed only to commit with tool.git)`,hint:"Set them yourself (`git config --global user.name …`) before a tool.git node commits."}:{name:`git identity`,status:`ok`,detail:`user.name and user.email are set`}}}),yE({id:`shell`,label:`Any program`,program:null,options:{},args:()=>[]})],OE=`tool.`,kE={maxParallel:rs().int().positive().optional().describe(`Most items running at once. Default: limits.concurrency.`),onFailure:Os([`finish`,`stop`]).optional().describe("When an item fails: `finish` runs every item (default), `stop` starts no more.")},AE={forEach:vs([H({items:ps(ls()).min(1).describe(`The list, written here. Each entry is one item.`),...kE}),H({from:V().describe(`Where the list comes from: one path, e.g. {{nodes.plan.output.tasks}}.`),maxItems:rs().int().positive().describe(`Most items allowed. A longer list asks whether to stop, run this many, or run all.`),...kE})]).optional().describe("Run this node once per item of a list, with no model turn to fan out or gather. Items are `<id>.0`, `<id>.1`, ….")},jE={lock:V().regex(/\S/u,`a lock needs a name`).describe("The lock this node holds, e.g. `branch:{{inputs.branch}}`. Held from the first node that names it to the last, or the run's end; one run at a time holds it, the others wait. One name per node.").optional()},ME=V().regex(/^[A-Za-z_][A-Za-z0-9_]*$/u),NE=vs([ps(vs([V(),rs(),ss()])).min(1),Os([`string`,`number`,`integer`,`boolean`])]),PE="`list` takes a map of each item's fields, e.g. `list: { title: string }` (`list: {}` for items of any shape)",FE=H({list:Es(V(),NE).describe(`The fields each item has, e.g. { title: string }; { } for no shape.`)}).describe(`A list of items, such as a plan's tasks.`),IE=Es(V(),vs([NE,FE])),LE={env:Es(ME,V()).optional().describe(`Environment variables for the program. Values are templates, and may read the user's own variables as {{env.NAME}}.`),plainEnv:ps(ME).optional().describe(`Variables read as {{env.NAME}} that are not secret, such as a region: their values are not masked in what programs print.`),output:H({format:As(`json`).describe(`The program's result is JSON, read as output.json: the file at $ORK_OUTPUT if it wrote one, otherwise its stdout.`),schema:IE.optional().describe(`The fields of that JSON a later node relies on, e.g. { state: [OPEN, CLOSED] }. A value outside these fails the node.`)}).optional().describe(`Structured output from the program.`)},RE=V().regex(/^[a-z][a-z0-9_-]*$/u,`node ids are lowercase: letters, digits, '-' and '_'`),zE=e=>{let t=typeof e==`string`&&Object.hasOwn(EE,e)?EE[e]:void 0;return t===void 0?void 0:`driver \`${String(e)}\` was retired; use \`${t}\``},BE=Os(TE,{error:e=>zE(e.input)}),VE=V().min(1),HE=Os([`low`,`medium`,`high`,`xhigh`,`max`]).describe(`Reasoning effort. Default: Claude Code's for the model.`),UE=Os([`worktree`,`continue`,`shared`,`readonly`]),WE=rs().positive(),GE=rs().int().positive(),KE=H({dayUsd:WE.optional().describe(`Most to spend in a calendar day.`),dayTokens:GE.optional().describe(`Most tokens (input, output, cache-write) to use in a calendar day.`),weekUsd:WE.optional().describe(`Most to spend in a calendar week, from Monday.`),monthUsd:WE.optional().describe(`Most to spend in a calendar month.`)}),qE={s:1e3,m:6e4,h:36e5},JE=e=>{let t=/^(\d+)([smh])$/u.exec(e??``);if(t===null)return;let[,n=`0`,r=`s`]=t;return Number(n)*(qE[r]??1e3)},YE=2**31-1,XE=V().regex(/^\d+[smh]$/u,`use e.g. 30s, 15m, 2h`).refine(e=>(JE(e)??0)<=YE,`the longest this can be is 596h`),ZE=XE.refine(e=>!/^0+[smh]$/u.test(e),`a timeout must be longer than zero`),QE=e=>XE.refine(t=>(JE(t)??0)>=(JE(e)??0),`look no more often than every ${e}`),$E=H({every:QE(`5s`).describe(`How long to wait between looks, e.g. 30s. At least 5s.`),until:V().min(1).describe(`Stop looking when this holds. It reads what an edge's when: does.`),timeout:ZE.describe(`How long to go on looking, e.g. 2h; then the node fails. Time between looks doesn't count against limits.timeout.`),misses:rs().int().positive().optional().describe(`How many failed looks in a row end the wait, such as a network error. Default: 3.`)}).refine(({every:e,timeout:t})=>(JE(t)??0)>(JE(e)??0),`watch.timeout must be longer than watch.every`),eD=H({caveman:ss().optional().describe(`Terse voice in chat, reports and messages. Default: on.`),ponytail:vs([ss(),Os([`lite`,`full`,`ultra`])]).optional().describe("Smallest complete change. `true` is `full`. Default: `full`.")}),tD=rs().int().positive(),nD=ps(V().min(1)).optional().describe("MCP servers from the project's `.mcp.json` this node's sessions load, beside Ork's own. Default: none."),rD=H({allow:ps(V()).optional(),deny:ps(V()).optional(),only:ps(V()).optional().describe(`The only built-in tools the session has; Ork's tools stay.`)}),iD=V().regex(/^[a-z][a-z0-9_-]*$/u,`agent names are lowercase: letters, digits, '-' and '_'`),aD={parent:RE.optional().describe(`Owner of this node in the ownership tree.`),label:V().optional(),description:V().optional()},oD={notify:ps(H({to:RE.describe("The `agent.leader` or `agent.worker` to write to."),when:V().optional().describe(`Send only when this holds. It reads what an edge's when: does, plus ok and error. Default: every finish.`),body:V().optional().describe(`The message, a template. Default: Ork's one line on the result.`)})).optional().describe(`Messages to send when this node finishes, with no model turn. Each starts no session.`)},sD=H({type:As(`mcp.call`),...aD,server:V().describe("The server's name in the project's `.mcp.json`."),tool:V().describe(`The tool to call on it.`),arguments:Es(V(),ls()).optional().describe(`The tool's arguments. Strings are templates; one that is only {{ … }} keeps its value's type.`),output:H({schema:IE.optional().describe(`The fields of the tool's JSON result a later node relies on, e.g. { state: [open, closed] }. A value outside these fails the node.`)}).optional().describe(`What the tool's result says.`),env:LE.env,plainEnv:LE.plainEnv,timeout:ZE.optional().describe(`How long the call may take, e.g. 5m; then the node fails. With watch:, how long one look may take.`),watch:$E.optional().describe(`Call the tool again and again until a condition holds, with no model turn.`),...oD,...jE,...AE}),cD={command:V().optional().describe(`Program and arguments (no shell), or script: instead. Supports templates.`),script:V().optional().describe(`The text of a short program, instead of command. It takes no templates: values arrive through env:, as $NAME, so a value cannot become code.`),interpreter:V().optional().describe("What runs `script:`: a program and arguments. Default: `sh -eu`.")},lD=ss().optional().describe(`Skip the command when the same check already passed on identical files (a hash of the working tree, the command, Node's version); a pass is recorded. Default: false.`),uD=H({...cD,...LE,timeout:ZE.optional().describe(`How long the program may run, e.g. 5m; then it is killed and the step fails.`)}),dD=uD.extend({attempts:rs().int().min(0).max(5).optional().describe(`How many times a failed check resumes the session to fix it before the node fails. Default: 1.`),once:lD}).describe(`A program that must pass before the node's report is accepted. It runs in the node's checkout.`),fD={before:uD.optional().describe(`A program to run in the node's checkout before its session starts: if it fails, the node fails and no model turn is spent. Its prompt can read {{before.stdout}}, {{before.json.*}}.`),verify:dD.optional()},pD={...aD,...cD,allow:ps(V()).optional().describe("Allowed subcommand prefixes, e.g. `pr view`, `pr merge`."),cwd:V().optional(),timeout:ZE.optional().describe(`How long the command may run, e.g. 5m; then it is killed and the node fails. With watch:, how long one look may take.`),watch:$E.optional().describe(`Run the command again and again until a condition holds, with no model turn.`),once:lD,...LE,...oD,...jE,...AE},mD=e=>H({type:As(e),...pD}),hD=e=>{let t=mD(`${OE}${e.id}`);return e.program===null?t.extend(e.options):t.omit({script:!0,interpreter:!0}).extend({command:V().describe(`Arguments for the CLI (no shell). Supports templates.`),...e.options})},gD=DE.map(e=>hD(e)),_D=ls().refine(e=>typeof e!=`object`||!e||!(`list`in e),{message:PE}),vD=`expected low, medium, high, xhigh or max, or {{item.<field>}}`,yD=vs([HE,V().regex(/\{\{.*\}\}/su,{error:vD})],{error:vD}).describe(`Reasoning effort, or {{item.<field>}} on a forEach node. Default: Claude Code's for the model.`),bD={model:VE.optional(),effort:yD.optional(),driver:BE.optional(),skills:ps(V()).optional().describe(`Node-layer skills (highest precedence).`),context:ps(V()).optional().describe(`Node-layer context files.`),isolation:UE.optional(),budgetUsd:WE.optional(),budgetTokens:GE.optional(),maxTurns:tD.optional(),timeout:ZE.optional().describe(`How long the node may work, e.g. 30m; time waiting on the user does not count.`),practices:eD.optional(),tools:rD.optional(),session:Os([`fresh`,`resume`]).optional().describe(`When the node runs again (a loop, another delegation): resume its session, or start a fresh one with the new input. Default: resume for a leader, fresh for a worker.`),output:H({schema:Es(V(),vs([FE,_D])).optional().describe(`Extra structured fields the node must report, e.g. { verdict: [approve, escalate] }.`),gather:ps(V().min(1)).min(1).optional().describe(`List fields kept across rounds: each round's entries are added to the earlier rounds' instead of replacing them, e.g. [decisions].`)}).optional()},xD={...aD,agent:iD.optional().describe(`The agent that fills this node; its settings apply where the node sets none, and the prompt is its task.`),prompt:V().optional().describe(`Task brief. Supports {{inputs.*}} and {{nodes.<id>.output.*}} templates.`),instructions:V().optional().describe(`Node-layer instructions appended to the system prompt.`),...bD},SD=H({type:As(`agent.leader`),...xD,mcp:nD,...oD,...fD,maxWorkers:rs().int().nonnegative().optional().describe(`Cap on dynamically spawned workers.`),questions:Os([`owner`,`user`]).optional().describe("Who a child's ask_user goes to first: `owner` asks a fork of this leader's session, which answers when what it was given settles it or passes it on; `user` (the default) asks the person.")}),CD=H({type:As(`agent.worker`),...xD,mcp:nD,...oD,...jE,...AE,...fD}),wD=H({type:As(`agent.subagent`),...xD,parent:RE.describe(`The Claude node whose session hosts this sub-agent.`),description:V().describe(`When the parent should use this sub-agent.`)}),TD=H({type:As(`control.split`),...aD}),ED=H({type:As(`control.join`),...aD,mode:Os([`all`,`any`,`n`]).optional().describe(`Default: all.`),n:rs().int().positive().optional()}),DD=H({type:As(`control.router`),...aD,mode:Os([`first`,`all`]).optional().describe(`Follow the first matching edge (default), or every match.`)}),OD=vs([V(),H({id:V(),label:V().optional(),description:V().optional()})]),kD=H({type:As(`human.gate`),...aD,...oD,question:V(),document:V().optional(),options:ps(OD).min(2),recommended:V().optional(),timeout:XE.optional(),default:V().optional().describe(`Option chosen when the timeout expires.`)}),AD=H({type:As(`workflow.call`),...aD,...oD,...AE,workflow:V().describe(`The workflow's name, as in its project's workflows folder.`),project:V().optional().describe(`A registered project's id. Default: this project.`),node:RE.optional().describe(`A leader or worker of the called workflow to talk to and wait on; the call then keeps one run as a conversation.`),inputs:Es(V(),V()).optional().describe(`The called workflow's inputs. Supports templates.`),wait:Os([`run`,`node`,`none`]).optional().describe("When this node finishes: the run has ended (default without `node`), the node has reported (default with `node`), or as soon as the run has started."),ref:V().optional().describe(`What the called run's worktrees start from, e.g. {{nodes.build.output.branch}}.`),timeout:ZE.optional().describe(`How long the call may take, e.g. 30m; then the called run is stopped and the node fails.`),maxMessages:rs().int().positive().optional().describe(`Ask the user whether to go on after this many messages.`)}),jD=bs(`type`,[SD,CD,wD,...gD,TD,ED,DD,kD,AD,sD]);H(bD);var MD=H({description:V().optional().describe(`When to use this agent; tools show it when choosing one.`),instructions:V().optional().describe(`The agent's role, appended to the system prompt of its nodes.`),...bD}),ND=H({driver:BE.optional(),model:VE.optional(),effort:HE.optional(),isolation:UE.optional(),budgetUsd:WE.optional(),budgetTokens:GE.optional(),maxTurns:tD.optional(),timeout:ZE.optional().describe(`For tool and Claude nodes that set none; a gate's own timeout is separate.`),practices:eD.optional(),mcp:nD,before:fD.before}),PD=H({git:H({commit:Os([`auto`,`never`]).optional().describe(`Default: auto, Ork commits a node's work on its branch. never: Ork runs no git commit; worktrees are detached and work stays uncommitted.`),merge:Os([`auto`,`patch`,`never`]).optional().describe(`How a passing child's work reaches its owner. auto: a --no-ff merge (needs commits). patch: its changes are applied, uncommitted. never: left in its own worktree. Default: auto, or patch under commit: never.`),base:V().min(1).optional().describe(`The commit worktrees without an owner start from, e.g. origin/main. Default: HEAD. Ork never fetches.`),branch:V().min(1).optional().describe(`Branch name template over {run}, {node}, {clone} and {inputs.<name>}. Default: ork/{run}/{node}.`),worktrees:V().min(1).optional().describe(`Worktree folder template, relative to the clone, beside it. Default: ../{clone}-worktrees/ork-{run}-{node}.`)}).optional(),permissions:rD.optional().describe(`Tool rules every Claude node gets on top of its own, e.g. deny: ['Bash(git push *)'].`),links:Os([`on`,`off`]).optional().describe(`Default: on, the user can link a running node to a node of another run. off: its nodes get no message tools unless they have someone to write to, and cannot be linked.`)}),FD=Os([`low`,`normal`]);H({schemaVersion:As(1),...PD.shape,defaults:ND.optional().describe(`Defaults for every workflow in the project; a workflow's own win.`),quotas:KE.optional().describe(`Most this project may spend on this machine. The user's own caps apply too.`),calls:H({accept:ps(V()).describe(`The registered projects whose workflows may call this one's.`)}).optional().describe(`Default: any registered project may call this one's workflows.`),context:ps(V()).optional().describe(`Context files every node reads, relative to the project root; they come before the workflow's.`),experimental:ps(V()).optional().describe(`Experimental features this project turns on.`),heavy:ps(V().min(1)).optional().describe(`The project's full-suite commands, as Bash permission patterns without Bash(…), e.g. pnpm check. A node with verify: may not run them in its session; vitest run does not cover vitest run <files>.`),priority:FD.optional().describe(`Default: low, sessions and tool commands start at a lower OS priority. normal: as the ork process.`)}),H({schemaVersion:As(1),quotas:KE.optional().describe(`Most to spend across every project on this machine.`)});var ID=bs(`type`,[sD,...gD]),LD=H({every:QE(`1m`).describe(`How long to wait between looks, e.g. 5m. At least 1m.`),check:ID.optional().describe(`What to look at; it reports { "events": [{ "key": "...", "inputs": { ... } }] }. Without one, the trigger starts a run every time.`),run:V().regex(/^[A-Za-z0-9][A-Za-z0-9._-]*$/u,`the name of a workflow in this project, not a path or a flag`).describe(`The workflow to start, by its name in this project.`),inputs:Es(V(),V()).optional().describe(`Inputs every run gets. They win over what a check reports, and aren't marked untrusted.`),maxRunsPerDay:rs().int().positive().optional().describe(`Most runs to start in a calendar day. Default: 10.`),concurrency:rs().int().positive().optional().describe(`How many of its runs may be going at once. A new key waits for the next look. Default: 1.`)});H({schemaVersion:As(1),triggers:Es(RE,LD)}),hs({events:ps(hs({key:V().min(1),inputs:Es(V(),vs([V(),rs(),ss()])).optional()}))});var RD=vs([RE,ps(RE).min(1)]),zD=vs([V(),H({from:RD,to:RD,when:V().optional(),maxRounds:rs().int().positive().optional()})]),BD=H({between:ws([RE,RE])}),VD=H({type:Os([`string`,`number`,`boolean`]).optional().describe(`Default: string.`),required:ss().optional(),default:vs([V(),rs(),ss()]).optional(),description:V().optional()}),HD=H({instructions:Os([`inherit`,`ignore`]).optional().describe(`Default: inherit.`),skills:vs([Os([`inherit`,`ignore`]),H({allow:ps(V())})]).optional().describe(`Default: inherit.`)}),UD=H({schemaVersion:As(1),name:V().regex(/^[a-z0-9][a-z0-9._-]*$/u,`workflow names are lowercase slugs`),description:V().optional(),inputs:Es(V(),VD).optional(),layers:H({skills:ps(V()).optional(),context:ps(V()).optional(),project:HD.optional()}).optional(),defaults:ND.optional(),rules:PD.optional().describe(`Rules for what Ork does on its own (git, permissions); they win over the project's .ork/project.yaml.`),agents:Es(iD,MD).optional().describe(`Agents defined in this workflow; they win over the project's and the user's of the same name.`),limits:H({budgetUsd:WE.optional().describe(`Hard cap for the whole run.`),budgetTokens:GE.optional().describe(`Hard cap for the whole run in tokens (input, output, cache-write).`),concurrency:rs().int().positive().optional().describe(`Max sessions running at once.`),timeout:ZE.optional().describe(`How long the whole run may work, e.g. 2h; time waiting on the user does not count.`)}).optional(),nodes:Es(RE,jD).refine(e=>Object.keys(e).length>0,`a workflow needs nodes`),edges:ps(zD).optional(),messages:ps(BD).optional(),outputs:Es(V(),V()).optional().describe(`What a workflow.call of this workflow can read, as templates over its nodes, rendered when the run ends.`)});jD.options.map(e=>e.shape.type.value),Object.keys(UD.shape),Object.keys(MD.shape),new Map(jD.options.map(e=>[e.shape.type.value,Object.keys(e.shape)]));var WD=(e,t)=>{let n=e.indexOf(`.`);if(n<=0)return{model:e};let r=e.slice(0,n);return t.includes(r)?{driver:r,model:e.slice(n+1)}:{model:e}},GD=ps(vs([V(),rs().int().min(0)])).min(1),KD={when:V().optional(),maxRounds:rs().int().positive().optional()},qD={whenWas:V().optional()};bs(`op`,[H({op:As(`set`),path:GD,value:ls()}),H({op:As(`delete`),path:GD}),H({op:As(`addNode`),id:V(),node:Es(V(),ls())}),H({op:As(`removeNode`),id:V()}),H({op:As(`renameNode`),from:V(),to:V()}),H({op:As(`connect`),from:V(),to:V(),...KD}),H({op:As(`disconnect`),from:V(),to:V(),...qD}),H({op:As(`setEdge`),from:V(),to:V(),...KD,...qD})]);var JD=({title:e,children:t,cli:n,focusable:r=!1})=>(0,q.jsxs)(`div`,{className:i_.empty,children:[(0,q.jsx)(`p`,{className:i_.emptyTitle,"data-empty-title":r?``:void 0,tabIndex:r?-1:void 0,children:e}),(0,q.jsx)(`div`,{className:i_.emptyBody,children:t}),n===void 0?null:(0,q.jsx)(`div`,{className:i_.emptyCommand,children:(0,q.jsx)(cC,{command:n})})]});function YD(e){if(!e)return null;for(let t of e.elements){let e=t.tagName;if(e===`BUTTON`||e===`INPUT`){let e=t;if(e.type===`submit`)return e}}return null}var XD=`data-checked`,ZD=`data-unchecked`;function QD(e){return{checked(t){return e.indeterminate?{}:t?{[XD]:``}:{[ZD]:``}},...sx}}var $D=U.createContext({disabled:!1});function eO(){return U.useContext($D)}function tO(e,t,n,r=!0,i,a){let[o,s]=U.useState(),c=hg(i?`${i}-label`:void 0),l=!!a?.trim(),u=e??(l?void 0:t)??o;return W(()=>{let i=e||t||l||!r?void 0:nO(n.current,c);o!==i&&s(i)}),u}function nO(e,t){let n=rO(e);if(n)return!n.id&&t&&(n.id=t),n.id||void 0}function rO(e){if(!e)return;let t=e.parentElement;if(t&&t.tagName===`LABEL`)return t;let n=e.id;if(n){let t=e.nextElementSibling;if(t&&t.htmlFor===n)return t}let r=e.labels;return r&&r[0]}var iO=U.createContext(void 0);function aO(){return U.useContext(iO)}var oO=U.createContext(void 0);function sO(){let e=U.useContext(oO);if(e===void 0)throw Error(gc(14));return e}var cO=`data-parent`,lO=U.forwardRef(function(e,t){let{checked:n,className:r,defaultChecked:i=!1,"aria-labelledby":a,disabled:o=!1,form:s,id:c,indeterminate:l=!1,inputRef:u,name:d,onCheckedChange:f,parent:p=!1,readOnly:m=!1,render:h,required:g=!1,uncheckedValue:_,value:v,nativeButton:y=!1,style:b,...x}=e,{clearErrors:S}=px(),{disabled:C,name:w,setDirty:T,setFilled:E,setTouched:D,state:O,validationMode:k,validityData:A,validation:j}=ux(),M=eO(),{labelId:N,registerControlId:P,getDescriptionProps:F}=hx(),I=aO(),L=I?.allValues===void 0?void 0:I.parent,R=L!==void 0,ee=C||M.disabled||I?.disabled||o,z=w??d,te=v??z,ne=hg(),re=I?.registerControlId!==P,ie=gx({id:c||void 0,enabled:re}),ae=y?ie:ne,oe={};R&&(p?oe=L.getParentProps():te!==void 0&&(oe=L.getChildProps(te)));let{checked:se=n,indeterminate:ce=l,onCheckedChange:le,...ue}=oe,de=I?.value,fe=U.useRef(null),pe=Vx(ee,fe),{getButtonProps:me,buttonRef:he}=ev({disabled:ee,native:y}),ge=I?.validation??j,[_e,ve]=Sb({controlled:te!==void 0&&de!==void 0&&!p?de.includes(te):se,default:i,name:`Checkbox`,state:`checked`}),ye=R?!!se:_e,be=R&&ce||l;dx(fe,ne,_e,void 0,!I&&!ee,d);let B=L?.registerChildId,xe=U.useRef(null),Se=ge.registerInput,Ce=I?te:void 0,we=U.useCallback(e=>Se(e,{controlRef:fe,value:Ce}),[Se,Ce]),Te=Au(u,xe,p?void 0:we),Ee=tO(a,N,xe,!y,ie,x[`aria-label`]);W(()=>{xe.current&&(xe.current.indeterminate=be),I||E(_e)},[_e,be,I,E]),wx(_e,()=>{I||(S(z),T(_e!==A.initialValue),ge.change(_e))});let De=Pf({checked:_e,disabled:ee,form:s,name:p?void 0:z,id:y?void 0:ie,required:g,ref:Te,style:z?Xu:Yu,tabIndex:-1,type:`checkbox`,"aria-hidden":!0,onChange(e){if(e.nativeEvent.defaultPrevented)return;if(m){e.preventDefault();return}let t=e.currentTarget.checked,n=K(iu,e.nativeEvent);if(f?.(t,n),!n.isCanceled&&(le?.(t,n),!n.isCanceled&&(ve(t),te!==void 0&&I!==void 0&&!p&&!R))){let e=t?[...I.value,te]:I.value.filter(e=>e!==te);I.setValue(e,n)}},onClick(e){e.stopPropagation()},onFocus(){fe.current?.focus()}},v===void 0?mc:{value:(I?_e&&v:v)||``},F,e=>ge.getValidationProps(ee,e));U.useEffect(()=>{if(!L||te===void 0)return;let e=L.disabledStatesRef.current;return e.set(te,ee),()=>{e.delete(te)}},[L,ee,te]);let Oe=U.useMemo(()=>({...O,checked:ye,disabled:ee,readOnly:m,required:g,indeterminate:be}),[O,ye,ee,m,g,be]),ke=QD(Oe),Ae=qf(`span`,e,{state:Oe,ref:[he,fe,t],props:[{id:ae,role:`checkbox`,"aria-checked":be?`mixed`:ye,"aria-readonly":m||void 0,"aria-required":g||void 0,"aria-labelledby":Ee,[cO]:p?``:void 0,onFocus(){pe(!0)},onBlur(){let e=xe.current;e&&(D(!0),pe(!1),k===`onBlur`&&ge.commit(I?de:e.checked))},onKeyDown(e){if(e.key!==`Enter`||(e.preventBaseUIHandler(),e.defaultPrevented))return;let t=xe.current?.form??null,n=e.currentTarget,r=e.nativeEvent,i=e.preventDefault,a=r.preventDefault,o=!1;e.preventDefault=()=>{o=!0,i.call(e)},r.preventDefault=()=>{o=!0,a.call(r)},a.call(r),Kc(n).queueMicrotask(()=>{e.preventDefault=i,r.preventDefault=a,o||YD(t)?.click()})},onClick(e){if(m||ee)return;e.preventDefault();let t=xe.current;t&&$_(t,e)}},x,ue,me,F,e=>ge.getValidationProps(ee,e)],stateAttributesMapping:ke}),je=Ae.props.id;return W(()=>{if(B&&!p&&te!==void 0&&je!==void 0)return B(te,je)},[B,p,te,je]),(0,q.jsxs)(oO.Provider,{value:Oe,children:[Ae,!_e&&!I&&z&&!p&&_!==void 0&&(0,q.jsx)(`input`,{type:`hidden`,form:s,name:z,value:_,disabled:ee}),(0,q.jsx)(`input`,{...De,suppressHydrationWarning:!0})]})}),uO=U.forwardRef(function(e,t){let{render:n,className:r,style:i,keepMounted:a=!1,...o}=e,s=sO(),c=s.checked||s.indeterminate,{mounted:l,transitionStatus:u,setMounted:d}=Hp(c),f=U.useRef(null),p={...s,transitionStatus:u};qp({batch:!0,enabled:!c,open:c,ref:f,onComplete(){c||d(!1)}});let m={...QD(s),...Ol},h=a||l,g=qf(`span`,e,{ref:[t,f],state:p,stateAttributesMapping:m,props:o});return h?g:null}),dO=U.createContext(void 0);function fO(){let e=U.useContext(dO);if(e===void 0)throw Error(gc(63));return e}var pO=`data-checked`,mO=`data-unchecked`,hO={...sx,checked(e){return e?{[pO]:``}:{[mO]:``}}},gO=U.forwardRef(function(e,t){let{checked:n,className:r,defaultChecked:i,"aria-labelledby":a,form:o,id:s,inputRef:c,name:l,nativeButton:u=!1,onCheckedChange:d,readOnly:f=!1,required:p=!1,disabled:m=!1,render:h,uncheckedValue:g,value:_,style:v,...y}=e,{clearErrors:b}=px(),{state:x,setTouched:S,setDirty:C,validityData:w,setFilled:T,validationMode:E,disabled:D,name:O,validation:k}=ux(),{labelId:A}=hx(),j=D||m,M=O??l,N=U.useRef(null),P=Au(N,c,k.inputRef),F=U.useRef(null),I=Vx(j,F),L=hg(),R=gx({id:s}),ee=u?void 0:R,[z,te]=Sb({controlled:n,default:!!i,name:`Switch`,state:`checked`});dx(F,L,z,void 0,!j,l),W(()=>{T(z)},[z,T]),wx(z,()=>{b(M),C(z!==w.initialValue),k.change(z)});let{getButtonProps:ne,buttonRef:re}=ev({disabled:j,native:u}),ie=tO(a,A,N,!u,ee,y[`aria-label`]),ae={id:u?R:L,role:`switch`,"aria-checked":z,"aria-readonly":f||void 0,"aria-required":p||void 0,"aria-labelledby":ie,onFocus(){I(!0)},onBlur(){let e=N.current;e&&!j&&(S(!0),I(!1),E===`onBlur`&&k.commit(e.checked))},onClick(e){if(f||j)return;e.preventDefault();let t=N.current;t&&$_(t,e)}},oe={...k.getValidationProps(j),checked:z,disabled:j,form:o,id:ee,name:M,required:p,style:M?Xu:Yu,tabIndex:-1,type:`checkbox`,"aria-hidden":!0,ref:P,onChange(e){if(e.nativeEvent.defaultPrevented)return;if(f){e.preventDefault();return}let t=e.currentTarget.checked,n=K(iu,e.nativeEvent);d?.(t,n),!n.isCanceled&&te(t)},onClick(e){e.stopPropagation()},onFocus(){F.current?.focus()},..._===void 0?mc:{value:_}},se=U.useMemo(()=>({...x,checked:z,disabled:j,readOnly:f,required:p}),[x,z,j,f,p]),ce=qf(`span`,e,{state:se,ref:[t,F,re],props:[ae,y,ne,e=>k.getValidationProps(j,e)],stateAttributesMapping:hO});return(0,q.jsxs)(dO.Provider,{value:se,children:[ce,!z&&M&&g!==void 0&&(0,q.jsx)(`input`,{type:`hidden`,form:o,name:M,value:g,disabled:j}),(0,q.jsx)(`input`,{...oe,suppressHydrationWarning:!0})]})}),_O=U.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e;return qf(`span`,e,{state:fO(),ref:t,stateAttributesMapping:hO,props:a})}),vO=({label:e,checked:t,onChange:n,disabled:r=!1,describedBy:i})=>(0,q.jsxs)(`label`,{className:nC.toggle,children:[(0,q.jsx)(lO,{"aria-describedby":i,checked:t,className:nC.box,disabled:r,onCheckedChange:e=>{n(e)},children:(0,q.jsx)(uO,{className:nC.mark,children:(0,q.jsx)(cy,{})})}),e]}),yO=({label:e,checked:t,onChange:n,disabled:r=!1})=>(0,q.jsxs)(`label`,{className:nC.toggle,children:[(0,q.jsx)(gO,{checked:t,className:nC.switch,disabled:r,onCheckedChange:e=>{n(e)},children:(0,q.jsx)(_O,{className:nC.thumb})}),e]});function bO(e){return e==null||e.hasAttribute(`disabled`)||e.getAttribute(`aria-disabled`)===`true`}var xO=U.createContext(void 0),SO=U.createContext(void 0);function CO(){let e=U.useContext(xO);if(e===void 0)throw Error(gc(60));return e}function wO(){let e=U.useContext(SO);if(e===void 0)throw Error(gc(61));return e}var TO={id:e=>e.id,labelId:e=>e.labelId,modal:e=>e.modal,multiple:e=>e.multiple,disabled:e=>e.disabled,readOnly:e=>e.readOnly,required:e=>e.required,highlightItemOnHover:e=>e.highlightItemOnHover,items:e=>e.items,itemToStringLabel:e=>e.itemToStringLabel,isItemEqualToValue:e=>e.isItemEqualToValue,value:e=>e.value,hasSelectedValue:e=>{let{value:t,multiple:n,itemToStringValue:r}=e;return t==null?!1:n&&Array.isArray(t)?t.length>0:Qb(t,r)!==``},hasNullItemLabel:(e,t)=>t?Xb(e.items):!1,open:e=>e.open,mounted:e=>e.mounted,forceMount:e=>e.forceMount,transitionStatus:e=>e.transitionStatus,openMethod:e=>e.openMethod,activeIndex:e=>e.activeIndex,selectedIndex:e=>e.selectedIndex,isActive:(e,t)=>e.activeIndex===t,isSelected:(e,t)=>{let n=e.isItemEqualToValue,r=e.value;return e.multiple?Array.isArray(r)&&r.some(e=>Rb(t,e,n)):Rb(t,r,n)},isSelectedByFocus:(e,t)=>e.selectedIndex===t,popupProps:e=>e.popupProps,triggerProps:e=>e.triggerProps,itemRoot:e=>e.itemRoot,triggerElement:e=>e.triggerElement,positionerElement:e=>e.positionerElement,listElement:e=>e.listElement,popupSide:e=>e.popupSide,scrollUpArrowVisible:e=>e.scrollUpArrowVisible,scrollDownArrowVisible:e=>e.scrollDownArrowVisible,hasScrollArrows:e=>e.hasScrollArrows};function EO(e,t){return Math.max(0,e-t)}function DO(e,t){if(t<=0)return 0;let n=E_(e,0,t),r=n,i=t-n,a=r<=1,o=i<=1;return a&&o?r<=i?0:t:a?0:o?t:n}function OO(e){let{id:t,value:n,defaultValue:r=null,onValueChange:i,open:a,defaultOpen:o=!1,onOpenChange:s,name:c,form:l,autoComplete:u,disabled:d=!1,readOnly:f=!1,required:p=!1,modal:m=!0,actionsRef:h,inputRef:g,onOpenChangeComplete:_,items:v,multiple:y=!1,itemToStringLabel:b,itemToStringValue:x,isItemEqualToValue:S=Lb,highlightItemOnHover:C=!0,children:w}=e,{clearErrors:T}=px(),{setDirty:E,setTouched:D,setFocused:O,validityData:k,setFilled:A,name:j,disabled:M,validation:N,validationMode:P}=ux(),F=gx({id:t}),I=M||d,L=j??c,[R,ee]=Sb({controlled:n,default:y?r??pc:r,name:`Select`,state:`value`}),[z,te]=Sb({controlled:a,default:o,name:`Select`,state:`open`}),ne=U.useRef([]),re=U.useRef([]),ie=U.useRef(null),ae=U.useRef(null),oe=U.useRef(0),se=U.useRef(null),ce=U.useRef([]),le=U.useRef(!1),ue=U.useRef(null),de=U.useRef(null),fe=U.useRef({allowSelectedMouseUp:!1,allowUnselectedMouseUp:!1,dragY:0}),pe=U.useRef(!1),me=U.useRef(R),{openMethod:he,triggerProps:ge}=Ex(z),_e=ic(()=>new Sm({id:F,labelId:void 0,modal:m,multiple:y,disabled:I,readOnly:f,required:p,highlightItemOnHover:C,itemToStringLabel:b,itemToStringValue:x,isItemEqualToValue:S,value:R,open:z,mounted:z,transitionStatus:void 0,items:v,forceMount:!1,openMethod:null,activeIndex:null,selectedIndex:null,popupProps:mc,triggerProps:mc,itemRoot:{props:mc,multiple:y,disabled:I,readOnly:f,isItemEqualToValue:S},triggerElement:null,positionerElement:null,listElement:null,popupSide:null,scrollUpArrowVisible:!1,scrollDownArrowVisible:!1,hasScrollArrows:!1},{setValue:fc,setOpen:fc,handleScrollArrowVisibility:fc,onOpenChangeComplete:fc,listRef:ne,popupRef:ie,scrollHandlerRef:ae,scrollArrowsMountedCountRef:oe,valueRef:se,valuesRef:ce,labelsRef:re,typingRef:le,selectionRef:fe,firstItemTextRef:ue,selectedItemTextRef:de,alignItemWithTriggerActiveRef:pe,initialValueRef:me},TO)).current,[ve,ye]=U.useState(!1),{mounted:be,transitionStatus:B,forceUnmount:xe}=Jp({open:z,ref:ie,preventUnmountOnClose:ve,setPreventUnmountOnClose:ye,onUnmount(){_e.update({activeIndex:null,openMethod:null,scrollUpArrowVisible:!1,scrollDownArrowVisible:!1}),_?.(!1)}}),Se=_e.useState(`activeIndex`),Ce=_e.useState(`selectedIndex`),we=_e.useState(`triggerElement`),Te=_e.useState(`positionerElement`),Ee=Qg(he),De=he??Ee,Oe=U.useMemo(()=>y?``:Qb(R,x),[y,R,x]),ke=U.useMemo(()=>y&&Array.isArray(R)?R.map(e=>Qb(e,x)):Qb(R,x),[y,R,x]);dx(Iu(we),F,R,J(()=>ke),!I,c);let Ae=y?Array.isArray(R)&&R.length>0:R!=null&&Oe!==``;W(()=>{A(Ae)},[Ae,A]),W(function(){let e=Ub(ce.current,R,S,y);e===null&&(de.current=null),!z&&_e.set(`selectedIndex`,e)},[y,z,R,S,_e]),wx(R,()=>{T(L),E(zb(R,k.initialValue,S)),N.change(R)});let je=J((e,t)=>{let n=t,r=nm(n);s?.(e,n),!t.isCanceled&&(e||ye(r()),te(e),e||t.reason!==`focus-out`&&t.reason!==`outside-press`||(D(!0),O(!1),P===`onBlur`&&N.commit(R)))});U.useImperativeHandle(h,()=>({unmount:xe,close:()=>{_e.state.open&&je(!1,K(Su))}}),[xe,je,_e]);let Me=J((e,t)=>{i?.(e,t),!t.isCanceled&&ee(e)}),Ne=J(e=>{let t=EO(e.scrollHeight,e.clientHeight),n=DO(e.scrollTop,t),r=n>0,i=n<t;_e.set(`scrollUpArrowVisible`,r),_e.set(`scrollDownArrowVisible`,i)}),Pe=Nm({open:z,onOpenChange:je,elements:{reference:we,floating:Te}}),Fe=Pp(Pe,{enabled:!I,event:`mousedown`}),Ie=Bp(Pe),Le=Xm(Pe,{enabled:!I,listRef:ne,activeIndex:Se,selectedIndex:Ce,disabledIndices:pc,onNavigate(e){(e!==null||z)&&_e.set(`activeIndex`,e)},focusItemOnHover:C}),Re=Zm(Pe,{enabled:!I&&(z||!f&&!y),listRef:re,activeIndex:Se,selectedIndex:Ce,disabledIndices:e=>bO(ne.current[e]),onMatch(e){z?_e.set(`activeIndex`,e):Me(ce.current[e],K(iu))},onTyping(e){le.current=e}}),ze=U.useMemo(()=>Pf(Re.reference,Le.reference,Ie.reference,Fe.reference,ge),[Fe.reference,Re.reference,Le.reference,Ie.reference,ge]),Be=U.useMemo(()=>Pf(Yp,Re.floating,Le.floating,Ie.floating),[Re.floating,Le.floating,Ie.floating]),Ve=Le.item??mc,He=U.useMemo(()=>({props:Ve,multiple:y,disabled:I,readOnly:f,isItemEqualToValue:S}),[Ve,y,I,f,S]);_e.useContextCallback(`setValue`,Me),_e.useContextCallback(`setOpen`,je),_e.useContextCallback(`handleScrollArrowVisibility`,Ne),_e.useContextCallback(`onOpenChangeComplete`,_),Cb(()=>{_e.update({popupProps:Be,triggerProps:ze,itemRoot:He})}),_e.useSyncedValues({id:F,modal:m,multiple:y,disabled:I,readOnly:f,required:p,highlightItemOnHover:C,value:R,open:z,mounted:be,transitionStatus:B,popupProps:Be,triggerProps:ze,itemRoot:He,items:v,itemToStringLabel:b,itemToStringValue:x,isItemEqualToValue:S,openMethod:De});let Ue=Au(g,N.inputRef),We=y?void 0:L,Ge=U.useMemo(()=>!y||!Array.isArray(R)||!L?null:R.map(e=>{let t=Qb(e,x);return(0,q.jsx)(`input`,{type:`hidden`,form:l,name:L,value:t,disabled:I},t)}),[y,R,l,L,x,I]);return(0,q.jsxs)(xO.Provider,{value:_e,children:[(0,q.jsx)(SO.Provider,{value:Pe,children:w}),(0,q.jsx)(`input`,{...N.getValidationProps(I,{onFocus(){_e.state.triggerElement?.focus({focusVisible:!0})},onChange(e){if(e.nativeEvent.defaultPrevented||I||f)return;let t=e.currentTarget.value,n=K(iu,e.nativeEvent);function r(){if(y)return;let e=t.toLowerCase(),r=ce.current.findIndex(t=>Qb(t,x).toLowerCase()===e||Zb(t,b).toLowerCase()===e);r===-1&&(r=ce.current.findIndex((t,n)=>{let r=re.current[n];return r!=null&&r.toLowerCase()===e}));let i=ce.current[r];i!=null&&Me(i,n)}_e.set(`forceMount`,!0),queueMicrotask(r)}}),id:F&&We==null?`${F}-hidden-input`:void 0,form:l,name:We,autoComplete:u,value:Oe,disabled:I,required:p&&!(y&&Ae),readOnly:f,ref:Ue,style:L?Xu:Yu,tabIndex:-1,"aria-hidden":!0,suppressHydrationWarning:!0}),Ge]})}var kO=U.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,o=a;delete o.id;let s=ux(),c=CO(),l=c.useState(`triggerElement`),u=c.useState(`id`),d=Nx({id:Ix(u),fallbackControlId:l?.id??u,setLabelId(e){let t=typeof e==`function`?e(c.state.labelId):e;c.set(`labelId`,t)}});return qf(`div`,e,{ref:t,state:s.state,props:[d,a],stateAttributesMapping:sx})}),AO=`data-popup-side`,jO=400,MO={...Bl,...sx,popupSide:e=>e?{[AO]:e}:null,value:()=>null},NO=U.forwardRef(function(e,t){let{render:n,className:r,id:i,disabled:a=!1,nativeButton:o=!0,style:s,...c}=e,{setTouched:l,validationMode:u,validation:d,state:f,disabled:p}=ux(),{labelId:m}=hx(),h=CO(),g=h.useState(`readOnly`),_=h.useState(`required`),v=h.useState(`disabled`),y=p||v||a,b=h.useState(`open`),x=h.useState(`mounted`),S=h.useState(`value`),C=h.useState(`triggerProps`),w=h.useState(`positionerElement`),T=h.useState(`listElement`),E=h.useState(`popupSide`),D=h.useState(`id`),O=h.useState(`labelId`),k=h.useState(`hasSelectedValue`),A=x&&w?E:null,j=i??D,M=Lx(m,O);gx({id:i});let N=Iu(w),P=U.useRef(null),F=Vx(y,P),{getButtonProps:I,buttonRef:L}=ev({disabled:y,native:o}),R=h.useStateSetter(`triggerElement`),ee=Sc(),z=Sc(),te=Sc();U.useEffect(()=>{if(b)return te.start(jO,()=>{h.context.selectionRef.current.allowUnselectedMouseUp=!0,h.context.selectionRef.current.allowSelectedMouseUp=!0}),()=>{te.clear()};h.context.selectionRef.current={allowSelectedMouseUp:!1,allowUnselectedMouseUp:!1,dragY:0},z.clear()},[b,h,z,te]);let ne=Pf(C,{id:j,role:`combobox`,"aria-expanded":b,"aria-haspopup":`listbox`,"aria-controls":b?T?.id??Zl(w)?.id:void 0,"aria-labelledby":M,"aria-readonly":g||void 0,"aria-required":_||void 0,tabIndex:y?-1:0,onFocus(e){F(!0),b&&h.context.alignItemWithTriggerActiveRef.current&&h.context.setOpen(!1,K(iu,e.nativeEvent)),ee.start(0,()=>{h.set(`forceMount`,!0)})},onBlur(e){G(w,e.relatedTarget)||(l(!0),F(!1),u===`onBlur`&&d.commit(S))},onMouseDown(e){if(b)return;let t=qu(e.currentTarget);function n(e){if(!P.current)return;let t=e.target;G(P.current,t)||G(N.current,t)||tS(e,P.current)||h.context.setOpen(!1,K(yu,e))}z.start(0,()=>{t.addEventListener(`mouseup`,n,{once:!0})})}},c,I),re=d.getValidationProps(y,ne);re.role=`combobox`;let ie={...f,open:b,disabled:y,value:S,readOnly:g,popupSide:A,placeholder:!k};return qf(`button`,e,{ref:[t,P,L,R],state:ie,stateAttributesMapping:MO,props:re})}),PO={value:()=>null},FO=U.forwardRef(function(e,t){let{className:n,render:r,children:i,placeholder:a,style:o,...s}=e,c=CO(),l=c.useState(`value`),u=c.useState(`items`),d=c.useState(`itemToStringLabel`),f=c.useState(`hasSelectedValue`),p=!f&&a!=null&&i==null,m=c.useState(`hasNullItemLabel`,p),h={value:l,placeholder:!f},g=null;return g=typeof i==`function`?i(l):i??(p&&!m?a:Array.isArray(l)?ex(l,u,d):$b(l,u,d)),qf(`span`,e,{state:h,ref:[t,c.context.valueRef],props:[{children:g},s],stateAttributesMapping:PO})}),IO=U.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e;return qf(`span`,e,{state:{open:CO().useState(`open`)},ref:t,props:[{"aria-hidden":!0,children:`▼`},a],stateAttributesMapping:zl})}),LO=U.forwardRef(function(e,t){let n=CO(),r=n.useState(`mounted`),i=n.useState(`forceMount`);return r||i?(0,q.jsx)(mp,{ref:t,...e}):null}),RO=U.createContext(void 0);function zO(){let e=U.useContext(RO);if(!e)throw Error(gc(59));return e}function BO(e,t){e&&Object.assign(e.style,t)}var VO={position:`relative`,maxHeight:`100%`,overflowX:`hidden`,overflowY:`auto`},HO={position:`fixed`},UO=U.forwardRef(function(e,t){let{anchor:n,className:r,render:i,positionMethod:a,side:o,align:s,sideOffset:c,alignOffset:l,collisionBoundary:u=`clipping-ancestors`,collisionPadding:d,arrowPadding:f,sticky:p,disableAnchorTracking:m,alignItemWithTrigger:h=!0,collisionAvoidance:g=op,style:_,...v}=e,y=CO(),b=wO(),x=y.useState(`open`),S=y.useState(`mounted`),C=y.useState(`modal`),w=y.useState(`value`),T=y.useState(`openMethod`),E=y.useState(`positionerElement`),D=y.useState(`triggerElement`),O=y.useState(`isItemEqualToValue`),k=y.useState(`transitionStatus`),A=U.useRef(null),j=U.useRef(null),[M,N]=U.useState(h),P=S&&M&&T!==`touch`;!S&&M!==h&&N(h),U.useImperativeHandle(y.context.alignItemWithTriggerActiveRef,()=>P),LS((P||C)&&x,T===`touch`,E,D);let F=Ug({anchor:n,floatingRootContext:b,positionMethod:a,mounted:S,side:o,sideOffset:c,align:s,alignOffset:l,arrowPadding:f,collisionBoundary:u,collisionPadding:d,sticky:p,disableAnchorTracking:m??P,collisionAvoidance:g,keepMounted:!0}),I=P?`none`:F.side,L=P?HO:F.positionerStyles,R={open:x,side:I,align:F.align,anchorHidden:F.anchorHidden};W(()=>{y.set(`popupSide`,F.side)},[y,F.side]);let ee=qg(e,R,{styles:L,transitionStatus:k,props:v,refs:[t,y.useStateSetter(`positionerElement`)],hidden:!S,inert:!x}),z=U.useRef(0),te=J(e=>{if(y.context.valuesRef.current.length===0)return;let t=z.current;z.current=e.size;let n=K(iu);if(t!==0&&!y.state.multiple&&w!==null&&Vb(y.context.valuesRef.current,w,O)===-1){let e=y.context.initialValueRef.current,t=e!=null&&Vb(y.context.valuesRef.current,e,O)!==-1?e:null;y.context.setValue(t,n),t===null&&(y.set(`selectedIndex`,null),y.context.selectedItemTextRef.current=null)}if(t!==0&&y.state.multiple&&Array.isArray(w)){let e=w.filter(e=>Vb(y.context.valuesRef.current,e,O)!==-1);e.length!==w.length&&(y.context.setValue(e,n),e.length===0&&(y.set(`selectedIndex`,null),y.context.selectedItemTextRef.current=null))}if(x&&P){y.update({scrollUpArrowVisible:!1,scrollDownArrowVisible:!1});let e={height:``};BO(E,e),BO(y.context.popupRef.current,e)}}),ne=U.useMemo(()=>({...F,side:I,alignItemWithTriggerActive:P,setControlledAlignItemWithTrigger:N,scrollUpArrowRef:A,scrollDownArrowRef:j}),[F,I,P,N]);return(0,q.jsx)(uS,{elementsRef:y.context.listRef,labelsRef:y.context.labelsRef,onMapChange:te,children:(0,q.jsxs)(RO.Provider,{value:ne,children:[S&&C&&(0,q.jsx)(wS,{inert:Zg(!x),cutout:D}),ee]})})}),WO=`base-ui-disable-scrollbar`,GO={className:WO,getElement(e){return(0,q.jsx)(`style`,{nonce:e,href:WO,precedence:`base-ui:low`,children:`.${WO}{scrollbar-width:none}.${WO}::-webkit-scrollbar{display:none}`})}},KO=U.createContext(void 0);function qO(e){let t=U.useContext(KO);if(t===void 0&&!e)throw Error(gc(69));return t}var JO=`--transform-origin`,YO={...Vl,...Ol},XO=U.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,...o}=e,s=CO(),c=s.useState(`multiple`),l=s.useState(`readOnly`),u=s.useState(`highlightItemOnHover`),d=wO(),{side:f,align:p,alignItemWithTriggerActive:m,isPositioned:h,setControlledAlignItemWithTrigger:g}=zO(),_=qO(!0)!=null,v=kg(),{nonce:y,disableStyleElements:b}=k(),x=s.useState(`id`),S=s.useState(`open`),C=s.useState(`openMethod`),w=s.useState(`mounted`),T=s.useState(`popupProps`),E=s.useState(`transitionStatus`),D=s.useState(`triggerElement`),O=s.useState(`positionerElement`),A=s.useState(`listElement`),j=U.useRef(!1),M=U.useRef(!1),N=U.useRef({}),P=Ku(),F=J(e=>{if(!O||!s.context.popupRef.current||!M.current)return;let t=O.style.top===`0px`,n=O.style.bottom===`0px`;if(j.current||!m||!t&&!n){s.context.handleScrollArrowVisibility(e);return}let r=$O(O),i=ek(O.getBoundingClientRect().height,`y`,r),a=qu(O),o=Kc(O),c=o.getComputedStyle(O),l=parseFloat(c.marginTop),u=parseFloat(c.marginBottom),d=ZO(o.getComputedStyle(s.context.popupRef.current)),f=Math.min(a.documentElement.clientHeight-l-u,d),p=e.scrollTop,h=QO(e),g=null,_=e=>{O.style.height=`${e}px`},v=t?h-p:p,y=Math.min(i+v,f);if(v<=1){let n=E_(v,0,f-i);n>0&&_(i+n),e.scrollTop=t?h:0,f-(i+n)<=1&&(j.current=!0),s.context.handleScrollArrowVisibility(e);return}f-y>1?g=t?1/0:0:n&&p<h&&(g=p-(v-(i+v-f)));let b=Math.ceil(y);if(b!==0&&_(b),g!=null){let t=E_(g,0,QO(e));Math.abs(e.scrollTop-t)>1&&(e.scrollTop=t)}b>=f-1&&(j.current=!0),s.context.handleScrollArrowVisibility(e)});U.useImperativeHandle(s.context.scrollHandlerRef,()=>F,[F]),qp({open:S,ref:s.context.popupRef,onComplete(){S&&s.context.onOpenChangeComplete(!0)}});let I={open:S,transitionStatus:E,side:f,align:p};W(()=>{O&&s.context.popupRef.current&&!Object.keys(N.current).length&&(N.current={top:O.style.top||`0`,left:O.style.left||`0`,right:O.style.right,height:O.style.height,bottom:O.style.bottom,minHeight:O.style.minHeight,maxHeight:O.style.maxHeight,marginTop:O.style.marginTop,marginBottom:O.style.marginBottom})},[s,O]),W(()=>{S||m||(M.current=!1,j.current=!1,BO(O,N.current))},[S,m,O]),W(()=>{let e=s.context.popupRef.current;if(!S||!D||!O||!e||m&&!h||s.state.transitionStatus===`ending`)return;if(M.current=!0,e.style.removeProperty(JO),!m){P.request(()=>s.context.handleScrollArrowVisibility(A||e));return}let t=rk(e);try{let t=s.context.selectedItemTextRef.current;t?.isConnected||(t=!s.select(`hasSelectedValue`)&&s.context.firstItemTextRef.current?.isConnected?s.context.firstItemTextRef.current:null);let n=s.context.valueRef.current,r=Kc(O),i=r.getComputedStyle(O),a=r.getComputedStyle(e),o=qu(D),c=$O(D),l=tk(D.getBoundingClientRect(),c),d=tk(O.getBoundingClientRect(),c),f=l.height,p=A||e,m=p.scrollHeight,h=parseFloat(a.borderBottomWidth),_=parseFloat(i.marginTop)||10,y=parseFloat(i.marginBottom)||10,b=parseFloat(i.minHeight)||100,x=ZO(a),S=o.documentElement.clientHeight-_-y,C=o.documentElement.clientWidth,w=S-l.bottom+f,T,E=v===`rtl`?l.right-d.width:l.left,k=0;if(t&&n){let e=tk(n.getBoundingClientRect(),c);T=tk(t.getBoundingClientRect(),c),E=d.left+(v===`rtl`?e.right-T.right:e.left-T.left);let r=e.top-l.top+e.height/2;k=T.top-d.top+T.height/2-r}let M=w+k+y+h,P=Math.min(S,M),F=S-_-y,I=M-P,L=C-5;O.style.left=`${E_(E,5,L-d.width)}px`,O.style.height=`${P}px`,O.style.maxHeight=`none`,O.style.marginTop=`${_}px`,O.style.marginBottom=`${y}px`,e.style.height=`100%`;let R=QO(p),ee=I>=R-1;ee&&(P=Math.min(S,d.height)-(I-R));let z=l.top<20||l.bottom>S-20||Math.ceil(P)+1<Math.min(m,b),te=(r.visualViewport?.scale??1)!==1&&Pc;if(z||te){BO(O,N.current),g(!1);return}let ne=Math.max(b,P);if(ee){let e=Math.max(0,S-M);O.style.top=d.height>=F?`0`:`${e}px`,O.style.height=`${P}px`,p.scrollTop=QO(p)}else O.style.bottom=`0`,p.scrollTop=I;if(T){let t=d.top,n=d.height,r=T.top+T.height/2,i=E_(n>0?(r-t)/n*100:50,0,100);e.style.setProperty(JO,`50% ${i}%`)}(ne===S||P>=x)&&(j.current=!0),s.context.handleScrollArrowVisibility(p),u&&s.state.selectedIndex===null&&s.state.activeIndex===null&&s.context.listRef.current[0]!=null&&s.set(`activeIndex`,0)}finally{t()}},[s,S,O,D,m,g,P,A,u,v,h]),U.useEffect(()=>{if(!m||!O||!S)return;let e=Kc(O);function t(e){s.context.setOpen(!1,K(Cu,e))}return Ou(e,`resize`,t)},[s,m,O,S]);let L={...A?{role:`presentation`}:{role:`listbox`,"aria-multiselectable":c||void 0,"aria-readonly":l||void 0,id:`${x}-list`},onKeyDown(e){_&&CC.has(e.key)&&e.stopPropagation()},onScroll(e){A||F(e.currentTarget)},...m&&{style:A?{height:`100%`}:VO},className:!A&&m?GO.className:void 0},R=qf(`div`,e,{ref:[t,s.context.popupRef],state:I,stateAttributesMapping:YO,props:[T,L,Kg(E),o]});return(0,q.jsxs)(U.Fragment,{children:[!b&&GO.getElement(y),(0,q.jsx)(Np,{context:d,modal:!1,disabled:!w,openInteractionType:C,returnFocus:a,restoreFocus:!0,children:R})]})});function ZO(e){let t=e.maxHeight;return t.endsWith(`px`)&&parseFloat(t)||1/0}function QO(e){return EO(e.scrollHeight,e.clientHeight)}function $O(e){return Hh.getScale(e)}function ek(e,t,n){return e/n[t]}function tk(e,t){return wd({x:ek(e.x,`x`,t),y:ek(e.y,`y`,t),width:ek(e.width,`x`,t),height:ek(e.height,`y`,t)})}var nk=[[`transform`,`none`],[`scale`,`1`],[`translate`,`0 0`]];function rk(e){let{style:t}=e,n={};for(let[e,r]of nk)n[e]=t.getPropertyValue(e),t.setProperty(e,r,`important`);return()=>{for(let[e]of nk){let r=n[e];r?t.setProperty(e,r):t.removeProperty(e)}}}var ik=U.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,o=CO(),s=o.useState(`multiple`),c=o.useState(`readOnly`),{alignItemWithTriggerActive:l}=zO(),u=o.useState(`hasScrollArrows`),d=o.useState(`openMethod`),f={id:`${o.useState(`id`)}-list`,role:`listbox`,"aria-multiselectable":s||void 0,"aria-readonly":c||void 0,onScroll(e){o.context.scrollHandlerRef.current?.(e.currentTarget)},...l&&{style:VO},className:u&&d!==`touch`?GO.className:void 0};return qf(`div`,e,{ref:[t,o.useStateSetter(`listElement`)],props:[f,a]})}),ak=U.createContext(void 0);function ok(){let e=U.useContext(ak);if(!e)throw Error(gc(57));return e}var sk=U.memo(U.forwardRef(function(e,t){let{render:n,className:r,style:i,value:a=null,label:o,disabled:s=!1,nativeButton:c=!1,...l}=e,u=U.useRef(null),d=GS({guess:!0,label:o,textRef:u}),f=CO(),{props:p,multiple:m,disabled:h,readOnly:g,isItemEqualToValue:_}=f.useState(`itemRoot`),v=h||s,y=f.useState(`isActive`,d.index),b=f.useState(`open`),x=f.useState(`isSelected`,a),S=f.useState(`isSelectedByFocus`,d.index),C=d.index,w=U.useRef(null);W(()=>{let e=f.context.valuesRef.current;return e[C]=a,()=>{delete e[C]}},[C,a,f]),W(()=>{let e=f.state.value,t=f.state.selectedIndex,n=t,r;m&&Array.isArray(e)?(n=Wb(C,a,f.context.valuesRef.current,e,_,t),r=n===C,C===t&&!r&&(f.context.selectedItemTextRef.current=null)):(r=e!==void 0&&Rb(a,e,_),r&&(n=C)),f.set(`selectedIndex`,n),r&&u.current&&(f.context.selectedItemTextRef.current=u.current)},[C,m,_,f,a]);let T=U.useRef(`mouse`),E=U.useRef(!1),{getButtonProps:D,buttonRef:O}=ev({disabled:v,focusableWhenDisabled:!0,native:c,composite:!0}),k={disabled:v,selected:x,highlighted:y};function A(e){if(h||g)return;let t=f.state.value;if(m){let n=Array.isArray(t)?t:[],r=x?Gb(n,a,_):[...n,a];f.context.setValue(r,K(lu,e))}else f.context.setValue(a,K(lu,e)),f.context.setOpen(!1,K(lu,e))}function j(){f.context.selectionRef.current.dragY=0}let M={role:`option`,"aria-selected":x,tabIndex:b&&y?0:-1,onKeyDown(e){f.set(`activeIndex`,C),e.key===` `&&f.context.typingRef.current&&e.preventDefault()},onClick(e){let t=T.current!==`touch`,n=e.nativeEvent.pointerType,r=t&&Bc(e.nativeEvent)&&(n!==void 0||y),i=t&&!r&&!E.current;E.current=!1,!(v||i)&&A(e.nativeEvent)},onPointerEnter(e){T.current=e.pointerType},onPointerMove(e){if(e.pointerType===`mouse`&&e.buttons===1){let t=f.context.selectionRef.current;t.dragY+=e.movementY,t.dragY**2>=64&&(t.allowUnselectedMouseUp=!0)}},onPointerDown(e){T.current=e.pointerType,E.current=!0,j()},onMouseUp(){if(j(),v||T.current===`touch`||E.current)return;let e=!f.context.selectionRef.current.allowSelectedMouseUp&&x,t=!f.context.selectionRef.current.allowUnselectedMouseUp&&!x;e||t||(E.current=!0,w.current?.click(),E.current=!1)}},N=qf(`div`,e,{ref:[O,t,d.ref,w],state:k,props:[p,M,l,D]}),P=U.useMemo(()=>({selected:x,index:C,textRef:u,selectedByFocus:S}),[x,C,u,S]);return(0,q.jsx)(ak.Provider,{value:P,children:N})})),ck=U.forwardRef(function(e,t){let{selected:n}=ok();return e.keepMounted||n?(0,q.jsx)($S,{...e,selected:n,ref:t}):null}),lk=U.memo(U.forwardRef(function(e,t){let{index:n,textRef:r,selectedByFocus:i}=ok(),a=CO(),{render:o,className:s,style:c,...l}=e;return qf(`div`,e,{ref:[U.useCallback(e=>{e&&(n===0&&(a.context.firstItemTextRef.current=e),i&&(a.context.selectedItemTextRef.current=e))},[a,n,i]),t,r],props:l})})),uk=({children:e})=>(0,q.jsx)(`span`,{className:nC.visuallyHidden,children:e}),dk=({label:e,unseen:t,options:n,value:r,onChange:i,describedBy:a})=>(0,q.jsxs)(OO,{items:n,onValueChange:e=>{e!==null&&i(e)},value:r,children:[(0,q.jsxs)(`div`,{className:nC.field,children:[(0,q.jsxs)(kO,{className:nC.label,children:[e,t===void 0?null:(0,q.jsx)(uk,{children:t})]}),(0,q.jsxs)(NO,{"aria-describedby":a,className:nC.control,children:[(0,q.jsx)(FO,{}),(0,q.jsx)(IO,{className:nC.icon,children:(0,q.jsx)(ly,{})})]})]}),(0,q.jsx)(LO,{children:(0,q.jsx)(UO,{align:`start`,alignItemWithTrigger:!1,className:o_.positioner,sideOffset:4,children:(0,q.jsx)(XO,{className:o_.popup,children:(0,q.jsx)(ik,{"aria-label":e,children:n.map(e=>(0,q.jsxs)(sk,{className:o_.item,value:e.value,children:[(0,q.jsx)(lk,{children:e.label}),(0,q.jsx)(ck,{className:nC.icon,children:(0,q.jsx)(cy,{})})]},e.value))})})})})]}),fk=U.forwardRef(function(e,t){let{render:n,className:r,id:i,name:a,value:o,disabled:s=!1,onValueChange:c,defaultValue:l,autoFocus:u=!1,style:d,...f}=e,{state:p,name:m,disabled:h,setTouched:g,setDirty:_,validityData:v,setFilled:y,validationMode:b,validation:x}=ux(),{clearErrors:S,elementRef:C,submitCountRef:w}=px(),T=h||s,E=m??a,D={...p,disabled:T},{labelId:O}=hx(),k=gx({id:i}),A=o!==void 0,j=o==null?void 0:String(o),M=J(()=>x.inputRef.current?.value);dx(x.inputRef,k,j,M,!T,a),W(()=>{let e=j??x.inputRef.current?.value;e!==void 0&&y(e!==``)},[j,l,x.inputRef,y]),wx(j,()=>{j!==void 0&&(S(E),_(j!==(v.initialValue??``)),x.change(j))});let N=U.useRef(null),P=Vx(T,N),F=Sc();return qf(`input`,e,{ref:[t,N],state:D,props:[{id:k,disabled:T,name:E,ref:x.inputRef,"aria-labelledby":O,autoFocus:u,...A?{value:o}:{defaultValue:l},onChange(e){let t=e.currentTarget.value,n=K(iu,e.nativeEvent);c?.(t,n),!A&&(_(t!==(v.initialValue??``)),y(t!==``),!e.nativeEvent.defaultPrevented&&!n.isCanceled&&(S(E),x.change(t)))},onFocus(){P(!0)},onBlur(e){if(g(!0),P(!1),b===`onBlur`){let t=e.currentTarget.value;x.commit(t),A&&queueMicrotask(()=>{let e=x.inputRef.current?.value;e!==void 0&&e!==t&&e!==(v.initialValue??``)&&x.commit(e)})}},onKeyDown(e){if(e.currentTarget.tagName===`INPUT`&&e.key===`Enter`){g(!0);let t=e.currentTarget.value,n=e.currentTarget.form;if(n&&n===C.current&&!e.defaultPrevented){let t=e.currentTarget,n=w.current;F.start(0,()=>{w.current===n&&x.commit(t.value)})}else x.commit(t)}}},f,e=>x.getValidationProps(T,e)],stateAttributesMapping:sx})}),pk=U.forwardRef(function(e,t){return(0,q.jsx)(fk,{ref:t,...e})}),mk=({label:e,unseen:t,value:n,onChange:r,onCommit:i,multiline:a=!1,rows:o=4,description:s,required:c=!1,type:l=`text`})=>{let u=(0,U.useId)(),d=`${u}-description`;return(0,q.jsxs)(`div`,{className:nC.field,children:[(0,q.jsxs)(`label`,{className:nC.label,htmlFor:u,children:[e,t===void 0?null:(0,q.jsx)(uk,{children:t}),c?` (required)`:``]}),(0,q.jsx)(`div`,{className:nC.group,children:(0,q.jsx)(pk,{"aria-describedby":s===void 0?void 0:d,className:nC.input,id:u,onBlur:i,onKeyDown:e=>{e.key===`Enter`&&!a&&i?.()},onValueChange:e=>{r(e)},render:a?(0,q.jsx)(`textarea`,{rows:o}):void 0,required:c,type:a?void 0:l,value:n})}),s===void 0?null:(0,q.jsx)(`p`,{className:nC.hint,id:d,children:(0,q.jsx)(r_,{text:s})})]})},hk={panel:`_panel_1pbue_7`,tools:`_tools_1pbue_19`,main:`_main_1pbue_35`,list:`_list_1pbue_47`,row:`_row_1pbue_60`,rowTop:`_rowTop_1pbue_97`,rowMeta:`_rowMeta_1pbue_98`,workflow:`_workflow_1pbue_130`,note:`_note_1pbue_137`,form:`_form_1pbue_146`,group:`_group_1pbue_154`,legend:`_legend_1pbue_166`,reason:`_reason_1pbue_185`,error:`_error_1pbue_186`,triggers:`_triggers_1pbue_218`,triggersTitle:`_triggersTitle_1pbue_236`,triggerList:`_triggerList_1pbue_253`,triggerName:`_triggerName_1pbue_264`,triggerLine:`_triggerLine_1pbue_272`,triggerCommand:`_triggerCommand_1pbue_281`},gk=[{value:``,label:`The workflow's, else the one ready`},...KC.map(e=>({value:e,label:e}))],_k=({workflow:e,values:t,onChange:n})=>(0,q.jsx)(q.Fragment,{children:Object.entries(e.inputs).map(([e,r])=>r.type===`boolean`?(0,q.jsx)(vO,{checked:t[e]===`true`,label:e,onChange:t=>{n(e,String(t))}},e):(0,q.jsx)(mk,{description:r.description,label:e,onChange:t=>{n(e,t)},required:r.required===!0,type:r.type===`number`?`number`:`text`,value:t[e]??``},e))}),vk=({value:e,onChange:t})=>(0,q.jsx)(dk,{label:`Driver`,onChange:e=>{let n=gk.find(t=>t.value===e);n!==void 0&&t(n.value)},options:gk,value:e}),yk=({flags:e,onChange:t})=>(0,q.jsxs)(`fieldset`,{className:hk.group,children:[(0,q.jsx)(`legend`,{className:hk.legend,children:`Flags`}),(0,q.jsx)(vk,{onChange:e=>{t({driver:e})},value:e.driver}),(0,q.jsx)(vO,{checked:e.inPlace,label:`--in-place: run worktree nodes in this checkout`,onChange:e=>{t({inPlace:e})}}),(0,q.jsx)(vO,{checked:e.allowDirty,label:`--allow-dirty: run with uncommitted instructions or skills`,onChange:e=>{t({allowDirty:e})}}),(0,q.jsx)(xk,{checked:e.machineClaude,onChange:e=>{t({machineClaude:e})}})]}),bk=`Your MCP servers and Claude's memory`,xk=({checked:e,onChange:t})=>{let n=(0,U.useId)();return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(vO,{checked:e,describedBy:n,label:`Use this machine's Claude setup`,onChange:t}),(0,q.jsx)(`p`,{className:nC.hint,id:n,children:bk})]})},Sk=()=>(0,q.jsx)(JD,{cli:`ork init`,title:`No projects yet.`,children:`Run this in a repository:`}),Ck=({error:e})=>(0,q.jsx)(`p`,{className:hk.error,role:`alert`,children:(0,q.jsx)(r_,{text:e})}),wk={driver:``,inPlace:!1,allowDirty:!1,machineClaude:!1},Tk=({default:e,type:t})=>e===void 0?t===`boolean`?`false`:``:String(e),Ek=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,Tk(t)])),Dk=(e,t,n)=>e===null?null:t.status===`failed`?`Cannot read the workflows of ${e}: ${t.error??`unknown error`}`:t.status===`ready`&&n===0?`${e} has no workflows. Add one to its .ork/workflows folder.`:null,Ok=(e,t,n)=>e===null?`Choose a project first`:t?`Reading workflows…`:n===0?`No workflows here`:`Type to find a workflow`,kk=(e,t,n)=>{if(e===null)return`Pick a project.`;if(t===null)return`Pick a workflow.`;if(t.error!==void 0)return`This workflow does not parse: ${t.error}`;for(let[e,r]of Object.entries(t.inputs)){let t=n[e]??``;if(r.required===!0&&t===``)return`Fill in ${e}.`;if(r.type===`number`&&t!==``&&!Number.isFinite(Number(t)))return`${e} must be a number.`}return null},Ak=(e,t)=>Object.fromEntries(Object.entries(e).flatMap(([e,n])=>{let r=t[e]??``;return r===``||r===Tk(n)?[]:[[e,r]]})),jk=/^[\w./:=@%+,-]+$/u,Mk=e=>jk.test(e)?e:`'${e.replaceAll(`'`,String.raw`'\''`)}'`,Nk=(e,t,n)=>[`ork run`,Mk(e.name),`--detach`,...Object.entries(Ak(e.inputs,t)).map(([e,t])=>`--input ${Mk(`${e}=${t}`)}`),...n.driver===``?[]:[`--driver ${n.driver}`],...n.inPlace?[`--in-place`]:[],...n.allowDirty?[`--allow-dirty`]:[],...n.machineClaude?[`--machine-claude`]:[]].join(` `),Pk=[],Fk=e=>{let t=ob(),n=vb(t.workflows.state);(0,U.useEffect)(()=>{e!==null&&t.workflows.load(e)},[t,e]);let r=n.status!==`idle`&&n.arg===e,i=r&&n.status===`ready`?n.data:Pk;return{list:i,reading:!r||n.status===`loading`,problem:Dk(e,r?n:{status:`idle`},i.length)}},Ik=(e,t)=>[...document.querySelectorAll(`[${e}]`)].find(n=>n.getAttribute(e)===t)??null,Lk=e=>Ik(`data-run-heading`,e)??Ik(`data-run-row`,e)??document.querySelector(`[data-run-workflow]`)??!0,Rk=()=>{let e=(0,U.useRef)(null);return{onStarted:t=>{e.current=t},finalFocus:()=>{let t=e.current;return e.current=null,t===null||Lk(t)}}},zk=(e,t)=>{let n=ob(),r=vb(n.projects.state),i=(0,U.useMemo)(()=>r.status===`ready`?r.data:[],[r]),[a]=(0,U.useState)(()=>n.runPreset.getValue()),[o,s]=(0,U.useState)(a?.project??null),[c,l]=(0,U.useState)(a?.workflow??null),[u,d]=(0,U.useState)({}),[f,p]=(0,U.useState)(wk),[m,h]=(0,U.useState)(null),[g,_]=(0,U.useState)(!1),v=o??(i.length===1?i[0]?.id??null:null),{list:y,reading:b,problem:x}=Fk(v),S=c??(y.length===1?y[0]?.name:null),C=y.find(({name:e})=>e===S)??null,w=(0,U.useMemo)(()=>({...Ek(C?.inputs??{}),...u}),[C,u]),T=x??kk(v,C,w);return(0,U.useEffect)(()=>{n.projects.load()},[n]),{projectsRead:r,projects:i,project:v,workflows:y,readingWorkflows:b,workflow:C,values:w,flags:f,blocked:T,refusal:m,starting:g,start:async()=>{if(T!==null||g||v===null||C===null)return;_(!0),h(null);let r=await n.startRun({project:v,workflow:C.name,inputs:Ak(C.inputs,w),...f.driver===``?{}:{driver:f.driver},...f.inPlace?{inPlace:!0}:{},...f.allowDirty?{allowDirty:!0}:{},...f.machineClaude?{machineClaude:!0}:{}});_(!1),r.ok?(n.arriveAt(r.data.runId),tb.add({title:`Run ${r.data.runId} started`}),t(r.data.runId),e()):h(r.error)},setFlags:p,chooseProject:e=>{s(e),l(null),d({})},chooseWorkflow:e=>{l(e),d({})},setInput:(e,t)=>{d(n=>({...n,[e]:t}))}}},Bk=({onDone:e,onStarted:t})=>{let n=zk(e,t),{projectsRead:r,projects:i,project:a,workflows:o,workflow:s}=n,{readingWorkflows:c}=n,{values:l,flags:u,blocked:d,refusal:f,starting:p}=n,m=(0,q.jsx)(PC,{children:(0,q.jsx)(Y,{onClick:e,variant:`ghost`,children:`Close`})});return r.status===`failed`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Ck,{error:`Cannot read the projects: ${r.error}`}),m]}):r.status===`ready`&&i.length===0?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Sk,{}),m]}):(0,q.jsxs)(`form`,{className:hk.form,onSubmit:e=>{e.preventDefault(),n.start()},children:[(0,q.jsx)(aC,{empty:`No project matches.`,label:`Project`,onChange:n.chooseProject,options:i.map(({id:e})=>({value:e,label:e})),placeholder:`Type to find a project`,value:a}),(0,q.jsx)(aC,{disabled:a===null||o.length===0,empty:`No workflow matches.`,label:`Workflow`,onChange:n.chooseWorkflow,options:o.map(({name:e})=>({value:e,label:e})),placeholder:Ok(a,c,o.length),value:s?.name??null}),s===null?null:(0,q.jsx)(_k,{onChange:n.setInput,values:l,workflow:s}),(0,q.jsx)(yk,{flags:u,onChange:e=>{n.setFlags(t=>({...t,...e}))}}),s===null?null:(0,q.jsx)(cC,{command:Nk(s,l,u)}),(0,q.jsx)(`output`,{className:hk.reason,children:d}),f===null?null:(0,q.jsx)(Ck,{error:f}),(0,q.jsxs)(PC,{children:[(0,q.jsx)(Y,{onClick:e,type:`button`,variant:`ghost`,children:`Cancel`}),(0,q.jsx)(Y,{disabled:d!==null||p,focusableWhenDisabled:!0,type:`submit`,variant:`primary`,children:p?`Starting…`:`Start run`})]})]})},Vk=()=>{let{runDialog:e,runPreset:t}=ob(),n=vb(e),{finalFocus:r,onStarted:i}=Rk();return(0,q.jsx)(NC,{description:`Starts in the background, from the project's root.`,finalFocus:r,onOpenChange:n=>{n||t.setValue(null),e.setValue(n)},open:n,title:`Run workflow`,children:(0,q.jsx)(Bk,{onDone:()=>{t.setValue(null),e.setValue(!1)},onStarted:i})})},Hk=e=>/mac|iphone|ipad/iu.test(e),Uk=(e,t,n)=>{let r=t.mod===!0;return e.code===t.code&&e.altKey===(t.alt===!0)&&e.shiftKey===(t.shift===!0)&&e.metaKey===(r&&n)&&e.ctrlKey===(t.ctrl===!0||r&&!n)},Wk=(e,t)=>{let n=e.glyph??e.key;return[...e.ctrl===!0?[t?`⌃`:`Ctrl`]:[],...e.mod===!0?[t?`⌘`:`Ctrl`]:[],...e.alt===!0?[t?`⌥`:`Alt`]:[],...e.shift===!0?[t?`⇧`:`Shift`]:[],n]},Gk=(e,t)=>[...e.ctrl===!0?[`Control`]:[],...e.mod===!0?[t?`Meta`:`Control`]:[],...e.alt===!0?[`Alt`]:[],...e.shift===!0?[`Shift`]:[],e.key].join(`+`),Kk=(e,t,n)=>({code:e,key:t,...n===void 0?{}:{glyph:n},alt:!0,shift:!0}),qk={left:[`ArrowLeft`,`←`],right:[`ArrowRight`,`→`],up:[`ArrowUp`,`↑`],down:[`ArrowDown`,`↓`]},Jk={palette:{code:`KeyK`,key:`K`,mod:!0},minimize:Kk(`KeyM`,`M`),maximize:Kk(`KeyX`,`X`),float:Kk(`KeyF`,`F`),close:Kk(`KeyW`,`W`),nextGroup:Kk(`BracketRight`,`]`),previousGroup:Kk(`BracketLeft`,`[`),goTo:e=>Kk(`Digit${String(e)}`,String(e)),resize:e=>{let[t,n]=qk[e];return Kk(t,t,n)},move:e=>{let[t,n]=qk[e];return{...Kk(t,t,n),ctrl:!0}}},Yk=9,Xk=e=>e<=Yk?Jk.goTo(e):void 0,Zk=()=>Hk(navigator.platform),Qk=()=>document.querySelector(`[data-modal]`)!==null,$k=(e,t)=>{(0,U.useEffect)(()=>{let n=Zk(),r=r=>{let i=e.palette.getValue();if(!i&&Qk())return;if(Uk(r,Jk.palette,n)){r.preventDefault(),e.palette.setValue(!i);return}if(i)return;let a=t.find(({shortcut:e})=>e!==void 0&&Uk(r,e,n));a!==void 0&&(r.preventDefault(),a.disabled===void 0?a.run():e.announce(a.disabled))};return window.addEventListener(`keydown`,r),()=>{window.removeEventListener(`keydown`,r)}},[e,t])},eA={shell:`_shell_aupfr_7`,bar:`_bar_aupfr_15`,name:`_name_aupfr_34`,logoOnDark:`_logoOnDark_aupfr_44`,logoOnLight:`_logoOnLight_aupfr_45`,spacer:`_spacer_aupfr_60`,status:`_status_aupfr_64`,middle:`_middle_aupfr_80`,dockArea:`_dockArea_aupfr_90`,rail:`_rail_aupfr_95`,stack:`_stack_aupfr_117`,stacked:`_stacked_aupfr_130`,stackedHeading:`_stackedHeading_aupfr_149`,stackedButton:`_stackedButton_aupfr_158`,stackedBody:`_stackedBody_aupfr_184`,visuallyHidden:`_visuallyHidden_aupfr_196`,count:`_count_aupfr_209`},tA=({workspace:e})=>{let{notifications:t}=ob(),n=_b(t.view,e=>e.unread);return(0,q.jsxs)(xb,{label:n===0?`Notifications`:`Notifications, ${String(n)} unread`,onClick:()=>{e.goTo(`notifications`)},children:[(0,q.jsx)(Oy,{}),n===0?null:(0,q.jsx)(`span`,{className:eA.count,children:n>99?`99+`:n})]})},nA=U.createContext(void 0);function rA(e){let t=U.useContext(nA);if(t===void 0&&!e)throw Error(gc(33));return t}var iA=U.createContext(void 0);function aA(e){let t=U.useContext(iA);if(t===void 0&&!e)throw Error(gc(36));return t}var oA=U.createContext(void 0);function sA(e=!0){let t=U.useContext(oA);if(t===void 0&&!e)throw Error(gc(25));return t}var cA=U.createContext(null);function lA(e=`root`){let t=U.useContext(cA),n=U.useContext(iA);return t===null||n===void 0?null:(e===`submenu-trigger`?n.virtualFocus||n.parentVirtualFocus:n.virtualFocus)?t:null}var uA={visible:!0,ref:null};function dA(){return uA}function fA(e,t,n=`root`){let r=lA(n),i=((n===`submenu-trigger`?r?.useSubmenuTrigger:r?.useItem)??dA)({label:e.label,children:e.children,render:e.render}),a=Au(t,i.ref);return{visible:i.visible,ref:a,props:i.props}}function pA(e){e.preventDefault()}function mA(e){let{closeOnClick:t,highlighted:n,id:r,nodeId:i,store:a,typingRef:o,itemRef:s,itemMetadata:c}=e,l=aA(),u=sA(!0),d=c.type===`submenu-trigger`,f=d?l.parentVirtualFocus:l.virtualFocus,p=(d&&l.parent.type===`menu`?l.parent.store:l.store).useState(`webkitAriaSelected`,n),{events:m}=a.useState(`floatingTreeRoot`),h=a.useState(`open`),g=u!==void 0,_=!f&&h&&n?0:-1;return U.useMemo(()=>({id:r,role:`menuitem`,tabIndex:_,"aria-selected":p,onMouseDown:f?pA:void 0,onKeyDown(e){e.key===` `&&o?.current&&e.preventDefault()},onMouseMove(e){i&&m.emit(`itemhover`,{nodeId:i,target:e.currentTarget})},onClick(e){t&&m.emit(`close`,{domEvent:e.nativeEvent,reason:lu})},onMouseUp(e){if(u){let t=u.initialCursorPointRef.current;if(u.initialCursorPointRef.current=null,g&&t&&Math.abs(e.clientX-t.x)<=1&&Math.abs(e.clientY-t.y)<=1||g&&!Mc&&e.button===2)return}s.current&&a.context.allowMouseUpTriggerRef.current&&(!g||e.button===2)&&c.type===`regular-item`&&$_(s.current,e,{detail:1,pointerType:`mouse`})}}),[t,_,r,m,i,a.context.allowMouseUpTriggerRef,o,s,u,g,c.type,p,f])}var hA={type:`regular-item`};function gA(e){let{closeOnClick:t,disabled:n,highlighted:r,id:i,store:a,typingRef:o=a.context.typingRef,nativeButton:s,itemMetadata:c,nodeId:l}=e,u=U.useRef(null),{getButtonProps:d,buttonRef:f}=ev({disabled:n,focusableWhenDisabled:!0,native:s,composite:!0}),p=mA({closeOnClick:t,highlighted:r,id:i,nodeId:l,store:a,typingRef:o,itemRef:u,itemMetadata:c}),m=U.useCallback(e=>Pf(p,{onMouseEnter(e){c.type===`submenu-trigger`&&c.setActive(e.nativeEvent)}},e,d),[p,d,c]),h=Au(u,f);return U.useMemo(()=>({getItemProps:m,itemRef:h}),[m,h])}var _A=U.forwardRef(function(e,t){let{render:n,className:r,id:i,label:a,nativeButton:o=!1,disabled:s=!1,closeOnClick:c=!0,style:l,...u}=e,{store:d}=aA(),f=GS({guess:!0,label:a}),p=hg(i),m=d.useState(`disabled`),h=d.useState(`isActive`,f.index),g=d.useState(`floatingNodeId`),_=d.useState(`itemProps`),v=s||m,{getItemProps:y,itemRef:b}=gA({closeOnClick:c,disabled:v,highlighted:h,id:p,store:d,nativeButton:o,nodeId:g,itemMetadata:hA});return qf(`div`,e,{state:{disabled:v,highlighted:h},props:[_,u,y],ref:[b,t,f.ref]})}),vA=U.forwardRef(function(e,t){let n=fA(e,t);return n.visible?(0,q.jsx)(_A,{...e,ref:n.ref}):null}),yA=U.createContext(void 0);function bA(){return U.useContext(yA)}function xA(e,t){let n=Zf(e.render);if(U.isValidElement(n)){let e=n.props;if(Object.hasOwn(e,`id`))return e.id??``}return e.id??t}function SA(e,t,n){let r=xA(e,t),i=r===t?void 0:r;return[r,U.useCallback(e=>n?.(e?i:void 0),[i,n])]}function CA(e,t,n){let r=Zf(e.render),i=U.isValidElement(r)?r.props:void 0,a=e[`aria-label`]??i?.[`aria-label`],o=e[`aria-labelledby`]??i?.[`aria-labelledby`];return o==null&&!a&&(o=t?t.id||void 0:n||void 0),o}var wA=U.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,id:o,initialFocus:s,...c}=e,{store:l,defaultFloatingId:u,setRenderedFloatingId:d,virtualFocus:f,orientation:p}=aA(),m=bA(),{side:h,align:g}=rA(),_=qO(!0)!=null,v=l.useState(`open`),y=l.useState(`transitionStatus`),b=l.useState(`popupProps`),x=l.useState(`mounted`),S=l.useState(`instantType`),C=l.useState(`activeTriggerElement`),w=l.useState(`parent`),T=l.useState(`lastOpenChangeReason`),E=l.useState(`rootId`),D=l.useState(`floatingRootContext`),O=l.useState(`floatingTreeRoot`),k=l.useState(`closeDelay`),A=l.useState(`hoverEnabled`),j=l.useState(`disabled`),M=l.useState(`openMethod`),N=l.useState(`activeTriggerId`),P=l.useState(`listElement`),[F,I]=SA(e,u,d),L=CA(e,C,N),R=w.type===`menu`?m:void 0,ee=w.type===`context-menu`,z=s??w.type!==`menu`;s===void 0&&P&&w.type!==`menu`&&(z=()=>l.state.activeIndex===null&&P),qp({open:v,ref:l.context.popupRef,onComplete(){v&&l.context.onOpenChangeComplete?.(!0)}}),U.useEffect(()=>{function e(e){l.setOpen(!1,K(e.reason,e.domEvent))}return O.events.on(`close`,e),()=>{O.events.off(`close`,e)}},[O.events,l]),Vm(D,{enabled:A&&!j&&!ee&&w.type!==`menubar`,closeDelay:k});let te=l.useStateSetter(`popupElement`),{parentVirtualFocusRef:ne,handleFocus:re}=(U.useContext(cA)?.useParentHandoff??EA)(l,w,v,f),ie=qf(`div`,e,{state:{transitionStatus:y,side:h,align:g,open:v,nested:w.type===`menu`,instant:S},ref:[t,l.context.popupRef,te,I],stateAttributesMapping:Hl,props:[b,{id:F,...P?{role:`presentation`}:{role:`menu`,"aria-orientation":p===`horizontal`?`horizontal`:void 0,"aria-labelledby":L},onKeyDown(e){R?.onPopupKeyDown?.(e),_&&CC.has(e.key)&&e.stopPropagation()},onFocus:re},Kg(y),c,{"data-rootownerid":E}]}),ae=w.type===void 0||ee;(C||w.type===`menubar`&&T!==`outside-press`)&&(ae=!0);let oe=R?.getReturnElement??ne;return(0,q.jsx)(Np,{context:D,openInteractionType:M,modal:ee,disabled:!x,returnFocus:a??oe??ae,explicitReturnFocus:a===void 0&&oe?!1:void 0,initialFocus:z,restoreFocus:!0,getInsideElements:w.type===void 0?()=>[l.context.beforeTriggerFocusGuardRef.current]:void 0,externalTree:w.type===`menubar`?void 0:O,previousFocusableElement:C,nextFocusableElement:w.type===void 0?l.context.triggerFocusTargetRef:void 0,beforeContentFocusGuardRef:l.context.beforeContentFocusGuardRef,children:ie})}),TA={parentVirtualFocusRef:void 0,handleFocus:void 0};function EA(){return TA}var DA=U.forwardRef(function(e,t){let n=lA()?.Popup??wA;return(0,q.jsx)(n,{...e,ref:t})}),OA=U.createContext(void 0);function kA(){let e=U.useContext(OA);if(e===void 0)throw Error(gc(32));return e}var AA=U.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,{store:i,parent:a}=aA();if(!(i.useState(`mounted`)||n))return null;let o=a.type===`menu`||a.type===`menubar`?`group`:void 0;return(0,q.jsx)(OA.Provider,{value:n,children:(0,q.jsx)(mp,{ref:t,...r,portalOwnerRole:o})})});function jA(e){let{store:t,domReference:n,positionerElement:r,open:i}=e,a=U.useRef(null),o=U.useRef(null),s=Kp(r);W(()=>{i||(o.current?.abort(),o.current=null,t.state.instantType===`trigger-change`&&t.set(`instantType`,void 0))},[i,t]),W(()=>{let e=n,r=a.current;if(e&&(a.current=e),!r||!e||e===r||!t.select(`open`))return;t.set(`instantType`,void 0);let i=new AbortController;return o.current=i,s(()=>{t.select(`open`)&&t.set(`instantType`,`trigger-change`)},i.signal),()=>{i.abort()}},[n,s,t])}var MA=U.forwardRef(function(e,t){let{anchor:n,positionMethod:r=`absolute`,className:i,render:a,side:o,align:s,sideOffset:c=0,alignOffset:l=0,collisionBoundary:u=`clipping-ancestors`,collisionPadding:d=5,arrowPadding:f=5,sticky:p=!1,disableAnchorTracking:m=!1,collisionAvoidance:h=op,style:g,..._}=e,{store:v,virtualFocus:y,syncHighlightedItem:b}=aA(),x=kA(),S=sA(!0),C=v.useState(`parent`),w=v.useState(`floatingRootContext`),T=v.useState(`floatingTreeRoot`),E=v.useState(`mounted`),D=v.useState(`open`),O=v.useState(`modal`),k=v.useState(`openMethod`),A=v.useState(`activeTriggerElement`),j=v.useState(`transitionStatus`),M=v.useState(`positionerElement`),N=v.useState(`instantType`),P=v.useState(`adaptiveOrigin`),F=v.useState(`lastOpenChangeReason`),I=v.useState(`floatingNodeId`),L=v.useState(`floatingParentNodeId`),R=w.useState(`domReferenceElement`),ee=n,z=c,te=l,ne=s,re=h;C.type===`context-menu`&&(ee=n??C.context?.anchor,ne??=`start`,!o&&ne!==`center`&&(te=e.alignOffset??2,z=e.sideOffset??-5));let ie=o,ae=ne;C.type===`menu`?(ie??=`inline-end`,ae??=`start`,re=e.collisionAvoidance??sp):C.type===`menubar`&&(ie??=C.context.orientation===`vertical`?`inline-end`:`bottom`,ae??=`start`);let oe=C.type===`context-menu`,se=Ug({anchor:ee,floatingRootContext:w,positionMethod:S?`fixed`:r,mounted:E,side:ie,sideOffset:z,align:ae,alignOffset:te,arrowPadding:oe?0:f,collisionBoundary:u,collisionPadding:d,sticky:p,nodeId:I,keepMounted:x,disableAnchorTracking:m,collisionAvoidance:re,shift:oe?{crossAxis:!(`side`in re&&re.side===`flip`),rootBoundary:`layoutViewport`}:void 0,externalTree:T,adaptiveOrigin:P,lazyFlip:y?`placement`:!1});U.useEffect(()=>{function e(e){e.open&&(e.parentNodeId===I&&v.set(`hoverEnabled`,!1),e.nodeId!==I&&e.parentNodeId===v.select(`floatingParentNodeId`)&&v.setOpen(!1,K(bu)))}return T.events.on(`menuopenchange`,e),()=>{T.events.off(`menuopenchange`,e)}},[v,T.events,I]),U.useEffect(()=>{if(v.select(`floatingParentNodeId`)==null)return;function e(e){if(e.open||e.nodeId!==v.select(`floatingParentNodeId`))return;let t=e.reason??`sibling-open`;v.setOpen(!1,K(t))}return T.events.on(`menuopenchange`,e),()=>{T.events.off(`menuopenchange`,e)}},[T.events,v]);let ce=Sc();U.useEffect(()=>{D||ce.clear()},[D,ce]),U.useEffect(()=>{function e(e){if(D&&e.nodeId===v.select(`floatingParentNodeId`)){if(e.target&&A&&A!==e.target){let e=v.select(`closeDelay`);e>0?ce.isStarted()||ce.start(e,()=>{v.setOpen(!1,K(bu))}):v.setOpen(!1,K(bu))}else ce.clear()}}return T.events.on(`itemhover`,e),()=>{T.events.off(`itemhover`,e)}},[T.events,D,A,v,ce]),U.useEffect(()=>{let e={open:D,nodeId:I,parentNodeId:L,reason:v.select(`lastOpenChangeReason`)};T.events.emit(`menuopenchange`,e)},[T.events,D,v,I,L]),jA({store:v,domReference:R,positionerElement:M,open:D});let le={open:D,side:se.side,align:se.align,anchorHidden:se.anchorHidden,nested:C.type===`menu`,instant:N},ue=C.type===`menubar`&&C.context.modal;LS(D&&(ue||O&&F!==`trigger-hover`),k===`touch`,M,A);let de=qg(e,le,{styles:se.positionerStyles,transitionStatus:j,props:_,refs:[t,v.useStateSetter(`positionerElement`)],hidden:!E,inert:!D}),fe=E&&C.type!==`menu`&&(C.type!==`menubar`&&O&&F!==`trigger-hover`||C.type===`menubar`&&C.context.modal),pe=null;return C.type===`menubar`?pe=C.context.contentElement:C.type===void 0&&(pe=A),(0,q.jsxs)(nA.Provider,{value:se,children:[fe&&(0,q.jsx)(wS,{ref:C.type===`context-menu`||C.type===`nested-context-menu`?C.context.internalBackdropRef:null,inert:Zg(!D),cutout:pe}),(0,q.jsx)(Sp,{id:I,children:(0,q.jsx)(uS,{elementsRef:v.context.itemDomElements,labelsRef:v.context.itemLabels,onMapChange:b,children:de})})]})}),NA=U.createContext(null);function PA(e){let t=U.useContext(NA);if(t===null&&!e)throw Error(gc(5));return t}var FA={...jm,disabled:e=>e.parent.type===`menubar`&&e.parent.context.disabled||e.disabled,modal:e=>(e.parent.type===void 0||e.parent.type===`context-menu`)&&(e.modal??!0),openMethod:e=>e.openMethod,keyboardOpen:e=>e.keyboardOpen,allowMouseEnter:e=>e.allowMouseEnter,highlightItemOnHover:e=>e.highlightItemOnHover,parent:e=>e.parent,rootId:e=>e.parent.type===`menu`?e.parent.store.select(`rootId`):e.parent.type===void 0?e.rootId:e.parent.context.rootId,activeIndex:e=>e.activeIndex,listElement:e=>e.listElement,triggerControlsId:(e,t)=>{let n=jm.triggerPopupId(e,t);return n?e.listElement?.id||n:void 0},filterTriggerProps:e=>e.filterTriggerProps,inputProps:e=>e.inputProps,webkitAriaSelected:(e,t)=>Pc&&e.inputFocused&&t?!0:void 0,highlightedItemId:e=>e.highlightedItem?.id||void 0,isActive:(e,t)=>e.activeIndex===t,hoverEnabled:e=>e.hoverEnabled,instantType:e=>e.instantType===`trigger-change`&&!jm.open(e)?void 0:e.instantType,lastOpenChangeReason:e=>e.openChangeReason,floatingTreeRoot:e=>e.parent.type===`menu`?e.parent.store.select(`floatingTreeRoot`):e.floatingTreeRoot,floatingNodeId:e=>e.floatingNodeId,floatingParentNodeId:e=>e.floatingParentNodeId,itemProps:e=>e.itemProps,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin,keyboardEventRelay:e=>{if(e.keyboardEventRelay)return e.keyboardEventRelay;if(e.parent.type===`menu`)return e.parent.store.select(`keyboardEventRelay`)}},IA=class extends Sm{constructor(e,t,n=!1){let r=new lm,i=RA(r,t,n,e);super(i,LA(r),FA),this.observe(`parent`,e=>{e.type===`menu`?this.context.allowMouseUpTriggerRef=e.store.context.allowMouseUpTriggerRef:e.type!==void 0&&(this.context.allowMouseUpTriggerRef=e.context.allowMouseUpTriggerRef)})}subscribeToParentMenu(){let e=this.state.parent;if(e.type!==`menu`)return;let t=e.store.select(`rootId`),n=e.store.select(`floatingTreeRoot`),r=e.store.select(`keyboardEventRelay`);return e.store.subscribe(()=>{let i=e.store.select(`rootId`),a=e.store.select(`floatingTreeRoot`),o=e.store.select(`keyboardEventRelay`);(t!==i||n!==a||r!==o)&&(t=i,n=a,r=o,this.notifyAll())})}setOpen(e,t){this.state.floatingRootContext.context.events.emit(`setOpen`,{open:e,eventDetails:t})}setActiveIndex(e,t,n){if(this.state.activeIndex!==e){let r=(e===null?void 0:this.context.itemDomElements.current[e])===this.context.reportedItem;this.context.highlightReason=r?`none`:t,this.context.highlightEvent=r?void 0:n}this.set(`activeIndex`,e)}highlightItem(e,t,n){let r=this.context.itemDomElements.current.indexOf(e);r>-1&&this.setActiveIndex(r,t,n)}};function LA(e){return{positionerRef:U.createRef(),popupRef:U.createRef(),typingRef:{current:!1},itemDomElements:{current:[]},itemLabels:{current:[]},highlightReason:`none`,highlightEvent:void 0,reportedItem:void 0,allowMouseUpTriggerRef:{current:!1},virtualFocusRef:void 0,triggerFocusTargetRef:U.createRef(),beforeTriggerFocusGuardRef:U.createRef(),beforeContentFocusGuardRef:U.createRef(),onOpenChangeComplete:void 0,triggerElements:e}}function RA(e,t,n=!1,r){return{...Tm(e,t,n),disabled:!1,modal:!0,openMethod:null,keyboardOpen:!1,allowMouseEnter:!1,highlightItemOnHover:!0,parent:{type:void 0},rootId:void 0,activeIndex:null,listElement:null,filterTriggerProps:mc,inputProps:mc,inputFocused:!1,highlightedItem:void 0,hoverEnabled:!0,instantType:void 0,openChangeReason:null,floatingTreeRoot:new gp,floatingNodeId:void 0,floatingParentNodeId:null,itemProps:mc,keyboardEventRelay:void 0,closeDelay:0,adaptiveOrigin:void 0,...r}}var zA=U.createContext(null);function BA(e,t){return(e===`trigger-press`||e===`item-press`)&&t?.detail===0}function VA(e,t){return e===`list-navigation`||BA(e,t)}var HA=lc(function(e){let{children:t,open:n,onOpenChange:r,onOpenChangeComplete:i,onItemHighlighted:a,defaultOpen:o=!1,disabled:s=!1,modal:c,loopFocus:l=!0,orientation:u=`vertical`,actionsRef:d,closeParentOnEsc:f=!1,handle:p,triggerId:m,defaultTriggerId:h=null,highlightItemOnHover:g=!0,isSubmenu:_=!1,virtualFocus:v=!1,virtualFocusRef:y,allowEscape:b=!0,resetOnPointerLeave:x=!0}=e,S=sA(!0),C=aA(!0),w=PA(!0),T=C?.store,E=C?.virtualFocus??!1,D=U.useMemo(()=>_&&T?{type:`menu`,store:T}:w?{type:`menubar`,context:w}:S&&!T?{type:`context-menu`,context:S}:{type:void 0},[S,T,w,_]),O=hg(),k=hg(),[A,j]=U.useState(void 0),M=(A??k)||void 0,N=yp(),P=D.type===`menu`?D.store:void 0,F=(n??o)&&P?.state.transitionStatus===`starting`,I=ic(()=>F?P?.state.instantType:void 0).current,L=ic(()=>{let e=new IA({open:o,openProp:n,activeTriggerId:h,triggerIdProp:m,parent:D,disabled:s,highlightItemOnHover:g,modal:D.type===void 0?c:void 0,rootId:O,instantType:I},M,N!=null);return e.context.virtualFocusRef=y,e}).current;L.useControlledProp(`openProp`,n),L.useControlledProp(`triggerIdProp`,m),L.useContextCallback(`onOpenChangeComplete`,i);let R=L.useState(`floatingTreeRoot`),ee=xp(R),z=L.useState(`open`),te=L.useState(`activeTriggerElement`),ne=L.useState(`positionerElement`),re=L.useState(`hoverEnabled`),ie=L.useState(`disabled`),ae=L.useState(`lastOpenChangeReason`),oe=L.useState(`parent`),se=L.useState(`activeIndex`),ce=L.useState(`keyboardOpen`),le=L.useState(`payload`),ue=L.useState(`floatingParentNodeId`),de=U.useRef(null),fe=U.useRef(oe.type!==`context-menu`),pe=Sc(),me=U.useRef(!0),he=Sc(),ge=ue!=null,{openMethod:_e,triggerProps:ve}=Ex(z);L.useSyncedValues({disabled:s,highlightItemOnHover:g,modal:oe.type===void 0?c:void 0,openMethod:_e,rootId:O}),am(L);let{forceUnmount:ye,transitionStatus:be}=om(z,L,()=>{L.set(`allowMouseEnter`,!1)},F),B=Kp(L.context.popupRef);U.useEffect(()=>{if(I===void 0)return;let e=()=>{L.state.instantType===I&&L.set(`instantType`,void 0)};if(!z){e();return}if(be!==void 0)return;if(L.context.popupRef.current==null){e();return}let t=new AbortController;return B(e,t.signal),()=>{t.abort()}},[I,z,be,B,L]),W(()=>{S&&!C?L.update({parent:{type:`context-menu`,context:S},floatingNodeId:ee,floatingParentNodeId:N}):(C||!L.select(`activeTriggerElement`))&&L.update({floatingNodeId:ee,floatingParentNodeId:N})},[S,C,ee,N,te,L]),U.useEffect(()=>{z||(de.current=null),oe.type===`context-menu`&&(z?pe.start(500,()=>{fe.current=!0}):(pe.clear(),fe.current=!1))},[pe,z,oe.type]),W(()=>{!z&&!re&&L.set(`hoverEnabled`,!0)},[z,re,L]);let xe=J((e,t)=>{let n=t.reason;if(!e&&!L.select(`open`)||z===e&&t.trigger===te&&ae===n)return;let i=nm(t);if(!e&&t.trigger==null&&(t.trigger=te??void 0),r?.(e,t),t.isCanceled)return;L.state.floatingRootContext.dispatchOpenChange(e,t);let a=t.event;if(e===!1&&n!==`item-press`&&a?.type===`click`&&a.pointerType===`touch`&&!me.current)return;e&&n===`trigger-focus`?(me.current=!1,he.start(300,()=>{me.current=!0})):(me.current=!0,he.clear());let o=!e&&(n===`escape-key`||n==null);de.current=t.event;let s=tm(L.state,e,t.trigger,i());s.openChangeReason=n,s.keyboardOpen=e&&VA(n,a),s.instantType=oe.type===`menubar`&&(n===`trigger-focus`||n===`focus-out`||n===`trigger-hover`||n===`list-navigation`||n===`sibling-open`)?`group`:BA(n,a)?`click`:o?`dismiss`:void 0,L.update(s)}),Se=Vp({popupStore:L,floatingRootContext:L.state.floatingRootContext,floatingId:M,nested:N!=null,onOpenChange:xe}),Ce=Se.context.events;W(()=>{let e=({open:e,eventDetails:t})=>xe(e,t);return Ce.on(`setOpen`,e),()=>{Ce?.off(`setOpen`,e)}},[Ce,xe]),W(()=>L.subscribeToParentMenu(),[L]);let we=U.useCallback(()=>{L.setOpen(!1,K(Su))},[L]);U.useImperativeHandle(d,()=>({unmount:ye,close:we}),[ye,we]);let Te;oe.type===`context-menu`&&(Te=oe.context),U.useImperativeHandle(Te?.positionerRef,()=>ne,[ne]),U.useImperativeHandle(Te?.actionsRef,()=>({setOpen:xe}),[xe]);let Ee=Bp(Se,{enabled:!ie,bubbles:{escapeKey:f&&oe.type===`menu`},outsidePress(){return oe.type!==`context-menu`||de.current?.type===`contextmenu`||fe.current},externalTree:ge?R:void 0}),De=kg(),Oe=Xm(Se,{enabled:!ie,listRef:L.context.itemDomElements,activeIndex:se,virtual:v,nested:oe.type===`menubar`||!v&&oe.type!==void 0,parentOrientation:oe.type===`menubar`?oe.context.orientation:void 0,loopFocus:l,focusItemOnOpen:v?ce:void 0,allowEscape:v&&l&&b,orientation:u,triggerOrientation:v?`vertical`:u,rtl:De===`rtl`,disabledIndices:pc,onNavigate(e,t){L.setActiveIndex(e,Tb(t),t?.nativeEvent)},openOnArrowKeyDown:oe.type!==`context-menu`&&!(v&&_),externalTree:!v&&ge?R:void 0,nestedReturnFocusRef:P?.context.virtualFocusRef,focusItemOnHover:g,resetOnPointerLeave:x}),ke=U.useCallback(e=>{L.context.typingRef.current=e},[L]),Ae=Zm(Se,{enabled:!ie&&!v,listRef:L.context.itemLabels,elementsRef:L.context.itemDomElements,activeIndex:se,resetMs:500,onMatch:(e,t)=>{z&&e!==se&&L.setActiveIndex(e,_u,t.nativeEvent)},onTyping:ke}),je=J(a),Me=U.useRef(-1),Ne=J(()=>{let e=L.state.activeIndex,t=e===null?void 0:L.context.itemDomElements.current[e]??void 0;if(t?.isConnected===!1)return;let n=t===void 0?-1:e;if(Me.current===n&&L.context.reportedItem===t)return;Me.current=n,L.context.reportedItem=t,v&&L.set(`highlightedItem`,t);let{highlightReason:r,highlightEvent:i}=L.context;L.context.highlightReason=iu,L.context.highlightEvent=void 0,a&&je(t,ru(r,i,{label:t===void 0?void 0:L.context.itemLabels.current[n]??void 0}))});W(()=>{Ne()},[se,Ne]);let Pe=U.useMemo(()=>{if(!v)return Oe.reference;if(!Oe.trigger)return mc;let{onFocus:e,...t}=Oe.trigger;return t},[v,Oe.reference,Oe.trigger]);L.useSyncedValue(`inputProps`,v?Oe.reference??mc:mc);let Fe=U.useMemo(()=>{let e=Pf(Ae.reference,Pe,Ee.reference,{onMouseMove(){L.set(`allowMouseEnter`,!0)}},ve);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=z,e},[L,Ae.reference,Pe,Ee.reference,ve,z]),Ie=U.useMemo(()=>{let e=Pf(Oe.trigger,Ee.trigger,ve);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=!1,e},[Oe.trigger,Ee.trigger,ve]);ic(()=>(L.update({inactiveTriggerProps:Ie}),null)),sm(L,{floatingRootContext:Se,activeTriggerProps:Fe,inactiveTriggerProps:Ie,popupProps:U.useMemo(()=>Pf(Yp,{onMouseMove(){L.set(`allowMouseEnter`,!0),oe.type===`menu`&&L.set(`hoverEnabled`,!1)},onClick(){L.select(`hoverEnabled`)&&L.set(`hoverEnabled`,!1)},onKeyDown(e){let t=L.select(`keyboardEventRelay`);t&&!e.isPropagationStopped()&&t(e)}},Ae.floating,Oe.floating,Ee.floating),[oe.type,L,Ae.floating,Oe.floating,Ee.floating]),itemProps:Oe.item??mc});let Le=U.useMemo(()=>({store:L,parent:D,orientation:u,loopFocus:l,allowEscape:b,defaultFloatingId:k,setRenderedFloatingId:j,virtualFocus:v,parentVirtualFocus:E,syncHighlightedItem:Ne}),[L,D,u,l,b,k,v,E,Ne]),Re=typeof t==`function`?t({payload:le}):t,ze=(0,q.jsxs)(iA.Provider,{value:Le,children:[p&&(0,q.jsx)(Qp,{handle:p,store:L}),Re]});return(oe.type===void 0||oe.type===`context-menu`)&&(ze=(0,q.jsx)(Cp,{externalTree:R,children:ze})),ze});function UA(e){let t=U.useContext(zA);if(t===null)return(0,q.jsx)(HA,{...e});let n=t.Root;return(0,q.jsx)(zA.Provider,{value:null,children:(0,q.jsx)(n,{...t.options,...e})})}function WA(e={}){let{highlightItemOnHover:t,highlightedIndex:n,onHighlightedIndexChange:r}=Z_(),{ref:i,index:a}=GS(e),o=n===a,s=U.useRef(null),c=Au(i,s);return{compositeProps:{tabIndex:o?0:-1,onFocus(){r(a)},onMouseMove(){let e=s.current;if(!t||!e)return;let n=e.hasAttribute(`disabled`)||e.ariaDisabled===`true`;!o&&!n&&e.focus()}},compositeRef:c,index:a}}function GA(e){let{render:t,className:n,style:r,state:i=mc,props:a=pc,refs:o=pc,metadata:s,stateAttributesMapping:c,tag:l=`div`,...u}=e,{compositeProps:d,compositeRef:f}=WA({metadata:s});return qf(l,e,{state:i,ref:[f,...o],props:[d,...a,u],stateAttributesMapping:c})}function KA(e){if(Xc(e)&&e.hasAttribute(`data-rootownerid`))return e.getAttribute(`data-rootownerid`);if(!cl(e))return KA(dl(e))}function qA(e,t){function n(n,r,i){let a=n.currentTarget;lp.flushSync(()=>{e.setOpen(!1,K(mu,n.nativeEvent,a))}),ef(a.isConnected?a:t.current,r,i)?.focus()}function r(t){n(t,-1,e.select(`positionerElement`))}function i(t){let r=e.select(`positionerElement`);r&&tf(t,r)?e.context.beforeContentFocusGuardRef.current?.focus():n(t,1,r)}return{handlePreFocusGuardFocus:r,handleFocusTargetFocus:i}}function JA(e){let{enabled:t=!0,mouseDownAction:n,open:r}=e,i=U.useRef(!1);return U.useMemo(()=>t?{onMouseDown:e=>{(n===`open`&&!r||n===`close`&&r)&&(i.current=!0,qu(e.currentTarget).addEventListener(`click`,()=>{i.current=!1},{once:!0}))},onClick:e=>{i.current&&(i.current=!1,e.preventBaseUIHandler())}}:mc,[t,n,r])}var YA=uc(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,id:s,openOnHover:c,delay:l=100,closeDelay:u=0,handle:d,payload:f,...p}=e,m=aA(!0),h=Mm(d)??m?.store;if(!h)throw Error(gc(85));let g=hg(s),_=h.useState(`isTriggerActive`,g),v=h.useState(`floatingRootContext`),y=h.useState(`isOpenedByTrigger`,g),b=h.useState(`triggerControlsId`,g),x=U.useRef(null),S=ZA(),C=Z_(!0),w=bp(),T=U.useMemo(()=>w??new gp,[w]),{registerTrigger:E,isMountedByThisTrigger:D}=im(g,x,h,{payload:f,closeDelay:u,parent:S,floatingTreeRoot:T,floatingNodeId:xp(T),floatingParentNodeId:yp(),keyboardEventRelay:C?.relayKeyboardEvent}),O=S.type===`menubar`,k=h.useState(`disabled`),A=a||k||O&&S.context.disabled,{getButtonProps:j,buttonRef:M}=ev({disabled:A,native:o});U.useEffect(()=>{!y&&S.type===void 0&&(h.context.allowMouseUpTriggerRef.current=!1)},[h,y,S.type]);let N=U.useRef(null),P=Sc(),F=J(e=>{if(!N.current)return;P.clear(),h.context.allowMouseUpTriggerRef.current=!1;let t=e.target;G(N.current,t)||G(h.select(`positionerElement`),t)||t===N.current||t!=null&&KA(t)===h.select(`rootId`)||tS(e,N.current)||T.events.emit(`close`,{domEvent:e,reason:yu})});U.useEffect(()=>{let e=qu(N.current);if(y&&h.select(`lastOpenChangeReason`)===`trigger-hover`)return e.addEventListener(`mouseup`,F,{once:!0}),()=>{e.removeEventListener(`mouseup`,F)}},[y,F,h]);let I=O&&S.context.hasSubmenuOpen,L=Um(v,{enabled:(c??I)&&!A&&(!O||I&&!D),handleClose:ah({blockPointerEvents:!O}),mouseOnly:!0,move:!1,restMs:S.type===void 0?l:void 0,delay:{close:u},triggerElementRef:x,externalTree:T,isActiveTrigger:_,isClosing:()=>h.select(`transitionStatus`)===`ending`}),R=XA(y,h.select(`lastOpenChangeReason`)),ee=Pp(v,{enabled:!A,event:y&&O?`click`:`mousedown`,toggle:!0,ignoreMouse:!1,stickIfOpen:S.type===void 0&&R}),z=Fm(v,{enabled:!A&&I}),te=JA({open:y,enabled:O,mouseDownAction:`open`}),ne=U.useMemo(()=>Pf(z.reference,ee.reference),[z.reference,ee.reference]),re=h.useState(`triggerProps`,D),ie=h.useState(`filterTriggerProps`),{handlePreFocusGuardFocus:ae,handleFocusTargetFocus:oe}=qA(h,x),se={disabled:A,open:y},ce=[N,t,M,E,x],le=[ne,L??mc,re,{"aria-haspopup":`menu`,"aria-controls":b,id:g,onMouseDown:e=>{h.select(`open`)||(P.start(200,()=>{h.context.allowMouseUpTriggerRef.current=!0}),qu(e.currentTarget).addEventListener(`mouseup`,F,{once:!0}))}},ie,O?{role:`menuitem`}:{},te,p,j],ue=qf(`button`,e,{enabled:!O,stateAttributesMapping:Bl,state:se,ref:ce,props:le});return O?(0,q.jsx)(GA,{tag:`button`,render:n,className:r,style:i,state:se,refs:ce,props:le,stateAttributesMapping:Bl}):y?(0,q.jsxs)(U.Fragment,{children:[(0,q.jsx)(Zu,{ref:h.context.beforeTriggerFocusGuardRef,onFocus:ae},`${g}-pre-focus-guard`),(0,q.jsx)(U.Fragment,{children:ue},g),(0,q.jsx)(Zu,{ref:h.context.triggerFocusTargetRef,onFocus:oe},`${g}-post-focus-guard`)]}):(0,q.jsx)(U.Fragment,{children:ue},g)});function XA(e,t){let n=Sc(),[r,i]=U.useState(!1);return W(()=>{e&&t===`trigger-hover`?(i(!0),n.start(500,()=>{i(!1)})):e||(n.clear(),i(!1))},[e,t,n]),r}function ZA(){let e=PA(!0);return U.useMemo(()=>e?{type:`menubar`,context:e}:{type:void 0},[e])}var QA=U.forwardRef(function(e,t){let{className:n,render:r,orientation:i=`horizontal`,style:a,...o}=e;return qf(`div`,e,{state:{orientation:i},ref:t,props:[{role:`separator`,"aria-orientation":i},o]})}),$A=(e,t)=>e===`separator`?`separator-${String(t)}`:e.label,ej=({entry:e})=>e===`separator`?(0,q.jsx)(QA,{className:o_.separator}):(0,q.jsxs)(vA,{className:o_.item,"data-variant":e.danger===!0?`danger`:`default`,disabled:e.disabled??!1,onClick:e.onSelect,children:[(0,q.jsx)(`span`,{children:e.label}),e.detail===void 0?null:(0,q.jsx)(`span`,{className:o_.itemDetail,children:e.detail}),e.hint===void 0?null:(0,q.jsx)(`kbd`,{children:e.hint})]}),tj=({trigger:e,entries:t})=>(0,q.jsxs)(UA,{children:[(0,q.jsx)(YA,{render:e}),(0,q.jsx)(AA,{children:(0,q.jsx)(MA,{align:`start`,className:o_.positioner,sideOffset:4,children:(0,q.jsx)(DA,{className:o_.popup,children:t.map((e,t)=>(0,q.jsx)(ej,{entry:e},$A(e,t)))})})})]}),nj=(e,{label:t})=>t===void 0?e:`${e} if ${t}`,rj={flow:e=>({from:[`leads to`,nj(e.to,e)],to:[`after`,nj(e.from,e)]}),back:e=>({from:[`goes back to`,nj(e.to,e)],to:[`comes back from`,nj(e.from,e)]}),owner:e=>({from:[`owns`,e.to],to:[`owned by`,e.from]}),message:e=>({from:[`can message`,e.to],to:[`can message`,e.from]})},ij=e=>{let t=new Map,n=(e,[n,r])=>{let i=t.get(e)??new Map;i.set(n,[...i.get(n)??[],r]),t.set(e,i)};for(let t of e){let{from:e,to:r}=rj[t.kind](t);n(t.from,e),n(t.to,r)}return new Map([...t].map(([e,t])=>[e,[...t].map(([e,t])=>`${e} ${t.join(`, `)}`).join(`; `)]))},aj=12,oj=(e,t,n)=>{let r=Math.abs(t.x-e.x)+Math.abs(t.y-e.y),i=r===0?0:n/r;return{x:e.x+(t.x-e.x)*i,y:e.y+(t.y-e.y)*i}},sj=({x:e,y:t})=>`${String(e)} ${String(t)}`,cj=(e,t)=>Math.abs(e.x-t.x)+Math.abs(e.y-t.y),lj=e=>{let[t,...n]=e;if(t===void 0)return``;let r=[`M ${sj(t)}`];for(let[i,a]of n.entries()){let o=e[i]??t,s=n[i+1];if(s===void 0)r.push(`L ${sj(a)}`);else{let e=Math.min(aj,cj(o,a)/2,cj(a,s)/2);r.push(`L ${sj(oj(a,o,e))}`,`Q ${sj(a)} ${sj(oj(a,s,e))}`)}}return r.join(` `)},uj=({shape:e,points:t})=>{let[n,r,i,a]=t;return e===`curve`&&n!==void 0&&r!==void 0&&i!==void 0&&a!==void 0?`M ${sj(n)} C ${sj(r)} ${sj(i)} ${sj(a)}`:lj(t)},dj=(e,t)=>Array.from({length:Math.ceil(e.length/t)},(n,r)=>e.slice(r*t,(r+1)*t)),fj=(e,t=28)=>{let n=[];for(let r of e.split(` `).flatMap(e=>dj(e,t))){let e=n.at(-1);e!==void 0&&e.length+1+r.length<=t?n[n.length-1]=`${e} ${r}`:n.push(r)}return n},pj=e=>e*14+2,mj=e=>{let t=e===void 0?[]:fj(e,21);return Math.ceil(90/4+pj(t.length)/2+hj)},hj=6,gj=6.6;Math.floor(144/gj);var _j={graph:`_graph_1nobd_7`,canvas:`_canvas_1nobd_15`,hint:`_hint_1nobd_45`,layer:`_layer_1nobd_58`,edges:`_edges_1nobd_67`,edgeLine:`_edgeLine_1nobd_82`,edgeHead:`_edgeHead_1nobd_95`,packet:`_packet_1nobd_136`,edgeLabel:`_edgeLabel_1nobd_160`,edgeLabelBack:`_edgeLabelBack_1nobd_174`,card:`_card_1nobd_180`,cardHead:`_cardHead_1nobd_264`,cardIcon:`_cardIcon_1nobd_273`,cardId:`_cardId_1nobd_284`,cardCost:`_cardCost_1nobd_295`,controls:`_controls_1nobd_306`,keyList:`_keyList_1nobd_331`,keyRow:`_keyRow_1nobd_342`,keyNames:`_keyNames_1nobd_346`,keyDoes:`_keyDoes_1nobd_355`},vj=6,yj=(e,t)=>{if(!(t===void 0||e!==`flow`&&e!==`owner`))return t.status===`running`?`flowing`:t.status===`queued`||t.status===`skipped`?`pending`:`taken`},bj=e=>e.reduce((t,n,r)=>{let i=e[r-1];return i===void 0?t:t+Math.hypot(n.x-i.x,n.y-i.y)},0),xj=({path:e,length:t})=>{let n=6/t;return(0,q.jsx)(`path`,{className:_j.packet,d:e,"data-packet":``,pathLength:2,strokeDasharray:`${String(n)} ${String(1-n)}`})},Sj=e=>{let t=e.at(-1),n=e.at(-2);if(t===void 0||n===void 0)return``;let r=Math.sign(t.x-n.x),i=Math.sign(t.y-n.y),a={x:t.x-r*vj,y:t.y-i*vj},o={x:-i*(vj/2),y:vj/2*r};return[t,{x:a.x+o.x,y:a.y+o.y},{x:a.x-o.x,y:a.y-o.y}].map(({x:e,y:t})=>`${String(e)},${String(t)}`).join(` `)},Cj=({label:e,at:t,limit:n})=>{let r=fj(e,n),i=Math.max(...r.map(e=>e.length))*gj+8,a=pj(r.length),o=t.y-(r.length-1)*14/2;return(0,q.jsxs)(`g`,{children:[(0,q.jsx)(`rect`,{className:_j.edgeLabelBack,height:a,rx:2,width:i,x:t.x-i/2,y:t.y-a/2}),(0,q.jsx)(`text`,{className:_j.edgeLabel,children:r.map((e,n)=>(0,q.jsx)(`tspan`,{x:t.x,y:o+n*14,children:e},`${String(n)}:${e}`))})]})},wj=(0,U.memo)(({edges:e,facts:t,quiet:n,width:r,height:i})=>(0,q.jsx)(`svg`,{"aria-hidden":`true`,className:_j.edges,"data-quiet":n?``:void 0,focusable:`false`,height:i,width:r,children:e.map(e=>{let n=yj(e.kind,t?.get(e.to)),r=uj(e);return(0,q.jsxs)(`g`,{"data-kind":e.kind,"data-state":n,children:[(0,q.jsx)(`path`,{className:_j.edgeLine,d:r}),e.kind===`message`?null:(0,q.jsx)(`polygon`,{className:_j.edgeHead,points:Sj(e.points)}),n===`flowing`?(0,q.jsx)(xj,{length:bj(e.points),path:r}):null,e.label===void 0||e.labelAt===void 0?null:(0,q.jsx)(Cj,{at:e.labelAt,label:e.label,limit:e.labelLimit})]},`${e.from}\n${e.to}\n${e.kind}`)})}));wj.displayName=`EdgePaths`;var Tj=e=>({x:e.x+e.width/2,y:e.y+e.height/2}),Ej=(e,t,n)=>{let r=Tj(t),i=Tj(n);return e===`left`?i.x<r.x:e===`right`?i.x>r.x:e===`up`?i.y<r.y:i.y>r.y},Dj=(e,t,n)=>{let r=Tj(t),i=e===`left`||e===`right`,a=e=>{let t=Tj(e);return Math.abs(i?t.x-r.x:t.y-r.y)+Math.abs(i?t.y-r.y:t.x-r.x)*2};return n.toSorted((e,t)=>a(e)-a(t))[0]},Oj=(e,t,n)=>{let r=e.nodes.find(e=>e.id===t);if(r===void 0)return;let i=new Set(e.edges.flatMap(e=>e.from===t?[e.to]:e.to===t?[e.from]:[])),a=e.nodes.filter(e=>e.id!==t),o=a.filter(e=>i.has(e.id)&&Ej(n,r,e));return(Dj(n,r,n===`left`||n===`right`?[]:a.filter(e=>e.x===r.x&&Ej(n,r,e)))??Dj(n,r,o))?.id},kj=5,Aj=e=>e.flatMap((e,t)=>e.split(``).flatMap((e,n)=>e===`#`?[`M${String(n)} ${String(t)}h1v1h-1z`]:[])).join(``),jj=e=>()=>(0,q.jsx)(`svg`,{"aria-hidden":`true`,fill:`currentColor`,focusable:`false`,height:`1em`,shapeRendering:`crispEdges`,viewBox:`0 0 ${String(kj)} ${String(kj)}`,width:`1em`,children:(0,q.jsx)(`path`,{d:Aj(e)})}),Mj=jj([`.....`,`.###.`,`.###.`,`.###.`,`.....`]),Nj=jj([`....#`,`...#.`,`#.#..`,`.#...`,`.....`]),Pj=jj([`..#..`,`.#.#.`,`#...#`,`.#.#.`,`..#..`]),Fj=jj([`.#.#.`,`.#.#.`,`.#.#.`,`.#.#.`,`.#.#.`]),Ij=jj([`#...#`,`.#.#.`,`..#..`,`.#.#.`,`#...#`]),Lj=jj([`#.#.#`,`.....`,`#...#`,`.....`,`#.#.#`]),Rj=jj([`.....`,`.....`,`#####`,`.....`,`.....`]),zj=jj([`#####`,`#...#`,`#...#`,`#...#`,`#####`]),Bj=jj([`..#..`,`..#..`,`#####`,`..#..`,`..#..`]),Vj=jj([`#....`,`.#...`,`..#..`,`.#...`,`#....`]),Hj=jj([`..#..`,`.###.`,`#.#.#`,`..#..`,`..#..`]),Uj={badge:`_badge_derh1_8`,word:`_word_derh1_38`,icon:`_icon_derh1_50`,blink:`_blink_derh1_1`},Wj={running:{Icon:Mj,word:`running`,tone:`running`},succeeded:{Icon:Nj,word:`succeeded`,tone:`succeeded`},waiting:{Icon:Pj,word:`waiting on you`,tone:`waiting`},paused:{Icon:Fj,word:`paused`,tone:`paused`},failed:{Icon:Ij,word:`failed`,tone:`failed`},crashed:{Icon:Ij,word:`crashed`,tone:`failed`},queued:{Icon:Lj,word:`queued`,tone:`queued`},skipped:{Icon:Rj,word:`skipped`,tone:`skipped`},interrupted:{Icon:zj,word:`interrupted`,tone:`interrupted`},budget_exhausted:{Icon:zj,word:`budget exhausted`,tone:`interrupted`},quota_exhausted:{Icon:zj,word:`quota spent`,tone:`interrupted`},timed_out:{Icon:zj,word:`timed out`,tone:`interrupted`}},Gj=e=>Wj[e].word,Kj=e=>Wj[e].tone,qj=({look:e,pill:t})=>{let{Icon:n,word:r,tone:i}=e;return(0,q.jsxs)(`span`,{className:Uj.badge,"data-look":t?`pill`:`bare`,"data-tone":i,children:[(0,q.jsx)(`span`,{className:Uj.icon,children:(0,q.jsx)(n,{})}),(0,q.jsx)(`span`,{className:Uj.word,children:r})]})},Jj=({status:e,word:t,pill:n=!1})=>{let r=Wj[e];return(0,q.jsx)(qj,{look:{...r,word:t??r.word},pill:n})},Yj={new:{Icon:Bj,word:`new`,tone:`waiting`},triaged:{Icon:Lj,word:`triaged`,tone:`queued`},accepted:{Icon:Vj,word:`accepted`,tone:`queued`},resolved:{Icon:Nj,word:`resolved`,tone:`succeeded`},published:{Icon:Hj,word:`published`,tone:`succeeded`},dismissed:{Icon:Rj,word:`dismissed`,tone:`skipped`}},Xj=({status:e,pill:t=!1})=>(0,q.jsx)(qj,{look:Yj[e],pill:t}),Zj={merged:{Icon:Nj,word:`merged`,tone:`succeeded`},unmerged:{Icon:Vj,word:`not merged`,tone:`queued`},detached:{Icon:Rj,word:`detached`,tone:`skipped`}},Qj=({state:e})=>(0,q.jsx)(qj,{look:Zj[e],pill:!1}),$j={"agent.leader":`leader`,"agent.worker":`worker`,"agent.subagent":`sub-agent`,"control.split":`split`,"control.join":`join`,"control.router":`router`,"human.gate":`gate`,"workflow.call":`workflow call`,"mcp.call":`MCP call`},eM=e=>$j[e]??(e.startsWith(`tool.`)?`${e.slice(5)} tool`:e),tM=5e-5,nM=(e,t=[e])=>{if(!Number.isFinite(e))return`–`;let n=Math.abs(e);if(n!==0&&n<tM)return e>0?`<$0.0001`:`$0.00`;let r=t.some(e=>{let t=Math.abs(Number(e.toFixed(4)));return t!==0&&t<10});return`${e<0?`-`:``}$${n.toFixed(r?4:2)}`},rM=e=>{if(e<1e3)return String(e);let t=Math.round(e/100)/10;return t<1e3?`${t.toFixed(1)}k`:`${(Math.round(e/1e5)/10).toFixed(1)}M`},iM=e=>rM(e).replace(/\.0(?=[kM]$)/u,``),aM=(e,t)=>t?`≥ ${e}`:e,oM=e=>String(e).padStart(2,`0`),sM=e=>{let t=Math.max(Math.floor(e/1e3),0),n=Math.floor(t/60),r=`${oM(n%60)}:${oM(t%60)}`;return n<60?`${String(n)}:${oM(t%60)}`:`${String(Math.floor(n/60))}:${r}`},cM=(e,t,n)=>[e,n.word??Gj(n.status),...n.progress===void 0?[]:[n.progress],...n.costUsd===void 0?[]:[nM(n.costUsd)],...n.tokens===void 0?[]:[`${rM(n.tokens)} tokens`],...n.model===void 0?[]:[n.model],...n.unpriced===!0?[`no price`]:[],eM(t)].join(`, `),lM={tokens:`_tokens_xg8q2_6`},uM={tabIndex:0},dM=`At least this much. Some sessions ran on a driver that reports no price, so their dollars are not counted. Tokens count every session.`,fM=`No price for this driver. Counted tokens are shown.`,pM=({text:e,partial:t,focusable:n=!1})=>t?(0,q.jsx)(u_,{label:dM,children:(0,q.jsxs)(`span`,{...n?uM:{},children:[(0,q.jsx)(`span`,{"aria-hidden":`true`,children:`≥ ${e}`}),(0,q.jsx)(uk,{children:`at least ${e}, partial`})]})}):e,mM=({count:e,unit:t=`tokens`})=>(0,q.jsx)(`span`,{className:lM.tokens,children:`${rM(e)} ${t}`}),hM=({count:e})=>(0,q.jsx)(u_,{label:fM,children:(0,q.jsx)(`span`,{children:(0,q.jsx)(mM,{count:e,unit:`tok`})})}),gM=`Input, output and cache-write tokens, as budgetTokens counts them. Cache reads are not counted.`,_M=()=>(0,q.jsx)(u_,{label:gM,children:(0,q.jsx)(`span`,{...uM,children:`Tokens counted`})}),vM=new Map([[`agent.leader`,(0,q.jsx)(Ly,{},`leader`)],[`agent.worker`,(0,q.jsx)(Ry,{},`worker`)],[`agent.subagent`,(0,q.jsx)(zy,{},`subagent`)],[`control.split`,(0,q.jsx)(By,{},`split`)],[`control.join`,(0,q.jsx)(Vy,{},`join`)],[`control.router`,(0,q.jsx)(Hy,{},`router`)],[`human.gate`,(0,q.jsx)(Uy,{},`gate`)],[`workflow.call`,(0,q.jsx)(Wy,{},`call`)],[`mcp.call`,(0,q.jsx)(Wy,{},`mcp`)],[`tool.gh`,(0,q.jsx)(Gy,{},`gh`)],[`tool.aws`,(0,q.jsx)(Ky,{},`aws`)],[`tool.git`,(0,q.jsx)(qy,{},`git`)]]),yM=({type:e})=>vM.get(e)??(0,q.jsx)(_y,{}),bM=(0,U.memo)(({node:e,facts:t,connections:n,selected:r,holding:i=!1,dimmed:a,tabbable:o,bind:s,onSelect:c,onFocused:l,onKey:u,onMenu:d,onHover:f})=>{let{id:p,type:m,x:h,y:g,width:_,height:v}=e,y=(0,q.jsxs)(`button`,{...l_(t.cli,n),"aria-current":r?`true`:void 0,"aria-label":cM(p,m,t),className:_j.card,"data-graph-node":``,"data-dim":a?``:void 0,"data-holding":i?``:void 0,"data-selected":r?``:void 0,"data-tone":Kj(t.status),onMouseEnter:()=>f?.(p),onMouseLeave:()=>f?.(null),onClick:()=>{c(p)},onContextMenu:d===void 0?void 0:e=>{e.preventDefault(),d(p)},onFocus:()=>{l(p)},onKeyDown:e=>{u(p,e)},ref:e=>{s(p,e)},style:{height:v,transform:`translate(${h}px, ${g}px)`,width:_},tabIndex:o?0:-1,type:`button`,children:[(0,q.jsxs)(`span`,{className:_j.cardHead,children:[(0,q.jsx)(`span`,{className:_j.cardIcon,children:(0,q.jsx)(yM,{type:m})}),(0,q.jsx)(`span`,{className:_j.cardId,children:p}),t.unpriced===!0&&t.tokens!==void 0?(0,q.jsx)(`span`,{className:_j.cardCost,children:(0,q.jsx)(mM,{count:t.tokens,unit:`tok`})}):null,t.unpriced!==!0&&t.costUsd!==void 0?(0,q.jsx)(`span`,{className:_j.cardCost,children:nM(t.costUsd)}):null]}),(0,q.jsx)(Jj,{status:t.status,word:t.word??t.progress})]});return t.cli===void 0?y:(0,q.jsx)(u_,{cli:t.cli,label:t.progress===void 0?void 0:`${t.word??Gj(t.status)} · ${t.progress}`,children:y})});bM.displayName=`NodeCard`;var xM=(e,t)=>{let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},SM=(e,t)=>{let n=e=>{e.preventDefault(),e instanceof WheelEvent&&t(e)};return e.addEventListener(`wheel`,n,{passive:!1}),()=>{e.removeEventListener(`wheel`,n)}},CM=(e,t)=>{let n=e.current?.getBoundingClientRect(),r=t.current?.getBoundingClientRect();return n===void 0||r===void 0?void 0:{x:n.x-r.x,y:n.y-r.y,width:n.width,height:n.height}},wM=.2,TM=e=>Math.min(2,Math.max(wM,e)),EM=(e,t)=>{if(e.width<=0||e.height<=0)return{x:0,y:0,k:1};let n=TM(Math.min(1,t.width/e.width,t.height/e.height));return{x:(t.width-e.width*n)/2,y:(t.height-e.height*n)/2,k:n}},DM=(e,t,n)=>{let r=TM(e.k*t),i=r/e.k;return{k:r,x:n.x-(n.x-e.x)*i,y:n.y-(n.y-e.y)*i}},OM=(e,t,n)=>({...e,x:e.x+t,y:e.y+n}),kM=(e,t,n,r)=>{let i={x:t.x*e.k+e.x,y:t.y*e.k+e.y,width:t.width*e.k,height:t.height*e.k};if(!MM(i,n))return e;let a=n.y-r-(i.y+i.height);return i.y+a>=r?OM(e,0,a):OM(e,n.x-r-(i.x+i.width),0)},AM=(e,t,n,r,i=24)=>{let a=(e,t,n)=>{let r=e+t;return t+i*2>=n?(n-t)/2-e:e<i?i-e:r>n-i?n-i-r:0},o=a(t.x*e.k+e.x,t.width*e.k,n.width),s=a(t.y*e.k+e.y,t.height*e.k,n.height),c=o===0&&s===0?e:OM(e,o,s);return r===void 0?c:kM(c,t,r,i)},jM=(e,t,n=160)=>({x:(-n-e.x)/e.k,y:(-n-e.y)/e.k,width:(t.width+n*2)/e.k,height:(t.height+n*2)/e.k}),MM=(e,t)=>e.x<t.x+t.width&&t.x<e.x+e.width&&e.y<t.y+t.height&&t.y<e.y+e.height,NM=16,PM=12,FM=e=>{let t=NM*e;for(;t<PM;)t*=2;return t},IM=e=>{let t=e.map(e=>e.x),n=e.map(e=>e.y),r=Math.min(...t),i=Math.min(...n);return{x:r,y:i,width:Math.max(...t)-r,height:Math.max(...n)-i}},LM=.01,RM=e=>({nodes:new Set(e.nodes.map(e=>e.id)),edges:new Set(e.edges.keys())}),zM=()=>{},BM=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y),VM=e=>{let t=(0,U.useRef)(null),n=(0,U.useRef)(null),r=(0,U.useRef)(null),i=(0,U.useRef)({x:0,y:0,k:1}),a=(0,U.useRef)(!1),o=(0,U.useRef)(0),s=(0,U.useRef)(new Map),[c,l]=(0,U.useState)(()=>RM(e)),u=(0,U.useRef)(``),[d,f]=(0,U.useState)(e);e!==d&&(f(e),l(RM(e)));let p=(0,U.useMemo)(()=>e.edges.map(e=>IM(e.points)),[e]),m=(0,U.useCallback)(()=>{let e=t.current?.getBoundingClientRect();return{width:e?.width??0,height:e?.height??0}},[]),h=(0,U.useCallback)(()=>{o.current=0;let{x:r,y:a,k:s}=i.current,c=n.current;c!==null&&(c.style.transform=`translate(${String(r)}px, ${String(a)}px) scale(${String(s)})`);let d=t.current;if(d!==null){let e=`${String(FM(s))}px`;d.style.backgroundSize=`${e} ${e}`,d.style.backgroundPosition=`${String(r)}px ${String(a)}px`,d.style.setProperty(`--graph-zoom`,String(s))}let f=m();if(f.width===0||f.height===0)return;let h=jM(i.current,f),g=e.nodes.filter(e=>MM(h,e)).map(e=>e.id),_=[...p.keys()].filter(e=>{let t=p[e];return t!==void 0&&MM(h,t)}),v=`${g.join(`
92
+ `)}\n\n${_.join(`,`)}`;v!==u.current&&(u.current=v,l({nodes:new Set(g),edges:new Set(_)}))},[p,e,m]),g=(0,U.useCallback)(()=>{o.current===0&&(o.current=requestAnimationFrame(h))},[h]),_=(0,U.useCallback)(()=>{a.current=!1,i.current=EM(e,m()),g()},[e,g,m]),v=(0,U.useCallback)(e=>{a.current=!0,i.current=e,g()},[g]),y=(0,U.useCallback)(e=>{let{width:t,height:n}=m();v(DM(i.current,e,{x:t/2,y:n/2}))},[v,m]),b=(0,U.useCallback)((e,t)=>{v(OM(i.current,e,t))},[v]),x=(0,U.useCallback)(e=>{let n=m();if(n.width===0||n.height===0)return;let a=AM(i.current,e,n,CM(r,t));a!==i.current&&v(a)},[v,m]);return(0,U.useEffect)(()=>{u.current=``,a.current?g():_()},[_,g]),(0,U.useEffect)(()=>{let e=t.current;return e===null?zM:xM(e,()=>{a.current?g():_()})},[_,g]),(0,U.useEffect)(()=>()=>{cancelAnimationFrame(o.current),o.current=0},[]),(0,U.useEffect)(()=>{let e=t.current;return e===null?zM:SM(e,t=>{if(t.ctrlKey||t.metaKey){let n=e.getBoundingClientRect();v(DM(i.current,Math.exp(-t.deltaY*LM),{x:t.clientX-n.left,y:t.clientY-n.top}))}else v(OM(i.current,-t.deltaX,-t.deltaY))})},[v]),{canvasRef:t,layerRef:n,controlsRef:r,shown:c,fit:_,zoom:y,pan:b,show:x,pointer:(0,U.useMemo)(()=>{let e=e=>{let t=e.currentTarget.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}},t=e=>{s.current.delete(e.pointerId)};return{onPointerDown:t=>{t.target instanceof Element&&t.target.closest(`button`)!==null||(t.currentTarget.setPointerCapture?.(t.pointerId),s.current.set(t.pointerId,e(t)))},onPointerMove:t=>{let n=s.current.get(t.pointerId);if(n===void 0)return;let r=e(t),a=[...s.current].find(([e])=>e!==t.pointerId)?.[1];if(a===void 0)v(OM(i.current,r.x-n.x,r.y-n.y));else{let e=BM(n,a);e>0&&v(DM(i.current,BM(r,a)/e,a))}s.current.set(t.pointerId,r)},onPointerUp:t,onPointerCancel:t}},[v])}},HM=U.createContext(void 0);function UM(e){let t=U.useContext(HM);if(t===void 0&&!e)throw Error(gc(47));return t}var WM={...jm,disabled:e=>e.disabled,instantType:e=>e.instantType===`trigger-change`&&!jm.open(e)?void 0:e.instantType,openMethod:e=>e.openMethod,openChangeReason:e=>e.openChangeReason,isPressOpenedByTrigger:(e,t)=>e.openChangeReason===`trigger-press`&&jm.isOpenedByTrigger(e,t),isTouchPressOpen:(e,t)=>t&&e.openMethod===`touch`&&e.openChangeReason===`trigger-press`,hasTriggerFocusGuards:(e,t)=>jm.isOpenedByTrigger(e,t)&&!e.focusManagerModal,modal:e=>e.modal,titleElementId:e=>e.titleElementId,descriptionElementId:e=>e.descriptionElementId,openOnHover:e=>e.openOnHover,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin},GM=class extends Sm{constructor(e,t,n){let r=new lm;super(KM(e,r,t,n),qM(r),WM)}setOpen=(e,t)=>{let n=t.reason===ou,r=t.reason===`trigger-press`&&t.event.detail===0,i=!e&&(t.reason===`escape-key`||t.reason==null),a=nm(t),o=this.select(`activeTriggerId`);if(!e&&t.reason===`close-press`&&t.trigger==null&&o!=null&&(t.trigger=this.context.triggerElements.getById(o)??this.select(`activeTriggerElement`)??void 0),this.context.onOpenChange?.(e,t),t.isCanceled)return;this.state.floatingRootContext.dispatchOpenChange(e,t);let s=()=>{let n=tm(this.state,e,t.trigger,a());n.openChangeReason=t.reason,this.update(n)};n?(this.context.stickIfOpen=!0,this.context.stickIfOpenTimeout.start(500,()=>{this.context.stickIfOpen=!1}),lp.flushSync(s)):s();let c;r?c=`click`:i?c=`dismiss`:t.reason===`focus-out`&&(c=`focus`),this.set(`instantType`,c)}};function KM(e,t,n,r=!1){let i={...Tm(t,n,r),disabled:!1,modal:!1,focusManagerModal:!1,instantType:void 0,openMethod:null,openChangeReason:null,titleElementId:void 0,descriptionElementId:void 0,openOnHover:!1,closeDelay:0,adaptiveOrigin:void 0,...e};return i.open&&e?.mounted===void 0&&(i.mounted=!0),i}function qM(e){return{popupRef:U.createRef(),onOpenChange:void 0,onOpenChangeComplete:void 0,triggerFocusTargetRef:U.createRef(),beforeTriggerFocusGuardRef:U.createRef(),beforeContentFocusGuardRef:U.createRef(),stickIfOpenTimeout:new xc,stickIfOpen:!0,triggerElements:e}}var JM=lc(function({props:e}){let{children:t,open:n,defaultOpen:r=!1,onOpenChange:i,onOpenChangeComplete:a,modal:o=!1,handle:s,triggerId:c,defaultTriggerId:l=null}=e,u=XM(s,{modal:o,open:r,openProp:n,activeTriggerId:l,triggerIdProp:c});u.useControlledProp(`openProp`,n),u.useControlledProp(`triggerIdProp`,c);let d=u.useState(`open`),f=u.useState(`mounted`),p=u.useState(`payload`);u.useContextCallback(`onOpenChange`,i),u.useContextCallback(`onOpenChangeComplete`,a),cm(u,d),am(u);let{forceUnmount:m}=om(d,u,()=>{u.context.stickIfOpen=!0,u.set(`openChangeReason`,null)});u.useSyncedValues({modal:o}),U.useEffect(()=>{d||u.context.stickIfOpenTimeout.clear()},[u,d]),U.useImperativeHandle(e.actionsRef,()=>({unmount:m,close:()=>u.setOpen(!1,K(Su))}),[m,u]);let h=d||f||s!=null;return(0,q.jsxs)(HM.Provider,{value:u,children:[s&&(0,q.jsx)(Qp,{handle:s,store:u}),h&&(0,q.jsx)(ZM,{store:u,modal:o}),typeof t==`function`?t({payload:p}):t]})});function YM(e){return UM(!0)?(0,q.jsx)(JM,{props:e}):(0,q.jsx)(Cp,{children:(0,q.jsx)(JM,{props:e})})}function XM(e,t){let n=Zp((e,n)=>new GM(t,e,n));return U.useEffect(()=>n.context.stickIfOpenTimeout.disposeEffect(),[n]),n}function ZM({store:e,modal:t}){let n=Bp(e.useState(`floatingRootContext`),{outsidePressEvent:{mouse:t===`trap-focus`?`sloppy`:`intentional`,touch:`sloppy`}}),r=n.reference,i=n.floating;return sm(e,{activeTriggerProps:r,inactiveTriggerProps:r,popupProps:i}),null}var QM=uc(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,handle:s,payload:c,openOnHover:l=!1,delay:u=300,closeDelay:d=0,id:f,...p}=e,m=UM(!0),h=Mm(s)??m;if(!h)throw Error(gc(74));let g=hg(f),_=h.useState(`isTriggerActive`,g),v=h.useState(`floatingRootContext`),y=h.useState(`isOpenedByTrigger`,g),b=h.useState(`triggerPopupId`,g),x=U.useRef(null),{registerTrigger:S,isMountedByThisTrigger:C}=im(g,x,h,{payload:c,disabled:a,openOnHover:l,closeDelay:d}),w=h.useState(`isPressOpenedByTrigger`,g),T=h.useState(`isTouchPressOpen`,l),E=h.useState(`hasTriggerFocusGuards`,g),D=Um(v,{enabled:!a&&l&&!T,mouseOnly:!0,move:!1,handleClose:ah(),restMs:u,delay:{close:d},triggerElementRef:x,isActiveTrigger:_,isClosing:()=>h.select(`transitionStatus`)===`ending`}),O=Pp(v,{stickIfOpen:J(()=>h.context.stickIfOpen)}),k=Tx(()=>h.select(`open`),e=>{h.set(`openMethod`,e)}),A=h.useState(`triggerProps`,C),{getButtonProps:j,buttonRef:M}=ev({disabled:a,native:o}),N={open(e){return w?Bl.open(e):zl.open(e)}},{handlePreFocusGuardFocus:P,handleFocusTargetFocus:F}=qA(h,x),I=qf(`button`,e,{state:{disabled:a,open:y},ref:[M,t,S,x],props:[O.reference,D,A,k,{[tp]:``,id:g,"aria-haspopup":`dialog`,"aria-expanded":y,"aria-controls":b},p,j],stateAttributesMapping:N}),L=(0,q.jsx)(U.Fragment,{children:I},g);return E?(0,q.jsxs)(U.Fragment,{children:[(0,q.jsx)(Zu,{ref:h.context.beforeTriggerFocusGuardRef,onFocus:P}),L,(0,q.jsx)(Zu,{ref:h.context.triggerFocusTargetRef,onFocus:F})]}):L}),$M=U.createContext(void 0);function eN(){let e=U.useContext($M);if(e===void 0)throw Error(gc(45));return e}var tN=U.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e;return UM().useState(`mounted`)||n?(0,q.jsx)($M.Provider,{value:n,children:(0,q.jsx)(mp,{ref:t,...r})}):null}),nN=U.createContext(void 0);function rN(){let e=U.useContext(nN);if(!e)throw Error(gc(46));return e}var iN=U.forwardRef(function(e,t){let{render:n,className:r,style:i,anchor:a,positionMethod:o,side:s,align:c,sideOffset:l,alignOffset:u,collisionBoundary:d=`clipping-ancestors`,collisionPadding:f,arrowPadding:p,sticky:m,disableAnchorTracking:h=!1,collisionAvoidance:g=sp,..._}=e,v=UM(),y=eN(),b=xp(),x=v.useState(`floatingRootContext`),S=v.useState(`mounted`),C=v.useState(`open`),w=v.useState(`openChangeReason`),T=v.useState(`activeTriggerElement`),E=v.useState(`modal`),D=v.useState(`openMethod`),O=v.useState(`positionerElement`),k=v.useState(`instantType`),A=v.useState(`transitionStatus`),j=Ug({anchor:a,floatingRootContext:x,positionMethod:o,mounted:S,side:s,sideOffset:l,align:c,alignOffset:u,arrowPadding:p,collisionBoundary:d,collisionPadding:f,sticky:m,disableAnchorTracking:h,keepMounted:y,nodeId:b,collisionAvoidance:g,adaptiveOrigin:v.useState(`adaptiveOrigin`)});jA({store:v,domReference:x.useState(`domReferenceElement`),positionerElement:O,open:C});let M=E===!0&&w!==`trigger-hover`;LS(C&&M,D===`touch`,O,T);let N=v.useStateSetter(`positionerElement`),P=qg(e,{open:C,side:j.side,align:j.align,anchorHidden:j.anchorHidden,instant:k},{styles:j.positionerStyles,transitionStatus:A,props:_,refs:[t,N],hidden:!S,inert:!C});return(0,q.jsxs)(nN.Provider,{value:j,children:[S&&M&&(0,q.jsx)(wS,{inert:Zg(!C),cutout:T}),(0,q.jsx)(Sp,{id:b,children:P})]})}),aN=U.createContext(void 0);function oN(){let[e,t]=U.useState(0),n=J(()=>(t(e=>e+1),()=>{t(e=>Math.max(0,e-1))}));return{context:U.useMemo(()=>({register:n}),[n]),hasClosePart:e>0}}var sN=U.forwardRef(function(e,t){let{render:n,className:r,style:i,initialFocus:a,finalFocus:o,...s}=e,c=UM(),l=rN(),u=qO(!0)!=null,{context:d,hasClosePart:f}=oN(),p=c.useState(`open`),m=c.useState(`openMethod`),h=c.useState(`instantType`),g=c.useState(`transitionStatus`),_=c.useState(`popupProps`),v=c.useState(`titleElementId`),y=c.useState(`descriptionElementId`),b=c.useState(`modal`),x=c.useState(`mounted`),S=c.useState(`openChangeReason`),C=c.useState(`activeTriggerElement`),w=c.useState(`floatingRootContext`),T=w.useState(`floatingId`),E=c.useState(`disabled`),D=c.useState(`openOnHover`),O=c.useState(`closeDelay`);qp({open:p,ref:c.context.popupRef,onComplete(){p&&c.context.onOpenChangeComplete?.(!0)}}),Vm(w,{enabled:D&&!E,closeDelay:O});let k=a===void 0?Xp(c.context.popupRef):a,A=b!==!1&&f;c.useSyncedValue(`focusManagerModal`,A);let j=c.useStateSetter(`popupElement`),M=qf(`div`,e,{state:{open:p,side:l.side,align:l.align,instant:h,transitionStatus:g},ref:[t,c.context.popupRef,j],props:[_,{id:T,role:`dialog`,...Yp,"aria-labelledby":v,"aria-describedby":y,onKeyDown(e){u&&CC.has(e.key)&&e.stopPropagation()}},Kg(g),s],stateAttributesMapping:Hl});return(0,q.jsx)(Np,{context:w,openInteractionType:m,modal:A,disabled:!x||S===`trigger-hover`,initialFocus:k,returnFocus:o,restoreFocus:`popup`,getInsideElements:()=>[c.context.beforeTriggerFocusGuardRef.current],previousFocusableElement:Xc(C)?C:void 0,nextFocusableElement:c.context.triggerFocusTargetRef,beforeContentFocusGuardRef:c.context.beforeContentFocusGuardRef,children:(0,q.jsx)(aN.Provider,{value:d,children:M})})}),cN=U.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,o=UM(),s=hg(a.id);return o.useSyncedValueWithCleanup(`titleElementId`,s),qf(`h2`,e,{ref:t,props:[{id:s},a]})}),lN=({trigger:e,title:t,children:n})=>(0,q.jsxs)(YM,{children:[(0,q.jsx)(QM,{render:e}),(0,q.jsx)(tN,{children:(0,q.jsx)(iN,{className:o_.positioner,sideOffset:4,children:(0,q.jsxs)(sN,{className:o_.panel,children:[(0,q.jsx)(cN,{className:o_.title,children:t}),n]})})})]}),uN=1.25,dN=[{keys:[[`←`],[`→`],[`↑`],[`↓`]],does:`Move the view; on a node, follow its edges`},{keys:[[`Enter`],[`Space`]],does:`Select the node`},{keys:[[`Shift`,`F10`]],does:`The node's controls`},{keys:[[`Escape`]],does:`Back to the view`},{keys:[[`+`],[`-`]],does:`Zoom in or out`},{keys:[[`0`]],does:`Fit the graph`}],fN=()=>(0,q.jsx)(lN,{title:`Keys on the graph`,trigger:(0,q.jsx)(xb,{label:`Keys on the graph`,children:(0,q.jsx)(Zy,{})}),children:(0,q.jsx)(`dl`,{className:_j.keyList,children:dN.map(({keys:e,does:t})=>(0,q.jsxs)(`div`,{className:_j.keyRow,children:[(0,q.jsx)(`dt`,{className:_j.keyNames,children:e.map(e=>(0,q.jsx)(a_,{keys:e},e.join(`+`)))}),(0,q.jsx)(`dd`,{className:_j.keyDoes,children:t})]},t))})}),pN=({controlsRef:e,zoom:t,fit:n,pan:r})=>(0,q.jsxs)(`div`,{className:_j.controls,ref:e,children:[(0,q.jsx)(xb,{keys:[`+`],label:`Zoom in`,onClick:()=>{t(uN)},children:(0,q.jsx)(Jy,{})}),(0,q.jsx)(xb,{keys:[`-`],label:`Zoom out`,onClick:()=>{t(1/uN)},children:(0,q.jsx)(Yy,{})}),(0,q.jsx)(xb,{keys:[`0`],label:`Fit the graph`,onClick:n,children:(0,q.jsx)(Xy,{})}),(0,q.jsx)(xb,{keys:[`←`],label:`Pan left`,onClick:()=>{r(48,0)},children:(0,q.jsx)(dy,{})}),(0,q.jsx)(xb,{keys:[`→`],label:`Pan right`,onClick:()=>{r(-48,0)},children:(0,q.jsx)(fy,{})}),(0,q.jsx)(xb,{keys:[`↑`],label:`Pan up`,onClick:()=>{r(0,48)},children:(0,q.jsx)(py,{})}),(0,q.jsx)(xb,{keys:[`↓`],label:`Pan down`,onClick:()=>{r(0,-48)},children:(0,q.jsx)(my,{})}),(0,q.jsx)(fN,{})]}),mN={status:`queued`},hN={ArrowLeft:`left`,ArrowRight:`right`,ArrowUp:`up`,ArrowDown:`down`},gN=()=>{},_N=(0,U.memo)(({layout:e,label:t,facts:n,selected:r,holding:i,onSelect:a=gN,onNodeMenu:o,live:s=!1,hovered:c=null,onHover:l})=>{let u=(0,U.useId)(),{canvasRef:d,layerRef:f,controlsRef:p,shown:m,fit:h,zoom:g,pan:_,show:v,pointer:y}=VM(e),[b,x]=(0,U.useState)(r),[S,C]=(0,U.useState)(r);r!==S&&(C(r),r!==void 0&&x(r));let w=(0,U.useRef)(new Map),T=(0,U.useRef)(null),E=(0,U.useMemo)(()=>new Map(e.nodes.map(e=>[e.id,e])),[e]),D=(0,U.useMemo)(()=>ij(e.edges),[e]),O=E.has(b??``)?b:e.nodes[0]?.id,k=i??r,A=(0,U.useRef)(k);(0,U.useEffect)(()=>{if(k===A.current)return;A.current=k;let e=E.get(k??``);e!==void 0&&v(e)},[E,k,v]),(0,U.useEffect)(()=>{let e=T.current;if(e===null)return;let t=w.current.get(e);t!==void 0&&(T.current=null,t.focus({preventScroll:!0}))});let j=(0,U.useCallback)((e,t)=>{t===null?w.current.delete(e):w.current.set(e,t)},[]),M=(0,U.useCallback)(e=>{x(e);let t=E.get(e);t!==void 0&&v(t)},[E,v]),N=(0,U.useCallback)((t,n)=>{let r=hN[n.key];if(r!==void 0){n.preventDefault(),n.stopPropagation();let i=Oj(e,t,r);if(i===void 0)return;let a=E.get(i);a!==void 0&&v(a),T.current=i,x(i)}else n.key===`Escape`?d.current?.focus({preventScroll:!0}):(n.key===`ContextMenu`||n.key===`F10`&&n.shiftKey)&&o!==void 0&&(n.preventDefault(),o(t))},[E,d,e,o,v]),P=e=>{if(e.metaKey||e.ctrlKey||e.altKey)return;let t=e.target===e.currentTarget,n={"+":()=>{g(uN)},"=":()=>{g(uN)},"-":()=>{g(1/uN)},0:h,...t?{ArrowLeft:()=>{_(48,0)},ArrowRight:()=>{_(-48,0)},ArrowUp:()=>{_(0,48)},ArrowDown:()=>{_(0,-48)}}:{}}[e.key];n!==void 0&&(e.preventDefault(),n())},F=e.nodes.filter(e=>m.nodes.has(e.id)||e.id===O),I=(0,U.useMemo)(()=>e.edges.filter((e,t)=>m.edges.has(t)),[e,m]);return(0,q.jsxs)(`div`,{className:_j.graph,children:[(0,q.jsxs)(`div`,{...y,"aria-describedby":u,"aria-label":t,"aria-roledescription":`graph`,className:_j.canvas,onKeyDown:P,ref:d,role:`application`,tabIndex:0,children:[(0,q.jsx)(`p`,{className:_j.hint,id:u,children:`Arrow keys move the view; on a node, they move along its edges, Enter selects it, Shift+F10 asks for its controls, and Escape goes back to the view. Plus and minus zoom, and 0 fits the graph.`}),(0,q.jsxs)(`div`,{className:_j.layer,ref:f,children:[(0,q.jsx)(wj,{edges:I,facts:s?n:void 0,height:e.height,quiet:c!==null,width:e.width}),F.map(e=>(0,q.jsx)(bM,{bind:j,connections:D.get(e.id),dimmed:c!==null&&c!==e.id,facts:n?.get(e.id)??mN,holding:e.id===i,node:e,onFocused:M,onHover:l,onKey:N,onMenu:o,onSelect:a,selected:e.id===r,tabbable:e.id===O},e.id))]})]}),(0,q.jsx)(pN,{controlsRef:p,fit:h,pan:_,zoom:g})]})});_N.displayName=`GraphView`;var vN=8,yN=e=>new Map(e.map((e,t)=>[e,t])),bN=(e,t,n)=>{let r=yN(e),i=yN(t),a=n.flatMap(([e,t])=>{let n=r.get(e),a=i.get(t);return n===void 0||a===void 0?[]:[[n,a]]}),o=0;for(let[e,[t=0,n=0]=[]]of a.entries())for(let[r=0,i=0]of a.slice(e+1))(t-r)*(n-i)<0&&(o+=1);return o},xN=(e,t)=>e.slice(1).reduce((n,r,i)=>n+bN(e[i]??[],r,t),0),SN=(e,t,n)=>{let r=(e,r)=>{let i=(t.get(e)??[]).flatMap(e=>{let t=n.get(e);return t===void 0?[]:[t]});return i.length===0?r:i.reduce((e,t)=>e+t,0)/i.length};return e.map((e,t)=>({id:e,index:t,weight:r(e,t)})).toSorted((e,t)=>e.weight-t.weight||e.index-t.index).map(({id:e})=>e)},CN=(e,t)=>{let n=new Map,r=new Map;for(let[e,i]of t)n.set(i,[...n.get(i)??[],e]),r.set(e,[...r.get(e)??[],i]);let i=e.map(e=>[...e]),a=i,o=xN(i,t);for(let e=0;e<vN&&o>0;e+=1){let s=e%2==0,c=i.map(e=>[...e]),l=c.map((e,t)=>t);for(let e of s?l.slice(1):l.slice(0,-1).toReversed()){let t=yN(c[e+(s?-1:1)]??[]);c[e]=SN(c[e]??[],s?n:r,t)}i=c;let u=xN(i,t);u<o&&(o=u,a=i)}return a},wN=12,TN=(e,t)=>{let n=[],r=0;for(let[i]of e.entries())i>0&&(r+=t[i-1]??0),n.push(r);let i=[];for(let[t,r]of e.entries())for(i.push({sum:r-(n[t]??0),size:1});;){let e=i.at(-1),t=i.at(-2);if(e===void 0||t===void 0||t.sum/t.size<=e.sum/e.size)break;i.splice(-2,2,{sum:t.sum+e.sum,size:t.size+e.size})}return i.flatMap(({sum:e,size:t})=>Array.from({length:t},()=>e/t)).map((e,t)=>e+(n[t]??0))},EN=(e,t,n)=>{let r=new Map,i=new Map;for(let[e,n]of t)r.set(n,[...r.get(n)??[],e]),i.set(e,[...i.get(e)??[],n]);let a=new Map,o=(e,t)=>{let r=TN(t,e.slice(1).map((t,r)=>n(e[r]??``,t)));for(let[t,n]of e.entries())a.set(n,r[t]??0)};for(let t of e)o(t,t.map(()=>0));let s=(e,t)=>{let n=e.map(e=>{let n=t.flatMap(t=>t.get(e)??[]).map(e=>a.get(e)??0);return n.length===0?a.get(e)??0:n.reduce((e,t)=>e+t,0)/n.length});o(e,n)};for(let t=0;t<wN;t+=1){let n=t%2==0;for(let a of n?e:e.toReversed())s(a,t===11?[r,i]:[n?r:i])}return a},DN=e=>{let t=new Set(e.nodes.map(e=>e.id)),n=[],r=(e,t,r,i)=>{n.push({index:n.length,from:e,to:t,kind:r,label:i})},i=new Set;for(let{from:n,to:a,when:o,maxRounds:s}of e.edges)t.has(n)&&t.has(a)&&(i.add(`${n}\n${a}`),r(n,a,s!==void 0||n===a?`back`:`flow`,o));for(let{id:n,parent:a}of e.nodes)a!==void 0&&t.has(a)&&!i.has(`${a}\n${n}`)&&r(a,n,`owner`);for(let[n,i]of e.channels??[])t.has(n)&&t.has(i)&&n!==i&&r(n,i,`message`);return n},ON=(e,t)=>{let n=new Map;for(let e of t)n.set(e.from,[...n.get(e.from)??[],e]);let r=new Map,i=e=>{r.set(e,`open`);for(let t of n.get(e)??[]){let e=r.get(t.to);e===`open`?t.kind=`back`:e===void 0&&i(t.to)}r.set(e,`done`)};for(let t of e)r.has(t)||i(t)},kN=(e,t)=>{let n=new Set(t.filter(e=>e.kind===`flow`).map(e=>e.to)),r=t.filter(e=>e.kind===`flow`||e.kind===`owner`&&!n.has(e.to));ON(e,r);let i=r.filter(e=>e.kind!==`back`),a=new Map(e.map(e=>[e,0])),o=!0;for(let t=0;o&&t<=e.length;t+=1){o=!1;for(let{from:e,to:t}of i){let n=(a.get(e)??0)+1;n>(a.get(t)??0)&&(a.set(t,n),o=!0)}}return a},AN=12,jN=(e,t)=>{let n=new Map,r=(e,t,r)=>{n.set(e,[...n.get(e)??[],{top:t,bottom:r}])};for(let n of e.values())r(t(n.id),n.y-AN,n.y+n.height+AN);return(e,t)=>{let i=t=>e.every(e=>(n.get(e)??[]).every(({top:e,bottom:n})=>t<=e||t>=n)),a=e.flatMap(e=>(n.get(e)??[]).flatMap(({top:e,bottom:t})=>[e,t])),o=t[0]??0,s=t.find(e=>i(e))??a.filter(e=>i(e)).toSorted((e,t)=>Math.abs(e-o)-Math.abs(t-o)||e-t)[0]??o;for(let t of e)r(t,s-AN,s+AN);return s}},MN=48,NN=36,PN=16,FN={flow:0,owner:0,back:14,message:-14},IN=(e,t)=>e.y+e.height/2+FN[t],LN=e=>e?.x??0,RN=e=>e?.y??0,zN=([e,t,n,r])=>({x:(LN(e)+3*LN(t)+3*LN(n)+LN(r))/8,y:(RN(e)+3*RN(t)+3*RN(n)+RN(r))/8}),BN=(e,t)=>({from:e.from,to:e.to,kind:e.kind,shape:`curve`,points:t,...e.label===void 0?{}:{label:e.label,labelAt:zN(t)}}),VN=(e,t,n)=>{let r=Math.max(NN,Math.abs(n.x-t.x)/2),i=n.x>=t.x?1:-1;return BN(e,[t,{x:t.x+r*i,y:t.y},{x:n.x-r*i,y:n.y},n])},HN=(e,t)=>{let n=Math.max(e.y,t.y),r=Math.min(e.y+e.height,t.y+t.height);return r-n<PN?void 0:(n+r)/2},UN=(e,t)=>{let n=t.x+t.width*.3,r=t.x+t.width*.7,i=t.y-30,a=BN(e,[{x:r,y:t.y},{x:r,y:i},{x:n,y:i},{x:n,y:t.y}]);return e.label===void 0?a:{...a,labelLimit:21}},WN=(e,t,n)=>{let r={x:t.x+t.width,y:IN(t,e.kind)},i={x:n.x+n.width,y:IN(n,e.kind)};return BN(e,[r,{x:r.x+MN,y:r.y},{x:i.x+MN,y:i.y},i])},GN=e=>{let t=[];for(let n of e){let e=t.at(-1),r=t.at(-2);(e?.x!==n.x||e.y!==n.y)&&(e!==void 0&&r!==void 0&&(r.x===e.x&&e.x===n.x||r.y===e.y&&e.y===n.y)&&t.pop(),t.push(n))}return t},KN=e=>{let t=e[0]??{x:0,y:0},n=-1;for(let[r,i]of e.slice(1).entries()){let a=e[r]??i,o=Math.abs(i.x-a.x)+Math.abs(i.y-a.y);o>n&&(n=o,t={x:(a.x+i.x)/2,y:(a.y+i.y)/2})}return t},qN=(e,t)=>{let n=GN(t);return{from:e.from,to:e.to,kind:e.kind,shape:`lines`,points:n,...e.label===void 0?{}:{label:e.label,labelAt:KN(n)}}},JN=e=>{let{chains:t,nodes:n,stopY:r,rankOf:i,columnX:a,columnWidth:o,gapWidth:s}=e,c=e=>a(e)+o,l=jN(n,i),u=t.filter(({stops:e})=>e.length>2),d=new Map,f=new Map;for(let{edge:e,stops:t}of u){let a=n.get(e.from),o=n.get(e.to);if(a!==void 0&&o!==void 0){let n=IN(a,e.kind),s=IN(o,e.kind),c=l(t.slice(1,-1).map(e=>{let[,t=``]=e.split(`:`);return Number(t)}),[n,s,...t.slice(1,-1).map(e=>r.get(e)??n)]);d.set(e.index,c);let u=Math.min(i(e.from),i(e.to)),p=Math.max(i(e.from),i(e.to));for(let t of[u,p-1])f.set(t,[...f.get(t)??[],e.index])}}let p=(e,t)=>{let n=f.get(e)??[];return c(e)+s(e)*(n.indexOf(t)+1)/(n.length+1)};return t.flatMap(({edge:e})=>{let t=n.get(e.from),r=n.get(e.to);if(t===void 0||r===void 0)return[];if(e.from===e.to)return[UN(e,t)];let a=i(e.from),o=i(e.to);if(a===o)return[WN(e,t,r)];let s=o>a,c={x:s?t.x+t.width:t.x,y:IN(t,e.kind)},l={x:s?r.x:r.x+r.width,y:IN(r,e.kind)},u=d.get(e.index);if(u===void 0){let n=HN(t,r);return[n===void 0?VN(e,c,l):VN(e,{...c,y:n},{...l,y:n})]}let f=Math.min(a,o),m=Math.max(a,o),h=p(s?f:m-1,e.index),g=p(s?m-1:f,e.index);return[qN(e,[c,{x:h,y:c.y},{x:h,y:u},{x:g,y:u},{x:g,y:l.y},l])]})},YN=({layers:e,chains:t,centers:n,space:r,reach:i})=>{let a=e=>n.get(e)??0,o=(e,t,o,s)=>{let c=a(e),l=t.map(e=>a(e)).toSorted((e,t)=>Math.abs(e-c)-Math.abs(t-c))[0];l!==void 0&&Math.abs(l-c)<i&&(o===void 0||a(o)+r(o,e)<=l)&&(s===void 0||l<=a(s)-r(e,s))&&n.set(e,l)},s=new Map,c=new Map;for(let{edge:e,stops:n}of t)e.kind===`flow`&&n.length===2&&(s.set(e.to,[...s.get(e.to)??[],e.from]),c.set(e.from,[...c.get(e.from)??[],e.to]));for(let t of e)for(let[e,n]of t.entries())o(n,s.get(n)??[],t[e-1],t[e+1]);for(let t of e)for(let[e,n]of t.entries())s.has(n)||o(n,c.get(n)??[],t[e-1],t[e+1])},XN=14,ZN=(e,t)=>`\0${String(e.index)}:${String(t)}`,QN=e=>e.startsWith(`\0`),$N=e=>(t,n)=>{let r=e=>QN(e)?0:23,i=QN(t)||QN(n)?XN:20;return r(t)+r(n)+Math.max(i,e.get(n)??0)},eP=e=>{let t=new Map;for(let{from:n,to:r,label:i}of e)n===r&&t.set(n,Math.max(t.get(n)??0,mj(i)));return t},tP=(e,t)=>e.map(e=>{let n=t.get(e.from)??0,r=t.get(e.to)??0,i=r>n?1:-1,a=Array.from({length:Math.max(Math.abs(r-n)-1,0)},(t,r)=>ZN(e,n+i*(r+1)));return{edge:e,stops:[e.from,...a,e.to]}}),nP=(e,t)=>e.flatMap(({stops:e})=>e.slice(1).flatMap((n,r)=>{let i=e[r]??n,a=t(i),o=t(n);return a===o?[]:a<o?[[i,n]]:[[n,i]]})),rP=(e,t)=>{let n=[...e.flatMap(e=>[e.x,e.x+e.width]),...t.flatMap(e=>e.points.map(e=>e.x))],r=[...e.flatMap(e=>[e.y,e.y+e.height]),...t.flatMap(e=>e.points.map(e=>e.y)),...t.flatMap(({label:e,labelAt:t,labelLimit:n})=>{if(e===void 0||t===void 0)return[];let r=pj(fj(e,n).length)/2;return[t.y-r,t.y+r]})];return{minX:Math.min(...n),minY:Math.min(...r),maxX:Math.max(...n),maxY:Math.max(...r)}},iP=(e,t)=>{let{minX:n,minY:r,maxX:i,maxY:a}=rP(e,t),o=16-n,s=16-r,c=({x:e,y:t})=>({x:e+o,y:t+s});return{nodes:e.map(e=>({...e,...c(e)})),edges:t.map(e=>({...e,points:e.points.map(c),...e.labelAt===void 0?{}:{labelAt:c(e.labelAt)}})),width:i-n+32,height:a-r+32}},aP=e=>{let t=e.nodes.map(e=>e.id),n=DN(e),r=kN(t,n),i=tP(n,r),a=new Map;for(let{edge:e,stops:t}of i){let n=r.get(e.from)??0,i=(r.get(e.to)??0)>n?1:-1;for(let[e,r]of t.slice(1,-1).entries())a.set(r,n+i*(e+1))}let o=e=>r.get(e)??a.get(e)??0,s=Math.max(0,...r.values()),c=Array.from({length:s+1},()=>[]);for(let e of[...t,...a.keys()])c[o(e)]?.push(e);let l=nP(i,o),u=$N(eP(n)),d=CN(c,l),f=EN(d,l,u);YN({layers:d,chains:i,centers:f,space:u,reach:20});let p=new Map;for(let{edge:e,stops:t}of i)if(e.label!==void 0&&e.from!==e.to&&t.length===2&&o(e.from)!==o(e.to)){let t=Math.min(o(e.from),o(e.to)),n=Math.max(...fj(e.label).map(e=>e.length))*gj+32;p.set(t,Math.max(p.get(t)??48,n))}let m=e=>p.get(e)??48,h=[0];for(let e=0;e<s;e+=1)h.push((h[e]??0)+152+m(e));let g=e=>h[e]??0,_=new Map(e.nodes.map(({id:e,type:t})=>{let n=o(e);return[e,{id:e,type:t,x:g(n),y:(f.get(e)??0)-23,width:152,height:46,rank:n}]})),v=JN({chains:i,nodes:_,stopY:f,rankOf:o,columnX:g,columnWidth:152,gapWidth:m});return iP([..._.values()],v)},oP=e=>typeof e==`object`&&!!e&&!Array.isArray(e),sP=e=>Array.isArray(e)?e.filter(e=>oP(e)):[],cP=e=>typeof e.description==`string`?e.description:void 0,lP=e=>e===!0?`On`:e===!1?`Off`:typeof e==`string`||typeof e==`number`?String(e):``,uP=e=>(Array.isArray(e.enum)?e.enum:`const`in e?[e.const]:e.type===`boolean`?[!0,!1]:void 0)?.map(e=>({value:e,label:lP(e)})),dP=e=>[...sP(e.anyOf),...sP(e.oneOf)],fP=e=>{let t=dP(e);if(t.length>0){let e=t.map(e=>uP(e));if(e.every(e=>e!==void 0))return{kind:`choice`,options:e.flat()};let[n]=t;return t.length===1&&n!==void 0?fP(n):{kind:`variants`,variants:t}}let n=uP(e);if(n!==void 0)return{kind:`choice`,options:n};if(e.type===`string`)return{kind:`text`,pattern:typeof e.pattern==`string`?e.pattern:void 0};if(e.type===`number`||e.type===`integer`)return{kind:`number`,integer:e.type===`integer`};if(e.type===`array`){let t=sP(e.prefixItems),[n]=t;return n===void 0?{kind:`list`,item:oP(e.items)?e.items:{}}:{kind:`list`,item:n,fixed:t.length}}if(e.type===`object`){if(oP(e.properties)){let t=Array.isArray(e.required)?e.required:[];return{kind:`object`,fields:Object.entries(e.properties).flatMap(([e,n])=>oP(n)?[{key:e,schema:n,required:t.includes(e)}]:[])}}return{kind:`record`,value:oP(e.additionalProperties)?e.additionalProperties:{}}}return{kind:`free`}},pP=(e,t)=>{let n=fP(e);switch(n.kind){case`text`:return typeof t==`string`;case`number`:return typeof t==`number`;case`choice`:return n.options.some(e=>e.value===t);case`list`:return Array.isArray(t);case`object`:case`record`:return oP(t);case`variants`:return n.variants.some(e=>pP(e,t));case`free`:return!0;default:return!1}},mP=(e,t)=>{let n=e.findIndex(e=>pP(e,t));return n===-1?0:n},hP=[[`text`,`Text`],[`number`,`Number`],[`choice`,`Choice`],[`list`,`List`],[`object`,`Details`],[`record`,`Named values`],[`variants`,`Other`],[`free`,`Anything`]],gP=e=>{let{kind:t}=fP(e);return hP.find(([e])=>e===t)?.[1]??t},_P=e=>{let t=fP(e);switch(t.kind){case`number`:return 0;case`choice`:return t.options[0]?.value;case`list`:return[];case`object`:case`record`:return{};case`text`:case`variants`:case`free`:return``;default:return t}},vP=e=>typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):``,yP={budgetUsd:`Budget (USD)`,budgetTokens:`Budget (tokens)`,plainEnv:`Plain environment`,env:`Environment`,cwd:`Working folder`,maxRounds:`Max rounds`,maxTurns:`Max turns`,maxMessages:`Max messages`,dayUsd:`Per day (USD)`,dayTokens:`Per day (tokens)`,weekUsd:`Per week (USD)`,monthUsd:`Per month (USD)`},bP=e=>{let t=yP[e];if(t!==void 0)return t;let n=e.replaceAll(/([a-z0-9])([A-Z])/gu,`$1 $2`).toLowerCase();return`${n.charAt(0).toUpperCase()}${n.slice(1)}`},xP=new Set([`prompt`,`instructions`,`question`,`script`,`body`,`command`]),SP=(e,t)=>xP.has(e)||typeof t==`string`&&t.includes(`
93
+ `),CP=e=>Number.isFinite(Number(e))&&String(Number(e))===e,wP=e=>{let t=e.trim();if(t!==``){if(t===`true`)return!0;if(t===`false`)return!1;if(t===`null`)return null;if(CP(t))return Number(t);if(!/^[[{"]/u.test(t))return e;try{return JSON.parse(t)}catch{return e}}},TP=e=>e===void 0?``:typeof e==`string`&&wP(e)===e?e:JSON.stringify(e),EP=(e,t)=>{let n=oP(e.properties)?e.properties.nodes:void 0,r=oP(n)?n.additionalProperties:void 0;return oP(r)?dP(r).find(e=>{let n=e.properties,r=oP(n)?n.type:void 0;return oP(r)&&r.const===t}):void 0},DP=e=>{let t=oP(e.properties)?e.properties.nodes:void 0,n=oP(t)?t.additionalProperties:void 0;return oP(n)?dP(n).flatMap(e=>{let t=e.properties,n=oP(t)?t.type:void 0;return oP(n)&&typeof n.const==`string`?[n.const]:[]}):[]},OP=e=>{let[t,n]=e.path;return t===`nodes`&&typeof n==`string`?n:void 0},kP=e=>{let t=e.path.at(-1);return e.message.endsWith(`received undefined`)&&typeof t==`string`?`${bP(t)} is required.`:e.message},AP=e=>{let t=new Map;for(let n of e){let e=OP(n);e!==void 0&&t.set(e,[...t.get(e)??[],n])}return t},jP=(e,t)=>`${String(e)} ${t}${e===1?``:`s`}`,MP=(e,t)=>{let n=AP(t),r=!t.some(({code:e})=>/^(schema|yaml)\./u.test(e));return new Map(e.nodes.map(({id:e})=>{let t=n.get(e)??[],i=t.filter(e=>e.severity===`error`).length,a=t.length-i;return i>0?[e,{status:`failed`,word:jP(i,`error`)}]:a>0?[e,{status:`waiting`,word:jP(a,`warning`)}]:[e,{status:`queued`,word:r?`no problems`:`not checked yet`}]}))},NP=(e,t)=>e.filter(e=>e.path.length===t.length&&e.path.every((e,n)=>e===t[n])),PP=(e,t)=>{let n=e;for(let e of t)if(Array.isArray(n)&&typeof e==`number`)n=n[e];else if(typeof n==`object`&&n&&!Array.isArray(n))n=Object.entries(n).find(([t])=>t===e)?.[1];else return;return n},FP=(e,t)=>e===t||e!==void 0&&t!==void 0&&JSON.stringify(e)===JSON.stringify(t),IP=e=>e.filter(e=>e.severity===`error`).length,LP=(e,t)=>{let n=(e.split(`.`).at(-1)??`node`).toLowerCase();if(!t.includes(n))return n;let r=2;for(;t.includes(`${n}-${String(r)}`);)r+=1;return`${n}-${String(r)}`},RP=new Set([`tool.gh`,`tool.aws`,`mcp.call`,`workflow.call`]),zP=e=>e.nodes.filter(({type:e})=>RP.has(e)).map(({id:e,type:t})=>`${e} (${t})`),BP=e=>e.nodes.filter(({type:e})=>e===`agent.leader`||e===`agent.worker`).map(({id:e})=>e),VP={panel:`_panel_16yrr_8`,tools:`_tools_16yrr_21`,chooser:`_chooser_16yrr_37`,create:`_create_16yrr_38`,actions:`_actions_16yrr_39`,connect:`_connect_16yrr_40`,notices:`_notices_16yrr_53`,status:`_status_16yrr_73`,error:`_error_16yrr_79`,empty:`_empty_16yrr_89`,body:`_body_16yrr_99`,palette:`_palette_16yrr_118`,inspector:`_inspector_16yrr_119`,middle:`_middle_16yrr_146`,canvas:`_canvas_16yrr_160`,problems:`_problems_16yrr_174`,clean:`_clean_16yrr_175`,problemsHead:`_problemsHead_16yrr_203`,walk:`_walk_16yrr_215`,problemList:`_problemList_16yrr_224`,types:`_types_16yrr_225`,edges:`_edges_16yrr_226`,problemLink:`_problemLink_16yrr_250`,heading:`_heading_16yrr_266`,subheading:`_subheading_16yrr_283`,type:`_type_16yrr_225`,fields:`_fields_16yrr_321`,edge:`_edge_16yrr_226`,testRow:`_testRow_16yrr_338`,field:`_field_16yrr_321`,choice:`_choice_16yrr_345`,problem:`_problem_16yrr_174`,problemIcon:`_problemIcon_16yrr_376`,problemWords:`_problemWords_16yrr_386`,hint:`_hint_16yrr_390`,group:`_group_16yrr_404`,summary:`_summary_16yrr_424`,row:`_row_16yrr_435`,rowName:`_rowName_16yrr_449`,edgeName:`_edgeName_16yrr_480`},HP=({builder:e})=>{let t=e.schema===null?[]:DP(e.schema),n=e.view?.graph.nodes.map(({id:e})=>e)??[],r=async t=>{let r=LP(t,n);await e.edit({op:`addNode`,id:r,node:{type:t}})&&e.select(r)};return(0,q.jsxs)(`nav`,{"aria-label":`Add a node`,className:VP.palette,children:[(0,q.jsx)(`h2`,{className:VP.heading,children:`Add a node`}),(0,q.jsx)(`ul`,{className:VP.types,children:t.map(e=>(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{className:VP.type,onClick:()=>{r(e)},type:`button`,children:[(0,q.jsx)(yM,{type:e}),eM(e)]})},e))})]})},UP=({problems:e,walk:t,onChoose:n})=>e.length===0?(0,q.jsxs)(`output`,{className:VP.clean,children:[`No problems found.`,t===null?``:` ${t}`]}):(0,q.jsxs)(`section`,{"aria-label":`Problems`,className:VP.problems,children:[(0,q.jsxs)(`div`,{className:VP.problemsHead,children:[(0,q.jsx)(`h2`,{className:VP.heading,children:IP(e)>0?`Fix these before saving`:`Warnings`}),t===null?null:(0,q.jsx)(`p`,{className:VP.walk,children:t})]}),(0,q.jsx)(`ul`,{className:VP.problemList,children:e.map(e=>{let t=OP(e),r=`${e.code} ${e.path.join(`.`)} ${e.message}`;return(0,q.jsx)(`li`,{children:t===void 0?(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:kP(e)})}):(0,q.jsxs)(`button`,{className:VP.problemLink,onClick:()=>{n(t)},type:`button`,children:[kP(e).startsWith(`\`${t}\``)?null:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`code`,{children:t}),`:`,` `]}),(0,q.jsx)(r_,{text:kP(e)})]})},r)})})]}),WP={fields:[],canFail:!1,canDeclare:!1},GP=3,KP=(e,t)=>e.says?.[t]??WP,qP={is:`is`,isnt:`isn't`,above:`is above`,atLeast:`is at least`,below:`is below`,atMost:`is at most`,contains:`contains`,anyIs:`any is`,allAre:`all are`,isTrue:`is true`,isFalse:`is false`},JP={values:[`is`,`isnt`],statuses:[`anyIs`,`allAre`],number:[`above`,`atLeast`,`below`,`atMost`,`is`,`isnt`],boolean:[`isTrue`,`isFalse`],text:[`contains`,`is`,`isnt`]},YP=e=>JP[e.kind],XP=e=>e!==`isTrue`&&e!==`isFalse`,ZP=e=>e.filter(({items:e})=>e===void 0),QP=(e,t)=>{let n=ZP(t).find(({field:t})=>t===e.field);return n===void 0||!YP(n).includes(e.test)?!1:n.values===void 0||e.value===void 0||n.values.includes(e.value)},$P=({condition:e,when:t},n)=>{let r=e??{mode:`succeeds`};return r.mode===`test`&&!r.rows.every(e=>QP(e,n.fields))?{mode:`hand`,text:t??``}:r},eF=(e,t)=>{let n=YP(e)[0]??`is`;if(!XP(n))return{field:e.field,test:n};let r=e.values?.[0]??(e.kind===`number`?0:``);return{field:e.field,test:n,value:t??r}},tF=(e,t)=>{let n=ZP(e.fields),r=n.find(({values:e})=>(e??[]).length>0)??n[0];return r===void 0?void 0:eF(r,r.values?.includes(t??``)===!0?t:void 0)},nF=e=>e.fields.flatMap(({field:e,values:t})=>e===`choice`?(t??[]).map(String):[]),rF=({condition:e},t)=>e===void 0||e.mode===`succeeds`||e.mode===`test`&&e.rows.some(({test:e,value:n})=>e===`is`&&n===t),iF=(e,t)=>{let n=e.edges.filter(({from:e})=>e===t);return n.length===0?[]:nF(KP(e,t)).filter(e=>!n.some(t=>rF(t,e)))},aF=(e,t,n)=>{let r=new Set([t]),i=[t];for(let t of i)for(let n of e.edges)n.from===t&&!r.has(n.to)&&(r.add(n.to),i.push(n.to));return r.has(n)},oF=e=>e===void 0?void 0:jw({mode:`test`,join:`all`,rows:[e]}),sF=(e,t,n)=>{let r=KP(e,t);if(aF(e,n,t))return oF(tF(r,`changes_requested`));let i=e.edges.filter(e=>e.from===t),a=nF(r);if(a.length>0){let[n]=i.length===0?a:iF(e,t);return n===void 0?void 0:oF({field:`choice`,test:`is`,value:n})}let o=i.find(({maxRounds:e})=>e!==void 0);return o?.condition===void 0?e.nodes.find(({id:e})=>e===t)?.type===`control.router`?oF(tF(r))??`true`:void 0:Nw(o.condition)},cF=(e,t,n)=>{let r=sF(e,t,n);return{op:`connect`,from:t,to:n,...r===void 0?{}:{when:r},...aF(e,n,t)?{maxRounds:GP}:{}}},lF=e=>typeof e==`object`&&!!e&&!Array.isArray(e),uF=(e,t)=>{let n=new Set,r=[t];for(let t of r)for(let i of e.edges)i.to===t&&i.maxRounds===void 0&&!n.has(i.from)&&(n.add(i.from),r.push(i.from));return n.delete(t),n},dF=(e,t)=>{let n=uF(e,t);return e.nodes.filter(e=>n.has(e.id)).flatMap(t=>KP(e,t.id).fields.flatMap(({field:e,items:n})=>n===void 0?[]:[{node:t.id,field:e,items:n,template:`{{nodes.${t.id}.output.${e}}}`}]))},fF=e=>lF(e)?`from`in e?`from`:`items`in e?`items`:`once`:`once`,pF=10,mF=(e,t)=>{if(t===`once`)return;let n=lF(e)?e:{},r=Object.fromEntries(Object.entries(n).filter(([e])=>e===`maxParallel`||e===`onFailure`));return t===`items`?{items:[``],...r}:{from:``,maxItems:pF,...r}},hF=e=>{let t=Number(e.trim());return e.trim()!==``&&Number.isSafeInteger(t)&&t>0?t:void 0},gF=/^[A-Za-z_][A-Za-z0-9_-]*$/u,_F=[`string`,`number`,`integer`,`boolean`],vF=e=>{let t=new Map,n=[];for(let r of e.split(`,`)){let e=r.trim();if(e===``)continue;let[i=``,a=`string`,...o]=e.split(`:`).map(e=>e.trim());!gF.test(i)||o.length>0?n.push(`\`${e}\` isn't a field name. Use letters, digits, _ or -, then an optional :type.`):_F.some(e=>e===a)?t.has(i)?n.push(`\`${i}\` is listed twice.`):t.set(i,a):n.push(`\`${e}\` isn't a type. Use string, number, integer or boolean.`)}return{shape:Object.fromEntries(t),problems:n}},yF=e=>gF.test(e),bF=(e,t,n)=>n&&(t||e.startsWith(`agent.`)),xF=(e,t)=>e.startsWith(`agent.`)?t:`json.${t}`,SF=e=>{let t=(Array.isArray(e)?e:[]).map(e=>lF(e)?Object.keys(e):[]),[n=[]]=t;return n.filter(e=>t.every(t=>t.includes(e)))},CF=(e,t)=>{if(!lF(t))return[];if(`items`in t)return SF(t.items);let n=t.from;if(typeof n!=`string`)return[];let r=/^\{\{\s*nodes\.([^.\s]+)\.output\.(.+?)\s*\}\}$/u.exec(n);return KP(e,r?.[1]??``).fields.find(({field:e})=>e===r?.[2])?.items?.map(e=>e.field)??[]},wF=new Set([`prompt`,`command`,`arguments`,`inputs`,`env`,`ref`]),TF=(e,t,n,r)=>{let[i,,a]=t;if(i!==`nodes`||typeof a!=`string`||!wF.has(a)||!lF(n))return r;let o=CF(e,n);return[r,`Reads ${["`{{item}}` and `{{index}}`",...o.length===0?[]:[o.map(e=>`\`{{item.${e}}}\``).join(`, `)]].join(`, and `)}.`].filter(Boolean).join(` `)},EF=e=>{let t=fP(e),n=t.kind===`variants`?t.variants[0]:void 0,r=n===void 0?void 0:n.properties,i=lF(r)?r.items:void 0;return lF(i)?i:{}},DF=(e,t,n)=>{let r=uF(e,n);return e.nodes.flatMap(({id:n,type:i})=>{let a=KP(e,n),o=t===null?void 0:EP(t,i),s=o===void 0?void 0:o.properties;return r.has(n)&&!a.fields.some(({kind:e})=>e===`statuses`)&&bF(i,a.canDeclare,lF(s)&&`output`in s)?[{id:n,type:i,fields:a.fields.map(({field:e})=>e.replace(/^json\./u,``))}]:[]})},OF=(e,t)=>{e.context.change(e.path,()=>t)},kF=e=>typeof e==`object`&&!!e&&!Array.isArray(e),AF=({lines:e})=>e.map(e=>(0,q.jsxs)(`p`,{className:VP.problem,children:[(0,q.jsx)(`span`,{className:VP.problemIcon,children:(0,q.jsx)(Ij,{})}),(0,q.jsx)(`span`,{className:VP.problemWords,children:(0,q.jsx)(r_,{text:e})})]},e)),jF=({label:e,unseen:t,shown:n,commit:r,description:i,required:a=!1,multiline:o=!1,number:s=!1})=>{let[c,l]=(0,U.useState)(n),[u,d]=(0,U.useState)(n),[f,p]=(0,U.useState)(null);return u!==n&&(d(n),p(null),n!==f&&l(n)),(0,q.jsx)(mk,{description:i,label:e,unseen:t,multiline:o,onChange:l,onCommit:()=>{c!==n&&c!==f&&(p(c),r(c))},required:a,type:s?`number`:`text`,value:c})},MF=`__not_set__`,NF=({options:e,...t})=>{let{name:n,schema:r,value:i,required:a}=t,o=[...a&&i!==void 0?[]:[{value:MF,label:a?`Choose one`:`Default`}],...e.map(e=>({value:vP(e.value),label:e.label}))],s=cP(r);return(0,q.jsxs)(`div`,{className:VP.choice,children:[(0,q.jsx)(dk,{label:bP(n),onChange:n=>{OF(t,n===MF?void 0:e.find(e=>vP(e.value)===n)?.value)},options:o,value:i===void 0?o[0]?.value??``:vP(i)}),s===void 0?null:(0,q.jsx)(`p`,{className:VP.hint,children:(0,q.jsx)(r_,{text:s})})]})},PF=({name:e,description:t,open:n,children:r})=>(0,q.jsxs)(`details`,{className:VP.group,open:n,children:[(0,q.jsx)(`summary`,{className:VP.summary,children:bP(e)}),t===void 0?null:(0,q.jsx)(`p`,{className:VP.hint,children:(0,q.jsx)(r_,{text:t})}),(0,q.jsx)(`div`,{className:VP.fields,children:r})]}),FF=/^[A-Za-z_][A-Za-z0-9_-]*$/u,IF=e=>e.split(`,`).map(e=>e.trim()).filter(e=>e!==``).map(e=>e===`true`?!0:e===`false`?!1:Number.isFinite(Number(e))?Number(e):e),LF=({to:e,onDeclare:t})=>{let[n,r]=(0,U.useState)(!1),[i,a]=(0,U.useState)(``),[o,s]=(0,U.useState)(``);if(!n)return(0,q.jsxs)(Y,{onClick:()=>{r(!0)},children:[`Add a field`,(0,q.jsxs)(uk,{children:[`, to `,e]})]});let c=IF(o);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(mk,{description:`A field of the JSON this node gives, such as state.`,label:`New field`,unseen:`, to ${e}`,onChange:a,value:i}),(0,q.jsx)(mk,{description:`Separated by commas. A run fails this node on anything else.`,label:`Its values`,unseen:`, to ${e}`,onChange:s,value:o}),(0,q.jsxs)(Y,{disabled:!FF.test(i)||c.length===0,onClick:()=>{t(i,c),r(!1),a(``),s(``)},children:[`Add `,i===``?`field`:i]})]})},RF=(e,t)=>{e?.querySelector(t)?.focus()},zF=({to:e,holders:t,onDeclare:n})=>{let r=(0,U.useRef)(null),[i,a]=(0,U.useState)(!1),[o,s]=(0,U.useState)(null),[c,l]=(0,U.useState)(``),[u,d]=(0,U.useState)(``),f=t.find(({id:e})=>e===o)??t[0];if(f===void 0)return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(Y,{disabled:!0,children:[`Add a list`,(0,q.jsxs)(uk,{children:[`, for `,e]})]}),(0,q.jsx)(`p`,{className:VP.hint,children:`No earlier node can declare a list. A list comes from a Claude node, tool or MCP call that runs before this one.`})]});if(!i)return(0,q.jsx)(`div`,{ref:r,children:(0,q.jsxs)(Y,{onClick:()=>{a(!0),queueMicrotask(()=>{RF(r.current,`input, [role=combobox]`)})},children:[`Add a list`,(0,q.jsxs)(uk,{children:[`, for `,e]})]})});let p=vF(u),m=f.fields.includes(c),h=c!==``&&!yF(c)?[`\`${c}\` isn't a name. Use letters, digits, _ or -.`]:m?[`\`${c}\` is already a field of \`${f.id}\`.`]:[],g=()=>{a(!1),l(``),d(``),queueMicrotask(()=>{RF(r.current,`button`)})};return(0,q.jsxs)(`div`,{className:VP.fields,ref:r,children:[t.length<2?null:(0,q.jsx)(dk,{label:`On node`,onChange:s,options:t.map(({id:e})=>({value:e,label:e})),value:f.id}),(0,q.jsx)(mk,{description:`A field of the JSON that node gives, such as tasks.`,label:`New list`,onChange:l,value:c}),(0,q.jsx)(AF,{lines:h}),(0,q.jsx)(mk,{description:`Separated by commas: a name, or name:type. Types: string, number, integer, boolean. Empty for items with no fields.`,label:`Item fields`,onChange:d,value:u}),(0,q.jsx)(AF,{lines:p.problems}),(0,q.jsxs)(Y,{disabled:!yF(c)||m||p.problems.length>0,onClick:()=>{n(f.id,c,p.shape),g()},children:[`Add `,c===``?`list`:c]}),(0,q.jsx)(Y,{onClick:g,children:`Cancel`})]})},BF=(e,t)=>t&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):e,VF=({row:e,fields:t,to:n,index:r,onChange:i})=>{let a=t.find(({field:t})=>t===e.field),o=`${r===0?``:`${String(r+1)} `}to ${n}`;if(a===void 0)return null;let s=a.values??[];return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(dk,{label:`Field`,unseen:`, ${o}`,onChange:e=>{let n=t.find(t=>t.field===e);n!==void 0&&i(eF(n))},options:t.map(({field:e})=>({value:e,label:e})),value:e.field}),(0,q.jsx)(dk,{label:`Test`,unseen:`, ${o}`,onChange:t=>{let n=t,{value:r}=eF(a);i({field:e.field,test:n,...XP(n)?{value:e.value??r??``}:{}})},options:YP(a).map(e=>({value:e,label:qP[e]})),value:e.test}),XP(e.test)&&s.length>0?(0,q.jsx)(dk,{label:`Value`,unseen:`, ${o}`,onChange:t=>{i({...e,value:s.find(e=>String(e)===t)??t})},options:s.map(e=>({value:String(e),label:String(e)})),value:String(e.value)}):null,XP(e.test)&&s.length===0?(0,q.jsx)(jF,{commit:t=>{i({...e,value:BF(t,a.kind===`number`)})},label:`Value`,unseen:`, ${o}`,number:a.kind===`number`,shown:String(e.value??``)}):null]})},HF=e=>`row ${String(e)}`,UF=({condition:e,says:t,to:n,onChange:r})=>{let{rows:i,join:a}=e,o=e=>{r({mode:`test`,join:a,rows:e})},s=tF(t);return(0,q.jsxs)(q.Fragment,{children:[i.length<2?null:(0,q.jsx)(dk,{label:`Which tests`,unseen:`, to ${n}`,onChange:e=>{r({mode:`test`,join:e===`any`?`any`:`all`,rows:i})},options:[{value:`all`,label:`All of these`},{value:`any`,label:`Any of these`}],value:a}),i.map((e,r)=>(0,q.jsxs)(`div`,{className:VP.testRow,children:[(0,q.jsx)(VF,{fields:ZP(t.fields),index:r,onChange:e=>{o(i.map((t,n)=>n===r?e:t))},row:e,to:n}),i.length<2?null:(0,q.jsxs)(Y,{onClick:()=>{o(i.filter((e,t)=>t!==r))},children:[`Remove test `,String(r+1),(0,q.jsxs)(uk,{children:[`, to `,n]})]})]},HF(r))),s===void 0?null:(0,q.jsxs)(Y,{onClick:()=>{o([...i,s])},children:[`Add a test`,(0,q.jsxs)(uk,{children:[`, to `,n]})]})]})},WF=({to:e,says:t,condition:n,when:r,loop:i,gate:a,canBeOtherwise:o,onChange:s,onDeclare:c})=>{let[l,u]=(0,U.useState)(!1),d=tF(t),f=l?`hand`:n.mode,p=e=>{u(e===`hand`),e!==`hand`&&(e===`fails`?s(`!ok`):e===`otherwise`?s(`true`):e===`succeeds`?s():d!==void 0&&s(jw({mode:`test`,join:`all`,rows:[d]})))},m=[{value:`succeeds`,label:i?`Every round`:a?`Whatever the answer`:`When it succeeds`},...t.canFail?[{value:`fails`,label:`When it fails`}]:[],...d===void 0?[]:[{value:`test`,label:`When a test holds`}],...o?[{value:`otherwise`,label:`Otherwise`}]:[],{value:`hand`,label:`Written by hand`}];return(0,q.jsxs)(`div`,{className:VP.fields,children:[(0,q.jsx)(dk,{label:`Follow this edge`,unseen:`, to ${e}`,onChange:p,options:m,value:f}),f===`test`&&n.mode===`test`?(0,q.jsx)(UF,{condition:n,onChange:e=>{s(jw(e))},says:t,to:e}):null,f===`hand`?(0,q.jsx)(jF,{commit:e=>{s(e===``?void 0:e)},description:`An expression, such as status == 'pass'. It's kept as you write it.`,label:`Condition`,unseen:`, to ${e}`,shown:r??``}):null,t.canDeclare?(0,q.jsx)(LF,{onDeclare:c,to:e}):null]})},GF=e=>e.when===void 0?{}:{whenWas:e.when},KF=({edge:e,last:t,builder:n})=>{let{from:r,to:i}=e,a=n.view?.graph;if(a===void 0)return null;let o=a.nodes.find(({id:e})=>e===r)?.type,s=KP(a,r),c=e.maxRounds===void 0?{}:{maxRounds:e.maxRounds},l=t=>({op:`setEdge`,from:r,to:i,...t===void 0?{}:{when:t},...c,...GF(e)}),u=e.maxRounds!==void 0;return(0,q.jsxs)(`li`,{className:VP.edge,children:[(0,q.jsxs)(`p`,{className:VP.edgeName,children:[`To `,i]}),(0,q.jsx)(WF,{canBeOtherwise:o===`control.router`&&t,condition:$P(e,s),gate:o===`human.gate`,loop:u,onChange:e=>{n.edit(l(e))},onDeclare:(e,t)=>{let[i]=t;n.edit({op:`set`,path:[`nodes`,r,`output`,`schema`,e],value:t},l(jw({mode:`test`,join:`all`,rows:[{field:`json.${e}`,test:`is`,...i===void 0?{}:{value:i}}]})))},says:s,to:i,when:e.when}),(0,q.jsx)(jF,{commit:t=>{n.edit({op:`setEdge`,from:r,to:i,...e.when===void 0?{}:{when:e.when},...t===``?{}:{maxRounds:Number(t)},...GF(e)})},description:`Needed on an edge that closes a loop.`,label:`Max rounds`,unseen:`, to ${i}`,number:!0,shown:e.maxRounds===void 0?``:String(e.maxRounds)}),(0,q.jsxs)(Y,{onClick:()=>{n.edit({op:`disconnect`,from:r,to:i,...GF(e)})},children:[`Remove edge`,(0,q.jsxs)(uk,{children:[` to `,i]})]})]})},qF=({id:e,builder:t})=>{let n=t.view?.graph,[r,i]=(0,U.useState)(``);if(n===void 0)return null;let a=n.edges.filter(({from:t})=>t===e),o=n.edges.filter(({to:t})=>t===e),s=n.nodes.map(e=>e.id).filter(e=>!a.some(({to:t})=>t===e)).toSorted((t,n)=>Number(t===e)-Number(n===e)),c=s.includes(r)?r:s[0]??``,l=iF(n,e);return(0,q.jsxs)(`section`,{"aria-label":`Edges of ${e}`,className:VP.fields,children:[(0,q.jsx)(`h3`,{className:VP.subheading,children:`Edges`}),o.length===0?null:(0,q.jsxs)(`p`,{className:VP.hint,children:[`From `,o.map(({from:e})=>e).join(`, `)]}),a.length===0?(0,q.jsx)(`p`,{className:VP.hint,children:`Nothing follows this node yet.`}):(0,q.jsx)(`ul`,{className:VP.edges,children:a.map((e,n)=>(0,q.jsx)(KF,{builder:t,edge:e,last:n===a.length-1},`${e.to} ${String(a.slice(0,n).filter(({to:t})=>t===e.to).length)}`))}),l.length===0?null:(0,q.jsxs)(`p`,{className:VP.hint,children:[`Answering `,l.join(` or `),` ends the run here.`]}),s.length===0?null:(0,q.jsxs)(`div`,{className:VP.connect,children:[(0,q.jsx)(dk,{label:`Connect to`,onChange:i,options:s.map(e=>({value:e,label:e})),value:c}),(0,q.jsx)(Y,{onClick:()=>{t.edit(cF(n,e,c))},children:`Connect`}),(0,q.jsx)(Y,{"aria-pressed":t.connecting,onClick:()=>{t.setConnecting(!t.connecting)},children:t.connecting?`Cancel picking`:`Pick a card`})]})]})},JF=()=>{},YF=e=>Array.isArray(e)?e:[],XF=({name:e,path:t,schema:n,value:r,context:i,item:a,fixed:o,minRows:s=0,draw:c})=>{let l=Array.isArray(r)?r:[];return(0,q.jsxs)(PF,{description:cP(n),name:e,open:l.length>0,children:[l.map((n,r)=>(0,q.jsxs)(`div`,{className:VP.row,children:[c({context:i,name:`${e} ${String(r+1)}`,path:[...t,r],required:!0,schema:a,value:n}),o===void 0&&l.length>s?(0,q.jsxs)(Y,{onClick:()=>{i.change(t,e=>{let t=YF(e).filter((e,t)=>t!==r);return t.length===0?void 0:t})},children:[`Remove `,bP(e).toLowerCase(),` `,r+1]}):null]},r)),o!==void 0&&l.length>=o?null:(0,q.jsxs)(Y,{onClick:()=>{i.change(t,e=>[...YF(e),_P(a)])},children:[`Add to `,bP(e).toLowerCase()]})]})},ZF=({name:e,path:t,schema:n,value:r,context:i,valueSchema:a,draw:o})=>{let s=kF(r)?Object.entries(r):[],[c,l]=(0,U.useState)(``),u=c.trim(),d=s.some(([e])=>e===u);return(0,q.jsxs)(PF,{description:cP(n),name:e,open:s.length>0,children:[s.map(([e,n])=>(0,q.jsxs)(`div`,{className:VP.row,children:[o({context:i,name:e,path:[...t,e],required:!0,schema:a,value:n}),(0,q.jsxs)(Y,{onClick:()=>{i.change([...t,e],JF)},children:[`Remove `,e]})]},e)),(0,q.jsx)(mk,{description:d?`${u} is already here.`:void 0,label:`New name in ${bP(e).toLowerCase()}`,onChange:l,value:c}),(0,q.jsxs)(Y,{disabled:u===``||d,focusableWhenDisabled:!0,onClick:()=>{i.change([...t,u],e=>e===void 0?_P(a):e),l(``)},children:[`Add to `,bP(e).toLowerCase()]})]})},QF=e=>{let{name:t,value:n,variants:r,draw:i}=e,a=mP(r,n),o=r[a]??{};return(0,q.jsxs)(`div`,{className:VP.fields,children:[(0,q.jsx)(dk,{label:`${bP(t)} as`,onChange:t=>{OF(e,_P(r[Number(t)]??{}))},options:r.map((e,t)=>({value:String(t),label:gP(e)})),value:String(a)}),i({...e,schema:o})]})},$F=e=>(0,q.jsx)(nI,{...e}),eI=({fields:e,value:t,path:n,context:r})=>{let i=kF(t)?t:{};return(0,q.jsx)(q.Fragment,{children:e.map(({key:e,schema:t,required:a})=>(0,q.jsx)(nI,{context:r,name:e,path:[...n,e],required:a,schema:t,value:i[e]},e))})},tI=e=>{let{name:t,path:n,schema:r,value:i,required:a,context:o}=e,s=fP(r),c=cP(r);switch(s.kind){case`text`:return(0,q.jsx)(jF,{commit:t=>{OF(e,t===``&&!a?void 0:t)},description:c,label:bP(t),multiline:SP(t,i),required:a,shown:typeof i==`string`?i:``});case`number`:return(0,q.jsx)(jF,{commit:t=>{OF(e,t===``?void 0:Number(t))},description:c,label:bP(t),number:!0,required:a,shown:typeof i==`number`?String(i):``});case`choice`:return(0,q.jsx)(NF,{...e,options:s.options});case`object`:return(0,q.jsx)(PF,{description:c,name:t,open:kF(i)&&Object.keys(i).length>0,children:(0,q.jsx)(eI,{context:o,fields:s.fields,path:n,value:i})});case`list`:return(0,q.jsx)(XF,{...e,draw:$F,fixed:s.fixed,item:s.item,minRows:typeof r.minItems==`number`?r.minItems:0});case`record`:return(0,q.jsx)(ZF,{...e,draw:$F,valueSchema:s.value});case`variants`:return(0,q.jsx)(QF,{...e,draw:$F,variants:s.variants});case`free`:return(0,q.jsx)(jF,{commit:t=>{OF(e,wP(t))},description:c??`Text, or JSON for a number or a list. Quote text that looks like either, such as "5".`,label:bP(t),multiline:typeof i==`string`&&i.includes(`
94
+ `),shown:TP(i)});default:return s}},nI=e=>{let{path:t,context:n,schema:r}=e,i=n.problems(t),a=t.length===3?n.hint?.(t,cP(r)):void 0,o=a===void 0?e:{...e,schema:{...r,description:a}};return(0,q.jsxs)(`div`,{className:VP.field,"data-problem":i.length>0?``:void 0,children:[n.custom?.(e)??tI(o),(0,q.jsx)(AF,{lines:i})]})},rI=e=>Array.isArray(e)?e:[],iI=({field:e,catalog:t})=>{let n=Array.isArray(e.value)?e.value.filter(e=>typeof e==`string`):[],[r,i]=(0,U.useState)(``),a=t=>{e.context.change(e.path,e=>rI(e).includes(t)?e:[...rI(e),t])},o=t.skills.filter(({name:e})=>!n.includes(e));return(0,q.jsxs)(`div`,{className:VP.fields,children:[(0,q.jsx)(`h3`,{className:VP.subheading,children:`Skills`}),n.length===0?(0,q.jsx)(`p`,{className:VP.hint,children:`It gets what the workflow and the project give it.`}):(0,q.jsx)(`ul`,{className:VP.edges,children:n.map(t=>(0,q.jsxs)(`li`,{className:VP.row,children:[(0,q.jsx)(`span`,{className:VP.rowName,children:t}),(0,q.jsxs)(Y,{onClick:()=>{e.context.change(e.path,e=>{let n=rI(e).filter(e=>e!==t);return n.length===0?void 0:n})},children:[`Remove `,t]})]},t))}),(0,q.jsx)(aC,{empty:`No skill matches.`,label:`Add a skill`,onChange:e=>{e!==null&&a(e)},options:o.map(({name:e,layer:t})=>({value:e,label:`${e} (${t})`})),placeholder:o.length===0?`No skills found`:`Type to find a skill`,value:null}),(0,q.jsx)(mk,{description:`Or a path to one, such as ./skills/checklist.`,label:`Skill by path`,onChange:i,onCommit:()=>{r.trim()!==``&&a(r.trim()),i(``)},value:r})]})},aI=(e,t)=>fP(t.schema).kind===`list`?(0,q.jsx)(iI,{catalog:e.catalog,field:t}):null,oI=`stop looking`,sI=({says:e,condition:t,until:n,onChange:r,onDeclare:i})=>{let[a,o]=(0,U.useState)(!1),s=$P({condition:t,when:n},e),c=tF(e),l=!a&&s.mode===`test`,u=n===void 0&&!a,d=u?`unset`:l?`test`:`hand`;return(0,q.jsxs)(`div`,{className:VP.fields,children:[(0,q.jsx)(dk,{label:`Look until`,onChange:e=>{o(e===`hand`),e===`test`&&c!==void 0&&r(jw({mode:`test`,join:`all`,rows:[c]}))},options:[...u?[{value:`unset`,label:`Choose one`}]:[],...c===void 0?[]:[{value:`test`,label:`A test holds`}],{value:`hand`,label:`Written by hand`}],value:d}),l?(0,q.jsx)(UF,{condition:s,onChange:e=>{r(jw(e))},says:e,to:oI}):null,d===`hand`?(0,q.jsx)(jF,{commit:e=>{r(e===``?void 0:e)},description:`An expression, such as json.state != 'pending'. It's kept as you write it.`,label:`Condition`,shown:n??``,unseen:`, to ${oI}`}):null,e.canDeclare?(0,q.jsx)(LF,{onDeclare:i,to:oI}):null]})},cI=({builder:e,id:t,field:n})=>{let r=e.view?.graph;return r===void 0?null:(0,q.jsx)(sI,{condition:r.untils?.[t],onChange:e=>{OF(n,e)},onDeclare:(n,r)=>{let[i]=r;e.edit({op:`set`,path:[`nodes`,t,`output`,`schema`,n],value:r},{op:`set`,path:[`nodes`,t,`watch`,`until`],value:`json.${n} == ${JSON.stringify(i)}`})},says:KP(r,t),until:typeof n.value==`string`?n.value:void 0})},lI=`__none__`,uI=(e,t)=>{let{document:n}=e.view??{},r=kF(n)?n.inputs:void 0,i=kF(r)?r[String(t.path[1])]:void 0,a=kF(i)?i.type:void 0,o=typeof a==`string`?a:`string`;return t.value===void 0||typeof t.value===o?tI({...t,schema:{...t.schema,type:o}}):null},dI=(e,t,n)=>{let r=e.view?.graph;if(r===void 0)return null;let i=n.path.at(-1),a=typeof n.value==`string`?n.value:void 0;if(i===`parent`&&t!==null){let e=r.nodes.map(e=>e.id).filter(e=>e!==t);return(0,q.jsx)(dk,{label:`Owner`,onChange:e=>{OF(n,e===lI?void 0:e)},options:[...n.required?[]:[{value:lI,label:`None`}],...e.map(e=>({value:e,label:e}))],value:a??lI})}if(i===`n`&&t!==null&&n.path.length===3){let e=r.edges.filter(({to:e})=>e===t).length,i=typeof n.value==`number`?n.value:1,a=Array.from({length:Math.max(e,i,1)},(e,t)=>String(t+1));return(0,q.jsx)(dk,{label:`How many inputs to wait for`,onChange:e=>{OF(n,Number(e))},options:a.map(e=>({value:e,label:e})),value:String(i)})}if((i===`recommended`||i==="default")&&t!==null&&n.path.length===3){let e=KP(r,t).fields.find(({field:e})=>e===`choice`)?.values??[];if(e.length>0)return(0,q.jsx)(dk,{label:i==="default"?`If it times out`:`Recommended`,onChange:e=>{OF(n,e===lI?void 0:e)},options:[{value:lI,label:`None`},...e.map(e=>({value:String(e),label:String(e)}))],value:a??lI})}return i===`until`&&t!==null&&n.path.includes(`watch`)?(0,q.jsx)(cI,{builder:e,field:n,id:t}):i===`to`&&n.path.includes(`notify`)?(0,q.jsx)(dk,{label:`To`,onChange:e=>{OF(n,e)},options:BP(r).map(e=>({value:e,label:e})),value:a??``}):i===`agent`?(0,q.jsx)(aC,{empty:`No agent matches.`,label:`Agent`,onChange:e=>{OF(n,e??void 0)},options:e.catalog.agents.map(({name:e,source:t})=>({value:e,label:`${e} (${t})`})),placeholder:`Type to find an agent`,value:a??null}):i==="default"&&n.path[0]===`inputs`?uI(e,n):i===`skills`?aI(e,n):null},fI=`__not_chosen__`,pI=[{value:`once`,label:`Once`},{value:`items`,label:`Once per item, listed here`},{value:`from`,label:`Once per item of a list from an earlier node`}],mI=({field:e,label:t,description:n,required:r,bad:i,onBad:a})=>(0,q.jsxs)(`div`,{className:VP.field,children:[(0,q.jsx)(jF,{commit:t=>{let n=hF(t),i=t.trim()===``&&!r;a(n===void 0&&!i),(n!==void 0||i)&&OF(e,n)},description:n,label:t,number:!0,required:r,shown:typeof e.value==`number`?String(e.value):``}),(0,q.jsx)(`div`,{role:`alert`,children:(0,q.jsx)(AF,{lines:i?[`${t} needs a whole number above 0.`]:[]})})]}),hI=({builder:e,id:t,field:n})=>{let r=e.view?.graph,i=(0,U.useRef)(null),[a,o]=(0,U.useState)(!1),[s,c]=(0,U.useState)(!1),l=fF(n.value),[u,d]=(0,U.useState)(l!==`once`);if(l!==`once`&&!u&&d(!0),r===void 0)return null;let{value:f,context:p,path:m}=n,h=kF(f)?f:{},g=typeof h.from==`string`?h.from:``,_=dF(r,t),v=_.find(({template:e})=>e===g),y=DF(r,e.schema,t),b=async(t,n,r)=>{let a=`{{nodes.${t}.output.${xF(y.find(e=>e.id===t)?.type??``,n)}}}`;await e.edit({op:`set`,path:[`nodes`,t,`output`,`schema`,n],value:{list:r}},{op:`set`,path:[...m,`from`],value:a}),i.current?.querySelectorAll(`[role=combobox]`)[1]?.focus()},x=e=>({...n,name:e,path:[...m,e],value:h[e]});return(0,q.jsx)(PF,{description:cP(n.schema),name:`forEach`,open:u,children:(0,q.jsxs)(`div`,{className:VP.fields,ref:i,children:[(0,q.jsx)(dk,{label:`Run this node`,onChange:e=>{OF(n,mF(f,e))},options:pI,value:l}),l===`once`?null:(0,q.jsx)(`p`,{className:VP.hint,children:(0,q.jsx)(r_,{text:`Items are \`${t}.0\` to \`${t}.n\`. Their results gather into \`results\`, \`statuses\` and \`count\`.`})}),l===`items`?(0,q.jsx)(nI,{...x(`items`),required:!0,schema:EF(n.schema)}):null,l===`from`?(0,q.jsxs)(`div`,{className:VP.field,children:[(0,q.jsx)(dk,{label:`List from`,onChange:e=>{let t=_.find(({template:t})=>t===e);t!==void 0&&p.change([...m,`from`],()=>t.template)},options:[...g===``?[{value:fI,label:`Choose a list`}]:[],...g===``||v!==void 0?[]:[{value:g,label:`${g} (not offered)`}],..._.map(({node:e,field:t,template:n})=>({value:n,label:`${t} (from ${e})`}))],value:g===``?fI:g}),(0,q.jsx)(AF,{lines:p.problems([...m,`from`])}),v===void 0?null:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`p`,{className:VP.hint,children:(0,q.jsx)(r_,{text:`Writes \`${v.template}\``})}),(0,q.jsx)(`p`,{className:VP.hint,children:(0,q.jsx)(r_,{text:v.items.length===0?`Items have no declared fields.`:`Each item has ${v.items.map(e=>`\`${e.field}\``).join(`, `)}.`})})]}),_.length===0?(0,q.jsx)(`p`,{className:VP.hint,children:`No earlier node declares a list. Add one below, or connect this node after one that does.`}):null,(0,q.jsx)(zF,{holders:y,onDeclare:(e,t,n)=>{b(e,t,n)},to:t})]}):null,l===`from`?(0,q.jsx)(mI,{bad:a,description:`A longer list asks whether to stop, run this many, or run all.`,field:x(`maxItems`),label:`Most items`,onBad:o,required:!0}):null,l===`once`?null:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(mI,{bad:s,description:"Default: the run's `limits.concurrency`.",field:x(`maxParallel`),label:`Most at once`,onBad:c,required:!1}),(0,q.jsx)(dk,{label:`When an item fails`,onChange:e=>{p.change([...m,`onFailure`],()=>e===`stop`?`stop`:void 0)},options:[{value:`finish`,label:`Run every item`},{value:`stop`,label:`Start no more items`}],value:h.onFailure===`stop`?`stop`:`finish`})]})]})})},gI=(e,t,n)=>n.path.at(-1)===`forEach`&&t!==null&&n.path.length===3?(0,q.jsx)(hI,{builder:e,field:n,id:t}):null,_I=e=>typeof e!=`string`||e.includes(`{{`)?void 0:WD(e,KC).driver,vI="A model for the run's driver, or `<driver>.<model>`, such as `claude-code.sonnet`.",yI=(e,t)=>{let n=_I(e);return[t??vI,...n===void 0?[]:[`Runs on ${n}.`]].join(` `)},bI=(e,t)=>{let n=_I(e);return n===void 0||typeof t!=`string`||t===n?void 0:`Model names ${n}, but this node's driver is ${t}. Make them match, or drop the prefix.`},xI=e=>e.at(-1)===`model`&&(e[0]===`nodes`&&e.length===3||e[0]===`defaults`&&e.length===2),SI=(e,t,n)=>({custom:n=>gI(e,t,n)??dI(e,t,n),hint:(t,n)=>{let r=e.view?.graph,i=e.view?.document,a=kF(i)?i.nodes:void 0,o=kF(a)?a[String(t[1])]:void 0,s=r===void 0||!kF(o)?n:TF(r,t,o.forEach,n);return xI(t)&&kF(o)?yI(o.model,s):s},change:(t,n)=>{e.change(t,n)},problems:t=>{let r=NP(n,t).map(e=>kP(e)),i=e.view?.document,a=xI(t)&&r.length===0?bI(PP(i,t),PP(i,[...t.slice(0,-1),`driver`])):void 0;return a===void 0?r:[...r,a]}}),CI=({schema:e,value:t,path:n,hide:r,context:i})=>{let a=fP(e);if(a.kind!==`object`)return null;let o=kF(t)?t:{};return(0,q.jsx)(q.Fragment,{children:a.fields.filter(({key:e})=>!r.includes(e)).map(e=>(0,q.jsx)(nI,{context:i,name:e.key,path:[...n,e.key],required:e.required,schema:e.schema,value:o[e.key]},e.key))})},wI=e=>kF(e)&&typeof e.type==`string`?e.type:``,TI=({id:e,builder:t})=>{let{view:n,schema:r}=t,[i,a]=(0,U.useState)(e),o=(0,U.useRef)(e),s=n?.document,c=kF(s)?s.nodes:void 0,l=kF(c)?c[e]:void 0,u=wI(l),d=r===null?void 0:EP(r,u),f=async()=>{i!==o.current&&(o.current=i,await t.edit({op:`renameNode`,from:e,to:i})?t.select(i):(o.current=e,a(e)))},p=async()=>{await t.edit({op:`removeNode`,id:e})&&t.select(null)};return(0,q.jsxs)(`div`,{className:VP.fields,children:[(0,q.jsx)(`h2`,{className:VP.heading,children:eM(u)}),(0,q.jsx)(mk,{description:`Lowercase, and read by other nodes. A new name follows every reference.`,label:`Name`,onChange:a,onCommit:()=>{f()},value:i}),d===void 0?(0,q.jsx)(`p`,{className:VP.hint,children:`This node has no known type, so there are no fields to show.`}):(0,q.jsx)(CI,{context:SI(t,e,n?.diagnostics??[]),hide:[`type`],path:[`nodes`,e],schema:d,value:l}),(0,q.jsx)(qF,{builder:t,id:e}),(0,q.jsxs)(Y,{onClick:()=>{p()},children:[`Remove `,e]})]})},EI=({builder:e})=>{let{view:t,schema:n}=e;return n===null?null:(0,q.jsxs)(`div`,{className:VP.fields,children:[(0,q.jsx)(`h2`,{className:VP.heading,children:`Workflow`}),(0,q.jsx)(CI,{context:SI(e,null,t?.diagnostics??[]),hide:[`schemaVersion`,`nodes`,`edges`],path:[],schema:n,value:t?.document})]})},DI=({builder:e})=>{let{selected:t,view:n}=e,r=n?.graph.nodes.some(({id:e})=>e===t)===!0;return t!==null&&r?(0,q.jsx)(TI,{builder:e,id:t},t):(0,q.jsx)(EI,{builder:e})},OI=({builder:e})=>{let t=e.view?.graph,n=e.view?.diagnostics,r=(0,U.useMemo)(()=>t===void 0?null:aP(t),[t]),i=(0,U.useMemo)(()=>t===void 0||n===void 0?void 0:MP(t,n),[t,n]);if(t===void 0||r===null)return null;if(t.nodes.length===0)return(0,q.jsx)(JD,{title:`No nodes yet.`,children:`Add one from the list beside this.`});let{selected:a,connecting:o}=e;return(0,q.jsx)(_N,{facts:i,label:`Workflow ${e.opened?.name??``}`,layout:r,onSelect:n=>{o&&a!==null?(e.setConnecting(!1),e.edit(cF(t,a,n))):e.select(n)},selected:a??void 0})},kI=({builder:e})=>{let{view:t}=e;return t===null?(0,q.jsx)(`div`,{className:VP.empty,children:(0,q.jsxs)(JD,{title:`No workflow open.`,children:[`Choose one above, or name a new one. A workflow you make here is the same file you could write by hand, and works with every`,` `,(0,q.jsx)(`code`,{children:`ork`}),` command.`]})}):(0,q.jsxs)(`div`,{className:VP.body,children:[(0,q.jsx)(HP,{builder:e}),(0,q.jsxs)(`div`,{className:VP.middle,children:[(0,q.jsx)(`div`,{className:VP.canvas,children:(0,q.jsx)(OI,{builder:e})}),(0,q.jsx)(UP,{onChoose:e.select,problems:t.diagnostics,walk:t.walk})]}),(0,q.jsx)(`aside`,{"aria-label":`Inspector`,className:VP.inspector,children:(0,q.jsx)(DI,{builder:e})})]})},AI=({builder:e})=>{let t=ob(),n=vb(t.projects.state),r=vb(t.workflows.state),i=n.status===`ready`?n.data:[],a=vb(t.builder.project),[o,s]=(0,U.useState)(``),c=a??(i.length===1?i[0]?.id:null)??null,{chooseProject:l}=e;(0,U.useEffect)(()=>{t.projects.load()},[t]),(0,U.useEffect)(()=>{c!==null&&(t.workflows.load(c),l(c))},[t,c,l]);let u=r.status===`ready`&&r.arg===c?r.data.map(({name:e})=>e):[],d=[...new Set([...u,...e.drafts])].toSorted(),f=async()=>{c!==null&&o!==``&&await e.create(c,o)&&s(``)};return(0,q.jsxs)(`div`,{className:VP.chooser,children:[(0,q.jsx)(aC,{empty:`No project matches.`,label:`Project`,onChange:e=>{t.builder.project.setValue(e)},options:i.map(({id:e})=>({value:e,label:e})),placeholder:`Type to find a project`,value:c}),(0,q.jsx)(aC,{disabled:c===null||d.length===0,empty:`No workflow matches.`,label:`Workflow`,onChange:t=>{c!==null&&t!==null&&e.open(c,t)},options:d.map(t=>({value:t,label:e.drafts.includes(t)?`${t} (draft)`:t})),placeholder:d.length===0?`None yet`:`Type to find one`,value:e.opened?.name??null}),(0,q.jsxs)(`form`,{className:VP.create,onSubmit:e=>{e.preventDefault(),f()},children:[(0,q.jsx)(mk,{label:`New workflow`,onChange:s,value:o}),(0,q.jsx)(Y,{disabled:c===null||o===``,focusableWhenDisabled:!0,type:`submit`,children:`Create`})]})]})},jI={agents:[],skills:[]},MI=e=>typeof e==`object`&&!!e&&!Array.isArray(e),NI=e=>{let[t,n]=(0,U.useState)(null),[r,i]=(0,U.useState)(jI),[a,o]=(0,U.useState)([]),s=(0,U.useRef)(null);(0,U.useEffect)(()=>{(async()=>{let t=await e.call(`builderSchema`);t.ok&&MI(t.data)&&n(t.data)})()},[e]);let c=(0,U.useCallback)(async t=>{let n={id:t},[r,a]=await Promise.all([e.call(`builderDrafts`,{params:n}),e.call(`builderCatalog`,{params:n})]);s.current===t&&(r.ok&&o(r.data),a.ok&&i(a.data))},[e]);return{schema:t,catalog:r,drafts:a,setDrafts:o,forProject:(0,U.useCallback)(e=>{s.current!==e&&o([]),s.current=e,c(e)},[c]),refreshDrafts:(0,U.useCallback)(()=>{s.current!==null&&c(s.current)},[c])}},PI=({project:e,name:t})=>({id:e,name:t}),FI=()=>{let{client:e,builder:t}=ob(),{inTurn:n,history:r,view:i,opened:a}=t,o=vb(a),s=vb(i),c=vb(t.selected),l=vb(r).length>0,[u,d]=(0,U.useState)(!1),[f,p]=(0,U.useState)(null),[m,h]=(0,U.useState)(null),{schema:g,catalog:_,drafts:v,setDrafts:y,refreshDrafts:b,forProject:x}=NI(e),S=(0,U.useCallback)(e=>{r.setValue(e)},[r]),C=(0,U.useCallback)(e=>{let t=a.getValue();return t?.project===e.project&&t.name===e.name},[a]),w=(0,U.useCallback)((e,n)=>{t.show(e,n),d(!1),p(null),h(null)},[t]),T=(0,U.useCallback)(e=>{x(e);let t=a.getValue();t!==null&&t.project!==e&&w(null,null)},[x,a,w]),E=(0,U.useCallback)((e,n)=>C(e)?n.ok?(t.update(n.data),p(null),!0):(p(n.error),!1):n.ok,[C,t]),D=(0,U.useCallback)((t,r)=>n(async()=>{let n={project:t,name:r},i=await e.call(`builderView`,{params:PI(n)});i.ok?w(n,i.data):p(i.error)}),[e,n,w]),O=(0,U.useCallback)((t,r)=>n(async()=>{let n=await e.call(`builderCreate`,{params:{id:t},body:{name:r}});return n.ok?(w({project:t,name:r},n.data),y(e=>[...e,r]),!0):(p(n.error),!1)}),[e,n,y,w]),k=(0,U.useCallback)(async(t,n)=>{let i=await e.call(`builderEdit`,{params:PI(t),body:{edits:n}}),a=E(t,i);return i.ok&&C(t)&&i.data.text!==i.data.previous.text&&S([...r.getValue(),i.data.previous]),a},[e,r,C,E,S]);return{opened:o,view:s,selected:c,connecting:u,refusal:f,canUndo:l,replaceAsked:m,schema:g,catalog:_,drafts:v,chooseProject:T,open:D,create:O,edit:(0,U.useCallback)((...e)=>o===null?Promise.resolve(!1):n(()=>k(o,e)),[n,o,k]),change:(0,U.useCallback)((e,t)=>o===null?Promise.resolve(!1):n(()=>{if(!C(o))return Promise.resolve(!1);let n=PP(i.getValue()?.document,e),r=t(n);if(FP(n,r))return Promise.resolve(!0);let a=[...e];return k(o,[r===void 0?{op:`delete`,path:a}:{op:`set`,path:a,value:r}])}),[n,C,o,k,i]),undo:(0,U.useCallback)(()=>o===null?Promise.resolve():n(async()=>{let t=r.getValue().at(-1);if(t===void 0||!C(o))return;let n=await e.call(`builderRestore`,{params:PI(o),body:t});E(o,n)&&S(r.getValue().slice(0,-1))}),[e,r,n,C,o,E,S]),discard:(0,U.useCallback)(()=>o===null?Promise.resolve():n(async()=>{let t=await e.call(`builderDiscard`,{params:PI(o)});b(),C(o)&&(t.ok?`gone`in t.data?w(null,null):w(o,t.data):p(t.error))}),[e,n,C,o,b,w]),save:(0,U.useCallback)((t=!1)=>{if(o===null)return Promise.resolve(!1);let r=PI(o);return n(async()=>{let n=await e.call(`builderSave`,{params:r,body:t?{force:!0}:{}});return n.ok?n.data.saved?(p(null),b(),C(o)&&S([]),E(o,await e.call(`builderView`,{params:r})),tb.add({title:`Saved ${o.name}`}),!0):(n.data.why===`changed`?h(n.data.message):p(n.data.message),!1):(p(n.error),!1)})},[e,n,C,o,b,E,S]),select:t.select,setConnecting:d,setReplaceAsked:h}},II=()=>{let e=ob(),t=FI(),{view:n,opened:r,refusal:i,connecting:a,selected:o}=t,[s,c]=(0,U.useState)(!1),[l,u]=(0,U.useState)(!1),d=n===null?0:IP(n.diagnostics),f=n===null?[]:zP(n.graph),p=async()=>{await t.save()&&c(!0)},m=()=>{r!==null&&(e.workflows.load(r.project),e.runPreset.setValue({project:r.project,workflow:r.name}),e.runDialog.setValue(!0))};return(0,q.jsxs)(`div`,{className:VP.panel,children:[(0,q.jsxs)(`header`,{className:VP.tools,children:[(0,q.jsx)(AI,{builder:t}),n===null?null:(0,q.jsxs)(`div`,{className:VP.actions,children:[(0,q.jsx)(Y,{disabled:!t.canUndo,focusableWhenDisabled:!0,onClick:()=>{t.undo()},children:`Undo`}),(0,q.jsx)(Y,{disabled:!n.draft,focusableWhenDisabled:!0,onClick:()=>{u(!0)},children:`Discard`}),(0,q.jsx)(Y,{disabled:d>0||!n.draft,focusableWhenDisabled:!0,onClick:()=>{t.save()},variant:`primary`,children:`Save`}),(0,q.jsx)(Y,{disabled:d>0,focusableWhenDisabled:!0,onClick:()=>{p()},children:`Run…`})]})]}),n===null?null:(0,q.jsxs)(`div`,{className:VP.notices,children:[i===null?null:(0,q.jsx)(`p`,{className:VP.error,role:`alert`,children:(0,q.jsx)(r_,{text:i})}),(0,q.jsx)(`output`,{className:VP.status,children:a&&o!==null?`Choose the card ${o} leads to.`:n.changedOnDisk?`The file changed since this draft began. Saving will ask before replacing it.`:n.draft?`Unsaved changes are kept as a draft.`:``})]}),(0,q.jsx)(kI,{builder:t}),(0,q.jsx)(FC,{confirm:`Discard the draft`,description:`This throws away every unsaved change, and it can't be undone.`,onConfirm:()=>{u(!1),t.discard()},onOpenChange:u,open:l,title:`Discard the draft of ${r?.name??``}?`}),(0,q.jsx)(FC,{confirm:`Replace the file`,description:`${t.replaceAsked??``} Replacing it loses what changed there.`,onConfirm:()=>{t.setReplaceAsked(null),t.save(!0)},onOpenChange:e=>{e||t.setReplaceAsked(null)},open:t.replaceAsked!==null,title:`The file changed`}),(0,q.jsx)(FC,{confirm:`Choose how to run it`,description:`This starts a real run, which can spend money and commit work.${f.length===0?``:` These nodes act outside its worktree: ${f.join(`, `)}.`}`,onConfirm:()=>{c(!1),m()},onOpenChange:c,open:s,title:`Run ${r?.name??``}?`})]})},LI=new Set([`agent.leader`,`agent.worker`]),RI=e=>{let t=new Set;for(let{event:n}of e)if(n.type===`run.started`)for(let{id:e,type:r}of n.nodes)LI.has(r)&&t.add(e);else n.type===`node.started`&&LI.has(n.nodeType)&&t.add(n.id);return[...t]},zI={now:`delivered to its session`,queued:`waits for its next session`,resumed:`resumed its session`},BI=e=>e===void 0?{}:{note:e===`script`?`a script`:`a rule`},VI=/^mcp__ork__/u,HI=new Set([`StructuredOutput`]),UI=(e,t)=>e.type===`assistant.text`?{...t,kind:`node`,text:e.text}:e.type===`tool.called`?HI.has(e.name)?void 0:{...t,kind:`activity`,text:`Used ${e.name.replace(VI,``)}`}:e.type===`session.started`?{...t,kind:`activity`,text:`Session on ${e.model}`}:void 0,WI=({seq:e,at:t,event:n},r)=>{let i={seq:e,at:t},a=e=>({...i,kind:`activity`,text:e});if(n.type===`node.event`)return n.id===r?n.event.fork===!0?n.event.type===`session.started`?a(`A fork took a child's question`):void 0:UI(n.event,i):void 0;if(n.type===`node.finished`){if(n.id!==r)return;let{summary:e}=n.output;if(n.ok&&typeof e==`string`)return{...i,kind:`node`,text:e,note:`its report`};let t=n.error===void 0?``:`: ${n.error}`;return a(n.ok?`Finished.`:`Failed${t}`)}if(n.type===`message.sent`&&n.to===r)return{...i,kind:`peer`,from:n.node,text:n.body,...BI(n.via)};if(`node`in n&&n.node===r){if(n.type===`user.message`)return{...i,kind:`you`,text:n.body,note:zI[n.delivered]};if(n.type===`message.sent`)return a(n.via===`rule`?`A rule wrote to ${n.to}: ${n.body}`:`Wrote to ${n.to}: ${n.body}`);if(n.type===`message.received`)return{...i,kind:`peer`,from:n.from,text:n.body,...BI(n.via)};if(n.type===`decision.opened`)return a(`Asked you: ${n.question}`);if(n.type===`decision.answered`)return a(n.note===void 0?`You answered: ${n.answer}`:`You answered: ${n.answer}. You said: ${n.note}`)}},GI=(e,t)=>e.flatMap(e=>WI(e,t)??[]),KI=({live:e})=>e===`running`?null:e===`paused`?`The run is paused. Continue it to write to this node.`:`The run has ended (${e}). To resume this node's session, use:`,qI=(e,t)=>`ork chat ${e} ${t}`,JI={panel:`_panel_s0gbu_7`,tools:`_tools_s0gbu_23`,main:`_main_s0gbu_33`,thread:`_thread_s0gbu_46`,items:`_items_s0gbu_62`,message:`_message_s0gbu_73`,meta:`_meta_s0gbu_81`,speaker:`_speaker_s0gbu_91`,time:`_time_s0gbu_101`,note:`_note_s0gbu_102`,text:`_text_s0gbu_112`,activity:`_activity_s0gbu_118`,activityText:`_activityText_s0gbu_131`,composer:`_composer_s0gbu_136`,box:`_box_s0gbu_156`,labelRow:`_labelRow_s0gbu_179`,send:`_send_s0gbu_189`,hint:`_hint_s0gbu_197`,why:`_why_s0gbu_198`,refusal:`_refusal_s0gbu_207`},YI=({run:e,node:t})=>{let n=ob(),r=(0,U.useId)(),i=(0,U.useId)(),[a,o]=(0,U.useState)(``),[s,c]=(0,U.useState)(!1),[l,u]=(0,U.useState)(null),d=KI(e),f=qI(e.id,t),p=(0,U.useRef)(!1),m=(0,U.useRef)(null);(0,U.useEffect)(()=>{d!==null&&p.current&&(p.current=!1,m.current?.focus())},[d]);let h=async()=>{if(s||a.trim()===``)return;c(!0),u(null);let r=await n.sendMessage(e.id,t,a);c(!1),r.ok?o(``):u(r.error)};return d===null?(0,q.jsxs)(`form`,{className:JI.composer,onSubmit:e=>{e.preventDefault(),h()},children:[(0,q.jsxs)(`div`,{className:JI.labelRow,children:[(0,q.jsxs)(`label`,{className:nC.label,htmlFor:r,children:[`Message to `,t]}),(0,q.jsx)(`span`,{className:JI.hint,id:i,children:`Enter sends, Shift+Enter starts a new line.`})]}),(0,q.jsxs)(`div`,{className:JI.send,children:[(0,q.jsx)(`textarea`,{"aria-describedby":i,className:JI.box,id:r,onBlur:()=>{p.current=!1},onChange:e=>{o(e.target.value)},onFocus:()=>{p.current=!0},onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),h())},rows:1,value:a}),(0,q.jsx)(Y,{cli:`${f} -m …`,disabled:s||a.trim()===``,focusableWhenDisabled:!0,type:`submit`,variant:`primary`,children:s?`Sending…`:`Send`})]}),l===null?null:(0,q.jsx)(`p`,{className:JI.refusal,role:`alert`,children:(0,q.jsx)(r_,{text:l})})]}):(0,q.jsxs)(`div`,{"aria-describedby":r,"aria-label":`Message to ${t}`,className:JI.composer,ref:m,role:`group`,tabIndex:-1,children:[(0,q.jsx)(`p`,{className:JI.why,id:r,children:(0,q.jsx)(r_,{text:d})}),e.live===`paused`?null:(0,q.jsx)(cC,{command:f})]})},XI=e=>`id`in e?e.id:`node`in e?e.node:`from`in e?e.from:void 0,ZI=e=>e.replaceAll(/\s+/gu,` `).trim(),QI=e=>e===void 0?``:` (${e})`,$I=({event:e})=>{switch(e.type){case`session.started`:return`session on ${e.model}`;case`assistant.text`:return ZI(e.text);case`session.waiting`:return ZI(e.reason);case`tool.called`:return`${e.name} ${ZI(JSON.stringify(e.input))}`;case`tool.result`:return e.isError?`tool failed`:`tool done`;case`plan.limit`:return e.status===`allowed`?``:`plan: ${e.window.replaceAll(`_`,` `)} limit ${e.status===`rejected`?`reached`:`is close`}`;case`session.finished`:return`session finished`;default:return``}},eL=e=>{let t=$I(e);return e.event.fork===!0&&t!==``?`fork: ${t}`:t},tL=e=>e.type===`node.finished`&&e.end.actor!==null?e:void 0,nL=(e,t)=>e>1?`round ${String(e)}: ${t}`:t,rL=({round:e,end:t})=>nL(e,t.message),iL=e=>{let{output:t,round:n,end:r}=e;if(r.actor!==null)return nL(n,`${r.label}: ${r.message}`);let{summary:i}=t;return nL(n,`ok${typeof i==`string`?`: ${ZI(i)}`:``}`)},aL=e=>{switch(e.type){case`run.started`:return`${e.workflow}, ${String(e.nodes.length)} nodes`;case`run.resumed`:return`keeps ${String(e.kept.length)} nodes`;case`run.command`:return e.node===void 0?e.command:`${e.command} ${e.node}`;case`run.finished`:return e.result.status;case`node.started`:return e.round>1?`${e.nodeType}, round ${String(e.round)}`:e.nodeType;case`node.event`:return eL(e);case`node.finished`:return iL(e);case`each.listed`:return`${String(e.count)} items`;case`each.exceeded`:return`${String(e.count)} items, over ${String(e.maxItems)}`;case`edge.taken`:return`${e.from} -> ${e.to}`;case`loop.exhausted`:return`${e.from} -> ${e.to} after ${String(e.maxRounds)} rounds`;case`watch.started`:return`until ${e.until}, every ${e.every}`;case`watch.changed`:return`look ${String(e.looks)}: ${e.said}`;case`watch.ended`:return`${e.outcome} after ${String(e.looks)} looks`;case`worktree`:return`${e.action} ${e.branch??e.path}`;case`decision.opened`:return ZI(e.question);case`decision.answered`:{let t=e.note===void 0?``:`; said: ${ZI(e.note)}`;return`${e.answer}, by ${e.by}${t}`}case`message.sent`:return`to ${e.to}${QI(e.via)}: ${ZI(e.body)}`;case`message.received`:return`from ${e.from}${QI(e.via)}: ${ZI(e.body)}`;case`call.started`:return`${e.workflow} as ${e.run}`;case`link.notice`:return ZI(e.text);case`owner.asked`:return`about ${e.about}: ${ZI(e.text)}`;case`owner.answered`:return e.answer;case`user.message`:return`${e.delivered}: ${ZI(e.body)}`;case`claim.taken`:return e.resource;case`claim.refused`:return`${e.resource}: ${e.holder} holds ${e.held}`;case`claim.released`:return`${e.resource}, ${e.reason}`;case`feedback.recorded`:return ZI(e.feedback.title);case`slot.waiting`:return`held by ${e.holders.join(`, `)}`;case`lock.waiting`:return`${e.lock}, held by ${e.holders.join(`, `)}`;case`verify.skipped`:return ZI(`${e.check}: already passed on these files · ${e.at} · ${e.who}`);case`message.read`:return`${String(e.ids.length)} messages`;case`decision.withdrawn`:case`slot.taken`:case`lock.taken`:case`lock.released`:case`node.held`:case`node.released`:case`node.skipped`:case`owner.unanswered`:return``;default:return``}},oL=new WeakMap,sL=e=>{let t=oL.get(e);if(t!==void 0)return t;let n=JSON.stringify(e.event).toLowerCase();return oL.set(e,n),n},cL=e=>/^(.+)\.\d+$/u.exec(e)?.[1],lL=(e,t)=>e!==void 0&&(e===t||cL(e)===t),uL=(e,{node:t,type:n,text:r})=>{let i=r.trim().toLowerCase();return t===null&&n===null&&i===``?e:e.filter(e=>(t===null||lL(XI(e.event),t))&&(n===null||e.event.type===n)&&(i===``||sL(e).includes(i)))},dL=e=>[...new Set(e)].toSorted((e,t)=>e.localeCompare(t,void 0,{numeric:!0})),fL=(e,t)=>({value:e,label:t.some(t=>cL(t)===e)?`${e} and its items`:e}),pL=(e,t)=>dL([...e.flatMap(({event:e})=>XI(e)??[]),...t===null?[]:[t]]),mL=e=>dL(e.map(({event:e})=>e.type)),hL=(e,t,n)=>`${e===t?`${String(e)} events`:`${String(e)} of ${String(t)} loaded`}${n>t?`, ${String(n)} in the run`:``}`,gL=(e,t)=>`ork logs ${e}${t===null?``:` --node ${t}`} --follow`,_L=e=>new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1}),vL=32,yL=({kind:e,from:t},n)=>e===`you`?`You`:e===`node`?n:t??``,bL=(0,U.memo)(({item:e,node:t})=>e.kind===`activity`?(0,q.jsxs)(`li`,{className:JI.activity,children:[(0,q.jsx)(`span`,{className:JI.activityText,children:e.text}),(0,q.jsx)(`span`,{className:JI.time,children:_L(e.at)})]}):(0,q.jsxs)(`li`,{className:JI.message,"data-kind":e.kind,children:[(0,q.jsxs)(`p`,{className:JI.meta,children:[(0,q.jsx)(`span`,{className:JI.speaker,children:yL(e,t)}),(0,q.jsx)(`span`,{className:JI.time,children:_L(e.at)}),e.note===void 0?null:(0,q.jsx)(`span`,{className:JI.note,children:e.note})]}),(0,q.jsx)(`p`,{className:JI.text,children:e.text})]}));bL.displayName=`ThreadRow`;var xL=({items:e,node:t})=>{let n=(0,U.useRef)(null),r=(0,U.useRef)(!0);return(0,U.useLayoutEffect)(()=>{let e=n.current;e!==null&&r.current&&(e.scrollTop=e.scrollHeight)}),(0,U.useEffect)(()=>{let e=n.current,t=new ResizeObserver(()=>{e!==null&&r.current&&(e.scrollTop=e.scrollHeight)});return e!==null&&t.observe(e),()=>{t.disconnect()}},[]),(0,q.jsx)(`div`,{"aria-label":`Conversation with ${t}`,className:JI.thread,onScroll:e=>{let{scrollHeight:t,scrollTop:n,clientHeight:i}=e.currentTarget;r.current=t-n-i<vL},ref:n,role:`log`,tabIndex:0,children:(0,q.jsx)(`ol`,{className:JI.items,children:e.map(e=>(0,q.jsx)(bL,{item:e,node:t},e.seq))})})},SL=({run:e,selected:t})=>{let n=ob(),r=(0,U.useMemo)(()=>n.feedOf(e.id),[n,e.id]);(0,U.useEffect)(()=>n.retainRun(e.id),[n,e.id]);let{events:i,tail:a,following:o,link:s}=vb(r.state),c=o?i:a,l=(0,U.useMemo)(()=>RI(i),[i]),u=t!==null&&l.includes(t)?t:l[0]??null,d=(0,U.useMemo)(()=>u===null?[]:GI(c,u),[c,u]);return u===null?(0,q.jsx)(JD,{title:s===`loading`&&i.length===0?`Reading the run…`:`This run has no one to talk to.`,children:`Only leaders and workers have sessions.`}):(0,q.jsxs)(`div`,{className:JI.panel,children:[(0,q.jsx)(`div`,{className:JI.tools,children:(0,q.jsx)(aC,{empty:`No node matches.`,label:`Node`,onChange:n.selectNode,options:l.map(e=>({value:e,label:e})),value:u})}),(0,q.jsx)(`div`,{className:JI.main,children:d.length===0?(0,q.jsx)(JD,{title:`Nothing from ${u} yet.`,children:`What it says and what you write show here.`}):(0,q.jsx)(xL,{items:d,node:u},u)}),(0,q.jsx)(YI,{node:u,run:e},`${e.id}/${u}`)]})},CL=()=>{let e=ob(),{run:t,node:n}=vb(e.selection),r=vb(e.runs)?.find(({id:e})=>e===t);return r===void 0?(0,q.jsx)(JD,{cli:`ork chat <run> <node>`,title:`No run chosen.`,children:`Choose one in the Runs panel, or in a terminal:`}):(0,q.jsx)(SL,{run:r,selected:n},r.id)},wL=(0,U.createContext)(null),TL=({id:e,label:t})=>t??e,EL=({id:e,runId:t},n,r=``)=>{let i=r.trim()===``?``:` --say ${Mk(r.trim())}`;return`ork decide ${t} --id ${e} --choose ${n?.id??`<option>`}${i}`},DL={terminal:`in the run's terminal`,decide:"with `ork decide`",ui:"in `ork ui`",owner:`by its owner`},OL=({status:e,options:t,answer:n,answeredBy:r,owner:i})=>{if(e===`withdrawn`)return`Withdrawn: it no longer needs an answer.`;if(e===`open`)return`Its run ended before it was answered.`;let a=t.find(({id:e})=>e===n),o=a===void 0?n??``:TL(a);if(r===`owner`&&i!==void 0)return`Answered ${o} by \`${i}\`, its owner.`;let s=i===void 0?``:`, after \`${i}\` passed it on`;return r===void 0?`Answered ${o}${s}.`:`Answered ${o} ${DL[r]}${s}.`},kL=({note:e})=>e===void 0?void 0:`They said: ${e}`,AL=(e,t)=>/^[1-9]$/u.test(t)?e[Number(t)-1]:void 0,jL=e=>(t,n)=>`${n===1?`Copy code`:`Copy code block ${t} of ${n}`} (${e})`,ML=({runId:e,id:t})=>`ork decide ${e} --id ${t} --document`,NL=e=>e.startsWith(`{
95
+ `),PL={value:` all`,label:``},FL=(e,t,n,r)=>{let i=new Map;for(let n of e){let e=t(n);e!==void 0&&i.set(e,(i.get(e)??0)+1)}let a=[...i];return(r?a.toSorted(([e],[t])=>e.localeCompare(t)):a).map(([e,t])=>({value:e,label:n(e,t)}))},IL=(e,{workflow:t,run:n},r)=>({...e.some(({runId:e})=>r(e)===t)&&t!==void 0?{workflow:t}:{},...e.some(({runId:e})=>e===n)&&n!==void 0?{run:n}:{}}),LL=(e,t)=>t===void 0||e.some(({value:e})=>e===t)?e:[...e,{value:t,label:`${t} (0)`}],RL=(e,{workflow:t,run:n},r)=>{let i=e.filter(({runId:e})=>t===void 0||r(e)===t);return{workflows:[{...PL,label:`All (${e.length})`},...LL(FL(e,({runId:e})=>r(e),(e,t)=>`${e} (${t})`,!0),t)],runs:[{...PL,label:`All (${i.length})`},...LL(FL(i,({runId:e})=>e,(e,t)=>{let n=r(e);return`${e}${n===void 0?``:` · ${n}`} (${t})`},!1),n)],shown:i.filter(({runId:e})=>n===void 0||e===n),active:{...t===void 0?{}:{workflow:t},...n===void 0?{}:{run:n}}}},zL=(e,t)=>t===e?e===1?`1 open decision.`:`${e} open decisions.`:`${t} of ${e} open decisions shown; ${e-t} hidden by the filter.`,BL=({workflow:e,run:t})=>e!==void 0||t!==void 0,VL=({workflow:e,run:t})=>t===void 0?`ork decide --list${e===void 0?``:` --workflow ${e}`}`:`ork decide ${t} --list`,HL={panel:`_panel_1qd3f_6`,list:`_list_1qd3f_22`,card:`_card_1qd3f_27`,fromText:`_fromText_1qd3f_43`,from:`_from_1qd3f_43`,read:`_read_1qd3f_69`,length:`_length_1qd3f_79`,document:`_document_1qd3f_90`,filter:`_filter_1qd3f_120`,filterFields:`_filterFields_1qd3f_134`,counts:`_counts_1qd3f_145`,options:`_options_1qd3f_154`,option:`_option_1qd3f_154`,optionMark:`_optionMark_1qd3f_217`,optionCommand:`_optionCommand_1qd3f_227`,unreachable:`_unreachable_1qd3f_239`,optionText:`_optionText_1qd3f_264`,optionLabel:`_optionLabel_1qd3f_288`,optionDescription:`_optionDescription_1qd3f_295`,refusal:`_refusal_1qd3f_304`,settled:`_settled_1qd3f_312`,settledTitle:`_settledTitle_1qd3f_322`,settledList:`_settledList_1qd3f_339`,settledQuestion:`_settledQuestion_1qd3f_360`,settledEnding:`_settledEnding_1qd3f_364`,settledNote:`_settledNote_1qd3f_374`},UL="Cannot answer here: `ork ui` is not reachable.",WL=`Cannot answer here: ork ui is not reachable`,GL=({decision:e,note:t,onNote:n,sending:r,unreachable:i,onChoose:a})=>(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(mk,{description:`It goes with the option you choose; a gate passes it on as its note.`,label:`Note for the run (optional)`,multiline:!0,onChange:n,rows:2,value:t}),t.trim()===``?null:(0,q.jsx)(cC,{command:EL(e,void 0,t)}),(0,q.jsx)(`ul`,{className:HL.options,children:e.options.map((n,o)=>{let s=n.id===e.recommended,c=EL(e,n,t),l=o<9?String(o+1):void 0;return(0,q.jsx)(`li`,{children:(0,q.jsx)(u_,{cli:c,label:i?UL:void 0,children:(0,q.jsxs)(`button`,{...l_(c,i?WL:void 0),"aria-disabled":r||i?`true`:void 0,"aria-keyshortcuts":l,className:HL.option,"data-option":``,"data-recommended":s?``:void 0,"data-unreachable":i?``:void 0,onClick:()=>{a(n)},type:`button`,children:[l===void 0?null:(0,q.jsx)(a_,{keys:[l]}),(0,q.jsxs)(`span`,{className:HL.optionText,children:[(0,q.jsx)(`span`,{className:HL.optionLabel,children:TL(n)}),n.description===void 0?null:(0,q.jsx)(`span`,{className:HL.optionDescription,children:n.description}),i?(0,q.jsx)(`code`,{className:HL.optionCommand,children:c}):null]}),s?(0,q.jsx)(`span`,{className:HL.optionMark,children:`recommended`}):null]})})},n.id)})})]}),KL={};function qL(e,t){let n=t||KL;return JL(e,typeof n.includeImageAlt!=`boolean`||n.includeImageAlt,typeof n.includeHtml!=`boolean`||n.includeHtml)}function JL(e,t,n){if(XL(e)){if(`value`in e)return e.type===`html`&&!n?``:e.value;if(t&&`alt`in e&&e.alt)return e.alt;if(`children`in e)return YL(e.children,t,n)}return Array.isArray(e)?YL(e,t,n):``}function YL(e,t,n){let r=[],i=-1;for(;++i<e.length;)r[i]=JL(e[i],t,n);return r.join(``)}function XL(e){return!!(e&&typeof e==`object`)}var ZL=document.createElement(`i`);function QL(e){let t=`&`+e+`;`;ZL.innerHTML=t;let n=ZL.textContent;return n.charCodeAt(n.length-1)===59&&e!==`semi`?!1:n!==t&&n}function $L(e,t,n,r){let i=e.length,a=0,o;if(t=t<0?-t>i?0:i+t:t>i?i:t,n=n>0?n:0,r.length<1e4)o=Array.from(r),o.unshift(t,n),e.splice(...o);else for(n&&e.splice(t,n);a<r.length;)o=r.slice(a,a+1e4),o.unshift(t,0),e.splice(...o),a+=1e4,t+=1e4}function eR(e,t){return e.length>0?($L(e,e.length,0,t),e):t}var tR={}.hasOwnProperty;function nR(e){let t={},n=-1;for(;++n<e.length;)rR(t,e[n]);return t}function rR(e,t){let n;for(n in t){let r=(tR.call(e,n)?e[n]:void 0)||(e[n]={}),i=t[n],a;if(i)for(a in i){tR.call(r,a)||(r[a]=[]);let e=i[a];iR(r[a],Array.isArray(e)?e:e?[e]:[])}}}function iR(e,t){let n=-1,r=[];for(;++n<t.length;)(t[n].add===`after`?e:r).push(t[n]);$L(e,0,0,r)}function aR(e,t){let n=Number.parseInt(e,t);return n<9||n===11||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)==65535||(n&65535)==65534||n>1114111?`�`:String.fromCodePoint(n)}function oR(e){return e.replace(/[\t\n\r ]+/g,` `).replace(/^ | $/g,``).toLowerCase().toUpperCase()}var sR=yR(/[A-Za-z]/),cR=yR(/[\dA-Za-z]/),lR=yR(/[#-'*+\--9=?A-Z^-~]/);function uR(e){return e!==null&&(e<32||e===127)}var dR=yR(/\d/),fR=yR(/[\dA-Fa-f]/),pR=yR(/[!-/:-@[-`{-~]/);function mR(e){return e!==null&&e<-2}function hR(e){return e!==null&&(e<0||e===32)}function gR(e){return e===-2||e===-1||e===32}var _R=yR(/\p{P}|\p{S}/u),vR=yR(/\s/);function yR(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}function bR(e,t,n,r){let i=r?r-1:1/0,a=0;return o;function o(r){return gR(r)?(e.enter(n),s(r)):t(r)}function s(r){return gR(r)&&a++<i?(e.consume(r),s):(e.exit(n),t(r))}}function xR(e,t,n,r,i,a){let o=0;return s;function s(t){return a>0&&gR(t)?(e.enter(r),c(t)):l(t)}function c(t){return gR(t)&&o<a?(e.consume(t),o++,c):(e.exit(r),l(t))}function l(e){return o>=i?t(e):n(e)}}var SR={tokenize:CR};function CR(e){let t=e.attempt(this.parser.constructs.contentInitial,r,i),n;return t;function r(n){if(n===null)e.consume(n);else return e.enter(`lineEnding`),e.consume(n),e.exit(`lineEnding`),bR(e,t,`linePrefix`)}function i(t){return e.enter(`paragraph`),a(t)}function a(t){let r=e.enter(`chunkText`,{contentType:`text`,previous:n});return n&&(n.next=r),n=r,o(t)}function o(t){if(t===null)e.exit(`chunkText`),e.exit(`paragraph`),e.consume(t);else return mR(t)?(e.consume(t),e.exit(`chunkText`),a):(e.consume(t),o)}}var wR=class{constructor(){this.index=new Map,this.map=[]}add(e,t,n){TR(this,e,t,n,!1)}addBefore(e,t,n){TR(this,e,t,n,!0)}consume(e){if(this.map.sort(function(e,t){return e[0]-t[0]}),this.map.length===0)return;let t=this.map.length,n=[];for(;t>0;)--t,n.push(e.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),e.length=this.map[t][0];n.push(e.slice()),e.length=0;let r=n.pop();for(;r;){for(let t of r)e.push(t);r=n.pop()}this.map.length=0,this.index.clear()}};function TR(e,t,n,r,i){if(n===0&&r.length===0)return;let a=e.index.get(t);if(a){a[1]+=n,i?(r.push(...a[2]),a[2]=r):a[2].push(...r);return}let o=[t,n,r];e.map.push(o),e.index.set(t,o)}var ER={tokenize:OR},DR={tokenize:kR};function OR(e){let t=this,n=[],r=0,i,a,o;return s;function s(i){if(r<n.length){let a=n[r];return t.containerState=a[1],e.attempt(a[0].continuation,c,l)(i)}return l(i)}function c(e){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,i&&v();let n=t.events.length,a=n,o;for(;a--;)if(t.events[a][0]===`exit`&&t.events[a][1].type===`chunkFlow`){o=t.events[a][1].end;break}_(r);let s=n;for(;s<t.events.length;)t.events[s][1].end={...o},s++;let c=new wR;return c.add(a+1,0,t.events.slice(n)),c.add(n,s-n,[]),c.consume(t.events),l(e)}return s(e)}function l(a){if(r===n.length){if(!i)return f(a);if(i.currentConstruct&&i.currentConstruct.concrete)return m(a);t.interrupt=!(!i.currentConstruct||i._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(DR,u,d)(a)}function u(e){return i&&v(),_(r),f(e)}function d(e){return t.parser.lazy[t.now().line]=r!==n.length,o=t.now().offset,m(e)}function f(n){return t.containerState={},e.attempt(DR,p,m)(n)}function p(e){return r++,n.push([t.currentConstruct,t.containerState]),f(e)}function m(n){if(n===null)i&&v(),_(0),e.consume(n);else return i||=t.parser.flow(t.now()),e.enter(`chunkFlow`,{_tokenizer:i,contentType:`flow`,previous:a}),h(n)}function h(n){if(n===null)g(e.exit(`chunkFlow`),!0),_(0),e.consume(n);else return mR(n)?(e.consume(n),g(e.exit(`chunkFlow`)),r=0,t.interrupt=void 0,s):(e.consume(n),h)}function g(e,n){let s=t.sliceStream(e);if(n&&s.push(null),e.previous=a,a&&(a.next=e),a=e,i.defineSkip(e.start),i.write(s),t.parser.lazy[e.start.line]){let e=i.events.length;for(;e--;)if(i.events[e][1].start.offset<o&&(!i.events[e][1].end||i.events[e][1].end.offset>o))return;let n=t.events.length,a=n,s,c;for(;a--;)if(t.events[a][0]===`exit`&&t.events[a][1].type===`chunkFlow`){if(s){c=t.events[a][1].end;break}s=!0}for(_(r),e=n;e<t.events.length;)t.events[e][1].end={...c},e++;let l=new wR;l.add(a+1,0,t.events.slice(n)),l.add(n,e-n,[]),l.consume(t.events)}}function _(r){let i=n.length;for(;i-->r;){let r=n[i];t.containerState=r[1],r[0].exit.call(t,e)}n.length=r}function v(){i.write([null]),a=void 0,i=void 0,t.containerState._closeFlow=void 0}}function kR(e,t,n){return bR(e,e.attempt(this.parser.constructs.document,t,n),`linePrefix`,this.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)}function AR(e){if(e===null||hR(e)||vR(e))return 1;if(_R(e))return 2}function jR(e,t,n){let r=[],i=-1;for(;++i<e.length;){let a=e[i].resolveAll;a&&!r.includes(a)&&(t=a(t,n),r.push(a))}return t}var MR={name:`attention`,resolveAll:NR,tokenize:PR};function NR(e,t){let n=-1,r;for(;++n<e.length;)if(e[n][0]===`enter`&&e[n][1].type===`attentionSequence`&&e[n][1]._close){let i=n;for(;i--;)if(e[i][0]===`exit`&&e[i][1].type===`attentionSequence`&&e[i][1]._open&&t.sliceSerialize(e[i][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[i][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[i][1].end.offset-e[i][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;let a=e[i][1].end.offset-e[i][1].start.offset>1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1,o={...e[i][1].end},s={...e[n][1].start};FR(o,-a),FR(s,a);let c={type:a>1?`strongSequence`:`emphasisSequence`,start:o,end:{...e[i][1].end}},l={type:a>1?`strongSequence`:`emphasisSequence`,start:{...e[n][1].start},end:s},u={type:a>1?`strongText`:`emphasisText`,start:{...e[i][1].end},end:{...e[n][1].start}},d={type:a>1?`strong`:`emphasis`,start:{...c.start},end:{...l.end}};e[i][1].end={...c.start},e[n][1].start={...l.end},r=[],e[i][1].end.offset-e[i][1].start.offset&&(r=eR(r,[[`enter`,e[i][1],t],[`exit`,e[i][1],t]])),r=eR(r,[[`enter`,d,t],[`enter`,c,t],[`exit`,c,t],[`enter`,u,t]]),r=eR(r,jR(t.parser.constructs.insideSpan.null,e.slice(i+1,n),t)),r=eR(r,[[`exit`,u,t],[`enter`,l,t],[`exit`,l,t],[`exit`,d,t]]);let f=0;e[n][1].end.offset-e[n][1].start.offset&&(f=2,r=eR(r,[[`enter`,e[n][1],t],[`exit`,e[n][1],t]])),$L(e,i-1,n-i+3,r),n=i+r.length-f-2;break}}for(n=-1;++n<e.length;)e[n][1].type===`attentionSequence`&&(e[n][1].type=`data`);return e}function PR(e,t){let n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=AR(r),a;return o;function o(t){return a=t,e.enter(`attentionSequence`),s(t)}function s(o){if(o===a)return e.consume(o),s;let c=e.exit(`attentionSequence`),l=AR(o),u=!l||l===2&&i||n.includes(o)&&o!==42&&o!==95,d=!i||i===2&&l||n.includes(r)&&r!==42&&r!==95;return c._open=!!(a===42?u:u&&(i||!d)),c._close=!!(a===42?d:d&&(l||!u)),t(o)}}function FR(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}var IR={name:`autolink`,tokenize:LR};function LR(e,t,n){let r=0;return i;function i(t){return e.enter(`autolink`),e.enter(`autolinkMarker`),e.consume(t),e.exit(`autolinkMarker`),e.enter(`autolinkProtocol`),a}function a(t){return sR(t)?(e.consume(t),o):t===64?n(t):l(t)}function o(e){return e===43||e===45||e===46||cR(e)?(r=1,s(e)):l(e)}function s(t){return t===58?(e.consume(t),r=0,c):(t===43||t===45||t===46||cR(t))&&r++<32?(e.consume(t),s):(r=0,l(t))}function c(r){return r===62?(e.exit(`autolinkProtocol`),e.enter(`autolinkMarker`),e.consume(r),e.exit(`autolinkMarker`),e.exit(`autolink`),t):r===null||r===32||r===60||uR(r)?n(r):(e.consume(r),c)}function l(t){return t===64?(e.consume(t),u):lR(t)?(e.consume(t),l):n(t)}function u(e){return cR(e)?d(e):n(e)}function d(n){return n===46?(e.consume(n),r=0,u):n===62?(e.exit(`autolinkProtocol`).type=`autolinkEmail`,e.enter(`autolinkMarker`),e.consume(n),e.exit(`autolinkMarker`),e.exit(`autolink`),t):f(n)}function f(t){if((t===45||cR(t))&&r++<63){let n=t===45?f:d;return e.consume(t),n}return n(t)}}var RR={partial:!0,tokenize:zR};function zR(e,t,n){return r;function r(t){return gR(t)?bR(e,i,`linePrefix`)(t):i(t)}function i(e){return e===null||mR(e)?t(e):n(e)}}var BR={continuation:{tokenize:HR},exit:UR,name:`blockQuote`,tokenize:VR};function VR(e,t,n){let r=this;return i;function i(t){if(t===62){let n=r.containerState;return n.open||=(e.enter(`blockQuote`,{_container:!0}),!0),e.enter(`blockQuotePrefix`),e.enter(`blockQuoteMarker`),e.consume(t),e.exit(`blockQuoteMarker`),a}return n(t)}function a(n){return gR(n)?(e.enter(`blockQuotePrefixWhitespace`),e.consume(n),e.exit(`blockQuotePrefixWhitespace`),e.exit(`blockQuotePrefix`),t):(e.exit(`blockQuotePrefix`),t(n))}}function HR(e,t,n){let r=this;return i;function i(t){return gR(t)?bR(e,a,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):a(t)}function a(r){return e.attempt(BR,t,n)(r)}}function UR(e){e.exit(`blockQuote`)}var WR={name:`characterEscape`,tokenize:GR};function GR(e,t,n){return r;function r(t){return e.enter(`characterEscape`),e.enter(`escapeMarker`),e.consume(t),e.exit(`escapeMarker`),i}function i(r){return pR(r)?(e.enter(`characterEscapeValue`),e.consume(r),e.exit(`characterEscapeValue`),e.exit(`characterEscape`),t):n(r)}}var KR={name:`characterReference`,tokenize:qR};function qR(e,t,n){let r=this,i=0,a,o;return s;function s(t){return e.enter(`characterReference`),e.enter(`characterReferenceMarker`),e.consume(t),e.exit(`characterReferenceMarker`),c}function c(t){return t===35?(e.enter(`characterReferenceMarkerNumeric`),e.consume(t),e.exit(`characterReferenceMarkerNumeric`),l):(e.enter(`characterReferenceValue`),a=31,o=cR,u(t))}function l(t){return t===88||t===120?(e.enter(`characterReferenceMarkerHexadecimal`),e.consume(t),e.exit(`characterReferenceMarkerHexadecimal`),e.enter(`characterReferenceValue`),a=6,o=fR,u):(e.enter(`characterReferenceValue`),a=7,o=dR,u(t))}function u(s){if(s===59&&i){let i=e.exit(`characterReferenceValue`);return o===cR&&!QL(r.sliceSerialize(i))?n(s):(e.enter(`characterReferenceMarker`),e.consume(s),e.exit(`characterReferenceMarker`),e.exit(`characterReference`),t)}return o(s)&&i++<a?(e.consume(s),u):n(s)}}var JR={partial:!0,tokenize:YR};function YR(e,t,n){let r=this;return i;function i(t){return t===null?n(t):(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),a)}function a(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}var XR={concrete:!0,name:`codeFenced`,tokenize:ZR};function ZR(e,t,n){let r=this,i={partial:!0,tokenize:x},a=0,o=0,s;return c;function c(e){return l(e)}function l(t){let n=r.events[r.events.length-1];return a=n&&n[1].type===`linePrefix`?n[2].sliceSerialize(n[1],!0).length:0,s=t,e.enter(`codeFenced`),e.enter(`codeFencedFence`),e.enter(`codeFencedFenceSequence`),u(t)}function u(t){return t===s?(o++,e.consume(t),u):o<3?n(t):(e.exit(`codeFencedFenceSequence`),gR(t)?bR(e,d,`whitespace`)(t):d(t))}function d(n){return n===null||mR(n)?(e.exit(`codeFencedFence`),r.interrupt?t(n):e.check(JR,h,b)(n)):(e.enter(`codeFencedFenceInfo`),e.enter(`chunkString`,{contentType:`string`}),f(n))}function f(t){return t===null||mR(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceInfo`),d(t)):gR(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceInfo`),bR(e,p,`whitespace`)(t)):t===96&&t===s?n(t):(e.consume(t),f)}function p(t){return t===null||mR(t)?d(t):(e.enter(`codeFencedFenceMeta`),e.enter(`chunkString`,{contentType:`string`}),m(t))}function m(t){return t===null||mR(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceMeta`),d(t)):t===96&&t===s?n(t):(e.consume(t),m)}function h(t){return e.attempt(i,b,g)(t)}function g(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),_}function _(t){return a>0&&gR(t)?bR(e,v,`linePrefix`,a+1)(t):v(t)}function v(t){return t===null||mR(t)?e.check(JR,h,b)(t):(e.enter(`codeFlowValue`),y(t))}function y(t){return t===null||mR(t)?(e.exit(`codeFlowValue`),v(t)):(e.consume(t),y)}function b(n){return e.exit(`codeFenced`),t(n)}function x(e,t,n){let i=0;return a;function a(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),c}function c(t){return e.enter(`codeFencedFence`),gR(t)?bR(e,l,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):l(t)}function l(t){return t===s?(e.enter(`codeFencedFenceSequence`),u(t)):n(t)}function u(t){return t===s?(i++,e.consume(t),u):i>=o?(e.exit(`codeFencedFenceSequence`),gR(t)?bR(e,d,`whitespace`)(t):d(t)):n(t)}function d(r){return r===null||mR(r)?(e.exit(`codeFencedFence`),t(r)):n(r)}}}var QR={name:`codeIndented`,tokenize:ez},$R={partial:!0,tokenize:tz};function ez(e,t,n){return r;function r(t){return e.enter(`codeIndented`),xR(e,i,n,`linePrefix`,4,4)(t)}function i(t){return t===null?o(t):mR(t)?e.attempt($R,i,o)(t):(e.enter(`codeFlowValue`),a(t))}function a(t){return t===null||mR(t)?(e.exit(`codeFlowValue`),i(t)):(e.consume(t),a)}function o(n){return e.exit(`codeIndented`),t(n)}}function tz(e,t,n){let r=this;return i;function i(o){return r.parser.lazy[r.now().line]?n(o):mR(o)?(e.enter(`lineEnding`),e.consume(o),e.exit(`lineEnding`),i):xR(e,t,a,`linePrefix`,4,4)(o)}function a(e){return mR(e)?i(e):n(e)}}var nz={name:`codeText`,previous:iz,resolve:rz,tokenize:az};function rz(e){let t=e.length-4,n=3,r,i;if((e[n][1].type===`lineEnding`||e[n][1].type===`space`)&&(e[t][1].type===`lineEnding`||e[t][1].type===`space`)){for(r=n;++r<t;)if(e[r][1].type===`codeTextData`){e[n][1].type=`codeTextPadding`,e[t][1].type=`codeTextPadding`,n+=2,t-=2;break}}for(r=n-1,t++;++r<=t;)i===void 0?r!==t&&e[r][1].type!==`lineEnding`&&(i=r):(r===t||e[r][1].type===`lineEnding`)&&(e[i][1].type=`codeTextData`,r!==i+2&&(e[i][1].end=e[r-1][1].end,e.splice(i+2,r-i-2),t-=r-i-2,r=i+2),i=void 0);return e}function iz(e){return e!==96||this.events[this.events.length-1][1].type===`characterEscape`}function az(e,t,n){let r=0,i,a;return o;function o(t){return e.enter(`codeText`),e.enter(`codeTextSequence`),s(t)}function s(t){return t===96?(e.consume(t),r++,s):(e.exit(`codeTextSequence`),c(t))}function c(t){return t===null?n(t):t===32?(e.enter(`space`),e.consume(t),e.exit(`space`),c):t===96?(a=e.enter(`codeTextSequence`),i=0,u(t)):mR(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),c):(e.enter(`codeTextData`),l(t))}function l(t){return t===null||t===32||t===96||mR(t)?(e.exit(`codeTextData`),c(t)):(e.consume(t),l)}function u(n){return n===96?(e.consume(n),i++,u):i===r?(e.exit(`codeTextSequence`),e.exit(`codeText`),t(n)):(a.type=`codeTextData`,l(n))}}var oz=class{constructor(e){this.left=e?[...e]:[],this.right=[]}get(e){if(e<0||e>=this.left.length+this.right.length)throw RangeError("Cannot access index `"+e+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return e<this.left.length?this.left[e]:this.right[this.right.length-e+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(e,t){let n=t??1/0;return n<this.left.length?this.left.slice(e,n):e>this.left.length?this.right.slice(this.right.length-n+this.left.length,this.right.length-e+this.left.length).reverse():this.left.slice(e).concat(this.right.slice(this.right.length-n+this.left.length).reverse())}splice(e,t,n){let r=t||0;this.setCursor(Math.trunc(e));let i=this.right.splice(this.right.length-r,1/0);return n&&sz(this.left,n),i.reverse()}pop(){return this.setCursor(1/0),this.left.pop()}push(e){this.setCursor(1/0),this.left.push(e)}pushMany(e){this.setCursor(1/0),sz(this.left,e)}unshift(e){this.setCursor(0),this.right.push(e)}unshiftMany(e){this.setCursor(0),sz(this.right,e.reverse())}setCursor(e){if(!(e===this.left.length||e>this.left.length&&this.right.length===0||e<0&&this.left.length===0)){if(e<this.left.length){let t=this.left.splice(e,1/0);sz(this.right,t.reverse())}else{let t=this.right.splice(this.left.length+this.right.length-e,1/0);sz(this.left,t.reverse())}}}};function sz(e,t){let n=0;if(t.length<1e4)e.push(...t);else for(;n<t.length;)e.push(...t.slice(n,n+1e4)),n+=1e4}function cz(e){let t={},n=-1,r,i,a,o,s,c,l,u=new oz(e);for(;++n<u.length;){for(;n in t;)n=t[n];if(r=u.get(n),n&&r[1].type===`chunkFlow`&&u.get(n-1)[1].type===`listItemPrefix`&&(c=r[1]._tokenizer.events,a=0,a<c.length&&c[a][1].type===`lineEndingBlank`&&(a+=2),a<c.length&&c[a][1].type===`content`))for(;++a<c.length&&c[a][1].type!==`content`;)c[a][1].type===`chunkText`&&(c[a][1]._isInFirstContentOfListItem=!0,a++);if(r[0]===`enter`)r[1].contentType&&(Object.assign(t,lz(u,n)),n=t[n],l=!0);else if(r[1]._container){for(a=n,i=void 0;a--;)if(o=u.get(a),o[1].type===`lineEnding`||o[1].type===`lineEndingBlank`)o[0]===`enter`&&(i&&(u.get(i)[1].type=`lineEndingBlank`),o[1].type=`lineEnding`,i=a);else if(o[1].type!==`linePrefix`&&o[1].type!==`listItemIndent`)break;i&&(r[1].end={...u.get(i)[1].start},s=u.slice(i,n),s.unshift(r),u.splice(i,n-i+1,s))}}return $L(e,0,1/0,u.slice(0)),!l}function lz(e,t){let n=e.get(t)[1],r=e.get(t)[2],i=t-1,a=[],o=n._tokenizer;o||(o=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(o._contentTypeTextTrailing=!0));let s=o.events,c=[],l={},u,d,f=-1,p=n,m=0,h=0,g=[h];for(;p;){for(;e.get(++i)[1]!==p;);a.push(i),p._tokenizer||(u=r.sliceStream(p),p.next||u.push(null),d&&o.defineSkip(p.start),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=!0),o.write(u),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=void 0)),d=p,p=p.next}for(p=n;++f<s.length;)s[f][0]===`exit`&&s[f-1][0]===`enter`&&s[f][1].type===s[f-1][1].type&&s[f][1].start.line!==s[f][1].end.line&&(h=f+1,g.push(h),p._tokenizer=void 0,p.previous=void 0,p=p.next);for(o.events=[],p?(p._tokenizer=void 0,p.previous=void 0):g.pop(),f=g.length;f--;){let t=s.slice(g[f],g[f+1]),n=a.pop();c.push([n,n+t.length-1]),e.splice(n,2,t)}for(c.reverse(),f=-1;++f<c.length;)l[m+c[f][0]]=m+c[f][1],m+=c[f][1]-c[f][0]-1;return l}var uz={resolve:fz,tokenize:pz},dz={partial:!0,tokenize:mz};function fz(e){return cz(e),e}function pz(e,t){let n;return r;function r(t){return e.enter(`content`),n=e.enter(`chunkContent`,{contentType:`content`}),i(t)}function i(t){return t===null?a(t):mR(t)?e.check(dz,o,a)(t):(e.consume(t),i)}function a(n){return e.exit(`chunkContent`),e.exit(`content`),t(n)}function o(t){return e.consume(t),e.exit(`chunkContent`),n.next=e.enter(`chunkContent`,{contentType:`content`,previous:n}),n=n.next,i}}function mz(e,t,n){let r=this;return i;function i(t){return e.exit(`chunkContent`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),bR(e,a,`linePrefix`)}function a(i){if(i===null||mR(i))return n(i);let a=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes(`codeIndented`)&&a&&a[1].type===`linePrefix`&&a[2].sliceSerialize(a[1],!0).length>=4?t(i):e.interrupt(r.parser.constructs.flow,n,t)(i)}}function hz(e,t,n,r,i,a,o,s,c){let l=c||1/0,u=0;return d;function d(t){return t===60?(e.enter(r),e.enter(i),e.enter(a),e.consume(t),e.exit(a),f):t===null||t===32||t===41||uR(t)?n(t):(e.enter(r),e.enter(o),e.enter(s),e.enter(`chunkString`,{contentType:`string`}),h(t))}function f(n){return n===62?(e.enter(a),e.consume(n),e.exit(a),e.exit(i),e.exit(r),t):(e.enter(s),e.enter(`chunkString`,{contentType:`string`}),p(n))}function p(t){return t===62?(e.exit(`chunkString`),e.exit(s),f(t)):t===null||t===60||mR(t)?n(t):(e.consume(t),t===92?m:p)}function m(t){return t===60||t===62||t===92?(e.consume(t),p):p(t)}function h(i){return!u&&(i===null||i===41||hR(i))?(e.exit(`chunkString`),e.exit(s),e.exit(o),e.exit(r),t(i)):u<l&&i===40?(e.consume(i),u++,h):i===41?(e.consume(i),u--,h):i===null||i===32||i===40||uR(i)?n(i):(e.consume(i),i===92?g:h)}function g(t){return t===40||t===41||t===92?(e.consume(t),h):h(t)}}function gz(e,t,n,r,i,a){let o=this,s=0,c;return l;function l(t){return e.enter(r),e.enter(i),e.consume(t),e.exit(i),e.enter(a),u}function u(l){return s>999||l===null||l===91||l===93&&!c||l===94&&!s&&`_hiddenFootnoteSupport`in o.parser.constructs?n(l):l===93?(e.exit(a),e.enter(i),e.consume(l),e.exit(i),e.exit(r),t):mR(l)?(e.enter(`lineEnding`),e.consume(l),e.exit(`lineEnding`),u):(e.enter(`chunkString`,{contentType:`string`}),d(l))}function d(t){return t===null||t===91||t===93||mR(t)||s++>999?(e.exit(`chunkString`),u(t)):(e.consume(t),c||=!gR(t),t===92?f:d)}function f(t){return t===91||t===92||t===93?(e.consume(t),s++,d):d(t)}}function _z(e,t,n,r,i,a){let o;return s;function s(t){return t===34||t===39||t===40?(e.enter(r),e.enter(i),e.consume(t),e.exit(i),o=t===40?41:t,c):n(t)}function c(n){return n===o?(e.enter(i),e.consume(n),e.exit(i),e.exit(r),t):(e.enter(a),l(n))}function l(t){return t===o?(e.exit(a),c(o)):t===null?n(t):mR(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),bR(e,l,`linePrefix`)):(e.enter(`chunkString`,{contentType:`string`}),u(t))}function u(t){return t===o||t===null||mR(t)?(e.exit(`chunkString`),l(t)):(e.consume(t),t===92?d:u)}function d(t){return t===o||t===92?(e.consume(t),u):u(t)}}function vz(e,t){let n;return r;function r(i){return mR(i)?(e.enter(`lineEnding`),e.consume(i),e.exit(`lineEnding`),n=!0,r):gR(i)?bR(e,r,n?`linePrefix`:`lineSuffix`)(i):t(i)}}var yz={name:`definition`,tokenize:xz},bz={partial:!0,tokenize:Sz};function xz(e,t,n){let r=this,i;return a;function a(t){return e.enter(`definition`),o(t)}function o(t){return gz.call(r,e,s,n,`definitionLabel`,`definitionLabelMarker`,`definitionLabelString`)(t)}function s(t){return i=oR(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),c):n(t)}function c(t){return hR(t)?vz(e,l)(t):l(t)}function l(t){return hz(e,u,n,`definitionDestination`,`definitionDestinationLiteral`,`definitionDestinationLiteralMarker`,`definitionDestinationRaw`,`definitionDestinationString`)(t)}function u(t){return e.attempt(bz,d,d)(t)}function d(t){return gR(t)?bR(e,f,`whitespace`)(t):f(t)}function f(a){return a===null||mR(a)?(e.exit(`definition`),r.parser.defined.push(i),t(a)):n(a)}}function Sz(e,t,n){return r;function r(t){return hR(t)?vz(e,i)(t):n(t)}function i(t){return _z(e,a,n,`definitionTitle`,`definitionTitleMarker`,`definitionTitleString`)(t)}function a(t){return gR(t)?bR(e,o,`whitespace`)(t):o(t)}function o(e){return e===null||mR(e)?t(e):n(e)}}var Cz={name:`hardBreakEscape`,tokenize:wz};function wz(e,t,n){return r;function r(t){return e.enter(`hardBreakEscape`),e.consume(t),i}function i(r){return mR(r)?(e.exit(`hardBreakEscape`),t(r)):n(r)}}var Tz={name:`headingAtx`,resolve:Ez,tokenize:Dz};function Ez(e,t){let n=e.length-2,r=3;if(e[r][1].type===`whitespace`&&(r+=2),n-2>r&&e[n][1].type===`whitespace`&&(n-=2),e[n][1].type===`atxHeadingSequence`&&(r===n-1||n-4>r&&e[n-2][1].type===`whitespace`)&&(n-=r+1===n?2:4),n>r){let i={type:`atxHeadingText`,start:e[r][1].start,end:e[n][1].end},a={type:`chunkText`,start:e[r][1].start,end:e[n][1].end,contentType:`text`};$L(e,r,n-r+1,[[`enter`,i,t],[`enter`,a,t],[`exit`,a,t],[`exit`,i,t]])}return e}function Dz(e,t,n){let r=0;return i;function i(t){return e.enter(`atxHeading`),a(t)}function a(t){return e.enter(`atxHeadingSequence`),o(t)}function o(t){return t===35&&r++<6?(e.consume(t),o):t===null||hR(t)?(e.exit(`atxHeadingSequence`),s(t)):n(t)}function s(n){return n===35?(e.enter(`atxHeadingSequence`),c(n)):n===null||mR(n)?(e.exit(`atxHeading`),t(n)):gR(n)?bR(e,s,`whitespace`)(n):(e.enter(`atxHeadingText`),l(n))}function c(t){return t===35?(e.consume(t),c):(e.exit(`atxHeadingSequence`),s(t))}function l(t){return t===null||t===35||hR(t)?(e.exit(`atxHeadingText`),s(t)):(e.consume(t),l)}}var Oz=`address.article.aside.base.basefont.blockquote.body.caption.center.col.colgroup.dd.details.dialog.dir.div.dl.dt.fieldset.figcaption.figure.footer.form.frame.frameset.h1.h2.h3.h4.h5.h6.head.header.hr.html.iframe.legend.li.link.main.menu.menuitem.nav.noframes.ol.optgroup.option.p.param.search.section.summary.table.tbody.td.tfoot.th.thead.title.tr.track.ul`.split(`.`),kz=[`pre`,`script`,`style`,`textarea`],Az={concrete:!0,name:`htmlFlow`,resolveTo:Mz,tokenize:Nz},jz={partial:!0,tokenize:Pz};function Mz(e){let t=e.length;for(;t--&&(e[t][0]!==`enter`||e[t][1].type!==`htmlFlow`););return t>1&&e[t-2][1].type===`linePrefix`&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function Nz(e,t,n){let r=this,i,a,o,s,c;return l;function l(e){return u(e)}function u(t){return e.enter(`htmlFlow`),e.enter(`htmlFlowData`),e.consume(t),d}function d(s){return s===33?(e.consume(s),f):s===47?(e.consume(s),a=!0,h):s===63?(e.consume(s),i=3,r.interrupt?t:I):sR(s)?(e.consume(s),o=String.fromCharCode(s),g):n(s)}function f(a){return a===45?(e.consume(a),i=2,p):a===91?(e.consume(a),i=5,s=0,m):sR(a)?(e.consume(a),i=4,r.interrupt?t:I):n(a)}function p(i){return i===45?(e.consume(i),r.interrupt?t:I):n(i)}function m(i){return i===`CDATA[`.charCodeAt(s++)?(e.consume(i),s===6?r.interrupt?t:O:m):n(i)}function h(t){return sR(t)?(e.consume(t),o=String.fromCharCode(t),g):n(t)}function g(s){if(s===null||s===47||s===62||hR(s)){let c=s===47,l=o.toLowerCase();return!c&&!a&&kz.includes(l)?(i=1,r.interrupt?t(s):O(s)):Oz.includes(o.toLowerCase())?(i=6,c?(e.consume(s),_):r.interrupt?t(s):O(s)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(s):a?v(s):y(s))}return s===45||cR(s)?(e.consume(s),o+=String.fromCharCode(s),g):n(s)}function _(i){return i===62?(e.consume(i),r.interrupt?t:O):n(i)}function v(t){return gR(t)?(e.consume(t),v):E(t)}function y(t){return t===47?(e.consume(t),E):t===58||t===95||sR(t)?(e.consume(t),b):gR(t)?(e.consume(t),y):E(t)}function b(t){return t===45||t===46||t===58||t===95||cR(t)?(e.consume(t),b):x(t)}function x(t){return t===61?(e.consume(t),S):gR(t)?(e.consume(t),x):y(t)}function S(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),c=t,C):gR(t)?(e.consume(t),S):w(t)}function C(t){return t===c?(e.consume(t),c=null,T):t===null||mR(t)?n(t):(e.consume(t),C)}function w(t){return t===null||t===34||t===39||t===47||t===60||t===61||t===62||t===96||hR(t)?x(t):(e.consume(t),w)}function T(e){return e===47||e===62||gR(e)?y(e):n(e)}function E(t){return t===62?(e.consume(t),D):n(t)}function D(t){return t===null||mR(t)?O(t):gR(t)?(e.consume(t),D):n(t)}function O(t){return t===45&&i===2?(e.consume(t),M):t===60&&i===1?(e.consume(t),N):t===62&&i===4?(e.consume(t),L):t===63&&i===3?(e.consume(t),I):t===93&&i===5?(e.consume(t),F):mR(t)&&(i===6||i===7)?(e.exit(`htmlFlowData`),e.check(jz,R,k)(t)):t===null||mR(t)?(e.exit(`htmlFlowData`),k(t)):(e.consume(t),O)}function k(t){return e.check(JR,A,R)(t)}function A(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),j}function j(t){return t===null||mR(t)?k(t):(e.enter(`htmlFlowData`),O(t))}function M(t){return t===45?(e.consume(t),I):O(t)}function N(t){return t===47?(e.consume(t),o=``,P):O(t)}function P(t){if(t===62){let n=o.toLowerCase();return kz.includes(n)?(e.consume(t),L):O(t)}return sR(t)&&o.length<8?(e.consume(t),o+=String.fromCharCode(t),P):O(t)}function F(t){return t===93?(e.consume(t),I):O(t)}function I(t){return t===62?(e.consume(t),L):t===45&&i===2?(e.consume(t),I):O(t)}function L(t){return t===null||mR(t)?(e.exit(`htmlFlowData`),R(t)):(e.consume(t),L)}function R(n){return e.exit(`htmlFlow`),t(n)}}function Pz(e,t,n){return r;function r(r){return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),e.attempt(RR,t,n)}}var Fz={name:`htmlText`,tokenize:Iz};function Iz(e,t,n){let r=this,i,a,o;return s;function s(t){return e.enter(`htmlText`),e.enter(`htmlTextData`),e.consume(t),c}function c(t){return t===33?(e.consume(t),l):t===47?(e.consume(t),x):t===63?(e.consume(t),y):sR(t)?(e.consume(t),w):n(t)}function l(t){return t===45?(e.consume(t),u):t===91?(e.consume(t),a=0,m):sR(t)?(e.consume(t),v):n(t)}function u(t){return t===45?(e.consume(t),p):n(t)}function d(t){return t===null?n(t):t===45?(e.consume(t),f):mR(t)?(o=d,N(t)):(e.consume(t),d)}function f(t){return t===45?(e.consume(t),p):d(t)}function p(e){return e===62?M(e):e===45?f(e):d(e)}function m(t){return t===`CDATA[`.charCodeAt(a++)?(e.consume(t),a===6?h:m):n(t)}function h(t){return t===null?n(t):t===93?(e.consume(t),g):mR(t)?(o=h,N(t)):(e.consume(t),h)}function g(t){return t===93?(e.consume(t),_):h(t)}function _(t){return t===62?M(t):t===93?(e.consume(t),_):h(t)}function v(t){return t===null||t===62?M(t):mR(t)?(o=v,N(t)):(e.consume(t),v)}function y(t){return t===null?n(t):t===63?(e.consume(t),b):mR(t)?(o=y,N(t)):(e.consume(t),y)}function b(e){return e===62?M(e):y(e)}function x(t){return sR(t)?(e.consume(t),S):n(t)}function S(t){return t===45||cR(t)?(e.consume(t),S):C(t)}function C(t){return mR(t)?(o=C,N(t)):gR(t)?(e.consume(t),C):M(t)}function w(t){return t===45||cR(t)?(e.consume(t),w):t===47||t===62||hR(t)?T(t):n(t)}function T(t){return t===47?(e.consume(t),M):t===58||t===95||sR(t)?(e.consume(t),E):mR(t)?(o=T,N(t)):gR(t)?(e.consume(t),T):M(t)}function E(t){return t===45||t===46||t===58||t===95||cR(t)?(e.consume(t),E):D(t)}function D(t){return t===61?(e.consume(t),O):mR(t)?(o=D,N(t)):gR(t)?(e.consume(t),D):T(t)}function O(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),i=t,k):mR(t)?(o=O,N(t)):gR(t)?(e.consume(t),O):(e.consume(t),A)}function k(t){return t===i?(e.consume(t),i=void 0,j):t===null?n(t):mR(t)?(o=k,N(t)):(e.consume(t),k)}function A(t){return t===null||t===34||t===39||t===60||t===61||t===96?n(t):t===47||t===62||hR(t)?T(t):(e.consume(t),A)}function j(e){return e===47||e===62||hR(e)?T(e):n(e)}function M(r){return r===62?(e.consume(r),e.exit(`htmlTextData`),e.exit(`htmlText`),t):n(r)}function N(t){return e.exit(`htmlTextData`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),P}function P(t){return gR(t)?bR(e,F,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):F(t)}function F(t){return e.enter(`htmlTextData`),o(t)}}var Lz={name:`labelEnd`,resolveAll:Vz,resolveTo:Hz,tokenize:Uz},Rz={tokenize:Wz},zz={tokenize:Gz},Bz={tokenize:Kz};function Vz(e){let t=-1,n=[];for(;++t<e.length;){let r=e[t][1];if(n.push(e[t]),r.type===`labelImage`||r.type===`labelLink`||r.type===`labelEnd`){let e=r.type===`labelImage`?4:2;r.type=`data`,t+=e}}return e.length!==n.length&&$L(e,0,e.length,n),e}function Hz(e,t){let n=e.length,r=0,i,a,o;for(;n--;){let t=e[n][1];if(i){if(t.type===`link`||t.type===`labelLink`&&t._inactive)break;e[n][0]===`enter`&&t.type===`labelLink`&&(t._inactive=!0)}else if(a){if(e[n][0]===`enter`&&(t.type===`labelImage`||t.type===`labelLink`)&&!t._balanced&&(i=n,t.type!==`labelLink`)){r=2;break}}else t.type===`labelEnd`&&(a=n)}let s={type:e[i][1].type===`labelLink`?`link`:`image`,start:{...e[i][1].start},end:{...e[e.length-1][1].end}},c={type:`label`,start:{...e[i][1].start},end:{...e[a][1].end}},l={type:`labelText`,start:{...e[i+r+2][1].end},end:{...e[a-2][1].start}};return o=[[`enter`,s,t],[`enter`,c,t]],o=eR(o,e.slice(i+1,i+r+3)),o=eR(o,[[`enter`,l,t]]),o=eR(o,jR(t.parser.constructs.insideSpan.null,e.slice(i+r+4,a-3),t)),o=eR(o,[[`exit`,l,t],e[a-2],e[a-1],[`exit`,c,t]]),o=eR(o,e.slice(a+1)),o=eR(o,[[`exit`,s,t]]),$L(e,i,e.length,o),e}function Uz(e,t,n){let r=this,i=r._labelStarts,a,o;if(i){for(;i.length>0&&i[i.length-1]._balanced;)i.pop();a=i[i.length-1]}return s;function s(t){return a?a._inactive?d(t):(o=r.parser.defined.includes(oR(r.sliceSerialize({start:a.end,end:r.now()}))),e.enter(`labelEnd`),e.enter(`labelMarker`),e.consume(t),e.exit(`labelMarker`),e.exit(`labelEnd`),c):n(t)}function c(t){return t===40?e.attempt(Rz,u,o?u:d)(t):t===91?e.attempt(zz,u,o?l:d)(t):o?u(t):d(t)}function l(t){return e.attempt(Bz,u,d)(t)}function u(e){return i.pop(),t(e)}function d(e){return a._balanced=!0,n(e)}}function Wz(e,t,n){return r;function r(t){return e.enter(`resource`),e.enter(`resourceMarker`),e.consume(t),e.exit(`resourceMarker`),i}function i(t){return hR(t)?vz(e,a)(t):a(t)}function a(t){return t===41?u(t):hz(e,o,s,`resourceDestination`,`resourceDestinationLiteral`,`resourceDestinationLiteralMarker`,`resourceDestinationRaw`,`resourceDestinationString`,32)(t)}function o(t){return hR(t)?vz(e,c)(t):u(t)}function s(e){return n(e)}function c(t){return t===34||t===39||t===40?_z(e,l,n,`resourceTitle`,`resourceTitleMarker`,`resourceTitleString`)(t):u(t)}function l(t){return hR(t)?vz(e,u)(t):u(t)}function u(r){return r===41?(e.enter(`resourceMarker`),e.consume(r),e.exit(`resourceMarker`),e.exit(`resource`),t):n(r)}}function Gz(e,t,n){let r=this;return i;function i(t){return gz.call(r,e,a,o,`reference`,`referenceMarker`,`referenceString`)(t)}function a(e){return r.parser.defined.includes(oR(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(e):n(e)}function o(e){return n(e)}}function Kz(e,t,n){return r;function r(t){return e.enter(`reference`),e.enter(`referenceMarker`),e.consume(t),e.exit(`referenceMarker`),i}function i(r){return r===93?(e.enter(`referenceMarker`),e.consume(r),e.exit(`referenceMarker`),e.exit(`reference`),t):n(r)}}var qz={name:`labelStartImage`,resolveAll:Lz.resolveAll,tokenize:Jz};function Jz(e,t,n){let r=this,i;return a;function a(t){return e.enter(`labelImage`),e.enter(`labelImageMarker`),e.consume(t),e.exit(`labelImageMarker`),o}function o(t){return t===91?(e.enter(`labelMarker`),e.consume(t),e.exit(`labelMarker`),i=e.exit(`labelImage`),s):n(t)}function s(e){return e===94&&`_hiddenFootnoteSupport`in r.parser.constructs?n(e):(r._labelStarts=r._labelStarts||[],r._labelStarts.push(i),t(e))}}var Yz={name:`labelStartLink`,resolveAll:Lz.resolveAll,tokenize:Xz};function Xz(e,t,n){let r=this,i;return a;function a(t){return e.enter(`labelLink`),e.enter(`labelMarker`),e.consume(t),e.exit(`labelMarker`),i=e.exit(`labelLink`),o}function o(e){return e===94&&`_hiddenFootnoteSupport`in r.parser.constructs?n(e):(r._labelStarts=r._labelStarts||[],r._labelStarts.push(i),t(e))}}var Zz={name:`lineEnding`,tokenize:Qz};function Qz(e,t){return n;function n(n){return e.enter(`lineEnding`),e.consume(n),e.exit(`lineEnding`),bR(e,t,`linePrefix`)}}var $z={name:`thematicBreak`,tokenize:eB};function eB(e,t,n){let r=0,i;return a;function a(t){return e.enter(`thematicBreak`),o(t)}function o(e){return i=e,s(e)}function s(a){return a===i?(e.enter(`thematicBreakSequence`),c(a)):r>=3&&(a===null||mR(a))?(e.exit(`thematicBreak`),t(a)):n(a)}function c(t){return t===i?(e.consume(t),r++,c):(e.exit(`thematicBreakSequence`),gR(t)?bR(e,s,`whitespace`)(t):s(t))}}var tB={continuation:{tokenize:aB},exit:sB,name:`list`,tokenize:iB},nB={partial:!0,tokenize:cB},rB={partial:!0,tokenize:oB};function iB(e,t,n){let r=this,i=r.events[r.events.length-1],a=i&&i[1].type===`linePrefix`?i[2].sliceSerialize(i[1],!0).length:0,o=0;return s;function s(t){let i=r.containerState.type||(t===42||t===43||t===45?`listUnordered`:`listOrdered`);if(i===`listUnordered`?!r.containerState.marker||t===r.containerState.marker:dR(t)){if(r.containerState.type||(r.containerState.type=i,e.enter(i,{_container:!0})),i===`listUnordered`)return e.enter(`listItemPrefix`),t===42||t===45?e.check($z,n,l)(t):l(t);if(!r.interrupt||t===49)return e.enter(`listItemPrefix`),e.enter(`listItemValue`),c(t)}return n(t)}function c(t){return dR(t)&&++o<10?(e.consume(t),c):(!r.interrupt||o<2)&&(r.containerState.marker?t===r.containerState.marker:t===41||t===46)?(e.exit(`listItemValue`),l(t)):n(t)}function l(t){return e.enter(`listItemMarker`),e.consume(t),e.exit(`listItemMarker`),r.containerState.marker=r.containerState.marker||t,e.check(RR,r.interrupt?n:u,e.attempt(nB,f,d))}function u(e){return r.containerState.initialBlankLine=!0,a++,f(e)}function d(t){return gR(t)?(e.enter(`listItemPrefixWhitespace`),e.consume(t),e.exit(`listItemPrefixWhitespace`),f):n(t)}function f(n){return r.containerState.size=a+r.sliceSerialize(e.exit(`listItemPrefix`),!0).length,t(n)}}function aB(e,t,n){let r=this;return r.containerState._closeFlow=void 0,e.check(RR,i,a);function i(n){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,bR(e,t,`listItemIndent`,r.containerState.size+1)(n)}function a(n){return r.containerState.furtherBlankLines||!gR(n)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,o(n)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(rB,t,o)(n))}function o(i){return r.containerState._closeFlow=!0,r.interrupt=void 0,bR(e,e.attempt(tB,t,n),`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(i)}}function oB(e,t,n){let r=this;return bR(e,i,`listItemIndent`,r.containerState.size+1);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`listItemIndent`&&i[2].sliceSerialize(i[1],!0).length===r.containerState.size?t(e):n(e)}}function sB(e){e.exit(this.containerState.type)}function cB(e,t,n){let r=this;return bR(e,i,`listItemPrefixWhitespace`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:5);function i(e){let i=r.events[r.events.length-1];return!gR(e)&&i&&i[1].type===`listItemPrefixWhitespace`?t(e):n(e)}}var lB={name:`setextUnderline`,resolveTo:uB,tokenize:dB};function uB(e,t){let n=new wR,r=e.length,i,a,o;for(;r--;)if(e[r][0]===`enter`){if(e[r][1].type===`content`){i=r;break}e[r][1].type===`paragraph`&&(a=r)}else e[r][1].type===`content`&&n.add(r,1,[]),!o&&e[r][1].type===`definition`&&(o=r);let s={type:`setextHeading`,start:{...e[i][1].start},end:{...e[e.length-1][1].end}};return e[a][1].type=`setextHeadingText`,o?(n.add(a,0,[[`enter`,s,t]]),n.add(o+1,0,[[`exit`,e[i][1],t]]),e[i][1].end={...e[o][1].end}):e[i][1]=s,n.add(e.length,0,[[`exit`,s,t]]),n.consume(e),e}function dB(e,t,n){let r=this,i;return a;function a(t){let a=r.events.length,s;for(;a--;)if(r.events[a][1].type!==`lineEnding`&&r.events[a][1].type!==`linePrefix`&&r.events[a][1].type!==`content`){s=r.events[a][1].type===`paragraph`;break}return!r.parser.lazy[r.now().line]&&(r.interrupt||s)?(e.enter(`setextHeadingLine`),i=t,o(t)):n(t)}function o(t){return e.enter(`setextHeadingLineSequence`),s(t)}function s(t){return t===i?(e.consume(t),s):(e.exit(`setextHeadingLineSequence`),gR(t)?bR(e,c,`lineSuffix`)(t):c(t))}function c(r){return r===null||mR(r)?(e.exit(`setextHeadingLine`),t(r)):n(r)}}var fB={tokenize:pB};function pB(e){let t=this,n=e.attempt(RR,r,e.attempt(this.parser.constructs.flowInitial,i,bR(e,e.attempt(this.parser.constructs.flow,i,e.attempt(uz,i)),`linePrefix`)));return n;function r(r){if(r===null)e.consume(r);else return e.enter(`lineEndingBlank`),e.consume(r),e.exit(`lineEndingBlank`),t.currentConstruct=void 0,n}function i(r){if(r===null)e.consume(r);else return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),t.currentConstruct=void 0,n}}var mB={resolveAll:vB()},hB=_B(`string`),gB=_B(`text`);function _B(e){return{resolveAll:vB(e===`text`?yB:void 0),tokenize:t};function t(t){let n=this,r=this.parser.constructs[e],i=t.attempt(r,a,o);return a;function a(e){return c(e)?i(e):o(e)}function o(e){if(e===null)t.consume(e);else return t.enter(`data`),t.consume(e),s}function s(e){return c(e)?(t.exit(`data`),i(e)):(t.consume(e),s)}function c(e){if(e===null)return!0;let t=r[e],i=-1;if(t)for(;++i<t.length;){let e=t[i];if(!e.previous||e.previous.call(n,n.previous))return!0}return!1}}}function vB(e){return t;function t(t,n){let r=-1,i;for(;++r<=t.length;)i===void 0?t[r]&&t[r][1].type===`data`&&(i=r,r++):t[r]&&t[r][1].type===`data`||(r!==i+2&&(t[i][1].end=t[r-1][1].end,t.splice(i+2,r-i-2),r=i+2),i=void 0);return e?e(t,n):t}}function yB(e,t){let n=new wR,r=0;for(;++r<=e.length;)if((r===e.length||e[r][1].type===`lineEnding`)&&e[r-1][1].type===`data`){let i=e[r-1][1],a=t.sliceStream(i),o=a.length,s=-1,c=0,l;for(;o--;){let e=a[o];if(typeof e==`string`){for(s=e.length;e.charCodeAt(s-1)===32;)c++,s--;if(s)break;s=-1}else if(e===-2)l=!0,c++;else if(e!==-1){o++;break}}if(t._contentTypeTextTrailing&&r===e.length&&(c=0),c){let a={type:r===e.length||l||c<2?`lineSuffix`:`hardBreakTrailing`,start:{_bufferIndex:o?s:i.start._bufferIndex+s,_index:i.start._index+o,line:i.end.line,column:i.end.column-c,offset:i.end.offset-c},end:{...i.end}};i.end={...a.start},i.start.offset===i.end.offset?Object.assign(i,a):n.add(r,0,[[`enter`,a,t],[`exit`,a,t]])}r++}return n.consume(e),e}var bB=M({attentionMarkers:()=>OB,contentInitial:()=>SB,disable:()=>kB,document:()=>xB,flow:()=>wB,flowInitial:()=>CB,insideSpan:()=>DB,string:()=>TB,text:()=>EB}),xB={42:tB,43:tB,45:tB,48:tB,49:tB,50:tB,51:tB,52:tB,53:tB,54:tB,55:tB,56:tB,57:tB,62:BR},SB={91:yz},CB={[-2]:QR,[-1]:QR,32:QR},wB={35:Tz,42:$z,45:[lB,$z],60:Az,61:lB,95:$z,96:XR,126:XR},TB={38:KR,92:WR},EB={[-5]:Zz,[-4]:Zz,[-3]:Zz,33:qz,38:KR,42:MR,60:[IR,Fz],91:Yz,92:[Cz,WR],93:Lz,95:MR,96:nz},DB={null:[MR,mB]},OB={null:[42,95]},kB={null:[]};function AB(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0},i={},a=[],o=[],s=[],c={attempt:C(x),check:C(S),consume:v,enter:y,exit:b,interrupt:C(S,{interrupt:!0})},l={code:null,containerState:{},defineSkip:h,events:[],now:m,parser:e,previous:null,sliceSerialize:f,sliceStream:p,write:d},u=t.tokenize.call(l,c);return t.resolveAll&&a.push(t),l;function d(e){return o=eR(o,e),g(),o[o.length-1]===null?(w(t,0),l.events=jR(a,l.events,l),l.events):[]}function f(e,t){return MB(p(e),t)}function p(e){return jB(o,e)}function m(){let{_bufferIndex:e,_index:t,line:n,column:i,offset:a}=r;return{_bufferIndex:e,_index:t,line:n,column:i,offset:a}}function h(e){i[e.line]=e.column,E()}function g(){for(;r._index<o.length;){let e=o[r._index];if(typeof e==`string`){let t=r._index;for(r._bufferIndex<0&&(r._bufferIndex=0);r._index===t&&r._bufferIndex<e.length;)_(e.charCodeAt(r._bufferIndex))}else _(e)}}function _(e){u=u(e)}function v(e){mR(e)?(r.line++,r.column=1,r.offset+=e===-3?2:1,E()):e!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===o[r._index].length&&(r._bufferIndex=-1,r._index++)),l.previous=e}function y(e,t){let n=t||{};return n.type=e,n.start=m(),l.events.push([`enter`,n,l]),s.push(n),n}function b(e){let t=s.pop();return t.end=m(),l.events.push([`exit`,t,l]),t}function x(e,t){w(e,t.from)}function S(e,t){t.restore()}function C(e,t){return n;function n(n,r,i){let a,o,s,u;return Array.isArray(n)?f(n):`tokenize`in n?f([n]):d(n);function d(e){return t;function t(t){let n=t!==null&&e[t],r=t!==null&&e.null;return f([...Array.isArray(n)?n:n?[n]:[],...Array.isArray(r)?r:r?[r]:[]])(t)}}function f(e){return a=e,o=0,e.length===0?i:p(e[o])}function p(e){return n;function n(n){return u=T(),s=e,e.partial||(l.currentConstruct=e),e.name&&l.parser.constructs.disable.null.includes(e.name)?h(n):e.tokenize.call(t?Object.assign(Object.create(l),t):l,c,m,h)(n)}}function m(t){return e(s,u),r}function h(e){return u.restore(),++o<a.length?p(a[o]):i}}}function w(e,t){e.resolveAll&&!a.includes(e)&&a.push(e),e.resolve&&$L(l.events,t,l.events.length-t,e.resolve(l.events.slice(t),l)),e.resolveTo&&(l.events=e.resolveTo(l.events,l))}function T(){let e=m(),t=l.previous,n=l.currentConstruct,i=l.events.length,a=Array.from(s);return{from:i,restore:o};function o(){r=e,l.previous=t,l.currentConstruct=n,l.events.length=i,s=a,E()}}function E(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function jB(e,t){let n=t.start._index,r=t.start._bufferIndex,i=t.end._index,a=t.end._bufferIndex,o;if(n===i)o=[e[n].slice(r,a)];else{if(o=e.slice(n,i),r>-1){let e=o[0];typeof e==`string`?o[0]=e.slice(r):o.shift()}a>0&&o.push(e[i].slice(0,a))}return o}function MB(e,t){let n=-1,r=[],i;for(;++n<e.length;){let a=e[n],o;if(typeof a==`string`)o=a;else switch(a){case-5:o=`\r`;break;case-4:o=`
96
96
  `;break;case-3:o=`\r
97
- `;break;case-2:o=t?` `:` `;break;case-1:if(!t&&i)continue;o=` `;break;default:o=String.fromCharCode(a)}i=a===-2,r.push(o)}return r.join(``)}function xB(e){let t={constructs:WL([cB,...(e||{}).extensions||[]]),content:n(uR),defined:[],document:n(mR),flow:n(eB),lazy:{},string:n(rB),text:n(iB)};return t;function n(e){return n;function n(n){return vB(t,e,n)}}}function SB(e){for(;!XR(e););return e}var CB=/[\0\t\n\r]/g;function wB(){let e=1,t=``,n=!0,r;return i;function i(i,a,o){i=t+(typeof i==`string`?i.toString():new TextDecoder(a||void 0).decode(i));let s=[],c=0;for(t=``,n&&=(i.charCodeAt(0)===65279&&c++,void 0);c<i.length;){CB.lastIndex=c;let n=CB.exec(i),a=n&&n.index!==void 0?n.index:i.length,o=i.charCodeAt(a);if(!n){t=i.slice(c);break}if(o===10&&c===a&&r)s.push(-3),r=void 0;else switch(r&&=(s.push(-5),void 0),c<a&&(s.push(i.slice(c,a)),e+=a-c),o){case 0:s.push(65533),e++;break;case 9:{let t=Math.ceil(e/4)*4;for(s.push(-2);e++<t;)s.push(-1);break}case 10:s.push(-4),e=1;break;default:r=!0,e=1}c=a+1}return o&&(r&&s.push(-5),t&&s.push(t),s.push(null)),s}}var TB=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function EB(e){return e.replace(TB,DB)}function DB(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){let e=n.charCodeAt(1),t=e===120||e===88;return qL(n.slice(t?2:1),t?16:10)}return BL(n)||e}function OB(e){return!e||typeof e!=`object`?``:`position`in e||`type`in e?AB(e.position):`start`in e||`end`in e?AB(e):`line`in e||`column`in e?kB(e):``}function kB(e){return jB(e&&e.line)+`:`+jB(e&&e.column)}function AB(e){return kB(e&&e.start)+`-`+kB(e&&e.end)}function jB(e){return e&&typeof e==`number`?e:1}var MB={}.hasOwnProperty;function NB(e,t,n){return t&&typeof t==`object`&&(n=t,t=void 0),PB(n)(SB(xB(n).document().write(wB()(e,t,!0))))}function PB(e){let t={afterExit:[],beforeEnter:[],transforms:[],canContainEols:[`emphasis`,`fragment`,`heading`,`paragraph`,`strong`],enter:{autolink:o(ge),autolinkProtocol:E,autolinkEmail:E,atxHeading:o(fe),blockQuote:o(se),characterEscape:E,characterReference:E,codeFenced:o(ce),codeFencedFenceInfo:s,codeFencedFenceMeta:s,codeIndented:o(ce,s),codeText:o(le,s),codeTextData:E,data:E,codeFlowValue:E,definition:o(ue),definitionDestinationString:s,definitionLabelString:s,definitionTitleString:s,emphasis:o(de),hardBreakEscape:o(pe),hardBreakTrailing:o(pe),htmlFlow:o(me,s),htmlFlowData:E,htmlText:o(me,s),htmlTextData:E,image:o(he),label:s,link:o(ge),listItem:o(ve),listItemValue:p,listOrdered:o(_e,f),listUnordered:o(_e),paragraph:o(ye),reference:z,referenceString:s,resourceDestinationString:s,resourceTitleString:s,setextHeading:o(fe),strong:o(be),thematicBreak:o(xe)},exit:{atxHeading:l(),atxHeadingSequence:S,autolink:l(),autolinkEmail:oe,autolinkProtocol:ae,blockQuote:l(),characterEscapeValue:D,characterReferenceMarkerHexadecimal:ne,characterReferenceMarkerNumeric:ne,characterReferenceValue:re,characterReference:ie,codeFenced:l(_),codeFencedFence:g,codeFencedFenceInfo:m,codeFencedFenceMeta:h,codeFlowValue:D,codeIndented:l(v),codeText:l(M),codeTextData:D,data:D,definition:l(),definitionDestinationString:x,definitionLabelString:y,definitionTitleString:b,emphasis:l(),hardBreakEscape:l(k),hardBreakTrailing:l(k),htmlFlow:l(A),htmlFlowData:D,htmlText:l(j),htmlTextData:D,image:l(P),label:I,labelText:F,lineEnding:O,link:l(N),listItem:l(),listOrdered:l(),listUnordered:l(),paragraph:l(),referenceString:te,resourceDestinationString:L,resourceTitleString:R,resource:ee,setextHeading:l(T),setextHeadingLineSequence:w,setextHeadingText:C,strong:l(),thematicBreak:l()}};IB(t,(e||{}).mdastExtensions||[]);let n={};return r;function r(e){let r={type:`root`,children:[],position:void 0},o={stack:[r],tokenStack:[],config:t,enter:c,exit:u,buffer:s,resume:d,data:n},l=[],f=[],p=-1;for(;++p<e.length;)f.push(e[p]),(e[p][1].type===`listOrdered`||e[p][1].type===`listUnordered`)&&(e[p][0]===`enter`?l.push(f.length-1):a(f,l.pop()));for(e=f,p=-1;++p<e.length;){let n=t[e[p][0]];e[p][0]===`enter`&&t.beforeEnter.length>0&&i(t.beforeEnter,{...o,sliceSerialize:e[p][2].sliceSerialize},e[p][1]),MB.call(n,e[p][1].type)&&n[e[p][1].type].call({...o,sliceSerialize:e[p][2].sliceSerialize},e[p][1]),e[p][0]===`exit`&&t.afterExit.length>0&&i(t.afterExit,{...o,sliceSerialize:e[p][2].sliceSerialize},e[p][1])}if(o.tokenStack.length>0){let e=o.tokenStack[o.tokenStack.length-1];(e[1]||RB).call(o,void 0,e[0])}for(r.position={start:FB(e.length>0?e[0][1].start:{line:1,column:1,offset:0}),end:FB(e.length>0?e[e.length-2][1].end:{line:1,column:1,offset:0})},p=-1;++p<t.transforms.length;)r=t.transforms[p](r)||r;return r}function i(e,t,n){let r=-1;for(;++r<e.length;)e[r].call(t,n)}function a(e,t){let n=e.length-1,r=t-1,i=-1,a=!1,o,s,c,l,u=[];for(;++r<=n;){let t=e[r];switch(t[1].type){case`listUnordered`:case`listOrdered`:case`blockQuote`:t[0]===`enter`?i++:i--,l=void 0;break;case`lineEndingBlank`:t[0]===`enter`&&(o&&!l&&!i&&!c&&(c=r),l=void 0);break;case`linePrefix`:case`listItemValue`:case`listItemMarker`:case`listItemPrefix`:case`listItemPrefixWhitespace`:break;default:l=void 0}if(!i&&t[0]===`enter`&&t[1].type===`listItemPrefix`||i===-1&&t[0]===`exit`&&(t[1].type===`listUnordered`||t[1].type===`listOrdered`)){if(o){let n=r;for(s=void 0;n--;){let t=e[n];if(t[1].type===`lineEnding`||t[1].type===`lineEndingBlank`){if(t[0]===`exit`)continue;s&&(e[s][1].type=`lineEndingBlank`,a=!0),t[1].type=`lineEnding`,s=n}else if(t[1].type!==`linePrefix`&&t[1].type!==`blockQuotePrefix`&&t[1].type!==`blockQuotePrefixWhitespace`&&t[1].type!==`blockQuoteMarker`&&t[1].type!==`listItemIndent`)break}c&&(!s||c<s)&&(o._spread=!0),o.end=Object.assign({},s?e[s][1].start:t[1].end),u.push({at:s||r,event:[`exit`,o,t[2]]})}if(t[1].type===`listItemPrefix`){let e={type:`listItem`,_spread:!1,start:Object.assign({},t[1].start),end:void 0};o=e,u.push({at:r,event:[`enter`,e,t[2]]}),c=void 0,l=!0}}}let d=e.splice(t),f=0;for(r=-1;++r<d.length;){for(;f<u.length&&u[f].at===t+r;)e.push(u[f++].event);e.push(d[r])}e[t][1]._spread=a}function o(e,t){return n;function n(n){c.call(this,e(n),n),t&&t.call(this,n)}}function s(){this.stack.push({type:`fragment`,children:[]})}function c(e,t,n){this.stack[this.stack.length-1].children.push(e),this.stack.push(e),this.tokenStack.push([t,n||void 0]),e.position={start:FB(t.start),end:void 0}}function l(e){return t;function t(t){e&&e.call(this,t),u.call(this,t)}}function u(e,t){let n=this.stack.pop(),r=this.tokenStack.pop();if(!r)throw Error("Cannot close `"+e.type+"` ("+OB({start:e.start,end:e.end})+`): it’s not open`);r[0].type!==e.type&&(t?t.call(this,e,r[0]):(r[1]||RB).call(this,e,r[0])),n.position.end=FB(e.end)}function d(){return FL(this.stack.pop())}function f(){this.data.expectingFirstListItemValue=!0}function p(e){if(this.data.expectingFirstListItemValue){let t=this.stack[this.stack.length-2];t.start=Number.parseInt(this.sliceSerialize(e),10),this.data.expectingFirstListItemValue=void 0}}function m(){let e=this.resume(),t=this.stack[this.stack.length-1];t.lang=e}function h(){let e=this.resume(),t=this.stack[this.stack.length-1];t.meta=e}function g(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function _(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,``),this.data.flowCodeInside=void 0}function v(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e.replace(/(\r?\n|\r)$/g,``)}function y(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.label=t,n.identifier=JL(this.sliceSerialize(e)).toLowerCase()}function b(){let e=this.resume(),t=this.stack[this.stack.length-1];t.title=e}function x(){let e=this.resume(),t=this.stack[this.stack.length-1];t.url=e}function S(e){let t=this.stack[this.stack.length-1];t.depth||=this.sliceSerialize(e).length}function C(){this.data.setextHeadingSlurpLineEnding=!0}function w(e){let t=this.stack[this.stack.length-1];t.depth=this.sliceSerialize(e).codePointAt(0)===61?1:2}function T(){this.data.setextHeadingSlurpLineEnding=void 0}function E(e){let t=this.stack[this.stack.length-1].children,n=t[t.length-1];n&&n.type===`text`||(n=B(),n.position={start:FB(e.start),end:void 0},t.push(n)),this.stack.push(n)}function D(e){let t=this.stack.pop();t.value+=this.sliceSerialize(e),t.position.end=FB(e.end)}function O(e){let n=this.stack[this.stack.length-1];if(this.data.atHardBreak){let t=n.children[n.children.length-1];t.position.end=FB(e.end),this.data.atHardBreak=void 0}else!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(n.type)&&(E.call(this,e),D.call(this,e))}function k(){this.data.atHardBreak=!0}function A(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e}function j(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e}function M(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e}function N(){let e=this.stack[this.stack.length-1];if(this.data.inReference){let t=this.data.referenceType||`shortcut`;e.type+=`Reference`,e.referenceType=t,delete e.url,delete e.title}else delete e.identifier,delete e.label;this.data.referenceType=void 0}function P(){let e=this.stack[this.stack.length-1];if(this.data.inReference){let t=this.data.referenceType||`shortcut`;e.type+=`Reference`,e.referenceType=t,delete e.url,delete e.title}else delete e.identifier,delete e.label;this.data.referenceType=void 0}function F(e){let t=this.sliceSerialize(e),n=this.stack[this.stack.length-2];n.label=EB(t),n.identifier=JL(t).toLowerCase()}function I(){let e=this.stack[this.stack.length-1],t=this.resume(),n=this.stack[this.stack.length-1];this.data.inReference=!0,n.type===`link`?n.children=e.children:n.alt=t}function L(){let e=this.resume(),t=this.stack[this.stack.length-1];t.url=e}function R(){let e=this.resume(),t=this.stack[this.stack.length-1];t.title=e}function ee(){this.data.inReference=void 0}function z(){this.data.referenceType=`collapsed`}function te(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.label=t,n.identifier=JL(this.sliceSerialize(e)).toLowerCase(),this.data.referenceType=`full`}function ne(e){this.data.characterReferenceType=e.type}function re(e){let t=this.sliceSerialize(e),n=this.data.characterReferenceType,r;n?(r=qL(t,n===`characterReferenceMarkerNumeric`?10:16),this.data.characterReferenceType=void 0):r=BL(t);let i=this.stack[this.stack.length-1];i.value+=r}function ie(e){let t=this.stack.pop();t.position.end=FB(e.end)}function ae(e){D.call(this,e);let t=this.stack[this.stack.length-1];t.url=this.sliceSerialize(e)}function oe(e){D.call(this,e);let t=this.stack[this.stack.length-1];t.url=`mailto:`+this.sliceSerialize(e)}function se(){return{type:`blockquote`,children:[],position:void 0}}function ce(){return{type:`code`,lang:null,meta:null,value:``,position:void 0}}function le(){return{type:`inlineCode`,value:``,position:void 0}}function ue(){return{type:`definition`,identifier:``,label:null,title:null,url:``,position:void 0}}function de(){return{type:`emphasis`,children:[],position:void 0}}function fe(){return{type:`heading`,depth:0,children:[],position:void 0}}function pe(){return{type:`break`,position:void 0}}function me(){return{type:`html`,value:``,position:void 0}}function he(){return{type:`image`,title:null,url:``,alt:null,position:void 0}}function ge(){return{type:`link`,title:null,url:``,children:[],position:void 0}}function _e(e){return{type:`list`,ordered:e.type===`listOrdered`,start:null,spread:e._spread,children:[],position:void 0}}function ve(e){return{type:`listItem`,spread:e._spread,checked:null,children:[],position:void 0}}function ye(){return{type:`paragraph`,children:[],position:void 0}}function be(){return{type:`strong`,children:[],position:void 0}}function B(){return{type:`text`,value:``,position:void 0}}function xe(){return{type:`thematicBreak`,position:void 0}}}function FB(e){return{line:e.line,column:e.column,offset:e.offset}}function IB(e,t){let n=-1;for(;++n<t.length;){let r=t[n];Array.isArray(r)?IB(e,r):LB(e,r)}}function LB(e,t){let n;for(n in t)if(MB.call(t,n))switch(n){case`canContainEols`:{let r=t[n];r&&e[n].push(...r);break}case`transforms`:{let r=t[n];r&&e[n].push(...r);break}case`afterExit`:case`beforeEnter`:{let r=t[n];r&&e[n].push(r);break}case`enter`:case`exit`:{let r=t[n];r&&Object.assign(e[n],r);break}}}function RB(e,t){throw Error(e?"Cannot close `"+e.type+"` ("+OB({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+OB({start:t.start,end:t.end})+`) is open`:"Cannot close document, a token (`"+t.type+"`, "+OB({start:t.start,end:t.end})+`) is still open`)}var zB=new Set([`http:`,`https:`,`mailto:`]),BB=e=>{try{return zB.has(new URL(e).protocol)}catch{return!1}},VB=50,HB=e=>{let t=0,n=[{node:e,depth:0}];for(let e=n.pop();e!==void 0;e=n.pop())if(t=Math.max(t,e.depth),`children`in e.node)for(let t of e.node.children)n.push({node:t,depth:e.depth+1});return t},UB=e=>{let t=NB(e);if(HB(t)>VB)throw RangeError(`Nested too deep`);return t},WB=e=>e.type===`break`?`
98
- `:e.type===`image`||e.type===`imageReference`?e.alt??``:`value`in e?e.value:`children`in e?e.children.map(WB).join(``):``,GB=[`root`,`blockquote`,`listItem`],KB=e=>`children`in e?e.children.reduce((t,n)=>t+(n.type===`code`||n.type===`html`&&GB.includes(e.type)?1:0)+KB(n),0):0,qB=(e,t=120)=>{let n=e=>{let n=e.trim();return n.length>t?`${n.slice(0,t-1)}…`:n};try{return n(WB(UB(e).children.find(e=>WB(e).trim()!==``)??{type:`text`,value:``}).split(`
97
+ `;break;case-2:o=t?` `:` `;break;case-1:if(!t&&i)continue;o=` `;break;default:o=String.fromCharCode(a)}i=a===-2,r.push(o)}return r.join(``)}function NB(e){let t={constructs:nR([bB,...(e||{}).extensions||[]]),content:n(SR),defined:[],document:n(ER),flow:n(fB),lazy:{},string:n(hB),text:n(gB)};return t;function n(e){return n;function n(n){return AB(t,e,n)}}}function PB(e){for(;!cz(e););return e}var FB=/[\0\t\n\r]/g;function IB(){let e=1,t=``,n=!0,r;return i;function i(i,a,o){i=t+(typeof i==`string`?i.toString():new TextDecoder(a||void 0).decode(i));let s=[],c=0;for(t=``,n&&=(i.charCodeAt(0)===65279&&c++,void 0);c<i.length;){FB.lastIndex=c;let n=FB.exec(i),a=n&&n.index!==void 0?n.index:i.length,o=i.charCodeAt(a);if(!n){t=i.slice(c);break}if(o===10&&c===a&&r)s.push(-3),r=void 0;else switch(r&&=(s.push(-5),void 0),c<a&&(s.push(i.slice(c,a)),e+=a-c),o){case 0:s.push(65533),e++;break;case 9:{let t=Math.ceil(e/4)*4;for(s.push(-2);e++<t;)s.push(-1);break}case 10:s.push(-4),e=1;break;default:r=!0,e=1}c=a+1}return o&&(r&&s.push(-5),t&&s.push(t),s.push(null)),s}}var LB=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function RB(e){return e.replace(LB,zB)}function zB(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){let e=n.charCodeAt(1),t=e===120||e===88;return aR(n.slice(t?2:1),t?16:10)}return QL(n)||e}function BB(e){return!e||typeof e!=`object`?``:`position`in e||`type`in e?HB(e.position):`start`in e||`end`in e?HB(e):`line`in e||`column`in e?VB(e):``}function VB(e){return UB(e&&e.line)+`:`+UB(e&&e.column)}function HB(e){return VB(e&&e.start)+`-`+VB(e&&e.end)}function UB(e){return e&&typeof e==`number`?e:1}var WB={}.hasOwnProperty;function GB(e,t,n){return t&&typeof t==`object`&&(n=t,t=void 0),KB(n)(PB(NB(n).document().write(IB()(e,t,!0))))}function KB(e){let t={afterExit:[],beforeEnter:[],transforms:[],canContainEols:[`emphasis`,`fragment`,`heading`,`paragraph`,`strong`],enter:{autolink:o(ge),autolinkProtocol:E,autolinkEmail:E,atxHeading:o(fe),blockQuote:o(se),characterEscape:E,characterReference:E,codeFenced:o(ce),codeFencedFenceInfo:s,codeFencedFenceMeta:s,codeIndented:o(ce,s),codeText:o(le,s),codeTextData:E,data:E,codeFlowValue:E,definition:o(ue),definitionDestinationString:s,definitionLabelString:s,definitionTitleString:s,emphasis:o(de),hardBreakEscape:o(pe),hardBreakTrailing:o(pe),htmlFlow:o(me,s),htmlFlowData:E,htmlText:o(me,s),htmlTextData:E,image:o(he),label:s,link:o(ge),listItem:o(ve),listItemValue:p,listOrdered:o(_e,f),listUnordered:o(_e),paragraph:o(ye),reference:z,referenceString:s,resourceDestinationString:s,resourceTitleString:s,setextHeading:o(fe),strong:o(be),thematicBreak:o(xe)},exit:{atxHeading:l(),atxHeadingSequence:S,autolink:l(),autolinkEmail:oe,autolinkProtocol:ae,blockQuote:l(),characterEscapeValue:D,characterReferenceMarkerHexadecimal:ne,characterReferenceMarkerNumeric:ne,characterReferenceValue:re,characterReference:ie,codeFenced:l(_),codeFencedFence:g,codeFencedFenceInfo:m,codeFencedFenceMeta:h,codeFlowValue:D,codeIndented:l(v),codeText:l(M),codeTextData:D,data:D,definition:l(),definitionDestinationString:x,definitionLabelString:y,definitionTitleString:b,emphasis:l(),hardBreakEscape:l(k),hardBreakTrailing:l(k),htmlFlow:l(A),htmlFlowData:D,htmlText:l(j),htmlTextData:D,image:l(P),label:I,labelText:F,lineEnding:O,link:l(N),listItem:l(),listOrdered:l(),listUnordered:l(),paragraph:l(),referenceString:te,resourceDestinationString:L,resourceTitleString:R,resource:ee,setextHeading:l(T),setextHeadingLineSequence:w,setextHeadingText:C,strong:l(),thematicBreak:l()}};JB(t,(e||{}).mdastExtensions||[]);let n={};return r;function r(e){let r={type:`root`,children:[],position:void 0},o={stack:[r],tokenStack:[],config:t,enter:c,exit:u,buffer:s,resume:d,data:n},l=[],f=[],p=-1;for(;++p<e.length;)f.push(e[p]),(e[p][1].type===`listOrdered`||e[p][1].type===`listUnordered`)&&(e[p][0]===`enter`?l.push(f.length-1):a(f,l.pop()));for(e=f,p=-1;++p<e.length;){let n=t[e[p][0]];e[p][0]===`enter`&&t.beforeEnter.length>0&&i(t.beforeEnter,{...o,sliceSerialize:e[p][2].sliceSerialize},e[p][1]),WB.call(n,e[p][1].type)&&n[e[p][1].type].call({...o,sliceSerialize:e[p][2].sliceSerialize},e[p][1]),e[p][0]===`exit`&&t.afterExit.length>0&&i(t.afterExit,{...o,sliceSerialize:e[p][2].sliceSerialize},e[p][1])}if(o.tokenStack.length>0){let e=o.tokenStack[o.tokenStack.length-1];(e[1]||XB).call(o,void 0,e[0])}for(r.position={start:qB(e.length>0?e[0][1].start:{line:1,column:1,offset:0}),end:qB(e.length>0?e[e.length-2][1].end:{line:1,column:1,offset:0})},p=-1;++p<t.transforms.length;)r=t.transforms[p](r)||r;return r}function i(e,t,n){let r=-1;for(;++r<e.length;)e[r].call(t,n)}function a(e,t){let n=e.length-1,r=t-1,i=-1,a=!1,o,s,c,l,u=[];for(;++r<=n;){let t=e[r];switch(t[1].type){case`listUnordered`:case`listOrdered`:case`blockQuote`:t[0]===`enter`?i++:i--,l=void 0;break;case`lineEndingBlank`:t[0]===`enter`&&(o&&!l&&!i&&!c&&(c=r),l=void 0);break;case`linePrefix`:case`listItemValue`:case`listItemMarker`:case`listItemPrefix`:case`listItemPrefixWhitespace`:break;default:l=void 0}if(!i&&t[0]===`enter`&&t[1].type===`listItemPrefix`||i===-1&&t[0]===`exit`&&(t[1].type===`listUnordered`||t[1].type===`listOrdered`)){if(o){let n=r;for(s=void 0;n--;){let t=e[n];if(t[1].type===`lineEnding`||t[1].type===`lineEndingBlank`){if(t[0]===`exit`)continue;s&&(e[s][1].type=`lineEndingBlank`,a=!0),t[1].type=`lineEnding`,s=n}else if(t[1].type!==`linePrefix`&&t[1].type!==`blockQuotePrefix`&&t[1].type!==`blockQuotePrefixWhitespace`&&t[1].type!==`blockQuoteMarker`&&t[1].type!==`listItemIndent`)break}c&&(!s||c<s)&&(o._spread=!0),o.end=Object.assign({},s?e[s][1].start:t[1].end),u.push({at:s||r,event:[`exit`,o,t[2]]})}if(t[1].type===`listItemPrefix`){let e={type:`listItem`,_spread:!1,start:Object.assign({},t[1].start),end:void 0};o=e,u.push({at:r,event:[`enter`,e,t[2]]}),c=void 0,l=!0}}}let d=e.splice(t),f=0;for(r=-1;++r<d.length;){for(;f<u.length&&u[f].at===t+r;)e.push(u[f++].event);e.push(d[r])}e[t][1]._spread=a}function o(e,t){return n;function n(n){c.call(this,e(n),n),t&&t.call(this,n)}}function s(){this.stack.push({type:`fragment`,children:[]})}function c(e,t,n){this.stack[this.stack.length-1].children.push(e),this.stack.push(e),this.tokenStack.push([t,n||void 0]),e.position={start:qB(t.start),end:void 0}}function l(e){return t;function t(t){e&&e.call(this,t),u.call(this,t)}}function u(e,t){let n=this.stack.pop(),r=this.tokenStack.pop();if(!r)throw Error("Cannot close `"+e.type+"` ("+BB({start:e.start,end:e.end})+`): it’s not open`);r[0].type!==e.type&&(t?t.call(this,e,r[0]):(r[1]||XB).call(this,e,r[0])),n.position.end=qB(e.end)}function d(){return qL(this.stack.pop())}function f(){this.data.expectingFirstListItemValue=!0}function p(e){if(this.data.expectingFirstListItemValue){let t=this.stack[this.stack.length-2];t.start=Number.parseInt(this.sliceSerialize(e),10),this.data.expectingFirstListItemValue=void 0}}function m(){let e=this.resume(),t=this.stack[this.stack.length-1];t.lang=e}function h(){let e=this.resume(),t=this.stack[this.stack.length-1];t.meta=e}function g(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function _(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,``),this.data.flowCodeInside=void 0}function v(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e.replace(/(\r?\n|\r)$/g,``)}function y(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.label=t,n.identifier=oR(this.sliceSerialize(e)).toLowerCase()}function b(){let e=this.resume(),t=this.stack[this.stack.length-1];t.title=e}function x(){let e=this.resume(),t=this.stack[this.stack.length-1];t.url=e}function S(e){let t=this.stack[this.stack.length-1];t.depth||=this.sliceSerialize(e).length}function C(){this.data.setextHeadingSlurpLineEnding=!0}function w(e){let t=this.stack[this.stack.length-1];t.depth=this.sliceSerialize(e).codePointAt(0)===61?1:2}function T(){this.data.setextHeadingSlurpLineEnding=void 0}function E(e){let t=this.stack[this.stack.length-1].children,n=t[t.length-1];n&&n.type===`text`||(n=B(),n.position={start:qB(e.start),end:void 0},t.push(n)),this.stack.push(n)}function D(e){let t=this.stack.pop();t.value+=this.sliceSerialize(e),t.position.end=qB(e.end)}function O(e){let n=this.stack[this.stack.length-1];if(this.data.atHardBreak){let t=n.children[n.children.length-1];t.position.end=qB(e.end),this.data.atHardBreak=void 0}else!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(n.type)&&(E.call(this,e),D.call(this,e))}function k(){this.data.atHardBreak=!0}function A(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e}function j(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e}function M(){let e=this.resume(),t=this.stack[this.stack.length-1];t.value=e}function N(){let e=this.stack[this.stack.length-1];if(this.data.inReference){let t=this.data.referenceType||`shortcut`;e.type+=`Reference`,e.referenceType=t,delete e.url,delete e.title}else delete e.identifier,delete e.label;this.data.referenceType=void 0}function P(){let e=this.stack[this.stack.length-1];if(this.data.inReference){let t=this.data.referenceType||`shortcut`;e.type+=`Reference`,e.referenceType=t,delete e.url,delete e.title}else delete e.identifier,delete e.label;this.data.referenceType=void 0}function F(e){let t=this.sliceSerialize(e),n=this.stack[this.stack.length-2];n.label=RB(t),n.identifier=oR(t).toLowerCase()}function I(){let e=this.stack[this.stack.length-1],t=this.resume(),n=this.stack[this.stack.length-1];this.data.inReference=!0,n.type===`link`?n.children=e.children:n.alt=t}function L(){let e=this.resume(),t=this.stack[this.stack.length-1];t.url=e}function R(){let e=this.resume(),t=this.stack[this.stack.length-1];t.title=e}function ee(){this.data.inReference=void 0}function z(){this.data.referenceType=`collapsed`}function te(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.label=t,n.identifier=oR(this.sliceSerialize(e)).toLowerCase(),this.data.referenceType=`full`}function ne(e){this.data.characterReferenceType=e.type}function re(e){let t=this.sliceSerialize(e),n=this.data.characterReferenceType,r;n?(r=aR(t,n===`characterReferenceMarkerNumeric`?10:16),this.data.characterReferenceType=void 0):r=QL(t);let i=this.stack[this.stack.length-1];i.value+=r}function ie(e){let t=this.stack.pop();t.position.end=qB(e.end)}function ae(e){D.call(this,e);let t=this.stack[this.stack.length-1];t.url=this.sliceSerialize(e)}function oe(e){D.call(this,e);let t=this.stack[this.stack.length-1];t.url=`mailto:`+this.sliceSerialize(e)}function se(){return{type:`blockquote`,children:[],position:void 0}}function ce(){return{type:`code`,lang:null,meta:null,value:``,position:void 0}}function le(){return{type:`inlineCode`,value:``,position:void 0}}function ue(){return{type:`definition`,identifier:``,label:null,title:null,url:``,position:void 0}}function de(){return{type:`emphasis`,children:[],position:void 0}}function fe(){return{type:`heading`,depth:0,children:[],position:void 0}}function pe(){return{type:`break`,position:void 0}}function me(){return{type:`html`,value:``,position:void 0}}function he(){return{type:`image`,title:null,url:``,alt:null,position:void 0}}function ge(){return{type:`link`,title:null,url:``,children:[],position:void 0}}function _e(e){return{type:`list`,ordered:e.type===`listOrdered`,start:null,spread:e._spread,children:[],position:void 0}}function ve(e){return{type:`listItem`,spread:e._spread,checked:null,children:[],position:void 0}}function ye(){return{type:`paragraph`,children:[],position:void 0}}function be(){return{type:`strong`,children:[],position:void 0}}function B(){return{type:`text`,value:``,position:void 0}}function xe(){return{type:`thematicBreak`,position:void 0}}}function qB(e){return{line:e.line,column:e.column,offset:e.offset}}function JB(e,t){let n=-1;for(;++n<t.length;){let r=t[n];Array.isArray(r)?JB(e,r):YB(e,r)}}function YB(e,t){let n;for(n in t)if(WB.call(t,n))switch(n){case`canContainEols`:{let r=t[n];r&&e[n].push(...r);break}case`transforms`:{let r=t[n];r&&e[n].push(...r);break}case`afterExit`:case`beforeEnter`:{let r=t[n];r&&e[n].push(r);break}case`enter`:case`exit`:{let r=t[n];r&&Object.assign(e[n],r);break}}}function XB(e,t){throw Error(e?"Cannot close `"+e.type+"` ("+BB({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+BB({start:t.start,end:t.end})+`) is open`:"Cannot close document, a token (`"+t.type+"`, "+BB({start:t.start,end:t.end})+`) is still open`)}var ZB=new Set([`http:`,`https:`,`mailto:`]),QB=e=>{try{return ZB.has(new URL(e).protocol)}catch{return!1}},$B=50,eV=e=>{let t=0,n=[{node:e,depth:0}];for(let e=n.pop();e!==void 0;e=n.pop())if(t=Math.max(t,e.depth),`children`in e.node)for(let t of e.node.children)n.push({node:t,depth:e.depth+1});return t},tV=e=>{let t=GB(e);if(eV(t)>$B)throw RangeError(`Nested too deep`);return t},nV=e=>e.type===`break`?`
98
+ `:e.type===`image`||e.type===`imageReference`?e.alt??``:`value`in e?e.value:`children`in e?e.children.map(nV).join(``):``,rV=[`root`,`blockquote`,`listItem`],iV=e=>`children`in e?e.children.reduce((t,n)=>t+(n.type===`code`||n.type===`html`&&rV.includes(e.type)?1:0)+iV(n),0):0,aV=(e,t=120)=>{let n=e=>{let n=e.trim();return n.length>t?`${n.slice(0,t-1)}…`:n};try{return n(nV(tV(e).children.find(e=>nV(e).trim()!==``)??{type:`text`,value:``}).split(`
99
99
  `).find(e=>e.trim()!==``)??``)}catch{return n(e.split(`
100
- `).find(e=>e.trim()!==``)??``)}},JB=e=>e===``?0:e.replace(/\n+$/u,``).split(`
101
- `).length,YB={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`},XB=[`h1`,`h2`,`h3`,`h4`,`h5`,`h6`],ZB=(e,t)=>t===1?`Copy code`:`Copy code block ${e} of ${t}`,QB=e=>String(e.position?.start.offset),$B=(e,t)=>{let n=0;return e.split(`
102
- `).flatMap((e,r)=>{let i=`${t}:${n}`;return n+=e.length+1,r===0?[e]:[(0,q.jsx)(`br`,{},i),e]})},eV=e=>e.map(e=>(0,q.jsx)(U.Fragment,{children:tV(e)},QB(e))),tV=e=>e.type===`text`?$B(e.value,QB(e)):e.type===`emphasis`?(0,q.jsx)(`em`,{children:eV(e.children)}):e.type===`strong`?(0,q.jsx)(`strong`,{children:eV(e.children)}):e.type===`delete`||e.type===`linkReference`?eV(e.children):e.type===`inlineCode`?(0,q.jsx)(`code`,{className:YB.inline,children:e.value}):e.type===`break`?(0,q.jsx)(`br`,{}):e.type===`html`?e.value:e.type===`link`?nV(e.url,e.children):e.type===`image`||e.type===`imageReference`?(0,q.jsx)(`span`,{className:YB.image,children:e.alt===void 0||e.alt===null||e.alt===``?`image`:`image: ${e.alt}`}):null,nV=(e,t)=>{if(BB(e))return(0,q.jsxs)(`a`,{className:YB.link,href:e,rel:`noopener noreferrer`,target:`_blank`,children:[eV(t),(0,q.jsx)(lk,{children:` (opens in a new tab)`})]});let n=t.map(e=>WB(e)).join(``);return n===e||n===``?(0,q.jsx)(`code`,{className:YB.target,children:e}):(0,q.jsxs)(q.Fragment,{children:[eV(t),` (`,(0,q.jsx)(`code`,{className:YB.target,children:e}),`)`]})},rV=(e,t,n)=>{let r=QB(e);if(e.type===`paragraph`)return(0,q.jsx)(`p`,{children:eV(e.children)},r);if(e.type===`heading`){let t=XB[Math.min(6,n.startLevel+e.depth-1)-1]??`h6`;return(0,q.jsx)(t,{children:eV(e.children)},r)}if(e.type===`thematicBreak`)return(0,q.jsx)(`hr`,{},r);if(e.type===`blockquote`)return(0,q.jsx)(`blockquote`,{children:aV(e,n)},r);if(e.type===`list`){let t=e.children.map(e=>(0,q.jsx)(`li`,{children:aV(e,n)},QB(e)));return e.ordered===!0?(0,q.jsx)(`ol`,{start:e.start??1,children:t},r):(0,q.jsx)(`ul`,{children:t},r)}return e.type===`definition`?(0,q.jsxs)(`p`,{children:[`[`,e.label??e.identifier,`]:`,` `,(0,q.jsx)(`code`,{className:YB.target,children:e.url})]},r):e.type===`code`?iV(e.value,e.lang,n,r):e.type===`html`?GB.includes(t.type)?iV(e.value,void 0,n,r):(0,q.jsx)(U.Fragment,{children:e.value},r):null},iV=(e,t,n,r)=>(0,q.jsx)(cC,{caption:t??void 0,command:e,label:n.copyLabel(n.next(),n.blocks)},r),aV=(e,t)=>e.children.map(n=>rV(n,e,t)),oV=e=>(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`p`,{className:YB.note,children:`Could not render this as Markdown: showing the text as written.`}),(0,q.jsx)(`pre`,{className:YB.written,children:e})]}),sV=({text:e,startLevel:t,lead:n=!1,muted:r=!1,copyLabel:i=ZB})=>{let a;try{let n=UB(e),r=0;a=aV(n,{startLevel:t,blocks:KB(n),next:()=>++r,copyLabel:i})}catch{a=oV(e)}return(0,q.jsx)(`div`,{className:YB.markdown,"data-lead":n?``:void 0,"data-muted":r?``:void 0,children:a})},cV=e=>{let t=JB(e);return t===1?`1 line`:`${t} lines`},lV=({decision:e,document:t})=>{let[n,r]=(0,U.useState)(!1),i=(0,U.useRef)(null),{id:a,node:o,runId:s}=e;return(0,q.jsxs)(`div`,{className:AL.read,children:[(0,q.jsx)(Y,{cli:bL(e),onClick:()=>{r(!0)},variant:`ghost`,children:`Read document`}),(0,q.jsx)(`span`,{className:AL.length,children:cV(t)}),(0,q.jsxs)(NC,{description:`Document for run ${s}. Read-only.`,initialFocus:i,onOpenChange:r,open:n,size:`wide`,title:`\`${o}\` · \`${a}\``,children:[(0,q.jsx)(`div`,{"aria-label":`Document`,className:AL.document,ref:i,role:`region`,tabIndex:0,children:(0,q.jsx)(sV,{copyLabel:yL(`${o} document`),startLevel:3,text:t})}),(0,q.jsx)(PC,{children:(0,q.jsx)(Y,{onClick:()=>{r(!1)},children:`Close`})})]})]})},uV={region:`_region_1w5dd_7`,more:`_more_1w5dd_23`},dV=e=>{let t=Number(getComputedStyle(e).lineHeight.replace(`px`,``));return e.scrollHeight>0&&t>0?Math.round(e.scrollHeight/t):null},fV=({source:e,children:t})=>{let n=(0,U.useRef)(null),r=(0,U.useId)(),[i,a]=(0,U.useState)(!1),[o,s]=(0,U.useState)(()=>JB(e)),c=(0,U.useCallback)(()=>{let t=n.current;s((t===null?null:dV(t))??JB(e))},[e]);(0,U.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,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{className:uV.region,"data-folded":l&&!i?``:void 0,id:r,onFocus:()=>{a(!0)},ref:n,children:t}),l?(0,q.jsx)(`div`,{className:uV.more,children:(0,q.jsx)(Y,{"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]})},pV=({decision:{kind:e,node:t,question:n,context:r},nameId:i})=>(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{hidden:!0,id:i,children:qB(n)}),(0,q.jsx)(fV,{source:n,children:(0,q.jsx)(sV,{copyLabel:yL(t),lead:!0,startLevel:4,text:n})}),r===void 0?null:e===`permission`?(0,q.jsx)(cC,{caption:xL(r)?`json`:void 0,command:r,label:`Copy command (${t})`}):(0,q.jsx)(fV,{source:r,children:(0,q.jsx)(sV,{copyLabel:yL(t),muted:!0,startLevel:4,text:r})})]}),mV=e=>e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLButtonElement&&!(`option`in e.dataset),hV=({decision:e,workflow:t,unreachable:n=!1,onAnswer:r,onOpenRun:i})=>{let{id:a,runId:o,node:s,document:c,options:l,recommended:u,owner:d}=e,f=(0,U.useId)(),p=(0,U.useId)(),[m,h]=(0,U.useState)(!1),[g,_]=(0,U.useState)(null),[v,y]=(0,U.useState)(``),b=async e=>{if(m||n)return;h(!0),_(null);let t=await r(a,e.id,v);h(!1),t.ok||_(t.error)};return(0,q.jsxs)(`section`,{"aria-labelledby":`${p} ${f}`,className:AL.card,"data-decision":a,onKeyDown:e=>{if(!(e.target instanceof Node)||!e.currentTarget.contains(e.target)||e.metaKey||e.ctrlKey||e.altKey||mV(e.target))return;let t=e.target===e.currentTarget,n=e.key===`Enter`&&t?l.find(e=>e.id===u):vL(l,e.key);n!==void 0&&(e.preventDefault(),b(n))},tabIndex:0,children:[(0,q.jsxs)(`div`,{className:AL.from,children:[(0,q.jsxs)(`h3`,{className:AL.fromText,id:p,children:[t===void 0?``:`${t} · `,o,` · `,s,d===void 0?``:`, passed on by ${d}`]}),(0,q.jsx)(Y,{onClick:()=>{i(o,s)},variant:`ghost`,children:`Open run`})]}),(0,q.jsx)(pV,{decision:e,nameId:f}),c===void 0?null:(0,q.jsx)(lV,{decision:e,document:c}),(0,q.jsx)(NL,{decision:e,note:v,onChoose:e=>{b(e)},onNote:y,sending:m,unreachable:n}),g===null?null:(0,q.jsxs)(`p`,{className:AL.refusal,role:`alert`,children:[`Could not answer: `,(0,q.jsx)(r_,{text:g})]})]})},gV=e=>{let t=cb.create(null),n=cb.create(null),r=cb.create(null),i=cb.create(null),a=cb.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)}}},_V=(e,t,n)=>e?.kind===`builder`&&e.project===t&&e.workflow===n,vV=()=>{let e=cb.create(null),t=t=>{e.setValue(t)},n=n=>{let r=e.getValue();t({kind:`builder`,...n,revision:_V(r,n.project,n.workflow)?r.revision:0})},r=(n,r,i)=>{let a=e.getValue();_V(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:gV({chooseBuilder:n,builderChanged:r,builderClosed:i}),chooseRun:(e,n)=>{t(e===null?null:{kind:`run`,run:e,node:n})}}},yV=e=>{let t=cb.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}}},bV=2e3,xV={events:[],latest:0,following:!0},SV=e=>e.events[0]?.seq??1,CV=e=>e.events.at(-1)?.seq??0,wV=e=>SV(e)>1,TV=e=>CV(e)<e.latest,EV=e=>e.slice(-2e3),DV=(e,t)=>Math.max(e.latest,t.at(-1)?.seq??0),OV=(e,t)=>{let n=CV(e);return t.filter(e=>e.seq>n)},kV=(e,t)=>{let n=DV(e,t);return e.following&&!TV(e)?{...e,latest:n,events:EV([...e.events,...OV(e,t)])}:{...e,latest:n}},AV=(e,t)=>({events:EV(t),latest:DV(e,t),following:!0}),jV=(e,t)=>({...e,latest:DV(e,t),events:EV([...e.events,...OV(e,t)])}),MV=(e,t)=>{let n=SV(e),r=[...t.filter(e=>e.seq<n),...e.events].slice(0,bV),i={...e,events:r};return{...i,following:e.following&&!TV(i)}},NV=e=>{let t=SV(e)-1,n=Math.max(0,t-500);return{after:n,limit:t-n}},PV=e=>new EventSource(e),FV=2,IV=1e3,LV=15e3,RV=e=>{try{return JSON.parse(e)}catch{return}},zV=({url:e,open:t,on:n,onStatus:r,onFailure:i})=>{let a=null,o=null,s=IV,c=null,l=e=>{e!==c&&(c=e,r(e))},u=()=>{let r=t(e());a=r,r.addEventListener(`open`,()=>{s=IV,l(`open`)}),r.addEventListener(`error`,()=>{l(`lost`),i?.(),r.readyState===FV&&(r.close(),o=setTimeout(u,s),s=Math.min(s*2,LV))});let c=Object.entries(n);for(let[e,t]of c)r.addEventListener(e,e=>{let n=RV(e.data);n!==void 0&&t(n)})};return l(`connecting`),u(),{close:()=>{o!==null&&clearTimeout(o),o=null,a?.close(),a=null}}},BV=1e3,VV=({runId:e,client:t,open:n})=>{let r=cb.create({...xV,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&&TV(e)&&!e.paging&&await p({after:CV(e),limit:500},jV)&&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({...kV(t,e),tail:[...t.tail,...e.filter(e=>e.seq>n)].slice(-500)}),m()},g=()=>{i?.close(),i=null},_=()=>{i=zV({url:()=>`${Sw(xw.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},AV);e===s&&(t?(a=!0,_()):(d({link:`lost`}),u=setTimeout(()=>void v(),BV)))};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();wV(e)&&!e.paging&&await p(NV(e),MV)},loadNewer:async()=>{let e=r.getValue();TV(e)&&!e.paging&&await p({after:CV(e),limit:500},jV)},hold:()=>{d({following:!1})},follow:async()=>{let e=r.getValue();e.paging||(TV(e)?await p({last:500},AV):d({following:!0}),await m())}}},HV=({runId:e,client:t,feed:n})=>{let r=cb.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}}}},UV=e=>e.live===`running`||e.live===`paused`,WV=({client:e,open:t})=>{let n=new Map,r=r=>{let i=n.get(r)??{feed:VV({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&&UV(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=>HV({runId:t,client:e,feed:r(t).feed})}},GV=`ork.notifications.read`,KV=hs({before:V().nullable(),ids:ps(V())}),qV=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} ${Wj(e.live)}.`,at:e.finishedAt??e.startedAt,pending:t}},JV=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}),YV=(e,t)=>[...t.map(e=>JV(e)),...e.flatMap(e=>qV(e)??[])].toSorted((e,t)=>t.at.localeCompare(e.at)),XV=(e,t)=>t.ids.includes(e.id)||!e.pending&&t.before!==null&&e.at<=t.before,ZV=({runs:e,decisions:t,storage:n,now:r=()=>new Date().toISOString()})=>{let i=new ub({before:null,ids:[]},{key:GV,storage:n});KV.safeParse(i.getValue()).success||i.reset();let a=cb.create({items:[],unread:0}),o=null,s=new Set,c=[],l=()=>{let e=i.getValue(),t=c.map(t=>({...t,unread:!XV(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=YV(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()}}},QV=(e,t)=>JSON.stringify(e)===JSON.stringify(t),$V=(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&&QV(t,e)?t:e});return r.length===e.length&&r.every((t,n)=>t===e[n])?e:r},eH=({client:e,open:t,pageVersion:n})=>{let r=cb.create(null),i=cb.create(null);return{info:r,open:t,pageVersion:n,dialog:i,restarting:cb.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)}}},tH=({client:e,open:t,pageVersion:n,runs:r,decisions:i})=>{let a=eH({client:e,open:t,pageVersion:n});return{version:a,follow:e=>zV({url:()=>xw.overview,open:t,on:{runs:e=>{r.setValue($V(r.getValue(),e))},decisions:e=>{i.setValue($V(i.getValue(),e))},version:a.receive},...e})}},nH=e=>e.status===`ready`?{data:e.data,arg:e.arg}:e.status===`idle`?void 0:e.shown,rH=e=>{let t=cb.create({status:`idle`}),n=0;return{state:t,load:async r=>{n+=1;let i=n,a=nH(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}})}}},iH=({link:e,server:t})=>e===`lost`||t!==null&&`error`in t,aH=e=>{let{link:t,server:n}=e;return n!==null&&`error`in n?`Cannot reach \`ork ui\`: ${n.error}`:iH(e)?"Lost the stream from `ork ui`. Retrying…":t===`open`&&n!==null?`Ork ${n.version}`:"Connecting to `ork ui`…"},oH=e=>e===null?null:e.filter(e=>UV(e)).length,sH=({client:e,open:t,storage:n,pageVersion:r=null})=>{let i=cb.create(null),a=cb.create(null),o=cb.create({link:`connecting`,server:null}),s=cb.create({run:null,node:null}),c=vV(),l=null,u=e=>{e.run!==l&&(l=null),s.setValue(e),c.chooseRun(e.run,e.node)},d=mb(n),f=cb.create(`all`),p=cb.create(!1),m=cb.create(null),h=rH(()=>e.call(`projects`)),g=rH(()=>e.call(`triggers`)),_=rH(t=>e.call(`workflows`,{params:{id:t}})),v=cb.create({project:`all`,period:`30`}),y=rH(({query:t})=>e.call(`usage`,{query:t})),b=cb.create({status:`open`,about:`all`}),x=rH(()=>e.call(`feedbackItems`)),S=cb.create(`all`),C=rH(()=>e.call(`worktrees`)),w=WV({client:e,open:t}),T=yV(e),E=ZV({runs:i,decisions:a,storage:n}),D=tH({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})}}},cH=()=>iH(vb(ob().connection)),lH=()=>(0,q.jsxs)(`p`,{className:AL.unreachable,"data-unreachable-notice":``,children:[(0,q.jsx)(My,{"aria-hidden":`true`}),(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:"Cannot answer here: `ork ui` is not reachable. Answer from a terminal with the command under each option."})})]}),uH=({view:e,open:t,onChange:n})=>{let{workflow:r,run:i}=e.active;return(0,q.jsxs)(`div`,{className:AL.filter,children:[(0,q.jsxs)(`div`,{className:AL.filterFields,children:[(0,q.jsx)(uk,{label:`Workflow`,onChange:e=>{n(e===` all`?{}:{workflow:e})},options:e.workflows,value:r??` all`}),(0,q.jsx)(uk,{label:`Run`,onChange:e=>{n({...r===void 0?{}:{workflow:r},...e===` all`?{}:{run:e}})},options:e.runs,value:i??` all`})]}),(0,q.jsxs)(`div`,{className:AL.counts,children:[(0,q.jsx)(`output`,{children:DL(t,e.shown.length)}),OL(e.active)?(0,q.jsx)(Y,{onClick:()=>{n({})},variant:`ghost`,children:`Clear filter`}):null]})]})},dH=({filter:e,open:t,onClear:n})=>t===0?(0,q.jsx)(qD,{cli:`ork decide`,title:`No decisions waiting.`,children:`Questions from your runs land here. In a terminal:`}):(0,q.jsxs)(qD,{cli:kL(e),title:`No decisions match the filter.`,children:[(0,q.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,q.jsx)(Y,{onClick:n,variant:`ghost`,children:`Clear filter`})]}),fH=({settled:e})=>e.length===0?null:(0,q.jsxs)(`section`,{"aria-label":`Settled decisions`,className:AL.settled,children:[(0,q.jsx)(`h3`,{className:AL.settledTitle,children:`Settled`}),(0,q.jsx)(`ul`,{className:AL.settledList,children:e.map(e=>(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:AL.settledQuestion,children:e.question}),(0,q.jsxs)(`span`,{className:AL.settledEnding,children:[(0,q.jsx)(`code`,{children:e.runId}),` · `,(0,q.jsx)(`code`,{children:e.node}),`.`,` `,(0,q.jsx)(r_,{text:gL(e)})]}),_L(e)===void 0?null:(0,q.jsx)(`span`,{className:AL.settledNote,children:_L(e)})]},e.id))})]}),pH=e=>e.tabIndex>=0?e:e.querySelector(`button`),mH=(e,t)=>{let n=(0,U.useRef)(null),r=(0,U.useRef)(null),i=(0,U.useRef)(e),a=(0,U.useRef)(null);return(0,U.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:pH(s))??n.current)?.focus()},[e,t]),(0,U.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)}}},hH=()=>{let e=ob(),t=(0,U.use)(fL),n=vb(e.decisions),r=vb(e.settledDecisions),i=vb(e.runs),a=cH(),o=(0,U.useRef)(r[0]?.id),{value:s,update:c}=e.preferences,l=vb(s).decisionFilter,u=(0,U.useMemo)(()=>n??[],[n]),d=(0,U.useCallback)(e=>i?.find(({id:t})=>t===e)?.workflow,[i]),f=n!==null&&i!==null,[p,m]=(0,U.useState)(!1),h=EL(u,!f||p?l:wL(u,l,d),d),g=new Set(u.map(({runId:e})=>e)).size>1,{panel:_,onFocus:v}=mH(h.shown.map(({id:e})=>e).join(`
103
- `),`[data-decision]`),y=e=>{c({decisionFilter:e})};return(0,U.useEffect)(()=>{if(p||!f)return;let e=wL(u,l,d);(e.workflow!==l.workflow||e.run!==l.run)&&c({decisionFilter:e}),m(!0)},[f,p,u,l,c,d]),(0,U.useEffect)(()=>{let e=r[0];e!==void 0&&e.id!==o.current&&(o.current=e.id,t?.announce(`${e.question} ${gL(e)}`))},[r,t]),(0,q.jsxs)(`div`,{"aria-label":`Decisions`,className:AL.panel,onFocus:v,ref:_,role:`group`,tabIndex:-1,children:[OL(h.active)||g?(0,q.jsx)(uH,{onChange:y,open:u.length,view:h}):null,h.shown.length===0?(0,q.jsx)(dH,{filter:h.active,onClear:()=>{y({})},open:u.length}):(0,q.jsxs)(`div`,{className:AL.list,children:[a?(0,q.jsx)(lH,{}):null,h.shown.map(t=>(0,q.jsx)(hV,{decision:t,onAnswer:e.answerDecision,onOpenRun:(t,n)=>{e.selectRun(t),e.selectNode(n)},unreachable:a,workflow:d(t.runId)},t.id))]}),(0,q.jsx)(fH,{settled:r})]})},gH={panel:`_panel_1eq6v_8`,tools:`_tools_1eq6v_24`,main:`_main_1eq6v_39`,status:`_status_1eq6v_52`,counts:`_counts_1eq6v_65`,error:`_error_1eq6v_82`,list:`_list_1eq6v_91`,item:`_item_1eq6v_106`,row:`_row_1eq6v_113`,time:`_time_1eq6v_152`,type:`_type_1eq6v_153`,node:`_node_1eq6v_159`,line:`_line_1eq6v_161`,detail:`_detail_1eq6v_186`,end:`_end_1eq6v_210`},_H=e=>e.map(e=>({value:e,label:e})),vH=({events:e,node:t,type:n,text:r,onNode:i,onType:a,onText:o})=>{let s=tL(e,t),c=s.map(e=>eL(e,s));return(0,q.jsxs)(`div`,{className:gH.tools,children:[(0,q.jsx)(aC,{empty:`No node matches.`,label:`Node`,onChange:i,options:c,placeholder:`All nodes`,value:t}),(0,q.jsx)(aC,{empty:`No event type matches.`,label:`Event`,onChange:a,options:_H(nL(e)),placeholder:`All events`,value:n}),(0,q.jsx)(pk,{label:`Text`,onChange:o,value:r})]})},yH={end:`_end_wtaow_6`,note:`_note_wtaow_15`},bH={agent:`failed`,workflow:`failed`,ork:`failed`,account:`waiting`,provider:`interrupted`,user:`interrupted`},xH=e=>bH[e],SH=({end:e,pill:t=!1})=>e.actor===null?null:(0,q.jsxs)(`span`,{className:yH.end,children:[(0,q.jsx)(qj,{pill:t,status:xH(e.actor),word:e.label}),e.transient?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,q.jsx)(lk,{children:`, `}),(0,q.jsx)(`span`,{className:yH.note,"data-transient":!0,children:`may pass`})]}):null]}),CH={well:`_well_14iu2_8`},wH=32,TH=({label:e,text:t,follow:n=!0,ref:r})=>{let i=(0,U.useRef)(null),a=r??i,o=(0,U.useRef)(!0);return(0,U.useLayoutEffect)(()=>{let e=a.current;e!==null&&n&&o.current&&(e.scrollTop=e.scrollHeight)}),(0,q.jsx)(`section`,{"aria-label":e,className:CH.well,onScroll:()=>{let e=a.current;e!==null&&(o.current=e.scrollHeight-e.scrollTop-e.clientHeight<wH)},ref:a,tabIndex:0,children:t})},EH={details:`_details_1cytm_6`,open:`_open_1cytm_16`,bar:`_bar_1cytm_25`,caption:`_caption_1cytm_35`,copy:`_copy_1cytm_49`},DH=({node:e,detail:t,cli:n})=>{let[r,i]=(0,U.useState)(!1),a=(0,U.useId)();return t===void 0?null:(0,q.jsxs)(`div`,{className:EH.details,children:[(0,q.jsxs)(Y,{"aria-controls":r?a:void 0,"aria-expanded":r,cli:n,onClick:()=>{i(e=>!e)},variant:`ghost`,children:[r?(0,q.jsx)(ly,{}):(0,q.jsx)(uy,{}),`Details`]}),r?(0,q.jsxs)(`div`,{className:EH.open,id:a,children:[(0,q.jsxs)(`div`,{className:EH.bar,children:[(0,q.jsx)(`span`,{className:EH.caption,children:`Scrubbed. At most 4 KiB.`}),(0,q.jsx)(`span`,{className:EH.copy,children:(0,q.jsx)(oC,{label:`Copy details`,text:t})})]}),(0,q.jsx)(TH,{follow:!1,label:`Raw details of ${e}`,text:t})]}):null]})},OH={note:`_note_1tzmy_7`,message:`_message_1tzmy_24`,hint:`_hint_1tzmy_25`,facts:`_facts_1tzmy_42`,who:`_who_1tzmy_53`,guide:`_guide_1tzmy_81`},kH=`https://github.com/mimshins/ork/blob/main/docs/guides/why-a-node-stopped.md`,AH={agent:`the agent`,workflow:`the workflow`,account:`your account`,provider:`the provider`,user:`you`,ork:`Ork`},jH=e=>e.endsWith(`.`)?e:`${e}.`,MH=({node:e,end:t,runId:n})=>t.actor===null?null:(0,q.jsxs)(`div`,{"aria-label":`How ${e} ended`,className:OH.note,role:`group`,children:[(0,q.jsxs)(`p`,{className:OH.message,children:[(0,q.jsx)(SH,{end:t,pill:!0}),(0,q.jsxs)(`span`,{children:[(0,q.jsx)(`code`,{children:e}),` `,(0,q.jsx)(r_,{text:jH(t.message)})]})]}),t.hint===``?null:(0,q.jsx)(`p`,{className:OH.hint,children:(0,q.jsx)(r_,{text:t.hint})}),(0,q.jsxs)(`div`,{className:OH.facts,children:[(0,q.jsxs)(`dl`,{className:OH.who,children:[(0,q.jsx)(`dt`,{children:`Who acts`}),(0,q.jsx)(`dd`,{children:AH[t.actor]})]}),(0,q.jsxs)(`a`,{className:OH.guide,href:`${kH}#${t.docsAnchor}`,rel:`noreferrer`,target:`_blank`,children:[`Why a node stops`,(0,q.jsx)(Fy,{}),(0,q.jsx)(lk,{children:` — what ${t.label} means (opens the guide in a new tab)`})]})]}),(0,q.jsx)(DH,{cli:`ork logs ${n} --node ${e}`,detail:t.detail,node:e})]}),NH=(0,U.memo)(({stored:e,open:t,tabbable:n,onToggle:r})=>{let{seq:i,at:a,event:o}=e,s=UI(o);return(0,q.jsxs)(`li`,{className:gH.item,children:[(0,q.jsxs)(`button`,{"aria-expanded":t,className:gH.row,"data-log-row":i,onClick:()=>{r(i)},tabIndex:n?0:-1,type:`button`,children:[(0,q.jsx)(`span`,{className:gH.time,children:aL(a)}),(0,q.jsx)(`span`,{className:gH.node,children:RI(o)??`run`}),(0,q.jsx)(`span`,{className:gH.type,children:o.type}),(0,q.jsx)(`span`,{className:gH.line,children:s===void 0?qI(o):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(SH,{end:s.end}),` `,GI(s)]})})]}),t&&s!==void 0?(0,q.jsx)(`div`,{className:gH.end,children:(0,q.jsx)(MH,{end:s.end,node:s.id,runId:e.runId})}):null,t?(0,q.jsx)(`pre`,{"aria-label":`Event ${String(i)} in full`,className:gH.detail,role:`group`,tabIndex:0,children:JSON.stringify(o,null,2)}):null]})});NH.displayName=`LogRow`;var PH=({shown:e,listRef:t,onScroll:n,label:r,reading:i})=>{let[a,o]=(0,U.useState)(new Set),[s,c]=(0,U.useState)(null),l=e.some(({seq:e})=>e===s)?s:e.at(-1)?.seq??null,u=(0,U.useCallback)(e=>{c(e),o(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n})},[]);return e.length===0?(0,q.jsx)(qD,{title:i?`Reading the run…`:`No event matches.`,children:`Only loaded events are filtered. Load older ones to look further.`}):(0,q.jsx)(`ol`,{"aria-label":r,className:gH.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,q.jsx)(NH,{onToggle:u,open:a.has(e.seq),stored:e,tabbable:e.seq===l},e.seq))})},FH=({events:e,shown:t,feed:n,cli:r})=>{let i=e.events.length,a=e.latest-CV(e);return(0,q.jsxs)(`div`,{className:gH.status,children:[(0,q.jsx)(`span`,{className:gH.counts,children:rL(t,i,e.latest)}),(0,q.jsx)(Y,{disabled:!wV(e)||e.paging,focusableWhenDisabled:!0,onClick:()=>{n.loadOlder()},variant:`ghost`,children:`Load older`}),(0,q.jsxs)(Y,{"aria-pressed":e.following,cli:r,onClick:()=>{e.following?n.hold():n.follow()},variant:`ghost`,children:[e.following?(0,q.jsx)(cy,{}):null,`Follow`,a>0?` (${String(a)} new)`:``]})]})},IH=({error:e})=>(0,q.jsx)(`p`,{className:gH.error,role:`alert`,children:(0,q.jsx)(r_,{text:e})}),LH=32,RH=e=>e.scrollHeight-e.scrollTop-e.clientHeight<LH,zH=(e,t)=>{let n=(0,U.useRef)(null),{following:r}=t,i=t.events[0]?.seq,a=(0,U.useRef)({firstSeq:i,height:0});return(0,U.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,U.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=RH(t),i=e.state.getValue();i.following&&!r?e.hold():!i.following&&r&&!TV(i)&&e.follow()}}},BH=500,VH=({runId:e,node:t})=>{let n=ob(),r=(0,U.useMemo)(()=>n.feedOf(e),[n,e]);(0,U.useEffect)(()=>n.retainRun(e),[n,e]);let i=vb(r.state),[a,o]=(0,U.useState)(null),[s,c]=(0,U.useState)(``),l=(0,U.useMemo)(()=>QI(i.events,{node:t,type:a,text:s}),[i.events,t,a,s]),{listRef:u,onScroll:d}=zH(r,i),f=(0,U.use)(fL),p=JSON.stringify([t,a,s]),m=(0,U.useRef)(p),h=rL(l.length,i.events.length,i.latest);return(0,U.useEffect)(()=>{let e=setTimeout(()=>{p!==m.current&&(m.current=p,f?.announce(h))},BH);return()=>{clearTimeout(e)}},[p,h,f]),(0,q.jsxs)(`div`,{className:gH.panel,children:[(0,q.jsx)(vH,{events:i.events,node:t,onNode:n.selectNode,onText:c,onType:o,text:s,type:a}),(0,q.jsxs)(`div`,{className:gH.main,children:[(0,q.jsx)(FH,{cli:iL(e,t),events:i,feed:r,shown:l.length}),i.error===null?null:(0,q.jsx)(IH,{error:i.error}),(0,q.jsx)(PH,{label:`Events of run ${e}`,listRef:u,onScroll:d,reading:i.link===`loading`&&i.events.length===0,shown:l})]})]})},HH=()=>{let{run:e,node:t}=vb(ob().selection);return e===null?(0,q.jsx)(qD,{cli:`ork logs <run>`,title:`No run chosen.`,children:`Choose one in the Runs panel, or in a terminal:`}):(0,q.jsx)(VH,{node:t,runId:e},e)},UH={monitor:`_monitor_17zqb_8`,header:`_header_17zqb_25`,stats:`_stats_17zqb_43`,stat:`_stat_17zqb_43`,statName:`_statName_17zqb_58`,statValue:`_statValue_17zqb_74`,title:`_title_17zqb_90`,runId:`_runId_17zqb_101`,controls:`_controls_17zqb_111`,error:`_error_17zqb_119`,canvas:`_canvas_17zqb_133`,table:`_table_17zqb_144`,tableHead:`_tableHead_17zqb_162`,tree:`_tree_17zqb_185`,treeRow:`_treeRow_17zqb_190`,treeNode:`_treeNode_17zqb_233`,treeToggle:`_treeToggle_17zqb_239`,treeId:`_treeId_17zqb_259`,treeType:`_treeType_17zqb_269`,treeStatus:`_treeStatus_17zqb_285`,treeNow:`_treeNow_17zqb_291`,treeTime:`_treeTime_17zqb_301`,treeCost:`_treeCost_17zqb_314`,sideTitle:`_sideTitle_17zqb_337`,node:`_node_17zqb_346`,nodeFacts:`_nodeFacts_17zqb_362`,watching:`_watching_17zqb_363`,end:`_end_17zqb_373`,links:`_links_17zqb_416`,linkList:`_linkList_17zqb_431`,link:`_link_17zqb_416`,linkEnds:`_linkEnds_17zqb_451`,linkCount:`_linkCount_17zqb_462`},WH=({error:e})=>(0,q.jsx)(`p`,{className:UH.error,role:`alert`,children:(0,q.jsx)(r_,{text:e})}),GH=({runId:e,layout:t,...n})=>(0,q.jsx)(`div`,{className:UH.canvas,children:t===null?(0,q.jsx)(qD,{cli:`ork tree ${e}`,title:`Reading the run…`,children:`For now:`}):(0,q.jsx)(aN,{...n,layout:t,live:!0})}),KH=e=>{let t=e.template===void 0?void 0:/\.(\d+)$/u.exec(e.id)?.[1];return t===void 0?void 0:Number(t)},qH=e=>{let t=e.children.filter(e=>KH(e)!==void 0).toSorted((e,t)=>(KH(e)??0)-(KH(t)??0));return[...e.children.filter(e=>!t.includes(e)),...t]},JH=(e,t=new Set)=>{let n=(e,r,i)=>e.flatMap(e=>[{node:e,depth:r,parent:i},...t.has(e.id)?[]:n(qH(e),r+1,e.id)]);return n(e,1)},YH={waiting:`queued`,running:`running`,ok:`succeeded`,failed:`failed`,skipped:`skipped`},XH={waiting:`skipped`,running:`interrupted`},ZH=(e,t,n=!1)=>{let r=n?XH[e.state]:void 0;return r===void 0?e.held===!0?`paused`:t?`waiting`:YH[e.state]:r},QH=(e,t)=>new Set((e??[]).filter(e=>e.runId===t).map(e=>e.node)),$H=18,eU=(e,t,n)=>{let r=n===0?``:`, ${String(n)} failed`,i=`${String(e)} of ${String(t)}${r}`;return i.length>$H?`${String(e)}/${String(t)}${r}`:i},tU=e=>{let{listed:t}=e;if(t===void 0)return;let n=e.children.filter(e=>(KH(e)??1/0)<t);return eU(n.filter(e=>[`ok`,`failed`,`skipped`].includes(e.state)).length,t,n.filter(e=>e.state===`failed`).length)},nU=(e,t,n,r=!1)=>new Map(JH(e).map(({node:e})=>{let i=e.inputTokens+e.outputTokens;return[e.id,{status:ZH(e,t.has(e.id),r),model:e.model,tokens:i===0?void 0:i,costUsd:e.costUsd===0?void 0:e.costUsd,progress:tU(e),cli:`ork logs ${n} --node ${e.id}`}]})),rU=(e,t)=>({run:e,nodes:new Map([...t].map(([e,{status:t}])=>[e,t]))}),iU=new Set([`failed`,`paused`]),aU=(e,t,n)=>[...n.run===t.run||n.run!==`running`?[]:[`Run ${e} ${Wj(n.run)}.`],...[...n.nodes].filter(([e,r])=>r!==t.nodes.get(e)&&iU.has(r)&&(r!==`paused`||n.run!==`paused`)).map(([e,t])=>`${e} ${Wj(t)}.`)],oU=({live:e},t)=>e===`running`&&t?`waiting`:e,sU=(e,t)=>{let n=new Set(e.nodes.map(e=>e.id)),r=JH(t).map(({node:e})=>e).filter(e=>!n.has(e.id)&&KH(e)===void 0).map(({id:e,type:t,parent:n})=>({id:e,type:t,parent:n}));return{...e,nodes:[...e.nodes,...r]}},cU={enabled:!0},lU=e=>({enabled:!1,why:e}),uU=({live:e})=>e===`running`||e===`paused`,dU=e=>e.id.startsWith(`node-`)?lU(`it ran one node; run that node again instead`):cU,fU=e=>{if(!uU(e)){let t=`the run has ended (${e.live})`,n={pause:lU(t),proceed:lU(t),stop:lU(t)};return e.live===`succeeded`?n:{...n,resume:dU(e)}}let t=e.live===`paused`;return{pause:t?lU(`the run is paused`):cU,proceed:t?cU:lU(`the run is not paused`),stop:cU}},pU=(e,t)=>{if(!uU(e)){let t=`the run has ended (${e.live})`;return{pause:lU(t),proceed:lU(t),stop:lU(t)}}if(t.state!==`running`&&t.state!==`waiting`){let e=`${t.id} has finished`;return{pause:lU(e),proceed:lU(e),stop:lU(e)}}let n=t.held===!0||e.paused.nodes.includes(t.id),r=t.state===`running`?cU:lU(`${t.id} is not running`);if(e.live===`paused`){let e=`the whole run is paused; continue the run`;return{pause:lU(e),proceed:lU(e),stop:r}}return{pause:n?lU(`${t.id} is paused`):cU,proceed:n?cU:lU(`${t.id} is not paused`),stop:r}},mU=e=>e.state===`waiting`||e.state===`skipped`?lU(`it hasn't run`):cU,hU={reason:`_reason_sb9l9_7`},gU={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`},_U=`Meta+Enter Control+Enter`,vU=({onSend:e,children:t})=>(0,q.jsx)(`form`,{className:gU.form,onKeyDown:t=>{t.key===`Enter`&&(t.metaKey||t.ctrlKey)&&(t.preventDefault(),e())},onSubmit:t=>{t.preventDefault(),e()},children:t}),yU=({why:e,id:t})=>(0,q.jsx)(`output`,{className:hU.reason,id:t,children:(0,q.jsx)(r_,{text:e??``})}),bU=({text:e})=>e===null?null:(0,q.jsx)(`p`,{className:gU.alert,role:`alert`,children:(0,q.jsx)(r_,{text:e})}),xU=[`friction`,`bug`,`context-gap`,`skill`,`workflow`,`idea`],SU=[`low`,`medium`,`high`],CU=[{value:``,label:`No rating`},{value:`good`,label:`good`},{value:`bad`,label:`bad`}],wU={text:``,rating:``,kind:`friction`,severity:null},TU=({rating:e,severity:t})=>t??(e===`bad`?`high`:`medium`),EU=e=>e.severity===null&&e.rating===`bad`,DU=e=>e.text.trim()===``?`Write the note first.`:null,OU=(e,t)=>({text:t.text,...e===void 0?{}:{node:e},kind:t.kind,severity:TU(t),...t.rating===``?{}:{rating:t.rating}}),kU=(e,t,n)=>{let r=TU({...n,severity:null}),i=TU(n);return[`ork feedback note`,e,...t===void 0?[]:[jk(t)],`-m`,n.text.trim()===``?`<text>`:jk(n.text),...n.kind===`friction`?[]:[`--kind ${n.kind}`],...i===r?[]:[`--severity ${i}`],...n.rating===``?[]:[`--rating ${n.rating}`]].join(` `)},AU=(e,t,n)=>({title:t===void 0?`Noted on run \`${e}\``:`Noted on \`${t}\``,description:`It joined item \`${n.slice(0,12)}\`.`}),jU=e=>e.map(e=>({value:e,label:e})),MU=({runId:e,node:t,onSend:n,onDone:r})=>{let[i,a]=(0,U.useState)(wU),[o,s]=(0,U.useState)(!1),[c,l]=(0,U.useState)(null),u=(0,U.useId)(),d=(0,U.useId)(),f=DU(i),p=e=>{a(t=>({...t,...e}))},m=async()=>{if(f!==null||o)return;s(!0),l(null);let e=await n(OU(t,i));s(!1),l(e),e===null&&r()};return(0,q.jsxs)(vU,{onSend:()=>{m()},children:[(0,q.jsx)(pk,{description:`Its first line is the title.`,label:`Note`,multiline:!0,onChange:e=>{p({text:e})},required:!0,value:i.text}),(0,q.jsx)(uk,{label:`Rating`,onChange:e=>{p({rating:e})},options:CU,value:i.rating}),(0,q.jsx)(uk,{label:`Kind`,onChange:e=>{p({kind:e})},options:jU(xU),value:i.kind}),(0,q.jsx)(uk,{label:`Severity`,onChange:e=>{p({severity:e})},describedBy:d,options:jU(SU),value:TU(i)}),(0,q.jsx)(yU,{id:d,why:EU(i)?`Severity: high, from the bad rating.`:null}),(0,q.jsx)(cC,{command:kU(e,t,i)}),(0,q.jsx)(yU,{id:u,why:f}),(0,q.jsx)(bU,{text:c}),(0,q.jsxs)(PC,{children:[(0,q.jsx)(Y,{disabled:o,onClick:r,type:`button`,variant:`ghost`,children:`Cancel`}),(0,q.jsx)(Y,{"aria-describedby":u,"aria-keyshortcuts":_U,disabled:f!==null||o,focusableWhenDisabled:!0,type:`submit`,variant:`primary`,children:o?`Adding…`:`Add note`})]})]})},NU={enabled:!0},PU=({runId:e,node:t,check:n=NU,onSend:r})=>{let[i,a]=(0,U.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,q.jsxs)(q.Fragment,{children:[t===void 0?(0,q.jsx)(xb,{cli:c,label:s,onClick:l,children:(0,q.jsx)(Py,{})}):(0,q.jsxs)(Y,{"aria-label":s,cli:c,disabled:!n.enabled,focusableWhenDisabled:!0,onClick:l,tip:n.enabled?void 0:s,children:[(0,q.jsx)(Py,{}),`Note…`]}),(0,q.jsx)(NC,{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,q.jsx)(MU,{node:t,onDone:()=>{a(!1)},onSend:r,runId:e})})]})},FU={enabled:!0},IU=(e,t,n)=>n.enabled?`${e} ${t}`:`${e} ${t}: ${n.why}`,LU=`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.`,RU=({runId:e,action:t})=>{let n=ob(),[r,i]=(0,U.useState)(!1),a=(0,U.useRef)(!1),o=`ork resume ${e} --detach`;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(Y,{"aria-label":IU(`Resume`,`run`,t),cli:o,disabled:!t.enabled,focusableWhenDisabled:!0,onClick:()=>{i(!0)},tip:t.enabled?void 0:t.why,variant:`ghost`,children:[(0,q.jsx)($y,{}),`Resume…`]}),(0,q.jsx)(FC,{cli:o,confirm:`Resume run`,description:LU,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`})]})},zU=({runId:e,node:t,actions:n,note:r=FU})=>{let i=ob(),[a,o]=(0,U.useState)(!1),s=t??`run`,c=t===void 0?``:` --node ${t}`,l=n=>{i.control(n,e,t).then(e=>(e.ok||tb.add({title:`Could not ${n} ${s}`,description:e.error}),e))},u=(0,q.jsx)(PU,{check:r,node:t,onSend:async n=>{let r=await i.client.call(`note`,{params:{id:e},body:n});return r.ok?(tb.add(AU(e,t,r.data.item)),null):`Could not add the note: ${r.error}`},runId:e});return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{"aria-label":t===void 0?`Run controls`:`Controls for ${t}`,className:UH.controls,role:`group`,children:[(0,q.jsx)(xb,{cli:`ork pause ${e}${c}`,disabled:!n.pause.enabled,focusableWhenDisabled:!0,label:IU(`Pause`,s,n.pause),onClick:()=>{l(`pause`)},children:(0,q.jsx)(ay,{})}),(0,q.jsx)(xb,{cli:`ork continue ${e}${c}`,disabled:!n.proceed.enabled,focusableWhenDisabled:!0,label:IU(`Continue`,s,n.proceed),onClick:()=>{l(`continue`)},children:(0,q.jsx)(iy,{})}),(0,q.jsx)(xb,{cli:`ork stop ${e}${c}`,disabled:!n.stop.enabled,focusableWhenDisabled:!0,label:IU(`Stop`,s,n.stop),onClick:()=>{o(!0)},children:(0,q.jsx)(oy,{})}),(0,q.jsx)(FC,{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,q.jsx)(RU,{action:n.resume,runId:e}),t===void 0?u:null]}),t===void 0?null:u]})},BU={s:1e3,m:6e4,h:36e5},VU=e=>{let t=/^(\d+)([smh])$/u.exec(e);return Number(t?.[1]??0)*(BU[t?.[2]??`s`]??1e3)},HU=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`},UU=e=>e===`running`||e===`paused`,WU=(e,t)=>{let n=VU(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 ${HU(n===0?0:n-r%n)}`,said:e.said}},GU=5e3,KU=({watching:e})=>{let[t,n]=(0,U.useState)(Date.now);(0,U.useEffect)(()=>{let e=setInterval(()=>{n(Date.now())},GU);return()=>{clearInterval(e)}},[]);let r=WU(e,t);return(0,q.jsxs)(`dl`,{className:UH.watching,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Waiting until`}),(0,q.jsx)(`dd`,{children:(0,q.jsx)(`code`,{children:r.until})})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Looks`}),(0,q.jsxs)(`dd`,{children:[r.looks,`, `,r.every]})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Next look`}),(0,q.jsx)(`dd`,{children:r.next})]}),r.said===void 0?null:(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Last said`}),(0,q.jsx)(`dd`,{children:(0,q.jsx)(`code`,{children:r.said})})]})]})},qU=({run:e,node:t,progress:n,sectionRef:r,onLeave:i,onOpenRun:a})=>{let{calledRun:o}=t,s=KH(t);return(0,q.jsxs)(`section`,{"aria-label":`Node ${t.id}`,className:UH.node,onKeyDown:e=>{let t=document.querySelector(`[data-modal]`)!==null;e.key===`Escape`&&!t&&i()},ref:r,children:[(0,q.jsx)(`h3`,{className:UH.sideTitle,children:t.id}),(0,q.jsxs)(`dl`,{className:UH.nodeFacts,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Type`}),(0,q.jsx)(`dd`,{children:$j(t.type)})]}),n===void 0?null:(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Items`}),(0,q.jsx)(`dd`,{children:n})]}),s===void 0||t.template===void 0?null:(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Item`}),(0,q.jsxs)(`dd`,{children:[`of `,(0,q.jsx)(`code`,{children:t.template}),`, index `,s]})]}),s===void 0?null:(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Logs`}),(0,q.jsx)(`dd`,{children:(0,q.jsx)(`code`,{children:`ork logs ${e.id} --node ${t.id}`})})]}),t.model===void 0?null:(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Model`}),(0,q.jsx)(`dd`,{children:t.model})]}),t.inputTokens+t.outputTokens===0?null:(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Tokens`}),(0,q.jsxs)(`dd`,{children:[nM(t.inputTokens),` in ·`,` `,nM(t.outputTokens),` out`]})]})]}),t.end===void 0||t.end.actor===null?null:(0,q.jsx)(`div`,{className:UH.end,children:(0,q.jsx)(MH,{end:t.end,node:t.id,runId:e.id},t.id)}),(0,q.jsx)(zU,{actions:pU(e,t),node:t.id,note:mU(t),runId:e.id}),t.watching===void 0||!UU(e.status)?null:(0,q.jsx)(KU,{watching:t.watching}),o===void 0?null:(0,q.jsxs)(Y,{onClick:()=>{a(o)},variant:`ghost`,children:[`Open run `,o]})]})},JU=new Set([`succeeded`,`failed`,`skipped`,`interrupted`]),YU=e=>e.length<2?e.join(``):`${e.slice(0,-1).join(`, `)} and ${e.at(-1)??``}`,XU=(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||!JU.has(i))}).map(({from:e})=>e);return r.length===0?``:`After ${YU([...new Set(r)])}`},ZU=e=>`${e.charAt(0).toUpperCase()}${e.slice(1)}`,QU=(e,t,n,r,i,a)=>{if(a!==void 0){let n=t===`failed`?e.now??``:``;return n===``?a:`${a} · ${n}`}if(t===`queued`)return XU(e.id,n,r);if(e.watching!==void 0&&!JU.has(t)){let{looks:t,next:n}=WU(e.watching,i);return ZU(`${t} ${t===`1`?`look`:`looks`}, next ${n}`)}return e.now??``},$U=({startedAt:e,finishedAt:t},n,r)=>{if(e===void 0)return`–`;let i=t??n;return iM((i===void 0?r:Date.parse(i))-Date.parse(e))},eW=e=>{let t=[...e];return`${String(t.filter(e=>JU.has(e)).length)} / ${String(t.length)}`},tW=({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(` · `)},nW={status:`queued`},rW=({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,U.useState)(new Set),[p,m]=(0,U.useState)(r),[h,g]=(0,U.useState)(r);r!==h&&(g(r),r!==null&&m(r));let _=(0,U.useMemo)(()=>JH(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,qH(r)[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,q.jsxs)(`div`,{className:UH.table,children:[(0,q.jsxs)(`div`,{"aria-hidden":`true`,className:UH.tableHead,children:[(0,q.jsx)(`span`,{children:`Node`}),(0,q.jsx)(`span`,{className:UH.treeType,children:`Type`}),(0,q.jsx)(`span`,{children:`Status`}),(0,q.jsx)(`span`,{children:`Now`}),(0,q.jsx)(`span`,{className:UH.treeTime,children:`Time`}),(0,q.jsx)(`span`,{className:UH.treeCost,children:`Cost`})]}),(0,q.jsx)(`div`,{"aria-label":`Ownership tree`,className:UH.tree,role:`tree`,children:_.map(({node:e,depth:f},p)=>{let h=t.get(e.id)??nW,g=e.children.length>0,_=g&&!d.has(e.id),b=QU(e,h.status,i,S,o,h.progress);return(0,U.createElement)(`div`,{...l_(KH(e)===void 0?void 0:h.cli,n.get(e.id)),"aria-expanded":g?_:void 0,"aria-label":[aM(e.id,e.type,{...h,progress:void 0}),...b===``?[]:[b]].join(`, `),"aria-level":f,"aria-selected":e.id===r,className:UH.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,q.jsxs)(`span`,{className:UH.treeNode,style:{paddingInlineStart:`${String((f-1)*.75)}rem`},children:[C?(0,q.jsxs)(`span`,{"aria-hidden":`true`,className:UH.treeToggle,onClick:g?t=>{t.stopPropagation(),y(e.id,!_)}:void 0,children:[g&&_?(0,q.jsx)(ly,{}):null,g&&!_?(0,q.jsx)(uy,{}):null]}):null,(0,q.jsx)(`span`,{className:UH.treeId,children:e.id})]}),(0,q.jsx)(`span`,{className:UH.treeType,children:e.type}),(0,q.jsx)(`span`,{className:UH.treeStatus,children:(0,q.jsx)(qj,{status:h.status})}),(0,q.jsx)(`span`,{className:UH.treeNow,children:b}),(0,q.jsx)(`span`,{className:UH.treeTime,children:$U(e,s,o)}),(0,q.jsx)(`span`,{className:UH.treeCost,children:h.costUsd===void 0?`–`:tM(h.costUsd)}))})})]})},iW={ends:`_ends_mstds_6`,list:`_list_mstds_21`,row:`_row_mstds_30`,id:`_id_mstds_62`},aW=3,oW=new Set([`failed`,`crashed`,`budget_exhausted`,`quota_exhausted`,`timed_out`,`interrupted`]),sW=({run:e,roots:t,onSelect:n})=>{let[r,i]=(0,U.useState)(!1),a=JH(t).flatMap(({node:e})=>e.end===void 0||e.end.actor===null?[]:[{id:e.id,end:e.end,at:e.finishedAt??``}]).toSorted((e,t)=>e.at.localeCompare(t.at));if(!oW.has(e.live)||a.length===0)return null;let o=a.length-aW;return(0,q.jsxs)(`section`,{"aria-label":`Why the run stopped`,className:iW.ends,children:[(0,q.jsx)(`ul`,{className:iW.list,children:(r?a:a.slice(0,aW)).map(({id:e,end:t})=>(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{"aria-label":`Select ${e}: ${t.label}${t.transient?`, may pass`:``}, ${t.message}`,className:iW.row,onClick:()=>{n(e)},type:`button`,children:[(0,q.jsx)(SH,{end:t}),(0,q.jsx)(`span`,{className:iW.id,children:e}),(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:t.message})})]})},e))}),o<=0?null:(0,q.jsx)(Y,{"aria-expanded":r,onClick:()=>{i(e=>!e)},variant:`ghost`,children:r?`Show fewer`:`Show ${String(o)} more`})]})},cW=new Map;function lW(e,t){let n=JSON.stringify({locale:yx(e),options:t}),r=cW.get(n);if(r)return r;let i=new Intl.NumberFormat(e,t);return cW.set(n,i),i}function uW(e,t,n){return e==null?``:lW(t,n).format(e)}var dW=U.createContext(void 0);function fW(){let e=U.useContext(dW);if(e===void 0)throw Error(gc(38));return e}function pW(e,t,n){return(e-t)*100/(n-t)}var mW=U.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]=U.useState(),h=pW(s,o,a),g=E_(Number.isNaN(h)?0:h,0,100),_=E_(Number.isNaN(s)?o:s,o,a),v=n?uW(_,i,n):uW(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,q.jsxs)(U.Fragment,{children:[u,(0,q.jsx)(`span`,{role:`presentation`,style:Yu,children:`x`})]})},x=U.useMemo(()=>({formattedValue:v,percentageValue:g,setLabelId:m,value:s}),[v,g,m,s]),S=qf(`div`,e,{ref:t,props:[b,f]});return(0,q.jsx)(dW.Provider,{value:x,children:S})}),hW=U.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,{setLabelId:s}=fW();return qf(`span`,e,{ref:t,props:[{id:Mx(a,s),role:`presentation`},o]})}),gW={meter:`_meter_1pby1_6`,label:`_label_1pby1_15`,value:`_value_1pby1_31`,track:`_track_1pby1_39`,block:`_block_1pby1_47`},_W=.8,vW=20,yW=(e,t,n=vW)=>e>=t?n:e<=0?0:Math.min(Math.max(Math.round(e/t*n),1),n-1),bW=(e,t)=>e>=t?`full`:e>=t*_W?`high`:`normal`,xW=({value:e,max:t,blocks:n=vW})=>{let r=yW(e,t,n);return(0,q.jsx)(`span`,{"aria-hidden":`true`,className:gW.track,"data-level":bW(e,t),children:Array.from({length:n},(e,t)=>(0,q.jsx)(`span`,{className:gW.block,"data-on":t<r?``:void 0},t))})},SW=({label:e,value:t,max:n,text:r})=>(0,q.jsxs)(mW,{"aria-valuetext":r,className:gW.meter,"data-level":bW(t,n),max:n,value:Math.min(t,n),children:[(0,q.jsx)(hW,{className:gW.label,children:e}),(0,q.jsx)(`span`,{className:gW.value,children:r}),(0,q.jsx)(xW,{max:n,value:t})]}),CW=16,wW=({run:e,facts:t,budgetUsd:n,now:r})=>{let i=tW(e);return(0,q.jsxs)(`dl`,{className:UH.stats,children:[(0,q.jsxs)(`div`,{className:UH.stat,children:[(0,q.jsxs)(`dt`,{className:UH.statName,children:[`Spent`,n===void 0?``:` · cap ${tM(n,[])}`]}),(0,q.jsxs)(`dd`,{className:UH.statValue,children:[tM(e.costUsd),n===void 0?null:(0,q.jsx)(xW,{blocks:CW,max:n,value:e.costUsd})]})]}),(0,q.jsxs)(`div`,{className:UH.stat,children:[(0,q.jsx)(`dt`,{className:UH.statName,children:`Nodes`}),(0,q.jsxs)(`dd`,{className:UH.statValue,children:[eW([...t.values()].map(({status:e})=>e)),i===null?null:` · ${i}`]})]}),(0,q.jsxs)(`div`,{className:UH.stat,children:[(0,q.jsx)(`dt`,{className:UH.statName,children:`Elapsed`}),(0,q.jsx)(`dd`,{className:UH.statValue,children:iM((e.finishedAt===void 0?r:Date.parse(e.finishedAt))-Date.parse(e.startedAt))})]})]})},TW=({run:e,waiting:t})=>{let n=ob(),r=(0,U.use)(fL),i=vb(n.decisions)?.filter(({runId:t})=>t===e.id).length;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(qj,{pill:!0,status:oU(e,t)}),i===void 0||i===0?null:(0,q.jsxs)(Y,{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,q.jsx)(My,{}),i===1?`1 decision`:`${i} decisions`,` waiting`]})]})},EW=({run:e,waiting:t,facts:n,budgetUsd:r,now:i})=>{let a=ob(),o=(0,U.useRef)(null),{parent:s}=e;return(0,U.useEffect)(()=>{a.takeArrival(e.id)&&o.current?.focus()},[a,e.id]),(0,q.jsxs)(`header`,{className:UH.header,children:[(0,q.jsxs)(`div`,{className:UH.stat,children:[(0,q.jsx)(`span`,{className:UH.statName,children:`Run`}),(0,q.jsxs)(`span`,{className:UH.statValue,children:[(0,q.jsx)(`h2`,{className:UH.title,"data-run-heading":e.id,ref:o,tabIndex:-1,children:e.workflow}),(0,q.jsx)(`code`,{className:UH.runId,children:e.id})]})]}),(0,q.jsx)(wW,{budgetUsd:r,facts:n,now:i,run:e}),(0,q.jsx)(TW,{run:e,waiting:t}),s===void 0?null:(0,q.jsxs)(Y,{onClick:()=>{a.arriveAt(s)},variant:`ghost`,children:[`Called by `,s]}),(0,q.jsx)(zU,{actions:fU(e),runId:e.id})]})},DW=({links:e,runId:t,onOpen:n})=>e.length===0?null:(0,q.jsxs)(`section`,{"aria-label":`Links to other runs`,className:UH.links,children:[(0,q.jsx)(`h3`,{className:UH.sideTitle,children:`Links`}),(0,q.jsx)(`ul`,{className:UH.linkList,children:e.map(e=>{let[r,i]=e.a.run===t?[e.a,e.b]:[e.b,e.a];return(0,q.jsxs)(`li`,{className:UH.link,children:[(0,q.jsxs)(`span`,{className:UH.linkEnds,children:[r.node,` ↔ `,i.run,`/`,i.node]}),(0,q.jsxs)(`span`,{className:UH.linkCount,children:[e.messages,`/`,e.maxMessages,e.endedAt===void 0?``:` · ended`]}),(0,q.jsx)(Y,{onClick:()=>{n(i.run)},variant:`ghost`,children:`Open`})]},e.id)})})]}),OW=1e3,kW=e=>{let[t,n]=(0,U.useState)(Date.now);return(0,U.useEffect)(()=>{let t=e?setInterval(()=>{n(Date.now())},OW):void 0;return()=>{clearInterval(t)}},[e]),t},AW=1e3,jW=(e,t)=>{let n=(0,U.use)(fL),r=(0,U.useRef)(null),i=(0,U.useRef)([]),a=(0,U.useRef)(void 0),{id:o,live:s}=e;(0,U.useEffect)(()=>{if(t.size===0)return;let e=rU(s,t),c=r.current===null?[]:aU(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(` `))},AW))},[t,o,s,n]),(0,U.useEffect)(()=>()=>{clearTimeout(a.current)},[])},MW=e=>{let t=ob(),n=e.id,r=(0,U.useMemo)(()=>t.watchRun(n),[t,n]);(0,U.useEffect)(()=>{let e=t.retainRun(n),i=r.start();return()=>{i(),e()}},[t,r,n]);let{graph:i,tree:a,links:o,error:s}=vb(r.state),c=vb(t.decisions),{node:l}=vb(t.selection),u=(0,U.useRef)(null),d=(0,U.useRef)(null),f=(0,U.useMemo)(()=>a??[],[a]),p=e.live!==`running`&&e.live!==`paused`,m=(0,U.useMemo)(()=>QH(c,n),[c,n]),h=(0,U.useMemo)(()=>nU(f,m,n,p),[f,m,n,p]),g=JH(f).map(({node:e})=>e.id).join(`
104
- `),_=(0,U.useMemo)(()=>i===null?null:qN(sU(i,f)),[i,g]),v=(0,U.useMemo)(()=>rj(_?.edges??[]),[_]),y=JH(f).find(({node:e})=>e.id===l)?.node,b=y!==void 0&&KH(y)!==void 0?y.template:void 0;jW(e,h);let x=(0,U.useCallback)(e=>{let{activeElement:n}=document;d.current=n instanceof HTMLElement?n:null,t.selectNode(e),requestAnimationFrame(()=>{u.current?.querySelector(`button`)?.focus()})},[t]),S=(0,U.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,holding:b,chosen:y,nodeControls:u,openControls:x,closeControls:S}},NW=({run:e})=>{let{state:t,graph:n,layout:r,facts:i,waiting:a,connections:o,roots:s,links:c,error:l,selected:u,holding:d,chosen:f,nodeControls:p,openControls:m,closeControls:h}=MW(e),[g,_]=(0,U.useState)(null),v=kW(e.live===`running`||e.live===`paused`);return(0,q.jsxs)(`div`,{className:UH.monitor,children:[(0,q.jsx)(EW,{budgetUsd:n?.budgetUsd,facts:i,now:v,run:e,waiting:a}),l===null?null:(0,q.jsx)(WH,{error:l}),(0,q.jsx)(sW,{onSelect:t.selectNode,roots:s,run:e}),(0,q.jsx)(GH,{facts:i,holding:d,hovered:g,label:`Graph of run ${e.id}, ${e.workflow}`,layout:r,onHover:_,onNodeMenu:m,onSelect:t.selectNode,runId:e.id,selected:u??void 0}),(0,q.jsx)(rW,{connections:o,edges:n?.edges??[],facts:i,hovered:g,now:v,onHover:_,onNodeMenu:m,onSelect:t.selectNode,roots:s,runFinishedAt:e.finishedAt,selected:u}),f===void 0?null:(0,q.jsx)(qU,{node:f,progress:i.get(f.id)?.progress,onLeave:h,onOpenRun:t.arriveAt,run:e,sectionRef:p}),(0,q.jsx)(DW,{links:c,onOpen:t.arriveAt,runId:e.id})]})},PW=()=>{let e=ob(),{run:t}=vb(e.selection),n=vb(e.runs)?.find(({id:e})=>e===t);return n===void 0?(0,q.jsx)(qD,{cli:`ork tree <run>`,title:`No run chosen.`,children:`Choose one in the Runs panel, or in a terminal:`}):(0,q.jsx)(NW,{run:n},n.id)},FW=()=>`Notification`in globalThis,IW=async()=>FW()?await Notification.requestPermission()===`granted`?`granted`:`denied`:`unsupported`,LW=(e,t,n)=>{if(!FW()||Notification.permission!==`granted`||document.visibilityState===`visible`)return;let r=new Notification(`Ork`,{body:e,tag:t});r.addEventListener(`click`,()=>{window.focus(),n(),r.close()})},RW=(e,t)=>e.live===`running`&&t?`waiting`:e.live,zW=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`})},BW=({paused:e,live:t})=>{let n=e.nodes.length;return t!==`running`||n===0?null:n===1?`1 node paused`:`${String(n)} nodes paused`},VW=(0,U.memo)(({run:e,selected:t,tabStop:n,waiting:r,onSelect:i})=>{let a=BW(e);return(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{"aria-current":t?`true`:void 0,className:mk.row,"data-run-row":e.id,onClick:()=>{i(e.id)},tabIndex:n?0:-1,type:`button`,children:[(0,q.jsxs)(`span`,{className:mk.rowTop,children:[(0,q.jsx)(`span`,{className:mk.workflow,children:e.workflow}),(0,q.jsx)(qj,{status:RW(e,r)})]}),(0,q.jsxs)(`span`,{className:mk.rowMeta,children:[(0,q.jsx)(`span`,{children:e.id}),(0,q.jsx)(`time`,{dateTime:e.startedAt,children:zW(e.startedAt)}),(0,q.jsx)(`span`,{children:tM(e.costUsd)}),a===null?null:(0,q.jsx)(`span`,{children:a})]})]})})});VW.displayName=`RunRow`;var HW=({onClick:e})=>(0,q.jsxs)(Y,{cli:`ork run <workflow>`,"data-run-workflow":``,onClick:e,variant:`primary`,children:[(0,q.jsx)(iy,{}),`Run workflow`]}),UW=({filtered:e})=>e?(0,q.jsx)(qD,{cli:`ork ps`,title:`No runs in this project.`,children:`Among the newest 50. For older ones:`}):(0,q.jsx)(qD,{cli:`ork run <workflow>`,title:`No runs yet.`,children:`Start one with Run workflow, or in a terminal:`}),WW={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`},GW=({item:e})=>{let t=ob(),n=(0,U.use)(fL);return(0,q.jsxs)(`li`,{className:WW.item,"data-notification":e.id,"data-unread":e.unread?``:void 0,children:[(0,q.jsx)(`p`,{className:WW.title,children:e.title}),(0,q.jsxs)(`p`,{className:WW.meta,children:[(0,q.jsx)(qj,{status:e.status}),(0,q.jsx)(`span`,{children:zW(e.at)}),e.unread?(0,q.jsx)(`span`,{className:WW.unread,children:`unread`}):null]}),(0,q.jsxs)(`p`,{className:WW.actions,children:[(0,q.jsx)(Y,{"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,q.jsx)(Y,{"aria-label":`Mark read: ${e.title}`,disabled:!e.unread,focusableWhenDisabled:!0,onClick:()=>{t.notifications.markRead(e.id)},variant:`ghost`,children:`Mark read`})]})]})},KW={denied:`The browser refused. Allow notifications for this page in its settings.`,unsupported:`This browser has no desktop notifications.`},qW=()=>{let{notifications:e,preferences:t}=ob(),{items:n,unread:r}=vb(e.view),{desktopNotifications:i}=vb(t.value),[a,o]=(0,U.useState)(null),{panel:s,onFocus:c}=mH(n.map(({id:e})=>e).join(`
105
- `),`[data-notification]`),l=async e=>{if(o(null),!e){t.update({desktopNotifications:!1});return}let n=await IW();n===`granted`?t.update({desktopNotifications:!0}):o(KW[n])};return(0,q.jsxs)(`div`,{"aria-label":`Notifications`,className:WW.panel,onFocus:c,ref:s,role:`group`,tabIndex:-1,children:[(0,q.jsxs)(`div`,{className:WW.tools,children:[(0,q.jsx)(vO,{checked:i,label:`Desktop notifications`,onChange:e=>{l(e)}}),(0,q.jsx)(Y,{disabled:r===0,focusableWhenDisabled:!0,onClick:e.markAllRead,variant:`ghost`,children:`Mark all read`})]}),(0,q.jsxs)(`div`,{className:WW.main,children:[a===null?null:(0,q.jsx)(`p`,{className:WW.refused,role:`alert`,children:a}),n.length===0?(0,q.jsx)(qD,{title:`Nothing yet.`,children:`Decisions, and runs that end, crash or pause, land here.`}):(0,q.jsx)(`ul`,{className:WW.list,children:n.map(e=>(0,q.jsx)(GW,{item:e},e.id))})]})]})},JW=e=>e.split(`/`).at(-1)??e,YW=e=>e.split(`/`).slice(-2).join(`/`),XW=(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,JW(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)?YW(e):t})).toSorted((e,t)=>e.label.localeCompare(t.label))]},ZW=3e4,QW={live:`Live`,new:`Off: new, not accepted yet`,changed:`Off: changed since it was accepted`,invalid:`Off: it has an error`},$W={new:`ork watch --accept`,changed:`ork watch --accept`,invalid:`ork validate`},eG=e=>new Date(e).toLocaleTimeString(void 0,{timeStyle:`short`}),tG=e=>[QW[e.standing],...e.lookedAt===void 0?[]:[`Last looked ${eG(e.lookedAt)}`],...e.error===void 0?[]:[`Last look failed: ${e.error}`],...e.held===void 0?[]:[`Waiting: ${e.held}`]],nG=()=>{let{triggers:e}=ob(),t=vb(e.state);(0,U.useEffect)(()=>{e.load();let t=setInterval(()=>{e.load()},ZW);return()=>{clearInterval(t)}},[e]);let n=nH(t)?.data;return n===void 0||n.triggers.length===0?null:(0,q.jsxs)(`section`,{"aria-label":`Triggers`,className:mk.triggers,children:[(0,q.jsx)(`h3`,{className:mk.triggersTitle,children:`Triggers`}),n.pid===void 0?(0,q.jsxs)(`p`,{className:mk.note,children:[(0,q.jsx)(`code`,{children:`ork watch`}),` isn't running, so nothing is looking.`]}):null,(0,q.jsx)(`ul`,{className:mk.triggerList,children:n.triggers.map(e=>(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:mk.triggerName,children:e.trigger}),` starts `,(0,q.jsx)(`code`,{children:e.run}),`, every ${e.every}`,tG(e).map(e=>(0,q.jsx)(`span`,{className:mk.triggerLine,children:(0,q.jsx)(r_,{text:e})},e)),$W[e.standing]===void 0?null:(0,q.jsx)(`span`,{className:mk.triggerCommand,children:(0,q.jsx)(cC,{command:$W[e.standing]??``})})]},`${e.project}/${e.trigger}`))})]})},rG=e=>_b(e.decisions,e=>new Set((e??[]).map(({runId:e})=>e))),iG=e=>{let t=vb(e.projects.state);return(0,U.useEffect)(()=>{e.projects.load()},[e]),t.status===`ready`?t.data:[]},aG=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())},oG=()=>{let e=ob(),t=vb(e.runs),n=vb(e.runFilter),r=_b(e.selection,({run:e})=>e),i=rG(e),a=iG(e),o=(0,U.useMemo)(()=>t??[],[t]),s=(0,U.useMemo)(()=>XW(a,o),[a,o]),c=(0,U.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,q.jsxs)(`div`,{className:mk.panel,children:[(0,q.jsxs)(`div`,{className:mk.tools,children:[(0,q.jsx)(uk,{label:`Project`,onChange:t=>{e.runFilter.setValue(t)},options:s,value:n}),(0,q.jsx)(HW,{onClick:()=>{e.runDialog.setValue(!0)}})]}),(0,q.jsx)(`div`,{className:mk.main,children:t===null?(0,q.jsx)(`p`,{className:mk.note,children:`Reading runs…`}):c.length===0?(0,q.jsx)(UW,{filtered:n!==`all`}):(0,q.jsx)(`ul`,{"aria-label":`Runs`,className:mk.list,onKeyDown:aG,children:c.map(t=>(0,q.jsx)(VW,{onSelect:e.selectRun,run:t,selected:t.id===r,tabStop:t.id===l,waiting:i.has(t.id)},t.id))})}),(0,q.jsx)(nG,{})]})},sG=e=>e.toLocaleString(`en`),cG=e=>`≈${sG(e)}`,lG=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}.`},uG=e=>e.reduce((e,t)=>e+(t.tokens??0),0),dG=e=>{let t=e.filter(e=>e.state===`live`).length,n=e.length-t;return n===0?`${sG(t)} live`:`${sG(t)} live, ${sG(n)} off`},fG=(e,t,n=0)=>{let r=`${t(e.length)} · ${cG(uG(e))}`;return n===0?r:`${r}, ${sG(n)} off`},pG=e=>`${sG(e)} ${e===1?`file`:`files`}`,mG=e=>`${sG(e)} live`,hG=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 ${sG(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:cG(uG(t)),empty:`No agent fills this node.`,pieces:t},{id:`instructions`,title:`Project instructions`,meta:cG(uG(n)),description:`Claude Code reads these itself; they aren't appended.`,empty:lG(e.instructions),pieces:n},{id:`skills`,title:`Skills`,meta:r.length===0?`none`:dG(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:fG(i,pG),empty:`No context files.`,pieces:i},{id:`practices`,title:`Practices`,meta:fG(a.filter(e=>e.state===`live`),mG,e.skippedPractices.length),empty:`No practices.`,pieces:a},{id:`appended`,title:`Appended system prompt`,meta:cG(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`}]}]},gG=(e,t)=>t?`Couldn't update: ${lG(e)} This is the answer from before.`:`Couldn't read the context: ${lG(e)}`,_G=e=>e===``?0:e.replace(/\n$/u,``).split(`
106
- `).length,vG=(e,t)=>{let n=t.endsWith(`/`)?t:`${t}/`;return e.startsWith(n)?e.slice(n.length):e},yG=(e,t)=>`ork context explain ${e} ${t}`,bG={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`},xG=({text:e})=>e.split(`≈`).map((e,t)=>t===0?e:(0,q.jsxs)(`span`,{children:[(0,q.jsx)(`span`,{"aria-hidden":`true`,children:`≈`}),(0,q.jsx)(`span`,{className:bG.visuallyHidden,children:`about `}),e]},t)),SG=({name:e,value:t})=>(0,q.jsxs)(`div`,{className:bG.fact,children:[(0,q.jsx)(`dt`,{className:bG.factName,children:e}),(0,q.jsx)(`dd`,{className:bG.factValue,children:(0,q.jsx)(xG,{text:t})})]}),CG=({node:e,type:t,from:n,appendedTokens:r,planned:i,reload:a,updating:o,cli:s,onReload:c,titleRef:l,children:u})=>(0,q.jsxs)(`header`,{className:bG.header,children:[(0,q.jsxs)(`dl`,{className:bG.facts,children:[(0,q.jsxs)(`div`,{className:bG.fact,children:[(0,q.jsx)(`dt`,{className:bG.factName,children:`Node`}),(0,q.jsx)(`dd`,{className:bG.factValue,children:(0,q.jsx)(`h2`,{className:bG.title,ref:l,tabIndex:-1,children:e})})]}),t===void 0?null:(0,q.jsx)(SG,{name:`Type`,value:t}),(0,q.jsx)(SG,{name:`From`,value:n}),r===void 0?null:(0,q.jsx)(SG,{name:`Appended`,value:`${cG(r)} tokens`})]}),(0,q.jsxs)(`div`,{className:bG.plannedLine,children:[i===null?null:(0,q.jsx)(`p`,{className:bG.planned,children:i}),o?(0,q.jsx)(`span`,{className:bG.updating,children:`Updating…`}):null,(0,q.jsx)(Y,{cli:s,onClick:c,variant:`ghost`,children:a})]}),u]}),wG=e=>`Changed after this run started: ${e.map(e=>`\`${e}\``).join(`, `)}. The run may have read ${e.length===1?`an older version`:`older versions`}.`,TG=({answer:e,error:t})=>{let n=e?.changedSinceStart??[],r=e?.planned===!0?e.explanation:null;return(0,q.jsxs)(q.Fragment,{children:[n.length===0?null:(0,q.jsxs)(`p`,{className:bG.notice,"data-note":`changed`,children:[(0,q.jsx)(`span`,{className:bG.noticeIcon,children:(0,q.jsx)(My,{})}),(0,q.jsx)(`span`,{className:bG.noticeWords,children:(0,q.jsx)(r_,{text:wG(n)})})]}),r?.template===void 0?null:(0,q.jsx)(`p`,{className:bG.notice,"data-note":`spawned`,children:(0,q.jsx)(`span`,{className:bG.noticeWords,children:(0,q.jsx)(r_,{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,q.jsxs)(`p`,{className:bG.notice,"data-note":`failed`,children:[(0,q.jsx)(`span`,{className:bG.noticeIcon,children:(0,q.jsx)(Fj,{})}),(0,q.jsx)(`span`,{className:bG.noticeWords,children:(0,q.jsx)(r_,{text:gG(t,e!==null)})})]})]})},EG=({why:e})=>(0,q.jsxs)(`div`,{className:bG.card,children:[(0,q.jsx)(`p`,{className:bG.cardTitle,children:`No context to show.`}),(0,q.jsx)(`p`,{className:bG.description,children:(0,q.jsx)(r_,{text:lG(e)})})]}),DG=({cli:e,draft:t,sized:n})=>(0,q.jsxs)(`footer`,{className:bG.foot,children:[t?(0,q.jsx)(`p`,{className:bG.description,children:`The CLI reads the saved file, not the draft.`}):null,(0,q.jsx)(cC,{command:e}),n?(0,q.jsx)(`p`,{className:bG.description,children:`Tokens are estimates, about four characters each.`}):null]}),OG=({target:e})=>e?.kind===`run`?(0,q.jsx)(qD,{title:`No node chosen in this run.`,children:`Choose one in the Monitor, Logs or Chats.`}):e?.kind===`builder`?(0,q.jsx)(qD,{title:`No node selected in the Builder.`,children:`Select a card to see what its session loads.`}):(0,q.jsx)(qD,{cli:`ork context explain <workflow> <node>`,title:`No node chosen.`,children:`Choose one in the Monitor or the Builder, or in a terminal:`}),kG=({words:e,more:t})=>{let n=`${e}${t?`, `:``}`;return n===``?null:(0,q.jsx)(`span`,{className:bG.visuallyHidden,children:n})},AG=({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,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:bG.mark,"data-state":e.state,children:e.state===void 0?null:e.state===`live`?(0,q.jsx)(cy,{}):(0,q.jsx)(Yy,{})}),(0,q.jsxs)(`span`,{className:bG.name,children:[e.name,(0,q.jsx)(kG,{more:n(0),words:``})]}),r?(0,q.jsxs)(`span`,{className:bG.details,children:[e.state===void 0?null:(0,q.jsxs)(`span`,{className:bG.state,children:[e.state,(0,q.jsx)(kG,{more:n(1),words:``})]}),e.layer===void 0?null:(0,q.jsxs)(`span`,{className:bG.layer,children:[e.layer,(0,q.jsx)(kG,{more:n(2),words:` layer`})]}),e.source===void 0?null:(0,q.jsxs)(`span`,{className:bG.source,children:[e.source,(0,q.jsx)(kG,{more:n(3),words:``})]})]}):null,e.tokens===void 0?null:(0,q.jsxs)(`span`,{className:bG.tokens,children:[(0,q.jsx)(xG,{text:cG(e.tokens)}),(0,q.jsx)(kG,{more:!1,words:` tokens`})]})]})},jG=({piece:e,id:t})=>{let n=e.text??``,r=_G(n);return(0,q.jsxs)(`div`,{className:bG.well,id:t,children:[(0,q.jsxs)(`div`,{className:bG.wellBar,children:[(0,q.jsx)(`span`,{className:bG.wellPlace,children:e.place}),(0,q.jsx)(`span`,{children:(0,q.jsx)(xG,{text:`${r.toLocaleString(`en`)} ${r===1?`line`:`lines`}${e.tokens===void 0?``:` · ${cG(e.tokens)} tokens`}`})}),(0,q.jsx)(`span`,{className:bG.wellCopy,children:(0,q.jsx)(oC,{label:`Copy the text of ${e.name}`,resultClass:bG.copied,text:n})})]}),n===``?(0,q.jsx)(`p`,{className:bG.emptyText,children:e.key===`appended`?`Nothing is appended.`:`This file is empty.`}):(0,q.jsx)(`pre`,{className:bG.text,children:n})]})},MG=({piece:e,open:t,onToggle:n})=>{let r=(0,U.useId)(),i=`${r}-why`,a=`${r}-text`,o=e.state??`live`,s=e.why===void 0?null:(0,q.jsx)(`p`,{className:bG.why,id:i,children:(0,q.jsx)(r_,{text:lG(e.why)})});return e.text===void 0?(0,q.jsxs)(`li`,{className:bG.item,children:[(0,q.jsxs)(`div`,{className:bG.row,"data-state":o,children:[(0,q.jsx)(`span`,{className:bG.toggle}),(0,q.jsx)(AG,{piece:e})]}),s]}):(0,q.jsxs)(`li`,{className:bG.item,children:[(0,q.jsxs)(`button`,{"aria-controls":t?a:void 0,"aria-describedby":e.why===void 0?void 0:i,"aria-expanded":t,className:bG.row,"data-piece":e.key,"data-state":o,onClick:()=>{n(e.key)},type:`button`,children:[(0,q.jsx)(`span`,{className:bG.toggle,children:t?(0,q.jsx)(ly,{}):(0,q.jsx)(uy,{})}),(0,q.jsx)(AG,{piece:e})]}),s,t?(0,q.jsx)(jG,{id:a,piece:e}):null]})},NG=({sections:e,opened:t,onToggle:n,busy:r})=>(0,q.jsx)(`div`,{"aria-busy":r,className:bG.stack,children:e.map(e=>(0,q.jsxs)(`section`,{className:bG.section,children:[(0,q.jsxs)(`div`,{className:bG.sectionHead,children:[(0,q.jsx)(`h3`,{className:bG.heading,children:e.title}),(0,q.jsx)(`span`,{className:bG.meta,children:(0,q.jsx)(xG,{text:e.meta})})]}),e.description===void 0?null:(0,q.jsx)(`p`,{className:bG.sectionNote,children:(0,q.jsx)(r_,{text:e.description})}),e.pieces.length===0?(0,q.jsx)(`p`,{className:bG.sectionNote,children:(0,q.jsx)(r_,{text:e.empty})}):(0,q.jsx)(`ul`,{className:bG.list,children:e.pieces.map(e=>(0,q.jsx)(MG,{onToggle:n,open:t.has(e.key),piece:e},e.key))})]},e.id))}),PG=e=>e.kind===`run`?`run/${e.run}/${e.node}`:`builder/${e.project}/${e.workflow}/${e.node}`,FG={answer:null,error:null,loading:!0},IG=e=>{let{client:t}=ob(),n=(0,U.use)(fL),[r,i]=(0,U.useState)(FG),a=(0,U.useRef)(!1);a.current=r.answer!==null;let[o,s]=(0,U.useState)(0),c=e.kind===`builder`?e.revision:0,l=PG(e);(0,U.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(gG(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,U.useCallback)(()=>{s(e=>e+1)},[]);return{...r,reload:u}},LG=e=>{let t=vb(ob().runs);if(e.kind===`builder`)return{from:`Builder · ${e.workflow}${e.draft?` · draft`:``}`,cli:yG(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:yG(n===void 0?`<workflow>`:vG(n.file,n.project),e.node),planned:`Planned from the project's files as they are now.`}},RG=({target:e,hadFocus:t})=>{let{answer:n,error:r,loading:i,reload:a}=IG(e),o=LG(e),[s,c]=(0,U.useState)(new Set),l=(0,U.useRef)(null),u=(0,U.useRef)(null),d=(0,U.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,U.useMemo)(()=>f===null?[]:hG(f),[f]),m=n===null?r===null?`loading`:`failed`:`shown`,h=(0,U.useRef)(null);return(0,U.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,q.jsxs)(`div`,{className:bG.panel,ref:l,children:[(0,q.jsx)(CG,{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,q.jsx)(TG,{answer:n,error:r})}),n?.planned===!1?(0,q.jsx)(EG,{why:n.why}):null,f===null?null:(0,q.jsx)(NG,{busy:i,onToggle:d,opened:s,sections:p}),n===null&&r===null?(0,q.jsx)(`p`,{"aria-busy":`true`,className:bG.card,children:(0,q.jsx)(`span`,{className:bG.description,children:`Planning ${e.node}…`})}):null,m===`loading`?null:(0,q.jsx)(DG,{cli:o.cli,draft:e.kind===`builder`&&e.draft,sized:f!==null})]})},zG=({target:e,hadFocus:t})=>{let n=(0,U.useRef)(null);return(0,U.useEffect)(()=>{let e=document.activeElement;(e===null||e===document.body)&&t.current&&n.current?.focus()},[t]),(0,q.jsx)(`div`,{ref:n,tabIndex:-1,children:(0,q.jsx)(OG,{target:e})})},BG=({target:e,hadFocus:t})=>{if(e===null||e.node===null)return(0,q.jsx)(zG,{hadFocus:t,target:e});let n={...e,node:e.node};return(0,q.jsx)(RG,{hadFocus:t,target:n},PG(n))},VG=()=>{let e=vb(ob().contextTarget),t=(0,U.useRef)(!1);return(0,q.jsx)(`div`,{className:bG.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,q.jsx)(BG,{hadFocus:t,target:e})})},HG=e=>e.slice(0,12),UG=[[`open`,`Not dismissed`],[`all`,`All`],[`new`,`New`],[`triaged`,`Triaged`],[`accepted`,`Accepted`],[`resolved`,`Resolved`],[`published`,`Published`],[`dismissed`,`Dismissed`]],WG=[{value:`all`,label:`All`},{value:`ork`,label:`ork`},{value:`workflow`,label:`workflow`},{value:`project`,label:`project`}],GG=(e,t)=>t===`all`?!0:t===`open`?e.status!==`dismissed`:e.status===t,KG=e=>UG.map(([t,n])=>({value:t,label:`${n} · ${String(e.filter(e=>GG(e,t)).length)}`})),qG=(e,t,n)=>e?n===null?`list`:t:`both`,JG=(e,{status:t,about:n})=>e.filter(e=>GG(e,t)&&(n===`all`||e.target===n)),YG=(e,t,n)=>e===1?`1 ${t}`:`${e.toLocaleString(`en`)} ${n}`,XG=e=>YG(e,`item`,`items`),ZG=e=>YG(e,`time`,`times`),QG=e=>YG(e,`run`,`runs`),$G={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`},eK=({status:e,about:t})=>{let n=$G[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.`}},tK=(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)]},nK=(e,t)=>e.find(e=>e.merged.includes(t)),rK={ok:!1,why:`reading what it allows`},iK=(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}},aK=e=>{let t=e.lessons,[n]=t;return t.every(e=>!e.ok)&&n!==void 0&&!n.ok?n.error:void 0},oK=(e,t)=>{let n=HG(e.id),r=e=>{if(t===null)return rK;let{actions:n,project:r}=t;return e===`lesson`?iK(n.lesson,aK(t)):e===`apply`?iK(n.apply,r.ok?void 0:r.error):iK(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`)}]},sK=(e,t)=>t.ok?e:`${e}: ${t.why}`,cK=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.`,lK=({item:e,id:t,root:n,acts:r,open:i,onOpenChange:a})=>{let[o,s]=(0,U.useState)(``),c=(0,U.useRef)(!1);return(0,q.jsx)(FC,{cli:`ork feedback apply ${t}${o===``?``:` --driver ${o}`}`,confirm:`Start run`,description:cK(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,q.jsx)(_k,{onChange:s,value:o})})},uK=(e,t)=>`about ${e.toLocaleString(`en`)} of ${t.toLocaleString(`en`)} tokens`,dK=(e,t,n)=>[`ork feedback accept ${HG(e.id)} --lesson`,...t===null||e.workflows.length<2?[]:[`--workflow ${jk(t)}`],...n===e.title||n.trim()===``?[]:[`-m ${jk(n)}`]].join(` `),fK=(e,t,n)=>e===null?`Choose a workflow.`:t.trim()===``?`Write the lesson first.`:n!==void 0&&!n.ok?n.error:null,pK=({place:e,cap:t})=>e.ok?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`p`,{className:gU.place,children:[(0,q.jsx)(`span`,{className:gU.caption,children:`Goes to `}),(0,q.jsx)(r_,{text:`\`${e.file}\` in \`${e.root}\``})]}),(0,q.jsx)(SW,{label:`Now`,max:t,text:e.exists?uK(e.tokens,t):`no lessons file yet; this starts it`,value:e.tokens})]}):(0,q.jsx)(`p`,{className:gU.note,children:(0,q.jsx)(r_,{text:e.error})}),mK=({open:e,onOpenChange:t,item:n,detail:r,onAdd:i})=>{let a=n.workflows.length>1,[o,s]=(0,U.useState)(a?null:n.workflows[0]??null),[c,l]=(0,U.useState)(n.title),[u,d]=(0,U.useState)(!1),[f,p]=(0,U.useState)(null),m=(0,U.useId)(),h=r.lessons.find(e=>e.workflow===o),g=fK(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,q.jsx)(NC,{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,q.jsxs)(vU,{onSend:()=>{_()},children:[a?(0,q.jsx)(uk,{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,q.jsx)(pk,{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,q.jsx)(pK,{cap:r.lessonCap,place:h}),(0,q.jsx)(cC,{command:dK(n,o,c)}),(0,q.jsx)(yU,{id:m,why:g}),(0,q.jsx)(bU,{text:f}),(0,q.jsxs)(PC,{children:[(0,q.jsx)(Y,{disabled:u,onClick:()=>{t(!1)},type:`button`,variant:`ghost`,children:`Cancel`}),(0,q.jsx)(Y,{"aria-describedby":m,"aria-keyshortcuts":_U,disabled:g!==null||u,focusableWhenDisabled:!0,type:`submit`,variant:`primary`,children:u?`Adding…`:`Add lesson`})]})]})})},hK={slot:`_slot_17gek_6`,alert:`_alert_17gek_17`},gK=({id:e,words:t,takeFocus:n,onTryAgain:r})=>{let i=(0,U.useRef)(null);return(0,U.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,q.jsxs)(`div`,{className:hK.slot,ref:i,children:[(0,q.jsx)(`p`,{className:hK.alert,id:e,role:`alert`,children:t===null?null:(0,q.jsx)(r_,{text:t})}),t===null||r===void 0?null:(0,q.jsx)(Y,{onClick:r,variant:`ghost`,children:`Try again`})]})},_K=({url:e})=>(0,q.jsxs)(`a`,{className:gU.link,href:e,rel:`noreferrer`,target:`_blank`,children:[e,(0,q.jsx)(Fy,{}),(0,q.jsx)(lk,{children:` (opens in a new tab)`})]}),vK=({preview:e})=>e.plan.kind===`create`?(0,q.jsx)(`p`,{className:gU.message,children:(0,q.jsx)(r_,{text:`A new thread in the Agent feedback category of \`${e.repo}\`.`})}):(0,q.jsxs)(`p`,{className:gU.message,children:[`A thread for this exists, so this goes on it as a +1 comment:`,` `,(0,q.jsx)(_K,{url:e.plan.url})]}),yK="Reading Ork's Discussions with your `gh`…",bK=`Nothing to show: the preview couldn't be read.`,xK=({id:e})=>(0,q.jsx)(`span`,{className:gU.note,id:e,children:`From the last read`}),SK=({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,q.jsxs)(q.Fragment,{children:[e===void 0||!a?null:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:gU.line,children:[(0,q.jsx)(`p`,{className:gU.caption,children:`Title`}),c?(0,q.jsx)(xK,{}):null]}),(0,q.jsx)(`p`,{className:gU.preview,"data-stale":r?``:void 0,children:e.post.title})]}),(0,q.jsxs)(`div`,{className:gU.wellHead,children:[(0,q.jsxs)(`div`,{className:gU.line,children:[(0,q.jsx)(`p`,{className:gU.caption,children:s}),c?(0,q.jsx)(xK,{id:i}):null]}),o===``?null:(0,q.jsx)(`span`,{className:gU.wellCopy,children:(0,q.jsx)(oC,{label:`Copy the ${s.toLowerCase()}`,text:o})})]}),(0,q.jsx)(`section`,{"aria-busy":t,"aria-describedby":c?i:void 0,"aria-label":`Text to post`,className:gU.preview,"data-scrolls":``,"data-stale":r?``:void 0,ref:n,tabIndex:0,children:o===``?(0,q.jsx)(r_,{text:t?yK:bK}):o}),(0,q.jsx)(`p`,{className:gU.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.`})]})},CK=({children:e})=>(0,q.jsxs)(`div`,{className:gU.dialogFoot,children:[(0,q.jsx)(`p`,{className:gU.note,children:(0,q.jsx)(r_,{text:"It posts with your own `gh` login."})}),(0,q.jsx)(`div`,{className:gU.actions,children:e})]}),wK=({id:e})=>(0,q.jsx)(`p`,{className:gU.note,id:e,children:(0,q.jsx)(r_,{text:"Your workflows' and projects' folders' names become `<name>`."})}),TK=({id:e,url:t,kind:n,onClose:r})=>{let i=(0,U.useRef)(null);return(0,U.useEffect)(()=>{i.current?.focus()},[]),(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`h3`,{className:gU.result,ref:i,tabIndex:-1,children:n===`created`?`Posted`:`Added a +1`}),(0,q.jsx)(`p`,{className:gU.message,children:(0,q.jsx)(_K,{url:t})}),(0,q.jsx)(`p`,{className:gU.message,children:`${e} is published.`}),(0,q.jsx)(`div`,{className:gU.actions,children:(0,q.jsx)(Y,{onClick:r,children:`Close`})})]})},EK=e=>e.step===`reading`||e.step===`readFailed`?e.shown:`preview`in e?e.preview:void 0,DK=e=>e.step===`reading`||e.step===`readFailed`,OK=e=>/[.!?]$/u.test(e.trim())?e.trim():`${e.trim()}.`,kK=(e,t,n)=>{let[r,i]=(0,U.useState)(!1),[a,o]=(0,U.useState)({step:`reading`}),s=(0,U.useRef)(0),c=(0,U.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=EK(e);return t===void 0?{step:`readFailed`,error:i.error}:{step:`readFailed`,error:i.error,shown:t}})},[e,t]);(0,U.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,EK(a))},tryAgain:()=>{a.step===`postFailed`?u(a.preview):l(r)},post:()=>{a.step===`preview`&&u(a.preview)}}},AK=`The text to post changed since you read it. Read it again before posting.`,jK=e=>e.step===`readFailed`?`Could not read Ork's Discussions: ${OK(e.error)} Nothing was sent.`:e.step===`postFailed`?`Could not post: ${OK(e.error)}`:null,MK=()=>{let e=document.activeElement;return e===null||e===document.body||e.getAttribute(`role`)===`dialog`},NK=e=>e.step===`reading`?`Reading the preview…`:null,PK=({client:e,item:t,id:n,region:r,onStep:i,onClose:a,onPosted:o})=>{let s=kK(e,t,o),{step:c,hideNames:l}=s,u=(0,U.useId)(),d=(0,U.useId)(),f=(0,U.useId)(),p=(0,U.useId)();if((0,U.useEffect)(()=>{i(c),c.step!==`posted`&&MK()&&r.current?.focus()},[c,i,r]),c.step===`posted`)return(0,q.jsx)(TK,{id:n,kind:c.kind,onClose:a,url:c.url});let m=EK(c),h=c.step===`posting`,g=m?.plan.kind===`comment`;return(0,q.jsxs)(q.Fragment,{children:[c.step===`preview`&&c.changed?(0,q.jsx)(`p`,{role:`alert`,children:AK}):null,m===void 0?null:(0,q.jsx)(vK,{preview:m}),(0,q.jsx)(SK,{preview:m,reading:c.step===`reading`,region:r,stale:DK(c),staleId:p}),(0,q.jsx)(_O,{checked:l,describedBy:u,disabled:h,label:`Hide repository and workflow names`,onChange:s.setHideNames}),(0,q.jsx)(wK,{id:u}),(0,q.jsx)(cC,{command:`ork feedback publish ${n}${l?` --hide-names`:``}`}),(0,q.jsx)(gK,{id:f,onTryAgain:s.tryAgain,takeFocus:c.step===`postFailed`?`always`:`ifLost`,words:jK(c)}),(0,q.jsx)(yU,{id:d,why:NK(c)}),(0,q.jsxs)(CK,{children:[(0,q.jsx)(Y,{disabled:h,focusableWhenDisabled:!0,onClick:a,variant:`ghost`,children:`Cancel`}),(0,q.jsx)(Y,{"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`})]})]})},FK=({open:e,onOpenChange:t,client:n,item:r,id:i,onPosted:a,onCancelled:o})=>{let s=(0,U.useRef)(null),c=(0,U.useRef)({busy:!1,tried:!1}),l=(0,U.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,q.jsx)(NC,{initialFocus:s,onOpenChange:e=>{e?t(!0):u()},open:e,size:`wide`,title:`Publish ${i} to Ork's Discussions`,children:(0,q.jsx)(PK,{client:n,id:i,item:r,onClose:u,onPosted:a,onStep:l,region:s})})},IK=({item:e,detail:t,acts:n})=>{let r=ob(),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(0),c=HG(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,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{"aria-label":`Actions on ${c}`,className:gU.actions,role:`group`,children:[oK(e,t).map(({key:e,word:t,cli:n,variant:r,check:i})=>(0,q.jsx)(Y,{"aria-label":sK(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,q.jsx)(Y,{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,q.jsx)(`p`,{className:gU.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,q.jsx)(mK,{detail:t,item:e,onAdd:r=>n.addLesson(e,r,t.lessonCap),onOpenChange:d,open:i===`lesson`},`lesson-${String(o)}`),(0,q.jsx)(lK,{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,q.jsx)(FK,{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]})},LK=({name:e,children:t})=>(0,q.jsxs)(`div`,{className:gU.fact,children:[(0,q.jsx)(`dt`,{className:gU.factName,children:e}),(0,q.jsx)(`dd`,{className:gU.factValue,children:t})]}),RK=({name:e,values:t})=>t.length===0?null:(0,q.jsx)(LK,{name:e,children:t.join(`, `)}),zK=({item:e,onSplit:t})=>{let n=HG(e.id);return(0,q.jsxs)(`dl`,{className:gU.facts,children:[(0,q.jsx)(LK,{name:`Item`,children:n}),(0,q.jsx)(LK,{name:`About`,children:e.target}),(0,q.jsx)(LK,{name:`Kind`,children:e.kind}),(0,q.jsx)(LK,{name:`Severity`,children:e.severity}),(0,q.jsx)(LK,{name:`Seen`,children:(0,q.jsxs)(`span`,{children:[(0,q.jsx)(`span`,{"aria-hidden":`true`,children:`${String(e.count)}×`}),(0,q.jsx)(lk,{children:ZG(e.count)}),` in ${QG(e.runs.length)}`]})}),(0,q.jsx)(LK,{name:`First seen`,children:(0,q.jsx)(`time`,{dateTime:e.firstSeen,children:zW(e.firstSeen)})}),(0,q.jsx)(LK,{name:`Last seen`,children:(0,q.jsx)(`time`,{dateTime:e.lastSeen,children:zW(e.lastSeen)})}),(0,q.jsx)(RK,{name:`Workflows`,values:e.workflows}),(0,q.jsx)(RK,{name:`Models`,values:e.models}),(0,q.jsx)(RK,{name:`Sources`,values:e.sources}),e.merged.length===0?null:(0,q.jsxs)(LK,{name:`Merged`,children:[e.merged.map(HG).join(`, `),(0,q.jsx)(Y,{cli:`ork feedback split ${n}`,onClick:t,variant:`ghost`,children:`Split`})]})]})},BK=({onBack:e})=>(0,q.jsxs)(Y,{onClick:e,variant:`ghost`,children:[(0,q.jsx)(dy,{}),`Back to items`]}),VK=({run:e,onOpen:t})=>(0,q.jsxs)(`p`,{className:gU.line,children:[(0,q.jsx)(`span`,{className:gU.lineIcon,children:(0,q.jsx)(iy,{})}),(0,q.jsxs)(`span`,{className:gU.message,children:[`Run `,(0,q.jsx)(`code`,{children:e}),` is proposing a fix.`]}),(0,q.jsx)(Y,{"aria-label":`Open run ${e}`,onClick:()=>{t(e)},variant:`ghost`,children:`Open run`})]}),HK=e=>[zW(e.at),e.feedback.source,...e.feedback.code===void 0?[]:[e.feedback.code],`run ${e.runId}`,...e.node===void 0?[]:[e.node]].join(` · `),UK=({record:e,title:t,onOpenRun:n})=>{let{feedback:r,runId:i,node:a}=e;return(0,q.jsxs)(`li`,{className:gU.record,children:[(0,q.jsxs)(`p`,{className:gU.recordMeta,children:[(0,q.jsx)(`span`,{children:HK(e)}),(0,q.jsxs)(Y,{onClick:()=>{n(i,a)},variant:`ghost`,children:[`Open run`,(0,q.jsx)(lk,{children:` ${i}${a===void 0?``:` at ${a}`}, ${zW(e.at)}`})]})]}),r.title===t?null:(0,q.jsx)(`h4`,{className:gU.recordTitle,children:r.title}),r.body===``?null:(0,q.jsx)(`p`,{className:gU.recordBody,children:r.body}),r.evidence.length===0?null:(0,q.jsxs)(`p`,{className:gU.evidence,children:[(0,q.jsx)(`span`,{className:gU.caption,children:`Evidence `}),r.evidence.join(`, `)]})]})},WK=({item:e,read:t,onOpenRun:n})=>{let r=HG(e.id),i=t.detail?.records;return(0,q.jsxs)(`div`,{className:gU.section,children:[(0,q.jsx)(`h3`,{className:gU.caption,children:i===void 0?`Records`:`Records · ${String(i.length)}, newest first`}),i===void 0&&t.error!==null?(0,q.jsxs)(`div`,{className:gU.line,children:[(0,q.jsx)(`p`,{className:gU.alert,role:`alert`,children:(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:`Could not read the records: ${t.error}`})})}),(0,q.jsx)(Y,{onClick:t.reload,variant:`ghost`,children:`Try again`})]}):null,i===void 0&&t.error===null?(0,q.jsx)(`p`,{"aria-busy":`true`,className:gU.message,children:`Reading records…`}):null,i===void 0?null:(0,q.jsx)(`ol`,{"aria-label":`Records of ${r}, newest first`,className:gU.records,role:`list`,children:i.toReversed().map(t=>(0,q.jsx)(UK,{onOpenRun:n,record:t,title:e.title},t.id))})]})},GK=({item:e,read:t,acts:n,narrow:r,onBack:i,onLeave:a})=>{let o=(0,U.useId)(),s=t.detail?.fixRun;return(0,q.jsxs)(`section`,{"aria-labelledby":o,className:gU.detail,onKeyDown:e=>{let t=document.querySelector(`[data-modal]`)!==null;e.key===`Escape`&&!t&&a()},children:[r?(0,q.jsx)(BK,{onBack:i}):null,(0,q.jsxs)(`div`,{className:gU.head,children:[(0,q.jsx)(`h2`,{className:gU.title,"data-feedback-heading":``,id:o,tabIndex:-1,children:e.title}),(0,q.jsx)(Yj,{pill:!0,status:e.status})]}),(0,q.jsx)(zK,{item:e,onSplit:()=>{n.split(e)}}),s===void 0?null:(0,q.jsx)(VK,{onOpen:n.openRun,run:s}),(0,q.jsx)(IK,{acts:n,detail:t.detail,item:e}),(0,q.jsx)(WK,{item:e,onOpenRun:n.openRun,read:t}),(0,q.jsx)(cC,{command:`ork feedback show ${e.id.slice(0,12)}`})]})},KK=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())},qK=()=>(0,q.jsx)(lk,{children:`, `}),JK=(0,U.memo)(({item:e,chosen:t,tabStop:n,onChoose:r})=>(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{"aria-current":t?`true`:void 0,className:gU.row,"data-item":e.id,onClick:()=>{r(e.id)},tabIndex:n?0:-1,type:`button`,children:[(0,q.jsxs)(`span`,{className:gU.rowTop,children:[(0,q.jsx)(`span`,{className:gU.rowTitle,children:e.title}),(0,q.jsx)(qK,{}),(0,q.jsx)(Yj,{status:e.status})]}),(0,q.jsx)(qK,{}),(0,q.jsxs)(`span`,{className:gU.rowMeta,children:[(0,q.jsx)(`span`,{children:HG(e.id)}),(0,q.jsx)(qK,{}),(0,q.jsxs)(`span`,{children:[(0,q.jsx)(`span`,{"aria-hidden":`true`,children:`${String(e.count)}×`}),(0,q.jsx)(lk,{children:ZG(e.count)})]}),(0,q.jsx)(qK,{}),(0,q.jsx)(`span`,{children:`${e.target} · ${e.kind}`}),e.severity===`high`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(qK,{}),(0,q.jsx)(`span`,{className:gU.high,children:`high`})]}):null,e.merged.length===0?null:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(qK,{}),(0,q.jsx)(`span`,{children:`+${String(e.merged.length)} merged`})]}),(0,q.jsx)(qK,{}),(0,q.jsxs)(`span`,{children:[(0,q.jsx)(lk,{children:`last seen `}),(0,q.jsx)(`time`,{dateTime:e.lastSeen,children:zW(e.lastSeen)})]})]})]})}));JK.displayName=`FeedbackRow`;var YK=({items:e,chosen:t,onChoose:n})=>{let r=e.some(({id:e})=>e===t)?t:e[0]?.id;return(0,q.jsx)(`ul`,{"aria-label":`Feedback items`,className:gU.list,onKeyDown:KK,role:`list`,children:e.map(e=>(0,q.jsx)(JK,{chosen:e.id===t,item:e,onChoose:n,tabStop:e.id===r},e.id))})},XK=({filter:e,items:t,count:n,updating:r,failed:i,onFilter:a,onReload:o})=>(0,q.jsxs)(`div`,{className:gU.tools,children:[(0,q.jsx)(uk,{label:`Status`,onChange:t=>{a({...e,status:t})},options:KG(t??[]),value:e.status}),(0,q.jsx)(uk,{label:`About`,onChange:t=>{a({...e,about:t})},options:WG,value:e.about}),(0,q.jsxs)(`div`,{className:gU.toolsEnd,children:[t===null?null:(0,q.jsx)(`span`,{className:gU.count,children:XG(n)}),r?(0,q.jsx)(`span`,{className:gU.updating,children:`Updating…`}):null,(0,q.jsx)(Y,{cli:e.status===`all`||e.status===`dismissed`?`ork feedback list --all`:`ork feedback list`,onClick:o,variant:`ghost`,children:i?`Try again`:`Reload`})]})]}),ZK=({error:e})=>(0,q.jsxs)(`p`,{className:gU.alert,"data-tone":`failed`,role:`alert`,children:[(0,q.jsx)(`span`,{className:gU.lineIcon,children:(0,q.jsx)(My,{})}),(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:`Could not read feedback: ${e}`})})]}),QK=({anything:e,filter:t})=>{if(!e)return(0,q.jsx)(qD,{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}=eK(t);return(0,q.jsx)(qD,{title:n,children:r})},$K=(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())})},eq=e=>{let{state:t,workspace:n,filter:r,narrow:i,choose:a,focus:o}=e,s=(0,U.useRef)(!1),c=()=>nH(t.feedback.state.getValue())?.data??[],l=(e,r)=>{$K(t,n,e,r)},u=async()=>{await t.feedback.load(),e.reloadDetail()};return{moving:s,setStatus:async(e,l)=>{let d=HG(e.id),f=JG(c(),r),p=await t.client.call(`feedbackStatus`,{params:{id:e.id},body:{status:l}});if(!p.ok){let e=l===`new`?`restore`:`dismiss`;tb.add({title:`Could not ${e} ${d}`,description:p.error});return}s.current=!0,await u();let m=JG(c(),r);if(!m.some(({id:t})=>t===e.id)){let t=tK(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=HG(e.id),i=await t.client.call(`accept`,{params:{id:e.id},body:{lesson:!1}});i.ok?(n?.announce(`Accepted ${r}.`),await u()):tb.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 tb.add({title:`Lesson added`,description:a===void 0?`${HG(e.id)} is accepted.`:`\`${a.file}\` in \`${a.root}\`, ${uK(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 tb.add({title:`Run ${i} started`,description:`\`ork:feedback-apply\` is proposing a fix for ${HG(e.id)}. Its question comes to Decisions.`}),l(i),u(),null},split:async e=>{let r=HG(e.id),i=await t.client.call(`split`,{params:{id:e.id}});i.ok?(o(`heading`),n?.announce(`Split ${XG(i.data.moved)} back out of ${r}.`),await u()):tb.add({title:`Could not split ${r}`,description:i.error})},openRun:(e,t)=>{l(e,t)},reloadAll:u,announce:e=>{n?.announce(e)}}},tq=5e3,nq=48,rq=16,iq=e=>{let t=vb(e.feedback.state),n=vb(e.runs),r=(0,U.useRef)(0),i=(0,U.useRef)(null),a=(0,U.useRef)(n),o=(0,U.useCallback)(async()=>{r.current=Date.now(),await e.feedback.load()},[e]);return(0,U.useEffect)(()=>(o(),()=>{i.current!==null&&clearTimeout(i.current),i.current=null}),[o]),(0,U.useEffect)(()=>{if(a.current===n||(a.current=n,i.current!==null))return;let e=Math.max(0,r.current+tq-Date.now());i.current=setTimeout(()=>{i.current=null,o()},e)},[n,o]),{read:t,load:o}},aq=(e,t,n)=>{let[r,i]=(0,U.useState)(null),[a,o]=(0,U.useState)(null),[s,c]=(0,U.useState)(``),[l,u]=(0,U.useState)(0),d=`${t??``}|${n}|${String(l)}`;(0,U.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,U.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}},oq=e=>{let[t,n]=(0,U.useState)(!1);return(0,U.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`,``))||rq;n(t<nq*i)});return r.observe(t),()=>{r.disconnect()}},[e]),t},sq=e=>e===void 0?``:[e.status,e.count,e.lastSeen,...e.merged].join(`|`),cq={heading:`[data-feedback-heading]`,list:`[data-feedback-list]`},lq=(e,t)=>e?.querySelector(typeof t==`string`?cq[t]:`[data-item="${t.row}"]`)??null,uq=e=>{let t=(0,U.useRef)(null),[,n]=(0,U.useState)(0);return(0,U.useEffect)(()=>{let n=t.current;if(n===null)return;let r=lq(e.current,n);r!==null&&(t.current=null,r.focus())}),(0,U.useCallback)(e=>{t.current=e,n(e=>e+1)},[])},dq=()=>{let e=(0,U.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)}}},fq=()=>{let e=ob(),t=(0,U.use)(fL),n=vb(e.feedbackFilter),{read:r,load:i}=iq(e),a=(0,U.useRef)(null),o=oq(a),[s,c]=(0,U.useState)(null),[l,u]=(0,U.useState)(`list`),d=nH(r)?.data??null,f=(0,U.useMemo)(()=>d??[],[d]),p=(0,U.useMemo)(()=>JG(f,n),[f,n]),m=p.find(({id:e})=>e===s),h=aq(e.client,m?.id??null,sq(m)),g=uq(a),_=dq(),v=(0,U.useCallback)(e=>{c(e),u(e===null?`list`:`detail`)},[]),y=eq({state:e,workspace:t,filter:n,narrow:o,choose:v,focus:g,reloadDetail:h.reload}),{moving:b}=y;return(0,U.useEffect)(()=>{if(s===null||d===null||b.current||p.some(({id:e})=>e===s))return;let e=nK(f,s);e!==void 0&&p.some(({id:t})=>t===e.id)?(c(e.id),t?.announce(`${HG(s)} was merged into ${HG(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:qG(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(`${XG(JG(f,n).length)}.`)},reload:()=>{i(),h.reload()}}},pq=({view:e})=>{let{read:t,all:n,items:r,shown:i,filter:a,chosen:o}=e;return(0,q.jsxs)(`div`,{"aria-label":`Items`,className:gU.card,"data-feedback-list":``,role:`group`,tabIndex:-1,children:[t.status===`failed`?(0,q.jsx)(ZK,{error:t.error}):null,n===null&&t.status!==`failed`?(0,q.jsx)(`p`,{className:gU.message,children:`Reading feedback…`}):null,n!==null&&i.length===0?(0,q.jsx)(QK,{anything:r.length>0,filter:a}):null,i.length===0?null:(0,q.jsx)(YK,{chosen:o,items:i,onChoose:e.choose})]})},mq=({view:e})=>{let{item:t,chosen:n,narrow:r}=e;return(0,q.jsxs)(`div`,{className:gU.card,"data-feedback-detail":``,children:[t===void 0?null:(0,q.jsx)(GK,{acts:e.acts,item:t,narrow:r,onBack:e.back,onLeave:e.back,read:e.detail}),t===void 0&&r&&n!==null?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(BK,{onBack:e.back}),(0,q.jsx)(`p`,{className:gU.message,children:`${HG(n)} isn't in this list any more.`})]}):null,t===void 0&&!r?(0,q.jsx)(`p`,{className:gU.message,children:`Choose an item to read its records.`}):null]})},hq=()=>{let e=fq(),{read:t,all:n,filter:r,shown:i,showing:a,focusWatch:o,root:s}=e;return(0,q.jsxs)(`div`,{"aria-label":`Feedback`,className:gU.panel,"data-layout":e.narrow?`narrow`:`wide`,onBlur:o.onBlur,onFocus:o.onFocus,ref:s,role:`group`,tabIndex:-1,children:[(0,q.jsx)(XK,{count:i.length,failed:t.status===`failed`,filter:r,items:n,onFilter:e.setFilter,onReload:e.reload,updating:t.status===`loading`&&n!==null}),(0,q.jsxs)(`div`,{className:gU.body,children:[a===`detail`?null:(0,q.jsx)(pq,{view:e}),a===`list`?null:(0,q.jsx)(mq,{view:e})]})]})},gq=`all`,_q=[{value:`7`,label:`Last 7 days`},{value:`30`,label:`Last 30 days`},{value:`90`,label:`Last 90 days`},{value:gq,label:`All time`}],vq=e=>e===gq,yq=(e,t)=>{if(vq(e))return;let n=new Date(t);return new Date(n.getFullYear(),n.getMonth(),n.getDate()-(Number(e)-1)).toISOString()},bq=(e,t,n)=>[`ork usage`,...e?[`--all`]:[],`--since ${vq(t)?`all`:`${t}d`}`,...n===void 0?[]:[`--by ${n}`]].join(` `),xq=92,Sq=e=>String(e).padStart(2,`0`),Cq=e=>`${String(e.getFullYear())}-${Sq(e.getMonth()+1)}-${Sq(e.getDate())}`,wq=e=>{let[t=0,n=1,r=1]=e.split(`-`).map(Number);return new Date(t,n-1,r)},Tq=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()-(e.getDay()+6)%7),Eq=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),Dq=(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=Cq(e);a.push(i.get(t)??{key:t,costUsd:0,sessions:0})}return a},Oq=(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?wq(i??``):Eq(new Date(t)),o=Eq(new Date(n)),s=Dq(r,1,a,o),c=s.length>xq?`week`:`day`,l=c===`day`?s:Dq(e.groups.week,7,Tq(a),o);return{unit:c,bars:l,maxUsd:Math.max(0,...l.map(e=>e.costUsd))}},kq=e=>tM(e),Aq=e=>{let t=[...e];return e=>tM(e,t)},jq=e=>e<1e3?String(e):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`,Mq=e=>`${String(Math.round(e*100))}%`,Nq={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`},Pq=e=>e.toSorted((e,t)=>t.costUsd-e.costUsd)[0],Fq=e=>`${String(e)} session${e===1?``:`s`}`,Iq=2,Lq=6,Rq=14,zq=e=>e<=Lq?`always`:e<=Rq?`wide`:`never`,Bq=({bars:e})=>{let t=zq(e.length);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{"aria-hidden":!0,className:Nq.axis,"data-labelled":t,children:[(0,q.jsx)(`span`,{children:e[0]?.key}),(0,q.jsx)(`span`,{children:e.at(-1)?.key})]}),(0,q.jsx)(`div`,{"aria-hidden":!0,className:Nq.axisEvery,"data-labelled":t,children:e.map(e=>(0,q.jsx)(`span`,{children:e.key.slice(5)},e.key))})]})},Vq=({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=Aq(r.map(e=>e.costUsd));return(0,q.jsxs)(`details`,{className:Nq.details,children:[(0,q.jsx)(`summary`,{children:`Show as a table`}),(0,q.jsxs)(`table`,{className:Nq.table,children:[(0,q.jsx)(`thead`,{children:(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`th`,{scope:`col`,children:n===`day`?`Day`:`Week of`}),(0,q.jsx)(`th`,{className:Nq.number,scope:`col`,children:`Cost`}),(0,q.jsx)(`th`,{className:Nq.number,scope:`col`,children:`Sessions`})]})}),(0,q.jsx)(`tbody`,{children:r.map(e=>(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`th`,{className:Nq.name,scope:`row`,children:e.key}),(0,q.jsx)(`td`,{className:Nq.number,children:a(e.costUsd)}),(0,q.jsx)(`td`,{className:Nq.number,children:e.sessions})]},e.key))})]}),i===0?null:(0,q.jsxs)(`p`,{className:Nq.note,children:[String(i),` `,n,i===1?``:`s`,` with no spend.`]})]})},Hq=({series:e})=>{let[t,n]=(0,U.useState)(null),{bars:r,maxUsd:i,unit:a}=e,o=r.find(e=>e.key===t)??null,s=Pq(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 ${kq(s.costUsd)} ${a===`day`?`on`:`in the week of`} ${s.key}.`;return(0,q.jsxs)(`section`,{"aria-label":u,className:Nq.section,children:[(0,q.jsxs)(`div`,{className:Nq.chartHead,children:[(0,q.jsx)(`h3`,{className:Nq.heading,children:u}),c===void 0?null:(0,q.jsxs)(`p`,{className:Nq.readout,children:[o===null?`Peak: `:``,d,c.key,c.key===l?` so far`:``,` · `,kq(c.costUsd),` ·`,` `,Fq(c.sessions)]})]}),(0,q.jsx)(`div`,{"aria-label":f,className:Nq.chart,onPointerLeave:()=>{n(null)},role:`img`,children:r.map(e=>(0,q.jsx)(`div`,{className:Nq.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,q.jsx)(`div`,{className:Nq.bar,style:{height:`${String(Math.max(Iq,e.costUsd/i*100))}%`}})},e.key))}),(0,q.jsx)(Bq,{bars:r}),(0,q.jsx)(Vq,{series:e})]})},Uq=e=>e===void 0?`All projects`:`This project`,Wq=e=>`$${e.toFixed(2)}`,Gq=e=>new Date(e).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}),Kq=({limits:e})=>e.problems.length===0&&e.caps.length===0&&e.plan.length===0?null:(0,q.jsxs)(`section`,{"aria-label":`Limits`,className:Nq.limits,children:[e.problems.map(e=>(0,q.jsx)(`p`,{className:Nq.note,children:(0,q.jsx)(r_,{text:e})},e)),e.caps.map(e=>(0,q.jsx)(SW,{label:`${Uq(e.project)}, this ${e.window}`,max:e.capUsd,text:`${Wq(e.spentUsd)} of ${Wq(e.capUsd)}, resets ${Gq(e.resetsAt)}`,value:Math.min(e.spentUsd,e.capUsd)},`${e.project??`all`}-${e.window}`)),e.plan.map(e=>(0,q.jsx)(`p`,{className:Nq.note,children:`Your Claude plan's ${e.window.replaceAll(`_`,` `)} limit ${e.status===`rejected`?`was reached`:`is close`}${e.resetsAt===void 0?``:`; it resets ${Gq(e.resetsAt)}`}.`},e.window))]}),qq=10,Jq=({title:e,label:t,groups:n,total:r,nameOf:i,moreCommand:a})=>{let o=n.length-qq,s=n.slice(0,qq),c=Aq(s.map(e=>e.costUsd));return(0,q.jsxs)(`section`,{"aria-label":e,className:Nq.section,children:[(0,q.jsx)(`h3`,{className:Nq.heading,children:e}),(0,q.jsxs)(`table`,{className:Nq.table,children:[(0,q.jsx)(`thead`,{children:(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`th`,{scope:`col`,children:t}),(0,q.jsx)(`th`,{className:Nq.number,scope:`col`,children:`Cost`}),(0,q.jsx)(`th`,{className:Nq.number,scope:`col`,children:`Share`}),(0,q.jsx)(`th`,{className:Nq.number,scope:`col`,children:`Sessions`}),(0,q.jsx)(`th`,{className:Nq.number,scope:`col`,children:`From cache`})]})}),(0,q.jsx)(`tbody`,{children:s.map(e=>(0,q.jsxs)(`tr`,{children:[(0,q.jsxs)(`th`,{className:Nq.name,scope:`row`,title:e.key,children:[i?.(e.key)??e.key,i===void 0?null:(0,q.jsx)(`span`,{className:Nq.path,children:e.key})]}),(0,q.jsx)(`td`,{className:Nq.number,children:c(e.costUsd)}),(0,q.jsx)(`td`,{className:Nq.number,children:Mq(r===0?0:e.costUsd/r)}),(0,q.jsx)(`td`,{className:Nq.number,children:e.sessions}),(0,q.jsx)(`td`,{className:Nq.number,children:Mq(e.cacheHitRate)})]},e.key))})]}),o>0?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`p`,{className:Nq.note,children:[`And `,o,` more that cost less. This lists them all:`]}),(0,q.jsx)(cC,{command:a})]}):null]})},Yq=({error:e,command:t,retry:n})=>(0,q.jsxs)(`div`,{className:Nq.section,children:[(0,q.jsxs)(`p`,{className:Nq.refused,role:`alert`,children:[`Cannot read usage: `,(0,q.jsx)(r_,{text:e})]}),(0,q.jsx)(`div`,{className:Nq.retry,children:(0,q.jsx)(Y,{onClick:n,children:`Try again`})}),(0,q.jsx)(`p`,{className:Nq.note,children:`On a terminal, the same report:`}),(0,q.jsx)(cC,{command:t})]}),Xq=({period:e,limits:t})=>(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Kq,{limits:t}),(0,q.jsx)(qD,{cli:`ork run <workflow>`,title:vq(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:`})]}),Zq=({report:e})=>{let{totals:t}=e,n=t.inputTokens+t.cacheReadTokens+t.cacheWriteTokens,r=[[`Spend`,kq(t.costUsd)],[`Runs with sessions`,String(t.runs)],[`Sessions`,String(t.sessions)],[`Tokens in`,jq(n)],[`Tokens out`,jq(t.outputTokens)],[`From cache`,Mq(t.cacheHitRate)]];return(0,q.jsx)(`dl`,{className:Nq.totals,children:r.map(([e,t])=>(0,q.jsxs)(`div`,{className:Nq.total,children:[(0,q.jsx)(`dt`,{children:e}),(0,q.jsx)(`dd`,{children:t})]},e))})},Qq=({report:e,since:t,now:n,period:r,everyProject:i,projectName:a})=>{let o=(0,U.useMemo)(()=>Oq(e,t,n),[e,t,n]),s=e.totals.costUsd,c=e=>bq(i,r,e);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Kq,{limits:e.limits}),(0,q.jsxs)(`div`,{className:Nq.overview,children:[(0,q.jsx)(Zq,{report:e}),e.hints.length===0?null:(0,q.jsxs)(`section`,{"aria-label":`Worth a look`,className:Nq.hintsSection,children:[(0,q.jsx)(`h3`,{className:Nq.heading,children:`Worth a look`}),(0,q.jsx)(`ul`,{className:Nq.hints,children:e.hints.map(e=>(0,q.jsx)(`li`,{children:(0,q.jsx)(r_,{text:e.message})},e.code))})]}),(0,q.jsx)(`div`,{className:Nq.chartArea,children:(0,q.jsx)(Hq,{series:o})})]}),(0,q.jsxs)(`div`,{className:Nq.breakdowns,children:[i?(0,q.jsx)(Jq,{groups:e.groups.project,label:`Project`,moreCommand:c(`project`),nameOf:a,title:`By project`,total:s}):null,(0,q.jsx)(Jq,{groups:e.groups.workflow,label:`Workflow`,moreCommand:c(`workflow`),title:`By workflow`,total:s}),(0,q.jsx)(Jq,{groups:e.groups.model,label:`Model`,moreCommand:c(`model`),title:`By model`,total:s}),(0,q.jsx)(Jq,{groups:e.groups.node,label:`Node`,moreCommand:c(`node`),title:`Costliest nodes`,total:s})]}),(0,q.jsx)(`p`,{className:Nq.note,children:`Costs are Claude Code's own estimates. On a subscription they are not what you are billed. On a terminal:`}),(0,q.jsx)(cC,{command:c()})]})},$q=()=>{let e=ob(),t=vb(e.usage.state),n=vb(e.runs),r=vb(e.projects.state),i=vb(e.usageFilter),{project:a,period:o}=i,[s,c]=(0,U.useState)(0),l=nH(t),u=(0,U.useRef)(null),d=_b(e.runs,e=>e?.filter(e=>e.live!==`running`&&e.live!==`paused`).length??0);(0,U.useEffect)(()=>{e.projects.load()},[e]),(0,U.useEffect)(()=>{let t=Date.now(),n=yq(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,U.useMemo)(()=>XW(r.status===`ready`?r.data:[],n??[]),[r,n]),p=a===`all`;return(0,q.jsxs)(`div`,{className:Nq.panel,children:[(0,q.jsxs)(`div`,{className:Nq.tools,children:[(0,q.jsx)(`div`,{className:Nq.projectFilter,children:(0,q.jsx)(uk,{label:`Project`,onChange:t=>{e.usageFilter.setValue({...i,project:t})},options:f,value:a})}),(0,q.jsx)(uk,{label:`Period`,onChange:t=>{e.usageFilter.setValue({...i,period:t})},options:_q,value:o})]}),(0,q.jsxs)(`section`,{"aria-busy":t.status===`loading`,"aria-label":`Usage report`,className:Nq.body,ref:u,tabIndex:0,children:[t.status===`failed`?(0,q.jsx)(Yq,{command:bq(p,o),error:t.error,retry:()=>{u.current?.focus(),c(s+1)}}):null,l===void 0?t.status===`failed`?null:(0,q.jsx)(`p`,{className:Nq.note,children:`Reading usage…`}):l.data.totals.sessions===0?(0,q.jsx)(Xq,{limits:l.data.limits,period:l.arg.period}):(0,q.jsx)(Qq,{everyProject:l.arg.query.project===void 0,now:l.arg.now,period:l.arg.period,projectName:e=>f.find(t=>t.value===e)?.label??JW(e),report:l.data,since:l.arg.query.since})]})]})},eJ=(e,t)=>`${String(e)} ${t}${e===1?``:t.endsWith(`h`)?`es`:`s`}`,tJ=e=>({worktrees:e.filter(e=>e.path!==null).length,branches:e.filter(e=>e.path===null).length}),nJ=e=>{let{worktrees:t,branches:n}=tJ(e);return[...t>0||n===0?[eJ(t,`worktree`)]:[],...n>0?[eJ(n,`branch`)]:[]].join(` · `)},rJ=(e,t)=>{let n=e.flatMap(e=>e.items),{worktrees:r,branches:i}=tJ(n),a=t??eJ(e.filter(e=>e.items.length>0).length,`project`);return n.length===0?`No Ork worktrees or branches in ${a}.`:`${[...r>0?[eJ(r,`worktree`)]:[],...i>0?[eJ(i,`branch`)]:[]].join(` and `)} in ${a}.`},iJ=(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`,aJ=e=>[e.root,...e.error===void 0?[e.head===null?`detached HEAD`:`current branch ${e.head}`]:[],...e.items.length===0?[]:[nJ(e.items)]],oJ=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}]],sJ=e=>e.run.known?`Open run ${e.runId} at ${e.nodeId}`:`Open run ${e.runId}: it isn't in Ork's records`,cJ=e=>{let t=`${e.remove.label.replace(`…`,``)} ${e.label}…`;return e.remove.refusal===void 0?t:`${t}: ${e.remove.refusal}`},lJ=(e,t,n,r)=>`cd ${jk(e)} && ork worktrees remove ${jk(t)}${n?` --branch`:``}${r?` --force`:``}`,uJ=e=>e.path===null?`branch`:e.state===`detached`||e.branch===void 0?`detached`:`worktree`,dJ=e=>({branch:`Delete branch \`${e.label}\``,detached:`Remove the worktree of \`${e.label}\``,worktree:`Remove \`${e.label}\``})[uJ(e)],fJ=(e,t)=>{let n=uJ(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.`},pJ=(e,t)=>e.merged?`It's merged into \`${t}\`.`:`It has ${eJ(e.ahead,`commit`)} not merged into \`${t}\`; deleting it loses them.`,mJ=e=>e.force?`Continue…`:e.removeWorktree&&e.deleteBranch?`Remove worktree and branch`:e.deleteBranch?`Delete branch`:e.prunes?`Prune`:`Remove worktree`,hJ=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=eJ(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.`},gJ=(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.`,_J=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(` `),vJ=(e,t)=>`cd ${jk(e)} && ork worktrees clean${t?` --branches`:``}`,yJ=`[data-worktree-row]`,bJ=(e,t)=>[...e?.querySelectorAll(yJ)??[]].findIndex(e=>e.dataset.worktreeRow===t),xJ=(e,t)=>{let n=ob(),r=(0,U.use)(fL),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(!1),[c,l]=(0,U.useState)(new Set),u=(0,U.useRef)(`back`),d=(0,U.useRef)(null),f=(0,U.useRef)(0),p=(0,U.useMemo)(()=>({openRun:e=>{$K(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:bJ(e.current,t.key),id:f.current+1}),f.current+=1,s(!0)}}),[n,r,e]),m=t=>{let n=e.current?.querySelectorAll(yJ)??[];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(gJ(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),$K(n,r,e.runId,e.nodeId)}}},SJ=(e,t)=>t===`all`?[...e]:e.filter(e=>e.root===t),CJ=(e,t)=>({...e,name:t}),wJ=()=>{let e=ob(),t=(0,U.use)(fL),n=vb(e.worktrees.state),r=vb(e.worktreesFilter),i=vb(e.runs),a=vb(e.projects.state),o=(0,U.useRef)(0),s=(0,U.useRef)(null),c=(0,U.useRef)(null),l=(0,U.useRef)(i),u=(0,U.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,U.useEffect)(()=>(u(),e.projects.state.getValue().status===`idle`&&e.projects.load(),()=>{c.current!==null&&clearTimeout(c.current),c.current=null}),[u,e]),(0,U.useEffect)(()=>{if(l.current===i||(l.current=i,c.current!==null))return;let e=Math.max(0,o.current+tq-Date.now());c.current=setTimeout(()=>{c.current=null,u()},e)},[i,u]);let d=nH(n)?.data.projects??null,f=XW(nH(a)?.data??[],[...i??[],...(d??[]).map(e=>({project:e.root}))]),p=e=>f.find(t=>t.value===e)?.label??e,m=(d??[]).map(e=>CJ(e,p(e.root))),h=f.flatMap(e=>m.filter(t=>t.root===e.value)),g=d===null?null:SJ(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(rJ(SJ(h,n),r))}}},TJ={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`},EJ={ArrowDown:e=>e+1,ArrowUp:e=>e-1,Home:()=>0,End:(e,t)=>t},DJ=e=>{let t=EJ[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())},OJ=(0,U.memo)(({row:e,project:t,acts:n})=>{let r=(0,U.useId)(),i=(0,U.useId)(),a=lJ(t.root,e.key,e.path===null,!1),o=oJ(e),{refusal:s}=e.remove;return(0,q.jsxs)(`li`,{className:TJ.row,"data-worktree-row":e.key,children:[(0,q.jsxs)(`p`,{className:TJ.rowName,children:[e.label,(0,q.jsx)(lk,{children:`, `})]}),(0,q.jsx)(`span`,{className:TJ.badge,children:(0,q.jsx)(Zj,{state:e.state})}),(0,q.jsx)(`p`,{className:TJ.meta,id:r,children:o.map((e,t)=>(0,q.jsxs)(`span`,{className:e.risk?TJ.risk:void 0,children:[e.text,t<o.length-1?` ·`:``]},t))}),(0,q.jsx)(`span`,{hidden:!0,id:i,children:`CLI: ${a}`}),(0,q.jsxs)(`div`,{className:TJ.actions,children:[(0,q.jsx)(Y,{"aria-label":sJ(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,q.jsx)(Y,{"aria-describedby":`${r} ${i}`,"aria-label":cJ(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)),kJ=({project:e,acts:t})=>{let n=(0,U.useId)();return(0,q.jsxs)(`section`,{"aria-labelledby":n,className:TJ.card,children:[(0,q.jsxs)(`div`,{className:TJ.head,children:[(0,q.jsx)(`h3`,{className:TJ.name,id:n,children:e.name}),(0,q.jsx)(`p`,{className:TJ.headMeta,children:aJ(e).join(` · `)})]}),e.error===void 0?(0,q.jsx)(`ul`,{"aria-label":`Worktrees in ${e.name}`,className:TJ.list,children:e.items.map(n=>(0,q.jsx)(OJ,{acts:t,project:e,row:n},n.key))}):(0,q.jsxs)(`p`,{className:TJ.alert,children:[(0,q.jsx)(`span`,{className:TJ.alertIcon,children:(0,q.jsx)(Fj,{})}),(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:`Could not read ${e.name}'s worktrees: ${e.error}`})})]}),e.fix===void 0?null:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`p`,{className:TJ.note,children:`If it moved, this points Ork at its new place:`}),(0,q.jsx)(cC,{command:e.fix})]})]})},AJ=e=>e.filter(e=>e.steps.length>0),jJ=e=>({worktrees:e.filter(e=>e.removeWorktree||e.prunes).length,branches:e.filter(e=>e.deleteBranch).length}),MJ=e=>e.removeWorktree||e.deleteBranch||e.prunes,NJ=e=>e.skip??`no worktree, branch kept`,PJ=e=>{let[t]=e;return e.length===1&&t!==void 0?`Clean merged worktrees in ${t.name}`:`Clean merged worktrees in ${eJ(e.length,`project`)}`},FJ=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.`,IJ=e=>{let{worktrees:t,branches:n}=jJ(e),r=[...t>0?[`removes ${eJ(t,`worktree`)}`]:[],...n>0?[`deletes ${eJ(n,`branch`)}`]:[]].join(` and `),i=e.filter(e=>!MJ(e)||e.skip!==void 0),a=new Map;for(let e of i)a.set(NJ(e),(a.get(NJ(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(` `)},LJ=e=>{let{worktrees:t,branches:n}=jJ(e.flatMap(e=>e.steps));return t===0&&n===0?null:t===0?`Delete ${eJ(n,`branch`)}`:n===0?`Remove ${eJ(t,`worktree`)}`:`Remove ${eJ(t,`worktree`)} and ${eJ(n,`branch`)}`},RJ=e=>e.some(e=>e.error!==void 0)?`Cleaned in part`:`Cleaned`,zJ={well:`_well_18f8h_7`},BJ=({label:e,reading:t,describedBy:n,ref:r,steady:i=!1,short:a=!1,children:o})=>(0,q.jsx)(`section`,{"aria-busy":t!==void 0,"aria-describedby":n,"aria-label":e,className:zJ.well,"data-short":a?``:void 0,"data-steady":i?``:void 0,ref:r,tabIndex:0,children:t===void 0?o:(0,q.jsx)(r_,{text:t})}),VJ=`Reading the plan…`,HJ=`Nothing to show: the plan couldn't be read.`,UJ=({reading:e,failed:t,well:n})=>(0,q.jsx)(BJ,{label:`Plan`,reading:e?VJ:void 0,ref:n,steady:!0,children:t?HJ:`Nothing to clean.`}),WJ=({checked:e,disabled:t,onChange:n})=>{let r=(0,U.useId)();return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(_O,{checked:e,describedBy:r,disabled:t,label:`Also delete the merged branches`,onChange:n}),(0,q.jsx)(`p`,{className:TJ.note,id:r,children:`Only branches merged into the current branch, which git deletes without losing a commit.`})]})},GJ=({project:e,branches:t,reading:n,failed:r,well:i})=>{let a=(0,U.useId)(),o=e.head??`its detached HEAD`;return(0,q.jsxs)(`section`,{"aria-label":e.name,className:TJ.section,children:[(0,q.jsx)(`h3`,{className:TJ.name,children:e.name}),(0,q.jsx)(`p`,{className:TJ.headMeta,children:(0,q.jsx)(r_,{text:`\`${e.root}\` · into \`${o}\``})}),(0,q.jsx)(`p`,{className:TJ.message,id:a,children:n||r?``:IJ(e.steps)}),(0,q.jsx)(`p`,{className:TJ.caption,children:`Plan`}),(0,q.jsxs)(BJ,{describedBy:a,label:`Plan for ${e.name}`,reading:n?VJ:void 0,ref:i,steady:!0,children:[r?HJ:null,e.steps.map(e=>(0,q.jsxs)(`span`,{children:[e.line.text,e.line.reason===void 0?null:(0,q.jsx)(`span`,{className:TJ.reason,children:` (${e.line.reason})`}),`
107
- `]},e.key))]}),(0,q.jsx)(`p`,{className:TJ.note,children:(0,q.jsx)(r_,{text:`In \`${e.root}\`:`})}),(0,q.jsx)(cC,{command:vJ(e.root,t)})]})},KJ=({lines:e})=>(0,q.jsx)(`ul`,{className:TJ.result,children:e.map(e=>(0,q.jsxs)(`li`,{className:TJ.resultLine,children:[(0,q.jsx)(Mj,{}),e]},e))}),qJ=({results:e})=>{let t=(0,U.useRef)(null);return(0,U.useEffect)(()=>{t.current?.focus()},[]),(0,q.jsxs)(`div`,{className:TJ.step,children:[(0,q.jsx)(`h3`,{className:TJ.title,ref:t,tabIndex:-1,children:RJ(e)}),e.filter(e=>e.done.length>0||e.error!==void 0).map(e=>(0,q.jsxs)(`section`,{"aria-label":e.name,className:TJ.section,children:[(0,q.jsx)(`h4`,{className:TJ.name,children:e.name}),e.error===void 0?null:(0,q.jsxs)(`p`,{className:TJ.alert,children:[(0,q.jsx)(`span`,{className:TJ.alertIcon,children:(0,q.jsx)(Fj,{})}),(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:`Stopped in ${e.name}: ${e.error}`})})]}),e.error===void 0||e.done.length===0?null:(0,q.jsx)(`p`,{className:TJ.note,children:`Done before it stopped:`}),(0,q.jsx)(KJ,{lines:e.done})]},e.root))]})},JJ=e=>{if(e.step!==`done`)return`plan`in e?e.plan:e.shown},YJ=(e,t,n)=>{let[r,i]=(0,U.useState)(!1),[a,o]=(0,U.useState)({step:`reading`}),s=(0,U.useRef)(0),c=(0,U.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,U.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,U.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,JJ(a))},clean:()=>{a.step===`plan`&&d(a.plan)},tryAgain:()=>{a.step===`cleanFailed`?d(a.plan):u(r,JJ(a))}}},XJ=e=>e.step===`readFailed`?`Could not read the plan: ${e.error}`:e.step===`cleanFailed`?`Could not clean: ${e.error}`:null,ZJ=e=>e.step===`reading`?`Reading the plan…`:e.step===`readFailed`?`The plan couldn't be read; Try again reads it.`:null,QJ=e=>{let t=YJ(e.client,e.project,e.onCleaned),{step:n}=t,r=(0,U.useRef)(null),i=(0,U.useId)(),a=(0,U.useId)(),o=n.step===`cleaning`,s=n.step===`reading`,c=JJ(n),l=c===void 0?e.scope:AJ(c.projects),u=LJ(l),d=n.step===`plan`&&n.changed,f=c!==void 0&&!s&&u===null,p=n.step===`readFailed`&&c===void 0;(0,U.useEffect)(()=>{d&&r.current?.focus()},[d]),(0,U.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,q.jsx)(NC,{description:FJ(e.project!==void 0),finalFocus:e.finalFocus,initialFocus:r,onOpenChange:e=>{e||m()},open:e.open,size:`wide`,title:PJ(l.length===0?e.scope:l),children:n.step===`done`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(qJ,{results:n.results}),(0,q.jsx)(PC,{children:(0,q.jsx)(Y,{onClick:m,children:`Close`})})]}):(0,q.jsxs)(q.Fragment,{children:[d?(0,q.jsx)(`p`,{role:`alert`,children:`The plan changed since you read it. Read it again before cleaning.`}):null,l.length===0?(0,q.jsx)(UJ,{failed:p,reading:s,well:r}):null,l.map((e,n)=>(0,q.jsx)(GJ,{branches:t.branches,failed:p,project:e,reading:s,well:n===0?r:void 0},e.root)),(0,q.jsx)(WJ,{checked:t.branches,disabled:o,onChange:t.setBranches}),(0,q.jsx)(gK,{id:a,onTryAgain:t.tryAgain,takeFocus:n.step===`cleanFailed`?`always`:`ifLost`,words:XJ(n)}),(0,q.jsx)(yU,{id:i,why:ZJ(n)}),(0,q.jsxs)(PC,{children:[(0,q.jsx)(Y,{disabled:o,focusableWhenDisabled:!0,onClick:m,variant:`ghost`,children:f?`Close`:`Cancel`}),f?null:(0,q.jsx)(Y,{"aria-describedby":`${i} ${a}`,disabled:n.step!==`plan`,focusableWhenDisabled:!0,onClick:t.clean,variant:`primary`,children:o?`Removing…`:u??`Remove worktrees`})]})]})})},$J=(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}`:``)},eY=`Nothing to show: its state couldn't be read.`,tY=({name:e,children:t})=>(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`dt`,{className:TJ.factName,children:e}),(0,q.jsx)(`dd`,{className:TJ.factValue,children:t})]}),nY=({plan:e,label:t,reading:n})=>(0,q.jsx)(BJ,{label:t,reading:n,steady:!0,children:e===void 0?eY:(0,q.jsxs)(q.Fragment,{children:[e.line.text,e.line.reason===void 0?null:(0,q.jsx)(`span`,{className:TJ.reason,children:` (${e.line.reason})`})]})}),rY=e=>{let{row:t,project:n,plan:r}=e,i=(0,U.useId)(),a=n.head??`the current branch`;return(0,q.jsxs)(`div`,{className:TJ.step,children:[(0,q.jsxs)(`dl`,{className:TJ.facts,children:[(0,q.jsx)(tY,{name:`Project`,children:`${n.name} ${n.root}`}),(0,q.jsxs)(tY,{name:`Run`,children:[`${t.runId} · ${t.nodeId}`,(0,q.jsx)(Y,{"aria-label":sJ(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,q.jsx)(tY,{name:`Path`,children:t.path}),(0,q.jsx)(tY,{name:`State`,children:$J(t,r,a)})]}),uJ(t)===`worktree`&&t.branch!==void 0?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(_O,{checked:e.deleteBranch,describedBy:i,disabled:e.busy,label:`Also delete the branch ${t.branch}`,onChange:e.onDeleteBranch}),(0,q.jsx)(`p`,{className:TJ.note,id:i,children:(0,q.jsx)(r_,{text:pJ(r??t,a)})})]}):null,(0,q.jsx)(`p`,{className:TJ.caption,children:`Plan`}),(0,q.jsx)(nY,{label:`Plan`,plan:r,reading:e.reading?`Reading its state…`:void 0}),(0,q.jsx)(cC,{command:lJ(n.root,t.key,r?.deleteBranch??e.deleteBranch,r?.force??!1)})]})},iY=({title:e,label:t,lines:n,more:r})=>(0,q.jsxs)(`div`,{className:TJ.section,children:[(0,q.jsx)(`p`,{className:TJ.caption,children:(0,q.jsx)(r_,{text:`${e} · ${String(n.length+r)}`})}),(0,q.jsx)(BJ,{label:t,short:!0,children:n.join(`
108
- `)}),r>0?(0,q.jsx)(`p`,{className:TJ.note,children:`and ${String(r)} more`}):null]}),aY=({row:e,plan:t,head:n,root:r})=>{let i=(0,U.useRef)(null);(0,U.useEffect)(()=>{i.current?.focus()},[]);let{losing:a}=t,o=`Commits not merged into ${n}`;return(0,q.jsxs)(`div`,{className:TJ.step,children:[(0,q.jsx)(`h3`,{className:TJ.title,ref:i,tabIndex:-1,children:`What's lost`}),a.changes.length===0?null:(0,q.jsx)(iY,{label:`Uncommitted changes`,lines:a.changes,more:a.more.changes,title:`Uncommitted changes`}),a.commits.length===0?null:(0,q.jsx)(iY,{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,q.jsx)(`p`,{className:TJ.note,children:_J(t)}),(0,q.jsx)(cC,{command:lJ(r,e.key,t.deleteBranch,!0)})]})},oY=e=>`plan`in e?e.plan:e.shown,sY=e=>e.step===`lost`||(e.step===`removing`||e.step===`removeFailed`)&&e.from===`lost`,cY=(e,t,n)=>{let[r,i]=(0,U.useState)(!1),[a,o]=(0,U.useState)({step:`reading`}),s=(0,U.useRef)(0),c=(0,U.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,U.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,U.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,oY(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,oY(a))}}},lY=`It changed since you read it. Read it again before removing.`,uY=(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?lY:null,dY=e=>e.step===`reading`?`Reading its state…`:e.step===`readFailed`?`Its state couldn't be read; Try again reads it.`:e.step===`choice`?hJ(e.plan):null,fY=({client:e,row:t,project:n,target:r,cancel:i,onBusy:a,onRemoved:o,onOpenRun:s,onClose:c})=>{let l=cY(e,r,o),{step:u}=l,d=(0,U.useId)(),f=(0,U.useId)(),p=(0,U.useRef)(null),m=u.step===`removing`,h=oY(u),g=sY(u),_=u.step===`choice`&&u.changed;(0,U.useEffect)(()=>{a(m)},[m,a]);let v=(0,U.useRef)(!1);(0,U.useEffect)(()=>{let e=v.current&&!g;v.current=g,(_||e)&&p.current?.focus()},[_,g]);let y=uY(u,t.label);return(0,q.jsxs)(q.Fragment,{children:[g&&h!==void 0?(0,q.jsx)(aY,{head:n.head??`the current branch`,plan:h,root:n.root,row:t}):(0,q.jsx)(rY,{busy:m,deleteBranch:l.deleteBranch,onDeleteBranch:l.setDeleteBranch,onOpenRun:s,plan:h,project:n,reading:u.step===`reading`,row:t}),(0,q.jsx)(gK,{id:f,onTryAgain:_?void 0:l.tryAgain,takeFocus:u.step===`removeFailed`?`always`:`ifLost`,words:y}),(0,q.jsx)(yU,{id:d,why:dY(u)}),(0,q.jsxs)(`div`,{className:TJ.foot,children:[g?(0,q.jsx)(Y,{disabled:m,focusableWhenDisabled:!0,onClick:l.back,variant:`ghost`,children:`Back`}):null,(0,q.jsx)(Y,{disabled:m,focusableWhenDisabled:!0,onClick:c,ref:i,variant:`ghost`,children:`Cancel`}),g?(0,q.jsx)(Y,{"aria-describedby":f,disabled:u.step!==`lost`,focusableWhenDisabled:!0,onClick:l.loseIt,variant:`danger`,children:m?`Removing…`:`Remove and lose this work`}):(0,q.jsx)(Y,{"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`:mJ(h)})]})]})},pY=({open:e,client:t,row:n,project:r,target:i,finalFocus:a,onRemoved:o,onOpenRun:s,onClose:c})=>{let l=(0,U.useRef)(null),u=(0,U.useRef)(!1),d=()=>{u.current||c()};return(0,q.jsx)(NC,{description:fJ(n,r.root),finalFocus:a,initialFocus:l,onOpenChange:e=>{e||d()},open:e,size:`wide`,title:dJ(n),children:(0,q.jsx)(fY,{cancel:l,client:t,onBusy:e=>{u.current=e},onClose:d,onOpenRun:s,onRemoved:o,project:r,row:n,target:i})})},mY=({acts:e,project:t,merged:n,load:r})=>{let{client:i}=ob(),{opened:a,open:o}=e;return a?.kind===`remove`?(0,q.jsx)(pY,{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,q.jsx)(QJ,{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},hY=({filter:e,options:t,items:n,updating:r,cleanBlocked:i,cleanButton:a,onFilter:o,onClean:s,onReload:c})=>(0,q.jsxs)(`div`,{className:TJ.tools,children:[(0,q.jsx)(uk,{label:`Project`,onChange:o,options:t,value:e}),(0,q.jsxs)(`div`,{className:TJ.toolsEnd,children:[n===null?null:(0,q.jsx)(`span`,{className:TJ.count,children:nJ(n)}),(0,q.jsx)(`output`,{className:TJ.count,children:r?`Updating…`:``}),(0,q.jsx)(Y,{"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,q.jsx)(Y,{cli:`ork worktrees`,onClick:c,tip:`In the project's folder.`,variant:`ghost`,children:`Reload`})]})]}),gY=({error:e})=>(0,q.jsxs)(`p`,{className:TJ.alert,role:`alert`,children:[(0,q.jsx)(`span`,{className:TJ.alertIcon,children:(0,q.jsx)(My,{})}),(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:`Could not read worktrees: ${e}`})})]}),_Y=({projects:e,one:t})=>e===0?(0,q.jsxs)(qD,{cli:`ork register <path>`,focusable:!0,title:`No projects registered yet.`,children:[(0,q.jsx)(`p`,{children:`In a repository:`}),(0,q.jsx)(cC,{command:`ork init`}),(0,q.jsx)(`p`,{children:`Or from outside it:`})]}):t===null?(0,q.jsx)(qD,{cli:`ork worktrees`,focusable:!0,title:`No Ork worktrees or branches.`,children:(0,q.jsx)(r_,{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,q.jsx)(qD,{focusable:!0,title:`No Ork worktrees or branches in ${t}.`,children:`Project: All projects shows every project's.`}),vY=(e,t)=>({...e,items:e.items.filter(n=>!t.has(`${e.root}|${n.key}`))}),yY={usage:{title:`Usage`,Icon:ky,Body:$q},context:{title:`Context`,Icon:jy,Body:VG},feedback:{title:`Feedback`,Icon:Ny,Body:hq},worktrees:{title:`Worktrees`,Icon:Iy,Body:()=>{let e=wJ(),{read:t,shown:n,filter:r}=e,i=r===`all`?null:r,{panel:a,onFocus:o}=mH((n??[]).flatMap(e=>e.items.map(t=>`${e.root}|${t.key}`)).join(`
109
- `),`[data-worktree-row]`),s=xJ(a,e.load),c=(n??[]).map(e=>vY(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,q.jsxs)(`div`,{"aria-label":`Worktrees`,className:TJ.panel,onFocus:o,onKeyDown:DJ,ref:a,role:`group`,tabIndex:-1,children:[(0,q.jsx)(hY,{cleanBlocked:iJ(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,q.jsx)(gY,{error:t.error}):null,n===null&&t.status!==`failed`?(0,q.jsx)(`p`,{className:TJ.message,children:`Reading worktrees…`}):null,n!==null&&l.length===0?(0,q.jsx)(_Y,{one:i===null?null:c[0]?.name??i,projects:e.all?.length??0}):null,l.map(e=>(0,q.jsx)(kJ,{acts:s.rowActs,project:e},e.root)),i===null&&l.length>0&&u>0?(0,q.jsx)(`p`,{className:TJ.note,children:`Nothing left in ${eJ(u,`other project`)}.`}):null,(0,q.jsx)(mY,{acts:s,load:e.load,merged:d,project:i??void 0})]})}}},bY={runs:{id:`runs`,title:`Runs`,Icon:Cy,Body:oG},monitor:{id:`monitor`,title:`Monitor`,Icon:wy,Body:PW},logs:{id:`logs`,title:`Logs`,Icon:Ty,Body:HH},decisions:{id:`decisions`,title:`Decisions`,Icon:Ey,Body:hH},chats:{id:`chats`,title:`Chats`,Icon:Dy,Body:dL},notifications:{id:`notifications`,title:`Notifications`,Icon:Oy,Body:qW},usage:{id:`usage`,...yY.usage},builder:{id:`builder`,title:`Builder`,Icon:Ay,Body:wI},context:{id:`context`,...yY.context},feedback:{id:`feedback`,...yY.feedback},worktrees:{id:`worktrees`,...yY.worktrees}},xY=Object.values(bY),SY=e=>e in bY,CY=e=>bY[e],wY=(e,t)=>e===void 0?void 0:Uk(e,t).join(t?``:`+`),TY=(e,t)=>{if(e.wide&&!e.open.includes(t))return e.minimized.includes(t)?`minimized`:`closed`},EY=({workspace:e})=>{let t=vb(e.view),n=Xk(),r=[...xY.map(({id:r,title:i},a)=>({label:i,detail:TY(t,r),hint:wY(Yk(a+1),n),onSelect:()=>{e.goTo(r)}})),`separator`,{label:`Reset layout`,onSelect:()=>{e.resetLayout()}}];return(0,q.jsx)(ej,{entries:r,trigger:(0,q.jsxs)(Y,{variant:`ghost`,children:[`Window`,(0,q.jsx)(ly,{})]})})},DY=({workspace:e})=>(0,q.jsxs)(`header`,{className:$k.bar,children:[(0,q.jsxs)(`h1`,{className:$k.name,children:[(0,q.jsx)(`img`,{alt:`Ork`,className:$k.logoOnDark,src:`/ork-wordmark-small.svg`}),(0,q.jsx)(`img`,{alt:`Ork`,className:$k.logoOnLight,src:`/ork-wordmark-small-on-light.svg`})]}),(0,q.jsx)(EY,{workspace:e}),(0,q.jsx)(`div`,{className:$k.spacer}),(0,q.jsx)(eA,{workspace:e}),(0,q.jsxs)(Y,{onClick:()=>{e.palette.setValue(!0)},variant:`ghost`,children:[(0,q.jsx)(gy,{}),`Commands`,(0,q.jsx)(a_,{keys:Uk(qk.palette,Xk())})]})]}),OY,kY=class{constructor(){}},AY=class extends kY{constructor(e,t,n,r){super(),this.viewId=e,this.groupId=t,this.panelId=n,this.tabGroupId=r}},jY=class extends kY{constructor(e,t){super(),this.viewId=e,this.paneId=t}},MY=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)}};OY=MY,MY.INSTANCE=new OY;function NY(){let e=MY.getInstance();if(e.hasData(AY.prototype))return e.getData(AY.prototype)[0]}function PY(){let e=MY.getInstance();if(e.hasData(jY.prototype))return e.getData(jY.prototype)[0]}var FY;(function(e){e.NONE={dispose:()=>{}};function t(e){return{dispose:()=>{e()}}}e.from=t})(FY||={});var X=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())}},IY=class{constructor(){this._disposable=FY.NONE}get value(){return this._disposable===FY.NONE?void 0:this._disposable}set value(e){this._disposable&&this._disposable.dispose(),this._disposable=e}dispose(){this._disposable&&=(this._disposable.dispose(),FY.NONE)}},LY;(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()})}}}})(LY||={});var RY=class{constructor(){this._defaultPrevented=!1}get defaultPrevented(){return this._defaultPrevented}preventDefault(){this._defaultPrevented=!0}},zY=class{constructor(){this._isAccepted=!1}get isAccepted(){return this._isAccepted}accept(){this._isAccepted=!0}},BY=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()}},VY=class e{static create(){return new e(Error(`listener stacktrace`).stack??``)}constructor(e){this.value=e}print(){console.warn(`dockview: stacktrace`,this.value)}},HY=class{constructor(e,t){this.callback=e,this.stacktrace=t}},Z=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 HY(t,e.ENABLE_TRACKING?VY.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,VY.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),FY.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))}};Z.ENABLE_TRACKING=!1,Z.MEMORY_LEAK_WATCHER=new BY;function Q(e,t,n,r){return e.addEventListener(t,n,r),{dispose:()=>{e.removeEventListener(t,n,r)}}}var UY=class{constructor(){this._onFired=new Z,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()}},WY=class extends X{constructor(e){super(),this._onDidChange=new Z,this.onDidChange=this._onDidChange.event,this._value=null,this.addDisposables(this._onDidChange,GY(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 GY(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 KY=(e,...t)=>{for(let n of t)e.classList.contains(n)&&e.classList.remove(n)},qY=(e,...t)=>{for(let n of t)e.classList.contains(n)||e.classList.add(n)},$=(e,t,n)=>{let r=e.classList.contains(t);n&&!r&&e.classList.add(t),!n&&r&&e.classList.remove(t)};function JY(e,t){for(;e;){if(e===t)return!0;e=e.parentNode}return!1}function YY(e){return new XY(e)}var XY=class extends X{constructor(e){super(),this._onDidFocus=new Z,this.onDidFocus=this._onDidFocus.event,this._onDidBlur=new Z,this.onDidBlur=this._onDidBlur.event,this.addDisposables(this._onDidFocus,this._onDidBlur);let t=JY(bX(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=()=>{JY(bX(e),e)!==t&&(t?i():r())},this.addDisposables(Q(e,`focus`,r,!0)),this.addDisposables(Q(e,`blur`,i,!0))}refreshState(){this._refreshStateHandler()}},ZY=`dv-quasiPreventDefault`;function QY(e){e[ZY]=!0}function $Y(e){return e[ZY]}function eX(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 tX(e){let t=[],n=e.getRootNode();for(;oX(n);)t.push(n),n=n.host.getRootNode();return t}function nX(e,t){let n=t?.getRootNode(),r=e,i=r.getRootNode();for(;i!==n&&oX(i);)r=i.host,i=r.getRootNode();return r}function rX(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 iX(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 aX(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 oX(e){return!!e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&`host`in e&&!!e.host}function sX(e){let t=e.getRootNode();return t!==e&&typeof t.elementsFromPoint==`function`?t:e.ownerDocument??document}function cX(e,t){e.dataset.testid=t}function lX(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 uX(e=document){let t=lX([`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 dX(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 fX(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=oX(e)?e.host:null}else r=r.parentElement;return n}var pX=class{constructor(e){this.element=e,this._classNames=[]}setClassNames(e){for(let e of this._classNames)$(this.element,e,!1);this._classNames=e.split(` `).filter(e=>e.trim().length>0);for(let e of this._classNames)$(this.element,e,!0)}},mX=100;function hX(e,t){let n=iX(e),r=iX(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 gX(e){let t=new Z,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()},mX),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 _X(e,t){let n;return new X(Q(e,`resize`,()=>{clearTimeout(n),n=setTimeout(()=>{t()},mX)}),FY.from(()=>clearTimeout(n)))}function vX(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 yX(e){let t=e;for(;t&&(t.style.zIndex===`auto`||t.style.zIndex===``);)t=t.parentElement;return t}function bX(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 xX(e){let t=e.getRootNode();return oX(t)?t:(e.ownerDocument??document).body}function SX(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 CX(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var a=e.apply(t,n);function o(e){SX(a,r,i,o,s,`next`,e)}function s(e){SX(a,r,i,o,s,`throw`,e)}o(void 0)})}}function wX(e){let t=DX(e);if(t)throw t}var TX=new Set([`javascript:`,`data:`,`blob:`,`vbscript:`,`file:`]),EX=250;function DX(e,t=globalThis.location){let n;try{n=new URL(e,t.href)}catch{return Error(`dockview: invalid popout URL: ${e}`)}if(TX.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 OX=class extends X{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 Z,this.onWillClose=this._onWillClose.event,this._onDidClose=new Z,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 CX(function*(){var t,n;if(e._window)throw Error(`instance of popout window is already open`);let r=`${e.options.url}`;wX(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 X;e._window={value:a,disposable:o},o.addDisposables(FY.from(()=>{a.close()}),e.watchForClose(a),Q(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),rX(n,[...Array.from(globalThis.document.styleSheets),...globalThis.document.adoptedStyleSheets??[]],{nonce:e.options.nonce});let i=[];for(let t=(r=e.options).styleRoot?.call(r);oX(t);t=t.host.getRootNode())i.push(...Array.from(t.styleSheets??[]),...t.adoptedStyleSheets??[]);i.length>0&&rX(n,i,{nonce:e.options.nonce}),Q(a,`beforeunload`,()=>{e.close()}),t(s)}catch(e){n(e)}})})})()}watchForClose(e){if(typeof e.closed!=`boolean`)return FY.NONE;let t=setInterval(()=>{e.closed&&this.close()},EX);return FY.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 kX(e){if(e.length===0)throw Error(`Invalid tail call`);return[e.slice(0,e.length-1),e[e.length-1]]}function AX(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 jX(e,t){let n=e.indexOf(t);n>-1&&(e.splice(n,1),e.unshift(t))}function MX(e,t){let n=e.indexOf(t);n>-1&&(e.splice(n,1),e.push(t))}function NX(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(t(r))return n}return-1}function PX(e,t){let n=e.indexOf(t);return n>-1&&(e.splice(n,1),!0)}var FX=(e,t,n)=>t>n?t:Math.min(n,Math.max(e,t)),IX=()=>{let e=1;return{next:()=>(e++).toString()}},LX=(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},RX=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=FX(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=FX(Math.round(this.size*e),this.minimumSize,this.maximumSize):this._cachedVisibleSize=Math.round(this._cachedVisibleSize*e)}dispose(){return this.disposable.dispose(),this.view}},zX=function(e){return e.HORIZONTAL=`HORIZONTAL`,e.VERTICAL=`VERTICAL`,e}({});function BX(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 VX;(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})(VX||={});var HX=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),KY(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,$(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,$(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 Z,this.onDidSashEnd=this._onDidSashEnd.event,this._onDidAddView=new Z,this.onDidAddView=this._onDidAddView.event,this._onDidRemoveView=new Z,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=LX(e,-1),u=LX(e+1,this.viewItems.length);if(i)for(let e of i)jX(l,e),jX(u,e);if(r)for(let e of r)MX(l,e),MX(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=FX(t,h,g),y=0,b=v;for(let e of l){let t=this.viewItems[e],r=n[e],i=FX(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=FX(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`?(KY(this.element,`dv-separator-border`),this.element.style.removeProperty(`--dv-separator-border`)):(qY(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=LX(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=FX(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=FX(t,e.minimumSize,e.maximumSize),e.size=t;let r=LX(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=VX.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 RX(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=uX(n),i=this._orientation===`HORIZONTAL`?t.clientX:t.clientY,a=NX(this.sashes,t=>t.container===e),o=this.viewItems.map(e=>e.size),s,c,l=LX(a,-1),u=LX(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=FX(n,t.minimumSize,t.maximumSize);let r=LX(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):VX.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=FX(Math.round(i*e/t),r.minimumSize,r.maximumSize))}}else{let t=LX(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=LX(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)jX(r,e);for(let t of e)MX(r,t)}typeof e==`number`&&MX(r,e);for(let e=0;n!==0&&e<r.length;e++){let t=this.viewItems[r[e]],i=FX(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`&&BX(r,`${n}px`,`0px`),this._orientation===`VERTICAL`&&BX(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=LX(e,-1),a=LX(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){$(e.container,`dv-disabled`,t===2),$(e.container,`dv-enabled`,t===3),$(e.container,`dv-maximum`,t===0),$(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()}},UX=Object.keys({orientation:void 0,descriptor:void 0,proportionalLayout:void 0,styles:void 0,margin:void 0,disableAutoResizing:void 0,className:void 0}),WX=class extends X{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 Z,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 HX(this.element,{orientation:this._orientation,proportionalLayout:!1,descriptor:t.descriptor}),this.getPanes().forEach(e=>{let t=new X(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:VX.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),qY(this.element,`dv-animated`),this.animationTimer=setTimeout(()=>{this.animationTimer=void 0,KY(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()}},GX=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 Z,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()}},KX=class e extends X{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=FY.NONE,this.children=[],this._onDidChange=new Z,this.onDidChange=this._onDidChange.event,this._onDidVisibilityChange=new Z,this.onDidVisibilityChange=this._onDidVisibilityChange.event,this._onDidInvalidateSizes=new Z,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 HX(this.element,{orientation:this.orientation,descriptor:e,proportionalLayout:t,styles:n,margin:o})}else this.splitview=new HX(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 X(LY.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 X(t.onDidVisibilityChange(({visible:e})=>{this.setChildVisible(n,e)}),t.onDidInvalidateSizes(()=>{this.invalidateCachedSizes()})):FY.NONE))}dispose(){this._childrenDisposable.dispose(),this.splitview.dispose(),this.children.forEach(e=>e.dispose()),super.dispose()}};function qX(e,t){if(e instanceof GX)return e;if(e instanceof KX)return qX(e.children[t?e.children.length-1:0],t);throw Error(`invalid node`)}function JX(e,t,n,r=1){let i=e.getChildCachedVisibleSize(t);return i===void 0?n:VX.Invisible(Math.round(i*r))}function YX(e,t,n){if(e instanceof KX){let r=new KX(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 KX?n.orthogonalSize:n.size;r.addChild(YX(n,n.size,n.orthogonalSize),JX(e,t,i),0,!0)}return r}return new GX(e.view,e.orientation,n)}function XX(e,t,n){if(e instanceof KX){let r=new KX(nZ(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 KX?s.orthogonalSize:s.size,l=e.size===0?0:Math.round(t*c/e.size);i+=l,o===0&&(l+=t-i),r.addChild(XX(s,n,l),JX(e,o,l,a),0,!0)}return r}return new GX(e.view,nZ(e.orientation),n)}function ZX(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 QX(e){let t=e.parentElement;if(!t)throw Error(`Invalid grid element`);if(/\bdv-grid-view\b/.test(t.className))return[];let n=ZX(t),r=t.parentElement.parentElement.parentElement;return[...QX(r),n]}function $X(e,t,n){if(tZ(e,t)===eZ(n)){let[e,r]=kX(t),i=r;return(n===`right`||n===`bottom`)&&(i+=1),[...e,i]}{let e=+(n===`right`||n===`bottom`);return[...t,e]}}function eZ(e){return e===`top`||e===`bottom`?`VERTICAL`:`HORIZONTAL`}function tZ(e,t){return t.length%2==0?nZ(e):e}var nZ=e=>e===`HORIZONTAL`?`VERTICAL`:`HORIZONTAL`;function rZ(e){return!!e.children}var iZ=(e,t)=>{let n=t===`VERTICAL`?e.box.width:e.box.height;if(!rZ(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=>iZ(e,nZ(t)));return typeof e.cachedVisibleSize==`number`?{type:`branch`,data:r,size:e.cachedVisibleSize,visible:!1}:{type:`branch`,data:r,size:n}},aZ=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=XX(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 KX&&(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=QX(e.element),[n,r]=this.getNode(t);if(!(r instanceof GX)||this._maximizedNode?.leaf===r)return;this.hasMaximizedView()&&this.exitMaximizedView(),iZ(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 GX?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 GX?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=QX(e.element));let n=this._onDidMaximizedNodeChange.pause();try{this.hasMaximizedView()&&this.exitMaximizedView();let n={root:iZ(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 KX(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 GX))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,nZ(t),n,e.size),visible:r.visible}));i=new KX(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 GX(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 GX)return;e.element.remove();let n=e.removeChild(0);e.dispose(),n.dispose(),this._root=YX(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 KX(nZ(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(XX(t,t.orthogonalSize,t.size),VX.Distribute,0)}else this._root.addChild(e,VX.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 GX)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,nZ(t),a))}return{box:r,children:i,cachedVisibleSize:n}}progmaticSelect(e,t=!1){let[n,r]=this.getNode(e);if(!(r instanceof GX))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 qX(i.children[t?a-1:a+1],t)}return qX(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 IY,this._onDidChange=new Z,this.onDidChange=this._onDidChange.event,this._onDidViewVisibilityChange=new Z,this.onDidViewVisibilityChange=this._onDidViewVisibilityChange.event,this._onDidMaximizedNodeChange=new Z,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 KX(n,e,t,0,0,this.locked,this.margin)}isViewVisible(e){let[t,n]=kX(e),[,r]=this.getNode(t);if(!(r instanceof KX))throw TypeError(`Invalid from location`);return r.isChildVisible(n)}setViewVisible(e,t){this.hasMaximizedView()&&this.exitMaximizedView();let[n,r]=kX(e),[,i]=this.getNode(n);if(!(i instanceof KX))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 KX))throw TypeError(`Invalid location`);r.moveChild(t,n)}addView(e,t,n){this.hasMaximizedView()&&this.exitMaximizedView();let[r,i]=kX(n),[a,o]=this.getNode(r);if(o instanceof KX){let n=new GX(e,nZ(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=VX.Invisible(d)),n.removeChild(c).dispose();let f=new KX(o.orientation,this.proportionalLayout,this.styles,o.size,o.orthogonalSize,this.locked,this.margin);n.addChild(f,o.size,c);let p=new GX(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 GX(e,n.orientation,o.size);f.addChild(m,t,i)}}remove(e,t){let n=QX(e.element);return this.removeView(n,t)}removeView(e,t){this.hasMaximizedView()&&this.exitMaximizedView();let[n,r]=kX(e),[i,a]=this.getNode(n);if(!(a instanceof KX))throw TypeError(`Invalid location`);let o=a.children[r];if(!(o instanceof GX))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 GX||(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 KX){let e=s.children.map(e=>e instanceof KX?e.orthogonalSize:e.size);p.splice(u,1,...e);for(let t=0;t<s.children.length;t++){let n=s.children[t],r=JX(s,t,e[t]);c.addChild(n,!f&&typeof r==`number`?VX.Invisible(r):r,u+t)}for(;s.children.length>0;)s.removeChild(0)}else{let e=new GX(s.view,nZ(s.orientation),s.size),t=f?s.orthogonalSize:VX.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 KX))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)}},oZ=Object.keys({disableAutoResizing:void 0,proportionalLayout:void 0,orientation:void 0,hideBorders:void 0,className:void 0}),sZ=class extends X{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(GY(this._element,e=>{if(this.isDisposed||this.disableResizing||!this._element.offsetParent||!aX(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||!aX(this._element))return;let e=Math.round(this._element.clientWidth),t=Math.round(this._element.clientHeight);e!==0&&t!==0&&this.layout(e,t)}},cZ=IX();function lZ(e){switch(e){case`left`:return`left`;case`right`:return`right`;case`above`:return`top`;case`below`:return`bottom`;default:return`center`}}var uZ=class extends sZ{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=cZ.next(),this._groups=new Map,this._onDidRemove=new Z,this.onDidRemove=this._onDidRemove.event,this._onDidAdd=new Z,this.onDidAdd=this._onDidAdd.event,this._onDidMaximizedChange=new Z,this.onDidMaximizedChange=this._onDidMaximizedChange.event,this._onDidActiveChange=new Z,this.onDidActiveChange=this._onDidActiveChange.event,this._bufferOnDidLayoutChange=new UY,this.onDidLayoutChange=LY.map(this._bufferOnDidLayoutChange.onEvent,e=>({reasons:e})),this._onDidViewVisibilityChangeMicroTaskQueue=new UY,this.onDidViewVisibilityChangeMicroTaskQueue=this._onDidViewVisibilityChangeMicroTaskQueue.onEvent,this.element.style.height=`100%`,this.element.style.width=`100%`,this._classNames=new pX(this.element),this._classNames.setClassNames(t.className??``),e.appendChild(this.element),this.gridview=new aZ(!!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()}),FY.from(()=>{this.element.remove()}),this.gridview.onDidChange(()=>{this._bufferOnDidLayoutChange.fire(`geometry`)}),LY.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(QX(e.element),t),this._bufferOnDidLayoutChange.fire(`geometry`)}isVisible(e){return this.gridview.isViewVisible(QX(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??VX.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,VX.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=QX(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=QX(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 dZ(e){"@babel/helpers - typeof";return dZ=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},dZ(e)}function fZ(e,t){if(dZ(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(dZ(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function pZ(e){var t=fZ(e,`string`);return dZ(t)==`symbol`?t:t+``}function mZ(e,t,n){return(t=pZ(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function hZ(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 gZ(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?hZ(Object(n),!0).forEach(function(t){mZ(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):hZ(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function _Z(e,t){return e===`center`?`Tab into ${t}`:`Split ${e} of ${t}`}function vZ(e,t){return e===`center`?`docked into ${t}`:`split ${e} of ${t}`}var yZ={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)=>`${_Z(e,t)}. Arrows to change, Enter to confirm, Escape to go back.`,moveCommitted:(e,t,n)=>`${e} ${vZ(n,t)}.`,moveCancelled:()=>`Move cancelled.`,moveNotAllowed:()=>`That move is not allowed.`,moveFloated:e=>`${e} floated.`};function bZ(e){return e?gZ(gZ({},yZ),e):yZ}var xZ=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()}},SZ=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()}},CZ=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()}},wZ=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 bZ(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()}},TZ=class extends X{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(Q(this.element,`dragenter`,e=>{this.onDragEnter(e)},!0)),this.addDisposables(Q(this.element,`dragover`,e=>{this.onDragOver(e)},!0)),this.addDisposables(Q(this.element,`dragleave`,e=>{this.onDragLeave(e)})),this.addDisposables(Q(this.element,`dragend`,e=>{this.onDragEnd(e)})),this.addDisposables(Q(this.element,`drop`,e=>{this.onDrop(e)}))}},EZ={value:50,type:`percentage`},DZ=100,OZ=100;function kZ(){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 AZ(e,t,n,r){let i=r?.smallWidthBoundary??DZ,a=r?.smallHeightBoundary??OZ,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??EZ;return _.type===`percentage`?g=FX(_.value,0,100)/100:((f||p)&&(g=FX(_.value,0,t)/t),(m||h)&&(g=FX(_.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 jZ(e,t,n,r,i){let a=AZ(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);$(e,`dv-drop-target-small-vertical`,a.isSmallY),$(e,`dv-drop-target-small-horizontal`,a.isSmallX),$(e,`dv-drop-target-selection-line`,f),$(e,`dv-drop-target-left`,a.isLeft),$(e,`dv-drop-target-right`,a.isRight),$(e,`dv-drop-target-top`,a.isTop),$(e,`dv-drop-target-bottom`,a.isBottom),$(e,`dv-drop-target-center`,t===`center`)}function MZ(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 NZ(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 PZ(e){let t=AZ(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),MZ(u,m)?(NZ(u,m),u.className=`dv-drop-target-anchor${e.className?` ${e.className}`:``}`,$(u,`dv-drop-target-left`,t.isLeft),$(u,`dv-drop-target-right`,t.isRight),$(u,`dv-drop-target-top`,t.isTop),$(u,`dv-drop-target-bottom`,t.isBottom),$(u,`dv-drop-target-anchor-line`,t.isSmallX&&(t.isLeft||t.isRight)||t.isSmallY&&(t.isTop||t.isBottom)),$(u,`dv-drop-target-center`,e.quadrant===`center`),c.changed&&($(u,`dv-drop-target-anchor-container-changed`,!0),setTimeout(()=>{$(u,`dv-drop-target-anchor-container-changed`,!1)},10)),{boundsChanged:!0,targetChanged:c.changed}):{boundsChanged:!1,targetChanged:c.changed}}var FZ=class extends RY{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 IZ(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 LZ(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 RZ={value:20,type:`percentage`},zZ=class e extends X{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 Z,this.onDrop=this._onDrop.event,this._onWillShowOverlay=new Z,this.onWillShowOverlay=this._onWillShowOverlay.event,this._disabled=!1,this._acceptedTargetZonesSet=new Set(this.options.acceptedTargetZones),this.dnd=new TZ(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 FZ({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=kZ();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;PZ({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&&jZ(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??RZ;return a.type===`percentage`?BZ(e,t,n,r,i,a.value):VZ(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=kZ();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}};zZ.USED_EVENT_ID=`__dockview_droptarget_event_is_used__`;function BZ(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 VZ(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 HZ(e,t,n){qY(t,`dv-dragged`),t.style.top=`-9999px`,t.style.position=`absolute`,(n?.owner?xX(n.owner):(n?.ownerDocument??document).body).appendChild(t),e.setDragImage(t,n?.x??0,n?.y??0),setTimeout(()=>{KY(t,`dv-dragged`),t.remove()},0)}var UZ=class e extends X{static getInstance(){return e._instance??=new e,e._instance}constructor(){super(),this._targets=new Set,this._targetByElement=new Map,this._onDragStart=new Z,this.onDragStart=this._onDragStart.event,this._onDragMove=new Z,this.onDragMove=this._onDragMove.event,this._onDragEnd=new Z,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=uX(n.ownerDocument??document),this._selectionShield=dX(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=Q(a,`pointermove`,e=>{e.pointerId===this._active?.pointerId&&this._handleMove(e)}),this._upListener=Q(a,`pointerup`,e=>{e.pointerId===this._active?.pointerId&&this._handleEnd(e,!0)}),this._cancelListener=Q(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?sX(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}},WZ={value:20,type:`percentage`},GZ=class extends X{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 Z,this.onDrop=this._onDrop.event,this._onWillShowOverlay=new Z,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,UZ.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 FZ({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)PZ({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=kZ();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&&jZ(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??WZ;return i.type===`percentage`?BZ(this._acceptedTargetZonesSet,e,t,n,r,i.value):VZ(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}},KZ=5,qZ=250,JZ=8,YZ=class extends X{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(Q(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=dX(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)??qZ;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??KZ,a=this.options.pressTolerance,o=(typeof a==`function`?a():a)??JZ,s=this.element.ownerDocument?.defaultView??globalThis.window;this._pendingMoveListener=Q(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=Q(s,`pointerup`,e=>{e.pointerId===this._pendingPointerId&&this._cancelPending()}),this._pendingCancelListener=Q(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);UZ.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()}},XZ=class{constructor(e){this._disposed=!1,this.element=e.element,this.offsetX=e.offsetX??0,this.offsetY=e.offsetY??0;let t=e.owner?xX(e.owner):document.body,n;oX(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())}},ZZ=class extends X{constructor(e,t){super(),this.el=e,this.opts=t,this._dataDisposable=new IY,this._pointerEventsDisposable=new IY,this._disabled=!!t.disabled,this.addDisposables(this._dataDisposable,this._pointerEventsDisposable,Q(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=uX(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&&(HZ(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`,``))}),Q(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(){}},QZ=class{constructor(){this.kind=`html5`}createDropTarget(e,t){return new zZ(e,t)}createDragSource(e,t){return new ZZ(e,t)}},$Z=class{constructor(){this.kind=`pointer`}createDropTarget(e,t){return new GZ(e,t)}createDragSource(e,t){let n=t.createGhost?n=>{let r=t.createGhost(n);if(!r)return;let i=new XZ({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 YZ(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}},eQ=new QZ,tQ=new $Z,nQ=Object.keys({disableAutoResizing:void 0,disableDnd:void 0,className:void 0}),rQ=class extends zY{constructor(e,t,n,r){super(),this.nativeEvent=e,this.position=t,this.getData=n,this.panel=r}},iQ=class extends RY{constructor(){super()}},aQ=class extends X{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 IY,this._onDidDimensionChange=new Z,this.onDidDimensionsChange=this._onDidDimensionChange.event,this._onDidChangeFocus=new Z,this.onDidFocusChange=this._onDidChangeFocus.event,this._onWillFocus=new Z,this.onWillFocus=this._onWillFocus.event,this._onDidVisibilityChange=new Z,this.onDidVisibilityChange=this._onDidVisibilityChange.event,this._onWillVisibilityChange=new Z,this.onWillVisibilityChange=this._onWillVisibilityChange.event,this._onDidActiveChange=new Z,this.onDidActiveChange=this._onDidActiveChange.event,this._onActiveChange=new Z,this.onActiveChange=this._onActiveChange.event,this._onDidParametersChange=new Z,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)}},oQ=class extends aQ{constructor(e,t){super(e,t),this._onDidConstraintsChangeInternal=new Z,this.onDidConstraintsChangeInternal=this._onDidConstraintsChangeInternal.event,this._onDidConstraintsChange=new Z({replay:!0}),this.onDidConstraintsChange=this._onDidConstraintsChange.event,this._onDidSizeChange=new Z,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)}},sQ=class extends oQ{set pane(e){this._pane=e}constructor(e,t){super(e,t),this._onDidExpansionChange=new Z({replay:!0}),this.onDidExpansionChange=this._onDidExpansionChange.event,this._onMouseEnter=new Z({}),this.onMouseEnter=this._onMouseEnter.event,this._onMouseLeave=new Z({}),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()}},cQ=class extends X{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=YY(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 iQ;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=gZ(gZ({},this._params),{},{params:gZ(gZ({},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()}},lQ=class extends cQ{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 sQ(e.id,e.component)),this._onDidChangeExpansionState=new Z({replay:!0}),this.onDidChangeExpansionState=this._onDidChangeExpansionState.event,this._onDidChange=new Z,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})}),Q(this.element,`mouseenter`,e=>{this.api._onMouseEnter.fire(e)}),Q(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?qY(this.header,`focused`):KY(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(gZ(gZ({},e),{},{api:this.api})),this.headerPart.init(gZ(gZ({},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 gZ(gZ({},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()}}}},uQ=class extends lQ{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 Z,this.onDidDrop=this._onDidDrop.event,this._onUnhandledDragOver=new Z,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:()=>(MY.getInstance().setData([new jY(t,e)],jY.prototype),{dispose:()=>{MY.getInstance().clearData(jY.prototype)}})};this.html5DragSource=eQ.createDragSource(this.header,n),this.pointerDragSource=tQ.createDragSource(this.header,n);let r={acceptedTargetZones:[`top`,`bottom`],overlayModel:{activationSize:{type:`percentage`,value:50}},canDisplayOverlay:(e,t)=>{let n=PY();if(n&&n.paneId!==this.id&&n.viewId===this.accessor.id)return!0;let r=new rQ(e,t,PY,this);return this._onUnhandledDragOver.fire(r),r.isAccepted}};this.target=eQ.createDropTarget(this.element,r),this.pointerTarget=tQ.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=PY();if(t?.viewId!==this.accessor.id){this._onDidDrop.fire(gZ(gZ({},e),{},{panel:this,api:new SZ(this.accessor),getData:PY}));return}let n=this._params.containerApi,r=t.paneId,i=n.getPanel(r);if(!i){this._onDidDrop.fire(gZ(gZ({},e),{},{panel:this,getData:PY,api:new SZ(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)}},dQ=0,fQ=()=>`dv-tabpanel-${dQ++}`,pQ=class extends X{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 IY,this._onDidFocus=new Z,this.onDidFocus=this._onDidFocus.event,this._onDidBlur=new Z,this.onDidBlur=this._onDidBlur.event,this._onDidDimensionsChange=new Z,this.onDidDimensionsChange=this._onDidDimensionsChange.event,this._element=document.createElement(`div`),this._element.className=`dv-content-container`,this._element.tabIndex=-1,this._element.id=fQ(),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 zZ(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=tQ.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)})??FY.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=YY(a);this.focusTracker=e;let t=new X;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()}},mQ=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},hQ=()=>mQ({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`}),gQ=()=>mQ({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`}),_Q=()=>mQ({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`}),vQ=()=>mQ({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`}),yQ=500,bQ=8,xQ=class extends X{constructor(e,t){super(),this.element=e,this.options=t,this._startX=0,this._startY=0,this.addDisposables(Q(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??yQ,n=this.options.tolerance??bQ,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=Q(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=Q(r,`pointerup`,e=>{e.pointerId===this._pointerId&&this._cancelPending()}),this._cancelListener=Q(r,`pointercancel`,e=>{e.pointerId===this._pointerId&&this._cancelPending()})}_installContextMenuGuard(e){let t,n=setTimeout(()=>t?.dispose(),500);t=Q(e,`contextmenu`,e=>{e.preventDefault(),clearTimeout(n),t?.dispose()},{capture:!0})}_installClickGuard(e){let t,n=setTimeout(()=>t?.dispose(),500);t=Q(e,`click`,e=>{eX(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 SQ(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 CQ()?{html5:!1,pointer:!0,pointerHandlesMouse:!0}:{html5:!0,pointer:!0,pointerHandlesMouse:!1}}}function CQ(){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 wQ=0,TQ=()=>`dv-tab-${wQ++}`,EQ=class extends X{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=MY.getInstance(),this._direction=`horizontal`,this._pinIndicator=void 0,this._onPointDown=new Z,this.onPointerDown=this._onPointDown.event,this._onTabClick=new Z,this.onTabClick=this._onTabClick.event,this._onDropped=new Z,this.onDrop=this._onDropped.event,this._onDragStart=new Z,this.onDragStart=this._onDragStart.event,this._onDragEnd=new Z,this.onDragEnd=this._onDragEnd.event;let c=SQ(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=TQ(),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),$(this.element,`dv-inactive-tab`,!0),this._updatePinnedClasses();let u=(e,t)=>{if(this.group.locked)return!1;let n=NY();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=eQ.createDropTarget(this._element,{acceptedTargetZones:[`left`,`right`],overlayModel:this._buildOverlayModel(),canDisplayOverlay:u,getOverrideTarget:()=>n.model.dropTargetContainer?.model}),this.pointerDropTarget=tQ.createDropTarget(this._element,{acceptedTargetZones:[`left`,`right`],overlayModel:this._buildOverlayModel(),canDisplayOverlay:u,getOverrideTarget:()=>n.model.dropTargetContainer?.model});let d={getData:()=>(this.panelTransfer.setData([new AY(this.accessor.id,this.group.id,this.panel.id)],AY.prototype),{dispose:()=>{this.panelTransfer.clearData(AY.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(()=>{$(this.element,`dv-tab--dragging`,!0)})},onDragEnd:e=>{this._onDragEnd.fire(e)}};this.html5DragSource=eQ.createDragSource(this._element,gZ(gZ({},d),{},{disabled:!c.html5})),this.pointerDragSource=tQ.createDragSource(this._element,gZ(gZ({},d),{},{disabled:!c.pointer,touchOnly:!c.pointerHandlesMouse,isCancelled:()=>!SQ(this.accessor.options).pointer})),this.onWillShowOverlay=LY.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:()=>{}},Q(this._element,`dragend`,()=>{$(this.element,`dv-tab--dragging`,!1)}),this.html5DragSource,Q(this._element,`pointerdown`,e=>{this._onPointDown.fire(e)}),Q(this._element,`click`,e=>{this._onTabClick.fire(e)}),Q(this._element,`contextmenu`,e=>{var t;(t=this.accessor.contextMenuService)==null||t.show(this.panel,this.group,e)}),new xQ(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;$(this.element,`dv-tab--pinned`,e),$(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(gQ()),this._element.insertBefore(e,this._element.firstChild),this._pinIndicator=e}else!n&&this._pinIndicator&&(this._pinIndicator.remove(),this._pinIndicator=void 0)}setActive(e){$(this.element,`dv-active-tab`,e),$(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=SQ(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}},DQ=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 X{get group(){return this.groupAccessor()}constructor(e){var t;super(),this.panelTransfer=MY.getInstance(),this._onDragStart=new Z,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=SQ(this.accessor.options);this._element.draggable=r.html5,$(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 AY(this.accessor.id,this.group.id,null)],AY.prototype),{dispose:()=>{this.panelTransfer.clearData(AY.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=eQ.createDragSource(this._element,gZ(gZ({},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=tQ.createDragSource(this._element,gZ(gZ({},a),{},{disabled:!r.pointer,touchOnly:!r.pointerHandlesMouse,touchInitiationDelay:()=>o()?500:250,pressTolerance:()=>o()?1/0:8,isCancelled:()=>!SQ(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 IY,c=()=>{let e=this.getFloatingOverlay();s.value=e?e.onDidStartMoving(()=>{this.pointerDragSource.cancelPending()}):FY.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=SQ(this.accessor.options);this._element.draggable=e.html5,$(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}},kQ=class extends X{get element(){return this._element}constructor(e,t){var n,r,i;super(),this.accessor=e,this.group=t,this._onDrop=new Z,this.onDrop=this._onDrop.event,this._onDragStart=new Z,this.onDragStart=this._onDragStart.event,this._element=document.createElement(`div`),this._element.className=`dv-void-container`,this.addDisposables(this._onDrop,this._onDragStart,Q(this._element,`pointerdown`,()=>{this.accessor.doSetGroupActive(this.group)}),Q(this._element,`pointerdown`,e=>{e.shiftKey&&QY(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=NY();return this.accessor.id===r?.viewId||t.model.canDisplayOverlay(e,n,`header_space`)};this.dropTarget=eQ.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=tQ.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=LY.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)})??FY.NONE)}updateDragAndDropState(){this.dragSource.updateDragAndDropState()}},AQ=class e extends X{get element(){return this._element}get orientation(){return this._orientation}set orientation(e){this._orientation!==e&&(this._scrollOffset=0,this._orientation=e,KY(this._scrollbar,`dv-scrollbar-vertical`,`dv-scrollbar-horizontal`),e===`vertical`?qY(this._scrollbar,`dv-scrollbar-vertical`):qY(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(Q(this.element,`wheel`,t=>{this._scrollOffset+=t.deltaY*e.MouseWheelSpeed,this.scheduleStyleUpdate()}),Q(this._scrollbar,`pointerdown`,e=>{e.preventDefault();let t=this._scrollbar.ownerDocument??document;$(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=()=>{$(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)}),Q(this.element,`scroll`,()=>{this.scheduleStyleUpdate()}),Q(this.scrollableElement,`scroll`,()=>{this._scrollOffset=this._orientation===`horizontal`?this.scrollableElement.scrollLeft:this.scrollableElement.scrollTop,this.scheduleStyleUpdate()}),GY(this.element,()=>{$(this.element,`dv-scrollable-resizing`,!0),this._animationTimer&&clearTimeout(this._animationTimer),this._animationTimer=setTimeout(()=>{clearTimeout(this._animationTimer),$(this.element,`dv-scrollable-resizing`,!1)},500),this.scheduleStyleUpdate()}),FY.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=FX(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}};AQ.MouseWheelSpeed=1;var jQ=`dv-tabs-container--wrap`;function MQ(e,t){return typeof e==`boolean`?e:!!e?.[t]}function NQ(e){return typeof e==`boolean`?e:e?Object.values(e).some(Boolean):!1}var PQ=class extends zY{constructor(e,t,n,r,i){super(),this.nativeEvent=e,this.target=t,this.position=n,this.getData=r,this.group=i}},FQ=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 IQ(e){return!!e.referencePanel}function LQ(e){return!!e.referenceGroup}function RQ(e){return!!e.referencePanel}function zQ(e){return!!e.referenceGroup}var BQ=[{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`}],VQ=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}},HQ;function UQ(){return HQ??=new VQ(BQ,!0),HQ}function WQ(e,t,n){let r=(n??UQ()).resolveValue(t);r===void 0?e.style.removeProperty(`--dv-tab-group-color`):e.style.setProperty(`--dv-tab-group-color`,r)}function GQ(e,t){return(t??UQ()).resolveValue(e)}var KQ=class extends X{get element(){return this._element}constructor(e){super(),this._palette=e,this._onClick=new Z,this.onClick=this._onClick.event,this._onContextMenu=new Z,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 xQ(this._element,{onLongPress:e=>{this._onContextMenu.fire(e)}}),Q(this._element,`click`,e=>{this._onClick.fire(e)}),Q(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){WQ(this._element,e,this._palette),$(this._element,`dv-tab-group-chip--accent-off`,this._palette?.enabled===!1)}updateLabel(e){this._label.textContent=e,$(this._label,`dv-tab-group-chip-label--empty`,!e)}updateCollapsed(e){$(this._element,`dv-tab-group-chip--collapsed`,e)}},qQ=`dv-tab-group-chip-continuation`,JQ=8,YQ=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=qQ,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(jQ);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=GQ(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-JQ/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-JQ/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}}},XQ=class extends YQ{_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=GQ(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)}}},ZQ=class extends YQ{applyShape(e,t,n,r,i,a,o,s){let c=GQ(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`))}},QQ=new Map,$Q=class{get chipRenderers(){return this._chipRenderers}get groupUnderlines(){return this._indicator?.underlines??QQ}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=SQ(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`?ZQ:XQ;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=SQ(this._ctx.accessor.options);e.element.draggable=n.html5;let r=MY.getInstance(),i=()=>(r.setData([new AY(this._ctx.accessor.id,this._ctx.group.id,null,t.id)],AY.prototype),{dispose:()=>{r.clearData(AY.prototype)}}),a=eQ.createDragSource(e.element,{getData:i,disabled:!n.html5,isCancelled:()=>!SQ(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(AY.prototype)};e.element.addEventListener(`dragend`,o,{once:!0});let s=tQ.createDragSource(e.element,{getData:i,disabled:!n.pointer,touchOnly:!n.pointerHandlesMouse,isCancelled:()=>!SQ(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 KQ(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 KQ?a.push(r.onContextMenu(o)):a.push(new xQ(r.element,{onLongPress:o}),Q(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=NY();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=eQ.createDropTarget(r.element,s),l=tQ.createDropTarget(r.element,s),u=t=>{this._callbacks.onChipDrop(e,t)};a.push(c,c.onDrop(u),l,l.onDrop(u));let d=new X(...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($(t.element,`dv-tab--grouped`,s),o){let e=o.panelIds,i=e[0]===n,s=e[e.length-1]===n;$(t.element,`dv-tab--group-first`,i),$(t.element,`dv-tab--group-last`,s),WQ(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 $(t.element,`dv-tab--group-first`,!1),$(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 e$(e,t){return t===`vertical`?e.height:e.width}function t$(e,t){return t===`vertical`?e.top:e.left}function n$(e,t){return t===`vertical`?e.clientY:e.clientX}var r$=class extends X{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(jQ)}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 e$(e,this._direction)}_mainAxisStart(e){return t$(e,this._direction)}_mainAxisCoord(e,t){return n$({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=sX(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=sX(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(gZ({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=NY();e?.tabGroupId&&e.groupId!==this.group.id&&this._animState.sourceTabGroupId!==e.tabGroupId&&(this._animState=null)}_initAnimStateForExternalDrag(){let e=NY();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`,$(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),$(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),$(e,n,!1);else{e.style.setProperty(r,`0px`),$(e,n,!0);let t=()=>{e.style.removeProperty(r),$(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`),$(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`),$(e.chip.element,`dv-tab-group-chip--shifting`,!1);this._tabGroupManager.positionUnderlines()}commitGroupMove(e,t){let n=NY();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)`,$(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)`,$(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)$(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)})}},i$=class extends X{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 WY(this._tabsList);this._observerDisposable.value=new X(e,e.onDidChange(e=>{let t=e.hasScrollX||e.hasScrollY;this.toggleDropdown({reset:!t}),this._applyPinnedSticky(),this._tabGroupManager.groupUnderlines.size>0&&this._tabGroupManager.positionUnderlines()}),Q(this._tabsList,`scroll`,()=>{this.toggleDropdown({reset:!1}),this._applyPinnedSticky(),this._tabGroupManager.groupUnderlines.size>0&&this._tabGroupManager.positionUnderlines()}))}else this._observerDisposable.value=FY.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 X(Q(e,`dragover`,e=>{this._animState&&e.preventDefault()}),Q(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),KY(this._tabsList,`dv-horizontal`,`dv-vertical`),e===`vertical`?qY(this._tabsList,`dv-tabs-container-vertical`,`dv-vertical`):(KY(this._tabsList,`dv-tabs-container-vertical`),qY(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 IY,this._pointerActivation=new IY,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 Z,this.onTabDragStart=this._onTabDragStart.event,this._onDrop=new Z,this.onDrop=this._onDrop.event,this._onWillShowOverlay=new Z,this.onWillShowOverlay=this._onWillShowOverlay.event,this._onOverflowTabsChange=new Z,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 AQ(this._tabsList),this._scrollbar.orientation=this.direction,this._element=this._scrollbar.element,this.addDisposables(this._scrollbar)),this._tabGroupManager=new $Q({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 r$(this);let r=tQ.createDropTarget(this._tabsList,{acceptedTargetZones:[`center`],canDisplayOverlay:()=>!1,isHitTestTransparent:()=>{let e=NY();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,UZ.getInstance().onDragEnd(e=>{this._reorder.handlePointerDragEnd(e)}),UZ.getInstance().onDragMove(e=>{this._reorder.handlePointerDragMove(e.clientX,e.clientY)}),Q(this.element,`pointerdown`,e=>{e.defaultPrevented||e.button===0&&this.accessor.doSetGroupActive(this.group)}),Q(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}),Q(this._tabsList,`keydown`,e=>{this._onKeyDown(e)}),Q(this._tabsList,`dragover`,e=>{this._reorder.processDragOver(e.clientX,e.clientY)&&e.preventDefault()},!0),Q(this._tabsList,`dragleave`,e=>{this._reorder.processDragLeave(e.relatedTarget)},!0),Q(this._tabsList,`dragend`,()=>{this._reorder.resetDragAnimation()}),Q(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(gZ({event:e},r)),this.runFlipAnimation(a,n.sourceTabId,i===-1,{from:Math.min(i,r.index),to:Math.max(i,r.index)})},!0),FY.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(!SQ(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 EQ(e,this.accessor,this.group);n.setContent(e.view.tab),this._direction!==`horizontal`&&n.setDirection(this._direction);let r={value:n,disposable:new X(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=e$(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:t$(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`,$(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=NY(),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 DQ(e,{kind:`tab`,panel:this.group.activePanel,api:this.accessor.api,group:this.group,getData:NY}))}))};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&&!hX(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&&!hX(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&&!hX(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=e$(a,this._direction);for(let t of e.panelIds){let e=this._tabMap.get(t);e&&(o+=e$(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:e$(a,this._direction),cursorOffsetFromDragStart:n$(n,this._direction)-t$(a,this._direction),sourceGapSize:o,containerStart:t$(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`,$(e.value.element,`dv-tab--dragging`,!0));let n=this._tabGroupManager.chipRenderers.get(e.id);n&&(n.chip.element.style.transition=`none`,$(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=NY();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 a$(){let e=document.createElement(`div`);e.className=`dv-tabs-overflow-dropdown-default`;let t=document.createElement(`span`);t.textContent=``;let n=vQ();return e.appendChild(n),e.appendChild(t),{element:e,update:e=>{t.textContent=`${e.tabs}`}}}var o$=class extends X{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`?(qY(this._element,`dv-groupview-header-vertical`),qY(this.rightActionsContainer,`dv-right-actions-container-vertical`),this.tabs.direction=e):(KY(this._element,`dv-groupview-header-vertical`),KY(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 IY,this._onDrop=new Z,this.onDrop=this._onDrop.event,this._onGroupDragStart=new Z,this.onGroupDragStart=this._onGroupDragStart.event,this._onWillShowOverlay=new Z,this.onWillShowOverlay=this._onWillShowOverlay.event,this._element=document.createElement(`div`),this._element.className=`dv-tabs-and-actions-container`,$(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 i$(t,e,{showTabsOverflowControl:!e.options.disableTabsOverflowList}),this.voidContainer=new kQ(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 DQ(e,{kind:`header_space`,panel:this.group.activePanel,api:this.accessor.api,group:this.group,getData:NY}))}),Q(this.leftActionsContainer,`dragleave`,e=>{let t=e.relatedTarget;!this.leftActionsContainer.contains(t)&&!this._element.contains(t)&&this.tabs.clearExternalAnimState()}),Q(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())}),Q(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)),$(this._element,`dv-tabs-and-actions-container--pinned-row`,!!e))}setDropIndexResolver(e){this._dropIndexResolver=e}resolveDropIndex(e,t){return this._dropIndexResolver(e,t)}updateClassnames(){$(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=a$();o.update({tabs:i}),this.dropdownPart=o,a.appendChild(o.element),this.rightActionsContainer.prepend(a),this._dropdownDisposable.value=new X(FY.from(()=>{var e,t;a.remove(),(e=this.dropdownPart)==null||(t=e.dispose)==null||t.call(e),this.dropdownPart=null}),Q(a,`pointerdown`,e=>{e.preventDefault()},{capture:!0}),Q(a,`click`,e=>{let t=yX(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 X,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`,WQ(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=gQ();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=FY.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`);$(d,`dv-tab`,!0),$(d,`dv-active-tab`,t.api.isActive),$(d,`dv-inactive-tab`,!t.api.isActive),r&&$(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()}},s$=class extends X{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 Z,this.onDidChange=this._onDidChange.event,this._onDidPanelChange=new Z,this.onDidPanelChange=this._onDidPanelChange.event,this._onDidCollapseChange=new Z,this.onDidCollapseChange=this._onDidCollapseChange.event,this._onDidDestroy=new Z,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()}},c$=class extends RY{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()}},l$=class extends c${get kind(){return this._kind}constructor(e){super(e),this._kind=e.kind}},u$=class extends X{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,$(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=bX(e);return t?JY(t,e):!1}get headerPosition(){return this._headerPosition??`top`}set headerPosition(e){this._headerPosition=e,this.invalidateHeaderSize(),KY(this.container,`dv-groupview-header-top`,`dv-groupview-header-bottom`,`dv-groupview-header-left`,`dv-groupview-header-right`),qY(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,$(this.container,`dv-groupview-floating`,!1),$(this.container,`dv-groupview-popout`,!1),$(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`]),$(this.container,`dv-groupview-floating`,!0);break;case`popout`:t([`top`,`bottom`,`left`,`right`,`center`]),$(this.container,`dv-groupview-popout`,!0);break;case`edge`:t([`center`]),$(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 Z,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 Z,this.onMove=this._onMove.event,this._onDidDrop=new Z,this.onDidDrop=this._onDidDrop.event,this._onWillDrop=new Z,this.onWillDrop=this._onWillDrop.event,this._onWillShowOverlay=new Z,this.onWillShowOverlay=this._onWillShowOverlay.event,this._onTabDragStart=new Z,this.onTabDragStart=this._onTabDragStart.event,this._onGroupDragStart=new Z,this.onGroupDragStart=this._onGroupDragStart.event,this._onDidAddPanel=new Z,this.onDidAddPanel=this._onDidAddPanel.event,this._onDidPanelTitleChange=new Z,this.onDidPanelTitleChange=this._onDidPanelTitleChange.event,this._onDidPanelParametersChange=new Z,this.onDidPanelParametersChange=this._onDidPanelParametersChange.event,this._onDidRemovePanel=new Z,this.onDidRemovePanel=this._onDidRemovePanel.event,this._onDidActivePanelChange=new Z,this.onDidActivePanelChange=this._onDidActivePanelChange.event,this._onUnhandledDragOver=new Z,this.onUnhandledDragOver=this._onUnhandledDragOver.event,this._tabGroups=[],this._tabGroupMap=new Map,this._panelToTabGroup=new Map,this._tabGroupIdCounter=0,this._pendingTabGroupUpdate=!1,this._onDidCreateTabGroup=new Z,this.onDidCreateTabGroup=this._onDidCreateTabGroup.event,this._onDidDestroyTabGroup=new Z,this.onDidDestroyTabGroup=this._onDidDestroyTabGroup.event,this._onDidAddPanelToTabGroup=new Z,this.onDidAddPanelToTabGroup=this._onDidAddPanelToTabGroup.event,this._onDidRemovePanelFromTabGroup=new Z,this.onDidRemovePanelFromTabGroup=this._onDidRemovePanelFromTabGroup.event,this._onDidTabGroupChange=new Z,this.onDidTabGroupChange=this._onDidTabGroupChange.event,this._onDidTabGroupCollapsedChange=new Z,this.onDidTabGroupCollapsedChange=this._onDidTabGroupCollapsedChange.event,$(this.container,`dv-groupview`,!0),this.container.setAttribute(`role`,`region`),this._api=new wZ(this.accessor),this.tabsContainer=new o$(this.accessor,this.groupPanel),this.contentContainer=new pQ(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(GY(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=NY()?.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 DQ(e,{kind:`content`,panel:this.activePanel,api:this._api,group:this.groupPanel,getData:NY}))}),this.contentContainer.pointerDropTarget.onWillShowOverlay(e=>{this._onWillShowOverlay.fire(new DQ(e,{kind:`content`,panel:this.activePanel,api:this._api,group:this.groupPanel,getData:NY}))}),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 s$(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 X(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,$(this.container,`dv-active-group`,e),$(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 X(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,Q(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,NY,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=NY();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 l$({nativeEvent:t,position:n,panel:o,index:r,getData:()=>NY(),kind:a(),group:this.groupPanel,api:this._api});if(this._onWillDrop.fire(s),s.defaultPrevented)return;let c=NY();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 c$({nativeEvent:t,position:n,panel:o,index:r,getData:()=>NY(),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()}},d$=class extends aQ{constructor(e,t,n){super(e,t),this._onDidConstraintsChangeInternal=new Z,this.onDidConstraintsChangeInternal=this._onDidConstraintsChangeInternal.event,this._onDidConstraintsChange=new Z,this.onDidConstraintsChange=this._onDidConstraintsChange.event,this._onDidSizeChange=new Z,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)}},f$=class extends cQ{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 d$(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 Z,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 gZ(gZ({},e),{},{minimumHeight:n(this.minimumHeight),maximumHeight:t(this.maximumHeight),minimumWidth:n(this.minimumWidth),maximumWidth:t(this.maximumWidth),snap:this.snap,priority:this.priority})}},p$=`dockview: DockviewGroupPanelApiImpl not initialized`,m$=class extends d${get location(){if(!this._group)throw Error(p$);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(p$);return this._group.locked}set locked(e){if(!this._group)throw Error(p$);this._group.locked=e}constructor(e,t){super(e,`__dockviewgroup__`),this.accessor=t,this._isApplyingSize=!1,this._onDidLocationChange=new Z,this.onDidLocationChange=this._onDidLocationChange.event,this._onDidActivePanelChange=new Z,this.onDidActivePanelChange=this._onDidActivePanelChange.event,this._onDidCollapsedChange=new Z,this.onDidCollapsedChange=this._onDidCollapsedChange.event,this._onDidPeekChange=new Z,this.onDidPeekChange=this._onDidPeekChange.event,this._onDidHeaderDirectionChange=new Z,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=gZ({},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(p$);this._group.model.headerPosition=e}getHeaderPosition(){if(!this._group)throw Error(p$);return this._group.model.headerPosition}moveTo(e){if(!this._group)throw Error(p$);this.accessor.withOrigin(`api`,()=>{let t=e.group??this.accessor.addGroup({direction:LZ(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(p$);this.location.type===`grid`&&this.accessor.maximizeGroup(this._group)}isMaximized(){if(!this._group)throw Error(p$);return this.accessor.isMaximizedGroup(this._group)}exitMaximized(){if(!this._group)throw Error(p$);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}},h$=100,g$=100,_$=class extends f${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??g$,minimumWidth:n.constraints?.minimumWidth??h$,maximumHeight:n.constraints?.maximumHeight,maximumWidth:n.constraints?.maximumWidth},new m$(t,e)),this._explicitConstraints={},this.api.initialize(this),this._model=new u$(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()}},v$={name:`abyss`,className:`dockview-theme-abyss`,colorScheme:`dark`,tabGroupIndicator:`none`},y$=class extends d${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 Z,this.onDidTitleChange=this._onDidTitleChange.event,this._onDidChangePinned=new Z,this.onDidChangePinned=this._onDidChangePinned.event,this._onDidActiveGroupChange=new Z,this.onDidActiveGroupChange=this._onDidActiveGroupChange.event,this._onDidGroupChange=new Z,this.onDidGroupChange=this._onDidGroupChange.event,this._onDidRendererChange=new Z,this.onDidRendererChange=this._onDidRendererChange.event,this._onDidLocationChange=new Z,this.onDidLocationChange=this._onDidLocationChange.event,this.groupEventsDisposable=new IY,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 X(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}))}))}},b$=class extends X{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 y$(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(gZ(gZ({},e),{},{api:this.api,containerApi:this.containerApi})),this.setTitle(e.title)}focus(){let e=new iQ;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=gZ(gZ({},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()}},x$=class extends X{get element(){return this._element}constructor(){super(),this._messages=yZ,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=hQ();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??yZ,this.addDisposables(e.api.onDidTitleChange(e=>{this._title=e.title,this.render()}),Q(this.action,`pointerdown`,e=>{e.preventDefault()}),Q(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())}},S$=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(gZ(gZ({},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(gZ(gZ({},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 x$;console.warn(`dockview: tabComponent '${t}' was not found. falling back to the default tab.`)}return new x$}},C$=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 S$(this.accessor,n,o,s),l=new b$(n,o,s,this.accessor,new wZ(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}},w$=class extends X{get element(){return this._element}constructor(){super(),this._element=document.createElement(`div`),this._element.className=`dv-watermark`}init(e){}},T$=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 E$(e){return e.width>0&&e.height>0}var D$=class e extends X{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 Z,this.onDidChange=this._onDidChange.event,this._onDidChangeEnd=new Z,this.onDidChangeEnd=this._onDidChangeEnd.event,this._onDidStartMoving=new Z,this.onDidStartMoving=this._onDidStartMoving.event,this._dragMove=new IY,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&&($(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(gZ(gZ(gZ(gZ({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})),T$.push(this._element)}setVisible(e){e!==this.isVisible&&(this._isVisible=e,$(this.element,`dv-hidden`,!this.isVisible))}bringToFront(){T$.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(!E$(t)||!E$(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=FX(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=FX(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=FX(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=FX(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,E$(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,$(this._element,`dv-resize-container-dragging`,!1),this._dragMove.value=FY.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=uX();if(e&&typeof t==`number`&&typeof e.setPointerCapture==`function`)try{e.setPointerCapture(t)}catch{}let s=()=>{$(this._element,`dv-resize-container-dragging`,!1),this._dragMove.value=FY.NONE,this._onDidChangeEnd.fire()};this._dragMove.value=new X({dispose:()=>{if(o.release(),e&&typeof t==`number`&&typeof e.releasePointerCapture==`function`)try{e.releasePointerCapture(t)}catch{}}},Q(globalThis.window,`pointermove`,e=>{if(this._dragCancelled)return;let t=this.options.container.getBoundingClientRect(),n=e.clientX-t.left,o=e.clientY-t.top;$(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=FX(u,-l,f),h=FX(t.height-s.height-u,-l,f),g=FX(d,-c,p),_=FX(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())}),Q(globalThis.window,`pointerup`,s),Q(globalThis.window,`pointercancel`,s))};this.addDisposables(Q(e,`pointerdown`,t=>{t.defaultPrevented?t.preventDefault():$Y(t)||n(e,t.pointerId)}),Q(this.options.content,`pointerdown`,e=>{e.defaultPrevented||$Y(e)||e.shiftKey&&n(this.options.content,e.pointerId)}),Q(this.options.content,`pointerdown`,()=>{T$.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 IY;this.addDisposables(r,Q(n,`pointerdown`,i=>{i.preventDefault();let a=null,o=uX(),s=i.pointerId;if(typeof n.setPointerCapture==`function`)try{n.setPointerCapture(s)}catch{}let c=()=>{r.dispose(),this._onDidChangeEnd.fire()};r.value=new X(Q(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=FX(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=FX(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=FX(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=FX(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{}}},Q(globalThis.window,`pointerup`,c),Q(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(){T$.destroy(this._element),this._element.remove(),super.dispose()}};D$.MINIMUM_HEIGHT=20,D$.MINIMUM_WIDTH=20;var O$=class extends X{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 Z,this.onDragStart=this._onDragStart.event,this._group=t,this._element=document.createElement(`div`),this._element.className=`dv-floating-titlebar`,this.addDisposables(this._onDragStart,Q(this._element,`pointerdown`,()=>{this.accessor.doSetGroupActive(this._group)}),Q(this._element,`pointerdown`,e=>{e.shiftKey&&QY(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 k$(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 A$=new Set([`AdvancedOverflow`,`AutoEdgeGroup`,`AutoHideEdgeGroup`,`DndCompass`,`KeyboardDocking`,`KeyboardNavigation`,`LayoutHistory`,`License`,`MultiRowTabs`,`PinnedTabs`,`SmartGuides`]),j$=new Set;function M$(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 A$.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 N$(e,t){let n=`${e}|${(t===void 0?[]:[].concat(t)).join(`|`)}`;j$.has(n)||(j$.add(n),console.error(M$(e,t)))}function P$(e,t,n){if(e!==void 0)return e;N$(t,n)}var F$=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()}},I$=[];function L$(){return[...I$]}var R$=[{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=>NQ(e.autoHideEdgeGroups)},{optionKey:`dockToEdgeGroups`,reason:`dockToEdgeGroups`,moduleName:`AutoEdgeGroup`,when:e=>NQ(e.dockToEdgeGroups)},{optionKey:`dndCompass`,reason:`dndCompass`,moduleName:`DndCompass`,when:e=>!!e.dndCompass},{optionKey:`keyboardNavigation`,reason:`keyboardNavigation`,moduleName:`KeyboardNavigation`,when:e=>!!e.keyboardNavigation}];function z$(e,t){let n=new Map;for(let r of R$){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)N$(e,t)}var B$={left:100,top:100,width:300,height:300},V$=class extends X{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 Z,this.onDidChangeAnchorGroup=this._onDidChangeAnchorGroup.event,this._group=e,this.addDisposables(this._onDidChangeAnchorGroup,t,{dispose:()=>this.gridview.dispose()})}position(e){this.overlay.setBounds(e)}},H$=class{get floatingGroups(){return this._floatingGroups}constructor(e){this._floatingGroups=[],this._host=e}add(e,t,n){let r=new V$(e,t,n),i=new X((()=>{let e=-1,t=-1;return GY(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 IY,s=e=>{a(e),o.value=new X(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(),PX(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()}},U$=k$({name:`FloatingGroup`,serviceKey:`floatingGroupService`,create:e=>new H$(e)}),W$=class{constructor(e){this._entries=[],this._restorationCleanups=new Set,this._restorationPromise=Promise.resolve(),this._onDidRemove=new Z,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){PX(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`?gZ(gZ({},i),{},{data:n.data[0].data}):gZ(gZ({},i),{},{grid:t})})}disposeAll(){for(let e of[...this._entries])e.disposable.dispose()}dispose(){this.cancelPendingRestorations(),this.disposeAll(),this._onDidRemove.dispose()}},G$=k$({name:`PopoutWindow`,serviceKey:`popoutWindowService`,create:e=>new W$(e)}),K$=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`,cX(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()}},q$=k$({name:`Watermark`,serviceKey:`watermarkService`,create:e=>new K$(e),init:(e,t)=>(t.update(),new X(LY.any(e.onDidAdd,e.onDidRemove)(()=>{t.update()}),e.onDidViewVisibilityChangeMicroTaskQueue(()=>{t.update()})))}),J$=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()}},Y$=k$({name:`EdgeGroup`,serviceKey:`edgeGroupService`,create:()=>new J$}),X$={activationSize:{type:`pixels`,value:10},size:{type:`pixels`,value:20}},Z$={activationSize:{type:`pixels`,value:32},size:{type:`pixels`,value:20}};function Q$(e,t){return typeof e.dndEdges==`object`&&e.dndEdges!==null?e.dndEdges:t&&NQ(e.dockToEdgeGroups)?Z$:X$}var $$=class{constructor(e){this._host=e;let t=(t,n)=>{let r=NY();return r?r.viewId===e.id?n!==`center`||e.isGridEmpty():!1:n===`center`&&!e.isGridEmpty()?!1:e.dispatchUnhandledDragOver(t,n)},n=Q$(e.options,!1);this._html5Target=eQ.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=tQ.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=LY.any(this._html5Target.onWillShowOverlay,this._pointerTarget.onWillShowOverlay),this.onDrop=LY.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=Q$({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()}},e1=k$({name:`RootDropTarget`,serviceKey:`rootDropTargetService`,create:e=>new $$(e),init:(e,t)=>(t.setOptions(e.options),FY.NONE)}),t1={left:`createLeftHeaderActionComponent`,right:`createRightHeaderActionComponent`,prefix:`createPrefixHeaderActionComponent`},n1=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 IY,right:new IY,prefix:new IY},this._perGroup.set(e,t)),t}_refreshSlot(e,t,n){let r=this._host.options[t1[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)}},r1=k$({name:`HeaderActions`,serviceKey:`headerActionsService`,create:e=>new n1(e),init:(e,t)=>new X(e.onDidRemoveGroup(e=>{t.disposeGroup(e)}))}),i1=e=>e===`load`||e===`clear`;function a1(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 o1=class extends X{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:a1(t,`polite`),assertive:a1(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=>{i1(e.kind)&&this._suppressDepth++}),e.onDidMutateLayout(e=>{i1(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:a1(r,`polite`),assertive:a1(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=bZ(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)}}},s1=k$({name:`LiveRegion`,serviceKey:`liveRegionService`,create:e=>new o1(e)}),c1=30,l1=-10,u1=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:c1,offsetY:l1,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),FY.from(()=>n.clearOverlay())}dispose(){}},d1=k$({name:`AdvancedDnD`,serviceKey:`advancedDnDService`,create:e=>new u1(e)}),f1=class{constructor(e){this._host=e}attachToGroup(e){return new X(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(){}},p1=k$({name:`TabGroupChips`,serviceKey:`tabGroupChipsService`,create:e=>new f1(e),init:(e,t)=>{let n=new Map;return new X(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 m1(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=yX(e);return i?.style.zIndex?`calc(${i.style.zIndex} * 2)`:void 0}var h1=0,g1=()=>`dv-ctx-menu-item-${h1++}`;function _1(e){return typeof e==`object`}function v1(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 y1(){let e=document.createElement(`div`);return e.className=`dv-context-menu-separator`,e.setAttribute(`role`,`separator`),e}function b1(){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 x1(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),b1()||requestAnimationFrame(()=>{n.focus(),n.select()}),t}function S1(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 C1=class{constructor(e){this.accessor=e}buildMaximizeItem(e,t){let n=e.api.isMaximized();return v1(n?`Restore`:`Maximize`,t,n?()=>e.api.exitMaximized():()=>e.api.maximize(),!n&&e.api.location.type!==`grid`)}buildCollapseItem(e,t){return v1(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:g1(),component:t.component});s&&(a.addDisposables(s),s.init(gZ(gZ({},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 y1();case`close`:return v1(`Close`,r,()=>t.api.close());case`closeOthers`:return v1(`Close Others`,r,()=>{n.panels.filter(e=>e!==t).forEach(e=>e.api.close())});case`closeAll`:return v1(`Close All`,r,()=>{[...n.panels].forEach(e=>e.api.close())});case`closeLeft`:{let e=n.panels.indexOf(t);return v1(`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 v1(`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 v1(`Float`,r,()=>this.accessor.api.addFloatingGroup(t),t.api.location.type===`floating`);case`popout`:return v1(`Open in New Window`,r,()=>{this.accessor.api.addPopoutGroup(t)},t.api.location.type===`popout`);case`pin`:return v1(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(v1(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 X,s=document.createElement(`div`);s.className=`dv-context-menu`,s.setAttribute(`role`,`menu`);try{for(let n of r){if(_1(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:m1(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 X,s=document.createElement(`div`);s.className=`dv-context-menu`,s.setAttribute(`role`,`menu`);try{for(let n of r)n===`separator`?s.appendChild(y1()):n===`rename`?s.appendChild(x1(e)):n===`colorPicker`?s.appendChild(S1(e,this.accessor.tabGroupColorPalette)):n===`collapse`?s.appendChild(this.buildCollapseItem(e,a)):n===`close`?s.appendChild(v1(`Close All`,a,()=>{t.panels.filter(t=>e.containsPanel(t.id)).forEach(e=>e.api.close())})):_1(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:m1(n.target,t)},{onClose:()=>o.dispose()})}},w1=[U$,G$,q$,Y$,e1,r1,s1,d1,p1,k$({name:`ContextMenu`,serviceKey:`contextMenuService`,create:e=>new C1(e)})],T1=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=iX(e);return this.cache.set(e,{rect:n,frameId:this.currentFrameId}),n}invalidate(){this.currentFrameId++}scheduleFrameUpdate(){this.rafId||=requestAnimationFrame(()=>{this.currentFrameId++,this.rafId=null})}},E1=-1;function D1(e){let t=e.group.api;return t.location.type===`edge`&&t.isCollapsed()}function O1(){let e=document.createElement(`div`);return e.tabIndex=-1,e}function k1(e,t,n){let r=`${n}px`;e[t]!==r&&(e[t]=r)}var A1=class extends X{constructor(e,t){super(),this.element=e,this.accessor=t,this.map={},this._disposed=!1,this._generation=0,this.positionCache=new T1,this.addDisposables(FY.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=O1();e.className=`dv-render-overlay`,e.style.visibility=`hidden`,this.map[n.api.id]={panel:n,disposable:FY.NONE,destroy:FY.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=D1(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||(k1(o.style,`width`,e.width),k1(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=E1;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=D1(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,k1(o.style,`left`,f),k1(o.style,`top`,p),k1(o.style,`width`,m),k1(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=``;$(o,`dv-render-overlay-float`,n.group.api.location.type===`floating`)});t.pendingUpdate===E1&&(t.pendingUpdate=i)},u=()=>{let e=!this.map[n.api.id]?.forceVisible&&D1(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 IY,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=FY.from(()=>i.disconnect()),i.observe(t,{attributeFilter:[`aria-level`],attributes:!0}),r()}):o.style.zIndex=``},p=new X(d,new TZ(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()})??FY.NONE,r.onDidDimensionsChange(e=>{c(e)}),n.api.onDidLocationChange(()=>{f()}));return this.map[n.api.id].destroy=FY.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}},j1=class extends X{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 M1(e){if(!e.matchMedia)return!1;let t=e.matchMedia(`(pointer: coarse)`).matches,n=e.matchMedia(`(pointer: fine)`).matches;return t&&!n}function N1(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 X,u=t=>e.isInside?e.isInside(t):eX(t,e.elements?.call(e)??[]);if((r||i.length>0)&&l.addDisposables(Q(t,`keydown`,t=>{(r&&t.key===`Escape`||i.includes(t.key))&&e.onDismiss()},n)),(a||e.onInsidePointerDown)&&l.addDisposables(Q(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(Q(t,`resize`,()=>{M1(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(nX(n,r())):eX(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 tX(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,Q(e,`focusin`,a,n))};l.addDisposables(Q(t,`focusin`,e=>{s(),a(e)},n),{dispose:()=>{for(let[,e]of o)e.dispose();o.clear()}}),s()}return l}var P1=class extends X{constructor(e,t=globalThis.window){super(),this._active=null,this._activeDisposable=new IY,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(FY.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 X(N1({window:this._window,onDismiss:()=>this.close(),elements:()=>this._active?[this._active]:[],keys:[`Enter`],pointerDownGraceMs:200,resize:!0}),n?.onClose?FY.from(n.onClose):FY.NONE),this._window.requestAnimationFrame(()=>{vX(r,this._root)})}close(){this._active&&=(this._active.remove(),this._activeDisposable.dispose(),null)}},F1=class extends X{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(FY.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}},I1=[`left`,`right`,`top`,`bottom`];function L1(e){return e===`left`||e===`right`}var R1={marginShare:0,size:1/0},z1=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=R1){this._onDidChange=new Z,this.onDidChange=this._onDidChange.event,this.snap=!1,this.priority=`low`,this._isCollapsed=!1,this._isVisible=!0,this._tabSizeDisposables=new X,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(GY(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()}},B1=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 Z,this.onDidChange=this._onDidChange.event}layout(e,t){this._layoutDockview(t,e)}setVisible(e){}dispose(){this._onDidChange.dispose()}},V1=class{get element(){return this._element}constructor(e,t=0){this._onDidChange=new Z,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 HX(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()}},H1=class{constructor(e,t,n,r=0,i=35){this._disposables=new X,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 B1(t,n);this._middleColumn=new V1(a,r),this._outerSplitview=new HX(this._shellElement,{orientation:`HORIZONTAL`,proportionalLayout:!1,margin:r}),this._middleIndex=0,this._outerSplitview.addView(this._middleColumn,{type:`distribute`},0),this._disposables.addDisposables(GY(this._shellElement,e=>{if(!this._shellElement.offsetParent||!aX(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 z1(gZ(gZ({},t),{},{collapsedSize:t.collapsedSize??this._defaultCollapsedSize}),n,L1(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||!aX(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 L1(e)?this._leftView!==void 0&&this._rightView!==void 0:this._topView!==void 0&&this._bottomView!==void 0}_axisFor(e){return L1(e)?this._outerSplitview:this._middleColumn.axis}_applyThemeSizing(){for(let e of I1){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 I1){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 I1){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 U1(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 W1(e){return new VQ(e.tabGroupColors??BQ,e.tabGroupAccent!==`off`)}function G1(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 K1=()=>({dispose:()=>{}}),q1=K1,J1=100,Y1=class extends uZ{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 SQ(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=P$(this._smartGuidesService,`SmartGuides`,`api.setSmartGuidesEnabled`))==null||t.setEnabled(e)}updateSmartGuidesOptions(e){var t;(t=P$(this._smartGuidesService,`SmartGuides`,`api.updateSmartGuidesOptions`))==null||t.updateOptions(e)}get onDidSnapFloat(){return this._smartGuidesService?.onDidSnapFloat??K1}get onDidSnapTogether(){return this._smartGuidesService?.onDidSnapTogether??K1}_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?gZ(gZ({},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 l$({nativeEvent:e,position:t,panel:void 0,api:this._api,group:void 0,getData:NY,kind:`edge`});if(this._onWillDrop.fire(n),n.defaultPrevented)return;let r=NY();r?this.moveGroupOrPanel({from:{groupId:r.groupId,panelId:r.panelId??void 0},to:{group:this.orthogonalize(t),position:`center`}}):this._onDidDrop.fire(new c$({nativeEvent:e,position:t,panel:void 0,api:this._api,group:void 0,getData:NY}))}get headerActionsService(){return this._moduleRegistry.services.headerActionsService}get _layoutHistoryService(){return this._moduleRegistry.services.layoutHistoryService}undo(){var e;(e=P$(this._layoutHistoryService,`LayoutHistory`,`api.undo`))==null||e.undo()}redo(){var e;(e=P$(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??q1}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,NY);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=QX(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)??FY.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=IX(),this._deserializer=new C$(this),this._moduleRegistry=new F$,this._onWillDragPanel=new Z,this.onWillDragPanel=this._onWillDragPanel.event,this._onWillDragGroup=new Z,this.onWillDragGroup=this._onWillDragGroup.event,this._onDidDrop=new Z,this.onDidDrop=this._onDidDrop.event,this._onWillDrop=new Z,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 Z,this.onWillMutateLayout=this._onWillMutateLayout.event,this._onDidMutateLayout=new Z,this.onDidMutateLayout=this._onDidMutateLayout.event,this._onWillShowOverlay=new Z,this.onWillShowOverlay=this._onWillShowOverlay.event,this._onUnhandledDragOver=new Z,this.onUnhandledDragOver=this._onUnhandledDragOver.event,this._onDidRemovePanel=new Z,this.onDidRemovePanel=this._onDidRemovePanel.event,this._onDidAddPanel=new Z,this.onDidAddPanel=this._onDidAddPanel.event,this._onDidPopoutGroupSizeChange=new Z,this.onDidPopoutGroupSizeChange=this._onDidPopoutGroupSizeChange.event,this._onDidPopoutGroupPositionChange=new Z,this.onDidPopoutGroupPositionChange=this._onDidPopoutGroupPositionChange.event,this._onDidAddPopoutGroup=new Z,this.onDidAddPopoutGroup=this._onDidAddPopoutGroup.event,this._onDidRemovePopoutGroup=new Z,this.onDidRemovePopoutGroup=this._onDidRemovePopoutGroup.event,this._onDidChangePopouts=new Z,this.onDidChangePopouts=this._onDidChangePopouts.event,this._onDidOpenPopoutWindowFail=new Z,this.onDidOpenPopoutWindowFail=this._onDidOpenPopoutWindowFail.event,this._onWillClosePopoutWindow=new Z,this.onWillClosePopoutWindow=this._onWillClosePopoutWindow.event,this._onDidStartFloatingGroupDrag=new Z,this.onDidStartFloatingGroupDrag=this._onDidStartFloatingGroupDrag.event,this._onDidEndFloatingGroupDrag=new Z,this.onDidEndFloatingGroupDrag=this._onDidEndFloatingGroupDrag.event,this._onDidLayoutFromJSON=new Z,this.onDidLayoutFromJSON=this._onDidLayoutFromJSON.event,this._onDidActivePanelChange=new Z({replay:!0}),this.onDidActivePanelChange=this._onDidActivePanelChange.event,this._onDidPanelPinnedChange=new Z,this.onDidPanelPinnedChange=this._onDidPanelPinnedChange.event,this._onDidMovePanel=new Z,this.onDidMovePanel=this._onDidMovePanel.event,this._onDidCreateTabGroup=new Z,this.onDidCreateTabGroup=this._onDidCreateTabGroup.event,this._onDidDestroyTabGroup=new Z,this.onDidDestroyTabGroup=this._onDidDestroyTabGroup.event,this._onDidAddPanelToTabGroup=new Z,this.onDidAddPanelToTabGroup=this._onDidAddPanelToTabGroup.event,this._onDidRemovePanelFromTabGroup=new Z,this.onDidRemovePanelFromTabGroup=this._onDidRemovePanelFromTabGroup.event,this._onDidTabGroupChange=new Z,this.onDidTabGroupChange=this._onDidTabGroupChange.event,this._onDidTabGroupCollapsedChange=new Z,this.onDidTabGroupCollapsedChange=this._onDidTabGroupCollapsedChange.event,this._onDidMaximizedGroupChange=new Z,this.onDidMaximizedGroupChange=this._onDidMaximizedGroupChange.event,this._inShellLayout=!1,this._onDidRemoveGroup=new Z,this.onDidRemoveGroup=this._onDidRemoveGroup.event,this._onDidEdgeGroupAutoHideChange=new Z,this.onDidEdgeGroupAutoHideChange=this._onDidEdgeGroupAutoHideChange.event,this._onDidAddGroup=new Z,this.onDidAddGroup=this._onDidAddGroup.event,this._onDidOptionsChange=new Z,this.onDidOptionsChange=this._onDidOptionsChange.event,this._onDidActiveGroupChange=new Z,this.onDidActiveGroupChange=this._onDidActiveGroupChange.event,this._peekingGroups=new Set,this._moving=!1,this._options=t,this._tabGroupColorPalette=W1(t);let n=t.modules??[...w1,...L$()];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 P1(this.element),this.addDisposables(this.popupService,FY.from(()=>{for(let e of this._openingPopoutWindows)e.dispose();this._openingPopoutWindows.clear()})),this._api=new wZ(this),this.disableResizing=!0,this.element.remove(),this._shellManager=new H1(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 pX(this._shellManager.element),this.rootDropTargetContainer=new F1(this._shellManager.element,{disabled:!0}),this.floatingDropTargetContainer=new F1(this._shellManager.element,{disabled:!1}),this.overlayRenderContainer=new A1(this._shellManager.element,this),this._floatingOverlayHost=document.createElement(`div`),this._floatingOverlayHost.className=`dv-floating-overlay-host`,this._shellManager.element.appendChild(this._floatingOverlayHost),$(this.gridview.element,`dv-dockview`,!0),$(this.element,`dv-debug`,!!t.debug),this.updateTheme(),t.debug&&this.addDisposables(new j1(this)),this.addDisposables(FY.from(()=>this._pendingLocationChanges.clear()),this.rootDropTargetContainer,this.floatingDropTargetContainer,Q(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,LY.any(this.onDidPopoutGroupSizeChange,this.onDidPopoutGroupPositionChange)(()=>{this.fireLayoutChange(`geometry`)}),LY.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})}),LY.any(this.onDidAddPanel,this.onDidRemovePanel,this.onDidAddGroup,this.onDidRemove,this.onDidRemoveGroup,this.onDidMovePanel)(()=>{this._bufferOnDidLayoutChange.fire(`structure`)}),this.onDidActivePanelChange(()=>{this._bufferOnDidLayoutChange.fire(`activePanel`)}),FY.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 DQ(e,{kind:`edge`,panel:void 0,api:this._api,group:void 0,getData:NY}))}),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=P$(this._popoutWindowService,`PopoutWindow`,`api.addPopoutGroup`);if(!r||e instanceof _$&&e.model.location.type===`edge`)return Promise.resolve(!1);if(e instanceof b$&&e.group.size===1&&this.closeEmptyGroups)return this.addPopoutGroup(e.group,t);let i=fX(this.gridview.element),a=this.element;function o(){if(t?.position)return t.position;let n=(e instanceof _$?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 OX(`${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 X(d,d.onDidClose(()=>{f.dispose()}));this._openingPopoutWindows.add(f);let p=DX(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&&(U1(e),this._onDidOpenPopoutWindowFail.fire(e)),!1}let i=t?.referenceGroup??(e instanceof b$?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 A1(u,this);s.model.renderContainer=m;let h=t?.overridePopoutGridview??this.createNestedGridview();t?.overridePopoutGridview?h.locked=this.gridview.locked:h.addView(s,VX.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 b$){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(()=>G1({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 F1(b,{disabled:this.rootDropTargetContainer.disabled});n.appendChild(b),s.model.dropTargetContainer=x;let S=new P1(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 IY;f.addDisposables(w);let T=e=>{w.value=new X(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=gX(d.window);f.addDisposables(k,_X(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})}),Q(d.window,`resize`,()=>{h.layout(d.window.innerWidth,d.window.innerHeight)}),m,FY.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(U1(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(()=>G1({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(()=>G1({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(!P$(this._floatingGroupService,`FloatingGroup`,`api.addFloatingGroup`)||e instanceof _$&&e.model.location.type===`edge`)return;let n,r=[];if(e instanceof b$){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(()=>G1({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=B$.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=B$.top,e.width=typeof t.width==`number`?Math.max(t.width,0):B$.width,e.height=typeof t.height==`number`?Math.max(t.height,0):B$.height,e}return{left:typeof t?.x==`number`?Math.max(t.x,0):B$.left,top:typeof t?.y==`number`?Math.max(t.y,0):B$.top,width:typeof t?.width==`number`?Math.max(t.width,0):B$.width,height:typeof t?.height==`number`?Math.max(t.height,0):B$.height}}let a=i(),o=this.createNestedGridview();o.addView(n,VX.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 aZ(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=P$(this._floatingGroupService,`FloatingGroup`,`api.addFloatingGroup`);if(!a)return;let o=(i?.dragHandle??this.options.floatingGroupDragHandle??`titlebar`)===`titlebar`?new O$(this,t):void 0,s=new D$(gZ(gZ({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,FY.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=gZ(gZ({},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??BQ),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){z$(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(M$(`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=L1(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 X(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=P$(this._moduleRegistry.services.autoHideEdgeGroupService,`AutoHideEdgeGroup`,`api.pinEdgeGroup`))==null||t.pin(e)}autoHideEdgeGroup(e){var t;(t=P$(this._moduleRegistry.services.autoHideEdgeGroupService,`AutoHideEdgeGroup`,`api.autoHideEdgeGroup`))==null||t.autoHide(e)}peekEdgeGroup(e,t){var n;(n=P$(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=P$(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&&MQ(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=QX(e.element),i=(t?n.previous(r):n.next(r)).view;if(n===this.gridview||i!==e)return i}let r=[],i=e=>{rZ(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(FY.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=P$(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?P$(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(gZ(gZ({},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(IQ(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(LQ(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(IZ(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=lZ(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,gZ(gZ({},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=QX(t.element),l=$X(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,gZ(gZ({},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 w$}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&&(RQ(t)||zQ(t)||typeof t.direction==`string`))return this._doAddGroup(gZ(gZ({},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(RQ(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(zQ(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(RQ(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(zQ(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(IZ(e.direction),e);return e.skipSetActive||this.doSetGroupAndPanelActive(t),t}let n=lZ(e.direction||`within`),r=this.getGridviewForGroup(t),i=QX(t.element),a=$X(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 CX(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=QX(t.element),s=$X(n.orientation,a,i);if(o.size<2&&!this.keepEmptyGroups(e)){if(o===t)return;let[e,c]=kX(s);if(o.api.location.type===`grid`&&n===this.gridview){let[n,i]=kX(QX(o.element));if((this.options.dropSizing!==`distribute`||o===t)&&AX(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=$X(n.orientation,QX(t.element),i),c=this.createGroupAtLocation(s,this.sizingForDrop(QX(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=QX(t.element),d=$X(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=$X(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`?QX(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=$X(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=QX(t.element),a=QX(n.element)}catch{return!1}return i.length===0||a.length===0?!1:AX(kX(i)[0],kX(a)[0])&&tZ(e.orientation,a)===eZ(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(QX(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=QX(n.element),s=$X(a.orientation,o,r),c;c=e&&this.options.dropSizing!==`distribute`?eZ(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<J1;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 ${J1} 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 _$(this,t,e);if(n.init({params:{},accessor:this}),!this._groups.has(n.id)){let e=new X(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 S$(this,e.id,n,r),a=new b$(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`?VX.Distribute:VX.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:nZ(n)}updateTheme(){var e,t;let n=this._options.theme??v$;(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`;$(this.element,`dv-tab-group-indicator-none`,o),this._shellManager&&$(this._shellManager.element,`dv-tab-group-indicator-none`,o);for(let e of this.groups)e.model.updateTabGroups()}},X1=class extends uZ{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 Z,this.onDidLayoutFromJSON=this._onDidLayoutfromJSON.event,this._onDidRemoveGroup=new Z,this.onDidRemoveGroup=this._onDidRemoveGroup.event,this._onDidAddGroup=new Z,this.onDidAddGroup=this._onDidAddGroup.event,this._onDidActiveGroupChange=new Z,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=gZ(gZ({},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(QX(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=lZ(t.direction);if(r===`center`)throw Error(`${r} not supported as an option`);let i=QX(n.element),a=$X(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=lZ(e.position.direction);if(r===`center`)throw Error(`${r} not supported as an option`);{let e=QX(n.element);t=$X(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 X(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=QX(e.element),[a,o]=kX($X(this.gridview.orientation,i,n)),[s,c]=kX(QX(r.element));if(AX(s,a)){this.gridview.moveView(s,c,o);return}let l=this.doRemoveGroup(r,{skipActive:!0,skipDispose:!0}),u=QX(e.element),d=$X(this.gridview.orientation,u,n);this.doAddGroup(l,d)}removeGroup(e){super.removeGroup(e)}dispose(){super.dispose(),this._onDidLayoutfromJSON.dispose()}},Z1=class extends sZ{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 X(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 IY,this._panels=new Map,this._onDidLayoutfromJSON=new Z,this.onDidLayoutFromJSON=this._onDidLayoutfromJSON.event,this._onDidAddView=new Z,this.onDidAddView=this._onDidAddView.event,this._onDidRemoveView=new Z,this.onDidRemoveView=this._onDidRemoveView.event,this._onDidLayoutChange=new Z,this.onDidLayoutChange=this._onDidLayoutChange.event,this.element.style.height=`100%`,this.element.style.width=`100%`,this._classNames=new pX(this.element),this._classNames.setClassNames(t.className??``),e.appendChild(this.element),this._options=t,this.splitview=new HX(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=gZ(gZ({},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:VX.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 gZ({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 HX(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,VX.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()}},Q1=class extends X{get element(){return this._element}constructor(){super(),this._expandedIcon=_Q(),this._collapsedIcon=vQ(),this.disposable=new IY,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(Q(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;$(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()}},$1=IX(),e0=22,t0=0,n0=2**53-1,r0=class extends uQ{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}},i0=class extends sZ{get id(){return this._id}get panels(){return this.paneview.getPanes()}set paneview(e){this._paneview=e,this._disposable.value=new X(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=$1.next(),this._disposable=new IY,this._viewDisposables=new Map,this._onDidLayoutfromJSON=new Z,this.onDidLayoutFromJSON=this._onDidLayoutfromJSON.event,this._onDidLayoutChange=new Z,this.onDidLayoutChange=this._onDidLayoutChange.event,this._onDidDrop=new Z,this.onDidDrop=this._onDidDrop.event,this._onDidAddView=new Z,this.onDidAddView=this._onDidAddView.event,this._onDidRemoveView=new Z,this.onDidRemoveView=this._onDidRemoveView.event,this._onUnhandledDragOver=new Z,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 pX(this.element),this._classNames.setClassNames(t.className??``),e.appendChild(this.element),this._options=t,this.paneview=new WX(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=gZ(gZ({},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 Q1;let r=new r0({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??e0,minimumBodySize:t0,maximumBodySize:n0});this.doAddPanel(r);let i=typeof e.size==`number`?e.size:VX.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 SZ(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 gZ({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 WX(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 Q1;let a=new r0({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??e0,minimumBodySize:e.minimumSize??t0,maximumBodySize:e.maximumSize??n0});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 SZ(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 WX(this.element,{orientation:`VERTICAL`}),this.layout(e,t)}doAddPanel(e){let t=new X(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()}},a0=class extends cQ{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 oQ(e,t)),this._evaluatedMinimumSize=0,this._evaluatedMaximumSize=1/0,this._minimumSize=0,this._maximumSize=1/0,this._snap=!1,this._onDidChange=new Z,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 gZ(gZ({},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 o0(e,t){return new Y1(e,t).api}function s0(e,t){return new xZ(new Z1(e,t))}function c0(e,t){return new CZ(new X1(e,t))}function l0(e,t){return new SZ(new i0(e,t))}function u0(e){"@babel/helpers - typeof";return u0=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},u0(e)}function d0(e,t){if(u0(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(u0(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function f0(e){var t=d0(e,`string`);return u0(t)==`symbol`?t:t+``}function p0(e,t,n){return(t=f0(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function m0(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 h0(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?m0(Object(n),!0).forEach(function(t){p0(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):m0(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var g0=(e,t)=>{let[,n]=U.useState(0),r=U.useRef(e.componentProps);return U.useImperativeHandle(t,()=>({update:e=>{r.current=h0(h0({},r.current),e),n(e=>e+1)}}),[]),U.createElement(e.component,r.current)};g0.displayName=`DockviewReactJsBridge`;var _0=(()=>{let e=1;return{next:()=>`dockview_react_portal_key_${(e++).toString()}`}})(),v0=U.createContext({}),y0=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=h0(h0({},this._initialProps),e)}createPortal(){if(this.disposed)throw Error(`invalid operation: resource is already disposed`);if(!x0(this.component))throw Error(`Dockview: Only React.memo(...), React.ForwardRef(...) and functional components are accepted as components`);let e=U.createElement(U.forwardRef(g0),{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?U.createElement(v0.Provider,{value:this.context},e):e,n=lp.createPortal(t,this.parent,_0.next());this.ref={portal:n,disposable:this.portalStore.addPortal(n)}}dispose(){var e;(e=this.ref)==null||e.disposable.dispose(),this.disposed=!0}},b0=()=>{let[e,t]=U.useState([]);return U.useDebugValue(`Portal count: ${e.length}`),[e,U.useCallback(e=>{t(t=>[...t,e]);let n=!1;return FY.from(()=>{if(n)throw Error(`invalid operation: resource already disposed`);n=!0,t(t=>t.filter(t=>t!==e))})},[])]};function x0(e){return typeof e==`function`||!!e?.$$typeof}function S0(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(),FY.from(()=>i.disconnect())}var C0=Number.parseInt(`19.3.1`,10)>=18;function w0(e,t,n){let r=U.useRef(void 0);U.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()};C0&&a.isConnected&&typeof MutationObserver<`u`?r.current=S0(a,e):e()}},[])}function T0(e){let t=U.useRef({instance:void 0,values:new Map});return U.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 E0=class{get element(){return this._element}constructor(e,t,n){this.id=e,this.component=t,this.reactPortalStore=n,this._onDidFocus=new Z,this.onDidFocus=this._onDidFocus.event,this._onDidBlur=new Z,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 y0(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()}},D0=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 y0(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()}},O0=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 y0(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()}},k0=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 IY,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 X(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 y0(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}})}},A0=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 y0(this._element,this.reactPortalStore,this.component,e)}dispose(){var e;(e=this.part)==null||e.dispose()}},j0=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 y0(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()}},M0=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 y0(this._element,this.reactPortalStore,this.component,{group:e.group,api:e.api})}dispose(){var e;(e=this.part)==null||e.dispose()}};function N0(e,t){return e?n=>new k0(e,t,n):void 0}var P0=`props.defaultTabComponent`;function F0(e){return FQ.reduce((t,n)=>(n in e&&(t[n]=e[n]),t),{})}var I0=U.forwardRef((e,t)=>{let n=U.useRef(null),r=U.useRef(void 0),[i,a]=b0(),o=T0(r);U.useImperativeHandle(t,()=>n.current,[]);let s=U.useRef({});return U.useEffect(()=>{let t={};FQ.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},FQ.map(t=>e[t])),w0(n,r,t=>{let n=h0({},e.tabComponents);e.defaultTabComponent&&(n[P0]=e.defaultTabComponent);let r={createLeftHeaderActionComponent:N0(e.leftHeaderActionsComponent,{addPortal:a}),createRightHeaderActionComponent:N0(e.rightHeaderActionsComponent,{addPortal:a}),createPrefixHeaderActionComponent:N0(e.prefixHeaderActionsComponent,{addPortal:a}),createComponent:t=>new E0(t.id,e.components[t.name],{addPortal:a}),createTabComponent(e){return new D0(e.id,n[e.name],{addPortal:a})},createWatermarkComponent:e.watermarkComponent?()=>new O0(`watermark`,e.watermarkComponent,{addPortal:a}):void 0,defaultTabComponent:e.defaultTabComponent?P0:void 0,createContextMenuItemComponent:e=>{if(e.component)return new A0(e.id,e.component,{addPortal:a})}},i=F0(e);if(e.tabGroupChipComponent){let t=e.tabGroupChipComponent;i.createTabGroupChipComponent=()=>new j0(t,{addPortal:a})}if(e.groupDragGhostComponent){let t=e.groupDragGhostComponent;i.createGroupDragGhostComponent=()=>new M0(t,{addPortal:a})}let o=o0(t,h0(h0({},i),r)),{clientWidth:s,clientHeight:c}=t;return o.layout(s,c),e.onReady&&e.onReady({api:o}),o}),U.useEffect(()=>{if(!r.current)return()=>{};let t=r.current.onDidDrop(t=>{e.onDidDrop&&e.onDidDrop(t)});return()=>{t.dispose()}},[e.onDidDrop]),U.useEffect(()=>{if(!r.current)return()=>{};let t=r.current.onWillDrop(t=>{e.onWillDrop&&e.onWillDrop(t)});return()=>{t.dispose()}},[e.onWillDrop]),U.useEffect(()=>{r.current&&!o({tabGroupChipComponent:e.tabGroupChipComponent})&&r.current.updateOptions({createTabGroupChipComponent:e.tabGroupChipComponent?()=>new j0(e.tabGroupChipComponent,{addPortal:a}):void 0})},[e.tabGroupChipComponent]),U.useEffect(()=>{r.current&&!o({groupDragGhostComponent:e.groupDragGhostComponent})&&r.current.updateOptions({createGroupDragGhostComponent:e.groupDragGhostComponent?()=>new M0(e.groupDragGhostComponent,{addPortal:a}):void 0})},[e.groupDragGhostComponent]),U.useEffect(()=>{r.current&&!o({components:e.components})&&r.current.updateOptions({createComponent:t=>new E0(t.id,e.components[t.name],{addPortal:a})})},[e.components]),U.useEffect(()=>{if(!r.current||o({tabComponents:e.tabComponents,defaultTabComponent:e.defaultTabComponent}))return;let t=h0({},e.tabComponents);e.defaultTabComponent&&(t[P0]=e.defaultTabComponent),r.current.updateOptions({defaultTabComponent:e.defaultTabComponent?P0:void 0,createTabComponent(e){return new D0(e.id,t[e.name],{addPortal:a})}})},[e.tabComponents,e.defaultTabComponent]),U.useEffect(()=>{r.current&&!o({watermarkComponent:e.watermarkComponent})&&r.current.updateOptions({createWatermarkComponent:e.watermarkComponent?()=>new O0(`watermark`,e.watermarkComponent,{addPortal:a}):void 0})},[e.watermarkComponent]),U.useEffect(()=>{r.current&&!o({rightHeaderActionsComponent:e.rightHeaderActionsComponent})&&r.current.updateOptions({createRightHeaderActionComponent:N0(e.rightHeaderActionsComponent,{addPortal:a})})},[e.rightHeaderActionsComponent]),U.useEffect(()=>{r.current&&!o({leftHeaderActionsComponent:e.leftHeaderActionsComponent})&&r.current.updateOptions({createLeftHeaderActionComponent:N0(e.leftHeaderActionsComponent,{addPortal:a})})},[e.leftHeaderActionsComponent]),U.useEffect(()=>{r.current&&!o({prefixHeaderActionsComponent:e.prefixHeaderActionsComponent})&&r.current.updateOptions({createPrefixHeaderActionComponent:N0(e.prefixHeaderActionsComponent,{addPortal:a})})},[e.prefixHeaderActionsComponent]),U.createElement(`div`,{style:{height:`100%`,width:`100%`},ref:n},i)});I0.displayName=`DockviewComponent`;var L0=class extends a0{constructor(e,t,n,r){super(e,t),this.reactComponent=n,this.reactPortalStore=r}getComponent(){return new y0(this.element,this.reactPortalStore,this.reactComponent,{params:this._params?.params??{},api:this.api,containerApi:new xZ(this._params.accessor)})}};function R0(e){return UX.reduce((t,n)=>(n in e&&(t[n]=e[n]),t),{})}var z0=U.forwardRef((e,t)=>{let n=U.useRef(null),r=U.useRef(void 0),[i,a]=b0(),o=T0(r);U.useImperativeHandle(t,()=>n.current,[]);let s=U.useRef({});return U.useEffect(()=>{let t={};UX.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},UX.map(t=>e[t])),w0(n,r,t=>{let n=s0(t,h0(h0({},R0(e)),{createComponent:t=>new L0(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}),U.useEffect(()=>{r.current&&!o({components:e.components})&&r.current.updateOptions({createComponent:t=>new L0(t.id,t.name,e.components[t.name],{addPortal:a})})},[e.components]),U.createElement(`div`,{style:{height:`100%`,width:`100%`},ref:n},i)});z0.displayName=`SplitviewComponent`;var B0=class extends f${constructor(e,t,n,r){super(e,t),this.reactComponent=n,this.reactPortalStore=r}getComponent(){return new y0(this.element,this.reactPortalStore,this.reactComponent,{params:this._params?.params??{},api:this.api,containerApi:new CZ(this._params.accessor)})}};function V0(e){return oZ.reduce((t,n)=>(n in e&&(t[n]=e[n]),t),{})}var H0=U.forwardRef((e,t)=>{let n=U.useRef(null),r=U.useRef(void 0),[i,a]=b0(),o=T0(r);U.useImperativeHandle(t,()=>n.current,[]);let s=U.useRef({});return U.useEffect(()=>{let t={};oZ.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},oZ.map(t=>e[t])),w0(n,r,t=>{let n=c0(t,h0(h0({},V0(e)),{createComponent:t=>new B0(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}),U.useEffect(()=>{r.current&&!o({components:e.components})&&r.current.updateOptions({createComponent:t=>new B0(t.id,t.name,e.components[t.name],{addPortal:a})})},[e.components]),U.createElement(`div`,{style:{height:`100%`,width:`100%`},ref:n},i)});H0.displayName=`GridviewComponent`;var U0=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 y0(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 W0(e){return nQ.reduce((t,n)=>(n in e&&(t[n]=e[n]),t),{})}var G0=U.forwardRef((e,t)=>{let n=U.useRef(null),r=U.useRef(void 0),[i,a]=b0(),o=T0(r);U.useImperativeHandle(t,()=>n.current,[]);let s=U.useRef({});return U.useEffect(()=>{let t={};nQ.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},nQ.map(t=>e[t])),w0(n,r,t=>{let n=e.headerComponents??{},r=l0(t,h0(h0({},W0(e)),{createComponent:t=>new U0(t.id,e.components[t.name],{addPortal:a}),createHeaderComponent:e=>new U0(e.id,n[e.name],{addPortal:a})})),{clientWidth:i,clientHeight:o}=t;return r.layout(i,o),e.onReady&&e.onReady({api:r}),r}),U.useEffect(()=>{r.current&&!o({components:e.components})&&r.current.updateOptions({createComponent:t=>new U0(t.id,e.components[t.name],{addPortal:a})})},[e.components]),U.useEffect(()=>{if(!r.current||o({headerComponents:e.headerComponents}))return;let t=e.headerComponents??{};r.current.updateOptions({createHeaderComponent:e=>new U0(e.id,t[e.name],{addPortal:a})})},[e.headerComponents]),U.useEffect(()=>{if(!r.current)return()=>{};let t=r.current.onDidDrop(t=>{e.onDidDrop&&e.onDidDrop(t)});return()=>{t.dispose()}},[e.onDidDrop]),U.createElement(`div`,{style:{height:`100%`,width:`100%`},ref:n},i)});G0.displayName=`PaneviewComponent`;var K0={dock:`_dock_psx21_10`,tab:`_tab_psx21_155`,buttons:`_buttons_psx21_178`,body:`_body_psx21_189`,heading:`_heading_psx21_197`,none:`_none_psx21_209`},q0=({label:e,shortcut:t,onClick:n,children:r})=>{let i=Xk();return(0,q.jsx)(xb,{"aria-keyshortcuts":Wk(t,i),keys:Uk(t,i),label:e,onClick:n,children:r})},J0=({group:e,activePanel:t,workspace:n})=>{vb(n.view);let r=t?.title??`panel`,i=t!==void 0&&SY(t.id)?t.id:void 0,a=e.api.location.type===`floating`,o=e.api.isMaximized();return(0,q.jsxs)(`div`,{className:K0.buttons,children:[(0,q.jsx)(q0,{label:`Minimize ${r}`,onClick:()=>{n.minimize(i)},shortcut:qk.minimize,children:(0,q.jsx)(vy,{})}),a?null:(0,q.jsx)(q0,{label:o?`Restore ${r}`:`Maximize ${r}`,onClick:()=>{n.toggleMaximize(e)},shortcut:qk.maximize,children:o?(0,q.jsx)(by,{}):(0,q.jsx)(yy,{})}),(0,q.jsx)(q0,{label:a?`Dock ${r}`:`Float ${r}`,onClick:()=>{n.toggleFloat(e)},shortcut:qk.float,children:a?(0,q.jsx)(Sy,{}):(0,q.jsx)(xy,{})}),(0,q.jsx)(q0,{label:`Close ${r}`,onClick:()=>{n.close(i)},shortcut:qk.close,children:(0,q.jsx)(sy,{})})]})},Y0=e=>{let t=(0,U.use)(fL);return t===null?null:(0,q.jsx)(J0,{...e,workspace:t})},X0=6,Z0=({api:e})=>{let t=SY(e.id)?CY(e.id).Icon:null;return(0,q.jsxs)(`span`,{className:K0.tab,children:[t===null?null:(0,q.jsx)(t,{}),e.title]})},Q0=()=>(0,q.jsx)(`div`,{className:K0.none,children:(0,q.jsx)(qD,{title:`No panels open.`,children:`Reopen one from Window, or press the command palette's keys.`})}),$0=Object.fromEntries(xY.map(({id:e,title:t,Body:n})=>[e,()=>(0,q.jsxs)(`div`,{className:K0.body,children:[(0,q.jsx)(`h2`,{className:K0.heading,children:t}),(0,q.jsx)(n,{})]})])),e2={name:`ork`,className:K0.dock??``,gap:X0,dndOverlayMounting:`relative`,dndPanelOverlay:`group`,dndTabIndicator:`line`},t2=({workspace:e})=>{let t=(0,U.useCallback)(({api:t})=>{e.attach(t)},[e]);return(0,U.useEffect)(()=>()=>{e.detach()},[e]),(0,q.jsx)(I0,{announcer:({message:t})=>{e.announceFromDock(t)},components:$0,defaultTabComponent:Z0,disableTabsOverflowList:!0,onReady:t,rightHeaderActionsComponent:Y0,theme:e2,watermarkComponent:Q0})},n2=`(min-width: 64rem)`,r2=(e,t,n)=>{let r=e?.panels??[],i=e?.activePanel?.id;return{wide:n,open:xY.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&&SY(i)?i:null,floating:e?.activePanel?.group.api.location.type===`floating`,maximized:e?.hasMaximizedGroup()??!1}},i2=(e,t)=>JSON.stringify(e)===JSON.stringify(t),a2=e=>`stack-${e}`,o2=e=>`rail-${e}`,s2=e=>{document.querySelector(`#${e}`)?.focus()},c2=({workspace:e})=>{let{minimized:t}=vb(e.view);return t.length===0?null:(0,q.jsx)(`nav`,{"aria-label":`Minimized panels`,className:$k.rail,children:t.map(t=>{let{title:n,Icon:r}=CY(t);return(0,q.jsx)(xb,{id:o2(t),label:`Restore ${n}`,onClick:()=>{e.restore(t)},children:(0,q.jsx)(r,{})},t)})})},l2=({workspace:e})=>{let{folded:t}=vb(e.view);return(0,q.jsx)(`div`,{className:$k.stack,children:xY.map(({id:n,title:r,Icon:i,Body:a})=>{let o=!t.includes(n),s=`${a2(n)}-body`;return(0,q.jsxs)(`section`,{"aria-labelledby":a2(n),className:$k.stacked,children:[(0,q.jsx)(`h2`,{className:$k.stackedHeading,children:(0,q.jsxs)(`button`,{"aria-controls":o?s:void 0,"aria-expanded":o,className:$k.stackedButton,id:a2(n),onClick:()=>{e.toggleFold(n)},type:`button`,children:[o?(0,q.jsx)(ly,{}):(0,q.jsx)(uy,{}),(0,q.jsx)(i,{}),r]})}),o?(0,q.jsx)(`div`,{className:$k.stackedBody,id:s,children:(0,q.jsx)(a,{})}):null]},n)})})},u2=e=>{(0,U.useEffect)(()=>{let t=window.matchMedia(n2),n=()=>{e.setWide(t.matches)};return n(),t.addEventListener(`change`,n),()=>{t.removeEventListener(`change`,n)}},[e])},d2=({workspace:e})=>{let{wide:t}=vb(e.view);return u2(e),(0,q.jsx)(`main`,{className:$k.middle,children:t?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(c2,{workspace:e}),(0,q.jsx)(`div`,{className:$k.dockArea,children:(0,q.jsx)(t2,{workspace:e})})]}):(0,q.jsx)(l2,{workspace:e})})},f2=`ork-new-version-action`,p2=(e,t,n)=>e?.version===t&&n-Date.parse(e.at)<864e5,m2=(e,t,n)=>{let{job:r}=e;if(r!==null)return r.state===`running`?{kind:`running`,latest:r.latest}:p2(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}},h2=({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=m2(e,r,i);if(o!==void 0)return o;let{newer:s,releaseNotes:c}=e;return s===null||c===null||p2(r,s,i)?null:{kind:`newer`,newer:s,current:e.current,releaseNotes:c}},g2=e=>e===null?`none`:`${e.kind}:${`newer`in e?e.newer:`latest`in e?e.latest:e.server}`,_2=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,v2=e=>e.kind===`newer`?e.newer:e.kind===`installed`||e.kind===`failed`?e.latest:null,y2={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`},b2=({latest:e,current:t})=>(0,q.jsxs)(`p`,{className:y2.line,children:[`Ork`,` `,(0,q.jsx)(`span`,{className:y2.version,"data-new":``,children:e}),` `,`is out (you have `,(0,q.jsx)(`span`,{className:y2.version,children:t}),`).`]}),x2=({url:e,version:t,children:n})=>(0,q.jsxs)(`a`,{className:y2.link,href:e,rel:`noreferrer`,target:`_blank`,children:[n,t===void 0?null:(0,q.jsx)(lk,{children:` in ${t}`}),(0,q.jsx)(Fy,{}),(0,q.jsx)(lk,{children:` (opens in a new tab)`})]}),S2=8,C2=({ids:e})=>{if(e.length===0)return null;let t=e.slice(0,S2).map(e=>`\`${e.slice(0,8)}\``),n=e.length-S2,r=n>0?`${t.join(`, `)} and ${String(n)} more`:t.join(`, `);return(0,q.jsxs)(`p`,{className:y2.alert,"data-tone":`note`,children:[(0,q.jsx)(`span`,{className:y2.alertIcon,children:(0,q.jsx)(My,{})}),(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:`Running now: ${r}. Their next sessions would start from the new install; upgrading after they finish is safer.`})})]})},w2=()=>{let e=document.activeElement;return e===null||e===document.body||e.getAttribute(`role`)===`dialog`},T2=({tone:e,text:t,ref:n})=>{let r=(0,U.useRef)(null),i=n??r;return(0,U.useLayoutEffect)(()=>{i.current?.focus()},[i]),(0,U.useEffect)(()=>{let e=requestAnimationFrame(()=>{e=requestAnimationFrame(()=>{w2()&&i.current?.focus()})});return()=>{cancelAnimationFrame(e)}},[i]),(0,q.jsxs)(`h3`,{className:y2.heading,ref:i,tabIndex:-1,children:[e===void 0?null:(0,q.jsx)(`span`,{className:y2.glyph,"data-tone":e,children:e===`succeeded`?(0,q.jsx)(Mj,{}):(0,q.jsx)(Fj,{})}),(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:t})})]})},E2=({since:e})=>{let t=kW(!0),n=Math.max(0,Math.floor((t-e)/1e3));return(0,q.jsx)(`span`,{"aria-hidden":`true`,className:y2.clock,children:`${String(n)} s`})},D2=({text:e,icon:t=!1})=>e===null?null:(0,q.jsxs)(`p`,{className:y2.alert,role:`alert`,children:[t?(0,q.jsx)(My,{}):null,(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:e})})]}),O2=({why:e,id:t})=>(0,q.jsx)(`output`,{className:y2.note,id:t,children:(0,q.jsx)(r_,{text:e??``})}),k2=({note:e,children:t})=>(0,q.jsxs)(`div`,{className:y2.foot,children:[e===void 0?null:(0,q.jsx)(`p`,{className:y2.note,children:(0,q.jsx)(r_,{text:e})}),(0,q.jsx)(`div`,{className:y2.actions,children:t})]}),A2=`Dismissed for a day. Upgrade Ork… is in Commands.`,j2=(e,t,n,r)=>{let i=(0,U.useRef)(null),a=g2(e);(0,U.useEffect)(()=>{if(!t)return;let o=i.current;if(i.current=a,o===null||o===a||n)return;let s=_2(e);s!==null&&r.announce(s)},[e,a,t,n,r])},M2=()=>{let[e,t]=(0,U.useState)(Date.now);return(0,U.useEffect)(()=>{let e=setInterval(()=>{t(Date.now())},6e4);return()=>{clearInterval(e)}},[]),e},N2=()=>{window.location.reload()},P2={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}},F2=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}.`,I2=({banner:e,onOpen:t})=>{let n=P2[e.kind];return(0,q.jsxs)(q.Fragment,{children:[e.kind===`newer`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(b2,{current:e.current,latest:e.newer}),(0,q.jsx)(x2,{url:e.releaseNotes,version:e.newer,children:`What changed`})]}):(0,q.jsx)(`p`,{className:y2.line,children:(0,q.jsx)(r_,{text:F2(e)})}),(0,q.jsx)(`span`,{className:y2.spacer}),(0,q.jsx)(Y,{cli:e.kind===`newer`?`ork upgrade`:void 0,id:f2,onClick:()=>{n.opens===null?N2():t(n.opens)},variant:n.primary?`primary`:`default`,children:n.label})]})},L2=({workspace:e})=>{let{version:t,connection:n,preferences:r}=ob(),i=vb(t.info),a=vb(n),o=vb(r.value),s=vb(t.dialog),c=M2(),l=h2({info:i,connection:a,pageVersion:t.pageVersion,dismissed:o.updateDismissed,now:c});j2(l,i!==null&&a.server!==null,s!==null,e);let u=l===null?null:v2(l);return(0,q.jsx)(`div`,{className:y2.slot,children:l===null?null:(0,q.jsxs)(`section`,{"aria-label":`New version`,className:y2.banner,children:[(0,q.jsx)(`span`,{className:y2.icon,children:(0,q.jsx)(Qy,{})}),(0,q.jsx)(I2,{banner:l,onOpen:t.openDialog}),u===null?null:(0,q.jsx)(xb,{label:`Dismiss for a day`,onClick:()=>{r.update({updateDismissed:{version:u,at:new Date().toISOString()}}),e.announce(A2),e.focusPanels()},children:(0,q.jsx)(sy,{})})]})})},R2=e=>e===null?`Asking the npm registry for the latest version…`:`Asking the registry at \`${e}\` for the latest version…`,z2=({plan:e})=>(0,q.jsxs)(`dl`,{className:y2.facts,children:[(0,q.jsx)(`dt`,{className:y2.factName,children:`Installed with`}),(0,q.jsx)(`dd`,{className:y2.factValue,children:e.installer?.label??`Ork couldn't tell`}),e.kind===`command`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`dt`,{className:y2.factName,children:`Command`}),(0,q.jsx)(`dd`,{className:y2.factValue,children:(0,q.jsx)(`section`,{"aria-label":`Command to run`,children:(0,q.jsx)(cC,{command:e.command.join(` `)})})})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`dt`,{className:y2.factName,children:`What to do`}),(0,q.jsxs)(`dd`,{className:y2.factValue,children:[(0,q.jsx)(`p`,{className:y2.adviceWords,children:(0,q.jsx)(r_,{text:e.words})}),e.commands.map(e=>(0,q.jsx)(cC,{command:e},e))]})]})]}),B2=({plan:e})=>(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(b2,{current:e.current,latest:e.latest}),(0,q.jsxs)(`p`,{className:y2.message,children:[`What changed:`,` `,(0,q.jsx)(x2,{url:e.releaseNotes,children:e.releaseNotes})]}),(0,q.jsx)(z2,{plan:e}),e.kind===`advice`?(0,q.jsx)(`p`,{className:y2.note,children:`Ork runs only a package manager's own command from here; this one is yours to run.`}):null,(0,q.jsx)(C2,{ids:e.running}),(0,q.jsx)(`p`,{className:y2.note,children:`The same, in a terminal:`}),(0,q.jsx)(cC,{command:`ork upgrade`})]}),V2=({step:e,registry:t})=>e.step===`plan`?(0,q.jsx)(B2,{plan:e.plan}):e.step===`latest`?(0,q.jsx)(T2,{text:`Ork ${e.current} is the latest version.`,tone:`succeeded`}):e.step===`unreachable`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(D2,{icon:!0,text:e.words}),(0,q.jsx)(`p`,{className:y2.message,children:`Nothing was changed.`})]}):(0,q.jsx)(`section`,{"aria-busy":`true`,"aria-label":`Asking`,className:y2.message,children:(0,q.jsx)(r_,{text:R2(t)})}),H2=({step:e,registry:t,first:n,onClose:r,onAsk:i,onUpgrade:a})=>{let o=(0,U.useId)();(0,U.useEffect)(()=>{w2()&&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,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(V2,{registry:t,step:e}),(0,q.jsx)(D2,{text:e.step===`plan`?e.refusal:null}),(0,q.jsx)(O2,{id:o,why:e.step===`checking`?`Asking the registry…`:null}),(0,q.jsxs)(k2,{note:c?`It runs on this machine as you.`:void 0,children:[e.step===`unreachable`?(0,q.jsx)(Y,{onClick:()=>{n.current?.focus(),i()},variant:`ghost`,children:`Try again`},`again`):null,(0,q.jsx)(Y,{disabled:l,focusableWhenDisabled:!0,onClick:r,ref:n,variant:c?`ghost`:`default`,children:c?`Cancel`:`Close`},`close`),c?(0,q.jsx)(Y,{"aria-describedby":o,disabled:!s||l,focusableWhenDisabled:!0,onClick:a,variant:`primary`,children:e.step===`plan`?`Upgrade to ${e.plan.latest}`:`Upgrade`},`upgrade`):null]})]})},U2=({step:e,port:t})=>{let n=(0,U.useId)();return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(T2,{text:"Restarting `ork ui`…"}),(0,q.jsx)(`p`,{className:y2.message,children:e.step===`back`?`Ork ${e.version} is up. Reloading…`:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(r_,{text:`Waiting for \`ork ui\` to come back on port ${t}. Runs keep running.`}),` `,(0,q.jsx)(E2,{since:e.since})]})}),(0,q.jsx)(O2,{id:n,why:"It closes once `ork ui` is back."}),(0,q.jsx)(k2,{children:(0,q.jsx)(Y,{"aria-describedby":n,disabled:!0,focusableWhenDisabled:!0,children:`Close`})})]})},W2=({step:e,port:t,onClose:n,onKeepWaiting:r,onReload:i})=>{if(e.step===`restarting`||e.step===`back`)return(0,q.jsx)(U2,{port:t,step:e});let a=G2(e,t);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(T2,{text:a.heading,tone:`failed`}),(0,q.jsx)(D2,{text:a.words}),(0,q.jsx)(cC,{command:a.command}),(0,q.jsxs)(k2,{children:[e.step===`gaveUp`?(0,q.jsx)(Y,{onClick:r,children:`Keep waiting`}):(0,q.jsx)(Y,{onClick:n,children:`Close`}),e.step===`signedOut`?null:(0,q.jsx)(Y,{onClick:i,variant:`primary`,children:`Reload`})]})]})},G2=(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`},K2="Lost the output from `ork ui`. The command may still be running; reconnecting…",q2=e=>e.command[0]??`it`,J2=(e,t)=>{let n=t.split(`
110
- `).findLast(e=>e.startsWith(`Could not run`));return e.code===127&&n!==void 0?n:`\`${q2(e)}\` failed (exit ${String(e.code??1)}); the upgrade did not finish.`},Y2=({job:e,lost:t,output:n})=>{let r=(0,U.useId)();(0,U.useEffect)(()=>{n.current?.focus()},[n]);let i=q2(e);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`p`,{className:y2.message,children:[(0,q.jsx)(r_,{text:`Running \`${i}\`…`}),` `,(0,q.jsx)(E2,{since:Date.parse(e.startedAt)})]}),(0,q.jsx)(cC,{command:e.command.join(` `)}),t?(0,q.jsx)(D2,{text:K2}):null,(0,q.jsx)(O2,{id:r,why:`It closes when ${i} ends; closing now would hide how it ended.`}),(0,q.jsx)(k2,{children:(0,q.jsx)(Y,{"aria-describedby":r,disabled:!0,focusableWhenDisabled:!0,children:`Close`})})]})},X2=({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 ${q2(u)}`;if(e.step===`running`)return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(TH,{label:d,ref:a,text:t}),(0,q.jsx)(Y2,{job:u,lost:n,output:a})]});let f=(0,q.jsx)(TH,{label:d,text:t});return e.step===`failed`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(T2,{ref:o,text:`The upgrade did not finish`,tone:`failed`}),(0,q.jsx)(D2,{text:`${J2(u,t)} Nothing was restarted; \`ork ui\` still runs ${r}.`}),f,(0,q.jsx)(`p`,{className:y2.note,children:`To run it in a terminal yourself:`}),(0,q.jsx)(cC,{command:u.command.join(` `)}),(0,q.jsxs)(k2,{children:[(0,q.jsx)(Y,{onClick:s,children:`Close`}),(0,q.jsx)(Y,{onClick:c,variant:`ghost`,children:`Try again`})]})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(T2,{ref:o,text:`Upgraded to ${u.latest}`,tone:`succeeded`}),(0,q.jsx)(`p`,{className:y2.message,children:(0,q.jsx)(r_,{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,q.jsx)(D2,{text:e.refusal}),(0,q.jsxs)(k2,{children:[(0,q.jsx)(Y,{onClick:s,variant:`ghost`,children:`Later`}),(0,q.jsxs)(Y,{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,q.jsx)($y,{}),`Restart`]})]})]})},Z2={pollMs:1e3,waitMs:6e4,reloadMs:1500},Q2=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},$2=({client:e,step:t,setStep:n,announce:r,reload:i,timing:a})=>{let o=(0,U.useRef)({announce:r,reload:i});(0,U.useEffect)(()=>{o.current={announce:r,reload:i}}),(0,U.useEffect)(()=>{let r=t.step===`restarting`?t:null,i=!1,s=async t=>{let r=await Q2(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])},e4=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.`,t4=(e,t)=>e.kind===`unreachable`?{step:`unreachable`,words:e4(t)}:e.kind===`latest`?{step:`latest`,current:e.current}:{step:`plan`,plan:e,refusal:null,starting:!1},n4=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.`,r4=e=>e.state===`running`?{step:`running`,job:e}:e.state===`succeeded`?{step:`done`,job:e,refusal:null,asking:!1}:{step:`failed`,job:e},i4=({client:e,open:t,job:n,registry:r,announce:i,onAsked:a})=>{let[o,s]=(0,U.useState)(()=>n===null?{step:`checking`}:r4(n)),[c,l]=(0,U.useState)([]),[u,d]=(0,U.useState)(!1),f=(0,U.useRef)(null),p=(0,U.useRef)(0),m=(0,U.useRef)({announce:i,onAsked:a,registry:r});(0,U.useEffect)(()=>{m.current={announce:i,onAsked:a,registry:r}});let h=(0,U.useCallback)(e=>{f.current?.close(),p.current=0,l([]);let n=zV({url:()=>`${xw.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(r4({...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,U.useCallback)(async()=>{s({step:`checking`});let t=await e.call(`upgradePlan`);m.current.onAsked();let n=t.ok?t4(t.data,m.current.registry):{step:`unreachable`,words:t.error};s(n),n.step===`plan`&&m.current.announce(n4(n.plan))},[e]),_=(0,U.useRef)(n);(0,U.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=t4(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(`
111
- `),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()})}}},a4=e=>[`checking`,`unreachable`,`latest`,`plan`].includes(e.step),o4=e=>[`running`,`done`,`failed`].includes(e.step),s4=e=>!a4(e)&&!o4(e),c4=({starts:e,timing:t,reload:n,onStep:r,onClose:i})=>{let{version:a,client:o}=ob(),s=(0,U.use)(fL),c=vb(a.info),l=vb(a.dialog),u=(0,U.useCallback)(e=>s?.announce(e),[s]),d=i4({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;$2({client:o,step:f,setStep:p,announce:u,reload:n,timing:t}),(0,U.useEffect)(()=>{r(f)},[f,r]);let m=f.step===`restarting`||f.step===`back`;(0,U.useEffect)(()=>(a.restarting.setValue(m),()=>{a.restarting.setValue(!1)}),[a,m]);let h=window.location.port;return a4(f)?(0,q.jsx)(H2,{first:e.first,onAsk:d.ask,onClose:i,onUpgrade:d.upgrade,registry:c?.registry??null,step:f}):o4(f)?(0,q.jsx)(X2,{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}):s4(f)?(0,q.jsx)(W2,{onClose:i,onKeepWaiting:d.keepWaiting,onReload:n,port:h,step:f}):null},l4=()=>{window.location.reload()},u4=e=>![`running`,`restarting`,`back`].includes(e.step)&&!(e.step===`plan`&&e.starting)&&!(e.step===`done`&&e.asking),d4=`Upgrade Ork`,f4=({timing:e=Z2,reload:t=l4})=>{let{version:n}=ob(),r=(0,U.use)(fL),i=vb(n.dialog),a=vb(n.info),o=(0,U.useRef)(null),s=(0,U.useRef)(null),c=(0,U.useRef)(null),l=i===`job`&&a?.job?.state!==`running`,u=i===`job`?l?c:s:o,[d,f]=(0,U.useState)(d4),p=(0,U.useRef)({closable:!0,ran:!1}),m=(0,U.useCallback)(e=>{p.current={closable:u4(e),ran:p.current.ran||`job`in e},f(t=>a4(e)?d4:`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(d4),n.closeDialog())};return(0,q.jsx)(NC,{finalFocus:()=>{let e=document.querySelector(`#${f2}`);return e===null?(r?.focusPanels(),!1):e},initialFocus:u,onOpenChange:e=>{e||h()},open:i!==null,size:`wide`,title:d,children:(0,q.jsx)(c4,{onClose:h,onStep:m,reload:t,starts:{first:o,output:s,heading:c},timing:e})})},p4=({workspace:e})=>(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(L2,{workspace:e}),(0,q.jsx)(f4,{})]});function m4(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]=U.useState(r??``),[p,m]=U.useState(``);U.useEffect(()=>{(u||!c)&&m(``)},[n,u,c]);let h;h=c&&p!==``?p:u?n??``:d;let g=Sx({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?Zb(t,o):``)}return(0,q.jsx)(Ax,{...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 h4=QS,g4=[`Panels`,`Runs`,`Window`,`Layout`,`View`,`Ork`],_4=`Needs a wider window.`,v4=`No panel is active.`,y4=[`left`,`right`,`up`,`down`],b4={left:`narrower`,right:`wider`,up:`shorter`,down:`taller`},x4=e=>e.wide?e.active===null?v4:void 0:_4,S4=e=>xY.map((t,n)=>{let r={id:`go-${t.id}`,title:`Go to ${t.title}`,group:`Panels`,run:()=>{e.goTo(t.id)}},i=Yk(n+1);return i!==void 0&&(r.shortcut=i),r}),C4=e=>[{id:`run-workflow`,title:`Run workflow…`,group:`Runs`,run:()=>{e.runDialog.setValue(!0)}}],w4=(e,t)=>{let n=x4(t),r=t.active===null?`panel`:CY(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:qk.minimize,run:()=>{e.minimize()},disabled:n},{id:`maximize`,title:t.maximized?`Restore ${r}`:`Maximize ${r}`,group:`Window`,shortcut:qk.maximize,run:()=>{e.toggleMaximize()},disabled:i},{id:`float`,title:t.floating?`Dock ${r}`:`Float ${r}`,group:`Window`,shortcut:qk.float,run:()=>{e.toggleFloat()},disabled:n},{id:`close`,title:`Close ${r}`,group:`Window`,shortcut:qk.close,run:()=>{e.close()},disabled:n},...y4.map(t=>({id:`resize-${t}`,title:`Make ${r} ${b4[t]}`,group:`Window`,shortcut:qk.resize(t),run:()=>{e.resize(t)},disabled:a})),...y4.map(t=>({id:`move-${t}`,title:`Move ${r} ${t}`,group:`Window`,shortcut:qk.move(t),run:()=>{e.move(t)},disabled:n}))]},T4=(e,t)=>{let n=t.wide?void 0:_4;return[{id:`next-group`,title:`Focus next panel group`,group:`Layout`,shortcut:qk.nextGroup,run:()=>{e.cycleGroup(1)},disabled:n},{id:`previous-group`,title:`Focus previous panel group`,group:`Layout`,shortcut:qk.previousGroup,run:()=>{e.cycleGroup(-1)},disabled:n},{id:`reset-layout`,title:`Reset layout`,group:`Layout`,run:()=>{e.resetLayout()}}]},E4=[{theme:`system`,title:`Follow the system`},{theme:`dark`,title:`Dark`},{theme:`light`,title:`Light`}],D4=[{density:`compact`,title:`Compact`},{density:`comfortable`,title:`Comfortable`}],O4=(e,t,n)=>[...E4.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})),...D4.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}))],k4=e=>[{id:`upgrade-ork`,title:`Upgrade Ork…`,group:`Ork`,detail:`Asks the registry for a new version now.`,run:()=>{e.version.openDialog(`ask`)}}],A4=(e,t,n,r)=>[...S4(e),...C4(n),...w4(e,t),...T4(e,t),...O4(e,n.preferences,r),...k4(n)],j4={palette:`_palette_p3ocp_6`,input:`_input_p3ocp_45`,list:`_list_p3ocp_78`,group:`_group_p3ocp_88`,empty:`_empty_p3ocp_106`},M4=e=>g4.map(t=>({value:t,items:e.filter(e=>e.group===t).map(e=>({label:e.title,command:e}))})),N4=({commands:e,onChoose:t})=>{let n=(0,U.useMemo)(()=>M4(e),[e]),r=Xk();return(0,q.jsxs)(m4,{autoHighlight:`always`,inline:!0,items:n,keepHighlight:!0,open:!0,children:[(0,q.jsx)(Zx,{"aria-label":`Search commands`,className:j4.input,placeholder:`Type a command`}),(0,q.jsx)(tC,{children:(0,q.jsx)(`p`,{className:j4.empty,children:`No command matches.`})}),(0,q.jsx)(_S,{className:j4.list,children:e=>(0,q.jsxs)(US,{items:e.items,children:[(0,q.jsx)(WS,{className:j4.group,children:e.value}),(0,q.jsx)(sS,{children:e=>(0,q.jsxs)(h4,{className:o_.item,disabled:e.command.disabled!==void 0,onClick:()=>{t(e.command)},value:e,children:[(0,q.jsx)(`span`,{children:e.label}),(e.command.disabled??e.command.detail)===void 0?null:(0,q.jsx)(`span`,{className:o_.itemDetail,children:e.command.disabled??e.command.detail}),e.command.shortcut===void 0?null:(0,q.jsx)(a_,{keys:Uk(e.command.shortcut,r)})]},e.command.id)})]},e.value)})]})},P4=()=>(document.activeElement===null||document.activeElement===document.body)&&document.querySelector(`[data-modal]`)===null,F4=e=>{requestAnimationFrame(()=>{requestAnimationFrame(e)})},I4=({workspace:e,commands:t})=>{let n=vb(e.palette),r=(0,U.useRef)(null),i=(0,U.useRef)(!1),a=(0,U.useRef)(null);(0,U.useLayoutEffect)(()=>{n&&(i.current=!1,a.current=document.activeElement)},[n]);let o=t=>{e.palette.setValue(t)},s=()=>{if(!P4())return;let t=a.current;t instanceof HTMLElement&&t.isConnected?t.focus():e.focusPanels()};return(0,q.jsx)(AC,{onOpenChange:o,onOpenChangeComplete:e=>{if(e)return;let t=r.current;r.current=null,t!==null&&(t.run(),F4(s))},open:n,children:(0,q.jsxs)(OC,{children:[(0,q.jsx)(vC,{className:jC.backdrop}),(0,q.jsx)(DC,{"aria-label":`Command palette`,"aria-modal":`true`,className:j4.palette,finalFocus:()=>!i.current,children:(0,q.jsx)(N4,{commands:t,onChoose:e=>{r.current=e,i.current=!0,o(!1)}})})]})})},L4=(e,t,n)=>`${String(e)} ${e===1?t:n}`,R4=()=>{let{runs:e,decisions:t,connection:n}=ob(),r=_b(e,oH),i=_b(t,e=>e?.length??null);return _b(n,({link:e})=>e===`open`)&&r!==null&&i!==null?(0,q.jsxs)(`span`,{className:$k.status,children:[L4(r,`run live`,`runs live`),`,`,` `,L4(i,`decision open`,`decisions open`)]}):null},z4=({workspace:e})=>{let t=vb(e.announcement),{connection:n,version:r}=ob(),i=_b(n,aH),a=vb(r.restarting);return(0,q.jsxs)(`footer`,{className:$k.bar,children:[(0,q.jsx)(`output`,{"aria-live":a?`off`:void 0,className:$k.status,children:(0,q.jsx)(r_,{text:i})}),(0,q.jsx)(R4,{}),(0,q.jsx)(`output`,{"aria-atomic":`true`,"aria-live":`polite`,className:$k.visuallyHidden,children:t})]})},B4=e=>{let t=ob(),{preferences:n}=t,r=vb(e.view),i=vb(n.value),a=(0,U.useMemo)(()=>A4(e,r,t,i),[e,r,t,i]);return Qk(e,a),a},V4=e=>{let t=ob();(0,U.useEffect)(()=>t.notifications.onNew(n=>{if(e.announce(n.map(({title:e})=>e).join(` `)),t.preferences.value.getValue().desktopNotifications)for(let r of n)LW(r.title,r.id,()=>{t.selectRun(r.runId),e.goTo(`notifications`)})}),[t,e])},H4=({workspace:e})=>{let t=B4(e);return V4(e),(0,q.jsx)(fL,{value:e,children:(0,q.jsxs)(`div`,{className:$k.shell,children:[(0,q.jsx)(DY,{workspace:e}),(0,q.jsx)(p4,{workspace:e}),(0,q.jsx)(d2,{workspace:e}),(0,q.jsx)(z4,{workspace:e}),(0,q.jsx)(I4,{commands:t,workspace:e}),(0,q.jsx)(Bk,{})]})})},U4=()=>{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)}}},W4=()=>{try{return window.localStorage}catch{return U4()}},G4=1e3,K4=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(` `))},G4)};return e=>{let i=n_(e);n?t.push(i):r(i)}},q4=280,J4=340,Y4=240,X4={minimumWidth:240,minimumHeight:120},Z4=e=>{e.api.setConstraints(X4)},Q4=(e,t,n)=>[e.onDidAddGroup(Z4),e.onDidLayoutChange(()=>{n(),t()}),e.onDidAddPanel(t),e.onDidRemovePanel(t),e.onDidActivePanelChange(t),e.onDidMaximizedGroupChange(t)],$4=(e,t)=>{try{return e.fromJSON(t),!0}catch{return e.clear(),!1}},e3=(e,t,n)=>e.addPanel({id:t,component:t,title:CY(t).title,...n}),t3=e=>{let t=e3(e,`monitor`,{});e3(e,`builder`,{position:{referencePanel:`monitor`,direction:`within`},inactive:!0}),e3(e,`runs`,{position:{referencePanel:`monitor`,direction:`left`},initialWidth:q4,inactive:!0}),e3(e,`decisions`,{position:{referencePanel:`monitor`,direction:`right`},initialWidth:J4,inactive:!0}),e3(e,`notifications`,{position:{referencePanel:`decisions`,direction:`within`},inactive:!0}),e3(e,`context`,{position:{referencePanel:`decisions`,direction:`below`}}),e3(e,`logs`,{position:{referencePanel:`monitor`,direction:`below`},initialHeight:Y4,inactive:!0}),e3(e,`chats`,{position:{referencePanel:`logs`,direction:`within`},inactive:!0}),e3(e,`usage`,{position:{referencePanel:`logs`,direction:`within`},inactive:!0}),e3(e,`feedback`,{position:{referencePanel:`usage`,direction:`within`},inactive:!0}),e3(e,`worktrees`,{position:{referencePanel:`feedback`,direction:`within`},inactive:!0}),t.api.setActive()},n3=(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=n3(e,t,!n);if(r!==void 0)return r}},r3={horizontal:`left`,vertical:`above`},i3={horizontal:`right`,vertical:`below`},a3=(e,t)=>{let{root:n,orientation:r}=e.toJSON().grid,i=r===zX.HORIZONTAL,a=n3(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?i3[l]:r3[l];return Array.isArray(d.data)?c?{group:null,direction:p,...f}:void 0:{group:d.data.id,direction:p,...f}},o3=(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}},s3=(e,t)=>{let{group:n}=t,r=o3(e,n),i=a3(e,n);return{group:n.id,index:n.panels.indexOf(t),...r===void 0?{}:{floating:r},...i===void 0?{}:{beside:i}}},c3=(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`}}},l3=(e,t,n)=>e3(e,t,c3(e,n)),u3=(e,t)=>e.groups.find(e=>e.id===t),d3=e=>{let t=e.element.querySelector(`[role="tab"][aria-selected="true"]`);return t?.focus(),t!==null},f3=e=>{e.api.setActive(),requestAnimationFrame(()=>{d3(e.group)})},p3=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),m3=(e,t)=>{let n=p3(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(),d3(i))},h3=e=>{e.api.location.type===`grid`&&(e.api.isMaximized()?e.api.exitMaximized():e.api.maximize(),d3(e))},g3={right:{axis:`width`,delta:32},left:{axis:`width`,delta:-32},down:{axis:`height`,delta:32},up:{axis:`height`,delta:-32}},_3=(e,t)=>{let{axis:n,delta:r}=g3[t];e.api.setSize({[n]:e.api[n]+r})},v3=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}.`},y3={right:{x:32,y:0},left:{x:-32,y:0},down:{x:0,y:32},up:{x:0,y:-32}},b3={left:`left`,right:`right`,up:`above`,down:`below`},x3=(e,t,n)=>{let{group:r}=t,i=o3(e,r);if(i!==void 0){let{x:t,y:a}=y3[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:u3(e,a.id);o===void 0?(r.panels.length!==1||e.groups.length!==1)&&t.api.moveTo({group:e.addGroup({direction:b3[n]}),position:`center`}):t.api.moveTo({group:o,position:`center`})},S3={left:`left`,right:`right`,above:`top`,below:`bottom`},C3=(e,t,n)=>{let r=t.activePanel;if(r===void 0)return;if(t.api.location.type!==`floating`){let{beside:i}=s3(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:u3(e,i.group),o=i?.direction??`right`;t.api.moveTo(a===void 0?{position:S3[o]}:{group:a,position:S3[o]}),i!==void 0&&t.api.setSize(o===`left`||o===`right`?{width:i.width}:{height:i.height})},w3=`ork.layout.v1`,T3=Qs(e=>typeof e==`string`&&SY(e)),E3=hs({left:rs(),top:rs(),width:rs(),height:rs()}),D3=hs({id:T3,anchor:hs({group:V(),index:rs(),floating:E3.optional(),beside:hs({group:V().nullable(),direction:Os([`left`,`right`,`above`,`below`]),width:rs(),height:rs()}).optional()})}),O3=gs({grid:gs({root:gs({})}),panels:Es(V(),gs({contentComponent:T3}))}),k3=hs({dock:ls(),minimized:ps(D3),folded:ps(T3)}),A3=(e,t,n)=>[...e.filter(e=>e!==t),...n?[t]:[]],j3={dock:null,minimized:[],folded:[]},M3=e=>O3.safeParse(e).success,N3=e=>{let t=k3.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(!M3(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}},P3=e=>new ub(j3,{key:w3,storage:e}),F3=({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&&h3(r),n()},toggleFloat:t=>{let i=e(),a=t??i?.activeGroup;i!==null&&a!==void 0&&(s(),C3(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&&(_3(r,t),i(v3(a)))},move:t=>{let o=e(),c=o?.activePanel;o!==null&&c!==void 0&&(a(()=>{s(),x3(o,c,t)}),n(),r(),i(`${c.title??c.id} moved ${t}.`))},cycleGroup:t=>{let n=e();n!==null&&m3(n,t)}}},I3=({storage:e,wide:t,onLayoutDropped:n})=>{let r=P3(e),i=N3(r.getValue()),a=i===null;a&&r.reset();let o=cb.create(r2(null,i??j3,t)),s=cb.create(!1),c=cb.create(``),l=null,u=!1,d=[],f=K4(c),p=e=>{u||f(e)},m=e=>{u=!0,e(),u=!1},h=()=>{let e=o.getValue(),t=r2(l,r.getValue(),e.wide);i2(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&&$4(e,t)||(a||=t!==null,r.setValue({...j3,folded:i}),t3(e)),a&&n?.(),a=!1,e.groups.forEach(Z4),d=Q4(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&&d3(t))&&e!==void 0&&s2(o2(e))})},w=()=>{let[e]=xY;o.getValue().wide?C():e!==void 0&&s2(a2(e.id))},T=e=>{let t=b(e);if(l===null||t===void 0)return;let n=t.id;if(!SY(n))return;m(x);let r=s3(l,t);S(e=>[...e,{id:n,anchor:r}]),m(()=>{t.api.close()}),f(`${CY(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(),f3(l3(n,e,t?.anchor))}),f(`${CY(e).title} restored.`),_()},D=(e,t)=>{let n=r.getValue();r.setValue({...n,folded:A3(n.folded,e,t)}),_()},O=e=>{D(e,!r.getValue().folded.includes(e))},k=e=>{if(!o.getValue().wide){D(e,!1),s2(a2(e));return}if(l===null)return;let t=l.getPanel(e);if(t!==void 0)t.api.isMaximized()||x(),f3(t);else if(o.getValue().minimized.includes(e))E(e);else{let t=l;m(()=>{x(),f3(l3(t,e))}),f(`${CY(e).title} opened.`)}},A=F3({dock:()=>l,targetPanel:b,commit:_,refocus:C,announce:f,quietly:m}),j=()=>{if(r.setValue(j3),l!==null){let e=l;m(()=>{e.clear(),t3(e)}),l.groups.forEach(Z4),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}},L3=Ew(),R3=`1.0.0-alpha.13`,z3=()=>sH({client:L3,open:PV,storage:W4(),pageVersion:R3}),B3=()=>I3({storage:W4(),wide:window.matchMedia(n2).matches,onLayoutDropped:()=>{tb.add({title:`Layout reset`,description:`The saved layout could not be read.`})}}),V3=()=>{let[e]=(0,U.useState)(z3),[t]=(0,U.useState)(B3);return(0,U.useLayoutEffect)(()=>hb(window,e.preferences),[e]),(0,U.useEffect)(()=>e.start(),[e]),(0,q.jsx)(ab,{value:e,children:(0,q.jsx)(c_,{children:(0,q.jsx)(rb,{children:(0,q.jsx)(H4,{workspace:t})})})})};export{V3 as App};
100
+ `).find(e=>e.trim()!==``)??``)}},oV=e=>e===``?0:e.replace(/\n+$/u,``).split(`
101
+ `).length,sV={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`},cV=[`h1`,`h2`,`h3`,`h4`,`h5`,`h6`],lV=(e,t)=>t===1?`Copy code`:`Copy code block ${e} of ${t}`,uV=e=>String(e.position?.start.offset),dV=(e,t)=>{let n=0;return e.split(`
102
+ `).flatMap((e,r)=>{let i=`${t}:${n}`;return n+=e.length+1,r===0?[e]:[(0,q.jsx)(`br`,{},i),e]})},fV=e=>e.map(e=>(0,q.jsx)(U.Fragment,{children:pV(e)},uV(e))),pV=e=>e.type===`text`?dV(e.value,uV(e)):e.type===`emphasis`?(0,q.jsx)(`em`,{children:fV(e.children)}):e.type===`strong`?(0,q.jsx)(`strong`,{children:fV(e.children)}):e.type===`delete`||e.type===`linkReference`?fV(e.children):e.type===`inlineCode`?(0,q.jsx)(`code`,{className:sV.inline,children:e.value}):e.type===`break`?(0,q.jsx)(`br`,{}):e.type===`html`?e.value:e.type===`link`?mV(e.url,e.children):e.type===`image`||e.type===`imageReference`?(0,q.jsx)(`span`,{className:sV.image,children:e.alt===void 0||e.alt===null||e.alt===``?`image`:`image: ${e.alt}`}):null,mV=(e,t)=>{if(QB(e))return(0,q.jsxs)(`a`,{className:sV.link,href:e,rel:`noopener noreferrer`,target:`_blank`,children:[fV(t),(0,q.jsx)(uk,{children:` (opens in a new tab)`})]});let n=t.map(e=>nV(e)).join(``);return n===e||n===``?(0,q.jsx)(`code`,{className:sV.target,children:e}):(0,q.jsxs)(q.Fragment,{children:[fV(t),` (`,(0,q.jsx)(`code`,{className:sV.target,children:e}),`)`]})},hV=(e,t,n)=>{let r=uV(e);if(e.type===`paragraph`)return(0,q.jsx)(`p`,{children:fV(e.children)},r);if(e.type===`heading`){let t=cV[Math.min(6,n.startLevel+e.depth-1)-1]??`h6`;return(0,q.jsx)(t,{children:fV(e.children)},r)}if(e.type===`thematicBreak`)return(0,q.jsx)(`hr`,{},r);if(e.type===`blockquote`)return(0,q.jsx)(`blockquote`,{children:_V(e,n)},r);if(e.type===`list`){let t=e.children.map(e=>(0,q.jsx)(`li`,{children:_V(e,n)},uV(e)));return e.ordered===!0?(0,q.jsx)(`ol`,{start:e.start??1,children:t},r):(0,q.jsx)(`ul`,{children:t},r)}return e.type===`definition`?(0,q.jsxs)(`p`,{children:[`[`,e.label??e.identifier,`]:`,` `,(0,q.jsx)(`code`,{className:sV.target,children:e.url})]},r):e.type===`code`?gV(e.value,e.lang,n,r):e.type===`html`?rV.includes(t.type)?gV(e.value,void 0,n,r):(0,q.jsx)(U.Fragment,{children:e.value},r):null},gV=(e,t,n,r)=>(0,q.jsx)(cC,{caption:t??void 0,command:e,label:n.copyLabel(n.next(),n.blocks)},r),_V=(e,t)=>e.children.map(n=>hV(n,e,t)),vV=e=>(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`p`,{className:sV.note,children:`Could not render this as Markdown: showing the text as written.`}),(0,q.jsx)(`pre`,{className:sV.written,children:e})]}),yV=({text:e,startLevel:t,lead:n=!1,muted:r=!1,copyLabel:i=lV})=>{let a;try{let n=tV(e),r=0;a=_V(n,{startLevel:t,blocks:iV(n),next:()=>++r,copyLabel:i})}catch{a=vV(e)}return(0,q.jsx)(`div`,{className:sV.markdown,"data-lead":n?``:void 0,"data-muted":r?``:void 0,children:a})},bV=e=>{let t=oV(e);return t===1?`1 line`:`${t} lines`},xV=({decision:e,document:t})=>{let[n,r]=(0,U.useState)(!1),i=(0,U.useRef)(null),{id:a,node:o,runId:s}=e;return(0,q.jsxs)(`div`,{className:HL.read,children:[(0,q.jsx)(Y,{cli:ML(e),onClick:()=>{r(!0)},variant:`ghost`,children:`Read document`}),(0,q.jsx)(`span`,{className:HL.length,children:bV(t)}),(0,q.jsxs)(NC,{description:`Document for run ${s}. Read-only.`,initialFocus:i,onOpenChange:r,open:n,size:`wide`,title:`\`${o}\` · \`${a}\``,children:[(0,q.jsx)(`div`,{"aria-label":`Document`,className:HL.document,ref:i,role:`region`,tabIndex:0,children:(0,q.jsx)(yV,{copyLabel:jL(`${o} document`),startLevel:3,text:t})}),(0,q.jsx)(PC,{children:(0,q.jsx)(Y,{onClick:()=>{r(!1)},children:`Close`})})]})]})},SV={region:`_region_1w5dd_7`,more:`_more_1w5dd_23`},CV=e=>{let t=Number(getComputedStyle(e).lineHeight.replace(`px`,``));return e.scrollHeight>0&&t>0?Math.round(e.scrollHeight/t):null},wV=({source:e,children:t})=>{let n=(0,U.useRef)(null),r=(0,U.useId)(),[i,a]=(0,U.useState)(!1),[o,s]=(0,U.useState)(()=>oV(e)),c=(0,U.useCallback)(()=>{let t=n.current;s((t===null?null:CV(t))??oV(e))},[e]);(0,U.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,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{className:SV.region,"data-folded":l&&!i?``:void 0,id:r,onFocus:()=>{a(!0)},ref:n,children:t}),l?(0,q.jsx)(`div`,{className:SV.more,children:(0,q.jsx)(Y,{"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]})},TV=({decision:{kind:e,node:t,question:n,context:r},nameId:i})=>(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{hidden:!0,id:i,children:aV(n)}),(0,q.jsx)(wV,{source:n,children:(0,q.jsx)(yV,{copyLabel:jL(t),lead:!0,startLevel:4,text:n})}),r===void 0?null:e===`permission`?(0,q.jsx)(cC,{caption:NL(r)?`json`:void 0,command:r,label:`Copy command (${t})`}):(0,q.jsx)(wV,{source:r,children:(0,q.jsx)(yV,{copyLabel:jL(t),muted:!0,startLevel:4,text:r})})]}),EV=e=>e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLButtonElement&&!(`option`in e.dataset),DV=({decision:e,workflow:t,unreachable:n=!1,onAnswer:r,onOpenRun:i})=>{let{id:a,runId:o,node:s,document:c,options:l,recommended:u,owner:d}=e,f=(0,U.useId)(),p=(0,U.useId)(),[m,h]=(0,U.useState)(!1),[g,_]=(0,U.useState)(null),[v,y]=(0,U.useState)(``),b=async e=>{if(m||n)return;h(!0),_(null);let t=await r(a,e.id,v);h(!1),t.ok||_(t.error)};return(0,q.jsxs)(`section`,{"aria-labelledby":`${p} ${f}`,className:HL.card,"data-decision":a,onKeyDown:e=>{if(!(e.target instanceof Node)||!e.currentTarget.contains(e.target)||e.metaKey||e.ctrlKey||e.altKey||EV(e.target))return;let t=e.target===e.currentTarget,n=e.key===`Enter`&&t?l.find(e=>e.id===u):AL(l,e.key);n!==void 0&&(e.preventDefault(),b(n))},tabIndex:0,children:[(0,q.jsxs)(`div`,{className:HL.from,children:[(0,q.jsxs)(`h3`,{className:HL.fromText,id:p,children:[t===void 0?``:`${t} · `,o,` · `,s,d===void 0?``:`, passed on by ${d}`]}),(0,q.jsx)(Y,{onClick:()=>{i(o,s)},variant:`ghost`,children:`Open run`})]}),(0,q.jsx)(TV,{decision:e,nameId:f}),c===void 0?null:(0,q.jsx)(xV,{decision:e,document:c}),(0,q.jsx)(GL,{decision:e,note:v,onChoose:e=>{b(e)},onNote:y,sending:m,unreachable:n}),g===null?null:(0,q.jsxs)(`p`,{className:HL.refusal,role:`alert`,children:[`Could not answer: `,(0,q.jsx)(r_,{text:g})]})]})},OV=e=>{let t=cb.create(null),n=cb.create(null),r=cb.create(null),i=cb.create(null),a=cb.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)}}},kV=(e,t,n)=>e?.kind===`builder`&&e.project===t&&e.workflow===n,AV=()=>{let e=cb.create(null),t=t=>{e.setValue(t)},n=n=>{let r=e.getValue();t({kind:`builder`,...n,revision:kV(r,n.project,n.workflow)?r.revision:0})},r=(n,r,i)=>{let a=e.getValue();kV(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:OV({chooseBuilder:n,builderChanged:r,builderClosed:i}),chooseRun:(e,n)=>{t(e===null?null:{kind:`run`,run:e,node:n})}}},jV=e=>{let t=cb.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}}},MV=2e3,NV={events:[],latest:0,following:!0},PV=e=>e.events[0]?.seq??1,FV=e=>e.events.at(-1)?.seq??0,IV=e=>PV(e)>1,LV=e=>FV(e)<e.latest,RV=e=>e.slice(-2e3),zV=(e,t)=>Math.max(e.latest,t.at(-1)?.seq??0),BV=(e,t)=>{let n=FV(e);return t.filter(e=>e.seq>n)},VV=(e,t)=>{let n=zV(e,t);return e.following&&!LV(e)?{...e,latest:n,events:RV([...e.events,...BV(e,t)])}:{...e,latest:n}},HV=(e,t)=>({events:RV(t),latest:zV(e,t),following:!0}),UV=(e,t)=>({...e,latest:zV(e,t),events:RV([...e.events,...BV(e,t)])}),WV=(e,t)=>{let n=PV(e),r=[...t.filter(e=>e.seq<n),...e.events].slice(0,MV),i={...e,events:r};return{...i,following:e.following&&!LV(i)}},GV=e=>{let t=PV(e)-1,n=Math.max(0,t-500);return{after:n,limit:t-n}},KV=e=>new EventSource(e),qV=2,JV=1e3,YV=15e3,XV=e=>{try{return JSON.parse(e)}catch{return}},ZV=({url:e,open:t,on:n,onStatus:r,onFailure:i})=>{let a=null,o=null,s=JV,c=null,l=e=>{e!==c&&(c=e,r(e))},u=()=>{let r=t(e());a=r,r.addEventListener(`open`,()=>{s=JV,l(`open`)}),r.addEventListener(`error`,()=>{l(`lost`),i?.(),r.readyState===qV&&(r.close(),o=setTimeout(u,s),s=Math.min(s*2,YV))});let c=Object.entries(n);for(let[e,t]of c)r.addEventListener(e,e=>{let n=XV(e.data);n!==void 0&&t(n)})};return l(`connecting`),u(),{close:()=>{o!==null&&clearTimeout(o),o=null,a?.close(),a=null}}},QV=1e3,$V=({runId:e,client:t,open:n})=>{let r=cb.create({...NV,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&&LV(e)&&!e.paging&&await p({after:FV(e),limit:500},UV)&&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({...VV(t,e),tail:[...t.tail,...e.filter(e=>e.seq>n)].slice(-500)}),m()},g=()=>{i?.close(),i=null},_=()=>{i=ZV({url:()=>`${Sw(xw.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},HV);e===s&&(t?(a=!0,_()):(d({link:`lost`}),u=setTimeout(()=>void v(),QV)))};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();IV(e)&&!e.paging&&await p(GV(e),WV)},loadNewer:async()=>{let e=r.getValue();LV(e)&&!e.paging&&await p({after:FV(e),limit:500},UV)},hold:()=>{d({following:!1})},follow:async()=>{let e=r.getValue();e.paging||(LV(e)?await p({last:500},HV):d({following:!0}),await m())}}},eH=({runId:e,client:t,feed:n})=>{let r=cb.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}}}},tH=e=>e.live===`running`||e.live===`paused`,nH=({client:e,open:t})=>{let n=new Map,r=r=>{let i=n.get(r)??{feed:$V({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&&tH(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=>eH({runId:t,client:e,feed:r(t).feed})}},rH=`ork.notifications.read`,iH=hs({before:V().nullable(),ids:ps(V())}),aH=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} ${Gj(e.live)}.`,at:e.finishedAt??e.startedAt,pending:t}},oH=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}),sH=(e,t)=>[...t.map(e=>oH(e)),...e.flatMap(e=>aH(e)??[])].toSorted((e,t)=>t.at.localeCompare(e.at)),cH=(e,t)=>t.ids.includes(e.id)||!e.pending&&t.before!==null&&e.at<=t.before,lH=({runs:e,decisions:t,storage:n,now:r=()=>new Date().toISOString()})=>{let i=new ub({before:null,ids:[]},{key:rH,storage:n});iH.safeParse(i.getValue()).success||i.reset();let a=cb.create({items:[],unread:0}),o=null,s=new Set,c=[],l=()=>{let e=i.getValue(),t=c.map(t=>({...t,unread:!cH(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=sH(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()}}},uH=(e,t)=>JSON.stringify(e)===JSON.stringify(t),dH=(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&&uH(t,e)?t:e});return r.length===e.length&&r.every((t,n)=>t===e[n])?e:r},fH=({client:e,open:t,pageVersion:n})=>{let r=cb.create(null),i=cb.create(null);return{info:r,open:t,pageVersion:n,dialog:i,restarting:cb.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)}}},pH=({client:e,open:t,pageVersion:n,runs:r,decisions:i})=>{let a=fH({client:e,open:t,pageVersion:n});return{version:a,follow:e=>ZV({url:()=>xw.overview,open:t,on:{runs:e=>{r.setValue(dH(r.getValue(),e))},decisions:e=>{i.setValue(dH(i.getValue(),e))},version:a.receive},...e})}},mH=e=>e.status===`ready`?{data:e.data,arg:e.arg}:e.status===`idle`?void 0:e.shown,hH=e=>{let t=cb.create({status:`idle`}),n=0;return{state:t,load:async r=>{n+=1;let i=n,a=mH(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}})}}},gH=({link:e,server:t})=>e===`lost`||t!==null&&`error`in t,_H=e=>{let{link:t,server:n}=e;return n!==null&&`error`in n?`Cannot reach \`ork ui\`: ${n.error}`:gH(e)?"Lost the stream from `ork ui`. Retrying…":t===`open`&&n!==null?`Ork ${n.version}`:"Connecting to `ork ui`…"},vH=e=>e===null?null:e.filter(e=>tH(e)).length,yH=({client:e,open:t,storage:n,pageVersion:r=null})=>{let i=cb.create(null),a=cb.create(null),o=cb.create({link:`connecting`,server:null}),s=cb.create({run:null,node:null}),c=AV(),l=null,u=e=>{e.run!==l&&(l=null),s.setValue(e),c.chooseRun(e.run,e.node)},d=mb(n),f=cb.create(`all`),p=cb.create(!1),m=cb.create(null),h=hH(()=>e.call(`projects`)),g=hH(()=>e.call(`triggers`)),_=hH(t=>e.call(`workflows`,{params:{id:t}})),v=cb.create({project:`all`,period:`30`}),y=hH(({query:t})=>e.call(`usage`,{query:t})),b=cb.create({status:`open`,about:`all`}),x=hH(()=>e.call(`feedbackItems`)),S=cb.create(`all`),C=hH(()=>e.call(`worktrees`)),w=nH({client:e,open:t}),T=jV(e),E=lH({runs:i,decisions:a,storage:n}),D=pH({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})}}},bH=()=>gH(vb(ob().connection)),xH=()=>(0,q.jsxs)(`p`,{className:HL.unreachable,"data-unreachable-notice":``,children:[(0,q.jsx)(My,{"aria-hidden":`true`}),(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:"Cannot answer here: `ork ui` is not reachable. Answer from a terminal with the command under each option."})})]}),SH=({view:e,open:t,onChange:n})=>{let{workflow:r,run:i}=e.active;return(0,q.jsxs)(`div`,{className:HL.filter,children:[(0,q.jsxs)(`div`,{className:HL.filterFields,children:[(0,q.jsx)(dk,{label:`Workflow`,onChange:e=>{n(e===` all`?{}:{workflow:e})},options:e.workflows,value:r??` all`}),(0,q.jsx)(dk,{label:`Run`,onChange:e=>{n({...r===void 0?{}:{workflow:r},...e===` all`?{}:{run:e}})},options:e.runs,value:i??` all`})]}),(0,q.jsxs)(`div`,{className:HL.counts,children:[(0,q.jsx)(`output`,{children:zL(t,e.shown.length)}),BL(e.active)?(0,q.jsx)(Y,{onClick:()=>{n({})},variant:`ghost`,children:`Clear filter`}):null]})]})},CH=({filter:e,open:t,onClear:n})=>t===0?(0,q.jsx)(JD,{cli:`ork decide`,title:`No decisions waiting.`,children:`Questions from your runs land here. In a terminal:`}):(0,q.jsxs)(JD,{cli:VL(e),title:`No decisions match the filter.`,children:[(0,q.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,q.jsx)(Y,{onClick:n,variant:`ghost`,children:`Clear filter`})]}),wH=({settled:e})=>e.length===0?null:(0,q.jsxs)(`section`,{"aria-label":`Settled decisions`,className:HL.settled,children:[(0,q.jsx)(`h3`,{className:HL.settledTitle,children:`Settled`}),(0,q.jsx)(`ul`,{className:HL.settledList,children:e.map(e=>(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:HL.settledQuestion,children:e.question}),(0,q.jsxs)(`span`,{className:HL.settledEnding,children:[(0,q.jsx)(`code`,{children:e.runId}),` · `,(0,q.jsx)(`code`,{children:e.node}),`.`,` `,(0,q.jsx)(r_,{text:OL(e)})]}),kL(e)===void 0?null:(0,q.jsx)(`span`,{className:HL.settledNote,children:kL(e)})]},e.id))})]}),TH=e=>e.tabIndex>=0?e:e.querySelector(`button`),EH=(e,t)=>{let n=(0,U.useRef)(null),r=(0,U.useRef)(null),i=(0,U.useRef)(e),a=(0,U.useRef)(null);return(0,U.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:TH(s))??n.current)?.focus()},[e,t]),(0,U.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)}}},DH=()=>{let e=ob(),t=(0,U.use)(wL),n=vb(e.decisions),r=vb(e.settledDecisions),i=vb(e.runs),a=bH(),o=(0,U.useRef)(r[0]?.id),{value:s,update:c}=e.preferences,l=vb(s).decisionFilter,u=(0,U.useMemo)(()=>n??[],[n]),d=(0,U.useCallback)(e=>i?.find(({id:t})=>t===e)?.workflow,[i]),f=n!==null&&i!==null,[p,m]=(0,U.useState)(!1),h=RL(u,!f||p?l:IL(u,l,d),d),g=new Set(u.map(({runId:e})=>e)).size>1,{panel:_,onFocus:v}=EH(h.shown.map(({id:e})=>e).join(`
103
+ `),`[data-decision]`),y=e=>{c({decisionFilter:e})};return(0,U.useEffect)(()=>{if(p||!f)return;let e=IL(u,l,d);(e.workflow!==l.workflow||e.run!==l.run)&&c({decisionFilter:e}),m(!0)},[f,p,u,l,c,d]),(0,U.useEffect)(()=>{let e=r[0];e!==void 0&&e.id!==o.current&&(o.current=e.id,t?.announce(`${e.question} ${OL(e)}`))},[r,t]),(0,q.jsxs)(`div`,{"aria-label":`Decisions`,className:HL.panel,onFocus:v,ref:_,role:`group`,tabIndex:-1,children:[BL(h.active)||g?(0,q.jsx)(SH,{onChange:y,open:u.length,view:h}):null,h.shown.length===0?(0,q.jsx)(CH,{filter:h.active,onClear:()=>{y({})},open:u.length}):(0,q.jsxs)(`div`,{className:HL.list,children:[a?(0,q.jsx)(xH,{}):null,h.shown.map(t=>(0,q.jsx)(DV,{decision:t,onAnswer:e.answerDecision,onOpenRun:(t,n)=>{e.selectRun(t),e.selectNode(n)},unreachable:a,workflow:d(t.runId)},t.id))]}),(0,q.jsx)(wH,{settled:r})]})},OH={panel:`_panel_1eq6v_8`,tools:`_tools_1eq6v_24`,main:`_main_1eq6v_39`,status:`_status_1eq6v_52`,counts:`_counts_1eq6v_65`,error:`_error_1eq6v_82`,list:`_list_1eq6v_91`,item:`_item_1eq6v_106`,row:`_row_1eq6v_113`,time:`_time_1eq6v_152`,type:`_type_1eq6v_153`,node:`_node_1eq6v_159`,line:`_line_1eq6v_161`,detail:`_detail_1eq6v_186`,end:`_end_1eq6v_210`},kH=e=>e.map(e=>({value:e,label:e})),AH=({events:e,node:t,type:n,text:r,onNode:i,onType:a,onText:o})=>{let s=pL(e,t),c=s.map(e=>fL(e,s));return(0,q.jsxs)(`div`,{className:OH.tools,children:[(0,q.jsx)(aC,{empty:`No node matches.`,label:`Node`,onChange:i,options:c,placeholder:`All nodes`,value:t}),(0,q.jsx)(aC,{empty:`No event type matches.`,label:`Event`,onChange:a,options:kH(mL(e)),placeholder:`All events`,value:n}),(0,q.jsx)(mk,{label:`Text`,onChange:o,value:r})]})},jH={end:`_end_wtaow_6`,note:`_note_wtaow_15`},MH={agent:`failed`,workflow:`failed`,ork:`failed`,account:`waiting`,provider:`interrupted`,user:`interrupted`},NH=e=>MH[e],PH=({end:e,pill:t=!1})=>e.actor===null?null:(0,q.jsxs)(`span`,{className:jH.end,children:[(0,q.jsx)(Jj,{pill:t,status:NH(e.actor),word:e.label}),e.transient?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,q.jsx)(uk,{children:`, `}),(0,q.jsx)(`span`,{className:jH.note,"data-transient":!0,children:`may pass`})]}):null]}),FH={well:`_well_14iu2_8`},IH=32,LH=({label:e,text:t,follow:n=!0,ref:r})=>{let i=(0,U.useRef)(null),a=r??i,o=(0,U.useRef)(!0);return(0,U.useLayoutEffect)(()=>{let e=a.current;e!==null&&n&&o.current&&(e.scrollTop=e.scrollHeight)}),(0,q.jsx)(`section`,{"aria-label":e,className:FH.well,onScroll:()=>{let e=a.current;e!==null&&(o.current=e.scrollHeight-e.scrollTop-e.clientHeight<IH)},ref:a,tabIndex:0,children:t})},RH={details:`_details_1cytm_6`,open:`_open_1cytm_16`,bar:`_bar_1cytm_25`,caption:`_caption_1cytm_35`,copy:`_copy_1cytm_49`},zH=({node:e,detail:t,cli:n})=>{let[r,i]=(0,U.useState)(!1),a=(0,U.useId)();return t===void 0?null:(0,q.jsxs)(`div`,{className:RH.details,children:[(0,q.jsxs)(Y,{"aria-controls":r?a:void 0,"aria-expanded":r,cli:n,onClick:()=>{i(e=>!e)},variant:`ghost`,children:[r?(0,q.jsx)(ly,{}):(0,q.jsx)(uy,{}),`Details`]}),r?(0,q.jsxs)(`div`,{className:RH.open,id:a,children:[(0,q.jsxs)(`div`,{className:RH.bar,children:[(0,q.jsx)(`span`,{className:RH.caption,children:`Scrubbed. At most 4 KiB.`}),(0,q.jsx)(`span`,{className:RH.copy,children:(0,q.jsx)(oC,{label:`Copy details`,text:t})})]}),(0,q.jsx)(LH,{follow:!1,label:`Raw details of ${e}`,text:t})]}):null]})},BH={note:`_note_1tzmy_7`,message:`_message_1tzmy_24`,hint:`_hint_1tzmy_25`,facts:`_facts_1tzmy_42`,who:`_who_1tzmy_53`,guide:`_guide_1tzmy_81`},VH=`https://github.com/mimshins/ork/blob/main/docs/guides/why-a-node-stopped.md`,HH={agent:`the agent`,workflow:`the workflow`,account:`your account`,provider:`the provider`,user:`you`,ork:`Ork`},UH=e=>e.endsWith(`.`)?e:`${e}.`,WH=({node:e,end:t,runId:n})=>t.actor===null?null:(0,q.jsxs)(`div`,{"aria-label":`How ${e} ended`,className:BH.note,role:`group`,children:[(0,q.jsxs)(`p`,{className:BH.message,children:[(0,q.jsx)(PH,{end:t,pill:!0}),(0,q.jsxs)(`span`,{children:[(0,q.jsx)(`code`,{children:e}),` `,(0,q.jsx)(r_,{text:UH(t.message)})]})]}),t.hint===``?null:(0,q.jsx)(`p`,{className:BH.hint,children:(0,q.jsx)(r_,{text:t.hint})}),(0,q.jsxs)(`div`,{className:BH.facts,children:[(0,q.jsxs)(`dl`,{className:BH.who,children:[(0,q.jsx)(`dt`,{children:`Who acts`}),(0,q.jsx)(`dd`,{children:HH[t.actor]})]}),(0,q.jsxs)(`a`,{className:BH.guide,href:`${VH}#${t.docsAnchor}`,rel:`noreferrer`,target:`_blank`,children:[`Why a node stops`,(0,q.jsx)(Fy,{}),(0,q.jsx)(uk,{children:` — what ${t.label} means (opens the guide in a new tab)`})]})]}),(0,q.jsx)(zH,{cli:`ork logs ${n} --node ${e}`,detail:t.detail,node:e})]}),GH=(0,U.memo)(({stored:e,open:t,tabbable:n,onToggle:r})=>{let{seq:i,at:a,event:o}=e,s=tL(o);return(0,q.jsxs)(`li`,{className:OH.item,children:[(0,q.jsxs)(`button`,{"aria-expanded":t,className:OH.row,"data-log-row":i,onClick:()=>{r(i)},tabIndex:n?0:-1,type:`button`,children:[(0,q.jsx)(`span`,{className:OH.time,children:_L(a)}),(0,q.jsx)(`span`,{className:OH.node,children:XI(o)??`run`}),(0,q.jsx)(`span`,{className:OH.type,children:o.type}),(0,q.jsx)(`span`,{className:OH.line,children:s===void 0?aL(o):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(PH,{end:s.end}),` `,rL(s)]})})]}),t&&s!==void 0?(0,q.jsx)(`div`,{className:OH.end,children:(0,q.jsx)(WH,{end:s.end,node:s.id,runId:e.runId})}):null,t?(0,q.jsx)(`pre`,{"aria-label":`Event ${String(i)} in full`,className:OH.detail,role:`group`,tabIndex:0,children:JSON.stringify(o,null,2)}):null]})});GH.displayName=`LogRow`;var KH=({shown:e,listRef:t,onScroll:n,label:r,reading:i})=>{let[a,o]=(0,U.useState)(new Set),[s,c]=(0,U.useState)(null),l=e.some(({seq:e})=>e===s)?s:e.at(-1)?.seq??null,u=(0,U.useCallback)(e=>{c(e),o(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n})},[]);return e.length===0?(0,q.jsx)(JD,{title:i?`Reading the run…`:`No event matches.`,children:`Only loaded events are filtered. Load older ones to look further.`}):(0,q.jsx)(`ol`,{"aria-label":r,className:OH.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,q.jsx)(GH,{onToggle:u,open:a.has(e.seq),stored:e,tabbable:e.seq===l},e.seq))})},qH=({events:e,shown:t,feed:n,cli:r})=>{let i=e.events.length,a=e.latest-FV(e);return(0,q.jsxs)(`div`,{className:OH.status,children:[(0,q.jsx)(`span`,{className:OH.counts,children:hL(t,i,e.latest)}),(0,q.jsx)(Y,{disabled:!IV(e)||e.paging,focusableWhenDisabled:!0,onClick:()=>{n.loadOlder()},variant:`ghost`,children:`Load older`}),(0,q.jsxs)(Y,{"aria-pressed":e.following,cli:r,onClick:()=>{e.following?n.hold():n.follow()},variant:`ghost`,children:[e.following?(0,q.jsx)(cy,{}):null,`Follow`,a>0?` (${String(a)} new)`:``]})]})},JH=({error:e})=>(0,q.jsx)(`p`,{className:OH.error,role:`alert`,children:(0,q.jsx)(r_,{text:e})}),YH=32,XH=e=>e.scrollHeight-e.scrollTop-e.clientHeight<YH,ZH=(e,t)=>{let n=(0,U.useRef)(null),{following:r}=t,i=t.events[0]?.seq,a=(0,U.useRef)({firstSeq:i,height:0});return(0,U.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,U.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=XH(t),i=e.state.getValue();i.following&&!r?e.hold():!i.following&&r&&!LV(i)&&e.follow()}}},QH=500,$H=({runId:e,node:t})=>{let n=ob(),r=(0,U.useMemo)(()=>n.feedOf(e),[n,e]);(0,U.useEffect)(()=>n.retainRun(e),[n,e]);let i=vb(r.state),[a,o]=(0,U.useState)(null),[s,c]=(0,U.useState)(``),l=(0,U.useMemo)(()=>uL(i.events,{node:t,type:a,text:s}),[i.events,t,a,s]),{listRef:u,onScroll:d}=ZH(r,i),f=(0,U.use)(wL),p=JSON.stringify([t,a,s]),m=(0,U.useRef)(p),h=hL(l.length,i.events.length,i.latest);return(0,U.useEffect)(()=>{let e=setTimeout(()=>{p!==m.current&&(m.current=p,f?.announce(h))},QH);return()=>{clearTimeout(e)}},[p,h,f]),(0,q.jsxs)(`div`,{className:OH.panel,children:[(0,q.jsx)(AH,{events:i.events,node:t,onNode:n.selectNode,onText:c,onType:o,text:s,type:a}),(0,q.jsxs)(`div`,{className:OH.main,children:[(0,q.jsx)(qH,{cli:gL(e,t),events:i,feed:r,shown:l.length}),i.error===null?null:(0,q.jsx)(JH,{error:i.error}),(0,q.jsx)(KH,{label:`Events of run ${e}`,listRef:u,onScroll:d,reading:i.link===`loading`&&i.events.length===0,shown:l})]})]})},eU=()=>{let{run:e,node:t}=vb(ob().selection);return e===null?(0,q.jsx)(JD,{cli:`ork logs <run>`,title:`No run chosen.`,children:`Choose one in the Runs panel, or in a terminal:`}):(0,q.jsx)($H,{node:t,runId:e},e)},tU={monitor:`_monitor_17zqb_8`,header:`_header_17zqb_25`,stats:`_stats_17zqb_43`,stat:`_stat_17zqb_43`,statName:`_statName_17zqb_58`,statValue:`_statValue_17zqb_74`,title:`_title_17zqb_90`,runId:`_runId_17zqb_101`,controls:`_controls_17zqb_111`,error:`_error_17zqb_119`,canvas:`_canvas_17zqb_133`,table:`_table_17zqb_144`,tableHead:`_tableHead_17zqb_162`,tree:`_tree_17zqb_185`,treeRow:`_treeRow_17zqb_190`,treeNode:`_treeNode_17zqb_233`,treeToggle:`_treeToggle_17zqb_239`,treeId:`_treeId_17zqb_259`,treeType:`_treeType_17zqb_269`,treeStatus:`_treeStatus_17zqb_285`,treeNow:`_treeNow_17zqb_291`,treeTime:`_treeTime_17zqb_301`,treeCost:`_treeCost_17zqb_314`,sideTitle:`_sideTitle_17zqb_337`,node:`_node_17zqb_346`,nodeFacts:`_nodeFacts_17zqb_362`,watching:`_watching_17zqb_363`,end:`_end_17zqb_373`,links:`_links_17zqb_416`,linkList:`_linkList_17zqb_431`,link:`_link_17zqb_416`,linkEnds:`_linkEnds_17zqb_451`,linkCount:`_linkCount_17zqb_462`},nU=({error:e})=>(0,q.jsx)(`p`,{className:tU.error,role:`alert`,children:(0,q.jsx)(r_,{text:e})}),rU=({runId:e,layout:t,...n})=>(0,q.jsx)(`div`,{className:tU.canvas,children:t===null?(0,q.jsx)(JD,{cli:`ork tree ${e}`,title:`Reading the run…`,children:`For now:`}):(0,q.jsx)(_N,{...n,layout:t,live:!0})}),iU=e=>{let t=e.template===void 0?void 0:/\.(\d+)$/u.exec(e.id)?.[1];return t===void 0?void 0:Number(t)},aU=e=>{let t=e.children.filter(e=>iU(e)!==void 0).toSorted((e,t)=>(iU(e)??0)-(iU(t)??0));return[...e.children.filter(e=>!t.includes(e)),...t]},oU=(e,t=new Set)=>{let n=(e,r,i)=>e.flatMap(e=>[{node:e,depth:r,parent:i},...t.has(e.id)?[]:n(aU(e),r+1,e.id)]);return n(e,1)},sU={waiting:`queued`,running:`running`,ok:`succeeded`,failed:`failed`,skipped:`skipped`},cU={waiting:`skipped`,running:`interrupted`},lU=(e,t,n=!1)=>{let r=n?cU[e.state]:void 0;return r===void 0?e.held===!0?`paused`:t?`waiting`:sU[e.state]:r},uU=(e,t)=>new Set((e??[]).filter(e=>e.runId===t).map(e=>e.node)),dU=18,fU=(e,t,n)=>{let r=n===0?``:`, ${String(n)} failed`,i=`${String(e)} of ${String(t)}${r}`;return i.length>dU?`${String(e)}/${String(t)}${r}`:i},pU=e=>{let{listed:t}=e;if(t===void 0)return;let n=e.children.filter(e=>(iU(e)??1/0)<t);return fU(n.filter(e=>[`ok`,`failed`,`skipped`].includes(e.state)).length,t,n.filter(e=>e.state===`failed`).length)},mU=(e,t,n,r=!1)=>new Map(oU(e).map(({node:e})=>{let i=e.inputTokens+e.outputTokens+(e.cacheWriteTokens??0);return[e.id,{status:lU(e,t.has(e.id),r),model:e.model,tokens:i===0?void 0:i,unpriced:e.unpriced===!0||void 0,costUsd:e.costUsd===0?void 0:e.costUsd,progress:pU(e),cli:`ork logs ${n} --node ${e.id}`}]})),hU=(e,t)=>({run:e,nodes:new Map([...t].map(([e,{status:t}])=>[e,t]))}),gU=new Set([`failed`,`paused`]),_U=(e,t,n)=>[...n.run===t.run||n.run!==`running`?[]:[`Run ${e} ${Gj(n.run)}.`],...[...n.nodes].filter(([e,r])=>r!==t.nodes.get(e)&&gU.has(r)&&(r!==`paused`||n.run!==`paused`)).map(([e,t])=>`${e} ${Gj(t)}.`)],vU=({live:e},t)=>e===`running`&&t?`waiting`:e,yU=(e,t)=>{let n=new Set(e.nodes.map(e=>e.id)),r=oU(t).map(({node:e})=>e).filter(e=>!n.has(e.id)&&iU(e)===void 0).map(({id:e,type:t,parent:n})=>({id:e,type:t,parent:n}));return{...e,nodes:[...e.nodes,...r]}},bU={enabled:!0},xU=e=>({enabled:!1,why:e}),SU=({live:e})=>e===`running`||e===`paused`,CU=e=>e.id.startsWith(`node-`)?xU(`it ran one node; run that node again instead`):bU,wU=e=>{if(!SU(e)){let t=`the run has ended (${e.live})`,n={pause:xU(t),proceed:xU(t),stop:xU(t)};return e.live===`succeeded`?n:{...n,resume:CU(e)}}let t=e.live===`paused`;return{pause:t?xU(`the run is paused`):bU,proceed:t?bU:xU(`the run is not paused`),stop:bU}},TU=(e,t)=>{if(!SU(e)){let t=`the run has ended (${e.live})`;return{pause:xU(t),proceed:xU(t),stop:xU(t)}}if(t.state!==`running`&&t.state!==`waiting`){let e=`${t.id} has finished`;return{pause:xU(e),proceed:xU(e),stop:xU(e)}}let n=t.held===!0||e.paused.nodes.includes(t.id),r=t.state===`running`?bU:xU(`${t.id} is not running`);if(e.live===`paused`){let e=`the whole run is paused; continue the run`;return{pause:xU(e),proceed:xU(e),stop:r}}return{pause:n?xU(`${t.id} is paused`):bU,proceed:n?bU:xU(`${t.id} is not paused`),stop:r}},EU=e=>e.state===`waiting`||e.state===`skipped`?xU(`it hasn't run`):bU,DU={reason:`_reason_sb9l9_7`},OU={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`},kU=`Meta+Enter Control+Enter`,AU=({onSend:e,children:t})=>(0,q.jsx)(`form`,{className:OU.form,onKeyDown:t=>{t.key===`Enter`&&(t.metaKey||t.ctrlKey)&&(t.preventDefault(),e())},onSubmit:t=>{t.preventDefault(),e()},children:t}),jU=({why:e,id:t})=>(0,q.jsx)(`output`,{className:DU.reason,id:t,children:(0,q.jsx)(r_,{text:e??``})}),MU=({text:e})=>e===null?null:(0,q.jsx)(`p`,{className:OU.alert,role:`alert`,children:(0,q.jsx)(r_,{text:e})}),NU=[`friction`,`bug`,`context-gap`,`skill`,`workflow`,`idea`],PU=[`low`,`medium`,`high`],FU=[{value:``,label:`No rating`},{value:`good`,label:`good`},{value:`bad`,label:`bad`}],IU={text:``,rating:``,kind:`friction`,severity:null},LU=({rating:e,severity:t})=>t??(e===`bad`?`high`:`medium`),RU=e=>e.severity===null&&e.rating===`bad`,zU=e=>e.text.trim()===``?`Write the note first.`:null,BU=(e,t)=>({text:t.text,...e===void 0?{}:{node:e},kind:t.kind,severity:LU(t),...t.rating===``?{}:{rating:t.rating}}),VU=(e,t,n)=>{let r=LU({...n,severity:null}),i=LU(n);return[`ork feedback note`,e,...t===void 0?[]:[Mk(t)],`-m`,n.text.trim()===``?`<text>`:Mk(n.text),...n.kind===`friction`?[]:[`--kind ${n.kind}`],...i===r?[]:[`--severity ${i}`],...n.rating===``?[]:[`--rating ${n.rating}`]].join(` `)},HU=(e,t,n)=>({title:t===void 0?`Noted on run \`${e}\``:`Noted on \`${t}\``,description:`It joined item \`${n.slice(0,12)}\`.`}),UU=e=>e.map(e=>({value:e,label:e})),WU=({runId:e,node:t,onSend:n,onDone:r})=>{let[i,a]=(0,U.useState)(IU),[o,s]=(0,U.useState)(!1),[c,l]=(0,U.useState)(null),u=(0,U.useId)(),d=(0,U.useId)(),f=zU(i),p=e=>{a(t=>({...t,...e}))},m=async()=>{if(f!==null||o)return;s(!0),l(null);let e=await n(BU(t,i));s(!1),l(e),e===null&&r()};return(0,q.jsxs)(AU,{onSend:()=>{m()},children:[(0,q.jsx)(mk,{description:`Its first line is the title.`,label:`Note`,multiline:!0,onChange:e=>{p({text:e})},required:!0,value:i.text}),(0,q.jsx)(dk,{label:`Rating`,onChange:e=>{p({rating:e})},options:FU,value:i.rating}),(0,q.jsx)(dk,{label:`Kind`,onChange:e=>{p({kind:e})},options:UU(NU),value:i.kind}),(0,q.jsx)(dk,{label:`Severity`,onChange:e=>{p({severity:e})},describedBy:d,options:UU(PU),value:LU(i)}),(0,q.jsx)(jU,{id:d,why:RU(i)?`Severity: high, from the bad rating.`:null}),(0,q.jsx)(cC,{command:VU(e,t,i)}),(0,q.jsx)(jU,{id:u,why:f}),(0,q.jsx)(MU,{text:c}),(0,q.jsxs)(PC,{children:[(0,q.jsx)(Y,{disabled:o,onClick:r,type:`button`,variant:`ghost`,children:`Cancel`}),(0,q.jsx)(Y,{"aria-describedby":u,"aria-keyshortcuts":kU,disabled:f!==null||o,focusableWhenDisabled:!0,type:`submit`,variant:`primary`,children:o?`Adding…`:`Add note`})]})]})},GU={enabled:!0},KU=({runId:e,node:t,check:n=GU,onSend:r})=>{let[i,a]=(0,U.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,q.jsxs)(q.Fragment,{children:[t===void 0?(0,q.jsx)(xb,{cli:c,label:s,onClick:l,children:(0,q.jsx)(Py,{})}):(0,q.jsxs)(Y,{"aria-label":s,cli:c,disabled:!n.enabled,focusableWhenDisabled:!0,onClick:l,tip:n.enabled?void 0:s,children:[(0,q.jsx)(Py,{}),`Note…`]}),(0,q.jsx)(NC,{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,q.jsx)(WU,{node:t,onDone:()=>{a(!1)},onSend:r,runId:e})})]})},qU={enabled:!0},JU=(e,t,n)=>n.enabled?`${e} ${t}`:`${e} ${t}: ${n.why}`,YU=`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.`,XU=({runId:e,action:t})=>{let n=ob(),[r,i]=(0,U.useState)(!1),a=(0,U.useRef)(!1),o=`ork resume ${e} --detach`;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(Y,{"aria-label":JU(`Resume`,`run`,t),cli:o,disabled:!t.enabled,focusableWhenDisabled:!0,onClick:()=>{i(!0)},tip:t.enabled?void 0:t.why,variant:`ghost`,children:[(0,q.jsx)($y,{}),`Resume…`]}),(0,q.jsx)(FC,{cli:o,confirm:`Resume run`,description:YU,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`})]})},ZU=({runId:e,node:t,actions:n,note:r=qU})=>{let i=ob(),[a,o]=(0,U.useState)(!1),s=t??`run`,c=t===void 0?``:` --node ${t}`,l=n=>{i.control(n,e,t).then(e=>(e.ok||tb.add({title:`Could not ${n} ${s}`,description:e.error}),e))},u=(0,q.jsx)(KU,{check:r,node:t,onSend:async n=>{let r=await i.client.call(`note`,{params:{id:e},body:n});return r.ok?(tb.add(HU(e,t,r.data.item)),null):`Could not add the note: ${r.error}`},runId:e});return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{"aria-label":t===void 0?`Run controls`:`Controls for ${t}`,className:tU.controls,role:`group`,children:[(0,q.jsx)(xb,{cli:`ork pause ${e}${c}`,disabled:!n.pause.enabled,focusableWhenDisabled:!0,label:JU(`Pause`,s,n.pause),onClick:()=>{l(`pause`)},children:(0,q.jsx)(ay,{})}),(0,q.jsx)(xb,{cli:`ork continue ${e}${c}`,disabled:!n.proceed.enabled,focusableWhenDisabled:!0,label:JU(`Continue`,s,n.proceed),onClick:()=>{l(`continue`)},children:(0,q.jsx)(iy,{})}),(0,q.jsx)(xb,{cli:`ork stop ${e}${c}`,disabled:!n.stop.enabled,focusableWhenDisabled:!0,label:JU(`Stop`,s,n.stop),onClick:()=>{o(!0)},children:(0,q.jsx)(oy,{})}),(0,q.jsx)(FC,{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,q.jsx)(XU,{action:n.resume,runId:e}),t===void 0?u:null]}),t===void 0?null:u]})},QU={s:1e3,m:6e4,h:36e5},$U=e=>{let t=/^(\d+)([smh])$/u.exec(e);return Number(t?.[1]??0)*(QU[t?.[2]??`s`]??1e3)},eW=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`},tW=e=>e===`running`||e===`paused`,nW=(e,t)=>{let n=$U(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 ${eW(n===0?0:n-r%n)}`,said:e.said}},rW=5e3,iW=({watching:e})=>{let[t,n]=(0,U.useState)(Date.now);(0,U.useEffect)(()=>{let e=setInterval(()=>{n(Date.now())},rW);return()=>{clearInterval(e)}},[]);let r=nW(e,t);return(0,q.jsxs)(`dl`,{className:tU.watching,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Waiting until`}),(0,q.jsx)(`dd`,{children:(0,q.jsx)(`code`,{children:r.until})})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Looks`}),(0,q.jsxs)(`dd`,{children:[r.looks,`, `,r.every]})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Next look`}),(0,q.jsx)(`dd`,{children:r.next})]}),r.said===void 0?null:(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Last said`}),(0,q.jsx)(`dd`,{children:(0,q.jsx)(`code`,{children:r.said})})]})]})},aW=({run:e,node:t,progress:n,sectionRef:r,onLeave:i,onOpenRun:a})=>{let{calledRun:o}=t,s=iU(t);return(0,q.jsxs)(`section`,{"aria-label":`Node ${t.id}`,className:tU.node,onKeyDown:e=>{let t=document.querySelector(`[data-modal]`)!==null;e.key===`Escape`&&!t&&i()},ref:r,children:[(0,q.jsx)(`h3`,{className:tU.sideTitle,children:t.id}),(0,q.jsxs)(`dl`,{className:tU.nodeFacts,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Type`}),(0,q.jsx)(`dd`,{children:eM(t.type)})]}),n===void 0?null:(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Items`}),(0,q.jsx)(`dd`,{children:n})]}),s===void 0||t.template===void 0?null:(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Item`}),(0,q.jsxs)(`dd`,{children:[`of `,(0,q.jsx)(`code`,{children:t.template}),`, index `,s]})]}),s===void 0?null:(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Logs`}),(0,q.jsx)(`dd`,{children:(0,q.jsx)(`code`,{children:`ork logs ${e.id} --node ${t.id}`})})]}),t.model===void 0?null:(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Model`}),(0,q.jsx)(`dd`,{children:t.model})]}),t.inputTokens+t.outputTokens===0?null:(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Tokens`}),(0,q.jsxs)(`dd`,{children:[rM(t.inputTokens),` in ·`,` `,rM(t.outputTokens),` out`]})]})]}),t.end===void 0||t.end.actor===null?null:(0,q.jsx)(`div`,{className:tU.end,children:(0,q.jsx)(WH,{end:t.end,node:t.id,runId:e.id},t.id)}),(0,q.jsx)(ZU,{actions:TU(e,t),node:t.id,note:EU(t),runId:e.id}),t.watching===void 0||!tW(e.status)?null:(0,q.jsx)(iW,{watching:t.watching}),o===void 0?null:(0,q.jsxs)(Y,{onClick:()=>{a(o)},variant:`ghost`,children:[`Open run `,o]})]})},oW=new Set([`succeeded`,`failed`,`skipped`,`interrupted`]),sW=e=>e.length<2?e.join(``):`${e.slice(0,-1).join(`, `)} and ${e.at(-1)??``}`,cW=(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||!oW.has(i))}).map(({from:e})=>e);return r.length===0?``:`After ${sW([...new Set(r)])}`},lW=e=>`${e.charAt(0).toUpperCase()}${e.slice(1)}`,uW=(e,t,n,r,i,a)=>{if(a!==void 0){let n=t===`failed`?e.now??``:``;return n===``?a:`${a} · ${n}`}if(t===`queued`)return cW(e.id,n,r);if(e.watching!==void 0&&!oW.has(t)){let{looks:t,next:n}=nW(e.watching,i);return lW(`${t} ${t===`1`?`look`:`looks`}, next ${n}`)}return e.now??``},dW=({startedAt:e,finishedAt:t},n,r)=>{if(e===void 0)return`–`;let i=t??n;return sM((i===void 0?r:Date.parse(i))-Date.parse(e))},fW=e=>{let t=[...e];return`${String(t.filter(e=>oW.has(e)).length)} / ${String(t.length)}`},pW=({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(` · `)},mW={status:`queued`},hW=({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,U.useState)(new Set),[p,m]=(0,U.useState)(r),[h,g]=(0,U.useState)(r);r!==h&&(g(r),r!==null&&m(r));let _=(0,U.useMemo)(()=>oU(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,aU(r)[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,q.jsxs)(`div`,{className:tU.table,children:[(0,q.jsxs)(`div`,{"aria-hidden":`true`,className:tU.tableHead,children:[(0,q.jsx)(`span`,{children:`Node`}),(0,q.jsx)(`span`,{className:tU.treeType,children:`Type`}),(0,q.jsx)(`span`,{children:`Status`}),(0,q.jsx)(`span`,{children:`Now`}),(0,q.jsx)(`span`,{className:tU.treeTime,children:`Time`}),(0,q.jsx)(`span`,{className:tU.treeCost,children:`Cost`})]}),(0,q.jsx)(`div`,{"aria-label":`Ownership tree`,className:tU.tree,role:`tree`,children:_.map(({node:e,depth:f},p)=>{let h=t.get(e.id)??mW,g=e.children.length>0,_=g&&!d.has(e.id),b=uW(e,h.status,i,S,o,h.progress);return(0,U.createElement)(`div`,{...l_(iU(e)===void 0?void 0:h.cli,n.get(e.id)),"aria-expanded":g?_:void 0,"aria-label":[cM(e.id,e.type,{...h,progress:void 0}),...b===``?[]:[b]].join(`, `),"aria-level":f,"aria-selected":e.id===r,className:tU.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,q.jsxs)(`span`,{className:tU.treeNode,style:{paddingInlineStart:`${String((f-1)*.75)}rem`},children:[C?(0,q.jsxs)(`span`,{"aria-hidden":`true`,className:tU.treeToggle,onClick:g?t=>{t.stopPropagation(),y(e.id,!_)}:void 0,children:[g&&_?(0,q.jsx)(ly,{}):null,g&&!_?(0,q.jsx)(uy,{}):null]}):null,(0,q.jsx)(`span`,{className:tU.treeId,children:e.id})]}),(0,q.jsx)(`span`,{className:tU.treeType,children:e.type}),(0,q.jsx)(`span`,{className:tU.treeStatus,children:(0,q.jsx)(Jj,{status:h.status})}),(0,q.jsx)(`span`,{className:tU.treeNow,children:b}),(0,q.jsx)(`span`,{className:tU.treeTime,children:dW(e,s,o)}),(0,q.jsx)(`span`,{className:tU.treeCost,children:h.unpriced===!0&&h.tokens!==void 0?(0,q.jsx)(hM,{count:h.tokens}):h.costUsd===void 0?`–`:nM(h.costUsd)}))})})]})},gW={ends:`_ends_mstds_6`,list:`_list_mstds_21`,row:`_row_mstds_30`,id:`_id_mstds_62`},_W=3,vW=new Set([`failed`,`crashed`,`budget_exhausted`,`quota_exhausted`,`timed_out`,`interrupted`]),yW=({run:e,roots:t,onSelect:n})=>{let[r,i]=(0,U.useState)(!1),a=oU(t).flatMap(({node:e})=>e.end===void 0||e.end.actor===null?[]:[{id:e.id,end:e.end,at:e.finishedAt??``}]).toSorted((e,t)=>e.at.localeCompare(t.at));if(!vW.has(e.live)||a.length===0)return null;let o=a.length-_W;return(0,q.jsxs)(`section`,{"aria-label":`Why the run stopped`,className:gW.ends,children:[(0,q.jsx)(`ul`,{className:gW.list,children:(r?a:a.slice(0,_W)).map(({id:e,end:t})=>(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{"aria-label":`Select ${e}: ${t.label}${t.transient?`, may pass`:``}, ${t.message}`,className:gW.row,onClick:()=>{n(e)},type:`button`,children:[(0,q.jsx)(PH,{end:t}),(0,q.jsx)(`span`,{className:gW.id,children:e}),(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:t.message})})]})},e))}),o<=0?null:(0,q.jsx)(Y,{"aria-expanded":r,onClick:()=>{i(e=>!e)},variant:`ghost`,children:r?`Show fewer`:`Show ${String(o)} more`})]})},bW=new Map;function xW(e,t){let n=JSON.stringify({locale:yx(e),options:t}),r=bW.get(n);if(r)return r;let i=new Intl.NumberFormat(e,t);return bW.set(n,i),i}function SW(e,t,n){return e==null?``:xW(t,n).format(e)}var CW=U.createContext(void 0);function wW(){let e=U.useContext(CW);if(e===void 0)throw Error(gc(38));return e}function TW(e,t,n){return(e-t)*100/(n-t)}var EW=U.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]=U.useState(),h=TW(s,o,a),g=E_(Number.isNaN(h)?0:h,0,100),_=E_(Number.isNaN(s)?o:s,o,a),v=n?SW(_,i,n):SW(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,q.jsxs)(U.Fragment,{children:[u,(0,q.jsx)(`span`,{role:`presentation`,style:Yu,children:`x`})]})},x=U.useMemo(()=>({formattedValue:v,percentageValue:g,setLabelId:m,value:s}),[v,g,m,s]),S=qf(`div`,e,{ref:t,props:[b,f]});return(0,q.jsx)(CW.Provider,{value:x,children:S})}),DW=U.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,{setLabelId:s}=wW();return qf(`span`,e,{ref:t,props:[{id:Mx(a,s),role:`presentation`},o]})}),OW={meter:`_meter_1pby1_6`,label:`_label_1pby1_15`,value:`_value_1pby1_31`,track:`_track_1pby1_39`,block:`_block_1pby1_47`},kW=.8,AW=20,jW=(e,t,n=AW)=>e>=t?n:e<=0?0:Math.min(Math.max(Math.round(e/t*n),1),n-1),MW=(e,t)=>e>=t?`full`:e>=t*kW?`high`:`normal`,NW=({value:e,max:t,blocks:n=AW})=>{let r=jW(e,t,n);return(0,q.jsx)(`span`,{"aria-hidden":`true`,className:OW.track,"data-level":MW(e,t),children:Array.from({length:n},(e,t)=>(0,q.jsx)(`span`,{className:OW.block,"data-on":t<r?``:void 0},t))})},PW=({label:e,value:t,max:n,text:r})=>(0,q.jsxs)(EW,{"aria-valuetext":r,className:OW.meter,"data-level":MW(t,n),max:n,value:Math.min(t,n),children:[(0,q.jsx)(DW,{className:OW.label,children:e}),(0,q.jsx)(`span`,{className:OW.value,children:r}),(0,q.jsx)(NW,{max:n,value:t})]}),FW=16,IW=({run:e,facts:t,budgetUsd:n,budgetTokens:r,now:i})=>{let a=pW(e),o=e.tokens===void 0||e.tokens===0?void 0:e.tokens;return(0,q.jsxs)(`dl`,{className:tU.stats,children:[(0,q.jsxs)(`div`,{className:tU.stat,children:[(0,q.jsxs)(`dt`,{className:tU.statName,children:[`Spent`,n===void 0?``:` · cap ${nM(n,[])}`,r===void 0?``:` · cap ${iM(r)} tokens`]}),(0,q.jsxs)(`dd`,{className:tU.statValue,children:[(0,q.jsx)(pM,{focusable:!0,partial:e.partial===!0,text:nM(e.costUsd)}),n===void 0?null:(0,q.jsx)(NW,{blocks:FW,max:n,value:e.costUsd})]}),o===void 0?null:(0,q.jsxs)(`dd`,{className:tU.statValue,children:[(0,q.jsx)(mM,{count:o}),r===void 0?null:(0,q.jsx)(NW,{blocks:FW,max:r,value:o})]})]}),(0,q.jsxs)(`div`,{className:tU.stat,children:[(0,q.jsx)(`dt`,{className:tU.statName,children:`Nodes`}),(0,q.jsxs)(`dd`,{className:tU.statValue,children:[fW([...t.values()].map(({status:e})=>e)),a===null?null:` · ${a}`]})]}),(0,q.jsxs)(`div`,{className:tU.stat,children:[(0,q.jsx)(`dt`,{className:tU.statName,children:`Elapsed`}),(0,q.jsx)(`dd`,{className:tU.statValue,children:sM((e.finishedAt===void 0?i:Date.parse(e.finishedAt))-Date.parse(e.startedAt))})]})]})},LW=({run:e,waiting:t})=>{let n=ob(),r=(0,U.use)(wL),i=vb(n.decisions)?.filter(({runId:t})=>t===e.id).length;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Jj,{pill:!0,status:vU(e,t)}),i===void 0||i===0?null:(0,q.jsxs)(Y,{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,q.jsx)(My,{}),i===1?`1 decision`:`${i} decisions`,` waiting`]})]})},RW=({run:e,waiting:t,facts:n,budgetUsd:r,budgetTokens:i,now:a})=>{let o=ob(),s=(0,U.useRef)(null),{parent:c}=e;return(0,U.useEffect)(()=>{o.takeArrival(e.id)&&s.current?.focus()},[o,e.id]),(0,q.jsxs)(`header`,{className:tU.header,children:[(0,q.jsxs)(`div`,{className:tU.stat,children:[(0,q.jsx)(`span`,{className:tU.statName,children:`Run`}),(0,q.jsxs)(`span`,{className:tU.statValue,children:[(0,q.jsx)(`h2`,{className:tU.title,"data-run-heading":e.id,ref:s,tabIndex:-1,children:e.workflow}),(0,q.jsx)(`code`,{className:tU.runId,children:e.id})]})]}),(0,q.jsx)(IW,{budgetTokens:i,budgetUsd:r,facts:n,now:a,run:e}),(0,q.jsx)(LW,{run:e,waiting:t}),c===void 0?null:(0,q.jsxs)(Y,{onClick:()=>{o.arriveAt(c)},variant:`ghost`,children:[`Called by `,c]}),(0,q.jsx)(ZU,{actions:wU(e),runId:e.id})]})},zW=({links:e,runId:t,onOpen:n})=>e.length===0?null:(0,q.jsxs)(`section`,{"aria-label":`Links to other runs`,className:tU.links,children:[(0,q.jsx)(`h3`,{className:tU.sideTitle,children:`Links`}),(0,q.jsx)(`ul`,{className:tU.linkList,children:e.map(e=>{let[r,i]=e.a.run===t?[e.a,e.b]:[e.b,e.a];return(0,q.jsxs)(`li`,{className:tU.link,children:[(0,q.jsxs)(`span`,{className:tU.linkEnds,children:[r.node,` ↔ `,i.run,`/`,i.node]}),(0,q.jsxs)(`span`,{className:tU.linkCount,children:[e.messages,`/`,e.maxMessages,e.endedAt===void 0?``:` · ended`]}),(0,q.jsx)(Y,{onClick:()=>{n(i.run)},variant:`ghost`,children:`Open`})]},e.id)})})]}),BW=1e3,VW=e=>{let[t,n]=(0,U.useState)(Date.now);return(0,U.useEffect)(()=>{let t=e?setInterval(()=>{n(Date.now())},BW):void 0;return()=>{clearInterval(t)}},[e]),t},HW=1e3,UW=(e,t)=>{let n=(0,U.use)(wL),r=(0,U.useRef)(null),i=(0,U.useRef)([]),a=(0,U.useRef)(void 0),{id:o,live:s}=e;(0,U.useEffect)(()=>{if(t.size===0)return;let e=hU(s,t),c=r.current===null?[]:_U(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(` `))},HW))},[t,o,s,n]),(0,U.useEffect)(()=>()=>{clearTimeout(a.current)},[])},WW=e=>{let t=ob(),n=e.id,r=(0,U.useMemo)(()=>t.watchRun(n),[t,n]);(0,U.useEffect)(()=>{let e=t.retainRun(n),i=r.start();return()=>{i(),e()}},[t,r,n]);let{graph:i,tree:a,links:o,error:s}=vb(r.state),c=vb(t.decisions),{node:l}=vb(t.selection),u=(0,U.useRef)(null),d=(0,U.useRef)(null),f=(0,U.useMemo)(()=>a??[],[a]),p=e.live!==`running`&&e.live!==`paused`,m=(0,U.useMemo)(()=>uU(c,n),[c,n]),h=(0,U.useMemo)(()=>mU(f,m,n,p),[f,m,n,p]),g=oU(f).map(({node:e})=>e.id).join(`
104
+ `),_=(0,U.useMemo)(()=>i===null?null:aP(yU(i,f)),[i,g]),v=(0,U.useMemo)(()=>ij(_?.edges??[]),[_]),y=oU(f).find(({node:e})=>e.id===l)?.node,b=y!==void 0&&iU(y)!==void 0?y.template:void 0;UW(e,h);let x=(0,U.useCallback)(e=>{let{activeElement:n}=document;d.current=n instanceof HTMLElement?n:null,t.selectNode(e),requestAnimationFrame(()=>{u.current?.querySelector(`button`)?.focus()})},[t]),S=(0,U.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,holding:b,chosen:y,nodeControls:u,openControls:x,closeControls:S}},GW=({run:e})=>{let{state:t,graph:n,layout:r,facts:i,waiting:a,connections:o,roots:s,links:c,error:l,selected:u,holding:d,chosen:f,nodeControls:p,openControls:m,closeControls:h}=WW(e),[g,_]=(0,U.useState)(null),v=VW(e.live===`running`||e.live===`paused`);return(0,q.jsxs)(`div`,{className:tU.monitor,children:[(0,q.jsx)(RW,{budgetTokens:n?.budgetTokens,budgetUsd:n?.budgetUsd,facts:i,now:v,run:e,waiting:a}),l===null?null:(0,q.jsx)(nU,{error:l}),(0,q.jsx)(yW,{onSelect:t.selectNode,roots:s,run:e}),(0,q.jsx)(rU,{facts:i,holding:d,hovered:g,label:`Graph of run ${e.id}, ${e.workflow}`,layout:r,onHover:_,onNodeMenu:m,onSelect:t.selectNode,runId:e.id,selected:u??void 0}),(0,q.jsx)(hW,{connections:o,edges:n?.edges??[],facts:i,hovered:g,now:v,onHover:_,onNodeMenu:m,onSelect:t.selectNode,roots:s,runFinishedAt:e.finishedAt,selected:u}),f===void 0?null:(0,q.jsx)(aW,{node:f,progress:i.get(f.id)?.progress,onLeave:h,onOpenRun:t.arriveAt,run:e,sectionRef:p}),(0,q.jsx)(zW,{links:c,onOpen:t.arriveAt,runId:e.id})]})},KW=()=>{let e=ob(),{run:t}=vb(e.selection),n=vb(e.runs)?.find(({id:e})=>e===t);return n===void 0?(0,q.jsx)(JD,{cli:`ork tree <run>`,title:`No run chosen.`,children:`Choose one in the Runs panel, or in a terminal:`}):(0,q.jsx)(GW,{run:n},n.id)},qW=()=>`Notification`in globalThis,JW=async()=>qW()?await Notification.requestPermission()===`granted`?`granted`:`denied`:`unsupported`,YW=(e,t,n)=>{if(!qW()||Notification.permission!==`granted`||document.visibilityState===`visible`)return;let r=new Notification(`Ork`,{body:e,tag:t});r.addEventListener(`click`,()=>{window.focus(),n(),r.close()})},XW=(e,t)=>e.live===`running`&&t?`waiting`:e.live,ZW=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`})},QW=({paused:e,live:t})=>{let n=e.nodes.length;return t!==`running`||n===0?null:n===1?`1 node paused`:`${String(n)} nodes paused`},$W=(0,U.memo)(({run:e,selected:t,tabStop:n,waiting:r,onSelect:i})=>{let a=QW(e);return(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{"aria-current":t?`true`:void 0,className:hk.row,"data-run-row":e.id,onClick:()=>{i(e.id)},tabIndex:n?0:-1,type:`button`,children:[(0,q.jsxs)(`span`,{className:hk.rowTop,children:[(0,q.jsx)(`span`,{className:hk.workflow,children:e.workflow}),(0,q.jsx)(Jj,{status:XW(e,r)})]}),(0,q.jsxs)(`span`,{className:hk.rowMeta,children:[(0,q.jsx)(`span`,{children:e.id}),(0,q.jsx)(`time`,{dateTime:e.startedAt,children:ZW(e.startedAt)}),(0,q.jsxs)(`span`,{children:[(0,q.jsx)(pM,{partial:e.partial===!0,text:nM(e.costUsd)}),e.tokens===void 0||e.tokens===0?null:(0,q.jsxs)(q.Fragment,{children:[` · `,(0,q.jsx)(mM,{count:e.tokens,unit:`tok`})]})]}),a===null?null:(0,q.jsx)(`span`,{children:a})]})]})})});$W.displayName=`RunRow`;var eG=({onClick:e})=>(0,q.jsxs)(Y,{cli:`ork run <workflow>`,"data-run-workflow":``,onClick:e,variant:`primary`,children:[(0,q.jsx)(iy,{}),`Run workflow`]}),tG=({filtered:e})=>e?(0,q.jsx)(JD,{cli:`ork ps`,title:`No runs in this project.`,children:`Among the newest 50. For older ones:`}):(0,q.jsx)(JD,{cli:`ork run <workflow>`,title:`No runs yet.`,children:`Start one with Run workflow, or in a terminal:`}),nG={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`},rG=({item:e})=>{let t=ob(),n=(0,U.use)(wL);return(0,q.jsxs)(`li`,{className:nG.item,"data-notification":e.id,"data-unread":e.unread?``:void 0,children:[(0,q.jsx)(`p`,{className:nG.title,children:e.title}),(0,q.jsxs)(`p`,{className:nG.meta,children:[(0,q.jsx)(Jj,{status:e.status}),(0,q.jsx)(`span`,{children:ZW(e.at)}),e.unread?(0,q.jsx)(`span`,{className:nG.unread,children:`unread`}):null]}),(0,q.jsxs)(`p`,{className:nG.actions,children:[(0,q.jsx)(Y,{"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,q.jsx)(Y,{"aria-label":`Mark read: ${e.title}`,disabled:!e.unread,focusableWhenDisabled:!0,onClick:()=>{t.notifications.markRead(e.id)},variant:`ghost`,children:`Mark read`})]})]})},iG={denied:`The browser refused. Allow notifications for this page in its settings.`,unsupported:`This browser has no desktop notifications.`},aG=()=>{let{notifications:e,preferences:t}=ob(),{items:n,unread:r}=vb(e.view),{desktopNotifications:i}=vb(t.value),[a,o]=(0,U.useState)(null),{panel:s,onFocus:c}=EH(n.map(({id:e})=>e).join(`
105
+ `),`[data-notification]`),l=async e=>{if(o(null),!e){t.update({desktopNotifications:!1});return}let n=await JW();n===`granted`?t.update({desktopNotifications:!0}):o(iG[n])};return(0,q.jsxs)(`div`,{"aria-label":`Notifications`,className:nG.panel,onFocus:c,ref:s,role:`group`,tabIndex:-1,children:[(0,q.jsxs)(`div`,{className:nG.tools,children:[(0,q.jsx)(yO,{checked:i,label:`Desktop notifications`,onChange:e=>{l(e)}}),(0,q.jsx)(Y,{disabled:r===0,focusableWhenDisabled:!0,onClick:e.markAllRead,variant:`ghost`,children:`Mark all read`})]}),(0,q.jsxs)(`div`,{className:nG.main,children:[a===null?null:(0,q.jsx)(`p`,{className:nG.refused,role:`alert`,children:a}),n.length===0?(0,q.jsx)(JD,{title:`Nothing yet.`,children:`Decisions, and runs that end, crash or pause, land here.`}):(0,q.jsx)(`ul`,{className:nG.list,children:n.map(e=>(0,q.jsx)(rG,{item:e},e.id))})]})]})},oG=e=>e.split(`/`).at(-1)??e,sG=e=>e.split(`/`).slice(-2).join(`/`),cG=(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,oG(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)?sG(e):t})).toSorted((e,t)=>e.label.localeCompare(t.label))]},lG=3e4,uG={live:`Live`,new:`Off: new, not accepted yet`,changed:`Off: changed since it was accepted`,invalid:`Off: it has an error`},dG={new:`ork watch --accept`,changed:`ork watch --accept`,invalid:`ork validate`},fG=e=>new Date(e).toLocaleTimeString(void 0,{timeStyle:`short`}),pG=e=>[uG[e.standing],...e.lookedAt===void 0?[]:[`Last looked ${fG(e.lookedAt)}`],...e.error===void 0?[]:[`Last look failed: ${e.error}`],...e.held===void 0?[]:[`Waiting: ${e.held}`]],mG=()=>{let{triggers:e}=ob(),t=vb(e.state);(0,U.useEffect)(()=>{e.load();let t=setInterval(()=>{e.load()},lG);return()=>{clearInterval(t)}},[e]);let n=mH(t)?.data;return n===void 0||n.triggers.length===0?null:(0,q.jsxs)(`section`,{"aria-label":`Triggers`,className:hk.triggers,children:[(0,q.jsx)(`h3`,{className:hk.triggersTitle,children:`Triggers`}),n.pid===void 0?(0,q.jsxs)(`p`,{className:hk.note,children:[(0,q.jsx)(`code`,{children:`ork watch`}),` isn't running, so nothing is looking.`]}):null,(0,q.jsx)(`ul`,{className:hk.triggerList,children:n.triggers.map(e=>(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:hk.triggerName,children:e.trigger}),` starts `,(0,q.jsx)(`code`,{children:e.run}),`, every ${e.every}`,pG(e).map(e=>(0,q.jsx)(`span`,{className:hk.triggerLine,children:(0,q.jsx)(r_,{text:e})},e)),dG[e.standing]===void 0?null:(0,q.jsx)(`span`,{className:hk.triggerCommand,children:(0,q.jsx)(cC,{command:dG[e.standing]??``})})]},`${e.project}/${e.trigger}`))})]})},hG=e=>_b(e.decisions,e=>new Set((e??[]).map(({runId:e})=>e))),gG=e=>{let t=vb(e.projects.state);return(0,U.useEffect)(()=>{e.projects.load()},[e]),t.status===`ready`?t.data:[]},_G=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())},vG=()=>{let e=ob(),t=vb(e.runs),n=vb(e.runFilter),r=_b(e.selection,({run:e})=>e),i=hG(e),a=gG(e),o=(0,U.useMemo)(()=>t??[],[t]),s=(0,U.useMemo)(()=>cG(a,o),[a,o]),c=(0,U.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,q.jsxs)(`div`,{className:hk.panel,children:[(0,q.jsxs)(`div`,{className:hk.tools,children:[(0,q.jsx)(dk,{label:`Project`,onChange:t=>{e.runFilter.setValue(t)},options:s,value:n}),(0,q.jsx)(eG,{onClick:()=>{e.runDialog.setValue(!0)}})]}),(0,q.jsx)(`div`,{className:hk.main,children:t===null?(0,q.jsx)(`p`,{className:hk.note,children:`Reading runs…`}):c.length===0?(0,q.jsx)(tG,{filtered:n!==`all`}):(0,q.jsx)(`ul`,{"aria-label":`Runs`,className:hk.list,onKeyDown:_G,children:c.map(t=>(0,q.jsx)($W,{onSelect:e.selectRun,run:t,selected:t.id===r,tabStop:t.id===l,waiting:i.has(t.id)},t.id))})}),(0,q.jsx)(mG,{})]})},yG=e=>e.toLocaleString(`en`),bG=e=>`≈${yG(e)}`,xG=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}.`},SG=e=>e.reduce((e,t)=>e+(t.tokens??0),0),CG=e=>{let t=e.filter(e=>e.state===`live`).length,n=e.length-t;return n===0?`${yG(t)} live`:`${yG(t)} live, ${yG(n)} off`},wG=(e,t,n=0)=>{let r=`${t(e.length)} · ${bG(SG(e))}`;return n===0?r:`${r}, ${yG(n)} off`},TG=e=>`${yG(e)} ${e===1?`file`:`files`}`,EG=e=>`${yG(e)} live`,DG=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 ${yG(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:bG(SG(t)),empty:`No agent fills this node.`,pieces:t},{id:`instructions`,title:`Project instructions`,meta:bG(SG(n)),description:`Claude Code reads these itself; they aren't appended.`,empty:xG(e.instructions),pieces:n},{id:`skills`,title:`Skills`,meta:r.length===0?`none`:CG(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:wG(i,TG),empty:`No context files.`,pieces:i},{id:`practices`,title:`Practices`,meta:wG(a.filter(e=>e.state===`live`),EG,e.skippedPractices.length),empty:`No practices.`,pieces:a},{id:`appended`,title:`Appended system prompt`,meta:bG(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`}]}]},OG=(e,t)=>t?`Couldn't update: ${xG(e)} This is the answer from before.`:`Couldn't read the context: ${xG(e)}`,kG=e=>e===``?0:e.replace(/\n$/u,``).split(`
106
+ `).length,AG=(e,t)=>{let n=t.endsWith(`/`)?t:`${t}/`;return e.startsWith(n)?e.slice(n.length):e},jG=(e,t)=>`ork context explain ${e} ${t}`,MG={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`},NG=({text:e})=>e.split(`≈`).map((e,t)=>t===0?e:(0,q.jsxs)(`span`,{children:[(0,q.jsx)(`span`,{"aria-hidden":`true`,children:`≈`}),(0,q.jsx)(`span`,{className:MG.visuallyHidden,children:`about `}),e]},t)),PG=({name:e,value:t})=>(0,q.jsxs)(`div`,{className:MG.fact,children:[(0,q.jsx)(`dt`,{className:MG.factName,children:e}),(0,q.jsx)(`dd`,{className:MG.factValue,children:(0,q.jsx)(NG,{text:t})})]}),FG=({node:e,type:t,from:n,appendedTokens:r,planned:i,reload:a,updating:o,cli:s,onReload:c,titleRef:l,children:u})=>(0,q.jsxs)(`header`,{className:MG.header,children:[(0,q.jsxs)(`dl`,{className:MG.facts,children:[(0,q.jsxs)(`div`,{className:MG.fact,children:[(0,q.jsx)(`dt`,{className:MG.factName,children:`Node`}),(0,q.jsx)(`dd`,{className:MG.factValue,children:(0,q.jsx)(`h2`,{className:MG.title,ref:l,tabIndex:-1,children:e})})]}),t===void 0?null:(0,q.jsx)(PG,{name:`Type`,value:t}),(0,q.jsx)(PG,{name:`From`,value:n}),r===void 0?null:(0,q.jsx)(PG,{name:`Appended`,value:`${bG(r)} tokens`})]}),(0,q.jsxs)(`div`,{className:MG.plannedLine,children:[i===null?null:(0,q.jsx)(`p`,{className:MG.planned,children:i}),o?(0,q.jsx)(`span`,{className:MG.updating,children:`Updating…`}):null,(0,q.jsx)(Y,{cli:s,onClick:c,variant:`ghost`,children:a})]}),u]}),IG=e=>`Changed after this run started: ${e.map(e=>`\`${e}\``).join(`, `)}. The run may have read ${e.length===1?`an older version`:`older versions`}.`,LG=({answer:e,error:t})=>{let n=e?.changedSinceStart??[],r=e?.planned===!0?e.explanation:null;return(0,q.jsxs)(q.Fragment,{children:[n.length===0?null:(0,q.jsxs)(`p`,{className:MG.notice,"data-note":`changed`,children:[(0,q.jsx)(`span`,{className:MG.noticeIcon,children:(0,q.jsx)(My,{})}),(0,q.jsx)(`span`,{className:MG.noticeWords,children:(0,q.jsx)(r_,{text:IG(n)})})]}),r?.template===void 0?null:(0,q.jsx)(`p`,{className:MG.notice,"data-note":`spawned`,children:(0,q.jsx)(`span`,{className:MG.noticeWords,children:(0,q.jsx)(r_,{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,q.jsxs)(`p`,{className:MG.notice,"data-note":`failed`,children:[(0,q.jsx)(`span`,{className:MG.noticeIcon,children:(0,q.jsx)(Ij,{})}),(0,q.jsx)(`span`,{className:MG.noticeWords,children:(0,q.jsx)(r_,{text:OG(t,e!==null)})})]})]})},RG=({why:e})=>(0,q.jsxs)(`div`,{className:MG.card,children:[(0,q.jsx)(`p`,{className:MG.cardTitle,children:`No context to show.`}),(0,q.jsx)(`p`,{className:MG.description,children:(0,q.jsx)(r_,{text:xG(e)})})]}),zG=({cli:e,draft:t,sized:n})=>(0,q.jsxs)(`footer`,{className:MG.foot,children:[t?(0,q.jsx)(`p`,{className:MG.description,children:`The CLI reads the saved file, not the draft.`}):null,(0,q.jsx)(cC,{command:e}),n?(0,q.jsx)(`p`,{className:MG.description,children:`Tokens are estimates, about four characters each.`}):null]}),BG=({target:e})=>e?.kind===`run`?(0,q.jsx)(JD,{title:`No node chosen in this run.`,children:`Choose one in the Monitor, Logs or Chats.`}):e?.kind===`builder`?(0,q.jsx)(JD,{title:`No node selected in the Builder.`,children:`Select a card to see what its session loads.`}):(0,q.jsx)(JD,{cli:`ork context explain <workflow> <node>`,title:`No node chosen.`,children:`Choose one in the Monitor or the Builder, or in a terminal:`}),VG=({words:e,more:t})=>{let n=`${e}${t?`, `:``}`;return n===``?null:(0,q.jsx)(`span`,{className:MG.visuallyHidden,children:n})},HG=({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,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:MG.mark,"data-state":e.state,children:e.state===void 0?null:e.state===`live`?(0,q.jsx)(cy,{}):(0,q.jsx)(Yy,{})}),(0,q.jsxs)(`span`,{className:MG.name,children:[e.name,(0,q.jsx)(VG,{more:n(0),words:``})]}),r?(0,q.jsxs)(`span`,{className:MG.details,children:[e.state===void 0?null:(0,q.jsxs)(`span`,{className:MG.state,children:[e.state,(0,q.jsx)(VG,{more:n(1),words:``})]}),e.layer===void 0?null:(0,q.jsxs)(`span`,{className:MG.layer,children:[e.layer,(0,q.jsx)(VG,{more:n(2),words:` layer`})]}),e.source===void 0?null:(0,q.jsxs)(`span`,{className:MG.source,children:[e.source,(0,q.jsx)(VG,{more:n(3),words:``})]})]}):null,e.tokens===void 0?null:(0,q.jsxs)(`span`,{className:MG.tokens,children:[(0,q.jsx)(NG,{text:bG(e.tokens)}),(0,q.jsx)(VG,{more:!1,words:` tokens`})]})]})},UG=({piece:e,id:t})=>{let n=e.text??``,r=kG(n);return(0,q.jsxs)(`div`,{className:MG.well,id:t,children:[(0,q.jsxs)(`div`,{className:MG.wellBar,children:[(0,q.jsx)(`span`,{className:MG.wellPlace,children:e.place}),(0,q.jsx)(`span`,{children:(0,q.jsx)(NG,{text:`${r.toLocaleString(`en`)} ${r===1?`line`:`lines`}${e.tokens===void 0?``:` · ${bG(e.tokens)} tokens`}`})}),(0,q.jsx)(`span`,{className:MG.wellCopy,children:(0,q.jsx)(oC,{label:`Copy the text of ${e.name}`,resultClass:MG.copied,text:n})})]}),n===``?(0,q.jsx)(`p`,{className:MG.emptyText,children:e.key===`appended`?`Nothing is appended.`:`This file is empty.`}):(0,q.jsx)(`pre`,{className:MG.text,children:n})]})},WG=({piece:e,open:t,onToggle:n})=>{let r=(0,U.useId)(),i=`${r}-why`,a=`${r}-text`,o=e.state??`live`,s=e.why===void 0?null:(0,q.jsx)(`p`,{className:MG.why,id:i,children:(0,q.jsx)(r_,{text:xG(e.why)})});return e.text===void 0?(0,q.jsxs)(`li`,{className:MG.item,children:[(0,q.jsxs)(`div`,{className:MG.row,"data-state":o,children:[(0,q.jsx)(`span`,{className:MG.toggle}),(0,q.jsx)(HG,{piece:e})]}),s]}):(0,q.jsxs)(`li`,{className:MG.item,children:[(0,q.jsxs)(`button`,{"aria-controls":t?a:void 0,"aria-describedby":e.why===void 0?void 0:i,"aria-expanded":t,className:MG.row,"data-piece":e.key,"data-state":o,onClick:()=>{n(e.key)},type:`button`,children:[(0,q.jsx)(`span`,{className:MG.toggle,children:t?(0,q.jsx)(ly,{}):(0,q.jsx)(uy,{})}),(0,q.jsx)(HG,{piece:e})]}),s,t?(0,q.jsx)(UG,{id:a,piece:e}):null]})},GG=({sections:e,opened:t,onToggle:n,busy:r})=>(0,q.jsx)(`div`,{"aria-busy":r,className:MG.stack,children:e.map(e=>(0,q.jsxs)(`section`,{className:MG.section,children:[(0,q.jsxs)(`div`,{className:MG.sectionHead,children:[(0,q.jsx)(`h3`,{className:MG.heading,children:e.title}),(0,q.jsx)(`span`,{className:MG.meta,children:(0,q.jsx)(NG,{text:e.meta})})]}),e.description===void 0?null:(0,q.jsx)(`p`,{className:MG.sectionNote,children:(0,q.jsx)(r_,{text:e.description})}),e.pieces.length===0?(0,q.jsx)(`p`,{className:MG.sectionNote,children:(0,q.jsx)(r_,{text:e.empty})}):(0,q.jsx)(`ul`,{className:MG.list,children:e.pieces.map(e=>(0,q.jsx)(WG,{onToggle:n,open:t.has(e.key),piece:e},e.key))})]},e.id))}),KG=e=>e.kind===`run`?`run/${e.run}/${e.node}`:`builder/${e.project}/${e.workflow}/${e.node}`,qG={answer:null,error:null,loading:!0},JG=e=>{let{client:t}=ob(),n=(0,U.use)(wL),[r,i]=(0,U.useState)(qG),a=(0,U.useRef)(!1);a.current=r.answer!==null;let[o,s]=(0,U.useState)(0),c=e.kind===`builder`?e.revision:0,l=KG(e);(0,U.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(OG(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,U.useCallback)(()=>{s(e=>e+1)},[]);return{...r,reload:u}},YG=e=>{let t=vb(ob().runs);if(e.kind===`builder`)return{from:`Builder · ${e.workflow}${e.draft?` · draft`:``}`,cli:jG(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:jG(n===void 0?`<workflow>`:AG(n.file,n.project),e.node),planned:`Planned from the project's files as they are now.`}},XG=({target:e,hadFocus:t})=>{let{answer:n,error:r,loading:i,reload:a}=JG(e),o=YG(e),[s,c]=(0,U.useState)(new Set),l=(0,U.useRef)(null),u=(0,U.useRef)(null),d=(0,U.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,U.useMemo)(()=>f===null?[]:DG(f),[f]),m=n===null?r===null?`loading`:`failed`:`shown`,h=(0,U.useRef)(null);return(0,U.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,q.jsxs)(`div`,{className:MG.panel,ref:l,children:[(0,q.jsx)(FG,{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,q.jsx)(LG,{answer:n,error:r})}),n?.planned===!1?(0,q.jsx)(RG,{why:n.why}):null,f===null?null:(0,q.jsx)(GG,{busy:i,onToggle:d,opened:s,sections:p}),n===null&&r===null?(0,q.jsx)(`p`,{"aria-busy":`true`,className:MG.card,children:(0,q.jsx)(`span`,{className:MG.description,children:`Planning ${e.node}…`})}):null,m===`loading`?null:(0,q.jsx)(zG,{cli:o.cli,draft:e.kind===`builder`&&e.draft,sized:f!==null})]})},ZG=({target:e,hadFocus:t})=>{let n=(0,U.useRef)(null);return(0,U.useEffect)(()=>{let e=document.activeElement;(e===null||e===document.body)&&t.current&&n.current?.focus()},[t]),(0,q.jsx)(`div`,{ref:n,tabIndex:-1,children:(0,q.jsx)(BG,{target:e})})},QG=({target:e,hadFocus:t})=>{if(e===null||e.node===null)return(0,q.jsx)(ZG,{hadFocus:t,target:e});let n={...e,node:e.node};return(0,q.jsx)(XG,{hadFocus:t,target:n},KG(n))},$G=()=>{let e=vb(ob().contextTarget),t=(0,U.useRef)(!1);return(0,q.jsx)(`div`,{className:MG.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,q.jsx)(QG,{hadFocus:t,target:e})})},eK=e=>e.slice(0,12),tK=[[`open`,`Not dismissed`],[`all`,`All`],[`new`,`New`],[`triaged`,`Triaged`],[`accepted`,`Accepted`],[`resolved`,`Resolved`],[`published`,`Published`],[`dismissed`,`Dismissed`]],nK=[{value:`all`,label:`All`},{value:`ork`,label:`ork`},{value:`workflow`,label:`workflow`},{value:`project`,label:`project`}],rK=(e,t)=>t===`all`?!0:t===`open`?e.status!==`dismissed`:e.status===t,iK=e=>tK.map(([t,n])=>({value:t,label:`${n} · ${String(e.filter(e=>rK(e,t)).length)}`})),aK=(e,t,n)=>e?n===null?`list`:t:`both`,oK=(e,{status:t,about:n})=>e.filter(e=>rK(e,t)&&(n===`all`||e.target===n)),sK=(e,t,n)=>e===1?`1 ${t}`:`${e.toLocaleString(`en`)} ${n}`,cK=e=>sK(e,`item`,`items`),lK=e=>sK(e,`time`,`times`),uK=e=>sK(e,`run`,`runs`),dK={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`},fK=({status:e,about:t})=>{let n=dK[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.`}},pK=(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)]},mK=(e,t)=>e.find(e=>e.merged.includes(t)),hK={ok:!1,why:`reading what it allows`},gK=(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}},_K=e=>{let t=e.lessons,[n]=t;return t.every(e=>!e.ok)&&n!==void 0&&!n.ok?n.error:void 0},vK=(e,t)=>{let n=eK(e.id),r=e=>{if(t===null)return hK;let{actions:n,project:r}=t;return e===`lesson`?gK(n.lesson,_K(t)):e===`apply`?gK(n.apply,r.ok?void 0:r.error):gK(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`)}]},yK=(e,t)=>t.ok?e:`${e}: ${t.why}`,bK=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.`,xK=({item:e,id:t,root:n,acts:r,open:i,onOpenChange:a})=>{let[o,s]=(0,U.useState)(``),c=(0,U.useRef)(!1);return(0,q.jsx)(FC,{cli:`ork feedback apply ${t}${o===``?``:` --driver ${o}`}`,confirm:`Start run`,description:bK(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,q.jsx)(vk,{onChange:s,value:o})})},SK=(e,t)=>`about ${e.toLocaleString(`en`)} of ${t.toLocaleString(`en`)} tokens`,CK=(e,t,n)=>[`ork feedback accept ${eK(e.id)} --lesson`,...t===null||e.workflows.length<2?[]:[`--workflow ${Mk(t)}`],...n===e.title||n.trim()===``?[]:[`-m ${Mk(n)}`]].join(` `),wK=(e,t,n)=>e===null?`Choose a workflow.`:t.trim()===``?`Write the lesson first.`:n!==void 0&&!n.ok?n.error:null,TK=({place:e,cap:t})=>e.ok?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`p`,{className:OU.place,children:[(0,q.jsx)(`span`,{className:OU.caption,children:`Goes to `}),(0,q.jsx)(r_,{text:`\`${e.file}\` in \`${e.root}\``})]}),(0,q.jsx)(PW,{label:`Now`,max:t,text:e.exists?SK(e.tokens,t):`no lessons file yet; this starts it`,value:e.tokens})]}):(0,q.jsx)(`p`,{className:OU.note,children:(0,q.jsx)(r_,{text:e.error})}),EK=({open:e,onOpenChange:t,item:n,detail:r,onAdd:i})=>{let a=n.workflows.length>1,[o,s]=(0,U.useState)(a?null:n.workflows[0]??null),[c,l]=(0,U.useState)(n.title),[u,d]=(0,U.useState)(!1),[f,p]=(0,U.useState)(null),m=(0,U.useId)(),h=r.lessons.find(e=>e.workflow===o),g=wK(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,q.jsx)(NC,{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,q.jsxs)(AU,{onSend:()=>{_()},children:[a?(0,q.jsx)(dk,{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,q.jsx)(mk,{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,q.jsx)(TK,{cap:r.lessonCap,place:h}),(0,q.jsx)(cC,{command:CK(n,o,c)}),(0,q.jsx)(jU,{id:m,why:g}),(0,q.jsx)(MU,{text:f}),(0,q.jsxs)(PC,{children:[(0,q.jsx)(Y,{disabled:u,onClick:()=>{t(!1)},type:`button`,variant:`ghost`,children:`Cancel`}),(0,q.jsx)(Y,{"aria-describedby":m,"aria-keyshortcuts":kU,disabled:g!==null||u,focusableWhenDisabled:!0,type:`submit`,variant:`primary`,children:u?`Adding…`:`Add lesson`})]})]})})},DK={slot:`_slot_17gek_6`,alert:`_alert_17gek_17`},OK=({id:e,words:t,takeFocus:n,onTryAgain:r})=>{let i=(0,U.useRef)(null);return(0,U.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,q.jsxs)(`div`,{className:DK.slot,ref:i,children:[(0,q.jsx)(`p`,{className:DK.alert,id:e,role:`alert`,children:t===null?null:(0,q.jsx)(r_,{text:t})}),t===null||r===void 0?null:(0,q.jsx)(Y,{onClick:r,variant:`ghost`,children:`Try again`})]})},kK=({url:e})=>(0,q.jsxs)(`a`,{className:OU.link,href:e,rel:`noreferrer`,target:`_blank`,children:[e,(0,q.jsx)(Fy,{}),(0,q.jsx)(uk,{children:` (opens in a new tab)`})]}),AK=({preview:e})=>e.plan.kind===`create`?(0,q.jsx)(`p`,{className:OU.message,children:(0,q.jsx)(r_,{text:`A new thread in the Agent feedback category of \`${e.repo}\`.`})}):(0,q.jsxs)(`p`,{className:OU.message,children:[`A thread for this exists, so this goes on it as a +1 comment:`,` `,(0,q.jsx)(kK,{url:e.plan.url})]}),jK="Reading Ork's Discussions with your `gh`…",MK=`Nothing to show: the preview couldn't be read.`,NK=({id:e})=>(0,q.jsx)(`span`,{className:OU.note,id:e,children:`From the last read`}),PK=({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,q.jsxs)(q.Fragment,{children:[e===void 0||!a?null:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:OU.line,children:[(0,q.jsx)(`p`,{className:OU.caption,children:`Title`}),c?(0,q.jsx)(NK,{}):null]}),(0,q.jsx)(`p`,{className:OU.preview,"data-stale":r?``:void 0,children:e.post.title})]}),(0,q.jsxs)(`div`,{className:OU.wellHead,children:[(0,q.jsxs)(`div`,{className:OU.line,children:[(0,q.jsx)(`p`,{className:OU.caption,children:s}),c?(0,q.jsx)(NK,{id:i}):null]}),o===``?null:(0,q.jsx)(`span`,{className:OU.wellCopy,children:(0,q.jsx)(oC,{label:`Copy the ${s.toLowerCase()}`,text:o})})]}),(0,q.jsx)(`section`,{"aria-busy":t,"aria-describedby":c?i:void 0,"aria-label":`Text to post`,className:OU.preview,"data-scrolls":``,"data-stale":r?``:void 0,ref:n,tabIndex:0,children:o===``?(0,q.jsx)(r_,{text:t?jK:MK}):o}),(0,q.jsx)(`p`,{className:OU.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.`})]})},FK=({children:e})=>(0,q.jsxs)(`div`,{className:OU.dialogFoot,children:[(0,q.jsx)(`p`,{className:OU.note,children:(0,q.jsx)(r_,{text:"It posts with your own `gh` login."})}),(0,q.jsx)(`div`,{className:OU.actions,children:e})]}),IK=({id:e})=>(0,q.jsx)(`p`,{className:OU.note,id:e,children:(0,q.jsx)(r_,{text:"Your workflows' and projects' folders' names become `<name>`."})}),LK=({id:e,url:t,kind:n,onClose:r})=>{let i=(0,U.useRef)(null);return(0,U.useEffect)(()=>{i.current?.focus()},[]),(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`h3`,{className:OU.result,ref:i,tabIndex:-1,children:n===`created`?`Posted`:`Added a +1`}),(0,q.jsx)(`p`,{className:OU.message,children:(0,q.jsx)(kK,{url:t})}),(0,q.jsx)(`p`,{className:OU.message,children:`${e} is published.`}),(0,q.jsx)(`div`,{className:OU.actions,children:(0,q.jsx)(Y,{onClick:r,children:`Close`})})]})},RK=e=>e.step===`reading`||e.step===`readFailed`?e.shown:`preview`in e?e.preview:void 0,zK=e=>e.step===`reading`||e.step===`readFailed`,BK=e=>/[.!?]$/u.test(e.trim())?e.trim():`${e.trim()}.`,VK=(e,t,n)=>{let[r,i]=(0,U.useState)(!1),[a,o]=(0,U.useState)({step:`reading`}),s=(0,U.useRef)(0),c=(0,U.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=RK(e);return t===void 0?{step:`readFailed`,error:i.error}:{step:`readFailed`,error:i.error,shown:t}})},[e,t]);(0,U.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,RK(a))},tryAgain:()=>{a.step===`postFailed`?u(a.preview):l(r)},post:()=>{a.step===`preview`&&u(a.preview)}}},HK=`The text to post changed since you read it. Read it again before posting.`,UK=e=>e.step===`readFailed`?`Could not read Ork's Discussions: ${BK(e.error)} Nothing was sent.`:e.step===`postFailed`?`Could not post: ${BK(e.error)}`:null,WK=()=>{let e=document.activeElement;return e===null||e===document.body||e.getAttribute(`role`)===`dialog`},GK=e=>e.step===`reading`?`Reading the preview…`:null,KK=({client:e,item:t,id:n,region:r,onStep:i,onClose:a,onPosted:o})=>{let s=VK(e,t,o),{step:c,hideNames:l}=s,u=(0,U.useId)(),d=(0,U.useId)(),f=(0,U.useId)(),p=(0,U.useId)();if((0,U.useEffect)(()=>{i(c),c.step!==`posted`&&WK()&&r.current?.focus()},[c,i,r]),c.step===`posted`)return(0,q.jsx)(LK,{id:n,kind:c.kind,onClose:a,url:c.url});let m=RK(c),h=c.step===`posting`,g=m?.plan.kind===`comment`;return(0,q.jsxs)(q.Fragment,{children:[c.step===`preview`&&c.changed?(0,q.jsx)(`p`,{role:`alert`,children:HK}):null,m===void 0?null:(0,q.jsx)(AK,{preview:m}),(0,q.jsx)(PK,{preview:m,reading:c.step===`reading`,region:r,stale:zK(c),staleId:p}),(0,q.jsx)(vO,{checked:l,describedBy:u,disabled:h,label:`Hide repository and workflow names`,onChange:s.setHideNames}),(0,q.jsx)(IK,{id:u}),(0,q.jsx)(cC,{command:`ork feedback publish ${n}${l?` --hide-names`:``}`}),(0,q.jsx)(OK,{id:f,onTryAgain:s.tryAgain,takeFocus:c.step===`postFailed`?`always`:`ifLost`,words:UK(c)}),(0,q.jsx)(jU,{id:d,why:GK(c)}),(0,q.jsxs)(FK,{children:[(0,q.jsx)(Y,{disabled:h,focusableWhenDisabled:!0,onClick:a,variant:`ghost`,children:`Cancel`}),(0,q.jsx)(Y,{"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`})]})]})},qK=({open:e,onOpenChange:t,client:n,item:r,id:i,onPosted:a,onCancelled:o})=>{let s=(0,U.useRef)(null),c=(0,U.useRef)({busy:!1,tried:!1}),l=(0,U.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,q.jsx)(NC,{initialFocus:s,onOpenChange:e=>{e?t(!0):u()},open:e,size:`wide`,title:`Publish ${i} to Ork's Discussions`,children:(0,q.jsx)(KK,{client:n,id:i,item:r,onClose:u,onPosted:a,onStep:l,region:s})})},JK=({item:e,detail:t,acts:n})=>{let r=ob(),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(0),c=eK(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,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{"aria-label":`Actions on ${c}`,className:OU.actions,role:`group`,children:[vK(e,t).map(({key:e,word:t,cli:n,variant:r,check:i})=>(0,q.jsx)(Y,{"aria-label":yK(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,q.jsx)(Y,{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,q.jsx)(`p`,{className:OU.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,q.jsx)(EK,{detail:t,item:e,onAdd:r=>n.addLesson(e,r,t.lessonCap),onOpenChange:d,open:i===`lesson`},`lesson-${String(o)}`),(0,q.jsx)(xK,{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,q.jsx)(qK,{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]})},YK=({name:e,children:t})=>(0,q.jsxs)(`div`,{className:OU.fact,children:[(0,q.jsx)(`dt`,{className:OU.factName,children:e}),(0,q.jsx)(`dd`,{className:OU.factValue,children:t})]}),XK=({name:e,values:t})=>t.length===0?null:(0,q.jsx)(YK,{name:e,children:t.join(`, `)}),ZK=({item:e,onSplit:t})=>{let n=eK(e.id);return(0,q.jsxs)(`dl`,{className:OU.facts,children:[(0,q.jsx)(YK,{name:`Item`,children:n}),(0,q.jsx)(YK,{name:`About`,children:e.target}),(0,q.jsx)(YK,{name:`Kind`,children:e.kind}),(0,q.jsx)(YK,{name:`Severity`,children:e.severity}),(0,q.jsx)(YK,{name:`Seen`,children:(0,q.jsxs)(`span`,{children:[(0,q.jsx)(`span`,{"aria-hidden":`true`,children:`${String(e.count)}×`}),(0,q.jsx)(uk,{children:lK(e.count)}),` in ${uK(e.runs.length)}`]})}),(0,q.jsx)(YK,{name:`First seen`,children:(0,q.jsx)(`time`,{dateTime:e.firstSeen,children:ZW(e.firstSeen)})}),(0,q.jsx)(YK,{name:`Last seen`,children:(0,q.jsx)(`time`,{dateTime:e.lastSeen,children:ZW(e.lastSeen)})}),(0,q.jsx)(XK,{name:`Workflows`,values:e.workflows}),(0,q.jsx)(XK,{name:`Models`,values:e.models}),(0,q.jsx)(XK,{name:`Sources`,values:e.sources}),e.merged.length===0?null:(0,q.jsxs)(YK,{name:`Merged`,children:[e.merged.map(eK).join(`, `),(0,q.jsx)(Y,{cli:`ork feedback split ${n}`,onClick:t,variant:`ghost`,children:`Split`})]})]})},QK=({onBack:e})=>(0,q.jsxs)(Y,{onClick:e,variant:`ghost`,children:[(0,q.jsx)(dy,{}),`Back to items`]}),$K=({run:e,onOpen:t})=>(0,q.jsxs)(`p`,{className:OU.line,children:[(0,q.jsx)(`span`,{className:OU.lineIcon,children:(0,q.jsx)(iy,{})}),(0,q.jsxs)(`span`,{className:OU.message,children:[`Run `,(0,q.jsx)(`code`,{children:e}),` is proposing a fix.`]}),(0,q.jsx)(Y,{"aria-label":`Open run ${e}`,onClick:()=>{t(e)},variant:`ghost`,children:`Open run`})]}),eq=e=>[ZW(e.at),e.feedback.source,...e.feedback.code===void 0?[]:[e.feedback.code],`run ${e.runId}`,...e.node===void 0?[]:[e.node]].join(` · `),tq=({record:e,title:t,onOpenRun:n})=>{let{feedback:r,runId:i,node:a}=e;return(0,q.jsxs)(`li`,{className:OU.record,children:[(0,q.jsxs)(`p`,{className:OU.recordMeta,children:[(0,q.jsx)(`span`,{children:eq(e)}),(0,q.jsxs)(Y,{onClick:()=>{n(i,a)},variant:`ghost`,children:[`Open run`,(0,q.jsx)(uk,{children:` ${i}${a===void 0?``:` at ${a}`}, ${ZW(e.at)}`})]})]}),r.title===t?null:(0,q.jsx)(`h4`,{className:OU.recordTitle,children:r.title}),r.body===``?null:(0,q.jsx)(`p`,{className:OU.recordBody,children:r.body}),r.evidence.length===0?null:(0,q.jsxs)(`p`,{className:OU.evidence,children:[(0,q.jsx)(`span`,{className:OU.caption,children:`Evidence `}),r.evidence.join(`, `)]})]})},nq=({item:e,read:t,onOpenRun:n})=>{let r=eK(e.id),i=t.detail?.records;return(0,q.jsxs)(`div`,{className:OU.section,children:[(0,q.jsx)(`h3`,{className:OU.caption,children:i===void 0?`Records`:`Records · ${String(i.length)}, newest first`}),i===void 0&&t.error!==null?(0,q.jsxs)(`div`,{className:OU.line,children:[(0,q.jsx)(`p`,{className:OU.alert,role:`alert`,children:(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:`Could not read the records: ${t.error}`})})}),(0,q.jsx)(Y,{onClick:t.reload,variant:`ghost`,children:`Try again`})]}):null,i===void 0&&t.error===null?(0,q.jsx)(`p`,{"aria-busy":`true`,className:OU.message,children:`Reading records…`}):null,i===void 0?null:(0,q.jsx)(`ol`,{"aria-label":`Records of ${r}, newest first`,className:OU.records,role:`list`,children:i.toReversed().map(t=>(0,q.jsx)(tq,{onOpenRun:n,record:t,title:e.title},t.id))})]})},rq=({item:e,read:t,acts:n,narrow:r,onBack:i,onLeave:a})=>{let o=(0,U.useId)(),s=t.detail?.fixRun;return(0,q.jsxs)(`section`,{"aria-labelledby":o,className:OU.detail,onKeyDown:e=>{let t=document.querySelector(`[data-modal]`)!==null;e.key===`Escape`&&!t&&a()},children:[r?(0,q.jsx)(QK,{onBack:i}):null,(0,q.jsxs)(`div`,{className:OU.head,children:[(0,q.jsx)(`h2`,{className:OU.title,"data-feedback-heading":``,id:o,tabIndex:-1,children:e.title}),(0,q.jsx)(Xj,{pill:!0,status:e.status})]}),(0,q.jsx)(ZK,{item:e,onSplit:()=>{n.split(e)}}),s===void 0?null:(0,q.jsx)($K,{onOpen:n.openRun,run:s}),(0,q.jsx)(JK,{acts:n,detail:t.detail,item:e}),(0,q.jsx)(nq,{item:e,onOpenRun:n.openRun,read:t}),(0,q.jsx)(cC,{command:`ork feedback show ${e.id.slice(0,12)}`})]})},iq=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())},aq=()=>(0,q.jsx)(uk,{children:`, `}),oq=(0,U.memo)(({item:e,chosen:t,tabStop:n,onChoose:r})=>(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{"aria-current":t?`true`:void 0,className:OU.row,"data-item":e.id,onClick:()=>{r(e.id)},tabIndex:n?0:-1,type:`button`,children:[(0,q.jsxs)(`span`,{className:OU.rowTop,children:[(0,q.jsx)(`span`,{className:OU.rowTitle,children:e.title}),(0,q.jsx)(aq,{}),(0,q.jsx)(Xj,{status:e.status})]}),(0,q.jsx)(aq,{}),(0,q.jsxs)(`span`,{className:OU.rowMeta,children:[(0,q.jsx)(`span`,{children:eK(e.id)}),(0,q.jsx)(aq,{}),(0,q.jsxs)(`span`,{children:[(0,q.jsx)(`span`,{"aria-hidden":`true`,children:`${String(e.count)}×`}),(0,q.jsx)(uk,{children:lK(e.count)})]}),(0,q.jsx)(aq,{}),(0,q.jsx)(`span`,{children:`${e.target} · ${e.kind}`}),e.severity===`high`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(aq,{}),(0,q.jsx)(`span`,{className:OU.high,children:`high`})]}):null,e.merged.length===0?null:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(aq,{}),(0,q.jsx)(`span`,{children:`+${String(e.merged.length)} merged`})]}),(0,q.jsx)(aq,{}),(0,q.jsxs)(`span`,{children:[(0,q.jsx)(uk,{children:`last seen `}),(0,q.jsx)(`time`,{dateTime:e.lastSeen,children:ZW(e.lastSeen)})]})]})]})}));oq.displayName=`FeedbackRow`;var sq=({items:e,chosen:t,onChoose:n})=>{let r=e.some(({id:e})=>e===t)?t:e[0]?.id;return(0,q.jsx)(`ul`,{"aria-label":`Feedback items`,className:OU.list,onKeyDown:iq,role:`list`,children:e.map(e=>(0,q.jsx)(oq,{chosen:e.id===t,item:e,onChoose:n,tabStop:e.id===r},e.id))})},cq=({filter:e,items:t,count:n,updating:r,failed:i,onFilter:a,onReload:o})=>(0,q.jsxs)(`div`,{className:OU.tools,children:[(0,q.jsx)(dk,{label:`Status`,onChange:t=>{a({...e,status:t})},options:iK(t??[]),value:e.status}),(0,q.jsx)(dk,{label:`About`,onChange:t=>{a({...e,about:t})},options:nK,value:e.about}),(0,q.jsxs)(`div`,{className:OU.toolsEnd,children:[t===null?null:(0,q.jsx)(`span`,{className:OU.count,children:cK(n)}),r?(0,q.jsx)(`span`,{className:OU.updating,children:`Updating…`}):null,(0,q.jsx)(Y,{cli:e.status===`all`||e.status===`dismissed`?`ork feedback list --all`:`ork feedback list`,onClick:o,variant:`ghost`,children:i?`Try again`:`Reload`})]})]}),lq=({error:e})=>(0,q.jsxs)(`p`,{className:OU.alert,"data-tone":`failed`,role:`alert`,children:[(0,q.jsx)(`span`,{className:OU.lineIcon,children:(0,q.jsx)(My,{})}),(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:`Could not read feedback: ${e}`})})]}),uq=({anything:e,filter:t})=>{if(!e)return(0,q.jsx)(JD,{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}=fK(t);return(0,q.jsx)(JD,{title:n,children:r})},dq=(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())})},fq=e=>{let{state:t,workspace:n,filter:r,narrow:i,choose:a,focus:o}=e,s=(0,U.useRef)(!1),c=()=>mH(t.feedback.state.getValue())?.data??[],l=(e,r)=>{dq(t,n,e,r)},u=async()=>{await t.feedback.load(),e.reloadDetail()};return{moving:s,setStatus:async(e,l)=>{let d=eK(e.id),f=oK(c(),r),p=await t.client.call(`feedbackStatus`,{params:{id:e.id},body:{status:l}});if(!p.ok){let e=l===`new`?`restore`:`dismiss`;tb.add({title:`Could not ${e} ${d}`,description:p.error});return}s.current=!0,await u();let m=oK(c(),r);if(!m.some(({id:t})=>t===e.id)){let t=pK(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=eK(e.id),i=await t.client.call(`accept`,{params:{id:e.id},body:{lesson:!1}});i.ok?(n?.announce(`Accepted ${r}.`),await u()):tb.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 tb.add({title:`Lesson added`,description:a===void 0?`${eK(e.id)} is accepted.`:`\`${a.file}\` in \`${a.root}\`, ${SK(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 tb.add({title:`Run ${i} started`,description:`\`ork:feedback-apply\` is proposing a fix for ${eK(e.id)}. Its question comes to Decisions.`}),l(i),u(),null},split:async e=>{let r=eK(e.id),i=await t.client.call(`split`,{params:{id:e.id}});i.ok?(o(`heading`),n?.announce(`Split ${cK(i.data.moved)} back out of ${r}.`),await u()):tb.add({title:`Could not split ${r}`,description:i.error})},openRun:(e,t)=>{l(e,t)},reloadAll:u,announce:e=>{n?.announce(e)}}},pq=5e3,mq=48,hq=16,gq=e=>{let t=vb(e.feedback.state),n=vb(e.runs),r=(0,U.useRef)(0),i=(0,U.useRef)(null),a=(0,U.useRef)(n),o=(0,U.useCallback)(async()=>{r.current=Date.now(),await e.feedback.load()},[e]);return(0,U.useEffect)(()=>(o(),()=>{i.current!==null&&clearTimeout(i.current),i.current=null}),[o]),(0,U.useEffect)(()=>{if(a.current===n||(a.current=n,i.current!==null))return;let e=Math.max(0,r.current+pq-Date.now());i.current=setTimeout(()=>{i.current=null,o()},e)},[n,o]),{read:t,load:o}},_q=(e,t,n)=>{let[r,i]=(0,U.useState)(null),[a,o]=(0,U.useState)(null),[s,c]=(0,U.useState)(``),[l,u]=(0,U.useState)(0),d=`${t??``}|${n}|${String(l)}`;(0,U.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,U.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}},vq=e=>{let[t,n]=(0,U.useState)(!1);return(0,U.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`,``))||hq;n(t<mq*i)});return r.observe(t),()=>{r.disconnect()}},[e]),t},yq=e=>e===void 0?``:[e.status,e.count,e.lastSeen,...e.merged].join(`|`),bq={heading:`[data-feedback-heading]`,list:`[data-feedback-list]`},xq=(e,t)=>e?.querySelector(typeof t==`string`?bq[t]:`[data-item="${t.row}"]`)??null,Sq=e=>{let t=(0,U.useRef)(null),[,n]=(0,U.useState)(0);return(0,U.useEffect)(()=>{let n=t.current;if(n===null)return;let r=xq(e.current,n);r!==null&&(t.current=null,r.focus())}),(0,U.useCallback)(e=>{t.current=e,n(e=>e+1)},[])},Cq=()=>{let e=(0,U.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)}}},wq=()=>{let e=ob(),t=(0,U.use)(wL),n=vb(e.feedbackFilter),{read:r,load:i}=gq(e),a=(0,U.useRef)(null),o=vq(a),[s,c]=(0,U.useState)(null),[l,u]=(0,U.useState)(`list`),d=mH(r)?.data??null,f=(0,U.useMemo)(()=>d??[],[d]),p=(0,U.useMemo)(()=>oK(f,n),[f,n]),m=p.find(({id:e})=>e===s),h=_q(e.client,m?.id??null,yq(m)),g=Sq(a),_=Cq(),v=(0,U.useCallback)(e=>{c(e),u(e===null?`list`:`detail`)},[]),y=fq({state:e,workspace:t,filter:n,narrow:o,choose:v,focus:g,reloadDetail:h.reload}),{moving:b}=y;return(0,U.useEffect)(()=>{if(s===null||d===null||b.current||p.some(({id:e})=>e===s))return;let e=mK(f,s);e!==void 0&&p.some(({id:t})=>t===e.id)?(c(e.id),t?.announce(`${eK(s)} was merged into ${eK(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:aK(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(`${cK(oK(f,n).length)}.`)},reload:()=>{i(),h.reload()}}},Tq=({view:e})=>{let{read:t,all:n,items:r,shown:i,filter:a,chosen:o}=e;return(0,q.jsxs)(`div`,{"aria-label":`Items`,className:OU.card,"data-feedback-list":``,role:`group`,tabIndex:-1,children:[t.status===`failed`?(0,q.jsx)(lq,{error:t.error}):null,n===null&&t.status!==`failed`?(0,q.jsx)(`p`,{className:OU.message,children:`Reading feedback…`}):null,n!==null&&i.length===0?(0,q.jsx)(uq,{anything:r.length>0,filter:a}):null,i.length===0?null:(0,q.jsx)(sq,{chosen:o,items:i,onChoose:e.choose})]})},Eq=({view:e})=>{let{item:t,chosen:n,narrow:r}=e;return(0,q.jsxs)(`div`,{className:OU.card,"data-feedback-detail":``,children:[t===void 0?null:(0,q.jsx)(rq,{acts:e.acts,item:t,narrow:r,onBack:e.back,onLeave:e.back,read:e.detail}),t===void 0&&r&&n!==null?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(QK,{onBack:e.back}),(0,q.jsx)(`p`,{className:OU.message,children:`${eK(n)} isn't in this list any more.`})]}):null,t===void 0&&!r?(0,q.jsx)(`p`,{className:OU.message,children:`Choose an item to read its records.`}):null]})},Dq=()=>{let e=wq(),{read:t,all:n,filter:r,shown:i,showing:a,focusWatch:o,root:s}=e;return(0,q.jsxs)(`div`,{"aria-label":`Feedback`,className:OU.panel,"data-layout":e.narrow?`narrow`:`wide`,onBlur:o.onBlur,onFocus:o.onFocus,ref:s,role:`group`,tabIndex:-1,children:[(0,q.jsx)(cq,{count:i.length,failed:t.status===`failed`,filter:r,items:n,onFilter:e.setFilter,onReload:e.reload,updating:t.status===`loading`&&n!==null}),(0,q.jsxs)(`div`,{className:OU.body,children:[a===`detail`?null:(0,q.jsx)(Tq,{view:e}),a===`list`?null:(0,q.jsx)(Eq,{view:e})]})]})},Oq=`all`,kq=[{value:`7`,label:`Last 7 days`},{value:`30`,label:`Last 30 days`},{value:`90`,label:`Last 90 days`},{value:Oq,label:`All time`}],Aq=e=>e===Oq,jq=(e,t)=>{if(Aq(e))return;let n=new Date(t);return new Date(n.getFullYear(),n.getMonth(),n.getDate()-(Number(e)-1)).toISOString()},Mq=(e,t,n)=>[`ork usage`,...e?[`--all`]:[],`--since ${Aq(t)?`all`:`${t}d`}`,...n===void 0?[]:[`--by ${n}`]].join(` `),Nq=92,Pq=e=>String(e).padStart(2,`0`),Fq=e=>`${String(e.getFullYear())}-${Pq(e.getMonth()+1)}-${Pq(e.getDate())}`,Iq=e=>{let[t=0,n=1,r=1]=e.split(`-`).map(Number);return new Date(t,n-1,r)},Lq=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()-(e.getDay()+6)%7),Rq=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),zq=(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=Fq(e);a.push(i.get(t)??{key:t,costUsd:0,sessions:0})}return a},Bq=(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?Iq(i??``):Rq(new Date(t)),o=Rq(new Date(n)),s=zq(r,1,a,o),c=s.length>Nq?`week`:`day`,l=c===`day`?s:zq(e.groups.week,7,Lq(a),o);return{unit:c,bars:l,maxUsd:Math.max(0,...l.map(e=>e.costUsd))}},Vq=e=>nM(e),Hq=e=>{let t=[...e];return e=>nM(e,t)},Uq=rM,Wq=(e,t)=>aM(Vq(e),t),Gq=e=>`${String(Math.round(e*100))}%`,Kq={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`},qq=e=>e.toSorted((e,t)=>t.costUsd-e.costUsd)[0],Jq=e=>`${String(e)} session${e===1?``:`s`}`,Yq=2,Xq=6,Zq=14,Qq=e=>e<=Xq?`always`:e<=Zq?`wide`:`never`,$q=({bars:e})=>{let t=Qq(e.length);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{"aria-hidden":!0,className:Kq.axis,"data-labelled":t,children:[(0,q.jsx)(`span`,{children:e[0]?.key}),(0,q.jsx)(`span`,{children:e.at(-1)?.key})]}),(0,q.jsx)(`div`,{"aria-hidden":!0,className:Kq.axisEvery,"data-labelled":t,children:e.map(e=>(0,q.jsx)(`span`,{children:e.key.slice(5)},e.key))})]})},eJ=({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=Hq(r.map(e=>e.costUsd)),o=r.some(e=>(e.tokens??0)>0);return(0,q.jsxs)(`details`,{className:Kq.details,children:[(0,q.jsx)(`summary`,{children:`Show as a table`}),(0,q.jsxs)(`table`,{className:Kq.table,children:[(0,q.jsx)(`thead`,{children:(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`th`,{scope:`col`,children:n===`day`?`Day`:`Week of`}),(0,q.jsx)(`th`,{className:Kq.number,scope:`col`,children:`Cost`}),o?(0,q.jsx)(`th`,{className:Kq.number,scope:`col`,children:`Tokens`}):null,(0,q.jsx)(`th`,{className:Kq.number,scope:`col`,children:`Sessions`})]})}),(0,q.jsx)(`tbody`,{children:r.map(e=>(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`th`,{className:Kq.name,scope:`row`,children:e.key}),(0,q.jsx)(`td`,{className:Kq.number,children:(0,q.jsx)(pM,{partial:e.partial===!0,text:a(e.costUsd)})}),o?(0,q.jsx)(`td`,{className:Kq.number,children:rM(e.tokens??0)}):null,(0,q.jsx)(`td`,{className:Kq.number,children:e.sessions})]},e.key))})]}),i===0?null:(0,q.jsxs)(`p`,{className:Kq.note,children:[String(i),` `,n,i===1?``:`s`,` with no spend.`]})]})},tJ=({series:e})=>{let[t,n]=(0,U.useState)(null),{bars:r,maxUsd:i,unit:a}=e,o=r.find(e=>e.key===t)??null,s=qq(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 ${Wq(s.costUsd,s.partial===!0)} ${a===`day`?`on`:`in the week of`} ${s.key}${r.some(e=>e.partial===!0)?`, some ${a}s partial`:``}.`;return(0,q.jsxs)(`section`,{"aria-label":u,className:Kq.section,children:[(0,q.jsxs)(`div`,{className:Kq.chartHead,children:[(0,q.jsx)(`h3`,{className:Kq.heading,children:u}),c===void 0?null:(0,q.jsxs)(`p`,{className:Kq.readout,children:[o===null?`Peak: `:``,d,c.key,c.key===l?` so far`:``,` ·`,` `,(0,q.jsx)(pM,{partial:c.partial===!0,text:Vq(c.costUsd)}),(c.tokens??0)>0?(0,q.jsxs)(q.Fragment,{children:[` · `,(0,q.jsx)(mM,{count:c.tokens??0})]}):null,` `,`· `,Jq(c.sessions)]})]}),(0,q.jsx)(`div`,{"aria-label":f,className:Kq.chart,onPointerLeave:()=>{n(null)},role:`img`,children:r.map(e=>(0,q.jsx)(`div`,{className:Kq.column,"data-partial":e.key===l?``:void 0,"data-pointed":e.key===o?.key?``:void 0,onPointerEnter:()=>{n(e.key)},children:e.costUsd===0&&e.partial!==!0?null:(0,q.jsx)(`div`,{className:Kq.bar,style:{height:`${String(Math.max(Yq,i===0?0:e.costUsd/i*100))}%`}})},e.key))}),(0,q.jsx)($q,{bars:r}),(0,q.jsx)(eJ,{series:e})]})},nJ=e=>e===void 0?`All projects`:`This project`,rJ=e=>`$${e.toFixed(2)}`,iJ=e=>new Date(e).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}),aJ=e=>`${e.project??`all`}-${e.window}`,oJ=({cap:e})=>(0,q.jsx)(PW,{label:`${nJ(e.project)}, this ${e.window}, in tokens`,max:e.capTokens,text:`${rM(e.spentTokens)} of ${iM(e.capTokens)} tokens, resets ${iJ(e.resetsAt)}${e.spentTokens>=e.capTokens?`, reached`:``}`,value:Math.min(e.spentTokens,e.capTokens)}),sJ=({limits:e})=>{let t=e.tokenCaps??[],n=new Set(e.caps.map(aJ));return e.problems.length===0&&e.caps.length===0&&t.length===0&&e.plan.length===0?null:(0,q.jsxs)(`section`,{"aria-label":`Limits`,className:Kq.limits,children:[e.problems.map(e=>(0,q.jsx)(`p`,{className:Kq.note,children:(0,q.jsx)(r_,{text:e})},e)),e.caps.map(e=>(0,q.jsxs)(U.Fragment,{children:[(0,q.jsx)(PW,{label:`${nJ(e.project)}, this ${e.window}`,max:e.capUsd,text:`${rJ(e.spentUsd)} of ${rJ(e.capUsd)}, resets ${iJ(e.resetsAt)}`,value:Math.min(e.spentUsd,e.capUsd)}),t.filter(t=>aJ(t)===aJ(e)).map(e=>(0,q.jsx)(oJ,{cap:e},`${aJ(e)}-tokens`))]},aJ(e))),t.filter(e=>!n.has(aJ(e))).map(e=>(0,q.jsx)(oJ,{cap:e},`${aJ(e)}-tokens`)),t.length===0?null:(0,q.jsx)(`p`,{className:Kq.note,children:`Tokens counted: input, output and cache write. Cache reads are not counted.`}),e.plan.map(e=>(0,q.jsx)(`p`,{className:Kq.note,children:`Your Claude plan's ${e.window.replaceAll(`_`,` `)} limit ${e.status===`rejected`?`was reached`:`is close`}${e.resetsAt===void 0?``:`; it resets ${iJ(e.resetsAt)}`}.`},e.window))]})},cJ=10,lJ=({title:e,label:t,groups:n,total:r,nameOf:i,moreCommand:a})=>{let o=n.length-cJ,s=n.slice(0,cJ),c=Hq(s.map(e=>e.costUsd)),l=s.some(e=>(e.tokens??0)>0);return(0,q.jsxs)(`section`,{"aria-label":e,className:Kq.section,children:[(0,q.jsx)(`h3`,{className:Kq.heading,children:e}),(0,q.jsxs)(`table`,{className:Kq.table,children:[(0,q.jsx)(`thead`,{children:(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`th`,{scope:`col`,children:t}),(0,q.jsx)(`th`,{className:Kq.number,scope:`col`,children:`Cost`}),l?(0,q.jsx)(`th`,{className:Kq.number,scope:`col`,children:`Tokens`}):null,(0,q.jsx)(`th`,{className:Kq.number,scope:`col`,children:`Share`}),(0,q.jsx)(`th`,{className:Kq.number,scope:`col`,children:`Sessions`}),(0,q.jsx)(`th`,{className:Kq.number,scope:`col`,children:`From cache`})]})}),(0,q.jsx)(`tbody`,{children:s.map(e=>(0,q.jsxs)(`tr`,{children:[(0,q.jsxs)(`th`,{className:Kq.name,scope:`row`,title:e.key,children:[i?.(e.key)??e.key,i===void 0?null:(0,q.jsx)(`span`,{className:Kq.path,children:e.key})]}),(0,q.jsx)(`td`,{className:Kq.number,children:(0,q.jsx)(pM,{partial:e.partial===!0,text:c(e.costUsd)})}),l?(0,q.jsx)(`td`,{className:Kq.number,children:Uq(e.tokens??0)}):null,(0,q.jsx)(`td`,{className:Kq.number,children:Gq(r===0?0:e.costUsd/r)}),(0,q.jsx)(`td`,{className:Kq.number,children:e.sessions}),(0,q.jsx)(`td`,{className:Kq.number,children:Gq(e.cacheHitRate)})]},e.key))})]}),o>0?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`p`,{className:Kq.note,children:[`And `,o,` more that cost less. This lists them all:`]}),(0,q.jsx)(cC,{command:a})]}):null]})},uJ=({error:e,command:t,retry:n})=>(0,q.jsxs)(`div`,{className:Kq.section,children:[(0,q.jsxs)(`p`,{className:Kq.refused,role:`alert`,children:[`Cannot read usage: `,(0,q.jsx)(r_,{text:e})]}),(0,q.jsx)(`div`,{className:Kq.retry,children:(0,q.jsx)(Y,{onClick:n,children:`Try again`})}),(0,q.jsx)(`p`,{className:Kq.note,children:`On a terminal, the same report:`}),(0,q.jsx)(cC,{command:t})]}),dJ=({period:e,limits:t})=>(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(sJ,{limits:t}),(0,q.jsx)(JD,{cli:`ork run <workflow>`,title:Aq(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:`})]}),fJ=({report:e})=>{let{totals:t}=e,n=t.inputTokens+t.cacheReadTokens+t.cacheWriteTokens,r=[[`Spend`,(0,q.jsx)(pM,{focusable:!0,partial:t.partial===!0,text:Vq(t.costUsd)},`spend`)],[`Runs with sessions`,String(t.runs)],[`Sessions`,String(t.sessions)],[`Tokens in`,Uq(n)],[`Tokens out`,Uq(t.outputTokens)],[`From cache`,Gq(t.cacheHitRate)],...t.tokens===void 0||t.tokens===0?[]:[[`Tokens counted`,Uq(t.tokens)]]];return(0,q.jsx)(`dl`,{className:Kq.totals,children:r.map(([e,t])=>(0,q.jsxs)(`div`,{className:Kq.total,children:[(0,q.jsx)(`dt`,{children:e===`Tokens counted`?(0,q.jsx)(_M,{}):e}),(0,q.jsx)(`dd`,{children:t})]},e))})},pJ=({report:e,since:t,now:n,period:r,everyProject:i,projectName:a})=>{let o=(0,U.useMemo)(()=>Bq(e,t,n),[e,t,n]),s=e.totals.costUsd,c=e=>Mq(i,r,e);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(sJ,{limits:e.limits}),(0,q.jsxs)(`div`,{className:Kq.overview,children:[(0,q.jsx)(fJ,{report:e}),e.hints.length===0?null:(0,q.jsxs)(`section`,{"aria-label":`Worth a look`,className:Kq.hintsSection,children:[(0,q.jsx)(`h3`,{className:Kq.heading,children:`Worth a look`}),(0,q.jsx)(`ul`,{className:Kq.hints,children:e.hints.map(e=>(0,q.jsx)(`li`,{children:(0,q.jsx)(r_,{text:e.message})},e.code))})]}),(0,q.jsx)(`div`,{className:Kq.chartArea,children:(0,q.jsx)(tJ,{series:o})})]}),(0,q.jsxs)(`div`,{className:Kq.breakdowns,children:[i?(0,q.jsx)(lJ,{groups:e.groups.project,label:`Project`,moreCommand:c(`project`),nameOf:a,title:`By project`,total:s}):null,(0,q.jsx)(lJ,{groups:e.groups.workflow,label:`Workflow`,moreCommand:c(`workflow`),title:`By workflow`,total:s}),(0,q.jsx)(lJ,{groups:e.groups.model,label:`Model`,moreCommand:c(`model`),title:`By model`,total:s}),(0,q.jsx)(lJ,{groups:e.groups.node,label:`Node`,moreCommand:c(`node`),title:`Costliest nodes`,total:s})]}),(0,q.jsxs)(`p`,{className:Kq.note,children:[`Costs are Claude Code's own estimates. On a subscription they are not what you are billed.`,e.totals.partial===!0?` Dollars miss sessions on drivers with no price; tokens count all of them.`:``,` `,`On a terminal:`]}),(0,q.jsx)(cC,{command:c()})]})},mJ=()=>{let e=ob(),t=vb(e.usage.state),n=vb(e.runs),r=vb(e.projects.state),i=vb(e.usageFilter),{project:a,period:o}=i,[s,c]=(0,U.useState)(0),l=mH(t),u=(0,U.useRef)(null),d=_b(e.runs,e=>e?.filter(e=>e.live!==`running`&&e.live!==`paused`).length??0);(0,U.useEffect)(()=>{e.projects.load()},[e]),(0,U.useEffect)(()=>{let t=Date.now(),n=jq(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,U.useMemo)(()=>cG(r.status===`ready`?r.data:[],n??[]),[r,n]),p=a===`all`;return(0,q.jsxs)(`div`,{className:Kq.panel,children:[(0,q.jsxs)(`div`,{className:Kq.tools,children:[(0,q.jsx)(`div`,{className:Kq.projectFilter,children:(0,q.jsx)(dk,{label:`Project`,onChange:t=>{e.usageFilter.setValue({...i,project:t})},options:f,value:a})}),(0,q.jsx)(dk,{label:`Period`,onChange:t=>{e.usageFilter.setValue({...i,period:t})},options:kq,value:o})]}),(0,q.jsxs)(`section`,{"aria-busy":t.status===`loading`,"aria-label":`Usage report`,className:Kq.body,ref:u,tabIndex:0,children:[t.status===`failed`?(0,q.jsx)(uJ,{command:Mq(p,o),error:t.error,retry:()=>{u.current?.focus(),c(s+1)}}):null,l===void 0?t.status===`failed`?null:(0,q.jsx)(`p`,{className:Kq.note,children:`Reading usage…`}):l.data.totals.sessions===0?(0,q.jsx)(dJ,{limits:l.data.limits,period:l.arg.period}):(0,q.jsx)(pJ,{everyProject:l.arg.query.project===void 0,now:l.arg.now,period:l.arg.period,projectName:e=>f.find(t=>t.value===e)?.label??oG(e),report:l.data,since:l.arg.query.since})]})]})},hJ=(e,t)=>`${String(e)} ${t}${e===1?``:t.endsWith(`h`)?`es`:`s`}`,gJ=e=>({worktrees:e.filter(e=>e.path!==null).length,branches:e.filter(e=>e.path===null).length}),_J=e=>{let{worktrees:t,branches:n}=gJ(e);return[...t>0||n===0?[hJ(t,`worktree`)]:[],...n>0?[hJ(n,`branch`)]:[]].join(` · `)},vJ=(e,t)=>{let n=e.flatMap(e=>e.items),{worktrees:r,branches:i}=gJ(n),a=t??hJ(e.filter(e=>e.items.length>0).length,`project`);return n.length===0?`No Ork worktrees or branches in ${a}.`:`${[...r>0?[hJ(r,`worktree`)]:[],...i>0?[hJ(i,`branch`)]:[]].join(` and `)} in ${a}.`},yJ=(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`,bJ=e=>[e.root,...e.error===void 0?[e.head===null?`detached HEAD`:`current branch ${e.head}`]:[],...e.items.length===0?[]:[_J(e.items)]],xJ=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}]],SJ=e=>e.run.known?`Open run ${e.runId} at ${e.nodeId}`:`Open run ${e.runId}: it isn't in Ork's records`,CJ=e=>{let t=`${e.remove.label.replace(`…`,``)} ${e.label}…`;return e.remove.refusal===void 0?t:`${t}: ${e.remove.refusal}`},wJ=(e,t,n,r)=>`cd ${Mk(e)} && ork worktrees remove ${Mk(t)}${n?` --branch`:``}${r?` --force`:``}`,TJ=e=>e.path===null?`branch`:e.state===`detached`||e.branch===void 0?`detached`:`worktree`,EJ=e=>({branch:`Delete branch \`${e.label}\``,detached:`Remove the worktree of \`${e.label}\``,worktree:`Remove \`${e.label}\``})[TJ(e)],DJ=(e,t)=>{let n=TJ(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.`},OJ=(e,t)=>e.merged?`It's merged into \`${t}\`.`:`It has ${hJ(e.ahead,`commit`)} not merged into \`${t}\`; deleting it loses them.`,kJ=e=>e.force?`Continue…`:e.removeWorktree&&e.deleteBranch?`Remove worktree and branch`:e.deleteBranch?`Delete branch`:e.prunes?`Prune`:`Remove worktree`,AJ=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=hJ(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.`},jJ=(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.`,MJ=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(` `),NJ=(e,t)=>`cd ${Mk(e)} && ork worktrees clean${t?` --branches`:``}`,PJ=`[data-worktree-row]`,FJ=(e,t)=>[...e?.querySelectorAll(PJ)??[]].findIndex(e=>e.dataset.worktreeRow===t),IJ=(e,t)=>{let n=ob(),r=(0,U.use)(wL),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(!1),[c,l]=(0,U.useState)(new Set),u=(0,U.useRef)(`back`),d=(0,U.useRef)(null),f=(0,U.useRef)(0),p=(0,U.useMemo)(()=>({openRun:e=>{dq(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:FJ(e.current,t.key),id:f.current+1}),f.current+=1,s(!0)}}),[n,r,e]),m=t=>{let n=e.current?.querySelectorAll(PJ)??[];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(jJ(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),dq(n,r,e.runId,e.nodeId)}}},LJ=(e,t)=>t===`all`?[...e]:e.filter(e=>e.root===t),RJ=(e,t)=>({...e,name:t}),zJ=()=>{let e=ob(),t=(0,U.use)(wL),n=vb(e.worktrees.state),r=vb(e.worktreesFilter),i=vb(e.runs),a=vb(e.projects.state),o=(0,U.useRef)(0),s=(0,U.useRef)(null),c=(0,U.useRef)(null),l=(0,U.useRef)(i),u=(0,U.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,U.useEffect)(()=>(u(),e.projects.state.getValue().status===`idle`&&e.projects.load(),()=>{c.current!==null&&clearTimeout(c.current),c.current=null}),[u,e]),(0,U.useEffect)(()=>{if(l.current===i||(l.current=i,c.current!==null))return;let e=Math.max(0,o.current+pq-Date.now());c.current=setTimeout(()=>{c.current=null,u()},e)},[i,u]);let d=mH(n)?.data.projects??null,f=cG(mH(a)?.data??[],[...i??[],...(d??[]).map(e=>({project:e.root}))]),p=e=>f.find(t=>t.value===e)?.label??e,m=(d??[]).map(e=>RJ(e,p(e.root))),h=f.flatMap(e=>m.filter(t=>t.root===e.value)),g=d===null?null:LJ(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(vJ(LJ(h,n),r))}}},BJ={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`},VJ={ArrowDown:e=>e+1,ArrowUp:e=>e-1,Home:()=>0,End:(e,t)=>t},HJ=e=>{let t=VJ[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())},UJ=(0,U.memo)(({row:e,project:t,acts:n})=>{let r=(0,U.useId)(),i=(0,U.useId)(),a=wJ(t.root,e.key,e.path===null,!1),o=xJ(e),{refusal:s}=e.remove;return(0,q.jsxs)(`li`,{className:BJ.row,"data-worktree-row":e.key,children:[(0,q.jsxs)(`p`,{className:BJ.rowName,children:[e.label,(0,q.jsx)(uk,{children:`, `})]}),(0,q.jsx)(`span`,{className:BJ.badge,children:(0,q.jsx)(Qj,{state:e.state})}),(0,q.jsx)(`p`,{className:BJ.meta,id:r,children:o.map((e,t)=>(0,q.jsxs)(`span`,{className:e.risk?BJ.risk:void 0,children:[e.text,t<o.length-1?` ·`:``]},t))}),(0,q.jsx)(`span`,{hidden:!0,id:i,children:`CLI: ${a}`}),(0,q.jsxs)(`div`,{className:BJ.actions,children:[(0,q.jsx)(Y,{"aria-label":SJ(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,q.jsx)(Y,{"aria-describedby":`${r} ${i}`,"aria-label":CJ(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)),WJ=({project:e,acts:t})=>{let n=(0,U.useId)();return(0,q.jsxs)(`section`,{"aria-labelledby":n,className:BJ.card,children:[(0,q.jsxs)(`div`,{className:BJ.head,children:[(0,q.jsx)(`h3`,{className:BJ.name,id:n,children:e.name}),(0,q.jsx)(`p`,{className:BJ.headMeta,children:bJ(e).join(` · `)})]}),e.error===void 0?(0,q.jsx)(`ul`,{"aria-label":`Worktrees in ${e.name}`,className:BJ.list,children:e.items.map(n=>(0,q.jsx)(UJ,{acts:t,project:e,row:n},n.key))}):(0,q.jsxs)(`p`,{className:BJ.alert,children:[(0,q.jsx)(`span`,{className:BJ.alertIcon,children:(0,q.jsx)(Ij,{})}),(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:`Could not read ${e.name}'s worktrees: ${e.error}`})})]}),e.fix===void 0?null:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`p`,{className:BJ.note,children:`If it moved, this points Ork at its new place:`}),(0,q.jsx)(cC,{command:e.fix})]})]})},GJ=e=>e.filter(e=>e.steps.length>0),KJ=e=>({worktrees:e.filter(e=>e.removeWorktree||e.prunes).length,branches:e.filter(e=>e.deleteBranch).length}),qJ=e=>e.removeWorktree||e.deleteBranch||e.prunes,JJ=e=>e.skip??`no worktree, branch kept`,YJ=e=>{let[t]=e;return e.length===1&&t!==void 0?`Clean merged worktrees in ${t.name}`:`Clean merged worktrees in ${hJ(e.length,`project`)}`},XJ=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.`,ZJ=e=>{let{worktrees:t,branches:n}=KJ(e),r=[...t>0?[`removes ${hJ(t,`worktree`)}`]:[],...n>0?[`deletes ${hJ(n,`branch`)}`]:[]].join(` and `),i=e.filter(e=>!qJ(e)||e.skip!==void 0),a=new Map;for(let e of i)a.set(JJ(e),(a.get(JJ(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(` `)},QJ=e=>{let{worktrees:t,branches:n}=KJ(e.flatMap(e=>e.steps));return t===0&&n===0?null:t===0?`Delete ${hJ(n,`branch`)}`:n===0?`Remove ${hJ(t,`worktree`)}`:`Remove ${hJ(t,`worktree`)} and ${hJ(n,`branch`)}`},$J=e=>e.some(e=>e.error!==void 0)?`Cleaned in part`:`Cleaned`,eY={well:`_well_18f8h_7`},tY=({label:e,reading:t,describedBy:n,ref:r,steady:i=!1,short:a=!1,children:o})=>(0,q.jsx)(`section`,{"aria-busy":t!==void 0,"aria-describedby":n,"aria-label":e,className:eY.well,"data-short":a?``:void 0,"data-steady":i?``:void 0,ref:r,tabIndex:0,children:t===void 0?o:(0,q.jsx)(r_,{text:t})}),nY=`Reading the plan…`,rY=`Nothing to show: the plan couldn't be read.`,iY=({reading:e,failed:t,well:n})=>(0,q.jsx)(tY,{label:`Plan`,reading:e?nY:void 0,ref:n,steady:!0,children:t?rY:`Nothing to clean.`}),aY=({checked:e,disabled:t,onChange:n})=>{let r=(0,U.useId)();return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(vO,{checked:e,describedBy:r,disabled:t,label:`Also delete the merged branches`,onChange:n}),(0,q.jsx)(`p`,{className:BJ.note,id:r,children:`Only branches merged into the current branch, which git deletes without losing a commit.`})]})},oY=({project:e,branches:t,reading:n,failed:r,well:i})=>{let a=(0,U.useId)(),o=e.head??`its detached HEAD`;return(0,q.jsxs)(`section`,{"aria-label":e.name,className:BJ.section,children:[(0,q.jsx)(`h3`,{className:BJ.name,children:e.name}),(0,q.jsx)(`p`,{className:BJ.headMeta,children:(0,q.jsx)(r_,{text:`\`${e.root}\` · into \`${o}\``})}),(0,q.jsx)(`p`,{className:BJ.message,id:a,children:n||r?``:ZJ(e.steps)}),(0,q.jsx)(`p`,{className:BJ.caption,children:`Plan`}),(0,q.jsxs)(tY,{describedBy:a,label:`Plan for ${e.name}`,reading:n?nY:void 0,ref:i,steady:!0,children:[r?rY:null,e.steps.map(e=>(0,q.jsxs)(`span`,{children:[e.line.text,e.line.reason===void 0?null:(0,q.jsx)(`span`,{className:BJ.reason,children:` (${e.line.reason})`}),`
107
+ `]},e.key))]}),(0,q.jsx)(`p`,{className:BJ.note,children:(0,q.jsx)(r_,{text:`In \`${e.root}\`:`})}),(0,q.jsx)(cC,{command:NJ(e.root,t)})]})},sY=({lines:e})=>(0,q.jsx)(`ul`,{className:BJ.result,children:e.map(e=>(0,q.jsxs)(`li`,{className:BJ.resultLine,children:[(0,q.jsx)(Nj,{}),e]},e))}),cY=({results:e})=>{let t=(0,U.useRef)(null);return(0,U.useEffect)(()=>{t.current?.focus()},[]),(0,q.jsxs)(`div`,{className:BJ.step,children:[(0,q.jsx)(`h3`,{className:BJ.title,ref:t,tabIndex:-1,children:$J(e)}),e.filter(e=>e.done.length>0||e.error!==void 0).map(e=>(0,q.jsxs)(`section`,{"aria-label":e.name,className:BJ.section,children:[(0,q.jsx)(`h4`,{className:BJ.name,children:e.name}),e.error===void 0?null:(0,q.jsxs)(`p`,{className:BJ.alert,children:[(0,q.jsx)(`span`,{className:BJ.alertIcon,children:(0,q.jsx)(Ij,{})}),(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:`Stopped in ${e.name}: ${e.error}`})})]}),e.error===void 0||e.done.length===0?null:(0,q.jsx)(`p`,{className:BJ.note,children:`Done before it stopped:`}),(0,q.jsx)(sY,{lines:e.done})]},e.root))]})},lY=e=>{if(e.step!==`done`)return`plan`in e?e.plan:e.shown},uY=(e,t,n)=>{let[r,i]=(0,U.useState)(!1),[a,o]=(0,U.useState)({step:`reading`}),s=(0,U.useRef)(0),c=(0,U.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,U.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,U.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,lY(a))},clean:()=>{a.step===`plan`&&d(a.plan)},tryAgain:()=>{a.step===`cleanFailed`?d(a.plan):u(r,lY(a))}}},dY=e=>e.step===`readFailed`?`Could not read the plan: ${e.error}`:e.step===`cleanFailed`?`Could not clean: ${e.error}`:null,fY=e=>e.step===`reading`?`Reading the plan…`:e.step===`readFailed`?`The plan couldn't be read; Try again reads it.`:null,pY=e=>{let t=uY(e.client,e.project,e.onCleaned),{step:n}=t,r=(0,U.useRef)(null),i=(0,U.useId)(),a=(0,U.useId)(),o=n.step===`cleaning`,s=n.step===`reading`,c=lY(n),l=c===void 0?e.scope:GJ(c.projects),u=QJ(l),d=n.step===`plan`&&n.changed,f=c!==void 0&&!s&&u===null,p=n.step===`readFailed`&&c===void 0;(0,U.useEffect)(()=>{d&&r.current?.focus()},[d]),(0,U.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,q.jsx)(NC,{description:XJ(e.project!==void 0),finalFocus:e.finalFocus,initialFocus:r,onOpenChange:e=>{e||m()},open:e.open,size:`wide`,title:YJ(l.length===0?e.scope:l),children:n.step===`done`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(cY,{results:n.results}),(0,q.jsx)(PC,{children:(0,q.jsx)(Y,{onClick:m,children:`Close`})})]}):(0,q.jsxs)(q.Fragment,{children:[d?(0,q.jsx)(`p`,{role:`alert`,children:`The plan changed since you read it. Read it again before cleaning.`}):null,l.length===0?(0,q.jsx)(iY,{failed:p,reading:s,well:r}):null,l.map((e,n)=>(0,q.jsx)(oY,{branches:t.branches,failed:p,project:e,reading:s,well:n===0?r:void 0},e.root)),(0,q.jsx)(aY,{checked:t.branches,disabled:o,onChange:t.setBranches}),(0,q.jsx)(OK,{id:a,onTryAgain:t.tryAgain,takeFocus:n.step===`cleanFailed`?`always`:`ifLost`,words:dY(n)}),(0,q.jsx)(jU,{id:i,why:fY(n)}),(0,q.jsxs)(PC,{children:[(0,q.jsx)(Y,{disabled:o,focusableWhenDisabled:!0,onClick:m,variant:`ghost`,children:f?`Close`:`Cancel`}),f?null:(0,q.jsx)(Y,{"aria-describedby":`${i} ${a}`,disabled:n.step!==`plan`,focusableWhenDisabled:!0,onClick:t.clean,variant:`primary`,children:o?`Removing…`:u??`Remove worktrees`})]})]})})},mY=(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}`:``)},hY=`Nothing to show: its state couldn't be read.`,gY=({name:e,children:t})=>(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`dt`,{className:BJ.factName,children:e}),(0,q.jsx)(`dd`,{className:BJ.factValue,children:t})]}),_Y=({plan:e,label:t,reading:n})=>(0,q.jsx)(tY,{label:t,reading:n,steady:!0,children:e===void 0?hY:(0,q.jsxs)(q.Fragment,{children:[e.line.text,e.line.reason===void 0?null:(0,q.jsx)(`span`,{className:BJ.reason,children:` (${e.line.reason})`})]})}),vY=e=>{let{row:t,project:n,plan:r}=e,i=(0,U.useId)(),a=n.head??`the current branch`;return(0,q.jsxs)(`div`,{className:BJ.step,children:[(0,q.jsxs)(`dl`,{className:BJ.facts,children:[(0,q.jsx)(gY,{name:`Project`,children:`${n.name} ${n.root}`}),(0,q.jsxs)(gY,{name:`Run`,children:[`${t.runId} · ${t.nodeId}`,(0,q.jsx)(Y,{"aria-label":SJ(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,q.jsx)(gY,{name:`Path`,children:t.path}),(0,q.jsx)(gY,{name:`State`,children:mY(t,r,a)})]}),TJ(t)===`worktree`&&t.branch!==void 0?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(vO,{checked:e.deleteBranch,describedBy:i,disabled:e.busy,label:`Also delete the branch ${t.branch}`,onChange:e.onDeleteBranch}),(0,q.jsx)(`p`,{className:BJ.note,id:i,children:(0,q.jsx)(r_,{text:OJ(r??t,a)})})]}):null,(0,q.jsx)(`p`,{className:BJ.caption,children:`Plan`}),(0,q.jsx)(_Y,{label:`Plan`,plan:r,reading:e.reading?`Reading its state…`:void 0}),(0,q.jsx)(cC,{command:wJ(n.root,t.key,r?.deleteBranch??e.deleteBranch,r?.force??!1)})]})},yY=({title:e,label:t,lines:n,more:r})=>(0,q.jsxs)(`div`,{className:BJ.section,children:[(0,q.jsx)(`p`,{className:BJ.caption,children:(0,q.jsx)(r_,{text:`${e} · ${String(n.length+r)}`})}),(0,q.jsx)(tY,{label:t,short:!0,children:n.join(`
108
+ `)}),r>0?(0,q.jsx)(`p`,{className:BJ.note,children:`and ${String(r)} more`}):null]}),bY=({row:e,plan:t,head:n,root:r})=>{let i=(0,U.useRef)(null);(0,U.useEffect)(()=>{i.current?.focus()},[]);let{losing:a}=t,o=`Commits not merged into ${n}`;return(0,q.jsxs)(`div`,{className:BJ.step,children:[(0,q.jsx)(`h3`,{className:BJ.title,ref:i,tabIndex:-1,children:`What's lost`}),a.changes.length===0?null:(0,q.jsx)(yY,{label:`Uncommitted changes`,lines:a.changes,more:a.more.changes,title:`Uncommitted changes`}),a.commits.length===0?null:(0,q.jsx)(yY,{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,q.jsx)(`p`,{className:BJ.note,children:MJ(t)}),(0,q.jsx)(cC,{command:wJ(r,e.key,t.deleteBranch,!0)})]})},xY=e=>`plan`in e?e.plan:e.shown,SY=e=>e.step===`lost`||(e.step===`removing`||e.step===`removeFailed`)&&e.from===`lost`,CY=(e,t,n)=>{let[r,i]=(0,U.useState)(!1),[a,o]=(0,U.useState)({step:`reading`}),s=(0,U.useRef)(0),c=(0,U.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,U.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,U.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,xY(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,xY(a))}}},wY=`It changed since you read it. Read it again before removing.`,TY=(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?wY:null,EY=e=>e.step===`reading`?`Reading its state…`:e.step===`readFailed`?`Its state couldn't be read; Try again reads it.`:e.step===`choice`?AJ(e.plan):null,DY=({client:e,row:t,project:n,target:r,cancel:i,onBusy:a,onRemoved:o,onOpenRun:s,onClose:c})=>{let l=CY(e,r,o),{step:u}=l,d=(0,U.useId)(),f=(0,U.useId)(),p=(0,U.useRef)(null),m=u.step===`removing`,h=xY(u),g=SY(u),_=u.step===`choice`&&u.changed;(0,U.useEffect)(()=>{a(m)},[m,a]);let v=(0,U.useRef)(!1);(0,U.useEffect)(()=>{let e=v.current&&!g;v.current=g,(_||e)&&p.current?.focus()},[_,g]);let y=TY(u,t.label);return(0,q.jsxs)(q.Fragment,{children:[g&&h!==void 0?(0,q.jsx)(bY,{head:n.head??`the current branch`,plan:h,root:n.root,row:t}):(0,q.jsx)(vY,{busy:m,deleteBranch:l.deleteBranch,onDeleteBranch:l.setDeleteBranch,onOpenRun:s,plan:h,project:n,reading:u.step===`reading`,row:t}),(0,q.jsx)(OK,{id:f,onTryAgain:_?void 0:l.tryAgain,takeFocus:u.step===`removeFailed`?`always`:`ifLost`,words:y}),(0,q.jsx)(jU,{id:d,why:EY(u)}),(0,q.jsxs)(`div`,{className:BJ.foot,children:[g?(0,q.jsx)(Y,{disabled:m,focusableWhenDisabled:!0,onClick:l.back,variant:`ghost`,children:`Back`}):null,(0,q.jsx)(Y,{disabled:m,focusableWhenDisabled:!0,onClick:c,ref:i,variant:`ghost`,children:`Cancel`}),g?(0,q.jsx)(Y,{"aria-describedby":f,disabled:u.step!==`lost`,focusableWhenDisabled:!0,onClick:l.loseIt,variant:`danger`,children:m?`Removing…`:`Remove and lose this work`}):(0,q.jsx)(Y,{"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`:kJ(h)})]})]})},OY=({open:e,client:t,row:n,project:r,target:i,finalFocus:a,onRemoved:o,onOpenRun:s,onClose:c})=>{let l=(0,U.useRef)(null),u=(0,U.useRef)(!1),d=()=>{u.current||c()};return(0,q.jsx)(NC,{description:DJ(n,r.root),finalFocus:a,initialFocus:l,onOpenChange:e=>{e||d()},open:e,size:`wide`,title:EJ(n),children:(0,q.jsx)(DY,{cancel:l,client:t,onBusy:e=>{u.current=e},onClose:d,onOpenRun:s,onRemoved:o,project:r,row:n,target:i})})},kY=({acts:e,project:t,merged:n,load:r})=>{let{client:i}=ob(),{opened:a,open:o}=e;return a?.kind===`remove`?(0,q.jsx)(OY,{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,q.jsx)(pY,{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},AY=({filter:e,options:t,items:n,updating:r,cleanBlocked:i,cleanButton:a,onFilter:o,onClean:s,onReload:c})=>(0,q.jsxs)(`div`,{className:BJ.tools,children:[(0,q.jsx)(dk,{label:`Project`,onChange:o,options:t,value:e}),(0,q.jsxs)(`div`,{className:BJ.toolsEnd,children:[n===null?null:(0,q.jsx)(`span`,{className:BJ.count,children:_J(n)}),(0,q.jsx)(`output`,{className:BJ.count,children:r?`Updating…`:``}),(0,q.jsx)(Y,{"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,q.jsx)(Y,{cli:`ork worktrees`,onClick:c,tip:`In the project's folder.`,variant:`ghost`,children:`Reload`})]})]}),jY=({error:e})=>(0,q.jsxs)(`p`,{className:BJ.alert,role:`alert`,children:[(0,q.jsx)(`span`,{className:BJ.alertIcon,children:(0,q.jsx)(My,{})}),(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:`Could not read worktrees: ${e}`})})]}),MY=({projects:e,one:t})=>e===0?(0,q.jsxs)(JD,{cli:`ork register <path>`,focusable:!0,title:`No projects registered yet.`,children:[(0,q.jsx)(`p`,{children:`In a repository:`}),(0,q.jsx)(cC,{command:`ork init`}),(0,q.jsx)(`p`,{children:`Or from outside it:`})]}):t===null?(0,q.jsx)(JD,{cli:`ork worktrees`,focusable:!0,title:`No Ork worktrees or branches.`,children:(0,q.jsx)(r_,{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,q.jsx)(JD,{focusable:!0,title:`No Ork worktrees or branches in ${t}.`,children:`Project: All projects shows every project's.`}),NY=(e,t)=>({...e,items:e.items.filter(n=>!t.has(`${e.root}|${n.key}`))}),PY={usage:{title:`Usage`,Icon:ky,Body:mJ},context:{title:`Context`,Icon:jy,Body:$G},feedback:{title:`Feedback`,Icon:Ny,Body:Dq},worktrees:{title:`Worktrees`,Icon:Iy,Body:()=>{let e=zJ(),{read:t,shown:n,filter:r}=e,i=r===`all`?null:r,{panel:a,onFocus:o}=EH((n??[]).flatMap(e=>e.items.map(t=>`${e.root}|${t.key}`)).join(`
109
+ `),`[data-worktree-row]`),s=IJ(a,e.load),c=(n??[]).map(e=>NY(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,q.jsxs)(`div`,{"aria-label":`Worktrees`,className:BJ.panel,onFocus:o,onKeyDown:HJ,ref:a,role:`group`,tabIndex:-1,children:[(0,q.jsx)(AY,{cleanBlocked:yJ(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,q.jsx)(jY,{error:t.error}):null,n===null&&t.status!==`failed`?(0,q.jsx)(`p`,{className:BJ.message,children:`Reading worktrees…`}):null,n!==null&&l.length===0?(0,q.jsx)(MY,{one:i===null?null:c[0]?.name??i,projects:e.all?.length??0}):null,l.map(e=>(0,q.jsx)(WJ,{acts:s.rowActs,project:e},e.root)),i===null&&l.length>0&&u>0?(0,q.jsx)(`p`,{className:BJ.note,children:`Nothing left in ${hJ(u,`other project`)}.`}):null,(0,q.jsx)(kY,{acts:s,load:e.load,merged:d,project:i??void 0})]})}}},FY={runs:{id:`runs`,title:`Runs`,Icon:Cy,Body:vG},monitor:{id:`monitor`,title:`Monitor`,Icon:wy,Body:KW},logs:{id:`logs`,title:`Logs`,Icon:Ty,Body:eU},decisions:{id:`decisions`,title:`Decisions`,Icon:Ey,Body:DH},chats:{id:`chats`,title:`Chats`,Icon:Dy,Body:CL},notifications:{id:`notifications`,title:`Notifications`,Icon:Oy,Body:aG},usage:{id:`usage`,...PY.usage},builder:{id:`builder`,title:`Builder`,Icon:Ay,Body:II},context:{id:`context`,...PY.context},feedback:{id:`feedback`,...PY.feedback},worktrees:{id:`worktrees`,...PY.worktrees}},IY=Object.values(FY),LY=e=>e in FY,RY=e=>FY[e],zY=(e,t)=>e===void 0?void 0:Wk(e,t).join(t?``:`+`),BY=(e,t)=>{if(e.wide&&!e.open.includes(t))return e.minimized.includes(t)?`minimized`:`closed`},VY=({workspace:e})=>{let t=vb(e.view),n=Zk(),r=[...IY.map(({id:r,title:i},a)=>({label:i,detail:BY(t,r),hint:zY(Xk(a+1),n),onSelect:()=>{e.goTo(r)}})),`separator`,{label:`Reset layout`,onSelect:()=>{e.resetLayout()}}];return(0,q.jsx)(tj,{entries:r,trigger:(0,q.jsxs)(Y,{variant:`ghost`,children:[`Window`,(0,q.jsx)(ly,{})]})})},HY=({workspace:e})=>(0,q.jsxs)(`header`,{className:eA.bar,children:[(0,q.jsxs)(`h1`,{className:eA.name,children:[(0,q.jsx)(`img`,{alt:`Ork`,className:eA.logoOnDark,src:`/ork-wordmark-small.svg`}),(0,q.jsx)(`img`,{alt:`Ork`,className:eA.logoOnLight,src:`/ork-wordmark-small-on-light.svg`})]}),(0,q.jsx)(VY,{workspace:e}),(0,q.jsx)(`div`,{className:eA.spacer}),(0,q.jsx)(tA,{workspace:e}),(0,q.jsxs)(Y,{onClick:()=>{e.palette.setValue(!0)},variant:`ghost`,children:[(0,q.jsx)(gy,{}),`Commands`,(0,q.jsx)(a_,{keys:Wk(Jk.palette,Zk())})]})]}),UY,WY=class{constructor(){}},GY=class extends WY{constructor(e,t,n,r){super(),this.viewId=e,this.groupId=t,this.panelId=n,this.tabGroupId=r}},KY=class extends WY{constructor(e,t){super(),this.viewId=e,this.paneId=t}},qY=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)}};UY=qY,qY.INSTANCE=new UY;function JY(){let e=qY.getInstance();if(e.hasData(GY.prototype))return e.getData(GY.prototype)[0]}function YY(){let e=qY.getInstance();if(e.hasData(KY.prototype))return e.getData(KY.prototype)[0]}var XY;(function(e){e.NONE={dispose:()=>{}};function t(e){return{dispose:()=>{e()}}}e.from=t})(XY||={});var X=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())}},ZY=class{constructor(){this._disposable=XY.NONE}get value(){return this._disposable===XY.NONE?void 0:this._disposable}set value(e){this._disposable&&this._disposable.dispose(),this._disposable=e}dispose(){this._disposable&&=(this._disposable.dispose(),XY.NONE)}},QY;(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()})}}}})(QY||={});var $Y=class{constructor(){this._defaultPrevented=!1}get defaultPrevented(){return this._defaultPrevented}preventDefault(){this._defaultPrevented=!0}},eX=class{constructor(){this._isAccepted=!1}get isAccepted(){return this._isAccepted}accept(){this._isAccepted=!0}},tX=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()}},nX=class e{static create(){return new e(Error(`listener stacktrace`).stack??``)}constructor(e){this.value=e}print(){console.warn(`dockview: stacktrace`,this.value)}},rX=class{constructor(e,t){this.callback=e,this.stacktrace=t}},Z=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 rX(t,e.ENABLE_TRACKING?nX.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,nX.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),XY.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))}};Z.ENABLE_TRACKING=!1,Z.MEMORY_LEAK_WATCHER=new tX;function Q(e,t,n,r){return e.addEventListener(t,n,r),{dispose:()=>{e.removeEventListener(t,n,r)}}}var iX=class{constructor(){this._onFired=new Z,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()}},aX=class extends X{constructor(e){super(),this._onDidChange=new Z,this.onDidChange=this._onDidChange.event,this._value=null,this.addDisposables(this._onDidChange,oX(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 oX(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 sX=(e,...t)=>{for(let n of t)e.classList.contains(n)&&e.classList.remove(n)},cX=(e,...t)=>{for(let n of t)e.classList.contains(n)||e.classList.add(n)},$=(e,t,n)=>{let r=e.classList.contains(t);n&&!r&&e.classList.add(t),!n&&r&&e.classList.remove(t)};function lX(e,t){for(;e;){if(e===t)return!0;e=e.parentNode}return!1}function uX(e){return new dX(e)}var dX=class extends X{constructor(e){super(),this._onDidFocus=new Z,this.onDidFocus=this._onDidFocus.event,this._onDidBlur=new Z,this.onDidBlur=this._onDidBlur.event,this.addDisposables(this._onDidFocus,this._onDidBlur);let t=lX(FX(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=()=>{lX(FX(e),e)!==t&&(t?i():r())},this.addDisposables(Q(e,`focus`,r,!0)),this.addDisposables(Q(e,`blur`,i,!0))}refreshState(){this._refreshStateHandler()}},fX=`dv-quasiPreventDefault`;function pX(e){e[fX]=!0}function mX(e){return e[fX]}function hX(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 gX(e){let t=[],n=e.getRootNode();for(;xX(n);)t.push(n),n=n.host.getRootNode();return t}function _X(e,t){let n=t?.getRootNode(),r=e,i=r.getRootNode();for(;i!==n&&xX(i);)r=i.host,i=r.getRootNode();return r}function vX(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 yX(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 bX(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 xX(e){return!!e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&`host`in e&&!!e.host}function SX(e){let t=e.getRootNode();return t!==e&&typeof t.elementsFromPoint==`function`?t:e.ownerDocument??document}function CX(e,t){e.dataset.testid=t}function wX(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 TX(e=document){let t=wX([`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 EX(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 DX(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=xX(e)?e.host:null}else r=r.parentElement;return n}var OX=class{constructor(e){this.element=e,this._classNames=[]}setClassNames(e){for(let e of this._classNames)$(this.element,e,!1);this._classNames=e.split(` `).filter(e=>e.trim().length>0);for(let e of this._classNames)$(this.element,e,!0)}},kX=100;function AX(e,t){let n=yX(e),r=yX(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 jX(e){let t=new Z,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()},kX),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 MX(e,t){let n;return new X(Q(e,`resize`,()=>{clearTimeout(n),n=setTimeout(()=>{t()},kX)}),XY.from(()=>clearTimeout(n)))}function NX(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 PX(e){let t=e;for(;t&&(t.style.zIndex===`auto`||t.style.zIndex===``);)t=t.parentElement;return t}function FX(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 IX(e){let t=e.getRootNode();return xX(t)?t:(e.ownerDocument??document).body}function LX(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 RX(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var a=e.apply(t,n);function o(e){LX(a,r,i,o,s,`next`,e)}function s(e){LX(a,r,i,o,s,`throw`,e)}o(void 0)})}}function zX(e){let t=HX(e);if(t)throw t}var BX=new Set([`javascript:`,`data:`,`blob:`,`vbscript:`,`file:`]),VX=250;function HX(e,t=globalThis.location){let n;try{n=new URL(e,t.href)}catch{return Error(`dockview: invalid popout URL: ${e}`)}if(BX.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 UX=class extends X{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 Z,this.onWillClose=this._onWillClose.event,this._onDidClose=new Z,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 RX(function*(){var t,n;if(e._window)throw Error(`instance of popout window is already open`);let r=`${e.options.url}`;zX(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 X;e._window={value:a,disposable:o},o.addDisposables(XY.from(()=>{a.close()}),e.watchForClose(a),Q(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),vX(n,[...Array.from(globalThis.document.styleSheets),...globalThis.document.adoptedStyleSheets??[]],{nonce:e.options.nonce});let i=[];for(let t=(r=e.options).styleRoot?.call(r);xX(t);t=t.host.getRootNode())i.push(...Array.from(t.styleSheets??[]),...t.adoptedStyleSheets??[]);i.length>0&&vX(n,i,{nonce:e.options.nonce}),Q(a,`beforeunload`,()=>{e.close()}),t(s)}catch(e){n(e)}})})})()}watchForClose(e){if(typeof e.closed!=`boolean`)return XY.NONE;let t=setInterval(()=>{e.closed&&this.close()},VX);return XY.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 WX(e){if(e.length===0)throw Error(`Invalid tail call`);return[e.slice(0,e.length-1),e[e.length-1]]}function GX(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 KX(e,t){let n=e.indexOf(t);n>-1&&(e.splice(n,1),e.unshift(t))}function qX(e,t){let n=e.indexOf(t);n>-1&&(e.splice(n,1),e.push(t))}function JX(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(t(r))return n}return-1}function YX(e,t){let n=e.indexOf(t);return n>-1&&(e.splice(n,1),!0)}var XX=(e,t,n)=>t>n?t:Math.min(n,Math.max(e,t)),ZX=()=>{let e=1;return{next:()=>(e++).toString()}},QX=(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},$X=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=XX(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=XX(Math.round(this.size*e),this.minimumSize,this.maximumSize):this._cachedVisibleSize=Math.round(this._cachedVisibleSize*e)}dispose(){return this.disposable.dispose(),this.view}},eZ=function(e){return e.HORIZONTAL=`HORIZONTAL`,e.VERTICAL=`VERTICAL`,e}({});function tZ(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 nZ;(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})(nZ||={});var rZ=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),sX(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,$(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,$(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 Z,this.onDidSashEnd=this._onDidSashEnd.event,this._onDidAddView=new Z,this.onDidAddView=this._onDidAddView.event,this._onDidRemoveView=new Z,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=QX(e,-1),u=QX(e+1,this.viewItems.length);if(i)for(let e of i)KX(l,e),KX(u,e);if(r)for(let e of r)qX(l,e),qX(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=XX(t,h,g),y=0,b=v;for(let e of l){let t=this.viewItems[e],r=n[e],i=XX(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=XX(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`?(sX(this.element,`dv-separator-border`),this.element.style.removeProperty(`--dv-separator-border`)):(cX(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=QX(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=XX(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=XX(t,e.minimumSize,e.maximumSize),e.size=t;let r=QX(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=nZ.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 $X(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=TX(n),i=this._orientation===`HORIZONTAL`?t.clientX:t.clientY,a=JX(this.sashes,t=>t.container===e),o=this.viewItems.map(e=>e.size),s,c,l=QX(a,-1),u=QX(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=XX(n,t.minimumSize,t.maximumSize);let r=QX(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):nZ.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=XX(Math.round(i*e/t),r.minimumSize,r.maximumSize))}}else{let t=QX(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=QX(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)KX(r,e);for(let t of e)qX(r,t)}typeof e==`number`&&qX(r,e);for(let e=0;n!==0&&e<r.length;e++){let t=this.viewItems[r[e]],i=XX(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`&&tZ(r,`${n}px`,`0px`),this._orientation===`VERTICAL`&&tZ(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=QX(e,-1),a=QX(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){$(e.container,`dv-disabled`,t===2),$(e.container,`dv-enabled`,t===3),$(e.container,`dv-maximum`,t===0),$(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()}},iZ=Object.keys({orientation:void 0,descriptor:void 0,proportionalLayout:void 0,styles:void 0,margin:void 0,disableAutoResizing:void 0,className:void 0}),aZ=class extends X{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 Z,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 rZ(this.element,{orientation:this._orientation,proportionalLayout:!1,descriptor:t.descriptor}),this.getPanes().forEach(e=>{let t=new X(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:nZ.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),cX(this.element,`dv-animated`),this.animationTimer=setTimeout(()=>{this.animationTimer=void 0,sX(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()}},oZ=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 Z,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()}},sZ=class e extends X{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=XY.NONE,this.children=[],this._onDidChange=new Z,this.onDidChange=this._onDidChange.event,this._onDidVisibilityChange=new Z,this.onDidVisibilityChange=this._onDidVisibilityChange.event,this._onDidInvalidateSizes=new Z,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 rZ(this.element,{orientation:this.orientation,descriptor:e,proportionalLayout:t,styles:n,margin:o})}else this.splitview=new rZ(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 X(QY.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 X(t.onDidVisibilityChange(({visible:e})=>{this.setChildVisible(n,e)}),t.onDidInvalidateSizes(()=>{this.invalidateCachedSizes()})):XY.NONE))}dispose(){this._childrenDisposable.dispose(),this.splitview.dispose(),this.children.forEach(e=>e.dispose()),super.dispose()}};function cZ(e,t){if(e instanceof oZ)return e;if(e instanceof sZ)return cZ(e.children[t?e.children.length-1:0],t);throw Error(`invalid node`)}function lZ(e,t,n,r=1){let i=e.getChildCachedVisibleSize(t);return i===void 0?n:nZ.Invisible(Math.round(i*r))}function uZ(e,t,n){if(e instanceof sZ){let r=new sZ(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 sZ?n.orthogonalSize:n.size;r.addChild(uZ(n,n.size,n.orthogonalSize),lZ(e,t,i),0,!0)}return r}return new oZ(e.view,e.orientation,n)}function dZ(e,t,n){if(e instanceof sZ){let r=new sZ(_Z(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 sZ?s.orthogonalSize:s.size,l=e.size===0?0:Math.round(t*c/e.size);i+=l,o===0&&(l+=t-i),r.addChild(dZ(s,n,l),lZ(e,o,l,a),0,!0)}return r}return new oZ(e.view,_Z(e.orientation),n)}function fZ(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 pZ(e){let t=e.parentElement;if(!t)throw Error(`Invalid grid element`);if(/\bdv-grid-view\b/.test(t.className))return[];let n=fZ(t),r=t.parentElement.parentElement.parentElement;return[...pZ(r),n]}function mZ(e,t,n){if(gZ(e,t)===hZ(n)){let[e,r]=WX(t),i=r;return(n===`right`||n===`bottom`)&&(i+=1),[...e,i]}{let e=+(n===`right`||n===`bottom`);return[...t,e]}}function hZ(e){return e===`top`||e===`bottom`?`VERTICAL`:`HORIZONTAL`}function gZ(e,t){return t.length%2==0?_Z(e):e}var _Z=e=>e===`HORIZONTAL`?`VERTICAL`:`HORIZONTAL`;function vZ(e){return!!e.children}var yZ=(e,t)=>{let n=t===`VERTICAL`?e.box.width:e.box.height;if(!vZ(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=>yZ(e,_Z(t)));return typeof e.cachedVisibleSize==`number`?{type:`branch`,data:r,size:e.cachedVisibleSize,visible:!1}:{type:`branch`,data:r,size:n}},bZ=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=dZ(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 sZ&&(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=pZ(e.element),[n,r]=this.getNode(t);if(!(r instanceof oZ)||this._maximizedNode?.leaf===r)return;this.hasMaximizedView()&&this.exitMaximizedView(),yZ(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 oZ?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 oZ?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=pZ(e.element));let n=this._onDidMaximizedNodeChange.pause();try{this.hasMaximizedView()&&this.exitMaximizedView();let n={root:yZ(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 sZ(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 oZ))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,_Z(t),n,e.size),visible:r.visible}));i=new sZ(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 oZ(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 oZ)return;e.element.remove();let n=e.removeChild(0);e.dispose(),n.dispose(),this._root=uZ(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 sZ(_Z(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(dZ(t,t.orthogonalSize,t.size),nZ.Distribute,0)}else this._root.addChild(e,nZ.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 oZ)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,_Z(t),a))}return{box:r,children:i,cachedVisibleSize:n}}progmaticSelect(e,t=!1){let[n,r]=this.getNode(e);if(!(r instanceof oZ))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 cZ(i.children[t?a-1:a+1],t)}return cZ(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 ZY,this._onDidChange=new Z,this.onDidChange=this._onDidChange.event,this._onDidViewVisibilityChange=new Z,this.onDidViewVisibilityChange=this._onDidViewVisibilityChange.event,this._onDidMaximizedNodeChange=new Z,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 sZ(n,e,t,0,0,this.locked,this.margin)}isViewVisible(e){let[t,n]=WX(e),[,r]=this.getNode(t);if(!(r instanceof sZ))throw TypeError(`Invalid from location`);return r.isChildVisible(n)}setViewVisible(e,t){this.hasMaximizedView()&&this.exitMaximizedView();let[n,r]=WX(e),[,i]=this.getNode(n);if(!(i instanceof sZ))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 sZ))throw TypeError(`Invalid location`);r.moveChild(t,n)}addView(e,t,n){this.hasMaximizedView()&&this.exitMaximizedView();let[r,i]=WX(n),[a,o]=this.getNode(r);if(o instanceof sZ){let n=new oZ(e,_Z(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=nZ.Invisible(d)),n.removeChild(c).dispose();let f=new sZ(o.orientation,this.proportionalLayout,this.styles,o.size,o.orthogonalSize,this.locked,this.margin);n.addChild(f,o.size,c);let p=new oZ(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 oZ(e,n.orientation,o.size);f.addChild(m,t,i)}}remove(e,t){let n=pZ(e.element);return this.removeView(n,t)}removeView(e,t){this.hasMaximizedView()&&this.exitMaximizedView();let[n,r]=WX(e),[i,a]=this.getNode(n);if(!(a instanceof sZ))throw TypeError(`Invalid location`);let o=a.children[r];if(!(o instanceof oZ))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 oZ||(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 sZ){let e=s.children.map(e=>e instanceof sZ?e.orthogonalSize:e.size);p.splice(u,1,...e);for(let t=0;t<s.children.length;t++){let n=s.children[t],r=lZ(s,t,e[t]);c.addChild(n,!f&&typeof r==`number`?nZ.Invisible(r):r,u+t)}for(;s.children.length>0;)s.removeChild(0)}else{let e=new oZ(s.view,_Z(s.orientation),s.size),t=f?s.orthogonalSize:nZ.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 sZ))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)}},xZ=Object.keys({disableAutoResizing:void 0,proportionalLayout:void 0,orientation:void 0,hideBorders:void 0,className:void 0}),SZ=class extends X{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(oX(this._element,e=>{if(this.isDisposed||this.disableResizing||!this._element.offsetParent||!bX(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||!bX(this._element))return;let e=Math.round(this._element.clientWidth),t=Math.round(this._element.clientHeight);e!==0&&t!==0&&this.layout(e,t)}},CZ=ZX();function wZ(e){switch(e){case`left`:return`left`;case`right`:return`right`;case`above`:return`top`;case`below`:return`bottom`;default:return`center`}}var TZ=class extends SZ{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=CZ.next(),this._groups=new Map,this._onDidRemove=new Z,this.onDidRemove=this._onDidRemove.event,this._onDidAdd=new Z,this.onDidAdd=this._onDidAdd.event,this._onDidMaximizedChange=new Z,this.onDidMaximizedChange=this._onDidMaximizedChange.event,this._onDidActiveChange=new Z,this.onDidActiveChange=this._onDidActiveChange.event,this._bufferOnDidLayoutChange=new iX,this.onDidLayoutChange=QY.map(this._bufferOnDidLayoutChange.onEvent,e=>({reasons:e})),this._onDidViewVisibilityChangeMicroTaskQueue=new iX,this.onDidViewVisibilityChangeMicroTaskQueue=this._onDidViewVisibilityChangeMicroTaskQueue.onEvent,this.element.style.height=`100%`,this.element.style.width=`100%`,this._classNames=new OX(this.element),this._classNames.setClassNames(t.className??``),e.appendChild(this.element),this.gridview=new bZ(!!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()}),XY.from(()=>{this.element.remove()}),this.gridview.onDidChange(()=>{this._bufferOnDidLayoutChange.fire(`geometry`)}),QY.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(pZ(e.element),t),this._bufferOnDidLayoutChange.fire(`geometry`)}isVisible(e){return this.gridview.isViewVisible(pZ(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??nZ.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,nZ.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=pZ(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=pZ(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 EZ(e){"@babel/helpers - typeof";return EZ=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},EZ(e)}function DZ(e,t){if(EZ(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(EZ(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function OZ(e){var t=DZ(e,`string`);return EZ(t)==`symbol`?t:t+``}function kZ(e,t,n){return(t=OZ(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function AZ(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 jZ(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?AZ(Object(n),!0).forEach(function(t){kZ(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):AZ(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function MZ(e,t){return e===`center`?`Tab into ${t}`:`Split ${e} of ${t}`}function NZ(e,t){return e===`center`?`docked into ${t}`:`split ${e} of ${t}`}var PZ={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)=>`${MZ(e,t)}. Arrows to change, Enter to confirm, Escape to go back.`,moveCommitted:(e,t,n)=>`${e} ${NZ(n,t)}.`,moveCancelled:()=>`Move cancelled.`,moveNotAllowed:()=>`That move is not allowed.`,moveFloated:e=>`${e} floated.`};function FZ(e){return e?jZ(jZ({},PZ),e):PZ}var IZ=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()}},LZ=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()}},RZ=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()}},zZ=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 FZ(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()}},BZ=class extends X{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(Q(this.element,`dragenter`,e=>{this.onDragEnter(e)},!0)),this.addDisposables(Q(this.element,`dragover`,e=>{this.onDragOver(e)},!0)),this.addDisposables(Q(this.element,`dragleave`,e=>{this.onDragLeave(e)})),this.addDisposables(Q(this.element,`dragend`,e=>{this.onDragEnd(e)})),this.addDisposables(Q(this.element,`drop`,e=>{this.onDrop(e)}))}},VZ={value:50,type:`percentage`},HZ=100,UZ=100;function WZ(){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 GZ(e,t,n,r){let i=r?.smallWidthBoundary??HZ,a=r?.smallHeightBoundary??UZ,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??VZ;return _.type===`percentage`?g=XX(_.value,0,100)/100:((f||p)&&(g=XX(_.value,0,t)/t),(m||h)&&(g=XX(_.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 KZ(e,t,n,r,i){let a=GZ(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);$(e,`dv-drop-target-small-vertical`,a.isSmallY),$(e,`dv-drop-target-small-horizontal`,a.isSmallX),$(e,`dv-drop-target-selection-line`,f),$(e,`dv-drop-target-left`,a.isLeft),$(e,`dv-drop-target-right`,a.isRight),$(e,`dv-drop-target-top`,a.isTop),$(e,`dv-drop-target-bottom`,a.isBottom),$(e,`dv-drop-target-center`,t===`center`)}function qZ(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 JZ(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 YZ(e){let t=GZ(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),qZ(u,m)?(JZ(u,m),u.className=`dv-drop-target-anchor${e.className?` ${e.className}`:``}`,$(u,`dv-drop-target-left`,t.isLeft),$(u,`dv-drop-target-right`,t.isRight),$(u,`dv-drop-target-top`,t.isTop),$(u,`dv-drop-target-bottom`,t.isBottom),$(u,`dv-drop-target-anchor-line`,t.isSmallX&&(t.isLeft||t.isRight)||t.isSmallY&&(t.isTop||t.isBottom)),$(u,`dv-drop-target-center`,e.quadrant===`center`),c.changed&&($(u,`dv-drop-target-anchor-container-changed`,!0),setTimeout(()=>{$(u,`dv-drop-target-anchor-container-changed`,!1)},10)),{boundsChanged:!0,targetChanged:c.changed}):{boundsChanged:!1,targetChanged:c.changed}}var XZ=class extends $Y{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 ZZ(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 QZ(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 $Z={value:20,type:`percentage`},eQ=class e extends X{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 Z,this.onDrop=this._onDrop.event,this._onWillShowOverlay=new Z,this.onWillShowOverlay=this._onWillShowOverlay.event,this._disabled=!1,this._acceptedTargetZonesSet=new Set(this.options.acceptedTargetZones),this.dnd=new BZ(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 XZ({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=WZ();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;YZ({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&&KZ(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??$Z;return a.type===`percentage`?tQ(e,t,n,r,i,a.value):nQ(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=WZ();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}};eQ.USED_EVENT_ID=`__dockview_droptarget_event_is_used__`;function tQ(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 nQ(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 rQ(e,t,n){cX(t,`dv-dragged`),t.style.top=`-9999px`,t.style.position=`absolute`,(n?.owner?IX(n.owner):(n?.ownerDocument??document).body).appendChild(t),e.setDragImage(t,n?.x??0,n?.y??0),setTimeout(()=>{sX(t,`dv-dragged`),t.remove()},0)}var iQ=class e extends X{static getInstance(){return e._instance??=new e,e._instance}constructor(){super(),this._targets=new Set,this._targetByElement=new Map,this._onDragStart=new Z,this.onDragStart=this._onDragStart.event,this._onDragMove=new Z,this.onDragMove=this._onDragMove.event,this._onDragEnd=new Z,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=TX(n.ownerDocument??document),this._selectionShield=EX(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=Q(a,`pointermove`,e=>{e.pointerId===this._active?.pointerId&&this._handleMove(e)}),this._upListener=Q(a,`pointerup`,e=>{e.pointerId===this._active?.pointerId&&this._handleEnd(e,!0)}),this._cancelListener=Q(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?SX(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}},aQ={value:20,type:`percentage`},oQ=class extends X{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 Z,this.onDrop=this._onDrop.event,this._onWillShowOverlay=new Z,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,iQ.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 XZ({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)YZ({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=WZ();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&&KZ(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??aQ;return i.type===`percentage`?tQ(this._acceptedTargetZonesSet,e,t,n,r,i.value):nQ(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}},sQ=5,cQ=250,lQ=8,uQ=class extends X{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(Q(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=EX(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)??cQ;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??sQ,a=this.options.pressTolerance,o=(typeof a==`function`?a():a)??lQ,s=this.element.ownerDocument?.defaultView??globalThis.window;this._pendingMoveListener=Q(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=Q(s,`pointerup`,e=>{e.pointerId===this._pendingPointerId&&this._cancelPending()}),this._pendingCancelListener=Q(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);iQ.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()}},dQ=class{constructor(e){this._disposed=!1,this.element=e.element,this.offsetX=e.offsetX??0,this.offsetY=e.offsetY??0;let t=e.owner?IX(e.owner):document.body,n;xX(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())}},fQ=class extends X{constructor(e,t){super(),this.el=e,this.opts=t,this._dataDisposable=new ZY,this._pointerEventsDisposable=new ZY,this._disabled=!!t.disabled,this.addDisposables(this._dataDisposable,this._pointerEventsDisposable,Q(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=TX(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&&(rQ(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`,``))}),Q(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(){}},pQ=class{constructor(){this.kind=`html5`}createDropTarget(e,t){return new eQ(e,t)}createDragSource(e,t){return new fQ(e,t)}},mQ=class{constructor(){this.kind=`pointer`}createDropTarget(e,t){return new oQ(e,t)}createDragSource(e,t){let n=t.createGhost?n=>{let r=t.createGhost(n);if(!r)return;let i=new dQ({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 uQ(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}},hQ=new pQ,gQ=new mQ,_Q=Object.keys({disableAutoResizing:void 0,disableDnd:void 0,className:void 0}),vQ=class extends eX{constructor(e,t,n,r){super(),this.nativeEvent=e,this.position=t,this.getData=n,this.panel=r}},yQ=class extends $Y{constructor(){super()}},bQ=class extends X{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 ZY,this._onDidDimensionChange=new Z,this.onDidDimensionsChange=this._onDidDimensionChange.event,this._onDidChangeFocus=new Z,this.onDidFocusChange=this._onDidChangeFocus.event,this._onWillFocus=new Z,this.onWillFocus=this._onWillFocus.event,this._onDidVisibilityChange=new Z,this.onDidVisibilityChange=this._onDidVisibilityChange.event,this._onWillVisibilityChange=new Z,this.onWillVisibilityChange=this._onWillVisibilityChange.event,this._onDidActiveChange=new Z,this.onDidActiveChange=this._onDidActiveChange.event,this._onActiveChange=new Z,this.onActiveChange=this._onActiveChange.event,this._onDidParametersChange=new Z,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)}},xQ=class extends bQ{constructor(e,t){super(e,t),this._onDidConstraintsChangeInternal=new Z,this.onDidConstraintsChangeInternal=this._onDidConstraintsChangeInternal.event,this._onDidConstraintsChange=new Z({replay:!0}),this.onDidConstraintsChange=this._onDidConstraintsChange.event,this._onDidSizeChange=new Z,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)}},SQ=class extends xQ{set pane(e){this._pane=e}constructor(e,t){super(e,t),this._onDidExpansionChange=new Z({replay:!0}),this.onDidExpansionChange=this._onDidExpansionChange.event,this._onMouseEnter=new Z({}),this.onMouseEnter=this._onMouseEnter.event,this._onMouseLeave=new Z({}),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()}},CQ=class extends X{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=uX(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 yQ;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=jZ(jZ({},this._params),{},{params:jZ(jZ({},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()}},wQ=class extends CQ{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 SQ(e.id,e.component)),this._onDidChangeExpansionState=new Z({replay:!0}),this.onDidChangeExpansionState=this._onDidChangeExpansionState.event,this._onDidChange=new Z,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})}),Q(this.element,`mouseenter`,e=>{this.api._onMouseEnter.fire(e)}),Q(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?cX(this.header,`focused`):sX(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(jZ(jZ({},e),{},{api:this.api})),this.headerPart.init(jZ(jZ({},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 jZ(jZ({},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()}}}},TQ=class extends wQ{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 Z,this.onDidDrop=this._onDidDrop.event,this._onUnhandledDragOver=new Z,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:()=>(qY.getInstance().setData([new KY(t,e)],KY.prototype),{dispose:()=>{qY.getInstance().clearData(KY.prototype)}})};this.html5DragSource=hQ.createDragSource(this.header,n),this.pointerDragSource=gQ.createDragSource(this.header,n);let r={acceptedTargetZones:[`top`,`bottom`],overlayModel:{activationSize:{type:`percentage`,value:50}},canDisplayOverlay:(e,t)=>{let n=YY();if(n&&n.paneId!==this.id&&n.viewId===this.accessor.id)return!0;let r=new vQ(e,t,YY,this);return this._onUnhandledDragOver.fire(r),r.isAccepted}};this.target=hQ.createDropTarget(this.element,r),this.pointerTarget=gQ.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=YY();if(t?.viewId!==this.accessor.id){this._onDidDrop.fire(jZ(jZ({},e),{},{panel:this,api:new LZ(this.accessor),getData:YY}));return}let n=this._params.containerApi,r=t.paneId,i=n.getPanel(r);if(!i){this._onDidDrop.fire(jZ(jZ({},e),{},{panel:this,getData:YY,api:new LZ(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)}},EQ=0,DQ=()=>`dv-tabpanel-${EQ++}`,OQ=class extends X{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 ZY,this._onDidFocus=new Z,this.onDidFocus=this._onDidFocus.event,this._onDidBlur=new Z,this.onDidBlur=this._onDidBlur.event,this._onDidDimensionsChange=new Z,this.onDidDimensionsChange=this._onDidDimensionsChange.event,this._element=document.createElement(`div`),this._element.className=`dv-content-container`,this._element.tabIndex=-1,this._element.id=DQ(),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 eQ(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=gQ.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)})??XY.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=uX(a);this.focusTracker=e;let t=new X;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()}},kQ=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},AQ=()=>kQ({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`}),jQ=()=>kQ({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`}),MQ=()=>kQ({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`}),NQ=()=>kQ({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`}),PQ=500,FQ=8,IQ=class extends X{constructor(e,t){super(),this.element=e,this.options=t,this._startX=0,this._startY=0,this.addDisposables(Q(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??PQ,n=this.options.tolerance??FQ,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=Q(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=Q(r,`pointerup`,e=>{e.pointerId===this._pointerId&&this._cancelPending()}),this._cancelListener=Q(r,`pointercancel`,e=>{e.pointerId===this._pointerId&&this._cancelPending()})}_installContextMenuGuard(e){let t,n=setTimeout(()=>t?.dispose(),500);t=Q(e,`contextmenu`,e=>{e.preventDefault(),clearTimeout(n),t?.dispose()},{capture:!0})}_installClickGuard(e){let t,n=setTimeout(()=>t?.dispose(),500);t=Q(e,`click`,e=>{hX(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 LQ(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 RQ()?{html5:!1,pointer:!0,pointerHandlesMouse:!0}:{html5:!0,pointer:!0,pointerHandlesMouse:!1}}}function RQ(){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 zQ=0,BQ=()=>`dv-tab-${zQ++}`,VQ=class extends X{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=qY.getInstance(),this._direction=`horizontal`,this._pinIndicator=void 0,this._onPointDown=new Z,this.onPointerDown=this._onPointDown.event,this._onTabClick=new Z,this.onTabClick=this._onTabClick.event,this._onDropped=new Z,this.onDrop=this._onDropped.event,this._onDragStart=new Z,this.onDragStart=this._onDragStart.event,this._onDragEnd=new Z,this.onDragEnd=this._onDragEnd.event;let c=LQ(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=BQ(),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),$(this.element,`dv-inactive-tab`,!0),this._updatePinnedClasses();let u=(e,t)=>{if(this.group.locked)return!1;let n=JY();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=hQ.createDropTarget(this._element,{acceptedTargetZones:[`left`,`right`],overlayModel:this._buildOverlayModel(),canDisplayOverlay:u,getOverrideTarget:()=>n.model.dropTargetContainer?.model}),this.pointerDropTarget=gQ.createDropTarget(this._element,{acceptedTargetZones:[`left`,`right`],overlayModel:this._buildOverlayModel(),canDisplayOverlay:u,getOverrideTarget:()=>n.model.dropTargetContainer?.model});let d={getData:()=>(this.panelTransfer.setData([new GY(this.accessor.id,this.group.id,this.panel.id)],GY.prototype),{dispose:()=>{this.panelTransfer.clearData(GY.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(()=>{$(this.element,`dv-tab--dragging`,!0)})},onDragEnd:e=>{this._onDragEnd.fire(e)}};this.html5DragSource=hQ.createDragSource(this._element,jZ(jZ({},d),{},{disabled:!c.html5})),this.pointerDragSource=gQ.createDragSource(this._element,jZ(jZ({},d),{},{disabled:!c.pointer,touchOnly:!c.pointerHandlesMouse,isCancelled:()=>!LQ(this.accessor.options).pointer})),this.onWillShowOverlay=QY.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:()=>{}},Q(this._element,`dragend`,()=>{$(this.element,`dv-tab--dragging`,!1)}),this.html5DragSource,Q(this._element,`pointerdown`,e=>{this._onPointDown.fire(e)}),Q(this._element,`click`,e=>{this._onTabClick.fire(e)}),Q(this._element,`contextmenu`,e=>{var t;(t=this.accessor.contextMenuService)==null||t.show(this.panel,this.group,e)}),new IQ(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;$(this.element,`dv-tab--pinned`,e),$(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(jQ()),this._element.insertBefore(e,this._element.firstChild),this._pinIndicator=e}else!n&&this._pinIndicator&&(this._pinIndicator.remove(),this._pinIndicator=void 0)}setActive(e){$(this.element,`dv-active-tab`,e),$(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=LQ(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}},HQ=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}},UQ=class extends X{get group(){return this.groupAccessor()}constructor(e){var t;super(),this.panelTransfer=qY.getInstance(),this._onDragStart=new Z,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=LQ(this.accessor.options);this._element.draggable=r.html5,$(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 GY(this.accessor.id,this.group.id,null)],GY.prototype),{dispose:()=>{this.panelTransfer.clearData(GY.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=hQ.createDragSource(this._element,jZ(jZ({},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=gQ.createDragSource(this._element,jZ(jZ({},a),{},{disabled:!r.pointer,touchOnly:!r.pointerHandlesMouse,touchInitiationDelay:()=>o()?500:250,pressTolerance:()=>o()?1/0:8,isCancelled:()=>!LQ(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 ZY,c=()=>{let e=this.getFloatingOverlay();s.value=e?e.onDidStartMoving(()=>{this.pointerDragSource.cancelPending()}):XY.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=LQ(this.accessor.options);this._element.draggable=e.html5,$(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}},WQ=class extends X{get element(){return this._element}constructor(e,t){var n,r,i;super(),this.accessor=e,this.group=t,this._onDrop=new Z,this.onDrop=this._onDrop.event,this._onDragStart=new Z,this.onDragStart=this._onDragStart.event,this._element=document.createElement(`div`),this._element.className=`dv-void-container`,this.addDisposables(this._onDrop,this._onDragStart,Q(this._element,`pointerdown`,()=>{this.accessor.doSetGroupActive(this.group)}),Q(this._element,`pointerdown`,e=>{e.shiftKey&&pX(e)},!0)),this.dragSource=new UQ({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=JY();return this.accessor.id===r?.viewId||t.model.canDisplayOverlay(e,n,`header_space`)};this.dropTarget=hQ.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=gQ.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=QY.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)})??XY.NONE)}updateDragAndDropState(){this.dragSource.updateDragAndDropState()}},GQ=class e extends X{get element(){return this._element}get orientation(){return this._orientation}set orientation(e){this._orientation!==e&&(this._scrollOffset=0,this._orientation=e,sX(this._scrollbar,`dv-scrollbar-vertical`,`dv-scrollbar-horizontal`),e===`vertical`?cX(this._scrollbar,`dv-scrollbar-vertical`):cX(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(Q(this.element,`wheel`,t=>{this._scrollOffset+=t.deltaY*e.MouseWheelSpeed,this.scheduleStyleUpdate()}),Q(this._scrollbar,`pointerdown`,e=>{e.preventDefault();let t=this._scrollbar.ownerDocument??document;$(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=()=>{$(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)}),Q(this.element,`scroll`,()=>{this.scheduleStyleUpdate()}),Q(this.scrollableElement,`scroll`,()=>{this._scrollOffset=this._orientation===`horizontal`?this.scrollableElement.scrollLeft:this.scrollableElement.scrollTop,this.scheduleStyleUpdate()}),oX(this.element,()=>{$(this.element,`dv-scrollable-resizing`,!0),this._animationTimer&&clearTimeout(this._animationTimer),this._animationTimer=setTimeout(()=>{clearTimeout(this._animationTimer),$(this.element,`dv-scrollable-resizing`,!1)},500),this.scheduleStyleUpdate()}),XY.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=XX(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}};GQ.MouseWheelSpeed=1;var KQ=`dv-tabs-container--wrap`;function qQ(e,t){return typeof e==`boolean`?e:!!e?.[t]}function JQ(e){return typeof e==`boolean`?e:e?Object.values(e).some(Boolean):!1}var YQ=class extends eX{constructor(e,t,n,r,i){super(),this.nativeEvent=e,this.target=t,this.position=n,this.getData=r,this.group=i}},XQ=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 ZQ(e){return!!e.referencePanel}function QQ(e){return!!e.referenceGroup}function $Q(e){return!!e.referencePanel}function e$(e){return!!e.referenceGroup}var t$=[{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`}],n$=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}},r$;function i$(){return r$??=new n$(t$,!0),r$}function a$(e,t,n){let r=(n??i$()).resolveValue(t);r===void 0?e.style.removeProperty(`--dv-tab-group-color`):e.style.setProperty(`--dv-tab-group-color`,r)}function o$(e,t){return(t??i$()).resolveValue(e)}var s$=class extends X{get element(){return this._element}constructor(e){super(),this._palette=e,this._onClick=new Z,this.onClick=this._onClick.event,this._onContextMenu=new Z,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 IQ(this._element,{onLongPress:e=>{this._onContextMenu.fire(e)}}),Q(this._element,`click`,e=>{this._onClick.fire(e)}),Q(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){a$(this._element,e,this._palette),$(this._element,`dv-tab-group-chip--accent-off`,this._palette?.enabled===!1)}updateLabel(e){this._label.textContent=e,$(this._label,`dv-tab-group-chip-label--empty`,!e)}updateCollapsed(e){$(this._element,`dv-tab-group-chip--collapsed`,e)}},c$=`dv-tab-group-chip-continuation`,l$=8,u$=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=c$,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(KQ);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=o$(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-l$/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-l$/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}}},d$=class extends u${_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=o$(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)}}},f$=class extends u${applyShape(e,t,n,r,i,a,o,s){let c=o$(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`))}},p$=new Map,m$=class{get chipRenderers(){return this._chipRenderers}get groupUnderlines(){return this._indicator?.underlines??p$}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=LQ(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`?f$:d$;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=LQ(this._ctx.accessor.options);e.element.draggable=n.html5;let r=qY.getInstance(),i=()=>(r.setData([new GY(this._ctx.accessor.id,this._ctx.group.id,null,t.id)],GY.prototype),{dispose:()=>{r.clearData(GY.prototype)}}),a=hQ.createDragSource(e.element,{getData:i,disabled:!n.html5,isCancelled:()=>!LQ(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(GY.prototype)};e.element.addEventListener(`dragend`,o,{once:!0});let s=gQ.createDragSource(e.element,{getData:i,disabled:!n.pointer,touchOnly:!n.pointerHandlesMouse,isCancelled:()=>!LQ(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 s$(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 s$?a.push(r.onContextMenu(o)):a.push(new IQ(r.element,{onLongPress:o}),Q(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=JY();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=hQ.createDropTarget(r.element,s),l=gQ.createDropTarget(r.element,s),u=t=>{this._callbacks.onChipDrop(e,t)};a.push(c,c.onDrop(u),l,l.onDrop(u));let d=new X(...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($(t.element,`dv-tab--grouped`,s),o){let e=o.panelIds,i=e[0]===n,s=e[e.length-1]===n;$(t.element,`dv-tab--group-first`,i),$(t.element,`dv-tab--group-last`,s),a$(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 $(t.element,`dv-tab--group-first`,!1),$(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 h$(e,t){return t===`vertical`?e.height:e.width}function g$(e,t){return t===`vertical`?e.top:e.left}function _$(e,t){return t===`vertical`?e.clientY:e.clientX}var v$=class extends X{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(KQ)}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 h$(e,this._direction)}_mainAxisStart(e){return g$(e,this._direction)}_mainAxisCoord(e,t){return _$({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=SX(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=SX(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(jZ({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=JY();e?.tabGroupId&&e.groupId!==this.group.id&&this._animState.sourceTabGroupId!==e.tabGroupId&&(this._animState=null)}_initAnimStateForExternalDrag(){let e=JY();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`,$(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),$(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),$(e,n,!1);else{e.style.setProperty(r,`0px`),$(e,n,!0);let t=()=>{e.style.removeProperty(r),$(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`),$(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`),$(e.chip.element,`dv-tab-group-chip--shifting`,!1);this._tabGroupManager.positionUnderlines()}commitGroupMove(e,t){let n=JY();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)`,$(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)`,$(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)$(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)})}},y$=class extends X{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 aX(this._tabsList);this._observerDisposable.value=new X(e,e.onDidChange(e=>{let t=e.hasScrollX||e.hasScrollY;this.toggleDropdown({reset:!t}),this._applyPinnedSticky(),this._tabGroupManager.groupUnderlines.size>0&&this._tabGroupManager.positionUnderlines()}),Q(this._tabsList,`scroll`,()=>{this.toggleDropdown({reset:!1}),this._applyPinnedSticky(),this._tabGroupManager.groupUnderlines.size>0&&this._tabGroupManager.positionUnderlines()}))}else this._observerDisposable.value=XY.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 X(Q(e,`dragover`,e=>{this._animState&&e.preventDefault()}),Q(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),sX(this._tabsList,`dv-horizontal`,`dv-vertical`),e===`vertical`?cX(this._tabsList,`dv-tabs-container-vertical`,`dv-vertical`):(sX(this._tabsList,`dv-tabs-container-vertical`),cX(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 ZY,this._pointerActivation=new ZY,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 Z,this.onTabDragStart=this._onTabDragStart.event,this._onDrop=new Z,this.onDrop=this._onDrop.event,this._onWillShowOverlay=new Z,this.onWillShowOverlay=this._onWillShowOverlay.event,this._onOverflowTabsChange=new Z,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 GQ(this._tabsList),this._scrollbar.orientation=this.direction,this._element=this._scrollbar.element,this.addDisposables(this._scrollbar)),this._tabGroupManager=new m$({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 v$(this);let r=gQ.createDropTarget(this._tabsList,{acceptedTargetZones:[`center`],canDisplayOverlay:()=>!1,isHitTestTransparent:()=>{let e=JY();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,iQ.getInstance().onDragEnd(e=>{this._reorder.handlePointerDragEnd(e)}),iQ.getInstance().onDragMove(e=>{this._reorder.handlePointerDragMove(e.clientX,e.clientY)}),Q(this.element,`pointerdown`,e=>{e.defaultPrevented||e.button===0&&this.accessor.doSetGroupActive(this.group)}),Q(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}),Q(this._tabsList,`keydown`,e=>{this._onKeyDown(e)}),Q(this._tabsList,`dragover`,e=>{this._reorder.processDragOver(e.clientX,e.clientY)&&e.preventDefault()},!0),Q(this._tabsList,`dragleave`,e=>{this._reorder.processDragLeave(e.relatedTarget)},!0),Q(this._tabsList,`dragend`,()=>{this._reorder.resetDragAnimation()}),Q(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(jZ({event:e},r)),this.runFlipAnimation(a,n.sourceTabId,i===-1,{from:Math.min(i,r.index),to:Math.max(i,r.index)})},!0),XY.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(!LQ(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 VQ(e,this.accessor,this.group);n.setContent(e.view.tab),this._direction!==`horizontal`&&n.setDirection(this._direction);let r={value:n,disposable:new X(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=h$(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:g$(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`,$(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=JY(),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 HQ(e,{kind:`tab`,panel:this.group.activePanel,api:this.accessor.api,group:this.group,getData:JY}))}))};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&&!AX(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&&!AX(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&&!AX(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=h$(a,this._direction);for(let t of e.panelIds){let e=this._tabMap.get(t);e&&(o+=h$(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:h$(a,this._direction),cursorOffsetFromDragStart:_$(n,this._direction)-g$(a,this._direction),sourceGapSize:o,containerStart:g$(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`,$(e.value.element,`dv-tab--dragging`,!0));let n=this._tabGroupManager.chipRenderers.get(e.id);n&&(n.chip.element.style.transition=`none`,$(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=JY();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 b$(){let e=document.createElement(`div`);e.className=`dv-tabs-overflow-dropdown-default`;let t=document.createElement(`span`);t.textContent=``;let n=NQ();return e.appendChild(n),e.appendChild(t),{element:e,update:e=>{t.textContent=`${e.tabs}`}}}var x$=class extends X{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`?(cX(this._element,`dv-groupview-header-vertical`),cX(this.rightActionsContainer,`dv-right-actions-container-vertical`),this.tabs.direction=e):(sX(this._element,`dv-groupview-header-vertical`),sX(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 ZY,this._onDrop=new Z,this.onDrop=this._onDrop.event,this._onGroupDragStart=new Z,this.onGroupDragStart=this._onGroupDragStart.event,this._onWillShowOverlay=new Z,this.onWillShowOverlay=this._onWillShowOverlay.event,this._element=document.createElement(`div`),this._element.className=`dv-tabs-and-actions-container`,$(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 y$(t,e,{showTabsOverflowControl:!e.options.disableTabsOverflowList}),this.voidContainer=new WQ(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 HQ(e,{kind:`header_space`,panel:this.group.activePanel,api:this.accessor.api,group:this.group,getData:JY}))}),Q(this.leftActionsContainer,`dragleave`,e=>{let t=e.relatedTarget;!this.leftActionsContainer.contains(t)&&!this._element.contains(t)&&this.tabs.clearExternalAnimState()}),Q(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())}),Q(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)),$(this._element,`dv-tabs-and-actions-container--pinned-row`,!!e))}setDropIndexResolver(e){this._dropIndexResolver=e}resolveDropIndex(e,t){return this._dropIndexResolver(e,t)}updateClassnames(){$(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=b$();o.update({tabs:i}),this.dropdownPart=o,a.appendChild(o.element),this.rightActionsContainer.prepend(a),this._dropdownDisposable.value=new X(XY.from(()=>{var e,t;a.remove(),(e=this.dropdownPart)==null||(t=e.dispose)==null||t.call(e),this.dropdownPart=null}),Q(a,`pointerdown`,e=>{e.preventDefault()},{capture:!0}),Q(a,`click`,e=>{let t=PX(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 X,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`,a$(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=jQ();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=XY.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`);$(d,`dv-tab`,!0),$(d,`dv-active-tab`,t.api.isActive),$(d,`dv-inactive-tab`,!t.api.isActive),r&&$(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()}},S$=class extends X{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 Z,this.onDidChange=this._onDidChange.event,this._onDidPanelChange=new Z,this.onDidPanelChange=this._onDidPanelChange.event,this._onDidCollapseChange=new Z,this.onDidCollapseChange=this._onDidCollapseChange.event,this._onDidDestroy=new Z,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()}},C$=class extends $Y{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()}},w$=class extends C${get kind(){return this._kind}constructor(e){super(e),this._kind=e.kind}},T$=class extends X{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,$(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=FX(e);return t?lX(t,e):!1}get headerPosition(){return this._headerPosition??`top`}set headerPosition(e){this._headerPosition=e,this.invalidateHeaderSize(),sX(this.container,`dv-groupview-header-top`,`dv-groupview-header-bottom`,`dv-groupview-header-left`,`dv-groupview-header-right`),cX(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,$(this.container,`dv-groupview-floating`,!1),$(this.container,`dv-groupview-popout`,!1),$(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`]),$(this.container,`dv-groupview-floating`,!0);break;case`popout`:t([`top`,`bottom`,`left`,`right`,`center`]),$(this.container,`dv-groupview-popout`,!0);break;case`edge`:t([`center`]),$(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 Z,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 Z,this.onMove=this._onMove.event,this._onDidDrop=new Z,this.onDidDrop=this._onDidDrop.event,this._onWillDrop=new Z,this.onWillDrop=this._onWillDrop.event,this._onWillShowOverlay=new Z,this.onWillShowOverlay=this._onWillShowOverlay.event,this._onTabDragStart=new Z,this.onTabDragStart=this._onTabDragStart.event,this._onGroupDragStart=new Z,this.onGroupDragStart=this._onGroupDragStart.event,this._onDidAddPanel=new Z,this.onDidAddPanel=this._onDidAddPanel.event,this._onDidPanelTitleChange=new Z,this.onDidPanelTitleChange=this._onDidPanelTitleChange.event,this._onDidPanelParametersChange=new Z,this.onDidPanelParametersChange=this._onDidPanelParametersChange.event,this._onDidRemovePanel=new Z,this.onDidRemovePanel=this._onDidRemovePanel.event,this._onDidActivePanelChange=new Z,this.onDidActivePanelChange=this._onDidActivePanelChange.event,this._onUnhandledDragOver=new Z,this.onUnhandledDragOver=this._onUnhandledDragOver.event,this._tabGroups=[],this._tabGroupMap=new Map,this._panelToTabGroup=new Map,this._tabGroupIdCounter=0,this._pendingTabGroupUpdate=!1,this._onDidCreateTabGroup=new Z,this.onDidCreateTabGroup=this._onDidCreateTabGroup.event,this._onDidDestroyTabGroup=new Z,this.onDidDestroyTabGroup=this._onDidDestroyTabGroup.event,this._onDidAddPanelToTabGroup=new Z,this.onDidAddPanelToTabGroup=this._onDidAddPanelToTabGroup.event,this._onDidRemovePanelFromTabGroup=new Z,this.onDidRemovePanelFromTabGroup=this._onDidRemovePanelFromTabGroup.event,this._onDidTabGroupChange=new Z,this.onDidTabGroupChange=this._onDidTabGroupChange.event,this._onDidTabGroupCollapsedChange=new Z,this.onDidTabGroupCollapsedChange=this._onDidTabGroupCollapsedChange.event,$(this.container,`dv-groupview`,!0),this.container.setAttribute(`role`,`region`),this._api=new zZ(this.accessor),this.tabsContainer=new x$(this.accessor,this.groupPanel),this.contentContainer=new OQ(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(oX(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=JY()?.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 HQ(e,{kind:`content`,panel:this.activePanel,api:this._api,group:this.groupPanel,getData:JY}))}),this.contentContainer.pointerDropTarget.onWillShowOverlay(e=>{this._onWillShowOverlay.fire(new HQ(e,{kind:`content`,panel:this.activePanel,api:this._api,group:this.groupPanel,getData:JY}))}),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 S$(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 X(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,$(this.container,`dv-active-group`,e),$(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 X(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,Q(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 YQ(e,n,t,JY,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=JY();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 w$({nativeEvent:t,position:n,panel:o,index:r,getData:()=>JY(),kind:a(),group:this.groupPanel,api:this._api});if(this._onWillDrop.fire(s),s.defaultPrevented)return;let c=JY();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 C$({nativeEvent:t,position:n,panel:o,index:r,getData:()=>JY(),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()}},E$=class extends bQ{constructor(e,t,n){super(e,t),this._onDidConstraintsChangeInternal=new Z,this.onDidConstraintsChangeInternal=this._onDidConstraintsChangeInternal.event,this._onDidConstraintsChange=new Z,this.onDidConstraintsChange=this._onDidConstraintsChange.event,this._onDidSizeChange=new Z,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)}},D$=class extends CQ{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 E$(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 Z,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 jZ(jZ({},e),{},{minimumHeight:n(this.minimumHeight),maximumHeight:t(this.maximumHeight),minimumWidth:n(this.minimumWidth),maximumWidth:t(this.maximumWidth),snap:this.snap,priority:this.priority})}},O$=`dockview: DockviewGroupPanelApiImpl not initialized`,k$=class extends E${get location(){if(!this._group)throw Error(O$);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(O$);return this._group.locked}set locked(e){if(!this._group)throw Error(O$);this._group.locked=e}constructor(e,t){super(e,`__dockviewgroup__`),this.accessor=t,this._isApplyingSize=!1,this._onDidLocationChange=new Z,this.onDidLocationChange=this._onDidLocationChange.event,this._onDidActivePanelChange=new Z,this.onDidActivePanelChange=this._onDidActivePanelChange.event,this._onDidCollapsedChange=new Z,this.onDidCollapsedChange=this._onDidCollapsedChange.event,this._onDidPeekChange=new Z,this.onDidPeekChange=this._onDidPeekChange.event,this._onDidHeaderDirectionChange=new Z,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=jZ({},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(O$);this._group.model.headerPosition=e}getHeaderPosition(){if(!this._group)throw Error(O$);return this._group.model.headerPosition}moveTo(e){if(!this._group)throw Error(O$);this.accessor.withOrigin(`api`,()=>{let t=e.group??this.accessor.addGroup({direction:QZ(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(O$);this.location.type===`grid`&&this.accessor.maximizeGroup(this._group)}isMaximized(){if(!this._group)throw Error(O$);return this.accessor.isMaximizedGroup(this._group)}exitMaximized(){if(!this._group)throw Error(O$);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}},A$=100,j$=100,M$=class extends D${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??j$,minimumWidth:n.constraints?.minimumWidth??A$,maximumHeight:n.constraints?.maximumHeight,maximumWidth:n.constraints?.maximumWidth},new k$(t,e)),this._explicitConstraints={},this.api.initialize(this),this._model=new T$(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()}},N$={name:`abyss`,className:`dockview-theme-abyss`,colorScheme:`dark`,tabGroupIndicator:`none`},P$=class extends E${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 Z,this.onDidTitleChange=this._onDidTitleChange.event,this._onDidChangePinned=new Z,this.onDidChangePinned=this._onDidChangePinned.event,this._onDidActiveGroupChange=new Z,this.onDidActiveGroupChange=this._onDidActiveGroupChange.event,this._onDidGroupChange=new Z,this.onDidGroupChange=this._onDidGroupChange.event,this._onDidRendererChange=new Z,this.onDidRendererChange=this._onDidRendererChange.event,this._onDidLocationChange=new Z,this.onDidLocationChange=this._onDidLocationChange.event,this.groupEventsDisposable=new ZY,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 X(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}))}))}},F$=class extends X{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 P$(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(jZ(jZ({},e),{},{api:this.api,containerApi:this.containerApi})),this.setTitle(e.title)}focus(){let e=new yQ;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=jZ(jZ({},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()}},I$=class extends X{get element(){return this._element}constructor(){super(),this._messages=PZ,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=AQ();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??PZ,this.addDisposables(e.api.onDidTitleChange(e=>{this._title=e.title,this.render()}),Q(this.action,`pointerdown`,e=>{e.preventDefault()}),Q(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())}},L$=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(jZ(jZ({},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(jZ(jZ({},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 I$;console.warn(`dockview: tabComponent '${t}' was not found. falling back to the default tab.`)}return new I$}},R$=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 L$(this.accessor,n,o,s),l=new F$(n,o,s,this.accessor,new zZ(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}},z$=class extends X{get element(){return this._element}constructor(){super(),this._element=document.createElement(`div`),this._element.className=`dv-watermark`}init(e){}},B$=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 V$(e){return e.width>0&&e.height>0}var H$=class e extends X{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 Z,this.onDidChange=this._onDidChange.event,this._onDidChangeEnd=new Z,this.onDidChangeEnd=this._onDidChangeEnd.event,this._onDidStartMoving=new Z,this.onDidStartMoving=this._onDidStartMoving.event,this._dragMove=new ZY,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&&($(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(jZ(jZ(jZ(jZ({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})),B$.push(this._element)}setVisible(e){e!==this.isVisible&&(this._isVisible=e,$(this.element,`dv-hidden`,!this.isVisible))}bringToFront(){B$.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(!V$(t)||!V$(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=XX(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=XX(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=XX(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=XX(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,V$(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,$(this._element,`dv-resize-container-dragging`,!1),this._dragMove.value=XY.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=TX();if(e&&typeof t==`number`&&typeof e.setPointerCapture==`function`)try{e.setPointerCapture(t)}catch{}let s=()=>{$(this._element,`dv-resize-container-dragging`,!1),this._dragMove.value=XY.NONE,this._onDidChangeEnd.fire()};this._dragMove.value=new X({dispose:()=>{if(o.release(),e&&typeof t==`number`&&typeof e.releasePointerCapture==`function`)try{e.releasePointerCapture(t)}catch{}}},Q(globalThis.window,`pointermove`,e=>{if(this._dragCancelled)return;let t=this.options.container.getBoundingClientRect(),n=e.clientX-t.left,o=e.clientY-t.top;$(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=XX(u,-l,f),h=XX(t.height-s.height-u,-l,f),g=XX(d,-c,p),_=XX(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())}),Q(globalThis.window,`pointerup`,s),Q(globalThis.window,`pointercancel`,s))};this.addDisposables(Q(e,`pointerdown`,t=>{t.defaultPrevented?t.preventDefault():mX(t)||n(e,t.pointerId)}),Q(this.options.content,`pointerdown`,e=>{e.defaultPrevented||mX(e)||e.shiftKey&&n(this.options.content,e.pointerId)}),Q(this.options.content,`pointerdown`,()=>{B$.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 ZY;this.addDisposables(r,Q(n,`pointerdown`,i=>{i.preventDefault();let a=null,o=TX(),s=i.pointerId;if(typeof n.setPointerCapture==`function`)try{n.setPointerCapture(s)}catch{}let c=()=>{r.dispose(),this._onDidChangeEnd.fire()};r.value=new X(Q(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=XX(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=XX(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=XX(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=XX(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{}}},Q(globalThis.window,`pointerup`,c),Q(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(){B$.destroy(this._element),this._element.remove(),super.dispose()}};H$.MINIMUM_HEIGHT=20,H$.MINIMUM_WIDTH=20;var U$=class extends X{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 Z,this.onDragStart=this._onDragStart.event,this._group=t,this._element=document.createElement(`div`),this._element.className=`dv-floating-titlebar`,this.addDisposables(this._onDragStart,Q(this._element,`pointerdown`,()=>{this.accessor.doSetGroupActive(this._group)}),Q(this._element,`pointerdown`,e=>{e.shiftKey&&pX(e)},!0)),this.dragSource=new UQ({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 W$(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 G$=new Set([`AdvancedOverflow`,`AutoEdgeGroup`,`AutoHideEdgeGroup`,`DndCompass`,`KeyboardDocking`,`KeyboardNavigation`,`LayoutHistory`,`License`,`MultiRowTabs`,`PinnedTabs`,`SmartGuides`]),K$=new Set;function q$(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 G$.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 J$(e,t){let n=`${e}|${(t===void 0?[]:[].concat(t)).join(`|`)}`;K$.has(n)||(K$.add(n),console.error(q$(e,t)))}function Y$(e,t,n){if(e!==void 0)return e;J$(t,n)}var X$=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()}},Z$=[];function Q$(){return[...Z$]}var $$=[{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=>JQ(e.autoHideEdgeGroups)},{optionKey:`dockToEdgeGroups`,reason:`dockToEdgeGroups`,moduleName:`AutoEdgeGroup`,when:e=>JQ(e.dockToEdgeGroups)},{optionKey:`dndCompass`,reason:`dndCompass`,moduleName:`DndCompass`,when:e=>!!e.dndCompass},{optionKey:`keyboardNavigation`,reason:`keyboardNavigation`,moduleName:`KeyboardNavigation`,when:e=>!!e.keyboardNavigation}];function e1(e,t){let n=new Map;for(let r of $$){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)J$(e,t)}var t1={left:100,top:100,width:300,height:300},n1=class extends X{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 Z,this.onDidChangeAnchorGroup=this._onDidChangeAnchorGroup.event,this._group=e,this.addDisposables(this._onDidChangeAnchorGroup,t,{dispose:()=>this.gridview.dispose()})}position(e){this.overlay.setBounds(e)}},r1=class{get floatingGroups(){return this._floatingGroups}constructor(e){this._floatingGroups=[],this._host=e}add(e,t,n){let r=new n1(e,t,n),i=new X((()=>{let e=-1,t=-1;return oX(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 ZY,s=e=>{a(e),o.value=new X(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(),YX(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()}},i1=W$({name:`FloatingGroup`,serviceKey:`floatingGroupService`,create:e=>new r1(e)}),a1=class{constructor(e){this._entries=[],this._restorationCleanups=new Set,this._restorationPromise=Promise.resolve(),this._onDidRemove=new Z,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){YX(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`?jZ(jZ({},i),{},{data:n.data[0].data}):jZ(jZ({},i),{},{grid:t})})}disposeAll(){for(let e of[...this._entries])e.disposable.dispose()}dispose(){this.cancelPendingRestorations(),this.disposeAll(),this._onDidRemove.dispose()}},o1=W$({name:`PopoutWindow`,serviceKey:`popoutWindowService`,create:e=>new a1(e)}),s1=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`,CX(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()}},c1=W$({name:`Watermark`,serviceKey:`watermarkService`,create:e=>new s1(e),init:(e,t)=>(t.update(),new X(QY.any(e.onDidAdd,e.onDidRemove)(()=>{t.update()}),e.onDidViewVisibilityChangeMicroTaskQueue(()=>{t.update()})))}),l1=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()}},u1=W$({name:`EdgeGroup`,serviceKey:`edgeGroupService`,create:()=>new l1}),d1={activationSize:{type:`pixels`,value:10},size:{type:`pixels`,value:20}},f1={activationSize:{type:`pixels`,value:32},size:{type:`pixels`,value:20}};function p1(e,t){return typeof e.dndEdges==`object`&&e.dndEdges!==null?e.dndEdges:t&&JQ(e.dockToEdgeGroups)?f1:d1}var m1=class{constructor(e){this._host=e;let t=(t,n)=>{let r=JY();return r?r.viewId===e.id?n!==`center`||e.isGridEmpty():!1:n===`center`&&!e.isGridEmpty()?!1:e.dispatchUnhandledDragOver(t,n)},n=p1(e.options,!1);this._html5Target=hQ.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=gQ.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=QY.any(this._html5Target.onWillShowOverlay,this._pointerTarget.onWillShowOverlay),this.onDrop=QY.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=p1({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()}},h1=W$({name:`RootDropTarget`,serviceKey:`rootDropTargetService`,create:e=>new m1(e),init:(e,t)=>(t.setOptions(e.options),XY.NONE)}),g1={left:`createLeftHeaderActionComponent`,right:`createRightHeaderActionComponent`,prefix:`createPrefixHeaderActionComponent`},_1=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 ZY,right:new ZY,prefix:new ZY},this._perGroup.set(e,t)),t}_refreshSlot(e,t,n){let r=this._host.options[g1[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)}},v1=W$({name:`HeaderActions`,serviceKey:`headerActionsService`,create:e=>new _1(e),init:(e,t)=>new X(e.onDidRemoveGroup(e=>{t.disposeGroup(e)}))}),y1=e=>e===`load`||e===`clear`;function b1(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 x1=class extends X{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:b1(t,`polite`),assertive:b1(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=>{y1(e.kind)&&this._suppressDepth++}),e.onDidMutateLayout(e=>{y1(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:b1(r,`polite`),assertive:b1(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=FZ(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)}}},S1=W$({name:`LiveRegion`,serviceKey:`liveRegionService`,create:e=>new x1(e)}),C1=30,w1=-10,T1=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:C1,offsetY:w1,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),XY.from(()=>n.clearOverlay())}dispose(){}},E1=W$({name:`AdvancedDnD`,serviceKey:`advancedDnDService`,create:e=>new T1(e)}),D1=class{constructor(e){this._host=e}attachToGroup(e){return new X(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(){}},O1=W$({name:`TabGroupChips`,serviceKey:`tabGroupChipsService`,create:e=>new D1(e),init:(e,t)=>{let n=new Map;return new X(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 k1(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=PX(e);return i?.style.zIndex?`calc(${i.style.zIndex} * 2)`:void 0}var A1=0,j1=()=>`dv-ctx-menu-item-${A1++}`;function M1(e){return typeof e==`object`}function N1(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 P1(){let e=document.createElement(`div`);return e.className=`dv-context-menu-separator`,e.setAttribute(`role`,`separator`),e}function F1(){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 I1(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),F1()||requestAnimationFrame(()=>{n.focus(),n.select()}),t}function L1(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 R1=class{constructor(e){this.accessor=e}buildMaximizeItem(e,t){let n=e.api.isMaximized();return N1(n?`Restore`:`Maximize`,t,n?()=>e.api.exitMaximized():()=>e.api.maximize(),!n&&e.api.location.type!==`grid`)}buildCollapseItem(e,t){return N1(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:j1(),component:t.component});s&&(a.addDisposables(s),s.init(jZ(jZ({},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 P1();case`close`:return N1(`Close`,r,()=>t.api.close());case`closeOthers`:return N1(`Close Others`,r,()=>{n.panels.filter(e=>e!==t).forEach(e=>e.api.close())});case`closeAll`:return N1(`Close All`,r,()=>{[...n.panels].forEach(e=>e.api.close())});case`closeLeft`:{let e=n.panels.indexOf(t);return N1(`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 N1(`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 N1(`Float`,r,()=>this.accessor.api.addFloatingGroup(t),t.api.location.type===`floating`);case`popout`:return N1(`Open in New Window`,r,()=>{this.accessor.api.addPopoutGroup(t)},t.api.location.type===`popout`);case`pin`:return N1(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(N1(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 X,s=document.createElement(`div`);s.className=`dv-context-menu`,s.setAttribute(`role`,`menu`);try{for(let n of r){if(M1(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:k1(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 X,s=document.createElement(`div`);s.className=`dv-context-menu`,s.setAttribute(`role`,`menu`);try{for(let n of r)n===`separator`?s.appendChild(P1()):n===`rename`?s.appendChild(I1(e)):n===`colorPicker`?s.appendChild(L1(e,this.accessor.tabGroupColorPalette)):n===`collapse`?s.appendChild(this.buildCollapseItem(e,a)):n===`close`?s.appendChild(N1(`Close All`,a,()=>{t.panels.filter(t=>e.containsPanel(t.id)).forEach(e=>e.api.close())})):M1(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:k1(n.target,t)},{onClose:()=>o.dispose()})}},z1=[i1,o1,c1,u1,h1,v1,S1,E1,O1,W$({name:`ContextMenu`,serviceKey:`contextMenuService`,create:e=>new R1(e)})],B1=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=yX(e);return this.cache.set(e,{rect:n,frameId:this.currentFrameId}),n}invalidate(){this.currentFrameId++}scheduleFrameUpdate(){this.rafId||=requestAnimationFrame(()=>{this.currentFrameId++,this.rafId=null})}},V1=-1;function H1(e){let t=e.group.api;return t.location.type===`edge`&&t.isCollapsed()}function U1(){let e=document.createElement(`div`);return e.tabIndex=-1,e}function W1(e,t,n){let r=`${n}px`;e[t]!==r&&(e[t]=r)}var G1=class extends X{constructor(e,t){super(),this.element=e,this.accessor=t,this.map={},this._disposed=!1,this._generation=0,this.positionCache=new B1,this.addDisposables(XY.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=U1();e.className=`dv-render-overlay`,e.style.visibility=`hidden`,this.map[n.api.id]={panel:n,disposable:XY.NONE,destroy:XY.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=H1(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||(W1(o.style,`width`,e.width),W1(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=V1;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=H1(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,W1(o.style,`left`,f),W1(o.style,`top`,p),W1(o.style,`width`,m),W1(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=``;$(o,`dv-render-overlay-float`,n.group.api.location.type===`floating`)});t.pendingUpdate===V1&&(t.pendingUpdate=i)},u=()=>{let e=!this.map[n.api.id]?.forceVisible&&H1(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 ZY,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=XY.from(()=>i.disconnect()),i.observe(t,{attributeFilter:[`aria-level`],attributes:!0}),r()}):o.style.zIndex=``},p=new X(d,new BZ(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()})??XY.NONE,r.onDidDimensionsChange(e=>{c(e)}),n.api.onDidLocationChange(()=>{f()}));return this.map[n.api.id].destroy=XY.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}},K1=class extends X{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 q1(e){if(!e.matchMedia)return!1;let t=e.matchMedia(`(pointer: coarse)`).matches,n=e.matchMedia(`(pointer: fine)`).matches;return t&&!n}function J1(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 X,u=t=>e.isInside?e.isInside(t):hX(t,e.elements?.call(e)??[]);if((r||i.length>0)&&l.addDisposables(Q(t,`keydown`,t=>{(r&&t.key===`Escape`||i.includes(t.key))&&e.onDismiss()},n)),(a||e.onInsidePointerDown)&&l.addDisposables(Q(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(Q(t,`resize`,()=>{q1(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(_X(n,r())):hX(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 gX(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,Q(e,`focusin`,a,n))};l.addDisposables(Q(t,`focusin`,e=>{s(),a(e)},n),{dispose:()=>{for(let[,e]of o)e.dispose();o.clear()}}),s()}return l}var Y1=class extends X{constructor(e,t=globalThis.window){super(),this._active=null,this._activeDisposable=new ZY,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(XY.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 X(J1({window:this._window,onDismiss:()=>this.close(),elements:()=>this._active?[this._active]:[],keys:[`Enter`],pointerDownGraceMs:200,resize:!0}),n?.onClose?XY.from(n.onClose):XY.NONE),this._window.requestAnimationFrame(()=>{NX(r,this._root)})}close(){this._active&&=(this._active.remove(),this._activeDisposable.dispose(),null)}},X1=class extends X{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(XY.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}},Z1=[`left`,`right`,`top`,`bottom`];function Q1(e){return e===`left`||e===`right`}var $1={marginShare:0,size:1/0},e0=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=$1){this._onDidChange=new Z,this.onDidChange=this._onDidChange.event,this.snap=!1,this.priority=`low`,this._isCollapsed=!1,this._isVisible=!0,this._tabSizeDisposables=new X,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(oX(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()}},t0=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 Z,this.onDidChange=this._onDidChange.event}layout(e,t){this._layoutDockview(t,e)}setVisible(e){}dispose(){this._onDidChange.dispose()}},n0=class{get element(){return this._element}constructor(e,t=0){this._onDidChange=new Z,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 rZ(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()}},r0=class{constructor(e,t,n,r=0,i=35){this._disposables=new X,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 t0(t,n);this._middleColumn=new n0(a,r),this._outerSplitview=new rZ(this._shellElement,{orientation:`HORIZONTAL`,proportionalLayout:!1,margin:r}),this._middleIndex=0,this._outerSplitview.addView(this._middleColumn,{type:`distribute`},0),this._disposables.addDisposables(oX(this._shellElement,e=>{if(!this._shellElement.offsetParent||!bX(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 e0(jZ(jZ({},t),{},{collapsedSize:t.collapsedSize??this._defaultCollapsedSize}),n,Q1(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||!bX(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 Q1(e)?this._leftView!==void 0&&this._rightView!==void 0:this._topView!==void 0&&this._bottomView!==void 0}_axisFor(e){return Q1(e)?this._outerSplitview:this._middleColumn.axis}_applyThemeSizing(){for(let e of Z1){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 Z1){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 Z1){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 i0(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 a0(e){return new n$(e.tabGroupColors??t$,e.tabGroupAccent!==`off`)}function o0(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 s0=()=>({dispose:()=>{}}),c0=s0,l0=100,u0=class extends TZ{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 LQ(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=Y$(this._smartGuidesService,`SmartGuides`,`api.setSmartGuidesEnabled`))==null||t.setEnabled(e)}updateSmartGuidesOptions(e){var t;(t=Y$(this._smartGuidesService,`SmartGuides`,`api.updateSmartGuidesOptions`))==null||t.updateOptions(e)}get onDidSnapFloat(){return this._smartGuidesService?.onDidSnapFloat??s0}get onDidSnapTogether(){return this._smartGuidesService?.onDidSnapTogether??s0}_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?jZ(jZ({},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 w$({nativeEvent:e,position:t,panel:void 0,api:this._api,group:void 0,getData:JY,kind:`edge`});if(this._onWillDrop.fire(n),n.defaultPrevented)return;let r=JY();r?this.moveGroupOrPanel({from:{groupId:r.groupId,panelId:r.panelId??void 0},to:{group:this.orthogonalize(t),position:`center`}}):this._onDidDrop.fire(new C$({nativeEvent:e,position:t,panel:void 0,api:this._api,group:void 0,getData:JY}))}get headerActionsService(){return this._moduleRegistry.services.headerActionsService}get _layoutHistoryService(){return this._moduleRegistry.services.layoutHistoryService}undo(){var e;(e=Y$(this._layoutHistoryService,`LayoutHistory`,`api.undo`))==null||e.undo()}redo(){var e;(e=Y$(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??c0}get hasEdgeDragReveal(){return!!this._moduleRegistry.services.autoEdgeGroupService}isGridEmpty(){return this.gridview.length===0}rootDropTargetOverrideTarget(){return this.rootDropTargetContainer?.model}dispatchUnhandledDragOver(e,t){let n=new YQ(e,`edge`,t,JY);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=pZ(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)??XY.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=ZX(),this._deserializer=new R$(this),this._moduleRegistry=new X$,this._onWillDragPanel=new Z,this.onWillDragPanel=this._onWillDragPanel.event,this._onWillDragGroup=new Z,this.onWillDragGroup=this._onWillDragGroup.event,this._onDidDrop=new Z,this.onDidDrop=this._onDidDrop.event,this._onWillDrop=new Z,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 Z,this.onWillMutateLayout=this._onWillMutateLayout.event,this._onDidMutateLayout=new Z,this.onDidMutateLayout=this._onDidMutateLayout.event,this._onWillShowOverlay=new Z,this.onWillShowOverlay=this._onWillShowOverlay.event,this._onUnhandledDragOver=new Z,this.onUnhandledDragOver=this._onUnhandledDragOver.event,this._onDidRemovePanel=new Z,this.onDidRemovePanel=this._onDidRemovePanel.event,this._onDidAddPanel=new Z,this.onDidAddPanel=this._onDidAddPanel.event,this._onDidPopoutGroupSizeChange=new Z,this.onDidPopoutGroupSizeChange=this._onDidPopoutGroupSizeChange.event,this._onDidPopoutGroupPositionChange=new Z,this.onDidPopoutGroupPositionChange=this._onDidPopoutGroupPositionChange.event,this._onDidAddPopoutGroup=new Z,this.onDidAddPopoutGroup=this._onDidAddPopoutGroup.event,this._onDidRemovePopoutGroup=new Z,this.onDidRemovePopoutGroup=this._onDidRemovePopoutGroup.event,this._onDidChangePopouts=new Z,this.onDidChangePopouts=this._onDidChangePopouts.event,this._onDidOpenPopoutWindowFail=new Z,this.onDidOpenPopoutWindowFail=this._onDidOpenPopoutWindowFail.event,this._onWillClosePopoutWindow=new Z,this.onWillClosePopoutWindow=this._onWillClosePopoutWindow.event,this._onDidStartFloatingGroupDrag=new Z,this.onDidStartFloatingGroupDrag=this._onDidStartFloatingGroupDrag.event,this._onDidEndFloatingGroupDrag=new Z,this.onDidEndFloatingGroupDrag=this._onDidEndFloatingGroupDrag.event,this._onDidLayoutFromJSON=new Z,this.onDidLayoutFromJSON=this._onDidLayoutFromJSON.event,this._onDidActivePanelChange=new Z({replay:!0}),this.onDidActivePanelChange=this._onDidActivePanelChange.event,this._onDidPanelPinnedChange=new Z,this.onDidPanelPinnedChange=this._onDidPanelPinnedChange.event,this._onDidMovePanel=new Z,this.onDidMovePanel=this._onDidMovePanel.event,this._onDidCreateTabGroup=new Z,this.onDidCreateTabGroup=this._onDidCreateTabGroup.event,this._onDidDestroyTabGroup=new Z,this.onDidDestroyTabGroup=this._onDidDestroyTabGroup.event,this._onDidAddPanelToTabGroup=new Z,this.onDidAddPanelToTabGroup=this._onDidAddPanelToTabGroup.event,this._onDidRemovePanelFromTabGroup=new Z,this.onDidRemovePanelFromTabGroup=this._onDidRemovePanelFromTabGroup.event,this._onDidTabGroupChange=new Z,this.onDidTabGroupChange=this._onDidTabGroupChange.event,this._onDidTabGroupCollapsedChange=new Z,this.onDidTabGroupCollapsedChange=this._onDidTabGroupCollapsedChange.event,this._onDidMaximizedGroupChange=new Z,this.onDidMaximizedGroupChange=this._onDidMaximizedGroupChange.event,this._inShellLayout=!1,this._onDidRemoveGroup=new Z,this.onDidRemoveGroup=this._onDidRemoveGroup.event,this._onDidEdgeGroupAutoHideChange=new Z,this.onDidEdgeGroupAutoHideChange=this._onDidEdgeGroupAutoHideChange.event,this._onDidAddGroup=new Z,this.onDidAddGroup=this._onDidAddGroup.event,this._onDidOptionsChange=new Z,this.onDidOptionsChange=this._onDidOptionsChange.event,this._onDidActiveGroupChange=new Z,this.onDidActiveGroupChange=this._onDidActiveGroupChange.event,this._peekingGroups=new Set,this._moving=!1,this._options=t,this._tabGroupColorPalette=a0(t);let n=t.modules??[...z1,...Q$()];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 Y1(this.element),this.addDisposables(this.popupService,XY.from(()=>{for(let e of this._openingPopoutWindows)e.dispose();this._openingPopoutWindows.clear()})),this._api=new zZ(this),this.disableResizing=!0,this.element.remove(),this._shellManager=new r0(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 OX(this._shellManager.element),this.rootDropTargetContainer=new X1(this._shellManager.element,{disabled:!0}),this.floatingDropTargetContainer=new X1(this._shellManager.element,{disabled:!1}),this.overlayRenderContainer=new G1(this._shellManager.element,this),this._floatingOverlayHost=document.createElement(`div`),this._floatingOverlayHost.className=`dv-floating-overlay-host`,this._shellManager.element.appendChild(this._floatingOverlayHost),$(this.gridview.element,`dv-dockview`,!0),$(this.element,`dv-debug`,!!t.debug),this.updateTheme(),t.debug&&this.addDisposables(new K1(this)),this.addDisposables(XY.from(()=>this._pendingLocationChanges.clear()),this.rootDropTargetContainer,this.floatingDropTargetContainer,Q(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,QY.any(this.onDidPopoutGroupSizeChange,this.onDidPopoutGroupPositionChange)(()=>{this.fireLayoutChange(`geometry`)}),QY.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})}),QY.any(this.onDidAddPanel,this.onDidRemovePanel,this.onDidAddGroup,this.onDidRemove,this.onDidRemoveGroup,this.onDidMovePanel)(()=>{this._bufferOnDidLayoutChange.fire(`structure`)}),this.onDidActivePanelChange(()=>{this._bufferOnDidLayoutChange.fire(`activePanel`)}),XY.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 HQ(e,{kind:`edge`,panel:void 0,api:this._api,group:void 0,getData:JY}))}),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=Y$(this._popoutWindowService,`PopoutWindow`,`api.addPopoutGroup`);if(!r||e instanceof M$&&e.model.location.type===`edge`)return Promise.resolve(!1);if(e instanceof F$&&e.group.size===1&&this.closeEmptyGroups)return this.addPopoutGroup(e.group,t);let i=DX(this.gridview.element),a=this.element;function o(){if(t?.position)return t.position;let n=(e instanceof M$?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 UX(`${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 X(d,d.onDidClose(()=>{f.dispose()}));this._openingPopoutWindows.add(f);let p=HX(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&&(i0(e),this._onDidOpenPopoutWindowFail.fire(e)),!1}let i=t?.referenceGroup??(e instanceof F$?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 G1(u,this);s.model.renderContainer=m;let h=t?.overridePopoutGridview??this.createNestedGridview();t?.overridePopoutGridview?h.locked=this.gridview.locked:h.addView(s,nZ.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 F$){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(()=>o0({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 X1(b,{disabled:this.rootDropTargetContainer.disabled});n.appendChild(b),s.model.dropTargetContainer=x;let S=new Y1(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 ZY;f.addDisposables(w);let T=e=>{w.value=new X(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=jX(d.window);f.addDisposables(k,MX(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})}),Q(d.window,`resize`,()=>{h.layout(d.window.innerWidth,d.window.innerHeight)}),m,XY.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(i0(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(()=>o0({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(()=>o0({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(!Y$(this._floatingGroupService,`FloatingGroup`,`api.addFloatingGroup`)||e instanceof M$&&e.model.location.type===`edge`)return;let n,r=[];if(e instanceof F$){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(()=>o0({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=t1.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=t1.top,e.width=typeof t.width==`number`?Math.max(t.width,0):t1.width,e.height=typeof t.height==`number`?Math.max(t.height,0):t1.height,e}return{left:typeof t?.x==`number`?Math.max(t.x,0):t1.left,top:typeof t?.y==`number`?Math.max(t.y,0):t1.top,width:typeof t?.width==`number`?Math.max(t.width,0):t1.width,height:typeof t?.height==`number`?Math.max(t.height,0):t1.height}}let a=i(),o=this.createNestedGridview();o.addView(n,nZ.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 bZ(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=Y$(this._floatingGroupService,`FloatingGroup`,`api.addFloatingGroup`);if(!a)return;let o=(i?.dragHandle??this.options.floatingGroupDragHandle??`titlebar`)===`titlebar`?new U$(this,t):void 0,s=new H$(jZ(jZ({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,XY.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=jZ(jZ({},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??t$),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){e1(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(q$(`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=Q1(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 X(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=Y$(this._moduleRegistry.services.autoHideEdgeGroupService,`AutoHideEdgeGroup`,`api.pinEdgeGroup`))==null||t.pin(e)}autoHideEdgeGroup(e){var t;(t=Y$(this._moduleRegistry.services.autoHideEdgeGroupService,`AutoHideEdgeGroup`,`api.autoHideEdgeGroup`))==null||t.autoHide(e)}peekEdgeGroup(e,t){var n;(n=Y$(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=Y$(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&&qQ(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=pZ(e.element),i=(t?n.previous(r):n.next(r)).view;if(n===this.gridview||i!==e)return i}let r=[],i=e=>{vZ(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(XY.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=Y$(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?Y$(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(jZ(jZ({},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(ZQ(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(QQ(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(ZZ(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=wZ(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,jZ(jZ({},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=pZ(t.element),l=mZ(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,jZ(jZ({},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 z$}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)||e$(t)||typeof t.direction==`string`))return this._doAddGroup(jZ(jZ({},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(e$(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(e$(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(ZZ(e.direction),e);return e.skipSetActive||this.doSetGroupAndPanelActive(t),t}let n=wZ(e.direction||`within`),r=this.getGridviewForGroup(t),i=pZ(t.element),a=mZ(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 RX(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=pZ(t.element),s=mZ(n.orientation,a,i);if(o.size<2&&!this.keepEmptyGroups(e)){if(o===t)return;let[e,c]=WX(s);if(o.api.location.type===`grid`&&n===this.gridview){let[n,i]=WX(pZ(o.element));if((this.options.dropSizing!==`distribute`||o===t)&&GX(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=mZ(n.orientation,pZ(t.element),i),c=this.createGroupAtLocation(s,this.sizingForDrop(pZ(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=pZ(t.element),d=mZ(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=mZ(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`?pZ(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=mZ(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=pZ(t.element),a=pZ(n.element)}catch{return!1}return i.length===0||a.length===0?!1:GX(WX(i)[0],WX(a)[0])&&gZ(e.orientation,a)===hZ(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(pZ(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=pZ(n.element),s=mZ(a.orientation,o,r),c;c=e&&this.options.dropSizing!==`distribute`?hZ(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<l0;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 ${l0} 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 M$(this,t,e);if(n.init({params:{},accessor:this}),!this._groups.has(n.id)){let e=new X(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 L$(this,e.id,n,r),a=new F$(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`?nZ.Distribute:nZ.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:_Z(n)}updateTheme(){var e,t;let n=this._options.theme??N$;(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`;$(this.element,`dv-tab-group-indicator-none`,o),this._shellManager&&$(this._shellManager.element,`dv-tab-group-indicator-none`,o);for(let e of this.groups)e.model.updateTabGroups()}},d0=class extends TZ{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 Z,this.onDidLayoutFromJSON=this._onDidLayoutfromJSON.event,this._onDidRemoveGroup=new Z,this.onDidRemoveGroup=this._onDidRemoveGroup.event,this._onDidAddGroup=new Z,this.onDidAddGroup=this._onDidAddGroup.event,this._onDidActiveGroupChange=new Z,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=jZ(jZ({},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(pZ(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=wZ(t.direction);if(r===`center`)throw Error(`${r} not supported as an option`);let i=pZ(n.element),a=mZ(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=wZ(e.position.direction);if(r===`center`)throw Error(`${r} not supported as an option`);{let e=pZ(n.element);t=mZ(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 X(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=pZ(e.element),[a,o]=WX(mZ(this.gridview.orientation,i,n)),[s,c]=WX(pZ(r.element));if(GX(s,a)){this.gridview.moveView(s,c,o);return}let l=this.doRemoveGroup(r,{skipActive:!0,skipDispose:!0}),u=pZ(e.element),d=mZ(this.gridview.orientation,u,n);this.doAddGroup(l,d)}removeGroup(e){super.removeGroup(e)}dispose(){super.dispose(),this._onDidLayoutfromJSON.dispose()}},f0=class extends SZ{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 X(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 ZY,this._panels=new Map,this._onDidLayoutfromJSON=new Z,this.onDidLayoutFromJSON=this._onDidLayoutfromJSON.event,this._onDidAddView=new Z,this.onDidAddView=this._onDidAddView.event,this._onDidRemoveView=new Z,this.onDidRemoveView=this._onDidRemoveView.event,this._onDidLayoutChange=new Z,this.onDidLayoutChange=this._onDidLayoutChange.event,this.element.style.height=`100%`,this.element.style.width=`100%`,this._classNames=new OX(this.element),this._classNames.setClassNames(t.className??``),e.appendChild(this.element),this._options=t,this.splitview=new rZ(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=jZ(jZ({},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:nZ.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 jZ({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 rZ(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,nZ.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()}},p0=class extends X{get element(){return this._element}constructor(){super(),this._expandedIcon=MQ(),this._collapsedIcon=NQ(),this.disposable=new ZY,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(Q(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;$(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()}},m0=ZX(),h0=22,g0=0,_0=2**53-1,v0=class extends TQ{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}},y0=class extends SZ{get id(){return this._id}get panels(){return this.paneview.getPanes()}set paneview(e){this._paneview=e,this._disposable.value=new X(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=m0.next(),this._disposable=new ZY,this._viewDisposables=new Map,this._onDidLayoutfromJSON=new Z,this.onDidLayoutFromJSON=this._onDidLayoutfromJSON.event,this._onDidLayoutChange=new Z,this.onDidLayoutChange=this._onDidLayoutChange.event,this._onDidDrop=new Z,this.onDidDrop=this._onDidDrop.event,this._onDidAddView=new Z,this.onDidAddView=this._onDidAddView.event,this._onDidRemoveView=new Z,this.onDidRemoveView=this._onDidRemoveView.event,this._onUnhandledDragOver=new Z,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 OX(this.element),this._classNames.setClassNames(t.className??``),e.appendChild(this.element),this._options=t,this.paneview=new aZ(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=jZ(jZ({},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 p0;let r=new v0({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??h0,minimumBodySize:g0,maximumBodySize:_0});this.doAddPanel(r);let i=typeof e.size==`number`?e.size:nZ.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 LZ(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 jZ({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 aZ(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 p0;let a=new v0({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??h0,minimumBodySize:e.minimumSize??g0,maximumBodySize:e.maximumSize??_0});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 LZ(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 aZ(this.element,{orientation:`VERTICAL`}),this.layout(e,t)}doAddPanel(e){let t=new X(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()}},b0=class extends CQ{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 xQ(e,t)),this._evaluatedMinimumSize=0,this._evaluatedMaximumSize=1/0,this._minimumSize=0,this._maximumSize=1/0,this._snap=!1,this._onDidChange=new Z,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 jZ(jZ({},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 x0(e,t){return new u0(e,t).api}function S0(e,t){return new IZ(new f0(e,t))}function C0(e,t){return new RZ(new d0(e,t))}function w0(e,t){return new LZ(new y0(e,t))}function T0(e){"@babel/helpers - typeof";return T0=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},T0(e)}function E0(e,t){if(T0(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(T0(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function D0(e){var t=E0(e,`string`);return T0(t)==`symbol`?t:t+``}function O0(e,t,n){return(t=D0(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function k0(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 A0(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?k0(Object(n),!0).forEach(function(t){O0(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):k0(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var j0=(e,t)=>{let[,n]=U.useState(0),r=U.useRef(e.componentProps);return U.useImperativeHandle(t,()=>({update:e=>{r.current=A0(A0({},r.current),e),n(e=>e+1)}}),[]),U.createElement(e.component,r.current)};j0.displayName=`DockviewReactJsBridge`;var M0=(()=>{let e=1;return{next:()=>`dockview_react_portal_key_${(e++).toString()}`}})(),N0=U.createContext({}),P0=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=A0(A0({},this._initialProps),e)}createPortal(){if(this.disposed)throw Error(`invalid operation: resource is already disposed`);if(!I0(this.component))throw Error(`Dockview: Only React.memo(...), React.ForwardRef(...) and functional components are accepted as components`);let e=U.createElement(U.forwardRef(j0),{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?U.createElement(N0.Provider,{value:this.context},e):e,n=lp.createPortal(t,this.parent,M0.next());this.ref={portal:n,disposable:this.portalStore.addPortal(n)}}dispose(){var e;(e=this.ref)==null||e.disposable.dispose(),this.disposed=!0}},F0=()=>{let[e,t]=U.useState([]);return U.useDebugValue(`Portal count: ${e.length}`),[e,U.useCallback(e=>{t(t=>[...t,e]);let n=!1;return XY.from(()=>{if(n)throw Error(`invalid operation: resource already disposed`);n=!0,t(t=>t.filter(t=>t!==e))})},[])]};function I0(e){return typeof e==`function`||!!e?.$$typeof}function L0(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(),XY.from(()=>i.disconnect())}var R0=Number.parseInt(`19.3.1`,10)>=18;function z0(e,t,n){let r=U.useRef(void 0);U.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()};R0&&a.isConnected&&typeof MutationObserver<`u`?r.current=L0(a,e):e()}},[])}function B0(e){let t=U.useRef({instance:void 0,values:new Map});return U.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 V0=class{get element(){return this._element}constructor(e,t,n){this.id=e,this.component=t,this.reactPortalStore=n,this._onDidFocus=new Z,this.onDidFocus=this._onDidFocus.event,this._onDidBlur=new Z,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 P0(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()}},H0=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 P0(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()}},U0=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 P0(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()}},W0=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 ZY,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 X(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 P0(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}})}},G0=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 P0(this._element,this.reactPortalStore,this.component,e)}dispose(){var e;(e=this.part)==null||e.dispose()}},K0=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 P0(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()}},q0=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 P0(this._element,this.reactPortalStore,this.component,{group:e.group,api:e.api})}dispose(){var e;(e=this.part)==null||e.dispose()}};function J0(e,t){return e?n=>new W0(e,t,n):void 0}var Y0=`props.defaultTabComponent`;function X0(e){return XQ.reduce((t,n)=>(n in e&&(t[n]=e[n]),t),{})}var Z0=U.forwardRef((e,t)=>{let n=U.useRef(null),r=U.useRef(void 0),[i,a]=F0(),o=B0(r);U.useImperativeHandle(t,()=>n.current,[]);let s=U.useRef({});return U.useEffect(()=>{let t={};XQ.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},XQ.map(t=>e[t])),z0(n,r,t=>{let n=A0({},e.tabComponents);e.defaultTabComponent&&(n[Y0]=e.defaultTabComponent);let r={createLeftHeaderActionComponent:J0(e.leftHeaderActionsComponent,{addPortal:a}),createRightHeaderActionComponent:J0(e.rightHeaderActionsComponent,{addPortal:a}),createPrefixHeaderActionComponent:J0(e.prefixHeaderActionsComponent,{addPortal:a}),createComponent:t=>new V0(t.id,e.components[t.name],{addPortal:a}),createTabComponent(e){return new H0(e.id,n[e.name],{addPortal:a})},createWatermarkComponent:e.watermarkComponent?()=>new U0(`watermark`,e.watermarkComponent,{addPortal:a}):void 0,defaultTabComponent:e.defaultTabComponent?Y0:void 0,createContextMenuItemComponent:e=>{if(e.component)return new G0(e.id,e.component,{addPortal:a})}},i=X0(e);if(e.tabGroupChipComponent){let t=e.tabGroupChipComponent;i.createTabGroupChipComponent=()=>new K0(t,{addPortal:a})}if(e.groupDragGhostComponent){let t=e.groupDragGhostComponent;i.createGroupDragGhostComponent=()=>new q0(t,{addPortal:a})}let o=x0(t,A0(A0({},i),r)),{clientWidth:s,clientHeight:c}=t;return o.layout(s,c),e.onReady&&e.onReady({api:o}),o}),U.useEffect(()=>{if(!r.current)return()=>{};let t=r.current.onDidDrop(t=>{e.onDidDrop&&e.onDidDrop(t)});return()=>{t.dispose()}},[e.onDidDrop]),U.useEffect(()=>{if(!r.current)return()=>{};let t=r.current.onWillDrop(t=>{e.onWillDrop&&e.onWillDrop(t)});return()=>{t.dispose()}},[e.onWillDrop]),U.useEffect(()=>{r.current&&!o({tabGroupChipComponent:e.tabGroupChipComponent})&&r.current.updateOptions({createTabGroupChipComponent:e.tabGroupChipComponent?()=>new K0(e.tabGroupChipComponent,{addPortal:a}):void 0})},[e.tabGroupChipComponent]),U.useEffect(()=>{r.current&&!o({groupDragGhostComponent:e.groupDragGhostComponent})&&r.current.updateOptions({createGroupDragGhostComponent:e.groupDragGhostComponent?()=>new q0(e.groupDragGhostComponent,{addPortal:a}):void 0})},[e.groupDragGhostComponent]),U.useEffect(()=>{r.current&&!o({components:e.components})&&r.current.updateOptions({createComponent:t=>new V0(t.id,e.components[t.name],{addPortal:a})})},[e.components]),U.useEffect(()=>{if(!r.current||o({tabComponents:e.tabComponents,defaultTabComponent:e.defaultTabComponent}))return;let t=A0({},e.tabComponents);e.defaultTabComponent&&(t[Y0]=e.defaultTabComponent),r.current.updateOptions({defaultTabComponent:e.defaultTabComponent?Y0:void 0,createTabComponent(e){return new H0(e.id,t[e.name],{addPortal:a})}})},[e.tabComponents,e.defaultTabComponent]),U.useEffect(()=>{r.current&&!o({watermarkComponent:e.watermarkComponent})&&r.current.updateOptions({createWatermarkComponent:e.watermarkComponent?()=>new U0(`watermark`,e.watermarkComponent,{addPortal:a}):void 0})},[e.watermarkComponent]),U.useEffect(()=>{r.current&&!o({rightHeaderActionsComponent:e.rightHeaderActionsComponent})&&r.current.updateOptions({createRightHeaderActionComponent:J0(e.rightHeaderActionsComponent,{addPortal:a})})},[e.rightHeaderActionsComponent]),U.useEffect(()=>{r.current&&!o({leftHeaderActionsComponent:e.leftHeaderActionsComponent})&&r.current.updateOptions({createLeftHeaderActionComponent:J0(e.leftHeaderActionsComponent,{addPortal:a})})},[e.leftHeaderActionsComponent]),U.useEffect(()=>{r.current&&!o({prefixHeaderActionsComponent:e.prefixHeaderActionsComponent})&&r.current.updateOptions({createPrefixHeaderActionComponent:J0(e.prefixHeaderActionsComponent,{addPortal:a})})},[e.prefixHeaderActionsComponent]),U.createElement(`div`,{style:{height:`100%`,width:`100%`},ref:n},i)});Z0.displayName=`DockviewComponent`;var Q0=class extends b0{constructor(e,t,n,r){super(e,t),this.reactComponent=n,this.reactPortalStore=r}getComponent(){return new P0(this.element,this.reactPortalStore,this.reactComponent,{params:this._params?.params??{},api:this.api,containerApi:new IZ(this._params.accessor)})}};function $0(e){return iZ.reduce((t,n)=>(n in e&&(t[n]=e[n]),t),{})}var e2=U.forwardRef((e,t)=>{let n=U.useRef(null),r=U.useRef(void 0),[i,a]=F0(),o=B0(r);U.useImperativeHandle(t,()=>n.current,[]);let s=U.useRef({});return U.useEffect(()=>{let t={};iZ.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},iZ.map(t=>e[t])),z0(n,r,t=>{let n=S0(t,A0(A0({},$0(e)),{createComponent:t=>new Q0(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}),U.useEffect(()=>{r.current&&!o({components:e.components})&&r.current.updateOptions({createComponent:t=>new Q0(t.id,t.name,e.components[t.name],{addPortal:a})})},[e.components]),U.createElement(`div`,{style:{height:`100%`,width:`100%`},ref:n},i)});e2.displayName=`SplitviewComponent`;var t2=class extends D${constructor(e,t,n,r){super(e,t),this.reactComponent=n,this.reactPortalStore=r}getComponent(){return new P0(this.element,this.reactPortalStore,this.reactComponent,{params:this._params?.params??{},api:this.api,containerApi:new RZ(this._params.accessor)})}};function n2(e){return xZ.reduce((t,n)=>(n in e&&(t[n]=e[n]),t),{})}var r2=U.forwardRef((e,t)=>{let n=U.useRef(null),r=U.useRef(void 0),[i,a]=F0(),o=B0(r);U.useImperativeHandle(t,()=>n.current,[]);let s=U.useRef({});return U.useEffect(()=>{let t={};xZ.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},xZ.map(t=>e[t])),z0(n,r,t=>{let n=C0(t,A0(A0({},n2(e)),{createComponent:t=>new t2(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}),U.useEffect(()=>{r.current&&!o({components:e.components})&&r.current.updateOptions({createComponent:t=>new t2(t.id,t.name,e.components[t.name],{addPortal:a})})},[e.components]),U.createElement(`div`,{style:{height:`100%`,width:`100%`},ref:n},i)});r2.displayName=`GridviewComponent`;var i2=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 P0(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 a2(e){return _Q.reduce((t,n)=>(n in e&&(t[n]=e[n]),t),{})}var o2=U.forwardRef((e,t)=>{let n=U.useRef(null),r=U.useRef(void 0),[i,a]=F0(),o=B0(r);U.useImperativeHandle(t,()=>n.current,[]);let s=U.useRef({});return U.useEffect(()=>{let t={};_Q.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},_Q.map(t=>e[t])),z0(n,r,t=>{let n=e.headerComponents??{},r=w0(t,A0(A0({},a2(e)),{createComponent:t=>new i2(t.id,e.components[t.name],{addPortal:a}),createHeaderComponent:e=>new i2(e.id,n[e.name],{addPortal:a})})),{clientWidth:i,clientHeight:o}=t;return r.layout(i,o),e.onReady&&e.onReady({api:r}),r}),U.useEffect(()=>{r.current&&!o({components:e.components})&&r.current.updateOptions({createComponent:t=>new i2(t.id,e.components[t.name],{addPortal:a})})},[e.components]),U.useEffect(()=>{if(!r.current||o({headerComponents:e.headerComponents}))return;let t=e.headerComponents??{};r.current.updateOptions({createHeaderComponent:e=>new i2(e.id,t[e.name],{addPortal:a})})},[e.headerComponents]),U.useEffect(()=>{if(!r.current)return()=>{};let t=r.current.onDidDrop(t=>{e.onDidDrop&&e.onDidDrop(t)});return()=>{t.dispose()}},[e.onDidDrop]),U.createElement(`div`,{style:{height:`100%`,width:`100%`},ref:n},i)});o2.displayName=`PaneviewComponent`;var s2={dock:`_dock_psx21_10`,tab:`_tab_psx21_155`,buttons:`_buttons_psx21_178`,body:`_body_psx21_189`,heading:`_heading_psx21_197`,none:`_none_psx21_209`},c2=({label:e,shortcut:t,onClick:n,children:r})=>{let i=Zk();return(0,q.jsx)(xb,{"aria-keyshortcuts":Gk(t,i),keys:Wk(t,i),label:e,onClick:n,children:r})},l2=({group:e,activePanel:t,workspace:n})=>{vb(n.view);let r=t?.title??`panel`,i=t!==void 0&&LY(t.id)?t.id:void 0,a=e.api.location.type===`floating`,o=e.api.isMaximized();return(0,q.jsxs)(`div`,{className:s2.buttons,children:[(0,q.jsx)(c2,{label:`Minimize ${r}`,onClick:()=>{n.minimize(i)},shortcut:Jk.minimize,children:(0,q.jsx)(vy,{})}),a?null:(0,q.jsx)(c2,{label:o?`Restore ${r}`:`Maximize ${r}`,onClick:()=>{n.toggleMaximize(e)},shortcut:Jk.maximize,children:o?(0,q.jsx)(by,{}):(0,q.jsx)(yy,{})}),(0,q.jsx)(c2,{label:a?`Dock ${r}`:`Float ${r}`,onClick:()=>{n.toggleFloat(e)},shortcut:Jk.float,children:a?(0,q.jsx)(Sy,{}):(0,q.jsx)(xy,{})}),(0,q.jsx)(c2,{label:`Close ${r}`,onClick:()=>{n.close(i)},shortcut:Jk.close,children:(0,q.jsx)(sy,{})})]})},u2=e=>{let t=(0,U.use)(wL);return t===null?null:(0,q.jsx)(l2,{...e,workspace:t})},d2=6,f2=({api:e})=>{let t=LY(e.id)?RY(e.id).Icon:null;return(0,q.jsxs)(`span`,{className:s2.tab,children:[t===null?null:(0,q.jsx)(t,{}),e.title]})},p2=()=>(0,q.jsx)(`div`,{className:s2.none,children:(0,q.jsx)(JD,{title:`No panels open.`,children:`Reopen one from Window, or press the command palette's keys.`})}),m2=Object.fromEntries(IY.map(({id:e,title:t,Body:n})=>[e,()=>(0,q.jsxs)(`div`,{className:s2.body,children:[(0,q.jsx)(`h2`,{className:s2.heading,children:t}),(0,q.jsx)(n,{})]})])),h2={name:`ork`,className:s2.dock??``,gap:d2,dndOverlayMounting:`relative`,dndPanelOverlay:`group`,dndTabIndicator:`line`},g2=({workspace:e})=>{let t=(0,U.useCallback)(({api:t})=>{e.attach(t)},[e]);return(0,U.useEffect)(()=>()=>{e.detach()},[e]),(0,q.jsx)(Z0,{announcer:({message:t})=>{e.announceFromDock(t)},components:m2,defaultTabComponent:f2,disableTabsOverflowList:!0,onReady:t,rightHeaderActionsComponent:u2,theme:h2,watermarkComponent:p2})},_2=`(min-width: 64rem)`,v2=(e,t,n)=>{let r=e?.panels??[],i=e?.activePanel?.id;return{wide:n,open:IY.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&&LY(i)?i:null,floating:e?.activePanel?.group.api.location.type===`floating`,maximized:e?.hasMaximizedGroup()??!1}},y2=(e,t)=>JSON.stringify(e)===JSON.stringify(t),b2=e=>`stack-${e}`,x2=e=>`rail-${e}`,S2=e=>{document.querySelector(`#${e}`)?.focus()},C2=({workspace:e})=>{let{minimized:t}=vb(e.view);return t.length===0?null:(0,q.jsx)(`nav`,{"aria-label":`Minimized panels`,className:eA.rail,children:t.map(t=>{let{title:n,Icon:r}=RY(t);return(0,q.jsx)(xb,{id:x2(t),label:`Restore ${n}`,onClick:()=>{e.restore(t)},children:(0,q.jsx)(r,{})},t)})})},w2=({workspace:e})=>{let{folded:t}=vb(e.view);return(0,q.jsx)(`div`,{className:eA.stack,children:IY.map(({id:n,title:r,Icon:i,Body:a})=>{let o=!t.includes(n),s=`${b2(n)}-body`;return(0,q.jsxs)(`section`,{"aria-labelledby":b2(n),className:eA.stacked,children:[(0,q.jsx)(`h2`,{className:eA.stackedHeading,children:(0,q.jsxs)(`button`,{"aria-controls":o?s:void 0,"aria-expanded":o,className:eA.stackedButton,id:b2(n),onClick:()=>{e.toggleFold(n)},type:`button`,children:[o?(0,q.jsx)(ly,{}):(0,q.jsx)(uy,{}),(0,q.jsx)(i,{}),r]})}),o?(0,q.jsx)(`div`,{className:eA.stackedBody,id:s,children:(0,q.jsx)(a,{})}):null]},n)})})},T2=e=>{(0,U.useEffect)(()=>{let t=window.matchMedia(_2),n=()=>{e.setWide(t.matches)};return n(),t.addEventListener(`change`,n),()=>{t.removeEventListener(`change`,n)}},[e])},E2=({workspace:e})=>{let{wide:t}=vb(e.view);return T2(e),(0,q.jsx)(`main`,{className:eA.middle,children:t?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(C2,{workspace:e}),(0,q.jsx)(`div`,{className:eA.dockArea,children:(0,q.jsx)(g2,{workspace:e})})]}):(0,q.jsx)(w2,{workspace:e})})},D2=`ork-new-version-action`,O2=(e,t,n)=>e?.version===t&&n-Date.parse(e.at)<864e5,k2=(e,t,n)=>{let{job:r}=e;if(r!==null)return r.state===`running`?{kind:`running`,latest:r.latest}:O2(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}},A2=({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=k2(e,r,i);if(o!==void 0)return o;let{newer:s,releaseNotes:c}=e;return s===null||c===null||O2(r,s,i)?null:{kind:`newer`,newer:s,current:e.current,releaseNotes:c}},j2=e=>e===null?`none`:`${e.kind}:${`newer`in e?e.newer:`latest`in e?e.latest:e.server}`,M2=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,N2=e=>e.kind===`newer`?e.newer:e.kind===`installed`||e.kind===`failed`?e.latest:null,P2={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`},F2=({latest:e,current:t})=>(0,q.jsxs)(`p`,{className:P2.line,children:[`Ork`,` `,(0,q.jsx)(`span`,{className:P2.version,"data-new":``,children:e}),` `,`is out (you have `,(0,q.jsx)(`span`,{className:P2.version,children:t}),`).`]}),I2=({url:e,version:t,children:n})=>(0,q.jsxs)(`a`,{className:P2.link,href:e,rel:`noreferrer`,target:`_blank`,children:[n,t===void 0?null:(0,q.jsx)(uk,{children:` in ${t}`}),(0,q.jsx)(Fy,{}),(0,q.jsx)(uk,{children:` (opens in a new tab)`})]}),L2=8,R2=({ids:e})=>{if(e.length===0)return null;let t=e.slice(0,L2).map(e=>`\`${e.slice(0,8)}\``),n=e.length-L2,r=n>0?`${t.join(`, `)} and ${String(n)} more`:t.join(`, `);return(0,q.jsxs)(`p`,{className:P2.alert,"data-tone":`note`,children:[(0,q.jsx)(`span`,{className:P2.alertIcon,children:(0,q.jsx)(My,{})}),(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:`Running now: ${r}. Their next sessions would start from the new install; upgrading after they finish is safer.`})})]})},z2=()=>{let e=document.activeElement;return e===null||e===document.body||e.getAttribute(`role`)===`dialog`},B2=({tone:e,text:t,ref:n})=>{let r=(0,U.useRef)(null),i=n??r;return(0,U.useLayoutEffect)(()=>{i.current?.focus()},[i]),(0,U.useEffect)(()=>{let e=requestAnimationFrame(()=>{e=requestAnimationFrame(()=>{z2()&&i.current?.focus()})});return()=>{cancelAnimationFrame(e)}},[i]),(0,q.jsxs)(`h3`,{className:P2.heading,ref:i,tabIndex:-1,children:[e===void 0?null:(0,q.jsx)(`span`,{className:P2.glyph,"data-tone":e,children:e===`succeeded`?(0,q.jsx)(Nj,{}):(0,q.jsx)(Ij,{})}),(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:t})})]})},V2=({since:e})=>{let t=VW(!0),n=Math.max(0,Math.floor((t-e)/1e3));return(0,q.jsx)(`span`,{"aria-hidden":`true`,className:P2.clock,children:`${String(n)} s`})},H2=({text:e,icon:t=!1})=>e===null?null:(0,q.jsxs)(`p`,{className:P2.alert,role:`alert`,children:[t?(0,q.jsx)(My,{}):null,(0,q.jsx)(`span`,{children:(0,q.jsx)(r_,{text:e})})]}),U2=({why:e,id:t})=>(0,q.jsx)(`output`,{className:P2.note,id:t,children:(0,q.jsx)(r_,{text:e??``})}),W2=({note:e,children:t})=>(0,q.jsxs)(`div`,{className:P2.foot,children:[e===void 0?null:(0,q.jsx)(`p`,{className:P2.note,children:(0,q.jsx)(r_,{text:e})}),(0,q.jsx)(`div`,{className:P2.actions,children:t})]}),G2=`Dismissed for a day. Upgrade Ork… is in Commands.`,K2=(e,t,n,r)=>{let i=(0,U.useRef)(null),a=j2(e);(0,U.useEffect)(()=>{if(!t)return;let o=i.current;if(i.current=a,o===null||o===a||n)return;let s=M2(e);s!==null&&r.announce(s)},[e,a,t,n,r])},q2=()=>{let[e,t]=(0,U.useState)(Date.now);return(0,U.useEffect)(()=>{let e=setInterval(()=>{t(Date.now())},6e4);return()=>{clearInterval(e)}},[]),e},J2=()=>{window.location.reload()},Y2={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}},X2=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}.`,Z2=({banner:e,onOpen:t})=>{let n=Y2[e.kind];return(0,q.jsxs)(q.Fragment,{children:[e.kind===`newer`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(F2,{current:e.current,latest:e.newer}),(0,q.jsx)(I2,{url:e.releaseNotes,version:e.newer,children:`What changed`})]}):(0,q.jsx)(`p`,{className:P2.line,children:(0,q.jsx)(r_,{text:X2(e)})}),(0,q.jsx)(`span`,{className:P2.spacer}),(0,q.jsx)(Y,{cli:e.kind===`newer`?`ork upgrade`:void 0,id:D2,onClick:()=>{n.opens===null?J2():t(n.opens)},variant:n.primary?`primary`:`default`,children:n.label})]})},Q2=({workspace:e})=>{let{version:t,connection:n,preferences:r}=ob(),i=vb(t.info),a=vb(n),o=vb(r.value),s=vb(t.dialog),c=q2(),l=A2({info:i,connection:a,pageVersion:t.pageVersion,dismissed:o.updateDismissed,now:c});K2(l,i!==null&&a.server!==null,s!==null,e);let u=l===null?null:N2(l);return(0,q.jsx)(`div`,{className:P2.slot,children:l===null?null:(0,q.jsxs)(`section`,{"aria-label":`New version`,className:P2.banner,children:[(0,q.jsx)(`span`,{className:P2.icon,children:(0,q.jsx)(Qy,{})}),(0,q.jsx)(Z2,{banner:l,onOpen:t.openDialog}),u===null?null:(0,q.jsx)(xb,{label:`Dismiss for a day`,onClick:()=>{r.update({updateDismissed:{version:u,at:new Date().toISOString()}}),e.announce(G2),e.focusPanels()},children:(0,q.jsx)(sy,{})})]})})},$2=e=>e===null?`Asking the npm registry for the latest version…`:`Asking the registry at \`${e}\` for the latest version…`,e4=({plan:e})=>(0,q.jsxs)(`dl`,{className:P2.facts,children:[(0,q.jsx)(`dt`,{className:P2.factName,children:`Installed with`}),(0,q.jsx)(`dd`,{className:P2.factValue,children:e.installer?.label??`Ork couldn't tell`}),e.kind===`command`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`dt`,{className:P2.factName,children:`Command`}),(0,q.jsx)(`dd`,{className:P2.factValue,children:(0,q.jsx)(`section`,{"aria-label":`Command to run`,children:(0,q.jsx)(cC,{command:e.command.join(` `)})})})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`dt`,{className:P2.factName,children:`What to do`}),(0,q.jsxs)(`dd`,{className:P2.factValue,children:[(0,q.jsx)(`p`,{className:P2.adviceWords,children:(0,q.jsx)(r_,{text:e.words})}),e.commands.map(e=>(0,q.jsx)(cC,{command:e},e))]})]})]}),t4=({plan:e})=>(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(F2,{current:e.current,latest:e.latest}),(0,q.jsxs)(`p`,{className:P2.message,children:[`What changed:`,` `,(0,q.jsx)(I2,{url:e.releaseNotes,children:e.releaseNotes})]}),(0,q.jsx)(e4,{plan:e}),e.kind===`advice`?(0,q.jsx)(`p`,{className:P2.note,children:`Ork runs only a package manager's own command from here; this one is yours to run.`}):null,(0,q.jsx)(R2,{ids:e.running}),(0,q.jsx)(`p`,{className:P2.note,children:`The same, in a terminal:`}),(0,q.jsx)(cC,{command:`ork upgrade`})]}),n4=({step:e,registry:t})=>e.step===`plan`?(0,q.jsx)(t4,{plan:e.plan}):e.step===`latest`?(0,q.jsx)(B2,{text:`Ork ${e.current} is the latest version.`,tone:`succeeded`}):e.step===`unreachable`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(H2,{icon:!0,text:e.words}),(0,q.jsx)(`p`,{className:P2.message,children:`Nothing was changed.`})]}):(0,q.jsx)(`section`,{"aria-busy":`true`,"aria-label":`Asking`,className:P2.message,children:(0,q.jsx)(r_,{text:$2(t)})}),r4=({step:e,registry:t,first:n,onClose:r,onAsk:i,onUpgrade:a})=>{let o=(0,U.useId)();(0,U.useEffect)(()=>{z2()&&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,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(n4,{registry:t,step:e}),(0,q.jsx)(H2,{text:e.step===`plan`?e.refusal:null}),(0,q.jsx)(U2,{id:o,why:e.step===`checking`?`Asking the registry…`:null}),(0,q.jsxs)(W2,{note:c?`It runs on this machine as you.`:void 0,children:[e.step===`unreachable`?(0,q.jsx)(Y,{onClick:()=>{n.current?.focus(),i()},variant:`ghost`,children:`Try again`},`again`):null,(0,q.jsx)(Y,{disabled:l,focusableWhenDisabled:!0,onClick:r,ref:n,variant:c?`ghost`:`default`,children:c?`Cancel`:`Close`},`close`),c?(0,q.jsx)(Y,{"aria-describedby":o,disabled:!s||l,focusableWhenDisabled:!0,onClick:a,variant:`primary`,children:e.step===`plan`?`Upgrade to ${e.plan.latest}`:`Upgrade`},`upgrade`):null]})]})},i4=({step:e,port:t})=>{let n=(0,U.useId)();return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(B2,{text:"Restarting `ork ui`…"}),(0,q.jsx)(`p`,{className:P2.message,children:e.step===`back`?`Ork ${e.version} is up. Reloading…`:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(r_,{text:`Waiting for \`ork ui\` to come back on port ${t}. Runs keep running.`}),` `,(0,q.jsx)(V2,{since:e.since})]})}),(0,q.jsx)(U2,{id:n,why:"It closes once `ork ui` is back."}),(0,q.jsx)(W2,{children:(0,q.jsx)(Y,{"aria-describedby":n,disabled:!0,focusableWhenDisabled:!0,children:`Close`})})]})},a4=({step:e,port:t,onClose:n,onKeepWaiting:r,onReload:i})=>{if(e.step===`restarting`||e.step===`back`)return(0,q.jsx)(i4,{port:t,step:e});let a=o4(e,t);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(B2,{text:a.heading,tone:`failed`}),(0,q.jsx)(H2,{text:a.words}),(0,q.jsx)(cC,{command:a.command}),(0,q.jsxs)(W2,{children:[e.step===`gaveUp`?(0,q.jsx)(Y,{onClick:r,children:`Keep waiting`}):(0,q.jsx)(Y,{onClick:n,children:`Close`}),e.step===`signedOut`?null:(0,q.jsx)(Y,{onClick:i,variant:`primary`,children:`Reload`})]})]})},o4=(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`},s4="Lost the output from `ork ui`. The command may still be running; reconnecting…",c4=e=>e.command[0]??`it`,l4=(e,t)=>{let n=t.split(`
110
+ `).findLast(e=>e.startsWith(`Could not run`));return e.code===127&&n!==void 0?n:`\`${c4(e)}\` failed (exit ${String(e.code??1)}); the upgrade did not finish.`},u4=({job:e,lost:t,output:n})=>{let r=(0,U.useId)();(0,U.useEffect)(()=>{n.current?.focus()},[n]);let i=c4(e);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`p`,{className:P2.message,children:[(0,q.jsx)(r_,{text:`Running \`${i}\`…`}),` `,(0,q.jsx)(V2,{since:Date.parse(e.startedAt)})]}),(0,q.jsx)(cC,{command:e.command.join(` `)}),t?(0,q.jsx)(H2,{text:s4}):null,(0,q.jsx)(U2,{id:r,why:`It closes when ${i} ends; closing now would hide how it ended.`}),(0,q.jsx)(W2,{children:(0,q.jsx)(Y,{"aria-describedby":r,disabled:!0,focusableWhenDisabled:!0,children:`Close`})})]})},d4=({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 ${c4(u)}`;if(e.step===`running`)return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(LH,{label:d,ref:a,text:t}),(0,q.jsx)(u4,{job:u,lost:n,output:a})]});let f=(0,q.jsx)(LH,{label:d,text:t});return e.step===`failed`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(B2,{ref:o,text:`The upgrade did not finish`,tone:`failed`}),(0,q.jsx)(H2,{text:`${l4(u,t)} Nothing was restarted; \`ork ui\` still runs ${r}.`}),f,(0,q.jsx)(`p`,{className:P2.note,children:`To run it in a terminal yourself:`}),(0,q.jsx)(cC,{command:u.command.join(` `)}),(0,q.jsxs)(W2,{children:[(0,q.jsx)(Y,{onClick:s,children:`Close`}),(0,q.jsx)(Y,{onClick:c,variant:`ghost`,children:`Try again`})]})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(B2,{ref:o,text:`Upgraded to ${u.latest}`,tone:`succeeded`}),(0,q.jsx)(`p`,{className:P2.message,children:(0,q.jsx)(r_,{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,q.jsx)(H2,{text:e.refusal}),(0,q.jsxs)(W2,{children:[(0,q.jsx)(Y,{onClick:s,variant:`ghost`,children:`Later`}),(0,q.jsxs)(Y,{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,q.jsx)($y,{}),`Restart`]})]})]})},f4={pollMs:1e3,waitMs:6e4,reloadMs:1500},p4=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},m4=({client:e,step:t,setStep:n,announce:r,reload:i,timing:a})=>{let o=(0,U.useRef)({announce:r,reload:i});(0,U.useEffect)(()=>{o.current={announce:r,reload:i}}),(0,U.useEffect)(()=>{let r=t.step===`restarting`?t:null,i=!1,s=async t=>{let r=await p4(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])},h4=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.`,g4=(e,t)=>e.kind===`unreachable`?{step:`unreachable`,words:h4(t)}:e.kind===`latest`?{step:`latest`,current:e.current}:{step:`plan`,plan:e,refusal:null,starting:!1},_4=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.`,v4=e=>e.state===`running`?{step:`running`,job:e}:e.state===`succeeded`?{step:`done`,job:e,refusal:null,asking:!1}:{step:`failed`,job:e},y4=({client:e,open:t,job:n,registry:r,announce:i,onAsked:a})=>{let[o,s]=(0,U.useState)(()=>n===null?{step:`checking`}:v4(n)),[c,l]=(0,U.useState)([]),[u,d]=(0,U.useState)(!1),f=(0,U.useRef)(null),p=(0,U.useRef)(0),m=(0,U.useRef)({announce:i,onAsked:a,registry:r});(0,U.useEffect)(()=>{m.current={announce:i,onAsked:a,registry:r}});let h=(0,U.useCallback)(e=>{f.current?.close(),p.current=0,l([]);let n=ZV({url:()=>`${xw.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(v4({...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,U.useCallback)(async()=>{s({step:`checking`});let t=await e.call(`upgradePlan`);m.current.onAsked();let n=t.ok?g4(t.data,m.current.registry):{step:`unreachable`,words:t.error};s(n),n.step===`plan`&&m.current.announce(_4(n.plan))},[e]),_=(0,U.useRef)(n);(0,U.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=g4(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(`
111
+ `),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()})}}},b4=e=>[`checking`,`unreachable`,`latest`,`plan`].includes(e.step),x4=e=>[`running`,`done`,`failed`].includes(e.step),S4=e=>!b4(e)&&!x4(e),C4=({starts:e,timing:t,reload:n,onStep:r,onClose:i})=>{let{version:a,client:o}=ob(),s=(0,U.use)(wL),c=vb(a.info),l=vb(a.dialog),u=(0,U.useCallback)(e=>s?.announce(e),[s]),d=y4({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;m4({client:o,step:f,setStep:p,announce:u,reload:n,timing:t}),(0,U.useEffect)(()=>{r(f)},[f,r]);let m=f.step===`restarting`||f.step===`back`;(0,U.useEffect)(()=>(a.restarting.setValue(m),()=>{a.restarting.setValue(!1)}),[a,m]);let h=window.location.port;return b4(f)?(0,q.jsx)(r4,{first:e.first,onAsk:d.ask,onClose:i,onUpgrade:d.upgrade,registry:c?.registry??null,step:f}):x4(f)?(0,q.jsx)(d4,{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}):S4(f)?(0,q.jsx)(a4,{onClose:i,onKeepWaiting:d.keepWaiting,onReload:n,port:h,step:f}):null},w4=()=>{window.location.reload()},T4=e=>![`running`,`restarting`,`back`].includes(e.step)&&!(e.step===`plan`&&e.starting)&&!(e.step===`done`&&e.asking),E4=`Upgrade Ork`,D4=({timing:e=f4,reload:t=w4})=>{let{version:n}=ob(),r=(0,U.use)(wL),i=vb(n.dialog),a=vb(n.info),o=(0,U.useRef)(null),s=(0,U.useRef)(null),c=(0,U.useRef)(null),l=i===`job`&&a?.job?.state!==`running`,u=i===`job`?l?c:s:o,[d,f]=(0,U.useState)(E4),p=(0,U.useRef)({closable:!0,ran:!1}),m=(0,U.useCallback)(e=>{p.current={closable:T4(e),ran:p.current.ran||`job`in e},f(t=>b4(e)?E4:`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(E4),n.closeDialog())};return(0,q.jsx)(NC,{finalFocus:()=>{let e=document.querySelector(`#${D2}`);return e===null?(r?.focusPanels(),!1):e},initialFocus:u,onOpenChange:e=>{e||h()},open:i!==null,size:`wide`,title:d,children:(0,q.jsx)(C4,{onClose:h,onStep:m,reload:t,starts:{first:o,output:s,heading:c},timing:e})})},O4=({workspace:e})=>(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Q2,{workspace:e}),(0,q.jsx)(D4,{})]});function k4(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]=U.useState(r??``),[p,m]=U.useState(``);U.useEffect(()=>{(u||!c)&&m(``)},[n,u,c]);let h;h=c&&p!==``?p:u?n??``:d;let g=Sx({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?Zb(t,o):``)}return(0,q.jsx)(Ax,{...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 A4=QS,j4=[`Panels`,`Runs`,`Window`,`Layout`,`View`,`Ork`],M4=`Needs a wider window.`,N4=`No panel is active.`,P4=[`left`,`right`,`up`,`down`],F4={left:`narrower`,right:`wider`,up:`shorter`,down:`taller`},I4=e=>e.wide?e.active===null?N4:void 0:M4,L4=e=>IY.map((t,n)=>{let r={id:`go-${t.id}`,title:`Go to ${t.title}`,group:`Panels`,run:()=>{e.goTo(t.id)}},i=Xk(n+1);return i!==void 0&&(r.shortcut=i),r}),R4=e=>[{id:`run-workflow`,title:`Run workflow…`,group:`Runs`,run:()=>{e.runDialog.setValue(!0)}}],z4=(e,t)=>{let n=I4(t),r=t.active===null?`panel`:RY(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:Jk.minimize,run:()=>{e.minimize()},disabled:n},{id:`maximize`,title:t.maximized?`Restore ${r}`:`Maximize ${r}`,group:`Window`,shortcut:Jk.maximize,run:()=>{e.toggleMaximize()},disabled:i},{id:`float`,title:t.floating?`Dock ${r}`:`Float ${r}`,group:`Window`,shortcut:Jk.float,run:()=>{e.toggleFloat()},disabled:n},{id:`close`,title:`Close ${r}`,group:`Window`,shortcut:Jk.close,run:()=>{e.close()},disabled:n},...P4.map(t=>({id:`resize-${t}`,title:`Make ${r} ${F4[t]}`,group:`Window`,shortcut:Jk.resize(t),run:()=>{e.resize(t)},disabled:a})),...P4.map(t=>({id:`move-${t}`,title:`Move ${r} ${t}`,group:`Window`,shortcut:Jk.move(t),run:()=>{e.move(t)},disabled:n}))]},B4=(e,t)=>{let n=t.wide?void 0:M4;return[{id:`next-group`,title:`Focus next panel group`,group:`Layout`,shortcut:Jk.nextGroup,run:()=>{e.cycleGroup(1)},disabled:n},{id:`previous-group`,title:`Focus previous panel group`,group:`Layout`,shortcut:Jk.previousGroup,run:()=>{e.cycleGroup(-1)},disabled:n},{id:`reset-layout`,title:`Reset layout`,group:`Layout`,run:()=>{e.resetLayout()}}]},V4=[{theme:`system`,title:`Follow the system`},{theme:`dark`,title:`Dark`},{theme:`light`,title:`Light`}],H4=[{density:`compact`,title:`Compact`},{density:`comfortable`,title:`Comfortable`}],U4=(e,t,n)=>[...V4.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})),...H4.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}))],W4=e=>[{id:`upgrade-ork`,title:`Upgrade Ork…`,group:`Ork`,detail:`Asks the registry for a new version now.`,run:()=>{e.version.openDialog(`ask`)}}],G4=(e,t,n,r)=>[...L4(e),...R4(n),...z4(e,t),...B4(e,t),...U4(e,n.preferences,r),...W4(n)],K4={palette:`_palette_p3ocp_6`,input:`_input_p3ocp_45`,list:`_list_p3ocp_78`,group:`_group_p3ocp_88`,empty:`_empty_p3ocp_106`},q4=e=>j4.map(t=>({value:t,items:e.filter(e=>e.group===t).map(e=>({label:e.title,command:e}))})),J4=({commands:e,onChoose:t})=>{let n=(0,U.useMemo)(()=>q4(e),[e]),r=Zk();return(0,q.jsxs)(k4,{autoHighlight:`always`,inline:!0,items:n,keepHighlight:!0,open:!0,children:[(0,q.jsx)(Zx,{"aria-label":`Search commands`,className:K4.input,placeholder:`Type a command`}),(0,q.jsx)(tC,{children:(0,q.jsx)(`p`,{className:K4.empty,children:`No command matches.`})}),(0,q.jsx)(_S,{className:K4.list,children:e=>(0,q.jsxs)(US,{items:e.items,children:[(0,q.jsx)(WS,{className:K4.group,children:e.value}),(0,q.jsx)(sS,{children:e=>(0,q.jsxs)(A4,{className:o_.item,disabled:e.command.disabled!==void 0,onClick:()=>{t(e.command)},value:e,children:[(0,q.jsx)(`span`,{children:e.label}),(e.command.disabled??e.command.detail)===void 0?null:(0,q.jsx)(`span`,{className:o_.itemDetail,children:e.command.disabled??e.command.detail}),e.command.shortcut===void 0?null:(0,q.jsx)(a_,{keys:Wk(e.command.shortcut,r)})]},e.command.id)})]},e.value)})]})},Y4=()=>(document.activeElement===null||document.activeElement===document.body)&&document.querySelector(`[data-modal]`)===null,X4=e=>{requestAnimationFrame(()=>{requestAnimationFrame(e)})},Z4=({workspace:e,commands:t})=>{let n=vb(e.palette),r=(0,U.useRef)(null),i=(0,U.useRef)(!1),a=(0,U.useRef)(null);(0,U.useLayoutEffect)(()=>{n&&(i.current=!1,a.current=document.activeElement)},[n]);let o=t=>{e.palette.setValue(t)},s=()=>{if(!Y4())return;let t=a.current;t instanceof HTMLElement&&t.isConnected?t.focus():e.focusPanels()};return(0,q.jsx)(AC,{onOpenChange:o,onOpenChangeComplete:e=>{if(e)return;let t=r.current;r.current=null,t!==null&&(t.run(),X4(s))},open:n,children:(0,q.jsxs)(OC,{children:[(0,q.jsx)(vC,{className:jC.backdrop}),(0,q.jsx)(DC,{"aria-label":`Command palette`,"aria-modal":`true`,className:K4.palette,finalFocus:()=>!i.current,children:(0,q.jsx)(J4,{commands:t,onChoose:e=>{r.current=e,i.current=!0,o(!1)}})})]})})},Q4=(e,t,n)=>`${String(e)} ${e===1?t:n}`,$4=()=>{let{runs:e,decisions:t,connection:n}=ob(),r=_b(e,vH),i=_b(t,e=>e?.length??null);return _b(n,({link:e})=>e===`open`)&&r!==null&&i!==null?(0,q.jsxs)(`span`,{className:eA.status,children:[Q4(r,`run live`,`runs live`),`,`,` `,Q4(i,`decision open`,`decisions open`)]}):null},e3=({workspace:e})=>{let t=vb(e.announcement),{connection:n,version:r}=ob(),i=_b(n,_H),a=vb(r.restarting);return(0,q.jsxs)(`footer`,{className:eA.bar,children:[(0,q.jsx)(`output`,{"aria-live":a?`off`:void 0,className:eA.status,children:(0,q.jsx)(r_,{text:i})}),(0,q.jsx)($4,{}),(0,q.jsx)(`output`,{"aria-atomic":`true`,"aria-live":`polite`,className:eA.visuallyHidden,children:t})]})},t3=e=>{let t=ob(),{preferences:n}=t,r=vb(e.view),i=vb(n.value),a=(0,U.useMemo)(()=>G4(e,r,t,i),[e,r,t,i]);return $k(e,a),a},n3=e=>{let t=ob();(0,U.useEffect)(()=>t.notifications.onNew(n=>{if(e.announce(n.map(({title:e})=>e).join(` `)),t.preferences.value.getValue().desktopNotifications)for(let r of n)YW(r.title,r.id,()=>{t.selectRun(r.runId),e.goTo(`notifications`)})}),[t,e])},r3=({workspace:e})=>{let t=t3(e);return n3(e),(0,q.jsx)(wL,{value:e,children:(0,q.jsxs)(`div`,{className:eA.shell,children:[(0,q.jsx)(HY,{workspace:e}),(0,q.jsx)(O4,{workspace:e}),(0,q.jsx)(E2,{workspace:e}),(0,q.jsx)(e3,{workspace:e}),(0,q.jsx)(Z4,{commands:t,workspace:e}),(0,q.jsx)(Vk,{})]})})},i3=()=>{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)}}},a3=()=>{try{return window.localStorage}catch{return i3()}},o3=1e3,s3=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(` `))},o3)};return e=>{let i=n_(e);n?t.push(i):r(i)}},c3=280,l3=340,u3=240,d3={minimumWidth:240,minimumHeight:120},f3=e=>{e.api.setConstraints(d3)},p3=(e,t,n)=>[e.onDidAddGroup(f3),e.onDidLayoutChange(()=>{n(),t()}),e.onDidAddPanel(t),e.onDidRemovePanel(t),e.onDidActivePanelChange(t),e.onDidMaximizedGroupChange(t)],m3=(e,t)=>{try{return e.fromJSON(t),!0}catch{return e.clear(),!1}},h3=(e,t,n)=>e.addPanel({id:t,component:t,title:RY(t).title,...n}),g3=e=>{let t=h3(e,`monitor`,{});h3(e,`builder`,{position:{referencePanel:`monitor`,direction:`within`},inactive:!0}),h3(e,`runs`,{position:{referencePanel:`monitor`,direction:`left`},initialWidth:c3,inactive:!0}),h3(e,`decisions`,{position:{referencePanel:`monitor`,direction:`right`},initialWidth:l3,inactive:!0}),h3(e,`notifications`,{position:{referencePanel:`decisions`,direction:`within`},inactive:!0}),h3(e,`context`,{position:{referencePanel:`decisions`,direction:`below`}}),h3(e,`logs`,{position:{referencePanel:`monitor`,direction:`below`},initialHeight:u3,inactive:!0}),h3(e,`chats`,{position:{referencePanel:`logs`,direction:`within`},inactive:!0}),h3(e,`usage`,{position:{referencePanel:`logs`,direction:`within`},inactive:!0}),h3(e,`feedback`,{position:{referencePanel:`usage`,direction:`within`},inactive:!0}),h3(e,`worktrees`,{position:{referencePanel:`feedback`,direction:`within`},inactive:!0}),t.api.setActive()},_3=(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=_3(e,t,!n);if(r!==void 0)return r}},v3={horizontal:`left`,vertical:`above`},y3={horizontal:`right`,vertical:`below`},b3=(e,t)=>{let{root:n,orientation:r}=e.toJSON().grid,i=r===eZ.HORIZONTAL,a=_3(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?y3[l]:v3[l];return Array.isArray(d.data)?c?{group:null,direction:p,...f}:void 0:{group:d.data.id,direction:p,...f}},x3=(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}},S3=(e,t)=>{let{group:n}=t,r=x3(e,n),i=b3(e,n);return{group:n.id,index:n.panels.indexOf(t),...r===void 0?{}:{floating:r},...i===void 0?{}:{beside:i}}},C3=(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`}}},w3=(e,t,n)=>h3(e,t,C3(e,n)),T3=(e,t)=>e.groups.find(e=>e.id===t),E3=e=>{let t=e.element.querySelector(`[role="tab"][aria-selected="true"]`);return t?.focus(),t!==null},D3=e=>{e.api.setActive(),requestAnimationFrame(()=>{E3(e.group)})},O3=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),k3=(e,t)=>{let n=O3(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(),E3(i))},A3=e=>{e.api.location.type===`grid`&&(e.api.isMaximized()?e.api.exitMaximized():e.api.maximize(),E3(e))},j3={right:{axis:`width`,delta:32},left:{axis:`width`,delta:-32},down:{axis:`height`,delta:32},up:{axis:`height`,delta:-32}},M3=(e,t)=>{let{axis:n,delta:r}=j3[t];e.api.setSize({[n]:e.api[n]+r})},N3=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}.`},P3={right:{x:32,y:0},left:{x:-32,y:0},down:{x:0,y:32},up:{x:0,y:-32}},F3={left:`left`,right:`right`,up:`above`,down:`below`},I3=(e,t,n)=>{let{group:r}=t,i=x3(e,r);if(i!==void 0){let{x:t,y:a}=P3[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:T3(e,a.id);o===void 0?(r.panels.length!==1||e.groups.length!==1)&&t.api.moveTo({group:e.addGroup({direction:F3[n]}),position:`center`}):t.api.moveTo({group:o,position:`center`})},L3={left:`left`,right:`right`,above:`top`,below:`bottom`},R3=(e,t,n)=>{let r=t.activePanel;if(r===void 0)return;if(t.api.location.type!==`floating`){let{beside:i}=S3(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:T3(e,i.group),o=i?.direction??`right`;t.api.moveTo(a===void 0?{position:L3[o]}:{group:a,position:L3[o]}),i!==void 0&&t.api.setSize(o===`left`||o===`right`?{width:i.width}:{height:i.height})},z3=`ork.layout.v1`,B3=Qs(e=>typeof e==`string`&&LY(e)),V3=hs({left:rs(),top:rs(),width:rs(),height:rs()}),H3=hs({id:B3,anchor:hs({group:V(),index:rs(),floating:V3.optional(),beside:hs({group:V().nullable(),direction:Os([`left`,`right`,`above`,`below`]),width:rs(),height:rs()}).optional()})}),U3=gs({grid:gs({root:gs({})}),panels:Es(V(),gs({contentComponent:B3}))}),W3=hs({dock:ls(),minimized:ps(H3),folded:ps(B3)}),G3=(e,t,n)=>[...e.filter(e=>e!==t),...n?[t]:[]],K3={dock:null,minimized:[],folded:[]},q3=e=>U3.safeParse(e).success,J3=e=>{let t=W3.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(!q3(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}},Y3=e=>new ub(K3,{key:z3,storage:e}),X3=({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&&A3(r),n()},toggleFloat:t=>{let i=e(),a=t??i?.activeGroup;i!==null&&a!==void 0&&(s(),R3(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&&(M3(r,t),i(N3(a)))},move:t=>{let o=e(),c=o?.activePanel;o!==null&&c!==void 0&&(a(()=>{s(),I3(o,c,t)}),n(),r(),i(`${c.title??c.id} moved ${t}.`))},cycleGroup:t=>{let n=e();n!==null&&k3(n,t)}}},Z3=({storage:e,wide:t,onLayoutDropped:n})=>{let r=Y3(e),i=J3(r.getValue()),a=i===null;a&&r.reset();let o=cb.create(v2(null,i??K3,t)),s=cb.create(!1),c=cb.create(``),l=null,u=!1,d=[],f=s3(c),p=e=>{u||f(e)},m=e=>{u=!0,e(),u=!1},h=()=>{let e=o.getValue(),t=v2(l,r.getValue(),e.wide);y2(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&&m3(e,t)||(a||=t!==null,r.setValue({...K3,folded:i}),g3(e)),a&&n?.(),a=!1,e.groups.forEach(f3),d=p3(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&&E3(t))&&e!==void 0&&S2(x2(e))})},w=()=>{let[e]=IY;o.getValue().wide?C():e!==void 0&&S2(b2(e.id))},T=e=>{let t=b(e);if(l===null||t===void 0)return;let n=t.id;if(!LY(n))return;m(x);let r=S3(l,t);S(e=>[...e,{id:n,anchor:r}]),m(()=>{t.api.close()}),f(`${RY(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(),D3(w3(n,e,t?.anchor))}),f(`${RY(e).title} restored.`),_()},D=(e,t)=>{let n=r.getValue();r.setValue({...n,folded:G3(n.folded,e,t)}),_()},O=e=>{D(e,!r.getValue().folded.includes(e))},k=e=>{if(!o.getValue().wide){D(e,!1),S2(b2(e));return}if(l===null)return;let t=l.getPanel(e);if(t!==void 0)t.api.isMaximized()||x(),D3(t);else if(o.getValue().minimized.includes(e))E(e);else{let t=l;m(()=>{x(),D3(w3(t,e))}),f(`${RY(e).title} opened.`)}},A=X3({dock:()=>l,targetPanel:b,commit:_,refocus:C,announce:f,quietly:m}),j=()=>{if(r.setValue(K3),l!==null){let e=l;m(()=>{e.clear(),g3(e)}),l.groups.forEach(f3),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}},Q3=Ew(),$3=`1.0.0-alpha.14`,e6=()=>yH({client:Q3,open:KV,storage:a3(),pageVersion:$3}),t6=()=>Z3({storage:a3(),wide:window.matchMedia(_2).matches,onLayoutDropped:()=>{tb.add({title:`Layout reset`,description:`The saved layout could not be read.`})}}),n6=()=>{let[e]=(0,U.useState)(e6),[t]=(0,U.useState)(t6);return(0,U.useLayoutEffect)(()=>hb(window,e.preferences),[e]),(0,U.useEffect)(()=>e.start(),[e]),(0,q.jsx)(ab,{value:e,children:(0,q.jsx)(c_,{children:(0,q.jsx)(rb,{children:(0,q.jsx)(r3,{workspace:t})})})})};export{n6 as App};