UNPKG

multiple-select-vanilla

Version:
3 lines (2 loc) 45 kB
"use strict";var T=Object.defineProperty;var tt=Object.getOwnPropertyDescriptor;var et=Object.getOwnPropertyNames;var st=Object.prototype.hasOwnProperty;var it=(o,t,e)=>t in o?T(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var lt=(o,t)=>{for(var e in t)T(o,e,{get:t[e],enumerable:!0})},ot=(o,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of et(t))!st.call(o,l)&&l!==e&&T(o,l,{get:()=>t[l],enumerable:!(s=tt(t,l))||s.enumerable});return o};var nt=o=>ot(T({},"__esModule",{value:!0}),o);var u=(o,t,e)=>(it(o,typeof t!="symbol"?t+"":t,e),e);var ht={};lt(ht,{BindingEventService:()=>A,MultipleSelectInstance:()=>H,VirtualScroll:()=>F,calculateAvailableSpace:()=>D,compareObjects:()=>N,convertItemRowToHtml:()=>b,convertStringStyleToElementStyle:()=>k,createDomElement:()=>h,createDomStructure:()=>$,deepCopy:()=>v,emptyElement:()=>g,findByParam:()=>f,findParent:()=>w,getElementOffset:()=>L,getElementSize:()=>y,insertAfter:()=>G,isDefined:()=>B,multipleSelect:()=>O,objectRemoveEmptyProps:()=>I,removeDiacritics:()=>m,removeUndefined:()=>C,setDataKeys:()=>W,stripScripts:()=>j,toCamelCase:()=>P,toggleElement:()=>M,toggleElementClass:()=>pt,windowScrollPosition:()=>X});module.exports=nt(ht);var A=class{constructor(t){u(this,"_distinctEvent");u(this,"_boundedEvents",[]);this._distinctEvent=t?.distinctEvent??!1}get boundedEvents(){return this._boundedEvents}dispose(){this.unbindAll(),this._boundedEvents=[]}bind(t,e,s,l){let i=Array.isArray(e)?e:[e];if(t?.forEach)t?.forEach(n=>{for(let a of i)(!this._distinctEvent||this._distinctEvent&&!this.hasBinding(n,a))&&(n.addEventListener(a,s,l),this._boundedEvents.push({element:n,eventName:a,listener:s}))});else for(let n of i)(!this._distinctEvent||this._distinctEvent&&!this.hasBinding(t,n))&&(t.addEventListener(n,s,l),this._boundedEvents.push({element:t,eventName:n,listener:s}))}hasBinding(t,e){return this._boundedEvents.some(s=>s.element===t&&(!e||s.eventName===e))}unbind(t,e,s){if(t){let l=Array.isArray(t)?t:[t],i=Array.isArray(e)?e||"":[e||""];for(let n of l){s||(s=this._boundedEvents.find(a=>{if(a.element===n&&(!e||a.eventName===e))return a.listener}));for(let a of i)n?.removeEventListener?.(a,s)}}}unbindAll(){for(;this._boundedEvents.length>0;){let t=this._boundedEvents.pop(),{element:e,eventName:s,listener:l}=t;this.unbind(e,s,l)}}};var Y=typeof window<"u"&&window.multipleSelect!==void 0?window.multipleSelect:{locales:{}};Y.locales={"en-US":{formatSelectAll(){return"[Select all]"},formatAllSelected(){return"All selected"},formatCountSelected(o,t){return`${o} of ${t} selected`},formatNoMatchesFound(){return"No matches found"},formatOkButton(){return"OK"}}};var x=Y.locales;var ut=50,at=4,J={name:"",placeholder:"",classes:"",classPrefix:"",data:void 0,locale:void 0,selectAll:!0,single:void 0,singleRadio:!1,multiple:!1,hideOptgroupCheckboxes:!1,multipleWidth:80,width:void 0,dropWidth:void 0,maxHeight:250,maxHeightUnit:"px",position:"bottom",displayValues:!1,displayTitle:!1,displayDelimiter:", ",minimumCountSelected:3,ellipsis:!1,isOpen:!1,keepOpen:!1,openOnHover:!1,container:null,filter:!1,filterGroup:!1,filterPlaceholder:"",filterAcceptOnEnter:!1,filterByDataLength:void 0,customFilter(o){let{text:t,label:e,search:s}=o;return(e||t||"").includes(s)},showClear:!1,autoAdjustDropHeight:!1,autoAdjustDropPosition:!1,autoAdjustDropWidthByTextSize:!1,adjustedHeightPadding:10,useSelectOptionLabel:!1,useSelectOptionLabelToHtml:!1,cssStyler:()=>null,styler:()=>!1,textTemplate:o=>o.innerHTML.trim(),labelTemplate:o=>o.label,onOpen:()=>!1,onClose:()=>!1,onCheckAll:()=>!1,onUncheckAll:()=>!1,onFocus:()=>!1,onBlur:()=>!1,onOptgroupClick:()=>!1,onBeforeClick:()=>!0,onClick:()=>!1,onFilter:()=>!1,onClear:()=>!1,onAfterCreate:()=>!1,onDestroy:()=>!1,onAfterDestroy:()=>!1,onDestroyed:()=>!1},rt=["init","getOptions","refreshOptions","getSelects","setSelects","enable","disable","open","close","check","uncheck","checkAll","uncheckAll","checkInvert","focus","blur","refresh","destroy"];Object.assign(J,x["en-US"]);var ct={BLOCK_ROWS:ut,CLUSTER_BLOCKS:at,DEFAULTS:J,METHODS:rt},d=ct;function N(o,t,e=!1){let s=Object.keys(o),l=Object.keys(t);if(e&&s.length!==l.length)return!1;for(let i of s)if(l.includes(i)&&o[i]!==t[i])return!1;return!0}function v(o){let t=()=>{let l={};for(let i in o)Object.prototype.hasOwnProperty.call(o,i)&&(l[i]=v(o[i]));return l},e=()=>o.map(l=>v(l)),s=Object.prototype.toString.call(o).slice(8,-1).toLowerCase();return s==="object"?t():s==="array"?e():o}function B(o){return o!=null&&o!==""}function I(o,t){return typeof o=="object"?Object.fromEntries(t?Object.entries(o).filter(([e,s])=>!B(s)&&!t.includes(e)||B(s)):Object.entries(o).filter(([e,s])=>B(s))):o}function W(o){let t=0;return o.forEach((e,s)=>{e.type==="optgroup"?(e._key=`group_${s}`,e.visible=typeof e.visible>"u"?!0:e.visible,e.children.forEach((l,i)=>{l&&(l.visible=typeof l?.visible>"u"?!0:l.visible,l.divider||(l._key=`option_${s}_${i}`,t+=1))})):(e.visible=typeof e.visible>"u"?!0:e.visible,e.divider||(e._key=`option_${s}`,t+=1))}),t}function f(o,t,e){if(Array.isArray(o))for(let s of o){if(s[t]===e||s[t]===`${+s[t]}`&&+s[t]===e)return s;if(s.type==="optgroup"){for(let l of s.children)if(l&&(l[t]===e||l[t]===`${+l[t]}`&&+l[t]===e))return l}}}function j(o){return o.replace(/(\b)(on[a-z]+)(\s*)=([^>]*)|javascript:([^>]*)[^>]*|(<\s*)(\/*)script([<>]*).*(<\s*)(\/*)script(>*)|(&lt;|&#60;)(\/*)(script|script defer)(.*)(&#62;|&gt;|&gt;">)/gi,"")}function C(o){return Object.keys(o).forEach(t=>o[t]===void 0?delete o[t]:""),o}function P(o){return o.replace(/[\W_]+(.)/g,(t,e)=>e.toUpperCase())}function m(o){return typeof o!="string"?o:o.normalize?o.normalize("NFD").replace(/[\u0300-\u036F]/g,""):[{base:"A",letters:/[\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F]/g},{base:"AA",letters:/[\uA732]/g},{base:"AE",letters:/[\u00C6\u01FC\u01E2]/g},{base:"AO",letters:/[\uA734]/g},{base:"AU",letters:/[\uA736]/g},{base:"AV",letters:/[\uA738\uA73A]/g},{base:"AY",letters:/[\uA73C]/g},{base:"B",letters:/[\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181]/g},{base:"C",letters:/[\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E]/g},{base:"D",letters:/[\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779]/g},{base:"DZ",letters:/[\u01F1\u01C4]/g},{base:"Dz",letters:/[\u01F2\u01C5]/g},{base:"E",letters:/[\u0045\u24BA\uFF25\u00C8\u00C9\u00CA\u1EC0\u1EBE\u1EC4\u1EC2\u1EBC\u0112\u1E14\u1E16\u0114\u0116\u00CB\u1EBA\u011A\u0204\u0206\u1EB8\u1EC6\u0228\u1E1C\u0118\u1E18\u1E1A\u0190\u018E]/g},{base:"F",letters:/[\u0046\u24BB\uFF26\u1E1E\u0191\uA77B]/g},{base:"G",letters:/[\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E]/g},{base:"H",letters:/[\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D]/g},{base:"I",letters:/[\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197]/g},{base:"J",letters:/[\u004A\u24BF\uFF2A\u0134\u0248]/g},{base:"K",letters:/[\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2]/g},{base:"L",letters:/[\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780]/g},{base:"LJ",letters:/[\u01C7]/g},{base:"Lj",letters:/[\u01C8]/g},{base:"M",letters:/[\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C]/g},{base:"N",letters:/[\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4]/g},{base:"NJ",letters:/[\u01CA]/g},{base:"Nj",letters:/[\u01CB]/g},{base:"O",letters:/[\u004F\u24C4\uFF2F\u00D2\u00D3\u00D4\u1ED2\u1ED0\u1ED6\u1ED4\u00D5\u1E4C\u022C\u1E4E\u014C\u1E50\u1E52\u014E\u022E\u0230\u00D6\u022A\u1ECE\u0150\u01D1\u020C\u020E\u01A0\u1EDC\u1EDA\u1EE0\u1EDE\u1EE2\u1ECC\u1ED8\u01EA\u01EC\u00D8\u01FE\u0186\u019F\uA74A\uA74C]/g},{base:"OI",letters:/[\u01A2]/g},{base:"OO",letters:/[\uA74E]/g},{base:"OU",letters:/[\u0222]/g},{base:"P",letters:/[\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754]/g},{base:"Q",letters:/[\u0051\u24C6\uFF31\uA756\uA758\u024A]/g},{base:"R",letters:/[\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782]/g},{base:"S",letters:/[\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784]/g},{base:"T",letters:/[\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786]/g},{base:"TZ",letters:/[\uA728]/g},{base:"U",letters:/[\u0055\u24CA\uFF35\u00D9\u00DA\u00DB\u0168\u1E78\u016A\u1E7A\u016C\u00DC\u01DB\u01D7\u01D5\u01D9\u1EE6\u016E\u0170\u01D3\u0214\u0216\u01AF\u1EEA\u1EE8\u1EEE\u1EEC\u1EF0\u1EE4\u1E72\u0172\u1E76\u1E74\u0244]/g},{base:"V",letters:/[\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245]/g},{base:"VY",letters:/[\uA760]/g},{base:"W",letters:/[\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72]/g},{base:"X",letters:/[\u0058\u24CD\uFF38\u1E8A\u1E8C]/g},{base:"Y",letters:/[\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE]/g},{base:"Z",letters:/[\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762]/g},{base:"a",letters:/[\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u00E4\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250]/g},{base:"aa",letters:/[\uA733]/g},{base:"ae",letters:/[\u00E6\u01FD\u01E3]/g},{base:"ao",letters:/[\uA735]/g},{base:"au",letters:/[\uA737]/g},{base:"av",letters:/[\uA739\uA73B]/g},{base:"ay",letters:/[\uA73D]/g},{base:"b",letters:/[\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253]/g},{base:"c",letters:/[\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184]/g},{base:"d",letters:/[\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A]/g},{base:"dz",letters:/[\u01F3\u01C6]/g},{base:"e",letters:/[\u0065\u24D4\uFF45\u00E8\u00E9\u00EA\u1EC1\u1EBF\u1EC5\u1EC3\u1EBD\u0113\u1E15\u1E17\u0115\u0117\u00EB\u1EBB\u011B\u0205\u0207\u1EB9\u1EC7\u0229\u1E1D\u0119\u1E19\u1E1B\u0247\u025B\u01DD]/g},{base:"f",letters:/[\u0066\u24D5\uFF46\u1E1F\u0192\uA77C]/g},{base:"g",letters:/[\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F]/g},{base:"h",letters:/[\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265]/g},{base:"hv",letters:/[\u0195]/g},{base:"i",letters:/[\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131]/g},{base:"j",letters:/[\u006A\u24D9\uFF4A\u0135\u01F0\u0249]/g},{base:"k",letters:/[\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3]/g},{base:"l",letters:/[\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747]/g},{base:"lj",letters:/[\u01C9]/g},{base:"m",letters:/[\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F]/g},{base:"n",letters:/[\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5]/g},{base:"nj",letters:/[\u01CC]/g},{base:"o",letters:/[\u006F\u24DE\uFF4F\u00F2\u00F3\u00F4\u1ED3\u1ED1\u1ED7\u1ED5\u00F5\u1E4D\u022D\u1E4F\u014D\u1E51\u1E53\u014F\u022F\u0231\u00F6\u022B\u1ECF\u0151\u01D2\u020D\u020F\u01A1\u1EDD\u1EDB\u1EE1\u1EDF\u1EE3\u1ECD\u1ED9\u01EB\u01ED\u00F8\u01FF\u0254\uA74B\uA74D\u0275]/g},{base:"oi",letters:/[\u01A3]/g},{base:"ou",letters:/[\u0223]/g},{base:"oo",letters:/[\uA74F]/g},{base:"p",letters:/[\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755]/g},{base:"q",letters:/[\u0071\u24E0\uFF51\u024B\uA757\uA759]/g},{base:"r",letters:/[\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783]/g},{base:"s",letters:/[\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B]/g},{base:"t",letters:/[\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787]/g},{base:"tz",letters:/[\uA729]/g},{base:"u",letters:/[\u0075\u24E4\uFF55\u00F9\u00FA\u00FB\u0169\u1E79\u016B\u1E7B\u016D\u00FC\u01DC\u01D8\u01D6\u01DA\u1EE7\u016F\u0171\u01D4\u0215\u0217\u01B0\u1EEB\u1EE9\u1EEF\u1EED\u1EF1\u1EE5\u1E73\u0173\u1E77\u1E75\u0289]/g},{base:"v",letters:/[\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C]/g},{base:"vy",letters:/[\uA761]/g},{base:"w",letters:/[\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73]/g},{base:"x",letters:/[\u0078\u24E7\uFF58\u1E8B\u1E8D]/g},{base:"y",letters:/[\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF]/g},{base:"z",letters:/[\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763]/g}].reduce((e,{letters:s,base:l})=>e.replace(s,l),o)}function k(o){let t={};if(o){let e=o.replace(/\s/g,"").split(";");for(let s of e){let[l,i]=s.trim().split(":");l&&(t[P(l)]=i.trim())}console.warn("[multiple-select-vanilla] Please note that `styler` is deprecated, please migrate to `cssStyler` when possible.")}return t}function D(o){let t=0,e=0,s=0,l=0,i=window.innerHeight??0,n=window.innerWidth??0,a=X(),c=a.top,r=a.left,p=L(o);if(p){let E=p.top??0,S=p.left??0;e=E-c,t=i-(E-c),s=S-r,l=n-(S-r)}return{top:e,bottom:t,left:s,right:l}}function h(o,t,e){let s=document.createElement(o);return t&&Object.keys(t).forEach(l=>{let i=t[l];typeof i=="object"?Object.assign(s[l],i):s[l]=t[l]}),e?.appendChild&&e.appendChild(s),s}function $(o,t,e){let s="";o.props?.innerHTML&&(s=o.props.innerHTML,delete o.props.innerHTML);let l=h(o.tagName,I(o.props,["class","title","style"]),t),i=e;if(i||(i=l),s&&(l.innerHTML=s),o.attrs)for(let n of Object.keys(o.attrs))l.setAttribute(n,o.attrs[n]);if(o.children)for(let n of o.children)$(n,l,i);return t?.appendChild(l),l}function b(o){return o.hasOwnProperty("tagName")?$(o):document.createElement("li")}function g(o){for(;o?.firstChild;)o.lastChild&&o.removeChild(o.lastChild);return o}function L(o){if(!o)return;let t=o?.getBoundingClientRect?.(),e=0,s=0,l=0,i=0;return t?.top!==void 0&&t.left!==void 0&&(e=t.top+window.pageYOffset,s=t.left+window.pageXOffset,i=t.right,l=t.bottom),{top:e,left:s,bottom:l,right:i}}function y(o,t,e){let s=parseFloat(o.style[e]);if(!s||isNaN(s)){switch(t){case"outer":s=o[e==="width"?"offsetWidth":"offsetHeight"];break;case"scroll":s=o[e==="width"?"scrollWidth":"scrollHeight"];break;case"inner":default:s=o[e==="width"?"clientWidth":"clientHeight"];break}s=o.getBoundingClientRect()[e]}if(!s||isNaN(s)){let l=o.style.display,i=o.style.position;o.style.display="block",o.style.position="absolute";let n=window.getComputedStyle(o)[e];s=parseFloat(n),isNaN(s)&&(s=0),o.style.display=l,o.style.position=i}return s||0}function w(o,t){let e=null,s=o?.parentElement;for(;s;){let[l,i,n,a]=t.match(/^([a-z]*)([#.]{1})([a-z\-]+)$/i)||[];if(n&&a)for(let c of a.replace(n,"").split(" "))s.classList.contains(c)&&(i?s?.tagName.toLowerCase()===i&&(e=s):e=s);s=s.parentElement}return e}function G(o,t){o.parentNode?.insertBefore(t,o.nextSibling)}function M(o,t){o?.style&&(o.style.display=o.style.display==="none"&&t!==!1||t===!0?"block":"none")}function pt(o,t){if(o?.classList){let s=t===!0||!o.classList.contains("selected")?"add":"remove";o.classList[s]("selected")}}function X(){return{left:window.pageXOffset||document.documentElement.scrollLeft||0,top:window.pageYOffset||document.documentElement.scrollTop||0}}var F=class{constructor(t){u(this,"cache");u(this,"clusterRows");u(this,"dataStart");u(this,"dataEnd");u(this,"rows");u(this,"scrollEl");u(this,"blockHeight");u(this,"clusterHeight");u(this,"contentEl");u(this,"parentEl");u(this,"itemHeight");u(this,"lastCluster");u(this,"scrollTop");u(this,"destroy");u(this,"callback");u(this,"sanitizer");this.rows=t.rows,this.scrollEl=t.scrollEl,this.contentEl=t.contentEl,this.parentEl=t.contentEl?.parentElement,this.callback=t.callback,this.cache={},this.scrollTop=this.scrollEl.scrollTop,this.initDOM(this.rows),this.scrollEl.scrollTop=this.scrollTop,this.lastCluster=0;let e=()=>{this.lastCluster!==(this.lastCluster=this.getNum())&&(this.initDOM(this.rows),this.callback())};this.scrollEl.addEventListener("scroll",e,!1),this.destroy=()=>{g(this.contentEl),this.scrollEl.removeEventListener("scroll",e,!1)}}initDOM(t){if(typeof this.clusterHeight>"u"){this.cache.scrollTop=this.scrollEl.scrollTop;let n=b(t[0]);this.contentEl.appendChild(n),this.contentEl.appendChild(n),this.contentEl.appendChild(n),this.cache.data=[t[0]],this.getRowsHeight()}let e=this.initData(t,this.getNum()),s=this.checkChanges("data",e.rows),l=this.checkChanges("top",e.topOffset),i=this.checkChanges("bottom",e.bottomOffset);g(this.contentEl),s&&l?(e.topOffset&&this.contentEl.appendChild(this.getExtra("top",e.topOffset)),e.rows.forEach(n=>this.contentEl.appendChild(b(n))),e.bottomOffset&&this.contentEl.appendChild(this.getExtra("bottom",e.bottomOffset))):i&&this.contentEl.lastChild&&(this.contentEl.lastChild.style.height=`${e.bottomOffset}px`)}getRowsHeight(){if(typeof this.itemHeight>"u"){let t=this.parentEl?.style.display||"";this.parentEl&&(t===""||t==="none")&&(this.parentEl.style.display="block");let e=this.contentEl.children,s=e[Math.floor(e.length/2)];this.itemHeight=s.offsetHeight,this.parentEl&&(this.parentEl.style.display=t)}this.blockHeight=this.itemHeight*d.BLOCK_ROWS,this.clusterRows=d.BLOCK_ROWS*d.CLUSTER_BLOCKS,this.clusterHeight=this.blockHeight*d.CLUSTER_BLOCKS}getNum(){this.scrollTop=this.scrollEl.scrollTop;let t=(this.clusterHeight||0)-(this.blockHeight||0);return t&&Math.floor(this.scrollTop/t)||0}initData(t,e){if(t.length<d.BLOCK_ROWS)return{topOffset:0,bottomOffset:0,rowsAbove:0,rows:t};let s=Math.max((this.clusterRows-d.BLOCK_ROWS)*e,0),l=s+this.clusterRows,i=Math.max(s*this.itemHeight,0),n=Math.max((t.length-l)*this.itemHeight,0),a=[],c=s;i<1&&c++;for(let r=s;r<l;r++)t[r]&&a.push(t[r]);return this.dataStart=s,this.dataEnd=l,{topOffset:i,bottomOffset:n,rowsAbove:c,rows:a}}checkChanges(t,e){let s=e!==this.cache[t];return this.cache[t]=e,s}getExtra(t,e){let s=document.createElement("li");return s.className=`virtual-scroll-${t}`,e&&(s.style.height=`${e}px`),s}};var H=class{constructor(t,e){this.elm=t;u(this,"_bindEventService");u(this,"allSelected",!1);u(this,"fromHtml",!1);u(this,"choiceElm");u(this,"closeElm");u(this,"closeSearchElm");u(this,"filterText","");u(this,"updateData",[]);u(this,"data",[]);u(this,"dataTotal");u(this,"dropElm");u(this,"okButtonElm");u(this,"filterParentElm");u(this,"ulElm");u(this,"parentElm");u(this,"labelElm");u(this,"selectAllParentElm");u(this,"selectAllElm");u(this,"searchInputElm");u(this,"selectGroupElms");u(this,"selectItemElms");u(this,"disableItemElms");u(this,"noResultsElm");u(this,"options");u(this,"selectAllName","");u(this,"selectGroupName","");u(this,"selectItemName","");u(this,"tabIndex");u(this,"updateDataStart");u(this,"updateDataEnd");u(this,"virtualScroll");u(this,"locales",{});this.options=Object.assign({},d.DEFAULTS,this.elm.dataset,e),this._bindEventService=new A({distinctEvent:!0})}get isRenderAsHtml(){return this.options.renderOptionLabelAsHtml||this.options.useSelectOptionLabelToHtml}init(){this.initLocale(),this.initContainer(),this.initData(),this.initSelected(!0),this.initFilter(),this.initDrop(),this.initView(),this.options.onAfterCreate()}destroy(t=!0){this.elm&&this.parentElm&&(this.options.onDestroy({hardDestroy:t}),t&&this.options.onHardDestroy(),this.elm.parentElement&&this.parentElm.parentElement&&this.elm.parentElement.insertBefore(this.elm,this.parentElm.parentElement.firstChild),this.elm.classList.remove("ms-offscreen"),this._bindEventService.unbindAll(),this.tabIndex&&(this.elm.tabIndex=+this.tabIndex),this.virtualScroll?.destroy(),this.dropElm?.remove(),this.parentElm.parentNode?.removeChild(this.parentElm),this.fromHtml&&(delete this.options.data,this.fromHtml=!1),this.options.onAfterDestroy({hardDestroy:t}),t&&(this.options.onAfterHardDestroy?.(),Object.keys(this.options).forEach(e=>delete this[e])))}initLocale(){if(this.options.locale){let t=window.multipleSelect.locales,e=this.options.locale.split(/-|_/);if(e[0]=e[0].toLowerCase(),e[1]&&(e[1]=e[1].toUpperCase()),t[this.options.locale])Object.assign(this.options,t[this.options.locale]);else if(t[e.join("-")])Object.assign(this.options,t[e.join("-")]);else if(t[e[0]])Object.assign(this.options,t[e[0]]);else throw new Error(`[multiple-select-vanilla] invalid locales "${this.options.locale}", make sure to import it before using it`)}}initContainer(){let t=this.elm.getAttribute("name")||this.options.name||"";this.options.classes&&this.elm.classList.add(this.options.classes),this.options.classPrefix&&(this.elm.classList.add(this.options.classPrefix),this.options.size&&this.elm.classList.add(`${this.options.classPrefix}-${this.options.size}`)),this.elm.style.display="none",this.labelElm=this.elm.closest("label"),!this.labelElm&&this.elm.id&&(this.labelElm=document.createElement("label"),this.labelElm.htmlFor=this.elm.id),this.labelElm?.querySelector("input")&&(this.labelElm=null),typeof this.options.single>"u"&&(this.options.single=!this.elm.multiple),this.parentElm=h("div",{className:`ms-parent ${this.elm.className||""} ${this.options.classes}`,dataset:{test:"sel"}});let e=this.elm.getAttribute("title")||"";e&&(this.parentElm.title=e),this.options.placeholder=this.options.placeholder||this.elm.getAttribute("placeholder")||"",this.tabIndex=this.elm.getAttribute("tabindex");let s="";this.tabIndex!==null&&(this.elm.tabIndex=-1,s=this.tabIndex&&`tabindex="${this.tabIndex}"`),this.choiceElm=h("button",{className:"ms-choice",type:"button"},this.parentElm),isNaN(s)&&(this.choiceElm.tabIndex=+s),this.choiceElm.appendChild(h("span",{className:"ms-placeholder",textContent:this.options.placeholder})),this.options.showClear&&this.choiceElm.appendChild(h("div",{className:"icon-close"})),this.choiceElm.appendChild(h("div",{className:"icon-caret"})),this.dropElm=h("div",{className:`ms-drop ${this.options.position}`},this.parentElm),t&&(this.dropElm.dataset.name=t);let l=this.elm.getAttribute("data-test")||this.options.dataTest;l&&(this.parentElm.dataset.test=l,this.dropElm.dataset.test=l),this.closeElm=this.choiceElm.querySelector(".icon-close"),this.options.dropWidth&&(this.dropElm.style.width=typeof this.options.dropWidth=="string"?this.options.dropWidth:`${this.options.dropWidth}px`),G(this.elm,this.parentElm),this.elm.disabled&&this.choiceElm.classList.add("disabled"),this.selectAllName=`selectAll${t}`,this.selectGroupName=`selectGroup${t}`,this.selectItemName=`selectItem${t}`,this.options.keepOpen||(this._bindEventService.unbind(document.body,"click"),this._bindEventService.bind(document.body,"click",i=>{i.target===this.choiceElm||w(i.target,".ms-choice")===this.choiceElm||(i.target===this.dropElm||w(i.target,".ms-drop")!==this.dropElm&&i.target!==this.elm)&&this.options.isOpen&&this.close()}))}initData(){let t=[];if(this.options.data){if(Array.isArray(this.options.data))this.data=this.options.data.map(e=>typeof e=="string"||typeof e=="number"?{text:e,value:e}:e);else if(typeof this.options.data=="object"){for(let[e,s]of Object.entries(this.options.data))t.push({value:e,text:`${s}`});this.data=t}}else this.elm.childNodes.forEach(e=>{let s=this.initRow(e);s&&t.push(s)}),this.options.data=t,this.data=t,this.fromHtml=!0;this.dataTotal=W(this.data||[])}initRow(t,e){let s={};return t.tagName?.toLowerCase()==="option"?(s.type="option",s.text=this.options.textTemplate(t),s.value=t.value,s.visible=!0,s.selected=!!t.selected,s.disabled=e||t.disabled,s.classes=t.getAttribute("class")||"",s.title=t.getAttribute("title")||"",t.dataset.value&&(s._value=t.dataset.value),Object.keys(t.dataset).length&&(s._data=t.dataset,s._data.divider&&(s.divider=s._data.divider)),s):t.tagName?.toLowerCase()==="optgroup"?(s.type="optgroup",s.label=this.options.labelTemplate(t),s.visible=!0,s.selected=!!t.selected,s.disabled=t.disabled,s.children=[],Object.keys(t.dataset).length&&(s._data=t.dataset),t.childNodes.forEach(l=>{s.children.push(this.initRow(l,s.disabled))}),s):null}initDrop(){this.initList(),this.update(!0),this.options.isOpen&&this.open(10),this.options.openOnHover&&this.parentElm&&(this._bindEventService.bind(this.parentElm,"mouseover",()=>this.open(null)),this._bindEventService.bind(this.parentElm,"mouseout",()=>this.close()))}initFilter(){if(this.filterText="",this.options.filter||!this.options.filterByDataLength)return;let t=0;for(let e of this.data||[])e.type==="optgroup"?t+=e.children.length:t+=1;this.options.filter=t>this.options.filterByDataLength}initList(){if(this.options.filter&&(this.filterParentElm=h("div",{className:"ms-search"},this.dropElm),this.filterParentElm.appendChild(h("input",{autocomplete:"off",autocapitalize:"off",spellcheck:!1,type:"text",placeholder:this.options.filterPlaceholder||"\u{1F50E}\uFE0E"})),this.options.showSearchClear&&this.filterParentElm.appendChild(h("span",{className:"icon-close"}))),this.options.selectAll&&!this.options.single){let t=this.elm.getAttribute("name")||this.options.name||"";this.selectAllParentElm=h("div",{className:"ms-select-all"});let e=document.createElement("label");h("input",{type:"checkbox",ariaChecked:String(this.allSelected),checked:this.allSelected,dataset:{name:`selectAll${t}`}},e),e.appendChild(h("span",{textContent:this.formatSelectAll()})),this.selectAllParentElm.appendChild(e),this.dropElm.appendChild(this.selectAllParentElm)}this.ulElm=document.createElement("ul"),this.dropElm.appendChild(this.ulElm),this.options.showOkButton&&!this.options.single&&(this.okButtonElm=h("button",{className:"ms-ok-button",type:"button",textContent:this.formatOkButton()},this.dropElm)),this.initListItems()}initListItems(){let t=0,e=this.getListRows();if(this.options.selectAll&&!this.options.single&&(t=-1),e.length>d.BLOCK_ROWS*d.CLUSTER_BLOCKS){this.virtualScroll?.destroy();let s=this.dropElm.style.display!=="none";s||(this.dropElm.style.left="-10000",this.dropElm.style.display="block");let l=()=>{this.virtualScroll&&(this.updateDataStart=this.virtualScroll.dataStart+t,this.updateDataEnd=this.virtualScroll.dataEnd+t,this.updateDataStart<0&&(this.updateDataStart=0),this.updateDataEnd>this.getDataLength()&&(this.updateDataEnd=this.getDataLength()))};this.ulElm&&(this.virtualScroll=new F({rows:e,scrollEl:this.ulElm,contentEl:this.ulElm,sanitizer:this.options.sanitizer,callback:()=>{l(),this.events()}})),l(),s||(this.dropElm.style.left="0",this.dropElm.style.display="none")}else this.ulElm&&(g(this.ulElm),e.forEach(s=>this.ulElm.appendChild(b(s)))),this.updateDataStart=0,this.updateDataEnd=this.updateData.length,this.virtualScroll=null;return this.events(),e}getListRows(){let t=[];return this.updateData=[],this.data?.forEach(e=>t.push(...this.initListItem(e))),t.push({tagName:"li",props:{className:"ms-no-results",textContent:this.formatNoMatchesFound()}}),t}initListItem(t,e=0){let s=t?.title||"",l=this.options.multiple?"multiple":"",i=this.options.single?"radio":"checkbox",n="";if(!t?.visible)return[];if(this.updateData.push(t),this.options.single&&!this.options.singleRadio&&(n="hide-radio "),t.selected&&(n+="selected "),t.type==="optgroup"){let _=[],Z=this.options.hideOptgroupCheckboxes||this.options.single?{tagName:"span",props:{dataset:{name:this.selectGroupName,key:t._key}}}:{tagName:"input",props:{type:"checkbox",dataset:{name:this.selectGroupName,key:t._key},ariaChecked:String(t.selected||!1),checked:!!t.selected,disabled:t.disabled}};!n.includes("hide-radio")&&(this.options.hideOptgroupCheckboxes||this.options.single)&&(n+="hide-radio ");let U={tagName:"span",props:{}};this.applyAsTextOrHtmlWhenEnabled(U.props,t.label);let R={tagName:"li",props:{className:`group ${n}`.trim()},children:[{tagName:"label",props:{className:`optgroup${this.options.single||t.disabled?" disabled":""}`},children:[Z,U]}]},K=this.options.cssStyler(t),V=String(this.options.styler(t)||"");return V&&(R.props.style=k(V)),K&&(R.props.style=K),_.push(R),t.children.forEach(Q=>_.push(...this.initListItem(Q,1))),_}if(n+=t.classes||"",e&&this.options.single&&(n+=`option-level-${e} `),t.divider)return[{tagName:"li",props:{className:"option-divider"}}];let a=l||n?(l+n).trim():"",c=`${t.disabled?"disabled":""}`,r={tagName:"span",props:{}};this.applyAsTextOrHtmlWhenEnabled(r.props,t.text);let p={tagName:"input",props:{type:i,value:encodeURI(t.value),dataset:{key:t._key,name:this.selectItemName},ariaChecked:String(t.selected||!1),checked:!!t.selected,disabled:!!t.disabled}};t.selected&&(p.attrs={checked:"checked"});let E={tagName:"li",props:{className:a,title:s},children:[{tagName:"label",props:{className:c},children:[p,r]}]},S=this.options.cssStyler(t),z=String(this.options.styler(t)||"");return z&&(E.props.style=k(z)),S&&(E.props.style=S),[E]}initSelected(t=!1){let e=0;for(let s of this.data||[])if(s.type==="optgroup"){let l=s.children.filter(i=>i&&i.selected&&!i.disabled&&i.visible).length;s.children.length&&(s.selected=!this.options.single&&l&&l===s.children.filter(i=>i&&!i.disabled&&i.visible&&!i.divider).length),e+=l}else e+=s.selected&&!s.disabled&&s.visible?1:0;this.allSelected=this.data?.filter(s=>s.selected&&!s.disabled&&s.visible).length===this.data?.filter(s=>!s.disabled&&s.visible&&!s.divider).length,t||(this.allSelected?this.options.onCheckAll():e===0&&this.options.onUncheckAll())}initView(){let t;window.getComputedStyle?(t=window.getComputedStyle(this.elm).width,t==="auto"&&(t=y(this.dropElm,"outer","width")+20)):t=y(this.elm,"outer","width")+20,this.parentElm.style.width=`${this.options.width||t}px`,this.elm.classList.add("ms-offscreen")}events(){this._bindEventService.unbind(this.okButtonElm),this._bindEventService.unbind(this.searchInputElm),this._bindEventService.unbind(this.selectAllElm),this._bindEventService.unbind(this.selectGroupElms),this._bindEventService.unbind(this.selectItemElms),this._bindEventService.unbind(this.disableItemElms),this._bindEventService.unbind(this.noResultsElm),this.closeSearchElm=this.filterParentElm?.querySelector(".icon-close"),this.searchInputElm=this.dropElm.querySelector(".ms-search input"),this.selectAllElm=this.dropElm.querySelector(`input[data-name="${this.selectAllName}"]`),this.selectGroupElms=this.dropElm.querySelectorAll(`input[data-name="${this.selectGroupName}"],span[data-name="${this.selectGroupName}"]`),this.selectItemElms=this.dropElm.querySelectorAll(`input[data-name="${this.selectItemName}"]:enabled`),this.disableItemElms=this.dropElm.querySelectorAll(`input[data-name="${this.selectItemName}"]:disabled`),this.noResultsElm=this.dropElm.querySelector(".ms-no-results");let t=e=>{e.preventDefault(),!e.target.classList.contains("icon-close")&&this[this.options.isOpen?"close":"open"]()};this.labelElm&&this._bindEventService.bind(this.labelElm,"click",e=>{e.target.nodeName.toLowerCase()==="label"&&(t(e),(!this.options.filter||!this.options.isOpen)&&this.focus(),e.stopPropagation())}),this._bindEventService.bind(this.choiceElm,"click",t),this.options.onFocus&&this._bindEventService.bind(this.choiceElm,"focus",this.options.onFocus),this.options.onBlur&&this._bindEventService.bind(this.choiceElm,"blur",this.options.onBlur),this._bindEventService.bind(this.parentElm,"keydown",e=>{e.code==="Escape"&&!this.options.keepOpen&&(this.close(),this.choiceElm.focus())}),this.closeElm&&this._bindEventService.bind(this.closeElm,"click",e=>{e.preventDefault(),this._checkAll(!1,!0),this.initSelected(!1),this.updateSelected(),this.update(),this.options.onClear()}),this.closeSearchElm&&this._bindEventService.bind(this.closeSearchElm,"click",e=>{e.preventDefault(),this.searchInputElm&&(this.searchInputElm.value="",this.searchInputElm.focus()),this.filter()}),this.searchInputElm&&(this._bindEventService.bind(this.searchInputElm,"keydown",e=>{e.code==="Tab"&&e.shiftKey&&this.close()}),this._bindEventService.bind(this.searchInputElm,"keyup",e=>{if(this.options.filterAcceptOnEnter&&["Enter","Space"].includes(e.code)&&this.searchInputElm?.value){if(this.options.single){let s=[];this.selectItemElms?.forEach(l=>{l.closest("li")?.style.display!=="none"&&s.push(l)}),s.length&&s[0].hasAttribute("data-name")&&this.setSelects([s[0].value])}else this.selectAllElm?.click();this.close(),this.focus();return}this.filter()})),this.selectAllElm&&(this._bindEventService.unbind(this.selectAllElm,"click"),this._bindEventService.bind(this.selectAllElm,"click",e=>{this._checkAll(e.currentTarget?.checked)})),this.okButtonElm&&(this._bindEventService.unbind(this.okButtonElm,"click"),this._bindEventService.bind(this.okButtonElm,"click",e=>{t(e),e.stopPropagation()})),this._bindEventService.bind(this.selectGroupElms,"click",e=>{let s=e.currentTarget,l=s.checked,i=f(this.data,"_key",s.dataset.key);this._checkGroup(i,l),this.options.onOptgroupClick(C({label:i.label,selected:i.selected,data:i._data,children:i.children.map(n=>{if(n)return C({text:n.text,value:n.value,selected:n.selected,disabled:n.disabled,data:n._data})})}))}),this._bindEventService.bind(this.selectItemElms,"click",e=>{let s=e.currentTarget,l=s.checked,i=f(this.data,"_key",s.dataset.key),n=()=>{this.options.single&&this.options.isOpen&&!this.options.keepOpen&&this.close()};if(this.options.onBeforeClick(i)===!1){n();return}this._check(i,l),this.options.onClick(C({text:i.text,value:i.value,selected:i.selected,data:i._data})),n()})}open(t=0){if(t!==null&&t>=0){let e;clearTimeout(e),e=setTimeout(()=>this.openDrop(),t)}else this.openDrop()}openDrop(){if(this.choiceElm?.classList.contains("disabled"))return;if(this.options.isOpen=!0,this.parentElm.classList.add("ms-parent-open"),this.choiceElm?.querySelector("div")?.classList.add("open"),this.dropElm.style.display="block",this.selectAllElm?.parentElement&&(this.selectAllElm.parentElement.style.display="block"),this.noResultsElm&&(this.noResultsElm.style.display="none"),this.getDataLength()||(this.selectAllElm?.parentElement&&(this.selectAllElm.parentElement.style.display="none"),this.noResultsElm&&(this.noResultsElm.style.display="block")),this.options.container){let i=L(this.dropElm),n;this.options.container instanceof Node?n=this.options.container:typeof this.options.container=="string"&&(n=this.options.container==="body"?document.body:document.querySelector(this.options.container)),n.appendChild(this.dropElm),this.dropElm.style.top=`${i?.top??0}px`,this.dropElm.style.left=`${i?.left??0}px`,this.dropElm.style.minWidth="auto",this.dropElm.style.width=`${y(this.parentElm,"outer","width")}px`}let t=this.options.minHeight,e=this.options.maxHeight;this.options.maxHeightUnit==="row"&&(e=y(this.dropElm.querySelector("ul>li"),"outer","height")*this.options.maxHeight);let s=this.dropElm.querySelector("ul");s&&(t&&(s.style.minHeight=`${t}px`),s.style.maxHeight=`${e}px`),this.dropElm.querySelectorAll(".multiple").forEach(i=>i.style.width=`${this.options.multipleWidth}px`),this.getDataLength()&&this.options.filter&&(this.searchInputElm&&(this.searchInputElm.value="",this.searchInputElm.focus()),this.filter(!0)),this.options.autoAdjustDropWidthByTextSize&&this.adjustDropWidthByText();let l=this.options.position;if(this.options.autoAdjustDropHeight){if(this.options.autoAdjustDropPosition){let{bottom:i,top:n}=D(this.dropElm),a=this.dropElm.getBoundingClientRect().height;l=i<a&&n>i?"top":"bottom"}this.adjustDropHeight(l)}this.options.autoAdjustDropPosition&&this.adjustDropPosition(!0),this.options.onOpen()}close(){this.options.isOpen=!1,this.parentElm.classList.remove("ms-parent-open"),this.choiceElm?.querySelector("div")?.classList.remove("open"),this.dropElm.style.display="none",this.options.container&&(this.parentElm.appendChild(this.dropElm),this.dropElm.style.top="auto",this.dropElm.style.left="auto"),this.options.onClose()}applyAsTextOrHtmlWhenEnabled(t,e){t||(t={}),this.isRenderAsHtml?t.innerHTML=typeof this.options.sanitizer=="function"?this.options.sanitizer(e):e:t.textContent=e}update(t=!1){let e=this.getSelects(),s=this.getSelects("text");this.options.displayValues&&(s=e);let l=this.choiceElm?.querySelector("span"),i=e.length,n=null,a=()=>{if(this.options.useSelectOptionLabel||this.options.useSelectOptionLabelToHtml){let r=e.join(this.options.displayDelimiter);return this.options.useSelectOptionLabelToHtml?j(r):r}return s.join(this.options.displayDelimiter)};if(l){if(i===0){let r=this.options.placeholder||"";l.classList.add("ms-placeholder"),this.applyAsTextOrHtmlWhenEnabled(l,r)}else i<this.options.minimumCountSelected?n=a():this.formatAllSelected()&&i===this.dataTotal?n=this.formatAllSelected():this.options.ellipsis&&i>this.options.minimumCountSelected?n=`${s.slice(0,this.options.minimumCountSelected).join(this.options.displayDelimiter)}...`:this.formatCountSelected(i,this.dataTotal)&&i>this.options.minimumCountSelected?n=this.formatCountSelected(i,this.dataTotal):n=a();if(n!==null&&(l?.classList.remove("ms-placeholder"),this.applyAsTextOrHtmlWhenEnabled(l,n)),this.options.displayTitle||this.options.addTitle){this.options.addTitle&&console.warn("[Multiple-Select-Vanilla] Please note that the `addTitle` option was deprecated and replaced by `displayTitle`.");let r=this.options.useSelectOptionLabel||this.options.useSelectOptionLabelToHtml?"value":"text";l.title=this.getSelects(r).join(this.options.displayDelimiter)}}let c=this.getSelects();this.options.single?this.elm.value=c.length?c[0]:"":Array.from(this.elm.options).forEach(r=>{r.selected=c.some(p=>p===r.value)}),t||this.elm.dispatchEvent(new Event("change"))}updateSelected(t){for(let s=this.updateDataStart;s<this.updateDataEnd;s++){let l=this.updateData[s],i=this.dropElm.querySelector(`input[data-key=${l._key}]`);if(i){i.checked=l.selected;let n=i.closest("li");n&&(l.selected&&!n.classList.contains("selected")?n.classList.add("selected"):l.selected||n.classList.remove("selected"))}}let e=this.data?.filter(s=>s.visible).length===0;this.selectAllElm&&(this.selectAllElm.checked=this.allSelected,M(this.selectAllElm.closest("li"),!e)),M(this.noResultsElm,e),this.virtualScroll&&(this.virtualScroll.rows=t??this.getListRows())}getData(){return this.options.data}getDataLength(){return this.data?.length??0}getOptions(t=!0){let e=Object.assign({},this.options);return delete e.data,t?v(e):this.options}refreshOptions(t){N(this.options,t,!0)||(this.options=Object.assign(this.options,t),this.destroy(!1),this.init())}getDropElement(){return this.dropElm}getParentElement(){return this.parentElm}getSelects(t="value"){let e=[];for(let s of this.data||[])if(s.type==="optgroup"){let l=s.children.filter(i=>i?.selected);if(!l.length)continue;if(t==="value"||this.options.single)e.push(...l.map(i=>t==="value"&&i._value||i[t]));else{let i=[];i.push("["),i.push(s.label),i.push(`: ${l.map(n=>n[t]).join(", ")}`),i.push("]"),e.push(i.join(""))}}else s.selected&&e.push(t==="value"&&s._value||s[t]);return e}setSelects(t,e="value",s=!1){let l=!1,i=n=>{for(let a of n){let c=!1;if(e==="text"){let r=document.createElement("div");this.applyAsTextOrHtmlWhenEnabled(r,a.text),c=t.includes(r.textContent?.trim()??"")}else c=t.includes(a._value||a.value),!c&&a.value===`${+a.value}`&&(c=t.includes(+a.value));a.selected!==c&&(l=!0),a.selected=c}};for(let n of this.data||[])n.type==="optgroup"?i(n.children):i([n]);l&&(this.initSelected(s),this.updateSelected(),this.update(s))}enable(){this.choiceElm?.classList.remove("disabled")}disable(){this.choiceElm?.classList.add("disabled")}check(t){let e=f(this.data,"value",t);e&&this._check(e,!0)}uncheck(t){let e=f(this.data,"value",t);e&&this._check(e,!1)}_check(t,e){this.options.single&&this._checkAll(!1,!0),t.selected=e,this.initSelected(),this.updateSelected(),this.update()}checkAll(){this._checkAll(!0)}uncheckAll(){this._checkAll(!1)}_checkAll(t,e){for(let s of this.data||[])s.type==="optgroup"?this._checkGroup(s,t,!0):!s.disabled&&!s.divider&&(e||s.visible)&&(s.selected=t);e||(this.initSelected(),this.updateSelected(),this.update())}_checkGroup(t,e,s){t.selected=e,t.children.forEach(l=>{l&&!l.disabled&&!l.divider&&(s||l.visible)&&(l.selected=e)}),s||(this.initSelected(),this.updateSelected(),this.update())}checkInvert(){if(!this.options.single){for(let t of this.data||[])if(t.type==="optgroup")for(let e of t.children)e&&(e.divider||(e.selected=!e.selected));else t&&!t.divider&&(t.selected=!t.selected);this.initSelected(),this.updateSelected(),this.update()}}focus(){this.choiceElm?.focus(),this.options.onFocus()}blur(){this.choiceElm?.blur(),this.options.onBlur()}refresh(){this.destroy(!1),this.init()}filter(t){let e=this.searchInputElm?.value.trim()??"",s=e.toLowerCase();if(this.filterText===s)return;this.filterText=s;for(let i of this.data||[])if(i.type==="optgroup")if(this.options.filterGroup){let n=`${i?.label??""}`;if(i!=null){let a=this.options.customFilter({label:m(n.toLowerCase()),search:m(s),originalLabel:n,originalSearch:e,row:i});i.visible=a;for(let c of i.children)c&&(c.visible=a)}}else{for(let n of i.children)if(n!=null){let a=`${n?.text??""}`;n.visible=this.options.customFilter({text:m(a.toLowerCase()),search:m(s),originalText:a,originalSearch:e,row:n,parent:i})}i.visible=i.children.filter(n=>n?.visible).length>0}else{let n=`${i?.text??""}`;i.visible=this.options.customFilter({text:m(n.toLowerCase()),search:m(s),originalText:n,originalSearch:e,row:i})}let l=this.initListItems();this.initSelected(t),this.updateSelected(l),t||this.options.onFilter(e)}adjustDropHeight(t){let e=t!=="top",s=this.filterParentElm?.getBoundingClientRect().height??0,l=this.okButtonElm?.getBoundingClientRect().height??0,i=this.options.single?0:this.selectAllParentElm?.getBoundingClientRect().height??0,n=s+l+i+5,{bottom:a,top:c}=D(this.parentElm),r=this.options.maxHeight;if(e?r=a-n-this.options.adjustedHeightPadding:r=c-n-this.options.adjustedHeightPadding,!this.options.maxHeight||this.options.maxHeight&&r<this.options.maxHeight){let p=this.dropElm?.querySelector("ul");return p&&(p.style.maxHeight=`${r}px`),!0}return!1}adjustDropPosition(t){let e="bottom";if(this.dropElm&&this.parentElm){let{bottom:s,top:l}=D(this.dropElm),{top:i,left:n}=L(this.parentElm),a=this.dropElm.getBoundingClientRect().height,c=this.dropElm.getBoundingClientRect().width,r=document.body.offsetWidth||window.innerWidth,p=this.parentElm.getBoundingClientRect().width;if(s>a)e="bottom";else if(a>s&&l>s){if(this.options.container){let E=i-a;E<0&&(E=0),(E>0||t)&&(e="top",this.dropElm.style.top=`${E<0?0:E}px`)}else e="top",this.dropElm.classList.add(e);this.dropElm.classList.remove("bottom")}r-c<n&&(this.dropElm.style.left=`${n-(c-p)}px`)}return e}adjustDropWidthByText(){let e=this.parentElm.scrollWidth;(this.options.dropWidth||this.options.width)&&(e=this.options.dropWidth||this.options.width||0);let s=this.dropElm.querySelector(".ms-select-all span"),l=this.dropElm.querySelector("ul"),i=26,n=s?.clientWidth??0+i,c=l.scrollHeight>l.clientHeight?this.getScrollbarWidth():0,r=0;this.dropElm.querySelectorAll("li label").forEach(p=>{p.scrollWidth>r&&(r=p.scrollWidth)}),r+=i+c,r<n&&(r=n),this.options.maxWidth&&r>this.options.maxWidth&&(r=this.options.maxWidth),this.options.minWidth&&r<this.options.minWidth&&(r=this.options.minWidth),(e==="100%"||+e<r)&&(this.dropElm.style.width=`${r}px`,this.dropElm.style.maxWidth=`${r}px`)}getScrollbarWidth(){let t=document.createElement("div");t.style.visibility="hidden",t.style.width="100px",document.body.appendChild(t);let e=t.offsetWidth;t.style.overflow="scroll";let s=document.createElement("div");s.style.width="100%",t.appendChild(s);let l=s.offsetWidth;return t.parentNode?.removeChild(t),e-l}formatAllSelected(){return this.options.allSelectedText||this.options.formatAllSelected()}formatCountSelected(t,e){return this.options.countSelectedText?this.options.countSelectedText.replace("#",`${t}`).replace("%",`${e}`):this.options.formatCountSelected(t,e)}formatNoMatchesFound(){return this.options.noMatchesFoundText||this.options.formatNoMatchesFound()}formatOkButton(){return this.options.okButtonText||this.options.formatOkButton()}formatSelectAll(){return this.options.selectAllText||this.options.formatSelectAll()}};var O=function(o,t){return typeof o=="string"?q(document.querySelectorAll(o),t):o instanceof Node?q([o],t):q(o,t)};function q(o,t){let e=Array.from(o),s=[];for(let l=0;l<e.length;l++){let i=e[l];try{i._multipleSelect!==void 0&&(i._multipleSelect.destroy(),delete i._multipleSelect),i._multipleSelect=new H(i,t||{}),i._multipleSelect.init();let n=i._multipleSelect.getOptions(!1);n.onHardDestroy=()=>delete i._multipleSelect,n.onAfterHardDestroyed=()=>s[l]=null,s.push(i._multipleSelect)}catch(n){console.error(n)}}return s.length===1?s[0]:s}O.defaults=d.DEFAULTS;O.locales={...x};O.methods=d.METHODS;typeof window<"u"&&(window.multipleSelect=O); //# sourceMappingURL=multiple-select.cjs.map