selective-ui 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/selective-ui.css +3 -1
  2. package/dist/selective-ui.css.map +1 -1
  3. package/dist/selective-ui.esm.js +435 -405
  4. package/dist/selective-ui.esm.js.map +1 -1
  5. package/dist/selective-ui.esm.min.js +2 -2
  6. package/dist/selective-ui.esm.min.js.br +0 -0
  7. package/dist/selective-ui.min.css +1 -1
  8. package/dist/selective-ui.min.css.br +0 -0
  9. package/dist/selective-ui.min.js +2 -2
  10. package/dist/selective-ui.min.js.br +0 -0
  11. package/dist/selective-ui.umd.js +436 -406
  12. package/dist/selective-ui.umd.js.map +1 -1
  13. package/package.json +1 -1
  14. package/src/css/components/popup.css +3 -1
  15. package/src/ts/adapter/mixed-adapter.ts +40 -40
  16. package/src/ts/components/accessorybox.ts +49 -21
  17. package/src/ts/components/directive.ts +3 -3
  18. package/src/ts/components/empty-state.ts +7 -7
  19. package/src/ts/components/loading-state.ts +7 -7
  20. package/src/ts/components/option-handle.ts +17 -17
  21. package/src/ts/components/placeholder.ts +12 -12
  22. package/src/ts/components/popup.ts +93 -108
  23. package/src/ts/components/searchbox.ts +14 -14
  24. package/src/ts/components/selectbox.ts +25 -22
  25. package/src/ts/core/base/adapter.ts +12 -12
  26. package/src/ts/core/base/model.ts +12 -13
  27. package/src/ts/core/base/recyclerview.ts +7 -7
  28. package/src/ts/core/base/view.ts +6 -6
  29. package/src/ts/core/base/virtual-recyclerview.ts +50 -50
  30. package/src/ts/core/model-manager.ts +53 -53
  31. package/src/ts/core/search-controller.ts +69 -69
  32. package/src/ts/models/group-model.ts +21 -21
  33. package/src/ts/models/option-model.ts +30 -30
  34. package/src/ts/services/dataset-observer.ts +17 -17
  35. package/src/ts/services/ea-observer.ts +21 -21
  36. package/src/ts/services/effector.ts +25 -25
  37. package/src/ts/services/refresher.ts +1 -1
  38. package/src/ts/services/resize-observer.ts +29 -29
  39. package/src/ts/services/select-observer.ts +29 -29
  40. package/src/ts/types/components/popup.type.ts +15 -0
  41. package/src/ts/types/utils/istorage.type.ts +1 -1
  42. package/src/ts/utils/callback-scheduler.ts +4 -4
  43. package/src/ts/utils/ievents.ts +4 -4
  44. package/src/ts/utils/istorage.ts +5 -5
  45. package/src/ts/utils/libs.ts +38 -29
  46. package/src/ts/utils/selective.ts +11 -11
  47. package/src/ts/views/group-view.ts +7 -7
  48. package/src/ts/views/option-view.ts +51 -51
@@ -1,2 +1,2 @@
1
- /*! Selective UI v1.2.1 | MIT License */
2
- var t,i;t=this,i=function(t){"use strict";function i(t){return new g(t??null)}class s{constructor(){this.t={showPanel:!0,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.i=new Map,this.h=new Map,this.o=[]}}class e{static get l(){return this.u||(this.u=new s),this.u}static p(t){if(null===t||"object"!=typeof t)return t;const i=Array.isArray(t)?[]:{};for(const s in t)Object.prototype.hasOwnProperty.call(t,s)&&(i[s]=this.p(t[s]));return i}static m(t=6){let i="";for(let s=0;s<t;s++)i+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random()));return i}static v(t){if(!t)return[];if("string"==typeof t){const i=document.querySelectorAll(t);return Array.from(i)}return t instanceof Element?[t]:t instanceof NodeList||Array.isArray(t)?Array.from(t):[]}static T(t={}){return this.O(document.createElement(t.node??"div"),t,!0)}static O(t=document.documentElement,i=null,s=!1){const e={...i??{}},h=s?t:this.M(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.A&&(h.setAttribute("aria-labelledby",e.A+""),delete e.A),e.C&&(h.setAttribute("aria-controls",e.C+""),delete e.C),e.S&&(h.setAttribute("aria-haspopup",e.S+""),delete e.S),e.H&&(h.setAttribute("aria-multiselectable",e.H+""),delete e.H),e.L&&(h.setAttribute("aria-autocomplete",e.L+""),delete e.L),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 M(t){if(t instanceof Element)return t;throw new TypeError("Node is not an Element")}static P(t){return this.I(t)}static I(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?.F&&this.I(r.F,l,!1,!1,h),i?s?i.prepend(l):i.append(l):e||n||(n=l)}return e||(h.id=this.m(7),i||(h={tags:h,view:n})),h}static j(t,i){const s=this.p(i);for(const e in s){const i=t[e];i?s[e]=i:void 0!==t?.dataset?.[e]&&(s[e]=t.dataset[e])}return s}static $(...t){if(0===t.length)return{};if(1===t.length)return this.p(t[0]);const i=this.p(t[0]);for(let s=1;s<t.length;s++){const e=t[s];for(const t in e)if("on"===t){const s=e[t];for(const e in s)i[t][e].push(s[e])}else i[t]=e[t]}return i}static V(t){if("boolean"==typeof t)return t;if("string"!=typeof t)return!!t;switch(t.trim().toLowerCase()){case"true":case"1":case"yes":case"on":return!0;default:return!1}}static k(t){return this.l.i.delete(t)}static _(t){return this.l.i.get(t)}static R(t,i){this.l.i.set(t,i)}static D(t){return this.l.h.delete(t)}static N(t){return this.l.h.get(t)}static B(t,i){this.l.h.set(t,i)}static U(){return this.l.t}static G(){return this.l.o}static W(t){if(null==t)return"";let i=(t+"").replace(/<`/g,"<").replace(/`>/g,">").replace(/\<\`/g,"<").replace(/\`\>/g,">").trim();const s=globalThis?.document;if(!s||"function"!=typeof s.createElement)return i=i.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"").replace(/<iframe\b[^>]*>[\s\S]*?<\/iframe>/gi,"").replace(/<(object|embed|link)\b[^>]*>[\s\S]*?<\/\1>/gi,""),i=i.replace(/\son[a-z]+\s*=\s*(['"]).*?\1/gi,""),i=i.replace(/\s([a-z-:]+)\s*=\s*(['"])\s*javascript:[^'"]*\2/gi,""),i;const e=s.createElement("div");return e.innerHTML=i,e.querySelectorAll("script, style, iframe, object, embed, link").forEach(t=>t.remove()),e.querySelectorAll("*").forEach(t=>{for(const i in t.attributes){const s=t.attributes[i],e=s.name??"",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 q(t){const i=document.createElement("DIV");i.innerHTML=t;const s=i.textContent??i.innerText??"";return i.remove(),s.trim()}static J(t){return null==t?"":(t+"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/đ/g,"d").replace(/Đ/g,"d")}static K(t){const i=[];return Array.from(t.children).forEach(t=>{if("OPTGROUP"===t.tagName){const s=t;i.push(s),Array.from(s.children).forEach(t=>{t.__parentGroup=s,i.push(t)})}else"OPTION"===t.tagName&&i.push(t)}),i}static Y(){const t=navigator.userAgent;return/iP(hone|ad|od)/.test(t)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1}static X(t){const i=(t+"").trim();if(i.endsWith("px"))return i;if(i.endsWith("vh"))return window.innerHeight*parseFloat(i)/100+"px";if(i.endsWith("vw"))return window.innerWidth*parseFloat(i)/100+"px";const s=parseFloat(getComputedStyle(document.documentElement).fontSize);if(i.endsWith("rem"))return s*parseFloat(i)+"px";const e=this.T({node:"div",style:{height:i,opacity:"0"}});document.body.appendChild(e);const h=e.offsetHeight+"px";return e.remove(),h}}e.u=null,e.Z=new class{constructor(){this.tt=new Map,this.it=new Map}on(t,i,s={}){const e=s.st??50,h=s.once??!1;this.tt.has(t)||this.tt.set(t,[]),this.tt.get(t).push({et:i,timeout:e,once:h})}off(t){const i=this.it.get(t);if(i){for(const t of i.values())clearTimeout(t);i.clear(),this.it.delete(t)}this.tt.delete(t)}run(t,...i){const s=this.tt.get(t);if(!s)return;this.it.has(t)||this.it.set(t,new Map);const e=this.it.get(t);for(let h=0;h<s.length;h++){const t=s[h];if(!t)continue;const n=e.get(h);n&&clearTimeout(n);const o=setTimeout(()=>{if(t.et(i.length>0?i:null),t.once){s[h]=void 0;const t=e.get(h);t&&clearTimeout(t),e.delete(h)}},t.timeout);e.set(h,o)}}clear(t){if(void 0===t)for(const i of Array.from(this.tt.keys()))this.off(i);else this.off(t)}};class h{static ht(){const t={isContinue:!0,isCancel:!1};return{token:{get isContinue(){return t.isContinue},get isCancel(){return t.isCancel}},et:{stopPropagation(){t.isContinue=!1},cancel(){t.isCancel=!0,t.isContinue=!1}}}}static nt(t,...i){const{token:s,et:e}=this.ht();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 ot(t,i,s={bubbles:!0,cancelable:!0}){const e=new Event(i,s);return t.dispatchEvent(e),e}static rt(t,...i){if(Array.isArray(t))for(const s of t)"function"==typeof s&&s(...i)}}class n{static lt(t,i){const 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.ct=null,t&&this.init(t)}init(t){this.node=e.T({node:"div",classList:"selective-ui-placeholder",innerHTML:t.placeholder}),this.ct=t}get(){return this.ct?.placeholder??""}set(t,i=!0){if(!this.node||!this.ct)return;i&&(this.ct.placeholder=t);const s=e.W(t);this.node.innerHTML=this.ct.allowHtml?s:e.q(s)}}class r{constructor(){this.node=this.ut()}ut(){return e.T({node:"div",classList:"selective-ui-directive",role:"button",ariaLabel:"Toggle dropdown"})}dt(t){this.node.classList.toggle("drop-down",!!t)}}class l{constructor(t=null){this.gt=null,this.node=null,this.options=null,this.ft=[],this.bt=[],t&&this.init(t)}init(t){this.gt=e.I({wt:{tag:{node:"div",classList:["selective-ui-option-handle","hide"]},F:{yt:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textSelectAll,onclick:()=>{h.rt(this.ft)}}},vt:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textDeselectAll,onclick:()=>{h.rt(this.bt)}}}}}}),this.node=this.gt.view,this.options=t}available(){return!!this.options&&e.V(this.options.multiple)&&e.V(this.options.selectall)}refresh(){this.node&&(this.available()?this.show():this.hide())}show(){this.node&&this.node.classList.remove("hide")}hide(){this.node&&this.node.classList.add("hide")}xt(t=null){"function"==typeof t&&this.ft.push(t)}Tt(t=null){"function"==typeof t&&this.bt.push(t)}}class a{constructor(t=null){this.node=null,this.options=null,t&&this.init(t)}init(t){this.options=t,this.node=e.T({node:"div",classList:["selective-ui-empty-state","hide"],role:"status",ariaLive:"polite"})}show(t="nodata"){this.node&&this.options&&(this.node.textContent="notfound"===t?this.options.textNotFound:this.options.textNoData,this.node.classList.remove("hide"))}hide(){this.node&&this.node.classList.add("hide")}get isVisible(){return!!this.node&&!this.node.classList.contains("hide")}}class c{constructor(t=null){this.node=null,this.options=null,t&&this.init(t)}init(t){this.options=t,this.node=e.T({node:"div",classList:["selective-ui-loading-state","hide"],textContent:t.textLoading,role:"status",ariaLive:"polite"})}show(t){this.node&&this.options&&(this.node.textContent=this.options.textLoading,this.node.classList.toggle("small",!!t),this.node.classList.remove("hide"))}hide(){this.node&&this.node.classList.add("hide")}get isVisible(){return!!this.node&&!this.node.classList.contains("hide")}}class u{constructor(){this.Ot=!1,this.element=null,this.Mt=null,this.At=null,this.Ot=!0,this.Ct=this.St.bind(this)}Ht(t){}St(){const t=this.element;if(!t||"function"!=typeof t.getBoundingClientRect)return void this.Ht({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.Ht({width:i?.width??0,height:i?.height??0,top:i?.top??0,left:i?.left??0,padding:{top:parseFloat(s?.paddingTop??"0"),right:parseFloat(s?.paddingRight??"0"),bottom:parseFloat(s?.paddingBottom??"0"),left:parseFloat(s?.paddingLeft??"0")},border:{top:parseFloat(s?.borderTopWidth??"0"),right:parseFloat(s?.borderRightWidth??"0"),bottom:parseFloat(s?.borderBottomWidth??"0"),left:parseFloat(s?.borderLeftWidth??"0")},margin:{top:parseFloat(s?.marginTop??"0"),right:parseFloat(s?.marginRight??"0"),bottom:parseFloat(s?.marginBottom??"0"),left:parseFloat(s?.marginLeft??"0")}})}ot(){this.St()}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.Ht=()=>{},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.Lt=!1,this.Pt=null,this.node=null,this.It=null,this.Et=null,this.Ft=null,this.jt=null,this.$t=null,this.Vt=null,this.kt=null,this._t=null,this.Rt=null,this.Dt=null,this.Nt={Bt:36,Ut:8,zt:!0},this.Gt=s,t&&i&&this.init(t,i)}init(t,i){if(!this.Gt)throw Error("Popup requires a ModelManager instance.");this.jt=new l(i),this.$t=new a(i),this.Vt=new c(i);const s=e.I({Wt:{tag:{node:"div",classList:"selective-ui-popup",style:{maxHeight:i.panelHeight}},F:{wt:{tag:this.jt.node},qt:{tag:{id:i.Jt,node:"div",classList:"selective-ui-options-container",role:"listbox"}},Kt:{tag:this.Vt.node},Qt:{tag:this.$t.node}}}},null);this.node=s.view,this._t=s.tags.qt,this.Ft=e._(t),this.options=i,this.Gt.load(this._t,{isMultiple:i.multiple},i.virtualScroll?{Yt:this.node,Bt:this.Nt.Bt,Ut:this.Nt.Ut,zt:this.Nt.zt}:{});const h=this.Gt.Xt();this.Pt=h.Zt,this.kt=h.kt,this.jt.xt(()=>{h.Zt.ti(!0)}),this.jt.Tt(()=>{h.Zt.ti(!1)}),this.ii()}async si(){this.options&&this.Vt&&this.jt&&this.Pt&&this.Gt&&(this.Dt&&clearTimeout(this.Dt),this.Gt.ei(!0),!1!==e.V(this.options.loadingfield)&&(this.$t.hide(),this.Vt.show(this.Pt.ni().hi),this.oi()))}async ri(){this.options&&this.Vt&&this.Pt&&this.Gt&&(this.Dt&&clearTimeout(this.Dt),this.Dt=setTimeout(()=>{this.Gt?.ei(!1),this.Vt?.hide();const t=this.Pt?.ni();this.li(t??void 0),this.oi()},200))}ii(){this.Pt&&(this.Pt.ai(t=>{this.li(t)}),this.Pt.ci("items",()=>{const t=this.Pt.ni();this.li(t),this.oi()}))}li(t){if(!(this.Pt&&this.$t&&this.jt&&this._t))return;const i=t??this.Pt.ni();i.isEmpty?(this.$t.show("nodata"),this._t.classList.add("hide"),this.jt.hide()):i.hi?(this.$t.hide(),this._t.classList.remove("hide"),this.jt.refresh()):(this.$t.show("notfound"),this._t.classList.add("hide"),this.jt.hide())}ui(t,i){this.Pt?.di(t,i)}pi(t,i){this.Pt?.ci(t,i)}gi(t){this.It=t}open(t=null,i){if(!(this.node&&this.options&&this.jt&&this.Ft&&this.It))return;this.Lt||(document.body.appendChild(this.node),this.Lt=!0,this.Et=new u,this.It.fi(this.node),this.node.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()})),this.jt.refresh(),i&&this.li();const s=this.mi(),{position:e,top:h,maxHeight:n,bi:o}=this.wi(s);this.It.expand({duration:this.options.animationtime,display:"flex",width:s.width,left:s.left,top:h,maxHeight:n,bi:o,position:e,yi:()=>{if(!this.Et||!this.Ft)return;this.Et.Ht=()=>{const t=this.mi();this.xi(t)},this.Et.connect(this.Ft.container.tags.Ti),t?.();const i=this.kt;i?.resume?.()}})}close(t=null){if(!(this.Lt&&this.options&&this.Et&&this.It))return;const i=this.kt;i?.suspend?.(),this.Et.disconnect(),this.It.collapse({duration:this.options.animationtime,yi:t??void 0})}oi(){this.Lt&&this.Et?.ot()}Oi(t,i){this.node&&(this.Rt=async()=>{const i=t.Mi();if(!i.Ai)return;const s=this.node;if(s.scrollHeight-s.scrollTop-s.clientHeight<100&&!i.Ci&&i.hasMore){const i=await t.Si();!i.Hi&&i.message&&console.log("Load more:",i.message)}},this.node.addEventListener("scroll",this.Rt))}Li(){this.Dt&&(clearTimeout(this.Dt),this.Dt=null),this.node&&this.Rt&&(this.node.removeEventListener("scroll",this.Rt),this.Rt=null);try{this.Et?.disconnect()}catch(t){}this.Et=null;try{this.It?.fi?.(null)}catch(t){}if(this.It=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._t=null;try{this.Gt?.ei?.(!1),this.kt?.clear?.(),this.kt=null,this.Pt=null,this.node.remove()}catch(t){}this.Gt=null,this.jt=null,this.$t=null,this.Vt=null,this.Ft=null,this.options=null,this.Lt=!1}mi(){const t=this.Ft.container.tags.Ti,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)}}}wi(t){const i=window.visualViewport,s=e.Y(),h=i?.height??window.innerHeight,n=this.It.Pi("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,bi:d,Ii:n}}xi(t){if(!this.options||!this.It)return;const{position:i,top:s,maxHeight:e,bi:h}=this.wi(t);this.It.resize({duration:this.options.animationtime,width:t.width,left:t.left,top:s,maxHeight:e,bi:h,position:i,animate:!0})}}class p{constructor(t=null){this.gt=null,this.node=null,this.Ei=null,this.Fi=null,this.options=null,this.ji=null,this.$i=null,this.Vi=null,this.options=t,t&&this.init(t)}init(t){this.gt=e.I({ki:{tag:{node:"div",classList:["selective-ui-searchbox","hide"]},F:{Ei:{tag:{id:e.m(),node:"input",type:"search",classList:["selective-ui-searchbox-input"],placeholder:t.placeholder,role:"searchbox",C:t.Jt,L:"list"}}}}}),this.node=this.gt.view,this.Ei=this.gt.tags.Ei;let i=!1;const s=this.gt.tags.Ei;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.ji?.(1)):"ArrowUp"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.ji?.(-1)):"Enter"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.$i?.()):"Escape"===t.key&&(t.preventDefault(),t.stopPropagation(),i=!0,this.Vi?.()),t.stopPropagation()}),s.addEventListener("input",()=>{i||this.Fi?.(s.value,!0)})}show(){this.node&&this.Ei&&this.options&&(this.node.classList.remove("hide"),this.Ei.readOnly=!this.options.searchable,this.options.searchable&&requestAnimationFrame(()=>{this.Ei?.focus()}))}hide(){this.node&&this.node.classList.add("hide")}clear(t=!0){this.gt&&(this.gt.tags.Ei.value="",this.Fi?.("",t))}_i(t){this.Ei&&(this.Ei.placeholder=e.q(t))}Ri(t){this.Ei&&this.Ei.setAttribute("aria-activedescendant",t)}}class g{constructor(t=null){this.Di=null,this.Ni=null,this.Bi=!1,t&&this.fi(t)}fi(t){if("string"==typeof t){const i=document.querySelector(t);return void(i instanceof HTMLElement&&(this.element=i))}this.element=t}cancel(){return this.Di&&(clearTimeout(this.Di),this.Di=null),this.Ni&&(clearTimeout(this.Ni),this.Ni=null),this.Bi=!1,this}Pi(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.Bi=!0;const{duration:i=200,display:s="flex",width:e,left:h,top:n,maxHeight:o,bi:r,position:l="bottom",yi: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.Di=setTimeout(()=>{this.element.style.transition="none",this.Bi=!1,a?.()},i)}),this}collapse(t){if(!this.element)return this;this.cancel(),this.Bi=!0;const{duration:i=200,yi: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.Di=setTimeout(()=>{Object.assign(this.element.style,{display:"none",transition:"none"}),this.Bi=!1,s?.()},i)}),this}showSwipeWidth(t){if(!this.element)return this;this.cancel(),this.Bi=!0;const{duration:i=200,display:s="block",yi:e}=t;Object.assign(this.element.style,{transition:"none",display:s,width:"fit-content"});const h=this.Pi(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.Di=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:""}),this.Bi=!1,e?.()},i),this}hideSwipeWidth(t){if(!this.element)return this;this.cancel(),this.Bi=!0;const{duration:i=200,yi:s}=t,e=this.Pi().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.Di=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:"",display:""}),this.Bi=!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,bi:o,position:r="bottom",animate:l=!0,yi: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.Ni=setTimeout(()=>{this.element?.style&&(this.element.style.transition=null)},i),Object.assign(this.element.style,t),l&&(c||r>1)?this.Ni=setTimeout(()=>{this.element.style.transition=null,c&&delete this.element.style.transition,a?.()},i):(c&&delete this.element.style.transition,a?.())},20),this}get Ui(){return this.Bi}}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.zi=!1,this.options=t,this.targetElement=i,this.view=s}update(t){this.targetElement=t,this.Gi()}remove(){this.targetElement=null,this.view?.Wi()?.remove?.(),this.view=null,this.zi=!0,this.qi()}Gi(){}qi(){}}class m extends f{constructor(t,i){super(t,i??null,null),this.label="",this.items=[],this.collapsed=!1,this.Ji=[],i&&(this.label=i.label,this.collapsed=e.V(i.dataset?.collapsed))}get value(){return this.items.map(t=>t.value)}get Ki(){return this.items.filter(t=>t.selected)}get Qi(){return this.items.filter(t=>t.visible)}get Yi(){return this.Qi.length>0}update(t){this.label=t.label,this.view?.Xi(this.label)}Gi(){this.view&&(this.view.Xi(this.label),this.view.Zi(this.collapsed))}ts(t){this.Ji.push(t)}ss(){this.collapsed=!this.collapsed,this.view?.Zi(this.collapsed),h.nt([this,this.collapsed],...this.Ji)}es(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)}hs(){this.view?.hs()}}class b extends f{constructor(t,i=null,s=null){super(t,i,s),this.ns=[],this.rs=[],this.ls=[],this.cs=!0,this.us=!1,this.group=null,(async()=>{this.ds=e.J(this.textContent.toLowerCase())})()}get ps(){return this.dataset?.imgsrc||this.dataset?.image||""}get hasImage(){return!!this.ps}get value(){return this.targetElement?.value??""}get selected(){return!!this.targetElement?.selected}set selected(t){this.gs=t,h.nt([this,t],...this.ns)}get visible(){return this.cs}set visible(t){if(this.cs===t)return;this.cs=t;const i=this.view?.Wi?.();i&&i.classList.toggle("hide",!t),h.nt([this,t],...this.ls)}get gs(){return this.selected}set gs(t){const i=this.view?.view?.tags?.fs,s=this.view?.Wi?.();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.nt([this,t],...this.rs)}get text(){const t=e.W(this.dataset?.mask??this.targetElement?.text??"");return this.options.allowHtml?t:e.q(t)}get textContent(){return this.options.allowHtml?e.q(this.text).trim():this.text.trim()}get dataset(){return this.targetElement?.dataset??{}}get bs(){return this.us}set bs(t){const i=!!t,s=this.view?.Wi?.();this.us!==i&&(this.us=i),s&&s.classList.toggle("highlight",i)}ws(t){this.ns.push(t)}ys(t){this.rs.push(t)}ai(t){this.ls.push(t)}Gi(){if(this.ds=e.J(this.textContent.toLowerCase()),!this.view)return;const t=this.view.view.tags.vs;t&&(this.options.allowHtml?t.innerHTML=this.text:t.textContent=this.textContent);const i=this.view.view.tags.xs;i&&this.hasImage&&(i.src=this.ps,i.alt=this.text),this.targetElement&&(this.gs=this.targetElement.selected)}}class w{constructor(t){this.Ts=[],this.Os=null,this.Ms=null,this.As=null,this.options=null,this.options=t}Cs(t){this.Ss=t}Hs(t){this.Ls=t}Ps(t){const i=this.Is(t),s=i!==this.As;return s&&(this.As=i),s}Is(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")}Es(t){this.Ts=[];let i=null;return t.forEach(t=>{if("OPTGROUP"===t.tagName)i=new m(this.options,t),this.Ts.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.es(e),e.group=i):(this.Ts.push(e),i=null)}}),this.Ts}replace(t){this.As=null,this.Es(t),this.Os&&this.Os.Fs(this.Ts),this.refresh(!1)}notify(){this.Os&&this.refresh(!1)}load(t,i={},s={}){this.Os=new this.Ss(this.Ts),Object.assign(this.Os,i),this.Ms=new this.Ls(t),Object.assign(this.Ms,s),this.Ms.js(this.Os)}update(t){if(!this.Ps(t))return;const i=this.Ts,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.es(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.es(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.Ts=s,this.Os&&this.Os.$s(this.Ts),this.onUpdated(),this.refresh(r)}onUpdated(){}ei(t){this.Os&&(this.Os.Vs=t)}refresh(t){this.Ms&&(this.Ms.refresh(t),this.onUpdated())}Xt(){return{ks:this.Ts,Zt:this.Os,kt:this.Ms}}_s(t){this.Os?.Rs(t)}Ds(t){this.Os?.Ns(t)}}class y{constructor(t=null){this.Bs=null,this.Zt=null,this.Bs=t}Us(t){this.Bs=t}js(t){this.Zt=t,t.di("items",()=>{this.clear()}),t.ci("items",()=>{this.zs()}),this.zs()}clear(){this.Bs&&this.Bs.replaceChildren()}zs(){this.Zt&&this.Bs&&this.Zt.Gs(this.Bs)}refresh(t){this.zs()}}class v{constructor(t=null){this.gt=null,this.node=null,this.options=null,this.Ws=null,this.qs=null,this.Js=null,t&&this.init(t)}init(t){this.gt=e.I({Ks:{tag:{node:"div",classList:["selective-ui-accessorybox","hide"],onmouseup:t=>{t.stopPropagation()}}}}),this.node=this.gt.view,this.options=t}Qs(t){this.Ws=t,this.qs=t.parentElement,this.Ys()}Ys(){this.qs&&this.node&&this.Ws&&this.options&&this.qs.insertBefore(this.node,"top"===this.options.accessoryStyle?this.Ws:this.Ws.nextSibling)}Xs(t){this.Js=t}Zs(t){this.node&&this.options&&(this.node.replaceChildren(),t.length>0&&this.options.multiple?(this.node.classList.remove("hide"),t.forEach(t=>{e.I({te:{tag:{node:"div",classList:["accessory-item"]},F:{ie:{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.Js?._s?.("select"),setTimeout(()=>{t.selected=!1},10)}}},se:{tag:{node:"span",classList:["accessory-item-content"],innerHTML:t.text}}}}},this.node)})):this.node.classList.add("hide"),h.ot(window,"resize"))}}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,Ci:!1,le:"",Ai:!1},this.ae=t,this.Gt=i,this.oe=s}ce(){return!!this.ee}async ue(t){if(!this.ee)return{Hi:!1,items:[],message:"Ajax not configured"};const i=Array.isArray(t)?t:[t];if(0===i.length)return{Hi:!0,items:[]};try{const t=this.ee;let s,e;if(s="function"==typeof t.de?t.de(i):{values:i.join(","),pe:"1",..."function"==typeof t.data?t.data.bind(this.oe.ge.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{Hi:!0,items:this.fe(h).items}}catch(s){return console.error("Load by values error:",s),{Hi:!1,message:s?.message,items:[]}}}me(t){const i=Array.from(this.ae.options).map(t=>t.value);return{be:t.filter(t=>i.includes(t)),we:t.filter(t=>!i.includes(t))}}ye(t){this.ee=t}setPopup(t){this.ne=t}Mi(){return{...this.re}}ve(){this.re={currentPage:0,totalPages:1,hasMore:!1,Ci:!1,le:"",Ai:this.re.Ai}}clear(){this.re.le="";const{ks:t}=this.Gt.Xt(),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.xe(t,i):this.Te(t)}async Si(){return this.ee?this.re.Ci?{Hi:!1,message:"Already loading"}:this.re.Ai?this.re.hasMore?(this.re.currentPage++,this.xe(this.re.le,!0)):{Hi:!1,message:"No more data"}:{Hi:!1,message:"Pagination not enabled"}:{Hi:!1,message:"Ajax not enabled"}}async Te(t){this.Oe(t)&&(this.re.le=t);const i=((t??"")+"").toLowerCase(),s=e.J(i),{ks:h}=this.Gt.Xt(),n=[];for(const e of h)e instanceof b?n.push(e):e instanceof m&&Array.isArray(e.items)&&n.push(...e.items);let o=!1;return n.forEach(t=>{const e=""===i||t.ds.includes(s);t.visible=e,e&&(o=!0)}),{Hi:!0,Me:o,isEmpty:0===n.length}}Oe(t){return t!==this.re.le}async xe(t,i=!1){const s=this.ee;this.Oe(t)&&(this.ve(),this.re.le=t,i=!1),this.re.Ci=!0,this.ne?.si(),this.he?.abort(),this.he=new AbortController;const e=this.re.currentPage,h=Array.from(this.ae.selectedOptions).map(t=>t.value).join(",");let n;"function"==typeof s.data?(n=s.data.bind(this.oe.ge.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.fe(e);return h.Ae?(this.re.Ai=!0,this.re.currentPage=h.page,this.re.totalPages=h.totalPages,this.re.hasMore=h.hasMore):this.re.Ai=!1,this.Ce(h.items,!!s.keepSelected,i),this.re.Ci=!1,this.ne?.ri(),{Hi:!0,Me:h.items.length>0,isEmpty:0===h.items.length,Ae:h.Ae,hasMore:h.hasMore,currentPage:h.page,totalPages:h.totalPages}}catch(o){return this.re.Ci=!1,this.ne?.ri(),"AbortError"===o?.name?{Hi:!1,message:"Request aborted"}:(console.error("Ajax search error:",o),{Hi:!1,message:o?.message})}}fe(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.Se||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.ae;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 T{constructor(t){this.He=null,this.Le=null,this.Pe=50,this.ae=t,this.Le=this.Ie(),this.Ee=new MutationObserver(()=>{this.He&&clearTimeout(this.He),this.He=setTimeout(()=>{this.Fe()},this.Pe)}),t.addEventListener("options:changed",()=>{this.He&&clearTimeout(this.He),this.He=setTimeout(()=>{this.Fe()},this.Pe)})}Ie(){const t=Array.from(this.ae.options);return{length:t.length,values:t.map(t=>t.value).join(","),je:t.map(t=>t.text).join(","),selected:t.map(t=>t.selected+"").join(",")}}$e(){const t=this.Ie(),i=JSON.stringify(t)!==JSON.stringify(this.Le);return i&&(this.Le=t),i}Fe(){this.$e()&&this.Ht(this.ae)}connect(){this.Ee.observe(this.ae,{childList:!0,subtree:!1,attributes:!0,attributeFilter:["selected","value","disabled"]})}Ht(t){}disconnect(){this.He&&clearTimeout(this.He),this.He=null,this.Ee.disconnect()}}class O{constructor(t){this.He=null,this.Ve=t,this.Ee=new MutationObserver(t=>{let i=!1;for(const s of t)if("attributes"===s.type&&s.attributeName?.startsWith("data-")){i=!0;break}i&&(this.He&&clearTimeout(this.He),this.He=setTimeout(()=>{this.Ht({...this.Ve.dataset})},50))}),t.addEventListener("dataset:changed",()=>{this.Ht({...this.Ve.dataset})})}connect(){this.Ee.observe(this.Ve,{attributes:!0,attributeOldValue:!0})}Ht(t){}disconnect(){this.He&&clearTimeout(this.He),this.He=null,this.Ee.disconnect()}}class M{constructor(t=[]){this.items=[],this.ke=e.m(12),this.Vs=!1,this.items=t,this._e()}_e(){}Re(t,i,s){const e=i;t.Ot?e?.update?.():e?.zs?.()}di(t,i){e.Z.on(`${t}ing_${this.ke}`,i,{st:1})}ci(t,i){e.Z.on(`${t}_${this.ke}`,i)}Ns(t,...i){e.Z.run(`${t}_${this.ke}`,...i)}Rs(t,...i){e.Z.run(`${t}ing_${this.ke}`,...i)}De(t,i){return null}Ne(){return this.items.length}Be(t){this.Rs("items",t),this.items=t,this.Ns("items",t)}Fs(t){this.Be(t)}Gs(t){for(let i=0;i<this.Ne();i++){const s=this.items[i];let e=s.view;s.Ot||(e=this.De(t,s),s.view=e),this.Re(s,e,i),s.Ot=!0}}$s(t){}}class A{constructor(t){this.parent=null,this.view=null,this.parent=t}zs(){}update(){}Wi(){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}zs(){const t=e.m(7);this.view=e.P({Ue:{tag:{node:"div",classList:["selective-ui-group"],role:"group",A:`seui-${t}-header`,id:`seui-${t}-group`},F:{ze:{tag:{node:"div",classList:["selective-ui-group-header"],role:"presentation",id:`seui-${t}-header`}},Ge:{tag:{node:"div",classList:["selective-ui-group-items"],role:"group"}}}}}),this.parent.appendChild(this.view.view)}update(){this.Xi()}Xi(t=null){this.view&&null!==t&&(this.view.tags.ze.textContent=t)}We(){if(!this.view)throw Error("GroupView is not rendered.");return this.view.tags.Ge}hs(){if(!this.view)return;const t=Array.from(this.view.tags.Ge.children).filter(t=>!t.classList.contains("hide"));this.view.view.classList.toggle("hide",!(t.length>0))}Zi(t){this.view&&(this.view.view.classList.toggle("collapsed",t),this.view.tags.ze.setAttribute("aria-expanded",t?"false":"true"))}}class S extends A{constructor(t){super(t),this.view=null,this.qe=null,this.Je=null,this.Ke=!1,this.Qe()}Qe(){const t=this;this.qe={isMultiple:!1,hasImage:!1,imagePosition:"right",imageWidth:"60px",imageHeight:"60px",imageBorderRadius:"4px",labelValign:"center",labelHalign:"left"},this.Je=new Proxy(this.qe,{set(i,s,e){if("string"!=typeof s)return!0;const h=s,n=i[h];return n!==e&&(i[h]=e,t.Ke&&t.Ye(h,e,n)),!0}})}get isMultiple(){return this.qe.isMultiple}set isMultiple(t){this.Je.isMultiple=!!t}get hasImage(){return this.qe.hasImage}set hasImage(t){this.Je.hasImage=!!t}get Xe(){return this.Je}set Xe(t){if(!t||!this.Je||!this.qe)return;const i={};void 0!==t.imageWidth&&t.imageWidth!==this.qe.imageWidth&&(i.imageWidth=t.imageWidth),void 0!==t.imageHeight&&t.imageHeight!==this.qe.imageHeight&&(i.imageHeight=t.imageHeight),void 0!==t.imageBorderRadius&&t.imageBorderRadius!==this.qe.imageBorderRadius&&(i.imageBorderRadius=t.imageBorderRadius),void 0!==t.imagePosition&&t.imagePosition!==this.qe.imagePosition&&(i.imagePosition=t.imagePosition),void 0!==t.labelValign&&t.labelValign!==this.qe.labelValign&&(i.labelValign=t.labelValign),void 0!==t.labelHalign&&t.labelHalign!==this.qe.labelHalign&&(i.labelHalign=t.labelHalign),Object.keys(i).length>0&&Object.assign(this.Je,i)}zs(){const t=["selective-ui-option-view"],i=e.m(7),s="option_"+i;this.qe.isMultiple&&t.push("multiple"),this.qe.hasImage&&(t.push("has-image"),t.push("image-"+this.qe.imagePosition));const h={fs:{tag:{node:"input",type:this.qe.isMultiple?"checkbox":"radio",classList:"allow-choice",id:s}},...this.qe.hasImage&&{xs:{tag:{node:"img",classList:"option-image",style:{width:this.qe.imageWidth,height:this.qe.imageHeight,borderRadius:this.qe.imageBorderRadius}}}},Ze:{tag:{node:"label",htmlFor:s,classList:["align-vertical-"+this.qe.labelValign,"align-horizontal-"+this.qe.labelHalign]},F:{vs:{tag:{node:"div"}}}}};this.view=e.P({th:{tag:{node:"div",id:`seui-${i}-option`,classList:t,role:"option",ariaSelected:"false",tabIndex:"-1"},F:h}}),this.parent.appendChild(this.view.view),this.Ke=!0}Ye(t,i,s){const e=this.view;if(!e||!e.view)return;const h=e.view,n=e.tags?.fs,o=e.tags?.Ze;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.qe.imagePosition),this.ih();else{h.className=h.className.replace(/image-(top|right|bottom|left)/g,"").trim();const t=e.tags?.xs;t&&(t.remove(),e.tags.xs=null)}break}case"imagePosition":this.qe.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?.xs;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.qe.labelValign} align-horizontal-${this.qe.labelHalign}`;o.className!==t&&(o.className=t)}}}ih(){const t=this.view;if(!t||!t.view)return;const i=t.tags?.xs;if(i)return;const s=t.view,e=t.tags?.Ze,h=document.createElement("img");h.className="option-image",h.style.width=this.qe.imageWidth,h.style.height=this.qe.imageHeight,h.style.borderRadius=this.qe.imageBorderRadius,e&&e.parentElement?s.insertBefore(h,e):s.appendChild(h),t.tags.xs=h}}class H extends M{constructor(t=[]){super(t),this.isMultiple=!1,this.sh=[],this.eh=-1,this.hh=null,this.groups=[],this.nh=[],this.oh(),e.Z.on("sche_vis_"+this.ke,()=>{const t=this.nh.filter(t=>t.visible).length,i=this.nh.length;this.sh.forEach(s=>{s({rh:t,ah:i,hi:t>0,isEmpty:0===i})}),e.Z.run("sche_vis_proxy_"+this.ke)},{st:10})}oh(){this.nh=[],this.groups=[],this.items.forEach(t=>{t instanceof m?(this.groups.push(t),this.nh.push(...t.items)):t instanceof b&&this.nh.push(t)})}De(t,i){return i instanceof m?new C(t):new S(t)}Re(t,i,s){t.position=s,t instanceof m?this.uh(t,i,s):t instanceof b&&this.dh(t,i,s),t.Ot=!0}uh(t,i,s){super.Re(t,i,s),t.view=i;const e=i.view.tags.ze;e.textContent=t.label,t.Ot||(e.style.cursor="pointer",e.addEventListener("click",()=>{t.ss()}),t.ts((t,i,s)=>{i.items.forEach(t=>{const i=t.view?.Wi?.();i&&(i.style.display=s?"none":"")}),this.ph(i,s)}));const h=i.We();t.items.forEach((t,i)=>{let s=t.view;t.Ot&&s||(s=new S(h)),this.dh(t,s,i),t.Ot=!0}),i.Zi(t.collapsed),i.hs()}dh(t,i,s){if(i.isMultiple=this.isMultiple,i.hasImage=t.hasImage,i.Xe={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.Re(t,i,s),t.view=i,t.hasImage){const s=i.view.tags.xs;s&&(s.src!==t.ps&&(s.src=t.ps),s.alt!==t.text&&(s.alt=t.text))}i.view.tags.vs.innerHTML=t.text,t.Ot||(i.view.tags.th.addEventListener("click",i=>{i.stopPropagation(),i.preventDefault(),this.Vs||(this.isMultiple?(this.Rs("select"),setTimeout(()=>{t.selected=!t.selected},5)):!0!==t.selected&&(this.Rs("select"),setTimeout(()=>{this.hh&&(this.hh.selected=!1),t.selected=!0},5)))}),i.view.tags.th.title=t.textContent,i.view.tags.th.addEventListener("mouseenter",()=>{this.Vs||this.gh(this.nh.indexOf(t),!1)}),t.ws(()=>{this.Ns("selected")}),t.ys((i,s,e)=>{e&&(this.hh=t),this.Ns("selected_internal")}),t.ai((t,i)=>{i.group?.hs(),this.fh()})),t.selected&&(this.hh=t,t.gs=!0)}Be(t){this.Rs("items",t),this.items=t,this.oh(),this.Ns("items",t)}Fs(t){this.Be(t)}$s(t){this.items=t,this.oh()}mh(){return this.nh.filter(t=>t.selected)}bh(){return this.nh.find(t=>t.selected)}ti(t){this.isMultiple&&this.nh.forEach(i=>{i.selected=t})}ai(t){this.sh.push(t)}fh(){e.Z.run("sche_vis_"+this.ke)}ni(){const t=this.nh.filter(t=>t.visible).length,i=this.nh.length;return{rh:t,ah:i,hi:t>0,isEmpty:0===i}}wh(){this.gh(0)}navigate(t,i=!0){const s=this.nh.filter(t=>t.visible);if(0===s.length)return;let e=s.findIndex(t=>t===this.nh[this.eh]);-1===e&&(e=-1);let h=e+t;h>=s.length&&(h=0),h<0&&(h=s.length-1);const n=this.nh.indexOf(s[h]);this.gh(n,i)}yh(){if(this.eh>-1&&this.nh[this.eh]){const t=this.nh[this.eh];if(t.visible){const i=t.view?.Wi?.();i&&i.click()}}}gh(t,i=!0){let s=0;if("number"==typeof t)s=t;else if(t instanceof b){const i=this.nh.indexOf(t);s=i>-1?i:0}else s=0;this.eh>-1&&this.nh[this.eh]&&(this.nh[this.eh].bs=!1);for(let e=s;e<this.nh.length;e++){const t=this.nh[e];if(t?.visible){if(t.bs=!0,this.eh=e,i){const i=t.view?.Wi?.();i?i.scrollIntoView({block:"center",behavior:"smooth"}):this.kt?.xh?.(e,{scrollIntoView:!0})}return void this.Th(e,t.view?.Wi?.()?.id)}}}Th(t,i){}ph(t,i){}}class L{constructor(t=0){this.Oh=[],this.n=0,this.reset(t)}reset(t){this.n=t,this.Oh=Array(t+1).fill(0)}add(t,i){for(let s=t;s<=this.n;s+=s&-s)this.Oh[s]+=i}Mh(t){let i=0;for(let s=t;s>0;s-=s&-s)i+=this.Oh[s];return i}Ah(t,i){return i<t?0:this.Mh(i)-this.Mh(t-1)}Ch(t){this.reset(t.length),t.forEach((t,i)=>this.add(i+1,t))}Sh(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.Oh[s]<=t&&(i=s,e+=this.Oh[s])}return i}}class P extends y{constructor(t=null){super(t),this.Hh={Yt:void 0,Bt:36,Ut:8,zt:!0,Lh:!0},this.Ph=[],this.Ih=new L(0),this.Eh=new Map,this.Fh=!1,this.start=0,this.end=-1,this.jh=null,this.$h=null,this.Vh=!1,this.kh=!1,this._h=0,this.Rh=!1,this.Dh=!1,this.Nh=0,this.Bh=0,this.Uh=0,this.zh=0}configure(t){this.Hh={...this.Hh,...t}}js(t){if(this.Zt&&this.dispose(),super.js(t),t.kt=this,!this.Bs)return;this.Bs.replaceChildren();const i=e.I({Gh:{tag:{node:"div",classList:"selective-ui-virtual-pad-top"}},Wh:{tag:{node:"div",classList:"selective-ui-virtual-items"}},qh:{tag:{node:"div",classList:"selective-ui-virtual-pad-bottom"}}},this.Bs);if(this.Gh=i.Gh,this.Wh=i.Wh,this.qh=i.qh,this.Yt=this.Hh.Yt??this.Bs.closest(".selective-ui-popup")??this.Bs.parentElement,!this.Yt)throw Error("VirtualRecyclerView: scrollEl not found");this.Jh=this.Kh.bind(this),this.Yt.addEventListener("scroll",this.Jh,{passive:!0}),this.refresh(!1),this.Qh(),t?.ai?.(()=>this.Yh())}suspend(){this.Rh=!0,this.Xh(),this.Yt&&this.Jh&&this.Yt.removeEventListener("scroll",this.Jh),this.Zh&&(this.Zh.disconnect(),this.Dh=!0)}resume(){this.Rh=!1,this.Yt&&this.Jh&&this.Yt.addEventListener("scroll",this.Jh,{passive:!0}),this.Dh&&(this.Qh(),this.Dh=!1),this.tn()}refresh(t){if(!this.Zt||!this.Bs)return;t||this.Yh();const i=this.Zt.Ne();this._h=i,0!==i?(this.Ph.length=i,this.Fh||(this.sn(),this.Fh=!0),this.en(i),this.tn()):this.hn()}xh(t,i){this.nn(t,t),i?.scrollIntoView&&this.rn(t)}rn(t){if((this.Zt?.Ne?.()??0)<=0)return;const i=this.ln(t),s=this.an()+i,e=Math.max(0,this.Yt.scrollHeight-this.Yt.clientHeight);this.Yt.scrollTop=Math.min(Math.max(0,s),e)}dispose(){this.Xh(),this.Yt&&this.Jh&&this.Yt.removeEventListener("scroll",this.Jh),this.Zh?.disconnect(),this.Eh.forEach(t=>t.remove()),this.Eh.clear()}Yh(){if(!this.Zt)return;const t=this.Zt.Ne();t<=0||(this.suspend(),this.hn(),this.cn(),this.un(t),this.en(t),this.start=0,this.end=-1,this.resume())}Xh(){null!=this.jh&&(cancelAnimationFrame(this.jh),this.jh=null),null!=this.$h&&(cancelAnimationFrame(this.$h),this.$h=null)}hn(){this.Eh.forEach(t=>t.remove()),this.Eh.clear(),this.Ph=[],this.Ih.reset(0),this.Gh.style.height="0px",this.qh.style.height="0px",this.Fh=!1,this.Uh=0,this.zh=0}sn(){this.dn(0);const t=this.Eh.get(0);if(!t)return;const i=this.pn(t);if(isNaN(i)||(this.Hh.Bt=i),!this.Hh.zt){t.remove(),this.Eh.delete(0);const i=this.Zt.items[0];i&&(i.Ot=!1,i.view=null)}}gn(t){const i=this.Zt?.items?.[t];return i?.visible??!0}fn(t,i){for(let s=Math.max(0,t);s<i;s++)if(this.gn(s))return s;return-1}un(t){this.Uh=0,this.zh=0;for(let i=0;i<t;i++){if(!this.gn(i))continue;const t=this.Ph[i];null!=t&&(this.Uh+=t,this.zh++)}}an(){const t=this.Bs.getBoundingClientRect(),i=this.Yt.getBoundingClientRect();return t.top-i.top+this.Yt.scrollTop}mn(){const t=performance.now();if(t-this.Nh<16)return this.Bh;const i=this.Yt.querySelector(".selective-ui-option-handle:not(.hide)");return this.Bh=i?.offsetHeight??0,this.Nh=t,this.Bh}tn(){null!=this.jh||this.Rh||(this.jh=requestAnimationFrame(()=>{this.jh=null,this.bn()}))}pn(t){const i=t.getBoundingClientRect(),s=getComputedStyle(t);return Math.max(1,i.height+(parseFloat(s.marginTop)||0)+(parseFloat(s.marginBottom)||0))}wn(){return this.Hh.Lh&&this.zh>0?Math.max(1,this.Uh/this.zh):this.Hh.Bt}en(t){const i=this.wn(),s=Array.from({length:t},(t,s)=>this.gn(s)?this.Ph[s]??i:0);this.Ih.Ch(s)}yn(t,i){if(!this.gn(t))return!1;const s=this.wn(),e=this.Ph[t]??s;if(Math.abs(i-e)<=P.vn)return!1;const h=this.Ph[t];return null==h?(this.Uh+=i,this.zh++):this.Uh+=i-h,this.Ph[t]=i,this.Ih.add(t+1,i-e),!0}xn(t,i){const s=this.Ih.Sh(Math.max(0,t)),e=Math.min(i-1,s),h=this.fn(e,i);return-1===h?Math.max(0,e):h}Tn(t,i){i.setAttribute(P.On,t+"");const s=this.Eh.get(t-1);if(s?.parentElement===this.Wh)return void s.after(i);const e=this.Eh.get(t+1);if(e?.parentElement===this.Wh)return void this.Wh.insertBefore(i,e);const h=Array.from(this.Wh.children);for(const n of h){const s=n.getAttribute(P.On);if(s&&+s>t)return void this.Wh.insertBefore(i,n)}this.Wh.appendChild(i)}Mn(t,i){if(i.parentElement!==this.Wh)return void this.Tn(t,i);i.setAttribute(P.On,t+"");const s=i.previousElementSibling,e=i.nextElementSibling;(s&&+s.getAttribute(P.On)>t||e&&+e.getAttribute(P.On)<t)&&(i.remove(),this.Tn(t,i))}Qh(){this.Zh||(this.Zh=new ResizeObserver(()=>{this.kh||this.Rh||!this.Zt||null!=this.$h||(this.$h=requestAnimationFrame(()=>{this.$h=null,this.An()}))}),this.Zh.observe(this.Wh))}An(){if(!this.Zt)return;const t=this.Zt.Ne();if(t<=0)return;let i=!1;for(let s=this.start;s<=this.end;s++){if(!this.gn(s))continue;const t=this.Zt.items[s],e=t?.view?.Wi?.();if(!e)continue;const h=this.pn(e);this.yn(s,h)&&(i=!0)}i&&(this.Hh.Lh&&this.en(t),this.tn())}Kh(){this.tn()}bn(){if(!this.Vh&&!this.Rh){this.Vh=!0;try{if(!this.Zt)return;const t=this.Zt.Ne();if(t<=0)return;this._h!==t&&(this._h=t,this.Ph.length=t,this.en(t));const i=this.an(),s=Math.max(0,this.Yt.scrollTop-i),e=this.mn(),h=Math.max(0,this.Yt.clientHeight-e),n=this.xn(s,t),o=i+this.ln(n)-this.Yt.scrollTop,r=this.xn(s,t);if(-1===r)return void this.hn();const l=this.wn(),a=this.Hh.Ut*l;let c=this.fn(Math.min(t-1,this.Ih.Sh(Math.max(0,s-a))),t)??r,u=Math.min(t-1,this.Ih.Sh(s+h+a));if(c===this.start&&u===this.end)return;this.start=c,this.end=u,this.kh=!0;try{this.nn(this.start,this.end),this.Cn(this.start,this.end),this.Hh.zt&&this.An();const i=this.ln(this.start),s=this.Sn(this.start,this.end),e=this.Hn(t),h=Math.max(0,e-i-s);this.Gh.style.height=i+"px",this.qh.style.height=h+"px"}finally{this.kh=!1}const d=this.ln(n),p=this.an()+d-o,g=Math.max(0,this.Yt.scrollHeight-this.Yt.clientHeight),f=Math.min(Math.max(0,p),g);Math.abs(this.Yt.scrollTop-f)>.5&&(this.Yt.scrollTop=f)}finally{this.Vh=!1}}}nn(t,i){for(let s=t;s<=i;s++)this.dn(s)}dn(t){if(!this.gn(t)){const i=this.Eh.get(t);return i?.parentElement===this.Wh&&i.remove(),void this.Eh.delete(t)}const i=this.Zt.items[t];if(!i)return;const s=this.Eh.get(t);if(s)return void(i?.view?(this.Mn(t,s),this.Zt.Re(i,i.view,t)):(s.remove(),this.Eh.delete(t)));if(i.Ot)i.view&&this.Zt.Re(i,i.view,t);else{const s=this.Zt.De(this.Wh,i);i.view=s,this.Zt.Re(i,s,t),i.Ot=!0}const e=i.view?.Wi?.();e&&(this.Mn(t,e),this.Eh.set(t,e))}Cn(t,i){this.Eh.forEach((s,e)=>{(e<t||e>i)&&(s.parentElement===this.Wh&&s.remove(),this.Eh.delete(e))})}cn(){this.Eh.forEach((t,i)=>{this.gn(i)||(t.parentElement===this.Wh&&t.remove(),this.Eh.delete(i))})}ln(t){return this.Ih.Mh(t)}Sn(t,i){return this.Ih.Ah(t+1,i+1)}Hn(t){return this.Ih.Mh(t)}}P.vn=.5,P.On="data-vindex";class I{constructor(t=null,i=null){this.container={},this.oldValue=null,this.node=null,this.options=null,this.Ln=null,this.isOpen=!1,this.Pn=!1,this.In=!1,this.ge=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?.Ti?.setAttribute("aria-disabled",t+""))}get En(){return!!this.options?.readonly}set En(t){this.options&&this.node&&(this.options.readonly=t,this.node.classList.toggle("readonly",t))}get isVisible(){return!!this.options?.visible}set isVisible(t){this.options&&this.node&&(this.options.visible=t,this.node.classList.toggle("invisible",!t))}init(t,s){const h=e._(t).options,l=new o(h),a=new r,c=new p(h),effector=i(),u=new w(h),g=new v(h),f=new x(t,u,this),m=new T(t),b=new O(t);this.ge=s,this.options=h,l.node&&(l.node.id=(h.Fn??"")+"");const M=e.I({jn:{tag:{node:"div",classList:"selective-ui-MAIN"},F:{Ti:{tag:{node:"div",classList:"selective-ui-view",tabIndex:0,onkeydown:t=>{"Enter"!==t.key&&" "!==t.key&&"ArrowDown"!==t.key||(t.preventDefault(),this.$n()?.open())}},F:{Vn:{tag:l.node},kn:{tag:a.node},ki:{tag:c.node}}}}}},null);this.container=M,this.node=M.view,t.parentNode?.insertBefore(this.node,t),this.node.insertBefore(t,M.tags.Ti),g.Qs(M.tags.Ti),g.Xs(u),M.tags.Ti.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()}),n.lt(t,M.tags.Ti),t.classList.add("init"),u.Cs(H),u.Hs(h.virtualScroll?P:y),u.Es(e.K(t)),u.onUpdated=()=>{M._n?.oi?.()},this.Ln=u,M.Rn=f,M.placeholder=l,M.Dn=a,M.Nn=c,M.effector=effector,M.targetElement=t,M.Bn=g,M.Un=m,M.zn=b,M._n=new d(t,h,u),M._n.gi(effector),M._n.Oi(f,h),M._n.pi("selected",()=>{this.$n()?.change(null,!0)}),M._n.pi("selected_internal",()=>{this.$n()?.change(null,!1)}),M._n.ui("select",()=>{this.oldValue=this.$n()?.value??""}),this.$n()?.change(null,!1),m.connect(),m.Ht=t=>{u.update(e.K(t)),this.$n()?.refreshMask()},b.connect(),b.Ht=t=>{e.V(t.disabled)!==this.isDisabled&&(this.isDisabled=e.V(t.disabled)),e.V(t.readonly)!==this.En&&(this.En=e.V(t.readonly)),e.V(t.visible)!==this.isVisible&&(this.isVisible=e.V(t.visible??"1"))},t.addEventListener("options:changed",()=>{u.update(e.K(t)),this.$n()?.refreshMask(),M._n?.oi?.()}),h.ajax&&f.ye(h.ajax);const A=M._n.Pt;let C=null;const S=(t,i)=>{i||""!==t?(""!==t&&(this.In=!0),f.search(t).then(t=>{clearTimeout(C),e.Z.on("sche_vis_proxy_"+A.ke,()=>{M._n?.oi?.(),t?.Me&&(C=setTimeout(()=>{A.wh(),M._n?.oi?.()},h.animationtime??0))},{st:10})}).catch(t=>{console.error("Search error:",t)})):f.clear()};let L=null;c.Fi=(t,i)=>{f.Oe(t)&&(L&&clearTimeout(L),f.ce()?(M._n?.si?.(),L=setTimeout(()=>{S(t,i)},h.delaysearchtime??0)):L=setTimeout(()=>{S(t,i)},10))},f.setPopup(M._n),c.ji=t=>{A.navigate(t)},c.$i=()=>{A.yh()},c.Vi=()=>{this.$n()?.close(),M.tags.Ti.focus()},A.Th=(t,i)=>{i&&c.Ri(i)},A.ph=()=>{M._n?.oi?.()},this.isDisabled=e.V(h.disabled),this.En=e.V(h.readonly)}Gn(){const t=this.container??{},{Un:i,zn:s}=t;i?.disconnect&&i.disconnect(),s?.disconnect&&s.disconnect()}$n(){const t=this.container,i=this,s=()=>this.ge.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.Nn?._i(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.Wn().forEach(i=>{i.selected&&t.push(i.value)}),t},get valueString(){return this.valueArray.join(o.customDelimiter)},get valueOptions(){const t=[];return i.Wn(!0).forEach(i=>{t.push(i)}),t},get mask(){const t=[];return i.Wn(!0).forEach(i=>{t.push(i.text)}),t},get valueText(){const t=[];i.Wn(!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.Wn(!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.Wn().length>o.maxSelected)&&!this.disabled&&!this.readonly&&o.multiple){if(e){if(h.nt([s()],...o.on.beforeChange).isCancel)return;i.oldValue=this.value}i.Wn().forEach(t=>{t.gs=!0}),this.change(!1,e)}},deSelectAll(t,e=!0){if(!this.disabled&&!this.readonly&&o.multiple){if(e){if(h.nt([s()],...o.on.beforeChange).isCancel)return;i.oldValue=this.value}i.Wn().forEach(t=>{t.gs=!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.Wn().forEach(t=>t.gs=!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.Rn?.ce?.()){const{we:s}=t.Rn.me(n);if(s.length>0)return void(async()=>{o.loadingfield&&t._n?.si?.();try{t.Rn.ve();const e=await t.Rn.ue(s);e.Hi&&e.items.length>0?(e.items.forEach(t=>{s.includes(t.value)&&(t.selected=!0)}),t.Rn.Ce?.(e.items,!0,!0),setTimeout(()=>{i.Wn().forEach(t=>{t.gs=n.some(i=>i==t.value)}),this.change(!1,!1)},100)):s.length>0&&console.warn(`Could not load ${s.length} values:`,s)}catch(e){console.error("Error loading missing values:",e)}finally{o.loadingfield&&t._n?.ri?.()}})()}if(r){if(h.nt([s()],...o.on.beforeChange).isCancel)return;i.oldValue=this.value}i.Wn().forEach(t=>{t.gs=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.ge?.find?.();if(e&&!e.isEmpty&&e.close().isCancel)return;if(this.disabled)return;if(h.nt([s()],...o.on.beforeShow).isCancel)return;i.isOpen=!0,t.Dn.dt(!0);const n=t._n.Pt,r=n.bh();r?n.gh(r,!1):n.wh(),i.Pn&&!i.In||!o?.ajax?t._n.open(null,!0):(t.Rn.ve(),t._n.si(),i.Pn=!0,i.In=!1,setTimeout(()=>{t._n&&t.Rn&&t.Rn.search("").then(()=>t._n?.oi?.()).catch(t=>console.error("Initial ajax load error:",t))},o.animationtime),t._n.open(null,!1)),t.Nn.show();const l=t.tags.Ti;l.setAttribute("aria-expanded","true"),l.setAttribute("aria-controls",o.Jt),l.setAttribute("aria-haspopup","listbox"),l.setAttribute("aria-labelledby",o.Fn),o.multiple&&l.setAttribute("aria-multiselectable","true"),h.nt([s()],...o.on.show)},close(){i.isOpen&&(h.nt([s()],...o.on.beforeClose).isCancel||(i.isOpen=!1,t.Dn.dt(!1),t._n.close(()=>{t.Nn.clear(!1)}),t.Nn.hide(),t.tags.Ti.setAttribute("aria-expanded","false"),h.nt([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.nt([s(),this.value],...o.on.beforeChange).isCancel)return void this.setValue(null,this.oldValue,!1)}this.refreshMask(),t.Bn.Zs(this.valueOptions),n&&(t.targetElement&&h.ot(t.targetElement,"change"),h.nt([s(),this.value],...o.on.change),i.options?.autoclose&&this.close())},refreshMask(){let s=o.placeholder;!o.multiple&&i.Wn().length>0&&(s=this.mask[0]),s??(s=o.placeholder),t.placeholder.set(s,!1),t.Nn._i(s)},on(t,i,s){o.on[i]||(o.on[i]=[]),o.on[i].push(s)},ajax(i,s){t.Rn.ye(s)},loadAjax:()=>new Promise((e,h)=>{t._n.si(),t.Rn.ve(),i.Pn=!0,i.In=!1,t._n&&t.Rn?t.Rn.search("").then(()=>{t._n?.oi?.(),e(s())}).catch(t=>{console.error("Initial ajax load error:",t),h(t)}):e(s())})};return this.qn(r,"disabled","isDisabled"),this.qn(r,"readonly","isReadOnly"),this.qn(r,"visible","isVisible"),r}qn(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})}Wn(t=null){if(!this.Ln)return[];const{ks:i}=this.Ln.Xt(),s=[];for(const e of i)e instanceof b?s.push(e):e instanceof m&&Array.isArray(e.items)&&e.items.length&&s.push(...e.items);return"boolean"==typeof t?s.filter(i=>i.selected===t):s}Li(){this.container._n.Li()}}class E{constructor(){this.Jn=!1,this.Ee=null,this.Kn=[]}Qn(t){this.Kn.push(t)}Yn(){this.Kn=[]}start(t){if(this.Jn)return;this.Jn=!0;const i=t.toUpperCase(),s=t.toLowerCase();this.Ee=new MutationObserver(t=>{for(const e of t)e.addedNodes.forEach(t=>{if(1!==t.nodeType)return;const e=t;e.tagName===i&&this.Xn(e),e.querySelectorAll(s).forEach(t=>this.Xn(t))})}),this.Ee.observe(document.body,{childList:!0,subtree:!0})}stop(){this.Jn&&(this.Jn=!1,this.Ee?.disconnect(),this.Ee=null)}Xn(t){this.Kn.forEach(i=>i(t))}}class F{constructor(){this.Zn=new Map}bind(t,i){const s=e.$(e.U(),i);s.on=s.on??{},s.on.load=s.on.load??[],this.Zn.set(t,s);const n=e.m();e.Z.on(n,()=>{h.nt([this.find(t)],...s.on.load),e.Z.clear(n),s.on.load=[]}),e.v(t).forEach(t=>{(async()=>{"SELECT"===t.tagName&&(e.D(t),this.io(t,s)&&e.Z.run(n))})()}),e.G().includes(t)||e.G().push(t)}find(t="*"){const i={isEmpty:!0};if("*"===t&&""===(t=e.G().join(", ")))return i;const s=e.v(t);if(0===s.length)return i;const h=e._(s[0]);if(!h||!h.action)return i;const n={};for(const e in h.action)n[e]=this.so(e,h.action);const o={isEmpty:!1};for(const e in n){const t=n[e];switch(t.type){case"get-set":this.eo(o,t.name,s);break;case"func":this.ho(o,t.name,s)}}return o}no(){this.oo=new E,this.oo.Qn(t=>{this.Zn.forEach((i,s)=>{try{t.matches(s)&&this.io(t,i)}catch(e){console.warn("Invalid selector: "+s,e)}})}),this.oo.start("select")}destroy(t=null){null===t?this.ro():"string"==typeof t?this.lo(t):t instanceof HTMLSelectElement&&this.ao(t)}ro(){e.G().forEach(t=>this.lo(t)),this.Zn.clear(),e.G().length=0,this.oo?.stop()}lo(t){e.v(t).forEach(t=>{"SELECT"===t.tagName&&this.ao(t)}),this.Zn.delete(t);const i=e.G(),s=i.indexOf(t);s>-1&&i.splice(s,1)}ao(t){const i=e._(t);if(!i)return;const s=i.container?._n;s?.Li(),e.B(t,i);const h=!!this.oo;h&&this.oo?.stop();try{i.self?.Gn?.()}catch(o){}const n=i.container?.element??t.parentElement;t.style.display="",t.style.visibility="",t.disabled=!1,delete t.dataset.co,n&&n.parentNode?n.parentNode.replaceChild(t,n):document.body.appendChild(t),e.k(t),h&&this.Zn.size>0&&this.oo?.start("select")}rebind(t,i){this.lo(t),this.bind(t,i)}io(t,i){if(e._(t)||e.N(t))return!1;const s=e.m(8),h=e.j(t,i);h.uo=s,h.Jt=`seui-${s}-optionlist`,h.Fn=`seui-${s}-placeholder`;const n={options:h};e.R(t,n);const o=new I(t,this);return n.container=o.container,n.action=o.$n(),n.self=o,o.container.view.addEventListener("mouseup",()=>{n.action?.toggle?.()}),!0}so(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}}eo(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})}ho(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.ht();if(o??(o=r.action[i](l.et,...n)),!l.token.isContinue)break}return o??t}}}if(void 0===globalThis.GLOBAL_SEUI){const $=new F;globalThis.GLOBAL_SEUI={version:"1.2.1",name:"SelectiveUI",bind:$.bind.bind($),find:$.find.bind($),destroy:$.destroy.bind($),effector:i.bind(i),rebind:$.rebind.bind($)};let V=!1;function k(){V||(V=!0,document.addEventListener("mousedown",()=>{const t=e.G();if(t.length>0){const i=$.find(t.join(", "));i.isEmpty||i.close()}}),$.no())}"undefined"!=typeof document&&("loading"===document.readyState?document.addEventListener("DOMContentLoaded",k):k()),console.log("[SelectiveUI] v1.2.1 loaded successfully")}else console.warn(`[${globalThis.GLOBAL_SEUI.name}] Already loaded (v${globalThis.GLOBAL_SEUI.version}). Using existing instance. Please remove duplicate <script> tags.`);const version=globalThis.GLOBAL_SEUI.version,j=globalThis.GLOBAL_SEUI.name;t.bind=(t,i={})=>{globalThis.GLOBAL_SEUI.bind(t,i)},t.destroy=(t=null)=>{globalThis.GLOBAL_SEUI.destroy(t)},t.effector=t=>globalThis.GLOBAL_SEUI.effector(t),t.find=t=>globalThis.GLOBAL_SEUI.find(t),t.name=j,t.rebind=(t,i={})=>{globalThis.GLOBAL_SEUI.rebind(t,i)},t.version=version},"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).SelectiveUI={});
1
+ /*! Selective UI v1.2.2 | MIT License */
2
+ var t,i;t=this,i=function(t){"use strict";function i(t){return new g(t??null)}class s{constructor(){this.t={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.i=new Map,this.h=new Map,this.o=[]}}class e{static get l(){return this.u||(this.u=new s),this.u}static p(t){if(null===t||"object"!=typeof t)return t;const i=Array.isArray(t)?[]:{};for(const s in t)Object.prototype.hasOwnProperty.call(t,s)&&(i[s]=this.p(t[s]));return i}static m(t=6){let i="";for(let s=0;s<t;s++)i+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random()));return i}static v(t){if(!t)return[];if("string"==typeof t){const i=document.querySelectorAll(t);return Array.from(i)}return t instanceof Element?[t]:t instanceof NodeList||Array.isArray(t)?Array.from(t):[]}static T(t={}){return this.O(document.createElement(t.node??"div"),t,!0)}static O(t=document.documentElement,i=null,s=!1){const e={...i??{}},h=s?t:this.M(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.A&&(h.setAttribute("aria-labelledby",e.A+""),delete e.A),e.C&&(h.setAttribute("aria-controls",e.C+""),delete e.C),e.S&&(h.setAttribute("aria-haspopup",e.S+""),delete e.S),e.H&&(h.setAttribute("aria-multiselectable",e.H+""),delete e.H),e.L&&(h.setAttribute("aria-autocomplete",e.L+""),delete e.L),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 M(t){if(t instanceof Element)return t;throw new TypeError("Node is not an Element")}static P(t){return this.I(t)}static I(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?.F&&this.I(r.F,l,!1,!1,h),i?s?i.prepend(l):i.append(l):e||n||(n=l)}return e||(h.id=this.m(7),i||(h={tags:h,view:n})),h}static j(t,i){const s=this.p(i);for(const e in s){const i=t[e];i?s[e]="boolean"==typeof s[e]?this.$(i):i:void 0!==t?.dataset?.[e]&&(s[e]="boolean"==typeof s[e]?this.$(t.dataset[e]):t.dataset[e])}return s}static V(...t){if(0===t.length)return{};if(1===t.length)return this.p(t[0]);const i=this.p(t[0]);for(let s=1;s<t.length;s++){const e=t[s];for(const t in e)if("on"===t){const s=e[t];for(const e in s)i[t][e].push(s[e])}else i[t]=e[t]}return i}static $(t){if("boolean"==typeof t)return t;if("string"!=typeof t)return!!t;switch(t.trim().toLowerCase()){case"true":case"1":case"yes":case"on":return!0;default:return!1}}static k(t){return this.l.i.delete(t)}static R(t){return this.l.i.get(t)}static D(t,i){this.l.i.set(t,i)}static _(t){return this.l.h.delete(t)}static N(t){return this.l.h.get(t)}static B(t,i){this.l.h.set(t,i)}static U(){return this.l.t}static G(){return this.l.o}static W(t){if(null==t)return"";let i=(t+"").replace(/<`/g,"<").replace(/`>/g,">").replace(/\<\`/g,"<").replace(/\`\>/g,">").trim();const s=globalThis?.document;if(!s||"function"!=typeof s.createElement)return i=i.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"").replace(/<iframe\b[^>]*>[\s\S]*?<\/iframe>/gi,"").replace(/<(object|embed|link)\b[^>]*>[\s\S]*?<\/\1>/gi,""),i=i.replace(/\son[a-z]+\s*=\s*(['"]).*?\1/gi,""),i=i.replace(/\s([a-z-:]+)\s*=\s*(['"])\s*javascript:[^'"]*\2/gi,""),i;const e=s.createElement("div");return e.innerHTML=i,e.querySelectorAll("script, style, iframe, object, embed, link").forEach(t=>t.remove()),e.querySelectorAll("*").forEach(t=>{for(const i in t.attributes){const s=t.attributes[i],e=s.name??"",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 q(t){const i=document.createElement("DIV");i.innerHTML=t;const s=i.textContent??i.innerText??"";return i.remove(),s.trim()}static J(t){return null==t?"":(t+"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/đ/g,"d").replace(/Đ/g,"d")}static K(t){const i=[];return Array.from(t.children).forEach(t=>{if("OPTGROUP"===t.tagName){const s=t;i.push(s),Array.from(s.children).forEach(t=>{t.__parentGroup=s,i.push(t)})}else"OPTION"===t.tagName&&i.push(t)}),i}static Y(){const t=navigator.userAgent;return/iP(hone|ad|od)/.test(t)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1}static X(t){const i=(t+"").trim();if(i.endsWith("px"))return i;if(i.endsWith("vh"))return window.innerHeight*parseFloat(i)/100+"px";if(i.endsWith("vw"))return window.innerWidth*parseFloat(i)/100+"px";const s=parseFloat(getComputedStyle(document.documentElement).fontSize);if(i.endsWith("rem"))return s*parseFloat(i)+"px";const e=this.T({node:"div",style:{height:i,opacity:"0"}});document.body.appendChild(e);const h=e.offsetHeight+"px";return e.remove(),h}}e.u=null,e.Z=new class{constructor(){this.tt=new Map,this.it=new Map}on(t,i,s={}){const e=s.st??50,h=s.once??!1;this.tt.has(t)||this.tt.set(t,[]),this.tt.get(t).push({et:i,timeout:e,once:h})}off(t){const i=this.it.get(t);if(i){for(const t of i.values())clearTimeout(t);i.clear(),this.it.delete(t)}this.tt.delete(t)}run(t,...i){const s=this.tt.get(t);if(!s)return;this.it.has(t)||this.it.set(t,new Map);const e=this.it.get(t);for(let h=0;h<s.length;h++){const t=s[h];if(!t)continue;const n=e.get(h);n&&clearTimeout(n);const o=setTimeout(()=>{if(t.et(i.length>0?i:null),t.once){s[h]=void 0;const t=e.get(h);t&&clearTimeout(t),e.delete(h)}},t.timeout);e.set(h,o)}}clear(t){if(void 0===t)for(const i of Array.from(this.tt.keys()))this.off(i);else this.off(t)}};class h{static ht(){const t={isContinue:!0,isCancel:!1};return{token:{get isContinue(){return t.isContinue},get isCancel(){return t.isCancel}},et:{stopPropagation(){t.isContinue=!1},cancel(){t.isCancel=!0,t.isContinue=!1}}}}static nt(t,...i){const{token:s,et:e}=this.ht();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 ot(t,i,s={bubbles:!0,cancelable:!0}){const e=new Event(i,s);return t.dispatchEvent(e),e}static rt(t,...i){if(Array.isArray(t))for(const s of t)"function"==typeof s&&s(...i)}}class n{static lt(t,i){const s=e.R(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.W(t);this.node.innerHTML=this.options.allowHtml?s:e.q(s)}}class r{constructor(){this.node=this.init()}init(){return e.T({node:"div",classList:"selective-ui-directive",role:"button",ariaLabel:"Toggle dropdown"})}ct(t){this.node.classList.toggle("drop-down",!!t)}}class l{constructor(t=null){this.ut=null,this.node=null,this.options=null,this.dt=[],this.gt=[],t&&this.init(t)}init(t){this.ut=e.I({ft:{tag:{node:"div",classList:["selective-ui-option-handle","hide"]},F:{bt:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textSelectAll,onclick:()=>{h.rt(this.dt)}}},wt:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textDeselectAll,onclick:()=>{h.rt(this.gt)}}}}}}),this.node=this.ut.view,this.options=t}available(){return!!this.options&&e.$(this.options.multiple)&&e.$(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")}yt(t=null){"function"==typeof t&&this.dt.push(t)}vt(t=null){"function"==typeof t&&this.gt.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.xt=!1,this.element=null,this.Tt=null,this.Ot=null,this.xt=!0,this.Mt=this.At.bind(this)}Ct(t){}At(){const t=this.element;if(!t||"function"!=typeof t.getBoundingClientRect)return void this.Ct({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.Ct({width:i?.width??0,height:i?.height??0,top:i?.top??0,left:i?.left??0,padding:{top:parseFloat(s?.paddingTop??"0"),right:parseFloat(s?.paddingRight??"0"),bottom:parseFloat(s?.paddingBottom??"0"),left:parseFloat(s?.paddingLeft??"0")},border:{top:parseFloat(s?.borderTopWidth??"0"),right:parseFloat(s?.borderRightWidth??"0"),bottom:parseFloat(s?.borderBottomWidth??"0"),left:parseFloat(s?.borderLeftWidth??"0")},margin:{top:parseFloat(s?.marginTop??"0"),right:parseFloat(s?.marginRight??"0"),bottom:parseFloat(s?.marginBottom??"0"),left:parseFloat(s?.marginLeft??"0")}})}ot(){this.At()}connect(t){if(!(t instanceof Element))throw Error("Invalid element");this.element=t,this.Tt=new ResizeObserver(this.Mt),this.Tt.observe(t),this.Ot=new MutationObserver(this.Mt),this.Ot.observe(t,{attributes:!0,attributeFilter:["style","class"]}),window.addEventListener("scroll",this.Mt,!0),window.addEventListener("resize",this.Mt),window.visualViewport&&(window.visualViewport.addEventListener("resize",this.Mt),window.visualViewport.addEventListener("scroll",this.Mt))}disconnect(){this.Tt?.disconnect(),this.Ot?.disconnect(),this.Ct=()=>{},window.removeEventListener("scroll",this.Mt,!0),window.removeEventListener("resize",this.Mt),window.visualViewport&&(window.visualViewport.removeEventListener("resize",this.Mt),window.visualViewport.removeEventListener("scroll",this.Mt)),this.Tt=null,this.Ot=null,this.element=null}}class d{constructor(t=null,i=null,s=null){this.options=null,this.St=!1,this.Ht=null,this.node=null,this.Lt=null,this.Pt=null,this.parent=null,this.It=null,this.Et=null,this.Ft=null,this.jt=null,this.$t=null,this.Vt=null,this.kt=null,this.Rt={Dt:36,_t:8,Nt:!0},this.Bt=s,t&&i&&this.init(t,i)}init(t,i){if(!this.Bt)throw Error("Popup requires a ModelManager instance.");this.It=new l(i),this.Et=new a(i),this.Ft=new c(i);const s=e.I({Ut:{tag:{node:"div",classList:"selective-ui-popup",style:{maxHeight:i.panelHeight}},F:{ft:{tag:this.It.node},zt:{tag:{id:i.Gt,node:"div",classList:"selective-ui-options-container",role:"listbox"}},Wt:{tag:this.Ft.node},qt:{tag:this.Et.node}}}},null);this.node=s.view,this.$t=s.tags.zt,this.parent=e.R(t),this.options=i,this.Bt.load(this.$t,{isMultiple:i.multiple},i.virtualScroll?{Jt:this.node,Dt:this.Rt.Dt,_t:this.Rt._t,Nt:this.Rt.Nt}:{});const h=this.Bt.Kt();this.Ht=h.Qt,this.jt=h.jt,this.It.yt(()=>{h.Qt.Yt(!0)}),this.It.vt(()=>{h.Qt.Yt(!1)}),this.Xt()}async Zt(){this.options&&this.Ft&&this.It&&this.Ht&&this.Bt&&(this.kt&&clearTimeout(this.kt),this.Bt.ti(!0),!1!==e.$(this.options.loadingfield)&&(this.Et.hide(),this.Ft.show(this.Ht.si().ii),this.ei()))}async hi(){this.options&&this.Ft&&this.Ht&&this.Bt&&(this.kt&&clearTimeout(this.kt),this.kt=setTimeout(()=>{this.Bt?.ti(!1),this.Ft?.hide();const t=this.Ht?.si();this.ni(t??void 0),this.ei()},200))}Xt(){this.Ht&&(this.Ht.oi(t=>{this.ni(t)}),this.Ht.ri("items",()=>{const t=this.Ht.si();this.ni(t),this.ei()}))}ni(t){if(!(this.Ht&&this.Et&&this.It&&this.$t))return;const i=t??this.Ht.si();i.isEmpty?(this.Et.show("nodata"),this.$t.classList.add("hide"),this.It.hide()):i.ii?(this.Et.hide(),this.$t.classList.remove("hide"),this.It.refresh()):(this.Et.show("notfound"),this.$t.classList.add("hide"),this.It.hide())}li(t,i){this.Ht?.ai(t,i)}ci(t,i){this.Ht?.ri(t,i)}ui(t){this.Lt=t}open(t=null,i){if(!(this.node&&this.options&&this.It&&this.parent&&this.Lt))return;this.St||(document.body.appendChild(this.node),this.St=!0,this.Pt=new u,this.Lt.di(this.node),this.node.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()})),this.It.refresh(),i&&this.ni();const s=this.pi(),{position:e,top:h,maxHeight:n,gi:o}=this.fi(s);this.Lt.expand({duration:this.options.animationtime,display:"flex",width:s.width,left:s.left,top:h,maxHeight:n,gi:o,position:e,mi:()=>{if(!this.Pt||!this.parent)return;this.Pt.Ct=()=>{const t=this.pi();this.bi(t)},this.Pt.connect(this.parent.container.tags.wi),t?.();const i=this.jt;i?.resume?.()}})}close(t=null){if(!(this.St&&this.options&&this.Pt&&this.Lt))return;const i=this.jt;i?.suspend?.(),this.Pt.disconnect(),this.Lt.collapse({duration:this.options.animationtime,mi:t??void 0})}ei(){this.St&&this.Pt?.ot()}yi(t,i){this.node&&(this.Vt=async()=>{const i=t.xi();if(!i.Ti)return;const s=this.node;if(s.scrollHeight-s.scrollTop-s.clientHeight<100&&!i.Oi&&i.hasMore){const i=await t.Mi();!i.Ai&&i.message&&console.log("Load more:",i.message)}},this.node.addEventListener("scroll",this.Vt))}Ci(){this.kt&&(clearTimeout(this.kt),this.kt=null),this.node&&this.Vt&&(this.node.removeEventListener("scroll",this.Vt),this.Vt=null);try{this.Pt?.disconnect()}catch(t){}this.Pt=null;try{this.Lt?.di?.(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.$t=null;try{this.Bt?.ti?.(!1),this.jt?.clear?.(),this.jt=null,this.Ht=null,this.node.remove()}catch(t){}this.Bt=null,this.It=null,this.Et=null,this.Ft=null,this.parent=null,this.options=null,this.St=!1}pi(){const t=this.parent.container.tags.wi,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)}}}fi(t){const i=window.visualViewport,s=e.Y(),h=i?.height??window.innerHeight,n=this.Lt.Si("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,gi:d,Hi:n}}bi(t){if(!this.options||!this.Lt)return;const{position:i,top:s,maxHeight:e,gi:h}=this.fi(t);this.Lt.resize({duration:this.options.animationtime,width:t.width,left:t.left,top:s,maxHeight:e,gi:h,position:i,animate:!0})}}class p{constructor(t=null){this.ut=null,this.node=null,this.Li=null,this.Pi=null,this.options=null,this.Ii=null,this.Ei=null,this.Fi=null,this.options=t,t&&this.init(t)}init(t){this.ut=e.I({ji:{tag:{node:"div",classList:["selective-ui-searchbox","hide"]},F:{Li:{tag:{id:e.m(),node:"input",type:"search",classList:["selective-ui-searchbox-input"],placeholder:t.placeholder,role:"searchbox",C:t.Gt,L:"list"}}}}}),this.node=this.ut.view,this.Li=this.ut.tags.Li;let i=!1;const s=this.ut.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.Ii?.(1)):"ArrowUp"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.Ii?.(-1)):"Enter"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.Ei?.()):"Escape"===t.key&&(t.preventDefault(),t.stopPropagation(),i=!0,this.Fi?.()),t.stopPropagation()}),s.addEventListener("input",()=>{i||this.Pi?.(s.value,!0)})}show(){this.node&&this.Li&&this.options&&(this.node.classList.remove("hide"),this.Li.readOnly=!this.options.searchable,this.options.searchable&&requestAnimationFrame(()=>{this.Li?.focus()}))}hide(){this.node&&this.node.classList.add("hide")}clear(t=!0){this.ut&&(this.ut.tags.Li.value="",this.Pi?.("",t))}$i(t){this.Li&&(this.Li.placeholder=e.q(t))}Vi(t){this.Li&&this.Li.setAttribute("aria-activedescendant",t)}}class g{constructor(t=null){this.ki=null,this.Ri=null,this.Di=!1,t&&this.di(t)}di(t){if("string"==typeof t){const i=document.querySelector(t);return void(i instanceof HTMLElement&&(this.element=i))}this.element=t}cancel(){return this.ki&&(clearTimeout(this.ki),this.ki=null),this.Ri&&(clearTimeout(this.Ri),this.Ri=null),this.Di=!1,this}Si(t="flex"){if(!this.element)return{width:0,height:0,scrollHeight:0};const i={display:this.element.style.display,visibility:this.element.style.visibility,position:this.element.style.position,height:this.element.style.height,width:this.element.style.width};Object.assign(this.element.style,{display:t,visibility:"hidden",position:"fixed",height:"fit-content",width:"fit-content"});const s=window.getComputedStyle(this.element),e=parseFloat(s.borderTopWidth),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.Di=!0;const{duration:i=200,display:s="flex",width:e,left:h,top:n,maxHeight:o,gi:r,position:l="bottom",mi: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.ki=setTimeout(()=>{this.element.style.transition="none",this.Di=!1,a?.()},i)}),this}collapse(t){if(!this.element)return this;this.cancel(),this.Di=!0;const{duration:i=200,mi: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.ki=setTimeout(()=>{Object.assign(this.element.style,{display:"none",transition:"none"}),this.Di=!1,s?.()},i)}),this}showSwipeWidth(t){if(!this.element)return this;this.cancel(),this.Di=!0;const{duration:i=200,display:s="block",mi:e}=t;Object.assign(this.element.style,{transition:"none",display:s,width:"fit-content"});const h=this.Si(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.ki=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:""}),this.Di=!1,e?.()},i),this}hideSwipeWidth(t){if(!this.element)return this;this.cancel(),this.Di=!0;const{duration:i=200,mi:s}=t,e=this.Si().width;return Object.assign(this.element.style,{transition:"none",width:e+"px"}),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`width ${i}ms`,width:"0px",overflow:"hidden"})}),this.ki=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:"",display:""}),this.Di=!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,gi:o,position:r="bottom",animate:l=!0,mi: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.Ri=setTimeout(()=>{this.element?.style&&(this.element.style.transition=null)},i),Object.assign(this.element.style,t),l&&(c||r>1)?this.Ri=setTimeout(()=>{this.element.style.transition=null,c&&delete this.element.style.transition,a?.()},i):(c&&delete this.element.style.transition,a?.())},20),this}get _i(){return this.Di}}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.xt=!1,this.Ni=!1,this.options=t,this.targetElement=i,this.view=s}update(t){this.targetElement=t,this.Bi()}remove(){this.targetElement=null,this.view?.Ui()?.remove?.(),this.view=null,this.Ni=!0,this.zi()}Bi(){}zi(){}}class m extends f{constructor(t,i){super(t,i??null,null),this.label="",this.items=[],this.collapsed=!1,this.Gi=[],i&&(this.label=i.label,this.collapsed=e.$(i.dataset?.collapsed))}get value(){return this.items.map(t=>t.value)}get Wi(){return this.items.filter(t=>t.selected)}get qi(){return this.items.filter(t=>t.visible)}get Ji(){return this.qi.length>0}update(t){this.label=t.label,this.view?.Ki(this.label)}Bi(){this.view&&(this.view.Ki(this.label),this.view.Qi(this.collapsed))}Yi(t){this.Gi.push(t)}Xi(){this.collapsed=!this.collapsed,this.view?.Qi(this.collapsed),h.nt([this,this.collapsed],...this.Gi)}Zi(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)}ts(){this.view?.ts()}}class b extends f{constructor(t,i=null,s=null){super(t,i,s),this.ss=[],this.es=[],this.hs=[],this.ns=!0,this.rs=!1,this.group=null,(async()=>{this.ls=e.J(this.textContent.toLowerCase())})()}get cs(){return this.dataset?.imgsrc||this.dataset?.image||""}get hasImage(){return!!this.cs}get value(){return this.targetElement?.value??""}get selected(){return!!this.targetElement?.selected}set selected(t){this.us=t,h.nt([this,t],...this.ss)}get visible(){return this.ns}set visible(t){if(this.ns===t)return;this.ns=t;const i=this.view?.Ui?.();i&&i.classList.toggle("hide",!t),h.nt([this,t],...this.hs)}get us(){return this.selected}set us(t){const i=this.view?.view?.tags?.ds,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.nt([this,t],...this.es)}get text(){const t=e.W(this.dataset?.mask??this.targetElement?.text??"");return this.options.allowHtml?t:e.q(t)}get textContent(){return this.options.allowHtml?e.q(this.text).trim():this.text.trim()}get dataset(){return this.targetElement?.dataset??{}}get ps(){return this.rs}set ps(t){const i=!!t,s=this.view?.Ui?.();this.rs!==i&&(this.rs=i),s&&s.classList.toggle("highlight",i)}gs(t){this.ss.push(t)}fs(t){this.es.push(t)}oi(t){this.hs.push(t)}Bi(){if(this.ls=e.J(this.textContent.toLowerCase()),!this.view)return;const t=this.view.view.tags.bs;t&&(this.options.allowHtml?t.innerHTML=this.text:t.textContent=this.textContent);const i=this.view.view.tags.ws;i&&this.hasImage&&(i.src=this.cs,i.alt=this.text),this.targetElement&&(this.us=this.targetElement.selected)}}class w{constructor(t){this.ys=[],this.vs=null,this.xs=null,this.Ts=null,this.options=null,this.options=t}Os(t){this.Ms=t}As(t){this.Cs=t}Ss(t){const i=this.Hs(t),s=i!==this.Ts;return s&&(this.Ts=i),s}Hs(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")}Ls(t){this.ys=[];let i=null;return t.forEach(t=>{if("OPTGROUP"===t.tagName)i=new m(this.options,t),this.ys.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.Zi(e),e.group=i):(this.ys.push(e),i=null)}}),this.ys}replace(t){this.Ts=null,this.Ls(t),this.vs&&this.vs.Ps(this.ys),this.refresh(!1)}notify(){this.vs&&this.refresh(!1)}load(t,i={},s={}){this.vs=new this.Ms(this.ys),Object.assign(this.vs,i),this.xs=new this.Cs(t),Object.assign(this.xs,s),this.xs.Is(this.vs)}update(t){if(!this.Ss(t))return;const i=this.ys,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.Zi(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.Zi(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.ys=s,this.vs&&this.vs.Es(this.ys),this.onUpdated(),this.refresh(r)}onUpdated(){}ti(t){this.vs&&(this.vs.Fs=t)}refresh(t){this.xs&&(this.xs.refresh(t),this.onUpdated())}Kt(){return{js:this.ys,Qt:this.vs,jt:this.xs}}$s(t){this.vs?.Vs(t)}ks(t){this.vs?.Rs(t)}}class y{constructor(t=null){this.Ds=null,this.Qt=null,this.Ds=t}_s(t){this.Ds=t}Is(t){this.Qt=t,t.ai("items",()=>{this.clear()}),t.ri("items",()=>{this.Ns()}),this.Ns()}clear(){this.Ds&&this.Ds.replaceChildren()}Ns(){this.Qt&&this.Ds&&this.Qt.Bs(this.Ds)}refresh(t){this.Ns()}}class v{constructor(t=null){this.ut=null,this.node=null,this.options=null,this.Us=null,this.zs=null,this.Bt=null,this.Gs=[],t&&this.init(t)}init(t){this.ut=e.I({Ws:{tag:{node:"div",classList:["selective-ui-accessorybox","hide"],onmouseup:t=>{t.stopPropagation()}}}}),this.node=this.ut.view,this.options=t}qs(t){this.Us=t,this.zs=t.parentElement,this.Js()}Js(){this.zs&&this.node&&this.Us&&this.options&&this.zs.insertBefore(this.node,"top"===this.options.accessoryStyle?this.Us:this.Us.nextSibling)}Ks(t){this.Bt=t}Qs(t){this.node&&this.options&&(this.node.replaceChildren(),t.length>0&&this.options.multiple?t.forEach(t=>{e.I({Ys:{tag:{node:"div",classList:["accessory-item"]},F:{Xs:{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.Bt?.$s?.("select"),setTimeout(()=>{t.selected=!1},10)}}},Zs:{tag:{node:"span",classList:["accessory-item-content"],innerHTML:t.text}}}}},this.node)}):t=[],this.Gs=t,this.te(),h.ot(window,"resize"))}te(){this.options?.accessoryVisible&&this.Gs.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.ie=null,this.se=null,this.ee=null,this.he=null,this.ne={currentPage:0,totalPages:1,hasMore:!1,Oi:!1,oe:"",Ti:!1},this.select=t,this.Bt=i,this.he=s}re(){return!!this.ie}async le(t){if(!this.ie)return{Ai:!1,items:[],message:"Ajax not configured"};const i=Array.isArray(t)?t:[t];if(0===i.length)return{Ai:!0,items:[]};try{const t=this.ie;let s,e;if(s="function"==typeof t.ae?t.ae(i):{values:i.join(","),ce:"1",..."function"==typeof t.data?t.data.bind(this.he.ue.find(this.he.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{Ai:!0,items:this.de(h).items}}catch(s){return console.error("Load by values error:",s),{Ai:!1,message:s?.message,items:[]}}}pe(t){const i=Array.from(this.select.options).map(t=>t.value);return{ge:t.filter(t=>i.includes(t)),fe:t.filter(t=>!i.includes(t))}}me(t){this.ie=t}setPopup(t){this.ee=t}xi(){return{...this.ne}}be(){this.ne={currentPage:0,totalPages:1,hasMore:!1,Oi:!1,oe:"",Ti:this.ne.Ti}}clear(){this.ne.oe="";const{js:t}=this.Bt.Kt(),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.ie?this.we(t,i):this.ye(t)}async Mi(){return this.ie?this.ne.Oi?{Ai:!1,message:"Already loading"}:this.ne.Ti?this.ne.hasMore?(this.ne.currentPage++,this.we(this.ne.oe,!0)):{Ai:!1,message:"No more data"}:{Ai:!1,message:"Pagination not enabled"}:{Ai:!1,message:"Ajax not enabled"}}async ye(t){this.ve(t)&&(this.ne.oe=t);const i=((t??"")+"").toLowerCase(),s=e.J(i),{js:h}=this.Bt.Kt(),n=[];for(const e of h)e instanceof b?n.push(e):e instanceof m&&Array.isArray(e.items)&&n.push(...e.items);let o=!1;return n.forEach(t=>{const e=""===i||t.ls.includes(s);t.visible=e,e&&(o=!0)}),{Ai:!0,xe:o,isEmpty:0===n.length}}ve(t){return t!==this.ne.oe}async we(t,i=!1){const s=this.ie;this.ve(t)&&(this.be(),this.ne.oe=t,i=!1),this.ne.Oi=!0,this.ee?.Zt(),this.se?.abort(),this.se=new AbortController;const e=this.ne.currentPage,h=Array.from(this.select.selectedOptions).map(t=>t.value).join(",");let n;"function"==typeof s.data?(n=s.data.bind(this.he.ue.find(this.he.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.se.signal})}else{const i=""+new URLSearchParams(n);t=await fetch(`${s.url}?${i}`,{signal:this.se.signal})}const e=await t.json(),h=this.de(e);return h.Te?(this.ne.Ti=!0,this.ne.currentPage=h.page,this.ne.totalPages=h.totalPages,this.ne.hasMore=h.hasMore):this.ne.Ti=!1,this.Oe(h.items,!!s.keepSelected,i),this.ne.Oi=!1,this.ee?.hi(),{Ai:!0,xe:h.items.length>0,isEmpty:0===h.items.length,Te:h.Te,hasMore:h.hasMore,currentPage:h.page,totalPages:h.totalPages}}catch(o){return this.ne.Oi=!1,this.ee?.hi(),"AbortError"===o?.name?{Ai:!1,message:"Request aborted"}:(console.error("Ajax search error:",o),{Ai:!1,message:o?.message})}}de(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.Me||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}}),Te:s,page:e,totalPages:h,hasMore:n}}Oe(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 T{constructor(t){this.Ae=null,this.Ce=null,this.Se=50,this.select=t,this.Ce=this.He(),this.Le=new MutationObserver(()=>{this.Ae&&clearTimeout(this.Ae),this.Ae=setTimeout(()=>{this.Pe()},this.Se)}),t.addEventListener("options:changed",()=>{this.Ae&&clearTimeout(this.Ae),this.Ae=setTimeout(()=>{this.Pe()},this.Se)})}He(){const t=Array.from(this.select.options);return{length:t.length,values:t.map(t=>t.value).join(","),Ie:t.map(t=>t.text).join(","),selected:t.map(t=>t.selected+"").join(",")}}Ee(){const t=this.He(),i=JSON.stringify(t)!==JSON.stringify(this.Ce);return i&&(this.Ce=t),i}Pe(){this.Ee()&&this.Ct(this.select)}connect(){this.Le.observe(this.select,{childList:!0,subtree:!1,attributes:!0,attributeFilter:["selected","value","disabled"]})}Ct(t){}disconnect(){this.Ae&&clearTimeout(this.Ae),this.Ae=null,this.Le.disconnect()}}class O{constructor(t){this.Ae=null,this.element=t,this.Le=new MutationObserver(t=>{let i=!1;for(const s of t)if("attributes"===s.type&&s.attributeName?.startsWith("data-")){i=!0;break}i&&(this.Ae&&clearTimeout(this.Ae),this.Ae=setTimeout(()=>{this.Ct({...this.element.dataset})},50))}),t.addEventListener("dataset:changed",()=>{this.Ct({...this.element.dataset})})}connect(){this.Le.observe(this.element,{attributes:!0,attributeOldValue:!0})}Ct(t){}disconnect(){this.Ae&&clearTimeout(this.Ae),this.Ae=null,this.Le.disconnect()}}class M{constructor(t=[]){this.items=[],this.Fe=e.m(12),this.Fs=!1,this.items=t,this.je()}je(){}$e(t,i,s){const e=i;t.xt?e?.update?.():e?.Ns?.()}ai(t,i){e.Z.on(`${t}ing_${this.Fe}`,i,{st:1})}ri(t,i){e.Z.on(`${t}_${this.Fe}`,i)}Rs(t,...i){e.Z.run(`${t}_${this.Fe}`,...i)}Vs(t,...i){e.Z.run(`${t}ing_${this.Fe}`,...i)}Ve(t,i){return null}ke(){return this.items.length}Re(t){this.Vs("items",t),this.items=t,this.Rs("items",t)}Ps(t){this.Re(t)}Bs(t){for(let i=0;i<this.ke();i++){const s=this.items[i];let e=s.view;s.xt||(e=this.Ve(t,s),s.view=e),this.$e(s,e,i),s.xt=!0}}Es(t){}}class A{constructor(t){this.parent=null,this.view=null,this.parent=t}Ns(){}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}Ns(){const t=e.m(7);this.view=e.P({De:{tag:{node:"div",classList:["selective-ui-group"],role:"group",A:`seui-${t}-header`,id:`seui-${t}-group`},F:{_e:{tag:{node:"div",classList:["selective-ui-group-header"],role:"presentation",id:`seui-${t}-header`}},Ne:{tag:{node:"div",classList:["selective-ui-group-items"],role:"group"}}}}}),this.parent.appendChild(this.view.view)}update(){this.Ki()}Ki(t=null){this.view&&null!==t&&(this.view.tags._e.textContent=t)}Be(){if(!this.view)throw Error("GroupView is not rendered.");return this.view.tags.Ne}ts(){if(!this.view)return;const t=Array.from(this.view.tags.Ne.children).filter(t=>!t.classList.contains("hide"));this.view.view.classList.toggle("hide",!(t.length>0))}Qi(t){this.view&&(this.view.view.classList.toggle("collapsed",t),this.view.tags._e.setAttribute("aria-expanded",t?"false":"true"))}}class S extends A{constructor(t){super(t),this.view=null,this.config=null,this.Ue=null,this.ze=!1,this.Ge()}Ge(){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.ze&&t.We(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 qe(){return this.Ue}set qe(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)}Ns(){const t=["selective-ui-option-view"],i=e.m(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={ds:{tag:{node:"input",type:this.config.isMultiple?"checkbox":"radio",classList:"allow-choice",id:s}},...this.config.hasImage&&{ws:{tag:{node:"img",classList:"option-image",style:{width:this.config.imageWidth,height:this.config.imageHeight,borderRadius:this.config.imageBorderRadius}}}},Je:{tag:{node:"label",htmlFor:s,classList:["align-vertical-"+this.config.labelValign,"align-horizontal-"+this.config.labelHalign]},F:{bs:{tag:{node:"div"}}}}};this.view=e.P({Ke:{tag:{node:"div",id:`seui-${i}-option`,classList:t,role:"option",ariaSelected:"false",tabIndex:"-1"},F:h}}),this.parent.appendChild(this.view.view),this.ze=!0}We(t,i,s){const e=this.view;if(!e||!e.view)return;const h=e.view,n=e.tags?.ds,o=e.tags?.Je;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.Qe();else{h.className=h.className.replace(/image-(top|right|bottom|left)/g,"").trim();const t=e.tags?.ws;t&&(t.remove(),e.tags.ws=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?.ws;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)}}}Qe(){const t=this.view;if(!t||!t.view)return;const i=t.tags?.ws;if(i)return;const s=t.view,e=t.tags?.Je,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.ws=h}}class H extends M{constructor(t=[]){super(t),this.isMultiple=!1,this.Ye=[],this.Xe=-1,this.Ze=null,this.groups=[],this.th=[],this.ih(),e.Z.on("sche_vis_"+this.Fe,()=>{const t=this.th.filter(t=>t.visible).length,i=this.th.length;this.Ye.forEach(s=>{s({sh:t,eh:i,ii:t>0,isEmpty:0===i})}),e.Z.run("sche_vis_proxy_"+this.Fe)},{st:10})}ih(){this.th=[],this.groups=[],this.items.forEach(t=>{t instanceof m?(this.groups.push(t),this.th.push(...t.items)):t instanceof b&&this.th.push(t)})}Ve(t,i){return i instanceof m?new C(t):new S(t)}$e(t,i,s){t.position=s,t instanceof m?this.hh(t,i,s):t instanceof b&&this.nh(t,i,s),t.xt=!0}hh(t,i,s){super.$e(t,i,s),t.view=i;const e=i.view.tags._e;e.textContent=t.label,t.xt||(e.style.cursor="pointer",e.addEventListener("click",()=>{t.Xi()}),t.Yi((t,i,s)=>{i.items.forEach(t=>{const i=t.view?.Ui?.();i&&(i.style.display=s?"none":"")}),this.oh(i,s)}));const h=i.Be();t.items.forEach((t,i)=>{let s=t.view;t.xt&&s||(s=new S(h)),this.nh(t,s,i),t.xt=!0}),i.Qi(t.collapsed),i.ts()}nh(t,i,s){if(i.isMultiple=this.isMultiple,i.hasImage=t.hasImage,i.qe={imageWidth:t.options.imageWidth,imageHeight:t.options.imageHeight,imageBorderRadius:t.options.imageBorderRadius,imagePosition:t.options.imagePosition,labelValign:t.options.labelValign,labelHalign:t.options.labelHalign},t.xt||super.$e(t,i,s),t.view=i,t.hasImage){const s=i.view.tags.ws;s&&(s.src!==t.cs&&(s.src=t.cs),s.alt!==t.text&&(s.alt=t.text))}i.view.tags.bs.innerHTML=t.text,t.xt||(i.view.tags.Ke.addEventListener("click",i=>{i.stopPropagation(),i.preventDefault(),this.Fs||(this.isMultiple?(this.Vs("select"),setTimeout(()=>{t.selected=!t.selected},5)):!0!==t.selected&&(this.Vs("select"),setTimeout(()=>{this.Ze&&(this.Ze.selected=!1),t.selected=!0},5)))}),i.view.tags.Ke.title=t.textContent,i.view.tags.Ke.addEventListener("mouseenter",()=>{this.Fs||this.rh(this.th.indexOf(t),!1)}),t.gs(()=>{this.Rs("selected")}),t.fs((i,s,e)=>{e&&(this.Ze=t),this.Rs("selected_internal")}),t.oi((t,i)=>{i.group?.ts(),this.ah()})),t.selected&&(this.Ze=t,t.us=!0)}Re(t){this.Vs("items",t),this.items=t,this.ih(),this.Rs("items",t)}Ps(t){this.Re(t)}Es(t){this.items=t,this.ih()}uh(){return this.th.filter(t=>t.selected)}dh(){return this.th.find(t=>t.selected)}Yt(t){this.isMultiple&&this.th.forEach(i=>{i.selected=t})}oi(t){this.Ye.push(t)}ah(){e.Z.run("sche_vis_"+this.Fe)}si(){const t=this.th.filter(t=>t.visible).length,i=this.th.length;return{sh:t,eh:i,ii:t>0,isEmpty:0===i}}ph(){this.rh(0)}navigate(t,i=!0){const s=this.th.filter(t=>t.visible);if(0===s.length)return;let e=s.findIndex(t=>t===this.th[this.Xe]);-1===e&&(e=-1);let h=e+t;h>=s.length&&(h=0),h<0&&(h=s.length-1);const n=this.th.indexOf(s[h]);this.rh(n,i)}gh(){if(this.Xe>-1&&this.th[this.Xe]){const t=this.th[this.Xe];if(t.visible){const i=t.view?.Ui?.();i&&i.click()}}}rh(t,i=!0){let s=0;if("number"==typeof t)s=t;else if(t instanceof b){const i=this.th.indexOf(t);s=i>-1?i:0}else s=0;this.Xe>-1&&this.th[this.Xe]&&(this.th[this.Xe].ps=!1);for(let e=s;e<this.th.length;e++){const t=this.th[e];if(t?.visible){if(t.ps=!0,this.Xe=e,i){const i=t.view?.Ui?.();i?i.scrollIntoView({block:"center",behavior:"smooth"}):this.jt?.fh?.(e,{scrollIntoView:!0})}return void this.mh(e,t.view?.Ui?.()?.id)}}}mh(t,i){}oh(t,i){}}class L{constructor(t=0){this.bh=[],this.n=0,this.reset(t)}reset(t){this.n=t,this.bh=Array(t+1).fill(0)}add(t,i){for(let s=t;s<=this.n;s+=s&-s)this.bh[s]+=i}wh(t){let i=0;for(let s=t;s>0;s-=s&-s)i+=this.bh[s];return i}yh(t,i){return i<t?0:this.wh(i)-this.wh(t-1)}xh(t){this.reset(t.length),t.forEach((t,i)=>this.add(i+1,t))}Th(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.bh[s]<=t&&(i=s,e+=this.bh[s])}return i}}class P extends y{constructor(t=null){super(t),this.Oh={Jt:void 0,Dt:36,_t:8,Nt:!0,Mh:!0},this.Ah=[],this.Ch=new L(0),this.Sh=new Map,this.Hh=!1,this.start=0,this.end=-1,this.Lh=null,this.Ph=null,this.updating=!1,this.Ih=!1,this.Eh=0,this.Fh=!1,this.jh=!1,this.$h=0,this.Vh=0,this.kh=0,this.Rh=0}configure(t){this.Oh={...this.Oh,...t}}Is(t){if(this.Qt&&this.dispose(),super.Is(t),t.jt=this,!this.Ds)return;this.Ds.replaceChildren();const i=e.I({Dh:{tag:{node:"div",classList:"selective-ui-virtual-pad-top"}},_h:{tag:{node:"div",classList:"selective-ui-virtual-items"}},Nh:{tag:{node:"div",classList:"selective-ui-virtual-pad-bottom"}}},this.Ds);if(this.Dh=i.Dh,this._h=i._h,this.Nh=i.Nh,this.Jt=this.Oh.Jt??this.Ds.closest(".selective-ui-popup")??this.Ds.parentElement,!this.Jt)throw Error("VirtualRecyclerView: scrollEl not found");this.Bh=this.Uh.bind(this),this.Jt.addEventListener("scroll",this.Bh,{passive:!0}),this.refresh(!1),this.zh(),t?.oi?.(()=>this.Gh())}suspend(){this.Fh=!0,this.Wh(),this.Jt&&this.Bh&&this.Jt.removeEventListener("scroll",this.Bh),this.qh&&(this.qh.disconnect(),this.jh=!0)}resume(){this.Fh=!1,this.Jt&&this.Bh&&this.Jt.addEventListener("scroll",this.Bh,{passive:!0}),this.jh&&(this.zh(),this.jh=!1),this.Jh()}refresh(t){if(!this.Qt||!this.Ds)return;t||this.Gh();const i=this.Qt.ke();this.Eh=i,0!==i?(this.Ah.length=i,this.Hh||(this.Kh(),this.Hh=!0),this.Qh(i),this.Jh()):this.Yh()}fh(t,i){this.Xh(t,t),i?.scrollIntoView&&this.Zh(t)}Zh(t){if((this.Qt?.ke?.()??0)<=0)return;const i=this.tn(t),s=this.sn()+i,e=Math.max(0,this.Jt.scrollHeight-this.Jt.clientHeight);this.Jt.scrollTop=Math.min(Math.max(0,s),e)}dispose(){this.Wh(),this.Jt&&this.Bh&&this.Jt.removeEventListener("scroll",this.Bh),this.qh?.disconnect(),this.Sh.forEach(t=>t.remove()),this.Sh.clear()}Gh(){if(!this.Qt)return;const t=this.Qt.ke();t<=0||(this.suspend(),this.Yh(),this.en(),this.hn(t),this.Qh(t),this.start=0,this.end=-1,this.resume())}Wh(){null!=this.Lh&&(cancelAnimationFrame(this.Lh),this.Lh=null),null!=this.Ph&&(cancelAnimationFrame(this.Ph),this.Ph=null)}Yh(){this.Sh.forEach(t=>t.remove()),this.Sh.clear(),this.Ah=[],this.Ch.reset(0),this.Dh.style.height="0px",this.Nh.style.height="0px",this.Hh=!1,this.kh=0,this.Rh=0}Kh(){this.nn(0);const t=this.Sh.get(0);if(!t)return;const i=this.rn(t);if(isNaN(i)||(this.Oh.Dt=i),!this.Oh.Nt){t.remove(),this.Sh.delete(0);const i=this.Qt.items[0];i&&(i.xt=!1,i.view=null)}}ln(t){const i=this.Qt?.items?.[t];return i?.visible??!0}an(t,i){for(let s=Math.max(0,t);s<i;s++)if(this.ln(s))return s;return-1}hn(t){this.kh=0,this.Rh=0;for(let i=0;i<t;i++){if(!this.ln(i))continue;const t=this.Ah[i];null!=t&&(this.kh+=t,this.Rh++)}}sn(){const t=this.Ds.getBoundingClientRect(),i=this.Jt.getBoundingClientRect();return t.top-i.top+this.Jt.scrollTop}cn(){const t=performance.now();if(t-this.$h<16)return this.Vh;const i=this.Jt.querySelector(".selective-ui-option-handle:not(.hide)");return this.Vh=i?.offsetHeight??0,this.$h=t,this.Vh}Jh(){null!=this.Lh||this.Fh||(this.Lh=requestAnimationFrame(()=>{this.Lh=null,this.un()}))}rn(t){const i=t.getBoundingClientRect(),s=getComputedStyle(t);return Math.max(1,i.height+(parseFloat(s.marginTop)||0)+(parseFloat(s.marginBottom)||0))}dn(){return this.Oh.Mh&&this.Rh>0?Math.max(1,this.kh/this.Rh):this.Oh.Dt}Qh(t){const i=this.dn(),s=Array.from({length:t},(t,s)=>this.ln(s)?this.Ah[s]??i:0);this.Ch.xh(s)}pn(t,i){if(!this.ln(t))return!1;const s=this.dn(),e=this.Ah[t]??s;if(Math.abs(i-e)<=P.gn)return!1;const h=this.Ah[t];return null==h?(this.kh+=i,this.Rh++):this.kh+=i-h,this.Ah[t]=i,this.Ch.add(t+1,i-e),!0}fn(t,i){const s=this.Ch.Th(Math.max(0,t)),e=Math.min(i-1,s),h=this.an(e,i);return-1===h?Math.max(0,e):h}mn(t,i){i.setAttribute(P.bn,t+"");const s=this.Sh.get(t-1);if(s?.parentElement===this._h)return void s.after(i);const e=this.Sh.get(t+1);if(e?.parentElement===this._h)return void this._h.insertBefore(i,e);const h=Array.from(this._h.children);for(const n of h){const s=n.getAttribute(P.bn);if(s&&+s>t)return void this._h.insertBefore(i,n)}this._h.appendChild(i)}wn(t,i){if(i.parentElement!==this._h)return void this.mn(t,i);i.setAttribute(P.bn,t+"");const s=i.previousElementSibling,e=i.nextElementSibling;(s&&+s.getAttribute(P.bn)>t||e&&+e.getAttribute(P.bn)<t)&&(i.remove(),this.mn(t,i))}zh(){this.qh||(this.qh=new ResizeObserver(()=>{this.Ih||this.Fh||!this.Qt||null!=this.Ph||(this.Ph=requestAnimationFrame(()=>{this.Ph=null,this.yn()}))}),this.qh.observe(this._h))}yn(){if(!this.Qt)return;const t=this.Qt.ke();if(t<=0)return;let i=!1;for(let s=this.start;s<=this.end;s++){if(!this.ln(s))continue;const t=this.Qt.items[s],e=t?.view?.Ui?.();if(!e)continue;const h=this.rn(e);this.pn(s,h)&&(i=!0)}i&&(this.Oh.Mh&&this.Qh(t),this.Jh())}Uh(){this.Jh()}un(){if(!this.updating&&!this.Fh){this.updating=!0;try{if(!this.Qt)return;const t=this.Qt.ke();if(t<=0)return;this.Eh!==t&&(this.Eh=t,this.Ah.length=t,this.Qh(t));const i=this.sn(),s=Math.max(0,this.Jt.scrollTop-i),e=this.cn(),h=Math.max(0,this.Jt.clientHeight-e),n=this.fn(s,t),o=i+this.tn(n)-this.Jt.scrollTop,r=this.fn(s,t);if(-1===r)return void this.Yh();const l=this.dn(),a=this.Oh._t*l;let c=this.an(Math.min(t-1,this.Ch.Th(Math.max(0,s-a))),t)??r,u=Math.min(t-1,this.Ch.Th(s+h+a));if(c===this.start&&u===this.end)return;this.start=c,this.end=u,this.Ih=!0;try{this.Xh(this.start,this.end),this.vn(this.start,this.end),this.Oh.Nt&&this.yn();const i=this.tn(this.start),s=this.xn(this.start,this.end),e=this.Tn(t),h=Math.max(0,e-i-s);this.Dh.style.height=i+"px",this.Nh.style.height=h+"px"}finally{this.Ih=!1}const d=this.tn(n),p=this.sn()+d-o,g=Math.max(0,this.Jt.scrollHeight-this.Jt.clientHeight),f=Math.min(Math.max(0,p),g);Math.abs(this.Jt.scrollTop-f)>.5&&(this.Jt.scrollTop=f)}finally{this.updating=!1}}}Xh(t,i){for(let s=t;s<=i;s++)this.nn(s)}nn(t){if(!this.ln(t)){const i=this.Sh.get(t);return i?.parentElement===this._h&&i.remove(),void this.Sh.delete(t)}const i=this.Qt.items[t];if(!i)return;const s=this.Sh.get(t);if(s)return void(i?.view?(this.wn(t,s),this.Qt.$e(i,i.view,t)):(s.remove(),this.Sh.delete(t)));if(i.xt)i.view&&this.Qt.$e(i,i.view,t);else{const s=this.Qt.Ve(this._h,i);i.view=s,this.Qt.$e(i,s,t),i.xt=!0}const e=i.view?.Ui?.();e&&(this.wn(t,e),this.Sh.set(t,e))}vn(t,i){this.Sh.forEach((s,e)=>{(e<t||e>i)&&(s.parentElement===this._h&&s.remove(),this.Sh.delete(e))})}en(){this.Sh.forEach((t,i)=>{this.ln(i)||(t.parentElement===this._h&&t.remove(),this.Sh.delete(i))})}tn(t){return this.Ch.wh(t)}xn(t,i){return this.Ch.yh(t+1,i+1)}Tn(t){return this.Ch.wh(t)}}P.gn=.5,P.bn="data-vindex";class I{constructor(t=null,i=null){this.container={},this.oldValue=null,this.node=null,this.options=null,this.On=null,this.isOpen=!1,this.Mn=!1,this.An=!1,this.ue=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?.wi?.setAttribute("aria-disabled",t+""))}get Cn(){return!!this.options?.readonly}set Cn(t){this.options&&this.node&&(this.options.readonly=t,this.node.classList.toggle("readonly",t))}get isVisible(){return!!this.options?.visible}set isVisible(t){this.options&&this.node&&(this.options.visible=t,this.node.classList.toggle("invisible",!t))}init(t,s){const h=e.R(t).options,l=new o(h),a=new r,c=new p(h),effector=i(),u=new w(h),g=new v(h),f=new x(t,u,this),m=new T(t),b=new O(t);this.ue=s,this.options=h,l.node&&(l.node.id=(h.Sn??"")+"");const M=e.I({Hn:{tag:{node:"div",classList:"selective-ui-MAIN"},F:{wi:{tag:{node:"div",classList:"selective-ui-view",tabIndex:0,onkeydown:t=>{"Enter"!==t.key&&" "!==t.key&&"ArrowDown"!==t.key||(t.preventDefault(),this.Ln()?.open())}},F:{Pn:{tag:l.node},In:{tag:a.node},ji:{tag:c.node}}}}}},null);this.container=M,this.node=M.view,t.parentNode?.insertBefore(this.node,t),this.node.insertBefore(t,M.tags.wi),g.qs(M.tags.wi),g.Ks(u),M.tags.wi.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()}),n.lt(t,M.tags.wi),t.classList.add("init"),u.Os(H),u.As(h.virtualScroll?P:y),u.Ls(e.K(t)),u.onUpdated=()=>{M.ee?.ei?.()},this.On=u,M.En=f,M.placeholder=l,M.Fn=a,M.jn=c,M.effector=effector,M.targetElement=t,M.$n=g,M.Vn=m,M.kn=b,M.ee=new d(t,h,u),M.ee.ui(effector),M.ee.yi(f,h),M.ee.ci("selected",()=>{this.Ln()?.change(null,!0)}),M.ee.ci("selected_internal",()=>{this.Ln()?.change(null,!1)}),M.ee.li("select",()=>{this.oldValue=this.Ln()?.value??""}),this.Ln()?.change(null,!1),m.connect(),m.Ct=t=>{u.update(e.K(t)),this.Ln()?.refreshMask()},b.connect(),b.Ct=t=>{e.$(t.disabled)!==this.isDisabled&&(this.isDisabled=e.$(t.disabled)),e.$(t.readonly)!==this.Cn&&(this.Cn=e.$(t.readonly)),e.$(t.visible)!==this.isVisible&&(this.isVisible=e.$(t.visible??"1"))},t.addEventListener("options:changed",()=>{u.update(e.K(t)),this.Ln()?.refreshMask(),M.ee?.ei?.()}),h.ajax&&f.me(h.ajax);const A=M.ee.Ht;let C=null;const S=(t,i)=>{i||""!==t?(""!==t&&(this.An=!0),f.search(t).then(t=>{clearTimeout(C),e.Z.clear("sche_vis_proxy_"+A.Fe),e.Z.on("sche_vis_proxy_"+A.Fe,()=>{M.ee?.ei?.(),t?.xe&&(C=setTimeout(()=>{A.ph(),M.ee?.ei?.()},h.animationtime??0))},{st:10})}).catch(t=>{console.error("Search error:",t)})):f.clear()};let L=null;c.Pi=(t,i)=>{f.ve(t)&&(L&&clearTimeout(L),f.re()?(M.ee?.Zt?.(),L=setTimeout(()=>{S(t,i)},h.delaysearchtime??0)):L=setTimeout(()=>{S(t,i)},10))},f.setPopup(M.ee),c.Ii=t=>{A.navigate(t)},c.Ei=()=>{A.gh()},c.Fi=()=>{this.Ln()?.close(),M.tags.wi.focus()},A.mh=(t,i)=>{i&&c.Vi(i)},A.oh=()=>{M.ee?.ei?.()},this.isDisabled=e.$(h.disabled),this.Cn=e.$(h.readonly)}Rn(){const t=this.container??{},{Vn:i,kn:s}=t;i?.disconnect&&i.disconnect(),s?.disconnect&&s.disconnect()}Ln(){const t=this.container,i=this,s=()=>this.ue.find(t.targetElement),n=e.R(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.jn?.$i(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.Dn().forEach(i=>{i.selected&&t.push(i.value)}),t},get valueString(){return this.valueArray.join(o.customDelimiter)},get valueOptions(){const t=[];return i.Dn(!0).forEach(i=>{t.push(i)}),t},get mask(){const t=[];return i.Dn(!0).forEach(i=>{t.push(i.text)}),t},get valueText(){const t=[];i.Dn(!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.Dn(!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.Dn().length>o.maxSelected)&&!this.disabled&&!this.readonly&&o.multiple){if(e){if(h.nt([s()],...o.on.beforeChange).isCancel)return;i.oldValue=this.value}i.Dn().forEach(t=>{t.us=!0}),this.change(!1,e)}},deSelectAll(t,e=!0){if(!this.disabled&&!this.readonly&&o.multiple){if(e){if(h.nt([s()],...o.on.beforeChange).isCancel)return;i.oldValue=this.value}i.Dn().forEach(t=>{t.us=!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.Dn().forEach(t=>t.us=!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.En?.re?.()){const{fe:s}=t.En.pe(n);if(s.length>0)return void(async()=>{o.loadingfield&&t.ee?.Zt?.();try{t.En.be();const e=await t.En.le(s);e.Ai&&e.items.length>0?(e.items.forEach(t=>{s.includes(t.value)&&(t.selected=!0)}),t.En.Oe?.(e.items,!0,!0),setTimeout(()=>{i.Dn().forEach(t=>{t.us=n.some(i=>i==t.value)}),this.change(!1,!1)},100)):s.length>0&&console.warn(`Could not load ${s.length} values:`,s)}catch(e){console.error("Error loading missing values:",e)}finally{o.loadingfield&&t.ee?.hi?.()}})()}if(r){if(h.nt([s()],...o.on.beforeChange).isCancel)return;i.oldValue=this.value}i.Dn().forEach(t=>{t.us=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.ue?.find?.();if(e&&!e.isEmpty&&e.close().isCancel)return;if(this.disabled)return;if(h.nt([s()],...o.on.beforeShow).isCancel)return;i.isOpen=!0,t.Fn.ct(!0);const n=t.ee.Ht,r=n.dh();r?n.rh(r,!1):n.ph(),i.Mn&&!i.An||!o?.ajax?t.ee.open(null,!0):(t.En.be(),t.ee.Zt(),i.Mn=!0,i.An=!1,setTimeout(()=>{t.ee&&t.En&&t.En.search("").then(()=>t.ee?.ei?.()).catch(t=>console.error("Initial ajax load error:",t))},o.animationtime),t.ee.open(null,!1)),t.jn.show();const l=t.tags.wi;l.setAttribute("aria-expanded","true"),l.setAttribute("aria-controls",o.Gt),l.setAttribute("aria-haspopup","listbox"),l.setAttribute("aria-labelledby",o.Sn),o.multiple&&l.setAttribute("aria-multiselectable","true"),h.nt([s()],...o.on.show)},close(){i.isOpen&&(h.nt([s()],...o.on.beforeClose).isCancel||(i.isOpen=!1,t.Fn.ct(!1),t.ee.close(()=>{t.jn.clear(!1)}),t.jn.hide(),t.tags.wi.setAttribute("aria-expanded","false"),h.nt([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.nt([s(),this.value],...o.on.beforeChange).isCancel)return void this.setValue(null,this.oldValue,!1)}this.refreshMask(),t.$n.Qs(this.valueOptions),n&&(t.targetElement&&h.ot(t.targetElement,"change"),h.nt([s(),this.value],...o.on.change),i.options?.autoclose&&this.close())},refreshMask(){let s=o.placeholder;!o.multiple&&i.Dn().length>0&&(s=this.mask[0]),s??(s=o.placeholder),t.placeholder.set(s,!1),t.jn.$i(s)},on(t,i,s){o.on[i]||(o.on[i]=[]),o.on[i].push(s)},ajax(i,s){t.En.me(s)},loadAjax:()=>new Promise((e,h)=>{t.ee.Zt(),t.En.be(),i.Mn=!0,i.An=!1,t.ee&&t.En?t.En.search("").then(()=>{t.ee?.ei?.(),e(s())}).catch(t=>{console.error("Initial ajax load error:",t),h(t)}):e(s())})};return this._n(r,"disabled","isDisabled"),this._n(r,"readonly","isReadOnly"),this._n(r,"visible","isVisible"),r}_n(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})}Dn(t=null){if(!this.On)return[];const{js:i}=this.On.Kt(),s=[];for(const e of i)e instanceof b?s.push(e):e instanceof m&&Array.isArray(e.items)&&e.items.length&&s.push(...e.items);return"boolean"==typeof t?s.filter(i=>i.selected===t):s}Ci(){this.container.ee.Ci()}}class E{constructor(){this.isActive=!1,this.Le=null,this.actions=[]}Nn(t){this.actions.push(t)}Bn(){this.actions=[]}start(t){if(this.isActive)return;this.isActive=!0;const i=t.toUpperCase(),s=t.toLowerCase();this.Le=new MutationObserver(t=>{for(const e of t)e.addedNodes.forEach(t=>{if(1!==t.nodeType)return;const e=t;e.tagName===i&&this.Un(e),e.querySelectorAll(s).forEach(t=>this.Un(t))})}),this.Le.observe(document.body,{childList:!0,subtree:!0})}stop(){this.isActive&&(this.isActive=!1,this.Le?.disconnect(),this.Le=null)}Un(t){this.actions.forEach(i=>i(t))}}class F{constructor(){this.zn=new Map}bind(t,i){const s=e.V(e.U(),i);s.on=s.on??{},s.on.load=s.on.load??[],this.zn.set(t,s);const n=e.m();e.Z.on(n,()=>{h.nt([this.find(t)],...s.on.load),e.Z.clear(n),s.on.load=[]}),e.v(t).forEach(t=>{(async()=>{"SELECT"===t.tagName&&(e._(t),this.Gn(t,s)&&e.Z.run(n))})()}),e.G().includes(t)||e.G().push(t)}find(t="*"){const i={isEmpty:!0};if("*"===t&&""===(t=e.G().join(", ")))return i;const s=e.v(t);if(0===s.length)return i;const h=e.R(s[0]);if(!h||!h.action)return i;const n={};for(const e in h.action)n[e]=this.Wn(e,h.action);const o={isEmpty:!1};for(const e in n){const t=n[e];switch(t.type){case"get-set":this.qn(o,t.name,s);break;case"func":this.Jn(o,t.name,s)}}return o}Kn(){this.Qn=new E,this.Qn.Nn(t=>{this.zn.forEach((i,s)=>{try{t.matches(s)&&this.Gn(t,i)}catch(e){console.warn("Invalid selector: "+s,e)}})}),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.G().forEach(t=>this.Xn(t)),this.zn.clear(),e.G().length=0,this.Qn?.stop()}Xn(t){e.v(t).forEach(t=>{"SELECT"===t.tagName&&this.Zn(t)}),this.zn.delete(t);const i=e.G(),s=i.indexOf(t);s>-1&&i.splice(s,1)}Zn(t){const i=e.R(t);if(!i)return;const s=i.container?.ee;s?.Ci(),e.B(t,i);const h=!!this.Qn;h&&this.Qn?.stop();try{i.self?.Rn?.()}catch(o){}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.k(t),h&&this.zn.size>0&&this.Qn?.start("select")}rebind(t,i){this.Xn(t),this.bind(t,i)}Gn(t,i){if(e.R(t)||e.N(t))return!1;const s=e.m(8),h=e.j(t,i);h.so=s,h.Gt=`seui-${s}-optionlist`,h.Sn=`seui-${s}-placeholder`;const n={options:h};e.D(t,n);const o=new I(t,this);return n.container=o.container,n.action=o.Ln(),n.self=o,o.container.view.addEventListener("mouseup",()=>{n.action?.toggle?.()}),!0}Wn(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}}qn(t,i,s){Object.defineProperty(t,i,{get(){const t=e.R(s[0]);return t.action?.[i]},set(t){s.forEach(s=>{const h=e.R(s);h?.action&&(h.action[i]=t)})},enumerable:!0,configurable:!0})}Jn(t,i,s){t[i]=(...n)=>{let o=null;for(let t=0;t<s.length;t++){const r=e.R(s[t]);if(!r?.action)continue;const l=h.ht();if(o??(o=r.action[i](l.et,...n)),!l.token.isContinue)break}return o??t}}}if(void 0===globalThis.GLOBAL_SEUI){const $=new F;globalThis.GLOBAL_SEUI={version:"1.2.2",name:"SelectiveUI",bind:$.bind.bind($),find:$.find.bind($),destroy:$.destroy.bind($),effector:i.bind(i),rebind:$.rebind.bind($)};let V=!1;function k(){V||(V=!0,document.addEventListener("mousedown",()=>{const t=e.G();if(t.length>0){const i=$.find(t.join(", "));i.isEmpty||i.close()}}),$.Kn())}"undefined"!=typeof document&&("loading"===document.readyState?document.addEventListener("DOMContentLoaded",k):k()),console.log("[SelectiveUI] v1.2.2 loaded successfully")}else console.warn(`[${globalThis.GLOBAL_SEUI.name}] Already loaded (v${globalThis.GLOBAL_SEUI.version}). Using existing instance. Please remove duplicate <script> tags.`);const version=globalThis.GLOBAL_SEUI.version,j=globalThis.GLOBAL_SEUI.name;t.bind=(t,i={})=>{globalThis.GLOBAL_SEUI.bind(t,i)},t.destroy=(t=null)=>{globalThis.GLOBAL_SEUI.destroy(t)},t.effector=t=>globalThis.GLOBAL_SEUI.effector(t),t.find=t=>globalThis.GLOBAL_SEUI.find(t),t.name=j,t.rebind=(t,i={})=>{globalThis.GLOBAL_SEUI.rebind(t,i)},t.version=version},"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).SelectiveUI={});
Binary file