keytrap
code:mod.js
function p(t){return t instanceof CompositionEvent?...t.data.map(o=>${0}-${o}):${+t.shiftKey*8+ +t.ctrlKey*4+ +t.altKey*2+ +t.altKey}-${t.key}}const v={option:"alt",command:"meta",return:"enter",escape:"esc",plus:"+",mod:/Mac|iPod|iPhone|iPad/.test(navigator.userAgent)?"meta":"ctrl"},k=t=>t.split(/ +/).map(o=>{const e=o.replaceAll("++","+plus").split("+");let n="",r=0;for(n of e)n=vn??n,r|=n==="shift"||n==="ctrl"?4:n==="alt"?2:n==="meta"?1:0;return${r}-${n}}),m=(t,o)=>{conste,...n=k(o);if(!e)return;let r=t.get(e)??new Map,void 0;t.set(e,r);for(const a of n){const u=r0.get(a)??new Map,void 0;r0.set(a,u),r=u}return r},y=(t,o)=>{const e=o?.0.get?.(t);if(!e)return0,e;constn,r=e;return n.size===0?r??0,e:-1,e},d=new Map,h=t=>{const o=new Map;let e=o,void 0,n;const r=s=>{if(!(s instanceof KeyboardEvent)||"Shift","Control","Alt","Meta".includes(s.key))return;clearTimeout(n);const c=p(s),i,f=y(c,e);if(e=f??o,void 0,i!==0)if(s.preventDefault(),s.stopPropagation(),i===-1){if(!e?.1)return;n=setTimeout(e1,1e3)}else i()},a=s=>{if(!(s instanceof CompositionEvent))return;clearTimeout(n);const c=p(s);let i=-1;for(const f of c){const l=y(f,e);i=l0,e=l1??o,void 0}if(i!==0)if(s.preventDefault(),s.stopPropagation(),i===-1){if(!e?.1)return;n=setTimeout(e1,1e3)}else i()};return t.addEventListener("keydown",r),t.addEventListener("compositionend",a),{bind:(s,c)=>{const i=m(o,s);i&&(i1=c)},unbind:s=>{const c=m(o,s);c&&(c1=void 0)},dispose:()=>{t.removeEventListener("keydown",r),t.removeEventListener("compositionend",a)}}},E=t=>{{const r=d.get(t);if(r)return r}const{dispose:o,...e}=h(t),n={...e,dispose:()=>{o(),d.delete(t)}};return d.set(t,n),n};export{E as trap};