!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["vue-focusable"]={})}(this,(function(t){"use strict";function e(t,e,n){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return t+""}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var o,i,r,u="parent-scroll-group",l="focus-first",c="find-focus-type",s="scroll-group",a="scroll-direction",f="scroll-record",d="scroll-right-hidden",v="scroll-bottom-hidden",m="scroll-left-hidden",h="scroll-top-hidden",g="root-scroll",p="scroll-item",b="limit-group",E="limit-item",y="up",A="down",w="left",T="right",D="enter",C="back",F={KEY_LEFT:[37,21],KEY_UP:[38,19],KEY_RIGHT:[39,22],KEY_DOWN:[40,20],KEY_ENTER:[13,23],KEY_BACK:[27,1e4],itemAttrname:"focusable",focusClassName:"focus",focusedAttrname:"focused",pressedAttrname:"pressed",easing:"",smoothTime:800,offsetDistanceX:50,offsetDistanceY:50,longPressTime:700,dblEnterTime:200,scrollDelay:0,scrollHiddenTime:200,fps:!1,distanceToCenter:!1,touchpad:!0,autoFocus:!0,endToNext:!1},M=function(t,e){for(var n=0;n
x
'),i.close(),t=i.documentElement.scrollHeight>i.body.scrollHeight),null===(n=o.parentNode)||void 0===n||n.removeChild(o)}return t}())return document.documentElement;var o=document.body;return(o=o&&!/body/i.test(o.tagName)?function(t){for(var e,n=t;n=n.nextSibling;)if(1==n.nodeType&&(e=n,window.HTMLBodyElement?e instanceof HTMLBodyElement:/body/i.test(e.tagName)))return n;return null}(o):o)&&function(t){var o=e(t),i=e(document.documentElement);return"visible"!=o.overflow&&"visible"!=i.overflow&&n(o)&&n(i)}(o)?null:o}()}(),R=null,N="",q="",L=0,Y=0,K=[],P={el:null,clientRect:void 0},G=[void 0,null],B=[y,T,A,w],k=1/0,_={},X=null,H=function(){var t=F.focusClassName,e=F.itemAttrname;return z().querySelector(".".concat(t,"[").concat(e,"]"))},j=function(){for(var t=F.itemAttrname,e=z(),n=P.el||H(),o=null==n?void 0:n.getAttribute(p),i=e.querySelectorAll('[scroll-group]:not([scroll-group="'.concat(o,'"])')),r=[],u=0;u-1){var o,i=F.focusClassName,r=F.itemAttrname,u=t.querySelector(".".concat(i,"[").concat(r,"]"));if(u){var l=F.focusedAttrname;u.classList.remove(F.focusClassName),u.removeAttribute(l)}K.splice(n,1);var c=z().querySelector(".".concat(i,"[").concat(r,"]"));R=c,P.el=c,P.clientRect=null==c||null===(o=c.getBoundingClientRect)||void 0===o?void 0:o.call(c)}},et=function(t){var e=t.key,n=t.el;e in _&&!n?delete _[e]:_[e]={lastFocus:n}},nt=function(t){var e=t.scrollLeft,n=t.scrollTop,o=t.scrollWidth,i=t.scrollHeight,r=t.clientWidth,u=t.clientHeight;e?t.setAttribute(m,""):t.removeAttribute(m),n?t.setAttribute(h,""):t.removeAttribute(h),r+e0&&void 0!==arguments[0])||arguments[0])},it=function(){F.distanceToCenter=!0===(!(arguments.length>0&&void 0!==arguments[0])||arguments[0])},rt=function(){F.offsetDistanceX=F.offsetDistanceY=arguments.length>0&&void 0!==arguments[0]?arguments[0]:50},ut=function(){F.offsetDistanceX=arguments.length>0&&void 0!==arguments[0]?arguments[0]:50},lt=function(){F.offsetDistanceY=arguments.length>0&&void 0!==arguments[0]?arguments[0]:50},ct=function(){F.endToNext=arguments.length>0&&void 0!==arguments[0]&&arguments[0]},st=function(){F.smoothTime=arguments.length>0&&void 0!==arguments[0]?arguments[0]:800},at=function(){F.scrollDelay=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0},ft=function(t){return F[t]},dt=function(){return L=0},vt=function(){xt(X),X=null},mt=function(t,e){if(e&&t){var n=P.clientRect||t.getBoundingClientRect(),o=n.top,i=n.left,r=n.bottom,u=n.right,l=e.getBoundingClientRect(),c=l.left,s=l.bottom,a=l.right,f=[];return os&&f.push(A),ia&&f.push(T),{directionArr:f}}return{}},ht=function(t){var e=(null==t?void 0:t.getAttribute(p))||"";return{scrollItemKey:e,scrollGroup:e?document.querySelector('[scroll-group="'.concat(e,'"]')):null}},gt=function(t){var e=t.focusEl,n=t.scrollEl,o=void 0===n?null:n,i=t.smooth,r=t.smoothTime,l=t.end,c=t.easing,s=t.distanceToCenter,a=t.offsetDistanceX,f=t.offsetDistanceY,d=ht(e).scrollGroup||e,v=null==d?void 0:d.getAttribute(u),m=(v?document.querySelector('[scroll-group="'.concat(v,'"]')):null)||o;if(m){U({focusEl:d,scrollEl:m,smooth:i,smoothTime:r,end:l,easing:c,distanceToCenter:s,offsetDistanceX:a,offsetDistanceY:f});var h=z();gt({focusEl:m,scrollEl:m===h?null:h,smooth:i,smoothTime:r,end:l,easing:c,distanceToCenter:s,offsetDistanceX:a,offsetDistanceY:f})}else"false"!==(null==d?void 0:d.getAttribute(g))&&U({focusEl:d,scrollEl:x,smooth:i,smoothTime:r,end:l,easing:c,distanceToCenter:s,offsetDistanceX:a,offsetDistanceY:f})},pt=function(t){for(var e=t.currFocusEl,n=t.focusableEls,o=t.direction,i=F.itemAttrname,r=P.clientRect||e.getBoundingClientRect(),u=r.top,l=r.right,f=r.bottom,d=r.left,v=[k,null],m=[k,null],h=function(){var t,r,c=n[g];if(c!==e){var a=c.getBoundingClientRect(),h=a.top,p=a.right,b=a.bottom,E=a.left,D=a.width,C=a.height,F={left:El,up:hf},M={left:t=function(){return u>=h&&u<=b||f>=h&&f<=b||u<=h&&f>=b},right:t,up:r=function(){return d>=E&&d<=p||l>=E&&l<=p||d<=E&&l>=p},down:r}[o]();if(D&&C&&F[o]){var S=Math.abs,O=Math.min,I=function(){return O(S(d-E),S(d-p),S(l-E),S(l-p))},x=function(){return O(S(u-h),S(u-b),S(f-h),S(f-b))},R=function(){switch(o){case y:return{a:S(u-b),b:I()};case T:return{a:S(l-E),b:x()};case A:return{a:S(f-h),b:I()};case w:return{a:S(d-p),b:x()}}}(),N=zt(R.a,R.b);if(M){if(N0&&void 0!==arguments[0]?arguments[0]:"";if("string"==typeof t){for(var e=t.split("."),n=S,o=0;oh&&(f=t-g%h,l(e({end:!1},u,s(r,n,o-n,i))))}else l(e({end:!1},u,s(r,n,o-n,i)));else I(d),O=!0,l(e({end:!0},u,s(i,n,o-n,i)))}else l(e({end:!0},u,o))};return m(),{cancel:function(){return I(d)}}}({from:c,to:s,easing:l,duration:i?M(G,r)?a:r:0,type:o,fps:f,update:function(t){if(n[o]=t[o],t.end){var e=bt[n];e&&(delete e[o],!Object.keys(e).length&&delete bt[n]),"function"==typeof u&&u()}}});bt[n]&&(bt[n][o]=v.cancel)},yt=function(t){var e=t.currFocusEl,n=t.direction;e===t.nextFocusEl&&N===n?L++:L=0;var o=Y;e&&Jt(e,n,{count:L});var i=Y;return Y=0,o!==i},At=function(t){var e=t.currFocusEl,n=t.nextFocusEl,o=t.direction,i=(null==e?void 0:e.getAttribute(a))||"",r=ht(e).scrollGroup;switch(i){case"x":return!M([w,T],o)||null!=r&&r.contains(n)?null:e;case"y":return!M([y,A],o)||null!=r&&r.contains(n)?null:e;default:return null}},wt=function(t){var e=t.sideLen,n=t.el,o=t.currFocusEl,i=t.direction,r=t.originTop,u=t.originLeft,c=t.originRight,a=t.originBottom,d=n.getAttribute(s),v=d?document.querySelector('[scroll-group="'.concat(d,'"]')):null;if(v&&v.hasAttribute(f)){var m,h=null===(m=_[d])||void 0===m?void 0:m.lastFocus;if(h)return[e,h];if(n.hasAttribute(l))for(var g=n.querySelectorAll("[".concat(F.itemAttrname,"]")),p=0;p=x&&x>=D[0]){var q=x===D[0];D[0]=x,q?D[1].push(S):D[1]=[S]}break;case T:if(c<=R&&R<=D[0]){var L=R===D[0];D[0]=R,L?D[1].push(S):D[1]=[S]}break;case A:if(a<=I&&I<=D[0]){var Y=I===D[0];D[0]=I,Y?D[1].push(S):D[1]=[S]}break;case w:if(u>=N&&N>=D[0]){var K=N===D[0];D[0]=N,K?D[1].push(S):D[1]=[S]}}}return[e,pt({currFocusEl:o,focusableEls:D[1],direction:i})]},Tt=null,Dt=!1,Ct=null,Ft=null,Mt=0,St=null,Ot=null,It=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t){return window.setTimeout(t,16.67)},xt=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||function(t){return window.clearTimeout(t)},Rt=function(t){var e=te(t);switch(e){case y:case T:case A:case w:Pt(t,e);break;case D:Bt(null,!0),Tt||(Tt=window.setTimeout(_t,F.longPressTime))}},Nt=function(t){switch(te(t)){case D:if(Mt++,Bt(null,!1),Xt(),Dt)jt();else{var e=F.dblEnterTime;e?!Ct&&(Ct=window.setTimeout(Qt,e)):Ht()}Dt=!1;break;case C:kt()}},qt=function(t){if(F.touchpad){var e=t.target;if(!Ft&&e.hasAttribute(F.itemAttrname)){var n=Bt(e,!0);Ft=n,Tt||(Tt=window.setTimeout(_t,F.longPressTime))}}},Lt=function(){Ft=null,Xt()},Yt=function(t){t.preventDefault();var e=F.itemAttrname,n=F.dblEnterTime;if(F.touchpad){Xt();var o=H();if(o)for(var i=[y,T,A,w],r=0;r0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return Math.sqrt(t*t+e*e)},Jt=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};It((function(){return t.dispatchEvent(Zt(e,n))}))},Zt=function(t){var e,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return window.CustomEvent?e=new window.CustomEvent(t,{bubbles:!0,cancelable:!1,detail:n}):(e=document.createEvent("CustomEvent")).initCustomEvent(t,!0,!1,n),e},te=function(t){var e=t.keyCode||t.which,n=F.KEY_RIGHT,o=F.KEY_DOWN,i=F.KEY_LEFT,r=F.KEY_ENTER,u=F.KEY_BACK,l="";return M(F.KEY_UP,e)?l=y:M(n,e)?l=T:M(o,e)?l=A:M(i,e)?l=w:M(r,e)?l=D:M(u,e)&&(l=C),l},ee=-1,ne=-1,oe=function(t,e){var n=F.itemAttrname;M([void 0,!0],e)?t.setAttribute(n,""):t.removeAttribute(n)},ie=function(t,e){var n,o,i,r=F.itemAttrname,d=F.scrollHiddenTime,v={x:"x",y:"y"},m=e||{},h=m.direction,b=void 0===h?"":h,E=m.record,y=m.focusFirst,A=void 0!==y&&y,w=m.findFocusType,T=void 0===w?1:w,D=m.needScrollHidden,C=void 0!==D&&D,M=m.rootScroll,S=void 0===M||M;void 0===E||E?t.setAttribute(f,""):t.removeAttribute(f),A?t.setAttribute(l,""):t.removeAttribute(l),0===T?t.setAttribute(c,"0"):t.removeAttribute(c),S?t.removeAttribute(g):t.setAttribute(g,"false"),t.style.overflow="auto",C&&(nt(t),t.onscroll=(n=function(){return nt(t)},o=d,function(t){window.clearTimeout(i),i=window.setTimeout((function(){n.apply(void 0,t)}),o)})),t.hasAttribute(s)||(ee++,t.setAttribute(s,ee+""));for(var O=t.getAttribute(s)||"",I=t.querySelectorAll("[scroll-group]"),x=0;x1&&void 0!==arguments[1])||arguments[1],n=F.itemAttrname;t.hasAttribute(b)||(ne++,t.setAttribute("".concat(b),ne+""));for(var o=t.getAttribute(b)||"",i=t.querySelectorAll("[".concat(n,"]")),r=0;r0&&void 0!==arguments[0]?arguments[0]:{};for(var n in t)n in F&&(F[n]=t[n]);return e(e({},o,(function(t,e){oe(t,e.value)})),i,(function(t,e){oe(t,e.value)}))},ce=function(){return e(e(e({},o,(function(t,e){ie(t,e.value)})),i,(function(t,e){var n;ie(t,e.value);var o=t.getAttribute(s),i=null===(n=_[o])||void 0===n?void 0:n.lastFocus;i&&!t.contains(i)&&re(t)})),r,(function(t){re(t)}))},se=function(){return e(e(e({},o,(function(t,e){ue(t,e.value)})),i,(function(t,e){ue(t,e.value)})),r,(function(t){tt(t,!1)}))},ae=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{install:function(e){if(!ae.installed){ae.installed=!0,function(t){Vt=t.version&&+t.version.split(".")[0]||2}(e);var n=Vt>=3?{mountedKey:"mounted",updatedKey:"updated",unmountedKey:"unmounted"}:{mountedKey:"bind",updatedKey:"componentUpdated",unmountedKey:"unbind"};o=n.mountedKey,i=n.updatedKey,r=n.unmountedKey;for(var u=[{key:"focusable",value:le},{key:"scrollGroup",value:ce},{key:"limitGroup",value:se}],l=0;l