var O=Object.defineProperty;var P=t=>{throw TypeError(t)};var R=(t,r,e)=>r in t?O(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e;var C=(t,r,e)=>R(t,typeof r!="symbol"?r+"":r,e),M=(t,r,e)=>r.has(t)||P("Cannot "+e);var s=(t,r,e)=>(M(t,r,"read from private field"),e?e.call(t):r.get(t)),d=(t,r,e)=>r.has(t)?P("Cannot add the same private member more than once"):r instanceof WeakSet?r.add(t):r.set(t,e),S=(t,r,e,o)=>(M(t,r,"write to private field"),o?o.call(t,e):r.set(t,e),e),F=(t,r,e)=>(M(t,r,"access private method"),e);import{Y as q,u as U,p as B,d as L}from"./Dpn8_Hnn.mjs";import"./E-vkuI0X.mjs";import{i as _}from"./DueIe5zz.mjs";import{c as j,o as z}from"./Bg0ZbUei.mjs";import{p as D}from"./CUWjGq9Z.mjs";import{o as K,p as V}from"./C02ceTqP.mjs";import{U as N,V as Y}from"./CyJ0Hgdp.mjs";import{r as $}from"./mb_JAnfe.mjs";var a,u,h,l,x;const p=class p{constructor(r){d(this,l);d(this,a,new WeakMap);d(this,u);d(this,h);S(this,h,r)}observe(r,e){var o=s(this,a).get(r)||new Set;return o.add(e),s(this,a).set(r,o),F(this,l,x).call(this).observe(r,s(this,h)),()=>{var n=s(this,a).get(r);n.delete(e),n.size===0&&(s(this,a).delete(r),s(this,u).unobserve(r))}}};a=new WeakMap,u=new WeakMap,h=new WeakMap,l=new WeakSet,x=function(){var r;return(r=s(this,u))!=null?r:S(this,u,new ResizeObserver(e=>{for(var o of e){p.entries.set(o.target,o);for(var n of s(this,a).get(o.target)||[])n(o)}}))},C(p,"entries",new WeakMap);let b=p;var G=new b({box:"border-box"});function Mt(t,r,e){var o=G.observe(t,()=>e(t[r]));q(()=>(U(()=>e(t[r])),o))}function St(t){return function(...r){var e=r[0];return e.stopPropagation(),t==null?void 0:t.apply(this,r)}}function yt(t){return function(...r){var e=r[0];return e.preventDefault(),t==null?void 0:t.apply(this,r)}}function f(){const t=window.navigator.platform;return t.startsWith("Mac")||t.startsWith("iP")}function bt(){return!/iphone|ipad|ipod|android/i.test(window.navigator.userAgent)}function At(){const t=window.navigator.userAgent;if(t.includes("Safari")&&!t.includes("Chrome"))return null;const r=t.match(/Chrome\/(\d+)/);return r?parseInt(r[1],10):null}const A=["Control","Alt","Shift","Meta"],v=f()?["Meta","Alt","Shift","Control"]:["Control","Alt","Shift","OS"];function H(t){return v[A.indexOf(t)]}function J(t){let r=!1;for(const e of A)r||(r=t.code.startsWith(e));return r}const Q=(t,r=[])=>e=>A.reduce((o,n,i)=>o&&(r.includes(n)||e.getModifierState(v[i])===t.includes(n)),!0),m=t=>r=>{const e=H(t),o=r.getModifierState(e);return r.type==="keyup"?o&&r.key!==e:o},vt=m("Control"),Pt=m("Shift"),Ct=m("Alt"),g=m("Meta");function X(t){const r=f()?["^","⌥","⇧","⌘"]:[`${N()}+`,"Alt+",`${Y()}+`,"Win+"];let e="";for(const o of t)e+=r[v.indexOf(o)];return e}function Z(t){switch(t){case"Backspace":return"⌫";case"Delete":return"⌦";case"Escape":return"⎋";default:return t}}function Ft(t){return t.key==="ArrowLeft"?!0:f()&&g(t)&&t.code==="KeyB"}function Dt(t){return t.key==="ArrowRight"?!0:f()&&g(t)&&t.code==="KeyF"}function Kt(t){return t.key==="ArrowUp"?!0:f()&&g(t)&&t.code==="KeyP"}function xt(t){return t.key==="ArrowDown"?!0:f()&&g(t)&&t.code==="KeyN"}function Et(t){return r=>{switch(r.code){case"Enter":case"Space":t();break}}}const tt={Backspace:8,Delete:46,Tab:9,Enter:13,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123,"=":187,"-":189,"[":219,"]":221,"\\":220,";":186,"'":222,",":188,".":190,"/":191,"`":192};function E(t){return!t.endsWith("?")}function T(t){return t.split(", ").map(r=>r.split("+"))}function rt(t){return X(t.slice(0,-1).filter(E))+Z(t[t.length-1])}function et(t){return T(t).map(rt).join(", ")}function ot(t,r){return t.which===r}function nt(t,r){const e=[],o=[];return r.forEach(n=>{(t(n)?e:o).push(n)}),[e,o]}function it(t){return t.substring(0,t.length-1)}function st(t){const[r,e]=nt(E,t),o=e.map(it);return[r,o]}const at=(t,r,e)=>o=>ot(o,t)&&Q(r,e)(o);function ct(t){return tt[t]||t.toUpperCase().charCodeAt(0)}function ut(t){const r=ct(t[t.length-1]),[e,o]=st(t.slice(0,-1));return at(r,e,o)}function W(t,r,e,...o){if(o.length===0)return e(r);const[n,...i]=o,k=K(document,"keydown",w,{once:!0});function w(c){n(c)?W(t,c,e,...i):J(c)||k()}}const y={target:document,event:"keydown"};function I(t,r,e=y){const{target:o=y.target,event:n=y.event}=e,[i,...k]=T(r).map(ut);function w(c){i(c)&&W(o,c,t,...k)}return K(o,n,w)}$("anki/shortcuts",{registerShortcut:I,getPlatformString:et});function Tt(t,r){B(r,!1);let e=D(r,"keyCombination",8),o=D(r,"event",8,void 0);const n=j();z(()=>I(i=>{V(i),n("action",{originalEvent:i})},e(),{event:o()})),_(),L()}export{Tt as S,Kt as a,Mt as b,Ct as c,Ft as d,Dt as e,vt as f,et as g,f as h,xt as i,bt as j,St as k,At as l,Et as o,yt as p,I as r,Pt as s};
