/**
@license
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at
http://polymer.github.io/LICENSE.txt The complete set of authors may be found at
http://polymer.github.io/AUTHORS.txt The complete set of contributors may be
found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as
part of the polymer project is also subject to an additional IP rights grant
found at http://polymer.github.io/PATENTS.txt
*/
import"../polymer/polymer-legacy.js";import{dom as e}from"../polymer/lib/legacy/polymer.dom.js";var t=Element.prototype,r=t.matches||t.matchesSelector||t.mozMatchesSelector||t.msMatchesSelector||t.oMatchesSelector||t.webkitMatchesSelector;export const IronFocusablesHelper=new class IronFocusablesHelperClass{getTabbableNodes(e){var t=[];return this._collectTabbableNodes(e,t)?this._sortByTabIndex(t):t}isFocusable(e){return r.call(e,"input, select, textarea, button, object")?r.call(e,":not([disabled])"):r.call(e,"a[href], area[href], iframe, [tabindex], [contentEditable]")}isTabbable(e){return this.isFocusable(e)&&r.call(e,':not([tabindex="-1"])')&&this._isVisible(e)}_normalizedTabIndex(e){if(this.isFocusable(e)){var t=e.getAttribute("tabindex")||0;return Number(t)}return-1}_collectTabbableNodes(t,r){if(t.nodeType!==Node.ELEMENT_NODE)return!1;var a=t;if(!this._isVisible(a))return!1;var s,l=this._normalizedTabIndex(a),i=l>0;l>=0&&r.push(a),s="content"===a.localName||"slot"===a.localName?e(a).getDistributedNodes():e(a.root||a).children;for(var o=0;o<s.length;o++)i=this._collectTabbableNodes(s[o],r)||i;return i}_isVisible(e){var t=e.style;return"hidden"!==t.visibility&&"none"!==t.display&&("hidden"!==(t=window.getComputedStyle(e)).visibility&&"none"!==t.display)}_sortByTabIndex(e){var t=e.length;if(t<2)return e;var r=Math.ceil(t/2),a=this._sortByTabIndex(e.slice(0,r)),s=this._sortByTabIndex(e.slice(r));return this._mergeSortByTabIndex(a,s)}_mergeSortByTabIndex(e,t){for(var r=[];e.length>0&&t.length>0;)this._hasLowerTabOrder(e[0],t[0])?r.push(t.shift()):r.push(e.shift());return r.concat(e,t)}_hasLowerTabOrder(e,t){var r=Math.max(e.tabIndex,0),a=Math.max(t.tabIndex,0);return 0===r||0===a?a>r:r>a}};