@fungi.computer/inkcap 0.11.7 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./FileTab-BHqgbtrf.js","./rolldown-runtime-hePW80VL.js","./tree-path-OxFSrOVk.js","./useForm-BJ9GDXFn.js","./InkcapFileTree-4aUfCyx4.js","./folder-open-I8YWN3IG.js","./useFileTree-CdHHfQqh.js","./InkcapRepositoryApp-D5l2ef9a.js"])))=>i.map(i=>d[i]);
2
- import{r as e,t}from"./rolldown-runtime-hePW80VL.js";import{$ as n,$r as r,$t as i,A as a,An as o,At as s,B as c,Bi as l,Br as u,Bt as d,C as f,Cn as p,Ct as m,D as h,Dn as g,Dt as _,E as v,En as y,Et as b,F as x,Fn as S,Ft as ee,G as C,Gr as w,Gt as T,H as te,Ht as E,I as D,Ii as O,In as k,It as A,Jr as j,Jt as M,K as N,Ki as P,Kt as F,L as I,Ln as L,Lr as R,Lt as z,M as ne,Ma as B,Mi as V,Mn as re,Mt as H,N as U,Nn as ie,Nt as W,O as ae,Oi as oe,On as se,Ot as ce,P as le,Pa as G,Pn as ue,Pt as de,Q as fe,Qi as pe,Qt as me,Rn as K,S as he,Sn as ge,Sr as q,St as _e,T as ve,Tn as ye,Tt as be,Ui as xe,Ur as Se,Ut as Ce,V as we,Vr as Te,Vt as Ee,W as De,Wr as Oe,Wt as ke,X as Ae,Xr as J,Xt as je,Yr as Me,Yt as Ne,Z as Pe,Zi as Fe,Zr as Ie,Zt as Le,_ as Re,_n as ze,_r as Be,_t as Ve,a as He,ai as Ue,an as We,at as Ge,b as Ke,bi as qe,br as Je,bt as Ye,c as Xe,d as Ze,dn as Qe,dt as $e,ei as Y,en as et,et as tt,f as nt,fn as rt,ft as it,g as at,gt as ot,h as st,hn as ct,hr as lt,ht as ut,i as dt,ii as ft,in as pt,it as mt,j as ht,ja as gt,ji as _t,jn as vt,jt as yt,k as bt,kn as xt,kt as St,l as Ct,lt as wt,m as Tt,mn as Et,mt as Dt,n as Ot,ni as kt,nn as At,nt as jt,o as Mt,on as Nt,ot as Pt,p as Ft,pn as It,pt as Lt,q as Rt,qr as zt,qt as Bt,ri as Vt,rn as Ht,rt as Ut,s as Wt,sn as Gt,st as Kt,t as qt,ti as X,tn as Jt,tt as Yt,u as Xt,un as Zt,ut as Qt,vi as $t,vn as en,vt as tn,w as nn,wi as rn,wr as an,wt as on,x as sn,xi as cn,xr as ln,xt as un,y as dn,yi as fn,yn as pn,yr as mn,yt as hn,z as gn,zi as _n,zn as vn,zr as yn,zt as bn}from"./tree-path-OxFSrOVk.js";import{$ as xn,A as Sn,At as Cn,B as wn,C as Tn,Ct as En,D as Dn,Dt as On,E as kn,Et as An,F as jn,Ft as Mn,G as Nn,H as Pn,I as Fn,It as In,J as Ln,K as Rn,L as zn,Lt as Bn,M as Vn,Mt as Hn,N as Un,O as Wn,Ot as Gn,P as Kn,Q as qn,R as Jn,S as Yn,St as Xn,T as Zn,Tt as Qn,U as $n,V as er,W as tr,X as nr,Y as rr,Z as ir,_ as ar,_t as or,a as sr,at as cr,b as lr,bt as ur,ct as dr,d as fr,dt as pr,et as mr,f as hr,ft as gr,g as _r,gt as vr,h as yr,ht as br,it as xr,j as Sr,k as Cr,kt as wr,lt as Tr,m as Er,mt as Dr,n as Or,nt as kr,ot as Ar,p as jr,pt as Mr,q as Nr,r as Pr,rt as Fr,st as Ir,t as Lr,tt as Rr,u as zr,ut as Br,v as Vr,vt as Hr,w as Ur,wt as Wr,x as Gr,xt as Kr,y as qr,yt as Jr,z as Yr}from"./folder-open-I8YWN3IG.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var Z=e(qe(),1);function Xr(e,t,n){let r=Gn(),i=On(),a=In(n),o=a.defaultQueryOptions(e),s=a.getQueryCache().get(o.queryHash),c=e.subscribed!==!1;o._optimisticResults=r?`isRestoring`:c?`optimistic`:void 0,Kr(o),Wr(o,i,s),An(i);let[l]=Z.useState(()=>new t(a,o)),u=l.getOptimisticResult(o),d=!r&&c;if(Z.useSyncExternalStore(Z.useCallback(e=>{let t=d?l.subscribe(Cn.batchCalls(e)):Hn;return l.updateResult(),t},[l,d]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),Z.useEffect(()=>{l.setOptions(o)},[o,l]),En(o,u))throw Xn(o,l,i);if(Qn({result:u,errorResetBoundary:i,throwOnError:o.throwOnError,query:s,suspense:o.suspense}))throw u.error;return o.notifyOnChangeProps?u:l.trackResult(u)}function Zr(e,t){return Xr(e,wr,t)}yn(`light.dark.latte.mocha.readout.readout-night.field-guide.field-guide-night.embed.embed-dark.phosphor.codec.paper.ember.tide.tape.sunrise.pirate-radio.pirate-radio-night.consulting.consulting-ink.consulting-night.consulting-night-ink.consulting-riso-latte.consulting-riso-latte-ink.consulting-riso-glomzy.consulting-riso-glomzy-ink.vishnu.coin.coin-night.chamfer`.split(`.`));var Qr=`data-theme`;function $r(e){return e||(globalThis.document?.documentElement??null)}function ei(e){let t=e.trim();if(t.length===0)throw TypeError(`Theme must be a non-empty string`);return t}function ti(e,t){let n=ei(e),r=$r(t);r&&r.setAttribute(Qr,n)}function ni(e){return $r(e)?.getAttribute(Qr)??null}function ri(e,t){let n=$r(t),r=globalThis,i=(n?.ownerDocument??null)?.defaultView?.MutationObserver??r.MutationObserver;if(!n||!i)return()=>void 0;let a=new i(t=>{if(!t.some(e=>e.type===`attributes`&&e.attributeName===Qr))return;let r=n.getAttribute(Qr);r&&e(r)});a.observe(n,{attributes:!0,attributeFilter:[Qr]});let o=!1;return()=>{o||(o=!0,a.disconnect())}}var ii=t((e=>{var t=ln();e.createRoot=t.createRoot,e.hydrateRoot=t.hydrateRoot}));function ai(e){let t=e.trim().toLowerCase();if(!t)throw Error(`Invalid keymap token: token cannot be empty`);return t}function oi(e){let t=e.trim().toLowerCase();if(!t)throw Error(`Invalid key name: key name cannot be empty`);return t}function si(e){return{name:oi(e.name),ctrl:e.ctrl??!1,shift:e.shift??!1,meta:e.meta??!1,super:e.super??!1,hyper:e.hyper||void 0}}function ci(e){return{name:e.name,ctrl:e.ctrl,shift:e.shift,meta:e.meta,super:e.super,hyper:e.hyper||void 0}}function li(e,t){let n=ci(si(e));return{stroke:n,display:t?.display??_i(n),match:t?.match??pi(n),tokenName:t?.tokenName?ai(t.tokenName):void 0}}function ui(e){return{stroke:ci(e.stroke),display:e.display,match:e.match,tokenName:e.tokenName,patternName:e.patternName,payloadKey:e.payloadKey}}function di(e){return e.map(e=>ui(e))}function fi(e){return`match`in e?e.match:`stroke`in e?pi(e.stroke):pi(e)}function pi(e){return`key:${vi(si(e))}`}function mi(e){let t=e.trim();if(!t)throw Error(`Invalid keymap match id: id cannot be empty`);return`text:${t}`}function hi(e,t){return`stroke`in e?t?.preferDisplay&&e.display?e.display:_i(e.stroke):_i(si(e))}function gi(e,t){return e.map(e=>hi(e,t)).join(t?.separator??``)}function _i(e){let t=[];return e.ctrl&&t.push(`ctrl`),e.shift&&t.push(`shift`),e.meta&&t.push(`meta`),e.super&&t.push(`super`),e.hyper&&t.push(`hyper`),t.push(e.name===`return`?`enter`:e.name),t.join(`+`)}function vi(e){return`${e.name}:${+!!e.ctrl}:${+!!e.shift}:${+!!e.meta}:${+!!e.super}:${+!!e.hyper}`}var yi=Symbol(`keymap-extension-context`);function bi(e){return e.isDestroyed?null:e.getFocusedTarget()}function xi(e,t,n){let r=t??e.rootTarget,i=t!==null;for(;r;){if(n(r,i)===!1)return;r=e.getParentTarget(r),i=!1}}function Si(e,t){let n=new Set;return xi(e,t,e=>{n.add(e)}),n}function Ci(e,t,n){let r=[],i=Si(t,n),a=Array.isArray(e)?e:wi(e);for(let e of a)Ti(t,e,n,i)&&r.push(e);return r}function wi(e){return[...e].sort((e,t)=>t.priority-e.priority||t.order-e.order)}function Ti(e,t,n,r=Si(e,n)){let i=t.target;return i?e.isTargetDestroyed(i)?!1:t.targetMode===`focus`?i===n:r.has(i):!0}function Ei(e){let t=e.binding.sequence[e.index];if(!t?.patternName)return 0;let n=e.patterns?.at(-1);return n?.name===t.patternName?n.values.length:0}function Di(e,t,n=!0){let r=e.binding.sequence[e.index];if(!r?.patternName)return!0;let i=t.get(r.patternName);return i?Ei(e)>=i.min:n}function Oi(e,t,n=!0){let r=e.binding.sequence[e.index];if(r?.patternName){let n=t.get(r.patternName);if(n&&Ei(e)<n.max)return!0}return Di(e,t,n)&&e.index+1<e.binding.sequence.length}function ki(e,t){return e.index===e.binding.sequence.length-1&&Di(e,t,!1)}function Ai(e,t,n,r){return{parent:e,depth:e?e.depth+1:0,stroke:t,match:n,pattern:r,children:new Map,patternChildren:[],bindings:[],reachableBindings:[]}}function ji(e,t){let n=Ai(null,null,null);for(let r of e){if(r.event!==`press`)continue;let e=n;for(let n of r.sequence){let i;if(n.patternName){let r=t.get(n.patternName);i=e.patternChildren.find(e=>e.pattern?.name===n.patternName),i||(i=Ai(e,n.stroke,n.match,r),e.patternChildren.push(i))}else i=e.children.get(n.match),i||(i=Ai(e,n.stroke,n.match),e.children.set(n.match,i));i.reachableBindings.push(r),e=i}e.bindings.push(r)}return n}function Mi(e,t){let n=[];for(let r of e){if(!Di(r,t))continue;let e=r.index+1,i=r.binding.sequence[e];i&&n.push({part:i,binding:r.binding,index:e,exact:e===r.binding.sequence.length-1,continues:e<r.binding.sequence.length-1})}return n}function Ni(e,t,n,r){let i=n.patternName;if(!i)return{...e,index:t};let a=[...e.patterns??[]],o=a.at(-1);return o?.name===i?a[a.length-1]={...o,values:[...o.values,r],parts:[...o.parts,n]}:a.push({name:i,payloadKey:n.payloadKey??i,values:[r],parts:[n]}),{layer:e.layer,binding:e.binding,index:t,parts:[...e.parts,n],patterns:a}}function Pi(e,t){let n=e.parts.at(-1);if(!n||n.patternName)return t.length;let r=t.indexOf(n.match);return r===-1?t.length:r}function Fi(e,t,n,r,i,a,o,s,c){let l=t.sequence[n];if(l){if(l.patternName){let a=s(l.patternName,o);if(!a)return;let u=c(o,l.patternName,a);return Ni({layer:e,binding:t,index:n,parts:r,patterns:i},n,u,a.value??o.name)}if(a.includes(l.match))return{layer:e,binding:t,index:n,parts:[...r,l],patterns:i}}}function Ii(e,t,n,r,i,a){let o=e.binding.sequence[e.index];if(o?.patternName){let s=r.get(o.patternName);if(s&&Ei(e)<s.max){let t=i(s.name,n);if(t){let r=a(n,s.name,t);return Ni(e,e.index,r,t.value??n.name)}}return Di(e,r,!1)?Fi(e.layer,e.binding,e.index+1,e.parts,e.patterns,t,n,i,a):void 0}return Fi(e.layer,e.binding,e.index+1,e.parts,e.patterns,t,n,i,a)}function Li(e,t,n,r,i){let a=[],o=1/0;for(let s of e.bindings){if(s.event!==`press`)continue;let c=Fi(e,s,0,[],void 0,t,n,r,i);if(!c)continue;let l=Pi(c,t);l<o&&(o=l,a.length=0),l===o&&a.push(c)}return a}import.meta.require;function Ri(e){let t=Object.create(null),n=(e,n)=>{let r=t[e];if(!r)return;let i=r.filter(e=>e!==n);i.length===0?delete t[e]:i.length!==r.length&&(t[e]=i)};return{hook(e,r){return t[e]=[...t[e]??[],r],()=>n(e,r)},has(e){return(t[e]?.length??0)>0},emit(n,...r){let i=t[n];if(i)for(let t of i)try{r.length===0?t():t(r[0])}catch(t){e(n,t)}}}}function zi(){let e=[];return{get:()=>e,set:t=>{e=t},remove(t){e=e.filter(e=>e!==t)},has:()=>e.length>0,clear:()=>{e=[]}}}function Bi(){let e=zi();return{append(t){return e.set([...e.get(),t]),()=>e.remove(t)},prepend(t){return e.set([t,...e.get()]),()=>e.remove(t)},values:e.get,has:e.has,clear:e.clear}}function Vi(){let e=zi(),t=0;return{register(n,r){let i={...r,listener:n,order:t++};return e.set([...e.get(),i].sort((e,t)=>t.priority-e.priority||e.order-t.order)),()=>e.remove(i)},entries:e.get,has:e.has,clear:e.clear}}function Hi(e){return typeof e==`string`||!!e&&typeof e==`object`&&!Array.isArray(e)}function Ui(e){if(!Array.isArray(e))return{ok:!1,reason:`Invalid keymap bindings: expected an array of binding objects`};for(let[t,n]of e.entries()){if(!n||typeof n!=`object`||Array.isArray(n))return{ok:!1,reason:`Invalid keymap binding at index ${t}: expected a binding object`};if(!Hi(n.key))return{ok:!1,reason:`Invalid keymap binding at index ${t}: expected "key" to be a string or keystroke object`}}return{ok:!0}}function Wi(e){let t=Ui(e);if(!t.ok)throw Error(t.reason);return e.map(e=>({...e,key:typeof e.key==`string`?e.key:{...e.key}}))}function Gi(e){return{...e,sequence:di(e.sequence)}}function Ki(e,t){let n=Bi();return{prependLayerAnalyzer(e){return n.prepend(e)},appendLayerAnalyzer(e){return n.append(e)},clearLayerAnalyzers(){n.clear()},analyzeLayer(r){let i=n.values();if(i.length===0)return;let a=qi(r.bindings),o={target:r.target,order:r.order,sourceBindings:r.sourceBindings,bindings:a,hasTokenBindings:r.hasTokenBindings,checkCommandResolution(e){return t.getCommandResolutionStatus(e,r.commands)},warn(t,n,r){e.emitWarning(t,n,r)},warnOnce(t,n,r,i){e.warnOnce(t,n,r,i)},error(t,n,r){e.emitError(t,n,r)}};for(let t of i)try{t(o)}catch(t){e.emitError(`layer-analyzer-error`,t,`[Keymap] Error in layer analyzer:`)}}}}function qi(e){return e.map(t=>({sequence:di(t.sequence),command:t.command,attrs:t.attrs,event:t.event,preventDefault:t.preventDefault,fallthrough:t.fallthrough,parsedBinding:Gi(t.parsedBinding),sourceTarget:t.sourceTarget,sourceLayerOrder:t.sourceLayerOrder,bindingIndex:t.bindingIndex,hasCommandAtSequence:e.some(e=>e.event===`press`&&e.command!==void 0&&Ji(e,t)),hasContinuations:e.some(e=>e.event===`press`&&Yi(t,e))}))}function Ji(e,t){return e.sequence.length===t.sequence.length&&e.sequence.every((e,n)=>e.match===t.sequence[n]?.match)}function Yi(e,t){return e.sequence.length<t.sequence.length&&e.sequence.every((e,n)=>e.match===t.sequence[n]?.match)}function Xi(){return{version:-1,notifyVersion:-1,focused:void 0,value:[],targets:new WeakMap}}function Zi(){return{plain:Xi(),bindings:Xi(),metadata:Xi(),bindingsAndMetadata:Xi()}}function Qi(e,t){if(t===void 0)return e.plain;let n=t.includeBindings===!0,r=t.includeMetadata===!0;return n?r?e.bindingsAndMetadata:e.bindings:r?e.metadata:e.plain}function $i(e,t,n){let r=n?e.targets.get(n):e.nullTarget;return r?.version===t?r:void 0}function ea(e,t,n,r){let i={version:t,value:r};n?e.targets.set(n,i):e.nullTarget=i}function ta(e,t){if(e===t)return!0;if(!e||!t||e.captures.length!==t.captures.length)return!1;for(let n=0;n<e.captures.length;n+=1){let r=e.captures[n],i=t.captures[n];if(!r||!i||r.layer!==i.layer||r.binding!==i.binding||r.index!==i.index||r.parts.length!==i.parts.length)return!1;for(let e=0;e<r.parts.length;e+=1)if(r.parts[e]?.match!==i.parts[e]?.match)return!1;let a=r.patterns??[],o=i.patterns??[];if(a.length!==o.length)return!1;for(let e=0;e<a.length;e+=1){let t=a[e],n=o[e];if(!t||!n||t.name!==n.name||t.values.length!==n.values.length)return!1;for(let e=0;e<t.values.length;e+=1)if(!Object.is(t.values[e],n.values[e]))return!1}}return!0}function na(e){let t=e.parts.at(-1);if(!t||e.parts.length<=1)return;let n=e.index-1,r=e.patterns;if(t.patternName){let i=r?.at(-1);i?.name===t.patternName&&(i.values.length>1?(n=e.index,r=[...(r??[]).slice(0,-1),{...i,values:i.values.slice(0,-1),parts:i.parts.slice(0,-1)}]):r=(r??[]).slice(0,-1))}return{layer:e.layer,binding:e.binding,index:n,parts:e.parts.slice(0,-1),patterns:r}}function ra(e){let t=e.captures[0];if(!t||t.parts.length===0)return[];let n=[];for(let r=0;r<t.parts.length;r+=1){let i=t.parts[r];if(!i)continue;let a,o,s=!1,c=!1;for(let t of e.captures){let e=t.parts[r];if(e){if(a===void 0){a=e.display,o=e.tokenName;continue}!s&&a!==e.display&&(s=!0),!c&&o!==e.tokenName&&(c=!0)}}(a===void 0||s)&&(a=hi(i.stroke)),c&&(o=void 0),n.push(li(i.stroke,{display:a,match:i.match,tokenName:o}))}return n}function ia(e){if(e.isDestroyed)throw Error(`Cannot use a keymap after its host was destroyed`);return e}function aa(e,t,n,r,i,a,o={}){let s=Zi(),c=-1,l=[],u=()=>ia(t).getFocusedTarget(),d=()=>bi(t),f=t=>{let n=e.pending;ta(n,t)||(e.pending=t,o.onPendingSequenceChanged?.(n,t),re(),r.queueStateChange())},p=()=>{let t=e.pending;if(!t)return;let n=u(),r=a.getActiveCommandView(n),o=t.captures.filter(t=>e.layers.has(t.layer)&&ee(t.layer,n)&&i.matchesConditions(t.layer)&&te(t.binding,n,r)&&Oi(t,e.patterns));if(o.length===0){f(null);return}return o.length!==t.captures.length&&f({captures:o}),e.pending??void 0},m=()=>{t.isDestroyed||!e.pending||p()},h=()=>!t.isDestroyed&&e.pending!==null,g=()=>{if(c===e.cacheVersion)return l;let t=p(),n=t?ra(t):[];return(!t||w())&&(c=e.cacheVersion,l=n),n},_=()=>{let e=p();if(!e)return!1;let t=e.captures[0];if(!t||t.parts.length<=1)return f(null),!0;let n=[];for(let t of e.captures){let e=na(t);e&&n.push(e)}return n.length===0?(f(null),!0):(f({captures:n}),!0)},v=t=>{let n=t?.includeBindings===!0,r=t?.includeMetadata===!0,i=Qi(s,t);return i.notifyVersion===e.derivedVersion?i.value:y(i,n,r)},y=(n,r,i)=>{t.isDestroyed&&ia(t);let o=u(),s=$i(n,e.cacheVersion,o);if(s)return n.notifyVersion=e.derivedVersion,n.version=e.cacheVersion,n.focused=o,n.value=s.value,s.value;let c=a.getActiveCommandView(o),l=p(),d=l?[]:S(o),f=l?N(l.captures,r,i,o,c):k(d,r,i,o,c);return(l?w():C(d))&&(n.version=e.cacheVersion,n.notifyVersion=e.derivedVersion,n.focused=o,n.value=f,ea(n,e.cacheVersion,o,f)),f},b=(e,t)=>{let n=t?.includeBindings===!0,r=t?.includeMetadata===!0,i=u(),o=a.getActiveCommandView(i);return N(e,n,r,i,o)},x=(e,t)=>{let n=t?.includeBindings===!0,r=t?.includeMetadata===!0,i=e===d()?p():void 0,o=a.getActiveCommandView(e);return i?N(i.captures,n,r,e,o):k(S(e),n,r,e,o)},S=n=>e.activeLayersCacheVersion===e.cacheVersion&&e.activeLayersCacheFocused===n?e.activeLayersCache:(e.activeLayersCacheVersion=e.cacheVersion,e.activeLayersCacheFocused=n,e.activeLayersCache=Ci(e.sortedLayers,t,n),e.activeLayersCache),ee=(e,n)=>Ti(t,e,n),C=t=>!e.commandResolvers.has()&&e.activeKeyCacheBlockers===0,w=()=>!e.commandResolvers.has()&&e.activeKeyCacheBlockers===0,T=(e,t,n)=>{let r=[];for(let o of e)i.matchesConditions(o)&&a.isBindingVisible(o,t,n)&&r.push(o);return r},te=(e,t,n)=>i.matchesConditions(e)&&a.isBindingVisible(e,t,n),E=(e,t)=>{let n,r,i=!1,a=!1;for(let o of e){let e=o.sequence[t];if(e){if(n===void 0){n=e.display,r=e.tokenName;continue}!i&&n!==e.display&&(i=!0),!a&&r!==e.tokenName&&(a=!0)}}if(n===void 0||i){let r=e[0]?.sequence[t]?.stroke;n=r?hi(r):``}return a&&(r=void 0),{display:n,tokenName:r}},D=(e,t,n)=>({sequence:e.sequence,command:e.command,commandAttrs:a.getBindingCommandAttrs(e,t,n),attrs:e.attrs,event:e.event,preventDefault:e.preventDefault,fallthrough:e.fallthrough}),O=(e,t,n)=>e.map(e=>D(e,t,n)),k=(e,t,n,r,a)=>{let o=new Map,s=new Set;for(let n of e)n.root.children.size===0&&n.root.patternChildren.length===0||!i.matchesConditions(n)||(A(n.root.children.values(),o,s,t,r,a),A(n.root.patternChildren,o,s,t,r,a));return I(o,t,n,r,a)},A=(e,t,n,r,i,a)=>{for(let o of e){let e=o.match;if(!e||n.has(e)||!o.stroke)continue;let s=j(o,r,i,a);if(!s)continue;let c=t.get(e);c?B(c,s,r):t.set(e,ne(o.stroke,s,r)),s.stop&&n.add(e)}},j=(e,t,n,r)=>{if(!(e.children.size>0||e.patternChildren.length>0)){let i=z(M(e)?T(e.bindings,n,r):e.bindings,n,r);if(!i)return;let a=E(i.bindings,e.depth-1);return{display:a.display,tokenName:a.tokenName,continues:!1,firstBinding:i.bindings[0],commandBinding:i.commandBinding,bindings:t?[...i.bindings]:void 0,stop:i.stop}}let i=T(e.reachableBindings,n,r);if(i.length===0)return;let a=z(e.bindings,n,r),o=E(i,e.depth-1);return{display:o.display,tokenName:o.tokenName,continues:!0,firstBinding:a?.bindings[0],commandBinding:a?.commandBinding,bindings:t&&a?[...a.bindings]:void 0,stop:!0}},M=t=>{if(e.commandResolvers.has())return!0;for(let e of t.bindings)if(e.matchers.length>0)return!0;return!1},N=(t,n,r,i,a)=>{let o=new Map,s=new Set;return P(Mi(t,e.patterns),o,s,n,i,a),I(o,n,r,i,a)},P=(e,t,n,r,i,a)=>{let o=new Set;for(let s of e)o.has(s.part.match)||(o.add(s.part.match),F(s,e,t,n,r,i,a))},F=(e,t,n,r,i,a,o)=>{let s=e.part.match;if(r.has(s))return;let c=L(e,t,i,a,o);if(!c)return;let l=n.get(s);l?B(l,c,i):n.set(s,ne(e.part.stroke,c,i)),c.stop&&r.add(s)},I=(e,t,n,r,i)=>{let a=[];for(let o of e.values()){let e=V(o,t,n,r,i);e&&a.push(e)}return a},L=(e,t,n,r,i)=>{let a=t.filter(t=>t.part.match===e.part.match),o=a.filter(e=>e.exact).map(e=>e.binding),s=z(o,r,i),c=a.some(e=>e.continues);if(!c&&!s)return;let l=R(a);return{display:l.display,tokenName:l.tokenName,continues:c,firstBinding:s?.bindings[0],commandBinding:s?.commandBinding,bindings:n&&s?[...s.bindings]:void 0,stop:c||s?.stop===!0}},R=e=>{let t,n,r=!1,i=!1;for(let a of e){let e=a.part;if(t===void 0){t=e.display,n=e.tokenName;continue}!r&&t!==e.display&&(r=!0),!i&&n!==e.tokenName&&(i=!0)}let a=e[0]?.part;return(t===void 0||r)&&(t=a?hi(a.stroke):``),i&&(n=void 0),{display:t,tokenName:n}},z=(e,t,n)=>{let r=[],o;for(let s of e)if(!(!i.matchesConditions(s)||!a.isBindingVisible(s,t,n))&&(r.push(s),s.command!==void 0&&(o??=s,!s.fallthrough)))return{bindings:r,commandBinding:o,stop:!0};if(r.length!==0)return{bindings:r,commandBinding:o,stop:!1}},ne=(e,t,n)=>({stroke:e,display:t.display,tokenName:t.tokenName,continues:t.continues,firstBinding:t.firstBinding,commandBinding:t.commandBinding,bindings:n&&t.bindings?[...t.bindings]:void 0}),B=(e,t,n)=>{if(!e.firstBinding&&t.firstBinding&&(e.firstBinding=t.firstBinding),!e.commandBinding&&t.commandBinding&&(e.commandBinding=t.commandBinding),t.continues&&(e.continues=!0),!(!n||!t.bindings||t.bindings.length===0)){if(!e.bindings){e.bindings=[...t.bindings];return}e.bindings.push(...t.bindings)}},V=(e,t,n,r,i)=>{if(!e.commandBinding&&!e.continues)return;let o={stroke:ci(e.stroke),display:e.display,continues:e.continues};if(e.tokenName&&(o.tokenName=e.tokenName),e.commandBinding&&(o.command=e.commandBinding.command),t&&e.bindings&&e.bindings.length>0&&(o.bindings=e.bindings.length===1?[D(e.bindings[0],r,i)]:O(e.bindings,r,i)),n){e.firstBinding?.attrs&&(o.bindingAttrs=e.firstBinding.attrs);let t=e.commandBinding?a.getBindingCommandAttrs(e.commandBinding,r,i):void 0;t&&(o.commandAttrs=t)}return o},re=()=>{n.has(`pendingSequence`)&&n.emit(`pendingSequence`,e.pending?ra(e.pending):[])};return{getFocusedTarget:u,getFocusedTargetIfAvailable:d,setPendingSequence:f,ensureValidPendingSequence:p,revalidatePendingSequenceIfNeeded:m,hasPendingSequenceState:h,getPendingSequence:g,popPendingSequence:_,getActiveKeys:v,getActiveKeysForCaptures:b,getActiveKeysForFocused:x,getActiveLayers:S,isLayerActiveForFocused:ee,collectSequencePartsFromPending:ra,collectMatchingBindings:T,collectActiveBindings:O}}var oa=new Set([`name`,`run`,`fields`,`attrs`,`rejectedResult`]),sa=new Set([`key`,`cmd`,`event`,`preventDefault`,`fallthrough`]),ca=new Set([`target`,`targetMode`,`priority`,`bindings`,`commands`]);function la(e){if(e===void 0||typeof e==`function`)return e;let t=e.trim();if(!t)throw Error(`Invalid keymap command: command cannot be empty`);return t}function ua(e){let t=e.trim();if(!t)throw Error(`Invalid keymap command name: name cannot be empty`);if(/\s/.test(t))throw Error(`Invalid keymap command name "${e}": command names cannot contain whitespace`);return t}function da(e,t,n){let r=e.get(t);r?r.push(n):e.set(t,[n])}function fa(e){let t=[],n=new Map;for(let r of e.layers)for(let e of r.commands){let i={layer:r,commandState:e};t.push(i),da(n,e.command.name,i)}return{entries:t,chainsByName:n}}function pa(e,t,n){let r=[],i=[],a=new Map,o=new Map;for(let s of e)if(s.commands.length!==0&&!(n&&!t.matchesConditions(s)))for(let e of s.commands){if(!t.matchesConditions(e))continue;let n={layer:s,commandState:e};r.push(n),da(o,e.command.name,n),a.has(e.command.name)||(a.set(e.command.name,n),i.push(n))}return{layers:e,entries:r,reachable:i,reachableByName:a,chainsByName:o}}function ma(e,t,n,r){return(e.activeLayersCacheVersion!==e.cacheVersion||e.activeLayersCacheFocused!==r)&&(e.activeLayersCacheVersion=e.cacheVersion,e.activeLayersCacheFocused=r,e.activeLayersCache=Ci(e.sortedLayers,t,r)),pa(e.activeLayersCache,n,!0)}function ha(e,t,n,r){if(Object.prototype.hasOwnProperty.call(e,t)&&!Object.is(e[t],n))throw Error(`Conflicting keymap requirement for "${t}" from ${r}`);e[t]=n}function ga(e,t,n,r){if(Object.prototype.hasOwnProperty.call(e,t)&&!Object.is(e[t],n))throw Error(`Conflicting keymap attribute for "${t}" from ${r}`);e[t]=n}function _a(e){let t=`field ${e.fieldName}`;return{require(n,r){ha(e.requirements,n,r,t)},attr(n,r){if(!e.attrs)throw Error(`Keymap ${t} cannot publish attrs`);ga(e.attrs,n,r,t)},activeWhen(n){e.matchers.push(e.conditions.buildRuntimeMatcher(n,t))}}}function va(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function ya(e,t){return e instanceof Error&&e.message?e.message:t}function ba(e){return!e||typeof e!=`object`&&typeof e!=`function`?!1:typeof e.then==`function`}function xa(e,t){let n=t?.deep===!0,r=t?.freeze===!0,i=t?.preserveNonPlainObjects===!0;if(Array.isArray(e)){let i=n?e.map(e=>xa(e,t)):[...e];return r?Object.freeze(i):i}if(e&&typeof e==`object`){if(i&&!va(e))return e;let a={};for(let[r,i]of Object.entries(e))a[r]=n?xa(i,t):i;return r?Object.freeze(a):a}return e}var Sa=[`name`],Ca=Object.freeze({}),wa=new WeakMap;function Ta(e,t,n,r,i){let a=-1,o,s=-1,c,l,u=-1,d,f,p=-1,m,h=-1,g=new Map,_=t=>Da({commands:t,commandFields:e.commandFields,conditions:r,onError:(e,t,r)=>{n.emitError(e,t,r)}}),v=t=>I(()=>e.commandResolvers.prepend(t),t),y=t=>I(()=>e.commandResolvers.append(t),t),b=()=>{e.commandResolvers.has()&&n.runWithStateChangeBatch(()=>{e.commandResolvers.clear(),i.onCommandResolversChanged(),n.queueStateChange()})},x=e=>U(e).map(e=>Ea(e.commandState)),S=e=>{let t=H(e),n=U(e,t);if(n.length===0)return[];let r=n.map(e=>({entry:e,command:Ea(e.commandState),commandAttrs:e.commandState.attrs,bindings:[]})),i=new Map;for(let[e,t]of r.entries()){let n=i.get(t.command.name);n?n.push(e):i.set(t.command.name,[e])}return i.size>0&&ie(r,i,t),r.map(e=>({command:e.command,bindings:e.bindings}))},ee=t=>{if(t.visibility===`registered`&&u===e.derivedVersion&&d===t.commands&&f)return f;let n=new Map;for(let e of t.commands)n.has(e)||n.set(e,[]);return n.size===0?n:(W(n,H(t)),t.visibility===`registered`&&(u=e.derivedVersion,d=t.commands,f=n),n)},C=(e,t,n)=>{let r=A(t);if(n){let i=[],a=r.chainsByName.get(e);if(a)for(let e of a)i.push({target:e.layer.target,command:e.commandState.command,attrs:e.commandState.attrs,payload:n.payload});let o=G(e,t,{mode:`active`,execution:n});return o.resolved&&i.push(o.resolved),{entries:i.length>0?i:void 0,hadError:o.hadError}}let i=[];for(let t of r.chainsByName.get(e)??[])i.push({target:t.layer.target,command:t.commandState.command,attrs:t.commandState.attrs});let a=G(e,t,{mode:`active`});return a.resolved&&i.push(a.resolved),{entries:i.length>0?i:void 0,hadError:a.hadError}},w=t=>{if(h!==e.derivedVersion&&(h=e.derivedVersion,g=new Map),g.has(t))return g.get(t)??void 0;let n=ne(z(t));return g.set(t,n??null),n},T=(e,t)=>ne(A(t).chainsByName.get(e)),te=(e,t)=>G(e,null,{mode:`registered`,execution:t}),E=(e,t,n)=>G(e,t,{mode:`active`,execution:n}),D=(e,t)=>L(e,t)?.command,O=e=>R(e)?.commandState.command,k=(e,n,i)=>{let a=j().chainsByName.get(e);if(!a||a.length===0)return;let o,s;for(let e of a){if(!Ti(t,e.layer,n)){o??=e;continue}(!r.matchesConditions(e.layer)||!r.matchesConditions(e.commandState))&&(s??=e)}let c=s??o;if(c)return{reason:s?`disabled`:`inactive`,command:i?c.commandState.command:void 0}},A=n=>{if(s===e.derivedVersion&&c===n&&l)return l;let i=ma(e,t,r,n);return M()&&(s=e.derivedVersion,c=n,l=i),i},j=()=>a===e.derivedVersion&&o?o:(a=e.derivedVersion,o=fa(e),o),M=()=>e.activeCommandViewCacheBlockers===0,N=(e,t,n)=>e.command===void 0||e.run?!0:typeof e.command==`string`?n.reachableByName.has(e.command)?!0:B(e.command,t,`active`)!==void 0:!1,P=(e,t,n)=>{if(typeof e.command!=`string`)return;let r=n.reachableByName.get(e.command);return r?r.commandState.attrs:B(e.command,t,`active`)?.attrs},F=(e,n)=>{if(n?.some(t=>t.command.name===e)||j().chainsByName.has(e))return`resolved`;let r=G(e,bi(t));return r.resolved||r.hadError?r.resolved?`resolved`:`error`:`unresolved`},I=(t,r)=>n.runWithStateChangeBatch(()=>{let a=t();return i.onCommandResolversChanged(),n.queueStateChange(),()=>{n.runWithStateChangeBatch(()=>{a(),!e.commandResolvers.values().includes(r)&&(i.onCommandResolversChanged(),n.queueStateChange())})}}),L=(e,t)=>{let n=A(t).reachableByName.get(e);return n?{target:n.layer.target,command:n.commandState.command,attrs:n.commandState.attrs}:B(e,t,`active`)},R=e=>z(e)?.[0],z=t=>{let n=[];for(let r of e.sortedLayers)for(let e of r.commands)e.command.name===t&&n.push({layer:r,commandState:e});return n.length>0?n:void 0},ne=e=>{if(e?.length)return e.map(e=>({target:e.layer.target,command:e.commandState.command,attrs:e.commandState.attrs}))},B=(e,t,n)=>G(e,t,{mode:n}).resolved,V=()=>j().entries,re=()=>{if(p===e.derivedVersion&&m)return m;let t=new Map;for(let n of e.layers)for(let e of n.bindings){if(typeof e.command!=`string`)continue;let n=t.get(e.command);n?n.push(e):t.set(e.command,[e])}return p=e.derivedVersion,m=t,t},H=e=>{let n=e?.visibility??`reachable`,r=e&&Object.prototype.hasOwnProperty.call(e,`focused`)?e.focused??null:bi(t);return n===`registered`?{visibility:n,focused:r}:{visibility:n,focused:r,activeView:A(r)}},U=(e,t=H(e))=>{let r;return r=t.visibility===`registered`?V():t.visibility===`active`?t.activeView?.entries??[]:t.activeView?.reachable??[],Ma({entries:r,query:e,getCommand:e=>Ea(e),onFilterError:e=>{n.emitError(`command-query-filter-error`,e,`[Keymap] Error in command query filter:`)}})},ie=(e,t,n)=>{ae(n,n=>{oe(e,t,n)})},W=(e,t)=>{if(t.visibility===`registered`){let t=re();for(let[n,r]of e){let e=j().chainsByName.get(n)?.[0]?.commandState.attrs;for(let i of t.get(n)??[])r.push(ce(i,e))}return}ae(t,n=>{se(e,n,t)})},ae=(t,n)=>{if(t.visibility===`registered`){for(let t of e.layers)for(let e of t.bindings)n(e);return}let i=t.activeView;if(i){for(let e of i.layers)if(!(e.bindings.length===0||!r.matchesConditions(e)))for(let a of e.bindings)r.matchesConditions(a)&&N(a,t.focused,i)&&n(a)}},oe=(e,t,n)=>{if(typeof n.command!=`string`)return;let r=t.get(n.command);if(!(!r||r.length===0))for(let t of r){let r=e[t];r&&r.bindings.push(ce(n,r.commandAttrs))}},se=(e,t,n)=>{if(typeof t.command!=`string`)return;let r=e.get(t.command);r&&r.push(ce(t,le(t,n)))},ce=(e,t)=>({sequence:e.sequence,command:e.command,commandAttrs:t,attrs:e.attrs,event:e.event,preventDefault:e.preventDefault,fallthrough:e.fallthrough}),le=(e,t)=>{if(typeof e.command!=`string`)return;if(t.visibility===`registered`)return j().chainsByName.get(e.command)?.[0]?.commandState.attrs;let n=t.activeView;if(n)return P(e,t.focused,n)},G=(t,r,i)=>{let a=i?.mode??`active`,o=i?.execution??{input:t},s=Oa(t,e.commandResolvers.values(),()=>fe(r,a,o),e=>{n.emitError(`command-resolver-error`,e,`[Keymap] Error in command resolver for "${t}":`)}),c=s.resolved;if(c){let e=de(c.command.name,r,a);e?.commandState.command===c.command&&c.target===void 0&&(c={...c,target:e.layer.target},s.resolved=c)}if(c&&!c.attrs){let e=ue(c.command.name,r,a)??ja(c.command);e&&(s.resolved={...c,attrs:e})}return s},ue=(e,t,n)=>n===`registered`?R(e)?.commandState.attrs:A(t).reachableByName.get(e)?.commandState.attrs,de=(e,t,n)=>n===`registered`?R(e):A(t).reachableByName.get(e),fe=(e,t,n)=>{let r=n.input,i=n.payload;return{context:{get input(){return r},get payload(){return i},setInput(e){r=e},setPayload(e){i=e},getCommand:n=>t===`registered`?O(n):D(n,e)},getExecutionFields(){return{input:r,payload:i}}}};return{normalizeCommands:_,prependCommandResolver:v,appendCommandResolver:y,clearCommandResolvers:b,getCommands:x,getCommandEntries:S,getCommandBindings:ee,getResolvedCommandChain:C,getRegisteredResolvedEntries:w,getActiveRegisteredResolvedEntries:T,resolveRegisteredResolverFallback:te,resolveActiveResolverFallback:E,getTopCommand:D,getDispatchUnavailableCommandState:k,getActiveCommandView:A,isBindingVisible:N,getBindingCommandAttrs:P,getCommandResolutionStatus:F}}function Ea(e){return e.command}function Da(e){let t=[],n=new Set;for(let r of e.commands)try{let i={},a=[],o=ua(r.name),s=ka(r),c={};if(n.has(o)){e.onError(`duplicate-command`,{command:o},`Duplicate keymap command "${o}" in the same layer`);continue}r.name=o;for(let[t,n]of Object.entries(s)){if(n===void 0)continue;let r=e.commandFields.get(t);r&&r(n,_a({fieldName:t,conditions:e.conditions,requirements:i,matchers:a,attrs:c}))}let l={command:r,fields:s,attrs:Object.keys(c).length===0?void 0:c,requires:Object.entries(i),matchers:a};n.add(l.command.name),t.push(l)}catch(t){e.onError(`register-command-failed`,t,ya(t,`Failed to register keymap command "${String(r.name)}"`));continue}return t}function Oa(e,t,n,r){if(t.length===0)return{hadError:!1};let i=!1;for(let a of t){let t,o=n();try{t=a(e,o.context)}catch(e){i=!0,r(e);continue}if(t)return{hadError:i,resolved:Aa(t,o.getExecutionFields())}}return{hadError:i}}function ka(e){let t={};for(let[n,r]of Object.entries(e))!oa.has(n)&&r!==void 0&&(t[n]=r);return Object.keys(t).length===0?Ca:t}function Aa(e,t){return{command:e,input:t.input,payload:t.payload}}function ja(e){let t=ka(e);return t===Ca?void 0:t}function Ma(e){let t=e.query?.namespace,n=Na(e.query?.limit);if(n===0)return[];let r=e.query?.search?.trim().toLowerCase()??``,i=Sa;e.query?.searchIn&&e.query.searchIn.length>0&&(i=e.query.searchIn);let a=e.query?.filter,o,s,c;if(typeof a==`function`)s=a;else if(a){let e=Object.entries(a),t=[];for(let[n,r]of e){if(n===`name`){if(typeof r==`string`){c=new Set([r]);continue}if(Array.isArray(r)){let e=new Set;for(let t of r)typeof t==`string`&&e.add(t);c=e;continue}}t.push([n,r])}o=t.length>0?t:void 0}let l=[];for(let a of e.entries){let u=a.commandState;if(Fa(u,t)&&Pa(u,r,i)&&!(c&&!c.has(u.command.name))&&Ia(u,o,e)){if(s){let t=!1;try{t=s(e.getCommand(u))}catch(t){e.onFilterError(t);continue}if(!t)continue}if(l.push(a),n!==void 0&&l.length>=n)break}}return l}function Na(e){if(e===void 0)return;let t=Math.floor(Number(e));return!Number.isFinite(t)||t<=0?0:t}function Pa(e,t,n){if(!t)return!0;for(let r of n)if(La(e,r,t))return!0;return!1}function Fa(e,t){if(t===void 0)return!0;let n=e.fields;return Object.prototype.hasOwnProperty.call(n,`namespace`)?Wa(n.namespace,t):!1}function Ia(e,t,n){if(!t)return!0;for(let[r,i]of t)if(!Va(e,r,i,n))return!1;return!0}function La(e,t,n){return Ra(e,t)?.includes(n)===!0}function Ra(e,t){let n=wa.get(e);if(n||(n=new Map,wa.set(e,n)),n.has(t))return n.get(t);let r=e.fields,i=e.attrs,a;t===`name`?a=e.command.name:Object.prototype.hasOwnProperty.call(r,t)?a=r[t]:i&&Object.prototype.hasOwnProperty.call(i,t)&&(a=i[t]);let o=za(a);return n.set(t,o),o}function za(e){if(Array.isArray(e)){let t=[];for(let n of e){let e=za(n);e!==void 0&&t.push(e)}return t.length>0?t.join(`\0`):void 0}if(typeof e==`string`)return e.toLowerCase();if(typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`)return String(e).toLowerCase()}function Ba(e,t,n,r){try{return e(t,n)}catch(e){return r(e),!1}}function Va(e,t,n,r){return typeof n==`function`?Ha(e,t,n,r):Ua(e,t,n)}function Ha(e,t,n,r){let i=e.command,a=e.fields,o=e.attrs,s,c=!1,l=()=>s??=r.getCommand(e);return t===`name`&&(c=!0,Ba(n,i.name,l(),r.onFilterError))||Object.prototype.hasOwnProperty.call(a,t)&&(c=!0,Ba(n,a[t],l(),r.onFilterError))||o&&Object.prototype.hasOwnProperty.call(o,t)&&(c=!0,Ba(n,o[t],l(),r.onFilterError))?!0:!c&&Ba(n,void 0,l(),r.onFilterError)}function Ua(e,t,n){let r=e.command,i=e.fields,a=e.attrs;return t===`name`&&Wa(r.name,n)||Object.prototype.hasOwnProperty.call(i,t)&&Wa(i[t],n)?!0:!!a&&Object.prototype.hasOwnProperty.call(a,t)&&Wa(a[t],n)}function Wa(e,t){return Array.isArray(t)?t.some(t=>Ga(e,t)):Ga(e,t)}function Ga(e,t){return Array.isArray(e)?e.some(e=>Ga(e,t)):Object.is(e,t)}function Ka(e,t,n,r,i){let a=(e,t,n,r,a,o)=>({keymap:i.keymap,event:e,focused:t,target:n,data:r,input:a,payload:o}),o=(t,n,r,i)=>{let a=typeof n==`function`?void 0:n,o=typeof n==`function`?n:n.run,s=i?a:void 0,c;try{c=o(a?{...r,command:a}:r)}catch(n){return e.emitError(`command-execution-error`,n,`[Keymap] Error running command "${t}":`),{status:`error`,result:s?{ok:!1,reason:`error`,command:s}:{ok:!1,reason:`error`}}}if(ba(c))return c.catch(n=>{e.emitError(`async-command-error`,n,`[Keymap] Async error in command "${t}":`)}),{status:`handled`,result:s?{ok:!0,command:s}:{ok:!0}};if(qa(c)){let e=c;return(!c.ok&&c.reason!==`not-found`&&i&&a&&!c.command||c.ok&&i&&a&&!c.command)&&(e={...c,command:a}),{status:c.ok?`handled`:`rejected`,result:e}}return c===!1?{status:`rejected`,result:s?{ok:!1,reason:`rejected`,command:s}:{ok:!1,reason:`rejected`}}:{status:`handled`,result:s?{ok:!0,command:s}:{ok:!0}}},s=(e,t,n,r,i,s,c,l)=>{let u;for(let d of t??[]){let t=o(e,d.command,a(n,r,i??d.target??null,s,e,c),l);if(t.status===`handled`||t.status===`error`)return[t.result,u];u=t.result}return[void 0,u]},c=(e,c,l)=>{let u;try{u=la(e)}catch{return{ok:!1,reason:`invalid-args`}}if(typeof u!=`string`)return{ok:!1,reason:`not-found`};let d=c?.includeCommand===!0,f=c?.focused??n.getFocusedTargetIfAvailable(),p=c?.event??i.createCommandEvent(),m=t.getReadonlyData(),h=c?.payload,g=l===`registered`?r.getRegisteredResolvedEntries(u):r.getActiveRegisteredResolvedEntries(u,f),[_,v]=s(u,g,p,f,c?.target,m,h,d);if(_)return _;let y=v,b=l===`registered`?r.resolveRegisteredResolverFallback(u,{input:u,payload:h}):r.resolveActiveResolverFallback(u,f,{input:u,payload:h});if(b.resolved){let e=o(u,b.resolved.command,a(p,f,c?.target??b.resolved.target??null,m,b.resolved.input??u,b.resolved.payload),d);if(e.status===`handled`||e.status===`error`)return e.result;y=e.result}if(b.hadError)return{ok:!1,reason:`error`};if(l===`active`){let e=r.getDispatchUnavailableCommandState(u,f,d);if(e)return e.command?{ok:!1,reason:e.reason,command:e.command}:{ok:!1,reason:e.reason}}return y??{ok:!1,reason:`not-found`}};return{runCommand(e,t){return c(e,t,`registered`)},dispatchCommand(e,t){return c(e,t,`active`)},runBinding(e,n,i,s,c){let l=t.getReadonlyData();if(n.run)return o(typeof n.command==`string`?n.command:`<function>`,n.run,a(i,s,e.target??null,l,typeof n.command==`string`?n.command:`<function>`,c),!1).status!==`rejected`&&(Ja(n,i),!0);if(typeof n.command!=`string`)return!1;let u=r.getResolvedCommandChain(n.command,s,c===void 0?void 0:{input:n.command,payload:c}).entries;for(let t of u??[])if(o(n.command,t.command,a(i,s,t.target??e.target??null,l,t.input??n.command,t.payload),!1).status!==`rejected`)return Ja(n,i),!0;return!1}}}function qa(e){return typeof e==`object`&&!!e&&`ok`in e}function Ja(e,t){e.preventDefault&&(t.preventDefault(),t.stopPropagation())}var Ya=Object.freeze({}),Xa=[],Za=[];function Qa(e){if(Object.keys(e).length!==0)return xa(e,{freeze:!0})}function $a(e,t,n,r){let i=t=>ao(t,e.bindingParsers.values(),{tokens:e.tokens,patterns:e.patterns,layer:Ya,parseObjectKey:(e,t)=>c(e,t)}),a=t=>{if(typeof t!=`string`)return[c(t)];let n=io(t,e.bindingParsers.values(),{tokens:e.tokens,patterns:e.patterns,layer:Ya,parseObjectKey:(e,t)=>c(e,t)});for(let e of n.unknownTokens)r.warnUnknownToken(e,t);return n.unknownTokens.length>0?[]:n.parts},o=(e,t)=>gi(a(e),t),s=(i,a,o,s,d)=>{let f=[],p=!1,m=e.bindingExpanders.values(),h=e.bindingParsers.values(),g=e.bindingFields,_=e.disambiguationResolvers.has(),v=r.warnUnknownField,y=r.warnUnknownToken;for(let[r,b]of i.entries()){let i;try{i=no(b.key,m,{layer:d})}catch(e){t.emitError(`binding-expand-error`,e,ya(e,`Failed to expand keymap binding`));continue}for(let m of i){let i=m.key,x;try{x=typeof i==`string`?io(i,h,{tokens:a,patterns:e.patterns,layer:d,parseObjectKey:(e,t)=>c(e,t)}):{parts:[c(i)],usedTokens:[],unknownTokens:[],hasTokenBindings:!1},x=ro(x,m)}catch(e){t.emitError(`binding-parse-error`,e,ya(e,`Failed to parse keymap binding`));continue}let S=x.parts;p||=x.hasTokenBindings;for(let e of x.unknownTokens)y(e,typeof i==`string`?i:String(i.name));if(!(x.unknownTokens.length>0))for(let i of u(b,S,a,h,d))try{let t=l(i.event),a=i.sequence,c={},u={},d=[];for(let e in i){if(e===`sequence`||sa.has(e))continue;let t=i[e];if(t===void 0)continue;let r=g.get(e);if(!r){v(`binding`,e);continue}r(t,_a({fieldName:e,conditions:n,requirements:c,matchers:d,attrs:u}))}let p=Object.keys(u).length>0?Qa(u):void 0,m=la(i.cmd),h={binding:b,sequence:a,command:m,event:t,parsedBinding:Gi(i),sourceTarget:o,sourceLayerOrder:s,bindingIndex:r,requires:Object.keys(c).length>0?Object.entries(c):Xa,matchers:d.length>0?d:Za,preventDefault:i.preventDefault!==!1,fallthrough:i.fallthrough??!1};if(p&&(h.attrs=p),typeof m==`function`&&(h.run=m),a.length===0)continue;if(t===`release`&&a.length>1)throw Error(`Keymap release bindings only support a single key stroke`);let y=a.at(-1);if(y?.patternName){let t=e.patterns.get(y.patternName);if(t&&t.max!==t.min)throw Error(`Keymap unbounded sequence patterns must be followed by a concrete continuation`)}t===`press`&&!_&&to(f,h),f.push(h)}catch(e){t.emitError(`binding-compile-error`,e,ya(e,`Failed to compile keymap binding`))}}}return{bindings:f,hasTokenBindings:p}},c=(e,t)=>li(e,t),l=e=>{if(e===void 0||e===`press`)return`press`;if(e===`release`)return`release`;throw Error(`Invalid keymap binding event "${String(e)}": expected "press" or "release"`)},u=(n,r,i,a,o)=>{let s=e.bindingTransformers.values();if(s.length===0)return[{...n,sequence:di(r)}];let l={...n,sequence:di(r)},u=[],d=!0,f=o??Ya;for(let n of s)try{n(l,{layer:f,parseKey:t=>ao(t,a,{tokens:i,patterns:e.patterns,layer:f,parseObjectKey:(e,t)=>c(e,t)}),add:e=>{u.push(Gi(e))},skipOriginal:()=>{d=!1}})}catch(e){t.emitError(`binding-transformer-error`,e,`[Keymap] Error in binding transformer:`)}return d?u.length===0?[l]:[l,...u]:u};return{parseTokenKey:i,parseKeySequence:a,formatKey:o,compileBindings:s}}function eo(e,t){if(e.length>=t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]?.match!==t[n]?.match)return!1;return!0}function to(e,t){for(let n of e)if(n.event===`press`&&(n.command!==void 0&&eo(n.sequence,t.sequence)||t.command!==void 0&&eo(t.sequence,n.sequence)))throw Error(`Keymap bindings cannot use the same sequence as both an exact match and a prefix in the same layer`)}function no(e,t,n){if(typeof e!=`string`||t.length===0)return[{key:e}];let r=n?.layer??Ya,i=[{key:e}];for(let e of t){let t=[];for(let n of i){let i=e({input:n.key,displays:n.displays,layer:r});if(!i){t.push(n);continue}if(i.length===0)throw Error(`Keymap binding expander must return at least one key sequence for "${n.key}"`);for(let e of i){if(!e||typeof e!=`object`||Array.isArray(e)||typeof e.key!=`string`)throw Error(`Keymap binding expander must return expansion objects with string keys for "${n.key}"`);if(e.displays!==void 0){if(!Array.isArray(e.displays))throw Error(`Keymap binding expander displays must be an array of strings for "${n.key}"`);for(let t of e.displays)if(typeof t!=`string`)throw Error(`Keymap binding expander displays must be an array of strings for "${n.key}"`)}t.push(e)}}i=t}return i}function ro(e,t){if(!t.displays)return e;if(t.displays.length!==e.parts.length)throw Error(`Keymap binding expansion displays length must match parsed sequence length for "${String(t.key)}"`);return{...e,parts:e.parts.map((e,n)=>({...e,display:t.displays[n]}))}}function io(e,t,n){if(e.length===0)throw Error(`Invalid key sequence: sequence cannot be empty`);if(t.length===0)throw Error(`No keymap binding parsers are registered`);let r=n.tokens??new Map,i=n.patterns??new Map,a=n.layer??Ya,o=n.parseObjectKey,s=[],c=new Set,l=new Set,u=0;for(;u<e.length;){let n=!1;for(let d of t){let t=d({input:e,index:u,layer:a,tokens:r,patterns:i,normalizeTokenName:ai,createMatch:mi,parseObjectKey:o});if(t){if(t.nextIndex<=u||t.nextIndex>e.length)throw Error(`Keymap binding parser must advance the input for "${e}" at index ${u}`);s.push(...t.parts);for(let e of t.usedTokens??[])c.add(e);for(let e of t.unknownTokens??[])l.add(e);u=t.nextIndex,n=!0;break}}if(!n)throw Error(`No keymap binding parser handled input at index ${u} in "${e}"`)}return{parts:s,usedTokens:[...c],unknownTokens:[...l],hasTokenBindings:c.size>0||l.size>0}}function ao(e,t,n){if(typeof e!=`string`)return n.parseObjectKey(e);let{parts:r}=io(e,t,n),[i]=r;if(!i||r.length!==1)throw Error(`Invalid key "${String(e)}": expected a single key stroke`);return i}function oo(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.get==`function`&&typeof t.subscribe==`function`}function so(e,t){let n=e=>e.requires.length===0&&e.matchers.length===0,r=e=>{try{return e.match()}catch(n){return t.emitError(`runtime-matcher-error`,n,`[Keymap] Error evaluating runtime matcher from ${e.source}:`),!1}},i=e=>{if(e.matchers.length===0)return!0;if(e.matchers.length===1){let[t]=e.matchers;return!t||r(t)}for(let t of e.matchers)if(!r(t))return!1;return!0},a=t=>{if(t.length===0)return!0;for(let[n,r]of t)if(!Object.is(e.data[n],r))return!1;return!0};return{buildRuntimeMatcher(e,t){if(typeof e==`function`)return{source:t,match:e};if(oo(e))return{source:t,match:()=>e.get(),subscribe:t=>e.subscribe(t)};throw Error(`Keymap ${t} expected a function or a reactive matcher`)},matchesConditions:e=>n(e)||a(e.requires)&&i(e)}}var co=Symbol(`keymap-disambiguation-decision`),lo=Symbol(`keymap-deferred-disambiguation-decision`);function uo(e,t){return{[co]:!0,action:e,handler:t}}function fo(e){return{[lo]:!0,action:e}}function po(e){return!!e&&typeof e==`object`&&e[co]===!0}function mo(e){return!!e&&typeof e==`object`&&e[lo]===!0}function ho(e,t){return t.aborted?Promise.resolve(!1):new Promise(n=>{let r=setTimeout(()=>{t.removeEventListener(`abort`,i),n(!0)},Math.max(0,e)),i=()=>{clearTimeout(r),t.removeEventListener(`abort`,i),n(!1)};t.addEventListener(`abort`,i,{once:!0})})}function go(e,t,n,r){let i=e.get(n);if(i)try{return i.matcher(r)}catch(e){t.emitError(`sequence-pattern-match-error`,e,`[Keymap] Error matching sequence pattern "${i.name}":`);return}}function _o(e,t,n,r){let i=e.get(n)?.payloadKey??n;return{...li({name:t.name,ctrl:t.ctrl,shift:t.shift,meta:t.meta,super:t.super??!1,hyper:t.hyper||void 0},{display:r.display??String(r.value??t.name)}),patternName:n,payloadKey:i}}function vo(e,t,n){if(!n?.patterns||n.patterns.length===0)return;let r={},i=!1;for(let a of n.patterns){let n=e.get(a.name),o;try{o=n?.finalize?n.finalize(a.values):a.values.length===1?a.values[0]:[...a.values]}catch(e){t.emitError(`sequence-pattern-finalize-error`,e,`[Keymap] Error finalizing sequence pattern "${a.name}":`);continue}let s=r[a.payloadKey];s===void 0?(r[a.payloadKey]=o,i=!0):Array.isArray(s)?s.push(o):r[a.payloadKey]=[s,o]}return i?r:void 0}function yo(e,t,n,r,i,a,o,s,c,l){let u={resolveKey:e=>o.parseTokenKey(e).match},d=null,f=0;function p(t,n,r){if(t===`key`){let t=r;return e.keyHooks.register(n,{priority:t?.priority??0,release:t?.release??!1})}if(t===`key:after`){let t=r;return e.keyAfterHooks.register(n,{priority:t?.priority??0,release:t?.release??!1})}let i=r;return e.rawHooks.register(n,{priority:i?.priority??0})}function m(t){return e.eventMatchResolvers.prepend(t)}function h(t){return e.eventMatchResolvers.append(t)}function g(){e.eventMatchResolvers.clear()}function _(t){return F(()=>e.disambiguationResolvers.prepend(t),t)}function v(t){return F(()=>e.disambiguationResolvers.append(t),t)}function y(){e.disambiguationResolvers.has()&&t.runWithStateChangeBatch(()=>{e.disambiguationResolvers.clear(),c.recompileBindings()})}function b(e,t){d&&ce()}function x(n){let r=e.rawHooks.entries();if(r.length===0)return!1;let i=!1,a={sequence:n,stop(){i=!0}};for(let e of r){try{e.listener(a)}catch(e){t.emitError(`raw-intercept-error`,e,`[Keymap] Error in raw intercept listener:`)}if(i)return!0}return!1}function S(e,t){return{sequence:di(e.sequence),command:e.command,commandAttrs:s.getBindingCommandAttrs(e,t,s.getActiveCommandView(t)),attrs:e.attrs,event:e.event,preventDefault:e.preventDefault,fallthrough:e.fallthrough,sourceLayerOrder:e.sourceLayerOrder,bindingIndex:e.bindingIndex}}function ee(e){l.has(`dispatch`)&&l.emit(`dispatch`,e)}function C(e,t,n,r){l.has(`dispatch`)&&ee({phase:e,event:n.event,focused:r,layer:{order:t.order,priority:t.priority,target:t.target,targetMode:t.targetMode},binding:S(n,r),sequence:di(n.sequence),command:n.command})}function w(e,t,n){if(!l.has(`dispatch`))return;let i=t[0],a=t.length>0?r.collectSequencePartsFromPending({captures:t}):[];ee({phase:e,event:`press`,focused:n,layer:i?{order:i.layer.order,priority:i.layer.priority,target:i.layer.target,targetMode:i.layer.targetMode}:void 0,sequence:a})}function T(t){let n=e.keyAfterHooks.entries();for(let e of n)if(e.release===t)return n}function te(e){return e.sequence?di(e.sequence):e.captures?r.collectSequencePartsFromPending({captures:e.captures}):[]}function E(e,t){return{handled:e!==`sequence-miss`,reason:e,captures:t}}function D(e,t){return{handled:t,reason:t?`binding-handled`:`binding-rejected`,sequence:e.sequence}}function O(e,t){return t.handled||e.reason===`no-match`?t:e}function k(e,i,a,o,s){let c={event:i,eventType:a?`release`:`press`,focused:o,handled:s.handled,reason:s.reason,sequence:te(s),pendingSequence:r.getPendingSequence(),setData:(e,t)=>{n.setData(e,t)},getData:e=>n.getData(e),consume:e=>{let t=e?.preventDefault??!0,n=e?.stopPropagation??!0;t&&i.preventDefault(),n&&i.stopPropagation()}};for(let n of e)if(n.release===a)try{n.listener(c)}catch(e){t.emitError(`key-after-intercept-error`,e,`[Keymap] Error in key:after intercept listener:`)}}function A(){return{handled:!1,reason:`no-match`}}function j(e){e.preventDefault(),e.stopPropagation()}function M(e,t,n,i){r.setPendingSequence({captures:t});let a=E(`sequence-pending`,t);return w(e,t,n),j(i),a}function N(e,t,n,i){let a=E(e,t);return w(`sequence-clear`,t,n),r.setPendingSequence(null),j(i),a}function P(i,a){a||ce();let o=T(a),s=o?r.getFocusedTarget():null,c=e.keyHooks.entries(),l={event:i,setData:(e,t)=>{n.setData(e,t)},getData:e=>n.getData(e),consume:e=>{let t=e?.preventDefault??!0,n=e?.stopPropagation??!0;t&&i.preventDefault(),n&&i.stopPropagation()}};for(let e of c)if(e.release===a){try{e.listener(l)}catch(e){t.emitError(`key-intercept-error`,e,`[Keymap] Error in key intercept listener:`)}if(i.propagationStopped){o&&k(o,i,a,s,{handled:!0,reason:`intercept-consumed`,sequence:[]});return}}if(a){let e=I(i);o&&k(o,i,a,s,e);return}let u=L(i);o&&k(o,i,a,s,u)}function F(n,r){return t.runWithStateChangeBatch(()=>{let i=e.disambiguationResolvers.has(),a=n();return!i&&e.disambiguationResolvers.has()&&c.recompileBindings(),()=>{t.runWithStateChangeBatch(()=>{let t=e.disambiguationResolvers.has();a(),!e.disambiguationResolvers.values().includes(r)&&t&&!e.disambiguationResolvers.has()&&c.recompileBindings()})}})}function I(e){let t=r.getFocusedTarget(),n=r.getActiveLayers(t),a=pe(e),o=A();for(let r of a)layerLoop:for(let a of n){if(a.bindings.length===0||!i.matchesConditions(a))continue;let n=me(a,r,e,t);if(o=O(o,n.outcome),n.handled){if(n.stop)return o;continue layerLoop}}return o}function L(e){let t=r.getFocusedTarget(),n=r.ensureValidPendingSequence(),i=pe(e);if(n)return R(n,i,e,t);let a=r.getActiveLayers(t),o=A();for(let n of i){let r=ne(a,[n],e,t);if(o=O(o,r),r.handled)return o}return o}function R(t,n,i,a){let o=s.getActiveCommandView(a),c=[];for(let r of t.captures){let t=Ii(r,n,i,e.patterns,K,he);t&&c.push(t)}let l=c.reduce((e,t)=>Math.min(e,Pi(t,n)),1/0),u=c.filter(e=>Pi(e,n)===l);if(u.length===0||!u.some(e=>ve(e,a,o))){let e=E(`sequence-miss`,t.captures);return w(`sequence-clear`,t.captures,a),r.setPendingSequence(null),e}return z(u,0,!1,i,a)}function z(t,n,i,a,o){let s=i,c=A(),l=new Set;for(let i=n;i<t.length;i+=1){let n=t[i];if(!n||l.has(n))continue;let u=de(t,i,n);if(u.length>0){if(s)continue;let e=fe(t,n);return re(t,i,u,e,a,o,s)||M(`sequence-advance`,u,o,a)}if(!ki(n,e.patterns))continue;let d=fe(t,n);for(let e of d)l.add(e);let f=ye(n.layer,d,a,o);if(c=O(c,f.outcome),f.handled&&(s=!0,f.stop))return w(`sequence-clear`,t,o),r.setPendingSequence(null),c}return w(`sequence-clear`,t,o),r.setPendingSequence(null),c}function ne(e,t,n,r){return B(e,0,t,n,r)}function B(t,n,r,a,o){let c=s.getActiveCommandView(o),l=A();for(let s=n;s<t.length;s+=1){let n=t[s];if(!n||!i.matchesConditions(n))continue;let u=ge(n,r,a,o,c);if(u.length===0)continue;if(u.filter(t=>Oi(t,e.patterns,!1)).length>0){let n=u.filter(t=>ki(t,e.patterns)),i=ue(t,s,r,a,o);return V(t,s,r,i,n,a,o)||M(`sequence-start`,i,o,a)}let d=ye(n,u.filter(t=>ki(t,e.patterns)),a,o);if(l=O(l,d.outcome),d.handled&&d.stop)return l}return l}function V(e,t,n,i,a,o,s){return H({event:o,focused:s,continuationCaptures:i,exactBindingsSource:a.map(e=>e.binding),sequencePhase:`sequence-start`,runExact:()=>{r.setPendingSequence(null);let i=a[0]?.layer;if(!i)return A();let c=ye(i,a,o,s);return c.stop?c.outcome:O(c.outcome,B(e,t+1,n,o,s))}})}function re(e,t,n,i,a,o,s){return H({event:a,focused:o,continuationCaptures:n,exactBindingsSource:i.map(e=>e.binding),sequencePhase:`sequence-advance`,runExact:()=>{r.setPendingSequence(null);let n=i[0]?.layer;if(!n)return A();let c=ye(n,i,a,o);return c.stop?c.outcome:O(c.outcome,z(e,t+1,s||c.handled,a,o))}})}function H(t){let{event:n,focused:i,continuationCaptures:a,exactBindingsSource:o,sequencePhase:c,runExact:l}=t;if(!e.disambiguationResolvers.has()||a.length===0)return;let u=s.getActiveCommandView(i),d=r.collectMatchingBindings(o,i,u);if(!d.some(e=>e.command!==void 0))return;let f=()=>M(c,a,i,n),p=()=>N(`sequence-cleared`,a,i,n),m,h=()=>(m??=r.collectSequencePartsFromPending({captures:a}),m),g=ie({event:n,focused:i,getSequence:h,exactBindings:d,continuationCaptures:a,activeView:u});return g?U(g,a,l,f,p,i,h):(G(h()),f())}function U(e,t,n,r,i,a,o){if(e.action===`run-exact`)return n();if(e.action===`continue-sequence`)return r();if(e.action===`clear`)return i();let s=r();return W(t,e.handler,a,o(),e=>{if(e){if(e.action===`run-exact`){n();return}if(e.action===`continue-sequence`){r();return}i()}}),s}function ie(i){let a,o,s,c,l={event:i.event,focused:i.focused,get sequence(){return a??=di(i.getSequence()),a},get stroke(){let e=i.getSequence().at(-1);if(!e)throw Error(`Disambiguation context expected a non-empty sequence`);return c??={...e,stroke:ci(e.stroke)},c},get exact(){return o??=r.collectActiveBindings(i.exactBindings,i.focused,i.activeView).map(e=>({...e,sequence:di(e.sequence)})),o},get continuations(){return s??=r.getActiveKeysForCaptures(i.continuationCaptures,{includeBindings:!0,includeMetadata:!0}),s},getData:e=>n.getData(e),setData:(e,t)=>{n.setData(e,t)},runExact:()=>uo(`run-exact`),continueSequence:()=>uo(`continue-sequence`),clear:()=>uo(`clear`),defer:e=>uo(`defer`,e)};for(let n of e.disambiguationResolvers.values()){let e;try{e=n(l)}catch(e){t.emitError(`disambiguation-resolver-error`,e,`[Keymap] Error in disambiguation resolver:`);continue}if(e!==void 0){if(ba(e)){t.emitError(`invalid-disambiguation-resolver-return`,e,`[Keymap] Disambiguation resolvers must return synchronously; use ctx.defer(...) for async handling`);continue}if(!po(e)){t.emitError(`invalid-disambiguation-decision`,e,`[Keymap] Invalid disambiguation decision returned by resolver:`);continue}return e}}}function W(e,t,n,r,i){ce();let a=new AbortController,o={id:f++,controller:a,captures:e,apply:i};d=o,queueMicrotask(()=>{ae(o,t,n,r)})}function ae(e,n,r,i){if(!le(e))return;let a={signal:e.controller.signal,sequence:di(i),focused:r,sleep:t=>ho(t,e.controller.signal),runExact:()=>fo(`run-exact`),continueSequence:()=>fo(`continue-sequence`),clear:()=>fo(`clear`)},o;try{o=n(a)}catch(n){le(e)&&(t.emitError(`deferred-disambiguation-error`,n,`[Keymap] Error in deferred disambiguation handler:`),se(e));return}if(ba(o)){o.then(t=>{oe(e,t)}).catch(n=>{le(e)&&(t.emitError(`deferred-disambiguation-error`,n,`[Keymap] Error in deferred disambiguation handler:`),se(e))});return}oe(e,o)}function oe(e,n){if(le(e)){if(n!==void 0&&!mo(n)){t.emitError(`invalid-deferred-disambiguation-decision`,n,`[Keymap] Invalid deferred disambiguation decision returned by handler:`),se(e);return}se(e),e.apply(n)}}function se(e){le(e)&&(d=null)}function ce(){let e=d;e&&(d=null,e.controller.abort())}function le(e){return d===e}function G(e){let n=gi(e,{preferDisplay:!0});t.warnOnce(`unresolved-disambiguation:${n}`,`unresolved-disambiguation`,{sequence:n},`[Keymap] Ambiguous exact/prefix sequence "${n}" fell back to prefix handling because no disambiguation resolver resolved it`)}function ue(t,n,r,a,o){let c=[],l=s.getActiveCommandView(o);for(let s=n;s<t.length;s+=1){let n=t[s];if(n&&i.matchesConditions(n))for(let t of ge(n,r,a,o,l))Oi(t,e.patterns,!1)&&c.push(t)}return c}function de(t,n,r){return t.filter((t,i)=>i>=n&&Oi(t,e.patterns,!1)&&xo(t.parts,r.parts))}function fe(t,n){return t.filter(t=>t.layer===n.layer&&ki(t,e.patterns)&&xo(t.parts,n.parts))}function pe(n){let r=e.eventMatchResolvers.values();if(r.length===0)return[];if(r.length===1)return bo(r[0],n,u,t);let i=[],a=new Set;for(let e of r){let r;try{r=e(n,u)}catch(e){t.emitError(`event-match-resolver-error`,e,`[Keymap] Error in event match resolver:`);continue}if(!(!r||r.length===0))for(let e of r){if(typeof e!=`string`){t.emitError(`invalid-event-match-resolver-candidate`,e,`[Keymap] Invalid event match resolver candidate:`);continue}a.has(e)||(a.add(e),i.push(e))}}return i}function me(e,t,n,r){let o=!1,s=A();for(let c of e.bindings){if(c.event!==`release`)continue;let l=c.sequence[0];if(!l||l.match!==t||!i.matchesConditions(c))continue;let u=a.runBinding(e,c,n,r);if(s=O(s,D(c,u)),!u){C(`binding-reject`,e,c,r);continue}if(C(`binding-execute`,e,c,r),o=!0,!c.fallthrough)return{handled:!0,stop:!0,outcome:s}}return{handled:o,stop:!1,outcome:s}}function K(n,r){return go(e.patterns,t,n,r)}function he(t,n,r){return _o(e.patterns,t,n,r)}function ge(e,t,n,r,i){let a=Li(e,t,n,K,he);return a.some(e=>ve(e,r,i))?a:[]}function q(n){return vo(e.patterns,t,n)}function _e(e,t,n){return i.matchesConditions(e)&&s.isBindingVisible(e,t,n)}function ve(e,t,n){return _e(e.binding,t,n)}function ye(e,t,n,r){let o=!1,s=A();for(let c of t){let t=c.binding;if(!i.matchesConditions(t))continue;let l=a.runBinding(e,t,n,r,q(c));if(s=O(s,D(t,l)),!l){C(`binding-reject`,e,t,r);continue}if(C(`binding-execute`,e,t,r),o=!0,!t.fallthrough)return{handled:!0,stop:!0,outcome:s}}return{handled:o,stop:!1,outcome:s}}return{intercept:p,prependEventMatchResolver:m,appendEventMatchResolver:h,clearEventMatchResolvers:g,prependDisambiguationResolver:_,appendDisambiguationResolver:v,clearDisambiguationResolvers:y,handlePendingSequenceChange:b,handleRawSequence:x,handleKeyEvent:P}}function bo(e,t,n,r){let i;try{i=e(t,n)}catch(e){return r.emitError(`event-match-resolver-error`,e,`[Keymap] Error in event match resolver:`),[]}if(!i||i.length===0)return[];if(i.length===1){let[e]=i;return typeof e==`string`?[e]:(r.emitError(`invalid-event-match-resolver-candidate`,e,`[Keymap] Invalid event match resolver candidate:`),[])}let a=[],o=new Set;for(let e of i){if(typeof e!=`string`){r.emitError(`invalid-event-match-resolver-candidate`,e,`[Keymap] Invalid event match resolver candidate:`);continue}o.has(e)||(o.add(e),a.push(e))}return a}function xo(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]?.match!==t[n]?.match)return!1;return!0}var So=()=>{};function Co(e,t,n,r){if(n===void 0)return r;if(typeof n!=`number`||!Number.isInteger(n)||n<0)throw Error(`Keymap sequence pattern "${e}" ${t} must be a non-negative integer`);return n}function wo(e,t){let{kind:n,reservedFields:r,registeredFields:i,emitError:a}=t,o=Object.entries(e),s=[];for(let[e,t]of o){if(r.has(e)){a(`reserved-${n}-field`,{field:e,kind:n},`Keymap ${n} field "${e}" is reserved`);continue}if(i.has(e)){a(`duplicate-${n}-field`,{field:e,kind:n},`Keymap ${n} field "${e}" is already registered`);continue}i.set(e,t),s.push([e,t])}return()=>{for(let[e,t]of s)i.get(e)===t&&i.delete(e)}}function To(e,t,n,r,i){let a;try{a=ai(i.name)}catch(e){return t.emitError(`token-name-normalize-error`,e,ya(e,`Failed to register keymap token`)),So}if(e.tokens.has(a)||e.patterns.has(a))return t.emitError(`duplicate-token`,{token:a},`Keymap token "${a}" is already registered`),So;let o;try{if(o=n.parseTokenKey(i.key),o.patternName)throw Error(`Invalid key "${String(i.key)}": expected a concrete key stroke`)}catch(e){return t.emitError(`token-parse-error`,e,ya(e,`Failed to register keymap token "${a}"`)),So}let s={stroke:o.stroke,match:o.match},c=new Map(e.tokens);c.set(a,s);try{r.applyTokenState(c)}catch(e){return t.emitError(`token-register-error`,e,ya(e,`Failed to register keymap token "${a}"`)),So}return()=>{if(e.tokens.get(a)!==s)return;let n=new Map(e.tokens);n.delete(a);try{r.applyTokenState(n)}catch(e){t.emitError(`token-unregister-error`,e,ya(e,`Failed to unregister keymap token "${a}"`))}}}function Eo(e,t,n,r){let i,a;try{i=ai(r.name);let e=Co(i,`min`,r.min,1),t=Co(i,`max`,r.max,2**53-1);if(t<e)throw Error(`Keymap sequence pattern "${i}" max must be greater than or equal to min`);a={name:i,display:r.display,payloadKey:r.payloadKey??i,match:mi(`pattern:${i}`),min:e,max:t,matcher:e=>r.match(e),finalize:r.finalize}}catch(e){return t.emitError(`sequence-pattern-register-error`,e,ya(e,`Failed to register keymap sequence pattern`)),So}return e.tokens.has(i)||e.patterns.has(i)?(t.emitError(`duplicate-sequence-pattern`,{pattern:i},`Keymap sequence pattern "${i}" is already registered`),So):(e.patterns.set(i,a),n.recompileBindings(),()=>{e.patterns.get(i)===a&&(e.patterns.delete(i),n.recompileBindings())})}function Do(e,t,n,r){return wo(r,{kind:n,reservedFields:n===`layer`?ca:n===`binding`?sa:oa,registeredFields:n===`layer`?e.layerFields:n===`binding`?e.bindingFields:e.commandFields,emitError:(e,n,r)=>t.emitError(e,n,r)})}var Oo=()=>{};function ko(e,t){return t.priority-e.priority||t.order-e.order}function Ao(e){if(e.matchers.length>0)return!0;for(let t of e.commands)if(t.matchers.length>0)return!0;for(let t of e.bindings)if(t.matchers.length>0)return!0;return!1}function jo(e){if(e.commands.length===0)return!1;if(e.matchers.length>0)return!0;for(let t of e.commands)if(t.matchers.length>0)return!0;return!1}function Mo(e,t,n,r,i){let a=n=>t.runWithStateChangeBatch(()=>{let a=n.target;if(a&&i.host.isTargetDestroyed(a))return t.emitError(`destroyed-layer-target`,{target:a},`Cannot register a keymap layer for a destroyed keymap target`),Oo;let o,s,c,p,m,v,y;try{y=l(n),o=u(Wi(n.bindings??[]),n);let e=d(n.commands??[],n);v=e.length===0?[]:i.commands.normalizeCommands(e),{requires:s,matchers:c,fields:p,attrs:m}=f(n)}catch(e){return t.emitError(`register-layer-failed`,e,ya(e,`Failed to register keymap layer`)),Oo}let b=e.order++,x=i.compiler.compileBindings(o,e.tokens,a,b,p);if(x.bindings.length===0&&!x.hasTokenBindings&&v.length===0)return Oo;i.diagnostics?.analyzeLayer({target:a,order:b,commands:v,sourceBindings:o,bindings:x.bindings,hasTokenBindings:x.hasTokenBindings});let S={order:b,target:a,targetMode:y,priority:n.priority??0,requires:s,matchers:c,fields:p,attrs:m,commands:v,sourceBindings:o,bindings:x.bindings,root:ji(x.bindings,e.patterns),hasTokenBindings:x.hasTokenBindings,activeKeyCacheBlocked:!1,activeCommandViewCacheBlocked:!1};_(S),e.layers.add(S),e.sortedLayers=[...e.sortedLayers,S].sort(ko),g(S);for(let e of S.commands)g(e);for(let e of S.bindings)g(e);return a&&(S.offTargetDestroy=i.host.onTargetDestroy(a,()=>{h(S)})),S.commands.length>0&&r.ensureValidPendingSequence(),t.queueStateChange(),()=>{h(S)}}),o=n=>{t.runWithStateChangeBatch(()=>{let i=new Map;for(let t of e.layers)t.hasTokenBindings&&i.set(t,p(t,n));e.tokens=n;let a=!1;for(let[e,t]of i)m(e,t)&&(a=!0);a&&r.setPendingSequence(null),i.size>0&&t.queueStateChange()})},s=()=>{t.runWithStateChangeBatch(()=>{let n=0,i=!1;for(let t of e.layers){if(t.sourceBindings.length===0)continue;let r=p(t,e.tokens);m(t,r)&&(i=!0),n+=1}i&&r.setPendingSequence(null),n>0&&t.queueStateChange()})},c=()=>{for(let t of e.layers){y(t);for(let e of t.commands)y(e);for(let e of t.bindings)y(e);t.offTargetDestroy?.(),t.offTargetDestroy=void 0}},l=e=>{if(e.targetMode){if(!e.target)throw Error(`Keymap targetMode "${e.targetMode}" requires a target`);return e.targetMode}return e.target?`focus-within`:void 0},u=(t,n)=>{let r=e.layerBindingsTransformers.values();if(r.length===0)return t;let i=t;for(let e of r){let t=e(i,{layer:n,validateBindings:e=>Ui(e)});t&&(i=Wi(t))}return i},d=(n,r)=>{let i=e.commandTransformers.values();if(n.length===0||i.length===0)return n;let a=[];for(let e of n){let n={...e},o=[],s=!0;for(let e of i)try{e(n,{layer:r,add(e){o.push({...e})},skipOriginal(){s=!1}})}catch(e){t.emitError(`command-transformer-error`,e,`[Keymap] Error in command transformer:`)}s&&a.push(n),a.push(...o)}return a},f=t=>{let r={},a=[],o=Object.create(null),s={};for(let[c,l]of Object.entries(t)){if(ca.has(c)||l===void 0)continue;o[c]=xa(l);let t=e.layerFields.get(c);if(!t){i.warnUnknownField(`layer`,c);continue}t(l,_a({fieldName:c,conditions:n,requirements:r,matchers:a,attrs:s}))}return{requires:Object.entries(r),matchers:a,fields:Object.keys(o).length>0?Object.freeze(o):void 0,attrs:Object.keys(s).length>0?xa(s,{freeze:!0}):void 0}},p=(e,t)=>i.compiler.compileBindings(e.sourceBindings,t,e.target,e.order,e.fields),m=(t,n)=>{i.diagnostics?.analyzeLayer({target:t.target,order:t.order,commands:t.commands,sourceBindings:t.sourceBindings,bindings:n.bindings,hasTokenBindings:n.hasTokenBindings}),v(t);for(let e of t.bindings)y(e);t.bindings=n.bindings,t.root=ji(n.bindings,e.patterns),t.hasTokenBindings=n.hasTokenBindings,_(t);for(let e of t.bindings)g(e);return e.pending?.captures.some(e=>e.layer===t)??!1},h=n=>{t.runWithStateChangeBatch(()=>{if(e.layers.delete(n)){e.sortedLayers=e.sortedLayers.filter(e=>e!==n),v(n),y(n);for(let e of n.commands)y(e);for(let e of n.bindings)y(e);n.offTargetDestroy?.(),n.offTargetDestroy=void 0,e.pending?.captures.some(e=>e.layer===n)?r.setPendingSequence(null):n.commands.length>0&&!i.host.isDestroyed&&r.ensureValidPendingSequence(),t.queueStateChange()}})},g=e=>{for(let n of e.matchers)if(n.subscribe)try{n.dispose=n.subscribe(()=>{if(!r.hasPendingSequenceState()){t.queueStateChange();return}t.runWithStateChangeBatch(()=>{r.revalidatePendingSequenceIfNeeded(),t.queueStateChange()})})}catch(e){t.emitError(`reactive-matcher-subscribe-error`,e,ya(e,`Failed to subscribe to reactive matcher from ${n.source}`))}},_=t=>{let n=Ao(t),r=jo(t);t.activeKeyCacheBlocked=n,t.activeCommandViewCacheBlocked=r,n&&(e.activeKeyCacheBlockers+=1),r&&(e.activeCommandViewCacheBlockers+=1)},v=t=>{t.activeKeyCacheBlocked&&=(--e.activeKeyCacheBlockers,!1),t.activeCommandViewCacheBlocked&&=(--e.activeCommandViewCacheBlockers,!1)},y=e=>{for(let n of e.matchers)if(n.dispose){try{n.dispose()}catch(e){t.emitError(`reactive-matcher-dispose-error`,e,ya(e,`Failed to dispose reactive matcher from ${n.source}`))}n.dispose=void 0}};return{registerLayer:a,applyTokenState:o,recompileBindings:s,cleanup:c}}var No=1e3;function Po(e,t,n){let r=(e,n,r)=>{if(!t.has(`warning`)){let t=`[${e}] ${r}`;n instanceof Error?console.warn(t,n):console.warn(t);return}t.emit(`warning`,{code:e,message:r,warning:n})},i=(e,n,r)=>{if(!t.has(`error`)){let t=`[${e}] ${r}`;n instanceof Error?console.error(t,n):console.error(t);return}t.emit(`error`,{code:e,message:r,error:n})},a=()=>{if(!(!e.stateChangePending||e.stateChangeDepth>0||e.flushingStateChange)){e.flushingStateChange=!0;try{let t=0;for(;e.stateChangePending&&e.stateChangeDepth===0;){if(t>=No){e.stateChangePending=!1,i(`state-change-feedback-loop`,{iterations:No},`[Keymap] Possible infinite state listener feedback loop detected after ${No} iterations; pending state notifications were dropped`);break}t+=1,e.stateChangePending=!1,n.emit(`state`)}}finally{e.flushingStateChange=!1}}};return{runWithStateChangeBatch(t){e.stateChangeDepth+=1;try{return t()}finally{--e.stateChangeDepth,e.stateChangeDepth===0&&a()}},queueStateChange(t){e.derivedVersion+=1,t?.invalidateCaches!==!1&&(e.cacheVersion+=1),n.has(`state`)&&(e.stateChangePending=!0,e.stateChangeDepth===0&&!e.flushingStateChange&&a())},emitWarning:r,emitError:i,reportListenerError(e,t){if(e===`state`){i(`state-listener-error`,t,`[Keymap] Error in state listener:`);return}if(e===`pendingSequence`){i(`pending-sequence-listener-error`,t,`[Keymap] Error in pending sequence listener:`);return}e===`dispatch`&&i(`dispatch-listener-error`,t,`[Keymap] Error in dispatch listener:`)},warnOnce(t,n,i,a){e.usedWarningKeys.has(t)||(e.usedWarningKeys.add(t),r(n,i,a))}}}function Fo(e,t,n){return{getData(t){return e.data[t]},setData(r,i){t.runWithStateChangeBatch(()=>{if(i===void 0){if(!(r in e.data))return;delete e.data[r],e.dataVersion+=1,n.ensureValidPendingSequence(),t.queueStateChange();return}Object.is(e.data[r],i)||(e.data[r]=i,e.dataVersion+=1,n.ensureValidPendingSequence(),t.queueStateChange())})},getReadonlyData(){return e.readonlyDataVersion===e.dataVersion?e.readonlyData:(e.readonlyData=Object.freeze({...e.data}),e.readonlyDataVersion=e.dataVersion,e.readonlyData)}}}var Io=Object.freeze({});function Lo(){return{order:0,tokens:new Map,patterns:new Map,layerFields:new Map,layerBindingsTransformers:Bi(),bindingExpanders:Bi(),bindingParsers:Bi(),bindingTransformers:Bi(),bindingFields:new Map,commandTransformers:Bi(),commandFields:new Map,eventMatchResolvers:Bi(),disambiguationResolvers:Bi(),keyHooks:Vi(),keyAfterHooks:Vi(),rawHooks:Vi(),layers:new Set,sortedLayers:[],activeLayersCacheVersion:-1,activeLayersCacheFocused:void 0,activeLayersCache:[],activeKeyCacheBlockers:0,activeCommandViewCacheBlockers:0,commandResolvers:Bi(),pending:null,data:{},dataVersion:0,readonlyDataVersion:-1,readonlyData:Io,cacheVersion:0,derivedVersion:0,stateChangeDepth:0,stateChangePending:!1,flushingStateChange:!1,usedWarningKeys:new Set}}function Ro(e){return fi(e)}var zo=class{#e=Lo();#t=!1;#n=new Map;#r=[];#i=Ri(()=>{});#a;#o;#s;#c;#l;#u;#d;#f;#p;#m;#h;#g;#_;#v;#y;#b;getPendingSequence;getActiveKeys;constructor(e){if(this.#b=e,e.isDestroyed)throw Error(`Cannot create a keymap for a destroyed host`);this.#a=Ri((e,t)=>{this.#o.reportListenerError(e,t)}),this.#o=Po(this.#e,this.#i,this.#a),this.#l=so(this.#e,this.#o),this.#u=Ta(this.#e,this.#b,this.#o,this.#l,{onCommandResolversChanged:()=>{this.#s.ensureValidPendingSequence()}}),this.#s=aa(this.#e,this.#b,this.#a,this.#o,this.#l,this.#u,{onPendingSequenceChanged:(e,t)=>{this.#p?.handlePendingSequenceChange(e,t)}}),this.#c=Fo(this.#e,this.#o,this.#s),this.#d=Ka(this.#o,this.#c,this.#s,this.#u,{keymap:this,createCommandEvent:()=>this.#b.createCommandEvent()}),this.#f=$a(this.#e,this.#o,this.#l,{warnUnknownField:(e,t)=>{this.#C(e,t)},warnUnknownToken:(e,t)=>{this.#w(e,t)}}),this.#h=Ki(this.#o,this.#u),this.#m=Mo(this.#e,this.#o,this.#l,this.#s,{compiler:this.#f,commands:this.#u,host:this.#b,diagnostics:this.#h,warnUnknownField:(e,t)=>{this.#C(e,t)}}),this.#p=yo(this.#e,this.#o,this.#c,this.#s,this.#l,this.#d,this.#f,this.#u,this.#m,this.#a),this.getPendingSequence=this.#s.getPendingSequence,this.getActiveKeys=this.#s.getActiveKeys,this.#g=e=>{this.#p.handleKeyEvent(e,!1)},this.#_=e=>{this.#p.handleKeyEvent(e,!0)},this.#v=e=>this.#p.handleRawSequence(e),this.#y=e=>{this.#S(e)},this.#r.push(this.#b.onKeyPress(this.#g)),this.#r.push(this.#b.onKeyRelease(this.#_)),this.#b.onRawInput&&this.#r.push(this.#b.onRawInput(this.#v)),this.#r.push(this.#b.onFocusChange(this.#y)),this.#b.onDestroy&&this.#r.push(this.#b.onDestroy(()=>{this.#x()}))}[yi](){return{state:this.#e,host:this.#b,conditions:this.#l,catalog:this.#u,activation:this.#s}}#x(){if(!this.#t){this.#t=!0,this.#s.setPendingSequence(null);for(let e of this.#n.values())e.dispose();this.#n.clear(),this.#m.cleanup();for(let e of this.#r.splice(0))e()}}setData(e,t){this.#c.setData(e,t)}getData(e){return this.#c.getData(e)}getHostMetadata(){return this.#b.metadata}hasPendingSequence(){return this.#s.ensureValidPendingSequence()!==void 0}createKeyMatcher(e){let t=this.#f.parseTokenKey(e).match;return e=>e?Ro(e)===t:!1}parseKeySequence(e){return this.#f.parseKeySequence(e)}formatKey(e,t){return this.#f.formatKey(e,t)}clearPendingSequence(){this.#s.setPendingSequence(null)}popPendingSequence(){return this.#s.popPendingSequence()}getCommands(e){return this.#u.getCommands(e)}getCommandEntries(e){return this.#u.getCommandEntries(e)}getCommandBindings(e){return this.#u.getCommandBindings(e)}acquireResource(e,t){if(this.#t||this.#b.isDestroyed)throw Error(`Cannot use a keymap after its host was destroyed`);let n=this.#n.get(e);if(n)return n.count+=1,()=>{this.#T(e,n)};let r={count:1,dispose:t()};return this.#n.set(e,r),()=>{this.#T(e,r)}}runCommand(e,t){return this.#d.runCommand(e,t)}dispatchCommand(e,t){return this.#d.dispatchCommand(e,t)}on(e,t){return e===`warning`||e===`error`?this.#i.hook(e,t):this.#a.hook(e,t)}intercept(e,t,n){return this.#p.intercept(e,t,n)}registerLayer(e){return this.#m.registerLayer(e)}registerLayerFields(e){return Do(this.#e,this.#o,`layer`,e)}prependLayerBindingsTransformer(e){return this.#e.layerBindingsTransformers.prepend(e)}appendLayerBindingsTransformer(e){return this.#e.layerBindingsTransformers.append(e)}clearLayerBindingsTransformers(){this.#e.layerBindingsTransformers.clear()}prependBindingTransformer(e){return this.#e.bindingTransformers.prepend(e)}appendBindingTransformer(e){return this.#e.bindingTransformers.append(e)}clearBindingTransformers(){this.#e.bindingTransformers.clear()}prependCommandTransformer(e){return this.#e.commandTransformers.prepend(e)}appendCommandTransformer(e){return this.#e.commandTransformers.append(e)}clearCommandTransformers(){this.#e.commandTransformers.clear()}prependBindingParser(e){return this.#e.bindingParsers.prepend(e)}appendBindingParser(e){return this.#e.bindingParsers.append(e)}clearBindingParsers(){this.#e.bindingParsers.clear()}registerToken(e){return To(this.#e,this.#o,this.#f,this.#m,e)}registerSequencePattern(e){return Eo(this.#e,this.#o,this.#m,e)}prependBindingExpander(e){return this.#e.bindingExpanders.prepend(e)}appendBindingExpander(e){return this.#e.bindingExpanders.append(e)}clearBindingExpanders(){this.#e.bindingExpanders.clear()}registerBindingFields(e){return Do(this.#e,this.#o,`binding`,e)}registerCommandFields(e){return Do(this.#e,this.#o,`command`,e)}prependCommandResolver(e){return this.#u.prependCommandResolver(e)}appendCommandResolver(e){return this.#u.appendCommandResolver(e)}clearCommandResolvers(){this.#u.clearCommandResolvers()}prependLayerAnalyzer(e){return this.#h.prependLayerAnalyzer(e)}appendLayerAnalyzer(e){return this.#h.appendLayerAnalyzer(e)}clearLayerAnalyzers(){this.#h.clearLayerAnalyzers()}prependEventMatchResolver(e){return this.#p.prependEventMatchResolver(e)}appendEventMatchResolver(e){return this.#p.appendEventMatchResolver(e)}clearEventMatchResolvers(){this.#p.clearEventMatchResolvers()}prependDisambiguationResolver(e){return this.#p.prependDisambiguationResolver(e)}appendDisambiguationResolver(e){return this.#p.appendDisambiguationResolver(e)}clearDisambiguationResolvers(){this.#p.clearDisambiguationResolvers()}#S(e){this.#o.runWithStateChangeBatch(()=>{this.#s.setPendingSequence(null),this.#o.queueStateChange({invalidateCaches:!1})})}#C(e,t){this.#o.warnOnce(`${e}:${t}`,`unknown-${e}-field`,{field:t,kind:e},`[Keymap] Unknown ${e} field "${t}" was ignored`)}#w(e,t){this.#o.warnOnce(`token:${e}`,`unknown-token`,{token:e,sequence:t},`[Keymap] Unknown token "${e}" in key sequence "${t}"; binding was skipped until the token is registered`)}#T(e,t){this.#n.get(e)===t&&(--t.count,!(t.count>0)&&(t.dispose(),this.#n.delete(e)))}},Bo=new Set(`up.down.left.right.clear.escape.return.linefeed.enter.tab.backspace.delete.insert.home.end.pageup.pagedown.space.lt.gt.plus.minus.equal.comma.period.slash.backslash.semicolon.quote.backquote.leftbracket.rightbracket.capslock.numlock.scrolllock.printscreen.pause.menu.apps.kp0.kp1.kp2.kp3.kp4.kp5.kp6.kp7.kp8.kp9.kpdecimal.kpdivide.kpmultiply.kpminus.kpplus.kpenter.kpequal.kpseparator.kpleft.kpright.kpup.kpdown.kppageup.kppagedown.kphome.kpend.kpinsert.kpdelete.mediaplay.mediapause.mediaplaypause.mediareverse.mediastop.mediafastforward.mediarewind.medianext.mediaprev.mediarecord.volumedown.volumeup.mute.leftshift.leftctrl.leftalt.leftsuper.lefthyper.leftmeta.rightshift.rightctrl.rightalt.rightsuper.righthyper.rightmeta.iso_level3_shift.iso_level5_shift.option.alt.meta.super.hyper.control.ctrl.shift`.split(`.`)),Vo=new Set([`ctrl`,`control`,`shift`,`meta`,`alt`,`option`,`super`,`hyper`]),Ho=Wo(Bo),Uo=Wo(Vo);function Wo(e){let t=new Map;for(let n of e){let e=n.charCodeAt(0);if(Number.isNaN(e))continue;let r=t.get(e);r||(r=[],t.set(e,r)),r.push(n)}for(let e of t.values())e.sort((e,t)=>t.length-e.length);return t}function Go(e){return e>=65&&e<=90?e+32:e}function Ko(e){return e>=48&&e<=57}function qo(e,t,n){if(e.startsWith(t,n))return!0;if(n+t.length>e.length)return!1;for(let r=0;r<t.length;r+=1)if(Go(e.charCodeAt(n+r))!==t.charCodeAt(r))return!1;return!0}function Jo(e,t,n){let r=t.charCodeAt(n);if(Number.isNaN(r))return;let i=e.get(Go(r));if(i){for(let e of i)if(qo(t,e,n))return e}}function Yo(e,t,n,r,i){return e.parseObjectKey(t,{display:n,match:r,tokenName:i})}function Xo(e,t){if(e===` `)return t.parseObjectKey({name:`space`},{display:`space`});if(e===`+`)return t.parseObjectKey({name:`+`},{display:`+`});let n=e.split(`+`),r=``,i=``,a=!1,o=!1,s=!1,c=!1,l=!1;for(let t of n){let n=t.trim();if(!n)continue;let u=n.toLowerCase();if(u===`ctrl`||u===`control`){a=!0;continue}if(u===`shift`){o=!0;continue}if(u===`meta`||u===`alt`||u===`option`){s=!0;continue}if(u===`super`){c=!0;continue}if(u===`hyper`){l=!0;continue}if(r)throw Error(`Invalid key "${e}": multiple key names are not supported`);r=n,i=u}if(!r)throw Error(`Invalid key "${e}": missing key name`);let u=[];return a&&u.push(`ctrl`),o&&u.push(`shift`),s&&u.push(`meta`),c&&u.push(`super`),l&&u.push(`hyper`),u.push(i),t.parseObjectKey({name:r,ctrl:a,shift:o,meta:s,super:c,hyper:l||void 0},{display:u.join(`+`)})}function Zo(e,t){let n=e.trim().toLowerCase();return t.parseObjectKey({name:n},{display:n})}function Qo(e,t){let n=Jo(Ho,e,t);if(n)return n;if(Go(e.charCodeAt(t))!==102||!Ko(e.charCodeAt(t+1)))return;let r=Ko(e.charCodeAt(t+2))?t+3:t+2;return e.slice(t,r).toLowerCase()}function $o(e,t){return Jo(Uo,e,t)}function es(e,t,n){let r=t,i=!1,a=!1,o=!1,s=!1,c=!1;for(;r<e.length;){let t=$o(e,r);if(!t)break;let n=r+t.length;if(e[n]!==`+`)break;t===`ctrl`||t===`control`?i=!0:t===`shift`?a=!0:t===`meta`||t===`alt`||t===`option`?o=!0:t===`super`?s=!0:t===`hyper`&&(c=!0),r=n+1}if(r===t)return;let l=e[r];if(l===void 0)throw Error(`Invalid key "${e.slice(t)}": missing key name`);let u=Qo(e,r)??l,d=u===` `?`space`:u===`+`?`+`:u.toLowerCase(),f=[];return i&&f.push(`ctrl`),a&&f.push(`shift`),o&&f.push(`meta`),s&&f.push(`super`),c&&f.push(`hyper`),f.push(d),{part:n.parseObjectKey({name:u===` `?`space`:u,ctrl:i,shift:a,meta:o,super:s,hyper:c||void 0},{display:f.join(`+`)}),nextIndex:r+u.length}}var ts=e=>{let{input:t,index:n,tokens:r,normalizeTokenName:i}=e;if(n===0&&t.includes(`+`)&&/\s/.test(t))return{parts:[Xo(t,e)],nextIndex:t.length};let a=t[n];if(a===void 0)return;if(a===`<`){let o=t.indexOf(`>`,n);if(o===-1)return{parts:[Xo(a,e)],nextIndex:n+1};let s=i(t.slice(n+1,o)),c=r.get(s);return c?{parts:[Yo(e,c.stroke,`<${s}>`,c.match,s)],nextIndex:o+1,usedTokens:[s]}:{parts:[],nextIndex:o+1,unknownTokens:[s]}}if(a===`{`){let r=t.indexOf(`}`,n);if(r===-1)return{parts:[Xo(a,e)],nextIndex:n+1};let o=i(t.slice(n+1,r)),s=e.patterns.get(o);return s?{parts:[{...e.parseObjectKey({name:o,ctrl:!1,shift:!1,meta:!1,super:!1},{display:s.display??`{${o}}`,match:s.match}),patternName:s.name,payloadKey:s.payloadKey}],nextIndex:r+1,usedTokens:[o]}:{parts:[],nextIndex:r+1,unknownTokens:[o]}}let o=es(t,n,e);if(o)return{parts:[o.part],nextIndex:o.nextIndex};let s=Qo(t,n);return s?{parts:[Zo(s,e)],nextIndex:n+s.length}:{parts:[Xo(a,e)],nextIndex:n+1}},ns=(e,t)=>[t.resolveKey({name:e.name,ctrl:e.ctrl,shift:e.shift,meta:e.meta,super:e.super??!1,hyper:e.hyper||void 0})];function rs(e){return e.appendBindingParser(e=>ts(e))}function is(e){return e.appendEventMatchResolver((e,t)=>ns(e,t))}function as(e){let t=rs(e),n=is(e);return()=>{n(),t()}}var os=Symbol(`keymap:mod-bindings`),ss=/(^|[+,\s])mod(?=\s*\+)/i,cs=/(^|[+,\s])mod(?=\s*\+)/gi;function ls(e){let t=e.primaryModifier;return(t===`ctrl`||t===`super`)&&e.modifiers[t]!==`unsupported`?t:e.modifiers.ctrl===`unsupported`?`super`:`ctrl`}function us(e){if(e.includes(`,`))return[e];let t=e.trim();return t.includes(` `)?t.split(/\s+/):[e]}function ds(e){return e.acquireResource(os,()=>e.appendBindingExpander(({input:t,displays:n})=>{if(!ss.test(t))return;let r=ls(e.getHostMetadata());return[{key:t.replace(cs,(e,t)=>`${t}${r}`),displays:n??us(t)}]}))}var fs=new Map([[` `,`space`],[`Spacebar`,`space`],[`ArrowUp`,`up`],[`ArrowDown`,`down`],[`ArrowLeft`,`left`],[`ArrowRight`,`right`],[`Escape`,`escape`],[`Esc`,`escape`],[`Enter`,`return`],[`Backspace`,`backspace`],[`Delete`,`delete`],[`Tab`,`tab`],[`Home`,`home`],[`End`,`end`],[`PageUp`,`pageup`],[`PageDown`,`pagedown`],[`Insert`,`insert`],[`CapsLock`,`capslock`],[`NumLock`,`numlock`],[`ScrollLock`,`scrolllock`],[`ContextMenu`,`menu`],[`Meta`,`super`],[`OS`,`super`],[`Alt`,`alt`],[`Control`,`control`],[`Shift`,`shift`]]);function ps(e){let t=e?.trim().toLowerCase();return t?t.includes(`mac`)||t.includes(`darwin`)?`macos`:t.includes(`win`)?`windows`:t.includes(`linux`)||t.includes(`x11`)?`linux`:`unknown`:`unknown`}function ms(){let e=globalThis.navigator,t=e?.userAgentData?.platform,n=ps(t);return n===`unknown`?ps(e?.platform??e?.userAgent):n}function hs(){let e=ms();return{platform:e,primaryModifier:e===`macos`?`super`:e===`unknown`?`unknown`:`ctrl`,modifiers:{ctrl:`supported`,shift:`supported`,meta:`supported`,super:`supported`,hyper:`unsupported`}}}function gs(e){return e.length===1&&!/^[a-z0-9]$/i.test(e)}function _s(e){let t={name:e.name,ctrl:e.ctrl,shift:e.shift,meta:e.meta,super:e.super??!1,hyper:e.hyper||void 0};return!t.shift||!gs(t.name)?[t]:[t,{...t,shift:!1}]}var vs=class{name;ctrl;shift;meta;superKey;originalEvent;propagationStopped=!1;constructor(e,t,n,r,i,a){this.name=e,this.ctrl=t,this.shift=n,this.meta=r,this.superKey=i,this.originalEvent=a}get super(){return this.superKey}preventDefault(){this.originalEvent?.preventDefault()}stopPropagation(){this.propagationStopped=!0,this.originalEvent?.stopPropagation()}};function ys(){return globalThis.MutationObserver}function bs(e){return fs.get(e)||(/^F\d{1,2}$/i.test(e)||e.length===1?e.toLowerCase():e.trim().toLowerCase().replace(/\s+/g,``))}function xs(e){if(!e)return new vs(`command`,!1,!1,!1,!1);let t=globalThis.KeyboardEvent;return new vs(bs(e.key),e.ctrlKey,e.shiftKey,e.altKey,e.metaKey,t&&e instanceof t?e:void 0)}var Ss=class{metadata=hs();rootTarget;isDestroyed=!1;observer;targetDestroyListeners=new Map;constructor(e){this.rootTarget=e}getFocusedTarget(){let e=this.rootTarget.ownerDocument.activeElement;return!e||typeof e!=`object`?null:e===this.rootTarget||this.rootTarget.contains(e)?e:null}getParentTarget(e){return e.parentElement}isTargetDestroyed(e){return e===this.rootTarget?!1:!e.isConnected||!this.rootTarget.contains(e)}onKeyPress(e){let t=t=>{e(xs(t))};return this.rootTarget.addEventListener(`keydown`,t,{capture:!0}),()=>{this.rootTarget.removeEventListener(`keydown`,t,{capture:!0})}}onKeyRelease(e){let t=t=>{e(xs(t))};return this.rootTarget.addEventListener(`keyup`,t,{capture:!0}),()=>{this.rootTarget.removeEventListener(`keyup`,t,{capture:!0})}}onFocusChange(e){let t=()=>{queueMicrotask(()=>{e(this.getFocusedTarget())})};return this.rootTarget.addEventListener(`focusin`,t,{capture:!0}),this.rootTarget.addEventListener(`focusout`,t,{capture:!0}),()=>{this.rootTarget.removeEventListener(`focusin`,t,{capture:!0}),this.rootTarget.removeEventListener(`focusout`,t,{capture:!0})}}onTargetDestroy(e,t){let n=this.targetDestroyListeners.get(e);return n||(n=new Set,this.targetDestroyListeners.set(e,n)),n.add(t),this.ensureObserver(),this.flushDisconnectedTargets(),()=>{let n=this.targetDestroyListeners.get(e);n&&(n.delete(t),n.size===0&&this.targetDestroyListeners.delete(e),this.targetDestroyListeners.size===0&&this.disconnectObserver())}}createCommandEvent(){return xs()}ensureObserver(){if(this.observer||this.targetDestroyListeners.size===0)return;let e=ys();e&&(this.observer=new e(()=>{this.flushDisconnectedTargets()}),this.observer.observe(this.rootTarget,{childList:!0,subtree:!0}))}disconnectObserver(){this.observer&&=(this.observer.disconnect(),void 0)}flushDisconnectedTargets(){for(let[e,t]of this.targetDestroyListeners)if(this.isTargetDestroyed(e)){this.targetDestroyListeners.delete(e);for(let e of[...t])e()}this.targetDestroyListeners.size===0&&this.disconnectObserver()}};function Cs(e){return new Ss(e)}var ws=(e,t)=>_s(e).map(e=>t.resolveKey(e));function Ts(e){return e instanceof q?{code:e.code,message:Ds(e.message),retryable:e.retryable,...e.need!==void 0&&{need:e.need}}:{code:`HOST_FAILURE`,message:`Host operation failed`,retryable:!1}}function Es(e){try{let t=$n(e);return new q(t.message,{code:t.code,retryable:t.retryable,...t.need!==void 0&&{need:t.need}})}catch(e){return new q(`The host returned a malformed error`,{cause:e,code:`PROTOCOL`,retryable:!1})}}function Ds(e){return e.trim().slice(0,512)||`Host operation failed`}var Os=e=>({ok:!0,value:e}),ks=e=>({error:Ts(e),ok:!1});async function As(e,t){let n,r=new Set;try{return n=await e,js(t(n))}catch(e){throw Ms(e)&&Ns(e,r),e instanceof q?e:new q(`The remote operation failed`,{cause:e,code:`HOST_FAILURE`,retryable:!0})}finally{n!==e&&Ms(n)&&Ns(n,r)}}function js(e){if(e.ok)return e.value;throw Es(e.error)}function Ms(e){return B(e)&&Symbol.dispose in e&&gt(e[Symbol.dispose])}function Ns(e,t){if(!t.has(e)){t.add(e);try{e[Symbol.dispose]()}catch(e){console.warn(`RPC result disposal failed`,e)}}}function Ps(){let e=[],t=new Set;return{get:()=>e,subscribe:e=>(t.add(e),()=>t.delete(e)),update:n=>{e=n;for(let e of Array.from(t))try{e()}catch(e){console.warn(`App binding subscriber failed`,e)}}}}function Fs(e){let t=kr(e),n=new Set;return{get:()=>t,subscribe:e=>(n.add(e),()=>n.delete(e)),update:e=>{t=kr(e);for(let e of Array.from(n))try{e()}catch(e){console.warn(`Reserved chord subscriber failed`,e)}}}}function Is(e){let t=!0,n,r=e.window.document.querySelector(`html`);if(!r)return()=>{t=!1};let i=Cs(r),a=new zo(i);as(a),ds(a),a.prependEventMatchResolver(ws);let o=Rs(e.onBroken),s=Hs(a,e.chords,e.remote,o),c=Ls(e,o,()=>t,e=>{n=e},()=>n),l=i.onFocusChange(()=>{queueMicrotask(c)}),u=()=>{queueMicrotask(c)};e.window.addEventListener(`focus`,u),e.window.addEventListener(`blur`,u);let d=e.bindings,f=()=>zs(e.window.document,e.identity.surfaceId).editing,p=d===void 0?()=>void 0:Bs(a,d,f),m=d===void 0?()=>void 0:d.subscribe(()=>{p(),p=Bs(a,d,f)}),h=e.chords.subscribe(()=>{s(),s=Hs(a,e.chords,e.remote,o)});return queueMicrotask(c),()=>{t&&(t=!1,l(),e.window.removeEventListener(`focus`,u),e.window.removeEventListener(`blur`,u),h(),s(),m(),p())}}function Ls(e,t,n,r,i){return()=>{if(!n())return;let a=zs(e.window.document,e.identity.surfaceId),o=i();(a.editing!==o?.editing||a.surface!==o.surface)&&(r(a),t(()=>e.remote.reportFocus(a)))}}function Rs(e){return t=>{try{As(t(),Tr).catch(t=>{or(`browser-bridge.host-call`,t),e(t)})}catch(t){or(`browser-bridge.host-call`,t),e(t)}}}function zs(e,t){let n=e.activeElement;return Nn({editing:!!(n?.matches(`input, textarea, select, [contenteditable='true']`)===!0||n?.closest(`[contenteditable='true']`)),surface:e.hasFocus()?t:null})}function Bs(e,t,n){let r=t.get();return e.registerLayer({bindings:r.map((e,t)=>({cmd:`app/${String(t)}`,key:e.key})),commands:r.map((e,t)=>({name:`app/${String(t)}`,run:t=>{let r=t.event.originalEvent;if(r?.defaultPrevented||r?.isComposing||Vs(e.key)&&n())return!1;e.run()}})),priority:500})}function Vs(e){return!/(?:^|\+)(?:ctrl|control|super|meta|cmd|alt|option|mod)\+/iu.test(e)}function Hs(e,t,n,r){let i=t.get();return e.registerLayer({bindings:i.map(e=>({cmd:`reserved/${e.id}`,key:{ctrl:e.ctrlKey,meta:e.altKey,name:bs(e.key),shift:e.shiftKey,super:e.metaKey}})),commands:i.map(e=>({name:`reserved/${e.id}`,run:t=>{let i=t.event.originalEvent;if(i?.defaultPrevented||i?.isComposing)return!1;r(()=>n.invokeReservedChord(e.id,i?.repeat??!1))}})),priority:1e3})}function Us(e){let t=t=>{if(t.defaultPrevented||t.isComposing)return;let n=Ks(t,e.mac);n!==null&&(t.preventDefault(),!t.repeat&&(n===`back`&&e.canGoBack()&&e.back(),n===`forward`&&e.canGoForward()&&e.forward()))},n=t=>{let n=Gs(t.button);if(n===null)return;let r=t.defaultPrevented;t.preventDefault(),!(t.type!==`mouseup`||r)&&(n===`back`&&e.canGoBack()&&e.back(),n===`forward`&&e.canGoForward()&&e.forward())};e.window.addEventListener(`keydown`,t);for(let t of Ws)e.window.addEventListener(t,n);return()=>{e.window.removeEventListener(`keydown`,t);for(let t of Ws)e.window.removeEventListener(t,n)}}var Ws=[`mousedown`,`mouseup`,`auxclick`];function Gs(e){return e===3?`back`:e===4?`forward`:null}function Ks(e,t){return e.shiftKey||e.ctrlKey?null:t?!e.metaKey||e.altKey?null:e.key===`[`?`back`:e.key===`]`?`forward`:qs(e.target)?null:e.key===`ArrowLeft`?`back`:e.key===`ArrowRight`?`forward`:null:!e.altKey||e.metaKey?null:e.key===`ArrowLeft`?`back`:e.key===`ArrowRight`?`forward`:null}function qs(e){return e instanceof HTMLElement?e.isContentEditable||e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement:!1}function Js(){return!G(globalThis.navigator)&&/Mac|iPhone|iPad/u.test(globalThis.navigator.userAgent)}var Ys=e=>crypto.getRandomValues(new Uint8Array(e)),Xs=(e,t,n)=>{let r=256-256%e.length;if(r===256){let r=e.length-1;return(i=t)=>{if(!i)return``;let a=``;for(;;){let t=n(i),o=i;for(;o--;)if(a+=e[t[o]&r],a.length>=i)return a}}}let i=Math.ceil(409.6*t/r);return(a=t)=>{if(!a)return``;let o=``;for(;;){let t=n(i),s=i;for(;s--;)if(t[s]<r&&(o+=e[t[s]%e.length],o.length>=a))return o}}},Zs=(e,t=21)=>Xs(e,t|0,Ys),Qs=`abcdefghijklmnopqrstuvwxyz0123456789`;function $s(e=21){if(e===1/0||e===-1/0)throw RangeError(`nanoid length must be finite`);return Zs(Qs,e)()}var ec=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,tc=/^[a-z][a-z0-9]*(?:_[a-z][a-z0-9]*)*$/,nc=X().min(1).max(64).regex(ec),rc=X().min(1).max(64).regex(ec),ic=X().min(1).max(32).regex(tc),ac=Ie({prefix:ic}),oc=Ie({family:nc,version:Me(1),kinds:r(rc,ac)}).superRefine((e,t)=>{let n=Object.entries(e.kinds);if(n.length<1||n.length>64){t.addIssue({code:`custom`,message:`Identifier families must declare between one and 64 kinds`});return}let r=new Set;for(let[,e]of n){if(r.has(e.prefix)){t.addIssue({code:`custom`,message:`Identifier kind prefixes must be distinct`});return}r.add(e.prefix)}}),sc=X(),cc=/^[a-z0-9]+$/,lc=new TextEncoder;function uc(e){return e===32||e>=9&&e<=13}function dc(e){let t=0,n=e.length;for(;t<n&&uc(e.charCodeAt(t));)t+=1;for(;n>t&&uc(e.charCodeAt(n-1));)--n;return e.slice(t,n).replace(/[A-Z]/g,e=>String.fromCharCode(e.charCodeAt(0)+32))}function fc(e){let t=`${e.prefix}_`;function n(e){if(!e.startsWith(t))return!1;let n=e.slice(t.length);return n.length===21&&cc.test(n)}let r=j(()=>w(e=>{let t=sc.safeParse(e);return t.success&&n(t.data)}));function i(i){let a,o=i,s=lc.encode(o).byteLength,c=r.safeParse(o),l=o.startsWith(t)?o.slice(t.length):void 0;if(s<3||s>96)a=`bounds`;else if(l!==void 0&&Array.from(l).length!==21)a=`bounds`;else if(c.success)return{ok:!0,value:c.data};else a=n(dc(o))?`non_canonical`:`grammar`;return{ok:!1,error:{code:`invalid_id`,family:e.family,kind:e.kind,version:1,reason:a}}}let a=j(()=>sc.transform((e,t)=>{let n=i(e);return n.ok?n.value:(t.addIssue({code:`custom`,message:n.error.reason}),$t)}));function o(){let n;try{n=$s(21)}catch{throw e.entropyUnavailable()}return r.parse(`${t}${n}`)}return{family:e.family,kind:e.kind,version:1,generate:o,schema:a,parse:i,is:e=>i(e).ok}}var pc=r(X(),Ie({family:X(),kind:X(),version:Me(1),generate:u(),schema:Te(R),parse:u(),is:u()})),mc=class extends Error{name=`CairnDefinitionError`;code=`invalid_definition`;constructor(){super(`Cairn identifier family definition is invalid`)}},hc=class extends Error{name=`CairnGenerationError`;code=`entropy_unavailable`;family;kind;version=1;constructor(e){super(`Cairn entropy source is unavailable`),this.family=e.family,this.kind=e.kind}};function gc(e){let t;try{t=oc.safeParse(e)}catch{throw new mc}if(!t.success)throw new mc;let n=t.data,r={};for(let[t,i]of Object.entries(n.kinds)){let a=i.prefix;r[t]=fc({family:e.family,kind:t,prefix:a,entropyUnavailable:()=>new hc({family:n.family,kind:t})})}let i=w(e=>{let t=pc.safeParse(e);if(!t.success)return!1;let r=Object.entries(t.data);return r.length===Object.keys(n.kinds).length&&r.every(([e,t])=>Object.hasOwn(n.kinds,e)&&t.kind===e&&t.family===n.family)}).safeParse(r);if(!i.success)throw new mc;return i.data}var _c=[];for(let e=0;e<256;++e)_c.push((e+256).toString(16).slice(1));function vc(e,t=0){return(_c[e[t+0]]+_c[e[t+1]]+_c[e[t+2]]+_c[e[t+3]]+`-`+_c[e[t+4]]+_c[e[t+5]]+`-`+_c[e[t+6]]+_c[e[t+7]]+`-`+_c[e[t+8]]+_c[e[t+9]]+`-`+_c[e[t+10]]+_c[e[t+11]]+_c[e[t+12]]+_c[e[t+13]]+_c[e[t+14]]+_c[e[t+15]]).toLowerCase()}var yc,bc=new Uint8Array(16);function xc(){if(!yc){if(typeof crypto>`u`||!crypto.getRandomValues)throw Error(`crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported`);yc=crypto.getRandomValues.bind(crypto)}return yc(bc)}var Sc={randomUUID:typeof crypto<`u`&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Cc(e,t,n){if(Sc.randomUUID&&!t&&!e)return Sc.randomUUID();e||={};let r=e.random??e.rng?.()??xc();if(r.length<16)throw Error(`Random bytes length must be >= 16`);if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){if(n||=0,n<0||n+16>t.length)throw RangeError(`UUID byte range ${n}:${n+15} is out of buffer bounds`);for(let e=0;e<16;++e)t[n+e]=r[e];return t}return vc(r)}var wc=Ue({version:`v7`}),Tc=X().regex(/^replay_[a-f0-9]{64}$/);w(e=>Tc.safeParse(e).success);var Ec=Ue({version:`v4`});w(e=>wc.safeParse(e).success);var Dc=w(e=>Ec.safeParse(e).success);function Oc(){return Dc.parse(Cc())}var kc=class extends br{#e=!0;#t;#n=new Map;constructor(e){super(),this.#t=e}cancel(e){try{return this.#n.get(Jn(e))?.abort(),Promise.resolve(Os(void 0))}catch(e){return Promise.resolve(ks(e))}}dispose(){if(this.#e){this.#e=!1;for(let e of this.#n.values())e.abort();this.#n.clear()}}async invoke(e){try{if(!this.#e)throw new q(`The command is disposed`,{code:`DISCONNECTED`,retryable:!0});let t=Yr(e);if(this.#n.has(t.requestId))throw new q(`Duplicate command request`,{code:`PROTOCOL`,retryable:!1});if(this.#n.size>=64)throw new q(`Too many command requests`,{code:`HOST_FAILURE`,retryable:!0});let n=new AbortController;this.#n.set(t.requestId,n);try{let e=await this.#t(Vn(t,n.signal)),r=wn(e);return Os(r===void 0?{status:`handled`}:{status:`handled`,result:r})}finally{this.#n.delete(t.requestId)}}catch(e){if(e instanceof Hr)try{let t={code:e.code,message:e.message,details:e.details};return Os({status:`failed`,error:Jr(t)})}catch(e){return ks(e)}return ks(e)}}[Symbol.dispose](){this.dispose()}};function Ac(e){let t=[];for(let n of e.values()){let{commandId:e,definition:r,target:i}=n;if(e===void 0)continue;let a=r.availability?.status!==`unavailable`;for(let n of r.projections?.bindings?.values??[])n.trim().includes(` `)||n.startsWith(`<`)||t.push({key:n,run:()=>{a&&Promise.resolve().then(async()=>{let t=js(await i.invoke({commandId:e,origin:`keyboard`,requestId:Oc()}));if(t.status===`failed`)throw new Hr(t.error.code,t.error.message,t.error.details)}).catch(e=>{console.warn(`App key command failed`,e)})}})}return t}function jc(e,t,n,r){let i=new Map,a=!1,o=()=>{r?.update(a?[]:Ac(i))},s=e=>{try{n()}catch(t){console.warn(`App command failure callback failed`,t,e)}},c=e=>{try{As(e(),Tr).catch(e=>{s(e)})}catch(e){console.warn(`App command RPC supervision failed`,e),s(e)}};return{commands:Nc(e,t,i,()=>a,t=>{let n=i.get(t);if(!n)return;i.delete(t),n.target.dispose(),o();let r=n.commandId;!a&&r!==void 0&&c(()=>e.unregisterCommand(r))},o),dispose(){if(!a){a=!0;for(let e of i.values())e.target[Symbol.dispose]();i.clear(),o()}}}}function Mc(e,t,n){let r=t.id;if(e.size>=128||e.has(r))throw n.dispose(),new q(`Command registration is unavailable`,{code:`INVALID_ARGUMENT`,retryable:!1});let i={commandId:void 0,definition:t,target:n};e.set(r,i);let a=!1;return{commit(e){a||(i.commandId=e)},release(){a||(a=!0,e.get(r)===i&&e.delete(r),n.dispose())},target:n}}function Nc(e,t,n,r,i,a){return Object.freeze({async register(o,s){if(t(),!gt(s))throw new q(`Command handler must be a function`,{code:`INVALID_ARGUMENT`,retryable:!1});let c=zn(o),l=new kc(s),u=Mc(n,c,l);try{let t=await Pc(e,c,u.target);r()&&await Fc(e,t.commandId,l),u.commit(t.commandId),a()}catch(e){throw u.release(),e}let d=!0;return()=>{d&&(d=!1,i(c.id))}}})}async function Pc(e,t,n){return As(e.registerCommand(t,n),Rr)}async function Fc(e,t,n){throw n.dispose(),await As(e.unregisterCommand(t),Tr),new q(`The command controller is disposed`,{code:`DISCONNECTED`,retryable:!0})}var Ic=l(e=>e instanceof Dr),Lc=class extends br{#e=!1;#t;constructor(e){super(),this.#t=e}disconnect(e){try{if(this.#e)throw Jc();let t=e===void 0?void 0:$n(e);return setTimeout(()=>this.#t.disconnect?.(t??Qc()),0),Promise.resolve(Os(void 0))}catch(e){return Promise.resolve(ks(e))}}async requestClose(){try{if(this.#e)throw Jc();return Os(await(this.#t.beforeClose?.()??!0))}catch(e){return ks(e)}}async requestBack(){try{if(this.#e)throw Jc();return Os(await(this.#t.back?.()??!1))}catch(e){return ks(e)}}async requestForward(){try{if(this.#e)throw Jc();return Os(await(this.#t.forward?.()??!1))}catch(e){return ks(e)}}async activateNavigation(e){try{if(this.#e)throw Jc();let t=nr(e);return gr(this.#t.navigation,t)?Os(await(this.#t.activate?.(t)??!1)):Os(!1)}catch(e){return ks(e)}}async activateStatus(e){try{if(this.#e)throw Jc();let t=cr(e);return Mr(this.#t.statusItems,t)?Os(await(this.#t.statusAction?.(t)??!1)):Os(!1)}catch(e){return ks(e)}}[Symbol.dispose](){this.#e=!0}async updateContext(e){return this.#e?ks(Jc()):this.#n(e,`context`,Pn,e=>{this.#t.context.update(e)})}reconfigure(e){let t=[];try{if(this.#e)throw Jc();let n=Rn(e);if(n.context.version<=this.#t.versions.context)return Promise.resolve(Os(void 0));for(let e of n.capabilities)t.push({...e,handle:xe(Ic)(e.handle).dup()});if(!this.#t.capabilities)throw Jc();return this.#t.capabilities.replace(t),t=[],this.#t.versions.context=n.context.version,this.#t.context.update(n.context.value),Promise.resolve(Os(void 0))}catch(e){for(let e of t)Sn(e.handle);return Promise.resolve(ks(e))}}updateLifecycle(e){try{if(this.#e)throw Jc();let t=tr(Ln)(e);if(t.version<=this.#t.versions.lifecycle)return Promise.resolve(Os(void 0));if(!$c(this.#t.lifecycle.get(),t.value))throw new q(`The host sent an invalid lifecycle transition`,{code:`PROTOCOL`,retryable:!1});return this.#t.versions.lifecycle=t.version,this.#t.lifecycle.update(t.value),Promise.resolve(Os(void 0))}catch(e){return Promise.resolve(ks(e))}}async updateReservedChords(e){return this.#e?ks(Jc()):this.#n(e,`chords`,kr,e=>{this.#t.chords.update(e)})}async updateTheme(e){return this.#e?ks(Jc()):this.#n(e,`theme`,Ir,e=>{this.#t.theme.update(e)})}#n(e,t,n,r){try{let i=tr(n)(e);return i.version>this.#t.versions[t]&&(this.#t.versions[t]=i.version,r(i.value)),Promise.resolve(Os(void 0))}catch(e){return Promise.resolve(ks(e))}}};async function Rc(e){let t=Hc(),n=new Lc(t),r=vr(e.port,n),i,a=Vc(r);try{performance.mark(`fungi.app-open.agar-rpc-connect-start`);let o=await Promise.race([r.connect({epoch:e.epoch,protocolVersion:2}),a]);performance.mark(`fungi.app-open.agar-rpc-connect-ready`),i=o;let s=js(Kn(o));if(!e.isActive())throw Bc();let c=Uc({bootstrap:s,bootstrapOwner:i,options:e,remote:r,state:t,target:n});return performance.mark(`fungi.app-open.agar-root-created`),i=void 0,c}catch(t){return tl(t,e,n,r,i)}}function zc(e,t){e.context.update(t.context.value),e.theme.update(t.theme.value),e.lifecycle.update(t.lifecycle.value),e.chords.update(t.chords.value),e.versions.context=t.context.version,e.versions.theme=t.theme.version,e.versions.lifecycle=t.lifecycle.version,e.versions.chords=t.chords.version}function Bc(){return new q(`App connection was cancelled`,{code:`CANCELLED`,retryable:!1})}function Vc(e){let t,n=new Promise((e,n)=>{t=n});return n.catch(e=>{or(`app-session.rpc-disconnect`,e)}),e.onRpcBroken(()=>t?.(new q(`The app host disconnected`,{code:`DISCONNECTED`,retryable:!0}))),n}function Hc(){return{statusItems:[],navigation:{canGoBack:!1,canGoForward:!1},bindings:Ps(),chords:Fs([]),context:Sr({computerId:null,focus:{editing:!1,surface:null},openRequest:null,visibility:`hidden`}),lifecycle:Sr(`connecting`),theme:Sr(`default`),canGoBack:!1,canGoForward:!1,versions:{chords:-1,context:-1,lifecycle:-1,theme:-1}}}function Uc(e){let t=Nr(e.bootstrap.identity),n=el(e.bootstrap);zc(e.state,n);let r=Cr(e.bootstrap.capabilities);return e.state.capabilities=r,Gc(e,t,r)}function Wc(e,t,n){return Is({bindings:e.state.bindings,chords:e.state.chords,identity:t,onBroken:e=>{n({code:`DISCONNECTED`,message:e instanceof q?e.message:`The app host rejected a browser bridge operation`,retryable:!0})},remote:e.remote,window:e.options.window})}function Gc(e,t,n){let r=!1,i=t=>{r||(r=!0,Xc([()=>{t&&e.state.lifecycle.update(`disconnected`)},()=>{e.state.lifecycle.update(`disposing`)},l,u,()=>{o.dispose()},()=>{e.state.beforeClose=void 0,e.state.back=void 0,e.state.forward=void 0,e.state.activate=void 0,e.state.statusAction=void 0},()=>{n.disconnect()},()=>{e.target[Symbol.dispose]()},()=>{Sn(e.bootstrapOwner)},()=>{Sn(e.remote)},()=>{e.options.port.close()},()=>{e.state.lifecycle.update(`disposed`)},e.options.onDisposed],`app connection disposal`))},a=()=>{if(r)throw new q(`The app connection is disposed`,{code:`DISCONNECTED`,retryable:!0})},o=jc(e.remote,a,()=>{i({code:`DISCONNECTED`,message:`The app host rejected a terminal command operation`,retryable:!0})},e.state.bindings),s=qc(e.remote,a,e.state),c=Kc(e.state,e.remote,a),l=Wc(e,t,i),u=Us({window:e.options.window,mac:Js(),canGoBack:()=>e.state.canGoBack&&e.state.back!==void 0,back:()=>{let t=e.state.back;t&&Promise.resolve().then(t).catch(e=>{or(`app-window.back-input`,e)})},canGoForward:()=>e.state.canGoForward&&e.state.forward!==void 0,forward:()=>{let t=e.state.forward;t&&Promise.resolve().then(t).catch(e=>{or(`app-window.forward-input`,e)})}});return e.state.disconnect=i,e.remote.onRpcBroken(()=>{Yc(i)}),Zc({capabilities:n.directory,commands:o.commands,context:e.state.context,dispose:i,identity:t,lifecycle:e.state.lifecycle,theme:e.state.theme,ui:s,window:c})}function Kc(e,t,n){let r=Object.freeze({async publish(r){n();let i=qn(r);e.canGoBack=i.canGoBack,e.canGoForward=i.canGoForward,e.navigation=ir(i),await As(t.reportNavigation(i),Tr)},onActivate(t){if(n(),e.activate!==void 0)throw new q(`The App already owns navigation activations`,{code:`INVALID_ARGUMENT`,retryable:!1});e.activate=t;let r=!1;return()=>{r||(r=!0,e.activate===t&&(e.activate=void 0))}},onForward(t){if(n(),e.forward!==void 0)throw new q(`The App already owns Forward requests`,{code:`INVALID_ARGUMENT`,retryable:!1});e.forward=t;let r=!1;return()=>{r||(r=!0,e.forward===t&&(e.forward=void 0))}},onBack(t){if(n(),e.back!==void 0)throw new q(`The App already owns Back requests`,{code:`INVALID_ARGUMENT`,retryable:!1});e.back=t;let r=!1;return()=>{r||(r=!0,e.back===t&&(e.back=void 0))}}});return Object.freeze({navigation:r,onBeforeClose(t){if(n(),e.beforeClose!==void 0)throw new q(`The App already owns a close consultation`,{code:`INVALID_ARGUMENT`,retryable:!1});e.beforeClose=t;let r=!1;return()=>{r||(r=!0,e.beforeClose===t&&(e.beforeClose=void 0))}}})}function qc(e,t,n){return Object.freeze({async requestComputerChoice(){t(),await As(e.requestComputerChoice(),Tr)},async requestBrowserAction(n){t();let r=jn(n);return r.kind===`refused`?r:await As(e.requestBrowserAction(r),Fn)},onStatusAction(e){if(t(),n.statusAction!==void 0)throw new q(`The App already owns its status actions`,{code:`INVALID_ARGUMENT`,retryable:!1});n.statusAction=e;let r=!1;return()=>{r||(r=!0,n.statusAction===e&&(n.statusAction=void 0))}},async requestAppPermissions(n){return t(),await As(e.requestAppPermissions(mr(n)),xn)},async openDesktopSettings(){t(),await As(e.openDesktopSettings(),Tr)},async openSetup(n){return t(),await As(e.openSetup(Fr(n)),xr)},async openTeamBilling(){t(),await As(e.openTeamBilling(),Tr)},async openNavigation(n){t(),await As(e.openNavigation(rr(n)),Tr)},async reportStatus(r){t();let i=Ar(r);n.statusItems=i,await As(e.reportStatus(i),Tr)},async reportAgentSessionSelection(n){t(),await As(e.reportAgentSessionSelection(Un(n)),Tr)},async showToast(n){t(),await As(e.showToast(dr(n)),Tr)}})}function Jc(){return new q(`The app connection is disposed`,{code:`DISCONNECTED`,retryable:!0})}function Yc(e){e({code:`DISCONNECTED`,message:`The app host disconnected`,retryable:!0})}function Xc(e,t){for(let n of e)try{n()}catch(e){console.warn(`${t} cleanup failed`,e)}}function Zc(e){return Object.freeze(e)}function Qc(){return{code:`DISCONNECTED`,message:`The app host disconnected`,retryable:!1}}function $c(e,t){return e===t||e===`connected`&&t===`suspended`||e===`suspended`&&t===`connected`}function el(e){let t=tr(Pn)(e.context),n=tr(Ir)(e.theme),r=tr(Ln)(e.lifecycle),i=tr(kr)(e.reservedChords);if(r.value!==`connected`&&r.value!==`suspended`)throw new q(`The bootstrap lifecycle is invalid`,{code:`PROTOCOL`,retryable:!1});return{chords:i,context:t,lifecycle:r,theme:n}}function tl(e,t,n,r,i){throw Xc([()=>{n[Symbol.dispose]()},()=>{i&&Sn(i)},()=>{Sn(r)},()=>{t.port.close()},t.onDisposed],`app connection rejection`),e instanceof q?e:new q(`Unable to establish the app RPC session`,{cause:e,code:`PROTOCOL`,retryable:!1})}var nl=!1,rl=class{options;#e;#t;#n=!1;#r;#i;constructor(e){this.options=e,this.#e=globalThis.window}start(){performance.mark(`fungi.app-open.agar-connect-start`);let e=this.#l();return e?Promise.reject(e):(nl=!0,this.#a())}#a(){return new Promise((e,t)=>{let n=(n,a)=>{this.#o(n,a,i,r,e,t)},r=()=>{n(al())},i=e=>{this.#s(e,n,i)};this.#e.addEventListener(`message`,i),this.options.signal?.addEventListener(`abort`,r,{once:!0});let a=()=>{try{performance.mark(`fungi.app-open.agar-ready-sent`),this.#e.parent.postMessage({protocolVersion:2,type:pr},`*`)}catch(e){or(`connect.notify-host`,e),n(dl(e))}};this.#r=setInterval(a,200),this.#i=setTimeout(()=>{n(sl())},1e4),a()})}#o(e,t,n,r,i,a){if(!this.#n){if(this.#n=!0,this.#c(),this.#e.removeEventListener(`message`,n),this.options.signal?.removeEventListener(`abort`,r),e||!t){this.#t?.close(),nl=!1,a(e??sl());return}i(t)}}#s(e,t,n){if(!ul(e.data))return;if(performance.mark(`fungi.app-open.agar-connect-received`),e.source!==this.#e.parent||cl(e.origin)===void 0){t(ll());return}let r=fl(e,t);if(!r)return;let i=e.ports.length===1?e.ports[0]:void 0;if(!i){t(pl(`The app host did not transfer exactly one port`));return}this.#t=i,this.#c(),this.#e.removeEventListener(`message`,n),Rc({epoch:r.epoch,isActive:()=>!this.#n,onDisposed:()=>{nl=!1},port:i,window:this.#e}).then(e=>{performance.mark(`fungi.app-open.agar-root-ready`),t(void 0,e)},e=>{t(ol(e))})}#c(){clearInterval(this.#r),clearTimeout(this.#i),this.#r=void 0,this.#i=void 0}#l(){if(this.options.signal?.aborted)return al();if(nl)return new q(`An app connection is already live`,{code:`IDENTITY`,retryable:!1});if(G(globalThis.window)||this.#e.parent===this.#e)return new q(`The app host is unavailable`,{code:`DISCONNECTED`,retryable:!0})}};function il(e){return new rl(e).start()}function al(){return new q(`App connection was cancelled`,{code:`CANCELLED`,retryable:!1})}function ol(e){return e instanceof q?e:new q(`Unable to connect to the app host`,{cause:e,code:`PROTOCOL`,retryable:!1})}function sl(){return new q(`The app host disconnected`,{code:`DISCONNECTED`,retryable:!0})}function cl(e){if(!URL.canParse(e))return;let t=new URL(e).origin;return t===e?t:void 0}function ll(){return new q(`The app connection identity is invalid`,{code:`IDENTITY`,retryable:!1})}var ul=P(V({type:rn(Br)}));function dl(e){return new q(`Unable to notify the app host`,{cause:e,code:`DISCONNECTED`,retryable:!0})}function fl(e,t){try{return er(e.data)}catch(e){or(`connect.decode-message`,e),t(e instanceof q?e:new q(`Malformed app connection`,{cause:e,code:`PROTOCOL`,retryable:!1}));return}}function pl(e){return new q(e,{code:`PROTOCOL`,retryable:!1})}var ml=ii();function hl(e,t,n){e.style.isolation=`isolate`;let r=(0,ml.createRoot)(e),i=new AbortController,a=e.ownerDocument.documentElement,o=ni(a),s,c,l,u=!1,d=e=>{let i=(0,Z.createElement)(gl,{state:e,render:n});r.render(t.queryClient?(0,Z.createElement)(Mn,{client:t.queryClient},i):i)},f=()=>{l?.(),l=void 0,c?.(),c=void 0;let e=s;s=void 0,e?.dispose(),u&&=(o===null?a.removeAttribute(`data-theme`):ti(o,a),!1)},{defaultView:p}=e.ownerDocument;return performance.mark(`fungi.app-open.react-root-render-start`),p?p.parent===p?d({app:null,status:`standalone`}):(d({app:null,status:`connecting`}),il({host:`parent`,signal:i.signal}).then(e=>{if(i.signal.aborted){e.dispose();return}s=e;let t=()=>{let t=e.lifecycle.get();return t===`disposing`||t===`disconnected`||t===`disposed`?(f(),d({app:null,status:`ended`}),!0):!1};l=e.lifecycle.subscribe(t),!t()&&(u=!0,ti(e.theme.get(),a),c=e.theme.subscribe(e=>{ti(e,a)}),d({app:e,status:`live`}))}).catch(e=>{i.signal.aborted&&e instanceof q&&e.code===`CANCELLED`||(console.error(`${t.name} host connection failed`,e),f(),i.signal.aborted||d({app:null,status:`not-hosted`,error:e instanceof q?e:new q(`The App host is unavailable`,{cause:e,code:`HOST_FAILURE`,retryable:!0})}))})):d({app:null,status:`not-hosted`,error:new q(`The App document has no window`,{code:`DISCONNECTED`,retryable:!1})}),()=>{i.signal.aborted||(i.abort(),r.unmount(),f())}}function gl({state:e,render:t}){return(0,Z.useLayoutEffect)(()=>{performance.mark(`fungi.app-open.react-initial-commit`)},[]),(0,Z.useLayoutEffect)(()=>{e.app&&performance.mark(`fungi.app-open.react-connected-commit`)},[e.app]),(0,Z.createElement)(Z.Fragment,null,e.status===`not-hosted`?(0,Z.createElement)(`p`,{role:`alert`},`App host connection unavailable. Open this App through its host to try again.`):null,t(e))}var _l=O([V({kind:rn(`compose`),text:_t.pipe(_n(pe(1)),_n(Fe(2e3)))}),V({kind:rn(`navigate`),params:cn(V({key:_t.pipe(_n(pe(1)),_n(Fe(64))),value:_t.pipe(_n(Fe(1024)))})).pipe(_n(Fe(16)))})]);O([V({role:_t.pipe(_n(pe(1)),_n(Fe(80))),intent:_l}),V({appId:_t.pipe(_n(pe(1)),_n(Fe(128))),intent:_l})],{mode:`oneOf`});var vl=Y({displayName:X().min(1).max(80).nullable()}).nullable();Yn(`apps.open`,1,j(()=>qr({open:Gr,role:lr(Vr(vl))})));var yl=Yn(`apps.call`,1,j(()=>qr({call:lr(Vr(Vt().transform(e=>ur(e))))}))),Q=fn(),bl={neutral:`alert-neutral`,primary:`alert-primary`,secondary:`alert-secondary`,accent:`alert-accent`,success:`alert-success`,info:`alert-info`,warning:`alert-warning`,error:`alert-error`},xl=(0,Z.forwardRef)(function({action:e,children:t,className:n,description:r,title:i,tone:a=`neutral`,...o},s){return(0,Q.jsxs)(`div`,{...o,className:mn(`alert caps-alert`,bl[a],n),"data-tone":a,role:o.role??`alert`,ref:s,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[i?(0,Q.jsx)(`h3`,{className:`font-semibold`,children:i}):null,r?(0,Q.jsx)(`p`,{className:`text-sm`,children:r}):null,t]}),e?(0,Q.jsx)(`div`,{className:`shrink-0`,children:e}):null]})}),Sl=j(()=>X().regex(/^(container|vm-[a-z0-9][a-z0-9-]{0,62}|local-[a-z2-7]{16})$/)),Cl=new TextEncoder,wl=131072,Tl=16384,El=Object.freeze({maximumTimeMs:12e4}),Dl=zt(),Ol=j(()=>X().min(1).max(128).regex(/^[A-Za-z][A-Za-z0-9_]*$/)),kl=j(()=>J().int().min(1).max(65535));Y({port:kl}),j(()=>Y({port:kl,exposed:Oe()})),j(()=>Y({port:kl,removed:Oe()})),j(()=>Y({ports:Se(kl).max(64)}));var Al=j(()=>r(X(),Vt()).refine(e=>Dl.safeParse(e).success,`Capability schema must contain JSON values`));j(()=>Se(Y({id:Ol,name:Ol,kind:X(),description:X(),parameters:Al,output:Al})));var $=X().min(1).max(4096).startsWith(`/`).refine(e=>!e.includes(`\0`),`Path cannot contain null bytes`),jl=(e=0)=>X().min(e).refine(e=>Cl.encode(e).byteLength<=wl,`Text exceeds the ${String(wl)}-byte Computer bound`);Y({path:$}),j(()=>Y({path:$,content:jl()}));var Ml=Y({path:$,byteOffset:J().int().nonnegative().optional(),byteLength:J().int().positive().max(wl).optional()});j(()=>Y({path:Ml.shape.path,byteOffset:J().int().nonnegative(),content:X(),encoding:Me(`base64`),truncated:Oe()})),j(()=>Y({previewUrl:ft(),expiresAt:J().int().positive()}));var Nl=J().int().min(1).max(256).default(100),Pl=J().int().nonnegative().default(0);Y({path:$.default(`/`),limit:Nl,offset:Pl});var Fl=j(()=>Y({name:X(),size:J().int().nonnegative(),modifiedAt:J(),type:yn({file:`file`,directory:`directory`,symlink:`symlink`})}));j(()=>Y({path:$,entries:Se(Fl).max(256),nextOffset:J().int().nonnegative().nullable()}));var Il=j(()=>X().refine(e=>Cl.encode(e).byteLength<=wl,`File exceeds the Computer write bound`));Y({path:$,content:Il}),j(()=>Y({path:$,bytes:J().int().nonnegative()})),Y({path:$,expectedContent:Il,content:Il}),j(()=>Y({path:$,pattern:X().min(1).max(512),limit:J().int().min(1).max(256).default(256)})),j(()=>Y({path:$,matches:Se($).max(256),truncated:Oe()})),j(()=>Y({path:$,pattern:X().min(1).max(512),regex:Oe().default(!1),ignoreCase:Oe().default(!1),include:X().min(1).max(512).optional(),limit:J().int().min(1).max(256).default(256)})),j(()=>Y({path:$,matches:Se(Y({path:$,line:J().int().positive(),text:X()})).max(256),truncated:Oe()})),j(()=>Y({path:$,oldText:jl(1),newText:jl()})),j(()=>Y({path:$,bytes:J().int().nonnegative(),diff:X(),firstChangedLine:J().int().positive().nullable()})),j(()=>Y({path:$,recursive:Oe().default(!0)})),Y({path:$}),Y({from:$,to:$,createParents:Oe().default(!1)}),Y({from:$,to:$});var Ll=Ue({version:`v7`});function Rl(e){return Y({command:X().min(1).max(Tl),cwd:$.optional(),backend:Sl.optional(),timeoutMs:J().int().min(1).max(e.maximumTimeMs).default(1e4)})}Rl(El).extend({requestId:Ll});var zl=Y({stream:yn({stdout:`stdout`,stderr:`stderr`}),keptBytes:J().int().nonnegative(),totalBytes:J().int().positive()}),Bl=Y({status:yn({completed:`completed`,failed:`failed`,cancelled:`cancelled`}),exitCode:J().int(),stdout:X(),stderr:X(),truncated:kt([Me(!1),Se(zl).min(1)])}),Vl=gc({family:`computer-process`,version:1,kinds:{process:{prefix:`computer_process`}}}).process,Hl=j(()=>X().refine(e=>Vl.is(e)));Y({requestId:X().min(1).max(256),requestScope:X().min(1).max(512),port:kl.optional(),command:X().min(1).max(Tl),cwd:$.optional()}).omit({requestId:!0,requestScope:!0}),Y({id:Hl});var Ul=yn({running:`running`,exited:`exited`,uncertain:`uncertain`}),Wl=yn({synced:`synced`,pending:`pending`,unknown:`unknown`}),Gl=Y({id:Hl,port:kl.nullable(),command:X(),cwd:X().nullable(),state:Ul,exitCode:J().int().nullable(),sync:Wl,startedAt:J().int(),endedAt:J().int().nullable(),endedReason:Me(`idle-sleep`).nullable()});Y({processes:Se(Gl).max(64)}),Y({id:Hl,lines:J().int().min(1).max(200).optional()}),Y({process:Gl,lines:Se(X().max(2e3)).max(200),truncated:Oe()}),j(()=>Y({process:Gl,signalled:Oe()}));var Kl=yn({accepted:`accepted`,running:`running`,succeeded:`succeeded`,failed:`failed`,unknown:`unknown`,expired:`expired`});Y({requestId:Ll,status:Kl,output:Bl.nullable()}).omit({requestId:!0}),yn({"files.read":`files.read`,"files.readBytes":`files.readBytes`,"files.write":`files.write`,"files.writeBytes":`files.writeBytes`,"files.list":`files.list`,"files.glob":`files.glob`,"files.grep":`files.grep`,"files.edit":`files.edit`,"files.patch":`files.patch`,"files.move":`files.move`,mkdir:`mkdir`,bash:`bash`,exec:`exec`});var ql=gc({family:`inkcap`,version:1,kinds:{document:{prefix:`inkcap_document`}}}),Jl=J().int().positive().max(2**53-1),Yl=Y({computerId:X().min(1).max(256),path:$.refine(e=>!e.split(`/`).includes(`..`),`Parent path segments are not allowed`)}),Xl=Yl.extend({id:X().refine(e=>ql.document.is(e),`Invalid document identity`),activity:yn([`opened`,`edited`]),occurredAt:J().int().nonnegative().max(2**53-1),sequence:Jl});Y({limit:J().int().min(1).max(50).default(20),after:Y({before:Jl}).optional()}),Y({rows:Se(Xl).max(50),next:Y({before:Jl}).nullable()});var Zl=Y({recorded:Me(!0)}),Ql=Y({error:Me(`not_granted`)});Yn(`app.backend`,1,j(()=>qr({request:lr(Vr(Vt().transform(e=>ur(e))))})));var $l=Yn(`app.methods`,1,j(()=>qr({call:lr(Vr(Vt().transform(e=>ur(e))))})));async function eu(e,t,n,r){try{let i=Yl.parse({computerId:t,path:n}),a=await e.capabilities.require($l).call(`documents.${r}`,JSON.stringify(i));if(Ql.safeParse(a).success)throw Error(`Document activity was not admitted`);return Zl.parse(a),!0}catch(e){return console.error(`Inkcap document activity could not be recorded`,Bn(e)),!1}}var tu=X().regex(/^[a-zA-Z0-9._-]{1,128}$/).refine(e=>e!==`.`&&e!==`..`),nu=X().regex(/^[0-9a-f]{40}$/);Y({ref:X().startsWith(`refs/`).max(1024),before:nu,after:nu}),j(()=>X().min(1).max(512));var ru=Y({name:X(),email:X()}),iu=Y({hash:nu,treeHash:nu,message:X(),author:ru,committer:ru,parents:Se(nu),authoredAt:J(),committedAt:J()}),au=Y({name:X(),mode:X(),hash:nu,type:yn([`blob`,`tree`,`commit`])}),ou=Y({ref:X(),commit:iu,path:X(),entries:Se(au)}),su=65536,cu=X().min(1).max(1024).refine(e=>!e.startsWith(`/`)&&!e.includes(`\\`)&&!e.includes(`\0`)&&e.split(`/`).every(e=>e!==``&&e!==`.`&&e!==`..`&&e!==`.git`),`Choose a relative repository file path.`),lu=X().min(1).max(256),uu={repo:tu,branch:lu,path:cu},du=yn([`pending`,`synced`,`conflict`,`failed`]),fu=Y({text:X(),revision:J().int().positive(),state:du,theirs:Y({blob:nu.nullable(),commit:nu}).optional(),failure:yn([`branch_missing`,`access_changed`,`sync_failed`,`permanent_material`]).optional()}),pu=Y({...uu,baseBlob:nu.nullable(),baseCommit:nu,text:X().max(su),revision:J().int().positive().nullable()}),mu=kt([Y({kind:Me(`saved`),revision:J().int().positive(),state:Me(`pending`)}),Y({kind:Me(`synced`),revision:J().int().positive(),commit:nu}),Y({kind:Me(`conflict`),revision:J().int().nonnegative(),theirs:fu.shape.theirs.optional()}),Y({kind:Me(`failed`),revision:J().int().positive(),reason:yn([`branch_missing`,`access_changed`,`sync_failed`,`permanent_material`])}),Y({kind:Me(`refused`),reason:yn([`not-source-writer`,`background-unavailable`])})]),hu=Y({...uu,revision:J().int().positive()}),gu=kt([Y({kind:yn([`discarded`,`not_found`])}),Y({kind:Me(`conflict`),revision:J().int().positive()})]),_u=Y({settled:Se(Y({...uu,result:mu})),more:Oe()}),vu=Y({version:J().int().positive().nullable(),commit:nu,blob:nu.nullable(),pending:fu.optional(),ref:X(),path:X(),size:J(),binary:Oe(),text:X().nullable()}),yu=Y({ref:X(),commits:Se(Y({commit:iu,agent:X().nullable()})),next:X().optional()}),bu=Y({ref:X(),commit:iu,paths:Se(X()),truncated:Oe()}),xu=Y({kind:Me(`rebuilding`)}),Su=Y({done:Oe(),cursor:X().nullable()}),Cu=kt([Y({repository:tu,branch:lu,path:cu}),Y({path:X().min(1).max(1024)})]);function wu(e){let t=Cu.safeParse(Object.fromEntries(e.map(({key:e,value:t})=>[e,t])));return t.success?t.data:null}function Tu(e){let t=[],n=[],r=e,i=Eu(r,t,n),a=new Set,o=()=>{i=Eu(r,t,n);for(let e of a)e(i)};return Object.freeze({get:()=>i,subscribe(e){return a.add(e),()=>{a.delete(e)}},push(e){t.push(r),n.length=0,r=e,o()},replace(e){r=e,o()},back(){let e=t.pop();return e!==void 0&&(n.push(r),r=e,o(),!0)},forward(){let e=n.pop();return e!==void 0&&(t.push(r),r=e,o(),!0)}})}function Eu(e,t,n){return Object.freeze({current:e,canGoBack:t.length>0,canGoForward:n.length>0})}function Du(){return Tu(null)}function Ou(e,t){let{current:n}=e.get();n!==t&&(n===null?e.replace(t):e.push(t))}function ku(e,t){let n=Au(e),r=[],i=-1;n.entries.forEach((e,a)=>{e!==t&&(r.at(-1)!==e&&r.push(e),a<=n.index&&(i=r.length-1))});let a=Du();r.forEach(e=>{Ou(a,e)});for(let e=r.length-1-Math.max(0,i);e>0;e--)a.back();return a}function Au(e){let t=0;for(;e.back();)t++;let n=[];do{let{current:t}=e.get();t!==null&&n.push(t)}while(e.forward());for(let r=n.length-1-t;r>0;r--)e.back();return{entries:n,index:t}}var ju={id:`new-draft`,title:`New Draft`,category:`File`,description:`Create a new draft in Inkcap`,projections:{bindings:{values:[`<leader>n`],order:0},menu:{order:0},palette:{order:0}},action:{presentation:{type:`action`}}},Mu={id:`browse-files`,title:`Show Files`,category:`File`,description:`Choose a file to open from Explorer`,projections:{menu:{order:1},palette:{order:2}},action:{presentation:{type:`action`}}},Nu={id:`save`,title:`Save`,category:`File`,description:`Save the focused Inkcap document`,projections:{bindings:{values:[`mod+s`],order:1},menu:{order:2},palette:{order:1}},action:{presentation:{type:`action`}}},Pu={id:`save-as`,title:`Save As…`,category:`File`,description:`Save the focused Inkcap document under a new path`,projections:{menu:{order:3},palette:{order:3}},action:{presentation:{type:`action`}}},Fu={id:`open-file`,title:`Open File`,category:`File`,description:`Open a file handed off by another App`,projections:{menu:{order:4}},action:{inputSchema:{type:`object`,properties:{computerId:{type:`string`},path:{type:`string`}},required:[`computerId`,`path`],additionalProperties:!1},presentation:{type:`action`}}},Iu=V({computerId:_t.check(pe(1),Fe(256)),path:_t.check(pe(1),Fe(1024))});function Lu(e,t){let n=(0,Z.useRef)();(0,Z.useEffect)(()=>(n.current={app:e,binding:t},()=>{n.current=void 0}),[e,t]);let r=t.save?.()?.availability(),i=r?.status??`unavailable`,a=r?.status===`unavailable`?r.reason:r?void 0:`No focused savable dirty document.`,o=t.save?.()?.saveAsAvailability(),s=o?.status??`unavailable`,c=o?.status===`unavailable`?o.reason:o?void 0:`No open file to save as.`,l=(0,Z.useCallback)(()=>{let t=t=>{if(!(!e||t?.aborted||n.current?.app!==e||!Ru(e)))return n.current.binding};return[{...ju,handler:({signal:e})=>{t(e)?.newDraft()}},{...Mu,handler:({signal:e})=>{t(e)?.browseFiles()}},{...Nu,availability:()=>i===`available`?{status:`available`}:{status:`unavailable`,reason:a??`No focused savable dirty document.`},handler:async({signal:e})=>{let n=t(e);if(!n)return;let r=n.save?.();if(!r)throw Error(`No focused savable dirty document.`);let i=r.availability();if(i.status===`unavailable`)throw Error(i.reason);if(!await r.save())throw Error(`No focused savable dirty document.`)}},{...Pu,availability:()=>s===`available`?{status:`available`}:{status:`unavailable`,reason:c??`No open file to save as.`},handler:({signal:e})=>{let n=t(e);if(!n)return;let r=n.save?.();if(!r)throw Error(`No open file to save as.`);let i=r.saveAsAvailability();if(i.status===`unavailable`)throw Error(i.reason);r.saveAs()}},{...Fu,handler:async({arguments:e,signal:n})=>{let r=t(n);if(!r)return;if(!r.openFile)throw Error(`Inkcap is not ready to open a handed-off file.`);let i;try{i=xe(Iu,{onExcessProperty:`error`})(e)}catch(e){throw Error(`Inkcap open-file arguments are invalid.`,{cause:e})}await r.openFile(i)}}]},[e,i,a,s,c]);Tn(e,{sourceId:`inkcap-file`,namespace:`inkcap`},l)}function Ru(e){let t=e.lifecycle.get();return t!==`disposing`&&t!==`disposed`&&t!==`disconnected`}var zu=new Map([[`png`,`image/png`],[`jpg`,`image/jpeg`],[`jpeg`,`image/jpeg`],[`gif`,`image/gif`],[`webp`,`image/webp`],[`svg`,`image/svg+xml`],[`avif`,`image/avif`]]),Bu=new Map([[`mp4`,`video/mp4`],[`webm`,`video/webm`]]);function Vu(e){return zu.get(e.split(`.`).pop()?.toLowerCase()??``)}function Hu(e){return Bu.get(e.split(`.`).pop()?.toLowerCase()??``)}function Uu(e){let t=Vu(e);if(t)return{kind:`image`,mediaType:t};let n=Hu(e);if(n)return{kind:`video`,mediaType:n}}function Wu(e){return e.toLowerCase().endsWith(`.md`)}async function Gu(e,t){let n=t?.revision,r=await(await e()).arrayBuffer();if(t?.closed)return{kind:`closed`};if(t&&t.revision!==n)return{kind:`changed`};try{return{kind:`ready`,contents:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0}).decode(r)}}catch{return{kind:`invalid-text`}}}async function Ku(e,t){let n=t?.revision,r=await e();return t?.closed?{kind:`closed`}:t&&t.revision!==n?{kind:`changed`}:{kind:`ready`,blob:r}}async function qu(e,t,n,r){let i=()=>jr(e.capabilities,{path:t},{signal:n}),a=Uu(t);if(a){let e=await Ku(i,r);return e.kind===`ready`?{kind:a.kind,blob:e.blob.slice(0,e.blob.size,a.mediaType)}:e}let o=await Gu(i,r);return o.kind===`ready`?{kind:`text`,contents:o.contents}:o}var Ju=`/workspace`;function Yu(e){let t=e?.trim()??``;return t===``?Ju:t.startsWith(`/`)?t:`/${t}`}var Xu=e=>e.slice(e.lastIndexOf(`/`)+1),Zu=e=>{let t=e.lastIndexOf(`/`);return t<=0?`/`:e.slice(0,t)};async function Qu(e,t){let n=await $u(t,Zu(e),Xu(e));if(n.kind===`listed`)return n.found;let r=Zu(e);for(;r!==`/`;){let e=Zu(r),i=await $u(t,e,Xu(r));if(i.kind===`listed`){if(i.found)throw n.error;return!1}r=e}throw n.error}function $u(e,t,n){return e(t,n).then(e=>({kind:`listed`,found:e}),e=>({kind:`failed`,error:e}))}var ed=L(`ChevronsUpDown`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),td=L(`FileCode2`,[[`path`,{d:`M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4`,key:`1pf5j1`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`m5 12-3 3 3 3`,key:`oke12k`}],[`path`,{d:`m9 18 3-3-3-3`,key:`112psh`}]]),nd=L(`PanelLeft`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}]]),rd=8e3,id=(0,Z.forwardRef)(function({className:e,detail:t,framed:n=!0,icon:r,message:i,onRetry:a,size:o=`md`,slowAfterMs:s=rd,variant:c=`line`,...l},u){let[d,f]=(0,Z.useState)(!1);return(0,Z.useEffect)(()=>{if(f(!1),!Number.isFinite(s))return;let e=globalThis.setTimeout(()=>{f(!0)},s);return()=>{globalThis.clearTimeout(e)}},[s,i]),(0,Q.jsxs)(`div`,{...l,className:mn(`caps-loading-state`,e),"data-framed":n?void 0:`false`,"data-icon":r?``:void 0,"data-size":o,"data-slow":d||void 0,ref:u,role:`status`,children:[r?(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`caps-loading-state-icon`,children:r}):null,(0,Q.jsx)(vn,{decorative:!0,size:o,variant:c}),(0,Q.jsxs)(`span`,{className:`caps-loading-state-copy`,children:[(0,Q.jsx)(`span`,{children:i}),t?(0,Q.jsx)(`span`,{className:`caps-loading-state-detail`,children:t}):null,d?(0,Q.jsx)(`span`,{className:`caps-loading-state-detail`,children:`Still working…`}):null]}),d&&a?(0,Q.jsx)(K,{className:`caps-loading-state-retry`,size:`sm`,variant:`outline`,onClick:a,children:`Retry`}):null]})}),ad={2:`h2`,3:`h3`,4:`h4`};function od(e,t){let{reduced:n}=t,r=e&&!n,i=lt(t,600),[a,o]=(0,Z.useState)(r);return(0,Z.useEffect)(()=>{if(o(r),!r)return;let e=globalThis.setTimeout(()=>{o(!1)},i);return()=>{globalThis.clearTimeout(e)}},[r,i]),a}var sd=(0,Q.jsx)(vn,{decorative:!0,pace:`idle`,size:`md`,tone:`primary`,variant:`wander`}),cd=(0,Z.forwardRef)(function({actions:e,secondaryAction:t,className:n,description:r,headingLevel:i=2,primaryAction:a,suggestions:o,thinking:s=!1,title:c,visual:l,renderVisual:u,variant:d=`plain`,...f},p){let m=(0,Z.useId)(),h=(0,Z.useRef)(null),g=Be(h),_=od(d===`speech`,g)&&!s,v=ad[i],y=l??(d===`panel`?`blobs`:void 0),b=u?u({speaking:_,thinking:s}):y===`blobs`?sd:y,x=`${m}-reason`,S=(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(v,{ref:h,className:`empty-state-title`,id:f[`aria-labelledby`]?void 0:m,children:c}),(0,Q.jsx)(`p`,{children:r}),a?(0,Q.jsxs)(`div`,{className:`empty-state-primary`,children:[(0,Q.jsxs)(`div`,{className:`empty-state-action-row`,children:[(0,Q.jsx)(K,{"aria-describedby":a.disabled&&a.disabledReason?x:void 0,disabled:a.disabled,loading:a.pending===!0,onClick:a.onSelect,variant:`primary`,children:a.label}),t]}),a.disabled&&a.disabledReason?(0,Q.jsx)(`span`,{className:`empty-state-reason`,id:x,children:a.disabledReason}):null]}):null,o&&o.length>0?(0,Q.jsx)(`ul`,{"aria-label":`Try one of these`,className:`empty-state-suggestions`,children:o.map((e,t)=>(0,Q.jsx)(`li`,{children:(0,Q.jsx)(K,{disabled:e.disabled,loading:e.pending===!0,size:`sm`,variant:`outline`,onClick:e.onSelect,children:e.label})},`${String(t)}:${e.label}`))}):null,e?(0,Q.jsx)(`div`,{className:`empty-state-actions`,children:e}):null]});return(0,Q.jsxs)(`section`,{...f,"aria-labelledby":f[`aria-labelledby`]??m,className:mn(`empty-state`,d!==`plain`&&`empty-state-${d}`,n),ref:p,children:[b?(0,Q.jsx)(`div`,{"aria-hidden":`true`,className:`empty-state-visual`,children:b}):null,d===`speech`?(0,Q.jsx)(`div`,{className:`empty-state-bubble`,children:S}):S]})}),ld=(0,Z.createContext)(null),ud=(0,Z.forwardRef)(function({children:e,defaultValue:t,onValueChange:n,value:r,...i},a){let[o,s]=(0,Z.useState)(t),c=r??o,l=(0,Z.useId)(),u=e=>{r===void 0&&s(e),n?.(e)},d=(e,t)=>`${l}-${e}-${encodeURIComponent(t)}`;return(0,Q.jsx)(ld.Provider,{value:{onValueChange:u,panelId:e=>d(`panel`,e),selectedValue:c,tabId:e=>d(`tab`,e)},children:(0,Q.jsx)(`div`,{...i,className:mn(`w-full`,i.className),ref:a,children:e})})});function dd(){let e=(0,Z.useContext)(ld);if(!e)throw Error(`Tabs parts must be used inside <Tabs>`);return e}var fd=(0,Z.forwardRef)(function({className:e,variant:t=`bordered`,...n},r){return(0,Q.jsx)(`div`,{...n,"aria-orientation":n[`aria-orientation`]??`horizontal`,className:mn(t===`segmented`?`tabs caps-tabs-segmented w-full`:`tabs tabs-border flex w-full items-center gap-xs`,e),"data-variant":t,ref:r,role:`tablist`})}),pd=(0,Z.forwardRef)(function({className:e,disabled:t,onClick:n,onKeyDown:r,value:i,...a},o){let s=dd(),c=s.selectedValue===i,l=e=>{let t=e.currentTarget.closest(`[role="tablist"]`);if(!(t instanceof HTMLElement))return;let n=Array.from(t.querySelectorAll(`[role="tab"]`)).filter(e=>!e.disabled&&e.getAttribute(`aria-disabled`)!==`true`),r=n.indexOf(e.currentTarget);if(r<0||n.length===0)return;let a;if(e.key===`ArrowRight`)a=(r+1)%n.length;else if(e.key===`ArrowLeft`)a=(r-1+n.length)%n.length;else if(e.key===`Home`)a=0;else if(e.key===`End`)a=n.length-1;else return;e.preventDefault();let o=n[a];o?.focus(),o&&s.onValueChange(o.dataset.tabValue??i)};return(0,Q.jsx)(`button`,{...a,"aria-controls":s.panelId(i),"aria-disabled":t?!0:void 0,"aria-selected":c,className:mn(`tab whitespace-nowrap text-base-content transition-colors focus-visible:outline-none focus-visible:ring-2 caps-focus-color`,c&&`tab-active`,e),"data-tab-value":i,disabled:t,id:s.tabId(i),onClick:e=>{n?.(e),!e.defaultPrevented&&!t&&s.onValueChange(i)},onKeyDown:e=>{r?.(e),e.defaultPrevented||l(e)},ref:o,role:`tab`,tabIndex:t?-1:c?0:-1,type:a.type??`button`})}),md=(0,Z.forwardRef)(function({children:e,className:t,forceMount:n=!1,value:r,...i},a){let o=dd(),s=o.selectedValue===r;return!s&&!n?null:(0,Q.jsx)(`div`,{...i,"aria-labelledby":o.tabId(r),className:mn(`mt-md focus-visible:outline-none`,t),hidden:!s,id:o.panelId(r),ref:a,role:`tabpanel`,tabIndex:0,children:e})}),hd=(0,Z.forwardRef)(function({tone:e=`neutral`,size:t=`md`,pressed:n=!1,touch:r,className:i,...a},o){return(0,Q.jsx)(`kbd`,{...a,ref:o,className:mn(`caps-keycap`,i),"data-tone":e,"data-size":t,"data-pressed":n,"data-touch":r})});(0,Z.forwardRef)(function({label:e,shortcut:t,icon:n,readout:r,tone:i=`neutral`,density:a=`regular`,pressed:o,expanded:s,className:c,type:l=`button`,...u},d){let f=o??s;return(0,Q.jsxs)(`button`,{...u,ref:d,type:l,className:mn(`caps-keycap-button`,c),"data-tone":i,"data-density":a===`compact`?a:void 0,"aria-pressed":o,"aria-expanded":s,"aria-keyshortcuts":u[`aria-keyshortcuts`]??t,children:[f===void 0?null:(0,Q.jsx)(`span`,{className:`caps-keycap-led`,"data-lit":f,"aria-hidden":`true`}),n?(0,Q.jsx)(`span`,{className:`caps-keycap-button-icon`,"aria-hidden":`true`,children:n}):null,e===null?null:(0,Q.jsx)(`span`,{className:`caps-keycap-button-label`,children:e}),r,t?(0,Q.jsx)(hd,{size:`sm`,tone:`neutral`,touch:`hide`,"aria-hidden":`true`,children:t}):null]})});var gd=Z.createContext(void 0);function _d(e){let t=Z.useContext(gd);if(t===void 0&&!e)throw Error(ue(33));return t}var vd=Z.createContext(void 0);function yd(e){let t=Z.useContext(vd);if(t===void 0&&!e)throw Error(ue(36));return t}var bd=Z.createContext(void 0);function xd(e=!0){let t=Z.useContext(bd);if(t===void 0&&!e)throw Error(ue(25));return t}function Sd({controlled:e,default:t,name:n,state:r=`value`}){let{current:i}=Z.useRef(e!==void 0),[a,o]=Z.useState(()=>t);return[i&&e!==void 0?e:a,Z.useCallback(e=>{i||o(e)},[])]}var Cd=Z.createContext(null);function wd(e=`root`){let t=Z.useContext(Cd),n=Z.useContext(vd);return t===null||n===void 0?null:(e===`submenu-trigger`?n.virtualFocus||n.parentVirtualFocus:n.virtualFocus)?t:null}var Td={visible:!0,ref:null};function Ed(){return Td}function Dd(e,t,n=`root`){let r=wd(n),i=((n===`submenu-trigger`?r?.useSubmenuTrigger:r?.useItem)??Ed)({label:e.label,children:e.children,render:e.render}),a=re(t,i.ref);return{visible:i.visible,ref:a,props:i.props}}var Od=Z.createContext(void 0);function kd(){let e=Z.useContext(Od);if(e===void 0)throw Error(ue(30));return e}function Ad(e){e.preventDefault()}function jd(e){let{closeOnClick:t,highlighted:n,id:r,nodeId:i,store:a,typingRef:o,itemRef:s,itemMetadata:c}=e,l=yd(),u=xd(!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 Z.useMemo(()=>({id:r,role:`menuitem`,tabIndex:_,"aria-selected":p,onMouseDown:f?Ad: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:rt})},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&&!Ne&&e.button===2)return}s.current&&a.context.allowMouseUpTriggerRef.current&&(!g||e.button===2)&&c.type===`regular-item`&&Le(s.current,e,{detail:1,pointerType:`mouse`})}}),[t,_,r,m,i,a.context.allowMouseUpTriggerRef,o,s,u,g,c.type,p,f])}var Md={type:`regular-item`};function Nd(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=Z.useRef(null),{getButtonProps:d,buttonRef:f}=je({disabled:n,focusableWhenDisabled:!0,native:s,composite:!0}),p=jd({closeOnClick:t,highlighted:r,id:i,nodeId:l,store:a,typingRef:o,itemRef:u,itemMetadata:c}),m=Z.useCallback(e=>se(p,{onMouseEnter(e){c.type===`submenu-trigger`&&c.setActive(e.nativeEvent)}},e,d),[p,d,c]),h=re(u,f);return Z.useMemo(()=>({getItemProps:m,itemRef:h}),[m,h])}var Pd=Z.createContext({register:()=>{},unregister:()=>{},subscribeMapChange:()=>()=>{},nextIndexRef:{current:0}});function Fd(){return Z.useContext(Pd)}function Id(e={}){let{guess:t,label:n,metadata:r,textRef:i,index:a}=e,{register:o,unregister:s,subscribeMapChange:c,nextIndexRef:l}=Fd(),u=Z.useRef(-1),[d,f]=Z.useState(a==null&&t?()=>{if(u.current===-1){let e=l.current;l.current+=1,u.current=e}return u.current}:-1),p=a??d,m=Z.useRef(null),h=Z.useCallback(e=>{let t=m.current;t&&s(t),m.current=e,e&&o(e,{metadata:r??null,index:a??null,label:n,textRef:i})},[a,o,s,r,n,i]);return et(()=>{if(a==null)return c(e=>{let t=m.current?e.get(m.current)?.index:null;t!=null&&f(t)})},[a,c]),{ref:h,index:p}}var Ld=`data-checked`,Rd=`data-unchecked`,zd={checked(e){return e?{[Ld]:``}:{[Rd]:``}},...ye},Bd=Z.forwardRef(function(e,t){let{render:n,className:r,id:i,label:a,nativeButton:o=!1,disabled:s=!1,closeOnClick:c=!1,checked:l=!1,onCheckedChange:u,style:d,...f}=e,{store:p}=yd(),m=Id({guess:!0,label:a}),h=F(i),_=p.useState(`disabled`),v=p.useState(`isActive`,m.index),y=p.useState(`floatingNodeId`),b=p.useState(`itemProps`),x=s||_,{getItemProps:S,itemRef:ee}=Nd({closeOnClick:c,disabled:x,highlighted:v,id:h,store:p,nativeButton:o,nodeId:y,itemMetadata:Md}),C=Z.useMemo(()=>({disabled:x,highlighted:v,checked:l}),[x,v,l]);function w(e){let t=ke(rt,e.nativeEvent,void 0,{preventUnmountOnClose:vt});u?.(!l,t)}let T=g(`div`,e,{state:C,stateAttributesMapping:zd,props:[b,{role:`menuitemcheckbox`,"aria-checked":l,onClick:w},f,S],ref:[ee,t,m.ref]});return(0,Q.jsx)(Od.Provider,{value:C,children:T})}),Vd=Z.forwardRef(function(e,t){let{checked:n,defaultChecked:r,onCheckedChange:i,...a}=e,[o,s]=Sd({controlled:n,default:r??!1,name:`MenuCheckboxItem`,state:`checked`}),c=Dd(e,t);function l(e,t){i?.(e,t),t.isCanceled||s(e)}return c.visible?(0,Q.jsx)(Bd,{...a,checked:o,onCheckedChange:l,ref:c.ref}):null}),Hd=Z.forwardRef(function(e,t){let{render:n,className:r,style:i,keepMounted:a=!1,...o}=e,s=kd(),c=Z.useRef(null),{transitionStatus:l,mounted:u,setMounted:f}=E(s.checked);d({batch:!0,enabled:!s.checked,open:s.checked,ref:c,onComplete(){s.checked||f(!1)}});let p={checked:s.checked,disabled:s.disabled,highlighted:s.highlighted,transitionStatus:l};return g(`span`,e,{state:p,ref:[t,c],stateAttributesMapping:zd,props:{"aria-hidden":!0,...o},enabled:a||u})}),Ud=Z.createContext(void 0);function Wd(){let e=Z.useContext(Ud);if(e===void 0)throw Error(ue(31));return e}var Gd=Z.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=F(a),c=Wd();return et(()=>(c(s),()=>{c(e=>e===s?void 0:e)}),[c,s]),g(`div`,e,{ref:t,props:{id:s,"aria-hidden":!0,...o}})}),Kd=Z.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}=yd(),f=Id({guess:!0,label:a}),p=F(i),m=d.useState(`disabled`),h=d.useState(`isActive`,f.index),_=d.useState(`floatingNodeId`),v=d.useState(`itemProps`),y=s||m,{getItemProps:b,itemRef:x}=Nd({closeOnClick:c,disabled:y,highlighted:h,id:p,store:d,nativeButton:o,nodeId:_,itemMetadata:Md});return g(`div`,e,{state:{disabled:y,highlighted:h},props:[v,u,b],ref:[x,t,f.ref]})}),qd=Z.forwardRef(function(e,t){let n=Dd(e,t);return n.visible?(0,Q.jsx)(Kd,{...e,ref:n.ref}):null}),Jd=Ne&&M;function Yd(e,t={}){let{enabled:n=!0,delay:r}=t,{events:i,dataRef:a}=e.context,o=Z.useRef(!1),s=Z.useRef(null),c=Z.useRef(!0),l=bn();Z.useEffect(()=>{let t=e.select(`domReferenceElement`);if(!n)return;let r=Ht(t);function i(){let t=e.select(`domReferenceElement`);!e.select(`open`)&&We(t)&&t===H(me(t))&&(o.current=!0,s.current=t)}function a(){c.current=!0}function l(){c.current=!1}return un(_e(r,`blur`,i),Jd&&_e(r,`keydown`,a,!0),Jd&&_e(r,`pointerdown`,l,!0))},[e,n]),Z.useEffect(()=>{if(!n)return;function t(t){if(t.reason===`trigger-press`||t.reason===`escape-key`){let t=e.select(`domReferenceElement`);pt(t)&&(s.current=t,o.current=!0)}}return i.on(`openchange`,t),()=>{i.off(`openchange`,t)}},[i,n,e]);let u=Z.useMemo(()=>{function t(){o.current=!1,s.current=null}return{onMouseLeave(){t()},onFocus(n){let i=n.currentTarget;if(o.current){if(s.current===i)return;t()}let a=de(n.nativeEvent);if(pt(a)){if(Jd&&!n.relatedTarget){if(!c.current&&!b(a))return}else if(!_(a))return}let u=on(n.relatedTarget,e.context.triggerElements),{nativeEvent:d,currentTarget:f}=n;if(e.select(`open`)&&u||!r){e.setOpen(!0,ke(pn,d,f));return}l.start(r,()=>{o.current||e.setOpen(!0,ke(pn,d,f))})},onBlur(n){t();let r=n.relatedTarget,i=n.nativeEvent,o=pt(r)&&r.hasAttribute(it(`focus-guard`))&&r.getAttribute(`data-type`)===`outside`;l.start(0,()=>{let t=e.select(`domReferenceElement`),n=H(me(t));!r&&n===t||W(a.current.floatingContext?.refs.floating.current,n)||W(t,n)||o||on(r??n,e.context.triggerElements)||e.setOpen(!1,ke(pn,i))})}}},[a,r,e,l]);return Z.useMemo(()=>n?{reference:u,trigger:u}:{},[n,u])}function Xd(e){return M&&e.movementX===0&&e.movementY===0}function Zd(e,t,n){switch(e){case`vertical`:return t;case`horizontal`:return n;default:return t||n}}function Qd(e,t){return Zd(t,e===`ArrowUp`||e===`ArrowDown`,e===`ArrowLeft`||e===`ArrowRight`)}function $d(e,t,n){return Zd(t,e===`ArrowDown`,n?e===`ArrowLeft`:e===`ArrowRight`)||e===`Enter`||e===` `||e===``}function ef(e,t,n){return Zd(t,n?e===St:e===s,e===ce)}function tf(e,t,n,r){return t===`both`||t===`horizontal`&&r?e===`Escape`:Zd(t,n?e===s:e===St,e===yt)}function nf(e,t){let{listRef:n,activeIndex:r,onNavigate:i=()=>{},enabled:a=!0,selectedIndex:o=null,allowEscape:s=!1,loopFocus:c=!1,nested:l=!1,rtl:u=!1,virtual:d=!1,focusItemOnOpen:f=`auto`,focusItemOnHover:p=!0,openOnArrowKeyDown:h=!0,disabledIndices:g=void 0,orientation:_=`vertical`,triggerOrientation:v=_,parentOrientation:y,id:x,resetOnPointerLeave:S=!0,externalTree:C,nestedReturnFocusRef:w,grid:T}=t,te=T!=null,E=e.useState(`open`),D=e.useState(`floatingElement`),O=e.useState(`domReferenceElement`),k=e.context.dataRef,j=m(D),M=be(O),N=Ye(j),P=mt(),F=Ge(C),I=Z.useRef(f),L=Z.useRef(o??-1),R=Z.useRef(null),ne=Z.useRef(!0),B=Jt(e=>{i(L.current===-1?null:L.current,e)}),V=Z.useRef(!!D),re=Z.useRef(E),U=Z.useRef(!1),ie=Z.useRef(!1),ae=Z.useRef(null),oe=Ye(g),se=Ye(E),ce=Ye(o),le=Ye(S),G=Ce(),ue=Ce(),fe=Jt(()=>{G.cancel();function e(e){d||(ae.current=$e(e,{sync:U.current,preventScroll:!0}))}let t=n.current[L.current],r=ie.current;t&&e(t),(U.current?e=>e():e=>G.request(e))(()=>{let i=n.current[L.current]||t;i&&(t||e(i),_e&&(r||!ne.current)&&i.scrollIntoView?.({block:`nearest`,inline:`nearest`}))})});et(()=>{k.current.orientation=_},[k,_]),et(()=>{E||(R.current=null),(!E||f!==`auto`)&&(I.current=f)},[E,f]),et(()=>{a&&(E&&D?(L.current=o??-1,I.current&&o!=null&&(ie.current=!0,B())):V.current&&(L.current=-1,B()))},[a,E,D,o,B]),et(()=>{if(a){if(!E){U.current=!1;return}if(D){if(r==null){if(U.current=!1,ce.current!=null)return;if(V.current&&(L.current=-1,fe()),(!re.current||!V.current)&&I.current&&(R.current!=null||I.current===!0&&R.current==null)){let e=0,t=()=>{n.current[0]==null?(e<2&&(e?e=>ue.request(e):queueMicrotask)(t),e+=1):(L.current=R.current==null||$d(R.current,v,u)||l?Dt(n):Lt(n),R.current=null,B())};t()}}else Ve(n.current,r)||(L.current=r,fe(),ie.current=!1)}}},[a,E,D,r,ce,l,n,v,u,B,fe,ue]),et(()=>{if(!a||D||!F||d||!V.current)return;let e=F.nodesRef.current,t=e.find(e=>e.id===P)?.context?.elements.floating,n=H(me(O??t??null)),r=e.some(e=>e.context&&W(e.context.elements.floating,n));t&&!r&&ne.current&&t.focus({preventScroll:!0})},[a,D,O,F,P,d]),et(()=>{re.current=E,V.current=!!D});let pe=r!=null,K=Jt(e=>{if(!se.current)return;let t=n.current.indexOf(e.currentTarget);t!==-1&&(L.current!==t||r!==t)&&(L.current=t,B(e))}),he=Jt(()=>y??F?.nodesRef.current.find(e=>e.id===P)?.context?.dataRef?.current.orientation),ge=Jt(()=>Dt(n,oe.current)),q=Jt(t=>{if(ne.current=!1,U.current=!0,t.which===229||!se.current&&t.currentTarget===N.current)return;if(l&&tf(t.key,_,u,te)){Qd(t.key,he())||z(t),e.setOpen(!1,ke(Et,t.nativeEvent));let n=w?.current??O;We(n)&&n.focus();return}r!=null&&r!==L.current&&!Ve(n.current,r)&&(L.current=r);let i=L.current,a=Dt(n,g),o=Lt(n,g);if(M||(t.key===`Home`&&(z(t),L.current=a,B(t)),t.key===`End`&&(z(t),L.current=o,B(t))),T!=null){let e=T(t,L.current,n,_,c,u,g,a,o);if(e!=null&&e!==L.current&&(L.current=e,B(t)),_===`both`)return}if(Qd(t.key,_)){z(t);let e=H(t.currentTarget.ownerDocument);if(E&&!d&&W(t.currentTarget,e)&&!n.current.some(t=>t!=null&&W(t,e))){L.current=$d(t.key,_,u)?a:o,B(t),r===L.current&&fe();return}let{index:l,wrapped:f}=ut(n.current,i,{decrement:!$d(t.key,_,u),loopFocus:c,allowEscape:s,disabledIndices:g,minIndex:a,maxIndex:o});f&&(U.current=!1),L.current=l,B(t)}}),_e=Z.useMemo(()=>({onFocus(e){U.current=!0,K(e)},onClick({currentTarget:e}){d||e.focus({preventScroll:!0})},onMouseMove(e){Xd(e)||(U.current=!0,ie.current=!1,p&&K(e))},onPointerLeave(e){if(!se.current||!ne.current||e.pointerType===`touch`)return;U.current=!0;let t=e.relatedTarget;if(!(!p||n.current.includes(t))&&le.current&&(ae.current?.(),ae.current=null,L.current=-1,B(e),!d)){let e=N.current,t=H(me(e));e&&W(e,t)&&e.focus({preventScroll:!0})}}}),[K,se,N,p,n,B,le,d]),ve=Z.useMemo(()=>d&&E&&pe&&{"aria-activedescendant":`${x}-${r}`},[d,E,pe,x,r]),ye=Z.useMemo(()=>({...M?{}:ve,onKeyDown(t){if(t.key===`Tab`&&t.shiftKey&&E&&!d){let n=de(t.nativeEvent);if(n&&!W(N.current,n))return;z(t);let r=ke(Zt,t.nativeEvent);e.setOpen(!1,r);let i=w?.current??O;!r.isCanceled&&We(i)&&i.focus();return}q(t)},onPointerMove(e){Xd(e)||(ne.current=!0)}}),[ve,q,N,M,e,E,d,O,w]),xe=Z.useMemo(()=>{function t(t){e.setOpen(!0,ke(Et,t.nativeEvent,t.currentTarget))}function n(e){f===`auto`&&ee(e.nativeEvent)&&(I.current=!d)}function r(e){I.current=f,f===`auto`&&A(e.nativeEvent)&&(I.current=!0)}return{onKeyDown(n){let r=e.select(`open`);ne.current=!1;let i=n.key.startsWith(`Arrow`),a=ef(n.key,he(),u),o=Qd(n.key,r?_:v),s=(l?a:o)||n.key===`Enter`||n.key.trim()===``;if(d&&r&&(!l||b(n.currentTarget)))return q(n);if(!(!r&&!h&&i)){if(s){let e=Qd(n.key,he());R.current=l&&e?null:n.key}if(l){a&&(z(n),r?(L.current=ge(),B(n),d&&N.current?.focus()):t(n));return}o&&(ce.current!=null&&(L.current=ce.current),z(n),!r&&h?t(n):q(n),r&&B(n))}},onFocus(t){t.target===t.currentTarget&&e.select(`open`)&&!d&&(L.current=-1,B(t))},onPointerDown:r,onPointerEnter:r,onMouseDown:n,onClick:n}},[q,f,ge,l,B,e,h,_,v,he,u,ce,d,N]),Se=Z.useMemo(()=>({...ve,...xe}),[ve,xe]);return Z.useMemo(()=>a?{reference:Se,floating:ye,item:_e,trigger:xe}:{},[a,Se,ye,xe,_e])}function rf(e,t){let{listRef:n,elementsRef:r,activeIndex:i,onMatch:a,disabledIndices:o,onTyping:s,enabled:c=!0,resetMs:l=750,selectedIndex:u=null}=t,d=Jt(s),f=e.useState(`open`),p=bn(),m=Z.useRef(``),h=Z.useRef(u??i??-1),g=Z.useRef(null),_=Jt(e=>{function t(e){return r?.current[e]}function s(e){let n=t(e);return n&&!ot(n)||n?.matches(`:disabled`)?!1:o==null||!tn(xt,e,o)}function c(e,t,n=0){if(e.length===0)return-1;let r=(n%e.length+e.length)%e.length,i=t.toLowerCase();for(let t=0;t<e.length;t+=1){let n=(r+t)%e.length;if(!(!e[n]?.toLowerCase().startsWith(i)||!s(n)))return n}return-1}let _=n.current;if(m.current.length>0&&e.key===` `&&(z(e),d?.(!0)),m.current.length>0&&m.current[0]!==` `&&c(_,m.current)===-1&&e.key!==` `&&d?.(!1),_==null||e.key.length!==1||e.ctrlKey||e.metaKey||e.altKey)return;f&&e.key!==` `&&(z(e),d?.(!0));let v=m.current===``;v&&(h.current=u??i??-1),_.every((e,t)=>e&&s(t)?e[0]?.toLowerCase()!==e[1]?.toLowerCase():!0)&&m.current===e.key&&(m.current=``,h.current=g.current),m.current+=e.key,p.start(l,()=>{m.current=``,h.current=g.current,d?.(!1)});let y=((v?u??i??-1:h.current)??0)+1,b=c(_,m.current,y);b===-1?e.key!==` `&&(m.current=``,d?.(!1)):(a?.(b,e),g.current=b)}),v=Jt(t=>{let n=t.relatedTarget,r=e.select(`domReferenceElement`),i=e.select(`floatingElement`);W(r,n)||W(i,n)||(p.clear(),m.current=``,h.current=g.current,d?.(!1))});et(()=>{!f&&u!==null||(p.clear(),g.current=null,m.current!==``&&(m.current=``,d?.(!1)))},[f,u,p,d]);let y=Z.useMemo(()=>({onKeyDown:_,onBlur:v}),[_,v]);return Z.useMemo(()=>c?{reference:y,floating:y}:{},[c,y])}var af=Z.createContext(void 0);function of(){return Z.useContext(af)}function sf(e,t){let n=y(e.render);if(Z.isValidElement(n)){let e=n.props;if(Object.hasOwn(e,`id`))return e.id??``}return e.id??t}function cf(e,t,n){let r=sf(e,t),i=r===t?void 0:r;return[r,Z.useCallback(e=>n?.(e?i:void 0),[i,n])]}function lf(e,t,n){let r=y(e.render),i=Z.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 uf=Z.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,id:o,initialFocus:s,...c}=e,{store:l,defaultFloatingId:u,setRenderedFloatingId:f,virtualFocus:p,orientation:m}=yd(),_=of(),{side:y,align:b}=_d(),x=ae(!0)!=null,S=l.useState(`open`),ee=l.useState(`transitionStatus`),C=l.useState(`popupProps`),w=l.useState(`mounted`),T=l.useState(`instantType`),te=l.useState(`activeTriggerElement`),E=l.useState(`parent`),D=l.useState(`lastOpenChangeReason`),O=l.useState(`rootId`),k=l.useState(`floatingRootContext`),A=l.useState(`floatingTreeRoot`),j=l.useState(`closeDelay`),M=l.useState(`hoverEnabled`),N=l.useState(`disabled`),P=l.useState(`openMethod`),F=l.useState(`activeTriggerId`),I=l.useState(`listElement`),[L,R]=cf(e,u,f),z=lf(e,te,F),ne=E.type===`menu`?_:void 0,B=E.type===`context-menu`,V=s??E.type!==`menu`;s===void 0&&I&&E.type!==`menu`&&(V=()=>l.state.activeIndex===null&&I),d({open:S,ref:l.context.popupRef,onComplete(){S&&l.context.onOpenChangeComplete?.(!0)}}),Z.useEffect(()=>{function e(e){l.setOpen(!1,ke(e.reason,e.domEvent))}return A.events.on(`close`,e),()=>{A.events.off(`close`,e)}},[A.events,l]),ht(k,{enabled:M&&!N&&!B&&E.type!==`menubar`,closeDelay:j});let re=l.useStateSetter(`popupElement`),{parentVirtualFocusRef:H,handleFocus:U}=(Z.useContext(Cd)?.useParentHandoff??ff)(l,E,S,p),ie={transitionStatus:ee,side:y,align:b,open:S,nested:E.type===`menu`,instant:T},W=g(`div`,e,{state:ie,ref:[t,l.context.popupRef,re,R],stateAttributesMapping:ge,props:[C,{id:L,...I?{role:`presentation`}:{role:`menu`,"aria-orientation":m===`horizontal`?`horizontal`:void 0,"aria-labelledby":z},onKeyDown(e){ne?.onPopupKeyDown?.(e),x&&h.has(e.key)&&e.stopPropagation()},onFocus:U},v(ee),c,{"data-rootownerid":O}]}),oe=E.type===void 0||B;(te||E.type===`menubar`&&D!==`outside-press`)&&(oe=!0);let se=ne?.getReturnElement??H;return(0,Q.jsx)(tt,{context:k,openInteractionType:P,modal:B,disabled:!w,returnFocus:a??se??oe,explicitReturnFocus:a===void 0&&se?!1:void 0,initialFocus:V,restoreFocus:!0,getInsideElements:E.type===void 0?()=>[l.context.beforeTriggerFocusGuardRef.current]:void 0,externalTree:E.type===`menubar`?void 0:A,previousFocusableElement:te,nextFocusableElement:E.type===void 0?l.context.triggerFocusTargetRef:void 0,beforeContentFocusGuardRef:l.context.beforeContentFocusGuardRef,children:W})}),df={parentVirtualFocusRef:void 0,handleFocus:void 0};function ff(){return df}var pf=Z.forwardRef(function(e,t){let n=wd()?.Popup??uf;return(0,Q.jsx)(n,{...e,ref:t})}),mf=Z.createContext(void 0);function hf(){let e=Z.useContext(mf);if(e===void 0)throw Error(ue(32));return e}var gf=Z.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,{store:i,parent:a}=yd();if(!(i.useState(`mounted`)||n))return null;let o=a.type===`menu`||a.type===`menubar`?`group`:void 0;return(0,Q.jsx)(mf.Provider,{value:n,children:(0,Q.jsx)(Kt,{ref:t,...r,portalOwnerRole:o})})});function _f(e){let{children:t,elementsRef:n,labelsRef:r,onMapChange:i}=e,a=Jt(i),[,o]=Z.useState(0),s=ie(yf).current,c=ie(vf).current,l=Z.useRef(0),u=Z.useRef(!0),d=Z.useRef(null),f=Z.useRef(null),p=Jt(()=>{u.current||(u.current=!0,o(e=>e+1))}),m=Jt((e,t)=>{c.set(e,t),p()}),h=Jt(e=>{c.delete(e),p()}),g=Jt(e=>{let t=new Map;return n.current.length=0,r&&(r.current.length=0),e.forEach(e=>{t.set(e.element,{...e.registration.metadata??{},index:e.index}),n.current[e.index]=e.element,r&&(r.current[e.index]=e.registration.label===void 0?e.registration.textRef?.current?.textContent??e.element.textContent:e.registration.label)}),l.current=n.current.length,t});function _(e){if(f.current?.disconnect(),f.current=null,typeof MutationObserver!=`function`||e.length<2)return;let t=new MutationObserver(n=>{if(!Sf(n))return;let r=null;for(let n of e)if(n.isConnected){if(r&&Cf(r,n)>0){t.disconnect(),p();return}r=n}});f.current=t;let n=new Set;for(let t=1;t<e.length;t+=1){let r=xf(e[t-1],e[t]);r&&n.add(r)}n.forEach(e=>t.observe(e,{childList:!0}))}let v=Jt(()=>{let[e,t]=bf(c),n=g(e),r=d.current,i=!r||r.length!==e.length||e.some((e,t)=>{let n=r[t];return e.index!==n.index||e.element!==n.element||e.registration.index!==n.registration.index||e.registration.metadata!==n.registration.metadata});_(t),d.current=e,u.current=!1,i&&(s.forEach(e=>e(n)),a(n))});et(()=>(!u.current&&d.current&&g(d.current),()=>{n.current=[],r&&(r.current=[])}),[n,r,g]),et(()=>{u.current&&v()}),et(()=>()=>{f.current?.disconnect(),u.current=!0},[]);let y=Jt(e=>(s.add(e),()=>{s.delete(e)})),b=Z.useMemo(()=>({register:m,unregister:h,subscribeMapChange:y,nextIndexRef:l}),[m,h,y,l]);return(0,Q.jsx)(Pd.Provider,{value:b,children:t})}function vf(){return new Map}function yf(){return new Set}function bf(e){let t=new Set,n=[],r=[];e.forEach((e,i)=>{if(!i.isConnected)return;let a=e.index,o={index:a??-1,element:i,registration:e};a===null?r.push(o):a>=0&&(t.add(a),n.push(o))});let i=0;return r.sort((e,t)=>Cf(e.element,t.element)),r.forEach(e=>{for(;t.has(i);)i+=1;e.index=i,n.push(e),i+=1}),t.size>0&&n.sort((e,t)=>e.index-t.index),[n,r.map(e=>e.element)]}function xf(e,t){let n=e.parentElement;for(;n&&!n.contains(t);)n=n.parentElement;return n}function Sf(e){for(let t of e)for(let e=0;e<t.removedNodes.length;e+=1)if(t.removedNodes[e].isConnected)return!0;return!1}function Cf(e,t){return e.nextElementSibling===t?-1:t.nextElementSibling===e?1:e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1}var wf=Z.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:p=5,sticky:m=!1,disableAnchorTracking:h=!1,collisionAvoidance:g=wt,style:_,...v}=e,{store:y,virtualFocus:b,syncHighlightedItem:x}=yd(),S=hf(),ee=xd(!0),C=y.useState(`parent`),w=y.useState(`floatingRootContext`),T=y.useState(`floatingTreeRoot`),te=y.useState(`mounted`),E=y.useState(`open`),D=y.useState(`modal`),O=y.useState(`openMethod`),k=y.useState(`activeTriggerElement`),A=y.useState(`transitionStatus`),j=y.useState(`positionerElement`),M=y.useState(`instantType`),N=y.useState(`adaptiveOrigin`),P=y.useState(`lastOpenChangeReason`),F=y.useState(`floatingNodeId`),I=y.useState(`floatingParentNodeId`),L=w.useState(`domReferenceElement`),R=n,z=c,ne=l,B=s,V=g;C.type===`context-menu`&&(R=n??C.context?.anchor,B??=`start`,!o&&B!==`center`&&(ne=e.alignOffset??2,z=e.sideOffset??-5));let re=o,H=B;C.type===`menu`?(re??=`inline-end`,H??=`start`,V=e.collisionAvoidance??Qt):C.type===`menubar`&&(re??=C.context.orientation===`vertical`?`inline-end`:`bottom`,H??=`start`);let U=C.type===`context-menu`,ie=f({anchor:R,floatingRootContext:w,positionMethod:ee?`fixed`:r,mounted:te,side:re,sideOffset:z,align:H,alignOffset:ne,arrowPadding:U?0:p,collisionBoundary:u,collisionPadding:d,sticky:m,nodeId:F,keepMounted:S,disableAnchorTracking:h,collisionAvoidance:V,shift:U?{crossAxis:!(`side`in V&&V.side===`flip`),rootBoundary:`layoutViewport`}:void 0,externalTree:T,adaptiveOrigin:N,lazyFlip:b?`placement`:!1});Z.useEffect(()=>{function e(e){e.open&&(e.parentNodeId===F&&y.set(`hoverEnabled`,!1),e.nodeId!==F&&e.parentNodeId===y.select(`floatingParentNodeId`)&&y.setOpen(!1,ke(en)))}return T.events.on(`menuopenchange`,e),()=>{T.events.off(`menuopenchange`,e)}},[y,T.events,F]),Z.useEffect(()=>{if(y.select(`floatingParentNodeId`)==null)return;function e(e){if(e.open||e.nodeId!==y.select(`floatingParentNodeId`))return;let t=e.reason??`sibling-open`;y.setOpen(!1,ke(t))}return T.events.on(`menuopenchange`,e),()=>{T.events.off(`menuopenchange`,e)}},[T.events,y]);let W=bn();Z.useEffect(()=>{E||W.clear()},[E,W]),Z.useEffect(()=>{function e(e){if(!(!E||e.nodeId!==y.select(`floatingParentNodeId`))){if(e.target&&k&&k!==e.target){let e=y.select(`closeDelay`);e>0?W.isStarted()||W.start(e,()=>{y.setOpen(!1,ke(en))}):y.setOpen(!1,ke(en))}else W.clear()}}return T.events.on(`itemhover`,e),()=>{T.events.off(`itemhover`,e)}},[T.events,E,k,y,W]),Z.useEffect(()=>{let e={open:E,nodeId:F,parentNodeId:I,reason:y.select(`lastOpenChangeReason`)};T.events.emit(`menuopenchange`,e)},[T.events,E,y,F,I]),sn({store:y,domReference:L,positionerElement:j,open:E});let ae={open:E,side:ie.side,align:ie.align,anchorHidden:ie.anchorHidden,nested:C.type===`menu`,instant:M},oe=C.type===`menubar`&&C.context.modal;dn(E&&(oe||D&&P!==`trigger-hover`),O===`touch`,j,k);let se=Ke(e,ae,{styles:ie.positionerStyles,transitionStatus:A,props:v,refs:[t,y.useStateSetter(`positionerElement`)],hidden:!te,inert:!E}),ce=te&&C.type!==`menu`&&(C.type!==`menubar`&&D&&P!==`trigger-hover`||C.type===`menubar`&&C.context.modal),le=null;return C.type===`menubar`?le=C.context.contentElement:C.type===void 0&&(le=k),(0,Q.jsxs)(gd.Provider,{value:ie,children:[ce&&(0,Q.jsx)(he,{ref:C.type===`context-menu`||C.type===`nested-context-menu`?C.context.internalBackdropRef:null,inert:ve(!E),cutout:le}),(0,Q.jsx)(Yt,{id:F,children:(0,Q.jsx)(_f,{elementsRef:y.context.itemDomElements,labelsRef:y.context.itemLabels,onMapChange:x,children:se})})]})}),Tf=Z.createContext(null);function Ef(e){let t=Z.useContext(Tf);if(t===null&&!e)throw Error(ue(5));return t}function Df(e){return e==null?ct:e.type.startsWith(`key`)?It:e.type.startsWith(`mouse`)||e.type.startsWith(`pointer`)?ze:ct}var Of={...le,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=le.triggerPopupId(e,t);return n?e.listElement?.id||n:void 0},filterTriggerProps:e=>e.filterTriggerProps,inputProps:e=>e.inputProps,webkitAriaSelected:(e,t)=>M&&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`&&!le.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`)}},kf=class extends x{constructor(e,t,n=!1){let r=new gn,i=jf(r,t,n,e);super(i,Af(r),Of),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 Af(e){return{positionerRef:Z.createRef(),popupRef:Z.createRef(),typingRef:{current:!1},itemDomElements:{current:[]},itemLabels:{current:[]},highlightReason:`none`,highlightEvent:void 0,reportedItem:void 0,allowMouseUpTriggerRef:{current:!1},virtualFocusRef:void 0,triggerFocusTargetRef:Z.createRef(),beforeTriggerFocusGuardRef:Z.createRef(),beforeContentFocusGuardRef:Z.createRef(),onOpenChangeComplete:void 0,triggerElements:e}}function jf(e,t,n=!1,r){return{...U(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:o,inputProps:o,inputFocused:!1,highlightedItem:void 0,hoverEnabled:!0,instantType:void 0,openChangeReason:null,floatingTreeRoot:new Pt,floatingNodeId:void 0,floatingParentNodeId:null,itemProps:o,keyboardEventRelay:void 0,closeDelay:0,adaptiveOrigin:void 0,...r}}var Mf=Z.createContext(null);function Nf(e,t){return(e===`trigger-press`||e===`item-press`)&&t?.detail===0}function Pf(e,t){return e===`list-navigation`||Nf(e,t)}var Ff=D(function(e){let{children:t,open:n,onOpenChange:r,onOpenChangeComplete:i,onItemHighlighted:a,defaultOpen:s=!1,disabled:l=!1,modal:u,loopFocus:d=!0,orientation:f=`vertical`,actionsRef:p,closeParentOnEsc:m=!1,handle:h,triggerId:g,defaultTriggerId:_=null,highlightItemOnHover:v=!0,isSubmenu:y=!1,virtualFocus:b=!1,virtualFocusRef:x,allowEscape:S=!0,resetOnPointerLeave:ee=!0}=e,w=xd(!0),E=yd(!0),D=Ef(!0),O=E?.store,k=E?.virtualFocus??!1,A=Z.useMemo(()=>y&&O?{type:`menu`,store:O}:D?{type:`menubar`,context:D}:w&&!O?{type:`context-menu`,context:w}:{type:void 0},[w,O,D,y]),j=F(),M=F(),[P,I]=Z.useState(void 0),L=(P??M)||void 0,R=mt(),z=A.type===`menu`?A.store:void 0,ne=(n??s)&&z?.state.transitionStatus===`starting`,B=ie(()=>ne?z?.state.instantType:void 0).current,V=ie(()=>{let e=new kf({open:s,openProp:n,activeTriggerId:_,triggerIdProp:g,parent:A,disabled:l,highlightItemOnHover:v,modal:A.type===void 0?u:void 0,rootId:j,instantType:B},L,R!=null);return e.context.virtualFocusRef=x,e}).current;V.useControlledProp(`openProp`,n),V.useControlledProp(`triggerIdProp`,g),V.useContextCallback(`onOpenChangeComplete`,i);let re=V.useState(`floatingTreeRoot`),H=Ut(re),U=V.useState(`open`),W=V.useState(`activeTriggerElement`),ae=V.useState(`positionerElement`),oe=V.useState(`hoverEnabled`),ce=V.useState(`disabled`),le=V.useState(`lastOpenChangeReason`),G=V.useState(`parent`),ue=V.useState(`activeIndex`),de=V.useState(`keyboardOpen`),pe=V.useState(`payload`),me=V.useState(`floatingParentNodeId`),K=Z.useRef(null),he=Z.useRef(G.type!==`context-menu`),ge=bn(),q=Z.useRef(!0),_e=bn(),ve=me!=null,{openMethod:ye,triggerProps:be}=Re(U);V.useSyncedValues({disabled:l,highlightItemOnHover:v,modal:G.type===void 0?u:void 0,openMethod:ye,rootId:j}),C(V);let{forceUnmount:xe,transitionStatus:Se}=N(U,V,()=>{V.set(`allowMouseEnter`,!1)},ne),Ce=Ee(V.context.popupRef);Z.useEffect(()=>{if(B===void 0)return;let e=()=>{V.state.instantType===B&&V.set(`instantType`,void 0)};if(!U){e();return}if(Se!==void 0)return;if(V.context.popupRef.current==null){e();return}let t=new AbortController;return Ce(e,t.signal),()=>{t.abort()}},[B,U,Se,Ce,V]),et(()=>{w&&!E?V.update({parent:{type:`context-menu`,context:w},floatingNodeId:H,floatingParentNodeId:R}):(E||!V.select(`activeTriggerElement`))&&V.update({floatingNodeId:H,floatingParentNodeId:R})},[w,E,H,R,W,V]),Z.useEffect(()=>{if(U||(K.current=null),G.type===`context-menu`){if(!U){ge.clear(),he.current=!1;return}ge.start(500,()=>{he.current=!0})}},[ge,U,G.type]),et(()=>{!U&&!oe&&V.set(`hoverEnabled`,!0)},[U,oe,V]);let Te=Jt((e,t)=>{let n=t.reason;if(!e&&!V.select(`open`)||U===e&&t.trigger===W&&le===n)return;let i=te(t);if(!e&&t.trigger==null&&(t.trigger=W??void 0),r?.(e,t),t.isCanceled)return;V.state.floatingRootContext.dispatchOpenChange(e,t);let a=t.event;if(e===!1&&n!==`item-press`&&a?.type===`click`&&a.pointerType===`touch`&&!q.current)return;e&&n===`trigger-focus`?(q.current=!1,_e.start(300,()=>{q.current=!0})):(q.current=!0,_e.clear());let o=!e&&(n===`escape-key`||n==null);K.current=t.event;let s=De(V.state,e,t.trigger,i());s.openChangeReason=n,s.keyboardOpen=e&&Pf(n,a),s.instantType=G.type===`menubar`&&(n===`trigger-focus`||n===`focus-out`||n===`trigger-hover`||n===`list-navigation`||n===`sibling-open`)?`group`:Nf(n,a)?`click`:o?`dismiss`:void 0,V.update(s)}),Oe=Pe({popupStore:V,floatingRootContext:V.state.floatingRootContext,floatingId:L,nested:R!=null,onOpenChange:Te}),Ae=Oe.context.events;et(()=>{let e=({open:e,eventDetails:t})=>Te(e,t);return Ae.on(`setOpen`,e),()=>{Ae?.off(`setOpen`,e)}},[Ae,Te]),et(()=>V.subscribeToParentMenu(),[V]);let J=Z.useCallback(()=>{V.setOpen(!1,ke(Qe))},[V]);Z.useImperativeHandle(p,()=>({unmount:xe,close:J}),[xe,J]);let je;G.type===`context-menu`&&(je=G.context),Z.useImperativeHandle(je?.positionerRef,()=>ae,[ae]),Z.useImperativeHandle(je?.actionsRef,()=>({setOpen:Te}),[Te]);let Me=fe(Oe,{enabled:!ce,bubbles:{escapeKey:m&&G.type===`menu`},outsidePress(){return G.type!==`context-menu`||K.current?.type===`contextmenu`||he.current},externalTree:ve?re:void 0}),Ne=nn(),Fe=nf(Oe,{enabled:!ce,listRef:V.context.itemDomElements,activeIndex:ue,virtual:b,nested:G.type===`menubar`||!b&&G.type!==void 0,parentOrientation:G.type===`menubar`?G.context.orientation:void 0,loopFocus:d,focusItemOnOpen:b?de:void 0,allowEscape:b&&d&&S,orientation:f,triggerOrientation:b?`vertical`:f,rtl:Ne===`rtl`,disabledIndices:xt,onNavigate(e,t){V.setActiveIndex(e,Df(t),t?.nativeEvent)},openOnArrowKeyDown:G.type!==`context-menu`&&!(b&&y),externalTree:!b&&ve?re:void 0,nestedReturnFocusRef:z?.context.virtualFocusRef,focusItemOnHover:v,resetOnPointerLeave:ee}),Ie=Z.useCallback(e=>{V.context.typingRef.current=e},[V]),Le=rf(Oe,{enabled:!ce&&!b,listRef:V.context.itemLabels,elementsRef:V.context.itemDomElements,activeIndex:ue,resetMs:500,onMatch:(e,t)=>{U&&e!==ue&&V.setActiveIndex(e,It,t.nativeEvent)},onTyping:Ie}),ze=Jt(a),Be=Z.useRef(-1),Ve=Jt(()=>{let e=V.state.activeIndex,t=e===null?void 0:V.context.itemDomElements.current[e]??void 0;if(t?.isConnected===!1)return;let n=t===void 0?-1:e;if(Be.current===n&&V.context.reportedItem===t)return;Be.current=n,V.context.reportedItem=t,b&&V.set(`highlightedItem`,t);let{highlightReason:r,highlightEvent:i}=V.context;V.context.highlightReason=ct,V.context.highlightEvent=void 0,a&&ze(t,T(r,i,{label:t===void 0?void 0:V.context.itemLabels.current[n]??void 0}))});et(()=>{Ve()},[ue,Ve]);let He=Z.useMemo(()=>{if(!b)return Fe.reference;if(!Fe.trigger)return o;let{onFocus:e,...t}=Fe.trigger;return t},[b,Fe.reference,Fe.trigger]);V.useSyncedValue(`inputProps`,b?Fe.reference??o:o);let Ue=Z.useMemo(()=>{let e=se(Le.reference,He,Me.reference,{onMouseMove(){V.set(`allowMouseEnter`,!0)}},be);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=U,e},[V,Le.reference,He,Me.reference,be,U]),We=Z.useMemo(()=>{let e=se(Fe.trigger,Me.trigger,be);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=!1,e},[Fe.trigger,Me.trigger,be]);ie(()=>(V.update({inactiveTriggerProps:We}),null));let Ge=Z.useMemo(()=>se(c,{onMouseMove(){V.set(`allowMouseEnter`,!0),G.type===`menu`&&V.set(`hoverEnabled`,!1)},onClick(){V.select(`hoverEnabled`)&&V.set(`hoverEnabled`,!1)},onKeyDown(e){let t=V.select(`keyboardEventRelay`);t&&!e.isPropagationStopped()&&t(e)}},Le.floating,Fe.floating,Me.floating),[G.type,V,Le.floating,Fe.floating,Me.floating]),Ke=Fe.item??o;Rt(V,{floatingRootContext:Oe,activeTriggerProps:Ue,inactiveTriggerProps:We,popupProps:Ge,itemProps:Ke});let qe=Z.useMemo(()=>({store:V,parent:A,orientation:f,loopFocus:d,allowEscape:S,defaultFloatingId:M,setRenderedFloatingId:I,virtualFocus:b,parentVirtualFocus:k,syncHighlightedItem:Ve}),[V,A,f,d,S,M,b,k,Ve]),Je=typeof t==`function`?t({payload:pe}):t,Ye=(0,Q.jsxs)(vd.Provider,{value:qe,children:[h&&(0,Q.jsx)(we,{handle:h,store:V}),Je]});return(G.type===void 0||G.type===`context-menu`)&&(Ye=(0,Q.jsx)(jt,{externalTree:re,children:Ye})),Ye});function If(e){let t=Z.useContext(Mf);if(t===null)return(0,Q.jsx)(Ff,{...e});let n=t.Root;return(0,Q.jsx)(Mf.Provider,{value:null,children:(0,Q.jsx)(n,{...t.options,...e})})}var Lf=5;function Rf(e,t){let n=zf(t);return e.clientX>=n.left-Lf&&e.clientX<=n.right+Lf&&e.clientY>=n.top-Lf&&e.clientY<=n.bottom+Lf}function zf(e){let t=e.getBoundingClientRect(),n=Ht(e);if(Bt)return t;let r=n.getComputedStyle(e,`::before`),i=n.getComputedStyle(e,`::after`);if(r.content===`none`&&i.content===`none`)return t;let a=parseFloat(r.width)||0,o=parseFloat(r.height)||0,s=parseFloat(i.width)||0,c=parseFloat(i.height)||0,l=Math.max(t.width,a,s),u=Math.max(t.height,o,c),d=l-t.width,f=u-t.height;return{left:t.left-d/2,right:t.right+d/2,top:t.top-f/2,bottom:t.bottom+f/2}}function Bf(e={}){let{highlightItemOnHover:t,highlightedIndex:n,onHighlightedIndexChange:r}=i(),{ref:a,index:o}=Id(e),s=n===o,c=Z.useRef(null),l=re(a,c);return{compositeProps:{tabIndex:s?0:-1,onFocus(){r(o)},onMouseMove(){let e=c.current;if(!t||!e)return;let n=e.hasAttribute(`disabled`)||e.ariaDisabled===`true`;!s&&!n&&e.focus()}},compositeRef:l,index:o}}function Vf(e){let{render:t,className:n,style:r,state:i=o,props:a=xt,refs:s=xt,metadata:c,stateAttributesMapping:l,tag:u=`div`,...d}=e,{compositeProps:f,compositeRef:p}=Bf({metadata:c});return g(u,e,{state:i,ref:[p,...s],props:[f,...a,d],stateAttributesMapping:l})}function Hf(e){if(We(e)&&e.hasAttribute(`data-rootownerid`))return e.getAttribute(`data-rootownerid`);if(!Nt(e))return Hf(At(e))}function Uf(e){let{enabled:t=!0,mouseDownAction:n,open:r}=e,i=Z.useRef(!1);return Z.useMemo(()=>t?{onMouseDown:e=>{(n===`open`&&!r||n===`close`&&r)&&(i.current=!0,me(e.currentTarget).addEventListener(`click`,()=>{i.current=!1},{once:!0}))},onClick:e=>{i.current&&(i.current=!1,e.preventBaseUIHandler())}}:o,[t,n,r])}var Wf=I(function(e,t){let{render:r,className:s,style:c,disabled:l=!1,nativeButton:u=!0,id:d,openOnHover:f,delay:m=100,closeDelay:h=0,handle:_,payload:v,...y}=e,b=yd(!0),x=ne(_)??b?.store;if(!x)throw Error(ue(85));let S=F(d),ee=x.useState(`isTriggerActive`,S),C=x.useState(`floatingRootContext`),w=x.useState(`isOpenedByTrigger`,S),T=x.useState(`triggerControlsId`,S),te=Z.useRef(null),E=Kf(),D=i(!0),O=Ge(),k=Z.useMemo(()=>O??new Pt,[O]),A=Ut(k),j=mt(),{registerTrigger:M,isMountedByThisTrigger:N}=Ae(S,te,x,{payload:v,closeDelay:h,parent:E,floatingTreeRoot:k,floatingNodeId:A,floatingParentNodeId:j,keyboardEventRelay:D?.relayKeyboardEvent}),P=E.type===`menubar`,I=x.useState(`disabled`),L=l||I||P&&E.context.disabled,{getButtonProps:R,buttonRef:z}=je({disabled:L,native:u});Z.useEffect(()=>{!w&&E.type===void 0&&(x.context.allowMouseUpTriggerRef.current=!1)},[x,w,E.type]);let B=Z.useRef(null),V=bn(),re=Jt(e=>{if(!B.current)return;V.clear(),x.context.allowMouseUpTriggerRef.current=!1;let t=e.target;W(B.current,t)||W(x.select(`positionerElement`),t)||t===B.current||(t==null||Hf(t)!==x.select(`rootId`))&&(Rf(e,B.current)||k.events.emit(`close`,{domEvent:e,reason:Gt}))});Z.useEffect(()=>{let e=me(B.current);if(w&&x.select(`lastOpenChangeReason`)===`trigger-hover`)return e.addEventListener(`mouseup`,re,{once:!0}),()=>{e.removeEventListener(`mouseup`,re)}},[w,re,x]);let H=P&&E.context.hasSubmenuOpen,U=a(C,{enabled:(f??H)&&!L&&(!P||H&&!N),handleClose:bt({blockPointerEvents:!P}),mouseOnly:!0,move:!1,restMs:E.type===void 0?m:void 0,delay:{close:h},triggerElementRef:te,externalTree:k,isActiveTrigger:ee,isClosing:()=>x.select(`transitionStatus`)===`ending`}),ie=Gf(w,x.select(`lastOpenChangeReason`)),ae=n(C,{enabled:!L,event:w&&P?`click`:`mousedown`,toggle:!0,ignoreMouse:!1,stickIfOpen:E.type===void 0&&ie}),oe=Yd(C,{enabled:!L&&H}),ce=Uf({open:w,enabled:P,mouseDownAction:`open`}),le=Z.useMemo(()=>se(oe.reference,ae.reference),[oe.reference,ae.reference]),G=x.useState(`triggerProps`,N),de=x.useState(`filterTriggerProps`),{handlePreFocusGuardFocus:fe,handleFocusTargetFocus:pe}=at(x,te),K={disabled:L,open:w},he=[B,t,z,M,te],ge=[le,U??o,G,{"aria-haspopup":`menu`,"aria-controls":T,id:S,onMouseDown:e=>{x.select(`open`)||(V.start(200,()=>{x.context.allowMouseUpTriggerRef.current=!0}),me(e.currentTarget).addEventListener(`mouseup`,re,{once:!0}))}},de,P?{role:`menuitem`}:{},ce,y,R],q=g(`button`,e,{enabled:!P,stateAttributesMapping:p,state:K,ref:he,props:ge});return P?(0,Q.jsx)(Vf,{tag:`button`,render:r,className:s,style:c,state:K,refs:he,props:ge,stateAttributesMapping:p}):w?(0,Q.jsxs)(Z.Fragment,{children:[(0,Q.jsx)(hn,{ref:x.context.beforeTriggerFocusGuardRef,onFocus:fe},`${S}-pre-focus-guard`),(0,Q.jsx)(Z.Fragment,{children:q},S),(0,Q.jsx)(hn,{ref:x.context.triggerFocusTargetRef,onFocus:pe},`${S}-post-focus-guard`)]}):(0,Q.jsx)(Z.Fragment,{children:q},S)});function Gf(e,t){let n=bn(),[r,i]=Z.useState(!1);return et(()=>{e&&t===`trigger-hover`?(i(!0),n.start(500,()=>{i(!1)})):e||(n.clear(),i(!1))},[e,t,n]),r}function Kf(){let e=Ef(!0);return Z.useMemo(()=>e?{type:`menubar`,context:e}:{type:void 0},[e])}var qf=Z.forwardRef(function(e,t){let{className:n,render:r,orientation:i=`horizontal`,style:a,...o}=e;return g(`div`,e,{state:{orientation:i},ref:t,props:[{role:`separator`,"aria-orientation":i},o]})}),Jf=(0,Z.createContext)(null);function Yf({actionsRef:e,children:t,interactionOwner:n=`local`,onOpenChange:r,...i}){let a=(0,Z.useRef)(null),o=e??a;return Ft(()=>o.current?.close()),(0,Q.jsx)(Jf.Provider,{value:{actionsRef:o,interactionOwner:n},children:(0,Q.jsx)(If,{...i,actionsRef:o,onOpenChange:(e,t)=>{if(n===`host`&&!e&&t.reason===`escape-key`){t.cancel(),t.allowPropagation();return}r?.(e,t)},children:t})})}function Xf(){let e=(0,Z.useContext)(Jf);if(!e)throw Error(`DropdownMenu parts must be used inside <DropdownMenu>`);return e}var Zf=(0,Z.forwardRef)(function({className:e,render:t,type:n=`button`,...r},i){return(0,Q.jsx)(Wf,{...r,className:t=>mn(`btn caps-dropdown-trigger`,Je(e,t)),ref:i,render:t,type:n})}),Qf=(0,Z.forwardRef)(function({container:e,...t},n){let r=Tt(`popover`);return e==null&&r===null?null:(0,Q.jsx)(gf,{...t,container:e??r,ref:n})}),$f=(0,Z.forwardRef)(function({collisionBoundary:e,...t},n){let r=Tt(`popover`);return(0,Q.jsx)(wf,{...t,collisionBoundary:e??(r&&r!==document.body?r:void 0),ref:n})}),ep=(0,Z.forwardRef)(function({className:e,finalFocus:t,...n},r){let{interactionOwner:i}=Xf(),a=(0,Z.useRef)(null);(0,Z.useImperativeHandle)(r,()=>a.current);let o=st(`.caps-dropdown-item[data-highlighted]`),s=(0,Z.useCallback)(e=>{a.current=e,o(e)},[o]);return(0,Q.jsx)(pf,{...n,className:t=>mn(`caps-dropdown-popup min-w-40 rounded-box border border-base-300 bg-base-100 p-xs shadow-lg outline-none`,Je(e,t)),finalFocus:i===`host`?!1:t??!0,ref:s})}),tp=(0,Z.forwardRef)(function({align:e=`end`,alignOffset:t,children:n,container:r,keepMounted:i,side:a=`bottom`,sideOffset:o=4,...s},c){return(0,Q.jsx)(Qf,{container:r,keepMounted:i,children:(0,Q.jsx)($f,{align:e,alignOffset:t,side:a,sideOffset:o,children:(0,Q.jsx)(ep,{...s,ref:c,children:n})})})}),np=`caps-dropdown-item flex w-full items-center gap-sm rounded-field px-md py-sm text-left text-sm outline-none transition-colors hover:bg-base-200 focus-visible:bg-base-200 aria-[current=page]:bg-base-200 aria-[current=page]:font-semibold disabled:cursor-not-allowed disabled:text-base-content/40 data-disabled:cursor-not-allowed data-disabled:text-base-content/40`,rp=(0,Z.forwardRef)(function({className:e,onClick:t,onSelect:n,variant:r=`default`,...i},a){return(0,Q.jsx)(qd,{...i,className:t=>mn(np,r===`destructive`&&`text-error hover:bg-error hover:text-error-content focus-visible:bg-error focus-visible:text-error-content`,Je(e,t)),onClick:e=>{t?.(e),e.defaultPrevented||n?.(e)},ref:a})}),ip=(0,Z.forwardRef)(function({children:e,className:t,onClick:n,onSelect:r,...i},a){return(0,Q.jsxs)(Vd,{...i,className:e=>mn(np,Je(t,e)),onClick:e=>{n?.(e),e.defaultPrevented||r?.(e)},ref:a,children:[(0,Q.jsx)(`span`,{className:`min-w-0 flex-1`,children:e}),(0,Q.jsx)(Hd,{"aria-hidden":`true`,className:`shrink-0`,children:`✓`})]})}),ap=(0,Z.forwardRef)(function({className:e,...t},n){return(0,Q.jsx)(qf,{...t,className:t=>mn(`my-xs h-px bg-base-300`,Je(e,t)),ref:n})});(0,Z.forwardRef)(function({className:e,...t},n){return(0,Q.jsx)(Gd,{...t,className:t=>mn(`px-md pb-xs pt-sm text-xs font-semibold text-base-content/60`,Je(e,t)),ref:n})});var op=`<leader>`;new Intl.Segmenter(void 0,{granularity:`grapheme`});var sp=new Map([[`arrowleft`,`left`],[`arrowright`,`right`],[`arrowup`,`up`],[`arrowdown`,`down`],[`esc`,`escape`],[` `,`space`]]);function cp(e){let t=e.toLowerCase();return sp.get(t)??t}var lp=new Map([[`alt`,`alt`],[`option`,`alt`],[`ctrl`,`ctrl`],[`control`,`ctrl`],[`super`,`meta`],[`meta`,`meta`],[`cmd`,`meta`],[`shift`,`shift`],[`mod`,`platform`]]);function up(e,t){if(e.startsWith(op)||e.trim().includes(` `))return null;let n=e.toLowerCase().split(`+`),r=n.pop();if(r===void 0||r.length===0)return null;let i={key:cp(r),alt:!1,ctrl:!1,meta:!1,shift:!1};for(let e of n){let n=lp.get(e);if(n===void 0)return null;let r=n===`platform`?t?`meta`:`ctrl`:n;i[r]=!0}return i}var dp=`mod+k`;function fp(){return/Mac|iPhone|iPad/u.test(navigator.userAgent)}function pp(e,t){let n=[];return e.ctrl&&n.push(t?`⌃`:`Ctrl`),e.alt&&n.push(t?`⌥`:`Alt`),e.shift&&n.push(t?`⇧`:`Shift`),e.meta&&n.push(t?`⌘`:`Win`),n.push(e.key.toUpperCase()),n}function mp(e=fp()){let t=up(dp,e);return t?pp(t,e):[]}function hp(e=fp()){return mp(e).join(e?``:`+`)}var gp=`modulepreload`,_p=function(e,t){return new URL(e,t).href},vp={},yp=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=_p(t,n),t=s(t),t in vp)return;vp[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:gp,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},bp=(0,Z.lazy)(async()=>({default:(await yp(()=>import(`./FileTab-BHqgbtrf.js`),__vite__mapDeps([0,1,2,3]),import.meta.url)).FileTab})),xp=(0,Z.lazy)(async()=>({default:(await yp(()=>import(`./InkcapFileTree-4aUfCyx4.js`),__vite__mapDeps([4,1,2,5,3,6]),import.meta.url)).InkcapFileTree}));function Sp({model:e}){let[t,n]=(0,Z.useState)(null),[r,i]=(0,Z.useState)(!1),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(null),[l,u]=(0,Z.useState)(!1),d=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{let e=d.current;if(!e||!(`ResizeObserver`in globalThis))return;let t=()=>{i(e.clientWidth<=576)},n=new ResizeObserver(t);return t(),n.observe(e),()=>{n.disconnect()}},[]);let[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(null),g=e.canList&&e.selectedConnection!==null&&e.context.computerId!==null&&!e.selectedConnection.source,_=Zr(Pr(g?e.selectedConnection?.app??null:null,e.context.projectPath)),v=_.data?.entries.filter(e=>e.type===`file`)??[],y=v.at(0),b=g&&e.tabs.length===0&&(_.isPending||_.isSuccess&&_.data.entries.length===0),x=t??!b,ee=e=>{n(typeof e==`function`?e(x):e)},C=(0,Z.useRef)(e.browseRequest);(0,Z.useEffect)(()=>{C.current!==e.browseRequest&&(C.current=e.browseRequest,r?o(!0):n(!0))},[e.browseRequest,r]);let w=e.selectedConnection?.source?.kind===`repository`,T=e.canList&&e.selectedConnection!==null&&e.context.computerId!==null&&!e.selectedConnection.source&&e.selectedConnection.app.capabilities.has(fr),[te,E]=(0,Z.useState)(null),D=(0,Z.useId)(),O=t=>m&&e.selectedConnection&&(t.connection===null||t.connection===e.selectedConnection)?Ot(m,e.context.projectPath):t.path.startsWith(`/`)?qt(t.path):e.context.projectPath,A=t=>{let n=t.connection??e.selectedConnection;return!n||n.source?.kind!==`repository`&&n.app.context.get().computerId===null},j=t=>{let n=t.connection??e.selectedConnection;if(!n)return null;let r=O(t);return n.source?.kind===`repository`?r.replace(/^\/+/u,``)||null:r},M=(t,n)=>{let r=O(t);return(t.connection??e.selectedConnection)?.source?.kind===`repository`?cu.parse(n.trim()):t.connection||e.selectedConnection?dt(n,r):n.trim()},N=e.sourceLabel??e.context.computerName??`Computer`,P=e.tabs.filter(e=>e.dirty).length;Wn(e.connection?.app,[{kind:`text`,id:`documents`,priority:`low`,text:`${String(e.tabs.length)} ${e.tabs.length===1?`open file`:`open files`}`},{kind:`text`,id:`save`,text:P?`${String(P)} unsaved`:e.downloadedFile?.tabKey===e.active?`Downloaded ${e.downloadedFile.name}`:e.repositoryStatus??(e.tabs.length?`All changes saved`:`Ready`),end:!0}]);let F=e.tabs.find(t=>t.tabKey===e.active);(0,Z.useEffect)(()=>{let e=d.current?.querySelector(`.inkcap-tabs`);if(!e)return;let t=()=>{let t=e.scrollWidth-e.clientWidth;e.toggleAttribute(`data-overflow-start`,e.scrollLeft>1),e.toggleAttribute(`data-overflow-end`,e.scrollLeft<t-1),u(t>1)},n=()=>{let t=Array.from(e.querySelectorAll(`[role="tab"]`)),n=t.at(0),r=t.at(-1),i=r?.nextElementSibling,a=``;if(n&&r&&i instanceof HTMLElement){let t=i.offsetLeft+i.offsetWidth-n.offsetLeft,o=i.offsetLeft+i.offsetWidth-r.offsetLeft;t>e.clientWidth&&(a=`${String(Math.max(0,e.clientWidth-o))}px`)}e.style.paddingInlineEnd=a},r=()=>{n();let r=e.querySelector(`[aria-selected="true"]`),i=e.firstElementChild,a=r?.nextElementSibling;if(r&&i instanceof HTMLElement&&a instanceof HTMLElement){let t=r.offsetLeft-i.offsetLeft,n=a.offsetLeft+a.offsetWidth-i.offsetLeft;if(t<e.scrollLeft)e.scrollLeft=t;else if(n>e.scrollLeft+e.clientWidth){let r=n-e.clientWidth,a=Array.from(e.querySelectorAll(`[role="tab"]`)).map(e=>e.offsetLeft-i.offsetLeft).filter(e=>e>=r&&e<=t);e.scrollLeft=a[0]??t}}t()};r(),e.addEventListener(`scroll`,t,{passive:!0});let i=`ResizeObserver`in globalThis?new ResizeObserver(r):null;i?.observe(e);for(let t of e.children)i?.observe(t);return()=>{e.removeEventListener(`scroll`,t),i?.disconnect()}},[e.active,e.tabs.length,r]),(0,Z.useEffect)(()=>{h(null)},[e.selectedConnection?.app.identity.surfaceId,e.context.computerId,e.context.projectPath]),(0,Z.useEffect)(()=>{x&&e.selectedConnection&&e.context.computerId!==null&&e.canList&&p(!0)},[x,e.canList,e.context.computerId,e.selectedConnection]);let I=e.fileTree?.(t=>{e.onOpenFile(t),o(!1)},r)??(0,Q.jsx)(Cp,{model:e,narrow:r,treeLoadRequested:f,active:F,computer:N,onOpenFile:t=>{e.onOpenFile(t),o(!1)},onSelectPath:h,creationRequest:te,onCreationRequestHandled:()=>{E(null)},onDismissExplorerDialog:()=>{o(!1)}});return(0,Q.jsxs)(`main`,{ref:d,className:`inkcap-app`,"data-narrow":r?``:void 0,"aria-label":`Inkcap editor`,onKeyDown:e=>{e.nativeEvent.composedPath().some(e=>e instanceof HTMLElement&&e.isContentEditable)&&e.stopPropagation()},children:[e.error?(0,Q.jsx)(xl,{className:`inkcap-notice`,tone:`error`,title:`Couldn't complete that action`,description:e.error}):null,(0,Q.jsxs)(`div`,{className:`inkcap-work`,"data-explorer":x,children:[r?null:(0,Q.jsx)(`div`,{className:`inkcap-explorer`,id:`${D}-explorer`,hidden:!x,children:I}),(0,Q.jsxs)(ud,{className:`inkcap-editors`,value:e.active===null?``:String(e.active),onValueChange:t=>{let n=e.tabs.find(e=>String(e.tabKey)===t);n&&e.onActivate(n.tabKey)},children:[(0,Q.jsxs)(`div`,{className:`inkcap-tab-bar`,children:[r?(0,Q.jsxs)(He,{open:a,onOpenChange:o,children:[(0,Q.jsx)(nt,{render:(0,Q.jsxs)(K,{size:`sm`,variant:`ghost`,className:`inkcap-files-button`,children:[(0,Q.jsx)(nd,{"aria-hidden":`true`}),` Files`]})}),(0,Q.jsxs)(Wt,{className:`inkcap-explorer-dialog`,children:[(0,Q.jsxs)(Xt,{children:[(0,Q.jsx)(Ze,{children:`Files`}),(0,Q.jsx)(Xe,{children:`Browse files on ${e.sourceLabel??(!e.selectedConnection||e.context.computerId===null?`your Computer`:N)}.`})]}),I,(0,Q.jsx)(Ct,{children:(0,Q.jsx)(Mt,{render:(0,Q.jsx)(K,{variant:`outline`}),children:`Close`})})]})]}):(0,Q.jsxs)(K,{size:`sm`,variant:`ghost`,className:`inkcap-explorer-toggle inkcap-files-button`,title:x?`Hide file explorer`:`Show file explorer`,"aria-expanded":x,"aria-controls":`${D}-explorer`,onClick:()=>{ee(e=>!e)},children:[(0,Q.jsx)(nd,{"aria-hidden":`true`}),` Files`]}),(0,Q.jsx)(fd,{className:`inkcap-tabs gap-0`,"aria-label":`Editor tabs`,children:e.tabs.map(t=>(0,Q.jsxs)(Z.Fragment,{children:[(0,Q.jsxs)(pd,{className:`inkcap-tab`,value:String(t.tabKey),title:t.connection?.source?`${t.path} · ${t.connection.source.label}`:t.path,children:[(0,Q.jsx)(td,{"aria-hidden":`true`}),(0,Q.jsx)(`span`,{children:t.path.split(`/`).at(-1)}),t.dirty?(0,Q.jsx)(`span`,{className:`inkcap-dirty`,"aria-label":`Unsaved changes`}):null]}),(0,Q.jsx)(S,{size:`responsive`,variant:`ghost`,icon:(0,Q.jsx)(k,{}),"aria-label":`Close ${t.path}`,onClick:()=>{e.onClose(t.tabKey)}})]},t.tabKey))}),(0,Q.jsxs)(`div`,{className:`inkcap-tab-actions`,children:[l?(0,Q.jsxs)(Yf,{children:[(0,Q.jsx)(Zf,{render:(0,Q.jsxs)(K,{size:`sm`,variant:`ghost`,className:`inkcap-tab-list`,"aria-label":`Open files, ${String(e.tabs.length)}`,title:`Open files`,children:[(0,Q.jsx)(ed,{"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`tabular-nums`,children:e.tabs.length})]})}),(0,Q.jsx)(tp,{align:`end`,children:e.tabs.map(t=>(0,Q.jsx)(ip,{checked:t.tabKey===e.active,onSelect:()=>{e.onActivate(t.tabKey)},children:t.path.split(`/`).at(-1)},t.tabKey))})]}):null,(0,Q.jsx)(S,{size:`responsive`,icon:(0,Q.jsx)(Or,{}),"aria-label":`New draft`,title:`New draft (${hp()}, then N)`,onClick:e.onNewDraft}),(0,Q.jsx)(`span`,{className:`inkcap-menu-slot`,ref:c})]})]}),e.tabs.map(t=>(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(id,{message:`Opening editor`,size:`sm`,framed:!1}),children:(0,Q.jsx)(bp,{activityNotice:e.activityNotice?.path===t.path&&e.activityNotice.computerId===t.computerId,onDismissActivityNotice:e.onDismissActivityNotice,path:t.path,initial:t.initial,active:e.active===t.tabKey,menuSlot:s,narrow:r,local:t.connection===null,savable:t.connection===null||wp(t.connection),sourceLabel:(t.connection??e.selectedConnection)?.source?.kind===`repository`?(t.connection??e.selectedConnection)?.source?.label:void 0,previewUrl:t.previewUrl,previewKind:t.previewKind,target:t.target,syncConflict:t.connection?.source!==void 0&&e.repositoryStates?.get(`${t.connection.source.id}:${t.path}`)?.kind===`conflict`,tabKey:t.tabKey,onSaveBinding:e.onSaveBinding,onReopen:t.connection===null?void 0:()=>{e.onReopen(t)},saveAsDirectory:j(t),downloads:A(t),onSaved:e.onSaved,onSaveAs:async(n,r)=>{let i=M(t,n);return await e.onSaveAs(t,i,r),i},pathExists:async n=>{let r=M(t,n);return r===t.path?`absent`:await e.onPathExists(t,r)},onPathChange:n=>{e.onPathChange(t,n)},onStatus:(n,r)=>{e.onStatus(t,n,r)},write:(n,r)=>e.onWrite(t,n,r),overwrite:n=>e.onOverwrite(t,n),readCurrent:n=>e.onReadCurrent(t,n)})},t.tabKey)),e.tabs.length===0&&_.isError&&(!x||r&&!a)?(0,Q.jsx)(sr,{message:an(_.error).message,onRetry:()=>{_.refetch()}}):e.tabs.length===0?(0,Q.jsx)(cd,{className:`inkcap-empty`,variant:`quiet`,visual:`blobs`,title:w?`Open a repository file`:v.length>0?`Open a saved file`:T?`Start your first file`:`Write a draft`,description:w?`Browse the repository to choose a file to edit.`:v.length>0?`Your files are saved here. Choose one to keep working.`:T?`Write notes or code and save them here.`:g?`This folder is read-only. Open a file or write a draft.`:`Drafts stay in this window until you save them.`,primaryAction:w?{label:`Browse files`,onSelect:()=>{ee(!0),o(!0)}}:y?{label:`Open ${y.name}`,onSelect:()=>{e.onOpenFile(dt(y.name,e.context.projectPath))}}:T?{label:`New file`,onSelect:()=>{p(!0),r?o(!0):ee(!0),E({kind:`file`})}}:{label:`New draft`,onSelect:e.onNewDraft},suggestions:v.length>0?v.slice(1,9).map(t=>({label:t.name,onSelect:()=>{e.onOpenFile(dt(t.name,e.context.projectPath))}})):T?[`notes.md`,`todo.md`,`ideas.md`].map(e=>({label:e,onSelect:()=>{p(!0),r?o(!0):ee(!0),E({kind:`file`,name:e,immediate:!0})}})):void 0,secondaryAction:v.length>0?(0,Q.jsx)(K,{variant:`outline`,disabled:!T,title:T?void 0:`File write access is not granted.`,onClick:()=>{p(!0),r?o(!0):ee(!0),E({kind:`file`})},children:`New file`}):void 0,actions:v.length===0&&!r?(0,Q.jsxs)(`span`,{className:`inkcap-shortcut`,children:[(0,Q.jsx)(`span`,{children:`New draft:`}),mp().map(e=>(0,Q.jsx)(hd,{size:`sm`,children:e},e)),(0,Q.jsx)(`span`,{children:`then`}),(0,Q.jsx)(hd,{size:`sm`,children:`N`})]}):void 0}):null]})]}),(0,Q.jsx)(Tp,{open:e.windowClosing||e.closing!==null,all:e.windowClosing,reviewWhileSaving:e.windowClosing?e.tabs.some(e=>e.connection?.source?.kind===`repository`):e.tabs.some(t=>t.tabKey===e.closing&&t.connection?.source?.kind===`repository`),busy:e.windowCloseSaving||e.tabs.some(t=>t.tabKey===e.closing&&t.target.saving),error:e.error,onSave:e.windowClosing?e.onSaveWindowClose:()=>{e.closing!==null&&e.onSaveClose(e.closing)},onDiscard:e.windowClosing?e.onDiscardWindowClose:()=>{e.closing!==null&&e.onDiscardClose(e.closing)},onCancel:e.windowClosing?e.onCancelWindowClose:e.onCancelClose})]})}function Cp({model:e,narrow:t,treeLoadRequested:n,active:r,computer:i,onOpenFile:a,onSelectPath:o,creationRequest:s,onCreationRequestHandled:c,onDismissExplorerDialog:l}){return!e.selectedConnection||e.context.computerId===null||!e.canList?(0,Q.jsx)(cd,{className:`inkcap-tree inkcap-access`,"aria-label":`File tree`,variant:`panel`,visual:(0,Q.jsx)(Lr,{"aria-hidden":`true`}),title:e.selectedConnection?e.context.computerId===null?`No Computer selected`:`Files unavailable`:`No Computer connected`,description:!e.selectedConnection||e.context.computerId===null?`Pick a Computer with the Computer picker to browse its files. You can still write a draft.`:`File access isn't granted. Your open documents remain available.`,actions:e.connection&&e.context.computerId===null?(0,Q.jsx)(K,{className:`whitespace-nowrap`,size:`sm`,variant:`outline`,onClick:()=>{l(),e.onChooseComputer()},children:`Choose Computer`}):void 0}):n?(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(id,{className:`inkcap-tree inkcap-access`,message:`Loading files`,size:`sm`,framed:!1}),children:(0,Q.jsx)(xp,{rowHeight:t?44:32,app:e.selectedConnection.app,rootPath:e.context.projectPath,rootLabel:i,activePath:r?.connection===e.selectedConnection&&r.computerId===e.context.computerId?r.path:null,onOpenFile:a,onSelectPath:o,creationRequest:s,onCreationRequestHandled:c},`${e.selectedConnection.app.identity.surfaceId}:${e.context.computerId}:${e.context.projectPath}:${String(t)}`)}):(0,Q.jsx)(id,{className:`inkcap-tree inkcap-access`,message:`Loading files`,size:`sm`,framed:!1})}function wp(e){let t=e.app.lifecycle.get();return t!==`disposing`&&t!==`disposed`&&t!==`disconnected`}function Tp({open:e,all:t,busy:n,reviewWhileSaving:r,error:i,onSave:a,onDiscard:o,onCancel:s}){return(0,Q.jsx)(He,{open:e&&!(r&&n),onOpenChange:e=>{!e&&!n&&s()},children:(0,Q.jsxs)(Wt,{children:[(0,Q.jsxs)(Xt,{children:[(0,Q.jsx)(Ze,{children:t?`Close Inkcap with unsaved changes`:`Unsaved changes`}),(0,Q.jsx)(Xe,{children:t?`Save your changed documents before closing Inkcap?`:`Save your changes before closing this document?`})]}),i?(0,Q.jsx)(xl,{tone:`error`,title:`Couldn't save`,description:i}):null,(0,Q.jsxs)(Ct,{children:[(0,Q.jsx)(K,{variant:`ghost`,size:`sm`,disabled:n,onClick:s,children:`Cancel`}),(0,Q.jsx)(K,{variant:`ghost`,size:`sm`,disabled:n,onClick:o,children:`Discard`}),(0,Q.jsx)(K,{size:`sm`,disabled:n,onClick:a,children:n?`Saving…`:t?`Save all`:`Save`})]})]})})}var Ep={computerId:null,computerName:null,projectPath:Ju},Dp={exists:(e,t,n)=>Qu(t,async(t,r)=>{let i=0;for(;i!==null;){let a=i,o=await hr(e.capabilities,{path:t,limit:256,offset:a});if(n.throwIfAborted(),o.entries.some(e=>e.name===r))return!0;if(o.nextOffset!==null&&o.nextOffset<=a)throw Error(`The folder listing did not advance.`);i=o.nextOffset}return!1}),read:(e,t,n,r)=>qu(e,t,n,r),replace:async(e,t,n)=>{await Er(e.capabilities,t,{signal:n})},write:async(e,t,n,r)=>{await yr(e.capabilities,{path:t,content:new Blob([n],{type:`text/plain;charset=utf-8`})},{signal:r})}};function Op(e){let t=e.app.lifecycle.get();return t!==`disposing`&&t!==`disposed`&&t!==`disconnected`}function kp(e,t,n,r,i){return!e.aborted&&Op(t)&&(t.source?.kind===`repository`||t.app.context.get().computerId===i)&&(n!==void 0||r===t)}function Ap(e,t,n,r){let i=t===void 0?void 0:n.find(e=>e.tabKey===t),a=i?.connection??r;if(!a||!Op(a))return null;let o=a.source?.kind===`repository`?null:a.app.context.get().computerId;if(i&&a.source?.kind!==`repository`&&i.computerId!==o)return null;let s=n.find(t=>t.path===e&&t.connection===a&&t.computerId===o);return t!==void 0&&!i?null:{selected:a,replacement:i,existing:s}}function jp(e,t,n,r,i,a,o,s,c){let l=Mp(e,t,r,i);if(l){o(l);return}a!==void 0&&s(r,a),o(``),(e.kind===`image`||e.kind===`video`)&&c(t,``,n,URL.createObjectURL(e.blob),e.kind),e.kind===`text`&&c(t,e.contents,n)}function Mp(e,t,n,r){if(e.kind===`changed`||e.kind===`closed`)return e.kind===`changed`?`Reopen cancelled because this tab changed during the read. Your edits remain open.`:`Reopen cancelled because this tab was closed.`;let i=n!==void 0&&n.target.revision!==r;if(n?.target.closed||i)return i?`Reopen cancelled because this tab changed during the read. Your edits remain open.`:`Reopen cancelled because this tab was closed.`;if(e.kind===`invalid-text`)return`The file ${t} is not valid UTF-8 text. Existing edits remain open.`}function Np({connection:e,context:t=Ep,files:n=Dp}){let r=In();function i(e){return e.source??{kind:`computer`,id:e.app.context.get().computerId??``,label:`Computer`,read:(t,r,i)=>n.read(e.app,t,r,i),replace:(t,r,i,a)=>n.replace(e.app,{path:t,content:r,expectedContent:i},a),write:(t,r,i)=>n.write(e.app,t,r,i),exists:(t,r)=>n.exists(e.app,t,r)}}let a=Zn(e?.app),o=Ur(e?.app)?.openRequest,s=(0,Z.useRef)(new Set),c=e?{...t,computerId:a,computerName:t.computerId===a?t.computerName:null}:t,[l,u]=(0,Z.useState)([]),[d,f]=(0,Z.useState)(Du),{current:p,canGoBack:m,canGoForward:h}=Dn(d)??d.get(),g=(0,Z.useRef)(d);g.current=d,kn(e?.app.window.navigation,{canGoBack:m,canGoForward:h,onBack:()=>g.current.back(),onForward:()=>g.current.forward()});let _=(0,Z.useCallback)(e=>{Ou(g.current,e)},[]),[v,y]=(0,Z.useState)(null),[b,x]=(0,Z.useState)(!1),[S,ee]=(0,Z.useState)(!1),[C,w]=(0,Z.useState)(``),[T,te]=(0,Z.useState)(null),[E,D]=(0,Z.useState)(null),O=(0,Z.useRef)([]),k=(0,Z.useRef)(0),A=(0,Z.useRef)(new Set),j=(0,Z.useRef)(new Set),M=(0,Z.useRef)(e),N=(0,Z.useRef)(null),P=(0,Z.useRef)(new Map),[,F]=(0,Z.useState)(0),I=(0,Z.useRef)(()=>Promise.reject(Error(`Inkcap is not ready to open a handed-off file.`))),L=(0,Z.useRef)(null);N.current=p,(0,Z.useEffect)(()=>{M.current=e,D(null);let t=e?.app.lifecycle.subscribe(t=>{(t===`disposing`||t===`disposed`||t===`disconnected`)&&M.current===e&&(M.current=null)});return()=>t?.()},[e,a]),(0,Z.useEffect)(()=>()=>{L.current?.resolve(!1),L.current=null,M.current=null,P.current.clear();for(let e of A.current)e.abort();A.current.clear()},[]),O.current=l,(0,Z.useEffect)(()=>()=>{for(let e of O.current)e.previewUrl&&URL.revokeObjectURL(e.previewUrl)},[]);let R=(0,Z.useCallback)((e,t,n,r,i,a=!0)=>{let o=++k.current,s=n?.source?.kind===`repository`?null:n?.app.context.get().computerId??null;u(a=>[...a,{tabKey:o,path:e,initial:t,connection:n,computerId:s,previewUrl:r,previewKind:i,dirty:!1,target:{revision:0,closed:!1,dirty:!1,saving:!1}}]),a&&_(o)},[_]),z=(0,Z.useCallback)(()=>{R(`Untitled ${String(k.current+1)}`,``,null)},[R]),ne=(0,Z.useCallback)(()=>{let e=N.current;return e===null?void 0:P.current.get(e)},[]),[B,V]=(0,Z.useState)(0),re=(0,Z.useCallback)(()=>{V(e=>e+1)},[]);Lu(e?.app??null,{newDraft:z,browseFiles:re,save:ne,openFile:e=>I.current(e)});function H(e){e.previewUrl&&URL.revokeObjectURL(e.previewUrl)}function U(e,t){e&&(e.target.closed=!0,H(e),u(e=>e.filter(e=>e.tabKey!==t)),f(e=>ku(e,t)))}async function ie(e,t,n,r){if(e.source?.kind===`repository`||t===null)return;let i=await eu(e.app,t,n,r);M.current===e&&e.app.context.get().computerId===t&&Op(e)&&D(i?null:{computerId:t,path:n})}async function W(e,t,n=!1){let r=Ap(e,t,l,M.current);if(!r)return;let{selected:a,replacement:o,existing:s}=r,c=a.source?.kind===`repository`?null:a.app.context.get().computerId;if(s&&t===void 0){_(s.tabKey);return}if(t!==void 0&&!o)return;let u=`${a.app.identity.surfaceId}:${a.source?.id??c??``}:${e}`;if(j.current.has(u))return;let d=o?.target.revision;j.current.add(u);let f=new AbortController;A.current.add(f);try{let r=await i(a).read(e,f.signal,o?.target);if(!kp(f.signal,a,t,M.current,c))return;let s=!Mp(r,e,o,d);jp(r,e,a,o,d,t,w,U,(e,r,i,a,o)=>{R(e,r,i,a,o,!n||N.current===t)}),!n&&s&&await ie(a,c,e,`opened`)}catch(t){if(f.signal.aborted)return;console.error(`Inkcap file read failed`,t),w(t instanceof q&&t.code===`FILE_TOO_LARGE`?a.source?.kind===`repository`?`This repository file is too large to edit in Inkcap. Choose a smaller file. Existing edits remain open.`:`This file is too large to preview in Inkcap. Choose a smaller file. Existing edits remain open.`:`Could not read ${e}. Access may be denied or ${a.source?.label??`the Computer`} unavailable. Existing edits remain open.`)}finally{A.current.delete(f),j.current.delete(u)}}I.current=async({computerId:e,path:t})=>{if(M.current?.source?.kind===`repository`)throw Error(`Open Computer file handoffs in the Computer source.`);if(M.current?.app.context.get().computerId!==e)throw Error(`The handed-off file belongs to a different admitted Computer.`);await W(t)};function ae(e,t=!1){let n=l.find(t=>t.tabKey===e);if(n){if(n.target.saving){w(`Wait for this save to finish before closing. Your edits remain open.`);return}if(n.target.dirty&&!t){y(e),w(``);return}n.target.closed=!0,H(n),y(t=>t===e?null:t),u(t=>t.filter(t=>t.tabKey!==e)),f(t=>ku(t,e))}}(0,Z.useEffect)(()=>{if(!e||o?.kind!==`navigate`)return;let t=wu(o.params);if(t===null||`repository`in t)return;let n=JSON.stringify([e.app.identity.surfaceId,o.requestId]);if(s.current.has(n))return;if(s.current.add(n),s.current.size>64){let e=s.current.values().next().value;e!==void 0&&s.current.delete(e)}let r=Yl.safeParse({computerId:a,path:t.path});if(!r.success||e.source?.kind===`repository`){w(`This Recent File is unavailable on the current Computer source.`);return}let i=!0;return I.current(r.data).catch(t=>{i&&(console.error(`Inkcap Recent File could not be opened`,Bn(t)),M.current===e&&w(`This Recent File could not be opened. Your existing documents remain open.`))}),()=>{i=!1}},[e,a,o]);async function oe(e,t,n){if(!Op(e))throw Error(`${e.source?.label??`Computer`} disconnected`);if(e.source?.kind!==`repository`&&(t===null||e.app.context.get().computerId!==t)){let e=`Select this file's original Computer before saving or reloading. Your edits remain open.`;throw w(e),Error(e)}let r=new AbortController;A.current.add(r);try{return await n(r.signal)}finally{A.current.delete(r)}}function se(e,t,n,r){return oe(e,t,async a=>{await i(e).write(n,r,a),await ie(e,t,n,`edited`)})}async function ce(e,t,n){let r=M.current?.app;if(!r)throw Error(`Download requires a connected App host.`);let i=t.split(`/`).at(-1)??t,a=/\.[^.]+$/.test(i)?i:`${i}.txt`,o=await r.ui.requestBrowserAction({kind:`saveFile`,name:a,mime:`text/plain;charset=utf-8`,bytes:new TextEncoder().encode(n)});if(o.kind===`refused`)throw Error(`Download refused: ${o.reason}`);if(o.kind!==`saved`)throw Error(`The App host did not accept this download.`);te({tabKey:e.tabKey,name:a})}function le(e,t={}){let n=e.connection;if(n){if(e.target.saving){w(`Wait for this save to finish before reopening.`);return}if(e.target.dirty){w(`Save your edits before reopening this file.`);return}if(!Op(n)){w(`Computer disconnected. Existing edits remain open.`);return}if(n.source?.kind!==`repository`&&n.app.context.get().computerId!==e.computerId){w(`Select this file's original Computer before reopening. Existing edits remain open.`);return}W(e.path,e.tabKey,t.background)}}let G=e,ue=G?.app.capabilities.has(zr)??!1,de=(0,Z.useCallback)((e,t)=>{t?P.current.set(e,t):P.current.delete(e),F(e=>e+1)},[]),fe=(0,Z.useCallback)(e=>{let t=L.current;L.current=null,x(!1),ee(!1),t?.resolve(e)},[]),pe=(0,Z.useCallback)(()=>{let e=L.current;if(e)return e.promise;if(!O.current.some(e=>e.target.dirty))return Promise.resolve(!0);if(O.current.some(e=>e.target.saving))return w(`Wait for the current save to finish before closing Inkcap.`),Promise.resolve(!1);let t,n=new Promise(e=>{t=e});return L.current={promise:n,resolve:t},w(``),x(!0),n},[]),me=(0,Z.useCallback)(async()=>{if(!(!L.current||S)){ee(!0);try{for(let e of O.current.filter(e=>e.target.dirty)){let t=P.current.get(e.tabKey);if(!t)throw Error(`A dirty document is unavailable to save.`);if(await t.save(),e.target.dirty)throw Error(`A dirty document could not be saved.`)}fe(!0)}catch(e){w(e instanceof Error?`${e.message} Inkcap remains open.`:`A document could not be saved. Inkcap remains open.`),ee(!1)}}},[fe,S]);return{connection:e,selectedConnection:G,canList:ue,context:c,error:C,downloadedFile:T,activityNotice:E,onDismissActivityNotice:()=>{D(null)},tabs:l,active:p,closing:v,windowClosing:b,windowCloseSaving:S,requestWindowClose:pe,onSaveWindowClose:()=>{me()},onDiscardWindowClose:()=>{fe(!0)},onCancelWindowClose:()=>{fe(!1)},onNewDraft:z,browseRequest:B,onChooseComputer:()=>{let e=M.current?.app;if(!e){w(`The Computer picker requires a connected App host.`);return}e.ui.requestComputerChoice().catch(e=>{console.error(`Inkcap Computer choice failed`,Bn(e)),w(e instanceof Error?e.message:`Couldn't open the Computer picker.`)})},onOpenFile:e=>{W(e)},onActivate:_,onClose:e=>{ae(e)},onSaveClose:e=>{let t=P.current.get(e);if(!t){w(`This document is no longer available to save.`);return}t.save().catch(e=>{w(e instanceof Error?e.message:`Couldn't save. Your document remains open.`)})},onDiscardClose:e=>{ae(e,!0)},onCancelClose:()=>{y(null)},onReopen:le,onSaveAs:async(e,t,n)=>{let i=e.connection??M.current;if(!i||i.source?.kind!==`repository`&&i.app.context.get().computerId===null){await ce(e,t,n);return}let a=i.source?.kind===`repository`?null:e.connection?e.computerId:i.app.context.get().computerId,o=ar.of(i.app,`tree`);await se(i,a,t,n),r.invalidateQueries({queryKey:o}),e.connection||u(t=>t.map(t=>t.tabKey===e.tabKey?{...t,connection:i,computerId:a}:t))},onPathExists:async(e,t)=>{let n=e.connection??M.current;if(!n||n.source?.kind!==`repository`&&n.app.context.get().computerId===null)return`absent`;let r=n.source?.kind===`repository`?null:e.connection?e.computerId:n.app.context.get().computerId;try{return await oe(n,r,e=>i(n).exists(t,e))?`exists`:`absent`}catch(e){return console.error(`Inkcap existence check failed`,e),n.app.ui.showToast({message:`Couldn't check whether ${t.split(`/`).at(-1)??t} exists. Nothing was saved.`,tone:`error`}).catch(e=>{console.error(`Inkcap check toast failed`,e)}),`unchecked`}},onPathChange:(e,t)=>{u(n=>n.map(n=>n.tabKey===e.tabKey?{...n,path:t}:n))},onStatus:(e,t,n)=>{t&&te(t=>t?.tabKey===e.tabKey?null:t),u(n=>n.map(n=>n.tabKey===e.tabKey?{...n,dirty:t}:n)),v===e.tabKey&&!t&&!n&&ae(e.tabKey)},onSaveBinding:de,onSaved:(e,t)=>{M.current?.app.ui.showToast({message:`${t?`Downloaded`:`Saved`} ${e}`,tone:`success`}).catch(e=>{console.error(`Inkcap save toast failed`,e)})},onWrite:async(e,t,n)=>{let r=e.connection;if(!r){await ce(e,e.path,t);return}await oe(r,e.computerId,async a=>{await i(r).replace(e.path,t,n,a),await ie(r,e.computerId,e.path,`edited`)})},onOverwrite:async(e,t)=>{if(!e.connection){await ce(e,e.path,t);return}await se(e.connection,e.computerId,e.path,t)},onReadCurrent:async e=>{let t=e.connection;if(!t||e.target.closed)throw Error(`File is no longer open on ${t?.source?.label??`a Computer`}`);return oe(t,e.computerId,async n=>{let r=await i(t).read(e.path,n);if(n.aborted||e.target.closed||!Op(t)||t.source?.kind!==`repository`&&t.app.context.get().computerId!==e.computerId)throw Error(`The original ${t.source?.label??`Computer`} is no longer available`);if(r.kind!==`text`)throw Error(`The ${t.source?.label??`Computer`} file could not be read as text`);return r.contents})}}}function Pp({connection:e,context:t=Ep,onReady:n}){let r=Np({connection:e,context:t});return(0,Z.useEffect)(()=>{if(e)return e.app.window.onBeforeClose(r.requestWindowClose)},[e,r.requestWindowClose]),(0,Z.useEffect)(()=>{n?.({requestWindowClose:r.requestWindowClose})},[n,r.requestWindowClose]),(0,Q.jsx)(Sp,{model:r})}function Fp(e){if(e?.kind!==`navigate`||!e.params.some(({key:e})=>e===`repository`))return null;let t=wu(e.params);return t===null||!(`repository`in t)?`invalid`:{repository:t.repository,initialBranch:t.branch,initialPath:t.path,openRequestId:e.requestId}}function Ip(e,t){return e.kind===`computer`||t.kind===`computer`?e.kind===t.kind:e.repository===t.repository&&e.initialBranch===t.initialBranch&&e.initialPath===t.initialPath&&e.openRequestId===t.openRequestId}function Lp(e){let[t,n]=(0,Z.useState)(e),r=(0,Z.useRef)(null),i=(0,Z.useRef)(!1);return(0,Z.useEffect)(()=>{if(!Ip(e,t)){if(e.kind===t.kind){n(e);return}i.current||(i.current=!0,(r.current??(()=>Promise.resolve(!0)))().then(t=>{i.current=!1,t&&n(e)}))}},[e,t]),{mounted:t,registerHandle:(0,Z.useCallback)(e=>{r.current=e},[])}}var Rp=(0,Z.lazy)(async()=>({default:(await yp(()=>import(`./InkcapRepositoryApp-D5l2ef9a.js`),__vite__mapDeps([7,1,2,5,6]),import.meta.url)).InkcapRepositoryApp}));function zp({app:e,computerName:t,projectPath:n}){let r=Ur(e),i=Fp(r?.openRequest??null),a=e?.capabilities.has(yl)??!1,{mounted:o,registerHandle:s}=Lp(i!==null&&i!==`invalid`&&a?{kind:`repository`,...i}:{kind:`computer`}),c=(0,Z.useCallback)(e=>{s(e.requestWindowClose)},[s]);return o.kind===`repository`&&e!==null?(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(Rp,{connection:{app:e},repository:o.repository,initialBranch:o.initialBranch,initialPath:o.initialPath,openRequestId:o.openRequestId,onReady:c})}):(0,Q.jsxs)(Q.Fragment,{children:[i===`invalid`?(0,Q.jsx)(xl,{tone:`warning`,title:`This repository link cannot be opened`,description:`Open the file again from Bonsai. Computer files and local drafts are still available.`}):i!==null&&!a&&(0,Q.jsx)(xl,{tone:`info`,title:`Repositories open from Bonsai`,description:`This host can still open Computer files and local drafts.`}),(0,Q.jsx)(Pp,{connection:e?{app:e}:null,context:{computerId:r?.computerId??null,computerName:t,projectPath:n},onReady:c})]})}var Bp=document.getElementById(`inkcap-root`);if(!Bp)throw Error(`Inkcap root is missing`);var Vp=new URLSearchParams(window.location.search),Hp=xe(V({project:oe(_t),computerName:oe(_t)}))({project:Vp.get(`project`),computerName:Vp.get(`computerName`)});hl(Bp,{name:`Inkcap`,queryClient:_r()},({app:e})=>(0,Z.createElement)(zp,{app:e,computerName:Hp.computerName,projectPath:Yu(Hp.project)}));export{xu as C,ni as D,yl as E,ri as O,_u as S,xl as T,hu as _,ip as a,pu as b,ap as c,id as d,Vu as f,vu as g,Su as h,Yf as i,Zr as k,Zf as l,yu as m,Sp as n,tp as o,Wu as p,yp as r,rp as s,Np as t,md as u,gu as v,ou as w,mu as x,bu as y};