selective-ui 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/selective-ui.esm.js +225 -200
- package/dist/selective-ui.esm.js.map +1 -1
- package/dist/selective-ui.esm.min.js +2 -1
- 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 +225 -200
- package/dist/selective-ui.umd.js.map +1 -1
- package/package.json +16 -15
- package/src/ts/adapter/mixed-adapter.ts +6 -7
- package/src/ts/components/accessorybox.ts +0 -10
- package/src/ts/components/directive.ts +0 -3
- package/src/ts/components/empty-state.ts +0 -3
- package/src/ts/components/loading-state.ts +3 -1
- package/src/ts/components/option-handle.ts +0 -5
- package/src/ts/components/placeholder.ts +0 -3
- package/src/ts/components/popup.ts +70 -11
- package/src/ts/components/searchbox.ts +2 -12
- package/src/ts/components/selectbox.ts +4 -2
- package/src/ts/core/base/adapter.ts +4 -5
- package/src/ts/core/base/model.ts +0 -1
- package/src/ts/core/base/recyclerview.ts +0 -6
- package/src/ts/core/base/view.ts +0 -24
- package/src/ts/core/model-manager.ts +3 -24
- package/src/ts/index.ts +10 -9
- package/src/ts/models/group-model.ts +0 -1
- package/src/ts/models/option-model.ts +3 -3
- package/src/ts/services/ea-observer.ts +0 -2
- package/src/ts/services/effector.ts +3 -4
- package/src/ts/services/refresher.ts +1 -1
- package/src/ts/services/resize-observer.ts +0 -1
- package/src/ts/services/select-observer.ts +0 -2
- package/src/ts/types/core/base/view.type.ts +0 -18
- package/src/ts/types/services/effector.type.ts +14 -0
- package/src/ts/types/utils/callback-scheduler.type.ts +69 -0
- package/src/ts/types/utils/libs.type.ts +0 -46
- package/src/ts/utils/callback-scheduler.ts +135 -0
- package/src/ts/utils/guard.ts +4 -10
- package/src/ts/utils/libs.ts +6 -77
- package/src/ts/utils/selective.ts +7 -5
- package/src/ts/views/group-view.ts +0 -1
- package/src/ts/views/option-view.ts +2 -0
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 v(t??null)}function s(){if("undefined"!=typeof window)return window[_]}function e(t,i={}){const e=s();if(D&&e)return e.bind(t,i);k.bind(t,i)}function n(t){const i=s();return D&&i?i.find(t):k.find(t)}function h(t){const i=s();if(D&&i)return i.destroy(t);k.destroy(t)}function o(t,i={}){const e=s();if(D&&e)return e.rebind(t,i);k.rebind(t,i)}function r(t){const e=s();return D&&e?e.effector(t):i(t)}class a{constructor(){this.defaultConfig={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.bindedMap=new Map,this.unbindedMap=new Map,this.bindedCommand=[]}}class l{static get iStorage(){return this.t||(this.t=new a),this.t}static isNullOrEmpty(t){return"boolean"!=typeof t&&(null==t||""===t||0===t||"0"===t)}static jsCopyObject(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.jsCopyObject(t[s]));return i}static randomString(t=6){let i="";for(let s=0;s<t;s++)i+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random()));return i}static getElements(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 nodeCreator(t={}){return this.nodeCloner(document.createElement(t.node??"div"),t,!0)}static nodeCloner(t=document.documentElement,i=null,s=!1){const e={...i??{}},n=s?t:this.nodeToElement(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.ariaLabelledby&&(n.setAttribute("aria-labelledby",e.ariaLabelledby+""),delete e.ariaLabelledby),e.ariaControls&&(n.setAttribute("aria-controls",e.ariaControls+""),delete e.ariaControls),e.ariaHaspopup&&(n.setAttribute("aria-haspopup",e.ariaHaspopup+""),delete e.ariaHaspopup),e.ariaMultiselectable&&(n.setAttribute("aria-multiselectable",e.ariaMultiselectable+""),delete e.ariaMultiselectable),e.ariaAutocomplete&&(n.setAttribute("aria-autocomplete",e.ariaAutocomplete+""),delete e.ariaAutocomplete),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 nodeToElement(t){if(t instanceof Element)return t;throw new TypeError("Node is not an Element")}static mountView(t){return this.mountNode(t)}static mountNode(t,i=null,s=!1,e=!1,n={}){let h=null;for(const o in t){const r=t[o],a=r?.tag?.tagName?r.tag:this.nodeCreator(r.tag);n[o]=a,r?.child&&this.mountNode(r.child,a,!1,!1,n),i?s?i.prepend(a):i.append(a):e||h||(h=a)}return e||(n.id=this.randomString(7),i||(n={tags:n,view:h})),n}static setStyle(t,i,s=null){const e="string"==typeof i?{[i]:s}:{...i},n=this.getElements(t);for(let h=0;h<n.length;h++){const t=n[h];t&&Object.assign(t.style,e)}}static buildConfig(t,i){const s=this.jsCopyObject(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 mergeConfig(...t){if(0===t.length)return{};if(1===t.length)return this.jsCopyObject(t[0]);const i=this.jsCopyObject(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 string2Boolean(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 removeBinderMap(t){return this.iStorage.bindedMap.delete(t)}static getBinderMap(t){return this.iStorage.bindedMap.get(t)}static setBinderMap(t,i){this.iStorage.bindedMap.set(t,i)}static removeUnbinderMap(t){return this.iStorage.unbindedMap.delete(t)}static getUnbinderMap(t){return this.iStorage.unbindedMap.get(t)}static setUnbinderMap(t,i){this.iStorage.unbindedMap.set(t,i)}static getDefaultConfig(){return this.iStorage.defaultConfig}static getBindedCommand(){return this.iStorage.bindedCommand}static tagTranslate(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 stripHtml(t){const i=document.createElement("DIV");i.innerHTML=t;const s=i.textContent??i.innerText??"";return i.remove(),s.trim()}static string2normalize(t){return null==t?"":(t+"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/đ/g,"d").replace(/Đ/g,"d")}static parseSelectToArray(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 IsIOS(){const t=navigator.userAgent;return/iP(hone|ad|od)/.test(t)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1}static any2px(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.nodeCreator({node:"div",style:{height:i,opacity:"0"}});document.body.appendChild(e);const n=e.offsetHeight+"px";return e.remove(),n}}l.t=null,l.timerProcess={executeStored:{},timerRunner:{},setExecute(t,i,s=50,e=!1){this.executeStored[t]||(this.executeStored[t]=[]),this.executeStored[t].push({execute:i,timeout:s,once:e})},clearExecute(t){delete this.executeStored[t]},run(t,...i){const s=this.executeStored[t];if(s){this.timerRunner[t]||(this.timerRunner[t]={});for(const e in s){const n=s[+e];n&&(this.timerRunner[t][e]||(this.timerRunner[t][e]=setTimeout(()=>{},0),clearTimeout(this.timerRunner[t][e])),clearTimeout(this.timerRunner[t][e]),this.timerRunner[t][e]=setTimeout(()=>{n.execute(i.length>0?i:null),n.once&&delete this.executeStored[t][+e]},n.timeout))}}}};class c{static buildEventToken(){const t={isContinue:!0,isCancel:!1};return{token:{get isContinue(){return t.isContinue},get isCancel(){return t.isCancel}},callback:{stopPropagation(){t.isContinue=!1},cancel(){t.isCancel=!0,t.isContinue=!1}}}}static callEvent(t,...i){const{token:s,callback:e}=this.buildEventToken();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 trigger(t,i,s={bubbles:!0,cancelable:!0}){const e=new Event(i,s);return t.dispatchEvent(e),e}static callFunctions(t,...i){if(Array.isArray(t))for(const s of t)"function"==typeof s&&s(...i)}}class u{static resizeBox(t,i){const s=l.getBinderMap(t);if(!s?.options)return;const e=s.options,n=e.minWidth,h=e.minHeight,o=Number.parseInt(e.width,10),r=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),o>0&&(a=e.width),r>0&&(c=e.height),l.setStyle(i,{width:a,height:c,minWidth:n,minHeight:h})}}class d{constructor(t){this.node=null,this.i=null,t&&this.init(t)}init(t){this.node=l.nodeCreator({node:"div",classList:"selective-ui-placeholder",innerHTML:t.placeholder}),this.i=t}get(){return this.i?.placeholder??""}set(t,i=!0){if(!this.node||!this.i)return;i&&(this.i.placeholder=t);const s=l.tagTranslate(t);this.node.innerHTML=this.i.allowHtml?s:l.stripHtml(s)}}class p{constructor(){this.node=this.h()}h(){return l.nodeCreator({node:"div",classList:"selective-ui-directive",role:"button",ariaLabel:"Toggle dropdown"})}setDropdown(t){this.node.classList.toggle("drop-down",!!t)}}class g{constructor(t=null){this.nodeMounted=null,this.node=null,this.options=null,this.o=[],this.l=[],t&&this.init(t)}init(t){this.nodeMounted=l.mountNode({OptionHandle:{tag:{node:"div",classList:["selective-ui-option-handle","hide"]},child:{SelectAll:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textSelectAll,onclick:()=>{c.callFunctions(this.o)}}},DeSelectAll:{tag:{node:"a",classList:"selective-ui-option-handle-item",textContent:t.textDeselectAll,onclick:()=>{c.callFunctions(this.l)}}}}}}),this.node=this.nodeMounted.view,this.options=t}available(){return!!this.options&&l.string2Boolean(this.options.multiple)&&l.string2Boolean(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")}OnSelectAll(t=null){"function"==typeof t&&this.o.push(t)}OnDeSelectAll(t=null){"function"==typeof t&&this.l.push(t)}}class f{constructor(t=null){this.node=null,this.options=null,t&&this.init(t)}init(t){this.options=t,this.node=l.nodeCreator({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 m{constructor(t=null){this.node=null,this.options=null,t&&this.init(t)}init(t){this.options=t,this.node=l.nodeCreator({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 b{constructor(){this.isInit=!1,this.element=null,this.u=null,this.p=null,this.isInit=!0,this.m=this.v.bind(this)}onChanged(t){}v(){const t=this.element;if(!t||"function"!=typeof t.getBoundingClientRect)return void this.onChanged({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.onChanged({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")}})}trigger(){this.v()}connect(t){if(!(t instanceof Element))throw Error("Invalid element");this.element=t,this.u=new ResizeObserver(this.m),this.u.observe(t),this.p=new MutationObserver(this.m),this.p.observe(t,{attributes:!0,attributeFilter:["style","class"]}),window.addEventListener("scroll",this.m,!0),window.addEventListener("resize",this.m),window.visualViewport&&(window.visualViewport.addEventListener("resize",this.m),window.visualViewport.addEventListener("scroll",this.m))}disconnect(){this.u?.disconnect(),this.p?.disconnect(),this.onChanged=()=>{},window.removeEventListener("scroll",this.m,!0),window.removeEventListener("resize",this.m),window.visualViewport&&(window.visualViewport.removeEventListener("resize",this.m),window.visualViewport.removeEventListener("scroll",this.m)),this.u=null,this.p=null,this.element=null}}class w{constructor(t=null,i=null,s=null){this.options=null,this.isCreated=!1,this.optionAdapter=null,this.node=null,this.O=null,this.C=null,this.T=null,this.optionHandle=null,this.emptyState=null,this.loadingState=null,this.recyclerView=null,this.A=null,this.S=null,this.L=null,this.P=s,t&&i&&this.init(t,i)}init(t,i){if(!this.P)throw Error("Popup requires a ModelManager instance.");this.optionHandle=new g(i),this.emptyState=new f(i),this.loadingState=new m(i);const s=l.mountNode({PopupContainer:{tag:{node:"div",classList:"selective-ui-popup",style:{maxHeight:i.panelHeight}},child:{OptionHandle:{tag:this.optionHandle.node},OptionsContainer:{tag:{id:i.SEID_LIST,node:"div",classList:"selective-ui-options-container",role:"listbox"}},LoadingState:{tag:this.loadingState.node},EmptyState:{tag:this.emptyState.node}}}},null);this.node=s.view,this.A=s.tags.OptionsContainer,this.T=l.getBinderMap(t),this.options=i,this.P.load(this.A,{isMultiple:i.multiple});const e=this.P.getResources();this.optionAdapter=e.adapter,this.recyclerView=e.recyclerView,this.optionHandle.OnSelectAll(()=>{e.adapter.checkAll(!0)}),this.optionHandle.OnDeSelectAll(()=>{e.adapter.checkAll(!1)}),this.M()}async showLoading(){this.options&&this.loadingState&&this.optionHandle&&this.optionAdapter&&this.P&&(this.L&&clearTimeout(this.L),this.P.skipEvent(!0),!1!==l.string2Boolean(this.options.loadingfield)&&(this.loadingState.show(this.optionAdapter.getVisibilityStats().hasVisible),this.optionHandle.hide(),this.triggerResize()))}async hideLoading(){this.options&&this.loadingState&&this.optionAdapter&&this.P&&(this.L&&clearTimeout(this.L),this.L=setTimeout(()=>{this.P?.skipEvent(!1),this.loadingState?.hide();const t=this.optionAdapter?.getVisibilityStats();this.H(t??void 0),this.triggerResize()},200))}M(){this.optionAdapter&&(this.optionAdapter.onVisibilityChanged(t=>{this.H(t)}),this.optionAdapter.onPropChanged("items",()=>{const t=this.optionAdapter.getVisibilityStats();this.H(t),this.triggerResize()}))}H(t){if(!(this.optionAdapter&&this.emptyState&&this.optionHandle&&this.A))return;const i=t??this.optionAdapter.getVisibilityStats();i.isEmpty?(this.emptyState.show("nodata"),this.A.classList.add("hide"),this.optionHandle.hide()):i.hasVisible?(this.emptyState.hide(),this.A.classList.remove("hide"),this.optionHandle.refresh()):(this.emptyState.show("notfound"),this.A.classList.add("hide"),this.optionHandle.hide())}onAdapterPropChanging(t,i){this.optionAdapter?.onPropChanging(t,i)}onAdapterPropChanged(t,i){this.optionAdapter?.onPropChanged(t,i)}setupEffector(t){this.O=t}open(t=null){if(!(this.node&&this.options&&this.optionHandle&&this.T&&this.O))return;this.isCreated||(document.body.appendChild(this.node),this.isCreated=!0,this.C=new b,this.O.setElement(this.node),this.node.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()})),this.optionHandle.refresh(),this.H();const i=this.$(),{position:s,top:e,maxHeight:n,realHeight:h}=this.j(i);this.O.expand({duration:this.options.animationtime,display:"flex",width:i.width,left:i.left,top:e,maxHeight:n,realHeight:h,position:s,onComplete:()=>{this.C&&this.T&&(this.C.onChanged=()=>{const t=this.$();this.I(t)},this.C.connect(this.T.container.tags.ViewPanel),t?.())}})}close(t=null){this.isCreated&&this.options&&this.C&&this.O&&(this.C.disconnect(),this.O.collapse({duration:this.options.animationtime,onComplete:t??void 0}))}triggerResize(){this.isCreated&&this.C?.trigger()}setupInfiniteScroll(t,i){this.node&&(this.S=async()=>{const i=t.getPaginationState();if(!i.isPaginationEnabled)return;const s=this.node;if(s.scrollHeight-s.scrollTop-s.clientHeight<100&&!i.isLoading&&i.hasMore){const i=await t.loadMore();!i.success&&i.message&&console.log("Load more:",i.message)}},this.node.addEventListener("scroll",this.S))}$(){const t=this.T.container.tags.ViewPanel,i=t.getBoundingClientRect(),s=window.getComputedStyle(t),e=window.visualViewport,n=l.IsIOS();return{width:i.width,height:i.height,top:i.top-(e&&n?e.offsetTop:0),left:i.left-(e&&n?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)}}}j(t){const i=window.visualViewport,s=l.IsIOS(),e=i?.height??window.innerHeight,n=i&&s?i.offsetTop:0,h=this.O.getHiddenDimensions("flex").scrollHeight,o=parseFloat(this.options?.panelHeight??"220")||220,r=parseFloat(this.options?.panelMinHeight??"100")||100,a=e-(t.top+t.height)-3,c=t.top-3;let u="bottom",d=o,p=Math.min(h,d);const g=a-15;return(p>=r?g>=r:g>=p)?(u="bottom",d=Math.min(a-15,o)):c>=Math.max(p,r)?(u="top",d=Math.min(c-15,o)):a>=c?(u="bottom",d=Math.max(a-15,r)):(u="top",d=Math.max(c-15,r)),p=Math.min(h,d),{position:u,top:"bottom"===u?t.top+t.height+3+n:t.top-p-3+n,maxHeight:d,realHeight:p,contentHeight:h}}I(t){if(!this.options||!this.O)return;const{position:i,top:s,maxHeight:e,realHeight:n}=this.j(t);this.O.resize({duration:this.options.animationtime,width:t.width,left:t.left,top:s,maxHeight:e,realHeight:n,position:i,animate:!0})}}class y{constructor(t=null){this.nodeMounted=null,this.node=null,this.SearchInput=null,this.onSearch=null,this.options=null,this.onNavigate=null,this.onEnter=null,this.onEsc=null,this.options=t,t&&this.init(t)}init(t){this.nodeMounted=l.mountNode({SearchBox:{tag:{node:"div",classList:["selective-ui-searchbox","hide"]},child:{SearchInput:{tag:{id:l.randomString(),node:"input",type:"search",classList:["selective-ui-searchbox-input"],placeholder:t.placeholder,role:"searchbox",ariaControls:t.SEID_LIST,ariaAutocomplete:"list"}}}}}),this.node=this.nodeMounted.view,this.SearchInput=this.nodeMounted.tags.SearchInput;let i=!1;const s=this.nodeMounted.tags.SearchInput;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.onNavigate?.(1)):"ArrowUp"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.onNavigate?.(-1)):"Enter"===t.key?(t.preventDefault(),t.stopPropagation(),i=!0,this.onEnter?.()):"Escape"===t.key&&(t.preventDefault(),t.stopPropagation(),i=!0,this.onEsc?.())}),s.addEventListener("input",()=>{i||this.onSearch?.(s.value,!0)})}show(){this.node&&this.SearchInput&&this.options&&(this.node.classList.remove("hide"),this.SearchInput.readOnly=!this.options.searchable,this.options.searchable&&requestAnimationFrame(()=>{this.SearchInput?.focus()}))}hide(){this.node&&this.node.classList.add("hide")}clear(t=!0){this.nodeMounted&&(this.nodeMounted.tags.SearchInput.value="",this.onSearch?.("",t))}setPlaceHolder(t){this.SearchInput&&(this.SearchInput.placeholder=l.stripHtml(t))}setActiveDescendant(t){this.SearchInput&&this.SearchInput.setAttribute("aria-activedescendant",t)}}class v{constructor(t=null){this.F=null,this.V=null,this.k=!1,t&&this.setElement(t)}setElement(t){if("string"==typeof t){const i=document.querySelector(t);return void(i instanceof HTMLElement&&(this.element=i))}this.element=t}cancel(){return this.F&&(clearTimeout(this.F),this.F=null),this.V&&(clearTimeout(this.V),this.V=null),this.k=!1,this}getHiddenDimensions(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.k=!0;const{duration:i=200,display:s="flex",width:e,left:n,top:h,maxHeight:o,realHeight:r,position:a="bottom",onComplete:l}=t;return Object.assign(this.element.style,{display:s,width:e+"px",left:n+"px",top:("bottom"===a?h:h+r)+"px",maxHeight:o+"px",height:"0px",opacity:"0",overflow:"hidden",transition:"none"}),this.element.classList.toggle("position-top","top"===a),this.element.classList.toggle("position-bottom","bottom"===a),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.F=setTimeout(()=>{this.element.style.transition="none",this.k=!1,l?.()},i)}),this}collapse(t){if(!this.element)return this;this.cancel(),this.k=!0;const{duration:i=200,onComplete: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.F=setTimeout(()=>{Object.assign(this.element.style,{display:"none",transition:"none"}),this.k=!1,s?.()},i)}),this}showSwipeWidth(t){if(!this.element)return this;this.cancel(),this.k=!0;const{duration:i=200,display:s="block",onComplete:e}=t;Object.assign(this.element.style,{transition:"none",display:s,width:"fit-content"});const n=this.getHiddenDimensions(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.F=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:""}),this.k=!1,e?.()},i),this}hideSwipeWidth(t){if(!this.element)return this;this.cancel(),this.k=!0;const{duration:i=200,onComplete:s}=t,e=this.getHiddenDimensions().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.F=setTimeout(()=>{Object.assign(this.element.style,{width:"",overflow:"",transition:"",display:""}),this.k=!1,s?.()},i),this}resize(t){if(!this.element)return this;this.V&&clearTimeout(this.V);const{duration:i=200,width:s,left:e,top:n,maxHeight:h,realHeight:o,position:r="bottom",animate:a=!0,onComplete:l}=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);a&&(c||r>5)?t.transition=`height ${i}ms, top ${i}ms`:this.V=setTimeout(()=>{this.element.style.transition="none"},i),Object.assign(this.element.style,t),a&&(c||r>1)?this.V=setTimeout(()=>{this.element.style.transition="none",c&&delete this.element.style.transition,l?.()},i):(c&&delete this.element.style.transition,l?.())}),this}get isAnimating(){return this.k}}class x{get value(){return this.targetElement?.getAttribute("value")??null}constructor(t,i=null,s=null){this.targetElement=null,this.view=null,this.position=-1,this.isInit=!1,this.options=t,this.targetElement=i,this.view=s}update(t){this.targetElement=t,this.onTargetChanged()}onTargetChanged(){}}class O extends x{constructor(t,i){super(t,i??null,null),this.label="",this.items=[],this.collapsed=!1,this.R=[],i&&(this.label=i.label,this.collapsed=l.string2Boolean(i.dataset?.collapsed))}get value(){return this.items.map(t=>t.value)}get selectedItems(){return this.items.filter(t=>t.selected)}get visibleItems(){return this.items.filter(t=>t.visible)}get hasVisibleItems(){return this.visibleItems.length>0}update(t){this.label=t.label,this.view?.updateLabel(this.label)}onTargetChanged(){this.view&&(this.view.updateLabel(this.label),this.view.setCollapsed(this.collapsed))}onCollapsedChanged(t){this.R.push(t)}toggleCollapse(){this.collapsed=!this.collapsed,this.view?.setCollapsed(this.collapsed),c.callEvent([this,this.collapsed],...this.R)}addItem(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)}updateVisibility(){this.view?.updateVisibility()}}class C extends x{constructor(){super(...arguments),this._=[],this.D=[],this.N=[],this.B=!0,this.G=!1,this.group=null}get imageSrc(){return this.dataset?.imgsrc||this.dataset?.image||""}get hasImage(){return!!this.imageSrc}get value(){return this.targetElement?.value??""}get selected(){return!!this.targetElement?.selected}set selected(t){this.selectedNonTrigger=t,c.callEvent([this,t],...this._)}get visible(){return this.B}set visible(t){if(this.B===t)return;this.B=t;const i=this.view?.getView?.();i&&i.classList.toggle("hide",!t),c.callEvent([this,t],...this.N)}get selectedNonTrigger(){return this.selected}set selectedNonTrigger(t){const i=this.view?.getTag?.("OptionInput"),s=this.view?.getView?.();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),c.callEvent([this,t],...this.D)}get text(){const t=l.tagTranslate(this.dataset?.mask??this.targetElement?.text??"");return this.options.allowHtml?t:l.stripHtml(t)}get textContent(){return this.options.allowHtml?l.stripHtml(this.text).trim():this.text.trim()}get dataset(){return this.targetElement?.dataset??{}}get highlighted(){return this.G}set highlighted(t){const i=!!t,s=this.view?.getView?.();this.G!==i&&(this.G=i),s&&s.classList.toggle("highlight",i)}onSelected(t){this._.push(t)}onInternalSelected(t){this.D.push(t)}onVisibilityChanged(t){this.N.push(t)}onTargetChanged(){if(!this.view)return;const t=this.view.getTag("LabelContent");t&&(this.options.allowHtml?t.innerHTML=this.text:t.textContent=this.textContent);const i=this.view.getTag("OptionImage");i&&this.hasImage&&(i.src=this.imageSrc,i.alt=this.text),this.targetElement&&(this.selectedNonTrigger=this.targetElement.selected)}}class T{constructor(t){this.U=[],this.W=null,this.q=null,this.J=null,this.options=null,this.options=t}setupAdapter(t){this.K=t}setupRecyclerView(t){this.Y=t}hasRealChanges(t){const i=this.X(t),s=i!==this.J;return s&&(this.J=i),s}X(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")}createModelResources(t){this.U=[];let i=null;return t.forEach(t=>{if("OPTGROUP"===t.tagName)i=new O(this.options,t),this.U.push(i);else if("OPTION"===t.tagName){const s=t,e=new C(this.options,s),n=s.__parentGroup;n&&i&&n===i.targetElement?(i.addItem(e),e.group=i):(this.U.push(e),i=null)}}),this.U}replace(t){this.J=null,this.createModelResources(t),this.W&&this.W.syncFromSource(this.U),this.refresh()}notify(){this.W&&this.refresh()}load(t,i={},s={}){this.W=new this.K(this.U),Object.assign(this.W,i),this.q=new this.Y(t),this.q.setAdapter(this.W),Object.assign(this.q,s)}update(t){if(!this.hasRealChanges(t))return;const i=this.U,s=[],e=new Map,n=new Map;i.forEach(t=>{t instanceof O?e.set(t.label,t):t instanceof C&&n.set(`${t.value}::${t.textContent}`,t)});let h=null,o=0;const r=[];t.forEach(t=>{if("OPTGROUP"===t.tagName){const i=t,n=e.get(i.label);n?(n.label!==i.label&&r.push(()=>n.update(i)),n.position=o,n.items=[],h=n,s.push(n),e.delete(i.label)):(h=new O(this.options,i),h.position=o,s.push(h)),o++}else if("OPTION"===t.tagName){const i=t,e=`${i.value}::${i.text}`,a=n.get(e);if(a)a.selected!==i.selected||a.position!==o?r.push(()=>{a.update(i),a.position=o}):a.position=o,i.__parentGroup&&h?(h.addItem(a),a.group=h):(a.group=null,s.push(a)),n.delete(e);else{const t=new C(this.options,i);t.position=o,i.__parentGroup&&h?(h.addItem(t),t.group=h):s.push(t)}o++}}),r.length>0&&requestAnimationFrame(()=>{r.forEach(t=>t())}),e.forEach(t=>{t.view?.getView?.()?.remove?.()}),n.forEach(t=>{t.view?.getView?.()?.remove?.()}),this.U=s,this.W&&this.W.updateData(this.U),this.onUpdated(),this.refresh()}onUpdated(){}skipEvent(t){this.W&&(this.W.isSkipEvent=t)}refresh(){this.q&&(this.q.refresh(),this.onUpdated())}getResources(){if(!this.W||!this.q)throw Error("ModelManager resources not loaded. Call load() first.");return{modelList:this.U,adapter:this.W,recyclerView:this.q}}triggerChanging(t){this.W?.changingProp(t)}triggerChanged(t){this.W?.changeProp(t)}}class A{constructor(t=null){this.viewElement=null,this.adapter=null,this.viewElement=t}setView(t){this.viewElement=t}setAdapter(t){this.adapter=t,t.onPropChanging("items",()=>{this.clear()}),t.onPropChanged("items",()=>{this.render()}),this.render()}clear(){this.viewElement&&this.viewElement.replaceChildren()}render(){this.adapter&&this.viewElement&&this.adapter.updateRecyclerView(this.viewElement)}refresh(){this.render()}}class S{constructor(t=null){this.nodeMounted=null,this.node=null,this.options=null,this.selectUIMask=null,this.parentMask=null,this.modelManager=null,t&&this.init(t)}init(t){this.nodeMounted=l.mountNode({AccessoryBox:{tag:{node:"div",classList:["selective-ui-accessorybox","hide"],onmouseup:t=>{t.stopPropagation()}}}}),this.node=this.nodeMounted.view,this.options=t}setRoot(t){this.selectUIMask=t,this.parentMask=t.parentElement,this.refreshLocation()}refreshLocation(){this.parentMask&&this.node&&this.selectUIMask&&this.options&&this.parentMask.insertBefore(this.node,"top"===this.options.accessoryStyle?this.selectUIMask:this.selectUIMask.nextSibling)}setModelManager(t){this.modelManager=t}setModelData(t){this.node&&this.options&&(this.node.replaceChildren(),t.length>0&&this.options.multiple?(this.node.classList.remove("hide"),t.forEach(t=>{l.mountNode({AccessoryItem:{tag:{node:"div",classList:["accessory-item"]},child:{Button:{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.modelManager?.triggerChanging?.("select"),setTimeout(()=>{t.selected=!1},10)}}},Content:{tag:{node:"span",classList:["accessory-item-content"],innerHTML:t.text}}}}},this.node)})):this.node.classList.add("hide"),c.trigger(window,"resize"))}}class L{constructor(t,i){this.Z=null,this.tt=null,this.it=null,this.st={currentPage:0,totalPages:1,hasMore:!1,isLoading:!1,currentKeyword:"",isPaginationEnabled:!1},this.et=t,this.P=i}isAjax(){return!!this.Z}async loadByValues(t){if(!this.Z)return{success:!1,items:[],message:"Ajax not configured"};const i=Array.isArray(t)?t:[t];if(0===i.length)return{success:!0,items:[]};try{const t=this.Z;let s,e;if(s="function"==typeof t.dataByValues?t.dataByValues(i):{values:i.join(","),load_by_values:"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{success:!0,items:this.nt(n).items}}catch(s){return console.error("Load by values error:",s),{success:!1,message:s?.message,items:[]}}}checkMissingValues(t){const i=Array.from(this.et.options).map(t=>t.value);return{existing:t.filter(t=>i.includes(t)),missing:t.filter(t=>!i.includes(t))}}setAjax(t){this.Z=t}setPopup(t){this.it=t}getPaginationState(){return{...this.st}}resetPagination(){this.st={currentPage:0,totalPages:1,hasMore:!1,isLoading:!1,currentKeyword:"",isPaginationEnabled:this.st.isPaginationEnabled}}clear(){this.st.currentKeyword="";const{modelList:t}=this.P.getResources(),i=[];for(const s of t)s instanceof C?i.push(s):s instanceof O&&Array.isArray(s.items)&&i.push(...s.items);i.forEach(t=>{t.visible=!0})}async search(t,i=!1){return this.Z?this.ht(t,i):this.ot(t)}async loadMore(){return this.Z?this.st.isLoading?{success:!1,message:"Already loading"}:this.st.isPaginationEnabled?this.st.hasMore?(this.st.currentPage++,this.ht(this.st.currentKeyword,!0)):{success:!1,message:"No more data"}:{success:!1,message:"Pagination not enabled"}:{success:!1,message:"Ajax not enabled"}}async ot(t){this.compareSearchTrigger(t)&&(this.st.currentKeyword=t);const i=((t??"")+"").toLowerCase(),s=l.string2normalize(i),{modelList:e}=this.P.getResources(),n=[];for(const o of e)o instanceof C?n.push(o):o instanceof O&&Array.isArray(o.items)&&n.push(...o.items);let h=!1;return n.forEach(t=>{const e=((t.textContent??t.text??"")+"").toLowerCase(),n=l.string2normalize(e),o=""===i||e.includes(i)||n.includes(s);t.visible=o,o&&(h=!0)}),{success:!0,hasResults:h,isEmpty:0===n.length}}compareSearchTrigger(t){return t!==this.st.currentKeyword}async ht(t,i=!1){const s=this.Z;this.compareSearchTrigger(t)&&(this.resetPagination(),this.st.currentKeyword=t,i=!1),this.st.isLoading=!0,this.it?.showLoading(),this.tt?.abort(),this.tt=new AbortController;const e=this.st.currentPage,n=Array.from(this.et.selectedOptions).map(t=>t.value).join(",");let h;"function"==typeof s.data?(h=s.data(t,e),h&&void 0===h.selectedValue&&(h.selectedValue=n)):h={search:t,page:e,selectedValue: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.tt.signal})}else{const i=""+new URLSearchParams(h);t=await fetch(`${s.url}?${i}`,{signal:this.tt.signal})}const e=await t.json(),n=this.nt(e);return n.hasPagination?(this.st.isPaginationEnabled=!0,this.st.currentPage=n.page,this.st.totalPages=n.totalPages,this.st.hasMore=n.hasMore):this.st.isPaginationEnabled=!1,this.applyAjaxResult(n.items,!!s.keepSelected,i),this.st.isLoading=!1,this.it?.hideLoading(),{success:!0,hasResults:n.items.length>0,isEmpty:0===n.items.length,hasPagination:n.hasPagination,hasMore:n.hasMore,currentPage:n.page,totalPages:n.totalPages}}catch(o){return this.st.isLoading=!1,this.it?.hideLoading(),"AbortError"===o?.name?{success:!1,message:"Request aborted"}:(console.error("Ajax search error:",o),{success:!1,message:o?.message})}}nt(t){let i=[],s=!1,e=0,n=1,h=!1;return t.object&&Array.isArray(t.object)?(i=t.object,void 0!==t.page&&(s=!0,e=parseInt(t.page??0,10),n=parseInt(t.totalPages??t.total_page??1,10),h=e<n-1)):t.data&&Array.isArray(t.data)?(i=t.data,void 0!==t.page&&(s=!0,e=parseInt(t.page??0,10),n=parseInt(t.totalPages??t.total_page??1,10),h=t.hasMore??e<n-1)):Array.isArray(t)?i=t:t.items&&Array.isArray(t.items)&&(i=t.items,t.pagination&&(s=!0,e=parseInt(t.pagination.page??0,10),n=parseInt(t.pagination.totalPages??t.pagination.total_page??1,10),h=t.pagination.hasMore??e<n-1)),{items:i.map(t=>{if(t instanceof HTMLOptionElement||t instanceof HTMLOptGroupElement)return t;if("optgroup"===t.type||t.isGroup||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}}),hasPagination:s,page:e,totalPages:n,hasMore:h}}applyAjaxResult(t,i,s=!1){const e=this.et;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 P{constructor(t){this.rt=null,this.lt=null,this.ct=50,this.et=t,this.lt=this.ut(),this.dt=new MutationObserver(()=>{this.rt&&clearTimeout(this.rt),this.rt=setTimeout(()=>{this.gt()},this.ct)}),t.addEventListener("options:changed",()=>{this.rt&&clearTimeout(this.rt),this.rt=setTimeout(()=>{this.gt()},this.ct)})}ut(){const t=Array.from(this.et.options);return{length:t.length,values:t.map(t=>t.value).join(","),texts:t.map(t=>t.text).join(","),selected:t.map(t=>t.selected+"").join(",")}}ft(){const t=this.ut(),i=JSON.stringify(t)!==JSON.stringify(this.lt);return i&&(this.lt=t),i}gt(){this.ft()&&this.onChanged(this.et)}connect(){this.dt.observe(this.et,{childList:!0,subtree:!1,attributes:!0,attributeFilter:["selected","value","disabled"]})}onChanged(t){}disconnect(){this.rt&&clearTimeout(this.rt),this.rt=null,this.dt.disconnect()}}class M{constructor(t){this.rt=null,this.bt=t,this.dt=new MutationObserver(t=>{let i=!1;for(const s of t)if("attributes"===s.type&&s.attributeName?.startsWith("data-")){i=!0;break}i&&(this.rt&&clearTimeout(this.rt),this.rt=setTimeout(()=>{this.onChanged({...this.bt.dataset})},50))}),t.addEventListener("dataset:changed",()=>{this.onChanged({...this.bt.dataset})})}connect(){this.dt.observe(this.bt,{attributes:!0,attributeOldValue:!0})}onChanged(t){}disconnect(){this.rt&&clearTimeout(this.rt),this.rt=null,this.dt.disconnect()}}class H{constructor(t=[]){this.items=[],this.adapterKey=l.randomString(12),this.isSkipEvent=!1,this.items=t,this.onInit()}onInit(){}onViewHolder(t,i,s){const e=i;t.isInit?e?.update?.():e?.render?.()}onPropChanging(t,i){l.timerProcess.setExecute(`${t}ing_${this.adapterKey}`,i,1)}onPropChanged(t,i){l.timerProcess.setExecute(`${t}_${this.adapterKey}`,i)}changeProp(t,...i){l.timerProcess.run(`${t}_${this.adapterKey}`,...i)}changingProp(t,...i){l.timerProcess.run(`${t}ing_${this.adapterKey}`,...i)}viewHolder(t,i){return null}itemCount(){return this.items.length}setItems(t){this.changingProp("items",t),this.items=t,this.changeProp("items",t)}syncFromSource(t){this.setItems(t)}updateRecyclerView(t){for(let i=0;i<this.itemCount();i++){const s=this.items[i];let e=s.view;s.isInit||(e=this.viewHolder(t,s),s.view=e),this.onViewHolder(s,e,i),s.isInit=!0}}updateData(t){}}class E{constructor(t){this.parent=null,this.view=null,this.parent=t}render(){}update(){}getView(){if(!this.view?.view)throw Error("View is not mounted. Did you forget to set this.view?");return this.view.view}getTag(t){if(!this.view)throw Error("View is not mounted. Did you forget to set this.view?");return this.view.tags[t]}getTags(){if(!this.view)throw Error("View is not mounted. Did you forget to set this.view?");return this.view.tags}}class $ extends E{constructor(){super(...arguments),this.view=null}render(){const t=l.randomString(7);this.view=l.mountView({GroupView:{tag:{node:"div",classList:["selective-ui-group"],role:"group",ariaLabelledby:`seui-${t}-header`,id:`seui-${t}-group`},child:{GroupHeader:{tag:{node:"div",classList:["selective-ui-group-header"],role:"presentation",id:`seui-${t}-header`}},GroupItems:{tag:{node:"div",classList:["selective-ui-group-items"],role:"group"}}}}}),this.parent.appendChild(this.view.view)}update(){this.updateLabel()}updateLabel(t=null){this.view&&null!==t&&(this.view.tags.GroupHeader.textContent=t)}getItemsContainer(){if(!this.view)throw Error("GroupView is not rendered.");return this.view.tags.GroupItems}updateVisibility(){if(!this.view)return;const t=Array.from(this.view.tags.GroupItems.children).filter(t=>!t.classList.contains("hide"));this.view.view.classList.toggle("hide",!(t.length>0))}setCollapsed(t){this.view&&(this.view.view.classList.toggle("collapsed",t),this.view.tags.GroupHeader.setAttribute("aria-expanded",t?"false":"true"))}}class j extends E{constructor(t){super(t),this.view=null,this.wt=null,this.yt=null,this.vt=!1,this.xt()}xt(){const t=this;this.wt={isMultiple:!1,hasImage:!1,imagePosition:"right",imageWidth:"60px",imageHeight:"60px",imageBorderRadius:"4px",labelValign:"center",labelHalign:"left"},this.yt=new Proxy(this.wt,{set(i,s,e){if("string"!=typeof s)return!0;const n=s,h=i[n];return h!==e&&(i[n]=e,t.vt&&t.Ot(n,e,h)),!0}})}get isMultiple(){return this.wt.isMultiple}set isMultiple(t){this.yt.isMultiple=!!t}get hasImage(){return this.wt.hasImage}set hasImage(t){this.yt.hasImage=!!t}get optionConfig(){return this.yt}set optionConfig(t){if(!t||!this.yt||!this.wt)return;const i={};void 0!==t.imageWidth&&t.imageWidth!==this.wt.imageWidth&&(i.imageWidth=t.imageWidth),void 0!==t.imageHeight&&t.imageHeight!==this.wt.imageHeight&&(i.imageHeight=t.imageHeight),void 0!==t.imageBorderRadius&&t.imageBorderRadius!==this.wt.imageBorderRadius&&(i.imageBorderRadius=t.imageBorderRadius),void 0!==t.imagePosition&&t.imagePosition!==this.wt.imagePosition&&(i.imagePosition=t.imagePosition),void 0!==t.labelValign&&t.labelValign!==this.wt.labelValign&&(i.labelValign=t.labelValign),void 0!==t.labelHalign&&t.labelHalign!==this.wt.labelHalign&&(i.labelHalign=t.labelHalign),Object.keys(i).length>0&&Object.assign(this.yt,i)}render(){const t=["selective-ui-option-view"],i=l.randomString(7),s="option_"+i;this.wt.isMultiple&&t.push("multiple"),this.wt.hasImage&&(t.push("has-image"),t.push("image-"+this.wt.imagePosition));const e={OptionInput:{tag:{node:"input",type:this.wt.isMultiple?"checkbox":"radio",classList:"allow-choice",id:s}},...this.wt.hasImage&&{OptionImage:{tag:{node:"img",classList:"option-image",style:{width:this.wt.imageWidth,height:this.wt.imageHeight,borderRadius:this.wt.imageBorderRadius}}}},OptionLabel:{tag:{node:"label",htmlFor:s,classList:["align-vertical-"+this.wt.labelValign,"align-horizontal-"+this.wt.labelHalign]},child:{LabelContent:{tag:{node:"div"}}}}};this.view=l.mountView({OptionView:{tag:{node:"div",id:`seui-${i}-option`,classList:t,role:"option",ariaSelected:"false",tabIndex:"-1"},child:e}}),this.parent.appendChild(this.view.view),this.vt=!0}Ot(t,i,s){const e=this.view;if(!e||!e.view)return;const n=e.view,h=e.tags?.OptionInput,o=e.tags?.OptionLabel;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.wt.imagePosition),this.Ct();else{n.className=n.className.replace(/image-(top|right|bottom|left)/g,"").trim();const t=e.tags?.OptionImage;t&&(t.remove(),e.tags.OptionImage=null)}break}case"imagePosition":this.wt.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?.OptionImage;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.wt.labelValign} align-horizontal-${this.wt.labelHalign}`;o.className!==t&&(o.className=t)}}}Ct(){const t=this.view;if(!t||!t.view)return;const i=t.tags?.OptionImage;if(i)return;const s=t.view,e=t.tags?.OptionLabel,n=document.createElement("img");n.className="option-image",n.style.width=this.wt.imageWidth,n.style.height=this.wt.imageHeight,n.style.borderRadius=this.wt.imageBorderRadius,e&&e.parentElement?s.insertBefore(n,e):s.appendChild(n),t.tags.OptionImage=n}}class I extends H{constructor(t=[]){super(t),this.isMultiple=!1,this.Tt=[],this.At=-1,this.St=null,this.groups=[],this.flatOptions=[],this.Lt()}Lt(){this.flatOptions=[],this.groups=[],this.items.forEach(t=>{t instanceof O?(this.groups.push(t),this.flatOptions.push(...t.items)):t instanceof C&&this.flatOptions.push(t)})}viewHolder(t,i){return i instanceof O?new $(t):new j(t)}onViewHolder(t,i,s){t.position=s,t instanceof O?this.Pt(t,i,s):t instanceof C&&this.Mt(t,i,s),t.isInit=!0}Pt(t,i,s){super.onViewHolder(t,i,s),t.view=i;const e=i.getTag("GroupHeader");e.textContent=t.label,t.isInit||(e.style.cursor="pointer",e.addEventListener("click",()=>{t.toggleCollapse()}),t.onCollapsedChanged((t,i,s)=>{i.items.forEach(t=>{const i=t.view?.getView?.();i&&(i.style.display=s?"none":"")}),this.onCollapsedChange(i,s)}));const n=i.getItemsContainer();t.items.forEach((t,i)=>{let s=t.view;t.isInit&&s||(s=new j(n)),this.Mt(t,s,i),t.isInit=!0}),i.setCollapsed(t.collapsed),i.updateVisibility()}Mt(t,i,s){if(i.isMultiple=this.isMultiple,i.hasImage=t.hasImage,i.optionConfig={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.isInit||super.onViewHolder(t,i,s),t.view=i,t.hasImage){const s=i.getTag("OptionImage");s&&(s.src!==t.imageSrc&&(s.src=t.imageSrc),s.alt!==t.text&&(s.alt=t.text))}i.getTag("LabelContent").innerHTML=t.text,t.isInit||(i.getTag("OptionView").addEventListener("click",i=>{i.stopPropagation(),i.preventDefault(),this.isSkipEvent||(this.isMultiple?(this.changingProp("select"),setTimeout(()=>{t.selected=!t.selected},5)):!0!==t.selected&&(this.changingProp("select"),setTimeout(()=>{this.St&&(this.St.selected=!1),t.selected=!0},5)))}),i.getTag("OptionView").title=t.textContent,i.getTag("OptionView").addEventListener("mouseenter",()=>{this.isSkipEvent||this.setHighlight(this.flatOptions.indexOf(t),!1)}),t.onSelected(()=>{this.changeProp("selected")}),t.onInternalSelected((i,s,e)=>{e&&(this.St=t),this.changeProp("selected_internal")}),t.onVisibilityChanged((t,i)=>{i.group?.updateVisibility(),this.Ht()})),t.selected&&(this.St=t,t.selectedNonTrigger=!0)}setItems(t){this.changingProp("items",t),this.items=t,this.Lt(),this.changeProp("items",t)}syncFromSource(t){this.setItems(t)}updateData(t){this.items=t,this.Lt()}getSelectedItems(){return this.flatOptions.filter(t=>t.selected)}getSelectedItem(){return this.flatOptions.find(t=>t.selected)}checkAll(t){this.isMultiple&&this.flatOptions.forEach(i=>{i.selected=t})}onVisibilityChanged(t){this.Tt.push(t)}Ht(){const t=this.flatOptions.filter(t=>t.visible).length,i=this.flatOptions.length;this.Tt.forEach(s=>{s({visibleCount:t,totalCount:i,hasVisible:t>0,isEmpty:0===i})})}getVisibilityStats(){const t=this.flatOptions.filter(t=>t.visible).length,i=this.flatOptions.length;return{visibleCount:t,totalCount:i,hasVisible:t>0,isEmpty:0===i}}resetHighlight(){this.setHighlight(0)}navigate(t,i=!0){const s=this.flatOptions.filter(t=>t.visible);if(0===s.length)return;let e=s.findIndex(t=>t===this.flatOptions[this.At]);-1===e&&(e=-1);let n=e+t;n>=s.length&&(n=0),n<0&&(n=s.length-1);const h=this.flatOptions.indexOf(s[n]);this.setHighlight(h,i)}selectHighlighted(){if(this.At>-1&&this.flatOptions[this.At]){const t=this.flatOptions[this.At];if(t.visible){const i=t.view?.getView?.();i&&i.click()}}}setHighlight(t,i=!0){let s=0;if("number"==typeof t)s=t;else if(t instanceof C){const i=this.flatOptions.indexOf(t);s=i>-1?i:0}else s=0;this.At>-1&&this.flatOptions[this.At]&&(this.flatOptions[this.At].highlighted=!1);for(let e=s;e<this.flatOptions.length;e++){const t=this.flatOptions[e];if(t.visible){if(t.highlighted=!0,this.At=e,i){const i=t.view?.getView?.();i&&i.scrollIntoView({block:"center",behavior:"smooth"})}return void this.onHighlightChange(e,t.view?.getView?.()?.id)}}}onHighlightChange(t,i){}onCollapsedChange(t,i){}}class F{constructor(t=null,i=null){this.container={},this.oldValue=null,this.node=null,this.options=null,this.optionModelManager=null,this.isOpen=!1,this.hasLoadedOnce=!1,this.isBeforeSearch=!1,this.Selective=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?.ViewPanel?.setAttribute("aria-disabled",t+""))}get isReadOnly(){return!!this.options?.readonly}set isReadOnly(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=l.getBinderMap(t).options,n=new d(e),h=new p,o=new y(e),r=i(),a=new T(e),c=new S(e),g=new L(t,a),f=new P(t),m=new M(t);this.Selective=s,this.options=e,n.node&&(n.node.id=(e.SEID_HOLDER??"")+"");const b=l.mountNode({Container:{tag:{node:"div",classList:"selective-ui-MAIN"},child:{ViewPanel:{tag:{node:"div",classList:"selective-ui-view",tabIndex:0,onkeydown:t=>{"Enter"!==t.key&&" "!==t.key&&"ArrowDown"!==t.key||(t.preventDefault(),this.getAction()?.open())}},child:{PlaceHolder:{tag:n.node},Directive:{tag:h.node},SearchBox:{tag:o.node}}}}}},null);this.container=b,this.node=b.view,t.parentNode?.insertBefore(this.node,t),this.node.insertBefore(t,b.tags.ViewPanel),c.setRoot(b.tags.ViewPanel),c.setModelManager(a),b.tags.ViewPanel.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()}),u.resizeBox(t,b.tags.ViewPanel),t.classList.add("init"),a.setupAdapter(I),a.setupRecyclerView(A),a.createModelResources(l.parseSelectToArray(t)),a.onUpdated=()=>{b.popup?.triggerResize?.()},this.optionModelManager=a,b.searchController=g,b.placeholder=n,b.directive=h,b.searchbox=o,b.effector=r,b.targetElement=t,b.accessorybox=c,b.selectObserver=f,b.datasetObserver=m,b.popup=new w(t,e,a),b.popup.setupEffector(r),b.popup.setupInfiniteScroll(g,e),b.popup.onAdapterPropChanged("selected",()=>{this.getAction()?.change(null,!0)}),b.popup.onAdapterPropChanged("selected_internal",()=>{this.getAction()?.change(null,!1)}),b.popup.onAdapterPropChanging("select",()=>{this.oldValue=this.getAction()?.value??""}),this.getAction()?.change(null,!1),f.connect(),f.onChanged=t=>{a.update(l.parseSelectToArray(t)),this.getAction()?.refreshMask()},m.connect(),m.onChanged=t=>{l.string2Boolean(t.disabled)!==this.isDisabled&&(this.isDisabled=l.string2Boolean(t.disabled)),l.string2Boolean(t.readonly)!==this.isReadOnly&&(this.isReadOnly=l.string2Boolean(t.readonly)),l.string2Boolean(t.visible)!==this.isVisible&&(this.isVisible=l.string2Boolean(t.visible??"1"))},t.addEventListener("options:changed",()=>{a.update(l.parseSelectToArray(t)),this.getAction()?.refreshMask(),b.popup?.triggerResize?.()}),e.ajax&&g.setAjax(e.ajax);const v=b.popup.optionAdapter,x=(t,i)=>{i||""!==t?(""!==t&&(this.isBeforeSearch=!0),g.search(t).then(t=>{b.popup?.triggerResize?.(),t?.hasResults&&setTimeout(()=>{v.resetHighlight()},e.animationtime??0)}).catch(t=>{console.error("Search error:",t)})):g.clear()};let O=null;o.onSearch=(t,i)=>{g.compareSearchTrigger(t)&&(g.isAjax()?(O&&clearTimeout(O),b.popup?.showLoading?.(),O=setTimeout(()=>{x(t,i)},e.delaysearchtime??0)):x(t,i))},g.setPopup(b.popup),o.onNavigate=t=>{v.navigate(t)},o.onEnter=()=>{v.selectHighlighted()},o.onEsc=()=>{this.getAction()?.close(),b.tags.ViewPanel.focus()},v.onHighlightChange=(t,i)=>{i&&o.setActiveDescendant(i)},v.onCollapsedChange=()=>{b.popup?.triggerResize?.()},this.isDisabled=l.string2Boolean(e.disabled),this.isReadOnly=l.string2Boolean(e.readonly)}deInit(){const t=this.container??{},{selectObserver:i,datasetObserver:s}=t;i?.disconnect&&i.disconnect(),s?.disconnect&&s.disconnect()}getAction(){const t=this.container,i=this,s=l.getBinderMap(t.targetElement);if(!s)return null;const e=s.options,n={get placeholder(){return t.placeholder.get()},set placeholder(i){t.placeholder?.set(i),t.searchbox?.setPlaceHolder(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.getModelOption().forEach(i=>{i.selected&&t.push(i.value)}),t},get valueString(){return this.valueArray.join(e.customDelimiter)},get valueOptions(){const t=[];return i.getModelOption().forEach(i=>{i.selected&&t.push(i)}),t},get mask(){const t=[];return i.getModelOption().forEach(i=>{i.selected&&t.push(i.text)}),t},get valueText(){const t=[];i.getModelOption().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.getModelOption().length>e.maxSelected)&&!this.disabled&&!this.readonly&&e.multiple){if(s){if(c.callEvent([this],...e.on.beforeChange).isCancel)return;i.oldValue=this.value}i.getModelOption().forEach(t=>{t.selectedNonTrigger=!0}),this.change(!1,s)}},deSelectAll(t,s=!0){if(!this.disabled&&!this.readonly&&e.multiple){if(s){if(c.callEvent([this],...e.on.beforeChange).isCancel)return;i.oldValue=this.value}i.getModelOption().forEach(t=>{t.selectedNonTrigger=!1}),this.change(!1,s)}},setValue(s=null,n,h=!0,o=!1){if(Array.isArray(n)||(n=[n]),0===(n=n.filter(t=>""!==t&&null!=t)).length)return i.getModelOption().forEach(t=>t.selectedNonTrigger=!1),void this.change(!1,h);if(e.multiple&&e.maxSelected>0&&n.length>e.maxSelected)console.warn(`Cannot select more than ${e.maxSelected} items`);else if(o||!this.disabled&&!this.readonly){if(t.searchController?.isAjax?.()){const{missing:s}=t.searchController.checkMissingValues(n);if(s.length>0)return void(async()=>{e.loadingfield&&t.popup?.showLoading?.();try{const e=await t.searchController.loadByValues(s);e.success&&e.items.length>0?(e.items.forEach(t=>{s.includes(t.value)&&(t.selected=!0)}),t.searchController.applyAjaxResult?.(e.items,!0,!0),setTimeout(()=>{i.getModelOption().forEach(t=>{t.selectedNonTrigger=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.popup?.hideLoading?.()}})()}if(h){if(c.callEvent([this],...e.on.beforeChange).isCancel)return;i.oldValue=this.value}i.getModelOption().forEach(t=>{t.selectedNonTrigger=n.some(i=>i==t.value)}),!e.multiple&&n.length>0&&(t.targetElement.value=n[0]),this.change(!1,h)}},open(){if(i.isOpen)return!1;const s=i.Selective?.find?.();if(s&&!s.isEmpty&&s.close().isCancel)return!1;if(this.disabled)return!1;if(c.callEvent([this],...e.on.beforeShow).isCancel)return!1;i.isOpen=!0,t.directive.setDropdown(!0);const n=t.popup.optionAdapter,h=n.getSelectedItem();h?n.setHighlight(h,!1):n.resetHighlight(),i.hasLoadedOnce&&!i.isBeforeSearch||!e?.ajax||(t.popup.showLoading(),i.hasLoadedOnce=!0,i.isBeforeSearch=!1,setTimeout(()=>{t.popup&&t.searchController&&t.searchController.search("").then(()=>t.popup?.triggerResize?.()).catch(t=>console.error("Initial ajax load error:",t))},e.animationtime)),t.popup.open(),t.searchbox.show();const o=t.tags.ViewPanel;return o.setAttribute("aria-expanded","true"),o.setAttribute("aria-controls",e.SEID_LIST),o.setAttribute("aria-haspopup","listbox"),o.setAttribute("aria-labelledby",e.SEID_HOLDER),e.multiple&&o.setAttribute("aria-multiselectable","true"),c.callEvent([this],...e.on.show),!0},close(){return!!i.isOpen&&!c.callEvent([this],...e.on.beforeClose).isCancel&&(i.isOpen=!1,t.directive.setDropdown(!1),t.popup.close(()=>{t.searchbox.clear(!1)}),t.searchbox.hide(),t.tags.ViewPanel.setAttribute("aria-expanded","false"),c.callEvent([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(c.callEvent([this,this.value],...e.on.beforeChange).isCancel)return void this.setValue(null,this.oldValue,!1)}this.refreshMask(),t.accessorybox.setModelData(this.valueOptions),n&&(t.targetElement&&c.trigger(t.targetElement,"change"),c.callEvent([this,this.value],...e.on.change),i.options?.autoclose&&this.close())},refreshMask(){let s=e.placeholder;!e.multiple&&i.getModelOption().length>0&&(s=this.mask[0]),s??(s=e.placeholder),t.placeholder.set(s,!1),t.searchbox.setPlaceHolder(s)},on(t,i,s){e.on[i]||(e.on[i]=[]),e.on[i].push(s)},ajax(i,s){t.searchController.setAjax(s)}};return this.createSymProp(n,"disabled","isDisabled"),this.createSymProp(n,"readonly","isReadOnly"),this.createSymProp(n,"visible","isVisible"),n}createSymProp(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})}getModelOption(t=null){if(!this.optionModelManager)return[];const{modelList:i}=this.optionModelManager.getResources(),s=[];for(const e of i)e instanceof C?s.push(e):e instanceof O&&Array.isArray(e.items)&&e.items.length&&s.push(...e.items);return"boolean"==typeof t?s.filter(i=>i.selected===t):s}}class V{constructor(){this.Et=!1,this.dt=null,this.$t=[]}onDetect(t){this.$t.push(t)}clearDetect(){this.$t=[]}start(t){if(this.Et)return;this.Et=!0;const i=t.toUpperCase(),s=t.toLowerCase();this.dt=new MutationObserver(t=>{for(const e of t)e.addedNodes.forEach(t=>{if(1!==t.nodeType)return;const e=t;e.tagName===i&&this.jt(e),e.querySelectorAll(s).forEach(t=>this.jt(t))})}),this.dt.observe(document.body,{childList:!0,subtree:!0})}stop(){this.Et&&(this.Et=!1,this.dt?.disconnect(),this.dt=null)}jt(t){this.$t.forEach(i=>i(t))}}class k{static bind(t,i){const s=l.mergeConfig(l.getDefaultConfig(),i);s.on=s.on??{},s.on.load=s.on.load??[],this.bindedQueries.set(t,s);const e=l.randomString();l.timerProcess.setExecute(e,()=>{c.callEvent([this.find(t)],...s.on.load),l.timerProcess.clearExecute(e),s.on.load=[]}),l.getElements(t).forEach(t=>{(async()=>{"SELECT"===t.tagName&&(l.removeUnbinderMap(t),this.applySelectBox(t,s)&&l.timerProcess.run(e))})()}),l.getBindedCommand().includes(t)||l.getBindedCommand().push(t)}static find(t="*"){const i={isEmpty:!0};if("*"===t&&""===(t=l.getBindedCommand().join(", ")))return i;const s=l.getElements(t);if(0===s.length)return i;const e=l.getBinderMap(s[0]);if(!e||!e.action)return i;const n={};for(const o in e.action)n[o]=this.getProperties(o,e.action);const h={isEmpty:!1};for(const o in n){const t=n[o];switch(t.type){case"get-set":this.buildGetSetAction(h,t.name,s);break;case"func":this.buildFuntionAction(h,t.name,s)}}return h}static Observer(){this.EAObserver=new V,this.EAObserver.onDetect(t=>{this.bindedQueries.forEach((i,s)=>{try{t.matches(s)&&this.applySelectBox(t,i)}catch(e){console.warn("Invalid selector: "+s,e)}})}),this.EAObserver.start("select")}static destroy(t=null){null===t?this.destroyAll():"string"==typeof t?this.destroyByQuery(t):t instanceof HTMLSelectElement&&this.destroyElement(t)}static destroyAll(){l.getBindedCommand().forEach(t=>this.destroyByQuery(t)),this.bindedQueries.clear(),l.getBindedCommand().length=0,this.EAObserver?.stop()}static destroyByQuery(t){l.getElements(t).forEach(t=>{"SELECT"===t.tagName&&this.destroyElement(t)}),this.bindedQueries.delete(t);const i=l.getBindedCommand(),s=i.indexOf(t);s>-1&&i.splice(s,1)}static destroyElement(t){const i=l.getBinderMap(t);if(!i)return;l.setUnbinderMap(t,i);const s=!!this.EAObserver;s&&this.EAObserver?.stop();try{i.self?.deInit?.()}catch(n){}const e=i.container?.element??t.parentElement;t.style.display="",t.style.visibility="",t.disabled=!1,delete t.dataset.selectiveId,e&&e.parentNode?e.parentNode.replaceChild(t,e):document.body.appendChild(t),l.removeBinderMap(t),s&&this.bindedQueries.size>0&&this.EAObserver?.start("select")}static rebind(t,i){this.destroyByQuery(t),this.bind(t,i)}static applySelectBox(t,i){if(l.getBinderMap(t)||l.getUnbinderMap(t))return!1;const s=l.randomString(8),e=l.buildConfig(t,i);e.SEID=s,e.SEID_LIST=`seui-${s}-optionlist`,e.SEID_HOLDER=`seui-${s}-placeholder`;const n={options:e};l.setBinderMap(t,n);const h=new F(t,this);return n.container=h.container,n.action=h.getAction(),n.self=h,h.container.view.addEventListener("mouseup",()=>{n.action?.toggle?.()}),!0}static getProperties(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 buildGetSetAction(t,i,s){Object.defineProperty(t,i,{get(){const t=l.getBinderMap(s[0]);return t.action?.[i]},set(t){s.forEach(s=>{const e=l.getBinderMap(s);e?.action&&(e.action[i]=t)})},enumerable:!0,configurable:!0})}static buildFuntionAction(t,i,s){t[i]=(...e)=>{for(let t=0;t<s.length;t++){const n=l.getBinderMap(s[t]);if(!n?.action)continue;const h=c.buildEventToken();if(n.action[i](h.callback,...e),!h.token.isContinue)break}return t}}}k.bindedQueries=new Map;const R="1.1.0",_="SelectiveUI",D=(t=>{if("undefined"==typeof window)return!1;const i=window[t];if(i&&i.It)return console.warn(`[${t}] Already loaded (v${i.Ft}). Using existing instance. Please remove duplicate <script> tags.`),!0;const s=i??{};return s.Vt=!0,window[t]=s,!1})(_);if(!D){let N=!1;function B(){N||(N=!0,document.addEventListener("mousedown",()=>{const t=l.getBindedCommand();if(t.length>0){const i=k.find(t.join(", "));i.isEmpty||i.close()}}),k.Observer(),((t,i,s)=>{if("undefined"==typeof window)return;const e=window[t]??{};e.It=!0,e.Vt=!1,e.Ft=i,Object.assign(e,s),Object.freeze(e),window[t]=e,console.log(`[${t}] v${i} loaded successfully`)})(_,R,{bind:e,find:n,destroy:h,rebind:o,effector:r,version:R}))}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",B):B()}t.bind=e,t.destroy=h,t.effector=r,t.find=n,t.name=_,t.rebind=o,t.version=R},"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).SelectiveUI={});
|
|
1
|
+
/*! Selective UI v1.1.2 | MIT License */
|
|
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={});
|
|
Binary file
|