selective-ui 1.1.3 → 1.1.4

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,4 +1,4 @@
1
- /*! Selective UI v1.1.3 | MIT License */
1
+ /*! Selective UI v1.1.4 | MIT License */
2
2
  /**
3
3
  * @class
4
4
  */
@@ -5457,7 +5457,7 @@ class Selective {
5457
5457
  * to include component styles in the final bundle.
5458
5458
  */
5459
5459
  /** Base/global styles for SelectiveUI. */
5460
- const iVersion = "1.1.3";
5460
+ const iVersion = "1.1.4";
5461
5461
  const iName = "SelectiveUI";
5462
5462
  if (typeof globalThis.GLOBAL_SEUI == "undefined") {
5463
5463
  const SECLASS = new Selective();
@@ -1,2 +1,2 @@
1
- /*! Selective UI v1.1.3 | MIT License */
2
- function t(t){return new p(t??null)}function bind(t,i={}){globalThis.GLOBAL_SEUI.bind(t,i)}function find(t){return globalThis.GLOBAL_SEUI.find(t)}function destroy(t=null){globalThis.GLOBAL_SEUI.destroy(t)}function rebind(t,i={}){globalThis.GLOBAL_SEUI.rebind(t,i)}function effector(t){return globalThis.GLOBAL_SEUI.effector(t)}class i{constructor(){this.t={showPanel:!0,accessoryStyle:"top",multiple:!1,minWidth:"50px",width:"0px",offsetWidth:null,minHeight:"30px",height:"30px",panelHeight:"220px",panelMinHeight:"100px",disabled:!1,readonly:!1,selectall:!0,keepSelected:!0,placeholder:"Select value",altMask:"",autoclose:!1,autoscroll:!0,autofocus:!0,searchable:!0,loadingfield:!0,visible:!0,skipError:!1,customDelimiter:",",textLoading:"Processing...",textNoData:"No data available",textNotFound:"Not found",textSelectAll:"Select all",textDeselectAll:"Deselect all",textAccessoryDeselect:"Deselect: ",animationtime:200,delaysearchtime:200,allowHtml:!0,maxSelected:0,labelHalign:"left",labelValign:"center",imageMode:!1,imageWidth:"60px",imageHeight:"60px",imageBorderRadius:"4px",imagePosition:"right",ajax:null,on:{load:[],beforeShow:[],show:[],beforeChange:[],change:[],beforeClose:[],close:[]}},this.i=new Map,this.h=new Map,this.o=[]}}class s{static get l(){return this.u||(this.u=new i),this.u}static p(t){if(null===t||"object"!=typeof t)return t;const i=Array.isArray(t)?[]:{};for(const s in t)Object.prototype.hasOwnProperty.call(t,s)&&(i[s]=this.p(t[s]));return i}static m(t=6){let i="";for(let s=0;s<t;s++)i+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random()));return i}static v(t){if(!t)return[];if("string"==typeof t){const i=document.querySelectorAll(t);return Array.from(i)}return t instanceof Element?[t]:t instanceof NodeList||Array.isArray(t)?Array.from(t):[]}static T(t={}){return this.O(document.createElement(t.node??"div"),t,!0)}static O(t=document.documentElement,i=null,s=!1){const e={...i??{}},n=s?t:this.C(t.cloneNode(!0)),h=e.classList;return"string"==typeof h?n.classList.add(h):Array.isArray(h)&&n.classList.add(...h),delete e.classList,["style","dataset"].forEach(t=>{const i=e[t];i&&"object"==typeof i&&Object.assign(n[t],i),delete e[t]}),e.role&&(n.setAttribute("role",e.role+""),delete e.role),e.ariaLive&&(n.setAttribute("aria-live",e.ariaLive+""),delete e.ariaLive),e.A&&(n.setAttribute("aria-labelledby",e.A+""),delete e.A),e.S&&(n.setAttribute("aria-controls",e.S+""),delete e.S),e.L&&(n.setAttribute("aria-haspopup",e.L+""),delete e.L),e.P&&(n.setAttribute("aria-multiselectable",e.P+""),delete e.P),e.M&&(n.setAttribute("aria-autocomplete",e.M+""),delete e.M),e.event&&"object"==typeof e.event&&(Object.entries(e.event).forEach(([t,i])=>{n.addEventListener(t,i)}),delete e.event),Object.entries(e).forEach(([t,i])=>{null===i?n.removeAttribute(t):n[t]=i}),n}static C(t){if(t instanceof Element)return t;throw new TypeError("Node is not an Element")}static H(t){return this.$(t)}static $(t,i=null,s=!1,e=!1,n={}){let h=null;for(const o in t){const r=t[o],l=r?.tag?.tagName?r.tag:this.T(r.tag);n[o]=l,r?.j&&this.$(r.j,l,!1,!1,n),i?s?i.prepend(l):i.append(l):e||h||(h=l)}return e||(n.id=this.m(7),i||(n={tags:n,view:h})),n}static F(t,i){const s=this.p(i);for(const i in s){const e=t[i];e?s[i]=e:void 0!==t?.dataset?.[i]&&(s[i]=t.dataset[i])}return s}static I(...t){if(0===t.length)return{};if(1===t.length)return this.p(t[0]);const i=this.p(t[0]);for(let s=1;s<t.length;s++){const e=t[s];for(const t in e)if("on"===t){const s=e[t];for(const e in s)i[t][e].push(s[e])}else i[t]=e[t]}return i}static V(t){if("boolean"==typeof t)return t;if("string"!=typeof t)return!!t;switch(t.trim().toLowerCase()){case"true":case"1":case"yes":case"on":return!0;default:return!1}}static k(t){return this.l.i.delete(t)}static R(t){return this.l.i.get(t)}static _(t,i){this.l.i.set(t,i)}static D(t){return this.l.h.delete(t)}static N(t){return this.l.h.get(t)}static B(t,i){this.l.h.set(t,i)}static G(){return this.l.t}static U(){return this.l.o}static W(t){if(null==t)return"";let i=(t+"").replace(/<`/g,"<").replace(/`>/g,">").replace(/\<\`/g,"<").replace(/\`\>/g,">").trim();const s=globalThis?.document;if(!s||"function"!=typeof s.createElement)return i=i.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"").replace(/<iframe\b[^>]*>[\s\S]*?<\/iframe>/gi,"").replace(/<(object|embed|link)\b[^>]*>[\s\S]*?<\/\1>/gi,""),i=i.replace(/\son[a-z]+\s*=\s*(['"]).*?\1/gi,""),i=i.replace(/\s([a-z-:]+)\s*=\s*(['"])\s*javascript:[^'"]*\2/gi,""),i;const e=s.createElement("div");return e.innerHTML=i,e.querySelectorAll("script, style, iframe, object, embed, link").forEach(t=>t.remove()),e.querySelectorAll("*").forEach(t=>{for(const i in t.attributes){const s=t.attributes[i],e=s.name??"",n=s.value??"";if(/^on/i.test(e))return void t.removeAttribute(e);/^(href|src|xlink:href)$/i.test(e)&&/^javascript:/i.test(n)&&t.removeAttribute(e)}}),(e.innerHTML??"").trim()}static q(t){const i=document.createElement("DIV");i.innerHTML=t;const s=i.textContent??i.innerText??"";return i.remove(),s.trim()}static J(t){return null==t?"":(t+"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/đ/g,"d").replace(/Đ/g,"d")}static K(t){const i=[];return Array.from(t.children).forEach(t=>{if("OPTGROUP"===t.tagName){const s=t;i.push(s),Array.from(s.children).forEach(t=>{t.__parentGroup=s,i.push(t)})}else"OPTION"===t.tagName&&i.push(t)}),i}static Y(){const t=navigator.userAgent;return/iP(hone|ad|od)/.test(t)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1}static X(t){const i=(t+"").trim();if(i.endsWith("px"))return i;if(i.endsWith("vh"))return window.innerHeight*parseFloat(i)/100+"px";if(i.endsWith("vw"))return window.innerWidth*parseFloat(i)/100+"px";const s=parseFloat(getComputedStyle(document.documentElement).fontSize);if(i.endsWith("rem"))return s*parseFloat(i)+"px";const e=this.T({node:"div",style:{height:i,opacity:"0"}});document.body.appendChild(e);const n=e.offsetHeight+"px";return e.remove(),n}}s.u=null,s.Z=new class{constructor(){this.tt=new Map,this.it=new Map}on(t,i,s={}){const e=s.st??50,n=s.once??!1;this.tt.has(t)||this.tt.set(t,[]),this.tt.get(t).push({et:i,timeout:e,once:n})}off(t){const i=this.it.get(t);if(i){for(const t of i.values())clearTimeout(t);i.clear(),this.it.delete(t)}this.tt.delete(t)}run(t,...i){const s=this.tt.get(t);if(!s)return;this.it.has(t)||this.it.set(t,new Map);const e=this.it.get(t);for(let t=0;t<s.length;t++){const n=s[t];if(!n)continue;const h=e.get(t);h&&clearTimeout(h);const o=setTimeout(()=>{if(n.et(i.length>0?i:null),n.once){s[t]=void 0;const i=e.get(t);i&&clearTimeout(i),e.delete(t)}},n.timeout);e.set(t,o)}}clear(t){if(void 0===t)for(const t of Array.from(this.tt.keys()))this.off(t);else this.off(t)}};class e{static nt(){const t={isContinue:!0,isCancel:!1};return{token:{get isContinue(){return t.isContinue},get isCancel(){return t.isCancel}},et:{stopPropagation(){t.isContinue=!1},cancel(){t.isCancel=!0,t.isContinue=!1}}}}static ht(t,...i){const{token:s,et:e}=this.nt();for(let n=0;n<i.length;n++){const h=i[n];if("function"==typeof h&&(t&&Array.isArray(t)?h(e,...t):h(e),s.isCancel||!s.isContinue))break}return s}static ot(t,i,s={bubbles:!0,cancelable:!0}){const e=new Event(i,s);return t.dispatchEvent(e),e}static rt(t,...i){if(Array.isArray(t))for(const s of t)"function"==typeof s&&s(...i)}}class n{static lt(t,i){const e=s.R(t);if(!e?.options)return;const n=e.options,h=n.minWidth,o=n.minHeight,r=Number.parseInt(n.width,10),l=Number.parseInt(n.height,10);let a=t.offsetWidth+"px",c=t.offsetHeight+"px";const u=getComputedStyle(t);"0px"===a&&"auto"!==u.width&&(a=u.width),"0px"===c&&"auto"!==u.height&&(c=u.height),r>0&&(a=n.width),l>0&&(c=n.height),Object.assign(i.style,{width:a,height:c,minWidth:h,minHeight:o})}}class h{constructor(t){this.node=null,this.ct=null,t&&this.init(t)}init(t){this.node=s.T({node:"div",classList:"selective-ui-placeholder",innerHTML:t.placeholder}),this.ct=t}get(){return this.ct?.placeholder??""}set(t,i=!0){if(!this.node||!this.ct)return;i&&(this.ct.placeholder=t);const e=s.W(t);this.node.innerHTML=this.ct.allowHtml?e:s.q(e)}}class o{constructor(){this.node=this.ut()}ut(){return s.T({node:"div",classList:"selective-ui-directive",role:"button",ariaLabel:"Toggle dropdown"})}dt(t){this.node.classList.toggle("drop-down",!!t)}}class r{constructor(t=null){this.gt=null,this.node=null,this.options=null,this.ft=[],this.bt=[],t&&this.init(t)}init(t){this.gt=s.$({wt:{tag:{node:"div",classList:["selective-ui-option-handle","hide"]},j:{yt:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textSelectAll,onclick:()=>{e.rt(this.ft)}}},vt:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textDeselectAll,onclick:()=>{e.rt(this.bt)}}}}}}),this.node=this.gt.view,this.options=t}available(){return!!this.options&&s.V(this.options.multiple)&&s.V(this.options.selectall)}refresh(){this.node&&(this.available()?this.show():this.hide())}show(){this.node&&this.node.classList.remove("hide")}hide(){this.node&&this.node.classList.add("hide")}xt(t=null){"function"==typeof t&&this.ft.push(t)}Tt(t=null){"function"==typeof t&&this.bt.push(t)}}class l{constructor(t=null){this.node=null,this.options=null,t&&this.init(t)}init(t){this.options=t,this.node=s.T({node:"div",classList:["selective-ui-empty-state","hide"],role:"status",ariaLive:"polite"})}show(t="nodata"){this.node&&this.options&&(this.node.textContent="notfound"===t?this.options.textNotFound:this.options.textNoData,this.node.classList.remove("hide"))}hide(){this.node&&this.node.classList.add("hide")}get isVisible(){return!!this.node&&!this.node.classList.contains("hide")}}class a{constructor(t=null){this.node=null,this.options=null,t&&this.init(t)}init(t){this.options=t,this.node=s.T({node:"div",classList:["selective-ui-loading-state","hide"],textContent:t.textLoading,role:"status",ariaLive:"polite"})}show(t){this.node&&this.options&&(this.node.textContent=this.options.textLoading,this.node.classList.toggle("small",!!t),this.node.classList.remove("hide"))}hide(){this.node&&this.node.classList.add("hide")}get isVisible(){return!!this.node&&!this.node.classList.contains("hide")}}class c{constructor(){this.Ot=!1,this.element=null,this.Ct=null,this.At=null,this.Ot=!0,this.St=this.Lt.bind(this)}Pt(t){}Lt(){const t=this.element;if(!t||"function"!=typeof t.getBoundingClientRect)return void this.Pt({width:0,height:0,top:0,left:0,padding:{top:0,right:0,bottom:0,left:0},border:{top:0,right:0,bottom:0,left:0},margin:{top:0,right:0,bottom:0,left:0}});const i=t.getBoundingClientRect(),s="undefined"!=typeof window&&"function"==typeof window.getComputedStyle?window.getComputedStyle(t):null;this.Pt({width:i?.width??0,height:i?.height??0,top:i?.top??0,left:i?.left??0,padding:{top:parseFloat(s?.paddingTop??"0"),right:parseFloat(s?.paddingRight??"0"),bottom:parseFloat(s?.paddingBottom??"0"),left:parseFloat(s?.paddingLeft??"0")},border:{top:parseFloat(s?.borderTopWidth??"0"),right:parseFloat(s?.borderRightWidth??"0"),bottom:parseFloat(s?.borderBottomWidth??"0"),left:parseFloat(s?.borderLeftWidth??"0")},margin:{top:parseFloat(s?.marginTop??"0"),right:parseFloat(s?.marginRight??"0"),bottom:parseFloat(s?.marginBottom??"0"),left:parseFloat(s?.marginLeft??"0")}})}ot(){this.Lt()}connect(t){if(!(t instanceof Element))throw Error("Invalid element");this.element=t,this.Ct=new ResizeObserver(this.St),this.Ct.observe(t),this.At=new MutationObserver(this.St),this.At.observe(t,{attributes:!0,attributeFilter:["style","class"]}),window.addEventListener("scroll",this.St,!0),window.addEventListener("resize",this.St),window.visualViewport&&(window.visualViewport.addEventListener("resize",this.St),window.visualViewport.addEventListener("scroll",this.St))}disconnect(){this.Ct?.disconnect(),this.At?.disconnect(),this.Pt=()=>{},window.removeEventListener("scroll",this.St,!0),window.removeEventListener("resize",this.St),window.visualViewport&&(window.visualViewport.removeEventListener("resize",this.St),window.visualViewport.removeEventListener("scroll",this.St)),this.Ct=null,this.At=null,this.element=null}}class u{constructor(t=null,i=null,s=null){this.options=null,this.Mt=!1,this.Ht=null,this.node=null,this.$t=null,this.jt=null,this.Et=null,this.Ft=null,this.It=null,this.Vt=null,this.kt=null,this.Rt=null,this._t=null,this.Dt=null,this.Nt=s,t&&i&&this.init(t,i)}init(t,i){if(!this.Nt)throw Error("Popup requires a ModelManager instance.");this.Ft=new r(i),this.It=new l(i),this.Vt=new a(i);const e=s.$({Bt:{tag:{node:"div",classList:"selective-ui-popup",style:{maxHeight:i.panelHeight}},j:{wt:{tag:this.Ft.node},zt:{tag:{id:i.Gt,node:"div",classList:"selective-ui-options-container",role:"listbox"}},Ut:{tag:this.Vt.node},Wt:{tag:this.It.node}}}},null);this.node=e.view,this.Rt=e.tags.zt,this.Et=s.R(t),this.options=i,this.Nt.load(this.Rt,{isMultiple:i.multiple});const n=this.Nt.qt();this.Ht=n.Jt,this.kt=n.kt,this.Ft.xt(()=>{n.Jt.Kt(!0)}),this.Ft.Tt(()=>{n.Jt.Kt(!1)}),this.Qt()}async Yt(){this.options&&this.Vt&&this.Ft&&this.Ht&&this.Nt&&(this.Dt&&clearTimeout(this.Dt),this.Nt.Xt(!0),!1!==s.V(this.options.loadingfield)&&(this.Vt.show(this.Ht.ti().Zt),this.Ft.hide(),this.ii()))}async si(){this.options&&this.Vt&&this.Ht&&this.Nt&&(this.Dt&&clearTimeout(this.Dt),this.Dt=setTimeout(()=>{this.Nt?.Xt(!1),this.Vt?.hide();const t=this.Ht?.ti();this.ei(t??void 0),this.ii()},200))}Qt(){this.Ht&&(this.Ht.ni(t=>{this.ei(t)}),this.Ht.hi("items",()=>{const t=this.Ht.ti();this.ei(t),this.ii()}))}ei(t){if(!(this.Ht&&this.It&&this.Ft&&this.Rt))return;const i=t??this.Ht.ti();i.isEmpty?(this.It.show("nodata"),this.Rt.classList.add("hide"),this.Ft.hide()):i.Zt?(this.It.hide(),this.Rt.classList.remove("hide"),this.Ft.refresh()):(this.It.show("notfound"),this.Rt.classList.add("hide"),this.Ft.hide())}oi(t,i){this.Ht?.ri(t,i)}li(t,i){this.Ht?.hi(t,i)}ai(t){this.$t=t}open(t=null){if(!(this.node&&this.options&&this.Ft&&this.Et&&this.$t))return;this.Mt||(document.body.appendChild(this.node),this.Mt=!0,this.jt=new c,this.$t.ci(this.node),this.node.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()})),this.Ft.refresh(),this.ei();const i=this.ui(),{position:s,top:e,maxHeight:n,di:h}=this.pi(i);this.$t.expand({duration:this.options.animationtime,display:"flex",width:i.width,left:i.left,top:e,maxHeight:n,di:h,position:s,gi:()=>{this.jt&&this.Et&&(this.jt.Pt=()=>{const t=this.ui();this.fi(t)},this.jt.connect(this.Et.container.tags.mi),t?.())}})}close(t=null){this.Mt&&this.options&&this.jt&&this.$t&&(this.jt.disconnect(),this.$t.collapse({duration:this.options.animationtime,gi:t??void 0}))}ii(){this.Mt&&this.jt?.ot()}bi(t,i){this.node&&(this._t=async()=>{const i=t.wi();if(!i.yi)return;const s=this.node;if(s.scrollHeight-s.scrollTop-s.clientHeight<100&&!i.xi&&i.Ti){const i=await t.Oi();!i.Ci&&i.message&&console.log("Load more:",i.message)}},this.node.addEventListener("scroll",this._t))}Ai(){this.Dt&&(clearTimeout(this.Dt),this.Dt=null),this.node&&this._t&&(this.node.removeEventListener("scroll",this._t),this._t=null);try{this.jt?.disconnect()}catch(t){}this.jt=null;try{this.$t?.ci?.(null)}catch(t){}if(this.$t=null,this.node)try{const t=this.node.cloneNode(!0);this.node.replaceWith(t),t.remove()}catch(t){this.node.remove()}this.node=null,this.Rt=null;try{this.Nt?.Xt?.(!1),this.kt?.clear?.(),this.kt=null,this.Ht=null,this.node.remove()}catch(t){}this.Nt=null,this.Ft=null,this.It=null,this.Vt=null,this.Et=null,this.options=null,this.Mt=!1}ui(){const t=this.Et.container.tags.mi,i=t.getBoundingClientRect(),e=window.getComputedStyle(t),n=window.visualViewport,h=s.Y();return{width:i.width,height:i.height,top:i.top-(n&&h?n.offsetTop:0),left:i.left-(n&&h?n.offsetLeft:0),padding:{top:parseFloat(e.paddingTop),right:parseFloat(e.paddingRight),bottom:parseFloat(e.paddingBottom),left:parseFloat(e.paddingLeft)},border:{top:parseFloat(e.borderTopWidth),right:parseFloat(e.borderRightWidth),bottom:parseFloat(e.borderBottomWidth),left:parseFloat(e.borderLeftWidth)}}}pi(t){const i=window.visualViewport,e=s.Y(),n=i?.height??window.innerHeight,h=i&&e?i.offsetTop:0,o=this.$t.Si("flex").scrollHeight,r=parseFloat(this.options?.panelHeight??"220")||220,l=parseFloat(this.options?.panelMinHeight??"100")||100,a=n-(t.top+t.height)-3,c=t.top-3;let u="bottom",d=r,p=Math.min(o,d);const g=a-15;return(p>=l?g>=l:g>=p)?(u="bottom",d=Math.min(a-15,r)):c>=Math.max(p,l)?(u="top",d=Math.min(c-15,r)):a>=c?(u="bottom",d=Math.max(a-15,l)):(u="top",d=Math.max(c-15,l)),p=Math.min(o,d),{position:u,top:"bottom"===u?t.top+t.height+3+h:t.top-p-3+h,maxHeight:d,di:p,Li:o}}fi(t){if(!this.options||!this.$t)return;const{position:i,top:s,maxHeight:e,di:n}=this.pi(t);this.$t.resize({duration:this.options.animationtime,width:t.width,left:t.left,top:s,maxHeight:e,di:n,position:i,animate:!0})}}class d{constructor(t=null){this.gt=null,this.node=null,this.Pi=null,this.Mi=null,this.options=null,this.Hi=null,this.$i=null,this.ji=null,this.options=t,t&&this.init(t)}init(t){this.gt=s.$({Ei:{tag:{node:"div",classList:["selective-ui-searchbox","hide"]},j:{Pi:{tag:{id:s.m(),node:"input",type:"search",classList:["selective-ui-searchbox-input"],placeholder:t.placeholder,role:"searchbox",S:t.Gt,M:"list"}}}}}),this.node=this.gt.view,this.Pi=this.gt.tags.Pi;let i=!1;const e=this.gt.tags.Pi;e.addEventListener("mousedown",t=>{t.stopPropagation()}),e.addEventListener("mouseup",t=>{t.stopPropagation()}),e.addEventListener("keydown",t=>{i=!1,"ArrowDown"===t.key||"Tab"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.Hi?.(1)):"ArrowUp"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.Hi?.(-1)):"Enter"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.$i?.()):"Escape"===t.key&&(t.preventDefault(),t.stopPropagation(),i=!0,this.ji?.())}),e.addEventListener("input",()=>{i||this.Mi?.(e.value,!0)})}show(){this.node&&this.Pi&&this.options&&(this.node.classList.remove("hide"),this.Pi.readOnly=!this.options.searchable,this.options.searchable&&requestAnimationFrame(()=>{this.Pi?.focus()}))}hide(){this.node&&this.node.classList.add("hide")}clear(t=!0){this.gt&&(this.gt.tags.Pi.value="",this.Mi?.("",t))}Fi(t){this.Pi&&(this.Pi.placeholder=s.q(t))}Ii(t){this.Pi&&this.Pi.setAttribute("aria-activedescendant",t)}}class p{constructor(t=null){this.Vi=null,this.ki=null,this.Ri=!1,t&&this.ci(t)}ci(t){if("string"==typeof t){const i=document.querySelector(t);return void(i instanceof HTMLElement&&(this.element=i))}this.element=t}cancel(){return this.Vi&&(clearTimeout(this.Vi),this.Vi=null),this.ki&&(clearTimeout(this.ki),this.ki=null),this.Ri=!1,this}Si(t="flex"){if(!this.element)return{width:0,height:0,scrollHeight:0};const i={display:this.element.style.display,visibility:this.element.style.visibility,position:this.element.style.position,height:this.element.style.height,width:this.element.style.width};Object.assign(this.element.style,{display:t,visibility:"hidden",position:"fixed",height:"fit-content",width:"fit-content"});const s=window.getComputedStyle(this.element),e=parseFloat(s.borderTopWidth),n=parseFloat(s.borderBottomWidth),h=this.element.scrollHeight+e+n,o=this.element.getBoundingClientRect(),r={width:o.width,height:o.height+e+n,scrollHeight:h};return Object.assign(this.element.style,i),r}expand(t){if(!this.element)return this;this.cancel(),this.Ri=!0;const{duration:i=200,display:s="flex",width:e,left:n,top:h,maxHeight:o,di:r,position:l="bottom",gi:a}=t;return Object.assign(this.element.style,{display:s,width:e+"px",left:n+"px",top:("bottom"===l?h:h+r)+"px",maxHeight:o+"px",height:"0px",opacity:"0",overflow:"hidden",transition:"none"}),this.element.classList.toggle("position-top","top"===l),this.element.classList.toggle("position-bottom","bottom"===l),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`top ${i}ms, height ${i}ms, opacity ${i}ms`,top:h+"px",height:r+"px",opacity:"1",overflow:r>=o?"auto":"hidden"}),this.Vi=setTimeout(()=>{this.element.style.transition="none",this.Ri=!1,a?.()},i)}),this}collapse(t){if(!this.element)return this;this.cancel(),this.Ri=!0;const{duration:i=200,gi:s}=t,e=this.element.offsetHeight,n=this.element.offsetTop,h=this.element.classList.contains("position-top")?"top":"bottom",o=this.element.scrollHeight-this.element.offsetHeight>0,r="top"===h?n+e:n;return requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`height ${i}ms, top ${i}ms, opacity ${i}ms`,height:"0px",top:r+"px",opacity:"0",overflow:o?"auto":"hidden"}),this.Vi=setTimeout(()=>{Object.assign(this.element.style,{display:"none",transition:"none"}),this.Ri=!1,s?.()},i)}),this}showSwipeWidth(t){if(!this.element)return this;this.cancel(),this.Ri=!0;const{duration:i=200,display:s="block",gi:e}=t;Object.assign(this.element.style,{transition:"none",display:s,width:"fit-content"});const n=this.Si(s).width;return Object.assign(this.element.style,{width:"0px"}),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`width ${i}ms`,width:n+"px",overflow:"hidden"})}),this.Vi=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:""}),this.Ri=!1,e?.()},i),this}hideSwipeWidth(t){if(!this.element)return this;this.cancel(),this.Ri=!0;const{duration:i=200,gi:s}=t,e=this.Si().width;return Object.assign(this.element.style,{transition:"none",width:e+"px"}),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`width ${i}ms`,width:"0px",overflow:"hidden"})}),this.Vi=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:"",display:""}),this.Ri=!1,s?.()},i),this}resize(t){if(!this.element)return this;this.ki&&clearTimeout(this.ki);const{duration:i=200,width:s,left:e,top:n,maxHeight:h,di:o,position:r="bottom",animate:l=!0,gi:a}=t,c=(this.element.classList.contains("position-top")?"top":"bottom")!==r,u=this.element.scrollHeight>h;return this.element.classList.toggle("position-top","top"===r),this.element.classList.toggle("position-bottom","bottom"===r),c&&(this.element.style.transition=`top ${i}ms ease-out, height ${i}ms ease-out, max-height ${i}ms ease-out;`),requestAnimationFrame(()=>{const t={width:s+"px",left:e+"px",top:n+"px",maxHeight:h+"px",height:o+"px",overflowY:u?"auto":"hidden"},r=Math.abs(this.element.offsetHeight-o);l&&(c||r>5)?t.transition=`height ${i}ms, top ${i}ms`:this.ki=setTimeout(()=>{this.element?.style&&(this.element.style.transition="none")},i),Object.assign(this.element.style,t),l&&(c||r>1)?this.ki=setTimeout(()=>{this.element.style.transition="none",c&&delete this.element.style.transition,a?.()},i):(c&&delete this.element.style.transition,a?.())}),this}get _i(){return this.Ri}}class g{get value(){return this.targetElement?.getAttribute("value")??null}constructor(t,i=null,s=null){this.targetElement=null,this.view=null,this.position=-1,this.Ot=!1,this.options=t,this.targetElement=i,this.view=s}update(t){this.targetElement=t,this.Di()}Di(){}}class f extends g{constructor(t,i){super(t,i??null,null),this.label="",this.items=[],this.collapsed=!1,this.Ni=[],i&&(this.label=i.label,this.collapsed=s.V(i.dataset?.collapsed))}get value(){return this.items.map(t=>t.value)}get Bi(){return this.items.filter(t=>t.selected)}get zi(){return this.items.filter(t=>t.visible)}get Gi(){return this.zi.length>0}update(t){this.label=t.label,this.view?.Ui(this.label)}Di(){this.view&&(this.view.Ui(this.label),this.view.Wi(this.collapsed))}qi(t){this.Ni.push(t)}Ji(){this.collapsed=!this.collapsed,this.view?.Wi(this.collapsed),e.ht([this,this.collapsed],...this.Ni)}Ki(t){this.items.push(t),t.group=this}removeItem(t){const i=this.items.indexOf(t);i>-1&&(this.items.splice(i,1),t.group=null)}Qi(){this.view?.Qi()}}class m extends g{constructor(){super(...arguments),this.Yi=[],this.Xi=[],this.Zi=[],this.ts=!0,this.ss=!1,this.group=null}get es(){return this.dataset?.imgsrc||this.dataset?.image||""}get hasImage(){return!!this.es}get value(){return this.targetElement?.value??""}get selected(){return!!this.targetElement?.selected}set selected(t){this.ns=t,e.ht([this,t],...this.Yi)}get visible(){return this.ts}set visible(t){if(this.ts===t)return;this.ts=t;const i=this.view?.hs?.();i&&i.classList.toggle("hide",!t),e.ht([this,t],...this.Zi)}get ns(){return this.selected}set ns(t){const i=this.view?.view?.tags?.rs,s=this.view?.hs?.();i&&(i.checked=t),s&&this.targetElement&&(s.classList.toggle("checked",!!t),s.setAttribute("aria-selected",t?"true":"false"),this.targetElement.toggleAttribute("selected",!!t)),this.targetElement&&(this.targetElement.selected=t),e.ht([this,t],...this.Xi)}get text(){const t=s.W(this.dataset?.mask??this.targetElement?.text??"");return this.options.allowHtml?t:s.q(t)}get textContent(){return this.options.allowHtml?s.q(this.text).trim():this.text.trim()}get dataset(){return this.targetElement?.dataset??{}}get ls(){return this.ss}set ls(t){const i=!!t,s=this.view?.hs?.();this.ss!==i&&(this.ss=i),s&&s.classList.toggle("highlight",i)}cs(t){this.Yi.push(t)}us(t){this.Xi.push(t)}ni(t){this.Zi.push(t)}Di(){if(!this.view)return;const t=this.view.view.tags.ds;t&&(this.options.allowHtml?t.innerHTML=this.text:t.textContent=this.textContent);const i=this.view.view.tags.ps;i&&this.hasImage&&(i.src=this.es,i.alt=this.text),this.targetElement&&(this.ns=this.targetElement.selected)}}class b{constructor(t){this.gs=[],this.fs=null,this.bs=null,this.ws=null,this.options=null,this.options=t}ys(t){this.vs=t}xs(t){this.Ts=t}Os(t){const i=this.Cs(t),s=i!==this.ws;return s&&(this.ws=i),s}Cs(t){return t.map(t=>{if("OPTGROUP"===t.tagName){const i=t,s=Array.from(i.children).map(t=>`${t.value}:${t.text}:${t.selected}`).join("\n");return`G:${i.label}:${s}`}return`O:${t.value}:${t.text}:${t.selected}`}).join("\n\n")}As(t){this.gs=[];let i=null;return t.forEach(t=>{if("OPTGROUP"===t.tagName)i=new f(this.options,t),this.gs.push(i);else if("OPTION"===t.tagName){const s=t,e=new m(this.options,s),n=s.__parentGroup;n&&i&&n===i.targetElement?(i.Ki(e),e.group=i):(this.gs.push(e),i=null)}}),this.gs}replace(t){this.ws=null,this.As(t),this.fs&&this.fs.Ss(this.gs),this.refresh()}notify(){this.fs&&this.refresh()}load(t,i={},s={}){this.fs=new this.vs(this.gs),Object.assign(this.fs,i),this.bs=new this.Ts(t),this.bs.Ls(this.fs),Object.assign(this.bs,s)}update(t){if(!this.Os(t))return;const i=this.gs,s=[],e=new Map,n=new Map;i.forEach(t=>{t instanceof f?e.set(t.label,t):t instanceof m&&n.set(`${t.value}::${t.textContent}`,t)});let h=null,o=0;t.forEach(t=>{if("OPTGROUP"===t.tagName){const i=t,n=e.get(i.label);n?(n.label!==i.label&&n.update(i),n.position=o,n.items=[],h=n,s.push(n),e.delete(i.label)):(h=new f(this.options,i),h.position=o,s.push(h)),o++}else if("OPTION"===t.tagName){const i=t,e=`${i.value}::${i.text}`,r=n.get(e);if(r)r.update(i),r.position=o,i.__parentGroup&&h?(h.Ki(r),r.group=h):(r.group=null,s.push(r)),n.delete(e);else{const t=new m(this.options,i);t.position=o,i.__parentGroup&&h?(h.Ki(t),t.group=h):s.push(t)}o++}}),e.forEach(t=>{t.view?.hs?.()?.remove?.()}),n.forEach(t=>{t.view?.hs?.()?.remove?.()}),this.gs=s,this.fs&&this.fs.Ps(this.gs),this.onUpdated(),this.refresh()}onUpdated(){}Xt(t){this.fs&&(this.fs.Ms=t)}refresh(){this.bs&&(this.bs.refresh(),this.onUpdated())}qt(){return{Hs:this.gs,Jt:this.fs,kt:this.bs}}$s(t){this.fs?.js(t)}Es(t){this.fs?.Fs(t)}}class w{constructor(t=null){this.Is=null,this.Jt=null,this.Is=t}Vs(t){this.Is=t}Ls(t){this.Jt=t,t.ri("items",()=>{this.clear()}),t.hi("items",()=>{this.ks()}),this.ks()}clear(){this.Is&&this.Is.replaceChildren()}ks(){this.Jt&&this.Is&&this.Jt.Rs(this.Is)}refresh(){this.ks()}}class y{constructor(t=null){this.gt=null,this.node=null,this.options=null,this._s=null,this.Ds=null,this.Ns=null,t&&this.init(t)}init(t){this.gt=s.$({Bs:{tag:{node:"div",classList:["selective-ui-accessorybox","hide"],onmouseup:t=>{t.stopPropagation()}}}}),this.node=this.gt.view,this.options=t}zs(t){this._s=t,this.Ds=t.parentElement,this.Gs()}Gs(){this.Ds&&this.node&&this._s&&this.options&&this.Ds.insertBefore(this.node,"top"===this.options.accessoryStyle?this._s:this._s.nextSibling)}Us(t){this.Ns=t}Ws(t){this.node&&this.options&&(this.node.replaceChildren(),t.length>0&&this.options.multiple?(this.node.classList.remove("hide"),t.forEach(t=>{s.$({qs:{tag:{node:"div",classList:["accessory-item"]},j:{Js:{tag:{node:"span",classList:["accessory-item-button"],role:"button",ariaLabel:`${this.options.textAccessoryDeselect}${t.textContent}`,title:`${this.options.textAccessoryDeselect}${t.textContent}`,onclick:i=>{i.preventDefault(),this.Ns?.$s?.("select"),setTimeout(()=>{t.selected=!1},10)}}},Ks:{tag:{node:"span",classList:["accessory-item-content"],innerHTML:t.text}}}}},this.node)})):this.node.classList.add("hide"),e.ot(window,"resize"))}}class v{constructor(t,i){this.Qs=null,this.Ys=null,this.Xs=null,this.Zs={currentPage:0,te:1,Ti:!1,xi:!1,ie:"",yi:!1},this.se=t,this.Nt=i}ee(){return!!this.Qs}async ne(t){if(!this.Qs)return{Ci:!1,items:[],message:"Ajax not configured"};const i=Array.isArray(t)?t:[t];if(0===i.length)return{Ci:!0,items:[]};try{const t=this.Qs;let s,e;if(s="function"==typeof t.he?t.he(i):{values:i.join(","),oe:"1",..."function"==typeof t.data?t.data("",0):t.data??{}},"POST"===(t.method??"GET")){const i=new URLSearchParams;Object.keys(s).forEach(t=>i.append(t,s[t]+"")),e=await fetch(t.url,{method:"POST",body:i,headers:{"Content-Type":"application/x-www-form-urlencoded"}})}else{const i=""+new URLSearchParams(s);e=await fetch(`${t.url}?${i}`)}if(!e.ok)throw Error("HTTP error! status: "+e.status);const n=await e.json();return{Ci:!0,items:this.re(n).items}}catch(t){return console.error("Load by values error:",t),{Ci:!1,message:t?.message,items:[]}}}le(t){const i=Array.from(this.se.options).map(t=>t.value);return{ae:t.filter(t=>i.includes(t)),ce:t.filter(t=>!i.includes(t))}}ue(t){this.Qs=t}setPopup(t){this.Xs=t}wi(){return{...this.Zs}}de(){this.Zs={currentPage:0,te:1,Ti:!1,xi:!1,ie:"",yi:this.Zs.yi}}clear(){this.Zs.ie="";const{Hs:t}=this.Nt.qt(),i=[];for(const s of t)s instanceof m?i.push(s):s instanceof f&&Array.isArray(s.items)&&i.push(...s.items);i.forEach(t=>{t.visible=!0})}async search(t,i=!1){return this.Qs?this.pe(t,i):this.ge(t)}async Oi(){return this.Qs?this.Zs.xi?{Ci:!1,message:"Already loading"}:this.Zs.yi?this.Zs.Ti?(this.Zs.currentPage++,this.pe(this.Zs.ie,!0)):{Ci:!1,message:"No more data"}:{Ci:!1,message:"Pagination not enabled"}:{Ci:!1,message:"Ajax not enabled"}}async ge(t){this.fe(t)&&(this.Zs.ie=t);const i=((t??"")+"").toLowerCase(),e=s.J(i),{Hs:n}=this.Nt.qt(),h=[];for(const t of n)t instanceof m?h.push(t):t instanceof f&&Array.isArray(t.items)&&h.push(...t.items);let o=!1;return h.forEach(t=>{const n=((t.textContent??t.text??"")+"").toLowerCase(),h=s.J(n),r=""===i||n.includes(i)||h.includes(e);t.visible=r,r&&(o=!0)}),{Ci:!0,me:o,isEmpty:0===h.length}}fe(t){return t!==this.Zs.ie}async pe(t,i=!1){const s=this.Qs;this.fe(t)&&(this.de(),this.Zs.ie=t,i=!1),this.Zs.xi=!0,this.Xs?.Yt(),this.Ys?.abort(),this.Ys=new AbortController;const e=this.Zs.currentPage,n=Array.from(this.se.selectedOptions).map(t=>t.value).join(",");let h;"function"==typeof s.data?(h=s.data(t,e),h&&void 0===h.be&&(h.be=n)):h={search:t,page:e,be:n,...s.data??{}};try{let t;if("POST"===(s.method??"GET")){const i=new URLSearchParams;Object.keys(h).forEach(t=>i.append(t,h[t]+"")),t=await fetch(s.url,{method:"POST",body:i,headers:{"Content-Type":"application/x-www-form-urlencoded"},signal:this.Ys.signal})}else{const i=""+new URLSearchParams(h);t=await fetch(`${s.url}?${i}`,{signal:this.Ys.signal})}const e=await t.json(),n=this.re(e);return n.we?(this.Zs.yi=!0,this.Zs.currentPage=n.page,this.Zs.te=n.te,this.Zs.Ti=n.Ti):this.Zs.yi=!1,this.ye(n.items,!!s.keepSelected,i),this.Zs.xi=!1,this.Xs?.si(),{Ci:!0,me:n.items.length>0,isEmpty:0===n.items.length,we:n.we,Ti:n.Ti,currentPage:n.page,te:n.te}}catch(t){return this.Zs.xi=!1,this.Xs?.si(),"AbortError"===t?.name?{Ci:!1,message:"Request aborted"}:(console.error("Ajax search error:",t),{Ci:!1,message:t?.message})}}re(t){let i=[],s=!1,e=0,n=1,h=!1;return t.object&&Array.isArray(t.object)?(i=t.object,void 0!==t.page&&(s=!0,e=parseInt(t.page??0,10),n=parseInt(t.te??t.ve??1,10),h=e<n-1)):t.data&&Array.isArray(t.data)?(i=t.data,void 0!==t.page&&(s=!0,e=parseInt(t.page??0,10),n=parseInt(t.te??t.ve??1,10),h=t.Ti??e<n-1)):Array.isArray(t)?i=t:t.items&&Array.isArray(t.items)&&(i=t.items,t.xe&&(s=!0,e=parseInt(t.xe.page??0,10),n=parseInt(t.xe.te??t.xe.ve??1,10),h=t.xe.Ti??e<n-1)),{items:i.map(t=>{if(t instanceof HTMLOptionElement||t instanceof HTMLOptGroupElement)return t;if("optgroup"===t.type||t.Te||t.group||t.label)return{type:"optgroup",label:t.label??t.name??t.title??"",data:t.data??{},options:(t.options??t.items??[]).map(t=>({value:t.value??t.id??t.key??"",text:t.text??t.label??t.name??t.title??"",selected:t.selected??!1,data:t.data??(t.imgsrc?{imgsrc:t.imgsrc}:{})}))};const i=t.data??{};return t?.imgsrc&&(i.imgsrc=t.imgsrc),{type:"option",value:t.value??t.id??t.key??"",text:t.text??t.label??t.name??t.title??"",selected:t.selected??!1,data:i}}),we:s,page:e,te:n,Ti:h}}ye(t,i,s=!1){const e=this.se;let n=[];i&&(n=Array.from(e.selectedOptions).map(t=>t.value)),s||(e.innerHTML=""),t.forEach(t=>{if("option"!==t.type&&t.type||""!==t.value||""!==t.text)if(t instanceof HTMLOptionElement||t instanceof HTMLOptGroupElement)e.appendChild(t);else if("optgroup"===t.type){const s=document.createElement("optgroup");s.label=t.label,t.data&&Object.keys(t.data).forEach(i=>{s.dataset[i]=t.data[i]+""}),Array.isArray(t.options)&&t.options.forEach(t=>{const e=document.createElement("option");e.value=t.value,e.text=t.text,t.data&&Object.keys(t.data).forEach(i=>{e.dataset[i]=t.data[i]+""}),(t.selected||i&&n.includes(e.value))&&(e.selected=!0),s.appendChild(e)}),e.appendChild(s)}else{const s=document.createElement("option");s.value=t.value,s.text=t.text,t.data&&Object.keys(t.data).forEach(i=>{s.dataset[i]=t.data[i]+""}),(t.selected||i&&n.includes(s.value))&&(s.selected=!0),e.appendChild(s)}}),e.dispatchEvent(new CustomEvent("options:changed"))}}class x{constructor(t){this.Oe=null,this.Ce=null,this.Ae=50,this.se=t,this.Ce=this.Se(),this.Le=new MutationObserver(()=>{this.Oe&&clearTimeout(this.Oe),this.Oe=setTimeout(()=>{this.Pe()},this.Ae)}),t.addEventListener("options:changed",()=>{this.Oe&&clearTimeout(this.Oe),this.Oe=setTimeout(()=>{this.Pe()},this.Ae)})}Se(){const t=Array.from(this.se.options);return{length:t.length,values:t.map(t=>t.value).join(","),Me:t.map(t=>t.text).join(","),selected:t.map(t=>t.selected+"").join(",")}}He(){const t=this.Se(),i=JSON.stringify(t)!==JSON.stringify(this.Ce);return i&&(this.Ce=t),i}Pe(){this.He()&&this.Pt(this.se)}connect(){this.Le.observe(this.se,{childList:!0,subtree:!1,attributes:!0,attributeFilter:["selected","value","disabled"]})}Pt(t){}disconnect(){this.Oe&&clearTimeout(this.Oe),this.Oe=null,this.Le.disconnect()}}class T{constructor(t){this.Oe=null,this.$e=t,this.Le=new MutationObserver(t=>{let i=!1;for(const s of t)if("attributes"===s.type&&s.attributeName?.startsWith("data-")){i=!0;break}i&&(this.Oe&&clearTimeout(this.Oe),this.Oe=setTimeout(()=>{this.Pt({...this.$e.dataset})},50))}),t.addEventListener("dataset:changed",()=>{this.Pt({...this.$e.dataset})})}connect(){this.Le.observe(this.$e,{attributes:!0,attributeOldValue:!0})}Pt(t){}disconnect(){this.Oe&&clearTimeout(this.Oe),this.Oe=null,this.Le.disconnect()}}class O{constructor(t=[]){this.items=[],this.je=s.m(12),this.Ms=!1,this.items=t,this.Ee()}Ee(){}Fe(t,i,s){const e=i;t.Ot?e?.update?.():e?.ks?.()}ri(t,i){s.Z.on(`${t}ing_${this.je}`,i,{st:1})}hi(t,i){s.Z.on(`${t}_${this.je}`,i)}Fs(t,...i){s.Z.run(`${t}_${this.je}`,...i)}js(t,...i){s.Z.run(`${t}ing_${this.je}`,...i)}Ie(t,i){return null}Ve(){return this.items.length}ke(t){this.js("items",t),this.items=t,this.Fs("items",t)}Ss(t){this.ke(t)}Rs(t){for(let i=0;i<this.Ve();i++){const s=this.items[i];let e=s.view;s.Ot||(e=this.Ie(t,s),s.view=e),this.Fe(s,e,i),s.Ot=!0}}Ps(t){}}class C{constructor(t){this.parent=null,this.view=null,this.parent=t}ks(){}update(){}hs(){if(!this.view?.view)throw Error("View is not mounted. Did you forget to set this.view?");return this.view.view}}class A extends C{constructor(){super(...arguments),this.view=null}ks(){const t=s.m(7);this.view=s.H({Re:{tag:{node:"div",classList:["selective-ui-group"],role:"group",A:`seui-${t}-header`,id:`seui-${t}-group`},j:{_e:{tag:{node:"div",classList:["selective-ui-group-header"],role:"presentation",id:`seui-${t}-header`}},De:{tag:{node:"div",classList:["selective-ui-group-items"],role:"group"}}}}}),this.parent.appendChild(this.view.view)}update(){this.Ui()}Ui(t=null){this.view&&null!==t&&(this.view.tags._e.textContent=t)}Ne(){if(!this.view)throw Error("GroupView is not rendered.");return this.view.tags.De}Qi(){if(!this.view)return;const t=Array.from(this.view.tags.De.children).filter(t=>!t.classList.contains("hide"));this.view.view.classList.toggle("hide",!(t.length>0))}Wi(t){this.view&&(this.view.view.classList.toggle("collapsed",t),this.view.tags._e.setAttribute("aria-expanded",t?"false":"true"))}}class S extends C{constructor(t){super(t),this.view=null,this.Be=null,this.ze=null,this.Ge=!1,this.Ue()}Ue(){const t=this;this.Be={isMultiple:!1,hasImage:!1,imagePosition:"right",imageWidth:"60px",imageHeight:"60px",imageBorderRadius:"4px",labelValign:"center",labelHalign:"left"},this.ze=new Proxy(this.Be,{set(i,s,e){if("string"!=typeof s)return!0;const n=s,h=i[n];return h!==e&&(i[n]=e,t.Ge&&t.We(n,e,h)),!0}})}get isMultiple(){return this.Be.isMultiple}set isMultiple(t){this.ze.isMultiple=!!t}get hasImage(){return this.Be.hasImage}set hasImage(t){this.ze.hasImage=!!t}get qe(){return this.ze}set qe(t){if(!t||!this.ze||!this.Be)return;const i={};void 0!==t.imageWidth&&t.imageWidth!==this.Be.imageWidth&&(i.imageWidth=t.imageWidth),void 0!==t.imageHeight&&t.imageHeight!==this.Be.imageHeight&&(i.imageHeight=t.imageHeight),void 0!==t.imageBorderRadius&&t.imageBorderRadius!==this.Be.imageBorderRadius&&(i.imageBorderRadius=t.imageBorderRadius),void 0!==t.imagePosition&&t.imagePosition!==this.Be.imagePosition&&(i.imagePosition=t.imagePosition),void 0!==t.labelValign&&t.labelValign!==this.Be.labelValign&&(i.labelValign=t.labelValign),void 0!==t.labelHalign&&t.labelHalign!==this.Be.labelHalign&&(i.labelHalign=t.labelHalign),Object.keys(i).length>0&&Object.assign(this.ze,i)}ks(){const t=["selective-ui-option-view"],i=s.m(7),e="option_"+i;this.Be.isMultiple&&t.push("multiple"),this.Be.hasImage&&(t.push("has-image"),t.push("image-"+this.Be.imagePosition));const n={rs:{tag:{node:"input",type:this.Be.isMultiple?"checkbox":"radio",classList:"allow-choice",id:e}},...this.Be.hasImage&&{ps:{tag:{node:"img",classList:"option-image",style:{width:this.Be.imageWidth,height:this.Be.imageHeight,borderRadius:this.Be.imageBorderRadius}}}},Je:{tag:{node:"label",htmlFor:e,classList:["align-vertical-"+this.Be.labelValign,"align-horizontal-"+this.Be.labelHalign]},j:{ds:{tag:{node:"div"}}}}};this.view=s.H({Ke:{tag:{node:"div",id:`seui-${i}-option`,classList:t,role:"option",ariaSelected:"false",tabIndex:"-1"},j:n}}),this.parent.appendChild(this.view.view),this.Ge=!0}We(t,i,s){const e=this.view;if(!e||!e.view)return;const n=e.view,h=e.tags?.rs,o=e.tags?.Je;switch(t){case"isMultiple":{const t=!!i;n.classList.toggle("multiple",t),h&&h.type!==(t?"checkbox":"radio")&&(h.type=t?"checkbox":"radio");break}case"hasImage":{const t=!!i;if(n.classList.toggle("has-image",t),t)n.classList.add("image-"+this.Be.imagePosition),this.Qe();else{n.className=n.className.replace(/image-(top|right|bottom|left)/g,"").trim();const t=e.tags?.ps;t&&(t.remove(),e.tags.ps=null)}break}case"imagePosition":this.Be.hasImage&&(n.className=n.className.replace(/image-(top|right|bottom|left)/g,"").trim(),n.classList.add("image-"+i));break;case"imageWidth":case"imageHeight":case"imageBorderRadius":{const s=e.tags?.ps;if(s){const e="imageWidth"===t?"width":"imageHeight"===t?"height":"borderRadius",n=i+"";s.style[e]!==n&&(s.style[e]=n)}break}case"labelValign":case"labelHalign":if(o){const t=`align-vertical-${this.Be.labelValign} align-horizontal-${this.Be.labelHalign}`;o.className!==t&&(o.className=t)}}}Qe(){const t=this.view;if(!t||!t.view)return;const i=t.tags?.ps;if(i)return;const s=t.view,e=t.tags?.Je,n=document.createElement("img");n.className="option-image",n.style.width=this.Be.imageWidth,n.style.height=this.Be.imageHeight,n.style.borderRadius=this.Be.imageBorderRadius,e&&e.parentElement?s.insertBefore(n,e):s.appendChild(n),t.tags.ps=n}}class L extends O{constructor(t=[]){super(t),this.isMultiple=!1,this.Ye=[],this.Xe=-1,this.Ze=null,this.groups=[],this.tn=[],this.sn()}sn(){this.tn=[],this.groups=[],this.items.forEach(t=>{t instanceof f?(this.groups.push(t),this.tn.push(...t.items)):t instanceof m&&this.tn.push(t)})}Ie(t,i){return i instanceof f?new A(t):new S(t)}Fe(t,i,s){t.position=s,t instanceof f?this.en(t,i,s):t instanceof m&&this.nn(t,i,s),t.Ot=!0}en(t,i,s){super.Fe(t,i,s),t.view=i;const e=i.view.tags._e;e.textContent=t.label,t.Ot||(e.style.cursor="pointer",e.addEventListener("click",()=>{t.Ji()}),t.qi((t,i,s)=>{i.items.forEach(t=>{const i=t.view?.hs?.();i&&(i.style.display=s?"none":"")}),this.hn(i,s)}));const n=i.Ne();t.items.forEach((t,i)=>{let s=t.view;t.Ot&&s||(s=new S(n)),this.nn(t,s,i),t.Ot=!0}),i.Wi(t.collapsed),i.Qi()}nn(t,i,s){if(i.isMultiple=this.isMultiple,i.hasImage=t.hasImage,i.qe={imageWidth:t.options.imageWidth,imageHeight:t.options.imageHeight,imageBorderRadius:t.options.imageBorderRadius,imagePosition:t.options.imagePosition,labelValign:t.options.labelValign,labelHalign:t.options.labelHalign},t.Ot||super.Fe(t,i,s),t.view=i,t.hasImage){const s=i.view.tags.ps;s&&(s.src!==t.es&&(s.src=t.es),s.alt!==t.text&&(s.alt=t.text))}i.view.tags.ds.innerHTML=t.text,t.Ot||(i.view.tags.Ke.addEventListener("click",i=>{i.stopPropagation(),i.preventDefault(),this.Ms||(this.isMultiple?(this.js("select"),setTimeout(()=>{t.selected=!t.selected},5)):!0!==t.selected&&(this.js("select"),setTimeout(()=>{this.Ze&&(this.Ze.selected=!1),t.selected=!0},5)))}),i.view.tags.Ke.title=t.textContent,i.view.tags.Ke.addEventListener("mouseenter",()=>{this.Ms||this.rn(this.tn.indexOf(t),!1)}),t.cs(()=>{this.Fs("selected")}),t.us((i,s,e)=>{e&&(this.Ze=t),this.Fs("selected_internal")}),t.ni((t,i)=>{i.group?.Qi(),this.ln()})),t.selected&&(this.Ze=t,t.ns=!0)}ke(t){this.js("items",t),this.items=t,this.sn(),this.Fs("items",t)}Ss(t){this.ke(t)}Ps(t){this.items=t,this.sn()}an(){return this.tn.filter(t=>t.selected)}cn(){return this.tn.find(t=>t.selected)}Kt(t){this.isMultiple&&this.tn.forEach(i=>{i.selected=t})}ni(t){this.Ye.push(t)}ln(){const t=this.tn.filter(t=>t.visible).length,i=this.tn.length;this.Ye.forEach(s=>{s({un:t,dn:i,Zt:t>0,isEmpty:0===i})})}ti(){const t=this.tn.filter(t=>t.visible).length,i=this.tn.length;return{un:t,dn:i,Zt:t>0,isEmpty:0===i}}pn(){this.rn(0)}navigate(t,i=!0){const s=this.tn.filter(t=>t.visible);if(0===s.length)return;let e=s.findIndex(t=>t===this.tn[this.Xe]);-1===e&&(e=-1);let n=e+t;n>=s.length&&(n=0),n<0&&(n=s.length-1);const h=this.tn.indexOf(s[n]);this.rn(h,i)}gn(){if(this.Xe>-1&&this.tn[this.Xe]){const t=this.tn[this.Xe];if(t.visible){const i=t.view?.hs?.();i&&i.click()}}}rn(t,i=!0){let s=0;if("number"==typeof t)s=t;else if(t instanceof m){const i=this.tn.indexOf(t);s=i>-1?i:0}else s=0;this.Xe>-1&&this.tn[this.Xe]&&(this.tn[this.Xe].ls=!1);for(let t=s;t<this.tn.length;t++){const s=this.tn[t];if(s.visible){if(s.ls=!0,this.Xe=t,i){const t=s.view?.hs?.();t&&t.scrollIntoView({fn:"center",behavior:"smooth"})}return void this.mn(t,s.view?.hs?.()?.id)}}}mn(t,i){}hn(t,i){}}class P{constructor(t=null,i=null){this.container={},this.oldValue=null,this.node=null,this.options=null,this.bn=null,this.isOpen=!1,this.wn=!1,this.yn=!1,this.vn=null,t&&this.init(t,i)}get isDisabled(){return!!this.options?.disabled}set isDisabled(t){this.options&&this.node&&(this.options.disabled=t,this.node.classList.toggle("disabled",t),this.node.setAttribute("aria-disabled",t+""),this.container.tags?.mi?.setAttribute("aria-disabled",t+""))}get xn(){return!!this.options?.readonly}set xn(t){this.options&&this.node&&(this.options.readonly=t,this.node.classList.toggle("readonly",t))}get isVisible(){return!!this.options?.visible}set isVisible(t){this.options&&this.node&&(this.options.visible=t,this.node.classList.toggle("invisible",!t))}init(i,e){const r=s.R(i).options,l=new h(r),a=new o,c=new d(r),effector=t(),p=new b(r),g=new y(r),f=new v(i,p),m=new x(i),O=new T(i);this.vn=e,this.options=r,l.node&&(l.node.id=(r.Tn??"")+"");const C=s.$({On:{tag:{node:"div",classList:"selective-ui-MAIN"},j:{mi:{tag:{node:"div",classList:"selective-ui-view",tabIndex:0,onkeydown:t=>{"Enter"!==t.key&&" "!==t.key&&"ArrowDown"!==t.key||(t.preventDefault(),this.Cn()?.open())}},j:{An:{tag:l.node},Sn:{tag:a.node},Ei:{tag:c.node}}}}}},null);this.container=C,this.node=C.view,i.parentNode?.insertBefore(this.node,i),this.node.insertBefore(i,C.tags.mi),g.zs(C.tags.mi),g.Us(p),C.tags.mi.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()}),n.lt(i,C.tags.mi),i.classList.add("init"),p.ys(L),p.xs(w),p.As(s.K(i)),p.onUpdated=()=>{C.Ln?.ii?.()},this.bn=p,C.Pn=f,C.placeholder=l,C.Mn=a,C.Hn=c,C.effector=effector,C.targetElement=i,C.$n=g,C.jn=m,C.En=O,C.Ln=new u(i,r,p),C.Ln.ai(effector),C.Ln.bi(f,r),C.Ln.li("selected",()=>{this.Cn()?.change(null,!0)}),C.Ln.li("selected_internal",()=>{this.Cn()?.change(null,!1)}),C.Ln.oi("select",()=>{this.oldValue=this.Cn()?.value??""}),this.Cn()?.change(null,!1),m.connect(),m.Pt=t=>{p.update(s.K(t)),this.Cn()?.refreshMask()},O.connect(),O.Pt=t=>{s.V(t.disabled)!==this.isDisabled&&(this.isDisabled=s.V(t.disabled)),s.V(t.readonly)!==this.xn&&(this.xn=s.V(t.readonly)),s.V(t.visible)!==this.isVisible&&(this.isVisible=s.V(t.visible??"1"))},i.addEventListener("options:changed",()=>{p.update(s.K(i)),this.Cn()?.refreshMask(),C.Ln?.ii?.()}),r.ajax&&f.ue(r.ajax);const A=C.Ln.Ht,S=(t,i)=>{i||""!==t?(""!==t&&(this.yn=!0),f.search(t).then(t=>{C.Ln?.ii?.(),t?.me&&setTimeout(()=>{A.pn()},r.animationtime??0)}).catch(t=>{console.error("Search error:",t)})):f.clear()};let P=null;c.Mi=(t,i)=>{f.fe(t)&&(f.ee()?(P&&clearTimeout(P),C.Ln?.Yt?.(),P=setTimeout(()=>{S(t,i)},r.delaysearchtime??0)):S(t,i))},f.setPopup(C.Ln),c.Hi=t=>{A.navigate(t)},c.$i=()=>{A.gn()},c.ji=()=>{this.Cn()?.close(),C.tags.mi.focus()},A.mn=(t,i)=>{i&&c.Ii(i)},A.hn=()=>{C.Ln?.ii?.()},this.isDisabled=s.V(r.disabled),this.xn=s.V(r.readonly)}Fn(){const t=this.container??{},{jn:i,En:s}=t;i?.disconnect&&i.disconnect(),s?.disconnect&&s.disconnect()}Cn(){const t=this.container,i=this,n=s.R(t.targetElement);if(!n)return null;const h=n.options,o={get placeholder(){return t.placeholder.get()},set placeholder(i){t.placeholder?.set(i),t.Hn?.Fi(i)},get oldValue(){return i.oldValue},set value(t){this.setValue(null,t,!0)},get value(){const t=this.valueArray,i=t.length;return i>1?t:0===i?"":t[0]},get valueArray(){const t=[];return i.In().forEach(i=>{i.selected&&t.push(i.value)}),t},get valueString(){return this.valueArray.join(h.customDelimiter)},get valueOptions(){const t=[];return i.In().forEach(i=>{i.selected&&t.push(i)}),t},get mask(){const t=[];return i.In().forEach(i=>{i.selected&&t.push(i.text)}),t},get valueText(){const t=[];i.In().forEach(i=>{i.selected&&t.push(i.text)});const s=t.length;return s>1?t:0===s?"":t[0]},get isOpen(){return i.isOpen},selectAll(t,s=!0){if(!(h.multiple&&h.maxSelected>0&&i.In().length>h.maxSelected)&&!this.disabled&&!this.readonly&&h.multiple){if(s){if(e.ht([this],...h.on.beforeChange).isCancel)return;i.oldValue=this.value}i.In().forEach(t=>{t.ns=!0}),this.change(!1,s)}},deSelectAll(t,s=!0){if(!this.disabled&&!this.readonly&&h.multiple){if(s){if(e.ht([this],...h.on.beforeChange).isCancel)return;i.oldValue=this.value}i.In().forEach(t=>{t.ns=!1}),this.change(!1,s)}},setValue(s=null,n,o=!0,r=!1){if(Array.isArray(n)||(n=[n]),0===(n=n.filter(t=>""!==t&&null!=t)).length)return i.In().forEach(t=>t.ns=!1),void this.change(!1,o);if(h.multiple&&h.maxSelected>0&&n.length>h.maxSelected)console.warn(`Cannot select more than ${h.maxSelected} items`);else if(r||!this.disabled&&!this.readonly){if(t.Pn?.ee?.()){const{ce:s}=t.Pn.le(n);if(s.length>0)return void(async()=>{h.loadingfield&&t.Ln?.Yt?.();try{const e=await t.Pn.ne(s);e.Ci&&e.items.length>0?(e.items.forEach(t=>{s.includes(t.value)&&(t.selected=!0)}),t.Pn.ye?.(e.items,!0,!0),setTimeout(()=>{i.In().forEach(t=>{t.ns=n.some(i=>i==t.value)}),this.change(!1,!1)},100)):s.length>0&&console.warn(`Could not load ${s.length} values:`,s)}catch(t){console.error("Error loading missing values:",t)}finally{h.loadingfield&&t.Ln?.si?.()}})()}if(o){if(e.ht([this],...h.on.beforeChange).isCancel)return;i.oldValue=this.value}i.In().forEach(t=>{t.ns=n.some(i=>i==t.value)}),!h.multiple&&n.length>0&&(t.targetElement.value=n[0]),this.change(!1,o)}},open(){if(i.isOpen)return!1;const s=i.vn?.find?.();if(s&&!s.isEmpty&&s.close().isCancel)return!1;if(this.disabled)return!1;if(e.ht([this],...h.on.beforeShow).isCancel)return!1;i.isOpen=!0,t.Mn.dt(!0);const n=t.Ln.Ht,o=n.cn();o?n.rn(o,!1):n.pn(),i.wn&&!i.yn||!h?.ajax||(t.Ln.Yt(),i.wn=!0,i.yn=!1,setTimeout(()=>{t.Ln&&t.Pn&&t.Pn.search("").then(()=>t.Ln?.ii?.()).catch(t=>console.error("Initial ajax load error:",t))},h.animationtime)),t.Ln.open(),t.Hn.show();const r=t.tags.mi;return r.setAttribute("aria-expanded","true"),r.setAttribute("aria-controls",h.Gt),r.setAttribute("aria-haspopup","listbox"),r.setAttribute("aria-labelledby",h.Tn),h.multiple&&r.setAttribute("aria-multiselectable","true"),e.ht([this],...h.on.show),!0},close(){return!!i.isOpen&&!e.ht([this],...h.on.beforeClose).isCancel&&(i.isOpen=!1,t.Mn.dt(!1),t.Ln.close(()=>{t.Hn.clear(!1)}),t.Hn.hide(),t.tags.mi.setAttribute("aria-expanded","false"),e.ht([this],...h.on.close),!0)},toggle(){i.isOpen?this.close():this.open()},change(s=null,n=!0){if(n){if(h.multiple&&h.maxSelected>0&&this.valueArray.length>h.maxSelected&&this.setValue(null,this.oldValue,!1,!0),this.disabled||this.readonly)return void this.setValue(null,this.oldValue,!1,!0);if(e.ht([this,this.value],...h.on.beforeChange).isCancel)return void this.setValue(null,this.oldValue,!1)}this.refreshMask(),t.$n.Ws(this.valueOptions),n&&(t.targetElement&&e.ot(t.targetElement,"change"),e.ht([this,this.value],...h.on.change),i.options?.autoclose&&this.close())},refreshMask(){let s=h.placeholder;!h.multiple&&i.In().length>0&&(s=this.mask[0]),s??(s=h.placeholder),t.placeholder.set(s,!1),t.Hn.Fi(s)},on(t,i,s){h.on[i]||(h.on[i]=[]),h.on[i].push(s)},ajax(i,s){t.Pn.ue(s)}};return this.Vn(o,"disabled","isDisabled"),this.Vn(o,"readonly","isReadOnly"),this.Vn(o,"visible","isVisible"),o}Vn(t,i,s){const e=this;Object.defineProperty(t,i,{get:()=>e[s],set(t){e[s]=!!t,e.container?.targetElement?.dataset&&(e.container.targetElement.dataset[i]=!!t+"")},enumerable:!0,configurable:!0})}In(t=null){if(!this.bn)return[];const{Hs:i}=this.bn.qt(),s=[];for(const t of i)t instanceof m?s.push(t):t instanceof f&&Array.isArray(t.items)&&t.items.length&&s.push(...t.items);return"boolean"==typeof t?s.filter(i=>i.selected===t):s}Ai(){this.container.Ln.Ai()}}class M{constructor(){this.kn=!1,this.Le=null,this.Rn=[]}_n(t){this.Rn.push(t)}Dn(){this.Rn=[]}start(t){if(this.kn)return;this.kn=!0;const i=t.toUpperCase(),s=t.toLowerCase();this.Le=new MutationObserver(t=>{for(const e of t)e.addedNodes.forEach(t=>{if(1!==t.nodeType)return;const e=t;e.tagName===i&&this.Nn(e),e.querySelectorAll(s).forEach(t=>this.Nn(t))})}),this.Le.observe(document.body,{childList:!0,subtree:!0})}stop(){this.kn&&(this.kn=!1,this.Le?.disconnect(),this.Le=null)}Nn(t){this.Rn.forEach(i=>i(t))}}class H{constructor(){this.Bn=new Map}bind(t,i){const n=s.I(s.G(),i);n.on=n.on??{},n.on.load=n.on.load??[],this.Bn.set(t,n);const h=s.m();s.Z.on(h,()=>{e.ht([this.find(t)],...n.on.load),s.Z.clear(h),n.on.load=[]}),s.v(t).forEach(t=>{(async()=>{"SELECT"===t.tagName&&(s.D(t),this.zn(t,n)&&s.Z.run(h))})()}),s.U().includes(t)||s.U().push(t)}find(t="*"){const i={isEmpty:!0};if("*"===t&&""===(t=s.U().join(", ")))return i;const e=s.v(t);if(0===e.length)return i;const n=s.R(e[0]);if(!n||!n.action)return i;const h={};for(const t in n.action)h[t]=this.Gn(t,n.action);const o={isEmpty:!1};for(const t in h){const i=h[t];switch(i.type){case"get-set":this.Un(o,i.name,e);break;case"func":this.Wn(o,i.name,e)}}return o}qn(){this.Jn=new M,this.Jn._n(t=>{this.Bn.forEach((i,s)=>{try{t.matches(s)&&this.zn(t,i)}catch(t){console.warn("Invalid selector: "+s,t)}})}),this.Jn.start("select")}destroy(t=null){null===t?this.Kn():"string"==typeof t?this.Qn(t):t instanceof HTMLSelectElement&&this.Yn(t)}Kn(){s.U().forEach(t=>this.Qn(t)),this.Bn.clear(),s.U().length=0,this.Jn?.stop()}Qn(t){s.v(t).forEach(t=>{"SELECT"===t.tagName&&this.Yn(t)}),this.Bn.delete(t);const i=s.U(),e=i.indexOf(t);e>-1&&i.splice(e,1)}Yn(t){const i=s.R(t);if(!i)return;const e=i.container?.Ln;e?.Ai(),s.B(t,i);const n=!!this.Jn;n&&this.Jn?.stop();try{i.self?.Fn?.()}catch(t){}const h=i.container?.element??t.parentElement;t.style.display="",t.style.visibility="",t.disabled=!1,delete t.dataset.Xn,h&&h.parentNode?h.parentNode.replaceChild(t,h):document.body.appendChild(t),s.k(t),n&&this.Bn.size>0&&this.Jn?.start("select")}rebind(t,i){this.Qn(t),this.bind(t,i)}zn(t,i){if(s.R(t)||s.N(t))return!1;const e=s.m(8),n=s.F(t,i);n.Zn=e,n.Gt=`seui-${e}-optionlist`,n.Tn=`seui-${e}-placeholder`;const h={options:n};s._(t,h);const o=new P(t,this);return h.container=o.container,h.action=o.Cn(),h.self=o,o.container.view.addEventListener("mouseup",()=>{h.action?.toggle?.()}),!0}Gn(t,i){const s=Object.getOwnPropertyDescriptor(i,t);let e="variable";return s?.get||s?.set&&"function"!=typeof i[t]?e="get-set":"function"==typeof i[t]&&(e="func"),{type:e,name:t}}Un(t,i,e){Object.defineProperty(t,i,{get(){const t=s.R(e[0]);return t.action?.[i]},set(t){e.forEach(e=>{const n=s.R(e);n?.action&&(n.action[i]=t)})},enumerable:!0,configurable:!0})}Wn(t,i,n){t[i]=(...h)=>{for(let t=0;t<n.length;t++){const o=s.R(n[t]);if(!o?.action)continue;const r=e.nt();if(o.action[i](r.et,...h),!r.token.isContinue)break}return t}}}const $="1.1.3",j="SelectiveUI";if(void 0===globalThis.GLOBAL_SEUI){const F=new H;globalThis.GLOBAL_SEUI={version:$,name:j,bind:F.bind.bind(F),find:F.find.bind(F),destroy:F.destroy.bind(F),effector:t.bind(t),rebind:F.rebind.bind(F)};let I=!1;function V(){I||(I=!0,document.addEventListener("mousedown",()=>{const t=s.U();if(t.length>0){const i=F.find(t.join(", "));i.isEmpty||i.close()}}),F.qn())}"undefined"!=typeof document&&("loading"===document.readyState?document.addEventListener("DOMContentLoaded",V):V()),console.log(`[${j}] v${$} loaded successfully`)}else console.warn(`[${globalThis.GLOBAL_SEUI.name}] Already loaded (v${globalThis.GLOBAL_SEUI.version}). Using existing instance. Please remove duplicate <script> tags.`);const version=globalThis.GLOBAL_SEUI.version,E=globalThis.GLOBAL_SEUI.name;export{bind,destroy,effector,find,E as name,rebind,version};
1
+ /*! Selective UI v1.1.4 | MIT License */
2
+ function t(t){return new p(t??null)}function bind(t,i={}){globalThis.GLOBAL_SEUI.bind(t,i)}function find(t){return globalThis.GLOBAL_SEUI.find(t)}function destroy(t=null){globalThis.GLOBAL_SEUI.destroy(t)}function rebind(t,i={}){globalThis.GLOBAL_SEUI.rebind(t,i)}function effector(t){return globalThis.GLOBAL_SEUI.effector(t)}class i{constructor(){this.t={showPanel:!0,accessoryStyle:"top",multiple:!1,minWidth:"50px",width:"0px",offsetWidth:null,minHeight:"30px",height:"30px",panelHeight:"220px",panelMinHeight:"100px",disabled:!1,readonly:!1,selectall:!0,keepSelected:!0,placeholder:"Select value",altMask:"",autoclose:!1,autoscroll:!0,autofocus:!0,searchable:!0,loadingfield:!0,visible:!0,skipError:!1,customDelimiter:",",textLoading:"Processing...",textNoData:"No data available",textNotFound:"Not found",textSelectAll:"Select all",textDeselectAll:"Deselect all",textAccessoryDeselect:"Deselect: ",animationtime:200,delaysearchtime:200,allowHtml:!0,maxSelected:0,labelHalign:"left",labelValign:"center",imageMode:!1,imageWidth:"60px",imageHeight:"60px",imageBorderRadius:"4px",imagePosition:"right",ajax:null,on:{load:[],beforeShow:[],show:[],beforeChange:[],change:[],beforeClose:[],close:[]}},this.i=new Map,this.h=new Map,this.o=[]}}class s{static get l(){return this.u||(this.u=new i),this.u}static p(t){if(null===t||"object"!=typeof t)return t;const i=Array.isArray(t)?[]:{};for(const s in t)Object.prototype.hasOwnProperty.call(t,s)&&(i[s]=this.p(t[s]));return i}static m(t=6){let i="";for(let s=0;s<t;s++)i+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random()));return i}static v(t){if(!t)return[];if("string"==typeof t){const i=document.querySelectorAll(t);return Array.from(i)}return t instanceof Element?[t]:t instanceof NodeList||Array.isArray(t)?Array.from(t):[]}static T(t={}){return this.O(document.createElement(t.node??"div"),t,!0)}static O(t=document.documentElement,i=null,s=!1){const e={...i??{}},n=s?t:this.C(t.cloneNode(!0)),h=e.classList;return"string"==typeof h?n.classList.add(h):Array.isArray(h)&&n.classList.add(...h),delete e.classList,["style","dataset"].forEach(t=>{const i=e[t];i&&"object"==typeof i&&Object.assign(n[t],i),delete e[t]}),e.role&&(n.setAttribute("role",e.role+""),delete e.role),e.ariaLive&&(n.setAttribute("aria-live",e.ariaLive+""),delete e.ariaLive),e.A&&(n.setAttribute("aria-labelledby",e.A+""),delete e.A),e.S&&(n.setAttribute("aria-controls",e.S+""),delete e.S),e.L&&(n.setAttribute("aria-haspopup",e.L+""),delete e.L),e.P&&(n.setAttribute("aria-multiselectable",e.P+""),delete e.P),e.M&&(n.setAttribute("aria-autocomplete",e.M+""),delete e.M),e.event&&"object"==typeof e.event&&(Object.entries(e.event).forEach(([t,i])=>{n.addEventListener(t,i)}),delete e.event),Object.entries(e).forEach(([t,i])=>{null===i?n.removeAttribute(t):n[t]=i}),n}static C(t){if(t instanceof Element)return t;throw new TypeError("Node is not an Element")}static H(t){return this.$(t)}static $(t,i=null,s=!1,e=!1,n={}){let h=null;for(const o in t){const r=t[o],l=r?.tag?.tagName?r.tag:this.T(r.tag);n[o]=l,r?.j&&this.$(r.j,l,!1,!1,n),i?s?i.prepend(l):i.append(l):e||h||(h=l)}return e||(n.id=this.m(7),i||(n={tags:n,view:h})),n}static F(t,i){const s=this.p(i);for(const i in s){const e=t[i];e?s[i]=e:void 0!==t?.dataset?.[i]&&(s[i]=t.dataset[i])}return s}static I(...t){if(0===t.length)return{};if(1===t.length)return this.p(t[0]);const i=this.p(t[0]);for(let s=1;s<t.length;s++){const e=t[s];for(const t in e)if("on"===t){const s=e[t];for(const e in s)i[t][e].push(s[e])}else i[t]=e[t]}return i}static V(t){if("boolean"==typeof t)return t;if("string"!=typeof t)return!!t;switch(t.trim().toLowerCase()){case"true":case"1":case"yes":case"on":return!0;default:return!1}}static k(t){return this.l.i.delete(t)}static R(t){return this.l.i.get(t)}static _(t,i){this.l.i.set(t,i)}static D(t){return this.l.h.delete(t)}static N(t){return this.l.h.get(t)}static B(t,i){this.l.h.set(t,i)}static G(){return this.l.t}static U(){return this.l.o}static W(t){if(null==t)return"";let i=(t+"").replace(/<`/g,"<").replace(/`>/g,">").replace(/\<\`/g,"<").replace(/\`\>/g,">").trim();const s=globalThis?.document;if(!s||"function"!=typeof s.createElement)return i=i.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"").replace(/<iframe\b[^>]*>[\s\S]*?<\/iframe>/gi,"").replace(/<(object|embed|link)\b[^>]*>[\s\S]*?<\/\1>/gi,""),i=i.replace(/\son[a-z]+\s*=\s*(['"]).*?\1/gi,""),i=i.replace(/\s([a-z-:]+)\s*=\s*(['"])\s*javascript:[^'"]*\2/gi,""),i;const e=s.createElement("div");return e.innerHTML=i,e.querySelectorAll("script, style, iframe, object, embed, link").forEach(t=>t.remove()),e.querySelectorAll("*").forEach(t=>{for(const i in t.attributes){const s=t.attributes[i],e=s.name??"",n=s.value??"";if(/^on/i.test(e))return void t.removeAttribute(e);/^(href|src|xlink:href)$/i.test(e)&&/^javascript:/i.test(n)&&t.removeAttribute(e)}}),(e.innerHTML??"").trim()}static q(t){const i=document.createElement("DIV");i.innerHTML=t;const s=i.textContent??i.innerText??"";return i.remove(),s.trim()}static J(t){return null==t?"":(t+"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/đ/g,"d").replace(/Đ/g,"d")}static K(t){const i=[];return Array.from(t.children).forEach(t=>{if("OPTGROUP"===t.tagName){const s=t;i.push(s),Array.from(s.children).forEach(t=>{t.__parentGroup=s,i.push(t)})}else"OPTION"===t.tagName&&i.push(t)}),i}static Y(){const t=navigator.userAgent;return/iP(hone|ad|od)/.test(t)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1}static X(t){const i=(t+"").trim();if(i.endsWith("px"))return i;if(i.endsWith("vh"))return window.innerHeight*parseFloat(i)/100+"px";if(i.endsWith("vw"))return window.innerWidth*parseFloat(i)/100+"px";const s=parseFloat(getComputedStyle(document.documentElement).fontSize);if(i.endsWith("rem"))return s*parseFloat(i)+"px";const e=this.T({node:"div",style:{height:i,opacity:"0"}});document.body.appendChild(e);const n=e.offsetHeight+"px";return e.remove(),n}}s.u=null,s.Z=new class{constructor(){this.tt=new Map,this.it=new Map}on(t,i,s={}){const e=s.st??50,n=s.once??!1;this.tt.has(t)||this.tt.set(t,[]),this.tt.get(t).push({et:i,timeout:e,once:n})}off(t){const i=this.it.get(t);if(i){for(const t of i.values())clearTimeout(t);i.clear(),this.it.delete(t)}this.tt.delete(t)}run(t,...i){const s=this.tt.get(t);if(!s)return;this.it.has(t)||this.it.set(t,new Map);const e=this.it.get(t);for(let t=0;t<s.length;t++){const n=s[t];if(!n)continue;const h=e.get(t);h&&clearTimeout(h);const o=setTimeout(()=>{if(n.et(i.length>0?i:null),n.once){s[t]=void 0;const i=e.get(t);i&&clearTimeout(i),e.delete(t)}},n.timeout);e.set(t,o)}}clear(t){if(void 0===t)for(const t of Array.from(this.tt.keys()))this.off(t);else this.off(t)}};class e{static nt(){const t={isContinue:!0,isCancel:!1};return{token:{get isContinue(){return t.isContinue},get isCancel(){return t.isCancel}},et:{stopPropagation(){t.isContinue=!1},cancel(){t.isCancel=!0,t.isContinue=!1}}}}static ht(t,...i){const{token:s,et:e}=this.nt();for(let n=0;n<i.length;n++){const h=i[n];if("function"==typeof h&&(t&&Array.isArray(t)?h(e,...t):h(e),s.isCancel||!s.isContinue))break}return s}static ot(t,i,s={bubbles:!0,cancelable:!0}){const e=new Event(i,s);return t.dispatchEvent(e),e}static rt(t,...i){if(Array.isArray(t))for(const s of t)"function"==typeof s&&s(...i)}}class n{static lt(t,i){const e=s.R(t);if(!e?.options)return;const n=e.options,h=n.minWidth,o=n.minHeight,r=Number.parseInt(n.width,10),l=Number.parseInt(n.height,10);let a=t.offsetWidth+"px",c=t.offsetHeight+"px";const u=getComputedStyle(t);"0px"===a&&"auto"!==u.width&&(a=u.width),"0px"===c&&"auto"!==u.height&&(c=u.height),r>0&&(a=n.width),l>0&&(c=n.height),Object.assign(i.style,{width:a,height:c,minWidth:h,minHeight:o})}}class h{constructor(t){this.node=null,this.ct=null,t&&this.init(t)}init(t){this.node=s.T({node:"div",classList:"selective-ui-placeholder",innerHTML:t.placeholder}),this.ct=t}get(){return this.ct?.placeholder??""}set(t,i=!0){if(!this.node||!this.ct)return;i&&(this.ct.placeholder=t);const e=s.W(t);this.node.innerHTML=this.ct.allowHtml?e:s.q(e)}}class o{constructor(){this.node=this.ut()}ut(){return s.T({node:"div",classList:"selective-ui-directive",role:"button",ariaLabel:"Toggle dropdown"})}dt(t){this.node.classList.toggle("drop-down",!!t)}}class r{constructor(t=null){this.gt=null,this.node=null,this.options=null,this.ft=[],this.bt=[],t&&this.init(t)}init(t){this.gt=s.$({wt:{tag:{node:"div",classList:["selective-ui-option-handle","hide"]},j:{yt:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textSelectAll,onclick:()=>{e.rt(this.ft)}}},vt:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textDeselectAll,onclick:()=>{e.rt(this.bt)}}}}}}),this.node=this.gt.view,this.options=t}available(){return!!this.options&&s.V(this.options.multiple)&&s.V(this.options.selectall)}refresh(){this.node&&(this.available()?this.show():this.hide())}show(){this.node&&this.node.classList.remove("hide")}hide(){this.node&&this.node.classList.add("hide")}xt(t=null){"function"==typeof t&&this.ft.push(t)}Tt(t=null){"function"==typeof t&&this.bt.push(t)}}class l{constructor(t=null){this.node=null,this.options=null,t&&this.init(t)}init(t){this.options=t,this.node=s.T({node:"div",classList:["selective-ui-empty-state","hide"],role:"status",ariaLive:"polite"})}show(t="nodata"){this.node&&this.options&&(this.node.textContent="notfound"===t?this.options.textNotFound:this.options.textNoData,this.node.classList.remove("hide"))}hide(){this.node&&this.node.classList.add("hide")}get isVisible(){return!!this.node&&!this.node.classList.contains("hide")}}class a{constructor(t=null){this.node=null,this.options=null,t&&this.init(t)}init(t){this.options=t,this.node=s.T({node:"div",classList:["selective-ui-loading-state","hide"],textContent:t.textLoading,role:"status",ariaLive:"polite"})}show(t){this.node&&this.options&&(this.node.textContent=this.options.textLoading,this.node.classList.toggle("small",!!t),this.node.classList.remove("hide"))}hide(){this.node&&this.node.classList.add("hide")}get isVisible(){return!!this.node&&!this.node.classList.contains("hide")}}class c{constructor(){this.Ot=!1,this.element=null,this.Ct=null,this.At=null,this.Ot=!0,this.St=this.Lt.bind(this)}Pt(t){}Lt(){const t=this.element;if(!t||"function"!=typeof t.getBoundingClientRect)return void this.Pt({width:0,height:0,top:0,left:0,padding:{top:0,right:0,bottom:0,left:0},border:{top:0,right:0,bottom:0,left:0},margin:{top:0,right:0,bottom:0,left:0}});const i=t.getBoundingClientRect(),s="undefined"!=typeof window&&"function"==typeof window.getComputedStyle?window.getComputedStyle(t):null;this.Pt({width:i?.width??0,height:i?.height??0,top:i?.top??0,left:i?.left??0,padding:{top:parseFloat(s?.paddingTop??"0"),right:parseFloat(s?.paddingRight??"0"),bottom:parseFloat(s?.paddingBottom??"0"),left:parseFloat(s?.paddingLeft??"0")},border:{top:parseFloat(s?.borderTopWidth??"0"),right:parseFloat(s?.borderRightWidth??"0"),bottom:parseFloat(s?.borderBottomWidth??"0"),left:parseFloat(s?.borderLeftWidth??"0")},margin:{top:parseFloat(s?.marginTop??"0"),right:parseFloat(s?.marginRight??"0"),bottom:parseFloat(s?.marginBottom??"0"),left:parseFloat(s?.marginLeft??"0")}})}ot(){this.Lt()}connect(t){if(!(t instanceof Element))throw Error("Invalid element");this.element=t,this.Ct=new ResizeObserver(this.St),this.Ct.observe(t),this.At=new MutationObserver(this.St),this.At.observe(t,{attributes:!0,attributeFilter:["style","class"]}),window.addEventListener("scroll",this.St,!0),window.addEventListener("resize",this.St),window.visualViewport&&(window.visualViewport.addEventListener("resize",this.St),window.visualViewport.addEventListener("scroll",this.St))}disconnect(){this.Ct?.disconnect(),this.At?.disconnect(),this.Pt=()=>{},window.removeEventListener("scroll",this.St,!0),window.removeEventListener("resize",this.St),window.visualViewport&&(window.visualViewport.removeEventListener("resize",this.St),window.visualViewport.removeEventListener("scroll",this.St)),this.Ct=null,this.At=null,this.element=null}}class u{constructor(t=null,i=null,s=null){this.options=null,this.Mt=!1,this.Ht=null,this.node=null,this.$t=null,this.jt=null,this.Et=null,this.Ft=null,this.It=null,this.Vt=null,this.kt=null,this.Rt=null,this._t=null,this.Dt=null,this.Nt=s,t&&i&&this.init(t,i)}init(t,i){if(!this.Nt)throw Error("Popup requires a ModelManager instance.");this.Ft=new r(i),this.It=new l(i),this.Vt=new a(i);const e=s.$({Bt:{tag:{node:"div",classList:"selective-ui-popup",style:{maxHeight:i.panelHeight}},j:{wt:{tag:this.Ft.node},zt:{tag:{id:i.Gt,node:"div",classList:"selective-ui-options-container",role:"listbox"}},Ut:{tag:this.Vt.node},Wt:{tag:this.It.node}}}},null);this.node=e.view,this.Rt=e.tags.zt,this.Et=s.R(t),this.options=i,this.Nt.load(this.Rt,{isMultiple:i.multiple});const n=this.Nt.qt();this.Ht=n.Jt,this.kt=n.kt,this.Ft.xt(()=>{n.Jt.Kt(!0)}),this.Ft.Tt(()=>{n.Jt.Kt(!1)}),this.Qt()}async Yt(){this.options&&this.Vt&&this.Ft&&this.Ht&&this.Nt&&(this.Dt&&clearTimeout(this.Dt),this.Nt.Xt(!0),!1!==s.V(this.options.loadingfield)&&(this.Vt.show(this.Ht.ti().Zt),this.Ft.hide(),this.ii()))}async si(){this.options&&this.Vt&&this.Ht&&this.Nt&&(this.Dt&&clearTimeout(this.Dt),this.Dt=setTimeout(()=>{this.Nt?.Xt(!1),this.Vt?.hide();const t=this.Ht?.ti();this.ei(t??void 0),this.ii()},200))}Qt(){this.Ht&&(this.Ht.ni(t=>{this.ei(t)}),this.Ht.hi("items",()=>{const t=this.Ht.ti();this.ei(t),this.ii()}))}ei(t){if(!(this.Ht&&this.It&&this.Ft&&this.Rt))return;const i=t??this.Ht.ti();i.isEmpty?(this.It.show("nodata"),this.Rt.classList.add("hide"),this.Ft.hide()):i.Zt?(this.It.hide(),this.Rt.classList.remove("hide"),this.Ft.refresh()):(this.It.show("notfound"),this.Rt.classList.add("hide"),this.Ft.hide())}oi(t,i){this.Ht?.ri(t,i)}li(t,i){this.Ht?.hi(t,i)}ai(t){this.$t=t}open(t=null){if(!(this.node&&this.options&&this.Ft&&this.Et&&this.$t))return;this.Mt||(document.body.appendChild(this.node),this.Mt=!0,this.jt=new c,this.$t.ci(this.node),this.node.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()})),this.Ft.refresh(),this.ei();const i=this.ui(),{position:s,top:e,maxHeight:n,di:h}=this.pi(i);this.$t.expand({duration:this.options.animationtime,display:"flex",width:i.width,left:i.left,top:e,maxHeight:n,di:h,position:s,gi:()=>{this.jt&&this.Et&&(this.jt.Pt=()=>{const t=this.ui();this.fi(t)},this.jt.connect(this.Et.container.tags.mi),t?.())}})}close(t=null){this.Mt&&this.options&&this.jt&&this.$t&&(this.jt.disconnect(),this.$t.collapse({duration:this.options.animationtime,gi:t??void 0}))}ii(){this.Mt&&this.jt?.ot()}bi(t,i){this.node&&(this._t=async()=>{const i=t.wi();if(!i.yi)return;const s=this.node;if(s.scrollHeight-s.scrollTop-s.clientHeight<100&&!i.xi&&i.hasMore){const i=await t.Ti();!i.Oi&&i.message&&console.log("Load more:",i.message)}},this.node.addEventListener("scroll",this._t))}Ci(){this.Dt&&(clearTimeout(this.Dt),this.Dt=null),this.node&&this._t&&(this.node.removeEventListener("scroll",this._t),this._t=null);try{this.jt?.disconnect()}catch(t){}this.jt=null;try{this.$t?.ci?.(null)}catch(t){}if(this.$t=null,this.node)try{const t=this.node.cloneNode(!0);this.node.replaceWith(t),t.remove()}catch(t){this.node.remove()}this.node=null,this.Rt=null;try{this.Nt?.Xt?.(!1),this.kt?.clear?.(),this.kt=null,this.Ht=null,this.node.remove()}catch(t){}this.Nt=null,this.Ft=null,this.It=null,this.Vt=null,this.Et=null,this.options=null,this.Mt=!1}ui(){const t=this.Et.container.tags.mi,i=t.getBoundingClientRect(),e=window.getComputedStyle(t),n=window.visualViewport,h=s.Y();return{width:i.width,height:i.height,top:i.top-(n&&h?n.offsetTop:0),left:i.left-(n&&h?n.offsetLeft:0),padding:{top:parseFloat(e.paddingTop),right:parseFloat(e.paddingRight),bottom:parseFloat(e.paddingBottom),left:parseFloat(e.paddingLeft)},border:{top:parseFloat(e.borderTopWidth),right:parseFloat(e.borderRightWidth),bottom:parseFloat(e.borderBottomWidth),left:parseFloat(e.borderLeftWidth)}}}pi(t){const i=window.visualViewport,e=s.Y(),n=i?.height??window.innerHeight,h=i&&e?i.offsetTop:0,o=this.$t.Ai("flex").scrollHeight,r=parseFloat(this.options?.panelHeight??"220")||220,l=parseFloat(this.options?.panelMinHeight??"100")||100,a=n-(t.top+t.height)-3,c=t.top-3;let u="bottom",d=r,p=Math.min(o,d);const g=a-15;return(p>=l?g>=l:g>=p)?(u="bottom",d=Math.min(a-15,r)):c>=Math.max(p,l)?(u="top",d=Math.min(c-15,r)):a>=c?(u="bottom",d=Math.max(a-15,l)):(u="top",d=Math.max(c-15,l)),p=Math.min(o,d),{position:u,top:"bottom"===u?t.top+t.height+3+h:t.top-p-3+h,maxHeight:d,di:p,Si:o}}fi(t){if(!this.options||!this.$t)return;const{position:i,top:s,maxHeight:e,di:n}=this.pi(t);this.$t.resize({duration:this.options.animationtime,width:t.width,left:t.left,top:s,maxHeight:e,di:n,position:i,animate:!0})}}class d{constructor(t=null){this.gt=null,this.node=null,this.Li=null,this.Pi=null,this.options=null,this.Mi=null,this.Hi=null,this.$i=null,this.options=t,t&&this.init(t)}init(t){this.gt=s.$({ji:{tag:{node:"div",classList:["selective-ui-searchbox","hide"]},j:{Li:{tag:{id:s.m(),node:"input",type:"search",classList:["selective-ui-searchbox-input"],placeholder:t.placeholder,role:"searchbox",S:t.Gt,M:"list"}}}}}),this.node=this.gt.view,this.Li=this.gt.tags.Li;let i=!1;const e=this.gt.tags.Li;e.addEventListener("mousedown",t=>{t.stopPropagation()}),e.addEventListener("mouseup",t=>{t.stopPropagation()}),e.addEventListener("keydown",t=>{i=!1,"ArrowDown"===t.key||"Tab"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.Mi?.(1)):"ArrowUp"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.Mi?.(-1)):"Enter"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.Hi?.()):"Escape"===t.key&&(t.preventDefault(),t.stopPropagation(),i=!0,this.$i?.())}),e.addEventListener("input",()=>{i||this.Pi?.(e.value,!0)})}show(){this.node&&this.Li&&this.options&&(this.node.classList.remove("hide"),this.Li.readOnly=!this.options.searchable,this.options.searchable&&requestAnimationFrame(()=>{this.Li?.focus()}))}hide(){this.node&&this.node.classList.add("hide")}clear(t=!0){this.gt&&(this.gt.tags.Li.value="",this.Pi?.("",t))}Ei(t){this.Li&&(this.Li.placeholder=s.q(t))}Fi(t){this.Li&&this.Li.setAttribute("aria-activedescendant",t)}}class p{constructor(t=null){this.Ii=null,this.Vi=null,this.ki=!1,t&&this.ci(t)}ci(t){if("string"==typeof t){const i=document.querySelector(t);return void(i instanceof HTMLElement&&(this.element=i))}this.element=t}cancel(){return this.Ii&&(clearTimeout(this.Ii),this.Ii=null),this.Vi&&(clearTimeout(this.Vi),this.Vi=null),this.ki=!1,this}Ai(t="flex"){if(!this.element)return{width:0,height:0,scrollHeight:0};const i={display:this.element.style.display,visibility:this.element.style.visibility,position:this.element.style.position,height:this.element.style.height,width:this.element.style.width};Object.assign(this.element.style,{display:t,visibility:"hidden",position:"fixed",height:"fit-content",width:"fit-content"});const s=window.getComputedStyle(this.element),e=parseFloat(s.borderTopWidth),n=parseFloat(s.borderBottomWidth),h=this.element.scrollHeight+e+n,o=this.element.getBoundingClientRect(),r={width:o.width,height:o.height+e+n,scrollHeight:h};return Object.assign(this.element.style,i),r}expand(t){if(!this.element)return this;this.cancel(),this.ki=!0;const{duration:i=200,display:s="flex",width:e,left:n,top:h,maxHeight:o,di:r,position:l="bottom",gi:a}=t;return Object.assign(this.element.style,{display:s,width:e+"px",left:n+"px",top:("bottom"===l?h:h+r)+"px",maxHeight:o+"px",height:"0px",opacity:"0",overflow:"hidden",transition:"none"}),this.element.classList.toggle("position-top","top"===l),this.element.classList.toggle("position-bottom","bottom"===l),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`top ${i}ms, height ${i}ms, opacity ${i}ms`,top:h+"px",height:r+"px",opacity:"1",overflow:r>=o?"auto":"hidden"}),this.Ii=setTimeout(()=>{this.element.style.transition="none",this.ki=!1,a?.()},i)}),this}collapse(t){if(!this.element)return this;this.cancel(),this.ki=!0;const{duration:i=200,gi:s}=t,e=this.element.offsetHeight,n=this.element.offsetTop,h=this.element.classList.contains("position-top")?"top":"bottom",o=this.element.scrollHeight-this.element.offsetHeight>0,r="top"===h?n+e:n;return requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`height ${i}ms, top ${i}ms, opacity ${i}ms`,height:"0px",top:r+"px",opacity:"0",overflow:o?"auto":"hidden"}),this.Ii=setTimeout(()=>{Object.assign(this.element.style,{display:"none",transition:"none"}),this.ki=!1,s?.()},i)}),this}showSwipeWidth(t){if(!this.element)return this;this.cancel(),this.ki=!0;const{duration:i=200,display:s="block",gi:e}=t;Object.assign(this.element.style,{transition:"none",display:s,width:"fit-content"});const n=this.Ai(s).width;return Object.assign(this.element.style,{width:"0px"}),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`width ${i}ms`,width:n+"px",overflow:"hidden"})}),this.Ii=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:""}),this.ki=!1,e?.()},i),this}hideSwipeWidth(t){if(!this.element)return this;this.cancel(),this.ki=!0;const{duration:i=200,gi:s}=t,e=this.Ai().width;return Object.assign(this.element.style,{transition:"none",width:e+"px"}),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`width ${i}ms`,width:"0px",overflow:"hidden"})}),this.Ii=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:"",display:""}),this.ki=!1,s?.()},i),this}resize(t){if(!this.element)return this;this.Vi&&clearTimeout(this.Vi);const{duration:i=200,width:s,left:e,top:n,maxHeight:h,di:o,position:r="bottom",animate:l=!0,gi:a}=t,c=(this.element.classList.contains("position-top")?"top":"bottom")!==r,u=this.element.scrollHeight>h;return this.element.classList.toggle("position-top","top"===r),this.element.classList.toggle("position-bottom","bottom"===r),c&&(this.element.style.transition=`top ${i}ms ease-out, height ${i}ms ease-out, max-height ${i}ms ease-out;`),requestAnimationFrame(()=>{const t={width:s+"px",left:e+"px",top:n+"px",maxHeight:h+"px",height:o+"px",overflowY:u?"auto":"hidden"},r=Math.abs(this.element.offsetHeight-o);l&&(c||r>5)?t.transition=`height ${i}ms, top ${i}ms`:this.Vi=setTimeout(()=>{this.element?.style&&(this.element.style.transition="none")},i),Object.assign(this.element.style,t),l&&(c||r>1)?this.Vi=setTimeout(()=>{this.element.style.transition="none",c&&delete this.element.style.transition,a?.()},i):(c&&delete this.element.style.transition,a?.())}),this}get Ri(){return this.ki}}class g{get value(){return this.targetElement?.getAttribute("value")??null}constructor(t,i=null,s=null){this.targetElement=null,this.view=null,this.position=-1,this.Ot=!1,this.options=t,this.targetElement=i,this.view=s}update(t){this.targetElement=t,this._i()}_i(){}}class f extends g{constructor(t,i){super(t,i??null,null),this.label="",this.items=[],this.collapsed=!1,this.Di=[],i&&(this.label=i.label,this.collapsed=s.V(i.dataset?.collapsed))}get value(){return this.items.map(t=>t.value)}get Ni(){return this.items.filter(t=>t.selected)}get Bi(){return this.items.filter(t=>t.visible)}get zi(){return this.Bi.length>0}update(t){this.label=t.label,this.view?.Gi(this.label)}_i(){this.view&&(this.view.Gi(this.label),this.view.Ui(this.collapsed))}Wi(t){this.Di.push(t)}qi(){this.collapsed=!this.collapsed,this.view?.Ui(this.collapsed),e.ht([this,this.collapsed],...this.Di)}Ji(t){this.items.push(t),t.group=this}removeItem(t){const i=this.items.indexOf(t);i>-1&&(this.items.splice(i,1),t.group=null)}Ki(){this.view?.Ki()}}class m extends g{constructor(){super(...arguments),this.Qi=[],this.Yi=[],this.Xi=[],this.Zi=!0,this.ts=!1,this.group=null}get ss(){return this.dataset?.imgsrc||this.dataset?.image||""}get hasImage(){return!!this.ss}get value(){return this.targetElement?.value??""}get selected(){return!!this.targetElement?.selected}set selected(t){this.es=t,e.ht([this,t],...this.Qi)}get visible(){return this.Zi}set visible(t){if(this.Zi===t)return;this.Zi=t;const i=this.view?.ns?.();i&&i.classList.toggle("hide",!t),e.ht([this,t],...this.Xi)}get es(){return this.selected}set es(t){const i=this.view?.view?.tags?.hs,s=this.view?.ns?.();i&&(i.checked=t),s&&this.targetElement&&(s.classList.toggle("checked",!!t),s.setAttribute("aria-selected",t?"true":"false"),this.targetElement.toggleAttribute("selected",!!t)),this.targetElement&&(this.targetElement.selected=t),e.ht([this,t],...this.Yi)}get text(){const t=s.W(this.dataset?.mask??this.targetElement?.text??"");return this.options.allowHtml?t:s.q(t)}get textContent(){return this.options.allowHtml?s.q(this.text).trim():this.text.trim()}get dataset(){return this.targetElement?.dataset??{}}get rs(){return this.ts}set rs(t){const i=!!t,s=this.view?.ns?.();this.ts!==i&&(this.ts=i),s&&s.classList.toggle("highlight",i)}ls(t){this.Qi.push(t)}cs(t){this.Yi.push(t)}ni(t){this.Xi.push(t)}_i(){if(!this.view)return;const t=this.view.view.tags.us;t&&(this.options.allowHtml?t.innerHTML=this.text:t.textContent=this.textContent);const i=this.view.view.tags.ds;i&&this.hasImage&&(i.src=this.ss,i.alt=this.text),this.targetElement&&(this.es=this.targetElement.selected)}}class b{constructor(t){this.ps=[],this.gs=null,this.fs=null,this.bs=null,this.options=null,this.options=t}ws(t){this.ys=t}vs(t){this.xs=t}Ts(t){const i=this.Os(t),s=i!==this.bs;return s&&(this.bs=i),s}Os(t){return t.map(t=>{if("OPTGROUP"===t.tagName){const i=t,s=Array.from(i.children).map(t=>`${t.value}:${t.text}:${t.selected}`).join("\n");return`G:${i.label}:${s}`}return`O:${t.value}:${t.text}:${t.selected}`}).join("\n\n")}Cs(t){this.ps=[];let i=null;return t.forEach(t=>{if("OPTGROUP"===t.tagName)i=new f(this.options,t),this.ps.push(i);else if("OPTION"===t.tagName){const s=t,e=new m(this.options,s),n=s.__parentGroup;n&&i&&n===i.targetElement?(i.Ji(e),e.group=i):(this.ps.push(e),i=null)}}),this.ps}replace(t){this.bs=null,this.Cs(t),this.gs&&this.gs.As(this.ps),this.refresh()}notify(){this.gs&&this.refresh()}load(t,i={},s={}){this.gs=new this.ys(this.ps),Object.assign(this.gs,i),this.fs=new this.xs(t),this.fs.Ss(this.gs),Object.assign(this.fs,s)}update(t){if(!this.Ts(t))return;const i=this.ps,s=[],e=new Map,n=new Map;i.forEach(t=>{t instanceof f?e.set(t.label,t):t instanceof m&&n.set(`${t.value}::${t.textContent}`,t)});let h=null,o=0;t.forEach(t=>{if("OPTGROUP"===t.tagName){const i=t,n=e.get(i.label);n?(n.label!==i.label&&n.update(i),n.position=o,n.items=[],h=n,s.push(n),e.delete(i.label)):(h=new f(this.options,i),h.position=o,s.push(h)),o++}else if("OPTION"===t.tagName){const i=t,e=`${i.value}::${i.text}`,r=n.get(e);if(r)r.update(i),r.position=o,i.__parentGroup&&h?(h.Ji(r),r.group=h):(r.group=null,s.push(r)),n.delete(e);else{const t=new m(this.options,i);t.position=o,i.__parentGroup&&h?(h.Ji(t),t.group=h):s.push(t)}o++}}),e.forEach(t=>{t.view?.ns?.()?.remove?.()}),n.forEach(t=>{t.view?.ns?.()?.remove?.()}),this.ps=s,this.gs&&this.gs.Ls(this.ps),this.onUpdated(),this.refresh()}onUpdated(){}Xt(t){this.gs&&(this.gs.Ps=t)}refresh(){this.fs&&(this.fs.refresh(),this.onUpdated())}qt(){return{Ms:this.ps,Jt:this.gs,kt:this.fs}}Hs(t){this.gs?.$s(t)}js(t){this.gs?.Es(t)}}class w{constructor(t=null){this.Fs=null,this.Jt=null,this.Fs=t}Is(t){this.Fs=t}Ss(t){this.Jt=t,t.ri("items",()=>{this.clear()}),t.hi("items",()=>{this.Vs()}),this.Vs()}clear(){this.Fs&&this.Fs.replaceChildren()}Vs(){this.Jt&&this.Fs&&this.Jt.ks(this.Fs)}refresh(){this.Vs()}}class y{constructor(t=null){this.gt=null,this.node=null,this.options=null,this.Rs=null,this._s=null,this.Ds=null,t&&this.init(t)}init(t){this.gt=s.$({Ns:{tag:{node:"div",classList:["selective-ui-accessorybox","hide"],onmouseup:t=>{t.stopPropagation()}}}}),this.node=this.gt.view,this.options=t}Bs(t){this.Rs=t,this._s=t.parentElement,this.zs()}zs(){this._s&&this.node&&this.Rs&&this.options&&this._s.insertBefore(this.node,"top"===this.options.accessoryStyle?this.Rs:this.Rs.nextSibling)}Gs(t){this.Ds=t}Us(t){this.node&&this.options&&(this.node.replaceChildren(),t.length>0&&this.options.multiple?(this.node.classList.remove("hide"),t.forEach(t=>{s.$({Ws:{tag:{node:"div",classList:["accessory-item"]},j:{qs:{tag:{node:"span",classList:["accessory-item-button"],role:"button",ariaLabel:`${this.options.textAccessoryDeselect}${t.textContent}`,title:`${this.options.textAccessoryDeselect}${t.textContent}`,onclick:i=>{i.preventDefault(),this.Ds?.Hs?.("select"),setTimeout(()=>{t.selected=!1},10)}}},Js:{tag:{node:"span",classList:["accessory-item-content"],innerHTML:t.text}}}}},this.node)})):this.node.classList.add("hide"),e.ot(window,"resize"))}}class v{constructor(t,i){this.Ks=null,this.Qs=null,this.Ys=null,this.Xs={currentPage:0,totalPages:1,hasMore:!1,xi:!1,Zs:"",yi:!1},this.te=t,this.Nt=i}ie(){return!!this.Ks}async se(t){if(!this.Ks)return{Oi:!1,items:[],message:"Ajax not configured"};const i=Array.isArray(t)?t:[t];if(0===i.length)return{Oi:!0,items:[]};try{const t=this.Ks;let s,e;if(s="function"==typeof t.ee?t.ee(i):{values:i.join(","),ne:"1",..."function"==typeof t.data?t.data("",0):t.data??{}},"POST"===(t.method??"GET")){const i=new URLSearchParams;Object.keys(s).forEach(t=>i.append(t,s[t]+"")),e=await fetch(t.url,{method:"POST",body:i,headers:{"Content-Type":"application/x-www-form-urlencoded"}})}else{const i=""+new URLSearchParams(s);e=await fetch(`${t.url}?${i}`)}if(!e.ok)throw Error("HTTP error! status: "+e.status);const n=await e.json();return{Oi:!0,items:this.he(n).items}}catch(t){return console.error("Load by values error:",t),{Oi:!1,message:t?.message,items:[]}}}oe(t){const i=Array.from(this.te.options).map(t=>t.value);return{re:t.filter(t=>i.includes(t)),le:t.filter(t=>!i.includes(t))}}ae(t){this.Ks=t}setPopup(t){this.Ys=t}wi(){return{...this.Xs}}ce(){this.Xs={currentPage:0,totalPages:1,hasMore:!1,xi:!1,Zs:"",yi:this.Xs.yi}}clear(){this.Xs.Zs="";const{Ms:t}=this.Nt.qt(),i=[];for(const s of t)s instanceof m?i.push(s):s instanceof f&&Array.isArray(s.items)&&i.push(...s.items);i.forEach(t=>{t.visible=!0})}async search(t,i=!1){return this.Ks?this.ue(t,i):this.de(t)}async Ti(){return this.Ks?this.Xs.xi?{Oi:!1,message:"Already loading"}:this.Xs.yi?this.Xs.hasMore?(this.Xs.currentPage++,this.ue(this.Xs.Zs,!0)):{Oi:!1,message:"No more data"}:{Oi:!1,message:"Pagination not enabled"}:{Oi:!1,message:"Ajax not enabled"}}async de(t){this.pe(t)&&(this.Xs.Zs=t);const i=((t??"")+"").toLowerCase(),e=s.J(i),{Ms:n}=this.Nt.qt(),h=[];for(const t of n)t instanceof m?h.push(t):t instanceof f&&Array.isArray(t.items)&&h.push(...t.items);let o=!1;return h.forEach(t=>{const n=((t.textContent??t.text??"")+"").toLowerCase(),h=s.J(n),r=""===i||n.includes(i)||h.includes(e);t.visible=r,r&&(o=!0)}),{Oi:!0,ge:o,isEmpty:0===h.length}}pe(t){return t!==this.Xs.Zs}async ue(t,i=!1){const s=this.Ks;this.pe(t)&&(this.ce(),this.Xs.Zs=t,i=!1),this.Xs.xi=!0,this.Ys?.Yt(),this.Qs?.abort(),this.Qs=new AbortController;const e=this.Xs.currentPage,n=Array.from(this.te.selectedOptions).map(t=>t.value).join(",");let h;"function"==typeof s.data?(h=s.data(t,e),h&&void 0===h.fe&&(h.fe=n)):h={search:t,page:e,fe:n,...s.data??{}};try{let t;if("POST"===(s.method??"GET")){const i=new URLSearchParams;Object.keys(h).forEach(t=>i.append(t,h[t]+"")),t=await fetch(s.url,{method:"POST",body:i,headers:{"Content-Type":"application/x-www-form-urlencoded"},signal:this.Qs.signal})}else{const i=""+new URLSearchParams(h);t=await fetch(`${s.url}?${i}`,{signal:this.Qs.signal})}const e=await t.json(),n=this.he(e);return n.me?(this.Xs.yi=!0,this.Xs.currentPage=n.page,this.Xs.totalPages=n.totalPages,this.Xs.hasMore=n.hasMore):this.Xs.yi=!1,this.be(n.items,!!s.keepSelected,i),this.Xs.xi=!1,this.Ys?.si(),{Oi:!0,ge:n.items.length>0,isEmpty:0===n.items.length,me:n.me,hasMore:n.hasMore,currentPage:n.page,totalPages:n.totalPages}}catch(t){return this.Xs.xi=!1,this.Ys?.si(),"AbortError"===t?.name?{Oi:!1,message:"Request aborted"}:(console.error("Ajax search error:",t),{Oi:!1,message:t?.message})}}he(t){let i=[],s=!1,e=0,n=1,h=!1;return t.object&&Array.isArray(t.object)?(i=t.object,void 0!==t.page&&(s=!0,e=parseInt(t.page??0,10),n=parseInt(t.totalPages??t.total_page??1,10),h=e<n-1)):t.data&&Array.isArray(t.data)?(i=t.data,void 0!==t.page&&(s=!0,e=parseInt(t.page??0,10),n=parseInt(t.totalPages??t.total_page??1,10),h=t.hasMore??e<n-1)):Array.isArray(t)?i=t:t.items&&Array.isArray(t.items)&&(i=t.items,t.pagination&&(s=!0,e=parseInt(t.pagination.page??0,10),n=parseInt(t.pagination.totalPages??t.pagination.total_page??1,10),h=t.pagination.hasMore??e<n-1)),{items:i.map(t=>{if(t instanceof HTMLOptionElement||t instanceof HTMLOptGroupElement)return t;if("optgroup"===t.type||t.we||t.group||t.label)return{type:"optgroup",label:t.label??t.name??t.title??"",data:t.data??{},options:(t.options??t.items??[]).map(t=>({value:t.value??t.id??t.key??"",text:t.text??t.label??t.name??t.title??"",selected:t.selected??!1,data:t.data??(t.imgsrc?{imgsrc:t.imgsrc}:{})}))};const i=t.data??{};return t?.imgsrc&&(i.imgsrc=t.imgsrc),{type:"option",value:t.value??t.id??t.key??"",text:t.text??t.label??t.name??t.title??"",selected:t.selected??!1,data:i}}),me:s,page:e,totalPages:n,hasMore:h}}be(t,i,s=!1){const e=this.te;let n=[];i&&(n=Array.from(e.selectedOptions).map(t=>t.value)),s||(e.innerHTML=""),t.forEach(t=>{if("option"!==t.type&&t.type||""!==t.value||""!==t.text)if(t instanceof HTMLOptionElement||t instanceof HTMLOptGroupElement)e.appendChild(t);else if("optgroup"===t.type){const s=document.createElement("optgroup");s.label=t.label,t.data&&Object.keys(t.data).forEach(i=>{s.dataset[i]=t.data[i]+""}),Array.isArray(t.options)&&t.options.forEach(t=>{const e=document.createElement("option");e.value=t.value,e.text=t.text,t.data&&Object.keys(t.data).forEach(i=>{e.dataset[i]=t.data[i]+""}),(t.selected||i&&n.includes(e.value))&&(e.selected=!0),s.appendChild(e)}),e.appendChild(s)}else{const s=document.createElement("option");s.value=t.value,s.text=t.text,t.data&&Object.keys(t.data).forEach(i=>{s.dataset[i]=t.data[i]+""}),(t.selected||i&&n.includes(s.value))&&(s.selected=!0),e.appendChild(s)}}),e.dispatchEvent(new CustomEvent("options:changed"))}}class x{constructor(t){this.ye=null,this.ve=null,this.xe=50,this.te=t,this.ve=this.Te(),this.Oe=new MutationObserver(()=>{this.ye&&clearTimeout(this.ye),this.ye=setTimeout(()=>{this.Ce()},this.xe)}),t.addEventListener("options:changed",()=>{this.ye&&clearTimeout(this.ye),this.ye=setTimeout(()=>{this.Ce()},this.xe)})}Te(){const t=Array.from(this.te.options);return{length:t.length,values:t.map(t=>t.value).join(","),Ae:t.map(t=>t.text).join(","),selected:t.map(t=>t.selected+"").join(",")}}Se(){const t=this.Te(),i=JSON.stringify(t)!==JSON.stringify(this.ve);return i&&(this.ve=t),i}Ce(){this.Se()&&this.Pt(this.te)}connect(){this.Oe.observe(this.te,{childList:!0,subtree:!1,attributes:!0,attributeFilter:["selected","value","disabled"]})}Pt(t){}disconnect(){this.ye&&clearTimeout(this.ye),this.ye=null,this.Oe.disconnect()}}class T{constructor(t){this.ye=null,this.Le=t,this.Oe=new MutationObserver(t=>{let i=!1;for(const s of t)if("attributes"===s.type&&s.attributeName?.startsWith("data-")){i=!0;break}i&&(this.ye&&clearTimeout(this.ye),this.ye=setTimeout(()=>{this.Pt({...this.Le.dataset})},50))}),t.addEventListener("dataset:changed",()=>{this.Pt({...this.Le.dataset})})}connect(){this.Oe.observe(this.Le,{attributes:!0,attributeOldValue:!0})}Pt(t){}disconnect(){this.ye&&clearTimeout(this.ye),this.ye=null,this.Oe.disconnect()}}class O{constructor(t=[]){this.items=[],this.Pe=s.m(12),this.Ps=!1,this.items=t,this.Me()}Me(){}He(t,i,s){const e=i;t.Ot?e?.update?.():e?.Vs?.()}ri(t,i){s.Z.on(`${t}ing_${this.Pe}`,i,{st:1})}hi(t,i){s.Z.on(`${t}_${this.Pe}`,i)}Es(t,...i){s.Z.run(`${t}_${this.Pe}`,...i)}$s(t,...i){s.Z.run(`${t}ing_${this.Pe}`,...i)}$e(t,i){return null}je(){return this.items.length}Ee(t){this.$s("items",t),this.items=t,this.Es("items",t)}As(t){this.Ee(t)}ks(t){for(let i=0;i<this.je();i++){const s=this.items[i];let e=s.view;s.Ot||(e=this.$e(t,s),s.view=e),this.He(s,e,i),s.Ot=!0}}Ls(t){}}class C{constructor(t){this.parent=null,this.view=null,this.parent=t}Vs(){}update(){}ns(){if(!this.view?.view)throw Error("View is not mounted. Did you forget to set this.view?");return this.view.view}}class A extends C{constructor(){super(...arguments),this.view=null}Vs(){const t=s.m(7);this.view=s.H({Fe:{tag:{node:"div",classList:["selective-ui-group"],role:"group",A:`seui-${t}-header`,id:`seui-${t}-group`},j:{Ie:{tag:{node:"div",classList:["selective-ui-group-header"],role:"presentation",id:`seui-${t}-header`}},Ve:{tag:{node:"div",classList:["selective-ui-group-items"],role:"group"}}}}}),this.parent.appendChild(this.view.view)}update(){this.Gi()}Gi(t=null){this.view&&null!==t&&(this.view.tags.Ie.textContent=t)}ke(){if(!this.view)throw Error("GroupView is not rendered.");return this.view.tags.Ve}Ki(){if(!this.view)return;const t=Array.from(this.view.tags.Ve.children).filter(t=>!t.classList.contains("hide"));this.view.view.classList.toggle("hide",!(t.length>0))}Ui(t){this.view&&(this.view.view.classList.toggle("collapsed",t),this.view.tags.Ie.setAttribute("aria-expanded",t?"false":"true"))}}class S extends C{constructor(t){super(t),this.view=null,this.Re=null,this._e=null,this.De=!1,this.Ne()}Ne(){const t=this;this.Re={isMultiple:!1,hasImage:!1,imagePosition:"right",imageWidth:"60px",imageHeight:"60px",imageBorderRadius:"4px",labelValign:"center",labelHalign:"left"},this._e=new Proxy(this.Re,{set(i,s,e){if("string"!=typeof s)return!0;const n=s,h=i[n];return h!==e&&(i[n]=e,t.De&&t.Be(n,e,h)),!0}})}get isMultiple(){return this.Re.isMultiple}set isMultiple(t){this._e.isMultiple=!!t}get hasImage(){return this.Re.hasImage}set hasImage(t){this._e.hasImage=!!t}get ze(){return this._e}set ze(t){if(!t||!this._e||!this.Re)return;const i={};void 0!==t.imageWidth&&t.imageWidth!==this.Re.imageWidth&&(i.imageWidth=t.imageWidth),void 0!==t.imageHeight&&t.imageHeight!==this.Re.imageHeight&&(i.imageHeight=t.imageHeight),void 0!==t.imageBorderRadius&&t.imageBorderRadius!==this.Re.imageBorderRadius&&(i.imageBorderRadius=t.imageBorderRadius),void 0!==t.imagePosition&&t.imagePosition!==this.Re.imagePosition&&(i.imagePosition=t.imagePosition),void 0!==t.labelValign&&t.labelValign!==this.Re.labelValign&&(i.labelValign=t.labelValign),void 0!==t.labelHalign&&t.labelHalign!==this.Re.labelHalign&&(i.labelHalign=t.labelHalign),Object.keys(i).length>0&&Object.assign(this._e,i)}Vs(){const t=["selective-ui-option-view"],i=s.m(7),e="option_"+i;this.Re.isMultiple&&t.push("multiple"),this.Re.hasImage&&(t.push("has-image"),t.push("image-"+this.Re.imagePosition));const n={hs:{tag:{node:"input",type:this.Re.isMultiple?"checkbox":"radio",classList:"allow-choice",id:e}},...this.Re.hasImage&&{ds:{tag:{node:"img",classList:"option-image",style:{width:this.Re.imageWidth,height:this.Re.imageHeight,borderRadius:this.Re.imageBorderRadius}}}},Ge:{tag:{node:"label",htmlFor:e,classList:["align-vertical-"+this.Re.labelValign,"align-horizontal-"+this.Re.labelHalign]},j:{us:{tag:{node:"div"}}}}};this.view=s.H({Ue:{tag:{node:"div",id:`seui-${i}-option`,classList:t,role:"option",ariaSelected:"false",tabIndex:"-1"},j:n}}),this.parent.appendChild(this.view.view),this.De=!0}Be(t,i,s){const e=this.view;if(!e||!e.view)return;const n=e.view,h=e.tags?.hs,o=e.tags?.Ge;switch(t){case"isMultiple":{const t=!!i;n.classList.toggle("multiple",t),h&&h.type!==(t?"checkbox":"radio")&&(h.type=t?"checkbox":"radio");break}case"hasImage":{const t=!!i;if(n.classList.toggle("has-image",t),t)n.classList.add("image-"+this.Re.imagePosition),this.We();else{n.className=n.className.replace(/image-(top|right|bottom|left)/g,"").trim();const t=e.tags?.ds;t&&(t.remove(),e.tags.ds=null)}break}case"imagePosition":this.Re.hasImage&&(n.className=n.className.replace(/image-(top|right|bottom|left)/g,"").trim(),n.classList.add("image-"+i));break;case"imageWidth":case"imageHeight":case"imageBorderRadius":{const s=e.tags?.ds;if(s){const e="imageWidth"===t?"width":"imageHeight"===t?"height":"borderRadius",n=i+"";s.style[e]!==n&&(s.style[e]=n)}break}case"labelValign":case"labelHalign":if(o){const t=`align-vertical-${this.Re.labelValign} align-horizontal-${this.Re.labelHalign}`;o.className!==t&&(o.className=t)}}}We(){const t=this.view;if(!t||!t.view)return;const i=t.tags?.ds;if(i)return;const s=t.view,e=t.tags?.Ge,n=document.createElement("img");n.className="option-image",n.style.width=this.Re.imageWidth,n.style.height=this.Re.imageHeight,n.style.borderRadius=this.Re.imageBorderRadius,e&&e.parentElement?s.insertBefore(n,e):s.appendChild(n),t.tags.ds=n}}class L extends O{constructor(t=[]){super(t),this.isMultiple=!1,this.qe=[],this.Je=-1,this.Ke=null,this.groups=[],this.Qe=[],this.Ye()}Ye(){this.Qe=[],this.groups=[],this.items.forEach(t=>{t instanceof f?(this.groups.push(t),this.Qe.push(...t.items)):t instanceof m&&this.Qe.push(t)})}$e(t,i){return i instanceof f?new A(t):new S(t)}He(t,i,s){t.position=s,t instanceof f?this.Xe(t,i,s):t instanceof m&&this.Ze(t,i,s),t.Ot=!0}Xe(t,i,s){super.He(t,i,s),t.view=i;const e=i.view.tags.Ie;e.textContent=t.label,t.Ot||(e.style.cursor="pointer",e.addEventListener("click",()=>{t.qi()}),t.Wi((t,i,s)=>{i.items.forEach(t=>{const i=t.view?.ns?.();i&&(i.style.display=s?"none":"")}),this.tn(i,s)}));const n=i.ke();t.items.forEach((t,i)=>{let s=t.view;t.Ot&&s||(s=new S(n)),this.Ze(t,s,i),t.Ot=!0}),i.Ui(t.collapsed),i.Ki()}Ze(t,i,s){if(i.isMultiple=this.isMultiple,i.hasImage=t.hasImage,i.ze={imageWidth:t.options.imageWidth,imageHeight:t.options.imageHeight,imageBorderRadius:t.options.imageBorderRadius,imagePosition:t.options.imagePosition,labelValign:t.options.labelValign,labelHalign:t.options.labelHalign},t.Ot||super.He(t,i,s),t.view=i,t.hasImage){const s=i.view.tags.ds;s&&(s.src!==t.ss&&(s.src=t.ss),s.alt!==t.text&&(s.alt=t.text))}i.view.tags.us.innerHTML=t.text,t.Ot||(i.view.tags.Ue.addEventListener("click",i=>{i.stopPropagation(),i.preventDefault(),this.Ps||(this.isMultiple?(this.$s("select"),setTimeout(()=>{t.selected=!t.selected},5)):!0!==t.selected&&(this.$s("select"),setTimeout(()=>{this.Ke&&(this.Ke.selected=!1),t.selected=!0},5)))}),i.view.tags.Ue.title=t.textContent,i.view.tags.Ue.addEventListener("mouseenter",()=>{this.Ps||this.sn(this.Qe.indexOf(t),!1)}),t.ls(()=>{this.Es("selected")}),t.cs((i,s,e)=>{e&&(this.Ke=t),this.Es("selected_internal")}),t.ni((t,i)=>{i.group?.Ki(),this.en()})),t.selected&&(this.Ke=t,t.es=!0)}Ee(t){this.$s("items",t),this.items=t,this.Ye(),this.Es("items",t)}As(t){this.Ee(t)}Ls(t){this.items=t,this.Ye()}nn(){return this.Qe.filter(t=>t.selected)}hn(){return this.Qe.find(t=>t.selected)}Kt(t){this.isMultiple&&this.Qe.forEach(i=>{i.selected=t})}ni(t){this.qe.push(t)}en(){const t=this.Qe.filter(t=>t.visible).length,i=this.Qe.length;this.qe.forEach(s=>{s({rn:t,ln:i,Zt:t>0,isEmpty:0===i})})}ti(){const t=this.Qe.filter(t=>t.visible).length,i=this.Qe.length;return{rn:t,ln:i,Zt:t>0,isEmpty:0===i}}an(){this.sn(0)}navigate(t,i=!0){const s=this.Qe.filter(t=>t.visible);if(0===s.length)return;let e=s.findIndex(t=>t===this.Qe[this.Je]);-1===e&&(e=-1);let n=e+t;n>=s.length&&(n=0),n<0&&(n=s.length-1);const h=this.Qe.indexOf(s[n]);this.sn(h,i)}cn(){if(this.Je>-1&&this.Qe[this.Je]){const t=this.Qe[this.Je];if(t.visible){const i=t.view?.ns?.();i&&i.click()}}}sn(t,i=!0){let s=0;if("number"==typeof t)s=t;else if(t instanceof m){const i=this.Qe.indexOf(t);s=i>-1?i:0}else s=0;this.Je>-1&&this.Qe[this.Je]&&(this.Qe[this.Je].rs=!1);for(let t=s;t<this.Qe.length;t++){const s=this.Qe[t];if(s.visible){if(s.rs=!0,this.Je=t,i){const t=s.view?.ns?.();t&&t.scrollIntoView({un:"center",behavior:"smooth"})}return void this.dn(t,s.view?.ns?.()?.id)}}}dn(t,i){}tn(t,i){}}class P{constructor(t=null,i=null){this.container={},this.oldValue=null,this.node=null,this.options=null,this.pn=null,this.isOpen=!1,this.gn=!1,this.fn=!1,this.mn=null,t&&this.init(t,i)}get isDisabled(){return!!this.options?.disabled}set isDisabled(t){this.options&&this.node&&(this.options.disabled=t,this.node.classList.toggle("disabled",t),this.node.setAttribute("aria-disabled",t+""),this.container.tags?.mi?.setAttribute("aria-disabled",t+""))}get bn(){return!!this.options?.readonly}set bn(t){this.options&&this.node&&(this.options.readonly=t,this.node.classList.toggle("readonly",t))}get isVisible(){return!!this.options?.visible}set isVisible(t){this.options&&this.node&&(this.options.visible=t,this.node.classList.toggle("invisible",!t))}init(i,e){const r=s.R(i).options,l=new h(r),a=new o,c=new d(r),effector=t(),p=new b(r),g=new y(r),f=new v(i,p),m=new x(i),O=new T(i);this.mn=e,this.options=r,l.node&&(l.node.id=(r.wn??"")+"");const C=s.$({yn:{tag:{node:"div",classList:"selective-ui-MAIN"},j:{mi:{tag:{node:"div",classList:"selective-ui-view",tabIndex:0,onkeydown:t=>{"Enter"!==t.key&&" "!==t.key&&"ArrowDown"!==t.key||(t.preventDefault(),this.vn()?.open())}},j:{xn:{tag:l.node},Tn:{tag:a.node},ji:{tag:c.node}}}}}},null);this.container=C,this.node=C.view,i.parentNode?.insertBefore(this.node,i),this.node.insertBefore(i,C.tags.mi),g.Bs(C.tags.mi),g.Gs(p),C.tags.mi.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()}),n.lt(i,C.tags.mi),i.classList.add("init"),p.ws(L),p.vs(w),p.Cs(s.K(i)),p.onUpdated=()=>{C.On?.ii?.()},this.pn=p,C.Cn=f,C.placeholder=l,C.An=a,C.Sn=c,C.effector=effector,C.targetElement=i,C.Ln=g,C.Pn=m,C.Mn=O,C.On=new u(i,r,p),C.On.ai(effector),C.On.bi(f,r),C.On.li("selected",()=>{this.vn()?.change(null,!0)}),C.On.li("selected_internal",()=>{this.vn()?.change(null,!1)}),C.On.oi("select",()=>{this.oldValue=this.vn()?.value??""}),this.vn()?.change(null,!1),m.connect(),m.Pt=t=>{p.update(s.K(t)),this.vn()?.refreshMask()},O.connect(),O.Pt=t=>{s.V(t.disabled)!==this.isDisabled&&(this.isDisabled=s.V(t.disabled)),s.V(t.readonly)!==this.bn&&(this.bn=s.V(t.readonly)),s.V(t.visible)!==this.isVisible&&(this.isVisible=s.V(t.visible??"1"))},i.addEventListener("options:changed",()=>{p.update(s.K(i)),this.vn()?.refreshMask(),C.On?.ii?.()}),r.ajax&&f.ae(r.ajax);const A=C.On.Ht,S=(t,i)=>{i||""!==t?(""!==t&&(this.fn=!0),f.search(t).then(t=>{C.On?.ii?.(),t?.ge&&setTimeout(()=>{A.an()},r.animationtime??0)}).catch(t=>{console.error("Search error:",t)})):f.clear()};let P=null;c.Pi=(t,i)=>{f.pe(t)&&(f.ie()?(P&&clearTimeout(P),C.On?.Yt?.(),P=setTimeout(()=>{S(t,i)},r.delaysearchtime??0)):S(t,i))},f.setPopup(C.On),c.Mi=t=>{A.navigate(t)},c.Hi=()=>{A.cn()},c.$i=()=>{this.vn()?.close(),C.tags.mi.focus()},A.dn=(t,i)=>{i&&c.Fi(i)},A.tn=()=>{C.On?.ii?.()},this.isDisabled=s.V(r.disabled),this.bn=s.V(r.readonly)}Hn(){const t=this.container??{},{Pn:i,Mn:s}=t;i?.disconnect&&i.disconnect(),s?.disconnect&&s.disconnect()}vn(){const t=this.container,i=this,n=s.R(t.targetElement);if(!n)return null;const h=n.options,o={get placeholder(){return t.placeholder.get()},set placeholder(i){t.placeholder?.set(i),t.Sn?.Ei(i)},get oldValue(){return i.oldValue},set value(t){this.setValue(null,t,!0)},get value(){const t=this.valueArray,i=t.length;return i>1?t:0===i?"":t[0]},get valueArray(){const t=[];return i.$n().forEach(i=>{i.selected&&t.push(i.value)}),t},get valueString(){return this.valueArray.join(h.customDelimiter)},get valueOptions(){const t=[];return i.$n().forEach(i=>{i.selected&&t.push(i)}),t},get mask(){const t=[];return i.$n().forEach(i=>{i.selected&&t.push(i.text)}),t},get valueText(){const t=[];i.$n().forEach(i=>{i.selected&&t.push(i.text)});const s=t.length;return s>1?t:0===s?"":t[0]},get isOpen(){return i.isOpen},selectAll(t,s=!0){if(!(h.multiple&&h.maxSelected>0&&i.$n().length>h.maxSelected)&&!this.disabled&&!this.readonly&&h.multiple){if(s){if(e.ht([this],...h.on.beforeChange).isCancel)return;i.oldValue=this.value}i.$n().forEach(t=>{t.es=!0}),this.change(!1,s)}},deSelectAll(t,s=!0){if(!this.disabled&&!this.readonly&&h.multiple){if(s){if(e.ht([this],...h.on.beforeChange).isCancel)return;i.oldValue=this.value}i.$n().forEach(t=>{t.es=!1}),this.change(!1,s)}},setValue(s=null,n,o=!0,r=!1){if(Array.isArray(n)||(n=[n]),0===(n=n.filter(t=>""!==t&&null!=t)).length)return i.$n().forEach(t=>t.es=!1),void this.change(!1,o);if(h.multiple&&h.maxSelected>0&&n.length>h.maxSelected)console.warn(`Cannot select more than ${h.maxSelected} items`);else if(r||!this.disabled&&!this.readonly){if(t.Cn?.ie?.()){const{le:s}=t.Cn.oe(n);if(s.length>0)return void(async()=>{h.loadingfield&&t.On?.Yt?.();try{const e=await t.Cn.se(s);e.Oi&&e.items.length>0?(e.items.forEach(t=>{s.includes(t.value)&&(t.selected=!0)}),t.Cn.be?.(e.items,!0,!0),setTimeout(()=>{i.$n().forEach(t=>{t.es=n.some(i=>i==t.value)}),this.change(!1,!1)},100)):s.length>0&&console.warn(`Could not load ${s.length} values:`,s)}catch(t){console.error("Error loading missing values:",t)}finally{h.loadingfield&&t.On?.si?.()}})()}if(o){if(e.ht([this],...h.on.beforeChange).isCancel)return;i.oldValue=this.value}i.$n().forEach(t=>{t.es=n.some(i=>i==t.value)}),!h.multiple&&n.length>0&&(t.targetElement.value=n[0]),this.change(!1,o)}},open(){if(i.isOpen)return!1;const s=i.mn?.find?.();if(s&&!s.isEmpty&&s.close().isCancel)return!1;if(this.disabled)return!1;if(e.ht([this],...h.on.beforeShow).isCancel)return!1;i.isOpen=!0,t.An.dt(!0);const n=t.On.Ht,o=n.hn();o?n.sn(o,!1):n.an(),i.gn&&!i.fn||!h?.ajax||(t.On.Yt(),i.gn=!0,i.fn=!1,setTimeout(()=>{t.On&&t.Cn&&t.Cn.search("").then(()=>t.On?.ii?.()).catch(t=>console.error("Initial ajax load error:",t))},h.animationtime)),t.On.open(),t.Sn.show();const r=t.tags.mi;return r.setAttribute("aria-expanded","true"),r.setAttribute("aria-controls",h.Gt),r.setAttribute("aria-haspopup","listbox"),r.setAttribute("aria-labelledby",h.wn),h.multiple&&r.setAttribute("aria-multiselectable","true"),e.ht([this],...h.on.show),!0},close(){return!!i.isOpen&&!e.ht([this],...h.on.beforeClose).isCancel&&(i.isOpen=!1,t.An.dt(!1),t.On.close(()=>{t.Sn.clear(!1)}),t.Sn.hide(),t.tags.mi.setAttribute("aria-expanded","false"),e.ht([this],...h.on.close),!0)},toggle(){i.isOpen?this.close():this.open()},change(s=null,n=!0){if(n){if(h.multiple&&h.maxSelected>0&&this.valueArray.length>h.maxSelected&&this.setValue(null,this.oldValue,!1,!0),this.disabled||this.readonly)return void this.setValue(null,this.oldValue,!1,!0);if(e.ht([this,this.value],...h.on.beforeChange).isCancel)return void this.setValue(null,this.oldValue,!1)}this.refreshMask(),t.Ln.Us(this.valueOptions),n&&(t.targetElement&&e.ot(t.targetElement,"change"),e.ht([this,this.value],...h.on.change),i.options?.autoclose&&this.close())},refreshMask(){let s=h.placeholder;!h.multiple&&i.$n().length>0&&(s=this.mask[0]),s??(s=h.placeholder),t.placeholder.set(s,!1),t.Sn.Ei(s)},on(t,i,s){h.on[i]||(h.on[i]=[]),h.on[i].push(s)},ajax(i,s){t.Cn.ae(s)}};return this.jn(o,"disabled","isDisabled"),this.jn(o,"readonly","isReadOnly"),this.jn(o,"visible","isVisible"),o}jn(t,i,s){const e=this;Object.defineProperty(t,i,{get:()=>e[s],set(t){e[s]=!!t,e.container?.targetElement?.dataset&&(e.container.targetElement.dataset[i]=!!t+"")},enumerable:!0,configurable:!0})}$n(t=null){if(!this.pn)return[];const{Ms:i}=this.pn.qt(),s=[];for(const t of i)t instanceof m?s.push(t):t instanceof f&&Array.isArray(t.items)&&t.items.length&&s.push(...t.items);return"boolean"==typeof t?s.filter(i=>i.selected===t):s}Ci(){this.container.On.Ci()}}class M{constructor(){this.En=!1,this.Oe=null,this.Fn=[]}In(t){this.Fn.push(t)}Vn(){this.Fn=[]}start(t){if(this.En)return;this.En=!0;const i=t.toUpperCase(),s=t.toLowerCase();this.Oe=new MutationObserver(t=>{for(const e of t)e.addedNodes.forEach(t=>{if(1!==t.nodeType)return;const e=t;e.tagName===i&&this.kn(e),e.querySelectorAll(s).forEach(t=>this.kn(t))})}),this.Oe.observe(document.body,{childList:!0,subtree:!0})}stop(){this.En&&(this.En=!1,this.Oe?.disconnect(),this.Oe=null)}kn(t){this.Fn.forEach(i=>i(t))}}class H{constructor(){this.Rn=new Map}bind(t,i){const n=s.I(s.G(),i);n.on=n.on??{},n.on.load=n.on.load??[],this.Rn.set(t,n);const h=s.m();s.Z.on(h,()=>{e.ht([this.find(t)],...n.on.load),s.Z.clear(h),n.on.load=[]}),s.v(t).forEach(t=>{(async()=>{"SELECT"===t.tagName&&(s.D(t),this._n(t,n)&&s.Z.run(h))})()}),s.U().includes(t)||s.U().push(t)}find(t="*"){const i={isEmpty:!0};if("*"===t&&""===(t=s.U().join(", ")))return i;const e=s.v(t);if(0===e.length)return i;const n=s.R(e[0]);if(!n||!n.action)return i;const h={};for(const t in n.action)h[t]=this.Dn(t,n.action);const o={isEmpty:!1};for(const t in h){const i=h[t];switch(i.type){case"get-set":this.Nn(o,i.name,e);break;case"func":this.Bn(o,i.name,e)}}return o}zn(){this.Gn=new M,this.Gn.In(t=>{this.Rn.forEach((i,s)=>{try{t.matches(s)&&this._n(t,i)}catch(t){console.warn("Invalid selector: "+s,t)}})}),this.Gn.start("select")}destroy(t=null){null===t?this.Un():"string"==typeof t?this.Wn(t):t instanceof HTMLSelectElement&&this.qn(t)}Un(){s.U().forEach(t=>this.Wn(t)),this.Rn.clear(),s.U().length=0,this.Gn?.stop()}Wn(t){s.v(t).forEach(t=>{"SELECT"===t.tagName&&this.qn(t)}),this.Rn.delete(t);const i=s.U(),e=i.indexOf(t);e>-1&&i.splice(e,1)}qn(t){const i=s.R(t);if(!i)return;const e=i.container?.On;e?.Ci(),s.B(t,i);const n=!!this.Gn;n&&this.Gn?.stop();try{i.self?.Hn?.()}catch(t){}const h=i.container?.element??t.parentElement;t.style.display="",t.style.visibility="",t.disabled=!1,delete t.dataset.Jn,h&&h.parentNode?h.parentNode.replaceChild(t,h):document.body.appendChild(t),s.k(t),n&&this.Rn.size>0&&this.Gn?.start("select")}rebind(t,i){this.Wn(t),this.bind(t,i)}_n(t,i){if(s.R(t)||s.N(t))return!1;const e=s.m(8),n=s.F(t,i);n.Kn=e,n.Gt=`seui-${e}-optionlist`,n.wn=`seui-${e}-placeholder`;const h={options:n};s._(t,h);const o=new P(t,this);return h.container=o.container,h.action=o.vn(),h.self=o,o.container.view.addEventListener("mouseup",()=>{h.action?.toggle?.()}),!0}Dn(t,i){const s=Object.getOwnPropertyDescriptor(i,t);let e="variable";return s?.get||s?.set&&"function"!=typeof i[t]?e="get-set":"function"==typeof i[t]&&(e="func"),{type:e,name:t}}Nn(t,i,e){Object.defineProperty(t,i,{get(){const t=s.R(e[0]);return t.action?.[i]},set(t){e.forEach(e=>{const n=s.R(e);n?.action&&(n.action[i]=t)})},enumerable:!0,configurable:!0})}Bn(t,i,n){t[i]=(...h)=>{for(let t=0;t<n.length;t++){const o=s.R(n[t]);if(!o?.action)continue;const r=e.nt();if(o.action[i](r.et,...h),!r.token.isContinue)break}return t}}}const $="1.1.4",j="SelectiveUI";if(void 0===globalThis.GLOBAL_SEUI){const F=new H;globalThis.GLOBAL_SEUI={version:$,name:j,bind:F.bind.bind(F),find:F.find.bind(F),destroy:F.destroy.bind(F),effector:t.bind(t),rebind:F.rebind.bind(F)};let I=!1;function V(){I||(I=!0,document.addEventListener("mousedown",()=>{const t=s.U();if(t.length>0){const i=F.find(t.join(", "));i.isEmpty||i.close()}}),F.zn())}"undefined"!=typeof document&&("loading"===document.readyState?document.addEventListener("DOMContentLoaded",V):V()),console.log(`[${j}] v${$} loaded successfully`)}else console.warn(`[${globalThis.GLOBAL_SEUI.name}] Already loaded (v${globalThis.GLOBAL_SEUI.version}). Using existing instance. Please remove duplicate <script> tags.`);const version=globalThis.GLOBAL_SEUI.version,E=globalThis.GLOBAL_SEUI.name;export{bind,destroy,effector,find,E as name,rebind,version};
Binary file
@@ -1,2 +1,2 @@
1
- /*! Selective UI v1.1.3 | MIT License */
2
- var t,i;t=this,i=function(t){"use strict";function i(t){return new g(t??null)}class s{constructor(){this.t={showPanel:!0,accessoryStyle:"top",multiple:!1,minWidth:"50px",width:"0px",offsetWidth:null,minHeight:"30px",height:"30px",panelHeight:"220px",panelMinHeight:"100px",disabled:!1,readonly:!1,selectall:!0,keepSelected:!0,placeholder:"Select value",altMask:"",autoclose:!1,autoscroll:!0,autofocus:!0,searchable:!0,loadingfield:!0,visible:!0,skipError:!1,customDelimiter:",",textLoading:"Processing...",textNoData:"No data available",textNotFound:"Not found",textSelectAll:"Select all",textDeselectAll:"Deselect all",textAccessoryDeselect:"Deselect: ",animationtime:200,delaysearchtime:200,allowHtml:!0,maxSelected:0,labelHalign:"left",labelValign:"center",imageMode:!1,imageWidth:"60px",imageHeight:"60px",imageBorderRadius:"4px",imagePosition:"right",ajax:null,on:{load:[],beforeShow:[],show:[],beforeChange:[],change:[],beforeClose:[],close:[]}},this.i=new Map,this.h=new Map,this.o=[]}}class e{static get l(){return this.u||(this.u=new s),this.u}static p(t){if(null===t||"object"!=typeof t)return t;const i=Array.isArray(t)?[]:{};for(const s in t)Object.prototype.hasOwnProperty.call(t,s)&&(i[s]=this.p(t[s]));return i}static m(t=6){let i="";for(let s=0;s<t;s++)i+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random()));return i}static v(t){if(!t)return[];if("string"==typeof t){const i=document.querySelectorAll(t);return Array.from(i)}return t instanceof Element?[t]:t instanceof NodeList||Array.isArray(t)?Array.from(t):[]}static T(t={}){return this.O(document.createElement(t.node??"div"),t,!0)}static O(t=document.documentElement,i=null,s=!1){const e={...i??{}},n=s?t:this.C(t.cloneNode(!0)),h=e.classList;return"string"==typeof h?n.classList.add(h):Array.isArray(h)&&n.classList.add(...h),delete e.classList,["style","dataset"].forEach(t=>{const i=e[t];i&&"object"==typeof i&&Object.assign(n[t],i),delete e[t]}),e.role&&(n.setAttribute("role",e.role+""),delete e.role),e.ariaLive&&(n.setAttribute("aria-live",e.ariaLive+""),delete e.ariaLive),e.A&&(n.setAttribute("aria-labelledby",e.A+""),delete e.A),e.S&&(n.setAttribute("aria-controls",e.S+""),delete e.S),e.L&&(n.setAttribute("aria-haspopup",e.L+""),delete e.L),e.P&&(n.setAttribute("aria-multiselectable",e.P+""),delete e.P),e.M&&(n.setAttribute("aria-autocomplete",e.M+""),delete e.M),e.event&&"object"==typeof e.event&&(Object.entries(e.event).forEach(([t,i])=>{n.addEventListener(t,i)}),delete e.event),Object.entries(e).forEach(([t,i])=>{null===i?n.removeAttribute(t):n[t]=i}),n}static C(t){if(t instanceof Element)return t;throw new TypeError("Node is not an Element")}static H(t){return this.$(t)}static $(t,i=null,s=!1,e=!1,n={}){let h=null;for(const o in t){const r=t[o],l=r?.tag?.tagName?r.tag:this.T(r.tag);n[o]=l,r?.j&&this.$(r.j,l,!1,!1,n),i?s?i.prepend(l):i.append(l):e||h||(h=l)}return e||(n.id=this.m(7),i||(n={tags:n,view:h})),n}static F(t,i){const s=this.p(i);for(const e in s){const i=t[e];i?s[e]=i:void 0!==t?.dataset?.[e]&&(s[e]=t.dataset[e])}return s}static I(...t){if(0===t.length)return{};if(1===t.length)return this.p(t[0]);const i=this.p(t[0]);for(let s=1;s<t.length;s++){const e=t[s];for(const t in e)if("on"===t){const s=e[t];for(const e in s)i[t][e].push(s[e])}else i[t]=e[t]}return i}static V(t){if("boolean"==typeof t)return t;if("string"!=typeof t)return!!t;switch(t.trim().toLowerCase()){case"true":case"1":case"yes":case"on":return!0;default:return!1}}static k(t){return this.l.i.delete(t)}static R(t){return this.l.i.get(t)}static _(t,i){this.l.i.set(t,i)}static D(t){return this.l.h.delete(t)}static N(t){return this.l.h.get(t)}static B(t,i){this.l.h.set(t,i)}static G(){return this.l.t}static U(){return this.l.o}static W(t){if(null==t)return"";let i=(t+"").replace(/<`/g,"<").replace(/`>/g,">").replace(/\<\`/g,"<").replace(/\`\>/g,">").trim();const s=globalThis?.document;if(!s||"function"!=typeof s.createElement)return i=i.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"").replace(/<iframe\b[^>]*>[\s\S]*?<\/iframe>/gi,"").replace(/<(object|embed|link)\b[^>]*>[\s\S]*?<\/\1>/gi,""),i=i.replace(/\son[a-z]+\s*=\s*(['"]).*?\1/gi,""),i=i.replace(/\s([a-z-:]+)\s*=\s*(['"])\s*javascript:[^'"]*\2/gi,""),i;const e=s.createElement("div");return e.innerHTML=i,e.querySelectorAll("script, style, iframe, object, embed, link").forEach(t=>t.remove()),e.querySelectorAll("*").forEach(t=>{for(const i in t.attributes){const s=t.attributes[i],e=s.name??"",n=s.value??"";if(/^on/i.test(e))return void t.removeAttribute(e);/^(href|src|xlink:href)$/i.test(e)&&/^javascript:/i.test(n)&&t.removeAttribute(e)}}),(e.innerHTML??"").trim()}static q(t){const i=document.createElement("DIV");i.innerHTML=t;const s=i.textContent??i.innerText??"";return i.remove(),s.trim()}static J(t){return null==t?"":(t+"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/đ/g,"d").replace(/Đ/g,"d")}static K(t){const i=[];return Array.from(t.children).forEach(t=>{if("OPTGROUP"===t.tagName){const s=t;i.push(s),Array.from(s.children).forEach(t=>{t.__parentGroup=s,i.push(t)})}else"OPTION"===t.tagName&&i.push(t)}),i}static Y(){const t=navigator.userAgent;return/iP(hone|ad|od)/.test(t)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1}static X(t){const i=(t+"").trim();if(i.endsWith("px"))return i;if(i.endsWith("vh"))return window.innerHeight*parseFloat(i)/100+"px";if(i.endsWith("vw"))return window.innerWidth*parseFloat(i)/100+"px";const s=parseFloat(getComputedStyle(document.documentElement).fontSize);if(i.endsWith("rem"))return s*parseFloat(i)+"px";const e=this.T({node:"div",style:{height:i,opacity:"0"}});document.body.appendChild(e);const n=e.offsetHeight+"px";return e.remove(),n}}e.u=null,e.Z=new class{constructor(){this.tt=new Map,this.it=new Map}on(t,i,s={}){const e=s.st??50,n=s.once??!1;this.tt.has(t)||this.tt.set(t,[]),this.tt.get(t).push({et:i,timeout:e,once:n})}off(t){const i=this.it.get(t);if(i){for(const t of i.values())clearTimeout(t);i.clear(),this.it.delete(t)}this.tt.delete(t)}run(t,...i){const s=this.tt.get(t);if(!s)return;this.it.has(t)||this.it.set(t,new Map);const e=this.it.get(t);for(let n=0;n<s.length;n++){const t=s[n];if(!t)continue;const h=e.get(n);h&&clearTimeout(h);const o=setTimeout(()=>{if(t.et(i.length>0?i:null),t.once){s[n]=void 0;const t=e.get(n);t&&clearTimeout(t),e.delete(n)}},t.timeout);e.set(n,o)}}clear(t){if(void 0===t)for(const i of Array.from(this.tt.keys()))this.off(i);else this.off(t)}};class n{static nt(){const t={isContinue:!0,isCancel:!1};return{token:{get isContinue(){return t.isContinue},get isCancel(){return t.isCancel}},et:{stopPropagation(){t.isContinue=!1},cancel(){t.isCancel=!0,t.isContinue=!1}}}}static ht(t,...i){const{token:s,et:e}=this.nt();for(let n=0;n<i.length;n++){const h=i[n];if("function"==typeof h&&(t&&Array.isArray(t)?h(e,...t):h(e),s.isCancel||!s.isContinue))break}return s}static ot(t,i,s={bubbles:!0,cancelable:!0}){const e=new Event(i,s);return t.dispatchEvent(e),e}static rt(t,...i){if(Array.isArray(t))for(const s of t)"function"==typeof s&&s(...i)}}class h{static lt(t,i){const s=e.R(t);if(!s?.options)return;const n=s.options,h=n.minWidth,o=n.minHeight,r=Number.parseInt(n.width,10),l=Number.parseInt(n.height,10);let a=t.offsetWidth+"px",c=t.offsetHeight+"px";const u=getComputedStyle(t);"0px"===a&&"auto"!==u.width&&(a=u.width),"0px"===c&&"auto"!==u.height&&(c=u.height),r>0&&(a=n.width),l>0&&(c=n.height),Object.assign(i.style,{width:a,height:c,minWidth:h,minHeight:o})}}class o{constructor(t){this.node=null,this.ct=null,t&&this.init(t)}init(t){this.node=e.T({node:"div",classList:"selective-ui-placeholder",innerHTML:t.placeholder}),this.ct=t}get(){return this.ct?.placeholder??""}set(t,i=!0){if(!this.node||!this.ct)return;i&&(this.ct.placeholder=t);const s=e.W(t);this.node.innerHTML=this.ct.allowHtml?s:e.q(s)}}class r{constructor(){this.node=this.ut()}ut(){return e.T({node:"div",classList:"selective-ui-directive",role:"button",ariaLabel:"Toggle dropdown"})}dt(t){this.node.classList.toggle("drop-down",!!t)}}class l{constructor(t=null){this.gt=null,this.node=null,this.options=null,this.ft=[],this.bt=[],t&&this.init(t)}init(t){this.gt=e.$({wt:{tag:{node:"div",classList:["selective-ui-option-handle","hide"]},j:{yt:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textSelectAll,onclick:()=>{n.rt(this.ft)}}},vt:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textDeselectAll,onclick:()=>{n.rt(this.bt)}}}}}}),this.node=this.gt.view,this.options=t}available(){return!!this.options&&e.V(this.options.multiple)&&e.V(this.options.selectall)}refresh(){this.node&&(this.available()?this.show():this.hide())}show(){this.node&&this.node.classList.remove("hide")}hide(){this.node&&this.node.classList.add("hide")}xt(t=null){"function"==typeof t&&this.ft.push(t)}Tt(t=null){"function"==typeof t&&this.bt.push(t)}}class a{constructor(t=null){this.node=null,this.options=null,t&&this.init(t)}init(t){this.options=t,this.node=e.T({node:"div",classList:["selective-ui-empty-state","hide"],role:"status",ariaLive:"polite"})}show(t="nodata"){this.node&&this.options&&(this.node.textContent="notfound"===t?this.options.textNotFound:this.options.textNoData,this.node.classList.remove("hide"))}hide(){this.node&&this.node.classList.add("hide")}get isVisible(){return!!this.node&&!this.node.classList.contains("hide")}}class c{constructor(t=null){this.node=null,this.options=null,t&&this.init(t)}init(t){this.options=t,this.node=e.T({node:"div",classList:["selective-ui-loading-state","hide"],textContent:t.textLoading,role:"status",ariaLive:"polite"})}show(t){this.node&&this.options&&(this.node.textContent=this.options.textLoading,this.node.classList.toggle("small",!!t),this.node.classList.remove("hide"))}hide(){this.node&&this.node.classList.add("hide")}get isVisible(){return!!this.node&&!this.node.classList.contains("hide")}}class u{constructor(){this.Ot=!1,this.element=null,this.Ct=null,this.At=null,this.Ot=!0,this.St=this.Lt.bind(this)}Pt(t){}Lt(){const t=this.element;if(!t||"function"!=typeof t.getBoundingClientRect)return void this.Pt({width:0,height:0,top:0,left:0,padding:{top:0,right:0,bottom:0,left:0},border:{top:0,right:0,bottom:0,left:0},margin:{top:0,right:0,bottom:0,left:0}});const i=t.getBoundingClientRect(),s="undefined"!=typeof window&&"function"==typeof window.getComputedStyle?window.getComputedStyle(t):null;this.Pt({width:i?.width??0,height:i?.height??0,top:i?.top??0,left:i?.left??0,padding:{top:parseFloat(s?.paddingTop??"0"),right:parseFloat(s?.paddingRight??"0"),bottom:parseFloat(s?.paddingBottom??"0"),left:parseFloat(s?.paddingLeft??"0")},border:{top:parseFloat(s?.borderTopWidth??"0"),right:parseFloat(s?.borderRightWidth??"0"),bottom:parseFloat(s?.borderBottomWidth??"0"),left:parseFloat(s?.borderLeftWidth??"0")},margin:{top:parseFloat(s?.marginTop??"0"),right:parseFloat(s?.marginRight??"0"),bottom:parseFloat(s?.marginBottom??"0"),left:parseFloat(s?.marginLeft??"0")}})}ot(){this.Lt()}connect(t){if(!(t instanceof Element))throw Error("Invalid element");this.element=t,this.Ct=new ResizeObserver(this.St),this.Ct.observe(t),this.At=new MutationObserver(this.St),this.At.observe(t,{attributes:!0,attributeFilter:["style","class"]}),window.addEventListener("scroll",this.St,!0),window.addEventListener("resize",this.St),window.visualViewport&&(window.visualViewport.addEventListener("resize",this.St),window.visualViewport.addEventListener("scroll",this.St))}disconnect(){this.Ct?.disconnect(),this.At?.disconnect(),this.Pt=()=>{},window.removeEventListener("scroll",this.St,!0),window.removeEventListener("resize",this.St),window.visualViewport&&(window.visualViewport.removeEventListener("resize",this.St),window.visualViewport.removeEventListener("scroll",this.St)),this.Ct=null,this.At=null,this.element=null}}class d{constructor(t=null,i=null,s=null){this.options=null,this.Mt=!1,this.Ht=null,this.node=null,this.$t=null,this.jt=null,this.Et=null,this.Ft=null,this.It=null,this.Vt=null,this.kt=null,this.Rt=null,this._t=null,this.Dt=null,this.Nt=s,t&&i&&this.init(t,i)}init(t,i){if(!this.Nt)throw Error("Popup requires a ModelManager instance.");this.Ft=new l(i),this.It=new a(i),this.Vt=new c(i);const s=e.$({Bt:{tag:{node:"div",classList:"selective-ui-popup",style:{maxHeight:i.panelHeight}},j:{wt:{tag:this.Ft.node},zt:{tag:{id:i.Gt,node:"div",classList:"selective-ui-options-container",role:"listbox"}},Ut:{tag:this.Vt.node},Wt:{tag:this.It.node}}}},null);this.node=s.view,this.Rt=s.tags.zt,this.Et=e.R(t),this.options=i,this.Nt.load(this.Rt,{isMultiple:i.multiple});const n=this.Nt.qt();this.Ht=n.Jt,this.kt=n.kt,this.Ft.xt(()=>{n.Jt.Kt(!0)}),this.Ft.Tt(()=>{n.Jt.Kt(!1)}),this.Qt()}async Yt(){this.options&&this.Vt&&this.Ft&&this.Ht&&this.Nt&&(this.Dt&&clearTimeout(this.Dt),this.Nt.Xt(!0),!1!==e.V(this.options.loadingfield)&&(this.Vt.show(this.Ht.ti().Zt),this.Ft.hide(),this.ii()))}async si(){this.options&&this.Vt&&this.Ht&&this.Nt&&(this.Dt&&clearTimeout(this.Dt),this.Dt=setTimeout(()=>{this.Nt?.Xt(!1),this.Vt?.hide();const t=this.Ht?.ti();this.ei(t??void 0),this.ii()},200))}Qt(){this.Ht&&(this.Ht.ni(t=>{this.ei(t)}),this.Ht.hi("items",()=>{const t=this.Ht.ti();this.ei(t),this.ii()}))}ei(t){if(!(this.Ht&&this.It&&this.Ft&&this.Rt))return;const i=t??this.Ht.ti();i.isEmpty?(this.It.show("nodata"),this.Rt.classList.add("hide"),this.Ft.hide()):i.Zt?(this.It.hide(),this.Rt.classList.remove("hide"),this.Ft.refresh()):(this.It.show("notfound"),this.Rt.classList.add("hide"),this.Ft.hide())}oi(t,i){this.Ht?.ri(t,i)}li(t,i){this.Ht?.hi(t,i)}ai(t){this.$t=t}open(t=null){if(!(this.node&&this.options&&this.Ft&&this.Et&&this.$t))return;this.Mt||(document.body.appendChild(this.node),this.Mt=!0,this.jt=new u,this.$t.ci(this.node),this.node.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()})),this.Ft.refresh(),this.ei();const i=this.ui(),{position:s,top:e,maxHeight:n,di:h}=this.pi(i);this.$t.expand({duration:this.options.animationtime,display:"flex",width:i.width,left:i.left,top:e,maxHeight:n,di:h,position:s,gi:()=>{this.jt&&this.Et&&(this.jt.Pt=()=>{const t=this.ui();this.fi(t)},this.jt.connect(this.Et.container.tags.mi),t?.())}})}close(t=null){this.Mt&&this.options&&this.jt&&this.$t&&(this.jt.disconnect(),this.$t.collapse({duration:this.options.animationtime,gi:t??void 0}))}ii(){this.Mt&&this.jt?.ot()}bi(t,i){this.node&&(this._t=async()=>{const i=t.wi();if(!i.yi)return;const s=this.node;if(s.scrollHeight-s.scrollTop-s.clientHeight<100&&!i.xi&&i.Ti){const i=await t.Oi();!i.Ci&&i.message&&console.log("Load more:",i.message)}},this.node.addEventListener("scroll",this._t))}Ai(){this.Dt&&(clearTimeout(this.Dt),this.Dt=null),this.node&&this._t&&(this.node.removeEventListener("scroll",this._t),this._t=null);try{this.jt?.disconnect()}catch(t){}this.jt=null;try{this.$t?.ci?.(null)}catch(t){}if(this.$t=null,this.node)try{const t=this.node.cloneNode(!0);this.node.replaceWith(t),t.remove()}catch(t){this.node.remove()}this.node=null,this.Rt=null;try{this.Nt?.Xt?.(!1),this.kt?.clear?.(),this.kt=null,this.Ht=null,this.node.remove()}catch(t){}this.Nt=null,this.Ft=null,this.It=null,this.Vt=null,this.Et=null,this.options=null,this.Mt=!1}ui(){const t=this.Et.container.tags.mi,i=t.getBoundingClientRect(),s=window.getComputedStyle(t),n=window.visualViewport,h=e.Y();return{width:i.width,height:i.height,top:i.top-(n&&h?n.offsetTop:0),left:i.left-(n&&h?n.offsetLeft:0),padding:{top:parseFloat(s.paddingTop),right:parseFloat(s.paddingRight),bottom:parseFloat(s.paddingBottom),left:parseFloat(s.paddingLeft)},border:{top:parseFloat(s.borderTopWidth),right:parseFloat(s.borderRightWidth),bottom:parseFloat(s.borderBottomWidth),left:parseFloat(s.borderLeftWidth)}}}pi(t){const i=window.visualViewport,s=e.Y(),n=i?.height??window.innerHeight,h=i&&s?i.offsetTop:0,o=this.$t.Si("flex").scrollHeight,r=parseFloat(this.options?.panelHeight??"220")||220,l=parseFloat(this.options?.panelMinHeight??"100")||100,a=n-(t.top+t.height)-3,c=t.top-3;let u="bottom",d=r,p=Math.min(o,d);const g=a-15;return(p>=l?g>=l:g>=p)?(u="bottom",d=Math.min(a-15,r)):c>=Math.max(p,l)?(u="top",d=Math.min(c-15,r)):a>=c?(u="bottom",d=Math.max(a-15,l)):(u="top",d=Math.max(c-15,l)),p=Math.min(o,d),{position:u,top:"bottom"===u?t.top+t.height+3+h:t.top-p-3+h,maxHeight:d,di:p,Li:o}}fi(t){if(!this.options||!this.$t)return;const{position:i,top:s,maxHeight:e,di:n}=this.pi(t);this.$t.resize({duration:this.options.animationtime,width:t.width,left:t.left,top:s,maxHeight:e,di:n,position:i,animate:!0})}}class p{constructor(t=null){this.gt=null,this.node=null,this.Pi=null,this.Mi=null,this.options=null,this.Hi=null,this.$i=null,this.ji=null,this.options=t,t&&this.init(t)}init(t){this.gt=e.$({Ei:{tag:{node:"div",classList:["selective-ui-searchbox","hide"]},j:{Pi:{tag:{id:e.m(),node:"input",type:"search",classList:["selective-ui-searchbox-input"],placeholder:t.placeholder,role:"searchbox",S:t.Gt,M:"list"}}}}}),this.node=this.gt.view,this.Pi=this.gt.tags.Pi;let i=!1;const s=this.gt.tags.Pi;s.addEventListener("mousedown",t=>{t.stopPropagation()}),s.addEventListener("mouseup",t=>{t.stopPropagation()}),s.addEventListener("keydown",t=>{i=!1,"ArrowDown"===t.key||"Tab"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.Hi?.(1)):"ArrowUp"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.Hi?.(-1)):"Enter"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.$i?.()):"Escape"===t.key&&(t.preventDefault(),t.stopPropagation(),i=!0,this.ji?.())}),s.addEventListener("input",()=>{i||this.Mi?.(s.value,!0)})}show(){this.node&&this.Pi&&this.options&&(this.node.classList.remove("hide"),this.Pi.readOnly=!this.options.searchable,this.options.searchable&&requestAnimationFrame(()=>{this.Pi?.focus()}))}hide(){this.node&&this.node.classList.add("hide")}clear(t=!0){this.gt&&(this.gt.tags.Pi.value="",this.Mi?.("",t))}Fi(t){this.Pi&&(this.Pi.placeholder=e.q(t))}Ii(t){this.Pi&&this.Pi.setAttribute("aria-activedescendant",t)}}class g{constructor(t=null){this.Vi=null,this.ki=null,this.Ri=!1,t&&this.ci(t)}ci(t){if("string"==typeof t){const i=document.querySelector(t);return void(i instanceof HTMLElement&&(this.element=i))}this.element=t}cancel(){return this.Vi&&(clearTimeout(this.Vi),this.Vi=null),this.ki&&(clearTimeout(this.ki),this.ki=null),this.Ri=!1,this}Si(t="flex"){if(!this.element)return{width:0,height:0,scrollHeight:0};const i={display:this.element.style.display,visibility:this.element.style.visibility,position:this.element.style.position,height:this.element.style.height,width:this.element.style.width};Object.assign(this.element.style,{display:t,visibility:"hidden",position:"fixed",height:"fit-content",width:"fit-content"});const s=window.getComputedStyle(this.element),e=parseFloat(s.borderTopWidth),n=parseFloat(s.borderBottomWidth),h=this.element.scrollHeight+e+n,o=this.element.getBoundingClientRect(),r={width:o.width,height:o.height+e+n,scrollHeight:h};return Object.assign(this.element.style,i),r}expand(t){if(!this.element)return this;this.cancel(),this.Ri=!0;const{duration:i=200,display:s="flex",width:e,left:n,top:h,maxHeight:o,di:r,position:l="bottom",gi:a}=t;return Object.assign(this.element.style,{display:s,width:e+"px",left:n+"px",top:("bottom"===l?h:h+r)+"px",maxHeight:o+"px",height:"0px",opacity:"0",overflow:"hidden",transition:"none"}),this.element.classList.toggle("position-top","top"===l),this.element.classList.toggle("position-bottom","bottom"===l),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`top ${i}ms, height ${i}ms, opacity ${i}ms`,top:h+"px",height:r+"px",opacity:"1",overflow:r>=o?"auto":"hidden"}),this.Vi=setTimeout(()=>{this.element.style.transition="none",this.Ri=!1,a?.()},i)}),this}collapse(t){if(!this.element)return this;this.cancel(),this.Ri=!0;const{duration:i=200,gi:s}=t,e=this.element.offsetHeight,n=this.element.offsetTop,h=this.element.classList.contains("position-top")?"top":"bottom",o=this.element.scrollHeight-this.element.offsetHeight>0,r="top"===h?n+e:n;return requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`height ${i}ms, top ${i}ms, opacity ${i}ms`,height:"0px",top:r+"px",opacity:"0",overflow:o?"auto":"hidden"}),this.Vi=setTimeout(()=>{Object.assign(this.element.style,{display:"none",transition:"none"}),this.Ri=!1,s?.()},i)}),this}showSwipeWidth(t){if(!this.element)return this;this.cancel(),this.Ri=!0;const{duration:i=200,display:s="block",gi:e}=t;Object.assign(this.element.style,{transition:"none",display:s,width:"fit-content"});const n=this.Si(s).width;return Object.assign(this.element.style,{width:"0px"}),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`width ${i}ms`,width:n+"px",overflow:"hidden"})}),this.Vi=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:""}),this.Ri=!1,e?.()},i),this}hideSwipeWidth(t){if(!this.element)return this;this.cancel(),this.Ri=!0;const{duration:i=200,gi:s}=t,e=this.Si().width;return Object.assign(this.element.style,{transition:"none",width:e+"px"}),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`width ${i}ms`,width:"0px",overflow:"hidden"})}),this.Vi=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:"",display:""}),this.Ri=!1,s?.()},i),this}resize(t){if(!this.element)return this;this.ki&&clearTimeout(this.ki);const{duration:i=200,width:s,left:e,top:n,maxHeight:h,di:o,position:r="bottom",animate:l=!0,gi:a}=t,c=(this.element.classList.contains("position-top")?"top":"bottom")!==r,u=this.element.scrollHeight>h;return this.element.classList.toggle("position-top","top"===r),this.element.classList.toggle("position-bottom","bottom"===r),c&&(this.element.style.transition=`top ${i}ms ease-out, height ${i}ms ease-out, max-height ${i}ms ease-out;`),requestAnimationFrame(()=>{const t={width:s+"px",left:e+"px",top:n+"px",maxHeight:h+"px",height:o+"px",overflowY:u?"auto":"hidden"},r=Math.abs(this.element.offsetHeight-o);l&&(c||r>5)?t.transition=`height ${i}ms, top ${i}ms`:this.ki=setTimeout(()=>{this.element?.style&&(this.element.style.transition="none")},i),Object.assign(this.element.style,t),l&&(c||r>1)?this.ki=setTimeout(()=>{this.element.style.transition="none",c&&delete this.element.style.transition,a?.()},i):(c&&delete this.element.style.transition,a?.())}),this}get _i(){return this.Ri}}class f{get value(){return this.targetElement?.getAttribute("value")??null}constructor(t,i=null,s=null){this.targetElement=null,this.view=null,this.position=-1,this.Ot=!1,this.options=t,this.targetElement=i,this.view=s}update(t){this.targetElement=t,this.Di()}Di(){}}class m extends f{constructor(t,i){super(t,i??null,null),this.label="",this.items=[],this.collapsed=!1,this.Ni=[],i&&(this.label=i.label,this.collapsed=e.V(i.dataset?.collapsed))}get value(){return this.items.map(t=>t.value)}get Bi(){return this.items.filter(t=>t.selected)}get zi(){return this.items.filter(t=>t.visible)}get Gi(){return this.zi.length>0}update(t){this.label=t.label,this.view?.Ui(this.label)}Di(){this.view&&(this.view.Ui(this.label),this.view.Wi(this.collapsed))}qi(t){this.Ni.push(t)}Ji(){this.collapsed=!this.collapsed,this.view?.Wi(this.collapsed),n.ht([this,this.collapsed],...this.Ni)}Ki(t){this.items.push(t),t.group=this}removeItem(t){const i=this.items.indexOf(t);i>-1&&(this.items.splice(i,1),t.group=null)}Qi(){this.view?.Qi()}}class b extends f{constructor(){super(...arguments),this.Yi=[],this.Xi=[],this.Zi=[],this.ts=!0,this.ss=!1,this.group=null}get es(){return this.dataset?.imgsrc||this.dataset?.image||""}get hasImage(){return!!this.es}get value(){return this.targetElement?.value??""}get selected(){return!!this.targetElement?.selected}set selected(t){this.ns=t,n.ht([this,t],...this.Yi)}get visible(){return this.ts}set visible(t){if(this.ts===t)return;this.ts=t;const i=this.view?.hs?.();i&&i.classList.toggle("hide",!t),n.ht([this,t],...this.Zi)}get ns(){return this.selected}set ns(t){const i=this.view?.view?.tags?.rs,s=this.view?.hs?.();i&&(i.checked=t),s&&this.targetElement&&(s.classList.toggle("checked",!!t),s.setAttribute("aria-selected",t?"true":"false"),this.targetElement.toggleAttribute("selected",!!t)),this.targetElement&&(this.targetElement.selected=t),n.ht([this,t],...this.Xi)}get text(){const t=e.W(this.dataset?.mask??this.targetElement?.text??"");return this.options.allowHtml?t:e.q(t)}get textContent(){return this.options.allowHtml?e.q(this.text).trim():this.text.trim()}get dataset(){return this.targetElement?.dataset??{}}get ls(){return this.ss}set ls(t){const i=!!t,s=this.view?.hs?.();this.ss!==i&&(this.ss=i),s&&s.classList.toggle("highlight",i)}cs(t){this.Yi.push(t)}us(t){this.Xi.push(t)}ni(t){this.Zi.push(t)}Di(){if(!this.view)return;const t=this.view.view.tags.ds;t&&(this.options.allowHtml?t.innerHTML=this.text:t.textContent=this.textContent);const i=this.view.view.tags.ps;i&&this.hasImage&&(i.src=this.es,i.alt=this.text),this.targetElement&&(this.ns=this.targetElement.selected)}}class w{constructor(t){this.gs=[],this.fs=null,this.bs=null,this.ws=null,this.options=null,this.options=t}ys(t){this.vs=t}xs(t){this.Ts=t}Os(t){const i=this.Cs(t),s=i!==this.ws;return s&&(this.ws=i),s}Cs(t){return t.map(t=>{if("OPTGROUP"===t.tagName){const i=t,s=Array.from(i.children).map(t=>`${t.value}:${t.text}:${t.selected}`).join("\n");return`G:${i.label}:${s}`}return`O:${t.value}:${t.text}:${t.selected}`}).join("\n\n")}As(t){this.gs=[];let i=null;return t.forEach(t=>{if("OPTGROUP"===t.tagName)i=new m(this.options,t),this.gs.push(i);else if("OPTION"===t.tagName){const s=t,e=new b(this.options,s),n=s.__parentGroup;n&&i&&n===i.targetElement?(i.Ki(e),e.group=i):(this.gs.push(e),i=null)}}),this.gs}replace(t){this.ws=null,this.As(t),this.fs&&this.fs.Ss(this.gs),this.refresh()}notify(){this.fs&&this.refresh()}load(t,i={},s={}){this.fs=new this.vs(this.gs),Object.assign(this.fs,i),this.bs=new this.Ts(t),this.bs.Ls(this.fs),Object.assign(this.bs,s)}update(t){if(!this.Os(t))return;const i=this.gs,s=[],e=new Map,n=new Map;i.forEach(t=>{t instanceof m?e.set(t.label,t):t instanceof b&&n.set(`${t.value}::${t.textContent}`,t)});let h=null,o=0;t.forEach(t=>{if("OPTGROUP"===t.tagName){const i=t,n=e.get(i.label);n?(n.label!==i.label&&n.update(i),n.position=o,n.items=[],h=n,s.push(n),e.delete(i.label)):(h=new m(this.options,i),h.position=o,s.push(h)),o++}else if("OPTION"===t.tagName){const i=t,e=`${i.value}::${i.text}`,r=n.get(e);if(r)r.update(i),r.position=o,i.__parentGroup&&h?(h.Ki(r),r.group=h):(r.group=null,s.push(r)),n.delete(e);else{const t=new b(this.options,i);t.position=o,i.__parentGroup&&h?(h.Ki(t),t.group=h):s.push(t)}o++}}),e.forEach(t=>{t.view?.hs?.()?.remove?.()}),n.forEach(t=>{t.view?.hs?.()?.remove?.()}),this.gs=s,this.fs&&this.fs.Ps(this.gs),this.onUpdated(),this.refresh()}onUpdated(){}Xt(t){this.fs&&(this.fs.Ms=t)}refresh(){this.bs&&(this.bs.refresh(),this.onUpdated())}qt(){return{Hs:this.gs,Jt:this.fs,kt:this.bs}}$s(t){this.fs?.js(t)}Es(t){this.fs?.Fs(t)}}class y{constructor(t=null){this.Is=null,this.Jt=null,this.Is=t}Vs(t){this.Is=t}Ls(t){this.Jt=t,t.ri("items",()=>{this.clear()}),t.hi("items",()=>{this.ks()}),this.ks()}clear(){this.Is&&this.Is.replaceChildren()}ks(){this.Jt&&this.Is&&this.Jt.Rs(this.Is)}refresh(){this.ks()}}class v{constructor(t=null){this.gt=null,this.node=null,this.options=null,this._s=null,this.Ds=null,this.Ns=null,t&&this.init(t)}init(t){this.gt=e.$({Bs:{tag:{node:"div",classList:["selective-ui-accessorybox","hide"],onmouseup:t=>{t.stopPropagation()}}}}),this.node=this.gt.view,this.options=t}zs(t){this._s=t,this.Ds=t.parentElement,this.Gs()}Gs(){this.Ds&&this.node&&this._s&&this.options&&this.Ds.insertBefore(this.node,"top"===this.options.accessoryStyle?this._s:this._s.nextSibling)}Us(t){this.Ns=t}Ws(t){this.node&&this.options&&(this.node.replaceChildren(),t.length>0&&this.options.multiple?(this.node.classList.remove("hide"),t.forEach(t=>{e.$({qs:{tag:{node:"div",classList:["accessory-item"]},j:{Js:{tag:{node:"span",classList:["accessory-item-button"],role:"button",ariaLabel:`${this.options.textAccessoryDeselect}${t.textContent}`,title:`${this.options.textAccessoryDeselect}${t.textContent}`,onclick:i=>{i.preventDefault(),this.Ns?.$s?.("select"),setTimeout(()=>{t.selected=!1},10)}}},Ks:{tag:{node:"span",classList:["accessory-item-content"],innerHTML:t.text}}}}},this.node)})):this.node.classList.add("hide"),n.ot(window,"resize"))}}class x{constructor(t,i){this.Qs=null,this.Ys=null,this.Xs=null,this.Zs={currentPage:0,te:1,Ti:!1,xi:!1,ie:"",yi:!1},this.se=t,this.Nt=i}ee(){return!!this.Qs}async ne(t){if(!this.Qs)return{Ci:!1,items:[],message:"Ajax not configured"};const i=Array.isArray(t)?t:[t];if(0===i.length)return{Ci:!0,items:[]};try{const t=this.Qs;let s,e;if(s="function"==typeof t.he?t.he(i):{values:i.join(","),oe:"1",..."function"==typeof t.data?t.data("",0):t.data??{}},"POST"===(t.method??"GET")){const i=new URLSearchParams;Object.keys(s).forEach(t=>i.append(t,s[t]+"")),e=await fetch(t.url,{method:"POST",body:i,headers:{"Content-Type":"application/x-www-form-urlencoded"}})}else{const i=""+new URLSearchParams(s);e=await fetch(`${t.url}?${i}`)}if(!e.ok)throw Error("HTTP error! status: "+e.status);const n=await e.json();return{Ci:!0,items:this.re(n).items}}catch(s){return console.error("Load by values error:",s),{Ci:!1,message:s?.message,items:[]}}}le(t){const i=Array.from(this.se.options).map(t=>t.value);return{ae:t.filter(t=>i.includes(t)),ce:t.filter(t=>!i.includes(t))}}ue(t){this.Qs=t}setPopup(t){this.Xs=t}wi(){return{...this.Zs}}de(){this.Zs={currentPage:0,te:1,Ti:!1,xi:!1,ie:"",yi:this.Zs.yi}}clear(){this.Zs.ie="";const{Hs:t}=this.Nt.qt(),i=[];for(const s of t)s instanceof b?i.push(s):s instanceof m&&Array.isArray(s.items)&&i.push(...s.items);i.forEach(t=>{t.visible=!0})}async search(t,i=!1){return this.Qs?this.pe(t,i):this.ge(t)}async Oi(){return this.Qs?this.Zs.xi?{Ci:!1,message:"Already loading"}:this.Zs.yi?this.Zs.Ti?(this.Zs.currentPage++,this.pe(this.Zs.ie,!0)):{Ci:!1,message:"No more data"}:{Ci:!1,message:"Pagination not enabled"}:{Ci:!1,message:"Ajax not enabled"}}async ge(t){this.fe(t)&&(this.Zs.ie=t);const i=((t??"")+"").toLowerCase(),s=e.J(i),{Hs:n}=this.Nt.qt(),h=[];for(const e of n)e instanceof b?h.push(e):e instanceof m&&Array.isArray(e.items)&&h.push(...e.items);let o=!1;return h.forEach(t=>{const n=((t.textContent??t.text??"")+"").toLowerCase(),h=e.J(n),r=""===i||n.includes(i)||h.includes(s);t.visible=r,r&&(o=!0)}),{Ci:!0,me:o,isEmpty:0===h.length}}fe(t){return t!==this.Zs.ie}async pe(t,i=!1){const s=this.Qs;this.fe(t)&&(this.de(),this.Zs.ie=t,i=!1),this.Zs.xi=!0,this.Xs?.Yt(),this.Ys?.abort(),this.Ys=new AbortController;const e=this.Zs.currentPage,n=Array.from(this.se.selectedOptions).map(t=>t.value).join(",");let h;"function"==typeof s.data?(h=s.data(t,e),h&&void 0===h.be&&(h.be=n)):h={search:t,page:e,be:n,...s.data??{}};try{let t;if("POST"===(s.method??"GET")){const i=new URLSearchParams;Object.keys(h).forEach(t=>i.append(t,h[t]+"")),t=await fetch(s.url,{method:"POST",body:i,headers:{"Content-Type":"application/x-www-form-urlencoded"},signal:this.Ys.signal})}else{const i=""+new URLSearchParams(h);t=await fetch(`${s.url}?${i}`,{signal:this.Ys.signal})}const e=await t.json(),n=this.re(e);return n.we?(this.Zs.yi=!0,this.Zs.currentPage=n.page,this.Zs.te=n.te,this.Zs.Ti=n.Ti):this.Zs.yi=!1,this.ye(n.items,!!s.keepSelected,i),this.Zs.xi=!1,this.Xs?.si(),{Ci:!0,me:n.items.length>0,isEmpty:0===n.items.length,we:n.we,Ti:n.Ti,currentPage:n.page,te:n.te}}catch(o){return this.Zs.xi=!1,this.Xs?.si(),"AbortError"===o?.name?{Ci:!1,message:"Request aborted"}:(console.error("Ajax search error:",o),{Ci:!1,message:o?.message})}}re(t){let i=[],s=!1,e=0,n=1,h=!1;return t.object&&Array.isArray(t.object)?(i=t.object,void 0!==t.page&&(s=!0,e=parseInt(t.page??0,10),n=parseInt(t.te??t.ve??1,10),h=e<n-1)):t.data&&Array.isArray(t.data)?(i=t.data,void 0!==t.page&&(s=!0,e=parseInt(t.page??0,10),n=parseInt(t.te??t.ve??1,10),h=t.Ti??e<n-1)):Array.isArray(t)?i=t:t.items&&Array.isArray(t.items)&&(i=t.items,t.xe&&(s=!0,e=parseInt(t.xe.page??0,10),n=parseInt(t.xe.te??t.xe.ve??1,10),h=t.xe.Ti??e<n-1)),{items:i.map(t=>{if(t instanceof HTMLOptionElement||t instanceof HTMLOptGroupElement)return t;if("optgroup"===t.type||t.Te||t.group||t.label)return{type:"optgroup",label:t.label??t.name??t.title??"",data:t.data??{},options:(t.options??t.items??[]).map(t=>({value:t.value??t.id??t.key??"",text:t.text??t.label??t.name??t.title??"",selected:t.selected??!1,data:t.data??(t.imgsrc?{imgsrc:t.imgsrc}:{})}))};const i=t.data??{};return t?.imgsrc&&(i.imgsrc=t.imgsrc),{type:"option",value:t.value??t.id??t.key??"",text:t.text??t.label??t.name??t.title??"",selected:t.selected??!1,data:i}}),we:s,page:e,te:n,Ti:h}}ye(t,i,s=!1){const e=this.se;let n=[];i&&(n=Array.from(e.selectedOptions).map(t=>t.value)),s||(e.innerHTML=""),t.forEach(t=>{if("option"!==t.type&&t.type||""!==t.value||""!==t.text)if(t instanceof HTMLOptionElement||t instanceof HTMLOptGroupElement)e.appendChild(t);else if("optgroup"===t.type){const s=document.createElement("optgroup");s.label=t.label,t.data&&Object.keys(t.data).forEach(i=>{s.dataset[i]=t.data[i]+""}),Array.isArray(t.options)&&t.options.forEach(t=>{const e=document.createElement("option");e.value=t.value,e.text=t.text,t.data&&Object.keys(t.data).forEach(i=>{e.dataset[i]=t.data[i]+""}),(t.selected||i&&n.includes(e.value))&&(e.selected=!0),s.appendChild(e)}),e.appendChild(s)}else{const s=document.createElement("option");s.value=t.value,s.text=t.text,t.data&&Object.keys(t.data).forEach(i=>{s.dataset[i]=t.data[i]+""}),(t.selected||i&&n.includes(s.value))&&(s.selected=!0),e.appendChild(s)}}),e.dispatchEvent(new CustomEvent("options:changed"))}}class T{constructor(t){this.Oe=null,this.Ce=null,this.Ae=50,this.se=t,this.Ce=this.Se(),this.Le=new MutationObserver(()=>{this.Oe&&clearTimeout(this.Oe),this.Oe=setTimeout(()=>{this.Pe()},this.Ae)}),t.addEventListener("options:changed",()=>{this.Oe&&clearTimeout(this.Oe),this.Oe=setTimeout(()=>{this.Pe()},this.Ae)})}Se(){const t=Array.from(this.se.options);return{length:t.length,values:t.map(t=>t.value).join(","),Me:t.map(t=>t.text).join(","),selected:t.map(t=>t.selected+"").join(",")}}He(){const t=this.Se(),i=JSON.stringify(t)!==JSON.stringify(this.Ce);return i&&(this.Ce=t),i}Pe(){this.He()&&this.Pt(this.se)}connect(){this.Le.observe(this.se,{childList:!0,subtree:!1,attributes:!0,attributeFilter:["selected","value","disabled"]})}Pt(t){}disconnect(){this.Oe&&clearTimeout(this.Oe),this.Oe=null,this.Le.disconnect()}}class O{constructor(t){this.Oe=null,this.$e=t,this.Le=new MutationObserver(t=>{let i=!1;for(const s of t)if("attributes"===s.type&&s.attributeName?.startsWith("data-")){i=!0;break}i&&(this.Oe&&clearTimeout(this.Oe),this.Oe=setTimeout(()=>{this.Pt({...this.$e.dataset})},50))}),t.addEventListener("dataset:changed",()=>{this.Pt({...this.$e.dataset})})}connect(){this.Le.observe(this.$e,{attributes:!0,attributeOldValue:!0})}Pt(t){}disconnect(){this.Oe&&clearTimeout(this.Oe),this.Oe=null,this.Le.disconnect()}}class C{constructor(t=[]){this.items=[],this.je=e.m(12),this.Ms=!1,this.items=t,this.Ee()}Ee(){}Fe(t,i,s){const e=i;t.Ot?e?.update?.():e?.ks?.()}ri(t,i){e.Z.on(`${t}ing_${this.je}`,i,{st:1})}hi(t,i){e.Z.on(`${t}_${this.je}`,i)}Fs(t,...i){e.Z.run(`${t}_${this.je}`,...i)}js(t,...i){e.Z.run(`${t}ing_${this.je}`,...i)}Ie(t,i){return null}Ve(){return this.items.length}ke(t){this.js("items",t),this.items=t,this.Fs("items",t)}Ss(t){this.ke(t)}Rs(t){for(let i=0;i<this.Ve();i++){const s=this.items[i];let e=s.view;s.Ot||(e=this.Ie(t,s),s.view=e),this.Fe(s,e,i),s.Ot=!0}}Ps(t){}}class A{constructor(t){this.parent=null,this.view=null,this.parent=t}ks(){}update(){}hs(){if(!this.view?.view)throw Error("View is not mounted. Did you forget to set this.view?");return this.view.view}}class S extends A{constructor(){super(...arguments),this.view=null}ks(){const t=e.m(7);this.view=e.H({Re:{tag:{node:"div",classList:["selective-ui-group"],role:"group",A:`seui-${t}-header`,id:`seui-${t}-group`},j:{_e:{tag:{node:"div",classList:["selective-ui-group-header"],role:"presentation",id:`seui-${t}-header`}},De:{tag:{node:"div",classList:["selective-ui-group-items"],role:"group"}}}}}),this.parent.appendChild(this.view.view)}update(){this.Ui()}Ui(t=null){this.view&&null!==t&&(this.view.tags._e.textContent=t)}Ne(){if(!this.view)throw Error("GroupView is not rendered.");return this.view.tags.De}Qi(){if(!this.view)return;const t=Array.from(this.view.tags.De.children).filter(t=>!t.classList.contains("hide"));this.view.view.classList.toggle("hide",!(t.length>0))}Wi(t){this.view&&(this.view.view.classList.toggle("collapsed",t),this.view.tags._e.setAttribute("aria-expanded",t?"false":"true"))}}class L extends A{constructor(t){super(t),this.view=null,this.Be=null,this.ze=null,this.Ge=!1,this.Ue()}Ue(){const t=this;this.Be={isMultiple:!1,hasImage:!1,imagePosition:"right",imageWidth:"60px",imageHeight:"60px",imageBorderRadius:"4px",labelValign:"center",labelHalign:"left"},this.ze=new Proxy(this.Be,{set(i,s,e){if("string"!=typeof s)return!0;const n=s,h=i[n];return h!==e&&(i[n]=e,t.Ge&&t.We(n,e,h)),!0}})}get isMultiple(){return this.Be.isMultiple}set isMultiple(t){this.ze.isMultiple=!!t}get hasImage(){return this.Be.hasImage}set hasImage(t){this.ze.hasImage=!!t}get qe(){return this.ze}set qe(t){if(!t||!this.ze||!this.Be)return;const i={};void 0!==t.imageWidth&&t.imageWidth!==this.Be.imageWidth&&(i.imageWidth=t.imageWidth),void 0!==t.imageHeight&&t.imageHeight!==this.Be.imageHeight&&(i.imageHeight=t.imageHeight),void 0!==t.imageBorderRadius&&t.imageBorderRadius!==this.Be.imageBorderRadius&&(i.imageBorderRadius=t.imageBorderRadius),void 0!==t.imagePosition&&t.imagePosition!==this.Be.imagePosition&&(i.imagePosition=t.imagePosition),void 0!==t.labelValign&&t.labelValign!==this.Be.labelValign&&(i.labelValign=t.labelValign),void 0!==t.labelHalign&&t.labelHalign!==this.Be.labelHalign&&(i.labelHalign=t.labelHalign),Object.keys(i).length>0&&Object.assign(this.ze,i)}ks(){const t=["selective-ui-option-view"],i=e.m(7),s="option_"+i;this.Be.isMultiple&&t.push("multiple"),this.Be.hasImage&&(t.push("has-image"),t.push("image-"+this.Be.imagePosition));const n={rs:{tag:{node:"input",type:this.Be.isMultiple?"checkbox":"radio",classList:"allow-choice",id:s}},...this.Be.hasImage&&{ps:{tag:{node:"img",classList:"option-image",style:{width:this.Be.imageWidth,height:this.Be.imageHeight,borderRadius:this.Be.imageBorderRadius}}}},Je:{tag:{node:"label",htmlFor:s,classList:["align-vertical-"+this.Be.labelValign,"align-horizontal-"+this.Be.labelHalign]},j:{ds:{tag:{node:"div"}}}}};this.view=e.H({Ke:{tag:{node:"div",id:`seui-${i}-option`,classList:t,role:"option",ariaSelected:"false",tabIndex:"-1"},j:n}}),this.parent.appendChild(this.view.view),this.Ge=!0}We(t,i,s){const e=this.view;if(!e||!e.view)return;const n=e.view,h=e.tags?.rs,o=e.tags?.Je;switch(t){case"isMultiple":{const t=!!i;n.classList.toggle("multiple",t),h&&h.type!==(t?"checkbox":"radio")&&(h.type=t?"checkbox":"radio");break}case"hasImage":{const t=!!i;if(n.classList.toggle("has-image",t),t)n.classList.add("image-"+this.Be.imagePosition),this.Qe();else{n.className=n.className.replace(/image-(top|right|bottom|left)/g,"").trim();const t=e.tags?.ps;t&&(t.remove(),e.tags.ps=null)}break}case"imagePosition":this.Be.hasImage&&(n.className=n.className.replace(/image-(top|right|bottom|left)/g,"").trim(),n.classList.add("image-"+i));break;case"imageWidth":case"imageHeight":case"imageBorderRadius":{const s=e.tags?.ps;if(s){const e="imageWidth"===t?"width":"imageHeight"===t?"height":"borderRadius",n=i+"";s.style[e]!==n&&(s.style[e]=n)}break}case"labelValign":case"labelHalign":if(o){const t=`align-vertical-${this.Be.labelValign} align-horizontal-${this.Be.labelHalign}`;o.className!==t&&(o.className=t)}}}Qe(){const t=this.view;if(!t||!t.view)return;const i=t.tags?.ps;if(i)return;const s=t.view,e=t.tags?.Je,n=document.createElement("img");n.className="option-image",n.style.width=this.Be.imageWidth,n.style.height=this.Be.imageHeight,n.style.borderRadius=this.Be.imageBorderRadius,e&&e.parentElement?s.insertBefore(n,e):s.appendChild(n),t.tags.ps=n}}class P extends C{constructor(t=[]){super(t),this.isMultiple=!1,this.Ye=[],this.Xe=-1,this.Ze=null,this.groups=[],this.tn=[],this.sn()}sn(){this.tn=[],this.groups=[],this.items.forEach(t=>{t instanceof m?(this.groups.push(t),this.tn.push(...t.items)):t instanceof b&&this.tn.push(t)})}Ie(t,i){return i instanceof m?new S(t):new L(t)}Fe(t,i,s){t.position=s,t instanceof m?this.en(t,i,s):t instanceof b&&this.nn(t,i,s),t.Ot=!0}en(t,i,s){super.Fe(t,i,s),t.view=i;const e=i.view.tags._e;e.textContent=t.label,t.Ot||(e.style.cursor="pointer",e.addEventListener("click",()=>{t.Ji()}),t.qi((t,i,s)=>{i.items.forEach(t=>{const i=t.view?.hs?.();i&&(i.style.display=s?"none":"")}),this.hn(i,s)}));const n=i.Ne();t.items.forEach((t,i)=>{let s=t.view;t.Ot&&s||(s=new L(n)),this.nn(t,s,i),t.Ot=!0}),i.Wi(t.collapsed),i.Qi()}nn(t,i,s){if(i.isMultiple=this.isMultiple,i.hasImage=t.hasImage,i.qe={imageWidth:t.options.imageWidth,imageHeight:t.options.imageHeight,imageBorderRadius:t.options.imageBorderRadius,imagePosition:t.options.imagePosition,labelValign:t.options.labelValign,labelHalign:t.options.labelHalign},t.Ot||super.Fe(t,i,s),t.view=i,t.hasImage){const s=i.view.tags.ps;s&&(s.src!==t.es&&(s.src=t.es),s.alt!==t.text&&(s.alt=t.text))}i.view.tags.ds.innerHTML=t.text,t.Ot||(i.view.tags.Ke.addEventListener("click",i=>{i.stopPropagation(),i.preventDefault(),this.Ms||(this.isMultiple?(this.js("select"),setTimeout(()=>{t.selected=!t.selected},5)):!0!==t.selected&&(this.js("select"),setTimeout(()=>{this.Ze&&(this.Ze.selected=!1),t.selected=!0},5)))}),i.view.tags.Ke.title=t.textContent,i.view.tags.Ke.addEventListener("mouseenter",()=>{this.Ms||this.rn(this.tn.indexOf(t),!1)}),t.cs(()=>{this.Fs("selected")}),t.us((i,s,e)=>{e&&(this.Ze=t),this.Fs("selected_internal")}),t.ni((t,i)=>{i.group?.Qi(),this.ln()})),t.selected&&(this.Ze=t,t.ns=!0)}ke(t){this.js("items",t),this.items=t,this.sn(),this.Fs("items",t)}Ss(t){this.ke(t)}Ps(t){this.items=t,this.sn()}an(){return this.tn.filter(t=>t.selected)}cn(){return this.tn.find(t=>t.selected)}Kt(t){this.isMultiple&&this.tn.forEach(i=>{i.selected=t})}ni(t){this.Ye.push(t)}ln(){const t=this.tn.filter(t=>t.visible).length,i=this.tn.length;this.Ye.forEach(s=>{s({un:t,dn:i,Zt:t>0,isEmpty:0===i})})}ti(){const t=this.tn.filter(t=>t.visible).length,i=this.tn.length;return{un:t,dn:i,Zt:t>0,isEmpty:0===i}}pn(){this.rn(0)}navigate(t,i=!0){const s=this.tn.filter(t=>t.visible);if(0===s.length)return;let e=s.findIndex(t=>t===this.tn[this.Xe]);-1===e&&(e=-1);let n=e+t;n>=s.length&&(n=0),n<0&&(n=s.length-1);const h=this.tn.indexOf(s[n]);this.rn(h,i)}gn(){if(this.Xe>-1&&this.tn[this.Xe]){const t=this.tn[this.Xe];if(t.visible){const i=t.view?.hs?.();i&&i.click()}}}rn(t,i=!0){let s=0;if("number"==typeof t)s=t;else if(t instanceof b){const i=this.tn.indexOf(t);s=i>-1?i:0}else s=0;this.Xe>-1&&this.tn[this.Xe]&&(this.tn[this.Xe].ls=!1);for(let e=s;e<this.tn.length;e++){const t=this.tn[e];if(t.visible){if(t.ls=!0,this.Xe=e,i){const i=t.view?.hs?.();i&&i.scrollIntoView({fn:"center",behavior:"smooth"})}return void this.mn(e,t.view?.hs?.()?.id)}}}mn(t,i){}hn(t,i){}}class M{constructor(t=null,i=null){this.container={},this.oldValue=null,this.node=null,this.options=null,this.bn=null,this.isOpen=!1,this.wn=!1,this.yn=!1,this.vn=null,t&&this.init(t,i)}get isDisabled(){return!!this.options?.disabled}set isDisabled(t){this.options&&this.node&&(this.options.disabled=t,this.node.classList.toggle("disabled",t),this.node.setAttribute("aria-disabled",t+""),this.container.tags?.mi?.setAttribute("aria-disabled",t+""))}get xn(){return!!this.options?.readonly}set xn(t){this.options&&this.node&&(this.options.readonly=t,this.node.classList.toggle("readonly",t))}get isVisible(){return!!this.options?.visible}set isVisible(t){this.options&&this.node&&(this.options.visible=t,this.node.classList.toggle("invisible",!t))}init(t,s){const n=e.R(t).options,l=new o(n),a=new r,c=new p(n),effector=i(),u=new w(n),g=new v(n),f=new x(t,u),m=new T(t),b=new O(t);this.vn=s,this.options=n,l.node&&(l.node.id=(n.Tn??"")+"");const C=e.$({On:{tag:{node:"div",classList:"selective-ui-MAIN"},j:{mi:{tag:{node:"div",classList:"selective-ui-view",tabIndex:0,onkeydown:t=>{"Enter"!==t.key&&" "!==t.key&&"ArrowDown"!==t.key||(t.preventDefault(),this.Cn()?.open())}},j:{An:{tag:l.node},Sn:{tag:a.node},Ei:{tag:c.node}}}}}},null);this.container=C,this.node=C.view,t.parentNode?.insertBefore(this.node,t),this.node.insertBefore(t,C.tags.mi),g.zs(C.tags.mi),g.Us(u),C.tags.mi.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()}),h.lt(t,C.tags.mi),t.classList.add("init"),u.ys(P),u.xs(y),u.As(e.K(t)),u.onUpdated=()=>{C.Ln?.ii?.()},this.bn=u,C.Pn=f,C.placeholder=l,C.Mn=a,C.Hn=c,C.effector=effector,C.targetElement=t,C.$n=g,C.jn=m,C.En=b,C.Ln=new d(t,n,u),C.Ln.ai(effector),C.Ln.bi(f,n),C.Ln.li("selected",()=>{this.Cn()?.change(null,!0)}),C.Ln.li("selected_internal",()=>{this.Cn()?.change(null,!1)}),C.Ln.oi("select",()=>{this.oldValue=this.Cn()?.value??""}),this.Cn()?.change(null,!1),m.connect(),m.Pt=t=>{u.update(e.K(t)),this.Cn()?.refreshMask()},b.connect(),b.Pt=t=>{e.V(t.disabled)!==this.isDisabled&&(this.isDisabled=e.V(t.disabled)),e.V(t.readonly)!==this.xn&&(this.xn=e.V(t.readonly)),e.V(t.visible)!==this.isVisible&&(this.isVisible=e.V(t.visible??"1"))},t.addEventListener("options:changed",()=>{u.update(e.K(t)),this.Cn()?.refreshMask(),C.Ln?.ii?.()}),n.ajax&&f.ue(n.ajax);const A=C.Ln.Ht,S=(t,i)=>{i||""!==t?(""!==t&&(this.yn=!0),f.search(t).then(t=>{C.Ln?.ii?.(),t?.me&&setTimeout(()=>{A.pn()},n.animationtime??0)}).catch(t=>{console.error("Search error:",t)})):f.clear()};let L=null;c.Mi=(t,i)=>{f.fe(t)&&(f.ee()?(L&&clearTimeout(L),C.Ln?.Yt?.(),L=setTimeout(()=>{S(t,i)},n.delaysearchtime??0)):S(t,i))},f.setPopup(C.Ln),c.Hi=t=>{A.navigate(t)},c.$i=()=>{A.gn()},c.ji=()=>{this.Cn()?.close(),C.tags.mi.focus()},A.mn=(t,i)=>{i&&c.Ii(i)},A.hn=()=>{C.Ln?.ii?.()},this.isDisabled=e.V(n.disabled),this.xn=e.V(n.readonly)}Fn(){const t=this.container??{},{jn:i,En:s}=t;i?.disconnect&&i.disconnect(),s?.disconnect&&s.disconnect()}Cn(){const t=this.container,i=this,s=e.R(t.targetElement);if(!s)return null;const h=s.options,o={get placeholder(){return t.placeholder.get()},set placeholder(i){t.placeholder?.set(i),t.Hn?.Fi(i)},get oldValue(){return i.oldValue},set value(t){this.setValue(null,t,!0)},get value(){const t=this.valueArray,i=t.length;return i>1?t:0===i?"":t[0]},get valueArray(){const t=[];return i.In().forEach(i=>{i.selected&&t.push(i.value)}),t},get valueString(){return this.valueArray.join(h.customDelimiter)},get valueOptions(){const t=[];return i.In().forEach(i=>{i.selected&&t.push(i)}),t},get mask(){const t=[];return i.In().forEach(i=>{i.selected&&t.push(i.text)}),t},get valueText(){const t=[];i.In().forEach(i=>{i.selected&&t.push(i.text)});const s=t.length;return s>1?t:0===s?"":t[0]},get isOpen(){return i.isOpen},selectAll(t,s=!0){if(!(h.multiple&&h.maxSelected>0&&i.In().length>h.maxSelected)&&!this.disabled&&!this.readonly&&h.multiple){if(s){if(n.ht([this],...h.on.beforeChange).isCancel)return;i.oldValue=this.value}i.In().forEach(t=>{t.ns=!0}),this.change(!1,s)}},deSelectAll(t,s=!0){if(!this.disabled&&!this.readonly&&h.multiple){if(s){if(n.ht([this],...h.on.beforeChange).isCancel)return;i.oldValue=this.value}i.In().forEach(t=>{t.ns=!1}),this.change(!1,s)}},setValue(s=null,e,o=!0,r=!1){if(Array.isArray(e)||(e=[e]),0===(e=e.filter(t=>""!==t&&null!=t)).length)return i.In().forEach(t=>t.ns=!1),void this.change(!1,o);if(h.multiple&&h.maxSelected>0&&e.length>h.maxSelected)console.warn(`Cannot select more than ${h.maxSelected} items`);else if(r||!this.disabled&&!this.readonly){if(t.Pn?.ee?.()){const{ce:s}=t.Pn.le(e);if(s.length>0)return void(async()=>{h.loadingfield&&t.Ln?.Yt?.();try{const n=await t.Pn.ne(s);n.Ci&&n.items.length>0?(n.items.forEach(t=>{s.includes(t.value)&&(t.selected=!0)}),t.Pn.ye?.(n.items,!0,!0),setTimeout(()=>{i.In().forEach(t=>{t.ns=e.some(i=>i==t.value)}),this.change(!1,!1)},100)):s.length>0&&console.warn(`Could not load ${s.length} values:`,s)}catch(n){console.error("Error loading missing values:",n)}finally{h.loadingfield&&t.Ln?.si?.()}})()}if(o){if(n.ht([this],...h.on.beforeChange).isCancel)return;i.oldValue=this.value}i.In().forEach(t=>{t.ns=e.some(i=>i==t.value)}),!h.multiple&&e.length>0&&(t.targetElement.value=e[0]),this.change(!1,o)}},open(){if(i.isOpen)return!1;const s=i.vn?.find?.();if(s&&!s.isEmpty&&s.close().isCancel)return!1;if(this.disabled)return!1;if(n.ht([this],...h.on.beforeShow).isCancel)return!1;i.isOpen=!0,t.Mn.dt(!0);const e=t.Ln.Ht,o=e.cn();o?e.rn(o,!1):e.pn(),i.wn&&!i.yn||!h?.ajax||(t.Ln.Yt(),i.wn=!0,i.yn=!1,setTimeout(()=>{t.Ln&&t.Pn&&t.Pn.search("").then(()=>t.Ln?.ii?.()).catch(t=>console.error("Initial ajax load error:",t))},h.animationtime)),t.Ln.open(),t.Hn.show();const r=t.tags.mi;return r.setAttribute("aria-expanded","true"),r.setAttribute("aria-controls",h.Gt),r.setAttribute("aria-haspopup","listbox"),r.setAttribute("aria-labelledby",h.Tn),h.multiple&&r.setAttribute("aria-multiselectable","true"),n.ht([this],...h.on.show),!0},close(){return!!i.isOpen&&!n.ht([this],...h.on.beforeClose).isCancel&&(i.isOpen=!1,t.Mn.dt(!1),t.Ln.close(()=>{t.Hn.clear(!1)}),t.Hn.hide(),t.tags.mi.setAttribute("aria-expanded","false"),n.ht([this],...h.on.close),!0)},toggle(){i.isOpen?this.close():this.open()},change(s=null,e=!0){if(e){if(h.multiple&&h.maxSelected>0&&this.valueArray.length>h.maxSelected&&this.setValue(null,this.oldValue,!1,!0),this.disabled||this.readonly)return void this.setValue(null,this.oldValue,!1,!0);if(n.ht([this,this.value],...h.on.beforeChange).isCancel)return void this.setValue(null,this.oldValue,!1)}this.refreshMask(),t.$n.Ws(this.valueOptions),e&&(t.targetElement&&n.ot(t.targetElement,"change"),n.ht([this,this.value],...h.on.change),i.options?.autoclose&&this.close())},refreshMask(){let s=h.placeholder;!h.multiple&&i.In().length>0&&(s=this.mask[0]),s??(s=h.placeholder),t.placeholder.set(s,!1),t.Hn.Fi(s)},on(t,i,s){h.on[i]||(h.on[i]=[]),h.on[i].push(s)},ajax(i,s){t.Pn.ue(s)}};return this.Vn(o,"disabled","isDisabled"),this.Vn(o,"readonly","isReadOnly"),this.Vn(o,"visible","isVisible"),o}Vn(t,i,s){const e=this;Object.defineProperty(t,i,{get:()=>e[s],set(t){e[s]=!!t,e.container?.targetElement?.dataset&&(e.container.targetElement.dataset[i]=!!t+"")},enumerable:!0,configurable:!0})}In(t=null){if(!this.bn)return[];const{Hs:i}=this.bn.qt(),s=[];for(const e of i)e instanceof b?s.push(e):e instanceof m&&Array.isArray(e.items)&&e.items.length&&s.push(...e.items);return"boolean"==typeof t?s.filter(i=>i.selected===t):s}Ai(){this.container.Ln.Ai()}}class H{constructor(){this.kn=!1,this.Le=null,this.Rn=[]}_n(t){this.Rn.push(t)}Dn(){this.Rn=[]}start(t){if(this.kn)return;this.kn=!0;const i=t.toUpperCase(),s=t.toLowerCase();this.Le=new MutationObserver(t=>{for(const e of t)e.addedNodes.forEach(t=>{if(1!==t.nodeType)return;const e=t;e.tagName===i&&this.Nn(e),e.querySelectorAll(s).forEach(t=>this.Nn(t))})}),this.Le.observe(document.body,{childList:!0,subtree:!0})}stop(){this.kn&&(this.kn=!1,this.Le?.disconnect(),this.Le=null)}Nn(t){this.Rn.forEach(i=>i(t))}}class ${constructor(){this.Bn=new Map}bind(t,i){const s=e.I(e.G(),i);s.on=s.on??{},s.on.load=s.on.load??[],this.Bn.set(t,s);const h=e.m();e.Z.on(h,()=>{n.ht([this.find(t)],...s.on.load),e.Z.clear(h),s.on.load=[]}),e.v(t).forEach(t=>{(async()=>{"SELECT"===t.tagName&&(e.D(t),this.zn(t,s)&&e.Z.run(h))})()}),e.U().includes(t)||e.U().push(t)}find(t="*"){const i={isEmpty:!0};if("*"===t&&""===(t=e.U().join(", ")))return i;const s=e.v(t);if(0===s.length)return i;const n=e.R(s[0]);if(!n||!n.action)return i;const h={};for(const e in n.action)h[e]=this.Gn(e,n.action);const o={isEmpty:!1};for(const e in h){const t=h[e];switch(t.type){case"get-set":this.Un(o,t.name,s);break;case"func":this.Wn(o,t.name,s)}}return o}qn(){this.Jn=new H,this.Jn._n(t=>{this.Bn.forEach((i,s)=>{try{t.matches(s)&&this.zn(t,i)}catch(e){console.warn("Invalid selector: "+s,e)}})}),this.Jn.start("select")}destroy(t=null){null===t?this.Kn():"string"==typeof t?this.Qn(t):t instanceof HTMLSelectElement&&this.Yn(t)}Kn(){e.U().forEach(t=>this.Qn(t)),this.Bn.clear(),e.U().length=0,this.Jn?.stop()}Qn(t){e.v(t).forEach(t=>{"SELECT"===t.tagName&&this.Yn(t)}),this.Bn.delete(t);const i=e.U(),s=i.indexOf(t);s>-1&&i.splice(s,1)}Yn(t){const i=e.R(t);if(!i)return;const s=i.container?.Ln;s?.Ai(),e.B(t,i);const n=!!this.Jn;n&&this.Jn?.stop();try{i.self?.Fn?.()}catch(o){}const h=i.container?.element??t.parentElement;t.style.display="",t.style.visibility="",t.disabled=!1,delete t.dataset.Xn,h&&h.parentNode?h.parentNode.replaceChild(t,h):document.body.appendChild(t),e.k(t),n&&this.Bn.size>0&&this.Jn?.start("select")}rebind(t,i){this.Qn(t),this.bind(t,i)}zn(t,i){if(e.R(t)||e.N(t))return!1;const s=e.m(8),n=e.F(t,i);n.Zn=s,n.Gt=`seui-${s}-optionlist`,n.Tn=`seui-${s}-placeholder`;const h={options:n};e._(t,h);const o=new M(t,this);return h.container=o.container,h.action=o.Cn(),h.self=o,o.container.view.addEventListener("mouseup",()=>{h.action?.toggle?.()}),!0}Gn(t,i){const s=Object.getOwnPropertyDescriptor(i,t);let e="variable";return s?.get||s?.set&&"function"!=typeof i[t]?e="get-set":"function"==typeof i[t]&&(e="func"),{type:e,name:t}}Un(t,i,s){Object.defineProperty(t,i,{get(){const t=e.R(s[0]);return t.action?.[i]},set(t){s.forEach(s=>{const n=e.R(s);n?.action&&(n.action[i]=t)})},enumerable:!0,configurable:!0})}Wn(t,i,s){t[i]=(...h)=>{for(let t=0;t<s.length;t++){const o=e.R(s[t]);if(!o?.action)continue;const r=n.nt();if(o.action[i](r.et,...h),!r.token.isContinue)break}return t}}}const j="1.1.3",E="SelectiveUI";if(void 0===globalThis.GLOBAL_SEUI){const I=new $;globalThis.GLOBAL_SEUI={version:j,name:E,bind:I.bind.bind(I),find:I.find.bind(I),destroy:I.destroy.bind(I),effector:i.bind(i),rebind:I.rebind.bind(I)};let V=!1;function k(){V||(V=!0,document.addEventListener("mousedown",()=>{const t=e.U();if(t.length>0){const i=I.find(t.join(", "));i.isEmpty||i.close()}}),I.qn())}"undefined"!=typeof document&&("loading"===document.readyState?document.addEventListener("DOMContentLoaded",k):k()),console.log(`[${E}] v${j} loaded successfully`)}else console.warn(`[${globalThis.GLOBAL_SEUI.name}] Already loaded (v${globalThis.GLOBAL_SEUI.version}). Using existing instance. Please remove duplicate <script> tags.`);const version=globalThis.GLOBAL_SEUI.version,F=globalThis.GLOBAL_SEUI.name;t.bind=(t,i={})=>{globalThis.GLOBAL_SEUI.bind(t,i)},t.destroy=(t=null)=>{globalThis.GLOBAL_SEUI.destroy(t)},t.effector=t=>globalThis.GLOBAL_SEUI.effector(t),t.find=t=>globalThis.GLOBAL_SEUI.find(t),t.name=F,t.rebind=(t,i={})=>{globalThis.GLOBAL_SEUI.rebind(t,i)},t.version=version},"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).SelectiveUI={});
1
+ /*! Selective UI v1.1.4 | MIT License */
2
+ var t,i;t=this,i=function(t){"use strict";function i(t){return new g(t??null)}class s{constructor(){this.t={showPanel:!0,accessoryStyle:"top",multiple:!1,minWidth:"50px",width:"0px",offsetWidth:null,minHeight:"30px",height:"30px",panelHeight:"220px",panelMinHeight:"100px",disabled:!1,readonly:!1,selectall:!0,keepSelected:!0,placeholder:"Select value",altMask:"",autoclose:!1,autoscroll:!0,autofocus:!0,searchable:!0,loadingfield:!0,visible:!0,skipError:!1,customDelimiter:",",textLoading:"Processing...",textNoData:"No data available",textNotFound:"Not found",textSelectAll:"Select all",textDeselectAll:"Deselect all",textAccessoryDeselect:"Deselect: ",animationtime:200,delaysearchtime:200,allowHtml:!0,maxSelected:0,labelHalign:"left",labelValign:"center",imageMode:!1,imageWidth:"60px",imageHeight:"60px",imageBorderRadius:"4px",imagePosition:"right",ajax:null,on:{load:[],beforeShow:[],show:[],beforeChange:[],change:[],beforeClose:[],close:[]}},this.i=new Map,this.h=new Map,this.o=[]}}class e{static get l(){return this.u||(this.u=new s),this.u}static p(t){if(null===t||"object"!=typeof t)return t;const i=Array.isArray(t)?[]:{};for(const s in t)Object.prototype.hasOwnProperty.call(t,s)&&(i[s]=this.p(t[s]));return i}static m(t=6){let i="";for(let s=0;s<t;s++)i+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random()));return i}static v(t){if(!t)return[];if("string"==typeof t){const i=document.querySelectorAll(t);return Array.from(i)}return t instanceof Element?[t]:t instanceof NodeList||Array.isArray(t)?Array.from(t):[]}static T(t={}){return this.O(document.createElement(t.node??"div"),t,!0)}static O(t=document.documentElement,i=null,s=!1){const e={...i??{}},n=s?t:this.C(t.cloneNode(!0)),h=e.classList;return"string"==typeof h?n.classList.add(h):Array.isArray(h)&&n.classList.add(...h),delete e.classList,["style","dataset"].forEach(t=>{const i=e[t];i&&"object"==typeof i&&Object.assign(n[t],i),delete e[t]}),e.role&&(n.setAttribute("role",e.role+""),delete e.role),e.ariaLive&&(n.setAttribute("aria-live",e.ariaLive+""),delete e.ariaLive),e.A&&(n.setAttribute("aria-labelledby",e.A+""),delete e.A),e.S&&(n.setAttribute("aria-controls",e.S+""),delete e.S),e.L&&(n.setAttribute("aria-haspopup",e.L+""),delete e.L),e.P&&(n.setAttribute("aria-multiselectable",e.P+""),delete e.P),e.M&&(n.setAttribute("aria-autocomplete",e.M+""),delete e.M),e.event&&"object"==typeof e.event&&(Object.entries(e.event).forEach(([t,i])=>{n.addEventListener(t,i)}),delete e.event),Object.entries(e).forEach(([t,i])=>{null===i?n.removeAttribute(t):n[t]=i}),n}static C(t){if(t instanceof Element)return t;throw new TypeError("Node is not an Element")}static H(t){return this.$(t)}static $(t,i=null,s=!1,e=!1,n={}){let h=null;for(const o in t){const r=t[o],l=r?.tag?.tagName?r.tag:this.T(r.tag);n[o]=l,r?.j&&this.$(r.j,l,!1,!1,n),i?s?i.prepend(l):i.append(l):e||h||(h=l)}return e||(n.id=this.m(7),i||(n={tags:n,view:h})),n}static F(t,i){const s=this.p(i);for(const e in s){const i=t[e];i?s[e]=i:void 0!==t?.dataset?.[e]&&(s[e]=t.dataset[e])}return s}static I(...t){if(0===t.length)return{};if(1===t.length)return this.p(t[0]);const i=this.p(t[0]);for(let s=1;s<t.length;s++){const e=t[s];for(const t in e)if("on"===t){const s=e[t];for(const e in s)i[t][e].push(s[e])}else i[t]=e[t]}return i}static V(t){if("boolean"==typeof t)return t;if("string"!=typeof t)return!!t;switch(t.trim().toLowerCase()){case"true":case"1":case"yes":case"on":return!0;default:return!1}}static k(t){return this.l.i.delete(t)}static R(t){return this.l.i.get(t)}static _(t,i){this.l.i.set(t,i)}static D(t){return this.l.h.delete(t)}static N(t){return this.l.h.get(t)}static B(t,i){this.l.h.set(t,i)}static G(){return this.l.t}static U(){return this.l.o}static W(t){if(null==t)return"";let i=(t+"").replace(/<`/g,"<").replace(/`>/g,">").replace(/\<\`/g,"<").replace(/\`\>/g,">").trim();const s=globalThis?.document;if(!s||"function"!=typeof s.createElement)return i=i.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"").replace(/<iframe\b[^>]*>[\s\S]*?<\/iframe>/gi,"").replace(/<(object|embed|link)\b[^>]*>[\s\S]*?<\/\1>/gi,""),i=i.replace(/\son[a-z]+\s*=\s*(['"]).*?\1/gi,""),i=i.replace(/\s([a-z-:]+)\s*=\s*(['"])\s*javascript:[^'"]*\2/gi,""),i;const e=s.createElement("div");return e.innerHTML=i,e.querySelectorAll("script, style, iframe, object, embed, link").forEach(t=>t.remove()),e.querySelectorAll("*").forEach(t=>{for(const i in t.attributes){const s=t.attributes[i],e=s.name??"",n=s.value??"";if(/^on/i.test(e))return void t.removeAttribute(e);/^(href|src|xlink:href)$/i.test(e)&&/^javascript:/i.test(n)&&t.removeAttribute(e)}}),(e.innerHTML??"").trim()}static q(t){const i=document.createElement("DIV");i.innerHTML=t;const s=i.textContent??i.innerText??"";return i.remove(),s.trim()}static J(t){return null==t?"":(t+"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/đ/g,"d").replace(/Đ/g,"d")}static K(t){const i=[];return Array.from(t.children).forEach(t=>{if("OPTGROUP"===t.tagName){const s=t;i.push(s),Array.from(s.children).forEach(t=>{t.__parentGroup=s,i.push(t)})}else"OPTION"===t.tagName&&i.push(t)}),i}static Y(){const t=navigator.userAgent;return/iP(hone|ad|od)/.test(t)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1}static X(t){const i=(t+"").trim();if(i.endsWith("px"))return i;if(i.endsWith("vh"))return window.innerHeight*parseFloat(i)/100+"px";if(i.endsWith("vw"))return window.innerWidth*parseFloat(i)/100+"px";const s=parseFloat(getComputedStyle(document.documentElement).fontSize);if(i.endsWith("rem"))return s*parseFloat(i)+"px";const e=this.T({node:"div",style:{height:i,opacity:"0"}});document.body.appendChild(e);const n=e.offsetHeight+"px";return e.remove(),n}}e.u=null,e.Z=new class{constructor(){this.tt=new Map,this.it=new Map}on(t,i,s={}){const e=s.st??50,n=s.once??!1;this.tt.has(t)||this.tt.set(t,[]),this.tt.get(t).push({et:i,timeout:e,once:n})}off(t){const i=this.it.get(t);if(i){for(const t of i.values())clearTimeout(t);i.clear(),this.it.delete(t)}this.tt.delete(t)}run(t,...i){const s=this.tt.get(t);if(!s)return;this.it.has(t)||this.it.set(t,new Map);const e=this.it.get(t);for(let n=0;n<s.length;n++){const t=s[n];if(!t)continue;const h=e.get(n);h&&clearTimeout(h);const o=setTimeout(()=>{if(t.et(i.length>0?i:null),t.once){s[n]=void 0;const t=e.get(n);t&&clearTimeout(t),e.delete(n)}},t.timeout);e.set(n,o)}}clear(t){if(void 0===t)for(const i of Array.from(this.tt.keys()))this.off(i);else this.off(t)}};class n{static nt(){const t={isContinue:!0,isCancel:!1};return{token:{get isContinue(){return t.isContinue},get isCancel(){return t.isCancel}},et:{stopPropagation(){t.isContinue=!1},cancel(){t.isCancel=!0,t.isContinue=!1}}}}static ht(t,...i){const{token:s,et:e}=this.nt();for(let n=0;n<i.length;n++){const h=i[n];if("function"==typeof h&&(t&&Array.isArray(t)?h(e,...t):h(e),s.isCancel||!s.isContinue))break}return s}static ot(t,i,s={bubbles:!0,cancelable:!0}){const e=new Event(i,s);return t.dispatchEvent(e),e}static rt(t,...i){if(Array.isArray(t))for(const s of t)"function"==typeof s&&s(...i)}}class h{static lt(t,i){const s=e.R(t);if(!s?.options)return;const n=s.options,h=n.minWidth,o=n.minHeight,r=Number.parseInt(n.width,10),l=Number.parseInt(n.height,10);let a=t.offsetWidth+"px",c=t.offsetHeight+"px";const u=getComputedStyle(t);"0px"===a&&"auto"!==u.width&&(a=u.width),"0px"===c&&"auto"!==u.height&&(c=u.height),r>0&&(a=n.width),l>0&&(c=n.height),Object.assign(i.style,{width:a,height:c,minWidth:h,minHeight:o})}}class o{constructor(t){this.node=null,this.ct=null,t&&this.init(t)}init(t){this.node=e.T({node:"div",classList:"selective-ui-placeholder",innerHTML:t.placeholder}),this.ct=t}get(){return this.ct?.placeholder??""}set(t,i=!0){if(!this.node||!this.ct)return;i&&(this.ct.placeholder=t);const s=e.W(t);this.node.innerHTML=this.ct.allowHtml?s:e.q(s)}}class r{constructor(){this.node=this.ut()}ut(){return e.T({node:"div",classList:"selective-ui-directive",role:"button",ariaLabel:"Toggle dropdown"})}dt(t){this.node.classList.toggle("drop-down",!!t)}}class l{constructor(t=null){this.gt=null,this.node=null,this.options=null,this.ft=[],this.bt=[],t&&this.init(t)}init(t){this.gt=e.$({wt:{tag:{node:"div",classList:["selective-ui-option-handle","hide"]},j:{yt:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textSelectAll,onclick:()=>{n.rt(this.ft)}}},vt:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textDeselectAll,onclick:()=>{n.rt(this.bt)}}}}}}),this.node=this.gt.view,this.options=t}available(){return!!this.options&&e.V(this.options.multiple)&&e.V(this.options.selectall)}refresh(){this.node&&(this.available()?this.show():this.hide())}show(){this.node&&this.node.classList.remove("hide")}hide(){this.node&&this.node.classList.add("hide")}xt(t=null){"function"==typeof t&&this.ft.push(t)}Tt(t=null){"function"==typeof t&&this.bt.push(t)}}class a{constructor(t=null){this.node=null,this.options=null,t&&this.init(t)}init(t){this.options=t,this.node=e.T({node:"div",classList:["selective-ui-empty-state","hide"],role:"status",ariaLive:"polite"})}show(t="nodata"){this.node&&this.options&&(this.node.textContent="notfound"===t?this.options.textNotFound:this.options.textNoData,this.node.classList.remove("hide"))}hide(){this.node&&this.node.classList.add("hide")}get isVisible(){return!!this.node&&!this.node.classList.contains("hide")}}class c{constructor(t=null){this.node=null,this.options=null,t&&this.init(t)}init(t){this.options=t,this.node=e.T({node:"div",classList:["selective-ui-loading-state","hide"],textContent:t.textLoading,role:"status",ariaLive:"polite"})}show(t){this.node&&this.options&&(this.node.textContent=this.options.textLoading,this.node.classList.toggle("small",!!t),this.node.classList.remove("hide"))}hide(){this.node&&this.node.classList.add("hide")}get isVisible(){return!!this.node&&!this.node.classList.contains("hide")}}class u{constructor(){this.Ot=!1,this.element=null,this.Ct=null,this.At=null,this.Ot=!0,this.St=this.Lt.bind(this)}Pt(t){}Lt(){const t=this.element;if(!t||"function"!=typeof t.getBoundingClientRect)return void this.Pt({width:0,height:0,top:0,left:0,padding:{top:0,right:0,bottom:0,left:0},border:{top:0,right:0,bottom:0,left:0},margin:{top:0,right:0,bottom:0,left:0}});const i=t.getBoundingClientRect(),s="undefined"!=typeof window&&"function"==typeof window.getComputedStyle?window.getComputedStyle(t):null;this.Pt({width:i?.width??0,height:i?.height??0,top:i?.top??0,left:i?.left??0,padding:{top:parseFloat(s?.paddingTop??"0"),right:parseFloat(s?.paddingRight??"0"),bottom:parseFloat(s?.paddingBottom??"0"),left:parseFloat(s?.paddingLeft??"0")},border:{top:parseFloat(s?.borderTopWidth??"0"),right:parseFloat(s?.borderRightWidth??"0"),bottom:parseFloat(s?.borderBottomWidth??"0"),left:parseFloat(s?.borderLeftWidth??"0")},margin:{top:parseFloat(s?.marginTop??"0"),right:parseFloat(s?.marginRight??"0"),bottom:parseFloat(s?.marginBottom??"0"),left:parseFloat(s?.marginLeft??"0")}})}ot(){this.Lt()}connect(t){if(!(t instanceof Element))throw Error("Invalid element");this.element=t,this.Ct=new ResizeObserver(this.St),this.Ct.observe(t),this.At=new MutationObserver(this.St),this.At.observe(t,{attributes:!0,attributeFilter:["style","class"]}),window.addEventListener("scroll",this.St,!0),window.addEventListener("resize",this.St),window.visualViewport&&(window.visualViewport.addEventListener("resize",this.St),window.visualViewport.addEventListener("scroll",this.St))}disconnect(){this.Ct?.disconnect(),this.At?.disconnect(),this.Pt=()=>{},window.removeEventListener("scroll",this.St,!0),window.removeEventListener("resize",this.St),window.visualViewport&&(window.visualViewport.removeEventListener("resize",this.St),window.visualViewport.removeEventListener("scroll",this.St)),this.Ct=null,this.At=null,this.element=null}}class d{constructor(t=null,i=null,s=null){this.options=null,this.Mt=!1,this.Ht=null,this.node=null,this.$t=null,this.jt=null,this.Et=null,this.Ft=null,this.It=null,this.Vt=null,this.kt=null,this.Rt=null,this._t=null,this.Dt=null,this.Nt=s,t&&i&&this.init(t,i)}init(t,i){if(!this.Nt)throw Error("Popup requires a ModelManager instance.");this.Ft=new l(i),this.It=new a(i),this.Vt=new c(i);const s=e.$({Bt:{tag:{node:"div",classList:"selective-ui-popup",style:{maxHeight:i.panelHeight}},j:{wt:{tag:this.Ft.node},zt:{tag:{id:i.Gt,node:"div",classList:"selective-ui-options-container",role:"listbox"}},Ut:{tag:this.Vt.node},Wt:{tag:this.It.node}}}},null);this.node=s.view,this.Rt=s.tags.zt,this.Et=e.R(t),this.options=i,this.Nt.load(this.Rt,{isMultiple:i.multiple});const n=this.Nt.qt();this.Ht=n.Jt,this.kt=n.kt,this.Ft.xt(()=>{n.Jt.Kt(!0)}),this.Ft.Tt(()=>{n.Jt.Kt(!1)}),this.Qt()}async Yt(){this.options&&this.Vt&&this.Ft&&this.Ht&&this.Nt&&(this.Dt&&clearTimeout(this.Dt),this.Nt.Xt(!0),!1!==e.V(this.options.loadingfield)&&(this.Vt.show(this.Ht.ti().Zt),this.Ft.hide(),this.ii()))}async si(){this.options&&this.Vt&&this.Ht&&this.Nt&&(this.Dt&&clearTimeout(this.Dt),this.Dt=setTimeout(()=>{this.Nt?.Xt(!1),this.Vt?.hide();const t=this.Ht?.ti();this.ei(t??void 0),this.ii()},200))}Qt(){this.Ht&&(this.Ht.ni(t=>{this.ei(t)}),this.Ht.hi("items",()=>{const t=this.Ht.ti();this.ei(t),this.ii()}))}ei(t){if(!(this.Ht&&this.It&&this.Ft&&this.Rt))return;const i=t??this.Ht.ti();i.isEmpty?(this.It.show("nodata"),this.Rt.classList.add("hide"),this.Ft.hide()):i.Zt?(this.It.hide(),this.Rt.classList.remove("hide"),this.Ft.refresh()):(this.It.show("notfound"),this.Rt.classList.add("hide"),this.Ft.hide())}oi(t,i){this.Ht?.ri(t,i)}li(t,i){this.Ht?.hi(t,i)}ai(t){this.$t=t}open(t=null){if(!(this.node&&this.options&&this.Ft&&this.Et&&this.$t))return;this.Mt||(document.body.appendChild(this.node),this.Mt=!0,this.jt=new u,this.$t.ci(this.node),this.node.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()})),this.Ft.refresh(),this.ei();const i=this.ui(),{position:s,top:e,maxHeight:n,di:h}=this.pi(i);this.$t.expand({duration:this.options.animationtime,display:"flex",width:i.width,left:i.left,top:e,maxHeight:n,di:h,position:s,gi:()=>{this.jt&&this.Et&&(this.jt.Pt=()=>{const t=this.ui();this.fi(t)},this.jt.connect(this.Et.container.tags.mi),t?.())}})}close(t=null){this.Mt&&this.options&&this.jt&&this.$t&&(this.jt.disconnect(),this.$t.collapse({duration:this.options.animationtime,gi:t??void 0}))}ii(){this.Mt&&this.jt?.ot()}bi(t,i){this.node&&(this._t=async()=>{const i=t.wi();if(!i.yi)return;const s=this.node;if(s.scrollHeight-s.scrollTop-s.clientHeight<100&&!i.xi&&i.hasMore){const i=await t.Ti();!i.Oi&&i.message&&console.log("Load more:",i.message)}},this.node.addEventListener("scroll",this._t))}Ci(){this.Dt&&(clearTimeout(this.Dt),this.Dt=null),this.node&&this._t&&(this.node.removeEventListener("scroll",this._t),this._t=null);try{this.jt?.disconnect()}catch(t){}this.jt=null;try{this.$t?.ci?.(null)}catch(t){}if(this.$t=null,this.node)try{const t=this.node.cloneNode(!0);this.node.replaceWith(t),t.remove()}catch(t){this.node.remove()}this.node=null,this.Rt=null;try{this.Nt?.Xt?.(!1),this.kt?.clear?.(),this.kt=null,this.Ht=null,this.node.remove()}catch(t){}this.Nt=null,this.Ft=null,this.It=null,this.Vt=null,this.Et=null,this.options=null,this.Mt=!1}ui(){const t=this.Et.container.tags.mi,i=t.getBoundingClientRect(),s=window.getComputedStyle(t),n=window.visualViewport,h=e.Y();return{width:i.width,height:i.height,top:i.top-(n&&h?n.offsetTop:0),left:i.left-(n&&h?n.offsetLeft:0),padding:{top:parseFloat(s.paddingTop),right:parseFloat(s.paddingRight),bottom:parseFloat(s.paddingBottom),left:parseFloat(s.paddingLeft)},border:{top:parseFloat(s.borderTopWidth),right:parseFloat(s.borderRightWidth),bottom:parseFloat(s.borderBottomWidth),left:parseFloat(s.borderLeftWidth)}}}pi(t){const i=window.visualViewport,s=e.Y(),n=i?.height??window.innerHeight,h=i&&s?i.offsetTop:0,o=this.$t.Ai("flex").scrollHeight,r=parseFloat(this.options?.panelHeight??"220")||220,l=parseFloat(this.options?.panelMinHeight??"100")||100,a=n-(t.top+t.height)-3,c=t.top-3;let u="bottom",d=r,p=Math.min(o,d);const g=a-15;return(p>=l?g>=l:g>=p)?(u="bottom",d=Math.min(a-15,r)):c>=Math.max(p,l)?(u="top",d=Math.min(c-15,r)):a>=c?(u="bottom",d=Math.max(a-15,l)):(u="top",d=Math.max(c-15,l)),p=Math.min(o,d),{position:u,top:"bottom"===u?t.top+t.height+3+h:t.top-p-3+h,maxHeight:d,di:p,Si:o}}fi(t){if(!this.options||!this.$t)return;const{position:i,top:s,maxHeight:e,di:n}=this.pi(t);this.$t.resize({duration:this.options.animationtime,width:t.width,left:t.left,top:s,maxHeight:e,di:n,position:i,animate:!0})}}class p{constructor(t=null){this.gt=null,this.node=null,this.Li=null,this.Pi=null,this.options=null,this.Mi=null,this.Hi=null,this.$i=null,this.options=t,t&&this.init(t)}init(t){this.gt=e.$({ji:{tag:{node:"div",classList:["selective-ui-searchbox","hide"]},j:{Li:{tag:{id:e.m(),node:"input",type:"search",classList:["selective-ui-searchbox-input"],placeholder:t.placeholder,role:"searchbox",S:t.Gt,M:"list"}}}}}),this.node=this.gt.view,this.Li=this.gt.tags.Li;let i=!1;const s=this.gt.tags.Li;s.addEventListener("mousedown",t=>{t.stopPropagation()}),s.addEventListener("mouseup",t=>{t.stopPropagation()}),s.addEventListener("keydown",t=>{i=!1,"ArrowDown"===t.key||"Tab"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.Mi?.(1)):"ArrowUp"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.Mi?.(-1)):"Enter"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.Hi?.()):"Escape"===t.key&&(t.preventDefault(),t.stopPropagation(),i=!0,this.$i?.())}),s.addEventListener("input",()=>{i||this.Pi?.(s.value,!0)})}show(){this.node&&this.Li&&this.options&&(this.node.classList.remove("hide"),this.Li.readOnly=!this.options.searchable,this.options.searchable&&requestAnimationFrame(()=>{this.Li?.focus()}))}hide(){this.node&&this.node.classList.add("hide")}clear(t=!0){this.gt&&(this.gt.tags.Li.value="",this.Pi?.("",t))}Ei(t){this.Li&&(this.Li.placeholder=e.q(t))}Fi(t){this.Li&&this.Li.setAttribute("aria-activedescendant",t)}}class g{constructor(t=null){this.Ii=null,this.Vi=null,this.ki=!1,t&&this.ci(t)}ci(t){if("string"==typeof t){const i=document.querySelector(t);return void(i instanceof HTMLElement&&(this.element=i))}this.element=t}cancel(){return this.Ii&&(clearTimeout(this.Ii),this.Ii=null),this.Vi&&(clearTimeout(this.Vi),this.Vi=null),this.ki=!1,this}Ai(t="flex"){if(!this.element)return{width:0,height:0,scrollHeight:0};const i={display:this.element.style.display,visibility:this.element.style.visibility,position:this.element.style.position,height:this.element.style.height,width:this.element.style.width};Object.assign(this.element.style,{display:t,visibility:"hidden",position:"fixed",height:"fit-content",width:"fit-content"});const s=window.getComputedStyle(this.element),e=parseFloat(s.borderTopWidth),n=parseFloat(s.borderBottomWidth),h=this.element.scrollHeight+e+n,o=this.element.getBoundingClientRect(),r={width:o.width,height:o.height+e+n,scrollHeight:h};return Object.assign(this.element.style,i),r}expand(t){if(!this.element)return this;this.cancel(),this.ki=!0;const{duration:i=200,display:s="flex",width:e,left:n,top:h,maxHeight:o,di:r,position:l="bottom",gi:a}=t;return Object.assign(this.element.style,{display:s,width:e+"px",left:n+"px",top:("bottom"===l?h:h+r)+"px",maxHeight:o+"px",height:"0px",opacity:"0",overflow:"hidden",transition:"none"}),this.element.classList.toggle("position-top","top"===l),this.element.classList.toggle("position-bottom","bottom"===l),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`top ${i}ms, height ${i}ms, opacity ${i}ms`,top:h+"px",height:r+"px",opacity:"1",overflow:r>=o?"auto":"hidden"}),this.Ii=setTimeout(()=>{this.element.style.transition="none",this.ki=!1,a?.()},i)}),this}collapse(t){if(!this.element)return this;this.cancel(),this.ki=!0;const{duration:i=200,gi:s}=t,e=this.element.offsetHeight,n=this.element.offsetTop,h=this.element.classList.contains("position-top")?"top":"bottom",o=this.element.scrollHeight-this.element.offsetHeight>0,r="top"===h?n+e:n;return requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`height ${i}ms, top ${i}ms, opacity ${i}ms`,height:"0px",top:r+"px",opacity:"0",overflow:o?"auto":"hidden"}),this.Ii=setTimeout(()=>{Object.assign(this.element.style,{display:"none",transition:"none"}),this.ki=!1,s?.()},i)}),this}showSwipeWidth(t){if(!this.element)return this;this.cancel(),this.ki=!0;const{duration:i=200,display:s="block",gi:e}=t;Object.assign(this.element.style,{transition:"none",display:s,width:"fit-content"});const n=this.Ai(s).width;return Object.assign(this.element.style,{width:"0px"}),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`width ${i}ms`,width:n+"px",overflow:"hidden"})}),this.Ii=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:""}),this.ki=!1,e?.()},i),this}hideSwipeWidth(t){if(!this.element)return this;this.cancel(),this.ki=!0;const{duration:i=200,gi:s}=t,e=this.Ai().width;return Object.assign(this.element.style,{transition:"none",width:e+"px"}),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`width ${i}ms`,width:"0px",overflow:"hidden"})}),this.Ii=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:"",display:""}),this.ki=!1,s?.()},i),this}resize(t){if(!this.element)return this;this.Vi&&clearTimeout(this.Vi);const{duration:i=200,width:s,left:e,top:n,maxHeight:h,di:o,position:r="bottom",animate:l=!0,gi:a}=t,c=(this.element.classList.contains("position-top")?"top":"bottom")!==r,u=this.element.scrollHeight>h;return this.element.classList.toggle("position-top","top"===r),this.element.classList.toggle("position-bottom","bottom"===r),c&&(this.element.style.transition=`top ${i}ms ease-out, height ${i}ms ease-out, max-height ${i}ms ease-out;`),requestAnimationFrame(()=>{const t={width:s+"px",left:e+"px",top:n+"px",maxHeight:h+"px",height:o+"px",overflowY:u?"auto":"hidden"},r=Math.abs(this.element.offsetHeight-o);l&&(c||r>5)?t.transition=`height ${i}ms, top ${i}ms`:this.Vi=setTimeout(()=>{this.element?.style&&(this.element.style.transition="none")},i),Object.assign(this.element.style,t),l&&(c||r>1)?this.Vi=setTimeout(()=>{this.element.style.transition="none",c&&delete this.element.style.transition,a?.()},i):(c&&delete this.element.style.transition,a?.())}),this}get Ri(){return this.ki}}class f{get value(){return this.targetElement?.getAttribute("value")??null}constructor(t,i=null,s=null){this.targetElement=null,this.view=null,this.position=-1,this.Ot=!1,this.options=t,this.targetElement=i,this.view=s}update(t){this.targetElement=t,this._i()}_i(){}}class m extends f{constructor(t,i){super(t,i??null,null),this.label="",this.items=[],this.collapsed=!1,this.Di=[],i&&(this.label=i.label,this.collapsed=e.V(i.dataset?.collapsed))}get value(){return this.items.map(t=>t.value)}get Ni(){return this.items.filter(t=>t.selected)}get Bi(){return this.items.filter(t=>t.visible)}get zi(){return this.Bi.length>0}update(t){this.label=t.label,this.view?.Gi(this.label)}_i(){this.view&&(this.view.Gi(this.label),this.view.Ui(this.collapsed))}Wi(t){this.Di.push(t)}qi(){this.collapsed=!this.collapsed,this.view?.Ui(this.collapsed),n.ht([this,this.collapsed],...this.Di)}Ji(t){this.items.push(t),t.group=this}removeItem(t){const i=this.items.indexOf(t);i>-1&&(this.items.splice(i,1),t.group=null)}Ki(){this.view?.Ki()}}class b extends f{constructor(){super(...arguments),this.Qi=[],this.Yi=[],this.Xi=[],this.Zi=!0,this.ts=!1,this.group=null}get ss(){return this.dataset?.imgsrc||this.dataset?.image||""}get hasImage(){return!!this.ss}get value(){return this.targetElement?.value??""}get selected(){return!!this.targetElement?.selected}set selected(t){this.es=t,n.ht([this,t],...this.Qi)}get visible(){return this.Zi}set visible(t){if(this.Zi===t)return;this.Zi=t;const i=this.view?.ns?.();i&&i.classList.toggle("hide",!t),n.ht([this,t],...this.Xi)}get es(){return this.selected}set es(t){const i=this.view?.view?.tags?.hs,s=this.view?.ns?.();i&&(i.checked=t),s&&this.targetElement&&(s.classList.toggle("checked",!!t),s.setAttribute("aria-selected",t?"true":"false"),this.targetElement.toggleAttribute("selected",!!t)),this.targetElement&&(this.targetElement.selected=t),n.ht([this,t],...this.Yi)}get text(){const t=e.W(this.dataset?.mask??this.targetElement?.text??"");return this.options.allowHtml?t:e.q(t)}get textContent(){return this.options.allowHtml?e.q(this.text).trim():this.text.trim()}get dataset(){return this.targetElement?.dataset??{}}get rs(){return this.ts}set rs(t){const i=!!t,s=this.view?.ns?.();this.ts!==i&&(this.ts=i),s&&s.classList.toggle("highlight",i)}ls(t){this.Qi.push(t)}cs(t){this.Yi.push(t)}ni(t){this.Xi.push(t)}_i(){if(!this.view)return;const t=this.view.view.tags.us;t&&(this.options.allowHtml?t.innerHTML=this.text:t.textContent=this.textContent);const i=this.view.view.tags.ds;i&&this.hasImage&&(i.src=this.ss,i.alt=this.text),this.targetElement&&(this.es=this.targetElement.selected)}}class w{constructor(t){this.ps=[],this.gs=null,this.fs=null,this.bs=null,this.options=null,this.options=t}ws(t){this.ys=t}vs(t){this.xs=t}Ts(t){const i=this.Os(t),s=i!==this.bs;return s&&(this.bs=i),s}Os(t){return t.map(t=>{if("OPTGROUP"===t.tagName){const i=t,s=Array.from(i.children).map(t=>`${t.value}:${t.text}:${t.selected}`).join("\n");return`G:${i.label}:${s}`}return`O:${t.value}:${t.text}:${t.selected}`}).join("\n\n")}Cs(t){this.ps=[];let i=null;return t.forEach(t=>{if("OPTGROUP"===t.tagName)i=new m(this.options,t),this.ps.push(i);else if("OPTION"===t.tagName){const s=t,e=new b(this.options,s),n=s.__parentGroup;n&&i&&n===i.targetElement?(i.Ji(e),e.group=i):(this.ps.push(e),i=null)}}),this.ps}replace(t){this.bs=null,this.Cs(t),this.gs&&this.gs.As(this.ps),this.refresh()}notify(){this.gs&&this.refresh()}load(t,i={},s={}){this.gs=new this.ys(this.ps),Object.assign(this.gs,i),this.fs=new this.xs(t),this.fs.Ss(this.gs),Object.assign(this.fs,s)}update(t){if(!this.Ts(t))return;const i=this.ps,s=[],e=new Map,n=new Map;i.forEach(t=>{t instanceof m?e.set(t.label,t):t instanceof b&&n.set(`${t.value}::${t.textContent}`,t)});let h=null,o=0;t.forEach(t=>{if("OPTGROUP"===t.tagName){const i=t,n=e.get(i.label);n?(n.label!==i.label&&n.update(i),n.position=o,n.items=[],h=n,s.push(n),e.delete(i.label)):(h=new m(this.options,i),h.position=o,s.push(h)),o++}else if("OPTION"===t.tagName){const i=t,e=`${i.value}::${i.text}`,r=n.get(e);if(r)r.update(i),r.position=o,i.__parentGroup&&h?(h.Ji(r),r.group=h):(r.group=null,s.push(r)),n.delete(e);else{const t=new b(this.options,i);t.position=o,i.__parentGroup&&h?(h.Ji(t),t.group=h):s.push(t)}o++}}),e.forEach(t=>{t.view?.ns?.()?.remove?.()}),n.forEach(t=>{t.view?.ns?.()?.remove?.()}),this.ps=s,this.gs&&this.gs.Ls(this.ps),this.onUpdated(),this.refresh()}onUpdated(){}Xt(t){this.gs&&(this.gs.Ps=t)}refresh(){this.fs&&(this.fs.refresh(),this.onUpdated())}qt(){return{Ms:this.ps,Jt:this.gs,kt:this.fs}}Hs(t){this.gs?.$s(t)}js(t){this.gs?.Es(t)}}class y{constructor(t=null){this.Fs=null,this.Jt=null,this.Fs=t}Is(t){this.Fs=t}Ss(t){this.Jt=t,t.ri("items",()=>{this.clear()}),t.hi("items",()=>{this.Vs()}),this.Vs()}clear(){this.Fs&&this.Fs.replaceChildren()}Vs(){this.Jt&&this.Fs&&this.Jt.ks(this.Fs)}refresh(){this.Vs()}}class v{constructor(t=null){this.gt=null,this.node=null,this.options=null,this.Rs=null,this._s=null,this.Ds=null,t&&this.init(t)}init(t){this.gt=e.$({Ns:{tag:{node:"div",classList:["selective-ui-accessorybox","hide"],onmouseup:t=>{t.stopPropagation()}}}}),this.node=this.gt.view,this.options=t}Bs(t){this.Rs=t,this._s=t.parentElement,this.zs()}zs(){this._s&&this.node&&this.Rs&&this.options&&this._s.insertBefore(this.node,"top"===this.options.accessoryStyle?this.Rs:this.Rs.nextSibling)}Gs(t){this.Ds=t}Us(t){this.node&&this.options&&(this.node.replaceChildren(),t.length>0&&this.options.multiple?(this.node.classList.remove("hide"),t.forEach(t=>{e.$({Ws:{tag:{node:"div",classList:["accessory-item"]},j:{qs:{tag:{node:"span",classList:["accessory-item-button"],role:"button",ariaLabel:`${this.options.textAccessoryDeselect}${t.textContent}`,title:`${this.options.textAccessoryDeselect}${t.textContent}`,onclick:i=>{i.preventDefault(),this.Ds?.Hs?.("select"),setTimeout(()=>{t.selected=!1},10)}}},Js:{tag:{node:"span",classList:["accessory-item-content"],innerHTML:t.text}}}}},this.node)})):this.node.classList.add("hide"),n.ot(window,"resize"))}}class x{constructor(t,i){this.Ks=null,this.Qs=null,this.Ys=null,this.Xs={currentPage:0,totalPages:1,hasMore:!1,xi:!1,Zs:"",yi:!1},this.te=t,this.Nt=i}ie(){return!!this.Ks}async se(t){if(!this.Ks)return{Oi:!1,items:[],message:"Ajax not configured"};const i=Array.isArray(t)?t:[t];if(0===i.length)return{Oi:!0,items:[]};try{const t=this.Ks;let s,e;if(s="function"==typeof t.ee?t.ee(i):{values:i.join(","),ne:"1",..."function"==typeof t.data?t.data("",0):t.data??{}},"POST"===(t.method??"GET")){const i=new URLSearchParams;Object.keys(s).forEach(t=>i.append(t,s[t]+"")),e=await fetch(t.url,{method:"POST",body:i,headers:{"Content-Type":"application/x-www-form-urlencoded"}})}else{const i=""+new URLSearchParams(s);e=await fetch(`${t.url}?${i}`)}if(!e.ok)throw Error("HTTP error! status: "+e.status);const n=await e.json();return{Oi:!0,items:this.he(n).items}}catch(s){return console.error("Load by values error:",s),{Oi:!1,message:s?.message,items:[]}}}oe(t){const i=Array.from(this.te.options).map(t=>t.value);return{re:t.filter(t=>i.includes(t)),le:t.filter(t=>!i.includes(t))}}ae(t){this.Ks=t}setPopup(t){this.Ys=t}wi(){return{...this.Xs}}ce(){this.Xs={currentPage:0,totalPages:1,hasMore:!1,xi:!1,Zs:"",yi:this.Xs.yi}}clear(){this.Xs.Zs="";const{Ms:t}=this.Nt.qt(),i=[];for(const s of t)s instanceof b?i.push(s):s instanceof m&&Array.isArray(s.items)&&i.push(...s.items);i.forEach(t=>{t.visible=!0})}async search(t,i=!1){return this.Ks?this.ue(t,i):this.de(t)}async Ti(){return this.Ks?this.Xs.xi?{Oi:!1,message:"Already loading"}:this.Xs.yi?this.Xs.hasMore?(this.Xs.currentPage++,this.ue(this.Xs.Zs,!0)):{Oi:!1,message:"No more data"}:{Oi:!1,message:"Pagination not enabled"}:{Oi:!1,message:"Ajax not enabled"}}async de(t){this.pe(t)&&(this.Xs.Zs=t);const i=((t??"")+"").toLowerCase(),s=e.J(i),{Ms:n}=this.Nt.qt(),h=[];for(const e of n)e instanceof b?h.push(e):e instanceof m&&Array.isArray(e.items)&&h.push(...e.items);let o=!1;return h.forEach(t=>{const n=((t.textContent??t.text??"")+"").toLowerCase(),h=e.J(n),r=""===i||n.includes(i)||h.includes(s);t.visible=r,r&&(o=!0)}),{Oi:!0,ge:o,isEmpty:0===h.length}}pe(t){return t!==this.Xs.Zs}async ue(t,i=!1){const s=this.Ks;this.pe(t)&&(this.ce(),this.Xs.Zs=t,i=!1),this.Xs.xi=!0,this.Ys?.Yt(),this.Qs?.abort(),this.Qs=new AbortController;const e=this.Xs.currentPage,n=Array.from(this.te.selectedOptions).map(t=>t.value).join(",");let h;"function"==typeof s.data?(h=s.data(t,e),h&&void 0===h.fe&&(h.fe=n)):h={search:t,page:e,fe:n,...s.data??{}};try{let t;if("POST"===(s.method??"GET")){const i=new URLSearchParams;Object.keys(h).forEach(t=>i.append(t,h[t]+"")),t=await fetch(s.url,{method:"POST",body:i,headers:{"Content-Type":"application/x-www-form-urlencoded"},signal:this.Qs.signal})}else{const i=""+new URLSearchParams(h);t=await fetch(`${s.url}?${i}`,{signal:this.Qs.signal})}const e=await t.json(),n=this.he(e);return n.me?(this.Xs.yi=!0,this.Xs.currentPage=n.page,this.Xs.totalPages=n.totalPages,this.Xs.hasMore=n.hasMore):this.Xs.yi=!1,this.be(n.items,!!s.keepSelected,i),this.Xs.xi=!1,this.Ys?.si(),{Oi:!0,ge:n.items.length>0,isEmpty:0===n.items.length,me:n.me,hasMore:n.hasMore,currentPage:n.page,totalPages:n.totalPages}}catch(o){return this.Xs.xi=!1,this.Ys?.si(),"AbortError"===o?.name?{Oi:!1,message:"Request aborted"}:(console.error("Ajax search error:",o),{Oi:!1,message:o?.message})}}he(t){let i=[],s=!1,e=0,n=1,h=!1;return t.object&&Array.isArray(t.object)?(i=t.object,void 0!==t.page&&(s=!0,e=parseInt(t.page??0,10),n=parseInt(t.totalPages??t.total_page??1,10),h=e<n-1)):t.data&&Array.isArray(t.data)?(i=t.data,void 0!==t.page&&(s=!0,e=parseInt(t.page??0,10),n=parseInt(t.totalPages??t.total_page??1,10),h=t.hasMore??e<n-1)):Array.isArray(t)?i=t:t.items&&Array.isArray(t.items)&&(i=t.items,t.pagination&&(s=!0,e=parseInt(t.pagination.page??0,10),n=parseInt(t.pagination.totalPages??t.pagination.total_page??1,10),h=t.pagination.hasMore??e<n-1)),{items:i.map(t=>{if(t instanceof HTMLOptionElement||t instanceof HTMLOptGroupElement)return t;if("optgroup"===t.type||t.we||t.group||t.label)return{type:"optgroup",label:t.label??t.name??t.title??"",data:t.data??{},options:(t.options??t.items??[]).map(t=>({value:t.value??t.id??t.key??"",text:t.text??t.label??t.name??t.title??"",selected:t.selected??!1,data:t.data??(t.imgsrc?{imgsrc:t.imgsrc}:{})}))};const i=t.data??{};return t?.imgsrc&&(i.imgsrc=t.imgsrc),{type:"option",value:t.value??t.id??t.key??"",text:t.text??t.label??t.name??t.title??"",selected:t.selected??!1,data:i}}),me:s,page:e,totalPages:n,hasMore:h}}be(t,i,s=!1){const e=this.te;let n=[];i&&(n=Array.from(e.selectedOptions).map(t=>t.value)),s||(e.innerHTML=""),t.forEach(t=>{if("option"!==t.type&&t.type||""!==t.value||""!==t.text)if(t instanceof HTMLOptionElement||t instanceof HTMLOptGroupElement)e.appendChild(t);else if("optgroup"===t.type){const s=document.createElement("optgroup");s.label=t.label,t.data&&Object.keys(t.data).forEach(i=>{s.dataset[i]=t.data[i]+""}),Array.isArray(t.options)&&t.options.forEach(t=>{const e=document.createElement("option");e.value=t.value,e.text=t.text,t.data&&Object.keys(t.data).forEach(i=>{e.dataset[i]=t.data[i]+""}),(t.selected||i&&n.includes(e.value))&&(e.selected=!0),s.appendChild(e)}),e.appendChild(s)}else{const s=document.createElement("option");s.value=t.value,s.text=t.text,t.data&&Object.keys(t.data).forEach(i=>{s.dataset[i]=t.data[i]+""}),(t.selected||i&&n.includes(s.value))&&(s.selected=!0),e.appendChild(s)}}),e.dispatchEvent(new CustomEvent("options:changed"))}}class T{constructor(t){this.ye=null,this.ve=null,this.xe=50,this.te=t,this.ve=this.Te(),this.Oe=new MutationObserver(()=>{this.ye&&clearTimeout(this.ye),this.ye=setTimeout(()=>{this.Ce()},this.xe)}),t.addEventListener("options:changed",()=>{this.ye&&clearTimeout(this.ye),this.ye=setTimeout(()=>{this.Ce()},this.xe)})}Te(){const t=Array.from(this.te.options);return{length:t.length,values:t.map(t=>t.value).join(","),Ae:t.map(t=>t.text).join(","),selected:t.map(t=>t.selected+"").join(",")}}Se(){const t=this.Te(),i=JSON.stringify(t)!==JSON.stringify(this.ve);return i&&(this.ve=t),i}Ce(){this.Se()&&this.Pt(this.te)}connect(){this.Oe.observe(this.te,{childList:!0,subtree:!1,attributes:!0,attributeFilter:["selected","value","disabled"]})}Pt(t){}disconnect(){this.ye&&clearTimeout(this.ye),this.ye=null,this.Oe.disconnect()}}class O{constructor(t){this.ye=null,this.Le=t,this.Oe=new MutationObserver(t=>{let i=!1;for(const s of t)if("attributes"===s.type&&s.attributeName?.startsWith("data-")){i=!0;break}i&&(this.ye&&clearTimeout(this.ye),this.ye=setTimeout(()=>{this.Pt({...this.Le.dataset})},50))}),t.addEventListener("dataset:changed",()=>{this.Pt({...this.Le.dataset})})}connect(){this.Oe.observe(this.Le,{attributes:!0,attributeOldValue:!0})}Pt(t){}disconnect(){this.ye&&clearTimeout(this.ye),this.ye=null,this.Oe.disconnect()}}class C{constructor(t=[]){this.items=[],this.Pe=e.m(12),this.Ps=!1,this.items=t,this.Me()}Me(){}He(t,i,s){const e=i;t.Ot?e?.update?.():e?.Vs?.()}ri(t,i){e.Z.on(`${t}ing_${this.Pe}`,i,{st:1})}hi(t,i){e.Z.on(`${t}_${this.Pe}`,i)}Es(t,...i){e.Z.run(`${t}_${this.Pe}`,...i)}$s(t,...i){e.Z.run(`${t}ing_${this.Pe}`,...i)}$e(t,i){return null}je(){return this.items.length}Ee(t){this.$s("items",t),this.items=t,this.Es("items",t)}As(t){this.Ee(t)}ks(t){for(let i=0;i<this.je();i++){const s=this.items[i];let e=s.view;s.Ot||(e=this.$e(t,s),s.view=e),this.He(s,e,i),s.Ot=!0}}Ls(t){}}class A{constructor(t){this.parent=null,this.view=null,this.parent=t}Vs(){}update(){}ns(){if(!this.view?.view)throw Error("View is not mounted. Did you forget to set this.view?");return this.view.view}}class S extends A{constructor(){super(...arguments),this.view=null}Vs(){const t=e.m(7);this.view=e.H({Fe:{tag:{node:"div",classList:["selective-ui-group"],role:"group",A:`seui-${t}-header`,id:`seui-${t}-group`},j:{Ie:{tag:{node:"div",classList:["selective-ui-group-header"],role:"presentation",id:`seui-${t}-header`}},Ve:{tag:{node:"div",classList:["selective-ui-group-items"],role:"group"}}}}}),this.parent.appendChild(this.view.view)}update(){this.Gi()}Gi(t=null){this.view&&null!==t&&(this.view.tags.Ie.textContent=t)}ke(){if(!this.view)throw Error("GroupView is not rendered.");return this.view.tags.Ve}Ki(){if(!this.view)return;const t=Array.from(this.view.tags.Ve.children).filter(t=>!t.classList.contains("hide"));this.view.view.classList.toggle("hide",!(t.length>0))}Ui(t){this.view&&(this.view.view.classList.toggle("collapsed",t),this.view.tags.Ie.setAttribute("aria-expanded",t?"false":"true"))}}class L extends A{constructor(t){super(t),this.view=null,this.Re=null,this._e=null,this.De=!1,this.Ne()}Ne(){const t=this;this.Re={isMultiple:!1,hasImage:!1,imagePosition:"right",imageWidth:"60px",imageHeight:"60px",imageBorderRadius:"4px",labelValign:"center",labelHalign:"left"},this._e=new Proxy(this.Re,{set(i,s,e){if("string"!=typeof s)return!0;const n=s,h=i[n];return h!==e&&(i[n]=e,t.De&&t.Be(n,e,h)),!0}})}get isMultiple(){return this.Re.isMultiple}set isMultiple(t){this._e.isMultiple=!!t}get hasImage(){return this.Re.hasImage}set hasImage(t){this._e.hasImage=!!t}get ze(){return this._e}set ze(t){if(!t||!this._e||!this.Re)return;const i={};void 0!==t.imageWidth&&t.imageWidth!==this.Re.imageWidth&&(i.imageWidth=t.imageWidth),void 0!==t.imageHeight&&t.imageHeight!==this.Re.imageHeight&&(i.imageHeight=t.imageHeight),void 0!==t.imageBorderRadius&&t.imageBorderRadius!==this.Re.imageBorderRadius&&(i.imageBorderRadius=t.imageBorderRadius),void 0!==t.imagePosition&&t.imagePosition!==this.Re.imagePosition&&(i.imagePosition=t.imagePosition),void 0!==t.labelValign&&t.labelValign!==this.Re.labelValign&&(i.labelValign=t.labelValign),void 0!==t.labelHalign&&t.labelHalign!==this.Re.labelHalign&&(i.labelHalign=t.labelHalign),Object.keys(i).length>0&&Object.assign(this._e,i)}Vs(){const t=["selective-ui-option-view"],i=e.m(7),s="option_"+i;this.Re.isMultiple&&t.push("multiple"),this.Re.hasImage&&(t.push("has-image"),t.push("image-"+this.Re.imagePosition));const n={hs:{tag:{node:"input",type:this.Re.isMultiple?"checkbox":"radio",classList:"allow-choice",id:s}},...this.Re.hasImage&&{ds:{tag:{node:"img",classList:"option-image",style:{width:this.Re.imageWidth,height:this.Re.imageHeight,borderRadius:this.Re.imageBorderRadius}}}},Ge:{tag:{node:"label",htmlFor:s,classList:["align-vertical-"+this.Re.labelValign,"align-horizontal-"+this.Re.labelHalign]},j:{us:{tag:{node:"div"}}}}};this.view=e.H({Ue:{tag:{node:"div",id:`seui-${i}-option`,classList:t,role:"option",ariaSelected:"false",tabIndex:"-1"},j:n}}),this.parent.appendChild(this.view.view),this.De=!0}Be(t,i,s){const e=this.view;if(!e||!e.view)return;const n=e.view,h=e.tags?.hs,o=e.tags?.Ge;switch(t){case"isMultiple":{const t=!!i;n.classList.toggle("multiple",t),h&&h.type!==(t?"checkbox":"radio")&&(h.type=t?"checkbox":"radio");break}case"hasImage":{const t=!!i;if(n.classList.toggle("has-image",t),t)n.classList.add("image-"+this.Re.imagePosition),this.We();else{n.className=n.className.replace(/image-(top|right|bottom|left)/g,"").trim();const t=e.tags?.ds;t&&(t.remove(),e.tags.ds=null)}break}case"imagePosition":this.Re.hasImage&&(n.className=n.className.replace(/image-(top|right|bottom|left)/g,"").trim(),n.classList.add("image-"+i));break;case"imageWidth":case"imageHeight":case"imageBorderRadius":{const s=e.tags?.ds;if(s){const e="imageWidth"===t?"width":"imageHeight"===t?"height":"borderRadius",n=i+"";s.style[e]!==n&&(s.style[e]=n)}break}case"labelValign":case"labelHalign":if(o){const t=`align-vertical-${this.Re.labelValign} align-horizontal-${this.Re.labelHalign}`;o.className!==t&&(o.className=t)}}}We(){const t=this.view;if(!t||!t.view)return;const i=t.tags?.ds;if(i)return;const s=t.view,e=t.tags?.Ge,n=document.createElement("img");n.className="option-image",n.style.width=this.Re.imageWidth,n.style.height=this.Re.imageHeight,n.style.borderRadius=this.Re.imageBorderRadius,e&&e.parentElement?s.insertBefore(n,e):s.appendChild(n),t.tags.ds=n}}class P extends C{constructor(t=[]){super(t),this.isMultiple=!1,this.qe=[],this.Je=-1,this.Ke=null,this.groups=[],this.Qe=[],this.Ye()}Ye(){this.Qe=[],this.groups=[],this.items.forEach(t=>{t instanceof m?(this.groups.push(t),this.Qe.push(...t.items)):t instanceof b&&this.Qe.push(t)})}$e(t,i){return i instanceof m?new S(t):new L(t)}He(t,i,s){t.position=s,t instanceof m?this.Xe(t,i,s):t instanceof b&&this.Ze(t,i,s),t.Ot=!0}Xe(t,i,s){super.He(t,i,s),t.view=i;const e=i.view.tags.Ie;e.textContent=t.label,t.Ot||(e.style.cursor="pointer",e.addEventListener("click",()=>{t.qi()}),t.Wi((t,i,s)=>{i.items.forEach(t=>{const i=t.view?.ns?.();i&&(i.style.display=s?"none":"")}),this.tn(i,s)}));const n=i.ke();t.items.forEach((t,i)=>{let s=t.view;t.Ot&&s||(s=new L(n)),this.Ze(t,s,i),t.Ot=!0}),i.Ui(t.collapsed),i.Ki()}Ze(t,i,s){if(i.isMultiple=this.isMultiple,i.hasImage=t.hasImage,i.ze={imageWidth:t.options.imageWidth,imageHeight:t.options.imageHeight,imageBorderRadius:t.options.imageBorderRadius,imagePosition:t.options.imagePosition,labelValign:t.options.labelValign,labelHalign:t.options.labelHalign},t.Ot||super.He(t,i,s),t.view=i,t.hasImage){const s=i.view.tags.ds;s&&(s.src!==t.ss&&(s.src=t.ss),s.alt!==t.text&&(s.alt=t.text))}i.view.tags.us.innerHTML=t.text,t.Ot||(i.view.tags.Ue.addEventListener("click",i=>{i.stopPropagation(),i.preventDefault(),this.Ps||(this.isMultiple?(this.$s("select"),setTimeout(()=>{t.selected=!t.selected},5)):!0!==t.selected&&(this.$s("select"),setTimeout(()=>{this.Ke&&(this.Ke.selected=!1),t.selected=!0},5)))}),i.view.tags.Ue.title=t.textContent,i.view.tags.Ue.addEventListener("mouseenter",()=>{this.Ps||this.sn(this.Qe.indexOf(t),!1)}),t.ls(()=>{this.Es("selected")}),t.cs((i,s,e)=>{e&&(this.Ke=t),this.Es("selected_internal")}),t.ni((t,i)=>{i.group?.Ki(),this.en()})),t.selected&&(this.Ke=t,t.es=!0)}Ee(t){this.$s("items",t),this.items=t,this.Ye(),this.Es("items",t)}As(t){this.Ee(t)}Ls(t){this.items=t,this.Ye()}nn(){return this.Qe.filter(t=>t.selected)}hn(){return this.Qe.find(t=>t.selected)}Kt(t){this.isMultiple&&this.Qe.forEach(i=>{i.selected=t})}ni(t){this.qe.push(t)}en(){const t=this.Qe.filter(t=>t.visible).length,i=this.Qe.length;this.qe.forEach(s=>{s({rn:t,ln:i,Zt:t>0,isEmpty:0===i})})}ti(){const t=this.Qe.filter(t=>t.visible).length,i=this.Qe.length;return{rn:t,ln:i,Zt:t>0,isEmpty:0===i}}an(){this.sn(0)}navigate(t,i=!0){const s=this.Qe.filter(t=>t.visible);if(0===s.length)return;let e=s.findIndex(t=>t===this.Qe[this.Je]);-1===e&&(e=-1);let n=e+t;n>=s.length&&(n=0),n<0&&(n=s.length-1);const h=this.Qe.indexOf(s[n]);this.sn(h,i)}cn(){if(this.Je>-1&&this.Qe[this.Je]){const t=this.Qe[this.Je];if(t.visible){const i=t.view?.ns?.();i&&i.click()}}}sn(t,i=!0){let s=0;if("number"==typeof t)s=t;else if(t instanceof b){const i=this.Qe.indexOf(t);s=i>-1?i:0}else s=0;this.Je>-1&&this.Qe[this.Je]&&(this.Qe[this.Je].rs=!1);for(let e=s;e<this.Qe.length;e++){const t=this.Qe[e];if(t.visible){if(t.rs=!0,this.Je=e,i){const i=t.view?.ns?.();i&&i.scrollIntoView({un:"center",behavior:"smooth"})}return void this.dn(e,t.view?.ns?.()?.id)}}}dn(t,i){}tn(t,i){}}class M{constructor(t=null,i=null){this.container={},this.oldValue=null,this.node=null,this.options=null,this.pn=null,this.isOpen=!1,this.gn=!1,this.fn=!1,this.mn=null,t&&this.init(t,i)}get isDisabled(){return!!this.options?.disabled}set isDisabled(t){this.options&&this.node&&(this.options.disabled=t,this.node.classList.toggle("disabled",t),this.node.setAttribute("aria-disabled",t+""),this.container.tags?.mi?.setAttribute("aria-disabled",t+""))}get bn(){return!!this.options?.readonly}set bn(t){this.options&&this.node&&(this.options.readonly=t,this.node.classList.toggle("readonly",t))}get isVisible(){return!!this.options?.visible}set isVisible(t){this.options&&this.node&&(this.options.visible=t,this.node.classList.toggle("invisible",!t))}init(t,s){const n=e.R(t).options,l=new o(n),a=new r,c=new p(n),effector=i(),u=new w(n),g=new v(n),f=new x(t,u),m=new T(t),b=new O(t);this.mn=s,this.options=n,l.node&&(l.node.id=(n.wn??"")+"");const C=e.$({yn:{tag:{node:"div",classList:"selective-ui-MAIN"},j:{mi:{tag:{node:"div",classList:"selective-ui-view",tabIndex:0,onkeydown:t=>{"Enter"!==t.key&&" "!==t.key&&"ArrowDown"!==t.key||(t.preventDefault(),this.vn()?.open())}},j:{xn:{tag:l.node},Tn:{tag:a.node},ji:{tag:c.node}}}}}},null);this.container=C,this.node=C.view,t.parentNode?.insertBefore(this.node,t),this.node.insertBefore(t,C.tags.mi),g.Bs(C.tags.mi),g.Gs(u),C.tags.mi.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()}),h.lt(t,C.tags.mi),t.classList.add("init"),u.ws(P),u.vs(y),u.Cs(e.K(t)),u.onUpdated=()=>{C.On?.ii?.()},this.pn=u,C.Cn=f,C.placeholder=l,C.An=a,C.Sn=c,C.effector=effector,C.targetElement=t,C.Ln=g,C.Pn=m,C.Mn=b,C.On=new d(t,n,u),C.On.ai(effector),C.On.bi(f,n),C.On.li("selected",()=>{this.vn()?.change(null,!0)}),C.On.li("selected_internal",()=>{this.vn()?.change(null,!1)}),C.On.oi("select",()=>{this.oldValue=this.vn()?.value??""}),this.vn()?.change(null,!1),m.connect(),m.Pt=t=>{u.update(e.K(t)),this.vn()?.refreshMask()},b.connect(),b.Pt=t=>{e.V(t.disabled)!==this.isDisabled&&(this.isDisabled=e.V(t.disabled)),e.V(t.readonly)!==this.bn&&(this.bn=e.V(t.readonly)),e.V(t.visible)!==this.isVisible&&(this.isVisible=e.V(t.visible??"1"))},t.addEventListener("options:changed",()=>{u.update(e.K(t)),this.vn()?.refreshMask(),C.On?.ii?.()}),n.ajax&&f.ae(n.ajax);const A=C.On.Ht,S=(t,i)=>{i||""!==t?(""!==t&&(this.fn=!0),f.search(t).then(t=>{C.On?.ii?.(),t?.ge&&setTimeout(()=>{A.an()},n.animationtime??0)}).catch(t=>{console.error("Search error:",t)})):f.clear()};let L=null;c.Pi=(t,i)=>{f.pe(t)&&(f.ie()?(L&&clearTimeout(L),C.On?.Yt?.(),L=setTimeout(()=>{S(t,i)},n.delaysearchtime??0)):S(t,i))},f.setPopup(C.On),c.Mi=t=>{A.navigate(t)},c.Hi=()=>{A.cn()},c.$i=()=>{this.vn()?.close(),C.tags.mi.focus()},A.dn=(t,i)=>{i&&c.Fi(i)},A.tn=()=>{C.On?.ii?.()},this.isDisabled=e.V(n.disabled),this.bn=e.V(n.readonly)}Hn(){const t=this.container??{},{Pn:i,Mn:s}=t;i?.disconnect&&i.disconnect(),s?.disconnect&&s.disconnect()}vn(){const t=this.container,i=this,s=e.R(t.targetElement);if(!s)return null;const h=s.options,o={get placeholder(){return t.placeholder.get()},set placeholder(i){t.placeholder?.set(i),t.Sn?.Ei(i)},get oldValue(){return i.oldValue},set value(t){this.setValue(null,t,!0)},get value(){const t=this.valueArray,i=t.length;return i>1?t:0===i?"":t[0]},get valueArray(){const t=[];return i.$n().forEach(i=>{i.selected&&t.push(i.value)}),t},get valueString(){return this.valueArray.join(h.customDelimiter)},get valueOptions(){const t=[];return i.$n().forEach(i=>{i.selected&&t.push(i)}),t},get mask(){const t=[];return i.$n().forEach(i=>{i.selected&&t.push(i.text)}),t},get valueText(){const t=[];i.$n().forEach(i=>{i.selected&&t.push(i.text)});const s=t.length;return s>1?t:0===s?"":t[0]},get isOpen(){return i.isOpen},selectAll(t,s=!0){if(!(h.multiple&&h.maxSelected>0&&i.$n().length>h.maxSelected)&&!this.disabled&&!this.readonly&&h.multiple){if(s){if(n.ht([this],...h.on.beforeChange).isCancel)return;i.oldValue=this.value}i.$n().forEach(t=>{t.es=!0}),this.change(!1,s)}},deSelectAll(t,s=!0){if(!this.disabled&&!this.readonly&&h.multiple){if(s){if(n.ht([this],...h.on.beforeChange).isCancel)return;i.oldValue=this.value}i.$n().forEach(t=>{t.es=!1}),this.change(!1,s)}},setValue(s=null,e,o=!0,r=!1){if(Array.isArray(e)||(e=[e]),0===(e=e.filter(t=>""!==t&&null!=t)).length)return i.$n().forEach(t=>t.es=!1),void this.change(!1,o);if(h.multiple&&h.maxSelected>0&&e.length>h.maxSelected)console.warn(`Cannot select more than ${h.maxSelected} items`);else if(r||!this.disabled&&!this.readonly){if(t.Cn?.ie?.()){const{le:s}=t.Cn.oe(e);if(s.length>0)return void(async()=>{h.loadingfield&&t.On?.Yt?.();try{const n=await t.Cn.se(s);n.Oi&&n.items.length>0?(n.items.forEach(t=>{s.includes(t.value)&&(t.selected=!0)}),t.Cn.be?.(n.items,!0,!0),setTimeout(()=>{i.$n().forEach(t=>{t.es=e.some(i=>i==t.value)}),this.change(!1,!1)},100)):s.length>0&&console.warn(`Could not load ${s.length} values:`,s)}catch(n){console.error("Error loading missing values:",n)}finally{h.loadingfield&&t.On?.si?.()}})()}if(o){if(n.ht([this],...h.on.beforeChange).isCancel)return;i.oldValue=this.value}i.$n().forEach(t=>{t.es=e.some(i=>i==t.value)}),!h.multiple&&e.length>0&&(t.targetElement.value=e[0]),this.change(!1,o)}},open(){if(i.isOpen)return!1;const s=i.mn?.find?.();if(s&&!s.isEmpty&&s.close().isCancel)return!1;if(this.disabled)return!1;if(n.ht([this],...h.on.beforeShow).isCancel)return!1;i.isOpen=!0,t.An.dt(!0);const e=t.On.Ht,o=e.hn();o?e.sn(o,!1):e.an(),i.gn&&!i.fn||!h?.ajax||(t.On.Yt(),i.gn=!0,i.fn=!1,setTimeout(()=>{t.On&&t.Cn&&t.Cn.search("").then(()=>t.On?.ii?.()).catch(t=>console.error("Initial ajax load error:",t))},h.animationtime)),t.On.open(),t.Sn.show();const r=t.tags.mi;return r.setAttribute("aria-expanded","true"),r.setAttribute("aria-controls",h.Gt),r.setAttribute("aria-haspopup","listbox"),r.setAttribute("aria-labelledby",h.wn),h.multiple&&r.setAttribute("aria-multiselectable","true"),n.ht([this],...h.on.show),!0},close(){return!!i.isOpen&&!n.ht([this],...h.on.beforeClose).isCancel&&(i.isOpen=!1,t.An.dt(!1),t.On.close(()=>{t.Sn.clear(!1)}),t.Sn.hide(),t.tags.mi.setAttribute("aria-expanded","false"),n.ht([this],...h.on.close),!0)},toggle(){i.isOpen?this.close():this.open()},change(s=null,e=!0){if(e){if(h.multiple&&h.maxSelected>0&&this.valueArray.length>h.maxSelected&&this.setValue(null,this.oldValue,!1,!0),this.disabled||this.readonly)return void this.setValue(null,this.oldValue,!1,!0);if(n.ht([this,this.value],...h.on.beforeChange).isCancel)return void this.setValue(null,this.oldValue,!1)}this.refreshMask(),t.Ln.Us(this.valueOptions),e&&(t.targetElement&&n.ot(t.targetElement,"change"),n.ht([this,this.value],...h.on.change),i.options?.autoclose&&this.close())},refreshMask(){let s=h.placeholder;!h.multiple&&i.$n().length>0&&(s=this.mask[0]),s??(s=h.placeholder),t.placeholder.set(s,!1),t.Sn.Ei(s)},on(t,i,s){h.on[i]||(h.on[i]=[]),h.on[i].push(s)},ajax(i,s){t.Cn.ae(s)}};return this.jn(o,"disabled","isDisabled"),this.jn(o,"readonly","isReadOnly"),this.jn(o,"visible","isVisible"),o}jn(t,i,s){const e=this;Object.defineProperty(t,i,{get:()=>e[s],set(t){e[s]=!!t,e.container?.targetElement?.dataset&&(e.container.targetElement.dataset[i]=!!t+"")},enumerable:!0,configurable:!0})}$n(t=null){if(!this.pn)return[];const{Ms:i}=this.pn.qt(),s=[];for(const e of i)e instanceof b?s.push(e):e instanceof m&&Array.isArray(e.items)&&e.items.length&&s.push(...e.items);return"boolean"==typeof t?s.filter(i=>i.selected===t):s}Ci(){this.container.On.Ci()}}class H{constructor(){this.En=!1,this.Oe=null,this.Fn=[]}In(t){this.Fn.push(t)}Vn(){this.Fn=[]}start(t){if(this.En)return;this.En=!0;const i=t.toUpperCase(),s=t.toLowerCase();this.Oe=new MutationObserver(t=>{for(const e of t)e.addedNodes.forEach(t=>{if(1!==t.nodeType)return;const e=t;e.tagName===i&&this.kn(e),e.querySelectorAll(s).forEach(t=>this.kn(t))})}),this.Oe.observe(document.body,{childList:!0,subtree:!0})}stop(){this.En&&(this.En=!1,this.Oe?.disconnect(),this.Oe=null)}kn(t){this.Fn.forEach(i=>i(t))}}class ${constructor(){this.Rn=new Map}bind(t,i){const s=e.I(e.G(),i);s.on=s.on??{},s.on.load=s.on.load??[],this.Rn.set(t,s);const h=e.m();e.Z.on(h,()=>{n.ht([this.find(t)],...s.on.load),e.Z.clear(h),s.on.load=[]}),e.v(t).forEach(t=>{(async()=>{"SELECT"===t.tagName&&(e.D(t),this._n(t,s)&&e.Z.run(h))})()}),e.U().includes(t)||e.U().push(t)}find(t="*"){const i={isEmpty:!0};if("*"===t&&""===(t=e.U().join(", ")))return i;const s=e.v(t);if(0===s.length)return i;const n=e.R(s[0]);if(!n||!n.action)return i;const h={};for(const e in n.action)h[e]=this.Dn(e,n.action);const o={isEmpty:!1};for(const e in h){const t=h[e];switch(t.type){case"get-set":this.Nn(o,t.name,s);break;case"func":this.Bn(o,t.name,s)}}return o}zn(){this.Gn=new H,this.Gn.In(t=>{this.Rn.forEach((i,s)=>{try{t.matches(s)&&this._n(t,i)}catch(e){console.warn("Invalid selector: "+s,e)}})}),this.Gn.start("select")}destroy(t=null){null===t?this.Un():"string"==typeof t?this.Wn(t):t instanceof HTMLSelectElement&&this.qn(t)}Un(){e.U().forEach(t=>this.Wn(t)),this.Rn.clear(),e.U().length=0,this.Gn?.stop()}Wn(t){e.v(t).forEach(t=>{"SELECT"===t.tagName&&this.qn(t)}),this.Rn.delete(t);const i=e.U(),s=i.indexOf(t);s>-1&&i.splice(s,1)}qn(t){const i=e.R(t);if(!i)return;const s=i.container?.On;s?.Ci(),e.B(t,i);const n=!!this.Gn;n&&this.Gn?.stop();try{i.self?.Hn?.()}catch(o){}const h=i.container?.element??t.parentElement;t.style.display="",t.style.visibility="",t.disabled=!1,delete t.dataset.Jn,h&&h.parentNode?h.parentNode.replaceChild(t,h):document.body.appendChild(t),e.k(t),n&&this.Rn.size>0&&this.Gn?.start("select")}rebind(t,i){this.Wn(t),this.bind(t,i)}_n(t,i){if(e.R(t)||e.N(t))return!1;const s=e.m(8),n=e.F(t,i);n.Kn=s,n.Gt=`seui-${s}-optionlist`,n.wn=`seui-${s}-placeholder`;const h={options:n};e._(t,h);const o=new M(t,this);return h.container=o.container,h.action=o.vn(),h.self=o,o.container.view.addEventListener("mouseup",()=>{h.action?.toggle?.()}),!0}Dn(t,i){const s=Object.getOwnPropertyDescriptor(i,t);let e="variable";return s?.get||s?.set&&"function"!=typeof i[t]?e="get-set":"function"==typeof i[t]&&(e="func"),{type:e,name:t}}Nn(t,i,s){Object.defineProperty(t,i,{get(){const t=e.R(s[0]);return t.action?.[i]},set(t){s.forEach(s=>{const n=e.R(s);n?.action&&(n.action[i]=t)})},enumerable:!0,configurable:!0})}Bn(t,i,s){t[i]=(...h)=>{for(let t=0;t<s.length;t++){const o=e.R(s[t]);if(!o?.action)continue;const r=n.nt();if(o.action[i](r.et,...h),!r.token.isContinue)break}return t}}}const j="1.1.4",E="SelectiveUI";if(void 0===globalThis.GLOBAL_SEUI){const I=new $;globalThis.GLOBAL_SEUI={version:j,name:E,bind:I.bind.bind(I),find:I.find.bind(I),destroy:I.destroy.bind(I),effector:i.bind(i),rebind:I.rebind.bind(I)};let V=!1;function k(){V||(V=!0,document.addEventListener("mousedown",()=>{const t=e.U();if(t.length>0){const i=I.find(t.join(", "));i.isEmpty||i.close()}}),I.zn())}"undefined"!=typeof document&&("loading"===document.readyState?document.addEventListener("DOMContentLoaded",k):k()),console.log(`[${E}] v${j} loaded successfully`)}else console.warn(`[${globalThis.GLOBAL_SEUI.name}] Already loaded (v${globalThis.GLOBAL_SEUI.version}). Using existing instance. Please remove duplicate <script> tags.`);const version=globalThis.GLOBAL_SEUI.version,F=globalThis.GLOBAL_SEUI.name;t.bind=(t,i={})=>{globalThis.GLOBAL_SEUI.bind(t,i)},t.destroy=(t=null)=>{globalThis.GLOBAL_SEUI.destroy(t)},t.effector=t=>globalThis.GLOBAL_SEUI.effector(t),t.find=t=>globalThis.GLOBAL_SEUI.find(t),t.name=F,t.rebind=(t,i={})=>{globalThis.GLOBAL_SEUI.rebind(t,i)},t.version=version},"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).SelectiveUI={});
Binary file
@@ -1,4 +1,4 @@
1
- /*! Selective UI v1.1.3 | MIT License */
1
+ /*! Selective UI v1.1.4 | MIT License */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
4
4
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
@@ -5463,7 +5463,7 @@
5463
5463
  * to include component styles in the final bundle.
5464
5464
  */
5465
5465
  /** Base/global styles for SelectiveUI. */
5466
- const iVersion = "1.1.3";
5466
+ const iVersion = "1.1.4";
5467
5467
  const iName = "SelectiveUI";
5468
5468
  if (typeof globalThis.GLOBAL_SEUI == "undefined") {
5469
5469
  const SECLASS = new Selective();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "selective-ui",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "An overlay for the HTML select element.",
5
5
  "author": "Huỳnh Công Xuân Mai",
6
6
  "license": "MIT",
package/src/ts/index.ts CHANGED
@@ -38,7 +38,7 @@ import type {
38
38
  import type { EffectorInterface } from "./types/services/effector.type";
39
39
  import { Libs } from "./utils/libs";
40
40
 
41
- const iVersion = "1.1.3" as const;
41
+ const iVersion = "1.1.4" as const;
42
42
  const iName = "SelectiveUI" as const;
43
43
 
44
44
  declare global {