// @bun
var{defineProperty:$,getOwnPropertyNames:M,getOwnPropertyDescriptor:R}=Object,B=Object.prototype.hasOwnProperty;function I(x){return this[x]}var q=(x)=>{var j=(F??=new WeakMap).get(x),O;if(j)return j;if(j=$({},"__esModule",{value:!0}),x&&typeof x==="object"||typeof x==="function"){for(var E of M(x))if(!B.call(j,E))$(j,E,{get:I.bind(x,E),enumerable:!(O=R(x,E))||O.enumerable})}return F.set(x,j),j},F;var U=(x)=>x;function V(x,j){this[x]=U.bind(null,j)}var m=(x,j)=>{for(var O in j)$(x,O,{get:j[O],enumerable:!0,configurable:!0,set:V.bind(j,O)})};var w=(x,j)=>()=>(x&&(j=x(x=0)),j);var P=import.meta.require;function D(x){let j=x.toLowerCase().split("+").map((E)=>E.trim());return{key:j[j.length-1],ctrl:j.includes("ctrl")||j.includes("control"),alt:j.includes("alt")||j.includes("option"),shift:j.includes("shift"),meta:j.includes("meta")||j.includes("cmd")||j.includes("command")||j.includes("win")}}function H(x,j){let O=x.key.toLowerCase(),E=x.code.toLowerCase();return(O===j.key||E===j.key||E===`key${j.key}`||E===`digit${j.key}`||j.key==="space"&&x.code==="Space"||j.key==="enter"&&x.key==="Enter"||j.key==="escape"&&x.key==="Escape"||j.key==="esc"&&x.key==="Escape"||j.key==="tab"&&x.key==="Tab"||j.key==="backspace"&&x.key==="Backspace"||j.key==="delete"&&x.key==="Delete"||j.key==="up"&&x.key==="ArrowUp"||j.key==="down"&&x.key==="ArrowDown"||j.key==="left"&&x.key==="ArrowLeft"||j.key==="right"&&x.key==="ArrowRight")&&x.ctrlKey===j.ctrl&&x.altKey===j.alt&&x.shiftKey===j.shift&&x.metaKey===j.meta}function N(){let x=document.activeElement;if(!x)return!1;let j=x.tagName.toLowerCase();return j==="input"||j==="textarea"||j==="select"||x.isContentEditable}function C(x={}){let{target:j=typeof window<"u"?window:null,capture:O=!1,passive:E=!0}=x,A={pressed:new Set,lastKey:null,lastEvent:null,ctrl:!1,alt:!1,shift:!1,meta:!1,timestamp:0},G=[],Q=null,S=()=>{G.forEach((z)=>z(A))},W=(z)=>{let J=new Set(A.pressed);J.add(z.key.toLowerCase()),J.add(z.code.toLowerCase()),A={pressed:J,lastKey:z.key,lastEvent:z,ctrl:z.ctrlKey,alt:z.altKey,shift:z.shiftKey,meta:z.metaKey,timestamp:Date.now()},S()},X=(z)=>{let J=new Set(A.pressed);J.delete(z.key.toLowerCase()),J.delete(z.code.toLowerCase()),A={pressed:J,lastKey:z.key,lastEvent:z,ctrl:z.ctrlKey,alt:z.altKey,shift:z.shiftKey,meta:z.metaKey,timestamp:Date.now()},S()},Y=()=>{A={...A,pressed:new Set,ctrl:!1,alt:!1,shift:!1,meta:!1},S()},Z=()=>{if(!j)return;let z=j,J={capture:O,passive:E};if(z.addEventListener("keydown",W,J),z.addEventListener("keyup",X,J),typeof window<"u")window.addEventListener("blur",Y);Q=()=>{if(z.removeEventListener("keydown",W,J),z.removeEventListener("keyup",X,J),typeof window<"u")window.removeEventListener("blur",Y)}};return{get:()=>A,subscribe:(z)=>{if(G.length===0)Z();return G.push(z),z(A),()=>{if(G=G.filter((J)=>J!==z),G.length===0&&Q)Q(),Q=null}},isPressed:(z)=>{let J=z.toLowerCase();return A.pressed.has(J)},stop:()=>{if(Q)Q(),Q=null;G=[]}}}function g(x,j,O={}){let{target:E=typeof window<"u"?window:null,preventDefault:A=!0,stopPropagation:G=!1,ignoreRepeat:Q=!0,keyup:S=!1,ignoreInputs:W=!0}=O;if(!E)return()=>{};let Y=(Array.isArray(x)?x:[x]).map(D),Z=(_)=>{if(Q&&_.repeat)return;if(W&&N())return;if(!Y.some((L)=>H(_,L)))return;if(A)_.preventDefault();if(G)_.stopPropagation();j(_)},z=S?"keyup":"keydown",J=E;return J.addEventListener(z,Z),()=>{J.removeEventListener(z,Z)}}function b(x,j={}){let O=C(j),E=x.toLowerCase(),A=[],G=!1,Q=null;return{get:()=>O.isPressed(E),subscribe:(S)=>{if(A.length===0)Q=O.subscribe((W)=>{let X=W.pressed.has(E);if(X!==G)G=X,A.forEach((Y)=>Y(X))});return A.push(S),S(O.isPressed(E)),()=>{if(A=A.filter((W)=>W!==S),A.length===0&&Q)Q(),Q=null}}}}function c(x,j,O={}){let{timeout:E=1000,target:A=typeof window<"u"?window:null}=O;if(!A)return()=>{};let G=[],Q=0,S=(X)=>{let Y=Date.now();if(Y-Q>E)G=[];if(Q=Y,G.push(X.key.toLowerCase()),G.length>x.length)G=G.slice(-x.length);if(G.length===x.length){if(G.every((z,J)=>z===x[J].toLowerCase()))j(),G=[]}},W=A;return W.addEventListener("keydown",S),()=>{W.removeEventListener("keydown",S)}}var d={save:"ctrl+s",undo:"ctrl+z",redo:"ctrl+shift+z",copy:"ctrl+c",paste:"ctrl+v",cut:"ctrl+x",selectAll:"ctrl+a",find:"ctrl+f",replace:"ctrl+h",newTab:"ctrl+t",closeTab:"ctrl+w",refresh:"ctrl+r",escape:"escape",enter:"enter",saveMac:"meta+s",undoMac:"meta+z",redoMac:"meta+shift+z",copyMac:"meta+c",pasteMac:"meta+v",cutMac:"meta+x"};export{C as useKeyboard,c as useKeySequence,b as useKeyPressed,g as useHotkey,d as shortcuts};
