text: !function(e){if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof module&&void 0!==module.exports){var t=e();Object.defineProperty(exports,"__esModule",{value:!0}),exports.autocomplete=t,exports.default=t}else window.autocomplete=e()}(function(){"use strict";function e(e){function t(){return"none"!==m.display}function n(){E++,g=[],p=void 0,m.display="none"}function o(){for(;h.firstChild;)h.removeChild(h.firstChild);var t=!1,o="#9?$";g.forEach(function(e){e.group&&(t=!0)});var i=function(e){var t=v.createElement("div");return t.textContent=e.label,t};e.render&&(i=e.render);var l=function(e){var t=v.createElement("div");return t.textContent=e,t};if(e.renderGroup&&(l=e.renderGroup),g.forEach(function(t){if(t.group&&t.group!==o){o=t.group;var r=l(t.group);r&&(r.className+=" group",h.appendChild(r))}var a=i(t);a&&(a.addEventListener("click",function(o){e.onSelect(t.item,u),n(),o.preventDefault(),o.stopPropagation()}),t===p&&(a.className+=" selected"),h.appendChild(a))}),g.length<1){if(!e.emptyMsg)return void n();var a=v.createElement("div");a.className="empty",a.textContent=e.emptyMsg,h.appendChild(a)}var f=u.getBoundingClientRect(),d=f.top+u.offsetHeight+v.body.scrollTop;m.top=d+"px",m.left=f.left+"px",m.width=u.offsetWidth+"px",m.maxHeight=window.innerHeight-(f.top+u.offsetHeight)+"px",m.height="auto",m.display="block",r()}function i(i){var r=i.which||i.keyCode||0,l=++E;38!==r&&13!==r&&27!==r&&39!==r&&37!==r&&(40===r&&t()||(u.value.length>=y?e.fetch(u.value,function(e){E===l&&e&&!c&&(g=e,p=g.length>0?g[0]:void 0,o())}):n()))}function r(){var e=h.getElementsByClassName("selected");if(e.length>0){var t=e[0],n=t.previousElementSibling;if(n&&-1!==n.className.indexOf("group")&&!n.previousElementSibling&&(t=n),t.offsetTop<h.scrollTop)h.scrollTop=t.offsetTop;else{var o=t.offsetTop+t.offsetHeight,i=h.scrollTop+h.offsetHeight;o>i&&(h.scrollTop+=o-i)}}}function l(){if(g.length<1)p=void 0;else if(p===g[0])p=g[g.length-1];else for(var e=g.length-1;e>0;e--)if(p===g[e]||1===e){p=g[e-1];break}}function a(){if(g.length<1&&(p=void 0),!p||p===g[g.length-1])return void(p=g[0]);for(var e=0;e<g.length-1;e++)if(p===g[e]){p=g[e+1];break}}function f(i){var r=i.which||i.keyCode||0;if(38===r||40===r||27===r){var f=t();if(27===r)n();else{if(!t||g.length<1)return;38===r?l():a(),o()}return i.preventDefault(),void(f&&i.stopPropagation())}13===r&&p&&(e.onSelect(p.item,u),n())}function d(){setTimeout(function(){v.activeElement!==u&&n()},200)}function s(){c=!0,u.removeEventListener("keydown",f),u.removeEventListener("keyup",i),u.removeEventListener("blur",d),window.removeEventListener("resize",o),n();var e=h.parentNode;e&&e.removeChild(h)}var u,p,c,v=document,h=v.createElement("div"),m=h.style,g=[],y=e.minLength||2,E=0;if(!e.input)throw new Error("input undefined");return u=e.input,v.body.appendChild(h),h.className="autocomplete "+(e.className||""),m.position="absolute",m.display="none",u.addEventListener("keydown",f),u.addEventListener("keyup",i),u.addEventListener("blur",d),window.addEventListener("resize",o),{destroy:s}}return e});