// @bun
import{Bb as u,Kb as c,Ub as d}from"./chunk-qaknq49b.js";import{Ec as f}from"./chunk-hqvcxwes.js";import{Fj as m,Gj as l}from"./chunk-b0x7wzag.js";var w={delete:"del",enter:"return",escape:"esc",pagedown:"pgdn",pageup:"pgup"},I={meta:"alt"};function K(){if(process.platform==="darwin")return"macos";if(process.platform==="win32")return"windows";if(process.platform==="linux")return"linux";return"unknown"}function S(){return new f({name:"command",ctrl:!1,meta:!1,shift:!1,option:!1,sequence:"",number:!1,raw:"",eventType:"press",source:"raw"})}function C(e){let t=K(),r=new u({metadata:{platform:t,primaryModifier:t==="macos"?"super":t==="unknown"?"unknown":"ctrl",modifiers:{ctrl:"supported",shift:"supported",meta:"supported",super:"unknown",hyper:"unknown"}},rootTarget:{},isDestroyed:!1,getFocusedTarget(){return null},getParentTarget(s){return null},isTargetDestroyed(s){return!1},onKeyPress(s){return()=>{}},onKeyRelease(s){return()=>{}},onFocusChange(s){return()=>{}},onTargetDestroy(s,R){return()=>{}},createCommandEvent:S}),n=c(r),o=d(r,{trigger:e});return{keymap:r,dispose(){o(),n()}}}function y(e){return{tokenDisplay:{leader:e},keyNameAliases:w,modifierAliases:I}}function k(e){if(typeof e.key!=="string"||!e.key.includes(","))return[e];return e.key.split(",").map((t)=>t.trim()).filter(Boolean).map((t)=>({...e,key:t}))}function a(e,t){let r=C(t);try{return e.flatMap((n)=>k(n).map((o)=>({sequence:Array.from(r.keymap.parseKeySequence(o.key)),event:o.event??"press"})))}finally{r.dispose()}}function g(e,t){return m(a(e,t)[0]?.sequence,y(t))}function _(e,t){return l(a(e,t),y(t))}var P=200;function O(e){return{name:e.name===" "?"space":e.name,ctrl:!!e.ctrl,meta:!!e.meta,shift:!!e.shift,super:!!e.super,leader:!1}}function h(e){return{text:e.text,parts:structuredClone(e.parts),...e.mode?{mode:e.mode}:{}}}function B(e,t){return e.mode===t.mode&&e.text===t.text&&JSON.stringify(e.parts)===JSON.stringify(t.parts)}function q(e){if(e.event!=="press")return;let t=e.sequence[0],r=e.sequence[1];if(!t)return;if(!r)return t.patternName||t.tokenName?void 0:{name:t.stroke.name,ctrl:t.stroke.ctrl,meta:t.stroke.meta,shift:t.stroke.shift,super:t.stroke.super,leader:!1};if(e.sequence.length!==2||t.tokenName!=="leader"||r.patternName||r.tokenName)return;return{name:r.stroke.name,ctrl:r.stroke.ctrl,meta:r.stroke.meta,shift:r.stroke.shift,super:r.stroke.super,leader:!0}}function i(e,t){return a(e,t).flatMap((r)=>{let n=q(r);return n?[n]:[]})}function x(e,t,r){return i(e,t).flatMap((n)=>{if(n.leader)return[];return[{name:n.name,ctrl:n.ctrl||void 0,meta:n.meta||void 0,shift:n.shift||void 0,super:n.super||void 0,action:r}]})}function H(e){return[...x(e.inputSubmit,e.leader,"submit"),...x(e.inputNewline,e.leader,"newline")]}function W(e){return{leaders:i([{key:e.leader}],e.leader),cycles:i(e.variantCycle,e.leader),interrupts:i(e.interrupt,e.leader),previous:i(e.historyPrevious,e.leader),next:i(e.historyNext,e.leader),clear:i(e.inputClear,e.leader),bindings:H(e)}}function E(e,t){return g(e,t)}function J(e){let t=e.trim().toLowerCase();return t==="/exit"||t==="/quit"||t===":q"}function Y(e){return e.trim().toLowerCase()==="/new"}function p(e,t){return e.some((r)=>r.name===t.name&&r.ctrl===t.ctrl&&r.meta===t.meta&&r.shift===t.shift&&r.super===t.super&&r.leader===t.leader)}function j(e,t,r,n){if(!e&&p(r,t))return{arm:!0,clear:!1,cycle:!1,consume:!0};if(e)return{arm:!1,clear:!0,cycle:p(n,{...t,leader:!0}),consume:!0};if(!p(n,t))return{arm:!1,clear:!1,cycle:!1,consume:!1};return{arm:!1,clear:!1,cycle:!0,consume:!0}}function z(e){let t=(e??[]).filter((n)=>n.text.trim().length>0).map(h),r=[];for(let n of t){if(r.length>0&&B(r[r.length-1],n))continue;r.push(n)}return{items:r.slice(-P),index:null,draft:""}}function G(e,t){if(!t.text.trim())return e;let r=h(t);if(e.items[e.items.length-1]&&B(e.items[e.items.length-1],r))return{...e,index:null,draft:""};let n=[...e.items,r].slice(-P);return{...e,items:n,index:null,draft:""}}function Q(e,t,r,n){if(e.items.length===0)return{state:e,apply:!1};if(t===-1&&n!==0)return{state:e,apply:!1};if(t===1&&n!==Bun.stringWidth(r))return{state:e,apply:!1};if(e.index===null){if(t===1)return{state:e,apply:!1};let s=e.items.length-1;return{state:{...e,index:s,draft:r},text:e.items[s].text,cursor:0,apply:!0}}let o=e.index+t;if(o<0)return{state:e,apply:!1};if(o>=e.items.length)return{state:{...e,index:null},text:e.draft,cursor:Bun.stringWidth(e.draft),apply:!0};return{state:{...e,index:o},text:e.items[o].text,cursor:t===-1?0:Bun.stringWidth(e.items[o].text),apply:!0}}
export{_ as bb,O as cb,h as db,B as eb,i as fb,W as gb,E as hb,J as ib,Y as jb,p as kb,j as lb,z as mb,G as nb,Q as ob};
