selective-ui 1.2.2 → 1.2.3

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,2 +1,2 @@
1
- /*! Selective UI v1.2.2 | MIT License */
2
- function t(t){return new g(t??null)}function bind(t,i={}){F.bind(t,i)}function find(t){return F.find(t)}function destroy(t=null){F.destroy(t)}function rebind(t,i={}){F.rebind(t,i)}function effector(i){return t(i)}function i(){$||($=!0,document.addEventListener("mousedown",()=>{const t=e.t();if(t.length>0){const i=F.find(t.join(", "));i.isEmpty||i.close()}}),F.i())}class s{constructor(){this.h={accessoryVisible:!0,virtualScroll:!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.o=new Map,this.l=new Map,this.u=[]}}class e{static get p(){return this.m||(this.m=new s),this.m}static v(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.v(t[s]));return i}static O(t=6){let i="";for(let s=0;s<t;s++)i+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random()));return i}static M(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.A(document.createElement(t.node??"div"),t,!0)}static A(t=document.documentElement,i=null,s=!1){const e={...i??{}},h=s?t:this.C(t.cloneNode(!0)),n=e.classList;return"string"==typeof n?h.classList.add(n):Array.isArray(n)&&h.classList.add(...n),delete e.classList,["style","dataset"].forEach(t=>{const i=e[t];i&&"object"==typeof i&&Object.assign(h[t],i),delete e[t]}),e.role&&(h.setAttribute("role",e.role+""),delete e.role),e.ariaLive&&(h.setAttribute("aria-live",e.ariaLive+""),delete e.ariaLive),e.S&&(h.setAttribute("aria-labelledby",e.S+""),delete e.S),e.H&&(h.setAttribute("aria-controls",e.H+""),delete e.H),e.L&&(h.setAttribute("aria-haspopup",e.L+""),delete e.L),e.P&&(h.setAttribute("aria-multiselectable",e.P+""),delete e.P),e.I&&(h.setAttribute("aria-autocomplete",e.I+""),delete e.I),e.event&&"object"==typeof e.event&&(Object.entries(e.event).forEach(([t,i])=>{h.addEventListener(t,i)}),delete e.event),Object.entries(e).forEach(([t,i])=>{null===i?h.removeAttribute(t):h[t]=i}),h}static C(t){if(t instanceof Element)return t;throw new TypeError("Node is not an Element")}static F(t){return this.j(t)}static j(t,i=null,s=!1,e=!1,h={}){let n=null;for(const o in t){const r=t[o],l=r?.tag?.tagName?r.tag:this.T(r.tag);h[o]=l,r?.$&&this.j(r.$,l,!1,!1,h),i?s?i.prepend(l):i.append(l):e||n||(n=l)}return e||(h.id=this.O(7),i||(h={tags:h,view:n})),h}static V(t,i){const s=this.v(i);for(const i in s){const e=t[i];e?s[i]="boolean"==typeof s[i]?this.k(e):e:void 0!==t?.dataset?.[i]&&(s[i]="boolean"==typeof s[i]?this.k(t.dataset[i]):t.dataset[i])}return s}static R(...t){if(0===t.length)return{};if(1===t.length)return this.v(t[0]);const i=this.v(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 k(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 D(t){return this.p.o.delete(t)}static _(t){return this.p.o.get(t)}static N(t,i){this.p.o.set(t,i)}static B(t){return this.p.l.delete(t)}static U(t){return this.p.l.get(t)}static G(t,i){this.p.l.set(t,i)}static W(){return this.p.h}static t(){return this.p.u}static q(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??"",h=s.value??"";if(/^on/i.test(e))return void t.removeAttribute(e);/^(href|src|xlink:href)$/i.test(e)&&/^javascript:/i.test(h)&&t.removeAttribute(e)}}),(e.innerHTML??"").trim()}static J(t){const i=document.createElement("DIV");i.innerHTML=t;const s=i.textContent??i.innerText??"";return i.remove(),s.trim()}static K(t){return null==t?"":(t+"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/đ/g,"d").replace(/Đ/g,"d")}static Y(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 X(){const t=navigator.userAgent;return/iP(hone|ad|od)/.test(t)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1}static Z(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 h=e.offsetHeight+"px";return e.remove(),h}}e.m=null,e.tt=new class{constructor(){this.it=new Map,this.st=new Map}on(t,i,s={}){const e=s.et??50,h=s.once??!1;this.it.has(t)||this.it.set(t,[]),this.it.get(t).push({ht:i,timeout:e,once:h})}off(t){const i=this.st.get(t);if(i){for(const t of i.values())clearTimeout(t);i.clear(),this.st.delete(t)}this.it.delete(t)}run(t,...i){const s=this.it.get(t);if(!s)return;this.st.has(t)||this.st.set(t,new Map);const e=this.st.get(t);for(let t=0;t<s.length;t++){const h=s[t];if(!h)continue;const n=e.get(t);n&&clearTimeout(n);const o=setTimeout(()=>{if(h.ht(i.length>0?i:null),h.once){s[t]=void 0;const i=e.get(t);i&&clearTimeout(i),e.delete(t)}},h.timeout);e.set(t,o)}}clear(t){if(void 0===t)for(const t of Array.from(this.it.keys()))this.off(t);else this.off(t)}};class h{static nt(){const t={isContinue:!0,isCancel:!1};return{token:{get isContinue(){return t.isContinue},get isCancel(){return t.isCancel}},ht:{stopPropagation(){t.isContinue=!1},cancel(){t.isCancel=!0,t.isContinue=!1}}}}static ot(t,...i){const{token:s,ht:e}=this.nt();for(let h=0;h<i.length;h++){const n=i[h];if("function"==typeof n&&(t&&Array.isArray(t)?n(e,...t):n(e),s.isCancel||!s.isContinue))break}return s}static rt(t,i,s={bubbles:!0,cancelable:!0}){const e=new Event(i,s);return t.dispatchEvent(e),e}static lt(t,...i){if(Array.isArray(t))for(const s of t)"function"==typeof s&&s(...i)}}class n{static ct(t,i){const s=e._(t);if(!s?.options)return;const h=s.options,n=h.minWidth,o=h.minHeight,r=Number.parseInt(h.width,10),l=Number.parseInt(h.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=h.width),l>0&&(c=h.height),Object.assign(i.style,{width:a,height:c,minWidth:n,minHeight:o})}}class o{constructor(t){this.node=null,this.options=null,t&&this.init(t)}init(t){this.node=e.T({node:"div",classList:"selective-ui-placeholder",innerHTML:t.placeholder}),this.options=t}get(){return this.options?.placeholder??""}set(t,i=!0){if(!this.node||!this.options)return;i&&(this.options.placeholder=t);const s=e.q(t);this.node.innerHTML=this.options.allowHtml?s:e.J(s)}}class r{constructor(){this.node=this.init()}init(){return e.T({node:"div",classList:"selective-ui-directive",role:"button",ariaLabel:"Toggle dropdown"})}ut(t){this.node.classList.toggle("drop-down",!!t)}}class l{constructor(t=null){this.dt=null,this.node=null,this.options=null,this.gt=[],this.ft=[],t&&this.init(t)}init(t){this.dt=e.j({bt:{tag:{node:"div",classList:["selective-ui-option-handle","hide"]},$:{wt:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textSelectAll,onclick:()=>{h.lt(this.gt)}}},yt:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textDeselectAll,onclick:()=>{h.lt(this.ft)}}}}}}),this.node=this.dt.view,this.options=t}available(){return!!this.options&&e.k(this.options.multiple)&&e.k(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")}vt(t=null){"function"==typeof t&&this.gt.push(t)}xt(t=null){"function"==typeof t&&this.ft.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.Mt=null,this.Tt=null,this.Ot=!0,this.At=this.Ct.bind(this)}St(t){}Ct(){const t=this.element;if(!t||"function"!=typeof t.getBoundingClientRect)return void this.St({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.St({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")}})}rt(){this.Ct()}connect(t){if(!(t instanceof Element))throw Error("Invalid element");this.element=t,this.Mt=new ResizeObserver(this.At),this.Mt.observe(t),this.Tt=new MutationObserver(this.At),this.Tt.observe(t,{attributes:!0,attributeFilter:["style","class"]}),window.addEventListener("scroll",this.At,!0),window.addEventListener("resize",this.At),window.visualViewport&&(window.visualViewport.addEventListener("resize",this.At),window.visualViewport.addEventListener("scroll",this.At))}disconnect(){this.Mt?.disconnect(),this.Tt?.disconnect(),this.St=()=>{},window.removeEventListener("scroll",this.At,!0),window.removeEventListener("resize",this.At),window.visualViewport&&(window.visualViewport.removeEventListener("resize",this.At),window.visualViewport.removeEventListener("scroll",this.At)),this.Mt=null,this.Tt=null,this.element=null}}class d{constructor(t=null,i=null,s=null){this.options=null,this.Ht=!1,this.Lt=null,this.node=null,this.Pt=null,this.It=null,this.parent=null,this.Et=null,this.Ft=null,this.jt=null,this.$t=null,this.Vt=null,this.kt=null,this.Rt=null,this.Dt={_t:36,Nt:8,Bt:!0},this.zt=s,t&&i&&this.init(t,i)}init(t,i){if(!this.zt)throw Error("Popup requires a ModelManager instance.");this.Et=new l(i),this.Ft=new a(i),this.jt=new c(i);const s=e.j({Ut:{tag:{node:"div",classList:"selective-ui-popup",style:{maxHeight:i.panelHeight}},$:{bt:{tag:this.Et.node},Gt:{tag:{id:i.Wt,node:"div",classList:"selective-ui-options-container",role:"listbox"}},qt:{tag:this.jt.node},Jt:{tag:this.Ft.node}}}},null);this.node=s.view,this.Vt=s.tags.Gt,this.parent=e._(t),this.options=i,this.zt.load(this.Vt,{isMultiple:i.multiple},i.virtualScroll?{Kt:this.node,_t:this.Dt._t,Nt:this.Dt.Nt,Bt:this.Dt.Bt}:{});const h=this.zt.Qt();this.Lt=h.Yt,this.$t=h.$t,this.Et.vt(()=>{h.Yt.Xt(!0)}),this.Et.xt(()=>{h.Yt.Xt(!1)}),this.Zt()}async ti(){this.options&&this.jt&&this.Et&&this.Lt&&this.zt&&(this.Rt&&clearTimeout(this.Rt),this.zt.ii(!0),!1!==e.k(this.options.loadingfield)&&(this.Ft.hide(),this.jt.show(this.Lt.ei().si),this.hi()))}async ni(){this.options&&this.jt&&this.Lt&&this.zt&&(this.Rt&&clearTimeout(this.Rt),this.Rt=setTimeout(()=>{this.zt?.ii(!1),this.jt?.hide();const t=this.Lt?.ei();this.oi(t??void 0),this.hi()},200))}Zt(){this.Lt&&(this.Lt.ri(t=>{this.oi(t)}),this.Lt.li("items",()=>{const t=this.Lt.ei();this.oi(t),this.hi()}))}oi(t){if(!(this.Lt&&this.Ft&&this.Et&&this.Vt))return;const i=t??this.Lt.ei();i.isEmpty?(this.Ft.show("nodata"),this.Vt.classList.add("hide"),this.Et.hide()):i.si?(this.Ft.hide(),this.Vt.classList.remove("hide"),this.Et.refresh()):(this.Ft.show("notfound"),this.Vt.classList.add("hide"),this.Et.hide())}ai(t,i){this.Lt?.ci(t,i)}ui(t,i){this.Lt?.li(t,i)}di(t){this.Pt=t}open(t=null,i){if(!(this.node&&this.options&&this.Et&&this.parent&&this.Pt))return;this.Ht||(document.body.appendChild(this.node),this.Ht=!0,this.It=new u,this.Pt.pi(this.node),this.node.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()})),this.Et.refresh(),i&&this.oi();const s=this.gi(),{position:e,top:h,maxHeight:n,fi:o}=this.mi(s);this.Pt.expand({duration:this.options.animationtime,display:"flex",width:s.width,left:s.left,top:h,maxHeight:n,fi:o,position:e,bi:()=>{if(!this.It||!this.parent)return;this.It.St=()=>{const t=this.gi();this.wi(t)},this.It.connect(this.parent.container.tags.yi),t?.();const i=this.$t;i?.resume?.()}})}close(t=null){if(!(this.Ht&&this.options&&this.It&&this.Pt))return;const i=this.$t;i?.suspend?.(),this.It.disconnect(),this.Pt.collapse({duration:this.options.animationtime,bi:t??void 0})}hi(){this.Ht&&this.It?.rt()}xi(t,i){this.node&&(this.kt=async()=>{const i=t.Oi();if(!i.Mi)return;const s=this.node;if(s.scrollHeight-s.scrollTop-s.clientHeight<100&&!i.Ti&&i.hasMore){const i=await t.Ai();!i.Ci&&i.message&&console.log("Load more:",i.message)}},this.node.addEventListener("scroll",this.kt))}Si(){this.Rt&&(clearTimeout(this.Rt),this.Rt=null),this.node&&this.kt&&(this.node.removeEventListener("scroll",this.kt),this.kt=null);try{this.It?.disconnect()}catch(t){}this.It=null;try{this.Pt?.pi?.(null)}catch(t){}if(this.Pt=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.Vt=null;try{this.zt?.ii?.(!1),this.$t?.clear?.(),this.$t=null,this.Lt=null,this.node.remove()}catch(t){}this.zt=null,this.Et=null,this.Ft=null,this.jt=null,this.parent=null,this.options=null,this.Ht=!1}gi(){const t=this.parent.container.tags.yi,i=t.getBoundingClientRect(),s=window.getComputedStyle(t);return{width:i.width,height:i.height,top:i.top,left:i.left,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)}}}mi(t){const i=window.visualViewport,s=e.X(),h=i?.height??window.innerHeight,n=this.Pt.Hi("flex").scrollHeight,o=parseFloat(this.options?.panelHeight??"220")||220,r=parseFloat(this.options?.panelMinHeight??"100")||100,l=h-(t.top+t.height)-3,a=t.top-3;let c="bottom",u=o,d=Math.min(n,u);const p=l-15;(d>=r?p>=r:p>=d)?(c="bottom",u=Math.min(l-15,o)):a>=Math.max(d,r)?(c="top",u=Math.min(a-15,o)):l>=a?(c="bottom",u=Math.max(l-15,r)):(c="top",u=Math.max(a-15,r)),d=Math.min(n,u);const g=i&&s?i.offsetTop:0;return{position:c,top:"bottom"===c?t.top+t.height+3+g:t.top-d-3+g,maxHeight:u,fi:d,Li:n}}wi(t){if(!this.options||!this.Pt)return;const{position:i,top:s,maxHeight:e,fi:h}=this.mi(t);this.Pt.resize({duration:this.options.animationtime,width:t.width,left:t.left,top:s,maxHeight:e,fi:h,position:i,animate:!0})}}class p{constructor(t=null){this.dt=null,this.node=null,this.Pi=null,this.Ii=null,this.options=null,this.Ei=null,this.Fi=null,this.ji=null,this.options=t,t&&this.init(t)}init(t){this.dt=e.j({$i:{tag:{node:"div",classList:["selective-ui-searchbox","hide"]},$:{Pi:{tag:{id:e.O(),node:"input",type:"search",classList:["selective-ui-searchbox-input"],placeholder:t.placeholder,role:"searchbox",H:t.Wt,I:"list"}}}}}),this.node=this.dt.view,this.Pi=this.dt.tags.Pi;let i=!1;const s=this.dt.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.Ei?.(1)):"ArrowUp"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.Ei?.(-1)):"Enter"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.Fi?.()):"Escape"===t.key&&(t.preventDefault(),t.stopPropagation(),i=!0,this.ji?.()),t.stopPropagation()}),s.addEventListener("input",()=>{i||this.Ii?.(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.dt&&(this.dt.tags.Pi.value="",this.Ii?.("",t))}Vi(t){this.Pi&&(this.Pi.placeholder=e.J(t))}ki(t){this.Pi&&this.Pi.setAttribute("aria-activedescendant",t)}}class g{constructor(t=null){this.Ri=null,this.Di=null,this._i=!1,t&&this.pi(t)}pi(t){if("string"==typeof t){const i=document.querySelector(t);return void(i instanceof HTMLElement&&(this.element=i))}this.element=t}cancel(){return this.Ri&&(clearTimeout(this.Ri),this.Ri=null),this.Di&&(clearTimeout(this.Di),this.Di=null),this._i=!1,this}Hi(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),h=parseFloat(s.borderBottomWidth),n=this.element.scrollHeight+e+h,o=this.element.getBoundingClientRect(),r={width:o.width,height:o.height+e+h,scrollHeight:n};return Object.assign(this.element.style,i),r}expand(t){if(!this.element)return this;this.cancel(),this._i=!0;const{duration:i=200,display:s="flex",width:e,left:h,top:n,maxHeight:o,fi:r,position:l="bottom",bi:a}=t;return Object.assign(this.element.style,{display:s,width:e+"px",left:h+"px",top:("bottom"===l?n:n+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:n+"px",height:r+"px",opacity:"1",overflow:r>=o?"auto":"hidden"}),this.Ri=setTimeout(()=>{this.element.style.transition="none",this._i=!1,a?.()},i)}),this}collapse(t){if(!this.element)return this;this.cancel(),this._i=!0;const{duration:i=200,bi:s}=t,e=this.element.offsetHeight,h=this.element.offsetTop,n=this.element.classList.contains("position-top")?"top":"bottom",o=this.element.scrollHeight-this.element.offsetHeight>0,r="top"===n?h+e:h;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.Ri=setTimeout(()=>{Object.assign(this.element.style,{display:"none",transition:"none"}),this._i=!1,s?.()},i)}),this}showSwipeWidth(t){if(!this.element)return this;this.cancel(),this._i=!0;const{duration:i=200,display:s="block",bi:e}=t;Object.assign(this.element.style,{transition:"none",display:s,width:"fit-content"});const h=this.Hi(s).width;return Object.assign(this.element.style,{width:"0px"}),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`width ${i}ms`,width:h+"px",overflow:"hidden"})}),this.Ri=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:""}),this._i=!1,e?.()},i),this}hideSwipeWidth(t){if(!this.element)return this;this.cancel(),this._i=!0;const{duration:i=200,bi:s}=t,e=this.Hi().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.Ri=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:"",display:""}),this._i=!1,s?.()},i),this}resize(t){if(!this.element)return this;this.cancel();const{duration:i=200,width:s,left:e,top:h,maxHeight:n,fi:o,position:r="bottom",animate:l=!0,bi:a}=t,c=(this.element.classList.contains("position-top")?"top":"bottom")!==r,u=this.element.scrollHeight>n;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;`),setTimeout(()=>{const t={width:s+"px",left:e+"px",top:h+"px",maxHeight:n+"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.Di=setTimeout(()=>{this.element?.style&&(this.element.style.transition=null)},i),Object.assign(this.element.style,t),l&&(c||r>1)?this.Di=setTimeout(()=>{this.element.style.transition=null,c&&delete this.element.style.transition,a?.()},i):(c&&delete this.element.style.transition,a?.())},20),this}get Ni(){return this._i}}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.Bi=!1,this.options=t,this.targetElement=i,this.view=s}update(t){this.targetElement=t,this.zi()}remove(){this.targetElement=null,this.view?.Ui()?.remove?.(),this.view=null,this.Bi=!0,this.Gi()}zi(){}Gi(){}}class m extends f{constructor(t,i){super(t,i??null,null),this.label="",this.items=[],this.collapsed=!1,this.Wi=[],i&&(this.label=i.label,this.collapsed=e.k(i.dataset?.collapsed))}get value(){return this.items.map(t=>t.value)}get qi(){return this.items.filter(t=>t.selected)}get Ji(){return this.items.filter(t=>t.visible)}get Ki(){return this.Ji.length>0}update(t){this.label=t.label,this.view?.Qi(this.label)}zi(){this.view&&(this.view.Qi(this.label),this.view.Yi(this.collapsed))}Xi(t){this.Wi.push(t)}Zi(){this.collapsed=!this.collapsed,this.view?.Yi(this.collapsed),h.ot([this,this.collapsed],...this.Wi)}ts(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)}ss(){this.view?.ss()}}class b extends f{constructor(t,i=null,s=null){super(t,i,s),this.es=[],this.hs=[],this.ns=[],this.rs=!0,this.ls=!1,this.group=null,(async()=>{this.cs=e.K(this.textContent.toLowerCase())})()}get us(){return this.dataset?.imgsrc||this.dataset?.image||""}get hasImage(){return!!this.us}get value(){return this.targetElement?.value??""}get selected(){return!!this.targetElement?.selected}set selected(t){this.ds=t,h.ot([this,t],...this.es)}get visible(){return this.rs}set visible(t){if(this.rs===t)return;this.rs=t;const i=this.view?.Ui?.();i&&i.classList.toggle("hide",!t),h.ot([this,t],...this.ns)}get ds(){return this.selected}set ds(t){const i=this.view?.view?.tags?.ps,s=this.view?.Ui?.();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),h.ot([this,t],...this.hs)}get text(){const t=e.q(this.dataset?.mask??this.targetElement?.text??"");return this.options.allowHtml?t:e.J(t)}get textContent(){return this.options.allowHtml?e.J(this.text).trim():this.text.trim()}get dataset(){return this.targetElement?.dataset??{}}get gs(){return this.ls}set gs(t){const i=!!t,s=this.view?.Ui?.();this.ls!==i&&(this.ls=i),s&&s.classList.toggle("highlight",i)}fs(t){this.es.push(t)}bs(t){this.hs.push(t)}ri(t){this.ns.push(t)}zi(){if(this.cs=e.K(this.textContent.toLowerCase()),!this.view)return;const t=this.view.view.tags.ws;t&&(this.options.allowHtml?t.innerHTML=this.text:t.textContent=this.textContent);const i=this.view.view.tags.ys;i&&this.hasImage&&(i.src=this.us,i.alt=this.text),this.targetElement&&(this.ds=this.targetElement.selected)}}class w{constructor(t){this.vs=[],this.xs=null,this.Os=null,this.Ms=null,this.options=null,this.options=t}Ts(t){this.As=t}Cs(t){this.Ss=t}Hs(t){const i=this.Ls(t),s=i!==this.Ms;return s&&(this.Ms=i),s}Ls(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")}Ps(t){this.vs=[];let i=null;return t.forEach(t=>{if("OPTGROUP"===t.tagName)i=new m(this.options,t),this.vs.push(i);else if("OPTION"===t.tagName){const s=t,e=new b(this.options,s),h=s.__parentGroup;h&&i&&h===i.targetElement?(i.ts(e),e.group=i):(this.vs.push(e),i=null)}}),this.vs}replace(t){this.Ms=null,this.Ps(t),this.xs&&this.xs.Is(this.vs),this.refresh(!1)}notify(){this.xs&&this.refresh(!1)}load(t,i={},s={}){this.xs=new this.As(this.vs),Object.assign(this.xs,i),this.Os=new this.Ss(t),Object.assign(this.Os,s),this.Os.Es(this.xs)}update(t){if(!this.Hs(t))return;const i=this.vs,s=[],e=new Map,h=new Map;i.forEach(t=>{t instanceof m?e.set(t.label,t):t instanceof b&&h.set(`${t.value}::${t.textContent}`,t)});let n=null,o=0;t.forEach(t=>{if("OPTGROUP"===t.tagName){const i=t,h=e.get(i.label);h?(h.label!==i.label&&h.update(i),h.position=o,h.items=[],n=h,s.push(h),e.delete(i.label)):(n=new m(this.options,i),n.position=o,s.push(n)),o++}else if("OPTION"===t.tagName){const i=t,e=`${i.value}::${i.text}`,r=h.get(e);if(r)r.update(i),r.position=o,i.__parentGroup&&n?(n.ts(r),r.group=n):(r.group=null,s.push(r)),h.delete(e);else{const t=new b(this.options,i);t.position=o,i.__parentGroup&&n?(n.ts(t),t.group=n):s.push(t)}o++}});let r=!0;e.forEach(t=>{r=!1,t.remove()}),h.forEach(t=>{r=!1,t.remove()}),this.vs=s,this.xs&&this.xs.Fs(this.vs),this.onUpdated(),this.refresh(r)}onUpdated(){}ii(t){this.xs&&(this.xs.js=t)}refresh(t){this.Os&&(this.Os.refresh(t),this.onUpdated())}Qt(){return{$s:this.vs,Yt:this.xs,$t:this.Os}}Vs(t){this.xs?.ks(t)}Rs(t){this.xs?.Ds(t)}}class y{constructor(t=null){this._s=null,this.Yt=null,this._s=t}Ns(t){this._s=t}Es(t){this.Yt=t,t.ci("items",()=>{this.clear()}),t.li("items",()=>{this.Bs()}),this.Bs()}clear(){this._s&&this._s.replaceChildren()}Bs(){this.Yt&&this._s&&this.Yt.zs(this._s)}refresh(t){this.Bs()}}class v{constructor(t=null){this.dt=null,this.node=null,this.options=null,this.Us=null,this.Gs=null,this.zt=null,this.Ws=[],t&&this.init(t)}init(t){this.dt=e.j({qs:{tag:{node:"div",classList:["selective-ui-accessorybox","hide"],onmouseup:t=>{t.stopPropagation()}}}}),this.node=this.dt.view,this.options=t}Js(t){this.Us=t,this.Gs=t.parentElement,this.Ks()}Ks(){this.Gs&&this.node&&this.Us&&this.options&&this.Gs.insertBefore(this.node,"top"===this.options.accessoryStyle?this.Us:this.Us.nextSibling)}Qs(t){this.zt=t}Ys(t){this.node&&this.options&&(this.node.replaceChildren(),t.length>0&&this.options.multiple?t.forEach(t=>{e.j({Xs:{tag:{node:"div",classList:["accessory-item"]},$:{Zs:{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.zt?.Vs?.("select"),setTimeout(()=>{t.selected=!1},10)}}},te:{tag:{node:"span",classList:["accessory-item-content"],innerHTML:t.text}}}}},this.node)}):t=[],this.Ws=t,this.ie(),h.rt(window,"resize"))}ie(){this.options?.accessoryVisible&&this.Ws.length>0&&this.options.multiple?this.show():this.hide()}show(){this.node.classList.remove("hide")}hide(){this.node.classList.add("hide")}}class x{constructor(t,i,s){this.se=null,this.ee=null,this.he=null,this.ne=null,this.oe={currentPage:0,totalPages:1,hasMore:!1,Ti:!1,re:"",Mi:!1},this.select=t,this.zt=i,this.ne=s}le(){return!!this.se}async ae(t){if(!this.se)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.se;let s,e;if(s="function"==typeof t.ce?t.ce(i):{values:i.join(","),ue:"1",..."function"==typeof t.data?t.data.bind(this.ne.de.find(this.ne.container.targetElement))("",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 h=await e.json();return{Ci:!0,items:this.pe(h).items}}catch(t){return console.error("Load by values error:",t),{Ci:!1,message:t?.message,items:[]}}}ge(t){const i=Array.from(this.select.options).map(t=>t.value);return{fe:t.filter(t=>i.includes(t)),me:t.filter(t=>!i.includes(t))}}be(t){this.se=t}setPopup(t){this.he=t}Oi(){return{...this.oe}}we(){this.oe={currentPage:0,totalPages:1,hasMore:!1,Ti:!1,re:"",Mi:this.oe.Mi}}clear(){this.oe.re="";const{$s:t}=this.zt.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.se?this.ye(t,i):this.ve(t)}async Ai(){return this.se?this.oe.Ti?{Ci:!1,message:"Already loading"}:this.oe.Mi?this.oe.hasMore?(this.oe.currentPage++,this.ye(this.oe.re,!0)):{Ci:!1,message:"No more data"}:{Ci:!1,message:"Pagination not enabled"}:{Ci:!1,message:"Ajax not enabled"}}async ve(t){this.xe(t)&&(this.oe.re=t);const i=((t??"")+"").toLowerCase(),s=e.K(i),{$s:h}=this.zt.Qt(),n=[];for(const t of h)t instanceof b?n.push(t):t instanceof m&&Array.isArray(t.items)&&n.push(...t.items);let o=!1;return n.forEach(t=>{const e=""===i||t.cs.includes(s);t.visible=e,e&&(o=!0)}),{Ci:!0,Oe:o,isEmpty:0===n.length}}xe(t){return t!==this.oe.re}async ye(t,i=!1){const s=this.se;this.xe(t)&&(this.we(),this.oe.re=t,i=!1),this.oe.Ti=!0,this.he?.ti(),this.ee?.abort(),this.ee=new AbortController;const e=this.oe.currentPage,h=Array.from(this.select.selectedOptions).map(t=>t.value).join(",");let n;"function"==typeof s.data?(n=s.data.bind(this.ne.de.find(this.ne.container.targetElement))(t,e),n&&void 0===n.selectedValue&&(n.selectedValue=h)):n={search:t,page:e,selectedValue:h,...s.data??{}};try{let t;if("POST"===(s.method??"GET")){const i=new URLSearchParams;Object.keys(n).forEach(t=>i.append(t,n[t]+"")),t=await fetch(s.url,{method:"POST",body:i,headers:{"Content-Type":"application/x-www-form-urlencoded"},signal:this.ee.signal})}else{const i=""+new URLSearchParams(n);t=await fetch(`${s.url}?${i}`,{signal:this.ee.signal})}const e=await t.json(),h=this.pe(e);return h.Me?(this.oe.Mi=!0,this.oe.currentPage=h.page,this.oe.totalPages=h.totalPages,this.oe.hasMore=h.hasMore):this.oe.Mi=!1,this.Te(h.items,!!s.keepSelected,i),this.oe.Ti=!1,this.he?.ni(),{Ci:!0,Oe:h.items.length>0,isEmpty:0===h.items.length,Me:h.Me,hasMore:h.hasMore,currentPage:h.page,totalPages:h.totalPages}}catch(t){return this.oe.Ti=!1,this.he?.ni(),"AbortError"===t?.name?{Ci:!1,message:"Request aborted"}:(console.error("Ajax search error:",t),{Ci:!1,message:t?.message})}}pe(t){let i=[],s=!1,e=0,h=1,n=!1;return t.object&&Array.isArray(t.object)?(i=t.object,void 0!==t.page&&(s=!0,e=parseInt(t.page??0,10),h=parseInt(t.totalPages??t.total_page??1,10),n=e<h-1)):t.data&&Array.isArray(t.data)?(i=t.data,void 0!==t.page&&(s=!0,e=parseInt(t.page??0,10),h=parseInt(t.totalPages??t.total_page??1,10),n=t.hasMore??e<h-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),h=parseInt(t.pagination.totalPages??t.pagination.total_page??1,10),n=t.pagination.hasMore??e<h-1)),{items:i.map(t=>{if(t instanceof HTMLOptionElement||t instanceof HTMLOptGroupElement)return t;if("optgroup"===t.type||t.Ae||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:h,hasMore:n}}Te(t,i,s=!1){const e=this.select;let h=[];i&&(h=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&&h.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&&h.includes(s.value))&&(s.selected=!0),e.appendChild(s)}}),e.dispatchEvent(new CustomEvent("options:changed"))}}class O{constructor(t){this.Ce=null,this.Se=null,this.He=50,this.select=t,this.Se=this.Le(),this.Pe=new MutationObserver(()=>{this.Ce&&clearTimeout(this.Ce),this.Ce=setTimeout(()=>{this.Ie()},this.He)}),t.addEventListener("options:changed",()=>{this.Ce&&clearTimeout(this.Ce),this.Ce=setTimeout(()=>{this.Ie()},this.He)})}Le(){const t=Array.from(this.select.options);return{length:t.length,values:t.map(t=>t.value).join(","),Ee:t.map(t=>t.text).join(","),selected:t.map(t=>t.selected+"").join(",")}}Fe(){const t=this.Le(),i=JSON.stringify(t)!==JSON.stringify(this.Se);return i&&(this.Se=t),i}Ie(){this.Fe()&&this.St(this.select)}connect(){this.Pe.observe(this.select,{childList:!0,subtree:!1,attributes:!0,attributeFilter:["selected","value","disabled"]})}St(t){}disconnect(){this.Ce&&clearTimeout(this.Ce),this.Ce=null,this.Pe.disconnect()}}class M{constructor(t){this.Ce=null,this.element=t,this.Pe=new MutationObserver(t=>{let i=!1;for(const s of t)if("attributes"===s.type&&s.attributeName?.startsWith("data-")){i=!0;break}i&&(this.Ce&&clearTimeout(this.Ce),this.Ce=setTimeout(()=>{this.St({...this.element.dataset})},50))}),t.addEventListener("dataset:changed",()=>{this.St({...this.element.dataset})})}connect(){this.Pe.observe(this.element,{attributes:!0,attributeOldValue:!0})}St(t){}disconnect(){this.Ce&&clearTimeout(this.Ce),this.Ce=null,this.Pe.disconnect()}}class T{constructor(t=[]){this.items=[],this.je=e.O(12),this.js=!1,this.items=t,this.$e()}$e(){}Ve(t,i,s){const e=i;t.Ot?e?.update?.():e?.Bs?.()}ci(t,i){e.tt.on(`${t}ing_${this.je}`,i,{et:1})}li(t,i){e.tt.on(`${t}_${this.je}`,i)}Ds(t,...i){e.tt.run(`${t}_${this.je}`,...i)}ks(t,...i){e.tt.run(`${t}ing_${this.je}`,...i)}ke(t,i){return null}Re(){return this.items.length}De(t){this.ks("items",t),this.items=t,this.Ds("items",t)}Is(t){this.De(t)}zs(t){for(let i=0;i<this.Re();i++){const s=this.items[i];let e=s.view;s.Ot||(e=this.ke(t,s),s.view=e),this.Ve(s,e,i),s.Ot=!0}}Fs(t){}}class A{constructor(t){this.parent=null,this.view=null,this.parent=t}Bs(){}update(){}Ui(){if(!this.view?.view)throw Error("View is not mounted. Did you forget to set this.view?");return this.view.view}}class C extends A{constructor(){super(...arguments),this.view=null}Bs(){const t=e.O(7);this.view=e.F({_e:{tag:{node:"div",classList:["selective-ui-group"],role:"group",S:`seui-${t}-header`,id:`seui-${t}-group`},$:{Ne:{tag:{node:"div",classList:["selective-ui-group-header"],role:"presentation",id:`seui-${t}-header`}},Be:{tag:{node:"div",classList:["selective-ui-group-items"],role:"group"}}}}}),this.parent.appendChild(this.view.view)}update(){this.Qi()}Qi(t=null){this.view&&null!==t&&(this.view.tags.Ne.textContent=t)}ze(){if(!this.view)throw Error("GroupView is not rendered.");return this.view.tags.Be}ss(){if(!this.view)return;const t=Array.from(this.view.tags.Be.children).filter(t=>!t.classList.contains("hide"));this.view.view.classList.toggle("hide",!(t.length>0))}Yi(t){this.view&&(this.view.view.classList.toggle("collapsed",t),this.view.tags.Ne.setAttribute("aria-expanded",t?"false":"true"))}}class S extends A{constructor(t){super(t),this.view=null,this.config=null,this.Ue=null,this.Ge=!1,this.We()}We(){const t=this;this.config={isMultiple:!1,hasImage:!1,imagePosition:"right",imageWidth:"60px",imageHeight:"60px",imageBorderRadius:"4px",labelValign:"center",labelHalign:"left"},this.Ue=new Proxy(this.config,{set(i,s,e){if("string"!=typeof s)return!0;const h=s,n=i[h];return n!==e&&(i[h]=e,t.Ge&&t.qe(h,e,n)),!0}})}get isMultiple(){return this.config.isMultiple}set isMultiple(t){this.Ue.isMultiple=!!t}get hasImage(){return this.config.hasImage}set hasImage(t){this.Ue.hasImage=!!t}get Je(){return this.Ue}set Je(t){if(!t||!this.Ue||!this.config)return;const i={};void 0!==t.imageWidth&&t.imageWidth!==this.config.imageWidth&&(i.imageWidth=t.imageWidth),void 0!==t.imageHeight&&t.imageHeight!==this.config.imageHeight&&(i.imageHeight=t.imageHeight),void 0!==t.imageBorderRadius&&t.imageBorderRadius!==this.config.imageBorderRadius&&(i.imageBorderRadius=t.imageBorderRadius),void 0!==t.imagePosition&&t.imagePosition!==this.config.imagePosition&&(i.imagePosition=t.imagePosition),void 0!==t.labelValign&&t.labelValign!==this.config.labelValign&&(i.labelValign=t.labelValign),void 0!==t.labelHalign&&t.labelHalign!==this.config.labelHalign&&(i.labelHalign=t.labelHalign),Object.keys(i).length>0&&Object.assign(this.Ue,i)}Bs(){const t=["selective-ui-option-view"],i=e.O(7),s="option_"+i;this.config.isMultiple&&t.push("multiple"),this.config.hasImage&&(t.push("has-image"),t.push("image-"+this.config.imagePosition));const h={ps:{tag:{node:"input",type:this.config.isMultiple?"checkbox":"radio",classList:"allow-choice",id:s}},...this.config.hasImage&&{ys:{tag:{node:"img",classList:"option-image",style:{width:this.config.imageWidth,height:this.config.imageHeight,borderRadius:this.config.imageBorderRadius}}}},Ke:{tag:{node:"label",htmlFor:s,classList:["align-vertical-"+this.config.labelValign,"align-horizontal-"+this.config.labelHalign]},$:{ws:{tag:{node:"div"}}}}};this.view=e.F({Qe:{tag:{node:"div",id:`seui-${i}-option`,classList:t,role:"option",ariaSelected:"false",tabIndex:"-1"},$:h}}),this.parent.appendChild(this.view.view),this.Ge=!0}qe(t,i,s){const e=this.view;if(!e||!e.view)return;const h=e.view,n=e.tags?.ps,o=e.tags?.Ke;switch(t){case"isMultiple":{const t=!!i;h.classList.toggle("multiple",t),n&&n.type!==(t?"checkbox":"radio")&&(n.type=t?"checkbox":"radio");break}case"hasImage":{const t=!!i;if(h.classList.toggle("has-image",t),t)h.classList.add("image-"+this.config.imagePosition),this.Ye();else{h.className=h.className.replace(/image-(top|right|bottom|left)/g,"").trim();const t=e.tags?.ys;t&&(t.remove(),e.tags.ys=null)}break}case"imagePosition":this.config.hasImage&&(h.className=h.className.replace(/image-(top|right|bottom|left)/g,"").trim(),h.classList.add("image-"+i));break;case"imageWidth":case"imageHeight":case"imageBorderRadius":{const s=e.tags?.ys;if(s){const e="imageWidth"===t?"width":"imageHeight"===t?"height":"borderRadius",h=i+"";s.style[e]!==h&&(s.style[e]=h)}break}case"labelValign":case"labelHalign":if(o){const t=`align-vertical-${this.config.labelValign} align-horizontal-${this.config.labelHalign}`;o.className!==t&&(o.className=t)}}}Ye(){const t=this.view;if(!t||!t.view)return;const i=t.tags?.ys;if(i)return;const s=t.view,e=t.tags?.Ke,h=document.createElement("img");h.className="option-image",h.style.width=this.config.imageWidth,h.style.height=this.config.imageHeight,h.style.borderRadius=this.config.imageBorderRadius,e&&e.parentElement?s.insertBefore(h,e):s.appendChild(h),t.tags.ys=h}}class H extends T{constructor(t=[]){super(t),this.isMultiple=!1,this.Xe=[],this.Ze=-1,this.th=null,this.groups=[],this.ih=[],this.sh(),e.tt.on("sche_vis_"+this.je,()=>{const t=this.ih.filter(t=>t.visible).length,i=this.ih.length;this.Xe.forEach(s=>{s({eh:t,hh:i,si:t>0,isEmpty:0===i})}),e.tt.run("sche_vis_proxy_"+this.je)},{et:10})}sh(){this.ih=[],this.groups=[],this.items.forEach(t=>{t instanceof m?(this.groups.push(t),this.ih.push(...t.items)):t instanceof b&&this.ih.push(t)})}ke(t,i){return i instanceof m?new C(t):new S(t)}Ve(t,i,s){t.position=s,t instanceof m?this.nh(t,i,s):t instanceof b&&this.oh(t,i,s),t.Ot=!0}nh(t,i,s){super.Ve(t,i,s),t.view=i;const e=i.view.tags.Ne;e.textContent=t.label,t.Ot||(e.style.cursor="pointer",e.addEventListener("click",()=>{t.Zi()}),t.Xi((t,i,s)=>{i.items.forEach(t=>{const i=t.view?.Ui?.();i&&(i.style.display=s?"none":"")}),this.rh(i,s)}));const h=i.ze();t.items.forEach((t,i)=>{let s=t.view;t.Ot&&s||(s=new S(h)),this.oh(t,s,i),t.Ot=!0}),i.Yi(t.collapsed),i.ss()}oh(t,i,s){if(i.isMultiple=this.isMultiple,i.hasImage=t.hasImage,i.Je={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.Ve(t,i,s),t.view=i,t.hasImage){const s=i.view.tags.ys;s&&(s.src!==t.us&&(s.src=t.us),s.alt!==t.text&&(s.alt=t.text))}i.view.tags.ws.innerHTML=t.text,t.Ot||(i.view.tags.Qe.addEventListener("click",i=>{i.stopPropagation(),i.preventDefault(),this.js||(this.isMultiple?(this.ks("select"),setTimeout(()=>{t.selected=!t.selected},5)):!0!==t.selected&&(this.ks("select"),setTimeout(()=>{this.th&&(this.th.selected=!1),t.selected=!0},5)))}),i.view.tags.Qe.title=t.textContent,i.view.tags.Qe.addEventListener("mouseenter",()=>{this.js||this.ah(this.ih.indexOf(t),!1)}),t.fs(()=>{this.Ds("selected")}),t.bs((i,s,e)=>{e&&(this.th=t),this.Ds("selected_internal")}),t.ri((t,i)=>{i.group?.ss(),this.uh()})),t.selected&&(this.th=t,t.ds=!0)}De(t){this.ks("items",t),this.items=t,this.sh(),this.Ds("items",t)}Is(t){this.De(t)}Fs(t){this.items=t,this.sh()}dh(){return this.ih.filter(t=>t.selected)}ph(){return this.ih.find(t=>t.selected)}Xt(t){this.isMultiple&&this.ih.forEach(i=>{i.selected=t})}ri(t){this.Xe.push(t)}uh(){e.tt.run("sche_vis_"+this.je)}ei(){const t=this.ih.filter(t=>t.visible).length,i=this.ih.length;return{eh:t,hh:i,si:t>0,isEmpty:0===i}}gh(){this.ah(0)}navigate(t,i=!0){const s=this.ih.filter(t=>t.visible);if(0===s.length)return;let e=s.findIndex(t=>t===this.ih[this.Ze]);-1===e&&(e=-1);let h=e+t;h>=s.length&&(h=0),h<0&&(h=s.length-1);const n=this.ih.indexOf(s[h]);this.ah(n,i)}fh(){if(this.Ze>-1&&this.ih[this.Ze]){const t=this.ih[this.Ze];if(t.visible){const i=t.view?.Ui?.();i&&i.click()}}}ah(t,i=!0){let s=0;if("number"==typeof t)s=t;else if(t instanceof b){const i=this.ih.indexOf(t);s=i>-1?i:0}else s=0;this.Ze>-1&&this.ih[this.Ze]&&(this.ih[this.Ze].gs=!1);for(let t=s;t<this.ih.length;t++){const s=this.ih[t];if(s?.visible){if(s.gs=!0,this.Ze=t,i){const i=s.view?.Ui?.();i?i.scrollIntoView({block:"center",behavior:"smooth"}):this.$t?.mh?.(t,{scrollIntoView:!0})}return void this.bh(t,s.view?.Ui?.()?.id)}}}bh(t,i){}rh(t,i){}}class L{constructor(t=0){this.wh=[],this.n=0,this.reset(t)}reset(t){this.n=t,this.wh=Array(t+1).fill(0)}add(t,i){for(let s=t;s<=this.n;s+=s&-s)this.wh[s]+=i}yh(t){let i=0;for(let s=t;s>0;s-=s&-s)i+=this.wh[s];return i}xh(t,i){return i<t?0:this.yh(i)-this.yh(t-1)}Oh(t){this.reset(t.length),t.forEach((t,i)=>this.add(i+1,t))}Mh(t){let i=0,s=1;for(;s<<1<=this.n;)s<<=1;let e=0;for(let h=s;0!==h;h>>=1){const s=i+h;s<=this.n&&e+this.wh[s]<=t&&(i=s,e+=this.wh[s])}return i}}class P extends y{constructor(t=null){super(t),this.Th={Kt:void 0,_t:36,Nt:8,Bt:!0,Ah:!0},this.Ch=[],this.Sh=new L(0),this.Hh=new Map,this.Lh=!1,this.start=0,this.end=-1,this.Ph=null,this.Ih=null,this.updating=!1,this.Eh=!1,this.Fh=0,this.jh=!1,this.$h=!1,this.Vh=0,this.kh=0,this.Rh=0,this.Dh=0}configure(t){this.Th={...this.Th,...t}}Es(t){if(this.Yt&&this.dispose(),super.Es(t),t.$t=this,!this._s)return;this._s.replaceChildren();const i=e.j({_h:{tag:{node:"div",classList:"selective-ui-virtual-pad-top"}},Nh:{tag:{node:"div",classList:"selective-ui-virtual-items"}},Bh:{tag:{node:"div",classList:"selective-ui-virtual-pad-bottom"}}},this._s);if(this._h=i._h,this.Nh=i.Nh,this.Bh=i.Bh,this.Kt=this.Th.Kt??this._s.closest(".selective-ui-popup")??this._s.parentElement,!this.Kt)throw Error("VirtualRecyclerView: scrollEl not found");this.zh=this.Uh.bind(this),this.Kt.addEventListener("scroll",this.zh,{passive:!0}),this.refresh(!1),this.Gh(),t?.ri?.(()=>this.Wh())}suspend(){this.jh=!0,this.qh(),this.Kt&&this.zh&&this.Kt.removeEventListener("scroll",this.zh),this.Jh&&(this.Jh.disconnect(),this.$h=!0)}resume(){this.jh=!1,this.Kt&&this.zh&&this.Kt.addEventListener("scroll",this.zh,{passive:!0}),this.$h&&(this.Gh(),this.$h=!1),this.Kh()}refresh(t){if(!this.Yt||!this._s)return;t||this.Wh();const i=this.Yt.Re();this.Fh=i,0!==i?(this.Ch.length=i,this.Lh||(this.Qh(),this.Lh=!0),this.Yh(i),this.Kh()):this.Xh()}mh(t,i){this.Zh(t,t),i?.scrollIntoView&&this.tn(t)}tn(t){if((this.Yt?.Re?.()??0)<=0)return;const i=this.sn(t),s=this.en()+i,e=Math.max(0,this.Kt.scrollHeight-this.Kt.clientHeight);this.Kt.scrollTop=Math.min(Math.max(0,s),e)}dispose(){this.qh(),this.Kt&&this.zh&&this.Kt.removeEventListener("scroll",this.zh),this.Jh?.disconnect(),this.Hh.forEach(t=>t.remove()),this.Hh.clear()}Wh(){if(!this.Yt)return;const t=this.Yt.Re();t<=0||(this.suspend(),this.Xh(),this.hn(),this.nn(t),this.Yh(t),this.start=0,this.end=-1,this.resume())}qh(){null!=this.Ph&&(cancelAnimationFrame(this.Ph),this.Ph=null),null!=this.Ih&&(cancelAnimationFrame(this.Ih),this.Ih=null)}Xh(){this.Hh.forEach(t=>t.remove()),this.Hh.clear(),this.Ch=[],this.Sh.reset(0),this._h.style.height="0px",this.Bh.style.height="0px",this.Lh=!1,this.Rh=0,this.Dh=0}Qh(){this.rn(0);const t=this.Hh.get(0);if(!t)return;const i=this.ln(t);if(isNaN(i)||(this.Th._t=i),!this.Th.Bt){t.remove(),this.Hh.delete(0);const i=this.Yt.items[0];i&&(i.Ot=!1,i.view=null)}}an(t){const i=this.Yt?.items?.[t];return i?.visible??!0}cn(t,i){for(let s=Math.max(0,t);s<i;s++)if(this.an(s))return s;return-1}nn(t){this.Rh=0,this.Dh=0;for(let i=0;i<t;i++){if(!this.an(i))continue;const t=this.Ch[i];null!=t&&(this.Rh+=t,this.Dh++)}}en(){const t=this._s.getBoundingClientRect(),i=this.Kt.getBoundingClientRect();return t.top-i.top+this.Kt.scrollTop}un(){const t=performance.now();if(t-this.Vh<16)return this.kh;const i=this.Kt.querySelector(".selective-ui-option-handle:not(.hide)");return this.kh=i?.offsetHeight??0,this.Vh=t,this.kh}Kh(){null!=this.Ph||this.jh||(this.Ph=requestAnimationFrame(()=>{this.Ph=null,this.dn()}))}ln(t){const i=t.getBoundingClientRect(),s=getComputedStyle(t);return Math.max(1,i.height+(parseFloat(s.marginTop)||0)+(parseFloat(s.marginBottom)||0))}pn(){return this.Th.Ah&&this.Dh>0?Math.max(1,this.Rh/this.Dh):this.Th._t}Yh(t){const i=this.pn(),s=Array.from({length:t},(t,s)=>this.an(s)?this.Ch[s]??i:0);this.Sh.Oh(s)}gn(t,i){if(!this.an(t))return!1;const s=this.pn(),e=this.Ch[t]??s;if(Math.abs(i-e)<=P.fn)return!1;const h=this.Ch[t];return null==h?(this.Rh+=i,this.Dh++):this.Rh+=i-h,this.Ch[t]=i,this.Sh.add(t+1,i-e),!0}mn(t,i){const s=this.Sh.Mh(Math.max(0,t)),e=Math.min(i-1,s),h=this.cn(e,i);return-1===h?Math.max(0,e):h}bn(t,i){i.setAttribute(P.wn,t+"");const s=this.Hh.get(t-1);if(s?.parentElement===this.Nh)return void s.after(i);const e=this.Hh.get(t+1);if(e?.parentElement===this.Nh)return void this.Nh.insertBefore(i,e);const h=Array.from(this.Nh.children);for(const s of h){const e=s.getAttribute(P.wn);if(e&&+e>t)return void this.Nh.insertBefore(i,s)}this.Nh.appendChild(i)}yn(t,i){if(i.parentElement!==this.Nh)return void this.bn(t,i);i.setAttribute(P.wn,t+"");const s=i.previousElementSibling,e=i.nextElementSibling;(s&&+s.getAttribute(P.wn)>t||e&&+e.getAttribute(P.wn)<t)&&(i.remove(),this.bn(t,i))}Gh(){this.Jh||(this.Jh=new ResizeObserver(()=>{this.Eh||this.jh||!this.Yt||null!=this.Ih||(this.Ih=requestAnimationFrame(()=>{this.Ih=null,this.vn()}))}),this.Jh.observe(this.Nh))}vn(){if(!this.Yt)return;const t=this.Yt.Re();if(t<=0)return;let i=!1;for(let t=this.start;t<=this.end;t++){if(!this.an(t))continue;const s=this.Yt.items[t],e=s?.view?.Ui?.();if(!e)continue;const h=this.ln(e);this.gn(t,h)&&(i=!0)}i&&(this.Th.Ah&&this.Yh(t),this.Kh())}Uh(){this.Kh()}dn(){if(!this.updating&&!this.jh){this.updating=!0;try{if(!this.Yt)return;const t=this.Yt.Re();if(t<=0)return;this.Fh!==t&&(this.Fh=t,this.Ch.length=t,this.Yh(t));const i=this.en(),s=Math.max(0,this.Kt.scrollTop-i),e=this.un(),h=Math.max(0,this.Kt.clientHeight-e),n=this.mn(s,t),o=i+this.sn(n)-this.Kt.scrollTop,r=this.mn(s,t);if(-1===r)return void this.Xh();const l=this.pn(),a=this.Th.Nt*l;let c=this.cn(Math.min(t-1,this.Sh.Mh(Math.max(0,s-a))),t)??r,u=Math.min(t-1,this.Sh.Mh(s+h+a));if(c===this.start&&u===this.end)return;this.start=c,this.end=u,this.Eh=!0;try{this.Zh(this.start,this.end),this.xn(this.start,this.end),this.Th.Bt&&this.vn();const i=this.sn(this.start),s=this.On(this.start,this.end),e=this.Mn(t),h=Math.max(0,e-i-s);this._h.style.height=i+"px",this.Bh.style.height=h+"px"}finally{this.Eh=!1}const d=this.sn(n),p=this.en()+d-o,g=Math.max(0,this.Kt.scrollHeight-this.Kt.clientHeight),f=Math.min(Math.max(0,p),g);Math.abs(this.Kt.scrollTop-f)>.5&&(this.Kt.scrollTop=f)}finally{this.updating=!1}}}Zh(t,i){for(let s=t;s<=i;s++)this.rn(s)}rn(t){if(!this.an(t)){const i=this.Hh.get(t);return i?.parentElement===this.Nh&&i.remove(),void this.Hh.delete(t)}const i=this.Yt.items[t];if(!i)return;const s=this.Hh.get(t);if(s)return void(i?.view?(this.yn(t,s),this.Yt.Ve(i,i.view,t)):(s.remove(),this.Hh.delete(t)));if(i.Ot)i.view&&this.Yt.Ve(i,i.view,t);else{const s=this.Yt.ke(this.Nh,i);i.view=s,this.Yt.Ve(i,s,t),i.Ot=!0}const e=i.view?.Ui?.();e&&(this.yn(t,e),this.Hh.set(t,e))}xn(t,i){this.Hh.forEach((s,e)=>{(e<t||e>i)&&(s.parentElement===this.Nh&&s.remove(),this.Hh.delete(e))})}hn(){this.Hh.forEach((t,i)=>{this.an(i)||(t.parentElement===this.Nh&&t.remove(),this.Hh.delete(i))})}sn(t){return this.Sh.yh(t)}On(t,i){return this.Sh.xh(t+1,i+1)}Mn(t){return this.Sh.yh(t)}}P.fn=.5,P.wn="data-vindex";class I{constructor(t=null,i=null){this.container={},this.oldValue=null,this.node=null,this.options=null,this.Tn=null,this.isOpen=!1,this.An=!1,this.Cn=!1,this.de=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?.yi?.setAttribute("aria-disabled",t+""))}get Sn(){return!!this.options?.readonly}set Sn(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,s){const h=e._(i).options,l=new o(h),a=new r,c=new p(h),effector=t(),u=new w(h),g=new v(h),f=new x(i,u,this),m=new O(i),b=new M(i);this.de=s,this.options=h,l.node&&(l.node.id=(h.Hn??"")+"");const T=e.j({Ln:{tag:{node:"div",classList:"selective-ui-MAIN"},$:{yi:{tag:{node:"div",classList:"selective-ui-view",tabIndex:0,onkeydown:t=>{"Enter"!==t.key&&" "!==t.key&&"ArrowDown"!==t.key||(t.preventDefault(),this.Pn()?.open())}},$:{In:{tag:l.node},En:{tag:a.node},$i:{tag:c.node}}}}}},null);this.container=T,this.node=T.view,i.parentNode?.insertBefore(this.node,i),this.node.insertBefore(i,T.tags.yi),g.Js(T.tags.yi),g.Qs(u),T.tags.yi.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()}),n.ct(i,T.tags.yi),i.classList.add("init"),u.Ts(H),u.Cs(h.virtualScroll?P:y),u.Ps(e.Y(i)),u.onUpdated=()=>{T.he?.hi?.()},this.Tn=u,T.Fn=f,T.placeholder=l,T.jn=a,T.$n=c,T.effector=effector,T.targetElement=i,T.Vn=g,T.kn=m,T.Rn=b,T.he=new d(i,h,u),T.he.di(effector),T.he.xi(f,h),T.he.ui("selected",()=>{this.Pn()?.change(null,!0)}),T.he.ui("selected_internal",()=>{this.Pn()?.change(null,!1)}),T.he.ai("select",()=>{this.oldValue=this.Pn()?.value??""}),this.Pn()?.change(null,!1),m.connect(),m.St=t=>{u.update(e.Y(t)),this.Pn()?.refreshMask()},b.connect(),b.St=t=>{e.k(t.disabled)!==this.isDisabled&&(this.isDisabled=e.k(t.disabled)),e.k(t.readonly)!==this.Sn&&(this.Sn=e.k(t.readonly)),e.k(t.visible)!==this.isVisible&&(this.isVisible=e.k(t.visible??"1"))},i.addEventListener("options:changed",()=>{u.update(e.Y(i)),this.Pn()?.refreshMask(),T.he?.hi?.()}),h.ajax&&f.be(h.ajax);const A=T.he.Lt;let C=null;const S=(t,i)=>{i||""!==t?(""!==t&&(this.Cn=!0),f.search(t).then(t=>{clearTimeout(C),e.tt.clear("sche_vis_proxy_"+A.je),e.tt.on("sche_vis_proxy_"+A.je,()=>{T.he?.hi?.(),t?.Oe&&(C=setTimeout(()=>{A.gh(),T.he?.hi?.()},h.animationtime??0))},{et:10})}).catch(t=>{console.error("Search error:",t)})):f.clear()};let L=null;c.Ii=(t,i)=>{f.xe(t)&&(L&&clearTimeout(L),f.le()?(T.he?.ti?.(),L=setTimeout(()=>{S(t,i)},h.delaysearchtime??0)):L=setTimeout(()=>{S(t,i)},10))},f.setPopup(T.he),c.Ei=t=>{A.navigate(t)},c.Fi=()=>{A.fh()},c.ji=()=>{this.Pn()?.close(),T.tags.yi.focus()},A.bh=(t,i)=>{i&&c.ki(i)},A.rh=()=>{T.he?.hi?.()},this.isDisabled=e.k(h.disabled),this.Sn=e.k(h.readonly)}Dn(){const t=this.container??{},{kn:i,Rn:s}=t;i?.disconnect&&i.disconnect(),s?.disconnect&&s.disconnect()}Pn(){const t=this.container,i=this,s=()=>this.de.find(t.targetElement),n=e._(t.targetElement);if(!n)return null;const o=n.options,r={get targetElement(){return t.targetElement},get placeholder(){return t.placeholder.get()},set placeholder(i){t.placeholder?.set(i),t.$n?.Vi(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(o.customDelimiter)},get valueOptions(){const t=[];return i._n(!0).forEach(i=>{t.push(i)}),t},get mask(){const t=[];return i._n(!0).forEach(i=>{t.push(i.text)}),t},get valueText(){const t=[];i._n(!0).forEach(i=>{t.push(i.text)});const s=t.length;return s>1?t:0===s?"":t[0]},get isOpen(){return i.isOpen},getParent:()=>t.view.parentElement,valueDataset(t,s=null,e=!1){var h=[];if(i._n(!0).forEach(t=>{h.push(s?t.dataset[s]:t.dataset)}),!e){if(0==h.length)return"";if(1==h.length)return h[0]}return h},selectAll(t,e=!0){if(!(o.multiple&&o.maxSelected>0&&i._n().length>o.maxSelected)&&!this.disabled&&!this.readonly&&o.multiple){if(e){if(h.ot([s()],...o.on.beforeChange).isCancel)return;i.oldValue=this.value}i._n().forEach(t=>{t.ds=!0}),this.change(!1,e)}},deSelectAll(t,e=!0){if(!this.disabled&&!this.readonly&&o.multiple){if(e){if(h.ot([s()],...o.on.beforeChange).isCancel)return;i.oldValue=this.value}i._n().forEach(t=>{t.ds=!1}),this.change(!1,e)}},setValue(e=null,n,r=!0,l=!1){if(Array.isArray(n)||(n=[n]),0===(n=n.filter(t=>""!==t&&null!=t)).length)return i._n().forEach(t=>t.ds=!1),void this.change(!1,r);if(o.multiple&&o.maxSelected>0&&n.length>o.maxSelected)console.warn(`Cannot select more than ${o.maxSelected} items`);else if(l||!this.disabled&&!this.readonly){if(t.Fn?.le?.()){const{me:s}=t.Fn.ge(n);if(s.length>0)return void(async()=>{o.loadingfield&&t.he?.ti?.();try{t.Fn.we();const e=await t.Fn.ae(s);e.Ci&&e.items.length>0?(e.items.forEach(t=>{s.includes(t.value)&&(t.selected=!0)}),t.Fn.Te?.(e.items,!0,!0),setTimeout(()=>{i._n().forEach(t=>{t.ds=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{o.loadingfield&&t.he?.ni?.()}})()}if(r){if(h.ot([s()],...o.on.beforeChange).isCancel)return;i.oldValue=this.value}i._n().forEach(t=>{t.ds=n.some(i=>i==t.value)}),!o.multiple&&n.length>0&&(t.targetElement.value=n[0]),this.change(!1,r)}},open(){if(i.isOpen)return;const e=i.de?.find?.();if(e&&!e.isEmpty&&e.close().isCancel)return;if(this.disabled)return;if(h.ot([s()],...o.on.beforeShow).isCancel)return;i.isOpen=!0,t.jn.ut(!0);const n=t.he.Lt,r=n.ph();r?n.ah(r,!1):n.gh(),i.An&&!i.Cn||!o?.ajax?t.he.open(null,!0):(t.Fn.we(),t.he.ti(),i.An=!0,i.Cn=!1,setTimeout(()=>{t.he&&t.Fn&&t.Fn.search("").then(()=>t.he?.hi?.()).catch(t=>console.error("Initial ajax load error:",t))},o.animationtime),t.he.open(null,!1)),t.$n.show();const l=t.tags.yi;l.setAttribute("aria-expanded","true"),l.setAttribute("aria-controls",o.Wt),l.setAttribute("aria-haspopup","listbox"),l.setAttribute("aria-labelledby",o.Hn),o.multiple&&l.setAttribute("aria-multiselectable","true"),h.ot([s()],...o.on.show)},close(){i.isOpen&&(h.ot([s()],...o.on.beforeClose).isCancel||(i.isOpen=!1,t.jn.ut(!1),t.he.close(()=>{t.$n.clear(!1)}),t.$n.hide(),t.tags.yi.setAttribute("aria-expanded","false"),h.ot([s()],...o.on.close)))},toggle(){i.isOpen?this.close():this.open()},change(e=null,n=!0){if(n){if(o.multiple&&o.maxSelected>0&&this.valueArray.length>o.maxSelected&&this.setValue(null,this.oldValue,!1,!0),this.disabled||this.readonly)return void this.setValue(null,this.oldValue,!1,!0);if(h.ot([s(),this.value],...o.on.beforeChange).isCancel)return void this.setValue(null,this.oldValue,!1)}this.refreshMask(),t.Vn.Ys(this.valueOptions),n&&(t.targetElement&&h.rt(t.targetElement,"change"),h.ot([s(),this.value],...o.on.change),i.options?.autoclose&&this.close())},refreshMask(){let s=o.placeholder;!o.multiple&&i._n().length>0&&(s=this.mask[0]),s??(s=o.placeholder),t.placeholder.set(s,!1),t.$n.Vi(s)},on(t,i,s){o.on[i]||(o.on[i]=[]),o.on[i].push(s)},ajax(i,s){t.Fn.be(s)},loadAjax:()=>new Promise((e,h)=>{t.he.ti(),t.Fn.we(),i.An=!0,i.Cn=!1,t.he&&t.Fn?t.Fn.search("").then(()=>{t.he?.hi?.(),e(s())}).catch(t=>{console.error("Initial ajax load error:",t),h(t)}):e(s())})};return this.Nn(r,"disabled","isDisabled"),this.Nn(r,"readonly","isReadOnly"),this.Nn(r,"visible","isVisible"),r}Nn(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.Tn)return[];const{$s:i}=this.Tn.Qt(),s=[];for(const t of i)t instanceof b?s.push(t):t instanceof m&&Array.isArray(t.items)&&t.items.length&&s.push(...t.items);return"boolean"==typeof t?s.filter(i=>i.selected===t):s}Si(){this.container.he.Si()}}class E{constructor(){this.isActive=!1,this.Pe=null,this.actions=[]}Bn(t){this.actions.push(t)}zn(){this.actions=[]}start(t){if(this.isActive)return;this.isActive=!0;const i=t.toUpperCase(),s=t.toLowerCase();this.Pe=new MutationObserver(t=>{for(const e of t)e.addedNodes.forEach(t=>{if(1!==t.nodeType)return;const e=t;e.tagName===i&&this.Un(e),e.querySelectorAll(s).forEach(t=>this.Un(t))})}),this.Pe.observe(document.body,{childList:!0,subtree:!0})}stop(){this.isActive&&(this.isActive=!1,this.Pe?.disconnect(),this.Pe=null)}Un(t){this.actions.forEach(i=>i(t))}}const F=new class{constructor(){this.Gn=new Map}bind(t,i){const s=e.R(e.W(),i);s.on=s.on??{},s.on.load=s.on.load??[],this.Gn.set(t,s);const n=e.O();e.tt.on(n,()=>{h.ot([this.find(t)],...s.on.load),e.tt.clear(n),s.on.load=[]}),e.M(t).forEach(t=>{(async()=>{"SELECT"===t.tagName&&(e.B(t),this.Wn(t,s)&&e.tt.run(n))})()}),e.t().includes(t)||e.t().push(t)}find(t="*"){const i={isEmpty:!0};if("*"===t&&""===(t=e.t().join(", ")))return i;const s=e.M(t);if(0===s.length)return i;const h=e._(s[0]);if(!h||!h.action)return i;const n={};for(const t in h.action)n[t]=this.qn(t,h.action);const o={isEmpty:!1};for(const t in n){const i=n[t];switch(i.type){case"get-set":this.Jn(o,i.name,s);break;case"func":this.Kn(o,i.name,s)}}return o}i(){this.Qn=new E,this.Qn.Bn(t=>{this.Gn.forEach((i,s)=>{try{t.matches(s)&&this.Wn(t,i)}catch(t){console.warn("Invalid selector: "+s,t)}})}),this.Qn.start("select")}destroy(t=null){null===t?this.Yn():"string"==typeof t?this.Xn(t):t instanceof HTMLSelectElement&&this.Zn(t)}Yn(){e.t().forEach(t=>this.Xn(t)),this.Gn.clear(),e.t().length=0,this.Qn?.stop()}Xn(t){e.M(t).forEach(t=>{"SELECT"===t.tagName&&this.Zn(t)}),this.Gn.delete(t);const i=e.t(),s=i.indexOf(t);s>-1&&i.splice(s,1)}Zn(t){const i=e._(t);if(!i)return;const s=i.container?.he;s?.Si(),e.G(t,i);const h=!!this.Qn;h&&this.Qn?.stop();try{i.self?.Dn?.()}catch(t){}const n=i.container?.element??t.parentElement;t.style.display="",t.style.visibility="",t.disabled=!1,delete t.dataset.io,n&&n.parentNode?n.parentNode.replaceChild(t,n):document.body.appendChild(t),e.D(t),h&&this.Gn.size>0&&this.Qn?.start("select")}rebind(t,i){this.Xn(t),this.bind(t,i)}Wn(t,i){if(e._(t)||e.U(t))return!1;const s=e.O(8),h=e.V(t,i);h.so=s,h.Wt=`seui-${s}-optionlist`,h.Hn=`seui-${s}-placeholder`;const n={options:h};e.N(t,n);const o=new I(t,this);return n.container=o.container,n.action=o.Pn(),n.self=o,o.container.view.addEventListener("mouseup",()=>{n.action?.toggle?.()}),!0}qn(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}}Jn(t,i,s){Object.defineProperty(t,i,{get(){const t=e._(s[0]);return t.action?.[i]},set(t){s.forEach(s=>{const h=e._(s);h?.action&&(h.action[i]=t)})},enumerable:!0,configurable:!0})}Kn(t,i,s){t[i]=(...n)=>{let o=null;for(let t=0;t<s.length;t++){const r=e._(s[t]);if(!r?.action)continue;const l=h.nt();if(o??(o=r.action[i](l.ht,...n)),!l.token.isContinue)break}return o??t}}},version="1.2.2",j="SelectiveUI";let $=!1;"undefined"!=typeof document&&("loading"===document.readyState?document.addEventListener("DOMContentLoaded",i):i());export{bind,destroy,effector,find,j as name,rebind,version};
1
+ /*! Selective UI v1.2.3 | MIT License */
2
+ function t(t){return new g(t??null)}function bind(t,i={}){E.bind(t,i)}function find(t){return E.find(t)}function destroy(t=null){E.destroy(t)}function rebind(t,i={}){E.rebind(t,i)}function effector(i){return t(i)}function i(){$||($=!0,document.addEventListener("mousedown",()=>{const t=e.t();if(t.length>0){const i=E.find(t.join(", "));i.isEmpty||i.close()}}),E.i())}class s{constructor(){this.h={accessoryVisible:!0,virtualScroll:!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.o=new Map,this.l=new Map,this.u=[]}}class e{static get p(){return this.m||(this.m=new s),this.m}static v(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.v(t[s]));return i}static O(t=6){let i="";for(let s=0;s<t;s++)i+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random()));return i}static M(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 A(t={}){return this.C(document.createElement(t.node??"div"),t,!0)}static C(t=document.documentElement,i=null,s=!1){const e={...i??{}},h=s?t:this.T(t.cloneNode(!0)),n=e.classList;return"string"==typeof n?h.classList.add(n):Array.isArray(n)&&h.classList.add(...n),delete e.classList,["style","dataset"].forEach(t=>{const i=e[t];i&&"object"==typeof i&&Object.assign(h[t],i),delete e[t]}),e.role&&(h.setAttribute("role",e.role+""),delete e.role),e.ariaLive&&(h.setAttribute("aria-live",e.ariaLive+""),delete e.ariaLive),e.S&&(h.setAttribute("aria-labelledby",e.S+""),delete e.S),e.H&&(h.setAttribute("aria-controls",e.H+""),delete e.H),e.P&&(h.setAttribute("aria-haspopup",e.P+""),delete e.P),e.L&&(h.setAttribute("aria-multiselectable",e.L+""),delete e.L),e.I&&(h.setAttribute("aria-autocomplete",e.I+""),delete e.I),e.event&&"object"==typeof e.event&&(Object.entries(e.event).forEach(([t,i])=>{h.addEventListener(t,i)}),delete e.event),Object.entries(e).forEach(([t,i])=>{null===i?h.removeAttribute(t):h[t]=i}),h}static T(t){if(t instanceof Element)return t;throw new TypeError("Node is not an Element")}static F(t){return this.j(t)}static j(t,i=null,s=!1,e=!1,h={}){let n=null;for(const o in t){const r=t[o],l=r?.tag?.tagName?r.tag:this.A(r.tag);h[o]=l,r?.$&&this.j(r.$,l,!1,!1,h),i?s?i.prepend(l):i.append(l):e||n||(n=l)}return e||(h.id=this.O(7),i||(h={tags:h,view:n})),h}static V(t,i){const s=this.v(i);for(const i in s){const e=t[i];e?s[i]="boolean"==typeof s[i]?this.k(e):e:void 0!==t?.dataset?.[i]&&(s[i]="boolean"==typeof s[i]?this.k(t.dataset[i]):t.dataset[i])}return s}static R(...t){if(0===t.length)return{};if(1===t.length)return this.v(t[0]);const i=this.v(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 k(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 D(t){return this.p.o.delete(t)}static _(t){return this.p.o.get(t)}static N(t,i){this.p.o.set(t,i)}static B(t){return this.p.l.delete(t)}static U(t){return this.p.l.get(t)}static G(t,i){this.p.l.set(t,i)}static W(){return this.p.h}static t(){return this.p.u}static q(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??"",h=s.value??"";if(/^on/i.test(e))return void t.removeAttribute(e);/^(href|src|xlink:href)$/i.test(e)&&/^javascript:/i.test(h)&&t.removeAttribute(e)}}),(e.innerHTML??"").trim()}static J(t){const i=document.createElement("DIV");i.innerHTML=t;const s=i.textContent??i.innerText??"";return i.remove(),s.trim()}static K(t){return null==t?"":(t+"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/đ/g,"d").replace(/Đ/g,"d")}static Y(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 X(){const t=navigator.userAgent;return/iP(hone|ad|od)/.test(t)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1}static Z(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.A({node:"div",style:{height:i,opacity:"0"}});document.body.appendChild(e);const h=e.offsetHeight+"px";return e.remove(),h}}e.m=null,e.tt=new class{constructor(){this.it=new Map,this.st=new Map}on(t,i,s={}){const e=s.et??50,h=s.once??!1;this.it.has(t)||this.it.set(t,[]),this.it.get(t).push({ht:i,timeout:e,once:h})}off(t){const i=this.st.get(t);if(i){for(const t of i.values())clearTimeout(t);i.clear(),this.st.delete(t)}this.it.delete(t)}run(t,...i){const s=this.it.get(t);if(!s||0===s.length)return Promise.resolve();this.st.has(t)||this.st.set(t,new Map);const e=this.st.get(t),h=[];for(let t=0;t<s.length;t++){const n=s[t];if(!n)continue;const o=e.get(t);o&&clearTimeout(o);const r=new Promise(h=>{const o=setTimeout(async()=>{try{const t=n.ht(i.length>0?i:null);t instanceof Promise&&await t}catch{}finally{if(n.once){s[t]=void 0;const i=e.get(t);i&&clearTimeout(i),e.delete(t)}h()}},n.timeout);e.set(t,o)});h.push(r)}return Promise.all(h).then(()=>{})}clear(t){if(void 0===t)for(const t of Array.from(this.it.keys()))this.off(t);else this.off(t)}};class h{static nt(){const t={isContinue:!0,isCancel:!1};return{token:{get isContinue(){return t.isContinue},get isCancel(){return t.isCancel}},ht:{stopPropagation(){t.isContinue=!1},cancel(){t.isCancel=!0,t.isContinue=!1}}}}static ot(t,...i){const{token:s,ht:e}=this.nt();for(let h=0;h<i.length;h++){const n=i[h];if("function"==typeof n&&(t&&Array.isArray(t)?n(e,...t):n(e),s.isCancel||!s.isContinue))break}return s}static rt(t,i,s={bubbles:!0,cancelable:!0}){const e=new Event(i,s);return t.dispatchEvent(e),e}static lt(t,...i){if(Array.isArray(t))for(const s of t)"function"==typeof s&&s(...i)}}class n{static ct(t,i){const s=e._(t);if(!s?.options)return;const h=s.options,n=h.minWidth,o=h.minHeight,r=Number.parseInt(h.width,10),l=Number.parseInt(h.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=h.width),l>0&&(c=h.height),Object.assign(i.style,{width:a,height:c,minWidth:n,minHeight:o})}}class o{constructor(t){this.node=null,this.options=null,t&&this.init(t)}init(t){this.node=e.A({node:"div",classList:"selective-ui-placeholder",innerHTML:t.placeholder}),this.options=t}get(){return this.options?.placeholder??""}set(t,i=!0){if(!this.node||!this.options)return;i&&(this.options.placeholder=t);const s=e.q(t);this.node.innerHTML=this.options.allowHtml?s:e.J(s)}}class r{constructor(){this.node=this.init()}init(){return e.A({node:"div",classList:"selective-ui-directive",role:"button",ariaLabel:"Toggle dropdown"})}ut(t){this.node.classList.toggle("drop-down",!!t)}}class l{constructor(t=null){this.dt=null,this.node=null,this.options=null,this.gt=[],this.ft=[],t&&this.init(t)}init(t){this.dt=e.j({bt:{tag:{node:"div",classList:["selective-ui-option-handle","hide"]},$:{wt:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textSelectAll,onclick:()=>{h.lt(this.gt)}}},yt:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textDeselectAll,onclick:()=>{h.lt(this.ft)}}}}}}),this.node=this.dt.view,this.options=t}available(){return!!this.options&&e.k(this.options.multiple)&&e.k(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")}vt(t=null){"function"==typeof t&&this.gt.push(t)}xt(t=null){"function"==typeof t&&this.ft.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.A({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.A({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.Mt=null,this.At=null,this.Ot=!0,this.Ct=this.Tt.bind(this)}St(t){}Tt(){const t=this.element;if(!t||"function"!=typeof t.getBoundingClientRect)return void this.St({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.St({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")}})}rt(){this.Tt()}connect(t){if(!(t instanceof Element))throw Error("Invalid element");this.element=t,this.Mt=new ResizeObserver(this.Ct),this.Mt.observe(t),this.At=new MutationObserver(this.Ct),this.At.observe(t,{attributes:!0,attributeFilter:["style","class"]}),window.addEventListener("scroll",this.Ct,!0),window.addEventListener("resize",this.Ct),window.visualViewport&&(window.visualViewport.addEventListener("resize",this.Ct),window.visualViewport.addEventListener("scroll",this.Ct))}disconnect(){this.Mt?.disconnect(),this.At?.disconnect(),this.St=()=>{},window.removeEventListener("scroll",this.Ct,!0),window.removeEventListener("resize",this.Ct),window.visualViewport&&(window.visualViewport.removeEventListener("resize",this.Ct),window.visualViewport.removeEventListener("scroll",this.Ct)),this.Mt=null,this.At=null,this.element=null}}class d{constructor(t=null,i=null,s=null){this.options=null,this.Ht=!1,this.Pt=null,this.node=null,this.Lt=null,this.It=null,this.parent=null,this.Ft=null,this.Et=null,this.jt=null,this.$t=null,this.Vt=null,this.kt=null,this.Rt=null,this.Dt={_t:36,Nt:8,Bt:!0},this.zt=s,t&&i&&this.init(t,i)}init(t,i){if(!this.zt)throw Error("Popup requires a ModelManager instance.");this.Ft=new l(i),this.Et=new a(i),this.jt=new c(i);const s=e.j({Ut:{tag:{node:"div",classList:"selective-ui-popup",style:{maxHeight:i.panelHeight}},$:{bt:{tag:this.Ft.node},Gt:{tag:{id:i.Wt,node:"div",classList:"selective-ui-options-container",role:"listbox"}},qt:{tag:this.jt.node},Jt:{tag:this.Et.node}}}},null);this.node=s.view,this.Vt=s.tags.Gt,this.parent=e._(t),this.options=i,this.zt.load(this.Vt,{isMultiple:i.multiple},i.virtualScroll?{Kt:this.node,_t:this.Dt._t,Nt:this.Dt.Nt,Bt:this.Dt.Bt}:{});const h=this.zt.Qt();this.Pt=h.Yt,this.$t=h.$t,this.Ft.vt(()=>{h.Yt.Xt(!0)}),this.Ft.xt(()=>{h.Yt.Xt(!1)}),this.Zt()}async ti(){this.options&&this.jt&&this.Ft&&this.Pt&&this.zt&&(this.Rt&&clearTimeout(this.Rt),this.zt.ii(!0),!1!==e.k(this.options.loadingfield)&&(this.Et.hide(),this.jt.show(this.Pt.ei().si),this.hi()))}async ni(){this.options&&this.jt&&this.Pt&&this.zt&&(this.Rt&&clearTimeout(this.Rt),this.Rt=setTimeout(()=>{this.zt?.ii(!1),this.jt?.hide();const t=this.Pt?.ei();this.oi(t??void 0),this.hi()},this.options.animationtime))}Zt(){this.Pt&&(this.Pt.ri(t=>{this.oi(t)}),this.Pt.li("items",()=>{const t=this.Pt.ei();this.oi(t),this.hi()}))}oi(t){if(!(this.Pt&&this.Et&&this.Ft&&this.Vt))return;const i=t??this.Pt.ei();i.isEmpty?(this.Et.show("nodata"),this.Vt.classList.add("hide"),this.Ft.hide()):i.si?(this.Et.hide(),this.Vt.classList.remove("hide"),this.Ft.refresh()):(this.Et.show("notfound"),this.Vt.classList.add("hide"),this.Ft.hide())}ai(t,i){this.Pt?.ci(t,i)}ui(t,i){this.Pt?.li(t,i)}di(t){this.Lt=t}open(t=null,i){if(!(this.node&&this.options&&this.Ft&&this.parent&&this.Lt))return;this.Ht||(document.body.appendChild(this.node),this.Ht=!0,this.It=new u,this.Lt.pi(this.node),this.node.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()})),this.Ft.refresh(),i&&this.oi();const s=this.gi(),{position:e,top:h,maxHeight:n,fi:o}=this.mi(s);this.Lt.expand({duration:this.options.animationtime,display:"flex",width:s.width,left:s.left,top:h,maxHeight:n,fi:o,position:e,bi:()=>{if(!this.It||!this.parent)return;this.It.St=()=>{const t=this.gi();this.wi(t)},this.It.connect(this.parent.container.tags.yi),t?.();const i=this.$t;i?.resume?.()}})}close(t=null){if(!(this.Ht&&this.options&&this.It&&this.Lt))return;const i=this.$t;i?.suspend?.(),this.It.disconnect(),this.Lt.collapse({duration:this.options.animationtime,bi:t??void 0})}hi(){this.Ht&&this.It?.rt()}xi(t,i){this.node&&(this.kt=async()=>{const i=t.Oi();if(!i.Mi)return;const s=this.node;if(s.scrollHeight-s.scrollTop-s.clientHeight<100&&!i.Ai&&i.hasMore){const i=await t.Ci();!i.Ti&&i.message&&console.log("Load more:",i.message)}},this.node.addEventListener("scroll",this.kt))}Si(){this.Rt&&(clearTimeout(this.Rt),this.Rt=null),this.node&&this.kt&&(this.node.removeEventListener("scroll",this.kt),this.kt=null);try{this.It?.disconnect()}catch(t){}this.It=null;try{this.Lt?.pi?.(null)}catch(t){}if(this.Lt=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.Vt=null;try{this.zt?.ii?.(!1),this.$t?.clear?.(),this.$t=null,this.Pt=null,this.node.remove()}catch(t){}this.zt=null,this.Ft=null,this.Et=null,this.jt=null,this.parent=null,this.options=null,this.Ht=!1}gi(){const t=this.parent.container.tags.yi,i=t.getBoundingClientRect(),s=window.getComputedStyle(t);return{width:i.width,height:i.height,top:i.top,left:i.left,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)}}}mi(t){const i=window.visualViewport,s=e.X(),h=i?.height??window.innerHeight,n=this.Lt.Hi("flex").scrollHeight,o=parseFloat(this.options?.panelHeight??"220")||220,r=parseFloat(this.options?.panelMinHeight??"100")||100,l=h-(t.top+t.height)-3,a=t.top-3;let c="bottom",u=o,d=Math.min(n,u);const p=l-15;(d>=r?p>=r:p>=d)?(c="bottom",u=Math.min(l-15,o)):a>=Math.max(d,r)?(c="top",u=Math.min(a-15,o)):l>=a?(c="bottom",u=Math.max(l-15,r)):(c="top",u=Math.max(a-15,r)),d=Math.min(n,u);const g=i&&s?i.offsetTop:0;return{position:c,top:"bottom"===c?t.top+t.height+3+g:t.top-d-3+g,maxHeight:u,fi:d,Pi:n}}wi(t){if(!this.options||!this.Lt)return;const{position:i,top:s,maxHeight:e,fi:h}=this.mi(t);this.Lt.resize({duration:this.options.animationtime,width:t.width,left:t.left,top:s,maxHeight:e,fi:h,position:i,animate:!0})}}class p{constructor(t=null){this.dt=null,this.node=null,this.Li=null,this.Ii=null,this.options=null,this.Fi=null,this.Ei=null,this.ji=null,this.options=t,t&&this.init(t)}init(t){this.dt=e.j({$i:{tag:{node:"div",classList:["selective-ui-searchbox","hide"]},$:{Li:{tag:{id:e.O(),node:"input",type:"search",classList:["selective-ui-searchbox-input"],placeholder:t.placeholder,role:"searchbox",H:t.Wt,I:"list"}}}}}),this.node=this.dt.view,this.Li=this.dt.tags.Li;let i=!1;const s=this.dt.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.Fi?.(1)):"ArrowUp"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.Fi?.(-1)):"Enter"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.Ei?.()):"Escape"===t.key&&(t.preventDefault(),t.stopPropagation(),i=!0,this.ji?.()),t.stopPropagation()}),s.addEventListener("input",()=>{i||this.Ii?.(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.dt&&(this.dt.tags.Li.value="",this.Ii?.("",t))}Vi(t){this.Li&&(this.Li.placeholder=e.J(t))}ki(t){this.Li&&this.Li.setAttribute("aria-activedescendant",t)}}class g{constructor(t=null){this.Ri=null,this.Di=null,this._i=!1,t&&this.pi(t)}pi(t){if("string"==typeof t){const i=document.querySelector(t);return void(i instanceof HTMLElement&&(this.element=i))}this.element=t}cancel(){return this.Ri&&(clearTimeout(this.Ri),this.Ri=null),this.Di&&(clearTimeout(this.Di),this.Di=null),this._i=!1,this}Hi(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),h=parseFloat(s.borderBottomWidth),n=this.element.scrollHeight+e+h,o=this.element.getBoundingClientRect(),r={width:o.width,height:o.height+e+h,scrollHeight:n};return Object.assign(this.element.style,i),r}expand(t){if(!this.element)return this;this.cancel(),this._i=!0;const{duration:i=200,display:s="flex",width:e,left:h,top:n,maxHeight:o,fi:r,position:l="bottom",bi:a}=t;return Object.assign(this.element.style,{display:s,width:e+"px",left:h+"px",top:("bottom"===l?n:n+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:n+"px",height:r+"px",opacity:"1",overflow:r>=o?"auto":"hidden"}),this.Ri=setTimeout(()=>{this.element.style.transition="none",this._i=!1,a?.()},i)}),this}collapse(t){if(!this.element)return this;this.cancel(),this._i=!0;const{duration:i=200,bi:s}=t,e=this.element.offsetHeight,h=this.element.offsetTop,n=this.element.classList.contains("position-top")?"top":"bottom",o=this.element.scrollHeight-this.element.offsetHeight>0,r="top"===n?h+e:h;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.Ri=setTimeout(()=>{Object.assign(this.element.style,{display:"none",transition:"none"}),this._i=!1,s?.()},i)}),this}showSwipeWidth(t){if(!this.element)return this;this.cancel(),this._i=!0;const{duration:i=200,display:s="block",bi:e}=t;Object.assign(this.element.style,{transition:"none",display:s,width:"fit-content"});const h=this.Hi(s).width;return Object.assign(this.element.style,{width:"0px"}),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`width ${i}ms`,width:h+"px",overflow:"hidden"})}),this.Ri=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:""}),this._i=!1,e?.()},i),this}hideSwipeWidth(t){if(!this.element)return this;this.cancel(),this._i=!0;const{duration:i=200,bi:s}=t,e=this.Hi().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.Ri=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:"",display:""}),this._i=!1,s?.()},i),this}resize(t){if(!this.element)return this;this.cancel();const{duration:i=200,width:s,left:e,top:h,maxHeight:n,fi:o,position:r="bottom",animate:l=!0,bi:a}=t,c=(this.element.classList.contains("position-top")?"top":"bottom")!==r,u=this.element.scrollHeight>n;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:h+"px",maxHeight:n+"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.Di=setTimeout(()=>{this.element?.style&&(this.element.style.transition=null)},i),Object.assign(this.element.style,t),l&&(c||r>1)?this.Di=setTimeout(()=>{this.element.style.transition=null,c&&delete this.element.style.transition,a?.()},i):(c&&delete this.element.style.transition,a?.())}),this}get Ni(){return this._i}}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.Bi=!1,this.options=t,this.targetElement=i,this.view=s}update(t){this.targetElement=t,this.zi()}remove(){this.targetElement=null,this.view?.Ui()?.remove?.(),this.view=null,this.Bi=!0,this.Gi()}zi(){}Gi(){}}class m extends f{constructor(t,i){super(t,i??null,null),this.label="",this.items=[],this.collapsed=!1,this.Wi=[],i&&(this.label=i.label,this.collapsed=e.k(i.dataset?.collapsed))}get value(){return this.items.map(t=>t.value)}get qi(){return this.items.filter(t=>t.selected)}get Ji(){return this.items.filter(t=>t.visible)}get Ki(){return this.Ji.length>0}update(t){this.label=t.label,this.view?.Qi(this.label)}zi(){this.view&&(this.view.Qi(this.label),this.view.Yi(this.collapsed))}Xi(t){this.Wi.push(t)}Zi(){this.collapsed=!this.collapsed,this.view?.Yi(this.collapsed),h.ot([this,this.collapsed],...this.Wi)}ts(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)}ss(){this.view?.ss()}}class b extends f{constructor(t,i=null,s=null){super(t,i,s),this.es=[],this.hs=[],this.ns=[],this.rs=!0,this.ls=!1,this.group=null,(async()=>{this.cs=e.K(this.textContent.toLowerCase())})()}get us(){return this.dataset?.imgsrc||this.dataset?.image||""}get hasImage(){return!!this.us}get value(){return this.targetElement?.value??""}get selected(){return!!this.targetElement?.selected}set selected(t){this.ds=t,h.ot([this,t],...this.es)}get visible(){return this.rs}set visible(t){if(this.rs===t)return;this.rs=t;const i=this.view?.Ui?.();i&&i.classList.toggle("hide",!t),h.ot([this,t],...this.ns)}get ds(){return this.selected}set ds(t){const i=this.view?.view?.tags?.ps,s=this.view?.Ui?.();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),h.ot([this,t],...this.hs)}get text(){const t=e.q(this.dataset?.mask??this.targetElement?.text??"");return this.options.allowHtml?t:e.J(t)}get textContent(){return this.options.allowHtml?e.J(this.text).trim():this.text.trim()}get dataset(){return this.targetElement?.dataset??{}}get gs(){return this.ls}set gs(t){const i=!!t,s=this.view?.Ui?.();this.ls!==i&&(this.ls=i),s&&s.classList.toggle("highlight",i)}fs(t){this.es.push(t)}bs(t){this.hs.push(t)}ri(t){this.ns.push(t)}zi(){if(this.cs=e.K(this.textContent.toLowerCase()),!this.view)return;const t=this.view.view.tags.ws;t&&(this.options.allowHtml?t.innerHTML=this.text:t.textContent=this.textContent);const i=this.view.view.tags.ys;i&&this.hasImage&&(i.src=this.us,i.alt=this.text),this.targetElement&&(this.ds=this.targetElement.selected)}}class w{constructor(t){this.vs=[],this.xs=null,this.Os=null,this.Ms=null,this.options=null,this.As=0,this.options=t}Cs(t){this.Ts=t}Ss(t){this.Hs=t}Ps(t){const i=this.Ls(t),s=i!==this.Ms;return s&&(this.Ms=i),s}Ls(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")}Is(t){this.vs=[];let i=null;return t.forEach(t=>{if("OPTGROUP"===t.tagName)i=new m(this.options,t),this.vs.push(i);else if("OPTION"===t.tagName){const s=t,e=new b(this.options,s),h=s.__parentGroup;h&&i&&h===i.targetElement?(i.ts(e),e.group=i):(this.vs.push(e),i=null)}}),this.vs}async replace(t){this.Ms=null,this.Is(t),this.xs&&await this.xs.Fs(this.vs),this.refresh(!1)}notify(){this.xs&&this.refresh(!1)}load(t,i={},s={}){this.xs=new this.Ts(this.vs),Object.assign(this.xs,i),this.Os=new this.Hs(t),Object.assign(this.Os,s),this.Os.Es(this.xs)}update(t){if(!this.Ps(t))return;const i=this.vs,s=[],e=new Map,h=new Map;i.forEach(t=>{t instanceof m?e.set(t.label,t):t instanceof b&&h.set(`${t.value}::${t.textContent}`,t)});let n=null,o=0;t.forEach(t=>{if("OPTGROUP"===t.tagName){const i=t,h=e.get(i.label);h?(h.label!==i.label&&h.update(i),h.position=o,h.items=[],n=h,s.push(h),e.delete(i.label)):(n=new m(this.options,i),n.position=o,s.push(n)),o++}else if("OPTION"===t.tagName){const i=t,e=`${i.value}::${i.text}`,r=h.get(e);if(r)r.update(i),r.position=o,i.__parentGroup&&n?(n.ts(r),r.group=n):(r.group=null,s.push(r)),h.delete(e);else{const t=new b(this.options,i);t.position=o,i.__parentGroup&&n?(n.ts(t),t.group=n):s.push(t)}o++}});let r=!0;0==this.As&&(r=!1),this.As=o,e.forEach(t=>{r=!1,t.remove()}),h.forEach(t=>{r=!1,t.remove()}),this.vs=s,this.xs&&this.xs.js(this.vs),this.refresh(r)}onUpdated(){}ii(t){this.xs&&(this.xs.$s=t)}refresh(t){this.Os&&(this.Os.refresh(t),this.onUpdated())}Qt(){return{Vs:this.vs,Yt:this.xs,$t:this.Os}}ks(t){return this.xs?.Rs(t)}Ds(t){return this.xs?._s(t)}}class y{constructor(t=null){this.Ns=null,this.Yt=null,this.Ns=t}Bs(t){this.Ns=t}Es(t){this.Yt=t,t.ci("items",()=>{this.clear()}),t.li("items",()=>{this.zs()}),this.zs()}clear(){this.Ns&&this.Ns.replaceChildren()}zs(){this.Yt&&this.Ns&&this.Yt.Us(this.Ns)}refresh(t){this.zs()}}class v{constructor(t=null){this.dt=null,this.node=null,this.options=null,this.Gs=null,this.Ws=null,this.zt=null,this.qs=[],t&&this.init(t)}init(t){this.dt=e.j({Js:{tag:{node:"div",classList:["selective-ui-accessorybox","hide"],onmouseup:t=>{t.stopPropagation()}}}}),this.node=this.dt.view,this.options=t}Ks(t){this.Gs=t,this.Ws=t.parentElement,this.Qs()}Qs(){this.Ws&&this.node&&this.Gs&&this.options&&this.Ws.insertBefore(this.node,"top"===this.options.accessoryStyle?this.Gs:this.Gs.nextSibling)}Ys(t){this.zt=t}Xs(t){this.node&&this.options&&(this.node.replaceChildren(),t.length>0&&this.options.multiple?t.forEach(t=>{e.j({Zs:{tag:{node:"div",classList:["accessory-item"]},$:{te:{tag:{node:"span",classList:["accessory-item-button"],role:"button",ariaLabel:`${this.options.textAccessoryDeselect}${t.textContent}`,title:`${this.options.textAccessoryDeselect}${t.textContent}`,onclick:async i=>{i.preventDefault(),await(this.zt?.ks?.("select")),t.selected=!1}}},ie:{tag:{node:"span",classList:["accessory-item-content"],innerHTML:t.text}}}}},this.node)}):t=[],this.qs=t,this.se(),h.rt(window,"resize"))}se(){this.options?.accessoryVisible&&this.qs.length>0&&this.options.multiple?this.show():this.hide()}show(){this.node.classList.remove("hide")}hide(){this.node.classList.add("hide")}}class x{constructor(t,i,s){this.ee=null,this.he=null,this.ne=null,this.oe=null,this.re={currentPage:0,totalPages:1,hasMore:!1,Ai:!1,le:"",Mi:!1},this.select=t,this.zt=i,this.oe=s}ae(){return!!this.ee}async ce(t){if(!this.ee)return{Ti:!1,items:[],message:"Ajax not configured"};const i=Array.isArray(t)?t:[t];if(0===i.length)return{Ti:!0,items:[]};try{const t=this.ee;let s,e;if(s="function"==typeof t.ue?t.ue(i):{values:i.join(","),de:"1",..."function"==typeof t.data?t.data.bind(this.oe.pe.find(this.oe.container.targetElement))("",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 h=await e.json();return{Ti:!0,items:this.ge(h).items}}catch(t){return console.error("Load by values error:",t),{Ti:!1,message:t?.message,items:[]}}}fe(t){const i=Array.from(this.select.options).map(t=>t.value);return{me:t.filter(t=>i.includes(t)),be:t.filter(t=>!i.includes(t))}}we(t){this.ee=t}setPopup(t){this.ne=t}Oi(){return{...this.re}}ye(){this.re={currentPage:0,totalPages:1,hasMore:!1,Ai:!1,le:"",Mi:this.re.Mi}}clear(){this.re.le="";const{Vs:t}=this.zt.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.ee?this.ve(t,i):this.xe(t)}async Ci(){return this.ee?this.re.Ai?{Ti:!1,message:"Already loading"}:this.re.Mi?this.re.hasMore?(this.re.currentPage++,this.ve(this.re.le,!0)):{Ti:!1,message:"No more data"}:{Ti:!1,message:"Pagination not enabled"}:{Ti:!1,message:"Ajax not enabled"}}async xe(t){this.Oe(t)&&(this.re.le=t);const i=((t??"")+"").toLowerCase(),s=e.K(i),{Vs:h}=this.zt.Qt(),n=[];for(const t of h)t instanceof b?n.push(t):t instanceof m&&Array.isArray(t.items)&&n.push(...t.items);let o=!1;return n.forEach(t=>{const e=""===i||t.cs.includes(s);t.visible=e,e&&(o=!0)}),{Ti:!0,Me:o,isEmpty:0===n.length}}Oe(t){return t!==this.re.le}async ve(t,i=!1){const s=this.ee;this.Oe(t)&&(this.ye(),this.re.le=t,i=!1),this.re.Ai=!0,this.ne?.ti(),this.he?.abort(),this.he=new AbortController;const e=this.re.currentPage,h=Array.from(this.select.selectedOptions).map(t=>t.value).join(",");let n;"function"==typeof s.data?(n=s.data.bind(this.oe.pe.find(this.oe.container.targetElement))(t,e),n&&void 0===n.selectedValue&&(n.selectedValue=h)):n={search:t,page:e,selectedValue:h,...s.data??{}};try{let t;if("POST"===(s.method??"GET")){const i=new URLSearchParams;Object.keys(n).forEach(t=>i.append(t,n[t]+"")),t=await fetch(s.url,{method:"POST",body:i,headers:{"Content-Type":"application/x-www-form-urlencoded"},signal:this.he.signal})}else{const i=""+new URLSearchParams(n);t=await fetch(`${s.url}?${i}`,{signal:this.he.signal})}const e=await t.json(),h=this.ge(e);return h.Ae?(this.re.Mi=!0,this.re.currentPage=h.page,this.re.totalPages=h.totalPages,this.re.hasMore=h.hasMore):this.re.Mi=!1,this.Ce(h.items,!!s.keepSelected,i),this.re.Ai=!1,this.ne?.ni(),{Ti:!0,Me:h.items.length>0,isEmpty:0===h.items.length,Ae:h.Ae,hasMore:h.hasMore,currentPage:h.page,totalPages:h.totalPages}}catch(t){return this.re.Ai=!1,this.ne?.ni(),"AbortError"===t?.name?{Ti:!1,message:"Request aborted"}:(console.error("Ajax search error:",t),{Ti:!1,message:t?.message})}}ge(t){let i=[],s=!1,e=0,h=1,n=!1;return t.object&&Array.isArray(t.object)?(i=t.object,void 0!==t.page&&(s=!0,e=parseInt(t.page??0,10),h=parseInt(t.totalPages??t.total_page??1,10),n=e<h-1)):t.data&&Array.isArray(t.data)?(i=t.data,void 0!==t.page&&(s=!0,e=parseInt(t.page??0,10),h=parseInt(t.totalPages??t.total_page??1,10),n=t.hasMore??e<h-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),h=parseInt(t.pagination.totalPages??t.pagination.total_page??1,10),n=t.pagination.hasMore??e<h-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}}),Ae:s,page:e,totalPages:h,hasMore:n}}Ce(t,i,s=!1){const e=this.select;let h=[];i&&(h=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&&h.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&&h.includes(s.value))&&(s.selected=!0),e.appendChild(s)}})}}class O{constructor(t){this.Se=null,this.He=null,this.Pe=50,this.select=t,this.He=this.Le(),this.Ie=new MutationObserver(()=>{this.Se&&clearTimeout(this.Se),this.Se=setTimeout(()=>{this.Fe()},this.Pe)})}Le(){const t=Array.from(this.select.options);return{length:t.length,values:t.map(t=>t.value).join(","),Ee:t.map(t=>t.text).join(","),selected:t.map(t=>t.selected+"").join(",")}}je(){const t=this.Le(),i=JSON.stringify(t)!==JSON.stringify(this.He);return i&&(this.He=t),i}Fe(){this.je()&&this.St(this.select)}connect(){this.Ie.observe(this.select,{childList:!0,subtree:!1,attributes:!0,attributeFilter:["selected","value","disabled"]})}St(t){}disconnect(){this.Se&&clearTimeout(this.Se),this.Se=null,this.Ie.disconnect()}}class M{constructor(t){this.Se=null,this.element=t,this.Ie=new MutationObserver(t=>{let i=!1;for(const s of t)if("attributes"===s.type&&s.attributeName?.startsWith("data-")){i=!0;break}i&&(this.Se&&clearTimeout(this.Se),this.Se=setTimeout(()=>{this.St({...this.element.dataset})},50))}),t.addEventListener("dataset:changed",()=>{this.St({...this.element.dataset})})}connect(){this.Ie.observe(this.element,{attributes:!0,attributeOldValue:!0})}St(t){}disconnect(){this.Se&&clearTimeout(this.Se),this.Se=null,this.Ie.disconnect()}}class A{constructor(t=[]){this.items=[],this.$e=e.O(12),this.$s=!1,this.items=t,this.Ve()}Ve(){}ke(t,i,s){const e=i;t.Ot?e?.update?.():e?.zs?.()}ci(t,i){e.tt.on(`${t}ing_${this.$e}`,i,{et:0})}li(t,i){e.tt.on(`${t}_${this.$e}`,i,{et:0})}_s(t,...i){return e.tt.run(`${t}_${this.$e}`,...i)}Rs(t,...i){return e.tt.run(`${t}ing_${this.$e}`,...i)}Re(t,i){return null}De(){return this.items.length}async _e(t){await this.Rs("items",t),this.items=t,await this._s("items",t)}async Fs(t){await this._e(t)}Us(t){for(let i=0;i<this.De();i++){const s=this.items[i];let e=s.view;s.Ot||(e=this.Re(t,s),s.view=e),this.ke(s,e,i),s.Ot=!0}}js(t){}}class C{constructor(t){this.parent=null,this.view=null,this.parent=t}zs(){}update(){}Ui(){if(!this.view?.view)throw Error("View is not mounted. Did you forget to set this.view?");return this.view.view}}class T extends C{constructor(){super(...arguments),this.view=null}zs(){const t=e.O(7);this.view=e.F({Ne:{tag:{node:"div",classList:["selective-ui-group"],role:"group",S:`seui-${t}-header`,id:`seui-${t}-group`},$:{Be:{tag:{node:"div",classList:["selective-ui-group-header"],role:"presentation",id:`seui-${t}-header`}},ze:{tag:{node:"div",classList:["selective-ui-group-items"],role:"group"}}}}}),this.parent.appendChild(this.view.view)}update(){this.Qi()}Qi(t=null){this.view&&null!==t&&(this.view.tags.Be.textContent=t)}Ue(){if(!this.view)throw Error("GroupView is not rendered.");return this.view.tags.ze}ss(){if(!this.view)return;const t=Array.from(this.view.tags.ze.children).filter(t=>!t.classList.contains("hide"));this.view.view.classList.toggle("hide",!(t.length>0))}Yi(t){this.view&&(this.view.view.classList.toggle("collapsed",t),this.view.tags.Be.setAttribute("aria-expanded",t?"false":"true"))}}class S extends C{constructor(t){super(t),this.view=null,this.config=null,this.Ge=null,this.We=!1,this.qe()}qe(){const t=this;this.config={isMultiple:!1,hasImage:!1,imagePosition:"right",imageWidth:"60px",imageHeight:"60px",imageBorderRadius:"4px",labelValign:"center",labelHalign:"left"},this.Ge=new Proxy(this.config,{set(i,s,e){if("string"!=typeof s)return!0;const h=s,n=i[h];return n!==e&&(i[h]=e,t.We&&t.Je(h,e,n)),!0}})}get isMultiple(){return this.config.isMultiple}set isMultiple(t){this.Ge.isMultiple=!!t}get hasImage(){return this.config.hasImage}set hasImage(t){this.Ge.hasImage=!!t}get Ke(){return this.Ge}set Ke(t){if(!t||!this.Ge||!this.config)return;const i={};void 0!==t.imageWidth&&t.imageWidth!==this.config.imageWidth&&(i.imageWidth=t.imageWidth),void 0!==t.imageHeight&&t.imageHeight!==this.config.imageHeight&&(i.imageHeight=t.imageHeight),void 0!==t.imageBorderRadius&&t.imageBorderRadius!==this.config.imageBorderRadius&&(i.imageBorderRadius=t.imageBorderRadius),void 0!==t.imagePosition&&t.imagePosition!==this.config.imagePosition&&(i.imagePosition=t.imagePosition),void 0!==t.labelValign&&t.labelValign!==this.config.labelValign&&(i.labelValign=t.labelValign),void 0!==t.labelHalign&&t.labelHalign!==this.config.labelHalign&&(i.labelHalign=t.labelHalign),Object.keys(i).length>0&&Object.assign(this.Ge,i)}zs(){const t=["selective-ui-option-view"],i=e.O(7),s="option_"+i;this.config.isMultiple&&t.push("multiple"),this.config.hasImage&&(t.push("has-image"),t.push("image-"+this.config.imagePosition));const h={ps:{tag:{node:"input",type:this.config.isMultiple?"checkbox":"radio",classList:"allow-choice",id:s}},...this.config.hasImage&&{ys:{tag:{node:"img",classList:"option-image",style:{width:this.config.imageWidth,height:this.config.imageHeight,borderRadius:this.config.imageBorderRadius}}}},Qe:{tag:{node:"label",htmlFor:s,classList:["align-vertical-"+this.config.labelValign,"align-horizontal-"+this.config.labelHalign]},$:{ws:{tag:{node:"div"}}}}};this.view=e.F({Ye:{tag:{node:"div",id:`seui-${i}-option`,classList:t,role:"option",ariaSelected:"false",tabIndex:"-1"},$:h}}),this.parent.appendChild(this.view.view),this.We=!0}Je(t,i,s){const e=this.view;if(!e||!e.view)return;const h=e.view,n=e.tags?.ps,o=e.tags?.Qe;switch(t){case"isMultiple":{const t=!!i;h.classList.toggle("multiple",t),n&&n.type!==(t?"checkbox":"radio")&&(n.type=t?"checkbox":"radio");break}case"hasImage":{const t=!!i;if(h.classList.toggle("has-image",t),t)h.classList.add("image-"+this.config.imagePosition),this.Xe();else{h.className=h.className.replace(/image-(top|right|bottom|left)/g,"").trim();const t=e.tags?.ys;t&&(t.remove(),e.tags.ys=null)}break}case"imagePosition":this.config.hasImage&&(h.className=h.className.replace(/image-(top|right|bottom|left)/g,"").trim(),h.classList.add("image-"+i));break;case"imageWidth":case"imageHeight":case"imageBorderRadius":{const s=e.tags?.ys;if(s){const e="imageWidth"===t?"width":"imageHeight"===t?"height":"borderRadius",h=i+"";s.style[e]!==h&&(s.style[e]=h)}break}case"labelValign":case"labelHalign":if(o){const t=`align-vertical-${this.config.labelValign} align-horizontal-${this.config.labelHalign}`;o.className!==t&&(o.className=t)}}}Xe(){const t=this.view;if(!t||!t.view)return;const i=t.tags?.ys;if(i)return;const s=t.view,e=t.tags?.Qe,h=document.createElement("img");h.className="option-image",h.style.width=this.config.imageWidth,h.style.height=this.config.imageHeight,h.style.borderRadius=this.config.imageBorderRadius,e&&e.parentElement?s.insertBefore(h,e):s.appendChild(h),t.tags.ys=h}}class H extends A{constructor(t=[]){super(t),this.isMultiple=!1,this.Ze=[],this.th=-1,this.ih=null,this.groups=[],this.sh=[],this.eh(),e.tt.on("sche_vis_"+this.$e,()=>{const t=this.sh.filter(t=>t.visible).length,i=this.sh.length;this.Ze.forEach(s=>{s({hh:t,nh:i,si:t>0,isEmpty:0===i})}),e.tt.run("sche_vis_proxy_"+this.$e)},{et:10})}eh(){this.sh=[],this.groups=[],this.items.forEach(t=>{t instanceof m?(this.groups.push(t),this.sh.push(...t.items)):t instanceof b&&this.sh.push(t)})}Re(t,i){return i instanceof m?new T(t):new S(t)}ke(t,i,s){t.position=s,t instanceof m?this.oh(t,i,s):t instanceof b&&this.rh(t,i,s),t.Ot=!0}oh(t,i,s){super.ke(t,i,s),t.view=i;const e=i.view.tags.Be;e.textContent=t.label,t.Ot||(e.style.cursor="pointer",e.addEventListener("click",()=>{t.Zi()}),t.Xi((t,i,s)=>{i.items.forEach(t=>{const i=t.view?.Ui?.();i&&(i.style.display=s?"none":"")}),this.ah(i,s)}));const h=i.Ue();t.items.forEach((t,i)=>{let s=t.view;t.Ot&&s||(s=new S(h)),this.rh(t,s,i),t.Ot=!0}),i.Yi(t.collapsed),i.ss()}rh(t,i,s){if(i.isMultiple=this.isMultiple,i.hasImage=t.hasImage,i.Ke={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.ke(t,i,s),t.view=i,t.hasImage){const s=i.view.tags.ys;s&&(s.src!==t.us&&(s.src=t.us),s.alt!==t.text&&(s.alt=t.text))}i.view.tags.ws.innerHTML=t.text,t.Ot||(i.view.tags.Ye.addEventListener("click",async i=>{i.stopPropagation(),i.preventDefault(),this.$s||(this.isMultiple?(await this.Rs("select"),t.selected=!t.selected):!0!==t.selected&&(await this.Rs("select"),this.ih&&(this.ih.selected=!1),t.selected=!0))}),i.view.tags.Ye.title=t.textContent,i.view.tags.Ye.addEventListener("mouseenter",()=>{this.$s||this.uh(this.sh.indexOf(t),!1)}),t.fs(()=>{this._s("selected")}),t.bs((i,s,e)=>{e&&(this.ih=t),this._s("selected_internal")}),t.ri((t,i)=>{i.group?.ss(),this.dh()})),t.selected&&(this.ih=t,t.ds=!0)}async _e(t){await this.Rs("items",t),this.items=t,this.eh(),await this._s("items",t)}async Fs(t){await this._e(t)}js(t){this.items=t,this.eh()}ph(){return this.sh.filter(t=>t.selected)}gh(){return this.sh.find(t=>t.selected)}Xt(t){this.isMultiple&&this.sh.forEach(i=>{i.selected=t})}ri(t){this.Ze.push(t)}dh(){e.tt.run("sche_vis_"+this.$e)}ei(){const t=this.sh.filter(t=>t.visible).length,i=this.sh.length;return{hh:t,nh:i,si:t>0,isEmpty:0===i}}fh(){this.uh(0)}navigate(t,i=!0){const s=this.sh.filter(t=>t.visible);if(0===s.length)return;let e=s.findIndex(t=>t===this.sh[this.th]);-1===e&&(e=-1);let h=e+t;h>=s.length&&(h=0),h<0&&(h=s.length-1);const n=this.sh.indexOf(s[h]);this.uh(n,i)}mh(){if(this.th>-1&&this.sh[this.th]){const t=this.sh[this.th];if(t.visible){const i=t.view?.Ui?.();i&&i.click()}}}uh(t,i=!0){let s=0;if("number"==typeof t)s=t;else if(t instanceof b){const i=this.sh.indexOf(t);s=i>-1?i:0}else s=0;this.th>-1&&this.sh[this.th]&&(this.sh[this.th].gs=!1);for(let t=s;t<this.sh.length;t++){const s=this.sh[t];if(s?.visible){if(s.gs=!0,this.th=t,i){const i=s.view?.Ui?.();i?i.scrollIntoView({block:"center",behavior:"smooth"}):this.$t?.bh?.(t,{scrollIntoView:!0})}return void this.wh(t,s.view?.Ui?.()?.id)}}}wh(t,i){}ah(t,i){}}class P{constructor(t=0){this.yh=[],this.n=0,this.reset(t)}reset(t){this.n=t,this.yh=Array(t+1).fill(0)}add(t,i){for(let s=t;s<=this.n;s+=s&-s)this.yh[s]+=i}xh(t){let i=0;for(let s=t;s>0;s-=s&-s)i+=this.yh[s];return i}Oh(t,i){return i<t?0:this.xh(i)-this.xh(t-1)}Mh(t){this.reset(t.length),t.forEach((t,i)=>this.add(i+1,t))}Ah(t){let i=0,s=1;for(;s<<1<=this.n;)s<<=1;let e=0;for(let h=s;0!==h;h>>=1){const s=i+h;s<=this.n&&e+this.yh[s]<=t&&(i=s,e+=this.yh[s])}return i}}class L extends y{constructor(t=null){super(t),this.Ch={Kt:void 0,_t:36,Nt:8,Bt:!0,Th:!0},this.Sh=[],this.Hh=new P(0),this.Ph=new Map,this.Lh=!1,this.start=0,this.end=-1,this.Ih=null,this.Fh=null,this.updating=!1,this.Eh=!1,this.jh=0,this.$h=!1,this.Vh=!1,this.kh=0,this.Rh=0,this.Dh=0,this._h=0}configure(t){this.Ch={...this.Ch,...t}}Es(t){if(this.Yt&&this.dispose(),super.Es(t),t.$t=this,!this.Ns)return;this.Ns.replaceChildren();const i=e.j({Nh:{tag:{node:"div",classList:"selective-ui-virtual-pad-top"}},Bh:{tag:{node:"div",classList:"selective-ui-virtual-items"}},zh:{tag:{node:"div",classList:"selective-ui-virtual-pad-bottom"}}},this.Ns);if(this.Nh=i.Nh,this.Bh=i.Bh,this.zh=i.zh,this.Kt=this.Ch.Kt??this.Ns.closest(".selective-ui-popup")??this.Ns.parentElement,!this.Kt)throw Error("VirtualRecyclerView: scrollEl not found");this.Uh=this.Gh.bind(this),this.Kt.addEventListener("scroll",this.Uh,{passive:!0}),this.refresh(!1),this.Wh(),t?.ri?.(()=>this.qh())}suspend(){this.$h=!0,this.Jh(),this.Kt&&this.Uh&&this.Kt.removeEventListener("scroll",this.Uh),this.Kh&&(this.Kh.disconnect(),this.Vh=!0)}resume(){this.$h=!1,this.Kt&&this.Uh&&this.Kt.addEventListener("scroll",this.Uh,{passive:!0}),this.Vh&&(this.Wh(),this.Vh=!1),this.Qh()}refresh(t){if(!this.Yt||!this.Ns)return;t||this.qh();const i=this.Yt.De();this.jh=i,0!==i?(this.Sh.length=i,this.Lh||(this.Yh(),this.Lh=!0),this.Xh(i),this.Qh()):this.Zh()}bh(t,i){this.tn(t,t),i?.scrollIntoView&&this.sn(t)}sn(t){if((this.Yt?.De?.()??0)<=0)return;const i=this.en(t),s=this.hn()+i,e=Math.max(0,this.Kt.scrollHeight-this.Kt.clientHeight);this.Kt.scrollTop=Math.min(Math.max(0,s),e)}dispose(){this.Jh(),this.Kt&&this.Uh&&this.Kt.removeEventListener("scroll",this.Uh),this.Kh?.disconnect(),this.Ph.forEach(t=>t.remove()),this.Ph.clear()}qh(){if(!this.Yt)return;const t=this.Yt.De();t<=0||(this.suspend(),this.Zh(),this.nn(),this.rn(t),this.Xh(t),this.start=0,this.end=-1,this.resume())}Jh(){null!=this.Ih&&(cancelAnimationFrame(this.Ih),this.Ih=null),null!=this.Fh&&(cancelAnimationFrame(this.Fh),this.Fh=null)}Zh(){this.Ph.forEach(t=>t.remove()),this.Ph.clear(),this.Sh=[],this.Hh.reset(0),this.Nh.style.height="0px",this.zh.style.height="0px",this.Lh=!1,this.Dh=0,this._h=0}Yh(){this.ln(0);const t=this.Ph.get(0);if(!t)return;const i=this.an(t);if(isNaN(i)||(this.Ch._t=i),!this.Ch.Bt){t.remove(),this.Ph.delete(0);const i=this.Yt.items[0];i&&(i.Ot=!1,i.view=null)}}cn(t){const i=this.Yt?.items?.[t];return i?.visible??!0}un(t,i){for(let s=Math.max(0,t);s<i;s++)if(this.cn(s))return s;return-1}rn(t){this.Dh=0,this._h=0;for(let i=0;i<t;i++){if(!this.cn(i))continue;const t=this.Sh[i];null!=t&&(this.Dh+=t,this._h++)}}hn(){const t=this.Ns.getBoundingClientRect(),i=this.Kt.getBoundingClientRect();return Math.max(0,t.top-i.top+this.Kt.scrollTop)}dn(){const t=performance.now();if(t-this.kh<16)return this.Rh;const i=this.Kt.querySelector(".selective-ui-option-handle:not(.hide)");return this.Rh=i?.offsetHeight??0,this.kh=t,this.Rh}Qh(){null!=this.Ih||this.$h||(this.Ih=requestAnimationFrame(()=>{this.Ih=null,this.pn()}))}an(t){const i=t.getBoundingClientRect(),s=getComputedStyle(t);return Math.max(1,i.height+(parseFloat(s.marginTop)||0)+(parseFloat(s.marginBottom)||0))}gn(){return this.Ch.Th&&this._h>0?Math.max(1,this.Dh/this._h):this.Ch._t}Xh(t){const i=this.gn(),s=Array.from({length:t},(t,s)=>this.cn(s)?this.Sh[s]??i:0);this.Hh.Mh(s)}fn(t,i){if(!this.cn(t))return!1;const s=this.gn(),e=this.Sh[t]??s;if(Math.abs(i-e)<=L.mn)return!1;const h=this.Sh[t];return null==h?(this.Dh+=i,this._h++):this.Dh+=i-h,this.Sh[t]=i,this.Hh.add(t+1,i-e),!0}bn(t,i){const s=this.Hh.Ah(Math.max(0,t)),e=Math.min(i-1,s),h=this.un(e,i);return-1===h?Math.max(0,e):h}wn(t,i){i.setAttribute(L.yn,t+"");const s=this.Ph.get(t-1);if(s?.parentElement===this.Bh)return void s.after(i);const e=this.Ph.get(t+1);if(e?.parentElement===this.Bh)return void this.Bh.insertBefore(i,e);const h=Array.from(this.Bh.children);for(const s of h){const e=s.getAttribute(L.yn);if(e&&+e>t)return void this.Bh.insertBefore(i,s)}this.Bh.appendChild(i)}vn(t,i){if(i.parentElement!==this.Bh)return void this.wn(t,i);i.setAttribute(L.yn,t+"");const s=i.previousElementSibling,e=i.nextElementSibling;(s&&+s.getAttribute(L.yn)>t||e&&+e.getAttribute(L.yn)<t)&&(i.remove(),this.wn(t,i))}Wh(){this.Kh||(this.Kh=new ResizeObserver(()=>{this.Eh||this.$h||!this.Yt||null!=this.Fh||(this.Fh=requestAnimationFrame(()=>{this.Fh=null,this.xn()}))}),this.Kh.observe(this.Bh))}xn(){if(!this.Yt)return;const t=this.Yt.De();if(t<=0)return;let i=!1;for(let t=this.start;t<=this.end;t++){if(!this.cn(t))continue;const s=this.Yt.items[t],e=s?.view?.Ui?.();if(!e)continue;const h=this.an(e);this.fn(t,h)&&(i=!0)}i&&(this.Ch.Th&&this.Xh(t),this.Qh())}Gh(){this.Qh()}pn(){if(!this.updating&&!this.$h){this.updating=!0;try{if(!this.Yt)return;const t=this.Yt.De();if(t<=0)return;this.jh!==t&&(this.jh=t,this.Sh.length=t,this.Xh(t));const i=this.hn(),s=Math.max(0,this.Kt.scrollTop-i),e=this.dn(),h=Math.max(0,this.Kt.clientHeight-e),n=this.bn(s,t),o=this.en(n),r=i+o-this.Kt.scrollTop,l=this.bn(s,t);if(-1===l)return void this.Zh();const a=this.gn(),c=this.Ch.Nt*a;let u=this.un(Math.min(t-1,this.Hh.Ah(Math.max(0,s-c))),t)??l,d=Math.min(t-1,this.Hh.Ah(s+h+c));if(u===this.start&&d===this.end)return;this.start=u,this.end=d,this.Eh=!0;try{this.tn(this.start,this.end),this.On(this.start,this.end),this.Ch.Bt&&this.xn();const i=this.en(this.start),s=this.Mn(this.start,this.end),e=this.An(t),h=Math.max(0,e-i-s);this.Nh.style.height=i+"px",this.zh.style.height=h+"px"}finally{this.Eh=!1}const p=this.en(n),g=this.hn()+p-r,f=Math.max(0,this.Kt.scrollHeight-this.Kt.clientHeight),m=Math.min(Math.max(0,g),f),b=Math.abs(p-o)>1,w=Math.abs(this.Kt.scrollTop-m);b&&w>.5&&w<100&&(this.Kt.scrollTop=m)}finally{this.updating=!1}}}tn(t,i){for(let s=t;s<=i;s++)this.ln(s)}ln(t){if(!this.cn(t)){const i=this.Ph.get(t);return i?.parentElement===this.Bh&&i.remove(),void this.Ph.delete(t)}const i=this.Yt.items[t];if(!i)return;const s=this.Ph.get(t);if(s)return void(i?.view?(this.vn(t,s),this.Yt.ke(i,i.view,t)):(s.remove(),this.Ph.delete(t)));if(i.Ot)i.view&&this.Yt.ke(i,i.view,t);else{const s=this.Yt.Re(this.Bh,i);i.view=s,this.Yt.ke(i,s,t),i.Ot=!0}const e=i.view?.Ui?.();e&&(this.vn(t,e),this.Ph.set(t,e))}On(t,i){this.Ph.forEach((s,e)=>{(e<t||e>i)&&(s.parentElement===this.Bh&&s.remove(),this.Ph.delete(e))})}nn(){this.Ph.forEach((t,i)=>{this.cn(i)||(t.parentElement===this.Bh&&t.remove(),this.Ph.delete(i))})}en(t){return this.Hh.xh(t)}Mn(t,i){return this.Hh.Oh(t+1,i+1)}An(t){return this.Hh.xh(t)}}L.mn=.5,L.yn="data-vindex";class I{constructor(t=null,i=null){this.container={},this.oldValue=null,this.node=null,this.options=null,this.Cn=null,this.isOpen=!1,this.Tn=!1,this.Sn=!1,this.pe=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?.yi?.setAttribute("aria-disabled",t+""))}get Hn(){return!!this.options?.readonly}set Hn(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,s){const h=e._(i).options,l=new o(h),a=new r,c=new p(h),effector=t(),u=new w(h),g=new v(h),f=new x(i,u,this),m=new O(i),b=new M(i);this.pe=s,this.options=h,l.node&&(l.node.id=(h.Pn??"")+"");const A=e.j({Ln:{tag:{node:"div",classList:"selective-ui-MAIN"},$:{yi:{tag:{node:"div",classList:"selective-ui-view",tabIndex:0,onkeydown:t=>{"Enter"!==t.key&&" "!==t.key&&"ArrowDown"!==t.key||(t.preventDefault(),this.In()?.open())}},$:{Fn:{tag:l.node},En:{tag:a.node},$i:{tag:c.node}}}}}},null);this.container=A,this.node=A.view,i.parentNode?.insertBefore(this.node,i),this.node.insertBefore(i,A.tags.yi),g.Ks(A.tags.yi),g.Ys(u),A.tags.yi.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()}),n.ct(i,A.tags.yi),i.classList.add("init"),u.Cs(H),u.Ss(h.virtualScroll?L:y),u.Is(e.Y(i)),u.onUpdated=()=>{A.ne?.hi?.()},this.Cn=u,A.jn=f,A.placeholder=l,A.$n=a,A.Vn=c,A.effector=effector,A.targetElement=i,A.kn=g,A.Rn=m,A.Dn=b,A.ne=new d(i,h,u),A.ne.di(effector),A.ne.xi(f,h),A.ne.ui("selected",()=>{this.In()?.change(null,!0)}),A.ne.ui("selected_internal",()=>{this.In()?.change(null,!1)}),A.ne.ai("select",()=>{this.oldValue=this.In()?.value??""}),this.In()?.change(null,!1),m.connect(),m.St=t=>{u.update(e.Y(t)),this.In()?.refreshMask()},b.connect(),b.St=t=>{e.k(t.disabled)!==this.isDisabled&&(this.isDisabled=e.k(t.disabled)),e.k(t.readonly)!==this.Hn&&(this.Hn=e.k(t.readonly)),e.k(t.visible)!==this.isVisible&&(this.isVisible=e.k(t.visible??"1"))},h.ajax&&f.we(h.ajax);const C=A.ne.Pt;let T=null;const S=(t,i)=>{i||""!==t?(""!==t&&(this.Sn=!0),f.search(t).then(t=>{clearTimeout(T),e.tt.clear("sche_vis_proxy_"+C.$e),e.tt.on("sche_vis_proxy_"+C.$e,()=>{A.ne?.hi?.(),t?.Me&&(T=setTimeout(()=>{C.fh(),A.ne?.hi?.()},h.animationtime??0))},{et:10})}).catch(t=>{console.error("Search error:",t)})):f.clear()};let P=null;c.Ii=(t,i)=>{f.Oe(t)&&(P&&clearTimeout(P),f.ae()?(A.ne?.ti?.(),P=setTimeout(()=>{S(t,i)},h.delaysearchtime??0)):P=setTimeout(()=>{S(t,i)},10))},f.setPopup(A.ne),c.Fi=t=>{C.navigate(t)},c.Ei=()=>{C.mh()},c.ji=()=>{this.In()?.close(),A.tags.yi.focus()},C.wh=(t,i)=>{i&&c.ki(i)},C.ah=()=>{A.ne?.hi?.()},this.isDisabled=e.k(h.disabled),this.Hn=e.k(h.readonly)}_n(){const t=this.container??{},{Rn:i,Dn:s}=t;i?.disconnect&&i.disconnect(),s?.disconnect&&s.disconnect()}In(){const t=this.container,i=this,s=()=>this.pe.find(t.targetElement),n=e._(t.targetElement);if(!n)return null;const o=n.options,r={get targetElement(){return t.targetElement},get placeholder(){return t.placeholder.get()},set placeholder(i){t.placeholder?.set(i),t.Vn?.Vi(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.Nn().forEach(i=>{i.selected&&t.push(i.value)}),t},get valueString(){return this.valueArray.join(o.customDelimiter)},get valueOptions(){const t=[];return i.Nn(!0).forEach(i=>{t.push(i)}),t},get mask(){const t=[];return i.Nn(!0).forEach(i=>{t.push(i.text)}),t},get valueText(){const t=[];i.Nn(!0).forEach(i=>{t.push(i.text)});const s=t.length;return s>1?t:0===s?"":t[0]},get isOpen(){return i.isOpen},getParent:()=>t.view.parentElement,valueDataset(t,s=null,e=!1){var h=[];if(i.Nn(!0).forEach(t=>{h.push(s?t.dataset[s]:t.dataset)}),!e){if(0==h.length)return"";if(1==h.length)return h[0]}return h},selectAll(t,e=!0){if(!(o.multiple&&o.maxSelected>0&&i.Nn().length>o.maxSelected)&&!this.disabled&&!this.readonly&&o.multiple){if(e){if(h.ot([s()],...o.on.beforeChange).isCancel)return;i.oldValue=this.value}i.Nn().forEach(t=>{t.ds=!0}),this.change(!1,e)}},deSelectAll(t,e=!0){if(!this.disabled&&!this.readonly&&o.multiple){if(e){if(h.ot([s()],...o.on.beforeChange).isCancel)return;i.oldValue=this.value}i.Nn().forEach(t=>{t.ds=!1}),this.change(!1,e)}},setValue(e=null,n,r=!0,l=!1){if(Array.isArray(n)||(n=[n]),0===(n=n.filter(t=>""!==t&&null!=t)).length)return i.Nn().forEach(t=>t.ds=!1),void this.change(!1,r);if(o.multiple&&o.maxSelected>0&&n.length>o.maxSelected)console.warn(`Cannot select more than ${o.maxSelected} items`);else if(l||!this.disabled&&!this.readonly){if(t.jn?.ae?.()){const{be:s}=t.jn.fe(n);if(s.length>0)return void(async()=>{o.loadingfield&&t.ne?.ti?.();try{t.jn.ye();const e=await t.jn.ce(s);e.Ti&&e.items.length>0?(e.items.forEach(t=>{s.includes(t.value)&&(t.selected=!0)}),t.jn.Ce?.(e.items,!0,!0),setTimeout(()=>{i.Nn().forEach(t=>{t.ds=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{o.loadingfield&&t.ne?.ni?.()}})()}if(r){if(h.ot([s()],...o.on.beforeChange).isCancel)return;i.oldValue=this.value}i.Nn().forEach(t=>{t.ds=n.some(i=>i==t.value)}),!o.multiple&&n.length>0&&(t.targetElement.value=n[0]),this.change(!1,r)}},open(){if(i.isOpen)return;const e=i.pe?.find?.();if(e&&!e.isEmpty&&e.close().isCancel)return;if(this.disabled)return;if(h.ot([s()],...o.on.beforeShow).isCancel)return;i.isOpen=!0,t.$n.ut(!0);const n=t.ne.Pt,r=n.gh();r?n.uh(r,!1):n.fh(),i.Tn&&!i.Sn||!o?.ajax?t.ne.open(null,!0):(t.jn.ye(),t.ne.ti(),i.Tn=!0,i.Sn=!1,setTimeout(()=>{t.ne&&t.jn&&t.jn.search("").then(()=>t.ne?.hi?.()).catch(t=>console.error("Initial ajax load error:",t))},o.animationtime),t.ne.open(null,!1)),t.Vn.show();const l=t.tags.yi;l.setAttribute("aria-expanded","true"),l.setAttribute("aria-controls",o.Wt),l.setAttribute("aria-haspopup","listbox"),l.setAttribute("aria-labelledby",o.Pn),o.multiple&&l.setAttribute("aria-multiselectable","true"),h.ot([s()],...o.on.show)},close(){i.isOpen&&(h.ot([s()],...o.on.beforeClose).isCancel||(i.isOpen=!1,t.$n.ut(!1),t.ne.close(()=>{t.Vn.clear(!1)}),t.Vn.hide(),t.tags.yi.setAttribute("aria-expanded","false"),h.ot([s()],...o.on.close)))},toggle(){i.isOpen?this.close():this.open()},change(e=null,n=!0){if(n){if(o.multiple&&o.maxSelected>0&&this.valueArray.length>o.maxSelected&&this.setValue(null,this.oldValue,!1,!0),this.disabled||this.readonly)return void this.setValue(null,this.oldValue,!1,!0);if(h.ot([s(),this.value],...o.on.beforeChange).isCancel)return void this.setValue(null,this.oldValue,!1)}this.refreshMask(),t.kn.Xs(this.valueOptions),n&&(t.targetElement&&h.rt(t.targetElement,"change"),h.ot([s(),this.value],...o.on.change),i.options?.autoclose&&this.close())},refreshMask(){let s=o.placeholder;!o.multiple&&i.Nn().length>0&&(s=this.mask[0]),s??(s=o.placeholder),t.placeholder.set(s,!1),t.Vn.Vi(s)},on(t,i,s){o.on[i]||(o.on[i]=[]),o.on[i].push(s)},ajax(i,s){t.jn.we(s)},loadAjax:()=>new Promise((e,h)=>{t.ne.ti(),t.jn.ye(),i.Tn=!0,i.Sn=!1,t.ne&&t.jn?t.jn.search("").then(()=>{t.ne?.hi?.(),e(s())}).catch(t=>{console.error("Initial ajax load error:",t),h(t)}):e(s())})};return this.Bn(r,"disabled","isDisabled"),this.Bn(r,"readonly","isReadOnly"),this.Bn(r,"visible","isVisible"),r}Bn(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})}Nn(t=null){if(!this.Cn)return[];const{Vs:i}=this.Cn.Qt(),s=[];for(const t of i)t instanceof b?s.push(t):t instanceof m&&Array.isArray(t.items)&&t.items.length&&s.push(...t.items);return"boolean"==typeof t?s.filter(i=>i.selected===t):s}Si(){this.container.ne.Si()}}class F{constructor(){this.isActive=!1,this.Ie=null,this.actions=[]}zn(t){this.actions.push(t)}Un(){this.actions=[]}start(t){if(this.isActive)return;this.isActive=!0;const i=t.toUpperCase(),s=t.toLowerCase();this.Ie=new MutationObserver(t=>{for(const e of t)e.addedNodes.forEach(t=>{if(1!==t.nodeType)return;const e=t;e.tagName===i&&this.Gn(e),e.querySelectorAll(s).forEach(t=>this.Gn(t))})}),this.Ie.observe(document.body,{childList:!0,subtree:!0})}stop(){this.isActive&&(this.isActive=!1,this.Ie?.disconnect(),this.Ie=null)}Gn(t){this.actions.forEach(i=>i(t))}}const E=new class{constructor(){this.Wn=new Map}bind(t,i){const s=e.R(e.W(),i);s.on=s.on??{},s.on.load=s.on.load??[],this.Wn.set(t,s);const n=e.O();e.tt.on(n,()=>{h.ot([this.find(t)],...s.on.load),e.tt.clear(n),s.on.load=[]}),e.M(t).forEach(t=>{(async()=>{"SELECT"===t.tagName&&(e.B(t),this.qn(t,s)&&e.tt.run(n))})()}),e.t().includes(t)||e.t().push(t)}find(t="*"){const i={isEmpty:!0};if("*"===t&&""===(t=e.t().join(", ")))return i;const s=e.M(t);if(0===s.length)return i;const h=e._(s[0]);if(!h||!h.action)return i;const n={};for(const t in h.action)n[t]=this.Jn(t,h.action);const o={isEmpty:!1};for(const t in n){const i=n[t];switch(i.type){case"get-set":this.Kn(o,i.name,s);break;case"func":this.Qn(o,i.name,s)}}return o}i(){this.Yn=new F,this.Yn.zn(t=>{this.Wn.forEach((i,s)=>{try{t.matches(s)&&this.qn(t,i)}catch(t){console.warn("Invalid selector: "+s,t)}})}),this.Yn.start("select")}destroy(t=null){null===t?this.Xn():"string"==typeof t?this.Zn(t):t instanceof HTMLSelectElement&&this.io(t)}Xn(){e.t().forEach(t=>this.Zn(t)),this.Wn.clear(),e.t().length=0,this.Yn?.stop()}Zn(t){e.M(t).forEach(t=>{"SELECT"===t.tagName&&this.io(t)}),this.Wn.delete(t);const i=e.t(),s=i.indexOf(t);s>-1&&i.splice(s,1)}io(t){const i=e._(t);if(!i)return;const s=i.container?.ne;s?.Si(),e.G(t,i);const h=!!this.Yn;h&&this.Yn?.stop();try{i.self?._n?.()}catch(t){}const n=i.container?.element??t.parentElement;t.style.display="",t.style.visibility="",t.disabled=!1,delete t.dataset.so,n&&n.parentNode?n.parentNode.replaceChild(t,n):document.body.appendChild(t),e.D(t),h&&this.Wn.size>0&&this.Yn?.start("select")}rebind(t,i){this.Zn(t),this.bind(t,i)}qn(t,i){if(e._(t)||e.U(t))return!1;const s=e.O(8),h=e.V(t,i);h.eo=s,h.Wt=`seui-${s}-optionlist`,h.Pn=`seui-${s}-placeholder`;const n={options:h};e.N(t,n);const o=new I(t,this);return n.container=o.container,n.action=o.In(),n.self=o,o.container.view.addEventListener("mouseup",()=>{n.action?.toggle?.()}),!0}Jn(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}}Kn(t,i,s){Object.defineProperty(t,i,{get(){const t=e._(s[0]);return t.action?.[i]},set(t){s.forEach(s=>{const h=e._(s);h?.action&&(h.action[i]=t)})},enumerable:!0,configurable:!0})}Qn(t,i,s){t[i]=(...n)=>{let o=null;for(let t=0;t<s.length;t++){const r=e._(s[t]);if(!r?.action)continue;const l=h.nt();if(o??(o=r.action[i](l.ht,...n)),!l.token.isContinue)break}return o??t}}},version="1.2.3",j="SelectiveUI";let $=!1;"undefined"!=typeof document&&("loading"===document.readyState?document.addEventListener("DOMContentLoaded",i):i());export{bind,destroy,effector,find,j as name,rebind,version};
Binary file