var h=Object.defineProperty;var a=(l,e,i)=>e in l?h(l,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):l[e]=i;var c=(l,e,i)=>a(l,typeof e!="symbol"?e+"":e,i);class u{constructor(){c(this,"listeners",new Object);document.addEventListener("keydown",e=>this.processEvent(e))}processEvent(e){for(let i in this.listeners){const s=this.listeners[i].getConfig();s.hidden.length>0&&s.hidden.filter(n=>!(n instanceof HTMLElement)&&document.querySelector(n)===null).length!==s.hidden.length||s.visible.length>0&&!(s.visible.filter(n=>n instanceof HTMLElement||document.querySelector(n)!==null).length===s.visible.length)||s.callbacks.forEach(t=>{typeof t.action=="string"?this.processSingleAction({action:t.action.trim(),callback:t.callback}):typeof t.action=="object"&&t.action!==null&&t.action.length>0&&t.action.forEach(n=>{this.processSingleAction({action:n.toString().trim(),callback:t.callback})})})}}processSingleAction({action:e,callback:i}){const s=e.split("+"),t={ctrlKey:!1,altKey:!1,shiftKey:!1};s.forEach(r=>{switch(r){case"ctrl":t.ctrlKey=!0;break;case"alt":t.altKey=!0;break;case"shift":t.shiftKey=!0;break}});const n=s.filter(r=>!["ctrl","alt","shift"].includes(r));this.executeCallback({event,combinableKeys:t,callback:i,key:n[0]})}executeCallback({event:e,callback:i,combinableKeys:s,key:t}){if(e.key!==void 0&&e.key.toLowerCase()===t.toLowerCase()){let n=!0;for(let r in s)e[r]!==s[r]&&(n=!1);n&&i(e,t)}}create(e){return this.listeners[e]=new o}destroy(e){delete this.listeners[e]}}class o{constructor(){c(this,"visible",[]);c(this,"hidden",[]);c(this,"callbacks",[])}whenVisible(e){return typeof e=="object"?this.visible.push(...e):this.visible.push(e),this}clearVisible(){return this.visible=[],this}whenNotVisible(e){return e.length>0?this.hidden.push(...e):this.hidden.push(e),this}clearHidden(){return this.hidden=[],this}whenPressed(e,i){return this.callbacks.push({action:e,callback:i}),this}clearCallbacks(){return this.callbacks=[],this}getConfig(){return{callbacks:this.callbacks,hidden:this.hidden,visible:this.visible}}}export{u as N};
