Просмотр файла public/assets/js/bootstrap-tags.min.js

Размер файла: 21.09Kb
var k={items:[],allowNew:!1,showAllSuggestions:!1,badgeStyle:"primary",allowClear:!1,clearEnd:!1,selected:[],regex:"",separator:[],max:0,clearLabel:"Clear",searchLabel:"Type a value",showDropIcon:!0,keepOpen:!1,allowSame:!1,baseClass:"",placeholder:"",addOnBlur:!1,showDisabled:!1,hideNativeValidation:!1,suggestionsThreshold:-1,maximumItems:0,autoselectFirst:!0,updateOnSelect:!1,highlightTyped:!1,fullWidth:!0,fixed:!1,fuzzy:!1,singleBadge:!1,activeClasses:["bg-primary","text-white"],labelField:"label",valueField:"value",searchFields:["label"],queryParam:"query",server:"",serverMethod:"GET",serverParams:{},serverDataKey:"data",fetchOptions:{},liveServer:!1,noCache:!0,debounceTime:300,notFoundMessage:"",onRenderItem:(o,t,e)=>t,onSelectItem:(o,t)=>{},onClearItem:(o,t)=>{},onCreateItem:(o,t)=>{},onBlur:(o,t)=>{},onFocus:(o,t)=>{},onCanAdd:(o,t,e)=>{},onServerResponse:(o,t)=>o.json()},v="tags-",D="is-loading",M="is-active",m="is-invalid",H="is-max-reached",A="show",b="data-value",x="next",I="prev",N="form-control-focus",R="form-placeholder-shown",q="form-control-disabled",C=new WeakMap,z=0,T=window.bootstrap&&window.bootstrap.Tooltip;function j(o,t=300){let e;return(...s)=>{clearTimeout(e),e=setTimeout(()=>{o.apply(this,s)},t)}}function P(o,t=null){let e=f("span");document.body.appendChild(e),e.style.fontSize=t||"inherit",e.style.height="auto",e.style.width="auto",e.style.position="absolute",e.style.whiteSpace="no-wrap",e.innerHTML=o;let s=Math.ceil(e.clientWidth);return document.body.removeChild(e),s}function W(o){return o.normalize("NFD").replace(/[\u0300-\u036f]/g,"")}function O(o){return o?W(o.toString()).toLowerCase():""}function _(o,t){if(o.indexOf(t)>=0)return!0;let e=0;for(let s=0;s<t.length;s++){let i=t[s];if(i!=" "&&(e=o.indexOf(i,e)+1,e<=0))return!1}return!0}function E(o){o.style.display="none",L(o,{"aria-hidden":"true"})}function B(o){o.style.display="list-item",L(o,{"aria-hidden":"false"})}function L(o,t){for(let[e,s]of Object.entries(t))o.setAttribute(e,s)}function S(o,t){o.hasAttribute(t)&&o.removeAttribute(t)}function V(o){return["true","false","1","0",!0,!1].includes(o)&&!!JSON.parse(o)}function f(o){return document.createElement(o)}var y=class{constructor(t,e={}){if(!(t instanceof HTMLElement)){console.error("Invalid element",t);return}C.set(t,this),z++,this.i=t,this.I(e),this.h=!1,this.T=j(()=>{this.S(!0)},this.e.debounceTime),this.d=!0,this.O(),this.n=f("div"),this.r=f("div"),this.l=f("ul"),this.s=f("input"),this.n.appendChild(this.r),this.i.parentElement.insertBefore(this.n,this.i),this.F(),this.k(),this.D(),this.M(),this.H(),this.resetState(),this.handleEvent=s=>{this.N(s)},this.e.fixed&&(document.addEventListener("scroll",this,!0),window.addEventListener("resize",this)),this.s.addEventListener("focus",this),this.s.addEventListener("blur",this),this.s.addEventListener("input",this),this.s.addEventListener("keydown",this),this.l.addEventListener("mousemove",this),this.loadData(!0)}static init(t="select[multiple]",e={}){let s=document.querySelectorAll(t);for(let i=0;i<s.length;i++)y.getInstance(s[i])||new y(s[i],e)}static getInstance(t){if(C.has(t))return C.get(t)}dispose(){this.s.removeEventListener("focus",this),this.s.removeEventListener("blur",this),this.s.removeEventListener("input",this),this.s.removeEventListener("keydown",this),this.l.removeEventListener("mousemove",this),this.e.fixed&&(document.removeEventListener("scroll",this,!0),window.removeEventListener("resize",this)),this.i.style.display="block",this.n.parentElement.removeChild(this.n),this.parentForm&&this.parentForm.removeEventListener("reset",this),C.delete(this.i)}N(t){["scroll","resize"].includes(t.type)?(this.w&&window.cancelAnimationFrame(this.w),this.w=window.requestAnimationFrame(()=>{this[`on${t.type}`](t)})):this[`on${t.type}`](t)}I(t={}){this.e=Object.assign({},k,{showDropIcon:!!this.u()});let e=this.i.dataset.config?JSON.parse(this.i.dataset.config):{},s={...t,...e,...this.i.dataset};for(let[i,r]of Object.entries(k)){if(i=="config"||s[i]===void 0)continue;let n=s[i];switch(typeof r){case"number":this.e[i]=parseInt(n);break;case"boolean":this.e[i]=V(n);break;case"string":this.e[i]=n.toString();break;case"object":this.e[i]=n,typeof n=="string"&&(["{","["].includes(n[0])?this.e[i]=JSON.parse(n):this.e[i]=n.split(n.includes("|")?"|":","));break;case"function":this.e[i]=typeof n=="string"?n.split(".").reduce((l,a)=>l[a],window):n,this.e[i]||console.error("Invalid function",n);break;default:this.e[i]=n;break}}this.e.placeholder||(this.e.placeholder=this.R()),this.e.suggestionsThreshold==-1&&(this.e.suggestionsThreshold=this.e.liveServer?1:0)}config(t=null){return t?this.e[t]:this.e}setConfig(t,e){this.e[t]=e}O(){for(this.overflowParent=null,this.parentForm=this.i.parentElement;this.parentForm&&(this.parentForm.style.overflow==="hidden"&&(this.overflowParent=this.parentForm),this.parentForm=this.parentForm.parentElement,!(this.parentForm&&this.parentForm.nodeName=="FORM")););this.parentForm&&this.parentForm.addEventListener("reset",this)}R(){if(this.i.hasAttribute("placeholder"))return this.i.getAttribute("placeholder");if(this.i.dataset.placeholder)return this.i.dataset.placeholder;let t=this.i.querySelector("option");return!t||!this.e.autoselectFirst?"":(S(t,"selected"),t.selected=!1,t.value?"":t.textContent)}D(){let t=this.i;this.e.hideNativeValidation?(t.style.position="absolute",t.style.left="-9999px"):t.style.cssText="height:1px;width:1px;opacity:0;padding:0;margin:0;border:0;float:left;flex-basis:100%;",t.tabIndex=-1,t.addEventListener("focus",e=>{this.onclick(e)}),t.addEventListener("invalid",e=>{this.n.classList.add(m)})}H(){let t=this.l;t.classList.add("dropdown-menu",v+"menu"),t.id=v+"menu-"+z,t.setAttribute("role","menu");let e=t.style;e.padding="0",e.maxHeight="280px",this.e.fullWidth||(e.maxWidth="360px"),this.e.fixed&&(e.position="fixed"),e.overflowY="auto",e.overscrollBehavior="contain",e.textAlign="unset",t.addEventListener("mouseenter",s=>{this.h=!1}),this.n.appendChild(t),this.s.setAttribute("aria-controls",t.id)}F(){let t=this.n;t.classList.add("form-control","dropdown"),["form-select-lg","form-select-sm"].forEach(e=>{this.i.classList.contains(e)&&t.classList.add(e)}),this.e.suggestionsThreshold==0&&this.e.showDropIcon&&t.classList.add("form-select"),this.overflowParent&&(t.style.position="inherit"),t.style.height="auto",t.addEventListener("click",this)}k(){this.r.addEventListener("click",e=>{this.isDisabled()||this.s.style.visibility!="hidden"&&this.s.focus()});let t=this.r.style;t.display="flex",t.alignItems="center",t.flexWrap="wrap"}M(){let t=this.s;t.type="text",t.autocomplete="field-"+Date.now(),t.spellcheck=!1,L(t,{"aria-auto-complete":"list","aria-has-popup":"menu","aria-expanded":"false","aria-label":this.e.searchLabel,role:"combobox"}),t.style.cssText="background-color:transparent;color:currentColor;border:0;padding:0;outline:0;max-width:100%",this.resetSearchInput(!0),this.r.appendChild(t),this.q=window.getComputedStyle(t).direction==="rtl"}onfocus(t){this.n.classList.add(N),this.showOrSearch(),this.e.onFocus(t,this)}onblur(t){this.o&&this.o.abort();let e=!0;if(this.e.addOnBlur&&this.s.value&&(e=this.L()),this.n.classList.remove(N),this.hideSuggestions(e),this.d){let s=this.getSelection(),i={selection:s?s.dataset.value:null,input:this.s.value};this.e.onBlur(t,this),this.i.dispatchEvent(new CustomEvent("tags.blur",{bubbles:!0,detail:i}))}}oninput(t){let e=this.s.value;if(e){let s=e.slice(-1);if(this.e.separator.length&&this.e.separator.includes(s)){this.s.value=this.s.value.slice(0,-1);let i=this.s.value,r=i,n={};if(this.e.allowNew)n.new=1;else{let l=this.getSelection();if(!l)return;i=l.getAttribute(b),r=l.dataset.label}this.p(r,i,n);return}}setTimeout(()=>{this.a()}),this.showOrSearch()}onkeydown(t){let e=t.keyCode||t.key,s=t.target;switch(t.keyCode==229&&(e=s.value.charAt(s.selectionStart-1).charCodeAt(0)),e){case 13:case"Enter":t.preventDefault(),this.L();break;case 38:case"ArrowUp":t.preventDefault(),this.h=!0,this.m(I);break;case 40:case"ArrowDown":t.preventDefault(),this.h=!0,this.isDropdownVisible()?this.m(x):this.showOrSearch(!1);break;case 8:case"Backspace":this.s.value.length==0&&(this.removeLastItem(),this.a(),this.showOrSearch());break;case 27:case"Escape":this.s.focus(),this.hideSuggestions();break}}onmousemove(t){this.h=!1}onscroll(t){this.g()}onresize(t){this.g()}onclick(t=null){t&&t.preventDefault(),!(!this.isSingle()&&this.isMaxReached())&&this.s.focus()}onreset(t){this.reset()}loadData(t=!1){Object.keys(this.e.items).length>0?this.setData(this.e.items,!0):this.resetSuggestions(!0),this.e.server&&(this.e.liveServer||this.S(!t))}z(){let t=this.i.selectedOptions||[];for(let e=0;e<t.length;e++)t[e].value&&!t[e].hasAttribute("selected")&&t[e].setAttribute("selected","selected")}resetState(){this.isDisabled()?(this.n.setAttribute("readonly",""),this.s.setAttribute("disabled",""),this.n.classList.add(q)):(S(this.n,"readonly"),S(this.s,"disabled"),this.n.classList.remove(q))}resetSuggestions(t=!1){this.z();let e=Array.from(this.i.children).filter(s=>s instanceof HTMLOptGroupElement||!s.disabled||this.e.showDisabled).map(s=>s instanceof HTMLOptGroupElement?{group:s.getAttribute("label"),items:s.children}:{value:s.getAttribute("value"),label:s.textContent,disabled:s.disabled,selected:s.selected,data:Object.assign({disabled:s.disabled},s.dataset)});this.setData(e,t)}L(){let t=this.getSelection();if(t)return t.click(),!0;if(this.e.allowNew&&this.s.value){let e=this.s.value;return!!this.p(e,e,{new:1})}return!1}S(t=!1){this.o&&this.o.abort(),this.o=new AbortController;let e=Object.assign({},this.e.serverParams);if(e[this.e.queryParam]=this.s.value,this.e.noCache&&(e.t=Date.now()),e.related){let n=document.getElementById(e.related);if(n){e.related=n.value;let l=n.getAttribute("name");l&&(e[l]=n.value)}}let s=new URLSearchParams(e),i=this.e.server,r=Object.assign(this.e.fetchOptions,{method:this.e.serverMethod||"GET",signal:this.o.signal});r.method==="POST"?r.body=s:i+="?"+s.toString(),this.n.classList.add(D),fetch(i,r).then(n=>this.e.onServerResponse(n,this)).then(n=>{let l=n[this.e.serverDataKey]||n;this.setData(l,!t),this.o=null,t&&this.b()}).catch(n=>{n.name!=="AbortError"&&console.error(n)}).finally(n=>{this.n.classList.remove(D)})}p(t,e=null,s={}){if(!this.canAdd(t,s))return null;let i=this.addItem(t,e,s);return this.v(),this.e.keepOpen?this.b():this.resetSearchInput(),i}f(t){if(t.style.display==="none")return!1;let e=t.firstElementChild;return e.tagName==="A"&&!e.classList.contains("disabled")}m(t=x,e=null){let s=this.getSelection();if(s){let i=t===x?"nextSibling":"previousSibling";e=s.parentNode;do e=e[i];while(e&&!this.f(e));e?s.classList.remove(...this.c()):s&&(e=s.parentElement)}else{if(t===I)return e;if(!e)for(e=this.l.firstChild;e&&!this.f(e);)e=e.nextSibling}if(e){let i=e.offsetHeight,r=e.offsetTop,n=e.parentNode,l=n.offsetHeight,a=n.scrollHeight,h=n.offsetTop;if(i===0&&setTimeout(()=>{n.scrollTop=0}),t===I){let c=r-h>10?r-h:0;n.scrollTop=c}else r+i-(l+n.scrollTop)>0&&i>0&&(n.scrollTop=r+i-l+1,n.scrollTop+l>=a-10&&(n.scrollTop=r-h));let d=e.querySelector("a");d.classList.add(...this.c()),this.s.setAttribute("aria-activedescendant",d.id),this.e.updateOnSelect&&(this.s.value=d.dataset.label,this.a())}else this.s.setAttribute("aria-activedescendant","");return e}a(){this.n.classList.remove(R),this.s.value?this.s.size=this.s.value.length:this.getSelectedValues().length?(this.s.placeholder="",this.s.size=1):(this.s.size=this.e.placeholder.length>0?this.e.placeholder.length:1,this.s.placeholder=this.e.placeholder,this.n.classList.add(R));let t=this.s.value||this.s.placeholder,e=window.getComputedStyle(this.n).fontSize,s=P(t,e)+16;this.s.style.width=s+"px"}B(t){for(;this.l.lastChild;)this.l.removeChild(this.l.lastChild);let e=0,s=1;for(let i=0;i<t.length;i++){let r=t[i];if(r){if(r.group&&r.items){let n=f("li");n.setAttribute("role","presentation"),n.dataset.id=""+s;let l=f("span");if(n.append(l),l.classList.add("dropdown-header","text-truncate"),l.innerHTML=r.group,this.l.appendChild(n),r.items)for(let a=0;a<r.items.length;a++){let h=r.items[a];h.group_id=s,this.A(r.items[a],e),e++}s++}this.A(r,e),e++}}if(this.e.notFoundMessage){let i=f("li");i.setAttribute("role","presentation"),i.classList.add(v+"not-found"),i.innerHTML='<span class="dropdown-item"></span>',this.l.appendChild(i)}}A(t,e){if(!t[this.e.valueField])return;let s=t[this.e.valueField],i=t[this.e.labelField],r=this.e.onRenderItem(t,i,this),n=f("li");n.setAttribute("role","presentation"),t.group_id&&n.setAttribute("data-group-id",""+t.group_id);let l=f("a");n.append(l),l.id=this.l.id+"-"+e,l.classList.add("dropdown-item","text-truncate"),t.disabled&&l.classList.add("disabled"),l.setAttribute(b,s),l.dataset.label=i,this.e.searchFields.forEach(a=>{n.dataset[a]=t[a]}),l.setAttribute("href","#"),l.innerHTML=r,this.l.appendChild(n),l.addEventListener("mouseenter",a=>{this.h||(this.removeSelection(),n.querySelector("a").classList.add(...this.c()))}),l.addEventListener("mousedown",a=>{a.preventDefault()}),l.addEventListener("click",a=>{a.preventDefault(),a.stopPropagation(),this.p(i,s,t.data),this.e.onSelectItem(t,this)})}initialOptions(){return this.i.querySelectorAll("option[data-init]")}C(){this.i.querySelectorAll("option").forEach(t=>{S(t,"selected")})}reset(){this.removeAll(),this.d=!1;let t=this.initialOptions();this.C();for(let e=0;e<t.length;e++){let s=t[e];this.addItem(s.textContent,s.value,s.dataset)}this.v(),this.d=!0}resetSearchInput(t=!1){this.s.value="",this.a(),t||(this.hideSuggestions(),this.s===document.activeElement&&this.s.dispatchEvent(new Event("input"))),this.isMaxReached()?(this.n.classList.add(H),this.s.style.visibility="hidden"):this.s.style.visibility=="hidden"&&(this.s.style.visibility="visible"),this.isSingle()&&!t&&document.activeElement.blur()}getSelectedValues(){let t=this.i.querySelectorAll("option[selected]");return Array.from(t).map(e=>e.value)}getAvailableValues(){let t=this.i.querySelectorAll("option");return Array.from(t).map(e=>e.value)}showOrSearch(t=!0){if(t&&!this.V()){this.hideSuggestions(!1);return}this.e.liveServer?this.T():this.b()}hideSuggestions(t=!0){this.l.classList.remove(A),L(this.s,{"aria-expanded":"false"}),this.removeSelection(),t&&this.n.classList.remove(m)}toggleSuggestions(t=!0,e=!0){this.l.classList.contains(A)?this.hideSuggestions(e):this.showOrSearch(t)}V(){return this.isDisabled()||this.isMaxReached()?!1:this.s.value.length>=this.e.suggestionsThreshold}b(){if(document.activeElement!=this.s||this.s.style.visibility=="hidden")return;let t=O(this.s.value),e={},s=this.l.querySelectorAll("li"),i=0,r=null,n=!1,l={};for(let a=0;a<s.length;a++){let h=s[a],d=h.firstElementChild;if(d instanceof HTMLSpanElement){h.dataset.id&&(l[h.dataset.id]=!1),E(h);continue}if(d.classList.remove(...this.c()),!this.e.allowSame){let u=d.getAttribute(b);if(e[u]=e[u]||0,this.u(d.getAttribute(b),"[selected]",e[u]++)){E(h);continue}}let c=this.e.showAllSuggestions||t.length===0,g=t.length==0&&this.e.suggestionsThreshold===0;!c&&t.length>0&&this.e.searchFields.forEach(u=>{let p=O(d.dataset[u]);(this.e.fuzzy?_(p,t):p.indexOf(t)>=0)&&(g=!0)});let w=g||t.length===0;if(c||g?(i++,B(h),h.dataset.groupId&&(l[h.dataset.groupId]=!0),!r&&this.f(h)&&w&&(r=h),this.e.maximumItems>0&&i>this.e.maximumItems&&E(h)):E(h),this.e.highlightTyped){let u=d.textContent,p=O(u).indexOf(t),F=u.substring(0,p)+`<mark>${u.substring(p,p+t.length)}</mark>`+u.substring(p+t.length,u.length);d.innerHTML=F}this.f(h)&&(n=!0)}if(!this.e.allowNew&&!(t.length===0&&!n)&&this.n.classList.add(m),this.e.allowNew&&this.e.regex&&this.isInvalid()&&this.n.classList.remove(m),Array.from(s).filter(a=>a.dataset.id).forEach(a=>{l[a.dataset.id]===!0&&B(a)}),n&&(this.n.classList.remove(m),r&&this.e.autoselectFirst&&(this.removeSelection(),this.m(x,r))),i===0)if(this.e.notFoundMessage){let a=this.l.querySelector("."+v+"not-found");a.style.display="block";let h=this.e.notFoundMessage.replace("{{tag}}",this.s.value);a.innerHTML=`<span class="dropdown-item">${h}</span>`,this.E()}else this.hideSuggestions(!1);else this.E()}E(){this.l.classList.add(A),L(this.s,{"aria-expanded":"true"}),this.g()}g(){let t=this.q,e=this.e.fixed,s=this.e.fullWidth,i=this.s.getBoundingClientRect(),r=this.n.getBoundingClientRect(),n=0,l=0;if(e?s?(n=r.x,l=r.y+r.height+2):(n=i.x,l=i.y+i.height):s?(n=0,l=r.height+2):(n=this.s.offsetLeft,l=this.s.offsetHeight+6),t&&!s&&(n-=this.l.offsetWidth-i.width),!s){let d=Math.min(window.innerWidth,document.body.offsetWidth),c=t?i.x+i.width-this.l.offsetWidth-1:d-1-(i.x+this.l.offsetWidth);c<0&&(n=t?n-c:n+c)}s&&(this.l.style.width=this.n.offsetWidth+"px"),Object.assign(this.l.style,{transform:"unset",left:n+"px",top:l+"px"});let a=this.l.getBoundingClientRect(),h=window.innerHeight;if(a.y+a.height>h){let d=s?r.height+4:i.height;this.l.style.transform="translateY(calc(-100.1% - "+d+"px))"}}j(){let t=5;return window.jQuery&&$.fn.tooltip!=null&&$.fn.tooltip.Constructor!=null&&(t=parseInt($.fn.tooltip.Constructor.VERSION.charAt(0))),t}P(t){return!!Array.from(this.i.querySelectorAll("option")).find(s=>s.textContent==t&&s.getAttribute("selected"))}W(t){return!!Array.from(this.i.querySelectorAll("option")).find(s=>s.textContent==t&&!s.getAttribute("selected"))}_(t){return new RegExp(this.e.regex.trim()).test(t)}getSelection(){return this.l.querySelector("a."+M)}removeSelection(){let t=this.getSelection();t&&t.classList.remove(...this.c())}c(){return[...this.e.activeClasses,M]}getActiveSelection(){return this.getSelection()}removeActiveSelection(){return this.removeSelection()}removeAll(){this.getSelectedValues().forEach(e=>{this.removeItem(e,!0)}),this.a()}removeLastItem(t=!1){let e=this.r.querySelectorAll("span."+v+"badge");if(!e.length)return;let s=e[e.length-1];this.removeItem(s.getAttribute(b),t)}enable(){this.i.setAttribute("disabled",""),this.resetState()}disable(){S(this.i,"disabled"),this.resetState()}isDisabled(){return this.i.hasAttribute("disabled")||this.i.disabled||this.i.hasAttribute("readonly")}isDropdownVisible(){return this.l.classList.contains(A)}isInvalid(){return this.n.classList.contains(m)}isSingle(){return!this.i.hasAttribute("multiple")}isMaxReached(){return this.e.max&&this.getSelectedValues().length>=this.e.max}canAdd(t,e={}){if(!t||e.new&&!this.e.allowNew||this.isDisabled())return!1;if(!this.isSingle()&&!this.e.allowSame){if(e.new||this.e.server){if(this.P(t))return!1}else if(!this.W(t))return!1}return this.isMaxReached()?!1:this.e.regex&&e.new&&!this._(t)?(this.n.classList.add(m),!1):this.e.onCanAdd&&this.e.onCanAdd(t,e,this)===!1?(this.n.classList.add(m),!1):!0}setData(t,e=!1){Array.isArray(t)||(t=Object.entries(t).map(([s,i])=>({value:s,label:i}))),e&&(this.C(),t.forEach(s=>{let i=s[this.e.valueField],r=s[this.e.labelField];if(i&&(s.selected||this.e.selected.includes(i))){let n=this.addItem(r,i,s.data);n&&n.setAttribute("data-init","true")}})),this.B(t),this.v()}u(t=null,e="",s=0){let r="option"+(t===null?"":'[value="'+CSS.escape(t)+'"]')+e;return this.i.querySelectorAll(r)[s]||null}addItem(t,e=null,s={}){e||(e=t),this.isSingle()&&this.getSelectedValues().length&&this.removeLastItem(!0);let i=this.u(e,":not([selected])");if(!i){i=f("option"),i.value=e,i.textContent=t;for(let[r,n]of Object.entries(s))i.dataset[r]=n;this.i.appendChild(i),this.e.onCreateItem(i,this)}return i&&(s=Object.assign({title:i.getAttribute("title")},s,i.dataset)),i.setAttribute("selected","selected"),i.selected=!0,this.$(t,e,s),this.d&&this.i.dispatchEvent(new Event("change",{bubbles:!0})),i}v(){let t=this.i.innerHTML;this.i.innerHTML="",this.i.innerHTML=t,this.a()}$(t,e=null,s={}){let i=this.j()===5,r=this.e.allowClear&&!s.disabled,n=t,l=f("span"),a=[v+"badge"],h=this.isSingle()&&!this.e.singleBadge;if(!h){a.push("badge");let c=this.e.badgeStyle;s.badgeStyle&&(c=s.badgeStyle),s.badgeClass&&a.push(...s.badgeClass.split(" ")),this.e.baseClass?a.push(...this.e.baseClass.split(" ")):i?a=[...a,"bg-"+c,"text-truncate"]:a=[...a,"badge-"+c],l.style.maxWidth="100%"}s.disabled&&V(s.disabled)&&a.push("disabled","opacity-50");let d=h?0:2;if(l.style.margin=d+"px 6px "+d+"px 0px",l.style.marginBlock=d+"px",l.style.marginInline="0px 6px",l.classList.add(...a),l.setAttribute(b,e),s.title&&l.setAttribute("title",s.title),r){l.style.display="inline-flex",l.style.alignItems="center";let c=a.includes("text-dark")||h?"btn-close":"btn-close btn-close-white",g="margin-inline: 0px 6px;",w="";this.e.clearEnd&&(g="margin-inline: 6px 0px;",w="order:2;"),n=(i?'<button type="button" style="font-size:0.65em;'+w+g+'" class=" '+c+'" aria-label="'+this.e.clearLabel+'"></button>':'<button type="button" style="font-size:1em;'+w+g+'text-shadow:none;color:currentColor;transform:scale(1.2)" class=" close" aria-label="'+this.e.clearLabel+'"><span aria-hidden="true">&times;</span></button>')+n}l.innerHTML=n,this.r.insertBefore(l,this.s),s.title&&T&&i&&T.getOrCreateInstance(l),r&&l.querySelector("button").addEventListener("click",c=>{c.preventDefault(),c.stopPropagation(),this.isDisabled()||(this.removeItem(e),document.activeElement.blur(),this.a())})}removeItem(t,e=!1){let s=CSS.escape(t),i=this.r.querySelectorAll("span["+b+'="'+s+'"]');if(!i.length)return;let r=i.length-1,n=i[r];n&&(n.dataset.bsOriginalTitle&&T.getOrCreateInstance(n).dispose(),n.remove());let l=this.u(t,"[selected]",r);l&&(S(l,"selected"),l.selected=!1,this.d&&!e&&this.i.dispatchEvent(new Event("change",{bubbles:!0}))),this.s.style.visibility=="hidden"&&!this.isMaxReached()&&(this.s.style.visibility="visible",this.n.classList.remove(H)),e||this.e.onClearItem(t,this)}},G=y;export{G as default};