@yaireo/tagify
Version:
lightweight, efficient Tags input component in Vanilla JS / React / Angular [super customizable, tiny size & top performance]
28 lines (23 loc) • 83.8 kB
JSX
/*
Tagify v4.27.0 - tags input component
By: Yair Even-Or <vsync.design@gmail.com>
https://github.com/yairEO/tagify
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
This Software may not be rebranded and sold as a library under any other name
other than "Tagify" (by owner) or as part of another library.
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react/jsx-runtime"),require("react"),require("react-dom/server"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react/jsx-runtime","react","react-dom/server","prop-types"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Tagify={},t.jsxRuntime,t.React,t.server,t.propTypes)}(this,(function(t,e,n,i,s){"use strict";function a(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=a(n),r="​";function l(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function d(t){return function(t){if(Array.isArray(t))return l(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return l(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return l(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var c={isEnabled:function(){var t;return null===(t=window.TAGIFY_DEBUG)||void 0===t||t},log:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var i;this.isEnabled()&&(i=console).log.apply(i,["[Tagify]:"].concat(d(e)))},warn:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var i;this.isEnabled()&&(i=console).warn.apply(i,["[Tagify]:"].concat(d(e)))}},u=function(t,e,n,i){return t=""+t,e=""+e,i&&(t=t.trim(),e=e.trim()),n?t==e:t.toLowerCase()==e.toLowerCase()},g=function(t,e){return t&&Array.isArray(t)&&t.map((function(t){return h(t,e)}))};function h(t,e){var n,i={};for(n in t)e.indexOf(n)<0&&(i[n]=t[n]);return i}function p(t){var e=document.createElement("div");return t.replace(/\&#?[0-9a-z]+;/gi,(function(t){return e.innerHTML=t,e.innerText}))}function f(t){return(new DOMParser).parseFromString(t.trim(),"text/html").body.firstElementChild}function m(t,e){for(e=e||"previous";t=t[e+"Sibling"];)if(3==t.nodeType)return t}function v(t){return"string"==typeof t?t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/`|'/g,"'"):t}function y(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 b(t,e,n){var i,s;function a(t,e){for(var n in e)if(e.hasOwnProperty(n)){if(y(e[n])){y(t[n])?a(t[n],e[n]):t[n]=Object.assign({},e[n]);continue}if(Array.isArray(e[n])){t[n]=Object.assign([],e[n]);continue}t[n]=e[n]}}return i=t,(null!=(s=Object)&&"undefined"!=typeof Symbol&&s[Symbol.hasInstance]?s[Symbol.hasInstance](i):i instanceof s)||(t={}),a(t,e),n&&a(t,n),t}function w(){var t=[],e={},n=!0,i=!1,s=void 0;try{for(var a,o=arguments[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var r=a.value,l=!0,d=!1,c=void 0;try{for(var u,g=r[Symbol.iterator]();!(l=(u=g.next()).done);l=!0){var h=u.value;y(h)?e[h.value]||(t.push(h),e[h.value]=1):t.includes(h)||t.push(h)}}catch(t){d=!0,c=t}finally{try{l||null==g.return||g.return()}finally{if(d)throw c}}}}catch(t){i=!0,s=t}finally{try{n||null==o.return||o.return()}finally{if(i)throw s}}return t}function T(t){return String.prototype.normalize?"string"==typeof t?t.normalize("NFD").replace(/[\u0300-\u036f]/g,""):void 0:t}var O=function(){return/(?=.*chrome)(?=.*android)/i.test(navigator.userAgent)};function D(){return([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,(function(t){return(t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16)}))}function x(t){return t&&t.classList&&t.classList.contains(this.settings.classNames.tag)}function S(t){return t&&t.closest(this.settings.classNames.tagSelector)}function E(t,e){var n=window.getSelection();return e=e||n.getRangeAt(0),"string"==typeof t&&(t=document.createTextNode(t)),e&&(e.deleteContents(),e.insertNode(t)),t}function I(t,e,n){return t?(e&&(t.__tagifyTagData=n?e:b({},t.__tagifyTagData||{},e)),t.__tagifyTagData):(c.warn("tag element doesn't exist",{tagElm:t,data:e}),e)}function M(t){if(t&&t.parentNode){var e=t,n=window.getSelection(),i=n.getRangeAt(0);n.rangeCount&&(i.setStartAfter(e),i.collapse(!0),n.removeAllRanges(),n.addRange(i))}}function N(t,e){t.forEach((function(t){if(I(t.previousSibling)||!t.previousSibling){var n=document.createTextNode("");t.before(n),e&&M(n)}}))}var _={delimiters:",",pattern:null,tagTextProp:"value",maxTags:1/0,callbacks:{},addTagOnBlur:!0,addTagOn:["blur","tab","enter"],onChangeAfterBlur:!0,duplicates:!1,whitelist:[],blacklist:[],enforceWhitelist:!1,userInput:!0,focusable:!0,keepInvalidTags:!1,createInvalidTags:!0,mixTagsAllowedAfter:/,|\.|\:|\s/,mixTagsInterpolator:["[[","]]"],backspace:!0,skipInvalid:!1,pasteAsTags:!0,editTags:{clicks:2,keepInvalid:!0},transformTag:function(){},trim:!0,a11y:{focusableTags:!1},mixMode:{insertAfterTag:" "},autoComplete:{enabled:!0,rightKey:!1,tabKey:!1},classNames:{namespace:"tagify",mixMode:"tagify--mix",selectMode:"tagify--select",input:"tagify__input",focus:"tagify--focus",tagNoAnimation:"tagify--noAnim",tagInvalid:"tagify--invalid",tagNotAllowed:"tagify--notAllowed",scopeLoading:"tagify--loading",hasMaxTags:"tagify--hasMaxTags",hasNoTags:"tagify--noTags",empty:"tagify--empty",inputInvalid:"tagify__input--invalid",dropdown:"tagify__dropdown",dropdownWrapper:"tagify__dropdown__wrapper",dropdownHeader:"tagify__dropdown__header",dropdownFooter:"tagify__dropdown__footer",dropdownItem:"tagify__dropdown__item",dropdownItemActive:"tagify__dropdown__item--active",dropdownItemHidden:"tagify__dropdown__item--hidden",dropdownItemSelected:"tagify__dropdown__item--selected",dropdownInital:"tagify__dropdown--initial",tag:"tagify__tag",tagText:"tagify__tag-text",tagX:"tagify__tag__removeBtn",tagLoading:"tagify__tag--loading",tagEditing:"tagify__tag--editable",tagFlash:"tagify__tag--flash",tagHide:"tagify__tag--hide"},dropdown:{classname:"",enabled:2,maxItems:10,searchKeys:["value","searchBy"],fuzzySearch:!0,caseSensitive:!1,accentedSearch:!0,includeSelectedTags:!1,escapeHTML:!0,highlightFirst:!0,closeOnSelect:!0,clearOnSelect:!0,position:"all",appendTarget:null},hooks:{beforeRemoveTag:function(){return Promise.resolve()},beforePaste:function(){return Promise.resolve()},suggestionClick:function(){return Promise.resolve()},beforeKeyDown:function(){return Promise.resolve()}}};function A(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function C(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter((function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable})))),i.forEach((function(e){A(t,e,n[e])}))}return t}function k(t,e){return e=null!=e?e:{},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):function(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}(Object(e)).forEach((function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n))})),t}var L={events:{binding:function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],e=this.dropdown.events.callbacks,n=this.listeners.dropdown=this.listeners.dropdown||{position:this.dropdown.position.bind(this,null),onKeyDown:e.onKeyDown.bind(this),onMouseOver:e.onMouseOver.bind(this),onMouseLeave:e.onMouseLeave.bind(this),onClick:e.onClick.bind(this),onScroll:e.onScroll.bind(this)},i=t?"addEventListener":"removeEventListener";"manual"!=this.settings.dropdown.position&&(document[i]("scroll",n.position,!0),window[i]("resize",n.position),window[i]("keydown",n.onKeyDown)),this.DOM.dropdown[i]("mouseover",n.onMouseOver),this.DOM.dropdown[i]("mouseleave",n.onMouseLeave),this.DOM.dropdown[i]("mousedown",n.onClick),this.DOM.dropdown.content[i]("scroll",n.onScroll)},callbacks:{onKeyDown:function(t){var e=this;if(this.state.hasFocus&&!this.state.composing){var n=this.settings,i=this.DOM.dropdown.querySelector(n.classNames.dropdownItemActiveSelector),s=this.dropdown.getSuggestionDataByNode(i),a="mix"==n.mode,o="select"==n.mode;n.hooks.beforeKeyDown(t,{tagify:this}).then((function(r){switch(t.key){case"ArrowDown":case"ArrowUp":case"Down":case"Up":t.preventDefault();var l=e.dropdown.getAllSuggestionsRefs(),d="ArrowUp"==t.key||"Up"==t.key;i&&(i=e.dropdown.getNextOrPrevOption(i,!d)),i&&i.matches(n.classNames.dropdownItemSelector)||(i=l[d?l.length-1:0]),e.dropdown.highlightOption(i,!0);break;case"Escape":case"Esc":e.dropdown.hide();break;case"ArrowRight":if(e.state.actions.ArrowLeft||n.autoComplete.rightKey)return;case"Tab":var u=!n.autoComplete.rightKey||!n.autoComplete.tabKey;if(!a&&!o&&i&&u&&!e.state.editing&&s){t.preventDefault();var g=e.dropdown.getMappedValue(s);return e.input.autocomplete.set.call(e,g),!1}return!0;case"Enter":t.preventDefault(),n.hooks.suggestionClick(t,{tagify:e,tagData:s,suggestionElm:i}).then((function(){if(i)return e.dropdown.selectOption(i),i=e.dropdown.getNextOrPrevOption(i,!d),void e.dropdown.highlightOption(i);e.dropdown.hide(),a||e.addTags(e.state.inputText.trim(),!0)})).catch((function(t){return c.warn(t)}));break;case"Backspace":if(a||e.state.editing.scope)return;var h=e.input.raw.call(e);""!=h&&8203!=h.charCodeAt(0)||(!0===n.backspace?e.removeTags():"edit"==n.backspace&&setTimeout(e.editTag.bind(e),0))}}))}},onMouseOver:function(t){var e=t.target.closest(this.settings.classNames.dropdownItemSelector);this.dropdown.highlightOption(e)},onMouseLeave:function(t){this.dropdown.highlightOption()},onClick:function(t){var e=this;if(0==t.button&&t.target!=this.DOM.dropdown&&t.target!=this.DOM.dropdown.content){var n=t.target.closest(this.settings.classNames.dropdownItemSelector),i=this.dropdown.getSuggestionDataByNode(n);this.state.actions.selectOption=!0,setTimeout((function(){return e.state.actions.selectOption=!1}),50),this.settings.hooks.suggestionClick(t,{tagify:this,tagData:i,suggestionElm:n}).then((function(){n?e.dropdown.selectOption(n,t):e.dropdown.hide()})).catch((function(t){return c.warn(t)}))}},onScroll:function(t){var e=t.target,n=e.scrollTop/(e.scrollHeight-e.parentNode.clientHeight)*100;this.trigger("dropdown:scroll",{percentage:Math.round(n)})}}},refilter:function(t){t=t||this.state.dropdown.query||"",this.suggestedListItems=this.dropdown.filterListItems(t),this.dropdown.fill(),this.suggestedListItems.length||this.dropdown.hide(),this.trigger("dropdown:updated",this.DOM.dropdown)},getSuggestionDataByNode:function(t){for(var e,n=t&&t.getAttribute("value"),i=this.suggestedListItems.length;i--;){if(y(e=this.suggestedListItems[i])&&e.value==n)return e;if(e==n)return{value:e}}},getNextOrPrevOption:function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=this.dropdown.getAllSuggestionsRefs(),i=n.findIndex((function(e){return e===t}));return e?n[i+1]:n[i-1]},highlightOption:function(t,e){var n,i=this.settings.classNames.dropdownItemActive;if(this.state.ddItemElm&&(this.state.ddItemElm.classList.remove(i),this.state.ddItemElm.removeAttribute("aria-selected")),!t)return this.state.ddItemData=null,this.state.ddItemElm=null,void this.input.autocomplete.suggest.call(this);n=this.dropdown.getSuggestionDataByNode(t),this.state.ddItemData=n,this.state.ddItemElm=t,t.classList.add(i),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,n),this.dropdown.position())},selectOption:function(t,e){var n=this,i=this.settings,s=i.dropdown,a=s.clearOnSelect,o=s.closeOnSelect;if(!t)return this.addTags(this.state.inputText,!0),void(o&&this.dropdown.hide());e=e||{};var r=t.getAttribute("value"),l="noMatch"==r,d="mix"==i.mode,c=this.suggestedListItems.find((function(t){var e;return(null!==(e=t.value)&&void 0!==e?e:t)==r}));if(this.trigger("dropdown:select",{data:c,elm:t,event:e}),r&&(c||l)){if(this.state.editing){var u=this.normalizeTags([c])[0];c=i.transformTag.call(this,u)||u,this.onEditTagDone(null,b({__isValid:!0},c))}else this[d?"addMixTags":"addTags"]([c||this.input.raw.call(this)],a);(d||this.DOM.input.parentNode)&&(setTimeout((function(){n.DOM.input.focus(),n.toggleFocusClass(!0)})),o&&setTimeout(this.dropdown.hide.bind(this)),t.addEventListener("transitionend",(function(){n.dropdown.fillHeaderFooter(),setTimeout((function(){t.remove(),n.dropdown.refilter()}),100)}),{once:!0}),t.classList.add(this.settings.classNames.dropdownItemHidden))}else o&&setTimeout(this.dropdown.hide.bind(this))},selectAll:function(t){this.suggestedListItems.length=0,this.dropdown.hide(),this.dropdown.filterListItems("");var e=this.dropdown.filterListItems("");return t||(e=this.state.dropdown.suggestions),this.addTags(e,!0),this},filterListItems:function(t,e){var n,i,s,a,o,r,l=function(){var t,l,d=void 0,c=void 0;t=p[b],i=(null!=(l=Object)&&"undefined"!=typeof Symbol&&l[Symbol.hasInstance]?l[Symbol.hasInstance](t):t instanceof l)?p[b]:{value:p[b]};var f,m=!Object.keys(i).some((function(t){return v.includes(t)}))?["value"]:v;u.fuzzySearch&&!e.exact?(a=m.reduce((function(t,e){return t+" "+(i[e]||"")}),"").toLowerCase().trim(),u.accentedSearch&&(a=T(a),r=T(r)),d=0==a.indexOf(r),c=a===r,f=a,s=r.toLowerCase().split(" ").every((function(t){return f.includes(t.toLowerCase())}))):(d=!0,s=m.some((function(t){var n=""+(i[t]||"");return u.accentedSearch&&(n=T(n),r=T(r)),u.caseSensitive||(n=n.toLowerCase()),c=n===r,e.exact?n===r:0==n.indexOf(r)}))),o=!u.includeSelectedTags&&n.isTagDuplicate(y(i)?i.value:i),s&&!o&&(c&&d?h.push(i):"startsWith"==u.sortby&&d?g.unshift(i):g.push(i))},d=this,c=this.settings,u=c.dropdown,g=(e=e||{},[]),h=[],p=c.whitelist,f=u.maxItems>=0?u.maxItems:1/0,m=u.includeSelectedTags||"select"==c.mode,v=u.searchKeys,b=0;if(!(t="select"==c.mode&&this.value.length&&this.value[0][c.tagTextProp]==t?"":t)||!v.length)return g=m?p:p.filter((function(t){return!d.isTagDuplicate(y(t)?t.value:t)})),this.state.dropdown.suggestions=g,g.slice(0,f);for(r=u.caseSensitive?""+t:(""+t).toLowerCase();b<p.length;b++)n=this,l();return this.state.dropdown.suggestions=h.concat(g),"function"==typeof u.sortby?u.sortby(h.concat(g),r):h.concat(g).slice(0,f)},getMappedValue:function(t){var e=this.settings.dropdown.mapValueTo;return e?"function"==typeof e?e(t):t[e]||t.value:t.value},createListHTML:function(t){var e=this;return b([],t).map((function(t,n){"string"!=typeof t&&"number"!=typeof t||(t={value:t});var i=e.dropdown.getMappedValue(t);return i="string"==typeof i&&e.settings.dropdown.escapeHTML?v(i):i,e.settings.templates.dropdownItem.apply(e,[k(C({},t),{mappedValue:i}),e])})).join("")}};function j(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function P(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function V(t){return function(t){if(Array.isArray(t))return j(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return j(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return j(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function R(){for(var t in this.dropdown={},this._dropdown)this.dropdown[t]="function"==typeof this._dropdown[t]?this._dropdown[t].bind(this):this._dropdown[t];this.dropdown.refs(),this.DOM.dropdown.__tagify=this}var F,H,B,U=(F=function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter((function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable})))),i.forEach((function(e){P(t,e,n[e])}))}return t}({},L),H=null!=(H={refs:function(){this.DOM.dropdown=this.parseTemplate("dropdown",[this.settings]),this.DOM.dropdown.content=this.DOM.dropdown.querySelector("[data-selector='tagify-suggestions-wrapper']")},getHeaderRef:function(){return this.DOM.dropdown.querySelector("[data-selector='tagify-suggestions-header']")},getFooterRef:function(){return this.DOM.dropdown.querySelector("[data-selector='tagify-suggestions-footer']")},getAllSuggestionsRefs:function(){return V(this.DOM.dropdown.content.querySelectorAll(this.settings.classNames.dropdownItemSelector))},show:function(t){var e,n,i,s=this,a=this.settings,o="mix"==a.mode&&!a.enforceWhitelist,r=!a.whitelist||!a.whitelist.length,l="manual"==a.dropdown.position;if(t=void 0===t?this.state.inputText:t,!(r&&!o&&!a.templates.dropdownItemNoMatch||!1===a.dropdown.enable||this.state.isLoading||this.settings.readonly)){if(clearTimeout(this.dropdownHide__bindEventsTimeout),this.suggestedListItems=this.dropdown.filterListItems(t),t&&!this.suggestedListItems.length&&(this.trigger("dropdown:noMatch",t),a.templates.dropdownItemNoMatch&&(i=a.templates.dropdownItemNoMatch.call(this,{value:t}))),!i){if(this.suggestedListItems.length)t&&o&&!this.state.editing.scope&&!u(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();this.suggestedListItems=[{value:t}]}n=""+(y(e=this.suggestedListItems[0])?e.value:e),a.autoComplete&&n&&0==n.indexOf(t)&&this.input.autocomplete.suggest.call(this,e)}this.dropdown.fill(i),a.dropdown.highlightFirst&&this.dropdown.highlightOption(this.DOM.dropdown.content.querySelector(a.classNames.dropdownItemSelector)),this.state.dropdown.visible||setTimeout(this.dropdown.events.binding.bind(this)),this.state.dropdown.visible=t||!0,this.state.dropdown.query=t,this.setStateSelection(),l||setTimeout((function(){s.dropdown.position(),s.dropdown.render()})),setTimeout((function(){s.trigger("dropdown:show",s.DOM.dropdown)}))}},hide:function(t){var e=this,n=this.DOM,i=n.scope,s=n.dropdown,a="manual"==this.settings.dropdown.position&&!t;if(s&&document.body.contains(s)&&!a)return window.removeEventListener("resize",this.dropdown.position),this.dropdown.events.binding.call(this,!1),i.setAttribute("aria-expanded",!1),s.parentNode.removeChild(s),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",s),this},toggle:function(t){this.dropdown[this.state.dropdown.visible&&!t?"hide":"show"]()},getAppendTarget:function(){var t=this.settings.dropdown;return"function"==typeof t.appendTarget?t.appendTarget():t.appendTarget},render:function(){var t,e,n,i=this,s=(t=this.DOM.dropdown,(n=t.cloneNode(!0)).style.cssText="position:fixed; top:-9999px; opacity:0",document.body.appendChild(n),e=n.clientHeight,n.parentNode.removeChild(n),e),a=this.settings,o="number"==typeof a.dropdown.enabled&&a.dropdown.enabled>=0,r=this.dropdown.getAppendTarget();return o?(this.DOM.scope.setAttribute("aria-expanded",!0),document.body.contains(this.DOM.dropdown)||(this.DOM.dropdown.classList.add(a.classNames.dropdownInital),this.dropdown.position(s),r.appendChild(this.DOM.dropdown),setTimeout((function(){return i.DOM.dropdown.classList.remove(a.classNames.dropdownInital)}))),this):this},fill:function(t){t="string"==typeof t?t:this.dropdown.createListHTML(t||this.suggestedListItems);var e,n=this.settings.templates.dropdownContent.call(this,t);this.DOM.dropdown.content.innerHTML=(e=n)?e.replace(/\>[\r\n ]+\</g,"><").split(/>\s+</).join("><").trim():""},fillHeaderFooter:function(){var t=this.dropdown.filterListItems(this.state.dropdown.query),e=this.parseTemplate("dropdownHeader",[t]),n=this.parseTemplate("dropdownFooter",[t]),i=this.dropdown.getHeaderRef(),s=this.dropdown.getFooterRef();e&&(null==i||i.parentNode.replaceChild(e,i)),n&&(null==s||s.parentNode.replaceChild(n,s))},position:function(t){var e=this.settings.dropdown,n=this.dropdown.getAppendTarget();if("manual"!=e.position&&n){var i,s,a,o,r,l,d,c,u,g=this.DOM.dropdown,h=e.RTL,p=n===document.body,f=n===this.DOM.scope,m=p?window.pageYOffset:n.scrollTop,v=document.fullscreenElement||document.webkitFullscreenElement||document.documentElement,y=v.clientHeight,b=Math.max(v.clientWidth||0,window.innerWidth||0)>480?e.position:"all",w=this.DOM["input"==b?"input":"scope"];if(t=t||g.clientHeight,this.state.dropdown.visible){if("text"==b?(a=(i=function(){var t=document.getSelection();if(t.rangeCount){var e,n,i=t.getRangeAt(0),s=i.startContainer,a=i.startOffset;if(a>0)return(n=document.createRange()).setStart(s,a-1),n.setEnd(s,a),{left:(e=n.getBoundingClientRect()).right,top:e.top,bottom:e.bottom};if(s.getBoundingClientRect)return s.getBoundingClientRect()}return{left:-9999,top:-9999}}()).bottom,s=i.top,o=i.left,r="auto"):(l=function(t){var e=0,n=0;for(t=t.parentNode;t&&t!=v;)e+=t.offsetTop||0,n+=t.offsetLeft||0,t=t.parentNode;return{top:e,left:n}}(n),i=w.getBoundingClientRect(),s=f?-1:i.top-l.top,a=(f?i.height:i.bottom-l.top)-1,o=f?-1:i.left-l.left,r=i.width+"px"),!p){var T=function(){for(var t=0,n=e.appendTarget.parentNode;n;)t+=n.scrollTop||0,n=n.parentNode;return t}();s+=T,a+=T}var O;s=Math.floor(s),a=Math.ceil(a),c=((d=null!==(O=e.placeAbove)&&void 0!==O?O:y-i.bottom<t)?s:a)+m,u="left: ".concat(o+(h&&i.width||0)+window.pageXOffset,"px;"),g.style.cssText="".concat(u,"; top: ").concat(c,"px; min-width: ").concat(r,"; max-width: ").concat(r),g.setAttribute("placement",d?"top":"bottom"),g.setAttribute("position",b)}}}})?H:{},Object.getOwnPropertyDescriptors?Object.defineProperties(F,Object.getOwnPropertyDescriptors(H)):function(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}(Object(H)).forEach((function(t){Object.defineProperty(F,t,Object.getOwnPropertyDescriptor(H,t))})),F),W="@yaireo/tagify/",K={empty:"empty",exceed:"number of tags exceeded",pattern:"pattern mismatch",duplicate:"already exists",notAllowed:"not allowed"},q={wrapper:function(t,e){return'<tags class="'.concat(e.classNames.namespace," ").concat(e.mode?"".concat(e.classNames[e.mode+"Mode"]):""," ").concat(t.className,'"\n ').concat(e.readonly?"readonly":"","\n ").concat(e.disabled?"disabled":"","\n ").concat(e.required?"required":"","\n ").concat("select"===e.mode?"spellcheck='false'":"",'\n tabIndex="-1">\n ').concat(this.settings.templates.input.call(this),"\n ").concat(r,"\n </tags>")},input:function(){var t=this.settings,e=t.placeholder||r;return"<span ".concat(!t.readonly&&t.userInput?"contenteditable":"",' tabIndex="0" data-placeholder="').concat(e,'" aria-placeholder="').concat(t.placeholder||"",'"\n class="').concat(t.classNames.input,'"\n role="textbox"\n autocapitalize="false"\n autocorrect="off"\n spellcheck="false"\n aria-autocomplete="both"\n aria-multiline="').concat("mix"==t.mode,'"></span>')},tag:function(t,e){var n=e.settings;return'<tag title="'.concat(t.title||t.value,"\"\n contenteditable='false'\n tabIndex=\"").concat(n.a11y.focusableTags?0:-1,'"\n class="').concat(n.classNames.tag," ").concat(t.class||"",'"\n ').concat(this.getAttributes(t),">\n <x title='' tabIndex=\"").concat(n.a11y.focusableTags?0:-1,'" class="').concat(n.classNames.tagX,"\" role='button' aria-label='remove tag'></x>\n <div>\n <span ").concat("select"===n.mode&&n.userInput?"contenteditable='true'":"",' autocapitalize="false" autocorrect="off" spellcheck=\'false\' class="').concat(n.classNames.tagText,'">').concat(t[n.tagTextProp]||t.value,"</span>\n </div>\n </tag>")},dropdown:function(t){var e=t.dropdown,n="manual"==e.position;return'<div class="'.concat(n?"":t.classNames.dropdown," ").concat(e.classname,'" role="listbox" aria-labelledby="dropdown" dir="').concat(e.RTL?"rtl":"","\">\n <div data-selector='tagify-suggestions-wrapper' class=\"").concat(t.classNames.dropdownWrapper,'"></div>\n </div>')},dropdownContent:function(t){var e=this.settings.templates,n=this.state.dropdown.suggestions;return"\n ".concat(e.dropdownHeader.call(this,n),"\n ").concat(t,"\n ").concat(e.dropdownFooter.call(this,n),"\n ")},dropdownItem:function(t){return"<div ".concat(this.getAttributes(t),"\n class='").concat(this.settings.classNames.dropdownItem," ").concat(this.isTagDuplicate(t.value)?this.settings.classNames.dropdownItemSelected:""," ").concat(t.class||"",'\'\n tabindex="0"\n role="option">').concat(t.mappedValue||t.value,"</div>")},dropdownHeader:function(t){return"<header data-selector='tagify-suggestions-header' class=\"".concat(this.settings.classNames.dropdownHeader,'"></header>')},dropdownFooter:function(t){var e=t.length-this.settings.dropdown.maxItems;return e>0?"<footer data-selector='tagify-suggestions-footer' class=\"".concat(this.settings.classNames.dropdownFooter,'">\n ').concat(e," more items. Refine your search.\n </footer>"):""},dropdownItemNoMatch:null};function z(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function X(t,e){return null!=e&&"undefined"!=typeof Symbol&&e[Symbol.hasInstance]?!!e[Symbol.hasInstance](t):t instanceof e}function J(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var i,s,a=[],o=!0,r=!1;try{for(n=n.call(t);!(o=(i=n.next()).done)&&(a.push(i.value),!e||a.length!==e);o=!0);}catch(t){r=!0,s=t}finally{try{o||null==n.return||n.return()}finally{if(r)throw s}}return a}}(t,e)||function(t,e){if(!t)return;if("string"==typeof t)return z(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return z(t,e)}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function G(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function $(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Q(t,e){return null!=e&&"undefined"!=typeof Symbol&&e[Symbol.hasInstance]?!!e[Symbol.hasInstance](t):t instanceof e}function Y(t,e){return e=null!=e?e:{},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):function(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}(Object(e)).forEach((function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n))})),t}function Z(t){return function(t){if(Array.isArray(t))return G(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return G(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return G(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var tt={customBinding:function(){var t=this;this.customEventsList.forEach((function(e){t.on(e,t.settings.callbacks[e])}))},binding:function(){var t,e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],n=this.settings,i=this.events.callbacks,s=e?"addEventListener":"removeEventListener";if(!this.state.mainEvents||!e){for(var a in this.state.mainEvents=e,e&&!this.listeners.main&&(this.events.bindGlobal.call(this),this.settings.isJQueryPlugin&&jQuery(this.DOM.originalInput).on("tagify.removeAllTags",this.removeAllTags.bind(this))),t=this.listeners.main=this.listeners.main||{keydown:["input",i.onKeydown.bind(this)],click:["scope",i.onClickScope.bind(this)],dblclick:"select"!=n.mode&&["scope",i.onDoubleClickScope.bind(this)],paste:["input",i.onPaste.bind(this)],drop:["input",i.onDrop.bind(this)],compositionstart:["input",i.onCompositionStart.bind(this)],compositionend:["input",i.onCompositionEnd.bind(this)]})t[a]&&this.DOM[t[a][0]][s](a,t[a][1]);var o=this.listeners.main.inputMutationObserver||new MutationObserver(i.onInputDOMChange.bind(this));o.disconnect(),"mix"==n.mode&&o.observe(this.DOM.input,{childList:!0}),this.events.bindOriginaInputListener.call(this)}},bindOriginaInputListener:function(t){var e=(t||0)+500;this.listeners.main&&(clearInterval(this.listeners.main.originalInputValueObserverInterval),this.listeners.main.originalInputValueObserverInterval=setInterval(this.events.callbacks.observeOriginalInputValue.bind(this),e))},bindGlobal:function(t){var e,n=this.events.callbacks,i=t?"removeEventListener":"addEventListener";if(this.listeners&&(t||!this.listeners.global)){this.listeners.global=this.listeners.global||[{type:this.isIE?"keydown":"input",target:this.DOM.input,cb:n[this.isIE?"onInputIE":"onInput"].bind(this)},{type:"keydown",target:window,cb:n.onWindowKeyDown.bind(this)},{type:"focusin",target:this.DOM.scope,cb:n.onFocusBlur.bind(this)},{type:"focusout",target:this.DOM.scope,cb:n.onFocusBlur.bind(this)},{type:"click",target:document,cb:n.onClickAnywhere.bind(this),useCapture:!0}];var s=!0,a=!1,o=void 0;try{for(var r,l=this.listeners.global[Symbol.iterator]();!(s=(r=l.next()).done);s=!0)(e=r.value).target[i](e.type,e.cb,!!e.useCapture)}catch(t){a=!0,o=t}finally{try{s||null==l.return||l.return()}finally{if(a)throw o}}}},unbindGlobal:function(){this.events.bindGlobal.call(this,!0)},callbacks:{onFocusBlur:function(t){var e,n,i=this.settings,s=S.call(this,t.target),a=x.call(this,t.target),o=t.target.classList.contains(i.classNames.tagX),r="focusin"==t.type,l="focusout"==t.type;s&&r&&!a&&!o&&this.toggleFocusClass(this.state.hasFocus=+new Date);var d=t.target?this.trim(this.DOM.input.textContent):"",c=null===(n=this.value)||void 0===n||null===(e=n[0])||void 0===e?void 0:e[i.tagTextProp],u=i.dropdown.enabled>=0,g={relatedTarget:t.relatedTarget},h=this.state.actions.selectOption&&(u||!i.dropdown.closeOnSelect),p=this.state.actions.addNew&&u;if(l){if(t.relatedTarget===this.DOM.scope)return this.dropdown.hide(),void this.DOM.input.focus();this.postUpdate(),i.onChangeAfterBlur&&this.triggerChangeEvent()}if(!(h||p||o))if(r||s?(this.state.hasFocus=+new Date,this.toggleFocusClass(this.state.hasFocus)):this.state.hasFocus=!1,"mix"!=i.mode){if(r){if(!i.focusable)return;var f=0===i.dropdown.enabled&&!this.state.dropdown.visible;return this.toggleFocusClass(!0),this.trigger("focus",g),void(!f||a&&"select"!==i.mode||this.dropdown.show(this.value.length?"":void 0))}if(l){if(this.trigger("blur",g),this.loading(!1),"select"==i.mode){if(this.value.length){var m=this.getTagElms()[0];d=this.trim(m.textContent)}c===d&&(d="")}d&&!this.state.actions.selectOption&&i.addTagOnBlur&&i.addTagOn.includes("blur")&&this.addTags(d,!0)}s||(this.DOM.input.removeAttribute("style"),this.dropdown.hide())}else r?this.trigger("focus",g):l&&(this.trigger("blur",g),this.loading(!1),this.dropdown.hide(),this.state.dropdown.visible=void 0,this.setStateSelection())},onCompositionStart:function(t){this.state.composing=!0},onCompositionEnd:function(t){this.state.composing=!1},onWindowKeyDown:function(t){var e,n=this.settings,i=document.activeElement,s=S.call(this,i)&&this.DOM.scope.contains(document.activeElement),a=s&&i.hasAttribute("readonly");if(this.state.hasFocus||s&&!a){e=i.nextElementSibling;var o=t.target.classList.contains(n.classNames.tagX);switch(t.key){case"Backspace":n.readonly||this.state.editing||(this.removeTags(i),(e||this.DOM.input).focus());break;case"Enter":if(o)return void this.removeTags(t.target.parentNode);n.a11y.focusableTags&&x.call(this,i)&&setTimeout(this.editTag.bind(this),0,i);break;case"ArrowDown":this.state.dropdown.visible||"mix"==n.mode||this.dropdown.show()}}},onKeydown:function(t){var e=this,n=this.settings;if(!this.state.composing&&n.userInput){"select"==n.mode&&n.enforceWhitelist&&this.value.length&&"Tab"!=t.key&&t.preventDefault();var i=this.trim(t.target.textContent);this.trigger("keydown",{event:t}),n.hooks.beforeKeyDown(t,{tagify:this}).then((function(s){if("mix"==n.mode){switch(t.key){case"Left":case"ArrowLeft":e.state.actions.ArrowLeft=!0;break;case"Delete":case"Backspace":if(e.state.editing)return;var a=document.getSelection(),o="Delete"==t.key&&a.anchorOffset==(a.anchorNode.length||0),r=a.anchorNode.previousSibling,l=1==a.anchorNode.nodeType||!a.anchorOffset&&r&&1==r.nodeType&&a.anchorNode.previousSibling;p(e.DOM.input.innerHTML);var d,c,u,g=e.getTagElms(),h=1===a.anchorNode.length&&a.anchorNode.nodeValue==String.fromCharCode(8203);if("edit"==n.backspace&&l)return d=1==a.anchorNode.nodeType?null:a.anchorNode.previousElementSibling,setTimeout(e.editTag.bind(e),0,d),void t.preventDefault();if(O()&&Q(l,Element))return u=m(l),l.hasAttribute("readonly")||l.remove(),e.DOM.input.focus(),void setTimeout((function(){M(u),e.DOM.input.click()}));if("BR"==a.anchorNode.nodeName)return;if((o||l)&&1==a.anchorNode.nodeType?c=0==a.anchorOffset?o?g[0]:null:g[Math.min(g.length,a.anchorOffset)-1]:o?c=a.anchorNode.nextElementSibling:Q(l,Element)&&(c=l),3==a.anchorNode.nodeType&&!a.anchorNode.nodeValue&&a.anchorNode.previousElementSibling&&t.preventDefault(),(l||o)&&!n.backspace)return void t.preventDefault();if("Range"!=a.type&&!a.anchorOffset&&a.anchorNode==e.DOM.input&&"Delete"!=t.key)return void t.preventDefault();if("Range"!=a.type&&c&&c.hasAttribute("readonly"))return void M(m(c));"Delete"==t.key&&h&&I(a.anchorNode.nextSibling)&&e.removeTags(a.anchorNode.nextSibling),clearTimeout(B),B=setTimeout((function(){var t=document.getSelection();p(e.DOM.input.innerHTML),!o&&t.anchorNode.previousSibling,e.value=[].map.call(g,(function(t,n){var i=I(t);if(t.parentNode||i.readonly)return i;e.trigger("remove",{tag:t,index:n,data:i})})).filter((function(t){return t}))}),20)}return!0}var f="manual"==n.dropdown.position;switch(t.key){case"Backspace":"select"==n.mode&&n.enforceWhitelist&&e.value.length?e.removeTags():e.state.dropdown.visible&&"manual"!=n.dropdown.position||""!=t.target.textContent&&8203!=i.charCodeAt(0)||(!0===n.backspace?e.removeTags():"edit"==n.backspace&&setTimeout(e.editTag.bind(e),0));break;case"Esc":case"Escape":if(e.state.dropdown.visible)return;t.target.blur();break;case"Down":case"ArrowDown":e.state.dropdown.visible||e.dropdown.show();break;case"ArrowRight":var v=e.state.inputSuggestion||e.state.ddItemData;if(v&&n.autoComplete.rightKey)return void e.addTags([v],!0);break;case"Tab":var y="select"==n.mode;if(!i||y)return!0;t.preventDefault();case"Enter":if(e.state.dropdown.visible&&!f)return;t.preventDefault(),setTimeout((function(){e.state.dropdown.visible&&!f||e.state.actions.selectOption||!n.addTagOn.includes(t.key.toLowerCase())||e.addTags(i,!0)}))}})).catch((function(t){return t}))}},onInput:function(t){this.postUpdate();var e=this.settings;if("mix"==e.mode)return this.events.callbacks.onMixTagsInput.call(this,t);var n=this.input.normalize.call(this,void 0,{trim:!1}),i=n.length>=e.dropdown.enabled,s={value:n,inputElm:this.DOM.input},a=this.validateTag({value:n});"select"==e.mode&&this.toggleScopeValidation(a),s.isValid=a,this.state.inputText!=n&&(this.input.set.call(this,n,!1),-1!=n.search(e.delimiters)?this.addTags(n)&&this.input.set.call(this):e.dropdown.enabled>=0&&this.dropdown[i?"show":"hide"](n),this.trigger("input",s))},onMixTagsInput:function(t){var e,n,i,s,a,o,r,l,d=this,c=this.settings,u=this.value.length,g=this.getTagElms(),h=document.createDocumentFragment(),p=window.getSelection().getRangeAt(0),f=[].map.call(g,(function(t){return I(t).value}));if("deleteContentBackward"==t.inputType&&O()&&this.events.callbacks.onKeydown.call(this,{target:t.target,key:"Backspace"}),N(this.getTagElms()),this.value.slice().forEach((function(t){t.readonly&&!f.includes(t.value)&&h.appendChild(d.createTagElem(t))})),h.childNodes.length&&(p.insertNode(h),this.setRangeAtStartEnd(!1,h.lastChild)),g.length!=u)return this.value=[].map.call(this.getTagElms(),(function(t){return I(t)})),void this.update({withoutChangeEvent:!0});if(this.hasMaxTags())return!0;if(window.getSelection&&(o=window.getSelection()).rangeCount>0&&3==o.anchorNode.nodeType){if((p=o.getRangeAt(0).cloneRange()).collapse(!0),p.setStart(o.focusNode,0),i=(e=p.toString().slice(0,p.endOffset)).split(c.pattern).length-1,(n=e.match(c.pattern))&&(s=e.slice(e.lastIndexOf(n[n.length-1]))),s){if(this.state.actions.ArrowLeft=!1,this.state.tag={prefix:s.match(c.pattern)[0],value:s.replace(c.pattern,"")},this.state.tag.baseOffset=o.baseOffset-this.state.tag.value.length,l=this.state.tag.value.match(c.delimiters))return this.state.tag.value=this.state.tag.value.replace(c.delimiters,""),this.state.tag.delimiters=l[0],this.addTags(this.state.tag.value,c.dropdown.clearOnSelect),void this.dropdown.hide();a=this.state.tag.value.length>=c.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||i<this.state.mixMode.matchedPatternCount)&&(a=!1)}else this.state.flaggedTags={};this.state.mixMode.matchedPatternCount=i}setTimeout((function(){d.update({withoutChangeEvent:!0}),d.trigger("input",b({},d.state.tag,{textContent:d.DOM.input.textContent})),d.state.tag&&d.dropdown[a?"show":"hide"](d.state.tag.value)}),10)},onInputIE:function(t){var e=this;setTimeout((function(){e.events.callbacks.onInput.call(e,t)}))},observeOriginalInputValue:function(){this.DOM.originalInput.parentNode||this.destroy(),this.DOM.originalInput.value!=this.DOM.originalInput.tagifyValue&&this.loadOriginalValues()},onClickAnywhere:function(t){t.target==this.DOM.scope||this.DOM.scope.contains(t.target)||(this.toggleFocusClass(!1),this.state.hasFocus=!1,t.target.closest(".tagify__dropdown")&&t.target.closest(".tagify__dropdown").__tagify!=this&&this.dropdown.hide())},onClickScope:function(t){var e=this.settings,n=t.target.closest("."+e.classNames.tag),i=t.target===this.DOM.scope,s=+new Date-this.state.hasFocus;if(i&&"select"!=e.mode)this.DOM.input.focus();else{if(!t.target.classList.contains(e.classNames.tagX))return n&&!this.state.editing?(this.trigger("click",{tag:n,index:this.getNodeIndex(n),data:I(n),event:t}),void(1!==e.editTags&&1!==e.editTags.clicks&&"select"!=e.mode||this.events.callbacks.onDoubleClickScope.call(this,t))):void(t.target==this.DOM.input&&("mix"==e.mode&&this.fixFirefoxLastTagNoCaret(),s>500||!e.focusable)?this.state.dropdown.visible?this.dropdown.hide():0===e.dropdown.enabled&&"mix"!=e.mode&&this.dropdown.show(this.value.length?"":void 0):"select"!=e.mode||0!==e.dropdown.enabled||this.state.dropdown.visible||(this.events.callbacks.onDoubleClickScope.call(this,Y(function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter((function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable})))),i.forEach((function(e){$(t,e,n[e])}))}return t}({},t),{target:this.getTagElms()[0]})),!e.userInput&&this.dropdown.show()));this.removeTags(t.target.parentNode)}},onPaste:function(t){var e=this;t.preventDefault();var n,i,s,a=this.settings;if("select"==a.mode&&a.enforceWhitelist||!a.userInput)return!1;a.readonly||(i=t.clipboardData||window.clipboardData,s=i.getData("Text"),a.hooks.beforePaste(t,{tagify:this,pastedText:s,clipboardData:i}).then((function(a){void 0===a&&(a=s),a&&(e.injectAtCaret(a,window.getSelection().getRangeAt(0)),"mix"==e.settings.mode?e.events.callbacks.onMixTagsInput.call(e,t):e.settings.pasteAsTags?n=e.addTags(e.state.inputText+a,!0):(e.state.inputText=a,e.dropdown.show(a))),e.trigger("paste",{event:t,pastedText:s,clipboardData:i,tagsElems:n})})).catch((function(t){return t})))},onDrop:function(t){t.preventDefault()},onEditTagInput:function(t,e){var n,i=t.closest("."+this.settings.classNames.tag),s=this.getNodeIndex(i),a=I(i),o=this.input.normalize.call(this,t),r=($(n={},this.settings.tagTextProp,o),$(n,"__tagId",a.__tagId),n),l=this.validateTag(r);this.editTagChangeDetected(b(a,r))||!0!==t.originalIsValid||(l=!0),i.classList.toggle(this.settings.classNames.tagInvalid,!0!==l),a.__isValid=l,i.title=!0===l?a.title||a.value:l,o.length>=this.settings.dropdown.enabled&&(this.state.editing&&(this.state.editing.value=o),this.dropdown.show(o)),this.trigger("edit:input",{tag:i,index:s,data:b({},this.value[s],{newValue:o}),event:e})},onEditTagPaste:function(t,e){var n=(e.clipboardData||window.clipboardData).getData("Text");e.preventDefault();var i=E(n);this.setRangeAtStartEnd(!1,i)},onEditTagClick:function(t,e){this.events.callbacks.onClickScope.call(this,e)},onEditTagFocus:function(t){this.state.editing={scope:t,input:t.querySelector("[contenteditable]")}},onEditTagBlur:function(t,e){var n=x.call(this,e.relatedTarget);if("select"==this.settings.mode&&n&&e.relatedTarget.contains(e.target))this.dropdown.hide();else if(this.state.editing&&(this.state.hasFocus||this.toggleFocusClass(),this.DOM.scope.contains(t))){var i,s,a,o=this.settings,r=t.closest("."+o.classNames.tag),l=I(r),d=this.input.normalize.call(this,t),c=($(i={},o.tagTextProp,d),$(i,"__tagId",l.__tagId),i),u=l.__originalData,g=this.editTagChangeDetected(b(l,c)),h=this.validateTag(c);if(d)if(g){var p;if(s=this.hasMaxTags(),a=b({},u,($(p={},o.tagTextProp,this.trim(d)),$(p,"__isValid",h),p)),o.transformTag.call(this,a,u),!0!==(h=(!s||!0===u.__isValid)&&this.validateTag(a))){if(this.trigger("invalid",{data:a,tag:r,message:h}),o.editTags.keepInvalid)return;o.keepInvalidTags?a.__isValid=h:a=u}else o.keepInvalidTags&&(delete a.title,delete a["aria-invalid"],delete a.class);this.onEditTagDone(r,a)}else this.onEditTagDone(r,u);else this.onEditTagDone(r)}},onEditTagkeydown:function(t,e){if(!this.state.composing)switch(this.trigger("edit:keydown",{event:t}),t.key){case"Esc":case"Escape":this.state.editing=!1,!!e.__tagifyTagData.__originalData.value?e.parentNode.replaceChild(e.__tagifyTagData.__originalHTML,e):e.remove();break;case"Enter":case"Tab":t.preventDefault();setTimeout((function(){return t.target.blur()}),0)}},onDoubleClickScope:function(t){var e,n,i=t.target.closest("."+this.settings.classNames.tag),s=I(i),a=this.settings;i&&!1!==s.editable&&(e=i.classList.contains(this.settings.classNames.tagEditing),n=i.hasAttribute("readonly"),a.readonly||e||n||!this.settings.editTags||!a.userInput||(this.events.callbacks.onEditTagFocus.call(this,i),this.editTag(i)),this.toggleFocusClass(!0),"select"!=a.mode&&this.trigger("dblclick",{tag:i,index:this.getNodeIndex(i),data:I(i)}))},onInputDOMChange:function(t){var e=this;t.forEach((function(t){t.addedNodes.forEach((function(t){if("<div><br></div>"==t.outerHTML)t.replaceWith(document.createElement("br"));else if(1==t.nodeType&&t.querySelector(e.settings.classNames.tagSelector)){var n,i=document.createTextNode("");3==t.childNodes[0].nodeType&&"BR"!=t.previousSibling.nodeName&&(i=document.createTextNode("\n")),(n=t).replaceWith.apply(n,Z([i].concat(Z(Z(t.childNodes).slice(0,-1))))),M(i)}else if(x.call(e,t)){var s;if(3!=(null===(s=t.previousSibling)||void 0===s?void 0:s.nodeType)||t.previousSibling.textContent||t.previousSibling.remove(),t.previousSibling&&"BR"==t.previousSibling.nodeName){t.previousSibling.replaceWith("\n");for(var a=t.nextSibling,o="";a;)o+=a.textContent,a=a.nextSibling;o.trim()&&M(t.previousSibling)}else t.previousSibling&&!I(t.previousSibling)||t.before("")}})),t.removedNodes.forEach((function(t){t&&"BR"==t.nodeName&&x.call(e,n)&&(e.removeTags(n),e.fixFirefoxLastTagNoCaret())}))}));var n=this.DOM.input.lastChild;n&&""==n.nodeValue&&n.remove(),n&&"BR"==n.nodeName||this.DOM.input.appendChild(document.createElement("br"))}}};function et(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function nt(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function it(t,e){return null!=e&&"undefined"!=typeof Symbol&&e[Symbol.hasInstance]?!!e[Symbol.hasInstance](t):t instanceof e}function st(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter((function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable})))),i.forEach((function(e){nt(t,e,n[e])}))}return t}function at(t){return function(t){if(Array.isArray(t))return et(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return et(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return et(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ot(t,e){if(!t){c.warn("input element not found",t);var n=new Proxy(this,{get:function(){return function(){return n}}});return n}if(t.__tagify)return c.warn("input element is already Tagified - Same instance is returned.",t),t.__tagify;var i;b(this,function(t){var e=document.createTextNode(""),n={};function i(t,n,i){i&&n.split(/\s+/g).forEach((function(n){return e[t+"EventListener"].call(e,n,i)}))}return{removeAllCustomListeners:function(){Object.entries(n).forEach((function(t){var e=J(t,2),n=e[0];e[1].forEach((function(t){return i("remove",n,t)}))})),n={}},off:function(t,e){return t&&(e?i("remove",t,e):t.split(/\s+/g).forEach((function(t){var e;null===(e=n[t])||void 0===e||e.forEach((function(e){return i("remove",t,e)})),delete n[t]}))),this},on:function(t,e){return e&&"function"==typeof e&&(t.split(/\s+/g).forEach((function(t){Array.isArray(n[t])?n[t].push(e):n[t]=[e]})),i("add",t,e)),this},trigger:function(n,i,s){var a;if(s=s||{cloneData:!0},n)if(t.settings.isJQueryPlugin)"remove"==n&&(n="removeTag"),jQuery(t.DOM.originalInput).triggerHandler(n,[i]);else{try{var o="object"==typeof i?i:{value:i};if((o=s.cloneData?b({},o):o).tagify=this,i.event&&(o.event=this.cloneEvent(i.event)),X(i,Object))for(var r in i)X(i[r],HTMLElement)&&(o[r]=i[r]);a=new CustomEvent(n,{detail:o})}catch(t){c.warn(t)}e.dispatchEvent(a)}}}}(this)),this.isFirefox=/firefox|fxios/i.test(navigator.userAgent)&&!/seamonkey/i.test(navigator.userAgent),this.isIE=window.document.documentMode,e=e||{},this.getPersistedData=(i=e.id,function(t){var e,n="/"+t;if(1==localStorage.getItem(W+i+"/v",1))try{e=JSON.parse(localStorage[W+i+n])}catch(t){}return e}),this.setPersistedData=function(t){return t?(localStorage.setItem(W+t+"/v",1),function(e,n){var i="/"+n,s=JSON.stringify(e);e&&n&&(localStorage.setItem(W+t+i,s),dispatchEvent(new Event("storage")))}):function(){}}(e.id),this.clearPersistedData=function(t){r