define(["exports","./layoutmanager.js","./emby-apiclient/events.js"],function(_exports,_layoutmanager,_events){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;var defaultScope=document.body,scopes=[],_currentScope=defaultScope;function isAutoFocusEnabled(elem){if(_layoutmanager.default.tv)return!0;if(elem)switch(elem.tagName){case"INPUT":switch(elem.type){case"checkbox":case"radio":case"file":case"hidden":case"range":return!1;default:return!0}case"TEXTAREA":return!0}return!1}function getElementToAutoFocus(view,options){var element;return options&&!1===options.findAutoFocusElement||!(element=view.querySelector(".autofocus"))||!isCurrentlyFocusableInternal(element,!0)?getFocusableElements(view,1,".noautofocus",options)[0]||getFocusableElements(view,1,null,options)[0]:element}function autoFocus(view,options){view=getElementToAutoFocus(view,options);return view&&focus(view,options)}function focus(element,options){for(;element.classList.contains("focusable");){var autoFocusElement=getElementToAutoFocus(element,options);if(!autoFocusElement)break;element=autoFocusElement}return null!=options&&options.skipIfNotEnabled&&!isAutoFocusEnabled(element)?null:(focusInternal(element,options),element)}var lastFocusInfo={};function focusInternal(element,options){try{lastFocusInfo={element:element,options:options},element.focus({preventScroll:!0})}catch(err){console.log("Error in focusManager.focusInternal: "+err)}}var focusableTagNames=["INPUT","TEXTAREA","SELECT","BUTTON","A","DIV[tabindex]"],focusableQuerySelectors=focusableTagNames.map(function(t){return"A"===t&&(t+="[href]"),t+':not([tabindex="-1"]):not(:disabled)'}),focusableQuery=(focusableQuerySelectors.push(".focusable"),focusableQuerySelectors.join(","));var focusableTagNameQuery=focusableTagNames.join(","),focusableParentQuery=focusableTagNames.join(",")+",.focusable";function focusableParent(elem,includeGroups){return!1===includeGroups?elem.closest(focusableTagNameQuery):elem.closest(focusableParentQuery)}function isCurrentlyFocusableInternal(elem,checkOffsetParent){return!checkOffsetParent||null!==elem.offsetParent}function getFocusableElements(parent,limit,excludeSelector,options){for(var elems,fn=(parent=parent||_currentScope).getFocusableElements,focusableElements=(elems=(elems=fn?fn(parent,document.activeElement,null,options):elems)||parent.querySelectorAll(function(excludeSelector){if(!excludeSelector)return focusableQuery;for(var newQuerySelectors=[focusableQuerySelectors.length],i=0,length=focusableQuerySelectors.length;i=activeElementRect.bottom)continue;break;case 3:if(elementRect.bottom<=activeElementRect.bottom)continue;if(elementRectTop<=activeElementTop)continue}var x2=elementRectLeft+elementRectWidth-1,y2=elementRectTop+elementRectHeight-1,distX=void 0,distY=void 0;switch(direction){case 0:var intersectY=intersection(point1y,point2y,elementRectTop,y2),distX=Math.abs(point1x-Math.min(point1x,x2)),distY=intersectY||1+Math.min(Math.abs(point1y-y2),Math.abs(point2y-elementRectTop));break;case 1:intersectY=intersection(point1y,point2y,elementRectTop,y2);distX=Math.abs(point2x-Math.max(point2x,elementRectLeft)),distY=intersectY||1+Math.min(Math.abs(point1y-y2),Math.abs(point2y-elementRectTop));break;case 2:var intersectX=intersection(point1x,point2x,elementRectLeft,x2);distY=Math.abs(point1y-Math.min(point1y,y2)),distX=intersectX||1+Math.min(Math.abs(point1x-x2),Math.abs(point2x-elementRectLeft));break;case 3:intersectX=intersection(point1x,point2x,elementRectLeft,x2);distY=Math.abs(point2y-Math.max(point2y,elementRectTop)),distX=intersectX||1+Math.min(Math.abs(point1x-x2),Math.abs(point2x-elementRectLeft))}elementRectWidth=Math.sqrt(distX*distX+distY*distY);elementRectWidth