// @bun
import{NG as S}from"./chunk-xyhgvt88.js";var x={};S(x,{formatKeySequence:()=>L,formatCommandBindings:()=>y,createBindingLookup:()=>B,commandBindings:()=>v});var A=Object.prototype.hasOwnProperty,w=Object.freeze([]);function K(F){return!!F&&typeof F==="object"&&!Array.isArray(F)}function Y(F){return typeof F==="string"||K(F)}function _(F){if(typeof F==="string")return F;return{...F}}function I(F){if(F.length===0)throw Error("Invalid binding command: command cannot be empty");return F}function M(F,H){let Q=I(F);if(!H||!A.call(H,Q))return Q;let X=H[Q];if(typeof X!=="string")throw Error(`Invalid binding command map entry for "${Q}": expected a command string`);if(X.length===0)throw Error(`Invalid binding command map entry for "${Q}": command cannot be empty`);return X}function j(F,H){let Q=H===void 0?`"${F}"`:`"${F}" at index ${H}`;return Error(`Invalid binding value for ${Q}: expected false, a key, a binding object, or an array of keys/binding objects`)}function q(F,H,Q){if(!Y(H))throw j(F,Q);if(typeof H==="string"||!("key"in H))return{key:_(H),cmd:F};let X=H.key;if(!Y(X))throw j(F,Q);return{...H,key:_(X),cmd:F}}function h(F,H,Q){if(H===!1||H==="none")return;if(Array.isArray(H)){if(H.length===0)return;let W=H,J=Array(W.length);for(let $=0;$<W.length;$+=1){let E=q(F,W[$],$);J[$]=Q?O(F,E,Q):E}return J}let X=q(F,H);return[Q?O(F,X,Q):X]}function O(F,H,Q){let X=Q?.({command:F,binding:H});if(!X)return H;return{...X,...H}}function z(F){let H=0;for(let W of F.values())H+=W.length;let Q=Array(H),X=0;for(let W of F.values())for(let J=0;J<W.length;J+=1)Q[X]=W[J],X+=1;return Q}function V(F,H,Q){let X=new Map;for(let W in F){if(!A.call(F,W))continue;let J=M(W,H),$=h(J,F[W],Q);if(!$)X.delete(J);else X.set(J,$)}return{bindings:z(X),byCommand:X}}function D(F,H){let Q=new Map,X=[];for(let W of H){let J=F.get(W);if(!J)continue;Q.set(W,J);for(let $=0;$<J.length;$+=1)X.push(J[$])}return{bindings:X,byCommand:Q}}function B(F,H){let Q=F,X=V(Q,H?.commandMap,H?.bindingDefaults),W=new Map;return{get bindings(){return X.bindings},get(J){return X.byCommand.get(J)??w},has(J){return X.byCommand.has(J)},gather(J,$){let E=W.get(J);if(E)return E.bindings;let Z=D(X.byCommand,$);return W.set(J,Z),Z.bindings},pick(J,$){let E=W.get(J);if(!E)return[];let Z=[];for(let R of $){let P=E.byCommand.get(R);if(!P)continue;for(let G=0;G<P.length;G+=1)Z.push(P[G])}return Z},omit(J,$){let E=W.get(J);if(!E)return[];if($.length===0)return E.bindings;if($.length===1){let P=$[0],G=[];for(let T=0;T<E.bindings.length;T+=1){let U=E.bindings[T];if(typeof U.cmd==="string"&&U.cmd===P)continue;G.push(U)}return G}let Z=new Set($),R=[];for(let P=0;P<E.bindings.length;P+=1){let G=E.bindings[P];if(typeof G.cmd==="string"&&Z.has(G.cmd))continue;R.push(G)}return R},invalidate(J){if(J===void 0){W.clear();return}W.delete(J)},update(J){if(J)Q=J;X=V(Q,H?.commandMap,H?.bindingDefaults),W.clear()}}}function k(F){return typeof F==="string"||!!F&&typeof F==="object"&&!Array.isArray(F)}function v(F,H){let Q=[],X=new Map;for(let[W,J]of Object.entries(F)){if(!k(J)){let R=Error(`Invalid command binding for "${W}": command bindings must map command strings to key strings or keystroke objects`);H?.onError?.({code:"invalid-command-binding",command:W,value:J,reason:R});continue}let $=W.trim(),E={key:typeof J==="string"?J:{...J},cmd:$},Z=X.get($);if(Z!==void 0){let R=Q[Z];H?.onWarning?.({code:"command-binding-override",command:$,previousKey:R.key,nextKey:E.key}),Q[Z]=E;continue}X.set($,Q.length),Q.push(E)}return Q}function N(F,H){if(F.tokenName){let Z=H.tokenDisplay;if(!Z)return F.display;if(typeof Z==="function")return Z(F.tokenName,F)??F.display;return Z[F.tokenName]??F.display}if(F.patternName){let Z=H.patternDisplay;if(!Z)return F.display;if(typeof Z==="function")return Z(F.patternName,F)??F.display;return Z[F.patternName]??F.display}if(!H.keyNameAliases&&!H.modifierAliases)return F.display;let Q=F.stroke,X=H.modifierAliases,W="",J=0;if(Q.ctrl)W=X?.ctrl??"ctrl",J=1;if(Q.shift){let Z=X?.shift??"shift";W=J===0?Z:`${W}+${Z}`,J+=1}if(Q.meta){let Z=X?.meta??"meta";W=J===0?Z:`${W}+${Z}`,J+=1}if(Q.super){let Z=X?.super??"super";W=J===0?Z:`${W}+${Z}`,J+=1}if(Q.hyper){let Z=X?.hyper??"hyper";W=J===0?Z:`${W}+${Z}`,J+=1}let $=Q.name==="return"?"enter":Q.name,E=H.keyNameAliases?.[$]??$;return J===0?E:`${W}+${E}`}function L(F,H={}){if(!F||F.length===0)return"";let Q=H.separator??" ",X=N(F[0],H);for(let W=1;W<F.length;W+=1)X+=Q+N(F[W],H);return X}function y(F,H={}){if(!F?.length)return;let Q=H.bindingSeparator??", ",W=H.dedupe!==!1?new Set:void 0,J="",$=0;for(let E of F){let Z=L(E.sequence,H);if(!Z)continue;if(W){if(W.has(Z))continue;W.add(Z)}J=$===0?Z:`${J}${Q}${Z}`,$+=1}return J}
export{B as Ej,L as Fj,y as Gj,x as Hj};
