zidan-select 2.4.0 → 2.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * ZidanForm v2.4.0 — plugin-theme.css
2
+ * ZidanForm v2.4.2 — plugin-theme.css
3
3
  * Design tokens, paint, state colours, preset themes (default, modern,
4
4
  * minimal, dark, glass), the five select layouts and framework adapters
5
5
  * (bootstrap, tailwind, bulma, foundation).
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * ZidanForm Select-only v2.4.0 — plugin-select-core.css
2
+ * ZidanForm Select-only v2.4.2 — plugin-select-core.css
3
3
  * Structure for the select / combobox / tags control only.
4
4
  * Pairs with zidan-select.js and plugin-select-theme.css.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * ZidanForm Select-only v2.4.0 — plugin-select-core.css
2
+ * ZidanForm Select-only v2.4.2 — plugin-select-core.css
3
3
  * Structure for the select / combobox / tags control only.
4
4
  * Pairs with zidan-select.js and plugin-select-theme.css.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * ZidanForm Select-only v2.4.0 — plugin-select-theme.css
2
+ * ZidanForm Select-only v2.4.2 — plugin-select-theme.css
3
3
  * Tokens, 5 preset themes, select layouts, scrollbars and framework adapters.
4
4
  * Pairs with zidan-select.js and plugin-select-core.css.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * ZidanForm Select-only v2.4.0 — plugin-select-theme.css
2
+ * ZidanForm Select-only v2.4.2 — plugin-select-theme.css
3
3
  * Tokens, 5 preset themes, select layouts, scrollbars and framework adapters.
4
4
  * Pairs with zidan-select.js and plugin-select-core.css.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * ZidanForm Select-only v2.4.0 — type definitions.
2
+ * ZidanForm Select-only v2.4.2 — type definitions.
3
3
  * https://github.com/akhtar1985/zidan-select
4
4
  */
5
5
  export {
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * ZidanForm Select-only v2.4.0
2
+ * ZidanForm Select-only v2.4.2
3
3
  * Zero-dependency select / combobox / tags enhancement. Every other control family is omitted.
4
4
  * Pairs with plugin-select-core.css and plugin-select-theme.css.
5
5
  *
@@ -29,7 +29,7 @@
29
29
  })(typeof window !== 'undefined' ? window : this, function (global) {
30
30
  'use strict';
31
31
 
32
- var VERSION = '2.4.0';
32
+ var VERSION = '2.4.2';
33
33
 
34
34
  // Loading the file twice (classic script + module wrapper, or two bundles)
35
35
  // must not replace the classes and orphan the live instances.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * ZidanForm Select-only v2.4.0
2
+ * ZidanForm Select-only v2.4.2
3
3
  * Zero-dependency select / combobox / tags enhancement. Every other control family is omitted.
4
4
  * Pairs with plugin-select-core.css and plugin-select-theme.css.
5
5
  *
@@ -8,4 +8,4 @@
8
8
  * MIT License © akhtar1985
9
9
  *
10
10
  * Classic <script> adds window.ZidanForm plus window.ZidanSelect / zidanSelect / initZidanSelects.
11
- */(function(g,z){"use strict";var c=z(g);typeof window!="undefined"&&(window.ZidanForm=c.ZidanForm,c.ZidanSelect&&(window.ZidanSelect=c.ZidanSelect,window.zidanSelect=c.zidanSelect,window.initZidanSelects=c.initZidanSelects),c.zidanField&&(window.zidanField=c.zidanField),c.initZidanForms&&(window.initZidanForms=c.initZidanForms),c.registerIcon&&(window.registerZidanIcon=c.registerIcon)),typeof module!="undefined"&&module.exports&&(module.exports=c)})(typeof window!="undefined"?window:this,function(g){"use strict";var z="2.4.0";if(g&&g.ZidanForm&&g.ZidanForm.__zidanFormGuard===z)return g.ZidanForm.api;var c=typeof document!="undefined"?document:null,M=["classic-clean","floating-label","soft-pill","bordered-brutalist","glass-elevated"],C=["auto","none","vanilla","bootstrap","tailwind","bulma","foundation"],H=["default","modern","minimal","dark","glass"],U=["stacked","inline","card","compact","floating","outlined"],oe=["checkbox","radio","radio-group","file","input","textarea"],j="[data-zidan], [data-zidan-checkbox], [data-zidan-switch], [data-zidan-radio], [data-zidan-radio-group], [data-zidan-file], [data-zidan-input], [data-zidan-textarea], .zidan-field",N="[data-zidan-select], .zidan-select",le="[data-zidan-form], .zidan-form",I=["default","thin","fancy","hover","hidden"],P="zidan:",B=0;function he(e){return B+=1,(e||"zs")+"-"+B.toString(36)+Math.random().toString(36).slice(2,6)}function G(e,t){return!!(e&&e.classList&&e.classList.contains(t))}function K(e,t){return!e||!t||t.split(/\s+/).forEach(function(i){i&&e.classList.add(i)}),e}function m(e,t,i,r){var n=c.createElement(e);return t&&(n.className=t),i&&Object.keys(i).forEach(function(a){var o=i[a];o==null||o===!1||(a==="text"?n.textContent=String(o):n.setAttribute(a,o===!0?"":String(o)))}),r!=null&&(n.textContent=String(r)),n}function T(e){return e==null||e===""?[]:Array.isArray(e)?e.slice():[e]}function we(e){return!!(e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function")}function ue(e){if(!e)return!1;var t=e.closest?e.closest("[dir]"):null,i=t?t.getAttribute("dir"):"";if(!i&&c&&c.documentElement&&(i=c.documentElement.getAttribute("dir")||""),i)return String(i).toLowerCase()==="rtl";try{return!!(g.getComputedStyle&&g.getComputedStyle(e).direction==="rtl")}catch{return!1}}function b(e){return!!(e&&typeof e=="object"&&e.nodeType===1)}function E(e,t){if(e==null||e==="")return t;var i=String(e).toLowerCase();return!(i==="false"||i==="0"||i==="no"||i==="off")}function w(){for(var e={},t=0;t<arguments.length;t++)(function(i){!i||typeof i!="object"||Object.keys(i).forEach(function(r){i[r]!==void 0&&(e[r]=i[r])})})(arguments[t]);return e}function Q(e){if(!e||!e.getAttribute)return null;var t=e.getAttribute("data-zidan-options");if(!t)return null;try{var i=JSON.parse(t);return i&&typeof i=="object"&&!Array.isArray(i)?i:null}catch(r){return typeof console!="undefined"&&console.warn&&console.warn("[ZidanForm] ignoring invalid data-zidan-options JSON on",e,r),null}}function de(e,t,i){return Math.min(i,Math.max(t,e))}function ce(e,t){return String(e).replace(/\{(\w+)\}/g,function(i,r){return t&&t[r]!==void 0&&t[r]!==null?String(t[r]):i})}var Y={text:'<path d="M4 7h16M4 12h10M4 17h13"/>',mail:'<rect x="3" y="5" width="18" height="14" rx="2"/><path d="m3 7 9 6 9-6"/>',phone:'<path d="M22 16.9v3a2 2 0 0 1-2.2 2 19.8 19.8 0 0 1-8.6-3.1 19.5 19.5 0 0 1-6-6A19.8 19.8 0 0 1 2.1 4.2 2 2 0 0 1 4.1 2h3a2 2 0 0 1 2 1.7c.1 1 .4 1.9.7 2.8a2 2 0 0 1-.5 2.1L8.1 9.9a16 16 0 0 0 6 6l1.3-1.2a2 2 0 0 1 2.1-.5c.9.3 1.8.6 2.8.7a2 2 0 0 1 1.7 2Z"/>',user:'<circle cx="12" cy="8" r="4"/><path d="M4 21a8 8 0 0 1 16 0"/>',lock:'<rect x="4" y="10" width="16" height="11" rx="2"/><path d="M8 10V7a4 4 0 0 1 8 0v3"/>',search:'<circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/>',calendar:'<rect x="3" y="5" width="18" height="16" rx="2"/><path d="M16 3v4M8 3v4M3 11h18"/>',clock:'<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>',link:'<path d="M10 13a5 5 0 0 0 7 0l3-3a5 5 0 0 0-7-7l-1.5 1.5"/><path d="M14 11a5 5 0 0 0-7 0l-3 3a5 5 0 0 0 7 7l1.5-1.5"/>',hash:'<path d="M4 9h16M4 15h16M10 3 8 21M16 3l-2 18"/>',palette:'<path d="M12 3a9 9 0 0 0 0 18h1.5a2.5 2.5 0 0 0 0-5H12a2 2 0 0 1 0-4h4a5 5 0 0 0 0-10Z"/><circle cx="8.5" cy="8.5" r="1"/><circle cx="8" cy="14" r="1"/>',sliders:'<path d="M4 7h16M4 17h16"/><circle cx="9" cy="7" r="2.5"/><circle cx="15" cy="17" r="2.5"/>',file:'<path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/>',upload:'<path d="M12 16V4"/><path d="m7 9 5-5 5 5"/><path d="M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"/>',eye:'<path d="M2 12s3.5-6 10-6 10 6 10 6-3.5 6-10 6-10-6-10-6Z"/><circle cx="12" cy="12" r="3"/>',"eye-off":'<path d="m3 3 18 18"/><path d="M10.6 6.2A9.9 9.9 0 0 1 12 6c6.5 0 10 6 10 6a17 17 0 0 1-3.1 3.6"/><path d="M6.4 6.7C3.5 8.4 2 12 2 12s3.5 6 10 6c1.7 0 3.2-.4 4.5-1"/><path d="M9.9 9.9a3 3 0 0 0 4.2 4.2"/>',check:'<path d="m4 12.5 5 5L20 6.5"/>',x:'<path d="M6 6l12 12M18 6 6 18"/>',plus:'<path d="M12 5v14M5 12h14"/>',minus:'<path d="M5 12h14"/>',"chevron-down":'<path d="m6 9 6 6 6-6"/>',"chevron-up":'<path d="m6 15 6-6 6 6"/>',"chevron-left":'<path d="m15 6-6 6 6 6"/>',"chevron-right":'<path d="m9 6 6 6-6 6"/>',alert:'<path d="M12 9v4"/><path d="M12 17h.01"/><path d="M10.3 3.9 2.6 17.4A2 2 0 0 0 4.3 20h15.4a2 2 0 0 0 1.7-2.6L13.7 3.9a2 2 0 0 0-3.4 0Z"/>',info:'<circle cx="12" cy="12" r="9"/><path d="M12 11v5"/><path d="M12 8h.01"/>',globe:'<circle cx="12" cy="12" r="9"/><path d="M3 12h18"/><path d="M12 3a15 15 0 0 1 0 18 15 15 0 0 1 0-18Z"/>',"map-pin":'<path d="M20 10c0 6-8 12-8 12S4 16 4 10a8 8 0 1 1 16 0Z"/><circle cx="12" cy="10" r="3"/>',image:'<rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><path d="m21 15-5-5L5 21"/>',refresh:'<path d="M20 11a8 8 0 0 0-14.9-3.9L3 10"/><path d="M3 5v5h5"/><path d="M4 13a8 8 0 0 0 14.9 3.9L21 14"/><path d="M21 19v-5h-5"/>',trash:'<path d="M4 7h16"/><path d="M9 7V4h6v3"/><path d="M6 7l1 13h10l1-13"/><path d="M10 11v5M14 11v5"/>'},A={};Object.keys(Y).forEach(function(e){A[e]=Y[e]});var fe="http://www.w3.org/2000/svg",pe={svg:1,g:1,path:1,circle:1,rect:1,line:1,polyline:1,polygon:1,ellipse:1,title:1,defs:1,clipPath:1,clippath:1,mask:1};function ve(e){if(typeof e!="string"||!e.trim())return"";var t;try{if(typeof g.DOMParser=="undefined")return"";t=new g.DOMParser().parseFromString(e,"image/svg+xml")}catch{return""}if(!t||!t.documentElement)return"";var i=t.documentElement;if(String(i.nodeName).toLowerCase()!=="svg"||t.getElementsByTagName("parsererror").length)return"";var r=function(n){Array.prototype.slice.call(n.children||[]).forEach(function(a){var o=String(a.nodeName);if(o!==o.toLowerCase()&&(o=o.toLowerCase()),!pe[o]){a.parentNode.removeChild(a);return}Array.prototype.slice.call(a.attributes||[]).forEach(function(h){var l=String(h.name).toLowerCase();l.indexOf("on")===0&&a.removeAttribute(h.name),(l==="href"||l==="xlink:href")&&!/^#/.test(h.value)&&a.removeAttribute(h.name),/url\s*\(\s*['"]?\s*(?:https?:|\/\/)/i.test(h.value)&&a.removeAttribute(h.name)}),r(a)})};return r(i),i.outerHTML}function F(e){var t=e;return/^\s*</.test(t)&&!/^\s*<svg/i.test(t)?t='<svg xmlns="'+fe+'" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">'+t+"</svg>":/^\s*<svg/i.test(t)||(t=""),ve(t)}function Ae(e,t){var i="",r="";if(typeof e=="string"&&e?(r=e,/^\s*</.test(e)?i=F(e)||F('<path d="M4 12h16"/>'):A[e]&&(i=F(A[e])||"")):e&&typeof e=="object"&&e.name&&(r=e.name,i=F(A[e.name]||"")),!i)return null;var n=c.createElement("span");t&&(n.className=t),n.setAttribute("data-zs-icon",r||"custom");try{n.innerHTML=i}catch{return null}var a=n.firstChild;return a&&(a.setAttribute("focusable","false"),a.setAttribute("aria-hidden","true"),a.setAttribute("width","18"),a.setAttribute("height","18")),n}var me={text:"text",email:"mail",password:"lock",number:"hash",tel:"phone",url:"link",search:"search",date:"calendar",time:"clock","datetime-local":"calendar",month:"calendar",week:"calendar",range:"sliders",color:"palette"};function Le(e){return me[e]||""}function W(e,t){return typeof s!="undefined"&&(!e||typeof t!="string")?s:(e&&typeof t=="string"&&(A[String(e)]=t),typeof s!="undefined"?s:v)}function X(e,t,i,r,n){if(t&&t[i]!==void 0&&t[i]!==null)return t[i];if(e&&r&&e.getAttribute){var a=e.getAttribute("data-zidan-"+r);if(a!==null&&a!=="")return a}return n}function xe(e,t,i,r,n){if(t&&t[i]!==void 0&&t[i]!==null)return!!t[i];if(e&&r&&e.getAttribute){var a=e.getAttribute("data-zidan-"+r);if(a!==null)return E(a,n)}return n}function Me(e,t,i,r,n){var a=X(e,t,i,r,n);if(a==null||a==="")return n;var o=parseFloat(a);return isFinite(o)?o:n}function Ie(e,t,i,r,n){var a=X(e,t,i,r,null);return a==null||a===""?n:Array.isArray(a)?a.slice():String(a).split(",").map(function(o){return o.trim()}).filter(Boolean)}var D={required:"This field is required.",email:"Enter a valid email address.",url:"Enter a valid URL.",pattern:"The value does not match the expected format.",min:"Value must be at least {min}.",max:"Value must be at most {max}.",step:"Value must be a multiple of {step}.",minlength:"Use at least {minlength} characters.",maxlength:"Use at most {maxlength} characters.",badInput:"Enter a valid value.",phone:"Enter a valid phone number for {country}.",integer:"Enter a whole number.",date:"Enter a valid date.",weekend:"Weekends are not available \u2014 pick a weekday.",dateDisabled:"This date is not available.",fileType:"This file type is not allowed.",fileSize:"This file is too large.",fileCount:"Too many files.",pending:"Checking\u2026",generic:"Please check this field."};function Pe(e,t){if(!e||!e.validity||e.validity.valid)return"";var i=e.validity,r=t||D,n=String(e.type||"").toLowerCase(),a="",o={min:e.getAttribute("min"),max:e.getAttribute("max"),step:e.getAttribute("step")};return i.valueMissing?a="required":i.typeMismatch?a=n==="email"?"email":n==="url"?"url":"generic":i.patternMismatch?a="pattern":i.rangeUnderflow?a="min":i.rangeOverflow?a="max":i.stepMismatch?a="step":i.tooShort?(a="minlength",o.minlength=e.getAttribute("minlength")):i.tooLong?(a="maxlength",o.maxlength=e.getAttribute("maxlength")):(i.badInput||i.customError)&&(a="badInput"),a?ce(r[a]||D[a]||r.generic,o):e.validationMessage||r.generic}var J=["valueMissing","typeMismatch","patternMismatch","rangeUnderflow","rangeOverflow","stepMismatch","tooShort","tooLong","badInput","fileMissing"];function Fe(e){var t=e&&e.validity;if(!t)return!1;for(var i=0;i<J.length;i+=1)if(t[J[i]])return!0;return!1}function R(e,t){for(var i=e;i&&i.nodeType===1;){for(var r=0;r<t.length;r+=1){var n=i.getAttribute(t[r]);if(n)return n}i=i.parentElement}return""}function $(e,t,i){var r=String(e||"").toLowerCase();return t.indexOf(r)===-1?i:r}function Oe(e){if(Array.isArray(e))return e.slice();if(typeof e=="string"){var t=e.trim();if(t.charAt(0)==="[")try{var i=JSON.parse(t);if(Array.isArray(i))return i}catch{}else if(t.indexOf(",")!==-1)return t.split(",").map(function(r){return Number(r.trim())}).filter(function(r){return isFinite(r)})}return e}function ge(e,t){var i=t||{},r=i.theme||R(e,["data-zidan-theme","data-zs-theme"]);!r&&c&&(r=c.documentElement.getAttribute("data-zs-theme")||"");var n=i.framework||R(e,["data-zidan-framework","data-zs-framework"]);!n&&c&&(n=c.documentElement.getAttribute("data-zs-framework")||"");var a=i.layout||R(e,["data-zidan-layout","data-zs-layout"]);return{theme:$(r,H,"default"),framework:$(n,C,"none"),layout:a?String(a).toLowerCase():""}}function ye(e,t){var i=null;function r(){var n=arguments;clearTimeout(i),i=setTimeout(function(){i=null,e.apply(null,n)},t)}return r.cancel=function(){clearTimeout(i),i=null},r}var _={mode:null,layout:"classic-clean",themeFramework:"auto",id:null,name:null,disabled:!1,required:!1,options:null,value:null,label:null,placeholder:null,multiple:!1,searchable:null,clearable:!1,closeOnSelect:null,maxDropdownHeight:280,noResultsText:"No results found",emptyText:"No options",loadingText:"Searching\u2026",clearText:"Clear selection",fetchOptions:null,debounce:250,minChars:0,allowFreeText:!1,searchValues:!0,fetchPageSize:0,autoLoadMore:!0,cacheResults:!0,loadMoreText:"Load more",fetchUrl:null,fetchMethod:"GET",fetchQueryParam:"q",fetchPageParam:"page",fetchSkipParam:null,fetchPageSizeParam:"limit",fetchItemsPath:null,fetchTotalPath:null,fetchHasMorePath:null,fetchHeaders:null,fetchCredentials:"same-origin",maxTags:1/0,minTagLength:1,maxTagLength:1/0,caseSensitive:!1,delimiters:[","],commitOnTab:!1,commitOnBlur:!1,suggestions:null,valueDelimiter:",",customClasses:{},validation:null,scrollbar:"default",filterOption:null,renderOption:null,renderSelected:null,renderTag:null,validateTag:null,formatTag:null,onInit:null,onChange:null,onSelect:null,onOpen:null,onClose:null,onTagAdd:null,onTagRemove:null,onLoadMore:null,onError:null};function Z(e,t){if(t)return String(t).split(".").reduce(function(i,r){return i==null?void 0:i[r]},e)}function be(e){if(Array.isArray(e))return e;if(!e||typeof e!="object")return[];for(var t=["items","data","results","options","rows","products","records"],i=0;i<t.length;i++)if(Array.isArray(e[t[i]]))return e[t[i]];return[]}function _e(e){if(e==null)return null;if(typeof e!="object"){var t=String(e);return{value:t,label:t}}var i=e.value!==void 0?e.value:e.id!==void 0?e.id:e.slug!==void 0?e.slug:e.code!==void 0?e.code:e.key!==void 0?e.key:void 0,r=e.label!==void 0?e.label:e.name!==void 0?e.name:e.title!==void 0?e.title:e.full_name!==void 0?e.full_name:e.text!==void 0?e.text:void 0;return r===void 0&&(r=i===void 0?"":i),i===void 0&&(i=r),{value:i,label:r,disabled:!!e.disabled}}function Se(e){return function(t,i,r){if(typeof fetch!="function")return Promise.reject(new Error("This environment has no fetch()."));var n=r&&r.page?r.page:0,a=e.fetchPageSize>0?e.fetchPageSize:0,o;try{o=new URL(e.fetchUrl,typeof location!="undefined"&&location.href||void 0)}catch{return Promise.reject(new Error("Invalid fetchUrl: "+e.fetchUrl))}e.fetchQueryParam&&o.searchParams.set(e.fetchQueryParam,t||""),a>0&&e.fetchPageSizeParam&&o.searchParams.set(e.fetchPageSizeParam,String(a)),e.fetchSkipParam?a>0&&o.searchParams.set(e.fetchSkipParam,String(n*a)):e.fetchPageParam&&o.searchParams.set(e.fetchPageParam,String(n+1));var h={Accept:"application/json"};return e.fetchHeaders&&typeof e.fetchHeaders=="object"&&Object.keys(e.fetchHeaders).forEach(function(l){h[l]=e.fetchHeaders[l]}),fetch(o.toString(),{method:e.fetchMethod||"GET",headers:h,signal:i,credentials:e.fetchCredentials||"same-origin"}).then(function(l){if(!l.ok)throw new Error("Request failed ("+l.status+" "+(l.statusText||"error")+")");return l.json()}).then(function(l){var d=e.fetchItemsPath?Z(l,e.fetchItemsPath):be(l);Array.isArray(d)||(d=d==null?[]:[d]);var y=d.map(_e).filter(Boolean),u;e.fetchHasMorePath&&(u=!!Z(l,e.fetchHasMorePath));var f=e.fetchTotalPath?Z(l,e.fetchTotalPath):l&&typeof l=="object"?l.total:void 0,p=f==null?NaN:Number(f);return u===void 0&&isFinite(p)&&a>0&&(u=(n+1)*a<p),u===void 0&&(u=a>0&&y.length>=a),{items:y,hasMore:u,total:isFinite(p)?p:void 0}})}}function s(e,t){if(!(this instanceof s))return new s(e,t);if(!c)throw new Error("ZidanSelect requires a DOM environment.");var i=typeof e=="string"?c.querySelector(e):e;if(!b(i))throw new Error("ZidanSelect: target element not found.");i.__zidanSelect instanceof s&&i.__zidanSelect.destroy(),this.el=i,this.opts=this._normalizeOptions(t||{}),this.mode=this.opts.mode,this.layout=this.opts.layout,this.id=this.opts.id||he("zs"),this.isMount=/^(DIV|SPAN|SECTION|ARTICLE|FORM-FIELD)$/i.test(i.tagName)||(i.hasAttribute("data-zidan-select")||G(i,"zidan-select"))&&!/^(SELECT|INPUT|TEXTAREA)$/i.test(i.tagName),this.native=this.isMount?null:i,this.syncEl=null,this.items=[],this.value_=[],this.tags=[],this.activeIndex=-1,this.opened=!1,this.loading=!1,this.error=null,this.query="",this.rendered=[],this.listeners=new Map,this.asyncController=null,this.asyncItems=null,this.asyncQuery="",this.asyncPage=0,this.hasMore=!1,this.fetchingMore=!1,this.loadMoreError=null,this._fetchCache=Object.create(null),this._cacheKeys=[],this.timer=null,this.savedInputText="",this.disabled_=!!this.opts.disabled,this.destroyed=!1,this.resizeObserver=null,this._prepareData(),this._build(),this._prepareSync(),this._bind(),this._setInitialValue(),this._render(),this._observeResize(),i.__zidanSelect=this,this.emit("init",{instance:this,mode:this.mode,layout:this.layout,framework:this.framework}),this.call("onInit",{instance:this,mode:this.mode,value:this.getValue()})}s.prototype._normalizeOptions=function(e){e=w(Q(this.el),e);var t=this.el.dataset||{},i=this.el.tagName==="SELECT",r=/tags/i.test(t.zidanSelect||"")||/tags/i.test(t.zidanMode||""),n=e.mode||t.zidanMode||t.zidanSelect||(r?"tags":"select");n=String(n).toLowerCase(),(n==="multi"||n==="multiselect")&&(n="select"),["select","combobox","tags"].indexOf(n)===-1&&(n="select");var a=i?this.el.multiple:!1,o=e.themeFramework||t.zidanFramework||"auto";o=String(o).toLowerCase(),C.indexOf(o)===-1&&(o="auto");var h=e.layout||t.zidanLayout||"classic-clean";h=String(h).toLowerCase(),M.indexOf(h)===-1&&(h="classic-clean");var l=e.scrollbar||t.zidanScrollbar||_.scrollbar;l=String(l).toLowerCase(),I.indexOf(l)===-1&&(l=_.scrollbar);var d=function(f,p){return e[f]!==void 0&&e[f]!==null?e[f]:p},y=n==="tags"?"Add a tag\u2026":n==="combobox"?"Type to search\u2026":"Select an option\u2026",u={};return Object.keys(_).forEach(function(f){u[f]=_[f]}),u.mode=n,u.layout=h,u.themeFramework=o,u.multiple=n==="tags"?!0:d("multiple",a||E(t.zidanMultiple,!1)),u.searchable=d("searchable",E(t.zidanSearchable,n!=="select")),u.clearable=d("clearable",E(t.zidanClearable,!1)),u.disabled=d("disabled",E(t.zidanDisabled,i?this.el.disabled:!1)),u.placeholder=d("placeholder",t.zidanPlaceholder||this.el.getAttribute&&this.el.getAttribute("placeholder")||y),u.label=d("label",t.zidanLabel||null),u.name=d("name",t.zidanName||this.el.getAttribute&&this.el.getAttribute("name")||null),u.allowFreeText=d("allowFreeText",E(t.zidanAllowFreeText,n==="tags")),u.maxTags=d("maxTags",t.zidanMaxTags?parseInt(t.zidanMaxTags,10)||1/0:_.maxTags),u.minTagLength=d("minTagLength",t.zidanMinTagLength?parseInt(t.zidanMinTagLength,10)||1:_.minTagLength),u.maxTagLength=d("maxTagLength",t.zidanMaxTagLength?parseInt(t.zidanMaxTagLength,10)||1/0:_.maxTagLength),u.caseSensitive=d("caseSensitive",E(t.zidanCaseSensitive,!1)),u.validation=d("validation",t.zidanValidation||null),u.options=d("options",null),u.suggestions=d("suggestions",null),u.fetchPageSize=d("fetchPageSize",t.zidanFetchPageSize?parseInt(t.zidanFetchPageSize,10)||0:_.fetchPageSize),u.autoLoadMore=d("autoLoadMore",E(t.zidanAutoLoadMore,_.autoLoadMore)),u.cacheResults=d("cacheResults",E(t.zidanCacheResults,_.cacheResults)),u.loadMoreText=d("loadMoreText",t.zidanLoadMoreText||_.loadMoreText),u.fetchUrl=d("fetchUrl",t.zidanFetchUrl||null),u.fetchMethod=d("fetchMethod",t.zidanFetchMethod||_.fetchMethod),u.fetchQueryParam=d("fetchQueryParam",t.zidanFetchQueryParam!==void 0?t.zidanFetchQueryParam:_.fetchQueryParam),u.fetchPageParam=d("fetchPageParam",t.zidanFetchPageParam!==void 0?t.zidanFetchPageParam:_.fetchPageParam),u.fetchSkipParam=d("fetchSkipParam",t.zidanFetchSkipParam||null),u.fetchPageSizeParam=d("fetchPageSizeParam",t.zidanFetchPageSizeParam!==void 0?t.zidanFetchPageSizeParam:_.fetchPageSizeParam),u.fetchItemsPath=d("fetchItemsPath",t.zidanFetchItemsPath||null),u.fetchTotalPath=d("fetchTotalPath",t.zidanFetchTotalPath||null),u.fetchHasMorePath=d("fetchHasMorePath",t.zidanFetchHasMorePath||null),Object.keys(e).forEach(function(f){e[f]!==void 0&&(u[f]=e[f])}),u.mode=n,u.layout=h,u.themeFramework=o,u.scrollbar=l,u.theme||(u.theme=t.zidanTheme||t.zsTheme||""),n==="combobox"&&(u.searchable=!0),n==="tags"&&u.searchable===!1&&(u.searchable=!0),n==="tags"&&(u.multiple=!0),u.fetchUrl&&typeof u.fetchOptions!="function"&&(u.fetchOptions=Se(u)),u},s.prototype._prepareData=function(){var e=this.opts.options;if(!e&&this.el.tagName==="SELECT"&&(e=this._optionsFromSelect(this.el)),e||(e=this.opts.suggestions||[]),this.items=this._normalizeItems(e),this.mode==="tags"){var t=this.opts.suggestions||this.opts.options;!t&&this.el.tagName==="SELECT"&&(t=this._optionsFromSelect(this.el)),this.suggestions=this._normalizeItems(t||[])}},s.prototype._optionsFromSelect=function(e){var t=[];return Array.prototype.slice.call(e.children||[]).forEach(function(i){if(i.tagName==="OPTGROUP"){var r=i.label||"";Array.prototype.slice.call(i.children).forEach(function(n){n.tagName==="OPTION"&&t.push({value:n.value,label:n.textContent.trim(),group:r,disabled:n.disabled})})}else i.tagName==="OPTION"&&t.push({value:i.value,label:i.textContent.trim(),disabled:i.disabled})}),t},s.prototype._normalizeItems=function(e){var t=T(e),i=[],r=this;return t.forEach(function(n,a){if(n!=null){if(typeof n=="string"||typeof n=="number"){i.push({value:String(n),label:String(n),group:null,disabled:!1});return}if(typeof n=="object"&&Array.isArray(n.options)){var o=n.label!==void 0?String(n.label):n.group||"";r._normalizeItems(n.options).forEach(function(l){l.group=o,i.push(l)});return}if(typeof n=="object"){var h=n.value!==void 0?n.value:n.label!==void 0?n.label:a;i.push({value:String(h),label:n.label!==void 0?String(n.label):String(h),group:n.group!==void 0?String(n.group):null,disabled:!!n.disabled,data:n.data})}}}),i},s.prototype._resolveFramework=function(){if(this.opts.themeFramework&&this.opts.themeFramework!=="auto")return this.opts.themeFramework;if(!c)return"vanilla";try{var e=g.getComputedStyle(c.documentElement),t=e.getPropertyValue("--bs-body-bg");if(t&&t.trim())return"bootstrap";for(var i=c.styleSheets||[],r=0;r<i.length;r+=1){var n=i[r].href||"";if(/bootstrap(\.min)?\.css/i.test(n))return"bootstrap";if(/tailwind/i.test(n))return"tailwind"}if(c.body&&g.getComputedStyle(c.body).getPropertyValue("--tw-ring-offset-shadow")!=="")return"tailwind";if(c.querySelector(".btn-primary, .form-select, .form-control, .navbar"))return"bootstrap"}catch{}return"vanilla"},s.prototype._applyCustomClass=function(e,t){var i=this.opts.customClasses||{},r=i[t];return r&&K(e,r),e},s.prototype._toggleCustomClass=function(e,t,i){var r=this.opts.customClasses||{},n=r[t];return n&&String(n).split(/\s+/).forEach(function(a){a&&(i?e.classList.add(a):e.classList.remove(a))}),e},s.prototype._build=function(){var e=this,t=this.opts;this.framework=this._resolveFramework();var i=this.el.parentNode&&this.el.parentNode.classList&&this.el.parentNode.classList.contains("zs-root--mount"),r=ge(this.el,{theme:t.theme,framework:t.themeFramework,layout:t.layout});this.theme=r.theme;var n=m("div","zs-root");n.id=this.id+"-root",n.setAttribute("data-zs-theme",this.theme),n.setAttribute("data-zs-layout",this.layout),n.setAttribute("data-zs-framework",this.framework),n.setAttribute("data-zs-mode",this.mode),n.setAttribute("data-zs-scrollbar",t.scrollbar||"default"),ue(this.el)&&n.setAttribute("dir","rtl"),n.classList.add("zs-root--"+this.mode),this.mode==="tags"&&n.classList.add("zs-root--multiple"),t.multiple&&this.mode==="select"&&n.classList.add("zs-root--multiple"),this.layout==="floating-label"&&n.classList.add("zs-root--labeled"),this._applyCustomClass(n,"root");var a=m("div","zs-control");this.framework==="bootstrap"&&(a.classList.add("form-control","zs-bootstrap-control"),this.el.tagName==="SELECT"&&a.classList.add("form-select")),this._applyCustomClass(a,"control");var o=m("div","zs-chips");o.hidden=!0;var h=c.createElement("input");h.type="text",h.className="zs-input",h.id=this.id+"-input",h.autocomplete="off",h.spellcheck=!1,h.setAttribute("role","combobox"),h.setAttribute("aria-expanded","false"),h.setAttribute("aria-controls",this.id+"-listbox"),h.setAttribute("aria-autocomplete",t.searchable||this.mode!=="select"?"list":"none"),h.setAttribute("aria-haspopup","listbox"),this.mode==="select"&&!t.searchable&&(h.readOnly=!0),(t.ariaLabel||t.label)&&h.setAttribute("aria-label",t.ariaLabel||t.label),t.disabled&&(h.disabled=!0),this._applyCustomClass(h,"input");var l=null;if(t.label){l=m("label","zs-label",{for:h.id}),l.textContent=t.label,this.layout!=="floating-label"&&n.classList.add("zs-root--has-static-label");var d=this.el.labels&&this.el.labels[0]?this.el.labels[0]:null;d&&d.closest&&d.closest(".zs-root")&&(d=null),this._authorLabel=d||null,d&&(d.hidden=!0,d.setAttribute("data-zs-hidden-label","true"))}var y=m("button","zs-clear",{type:"button",tabindex:"-1","aria-label":t.clearText,title:t.clearText});y.innerHTML='<svg viewBox="0 0 16 16" width="12" height="12" aria-hidden="true" focusable="false"><path d="M3 3l10 10M13 3L3 13" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>',y.hidden=!0;var u=m("span","zs-arrow",{"aria-hidden":"true"});u.innerHTML='<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" focusable="false"><path d="M3.5 6l4.5 4.5L12.5 6" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/></svg>',a.appendChild(o),a.appendChild(h),a.appendChild(y),a.appendChild(u),l&&(this.layout==="floating-label"?a.insertBefore(l,o):n.appendChild(l));var f=m("div","zs-dropdown");f.id=this.id+"-listbox",f.setAttribute("role","listbox"),f.setAttribute("aria-multiselectable",String(!!(t.multiple||this.mode==="tags"))),this._applyCustomClass(f,"dropdown");var p=m("div","zs-live",{"aria-live":"polite","aria-atomic":"true"});n.appendChild(a),n.appendChild(f),n.appendChild(p),this.framework==="bootstrap"&&(t.validation==="invalid"&&a.classList.add("is-invalid"),t.validation==="valid"&&a.classList.add("is-valid"),(this.mode==="tags"||t.multiple)&&n.classList.add("zs-root--bootstrap")),this.isMount?(i||this.el.classList.add("zs-root--mount"),this.el.appendChild(n)):this.el.parentNode.insertBefore(n,this.el),this.root=n,this.controlEl=a,this.chipsEl=o,this.input=h,this.dropdown=f,this.clearBtn=y,this.arrowEl=u,this.labelEl=l,this.liveEl=p},s.prototype._prepareSync=function(){var e=this,t=this.opts;if(this.native)this.native.tagName==="SELECT"?(this.syncEl=this.native,this.native.multiple&&(this.opts.multiple=!0,this.root.classList.add("zs-root--multiple")),this.native.hidden=!0,this.native.classList.add("zs-native"),this.native.setAttribute("tabindex","-1"),this.native.setAttribute("aria-hidden","true")):(this.syncEl=this.native,this.native.hidden=!0,this.native.setAttribute("tabindex","-1"),this.native.setAttribute("aria-hidden","true")),t.required&&this.input.setAttribute("aria-required","true"),this.form=this.native.closest?this.native.closest("form"):null;else if(t.name){var i=m("input","zs-hidden",{type:"hidden",name:t.name});this.root.appendChild(i),this.syncEl=i,this.form=this.el.closest?this.el.closest("form"):null}else this.form=this.el.closest?this.el.closest("form"):null;return this.form&&(this.onFormReset=function(){setTimeout(function(){e._handleFormReset()},0)},this.form.addEventListener("reset",this.onFormReset)),t.required&&this.native&&this.native.tagName==="SELECT"&&!this.native.required?(this.native.required=!0,this._nativeRequiredAdded=!0):t.required&&!this.native&&this.form&&(this.onFormSubmit=function(r){e.value_.length||(r.preventDefault(),e.setValidation("invalid"),e.input&&e.input.focus&&e.input.focus(),e.announce("Please select an option."))},this.form.addEventListener("submit",this.onFormSubmit)),this.syncEl},s.prototype._setInitialValue=function(){var e=this.opts,t=e.value;if(t==null&&(this.native&&this.native.tagName==="SELECT"?t=this.native.multiple?Array.prototype.filter.call(this.native.options,function(r){return r.selected}).map(function(r){return r.value}):this.native.value:this.native&&(t=this.native.value)),this.mode==="tags"){var i=t;typeof i=="string"&&i&&!Array.isArray(i)&&this.syncEl&&this.syncEl.tagName!=="SELECT"&&(i=i.split(e.valueDelimiter)),T(i).forEach(function(r){this._addTagObject(String(r),{silent:!0})},this);return}t==null||t===""||this._setValueInternal(t,{silent:!0})},s.prototype._handleFormReset=function(){var e;if(this.native&&this.native.tagName==="SELECT"?e=this.native.multiple?Array.prototype.filter.call(this.native.options,function(t){return t.selected}).map(function(t){return t.value}):this.native.value:this.native?e=this.native.value:this.opts.value!==null&&this.opts.value!==void 0&&(e=this.opts.value),this.mode==="tags"){this.value_=[],T(e).forEach(function(t){this._addTagObject(t,{silent:!0})},this),this._render(),this._syncNative();return}this._setValueInternal(e,{silent:!0}),this._render()},s.prototype._hasValue=function(e){for(var t=this.opts.caseSensitive?String(e):String(e).toLowerCase(),i=0;i<this.value_.length;i+=1){var r=this.opts.caseSensitive?this.value_[i].value:this.value_[i].value.toLowerCase();if(r===t)return!0}return!1},s.prototype._itemFor=function(e){for(var t=String(e),i=0;i<this.items.length;i+=1)if(this.items[i].value===t)return this.items[i];for(var r=0;r<this.value_.length;r+=1)if(this.value_[r].value===t)return this.value_[r];return{value:t,label:t}},s.prototype._setValueInternal=function(e,t){var i=t||{},r=this.getValue(),n=this,a=T(e),o=[];if(a.forEach(function(l){if(!(l==null||l==="")){if(typeof l=="object"){o.push({value:String(l.value!==void 0?l.value:l.label),label:String(l.label!==void 0?l.label:l.value),data:l.data});return}for(var d=String(l),y=null,u=0;u<n.items.length;u+=1)if(n.items[u].value===d){y=n.items[u];break}o.push(y?{value:y.value,label:y.label,data:y.data}:{value:d,label:d})}}),!this.opts.multiple&&this.mode!=="tags"&&(o=o.slice(0,1)),this.value_=o,o.length&&this.opts.validation==="invalid"&&!i.silent&&(this.opts.validation=null),this._render(),this._syncNative(),!i.silent){var h=this.getValue();h!==r&&JSON.stringify(h)!==JSON.stringify(r)&&(this.emit("change",{value:h,previousValue:r,instance:this}),this.call("onChange",{value:h,previousValue:r,instance:this}))}return this},s.prototype._syncNative=function(){var e=this.syncEl;if(e){var t=this.value_.map(function(h){return h.value});if(e.tagName==="SELECT"){var i;if(e.multiple){for(i=0;i<e.options.length;i+=1)e.options[i].selected=t.indexOf(e.options[i].value)!==-1;var r=Array.prototype.map.call(e.options,function(h){return h.value});t.forEach(function(h){if(r.indexOf(h)===-1){var l=c.createElement("option");l.value=h,l.textContent=h,l.selected=!0,e.appendChild(l)}})}else{var n=t[0];if(n===void 0)e.value="";else{var a=!1;for(i=0;i<e.options.length;i+=1)if(e.options[i].value===n){a=!0;break}if(!a){var o=c.createElement("option");o.value=n,o.textContent=this._itemFor(n).label,e.appendChild(o)}e.value=n}}}else e.value=this.opts.multiple||this.mode==="tags"?t.join(this.opts.valueDelimiter):t[0]||""}},s.prototype._render=function(){var e=this.opts,t=this.value_.length>0;this.root.classList.toggle("zs-root--has-value",t),this.root.classList.toggle("zs-root--open",this.opened),this.root.classList.toggle("zs-root--disabled",!!this.disabled_),this.root.classList.toggle("zs-root--invalid",e.validation==="invalid"),this.root.classList.toggle("zs-root--valid",e.validation==="valid"),e.validation==="invalid"?this.root.setAttribute("data-zs-validation","invalid"):e.validation==="valid"?this.root.setAttribute("data-zs-validation","valid"):this.root.removeAttribute("data-zs-validation"),e.validation==="invalid"?this.input.setAttribute("aria-invalid","true"):e.validation==="valid"?this.input.setAttribute("aria-invalid","false"):this.input.removeAttribute("aria-invalid"),(this.el.required||e.required)&&this.input.setAttribute("aria-required","true"),e.validation==="invalid"?this.controlEl.classList.add("is-invalid"):this.controlEl.classList.remove("is-invalid"),e.validation==="valid"?this.controlEl.classList.add("is-valid"):this.controlEl.classList.remove("is-valid"),this._toggleCustomClass(this.controlEl,"invalid",e.validation==="invalid"),this._renderChips(),this._renderInputValue();var i=e.clearable&&t&&!this.disabled_;return this.clearBtn.hidden=!i,this.clearBtn.tabIndex=i?0:-1,this.input.disabled=!!this.disabled_,this.input.setAttribute("aria-expanded",String(this.opened)),this.root.classList.toggle("zs-root--placeholder",!this.input.value&&!t),this},s.prototype._renderChips=function(){var e=this,t=this.mode==="tags"||!!this.opts.multiple,i=this.chipsEl;i.textContent="",i.hidden=!t,t&&(this.value_.forEach(function(r,n){var a=m("span","zs-chip",{"data-zs-index":n});e.framework==="bootstrap"&&K(a,"badge rounded-pill"),e._applyCustomClass(a,"chip");var o,h=typeof e.opts.renderTag=="function"&&e.mode==="tags"?e.opts.renderTag({value:r.value,label:r.label},{index:n,instance:e,disabled:e.disabled_}):null;if(e.mode==="select"&&typeof e.opts.renderSelected=="function"&&(h=e.opts.renderSelected({value:r.value,label:r.label},{index:n,instance:e})),h)if(b(h))o=h,a.appendChild(o);else{var l=m("span","zs-chip-label");l.innerHTML=String(h),a.appendChild(l)}else o=m("span","zs-chip-label",null,r.label),a.appendChild(o);var d=m("button","zs-chip-remove",{type:"button","aria-label":"Remove "+r.label,title:"Remove "+r.label,"data-zs-remove":n});d.innerHTML='<svg viewBox="0 0 16 16" width="10" height="10" aria-hidden="true" focusable="false"><path d="M4 4l8 8M12 4l-8 8" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',e._applyCustomClass(d,"chipRemove"),a.appendChild(d),i.appendChild(a)}),this.root.classList.toggle("zs-root--has-value",this.value_.length>0))},s.prototype._renderInputValue=function(){var e=this.mode!=="tags"&&!this.opts.multiple;if(!e){this.input.placeholder=this.value_.length?"":this.opts.placeholder||"",this.opened?this.input.value=this.query:this.input.value="";return}if(this.opened&&this.opts.searchable){this.input.value=this.query,this.input.placeholder=this.opts.placeholder||"";return}if(this.opened&&!this.opts.searchable){this.input.value=this.value_.length?this.value_[0].label:"",this.input.placeholder=this.opts.placeholder||"";return}this.input.value=this.value_.length?this.value_[0].label:"",this.input.placeholder=this.opts.placeholder||"",this.value_.length||(this.input.value="")},s.prototype._sourceItems=function(){return this.mode==="tags"?this.suggestions||[]:typeof this.opts.fetchOptions=="function"&&this.asyncItems?this.asyncItems:this.items},s.prototype._visibleItems=function(){var e=this,t=this.query.trim(),i=this._sourceItems(),r=!!this.opts.caseSensitive,n=typeof this.opts.fetchOptions=="function"&&!!this.asyncItems;return!t||n&&typeof this.opts.filterOption!="function"?i.slice():i.filter(function(a){if(typeof e.opts.filterOption=="function")return!!e.opts.filterOption(a,t,{instance:e,mode:e.mode,caseSensitive:r,selected:e._hasValue(a.value)});var o=r?a.label:a.label.toLowerCase(),h=r?t:t.toLowerCase();if(o.indexOf(h)!==-1)return!0;if(e.opts.searchValues){var l=r?a.value:a.value.toLowerCase();if(l.indexOf(h)!==-1)return!0}return!1})},s.prototype._renderDropdown=function(){var e=this;if(this.opened){var t=this.dropdown.scrollTop;if(this.dropdown.textContent="",this.rendered=[],this.loading){var i=m("div","zs-state zs-state--loading",{role:"status"});i.appendChild(m("span","zs-spinner",{"aria-hidden":"true"})),i.appendChild(m("span","zs-state-text",null,this.opts.loadingText)),this.dropdown.appendChild(i)}else if(this.error){var r=m("div","zs-state zs-state--error",{role:"status"},this.error.message||"Something went wrong.");this.dropdown.appendChild(r)}else{var n=this._visibleItems();if(n.length){var o=null;n.forEach(function(l,d){if(l.group&&l.group!==o){var y=m("div","zs-group",{role:"presentation"},l.group);e.dropdown.appendChild(y),o=l.group}var u=e._hasValue(l.value),f=m("div","zs-option",{role:"option",id:e.id+"-opt-"+d,"data-zs-option":d});f.setAttribute("aria-selected",String(u)),l.disabled&&(f.setAttribute("aria-disabled","true"),f.classList.add("zs-option--disabled")),u&&f.classList.add("zs-option--selected"),e._applyCustomClass(f,"option"),u&&e._applyCustomClass(f,"selected"),l.disabled&&e._applyCustomClass(f,"disabled");var p=null;typeof e.opts.renderOption=="function"&&(p=e.opts.renderOption(l,{index:d,selected:u,active:d===e.activeIndex,query:e.query,instance:e})),p&&b(p)?f.appendChild(p):p!=null&&p!==""?f.innerHTML=String(p):f.appendChild(m("span","zs-option-label",null,l.label)),d===e.activeIndex&&(f.classList.add("zs-option--active"),e._applyCustomClass(f,"active")),e.rendered.push({element:f,item:l,index:d}),e.dropdown.appendChild(f)})}else{var a=this.query?this.opts.noResultsText:this.opts.emptyText;this.dropdown.appendChild(m("div","zs-state zs-state--empty",{role:"status"},a)),this.emit("no-results",{query:this.query,instance:this})}if(this.hasMore){var h=m("button","zs-more",{type:"button"});this.fetchingMore?(h.appendChild(m("span","zs-spinner",{"aria-hidden":"true"})),h.appendChild(m("span",null,null,this.opts.loadingText||"Loading\u2026")),h.disabled=!0,h.setAttribute("aria-busy","true")):(h.textContent=this.loadMoreError||this.opts.loadMoreText,this.loadMoreError&&h.classList.add("zs-more--error")),this.dropdown.appendChild(h)}}this.dropdown.scrollTop=t,this._updateActiveDescendant(!1),this.opened&&this._position()}},s.prototype._updateActiveDescendant=function(e){var t=this.rendered[this.activeIndex];if(t){if(this.input.setAttribute("aria-activedescendant",t.element.id),e!==!1){var i=t.element.offsetTop,r=i+t.element.offsetHeight;i<this.dropdown.scrollTop?this.dropdown.scrollTop=i-4:r>this.dropdown.scrollTop+this.dropdown.clientHeight&&(this.dropdown.scrollTop=r-this.dropdown.clientHeight+4)}}else this.input.removeAttribute("aria-activedescendant")},s.prototype._position=function(){if(this.opened){var e=this.controlEl.getBoundingClientRect(),t=g.innerHeight||c.documentElement.clientHeight,i=t-e.bottom-12,r=e.top-12,n=i<160&&r>i;this.root.classList.toggle("zs-root--dropup",n);var a=n?r:i,o=de(a,120,this.opts.maxDropdownHeight||280);this.dropdown.style.maxHeight=Math.max(120,o)+"px";var h=e.width;this.dropdown.style.minWidth=h+"px",this.root.classList.contains("zs-root--mount")&&(this.dropdown.style.left="0px",this.dropdown.style.right="0px")}},s.prototype.open=function(){if(this.destroyed||this.disabled_||this.opened)return this;if(this.opened=!0,this.query="",this.activeIndex=-1,this.loadMoreError=null,this.fetchingMore=!1,(this.mode==="combobox"||this.mode==="select"&&this.opts.searchable)&&(this.savedInputText=this.input.value),this.root.classList.add("zs-root--open"),this.dropdown.setAttribute("data-zs-visible","true"),this._render(),this._renderDropdown(),this._position(),this.emit("open",{instance:this}),this.call("onOpen",{instance:this}),typeof this.opts.fetchOptions=="function"&&(!this.asyncItems||this.asyncQuery!==""))this._fetch("");else if(this.mode!=="tags"){var e=this._firstEnabledIndex();e!==-1&&(this.activeIndex=e,this._renderDropdown())}if(this.opts.searchable&&!this.disabled_)try{this.input.select()}catch{this.input.focus()}var t=this._visibleItems();return this.announce(t.length+" option"+(t.length===1?"":"s")+" available"),this},s.prototype.close=function(){return this.destroyed||!this.opened?this:(this.opened=!1,this.root.classList.remove("zs-root--open"),this.dropdown.removeAttribute("data-zs-visible"),this.activeIndex=-1,this.query="",typeof this.opts.fetchOptions=="function"&&(this.asyncController&&(this.asyncController.abort(),this.asyncController=null),this.loading=!1,this.fetchingMore=!1,this.loadMoreError=null),this._render(),this.emit("close",{instance:this}),this.call("onClose",{instance:this}),this)},s.prototype.toggle=function(){return this.opened?this.close():this.open()},s.prototype._firstEnabledIndex=function(){for(var e=this._visibleItems(),t=0;t<e.length;t+=1)if(!e[t].disabled)return t;return-1},s.prototype._selectRendered=function(e){var t=this.rendered[e];return!t||t.item.disabled?!1:(this._selectItem(t.item),!0)},s.prototype._selectItem=function(e){if(!e||e.disabled)return this;var t=this.getValue();if(this.mode==="tags")return this.addTag(e.label),this.query="",this._renderDropdown(),this;if(this.mode==="combobox"&&this.opts.allowFreeText)this._setValueInternal([e.value]);else if(this.opts.multiple){if(this._hasValue(e.value)){this.value_=this.value_.filter(function(n){return n.value!==e.value}),this._render(),this._syncNative();var i=this.getValue();return JSON.stringify(i)!==JSON.stringify(t)&&(this.emit("change",{value:i,previousValue:t,instance:this}),this.call("onChange",{value:i,previousValue:t,instance:this})),this._renderDropdown(),this}this._setValueInternal(this.value_.concat([e]))}else this._setValueInternal([e]);this.emit("select",{value:this.getValue(),item:e,instance:this}),this.call("onSelect",{value:this.getValue(),item:e,instance:this});var r=this.opts.closeOnSelect===null?!this.opts.multiple:this.opts.closeOnSelect;return r?this.close():this.opened&&this._renderDropdown(),this},s.prototype._cacheKey=function(e,t){return e+"\0"+t},s.prototype._cacheGet=function(e,t){if(!this.opts.cacheResults)return null;var i=this._cacheKey(e,t),r=this._fetchCache[i];if(!r)return null;var n=this._cacheKeys.indexOf(i);return n!==-1&&(this._cacheKeys.splice(n,1),this._cacheKeys.push(i)),r},s.prototype._cacheSet=function(e,t,i){if(this.opts.cacheResults){var r=this._cacheKey(e,t);this._fetchCache[r]=i;var n=this._cacheKeys.indexOf(r);n!==-1&&this._cacheKeys.splice(n,1),this._cacheKeys.push(r);for(var a=s.cacheLimit||50;this._cacheKeys.length>a;)delete this._fetchCache[this._cacheKeys.shift()]}},s.prototype.clearCache=function(){return this._fetchCache=Object.create(null),this._cacheKeys=[],this},s.prototype._readFetchPayload=function(e,t,i){var r=e,n=!1;return e&&!Array.isArray(e)&&typeof e=="object"?(r=e.items||e.options||e.results||[],e.hasMore!==void 0?n=!!e.hasMore:e.total!==void 0&&i>0?n=(t+1)*i<Number(e.total):i>0&&(n=T(r).length>=i)):i>0&&(n=T(r).length>=i),{items:this._normalizeItems(r),hasMore:n}},s.prototype._applyCachedPage=function(e,t,i){var r=this._cacheGet(e,t);return r?(this.loading=!1,this.fetchingMore=!1,this.loadMoreError=null,this.error=null,this.asyncQuery=e,this.asyncPage=t,this.asyncItems=i?(this.asyncItems||[]).concat(r.items):r.items.slice(),this.hasMore=!!r.hasMore,i||(this.activeIndex=-1),this._renderDropdown(),!0):!1},s.prototype._fetch=function(e,t,i){var r=this;if(typeof this.opts.fetchOptions!="function")return Promise.resolve([]);if(e=e==null?"":String(e),t=t==null?0:parseInt(t,10)||0,i=!!i,i&&(this.loading||this.fetchingMore||!this.hasMore))return Promise.resolve([]);var n=this._cacheGet(e,t);if(n&&(!i||this.hasMore))return this.asyncController&&this.asyncController.abort(),this.asyncController=null,this._applyCachedPage(e,t,i),Promise.resolve(this._visibleItems());this.asyncController&&this.asyncController.abort();var a=typeof AbortController!="undefined"?new AbortController:null;this.asyncController=a,this.loading=!i,this.fetchingMore=i,this.error=null,this.loadMoreError=null,i||(this.hasMore=!1,this.asyncPage=0,this.announce(this.opts.loadingText)),this._renderDropdown();var o,h=new Promise(function(f){o=f});a&&a.signal.addEventListener&&a.signal.addEventListener("abort",function(){o([])}),i&&(this.emit("load-more",{page:t,query:e,instance:this}),this.call("onLoadMore",{page:t,query:e,instance:this}));var l=this.opts.fetchPageSize>0?this.opts.fetchPageSize:0,d=function(f){if(!(a&&a.signal.aborted)){r.loading=!1,r.fetchingMore=!1,r.loadMoreError=null,r.error=null;var p=r._readFetchPayload(f,t,l);r.asyncQuery=e,r.asyncPage=t,r.asyncItems=i?(r.asyncItems||[]).concat(p.items):p.items,r.hasMore=p.hasMore,r._cacheSet(e,t,{items:p.items,hasMore:p.hasMore}),i||(r.activeIndex=-1),r._renderDropdown();var k=r._visibleItems().length;r.announce(k+" result"+(k===1?"":"s")),o(r._visibleItems())}},y=function(f){if(f&&f.name==="AbortError"){o([]);return}if(a&&a.signal.aborted){o([]);return}var p=f&&f.message||"Unable to load options.";r.loading=!1,r.fetchingMore=!1,i?r.loadMoreError=p:r.error={message:p},r.emit("error",{error:f,message:p,instance:r}),r.call("onError",{error:f,message:p,instance:r}),r._renderDropdown(),o([])};try{var u=this.opts.fetchOptions(e,a?a.signal:void 0,{page:t,pageSize:l,append:i,instance:this});u&&typeof u.then=="function"?u.then(d).catch(y):d(u)}catch(f){y(f)}return h},s.prototype.loadMore=function(){return typeof this.opts.fetchOptions!="function"?this:this.loading||this.fetchingMore||!this.hasMore?this:this._fetch(this.asyncQuery||this.query||"",this.asyncPage+1,!0)},s.prototype.hasMoreResults=function(){return!!this.hasMore},s.prototype.getAsyncState=function(){return{query:this.asyncQuery,page:this.asyncPage,hasMore:!!this.hasMore,loading:!!this.loading,fetchingMore:!!this.fetchingMore,error:this.error?this.error.message:null}},s.prototype.refreshOptions=function(){return this.clearCache(),typeof this.opts.fetchOptions!="function"?this:(this.asyncItems=null,this.asyncQuery="",this.asyncPage=0,this.hasMore=!1,this.opened?this._fetch(this.query,0,!1):this)},s.prototype._tagError=function(e){this.announce(e),this.emit("error",{message:e,instance:this}),this.call("onError",{message:e,instance:this}),this.root.classList.add("zs-root--shake");var t=this.root;setTimeout(function(){t.classList.remove("zs-root--shake")},320)},s.prototype._addTagObject=function(e,t){var i=t||{},r=this.opts,n=String(e==null?"":e).trim();if(!n)return!1;if(this.value_.length>=r.maxTags)return i.silent||this._tagError("You can add up to "+r.maxTags+" tags."),!1;if(n.length<r.minTagLength)return i.silent||this._tagError("Tags need at least "+r.minTagLength+" character"+(r.minTagLength===1?"":"s")+"."),!1;if(n.length>r.maxTagLength)return i.silent||this._tagError("Tags can be at most "+r.maxTagLength+" characters."),!1;if(this._hasValue(n))return i.silent||this._tagError('"'+n+'" is already added.'),!1;if(this.mode==="tags"&&!r.allowFreeText){for(var a=this.suggestions&&this.suggestions.length?this.suggestions:this.items,o=r.caseSensitive?n:n.toLowerCase(),h=!1,l=0;l<a.length;l+=1){var d=r.caseSensitive?String(a[l].value):String(a[l].value).toLowerCase(),y=r.caseSensitive?String(a[l].label):String(a[l].label).toLowerCase();if(d===o||y===o){h=!0;break}}if(!h)return i.silent||this._tagError('"'+n+'" is not in the list.'),!1}var u=n;if(typeof r.formatTag=="function"){var f=r.formatTag(n,{instance:this,tags:this.getTags()});typeof f=="string"&&f&&(u=f)}if(typeof r.validateTag=="function"){var p=r.validateTag(u,this.getTags(),{instance:this});if(p===!1)return i.silent||this._tagError('"'+u+'" is not allowed.'),!1;if(typeof p=="string")return i.silent||this._tagError(p),!1}var k={value:u,label:u};return this.value_.push(k),this.query="",this.opts.validation==="invalid"&&(this.opts.validation=null),i.silent||(this._render(),this._syncNative(),this.opened&&this._renderDropdown(),this.announce(u+" added. "+this.value_.length+" tag"+(this.value_.length===1?"":"s")+" total."),this.emit("tag-add",{tag:u,value:this.getTags(),instance:this}),this.call("onTagAdd",{tag:u,value:this.getTags(),instance:this}),this.emit("change",{value:this.getTags(),instance:this}),this.call("onChange",{value:this.getTags(),instance:this})),!0},s.prototype.addTag=function(e){var t=this._addTagObject(e,{});return this._render(),this.opened&&this._renderDropdown(),t},s.prototype.removeTag=function(e){var t=typeof e=="number"?e:this.value_.findIndex(function(r){return String(r.value)===String(e)||String(r.label)===String(e)});if(t<0||t>=this.value_.length)return!1;var i=this.value_.splice(t,1)[0];return this._render(),this._syncNative(),this.opened&&this._renderDropdown(),this.announce(i.label+" removed. "+this.value_.length+" tag"+(this.value_.length===1?"":"s")+" remaining."),this.emit("tag-remove",{tag:i.value,value:this.getTags(),instance:this}),this.call("onTagRemove",{tag:i.value,value:this.getTags(),instance:this}),this.emit("change",{value:this.getTags(),instance:this}),this.call("onChange",{value:this.getTags(),instance:this}),this.input.focus(),!0},s.prototype.getTags=function(){return this.value_.map(function(e){return e.value})},s.prototype._onKeyDown=function(e){if(!this.destroyed){var t=e.key,i=this._visibleItems();if((t===" "||t==="Spacebar")&&!this.opened){e.preventDefault(),this.open();return}if(t==="ArrowDown"||t==="ArrowUp"){if(e.preventDefault(),!this.opened){this.open();return}if(!i.length)return;for(var r=t==="ArrowDown"?1:-1,n=this.activeIndex,a=0;a<i.length&&(n+=r,n<0&&(n=i.length-1),n>=i.length&&(n=0),!!i[n].disabled);a+=1);this.activeIndex=n,this._renderDropdown();return}if(t==="Home"||t==="End"){if(!this.opened)return;e.preventDefault();var o=-1,h;if(t==="Home"){for(h=0;h<i.length;h+=1)if(!i[h].disabled){o=h;break}}else for(h=i.length-1;h>=0;h-=1)if(!i[h].disabled){o=h;break}this.activeIndex=o,this._renderDropdown();return}if(t==="Enter"){if(this.opened){if(e.preventDefault(),this.activeIndex>=0){this._selectRendered(this.activeIndex),this.mode==="tags"&&(this.query="");return}if(this.mode==="tags"){this._commitTypedTag();return}if((this.mode==="combobox"||this.mode==="select")&&this.opts.allowFreeText){var l=this.query.trim();l&&(this._setValueInternal([l]),this.emit("select",{value:this.getValue(),item:{value:l,label:l},instance:this}),this.call("onSelect",{value:this.getValue(),item:{value:l,label:l},instance:this}),this.close());return}i.length===1&&this._selectRendered(0);return}if(this.mode==="tags"&&this.query.trim()){e.preventDefault(),this._commitTypedTag();return}e.preventDefault(),this.open();return}if(t==="Escape"){this.opened&&(e.preventDefault(),this.close());return}if(t==="Tab"){this.mode==="tags"&&this.opts.commitOnTab&&this.query.trim()&&this._commitTypedTag(),this.opened&&this.close();return}if(t==="Backspace"){if(this.mode==="tags"&&!this.input.value&&!this.query&&this.value_.length){e.preventDefault(),this.removeTag(this.value_.length-1);return}!this.input.value&&this.opened&&this.close();return}t==="Delete"&&this.opts.clearable&&this.value_.length&&(e.preventDefault(),this.clear())}},s.prototype._commitTypedTag=function(){var e=this.input.value,t=this._splitTags(e),i=!1;return t.forEach(function(r){this._addTagObject(r,{})&&(i=!0)},this),this.input.value="",this.query="",this._render(),this._syncNative(),this.opened&&this._renderDropdown(),i},s.prototype._splitTags=function(e){var t=String(e||""),i=this.opts.delimiters||[],r=[t];return i.forEach(function(n){n&&(r=r.reduce(function(a,o){return a.concat(o.split(n))},[]))}),r.map(function(n){return n.trim()}).filter(Boolean)},s.prototype._bind=function(){var e=this;this.onInput=function(){var t=e.input.value;if(!(e.mode==="select"&&!e.opts.searchable)&&(e.query=t,e.opened?(typeof e.opts.fetchOptions=="function"&&e.query.length>=(e.opts.minChars||0)&&(e.opts.debounce>0?e.debouncedFetch(e.query):e._fetch(e.query)),e.activeIndex=e.mode==="tags"?-1:e._firstEnabledIndex(),e._renderDropdown()):(e.open(),e.query=t,e.input.value=t,e._renderDropdown()),e.mode==="tags")){var i=e.opts.delimiters||[],r=i.some(function(n){return n&&t.indexOf(n)!==-1});r&&e._commitTypedTag()}},this.onKeyDown=function(t){e._onKeyDown(t)},this.onFocus=function(){e.disabled_||(e.root.classList.add("zs-root--focus"),(e.mode==="combobox"||e.mode==="tags"||e.mode==="select"&&e.opts.searchable)&&(e.opened||e.open()))},this.onBlur=function(){e.root.classList.remove("zs-root--focus"),setTimeout(function(){e.destroyed||e.root.contains(c.activeElement)||(e.mode==="tags"&&e.query.trim()&&e.opts.commitOnBlur&&e._commitTypedTag(),e.mode==="combobox"&&e.opts.allowFreeText&&e.query.trim()&&e._setValueInternal([e.query.trim()]),e.query="",e.close(),e._render())},0)},this.onControlClick=function(t){if(!e.disabled_){var i=t.target;if(!(i.closest&&i.closest(".zs-clear"))&&!(i.closest&&i.closest(".zs-chip-remove"))){if(e.opened){if(!e.opts.searchable&&!e.input.readOnly)return;e.opts.searchable||e.close();return}e.open()}}},this.onControlMouseDown=function(t){if(t.target!==e.input){if(t.target.closest&&(t.target.closest(".zs-chip-remove")||t.target.closest(".zs-clear"))){t.preventDefault();return}(t.target===e.controlEl||t.target.closest&&t.target.closest(".zs-chips"))&&(t.preventDefault(),e.input.focus())}},this.onClearClick=function(t){t.preventDefault(),t.stopPropagation(),e.clear()},this.onChipsClick=function(t){var i=t.target.closest?t.target.closest("[data-zs-remove]"):null;if(i){t.preventDefault(),t.stopPropagation();var r=parseInt(i.getAttribute("data-zs-remove"),10);if(!isNaN(r))if(e.mode==="tags")e.removeTag(r);else{var n=e.value_[r];if(!n)return;var a=e.getValue();e.value_.splice(r,1),e._render(),e._syncNative(),e.emit("change",{value:e.getValue(),previousValue:a,item:n,instance:e}),e.call("onChange",{value:e.getValue(),previousValue:a,item:n,instance:e}),e.announce(n.label+" removed."),e.opened&&e._renderDropdown()}}},this.onDropdownMouseDown=function(t){t.preventDefault()},this.onDropdownClick=function(t){var i=t.target.closest?t.target.closest(".zs-more"):null;if(i){t.preventDefault(),t.stopPropagation(),e.loadMore();return}var r=t.target.closest?t.target.closest("[data-zs-option]"):null;if(r){t.preventDefault();var n=parseInt(r.getAttribute("data-zs-option"),10);isNaN(n)||(e.activeIndex=n,e._selectRendered(n),e.mode==="tags"&&e.input.focus())}},this.onDocumentPointerDown=function(t){if(e.opened){var i=t.composedPath?t.composedPath():[];i.indexOf(e.root)===-1&&(e.root.contains(t.target)||(e.close(),e._render()))}},this.onWindowResize=function(){e.opened&&e._position()},this.onDropdownScroll=function(){if(!(!e.opts.autoLoadMore||!e.opened||!e.hasMore)&&!(e.loading||e.fetchingMore)){var t=e.dropdown;t.scrollTop+t.clientHeight>=t.scrollHeight-24&&e.loadMore()}},this.debouncedFetch=ye(function(t){e._fetch(t)},this.opts.debounce),this.el&&this.el.addEventListener&&(this.onNativeInvalid=function(){e.setValidation("invalid"),e.input&&e.input.focus&&e.input.focus()},this.el.addEventListener("invalid",this.onNativeInvalid)),this.input.addEventListener("input",this.onInput),this.input.addEventListener("keydown",this.onKeyDown),this.input.addEventListener("focus",this.onFocus),this.input.addEventListener("blur",this.onBlur),this.controlEl.addEventListener("click",this.onControlClick),this.controlEl.addEventListener("mousedown",this.onControlMouseDown),this.chipsEl.addEventListener("click",this.onChipsClick),this.clearBtn.addEventListener("click",this.onClearClick),this.dropdown.addEventListener("mousedown",this.onDropdownMouseDown),this.dropdown.addEventListener("click",this.onDropdownClick),this.dropdown.addEventListener("scroll",this.onDropdownScroll),c.addEventListener("pointerdown",this.onDocumentPointerDown,!0),g.addEventListener("resize",this.onWindowResize)},s.prototype._observeResize=function(){if(typeof ResizeObserver!="undefined"){var e=this;this.resizeObserver=new ResizeObserver(function(){e.opened&&e._position()}),this.resizeObserver.observe(this.controlEl)}},s.prototype.getValue=function(){if(this.mode==="tags")return this.getTags();var e=this.value_.map(function(t){return t.value});return this.opts.multiple?e:e.length?e[0]:null},s.prototype.setValue=function(e,t){var i=t||{};if(this.mode==="tags"){var r=typeof e=="string"?this._splitTags(e):T(e),n=this.getTags();if(this.value_=[],r.forEach(function(o){this._addTagObject(o,{silent:!0})},this),this.value_.length&&this.opts.validation==="invalid"&&(this.opts.validation=null),this._render(),this._syncNative(),!i.silent){var a=this.getTags();JSON.stringify(a)!==JSON.stringify(n)&&(this.emit("change",{value:a,previousValue:n,instance:this}),this.call("onChange",{value:a,previousValue:n,instance:this}))}return this.opened&&this._renderDropdown(),this}return this._setValueInternal(e,i)},s.prototype.clear=function(){return this.mode==="tags"?this.value_.length?(this.value_=[],this._render(),this._syncNative(),this.announce("All tags removed."),this.emit("change",{value:[],instance:this}),this.call("onChange",{value:[],instance:this}),this.opened&&this._renderDropdown(),this):this:(this._setValueInternal([],{}),this._render(),this)},s.prototype.setOptions=function(e){var t=this._normalizeItems(e);if(this.mode==="tags")this.suggestions=t;else{this.items=t;var i=this;if(this.value_=this.value_.filter(function(r){for(var n=0;n<i.items.length;n+=1)if(i.items[n].value===r.value)return!0;return i.opts.allowFreeText}),this.native&&this.native.tagName==="SELECT"){for(;this.native.firstChild;)this.native.removeChild(this.native.firstChild);this.items.forEach(function(r){var n=c.createElement("option");n.value=r.value,n.textContent=r.label,r.disabled&&(n.disabled=!0),i.native.appendChild(n)})}}return this.asyncItems=null,this.asyncPage=0,this.hasMore=!1,this.loadMoreError=null,this.clearCache(),this.activeIndex=-1,this._render(),this._syncNative(),this.opened&&this._renderDropdown(),this},s.prototype.enable=function(){return this.disabled_=!1,this._render(),this},s.prototype.disable=function(){return this.disabled_=!0,this.close(),this._render(),this},s.prototype.setLayout=function(e){var t=String(e||"").toLowerCase();if(M.indexOf(t)===-1)throw new Error('ZidanSelect: unknown layout "'+e+'". Use: '+M.join(", "));return this.layout=t,this.opts.layout=t,this.root.setAttribute("data-zs-layout",t),this.root.classList.toggle("zs-root--labeled",t==="floating-label"),this._position(),this},s.prototype.setFramework=function(e){var t=String(e||"").toLowerCase();if(C.indexOf(t)===-1)throw new Error('ZidanSelect: unknown framework "'+e+'". Use: '+C.join(", "));return this.opts.themeFramework=t,this.framework=t==="auto"?this._resolveFramework():t,this.root.setAttribute("data-zs-framework",this.framework),this.controlEl.classList.toggle("form-control",this.framework==="bootstrap"),this.controlEl.classList.toggle("zs-bootstrap-control",this.framework==="bootstrap"),this.controlEl.classList.toggle("form-select",this.framework==="bootstrap"&&this.el.tagName==="SELECT"),this._applyCustomClass(this.root,"root"),this._render(),this},s.prototype.setScrollbar=function(e){var t=String(e||"").toLowerCase();if(I.indexOf(t)===-1)throw new Error('ZidanSelect: unknown scrollbar "'+e+'". Use: '+I.join(", "));return this.opts.scrollbar=t,this.root&&this.root.setAttribute("data-zs-scrollbar",t),this},s.prototype.setValidation=function(e){return this.opts.validation=e,this._render(),this},s.prototype.on=function(e,t){var i=this._eventName(e);return this.root.addEventListener(i,t),this.listeners.has(i)||this.listeners.set(i,[]),this.listeners.get(i).push(t),this},s.prototype.off=function(e,t){var i=this._eventName(e),r=this.listeners.get(i)||[];if(t)this.root.removeEventListener(i,t),this.listeners.set(i,r.filter(function(a){return a!==t}));else{var n=this.root;r.forEach(function(a){n.removeEventListener(i,a)}),this.listeners.set(i,[])}return this},s.prototype._eventName=function(e){var t=String(e||"");return t.indexOf(P)===0?t:P+t},s.prototype.emit=function(e,t){if(!this.root||!c)return this;var i;try{i=new CustomEvent(P+e,{bubbles:!0,cancelable:!1,detail:t||{}})}catch{i=c.createEvent("CustomEvent"),i.initCustomEvent(P+e,!0,!1,t||{})}return this.root.dispatchEvent(i),this},s.prototype.call=function(e,t){var i=this.opts[e];if(typeof i=="function")try{return i(t)}catch(r){this.emit("error",{error:r,message:r&&r.message||String(r),callback:e,instance:this});return}},s.prototype.announce=function(e){!this.liveEl||!e||(this.liveEl.textContent="",this.liveEl.textContent=e)},s.prototype.destroy=function(){if(this.destroyed)return this;this.destroyed=!0,this.debouncedFetch&&this.debouncedFetch.cancel(),this.asyncController&&this.asyncController.abort(),this.clearCache(),this.resizeObserver&&this.resizeObserver.disconnect(),this.form&&this.onFormReset&&this.form.removeEventListener("reset",this.onFormReset),this.form&&this.onFormSubmit&&this.form.removeEventListener("submit",this.onFormSubmit),this._nativeRequiredAdded&&this.native&&(this.native.required=!1,this._nativeRequiredAdded=!1),c.removeEventListener("pointerdown",this.onDocumentPointerDown,!0),g.removeEventListener("resize",this.onWindowResize),this.el&&this.onNativeInvalid&&this.el.removeEventListener("invalid",this.onNativeInvalid),this.emit("destroy",{instance:this}),this.root&&this.root.parentNode&&this.root.parentNode.removeChild(this.root),this._authorLabel&&(this._authorLabel.hidden=!1,this._authorLabel.removeAttribute("data-zs-hidden-label"),this._authorLabel=null),this.native?(this.native.hidden=!1,this.native.classList.remove("zs-native"),this.native.removeAttribute("tabindex"),this.native.removeAttribute("aria-hidden")):this.el.classList&&this.el.classList.contains("zs-root--mount")&&this.el.classList.remove("zs-root--mount"),this.el.__zidanSelect===this&&delete this.el.__zidanSelect,this.listeners.clear();var e=s.instances.indexOf(this);return e!==-1&&s.instances.splice(e,1),this},s.prototype.isOpen=function(){return this.opened},s.prototype.refresh=function(){return this._render(),this.opened&&this._renderDropdown(),this};function L(e){if(!b(e))return null;var t=String(e.getAttribute("data-zidan")||"").toLowerCase();if(oe.indexOf(t)!==-1)return t;if(e.hasAttribute("data-zidan-radio-group"))return"radio-group";if(e.hasAttribute("data-zidan-radio"))return"radio";if(e.hasAttribute("data-zidan-checkbox")||e.hasAttribute("data-zidan-switch"))return"checkbox";if(e.hasAttribute("data-zidan-file"))return"file";if(e.hasAttribute("data-zidan-textarea"))return"textarea";if(e.hasAttribute("data-zidan-input"))return"input";var i=String(e.type||"").toLowerCase();if(i==="checkbox")return"checkbox";if(i==="radio")return"radio";if(i==="file")return"file";if(G(e,"zidan-field")){if(e.tagName==="FIELDSET")return e.querySelector('input[type="radio"]')?"radio-group":null;if(e.tagName==="TEXTAREA")return"textarea";if(e.tagName!=="INPUT"||i==="radio")return null;if(typeof TEXT_TYPES!="undefined"&&TEXT_TYPES.indexOf(i)!==-1)return"input"}return null}function O(e,t,i){var r=w(Q(e),i);if(e.__zidanField&&!r.force)return e.__zidanField;switch(t){case"checkbox":return typeof ZidanCheckbox!="undefined"?new ZidanCheckbox(e,r):null;case"radio":case"radio-group":return typeof ZidanRadioGroup!="undefined"?new ZidanRadioGroup(e,r):null;case"file":return typeof ZidanFileUpload!="undefined"?new ZidanFileUpload(e,r):null;case"input":case"textarea":return typeof ZidanTextField!="undefined"?new ZidanTextField(e,r):null;default:return null}}function ee(e,t){var i=[];typeof e=="string"?i=Array.prototype.slice.call(c.querySelectorAll(e)):b(e)?i=[e]:e&&typeof e.length=="number"&&(i=Array.prototype.slice.call(e));var r=[];return i.forEach(function(n){if(!n.__zidanField){var a=L(n)||ne(n);if(a){if(a==="radio"||a==="radio-group"){if(/^INPUT$/i.test(n.tagName)&&(n=n.closest?n.closest("fieldset, [data-zidan-radio-group]"):null,!n))return;a="radio-group"}var o=O(n,a,t||{});o&&r.push(o)}}}),r.length===1?r[0]:r}function te(e,t){var i=[];return e.forEach(function(r){if(!(!b(r)||r.__zidanField)){var n=L(r);if(n){if(n==="radio"||n==="radio-group"){if(/^INPUT$/i.test(r.tagName)&&(r=r.closest?r.closest("fieldset, [data-zidan-radio-group]"):null,!r))return;n="radio-group"}var a=O(r,n,t||{});a&&i.push(a)}}}),i}function x(e,t){var i=e||c;if(!i||!i.querySelectorAll)return[];var r=Array.prototype.slice.call(i.querySelectorAll(j));return b(i)&&i.matches&&i.matches(j)&&r.unshift(i),te(r,t)}var v={version:z,__zidanFormGuard:z,themes:H,frameworks:C.slice(),fieldLayouts:U,fields:[],_register:function(e){v.fields.indexOf(e)===-1&&v.fields.push(e)},_unregister:function(e){var t=v.fields.indexOf(e);t!==-1&&v.fields.splice(t,1)},get:function(e){var t=typeof e=="string"?c.querySelector(e):e;return b(t)&&t.__zidanField||null},init:function(e,t){return x(e||c,t||{})},field:ee,refresh:function(e){return x(e||c,{}),v.fields.slice().forEach(function(t){t.update()}),v.fields.slice()},destroyAll:function(){return v.fields.slice().forEach(function(e){e.destroy()}),v.fields=[],typeof s!="undefined"&&s.destroyAll&&s.destroyAll(),v},observe:function(e,t){var i=e||c.body;if(!i||!g.MutationObserver)return null;var r=new g.MutationObserver(function(n){n.forEach(function(a){Array.prototype.slice.call(a.addedNodes).forEach(function(o){b(o)&&(L(o)&&O(o,L(o)==="radio"?"radio-group":L(o),t||{}),o.querySelectorAll&&x(o,t||{}))})}),v.fields.slice().forEach(function(a){a.el.isConnected||a.destroy()}),typeof s!="undefined"&&s.instances.slice().forEach(function(a){a.el.isConnected||a.destroy()})});return r.observe(i,{childList:!0,subtree:!0}),r}};v.api=null,v.registerIcon=W,v.icons=A,typeof PHONE_COUNTRIES!="undefined"&&(v.phoneCountries=PHONE_COUNTRIES,v.phoneFormats=PHONE_FORMATS.slice(),v.formatPhone=formatPhone,v.detectPhoneCountry=detectPhoneCountry),v.messages=D,v.variants={},typeof CHECKBOX_VARIANTS!="undefined"&&(v.variants.checkbox=CHECKBOX_VARIANTS.slice()),typeof SWITCH_STYLES!="undefined"&&(v.variants.switch=SWITCH_STYLES.slice()),typeof RADIO_VARIANTS!="undefined"&&(v.variants.radio=RADIO_VARIANTS.slice()),typeof FILE_VARIANTS!="undefined"&&(v.variants.file=FILE_VARIANTS.slice()),typeof RANGE_VARIANTS!="undefined"&&(v.variants.range=RANGE_VARIANTS.slice()),typeof STEPPER_MODES!="undefined"&&(v.stepperModes=STEPPER_MODES.slice()),v.fieldLayouts=U.slice(),typeof s!="undefined"&&(s.version=z,s.__zidanSelectGuard=z,s.layouts=M.slice(),s.frameworks=C.slice(),s.scrollbars=I.slice(),s.defaults=_,s.cacheLimit=50,s.get=function(e){var t=typeof e=="string"?c.querySelector(e):e;return b(t)&&t.__zidanSelect||null},s.instances=[],s.destroyAll=function(){s.instances.slice().forEach(function(e){e.destroy()}),s.instances=[]});function Ee(e,t){var i=[];typeof e=="string"?i=Array.prototype.slice.call(c.querySelectorAll(e)):e&&typeof e.length=="number"&&!b(e)&&e!==g?i=Array.prototype.slice.call(e):b(e)&&(i=[e]);var r=i.map(function(n){var a=new s(n,t||{});return s.instances.push(a),a});return r.length===1?r[0]:r}function V(e,t){return e.filter(function(i){return b(i)&&!i.__zidanSelect}).map(function(i){return s.instances.push(new s(i,t||{})),i.__zidanSelect})}function ie(e,t){var i=e||c;if(!i||!i.querySelectorAll)return[];var r=Array.prototype.slice.call(i.querySelectorAll(N));return b(i)&&i.matches&&i.matches(N)&&r.unshift(i),V(r,t)}function q(e,t){T(e).forEach(function(i){i&&(typeof i=="string"?t(i,null):i.selector&&t(String(i.selector),i.options||null))})}function re(e,t){q(e,function(i,r){V(Array.prototype.slice.call(c.querySelectorAll(i)),w(t,r))})}function Te(e,t){q(e,function(i,r){var n=w(t,r);Array.prototype.slice.call(c.querySelectorAll(i)).forEach(function(a){if(!(!b(a)||a.__zidanField)){var o=L(a)||ne(a);o&&(o==="radio"&&(o="radio-group"),O(a,o,n))}})})}function ne(e){return typeof TEXT_TYPES=="undefined"||!b(e)?null:e.tagName==="TEXTAREA"?"textarea":e.tagName!=="INPUT"?null:TEXT_TYPES.indexOf(String(e.type).toLowerCase())!==-1?"input":null}function ze(e,t){if(typeof s=="undefined")return[];var i=N+", select",r=Array.prototype.slice.call(e.querySelectorAll(i));return b(e)&&e.matches&&e.matches(i)&&r.unshift(e),V(r,t)}function ae(e,t,i){b(e)&&(ze(e,t),typeof ZidanFileUpload!="undefined"&&te(Array.prototype.slice.call(e.querySelectorAll('input[type="file"]')),i),(typeof ZidanCheckbox!="undefined"||typeof ZidanRadioGroup!="undefined"||typeof ZidanFileUpload!="undefined"||typeof ZidanTextField!="undefined")&&x(e,i))}function Ce(e,t,i){Array.prototype.slice.call(c.querySelectorAll(le)).forEach(function(r){ae(r,t,i)}),q(e,function(r,n){Array.prototype.slice.call(c.querySelectorAll(r)).forEach(function(a){ae(a,w(t,n),w(i,n))})})}function se(){if(c){var e=g.ZIDAN_FORM_CONFIG||g.ZIDAN_SELECT_CONFIG||{};if(e.autoInit!==!1&&!(g.ZidanSelect&&g.ZidanSelect.autoInit===!1)&&c.documentElement.getAttribute("data-zidan-auto-init")!=="false"){var t=typeof s!="undefined",i=typeof ZidanCheckbox!="undefined"||typeof ZidanRadioGroup!="undefined"||typeof ZidanFileUpload!="undefined"||typeof ZidanTextField!="undefined",r=e.options||{},n=e.fieldOptions||e.fields||{};t&&(e.selector?re(e.selector,r):re(e.targets||e.selectors,r)),i&&Te(e.fieldTargets,n),Ce(e.formTargets,r,n),t&&!e.selector&&ie(c,r),i&&x(c,n)}}}c&&(c.readyState==="loading"?c.addEventListener("DOMContentLoaded",se):setTimeout(se,0));var S={ZidanForm:v,registerIcon:W};return typeof s!="undefined"&&(S.ZidanSelect=s,S.zidanSelect=Ee,S.initZidanSelects=ie),(typeof ZidanCheckbox!="undefined"||typeof ZidanRadioGroup!="undefined"||typeof ZidanFileUpload!="undefined"||typeof ZidanTextField!="undefined")&&(S.zidanField=ee,S.initZidanForms=x),typeof ZidanCheckbox!="undefined"&&(S.ZidanCheckbox=ZidanCheckbox),typeof ZidanRadioGroup!="undefined"&&(S.ZidanRadioGroup=ZidanRadioGroup),typeof ZidanFileUpload!="undefined"&&(S.ZidanFileUpload=ZidanFileUpload),typeof ZidanTextField!="undefined"&&(S.ZidanTextField=ZidanTextField),typeof formatPhone=="function"&&(S.formatPhone=formatPhone,S.detectPhoneCountry=detectPhoneCountry),v.api=S,S});
11
+ */(function(g,z){"use strict";var c=z(g);typeof window!="undefined"&&(window.ZidanForm=c.ZidanForm,c.ZidanSelect&&(window.ZidanSelect=c.ZidanSelect,window.zidanSelect=c.zidanSelect,window.initZidanSelects=c.initZidanSelects),c.zidanField&&(window.zidanField=c.zidanField),c.initZidanForms&&(window.initZidanForms=c.initZidanForms),c.registerIcon&&(window.registerZidanIcon=c.registerIcon)),typeof module!="undefined"&&module.exports&&(module.exports=c)})(typeof window!="undefined"?window:this,function(g){"use strict";var z="2.4.2";if(g&&g.ZidanForm&&g.ZidanForm.__zidanFormGuard===z)return g.ZidanForm.api;var c=typeof document!="undefined"?document:null,M=["classic-clean","floating-label","soft-pill","bordered-brutalist","glass-elevated"],C=["auto","none","vanilla","bootstrap","tailwind","bulma","foundation"],H=["default","modern","minimal","dark","glass"],U=["stacked","inline","card","compact","floating","outlined"],oe=["checkbox","radio","radio-group","file","input","textarea"],j="[data-zidan], [data-zidan-checkbox], [data-zidan-switch], [data-zidan-radio], [data-zidan-radio-group], [data-zidan-file], [data-zidan-input], [data-zidan-textarea], .zidan-field",N="[data-zidan-select], .zidan-select",le="[data-zidan-form], .zidan-form",I=["default","thin","fancy","hover","hidden"],P="zidan:",B=0;function he(e){return B+=1,(e||"zs")+"-"+B.toString(36)+Math.random().toString(36).slice(2,6)}function G(e,t){return!!(e&&e.classList&&e.classList.contains(t))}function K(e,t){return!e||!t||t.split(/\s+/).forEach(function(i){i&&e.classList.add(i)}),e}function m(e,t,i,r){var n=c.createElement(e);return t&&(n.className=t),i&&Object.keys(i).forEach(function(a){var o=i[a];o==null||o===!1||(a==="text"?n.textContent=String(o):n.setAttribute(a,o===!0?"":String(o)))}),r!=null&&(n.textContent=String(r)),n}function T(e){return e==null||e===""?[]:Array.isArray(e)?e.slice():[e]}function we(e){return!!(e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function")}function ue(e){if(!e)return!1;var t=e.closest?e.closest("[dir]"):null,i=t?t.getAttribute("dir"):"";if(!i&&c&&c.documentElement&&(i=c.documentElement.getAttribute("dir")||""),i)return String(i).toLowerCase()==="rtl";try{return!!(g.getComputedStyle&&g.getComputedStyle(e).direction==="rtl")}catch{return!1}}function b(e){return!!(e&&typeof e=="object"&&e.nodeType===1)}function E(e,t){if(e==null||e==="")return t;var i=String(e).toLowerCase();return!(i==="false"||i==="0"||i==="no"||i==="off")}function w(){for(var e={},t=0;t<arguments.length;t++)(function(i){!i||typeof i!="object"||Object.keys(i).forEach(function(r){i[r]!==void 0&&(e[r]=i[r])})})(arguments[t]);return e}function Q(e){if(!e||!e.getAttribute)return null;var t=e.getAttribute("data-zidan-options");if(!t)return null;try{var i=JSON.parse(t);return i&&typeof i=="object"&&!Array.isArray(i)?i:null}catch(r){return typeof console!="undefined"&&console.warn&&console.warn("[ZidanForm] ignoring invalid data-zidan-options JSON on",e,r),null}}function de(e,t,i){return Math.min(i,Math.max(t,e))}function ce(e,t){return String(e).replace(/\{(\w+)\}/g,function(i,r){return t&&t[r]!==void 0&&t[r]!==null?String(t[r]):i})}var Y={text:'<path d="M4 7h16M4 12h10M4 17h13"/>',mail:'<rect x="3" y="5" width="18" height="14" rx="2"/><path d="m3 7 9 6 9-6"/>',phone:'<path d="M22 16.9v3a2 2 0 0 1-2.2 2 19.8 19.8 0 0 1-8.6-3.1 19.5 19.5 0 0 1-6-6A19.8 19.8 0 0 1 2.1 4.2 2 2 0 0 1 4.1 2h3a2 2 0 0 1 2 1.7c.1 1 .4 1.9.7 2.8a2 2 0 0 1-.5 2.1L8.1 9.9a16 16 0 0 0 6 6l1.3-1.2a2 2 0 0 1 2.1-.5c.9.3 1.8.6 2.8.7a2 2 0 0 1 1.7 2Z"/>',user:'<circle cx="12" cy="8" r="4"/><path d="M4 21a8 8 0 0 1 16 0"/>',lock:'<rect x="4" y="10" width="16" height="11" rx="2"/><path d="M8 10V7a4 4 0 0 1 8 0v3"/>',search:'<circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/>',calendar:'<rect x="3" y="5" width="18" height="16" rx="2"/><path d="M16 3v4M8 3v4M3 11h18"/>',clock:'<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>',link:'<path d="M10 13a5 5 0 0 0 7 0l3-3a5 5 0 0 0-7-7l-1.5 1.5"/><path d="M14 11a5 5 0 0 0-7 0l-3 3a5 5 0 0 0 7 7l1.5-1.5"/>',hash:'<path d="M4 9h16M4 15h16M10 3 8 21M16 3l-2 18"/>',palette:'<path d="M12 3a9 9 0 0 0 0 18h1.5a2.5 2.5 0 0 0 0-5H12a2 2 0 0 1 0-4h4a5 5 0 0 0 0-10Z"/><circle cx="8.5" cy="8.5" r="1"/><circle cx="8" cy="14" r="1"/>',sliders:'<path d="M4 7h16M4 17h16"/><circle cx="9" cy="7" r="2.5"/><circle cx="15" cy="17" r="2.5"/>',file:'<path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/>',upload:'<path d="M12 16V4"/><path d="m7 9 5-5 5 5"/><path d="M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"/>',eye:'<path d="M2 12s3.5-6 10-6 10 6 10 6-3.5 6-10 6-10-6-10-6Z"/><circle cx="12" cy="12" r="3"/>',"eye-off":'<path d="m3 3 18 18"/><path d="M10.6 6.2A9.9 9.9 0 0 1 12 6c6.5 0 10 6 10 6a17 17 0 0 1-3.1 3.6"/><path d="M6.4 6.7C3.5 8.4 2 12 2 12s3.5 6 10 6c1.7 0 3.2-.4 4.5-1"/><path d="M9.9 9.9a3 3 0 0 0 4.2 4.2"/>',check:'<path d="m4 12.5 5 5L20 6.5"/>',x:'<path d="M6 6l12 12M18 6 6 18"/>',plus:'<path d="M12 5v14M5 12h14"/>',minus:'<path d="M5 12h14"/>',"chevron-down":'<path d="m6 9 6 6 6-6"/>',"chevron-up":'<path d="m6 15 6-6 6 6"/>',"chevron-left":'<path d="m15 6-6 6 6 6"/>',"chevron-right":'<path d="m9 6 6 6-6 6"/>',alert:'<path d="M12 9v4"/><path d="M12 17h.01"/><path d="M10.3 3.9 2.6 17.4A2 2 0 0 0 4.3 20h15.4a2 2 0 0 0 1.7-2.6L13.7 3.9a2 2 0 0 0-3.4 0Z"/>',info:'<circle cx="12" cy="12" r="9"/><path d="M12 11v5"/><path d="M12 8h.01"/>',globe:'<circle cx="12" cy="12" r="9"/><path d="M3 12h18"/><path d="M12 3a15 15 0 0 1 0 18 15 15 0 0 1 0-18Z"/>',"map-pin":'<path d="M20 10c0 6-8 12-8 12S4 16 4 10a8 8 0 1 1 16 0Z"/><circle cx="12" cy="10" r="3"/>',image:'<rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><path d="m21 15-5-5L5 21"/>',refresh:'<path d="M20 11a8 8 0 0 0-14.9-3.9L3 10"/><path d="M3 5v5h5"/><path d="M4 13a8 8 0 0 0 14.9 3.9L21 14"/><path d="M21 19v-5h-5"/>',trash:'<path d="M4 7h16"/><path d="M9 7V4h6v3"/><path d="M6 7l1 13h10l1-13"/><path d="M10 11v5M14 11v5"/>'},A={};Object.keys(Y).forEach(function(e){A[e]=Y[e]});var fe="http://www.w3.org/2000/svg",pe={svg:1,g:1,path:1,circle:1,rect:1,line:1,polyline:1,polygon:1,ellipse:1,title:1,defs:1,clipPath:1,clippath:1,mask:1};function ve(e){if(typeof e!="string"||!e.trim())return"";var t;try{if(typeof g.DOMParser=="undefined")return"";t=new g.DOMParser().parseFromString(e,"image/svg+xml")}catch{return""}if(!t||!t.documentElement)return"";var i=t.documentElement;if(String(i.nodeName).toLowerCase()!=="svg"||t.getElementsByTagName("parsererror").length)return"";var r=function(n){Array.prototype.slice.call(n.children||[]).forEach(function(a){var o=String(a.nodeName);if(o!==o.toLowerCase()&&(o=o.toLowerCase()),!pe[o]){a.parentNode.removeChild(a);return}Array.prototype.slice.call(a.attributes||[]).forEach(function(h){var l=String(h.name).toLowerCase();l.indexOf("on")===0&&a.removeAttribute(h.name),(l==="href"||l==="xlink:href")&&!/^#/.test(h.value)&&a.removeAttribute(h.name),/url\s*\(\s*['"]?\s*(?:https?:|\/\/)/i.test(h.value)&&a.removeAttribute(h.name)}),r(a)})};return r(i),i.outerHTML}function F(e){var t=e;return/^\s*</.test(t)&&!/^\s*<svg/i.test(t)?t='<svg xmlns="'+fe+'" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">'+t+"</svg>":/^\s*<svg/i.test(t)||(t=""),ve(t)}function Ae(e,t){var i="",r="";if(typeof e=="string"&&e?(r=e,/^\s*</.test(e)?i=F(e)||F('<path d="M4 12h16"/>'):A[e]&&(i=F(A[e])||"")):e&&typeof e=="object"&&e.name&&(r=e.name,i=F(A[e.name]||"")),!i)return null;var n=c.createElement("span");t&&(n.className=t),n.setAttribute("data-zs-icon",r||"custom");try{n.innerHTML=i}catch{return null}var a=n.firstChild;return a&&(a.setAttribute("focusable","false"),a.setAttribute("aria-hidden","true"),a.setAttribute("width","18"),a.setAttribute("height","18")),n}var me={text:"text",email:"mail",password:"lock",number:"hash",tel:"phone",url:"link",search:"search",date:"calendar",time:"clock","datetime-local":"calendar",month:"calendar",week:"calendar",range:"sliders",color:"palette"};function Le(e){return me[e]||""}function W(e,t){return typeof s!="undefined"&&(!e||typeof t!="string")?s:(e&&typeof t=="string"&&(A[String(e)]=t),typeof s!="undefined"?s:v)}function X(e,t,i,r,n){if(t&&t[i]!==void 0&&t[i]!==null)return t[i];if(e&&r&&e.getAttribute){var a=e.getAttribute("data-zidan-"+r);if(a!==null&&a!=="")return a}return n}function xe(e,t,i,r,n){if(t&&t[i]!==void 0&&t[i]!==null)return!!t[i];if(e&&r&&e.getAttribute){var a=e.getAttribute("data-zidan-"+r);if(a!==null)return E(a,n)}return n}function Me(e,t,i,r,n){var a=X(e,t,i,r,n);if(a==null||a==="")return n;var o=parseFloat(a);return isFinite(o)?o:n}function Ie(e,t,i,r,n){var a=X(e,t,i,r,null);return a==null||a===""?n:Array.isArray(a)?a.slice():String(a).split(",").map(function(o){return o.trim()}).filter(Boolean)}var D={required:"This field is required.",email:"Enter a valid email address.",url:"Enter a valid URL.",pattern:"The value does not match the expected format.",min:"Value must be at least {min}.",max:"Value must be at most {max}.",step:"Value must be a multiple of {step}.",minlength:"Use at least {minlength} characters.",maxlength:"Use at most {maxlength} characters.",badInput:"Enter a valid value.",phone:"Enter a valid phone number for {country}.",integer:"Enter a whole number.",date:"Enter a valid date.",weekend:"Weekends are not available \u2014 pick a weekday.",dateDisabled:"This date is not available.",fileType:"This file type is not allowed.",fileSize:"This file is too large.",fileCount:"Too many files.",pending:"Checking\u2026",generic:"Please check this field."};function Pe(e,t){if(!e||!e.validity||e.validity.valid)return"";var i=e.validity,r=t||D,n=String(e.type||"").toLowerCase(),a="",o={min:e.getAttribute("min"),max:e.getAttribute("max"),step:e.getAttribute("step")};return i.valueMissing?a="required":i.typeMismatch?a=n==="email"?"email":n==="url"?"url":"generic":i.patternMismatch?a="pattern":i.rangeUnderflow?a="min":i.rangeOverflow?a="max":i.stepMismatch?a="step":i.tooShort?(a="minlength",o.minlength=e.getAttribute("minlength")):i.tooLong?(a="maxlength",o.maxlength=e.getAttribute("maxlength")):(i.badInput||i.customError)&&(a="badInput"),a?ce(r[a]||D[a]||r.generic,o):e.validationMessage||r.generic}var J=["valueMissing","typeMismatch","patternMismatch","rangeUnderflow","rangeOverflow","stepMismatch","tooShort","tooLong","badInput","fileMissing"];function Fe(e){var t=e&&e.validity;if(!t)return!1;for(var i=0;i<J.length;i+=1)if(t[J[i]])return!0;return!1}function R(e,t){for(var i=e;i&&i.nodeType===1;){for(var r=0;r<t.length;r+=1){var n=i.getAttribute(t[r]);if(n)return n}i=i.parentElement}return""}function $(e,t,i){var r=String(e||"").toLowerCase();return t.indexOf(r)===-1?i:r}function Oe(e){if(Array.isArray(e))return e.slice();if(typeof e=="string"){var t=e.trim();if(t.charAt(0)==="[")try{var i=JSON.parse(t);if(Array.isArray(i))return i}catch{}else if(t.indexOf(",")!==-1)return t.split(",").map(function(r){return Number(r.trim())}).filter(function(r){return isFinite(r)})}return e}function ge(e,t){var i=t||{},r=i.theme||R(e,["data-zidan-theme","data-zs-theme"]);!r&&c&&(r=c.documentElement.getAttribute("data-zs-theme")||"");var n=i.framework||R(e,["data-zidan-framework","data-zs-framework"]);!n&&c&&(n=c.documentElement.getAttribute("data-zs-framework")||"");var a=i.layout||R(e,["data-zidan-layout","data-zs-layout"]);return{theme:$(r,H,"default"),framework:$(n,C,"none"),layout:a?String(a).toLowerCase():""}}function ye(e,t){var i=null;function r(){var n=arguments;clearTimeout(i),i=setTimeout(function(){i=null,e.apply(null,n)},t)}return r.cancel=function(){clearTimeout(i),i=null},r}var _={mode:null,layout:"classic-clean",themeFramework:"auto",id:null,name:null,disabled:!1,required:!1,options:null,value:null,label:null,placeholder:null,multiple:!1,searchable:null,clearable:!1,closeOnSelect:null,maxDropdownHeight:280,noResultsText:"No results found",emptyText:"No options",loadingText:"Searching\u2026",clearText:"Clear selection",fetchOptions:null,debounce:250,minChars:0,allowFreeText:!1,searchValues:!0,fetchPageSize:0,autoLoadMore:!0,cacheResults:!0,loadMoreText:"Load more",fetchUrl:null,fetchMethod:"GET",fetchQueryParam:"q",fetchPageParam:"page",fetchSkipParam:null,fetchPageSizeParam:"limit",fetchItemsPath:null,fetchTotalPath:null,fetchHasMorePath:null,fetchHeaders:null,fetchCredentials:"same-origin",maxTags:1/0,minTagLength:1,maxTagLength:1/0,caseSensitive:!1,delimiters:[","],commitOnTab:!1,commitOnBlur:!1,suggestions:null,valueDelimiter:",",customClasses:{},validation:null,scrollbar:"default",filterOption:null,renderOption:null,renderSelected:null,renderTag:null,validateTag:null,formatTag:null,onInit:null,onChange:null,onSelect:null,onOpen:null,onClose:null,onTagAdd:null,onTagRemove:null,onLoadMore:null,onError:null};function Z(e,t){if(t)return String(t).split(".").reduce(function(i,r){return i==null?void 0:i[r]},e)}function be(e){if(Array.isArray(e))return e;if(!e||typeof e!="object")return[];for(var t=["items","data","results","options","rows","products","records"],i=0;i<t.length;i++)if(Array.isArray(e[t[i]]))return e[t[i]];return[]}function _e(e){if(e==null)return null;if(typeof e!="object"){var t=String(e);return{value:t,label:t}}var i=e.value!==void 0?e.value:e.id!==void 0?e.id:e.slug!==void 0?e.slug:e.code!==void 0?e.code:e.key!==void 0?e.key:void 0,r=e.label!==void 0?e.label:e.name!==void 0?e.name:e.title!==void 0?e.title:e.full_name!==void 0?e.full_name:e.text!==void 0?e.text:void 0;return r===void 0&&(r=i===void 0?"":i),i===void 0&&(i=r),{value:i,label:r,disabled:!!e.disabled}}function Se(e){return function(t,i,r){if(typeof fetch!="function")return Promise.reject(new Error("This environment has no fetch()."));var n=r&&r.page?r.page:0,a=e.fetchPageSize>0?e.fetchPageSize:0,o;try{o=new URL(e.fetchUrl,typeof location!="undefined"&&location.href||void 0)}catch{return Promise.reject(new Error("Invalid fetchUrl: "+e.fetchUrl))}e.fetchQueryParam&&o.searchParams.set(e.fetchQueryParam,t||""),a>0&&e.fetchPageSizeParam&&o.searchParams.set(e.fetchPageSizeParam,String(a)),e.fetchSkipParam?a>0&&o.searchParams.set(e.fetchSkipParam,String(n*a)):e.fetchPageParam&&o.searchParams.set(e.fetchPageParam,String(n+1));var h={Accept:"application/json"};return e.fetchHeaders&&typeof e.fetchHeaders=="object"&&Object.keys(e.fetchHeaders).forEach(function(l){h[l]=e.fetchHeaders[l]}),fetch(o.toString(),{method:e.fetchMethod||"GET",headers:h,signal:i,credentials:e.fetchCredentials||"same-origin"}).then(function(l){if(!l.ok)throw new Error("Request failed ("+l.status+" "+(l.statusText||"error")+")");return l.json()}).then(function(l){var d=e.fetchItemsPath?Z(l,e.fetchItemsPath):be(l);Array.isArray(d)||(d=d==null?[]:[d]);var y=d.map(_e).filter(Boolean),u;e.fetchHasMorePath&&(u=!!Z(l,e.fetchHasMorePath));var f=e.fetchTotalPath?Z(l,e.fetchTotalPath):l&&typeof l=="object"?l.total:void 0,p=f==null?NaN:Number(f);return u===void 0&&isFinite(p)&&a>0&&(u=(n+1)*a<p),u===void 0&&(u=a>0&&y.length>=a),{items:y,hasMore:u,total:isFinite(p)?p:void 0}})}}function s(e,t){if(!(this instanceof s))return new s(e,t);if(!c)throw new Error("ZidanSelect requires a DOM environment.");var i=typeof e=="string"?c.querySelector(e):e;if(!b(i))throw new Error("ZidanSelect: target element not found.");i.__zidanSelect instanceof s&&i.__zidanSelect.destroy(),this.el=i,this.opts=this._normalizeOptions(t||{}),this.mode=this.opts.mode,this.layout=this.opts.layout,this.id=this.opts.id||he("zs"),this.isMount=/^(DIV|SPAN|SECTION|ARTICLE|FORM-FIELD)$/i.test(i.tagName)||(i.hasAttribute("data-zidan-select")||G(i,"zidan-select"))&&!/^(SELECT|INPUT|TEXTAREA)$/i.test(i.tagName),this.native=this.isMount?null:i,this.syncEl=null,this.items=[],this.value_=[],this.tags=[],this.activeIndex=-1,this.opened=!1,this.loading=!1,this.error=null,this.query="",this.rendered=[],this.listeners=new Map,this.asyncController=null,this.asyncItems=null,this.asyncQuery="",this.asyncPage=0,this.hasMore=!1,this.fetchingMore=!1,this.loadMoreError=null,this._fetchCache=Object.create(null),this._cacheKeys=[],this.timer=null,this.savedInputText="",this.disabled_=!!this.opts.disabled,this.destroyed=!1,this.resizeObserver=null,this._prepareData(),this._build(),this._prepareSync(),this._bind(),this._setInitialValue(),this._render(),this._observeResize(),i.__zidanSelect=this,this.emit("init",{instance:this,mode:this.mode,layout:this.layout,framework:this.framework}),this.call("onInit",{instance:this,mode:this.mode,value:this.getValue()})}s.prototype._normalizeOptions=function(e){e=w(Q(this.el),e);var t=this.el.dataset||{},i=this.el.tagName==="SELECT",r=/tags/i.test(t.zidanSelect||"")||/tags/i.test(t.zidanMode||""),n=e.mode||t.zidanMode||t.zidanSelect||(r?"tags":"select");n=String(n).toLowerCase(),(n==="multi"||n==="multiselect")&&(n="select"),["select","combobox","tags"].indexOf(n)===-1&&(n="select");var a=i?this.el.multiple:!1,o=e.themeFramework||t.zidanFramework||"auto";o=String(o).toLowerCase(),C.indexOf(o)===-1&&(o="auto");var h=e.layout||t.zidanLayout||"classic-clean";h=String(h).toLowerCase(),M.indexOf(h)===-1&&(h="classic-clean");var l=e.scrollbar||t.zidanScrollbar||_.scrollbar;l=String(l).toLowerCase(),I.indexOf(l)===-1&&(l=_.scrollbar);var d=function(f,p){return e[f]!==void 0&&e[f]!==null?e[f]:p},y=n==="tags"?"Add a tag\u2026":n==="combobox"?"Type to search\u2026":"Select an option\u2026",u={};return Object.keys(_).forEach(function(f){u[f]=_[f]}),u.mode=n,u.layout=h,u.themeFramework=o,u.multiple=n==="tags"?!0:d("multiple",a||E(t.zidanMultiple,!1)),u.searchable=d("searchable",E(t.zidanSearchable,n!=="select")),u.clearable=d("clearable",E(t.zidanClearable,!1)),u.disabled=d("disabled",E(t.zidanDisabled,i?this.el.disabled:!1)),u.placeholder=d("placeholder",t.zidanPlaceholder||this.el.getAttribute&&this.el.getAttribute("placeholder")||y),u.label=d("label",t.zidanLabel||null),u.name=d("name",t.zidanName||this.el.getAttribute&&this.el.getAttribute("name")||null),u.allowFreeText=d("allowFreeText",E(t.zidanAllowFreeText,n==="tags")),u.maxTags=d("maxTags",t.zidanMaxTags?parseInt(t.zidanMaxTags,10)||1/0:_.maxTags),u.minTagLength=d("minTagLength",t.zidanMinTagLength?parseInt(t.zidanMinTagLength,10)||1:_.minTagLength),u.maxTagLength=d("maxTagLength",t.zidanMaxTagLength?parseInt(t.zidanMaxTagLength,10)||1/0:_.maxTagLength),u.caseSensitive=d("caseSensitive",E(t.zidanCaseSensitive,!1)),u.validation=d("validation",t.zidanValidation||null),u.options=d("options",null),u.suggestions=d("suggestions",null),u.fetchPageSize=d("fetchPageSize",t.zidanFetchPageSize?parseInt(t.zidanFetchPageSize,10)||0:_.fetchPageSize),u.autoLoadMore=d("autoLoadMore",E(t.zidanAutoLoadMore,_.autoLoadMore)),u.cacheResults=d("cacheResults",E(t.zidanCacheResults,_.cacheResults)),u.loadMoreText=d("loadMoreText",t.zidanLoadMoreText||_.loadMoreText),u.fetchUrl=d("fetchUrl",t.zidanFetchUrl||null),u.fetchMethod=d("fetchMethod",t.zidanFetchMethod||_.fetchMethod),u.fetchQueryParam=d("fetchQueryParam",t.zidanFetchQueryParam!==void 0?t.zidanFetchQueryParam:_.fetchQueryParam),u.fetchPageParam=d("fetchPageParam",t.zidanFetchPageParam!==void 0?t.zidanFetchPageParam:_.fetchPageParam),u.fetchSkipParam=d("fetchSkipParam",t.zidanFetchSkipParam||null),u.fetchPageSizeParam=d("fetchPageSizeParam",t.zidanFetchPageSizeParam!==void 0?t.zidanFetchPageSizeParam:_.fetchPageSizeParam),u.fetchItemsPath=d("fetchItemsPath",t.zidanFetchItemsPath||null),u.fetchTotalPath=d("fetchTotalPath",t.zidanFetchTotalPath||null),u.fetchHasMorePath=d("fetchHasMorePath",t.zidanFetchHasMorePath||null),Object.keys(e).forEach(function(f){e[f]!==void 0&&(u[f]=e[f])}),u.mode=n,u.layout=h,u.themeFramework=o,u.scrollbar=l,u.theme||(u.theme=t.zidanTheme||t.zsTheme||""),n==="combobox"&&(u.searchable=!0),n==="tags"&&u.searchable===!1&&(u.searchable=!0),n==="tags"&&(u.multiple=!0),u.fetchUrl&&typeof u.fetchOptions!="function"&&(u.fetchOptions=Se(u)),u},s.prototype._prepareData=function(){var e=this.opts.options;if(!e&&this.el.tagName==="SELECT"&&(e=this._optionsFromSelect(this.el)),e||(e=this.opts.suggestions||[]),this.items=this._normalizeItems(e),this.mode==="tags"){var t=this.opts.suggestions||this.opts.options;!t&&this.el.tagName==="SELECT"&&(t=this._optionsFromSelect(this.el)),this.suggestions=this._normalizeItems(t||[])}},s.prototype._optionsFromSelect=function(e){var t=[];return Array.prototype.slice.call(e.children||[]).forEach(function(i){if(i.tagName==="OPTGROUP"){var r=i.label||"";Array.prototype.slice.call(i.children).forEach(function(n){n.tagName==="OPTION"&&t.push({value:n.value,label:n.textContent.trim(),group:r,disabled:n.disabled})})}else i.tagName==="OPTION"&&t.push({value:i.value,label:i.textContent.trim(),disabled:i.disabled})}),t},s.prototype._normalizeItems=function(e){var t=T(e),i=[],r=this;return t.forEach(function(n,a){if(n!=null){if(typeof n=="string"||typeof n=="number"){i.push({value:String(n),label:String(n),group:null,disabled:!1});return}if(typeof n=="object"&&Array.isArray(n.options)){var o=n.label!==void 0?String(n.label):n.group||"";r._normalizeItems(n.options).forEach(function(l){l.group=o,i.push(l)});return}if(typeof n=="object"){var h=n.value!==void 0?n.value:n.label!==void 0?n.label:a;i.push({value:String(h),label:n.label!==void 0?String(n.label):String(h),group:n.group!==void 0?String(n.group):null,disabled:!!n.disabled,data:n.data})}}}),i},s.prototype._resolveFramework=function(){if(this.opts.themeFramework&&this.opts.themeFramework!=="auto")return this.opts.themeFramework;if(!c)return"vanilla";try{var e=g.getComputedStyle(c.documentElement),t=e.getPropertyValue("--bs-body-bg");if(t&&t.trim())return"bootstrap";for(var i=c.styleSheets||[],r=0;r<i.length;r+=1){var n=i[r].href||"";if(/bootstrap(\.min)?\.css/i.test(n))return"bootstrap";if(/tailwind/i.test(n))return"tailwind"}if(c.body&&g.getComputedStyle(c.body).getPropertyValue("--tw-ring-offset-shadow")!=="")return"tailwind";if(c.querySelector(".btn-primary, .form-select, .form-control, .navbar"))return"bootstrap"}catch{}return"vanilla"},s.prototype._applyCustomClass=function(e,t){var i=this.opts.customClasses||{},r=i[t];return r&&K(e,r),e},s.prototype._toggleCustomClass=function(e,t,i){var r=this.opts.customClasses||{},n=r[t];return n&&String(n).split(/\s+/).forEach(function(a){a&&(i?e.classList.add(a):e.classList.remove(a))}),e},s.prototype._build=function(){var e=this,t=this.opts;this.framework=this._resolveFramework();var i=this.el.parentNode&&this.el.parentNode.classList&&this.el.parentNode.classList.contains("zs-root--mount"),r=ge(this.el,{theme:t.theme,framework:t.themeFramework,layout:t.layout});this.theme=r.theme;var n=m("div","zs-root");n.id=this.id+"-root",n.setAttribute("data-zs-theme",this.theme),n.setAttribute("data-zs-layout",this.layout),n.setAttribute("data-zs-framework",this.framework),n.setAttribute("data-zs-mode",this.mode),n.setAttribute("data-zs-scrollbar",t.scrollbar||"default"),ue(this.el)&&n.setAttribute("dir","rtl"),n.classList.add("zs-root--"+this.mode),this.mode==="tags"&&n.classList.add("zs-root--multiple"),t.multiple&&this.mode==="select"&&n.classList.add("zs-root--multiple"),this.layout==="floating-label"&&n.classList.add("zs-root--labeled"),this._applyCustomClass(n,"root");var a=m("div","zs-control");this.framework==="bootstrap"&&(a.classList.add("form-control","zs-bootstrap-control"),this.el.tagName==="SELECT"&&a.classList.add("form-select")),this._applyCustomClass(a,"control");var o=m("div","zs-chips");o.hidden=!0;var h=c.createElement("input");h.type="text",h.className="zs-input",h.id=this.id+"-input",h.autocomplete="off",h.spellcheck=!1,h.setAttribute("role","combobox"),h.setAttribute("aria-expanded","false"),h.setAttribute("aria-controls",this.id+"-listbox"),h.setAttribute("aria-autocomplete",t.searchable||this.mode!=="select"?"list":"none"),h.setAttribute("aria-haspopup","listbox"),this.mode==="select"&&!t.searchable&&(h.readOnly=!0),(t.ariaLabel||t.label)&&h.setAttribute("aria-label",t.ariaLabel||t.label),t.disabled&&(h.disabled=!0),this._applyCustomClass(h,"input");var l=null;if(t.label){l=m("label","zs-label",{for:h.id}),l.textContent=t.label,this.layout!=="floating-label"&&n.classList.add("zs-root--has-static-label");var d=this.el.labels&&this.el.labels[0]?this.el.labels[0]:null;d&&d.closest&&d.closest(".zs-root")&&(d=null),this._authorLabel=d||null,d&&(d.hidden=!0,d.setAttribute("data-zs-hidden-label","true"))}var y=m("button","zs-clear",{type:"button",tabindex:"-1","aria-label":t.clearText,title:t.clearText});y.innerHTML='<svg viewBox="0 0 16 16" width="12" height="12" aria-hidden="true" focusable="false"><path d="M3 3l10 10M13 3L3 13" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>',y.hidden=!0;var u=m("span","zs-arrow",{"aria-hidden":"true"});u.innerHTML='<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" focusable="false"><path d="M3.5 6l4.5 4.5L12.5 6" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/></svg>',a.appendChild(o),a.appendChild(h),a.appendChild(y),a.appendChild(u),l&&(this.layout==="floating-label"?a.insertBefore(l,o):n.appendChild(l));var f=m("div","zs-dropdown");f.id=this.id+"-listbox",f.setAttribute("role","listbox"),f.setAttribute("aria-multiselectable",String(!!(t.multiple||this.mode==="tags"))),this._applyCustomClass(f,"dropdown");var p=m("div","zs-live",{"aria-live":"polite","aria-atomic":"true"});n.appendChild(a),n.appendChild(f),n.appendChild(p),this.framework==="bootstrap"&&(t.validation==="invalid"&&a.classList.add("is-invalid"),t.validation==="valid"&&a.classList.add("is-valid"),(this.mode==="tags"||t.multiple)&&n.classList.add("zs-root--bootstrap")),this.isMount?(i||this.el.classList.add("zs-root--mount"),this.el.appendChild(n)):this.el.parentNode.insertBefore(n,this.el),this.root=n,this.controlEl=a,this.chipsEl=o,this.input=h,this.dropdown=f,this.clearBtn=y,this.arrowEl=u,this.labelEl=l,this.liveEl=p},s.prototype._prepareSync=function(){var e=this,t=this.opts;if(this.native)this.native.tagName==="SELECT"?(this.syncEl=this.native,this.native.multiple&&(this.opts.multiple=!0,this.root.classList.add("zs-root--multiple")),this.native.hidden=!0,this.native.classList.add("zs-native"),this.native.setAttribute("tabindex","-1"),this.native.setAttribute("aria-hidden","true")):(this.syncEl=this.native,this.native.hidden=!0,this.native.setAttribute("tabindex","-1"),this.native.setAttribute("aria-hidden","true")),t.required&&this.input.setAttribute("aria-required","true"),this.form=this.native.closest?this.native.closest("form"):null;else if(t.name){var i=m("input","zs-hidden",{type:"hidden",name:t.name});this.root.appendChild(i),this.syncEl=i,this.form=this.el.closest?this.el.closest("form"):null}else this.form=this.el.closest?this.el.closest("form"):null;return this.form&&(this.onFormReset=function(){setTimeout(function(){e._handleFormReset()},0)},this.form.addEventListener("reset",this.onFormReset)),t.required&&this.native&&this.native.tagName==="SELECT"&&!this.native.required?(this.native.required=!0,this._nativeRequiredAdded=!0):t.required&&!this.native&&this.form&&(this.onFormSubmit=function(r){e.value_.length||(r.preventDefault(),e.setValidation("invalid"),e.input&&e.input.focus&&e.input.focus(),e.announce("Please select an option."))},this.form.addEventListener("submit",this.onFormSubmit)),this.syncEl},s.prototype._setInitialValue=function(){var e=this.opts,t=e.value;if(t==null&&(this.native&&this.native.tagName==="SELECT"?t=this.native.multiple?Array.prototype.filter.call(this.native.options,function(r){return r.selected}).map(function(r){return r.value}):this.native.value:this.native&&(t=this.native.value)),this.mode==="tags"){var i=t;typeof i=="string"&&i&&!Array.isArray(i)&&this.syncEl&&this.syncEl.tagName!=="SELECT"&&(i=i.split(e.valueDelimiter)),T(i).forEach(function(r){this._addTagObject(String(r),{silent:!0})},this);return}t==null||t===""||this._setValueInternal(t,{silent:!0})},s.prototype._handleFormReset=function(){var e;if(this.native&&this.native.tagName==="SELECT"?e=this.native.multiple?Array.prototype.filter.call(this.native.options,function(t){return t.selected}).map(function(t){return t.value}):this.native.value:this.native?e=this.native.value:this.opts.value!==null&&this.opts.value!==void 0&&(e=this.opts.value),this.mode==="tags"){this.value_=[],T(e).forEach(function(t){this._addTagObject(t,{silent:!0})},this),this._render(),this._syncNative();return}this._setValueInternal(e,{silent:!0}),this._render()},s.prototype._hasValue=function(e){for(var t=this.opts.caseSensitive?String(e):String(e).toLowerCase(),i=0;i<this.value_.length;i+=1){var r=this.opts.caseSensitive?this.value_[i].value:this.value_[i].value.toLowerCase();if(r===t)return!0}return!1},s.prototype._itemFor=function(e){for(var t=String(e),i=0;i<this.items.length;i+=1)if(this.items[i].value===t)return this.items[i];for(var r=0;r<this.value_.length;r+=1)if(this.value_[r].value===t)return this.value_[r];return{value:t,label:t}},s.prototype._setValueInternal=function(e,t){var i=t||{},r=this.getValue(),n=this,a=T(e),o=[];if(a.forEach(function(l){if(!(l==null||l==="")){if(typeof l=="object"){o.push({value:String(l.value!==void 0?l.value:l.label),label:String(l.label!==void 0?l.label:l.value),data:l.data});return}for(var d=String(l),y=null,u=0;u<n.items.length;u+=1)if(n.items[u].value===d){y=n.items[u];break}o.push(y?{value:y.value,label:y.label,data:y.data}:{value:d,label:d})}}),!this.opts.multiple&&this.mode!=="tags"&&(o=o.slice(0,1)),this.value_=o,o.length&&this.opts.validation==="invalid"&&!i.silent&&(this.opts.validation=null),this._render(),this._syncNative(),!i.silent){var h=this.getValue();h!==r&&JSON.stringify(h)!==JSON.stringify(r)&&(this.emit("change",{value:h,previousValue:r,instance:this}),this.call("onChange",{value:h,previousValue:r,instance:this}))}return this},s.prototype._syncNative=function(){var e=this.syncEl;if(e){var t=this.value_.map(function(h){return h.value});if(e.tagName==="SELECT"){var i;if(e.multiple){for(i=0;i<e.options.length;i+=1)e.options[i].selected=t.indexOf(e.options[i].value)!==-1;var r=Array.prototype.map.call(e.options,function(h){return h.value});t.forEach(function(h){if(r.indexOf(h)===-1){var l=c.createElement("option");l.value=h,l.textContent=h,l.selected=!0,e.appendChild(l)}})}else{var n=t[0];if(n===void 0)e.value="";else{var a=!1;for(i=0;i<e.options.length;i+=1)if(e.options[i].value===n){a=!0;break}if(!a){var o=c.createElement("option");o.value=n,o.textContent=this._itemFor(n).label,e.appendChild(o)}e.value=n}}}else e.value=this.opts.multiple||this.mode==="tags"?t.join(this.opts.valueDelimiter):t[0]||""}},s.prototype._render=function(){var e=this.opts,t=this.value_.length>0;this.root.classList.toggle("zs-root--has-value",t),this.root.classList.toggle("zs-root--open",this.opened),this.root.classList.toggle("zs-root--disabled",!!this.disabled_),this.root.classList.toggle("zs-root--invalid",e.validation==="invalid"),this.root.classList.toggle("zs-root--valid",e.validation==="valid"),e.validation==="invalid"?this.root.setAttribute("data-zs-validation","invalid"):e.validation==="valid"?this.root.setAttribute("data-zs-validation","valid"):this.root.removeAttribute("data-zs-validation"),e.validation==="invalid"?this.input.setAttribute("aria-invalid","true"):e.validation==="valid"?this.input.setAttribute("aria-invalid","false"):this.input.removeAttribute("aria-invalid"),(this.el.required||e.required)&&this.input.setAttribute("aria-required","true"),e.validation==="invalid"?this.controlEl.classList.add("is-invalid"):this.controlEl.classList.remove("is-invalid"),e.validation==="valid"?this.controlEl.classList.add("is-valid"):this.controlEl.classList.remove("is-valid"),this._toggleCustomClass(this.controlEl,"invalid",e.validation==="invalid"),this._renderChips(),this._renderInputValue();var i=e.clearable&&t&&!this.disabled_;return this.clearBtn.hidden=!i,this.clearBtn.tabIndex=i?0:-1,this.input.disabled=!!this.disabled_,this.input.setAttribute("aria-expanded",String(this.opened)),this.root.classList.toggle("zs-root--placeholder",!this.input.value&&!t),this},s.prototype._renderChips=function(){var e=this,t=this.mode==="tags"||!!this.opts.multiple,i=this.chipsEl;i.textContent="",i.hidden=!t,t&&(this.value_.forEach(function(r,n){var a=m("span","zs-chip",{"data-zs-index":n});e.framework==="bootstrap"&&K(a,"badge rounded-pill"),e._applyCustomClass(a,"chip");var o,h=typeof e.opts.renderTag=="function"&&e.mode==="tags"?e.opts.renderTag({value:r.value,label:r.label},{index:n,instance:e,disabled:e.disabled_}):null;if(e.mode==="select"&&typeof e.opts.renderSelected=="function"&&(h=e.opts.renderSelected({value:r.value,label:r.label},{index:n,instance:e})),h)if(b(h))o=h,a.appendChild(o);else{var l=m("span","zs-chip-label");l.innerHTML=String(h),a.appendChild(l)}else o=m("span","zs-chip-label",null,r.label),a.appendChild(o);var d=m("button","zs-chip-remove",{type:"button","aria-label":"Remove "+r.label,title:"Remove "+r.label,"data-zs-remove":n});d.innerHTML='<svg viewBox="0 0 16 16" width="10" height="10" aria-hidden="true" focusable="false"><path d="M4 4l8 8M12 4l-8 8" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',e._applyCustomClass(d,"chipRemove"),a.appendChild(d),i.appendChild(a)}),this.root.classList.toggle("zs-root--has-value",this.value_.length>0))},s.prototype._renderInputValue=function(){var e=this.mode!=="tags"&&!this.opts.multiple;if(!e){this.input.placeholder=this.value_.length?"":this.opts.placeholder||"",this.opened?this.input.value=this.query:this.input.value="";return}if(this.opened&&this.opts.searchable){this.input.value=this.query,this.input.placeholder=this.opts.placeholder||"";return}if(this.opened&&!this.opts.searchable){this.input.value=this.value_.length?this.value_[0].label:"",this.input.placeholder=this.opts.placeholder||"";return}this.input.value=this.value_.length?this.value_[0].label:"",this.input.placeholder=this.opts.placeholder||"",this.value_.length||(this.input.value="")},s.prototype._sourceItems=function(){return this.mode==="tags"?this.suggestions||[]:typeof this.opts.fetchOptions=="function"&&this.asyncItems?this.asyncItems:this.items},s.prototype._visibleItems=function(){var e=this,t=this.query.trim(),i=this._sourceItems(),r=!!this.opts.caseSensitive,n=typeof this.opts.fetchOptions=="function"&&!!this.asyncItems;return!t||n&&typeof this.opts.filterOption!="function"?i.slice():i.filter(function(a){if(typeof e.opts.filterOption=="function")return!!e.opts.filterOption(a,t,{instance:e,mode:e.mode,caseSensitive:r,selected:e._hasValue(a.value)});var o=r?a.label:a.label.toLowerCase(),h=r?t:t.toLowerCase();if(o.indexOf(h)!==-1)return!0;if(e.opts.searchValues){var l=r?a.value:a.value.toLowerCase();if(l.indexOf(h)!==-1)return!0}return!1})},s.prototype._renderDropdown=function(){var e=this;if(this.opened){var t=this.dropdown.scrollTop;if(this.dropdown.textContent="",this.rendered=[],this.loading){var i=m("div","zs-state zs-state--loading",{role:"status"});i.appendChild(m("span","zs-spinner",{"aria-hidden":"true"})),i.appendChild(m("span","zs-state-text",null,this.opts.loadingText)),this.dropdown.appendChild(i)}else if(this.error){var r=m("div","zs-state zs-state--error",{role:"status"},this.error.message||"Something went wrong.");this.dropdown.appendChild(r)}else{var n=this._visibleItems();if(n.length){var o=null;n.forEach(function(l,d){if(l.group&&l.group!==o){var y=m("div","zs-group",{role:"presentation"},l.group);e.dropdown.appendChild(y),o=l.group}var u=e._hasValue(l.value),f=m("div","zs-option",{role:"option",id:e.id+"-opt-"+d,"data-zs-option":d});f.setAttribute("aria-selected",String(u)),l.disabled&&(f.setAttribute("aria-disabled","true"),f.classList.add("zs-option--disabled")),u&&f.classList.add("zs-option--selected"),e._applyCustomClass(f,"option"),u&&e._applyCustomClass(f,"selected"),l.disabled&&e._applyCustomClass(f,"disabled");var p=null;typeof e.opts.renderOption=="function"&&(p=e.opts.renderOption(l,{index:d,selected:u,active:d===e.activeIndex,query:e.query,instance:e})),p&&b(p)?f.appendChild(p):p!=null&&p!==""?f.innerHTML=String(p):f.appendChild(m("span","zs-option-label",null,l.label)),d===e.activeIndex&&(f.classList.add("zs-option--active"),e._applyCustomClass(f,"active")),e.rendered.push({element:f,item:l,index:d}),e.dropdown.appendChild(f)})}else{var a=this.query?this.opts.noResultsText:this.opts.emptyText;this.dropdown.appendChild(m("div","zs-state zs-state--empty",{role:"status"},a)),this.emit("no-results",{query:this.query,instance:this})}if(this.hasMore){var h=m("button","zs-more",{type:"button"});this.fetchingMore?(h.appendChild(m("span","zs-spinner",{"aria-hidden":"true"})),h.appendChild(m("span",null,null,this.opts.loadingText||"Loading\u2026")),h.disabled=!0,h.setAttribute("aria-busy","true")):(h.textContent=this.loadMoreError||this.opts.loadMoreText,this.loadMoreError&&h.classList.add("zs-more--error")),this.dropdown.appendChild(h)}}this.dropdown.scrollTop=t,this._updateActiveDescendant(!1),this.opened&&this._position()}},s.prototype._updateActiveDescendant=function(e){var t=this.rendered[this.activeIndex];if(t){if(this.input.setAttribute("aria-activedescendant",t.element.id),e!==!1){var i=t.element.offsetTop,r=i+t.element.offsetHeight;i<this.dropdown.scrollTop?this.dropdown.scrollTop=i-4:r>this.dropdown.scrollTop+this.dropdown.clientHeight&&(this.dropdown.scrollTop=r-this.dropdown.clientHeight+4)}}else this.input.removeAttribute("aria-activedescendant")},s.prototype._position=function(){if(this.opened){var e=this.controlEl.getBoundingClientRect(),t=g.innerHeight||c.documentElement.clientHeight,i=t-e.bottom-12,r=e.top-12,n=i<160&&r>i;this.root.classList.toggle("zs-root--dropup",n);var a=n?r:i,o=de(a,120,this.opts.maxDropdownHeight||280);this.dropdown.style.maxHeight=Math.max(120,o)+"px";var h=e.width;this.dropdown.style.minWidth=h+"px",this.root.classList.contains("zs-root--mount")&&(this.dropdown.style.left="0px",this.dropdown.style.right="0px")}},s.prototype.open=function(){if(this.destroyed||this.disabled_||this.opened)return this;if(this.opened=!0,this.query="",this.activeIndex=-1,this.loadMoreError=null,this.fetchingMore=!1,(this.mode==="combobox"||this.mode==="select"&&this.opts.searchable)&&(this.savedInputText=this.input.value),this.root.classList.add("zs-root--open"),this.dropdown.setAttribute("data-zs-visible","true"),this._render(),this._renderDropdown(),this._position(),this.emit("open",{instance:this}),this.call("onOpen",{instance:this}),typeof this.opts.fetchOptions=="function"&&(!this.asyncItems||this.asyncQuery!==""))this._fetch("");else if(this.mode!=="tags"){var e=this._firstEnabledIndex();e!==-1&&(this.activeIndex=e,this._renderDropdown())}if(this.opts.searchable&&!this.disabled_)try{this.input.select()}catch{this.input.focus()}var t=this._visibleItems();return this.announce(t.length+" option"+(t.length===1?"":"s")+" available"),this},s.prototype.close=function(){return this.destroyed||!this.opened?this:(this.opened=!1,this.root.classList.remove("zs-root--open"),this.dropdown.removeAttribute("data-zs-visible"),this.activeIndex=-1,this.query="",typeof this.opts.fetchOptions=="function"&&(this.asyncController&&(this.asyncController.abort(),this.asyncController=null),this.loading=!1,this.fetchingMore=!1,this.loadMoreError=null),this._render(),this.emit("close",{instance:this}),this.call("onClose",{instance:this}),this)},s.prototype.toggle=function(){return this.opened?this.close():this.open()},s.prototype._firstEnabledIndex=function(){for(var e=this._visibleItems(),t=0;t<e.length;t+=1)if(!e[t].disabled)return t;return-1},s.prototype._selectRendered=function(e){var t=this.rendered[e];return!t||t.item.disabled?!1:(this._selectItem(t.item),!0)},s.prototype._selectItem=function(e){if(!e||e.disabled)return this;var t=this.getValue();if(this.mode==="tags")return this.addTag(e.label),this.query="",this._renderDropdown(),this;if(this.mode==="combobox"&&this.opts.allowFreeText)this._setValueInternal([e.value]);else if(this.opts.multiple){if(this._hasValue(e.value)){this.value_=this.value_.filter(function(n){return n.value!==e.value}),this._render(),this._syncNative();var i=this.getValue();return JSON.stringify(i)!==JSON.stringify(t)&&(this.emit("change",{value:i,previousValue:t,instance:this}),this.call("onChange",{value:i,previousValue:t,instance:this})),this._renderDropdown(),this}this._setValueInternal(this.value_.concat([e]))}else this._setValueInternal([e]);this.emit("select",{value:this.getValue(),item:e,instance:this}),this.call("onSelect",{value:this.getValue(),item:e,instance:this});var r=this.opts.closeOnSelect===null?!this.opts.multiple:this.opts.closeOnSelect;return r?this.close():this.opened&&this._renderDropdown(),this},s.prototype._cacheKey=function(e,t){return e+"\0"+t},s.prototype._cacheGet=function(e,t){if(!this.opts.cacheResults)return null;var i=this._cacheKey(e,t),r=this._fetchCache[i];if(!r)return null;var n=this._cacheKeys.indexOf(i);return n!==-1&&(this._cacheKeys.splice(n,1),this._cacheKeys.push(i)),r},s.prototype._cacheSet=function(e,t,i){if(this.opts.cacheResults){var r=this._cacheKey(e,t);this._fetchCache[r]=i;var n=this._cacheKeys.indexOf(r);n!==-1&&this._cacheKeys.splice(n,1),this._cacheKeys.push(r);for(var a=s.cacheLimit||50;this._cacheKeys.length>a;)delete this._fetchCache[this._cacheKeys.shift()]}},s.prototype.clearCache=function(){return this._fetchCache=Object.create(null),this._cacheKeys=[],this},s.prototype._readFetchPayload=function(e,t,i){var r=e,n=!1;return e&&!Array.isArray(e)&&typeof e=="object"?(r=e.items||e.options||e.results||[],e.hasMore!==void 0?n=!!e.hasMore:e.total!==void 0&&i>0?n=(t+1)*i<Number(e.total):i>0&&(n=T(r).length>=i)):i>0&&(n=T(r).length>=i),{items:this._normalizeItems(r),hasMore:n}},s.prototype._applyCachedPage=function(e,t,i){var r=this._cacheGet(e,t);return r?(this.loading=!1,this.fetchingMore=!1,this.loadMoreError=null,this.error=null,this.asyncQuery=e,this.asyncPage=t,this.asyncItems=i?(this.asyncItems||[]).concat(r.items):r.items.slice(),this.hasMore=!!r.hasMore,i||(this.activeIndex=-1),this._renderDropdown(),!0):!1},s.prototype._fetch=function(e,t,i){var r=this;if(typeof this.opts.fetchOptions!="function")return Promise.resolve([]);if(e=e==null?"":String(e),t=t==null?0:parseInt(t,10)||0,i=!!i,i&&(this.loading||this.fetchingMore||!this.hasMore))return Promise.resolve([]);var n=this._cacheGet(e,t);if(n&&(!i||this.hasMore))return this.asyncController&&this.asyncController.abort(),this.asyncController=null,this._applyCachedPage(e,t,i),Promise.resolve(this._visibleItems());this.asyncController&&this.asyncController.abort();var a=typeof AbortController!="undefined"?new AbortController:null;this.asyncController=a,this.loading=!i,this.fetchingMore=i,this.error=null,this.loadMoreError=null,i||(this.hasMore=!1,this.asyncPage=0,this.announce(this.opts.loadingText)),this._renderDropdown();var o,h=new Promise(function(f){o=f});a&&a.signal.addEventListener&&a.signal.addEventListener("abort",function(){o([])}),i&&(this.emit("load-more",{page:t,query:e,instance:this}),this.call("onLoadMore",{page:t,query:e,instance:this}));var l=this.opts.fetchPageSize>0?this.opts.fetchPageSize:0,d=function(f){if(!(a&&a.signal.aborted)){r.loading=!1,r.fetchingMore=!1,r.loadMoreError=null,r.error=null;var p=r._readFetchPayload(f,t,l);r.asyncQuery=e,r.asyncPage=t,r.asyncItems=i?(r.asyncItems||[]).concat(p.items):p.items,r.hasMore=p.hasMore,r._cacheSet(e,t,{items:p.items,hasMore:p.hasMore}),i||(r.activeIndex=-1),r._renderDropdown();var k=r._visibleItems().length;r.announce(k+" result"+(k===1?"":"s")),o(r._visibleItems())}},y=function(f){if(f&&f.name==="AbortError"){o([]);return}if(a&&a.signal.aborted){o([]);return}var p=f&&f.message||"Unable to load options.";r.loading=!1,r.fetchingMore=!1,i?r.loadMoreError=p:r.error={message:p},r.emit("error",{error:f,message:p,instance:r}),r.call("onError",{error:f,message:p,instance:r}),r._renderDropdown(),o([])};try{var u=this.opts.fetchOptions(e,a?a.signal:void 0,{page:t,pageSize:l,append:i,instance:this});u&&typeof u.then=="function"?u.then(d).catch(y):d(u)}catch(f){y(f)}return h},s.prototype.loadMore=function(){return typeof this.opts.fetchOptions!="function"?this:this.loading||this.fetchingMore||!this.hasMore?this:this._fetch(this.asyncQuery||this.query||"",this.asyncPage+1,!0)},s.prototype.hasMoreResults=function(){return!!this.hasMore},s.prototype.getAsyncState=function(){return{query:this.asyncQuery,page:this.asyncPage,hasMore:!!this.hasMore,loading:!!this.loading,fetchingMore:!!this.fetchingMore,error:this.error?this.error.message:null}},s.prototype.refreshOptions=function(){return this.clearCache(),typeof this.opts.fetchOptions!="function"?this:(this.asyncItems=null,this.asyncQuery="",this.asyncPage=0,this.hasMore=!1,this.opened?this._fetch(this.query,0,!1):this)},s.prototype._tagError=function(e){this.announce(e),this.emit("error",{message:e,instance:this}),this.call("onError",{message:e,instance:this}),this.root.classList.add("zs-root--shake");var t=this.root;setTimeout(function(){t.classList.remove("zs-root--shake")},320)},s.prototype._addTagObject=function(e,t){var i=t||{},r=this.opts,n=String(e==null?"":e).trim();if(!n)return!1;if(this.value_.length>=r.maxTags)return i.silent||this._tagError("You can add up to "+r.maxTags+" tags."),!1;if(n.length<r.minTagLength)return i.silent||this._tagError("Tags need at least "+r.minTagLength+" character"+(r.minTagLength===1?"":"s")+"."),!1;if(n.length>r.maxTagLength)return i.silent||this._tagError("Tags can be at most "+r.maxTagLength+" characters."),!1;if(this._hasValue(n))return i.silent||this._tagError('"'+n+'" is already added.'),!1;if(this.mode==="tags"&&!r.allowFreeText){for(var a=this.suggestions&&this.suggestions.length?this.suggestions:this.items,o=r.caseSensitive?n:n.toLowerCase(),h=!1,l=0;l<a.length;l+=1){var d=r.caseSensitive?String(a[l].value):String(a[l].value).toLowerCase(),y=r.caseSensitive?String(a[l].label):String(a[l].label).toLowerCase();if(d===o||y===o){h=!0;break}}if(!h)return i.silent||this._tagError('"'+n+'" is not in the list.'),!1}var u=n;if(typeof r.formatTag=="function"){var f=r.formatTag(n,{instance:this,tags:this.getTags()});typeof f=="string"&&f&&(u=f)}if(typeof r.validateTag=="function"){var p=r.validateTag(u,this.getTags(),{instance:this});if(p===!1)return i.silent||this._tagError('"'+u+'" is not allowed.'),!1;if(typeof p=="string")return i.silent||this._tagError(p),!1}var k={value:u,label:u};return this.value_.push(k),this.query="",this.opts.validation==="invalid"&&(this.opts.validation=null),i.silent||(this._render(),this._syncNative(),this.opened&&this._renderDropdown(),this.announce(u+" added. "+this.value_.length+" tag"+(this.value_.length===1?"":"s")+" total."),this.emit("tag-add",{tag:u,value:this.getTags(),instance:this}),this.call("onTagAdd",{tag:u,value:this.getTags(),instance:this}),this.emit("change",{value:this.getTags(),instance:this}),this.call("onChange",{value:this.getTags(),instance:this})),!0},s.prototype.addTag=function(e){var t=this._addTagObject(e,{});return this._render(),this.opened&&this._renderDropdown(),t},s.prototype.removeTag=function(e){var t=typeof e=="number"?e:this.value_.findIndex(function(r){return String(r.value)===String(e)||String(r.label)===String(e)});if(t<0||t>=this.value_.length)return!1;var i=this.value_.splice(t,1)[0];return this._render(),this._syncNative(),this.opened&&this._renderDropdown(),this.announce(i.label+" removed. "+this.value_.length+" tag"+(this.value_.length===1?"":"s")+" remaining."),this.emit("tag-remove",{tag:i.value,value:this.getTags(),instance:this}),this.call("onTagRemove",{tag:i.value,value:this.getTags(),instance:this}),this.emit("change",{value:this.getTags(),instance:this}),this.call("onChange",{value:this.getTags(),instance:this}),this.input.focus(),!0},s.prototype.getTags=function(){return this.value_.map(function(e){return e.value})},s.prototype._onKeyDown=function(e){if(!this.destroyed){var t=e.key,i=this._visibleItems();if((t===" "||t==="Spacebar")&&!this.opened){e.preventDefault(),this.open();return}if(t==="ArrowDown"||t==="ArrowUp"){if(e.preventDefault(),!this.opened){this.open();return}if(!i.length)return;for(var r=t==="ArrowDown"?1:-1,n=this.activeIndex,a=0;a<i.length&&(n+=r,n<0&&(n=i.length-1),n>=i.length&&(n=0),!!i[n].disabled);a+=1);this.activeIndex=n,this._renderDropdown();return}if(t==="Home"||t==="End"){if(!this.opened)return;e.preventDefault();var o=-1,h;if(t==="Home"){for(h=0;h<i.length;h+=1)if(!i[h].disabled){o=h;break}}else for(h=i.length-1;h>=0;h-=1)if(!i[h].disabled){o=h;break}this.activeIndex=o,this._renderDropdown();return}if(t==="Enter"){if(this.opened){if(e.preventDefault(),this.activeIndex>=0){this._selectRendered(this.activeIndex),this.mode==="tags"&&(this.query="");return}if(this.mode==="tags"){this._commitTypedTag();return}if((this.mode==="combobox"||this.mode==="select")&&this.opts.allowFreeText){var l=this.query.trim();l&&(this._setValueInternal([l]),this.emit("select",{value:this.getValue(),item:{value:l,label:l},instance:this}),this.call("onSelect",{value:this.getValue(),item:{value:l,label:l},instance:this}),this.close());return}i.length===1&&this._selectRendered(0);return}if(this.mode==="tags"&&this.query.trim()){e.preventDefault(),this._commitTypedTag();return}e.preventDefault(),this.open();return}if(t==="Escape"){this.opened&&(e.preventDefault(),this.close());return}if(t==="Tab"){this.mode==="tags"&&this.opts.commitOnTab&&this.query.trim()&&this._commitTypedTag(),this.opened&&this.close();return}if(t==="Backspace"){if(this.mode==="tags"&&!this.input.value&&!this.query&&this.value_.length){e.preventDefault(),this.removeTag(this.value_.length-1);return}!this.input.value&&this.opened&&this.close();return}t==="Delete"&&this.opts.clearable&&this.value_.length&&(e.preventDefault(),this.clear())}},s.prototype._commitTypedTag=function(){var e=this.input.value,t=this._splitTags(e),i=!1;return t.forEach(function(r){this._addTagObject(r,{})&&(i=!0)},this),this.input.value="",this.query="",this._render(),this._syncNative(),this.opened&&this._renderDropdown(),i},s.prototype._splitTags=function(e){var t=String(e||""),i=this.opts.delimiters||[],r=[t];return i.forEach(function(n){n&&(r=r.reduce(function(a,o){return a.concat(o.split(n))},[]))}),r.map(function(n){return n.trim()}).filter(Boolean)},s.prototype._bind=function(){var e=this;this.onInput=function(){var t=e.input.value;if(!(e.mode==="select"&&!e.opts.searchable)&&(e.query=t,e.opened?(typeof e.opts.fetchOptions=="function"&&e.query.length>=(e.opts.minChars||0)&&(e.opts.debounce>0?e.debouncedFetch(e.query):e._fetch(e.query)),e.activeIndex=e.mode==="tags"?-1:e._firstEnabledIndex(),e._renderDropdown()):(e.open(),e.query=t,e.input.value=t,e._renderDropdown()),e.mode==="tags")){var i=e.opts.delimiters||[],r=i.some(function(n){return n&&t.indexOf(n)!==-1});r&&e._commitTypedTag()}},this.onKeyDown=function(t){e._onKeyDown(t)},this.onFocus=function(){e.disabled_||(e.root.classList.add("zs-root--focus"),(e.mode==="combobox"||e.mode==="tags"||e.mode==="select"&&e.opts.searchable)&&(e.opened||e.open()))},this.onBlur=function(){e.root.classList.remove("zs-root--focus"),setTimeout(function(){e.destroyed||e.root.contains(c.activeElement)||(e.mode==="tags"&&e.query.trim()&&e.opts.commitOnBlur&&e._commitTypedTag(),e.mode==="combobox"&&e.opts.allowFreeText&&e.query.trim()&&e._setValueInternal([e.query.trim()]),e.query="",e.close(),e._render())},0)},this.onControlClick=function(t){if(!e.disabled_){var i=t.target;if(!(i.closest&&i.closest(".zs-clear"))&&!(i.closest&&i.closest(".zs-chip-remove"))){if(e.opened){if(!e.opts.searchable&&!e.input.readOnly)return;e.opts.searchable||e.close();return}e.open()}}},this.onControlMouseDown=function(t){if(t.target!==e.input){if(t.target.closest&&(t.target.closest(".zs-chip-remove")||t.target.closest(".zs-clear"))){t.preventDefault();return}(t.target===e.controlEl||t.target.closest&&t.target.closest(".zs-chips"))&&(t.preventDefault(),e.input.focus())}},this.onClearClick=function(t){t.preventDefault(),t.stopPropagation(),e.clear()},this.onChipsClick=function(t){var i=t.target.closest?t.target.closest("[data-zs-remove]"):null;if(i){t.preventDefault(),t.stopPropagation();var r=parseInt(i.getAttribute("data-zs-remove"),10);if(!isNaN(r))if(e.mode==="tags")e.removeTag(r);else{var n=e.value_[r];if(!n)return;var a=e.getValue();e.value_.splice(r,1),e._render(),e._syncNative(),e.emit("change",{value:e.getValue(),previousValue:a,item:n,instance:e}),e.call("onChange",{value:e.getValue(),previousValue:a,item:n,instance:e}),e.announce(n.label+" removed."),e.opened&&e._renderDropdown()}}},this.onDropdownMouseDown=function(t){t.preventDefault()},this.onDropdownClick=function(t){var i=t.target.closest?t.target.closest(".zs-more"):null;if(i){t.preventDefault(),t.stopPropagation(),e.loadMore();return}var r=t.target.closest?t.target.closest("[data-zs-option]"):null;if(r){t.preventDefault();var n=parseInt(r.getAttribute("data-zs-option"),10);isNaN(n)||(e.activeIndex=n,e._selectRendered(n),e.mode==="tags"&&e.input.focus())}},this.onDocumentPointerDown=function(t){if(e.opened){var i=t.composedPath?t.composedPath():[];i.indexOf(e.root)===-1&&(e.root.contains(t.target)||(e.close(),e._render()))}},this.onWindowResize=function(){e.opened&&e._position()},this.onDropdownScroll=function(){if(!(!e.opts.autoLoadMore||!e.opened||!e.hasMore)&&!(e.loading||e.fetchingMore)){var t=e.dropdown;t.scrollTop+t.clientHeight>=t.scrollHeight-24&&e.loadMore()}},this.debouncedFetch=ye(function(t){e._fetch(t)},this.opts.debounce),this.el&&this.el.addEventListener&&(this.onNativeInvalid=function(){e.setValidation("invalid"),e.input&&e.input.focus&&e.input.focus()},this.el.addEventListener("invalid",this.onNativeInvalid)),this.input.addEventListener("input",this.onInput),this.input.addEventListener("keydown",this.onKeyDown),this.input.addEventListener("focus",this.onFocus),this.input.addEventListener("blur",this.onBlur),this.controlEl.addEventListener("click",this.onControlClick),this.controlEl.addEventListener("mousedown",this.onControlMouseDown),this.chipsEl.addEventListener("click",this.onChipsClick),this.clearBtn.addEventListener("click",this.onClearClick),this.dropdown.addEventListener("mousedown",this.onDropdownMouseDown),this.dropdown.addEventListener("click",this.onDropdownClick),this.dropdown.addEventListener("scroll",this.onDropdownScroll),c.addEventListener("pointerdown",this.onDocumentPointerDown,!0),g.addEventListener("resize",this.onWindowResize)},s.prototype._observeResize=function(){if(typeof ResizeObserver!="undefined"){var e=this;this.resizeObserver=new ResizeObserver(function(){e.opened&&e._position()}),this.resizeObserver.observe(this.controlEl)}},s.prototype.getValue=function(){if(this.mode==="tags")return this.getTags();var e=this.value_.map(function(t){return t.value});return this.opts.multiple?e:e.length?e[0]:null},s.prototype.setValue=function(e,t){var i=t||{};if(this.mode==="tags"){var r=typeof e=="string"?this._splitTags(e):T(e),n=this.getTags();if(this.value_=[],r.forEach(function(o){this._addTagObject(o,{silent:!0})},this),this.value_.length&&this.opts.validation==="invalid"&&(this.opts.validation=null),this._render(),this._syncNative(),!i.silent){var a=this.getTags();JSON.stringify(a)!==JSON.stringify(n)&&(this.emit("change",{value:a,previousValue:n,instance:this}),this.call("onChange",{value:a,previousValue:n,instance:this}))}return this.opened&&this._renderDropdown(),this}return this._setValueInternal(e,i)},s.prototype.clear=function(){return this.mode==="tags"?this.value_.length?(this.value_=[],this._render(),this._syncNative(),this.announce("All tags removed."),this.emit("change",{value:[],instance:this}),this.call("onChange",{value:[],instance:this}),this.opened&&this._renderDropdown(),this):this:(this._setValueInternal([],{}),this._render(),this)},s.prototype.setOptions=function(e){var t=this._normalizeItems(e);if(this.mode==="tags")this.suggestions=t;else{this.items=t;var i=this;if(this.value_=this.value_.filter(function(r){for(var n=0;n<i.items.length;n+=1)if(i.items[n].value===r.value)return!0;return i.opts.allowFreeText}),this.native&&this.native.tagName==="SELECT"){for(;this.native.firstChild;)this.native.removeChild(this.native.firstChild);this.items.forEach(function(r){var n=c.createElement("option");n.value=r.value,n.textContent=r.label,r.disabled&&(n.disabled=!0),i.native.appendChild(n)})}}return this.asyncItems=null,this.asyncPage=0,this.hasMore=!1,this.loadMoreError=null,this.clearCache(),this.activeIndex=-1,this._render(),this._syncNative(),this.opened&&this._renderDropdown(),this},s.prototype.enable=function(){return this.disabled_=!1,this._render(),this},s.prototype.disable=function(){return this.disabled_=!0,this.close(),this._render(),this},s.prototype.setLayout=function(e){var t=String(e||"").toLowerCase();if(M.indexOf(t)===-1)throw new Error('ZidanSelect: unknown layout "'+e+'". Use: '+M.join(", "));return this.layout=t,this.opts.layout=t,this.root.setAttribute("data-zs-layout",t),this.root.classList.toggle("zs-root--labeled",t==="floating-label"),this._position(),this},s.prototype.setFramework=function(e){var t=String(e||"").toLowerCase();if(C.indexOf(t)===-1)throw new Error('ZidanSelect: unknown framework "'+e+'". Use: '+C.join(", "));return this.opts.themeFramework=t,this.framework=t==="auto"?this._resolveFramework():t,this.root.setAttribute("data-zs-framework",this.framework),this.controlEl.classList.toggle("form-control",this.framework==="bootstrap"),this.controlEl.classList.toggle("zs-bootstrap-control",this.framework==="bootstrap"),this.controlEl.classList.toggle("form-select",this.framework==="bootstrap"&&this.el.tagName==="SELECT"),this._applyCustomClass(this.root,"root"),this._render(),this},s.prototype.setScrollbar=function(e){var t=String(e||"").toLowerCase();if(I.indexOf(t)===-1)throw new Error('ZidanSelect: unknown scrollbar "'+e+'". Use: '+I.join(", "));return this.opts.scrollbar=t,this.root&&this.root.setAttribute("data-zs-scrollbar",t),this},s.prototype.setValidation=function(e){return this.opts.validation=e,this._render(),this},s.prototype.on=function(e,t){var i=this._eventName(e);return this.root.addEventListener(i,t),this.listeners.has(i)||this.listeners.set(i,[]),this.listeners.get(i).push(t),this},s.prototype.off=function(e,t){var i=this._eventName(e),r=this.listeners.get(i)||[];if(t)this.root.removeEventListener(i,t),this.listeners.set(i,r.filter(function(a){return a!==t}));else{var n=this.root;r.forEach(function(a){n.removeEventListener(i,a)}),this.listeners.set(i,[])}return this},s.prototype._eventName=function(e){var t=String(e||"");return t.indexOf(P)===0?t:P+t},s.prototype.emit=function(e,t){if(!this.root||!c)return this;var i;try{i=new CustomEvent(P+e,{bubbles:!0,cancelable:!1,detail:t||{}})}catch{i=c.createEvent("CustomEvent"),i.initCustomEvent(P+e,!0,!1,t||{})}return this.root.dispatchEvent(i),this},s.prototype.call=function(e,t){var i=this.opts[e];if(typeof i=="function")try{return i(t)}catch(r){this.emit("error",{error:r,message:r&&r.message||String(r),callback:e,instance:this});return}},s.prototype.announce=function(e){!this.liveEl||!e||(this.liveEl.textContent="",this.liveEl.textContent=e)},s.prototype.destroy=function(){if(this.destroyed)return this;this.destroyed=!0,this.debouncedFetch&&this.debouncedFetch.cancel(),this.asyncController&&this.asyncController.abort(),this.clearCache(),this.resizeObserver&&this.resizeObserver.disconnect(),this.form&&this.onFormReset&&this.form.removeEventListener("reset",this.onFormReset),this.form&&this.onFormSubmit&&this.form.removeEventListener("submit",this.onFormSubmit),this._nativeRequiredAdded&&this.native&&(this.native.required=!1,this._nativeRequiredAdded=!1),c.removeEventListener("pointerdown",this.onDocumentPointerDown,!0),g.removeEventListener("resize",this.onWindowResize),this.el&&this.onNativeInvalid&&this.el.removeEventListener("invalid",this.onNativeInvalid),this.emit("destroy",{instance:this}),this.root&&this.root.parentNode&&this.root.parentNode.removeChild(this.root),this._authorLabel&&(this._authorLabel.hidden=!1,this._authorLabel.removeAttribute("data-zs-hidden-label"),this._authorLabel=null),this.native?(this.native.hidden=!1,this.native.classList.remove("zs-native"),this.native.removeAttribute("tabindex"),this.native.removeAttribute("aria-hidden")):this.el.classList&&this.el.classList.contains("zs-root--mount")&&this.el.classList.remove("zs-root--mount"),this.el.__zidanSelect===this&&delete this.el.__zidanSelect,this.listeners.clear();var e=s.instances.indexOf(this);return e!==-1&&s.instances.splice(e,1),this},s.prototype.isOpen=function(){return this.opened},s.prototype.refresh=function(){return this._render(),this.opened&&this._renderDropdown(),this};function L(e){if(!b(e))return null;var t=String(e.getAttribute("data-zidan")||"").toLowerCase();if(oe.indexOf(t)!==-1)return t;if(e.hasAttribute("data-zidan-radio-group"))return"radio-group";if(e.hasAttribute("data-zidan-radio"))return"radio";if(e.hasAttribute("data-zidan-checkbox")||e.hasAttribute("data-zidan-switch"))return"checkbox";if(e.hasAttribute("data-zidan-file"))return"file";if(e.hasAttribute("data-zidan-textarea"))return"textarea";if(e.hasAttribute("data-zidan-input"))return"input";var i=String(e.type||"").toLowerCase();if(i==="checkbox")return"checkbox";if(i==="radio")return"radio";if(i==="file")return"file";if(G(e,"zidan-field")){if(e.tagName==="FIELDSET")return e.querySelector('input[type="radio"]')?"radio-group":null;if(e.tagName==="TEXTAREA")return"textarea";if(e.tagName!=="INPUT"||i==="radio")return null;if(typeof TEXT_TYPES!="undefined"&&TEXT_TYPES.indexOf(i)!==-1)return"input"}return null}function O(e,t,i){var r=w(Q(e),i);if(e.__zidanField&&!r.force)return e.__zidanField;switch(t){case"checkbox":return typeof ZidanCheckbox!="undefined"?new ZidanCheckbox(e,r):null;case"radio":case"radio-group":return typeof ZidanRadioGroup!="undefined"?new ZidanRadioGroup(e,r):null;case"file":return typeof ZidanFileUpload!="undefined"?new ZidanFileUpload(e,r):null;case"input":case"textarea":return typeof ZidanTextField!="undefined"?new ZidanTextField(e,r):null;default:return null}}function ee(e,t){var i=[];typeof e=="string"?i=Array.prototype.slice.call(c.querySelectorAll(e)):b(e)?i=[e]:e&&typeof e.length=="number"&&(i=Array.prototype.slice.call(e));var r=[];return i.forEach(function(n){if(!n.__zidanField){var a=L(n)||ne(n);if(a){if(a==="radio"||a==="radio-group"){if(/^INPUT$/i.test(n.tagName)&&(n=n.closest?n.closest("fieldset, [data-zidan-radio-group]"):null,!n))return;a="radio-group"}var o=O(n,a,t||{});o&&r.push(o)}}}),r.length===1?r[0]:r}function te(e,t){var i=[];return e.forEach(function(r){if(!(!b(r)||r.__zidanField)){var n=L(r);if(n){if(n==="radio"||n==="radio-group"){if(/^INPUT$/i.test(r.tagName)&&(r=r.closest?r.closest("fieldset, [data-zidan-radio-group]"):null,!r))return;n="radio-group"}var a=O(r,n,t||{});a&&i.push(a)}}}),i}function x(e,t){var i=e||c;if(!i||!i.querySelectorAll)return[];var r=Array.prototype.slice.call(i.querySelectorAll(j));return b(i)&&i.matches&&i.matches(j)&&r.unshift(i),te(r,t)}var v={version:z,__zidanFormGuard:z,themes:H,frameworks:C.slice(),fieldLayouts:U,fields:[],_register:function(e){v.fields.indexOf(e)===-1&&v.fields.push(e)},_unregister:function(e){var t=v.fields.indexOf(e);t!==-1&&v.fields.splice(t,1)},get:function(e){var t=typeof e=="string"?c.querySelector(e):e;return b(t)&&t.__zidanField||null},init:function(e,t){return x(e||c,t||{})},field:ee,refresh:function(e){return x(e||c,{}),v.fields.slice().forEach(function(t){t.update()}),v.fields.slice()},destroyAll:function(){return v.fields.slice().forEach(function(e){e.destroy()}),v.fields=[],typeof s!="undefined"&&s.destroyAll&&s.destroyAll(),v},observe:function(e,t){var i=e||c.body;if(!i||!g.MutationObserver)return null;var r=new g.MutationObserver(function(n){n.forEach(function(a){Array.prototype.slice.call(a.addedNodes).forEach(function(o){b(o)&&(L(o)&&O(o,L(o)==="radio"?"radio-group":L(o),t||{}),o.querySelectorAll&&x(o,t||{}))})}),v.fields.slice().forEach(function(a){a.el.isConnected||a.destroy()}),typeof s!="undefined"&&s.instances.slice().forEach(function(a){a.el.isConnected||a.destroy()})});return r.observe(i,{childList:!0,subtree:!0}),r}};v.api=null,v.registerIcon=W,v.icons=A,typeof PHONE_COUNTRIES!="undefined"&&(v.phoneCountries=PHONE_COUNTRIES,v.phoneFormats=PHONE_FORMATS.slice(),v.formatPhone=formatPhone,v.detectPhoneCountry=detectPhoneCountry),v.messages=D,v.variants={},typeof CHECKBOX_VARIANTS!="undefined"&&(v.variants.checkbox=CHECKBOX_VARIANTS.slice()),typeof SWITCH_STYLES!="undefined"&&(v.variants.switch=SWITCH_STYLES.slice()),typeof RADIO_VARIANTS!="undefined"&&(v.variants.radio=RADIO_VARIANTS.slice()),typeof FILE_VARIANTS!="undefined"&&(v.variants.file=FILE_VARIANTS.slice()),typeof RANGE_VARIANTS!="undefined"&&(v.variants.range=RANGE_VARIANTS.slice()),typeof STEPPER_MODES!="undefined"&&(v.stepperModes=STEPPER_MODES.slice()),v.fieldLayouts=U.slice(),typeof s!="undefined"&&(s.version=z,s.__zidanSelectGuard=z,s.layouts=M.slice(),s.frameworks=C.slice(),s.scrollbars=I.slice(),s.defaults=_,s.cacheLimit=50,s.get=function(e){var t=typeof e=="string"?c.querySelector(e):e;return b(t)&&t.__zidanSelect||null},s.instances=[],s.destroyAll=function(){s.instances.slice().forEach(function(e){e.destroy()}),s.instances=[]});function Ee(e,t){var i=[];typeof e=="string"?i=Array.prototype.slice.call(c.querySelectorAll(e)):e&&typeof e.length=="number"&&!b(e)&&e!==g?i=Array.prototype.slice.call(e):b(e)&&(i=[e]);var r=i.map(function(n){var a=new s(n,t||{});return s.instances.push(a),a});return r.length===1?r[0]:r}function V(e,t){return e.filter(function(i){return b(i)&&!i.__zidanSelect}).map(function(i){return s.instances.push(new s(i,t||{})),i.__zidanSelect})}function ie(e,t){var i=e||c;if(!i||!i.querySelectorAll)return[];var r=Array.prototype.slice.call(i.querySelectorAll(N));return b(i)&&i.matches&&i.matches(N)&&r.unshift(i),V(r,t)}function q(e,t){T(e).forEach(function(i){i&&(typeof i=="string"?t(i,null):i.selector&&t(String(i.selector),i.options||null))})}function re(e,t){q(e,function(i,r){V(Array.prototype.slice.call(c.querySelectorAll(i)),w(t,r))})}function Te(e,t){q(e,function(i,r){var n=w(t,r);Array.prototype.slice.call(c.querySelectorAll(i)).forEach(function(a){if(!(!b(a)||a.__zidanField)){var o=L(a)||ne(a);o&&(o==="radio"&&(o="radio-group"),O(a,o,n))}})})}function ne(e){return typeof TEXT_TYPES=="undefined"||!b(e)?null:e.tagName==="TEXTAREA"?"textarea":e.tagName!=="INPUT"?null:TEXT_TYPES.indexOf(String(e.type).toLowerCase())!==-1?"input":null}function ze(e,t){if(typeof s=="undefined")return[];var i=N+", select",r=Array.prototype.slice.call(e.querySelectorAll(i));return b(e)&&e.matches&&e.matches(i)&&r.unshift(e),V(r,t)}function ae(e,t,i){b(e)&&(ze(e,t),typeof ZidanFileUpload!="undefined"&&te(Array.prototype.slice.call(e.querySelectorAll('input[type="file"]')),i),(typeof ZidanCheckbox!="undefined"||typeof ZidanRadioGroup!="undefined"||typeof ZidanFileUpload!="undefined"||typeof ZidanTextField!="undefined")&&x(e,i))}function Ce(e,t,i){Array.prototype.slice.call(c.querySelectorAll(le)).forEach(function(r){ae(r,t,i)}),q(e,function(r,n){Array.prototype.slice.call(c.querySelectorAll(r)).forEach(function(a){ae(a,w(t,n),w(i,n))})})}function se(){if(c){var e=g.ZIDAN_FORM_CONFIG||g.ZIDAN_SELECT_CONFIG||{};if(e.autoInit!==!1&&!(g.ZidanSelect&&g.ZidanSelect.autoInit===!1)&&c.documentElement.getAttribute("data-zidan-auto-init")!=="false"){var t=typeof s!="undefined",i=typeof ZidanCheckbox!="undefined"||typeof ZidanRadioGroup!="undefined"||typeof ZidanFileUpload!="undefined"||typeof ZidanTextField!="undefined",r=e.options||{},n=e.fieldOptions||e.fields||{};t&&(e.selector?re(e.selector,r):re(e.targets||e.selectors,r)),i&&Te(e.fieldTargets,n),Ce(e.formTargets,r,n),t&&!e.selector&&ie(c,r),i&&x(c,n)}}}c&&(c.readyState==="loading"?c.addEventListener("DOMContentLoaded",se):setTimeout(se,0));var S={ZidanForm:v,registerIcon:W};return typeof s!="undefined"&&(S.ZidanSelect=s,S.zidanSelect=Ee,S.initZidanSelects=ie),(typeof ZidanCheckbox!="undefined"||typeof ZidanRadioGroup!="undefined"||typeof ZidanFileUpload!="undefined"||typeof ZidanTextField!="undefined")&&(S.zidanField=ee,S.initZidanForms=x),typeof ZidanCheckbox!="undefined"&&(S.ZidanCheckbox=ZidanCheckbox),typeof ZidanRadioGroup!="undefined"&&(S.ZidanRadioGroup=ZidanRadioGroup),typeof ZidanFileUpload!="undefined"&&(S.ZidanFileUpload=ZidanFileUpload),typeof ZidanTextField!="undefined"&&(S.ZidanTextField=ZidanTextField),typeof formatPhone=="function"&&(S.formatPhone=formatPhone,S.detectPhoneCountry=detectPhoneCountry),v.api=S,S});
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * ZidanForm v2.4.0
2
+ * ZidanForm v2.4.2
3
3
  * Zero-dependency form enhancement library: select / combobox / tags,
4
4
  * checkboxes, switches, radio groups, file upload with drag & drop and
5
5
  * upload progress, text / number / phone / date / range inputs and textarea.
@@ -32,7 +32,7 @@
32
32
  })(typeof window !== 'undefined' ? window : this, function (global) {
33
33
  'use strict';
34
34
 
35
- var VERSION = '2.4.0';
35
+ var VERSION = '2.4.2';
36
36
 
37
37
  // Loading the file twice (classic script + module wrapper, or two bundles)
38
38
  // must not replace the classes and orphan the live instances.