lexgui 0.4.0 → 0.4.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.
@@ -1 +1 @@
1
- "use strict";console.warn("Script _build/lexgui.js_ is depracated and will be removed soon. Please use ES Modules or alternatives: https://jxarco.github.io/lexgui.js/docs/"),function(e){var t={version:"0.4.0",ready:!1,components:[],signals:{},extraCommandbarEntries:[],activeDraggable:null};function i(e,t,i){return Math.min(Math.max(e,t),i)}function a(e,t){return 0==t?Math.floor(e):+e.toFixed(t??2).replace(/([0-9]+(\.[0-9]+[1-9])?)(\.?0+$)/,"$1")}function l(e,t,i,a,l){return(e-t)*(l-a)/(i-t)+a}function s(e,t){setTimeout(e,t??0)}function n(e){return e.replace(/\s/g,"").replaceAll("@","_").replaceAll("+","_plus_").replaceAll(".","")}function r(e){return e.includes(".")?e.split(".").pop():null}function o(e){return JSON.parse(JSON.stringify(e))}function d(e){let t=parseInt(e.substring(1,3),16)/255,i=parseInt(e.substring(3,5),16)/255,a=parseInt(e.substring(5,7),16)/255;return[t,i,a]}function c(e){let t="#";for(let i of e)t+=(i=Math.floor(255*i)).toString(16);return t}function h(e,i=8){var a=document.createElement("span");a.className="lexinputmeasure",a.innerHTML=e,document.body.appendChild(a);var l=a.getBoundingClientRect();return t.UTILS.deleteElement(a),l.width+i}function u(){var e=function(){return((1+Math.random())*65536|0).toString(16).substring(1)};return e()+"-"+e()+"-"+e()}function p(e,a={}){let l=0,s=0,n=null,r=a.targetClass,o=a.dragMargin??3,d=(a,n,r)=>{let d=e.parentElement?e.parentElement.getBoundingClientRect():{x:0,y:0,width:0,height:0},c="fixed"==e.style.position,h=c?new t.vec2(d.x,d.y):new t.vec2;r=r??a.clientX-l-d.x,n=n??a.clientY-s-d.y,e.style.left=i(r,o+h.x,h.x+d.width-e.offsetWidth-o)+"px",e.style.top=i(n,o+h.y,h.y+d.height-e.offsetHeight-o)+"px",e.style.translate="none"};a.autoAdjust&&d(null,parseInt(e.style.left),parseInt(e.style.top));let c=t.UTILS.uidGenerator();e["draggable-id"]=c;let h=e=>{n&&d(e)},u=e=>{n&&a.onMove&&a.onMove(n)},p=a.onMove?u:h,m=a.onDragStart;e.setAttribute("draggable",!0),e.addEventListener("mousedown",function(e){n=e.target.classList.contains(r)||!r?e.target:null}),e.addEventListener("dragstart",function(i){if(i.preventDefault(),i.stopPropagation(),i.stopImmediatePropagation(),!n)return;var a=new Image;a.src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=",i.dataTransfer.setDragImage(a,0,0),i.dataTransfer.effectAllowed="move";let r=i.target.getBoundingClientRect(),o=n.parentElement.getBoundingClientRect(),d="fixed"==n.style.position,c=d?new t.vec2(o.x,o.y):new t.vec2;l=i.clientX-r.x-c.x,s=i.clientY-r.y-c.y,document.addEventListener("mousemove",p),n._eventCatched=!0,t.activeDraggable&&(t.activeDraggable.style.zIndex=t.DRAGGABLE_Z_INDEX),t.activeDraggable=e,t.activeDraggable.style.zIndex=t.DRAGGABLE_Z_INDEX+1,m&&m(n,i)},!1),document.addEventListener("mouseup",e=>{n&&(n=null,document.removeEventListener("mousemove",p))})}t.MOUSE_LEFT_CLICK=0,t.MOUSE_MIDDLE_CLICK=1,t.MOUSE_RIGHT_CLICK=2,t.MOUSE_DOUBLE_CLICK=2,t.MOUSE_TRIPLE_CLICK=3,t.CURVE_MOVEOUT_CLAMP=0,t.CURVE_MOVEOUT_DELETE=1,t.DRAGGABLE_Z_INDEX=101,t.clamp=i,t.round=a,t.remapRange=l,"undefined"!=typeof performance?t.getTime=performance.now.bind(performance):"undefined"!=typeof Date&&Date.now?t.getTime=Date.now.bind(Date):"undefined"!=typeof process?t.getTime=function(){var e=process.hrtime();return .001*e[0]+1e-6*e[1]}:t.getTime=function(){return new Date().getTime()},t.doAsync=s,t.getSupportedDOMName=n,t.has=function e(i){return t.components.indexOf(i)>-1},t.getExtension=r,t.deepCopy=o,t.setTheme=function e(i){i="light"==i?"light":"dark",document.documentElement.setAttribute("data-theme",i),t.emit("@on_new_color_scheme",i)},t.setThemeColor=function e(t,i){document.querySelector(":root").style.setProperty("--"+t,i)},t.getThemeColor=function e(t){let i=getComputedStyle(document.querySelector(":root")),a=i.getPropertyValue("--"+t);if(document.documentElement.getAttribute("data-theme"),a.includes("light-dark")){let l=i.getPropertyValue("color-scheme");return"light"==l?a.substring(a.indexOf("(")+1,a.indexOf(",")).replace(/\s/g,""):a.substring(a.indexOf(",")+1,a.indexOf(")")).replace(/\s/g,"")}return a},t.getBase64Image=function e(t){var i=document.createElement("canvas");return i.width=t.width,i.height=t.height,i.getContext("2d").drawImage(t,0,0),i.toDataURL("image/png")},t.hexToRgb=d,t.rgbToHex=c,t.measureRealWidth=h,t.guidGenerator=u,t.buildTextPattern=function e(t={}){let i=[];t.lowercase&&i.push("(?=.*[a-z])"),t.uppercase&&i.push("(?=.*[A-Z])"),t.digit&&i.push("(?=.*\\d)"),t.specialChar&&i.push("(?=.*[@#$%^&+=!])"),t.noSpaces&&i.push("(?!.*\\s)");let a,l=`^${i.join("")}.{${t.minLength||0},${t.maxLength||""}}$`;return t.asRegExp?RegExp(l):l},t.makeDraggable=p,t.makeCollapsible=function e(i,a,l,s={}){i.classList.add("collapsible");let n=s.collapsed??!0,r=t.makeIcon("Right");r.classList.add("collapser"),r.dataset.collapsed=n,r.style.marginLeft="auto",r.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation(),this.dataset.collapsed?(delete this.dataset.collapsed,a.style.display="block"):(this.dataset.collapsed=!0,a.style.display="none")}),i.appendChild(r),(l=l??i.parentElement).appendChild(a)},t.makeCodeSnippet=function e(i,a,l={}){if(!t.has("CodeEditor")){console.error("Import the CodeEditor component to create snippets!");return}let s=document.createElement("div");s.className="lexcodesnippet",s.style.width=a?a[0]:"auto",s.style.height=a?a[1]:"auto";let n=new v({noAppend:!0}),r=new t.CodeEditor(n,{skipInfo:!0,disableEdition:!0,allowAddScripts:!1,name:l.tabName});if(r.setText(i,l.language??"Plain Text"),l.linesAdded){let o=r.root.querySelector(".code");for(let d of l.linesAdded)if(d.constructor==Number)o.childNodes[d-1].classList.add("added");else if(d.constructor==Array)for(let c=d[0]-1;c<=d[1]-1;c++)o.childNodes[c].classList.add("added")}if(l.linesRemoved){let h=r.root.querySelector(".code");for(let u of l.linesRemoved)if(u.constructor==Number)h.childNodes[u-1].classList.add("removed");else if(u.constructor==Array)for(let p=u[0]-1;p<=u[1]-1;p++)h.childNodes[p].classList.add("removed")}if(l.windowMode){let m=document.createElement("div");m.className="lexwindowbuttons";let g=document.createElement("span");g.style.background="#ee4f50";let f=document.createElement("span");f.style.background="#f5b720";let $=document.createElement("span");$.style.background="#53ca29",m.appendChild(g),m.appendChild(f),m.appendChild($);let y=r.root.querySelector(".lexareatabs");y.prepend(m)}return(l.lineNumbers??!0)||r.root.classList.add("no-gutter"),s.appendChild(n.root),s},t.makeIcon=function e(i,a){let l=document.createElement("a");return l.title=a??"",l.className="lexicon",l.innerHTML=t.ICONS[i]??"",l},t.registerCommandbarEntry=function e(i,a){t.extraCommandbarEntries.push({name:i,callback:a})};class m{constructor(e,t){this.x=e??0,this.y=t??e??0}get xy(){return[this.x,this.y]}get yx(){return[this.y,this.x]}set(e,t){this.x=e,this.y=t}add(e,t=new m){return t.set(this.x+e.x,this.y+e.y),t}sub(e,t=new m){return t.set(this.x-e.x,this.y-e.y),t}mul(e,t=new m){return e.constructor==Number&&(e=new m(e)),t.set(this.x*e.x,this.y*e.y),t}div(e,t=new m){return e.constructor==Number&&(e=new m(e)),t.set(this.x/e.x,this.y/e.y),t}abs(e=new m){return e.set(Math.abs(this.x),Math.abs(this.y)),e}dot(e){return this.x*e.x+this.y*e.y}len2(){return this.dot(this)}len(){return Math.sqrt(this.len2())}nrm(e=new m){return e.set(this.x,this.y),e.mul(1/this.len(),e)}dst(e){return e.sub(this).len()}clp(e,t,a=new m){return a.set(i(this.x,e,t),i(this.y,e,t)),a}}t.vec2=m,t.init=function e(i={}){if(this.ready)return this.main_area;var a=document.createElement("div");a.id="lexroot",a.tabIndex=-1;var l=document.createElement("div");l.id="modal",this.modal=l,this.root=a,this.container=document.body,this.modal.classList.add("hiddenOpacity"),this.modal.toggle=function(e){this.classList.toggle("hiddenOpacity",e)},i.container&&(this.container=document.getElementById(i.container)),document.documentElement.setAttribute("data-strictVP",i.strictViewport??!0?"true":"false"),this.commandbar=function e(i){let a=document.createElement("dialog");a.className="commandbar",a.tabIndex=-1,i.appendChild(a);let l=[],s=null;a.addEventListener("keydown",function(e){if(e.stopPropagation(),e.stopImmediatePropagation(),s=s??-1,"Escape"==e.key)this.close(),g(!0);else if("Enter"==e.key){let t=l[s];if(t){let i=t.item.type&&"checkbox"===t.item.type;this.close(),i?(t.item.checked=!t.item.checked,t.callback.call(window,t.item.checked,t.entry_name)):t.callback.call(window,t.entry_name)}}else if("ArrowDown"==e.key&&s<l.length-1){s++,a.querySelectorAll(".hovered").forEach(e=>e.classList.remove("hovered")),l[s].classList.add("hovered");let n=l[s].offsetHeight*(s+1)-p.offsetHeight;n>0&&p.scrollTo({top:n,behavior:"smooth"})}else"ArrowUp"==e.key&&s>0&&(s--,a.querySelectorAll(".hovered").forEach(e=>e.classList.remove("hovered")),l[s].classList.add("hovered"))}),a.addEventListener("focusout",function(e){e.relatedTarget!=e.currentTarget&&(e.stopPropagation(),e.stopImmediatePropagation(),this.close(),g(!0))}),i.addEventListener("keydown",e=>{if(" "==e.key&&e.ctrlKey)e.stopImmediatePropagation(),e.stopPropagation(),t.setCommandbarState(!0);else for(let i of t.components){if(!t[i]||!t[i].prototype.onKeyPressed)continue;let a=t.CodeEditor.getInstances();for(let l of a)l.onKeyPressed(e)}});let n=document.createElement("div");n.className="gs-header";let r=document.createElement("a");r.className="fa-solid fa-magnifying-glass",n.appendChild(r);let o=document.createElement("input");o.placeholder="Search...",o.value="",n.appendChild(o);let d=new v({width:"100%",skipAppend:!0,className:"gs-tabs"}),c=d.addTabs(),h=null;{let u=(e,t)=>{h=t};c.add("All",document.createElement("div"),{selected:!0,onSelect:u})}let p=document.createElement("div");p.className="searchitembox";let m=null,g=e=>{p.innerHTML="",l.length=0,s=null,e&&(o.value="")},f=(e,i,n,r)=>{if(!e.length)return;m&&m.classList.remove("last");let o=document.createElement("div");o.className="searchitem last";let d=r&&r.type&&"checkbox"===r.type;d?o.innerHTML="<a class='fa fa-check'></a><span>"+(n+e)+"</span>":o.innerHTML=n+e,o.entry_name=e,o.callback=i,o.item=r,o.addEventListener("click",function(e){this.callback.call(window,this.entry_name),t.setCommandbarState(!1),g(!0)}),o.addEventListener("mouseenter",function(e){a.querySelectorAll(".hovered").forEach(e=>e.classList.remove("hovered")),this.classList.add("hovered"),s=l.indexOf(this)}),o.addEventListener("mouseleave",function(e){this.classList.remove("hovered")}),l.push(o),p.appendChild(o),m=o},$=(e,t,i)=>{let a=Object.keys(e)[0];if((e.name??i+a).toLowerCase().includes(t)&&e.callback&&f(e.name??a,e.callback,i,e),!e.name)for(let l of(i+=a+" > ",e[a]))$(l,t,i)};return a._addElements=e=>{for(let i of(g(),t.menubars))for(let a of i.items)$(a,e,"");for(let l of t.extraCommandbarEntries){let s=l.name;s.toLowerCase().includes(e)&&f(s,l.callback,"",{})}if(t.has("CodeEditor")){let n=t.CodeEditor.getInstances();if(!n.length)return;let r=n[0].languages;for(let o of Object.keys(r)){let d="Language: "+o,c=n[0]._getFileIcon(null,r[o].ext),h=c.includes("fa-")?"<i class='"+c+"'></i>":"<img src='https://raw.githubusercontent.com/jxarco/lexgui.js/master/"+c+"'>";h+=d+" <span class='lang-ext'>("+r[o].ext+")</span>",d.toLowerCase().includes(e)&&f(h,()=>{for(let e of n)e._changeLanguage(o)},"",{})}}},o.addEventListener("input",function(e){a._addElements(this.value.toLowerCase())}),a.appendChild(n),a.appendChild(d.root),a.appendChild(p),a}(this.container),this.container.appendChild(l),i.skipRoot?this.root=document.body:this.container.appendChild(a);{let s=document.createElement("section");s.className="notifications",this.notifications=document.createElement("ol"),this.notifications.className="",this.notifications.iWidth=0,s.appendChild(this.notifications),this.container.appendChild(s),this.notifications.addEventListener("mouseenter",()=>{this.notifications.classList.add("list")}),this.notifications.addEventListener("mouseleave",()=>{this.notifications.classList.remove("list")})}a.addEventListener("dragover",function(e){e.preventDefault()},!1),document.addEventListener("contextmenu",function(e){e.preventDefault()},!1);var n=document.getElementsByTagName("HEAD")[0],r=document.createElement("link");return r.rel="stylesheet",r.type="text/css",r.crossOrigin="anonymous",r.href="https://use.fontawesome.com/releases/v6.7.2/css/all.css",n.appendChild(r),this.DEFAULT_NAME_WIDTH="30%",this.DEFAULT_SPLITBAR_SIZE=4,this.OPEN_CONTEXTMENU_ENTRY="click",this.ready=!0,this.menubars=[],i.skipRoot||i.skipDefaultArea||(this.main_area=new v({id:i.id??"mainarea"})),(i.autoTheme??!0)&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: light)").matches&&(t.setTheme("light"),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",e=>{t.setTheme(e.matches?"dark":"light")})),this.main_area},t.setCommandbarState=function e(t,i=!0){let a=this.commandbar;t?(a.show(),a.querySelector("input").focus(),i&&a._addElements(void 0)):a.close()},t.message=function e(t,i,a={}){if(!t)throw"No message to show";return a.modal=!0,new _(i,e=>{e.addTextArea(null,t,null,{disabled:!0,fitHeight:!0})},a)},t.popup=function e(t,i,a={}){if(!t)throw"No message to show";a.size=a.size??["max-content","auto"],a.class="lexpopup";let l=a.timeout||3e3,s=new _(i,e=>{e.addTextArea(null,t,null,{disabled:!0,fitHeight:!0})},a);return setTimeout(()=>{s.close()},Math.max(l,150)),s},t.prompt=function e(t,i,a,l={}){l.modal=!0,l.className="prompt";let s="",n=new _(i,r=>{r.addTextArea(null,t,null,{disabled:!0,fitHeight:!0}),(l.input??!0)&&r.addText(null,l.input||s,e=>s=e,{placeholder:"..."}),r.sameLine(2),r.addButton(null,"Cancel",()=>{l.on_cancel&&l.on_cancel(),n.close()}),r.addButton(null,l.accept||"Continue",()=>{l.required&&""===s?(t+=t.includes("You must fill the input text.")?"":"\nYou must fill the input text.",n.close(),e(t,i,a,l)):(a&&a.call(this,s),n.close())},{buttonClass:"primary"})},l);return(l.input??!0)&&n.root.querySelector("input").focus(),n},t.toast=function e(t,i,a={}){if(!t)throw"The toast needs at least a title!";console.assert(this.notifications);let l=document.createElement("li");l.className="lextoast",l.style.translate="0 calc(100% + 30px)",this.notifications.prepend(l),s(()=>{this.notifications.offsetWidth>this.notifications.iWidth&&(this.notifications.iWidth=Math.min(this.notifications.offsetWidth,480),this.notifications.style.width=this.notifications.iWidth+"px"),l.dataset.open=!0},10);let n=document.createElement("div");n.className="lextoastcontent",l.appendChild(n);let r=document.createElement("div");if(r.className="title",r.innerHTML=t,n.appendChild(r),i){let o=document.createElement("div");o.className="desc",o.innerHTML=i,n.appendChild(o)}if(a.action){let d=new L;d.addButton(null,a.action.name??"Accept",a.action.callback.bind(this,l),{width:"auto",maxWidth:"150px",className:"right",buttonClass:"outline"}),l.appendChild(d.root.childNodes[0])}let c=this;if(l.close=function(){this.dataset.closed=!0,s(()=>{this.remove(),c.notifications.childElementCount||(c.notifications.style.width="unset",c.notifications.iWidth=0)},500)},a.closable??!0){let h=document.createElement("a");h.className="fa fa-xmark lexicon closer",h.addEventListener("click",()=>{l.close()}),l.appendChild(h)}let u=a.timeout??3e3;-1!=u&&s(()=>{l.close()},u)},t.badge=function e(t,i,a={}){let l=document.createElement("div");return l.innerHTML=t,l.className="lexbadge "+(i??""),Object.assign(l.style,a.style??{}),l.outerHTML},t.makeContainer=function e(t,i,a={}){let l=document.createElement("div");return l.className="lexcontainer "+(i??""),l.style.width=t&&t[0]?t[0]:"100%",l.style.height=t&&t[1]?t[1]:"100%",Object.assign(l.style,a),l};class g{constructor(e,t,i){this.name=e,this.value=t,this.domEvent=i}}t.IEvent=g;class f{static NONE=0;static NODE_SELECTED=1;static NODE_DELETED=2;static NODE_DBLCLICKED=3;static NODE_CONTEXTMENU=4;static NODE_DRAGGED=5;static NODE_RENAMED=6;static NODE_VISIBILITY=7;static NODE_CARETCHANGED=8;constructor(e,t,i){this.type=e||f.NONE,this.node=t,this.value=i,this.multiple=!1,this.panel=null}string(){switch(this.type){case f.NONE:return"tree_event_none";case f.NODE_SELECTED:return"tree_event_selected";case f.NODE_DELETED:return"tree_event_deleted";case f.NODE_DBLCLICKED:return"tree_event_dblclick";case f.NODE_CONTEXTMENU:return"tree_event_contextmenu";case f.NODE_DRAGGED:return"tree_event_dragged";case f.NODE_RENAMED:return"tree_event_renamed";case f.NODE_VISIBILITY:return"tree_event_visibility";case f.NODE_CARETCHANGED:return"tree_event_caretchanged"}}}t.TreeEvent=f,t.emit=function e(i,a,l={}){let s=t.signals[i];if(!s)return;let n=l.target;if(n){n[i]&&n[i].call(n,a);return}for(let r of s)if(r.constructor===b)r.set(a,l.skipCallback??!0),r.options&&r.options.callback&&r.options.callback(a,s);else{let o=r;o(null,a)}},t.addSignal=function e(i,a,l){a[i]=l,t.signals[i]||(t.signals[i]=[]),!(t.signals[i].indexOf(a)>-1)&&t.signals[i].push(a)};class v{constructor(e={}){var i=document.createElement("div");i.className="lexarea",e.id&&(i.id=e.id),e.className&&(i.className+=" "+e.className);var a=e.width||"calc( 100% )",l=e.height||"100%";this.setLimitBox(e.minWidth,e.minHeight,e.maxWidth,e.maxHeight),a.constructor==Number&&(a+="px"),l.constructor==Number&&(l+="px"),i.style.width=a,i.style.height=l,this.offset=0,this.root=i,this.size=[this.root.offsetWidth,this.root.offsetHeight],this.sections=[],this.panels=[],!e.skipAppend&&document.getElementById("lexroot").appendChild(this.root);let s=e.overlay;if(s){this.root.classList.add("overlay-"+s),e.left?this.root.style.left=e.left:e.right?this.root.style.right=e.right:e.top?this.root.style.top=e.top:e.bottom&&(this.root.style.bottom=e.bottom);let n=e.draggable??!0;if(n&&p(i,e),e.resizeable&&i.classList.add("resizeable"),e.resize){if(this.splitBar=document.createElement("div"),this.type=s,this.splitBar.className="lexsplitbar "+("left"==s||"right"==s?"horizontal":"vertical"),"right"==s)this.splitBar.style.width=t.DEFAULT_SPLITBAR_SIZE+"px",this.splitBar.style.left=-(t.DEFAULT_SPLITBAR_SIZE/2)+"px";else if("left"==s){let r=Math.min(document.body.clientWidth-t.DEFAULT_SPLITBAR_SIZE,this.root.clientWidth);this.splitBar.style.width=t.DEFAULT_SPLITBAR_SIZE+"px",this.splitBar.style.left=r+t.DEFAULT_SPLITBAR_SIZE/2+"px"}else if("top"==s){let o=Math.min(document.body.clientHeight-t.DEFAULT_SPLITBAR_SIZE,this.root.clientHeight);this.splitBar.style.height=t.DEFAULT_SPLITBAR_SIZE+"px",this.splitBar.style.top=o+t.DEFAULT_SPLITBAR_SIZE/2+"px"}else"bottom"==s&&(this.splitBar.style.height=t.DEFAULT_SPLITBAR_SIZE+"px",this.splitBar.style.top=-(t.DEFAULT_SPLITBAR_SIZE/2)+"px");this.splitBar.addEventListener("mousedown",function e(t){var i=d.root.ownerDocument;i.addEventListener("mousemove",h),i.addEventListener("mouseup",u),c[0]=t.x,c[1]=t.y,t.stopPropagation(),t.preventDefault(),document.body.classList.add("nocursor"),d.splitBar.classList.add("nocursor")}),this.root.appendChild(this.splitBar);var d=this,c=[0,0];function h(e){switch(d.type){case"right":var i=c[0]-e.x,a=d.root.offsetWidth+i;d.root.style.width=a+"px";break;case"left":var i=c[0]-e.x,a=Math.min(document.body.clientWidth-t.DEFAULT_SPLITBAR_SIZE,d.root.offsetWidth-i);d.root.style.width=a+"px",d.splitBar.style.left=a+t.DEFAULT_SPLITBAR_SIZE/2+"px";break;case"top":var i=c[1]-e.y,a=Math.min(document.body.clientHeight-t.DEFAULT_SPLITBAR_SIZE,d.root.offsetHeight-i);d.root.style.height=a+"px",d.splitBar.style.top=a+t.DEFAULT_SPLITBAR_SIZE/2+"px";break;case"bottom":var i=c[1]-e.y,a=d.root.offsetHeight+i;d.root.style.height=a+"px"}c[0]=e.x,c[1]=e.y,e.stopPropagation(),e.preventDefault(),d.onresize&&d.onresize(d.root.getBoundingClientRect())}function u(e){var t=d.root.ownerDocument;t.removeEventListener("mousemove",h),t.removeEventListener("mouseup",u),document.body.classList.remove("nocursor"),d.splitBar.classList.remove("nocursor")}}}}attach(e){if(this.sections.length){this.sections[1].attach(e);return}if(!e)throw"no content to attach";e.parent=this;let t=e.root?e.root:e;this.root.appendChild(t)}split(e={}){this.sections.length&&(this.offset=this.root.childNodes[0].offsetHeight,this._root=this.sections[0].root,this.root=this.sections[1].root);var i=e.type||"horizontal",a=e.sizes||["50%","50%"],l="auto"===e.sizes;if(!a[1]){let s=a[0],n=e.top?e.top:0;s.constructor==Number&&(s+=n,s+="px"),a[1]="calc( 100% - "+s+" )"}var r=new v({skipAppend:!0,className:"split"+(e.menubar||e.sidebar?"":" origin")}),o=new v({skipAppend:!0,className:"split"});r.parentArea=this,o.parentArea=this;let d=e.minimizable??!1,c=(e.resize??!0)||d;var h="0px";if(this.offset=0,c&&(this.resize=c,this.splitBar=document.createElement("div"),this.splitBar.className="lexsplitbar "+i,"horizontal"==i?this.splitBar.style.width=t.DEFAULT_SPLITBAR_SIZE+"px":this.splitBar.style.height=t.DEFAULT_SPLITBAR_SIZE+"px",this.splitBar.addEventListener("mousedown",function e(t){var i=y.root.ownerDocument;i.addEventListener("mousemove",E),i.addEventListener("mouseup",x),t.stopPropagation(),t.preventDefault(),document.body.classList.add("nocursor"),y.splitBar.classList.add("nocursor")}),h=t.DEFAULT_SPLITBAR_SIZE/2+"px",d&&(this.splitExtended=!1,o.root.addEventListener("animationend",e=>{let t=getComputedStyle(o.root).opacity;o.root.classList.remove(e.animationName+"-"+i),o.root.style.opacity=t,$(o.root)}),this.splitBar.addEventListener("contextmenu",e=>{e.preventDefault(),k(null,e,e=>{e.add("Extend",{disabled:this.splitExtended,callback:()=>{this.extend()}}),e.add("Reduce",{disabled:!this.splitExtended,callback:()=>{this.reduce()}})})}))),"horizontal"==i){var u=a[0],p=a[1];u.constructor==Number&&(u+="px"),p.constructor==Number&&(p+="px"),r.root.style.width="calc( "+u+" - "+h+" )",r.root.style.height="calc(100% - 0px)",o.root.style.width="calc( "+p+" - "+h+" )",o.root.style.height="calc(100% - 0px)",this.root.style.display="flex"}else if(r.root.style.width="100%",o.root.style.width="100%",l){r.root.style.height="auto";let m=new ResizeObserver(e=>{for(let t of e){let i=t.contentRect;o.root.style.height="calc(100% - "+(i.height+4)+"px )"}});m.observe(r.root)}else{var g=a[0],f=a[1];g.constructor==Number&&(g+="px"),f.constructor==Number&&(f+="px"),r.root.style.width="100%",r.root.style.height="auto"==g?g:"calc( "+g+" - "+h+" )",o.root.style.height="auto"==f?f:"calc( "+f+" - "+h+" )"}if(this.root.appendChild(r.root),c&&this.root.appendChild(this.splitBar),this.root.appendChild(o.root),this.sections=[r,o],this.type=i,this._update(),!c)return this.sections;var y=this;function E(e){"horizontal"==y.type?y._moveSplit(-e.movementX):y._moveSplit(-e.movementY);let t=y.root.querySelectorAll(".lexwidget");for(let i of t){let a=i.jsInstance;a.onresize&&a.onresize()}e.stopPropagation(),e.preventDefault()}function x(e){var t=y.root.ownerDocument;t.removeEventListener("mousemove",E),t.removeEventListener("mouseup",x),document.body.classList.remove("nocursor"),y.splitBar.classList.remove("nocursor")}return this.sections}setLimitBox(e=0,t=0,i=1/0,a=1/0){this.minWidth=e,this.minHeight=t,this.maxWidth=i,this.maxHeight=a}setSize(e){let[t,i]=e;void 0!=t&&t.constructor==Number&&(t+="px"),void 0!=i&&i.constructor==Number&&(i+="px"),t&&(this.root.style.width=t),i&&(this.root.style.height=i),this.onresize&&this.onresize(this.root.getBoundingClientRect()),s(()=>{this.size=[this.root.clientWidth,this.root.clientHeight],this.propagateEvent("onresize")},150)}extend(){if(this.splitExtended)return;let[e,t]=this.sections;this.splitExtended=!0,"vertical"==this.type?(this.offset=t.root.offsetHeight,t.root.classList.add("fadeout-vertical"),this._moveSplit(-1/0,!0)):(this.offset=t.root.offsetWidth-8,t.root.classList.add("fadeout-horizontal"),this._moveSplit(-1/0,!0,8)),s(()=>this.propagateEvent("onresize"),150)}reduce(){if(!this.splitExtended)return;this.splitExtended=!1;let[e,t]=this.sections;"vertical"==this.type?(t.root.classList.add("fadein-vertical"),this._moveSplit(this.offset)):(t.root.classList.add("fadein-horizontal"),this._moveSplit(this.offset)),s(()=>this.propagateEvent("onresize"),150)}hide(){this.root.classList.add("hidden")}show(){this.root.classList.remove("hidden")}toggle(e){this.root.classList.toggle("hidden",e)}propagateEvent(e){for(var t=0;t<this.sections.length;t++){let i=this.sections[t];i[e]&&i[e].call(this,i.root.getBoundingClientRect()),i.propagateEvent(e)}}addPanel(e){let t=new L(e);return this.attach(t),this.panels.push(t),t}addMenubar(e,i={}){let a=new E(i);e&&e(a),t.menubars.push(a);let[l,s]=this.split({type:"vertical",sizes:[48,null],resize:!1,menubar:!0});return a.siblingArea=s,l.attach(a),l.isMenubar=!0,(i.sticky??!0)&&l.root.classList.add("sticky"),a}addSidebar(e,i={}){let a=new x(i);e&&e(a),a._build(),t.menubars.push(a);let l=i.width??"16rem",[s,n]=this.split({type:"horizontal",sizes:[l,null],resize:!1,sidebar:!0});return a.siblingArea=n,s.attach(a),s.isSidebar=!0,a}addOverlayButtons(e,t={}){if(this.sections.length){this.sections[1].addOverlayButtons(e,t);return}console.assert(e.constructor==Array&&e.length),this.root.style.position="relative",t.className="lexoverlaybuttons";let i=this.addPanel(t),a=null,l=document.createElement("div");l.className="lexoverlaybuttonscontainer",l.appendChild(i.root),this.attach(l);let s=t.float;if(s)for(var n=0;n<s.length;n++){let r=s[n];switch(r){case"h":case"t":case"l":break;case"v":l.className+=" vertical";break;case"m":l.className+=" middle";break;case"b":l.className+=" bottom";break;case"c":l.className+=" center";break;case"r":l.className+=" right"}}let o=function(e,t,l){let s={width:"auto",selectable:e.selectable,selected:e.selected,icon:e.icon,img:e.img,className:e.class};t&&(a||((a=document.createElement("div")).className="lexoverlaygroup",i.queuedContainer=a),s.parent=a);let n=e.callback;e.options?i.addDropdown(null,e.options,e.name,n,s):i.addButton(null,e.name,function(t,i){if(e.selectable){if(e.group){let a=e.selected;e.group.forEach(e=>e.selected=!1),e.selected=!a}else e.selected=!e.selected}n(t,i)},s),a&&l&&(i.root.appendChild(a),a=null,i.clearQueue())};!function(){for(let t of(i.clear(),e))if(t.constructor===Array)for(let a=0;a<t.length;++a){let n=t[a];n.group=t,o(n,!0,a==t.length-1)}else o(t);if(s){var r=0;i.root.childNodes.forEach(e=>{r+=e.offsetHeight}),l.className.includes("middle")&&(l.style.top="-moz-calc( 50% - "+.5*r+"px )",l.style.top="-webkit-calc( 50% - "+.5*r+"px )",l.style.top="calc( 50% - "+.5*r+"px )")}}()}addTabs(e={}){let t=new y(this,e);return e.folding&&(this.parentArea._disableSplitResize(),this.root.style.paddingTop="4px"),t}_moveSplit(e,i=!1,a=0){if(!this.type)throw"No split area";if(void 0===e)return;let l=this.sections[0];var s=l.root;s.classList.contains("origin")||(s=s.parentElement);let n=this.sections[1],r=n.root,o=" - "+t.DEFAULT_SPLITBAR_SIZE+"px",d=null;if(i||(d=s.style.transition,s.style.transition=r.style.transition="none",$(s),$(r)),"horizontal"==this.type){var c=Math.max(r.offsetWidth+e,parseInt(n.minWidth));a&&(c=a),s.style.width="-moz-calc( 100% - "+c+"px "+o+" )",s.style.width="-webkit-calc( 100% - "+c+"px "+o+" )",s.style.width="calc( 100% - "+c+"px "+o+" )",s.style.minWidth=parseInt(l.minWidth)+"px",r.style.width=c+"px",l.maxWidth!=1/0&&(r.style.minWidth="calc( 100% - "+parseInt(l.maxWidth)+"px )")}else{var c=Math.max(r.offsetHeight+e+n.offset,parseInt(n.minHeight));a&&(c=a),s.style.height="-moz-calc( 100% - "+c+"px "+o+" )",s.style.height="-webkit-calc( 100% - "+c+"px "+o+" )",s.style.height="calc( 100% - "+c+"px "+o+" )",s.style.minHeight=l.minHeight+"px",r.style.height=c-n.offset+"px"}i||(s.style.transition=r.style.transition=d),this._update(),this.propagateEvent("onresize")}_disableSplitResize(){this.resize=!1,this.splitBar.remove(),delete this.splitBar}_update(){let e=this.root.getBoundingClientRect();this.size=[e.width,e.height];for(var t=0;t<this.sections.length;t++)this.sections[t]._update()}}function $(e){e.offsetHeight}t.Area=v;class y{static TAB_SIZE=28;static TAB_ID=0;constructor(e,i={}){this.onclose=i.onclose;let a=document.createElement("div");a.className="lexareatabs "+(i.fit?"fit":"row");let l=i.folding??!1;l&&a.classList.add("folding");let s=this;if(a.addEventListener("dragenter",function(e){e.preventDefault(),this.classList.add("dockingtab")}),a.addEventListener("dragleave",function(e){e.preventDefault(),this.classList.remove("dockingtab")}),a.addEventListener("drop",function(e){e.preventDefault();let i=e.dataTransfer.getData("source"),a=document.getElementById(i);if(!a)return;this.appendChild(a);let l=document.getElementById(i+"_content");s.area.attach(l),this.classList.remove("dockingtab"),t.emit("@on_tab_docked"),a.instance=s,a.click(),s.tabs[a.dataset.name]=l}),e.root.classList.add("lexareatabscontainer"),e.split({type:"vertical",sizes:i.sizes??"auto",resize:!1,top:6}),e.sections[0].attach(a),this.area=e.sections[1],this.area.root.className+=" lexareatabscontent",this.selected=null,this.root=a,this.tabs={},this.tabDOMs={},i.fit){let n=document.createElement("span");n.className="lexareatab thumb",this.thumb=n,this.root.appendChild(n);let r=new ResizeObserver(e=>{let t=this.thumb.item;if(t){var i=this.thumb.style.transition;this.thumb.style.transition="none",this.thumb.style.transform="translate( "+t.childIndex*t.offsetWidth+"px )",this.thumb.style.width=t.offsetWidth-5+"px",this.thumb.style.height=t.offsetHeight-6+"px",$(this.thumb),this.thumb.style.transition=i}});r.observe(this.area.root)}if(l){this.folded=!0,this.folding=l,"up"==l&&e.root.insertChildAtIndex(e.sections[1].root,0);let o=new ResizeObserver(t=>{for(let i of t){let a=i.contentRect,l=e.parentArea.sections[0].root;l.style.height="calc(100% - "+(42+a.height)+"px )"}});o.observe(this.area.root),this.area.root.classList.add("folded")}}add(e,i,a={}){let l=a.selected??!1;l&&(this.root.querySelectorAll("span").forEach(e=>e.classList.remove("selected")),this.area.root.querySelectorAll(".lextabcontent").forEach(e=>e.style.display="none")),l=!Object.keys(this.tabs).length&&!this.folding||l;let s=i.root?i.root:i;s.originalDisplay=s.style.display,s.style.display=l?s.originalDisplay:"none",s.classList.add("lextabcontent"),a.icon&&(a.icon.includes("fa-")?a.icon="<i class='"+a.icon+"'></i>":a.icon="<img src='https://raw.githubusercontent.com/jxarco/lexgui.js/master/"+a.icon+"'>");let n=document.createElement("span");n.dataset.name=e,n.className="lexareatab"+(l?" selected":""),n.innerHTML=(a.icon??"")+e,n.id=e.replace(/\s/g,"")+y.TAB_ID++,n.title=a.title??"",n.selected=l??!1,n.fixed=a.fixed,n.instance=this,s.id=n.id+"_content",n.selected&&(this.selected=e),t.addSignal("@on_tab_docked",n,function(){1==this.parentElement.childNodes.length&&this.parentElement.childNodes[0].click()}),n.addEventListener("click",e=>{if(e.preventDefault(),e.stopPropagation(),!n.fixed){let t=n.selected;n.parentElement.querySelectorAll("span").forEach(e=>e.selected=!1),n.selected=!t,n.parentElement.querySelectorAll("span").forEach(e=>e.classList.remove("selected")),n.classList.toggle("selected",this.folding&&n.selected),n.instance.area.root.querySelectorAll(".lextabcontent").forEach(e=>e.style.display="none"),s.style.display=s.originalDisplay,n.instance.selected=n.dataset.name}this.folding&&(this.folded=n.selected,this.area.root.classList.toggle("folded",!this.folded)),a.onSelect&&a.onSelect(e,n.dataset.name),this.thumb&&(this.thumb.style.transform="translate( "+n.childIndex*n.offsetWidth+"px )",this.thumb.style.width=n.offsetWidth-5+"px",this.thumb.style.height=n.offsetHeight-6+"px",this.thumb.item=n)}),n.addEventListener("contextmenu",e=>{e.preventDefault(),e.stopPropagation(),a.onContextMenu&&a.onContextMenu(e,n.dataset.name)}),n.addEventListener("mouseup",e=>{e.preventDefault(),e.stopPropagation(),1==e.button&&this.delete(n.dataset.name)}),n.setAttribute("draggable",!0),n.addEventListener("dragstart",function(e){if(1==this.parentElement.childNodes.length){e.preventDefault();return}e.dataTransfer.setData("source",e.target.id)}),n.childIndex=this.root.childElementCount-1,this.root.appendChild(n),this.area.attach(s),this.tabDOMs[e]=n,this.tabs[e]=i,setTimeout(()=>{a.onCreate&&a.onCreate.call(this,this.area.root.getBoundingClientRect()),l&&this.thumb&&(this.thumb.style.transform="translate( "+n.childIndex*n.offsetWidth+"px )",this.thumb.style.width=n.offsetWidth-5+"px",this.thumb.style.height=n.offsetHeight-6+"px",this.thumb.item=n)},10)}select(e){this.tabDOMs[e]&&this.tabDOMs[e].click()}delete(e){let t=this.tabDOMs[e];if(!t||t.fixed)return;this.onclose&&this.onclose(e),this.tabDOMs[e].remove(),delete this.tabDOMs[e],this.tabs[e].remove(),delete this.tabs[e];let i=this.root.lastChild;i&&!i.fixed&&this.root.lastChild.click()}}t.Tabs=y;class E{constructor(e={}){this.root=document.createElement("div"),this.root.className="lexmenubar",e.float&&(this.root.style.justifyContent=e.float),this.items=[],this.buttons=[],this.icons={},this.shorts={}}add(e,i={}){i.constructor==Function&&(i={callback:i});let a=e.split("/"),l=a[a.length-1];this.icons[l]=i.icon,this.shorts[l]=i.short;let n=0,r=this,o=(e,t)=>{if(void 0==e)return;let l=null;if(t.forEach(t=>{let i=Object.keys(t),a=i.find(t=>t==e);a&&(l=t[a])}),l)o(a[n++],l);else{let s={};s[e]=[];let r=a[n++];r||(s.callback=i.callback,s.disabled=i.disabled,s.type=i.type,s.checked=i.checked),t.push(s),o(r,s[e])}};for(let d of(o(a[n++],this.items),this.items)){let c=Object.keys(d)[0],h=c.replace(/\s/g,"").replaceAll(".","");if(this.root.querySelector("#"+h))continue;let u=document.createElement("div");u.className="lexmenuentry",u.id=h,u.innerHTML="<span>"+c+"</span>",u.tabIndex="1","left"==i.position?this.root.prepend(u):("right"==i.position&&(u.right=!0),this.root.lastChild&&this.root.lastChild.right?this.root.lastChild.before(u):this.root.appendChild(u));let p=function(){r.root.querySelectorAll(".lexmenuentry").forEach(e=>{e.classList.remove("selected"),e.built=!1}),t.root.querySelectorAll(".lexmenubox").forEach(e=>e.remove()),r.focused=!1},m=function(e,i,a,l){let n=document.createElement("div");n.className="lexmenubox",n.tabIndex="0",a.currentMenu=n;let o=a.classList.contains("lexmenuboxentry");o&&(n.dataset.submenu=!0);var d=a.getBoundingClientRect();n.style.left=(o?d.x+d.width:d.left)+"px",n.style.top=(o?d.y:d.bottom-4)+"px",d=n.getBoundingClientRect(),s(()=>{n.dataset.open=!0},10),t.root.appendChild(n);for(var c=0;c<e[i].length;++c){let h=e[i][c],u=Object.keys(h)[0],g=h[u].length,f="checkbox"==h.type,v=document.createElement("div");if(v.className="lexmenuboxentry",v.className+=(c==e[i].length-1?" last":"")+(h.disabled?" disabled":""),""==u)v.className=" lexseparator";else{v.id=u;let $=document.createElement("div");$.innerHTML="",$.classList="lexmenuboxentrycontainer",v.appendChild($);let y=r.icons[u];f?$.innerHTML+="<input type='checkbox' >":y?$.innerHTML+="<a class='"+y+" fa-sm'></a>":($.innerHTML+="<a class='fa-solid fa-sm noicon'></a>",$.classList.add("noicon")),$.innerHTML+="<div class='lexentryname'>"+u+"</div>"}let E=v.querySelector("input");if(E&&(E.checked=h.checked??!1,E.addEventListener("change",e=>{h.checked=E.checked;let t=h.callback;t&&(t.call(this,h.checked,u,v),p()),e.stopPropagation(),e.stopImmediatePropagation()})),n.appendChild(v),""==u)continue;if(n.addEventListener("keydown",function(e){e.preventDefault();let t=r.shorts[u];t&&(t=1==t.length?t.toLowerCase():t)==e.key&&v.click()}),v.addEventListener("click",e=>{E&&(h.checked=!h.checked);let t=h.callback;t&&(t.call(this,E?h.checked:u,E?u:v),p()),e.stopPropagation(),e.stopImmediatePropagation()}),!g){if(r.shorts[u]){let x=document.createElement("div");x.className="lexentryshort",x.innerText=r.shorts[u],v.appendChild(x)}continue}let b=document.createElement("a");b.className="fa-solid fa-angle-right fa-xs",v.appendChild(b),v.addEventListener("mouseover",e=>{!v.built&&(v.built=!0,m(h,u,v,++l),e.stopPropagation())}),v.addEventListener("mouseleave",e=>{v.currentMenu&&v.currentMenu!=e.toElement&&(l=-1,delete v.built,v.currentMenu.remove(),delete v.currentMenu)})}n.style.width=n.offsetWidth+"px"},g=()=>{p(),u.classList.add("selected"),u.built=!0,m(d,c,u,-1)};u.addEventListener("click",()=>{let e=d.callback;if(e){e.call(this,c,u);return}g(),this.focused=!0}),u.addEventListener("mouseover",e=>{this.focused&&!u.built&&g()}),u.addEventListener("blur",e=>{!(e.relatedTarget&&e.relatedTarget.classList.contains("lexmenubox"))&&p()})}}getButton(e){return this.buttons[e]}getSubitem(e,t){let i=null,a=t[0];for(let l=0;l<e.length;l++)if(e[l][a]){if(1==t.length)return e[l];return t.splice(0,1),this.getSubitem(e[l][a],t)}}getItem(e){let t=e.split("/");return this.getSubitem(this.items,t)}setButtonIcon(e,t,i,a={}){let l=this.buttons[e];if(l)l.querySelector("a").className="fa-solid "+t+" lexicon";else{let s=document.createElement("div"),n=a.disabled??!1;s.className="lexmenubutton"+(n?" disabled":""),s.title=e??"",s.innerHTML="<a class='"+t+" lexicon' style='font-size:x-large;'></a>",s.style.padding="5px 10px",s.style.maxHeight="calc(100% - 10px)",s.style.alignItems="center","right"==a.float&&(s.right=!0),this.root.lastChild&&this.root.lastChild.right?this.root.lastChild.before(s):"left"==a.float?this.root.prepend(s):this.root.appendChild(s);let r=s.querySelector("a");r.addEventListener("click",e=>{i&&!n&&i.call(this,r,e)})}}setButtonImage(e,t,i,a={}){let l=this.buttons[e];if(l)l.querySelector("a").className="fa-solid "+icon+" lexicon";else{let s=document.createElement("div"),n=a.disabled??!1;s.className="lexmenubutton"+(n?" disabled":""),s.title=e??"",s.innerHTML="<a><image src='"+t+"' class='lexicon' style='height:32px;'></a>",s.style.padding="5px",s.style.alignItems="center","right"==a.float&&(s.right=!0),this.root.lastChild&&this.root.lastChild.right?this.root.lastChild.before(s):"left"==a.float?this.root.prepend(s):this.root.appendChild(s);let r=s.querySelector("a");r.addEventListener("click",e=>{i&&!n&&i.call(this,r,e)})}}addButtons(e,t={}){if(!e)throw"No buttons to add!";this.buttonContainer||(this.buttonContainer=document.createElement("div"),this.buttonContainer.className="lexmenubuttons",this.buttonContainer.classList.add(t.float??"center"),"right"==t.position&&(this.buttonContainer.right=!0),this.root.lastChild&&this.root.lastChild.right?this.root.lastChild.before(this.buttonContainer):this.root.appendChild(this.buttonContainer));for(let i=0;i<e.length;++i){let a=e[i],l=document.createElement("label"),s=a.title,n=a.disabled??!1;l.className="lexmenubutton"+(n?" disabled":""),l.title=s??"",this.buttonContainer.appendChild(l);let r=document.createElement("a");r.className=a.icon+" lexicon",l.appendChild(r);let o=r;if(a.swap){l.classList.add("swap"),r.classList.add("swap-off");let d=document.createElement("input");d.type="checkbox",l.prepend(d),o=d;let c=document.createElement("a");c.className=a.swap+" swap-on lexicon",l.appendChild(c),l.swap=function(){let e=this.querySelector("input");e.checked=!e.checked},l.setState=function(e){let t=this.querySelector("input");t.checked=e}}o.addEventListener("click",e=>{if(a.callback&&!n){let t=l.querySelector("input");a.callback.call(this,e,t?.checked)}}),s&&(this.buttons[s]=l)}}}t.Menubar=E;class x{constructor(e={}){this.root=document.createElement("div"),this.root.className="lexsidebar",window.sidebar=this,this.collapsable=e.collapsable??!0,this.collapseWidth=e.collapseToIcons??!0?"58px":"0px",this.collapsed=!1,s(()=>{this.root.parentElement.ogWidth=this.root.parentElement.style.width,this.root.parentElement.style.transition="width 0.25s ease-out",this.resizeObserver=new ResizeObserver(e=>{for(let t of e)this.siblingArea.setSize(["calc(100% - "+t.contentRect.width+"px )",null])})},100);let i=32;if(!e.skipHeader){this.header=document.createElement("div"),this.header.className="lexsidebarheader",this.root.appendChild(this.header),this.header.addEventListener("click",t=>{this.collapsed?(t.preventDefault(),t.stopPropagation(),this.toggleCollapsed()):e.onHeaderPressed&&e.onHeaderPressed(t)});let a=document.createElement("span");if(a.className="lexavatar",this.header.appendChild(a),e.headerImage){let l=document.createElement("img");l.src=e.headerImage,a.appendChild(l)}else if(e.headerIcon){let n=t.makeIcon(e.headerIcon);a.appendChild(n)}{let r=document.createElement("div");this.header.appendChild(r);let o=document.createElement("span");o.innerHTML=e.headerTitle??"",r.appendChild(o);let d=document.createElement("span");d.innerHTML=e.headerSubtitle??"",r.appendChild(d)}if(this.collapsable){let c=t.makeIcon("Sidebar","Toggle Sidebar");this.header.appendChild(c),c.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),this.toggleCollapsed()})}i+=52}if(this.content=document.createElement("div"),this.content.className="lexsidebarcontent",this.root.appendChild(this.content),!e.skipFooter){this.footer=document.createElement("div"),this.footer.className="lexsidebarfooter",this.root.appendChild(this.footer),this.footer.addEventListener("click",t=>{e.onFooterPressed&&e.onFooterPressed(t)});let h=document.createElement("span");if(h.className="lexavatar",this.footer.appendChild(h),e.footerImage){let u=document.createElement("img");u.src=e.footerImage,h.appendChild(u)}else if(e.footerIcon){let p=t.makeIcon(e.footerIcon);h.appendChild(p)}{let m=document.createElement("div");this.footer.appendChild(m);let g=document.createElement("span");g.innerHTML=e.footerTitle??"",m.appendChild(g);let f=document.createElement("span");f.innerHTML=e.footerSubtitle??"",m.appendChild(f)}let v=t.makeIcon("MenuArrows");this.footer.appendChild(v),i+=52}this.content.style.height=`calc(100% - ${i}px)`,this.items=[],this.icons={},this.groups={}}toggleCollapsed(){this.collapsable&&(this.collapsed=!this.collapsed,this.collapsed?(this.root.classList.add("collapsing"),this.root.parentElement.style.width=this.collapseWidth):(this.root.classList.remove("collapsing"),this.root.classList.remove("collapsed"),this.root.parentElement.style.width=this.root.parentElement.ogWidth),this.resizeObserver.observe(this.root.parentElement),s(()=>{this.root.classList.toggle("collapsed",this.collapsed),this.resizeObserver.unobserve(this.root.parentElement)},250))}separator(){this.currentGroup=null,this.add("")}group(e,t){this.currentGroup=e,this.groups[e]=t}add(e,t={}){t.constructor==Function&&(t={callback:t});let i=e.split("/"),a=i[i.length-1];this.icons[a]=t.icon;let l=0,s=(e,a)=>{if(void 0==e)return;let n=null;if(a.forEach(t=>{let i=Object.keys(t),a=i.find(t=>t==e);a&&(n=t[a])}),n)s(i[l++],n);else{let r={};r[e]=[];let o=i[l++];o||(r.callback=t.callback,r.group=this.currentGroup,r.options=t),a.push(r),s(o,r[e])}};s(i[l++],this.items)}select(e){let t=e.replace(/\s/g,"").replaceAll(".",""),i=this.items.find(e=>e.name===t);i&&i.domEl.click()}_build(){for(let e of this.items){let i=e.options??{};if(e.dom)continue;let a=Object.keys(e)[0],l=a.replace(/\s/g,"").replaceAll(".",""),s=null,n=document.createElement("div");if(n.className="lexsidebarentry "+(i.className??""),n.id=l,e.group){let r=e.group.replace(/\s/g,"").replaceAll(".","");if(s=this.content.querySelector("#"+r)){if(!s.classList.contains("lexsidebargroup"))throw"Bad id: "+e.group}else{(s=document.createElement("div")).id=r,s.className="lexsidebargroup",this.content.appendChild(s);let o=document.createElement("div");o.className="lexsidebargrouptitle",s.appendChild(o);let d=document.createElement("div");if(d.innerHTML=e.group,o.appendChild(d),null!=this.groups[e.group]){let c=document.createElement("a");c.className=(this.groups[e.group].icon??"")+" lexicon",o.appendChild(c),c.addEventListener("click",t=>{this.groups[e.group].callback&&this.groups[e.group].callback(e.group,t)})}}}if(""==l){let h=document.createElement("div");h.className="lexsidebarseparator",this.content.appendChild(h);continue}this.collapseContainer?(this.collapseContainer.appendChild(n),this.collapseQueue--,this.collapseQueue||delete this.collapseContainer):s?s.appendChild(n):this.content.appendChild(n);let u=document.createElement("div");if(n.appendChild(u),e.dom=u,"checkbox"==i.type){e.value=i.value??!1;let p=new L;e.checkbox=p.addCheckbox(null,e.value,(t,l)=>{l.preventDefault(),l.stopPropagation();let s=i.callback;e.value=t,s&&s.call(this,a,t,l)},{label:a,signal:"@checkbox_"+a}),u.appendChild(p.root.childNodes[0])}else{if(i.icon){let m=document.createElement("i");m.className=i.icon,u.appendChild(m)}let g=document.createElement("a");g.innerHTML=a,u.appendChild(g)}if(n.addEventListener("click",t=>{if(!(t.target&&t.target.classList.contains("lexcheckbox"))){if(i.collapsable)u.querySelector(".collapser").click();else{let l=i.callback;l&&l.call(this,a,e.value,t),e.checkbox&&(e.value=!e.value,e.checkbox.set(e.value,!0))}this.root.querySelectorAll(".lexsidebarentry").forEach(e=>e.classList.remove("selected")),n.classList.add("selected")}}),i.action){let f=t.makeIcon(i.action.icon??"MoreHorizontal",i.action.name);u.appendChild(f),f.addEventListener("click",e=>{e.preventDefault(),e.stopImmediatePropagation();let t=i.action.callback;t&&t.call(this,a,e)})}else if(i.collapsable){let v=document.createElement("div");Object.assign(v.style,{width:"100%",display:"none"}),t.makeCollapsible(u,v,s??this.content),this.collapseQueue=i.collapsable,this.collapseContainer=v}let $=document.createElement("span");if($.className="lexsidebarentrydesc",$.innerHTML=a,n.appendChild($),u.addEventListener("mouseenter",()=>{setTimeout(()=>{$.style.display="unset"},150)}),u.addEventListener("mouseleave",()=>{setTimeout(()=>{$.style.display="none"},150)}),!e[a].length)continue;let y=document.createElement("div");y.className="lexsidebarsubentrycontainer",s?s.appendChild(y):this.content.appendChild(y);for(var E=0;E<e[a].length;++E){let x=e[a][E],b=x.options??{},w=Object.keys(x)[0],C=document.createElement("div");if(C.innerHTML=`<span>${w}</span>`,b.action){let _=t.makeIcon(b.action.icon??"MoreHorizontal",b.action.name);C.appendChild(_),_.addEventListener("click",e=>{e.preventDefault(),e.stopImmediatePropagation();let t=b.action.callback;t&&t.call(this,w,e)})}C.className="lexsidebarentry",C.id=w,y.appendChild(C),C.addEventListener("click",e=>{let t=b.callback;t&&t.call(this,w,C,e),this.root.querySelectorAll(".lexsidebarentry").forEach(e=>e.classList.remove("selected")),n.classList.add("selected")})}}}}t.SideBar=x;class b{static NONE=0;static TEXT=1;static TEXTAREA=2;static BUTTON=3;static DROPDOWN=4;static CHECKBOX=5;static TOGGLE=6;static RADIO=7;static COLOR=8;static RANGE=9;static NUMBER=10;static TITLE=11;static VECTOR=12;static TREE=13;static PROGRESS=14;static FILE=15;static LAYERS=16;static ARRAY=17;static LIST=18;static TAGS=19;static CURVE=20;static CARD=21;static IMAGE=22;static CONTENT=23;static CUSTOM=24;static SEPARATOR=25;static KNOB=26;static SIZE=27;static PAD=28;static FORM=29;static DIAL=30;static COUNTER=31;static TABLE=32;static NO_CONTEXT_TYPES=[b.BUTTON,b.LIST,b.FILE,b.PROGRESS];constructor(e,t,i){this.name=e,this.type=t,this.options=i}value(){if(this.onGetValue)return this.onGetValue();console.warn("Can't get value of "+this.typeName())}set(e,t=!1,i=""){if(this.onSetValue)return this.onSetValue(e,t);console.warn("Can't set value of "+this.typeName())}oncontextmenu(e){b.NO_CONTEXT_TYPES.includes(this.type)||k(this.typeName(),e,e=>{e.add("Copy",()=>{this.copy()}),e.add("Paste",{disabled:!this._can_paste(),callback:()=>{this.paste()}})})}copy(){navigator.clipboard.type=this.type,navigator.clipboard.customIdx=this.customIdx,navigator.clipboard.data=this.value(),navigator.clipboard.writeText(navigator.clipboard.data)}_can_paste(){return this.type===b.CUSTOM?void 0!==navigator.clipboard.customIdx&&this.customIdx==navigator.clipboard.customIdx:navigator.clipboard.type===this.type}paste(){this._can_paste()&&this.set(navigator.clipboard.data)}typeName(){switch(this.type){case b.TEXT:return"Text";case b.TEXTAREA:return"TextArea";case b.BUTTON:return"Button";case b.DROPDOWN:return"Dropdown";case b.CHECKBOX:return"Checkbox";case b.TOGGLE:return"Toggle";case b.RADIO:return"Radio";case b.COLOR:return"Color";case b.RANGE:return"Range";case b.NUMBER:return"Number";case b.VECTOR:return"Vector";case b.TREE:return"Tree";case b.PROGRESS:return"Progress";case b.FILE:return"File";case b.LAYERS:return"Layers";case b.ARRAY:return"Array";case b.LIST:return"List";case b.TAGS:return"Tags";case b.CURVE:return"Curve";case b.KNOB:return"Knob";case b.SIZE:return"Size";case b.PAD:return"Pad";case b.FORM:return"Form";case b.DIAL:return"Dial";case b.COUNTER:return"Counter";case b.TABLE:return"Table";case b.CUSTOM:return this.customName}console.error(`Unknown Widget type: ${this.type}`)}refresh(){}}t.Widget=b,t.ADD_CUSTOM_WIDGET=function e(i,a={}){let l=u();L.prototype["add"+i]=function(e,s,n){let r=this.create_widget(e,b.CUSTOM,a);r.customName=i,r.customIdx=l,r.onGetValue=()=>s,r.onSetValue=(t,i)=>{s=t,p(),d.querySelector(".lexcustomitems").toggleAttribute("hidden",!1),i||this._trigger(new g(e,s,null),n)};let d=r.domEl;d.style.flexWrap="wrap";let c,h,u=a.default??{},p=()=>{s&&(r.instance=s=Object.assign(o(u),s)),c&&c.remove(),h&&h.remove(),(c=document.createElement("div")).className="lexcustomcontainer",c.style.width="calc( 100% - "+t.DEFAULT_NAME_WIDTH+")",this.queue(c);let l="<a class='fa-solid "+(a.icon??"fa-cube")+"' style='float:left'></a>";l+=i+(s?"":" [empty]"),l+="<a class='fa-solid "+(s?"fa-bars-staggered":" ")+" menu' style='float:right; width:5%;'></a>";let m=this.addButton(null,l,(e,t)=>{s?d.querySelector(".lexcustomitems").toggleAttribute("hidden"):k(null,t,e=>{e.add("New "+i,()=>{s={},p(),d.querySelector(".lexcustomitems").toggleAttribute("hidden",!1)})})},{buttonClass:"custom"});if(this.clearQueue(),s&&m.querySelector("a.menu").addEventListener("click",e=>{e.stopImmediatePropagation(),e.stopPropagation(),k(null,e,e=>{e.add("Clear",()=>{s=null,p()})})}),(h=document.createElement("div")).className="lexcustomitems",h.toggleAttribute("hidden",!0),d.appendChild(c),d.appendChild(h),s){this.queue(h);let f=(t,i,a)=>{s[t]=i,this._trigger(new g(e,s,a),n)};for(let v in u){let $=s[v]??u[v];switch($.constructor){case String:"#"===$[0]?this.addColor(v,$,f.bind(this,v)):this.addText(v,$,f.bind(this,v));break;case Number:this.addNumber(v,$,f.bind(this,v));break;case Boolean:this.addCheckbox(v,$,f.bind(this,v));break;case Array:$.length>4?this.addArray(v,$,f.bind(this,v)):this._add_vector($.length,v,$,f.bind(this,v))}}this.clearQueue()}};p()}};class w{constructor(e,t,i){if(this.domEl=e,this.data=t,this.onevent=i.onevent,this.options=i,this.selected=[],t.constructor===Object)this._create_item(null,t);else for(let a of t)this._create_item(null,a)}_create_item(e,i,a=0,l){let s=this,n=this.domEl.querySelector("#lexnodetree_filter");if(i.children=i.children??[],n&&!i.id.includes(n.value)||void 0!=l&&l!=i.id){for(var r=0;r<i.children.length;++r)this._create_item(i,i.children[r],a+1,l);return}let o=this.domEl.querySelector("ul");i.visible=i.visible??!0,i.parent=e;let d=i.children.length>0,c=this.selected.indexOf(i)>-1||i.selected;if(this.options.onlyFolders){let h=!1;i.children.forEach(e=>h|="folder"==e.type),d=!!h}let u=document.createElement("li");u.className="lextreeitem datalevel"+a+(d?" parent":"")+(c?" selected":""),u.id=t.getSupportedDOMName(i.id),u.tabIndex="0";let p=this.options.skip_default_icon??!0?"":"fa-solid fa-square";d&&(p=i.closed?"fa-solid fa-caret-right":"fa-solid fa-caret-down"),u.innerHTML="<a class='"+p+" hierarchy'></a>",p=i.icon,i.icon&&(i.icon.includes("fa-")?u.innerHTML+="<a class='"+i.icon+" tree-item-icon'></a>":u.innerHTML+="<img src='https://raw.githubusercontent.com/jxarco/lexgui.js/master/"+i.icon+"'>"),u.innerHTML+=i.rename?"":i.id,u.setAttribute("draggable",!0),u.style.paddingLeft=(d?0:3)+(3+(a+1)*15)+"px",o.appendChild(u),u.addEventListener("click",e=>{if(g){g=!1;return}e.shiftKey||(o.querySelectorAll("li").forEach(e=>{e.classList.remove("selected")}),this.selected.length=0);let t=this.selected.indexOf(i);if(t>-1?(u.classList.remove("selected"),this.selected.splice(t,1)):(u.classList.add("selected"),this.selected.push(i)),d&&i.id.length>1){if(i.closed=!1,s.onevent){let a=new f(f.NODE_CARETCHANGED,i,i.closed);s.onevent(a)}s.frefresh(i.id)}if(s.onevent){let l=new f(f.NODE_SELECTED,e.shiftKey?this.selected:i);l.multiple=e.shiftKey,s.onevent(l)}}),u.addEventListener("dblclick",function(){if((s.options.rename??!0)&&(i.rename=!0,s.refresh()),s.onevent){let e=new f(f.NODE_DBLCLICKED,i);s.onevent(e)}}),u.addEventListener("contextmenu",e=>{if(e.preventDefault(),!s.onevent)return;let a=new f(f.NODE_CONTEXTMENU,this.selected.length>1?this.selected:i,e);a.multiple=this.selected.length>1,t.addContextMenu(a.multiple?"Selected Nodes":a.node.id,a.value,e=>{a.panel=e}),s.onevent(a),(this.options.addDefault??!1)==!0&&(a.panel.items&&a.panel.add(""),a.panel.add("Select Children",()=>{let e=t=>{if(!t.closed)for(let i of t.children??[]){if(i)this.domEl.querySelector("#"+i.id).classList.add("selected"),this.selected.push(i),e(i)}};e(i)}),a.panel.add("Delete",{callback:()=>{if(!i.parent)return;if(s.onevent){let t=new f(f.NODE_DELETED,i,e);s.onevent(t)}let a=i.parent.children,l=a.indexOf(i);a.splice(l,1),this.refresh()}}))}),u.addEventListener("keydown",e=>{if(!i.rename){if(e.preventDefault(),"Delete"==e.key){if(s.onevent){let a=new f(f.NODE_DELETED,this.selected.length>1?this.selected:i,e);a.multiple=this.selected.length>1,s.onevent(a)}for(let l of this.selected){let n=l.parent.children,r=n.indexOf(l);n.splice(r,1)}this.selected.length=0,this.refresh()}else if("ArrowUp"==e.key||"ArrowDown"==e.key){var o=this.selected.length>1?"ArrowUp"==e.key?this.selected.shift():this.selected.pop():this.selected[0],d=this.domEl.querySelector("#"+t.getSupportedDOMName(o.id)),c="ArrowUp"==e.key?d.previousSibling:d.nextSibling;c&&c.click()}}});let m=document.createElement("input");m.toggleAttribute("hidden",!i.rename),m.value=i.id,u.appendChild(m),i.rename&&(u.classList.add("selected"),m.focus()),m.addEventListener("keyup",function(e){if("Enter"==e.key){if(this.value=this.value.replace(/\s/g,"_"),s.onevent){let a=new f(f.NODE_RENAMED,i,this.value);s.onevent(a)}i.id=t.getSupportedDOMName(this.value),delete i.rename,s.frefresh(i.id),o.querySelector("#"+i.id).classList.add("selected")}else"Escape"==e.key&&(delete i.rename,s.frefresh(i.id))}),m.addEventListener("blur",function(e){delete i.rename,s.refresh()}),(this.options.draggable??!0)&&(e&&u.addEventListener("dragstart",e=>{window.__tree_node_dragged=i}),u.addEventListener("dragover",e=>{e.preventDefault()},!1),u.addEventListener("dragenter",e=>{e.target.classList.add("draggingover")}),u.addEventListener("dragleave",e=>{e.target.classList.remove("draggingover")}),u.addEventListener("drop",e=>{e.preventDefault();let t=window.__tree_node_dragged;if(!t)return;let a=i;if(t.id==a.id){console.warn("Cannot parent node to itself!");return}let l=function(e,t){var i=!1;for(var a of t.children){if(a.id==e.id)return!0;i|=l(e,a)}return i};if(l(a,t)){console.warn("Cannot parent node to a current child!");return}if(s.onevent){let n=new f(f.NODE_DRAGGED,t,a);s.onevent(n)}let r=t.parent.children.findIndex(e=>e.id==t.id),o=t.parent.children.splice(r,1);a.children.push(o[0]),s.refresh(),delete window.__tree_node_dragged}));let g=!1;if(d&&u.querySelector("a.hierarchy").addEventListener("click",function(e){if(g=!0,e.stopImmediatePropagation(),e.stopPropagation(),i.closed=!i.closed,s.onevent){let t=new f(f.NODE_CARETCHANGED,i,i.closed);s.onevent(t)}s.frefresh(i.id)}),!i.skipVisibility){let v=document.createElement("a");v.className="itemicon fa-solid fa-eye"+(i.visible?"":"-slash"),v.title="Toggle visible",v.addEventListener("click",function(e){if(e.stopPropagation(),i.visible=void 0!==i.visible&&!i.visible,this.className="itemicon fa-solid fa-eye"+(i.visible?"":"-slash"),s.onevent){let t=new f(f.NODE_VISIBILITY,i,i.visible);s.onevent(t)}}),u.appendChild(v)}if(i.actions)for(var r=0;r<i.actions.length;++r){let $=i.actions[r];var y=document.createElement("a");y.className="itemicon "+$.icon,y.title=$.name,y.addEventListener("click",function(e){$.callback(i,y),e.stopPropagation()}),u.appendChild(y)}if(void 0!=l&&i.id==l&&(this.selected=[i],u.click()),!i.closed)for(var r=0;r<i.children.length;++r){let E=i.children[r];(!this.options.onlyFolders||"folder"==E.type)&&this._create_item(i,E,a+1)}}refresh(e,t){this.data=e??this.data,this.domEl.querySelector("ul").innerHTML="",this._create_item(null,this.data,0,t)}frefresh(e){this.refresh();var t=this.domEl.querySelector("#"+e);t&&t.focus()}select(e){this.refresh(null,e)}}class L{constructor(e={}){var t=document.createElement("div");t.className="lexpanel",e.id&&(t.id=e.id),e.className&&(t.className+=" "+e.className),t.style.width=e.width||"calc( 100% - 6px )",t.style.height=e.height||"100%",Object.assign(t.style,e.style??{}),this._inline_widgets_left=-1,this._inline_queued_container=null,this.root=t,this.onevent=e=>{},this.branch_open=!1,this.branches=[],this.current_branch=null,this.widgets={},this._queue=[]}get(e){return this.widgets[e]}getValue(e){let t=this.widgets[e];if(!t)throw"No widget called "+e;return t.value()}setValue(e,t,i){let a=this.widgets[e];if(!a)throw"No widget called "+e;return a.set(t,i)}attach(e){if(!e)throw"no content to attach";e.parent=this;let t=e.root?e.root:e;this.root.appendChild(t)}clear(){for(let e in this.branch_open=!1,this.branches=[],this.current_branch=null,this.widgets)if(this.widgets[e].options&&this.widgets[e].options.signal){let i=this.widgets[e].options.signal;for(let a=0;a<t.signals[i].length;a++)t.signals[i][a]==this.widgets[e]&&(t.signals[i]=[...t.signals[i].slice(0,a),...t.signals[i].slice(a+1)])}if(this.signals)for(let l=0;l<this.signals.length;l++){let s=Object.values(this.signals[l])[0],n=s.options.signal;for(let r=0;r<t.signals[n].length;r++)t.signals[n][r]==s&&(t.signals[n]=[...t.signals[n].slice(0,r),...t.signals[n].slice(r+1)])}this.widgets={},this.root.innerHTML=""}sameLine(e){this._inline_queued_container=this.queuedContainer,this._inline_widgets_left=e||1/0}endLine(e){if(-1==this._inline_widgets_left){console.warn("No pending widgets to be inlined!");return}for(let t of(this._inline_widgets_left=-1,!this._inlineContainer&&(this._inlineContainer=document.createElement("div"),this._inlineContainer.className="lexinlinewidgets",e&&(this._inlineContainer.style.justifyContent=e)),this._inlineWidgets)){let i=t.constructor==Array;i?this._inline_queued_container?this._inlineContainer.appendChild(t[0]):t[1].appendChild(t[0]):this._inlineContainer.appendChild(t)}this._inline_queued_container?this._inline_queued_container.appendChild(this._inlineContainer):this.current_branch?this.current_branch.content.appendChild(this._inlineContainer):this.root.appendChild(this._inlineContainer),delete this._inlineWidgets,delete this._inlineContainer}branch(e,t={}){this.branch_open&&this.merge();var i=new C(e,t);return i.panel=this,this.branch_open=!0,this.current_branch=i,0==this.branches.length&&i.root.classList.add("first"),this.root.querySelectorAll(".lexbranch.last").forEach(e=>{e.classList.remove("last")}),i.root.classList.add("last"),this.branches.push(i),this.root.appendChild(i.root),t.filter&&this._addFilter(t.filter,{callback:this._searchWidgets.bind(this,i.name)}),i}merge(){this.branch_open=!1,this.current_branch=null}_pick(e,t){return void 0===e?t:e}static _dispatch_event(e,t,i,a,l){let s=new CustomEvent(t,{detail:i,bubbles:a,cancelable:l});e.dispatchEvent(s)}static _add_reset_property(e,t){var i=document.createElement("a");return i.style.display="none",i.style.marginRight="6px",i.className="lexicon fa fa-rotate-left",i.addEventListener("click",t),e.appendChild(i),i}create_widget(e,i,a={}){let l=new b(e,i,a),s=document.createElement("div");if(s.className="lexwidget",s.id=a.id??"",s.title=a.title??"",a.className&&(s.className+=" "+a.className),i!=b.TITLE&&(s.style.width="calc(100% - "+(this.current_branch||i==b.FILE?10:20)+"px)",a.width&&(s.style.width=s.style.minWidth=a.width),a.maxWidth&&(s.style.maxWidth=a.maxWidth),a.minWidth&&(s.style.minWidth=a.minWidth),a.height&&(s.style.height=s.style.minHeight=a.height)),void 0!=e){if(!a.hideName){let n=document.createElement("div");n.className="lexwidgetname",a.justifyName&&n.classList.add("float-"+a.justifyName),n.innerHTML=e||"",n.title=a.title??n.innerHTML,n.style.width=a.nameWidth||t.DEFAULT_NAME_WIDTH,s.appendChild(n),s.domName=n,n.addEventListener("contextmenu",function(e){e.preventDefault(),l.oncontextmenu(e)})}this.widgets[e]=l}return a.signal&&(e||(this.signals||(this.signals=[]),this.signals.push({[a.signal]:l})),t.addSignal(a.signal,l)),l.domEl=s,s.jsInstance=l,this._inline_widgets_left>0&&!a.skipInlineCount?(this._inlineWidgets||(this._inlineWidgets=[]),(e=>{this.queuedContainer?this._inlineWidgets.push([e,this.queuedContainer]):this._inlineWidgets.push(e)})(s),this._inline_widgets_left--,this._inline_widgets_left||this.endLine()):(e=>{a.container?a.container.appendChild(e):this.queuedContainer?this.queuedContainer.appendChild(e):this.current_branch?(a.skipWidget||this.current_branch.widgets.push(l),this.current_branch.content.appendChild(e)):(e.classList.add("nobranch"),this.root.appendChild(e))})(s),l}_addFilter(e,t={}){t.placeholder=e.constructor==String?e:"Filter properties..",t.skipWidget=t.skipWidget??!0,t.skipInlineCount=!0;let i=this.create_widget(null,b.TEXT,t).domEl;i.className+=" lexfilter noname";let a=document.createElement("input");a.className="lexinput-filter",a.setAttribute("placeholder",t.placeholder),a.style.width="calc( 100% - 17px )",a.value=t.filterValue||"";let l=document.createElement("a");return l.className="fa-solid fa-magnifying-glass",i.appendChild(l),i.appendChild(a),a.addEventListener("input",e=>{t.callback&&t.callback(a.value,e)}),i}_searchWidgets(e,t){for(let i of this.branches){if(i.name!==e)continue;for(let a of i.widgets)!a.domEl.classList.contains("lexfilter")&&a.domEl.remove();this.queue(i.content);let l=!t.length;for(let s of i.widgets){if(!l){if(!s.name)continue;t.toLowerCase();let n=s.name.toLowerCase();if(!n.includes(t))continue}this.queuedContainer.appendChild(s.domEl)}this.clearQueue();return}}_filterOptions(e,t){let i=!t.length,a=[];for(let l=0;l<e.length;l++){let s=e[l];if(!i){let n="string"==typeof s?s:s.value,r=t.toLowerCase(),o=n.toLowerCase();if(!o.includes(r))continue}a.push(s)}this.refresh(a)}_trigger(e,t){t&&t.call(this,e.value,e.domEvent,e.name),this.onevent&&this.onevent.call(this,e)}getBranch(e){return e?this.branches.find(t=>t.name==e):this.current_branch}queue(e){!e&&this.current_branch&&(e=this.current_branch.root),this.queuedContainer&&this._queue.push(this.queuedContainer),this.queuedContainer=e}clearQueue(){if(this._queue&&this._queue.length){this.queuedContainer=this._queue.pop();return}delete this.queuedContainer}addBlank(e=8,t){let i=this.create_widget(null,b.addBlank);return i.domEl.className+=" blank",i.domEl.style.height=e+"px",t&&(i.domEl.style.width=t),i}addTitle(e,t={}){if(!e)throw"Can't create Title without text!";let i=this.create_widget(null,b.TITLE,t).domEl;if(i.className="lextitle",t.icon){let a=document.createElement("a");a.className=t.icon,a.style.color=t.iconColor||"",i.appendChild(a)}let l=document.createElement("span");if(l.innerText=e,i.appendChild(l),Object.assign(i.style,t.style??{}),void 0!=t.link){let s=document.createElement("a");s.innerText=e,s.href=t.link,s.target=t.target??"",s.className="lextitle link",Object.assign(s.style,t.style??{}),i.replaceWith(s)}return i}addText(e,i,a,l={}){let s=this.create_widget(e,b.TEXT,l);s.onGetValue=()=>o.value,s.onSetValue=(e,t)=>{this.disabled?o.innerText=e:o.value=e,L._dispatch_event(o,"focusout",t)},s.valid=()=>{if(""==o.pattern)return!0;let e=RegExp(o.pattern);return e.test(o.value)};let n=s.domEl;s.name&&!l.skipReset&&L._add_reset_property(n.domName,function(){o.value=o.iValue,this.style.display="none",L._dispatch_event(o,"focusout")});let r=document.createElement("div");r.className="lextext"+(l.warning?" lexwarning":""),r.style.width=l.inputWidth||"calc( 100% - "+t.DEFAULT_NAME_WIDTH+" )",r.style.display="flex",l.textClass&&r.classList.add(l.textClass),this.disabled=(l.disabled||l.warning)??!!l.url;let o=null;if(this.disabled){o=document.createElement(l.url?"a":"div"),l.url&&(o.href=l.url,o.target="_blank");let d=l.warning?'<i class="fa-solid fa-triangle-exclamation"></i>':"";o.innerHTML=d+i||"",o.style.width="100%",o.style.textAlign=l.float??""}else{(o=document.createElement("input")).type=l.type||"",o.value=o.iValue=i||"",o.style.width="100%",o.style.textAlign=l.float??"",o.setAttribute("placeholder",l.placeholder??""),l.required&&o.setAttribute("required",l.required),l.pattern&&o.setAttribute("pattern",l.pattern);var c=(function(t,i){if(!s.valid())return;let l=i.detail,r=n.querySelector(".lexwidgetname .lexicon");r&&(r.style.display=t!=o.iValue?"block":"none"),l||this._trigger(new g(e,t,i),a)}).bind(this);let h=l.trigger??"default";if("default"==h?(o.addEventListener("keyup",function(e){"Enter"==e.key&&c(e.target.value,e)}),o.addEventListener("focusout",function(e){c(e.target.value,e)})):"input"==h&&o.addEventListener("input",function(e){c(e.target.value,e)}),o.addEventListener("mousedown",function(e){e.stopImmediatePropagation(),e.stopPropagation()}),l.icon){let u=document.createElement("a");u.className="inputicon "+l.icon,r.appendChild(u)}}return Object.assign(o.style,l.style??{}),r.appendChild(o),n.appendChild(r),s.name||(n.className+=" noname",r.style.width="100%"),s}addTextArea(e,i,a,l={}){let n=this.create_widget(e,b.TEXTAREA,l);n.onGetValue=()=>d.value,n.onSetValue=(e,t)=>{d.value=e,L._dispatch_event(d,"focusout",t)};let r=n.domEl;n.name&&!l.skipReset&&L._add_reset_property(r.domName,function(){d.value=d.iValue,this.style.display="none",L._dispatch_event(d,"focusout")});let o=document.createElement("div");o.className="lextextarea",o.style.width=l.inputWidth||"calc( 100% - "+t.DEFAULT_NAME_WIDTH+" )",o.style.height=l.height,o.style.display="flex";let d=document.createElement("textarea");d.value=d.iValue=i||"",d.style.width="100%",d.style.textAlign=l.float??"",Object.assign(d.style,l.style??{}),l.disabled&&d.setAttribute("disabled",!0),l.placeholder&&d.setAttribute("placeholder",l.placeholder);var c=(function(t,i){let l=i.detail,s=r.querySelector(".lexwidgetname .lexicon");s&&(s.style.display=t!=d.iValue?"block":"none"),l||this._trigger(new g(e,t,i),a)}).bind(this);let h=l.trigger??"default";if("default"==h?(d.addEventListener("keyup",function(e){"Enter"==e.key&&c(e.target.value,e)}),d.addEventListener("focusout",function(e){c(e.target.value,e)})):"input"==h&&d.addEventListener("input",function(e){c(e.target.value,e)}),l.icon){let u=document.createElement("a");u.className="inputicon "+l.icon,o.appendChild(u)}return o.appendChild(d),r.appendChild(o),n.name||(r.className+=" noname",o.style.width="100%"),s(()=>{l.fitHeight&&(d.style.height=d.scrollHeight+"px")},10),n}addLabel(e,t={}){return t.disabled=!0,this.addText(null,e,null,t)}addButton(e,i,a,l={}){let s=this.create_widget(e,b.BUTTON,l);s.onGetValue=()=>r.innerText,s.onSetValue=(e,t)=>{r.innerHTML=l.icon?"<a class='"+l.icon+"'></a>":l.img?"<img src='"+l.img+"'>":"<span>"+(e||"")+"</span>"};let n=s.domEl;var r=document.createElement("button");return r.title=l.title??"",r.className="lexbutton "+(l.buttonClass??""),l.selected&&r.classList.add("selected"),r.innerHTML=l.icon?"<a class='"+l.icon+"'></a>":l.img?"<img src='"+l.img+"'>":"<span>"+(i||"")+"</span>",r.style.width="calc( 100% - "+(l.nameWidth??t.DEFAULT_NAME_WIDTH)+")",l.disabled&&r.setAttribute("disabled",!0),r.addEventListener("click",t=>{l.selectable&&(l.parent&&l.parent.querySelectorAll(".lexbutton.selected").forEach(e=>{e!=r&&e.classList.remove("selected")}),r.classList.toggle("selected")),this._trigger(new g(e,i,t),a)}),n.appendChild(r),s.name||(r.className+=" noname",r.style.width="100%"),n}addComboButtons(e,i,a={}){let l=this.create_widget(e,b.BUTTON,a),s=l.domEl,n=this,r=document.createElement("div");r.className="lexcombobuttons ",a.float&&(r.className+=a.float),r.style.width="calc( 100% - "+t.DEFAULT_NAME_WIDTH+")";let o=document.createElement("div");o.className="lexcombobuttonsbox ";let d=!a.noSelection,c=d&&(a.toggle??!1);for(let h of i){if(!h.value)throw"Set 'value' for each button!";let u=document.createElement("button");u.className="lexbutton combo",u.title=h.icon?h.value:"",u.id=h.id??"",a.buttonClass&&u.classList.add(a.buttonClass),d&&(h.selected||a.selected==h.value)&&u.classList.add("selected"),u.innerHTML=(h.icon?"<a class='"+h.icon+"'></a>":"")+"<span>"+(h.icon?"":h.value)+"</span>",h.disabled&&u.setAttribute("disabled",!0),u.addEventListener("click",function(t){d&&(c?this.classList.toggle("selected"):(r.querySelectorAll("button").forEach(e=>e.classList.remove("selected")),this.classList.add("selected"))),n._trigger(new g(e,h.value,t),h.callback)}),o.appendChild(u)}return l.name||(s.className+=" noname",r.style.width="100%"),r.appendChild(o),s.appendChild(r),l}addCard(e,t={}){t.hideName=!0;let i=this.create_widget(e,b.CARD,t),a=i.domEl,l=document.createElement("div");if(l.className="lexcard",l.style.width="100%",t.img){let s=document.createElement("img");s.src=t.img,l.appendChild(s),void 0!=t.link&&(s.style.cursor="pointer",s.addEventListener("click",function(){let e=l.querySelector("a");e&&e.click()}))}let n=document.createElement("span");if(n.innerText=e,void 0!=t.link){let r=document.createElement("a");r.innerText=e,r.href=t.link,r.target=t.target??"",n.innerText="",n.appendChild(r)}return l.appendChild(n),t.callback&&(l.style.cursor="pointer",l.addEventListener("click",i=>{this._trigger(new g(e,null,i),t.callback)})),a.appendChild(l),i}addForm(e,i,a,l={}){if(i.constructor!=Object){console.error("Form data must be an Object");return}l.hideName=!0;let s=this.create_widget(e,b.FORM,l);s.onGetValue=()=>r.formData,s.onSetValue=(e,i)=>{r.formData=e;let a=r.querySelectorAll(".lexwidget");for(let l=0;l<a.length;++l){let s=a[l];if(s.jsInstance.type!=t.Widget.TEXT)continue;let n=a[l].querySelector(".lexwidgetname").innerText,o=a[l].querySelector(".lextext input");o.value=e[n]??"",L._dispatch_event(o,"focusout",i)}};let n=s.domEl,r=document.createElement("div");for(let o in r.className="lexformdata",this.queue(r),r.formData={},i){let d=i[o];d.constructor!=Object&&(d={}),d.placeholder=d.placeholder??o,d.width="calc(100% - 10px)",this.addLabel(o,{textClass:"formlabel"}),d.textWidget=this.addText(null,d.constructor==Object?d.value:d,e=>{r.formData[o]=e},d),r.formData[o]=d.constructor==Object?d.value:d}return this.addBlank(),this.addButton(null,l.actionName??"Submit",(e,t)=>{for(let l in i)if(!i[l].textWidget.valid())return;a&&a(r.formData,t)},{buttonClass:"primary",width:"calc(100% - 10px)"}),this.clearQueue(),n.appendChild(r),(!s.name||l.hideName)&&(n.className+=" noname",r.style.width="100%"),s}addContent(e,t={}){if(!e)return;if(e.constructor==String){let i=document.createElement("div");i.innerHTML=e,e=i.childElementCount>1?i:i.firstElementChild}let a=this.create_widget(null,b.CONTENT,t);return a.domEl.appendChild(e),a}async addImage(e,t={}){if(!e)return;t.hideName=!0;let i=this.create_widget(null,b.IMAGE,t),a=i.domEl,l=document.createElement("div");l.className="leximage",l.style.width="100%";let s=document.createElement("img");for(let n in s.src=e,t.style)s.style[n]=t.style[n];return await s.decode(),l.appendChild(s),a.appendChild(l),i}addDropdown(e,i,a,l,s={}){let n=this.create_widget(e,b.DROPDOWN,s);n.onGetValue=()=>r.querySelector("li.selected").getAttribute("value"),n.onSetValue=(t,i)=>{let s=r.querySelector(".lexwidgetname .lexicon");s&&(s.style.display=t!=c.iValue?"block":"none"),a=t,f.querySelectorAll("li").forEach(e=>{e.getAttribute("value")==a&&e.click()}),i||this._trigger(new g(e,a,null),l)};let r=n.domEl,o=this;n.name&&!s.skipReset&&L._add_reset_property(r.domName,function(){a=c.iValue,f.querySelectorAll("li").forEach(e=>{e.getAttribute("value")==a&&e.click()}),this.style.display="none"});let d=document.createElement("div");d.className="lexdropdown",d.style.width=s.inputWidth||"calc( 100% - "+t.DEFAULT_NAME_WIDTH+")";let c=document.createElement("div");c.className="lexdropdown lexoption",c.name=e,c.iValue=a;let h=a;h+="<a class='fa-solid fa-angle-down' style='float:right; margin-right: 3px;'></a>",this.queue(d);let u=e=>{let t=e.getParentArea(),i=p.getBoundingClientRect(),a=e.parentElement.closest("dialog");{let l=e.offsetHeight,s=i.y,n=window.innerHeight;if(t){let r=t.getBoundingClientRect();n=r.y+r.height}if(a){let o=a.getBoundingClientRect();s-=o.y}e.style.top=s+p.offsetHeight+"px";let d=s+l>n;d&&(e.style.top=s-l+"px",e.classList.add("place-above"))}{let c=e.offsetWidth,h=i.x;if(e.style.minWidth=i.width+"px",a){let u=a.getBoundingClientRect();h-=u.x}e.style.left=h+"px";let m=window.innerWidth;if(t){let g=t.getBoundingClientRect();m=g.x+g.width}let f=h+c>m;f&&(e.style.left=h-(c-i.width)+"px")}},p=this.addButton(null,h,(e,t)=>{if(f.unfocus_event){delete f.unfocus_event;return}m.classList.remove("place-above");let i=m.hasAttribute("open");i?m.close():(m.show(),u(m)),v&&v.querySelector("input").focus()},{buttonClass:"array",skipInlineCount:!0,disabled:s.disabled});this.clearQueue(),p.style.width="100%",p.refresh=e=>{""==p.querySelector("span").innerText?p.querySelector("span").innerText=e:p.querySelector("span").innerHTML=p.querySelector("span").innerHTML.replaceAll(p.querySelector("span").innerText,e)};let m=document.createElement("dialog");m.className="lexdropdownoptions";let f=document.createElement("ul");f.tabIndex=-1,f.className="lexoptions",m.appendChild(f),f.addEventListener("focusout",function(e){if(e.stopPropagation(),e.stopImmediatePropagation(),e.relatedTarget===p.querySelector("button"))this.unfocus_event=!0,setTimeout(()=>delete this.unfocus_event,200);else if(e.relatedTarget&&"INPUT"==e.relatedTarget.tagName)return;else if("lexinput-filter"==e.target.className)return;m.close()});let v=null;s.filter&&(v=this._addFilter(s.placeholder??"Search...",{container:f,callback:this._filterOptions.bind(f,i)}),f.appendChild(v),v.addEventListener("focusout",function(e){!(e.relatedTarget&&"UL"==e.relatedTarget.tagName&&e.relatedTarget.classList.contains("lexoptions"))&&m.close()}));let $=document.createElement("span");return $.style.height="calc(100% - 25px)",f.appendChild($),f.refresh=t=>{if($.innerHTML="",!t.length){let s=t.emptyMsg??"No options found.",n=document.createElement("div");n.className="option",n.style.flexDirection="unset",n.innerHTML=s;let d=document.createElement("li");d.className="lexdropdownitem empty",d.appendChild(n),$.appendChild(d);return}for(let h=0;h<t.length;h++){let u=t[h],y=document.createElement("li"),E=document.createElement("div");if(E.className="option",y.appendChild(E),y.addEventListener("click",t=>{m.close();let s=r.querySelector(".lexoptions .selected");s&&s.classList.remove("selected"),a=t.currentTarget.getAttribute("value"),t.currentTarget.toggleAttribute("hidden",!1),t.currentTarget.classList.add("selected"),p.refresh(a);let n=r.querySelector(".lexwidgetname .lexicon");n&&(n.style.display=a!=c.iValue?"block":"none"),o._trigger(new g(e,a,null),l),v&&(v.querySelector("input").value="",this._filterOptions.bind(f,i,"")())}),u.constructor!=Object)E.style.flexDirection="unset",E.innerHTML="</a><span>"+u+"</span><a class='fa-solid fa-check'>",E.value=u,y.setAttribute("value",u),y.className="lexdropdownitem",u==a&&(y.classList.add("selected"),c.innerHTML=u);else{let x=document.createElement("img");x.src=u.src,y.setAttribute("value",u.value),y.className="lexlistitem",E.innerText=u.value,E.className+=" media",E.prepend(x),E.setAttribute("value",u.value),E.setAttribute("data-index",h),E.setAttribute("data-src",u.src),E.setAttribute("title",u.value),a==u.value&&y.classList.add("selected")}$.appendChild(y)}},f.refresh(i),d.appendChild(m),r.appendChild(d),n.name||(r.className+=" noname",d.style.width="100%"),n}addCurve(e,i,a,l={}){if(!e)throw"Set Widget Name!";let n=this,r=this.create_widget(e,b.CURVE,l);r.onGetValue=()=>JSON.parse(JSON.stringify(h.element.value)),r.onSetValue=(t,i)=>{let l=o.querySelector(".lexwidgetname .lexicon");l&&(l.style.display=t!=h.element.value?"block":"none"),h.element.value=JSON.parse(JSON.stringify(t)),h.redraw(),i||n._trigger(new g(e,h.element.value,null),a)};let o=r.domEl,d=JSON.parse(JSON.stringify(i));l.skipReset||L._add_reset_property(o.domName,function(t){this.style.display="none",h.element.value=JSON.parse(JSON.stringify(d)),h.redraw(),n._trigger(new g(e,h.element.value,t),a)});var c=document.createElement("div");c.className="lexcurve",c.style.width="calc( 100% - "+t.DEFAULT_NAME_WIDTH+")",l.callback=(t,i)=>{let l=o.querySelector(".lexwidgetname .lexicon");l&&(l.style.display=t!=d?"block":"none"),n._trigger(new g(e,t,i),a)},l.name=e;let h=new A(this,i,l);return c.appendChild(h.element),o.appendChild(c),r.onresize=h.redraw.bind(h),r.curveInstance=h,s(()=>{h.canvas.width=c.offsetWidth,h.redraw()}),r}addDial(e,i,a,l={}){let n=this,r=this.create_widget(e,b.DIAL,l);r.onGetValue=()=>JSON.parse(JSON.stringify(h.element.value)),r.onSetValue=(t,i)=>{let l=o.querySelector(".lexwidgetname .lexicon");l&&(l.style.display=t!=h.element.value?"block":"none"),h.element.value=JSON.parse(JSON.stringify(t)),h.redraw(),i||n._trigger(new g(e,h.element.value,null),a)};let o=r.domEl,d=JSON.parse(JSON.stringify(i));r.name&&!l.skipReset&&L._add_reset_property(o.domName,function(t){this.style.display="none",h.element.value=JSON.parse(JSON.stringify(d)),h.redraw(),n._trigger(new g(e,h.element.value,t),a)});var c=document.createElement("div");c.className="lexcurve",c.style.width=r.name?"calc( 100% - "+t.DEFAULT_NAME_WIDTH+")":"100%",l.callback=(t,i)=>{let l=o.querySelector(".lexwidgetname .lexicon");l&&(l.style.display=t!=d?"block":"none"),n._trigger(new g(e,t,i),a)},l.name=e;let h=new S(this,i,l);return c.appendChild(h.element),o.appendChild(c),r.onresize=h.redraw.bind(h),r.curveInstance=h,s(()=>{h.element.style.height=h.element.offsetWidth+"px",h.canvas.width=h.element.offsetWidth,c.style.width=h.element.offsetWidth+"px",h.canvas.height=h.canvas.width,h.redraw()}),r}addLayers(e,i,a,l={}){if(!e)throw"Set Widget Name!";let s=this,n=this.create_widget(e,b.LAYERS,l);n.onGetValue=()=>r.value,n.onSetValue=(t,l)=>{let n=r.querySelector(".lexwidgetname .lexicon");n&&(n.style.display=t!=d?"block":"none"),i=r.value=t,c(),l||s._trigger(new g(e,i),a)};let r=n.domEl;L._add_reset_property(r.domName,function(t){this.style.display="none",i=r.value=d,c(),s._trigger(new g(e,i,t),a)});var o=document.createElement("div");o.className="lexlayers",o.style.width="calc( 100% - "+t.DEFAULT_NAME_WIDTH+")";let d=r.value=i,c=()=>{o.innerHTML="";let t=i.toString(2),l=t.length;for(var s=0;s<16-l;++s)t="0"+t;for(let n=0;n<16;++n){let c=document.createElement("div");if(c.className="lexlayer",void 0!=i){let h=t[16-n-1];void 0!=h&&"1"==h&&c.classList.add("selected")}c.innerText=n+1,c.title="Bit "+n+", value "+(1<<n),o.appendChild(c),c.addEventListener("click",t=>{t.stopPropagation(),t.stopImmediatePropagation(),t.target.classList.toggle("selected"),i^=1<<n,r.value=i;let l=r.querySelector(".lexwidgetname .lexicon");l&&(l.style.display=i!=d?"block":"none"),this._trigger(new g(e,i,t),a)})}};return c(),r.appendChild(o),n}addArray(e,i=[],a,l={}){if(!e)throw"Set Widget Name!";let s=this.create_widget(e,b.ARRAY,l);s.onGetValue=()=>{let e=n.querySelectorAll("input"),t=[];for(var i of e)t.push(i.value);return t},s.onSetValue=(t,l)=>{i=t,h(),l||this._trigger(new g(e,i,null),a)};let n=s.domEl;n.style.flexWrap="wrap";var r=document.createElement("div");r.className="lexarray",r.style.width="calc( 100% - "+t.DEFAULT_NAME_WIDTH+")",this.queue(r);let o="<a class='fa-solid fa-angle-down' style='float:right; margin-right: 3px;'></a>",d="Array (size "+i.length+")";d+=o,this.addButton(null,d,()=>{n.querySelector(".lexarrayitems").toggleAttribute("hidden")},{buttonClass:"array"}),this.clearQueue();let c=document.createElement("div");c.className="lexarrayitems",c.toggleAttribute("hidden",!0),n.appendChild(r),n.appendChild(c);let h=()=>{let t=n.querySelector(".lexbutton.array span");t.innerHTML="Array (size "+i.length+")",t.innerHTML+=o,c.innerHTML="",this.queue(c);for(let s=0;s<i.length;++s){let r=i[s],u=l.innerValues?"dropdown":r.constructor;switch(this.sameLine(2),u){case String:this.addText(s+"",r,function(e,t){i[s]=e,a(i)},{nameWidth:"4%",inputWidth:"95%",skipReset:!0});break;case Number:this.addNumber(s+"",r,function(e,t){i[s]=e,a(i)},{nameWidth:"4%",inputWidth:"95%",skipReset:!0});break;case"dropdown":this.addDropdown(s+"",l.innerValues,r,function(e,t){i[s]=e,a(i)},{nameWidth:"4%",inputWidth:"95%",skipReset:!0})}this.addButton(null,"<a class='lexicon fa-solid fa-trash'></a>",(t,l)=>{i.splice(i.indexOf(r),1),h(),this._trigger(new g(e,i,l),a)},{title:"Remove item",className:"micro"})}d="Add item",d+="<a class='fa-solid fa-plus' style='float:right; margin-right: 3px; margin-top: 2px;'></a>",this.addButton(null,d,(t,s)=>{i.push(l.innerValues?l.innerValues[0]:""),h(),this._trigger(new g(e,i,s),a)},{buttonClass:"array"}),this.clearQueue()};return h(),s}addList(e,i,a,l,s={}){let n=this.create_widget(e,b.LIST,s);n.onGetValue=()=>a,n.onSetValue=(t,s)=>{o.querySelectorAll(".lexlistitem").forEach(e=>e.classList.remove("selected"));let n=i.indexOf(t);-1==n||(o.children[n].classList.toggle("selected"),a=t,s||this._trigger(new g(e,t),l))},n.updateValues=t=>{i=t,o.innerHTML="";for(let s=0;s<i.length;++s){let n=null,r=i[s];r.constructor===Array&&(n=r[1],r=r[0]);let d=document.createElement("div");d.className="lexlistitem"+(a==r?" selected":""),d.innerHTML="<span>"+r+"</span>"+(n?"<a class='"+n+"'></a>":""),d.addEventListener("click",t=>{o.querySelectorAll(".lexlistitem").forEach(e=>e.classList.remove("selected")),d.classList.toggle("selected"),a=r,this._trigger(new g(e,r,t),l)}),o.appendChild(d)}};let r=n.domEl,o=document.createElement("div");return o.className="lexlist",o.style.width="calc( 100% - "+t.DEFAULT_NAME_WIDTH+")",n.updateValues(i),n.name||(r.className+=" noname",o.style.width="100%"),r.appendChild(o),n}addTags(e,i,a,l={}){let s=[].concat(i=i.replace(/\s/g,"").split(",")),n=this.create_widget(e,b.TAGS,l);n.onGetValue=()=>[].concat(i),n.onSetValue=(t,l)=>{i=[].concat(t),c();let n=r.querySelector(".lexwidgetname .lexicon");n&&(n.style.display=t!=s?"block":"none"),l||o._trigger(new g(e,i),a)};let r=n.domEl,o=this;n.name&&L._add_reset_property(r.domName,function(t){this.style.display="none",i=[].concat(s),c(),o._trigger(new g(e,i,t),a)});let d=document.createElement("div");d.className="lextags",d.style.width="calc( 100% - "+t.DEFAULT_NAME_WIDTH+")";let c=()=>{d.innerHTML="";for(let t=0;t<i.length;++t){let l=i[t],n=document.createElement("span");n.className="lextag",n.innerHTML=l;let h=document.createElement("a");h.className="lextagrmb fa-solid fa-xmark lexicon",n.appendChild(h),h.addEventListener("click",t=>{n.remove(),i.splice(i.indexOf(l),1);let d=r.querySelector(".lexwidgetname .lexicon");d&&(d.style.display=i!=s?"block":"none"),o._trigger(new g(e,i,t),a)}),d.appendChild(n)}let u=document.createElement("input");u.value="",u.placeholder="Add tag...",d.appendChild(u),u.onkeydown=function(t){let l=this.value.replace(/\s/g,"");if(" "==t.key||"Enter"==t.key){if(t.preventDefault(),!l.length||i.indexOf(l)>-1)return;i.push(l),c();let s=r.querySelector(".lexwidgetname .lexicon");s&&(s.style.display="block"),o._trigger(new g(e,i,t),a)}},u.focus()};return c(),n.name||(r.className+=" noname",d.style.width="100%"),r.appendChild(d),n}addCheckbox(e,t,i,a={}){if(!e&&!a.label)throw"Set Widget Name or at least a label!";let l=this.create_widget(e,b.CHECKBOX,a);l.onGetValue=()=>r.checked,l.onSetValue=(e,t)=>{r.checked!==e&&(r.checked=e,L._dispatch_event(r,"change",t))};let s=l.domEl;e&&L._add_reset_property(s.domName,function(){r.checked=!r.checked,L._dispatch_event(r,"change")});var n=document.createElement("div");n.className="lexcheckboxcont";let r=document.createElement("input");r.type="checkbox",r.className="lexcheckbox "+(a.className??""),r.checked=t,r.iValue=t,r.disabled=a.disabled??!1;let o=document.createElement("span");if(o.className="checkboxtext",o.innerHTML=a.label??"On",n.appendChild(r),n.appendChild(o),r.addEventListener("change",t=>{let a=t.detail?.constructor==Number?null:t.detail;if(!a){let l=s.querySelector(".lexwidgetname .lexicon");l&&(l.style.display=r.checked!=r.iValue?"block":"none")}let n=s.querySelector(".lexcheckboxsubmenu");n&&n.toggleAttribute("hidden",!r.checked),a||this._trigger(new g(e,r.checked,t),i)}),s.appendChild(n),a.suboptions){s.style.flexWrap="wrap";let d=document.createElement("div");d.className="lexcheckboxsubmenu",d.toggleAttribute("hidden",!r.checked),this.queue(d),a.suboptions.call(this,this),this.clearQueue(),s.appendChild(d)}return l}addToggle(e,t,i,a={}){if(!e)throw"Set Widget Name!";let l=this.create_widget(e,b.TOGGLE,a);l.onGetValue=()=>r.checked,l.onSetValue=(e,t)=>{r.checked!==e&&(r.checked=e,L._dispatch_event(r,"change",t))};let s=l.domEl;L._add_reset_property(s.domName,function(){r.checked=!r.checked,L._dispatch_event(r,"change")});var n=document.createElement("div");n.className="lextogglecont";let r=document.createElement("input");r.type="checkbox",r.className="lextoggle "+(a.className??""),r.checked=t,r.iValue=t,r.disabled=a.disabled??!1;let o=document.createElement("span");if(o.className="toggletext",o.innerHTML="On",n.appendChild(r),n.appendChild(o),r.addEventListener("change",t=>{let a=t.detail?.constructor==Number?null:t.detail;if(!a){let l=s.querySelector(".lexwidgetname .lexicon");l&&(l.style.display=r.checked!=r.iValue?"block":"none")}let n=s.querySelector(".lextogglesubmenu");n&&n.toggleAttribute("hidden",!r.checked),a||this._trigger(new g(e,r.checked,t),i)}),s.appendChild(n),a.suboptions){s.style.flexWrap="wrap";let d=document.createElement("div");d.className="lextogglesubmenu",d.toggleAttribute("hidden",!r.checked),this.queue(d),a.suboptions.call(this,this),this.clearQueue(),s.appendChild(d)}return l}addRadioGroup(e,t,i,a={}){let l=this.create_widget(null,b.RADIO,a);l.onGetValue=()=>{let e=n.querySelectorAll("button");for(let i=0;i<e.length;++i){let a=e[i];if(a.checked)return[i,t[i]]}},l.onSetValue=(e,t)=>{let i=n.querySelectorAll("button");for(let a=0;a<i.length;++a){let l=i[a];e==a&&L._dispatch_event(l,"click",t)}};let s=l.domEl;var n=document.createElement("div");n.className="lexradiogroup "+(a.className??"");let r=document.createElement("span");r.innerHTML=e,n.appendChild(r);let o=this;for(let d=0;d<t.length;++d){let c=document.createElement("div");c.className="lexradiogroupitem",n.appendChild(c);let h=document.createElement("button");h.className="lexbutton",h.disabled=a.disabled??!1,c.appendChild(h),h.addEventListener("click",function(e){let a=e.detail?.constructor==Number?null:e.detail;n.querySelectorAll("button").forEach(e=>{e.checked=!1,e.classList.remove("checked")}),this.checked=!this.checked,this.classList.toggle("checked"),a||o._trigger(new g(null,[d,t[d]],e),i)});{let u=document.createElement("span");h.appendChild(u)}let p=document.createElement("span");p.innerHTML=t[d],c.appendChild(p)}return a.selected&&(console.assert(a.selected.constructor==Number),l.set(a.selected,!0)),s.appendChild(n),l}addColor(e,i,a,l={}){if(!e)throw"Set Widget Name!";let s=this.create_widget(e,b.COLOR,l);s.onGetValue=()=>h.value,s.onSetValue=(e,t)=>{h.value=e,L._dispatch_event(h,"input",t)};let n=s.domEl,r=!1;L._add_reset_property(n.domName,function(){this.style.display="none",h.value=h.iValue,L._dispatch_event(h,"input")});var o=document.createElement("span");o.className="lexcolor",o.style.width="calc( 100% - "+t.DEFAULT_NAME_WIDTH+")";let h=document.createElement("input");h.style.width="32px",h.type="color",h.className="colorinput",h.id="color"+u(),h.useRGB=l.useRGB??!1,h.value=h.iValue=i.constructor===Array?c(i):i,l.disabled&&(h.disabled=!0),h.addEventListener("input",t=>{let i=t.target.value,l=t.detail;if(r||p.set(i),!l){let s=n.querySelector(".lexwidgetname .lexicon");s&&(s.style.display=i!=h.iValue?"block":"none")}h.useRGB&&(i=d(i)),l||this._trigger(new g(e,i,t),a)},!1),o.appendChild(h),this.queue(o);let p=this.addText(null,h.value,e=>{r=!0,s.set(e),r=!1},{width:"calc( 100% - 32px )"});return p.domEl.style.marginLeft="4px",this.clearQueue(),n.appendChild(o),s}addRange(e,a,l,s={}){let n=this.create_widget(e,b.RANGE,s);n.onGetValue=()=>+d.value,n.onSetValue=(e,t)=>{d.value=e,L._dispatch_event(d,"input",t)};let r=n.domEl;n.name&&L._add_reset_property(r.domName,function(){this.style.display="none",d.value=d.iValue,L._dispatch_event(d,"input")});var o=document.createElement("div");o.className="lexrange",o.style.width=s.inputWidth||"calc( 100% - "+t.DEFAULT_NAME_WIDTH+")";let d=document.createElement("input");return d.className="lexrangeslider "+(s.className??""),d.value=d.iValue=a,d.min=s.min,d.max=s.max,d.step=s.step??1,d.type="range",d.disabled=s.disabled??!1,s.left&&d.classList.add("left"),(s.fill??!0)||d.classList.add("no-fill"),d.addEventListener("input",t=>{if(isNaN(t.target.valueAsNumber))return;let a=t.detail,n=t.target.value=i(+t.target.valueAsNumber,+d.min,+d.max);if(d.value=n,!a){let o=r.querySelector(".lexwidgetname .lexicon");o&&(o.style.display=n!=d.iValue?"block":"none")}s.left&&(n=+d.max-n+ +d.min),a||this._trigger(new g(e,n,t),l)},{passive:!1}),d.addEventListener("mousedown",function(e){s.onPress&&s.onPress.bind(d)(e,d)},!1),d.addEventListener("mouseup",function(e){s.onRelease&&s.onRelease.bind(d)(e,d)},!1),n.setLimits=(e,t,i)=>{d.min=e??d.min,d.max=t??d.max,d.step=i??d.step,L._dispatch_event(d,"input",!0)},a.constructor==Number&&(a=i(a,+d.min,+d.max)),o.appendChild(d),r.appendChild(o),n.name||(r.className+=" noname",o.style.width="100%"),n}addNumber(e,l,s,n={}){let r=this.create_widget(e,b.NUMBER,n);r.onGetValue=()=>+p.value,r.onSetValue=(e,t)=>{p.value=a(e,n.precision),L._dispatch_event(p,"change",t)};let o=r.domEl;r.name&&L._add_reset_property(o.domName,function(){this.style.display="none",p.value=p.iValue,L._dispatch_event(p,"change")});var d=document.createElement("div");d.className="lexnumber",d.style.width=n.inputWidth||"calc( 100% - "+t.DEFAULT_NAME_WIDTH+")";let c=document.createElement("div");c.className="numberbox";let p=document.createElement("input");if(p.id="number_"+u(),p.className="vecinput",p.min=n.min??-1e24,p.max=n.max??1e24,p.step=n.step??"any",p.type="number",l.constructor==Number&&(l=i(l,+p.min,+p.max),l=a(l,n.precision)),p.value=p.iValue=l,c.appendChild(p),n.units){let m=document.createElement("span");m.className="lexunit",m.innerText=n.units,m.style.left=h(p.value)+"px",p.unitSpan=m,c.appendChild(m)}let f=document.createElement("a");if(f.className="fa-solid fa-arrows-up-down drag-icon hidden",c.appendChild(f),n.disabled&&(p.disabled=!0),!n.skipSlider&&void 0!==n.min&&void 0!==n.max){let v=document.createElement("input");v.className="lexinputslider",v.min=n.min,v.max=n.max,v.step=n.step??1,v.type="range",v.value=l,v.addEventListener("input",function(e){let t=+this.valueAsNumber;p.value=a(t,n.precision),L._dispatch_event(p,"change")},!1),v.addEventListener("mousedown",function(e){n.onPress&&n.onPress.bind(v)(e,v)},!1),v.addEventListener("mouseup",function(e){n.onRelease&&n.onRelease.bind(v)(e,v)},!1),c.appendChild(v),r.setLimits=(e,t,i)=>{p.min=v.min=e??p.min,p.max=v.max=t??p.max,p.step=i??p.step,v.step=i??v.step,L._dispatch_event(p,"change",!0)}}p.addEventListener("input",function(e){let t=+this.valueAsNumber;p.value=a(t,n.precision),n.units&&(p.unitSpan.style.left=h(p.value)+"px")},!1),p.addEventListener("wheel",function(e){if(e.preventDefault(),this!==document.activeElement)return;let t=n.step??1;e.shiftKey?t*=10:e.altKey&&(t*=.1);let i=+this.valueAsNumber-t*(e.deltaY>0?1:-1);this.value=a(i,n.precision),L._dispatch_event(p,"change")},{passive:!1}),p.addEventListener("change",t=>{if(isNaN(t.target.valueAsNumber))return;let l=t.detail,r=t.target.value=i(+t.target.valueAsNumber,+p.min,+p.max);if(r=n.precision?a(r,n.precision):r,c.querySelector(".lexinputslider")&&(c.querySelector(".lexinputslider").value=r),p.value=r,n.units&&(p.unitSpan.style.left=h(p.value)+"px"),!l){let d=o.querySelector(".lexwidgetname .lexicon");d&&(d.style.display=r!=p.iValue?"block":"none")}l||this._trigger(new g(e,r,t),s)},{passive:!1}),p.addEventListener("mousedown",function e(t){if(document.activeElement!=p){var i=$.root.ownerDocument;i.addEventListener("mousemove",y),i.addEventListener("mouseup",E),document.body.classList.add("noevents"),f.classList.remove("hidden"),t.stopImmediatePropagation(),t.stopPropagation(),document.pointerLockElement||p.requestPointerLock(),n.onPress&&n.onPress.bind(p)(t,p)}});var $=this;function y(e){let t=-e.movementY;if(0!=t){let i=n.step??1;e.shiftKey?i*=10:e.altKey&&(i*=.1);let a=+p.valueAsNumber+i*t;p.value=(+a).toFixed(4).replace(/([0-9]+(\.[0-9]+[1-9])?)(\.?0+$)/,"$1"),L._dispatch_event(p,"change")}e.stopPropagation(),e.preventDefault()}function E(e){var t=$.root.ownerDocument;t.removeEventListener("mousemove",y),t.removeEventListener("mouseup",E),document.body.classList.remove("noevents"),f.classList.add("hidden"),document.pointerLockElement&&document.exitPointerLock(),n.onRelease&&n.onRelease.bind(p)(e,p)}return d.appendChild(c),o.appendChild(d),r.name||(o.className+=" noname",d.style.width="100%"),r}static VECTOR_COMPONENTS={0:"x",1:"y",2:"z",3:"w"};_add_vector(e,l,s,n,r={}){if(e=i(e,2,4),s=s??Array(e).fill(0),!l)throw"Set Widget Name!";let o=this.create_widget(l,b.VECTOR,r);o.onGetValue=()=>{let e=d.querySelectorAll("input"),t=[];for(var i of e)t.push(+i.value);return t},o.onSetValue=(e,t)=>{let i=d.querySelectorAll(".vecinput");if(i.length==e.length){console.error("Input length does not match vector length.");return}for(let l=0;l<i.length;++l){let s=e[l];i[l].value=a(s,r.precision)??0,L._dispatch_event(i[l],"change",t)}};let d=o.domEl;L._add_reset_property(d.domName,function(){for(let e of(this.style.display="none",d.querySelectorAll(".vecinput")))e.value=e.iValue,L._dispatch_event(e,"change")});var c=document.createElement("div");c.className="lexvector",c.style.width="calc( 100% - "+t.DEFAULT_NAME_WIDTH+")";for(let h=0;h<e;++h){let p=document.createElement("div");p.className="vecbox",p.innerHTML="<span class='"+L.VECTOR_COMPONENTS[h]+"'></span>";let m=document.createElement("input");m.className="vecinput v"+e,m.min=r.min??-1e24,m.max=r.max??1e24,m.step=r.step??"any",m.type="number",m.id="vec"+e+"_"+u(),m.idx=h,s[h].constructor==Number&&(s[h]=i(s[h],+m.min,+m.max),s[h]=a(s[h],r.precision)),m.value=m.iValue=s[h];let f=document.createElement("a");f.className="fa-solid fa-arrows-up-down drag-icon hidden",p.appendChild(f),r.disabled&&(m.disabled=!0),m.addEventListener("wheel",function(e){if(e.preventDefault(),this!==document.activeElement)return;let t=r.step??1;if(e.shiftKey?t=10:e.altKey&&(t=.1),x.locked)for(let i of d.querySelectorAll(".vecinput"))i.value=a(+i.valueAsNumber-t*(e.deltaY>0?1:-1),r.precision),L._dispatch_event(i,"change");else this.value=a(+this.valueAsNumber-t*(e.deltaY>0?1:-1),r.precision),L._dispatch_event(m,"change")},{passive:!1}),m.addEventListener("change",e=>{if(isNaN(e.target.value))return;let t=e.detail,o=e.target.value=i(e.target.value,+m.min,+m.max);if(o=a(o,r.precision),!t){let c=d.querySelector(".lexwidgetname .lexicon");c&&(c.style.display=o!=m.iValue?"block":"none")}if(x.locked)for(let h of d.querySelectorAll(".vecinput"))h.value=o,s[h.idx]=o;else m.value=o,s[e.target.idx]=o;t||this._trigger(new g(l,s,e),n)},!1),m.addEventListener("mousedown",$);var v=this;function $(e){if(document.activeElement!=m){var t=v.root.ownerDocument;t.addEventListener("mousemove",y),t.addEventListener("mouseup",E),document.body.classList.add("noevents"),f.classList.remove("hidden"),e.stopImmediatePropagation(),e.stopPropagation(),document.pointerLockElement||m.requestPointerLock(),r.onPress&&r.onPress.bind(m)(e,m)}}function y(e){let t=-e.movementY;if(0!=t){let i=r.step??1;if(e.shiftKey?i=10:e.altKey&&(i=.1),x.locked)for(let l of d.querySelectorAll(".vecinput"))l.value=a(+l.valueAsNumber+i*t,r.precision),L._dispatch_event(l,"change");else m.value=a(+m.valueAsNumber+i*t,r.precision),L._dispatch_event(m,"change")}e.stopPropagation(),e.preventDefault()}function E(e){var t=v.root.ownerDocument;t.removeEventListener("mousemove",y),t.removeEventListener("mouseup",E),document.body.classList.remove("noevents"),f.classList.add("hidden"),document.pointerLockElement&&document.exitPointerLock(),r.onRelease&&r.onRelease.bind(m)(e,m)}p.appendChild(m),c.appendChild(p)}(void 0!==r.min||void 0!==r.max)&&(o.setLimits=(e,t,i)=>{let a=d.querySelectorAll(".vecinput");for(let r of a)r.min=e??r.min,r.max=t??r.max,r.step=i??r.step,L._dispatch_event(r,"change",!0);this._trigger(new g(l,s),n)});let x=document.createElement("a");return x.title="Lock",x.className="fa-solid fa-lock-open lexicon lock",c.appendChild(x),x.addEventListener("click",function(e){this.locked=!this.locked,this.locked?(this.classList.add("fa-lock"),this.classList.remove("fa-lock-open")):(this.classList.add("fa-lock-open"),this.classList.remove("fa-lock"))},!1),d.appendChild(c),o}addVector2(e,t,i,a){return this._add_vector(2,e,t,i,a)}addVector3(e,t,i,a){return this._add_vector(3,e,t,i,a)}addVector4(e,t,i,a){return this._add_vector(4,e,t,i,a)}addSize(e,t,i,a={}){let l=this.create_widget(e,b.SIZE,a);l.onGetValue=()=>{let e=[];for(let t=0;t<s.dimensions.length;++t)e.push(s.dimensions[t].value());return e},l.onSetValue=(e,t)=>{for(let i=0;i<s.dimensions.length;++i)s.dimensions[i].set(e[i],t)};let s=l.domEl;this.queue(s),s.aspectRatio=2==t.length?t[0]/t[1]:null,s.dimensions=[];for(let n=0;n<t.length;++n)if(s.dimensions[n]=this.addNumber(null,t[n],e=>{let t=l.value();if(s.locked){let a=0==n?1/s.aspectRatio:s.aspectRatio,r=(1+n)%2;t[r]=e*a,s.dimensions[r].set(t[r],!0)}i&&i(t)},{min:0,disabled:a.disabled,precision:a.precision}),n+1!=t.length){let r=document.createElement("a");r.className="lexsizecross fa-solid fa-xmark",s.appendChild(r)}if(this.clearQueue(),a.units){let o=document.createElement("span");o.className="lexunit",o.innerText=a.units,s.appendChild(o)}if(s.aspectRatio){let d=document.createElement("a");d.title="Lock Aspect Ratio",d.className="fa-solid fa-lock-open lexicon lock",s.appendChild(d),d.addEventListener("click",function(e){if(s.locked=!s.locked,s.locked){this.classList.add("fa-lock"),this.classList.remove("fa-lock-open");let t=l.value();s.aspectRatio=t[0]/t[1]}else this.classList.add("fa-lock-open"),this.classList.remove("fa-lock")},!1)}return l.name||(s.className+=" noname",container.style.width="100%"),l}addPad(e,i,a,n={}){if(!e)throw"Set Widget Name!";let r=this.create_widget(e,b.PAD,n);r.onGetValue=()=>h.value.xy,r.onSetValue=(t,i)=>{h.value.set(t[0],t[1]),u(h.value),i||this._trigger(new g(e,h.value.xy),a)};let o=r.domEl;var d=document.createElement("div");d.className="lexpad",d.style.width="calc( 100% - "+t.DEFAULT_NAME_WIDTH+")";let c=document.createElement("div");c.id="lexpad-"+e,c.className="lexinnerpad",c.style.width=n.padSize??"96px",c.style.height=n.padSize??"96px";let h=document.createElement("div");h.className="lexpadthumb",h.value=new t.vec2(i[0],i[1]),h.min=n.min??0,h.max=n.max??1;let u=e=>{let[i,a]=[c.offsetWidth,c.offsetHeight],s=new t.vec2(l(e.x,h.min,h.max,0,1),l(e.y,h.min,h.max,0,1));h.style.transform=`translate(calc( ${i*s.x}px - 50% ), calc( ${a*s.y}px - 50%)`};s(()=>{u(h.value)}),c.appendChild(h),d.appendChild(c),o.appendChild(d),c.addEventListener("mousedown",function e(t){if(document.activeElement!=h){var i=p.root.ownerDocument;i.addEventListener("mousemove",m),i.addEventListener("mouseup",f),document.body.classList.add("nocursor"),document.body.classList.add("noevents"),t.stopImmediatePropagation(),t.stopPropagation(),n.onPress&&n.onPress.bind(h)(t,h)}});let p=this;function m(i){let s=c.getBoundingClientRect(),n=new t.vec2(i.x-s.x,i.y-s.y);n.clp(0,c.offsetWidth,n);let[r,o]=[c.offsetWidth,c.offsetHeight],d=n.div(new t.vec2(c.offsetWidth,c.offsetHeight));h.style.transform=`translate(calc( ${r*d.x}px - 50% ), calc( ${o*d.y}px - 50%)`,h.value=new t.vec2(l(d.x,0,1,h.min,h.max),l(d.y,0,1,h.min,h.max)),p._trigger(new g(e,h.value.xy,i),a),i.stopPropagation(),i.preventDefault()}function f(e){var t=p.root.ownerDocument;t.removeEventListener("mousemove",m),t.removeEventListener("mouseup",f),document.body.classList.remove("nocursor"),document.body.classList.remove("noevents"),n.onRelease&&n.onRelease.bind(h)(e,h)}return r}addProgress(e,i,s={}){if(!e)throw"Set Widget Name!";let n=this.create_widget(e,b.PROGRESS,s);n.onGetValue=()=>d.value,n.onSetValue=(e,t)=>{r.querySelector("meter").value=e,c(),r.querySelector("span")&&(r.querySelector("span").innerText=e)};let r=n.domEl;var o=document.createElement("div");o.className="lexprogress",o.style.width="calc( 100% - "+t.DEFAULT_NAME_WIDTH+")";let d=document.createElement("meter");d.id="lexprogressbar-"+e,d.className="lexprogressbar",d.step="any",d.min=s.min??0,d.max=s.max??1,d.low=s.low??d.low,d.high=s.high??d.high,d.optimum=s.optimum??d.optimum,d.value=i;let c=()=>{let e=t.getThemeColor("global-selected");void 0!=d.low&&d.value<d.low?e=t.getThemeColor("global-color-error"):void 0!=d.high&&d.value<d.high&&(e=t.getThemeColor("global-color-warning")),d.style.background=`color-mix(in srgb, ${e} 20%, transparent)`};if(o.appendChild(d),r.appendChild(o),s.showValue){document.getElementById("progressvalue-"+e)&&document.getElementById("progressvalue-"+e).remove();let h=document.createElement("span");h.id="progressvalue-"+e,h.style.padding="0px 5px",h.innerText=i,o.appendChild(h)}if(s.editable){d.classList.add("editable"),d.addEventListener("mousedown",function t(i){var s=u.root.ownerDocument;s.addEventListener("mousemove",p),s.addEventListener("mouseup",m),document.body.classList.add("noevents"),d.classList.add("grabbing"),i.stopImmediatePropagation(),i.stopPropagation();let n=d.getBoundingClientRect(),r=a(l(i.offsetX,0,n.width,d.min,d.max));u.setValue(e,r)});let u=this;function p(t){if(0!=t.movementX){let i=d.getBoundingClientRect(),n=a(l(t.offsetX-i.x,0,i.width,d.min,d.max));u.setValue(e,n),s.callback&&s.callback(n,t)}t.stopPropagation(),t.preventDefault()}function m(e){var t=u.root.ownerDocument;t.removeEventListener("mousemove",p),t.removeEventListener("mouseup",m),document.body.classList.remove("noevents"),d.classList.remove("grabbing")}}return c(),n}addFile(e,i,a={}){if(!e)throw"Set Widget Name!";let l=this.create_widget(e,b.FILE,a),s=l.domEl,n=a.local??!0,r=a.type??"text",o=a.read??!0,d=document.createElement("input");if(d.className="lexfileinput",d.style.width="calc( 100% - "+t.DEFAULT_NAME_WIDTH+" - 10%)",d.type="file",d.disabled=a.disabled??!1,a.placeholder&&(d.placeholder=a.placeholder),d.addEventListener("change",function(e){let t=e.target.files;if(t.length){if(o){a.onBeforeRead&&a.onBeforeRead();let l=new FileReader;"text"===r?l.readAsText(t[0]):"buffer"===r?l.readAsArrayBuffer(t[0]):"bin"===r?l.readAsBinaryString(t[0]):"url"===r&&l.readAsDataURL(t[0]),l.onload=e=>{i.call(this,e.target.result,t[0])}}else i(t[0])}}),d.addEventListener("cancel",function(e){i(null)}),s.appendChild(d),this.queue(s),n){let c=null;this.addButton(null,"<a style='margin-top: 0px;' class='fa-solid fa-gear'></a>",()=>{!c&&(c=new _("Load Settings",e=>{e.addDropdown("Type",["text","buffer","bin","url"],r,e=>{r=e}),e.addButton(null,"Reload",e=>{d.dispatchEvent(new Event("change"))})},{onclose(e){e.remove(),c=null}}))},{className:"micro",skipInlineCount:!0,title:"Settings"})}return this.clearQueue(),l}addTree(e,t,i={}){let a=document.createElement("div");if(a.className="lextree",e){let l=document.createElement("span");l.innerHTML=e,a.appendChild(l)}let s=document.createElement("div");if(s.className="lextreetools",e||(s.className+=" notitle"),i.icons)for(let n of i.icons){let r=document.createElement("a");r.title=n.name,r.className="lexicon "+n.icon,r.addEventListener("click",n.callback),s.appendChild(r)}i.filter=i.filter??!0;let o=null;if(i.filter){(o=document.createElement("input")).id="lexnodetree_filter",o.setAttribute("placeholder","Filter.."),o.style.width="calc( 100% - 17px )",o.addEventListener("input",function(){h.refresh()});let d=document.createElement("a");d.className="lexicon fa-solid fa-magnifying-glass",s.appendChild(o),s.appendChild(d)}(i.icons||i.filter)&&a.appendChild(s);let c=document.createElement("ul");c.addEventListener("contextmenu",function(e){e.preventDefault()}),a.appendChild(c),this.root.appendChild(a);let h=new w(a,t,i);return h}addSeparator(){var e=document.createElement("div");e.className="lexseparator";let t=new b(null,b.SEPARATOR);t.domEl=e,this.current_branch?(this.current_branch.content.appendChild(e),this.current_branch.widgets.push(t)):this.root.appendChild(e)}addTabs(e,t={}){let i=this.current_branch?this.current_branch.content:this.root;if(this.current_branch||console.warn("No current branch!"),e.constructor!=Array)throw"Param @tabs must be an Array!";let a=t.vertical??!0,l=!a&&(t.showNames??!1),s=document.createElement("div");s.className="lextabscontainer",a||(s.className+=" horizontal");let n=document.createElement("div");n.className="tabs",s.appendChild(n),i.appendChild(s);for(let r=0;r<e.length;++r){let o=e[r];console.assert(o.name);let d=0==r,c=document.createElement("div");c.className="lextab "+(r==e.length-1?"last":"")+(d?"selected":""),c.innerHTML=(l?o.name:"")+"<a class='"+(o.icon||"fa fa-hashtag")+" "+(l?"withname":"")+"'></a>",c.title=o.name;let h=document.createElement("div");h.id=o.name.replace(/\s/g,""),h.className="widgets",d||h.toggleAttribute("hidden",!0),s.appendChild(h),c.addEventListener("click",e=>{n.querySelectorAll(".lextab").forEach(e=>{e.classList.remove("selected")}),e.target.classList.add("selected"),s.querySelectorAll(".widgets").forEach(e=>{e.toggleAttribute("hidden",!0)});let t=s.querySelector("#"+h.id);t.toggleAttribute("hidden"),o.onSelect&&o.onSelect(this,h)}),n.appendChild(c),o.onCreate&&(this.queue(h),o.onCreate(this,h),this.clearQueue())}this.addSeparator()}addCounter(e,t,a,l={}){let s=this.create_widget(e,b.COUNTER,l);s.onGetValue=()=>p.count,s.onSetValue=(e,t)=>{c(e,t)};let n=s.domEl,r=l.min??0,o=l.max??100,d=l.step??1,c=(t,l,s)=>{t=i(t,r,o),p.count=t,p.innerHTML=t,l||this._trigger(new g(e,t,s),a)},h=document.createElement("div");h.className="lexcounter",n.appendChild(h),this.queue(h),this.addButton(null,"<a style='margin-top: 0px;' class='fa-solid fa-minus'></a>",(e,t)=>{let i=d??1;t.shiftKey&&(i*=10),c(p.count-i,!1,t)},{className:"micro",skipInlineCount:!0,title:"Minus"}),this.clearQueue();let u=document.createElement("div");u.className="lexcounterbox",h.appendChild(u);let p=document.createElement("span");if(p.className="lexcountervalue",p.innerHTML=t,p.count=t,u.appendChild(p),l.label){let m=document.createElement("span");m.className="lexcounterlabel",m.innerHTML=l.label,u.appendChild(m)}return this.queue(h),this.addButton(null,"<a style='margin-top: 0px;' class='fa-solid fa-plus'></a>",(e,t)=>{let i=d??1;t.shiftKey&&(i*=10),c(p.count+i,!1,t)},{className:"micro",skipInlineCount:!0,title:"Plus"}),this.clearQueue(),s}addTable(e,i,a={}){if(!i)throw"Data is needed to create a table!";let l=this.create_widget(e,b.TABLE,a);l.onGetValue=()=>{},l.onSetValue=(e,t)=>{};let s=l.domEl,n=document.createElement("div");n.className="lextable",n.style.width="calc( 100% - "+t.DEFAULT_NAME_WIDTH+")";let r=document.createElement("table");function o(e,t,i,a){return i[e]<a[e]?-t:i[e]>a[e]?t:0}return n.appendChild(r),i.head=i.head??[],i.body=i.body??[],i.orderMap={},i.checkMap={},l.refreshTable=()=>{r.innerHTML="";{let e=document.createElement("thead");e.className="lextablehead",r.appendChild(e);let s=document.createElement("tr");if(a.selectable){let n=document.createElement("th"),d=document.createElement("input");d.type="checkbox",d.className="lexcheckbox",d.checked=i.checkMap[":root"]??!1,n.appendChild(d),d.addEventListener("change",function(){i.checkMap[":root"]=this.checked;let e=r.querySelector("tbody");for(let t of e.childNodes)i.checkMap[t.getAttribute("rowId")]=this.checked,t.querySelector("input").checked=this.checked}),s.appendChild(n)}for(let c of i.head){let h=document.createElement("th");h.innerHTML=`${c} <a class="fa-solid fa-sort"></a>`,h.querySelector("a").addEventListener("click",()=>{i.orderMap[c]||(i.orderMap[c]=1);let e=i.head.indexOf(c);i.body=i.body.sort(o.bind(this,e,i.orderMap[c])),i.orderMap[c]=-i.orderMap[c],l.refreshTable()}),s.appendChild(h)}if(a.rowActions){let u=document.createElement("th");u.className="sm",s.appendChild(u)}e.appendChild(s)}{let p=document.createElement("tbody");p.className="lextablebody",r.appendChild(p);for(let m=0;m<i.body.length;++m){let g=i.body[m],f=document.createElement("tr"),v=t.getSupportedDOMName(g.join("-"));if(f.setAttribute("rowId",v),a.selectable){let $=document.createElement("td"),y=document.createElement("input");y.type="checkbox",y.className="lexcheckbox",y.checked=i.checkMap[v],$.appendChild(y),y.addEventListener("change",function(){if(i.checkMap[v]=this.checked,!this.checked){let e=r.querySelector("thead input[type='checkbox']");e.checked=i.checkMap[":root"]=!1}}),f.appendChild($)}for(let E of g){let x=document.createElement("td");x.innerHTML=`${E}`,f.appendChild(x)}if(a.rowActions){let b=document.createElement("td");b.className="sm";let w=document.createElement("div");for(let L of(w.className="lextablebuttons",b.appendChild(w),a.rowActions)){let C=document.createElement("a");C.className="lexicon","delete"==L?(C.className+=" fa-solid fa-trash-can",C.addEventListener("click",function(){i.body.splice(m,1),f.remove()})):"menu"==L?(C.className+=" fa-solid fa-ellipsis",C.addEventListener("click",function(e){k(null,e,e=>{if(a.onMenuAction){a.onMenuAction(e);return}console.warn("Using <Menu action> without action callbacks.")})})):(console.assert(L.constructor==Object),C.className+=` ${L.icon}`),w.appendChild(C)}f.appendChild(b)}p.appendChild(f)}}},l.refreshTable(),l.name||(s.className+=" noname",n.style.width="100%"),s.appendChild(n),l}}t.Panel=L;class C{constructor(e,i={}){this.name=e;var a=document.createElement("div");a.className="lexbranch",i.id&&(a.id=i.id),i.className&&(a.className+=" "+i.className),a.style.width="calc(100% - 7px)",a.style.margin="0 auto";var l=this;this.root=a,this.widgets=[];var n=document.createElement("div");n.className="lexbranchtitle",n.innerHTML="<a class='fa-solid fa-angle-up switch-branch-button'></a>",i.icon&&(n.innerHTML+="<a class='branchicon "+i.icon+"' style='margin-right: 8px; margin-bottom: -2px;'>"),n.innerHTML+=e||"Branch",a.appendChild(n);var r=document.createElement("div");r.id=e.replace(/\s/g,""),r.className="lexbranchcontent",a.appendChild(r),this.content=r,this._addBranchSeparator(),i.closed&&(n.className+=" closed",a.className+=" closed",this.grabber.setAttribute("hidden",!0),s(()=>{this.content.setAttribute("hidden",!0)},15)),this.onclick=function(e){e.stopPropagation(),this.classList.toggle("closed"),this.parentElement.classList.toggle("closed"),l.content.toggleAttribute("hidden"),l.grabber.toggleAttribute("hidden"),t.emit("@on_branch_closed",this.classList.contains("closed"),{target:l.panel})},this.oncontextmenu=function(e){e.preventDefault(),e.stopPropagation(),!this.parentElement.classList.contains("dialog")&&k("Dock",e,t=>{e.preventDefault(),t.add("Floating",l._on_make_floating.bind(l))},{icon:"fa-regular fa-window-restore"})},n.addEventListener("click",this.onclick),n.addEventListener("contextmenu",this.oncontextmenu)}_on_make_floating(){let e=new _(this.name,e=>{for(let t of this.widgets)e.root.appendChild(t.domEl)});e.widgets=this.widgets;let t=this.root.parentElement;this.root.remove();let i=t.querySelector(".lexbranch");i&&i.classList.add("first");let a=t.querySelectorAll(".lexbranch");a.length&&a[a.length-1].classList.add("last")}_addBranchSeparator(){let e=document.createElement("div");e.className="lexwidgetseparator",e.style.width="100%",e.style.background="none";let a=document.createElement("div");a.innerHTML="&#9662;",e.appendChild(a),s(()=>{a.style.marginLeft=parseFloat(t.DEFAULT_NAME_WIDTH)/100*this.content.offsetWidth+"px"},10);let l=document.createElement("div");l.style.width="1px",l.style.marginLeft="6px",l.style.marginTop="2px",l.style.height="0px",a.appendChild(l),a.addEventListener("mousedown",function e(t){var i=n.root.ownerDocument;i.addEventListener("mouseup",o),i.addEventListener("mousemove",r),t.stopPropagation(),t.preventDefault();let a=n.root.offsetHeight-n.root.children[0].offsetHeight;l.style.height=a-3+"px",document.body.classList.add("nocursor")}),this.grabber=a;let n=this;function r(e){let t=e.movementX;if(0!=t){let l=parseFloat(a.style.marginLeft);a.style.marginLeft=i(l+t,32,n.content.offsetWidth-32)+"px"}}function o(e){n._updateWidgets(),l.style.height="0px";var t=n.root.ownerDocument;t.removeEventListener("mouseup",o),t.removeEventListener("mousemove",r),document.body.classList.remove("nocursor")}this.content.appendChild(e)}_updateWidgets(){for(var e=this.grabber.style.marginLeft,t=0;t<this.widgets.length;t++){let i=this.widgets[t],a=i.domEl;if(a.children.length<2)continue;var l=a.children[0],s=a.children[1];l.style.width=e;let n="0px";i.type===b.FILE&&(n="10%"),s.style.width="-moz-calc( 100% - "+e+" - "+n+" )",s.style.width="-webkit-calc( 100% - "+e+" - "+n+" )",s.style.width="calc( 100% - "+e+" - "+n+" )",i.onresize&&i.onresize()}}}t.Branch=C,t.Footer=class e{constructor(e={}){let t=document.createElement("footer");t.className="lexfooter";let i=document.createElement("div");if(i.className="wrapper",t.appendChild(i),e.columns&&e.columns.constructor==Array){let a=document.createElement("div");for(let l of(a.className="columns",a.style.gridTemplateColumns="1fr ".repeat(e.columns.length),i.appendChild(a),e.columns)){let s=document.createElement("div");s.className="col",a.appendChild(s);let n=document.createElement("h2");if(n.innerHTML=l.title,s.appendChild(n),!l.items||!l.items.length)continue;let r=document.createElement("ul");for(let o of(s.appendChild(r),l.items)){let d=document.createElement("li");d.innerHTML=`<a class="" href="${o.link}">${o.title}</a>`,r.appendChild(d)}}}if(e.credits||e.socials){let c=document.createElement("hr");i.appendChild(c);let h=document.createElement("div");if(h.className="credits-and-socials",i.appendChild(h),e.credits){let u=document.createElement("p");u.innerHTML=e.credits,h.appendChild(u)}if(e.socials){let p=document.createElement("div");for(let m of(p.className="social",e.socials)){let g=document.createElement("a");g.title=m.title,g.innerHTML=m.icon,g.href=m.link,g.target="_blank",p.appendChild(g)}h.appendChild(p)}}let f=e.parent??document.body;f.appendChild(t)}};class _{static _last_id=0;constructor(e,i,a={}){i||console.warn("Content is empty, add some widgets using 'callback' parameter!"),this._oncreate=i,this.id=u();let l=a.size??[],n=a.position??[],r=a.draggable??!0,o=a.modal??!1;var d=document.createElement("dialog");d.className="lexdialog "+(a.className??""),d.id=a.id??"dialog"+_._last_id++,t.root.appendChild(d),s(()=>{o?d.showModal():d.show()},10);let c=this;var h=document.createElement("div");if(e&&(h.className="lexdialogtitle",h.innerHTML=e,h.setAttribute("draggable",!1),h.oncontextmenu=function(i){i.preventDefault(),i.stopPropagation(),t.main_area&&"horizontal"===t.main_area.type&&k("Dock",i,a=>{i.preventDefault();let l=function(e){let t=e.panels[0];if(t)return t;for(var i of e.sections)if(t=l(i))return t},s=function(t){let i=t.branches.find(t=>t.name===e);for(let a of(i?t.root.appendChild(i.root):(t.branch(e),i=t.branches.find(t=>t.name===e)),c.widgets))i.content.appendChild(a.domEl);i.widgets=c.widgets,t.root.querySelectorAll(".lexbranch.last").forEach(e=>{e.classList.remove("last")}),i.root.classList.add("last"),d.remove()},n=l(t.main_area.sections[1]);a.add('<i class="fa-regular fa-window-maximize fa-window-maximize fa-rotate-90">',{disabled:!n,id:"dock_options0",callback(){s(n)}});let r=l(t.main_area.sections[0]);a.add('<i class="fa-regular fa-window-maximize fa-window-maximize fa-rotate-270">',{disabled:!r,id:"dock_options1",callback(){s(r)}})},{icon:"fa-regular fa-window-restore"})},d.appendChild(h)),a.closable??!0){this.close=()=>{a.onBeforeClose&&a.onBeforeClose(this),a.onclose?a.onclose(this.root):(d.close(),s(()=>{c.panel.clear(),d.remove()},150))};var m=document.createElement("a");m.className="lexdialogcloser fa-solid fa-xmark",m.title="Close",m.addEventListener("click",this.close),e?h.appendChild(m):(m.classList.add("notitle"),d.appendChild(m))}let g=new L;g.root.classList.add("lexdialogcontent"),e||g.root.classList.add("notitle"),i&&i.call(this,g),d.appendChild(g.root),g.root.querySelectorAll(".lexbranch").forEach(e=>e.classList.add("dialog")),this.panel=g,this.root=d,this.title=h,r&&p(d,Object.assign({targetClass:"lexdialogtitle"},a)),l.length&&"string"!=typeof l[0]&&(l[0]+="px"),l.length&&"string"!=typeof l[1]&&(l[1]+="px"),d.style.width=l[0]?l[0]:"25%",d.style.height=l[1]?l[1]:"auto",d.style.translate=a.position?"unset":"-50% -50%",a.size&&(this.size=l),d.style.left=n[0]??"50%",d.style.top=n[1]??"50%",g.root.style.width="calc( 100% - 30px )",g.root.style.height=e?"calc( 100% - "+(h.offsetHeight+30)+"px )":"calc( 100% - 51px )"}destroy(){this.root.remove()}refresh(){this.panel.root.innerHTML="",this._oncreate.call(this,this.panel)}setPosition(e,t){this.root.style.left=e+"px",this.root.style.top=t+"px"}setTitle(e){let t=this.root.querySelector(".lexdialogtitle");t&&(t.innerText=e)}}t.Dialog=_;class T extends _{static TOP=0;static BOTTOM=1;constructor(e,i,a={}){a.draggable=a.draggable??!1,a.closable=a.closable??!1,super(e,i,a);let l=this;if(t.addSignal("@on_branch_closed",this.panel,e=>{this.dock_pos==T.BOTTOM&&(this.root.style.top="calc(100% - "+(this.root.offsetHeight+3)+"px)")}),this.root.classList.add("pocket"),this.root.style.translate="none",this.root.style.top="0",this.root.style.left="unset",a.position||(this.root.style.right="3px",this.root.style.top="3px"),this.panel.root.style.width="calc( 100% - 12px )",this.panel.root.style.height="calc( 100% - 40px )",this.dock_pos=T.TOP,this.minimized=!1,this.title.tabIndex=-1,this.title.addEventListener("click",e=>{if(this.title._eventCatched){this.title._eventCatched=!1;return}this.size&&(this.minimized?this.root.style.height=this.size[1]:this.root.style.height="auto"),this.root.classList.toggle("minimized"),this.minimized=!this.minimized,this.dock_pos==T.BOTTOM&&(l.root.style.top=this.root.classList.contains("minimized")?"calc(100% - "+(l.title.offsetHeight+6)+"px)":"calc(100% - "+(l.root.offsetHeight+3)+"px)")}),!a.draggable){let s=a.float;if(s)for(var n=0;n<s.length;n++){let r=s[n];switch(r){case"b":this.root.style.top="calc(100% - "+(this.root.offsetHeight+3)+"px)";break;case"l":this.root.style.right="unset",this.root.style.left=a.position?a.position[1]:"3px"}}this.root.classList.add("dockable"),this.title.addEventListener("keydown",function(e){e.ctrlKey&&(l.root.style.right="unset","ArrowLeft"==e.key?l.root.style.left="0px":"ArrowRight"==e.key?l.root.style.left="calc(100% - "+(l.root.offsetWidth+3)+"px)":"ArrowUp"==e.key?(l.root.style.top="0px",l.dock_pos=T.TOP):"ArrowDown"==e.key&&(l.root.style.top="calc(100% - "+(l.root.offsetHeight+3)+"px)",l.dock_pos=T.BOTTOM))})}}}t.PocketDialog=T;class N{constructor(e,t,i={}){if(document.body.querySelectorAll(".lexcontextmenu").forEach(e=>e.remove()),this.root=document.createElement("div"),this.root.className="lexcontextmenu",this.root.style.left=e.x-48+document.scrollingElement.scrollLeft+"px",this.root.style.top=e.y-8+document.scrollingElement.scrollTop+"px",this.root.addEventListener("mouseleave",function(){this.remove()}),this.items=[],this.colors={},t){let a={};a[t]=[],a.className="cmtitle",a.icon=i.icon,this.items.push(a)}}_adjust_position(e,t,i=!1){let a=e.getBoundingClientRect();if(i){let l=window.innerWidth-a.right;l<0&&(e.style.left=e.offsetLeft+(l-t)+"px"),(l=window.innerHeight-(a.top+a.height))<0&&(e.style.top=e.offsetTop+(l-t+20)+"px")}else{let s=a.width;a.left<0?e.style.left=t+"px":window.innerWidth-a.right<0&&(e.style.left=window.innerWidth-s-t+"px"),a.top<0?e.style.top=t+"px":a.top+a.height>window.innerHeight&&(e.style.top=window.innerHeight-a.height-t+"px")}}_create_submenu(e,t,i,a){this.root.querySelectorAll(".lexcontextmenu").forEach(e=>e.remove());let l=document.createElement("div");l.className="lexcontextmenu",i.appendChild(l);for(var s=0;s<e[t].length;++s){let n=e[t][s],r=Object.keys(n)[0];this._create_entry(n,r,l,a)}var o=i.getBoundingClientRect();l.style.left=o.width+"px",l.style.marginTop=3.5-i.offsetHeight+"px",this._adjust_position(l,6,!0)}_create_entry(e,i,a,l){let s=e[i].length,r=document.createElement("div");r.className="lexmenuboxentry"+(e.className?" "+e.className:""),r.id=e.id??"eId"+n(i),r.innerHTML="";let o=e.icon;o&&(r.innerHTML+="<a class='"+o+" fa-sm'></a>");let d=e.disabled;if(r.innerHTML+="<div class='lexentryname"+(d?" disabled":"")+"'>"+i+"</div>",a.appendChild(r),this.colors[i]&&(r.style.borderColor=this.colors[i]),""==i){r.className+=" cmseparator";return}if(r.addEventListener("click",a=>{if(a.stopPropagation(),a.stopImmediatePropagation(),d)return;let n=e.callback;n&&(n.call(this,i,r),this.root.remove()),s&&"click"==t.OPEN_CONTEXTMENU_ENTRY&&this._create_submenu(e,i,r,++l)}),!s)return;let c=document.createElement("a");c.className="fa-solid fa-bars-staggered fa-xs",r.appendChild(c),"mouseover"==t.OPEN_CONTEXTMENU_ENTRY&&r.addEventListener("mouseover",t=>{r.built||(r.built=!0,this._create_submenu(e,i,r,++l),t.stopPropagation())}),r.addEventListener("mouseleave",()=>{l=-1,a.querySelectorAll(".lexcontextmenu").forEach(e=>e.remove())})}onCreate(){s(()=>this._adjust_position(this.root,6))}add(e,t={}){t.constructor==Function&&(t={callback:t}),e+="";let i=e.split("/"),a=i[i.length-1];this.colors[a]=t.color;let l=0,s=(e,a)=>{if(void 0==e)return;let n=null;if(a.forEach(t=>{let i=Object.keys(t),a=i.find(t=>t==e);a&&(n=t[a])}),n)s(i[l++],n);else{let r={};r[e]=[];let o=i[l++];o||(r.id=t.id,r.callback=t.callback,r.disabled=t.disabled??!1),a.push(r),s(o,r[e])}};s(i[l++],this.items);let r=e=>{let t=Object.keys(e)[0],i=e[t];if(i.length){if(null==i.find(e=>Object.keys(e)[0]==t)){let a={};a[t]=[],a.className="cmtitle",e[t].unshift(a)}for(var l of e[t]){let s=Object.keys(l)[0];for(var n=0;n<l[s].length;++n)r(l)}}};for(let o of this.items)r(o);for(let d of this.items){let c=Object.keys(d)[0],h="eId"+n(c),u="#"+(d.id??h);this.root.querySelector(u)||this._create_entry(d,c,this.root,-1)}}setColor(e,t){"#"!==t[0]&&(t=c(t)),this.colors[e]=t}}function k(e,i,a,l){var s=new N(i,e,l);return t.root.appendChild(s.root),a&&a(s),s.onCreate(),s}t.ContextMenu=N,t.addContextMenu=k;class A{constructor(e,i,a={}){let l=document.createElement("div");l.className="curve "+(a.className?a.className:""),l.style.minHeight="50px",l.style.width=a.width||"100%",l.style.minWidth="50px",l.style.minHeight="20px",l.bgcolor=a.bgColor||t.getThemeColor("global-intense-background"),l.pointscolor=a.pointsColor||t.getThemeColor("global-selected-light"),l.linecolor=a.lineColor||"#555",l.value=i||[],l.xrange=a.xrange||[0,1],l.yrange=a.yrange||[0,1],l.defaulty=null!=a.defaulty?a.defaulty:0,l.no_overlap=a.noOverlap||!1,l.show_samples=a.showSamples||0,l.allow_add_values=a.allowAddValues??!0,l.draggable_x=a.draggableX??!0,l.draggable_y=a.draggableY??!0,l.smooth=(a.smooth&&"number"==typeof a.smooth?a.smooth:.3)||!1,l.move_out=a.moveOutAction??t.CURVE_MOVEOUT_DELETE,t.addSignal("@on_new_color_scheme",(e,i)=>{l.bgcolor=a.bgColor||t.getThemeColor("global-intense-background"),l.pointscolor=a.pointsColor||t.getThemeColor("global-selected-light"),this.redraw()}),this.element=l;let s=document.createElement("canvas");function n(e){return[s.width*(e[0]-l.xrange[0])/l.xrange[1],s.height*(e[1]-l.yrange[0])/l.yrange[1]]}function r(e){return[e[0]*l.xrange[1]/s.width+l.xrange[0],e[1]*l.yrange[1]/s.height+l.yrange[0]]}s.width=a.width||200,s.height=a.height||50,l.appendChild(s),this.canvas=s,l.addEventListener("mousedown",function e(i){document.addEventListener("mousemove",c),document.addEventListener("mouseup",h);var a=s.getBoundingClientRect(),u=i.clientX-a.left,g=i.clientY-a.top;if(o=function e(t,i){for(var a=1e5,s=-1,r=0;r<l.value.length;r++){var o=n(l.value[r]),d=p([t,i],o);d<a&&d<8&&(a=d,s=r)}return s}(u,s.height-g),i.button==t.MOUSE_LEFT_CLICK&&-1==o&&l.allow_add_values){var f=r([u,s.height-g]);l.value.push(f),m(),o=l.value.indexOf(f)}d=[u,g],l.redraw(),i.preventDefault(),i.stopPropagation()}),l.getValueAt=function(e){if(e<l.xrange[0]||e>l.xrange[1])return l.defaulty;for(var t=[l.xrange[0],l.defaulty],i=0,a=0;a<l.value.length;a+=1){var s=l.value[a];if(e==s[0])return s[1];if(e<s[0])return i=(e-t[0])/(s[0]-t[0]),t[1]*(1-i)+s[1]*i;t=s}return s=[l.xrange[1],l.defaulty],i=(e-t[0])/(s[0]-t[0]),t[1]*(1-i)+s[1]*i},l.resample=function(e){for(var t=[],i=(l.xrange[1]-l.xrange[0])/e,a=l.xrange[0];a<=l.xrange[1];a+=i)t.push(l.getValueAt(a));return t},l.addValue=function(e){for(var t=0;t<l.value;t++)if(!(l.value[t][0]<e[0])){l.value.splice(t,0,e),redraw();return}l.value.push(e),redraw()};var o=-1;l.redraw=function(e={}){e.value&&(l.value=e.value),e.xrange&&(l.xrange=e.xrange),e.yrange&&(l.yrange=e.yrange),e.smooth&&(l.smooth=e.smooth);var i=s.parentElement.getBoundingClientRect();s.parentElement.parentElement&&(i=s.parentElement.parentElement.getBoundingClientRect()),i&&s.width!=i.width&&i.width&&i.width<1e3&&(s.width=i.width);var a=s.getContext("2d");a.setTransform(1,0,0,1,0,0),a.translate(0,s.height),a.scale(1,-1),a.fillStyle=l.bgcolor,a.fillRect(0,0,s.width,s.height),a.strokeStyle=l.linecolor,a.beginPath();var r=n([l.xrange[0],l.defaulty]);a.moveTo(r[0],r[1]);let d=[r[0],r[1]];for(var c in l.value){var h=l.value[c];r=n(h),d.push(r[0]),d.push(r[1]),l.smooth||a.lineTo(r[0],r[1])}r=n([l.xrange[1],l.defaulty]),d.push(r[0]),d.push(r[1]),l.smooth?t.UTILS.drawSpline(a,d,l.smooth):(a.lineTo(r[0],r[1]),a.stroke());for(var c=0;c<l.value.length;c+=1){var h=l.value[c];r=n(h),o==c?a.fillStyle="white":a.fillStyle=l.pointscolor,a.beginPath(),a.arc(r[0],r[1],o==c?4:3,0,2*Math.PI),a.fill()}if(l.show_samples){var u=l.resample(l.show_samples);a.fillStyle="#888";for(var c=0;c<u.length;c+=1){var h=[c*((l.xrange[1]-l.xrange[0])/l.show_samples)+l.xrange[0],u[c]];r=n(h),a.beginPath(),a.arc(r[0],r[1],2,0,2*Math.PI),a.fill()}}};var d=[0,0];function c(e){var i=s.getBoundingClientRect(),a=e.clientX-i.left,n=e.clientY-i.top;a<0?a=0:a>s.width&&(a=s.width),n<0?n=0:n>s.height&&(n=s.height);let c=[e.clientX-i.left,e.clientY-i.top];if(-1!=o&&p(c,[a,n])>.5*s.height){if(l.move_out==t.CURVE_MOVEOUT_DELETE)l.value.splice(o,1);else{let g=[c[0]-a,c[1]-n],f=l.value[o];f[0]=0==g[0]?f[0]:g[0]<0?l.xrange[0]:l.xrange[1],f[1]=0==g[1]?f[1]:g[1]<0?l.yrange[1]:l.yrange[0]}h(e);return}var v,$=r([-(l.draggable_x?d[0]-a:0),l.draggable_y?d[1]-n:0]);if(-1!=o){var y=l.xrange[0],E=l.xrange[1];l.no_overlap&&(o>0&&(y=l.value[o-1][0]),o<l.value.length-1&&(E=l.value[o+1][0]));var x=l.value[o];x[0]+=$[0],x[1]+=$[1],x[0]<y?x[0]=y:x[0]>E&&(x[0]=E),x[1]<l.yrange[0]?x[1]=l.yrange[0]:x[1]>l.yrange[1]&&(x[1]=l.yrange[1])}m(),l.redraw(),d[0]=a,d[1]=n,u(e),e.preventDefault(),e.stopPropagation()}function h(e){o=-1,l.redraw(),document.removeEventListener("mousemove",c),document.removeEventListener("mouseup",h),u(e),e.preventDefault(),e.stopPropagation()}function u(e){a.callback&&a.callback.call(l,l.value,e)}function p(e,t){return Math.sqrt(Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2))}function m(){var e=null;-1!=o&&(e=l.value[o]),l.value.sort(function(e,t){return e[0]-t[0]}),e&&(o=l.value.indexOf(e))}return l.redraw(),this}redraw(e={}){this.element.redraw(e)}}t.Curve=A;class S{constructor(e,i,a={}){let l=document.createElement("div");l.className="dial "+(a.className?a.className:""),l.style.width=l.style.height=a.size||"100%",l.style.minWidth=l.style.minHeight="50px",l.bgcolor=a.bgColor||t.getThemeColor("global-dark-background"),l.pointscolor=a.pointsColor||t.getThemeColor("global-selected-light"),l.linecolor=a.lineColor||"#555",l.value=i||[],l.xrange=a.xrange||[0,1],l.yrange=a.yrange||[0,1],l.defaulty=null!=a.defaulty?a.defaulty:0,l.no_overlap=a.noOverlap||!1,l.show_samples=a.showSamples||0,l.allow_add_values=a.allowAddValues??!0,l.draggable_x=a.draggableX??!0,l.draggable_y=a.draggableY??!0,l.smooth=(a.smooth&&"number"==typeof a.smooth?a.smooth:.3)||!1,l.move_out=a.moveOutAction??t.CURVE_MOVEOUT_DELETE,this.element=l;let s=document.createElement("canvas");function n(e,t){return e[0],[s.width*(e[0]-l.xrange[0])/l.xrange[1],s.height*(e[1]-l.yrange[0])/l.yrange[1]]}function r(e){return[e[0]*l.xrange[1]/s.width+l.xrange[0],e[1]*l.yrange[1]/s.height+l.yrange[0]]}s.width=s.height=a.size||200,l.appendChild(s),this.canvas=s,l.addEventListener("mousedown",function e(i){document.addEventListener("mousemove",c),document.addEventListener("mouseup",h);var a=s.getBoundingClientRect(),u=i.clientX-a.left,g=i.clientY-a.top;if(o=function e(t,i){for(var a=1e5,s=-1,r=0;r<l.value.length;r++){var o=n(l.value[r]),d=p([t,i],o);d<a&&d<8&&(a=d,s=r)}return s}(u,s.height-g),i.button==t.MOUSE_LEFT_CLICK&&-1==o&&l.allow_add_values){var f=r([u,s.height-g]);l.value.push(f),m(),o=l.value.indexOf(f)}d=[u,g],l.redraw(),i.preventDefault(),i.stopPropagation()}),l.getValueAt=function(e){if(e<l.xrange[0]||e>l.xrange[1])return l.defaulty;for(var t=[l.xrange[0],l.defaulty],i=0,a=0;a<l.value.length;a+=1){var s=l.value[a];if(e==s[0])return s[1];if(e<s[0])return i=(e-t[0])/(s[0]-t[0]),t[1]*(1-i)+s[1]*i;t=s}return s=[l.xrange[1],l.defaulty],i=(e-t[0])/(s[0]-t[0]),t[1]*(1-i)+s[1]*i},l.resample=function(e){for(var t=[],i=(l.xrange[1]-l.xrange[0])/e,a=l.xrange[0];a<=l.xrange[1];a+=i)t.push(l.getValueAt(a));return t},l.addValue=function(e){for(var t=0;t<l.value;t++)if(!(l.value[t][0]<e[0])){l.value.splice(t,0,e),redraw();return}l.value.push(e),redraw()};var o=-1;l.redraw=function(e={}){e.value&&(l.value=e.value),e.xrange&&(l.xrange=e.xrange),e.yrange&&(l.yrange=e.yrange),e.smooth&&(l.smooth=e.smooth);var t=s.parentElement.getBoundingClientRect();s.parentElement.parentElement&&(t=s.parentElement.parentElement.getBoundingClientRect()),t&&s.width!=t.width&&t.width&&t.width<1e3&&(s.width=t.width);var i=s.getContext("2d");i.setTransform(1,0,0,1,0,0),i.translate(0,s.height),i.scale(1,-1),i.fillStyle=l.bgcolor,i.fillRect(0,0,s.width,s.height),i.strokeStyle=l.linecolor,i.beginPath();var a=n([l.xrange[0],l.defaulty]);i.moveTo(a[0],a[1]);let r=[a[0],a[1]];for(var d in l.value){var c=l.value[d];a=n(c),r.push(a[0]),r.push(a[1])}a=n([l.xrange[1],l.defaulty]),r.push(a[0]),r.push(a[1]),a=n([0,0]),i.fillStyle="gray",i.beginPath(),i.arc(a[0],a[1],3,0,2*Math.PI),i.fill();for(var d=0;d<l.value.length;d+=1){var c=l.value[d];a=n(c),o==d?i.fillStyle="white":i.fillStyle=l.pointscolor,i.beginPath(),i.arc(a[0],a[1],o==d?4:3,0,2*Math.PI),i.fill()}if(l.show_samples){var h=l.resample(l.show_samples);i.fillStyle="#888";for(var d=0;d<h.length;d+=1){var c=[d*((l.xrange[1]-l.xrange[0])/l.show_samples)+l.xrange[0],h[d]];a=n(c),i.beginPath(),i.arc(a[0],a[1],2,0,2*Math.PI),i.fill()}}};var d=[0,0];function c(e){var i=s.getBoundingClientRect(),a=e.clientX-i.left,n=e.clientY-i.top;a<0?a=0:a>s.width&&(a=s.width),n<0?n=0:n>s.height&&(n=s.height);let c=[e.clientX-i.left,e.clientY-i.top];if(-1!=o&&p(c,[a,n])>.5*s.height){if(l.move_out==t.CURVE_MOVEOUT_DELETE)l.value.splice(o,1);else{let g=[c[0]-a,c[1]-n],f=l.value[o];f[0]=0==g[0]?f[0]:g[0]<0?l.xrange[0]:l.xrange[1],f[1]=0==g[1]?f[1]:g[1]<0?l.yrange[1]:l.yrange[0]}h(e);return}var v,$=r([-(l.draggable_x?d[0]-a:0),l.draggable_y?d[1]-n:0]);if(-1!=o){var y=l.xrange[0],E=l.xrange[1];l.no_overlap&&(o>0&&(y=l.value[o-1][0]),o<l.value.length-1&&(E=l.value[o+1][0]));var x=l.value[o];x[0]+=$[0],x[1]+=$[1],x[0]<y?x[0]=y:x[0]>E&&(x[0]=E),x[1]<l.yrange[0]?x[1]=l.yrange[0]:x[1]>l.yrange[1]&&(x[1]=l.yrange[1])}m(),l.redraw(),d[0]=a,d[1]=n,u(e),e.preventDefault(),e.stopPropagation()}function h(e){o=-1,l.redraw(),document.removeEventListener("mousemove",c),document.removeEventListener("mouseup",h),u(e),e.preventDefault(),e.stopPropagation()}function u(e){a.callback&&a.callback.call(l,l.value,e)}function p(e,t){return Math.sqrt(Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2))}function m(){var e=null;-1!=o&&(e=l.value[o]),l.value.sort(function(e,t){return e[0]-t[0]}),e&&(o=l.value.indexOf(e))}return l.redraw(),this}redraw(e={}){this.element.redraw(e)}}t.Dial=S;class D{static NONE=0;static ASSET_SELECTED=1;static ASSET_DELETED=2;static ASSET_RENAMED=3;static ASSET_CLONED=4;static ASSET_DBLCLICKED=5;static ENTER_FOLDER=6;static ASSET_CHECKED=7;constructor(e,t,i){this.type=e||f.NONE,this.item=t,this.value=i,this.multiple=!1}string(){switch(this.type){case D.NONE:return"assetview_event_none";case D.ASSET_SELECTED:return"assetview_event_selected";case D.ASSET_DELETED:return"assetview_event_deleted";case D.ASSET_RENAMED:return"assetview_event_renamed";case D.ASSET_CLONED:return"assetview_event_cloned";case D.ASSET_DBLCLICKED:return"assetview_event_dblclicked";case D.ENTER_FOLDER:return"assetview_event_enter_folder";case D.ASSET_CHECKED:return"assetview_event_checked"}}}t.AssetViewEvent=D;class P{static LAYOUT_CONTENT=0;static LAYOUT_LIST=1;static MAX_PAGE_ELEMENTS=50;constructor(e={}){this.rootPath="https://raw.githubusercontent.com/jxarco/lexgui.js/master/",this.layout=e.layout??P.LAYOUT_CONTENT,this.contentPage=1,e.rootPath&&(e.rootPath.constructor!==String?console.warn("Asset Root Path must be a String (now is "+path.constructor.name+")"):this.rootPath=e.rootPath);let i=document.createElement("div");i.className="lexassetbrowser",this.root=i;let a=new t.Area({height:"100%"});i.appendChild(a.root);let l,s,n=a;this.skipBrowser=e.skipBrowser??!1,this.skipPreview=e.skipPreview??!1,this.useNativeTitle=e.useNativeTitle??!1,this.onlyFolders=e.onlyFolders??!0,this.allowMultipleSelection=e.allowMultipleSelection??!1,this.previewActions=e.previewActions??[],this.contextMenu=e.contextMenu??[],this.onRefreshContent=e.onRefreshContent,this.skipBrowser||([l,s]=a.split({type:"horizontal",sizes:["15%","85%"]}),n=s,l.setLimitBox(210,0),s.setLimitBox(512,0)),this.skipPreview||([n,s]=n.split({type:"horizontal",sizes:["80%","20%"]})),this.allowedTypes=e.allowedTypes||["None","Image","Mesh","Script","JSON","Clip"],this.prevData=[],this.nextData=[],this.data=[],this._processData(this.data,null),this.currentData=this.data,this.path=["@"],this.skipBrowser||this._createTreePanel(l),this._createContentPanel(n),this.skipPreview||(this.previewPanel=s.addPanel({className:"lexassetcontentpanel",style:{overflow:"scroll"}}))}load(e,t){this.prevData.length=0,this.nextData.length=0,this.data=e,this._processData(this.data,null),this.currentData=this.data,this.path=["@"],this.skipBrowser||this._createTreePanel(this.area),this._refreshContent(),this.onevent=t}clear(){this.previewPanel&&this.previewPanel.clear(),this.leftPanel&&this.leftPanel.clear(),this.rightPanel&&this.rightPanel.clear()}_processData(e,t){e.constructor!==Array&&(e.folder=t,e.children=e.children??[]);let i=e.constructor===Array?e:e.children;for(var a=0;a<i.length;++a)this._processData(i[a],e)}_updatePath(e){this.path.length=0;let i=e=>{if(!e)return;let t=(e.children?e.children:e)[0];t&&t.folder&&(this.path.push(t.folder.id??"@"),i(t.folder.folder))};i(e),t.emit("@on_folder_change",this.path.reverse().join("/"))}_createTreePanel(e){this.leftPanel?this.leftPanel.clear():this.leftPanel=e.addPanel({className:"lexassetbrowserpanel"});let i={id:"/",children:this.data};this.tree=this.leftPanel.addTree("Content Browser",i,{filter:!1,onlyFolders:this.onlyFolders,onevent:e=>{let i=e.node,a=e.value;switch(e.type){case t.TreeEvent.NODE_SELECTED:e.multiple||this._enterFolder(i),i.parent||(this.prevData.push(this.currentData),this.currentData=this.data,this._refreshContent(),this.path=["@"],t.emit("@on_folder_change",this.path.join("/")));break;case t.TreeEvent.NODE_DRAGGED:i.folder=a,this._refreshContent()}}})}_setContentLayout(e){this.layout=e,this._refreshContent()}_createContentPanel(e){this.rightPanel?this.rightPanel.clear():this.rightPanel=e.addPanel({className:"lexassetcontentpanel"});let t=(e,t)=>{let i=k("Sort by",t,e=>{e.add("Name",()=>this._sortData("id")),e.add("Type",()=>this._sortData("type")),e.add(""),e.add("Ascending",()=>this._sortData()),e.add("Descending",()=>this._sortData(null,!0))}),a=this.parent.root.parentElement;a.classList.contains("lexdialog")&&(i.root.style.zIndex=+getComputedStyle(a).zIndex+1)},i=(e,t)=>{let i=k("Layout",t,e=>{e.add("Content",()=>this._setContentLayout(P.LAYOUT_CONTENT)),e.add(""),e.add("List",()=>this._setContentLayout(P.LAYOUT_LIST))}),a=this.parent.root.parentElement;a.classList.contains("lexdialog")&&(i.root.style.zIndex=+getComputedStyle(a).zIndex+1)},a=(e,t)=>{if(!this.allowNextPage)return;let i=this.contentPage;this.contentPage+=e,this.contentPage=Math.min(this.contentPage,((this.currentData.length-1)/P.MAX_PAGE_ELEMENTS|0)+1),this.contentPage=Math.max(this.contentPage,1),i!=this.contentPage&&this._refreshContent()};this.rightPanel.sameLine(),this.rightPanel.addDropdown("Filter",this.allowedTypes,this.allowedTypes[0],e=>this._refreshContent.call(this,null,e),{width:"30%",minWidth:"128px"}),this.rightPanel.addText(null,this.searchValue??"",e=>this._refreshContent.call(this,e,null),{placeholder:"Search assets.."}),this.rightPanel.addButton(null,"<a class='fa fa-arrow-up-short-wide'></a>",t.bind(this),{className:"micro",title:"Sort"}),this.rightPanel.addButton(null,"<a class='fa-solid fa-grip'></a>",i.bind(this),{className:"micro",title:"View"}),this.rightPanel.addButton(null,"<a class='fa-solid fa-angles-left'></a>",a.bind(this,-1),{className:"micro",title:"Previous Page"}),this.rightPanel.addButton(null,"<a class='fa-solid fa-angles-right'></a>",a.bind(this,1),{className:"micro",title:"Next Page"}),this.rightPanel.endLine(),this.skipBrowser||(this.rightPanel.sameLine(),this.rightPanel.addComboButtons(null,[{value:"Left",icon:"fa-solid fa-left-long",callback:e=>{this.prevData.length&&(this.nextData.push(this.currentData),this.currentData=this.prevData.pop(),this._refreshContent(),this._updatePath(this.currentData))}},{value:"Right",icon:"fa-solid fa-right-long",callback:e=>{this.nextData.length&&(this.prevData.push(this.currentData),this.currentData=this.nextData.pop(),this._refreshContent(),this._updatePath(this.currentData))}},{value:"Refresh",icon:"fa-solid fa-arrows-rotate",callback:e=>{this._refreshContent()}}],{width:"20%",minWidth:"164px",noSelection:!0}),this.rightPanel.addText(null,this.path.join("/"),null,{width:"70%",maxWidth:"calc(70% - 64px)",minWidth:"164px",disabled:!0,signal:"@on_folder_change",style:{fontWeight:"bolder",fontSize:"16px",color:"#aaa"}}),this.rightPanel.addText(null,"Page "+this.contentPage+" / "+(((this.currentData.length-1)/P.MAX_PAGE_ELEMENTS|0)+1),null,{disabled:!0,signal:"@on_page_change",width:"fit-content"}),this.rightPanel.endLine()),this.content=document.createElement("ul"),this.content.className="lexassetscontent",this.rightPanel.root.appendChild(this.content),this.content.addEventListener("dragenter",function(e){e.preventDefault(),this.classList.add("dragging")}),this.content.addEventListener("dragleave",function(e){e.preventDefault(),this.classList.remove("dragging")}),this.content.addEventListener("drop",e=>{e.preventDefault(),this._processDrop(e)}),this.content.addEventListener("click",function(){this.querySelectorAll(".lexassetitem").forEach(e=>e.classList.remove("selected"))}),this._refreshContent()}_refreshContent(e,i){let a=this.layout==P.LAYOUT_CONTENT;this.filter=i??this.filter??"None",this.searchValue=e??this.searchValue??"",this.content.innerHTML="",this.content.className=a?"lexassetscontent":"lexassetscontent list";let l=this,s=function(e){let i=e.type.charAt(0).toUpperCase()+e.type.slice(1),s=r(e.id),n="Folder"===i,o=document.createElement("li");if(o.className="lexassetitem "+e.type.toLowerCase(),o.tabIndex=-1,l.content.appendChild(o),l.useNativeTitle)o.title=i+": "+e.id;else{let d=document.createElement("span");d.className="lexitemdesc",d.innerHTML="File: "+e.id+"<br>Type: "+i,l.content.appendChild(d),o.addEventListener("mousemove",e=>{if(!a)return;let t=o.getBoundingClientRect(),i=e.target.getBoundingClientRect(),l=d.parentElement.getBoundingClientRect(),s=i.x-l.x-(i.x-t.x),n=i.y-l.y-(i.y-t.y);e.target.classList.contains("lexassettitle")&&(n+=i.y-t.y),d.style.left=s+e.offsetX+12+"px",d.style.top=n+e.offsetY+"px"}),o.addEventListener("mouseenter",()=>{a&&(d.style.display="unset")}),o.addEventListener("mouseleave",()=>{a&&setTimeout(()=>{d.style.display="none"},100)})}if(l.allowMultipleSelection){let c=document.createElement("input");c.type="checkbox",c.className="lexcheckbox",c.checked=e.selected,c.addEventListener("change",(t,i)=>{if(e.selected=!e.selected,l.onevent){let a=new D(D.ASSET_CHECKED,t.shiftKey?[e]:e);a.multiple=!!t.shiftKey,l.onevent(a)}t.stopPropagation(),t.stopImmediatePropagation()}),o.appendChild(c)}let h=document.createElement("span");if(h.className="lexassettitle",h.innerText=e.id,o.appendChild(h),!l.skipPreview){let u=null,p=e.src&&(["png","jpg"].indexOf(r(e.src))>-1||e.src.includes("data:image/"));if(p||n||!a){u=document.createElement("img");let m=e.unknown_extension?l.rootPath+"images/file.png":n?l.rootPath+"images/folder.png":e.src;u.src=a||n?m:l.rootPath+"images/file.png",o.appendChild(u)}else{(u=document.createElement("svg")).className="asset-file-preview",o.appendChild(u);let g=document.createElement("text");u.appendChild(g),g.innerText=s&&s!=e.id?"."+s.toUpperCase():e.type.toUpperCase();var f,v=2.5/g.innerText.length;v<1&&(g.style.fontSize=64*v+"px",u.style.paddingTop="calc(50% - "+(.5*g.offsetHeight+10)+"px)")}}if(!n){let $=document.createElement("span");$.className="lexassetinfo",$.innerText=i,o.appendChild($)}return o.addEventListener("click",function(i){i.stopImmediatePropagation(),i.stopPropagation();let a=i.detail==t.MOUSE_DOUBLE_CLICK;if(a){if(n){l._enterFolder(e);return}}else i.shiftKey||l.content.querySelectorAll(".lexassetitem").forEach(e=>e.classList.remove("selected")),this.classList.add("selected"),l.selectedItem=e,l.skipPreview||l._previewAsset(e);if(l.onevent){let s=new D(a?D.ASSET_DBLCLICKED:D.ASSET_SELECTED,i.shiftKey?[e]:e);s.multiple=!!i.shiftKey,l.onevent(s)}}),l.contextMenu&&o.addEventListener("contextmenu",function(i){i.preventDefault();let a=l.content.querySelectorAll(".selected").length;t.addContextMenu(a>1?a+" selected":n?e.id:e.type,i,t=>{a<=1&&t.add("Rename"),n||t.add("Clone",l._cloneItem.bind(l,e)),a<=1&&t.add("Properties"),t.add(""),t.add("Delete",l._deleteItem.bind(l,e))})}),o.addEventListener("dragstart",function(e){e.preventDefault()},!1),o},n=new FileReader,o=this.currentData.filter(e=>("None"==this.filter||e.type.toLowerCase()==this.filter.toLowerCase())&&e.id.toLowerCase().includes(this.searchValue.toLowerCase()));(i||e)&&(this.contentPage=1);let d=(this.contentPage-1)*P.MAX_PAGE_ELEMENTS,c=Math.min(d+P.MAX_PAGE_ELEMENTS,o.length);for(let h=d;h<c;++h){let u=o[h];u.path?t.request({url:u.path,dataType:"blob",success:t=>{u.bytesize=t.size,n.readAsDataURL(t),n.onload=t=>{u.src=t.currentTarget.result,u._path=u.path,delete u.path,this._refreshContent(e,i)}}}):u.domEl=s(u)}this.allowNextPage=o.length-1>P.MAX_PAGE_ELEMENTS,t.emit("@on_page_change","Page "+this.contentPage+" / "+(((o.length-1)/P.MAX_PAGE_ELEMENTS|0)+1)),this.onRefreshContent&&this.onRefreshContent(e,i)}_previewAsset(e){let i=e.src&&e.src.includes("data:image/");if(this.previewPanel.clear(),this.previewPanel.branch("Asset"),"image"==e.type||e.src){let a=["png","jpg"].indexOf(r(e.src))>-1||i;a&&this.previewPanel.addImage(e.src,{style:{width:"100%"}})}let l={disabled:!0};this.previewPanel.addText("Filename",e.id,null,l),e.lastModified&&this.previewPanel.addText("Last Modified",new Date(e.lastModified).toLocaleString(),null,l),(e._path||e.src)&&this.previewPanel.addText("URL",e._path?e._path:e.src,null,l),this.previewPanel.addText("Path",this.path.join("/"),null,l),this.previewPanel.addText("Type",e.type,null,l),e.bytesize&&this.previewPanel.addText("Size",(e.bytesize/1024).toPrecision(3)+" KBs",null,l),"folder"==e.type&&this.previewPanel.addText("Files",e.children?e.children.length.toString():"0",null,l),this.previewPanel.addSeparator();let s=[...this.previewActions];for(let n of(s.length||s.push({name:"Download",callback:()=>t.downloadURL(e.src,e.id)}),s))n.type&&n.type!==e.type||n.path&&n.path!==this.path.join("/")||this.previewPanel.addButton(null,n.name,n.callback.bind(this,e));this.previewPanel.merge()}_processDrop(e){let t=new FileReader,i=e.dataTransfer.files.length;for(let a=0;a<e.dataTransfer.files.length;++a){let l=e.dataTransfer.files[a],s=this.currentData.find(e=>e.id===l.name);s||(t.readAsDataURL(l),t.onload=e=>{let t=l.name.substr(l.name.lastIndexOf(".")+1).toLowerCase(),s={id:l.name,src:e.currentTarget.result,extension:t,lastModified:l.lastModified};switch(t){case"png":case"jpg":s.type="image";break;case"js":case"css":s.type="script";break;case"json":s.type="json";break;case"obj":s.type="mesh";break;default:s.type=t,s.unknown_extension=!0}this.currentData.push(s),a!=i-1||(this._refreshContent(),this.skipBrowser||this.tree.refresh())})}}_sortData(e,t=!1){e=e??this._lastSortBy??"id",this.currentData=this.currentData.sort((i,a)=>{var l=t?a[e].localeCompare(i[e]):i[e].localeCompare(a[e]);return 0==l&&(l=t?a.id.localeCompare(i.id):i.id.localeCompare(a.id)),l}),this._lastSortBy=e,this._refreshContent()}_enterFolder(e){if(this.prevData.push(this.currentData),this.currentData=e.children,this.contentPage=1,this._refreshContent(),this._updatePath(this.currentData),this.onevent){let t=new D(D.ENTER_FOLDER,e);this.onevent(t)}}_deleteItem(e){let t=this.currentData.indexOf(e);if(t<0){console.error("[AssetView Error] Cannot delete. Item not found.");return}if(this.currentData.splice(t,1),this._refreshContent(this.searchValue,this.filter),this.onevent){let i=new D(D.ASSET_DELETED,e);this.onevent(i)}this.tree.refresh(),this._processData(this.data)}_cloneItem(e){let t=this.currentData.indexOf(e);if(t<0)return;delete e.domEl,delete e.folder;let i=o(e);if(this.currentData.splice(t,0,i),this._refreshContent(this.searchValue,this.filter),this.onevent){let a=new D(D.ASSET_CLONED,e);this.onevent(a)}this._processData(this.data)}}t.AssetView=P,Object.assign(t,{request(e){var t=e.dataType||"text";"json"==t?t="text":"xml"==t?t="text":"binary"==t&&(t="arraybuffer",e.mimeType="application/octet-stream");var i=new XMLHttpRequest;i.open(e.data?"POST":"GET",e.url,!0),t&&(i.responseType=t),e.mimeType&&i.overrideMimeType(e.mimeType),e.nocache&&i.setRequestHeader("Cache-Control","no-cache"),i.onload=function(t){var i=this.response;if(200!=this.status){var a="Error "+this.status;e.error&&e.error(a);return}if("json"==e.dataType)try{i=JSON.parse(i)}catch(l){if(e.error)e.error(l);else throw l}else if("xml"==e.dataType)try{i=new DOMParser().parseFromString(i,"text/xml")}catch(s){if(e.error)e.error(s);else throw s}e.success&&e.success.call(this,i,this)},i.onerror=function(t){e.error&&e.error(t)};var a=new FormData;if(e.data)for(var l in e.data)a.append(l,e.data[l]);return i.send(a),i},requestText(e,t,i){return this.request({url:e,dataType:"text",success:t,error:i})},requestJSON(e,t,i){return this.request({url:e,dataType:"json",success:t,error:i})},requestBinary(e,t,i){return this.request({url:e,dataType:"binary",success:t,error:i})},requireScript(e,t,i,a,l){if(!e)throw"invalid URL";e.constructor===String&&(e=[e]);var s=e.length,n=[];for(var r in e){var o=document.createElement("script");o.num=r,o.type="text/javascript",o.src=e[r]+(l?"?version="+l:""),o.original_src=e[r],o.async=!1,o.onload=function(e){s--,n.push(this),s?a&&a(this.original_src,this.num):t&&t(n)},i&&(o.onerror=function(e){i(e,this.original_src,this.num)}),document.getElementsByTagName("head")[0].appendChild(o)}},downloadURL(e,i){let a=new FileReader,l=function(e){var t=document.createElement("a");t.href=e,t.download=i,document.body.appendChild(t),t.click(),document.body.removeChild(t)};e.includes("http")?t.request({url:e,dataType:"blob",success(e){a.readAsDataURL(e),a.onload=e=>{l(e.currentTarget.result)}}}):l(e)},downloadFile:function(e,t,i){if(!t){console.warn("No file provided to download");return}i||(i=t.constructor===String?"text/plain":"application/octet-stream");var a=null;a=t.constructor!==File&&t.constructor!==Blob?new Blob([t],{type:i}):t;var l=URL.createObjectURL(a),s=document.createElement("a");s.setAttribute("href",l),s.setAttribute("download",e),s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(function(){URL.revokeObjectURL(l)},6e4)}}),Object.defineProperty(String.prototype,"lastChar",{get:function(){return this[this.length-1]},enumerable:!0,configurable:!0}),Element.prototype.insertChildAtIndex=function(e,t=1/0){t>=this.children.length?this.appendChild(e):this.insertBefore(e,this.children[t])},Element.prototype.hasClass=function(e){return!!(e=[].concat(e)).filter(e=>this.classList.contains(e)).length},Element.prototype.addClass=function(e){e&&this.classList.add(e)},Element.prototype.getComputedSize=function(){let e=getComputedStyle(this);return{width:this.offsetWidth+e.getPropertyValue("marginLeft")+e.getPropertyValue("marginRight"),height:this.offsetHeight+e.getPropertyValue("marginTop")+e.getPropertyValue("marginBottom")}},Element.prototype.getParentArea=function(){let e=this.parentElement;for(;e;){if(e.classList.contains("lexarea"))return e;e=e.parentElement}},t.ICONS={Sidebar:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_iconCarrier"> <g id="Complete"> <g id="sidebar-left"> <g> <rect id="Square-2" data-name="Square" x="3" y="3" width="18" height="18" rx="2" ry="2" fill="none" stroke="currentColor" stroke-miterlimit="10" stroke-width="2"></rect> <line x1="9" y1="21" x2="9" y2="3" fill="none" stroke="currentColor" stroke-miterlimit="10" stroke-width="2"></line> </g> </g> </g> </g></svg>',More:'<svg fill="#000000" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_iconCarrier"> <g id="Complete"> <g id="F-More"> <path id="Vertical" d="M12,16a2,2,0,1,1-2,2A2,2,0,0,1,12,16ZM10,6a2,2,0,1,0,2-2A2,2,0,0,0,10,6Zm0,6a2,2,0,1,0,2-2A2,2,0,0,0,10,12Z"></path> </g> </g> </g></svg>',MoreHorizontal:'<svg fill="#000000" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_iconCarrier"> <g id="Complete"> <g id="F-More"> <path id="Horizontal" d="M8,12a2,2,0,1,1-2-2A2,2,0,0,1,8,12Zm10-2a2,2,0,1,0,2,2A2,2,0,0,0,18,10Zm-6,0a2,2,0,1,0,2,2A2,2,0,0,0,12,10Z"></path> </g> </g> </g></svg>',MenuArrows:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="#000000" transform="rotate(90)"><g id="SVGRepo_iconCarrier"> <g id="Complete"> <g id="Code"> <g> <polyline id="Right-2" data-name="Right" points="15.5 7 20.5 12 15.5 17" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"></polyline> <polyline id="Left-2" data-name="Left" points="8.5 7 3.5 12 8.5 17" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"></polyline> </g> </g> </g> </g></svg>',Plus:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="#000000"<g id="SVGRepo_iconCarrier"> <g id="Complete"> <g id="add-2" data-name="add"> <g> <line x1="12" y1="19" x2="12" y2="5" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"></line> <line x1="5" y1="12" x2="19" y2="12" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"></line> </g> </g> </g> </g></svg>',Down:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="#000000"><g id="SVGRepo_iconCarrier"> <title>i</title> <g id="Complete"> <g id="F-Chevron"> <polyline id="Down" points="5 8.5 12 15.5 19 8.5" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"></polyline> </g> </g> </g></svg>',Up:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="#000000"><g id="SVGRepo_iconCarrier"> <title>i</title> <g id="Complete"> <g id="F-Chevron"> <polyline id="Up" points="5 15.5 12 8.5 19 15.5" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"></polyline> </g> </g> </g></svg>',Right:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="#000000"><g id="SVGRepo_iconCarrier"> <title>i</title> <g id="Complete"> <g id="F-Chevron"> <polyline id="Right" points="8.5 5 15.5 12 8.5 19" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"></polyline> </g> </g> </g></svg>',Left:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="#000000"><g id="SVGRepo_iconCarrier"> <title>i</title> <g id="Complete"> <g id="F-Chevron"> <polyline id="Left" points="15.5 5 8.5 12 15.5 19" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"></polyline> </g> </g> </g></svg>'},t.UTILS={getTime:()=>new Date().getTime(),compareThreshold:(e,t,i,a)=>Math.abs(e-t)>=a||Math.abs(e-i)>=a,compareThresholdRange:(e,t,i,a)=>e>=i&&e<=a||t>=i&&t<=a||e<=i&&t>=a,uidGenerator:u,deleteElement(e){e&&e.remove()},flushCss(e){e.offsetHeight},getControlPoints(e,t,i,a,l,s,n){var r=Math.sqrt(Math.pow(i-e,2)+Math.pow(a-t,2)),o=n*r/(r+Math.sqrt(Math.pow(l-i,2)+Math.pow(s-a,2))),d=n-o;return[i+o*(e-l),a+o*(t-s),i-d*(e-l),a-d*(t-s)]},drawSpline(e,i,a){e.save();for(var l=[],s=i.length,n=0;n<s-4;n+=2)l=l.concat(t.UTILS.getControlPoints(i[n],i[n+1],i[n+2],i[n+3],i[n+4],i[n+5],a));for(var n=2;n<i.length-5;n+=2)e.beginPath(),e.moveTo(i[n],i[n+1]),e.bezierCurveTo(l[2*n-2],l[2*n-1],l[2*n],l[2*n+1],i[n+2],i[n+3]),e.stroke(),e.closePath();e.beginPath(),e.moveTo(i[0],i[1]),e.quadraticCurveTo(l[0],l[1],i[2],i[3]),e.stroke(),e.closePath(),e.beginPath(),e.moveTo(i[s-2],i[s-1]),e.quadraticCurveTo(l[2*s-10],l[2*s-9],i[s-4],i[s-3]),e.stroke(),e.closePath(),e.restore()}}}("undefined"!=typeof window?window:"undefined"!=typeof self?self:global);
1
+ "use strict";console.warn("Script _build/lexgui.js_ is depracated and will be removed soon. Please use ES Modules or alternatives: https://jxarco.github.io/lexgui.js/docs/"),function(){var w={version:"0.4.2",ready:!1,components:[],signals:{},extraCommandbarEntries:[],activeDraggable:null};function f(e,t,a){return Math.min(Math.max(e,t),a)}function E(e,t){return 0==t?Math.floor(e):+e.toFixed(t??2).replace(/([0-9]+(\.[0-9]+[1-9])?)(\.?0+$)/,"$1")}function p(e,t,a,n,s){return(e-t)*(s-n)/(a-t)+n}w.MOUSE_LEFT_CLICK=0,w.MOUSE_MIDDLE_CLICK=1,w.MOUSE_RIGHT_CLICK=2,w.MOUSE_DOUBLE_CLICK=2,w.MOUSE_TRIPLE_CLICK=3,w.CURVE_MOVEOUT_CLAMP=0,w.CURVE_MOVEOUT_DELETE=1,w.DRAGGABLE_Z_INDEX=101,w.clamp=f,w.round=E,w.remapRange=p,"undefined"!=typeof performance?w.getTime=performance.now.bind(performance):"undefined"!=typeof Date&&Date.now?w.getTime=Date.now.bind(Date):"undefined"!=typeof process?w.getTime=function(){var e=process.hrtime();return.001*e[0]+1e-6*e[1]}:w.getTime=function(){return(new Date).getTime()};function m(e,t){setTimeout(e,t??0)}function c(e){return e.replace(/\s/g,"").replaceAll("@","_").replaceAll("+","_plus_").replaceAll(".","")}function d(e){return e.includes(".")?e.split(".").pop():null}function g(e){return JSON.parse(JSON.stringify(e))}function h(e){return[parseInt(e.substring(1,3),16)/255,parseInt(e.substring(3,5),16)/255,parseInt(e.substring(5,7),16)/255]}function u(e){let t="#";for(var a of e)a=Math.floor(255*a),t+=a.toString(16);return t}function v(e,t=8){var a=document.createElement("span"),e=(a.className="lexinputmeasure",a.innerHTML=e,document.body.appendChild(a),a.getBoundingClientRect());return w.UTILS.deleteElement(a),e.width+t}function y(){function e(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return e()+"-"+e()+"-"+e()}function b(i,t={}){let l=0,o=0,n=null,a=t.targetClass,r=t.dragMargin??3,s=(e,t,a)=>{var n=i.parentElement?i.parentElement.getBoundingClientRect():{x:0,y:0,width:0,height:0},s="fixed"==i.style.position?new w.vec2(n.x,n.y):new w.vec2;a=a??e.clientX-l-n.x,t=t??e.clientY-o-n.y,i.style.left=f(a,r+s.x,s.x+n.width-i.offsetWidth-r)+"px",i.style.top=f(t,r+s.y,s.y+n.height-i.offsetHeight-r)+"px",i.style.translate="none"};t.autoAdjust&&s(null,parseInt(i.style.left),parseInt(i.style.top));var e=w.UTILS.uidGenerator();i["draggable-id"]=e;let d=t.onMove?e=>{n&&t.onMove&&t.onMove(n)}:e=>{n&&s(e)},c=t.onDragStart;i.setAttribute("draggable",!0),i.addEventListener("mousedown",function(e){n=e.target.classList.contains(a)||!a?e.target:null}),i.addEventListener("dragstart",function(e){var t,a;e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),n&&((t=new Image).src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=",e.dataTransfer.setDragImage(t,0,0),e.dataTransfer.effectAllowed="move",t=e.target.getBoundingClientRect(),a=n.parentElement.getBoundingClientRect(),a="fixed"==n.style.position?new w.vec2(a.x,a.y):new w.vec2,l=e.clientX-t.x-a.x,o=e.clientY-t.y-a.y,document.addEventListener("mousemove",d),n._eventCatched=!0,w.activeDraggable&&(w.activeDraggable.style.zIndex=w.DRAGGABLE_Z_INDEX),w.activeDraggable=i,w.activeDraggable.style.zIndex=w.DRAGGABLE_Z_INDEX+1,c)&&c(n,e)},!1),document.addEventListener("mouseup",e=>{n&&(n=null,document.removeEventListener("mousemove",d))})}w.doAsync=m,w.getSupportedDOMName=c,w.has=function(e){return-1<w.components.indexOf(e)},w.getExtension=d,w.deepCopy=g,w.setTheme=function(e){e="light"==e?"light":"dark",document.documentElement.setAttribute("data-theme",e),w.emit("@on_new_color_scheme",e)},w.setThemeColor=function(e,t){document.querySelector(":root").style.setProperty("--"+e,t)},w.getThemeColor=function(e){var t=getComputedStyle(document.querySelector(":root"));return(e=t.getPropertyValue("--"+e)).includes("light-dark")?("light"==t.getPropertyValue("color-scheme")?e.substring(e.indexOf("(")+1,e.indexOf(",")):e.substring(e.indexOf(",")+1,e.indexOf(")"))).replace(/\s/g,""):e},w.getBase64Image=function(e){var t=document.createElement("canvas");return t.width=e.width,t.height=e.height,t.getContext("2d").drawImage(e,0,0),t.toDataURL("image/png")},w.hexToRgb=h,w.rgbToHex=u,w.measureRealWidth=v,w.guidGenerator=y,w.buildTextPattern=function(e={}){var t=[],a=(e.lowercase&&t.push("(?=.*[a-z])"),e.uppercase&&t.push("(?=.*[A-Z])"),e.digit&&t.push("(?=.*\\d)"),e.specialChar&&t.push("(?=.*[@#$%^&+=!])"),e.noSpaces&&t.push("(?!.*\\s)"),e.minLength||0),n=e.maxLength||"",t=`^${t.join("")}.{${a},${n}}$`;return e.asRegExp?new RegExp(t):t},w.makeDraggable=b,w.makeCollapsible=function(e,t,a,n={}){e.classList.add("collapsible");var n=n.collapsed??!0,s=w.makeIcon("Right");s.classList.add("collapser"),s.dataset.collapsed=n,s.style.marginLeft="auto",s.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation(),this.dataset.collapsed?(delete this.dataset.collapsed,t.style.display="block"):(this.dataset.collapsed=!0,t.style.display="none")}),e.appendChild(s),(a=a??e.parentElement).appendChild(t)},w.makeCodeSnippet=function(t,e,a={}){if(w.has("CodeEditor")){var n,s,i,l=document.createElement("div"),e=(l.className="lexcodesnippet",l.style.width=e?e[0]:"auto",l.style.height=e?e[1]:"auto",new _({noAppend:!0})),o=new w.CodeEditor(e,{skipInfo:!0,disableEdition:!0,allowAddScripts:!1,name:a.tabName});if(o.setText(t,a.language??"Plain Text"),a.linesAdded){const t=o.root.querySelector(".code");for(var r of a.linesAdded)if(r.constructor==Number)t.childNodes[r-1].classList.add("added");else if(r.constructor==Array)for(let e=r[0]-1;e<=r[1]-1;e++)t.childNodes[e].classList.add("added")}if(a.linesRemoved){const t=o.root.querySelector(".code");for(var d of a.linesRemoved)if(d.constructor==Number)t.childNodes[d-1].classList.add("removed");else if(d.constructor==Array)for(let e=d[0]-1;e<=d[1]-1;e++)t.childNodes[e].classList.add("removed")}return a.windowMode&&((t=document.createElement("div")).className="lexwindowbuttons",(n=document.createElement("span")).style.background="#ee4f50",(s=document.createElement("span")).style.background="#f5b720",(i=document.createElement("span")).style.background="#53ca29",t.appendChild(n),t.appendChild(s),t.appendChild(i),o.root.querySelector(".lexareatabs").prepend(t)),(a.lineNumbers??!0)||o.root.classList.add("no-gutter"),l.appendChild(e.root),l}console.error("Import the CodeEditor component to create snippets!")},w.makeIcon=function(e,t,a=""){var n=document.createElement("a");return n.title=t??"",n.className="lexicon "+a,n.innerHTML=w.ICONS[e]??"",n},w.registerCommandbarEntry=function(e,t){w.extraCommandbarEntries.push({name:e,callback:t})};w.vec2=class r{constructor(e,t){this.x=e??0,this.y=t??e??0}get xy(){return[this.x,this.y]}get yx(){return[this.y,this.x]}set(e,t){this.x=e,this.y=t}add(e,t=new r){return t.set(this.x+e.x,this.y+e.y),t}sub(e,t=new r){return t.set(this.x-e.x,this.y-e.y),t}mul(e,t=new r){return e.constructor==Number&&(e=new r(e)),t.set(this.x*e.x,this.y*e.y),t}div(e,t=new r){return e.constructor==Number&&(e=new r(e)),t.set(this.x/e.x,this.y/e.y),t}abs(e=new r){return e.set(Math.abs(this.x),Math.abs(this.y)),e}dot(e){return this.x*e.x+this.y*e.y}len2(){return this.dot(this)}len(){return Math.sqrt(this.len2())}nrm(e=new r){return e.set(this.x,this.y),e.mul(1/this.len(),e)}dst(e){return e.sub(this).len()}clp(e,t,a=new r){return a.set(f(this.x,e,t),f(this.y,e,t)),a}},w.init=function(e={}){var t,a;return this.ready||((a=document.createElement("div")).id="lexroot",a.tabIndex=-1,(t=document.createElement("div")).id="modal",this.modal=t,this.root=a,this.container=document.body,this.modal.classList.add("hiddenOpacity"),this.modal.toggle=function(e){this.classList.toggle("hiddenOpacity",e)},e.container&&(this.container=document.getElementById(e.container)),this.usingStrictViewport=e.strictViewport??!0,document.documentElement.setAttribute("data-strictVP",this.usingStrictViewport?"true":"false"),this.usingStrictViewport||document.addEventListener("scroll",e=>{document.body.querySelectorAll(".lexmenubox").forEach(e=>{e._updatePosition()})}),this.commandbar=function(e){let l=document.createElement("dialog"),o=(l.className="commandbar",l.tabIndex=-1,e.appendChild(l),[]),r=null;l.addEventListener("keydown",function(e){var t,a;e.stopPropagation(),e.stopImmediatePropagation(),r=r??-1,"Escape"==e.key?(this.close(),h(!0)):"Enter"==e.key?(t=o[r])&&(a=t.item.type&&"checkbox"===t.item.type,this.close(),a?(t.item.checked=!t.item.checked,t.callback.call(window,t.item.checked,t.entry_name)):t.callback.call(window,t.entry_name)):"ArrowDown"==e.key&&r<o.length-1?(r++,l.querySelectorAll(".hovered").forEach(e=>e.classList.remove("hovered")),o[r].classList.add("hovered"),0<(a=o[r].offsetHeight*(r+1)-d.offsetHeight)&&d.scrollTo({top:a,behavior:"smooth"})):"ArrowUp"==e.key&&0<r&&(r--,l.querySelectorAll(".hovered").forEach(e=>e.classList.remove("hovered")),o[r].classList.add("hovered"))}),l.addEventListener("focusout",function(e){e.relatedTarget!=e.currentTarget&&(e.stopPropagation(),e.stopImmediatePropagation(),this.close(),h(!0))}),e.addEventListener("keydown",e=>{if(" "==e.key&&e.ctrlKey)e.stopImmediatePropagation(),e.stopPropagation(),w.setCommandbarState(!0);else for(var t of w.components){var a;if(w[t]&&w[t].prototype.onKeyPressed)for(a of w.CodeEditor.getInstances())a.onKeyPressed(e)}});(e=document.createElement("div")).className="gs-header";var t=document.createElement("a");t.className="fa-solid fa-magnifying-glass",e.appendChild(t);const a=document.createElement("input");a.placeholder="Search...",a.value="",e.appendChild(a);var n=(t=new _({width:"100%",skipAppend:!0,className:"gs-tabs"})).addTabs();let s;n.add("All",document.createElement("div"),{selected:!0,onSelect:(e,t)=>{s=t}});const d=document.createElement("div");d.className="searchitembox";let c=null;const h=e=>{d.innerHTML="",o.length=0,r=null,e&&(a.value="")},u=(e,t,a,n)=>{var s,i;e.length&&(c&&c.classList.remove("last"),(s=document.createElement("div")).className="searchitem last",i=n&&n.type&&"checkbox"===n.type,s.innerHTML=i?"<a class='fa fa-check'></a><span>"+(a+e)+"</span>":a+e,s.entry_name=e,s.callback=t,s.item=n,s.addEventListener("click",function(e){this.callback.call(window,this.entry_name),w.setCommandbarState(!1),h(!0)}),s.addEventListener("mouseenter",function(e){l.querySelectorAll(".hovered").forEach(e=>e.classList.remove("hovered")),this.classList.add("hovered"),r=o.indexOf(this)}),s.addEventListener("mouseleave",function(e){this.classList.remove("hovered")}),o.push(s),d.appendChild(s),c=s)},p=(e,t,a)=>{var n=Object.keys(e)[0],s=e.name??a+n;if(s.toLowerCase().includes(t)&&e.callback&&u(e.name??n,e.callback,a,e),!e.name){a+=n+" > ";for(var i of e[n])p(i,t,a)}};return l._addElements=e=>{h();for(var t of w.menubars)for(var a of t.items)p(a,e,"");for(var n of w.extraCommandbarEntries){var s=n.name;s.toLowerCase().includes(e)&&u(s,n.callback,"",{})}if(w.has("CodeEditor")){const r=w.CodeEditor.getInstances();if(r.length){var i=r[0].languages;for(let t of Object.keys(i)){var l="Language: "+t,o=r[0]._getFileIcon(null,i[t].ext),o=o.includes("fa-")?"<i class='"+o+"'></i>":"<img src='https://raw.githubusercontent.com/jxarco/lexgui.js/master/"+o+"'>";o+=l+" <span class='lang-ext'>("+i[t].ext+")</span>",l.toLowerCase().includes(e)&&u(o,()=>{for(var e of r)e._changeLanguage(t)},"",{})}}}},a.addEventListener("input",function(e){l._addElements(this.value.toLowerCase())}),l.appendChild(e),l.appendChild(t.root),l.appendChild(d),l}(this.container),this.container.appendChild(t),e.skipRoot?this.root=document.body:this.container.appendChild(a),(t=document.createElement("section")).className="notifications",this.notifications=document.createElement("ol"),this.notifications.className="",this.notifications.iWidth=0,t.appendChild(this.notifications),this.container.appendChild(t),this.notifications.addEventListener("mouseenter",()=>{this.notifications.classList.add("list")}),this.notifications.addEventListener("mouseleave",()=>{this.notifications.classList.remove("list")}),a.addEventListener("dragover",function(e){e.preventDefault()},!1),document.addEventListener("contextmenu",function(e){e.preventDefault()},!1),t=document.getElementsByTagName("HEAD")[0],(a=document.createElement("link")).rel="stylesheet",a.type="text/css",a.crossOrigin="anonymous",a.href="https://use.fontawesome.com/releases/v6.7.2/css/all.css",t.appendChild(a),this.DEFAULT_NAME_WIDTH="30%",this.DEFAULT_SPLITBAR_SIZE=4,this.OPEN_CONTEXTMENU_ENTRY="click",this.ready=!0,this.menubars=[],e.skipRoot||e.skipDefaultArea||(this.main_area=new _({id:e.id??"mainarea"})),(e.autoTheme??!0)&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: light)").matches&&(w.setTheme("light"),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",e=>{w.setTheme(e.matches?"dark":"light")}))),this.main_area},w.setCommandbarState=function(e,t=!0){var a=this.commandbar;e?(a.show(),a.querySelector("input").focus(),t&&a._addElements(void 0)):a.close()},w.message=function(t,e,a={}){if(t)return a.modal=!0,new S(e,e=>{e.addTextArea(null,t,null,{disabled:!0,fitHeight:!0})},a);throw"No message to show"},w.popup=function(t,e,a={}){if(!t)throw"No message to show";a.size=a.size??["max-content","auto"],a.class="lexpopup";var n=a.timeout||3e3;const s=new S(e,e=>{e.addTextArea(null,t,null,{disabled:!0,fitHeight:!0})},a);return setTimeout(()=>{s.close()},Math.max(n,150)),s},w.prompt=function t(a,n,s,i={}){i.modal=!0,i.className="prompt";let l="";const o=new S(n,e=>{e.addTextArea(null,a,null,{disabled:!0,fitHeight:!0}),(i.input??!0)&&e.addText(null,i.input||l,e=>l=e,{placeholder:"..."}),e.sameLine(2),e.addButton(null,"Cancel",()=>{i.on_cancel&&i.on_cancel(),o.close()}),e.addButton(null,i.accept||"Continue",()=>{i.required&&""===l?(a+=a.includes("You must fill the input text.")?"":"\nYou must fill the input text.",o.close(),t(a,n,s,i)):(s&&s.call(this,l),o.close())},{buttonClass:"primary"})},i);return(i.input??!0)&&o.root.querySelector("input").focus(),o},w.toast=function(e,t,a={}){if(!e)throw"The toast needs at least a title!";console.assert(this.notifications);const n=document.createElement("li");n.className="lextoast",n.style.translate="0 calc(100% + 30px)",this.notifications.prepend(n),m(()=>{this.notifications.offsetWidth>this.notifications.iWidth&&(this.notifications.iWidth=Math.min(this.notifications.offsetWidth,480),this.notifications.style.width=this.notifications.iWidth+"px"),n.dataset.open=!0},10);var s=document.createElement("div"),i=(s.className="lextoastcontent",n.appendChild(s),document.createElement("div"));i.className="title",i.innerHTML=e,s.appendChild(i),t&&((e=document.createElement("div")).className="desc",e.innerHTML=t,s.appendChild(e)),a.action&&((i=new k).addButton(null,a.action.name??"Accept",a.action.callback.bind(this,n),{width:"auto",maxWidth:"150px",className:"right",buttonClass:"outline"}),n.appendChild(i.root.childNodes[0]));const l=this;n.close=function(){this.dataset.closed=!0,m(()=>{this.remove(),l.notifications.childElementCount||(l.notifications.style.width="unset",l.notifications.iWidth=0)},500)},(a.closable??!0)&&((t=document.createElement("a")).className="fa fa-xmark lexicon closer",t.addEventListener("click",()=>{n.close()}),n.appendChild(t)),-1!=(s=a.timeout??3e3)&&m(()=>{n.close()},s)},w.badge=function(e,t,a={}){var n=document.createElement("div");return n.innerHTML=e,n.className="lexbadge "+(t??""),Object.assign(n.style,a.style??{}),n.outerHTML},w.makeContainer=function(e,t,a={}){var n=document.createElement("div");return n.className="lexcontainer "+(t??""),n.style.width=e&&e[0]?e[0]:"100%",n.style.height=e&&e[1]?e[1]:"100%",Object.assign(n.style,a),n};class x{constructor(e,t,a){this.name=e,this.value=t,this.domEvent=a}}w.IEvent=x;class L{static NONE=0;static NODE_SELECTED=1;static NODE_DELETED=2;static NODE_DBLCLICKED=3;static NODE_CONTEXTMENU=4;static NODE_DRAGGED=5;static NODE_RENAMED=6;static NODE_VISIBILITY=7;static NODE_CARETCHANGED=8;constructor(e,t,a){this.type=e||L.NONE,this.node=t,this.value=a,this.multiple=!1,this.panel=null}string(){switch(this.type){case L.NONE:return"tree_event_none";case L.NODE_SELECTED:return"tree_event_selected";case L.NODE_DELETED:return"tree_event_deleted";case L.NODE_DBLCLICKED:return"tree_event_dblclick";case L.NODE_CONTEXTMENU:return"tree_event_contextmenu";case L.NODE_DRAGGED:return"tree_event_dragged";case L.NODE_RENAMED:return"tree_event_renamed";case L.NODE_VISIBILITY:return"tree_event_visibility";case L.NODE_CARETCHANGED:return"tree_event_caretchanged"}}}w.TreeEvent=L,w.emit=function(e,t,a={}){var n=w.signals[e];if(n){var s=a.target;if(s)s[e]&&s[e].call(s,t);else for(var i of n)i.constructor===T?(i.set(t,a.skipCallback??!0),i.options&&i.options.callback&&i.options.callback(t,n)):i(null,t)}},w.addSignal=function(e,t,a){t[e]=a,w.signals[e]||(w.signals[e]=[]),-1<w.signals[e].indexOf(t)||w.signals[e].push(t)};class _{constructor(e={}){var n,s,t=document.createElement("div"),a=(t.className="lexarea",e.id&&(t.id=e.id),e.className&&(t.className+=" "+e.className),e.width||"calc( 100% )"),i=e.height||"100%",a=(this.setLimitBox(e.minWidth,e.minHeight,e.maxWidth,e.maxHeight),a.constructor==Number&&(a+="px"),i.constructor==Number&&(i+="px"),t.style.width=a,t.style.height=i,this.offset=0,this.root=t,this.size=[this.root.offsetWidth,this.root.offsetHeight],this.sections=[],this.panels=[],e.skipAppend||document.getElementById("lexroot").appendChild(this.root),e.overlay);function l(e){switch(n.type){case"right":var t=s[0]-e.x,a=n.root.offsetWidth+t;n.root.style.width=a+"px";break;case"left":t=s[0]-e.x,a=Math.min(document.body.clientWidth-w.DEFAULT_SPLITBAR_SIZE,n.root.offsetWidth-t);n.root.style.width=a+"px",n.splitBar.style.left=a+w.DEFAULT_SPLITBAR_SIZE/2+"px";break;case"top":t=s[1]-e.y,a=Math.min(document.body.clientHeight-w.DEFAULT_SPLITBAR_SIZE,n.root.offsetHeight-t);n.root.style.height=a+"px",n.splitBar.style.top=a+w.DEFAULT_SPLITBAR_SIZE/2+"px";break;case"bottom":t=s[1]-e.y,a=n.root.offsetHeight+t;n.root.style.height=a+"px"}s[0]=e.x,s[1]=e.y,e.stopPropagation(),e.preventDefault(),n.onresize&&n.onresize(n.root.getBoundingClientRect())}function o(e){var t=n.root.ownerDocument;t.removeEventListener("mousemove",l),t.removeEventListener("mouseup",o),document.body.classList.remove("nocursor"),n.splitBar.classList.remove("nocursor")}a&&(this.root.classList.add("overlay-"+a),e.left?this.root.style.left=e.left:e.right?this.root.style.right=e.right:e.top?this.root.style.top=e.top:e.bottom&&(this.root.style.bottom=e.bottom),(e.draggable??!0)&&b(t,e),e.resizeable&&t.classList.add("resizeable"),e.resize)&&(this.splitBar=document.createElement("div"),i="left"==a||"right"==a?"horizontal":"vertical",this.type=a,this.splitBar.className="lexsplitbar "+i,"right"==a?(this.splitBar.style.width=w.DEFAULT_SPLITBAR_SIZE+"px",this.splitBar.style.left=-w.DEFAULT_SPLITBAR_SIZE/2+"px"):"left"==a?(t=Math.min(document.body.clientWidth-w.DEFAULT_SPLITBAR_SIZE,this.root.clientWidth),this.splitBar.style.width=w.DEFAULT_SPLITBAR_SIZE+"px",this.splitBar.style.left=t+w.DEFAULT_SPLITBAR_SIZE/2+"px"):"top"==a?(e=Math.min(document.body.clientHeight-w.DEFAULT_SPLITBAR_SIZE,this.root.clientHeight),this.splitBar.style.height=w.DEFAULT_SPLITBAR_SIZE+"px",this.splitBar.style.top=e+w.DEFAULT_SPLITBAR_SIZE/2+"px"):"bottom"==a&&(this.splitBar.style.height=w.DEFAULT_SPLITBAR_SIZE+"px",this.splitBar.style.top=-w.DEFAULT_SPLITBAR_SIZE/2+"px"),this.splitBar.addEventListener("mousedown",function(e){var t=n.root.ownerDocument;t.addEventListener("mousemove",l),t.addEventListener("mouseup",o),s[0]=e.x,s[1]=e.y,e.stopPropagation(),e.preventDefault(),document.body.classList.add("nocursor"),n.splitBar.classList.add("nocursor")}),this.root.appendChild(this.splitBar),n=this,s=[0,0])}attach(e){if(this.sections.length)this.sections[1].attach(e);else{if(!e)throw"no content to attach";(e.parent=this).root.appendChild(e.root||e)}}split(t={}){this.sections.length&&(this.offset=this.root.childNodes[0].offsetHeight,this._root=this.sections[0].root,this.root=this.sections[1].root);var a=t.type||"horizontal",n=t.sizes||["50%","50%"],e="auto"===t.sizes;if(!n[1]){let e=n[0];var s=t.top||0;e.constructor==Number&&(e=e+s+"px"),n[1]="calc( 100% - "+e+" )"}var i,l,s=new _({skipAppend:!0,className:"split"+(t.menubar||t.sidebar?"":" origin")}),o=new _({skipAppend:!0,className:"split"}),r=(s.parentArea=this,o.parentArea=this,t.minimizable??!1),t=(t.resize??!0)||r,d="0px";return this.offset=0,t&&(this.resize=t,this.splitBar=document.createElement("div"),this.splitBar.className="lexsplitbar "+a,"horizontal"==a?this.splitBar.style.width=w.DEFAULT_SPLITBAR_SIZE+"px":this.splitBar.style.height=w.DEFAULT_SPLITBAR_SIZE+"px",this.splitBar.addEventListener("mousedown",function(e){var t=l.root.ownerDocument;t.addEventListener("mousemove",c),t.addEventListener("mouseup",h),e.stopPropagation(),e.preventDefault(),document.body.classList.add("nocursor"),l.splitBar.classList.add("nocursor")}),d=w.DEFAULT_SPLITBAR_SIZE/2+"px",r)&&(this.splitExtended=!1,o.root.addEventListener("animationend",e=>{var t=getComputedStyle(o.root).opacity;o.root.classList.remove(e.animationName+"-"+a),o.root.style.opacity=t,C(o.root)}),this.splitBar.addEventListener("contextmenu",e=>{e.preventDefault(),A(null,e,e=>{e.add("Extend",{disabled:this.splitExtended,callback:()=>{this.extend()}}),e.add("Reduce",{disabled:!this.splitExtended,callback:()=>{this.reduce()}})})})),"horizontal"==a?(r=n[0],i=n[1],r.constructor==Number&&(r+="px"),i.constructor==Number&&(i+="px"),s.root.style.width="calc( "+r+" - "+d+" )",s.root.style.height="calc(100% - 0px)",o.root.style.width="calc( "+i+" - "+d+" )",o.root.style.height="calc(100% - 0px)",this.root.style.display="flex"):(s.root.style.width="100%",o.root.style.width="100%",e?(s.root.style.height="auto",new ResizeObserver(e=>{for(const a of e){var t=a.contentRect;o.root.style.height="calc(100% - "+(t.height+4)+"px )"}}).observe(s.root)):(r=n[0],i=n[1],r.constructor==Number&&(r+="px"),i.constructor==Number&&(i+="px"),s.root.style.width="100%",s.root.style.height="auto"==r?r:"calc( "+r+" - "+d+" )",o.root.style.height="auto"==i?i:"calc( "+i+" - "+d+" )")),this.root.appendChild(s.root),t&&this.root.appendChild(this.splitBar),this.root.appendChild(o.root),this.sections=[s,o],this.type=a,this._update(),t&&(l=this),this.sections;function c(e){var t;"horizontal"==l.type?l._moveSplit(-e.movementX):l._moveSplit(-e.movementY);for(t of l.root.querySelectorAll(".lexwidget")){var a=t.jsInstance;a.onresize&&a.onresize()}e.stopPropagation(),e.preventDefault()}function h(e){var t=l.root.ownerDocument;t.removeEventListener("mousemove",c),t.removeEventListener("mouseup",h),document.body.classList.remove("nocursor"),l.splitBar.classList.remove("nocursor")}}setLimitBox(e=0,t=0,a=1/0,n=1/0){this.minWidth=e,this.minHeight=t,this.maxWidth=a,this.maxHeight=n}setSize(e){let[t,a]=e;null!=t&&t.constructor==Number&&(t+="px"),null!=a&&a.constructor==Number&&(a+="px"),t&&(this.root.style.width=t),a&&(this.root.style.height=a),this.onresize&&this.onresize(this.root.getBoundingClientRect()),m(()=>{this.size=[this.root.clientWidth,this.root.clientHeight],this.propagateEvent("onresize")},150)}extend(){var e,t;this.splitExtended||([e,t]=this.sections,this.splitExtended=!0,"vertical"==this.type?(this.offset=t.root.offsetHeight,t.root.classList.add("fadeout-vertical"),this._moveSplit(-1/0,!0)):(this.offset=t.root.offsetWidth-8,t.root.classList.add("fadeout-horizontal"),this._moveSplit(-1/0,!0,8)),m(()=>this.propagateEvent("onresize"),150))}reduce(){var e,t;this.splitExtended&&(this.splitExtended=!1,[e,t]=this.sections,"vertical"==this.type?t.root.classList.add("fadein-vertical"):t.root.classList.add("fadein-horizontal"),this._moveSplit(this.offset),m(()=>this.propagateEvent("onresize"),150))}hide(){this.root.classList.add("hidden")}show(){this.root.classList.remove("hidden")}toggle(e){this.root.classList.toggle("hidden",e)}propagateEvent(e){for(var t=0;t<this.sections.length;t++){var a=this.sections[t];a[e]&&a[e].call(this,a.root.getBoundingClientRect()),a.propagateEvent(e)}}addPanel(e){e=new k(e);return this.attach(e),this.panels.push(e),e}addMenubar(e,t={}){var a=new s(t),[e,n]=(e&&e(a),w.menubars.push(a),this.split({type:"vertical",sizes:[48,null],resize:!1,menubar:!0}));return a.siblingArea=n,e.attach(a),e.isMenubar=!0,(t.sticky??!0)&&e.root.classList.add("sticky"),a}addSidebar(e,t={}){var a=new n(t),e=(e&&e(a),a.update(),w.menubars.push(a),t.width??"16rem"),[t,e]=this.split({type:"horizontal",sizes:[e,null],resize:!1,sidebar:!0});return a.siblingArea=e,t.attach(a),t.isSidebar=!0,a}addOverlayButtons(e,t={}){if(this.sections.length)this.sections[1].addOverlayButtons(e,t);else{console.assert(e.constructor==Array&&e.length),this.root.style.position="relative",t.className="lexoverlaybuttons";let i=this.addPanel(t),l=null;const s=document.createElement("div"),o=(s.className="lexoverlaybuttonscontainer",s.appendChild(i.root),this.attach(s),t.float);if(o)for(var a=0;a<o.length;a++)switch(o[a]){case"h":break;case"v":s.className+=" vertical";break;case"t":break;case"m":s.className+=" middle";break;case"b":s.className+=" bottom";break;case"l":break;case"c":s.className+=" center";break;case"r":s.className+=" right"}const r=function(n,e,t){var a={width:"auto",selectable:n.selectable,selected:n.selected,icon:n.icon,img:n.img,className:n.class};e&&(l||((l=document.createElement("div")).className="lexoverlaygroup",i.queuedContainer=l),a.parent=l);let s=n.callback;n.options?i.addDropdown(null,n.options,n.name,s,a):i.addButton(null,n.name,function(e,t){var a;n.selectable&&(n.group?(a=n.selected,n.group.forEach(e=>e.selected=!1),n.selected=!a):n.selected=!n.selected),s(e,t)},a),l&&t&&(i.root.appendChild(l),l=null,i.clearQueue())};!function(){i.clear();for(var t of e)if(t.constructor===Array)for(let e=0;e<t.length;++e){var a=t[e];a.group=t,r(a,!0,e==t.length-1)}else r(t);var n;o&&(n=0,i.root.childNodes.forEach(e=>{n+=e.offsetHeight}),s.className.includes("middle"))&&(s.style.top="-moz-calc( 50% - "+.5*n+"px )",s.style.top="-webkit-calc( 50% - "+.5*n+"px )",s.style.top="calc( 50% - "+.5*n+"px )")}()}}addTabs(e={}){var t=new l(this,e);return e.folding&&(this.parentArea._disableSplitResize(),this.root.style.paddingTop="4px"),t}_moveSplit(t,a=!1,n=0){if(!this.type)throw"No split area";if(void 0!==t){var s,i=this.sections[0],l=i.root,o=(l.classList.contains("origin")||(l=l.parentElement),this.sections[1]),r=o.root,d=" - "+w.DEFAULT_SPLITBAR_SIZE+"px";let e=null;a||(e=l.style.transition,l.style.transition=r.style.transition="none",C(l),C(r)),"horizontal"==this.type?(s=Math.max(r.offsetWidth+t,parseInt(o.minWidth)),l.style.width="-moz-calc( 100% - "+(s=n?n:s)+"px "+d+" )",l.style.width="-webkit-calc( 100% - "+s+"px "+d+" )",l.style.width="calc( 100% - "+s+"px "+d+" )",l.style.minWidth=parseInt(i.minWidth)+"px",r.style.width=s+"px",i.maxWidth!=1/0&&(r.style.minWidth="calc( 100% - "+parseInt(i.maxWidth)+"px )")):(s=Math.max(r.offsetHeight+t+o.offset,parseInt(o.minHeight)),l.style.height="-moz-calc( 100% - "+(s=n?n:s)+"px "+d+" )",l.style.height="-webkit-calc( 100% - "+s+"px "+d+" )",l.style.height="calc( 100% - "+s+"px "+d+" )",l.style.minHeight=i.minHeight+"px",r.style.height=s-o.offset+"px"),a||(l.style.transition=r.style.transition=e),this._update(),this.propagateEvent("onresize")}}_disableSplitResize(){this.resize=!1,this.splitBar.remove(),delete this.splitBar}_update(){var e=this.root.getBoundingClientRect();this.size=[e.width,e.height];for(var t=0;t<this.sections.length;t++)this.sections[t]._update()}}function C(e){e.offsetHeight}w.Area=_;class l{static TAB_SIZE=28;static TAB_ID=0;constructor(n,e={}){this.onclose=e.onclose;var t=document.createElement("div"),a=(t.className="lexareatabs "+(e.fit?"fit":"row"),e.folding??!1);a&&t.classList.add("folding");let s=this;t.addEventListener("dragenter",function(e){e.preventDefault(),this.classList.add("dockingtab")}),t.addEventListener("dragleave",function(e){e.preventDefault(),this.classList.remove("dockingtab")}),t.addEventListener("drop",function(e){e.preventDefault();var e=e.dataTransfer.getData("source"),t=document.getElementById(e);t&&(this.appendChild(t),e=document.getElementById(e+"_content"),s.area.attach(e),this.classList.remove("dockingtab"),w.emit("@on_tab_docked"),t.instance=s,t.click(),s.tabs[t.dataset.name]=e)}),n.root.classList.add("lexareatabscontainer"),n.split({type:"vertical",sizes:e.sizes??"auto",resize:!1,top:6}),n.sections[0].attach(t),this.area=n.sections[1],this.area.root.className+=" lexareatabscontent",this.selected=null,this.root=t,this.tabs={},this.tabDOMs={},e.fit&&((t=document.createElement("span")).className="lexareatab thumb",this.thumb=t,this.root.appendChild(t),new ResizeObserver(e=>{var t,a=this.thumb.item;a&&(t=this.thumb.style.transition,this.thumb.style.transition="none",this.thumb.style.transform="translate( "+a.childIndex*a.offsetWidth+"px )",this.thumb.style.width=a.offsetWidth-5+"px",this.thumb.style.height=a.offsetHeight-6+"px",C(this.thumb),this.thumb.style.transition=t)}).observe(this.area.root)),a&&(this.folded=!0,"up"==(this.folding=a)&&n.root.insertChildAtIndex(n.sections[1].root,0),new ResizeObserver(e=>{for(const a of e){var t=a.contentRect;n.parentArea.sections[0].root.style.height="calc(100% - "+(42+t.height)+"px )"}}).observe(this.area.root),this.area.root.classList.add("folded"))}add(e,t,a={}){let n=a.selected??!1,s=(n&&(this.root.querySelectorAll("span").forEach(e=>e.classList.remove("selected")),this.area.root.querySelectorAll(".lextabcontent").forEach(e=>e.style.display="none")),n=!Object.keys(this.tabs).length&&!this.folding||n,t.root||t);s.originalDisplay=s.style.display,s.style.display=n?s.originalDisplay:"none",s.classList.add("lextabcontent"),a.icon&&(a.icon.includes("fa-")?a.icon="<i class='"+a.icon+"'></i>":a.icon="<img src='https://raw.githubusercontent.com/jxarco/lexgui.js/master/"+a.icon+"'>");let i=document.createElement("span");i.dataset.name=e,i.className="lexareatab"+(n?" selected":""),i.innerHTML=(a.icon??"")+e,i.id=e.replace(/\s/g,"")+l.TAB_ID++,i.title=a.title??"",i.selected=n??!1,i.fixed=a.fixed,i.instance=this,s.id=i.id+"_content",i.selected&&(this.selected=e),w.addSignal("@on_tab_docked",i,function(){1==this.parentElement.childNodes.length&&this.parentElement.childNodes[0].click()}),i.addEventListener("click",e=>{var t;e.preventDefault(),e.stopPropagation(),i.fixed||(t=i.selected,i.parentElement.querySelectorAll("span").forEach(e=>e.selected=!1),i.selected=!t,i.parentElement.querySelectorAll("span").forEach(e=>e.classList.remove("selected")),i.classList.toggle("selected",this.folding&&i.selected),i.instance.area.root.querySelectorAll(".lextabcontent").forEach(e=>e.style.display="none"),s.style.display=s.originalDisplay,i.instance.selected=i.dataset.name),this.folding&&(this.folded=i.selected,this.area.root.classList.toggle("folded",!this.folded)),a.onSelect&&a.onSelect(e,i.dataset.name),this.thumb&&(this.thumb.style.transform="translate( "+i.childIndex*i.offsetWidth+"px )",this.thumb.style.width=i.offsetWidth-5+"px",this.thumb.style.height=i.offsetHeight-6+"px",this.thumb.item=i)}),i.addEventListener("contextmenu",e=>{e.preventDefault(),e.stopPropagation(),a.onContextMenu&&a.onContextMenu(e,i.dataset.name)}),i.addEventListener("mouseup",e=>{e.preventDefault(),e.stopPropagation(),1==e.button&&this.delete(i.dataset.name)}),i.setAttribute("draggable",!0),i.addEventListener("dragstart",function(e){1==this.parentElement.childNodes.length?e.preventDefault():e.dataTransfer.setData("source",e.target.id)}),i.childIndex=this.root.childElementCount-1,this.root.appendChild(i),this.area.attach(s),this.tabDOMs[e]=i,this.tabs[e]=t,setTimeout(()=>{a.onCreate&&a.onCreate.call(this,this.area.root.getBoundingClientRect()),n&&this.thumb&&(this.thumb.style.transform="translate( "+i.childIndex*i.offsetWidth+"px )",this.thumb.style.width=i.offsetWidth-5+"px",this.thumb.style.height=i.offsetHeight-6+"px",this.thumb.item=i)},10)}select(e){this.tabDOMs[e]&&this.tabDOMs[e].click()}delete(e){var t=this.tabDOMs[e];t&&!t.fixed&&(this.onclose&&this.onclose(e),this.tabDOMs[e].remove(),delete this.tabDOMs[e],this.tabs[e].remove(),delete this.tabs[e],t=this.root.lastChild)&&!t.fixed&&this.root.lastChild.click()}}w.Tabs=l;class s{constructor(e={}){this.root=document.createElement("div"),this.root.className="lexmenubar",e.float&&(this.root.style.justifyContent=e.float),this.items=[],this.buttons=[],this.icons={},this.shorts={}}_resetMenubar(){this.root.querySelectorAll(".lexmenuentry").forEach(e=>{e.classList.remove("selected"),e.built=!1}),w.root.querySelectorAll(".lexmenubox").forEach(e=>e.remove()),this.focused=!1}_createSubmenu(e,t,a,s){let i=document.createElement("div");i.className="lexmenubox",i.tabIndex="0";const n=((a.currentMenu=i).parentEntry=a).classList.contains("lexmenuboxentry");n&&(i.dataset.submenu=!0),i._updatePosition=()=>{const t=i.style.transition;i.style.transition="none",C(i),m(()=>{var e=a.getBoundingClientRect();e.x+=document.scrollingElement.scrollLeft,e.y+=document.scrollingElement.scrollTop,i.style.left=(n?e.x+e.width:e.x)+"px",i.style.top=(n?e.y:e.y+e.height-4)+"px",i.style.transition=t})},i._updatePosition(),m(()=>{i.dataset.open=!0},10),w.root.appendChild(i);for(var l=0;l<e[t].length;++l){const h=e[t][l],u=Object.keys(h)[0];var o,r,d=h[u].length,c="checkbox"==h.type;let a=document.createElement("div"),n=(a.className="lexmenuboxentry",a.className+=(l==e[t].length-1?" last":"")+(h.disabled?" disabled":""),""==u?a.className=" lexseparator":(a.id=u,(o=document.createElement("div")).innerHTML="",o.classList="lexmenuboxentrycontainer",a.appendChild(o),r=this.icons[u],c?o.innerHTML+="<input type='checkbox' >":r?o.innerHTML+="<a class='"+r+" fa-sm'></a>":(o.innerHTML+="<a class='fa-solid fa-sm noicon'></a>",o.classList.add("noicon")),o.innerHTML+="<div class='lexentryname'>"+u+"</div>"),a.querySelector("input"));n&&(n.checked=h.checked??!1,n.addEventListener("change",e=>{h.checked=n.checked;var t=h.callback;t&&(t.call(this,h.checked,u,a),this._resetMenubar()),e.stopPropagation(),e.stopImmediatePropagation()})),i.appendChild(a),""!=u&&(i.addEventListener("keydown",e=>{e.preventDefault();let t=this.shorts[u];t&&(t=1==t.length?t.toLowerCase():t)==e.key&&a.click()}),a.addEventListener("click",e=>{n&&(h.checked=!h.checked);var t=h.callback;t&&(t.call(this,n?h.checked:u,n?u:a),this._resetMenubar()),e.stopPropagation(),e.stopImmediatePropagation()}),d?((c=document.createElement("a")).className="fa-solid fa-angle-right fa-xs",a.appendChild(c),a.addEventListener("mouseover",e=>{a.built||(a.built=!0,this._createSubmenu(h,u,a,++s),e.stopPropagation())}),a.addEventListener("mouseleave",e=>{a.currentMenu&&a.currentMenu!=e.toElement&&(s=-1,delete a.built,a.currentMenu.remove(),delete a.currentMenu)})):this.shorts[u]&&((r=document.createElement("div")).className="lexentryshort",r.innerText=this.shorts[u],a.appendChild(r)))}i.style.width=i.offsetWidth+"px"}add(e,i={}){i.constructor==Function&&(i={callback:i});const l=e.split("/");e=l[l.length-1];this.icons[e]=i.icon,this.shorts[e]=i.short;let o=0;const r=(n,e)=>{if(null!=n){let a=null;var t,s;e.forEach(e=>{var t=Object.keys(e).find(e=>e==n);t&&(a=e[t])}),a?r(l[o++],a):((t={})[n]=[],(s=l[o++])||(t.callback=i.callback,t.disabled=i.disabled,t.type=i.type,t.checked=i.checked),e.push(t),r(s,t[n]))}};r(l[o++],this.items);for(let n of this.items){let a=Object.keys(n)[0];var s=a.replace(/\s/g,"").replaceAll(".","");if(!this.root.querySelector("#"+s)){let t=document.createElement("div");t.className="lexmenuentry",t.id=s,t.innerHTML="<span>"+a+"</span>",t.tabIndex="1","left"==i.position?this.root.prepend(t):("right"==i.position&&(t.right=!0),this.root.lastChild&&this.root.lastChild.right?this.root.lastChild.before(t):this.root.appendChild(t));const d=()=>{this._resetMenubar(),t.classList.add("selected"),t.built=!0,this._createSubmenu(n,a,t,-1)};t.addEventListener("click",()=>{var e=n.callback;e?e.call(this,a,t):(d(),this.focused=!0)}),t.addEventListener("mouseover",e=>{this.focused&&!t.built&&d()}),t.addEventListener("blur",e=>{e.relatedTarget&&e.relatedTarget.classList.contains("lexmenubox")||this._resetMenubar()})}}}getButton(e){return this.buttons[e]}getSubitem(t,a){var n=a[0];for(let e=0;e<t.length;e++)if(t[e][n])return 1==a.length?t[e]:(a.splice(0,1),this.getSubitem(t[e][n],a))}getItem(e){e=e.split("/");return this.getSubitem(this.items,e)}setButtonIcon(e,t,a,n={}){if(!e)throw"Set Button Name!";let s=this.buttons[e];if(s)s.querySelector("a").className="fa-solid "+t+" lexicon";else{s=document.createElement("div");const i=n.disabled??!1,l=(s.className="lexmenubutton main"+(i?" disabled":""),s.title=e,s.innerHTML="<a class='"+t+" lexicon'></a>","right"==n.float&&(s.right=!0),this.root.lastChild&&this.root.lastChild.right?this.root.lastChild.before(s):"left"==n.float?this.root.prepend(s):this.root.appendChild(s),s.querySelector("a"));l.addEventListener("click",e=>{a&&!i&&a.call(this,l,e)}),this.buttons[e]=s}}setButtonImage(e,t,a,n={}){if(!e)throw"Set Button Name!";let s=this.buttons[e];if(s)s.querySelector("img").src=t;else{s=document.createElement("div");const i=n.disabled??!1,l=(s.className="lexmenubutton"+(i?" disabled":""),s.title=e,s.innerHTML="<a><image src='"+t+"' class='lexicon' style='height:32px;'></a>","right"==n.float&&(s.right=!0),this.root.lastChild&&this.root.lastChild.right?this.root.lastChild.before(s):"left"==n.float?this.root.prepend(s):this.root.appendChild(s),s.querySelector("a"));l.addEventListener("click",e=>{a&&!i&&a.call(this,l,e)}),this.buttons[e]=s}}addButtons(i,e={}){if(!i)throw"No buttons to add!";this.buttonContainer||(this.buttonContainer=document.createElement("div"),this.buttonContainer.className="lexmenubuttons",this.buttonContainer.classList.add(e.float??"center"),"right"==e.position&&(this.buttonContainer.right=!0),this.root.lastChild&&this.root.lastChild.right?this.root.lastChild.before(this.buttonContainer):this.root.appendChild(this.buttonContainer));for(let t=0;t<i.length;++t){let a=i[t],n=document.createElement("label");var l=a.title;let s=a.disabled??!1;n.className="lexmenubutton"+(s?" disabled":""),n.title=l??"",this.buttonContainer.appendChild(n);var o=document.createElement("a");o.className=a.icon+" lexicon",n.appendChild(o);let e=o;a.swap&&(n.classList.add("swap"),o.classList.add("swap-off"),(o=document.createElement("input")).type="checkbox",n.prepend(o),e=o,(o=document.createElement("a")).className=a.swap+" swap-on lexicon",n.appendChild(o),n.swap=function(){var e=this.querySelector("input");e.checked=!e.checked},n.setState=function(e){this.querySelector("input").checked=e}),e.addEventListener("click",e=>{var t;a.callback&&!s&&(t=n.querySelector("input"),a.callback.call(this,e,t?.checked))}),l&&(this.buttons[l]=n)}}}w.Menubar=s;class n{constructor(e={}){var t;this.root=document.createElement("div"),this.root.className="lexsidebar",this.collapsable=e.collapsable??!0,this._collapseWidth=e.collapseToIcons??!0?"58px":"0px",this.collapsed=!1,this.filterString="",m(()=>{this.root.parentElement.ogWidth=this.root.parentElement.style.width,this.root.parentElement.style.transition="width 0.25s ease-out",this.resizeObserver=new ResizeObserver(e=>{for(const t of e)this.siblingArea.setSize(["calc(100% - "+t.contentRect.width+"px )",null])})},10),e.skipHeader||(this.header=e.header??this._generateDefaultHeader(e),console.assert(this.header.constructor===HTMLDivElement,"Use an HTMLDivElement to build your custom header"),this.header.className="lexsidebarheader",this.root.appendChild(this.header),this.collapsable&&(t=w.makeIcon("Sidebar","Toggle Sidebar","toggler"),this.header.appendChild(t),t.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),this.toggleCollapsed()}))),e.filter&&((t=new k).addText(null,"",(e,t)=>{this.filterString=e,this.update()},{placeholder:"Search...",icon:"fa-solid fa-magnifying-glass"}),this.filter=t.root.childNodes[0],this.root.appendChild(this.filter)),this.content=document.createElement("div"),this.content.className="lexsidebarcontent",this.root.appendChild(this.content),e.skipFooter||(this.footer=e.footer??this._generateDefaultFooter(e),console.assert(this.footer.constructor===HTMLDivElement,"Use an HTMLDivElement to build your custom footer"),this.footer.className="lexsidebarfooter",this.root.appendChild(this.footer)),m(()=>{var e=32+(this.header?.offsetHeight??0)+(this.filter?.offsetHeight??0)+(this.footer?.offsetHeight??0);this.content.style.height=`calc(100% - ${e}px)`},10),this.items=[],this.icons={},this.groups={}}_generateDefaultHeader(t){var e=document.createElement("div"),a=(e.addEventListener("click",e=>{this.collapsed?(e.preventDefault(),e.stopPropagation(),this.toggleCollapsed()):t.onHeaderPressed&&t.onHeaderPressed(e)}),document.createElement("span")),a=(a.className="lexavatar",e.appendChild(a),t.headerImage?((n=document.createElement("img")).src=t.headerImage,a.appendChild(n)):t.headerIcon&&(n=w.makeIcon(t.headerIcon),a.appendChild(n)),document.createElement("div")),n=(a.className="infodefault",e.appendChild(a),document.createElement("span")),n=(n.innerHTML=t.headerTitle??"",a.appendChild(n),document.createElement("span"));return n.innerHTML=t.headerSubtitle??"",a.appendChild(n),e}_generateDefaultFooter(t){var e=document.createElement("div"),a=(e.addEventListener("click",e=>{t.onFooterPressed&&t.onFooterPressed(e)}),document.createElement("span")),a=(a.className="lexavatar",e.appendChild(a),t.footerImage?((n=document.createElement("img")).src=t.footerImage,a.appendChild(n)):t.footerIcon&&(n=w.makeIcon(t.footerIcon),a.appendChild(n)),document.createElement("div")),n=(a.className="infodefault",e.appendChild(a),document.createElement("span")),n=(n.innerHTML=t.footerTitle??"",a.appendChild(n),document.createElement("span")),a=(n.innerHTML=t.footerSubtitle??"",a.appendChild(n),w.makeIcon("MenuArrows"));return e.appendChild(a),e}toggleCollapsed(e){if(this.collapsable){if(this.collapsed=e??!this.collapsed,this.collapsed?(this.root.classList.add("collapsing"),this.root.parentElement.style.width=this._collapseWidth):(this.root.classList.remove("collapsing"),this.root.classList.remove("collapsed"),this.root.parentElement.style.width=this.root.parentElement.ogWidth),!this.resizeObserver)throw"Wait until ResizeObserver has been created!";this.resizeObserver.observe(this.root.parentElement),m(()=>{this.root.classList.toggle("collapsed",this.collapsed),this.resizeObserver.unobserve(this.root.parentElement)},250)}}separator(){this.currentGroup=null,this.add("")}group(e,t){this.currentGroup=e,this.groups[e]=t}add(e,i={}){i.constructor==Function&&(i={callback:i});const l=e.split("/");e=l[l.length-1];this.icons[e]=i.icon;let o=0;const r=(n,e)=>{if(null!=n){let a=null;var t,s;e.forEach(e=>{var t=Object.keys(e).find(e=>e==n);t&&(a=e[t])}),a?r(l[o++],a):((t={})[n]=[],(s=l[o++])||(t.callback=i.callback,t.group=this.currentGroup,t.options=i),e.push(t),r(s,t[n]))}};r(l[o++],this.items)}select(e){let t=e.replace(/\s/g,"").replaceAll(".","");e=this.items.find(e=>e.name===t);e&&e.dom.click()}update(){this.content.innerHTML="";for(var e of this.items)delete e.dom;for(let i of this.items){const h=i.options??{};if(!i.dom){let s=Object.keys(i)[0];if(!this.filterString.length||s.toLowerCase().includes(this.filterString.toLowerCase())){var l=s.replace(/\s/g,"").replaceAll(".","");let t=null,n=document.createElement("div");if(n.className="lexsidebarentry "+(h.className??""),n.id=i.name=l,i.group){var a=i.group.replace(/\s/g,"").replaceAll(".","");if(t=this.content.querySelector("#"+a)){if(!t.classList.contains("lexsidebargroup"))throw"Bad id: "+i.group}else{(t=document.createElement("div")).id=a,t.className="lexsidebargroup",this.content.appendChild(t);var a=document.createElement("div"),o=(a.className="lexsidebargrouptitle",t.appendChild(a),document.createElement("div"));o.innerHTML=i.group,a.appendChild(o),null!=this.groups[i.group]&&((o=document.createElement("a")).className=(this.groups[i.group].icon??"")+" lexicon",a.appendChild(o),o.addEventListener("click",e=>{this.groups[i.group].callback&&this.groups[i.group].callback(i.group,e)}))}}if(""==l){a=document.createElement("div");a.className="lexsidebarseparator",this.content.appendChild(a)}else{this.collapseContainer?(this.collapseContainer.appendChild(n),this.collapseQueue--,this.collapseQueue||delete this.collapseContainer):(t||this.content).appendChild(n);let a=document.createElement("div");n.appendChild(a),i.dom=n,"checkbox"==h.type?(i.value=h.value??!1,o=new k,i.checkbox=o.addCheckbox(null,i.value,(e,t)=>{t.preventDefault(),t.stopPropagation();var a=h.callback;i.value=e,a&&a.call(this,s,e,t)},{label:s,signal:"@checkbox_"+s}),a.appendChild(o.root.childNodes[0])):(h.icon&&((l=document.createElement("i")).className=h.icon,a.appendChild(l)),(l=document.createElement("a")).innerHTML=s,a.appendChild(l)),n.addEventListener("click",e=>{var t;e.target&&e.target.classList.contains("lexcheckbox")||(h.collapsable?a.querySelector(".collapser").click():((t=h.callback)&&t.call(this,s,i.value,e),i.checkbox&&(i.value=!i.value,i.checkbox.set(i.value,!0))),this.root.querySelectorAll(".lexsidebarentry").forEach(e=>e.classList.remove("selected")),n.classList.add("selected"))});var r,l=null!=h.collapsable?h.collapsable:h.collapsable||i[s].length;h.action?(r=w.makeIcon(h.action.icon??"MoreHorizontal",h.action.name),a.appendChild(r),r.addEventListener("click",e=>{e.preventDefault(),e.stopImmediatePropagation();var t=h.action.callback;t&&t.call(this,s,e)})):l&&(r=document.createElement("div"),Object.assign(r.style,{width:"100%",display:"none"}),w.makeCollapsible(a,r,t??this.content),this.collapseQueue=h.collapsable,this.collapseContainer=r);let e=document.createElement("span");if(e.className="lexsidebarentrydesc",e.innerHTML=s,n.appendChild(e),a.addEventListener("mouseenter",()=>{setTimeout(()=>{e.style.display="unset"},150)}),a.addEventListener("mouseleave",()=>{setTimeout(()=>{e.style.display="none"},150)}),i[s].length){var d=document.createElement("div");d.className="lexsidebarsubentrycontainer",l?(this.collapseContainer.appendChild(d),delete this.collapseContainer):(t||this.content).appendChild(d);for(let e=0;e<i[s].length;++e){var c=i[s][e];const u=c.options??{},p=Object.keys(c)[0];if(!this.filterString.length||p.toLowerCase().includes(this.filterString.toLowerCase())){let a=document.createElement("div");a.innerHTML=`<span>${p}</span>`,u.action&&(c=w.makeIcon(u.action.icon??"MoreHorizontal",u.action.name),a.appendChild(c),c.addEventListener("click",e=>{e.preventDefault(),e.stopImmediatePropagation();var t=u.action.callback;t&&t.call(this,p,e)})),a.className="lexsidebarentry",a.id=p,d.appendChild(a),a.addEventListener("click",e=>{var t=u.callback;t&&t.call(this,p,a,e),this.root.querySelectorAll(".lexsidebarentry").forEach(e=>e.classList.remove("selected")),n.classList.add("selected")})}}}}}}}}}w.SideBar=n;class T{static NONE=0;static TEXT=1;static TEXTAREA=2;static BUTTON=3;static DROPDOWN=4;static CHECKBOX=5;static TOGGLE=6;static RADIO=7;static BUTTONS=8;static COLOR=9;static RANGE=10;static NUMBER=11;static TITLE=12;static VECTOR=13;static TREE=14;static PROGRESS=15;static FILE=16;static LAYERS=17;static ARRAY=18;static LIST=19;static TAGS=20;static CURVE=21;static CARD=22;static IMAGE=23;static CONTENT=24;static CUSTOM=25;static SEPARATOR=26;static KNOB=27;static SIZE=28;static PAD=29;static FORM=30;static DIAL=31;static COUNTER=32;static TABLE=33;static TABS=34;static BLANK=35;static NO_CONTEXT_TYPES=[T.BUTTON,T.LIST,T.FILE,T.PROGRESS];constructor(e,t,a,n){this.name=e,this.type=t,this.options=n,this._initialValue=a}value(){if(this.onGetValue)return this.onGetValue();console.warn("Can't get value of "+this.typeName())}set(e,t,a){var n;if(this.onSetValue)return(n=this.domEl.querySelector(".lexwidgetname .lexicon"))&&(n.style.display=e!=this.value()?"block":"none",n.style.display=e!=this._initialValue?"block":"none"),this.onSetValue(e,t??!1,a);console.warn("Can't set value of "+this.typeName())}oncontextmenu(e){T.NO_CONTEXT_TYPES.includes(this.type)||A(this.typeName(),e,e=>{e.add("Copy",()=>{this.copy()}),e.add("Paste",{disabled:!this._can_paste(),callback:()=>{this.paste()}})})}copy(){navigator.clipboard.type=this.type,navigator.clipboard.customIdx=this.customIdx,navigator.clipboard.data=this.value(),navigator.clipboard.writeText(navigator.clipboard.data)}_can_paste(){return this.type===T.CUSTOM?void 0!==navigator.clipboard.customIdx&&this.customIdx==navigator.clipboard.customIdx:navigator.clipboard.type===this.type}paste(){this._can_paste()&&this.set(navigator.clipboard.data)}typeName(){switch(this.type){case T.TEXT:return"Text";case T.TEXTAREA:return"TextArea";case T.BUTTON:return"Button";case T.DROPDOWN:return"Dropdown";case T.CHECKBOX:return"Checkbox";case T.TOGGLE:return"Toggle";case T.RADIO:return"Radio";case T.COLOR:return"Color";case T.RANGE:return"Range";case T.NUMBER:return"Number";case T.VECTOR:return"Vector";case T.TREE:return"Tree";case T.PROGRESS:return"Progress";case T.FILE:return"File";case T.LAYERS:return"Layers";case T.ARRAY:return"Array";case T.LIST:return"List";case T.TAGS:return"Tags";case T.CURVE:return"Curve";case T.KNOB:return"Knob";case T.SIZE:return"Size";case T.PAD:return"Pad";case T.FORM:return"Form";case T.DIAL:return"Dial";case T.COUNTER:return"Counter";case T.TABLE:return"Table";case T.TABS:return"Tabs";case T.BLANK:return"Blank";case T.CUSTOM:return this.customName}console.error("Unknown Widget type: "+this.type)}refresh(){}}w.Widget=T,w.ADD_CUSTOM_WIDGET=function(p,m={}){let e=y();k.prototype["add"+p]=function(s,i,l){let o=this._createWidget(T.CUSTOM,s,null,m);o.customName=p,o.customIdx=e,o.onGetValue=()=>i,o.onSetValue=(e,t,a)=>{i=e,u(),r.querySelector(".lexcustomitems").toggleAttribute("hidden",!1),t||this._trigger(new x(s,i,a),l)};const r=o.domEl;r.style.flexWrap="wrap";let d,c,h=m.default??{};const u=()=>{i&&(o.instance=i=Object.assign(g(h),i)),d&&d.remove(),c&&c.remove(),(d=document.createElement("div")).className="lexcustomcontainer",d.style.width="calc( 100% - "+w.DEFAULT_NAME_WIDTH+")",this.queue(d);var e="<a class='fa-solid "+(m.icon??"fa-cube")+"' style='float:left'></a>",e=(e=e+(p+(i?"":" [empty]"))+("<a class='fa-solid "+(i?"fa-bars-staggered":" ")+" menu' style='float:right; width:5%;'></a>"),this.addButton(null,e,(e,t)=>{i?r.querySelector(".lexcustomitems").toggleAttribute("hidden"):A(null,t,e=>{e.add("New "+p,()=>{i={},u(),r.querySelector(".lexcustomitems").toggleAttribute("hidden",!1)})})},{buttonClass:"custom"}));if(this.clearQueue(),i&&e.querySelector("a.menu").addEventListener("click",e=>{e.stopImmediatePropagation(),e.stopPropagation(),A(null,e,e=>{e.add("Clear",()=>{i=null,u()})})}),(c=document.createElement("div")).className="lexcustomitems",c.toggleAttribute("hidden",!0),r.appendChild(d),r.appendChild(c),i){this.queue(c);var t,a=(e,t,a)=>{i[e]=t,this._trigger(new x(s,i,a),l)};for(t in h){var n=i[t]??h[t];switch(n.constructor){case String:"#"===n[0]?this.addColor(t,n,a.bind(this,t)):this.addText(t,n,a.bind(this,t));break;case Number:this.addNumber(t,n,a.bind(this,t));break;case Boolean:this.addCheckbox(t,n,a.bind(this,t));break;case Array:4<n.length?this.addArray(t,n,a.bind(this,t)):this._add_vector(n.length,t,n,a.bind(this,t))}}this.clearQueue()}};u()}};class N{constructor(e,t,a){if(this.domEl=e,this.data=t,this.onevent=a.onevent,this.options=a,this.selected=[],t.constructor===Object)this._create_item(null,t);else for(var n of t)this._create_item(null,n)}_create_item(e,i,t=0,a){const l=this;var n=this.domEl.querySelector("#lexnodetree_filter");if(i.children=i.children??[],n&&!i.id.includes(n.value)||null!=a&&a!=i.id){for(var s=0;s<i.children.length;++s)this._create_item(i,i.children[s],t+1,a);return}const o=this.domEl.querySelector("ul");i.visible=i.visible??!0,i.parent=e;let r=0<i.children.length;n=-1<this.selected.indexOf(i)||i.selected;if(this.options.onlyFolders){let t=!1;i.children.forEach(e=>t|="folder"==e.type),r=!!t}let d=document.createElement("li"),c=(d.className="lextreeitem datalevel"+t+(r?" parent":"")+(n?" selected":""),d.id=w.getSupportedDOMName(i.id),d.tabIndex="0",this.options.skip_default_icon??!0?"":"fa-solid fa-square");r&&(c=i.closed?"fa-solid fa-caret-right":"fa-solid fa-caret-down"),d.innerHTML="<a class='"+c+" hierarchy'></a>",c=i.icon,i.icon&&(i.icon.includes("fa-")?d.innerHTML+="<a class='"+i.icon+" tree-item-icon'></a>":d.innerHTML+="<img src='https://raw.githubusercontent.com/jxarco/lexgui.js/master/"+i.icon+"'>"),d.innerHTML+=i.rename?"":i.id,d.setAttribute("draggable",!0),d.style.paddingLeft=(r?0:3)+(3+15*(t+1))+"px",o.appendChild(d),d.addEventListener("click",e=>{var t;h?h=!1:(e.shiftKey||(o.querySelectorAll("li").forEach(e=>{e.classList.remove("selected")}),this.selected.length=0),-1<(t=this.selected.indexOf(i))?(d.classList.remove("selected"),this.selected.splice(t,1)):(d.classList.add("selected"),this.selected.push(i)),r&&1<i.id.length&&(i.closed=!1,l.onevent&&(t=new L(L.NODE_CARETCHANGED,i,i.closed),l.onevent(t)),l.frefresh(i.id)),l.onevent&&((t=new L(L.NODE_SELECTED,e.shiftKey?this.selected:i)).multiple=e.shiftKey,l.onevent(t)))}),d.addEventListener("dblclick",function(){var e;(l.options.rename??!0)&&(i.rename=!0,l.refresh()),l.onevent&&(e=new L(L.NODE_DBLCLICKED,i),l.onevent(e))}),d.addEventListener("contextmenu",a=>{if(a.preventDefault(),l.onevent){const t=new L(L.NODE_CONTEXTMENU,1<this.selected.length?this.selected:i,a);t.multiple=1<this.selected.length,w.addContextMenu(t.multiple?"Selected Nodes":t.node.id,t.value,e=>{t.panel=e}),l.onevent(t),1==(this.options.addDefault??!1)&&(t.panel.items&&t.panel.add(""),t.panel.add("Select Children",()=>{const a=e=>{if(!e.closed)for(var t of e.children??[])t&&(this.domEl.querySelector("#"+t.id).classList.add("selected"),this.selected.push(t),a(t))};a(i)}),t.panel.add("Delete",{callback:()=>{var e,t;i.parent&&(l.onevent&&(e=new L(L.NODE_DELETED,i,a),l.onevent(e)),t=(e=i.parent.children).indexOf(i),e.splice(t,1),this.refresh())}}))}}),d.addEventListener("keydown",e=>{if(!i.rename)if(e.preventDefault(),"Delete"==e.key){var t;l.onevent&&((s=new L(L.NODE_DELETED,1<this.selected.length?this.selected:i,e)).multiple=1<this.selected.length,l.onevent(s));for(t of this.selected){var a=t.parent.children,n=a.indexOf(t);a.splice(n,1)}this.selected.length=0,this.refresh()}else{var s;("ArrowUp"==e.key||"ArrowDown"==e.key)&&(s=1<this.selected.length?"ArrowUp"==e.key?this.selected.shift():this.selected.pop():this.selected[0],s=this.domEl.querySelector("#"+w.getSupportedDOMName(s.id)),e="ArrowUp"==e.key?s.previousSibling:s.nextSibling)&&e.click()}});n=document.createElement("input");n.toggleAttribute("hidden",!i.rename),n.value=i.id,d.appendChild(n),i.rename&&(d.classList.add("selected"),n.focus()),n.addEventListener("keyup",function(e){var t;"Enter"==e.key?(this.value=this.value.replace(/\s/g,"_"),l.onevent&&(t=new L(L.NODE_RENAMED,i,this.value),l.onevent(t)),i.id=w.getSupportedDOMName(this.value),delete i.rename,l.frefresh(i.id),o.querySelector("#"+i.id).classList.add("selected")):"Escape"==e.key&&(delete i.rename,l.frefresh(i.id))}),n.addEventListener("blur",function(e){delete i.rename,l.refresh()}),(this.options.draggable??!0)&&(e&&d.addEventListener("dragstart",e=>{window.__tree_node_dragged=i}),d.addEventListener("dragover",e=>{e.preventDefault()},!1),d.addEventListener("dragenter",e=>{e.target.classList.add("draggingover")}),d.addEventListener("dragleave",e=>{e.target.classList.remove("draggingover")}),d.addEventListener("drop",e=>{e.preventDefault();let t=window.__tree_node_dragged;if(t){var a,e=i;if(t.id==e.id)console.warn("Cannot parent node to itself!");else{const s=function(e,t){var a,n=!1;for(a of t.children){if(a.id==e.id)return!0;n|=s(e,a)}return n};s(e,t)?console.warn("Cannot parent node to a current child!"):(l.onevent&&(a=new L(L.NODE_DRAGGED,t,e),l.onevent(a)),a=t.parent.children.findIndex(e=>e.id==t.id),a=t.parent.children.splice(a,1),e.children.push(a[0]),l.refresh(),delete window.__tree_node_dragged)}}}));let h=!1;r&&d.querySelector("a.hierarchy").addEventListener("click",function(e){h=!0,e.stopImmediatePropagation(),e.stopPropagation(),i.closed=!i.closed,l.onevent&&(e=new L(L.NODE_CARETCHANGED,i,i.closed),l.onevent(e)),l.frefresh(i.id)});var u=document.createElement("div");if(d.appendChild(u),i.actions)for(let e=0;e<i.actions.length;++e){let t=i.actions[e],a=document.createElement("a");a.className="lexicon "+t.icon,a.title=t.name,a.addEventListener("click",function(e){t.callback(i,a),e.stopPropagation()}),u.appendChild(a)}if(i.skipVisibility||((n=document.createElement("a")).className="lexicon fa-solid fa-eye"+(i.visible?"":"-slash"),n.title="Toggle visible",n.addEventListener("click",function(e){e.stopPropagation(),i.visible=void 0!==i.visible&&!i.visible,this.className="lexicon fa-solid fa-eye"+(i.visible?"":"-slash"),l.onevent&&(e=new L(L.NODE_VISIBILITY,i,i.visible),l.onevent(e))}),u.appendChild(n)),null!=a&&i.id==a&&(this.selected=[i],d.click()),!i.closed)for(s=0;s<i.children.length;++s){var p=i.children[s];this.options.onlyFolders&&"folder"!=p.type||this._create_item(i,p,t+1)}}refresh(e,t){this.data=e??this.data,this.domEl.querySelector("ul").innerHTML="",this._create_item(null,this.data,0,t)}frefresh(e){this.refresh();e=this.domEl.querySelector("#"+e);e&&e.focus()}select(e){this.refresh(null,e)}}class k{constructor(e={}){var t=document.createElement("div");t.className="lexpanel",e.id&&(t.id=e.id),e.className&&(t.className+=" "+e.className),t.style.width=e.width||"calc( 100% - 6px )",t.style.height=e.height||"100%",Object.assign(t.style,e.style??{}),this._inline_widgets_left=-1,this._inline_queued_container=null,this.root=t,this.onevent=e=>{},this._branchOpen=!1,this.branches=[],this._currentBranch=null,this.widgets={},this._queue=[]}get(e){return this.widgets[e]}getValue(e){var t=this.widgets[e];if(t)return t.value();throw"No widget called "+e}setValue(e,t,a){var n=this.widgets[e];if(n)return n.set(t,a);throw"No widget called "+e}attach(e){console.assert(e,"No content to attach!"),(e.parent=this).root.appendChild(e.root||e)}clear(){for(var t in this._branchOpen=!1,this.branches=[],this._currentBranch=null,this.widgets)if(this.widgets[t].options&&this.widgets[t].options.signal){var a=this.widgets[t].options.signal;for(let e=0;e<w.signals[a].length;e++)w.signals[a][e]==this.widgets[t]&&(w.signals[a]=[...w.signals[a].slice(0,e),...w.signals[a].slice(e+1)])}if(this.signals)for(let e=0;e<this.signals.length;e++){var n=Object.values(this.signals[e])[0],s=n.options.signal;for(let e=0;e<w.signals[s].length;e++)w.signals[s][e]==n&&(w.signals[s]=[...w.signals[s].slice(0,e),...w.signals[s].slice(e+1)])}this.widgets={},this.root.innerHTML=""}sameLine(e){this._inline_queued_container=this.queuedContainer,this._inline_widgets_left=e||1/0}endLine(e){if(-1==this._inline_widgets_left)console.warn("No pending widgets to be inlined!");else{this._inline_widgets_left=-1,this._inlineContainer||(this._inlineContainer=document.createElement("div"),this._inlineContainer.className="lexinlinewidgets",e&&(this._inlineContainer.style.justifyContent=e));for(var t of this._inlineWidgets)t.constructor==Array?(this._inline_queued_container?this._inlineContainer:t[1]).appendChild(t[0]):this._inlineContainer.appendChild(t);(this._inline_queued_container||(this._currentBranch?this._currentBranch.content:this.root)).appendChild(this._inlineContainer),delete this._inlineWidgets,delete this._inlineContainer}}branch(e,t={}){this._branchOpen&&this.merge();e=new a(e,t);return(e.panel=this)._branchOpen=!0,this._currentBranch=e,0==this.branches.length&&e.root.classList.add("first"),this.root.querySelectorAll(".lexbranch.last").forEach(e=>{e.classList.remove("last")}),e.root.classList.add("last"),this.branches.push(e),this.root.appendChild(e.root),t.filter&&this._addFilter(t.filter,{callback:this._searchWidgets.bind(this,e.name)}),e}merge(){this._branchOpen=!1,this._currentBranch=null}_pick(e,t){return void 0===e?t:e}static _dispatch_event(e,t,a,n,s){t=new CustomEvent(t,{detail:a,bubbles:n,cancelable:s});e.dispatchEvent(t)}static _add_reset_property(e,t){var a=document.createElement("a");return a.style.display="none",a.style.marginRight="6px",a.className="lexicon fa fa-rotate-left",a.addEventListener("click",t),e.appendChild(a),a}_createWidget(e,t,a,n={}){w.CREATED_INSTANCES||(w.CREATED_INSTANCES=[]),w.CREATED_INSTANCES[e]=!0;let s=new T(t,e,a,n);var i=document.createElement("div"),a=(i.className="lexwidget",i.id=n.id??"",i.title=n.title??"",n.className&&(i.className+=" "+n.className),e!=T.TITLE&&(i.style.width="calc(100% - "+(this._currentBranch||e==T.FILE||e==T.TREE?10:20)+"px)",n.width&&(i.style.width=i.style.minWidth=n.width),n.maxWidth&&(i.style.maxWidth=n.maxWidth),n.minWidth&&(i.style.minWidth=n.minWidth),n.height)&&(i.style.height=i.style.minHeight=n.height),null!=t?(n.hideName||((e=document.createElement("div")).className="lexwidgetname",n.justifyName&&e.classList.add("float-"+n.justifyName),e.innerHTML=t,e.title=n.title??e.innerHTML,e.style.width=n.nameWidth||w.DEFAULT_NAME_WIDTH,i.appendChild(e),(i.domName=e).addEventListener("contextmenu",function(e){e.preventDefault(),s.oncontextmenu(e)}),n.skipReset)||null==a||k._add_reset_property(e,function(e){s.set(s._initialValue,!1,e),this.style.display="none"}),this.widgets[t]=s):n.hideName=!0,n.signal&&(t||(this.signals||(this.signals=[]),this.signals.push({[n.signal]:s})),w.addSignal(n.signal,s)),(s.domEl=i).jsInstance=s,e=>{(n.container||this.queuedContainer||(this._currentBranch?(n.skipWidget||this._currentBranch.widgets.push(s),this._currentBranch.content):(e.classList.add("nobranch"),this.root))).appendChild(e)}),e=e=>{this.queuedContainer?this._inlineWidgets.push([e,this.queuedContainer]):this._inlineWidgets.push(e)};return 0<this._inline_widgets_left&&!n.skipInlineCount?(this._inlineWidgets||(this._inlineWidgets=[]),e(i),this._inline_widgets_left--,this._inline_widgets_left||this.endLine()):a(i),s}_addFilter(e,t={}){t.placeholder=e.constructor==String?e:"Filter properties..",t.skipWidget=t.skipWidget??!0,t.skipInlineCount=!0;e=this._createWidget(T.TEXT,null,null,t).domEl;e.className+=" lexfilter noname";let a=document.createElement("input");a.className="lexinput-filter",a.setAttribute("placeholder",t.placeholder),a.style.width="calc( 100% - 17px )",a.value=t.filterValue||"";var n=document.createElement("a");return n.className="fa-solid fa-magnifying-glass",e.appendChild(n),e.appendChild(a),a.addEventListener("input",e=>{t.callback&&t.callback(a.value,e)}),e}_searchWidgets(e,t){for(var a of this.branches)if(a.name===e){for(var n of a.widgets)n.domEl.classList.contains("lexfilter")||n.domEl.remove();this.queue(a.content);var s,i=!t.length;for(s of a.widgets){if(!i){if(!s.name)continue;t.toLowerCase();if(!s.name.toLowerCase().includes(t))continue}this.queuedContainer.appendChild(s.domEl)}return void this.clearQueue()}}_filterOptions(t,a){var n=!a.length,s=[];for(let e=0;e<t.length;e++){var i=t[e];if(!n){var l="string"==typeof i?i:i.value,o=a.toLowerCase();if(!l.toLowerCase().includes(o))continue}s.push(i)}this.refresh(s)}_trigger(e,t){t&&t.call(this,e.value,e.domEvent,e.name),this.onevent&&this.onevent.call(this,e)}getBranch(t){return t?this.branches.find(e=>e.name==t):this._currentBranch}queue(e){!e&&this._currentBranch&&(e=this._currentBranch.root),this.queuedContainer&&this._queue.push(this.queuedContainer),this.queuedContainer=e}clearQueue(){this._queue&&this._queue.length?this.queuedContainer=this._queue.pop():delete this.queuedContainer}addBlank(e=8,t){var a=this._createWidget(T.BLANK);return a.domEl.className+=" blank",a.domEl.style.height=e+"px",t&&(a.domEl.style.width=t),a}addTitle(e,t={}){console.assert(e,"Can't create Title Widget without text!");var a=this._createWidget(T.TITLE,null,null,t).domEl,n=(a.className="lextitle",t.icon&&((n=document.createElement("a")).className=t.icon,n.style.color=t.iconColor||"",a.appendChild(n)),document.createElement("span"));return n.innerText=e,a.appendChild(n),Object.assign(a.style,t.style??{}),null!=t.link&&((n=document.createElement("a")).innerText=e,n.href=t.link,n.target=t.target??"",n.className="lextitle link",Object.assign(n.style,t.style??{}),a.replaceWith(n)),a}addText(n,s,i,l={}){let o=this._createWidget(T.TEXT,n,String(s),l);o.onGetValue=()=>s,o.onSetValue=(e,t,a)=>{o.valid(e)&&this._lastValueTriggered!=e&&(this._lastValueTriggered=s=e,l.disabled?r.innerText=e:r.value=e,t||this._trigger(new x(n,e,a),i))},o.valid=e=>!e.length||""==r.pattern||new RegExp(r.pattern).test(e);var e,t=o.domEl,a=document.createElement("div");a.className="lextext"+(l.warning?" lexwarning":""),a.style.width=l.inputWidth||"calc( 100% - "+w.DEFAULT_NAME_WIDTH+" )",a.style.display="flex",l.textClass&&a.classList.add(l.textClass),this.disabled=(l.disabled||l.warning)??!!l.url;let r=null;return this.disabled?(r=document.createElement(l.url?"a":"div"),l.url&&(r.href=l.url,r.target="_blank"),r.innerHTML=(l.warning?'<i class="fa-solid fa-triangle-exclamation"></i>':"")+s||"",r.style.width="100%",r.style.textAlign=l.float??""):((r=document.createElement("input")).type=l.type||"",r.value=r.iValue=s||"",r.style.width="100%",r.style.textAlign=l.float??"",r.setAttribute("placeholder",l.placeholder??""),l.required&&r.setAttribute("required",l.required),l.pattern&&r.setAttribute("pattern",l.pattern),"default"==(e=l.trigger??"default")?(r.addEventListener("keyup",function(e){"Enter"==e.key&&r.blur()}),r.addEventListener("focusout",function(e){o.set(e.target.value,!1,e)})):"input"==e&&r.addEventListener("input",function(e){o.set(e.target.value,!1,e)}),r.addEventListener("mousedown",function(e){e.stopImmediatePropagation(),e.stopPropagation()}),l.icon&&((e=document.createElement("a")).className="inputicon "+l.icon,a.appendChild(e))),Object.assign(r.style,l.style??{}),a.appendChild(r),t.appendChild(a),l.hideName&&(t.className+=" noname",a.style.width="100%"),o}addTextArea(n,s,i,e={}){let t=this._createWidget(T.TEXTAREA,n,s,e);t.onGetValue=()=>s,t.onSetValue=(e,t,a)=>{o.value=s=e,t||this._trigger(new x(n,e,a),i)};var a=t.domEl,l=document.createElement("div");l.className="lextextarea",l.style.width=e.inputWidth||"calc( 100% - "+w.DEFAULT_NAME_WIDTH+" )",l.style.height=e.height,l.style.display="flex";let o=document.createElement("textarea");o.value=o.iValue=s||"",o.style.width="100%",o.style.textAlign=e.float??"",Object.assign(o.style,e.style??{}),e.disabled&&o.setAttribute("disabled",!0),e.placeholder&&o.setAttribute("placeholder",e.placeholder);var r=e.trigger??"default",r=("default"==r?(o.addEventListener("keyup",function(e){"Enter"==e.key&&o.blur()}),o.addEventListener("focusout",function(e){t.set(e.target.value,!1,e)})):"input"==r&&o.addEventListener("input",function(e){t.set(e.target.value,!1,e)}),e.icon&&((r=document.createElement("a")).className="inputicon "+e.icon,l.appendChild(r)),l.appendChild(o),a.appendChild(l),!e.hideName);return r||(a.className+=" noname",l.style.width="100%"),m(()=>{e.fitHeight&&(o.style.height=o.scrollHeight+"px")},10),t}addLabel(e,t={}){return t.disabled=!0,this.addText(null,e,null,t)}addButton(t,a,n,s={}){var e=this._createWidget(T.BUTTON,t,null,s),e=(e.onGetValue=()=>i.innerText,e.onSetValue=(e,t,a)=>{i.innerHTML=s.icon?"<a class='"+s.icon+"'></a>":s.img?"<img src='"+s.img+"'>":"<span>"+(e||"")+"</span>"},e.domEl),i=document.createElement("button"),l=(i.title=s.title??"",i.className="lexbutton "+(s.buttonClass??""),s.selected&&i.classList.add("selected"),i.innerHTML=s.icon?"<a class='"+s.icon+"'></a>":s.img?"<img src='"+s.img+"'>":"<span>"+(a||"")+"</span>",i.style.width="calc( 100% - "+(s.nameWidth??w.DEFAULT_NAME_WIDTH)+")",s.disabled&&i.setAttribute("disabled",!0),i.addEventListener("click",e=>{s.selectable&&(s.parent&&s.parent.querySelectorAll(".lexbutton.selected").forEach(e=>{e!=i&&e.classList.remove("selected")}),i.classList.toggle("selected")),this._trigger(new x(t,a,e),n)}),e.appendChild(i),!s.hideName&&!(s.icon||s.img));return l||(i.className+=" noname",i.style.width="100%"),e}addComboButtons(a,e,n={}){var t=this._createWidget(T.BUTTONS,a,null,n),s=t.domEl;let i=this,l=document.createElement("div");l.className="lexcombobuttons ",n.float&&(l.className+=n.float),l.style.width="calc( 100% - "+w.DEFAULT_NAME_WIDTH+")";var o=document.createElement("div");o.className="lexcombobuttonsbox ";const r=!n.noSelection,d=r&&(n.toggle??!1);for(let t of e){if(!t.value)throw"Set 'value' for each button!";var c=document.createElement("button");c.className="lexbutton combo",c.title=t.icon?t.value:"",c.id=t.id??"",n.buttonClass&&c.classList.add(n.buttonClass),r&&(t.selected||n.selected==t.value)&&c.classList.add("selected"),c.innerHTML=(t.icon?"<a class='"+t.icon+"'></a>":"")+"<span>"+(t.icon?"":t.value)+"</span>",t.disabled&&c.setAttribute("disabled",!0),c.addEventListener("click",function(e){r&&(d?this.classList.toggle("selected"):(l.querySelectorAll("button").forEach(e=>e.classList.remove("selected")),this.classList.add("selected"))),i._trigger(new x(a,t.value,e),t.callback)}),o.appendChild(c)}return!n.hideName||(s.className+=" noname",l.style.width="100%"),l.appendChild(o),s.appendChild(l),t}addCard(t,a={}){a.hideName=!0;var e=this._createWidget(T.CARD,t,null,a),n=e.domEl;let s=document.createElement("div");s.className="lexcard",s.style.width="100%",a.img&&((l=document.createElement("img")).src=a.img,s.appendChild(l),null!=a.link)&&(l.style.cursor="pointer",l.addEventListener("click",function(){var e=s.querySelector("a");e&&e.click()}));var i,l=document.createElement("span");return l.innerText=t,null!=a.link&&((i=document.createElement("a")).innerText=t,i.href=a.link,i.target=a.target??"",l.innerText="",l.appendChild(i)),s.appendChild(l),a.callback&&(s.style.cursor="pointer",s.addEventListener("click",e=>{this._trigger(new x(t,null,e),a.callback)})),n.appendChild(s),e}addForm(e,n,s,t={}){if(n.constructor!=Object)return void console.error("Form data must be an Object");t.hideName=!0;var e=this._createWidget(T.FORM,e,null,t),a=(e.onGetValue=()=>l.formData,e.onSetValue=(t,a,e)=>{l.formData=t;var n,s,i=l.querySelectorAll(".lexwidget");for(let e=0;e<i.length;++e)i[e].jsInstance.type==w.Widget.TEXT&&(n=i[e].querySelector(".lexwidgetname").innerText,(s=i[e].querySelector(".lextext input")).value=t[n]??"",k._dispatch_event(s,"focusout",a))},e.domEl);let l=document.createElement("div");l.className="lexformdata",this.queue(l),l.formData={};for(let t in n){let e=n[t];(e=e.constructor!=Object?{}:e).placeholder=e.placeholder??t,e.width="calc(100% - 10px)",this.addLabel(t,{textClass:"formlabel"}),e.textWidget=this.addText(null,e.constructor==Object?e.value:e,e=>{l.formData[t]=e},e),l.formData[t]=e.constructor==Object?e.value:e}return this.addBlank(),this.addButton(null,t.actionName??"Submit",(e,t)=>{for(var a in n)if(!n[a].textWidget.valid())return;s&&s(l.formData,t)},{buttonClass:"primary",width:"calc(100% - 10px)"}),this.clearQueue(),a.appendChild(l),a.className+=" noname",l.style.width="100%",e}addContent(e,t,a={}){console.assert(t,"Empty content!"),t.constructor==String&&((n=document.createElement("div")).innerHTML=t,t=1<n.childElementCount?n:n.firstElementChild),a.hideName=!0;var n=this._createWidget(T.CONTENT,e,null,a);return n.domEl.appendChild(t),n}async addImage(e,t,a={}){console.assert(t,"Empty src/url for Image!");var n,e=this._createWidget(T.IMAGE,e,null,a),s=e.domEl,i=document.createElement("div"),l=(i.className="leximage",i.style.width="100%",document.createElement("img"));for(n in l.src=t,a.style)l.style[n]=a.style[n];return await l.decode(),i.appendChild(l),s.appendChild(i),e}addDropdown(n,o,r,s,e={}){let d=this._createWidget(T.DROPDOWN,n,r,e);d.onGetValue=()=>c.querySelector("li.selected").getAttribute("value"),d.onSetValue=(e,t,a)=>{r=e,m.querySelectorAll("li").forEach(e=>{e.getAttribute("value")==r&&e.click()}),t||this._trigger(new x(n,r,a),s)};const c=d.domEl;var t=document.createElement("div");t.className="lexdropdown",t.style.width=e.inputWidth||"calc( 100% - "+w.DEFAULT_NAME_WIDTH+")";let h=document.createElement("div");h.className="lexdropdown lexoption",h.name=n;var a=h.iValue=r;a+="<a class='fa-solid fa-angle-down' style='float:right; margin-right: 3px;'></a>",this.queue(t);let u=this.addButton(null,a,(e,t)=>{m.unfocus_event?delete m.unfocus_event:(p.classList.remove("place-above"),p.hasAttribute("open")?p.close():(p.show(),(a=>{var n=a.getParentArea();const s=u.getBoundingClientRect();var i=a.parentElement.closest("dialog");{var l=a.offsetHeight;let e=s.y,t=window.innerHeight;if(n&&(o=n.getBoundingClientRect(),t=o.y+o.height),i){const s=i.getBoundingClientRect();e-=s.y}a.style.top=e+u.offsetHeight+"px",e+l>t&&(a.style.top=e-l+"px",a.classList.add("place-above"))}{var o=a.offsetWidth;let e=s.x;if(a.style.minWidth=s.width+"px",i){const s=i.getBoundingClientRect();e-=s.x}a.style.left=e+"px";let t=window.innerWidth;n&&(l=n.getBoundingClientRect(),t=l.x+l.width),e+o>t&&(a.style.left=e-(o-s.width)+"px")}})(p)),g&&g.querySelector("input").focus())},{buttonClass:"array",skipInlineCount:!0,disabled:e.disabled});this.clearQueue(),u.style.width="100%",u.refresh=e=>{""==u.querySelector("span").innerText?u.querySelector("span").innerText=e:u.querySelector("span").innerHTML=u.querySelector("span").innerHTML.replaceAll(u.querySelector("span").innerText,e)};const p=document.createElement("dialog");p.className="lexdropdownoptions";let m=document.createElement("ul"),g=(m.tabIndex=-1,m.className="lexoptions",p.appendChild(m),m.addEventListener("focusout",function(e){if(e.stopPropagation(),e.stopImmediatePropagation(),e.relatedTarget===u.querySelector("button"))this.unfocus_event=!0,setTimeout(()=>delete this.unfocus_event,200);else{if(e.relatedTarget&&"INPUT"==e.relatedTarget.tagName)return;if("lexinput-filter"==e.target.className)return}p.close()}),null);e.filter&&(g=this._addFilter(e.placeholder??"Search...",{container:m,callback:this._filterOptions.bind(m,o)}),m.appendChild(g),g.addEventListener("focusout",function(e){e.relatedTarget&&"UL"==e.relatedTarget.tagName&&e.relatedTarget.classList.contains("lexoptions")||p.close()}));const v=document.createElement("span");return v.style.height="calc(100% - 25px)",m.appendChild(v),m.refresh=t=>{var e,a;if(v.innerHTML="",t.length)for(let e=0;e<t.length;e++){var n,s=t[e],i=document.createElement("li"),l=document.createElement("div");l.className="option",i.appendChild(l),i.addEventListener("click",e=>{p.close();var t=c.querySelector(".lexoptions .selected");t&&t.classList.remove("selected"),r=e.currentTarget.getAttribute("value"),e.currentTarget.toggleAttribute("hidden",!1),e.currentTarget.classList.add("selected"),u.refresh(r),d.set(r,!1,e),g&&(g.querySelector("input").value="",this._filterOptions.bind(m,o,"")())}),s.constructor!=Object?(l.style.flexDirection="unset",l.innerHTML="</a><span>"+s+"</span><a class='fa-solid fa-check'>",l.value=s,i.setAttribute("value",s),i.className="lexdropdownitem",s==r&&(i.classList.add("selected"),h.innerHTML=s)):((n=document.createElement("img")).src=s.src,i.setAttribute("value",s.value),i.className="lexlistitem",l.innerText=s.value,l.className+=" media",l.prepend(n),l.setAttribute("value",s.value),l.setAttribute("data-index",e),l.setAttribute("data-src",s.src),l.setAttribute("title",s.value),r==s.value&&i.classList.add("selected")),v.appendChild(i)}else a=t.emptyMsg??"No options found.",(e=document.createElement("div")).className="option",e.style.flexDirection="unset",e.innerHTML=a,(a=document.createElement("li")).className="lexdropdownitem empty",a.appendChild(e),v.appendChild(a)},m.refresh(o),t.appendChild(p),c.appendChild(t),e.hideName&&(c.className+=" noname",t.style.width="100%"),d}addCurve(n,e,s,t={}){var a=JSON.parse(JSON.stringify(e));let i=this;var a=this._createWidget(T.CURVE,n,a,t),l=(a.onGetValue=()=>JSON.parse(JSON.stringify(r.element.value)),a.onSetValue=(e,t,a)=>{r.element.value=JSON.parse(JSON.stringify(e)),r.redraw(),t||i._trigger(new x(n,r.element.value,a),s)},a.domEl),o=document.createElement("div");o.className="lexcurve",o.style.width="calc( 100% - "+w.DEFAULT_NAME_WIDTH+")",t.callback=(e,t)=>{i._trigger(new x(n,e,t),s)},t.name=n;let r=new D(this,e,t);return o.appendChild(r.element),l.appendChild(o),a.onresize=r.redraw.bind(r),a.curveInstance=r,m(()=>{r.canvas.width=o.offsetWidth,r.redraw()}),a}addDial(n,e,s,t={}){var a=JSON.parse(JSON.stringify(e));let i=this;var a=this._createWidget(T.DIAL,n,a,t),l=(a.onGetValue=()=>JSON.parse(JSON.stringify(r.element.value)),a.onSetValue=(e,t,a)=>{r.element.value=JSON.parse(JSON.stringify(e)),r.redraw(),t||i._trigger(new x(n,r.element.value,a),s)},a.domEl),o=document.createElement("div");o.className="lexcurve",o.style.width=a.name?"calc( 100% - "+w.DEFAULT_NAME_WIDTH+")":"100%",t.callback=(e,t)=>{i._trigger(new x(n,e,t),s)},t.name=n;let r=new M(this,e,t);return o.appendChild(r.element),l.appendChild(o),a.onresize=r.redraw.bind(r),a.curveInstance=r,m(()=>{r.element.style.height=r.element.offsetWidth+"px",r.canvas.width=r.element.offsetWidth,o.style.width=r.element.offsetWidth+"px",r.canvas.height=r.canvas.width,r.redraw()}),a}addLayers(n,i,s,e={}){let l=this,o=this._createWidget(T.LAYERS,n,i,e);o.onGetValue=()=>r.value,o.onSetValue=(e,t,a)=>{i=r.value=e,c(),t||l._trigger(new x(n,i,a),s)};const r=o.domEl;var d=document.createElement("div");d.className="lexlayers",d.style.width="calc( 100% - "+w.DEFAULT_NAME_WIDTH+")",r.value=i;const c=()=>{d.innerHTML="";let e=i.toString(2);for(var t=e.length,a=0;a<16-t;++a)e="0"+e;for(let t=0;t<16;++t){var n,s=document.createElement("div");s.className="lexlayer",null!=i&&null!=(n=e[16-t-1])&&"1"==n&&s.classList.add("selected"),s.innerText=t+1,s.title="Bit "+t+", value "+(1<<t),d.appendChild(s),s.addEventListener("click",e=>{e.stopPropagation(),e.stopImmediatePropagation(),e.target.classList.toggle("selected"),i^=1<<t,o.set(i,!1,e)})}};return c(),r.appendChild(d),o}addArray(s,i=[],l,o={}){var e=this._createWidget(T.ARRAY,s,null,o);e.onGetValue=()=>{var e,t=[];for(e of a.querySelectorAll("input"))t.push(e.value);return t},e.onSetValue=(e,t,a)=>{i=e,u(),t||this._trigger(new x(s,i,a),l)};const a=e.domEl,r=(a.style.flexWrap="wrap","4%");var t=document.createElement("div");t.className="lexarray",t.style.width="calc( 100% - "+w.DEFAULT_NAME_WIDTH+")",this.queue(t);const d="<a class='fa-solid fa-angle-down' style='float:right; margin-right: 3px;'></a>";let c="Array (size "+i.length+")",h=(c+=d,this.addButton(null,c,()=>{a.querySelector(".lexarrayitems").toggleAttribute("hidden")},{buttonClass:"array"}),this.clearQueue(),document.createElement("div"));h.className="lexarrayitems",h.toggleAttribute("hidden",!0),a.appendChild(t),a.appendChild(h);const u=()=>{var e=a.querySelector(".lexbutton.array span");e.innerHTML="Array (size "+i.length+")",e.innerHTML+=d,h.innerHTML="",this.queue(h);for(let a=0;a<i.length;++a){const n=i[a];var t=o.innerValues?"dropdown":n.constructor;switch(this.sameLine(2),t){case String:this.addText(a+"",n,function(e,t){i[a]=e,l(i)},{nameWidth:r,inputWidth:"95%",skipReset:!0});break;case Number:this.addNumber(a+"",n,function(e,t){i[a]=e,l(i)},{nameWidth:r,inputWidth:"95%",skipReset:!0});break;case"dropdown":this.addDropdown(a+"",o.innerValues,n,function(e,t){i[a]=e,l(i)},{nameWidth:r,inputWidth:"95%",skipReset:!0})}this.addButton(null,"<a class='lexicon fa-solid fa-trash'></a>",(e,t)=>{i.splice(i.indexOf(n),1),u(),this._trigger(new x(s,i,t),l)},{title:"Remove item",className:"micro"})}c="Add item",c+="<a class='fa-solid fa-plus' style='float:right; margin-right: 3px; margin-top: 2px;'></a>",this.addButton(null,c,(e,t)=>{i.push(o.innerValues?o.innerValues[0]:""),u(),this._trigger(new x(s,i,t),l)},{buttonClass:"array"}),this.clearQueue()};return u(),e}addList(s,i,l,o,e={}){var t=this._createWidget(T.LIST,s,l,e),a=(t.onGetValue=()=>l,t.onSetValue=(e,t,a)=>{r.querySelectorAll(".lexlistitem").forEach(e=>e.classList.remove("selected"));var n=i.indexOf(e);-1==n||(r.children[n].classList.toggle("selected"),l=e,t)||this._trigger(new x(s,e,a),o)},t.updateValues=e=>{i=e,r.innerHTML="";for(let n=0;n<i.length;++n){let e=null,t=i[n],a=(t.constructor===Array&&(e=t[1],t=t[0]),document.createElement("div"));a.className="lexlistitem"+(l==t?" selected":""),a.innerHTML="<span>"+t+"</span>"+(e?"<a class='"+e+"'></a>":""),a.addEventListener("click",e=>{r.querySelectorAll(".lexlistitem").forEach(e=>e.classList.remove("selected")),a.classList.toggle("selected"),l=t,this._trigger(new x(s,t,e),o)}),r.appendChild(a)}},t.domEl);let r=document.createElement("div");return r.className="lexlist",r.style.width="calc( 100% - "+w.DEFAULT_NAME_WIDTH+")",t.updateValues(i),e.hideName&&(a.className+=" noname",r.style.width="100%"),a.appendChild(r),t}addTags(n,s,i,e={}){s=s.replace(/\s/g,"").split(",");var t=[].concat(s);let l=this._createWidget(T.TAGS,n,t,e);l.onGetValue=()=>[].concat(s),l.onSetValue=(e,t,a)=>{s=[].concat(e),d(),t||o._trigger(new x(n,s,a),i)};t=l.domEl;let o=this;const r=document.createElement("div"),d=(r.className="lextags",r.style.width="calc( 100% - "+w.DEFAULT_NAME_WIDTH+")",()=>{r.innerHTML="";for(let e=0;e<s.length;++e){const a=s[e],n=document.createElement("span");n.className="lextag",n.innerHTML=a;var t=document.createElement("a");t.className="lextagrmb fa-solid fa-xmark lexicon",n.appendChild(t),t.addEventListener("click",e=>{n.remove(),s.splice(s.indexOf(a),1),l.set(s,!1,e)}),r.appendChild(n)}var e=document.createElement("input");e.value="",e.placeholder="Add tag...",r.appendChild(e),e.onkeydown=function(e){var t=this.value.replace(/\s/g,"");" "!=e.key&&"Enter"!=e.key||(e.preventDefault(),!t.length)||-1<s.indexOf(t)||(s.push(t),l.set(s,!1,e))},e.focus()});return d(),e.hideName&&(t.className+=" noname",r.style.width="100%"),t.appendChild(r),l}addCheckbox(n,s,i,e={}){if(!n&&!e.label)throw"Set Widget Name or at least a label!";let t=this._createWidget(T.CHECKBOX,n,s,e);t.onGetValue=()=>s,t.onSetValue=(e,t,a)=>{e==s||(o.checked=s=e,l.querySelector(".lexcheckboxsubmenu")?.toggleAttribute("hidden",!e),t)||this._trigger(new x(n,e,a),i)};const l=t.domEl;var a=document.createElement("div");a.className="lexcheckboxcont";let o=document.createElement("input");o.type="checkbox",o.className="lexcheckbox "+(e.className??""),o.checked=s,o.disabled=e.disabled??!1;var r=document.createElement("span");return r.className="checkboxtext",r.innerHTML=e.label??"On",a.appendChild(o),a.appendChild(r),o.addEventListener("change",e=>{t.set(o.checked,!1,e)}),l.appendChild(a),e.suboptions&&(l.style.flexWrap="wrap",(r=document.createElement("div")).className="lexcheckboxsubmenu",r.toggleAttribute("hidden",!o.checked),this.queue(r),e.suboptions.call(this,this),this.clearQueue(),l.appendChild(r)),t}addToggle(n,s,i,e={}){let t=this._createWidget(T.TOGGLE,n,s,e);t.onGetValue=()=>o.checked,t.onSetValue=(e,t,a)=>{e==s||(o.checked=s=e,l.querySelector(".lextogglesubmenu")?.toggleAttribute("hidden",!e),t)||this._trigger(new x(n,e,a),i)};const l=t.domEl;var a=document.createElement("div");a.className="lextogglecont";let o=document.createElement("input");o.type="checkbox",o.className="lextoggle "+(e.className??""),o.checked=s,o.iValue=s,o.disabled=e.disabled??!1;var r=document.createElement("span");return r.className="toggletext",r.innerHTML="On",a.appendChild(o),a.appendChild(r),o.addEventListener("change",e=>{t.set(o.checked,!1,e)}),l.appendChild(a),e.suboptions&&(l.style.flexWrap="wrap",(r=document.createElement("div")).className="lextogglesubmenu",r.toggleAttribute("hidden",!o.checked),this.queue(r),e.suboptions.call(this,this),this.clearQueue(),l.appendChild(r)),t}addRadioGroup(e,t,s,i,a={}){let n=this._createWidget(T.RADIO,e,null,a),l=null;n.onGetValue=()=>{var e=o.querySelectorAll("button");return l?[l,e[l]]:void 0},n.onSetValue=(e,t,a)=>{console.assert(e.constructor==Number,"RadioGroup _value_ must be an Array index!");var n=o.querySelectorAll("button"),n=(n.forEach(e=>{e.checked=!1,e.classList.remove("checked")}),n[e]);n.checked=!n.checked,n.classList.toggle("checked"),t||d._trigger(new x(null,[e,s[e]],a),i)};var e=n.domEl,o=document.createElement("div"),r=(o.className="lexradiogroup "+(a.className??""),document.createElement("span"));r.innerHTML=t,o.appendChild(r);const d=this;for(let t=0;t<s.length;++t){var c=document.createElement("div"),h=(c.className="lexradiogroupitem",o.appendChild(c),document.createElement("button")),u=(h.className="lexbutton",h.disabled=a.disabled??!1,c.appendChild(h),h.addEventListener("click",e=>{n.set(t,!1,e)}),document.createElement("span")),h=(h.appendChild(u),document.createElement("span"));h.innerHTML=s[t],c.appendChild(h)}return a.selected&&(console.assert(a.selected.constructor==Number,"RadioGroup _selected_ must be an Array index!"),l=a.selected,n.set(l,!0)),e.appendChild(o),n}addColor(n,s,i,e={}){s=s.constructor===Array?u(s):s;let t=this._createWidget(T.COLOR,n,s,e);t.onGetValue=()=>s,t.onSetValue=(e,t,a)=>{o.useRGB&&(e=h(e)),a&&r.set(e,!0,a),o.value=s=e,t||this._trigger(new x(n,e,a),i)};var a=t.domEl,l=document.createElement("span");l.className="lexcolor",l.style.width="calc( 100% - "+w.DEFAULT_NAME_WIDTH+")";let o=document.createElement("input");o.style.width="32px",o.type="color",o.className="colorinput",o.id="color"+y(),o.useRGB=e.useRGB??!1,o.value=o.iValue=s,e.disabled&&(o.disabled=!0),o.addEventListener("input",e=>{t.set(e.target.value,!1,e)},!1),l.appendChild(o),this.queue(l);const r=this.addText(null,o.value,e=>{t.set(e)},{width:"calc( 100% - 32px )"});return r.domEl.style.marginLeft="4px",this.clearQueue(),a.appendChild(l),t}addRange(n,s,i,l={}){let t=this._createWidget(T.RANGE,n,s,l);t.onGetValue=()=>s,t.onSetValue=(e,t,a)=>{isNaN(e)||(o.value=s=f(+e,+o.min,+o.max),t)||this._trigger(new x(n,l.left?+o.max-s+ +o.min:s,a),i)};var e=t.domEl,a=document.createElement("div");a.className="lexrange",a.style.width=l.inputWidth||"calc( 100% - "+w.DEFAULT_NAME_WIDTH+")";let o=document.createElement("input");return o.className="lexrangeslider "+(l.className??""),o.value=o.iValue=s,o.min=l.min,o.max=l.max,o.step=l.step??1,o.type="range",o.disabled=l.disabled??!1,l.left&&o.classList.add("left"),(l.fill??!0)||o.classList.add("no-fill"),o.addEventListener("input",e=>{t.set(e.target.valueAsNumber,!1,e)},{passive:!1}),o.addEventListener("mousedown",function(e){l.onPress&&l.onPress.bind(o)(e,o)},!1),o.addEventListener("mouseup",function(e){l.onRelease&&l.onRelease.bind(o)(e,o)},!1),t.setLimits=(e,t,a)=>{o.min=e??o.min,o.max=t??o.max,o.step=a??o.step,k._dispatch_event(o,"input",!0)},s.constructor==Number&&(s=f(s,+o.min,+o.max)),a.appendChild(o),e.appendChild(a),l.hideName&&(e.className+=" noname",a.style.width="100%"),t}addNumber(n,s,i,l={}){let o=this._createWidget(T.NUMBER,n,s,l);o.onGetValue=()=>s,o.onSetValue=(e,t,a)=>{isNaN(e)||(s=f(+e,+d.min,+d.max),d.value=s=E(s,l.precision),r.querySelector(".lexinputslider")&&(r.querySelector(".lexinputslider").value=s),l.units&&(d.unitSpan.style.left=v(s)+"px"),t)||this._trigger(new x(n,s,a),i)};var e,t=o.domEl,a=document.createElement("div");a.className="lexnumber",a.style.width=l.inputWidth||"calc( 100% - "+w.DEFAULT_NAME_WIDTH+")";let r=document.createElement("div"),d=(r.className="numberbox",document.createElement("input")),c=(d.id="number_"+y(),d.className="vecinput",d.min=l.min??-1e24,d.max=l.max??1e24,d.step=l.step??"any",d.type="number",s.constructor==Number&&(s=E(s=f(s,+d.min,+d.max),l.precision)),d.value=d.iValue=s,r.appendChild(d),l.units&&((e=document.createElement("span")).className="lexunit",e.innerText=l.units,e.style.left=v(d.value)+"px",d.unitSpan=e,r.appendChild(e)),document.createElement("a"));if(c.className="fa-solid fa-arrows-up-down drag-icon hidden",r.appendChild(c),l.disabled&&(d.disabled=!0),!l.skipSlider&&void 0!==l.min&&void 0!==l.max){let n=document.createElement("input");n.className="lexinputslider",n.min=l.min,n.max=l.max,n.step=l.step??1,n.type="range",n.value=s,n.addEventListener("input",function(e){o.set(this.valueAsNumber,!1,e)},!1),n.addEventListener("mousedown",function(e){l.onPress&&l.onPress.bind(n)(e,n)},!1),n.addEventListener("mouseup",function(e){l.onRelease&&l.onRelease.bind(n)(e,n)},!1),r.appendChild(n),o.setLimits=(e,t,a)=>{d.min=n.min=e??d.min,d.max=n.max=t??d.max,d.step=a??d.step,n.step=a??n.step,o.set(s,!0)}}d.addEventListener("input",function(e){s=E(s=+this.valueAsNumber,l.precision),l.units&&(d.unitSpan.style.left=v(d.value)+"px")},!1),d.addEventListener("wheel",function(t){if(t.preventDefault(),this===document.activeElement){let e=l.step??1;t.shiftKey?e*=10:t.altKey&&(e*=.1),s=+this.valueAsNumber-e*(0<t.deltaY?1:-1),o.set(s,!1,t)}},{passive:!1}),d.addEventListener("change",function(e){o.set(this.valueAsNumber,!1,e)},{passive:!1}),d.addEventListener("mousedown",function(e){var t;document.activeElement!=d&&((t=h.root.ownerDocument).addEventListener("mousemove",u),t.addEventListener("mouseup",p),document.body.classList.add("noevents"),c.classList.remove("hidden"),e.stopImmediatePropagation(),e.stopPropagation(),document.pointerLockElement||d.requestPointerLock(),l.onPress)&&l.onPress.bind(d)(e,d)});var h=this;function u(t){var a=-t.movementY;if(0!=a){let e=l.step??1;t.shiftKey?e*=10:t.altKey&&(e*=.1),s=+d.valueAsNumber+e*a,o.set(s,!1,t)}t.stopPropagation(),t.preventDefault()}function p(e){var t=h.root.ownerDocument;t.removeEventListener("mousemove",u),t.removeEventListener("mouseup",p),document.body.classList.remove("noevents"),c.classList.add("hidden"),document.pointerLockElement&&document.exitPointerLock(),l.onRelease&&l.onRelease.bind(d)(e,d)}return a.appendChild(r),t.appendChild(a),l.hideName&&(t.className+=" noname",a.style.width="100%"),o}static VECTOR_COMPONENTS={0:"x",1:"y",2:"z",3:"w"};_add_vector(t,s,i,l,o={}){t=f(t,2,4),i=i??new Array(t).fill(0);let r=this._createWidget(T.VECTOR,s,[].concat(i),o);r.onGetValue=()=>{var e,t=[];for(e of d.querySelectorAll("input"))t.push(+e.value);return t},r.onSetValue=(t,e,a)=>{if(c.length!=t.length)console.error("Input length does not match vector length.");else{for(let e=0;e<c.length;++e){var n;n=E(f(t[e],+c[e].min,+c[e].max),o.precision)??0,c[e].value=t[e]=n}e||this._trigger(new x(s,t,a),l)}};const d=r.domEl,c=[];var n=document.createElement("div");n.className="lexvector",n.style.width="calc( 100% - "+w.DEFAULT_NAME_WIDTH+")";for(let e=0;e<t;++e){var h=document.createElement("div");h.className="vecbox",h.innerHTML="<span class='"+k.VECTOR_COMPONENTS[e]+"'></span>";let s=document.createElement("input"),a=(s.className="vecinput v"+t,s.min=o.min??-1e24,s.max=o.max??1e24,s.step=o.step??"any",s.type="number",s.id="vec"+t+"_"+y(),s.idx=e,c[e]=s,i[e].constructor==Number&&(i[e]=f(i[e],+s.min,+s.max),i[e]=E(i[e],o.precision)),s.value=s.iValue=i[e],document.createElement("a"));a.className="fa-solid fa-arrows-up-down drag-icon hidden",h.appendChild(a),o.disabled&&(s.disabled=!0),s.addEventListener("wheel",function(t){if(t.preventDefault(),this===document.activeElement){let e=o.step??1;if(t.shiftKey?e=10:t.altKey&&(e=.1),v.locked)for(var a of d.querySelectorAll(".vecinput"))a.value=E(+a.valueAsNumber-e*(0<t.deltaY?1:-1),o.precision),k._dispatch_event(a,"change");else this.value=E(+this.valueAsNumber-e*(0<t.deltaY?1:-1),o.precision),k._dispatch_event(s,"change")}},{passive:!1}),s.addEventListener("change",e=>{if(!isNaN(e.target.value)){var t=E(f(e.target.value,+s.min,+s.max),o.precision);if(v.locked)for(var a of c)a.value=t,i[a.idx]=t;else s.value=t,i[e.target.idx]=t;r.set(i,!1,e)}},!1),s.addEventListener("mousedown",p);var u=this;function p(e){var t;document.activeElement!=s&&((t=u.root.ownerDocument).addEventListener("mousemove",m),t.addEventListener("mouseup",g),document.body.classList.add("noevents"),a.classList.remove("hidden"),e.stopImmediatePropagation(),e.stopPropagation(),document.pointerLockElement||s.requestPointerLock(),o.onPress)&&o.onPress.bind(s)(e,s)}function m(t){var a=-t.movementY;if(0!=a){let e=o.step??1;if(t.shiftKey?e=10:t.altKey&&(e=.1),v.locked)for(var n of d.querySelectorAll(".vecinput"))n.value=E(+n.valueAsNumber+e*a,o.precision),k._dispatch_event(n,"change");else s.value=E(+s.valueAsNumber+e*a,o.precision),k._dispatch_event(s,"change")}t.stopPropagation(),t.preventDefault()}function g(e){var t=u.root.ownerDocument;t.removeEventListener("mousemove",m),t.removeEventListener("mouseup",g),document.body.classList.remove("noevents"),a.classList.add("hidden"),document.pointerLockElement&&document.exitPointerLock(),o.onRelease&&o.onRelease.bind(s)(e,s)}h.appendChild(s),n.appendChild(h)}void 0===o.min&&void 0===o.max||(r.setLimits=(e,t,a)=>{for(var n of c)n.min=e??n.min,n.max=t??n.max,n.step=a??n.step;r.set(i,!0)});let v=document.createElement("a");return v.title="Lock",v.className="fa-solid fa-lock-open lexicon lock",n.appendChild(v),v.addEventListener("click",function(e){this.locked=!this.locked,this.locked?(this.classList.add("fa-lock"),this.classList.remove("fa-lock-open")):(this.classList.add("fa-lock-open"),this.classList.remove("fa-lock"))},!1),d.appendChild(n),r}addVector2(e,t,a,n){return this._add_vector(2,e,t,a,n)}addVector3(e,t,a,n){return this._add_vector(3,e,t,a,n)}addVector4(e,t,a,n){return this._add_vector(4,e,t,a,n)}addSize(e,t,i,a={}){let l=this._createWidget(T.SIZE,e,t,a);l.onGetValue=()=>{var t=[];for(let e=0;e<o.dimensions.length;++e)t.push(o.dimensions[e].value());return t},l.onSetValue=(t,a,e)=>{for(let e=0;e<o.dimensions.length;++e)o.dimensions[e].set(t[e],a)};const o=l.domEl;this.queue(o),o.aspectRatio=2==t.length?t[0]/t[1]:null,o.dimensions=[];for(let s=0;s<t.length;++s){var n;o.dimensions[s]=this.addNumber(null,t[s],e=>{var t,a,n=l.value();o.locked&&(t=0==s?1/o.aspectRatio:o.aspectRatio,n[a=(1+s)%2]=e*t,o.dimensions[a].set(n[a],!0)),i&&i(n)},{min:0,disabled:a.disabled,precision:a.precision}),s+1!=t.length&&((n=document.createElement("a")).className="lexsizecross fa-solid fa-xmark",o.appendChild(n))}this.clearQueue(),a.units&&((e=document.createElement("span")).className="lexunit",e.innerText=a.units,o.appendChild(e)),o.aspectRatio&&((e=document.createElement("a")).title="Lock Aspect Ratio",e.className="fa-solid fa-lock-open lexicon lock",o.appendChild(e),e.addEventListener("click",function(e){var t;o.locked=!o.locked,o.locked?(this.classList.add("fa-lock"),this.classList.remove("fa-lock-open"),t=l.value(),o.aspectRatio=t[0]/t[1]):(this.classList.add("fa-lock-open"),this.classList.remove("fa-lock"))},!1));e=!a.hideName;return e||(o.className+=" noname",container.style.width="100%"),l}addPad(s,e,i,a={}){var t=this._createWidget(T.PAD,s,null,a),n=(t.onGetValue=()=>r.value.xy,t.onSetValue=(e,t,a)=>{r.value.set(e[0],e[1]),d(r.value),t||this._trigger(new x(s,r.value.xy),i)},t.domEl),l=document.createElement("div");l.className="lexpad",l.style.width="calc( 100% - "+w.DEFAULT_NAME_WIDTH+")";let o=document.createElement("div"),r=(o.id="lexpad-"+s,o.className="lexinnerpad",o.style.width=a.padSize??"96px",o.style.height=a.padSize??"96px",document.createElement("div")),d=(r.className="lexpadthumb",r.value=new w.vec2(e[0],e[1]),r.min=a.min??0,r.max=a.max??1,e=>{var[t,a]=[o.offsetWidth,o.offsetHeight],e=new w.vec2(p(e.x,r.min,r.max,0,1),p(e.y,r.min,r.max,0,1));r.style.transform=`translate(calc( ${t*e.x}px - 50% ), calc( ${a*e.y}px - 50%)`}),c=(m(()=>{d(r.value)}),o.appendChild(r),l.appendChild(o),n.appendChild(l),o.addEventListener("mousedown",function(e){var t;document.activeElement!=r&&((t=c.root.ownerDocument).addEventListener("mousemove",h),t.addEventListener("mouseup",u),document.body.classList.add("nocursor"),document.body.classList.add("noevents"),e.stopImmediatePropagation(),e.stopPropagation(),a.onPress)&&a.onPress.bind(r)(e,r)}),this);function h(e){var t=o.getBoundingClientRect(),t=new w.vec2(e.x-t.x,e.y-t.y),[a,n]=(t.clp(0,o.offsetWidth,t),[o.offsetWidth,o.offsetHeight]),t=t.div(new w.vec2(o.offsetWidth,o.offsetHeight));r.style.transform=`translate(calc( ${a*t.x}px - 50% ), calc( ${n*t.y}px - 50%)`,r.value=new w.vec2(p(t.x,0,1,r.min,r.max),p(t.y,0,1,r.min,r.max)),c._trigger(new x(s,r.value.xy,e),i),e.stopPropagation(),e.preventDefault()}function u(e){var t=c.root.ownerDocument;t.removeEventListener("mousemove",h),t.removeEventListener("mouseup",u),document.body.classList.remove("nocursor"),document.body.classList.remove("noevents"),a.onRelease&&a.onRelease.bind(r)(e,r)}return t}addProgress(a,e,n={}){var t=this._createWidget(T.PROGRESS,a,e,n);t.onGetValue=()=>o.value,t.onSetValue=(e,t,a)=>{s.querySelector("meter").value=e,r(),s.querySelector("span")&&(s.querySelector("span").innerText=e)};const s=t.domEl;var i,l=document.createElement("div");l.className="lexprogress",l.style.width="calc( 100% - "+w.DEFAULT_NAME_WIDTH+")";let o=document.createElement("meter");o.id="lexprogressbar-"+a,o.className="lexprogressbar",o.step="any",o.min=n.min??0,o.max=n.max??1,o.low=n.low??o.low,o.high=n.high??o.high,o.optimum=n.optimum??o.optimum,o.value=e;const r=()=>{let e=w.getThemeColor("global-selected");null!=o.low&&o.value<o.low?e=w.getThemeColor("global-color-error"):null!=o.high&&o.value<o.high&&(e=w.getThemeColor("global-color-warning")),o.style.background=`color-mix(in srgb, ${e} 20%, transparent)`};if(l.appendChild(o),s.appendChild(l),n.showValue&&(document.getElementById("progressvalue-"+a)&&document.getElementById("progressvalue-"+a).remove(),(i=document.createElement("span")).id="progressvalue-"+a,i.style.padding="0px 5px",i.innerText=e,l.appendChild(i)),n.editable){o.classList.add("editable"),o.addEventListener("mousedown",function(e){var t=h.root.ownerDocument;t.addEventListener("mousemove",d),t.addEventListener("mouseup",c),document.body.classList.add("noevents"),o.classList.add("grabbing"),e.stopImmediatePropagation(),e.stopPropagation();t=o.getBoundingClientRect(),e=E(p(e.offsetX,0,t.width,o.min,o.max));h.setValue(a,e)});const h=this;function d(e){var t;0!=e.movementX&&(t=o.getBoundingClientRect(),t=E(p(e.offsetX-t.x,0,t.width,o.min,o.max)),h.setValue(a,t),n.callback)&&n.callback(t,e),e.stopPropagation(),e.preventDefault()}function c(e){var t=h.root.ownerDocument;t.removeEventListener("mousemove",d),t.removeEventListener("mouseup",c),document.body.classList.remove("noevents"),o.classList.remove("grabbing")}}return r(),t}addFile(e,a,n={}){var e=this._createWidget(T.FILE,e,null,n),t=e.domEl,s=n.local??!0;let i=n.type??"text",l=n.read??!0,o=document.createElement("input");if(o.className="lexfileinput",o.style.width="calc( 100% - "+w.DEFAULT_NAME_WIDTH+" - 10%)",o.type="file",o.disabled=n.disabled??!1,n.placeholder&&(o.placeholder=n.placeholder),o.addEventListener("change",function(e){const t=e.target.files;t.length&&(l?(n.onBeforeRead&&n.onBeforeRead(),e=new FileReader,"text"===i?e.readAsText(t[0]):"buffer"===i?e.readAsArrayBuffer(t[0]):"bin"===i?e.readAsBinaryString(t[0]):"url"===i&&e.readAsDataURL(t[0]),e.onload=e=>{a.call(this,e.target.result,t[0])}):a(t[0]))}),o.addEventListener("cancel",function(e){a(null)}),t.appendChild(o),this.queue(t),s){let t=null;this.addButton(null,"<a style='margin-top: 0px;' class='fa-solid fa-gear'></a>",()=>{t=t||new S("Load Settings",e=>{e.addDropdown("Type",["text","buffer","bin","url"],i,e=>{i=e}),e.addButton(null,"Reload",e=>{o.dispatchEvent(new Event("change"))})},{onclose:e=>{e.remove(),t=null}})},{className:"micro",skipInlineCount:!0,title:"Settings"})}return this.clearQueue(),e}addTree(e,t,a={}){a.hideName=!0;var n=this._createWidget(T.TREE,e,null,a).domEl,s=document.createElement("div"),i=(s.className="lextree",n.appendChild(s),e&&((n=document.createElement("span")).innerHTML=e,s.appendChild(n)),document.createElement("div"));if(i.className="lextreetools",e||(i.className+=" notitle"),a.icons)for(var l of a.icons){var o=document.createElement("a");o.title=l.name,o.className="lexicon "+l.icon,o.addEventListener("click",l.callback),i.appendChild(o)}a.filter=a.filter??!0;n=null,a.filter&&((n=document.createElement("input")).id="lexnodetree_filter",n.setAttribute("placeholder","Filter.."),n.style.width="calc( 100% - 17px )",n.addEventListener("input",function(){r.refresh()}),(e=document.createElement("a")).className="lexicon fa-solid fa-magnifying-glass",i.appendChild(n),i.appendChild(e)),(a.icons||a.filter)&&s.appendChild(i),n=document.createElement("ul");n.addEventListener("contextmenu",function(e){e.preventDefault()}),s.appendChild(n);const r=new N(s,t,a);return r}addSeparator(){var e=document.createElement("div"),t=(e.className="lexseparator",new T(T.SEPARATOR));t.domEl=e,this._currentBranch?(this._currentBranch.content.appendChild(e),this._currentBranch.widgets.push(t)):this.root.appendChild(e)}addTabs(n,e={}){var t=this._createWidget(T.TABS,null,null,e).domEl;if(n.constructor!=Array)throw"Param @tabs must be an Array!";var a=e.vertical??!0,s=!a&&(e.showNames??!1);let i=document.createElement("div"),l=(i.className="lextabscontainer",a||(i.className+=" horizontal"),document.createElement("div"));l.className="tabs",i.appendChild(l),t.appendChild(i);for(let e=0;e<n.length;++e){const r=n[e];console.assert(r.name);var o=0==e;let t=document.createElement("div"),a=(t.className="lextab "+(e==n.length-1?"last":"")+(o?"selected":""),t.innerHTML=(s?r.name:"")+"<a class='"+(r.icon||"fa fa-hashtag")+" "+(s?"withname":"")+"'></a>",t.title=r.name,document.createElement("div"));a.id=r.name.replace(/\s/g,""),a.className="widgets",o||a.toggleAttribute("hidden",!0),i.appendChild(a),t.addEventListener("click",e=>{l.querySelectorAll(".lextab").forEach(e=>{e.classList.remove("selected")}),t.classList.add("selected"),i.querySelectorAll(".widgets").forEach(e=>{e.toggleAttribute("hidden",!0)}),i.querySelector("#"+a.id).toggleAttribute("hidden"),r.onSelect&&r.onSelect(this,a)}),l.appendChild(t),r.onCreate&&(this.queue(a),r.onCreate(this,a),this.clearQueue())}this.addSeparator()}addCounter(n,e,s,t={}){let i=this._createWidget(T.COUNTER,n,e,t);i.onGetValue=()=>c.count,i.onSetValue=(e,t,a)=>{e=f(e,l,o),c.count=e,c.innerHTML=e,t||this._trigger(new x(n,e,a),s)};var a=i.domEl;const l=t.min??0,o=t.max??100,r=t.step??1;var d=document.createElement("div"),a=(d.className="lexcounter",a.appendChild(d),this.queue(d),this.addButton(null,"<a style='margin-top: 0px;' class='fa-solid fa-minus'></a>",(e,t)=>{let a=r??1;t.shiftKey&&(a*=10),i.set(c.count-a,!1,t)},{className:"micro",skipInlineCount:!0,title:"Minus"}),this.clearQueue(),document.createElement("div"));a.className="lexcounterbox",d.appendChild(a);const c=document.createElement("span");return c.className="lexcountervalue",c.innerHTML=e,c.count=e,a.appendChild(c),t.label&&((e=document.createElement("span")).className="lexcounterlabel",e.innerHTML=t.label,a.appendChild(e)),this.queue(d),this.addButton(null,"<a style='margin-top: 0px;' class='fa-solid fa-plus'></a>",(e,t)=>{let a=r??1;t.shiftKey&&(a*=10),i.set(c.count+a,!1,t)},{className:"micro",skipInlineCount:!0,title:"Plus"}),this.clearQueue(),i}addTable(e,f,E={}){if(!f)throw"Data is needed to create a table!";let y=this._createWidget(T.TABLE,e,null,E);y.onGetValue=()=>{},y.onSetValue=(e,t,a)=>{};var e=y.domEl,t=document.createElement("div");t.className="lextable",t.style.width="calc( 100% - "+w.DEFAULT_NAME_WIDTH+")";const b=document.createElement("table");function x(e,t,a,n){return a[e]<n[e]?-t:a[e]>n[e]?t:0}return t.appendChild(b),f.head=f.head??[],f.body=f.body??[],f.orderMap={},f.checkMap={},y.refreshTable=()=>{b.innerHTML="";var e,t,a=document.createElement("thead"),n=(a.className="lextablehead",b.appendChild(a),document.createElement("tr"));E.selectable&&(e=document.createElement("th"),(t=document.createElement("input")).type="checkbox",t.className="lexcheckbox",t.checked=f.checkMap[":root"]??!1,e.appendChild(t),t.addEventListener("change",function(){f.checkMap[":root"]=this.checked;for(const e of b.querySelector("tbody").childNodes)f.checkMap[e.getAttribute("rowId")]=this.checked,e.querySelector("input").checked=this.checked}),n.appendChild(e));for(const u of f.head){var s=document.createElement("th");s.innerHTML=u+' <a class="fa-solid fa-sort"></a>',s.querySelector("a").addEventListener("click",()=>{f.orderMap[u]||(f.orderMap[u]=1);var e=f.head.indexOf(u);f.body=f.body.sort(x.bind(this,e,f.orderMap[u])),f.orderMap[u]=-f.orderMap[u],y.refreshTable()}),n.appendChild(s)}E.rowActions&&((t=document.createElement("th")).className="sm",n.appendChild(t)),a.appendChild(n);var i=document.createElement("tbody");i.className="lextablebody",b.appendChild(i);for(let e=0;e<f.body.length;++e){var l,o=f.body[e];const p=document.createElement("tr"),m=w.getSupportedDOMName(o.join("-"));p.setAttribute("rowId",m),E.selectable&&(l=document.createElement("td"),(d=document.createElement("input")).type="checkbox",d.className="lexcheckbox",d.checked=f.checkMap[m],l.appendChild(d),d.addEventListener("change",function(){f.checkMap[m]=this.checked,this.checked||(b.querySelector("thead input[type='checkbox']").checked=f.checkMap[":root"]=!1)}),p.appendChild(l));for(const g of o){var r=document.createElement("td");r.innerHTML=""+g,p.appendChild(r)}if(E.rowActions){var d=document.createElement("td"),c=(d.className="sm",document.createElement("div"));c.className="lextablebuttons",d.appendChild(c);for(const v of E.rowActions){var h=document.createElement("a");h.className="lexicon","delete"==v?(h.className+=" fa-solid fa-trash-can",h.addEventListener("click",function(){f.body.splice(e,1),p.remove()})):"menu"==v?(h.className+=" fa-solid fa-ellipsis",h.addEventListener("click",function(e){A(null,e,e=>{E.onMenuAction?E.onMenuAction(e):console.warn("Using <Menu action> without action callbacks.")})})):(console.assert(v.constructor==Object),h.className+=" "+v.icon),c.appendChild(h)}p.appendChild(d)}i.appendChild(p)}},y.refreshTable(),E.hideName&&(e.className+=" noname",t.style.width="100%"),e.appendChild(t),y}}w.Panel=k;class a{constructor(e,t={}){this.name=e;var a=document.createElement("div"),n=(a.className="lexbranch",t.id&&(a.id=t.id),t.className&&(a.className+=" "+t.className),a.style.width="calc(100% - 7px)",a.style.margin="0 auto",this),s=(this.root=a,this.widgets=[],document.createElement("div")),i=(s.className="lexbranchtitle",t.icon&&(s.innerHTML="<a class='branchicon "+t.icon+"'>"),s.innerHTML+=e||"Branch",s.innerHTML+="<a class='fa-solid fa-angle-up switch-branch-button'></a>",a.appendChild(s),document.createElement("div"));i.id=e.replace(/\s/g,""),i.className="lexbranchcontent",a.appendChild(i),this.content=i,this._addBranchSeparator(),t.closed&&(s.className+=" closed",a.className+=" closed",this.grabber.setAttribute("hidden",!0),m(()=>{this.content.setAttribute("hidden",!0)},15)),this.onclick=function(e){e.stopPropagation(),this.classList.toggle("closed"),this.parentElement.classList.toggle("closed"),n.content.toggleAttribute("hidden"),n.grabber.toggleAttribute("hidden"),w.emit("@on_branch_closed",this.classList.contains("closed"),{target:n.panel})},this.oncontextmenu=function(t){t.preventDefault(),t.stopPropagation(),this.parentElement.classList.contains("dialog")||A("Dock",t,e=>{t.preventDefault(),e.add("Floating",n._on_make_floating.bind(n))},{icon:"fa-regular fa-window-restore"})},s.addEventListener("click",this.onclick),s.addEventListener("contextmenu",this.oncontextmenu)}_on_make_floating(){new S(this.name,e=>{for(var t of this.widgets)e.root.appendChild(t.domEl)}).widgets=this.widgets;var e=this.root.parentElement,t=(this.root.remove(),e.querySelector(".lexbranch")),t=(t&&t.classList.add("first"),e.querySelectorAll(".lexbranch"));t.length&&t[t.length-1].classList.add("last")}_addBranchSeparator(){var e=document.createElement("div");e.className="lexwidgetseparator",e.style.width="100%",e.style.background="none";const a=document.createElement("div"),n=(a.innerHTML="&#9662;",e.appendChild(a),m(()=>{a.style.marginLeft=parseFloat(w.DEFAULT_NAME_WIDTH)/100*this.content.offsetWidth+"px"},10),document.createElement("div"));n.style.width="1px",n.style.marginLeft="6px",n.style.marginTop="2px",n.style.height="0px",a.appendChild(n),a.addEventListener("mousedown",function(e){var t=s.root.ownerDocument;t.addEventListener("mouseup",l),t.addEventListener("mousemove",i),e.stopPropagation(),e.preventDefault();t=s.root.offsetHeight-s.root.children[0].offsetHeight;n.style.height=t-3+"px",document.body.classList.add("nocursor")}),this.grabber=a;let s=this;function i(e){var t,e=e.movementX;0!=e&&(t=parseFloat(a.style.marginLeft),a.style.marginLeft=f(t+e,32,s.content.offsetWidth-32)+"px")}function l(e){s._updateWidgets(),n.style.height="0px";var t=s.root.ownerDocument;t.removeEventListener("mouseup",l),t.removeEventListener("mousemove",i),document.body.classList.remove("nocursor")}this.content.appendChild(e)}_updateWidgets(){for(var t=this.grabber.style.marginLeft,e=0;e<this.widgets.length;e++){var a=this.widgets[e],n=a.domEl;if(!(n.children.length<2)){var s=n.children[0],n=n.children[1];s.style.width=t;let e="0px";a.type===T.FILE&&(e="10%"),n.style.width="-moz-calc( 100% - "+t+" - "+e+" )",n.style.width="-webkit-calc( 100% - "+t+" - "+e+" )",n.style.width="calc( 100% - "+t+" - "+e+" )",a.onresize&&a.onresize()}}}}w.Branch=a;w.Footer=class{constructor(e={}){var t=document.createElement("footer"),a=(t.className="lexfooter",document.createElement("div"));if(a.className="wrapper",t.appendChild(a),e.columns&&e.columns.constructor==Array){var n,s=document.createElement("div");s.className="columns",s.style.gridTemplateColumns="1fr ".repeat(e.columns.length),a.appendChild(s);for(n of e.columns){var i=document.createElement("div"),l=(i.className="col",s.appendChild(i),document.createElement("h2"));if(l.innerHTML=n.title,i.appendChild(l),n.items&&n.items.length){var o,r=document.createElement("ul");i.appendChild(r);for(o of n.items){var d=document.createElement("li");d.innerHTML=`<a class="" href="${o.link}">${o.title}</a>`,r.appendChild(d)}}}}if(e.credits||e.socials){var c=document.createElement("hr"),c=(a.appendChild(c),document.createElement("div"));if(c.className="credits-and-socials",a.appendChild(c),e.credits&&((a=document.createElement("p")).innerHTML=e.credits,c.appendChild(a)),e.socials){var h,u=document.createElement("div");u.className="social";for(h of e.socials){var p=document.createElement("a");p.title=h.title,p.innerHTML=h.icon,p.href=h.link,p.target="_blank",u.appendChild(p)}c.appendChild(u)}}(e.parent??document.body).appendChild(t)}};class S{static _last_id=0;constructor(l,e,t={}){e||console.warn("Content is empty, add some widgets using 'callback' parameter!"),this._oncreate=e,this.id=y();const a=t.size??[],n=t.position??[],s=t.draggable??!0,i=t.modal??!1;var o=document.createElement("dialog");o.className="lexdialog "+(t.className??""),o.id=t.id??"dialog"+S._last_id++,w.root.appendChild(o),m(()=>{i?o.showModal():o.show()},10);let r=this,d=document.createElement("div"),c;l&&(d.className="lexdialogtitle",d.innerHTML=l,d.setAttribute("draggable",!1),d.oncontextmenu=function(i){i.preventDefault(),i.stopPropagation(),w.main_area&&"horizontal"===w.main_area.type&&A("Dock",i,e=>{i.preventDefault();function n(e){let t=e.panels[0];if(t)return t;for(var a of e.sections)if(t=n(a))return t}function t(e){let t=e.branches.find(e=>e.name===l);t?e.root.appendChild(t.root):(e.branch(l),t=e.branches.find(e=>e.name===l));for(var a of r.widgets)t.content.appendChild(a.domEl);t.widgets=r.widgets,e.root.querySelectorAll(".lexbranch.last").forEach(e=>{e.classList.remove("last")}),t.root.classList.add("last"),o.remove()}let a=n(w.main_area.sections[1]),s=(e.add('<i class="fa-regular fa-window-maximize fa-window-maximize fa-rotate-90">',{disabled:!a,id:"dock_options0",callback:()=>{t(a)}}),n(w.main_area.sections[0]));e.add('<i class="fa-regular fa-window-maximize fa-window-maximize fa-rotate-270">',{disabled:!s,id:"dock_options1",callback:()=>{t(s)}})},{icon:"fa-regular fa-window-restore"})},o.appendChild(d)),(t.closable??!0)&&(this.close=()=>{t.onBeforeClose&&t.onBeforeClose(this),t.onclose?t.onclose(this.root):(o.close(),m(()=>{r.panel.clear(),o.remove()},150))},(c=document.createElement("a")).className="lexdialogcloser fa-solid fa-xmark",c.title="Close",c.addEventListener("click",this.close),(l?d:(c.classList.add("notitle"),o)).appendChild(c));var h=new k;h.root.classList.add("lexdialogcontent"),l||h.root.classList.add("notitle"),e&&e.call(this,h),o.appendChild(h.root),h.root.querySelectorAll(".lexbranch").forEach(e=>e.classList.add("dialog")),this.panel=h,this.root=o,this.title=d,s&&b(o,Object.assign({targetClass:"lexdialogtitle"},t)),a.length&&"string"!=typeof a[0]&&(a[0]+="px"),a.length&&"string"!=typeof a[1]&&(a[1]+="px"),o.style.width=a[0]||"25%",o.style.height=a[1]||"auto",o.style.translate=t.position?"unset":"-50% -50%",t.size&&(this.size=a),o.style.left=n[0]??"50%",o.style.top=n[1]??"50%",h.root.style.width="calc( 100% - 30px )",h.root.style.height=l?"calc( 100% - "+(d.offsetHeight+30)+"px )":"calc( 100% - 51px )"}destroy(){this.root.remove()}refresh(){this.panel.root.innerHTML="",this._oncreate.call(this,this.panel)}setPosition(e,t){this.root.style.left=e+"px",this.root.style.top=t+"px"}setTitle(e){var t=this.root.querySelector(".lexdialogtitle");t&&(t.innerText=e)}}w.Dialog=S;class o extends S{static TOP=0;static BOTTOM=1;constructor(e,t,a={}){a.draggable=a.draggable??!1,a.closable=a.closable??!1;super(e,t,a);let n=this;if(w.addSignal("@on_branch_closed",this.panel,e=>{this.dock_pos==o.BOTTOM&&(this.root.style.top="calc(100% - "+(this.root.offsetHeight+3)+"px)")}),this.root.classList.add("pocket"),this.root.style.translate="none",this.root.style.top="0",this.root.style.left="unset",a.position||(this.root.style.right="3px",this.root.style.top="3px"),this.panel.root.style.width="calc( 100% - 12px )",this.panel.root.style.height="calc( 100% - 40px )",this.dock_pos=o.TOP,this.minimized=!1,this.title.tabIndex=-1,this.title.addEventListener("click",e=>{this.title._eventCatched?this.title._eventCatched=!1:(this.size&&(this.minimized?this.root.style.height=this.size[1]:this.root.style.height="auto"),this.root.classList.toggle("minimized"),this.minimized=!this.minimized,this.dock_pos==o.BOTTOM&&(n.root.style.top=this.root.classList.contains("minimized")?"calc(100% - "+(n.title.offsetHeight+6)+"px)":"calc(100% - "+(n.root.offsetHeight+3)+"px)"))}),!a.draggable){var s=a.float;if(s)for(var i=0;i<s.length;i++)switch(s[i]){case"b":this.root.style.top="calc(100% - "+(this.root.offsetHeight+3)+"px)";break;case"l":this.root.style.right="unset",this.root.style.left=a.position?a.position[1]:"3px"}this.root.classList.add("dockable"),this.title.addEventListener("keydown",function(e){e.ctrlKey&&(n.root.style.right="unset","ArrowLeft"==e.key?n.root.style.left="0px":"ArrowRight"==e.key?n.root.style.left="calc(100% - "+(n.root.offsetWidth+3)+"px)":"ArrowUp"==e.key?(n.root.style.top="0px",n.dock_pos=o.TOP):"ArrowDown"==e.key&&(n.root.style.top="calc(100% - "+(n.root.offsetHeight+3)+"px)",n.dock_pos=o.BOTTOM))})}}}w.PocketDialog=o;class i{constructor(e,t,a={}){document.body.querySelectorAll(".lexcontextmenu").forEach(e=>e.remove()),this.root=document.createElement("div"),this.root.className="lexcontextmenu",this.root.style.left=e.x-48+document.scrollingElement.scrollLeft+"px",this.root.style.top=e.y-8+document.scrollingElement.scrollTop+"px",this.root.addEventListener("mouseleave",function(){this.remove()}),this.items=[],this.colors={},t&&((e={})[t]=[],e.className="cmtitle",e.icon=a.icon,this.items.push(e))}_adjustPosition(e,t,a=!1){var n=e.getBoundingClientRect();a?((a=window.innerWidth-n.right)<0&&(e.style.left=e.offsetLeft+(a-t)+"px"),(a=window.innerHeight-(n.top+n.height))<0&&(e.style.top=e.offsetTop+(a-t+20)+"px")):(a=n.width,n.left<0?e.style.left=t+"px":window.innerWidth-n.right<0&&(e.style.left=window.innerWidth-a-t+"px"),n.top<0?e.style.top=t+"px":n.top+n.height>window.innerHeight&&(e.style.top=window.innerHeight-n.height-t+"px"))}_createSubmenu(e,t,a,n){this.root.querySelectorAll(".lexcontextmenu").forEach(e=>e.remove());var s=document.createElement("div");s.className="lexcontextmenu",a.appendChild(s);for(var i=0;i<e[t].length;++i){var l=e[t][i],o=Object.keys(l)[0];this._createEntry(l,o,s,n)}var r=a.getBoundingClientRect();s.style.left=r.width+"px",s.style.marginTop=3.5-a.offsetHeight+"px",this._adjustPosition(s,6,!0)}_createEntry(t,a,e,n){const s=t[a].length;let i=document.createElement("div");i.className="lexmenuboxentry"+(t.className?" "+t.className:""),i.id=t.id??"eId"+c(a),i.innerHTML="";var l=t.icon;l&&(i.innerHTML+="<a class='"+l+" fa-sm'></a>");const o=t.disabled;i.innerHTML+="<div class='lexentryname"+(o?" disabled":"")+"'>"+a+"</div>",e.appendChild(i),this.colors[a]&&(i.style.borderColor=this.colors[a]),""==a?i.className+=" cmseparator":(i.addEventListener("click",e=>{e.stopPropagation(),e.stopImmediatePropagation(),o||((e=t.callback)&&(e.call(this,a,i),this.root.remove()),s&&"click"==w.OPEN_CONTEXTMENU_ENTRY&&this._createSubmenu(t,a,i,++n))}),s&&((l=document.createElement("a")).className="fa-solid fa-bars-staggered fa-xs",i.appendChild(l),"mouseover"==w.OPEN_CONTEXTMENU_ENTRY&&i.addEventListener("mouseover",e=>{i.built||(i.built=!0,this._createSubmenu(t,a,i,++n),e.stopPropagation())}),i.addEventListener("mouseleave",()=>{n=-1,e.querySelectorAll(".lexcontextmenu").forEach(e=>e.remove())})))}onCreate(){m(()=>this._adjustPosition(this.root,6))}add(e,i={}){i.constructor==Function&&(i={callback:i});const l=(e+="").split("/");var t,a,e=l[l.length-1];this.colors[e]=i.color;let o=0;const r=(n,e)=>{if(null!=n){let a=null;var t,s;e.forEach(e=>{var t=Object.keys(e).find(e=>e==n);t&&(a=e[t])}),a?r(l[o++],a):((t={})[n]=[],(s=l[o++])||(t.id=i.id,t.callback=i.callback,t.disabled=i.disabled??!1),e.push(t),r(s,t[n]))}},d=(r(l[o++],this.items),e=>{let t=Object.keys(e)[0];var a,n=e[t];if(n.length){null==n.find(e=>Object.keys(e)[0]==t)&&((n={})[t]=[],n.className="cmtitle",e[t].unshift(n));for(a of e[t])for(var s=Object.keys(a)[0],i=0;i<a[s].length;++i)d(a)}});for(t of this.items)d(t);for(a of this.items){var n=Object.keys(a)[0],s="eId"+c(n),s="#"+(a.id??s);this.root.querySelector(s)||this._createEntry(a,n,this.root,-1)}}setColor(e,t){"#"!==t[0]&&(t=u(t)),this.colors[e]=t}}function A(e,t,a,n){t=new i(t,e,n);return w.root.appendChild(t.root),a&&a(t),t.onCreate(),t}w.ContextMenu=i,w.addContextMenu=A;class D{constructor(e,t,a={}){let o=document.createElement("div"),r=(o.className="curve "+(a.className||""),o.style.minHeight="50px",o.style.width=a.width||"100%",o.style.minWidth="50px",o.style.minHeight="20px",o.bgcolor=a.bgColor||w.getThemeColor("global-intense-background"),o.pointscolor=a.pointsColor||w.getThemeColor("global-selected-light"),o.linecolor=a.lineColor||"#555",o.value=t||[],o.xrange=a.xrange||[0,1],o.yrange=a.yrange||[0,1],o.defaulty=null!=a.defaulty?a.defaulty:0,o.no_overlap=a.noOverlap||!1,o.show_samples=a.showSamples||0,o.allow_add_values=a.allowAddValues??!0,o.draggable_x=a.draggableX??!0,o.draggable_y=a.draggableY??!0,o.smooth=(a.smooth&&"number"==typeof a.smooth?a.smooth:.3)||!1,o.move_out=a.moveOutAction??w.CURVE_MOVEOUT_DELETE,w.addSignal("@on_new_color_scheme",(e,t)=>{o.bgcolor=a.bgColor||w.getThemeColor("global-intense-background"),o.pointscolor=a.pointsColor||w.getThemeColor("global-selected-light"),this.redraw()}),this.element=o,document.createElement("canvas"));function l(e){return[r.width*(e[0]-o.xrange[0])/o.xrange[1],r.height*(e[1]-o.yrange[0])/o.yrange[1]]}function d(e){return[e[0]*o.xrange[1]/r.width+o.xrange[0],e[1]*o.yrange[1]/r.height+o.yrange[0]]}r.width=a.width||200,r.height=a.height||50,o.appendChild(r),this.canvas=r,o.addEventListener("mousedown",function(e){document.addEventListener("mousemove",s),document.addEventListener("mouseup",u);var t=r.getBoundingClientRect(),a=e.clientX-t.left,t=e.clientY-t.top;{var n;c=function(e,t){for(var a=1e5,n=-1,s=0;s<o.value.length;s++){var i=l(o.value[s]),i=m([e,t],i);i<a&&i<8&&(a=i,n=s)}return n}(a,r.height-t),e.button==w.MOUSE_LEFT_CLICK&&-1==c&&o.allow_add_values&&(n=d([a,r.height-t]),o.value.push(n),g(),c=o.value.indexOf(n))}h=[a,t],o.redraw(),e.preventDefault(),e.stopPropagation()}),o.getValueAt=function(e){if(e<o.xrange[0]||e>o.xrange[1])return o.defaulty;for(var t=[o.xrange[0],o.defaulty],a=0,n=0;n<o.value.length;n+=1){var s=o.value[n];if(e==s[0])return s[1];if(e<s[0])return a=(e-t[0])/(s[0]-t[0]),t[1]*(1-a)+s[1]*a;t=s}return s=[o.xrange[1],o.defaulty],a=(e-t[0])/(s[0]-t[0]),t[1]*(1-a)+s[1]*a},o.resample=function(e){for(var t=[],a=(o.xrange[1]-o.xrange[0])/e,n=o.xrange[0];n<=o.xrange[1];n+=a)t.push(o.getValueAt(n));return t},o.addValue=function(e){for(var t=0;t<o.value;t++){var a=o.value[t];if(!(a[0]<e[0]))return o.value.splice(t,0,e),void redraw()}o.value.push(e),redraw()};var c=-1,h=(o.redraw=function(e={}){e.value&&(o.value=e.value),e.xrange&&(o.xrange=e.xrange),e.yrange&&(o.yrange=e.yrange),e.smooth&&(o.smooth=e.smooth);var e=r.parentElement.getBoundingClientRect(),t=((e=r.parentElement.parentElement?r.parentElement.parentElement.getBoundingClientRect():e)&&r.width!=e.width&&e.width&&e.width<1e3&&(r.width=e.width),r.getContext("2d")),a=(t.setTransform(1,0,0,1,0,0),t.translate(0,r.height),t.scale(1,-1),t.fillStyle=o.bgcolor,t.fillRect(0,0,r.width,r.height),t.strokeStyle=o.linecolor,t.beginPath(),l([o.xrange[0],o.defaulty])),n=(t.moveTo(a[0],a[1]),[a[0],a[1]]);for(s in o.value){a=l(o.value[s]);n.push(a[0]),n.push(a[1]),o.smooth||t.lineTo(a[0],a[1])}a=l([o.xrange[1],o.defaulty]),n.push(a[0]),n.push(a[1]),o.smooth?w.UTILS.drawSpline(t,n,o.smooth):(t.lineTo(a[0],a[1]),t.stroke());for(var s=0;s<o.value.length;s+=1)a=l(o.value[s]),t.fillStyle=c==s?"white":o.pointscolor,t.beginPath(),t.arc(a[0],a[1],c==s?4:3,0,2*Math.PI),t.fill();if(o.show_samples){var i=o.resample(o.show_samples);t.fillStyle="#888";for(s=0;s<i.length;s+=1)a=l([s*((o.xrange[1]-o.xrange[0])/o.show_samples)+o.xrange[0],i[s]]),t.beginPath(),t.arc(a[0],a[1],2,0,2*Math.PI),t.fill()}},[0,0]);function s(e){var t,a,n,s=r.getBoundingClientRect(),i=e.clientX-s.left,l=e.clientY-s.top,s=(i<0?i=0:i>r.width&&(i=r.width),l<0?l=0:l>r.height&&(l=r.height),[e.clientX-s.left,e.clientY-s.top]);-1!=c&&m(s,[i,l])>.5*r.height?(o.move_out==w.CURVE_MOVEOUT_DELETE?o.value.splice(c,1):(s=[s[0]-i,s[1]-l],(t=o.value[c])[0]=0==s[0]?t[0]:s[0]<0?o.xrange[0]:o.xrange[1],t[1]=0==s[1]?t[1]:s[1]<0?o.yrange[1]:o.yrange[0]),u(e)):(t=d([-(o.draggable_x?h[0]-i:0),o.draggable_y?h[1]-l:0]),-1!=c&&(s=o.xrange[0],a=o.xrange[1],o.no_overlap&&(0<c&&(s=o.value[c-1][0]),c<o.value.length-1)&&(a=o.value[c+1][0]),(n=o.value[c])[0]+=t[0],n[1]+=t[1],n[0]<s?n[0]=s:n[0]>a&&(n[0]=a),n[1]<o.yrange[0]?n[1]=o.yrange[0]:n[1]>o.yrange[1]&&(n[1]=o.yrange[1])),g(),o.redraw(),h[0]=i,h[1]=l,p(e),e.preventDefault(),e.stopPropagation())}function u(e){c=-1,o.redraw(),document.removeEventListener("mousemove",s),document.removeEventListener("mouseup",u),p(e),e.preventDefault(),e.stopPropagation()}function p(e){a.callback&&a.callback.call(o,o.value,e)}function m(e,t){return Math.sqrt(Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2))}function g(){var e=null;-1!=c&&(e=o.value[c]),o.value.sort(function(e,t){return e[0]-t[0]}),e&&(c=o.value.indexOf(e))}return o.redraw(),this}redraw(e={}){this.element.redraw(e)}}w.Curve=D;class M{constructor(e,t,a={}){let o=document.createElement("div"),r=(o.className="dial "+(a.className||""),o.style.width=o.style.height=a.size||"100%",o.style.minWidth=o.style.minHeight="50px",o.bgcolor=a.bgColor||w.getThemeColor("global-dark-background"),o.pointscolor=a.pointsColor||w.getThemeColor("global-selected-light"),o.linecolor=a.lineColor||"#555",o.value=t||[],o.xrange=a.xrange||[0,1],o.yrange=a.yrange||[0,1],o.defaulty=null!=a.defaulty?a.defaulty:0,o.no_overlap=a.noOverlap||!1,o.show_samples=a.showSamples||0,o.allow_add_values=a.allowAddValues??!0,o.draggable_x=a.draggableX??!0,o.draggable_y=a.draggableY??!0,o.smooth=(a.smooth&&"number"==typeof a.smooth?a.smooth:.3)||!1,o.move_out=a.moveOutAction??w.CURVE_MOVEOUT_DELETE,this.element=o,document.createElement("canvas"));function l(e){return Math.pow(e[0],2),[r.width*(e[0]-o.xrange[0])/o.xrange[1],r.height*(e[1]-o.yrange[0])/o.yrange[1]]}function d(e){return[e[0]*o.xrange[1]/r.width+o.xrange[0],e[1]*o.yrange[1]/r.height+o.yrange[0]]}r.width=r.height=a.size||200,o.appendChild(r),this.canvas=r,o.addEventListener("mousedown",function(e){document.addEventListener("mousemove",s),document.addEventListener("mouseup",u);var t=r.getBoundingClientRect(),a=e.clientX-t.left,t=e.clientY-t.top;{var n;c=function(e,t){for(var a=1e5,n=-1,s=0;s<o.value.length;s++){var i=l(o.value[s]),i=m([e,t],i);i<a&&i<8&&(a=i,n=s)}return n}(a,r.height-t),e.button==w.MOUSE_LEFT_CLICK&&-1==c&&o.allow_add_values&&(n=d([a,r.height-t]),o.value.push(n),g(),c=o.value.indexOf(n))}h=[a,t],o.redraw(),e.preventDefault(),e.stopPropagation()}),o.getValueAt=function(e){if(e<o.xrange[0]||e>o.xrange[1])return o.defaulty;for(var t=[o.xrange[0],o.defaulty],a=0,n=0;n<o.value.length;n+=1){var s=o.value[n];if(e==s[0])return s[1];if(e<s[0])return a=(e-t[0])/(s[0]-t[0]),t[1]*(1-a)+s[1]*a;t=s}return s=[o.xrange[1],o.defaulty],a=(e-t[0])/(s[0]-t[0]),t[1]*(1-a)+s[1]*a},o.resample=function(e){for(var t=[],a=(o.xrange[1]-o.xrange[0])/e,n=o.xrange[0];n<=o.xrange[1];n+=a)t.push(o.getValueAt(n));return t},o.addValue=function(e){for(var t=0;t<o.value;t++){var a=o.value[t];if(!(a[0]<e[0]))return o.value.splice(t,0,e),void redraw()}o.value.push(e),redraw()};var c=-1,h=(o.redraw=function(e={}){e.value&&(o.value=e.value),e.xrange&&(o.xrange=e.xrange),e.yrange&&(o.yrange=e.yrange),e.smooth&&(o.smooth=e.smooth);var e=r.parentElement.getBoundingClientRect(),t=((e=r.parentElement.parentElement?r.parentElement.parentElement.getBoundingClientRect():e)&&r.width!=e.width&&e.width&&e.width<1e3&&(r.width=e.width),r.getContext("2d")),a=(t.setTransform(1,0,0,1,0,0),t.translate(0,r.height),t.scale(1,-1),t.fillStyle=o.bgcolor,t.fillRect(0,0,r.width,r.height),t.strokeStyle=o.linecolor,t.beginPath(),l([o.xrange[0],o.defaulty])),n=(t.moveTo(a[0],a[1]),[a[0],a[1]]);for(s in o.value){a=l(o.value[s]);n.push(a[0]),n.push(a[1])}a=l([o.xrange[1],o.defaulty]),n.push(a[0]),n.push(a[1]);a=l([0,0]),t.fillStyle="gray",t.beginPath(),t.arc(a[0],a[1],3,0,2*Math.PI),t.fill();for(var s=0;s<o.value.length;s+=1)a=l(o.value[s]),t.fillStyle=c==s?"white":o.pointscolor,t.beginPath(),t.arc(a[0],a[1],c==s?4:3,0,2*Math.PI),t.fill();if(o.show_samples){var i=o.resample(o.show_samples);t.fillStyle="#888";for(s=0;s<i.length;s+=1)a=l([s*((o.xrange[1]-o.xrange[0])/o.show_samples)+o.xrange[0],i[s]]),t.beginPath(),t.arc(a[0],a[1],2,0,2*Math.PI),t.fill()}},[0,0]);function s(e){var t,a,n,s=r.getBoundingClientRect(),i=e.clientX-s.left,l=e.clientY-s.top,s=(i<0?i=0:i>r.width&&(i=r.width),l<0?l=0:l>r.height&&(l=r.height),[e.clientX-s.left,e.clientY-s.top]);-1!=c&&m(s,[i,l])>.5*r.height?(o.move_out==w.CURVE_MOVEOUT_DELETE?o.value.splice(c,1):(s=[s[0]-i,s[1]-l],(t=o.value[c])[0]=0==s[0]?t[0]:s[0]<0?o.xrange[0]:o.xrange[1],t[1]=0==s[1]?t[1]:s[1]<0?o.yrange[1]:o.yrange[0]),u(e)):(t=d([-(o.draggable_x?h[0]-i:0),o.draggable_y?h[1]-l:0]),-1!=c&&(s=o.xrange[0],a=o.xrange[1],o.no_overlap&&(0<c&&(s=o.value[c-1][0]),c<o.value.length-1)&&(a=o.value[c+1][0]),(n=o.value[c])[0]+=t[0],n[1]+=t[1],n[0]<s?n[0]=s:n[0]>a&&(n[0]=a),n[1]<o.yrange[0]?n[1]=o.yrange[0]:n[1]>o.yrange[1]&&(n[1]=o.yrange[1])),g(),o.redraw(),h[0]=i,h[1]=l,p(e),e.preventDefault(),e.stopPropagation())}function u(e){c=-1,o.redraw(),document.removeEventListener("mousemove",s),document.removeEventListener("mouseup",u),p(e),e.preventDefault(),e.stopPropagation()}function p(e){a.callback&&a.callback.call(o,o.value,e)}function m(e,t){return Math.sqrt(Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2))}function g(){var e=null;-1!=c&&(e=o.value[c]),o.value.sort(function(e,t){return e[0]-t[0]}),e&&(c=o.value.indexOf(e))}return o.redraw(),this}redraw(e={}){this.element.redraw(e)}}w.Dial=M;class P{static NONE=0;static ASSET_SELECTED=1;static ASSET_DELETED=2;static ASSET_RENAMED=3;static ASSET_CLONED=4;static ASSET_DBLCLICKED=5;static ENTER_FOLDER=6;static ASSET_CHECKED=7;constructor(e,t,a){this.type=e||L.NONE,this.item=t,this.value=a,this.multiple=!1}string(){switch(this.type){case P.NONE:return"assetview_event_none";case P.ASSET_SELECTED:return"assetview_event_selected";case P.ASSET_DELETED:return"assetview_event_deleted";case P.ASSET_RENAMED:return"assetview_event_renamed";case P.ASSET_CLONED:return"assetview_event_cloned";case P.ASSET_DBLCLICKED:return"assetview_event_dblclicked";case P.ENTER_FOLDER:return"assetview_event_enter_folder";case P.ASSET_CHECKED:return"assetview_event_checked"}}}w.AssetViewEvent=P;class O{static LAYOUT_CONTENT=0;static LAYOUT_LIST=1;static MAX_PAGE_ELEMENTS=50;constructor(e={}){this.rootPath="https://raw.githubusercontent.com/jxarco/lexgui.js/master/",this.layout=e.layout??O.LAYOUT_CONTENT,this.contentPage=1,e.rootPath&&(e.rootPath.constructor!==String?console.warn("Asset Root Path must be a String (now is "+path.constructor.name+")"):this.rootPath=e.rootPath);var t=document.createElement("div"),a=(t.className="lexassetbrowser",this.root=t,new w.Area({height:"100%"}));t.appendChild(a.root);let n,s,i=a;this.skipBrowser=e.skipBrowser??!1,this.skipPreview=e.skipPreview??!1,this.useNativeTitle=e.useNativeTitle??!1,this.onlyFolders=e.onlyFolders??!0,this.allowMultipleSelection=e.allowMultipleSelection??!1,this.previewActions=e.previewActions??[],this.contextMenu=e.contextMenu??[],this.onRefreshContent=e.onRefreshContent,this.skipBrowser||([n,s]=a.split({type:"horizontal",sizes:["15%","85%"]}),i=s,n.setLimitBox(210,0),s.setLimitBox(512,0)),this.skipPreview||([i,s]=i.split({type:"horizontal",sizes:["80%","20%"]})),this.allowedTypes=e.allowedTypes||["None","Image","Mesh","Script","JSON","Clip"],this.prevData=[],this.nextData=[],this.data=[],this._processData(this.data,null),this.currentData=this.data,this.path=["@"],this.skipBrowser||this._createTreePanel(n),this._createContentPanel(i),this.skipPreview||(this.previewPanel=s.addPanel({className:"lexassetcontentpanel",style:{overflow:"scroll"}}))}load(e,t){this.prevData.length=0,this.nextData.length=0,this.data=e,this._processData(this.data,null),this.currentData=this.data,this.path=["@"],this.skipBrowser||this._createTreePanel(this.area),this._refreshContent(),this.onevent=t}clear(){this.previewPanel&&this.previewPanel.clear(),this.leftPanel&&this.leftPanel.clear(),this.rightPanel&&this.rightPanel.clear()}_processData(e,t){e.constructor!==Array&&(e.folder=t,e.children=e.children??[]);for(var a=e.constructor===Array?e:e.children,n=0;n<a.length;++n)this._processData(a[n],e)}_updatePath(e){this.path.length=0;const t=e=>{e&&(e=(e.children||e)[0])&&e.folder&&(this.path.push(e.folder.id??"@"),t(e.folder.folder))};t(e),w.emit("@on_folder_change",this.path.reverse().join("/"))}_createTreePanel(e){this.leftPanel?this.leftPanel.clear():this.leftPanel=e.addPanel({className:"lexassetbrowserpanel"});e={id:"/",children:this.data};this.tree=this.leftPanel.addTree("Content Browser",e,{filter:!1,onlyFolders:this.onlyFolders,onevent:e=>{var t=e.node,a=e.value;switch(e.type){case w.TreeEvent.NODE_SELECTED:e.multiple||this._enterFolder(t),t.parent||(this.prevData.push(this.currentData),this.currentData=this.data,this._refreshContent(),this.path=["@"],w.emit("@on_folder_change",this.path.join("/")));break;case w.TreeEvent.NODE_DRAGGED:t.folder=a,this._refreshContent()}}})}_setContentLayout(e){this.layout=e,this._refreshContent()}_createContentPanel(e){this.rightPanel?this.rightPanel.clear():this.rightPanel=e.addPanel({className:"lexassetcontentpanel"});e=(e,t)=>{var a;this.allowNextPage&&(a=this.contentPage,this.contentPage+=e,this.contentPage=Math.min(this.contentPage,1+((this.currentData.length-1)/O.MAX_PAGE_ELEMENTS|0)),this.contentPage=Math.max(this.contentPage,1),a!=this.contentPage)&&this._refreshContent()};this.rightPanel.sameLine(),this.rightPanel.addDropdown("Filter",this.allowedTypes,this.allowedTypes[0],e=>this._refreshContent.call(this,null,e),{width:"30%",minWidth:"128px"}),this.rightPanel.addText(null,this.searchValue??"",e=>this._refreshContent.call(this,e,null),{placeholder:"Search assets.."}),this.rightPanel.addButton(null,"<a class='fa fa-arrow-up-short-wide'></a>",((e,t)=>{var t=A("Sort by",t,e=>{e.add("Name",()=>this._sortData("id")),e.add("Type",()=>this._sortData("type")),e.add(""),e.add("Ascending",()=>this._sortData()),e.add("Descending",()=>this._sortData(null,!0))}),a=this.parent.root.parentElement;a.classList.contains("lexdialog")&&(t.root.style.zIndex=+getComputedStyle(a).zIndex+1)}).bind(this),{className:"micro",title:"Sort"}),this.rightPanel.addButton(null,"<a class='fa-solid fa-grip'></a>",((e,t)=>{var t=A("Layout",t,e=>{e.add("Content",()=>this._setContentLayout(O.LAYOUT_CONTENT)),e.add(""),e.add("List",()=>this._setContentLayout(O.LAYOUT_LIST))}),a=this.parent.root.parentElement;a.classList.contains("lexdialog")&&(t.root.style.zIndex=+getComputedStyle(a).zIndex+1)}).bind(this),{className:"micro",title:"View"}),this.rightPanel.addButton(null,"<a class='fa-solid fa-angles-left'></a>",e.bind(this,-1),{className:"micro",title:"Previous Page"}),this.rightPanel.addButton(null,"<a class='fa-solid fa-angles-right'></a>",e.bind(this,1),{className:"micro",title:"Next Page"}),this.rightPanel.endLine(),this.skipBrowser||(this.rightPanel.sameLine(),this.rightPanel.addComboButtons(null,[{value:"Left",icon:"fa-solid fa-left-long",callback:e=>{this.prevData.length&&(this.nextData.push(this.currentData),this.currentData=this.prevData.pop(),this._refreshContent(),this._updatePath(this.currentData))}},{value:"Right",icon:"fa-solid fa-right-long",callback:e=>{this.nextData.length&&(this.prevData.push(this.currentData),this.currentData=this.nextData.pop(),this._refreshContent(),this._updatePath(this.currentData))}},{value:"Refresh",icon:"fa-solid fa-arrows-rotate",callback:e=>{this._refreshContent()}}],{width:"20%",minWidth:"164px",noSelection:!0}),this.rightPanel.addText(null,this.path.join("/"),null,{width:"70%",maxWidth:"calc(70% - 64px)",minWidth:"164px",disabled:!0,signal:"@on_folder_change",style:{fontWeight:"bolder",fontSize:"16px",color:"#aaa"}}),this.rightPanel.addText(null,"Page "+this.contentPage+" / "+(1+((this.currentData.length-1)/O.MAX_PAGE_ELEMENTS|0)),null,{disabled:!0,signal:"@on_page_change",width:"fit-content"}),this.rightPanel.endLine()),this.content=document.createElement("ul"),this.content.className="lexassetscontent",this.rightPanel.root.appendChild(this.content),this.content.addEventListener("dragenter",function(e){e.preventDefault(),this.classList.add("dragging")}),this.content.addEventListener("dragleave",function(e){e.preventDefault(),this.classList.remove("dragging")}),this.content.addEventListener("drop",e=>{e.preventDefault(),this._processDrop(e)}),this.content.addEventListener("click",function(){this.querySelectorAll(".lexassetitem").forEach(e=>e.classList.remove("selected"))}),this._refreshContent()}_refreshContent(a,n){const r=this.layout==O.LAYOUT_CONTENT;this.filter=n??this.filter??"None",this.searchValue=a??this.searchValue??"",this.content.innerHTML="",this.content.className=r?"lexassetscontent":"lexassetscontent list";let i=this;const s=new FileReader;var l=this.currentData.filter(e=>("None"==this.filter||e.type.toLowerCase()==this.filter.toLowerCase())&&e.id.toLowerCase().includes(this.searchValue.toLowerCase())),t=((n||a)&&(this.contentPage=1),(this.contentPage-1)*O.MAX_PAGE_ELEMENTS),o=Math.min(t+O.MAX_PAGE_ELEMENTS,l.length);for(let e=t;e<o;++e){let t=l[e];t.path?w.request({url:t.path,dataType:"blob",success:e=>{t.bytesize=e.size,s.readAsDataURL(e),s.onload=e=>{t.src=e.currentTarget.result,t._path=t.path,delete t.path,this._refreshContent(a,n)}}}):t.domEl=function(n){var e=n.type.charAt(0).toUpperCase()+n.type.slice(1),t=d(n.id);const a="Folder"===e;let o=document.createElement("li");if(o.className="lexassetitem "+n.type.toLowerCase(),o.tabIndex=-1,i.content.appendChild(o),i.useNativeTitle)o.title=e+": "+n.id;else{let l=document.createElement("span");l.className="lexitemdesc",l.innerHTML="File: "+n.id+"<br>Type: "+e,i.content.appendChild(l),o.addEventListener("mousemove",t=>{if(r){var a=o.getBoundingClientRect(),n=t.target.getBoundingClientRect(),s=l.parentElement.getBoundingClientRect(),i=n.x-s.x-(n.x-a.x);let e=n.y-s.y-(n.y-a.y);t.target.classList.contains("lexassettitle")&&(e+=n.y-a.y),l.style.left=i+t.offsetX+12+"px",l.style.top=e+t.offsetY+"px"}}),o.addEventListener("mouseenter",()=>{r&&(l.style.display="unset")}),o.addEventListener("mouseleave",()=>{r&&setTimeout(()=>{l.style.display="none"},100)})}i.allowMultipleSelection&&((s=document.createElement("input")).type="checkbox",s.className="lexcheckbox",s.checked=n.selected,s.addEventListener("change",(e,t)=>{var a;n.selected=!n.selected,i.onevent&&((a=new P(P.ASSET_CHECKED,e.shiftKey?[n]:n)).multiple=!!e.shiftKey,i.onevent(a)),e.stopPropagation(),e.stopImmediatePropagation()}),o.appendChild(s));var s=document.createElement("span");if(s.className="lexassettitle",s.innerText=n.id,o.appendChild(s),!i.skipPreview){let e=null;n.src&&(-1<["png","jpg"].indexOf(d(n.src))||n.src.includes("data:image/"))||a||!r?(e=document.createElement("img"),s=n.unknown_extension?i.rootPath+"images/file.png":a?i.rootPath+"images/folder.png":n.src,e.src=r||a?s:i.rootPath+"images/file.png",o.appendChild(e)):((e=document.createElement("svg")).className="asset-file-preview",o.appendChild(e),s=document.createElement("text"),e.appendChild(s),s.innerText=t&&t!=n.id?"."+t.toUpperCase():n.type.toUpperCase(),(t=2.5/s.innerText.length)<1&&(s.style.fontSize=64*t+"px",e.style.paddingTop="calc(50% - "+(.5*s.offsetHeight+10)+"px)"))}return a||((t=document.createElement("span")).className="lexassetinfo",t.innerText=e,o.appendChild(t)),o.addEventListener("click",function(e){e.stopImmediatePropagation(),e.stopPropagation();var t=e.detail==w.MOUSE_DOUBLE_CLICK;if(t){if(a)return void i._enterFolder(n)}else e.shiftKey||i.content.querySelectorAll(".lexassetitem").forEach(e=>e.classList.remove("selected")),this.classList.add("selected"),i.selectedItem=n,i.skipPreview||i._previewAsset(n);i.onevent&&((t=new P(t?P.ASSET_DBLCLICKED:P.ASSET_SELECTED,e.shiftKey?[n]:n)).multiple=!!e.shiftKey,i.onevent(t))}),i.contextMenu&&o.addEventListener("contextmenu",function(e){e.preventDefault();const t=i.content.querySelectorAll(".selected").length;w.addContextMenu(1<t?t+" selected":a?n.id:n.type,e,e=>{t<=1&&e.add("Rename"),a||e.add("Clone",i._cloneItem.bind(i,n)),t<=1&&e.add("Properties"),e.add(""),e.add("Delete",i._deleteItem.bind(i,n))})}),o.addEventListener("dragstart",function(e){e.preventDefault()},!1),o}(t)}this.allowNextPage=l.length-1>O.MAX_PAGE_ELEMENTS,w.emit("@on_page_change","Page "+this.contentPage+" / "+(1+((l.length-1)/O.MAX_PAGE_ELEMENTS|0))),this.onRefreshContent&&this.onRefreshContent(a,n)}_previewAsset(e){var t,a=e.src&&e.src.includes("data:image/"),a=(this.previewPanel.clear(),this.previewPanel.branch("Asset"),("image"==e.type||e.src)&&(-1<["png","jpg"].indexOf(d(e.src))||a)&&this.previewPanel.addImage(e.src,{style:{width:"100%"}}),{disabled:!0}),a=(this.previewPanel.addText("Filename",e.id,null,a),e.lastModified&&this.previewPanel.addText("Last Modified",new Date(e.lastModified).toLocaleString(),null,a),(e._path||e.src)&&this.previewPanel.addText("URL",e._path||e.src,null,a),this.previewPanel.addText("Path",this.path.join("/"),null,a),this.previewPanel.addText("Type",e.type,null,a),e.bytesize&&this.previewPanel.addText("Size",(e.bytesize/1024).toPrecision(3)+" KBs",null,a),"folder"==e.type&&this.previewPanel.addText("Files",e.children?e.children.length.toString():"0",null,a),this.previewPanel.addSeparator(),[...this.previewActions]);a.length||a.push({name:"Download",callback:()=>w.downloadURL(e.src,e.id)});for(t of a)t.type&&t.type!==e.type||t.path&&t.path!==this.path.join("/")||this.previewPanel.addButton(null,t.name,t.callback.bind(this,e));this.previewPanel.merge()}_processDrop(e){var t=new FileReader;const s=e.dataTransfer.files.length;for(let n=0;n<e.dataTransfer.files.length;++n){const i=e.dataTransfer.files[n];this.currentData.find(e=>e.id===i.name)||(t.readAsDataURL(i),t.onload=e=>{var t=i.name.substr(i.name.lastIndexOf(".")+1).toLowerCase(),a={id:i.name,src:e.currentTarget.result,extension:t,lastModified:i.lastModified};switch(t){case"png":case"jpg":a.type="image";break;case"js":case"css":a.type="script";break;case"json":a.type="json";break;case"obj":a.type="mesh";break;default:a.type=t,a.unknown_extension=!0}this.currentData.push(a),n==s-1&&(this._refreshContent(),this.skipBrowser||this.tree.refresh())})}}_sortData(n,s=!1){n=n??this._lastSortBy??"id",this.currentData=this.currentData.sort((e,t)=>{var a=s?t[n].localeCompare(e[n]):e[n].localeCompare(t[n]);return a=0==a?s?t.id.localeCompare(e.id):e.id.localeCompare(t.id):a}),this._lastSortBy=n,this._refreshContent()}_enterFolder(e){this.prevData.push(this.currentData),this.currentData=e.children,this.contentPage=1,this._refreshContent(),this._updatePath(this.currentData),this.onevent&&(e=new P(P.ENTER_FOLDER,e),this.onevent(e))}_deleteItem(e){var t=this.currentData.indexOf(e);t<0?console.error("[AssetView Error] Cannot delete. Item not found."):(this.currentData.splice(t,1),this._refreshContent(this.searchValue,this.filter),this.onevent&&(t=new P(P.ASSET_DELETED,e),this.onevent(t)),this.tree.refresh(),this._processData(this.data))}_cloneItem(e){var t,a=this.currentData.indexOf(e);a<0||(delete e.domEl,delete e.folder,t=g(e),this.currentData.splice(a,0,t),this._refreshContent(this.searchValue,this.filter),this.onevent&&(a=new P(P.ASSET_CLONED,e),this.onevent(a)),this._processData(this.data))}}w.AssetView=O,Object.assign(w,{request(n){var e=n.dataType||"text",t=("json"==e||"xml"==e?e="text":"binary"==e&&(e="arraybuffer",n.mimeType="application/octet-stream"),new XMLHttpRequest),a=(t.open(n.data?"POST":"GET",n.url,!0),e&&(t.responseType=e),n.mimeType&&t.overrideMimeType(n.mimeType),n.nocache&&t.setRequestHeader("Cache-Control","no-cache"),t.onload=function(e){var t,a=this.response;if(200!=this.status)t="Error "+this.status,n.error&&n.error(t);else{if("json"==n.dataType)try{a=JSON.parse(a)}catch(t){if(!n.error)throw t;n.error(t)}else if("xml"==n.dataType)try{a=(new DOMParser).parseFromString(a,"text/xml")}catch(t){if(!n.error)throw t;n.error(t)}n.success&&n.success.call(this,a,this)}},t.onerror=function(e){n.error&&n.error(e)},new FormData);if(n.data)for(var s in n.data)a.append(s,n.data[s]);return t.send(a),t},requestText(e,t,a){return this.request({url:e,dataType:"text",success:t,error:a})},requestJSON(e,t,a){return this.request({url:e,dataType:"json",success:t,error:a})},requestBinary(e,t,a){return this.request({url:e,dataType:"binary",success:t,error:a})},requireScript(e,t,a,n,s){if(!e)throw"invalid URL";var i,l=(e=e.constructor===String?[e]:e).length,o=[];for(i in e){var r=document.createElement("script");r.num=i,r.type="text/javascript",r.src=e[i]+(s?"?version="+s:""),r.original_src=e[i],r.async=!1,r.onload=function(e){l--,o.push(this),l?n&&n(this.original_src,this.num):t&&t(o)},a&&(r.onerror=function(e){a(e,this.original_src,this.num)}),document.getElementsByTagName("head")[0].appendChild(r)}},downloadURL(e,a){function t(e){var t=document.createElement("a");t.href=e,t.download=a,document.body.appendChild(t),t.click(),document.body.removeChild(t)}const n=new FileReader;e.includes("http")?w.request({url:e,dataType:"blob",success:e=>{n.readAsDataURL(e),n.onload=e=>{t(e.currentTarget.result)}}}):t(e)},downloadFile:function(e,t,a){var n,s;t?(a=a||(t.constructor===String?"text/plain":"application/octet-stream"),n=null,n=t.constructor!==File&&t.constructor!==Blob?new Blob([t],{type:a}):t,s=URL.createObjectURL(n),(a=document.createElement("a")).setAttribute("href",s),a.setAttribute("download",e),a.style.display="none",document.body.appendChild(a),a.click(),document.body.removeChild(a),setTimeout(function(){URL.revokeObjectURL(s)},6e4)):console.warn("No file provided to download")}}),Object.defineProperty(String.prototype,"lastChar",{get:function(){return this[this.length-1]},enumerable:!0,configurable:!0}),Element.prototype.insertChildAtIndex=function(e,t=1/0){t>=this.children.length?this.appendChild(e):this.insertBefore(e,this.children[t])},Element.prototype.hasClass=function(e){return!!(e=[].concat(e)).filter(e=>this.classList.contains(e)).length},Element.prototype.addClass=function(e){e&&this.classList.add(e)},Element.prototype.getComputedSize=function(){var e=getComputedStyle(this);return{width:this.offsetWidth+e.getPropertyValue("marginLeft")+e.getPropertyValue("marginRight"),height:this.offsetHeight+e.getPropertyValue("marginTop")+e.getPropertyValue("marginBottom")}},Element.prototype.getParentArea=function(){let e=this.parentElement;for(;e;){if(e.classList.contains("lexarea"))return e;e=e.parentElement}},w.ICONS={Sidebar:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_iconCarrier"> <g id="Complete"> <g id="sidebar-left"> <g> <rect id="Square-2" data-name="Square" x="3" y="3" width="18" height="18" rx="2" ry="2" fill="none" stroke="currentColor" stroke-miterlimit="10" stroke-width="2"></rect> <line x1="9" y1="21" x2="9" y2="3" fill="none" stroke="currentColor" stroke-miterlimit="10" stroke-width="2"></line> </g> </g> </g> </g></svg>',More:'<svg fill="#000000" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_iconCarrier"> <g id="Complete"> <g id="F-More"> <path id="Vertical" d="M12,16a2,2,0,1,1-2,2A2,2,0,0,1,12,16ZM10,6a2,2,0,1,0,2-2A2,2,0,0,0,10,6Zm0,6a2,2,0,1,0,2-2A2,2,0,0,0,10,12Z"></path> </g> </g> </g></svg>',MoreHorizontal:'<svg fill="#000000" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_iconCarrier"> <g id="Complete"> <g id="F-More"> <path id="Horizontal" d="M8,12a2,2,0,1,1-2-2A2,2,0,0,1,8,12Zm10-2a2,2,0,1,0,2,2A2,2,0,0,0,18,10Zm-6,0a2,2,0,1,0,2,2A2,2,0,0,0,12,10Z"></path> </g> </g> </g></svg>',MenuArrows:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="#000000" transform="rotate(90)"><g id="SVGRepo_iconCarrier"> <g id="Complete"> <g id="Code"> <g> <polyline id="Right-2" data-name="Right" points="15.5 7 20.5 12 15.5 17" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"></polyline> <polyline id="Left-2" data-name="Left" points="8.5 7 3.5 12 8.5 17" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"></polyline> </g> </g> </g> </g></svg>',Plus:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="#000000"<g id="SVGRepo_iconCarrier"> <g id="Complete"> <g id="add-2" data-name="add"> <g> <line x1="12" y1="19" x2="12" y2="5" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"></line> <line x1="5" y1="12" x2="19" y2="12" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"></line> </g> </g> </g> </g></svg>',Down:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="#000000"><g id="SVGRepo_iconCarrier"> <title>i</title> <g id="Complete"> <g id="F-Chevron"> <polyline id="Down" points="5 8.5 12 15.5 19 8.5" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"></polyline> </g> </g> </g></svg>',Up:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="#000000"><g id="SVGRepo_iconCarrier"> <title>i</title> <g id="Complete"> <g id="F-Chevron"> <polyline id="Up" points="5 15.5 12 8.5 19 15.5" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"></polyline> </g> </g> </g></svg>',Right:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="#000000"><g id="SVGRepo_iconCarrier"> <title>i</title> <g id="Complete"> <g id="F-Chevron"> <polyline id="Right" points="8.5 5 15.5 12 8.5 19" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"></polyline> </g> </g> </g></svg>',Left:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="#000000"><g id="SVGRepo_iconCarrier"> <title>i</title> <g id="Complete"> <g id="F-Chevron"> <polyline id="Left" points="15.5 5 8.5 12 15.5 19" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"></polyline> </g> </g> </g></svg>'},w.UTILS={getTime(){return(new Date).getTime()},compareThreshold(e,t,a,n){return Math.abs(e-t)>=n||Math.abs(e-a)>=n},compareThresholdRange(e,t,a,n){return a<=e&&e<=n||a<=t&&t<=n||e<=a&&n<=t},uidGenerator:y,deleteElement(e){e&&e.remove()},flushCss(e){e.offsetHeight},getControlPoints(e,t,a,n,s,i,l){var o=Math.sqrt(Math.pow(a-e,2)+Math.pow(n-t,2)),o=l*o/(o+Math.sqrt(Math.pow(s-a,2)+Math.pow(i-n,2))),l=l-o;return[a+o*(e-s),n+o*(t-i),a-l*(e-s),n-l*(t-i)]},drawSpline(e,t,a){e.save();for(var n=[],s=t.length,i=0;i<s-4;i+=2)n=n.concat(w.UTILS.getControlPoints(t[i],t[i+1],t[i+2],t[i+3],t[i+4],t[i+5],a));for(i=2;i<t.length-5;i+=2)e.beginPath(),e.moveTo(t[i],t[i+1]),e.bezierCurveTo(n[2*i-2],n[2*i-1],n[2*i],n[2*i+1],t[i+2],t[i+3]),e.stroke(),e.closePath();e.beginPath(),e.moveTo(t[0],t[1]),e.quadraticCurveTo(n[0],n[1],t[2],t[3]),e.stroke(),e.closePath(),e.beginPath(),e.moveTo(t[s-2],t[s-1]),e.quadraticCurveTo(n[2*s-10],n[2*s-9],t[s-4],t[s-3]),e.stroke(),e.closePath(),e.restore()}}}("undefined"==typeof window&&"undefined"==typeof self&&global);