text: var AuthorOptionsElement=function(){"use strict";function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function n(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),e}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&r(e,t)}function a(e){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function r(e,t){return(r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function u(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function c(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?u(e):t}function l(e){return function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}window.hasOwnProperty("AuthorBaseElement")||(console.error('[ERROR] <author-options> Required dependency "AuthorBaseElement" not found.'),console.info("AuthorBaseElement is available at https://github.com/author-elements/base"));var e=function(e){function t(){var f;return s(this,t),(f=c(this,a(t).call(this,'<template><style>@charset "UTF-8"; :host{contain:content;display:block;width:100%}:host *,:host :after,:host :before{box-sizing:border-box}author-options{contain:content;display:block;width:100%}author-options *,author-options :after,author-options :before{box-sizing:border-box}</style><slot name="afterbegin"></slot><slot name="beforeoptions"></slot><slot></slot><slot name="afteroptions"></slot><slot name="beforeend"></slot></template>'))).UTIL.defineProperties({cherryPickedOptions:{private:!0},form:{readonly:!0,get:function(){return f.parentNode.form}},displayOptions:{readonly:!0,get:function(){return new(f.PRIVATE.generateAuthorHTMLOptionsCollectionConstructor())(f.options.map(function(e){return e.displayElement}),f.selectedIndex,function(e,t){return f.addOption(f.PRIVATE.generateOptionObject(e),t)},function(e){return f.removeOptionByIndex(e)})}},hoveredIndex:{readonly:!0,get:function(){return f.options.findIndex(function(e){return e.displayElement.hover})}},isSlave:{private:!0,readonly:!0,get:function(){return"author-select"===f.parentNode.localName||"author-datalist"===f.parentNode.localName}},lastSelectedIndex:{private:!0},multiple:{readonly:!0,get:function(){return f.parentNode.multiple}},options:{readonly:!0,default:[]},selectedIndices:{readonly:!0,get:function(){return l(f.selectedOptions).map(function(e){return e.index})}},selectedOptions:{readonly:!0,get:function(){var e=f.querySelectorAll("[selected]");return new(f.PRIVATE.generateAuthorHTMLCollectionConstructor())(e)}},Selection:{readonly:!0,private:!0,default:function(){function t(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[];s(this,t),this.options=e}return n(t,[{key:"append",value:function(e){this.options.push(e)}},{key:"clear",value:function(){this.options=[]}},{key:"includes",value:function(e){return this.options.includes(e)}},{key:"prepend",value:function(e){this.options.unshift(e)}},{key:"selectAll",value:function(){this.options.forEach(function(e){return e.selected=!0})}},{key:"displayElements",get:function(){return this.options.map(function(e){return e.displayElement})}},{key:"length",get:function(){return this.options.length}},{key:"first",get:function(){return this.options[0]}},{key:"last",get:function(){return this.options[this.options.length-1]}}]),t}()},selectionStartIndex:{private:!0},visibleOptions:{readonly:!0,get:function(){return f.options.filter(function(e){return!e.hidden})}}}),f.UTIL.definePrivateMethods({arrowDownHandler:function(e){if(f.multiple){var t=f.PRIVATE.lastSelectedIndex;if(t!==f.options.length-1)return f.emit("option.selected",{index:null===t?0:t+1,keyboard:!0,shiftKey:e.detail.shiftKey,ctrlKey:!1,metaKey:!1})}else{var n=e.detail.startIndex;switch(n){case f.options.length-1:return;default:return f.hoverOption(n+1)}}},arrowUpHandler:function(e){if(f.multiple){var t=f.PRIVATE.lastSelectedIndex;if(0!==t)return f.emit("option.selected",{index:null===t?f.options.length-1:t-1,keyboard:!0,shiftKey:e.detail.shiftKey,ctrlKey:!1,metaKey:!1})}else{var n=e.detail.startIndex;switch(n){case-1:case 0:return;default:return f.hoverOption(n-1)}}},diffSelections:function(e,t){return e.filter(function(e){return!t.includes(e)})},generateAuthorHTMLOptionsCollectionConstructor:function(){var l=new WeakMap,t=f.PRIVATE.generateAuthorHTMLCollectionConstructor();return function(e){function r(e){var t,n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:-1,o=2<arguments.length?arguments[2]:void 0,i=3<arguments.length?arguments[3]:void 0;return s(this,r),(t=c(this,a(r).call(this,e))).selectedIndex=n,t.add=o,t.remove=i,l.set(u(t),{arr:e}),t}return i(r,t),n(r,[{key:Symbol.toStringTag,value:function(){return"AuthorHTMLOptionsCollection"}}]),r}()},generateOptgroup:function(e){if(!customElements.get("author-optgroup"))return f.UTIL.throwError({type:"dependency",vars:{name:"author-optgroup"}});var t=document.createElement("author-optgroup");t.id=f.UTIL.generateGuid("optgroup");var n=e.getAttribute("label");if(!n||""===n.trim())return f.UTIL.throwError({message:"<optgroup> must have a label attribute!"});t.setAttribute("label",n);var o=e.querySelectorAll("option");return Array.from(o).forEach(function(e){f.addOption(f.PRIVATE.generateOptionObject(e),null,t)}),t},generateOptionObject:function(e){return customElements.get("author-option")?new(f.PRIVATE.generateOptionConstructor())(u(f),f.UTIL.generateGuid(),e,document.createElement("author-option")):f.UTIL.throwError({type:"dependency",vars:{name:"author-option"}})},generateOptionConstructor:function(){var l=new WeakMap;return function(){function r(e,t,n,o){var i=this;s(this,r),this.key=t,this.form=e.form,this.defaultSelected=n.selected,this.sourceElement=n,this.displayElement=o,this.displayElement.parent=e,this.displayElement.selected=n.selected,this.displayElement.defaultSelected=n.selected,this.displayElement.innerHTML=n.innerHTML,Array.from(n.attributes).forEach(function(e){if("boolean"==typeof e.value)return e.value?i.displayElement.setAttribute(e.name,""):i.displayElement.removeAttribute(e.name);i.displayElement.setAttribute(e.name,e.value)}),l.set(this,{attributes:{disabled:n.disabled,id:n.getAttribute("id"),label:n.getAttribute("label")||n.textContent.trim(),selected:n.selected,value:n.hasAttribute("value")?n.getAttribute("value").trim():null,text:n.text.trim(),hidden:n.hidden},setAttr:function(e,t){"boolean"==typeof(i.sourceElement[e]=t)?t?i.displayElement.setAttribute(e,""):i.displayElement.removeAttribute(e):i.displayElement.setAttribute(e,t),l.get(i).attributes[e]=t}})}return n(r,[{key:"remove",value:function(){this.sourceElement.remove(),this.displayElement.remove()}},{key:"disabled",get:function(){return l.get(this).attributes.disabled},set:function(e){l.get(this).setAttr("disabled",e)}},{key:"hidden",get:function(){return l.get(this).attributes.hidden},set:function(e){l.get(this).setAttr("hidden",e)}},{key:"index",get:function(){return this.sourceElement.index}},{key:"id",get:function(){return l.get(this).attributes.id},set:function(e){l.get(this).setAttr("id",e)}},{key:"selected",get:function(){return l.get(this).attributes.selected},set:function(e){l.get(this).setAttr("selected",e)}},{key:"label",get:function(){return l.get(this).attributes.label},set:function(e){l.get(this).setAttr("label",e)}},{key:"text",get:function(){return l.get(this).attributes.text},set:function(e){l.get(this).setAttr("text",e)}},{key:"value",get:function(){return l.get(this).attributes.value},set:function(e){l.get(this).setAttr("value",e)}}]),r}()},getCurrentSelection:function(){return f.options.filter(function(e){return e.selected})},handleClickSelection:function(e,t){var n=f.PRIVATE,o=(n.cherryPickedOptions,n.getCurrentSelection),i=n.lastSelectedIndex,r=n.Selection,l=n.selectionStartIndex,s=e.index,a=e.shiftKey,u=e.ctrlKey,c=e.metaKey,d=f.options[s];if(a&&null!==i){f.PRIVATE.lastSelectedIndex=s,f.PRIVATE.cherryPickedOptions.clear();var p=[s,l].sort(function(e,t){return e-t});return t(new r(p[0]===p[1]?[d]:f.options.slice(p[0],p[1]+1)))}var h=o();return u||c?(f.PRIVATE.lastSelectedIndex=s,f.PRIVATE.selectionStartIndex=s,f.PRIVATE.cherryPickedOptions.options=d.selected?h.filter(function(e){return e!==d}):f.options.filter(function(e){return e===d||h.includes(e)}),t(f.PRIVATE.cherryPickedOptions)):1!==h.length||s!==i?(f.PRIVATE.lastSelectedIndex=s,f.PRIVATE.selectionStartIndex=s,f.PRIVATE.cherryPickedOptions.clear(),t(new r([d]))):void 0},handleKeyboardSelection:function(e,t){var n=f.PRIVATE,o=n.cherryPickedOptions,i=n.getCurrentSelection,r=n.Selection,l=n.selectionStartIndex,s=e.index,a=e.shiftKey,u=f.options[s],c=i();if(f.PRIVATE.lastSelectedIndex=s,!a||0===c.length)return f.PRIVATE.selectionStartIndex=s,f.PRIVATE.cherryPickedOptions.clear(),t(new r([u]));if(0<c.length){var d=[s,l].sort(),p=new r(d[0]===d[1]?[u]:f.options.slice(d[0],d[1]+1));return 0<o.length&&(p.options=f.options.filter(function(e){return p.includes(e)||o.includes(e)})),t(p)}},optionSelectionHandler:function(e){var t=f.PRIVATE,n=t.cherryPickedOptions,o=t.diffSelections,i=t.getCurrentSelection,r=t.generateAuthorHTMLCollectionConstructor,l=(t.handleClickSelection,t.handleKeyboardSelection,t.Selection);null===n&&(f.PRIVATE.cherryPickedOptions=new l([]));var s=e.detail,a=s.index,u=s.keyboard,c=function(e){var t=i(),n=e.length>=t.length?e.options:t;0!==o(n,n===t?e.options:t).length&&f.PRIVATE.isSlave&&(f.deselectAll(),e.selectAll(),f.emit("options.selected",{options:e.options,previous:f.selectedOptions,next:new(r())(e.displayElements)},f.parentNode))};return f.multiple?u?f.PRIVATE.handleKeyboardSelection(e.detail,c):f.PRIVATE.handleClickSelection(e.detail,c):c(new l([f.options[a]]))},parentStateChangeHandler:function(e){f.emit("state.change",e.detail);var t=e.detail,n=t.name,o=t.value;switch(n){case"multiple":if(!o&&0<f.selectedOptions.length){var i=f.selectedIndex;f.deselectAll(),f.emit("option.selected",{index:i})}break;default:return}}}),f.UTIL.registerListeners(u(f),{connected:function(){f.PRIVATE.selectionStartIndex=0<=f.selectedIndex?f.selectedIndex:0,f.PRIVATE.isSlave&&f.parentNode.on("state.change",f.PRIVATE.parentStateChangeHandler)},disconnected:function(){f.PRIVATE.isSlave&&f.parentNode.off("state.change",f.PRIVATE.parentStateChangeHandler)},"keydown.arrowUp":f.PRIVATE.arrowUpHandler,"keydown.arrowDown":f.PRIVATE.arrowDownHandler,"option.selected":f.PRIVATE.optionSelectionHandler}),f}return i(t,AuthorBaseElement(HTMLElement)),n(t,[{key:"addOptgroup",value:function(e){var t=document.createElement("author-optgroup-label");t.innerHTML=e.getAttribute("label"),this.appendChild(t),this.appendChild(e)}},{key:"addOption",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:this;if(!customElements.get("author-option"))return this.UTIL.throwError({type:"dependency",vars:{name:"author-option"}});e instanceof Option&&(e=this.PRIVATE.generateOptionObject(e)),this.PRIVATE.isSlave&&(this.parentNode["".concat(e.index)]=e.displayElement),t?(n.insertBefore(e.displayElement,n.children.item(t)),this.options.splice(t,0,e),this.PRIVATE.isSlave&&this.parentNode.sourceElement.add(e.sourceElement,t)):(n.appendChild(e.displayElement),this.options.push(e),this.PRIVATE.isSlave&&!this.parentNode.sourceElement[this.options.length-1]&&this.parentNode.sourceElement.appendChild(e.sourceElement)),!e.selected||this.multiple||(this.selectedIndex=e.index)}},{key:"addOptions",value:function(e){var n=this;Array.from(e).forEach(function(e){var t=e instanceof HTMLElement;switch(e.nodeName){case"OPTION":return n.addOption(t?n.PRIVATE.generateOptionObject(e):e);case"OPTGROUP":return n.addOptgroup(t?n.PRIVATE.generateOptgroup(e):e);default:return n.UTIL.printToConsole("".concat(e.nodeName.toLowerCase()," is not a valid child element for <author-select>. Removing..."),"warning")}})}},{key:"clear",value:function(){for(;this.lastChild;)this.removeChild(this.lastChild)}},{key:"deselect",value:function(e){var t=!(1<arguments.length&&void 0!==arguments[1])||arguments[1];"number"==typeof e&&(e=this.options[e]),e.selected=!1,this.PRIVATE.isSlave&&void 0!==this.selectedOptionsElement&&this.parentNode.selectedOptionsElement.remove(e,t)}},{key:"deselectAll",value:function(){var o=this,i=!(0<arguments.length&&void 0!==arguments[0])||arguments[0];this.options.filter(function(e){return e.selected}).forEach(function(e,t,n){o.deselect(e,n.length-1&&i)})}},{key:"hoverOption",value:function(e){this.unHoverAllOptions(),this.options[e].displayElement.hover=!0}},{key:"item",value:function(e){return this.options[e].displayElement}},{key:"namedItem",value:function(n){var e=this.options.filter(function(e){var t=e.sourceElement.attributes.getNamedItem("id");return t&&t.value===n});return e.length?e[e.length-1].displayElement:null}},{key:"removeOptionByIndex",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:null;null===e||e>=this.options.length||this.options[e].remove()}},{key:"unHoverAllOptions",value:function(){var n=this;this.options.forEach(function(e,t){return n.unHoverOption(t)})}},{key:"unHoverOption",value:function(e){this.options[e].displayElement.hover=!1}},{key:"selectedIndex",get:function(){return 0<this.selectedOptions.length?this.selectedOptions.item(0).index:-1},set:function(e){this.emit("option.selected",{index:e})}},{key:"selectionStartIndex",get:function(){return this.PRIVATE.selectionStartIndex},set:function(e){this.UTIL.throwError({type:"readonly",message:'"selectionStartIndex" cannot be set manually.'})}}]),t}();return customElements.define("author-options",e),e}();
  //# sourceMappingURL=author-options.es5.min.js.map
  