import{cd as b,g as h,W as g,aO as w,v as E,ay as I,ce as _,cf as S,cg as A}from"./Dk4AzF7j.js";const B={settings:"s",advisor:"i",metricview:"v",help:"h",commandcenter:"meta_k",showAllEntries:"ctrl_n",piniaDebug:"meta_d"},i={meta:"",ctrl:"",alt:"",win:"⊞",command:"⌘",shift:"⇧",control:"⌃",option:"⌥",enter:"↵",delete:"⌦",backspace:"⌫",escape:"⎋",tab:"⇥",capslock:"⇪",arrowup:"↑",arrowright:"→",arrowdown:"↓",arrowleft:"←",pageup:"⇞",pagedown:"⇟",home:"↖",end:"↘"},D=()=>{const r=h(()=>navigator&&navigator.userAgent&&navigator.userAgent.match(/Macintosh;/)),u=g({meta:" ",alt:" ",ctrl:" "});w(()=>{u.meta=r.value?i.command:"Ctrl",u.ctrl=r.value?i.control:"Ctrl",u.alt=r.value?i.option:"Alt"});function s(l){if(l)return["meta","alt","ctrl"].includes(l)?u[l]:i[l]||l.toUpperCase()}return{macOS:r,getKbdKey:s}},k=b(D),L=/^[^-]+.*-.*[^-]+$/,$=/^[^_]+.*_.*[^_]+$/,j=["arrowleft","arrowright","arrowup","arrowright","tab","escape","enter","backspace"];function C(r,u={}){const s=E([]),l=()=>{s.value.splice(0,s.value.length)},y=I(l,u.chainDelay??800),{macOS:K}=k(),d=_(),v=e=>{if(!e.key)return;const a=/^[a-z]{1}$/i.test(e.key),t=j.includes(e.key.toLowerCase());let o;if(s.value.push(e.key),s.value.length>=2){o=s.value.slice(-2).join("-");for(const n of m.value.filter(c=>c.chained))if(n.key===o){n.enabled&&(e.preventDefault(),n.handler(e)),l();return}}for(const n of m.value.filter(c=>!c.chained))if(e.key.toLowerCase()===n.key&&e.metaKey===n.metaKey&&e.ctrlKey===n.ctrlKey&&!((a||t)&&e.shiftKey!==n.shiftKey)){n.enabled&&(e.preventDefault(),n.handler(e)),l();return}y()},p=h(()=>{const e=d.value?.tagName,a=d.value?.contentEditable;return e==="INPUT"||e==="TEXTAREA"||a==="true"||a==="plaintext-only"?d.value?.name||!0:!1}),m=h(()=>Object.entries(S(r)).map(([e,a])=>{if(!a)return null;let t;e.includes("-")&&e!=="-"&&!e.includes("_")&&!e.match(L)?.length&&console.trace(`[Shortcut] Invalid key: "${e}"`),e.includes("_")&&e!=="_"&&!e.match($)?.length&&console.trace(`[Shortcut] Invalid key: "${e}"`);const o=e.includes("-")&&e!=="-"&&!e.includes("_");if(o)t={key:e.toLowerCase(),metaKey:!1,ctrlKey:!1,shiftKey:!1,altKey:!1};else{const c=e.toLowerCase().split("_").map(f=>f);t={key:c.filter(f=>!["meta","command","ctrl","shift","alt","option"].includes(f)).join("_"),metaKey:c.includes("meta")||c.includes("command"),ctrlKey:c.includes("ctrl"),shiftKey:c.includes("shift"),altKey:c.includes("alt")||c.includes("option")}}if(t.chained=o,!K.value&&t.metaKey&&!t.ctrlKey&&(t.metaKey=!1,t.ctrlKey=!0),typeof a=="function"?t.handler=a:typeof a=="object"&&(t={...t,handler:a.handler}),!t.handler)return console.trace("[Shortcut] Invalid value"),null;let n=!0;return a.usingInput?typeof a.usingInput=="string"&&(n=p.value===a.usingInput):n=!p.value,t.enabled=n,t}).filter(Boolean));return A("keydown",v)}export{C as d,B as s,k as u};
