selective-ui 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/selective-ui.esm.js +127 -110
- package/dist/selective-ui.esm.js.map +1 -1
- package/dist/selective-ui.esm.min.js +2 -2
- package/dist/selective-ui.esm.min.js.br +0 -0
- package/dist/selective-ui.min.js +2 -2
- package/dist/selective-ui.min.js.br +0 -0
- package/dist/selective-ui.umd.js +127 -110
- package/dist/selective-ui.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/ts/index.ts +137 -74
- package/src/ts/types/utils/selective.type.ts +6 -1
- package/src/ts/utils/selective.ts +14 -14
- package/src/ts/utils/guard.ts +0 -70
package/dist/selective-ui.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! Selective UI v1.1.
|
|
2
|
-
var t,i;t=this,i=function(t){"use strict";function i(t){return new f(t??null)}function s(){if("undefined"!=typeof window)return window[E]}function bind(t,i={}){const e=s();if(F&&e)return e.bind(t,i);j.bind(t,i)}function find(t){const i=s();return F&&i?i.find(t):j.find(t)}function destroy(t=null){const i=s();if(F&&i)return i.destroy(t);j.destroy(t)}function rebind(t,i={}){const e=s();if(F&&e)return e.rebind(t,i);j.rebind(t,i)}function effector(t){const e=s();return F&&e?e.effector(t):i(t)}class e{constructor(){this.t={showPanel:!0,accessoryStyle:"top",multiple:!1,minWidth:"50px",width:"0px",offsetWidth:null,minHeight:"30px",height:"30px",panelHeight:"220px",panelMinHeight:"100px",disabled:!1,readonly:!1,selectall:!0,keepSelected:!0,placeholder:"Select value",altMask:"",autoclose:!1,autoscroll:!0,autofocus:!0,searchable:!0,loadingfield:!0,visible:!0,skipError:!1,customDelimiter:",",textLoading:"Processing...",textNoData:"No data available",textNotFound:"Not found",textSelectAll:"Select all",textDeselectAll:"Deselect all",textAccessoryDeselect:"Deselect: ",animationtime:200,delaysearchtime:200,allowHtml:!0,maxSelected:0,labelHalign:"left",labelValign:"center",imageMode:!1,imageWidth:"60px",imageHeight:"60px",imageBorderRadius:"4px",imagePosition:"right",ajax:null,on:{load:[],beforeShow:[],show:[],beforeChange:[],change:[],beforeClose:[],close:[]}},this.i=new Map,this.h=new Map,this.o=[]}}class n{static get l(){return this.u||(this.u=new e),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 O(t={}){return this.C(document.createElement(t.node??"div"),t,!0)}static C(t=document.documentElement,i=null,s=!1){const e={...i??{}},n=s?t:this.T(t.cloneNode(!0)),h=e.classList;return"string"==typeof h?n.classList.add(h):Array.isArray(h)&&n.classList.add(...h),delete e.classList,["style","dataset"].forEach(t=>{const i=e[t];i&&"object"==typeof i&&Object.assign(n[t],i),delete e[t]}),e.role&&(n.setAttribute("role",e.role+""),delete e.role),e.ariaLive&&(n.setAttribute("aria-live",e.ariaLive+""),delete e.ariaLive),e.A&&(n.setAttribute("aria-labelledby",e.A+""),delete e.A),e.S&&(n.setAttribute("aria-controls",e.S+""),delete e.S),e.L&&(n.setAttribute("aria-haspopup",e.L+""),delete e.L),e.P&&(n.setAttribute("aria-multiselectable",e.P+""),delete e.P),e.M&&(n.setAttribute("aria-autocomplete",e.M+""),delete e.M),e.event&&"object"==typeof e.event&&(Object.entries(e.event).forEach(([t,i])=>{n.addEventListener(t,i)}),delete e.event),Object.entries(e).forEach(([t,i])=>{null===i?n.removeAttribute(t):n[t]=i}),n}static T(t){if(t instanceof Element)return t;throw new TypeError("Node is not an Element")}static H(t){return this.$(t)}static $(t,i=null,s=!1,e=!1,n={}){let h=null;for(const o in t){const r=t[o],l=r?.tag?.tagName?r.tag:this.O(r.tag);n[o]=l,r?.j&&this.$(r.j,l,!1,!1,n),i?s?i.prepend(l):i.append(l):e||h||(h=l)}return e||(n.id=this.m(7),i||(n={tags:n,view:h})),n}static F(t,i){const s=this.p(i);for(const e in s){const i=t[e];i?s[e]=i:void 0!==t?.dataset?.[e]&&(s[e]=t.dataset[e])}return s}static I(...t){if(0===t.length)return{};if(1===t.length)return this.p(t[0]);const i=this.p(t[0]);for(let s=1;s<t.length;s++){const e=t[s];for(const t in e)if("on"===t){const s=e[t];for(const e in s)i[t][e].push(s[e])}else i[t]=e[t]}return i}static V(t){if("boolean"==typeof t)return t;if("string"!=typeof t)return!!t;switch(t.trim().toLowerCase()){case"true":case"1":case"yes":case"on":return!0;default:return!1}}static k(t){return this.l.i.delete(t)}static R(t){return this.l.i.get(t)}static _(t,i){this.l.i.set(t,i)}static D(t){return this.l.h.delete(t)}static N(t){return this.l.h.get(t)}static B(t,i){this.l.h.set(t,i)}static G(){return this.l.t}static U(){return this.l.o}static W(t){if(null==t)return"";let i=(t+"").replace(/<`/g,"<").replace(/`>/g,">").replace(/\<\`/g,"<").replace(/\`\>/g,">").trim();const s=globalThis?.document;if(!s||"function"!=typeof s.createElement)return i=i.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"").replace(/<iframe\b[^>]*>[\s\S]*?<\/iframe>/gi,"").replace(/<(object|embed|link)\b[^>]*>[\s\S]*?<\/\1>/gi,""),i=i.replace(/\son[a-z]+\s*=\s*(['"]).*?\1/gi,""),i=i.replace(/\s([a-z-:]+)\s*=\s*(['"])\s*javascript:[^'"]*\2/gi,""),i;const e=s.createElement("div");return e.innerHTML=i,e.querySelectorAll("script, style, iframe, object, embed, link").forEach(t=>t.remove()),e.querySelectorAll("*").forEach(t=>{for(const i in t.attributes){const s=t.attributes[i],e=s.name??"",n=s.value??"";if(/^on/i.test(e))return void t.removeAttribute(e);/^(href|src|xlink:href)$/i.test(e)&&/^javascript:/i.test(n)&&t.removeAttribute(e)}}),(e.innerHTML??"").trim()}static q(t){const i=document.createElement("DIV");i.innerHTML=t;const s=i.textContent??i.innerText??"";return i.remove(),s.trim()}static J(t){return null==t?"":(t+"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/đ/g,"d").replace(/Đ/g,"d")}static K(t){const i=[];return Array.from(t.children).forEach(t=>{if("OPTGROUP"===t.tagName){const s=t;i.push(s),Array.from(s.children).forEach(t=>{t.__parentGroup=s,i.push(t)})}else"OPTION"===t.tagName&&i.push(t)}),i}static Y(){const t=navigator.userAgent;return/iP(hone|ad|od)/.test(t)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1}static X(t){const i=(t+"").trim();if(i.endsWith("px"))return i;if(i.endsWith("vh"))return window.innerHeight*parseFloat(i)/100+"px";if(i.endsWith("vw"))return window.innerWidth*parseFloat(i)/100+"px";const s=parseFloat(getComputedStyle(document.documentElement).fontSize);if(i.endsWith("rem"))return s*parseFloat(i)+"px";const e=this.O({node:"div",style:{height:i,opacity:"0"}});document.body.appendChild(e);const n=e.offsetHeight+"px";return e.remove(),n}}n.u=null,n.Z=new class{constructor(){this.tt=new Map,this.it=new Map}on(t,i,s={}){const e=s.st??50,n=s.once??!1;this.tt.has(t)||this.tt.set(t,[]),this.tt.get(t).push({et:i,timeout:e,once:n})}off(t){const i=this.it.get(t);if(i){for(const t of i.values())clearTimeout(t);i.clear(),this.it.delete(t)}this.tt.delete(t)}run(t,...i){const s=this.tt.get(t);if(!s)return;this.it.has(t)||this.it.set(t,new Map);const e=this.it.get(t);for(let n=0;n<s.length;n++){const t=s[n];if(!t)continue;const h=e.get(n);h&&clearTimeout(h);const o=setTimeout(()=>{if(t.et(i.length>0?i:null),t.once){s[n]=void 0;const t=e.get(n);t&&clearTimeout(t),e.delete(n)}},t.timeout);e.set(n,o)}}clear(t){if(void 0===t)for(const i of Array.from(this.tt.keys()))this.off(i);else this.off(t)}};class h{static nt(){const t={isContinue:!0,isCancel:!1};return{token:{get isContinue(){return t.isContinue},get isCancel(){return t.isCancel}},et:{stopPropagation(){t.isContinue=!1},cancel(){t.isCancel=!0,t.isContinue=!1}}}}static ht(t,...i){const{token:s,et:e}=this.nt();for(let n=0;n<i.length;n++){const h=i[n];if("function"==typeof h&&(t&&Array.isArray(t)?h(e,...t):h(e),s.isCancel||!s.isContinue))break}return s}static ot(t,i,s={bubbles:!0,cancelable:!0}){const e=new Event(i,s);return t.dispatchEvent(e),e}static rt(t,...i){if(Array.isArray(t))for(const s of t)"function"==typeof s&&s(...i)}}class o{static lt(t,i){const s=n.R(t);if(!s?.options)return;const e=s.options,h=e.minWidth,o=e.minHeight,r=Number.parseInt(e.width,10),l=Number.parseInt(e.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=e.width),l>0&&(c=e.height),Object.assign(i.style,{width:a,height:c,minWidth:h,minHeight:o})}}class r{constructor(t){this.node=null,this.ct=null,t&&this.init(t)}init(t){this.node=n.O({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=n.W(t);this.node.innerHTML=this.ct.allowHtml?s:n.q(s)}}class l{constructor(){this.node=this.ut()}ut(){return n.O({node:"div",classList:"selective-ui-directive",role:"button",ariaLabel:"Toggle dropdown"})}dt(t){this.node.classList.toggle("drop-down",!!t)}}class a{constructor(t=null){this.gt=null,this.node=null,this.options=null,this.ft=[],this.bt=[],t&&this.init(t)}init(t){this.gt=n.$({wt:{tag:{node:"div",classList:["selective-ui-option-handle","hide"]},j:{yt:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textSelectAll,onclick:()=>{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&&n.V(this.options.multiple)&&n.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)}Ot(t=null){"function"==typeof t&&this.bt.push(t)}}class c{constructor(t=null){this.node=null,this.options=null,t&&this.init(t)}init(t){this.options=t,this.node=n.O({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 u{constructor(t=null){this.node=null,this.options=null,t&&this.init(t)}init(t){this.options=t,this.node=n.O({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 d{constructor(){this.Ct=!1,this.element=null,this.Tt=null,this.At=null,this.Ct=!0,this.St=this.Lt.bind(this)}Pt(t){}Lt(){const t=this.element;if(!t||"function"!=typeof t.getBoundingClientRect)return void this.Pt({width:0,height:0,top:0,left:0,padding:{top:0,right:0,bottom:0,left:0},border:{top:0,right:0,bottom:0,left:0},margin:{top:0,right:0,bottom:0,left:0}});const i=t.getBoundingClientRect(),s="undefined"!=typeof window&&"function"==typeof window.getComputedStyle?window.getComputedStyle(t):null;this.Pt({width:i?.width??0,height:i?.height??0,top:i?.top??0,left:i?.left??0,padding:{top:parseFloat(s?.paddingTop??"0"),right:parseFloat(s?.paddingRight??"0"),bottom:parseFloat(s?.paddingBottom??"0"),left:parseFloat(s?.paddingLeft??"0")},border:{top:parseFloat(s?.borderTopWidth??"0"),right:parseFloat(s?.borderRightWidth??"0"),bottom:parseFloat(s?.borderBottomWidth??"0"),left:parseFloat(s?.borderLeftWidth??"0")},margin:{top:parseFloat(s?.marginTop??"0"),right:parseFloat(s?.marginRight??"0"),bottom:parseFloat(s?.marginBottom??"0"),left:parseFloat(s?.marginLeft??"0")}})}ot(){this.Lt()}connect(t){if(!(t instanceof Element))throw Error("Invalid element");this.element=t,this.Tt=new ResizeObserver(this.St),this.Tt.observe(t),this.At=new MutationObserver(this.St),this.At.observe(t,{attributes:!0,attributeFilter:["style","class"]}),window.addEventListener("scroll",this.St,!0),window.addEventListener("resize",this.St),window.visualViewport&&(window.visualViewport.addEventListener("resize",this.St),window.visualViewport.addEventListener("scroll",this.St))}disconnect(){this.Tt?.disconnect(),this.At?.disconnect(),this.Pt=()=>{},window.removeEventListener("scroll",this.St,!0),window.removeEventListener("resize",this.St),window.visualViewport&&(window.visualViewport.removeEventListener("resize",this.St),window.visualViewport.removeEventListener("scroll",this.St)),this.Tt=null,this.At=null,this.element=null}}class p{constructor(t=null,i=null,s=null){this.options=null,this.Mt=!1,this.Ht=null,this.node=null,this.$t=null,this.jt=null,this.Et=null,this.Ft=null,this.It=null,this.Vt=null,this.kt=null,this.Rt=null,this._t=null,this.Dt=null,this.Nt=s,t&&i&&this.init(t,i)}init(t,i){if(!this.Nt)throw Error("Popup requires a ModelManager instance.");this.Ft=new a(i),this.It=new c(i),this.Vt=new u(i);const s=n.$({Bt:{tag:{node:"div",classList:"selective-ui-popup",style:{maxHeight:i.panelHeight}},j:{wt:{tag:this.Ft.node},zt:{tag:{id:i.Gt,node:"div",classList:"selective-ui-options-container",role:"listbox"}},Ut:{tag:this.Vt.node},Wt:{tag:this.It.node}}}},null);this.node=s.view,this.Rt=s.tags.zt,this.Et=n.R(t),this.options=i,this.Nt.load(this.Rt,{isMultiple:i.multiple});const e=this.Nt.qt();this.Ht=e.Jt,this.kt=e.kt,this.Ft.xt(()=>{e.Jt.Kt(!0)}),this.Ft.Ot(()=>{e.Jt.Kt(!1)}),this.Qt()}async Yt(){this.options&&this.Vt&&this.Ft&&this.Ht&&this.Nt&&(this.Dt&&clearTimeout(this.Dt),this.Nt.Xt(!0),!1!==n.V(this.options.loadingfield)&&(this.Vt.show(this.Ht.ti().Zt),this.Ft.hide(),this.ii()))}async si(){this.options&&this.Vt&&this.Ht&&this.Nt&&(this.Dt&&clearTimeout(this.Dt),this.Dt=setTimeout(()=>{this.Nt?.Xt(!1),this.Vt?.hide();const t=this.Ht?.ti();this.ei(t??void 0),this.ii()},200))}Qt(){this.Ht&&(this.Ht.ni(t=>{this.ei(t)}),this.Ht.hi("items",()=>{const t=this.Ht.ti();this.ei(t),this.ii()}))}ei(t){if(!(this.Ht&&this.It&&this.Ft&&this.Rt))return;const i=t??this.Ht.ti();i.isEmpty?(this.It.show("nodata"),this.Rt.classList.add("hide"),this.Ft.hide()):i.Zt?(this.It.hide(),this.Rt.classList.remove("hide"),this.Ft.refresh()):(this.It.show("notfound"),this.Rt.classList.add("hide"),this.Ft.hide())}oi(t,i){this.Ht?.ri(t,i)}li(t,i){this.Ht?.hi(t,i)}ai(t){this.$t=t}open(t=null){if(!(this.node&&this.options&&this.Ft&&this.Et&&this.$t))return;this.Mt||(document.body.appendChild(this.node),this.Mt=!0,this.jt=new d,this.$t.ci(this.node),this.node.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()})),this.Ft.refresh(),this.ei();const i=this.ui(),{position:s,top:e,maxHeight:n,di:h}=this.pi(i);this.$t.expand({duration:this.options.animationtime,display:"flex",width:i.width,left:i.left,top:e,maxHeight:n,di:h,position:s,gi:()=>{this.jt&&this.Et&&(this.jt.Pt=()=>{const t=this.ui();this.fi(t)},this.jt.connect(this.Et.container.tags.mi),t?.())}})}close(t=null){this.Mt&&this.options&&this.jt&&this.$t&&(this.jt.disconnect(),this.$t.collapse({duration:this.options.animationtime,gi:t??void 0}))}ii(){this.Mt&&this.jt?.ot()}bi(t,i){this.node&&(this._t=async()=>{const i=t.wi();if(!i.yi)return;const s=this.node;if(s.scrollHeight-s.scrollTop-s.clientHeight<100&&!i.xi&&i.Oi){const i=await t.Ci();!i.Ti&&i.message&&console.log("Load more:",i.message)}},this.node.addEventListener("scroll",this._t))}Ai(){this.Dt&&(clearTimeout(this.Dt),this.Dt=null),this.node&&this._t&&(this.node.removeEventListener("scroll",this._t),this._t=null);try{this.jt?.disconnect()}catch(t){}this.jt=null;try{this.$t?.ci?.(null)}catch(t){}if(this.$t=null,this.node)try{const t=this.node.cloneNode(!0);this.node.replaceWith(t),t.remove()}catch(t){this.node.remove()}this.node=null,this.Rt=null;try{this.Nt?.Xt?.(!1),this.kt?.clear?.(),this.kt=null,this.Ht=null,this.node.remove()}catch(t){}this.Nt=null,this.Ft=null,this.It=null,this.Vt=null,this.Et=null,this.options=null,this.Mt=!1}ui(){const t=this.Et.container.tags.mi,i=t.getBoundingClientRect(),s=window.getComputedStyle(t),e=window.visualViewport,h=n.Y();return{width:i.width,height:i.height,top:i.top-(e&&h?e.offsetTop:0),left:i.left-(e&&h?e.offsetLeft:0),padding:{top:parseFloat(s.paddingTop),right:parseFloat(s.paddingRight),bottom:parseFloat(s.paddingBottom),left:parseFloat(s.paddingLeft)},border:{top:parseFloat(s.borderTopWidth),right:parseFloat(s.borderRightWidth),bottom:parseFloat(s.borderBottomWidth),left:parseFloat(s.borderLeftWidth)}}}pi(t){const i=window.visualViewport,s=n.Y(),e=i?.height??window.innerHeight,h=i&&s?i.offsetTop:0,o=this.$t.Si("flex").scrollHeight,r=parseFloat(this.options?.panelHeight??"220")||220,l=parseFloat(this.options?.panelMinHeight??"100")||100,a=e-(t.top+t.height)-3,c=t.top-3;let u="bottom",d=r,p=Math.min(o,d);const g=a-15;return(p>=l?g>=l:g>=p)?(u="bottom",d=Math.min(a-15,r)):c>=Math.max(p,l)?(u="top",d=Math.min(c-15,r)):a>=c?(u="bottom",d=Math.max(a-15,l)):(u="top",d=Math.max(c-15,l)),p=Math.min(o,d),{position:u,top:"bottom"===u?t.top+t.height+3+h:t.top-p-3+h,maxHeight:d,di:p,Li:o}}fi(t){if(!this.options||!this.$t)return;const{position:i,top:s,maxHeight:e,di:n}=this.pi(t);this.$t.resize({duration:this.options.animationtime,width:t.width,left:t.left,top:s,maxHeight:e,di:n,position:i,animate:!0})}}class g{constructor(t=null){this.gt=null,this.node=null,this.Pi=null,this.Mi=null,this.options=null,this.Hi=null,this.$i=null,this.ji=null,this.options=t,t&&this.init(t)}init(t){this.gt=n.$({Ei:{tag:{node:"div",classList:["selective-ui-searchbox","hide"]},j:{Pi:{tag:{id:n.m(),node:"input",type:"search",classList:["selective-ui-searchbox-input"],placeholder:t.placeholder,role:"searchbox",S:t.Gt,M:"list"}}}}}),this.node=this.gt.view,this.Pi=this.gt.tags.Pi;let i=!1;const s=this.gt.tags.Pi;s.addEventListener("mousedown",t=>{t.stopPropagation()}),s.addEventListener("mouseup",t=>{t.stopPropagation()}),s.addEventListener("keydown",t=>{i=!1,"ArrowDown"===t.key||"Tab"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.Hi?.(1)):"ArrowUp"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.Hi?.(-1)):"Enter"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.$i?.()):"Escape"===t.key&&(t.preventDefault(),t.stopPropagation(),i=!0,this.ji?.())}),s.addEventListener("input",()=>{i||this.Mi?.(s.value,!0)})}show(){this.node&&this.Pi&&this.options&&(this.node.classList.remove("hide"),this.Pi.readOnly=!this.options.searchable,this.options.searchable&&requestAnimationFrame(()=>{this.Pi?.focus()}))}hide(){this.node&&this.node.classList.add("hide")}clear(t=!0){this.gt&&(this.gt.tags.Pi.value="",this.Mi?.("",t))}Fi(t){this.Pi&&(this.Pi.placeholder=n.q(t))}Ii(t){this.Pi&&this.Pi.setAttribute("aria-activedescendant",t)}}class f{constructor(t=null){this.Vi=null,this.ki=null,this.Ri=!1,t&&this.ci(t)}ci(t){if("string"==typeof t){const i=document.querySelector(t);return void(i instanceof HTMLElement&&(this.element=i))}this.element=t}cancel(){return this.Vi&&(clearTimeout(this.Vi),this.Vi=null),this.ki&&(clearTimeout(this.ki),this.ki=null),this.Ri=!1,this}Si(t="flex"){if(!this.element)return{width:0,height:0,scrollHeight:0};const i={display:this.element.style.display,visibility:this.element.style.visibility,position:this.element.style.position,height:this.element.style.height,width:this.element.style.width};Object.assign(this.element.style,{display:t,visibility:"hidden",position:"fixed",height:"fit-content",width:"fit-content"});const s=window.getComputedStyle(this.element),e=parseFloat(s.borderTopWidth),n=parseFloat(s.borderBottomWidth),h=this.element.scrollHeight+e+n,o=this.element.getBoundingClientRect(),r={width:o.width,height:o.height+e+n,scrollHeight:h};return Object.assign(this.element.style,i),r}expand(t){if(!this.element)return this;this.cancel(),this.Ri=!0;const{duration:i=200,display:s="flex",width:e,left:n,top:h,maxHeight:o,di:r,position:l="bottom",gi:a}=t;return Object.assign(this.element.style,{display:s,width:e+"px",left:n+"px",top:("bottom"===l?h:h+r)+"px",maxHeight:o+"px",height:"0px",opacity:"0",overflow:"hidden",transition:"none"}),this.element.classList.toggle("position-top","top"===l),this.element.classList.toggle("position-bottom","bottom"===l),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`top ${i}ms, height ${i}ms, opacity ${i}ms`,top:h+"px",height:r+"px",opacity:"1",overflow:r>=o?"auto":"hidden"}),this.Vi=setTimeout(()=>{this.element.style.transition="none",this.Ri=!1,a?.()},i)}),this}collapse(t){if(!this.element)return this;this.cancel(),this.Ri=!0;const{duration:i=200,gi:s}=t,e=this.element.offsetHeight,n=this.element.offsetTop,h=this.element.classList.contains("position-top")?"top":"bottom",o=this.element.scrollHeight-this.element.offsetHeight>0,r="top"===h?n+e:n;return requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`height ${i}ms, top ${i}ms, opacity ${i}ms`,height:"0px",top:r+"px",opacity:"0",overflow:o?"auto":"hidden"}),this.Vi=setTimeout(()=>{Object.assign(this.element.style,{display:"none",transition:"none"}),this.Ri=!1,s?.()},i)}),this}showSwipeWidth(t){if(!this.element)return this;this.cancel(),this.Ri=!0;const{duration:i=200,display:s="block",gi:e}=t;Object.assign(this.element.style,{transition:"none",display:s,width:"fit-content"});const n=this.Si(s).width;return Object.assign(this.element.style,{width:"0px"}),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`width ${i}ms`,width:n+"px",overflow:"hidden"})}),this.Vi=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:""}),this.Ri=!1,e?.()},i),this}hideSwipeWidth(t){if(!this.element)return this;this.cancel(),this.Ri=!0;const{duration:i=200,gi:s}=t,e=this.Si().width;return Object.assign(this.element.style,{transition:"none",width:e+"px"}),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`width ${i}ms`,width:"0px",overflow:"hidden"})}),this.Vi=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:"",display:""}),this.Ri=!1,s?.()},i),this}resize(t){if(!this.element)return this;this.ki&&clearTimeout(this.ki);const{duration:i=200,width:s,left:e,top:n,maxHeight:h,di:o,position:r="bottom",animate:l=!0,gi:a}=t,c=(this.element.classList.contains("position-top")?"top":"bottom")!==r,u=this.element.scrollHeight>h;return this.element.classList.toggle("position-top","top"===r),this.element.classList.toggle("position-bottom","bottom"===r),c&&(this.element.style.transition=`top ${i}ms ease-out, height ${i}ms ease-out, max-height ${i}ms ease-out;`),requestAnimationFrame(()=>{const t={width:s+"px",left:e+"px",top:n+"px",maxHeight:h+"px",height:o+"px",overflowY:u?"auto":"hidden"},r=Math.abs(this.element.offsetHeight-o);l&&(c||r>5)?t.transition=`height ${i}ms, top ${i}ms`:this.ki=setTimeout(()=>{this.element?.style&&(this.element.style.transition="none")},i),Object.assign(this.element.style,t),l&&(c||r>1)?this.ki=setTimeout(()=>{this.element.style.transition="none",c&&delete this.element.style.transition,a?.()},i):(c&&delete this.element.style.transition,a?.())}),this}get _i(){return this.Ri}}class m{get value(){return this.targetElement?.getAttribute("value")??null}constructor(t,i=null,s=null){this.targetElement=null,this.view=null,this.position=-1,this.Ct=!1,this.options=t,this.targetElement=i,this.view=s}update(t){this.targetElement=t,this.Di()}Di(){}}class b extends m{constructor(t,i){super(t,i??null,null),this.label="",this.items=[],this.collapsed=!1,this.Ni=[],i&&(this.label=i.label,this.collapsed=n.V(i.dataset?.collapsed))}get value(){return this.items.map(t=>t.value)}get Bi(){return this.items.filter(t=>t.selected)}get zi(){return this.items.filter(t=>t.visible)}get Gi(){return this.zi.length>0}update(t){this.label=t.label,this.view?.Ui(this.label)}Di(){this.view&&(this.view.Ui(this.label),this.view.Wi(this.collapsed))}qi(t){this.Ni.push(t)}Ji(){this.collapsed=!this.collapsed,this.view?.Wi(this.collapsed),h.ht([this,this.collapsed],...this.Ni)}Ki(t){this.items.push(t),t.group=this}removeItem(t){const i=this.items.indexOf(t);i>-1&&(this.items.splice(i,1),t.group=null)}Qi(){this.view?.Qi()}}class w extends m{constructor(){super(...arguments),this.Yi=[],this.Xi=[],this.Zi=[],this.ts=!0,this.ss=!1,this.group=null}get es(){return this.dataset?.imgsrc||this.dataset?.image||""}get hasImage(){return!!this.es}get value(){return this.targetElement?.value??""}get selected(){return!!this.targetElement?.selected}set selected(t){this.ns=t,h.ht([this,t],...this.Yi)}get visible(){return this.ts}set visible(t){if(this.ts===t)return;this.ts=t;const i=this.view?.hs?.();i&&i.classList.toggle("hide",!t),h.ht([this,t],...this.Zi)}get ns(){return this.selected}set ns(t){const i=this.view?.view?.tags?.rs,s=this.view?.hs?.();i&&(i.checked=t),s&&this.targetElement&&(s.classList.toggle("checked",!!t),s.setAttribute("aria-selected",t?"true":"false"),this.targetElement.toggleAttribute("selected",!!t)),this.targetElement&&(this.targetElement.selected=t),h.ht([this,t],...this.Xi)}get text(){const t=n.W(this.dataset?.mask??this.targetElement?.text??"");return this.options.allowHtml?t:n.q(t)}get textContent(){return this.options.allowHtml?n.q(this.text).trim():this.text.trim()}get dataset(){return this.targetElement?.dataset??{}}get ls(){return this.ss}set ls(t){const i=!!t,s=this.view?.hs?.();this.ss!==i&&(this.ss=i),s&&s.classList.toggle("highlight",i)}cs(t){this.Yi.push(t)}us(t){this.Xi.push(t)}ni(t){this.Zi.push(t)}Di(){if(!this.view)return;const t=this.view.view.tags.ds;t&&(this.options.allowHtml?t.innerHTML=this.text:t.textContent=this.textContent);const i=this.view.view.tags.ps;i&&this.hasImage&&(i.src=this.es,i.alt=this.text),this.targetElement&&(this.ns=this.targetElement.selected)}}class y{constructor(t){this.gs=[],this.fs=null,this.bs=null,this.ws=null,this.options=null,this.options=t}ys(t){this.vs=t}xs(t){this.Os=t}Cs(t){const i=this.Ts(t),s=i!==this.ws;return s&&(this.ws=i),s}Ts(t){return t.map(t=>{if("OPTGROUP"===t.tagName){const i=t,s=Array.from(i.children).map(t=>`${t.value}:${t.text}:${t.selected}`).join("\n");return`G:${i.label}:${s}`}return`O:${t.value}:${t.text}:${t.selected}`}).join("\n\n")}As(t){this.gs=[];let i=null;return t.forEach(t=>{if("OPTGROUP"===t.tagName)i=new b(this.options,t),this.gs.push(i);else if("OPTION"===t.tagName){const s=t,e=new w(this.options,s),n=s.__parentGroup;n&&i&&n===i.targetElement?(i.Ki(e),e.group=i):(this.gs.push(e),i=null)}}),this.gs}replace(t){this.ws=null,this.As(t),this.fs&&this.fs.Ss(this.gs),this.refresh()}notify(){this.fs&&this.refresh()}load(t,i={},s={}){this.fs=new this.vs(this.gs),Object.assign(this.fs,i),this.bs=new this.Os(t),this.bs.Ls(this.fs),Object.assign(this.bs,s)}update(t){if(!this.Cs(t))return;const i=this.gs,s=[],e=new Map,n=new Map;i.forEach(t=>{t instanceof b?e.set(t.label,t):t instanceof w&&n.set(`${t.value}::${t.textContent}`,t)});let h=null,o=0;t.forEach(t=>{if("OPTGROUP"===t.tagName){const i=t,n=e.get(i.label);n?(n.label!==i.label&&n.update(i),n.position=o,n.items=[],h=n,s.push(n),e.delete(i.label)):(h=new b(this.options,i),h.position=o,s.push(h)),o++}else if("OPTION"===t.tagName){const i=t,e=`${i.value}::${i.text}`,r=n.get(e);if(r)r.update(i),r.position=o,i.__parentGroup&&h?(h.Ki(r),r.group=h):(r.group=null,s.push(r)),n.delete(e);else{const t=new w(this.options,i);t.position=o,i.__parentGroup&&h?(h.Ki(t),t.group=h):s.push(t)}o++}}),e.forEach(t=>{t.view?.hs?.()?.remove?.()}),n.forEach(t=>{t.view?.hs?.()?.remove?.()}),this.gs=s,this.fs&&this.fs.Ps(this.gs),this.onUpdated(),this.refresh()}onUpdated(){}Xt(t){this.fs&&(this.fs.Ms=t)}refresh(){this.bs&&(this.bs.refresh(),this.onUpdated())}qt(){return{Hs:this.gs,Jt:this.fs,kt:this.bs}}$s(t){this.fs?.js(t)}Es(t){this.fs?.Fs(t)}}class v{constructor(t=null){this.Is=null,this.Jt=null,this.Is=t}Vs(t){this.Is=t}Ls(t){this.Jt=t,t.ri("items",()=>{this.clear()}),t.hi("items",()=>{this.ks()}),this.ks()}clear(){this.Is&&this.Is.replaceChildren()}ks(){this.Jt&&this.Is&&this.Jt.Rs(this.Is)}refresh(){this.ks()}}class x{constructor(t=null){this.gt=null,this.node=null,this.options=null,this._s=null,this.Ds=null,this.Ns=null,t&&this.init(t)}init(t){this.gt=n.$({Bs:{tag:{node:"div",classList:["selective-ui-accessorybox","hide"],onmouseup:t=>{t.stopPropagation()}}}}),this.node=this.gt.view,this.options=t}zs(t){this._s=t,this.Ds=t.parentElement,this.Gs()}Gs(){this.Ds&&this.node&&this._s&&this.options&&this.Ds.insertBefore(this.node,"top"===this.options.accessoryStyle?this._s:this._s.nextSibling)}Us(t){this.Ns=t}Ws(t){this.node&&this.options&&(this.node.replaceChildren(),t.length>0&&this.options.multiple?(this.node.classList.remove("hide"),t.forEach(t=>{n.$({qs:{tag:{node:"div",classList:["accessory-item"]},j:{Js:{tag:{node:"span",classList:["accessory-item-button"],role:"button",ariaLabel:`${this.options.textAccessoryDeselect}${t.textContent}`,title:`${this.options.textAccessoryDeselect}${t.textContent}`,onclick:i=>{i.preventDefault(),this.Ns?.$s?.("select"),setTimeout(()=>{t.selected=!1},10)}}},Ks:{tag:{node:"span",classList:["accessory-item-content"],innerHTML:t.text}}}}},this.node)})):this.node.classList.add("hide"),h.ot(window,"resize"))}}class O{constructor(t,i){this.Qs=null,this.Ys=null,this.Xs=null,this.Zs={currentPage:0,te:1,Oi:!1,xi:!1,ie:"",yi:!1},this.se=t,this.Nt=i}ee(){return!!this.Qs}async ne(t){if(!this.Qs)return{Ti:!1,items:[],message:"Ajax not configured"};const i=Array.isArray(t)?t:[t];if(0===i.length)return{Ti:!0,items:[]};try{const t=this.Qs;let s,e;if(s="function"==typeof t.he?t.he(i):{values:i.join(","),oe:"1",..."function"==typeof t.data?t.data("",0):t.data??{}},"POST"===(t.method??"GET")){const i=new URLSearchParams;Object.keys(s).forEach(t=>i.append(t,s[t]+"")),e=await fetch(t.url,{method:"POST",body:i,headers:{"Content-Type":"application/x-www-form-urlencoded"}})}else{const i=""+new URLSearchParams(s);e=await fetch(`${t.url}?${i}`)}if(!e.ok)throw Error("HTTP error! status: "+e.status);const n=await e.json();return{Ti:!0,items:this.re(n).items}}catch(s){return console.error("Load by values error:",s),{Ti:!1,message:s?.message,items:[]}}}le(t){const i=Array.from(this.se.options).map(t=>t.value);return{ae:t.filter(t=>i.includes(t)),ce:t.filter(t=>!i.includes(t))}}ue(t){this.Qs=t}setPopup(t){this.Xs=t}wi(){return{...this.Zs}}de(){this.Zs={currentPage:0,te:1,Oi:!1,xi:!1,ie:"",yi:this.Zs.yi}}clear(){this.Zs.ie="";const{Hs:t}=this.Nt.qt(),i=[];for(const s of t)s instanceof w?i.push(s):s instanceof b&&Array.isArray(s.items)&&i.push(...s.items);i.forEach(t=>{t.visible=!0})}async search(t,i=!1){return this.Qs?this.pe(t,i):this.ge(t)}async Ci(){return this.Qs?this.Zs.xi?{Ti:!1,message:"Already loading"}:this.Zs.yi?this.Zs.Oi?(this.Zs.currentPage++,this.pe(this.Zs.ie,!0)):{Ti:!1,message:"No more data"}:{Ti:!1,message:"Pagination not enabled"}:{Ti:!1,message:"Ajax not enabled"}}async ge(t){this.fe(t)&&(this.Zs.ie=t);const i=((t??"")+"").toLowerCase(),s=n.J(i),{Hs:e}=this.Nt.qt(),h=[];for(const n of e)n instanceof w?h.push(n):n instanceof b&&Array.isArray(n.items)&&h.push(...n.items);let o=!1;return h.forEach(t=>{const e=((t.textContent??t.text??"")+"").toLowerCase(),h=n.J(e),r=""===i||e.includes(i)||h.includes(s);t.visible=r,r&&(o=!0)}),{Ti:!0,me:o,isEmpty:0===h.length}}fe(t){return t!==this.Zs.ie}async pe(t,i=!1){const s=this.Qs;this.fe(t)&&(this.de(),this.Zs.ie=t,i=!1),this.Zs.xi=!0,this.Xs?.Yt(),this.Ys?.abort(),this.Ys=new AbortController;const e=this.Zs.currentPage,n=Array.from(this.se.selectedOptions).map(t=>t.value).join(",");let h;"function"==typeof s.data?(h=s.data(t,e),h&&void 0===h.be&&(h.be=n)):h={search:t,page:e,be:n,...s.data??{}};try{let t;if("POST"===(s.method??"GET")){const i=new URLSearchParams;Object.keys(h).forEach(t=>i.append(t,h[t]+"")),t=await fetch(s.url,{method:"POST",body:i,headers:{"Content-Type":"application/x-www-form-urlencoded"},signal:this.Ys.signal})}else{const i=""+new URLSearchParams(h);t=await fetch(`${s.url}?${i}`,{signal:this.Ys.signal})}const e=await t.json(),n=this.re(e);return n.we?(this.Zs.yi=!0,this.Zs.currentPage=n.page,this.Zs.te=n.te,this.Zs.Oi=n.Oi):this.Zs.yi=!1,this.ye(n.items,!!s.keepSelected,i),this.Zs.xi=!1,this.Xs?.si(),{Ti:!0,me:n.items.length>0,isEmpty:0===n.items.length,we:n.we,Oi:n.Oi,currentPage:n.page,te:n.te}}catch(o){return this.Zs.xi=!1,this.Xs?.si(),"AbortError"===o?.name?{Ti:!1,message:"Request aborted"}:(console.error("Ajax search error:",o),{Ti:!1,message:o?.message})}}re(t){let i=[],s=!1,e=0,n=1,h=!1;return t.object&&Array.isArray(t.object)?(i=t.object,void 0!==t.page&&(s=!0,e=parseInt(t.page??0,10),n=parseInt(t.te??t.ve??1,10),h=e<n-1)):t.data&&Array.isArray(t.data)?(i=t.data,void 0!==t.page&&(s=!0,e=parseInt(t.page??0,10),n=parseInt(t.te??t.ve??1,10),h=t.Oi??e<n-1)):Array.isArray(t)?i=t:t.items&&Array.isArray(t.items)&&(i=t.items,t.xe&&(s=!0,e=parseInt(t.xe.page??0,10),n=parseInt(t.xe.te??t.xe.ve??1,10),h=t.xe.Oi??e<n-1)),{items:i.map(t=>{if(t instanceof HTMLOptionElement||t instanceof HTMLOptGroupElement)return t;if("optgroup"===t.type||t.Oe||t.group||t.label)return{type:"optgroup",label:t.label??t.name??t.title??"",data:t.data??{},options:(t.options??t.items??[]).map(t=>({value:t.value??t.id??t.key??"",text:t.text??t.label??t.name??t.title??"",selected:t.selected??!1,data:t.data??(t.imgsrc?{imgsrc:t.imgsrc}:{})}))};const i=t.data??{};return t?.imgsrc&&(i.imgsrc=t.imgsrc),{type:"option",value:t.value??t.id??t.key??"",text:t.text??t.label??t.name??t.title??"",selected:t.selected??!1,data:i}}),we:s,page:e,te:n,Oi:h}}ye(t,i,s=!1){const e=this.se;let n=[];i&&(n=Array.from(e.selectedOptions).map(t=>t.value)),s||(e.innerHTML=""),t.forEach(t=>{if("option"!==t.type&&t.type||""!==t.value||""!==t.text)if(t instanceof HTMLOptionElement||t instanceof HTMLOptGroupElement)e.appendChild(t);else if("optgroup"===t.type){const s=document.createElement("optgroup");s.label=t.label,t.data&&Object.keys(t.data).forEach(i=>{s.dataset[i]=t.data[i]+""}),Array.isArray(t.options)&&t.options.forEach(t=>{const e=document.createElement("option");e.value=t.value,e.text=t.text,t.data&&Object.keys(t.data).forEach(i=>{e.dataset[i]=t.data[i]+""}),(t.selected||i&&n.includes(e.value))&&(e.selected=!0),s.appendChild(e)}),e.appendChild(s)}else{const s=document.createElement("option");s.value=t.value,s.text=t.text,t.data&&Object.keys(t.data).forEach(i=>{s.dataset[i]=t.data[i]+""}),(t.selected||i&&n.includes(s.value))&&(s.selected=!0),e.appendChild(s)}}),e.dispatchEvent(new CustomEvent("options:changed"))}}class C{constructor(t){this.Ce=null,this.Te=null,this.Ae=50,this.se=t,this.Te=this.Se(),this.Le=new MutationObserver(()=>{this.Ce&&clearTimeout(this.Ce),this.Ce=setTimeout(()=>{this.Pe()},this.Ae)}),t.addEventListener("options:changed",()=>{this.Ce&&clearTimeout(this.Ce),this.Ce=setTimeout(()=>{this.Pe()},this.Ae)})}Se(){const t=Array.from(this.se.options);return{length:t.length,values:t.map(t=>t.value).join(","),Me:t.map(t=>t.text).join(","),selected:t.map(t=>t.selected+"").join(",")}}He(){const t=this.Se(),i=JSON.stringify(t)!==JSON.stringify(this.Te);return i&&(this.Te=t),i}Pe(){this.He()&&this.Pt(this.se)}connect(){this.Le.observe(this.se,{childList:!0,subtree:!1,attributes:!0,attributeFilter:["selected","value","disabled"]})}Pt(t){}disconnect(){this.Ce&&clearTimeout(this.Ce),this.Ce=null,this.Le.disconnect()}}class T{constructor(t){this.Ce=null,this.$e=t,this.Le=new MutationObserver(t=>{let i=!1;for(const s of t)if("attributes"===s.type&&s.attributeName?.startsWith("data-")){i=!0;break}i&&(this.Ce&&clearTimeout(this.Ce),this.Ce=setTimeout(()=>{this.Pt({...this.$e.dataset})},50))}),t.addEventListener("dataset:changed",()=>{this.Pt({...this.$e.dataset})})}connect(){this.Le.observe(this.$e,{attributes:!0,attributeOldValue:!0})}Pt(t){}disconnect(){this.Ce&&clearTimeout(this.Ce),this.Ce=null,this.Le.disconnect()}}class A{constructor(t=[]){this.items=[],this.je=n.m(12),this.Ms=!1,this.items=t,this.Ee()}Ee(){}Fe(t,i,s){const e=i;t.Ct?e?.update?.():e?.ks?.()}ri(t,i){n.Z.on(`${t}ing_${this.je}`,i,{st:1})}hi(t,i){n.Z.on(`${t}_${this.je}`,i)}Fs(t,...i){n.Z.run(`${t}_${this.je}`,...i)}js(t,...i){n.Z.run(`${t}ing_${this.je}`,...i)}Ie(t,i){return null}Ve(){return this.items.length}ke(t){this.js("items",t),this.items=t,this.Fs("items",t)}Ss(t){this.ke(t)}Rs(t){for(let i=0;i<this.Ve();i++){const s=this.items[i];let e=s.view;s.Ct||(e=this.Ie(t,s),s.view=e),this.Fe(s,e,i),s.Ct=!0}}Ps(t){}}class S{constructor(t){this.parent=null,this.view=null,this.parent=t}ks(){}update(){}hs(){if(!this.view?.view)throw Error("View is not mounted. Did you forget to set this.view?");return this.view.view}}class L extends S{constructor(){super(...arguments),this.view=null}ks(){const t=n.m(7);this.view=n.H({Re:{tag:{node:"div",classList:["selective-ui-group"],role:"group",A:`seui-${t}-header`,id:`seui-${t}-group`},j:{_e:{tag:{node:"div",classList:["selective-ui-group-header"],role:"presentation",id:`seui-${t}-header`}},De:{tag:{node:"div",classList:["selective-ui-group-items"],role:"group"}}}}}),this.parent.appendChild(this.view.view)}update(){this.Ui()}Ui(t=null){this.view&&null!==t&&(this.view.tags._e.textContent=t)}Ne(){if(!this.view)throw Error("GroupView is not rendered.");return this.view.tags.De}Qi(){if(!this.view)return;const t=Array.from(this.view.tags.De.children).filter(t=>!t.classList.contains("hide"));this.view.view.classList.toggle("hide",!(t.length>0))}Wi(t){this.view&&(this.view.view.classList.toggle("collapsed",t),this.view.tags._e.setAttribute("aria-expanded",t?"false":"true"))}}class P extends S{constructor(t){super(t),this.view=null,this.Be=null,this.ze=null,this.Ge=!1,this.Ue()}Ue(){const t=this;this.Be={isMultiple:!1,hasImage:!1,imagePosition:"right",imageWidth:"60px",imageHeight:"60px",imageBorderRadius:"4px",labelValign:"center",labelHalign:"left"},this.ze=new Proxy(this.Be,{set(i,s,e){if("string"!=typeof s)return!0;const n=s,h=i[n];return h!==e&&(i[n]=e,t.Ge&&t.We(n,e,h)),!0}})}get isMultiple(){return this.Be.isMultiple}set isMultiple(t){this.ze.isMultiple=!!t}get hasImage(){return this.Be.hasImage}set hasImage(t){this.ze.hasImage=!!t}get qe(){return this.ze}set qe(t){if(!t||!this.ze||!this.Be)return;const i={};void 0!==t.imageWidth&&t.imageWidth!==this.Be.imageWidth&&(i.imageWidth=t.imageWidth),void 0!==t.imageHeight&&t.imageHeight!==this.Be.imageHeight&&(i.imageHeight=t.imageHeight),void 0!==t.imageBorderRadius&&t.imageBorderRadius!==this.Be.imageBorderRadius&&(i.imageBorderRadius=t.imageBorderRadius),void 0!==t.imagePosition&&t.imagePosition!==this.Be.imagePosition&&(i.imagePosition=t.imagePosition),void 0!==t.labelValign&&t.labelValign!==this.Be.labelValign&&(i.labelValign=t.labelValign),void 0!==t.labelHalign&&t.labelHalign!==this.Be.labelHalign&&(i.labelHalign=t.labelHalign),Object.keys(i).length>0&&Object.assign(this.ze,i)}ks(){const t=["selective-ui-option-view"],i=n.m(7),s="option_"+i;this.Be.isMultiple&&t.push("multiple"),this.Be.hasImage&&(t.push("has-image"),t.push("image-"+this.Be.imagePosition));const e={rs:{tag:{node:"input",type:this.Be.isMultiple?"checkbox":"radio",classList:"allow-choice",id:s}},...this.Be.hasImage&&{ps:{tag:{node:"img",classList:"option-image",style:{width:this.Be.imageWidth,height:this.Be.imageHeight,borderRadius:this.Be.imageBorderRadius}}}},Je:{tag:{node:"label",htmlFor:s,classList:["align-vertical-"+this.Be.labelValign,"align-horizontal-"+this.Be.labelHalign]},j:{ds:{tag:{node:"div"}}}}};this.view=n.H({Ke:{tag:{node:"div",id:`seui-${i}-option`,classList:t,role:"option",ariaSelected:"false",tabIndex:"-1"},j:e}}),this.parent.appendChild(this.view.view),this.Ge=!0}We(t,i,s){const e=this.view;if(!e||!e.view)return;const n=e.view,h=e.tags?.rs,o=e.tags?.Je;switch(t){case"isMultiple":{const t=!!i;n.classList.toggle("multiple",t),h&&h.type!==(t?"checkbox":"radio")&&(h.type=t?"checkbox":"radio");break}case"hasImage":{const t=!!i;if(n.classList.toggle("has-image",t),t)n.classList.add("image-"+this.Be.imagePosition),this.Qe();else{n.className=n.className.replace(/image-(top|right|bottom|left)/g,"").trim();const t=e.tags?.ps;t&&(t.remove(),e.tags.ps=null)}break}case"imagePosition":this.Be.hasImage&&(n.className=n.className.replace(/image-(top|right|bottom|left)/g,"").trim(),n.classList.add("image-"+i));break;case"imageWidth":case"imageHeight":case"imageBorderRadius":{const s=e.tags?.ps;if(s){const e="imageWidth"===t?"width":"imageHeight"===t?"height":"borderRadius",n=i+"";s.style[e]!==n&&(s.style[e]=n)}break}case"labelValign":case"labelHalign":if(o){const t=`align-vertical-${this.Be.labelValign} align-horizontal-${this.Be.labelHalign}`;o.className!==t&&(o.className=t)}}}Qe(){const t=this.view;if(!t||!t.view)return;const i=t.tags?.ps;if(i)return;const s=t.view,e=t.tags?.Je,n=document.createElement("img");n.className="option-image",n.style.width=this.Be.imageWidth,n.style.height=this.Be.imageHeight,n.style.borderRadius=this.Be.imageBorderRadius,e&&e.parentElement?s.insertBefore(n,e):s.appendChild(n),t.tags.ps=n}}class M extends A{constructor(t=[]){super(t),this.isMultiple=!1,this.Ye=[],this.Xe=-1,this.Ze=null,this.groups=[],this.tn=[],this.sn()}sn(){this.tn=[],this.groups=[],this.items.forEach(t=>{t instanceof b?(this.groups.push(t),this.tn.push(...t.items)):t instanceof w&&this.tn.push(t)})}Ie(t,i){return i instanceof b?new L(t):new P(t)}Fe(t,i,s){t.position=s,t instanceof b?this.en(t,i,s):t instanceof w&&this.nn(t,i,s),t.Ct=!0}en(t,i,s){super.Fe(t,i,s),t.view=i;const e=i.view.tags._e;e.textContent=t.label,t.Ct||(e.style.cursor="pointer",e.addEventListener("click",()=>{t.Ji()}),t.qi((t,i,s)=>{i.items.forEach(t=>{const i=t.view?.hs?.();i&&(i.style.display=s?"none":"")}),this.hn(i,s)}));const n=i.Ne();t.items.forEach((t,i)=>{let s=t.view;t.Ct&&s||(s=new P(n)),this.nn(t,s,i),t.Ct=!0}),i.Wi(t.collapsed),i.Qi()}nn(t,i,s){if(i.isMultiple=this.isMultiple,i.hasImage=t.hasImage,i.qe={imageWidth:t.options.imageWidth,imageHeight:t.options.imageHeight,imageBorderRadius:t.options.imageBorderRadius,imagePosition:t.options.imagePosition,labelValign:t.options.labelValign,labelHalign:t.options.labelHalign},t.Ct||super.Fe(t,i,s),t.view=i,t.hasImage){const s=i.view.tags.ps;s&&(s.src!==t.es&&(s.src=t.es),s.alt!==t.text&&(s.alt=t.text))}i.view.tags.ds.innerHTML=t.text,t.Ct||(i.view.tags.Ke.addEventListener("click",i=>{i.stopPropagation(),i.preventDefault(),this.Ms||(this.isMultiple?(this.js("select"),setTimeout(()=>{t.selected=!t.selected},5)):!0!==t.selected&&(this.js("select"),setTimeout(()=>{this.Ze&&(this.Ze.selected=!1),t.selected=!0},5)))}),i.view.tags.Ke.title=t.textContent,i.view.tags.Ke.addEventListener("mouseenter",()=>{this.Ms||this.rn(this.tn.indexOf(t),!1)}),t.cs(()=>{this.Fs("selected")}),t.us((i,s,e)=>{e&&(this.Ze=t),this.Fs("selected_internal")}),t.ni((t,i)=>{i.group?.Qi(),this.ln()})),t.selected&&(this.Ze=t,t.ns=!0)}ke(t){this.js("items",t),this.items=t,this.sn(),this.Fs("items",t)}Ss(t){this.ke(t)}Ps(t){this.items=t,this.sn()}an(){return this.tn.filter(t=>t.selected)}cn(){return this.tn.find(t=>t.selected)}Kt(t){this.isMultiple&&this.tn.forEach(i=>{i.selected=t})}ni(t){this.Ye.push(t)}ln(){const t=this.tn.filter(t=>t.visible).length,i=this.tn.length;this.Ye.forEach(s=>{s({un:t,dn:i,Zt:t>0,isEmpty:0===i})})}ti(){const t=this.tn.filter(t=>t.visible).length,i=this.tn.length;return{un:t,dn:i,Zt:t>0,isEmpty:0===i}}pn(){this.rn(0)}navigate(t,i=!0){const s=this.tn.filter(t=>t.visible);if(0===s.length)return;let e=s.findIndex(t=>t===this.tn[this.Xe]);-1===e&&(e=-1);let n=e+t;n>=s.length&&(n=0),n<0&&(n=s.length-1);const h=this.tn.indexOf(s[n]);this.rn(h,i)}gn(){if(this.Xe>-1&&this.tn[this.Xe]){const t=this.tn[this.Xe];if(t.visible){const i=t.view?.hs?.();i&&i.click()}}}rn(t,i=!0){let s=0;if("number"==typeof t)s=t;else if(t instanceof w){const i=this.tn.indexOf(t);s=i>-1?i:0}else s=0;this.Xe>-1&&this.tn[this.Xe]&&(this.tn[this.Xe].ls=!1);for(let e=s;e<this.tn.length;e++){const t=this.tn[e];if(t.visible){if(t.ls=!0,this.Xe=e,i){const i=t.view?.hs?.();i&&i.scrollIntoView({fn:"center",behavior:"smooth"})}return void this.mn(e,t.view?.hs?.()?.id)}}}mn(t,i){}hn(t,i){}}class H{constructor(t=null,i=null){this.container={},this.oldValue=null,this.node=null,this.options=null,this.bn=null,this.isOpen=!1,this.wn=!1,this.yn=!1,this.vn=null,t&&this.init(t,i)}get isDisabled(){return!!this.options?.disabled}set isDisabled(t){this.options&&this.node&&(this.options.disabled=t,this.node.classList.toggle("disabled",t),this.node.setAttribute("aria-disabled",t+""),this.container.tags?.mi?.setAttribute("aria-disabled",t+""))}get xn(){return!!this.options?.readonly}set xn(t){this.options&&this.node&&(this.options.readonly=t,this.node.classList.toggle("readonly",t))}get isVisible(){return!!this.options?.visible}set isVisible(t){this.options&&this.node&&(this.options.visible=t,this.node.classList.toggle("invisible",!t))}init(t,s){const e=n.R(t).options,h=new r(e),a=new l,c=new g(e),effector=i(),u=new y(e),d=new x(e),f=new O(t,u),m=new C(t),b=new T(t);this.vn=s,this.options=e,h.node&&(h.node.id=(e.On??"")+"");const w=n.$({Cn:{tag:{node:"div",classList:"selective-ui-MAIN"},j:{mi:{tag:{node:"div",classList:"selective-ui-view",tabIndex:0,onkeydown:t=>{"Enter"!==t.key&&" "!==t.key&&"ArrowDown"!==t.key||(t.preventDefault(),this.Tn()?.open())}},j:{An:{tag:h.node},Sn:{tag:a.node},Ei:{tag:c.node}}}}}},null);this.container=w,this.node=w.view,t.parentNode?.insertBefore(this.node,t),this.node.insertBefore(t,w.tags.mi),d.zs(w.tags.mi),d.Us(u),w.tags.mi.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()}),o.lt(t,w.tags.mi),t.classList.add("init"),u.ys(M),u.xs(v),u.As(n.K(t)),u.onUpdated=()=>{w.Ln?.ii?.()},this.bn=u,w.Pn=f,w.placeholder=h,w.Mn=a,w.Hn=c,w.effector=effector,w.targetElement=t,w.$n=d,w.jn=m,w.En=b,w.Ln=new p(t,e,u),w.Ln.ai(effector),w.Ln.bi(f,e),w.Ln.li("selected",()=>{this.Tn()?.change(null,!0)}),w.Ln.li("selected_internal",()=>{this.Tn()?.change(null,!1)}),w.Ln.oi("select",()=>{this.oldValue=this.Tn()?.value??""}),this.Tn()?.change(null,!1),m.connect(),m.Pt=t=>{u.update(n.K(t)),this.Tn()?.refreshMask()},b.connect(),b.Pt=t=>{n.V(t.disabled)!==this.isDisabled&&(this.isDisabled=n.V(t.disabled)),n.V(t.readonly)!==this.xn&&(this.xn=n.V(t.readonly)),n.V(t.visible)!==this.isVisible&&(this.isVisible=n.V(t.visible??"1"))},t.addEventListener("options:changed",()=>{u.update(n.K(t)),this.Tn()?.refreshMask(),w.Ln?.ii?.()}),e.ajax&&f.ue(e.ajax);const A=w.Ln.Ht,S=(t,i)=>{i||""!==t?(""!==t&&(this.yn=!0),f.search(t).then(t=>{w.Ln?.ii?.(),t?.me&&setTimeout(()=>{A.pn()},e.animationtime??0)}).catch(t=>{console.error("Search error:",t)})):f.clear()};let L=null;c.Mi=(t,i)=>{f.fe(t)&&(f.ee()?(L&&clearTimeout(L),w.Ln?.Yt?.(),L=setTimeout(()=>{S(t,i)},e.delaysearchtime??0)):S(t,i))},f.setPopup(w.Ln),c.Hi=t=>{A.navigate(t)},c.$i=()=>{A.gn()},c.ji=()=>{this.Tn()?.close(),w.tags.mi.focus()},A.mn=(t,i)=>{i&&c.Ii(i)},A.hn=()=>{w.Ln?.ii?.()},this.isDisabled=n.V(e.disabled),this.xn=n.V(e.readonly)}Fn(){const t=this.container??{},{jn:i,En:s}=t;i?.disconnect&&i.disconnect(),s?.disconnect&&s.disconnect()}Tn(){const t=this.container,i=this,s=n.R(t.targetElement);if(!s)return null;const e=s.options,o={get placeholder(){return t.placeholder.get()},set placeholder(i){t.placeholder?.set(i),t.Hn?.Fi(i)},get oldValue(){return i.oldValue},set value(t){this.setValue(null,t,!0)},get value(){const t=this.valueArray,i=t.length;return i>1?t:0===i?"":t[0]},get valueArray(){const t=[];return i.In().forEach(i=>{i.selected&&t.push(i.value)}),t},get valueString(){return this.valueArray.join(e.customDelimiter)},get valueOptions(){const t=[];return i.In().forEach(i=>{i.selected&&t.push(i)}),t},get mask(){const t=[];return i.In().forEach(i=>{i.selected&&t.push(i.text)}),t},get valueText(){const t=[];i.In().forEach(i=>{i.selected&&t.push(i.text)});const s=t.length;return s>1?t:0===s?"":t[0]},get isOpen(){return i.isOpen},selectAll(t,s=!0){if(!(e.multiple&&e.maxSelected>0&&i.In().length>e.maxSelected)&&!this.disabled&&!this.readonly&&e.multiple){if(s){if(h.ht([this],...e.on.beforeChange).isCancel)return;i.oldValue=this.value}i.In().forEach(t=>{t.ns=!0}),this.change(!1,s)}},deSelectAll(t,s=!0){if(!this.disabled&&!this.readonly&&e.multiple){if(s){if(h.ht([this],...e.on.beforeChange).isCancel)return;i.oldValue=this.value}i.In().forEach(t=>{t.ns=!1}),this.change(!1,s)}},setValue(s=null,n,o=!0,r=!1){if(Array.isArray(n)||(n=[n]),0===(n=n.filter(t=>""!==t&&null!=t)).length)return i.In().forEach(t=>t.ns=!1),void this.change(!1,o);if(e.multiple&&e.maxSelected>0&&n.length>e.maxSelected)console.warn(`Cannot select more than ${e.maxSelected} items`);else if(r||!this.disabled&&!this.readonly){if(t.Pn?.ee?.()){const{ce:s}=t.Pn.le(n);if(s.length>0)return void(async()=>{e.loadingfield&&t.Ln?.Yt?.();try{const e=await t.Pn.ne(s);e.Ti&&e.items.length>0?(e.items.forEach(t=>{s.includes(t.value)&&(t.selected=!0)}),t.Pn.ye?.(e.items,!0,!0),setTimeout(()=>{i.In().forEach(t=>{t.ns=n.some(i=>i==t.value)}),this.change(!1,!1)},100)):s.length>0&&console.warn(`Could not load ${s.length} values:`,s)}catch(h){console.error("Error loading missing values:",h)}finally{e.loadingfield&&t.Ln?.si?.()}})()}if(o){if(h.ht([this],...e.on.beforeChange).isCancel)return;i.oldValue=this.value}i.In().forEach(t=>{t.ns=n.some(i=>i==t.value)}),!e.multiple&&n.length>0&&(t.targetElement.value=n[0]),this.change(!1,o)}},open(){if(i.isOpen)return!1;const s=i.vn?.find?.();if(s&&!s.isEmpty&&s.close().isCancel)return!1;if(this.disabled)return!1;if(h.ht([this],...e.on.beforeShow).isCancel)return!1;i.isOpen=!0,t.Mn.dt(!0);const n=t.Ln.Ht,o=n.cn();o?n.rn(o,!1):n.pn(),i.wn&&!i.yn||!e?.ajax||(t.Ln.Yt(),i.wn=!0,i.yn=!1,setTimeout(()=>{t.Ln&&t.Pn&&t.Pn.search("").then(()=>t.Ln?.ii?.()).catch(t=>console.error("Initial ajax load error:",t))},e.animationtime)),t.Ln.open(),t.Hn.show();const r=t.tags.mi;return r.setAttribute("aria-expanded","true"),r.setAttribute("aria-controls",e.Gt),r.setAttribute("aria-haspopup","listbox"),r.setAttribute("aria-labelledby",e.On),e.multiple&&r.setAttribute("aria-multiselectable","true"),h.ht([this],...e.on.show),!0},close(){return!!i.isOpen&&!h.ht([this],...e.on.beforeClose).isCancel&&(i.isOpen=!1,t.Mn.dt(!1),t.Ln.close(()=>{t.Hn.clear(!1)}),t.Hn.hide(),t.tags.mi.setAttribute("aria-expanded","false"),h.ht([this],...e.on.close),!0)},toggle(){i.isOpen?this.close():this.open()},change(s=null,n=!0){if(n){if(e.multiple&&e.maxSelected>0&&this.valueArray.length>e.maxSelected&&this.setValue(null,this.oldValue,!1,!0),this.disabled||this.readonly)return void this.setValue(null,this.oldValue,!1,!0);if(h.ht([this,this.value],...e.on.beforeChange).isCancel)return void this.setValue(null,this.oldValue,!1)}this.refreshMask(),t.$n.Ws(this.valueOptions),n&&(t.targetElement&&h.ot(t.targetElement,"change"),h.ht([this,this.value],...e.on.change),i.options?.autoclose&&this.close())},refreshMask(){let s=e.placeholder;!e.multiple&&i.In().length>0&&(s=this.mask[0]),s??(s=e.placeholder),t.placeholder.set(s,!1),t.Hn.Fi(s)},on(t,i,s){e.on[i]||(e.on[i]=[]),e.on[i].push(s)},ajax(i,s){t.Pn.ue(s)}};return this.Vn(o,"disabled","isDisabled"),this.Vn(o,"readonly","isReadOnly"),this.Vn(o,"visible","isVisible"),o}Vn(t,i,s){const e=this;Object.defineProperty(t,i,{get:()=>e[s],set(t){e[s]=!!t,e.container?.targetElement?.dataset&&(e.container.targetElement.dataset[i]=!!t+"")},enumerable:!0,configurable:!0})}In(t=null){if(!this.bn)return[];const{Hs:i}=this.bn.qt(),s=[];for(const e of i)e instanceof w?s.push(e):e instanceof b&&Array.isArray(e.items)&&e.items.length&&s.push(...e.items);return"boolean"==typeof t?s.filter(i=>i.selected===t):s}Ai(){this.container.Ln.Ai()}}class ${constructor(){this.kn=!1,this.Le=null,this.Rn=[]}_n(t){this.Rn.push(t)}Dn(){this.Rn=[]}start(t){if(this.kn)return;this.kn=!0;const i=t.toUpperCase(),s=t.toLowerCase();this.Le=new MutationObserver(t=>{for(const e of t)e.addedNodes.forEach(t=>{if(1!==t.nodeType)return;const e=t;e.tagName===i&&this.Nn(e),e.querySelectorAll(s).forEach(t=>this.Nn(t))})}),this.Le.observe(document.body,{childList:!0,subtree:!0})}stop(){this.kn&&(this.kn=!1,this.Le?.disconnect(),this.Le=null)}Nn(t){this.Rn.forEach(i=>i(t))}}class j{static bind(t,i){const s=n.I(n.G(),i);s.on=s.on??{},s.on.load=s.on.load??[],this.Bn.set(t,s);const e=n.m();n.Z.on(e,()=>{h.ht([this.find(t)],...s.on.load),n.Z.clear(e),s.on.load=[]}),n.v(t).forEach(t=>{(async()=>{"SELECT"===t.tagName&&(n.D(t),this.zn(t,s)&&n.Z.run(e))})()}),n.U().includes(t)||n.U().push(t)}static find(t="*"){const i={isEmpty:!0};if("*"===t&&""===(t=n.U().join(", ")))return i;const s=n.v(t);if(0===s.length)return i;const e=n.R(s[0]);if(!e||!e.action)return i;const h={};for(const n in e.action)h[n]=this.Gn(n,e.action);const o={isEmpty:!1};for(const n in h){const t=h[n];switch(t.type){case"get-set":this.Un(o,t.name,s);break;case"func":this.Wn(o,t.name,s)}}return o}static qn(){this.Jn=new $,this.Jn._n(t=>{this.Bn.forEach((i,s)=>{try{t.matches(s)&&this.zn(t,i)}catch(e){console.warn("Invalid selector: "+s,e)}})}),this.Jn.start("select")}static destroy(t=null){null===t?this.Kn():"string"==typeof t?this.Qn(t):t instanceof HTMLSelectElement&&this.Yn(t)}static Kn(){n.U().forEach(t=>this.Qn(t)),this.Bn.clear(),n.U().length=0,this.Jn?.stop()}static Qn(t){n.v(t).forEach(t=>{"SELECT"===t.tagName&&this.Yn(t)}),this.Bn.delete(t);const i=n.U(),s=i.indexOf(t);s>-1&&i.splice(s,1)}static Yn(t){const i=n.R(t);if(!i)return;const s=i.container?.Ln;s?.Ai(),n.B(t,i);const e=!!this.Jn;e&&this.Jn?.stop();try{i.self?.Fn?.()}catch(o){}const h=i.container?.element??t.parentElement;t.style.display="",t.style.visibility="",t.disabled=!1,delete t.dataset.Xn,h&&h.parentNode?h.parentNode.replaceChild(t,h):document.body.appendChild(t),n.k(t),e&&this.Bn.size>0&&this.Jn?.start("select")}static rebind(t,i){this.Qn(t),this.bind(t,i)}static zn(t,i){if(n.R(t)||n.N(t))return!1;const s=n.m(8),e=n.F(t,i);e.Zn=s,e.Gt=`seui-${s}-optionlist`,e.On=`seui-${s}-placeholder`;const h={options:e};n._(t,h);const o=new H(t,this);return h.container=o.container,h.action=o.Tn(),h.self=o,o.container.view.addEventListener("mouseup",()=>{h.action?.toggle?.()}),!0}static Gn(t,i){const s=Object.getOwnPropertyDescriptor(i,t);let e="variable";return s?.get||s?.set&&"function"!=typeof i[t]?e="get-set":"function"==typeof i[t]&&(e="func"),{type:e,name:t}}static Un(t,i,s){Object.defineProperty(t,i,{get(){const t=n.R(s[0]);return t.action?.[i]},set(t){s.forEach(s=>{const e=n.R(s);e?.action&&(e.action[i]=t)})},enumerable:!0,configurable:!0})}static Wn(t,i,s){t[i]=(...e)=>{for(let t=0;t<s.length;t++){const o=n.R(s[t]);if(!o?.action)continue;const r=h.nt();if(o.action[i](r.et,...e),!r.token.isContinue)break}return t}}}j.Bn=new Map;const version="1.1.2",E="SelectiveUI",F=(t=>{if("undefined"==typeof window)return!1;const i=window[t];return i?(console.warn(`[${t}] Already loaded (v${i.version}). Using existing instance. Please remove duplicate <script> tags.`),!0):(window[t]=i??{},!1)})(E);if(!F){((t,version,i)=>{if("undefined"==typeof window)return;const s=window[t]??{};s.version=version,Object.assign(s,i),Object.freeze(s),window[t]=s,console.log(`[${t}] v${version} loaded successfully`)})(E,version,{bind,find,destroy,rebind,effector,version});let I=!1;function V(){I||(I=!0,document.addEventListener("mousedown",()=>{const t=n.U();if(t.length>0){const i=j.find(t.join(", "));i.isEmpty||i.close()}}),j.qn())}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",V):V()}t.bind=bind,t.destroy=destroy,t.effector=effector,t.find=find,t.name=E,t.rebind=rebind,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).th={});
|
|
1
|
+
/*! Selective UI v1.1.3 | MIT License */
|
|
2
|
+
var t,i;t=this,i=function(t){"use strict";function i(t){return new g(t??null)}class s{constructor(){this.t={showPanel:!0,accessoryStyle:"top",multiple:!1,minWidth:"50px",width:"0px",offsetWidth:null,minHeight:"30px",height:"30px",panelHeight:"220px",panelMinHeight:"100px",disabled:!1,readonly:!1,selectall:!0,keepSelected:!0,placeholder:"Select value",altMask:"",autoclose:!1,autoscroll:!0,autofocus:!0,searchable:!0,loadingfield:!0,visible:!0,skipError:!1,customDelimiter:",",textLoading:"Processing...",textNoData:"No data available",textNotFound:"Not found",textSelectAll:"Select all",textDeselectAll:"Deselect all",textAccessoryDeselect:"Deselect: ",animationtime:200,delaysearchtime:200,allowHtml:!0,maxSelected:0,labelHalign:"left",labelValign:"center",imageMode:!1,imageWidth:"60px",imageHeight:"60px",imageBorderRadius:"4px",imagePosition:"right",ajax:null,on:{load:[],beforeShow:[],show:[],beforeChange:[],change:[],beforeClose:[],close:[]}},this.i=new Map,this.h=new Map,this.o=[]}}class e{static get l(){return this.u||(this.u=new s),this.u}static p(t){if(null===t||"object"!=typeof t)return t;const i=Array.isArray(t)?[]:{};for(const s in t)Object.prototype.hasOwnProperty.call(t,s)&&(i[s]=this.p(t[s]));return i}static m(t=6){let i="";for(let s=0;s<t;s++)i+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random()));return i}static v(t){if(!t)return[];if("string"==typeof t){const i=document.querySelectorAll(t);return Array.from(i)}return t instanceof Element?[t]:t instanceof NodeList||Array.isArray(t)?Array.from(t):[]}static T(t={}){return this.O(document.createElement(t.node??"div"),t,!0)}static O(t=document.documentElement,i=null,s=!1){const e={...i??{}},n=s?t:this.C(t.cloneNode(!0)),h=e.classList;return"string"==typeof h?n.classList.add(h):Array.isArray(h)&&n.classList.add(...h),delete e.classList,["style","dataset"].forEach(t=>{const i=e[t];i&&"object"==typeof i&&Object.assign(n[t],i),delete e[t]}),e.role&&(n.setAttribute("role",e.role+""),delete e.role),e.ariaLive&&(n.setAttribute("aria-live",e.ariaLive+""),delete e.ariaLive),e.A&&(n.setAttribute("aria-labelledby",e.A+""),delete e.A),e.S&&(n.setAttribute("aria-controls",e.S+""),delete e.S),e.L&&(n.setAttribute("aria-haspopup",e.L+""),delete e.L),e.P&&(n.setAttribute("aria-multiselectable",e.P+""),delete e.P),e.M&&(n.setAttribute("aria-autocomplete",e.M+""),delete e.M),e.event&&"object"==typeof e.event&&(Object.entries(e.event).forEach(([t,i])=>{n.addEventListener(t,i)}),delete e.event),Object.entries(e).forEach(([t,i])=>{null===i?n.removeAttribute(t):n[t]=i}),n}static C(t){if(t instanceof Element)return t;throw new TypeError("Node is not an Element")}static H(t){return this.$(t)}static $(t,i=null,s=!1,e=!1,n={}){let h=null;for(const o in t){const r=t[o],l=r?.tag?.tagName?r.tag:this.T(r.tag);n[o]=l,r?.j&&this.$(r.j,l,!1,!1,n),i?s?i.prepend(l):i.append(l):e||h||(h=l)}return e||(n.id=this.m(7),i||(n={tags:n,view:h})),n}static F(t,i){const s=this.p(i);for(const e in s){const i=t[e];i?s[e]=i:void 0!==t?.dataset?.[e]&&(s[e]=t.dataset[e])}return s}static I(...t){if(0===t.length)return{};if(1===t.length)return this.p(t[0]);const i=this.p(t[0]);for(let s=1;s<t.length;s++){const e=t[s];for(const t in e)if("on"===t){const s=e[t];for(const e in s)i[t][e].push(s[e])}else i[t]=e[t]}return i}static V(t){if("boolean"==typeof t)return t;if("string"!=typeof t)return!!t;switch(t.trim().toLowerCase()){case"true":case"1":case"yes":case"on":return!0;default:return!1}}static k(t){return this.l.i.delete(t)}static R(t){return this.l.i.get(t)}static _(t,i){this.l.i.set(t,i)}static D(t){return this.l.h.delete(t)}static N(t){return this.l.h.get(t)}static B(t,i){this.l.h.set(t,i)}static G(){return this.l.t}static U(){return this.l.o}static W(t){if(null==t)return"";let i=(t+"").replace(/<`/g,"<").replace(/`>/g,">").replace(/\<\`/g,"<").replace(/\`\>/g,">").trim();const s=globalThis?.document;if(!s||"function"!=typeof s.createElement)return i=i.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"").replace(/<iframe\b[^>]*>[\s\S]*?<\/iframe>/gi,"").replace(/<(object|embed|link)\b[^>]*>[\s\S]*?<\/\1>/gi,""),i=i.replace(/\son[a-z]+\s*=\s*(['"]).*?\1/gi,""),i=i.replace(/\s([a-z-:]+)\s*=\s*(['"])\s*javascript:[^'"]*\2/gi,""),i;const e=s.createElement("div");return e.innerHTML=i,e.querySelectorAll("script, style, iframe, object, embed, link").forEach(t=>t.remove()),e.querySelectorAll("*").forEach(t=>{for(const i in t.attributes){const s=t.attributes[i],e=s.name??"",n=s.value??"";if(/^on/i.test(e))return void t.removeAttribute(e);/^(href|src|xlink:href)$/i.test(e)&&/^javascript:/i.test(n)&&t.removeAttribute(e)}}),(e.innerHTML??"").trim()}static q(t){const i=document.createElement("DIV");i.innerHTML=t;const s=i.textContent??i.innerText??"";return i.remove(),s.trim()}static J(t){return null==t?"":(t+"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/đ/g,"d").replace(/Đ/g,"d")}static K(t){const i=[];return Array.from(t.children).forEach(t=>{if("OPTGROUP"===t.tagName){const s=t;i.push(s),Array.from(s.children).forEach(t=>{t.__parentGroup=s,i.push(t)})}else"OPTION"===t.tagName&&i.push(t)}),i}static Y(){const t=navigator.userAgent;return/iP(hone|ad|od)/.test(t)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1}static X(t){const i=(t+"").trim();if(i.endsWith("px"))return i;if(i.endsWith("vh"))return window.innerHeight*parseFloat(i)/100+"px";if(i.endsWith("vw"))return window.innerWidth*parseFloat(i)/100+"px";const s=parseFloat(getComputedStyle(document.documentElement).fontSize);if(i.endsWith("rem"))return s*parseFloat(i)+"px";const e=this.T({node:"div",style:{height:i,opacity:"0"}});document.body.appendChild(e);const n=e.offsetHeight+"px";return e.remove(),n}}e.u=null,e.Z=new class{constructor(){this.tt=new Map,this.it=new Map}on(t,i,s={}){const e=s.st??50,n=s.once??!1;this.tt.has(t)||this.tt.set(t,[]),this.tt.get(t).push({et:i,timeout:e,once:n})}off(t){const i=this.it.get(t);if(i){for(const t of i.values())clearTimeout(t);i.clear(),this.it.delete(t)}this.tt.delete(t)}run(t,...i){const s=this.tt.get(t);if(!s)return;this.it.has(t)||this.it.set(t,new Map);const e=this.it.get(t);for(let n=0;n<s.length;n++){const t=s[n];if(!t)continue;const h=e.get(n);h&&clearTimeout(h);const o=setTimeout(()=>{if(t.et(i.length>0?i:null),t.once){s[n]=void 0;const t=e.get(n);t&&clearTimeout(t),e.delete(n)}},t.timeout);e.set(n,o)}}clear(t){if(void 0===t)for(const i of Array.from(this.tt.keys()))this.off(i);else this.off(t)}};class n{static nt(){const t={isContinue:!0,isCancel:!1};return{token:{get isContinue(){return t.isContinue},get isCancel(){return t.isCancel}},et:{stopPropagation(){t.isContinue=!1},cancel(){t.isCancel=!0,t.isContinue=!1}}}}static ht(t,...i){const{token:s,et:e}=this.nt();for(let n=0;n<i.length;n++){const h=i[n];if("function"==typeof h&&(t&&Array.isArray(t)?h(e,...t):h(e),s.isCancel||!s.isContinue))break}return s}static ot(t,i,s={bubbles:!0,cancelable:!0}){const e=new Event(i,s);return t.dispatchEvent(e),e}static rt(t,...i){if(Array.isArray(t))for(const s of t)"function"==typeof s&&s(...i)}}class h{static lt(t,i){const s=e.R(t);if(!s?.options)return;const n=s.options,h=n.minWidth,o=n.minHeight,r=Number.parseInt(n.width,10),l=Number.parseInt(n.height,10);let a=t.offsetWidth+"px",c=t.offsetHeight+"px";const u=getComputedStyle(t);"0px"===a&&"auto"!==u.width&&(a=u.width),"0px"===c&&"auto"!==u.height&&(c=u.height),r>0&&(a=n.width),l>0&&(c=n.height),Object.assign(i.style,{width:a,height:c,minWidth:h,minHeight:o})}}class o{constructor(t){this.node=null,this.ct=null,t&&this.init(t)}init(t){this.node=e.T({node:"div",classList:"selective-ui-placeholder",innerHTML:t.placeholder}),this.ct=t}get(){return this.ct?.placeholder??""}set(t,i=!0){if(!this.node||!this.ct)return;i&&(this.ct.placeholder=t);const s=e.W(t);this.node.innerHTML=this.ct.allowHtml?s:e.q(s)}}class r{constructor(){this.node=this.ut()}ut(){return e.T({node:"div",classList:"selective-ui-directive",role:"button",ariaLabel:"Toggle dropdown"})}dt(t){this.node.classList.toggle("drop-down",!!t)}}class l{constructor(t=null){this.gt=null,this.node=null,this.options=null,this.ft=[],this.bt=[],t&&this.init(t)}init(t){this.gt=e.$({wt:{tag:{node:"div",classList:["selective-ui-option-handle","hide"]},j:{yt:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textSelectAll,onclick:()=>{n.rt(this.ft)}}},vt:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textDeselectAll,onclick:()=>{n.rt(this.bt)}}}}}}),this.node=this.gt.view,this.options=t}available(){return!!this.options&&e.V(this.options.multiple)&&e.V(this.options.selectall)}refresh(){this.node&&(this.available()?this.show():this.hide())}show(){this.node&&this.node.classList.remove("hide")}hide(){this.node&&this.node.classList.add("hide")}xt(t=null){"function"==typeof t&&this.ft.push(t)}Tt(t=null){"function"==typeof t&&this.bt.push(t)}}class a{constructor(t=null){this.node=null,this.options=null,t&&this.init(t)}init(t){this.options=t,this.node=e.T({node:"div",classList:["selective-ui-empty-state","hide"],role:"status",ariaLive:"polite"})}show(t="nodata"){this.node&&this.options&&(this.node.textContent="notfound"===t?this.options.textNotFound:this.options.textNoData,this.node.classList.remove("hide"))}hide(){this.node&&this.node.classList.add("hide")}get isVisible(){return!!this.node&&!this.node.classList.contains("hide")}}class c{constructor(t=null){this.node=null,this.options=null,t&&this.init(t)}init(t){this.options=t,this.node=e.T({node:"div",classList:["selective-ui-loading-state","hide"],textContent:t.textLoading,role:"status",ariaLive:"polite"})}show(t){this.node&&this.options&&(this.node.textContent=this.options.textLoading,this.node.classList.toggle("small",!!t),this.node.classList.remove("hide"))}hide(){this.node&&this.node.classList.add("hide")}get isVisible(){return!!this.node&&!this.node.classList.contains("hide")}}class u{constructor(){this.Ot=!1,this.element=null,this.Ct=null,this.At=null,this.Ot=!0,this.St=this.Lt.bind(this)}Pt(t){}Lt(){const t=this.element;if(!t||"function"!=typeof t.getBoundingClientRect)return void this.Pt({width:0,height:0,top:0,left:0,padding:{top:0,right:0,bottom:0,left:0},border:{top:0,right:0,bottom:0,left:0},margin:{top:0,right:0,bottom:0,left:0}});const i=t.getBoundingClientRect(),s="undefined"!=typeof window&&"function"==typeof window.getComputedStyle?window.getComputedStyle(t):null;this.Pt({width:i?.width??0,height:i?.height??0,top:i?.top??0,left:i?.left??0,padding:{top:parseFloat(s?.paddingTop??"0"),right:parseFloat(s?.paddingRight??"0"),bottom:parseFloat(s?.paddingBottom??"0"),left:parseFloat(s?.paddingLeft??"0")},border:{top:parseFloat(s?.borderTopWidth??"0"),right:parseFloat(s?.borderRightWidth??"0"),bottom:parseFloat(s?.borderBottomWidth??"0"),left:parseFloat(s?.borderLeftWidth??"0")},margin:{top:parseFloat(s?.marginTop??"0"),right:parseFloat(s?.marginRight??"0"),bottom:parseFloat(s?.marginBottom??"0"),left:parseFloat(s?.marginLeft??"0")}})}ot(){this.Lt()}connect(t){if(!(t instanceof Element))throw Error("Invalid element");this.element=t,this.Ct=new ResizeObserver(this.St),this.Ct.observe(t),this.At=new MutationObserver(this.St),this.At.observe(t,{attributes:!0,attributeFilter:["style","class"]}),window.addEventListener("scroll",this.St,!0),window.addEventListener("resize",this.St),window.visualViewport&&(window.visualViewport.addEventListener("resize",this.St),window.visualViewport.addEventListener("scroll",this.St))}disconnect(){this.Ct?.disconnect(),this.At?.disconnect(),this.Pt=()=>{},window.removeEventListener("scroll",this.St,!0),window.removeEventListener("resize",this.St),window.visualViewport&&(window.visualViewport.removeEventListener("resize",this.St),window.visualViewport.removeEventListener("scroll",this.St)),this.Ct=null,this.At=null,this.element=null}}class d{constructor(t=null,i=null,s=null){this.options=null,this.Mt=!1,this.Ht=null,this.node=null,this.$t=null,this.jt=null,this.Et=null,this.Ft=null,this.It=null,this.Vt=null,this.kt=null,this.Rt=null,this._t=null,this.Dt=null,this.Nt=s,t&&i&&this.init(t,i)}init(t,i){if(!this.Nt)throw Error("Popup requires a ModelManager instance.");this.Ft=new l(i),this.It=new a(i),this.Vt=new c(i);const s=e.$({Bt:{tag:{node:"div",classList:"selective-ui-popup",style:{maxHeight:i.panelHeight}},j:{wt:{tag:this.Ft.node},zt:{tag:{id:i.Gt,node:"div",classList:"selective-ui-options-container",role:"listbox"}},Ut:{tag:this.Vt.node},Wt:{tag:this.It.node}}}},null);this.node=s.view,this.Rt=s.tags.zt,this.Et=e.R(t),this.options=i,this.Nt.load(this.Rt,{isMultiple:i.multiple});const n=this.Nt.qt();this.Ht=n.Jt,this.kt=n.kt,this.Ft.xt(()=>{n.Jt.Kt(!0)}),this.Ft.Tt(()=>{n.Jt.Kt(!1)}),this.Qt()}async Yt(){this.options&&this.Vt&&this.Ft&&this.Ht&&this.Nt&&(this.Dt&&clearTimeout(this.Dt),this.Nt.Xt(!0),!1!==e.V(this.options.loadingfield)&&(this.Vt.show(this.Ht.ti().Zt),this.Ft.hide(),this.ii()))}async si(){this.options&&this.Vt&&this.Ht&&this.Nt&&(this.Dt&&clearTimeout(this.Dt),this.Dt=setTimeout(()=>{this.Nt?.Xt(!1),this.Vt?.hide();const t=this.Ht?.ti();this.ei(t??void 0),this.ii()},200))}Qt(){this.Ht&&(this.Ht.ni(t=>{this.ei(t)}),this.Ht.hi("items",()=>{const t=this.Ht.ti();this.ei(t),this.ii()}))}ei(t){if(!(this.Ht&&this.It&&this.Ft&&this.Rt))return;const i=t??this.Ht.ti();i.isEmpty?(this.It.show("nodata"),this.Rt.classList.add("hide"),this.Ft.hide()):i.Zt?(this.It.hide(),this.Rt.classList.remove("hide"),this.Ft.refresh()):(this.It.show("notfound"),this.Rt.classList.add("hide"),this.Ft.hide())}oi(t,i){this.Ht?.ri(t,i)}li(t,i){this.Ht?.hi(t,i)}ai(t){this.$t=t}open(t=null){if(!(this.node&&this.options&&this.Ft&&this.Et&&this.$t))return;this.Mt||(document.body.appendChild(this.node),this.Mt=!0,this.jt=new u,this.$t.ci(this.node),this.node.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()})),this.Ft.refresh(),this.ei();const i=this.ui(),{position:s,top:e,maxHeight:n,di:h}=this.pi(i);this.$t.expand({duration:this.options.animationtime,display:"flex",width:i.width,left:i.left,top:e,maxHeight:n,di:h,position:s,gi:()=>{this.jt&&this.Et&&(this.jt.Pt=()=>{const t=this.ui();this.fi(t)},this.jt.connect(this.Et.container.tags.mi),t?.())}})}close(t=null){this.Mt&&this.options&&this.jt&&this.$t&&(this.jt.disconnect(),this.$t.collapse({duration:this.options.animationtime,gi:t??void 0}))}ii(){this.Mt&&this.jt?.ot()}bi(t,i){this.node&&(this._t=async()=>{const i=t.wi();if(!i.yi)return;const s=this.node;if(s.scrollHeight-s.scrollTop-s.clientHeight<100&&!i.xi&&i.Ti){const i=await t.Oi();!i.Ci&&i.message&&console.log("Load more:",i.message)}},this.node.addEventListener("scroll",this._t))}Ai(){this.Dt&&(clearTimeout(this.Dt),this.Dt=null),this.node&&this._t&&(this.node.removeEventListener("scroll",this._t),this._t=null);try{this.jt?.disconnect()}catch(t){}this.jt=null;try{this.$t?.ci?.(null)}catch(t){}if(this.$t=null,this.node)try{const t=this.node.cloneNode(!0);this.node.replaceWith(t),t.remove()}catch(t){this.node.remove()}this.node=null,this.Rt=null;try{this.Nt?.Xt?.(!1),this.kt?.clear?.(),this.kt=null,this.Ht=null,this.node.remove()}catch(t){}this.Nt=null,this.Ft=null,this.It=null,this.Vt=null,this.Et=null,this.options=null,this.Mt=!1}ui(){const t=this.Et.container.tags.mi,i=t.getBoundingClientRect(),s=window.getComputedStyle(t),n=window.visualViewport,h=e.Y();return{width:i.width,height:i.height,top:i.top-(n&&h?n.offsetTop:0),left:i.left-(n&&h?n.offsetLeft:0),padding:{top:parseFloat(s.paddingTop),right:parseFloat(s.paddingRight),bottom:parseFloat(s.paddingBottom),left:parseFloat(s.paddingLeft)},border:{top:parseFloat(s.borderTopWidth),right:parseFloat(s.borderRightWidth),bottom:parseFloat(s.borderBottomWidth),left:parseFloat(s.borderLeftWidth)}}}pi(t){const i=window.visualViewport,s=e.Y(),n=i?.height??window.innerHeight,h=i&&s?i.offsetTop:0,o=this.$t.Si("flex").scrollHeight,r=parseFloat(this.options?.panelHeight??"220")||220,l=parseFloat(this.options?.panelMinHeight??"100")||100,a=n-(t.top+t.height)-3,c=t.top-3;let u="bottom",d=r,p=Math.min(o,d);const g=a-15;return(p>=l?g>=l:g>=p)?(u="bottom",d=Math.min(a-15,r)):c>=Math.max(p,l)?(u="top",d=Math.min(c-15,r)):a>=c?(u="bottom",d=Math.max(a-15,l)):(u="top",d=Math.max(c-15,l)),p=Math.min(o,d),{position:u,top:"bottom"===u?t.top+t.height+3+h:t.top-p-3+h,maxHeight:d,di:p,Li:o}}fi(t){if(!this.options||!this.$t)return;const{position:i,top:s,maxHeight:e,di:n}=this.pi(t);this.$t.resize({duration:this.options.animationtime,width:t.width,left:t.left,top:s,maxHeight:e,di:n,position:i,animate:!0})}}class p{constructor(t=null){this.gt=null,this.node=null,this.Pi=null,this.Mi=null,this.options=null,this.Hi=null,this.$i=null,this.ji=null,this.options=t,t&&this.init(t)}init(t){this.gt=e.$({Ei:{tag:{node:"div",classList:["selective-ui-searchbox","hide"]},j:{Pi:{tag:{id:e.m(),node:"input",type:"search",classList:["selective-ui-searchbox-input"],placeholder:t.placeholder,role:"searchbox",S:t.Gt,M:"list"}}}}}),this.node=this.gt.view,this.Pi=this.gt.tags.Pi;let i=!1;const s=this.gt.tags.Pi;s.addEventListener("mousedown",t=>{t.stopPropagation()}),s.addEventListener("mouseup",t=>{t.stopPropagation()}),s.addEventListener("keydown",t=>{i=!1,"ArrowDown"===t.key||"Tab"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.Hi?.(1)):"ArrowUp"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.Hi?.(-1)):"Enter"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.$i?.()):"Escape"===t.key&&(t.preventDefault(),t.stopPropagation(),i=!0,this.ji?.())}),s.addEventListener("input",()=>{i||this.Mi?.(s.value,!0)})}show(){this.node&&this.Pi&&this.options&&(this.node.classList.remove("hide"),this.Pi.readOnly=!this.options.searchable,this.options.searchable&&requestAnimationFrame(()=>{this.Pi?.focus()}))}hide(){this.node&&this.node.classList.add("hide")}clear(t=!0){this.gt&&(this.gt.tags.Pi.value="",this.Mi?.("",t))}Fi(t){this.Pi&&(this.Pi.placeholder=e.q(t))}Ii(t){this.Pi&&this.Pi.setAttribute("aria-activedescendant",t)}}class g{constructor(t=null){this.Vi=null,this.ki=null,this.Ri=!1,t&&this.ci(t)}ci(t){if("string"==typeof t){const i=document.querySelector(t);return void(i instanceof HTMLElement&&(this.element=i))}this.element=t}cancel(){return this.Vi&&(clearTimeout(this.Vi),this.Vi=null),this.ki&&(clearTimeout(this.ki),this.ki=null),this.Ri=!1,this}Si(t="flex"){if(!this.element)return{width:0,height:0,scrollHeight:0};const i={display:this.element.style.display,visibility:this.element.style.visibility,position:this.element.style.position,height:this.element.style.height,width:this.element.style.width};Object.assign(this.element.style,{display:t,visibility:"hidden",position:"fixed",height:"fit-content",width:"fit-content"});const s=window.getComputedStyle(this.element),e=parseFloat(s.borderTopWidth),n=parseFloat(s.borderBottomWidth),h=this.element.scrollHeight+e+n,o=this.element.getBoundingClientRect(),r={width:o.width,height:o.height+e+n,scrollHeight:h};return Object.assign(this.element.style,i),r}expand(t){if(!this.element)return this;this.cancel(),this.Ri=!0;const{duration:i=200,display:s="flex",width:e,left:n,top:h,maxHeight:o,di:r,position:l="bottom",gi:a}=t;return Object.assign(this.element.style,{display:s,width:e+"px",left:n+"px",top:("bottom"===l?h:h+r)+"px",maxHeight:o+"px",height:"0px",opacity:"0",overflow:"hidden",transition:"none"}),this.element.classList.toggle("position-top","top"===l),this.element.classList.toggle("position-bottom","bottom"===l),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`top ${i}ms, height ${i}ms, opacity ${i}ms`,top:h+"px",height:r+"px",opacity:"1",overflow:r>=o?"auto":"hidden"}),this.Vi=setTimeout(()=>{this.element.style.transition="none",this.Ri=!1,a?.()},i)}),this}collapse(t){if(!this.element)return this;this.cancel(),this.Ri=!0;const{duration:i=200,gi:s}=t,e=this.element.offsetHeight,n=this.element.offsetTop,h=this.element.classList.contains("position-top")?"top":"bottom",o=this.element.scrollHeight-this.element.offsetHeight>0,r="top"===h?n+e:n;return requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`height ${i}ms, top ${i}ms, opacity ${i}ms`,height:"0px",top:r+"px",opacity:"0",overflow:o?"auto":"hidden"}),this.Vi=setTimeout(()=>{Object.assign(this.element.style,{display:"none",transition:"none"}),this.Ri=!1,s?.()},i)}),this}showSwipeWidth(t){if(!this.element)return this;this.cancel(),this.Ri=!0;const{duration:i=200,display:s="block",gi:e}=t;Object.assign(this.element.style,{transition:"none",display:s,width:"fit-content"});const n=this.Si(s).width;return Object.assign(this.element.style,{width:"0px"}),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`width ${i}ms`,width:n+"px",overflow:"hidden"})}),this.Vi=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:""}),this.Ri=!1,e?.()},i),this}hideSwipeWidth(t){if(!this.element)return this;this.cancel(),this.Ri=!0;const{duration:i=200,gi:s}=t,e=this.Si().width;return Object.assign(this.element.style,{transition:"none",width:e+"px"}),requestAnimationFrame(()=>{Object.assign(this.element.style,{transition:`width ${i}ms`,width:"0px",overflow:"hidden"})}),this.Vi=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:"",display:""}),this.Ri=!1,s?.()},i),this}resize(t){if(!this.element)return this;this.ki&&clearTimeout(this.ki);const{duration:i=200,width:s,left:e,top:n,maxHeight:h,di:o,position:r="bottom",animate:l=!0,gi:a}=t,c=(this.element.classList.contains("position-top")?"top":"bottom")!==r,u=this.element.scrollHeight>h;return this.element.classList.toggle("position-top","top"===r),this.element.classList.toggle("position-bottom","bottom"===r),c&&(this.element.style.transition=`top ${i}ms ease-out, height ${i}ms ease-out, max-height ${i}ms ease-out;`),requestAnimationFrame(()=>{const t={width:s+"px",left:e+"px",top:n+"px",maxHeight:h+"px",height:o+"px",overflowY:u?"auto":"hidden"},r=Math.abs(this.element.offsetHeight-o);l&&(c||r>5)?t.transition=`height ${i}ms, top ${i}ms`:this.ki=setTimeout(()=>{this.element?.style&&(this.element.style.transition="none")},i),Object.assign(this.element.style,t),l&&(c||r>1)?this.ki=setTimeout(()=>{this.element.style.transition="none",c&&delete this.element.style.transition,a?.()},i):(c&&delete this.element.style.transition,a?.())}),this}get _i(){return this.Ri}}class f{get value(){return this.targetElement?.getAttribute("value")??null}constructor(t,i=null,s=null){this.targetElement=null,this.view=null,this.position=-1,this.Ot=!1,this.options=t,this.targetElement=i,this.view=s}update(t){this.targetElement=t,this.Di()}Di(){}}class m extends f{constructor(t,i){super(t,i??null,null),this.label="",this.items=[],this.collapsed=!1,this.Ni=[],i&&(this.label=i.label,this.collapsed=e.V(i.dataset?.collapsed))}get value(){return this.items.map(t=>t.value)}get Bi(){return this.items.filter(t=>t.selected)}get zi(){return this.items.filter(t=>t.visible)}get Gi(){return this.zi.length>0}update(t){this.label=t.label,this.view?.Ui(this.label)}Di(){this.view&&(this.view.Ui(this.label),this.view.Wi(this.collapsed))}qi(t){this.Ni.push(t)}Ji(){this.collapsed=!this.collapsed,this.view?.Wi(this.collapsed),n.ht([this,this.collapsed],...this.Ni)}Ki(t){this.items.push(t),t.group=this}removeItem(t){const i=this.items.indexOf(t);i>-1&&(this.items.splice(i,1),t.group=null)}Qi(){this.view?.Qi()}}class b extends f{constructor(){super(...arguments),this.Yi=[],this.Xi=[],this.Zi=[],this.ts=!0,this.ss=!1,this.group=null}get es(){return this.dataset?.imgsrc||this.dataset?.image||""}get hasImage(){return!!this.es}get value(){return this.targetElement?.value??""}get selected(){return!!this.targetElement?.selected}set selected(t){this.ns=t,n.ht([this,t],...this.Yi)}get visible(){return this.ts}set visible(t){if(this.ts===t)return;this.ts=t;const i=this.view?.hs?.();i&&i.classList.toggle("hide",!t),n.ht([this,t],...this.Zi)}get ns(){return this.selected}set ns(t){const i=this.view?.view?.tags?.rs,s=this.view?.hs?.();i&&(i.checked=t),s&&this.targetElement&&(s.classList.toggle("checked",!!t),s.setAttribute("aria-selected",t?"true":"false"),this.targetElement.toggleAttribute("selected",!!t)),this.targetElement&&(this.targetElement.selected=t),n.ht([this,t],...this.Xi)}get text(){const t=e.W(this.dataset?.mask??this.targetElement?.text??"");return this.options.allowHtml?t:e.q(t)}get textContent(){return this.options.allowHtml?e.q(this.text).trim():this.text.trim()}get dataset(){return this.targetElement?.dataset??{}}get ls(){return this.ss}set ls(t){const i=!!t,s=this.view?.hs?.();this.ss!==i&&(this.ss=i),s&&s.classList.toggle("highlight",i)}cs(t){this.Yi.push(t)}us(t){this.Xi.push(t)}ni(t){this.Zi.push(t)}Di(){if(!this.view)return;const t=this.view.view.tags.ds;t&&(this.options.allowHtml?t.innerHTML=this.text:t.textContent=this.textContent);const i=this.view.view.tags.ps;i&&this.hasImage&&(i.src=this.es,i.alt=this.text),this.targetElement&&(this.ns=this.targetElement.selected)}}class w{constructor(t){this.gs=[],this.fs=null,this.bs=null,this.ws=null,this.options=null,this.options=t}ys(t){this.vs=t}xs(t){this.Ts=t}Os(t){const i=this.Cs(t),s=i!==this.ws;return s&&(this.ws=i),s}Cs(t){return t.map(t=>{if("OPTGROUP"===t.tagName){const i=t,s=Array.from(i.children).map(t=>`${t.value}:${t.text}:${t.selected}`).join("\n");return`G:${i.label}:${s}`}return`O:${t.value}:${t.text}:${t.selected}`}).join("\n\n")}As(t){this.gs=[];let i=null;return t.forEach(t=>{if("OPTGROUP"===t.tagName)i=new m(this.options,t),this.gs.push(i);else if("OPTION"===t.tagName){const s=t,e=new b(this.options,s),n=s.__parentGroup;n&&i&&n===i.targetElement?(i.Ki(e),e.group=i):(this.gs.push(e),i=null)}}),this.gs}replace(t){this.ws=null,this.As(t),this.fs&&this.fs.Ss(this.gs),this.refresh()}notify(){this.fs&&this.refresh()}load(t,i={},s={}){this.fs=new this.vs(this.gs),Object.assign(this.fs,i),this.bs=new this.Ts(t),this.bs.Ls(this.fs),Object.assign(this.bs,s)}update(t){if(!this.Os(t))return;const i=this.gs,s=[],e=new Map,n=new Map;i.forEach(t=>{t instanceof m?e.set(t.label,t):t instanceof b&&n.set(`${t.value}::${t.textContent}`,t)});let h=null,o=0;t.forEach(t=>{if("OPTGROUP"===t.tagName){const i=t,n=e.get(i.label);n?(n.label!==i.label&&n.update(i),n.position=o,n.items=[],h=n,s.push(n),e.delete(i.label)):(h=new m(this.options,i),h.position=o,s.push(h)),o++}else if("OPTION"===t.tagName){const i=t,e=`${i.value}::${i.text}`,r=n.get(e);if(r)r.update(i),r.position=o,i.__parentGroup&&h?(h.Ki(r),r.group=h):(r.group=null,s.push(r)),n.delete(e);else{const t=new b(this.options,i);t.position=o,i.__parentGroup&&h?(h.Ki(t),t.group=h):s.push(t)}o++}}),e.forEach(t=>{t.view?.hs?.()?.remove?.()}),n.forEach(t=>{t.view?.hs?.()?.remove?.()}),this.gs=s,this.fs&&this.fs.Ps(this.gs),this.onUpdated(),this.refresh()}onUpdated(){}Xt(t){this.fs&&(this.fs.Ms=t)}refresh(){this.bs&&(this.bs.refresh(),this.onUpdated())}qt(){return{Hs:this.gs,Jt:this.fs,kt:this.bs}}$s(t){this.fs?.js(t)}Es(t){this.fs?.Fs(t)}}class y{constructor(t=null){this.Is=null,this.Jt=null,this.Is=t}Vs(t){this.Is=t}Ls(t){this.Jt=t,t.ri("items",()=>{this.clear()}),t.hi("items",()=>{this.ks()}),this.ks()}clear(){this.Is&&this.Is.replaceChildren()}ks(){this.Jt&&this.Is&&this.Jt.Rs(this.Is)}refresh(){this.ks()}}class v{constructor(t=null){this.gt=null,this.node=null,this.options=null,this._s=null,this.Ds=null,this.Ns=null,t&&this.init(t)}init(t){this.gt=e.$({Bs:{tag:{node:"div",classList:["selective-ui-accessorybox","hide"],onmouseup:t=>{t.stopPropagation()}}}}),this.node=this.gt.view,this.options=t}zs(t){this._s=t,this.Ds=t.parentElement,this.Gs()}Gs(){this.Ds&&this.node&&this._s&&this.options&&this.Ds.insertBefore(this.node,"top"===this.options.accessoryStyle?this._s:this._s.nextSibling)}Us(t){this.Ns=t}Ws(t){this.node&&this.options&&(this.node.replaceChildren(),t.length>0&&this.options.multiple?(this.node.classList.remove("hide"),t.forEach(t=>{e.$({qs:{tag:{node:"div",classList:["accessory-item"]},j:{Js:{tag:{node:"span",classList:["accessory-item-button"],role:"button",ariaLabel:`${this.options.textAccessoryDeselect}${t.textContent}`,title:`${this.options.textAccessoryDeselect}${t.textContent}`,onclick:i=>{i.preventDefault(),this.Ns?.$s?.("select"),setTimeout(()=>{t.selected=!1},10)}}},Ks:{tag:{node:"span",classList:["accessory-item-content"],innerHTML:t.text}}}}},this.node)})):this.node.classList.add("hide"),n.ot(window,"resize"))}}class x{constructor(t,i){this.Qs=null,this.Ys=null,this.Xs=null,this.Zs={currentPage:0,te:1,Ti:!1,xi:!1,ie:"",yi:!1},this.se=t,this.Nt=i}ee(){return!!this.Qs}async ne(t){if(!this.Qs)return{Ci:!1,items:[],message:"Ajax not configured"};const i=Array.isArray(t)?t:[t];if(0===i.length)return{Ci:!0,items:[]};try{const t=this.Qs;let s,e;if(s="function"==typeof t.he?t.he(i):{values:i.join(","),oe:"1",..."function"==typeof t.data?t.data("",0):t.data??{}},"POST"===(t.method??"GET")){const i=new URLSearchParams;Object.keys(s).forEach(t=>i.append(t,s[t]+"")),e=await fetch(t.url,{method:"POST",body:i,headers:{"Content-Type":"application/x-www-form-urlencoded"}})}else{const i=""+new URLSearchParams(s);e=await fetch(`${t.url}?${i}`)}if(!e.ok)throw Error("HTTP error! status: "+e.status);const n=await e.json();return{Ci:!0,items:this.re(n).items}}catch(s){return console.error("Load by values error:",s),{Ci:!1,message:s?.message,items:[]}}}le(t){const i=Array.from(this.se.options).map(t=>t.value);return{ae:t.filter(t=>i.includes(t)),ce:t.filter(t=>!i.includes(t))}}ue(t){this.Qs=t}setPopup(t){this.Xs=t}wi(){return{...this.Zs}}de(){this.Zs={currentPage:0,te:1,Ti:!1,xi:!1,ie:"",yi:this.Zs.yi}}clear(){this.Zs.ie="";const{Hs:t}=this.Nt.qt(),i=[];for(const s of t)s instanceof b?i.push(s):s instanceof m&&Array.isArray(s.items)&&i.push(...s.items);i.forEach(t=>{t.visible=!0})}async search(t,i=!1){return this.Qs?this.pe(t,i):this.ge(t)}async Oi(){return this.Qs?this.Zs.xi?{Ci:!1,message:"Already loading"}:this.Zs.yi?this.Zs.Ti?(this.Zs.currentPage++,this.pe(this.Zs.ie,!0)):{Ci:!1,message:"No more data"}:{Ci:!1,message:"Pagination not enabled"}:{Ci:!1,message:"Ajax not enabled"}}async ge(t){this.fe(t)&&(this.Zs.ie=t);const i=((t??"")+"").toLowerCase(),s=e.J(i),{Hs:n}=this.Nt.qt(),h=[];for(const e of n)e instanceof b?h.push(e):e instanceof m&&Array.isArray(e.items)&&h.push(...e.items);let o=!1;return h.forEach(t=>{const n=((t.textContent??t.text??"")+"").toLowerCase(),h=e.J(n),r=""===i||n.includes(i)||h.includes(s);t.visible=r,r&&(o=!0)}),{Ci:!0,me:o,isEmpty:0===h.length}}fe(t){return t!==this.Zs.ie}async pe(t,i=!1){const s=this.Qs;this.fe(t)&&(this.de(),this.Zs.ie=t,i=!1),this.Zs.xi=!0,this.Xs?.Yt(),this.Ys?.abort(),this.Ys=new AbortController;const e=this.Zs.currentPage,n=Array.from(this.se.selectedOptions).map(t=>t.value).join(",");let h;"function"==typeof s.data?(h=s.data(t,e),h&&void 0===h.be&&(h.be=n)):h={search:t,page:e,be:n,...s.data??{}};try{let t;if("POST"===(s.method??"GET")){const i=new URLSearchParams;Object.keys(h).forEach(t=>i.append(t,h[t]+"")),t=await fetch(s.url,{method:"POST",body:i,headers:{"Content-Type":"application/x-www-form-urlencoded"},signal:this.Ys.signal})}else{const i=""+new URLSearchParams(h);t=await fetch(`${s.url}?${i}`,{signal:this.Ys.signal})}const e=await t.json(),n=this.re(e);return n.we?(this.Zs.yi=!0,this.Zs.currentPage=n.page,this.Zs.te=n.te,this.Zs.Ti=n.Ti):this.Zs.yi=!1,this.ye(n.items,!!s.keepSelected,i),this.Zs.xi=!1,this.Xs?.si(),{Ci:!0,me:n.items.length>0,isEmpty:0===n.items.length,we:n.we,Ti:n.Ti,currentPage:n.page,te:n.te}}catch(o){return this.Zs.xi=!1,this.Xs?.si(),"AbortError"===o?.name?{Ci:!1,message:"Request aborted"}:(console.error("Ajax search error:",o),{Ci:!1,message:o?.message})}}re(t){let i=[],s=!1,e=0,n=1,h=!1;return t.object&&Array.isArray(t.object)?(i=t.object,void 0!==t.page&&(s=!0,e=parseInt(t.page??0,10),n=parseInt(t.te??t.ve??1,10),h=e<n-1)):t.data&&Array.isArray(t.data)?(i=t.data,void 0!==t.page&&(s=!0,e=parseInt(t.page??0,10),n=parseInt(t.te??t.ve??1,10),h=t.Ti??e<n-1)):Array.isArray(t)?i=t:t.items&&Array.isArray(t.items)&&(i=t.items,t.xe&&(s=!0,e=parseInt(t.xe.page??0,10),n=parseInt(t.xe.te??t.xe.ve??1,10),h=t.xe.Ti??e<n-1)),{items:i.map(t=>{if(t instanceof HTMLOptionElement||t instanceof HTMLOptGroupElement)return t;if("optgroup"===t.type||t.Te||t.group||t.label)return{type:"optgroup",label:t.label??t.name??t.title??"",data:t.data??{},options:(t.options??t.items??[]).map(t=>({value:t.value??t.id??t.key??"",text:t.text??t.label??t.name??t.title??"",selected:t.selected??!1,data:t.data??(t.imgsrc?{imgsrc:t.imgsrc}:{})}))};const i=t.data??{};return t?.imgsrc&&(i.imgsrc=t.imgsrc),{type:"option",value:t.value??t.id??t.key??"",text:t.text??t.label??t.name??t.title??"",selected:t.selected??!1,data:i}}),we:s,page:e,te:n,Ti:h}}ye(t,i,s=!1){const e=this.se;let n=[];i&&(n=Array.from(e.selectedOptions).map(t=>t.value)),s||(e.innerHTML=""),t.forEach(t=>{if("option"!==t.type&&t.type||""!==t.value||""!==t.text)if(t instanceof HTMLOptionElement||t instanceof HTMLOptGroupElement)e.appendChild(t);else if("optgroup"===t.type){const s=document.createElement("optgroup");s.label=t.label,t.data&&Object.keys(t.data).forEach(i=>{s.dataset[i]=t.data[i]+""}),Array.isArray(t.options)&&t.options.forEach(t=>{const e=document.createElement("option");e.value=t.value,e.text=t.text,t.data&&Object.keys(t.data).forEach(i=>{e.dataset[i]=t.data[i]+""}),(t.selected||i&&n.includes(e.value))&&(e.selected=!0),s.appendChild(e)}),e.appendChild(s)}else{const s=document.createElement("option");s.value=t.value,s.text=t.text,t.data&&Object.keys(t.data).forEach(i=>{s.dataset[i]=t.data[i]+""}),(t.selected||i&&n.includes(s.value))&&(s.selected=!0),e.appendChild(s)}}),e.dispatchEvent(new CustomEvent("options:changed"))}}class T{constructor(t){this.Oe=null,this.Ce=null,this.Ae=50,this.se=t,this.Ce=this.Se(),this.Le=new MutationObserver(()=>{this.Oe&&clearTimeout(this.Oe),this.Oe=setTimeout(()=>{this.Pe()},this.Ae)}),t.addEventListener("options:changed",()=>{this.Oe&&clearTimeout(this.Oe),this.Oe=setTimeout(()=>{this.Pe()},this.Ae)})}Se(){const t=Array.from(this.se.options);return{length:t.length,values:t.map(t=>t.value).join(","),Me:t.map(t=>t.text).join(","),selected:t.map(t=>t.selected+"").join(",")}}He(){const t=this.Se(),i=JSON.stringify(t)!==JSON.stringify(this.Ce);return i&&(this.Ce=t),i}Pe(){this.He()&&this.Pt(this.se)}connect(){this.Le.observe(this.se,{childList:!0,subtree:!1,attributes:!0,attributeFilter:["selected","value","disabled"]})}Pt(t){}disconnect(){this.Oe&&clearTimeout(this.Oe),this.Oe=null,this.Le.disconnect()}}class O{constructor(t){this.Oe=null,this.$e=t,this.Le=new MutationObserver(t=>{let i=!1;for(const s of t)if("attributes"===s.type&&s.attributeName?.startsWith("data-")){i=!0;break}i&&(this.Oe&&clearTimeout(this.Oe),this.Oe=setTimeout(()=>{this.Pt({...this.$e.dataset})},50))}),t.addEventListener("dataset:changed",()=>{this.Pt({...this.$e.dataset})})}connect(){this.Le.observe(this.$e,{attributes:!0,attributeOldValue:!0})}Pt(t){}disconnect(){this.Oe&&clearTimeout(this.Oe),this.Oe=null,this.Le.disconnect()}}class C{constructor(t=[]){this.items=[],this.je=e.m(12),this.Ms=!1,this.items=t,this.Ee()}Ee(){}Fe(t,i,s){const e=i;t.Ot?e?.update?.():e?.ks?.()}ri(t,i){e.Z.on(`${t}ing_${this.je}`,i,{st:1})}hi(t,i){e.Z.on(`${t}_${this.je}`,i)}Fs(t,...i){e.Z.run(`${t}_${this.je}`,...i)}js(t,...i){e.Z.run(`${t}ing_${this.je}`,...i)}Ie(t,i){return null}Ve(){return this.items.length}ke(t){this.js("items",t),this.items=t,this.Fs("items",t)}Ss(t){this.ke(t)}Rs(t){for(let i=0;i<this.Ve();i++){const s=this.items[i];let e=s.view;s.Ot||(e=this.Ie(t,s),s.view=e),this.Fe(s,e,i),s.Ot=!0}}Ps(t){}}class A{constructor(t){this.parent=null,this.view=null,this.parent=t}ks(){}update(){}hs(){if(!this.view?.view)throw Error("View is not mounted. Did you forget to set this.view?");return this.view.view}}class S extends A{constructor(){super(...arguments),this.view=null}ks(){const t=e.m(7);this.view=e.H({Re:{tag:{node:"div",classList:["selective-ui-group"],role:"group",A:`seui-${t}-header`,id:`seui-${t}-group`},j:{_e:{tag:{node:"div",classList:["selective-ui-group-header"],role:"presentation",id:`seui-${t}-header`}},De:{tag:{node:"div",classList:["selective-ui-group-items"],role:"group"}}}}}),this.parent.appendChild(this.view.view)}update(){this.Ui()}Ui(t=null){this.view&&null!==t&&(this.view.tags._e.textContent=t)}Ne(){if(!this.view)throw Error("GroupView is not rendered.");return this.view.tags.De}Qi(){if(!this.view)return;const t=Array.from(this.view.tags.De.children).filter(t=>!t.classList.contains("hide"));this.view.view.classList.toggle("hide",!(t.length>0))}Wi(t){this.view&&(this.view.view.classList.toggle("collapsed",t),this.view.tags._e.setAttribute("aria-expanded",t?"false":"true"))}}class L extends A{constructor(t){super(t),this.view=null,this.Be=null,this.ze=null,this.Ge=!1,this.Ue()}Ue(){const t=this;this.Be={isMultiple:!1,hasImage:!1,imagePosition:"right",imageWidth:"60px",imageHeight:"60px",imageBorderRadius:"4px",labelValign:"center",labelHalign:"left"},this.ze=new Proxy(this.Be,{set(i,s,e){if("string"!=typeof s)return!0;const n=s,h=i[n];return h!==e&&(i[n]=e,t.Ge&&t.We(n,e,h)),!0}})}get isMultiple(){return this.Be.isMultiple}set isMultiple(t){this.ze.isMultiple=!!t}get hasImage(){return this.Be.hasImage}set hasImage(t){this.ze.hasImage=!!t}get qe(){return this.ze}set qe(t){if(!t||!this.ze||!this.Be)return;const i={};void 0!==t.imageWidth&&t.imageWidth!==this.Be.imageWidth&&(i.imageWidth=t.imageWidth),void 0!==t.imageHeight&&t.imageHeight!==this.Be.imageHeight&&(i.imageHeight=t.imageHeight),void 0!==t.imageBorderRadius&&t.imageBorderRadius!==this.Be.imageBorderRadius&&(i.imageBorderRadius=t.imageBorderRadius),void 0!==t.imagePosition&&t.imagePosition!==this.Be.imagePosition&&(i.imagePosition=t.imagePosition),void 0!==t.labelValign&&t.labelValign!==this.Be.labelValign&&(i.labelValign=t.labelValign),void 0!==t.labelHalign&&t.labelHalign!==this.Be.labelHalign&&(i.labelHalign=t.labelHalign),Object.keys(i).length>0&&Object.assign(this.ze,i)}ks(){const t=["selective-ui-option-view"],i=e.m(7),s="option_"+i;this.Be.isMultiple&&t.push("multiple"),this.Be.hasImage&&(t.push("has-image"),t.push("image-"+this.Be.imagePosition));const n={rs:{tag:{node:"input",type:this.Be.isMultiple?"checkbox":"radio",classList:"allow-choice",id:s}},...this.Be.hasImage&&{ps:{tag:{node:"img",classList:"option-image",style:{width:this.Be.imageWidth,height:this.Be.imageHeight,borderRadius:this.Be.imageBorderRadius}}}},Je:{tag:{node:"label",htmlFor:s,classList:["align-vertical-"+this.Be.labelValign,"align-horizontal-"+this.Be.labelHalign]},j:{ds:{tag:{node:"div"}}}}};this.view=e.H({Ke:{tag:{node:"div",id:`seui-${i}-option`,classList:t,role:"option",ariaSelected:"false",tabIndex:"-1"},j:n}}),this.parent.appendChild(this.view.view),this.Ge=!0}We(t,i,s){const e=this.view;if(!e||!e.view)return;const n=e.view,h=e.tags?.rs,o=e.tags?.Je;switch(t){case"isMultiple":{const t=!!i;n.classList.toggle("multiple",t),h&&h.type!==(t?"checkbox":"radio")&&(h.type=t?"checkbox":"radio");break}case"hasImage":{const t=!!i;if(n.classList.toggle("has-image",t),t)n.classList.add("image-"+this.Be.imagePosition),this.Qe();else{n.className=n.className.replace(/image-(top|right|bottom|left)/g,"").trim();const t=e.tags?.ps;t&&(t.remove(),e.tags.ps=null)}break}case"imagePosition":this.Be.hasImage&&(n.className=n.className.replace(/image-(top|right|bottom|left)/g,"").trim(),n.classList.add("image-"+i));break;case"imageWidth":case"imageHeight":case"imageBorderRadius":{const s=e.tags?.ps;if(s){const e="imageWidth"===t?"width":"imageHeight"===t?"height":"borderRadius",n=i+"";s.style[e]!==n&&(s.style[e]=n)}break}case"labelValign":case"labelHalign":if(o){const t=`align-vertical-${this.Be.labelValign} align-horizontal-${this.Be.labelHalign}`;o.className!==t&&(o.className=t)}}}Qe(){const t=this.view;if(!t||!t.view)return;const i=t.tags?.ps;if(i)return;const s=t.view,e=t.tags?.Je,n=document.createElement("img");n.className="option-image",n.style.width=this.Be.imageWidth,n.style.height=this.Be.imageHeight,n.style.borderRadius=this.Be.imageBorderRadius,e&&e.parentElement?s.insertBefore(n,e):s.appendChild(n),t.tags.ps=n}}class P extends C{constructor(t=[]){super(t),this.isMultiple=!1,this.Ye=[],this.Xe=-1,this.Ze=null,this.groups=[],this.tn=[],this.sn()}sn(){this.tn=[],this.groups=[],this.items.forEach(t=>{t instanceof m?(this.groups.push(t),this.tn.push(...t.items)):t instanceof b&&this.tn.push(t)})}Ie(t,i){return i instanceof m?new S(t):new L(t)}Fe(t,i,s){t.position=s,t instanceof m?this.en(t,i,s):t instanceof b&&this.nn(t,i,s),t.Ot=!0}en(t,i,s){super.Fe(t,i,s),t.view=i;const e=i.view.tags._e;e.textContent=t.label,t.Ot||(e.style.cursor="pointer",e.addEventListener("click",()=>{t.Ji()}),t.qi((t,i,s)=>{i.items.forEach(t=>{const i=t.view?.hs?.();i&&(i.style.display=s?"none":"")}),this.hn(i,s)}));const n=i.Ne();t.items.forEach((t,i)=>{let s=t.view;t.Ot&&s||(s=new L(n)),this.nn(t,s,i),t.Ot=!0}),i.Wi(t.collapsed),i.Qi()}nn(t,i,s){if(i.isMultiple=this.isMultiple,i.hasImage=t.hasImage,i.qe={imageWidth:t.options.imageWidth,imageHeight:t.options.imageHeight,imageBorderRadius:t.options.imageBorderRadius,imagePosition:t.options.imagePosition,labelValign:t.options.labelValign,labelHalign:t.options.labelHalign},t.Ot||super.Fe(t,i,s),t.view=i,t.hasImage){const s=i.view.tags.ps;s&&(s.src!==t.es&&(s.src=t.es),s.alt!==t.text&&(s.alt=t.text))}i.view.tags.ds.innerHTML=t.text,t.Ot||(i.view.tags.Ke.addEventListener("click",i=>{i.stopPropagation(),i.preventDefault(),this.Ms||(this.isMultiple?(this.js("select"),setTimeout(()=>{t.selected=!t.selected},5)):!0!==t.selected&&(this.js("select"),setTimeout(()=>{this.Ze&&(this.Ze.selected=!1),t.selected=!0},5)))}),i.view.tags.Ke.title=t.textContent,i.view.tags.Ke.addEventListener("mouseenter",()=>{this.Ms||this.rn(this.tn.indexOf(t),!1)}),t.cs(()=>{this.Fs("selected")}),t.us((i,s,e)=>{e&&(this.Ze=t),this.Fs("selected_internal")}),t.ni((t,i)=>{i.group?.Qi(),this.ln()})),t.selected&&(this.Ze=t,t.ns=!0)}ke(t){this.js("items",t),this.items=t,this.sn(),this.Fs("items",t)}Ss(t){this.ke(t)}Ps(t){this.items=t,this.sn()}an(){return this.tn.filter(t=>t.selected)}cn(){return this.tn.find(t=>t.selected)}Kt(t){this.isMultiple&&this.tn.forEach(i=>{i.selected=t})}ni(t){this.Ye.push(t)}ln(){const t=this.tn.filter(t=>t.visible).length,i=this.tn.length;this.Ye.forEach(s=>{s({un:t,dn:i,Zt:t>0,isEmpty:0===i})})}ti(){const t=this.tn.filter(t=>t.visible).length,i=this.tn.length;return{un:t,dn:i,Zt:t>0,isEmpty:0===i}}pn(){this.rn(0)}navigate(t,i=!0){const s=this.tn.filter(t=>t.visible);if(0===s.length)return;let e=s.findIndex(t=>t===this.tn[this.Xe]);-1===e&&(e=-1);let n=e+t;n>=s.length&&(n=0),n<0&&(n=s.length-1);const h=this.tn.indexOf(s[n]);this.rn(h,i)}gn(){if(this.Xe>-1&&this.tn[this.Xe]){const t=this.tn[this.Xe];if(t.visible){const i=t.view?.hs?.();i&&i.click()}}}rn(t,i=!0){let s=0;if("number"==typeof t)s=t;else if(t instanceof b){const i=this.tn.indexOf(t);s=i>-1?i:0}else s=0;this.Xe>-1&&this.tn[this.Xe]&&(this.tn[this.Xe].ls=!1);for(let e=s;e<this.tn.length;e++){const t=this.tn[e];if(t.visible){if(t.ls=!0,this.Xe=e,i){const i=t.view?.hs?.();i&&i.scrollIntoView({fn:"center",behavior:"smooth"})}return void this.mn(e,t.view?.hs?.()?.id)}}}mn(t,i){}hn(t,i){}}class M{constructor(t=null,i=null){this.container={},this.oldValue=null,this.node=null,this.options=null,this.bn=null,this.isOpen=!1,this.wn=!1,this.yn=!1,this.vn=null,t&&this.init(t,i)}get isDisabled(){return!!this.options?.disabled}set isDisabled(t){this.options&&this.node&&(this.options.disabled=t,this.node.classList.toggle("disabled",t),this.node.setAttribute("aria-disabled",t+""),this.container.tags?.mi?.setAttribute("aria-disabled",t+""))}get xn(){return!!this.options?.readonly}set xn(t){this.options&&this.node&&(this.options.readonly=t,this.node.classList.toggle("readonly",t))}get isVisible(){return!!this.options?.visible}set isVisible(t){this.options&&this.node&&(this.options.visible=t,this.node.classList.toggle("invisible",!t))}init(t,s){const n=e.R(t).options,l=new o(n),a=new r,c=new p(n),effector=i(),u=new w(n),g=new v(n),f=new x(t,u),m=new T(t),b=new O(t);this.vn=s,this.options=n,l.node&&(l.node.id=(n.Tn??"")+"");const C=e.$({On:{tag:{node:"div",classList:"selective-ui-MAIN"},j:{mi:{tag:{node:"div",classList:"selective-ui-view",tabIndex:0,onkeydown:t=>{"Enter"!==t.key&&" "!==t.key&&"ArrowDown"!==t.key||(t.preventDefault(),this.Cn()?.open())}},j:{An:{tag:l.node},Sn:{tag:a.node},Ei:{tag:c.node}}}}}},null);this.container=C,this.node=C.view,t.parentNode?.insertBefore(this.node,t),this.node.insertBefore(t,C.tags.mi),g.zs(C.tags.mi),g.Us(u),C.tags.mi.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()}),h.lt(t,C.tags.mi),t.classList.add("init"),u.ys(P),u.xs(y),u.As(e.K(t)),u.onUpdated=()=>{C.Ln?.ii?.()},this.bn=u,C.Pn=f,C.placeholder=l,C.Mn=a,C.Hn=c,C.effector=effector,C.targetElement=t,C.$n=g,C.jn=m,C.En=b,C.Ln=new d(t,n,u),C.Ln.ai(effector),C.Ln.bi(f,n),C.Ln.li("selected",()=>{this.Cn()?.change(null,!0)}),C.Ln.li("selected_internal",()=>{this.Cn()?.change(null,!1)}),C.Ln.oi("select",()=>{this.oldValue=this.Cn()?.value??""}),this.Cn()?.change(null,!1),m.connect(),m.Pt=t=>{u.update(e.K(t)),this.Cn()?.refreshMask()},b.connect(),b.Pt=t=>{e.V(t.disabled)!==this.isDisabled&&(this.isDisabled=e.V(t.disabled)),e.V(t.readonly)!==this.xn&&(this.xn=e.V(t.readonly)),e.V(t.visible)!==this.isVisible&&(this.isVisible=e.V(t.visible??"1"))},t.addEventListener("options:changed",()=>{u.update(e.K(t)),this.Cn()?.refreshMask(),C.Ln?.ii?.()}),n.ajax&&f.ue(n.ajax);const A=C.Ln.Ht,S=(t,i)=>{i||""!==t?(""!==t&&(this.yn=!0),f.search(t).then(t=>{C.Ln?.ii?.(),t?.me&&setTimeout(()=>{A.pn()},n.animationtime??0)}).catch(t=>{console.error("Search error:",t)})):f.clear()};let L=null;c.Mi=(t,i)=>{f.fe(t)&&(f.ee()?(L&&clearTimeout(L),C.Ln?.Yt?.(),L=setTimeout(()=>{S(t,i)},n.delaysearchtime??0)):S(t,i))},f.setPopup(C.Ln),c.Hi=t=>{A.navigate(t)},c.$i=()=>{A.gn()},c.ji=()=>{this.Cn()?.close(),C.tags.mi.focus()},A.mn=(t,i)=>{i&&c.Ii(i)},A.hn=()=>{C.Ln?.ii?.()},this.isDisabled=e.V(n.disabled),this.xn=e.V(n.readonly)}Fn(){const t=this.container??{},{jn:i,En:s}=t;i?.disconnect&&i.disconnect(),s?.disconnect&&s.disconnect()}Cn(){const t=this.container,i=this,s=e.R(t.targetElement);if(!s)return null;const h=s.options,o={get placeholder(){return t.placeholder.get()},set placeholder(i){t.placeholder?.set(i),t.Hn?.Fi(i)},get oldValue(){return i.oldValue},set value(t){this.setValue(null,t,!0)},get value(){const t=this.valueArray,i=t.length;return i>1?t:0===i?"":t[0]},get valueArray(){const t=[];return i.In().forEach(i=>{i.selected&&t.push(i.value)}),t},get valueString(){return this.valueArray.join(h.customDelimiter)},get valueOptions(){const t=[];return i.In().forEach(i=>{i.selected&&t.push(i)}),t},get mask(){const t=[];return i.In().forEach(i=>{i.selected&&t.push(i.text)}),t},get valueText(){const t=[];i.In().forEach(i=>{i.selected&&t.push(i.text)});const s=t.length;return s>1?t:0===s?"":t[0]},get isOpen(){return i.isOpen},selectAll(t,s=!0){if(!(h.multiple&&h.maxSelected>0&&i.In().length>h.maxSelected)&&!this.disabled&&!this.readonly&&h.multiple){if(s){if(n.ht([this],...h.on.beforeChange).isCancel)return;i.oldValue=this.value}i.In().forEach(t=>{t.ns=!0}),this.change(!1,s)}},deSelectAll(t,s=!0){if(!this.disabled&&!this.readonly&&h.multiple){if(s){if(n.ht([this],...h.on.beforeChange).isCancel)return;i.oldValue=this.value}i.In().forEach(t=>{t.ns=!1}),this.change(!1,s)}},setValue(s=null,e,o=!0,r=!1){if(Array.isArray(e)||(e=[e]),0===(e=e.filter(t=>""!==t&&null!=t)).length)return i.In().forEach(t=>t.ns=!1),void this.change(!1,o);if(h.multiple&&h.maxSelected>0&&e.length>h.maxSelected)console.warn(`Cannot select more than ${h.maxSelected} items`);else if(r||!this.disabled&&!this.readonly){if(t.Pn?.ee?.()){const{ce:s}=t.Pn.le(e);if(s.length>0)return void(async()=>{h.loadingfield&&t.Ln?.Yt?.();try{const n=await t.Pn.ne(s);n.Ci&&n.items.length>0?(n.items.forEach(t=>{s.includes(t.value)&&(t.selected=!0)}),t.Pn.ye?.(n.items,!0,!0),setTimeout(()=>{i.In().forEach(t=>{t.ns=e.some(i=>i==t.value)}),this.change(!1,!1)},100)):s.length>0&&console.warn(`Could not load ${s.length} values:`,s)}catch(n){console.error("Error loading missing values:",n)}finally{h.loadingfield&&t.Ln?.si?.()}})()}if(o){if(n.ht([this],...h.on.beforeChange).isCancel)return;i.oldValue=this.value}i.In().forEach(t=>{t.ns=e.some(i=>i==t.value)}),!h.multiple&&e.length>0&&(t.targetElement.value=e[0]),this.change(!1,o)}},open(){if(i.isOpen)return!1;const s=i.vn?.find?.();if(s&&!s.isEmpty&&s.close().isCancel)return!1;if(this.disabled)return!1;if(n.ht([this],...h.on.beforeShow).isCancel)return!1;i.isOpen=!0,t.Mn.dt(!0);const e=t.Ln.Ht,o=e.cn();o?e.rn(o,!1):e.pn(),i.wn&&!i.yn||!h?.ajax||(t.Ln.Yt(),i.wn=!0,i.yn=!1,setTimeout(()=>{t.Ln&&t.Pn&&t.Pn.search("").then(()=>t.Ln?.ii?.()).catch(t=>console.error("Initial ajax load error:",t))},h.animationtime)),t.Ln.open(),t.Hn.show();const r=t.tags.mi;return r.setAttribute("aria-expanded","true"),r.setAttribute("aria-controls",h.Gt),r.setAttribute("aria-haspopup","listbox"),r.setAttribute("aria-labelledby",h.Tn),h.multiple&&r.setAttribute("aria-multiselectable","true"),n.ht([this],...h.on.show),!0},close(){return!!i.isOpen&&!n.ht([this],...h.on.beforeClose).isCancel&&(i.isOpen=!1,t.Mn.dt(!1),t.Ln.close(()=>{t.Hn.clear(!1)}),t.Hn.hide(),t.tags.mi.setAttribute("aria-expanded","false"),n.ht([this],...h.on.close),!0)},toggle(){i.isOpen?this.close():this.open()},change(s=null,e=!0){if(e){if(h.multiple&&h.maxSelected>0&&this.valueArray.length>h.maxSelected&&this.setValue(null,this.oldValue,!1,!0),this.disabled||this.readonly)return void this.setValue(null,this.oldValue,!1,!0);if(n.ht([this,this.value],...h.on.beforeChange).isCancel)return void this.setValue(null,this.oldValue,!1)}this.refreshMask(),t.$n.Ws(this.valueOptions),e&&(t.targetElement&&n.ot(t.targetElement,"change"),n.ht([this,this.value],...h.on.change),i.options?.autoclose&&this.close())},refreshMask(){let s=h.placeholder;!h.multiple&&i.In().length>0&&(s=this.mask[0]),s??(s=h.placeholder),t.placeholder.set(s,!1),t.Hn.Fi(s)},on(t,i,s){h.on[i]||(h.on[i]=[]),h.on[i].push(s)},ajax(i,s){t.Pn.ue(s)}};return this.Vn(o,"disabled","isDisabled"),this.Vn(o,"readonly","isReadOnly"),this.Vn(o,"visible","isVisible"),o}Vn(t,i,s){const e=this;Object.defineProperty(t,i,{get:()=>e[s],set(t){e[s]=!!t,e.container?.targetElement?.dataset&&(e.container.targetElement.dataset[i]=!!t+"")},enumerable:!0,configurable:!0})}In(t=null){if(!this.bn)return[];const{Hs:i}=this.bn.qt(),s=[];for(const e of i)e instanceof b?s.push(e):e instanceof m&&Array.isArray(e.items)&&e.items.length&&s.push(...e.items);return"boolean"==typeof t?s.filter(i=>i.selected===t):s}Ai(){this.container.Ln.Ai()}}class H{constructor(){this.kn=!1,this.Le=null,this.Rn=[]}_n(t){this.Rn.push(t)}Dn(){this.Rn=[]}start(t){if(this.kn)return;this.kn=!0;const i=t.toUpperCase(),s=t.toLowerCase();this.Le=new MutationObserver(t=>{for(const e of t)e.addedNodes.forEach(t=>{if(1!==t.nodeType)return;const e=t;e.tagName===i&&this.Nn(e),e.querySelectorAll(s).forEach(t=>this.Nn(t))})}),this.Le.observe(document.body,{childList:!0,subtree:!0})}stop(){this.kn&&(this.kn=!1,this.Le?.disconnect(),this.Le=null)}Nn(t){this.Rn.forEach(i=>i(t))}}class ${constructor(){this.Bn=new Map}bind(t,i){const s=e.I(e.G(),i);s.on=s.on??{},s.on.load=s.on.load??[],this.Bn.set(t,s);const h=e.m();e.Z.on(h,()=>{n.ht([this.find(t)],...s.on.load),e.Z.clear(h),s.on.load=[]}),e.v(t).forEach(t=>{(async()=>{"SELECT"===t.tagName&&(e.D(t),this.zn(t,s)&&e.Z.run(h))})()}),e.U().includes(t)||e.U().push(t)}find(t="*"){const i={isEmpty:!0};if("*"===t&&""===(t=e.U().join(", ")))return i;const s=e.v(t);if(0===s.length)return i;const n=e.R(s[0]);if(!n||!n.action)return i;const h={};for(const e in n.action)h[e]=this.Gn(e,n.action);const o={isEmpty:!1};for(const e in h){const t=h[e];switch(t.type){case"get-set":this.Un(o,t.name,s);break;case"func":this.Wn(o,t.name,s)}}return o}qn(){this.Jn=new H,this.Jn._n(t=>{this.Bn.forEach((i,s)=>{try{t.matches(s)&&this.zn(t,i)}catch(e){console.warn("Invalid selector: "+s,e)}})}),this.Jn.start("select")}destroy(t=null){null===t?this.Kn():"string"==typeof t?this.Qn(t):t instanceof HTMLSelectElement&&this.Yn(t)}Kn(){e.U().forEach(t=>this.Qn(t)),this.Bn.clear(),e.U().length=0,this.Jn?.stop()}Qn(t){e.v(t).forEach(t=>{"SELECT"===t.tagName&&this.Yn(t)}),this.Bn.delete(t);const i=e.U(),s=i.indexOf(t);s>-1&&i.splice(s,1)}Yn(t){const i=e.R(t);if(!i)return;const s=i.container?.Ln;s?.Ai(),e.B(t,i);const n=!!this.Jn;n&&this.Jn?.stop();try{i.self?.Fn?.()}catch(o){}const h=i.container?.element??t.parentElement;t.style.display="",t.style.visibility="",t.disabled=!1,delete t.dataset.Xn,h&&h.parentNode?h.parentNode.replaceChild(t,h):document.body.appendChild(t),e.k(t),n&&this.Bn.size>0&&this.Jn?.start("select")}rebind(t,i){this.Qn(t),this.bind(t,i)}zn(t,i){if(e.R(t)||e.N(t))return!1;const s=e.m(8),n=e.F(t,i);n.Zn=s,n.Gt=`seui-${s}-optionlist`,n.Tn=`seui-${s}-placeholder`;const h={options:n};e._(t,h);const o=new M(t,this);return h.container=o.container,h.action=o.Cn(),h.self=o,o.container.view.addEventListener("mouseup",()=>{h.action?.toggle?.()}),!0}Gn(t,i){const s=Object.getOwnPropertyDescriptor(i,t);let e="variable";return s?.get||s?.set&&"function"!=typeof i[t]?e="get-set":"function"==typeof i[t]&&(e="func"),{type:e,name:t}}Un(t,i,s){Object.defineProperty(t,i,{get(){const t=e.R(s[0]);return t.action?.[i]},set(t){s.forEach(s=>{const n=e.R(s);n?.action&&(n.action[i]=t)})},enumerable:!0,configurable:!0})}Wn(t,i,s){t[i]=(...h)=>{for(let t=0;t<s.length;t++){const o=e.R(s[t]);if(!o?.action)continue;const r=n.nt();if(o.action[i](r.et,...h),!r.token.isContinue)break}return t}}}const j="1.1.3",E="SelectiveUI";if(void 0===globalThis.GLOBAL_SEUI){const I=new $;globalThis.GLOBAL_SEUI={version:j,name:E,bind:I.bind.bind(I),find:I.find.bind(I),destroy:I.destroy.bind(I),effector:i.bind(i),rebind:I.rebind.bind(I)};let V=!1;function k(){V||(V=!0,document.addEventListener("mousedown",()=>{const t=e.U();if(t.length>0){const i=I.find(t.join(", "));i.isEmpty||i.close()}}),I.qn())}"undefined"!=typeof document&&("loading"===document.readyState?document.addEventListener("DOMContentLoaded",k):k()),console.log(`[${E}] v${j} loaded successfully`)}else console.warn(`[${globalThis.GLOBAL_SEUI.name}] Already loaded (v${globalThis.GLOBAL_SEUI.version}). Using existing instance. Please remove duplicate <script> tags.`);const version=globalThis.GLOBAL_SEUI.version,F=globalThis.GLOBAL_SEUI.name;t.bind=(t,i={})=>{globalThis.GLOBAL_SEUI.bind(t,i)},t.destroy=(t=null)=>{globalThis.GLOBAL_SEUI.destroy(t)},t.effector=t=>globalThis.GLOBAL_SEUI.effector(t),t.find=t=>globalThis.GLOBAL_SEUI.find(t),t.name=F,t.rebind=(t,i={})=>{globalThis.GLOBAL_SEUI.rebind(t,i)},t.version=version},"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).SelectiveUI={});
|
|
Binary file
|