text: /**
   * Tagify (v 3.15.3)- tags input component
   * By Yair Even-Or
   * Don't sell this code. (c)
   * https://github.com/yairEO/tagify
   */
  !function(t,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():t.Tagify=e()}(this,function(){"use strict";function s(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),i.push.apply(i,s)}return i}function h(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?s(i,!0).forEach(function(t){a(e,t,i[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):s(i).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))})}return e}function a(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function g(t){return function(t){if(Array.isArray(t)){for(var e=0,i=new Array(t.length);e<t.length;e++)i[e]=t[e];return i}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function r(t){return(r="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)}function d(t,e,i){return i?t==e:(""+t).toLowerCase()==(""+e).toLowerCase()}function u(t){var e=Object.prototype.toString.call(t).split(" ")[1].slice(0,-1);return t===Object(t)&&"Array"!=e&&"Function"!=e&&"RegExp"!=e&&"HTMLUnknownElement"!=e}function c(t){var e=document.createElement("div");return t.replace(/\&#?[0-9a-z]+;/gi,function(t){return e.innerHTML=t,e.innerText})}function i(t){return t?t.replace(/\>[\r\n ]+\</g,"><").replace(/(<.*?>)|\s+/g,function(t,e){return e||" "}):""}function o(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/`|'/g,"&#039;")}function p(t,e,i){function s(t,e){for(var i in e)e.hasOwnProperty(i)&&(u(e[i])?u(t[i])?s(t[i],e[i]):t[i]=Object.assign({},e[i]):t[i]=e[i])}return t instanceof Object||(t={}),s(t,e),i&&s(t,i),t}function f(t){return String.prototype.normalize?"string"==typeof t?t.normalize("NFD").replace(/[\u0300-\u036f]/g,""):void 0:t}function t(t,e){return t.previousElementSibling&&t.previousElementSibling.classList.contains("tagify")?(console.warn("Tagify: ","input element is already Tagified",t),this):t?(this.isFirefox="undefined"!=typeof InstallTrigger,this.isIE=window.document.documentMode,this.applySettings(t,e||{}),this.state={editing:!1,actions:{},mixMode:{},dropdown:{},flaggedTags:{}},this.value=[],this.listeners={},this.DOM={},p(this,new this.EventDispatcher(this)),this.build(t),this.getCSSVars(),this.loadOriginalValues(),this.events.customBinding.call(this),this.events.binding.call(this),void(t.autofocus&&this.DOM.input.focus())):(console.warn("Tagify: ","invalid input element ",t),this)}return(t.prototype={TEXTS:{empty:"empty",exceed:"number of tags exceeded",pattern:"pattern mismatch",duplicate:"already exists",notAllowed:"not allowed"},DEFAULTS:{delimiters:",",pattern:null,maxTags:1/0,callbacks:{},addTagOnBlur:!0,duplicates:!1,whitelist:[],blacklist:[],enforceWhitelist:!1,keepInvalidTags:!1,mixTagsAllowedAfter:/,|\.|\:|\s/,mixTagsInterpolator:["[[","]]"],backspace:!0,skipInvalid:!1,editTags:2,transformTag:function(){},autoComplete:{enabled:!0,rightKey:!1},classNames:{namespace:"tagify",input:"tagify__input",focus:"tagify--focus",tag:"tagify__tag",tagNoAnimation:"tagify--noAnim",tagInvalid:"tagify--invalid",tagNotAllowed:"tagify--notAllowed",inputInvalid:"tagify__input--invalid",tagX:"tagify__tag__removeBtn",tagText:"tagify__tag-text",dropdown:"tagify__dropdown",dropdownWrapper:"tagify__dropdown__wrapper",dropdownItem:"tagify__dropdown__item",dropdownItemActive:"tagify__dropdown__item--active",dropdownInital:"tagify__dropdown--initial",scopeLoading:"tagify--loading",tagLoading:"tagify__tag--loading",tagEditing:"tagify__tag--editable",tagFlash:"tagify__tag--flash",tagHide:"tagify__tag--hide",hasMaxTags:"tagify--hasMaxTags",hasNoTags:"tagify--noTags",empty:"tagify--empty"},dropdown:{classname:"",enabled:2,maxItems:10,searchKeys:[],fuzzySearch:!0,caseSensitive:!1,accentedSearch:!0,highlightFirst:!1,closeOnSelect:!0,position:"all",appendTarget:null},hooks:{beforeRemoveTag:function(){return Promise.resolve()},suggestionClick:function(){return Promise.resolve()}}},customEventsList:["change","add","remove","invalid","input","click","keydown","focus","blur","edit:input","edit:updated","edit:start","edit:keydown","dropdown:show","dropdown:hide","dropdown:select","dropdown:updated","dropdown:noMatch"],parseHTML:function(t){return(new DOMParser).parseFromString(t.trim(),"text/html").body.firstElementChild},templates:{wrapper:function(t,e){return'<tags class="'.concat(e.classNames.namespace," ").concat(e.mode?"".concat(e.classNames.namespace,"--").concat(e.mode):""," ").concat(t.className,'"\n                        ').concat(e.readonly?"readonly":"","\n                        ").concat(e.required?"required":"",'\n                        tabIndex="-1">\n                <span ').concat(e.readonly&&"mix"==e.mode?"":"contenteditable",' data-placeholder="').concat(e.placeholder||"&#8203;",'" aria-placeholder="').concat(e.placeholder||"",'"\n                    class="').concat(e.classNames.input,'"\n                    role="textbox"\n                    aria-autocomplete="both"\n                    aria-multiline="').concat("mix"==e.mode,'"></span>\n            </tags>')},tag:function(t){return'<tag title="'.concat(t.title||t.value,"\"\n                        contenteditable='false'\n                        spellcheck='false'\n                        tabIndex=\"-1\"\n                        class=\"").concat(this.settings.classNames.tag," ").concat(t.class?t.class:"",'"\n                        ').concat(this.getAttributes(t),">\n                <x title='' class=\"").concat(this.settings.classNames.tagX,"\" role='button' aria-label='remove tag'></x>\n                <div>\n                    <span class=\"").concat(this.settings.classNames.tagText,'">').concat(t.value,"</span>\n                </div>\n            </tag>")},dropdown:function(t){var e=t.dropdown,i="manual"==e.position,s="".concat(t.classNames.dropdown," ").concat(t.classNames.dropdown,"--").concat(e.position);return'<div class="'.concat(i?"":s," ").concat(e.classname,'" role="listbox" aria-labelledby="dropdown">\n                        <div class="').concat(t.classNames.dropdownWrapper,'"></div>\n                    </div>')},dropdownItem:function(t){return"<div ".concat(this.getAttributes(t),"\n                        class='").concat(this.settings.classNames.dropdownItem," ").concat(t.class?t.class:"",'\'\n                        tabindex="0"\n                        role="option">').concat(t.value,"</div>")},dropdownItemNoMatch:null},parseTemplate:function(t,e){return t=this.settings.templates[t]||t,this.parseHTML(i(t.apply(this,e)))},applySettings:function(i,t){this.DEFAULTS.templates=this.templates;var s=this.settings=p({},this.DEFAULTS,t);if(s.readonly=i.hasAttribute("readonly"),s.placeholder=i.getAttribute("placeholder")||s.placeholder||"",s.required=i.hasAttribute("required"),this.isIE&&(s.autoComplete=!1),["whitelist","blacklist"].forEach(function(t){var e=i.getAttribute("data-"+t);e&&(e=e.split(s.delimiters))instanceof Array&&(s[t]=e)}),"autoComplete"in t&&!u(t.autoComplete)&&(s.autoComplete=this.DEFAULTS.autoComplete,s.autoComplete.enabled=t.autoComplete),i.pattern)try{s.pattern=new RegExp(i.pattern)}catch(t){}if(this.settings.delimiters)try{s.delimiters=new RegExp(this.settings.delimiters,"g")}catch(t){}"select"==s.mode&&(s.dropdown.enabled=0),"mix"==s.mode&&(s.autoComplete.rightKey=!0),s.dropdown.appendTarget=t.dropdown&&t.dropdown.appendTarget?t.dropdown.appendTarget:document.body},getAttributes:function(t){if("[object Object]"!=Object.prototype.toString.call(t))return"";var e,i,s=Object.keys(t),a="";for(i=s.length;i--;)"class"!=(e=s[i])&&t.hasOwnProperty(e)&&void 0!==t[e]&&(a+=" "+e+(void 0!==t[e]?'="'.concat(t[e],'"'):""));return a},getCaretGlobalPosition:function(){var t=document.getSelection();if(t.rangeCount){var e,i,s=t.getRangeAt(0),a=s.startContainer,n=s.startOffset;return 0<n?((i=document.createRange()).setStart(a,n-1),i.setEnd(a,n),{left:(e=i.getBoundingClientRect()).right,top:e.top,bottom:e.bottom}):a.getBoundingClientRect()}return{left:-9999,top:-9999}},getCSSVars:function(){var t,e,i,s=getComputedStyle(this.DOM.scope,null);this.CSSVars={tagHideTransition:(t=function(t){if(!t)return{};var e=(t=t.trim().split(" ")[0]).split(/\d+/g).filter(function(t){return t}).pop().trim();return{value:+t.split(e).filter(function(t){return t})[0].trim(),unit:e}}((i="tag-hide-transition",s.getPropertyValue("--"+i))),e=t.value,"s"==t.unit?1e3*e:e)}},build:function(t){var e=this.DOM;e.originalInput=t,e.scope=this.parseTemplate("wrapper",[t,this.settings]),e.input=e.scope.querySelector("."+this.settings.classNames.input),t.parentNode.insertBefore(e.scope,t),0<=this.settings.dropdown.enabled&&this.dropdown.init.call(this)},destroy:function(){this.DOM.scope.parentNode.removeChild(this.DOM.scope),this.dropdown.hide.call(this,!0),clearTimeout(this.dropdownHide__bindEventsTimeout)},loadOriginalValues:function(t){var e=this;if(t=t||this.DOM.originalInput.value)if(this.removeAllTags(),"mix"==this.settings.mode)this.parseMixTags(t.trim());else{try{"string"!=typeof JSON.parse(t)&&(t=JSON.parse(t))}catch(t){}this.addTags(t).forEach(function(t){return t&&t.classList.add(e.settings.classNames.tagNoAnimation)})}else this.postUpdate();this.state.lastOriginalValueReported=this.DOM.originalInput.value,this.state.loadedOriginalValues=!0},cloneEvent:function(t){var e={};for(var i in t)e[i]=t[i];return e},EventDispatcher:function(n){var o=document.createTextNode("");function i(e,t,i){i&&t.split(/\s+/g).forEach(function(t){return o[e+"EventListener"].call(o,t,i)})}this.off=function(t,e){return i("remove",t,e),this},this.on=function(t,e){return e&&"function"==typeof e&&i("add",t,e),this},this.trigger=function(t,e){var i;if(t)if(n.settings.isJQueryPlugin)"remove"==t&&(t="removeTag"),jQuery(n.DOM.originalInput).triggerHandler(t,[e]);else{try{var s=p({},"object"===r(e)?e:{value:e});if(s.tagify=this,e instanceof Object)for(var a in e)e[a]instanceof HTMLElement&&(s[a]=e[a]);i=new CustomEvent(t,{detail:s})}catch(t){console.warn(t)}o.dispatchEvent(i)}}},loading:function(t){return this.state.isLoading=t,this.DOM.scope.classList[t?"add":"remove"](this.settings.classNames.scopeLoading),this},tagLoading:function(t,e){return t&&t.classList[e?"add":"remove"](this.settings.classNames.tagLoading),this},toggleFocusClass:function(t){this.DOM.scope.classList.toggle(this.settings.classNames.focus,!!t)},triggerChangeEvent:function(){var t=this.DOM.originalInput,e=this.state.lastOriginalValueReported!==t.value,i=new CustomEvent("change",{bubbles:!0});e&&(this.state.lastOriginalValueReported=t.value,i.simulated=!0,t._valueTracker&&t._valueTracker.setValue(Math.random()),t.dispatchEvent(i),this.trigger("change",this.state.lastOriginalValueReported),t.value=this.state.lastOriginalValueReported)},events:{customBinding:function(){var e=this;this.customEventsList.forEach(function(t){e.on(t,e.settings.callbacks[t])})},binding:function(t){var e,i=!(0<arguments.length&&void 0!==t)||t,s=this.events.callbacks,a=i?"addEventListener":"removeEventListener";if(!this.state.mainEvents||!i)for(var n in(this.state.mainEvents=i)&&!this.listeners.main&&(this.DOM.input.addEventListener(this.isIE?"keydown":"input",s[this.isIE?"onInputIE":"onInput"].bind(this)),this.settings.isJQueryPlugin&&jQuery(this.DOM.originalInput).on("tagify.removeAllTags",this.removeAllTags.bind(this))),e=this.listeners.main=this.listeners.main||{focus:["input",s.onFocusBlur.bind(this)],blur:["input",s.onFocusBlur.bind(this)],keydown:["input",s.onKeydown.bind(this)],click:["scope",s.onClickScope.bind(this)],dblclick:["scope",s.onDoubleClickScope.bind(this)],paste:["input",s.onPaste.bind(this)]})"blur"==n&&!i||this.DOM[e[n][0]][a](n,e[n][1])},callbacks:{onFocusBlur:function(t){var e=t.target?t.target.textContent.trim():"",i=this.settings,s=t.type,a=0<=i.dropdown.enabled,n={relatedTarget:t.relatedTarget},o=t.relatedTarget&&t.relatedTarget.classList.contains(this.settings.classNames.tag)&&this.DOM.scope.contains(t.relatedTarget),r=this.state.actions.selectOption&&(a||!i.dropdown.closeOnSelect),l=this.state.actions.addNew&&a,d=window.getSelection();if(!o){if("blur"==s){if(t.relatedTarget===this.DOM.scope)return this.dropdown.hide.call(this),void this.DOM.input.focus();this.postUpdate(),this.triggerChangeEvent()}if(!r&&!l)if(this.state.hasFocus="focus"==s&&+new Date,this.toggleFocusClass(this.state.hasFocus),"mix"!=i.mode){if("focus"==s)return this.trigger("focus",n),void(0===i.dropdown.enabled&&this.dropdown.show.call(this));"blur"==s&&(this.trigger("blur",n),this.loading(!1),("select"==this.settings.mode?!this.value.length||this.value[0].value!=e:e&&!this.state.actions.selectOption&&i.addTagOnBlur)&&this.addTags(e,!0)),this.DOM.input.removeAttribute("style"),this.dropdown.hide.call(this)}else"focus"==s?this.trigger("focus",n):"blur"==t.type&&(this.trigger("blur",n),this.loading(!1),this.dropdown.hide.call(this),this.state.dropdown.visible=void 0,this.state.selection={anchorOffset:d.anchorOffset,anchorNode:d.anchorNode})}},onKeydown:function(t){var s=this,e=t.target.textContent.trim();if(this.trigger("keydown",{originalEvent:this.cloneEvent(t)}),"mix"==this.settings.mode){switch(t.key){case"Left":case"ArrowLeft":this.state.actions.ArrowLeft=!0;break;case"Delete":case"Backspace":if(this.state.editing)return;var i=document.getSelection(),a="Delete"==t.key&&i.anchorOffset==i.anchorNode.length,n=1==i.anchorNode.nodeType||!i.anchorOffset&&i.anchorNode.previousElementSibling,o=c(this.DOM.input.innerHTML),r=this.getTagElms();if(3==i.anchorNode.nodeType&&!i.anchorNode.nodeValue&&i.anchorNode.previousElementSibling&&t.preventDefault(),(n||a)&&!this.settings.backspace)return void t.preventDefault();setTimeout(function(){var t=c(s.DOM.input.innerHTML);if((i.anchorNode==s.DOM.input&&t.length==o.length||!i.anchorOffset&&t.length>=o.length)&&(s.removeTags(i.anchorNode.previousElementSibling),s.fixFirefoxLastTagNoCaret(),2==s.DOM.input.children.length&&"BR"==s.DOM.input.children[1].tagName))return s.DOM.input.innerHTML="",!(s.value.length=0);s.value=[].map.call(r,function(t,e){var i=t.__tagifyTagData;if(t.parentNode)return i;s.trigger("remove",{tag:t,index:e,data:i})}).filter(function(t){return t})},50)}return!0}switch(t.key){case"Backspace":this.state.dropdown.visible&&"manual"!=this.settings.dropdown.position||""!=e&&8203!=e.charCodeAt(0)||(!0===this.settings.backspace?this.removeTags():"edit"==this.settings.backspace&&setTimeout(this.editTag.bind(this),0));break;case"Esc":case"Escape":if(this.state.dropdown.visible)return;t.target.blur();break;case"Down":case"ArrowDown":this.state.dropdown.visible||this.dropdown.show.call(this);break;case"ArrowRight":var l=this.state.inputSuggestion||this.state.ddItemData;if(l&&this.settings.autoComplete.rightKey)return void this.addTags([l],!0);break;case"Tab":if(t.preventDefault(),!e||"select"==this.settings.mode)return!0;case"Enter":if(this.state.dropdown.visible||229==t.keyCode)return;t.preventDefault(),setTimeout(function(){s.state.actions.selectOption||s.addTags(e,!0)})}},onInput:function(t){var e=this.input.normalize.call(this),i=e.length>=this.settings.dropdown.enabled,s={value:e,inputElm:this.DOM.input};if("mix"==this.settings.mode)return this.events.callbacks.onMixTagsInput.call(this,t);s.isValid=this.validateTag({value:e}),this.trigger("input",s),this.input.value!=e&&(this.input.set.call(this,e,!1),-1!=e.search(this.settings.delimiters)?this.addTags(e)&&this.input.set.call(this):0<=this.settings.dropdown.enabled&&this.dropdown[i?"show":"hide"].call(this,e))},onMixTagsInput:function(){var t,e,i,s,a,n,o,r,l=this,d=this.settings;if(this.value.length<this.getTagElms().length)return this.value=[].map.call(this.getTagElms(),function(t){return t.__tagifyTagData}),void this.update({withoutChangeEvent:!0});if(this.hasMaxTags())return!0;if(window.getSelection&&0<(o=window.getSelection()).rangeCount&&3==o.anchorNode.nodeType){if((t=o.getRangeAt(0).cloneRange()).collapse(!0),t.setStart(o.focusNode,0),s=(e=t.toString().slice(0,t.endOffset)).split(d.pattern).length-1,(i=e.match(d.pattern))&&(a=e.slice(e.lastIndexOf(i[i.length-1]))),a){this.state.actions.ArrowLeft=!1,this.state.tag={prefix:a.match(d.pattern)[0],value:a.replace(d.pattern,"")},this.state.tag.baseOffset=o.baseOffset-this.state.tag.value.length,n=this.state.tag.value.length>=d.dropdown.enabled;try{r=(r=this.state.flaggedTags[this.state.tag.baseOffset]).prefix==this.state.tag.prefix&&r.value[0]==this.state.tag.value[0],this.state.flaggedTags[this.state.tag.baseOffset]&&!this.state.tag.value&&delete this.state.flaggedTags[this.state.tag.baseOffset]}catch(t){}(r||s<this.state.mixMode.matchedPatternCount)&&(n=!1)}else this.state.flaggedTags={};this.state.mixMode.matchedPatternCount=s}setTimeout(function(){l.update({withoutChangeEvent:!0}),l.trigger("input",p({},l.state.tag,{textContent:l.DOM.input.textContent})),l.state.tag&&l.dropdown[n?"show":"hide"].call(l,l.state.tag.value)},10)},onInputIE:function(t){var e=this;setTimeout(function(){e.events.callbacks.onInput.call(e,t)})},onClickScope:function(t){var e=t.target.closest("."+this.settings.classNames.tag),i=this.settings,s=new Date-this.state.hasFocus;if(t.target!=this.DOM.scope){if(!t.target.classList.contains(this.settings.classNames.tagX))return e?(this.trigger("click",{tag:e,index:this.getNodeIndex(e),data:this.tagData(e),originalEvent:this.cloneEvent(t)}),void(1==this.settings.editTags&&this.events.callbacks.onDoubleClickScope.call(this,t))):void(t.target==this.DOM.input&&("mix"==i.mode&&this.fixFirefoxLastTagNoCaret(),500<s)?this.state.dropdown.visible?this.dropdown.hide.call(this):0===i.dropdown.enabled&&"mix"!=i.mode&&this.dropdown.show.call(this):"select"==i.mode&&(this.state.dropdown.visible||this.dropdown.show.call(this)));this.removeTags(t.target.parentNode)}else this.state.hasFocus||this.DOM.input.focus()},onPaste:function(t){var e;t.preventDefault(),e=(t.clipboardData||window.clipboardData).getData("Text"),"mix"==this.settings.mode?this.injectAtCaret(e,window.getSelection()):this.addTags(e)},onEditTagInput:function(t,e){var i=t.closest("."+this.settings.classNames.tag),s=this.getNodeIndex(i),a=this.tagData(i),n=this.input.normalize.call(this,t),o=n!=a.__originalData.value,r=this.validateTag({value:n});o||!0!==t.originalIsValid||(r=!0),i.classList.toggle(this.settings.classNames.invalid,!0!==r),a.__isValid=r,i.title=!0===r?a.title||a.value:r,n.length>=this.settings.dropdown.enabled&&(this.state.editing.value=n,this.dropdown.show.call(this,n)),this.trigger("edit:input",{tag:i,index:s,data:p({},this.value[s],{newValue:n}),originalEvent:this.cloneEvent(e)})},onEditTagFocus:function(t){this.state.editing={scope:t,input:t.querySelector("[contenteditable]")}},onEditTagBlur:function(t){if(this.state.editing=!1,this.state.hasFocus||this.toggleFocusClass(),this.DOM.scope.contains(t)){var e=t.closest("."+this.settings.classNames.tag),i=this.input.normalize.call(this,t),s=i,a=p({},this.tagData(e),{value:s}),n=s!=a.__originalData.value,o=this.validateTag(a);if(!i)return this.removeTags(e),void this.onEditTagDone(null,a);n?(this.settings.transformTag.call(this,a),!0===(o=this.validateTag(a))?(a=this.getWhitelistItemsByValue(s)[0]||a.__preInvalidData||{},a=Object.assign({},a,{value:s}),this.settings.transformTag.call(this,a),this.onEditTagDone(e,a)):this.trigger("invalid",{data:a,tag:e,message:o})):this.onEditTagDone(e,a.__originalData)}},onEditTagkeydown:function(t,e){switch(this.trigger("edit:keydown",{originalEvent:this.cloneEvent(t)}),t.key){case"Esc":case"Escape":t.target.textContent=e.__tagifyTagData.__originalData.value;case"Enter":case"Tab":t.preventDefault(),t.target.blur()}},onDoubleClickScope:function(t){var e,i,s=t.target.closest("."+this.settings.classNames.tag),a=this.settings;s&&(e=s.classList.contains(this.settings.classNames.tagEditing),i=s.hasAttribute("readonly"),"select"==a.mode||a.readonly||e||i||!this.settings.editTags||this.editTag(s),this.toggleFocusClass(!0),this.trigger("dblclick",{tag:s,index:this.getNodeIndex(s),data:this.tagData(s)}))}}},fixFirefoxLastTagNoCaret:function(){var t=this.DOM.input;if(this.isFirefox&&t.childNodes.length&&1==t.lastChild.nodeType)return t.appendChild(document.createTextNode("​")),this.setRangeAtStartEnd(!0),!0},placeCaretAfterTag:function(t){var e=t.nextSibling,i=window.getSelection(),s=i.getRangeAt(0);e||(e=document.createTextNode(""),t.appendChild(e),t.parentNode.insertBefore(e,t.nextSibling)),i.rangeCount&&(s.setStartAfter(t),s.setEndAfter(t),i.removeAllRanges(),i.addRange(s))},editTag:function(e,t){var i=this;t=t||{};var s=(e=e||this.getLastTag()).querySelector("."+this.settings.classNames.tagText),a=this.getNodeIndex(e),n=e.__tagifyTagData,o=this.events.callbacks,r=this,l=!0;if(s){if(!(n instanceof Object&&"editable"in n)||n.editable)return e.__tagifyTagData.__originalData=p({},n),e.classList.add(this.settings.classNames.tagEditing),s.setAttribute("contenteditable",!0),s.addEventListener("focus",o.onEditTagFocus.bind(this,e)),s.addEventListener("blur",function(){setTimeout(o.onEditTagBlur.bind(r),0,s)}),s.addEventListener("input",o.onEditTagInput.bind(this,s)),s.addEventListener("keydown",function(t){return o.onEditTagkeydown.call(i,t,e)}),s.focus(),this.setRangeAtStartEnd(!1,s),t.skipValidation||(l=this.editTagToggleValidity(e,n.value)),s.originalIsValid=l,this.trigger("edit:start",{tag:e,index:a,data:n,isValid:l}),this}else console.warn("Cannot find element in Tag template: .",this.settings.classNames.tagText)},editTagToggleValidity:function(t){var e,i=t.__tagifyTagData;if(i)return e=!(!i.__isValid||1==i.__isValid),t.classList.toggle(this.settings.classNames.tagInvalid,e),i.__isValid;console.warn("tag has no data: ",t,i)},onEditTagDone:function(t,e){e=e||{};var i={tag:t,index:this.getNodeIndex(t),data:e};this.trigger("edit:beforeUpdate",i),delete e.__originalData,t&&(this.editTagToggleValidity(t),this.replaceTag(t,e)),this.trigger("edit:updated",i),this.dropdown.hide.call(this),this.settings.keepInvalidTags&&this.reCheckInvalidTags()},replaceTag:function(t,e){e&&e.value||(e=t.__tagifyTagData),e.__isValid&&1!=e.__isValid&&p(e,this.getInvaildTagParams(e,e.__isValid));var i=this.createTagElem(e);t.parentNode.replaceChild(i,t),this.updateValueByDOMTags()},updateValueByDOMTags:function(){var e=this;this.value.length=0,[].forEach.call(this.getTagElms(),function(t){t.classList.contains(e.settings.classNames.tagNotAllowed)||e.value.push(e.tagData(t))}),this.update()},setRangeAtStartEnd:function(e,i){i=(i=i||this.DOM.input).lastChild||i;var s=document.getSelection();1<=s.rangeCount&&["Start","End"].forEach(function(t){return s.getRangeAt(0)["set"+t](i,e?0:i.length)})},injectAtCaret:function(t,e){e=e||this.state.selection||{};var i,s=window.getSelection();if(e.anchorNode&&void 0!==e.anchorOffset)return"string"==typeof t&&(t=document.createTextNode(t)),s.getRangeAt&&s.rangeCount&&((i=s.getRangeAt(0)).deleteContents(),i.insertNode(t)),this.DOM.input.focus(),this.setRangeAtStartEnd(!0,t.nextSibling),this.updateValueByDOMTags(),this.update(),this},input:{value:"",set:function(t,e){var i=0<arguments.length&&void 0!==t?t:"",s=!(1<arguments.length&&void 0!==e)||e,a=this.settings.dropdown.closeOnSelect;this.input.value=i,s&&(this.DOM.input.innerHTML=i),!i&&a&&this.dropdown.hide.bind(this),this.input.autocomplete.suggest.call(this),this.input.validate.call(this),this.setRangeAtStartEnd()},validate:function(){var t=!this.input.value||!0===this.validateTag({value:this.input.value});return this.DOM.input.classList.toggle(this.settings.classNames.inputInvalid,!t),t},normalize:function(t){var e=t||this.DOM.input,i=[];e.childNodes.forEach(function(t){return 3==t.nodeType&&i.push(t.nodeValue)}),i=i.join("\n");try{i=i.replace(/(?:\r\n|\r|\n)/g,this.settings.delimiters.source.charAt(0))}catch(t){}return i=i.replace(/\s/g," ").replace(/^\s+/,"")},autocomplete:{suggest:function(t){if(this.settings.autoComplete.enabled){"string"==typeof(t=t||{})&&(t={value:t});var e=t.value?""+t.value:"",i=e.substr(0,this.input.value.length).toLowerCase(),s=e.substring(this.input.value.length);e&&this.input.value&&i==this.input.value.toLowerCase()?(this.DOM.input.setAttribute("data-suggest",s),this.state.inputSuggestion=t):(this.DOM.input.removeAttribute("data-suggest"),delete this.state.inputSuggestion)}},set:function(t){var e=this.DOM.input.getAttribute("data-suggest"),i=t||(e?this.input.value+e:null);return!!i&&("mix"==this.settings.mode?this.replaceTextWithNode(document.createTextNode(this.state.tag.prefix+i)):(this.input.set.call(this,i),this.setRangeAtStartEnd()),this.input.autocomplete.suggest.call(this),this.dropdown.hide.call(this),!0)}}},getTagIdx:function(e){return this.value.findIndex(function(t){return JSON.stringify(t)==JSON.stringify(e)})},getNodeIndex:function(t){var e=0;if(t)for(;t=t.previousElementSibling;)e++;return e},getTagElms:function(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];var s=["."+this.settings.classNames.tag].concat(e).join(".");return this.DOM.scope.querySelectorAll(s)},getLastTag:function(){var t=this.DOM.scope.querySelectorAll(".".concat(this.settings.classNames.tag,":not(.").concat(this.settings.classNames.tagHide,"):not([readonly])"));return t[t.length-1]},tagData:function(t,e){return t?(e&&(t.__tagifyTagData=p({},t.__tagifyTagData||{},e)),t.__tagifyTagData):(console.warn("tag elment doesn't exist",t,e),e)},isTagDuplicate:function(i){var s=this.settings;return"select"!=s.mode&&this.value.reduce(function(t,e){return d((""+i).trim(),e.value,s.dropdown.caseSensitive)?t+1:t},0)},getTagIndexByValue:function(i){var s=this,a=[];return this.getTagElms().forEach(function(t,e){d(t.textContent.trim(),i,s.settings.dropdown.caseSensitive)&&a.push(e)}),a},getTagElmByValue:function(t){var e=this.getTagIndexByValue(t)[0];return this.getTagElms()[e]},flashTag:function(t){var e=this;t&&(t.classList.add(this.settings.classNames.tagFlash),setTimeout(function(){t.classList.remove(e.settings.classNames.tagFlash)},100))},isTagBlacklisted:function(e){return e=e.toLowerCase().trim(),this.settings.blacklist.filter(function(t){return e==t.toLowerCase()}).length},isTagWhitelisted:function(e){return this.settings.whitelist.some(function(t){return"string"==typeof e?d(e.trim(),t.value||t):d(JSON.stringify(t),JSON.stringify(e))})},validateTag:function(t){var e=t.value.trim(),i=this.settings,s=!0;return e?i.pattern&&i.pattern instanceof RegExp&&!i.pattern.test(e)?s=this.TEXTS.pattern:!i.duplicates&&this.isTagDuplicate(e)?s=this.TEXTS.duplicate:(this.isTagBlacklisted(e)||i.enforceWhitelist&&!this.isTagWhitelisted(e))&&(s=this.TEXTS.notAllowed):s=this.TEXTS.empty,s},getInvaildTagParams:function(t,e){return{"aria-invalid":!0,class:"".concat(t.class||""," ").concat(this.settings.classNames.tagNotAllowed).trim(),title:e}},hasMaxTags:function(){return this.value.length>=this.settings.maxTags&&this.TEXTS.exceed},normalizeTags:function(t){function i(t){return(t+"").split(n).filter(function(t){return t}).map(function(t){return{value:t.trim()}})}var s=this,e=this.settings,a=e.whitelist,n=e.delimiters,o=e.mode,r=!!a&&a[0]instanceof Object,l=t instanceof Array,d=[];if("number"==typeof t&&(t=t.toString()),"string"==typeof t){if(!t.trim())return[];t=i(t)}else if(l){var c;t=(c=[]).concat.apply(c,g(t.map(function(e){return e.value?i(e.value).map(function(t){return h(h({},e),t)}):i(e)})))}return r&&(t.forEach(function(t){var e=s.getWhitelistItemsByValue(t.value)[0];e&&e instanceof Object?d.push(e):"mix"!=o&&d.push(t)}),d.length&&(t=d)),t},getWhitelistItemsByValue:function(e){return this.settings.whitelist.filter.call(this,function(t){return"value"in t&&d(t.value||t,e,this.settings.dropdown.caseSensitive)})},parseMixTags:function(t){var o=this,e=this.settings,r=e.mixTagsInterpolator,l=e.duplicates,d=e.transformTag,c=e.enforceWhitelist,h=[];return t=t.split(r[0]).map(function(t,e){var i,s,a=t.split(r[1]),n=a[0];try{i=JSON.parse(n)}catch(t){i=o.normalizeTags(n)[0]}if(!(1<a.length)||c&&!o.isTagWhitelisted(i.value)||!l&&o.isTagDuplicate(i.value)){if(t)return e?r[0]+t:t}else d.call(o,i),s=o.createTagElem(i),h.push(i),s.classList.add(o.settings.classNames.tagNoAnimation),a[0]=s.outerHTML,o.value.push(i);return a.join("")}).join(""),this.DOM.input.innerHTML=t,this.DOM.input.appendChild(document.createTextNode("")),this.DOM.input.normalize(),this.getTagElms().forEach(function(t,e){return o.tagData(t,h[e])}),this.update({withoutChangeEvent:!0}),t},replaceTextWithNode:function(t,e){if(this.state.tag||e){e=e||this.state.tag.prefix+this.state.tag.value;var i,s,a=this.state.selection||window.getSelection(),n=a.anchorNode;return n.splitText(a.anchorOffset),i=n.nodeValue.lastIndexOf(e),(s=n.splitText(i)).nodeValue=s.nodeValue.replace(e,""),n.parentNode.insertBefore(t,s),s}},selectTag:function(t,e){if(!this.settings.enforceWhitelist||this.isTagWhitelisted(e.value))return this.input.set.call(this,e.value,!0),this.state.actions.selectOption&&setTimeout(this.setRangeAtStartEnd.bind(this)),this.getLastTag()?this.replaceTag(this.getLastTag(),e):this.appendTag(t),this.value[0]=e,this.trigger("add",{tag:t,data:e}),this.update(),[t]},addEmptyTag:function(){var t={value:""},e=this.createTagElem(t);this.tagData(e,t),this.appendTag(e),this.editTag(e,{skipValidation:!0})},addTags:function(t,e,i){var a=this,n=2<arguments.length&&void 0!==i?i:this.settings.skipInvalid,o=[],r=this.settings;return t&&0!=t.length?(t=this.normalizeTags(t),"mix"==r.mode?this.addMixTags(t):("select"==r.mode&&(e=!1),this.DOM.input.removeAttribute("style"),t.forEach(function(t){var e,i={},s=Object.assign({},t,{value:t.value+""});if(t=Object.assign({},s),r.transformTag.call(a,t),t.__isValid=a.hasMaxTags()||a.validateTag(t),!0!==t.__isValid){if(n)return;p(i,a.getInvaildTagParams(t,t.__isValid),{__preInvalidData:s}),t.__isValid==a.TEXTS.duplicate&&a.flashTag(a.getTagElmByValue(t.value))}if(t.readonly&&(i["aria-readonly"]=!0),e=a.createTagElem(p({},t,i)),o.push(e),"select"==r.mode)return a.selectTag(e,t);a.appendTag(e),t.__isValid&&!0===t.__isValid?(a.value.push(t),a.update(),a.trigger("add",{tag:e,index:a.value.length-1,data:t})):(a.trigger("invalid",{data:t,index:a.value.length,tag:e,message:t.__isValid}),r.keepInvalidTags||setTimeout(function(){return a.removeTags(e,!0)},1e3)),a.dropdown.position.call(a)}),t.length&&e&&this.input.set.call(this),this.dropdown.refilter.call(this),o)):("select"==r.mode&&this.removeAllTags(),o)},addMixTags:function(t){var e,i=this,s=this.settings;return s.transformTag.call(this,t[0]),t[0].prefix=t[0].prefix||this.state.tag?this.state.tag.prefix:(s.pattern.source||s.pattern)[0],e=this.createTagElem(t[0]),this.replaceTextWithNode(e)||this.DOM.input.appendChild(e),setTimeout(function(){return e.classList.add(i.settings.classNames.tagNoAnimation)},300),this.value.push(t[0]),this.update(),this.state.tag=null,this.trigger("add",p({},{tag:e},{data:t[0]})),this.fixFirefoxLastTagNoCaret(),setTimeout(this.placeCaretAfterTag.bind(this),100,e),e},appendTag:function(t){var e=this.DOM.scope.lastElementChild;e===this.DOM.input?this.DOM.scope.insertBefore(t,e):this.DOM.scope.appendChild(t)},createTagElem:function(t){var e,i=p({},t,{value:o(t.value)});return this.settings.readonly&&(t.readonly=!0),e=this.parseTemplate("tag",[i]),this.tagData(e,t),e},reCheckInvalidTags:function(){var a=this,t=this.settings,e=".".concat(t.classNames.tag,".").concat(t.classNames.tagNotAllowed),i=this.DOM.scope.querySelectorAll(e);[].forEach.call(i,function(t){var e=a.tagData(t),i=t.getAttribute("title")==a.TEXTS.duplicate,s=!0===a.validateTag(e);i&&s&&(e=e.__preInvalidData?e.__preInvalidData:{value:e.value},a.replaceTag(t,e))})},removeTags:function(t,i,s){var a,n=this;t=t&&t instanceof HTMLElement?[t]:t instanceof Array?t:t?[t]:[this.getLastTag()],a=t.reduce(function(t,e){return e&&"string"==typeof e&&(e=n.getTagElmByValue(e)),e&&t.push({node:e,data:n.tagData(e,{__removed:!0})}),t},[]),s="number"==typeof s?s:this.CSSVars.tagHideTransition,"select"==this.settings.mode&&(s=0,this.input.set.call(this)),1==a.length&&a[0].node.classList.contains(this.settings.classNames.tagNotAllowed)&&(i=!0),a.length&&this.settings.hooks.beforeRemoveTag(a,{tagify:this}).then(function(){function e(t){if(t.node.parentNode){var e=this.getTagIdx(t.data);t.node.parentNode.removeChild(t.node),i?this.settings.keepInvalidTags&&this.trigger("remove",{tag:t.node,index:e}):(this.trigger("remove",{tag:t.node,index:e,data:t.data}),this.dropdown.refilter.call(this),this.dropdown.position.call(this),this.DOM.input.normalize(),this.settings.keepInvalidTags&&this.reCheckInvalidTags())}}s&&10<s&&1==a.length?function(t){t.node.style.width=parseFloat(window.getComputedStyle(t.node).width)+"px",document.body.clientTop,t.node.classList.add(this.settings.classNames.tagHide),setTimeout(e.bind(this),s,t)}.call(n,a[0]):a.forEach(e.bind(n)),i||(a.forEach(function(t){var e=Object.assign({},t.data);delete e.__removed;var i=n.getTagIdx(e);-1<i&&n.value.splice(i,1)}),n.update())}).catch(function(t){})},removeAllTags:function(){this.value=[],"mix"==this.settings.mode?this.DOM.input.innerHTML="":Array.prototype.slice.call(this.getTagElms()).forEach(function(t){return t.parentNode.removeChild(t)}),this.dropdown.position.call(this),"select"==this.settings.mode&&this.input.set.call(this),this.update()},postUpdate:function(){var t=this.settings.classNames,e="mix"==this.settings.mode?this.DOM.originalInput.value:this.value.length;this.DOM.scope.classList.toggle(t.hasMaxTags,this.value.length>=this.settings.maxTags),this.DOM.scope.classList.toggle(t.hasNoTags,!this.value.length),this.DOM.scope.classList.toggle(t.empty,!e)},update:function(t){var e=this.DOM.originalInput,i=(t||{}).withoutChangeEvent,s=function(t,s){return t.map(function(t){var e={};for(var i in t)s.indexOf(i)<0&&(e[i]=t[i]);return e})}(this.value,["__isValid","__removed"]);e.value="mix"==this.settings.mode?this.getMixedTagsAsString(s):s.length?this.settings.originalInputValueFormat?this.settings.originalInputValueFormat(s):JSON.stringify(s):"",this.postUpdate(),!i&&this.state.loadedOriginalValues&&this.triggerChangeEvent()},getMixedTagsAsString:function(){var i="",s=this,a=this.settings.mixTagsInterpolator;return function e(t){t.childNodes.forEach(function(t){if(1==t.nodeType){if(t.classList.contains(s.settings.classNames.tag)&&s.tagData(t)){if(s.tagData(t).__removed)return;return void(i+=a[0]+JSON.stringify(t.__tagifyTagData)+a[1])}"BR"!=t.tagName||t.parentNode!=s.DOM.input&&1!=t.parentNode.childNodes.length?"DIV"!=t.tagName&&"P"!=t.tagName||(i+="\r\n",e(t)):i+="\r\n"}else i+=t.textContent})}(this.DOM.input),i},getNodeHeight:function(t){var e,i=t.cloneNode(!0);return i.style.cssText="position:fixed; top:-9999px; opacity:0",document.body.appendChild(i),e=i.clientHeight,i.parentNode.removeChild(i),e},dropdown:{init:function(){this.DOM.dropdown=this.parseTemplate("dropdown",[this.settings]),this.DOM.dropdown.content=this.DOM.dropdown.querySelector("."+this.settings.classNames.dropdownWrapper)},show:function(t){var e,i,s,a=this.settings,n=window.getSelection(),o="mix"==a.mode&&!a.enforceWhitelist,r=!a.whitelist||!a.whitelist.length,l="manual"==a.dropdown.position;if(!(r&&!o||!1===a.dropdown.enable||this.state.isLoading)){if(clearTimeout(this.dropdownHide__bindEventsTimeout),this.suggestedListItems=this.dropdown.filterListItems.call(this,t),t&&!this.suggestedListItems.length&&(this.trigger("dropdown:noMatch",t),a.templates.dropdownItemNoMatch&&(s=a.templates.dropdownItemNoMatch.call(this,{value:t}))),!s){if(this.suggestedListItems.length)t&&o&&!this.state.editing.scope&&!d(this.suggestedListItems[0].value,t)&&this.suggestedListItems.unshift({value:t});else{if(!t||!o||this.state.editing.scope)return this.input.autocomplete.suggest.call(this),void this.dropdown.hide.call(this);this.suggestedListItems=[{value:t}]}i=""+(u(e=this.suggestedListItems[0])?e.value:e),a.autoComplete&&i&&0==i.indexOf(t)&&this.input.autocomplete.suggest.call(this,e)}this.dropdown.fill.call(this,s),a.dropdown.highlightFirst&&this.dropdown.highlightOption.call(this,this.DOM.dropdown.content.children[0]),this.state.dropdown.visible||setTimeout(this.dropdown.events.binding.bind(this)),this.state.dropdown.visible=t||!0,this.state.dropdown.query=t,this.state.selection={anchorOffset:n.anchorOffset,anchorNode:n.anchorNode},l||(this.dropdown.position.call(this),this.dropdown.render.call(this)),this.trigger("dropdown:show",this.DOM.dropdown)}},hide:function(t){var e=this,i=this.DOM,s=i.scope,a=i.dropdown,n="manual"==this.settings.dropdown.position&&!t;if(a&&document.body.contains(a)&&!n)return window.removeEventListener("resize",this.dropdown.position),this.dropdown.events.binding.call(this,!1),s.setAttribute("aria-expanded",!1),a.parentNode.removeChild(a),setTimeout(function(){e.state.dropdown.visible=!1},100),this.state.dropdown.query=this.state.ddItemData=this.state.ddItemElm=this.state.selection=null,this.state.tag&&this.state.tag.value.length&&(this.state.flaggedTags[this.state.tag.baseOffset]=this.state.tag),this.trigger("dropdown:hide",a),this},render:function(){var t=this,e=this.getNodeHeight(this.DOM.dropdown),i=this.settings;return this.DOM.scope.setAttribute("aria-expanded",!0),document.body.contains(this.DOM.dropdown)||(this.DOM.dropdown.classList.add(i.classNames.dropdownInital),this.dropdown.position.call(this,e),i.dropdown.appendTarget.appendChild(this.DOM.dropdown),setTimeout(function(){return t.DOM.dropdown.classList.remove(i.classNames.dropdownInital)})),this},fill:function(t){t="string"==typeof t?t:this.dropdown.createListHTML.call(this,t||this.suggestedListItems),this.DOM.dropdown.content.innerHTML=i(t)},refilter:function(t){t=t||this.state.dropdown.query||"",this.suggestedListItems=this.dropdown.filterListItems.call(this,t),this.suggestedListItems.length?this.dropdown.fill.call(this):this.dropdown.hide.call(this),this.trigger("dropdown:updated",this.DOM.dropdown)},position:function(t){var e,i,s,a,n,o,r,l=this,d=this.DOM.dropdown,c=document.documentElement.clientHeight,h=this.DOM["input"==this.settings.dropdown.position?"input":"scope"];t=t||d.clientHeight,this.state.dropdown.visible&&(o="text"==this.settings.dropdown.position?(a=(i=this.getCaretGlobalPosition()).bottom,s=i.top,n=i.left,"auto"):(r=function(){for(var t=l.settings.dropdown.appendTarget,e=0,i=0;t;)e+=t.offsetLeft||0,i+=t.offsetTop||0,t=t.parentNode;return{left:e,top:i}}(),s=(i=h.getBoundingClientRect()).top+2-r.top,a=i.bottom-1-r.top,n=i.left-r.left,i.width+"px"),s=Math.floor(s),a=Math.ceil(a),e=c-i.bottom<t,d.style.cssText="left:"+(n+window.pageXOffset)+"px; width:"+o+";"+(e?"top: "+(s+window.pageYOffset)+"px":"top: "+(a+window.pageYOffset)+"px"),d.setAttribute("placement",e?"top":"bottom"))},events:{binding:function(t){var e=!(0<arguments.length&&void 0!==t)||t,i=this.dropdown.events.callbacks,s=this.listeners.dropdown=this.listeners.dropdown||{position:this.dropdown.position.bind(this),onKeyDown:i.onKeyDown.bind(this),onMouseOver:i.onMouseOver.bind(this),onMouseLeave:i.onMouseLeave.bind(this),onClick:i.onClick.bind(this),onScroll:i.onScroll.bind(this)},a=e?"addEventListener":"removeEventListener";"manual"!=this.settings.dropdown.position&&(window[a]("resize",s.position),window[a]("keydown",s.onKeyDown)),this.DOM.dropdown[a]("mouseover",s.onMouseOver),this.DOM.dropdown[a]("mouseleave",s.onMouseLeave),this.DOM.dropdown[a]("mousedown",s.onClick),this.DOM.dropdown.content[a]("scroll",s.onScroll)},callbacks:{onKeyDown:function(t){var e=this.DOM.dropdown.querySelector("[class$='--active']"),i=e;switch(t.key){case"ArrowDown":case"ArrowUp":case"Down":case"Up":var s;t.preventDefault(),i=(i=i&&i[("ArrowUp"==t.key||"Up"==t.key?"previous":"next")+"ElementSibling"])||(s=this.DOM.dropdown.content.children)["ArrowUp"==t.key||"Up"==t.key?s.length-1:0],this.dropdown.highlightOption.call(this,i,!0);break;case"Escape":case"Esc":this.dropdown.hide.call(this);break;case"ArrowRight":if(this.state.actions.ArrowLeft)return;case"Tab":if("mix"!=this.settings.mode&&!this.settings.autoComplete.rightKey){try{var a=i?i.textContent:this.suggestedListItems[0].value;this.input.autocomplete.set.call(this,a)}catch(t){}return!1}case"Enter":t.preventDefault(),this.dropdown.selectOption.call(this,e);break;case"Backspace":if("mix"==this.settings.mode||this.state.editing.scope)return;var n=this.input.value.trim();""!=n&&8203!=n.charCodeAt(0)||(!0===this.settings.backspace?this.removeTags():"edit"==this.settings.backspace&&setTimeout(this.editTag.bind(this),0))}},onMouseOver:function(t){var e=t.target.closest("."+this.settings.classNames.dropdownItem);e&&this.dropdown.highlightOption.call(this,e)},onMouseLeave:function(){this.dropdown.highlightOption.call(this)},onClick:function(t){var e=this;if(0==t.button&&t.target!=this.DOM.dropdown){var i=t.target.closest("."+this.settings.classNames.dropdownItem);this.state.actions.selectOption=!0,setTimeout(function(){return e.state.actions.selectOption=!1},50),this.settings.hooks.suggestionClick(t,{tagify:this,suggestionElm:i}).then(function(){i&&e.dropdown.selectOption.call(e,i)}).catch(function(t){return t})}},onScroll:function(t){var e=t.target,i=e.scrollTop/(e.scrollHeight-e.parentNode.clientHeight)*100;this.trigger("dropdown:scroll",{percentage:Math.round(i)})}}},highlightOption:function(t,e){var i,s=this.settings.classNames.dropdownItemActive;if(this.state.ddItemElm&&(this.state.ddItemElm.classList.remove(s),this.state.ddItemElm.removeAttribute("aria-selected")),!t)return this.state.ddItemData=null,this.state.ddItemElm=null,void this.input.autocomplete.suggest.call(this);i=this.suggestedListItems[this.getNodeIndex(t)],this.state.ddItemData=i,(this.state.ddItemElm=t).classList.add(s),t.setAttribute("aria-selected",!0),e&&(t.parentNode.scrollTop=t.clientHeight+t.offsetTop-t.parentNode.clientHeight),this.settings.autoComplete&&(this.input.autocomplete.suggest.call(this,i),"manual"!=this.settings.dropdown.position&&this.dropdown.position.call(this))},selectOption:function(t){var e=this,i=this.settings.dropdown.closeOnSelect;if(!t)return this.addTags(this.input.value,!0),void(i&&this.dropdown.hide.call(this));var s=t.getAttribute("tagifySuggestionIdx"),a=(s?this.suggestedListItems[+s]:"")||this.input.value;if(this.trigger("dropdown:select",{data:a,elm:t}),this.state.editing?this.onEditTagDone(this.state.editing.scope,h(h(h({},this.state.editing.scope.__tagifyTagData),{},{value:a.value},a instanceof Object?a:{}),{},{__isValid:!0})):this.addTags([a],!0),setTimeout(function(){e.DOM.input.focus(),e.toggleFocusClass(!0)}),i)return this.dropdown.hide.call(this);this.dropdown.refilter.call(this)},selectAll:function(){var t=this.settings.skipInvalid;return this.settings.skipInvalid=!0,this.addTags(this.settings.whitelist,!0),this.settings.skipInvalid=t,this.dropdown.hide.call(this),this},filterListItems:function(t){var i,e,s,a,n,o=this,r=this.settings,l=[],d=r.whitelist,c=r.dropdown.maxItems||1/0,h=r.dropdown.searchKeys.concat(["searchBy","value"]),g=0;if(!t)return(r.duplicates?d:d.filter(function(t){return!o.isTagDuplicate(u(t)?t.value:t)})).slice(0,c);for(n=r.dropdown.caseSensitive?""+t:(""+t).toLowerCase();g<d.length&&(i=d[g]instanceof Object?d[g]:{value:d[g]},e=r.dropdown.fuzzySearch?(s=h.reduce(function(t,e){return t+" "+(i[e]||"")},"").toLowerCase(),0<=(r.dropdown.accentedSearch?f(s).indexOf(f(n)):s.indexOf(n))):h.some(function(t){var e=""+i[t]||"";return r.dropdown.accentedSearch&&(e=f(e),n=f(n)),r.dropdown.caseSensitive||(e=e.toLowerCase()),0==e.indexOf(n)}),a=!r.duplicates&&this.isTagDuplicate(u(i)?i.value:i),e&&!a&&c--&&l.push(i),0!=c);g++);return l},createListHTML:function(t){var n=this;return t.map(function(t,e){"string"!=typeof t&&"number"!=typeof t||(t={value:t});var i=n.settings.dropdown.mapValueTo,s=i?"function"==typeof i?i(t):t[i]:t.value,a=p({},t,{value:s&&"string"==typeof s?o(s):s,tagifySuggestionIdx:e});return n.settings.templates.dropdownItem.call(n,a)}).join("")}}}).removeTag=t.prototype.removeTags,t});