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.
- package/README.md +1 -1
- package/build/components/audio.js +9 -18
- package/build/components/nodegraph.js +84 -78
- package/build/lexgui.css +222 -218
- package/build/lexgui.js +1230 -1196
- package/build/lexgui.min.css +7 -1
- package/build/lexgui.min.js +1 -1
- package/build/lexgui.module.js +1230 -1198
- package/build/lexgui.module.min.js +1 -1
- package/changelog.md +27 -1
- package/package.json +28 -22
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var LX={version:"0.4.0",ready:!1,components:[],signals:{},extraCommandbarEntries:[],activeDraggable:null};function clamp(e,t,i){return Math.min(Math.max(e,t),i)}function round(e,t){return 0==t?Math.floor(e):+e.toFixed(t??2).replace(/([0-9]+(\.[0-9]+[1-9])?)(\.?0+$)/,"$1")}function remapRange(e,t,i,a,l){return(e-t)*(l-a)/(i-t)+a}LX.MOUSE_LEFT_CLICK=0,LX.MOUSE_MIDDLE_CLICK=1,LX.MOUSE_RIGHT_CLICK=2,LX.MOUSE_DOUBLE_CLICK=2,LX.MOUSE_TRIPLE_CLICK=3,LX.CURVE_MOVEOUT_CLAMP=0,LX.CURVE_MOVEOUT_DELETE=1,LX.DRAGGABLE_Z_INDEX=101,LX.clamp=clamp,LX.round=round,LX.remapRange=remapRange,"undefined"!=typeof performance?LX.getTime=performance.now.bind(performance):"undefined"!=typeof Date&&Date.now?LX.getTime=Date.now.bind(Date):"undefined"!=typeof process?LX.getTime=function(){var e=process.hrtime();return .001*e[0]+1e-6*e[1]}:LX.getTime=function(){return new Date().getTime()};let ASYNC_ENABLED=!0;function doAsync(e,t){ASYNC_ENABLED?setTimeout(e,t??0):e()}function getSupportedDOMName(e){return e.replace(/\s/g,"").replaceAll("@","_").replaceAll("+","_plus_").replaceAll(".","")}function has(e){return LX.components.indexOf(e)>-1}function getExtension(e){return e.includes(".")?e.split(".").pop():null}function deepCopy(e){return JSON.parse(JSON.stringify(e))}function setTheme(e){e="light"==e?"light":"dark",document.documentElement.setAttribute("data-theme",e),LX.emit("@on_new_color_scheme",e)}function setThemeColor(e,t){document.querySelector(":root").style.setProperty("--"+e,t)}function getThemeColor(e){let t=getComputedStyle(document.querySelector(":root")),i=t.getPropertyValue("--"+e);if(document.documentElement.getAttribute("data-theme"),i.includes("light-dark")){let a=t.getPropertyValue("color-scheme");return"light"==a?i.substring(i.indexOf("(")+1,i.indexOf(",")).replace(/\s/g,""):i.substring(i.indexOf(",")+1,i.indexOf(")")).replace(/\s/g,"")}return i}function getBase64Image(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")}function hexToRgb(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 rgbToHex(e){let t="#";for(let i of e)t+=(i=Math.floor(255*i)).toString(16);return t}function measureRealWidth(e,t=8){var i=document.createElement("span");i.className="lexinputmeasure",i.innerHTML=e,document.body.appendChild(i);var a=i.getBoundingClientRect();return LX.UTILS.deleteElement(i),a.width+t}function simple_guidGenerator(){var e=function(){return((1+Math.random())*65536|0).toString(16).substring(1)};return e()+"-"+e()+"-"+e()}function buildTextPattern(e={}){let t=[];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)");let i,a=`^${t.join("")}.{${e.minLength||0},${e.maxLength||""}}$`;return e.asRegExp?RegExp(a):a}function makeDraggable(e,t={}){let i=0,a=0,l=null,n=t.targetClass,s=t.dragMargin??3,r=(t,l,n)=>{let r=e.parentElement?e.parentElement.getBoundingClientRect():{x:0,y:0,width:0,height:0},o="fixed"==e.style.position,d=o?new LX.vec2(r.x,r.y):new LX.vec2;n=n??t.clientX-i-r.x,l=l??t.clientY-a-r.y,e.style.left=clamp(n,s+d.x,d.x+r.width-e.offsetWidth-s)+"px",e.style.top=clamp(l,s+d.y,d.y+r.height-e.offsetHeight-s)+"px",e.style.translate="none"};t.autoAdjust&&r(null,parseInt(e.style.left),parseInt(e.style.top));let o=LX.UTILS.uidGenerator();e["draggable-id"]=o;let d=e=>{l&&r(e)},c=e=>{l&&t.onMove&&t.onMove(l)},h=t.onMove?c:d,u=t.onDragStart;e.setAttribute("draggable",!0),e.addEventListener("mousedown",function(e){l=e.target.classList.contains(n)||!n?e.target:null}),e.addEventListener("dragstart",function(t){if(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),!l)return;var n=new Image;n.src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=",t.dataTransfer.setDragImage(n,0,0),t.dataTransfer.effectAllowed="move";let s=t.target.getBoundingClientRect(),r=l.parentElement.getBoundingClientRect(),o="fixed"==l.style.position,d=o?new LX.vec2(r.x,r.y):new LX.vec2;i=t.clientX-s.x-d.x,a=t.clientY-s.y-d.y,document.addEventListener("mousemove",h),l._eventCatched=!0,LX.activeDraggable&&(LX.activeDraggable.style.zIndex=LX.DRAGGABLE_Z_INDEX),LX.activeDraggable=e,LX.activeDraggable.style.zIndex=LX.DRAGGABLE_Z_INDEX+1,u&&u(l,t)},!1),document.addEventListener("mouseup",e=>{l&&(l=null,document.removeEventListener("mousemove",h))})}function makeCollapsible(e,t,i,a={}){e.classList.add("collapsible");let l=a.collapsed??!0,n=LX.makeIcon("Right");n.classList.add("collapser"),n.dataset.collapsed=l,n.style.marginLeft="auto",n.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(n),(i=i??e.parentElement).appendChild(t)}function makeCodeSnippet(e,t,i={}){if(!LX.has("CodeEditor")){console.error("Import the CodeEditor component to create snippets!");return}let a=document.createElement("div");a.className="lexcodesnippet",a.style.width=t?t[0]:"auto",a.style.height=t?t[1]:"auto";let l=new Area({noAppend:!0}),n=new LX.CodeEditor(l,{skipInfo:!0,disableEdition:!0,allowAddScripts:!1,name:i.tabName});if(n.setText(e,i.language??"Plain Text"),i.linesAdded){let s=n.root.querySelector(".code");for(let r of i.linesAdded)if(r.constructor==Number)s.childNodes[r-1].classList.add("added");else if(r.constructor==Array)for(let o=r[0]-1;o<=r[1]-1;o++)s.childNodes[o].classList.add("added")}if(i.linesRemoved){let d=n.root.querySelector(".code");for(let c of i.linesRemoved)if(c.constructor==Number)d.childNodes[c-1].classList.add("removed");else if(c.constructor==Array)for(let h=c[0]-1;h<=c[1]-1;h++)d.childNodes[h].classList.add("removed")}if(i.windowMode){let u=document.createElement("div");u.className="lexwindowbuttons";let p=document.createElement("span");p.style.background="#ee4f50";let m=document.createElement("span");m.style.background="#f5b720";let g=document.createElement("span");g.style.background="#53ca29",u.appendChild(p),u.appendChild(m),u.appendChild(g);let f=n.root.querySelector(".lexareatabs");f.prepend(u)}return(i.lineNumbers??!0)||n.root.classList.add("no-gutter"),a.appendChild(l.root),a}function makeIcon(e,t){let i=document.createElement("a");return i.title=t??"",i.className="lexicon",i.innerHTML=LX.ICONS[e]??"",i}function registerCommandbarEntry(e,t){LX.extraCommandbarEntries.push({name:e,callback:t})}LX.doAsync=doAsync,LX.getSupportedDOMName=getSupportedDOMName,LX.has=has,LX.getExtension=getExtension,LX.deepCopy=deepCopy,LX.setTheme=setTheme,LX.setThemeColor=setThemeColor,LX.getThemeColor=getThemeColor,LX.getBase64Image=getBase64Image,LX.hexToRgb=hexToRgb,LX.rgbToHex=rgbToHex,LX.measureRealWidth=measureRealWidth,LX.guidGenerator=simple_guidGenerator,LX.buildTextPattern=buildTextPattern,LX.makeDraggable=makeDraggable,LX.makeCollapsible=makeCollapsible,LX.makeCodeSnippet=makeCodeSnippet,LX.makeIcon=makeIcon,LX.registerCommandbarEntry=registerCommandbarEntry;class vec2{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 vec2){return t.set(this.x+e.x,this.y+e.y),t}sub(e,t=new vec2){return t.set(this.x-e.x,this.y-e.y),t}mul(e,t=new vec2){return e.constructor==Number&&(e=new vec2(e)),t.set(this.x*e.x,this.y*e.y),t}div(e,t=new vec2){return e.constructor==Number&&(e=new vec2(e)),t.set(this.x/e.x,this.y/e.y),t}abs(e=new vec2){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 vec2){return e.set(this.x,this.y),e.mul(1/this.len(),e)}dst(e){return e.sub(this).len()}clp(e,t,i=new vec2){return i.set(clamp(this.x,e,t),clamp(this.y,e,t)),i}}function _createCommandbar(e){let t=document.createElement("dialog");t.className="commandbar",t.tabIndex=-1,e.appendChild(t);let i=[],a=null;t.addEventListener("keydown",function(e){if(e.stopPropagation(),e.stopImmediatePropagation(),a=a??-1,"Escape"==e.key)this.close(),p(!0);else if("Enter"==e.key){let l=i[a];if(l){let n=l.item.type&&"checkbox"===l.item.type;this.close(),n?(l.item.checked=!l.item.checked,l.callback.call(window,l.item.checked,l.entry_name)):l.callback.call(window,l.entry_name)}}else if("ArrowDown"==e.key&&a<i.length-1){a++,t.querySelectorAll(".hovered").forEach(e=>e.classList.remove("hovered")),i[a].classList.add("hovered");let s=i[a].offsetHeight*(a+1)-h.offsetHeight;s>0&&h.scrollTo({top:s,behavior:"smooth"})}else"ArrowUp"==e.key&&a>0&&(a--,t.querySelectorAll(".hovered").forEach(e=>e.classList.remove("hovered")),i[a].classList.add("hovered"))}),t.addEventListener("focusout",function(e){e.relatedTarget!=e.currentTarget&&(e.stopPropagation(),e.stopImmediatePropagation(),this.close(),p(!0))}),e.addEventListener("keydown",e=>{if(" "==e.key&&e.ctrlKey)e.stopImmediatePropagation(),e.stopPropagation(),LX.setCommandbarState(!0);else for(let t of LX.components){if(!LX[t]||!LX[t].prototype.onKeyPressed)continue;let i=LX.CodeEditor.getInstances();for(let a of i)a.onKeyPressed(e)}});let l=document.createElement("div");l.className="gs-header";let n=document.createElement("a");n.className="fa-solid fa-magnifying-glass",l.appendChild(n);let s=document.createElement("input");s.placeholder="Search...",s.value="",l.appendChild(s);let r=new Area({width:"100%",skipAppend:!0,className:"gs-tabs"}),o=r.addTabs(),d=null;{let c=(e,t)=>{d=t};o.add("All",document.createElement("div"),{selected:!0,onSelect:c})}let h=document.createElement("div");h.className="searchitembox";let u=null,p=e=>{h.innerHTML="",i.length=0,a=null,e&&(s.value="")},m=(e,l,n,s)=>{if(!e.length)return;u&&u.classList.remove("last");let r=document.createElement("div");r.className="searchitem last";let o=s&&s.type&&"checkbox"===s.type;o?r.innerHTML="<a class='fa fa-check'></a><span>"+(n+e)+"</span>":r.innerHTML=n+e,r.entry_name=e,r.callback=l,r.item=s,r.addEventListener("click",function(e){this.callback.call(window,this.entry_name),LX.setCommandbarState(!1),p(!0)}),r.addEventListener("mouseenter",function(e){t.querySelectorAll(".hovered").forEach(e=>e.classList.remove("hovered")),this.classList.add("hovered"),a=i.indexOf(this)}),r.addEventListener("mouseleave",function(e){this.classList.remove("hovered")}),i.push(r),h.appendChild(r),u=r},g=(e,t,i)=>{let a=Object.keys(e)[0];if((e.name??i+a).toLowerCase().includes(t)&&e.callback&&m(e.name??a,e.callback,i,e),!e.name)for(let l of(i+=a+" > ",e[a]))g(l,t,i)};return t._addElements=e=>{for(let t of(p(),LX.menubars))for(let i of t.items)g(i,e,"");for(let a of LX.extraCommandbarEntries){let l=a.name;l.toLowerCase().includes(e)&&m(l,a.callback,"",{})}if(LX.has("CodeEditor")){let n=LX.CodeEditor.getInstances();if(!n.length)return;let s=n[0].languages;for(let r of Object.keys(s)){let o="Language: "+r,d=n[0]._getFileIcon(null,s[r].ext),c=d.includes("fa-")?"<i class='"+d+"'></i>":"<img src='https://raw.githubusercontent.com/jxarco/lexgui.js/master/"+d+"'>";c+=o+" <span class='lang-ext'>("+s[r].ext+")</span>",o.toLowerCase().includes(e)&&m(c,()=>{for(let e of n)e._changeLanguage(r)},"",{})}}},s.addEventListener("input",function(e){t._addElements(this.value.toLowerCase())}),t.appendChild(l),t.appendChild(r.root),t.appendChild(h),t}function init(e={}){if(this.ready)return this.main_area;var t=document.createElement("div");t.id="lexroot",t.tabIndex=-1;var i=document.createElement("div");i.id="modal",this.modal=i,this.root=t,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)),document.documentElement.setAttribute("data-strictVP",e.strictViewport??!0?"true":"false"),this.commandbar=_createCommandbar(this.container),this.container.appendChild(i),e.skipRoot?this.root=document.body:this.container.appendChild(t);{let a=document.createElement("section");a.className="notifications",this.notifications=document.createElement("ol"),this.notifications.className="",this.notifications.iWidth=0,a.appendChild(this.notifications),this.container.appendChild(a),this.notifications.addEventListener("mouseenter",()=>{this.notifications.classList.add("list")}),this.notifications.addEventListener("mouseleave",()=>{this.notifications.classList.remove("list")})}t.addEventListener("dragover",function(e){e.preventDefault()},!1),document.addEventListener("contextmenu",function(e){e.preventDefault()},!1);var l=document.getElementsByTagName("HEAD")[0],n=document.createElement("link");return n.rel="stylesheet",n.type="text/css",n.crossOrigin="anonymous",n.href="https://use.fontawesome.com/releases/v6.7.2/css/all.css",l.appendChild(n),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 Area({id:e.id??"mainarea"})),(e.autoTheme??!0)&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: light)").matches&&(LX.setTheme("light"),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",e=>{LX.setTheme(e.matches?"dark":"light")})),this.main_area}function setCommandbarState(e,t=!0){let i=this.commandbar;e?(i.show(),i.querySelector("input").focus(),t&&i._addElements(void 0)):i.close()}function message(e,t,i={}){if(!e)throw"No message to show";return i.modal=!0,new Dialog(t,t=>{t.addTextArea(null,e,null,{disabled:!0,fitHeight:!0})},i)}function popup(e,t,i={}){if(!e)throw"No message to show";i.size=i.size??["max-content","auto"],i.class="lexpopup";let a=i.timeout||3e3,l=new Dialog(t,t=>{t.addTextArea(null,e,null,{disabled:!0,fitHeight:!0})},i);return setTimeout(()=>{l.close()},Math.max(a,150)),l}function prompt(e,t,i,a={}){a.modal=!0,a.className="prompt";let l="",n=new Dialog(t,s=>{s.addTextArea(null,e,null,{disabled:!0,fitHeight:!0}),(a.input??!0)&&s.addText(null,a.input||l,e=>l=e,{placeholder:"..."}),s.sameLine(2),s.addButton(null,"Cancel",()=>{a.on_cancel&&a.on_cancel(),n.close()}),s.addButton(null,a.accept||"Continue",()=>{a.required&&""===l?(e+=e.includes("You must fill the input text.")?"":"\nYou must fill the input text.",n.close(),prompt(e,t,i,a)):(i&&i.call(this,l),n.close())},{buttonClass:"primary"})},a);return(a.input??!0)&&n.root.querySelector("input").focus(),n}function toast(e,t,i={}){if(!e)throw"The toast needs at least a title!";console.assert(this.notifications);let a=document.createElement("li");a.className="lextoast",a.style.translate="0 calc(100% + 30px)",this.notifications.prepend(a),doAsync(()=>{this.notifications.offsetWidth>this.notifications.iWidth&&(this.notifications.iWidth=Math.min(this.notifications.offsetWidth,480),this.notifications.style.width=this.notifications.iWidth+"px"),a.dataset.open=!0},10);let l=document.createElement("div");l.className="lextoastcontent",a.appendChild(l);let n=document.createElement("div");if(n.className="title",n.innerHTML=e,l.appendChild(n),t){let s=document.createElement("div");s.className="desc",s.innerHTML=t,l.appendChild(s)}if(i.action){let r=new Panel;r.addButton(null,i.action.name??"Accept",i.action.callback.bind(this,a),{width:"auto",maxWidth:"150px",className:"right",buttonClass:"outline"}),a.appendChild(r.root.childNodes[0])}let o=this;if(a.close=function(){this.dataset.closed=!0,doAsync(()=>{this.remove(),o.notifications.childElementCount||(o.notifications.style.width="unset",o.notifications.iWidth=0)},500)},i.closable??!0){let d=document.createElement("a");d.className="fa fa-xmark lexicon closer",d.addEventListener("click",()=>{a.close()}),a.appendChild(d)}let c=i.timeout??3e3;-1!=c&&doAsync(()=>{a.close()},c)}function badge(e,t,i={}){let a=document.createElement("div");return a.innerHTML=e,a.className="lexbadge "+(t??""),Object.assign(a.style,i.style??{}),a.outerHTML}function makeContainer(e,t,i={}){let a=document.createElement("div");return a.className="lexcontainer "+(t??""),a.style.width=e&&e[0]?e[0]:"100%",a.style.height=e&&e[1]?e[1]:"100%",Object.assign(a.style,i),a}LX.vec2=vec2,LX.init=init,LX.setCommandbarState=setCommandbarState,LX.message=message,LX.popup=popup,LX.prompt=prompt,LX.toast=toast,LX.badge=badge,LX.makeContainer=makeContainer;class IEvent{constructor(e,t,i){this.name=e,this.value=t,this.domEvent=i}}LX.IEvent=IEvent;class TreeEvent{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||TreeEvent.NONE,this.node=t,this.value=i,this.multiple=!1,this.panel=null}string(){switch(this.type){case TreeEvent.NONE:return"tree_event_none";case TreeEvent.NODE_SELECTED:return"tree_event_selected";case TreeEvent.NODE_DELETED:return"tree_event_deleted";case TreeEvent.NODE_DBLCLICKED:return"tree_event_dblclick";case TreeEvent.NODE_CONTEXTMENU:return"tree_event_contextmenu";case TreeEvent.NODE_DRAGGED:return"tree_event_dragged";case TreeEvent.NODE_RENAMED:return"tree_event_renamed";case TreeEvent.NODE_VISIBILITY:return"tree_event_visibility";case TreeEvent.NODE_CARETCHANGED:return"tree_event_caretchanged"}}}function emit(e,t,i={}){let a=LX.signals[e];if(!a)return;let l=i.target;if(l){l[e]&&l[e].call(l,t);return}for(let n of a)if(n.constructor===Widget)n.set(t,i.skipCallback??!0),n.options&&n.options.callback&&n.options.callback(t,a);else{let s=n;s(null,t)}}function addSignal(e,t,i){t[e]=i,LX.signals[e]||(LX.signals[e]=[]),!(LX.signals[e].indexOf(t)>-1)&&LX.signals[e].push(t)}LX.TreeEvent=TreeEvent,LX.emit=emit,LX.addSignal=addSignal;class Area{constructor(e={}){var t,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 n=e.overlay;if(n){this.root.classList.add("overlay-"+n),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 s=e.draggable??!0;if(s&&makeDraggable(i,e),e.resizeable&&i.classList.add("resizeable"),e.resize){this.splitBar=document.createElement("div");let r="left"==n||"right"==n?"horizontal":"vertical";if(this.type=n,this.splitBar.className="lexsplitbar "+r,"right"==n)this.splitBar.style.width=LX.DEFAULT_SPLITBAR_SIZE+"px",this.splitBar.style.left=-(LX.DEFAULT_SPLITBAR_SIZE/2)+"px";else if("left"==n){let o=Math.min(document.body.clientWidth-LX.DEFAULT_SPLITBAR_SIZE,this.root.clientWidth);this.splitBar.style.width=LX.DEFAULT_SPLITBAR_SIZE+"px",this.splitBar.style.left=o+LX.DEFAULT_SPLITBAR_SIZE/2+"px"}else if("top"==n){let d=Math.min(document.body.clientHeight-LX.DEFAULT_SPLITBAR_SIZE,this.root.clientHeight);this.splitBar.style.height=LX.DEFAULT_SPLITBAR_SIZE+"px",this.splitBar.style.top=d+LX.DEFAULT_SPLITBAR_SIZE/2+"px"}else"bottom"==n&&(this.splitBar.style.height=LX.DEFAULT_SPLITBAR_SIZE+"px",this.splitBar.style.top=-(LX.DEFAULT_SPLITBAR_SIZE/2)+"px");this.splitBar.addEventListener("mousedown",u),this.root.appendChild(this.splitBar);var c=this,h=[0,0];function u(e){var t=c.root.ownerDocument;t.addEventListener("mousemove",p),t.addEventListener("mouseup",m),h[0]=e.x,h[1]=e.y,e.stopPropagation(),e.preventDefault(),document.body.classList.add("nocursor"),c.splitBar.classList.add("nocursor")}function p(e){switch(c.type){case"right":var t=h[0]-e.x,i=c.root.offsetWidth+t;c.root.style.width=i+"px";break;case"left":var t=h[0]-e.x,i=Math.min(document.body.clientWidth-LX.DEFAULT_SPLITBAR_SIZE,c.root.offsetWidth-t);c.root.style.width=i+"px",c.splitBar.style.left=i+LX.DEFAULT_SPLITBAR_SIZE/2+"px";break;case"top":var t=h[1]-e.y,i=Math.min(document.body.clientHeight-LX.DEFAULT_SPLITBAR_SIZE,c.root.offsetHeight-t);c.root.style.height=i+"px",c.splitBar.style.top=i+LX.DEFAULT_SPLITBAR_SIZE/2+"px";break;case"bottom":var t=h[1]-e.y,i=c.root.offsetHeight+t;c.root.style.height=i+"px"}h[0]=e.x,h[1]=e.y,e.stopPropagation(),e.preventDefault(),c.onresize&&c.onresize(c.root.getBoundingClientRect())}function m(e){var t=c.root.ownerDocument;t.removeEventListener("mousemove",p),t.removeEventListener("mouseup",m),document.body.classList.remove("nocursor"),c.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 t=e.type||"horizontal",i=e.sizes||["50%","50%"],a="auto"===e.sizes;if(!i[1]){let l=i[0],n=e.top?e.top:0;l.constructor==Number&&(l+=n,l+="px"),i[1]="calc( 100% - "+l+" )"}var s=new Area({skipAppend:!0,className:"split"+(e.menubar||e.sidebar?"":" origin")}),r=new Area({skipAppend:!0,className:"split"});s.parentArea=this,r.parentArea=this;let o=e.minimizable??!1,d=(e.resize??!0)||o;var c="0px";if(this.offset=0,d&&(this.resize=d,this.splitBar=document.createElement("div"),this.splitBar.className="lexsplitbar "+t,"horizontal"==t?this.splitBar.style.width=LX.DEFAULT_SPLITBAR_SIZE+"px":this.splitBar.style.height=LX.DEFAULT_SPLITBAR_SIZE+"px",this.splitBar.addEventListener("mousedown",function e(t){var i=f.root.ownerDocument;i.addEventListener("mousemove",v),i.addEventListener("mouseup",E),t.stopPropagation(),t.preventDefault(),document.body.classList.add("nocursor"),f.splitBar.classList.add("nocursor")}),c=LX.DEFAULT_SPLITBAR_SIZE/2+"px",o&&(this.splitExtended=!1,r.root.addEventListener("animationend",e=>{let i=getComputedStyle(r.root).opacity;r.root.classList.remove(e.animationName+"-"+t),r.root.style.opacity=i,flushCss(r.root)}),this.splitBar.addEventListener("contextmenu",e=>{e.preventDefault(),addContextMenu(null,e,e=>{e.add("Extend",{disabled:this.splitExtended,callback:()=>{this.extend()}}),e.add("Reduce",{disabled:!this.splitExtended,callback:()=>{this.reduce()}})})}))),"horizontal"==t){var h=i[0],u=i[1];h.constructor==Number&&(h+="px"),u.constructor==Number&&(u+="px"),s.root.style.width="calc( "+h+" - "+c+" )",s.root.style.height="calc(100% - 0px)",r.root.style.width="calc( "+u+" - "+c+" )",r.root.style.height="calc(100% - 0px)",this.root.style.display="flex"}else if(s.root.style.width="100%",r.root.style.width="100%",a){s.root.style.height="auto";let p=new ResizeObserver(e=>{for(let t of e){let i=t.contentRect;r.root.style.height="calc(100% - "+(i.height+4)+"px )"}});p.observe(s.root)}else{var m=i[0],g=i[1];m.constructor==Number&&(m+="px"),g.constructor==Number&&(g+="px"),s.root.style.width="100%",s.root.style.height="auto"==m?m:"calc( "+m+" - "+c+" )",r.root.style.height="auto"==g?g:"calc( "+g+" - "+c+" )"}if(this.root.appendChild(s.root),d&&this.root.appendChild(this.splitBar),this.root.appendChild(r.root),this.sections=[s,r],this.type=t,this._update(),!d)return this.sections;var f=this;function v(e){"horizontal"==f.type?f._moveSplit(-e.movementX):f._moveSplit(-e.movementY);let t=f.root.querySelectorAll(".lexwidget");for(let i of t){let a=i.jsInstance;a.onresize&&a.onresize()}e.stopPropagation(),e.preventDefault()}function E(e){var t=f.root.ownerDocument;t.removeEventListener("mousemove",v),t.removeEventListener("mouseup",E),document.body.classList.remove("nocursor"),f.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()),doAsync(()=>{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)),doAsync(()=>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)),doAsync(()=>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 Panel(e);return this.attach(t),this.panels.push(t),t}addMenubar(e,t={}){let i=new Menubar(t);e&&e(i),LX.menubars.push(i);let[a,l]=this.split({type:"vertical",sizes:[48,null],resize:!1,menubar:!0});return i.siblingArea=l,a.attach(i),a.isMenubar=!0,(t.sticky??!0)&&a.root.classList.add("sticky"),i}addSidebar(e,t={}){let i=new SideBar(t);e&&e(i),i._build(),LX.menubars.push(i);let a=t.width??"16rem",[l,n]=this.split({type:"horizontal",sizes:[a,null],resize:!1,sidebar:!0});return i.siblingArea=n,l.attach(i),l.isSidebar=!0,i}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 n=t.float;if(n)for(var s=0;s<n.length;s++){let r=n[s];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 n={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),n.parent=a);let s=e.callback;e.options?i.addDropdown(null,e.options,e.name,s,n):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}s(t,i)},n),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 s=t[a];s.group=t,o(s,!0,a==t.length-1)}else o(t);if(n){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 Tabs(this,e);return e.folding&&(this.parentArea._disableSplitResize(),this.root.style.paddingTop="4px"),t}_moveSplit(e,t=!1,i=0){if(!this.type)throw"No split area";if(void 0===e)return;let a=this.sections[0];var l=a.root;l.classList.contains("origin")||(l=l.parentElement);let n=this.sections[1],s=n.root,r=" - "+LX.DEFAULT_SPLITBAR_SIZE+"px",o=null;if(t||(o=l.style.transition,l.style.transition=s.style.transition="none",flushCss(l),flushCss(s)),"horizontal"==this.type){var d=Math.max(s.offsetWidth+e,parseInt(n.minWidth));i&&(d=i),l.style.width="-moz-calc( 100% - "+d+"px "+r+" )",l.style.width="-webkit-calc( 100% - "+d+"px "+r+" )",l.style.width="calc( 100% - "+d+"px "+r+" )",l.style.minWidth=parseInt(a.minWidth)+"px",s.style.width=d+"px",a.maxWidth!=1/0&&(s.style.minWidth="calc( 100% - "+parseInt(a.maxWidth)+"px )")}else{var d=Math.max(s.offsetHeight+e+n.offset,parseInt(n.minHeight));i&&(d=i),l.style.height="-moz-calc( 100% - "+d+"px "+r+" )",l.style.height="-webkit-calc( 100% - "+d+"px "+r+" )",l.style.height="calc( 100% - "+d+"px "+r+" )",l.style.minHeight=a.minHeight+"px",s.style.height=d-n.offset+"px"}t||(l.style.transition=s.style.transition=o),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 flushCss(e){e.offsetHeight}LX.Area=Area;class Tabs{static TAB_SIZE=28;static TAB_ID=0;constructor(e,t={}){this.onclose=t.onclose;let i=document.createElement("div");i.className="lexareatabs "+(t.fit?"fit":"row");let a=t.folding??!1;a&&i.classList.add("folding");let l=this;if(i.addEventListener("dragenter",function(e){e.preventDefault(),this.classList.add("dockingtab")}),i.addEventListener("dragleave",function(e){e.preventDefault(),this.classList.remove("dockingtab")}),i.addEventListener("drop",function(e){e.preventDefault();let t=e.dataTransfer.getData("source"),i=document.getElementById(t);if(!i)return;this.appendChild(i);let a=document.getElementById(t+"_content");l.area.attach(a),this.classList.remove("dockingtab"),LX.emit("@on_tab_docked"),i.instance=l,i.click(),l.tabs[i.dataset.name]=a}),e.root.classList.add("lexareatabscontainer"),e.split({type:"vertical",sizes:t.sizes??"auto",resize:!1,top:6}),e.sections[0].attach(i),this.area=e.sections[1],this.area.root.className+=" lexareatabscontent",this.selected=null,this.root=i,this.tabs={},this.tabDOMs={},t.fit){let n=document.createElement("span");n.className="lexareatab thumb",this.thumb=n,this.root.appendChild(n);let s=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",flushCss(this.thumb),this.thumb.style.transition=i}});s.observe(this.area.root)}if(a){this.folded=!0,this.folding=a,"up"==a&&e.root.insertChildAtIndex(e.sections[1].root,0);let r=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 )"}});r.observe(this.area.root),this.area.root.classList.add("folded")}}add(e,t,i={}){let a=i.selected??!1;a&&(this.root.querySelectorAll("span").forEach(e=>e.classList.remove("selected")),this.area.root.querySelectorAll(".lextabcontent").forEach(e=>e.style.display="none")),a=!Object.keys(this.tabs).length&&!this.folding||a;let l=t.root?t.root:t;l.originalDisplay=l.style.display,l.style.display=a?l.originalDisplay:"none",l.classList.add("lextabcontent"),i.icon&&(i.icon.includes("fa-")?i.icon="<i class='"+i.icon+"'></i>":i.icon="<img src='https://raw.githubusercontent.com/jxarco/lexgui.js/master/"+i.icon+"'>");let n=document.createElement("span");n.dataset.name=e,n.className="lexareatab"+(a?" selected":""),n.innerHTML=(i.icon??"")+e,n.id=e.replace(/\s/g,"")+Tabs.TAB_ID++,n.title=i.title??"",n.selected=a??!1,n.fixed=i.fixed,n.instance=this,l.id=n.id+"_content",n.selected&&(this.selected=e),LX.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"),l.style.display=l.originalDisplay,n.instance.selected=n.dataset.name}this.folding&&(this.folded=n.selected,this.area.root.classList.toggle("folded",!this.folded)),i.onSelect&&i.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(),i.onContextMenu&&i.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(l),this.tabDOMs[e]=n,this.tabs[e]=t,setTimeout(()=>{i.onCreate&&i.onCreate.call(this,this.area.root.getBoundingClientRect()),a&&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()}}LX.Tabs=Tabs;class Menubar{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,t={}){t.constructor==Function&&(t={callback:t});let i=e.split("/"),a=i[i.length-1];this.icons[a]=t.icon,this.shorts[a]=t.short;let l=0,n=this,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.disabled=t.disabled,r.type=t.type,r.checked=t.checked),a.push(r),s(o,r[e])}};for(let r of(s(i[l++],this.items),this.items)){let o=Object.keys(r)[0],d=o.replace(/\s/g,"").replaceAll(".","");if(this.root.querySelector("#"+d))continue;let c=document.createElement("div");c.className="lexmenuentry",c.id=d,c.innerHTML="<span>"+o+"</span>",c.tabIndex="1","left"==t.position?this.root.prepend(c):("right"==t.position&&(c.right=!0),this.root.lastChild&&this.root.lastChild.right?this.root.lastChild.before(c):this.root.appendChild(c));let h=function(){n.root.querySelectorAll(".lexmenuentry").forEach(e=>{e.classList.remove("selected"),e.built=!1}),LX.root.querySelectorAll(".lexmenubox").forEach(e=>e.remove()),n.focused=!1},u=function(e,t,i,a){let l=document.createElement("div");l.className="lexmenubox",l.tabIndex="0",i.currentMenu=l;let s=i.classList.contains("lexmenuboxentry");s&&(l.dataset.submenu=!0);var r=i.getBoundingClientRect();l.style.left=(s?r.x+r.width:r.left)+"px",l.style.top=(s?r.y:r.bottom-4)+"px",r=l.getBoundingClientRect(),doAsync(()=>{l.dataset.open=!0},10),LX.root.appendChild(l);for(var o=0;o<e[t].length;++o){let d=e[t][o],c=Object.keys(d)[0],p=d[c].length,m="checkbox"==d.type,g=document.createElement("div");if(g.className="lexmenuboxentry",g.className+=(o==e[t].length-1?" last":"")+(d.disabled?" disabled":""),""==c)g.className=" lexseparator";else{g.id=c;let f=document.createElement("div");f.innerHTML="",f.classList="lexmenuboxentrycontainer",g.appendChild(f);let v=n.icons[c];m?f.innerHTML+="<input type='checkbox' >":v?f.innerHTML+="<a class='"+v+" fa-sm'></a>":(f.innerHTML+="<a class='fa-solid fa-sm noicon'></a>",f.classList.add("noicon")),f.innerHTML+="<div class='lexentryname'>"+c+"</div>"}let E=g.querySelector("input");if(E&&(E.checked=d.checked??!1,E.addEventListener("change",e=>{d.checked=E.checked;let t=d.callback;t&&(t.call(this,d.checked,c,g),h()),e.stopPropagation(),e.stopImmediatePropagation()})),l.appendChild(g),""==c)continue;if(l.addEventListener("keydown",function(e){e.preventDefault();let t=n.shorts[c];t&&(t=1==t.length?t.toLowerCase():t)==e.key&&g.click()}),g.addEventListener("click",e=>{E&&(d.checked=!d.checked);let t=d.callback;t&&(t.call(this,E?d.checked:c,E?c:g),h()),e.stopPropagation(),e.stopImmediatePropagation()}),!p){if(n.shorts[c]){let $=document.createElement("div");$.className="lexentryshort",$.innerText=n.shorts[c],g.appendChild($)}continue}let y=document.createElement("a");y.className="fa-solid fa-angle-right fa-xs",g.appendChild(y),g.addEventListener("mouseover",e=>{!g.built&&(g.built=!0,u(d,c,g,++a),e.stopPropagation())}),g.addEventListener("mouseleave",e=>{g.currentMenu&&g.currentMenu!=e.toElement&&(a=-1,delete g.built,g.currentMenu.remove(),delete g.currentMenu)})}l.style.width=l.offsetWidth+"px"},p=()=>{h(),c.classList.add("selected"),c.built=!0,u(r,o,c,-1)};c.addEventListener("click",()=>{let e=r.callback;if(e){e.call(this,o,c);return}p(),this.focused=!0}),c.addEventListener("mouseover",e=>{this.focused&&!c.built&&p()}),c.addEventListener("blur",e=>{!(e.relatedTarget&&e.relatedTarget.classList.contains("lexmenubox"))&&h()})}}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 n=document.createElement("div"),s=a.disabled??!1;n.className="lexmenubutton"+(s?" disabled":""),n.title=e??"",n.innerHTML="<a class='"+t+" lexicon' style='font-size:x-large;'></a>",n.style.padding="5px 10px",n.style.maxHeight="calc(100% - 10px)",n.style.alignItems="center","right"==a.float&&(n.right=!0),this.root.lastChild&&this.root.lastChild.right?this.root.lastChild.before(n):"left"==a.float?this.root.prepend(n):this.root.appendChild(n);let r=n.querySelector("a");r.addEventListener("click",e=>{i&&!s&&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 n=document.createElement("div"),s=a.disabled??!1;n.className="lexmenubutton"+(s?" disabled":""),n.title=e??"",n.innerHTML="<a><image src='"+t+"' class='lexicon' style='height:32px;'></a>",n.style.padding="5px",n.style.alignItems="center","right"==a.float&&(n.right=!0),this.root.lastChild&&this.root.lastChild.right?this.root.lastChild.before(n):"left"==a.float?this.root.prepend(n):this.root.appendChild(n);let r=n.querySelector("a");r.addEventListener("click",e=>{i&&!s&&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"),n=a.title,s=a.disabled??!1;l.className="lexmenubutton"+(s?" disabled":""),l.title=n??"",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&&!s){let t=l.querySelector("input");a.callback.call(this,e,t?.checked)}}),n&&(this.buttons[n]=l)}}}LX.Menubar=Menubar;class SideBar{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,doAsync(()=>{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 t=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 i=document.createElement("span");if(i.className="lexavatar",this.header.appendChild(i),e.headerImage){let a=document.createElement("img");a.src=e.headerImage,i.appendChild(a)}else if(e.headerIcon){let l=LX.makeIcon(e.headerIcon);i.appendChild(l)}{let n=document.createElement("div");this.header.appendChild(n);let s=document.createElement("span");s.innerHTML=e.headerTitle??"",n.appendChild(s);let r=document.createElement("span");r.innerHTML=e.headerSubtitle??"",n.appendChild(r)}if(this.collapsable){let o=LX.makeIcon("Sidebar","Toggle Sidebar");this.header.appendChild(o),o.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),this.toggleCollapsed()})}t+=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 d=document.createElement("span");if(d.className="lexavatar",this.footer.appendChild(d),e.footerImage){let c=document.createElement("img");c.src=e.footerImage,d.appendChild(c)}else if(e.footerIcon){let h=LX.makeIcon(e.footerIcon);d.appendChild(h)}{let u=document.createElement("div");this.footer.appendChild(u);let p=document.createElement("span");p.innerHTML=e.footerTitle??"",u.appendChild(p);let m=document.createElement("span");m.innerHTML=e.footerSubtitle??"",u.appendChild(m)}let g=LX.makeIcon("MenuArrows");this.footer.appendChild(g),t+=52}this.content.style.height=`calc(100% - ${t}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),doAsync(()=>{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,n=(e,a)=>{if(void 0==e)return;let s=null;if(a.forEach(t=>{let i=Object.keys(t),a=i.find(t=>t==e);a&&(s=t[a])}),s)n(i[l++],s);else{let r={};r[e]=[];let o=i[l++];o||(r.callback=t.callback,r.group=this.currentGroup,r.options=t),a.push(r),n(o,r[e])}};n(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 t=e.options??{};if(e.dom)continue;let i=Object.keys(e)[0],a=i.replace(/\s/g,"").replaceAll(".",""),l=null,n=document.createElement("div");if(n.className="lexsidebarentry "+(t.className??""),n.id=a,e.group){let s=e.group.replace(/\s/g,"").replaceAll(".","");if(l=this.content.querySelector("#"+s)){if(!l.classList.contains("lexsidebargroup"))throw"Bad id: "+e.group}else{(l=document.createElement("div")).id=s,l.className="lexsidebargroup",this.content.appendChild(l);let r=document.createElement("div");r.className="lexsidebargrouptitle",l.appendChild(r);let o=document.createElement("div");if(o.innerHTML=e.group,r.appendChild(o),null!=this.groups[e.group]){let d=document.createElement("a");d.className=(this.groups[e.group].icon??"")+" lexicon",r.appendChild(d),d.addEventListener("click",t=>{this.groups[e.group].callback&&this.groups[e.group].callback(e.group,t)})}}}if(""==a){let c=document.createElement("div");c.className="lexsidebarseparator",this.content.appendChild(c);continue}this.collapseContainer?(this.collapseContainer.appendChild(n),this.collapseQueue--,this.collapseQueue||delete this.collapseContainer):l?l.appendChild(n):this.content.appendChild(n);let h=document.createElement("div");if(n.appendChild(h),e.dom=h,"checkbox"==t.type){e.value=t.value??!1;let u=new Panel;e.checkbox=u.addCheckbox(null,e.value,(a,l)=>{l.preventDefault(),l.stopPropagation();let n=t.callback;e.value=a,n&&n.call(this,i,a,l)},{label:i,signal:"@checkbox_"+i}),h.appendChild(u.root.childNodes[0])}else{if(t.icon){let p=document.createElement("i");p.className=t.icon,h.appendChild(p)}let m=document.createElement("a");m.innerHTML=i,h.appendChild(m)}if(n.addEventListener("click",a=>{if(!(a.target&&a.target.classList.contains("lexcheckbox"))){if(t.collapsable)h.querySelector(".collapser").click();else{let l=t.callback;l&&l.call(this,i,e.value,a),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")}}),t.action){let g=LX.makeIcon(t.action.icon??"MoreHorizontal",t.action.name);h.appendChild(g),g.addEventListener("click",e=>{e.preventDefault(),e.stopImmediatePropagation();let a=t.action.callback;a&&a.call(this,i,e)})}else if(t.collapsable){let f=document.createElement("div");Object.assign(f.style,{width:"100%",display:"none"}),LX.makeCollapsible(h,f,l??this.content),this.collapseQueue=t.collapsable,this.collapseContainer=f}let v=document.createElement("span");if(v.className="lexsidebarentrydesc",v.innerHTML=i,n.appendChild(v),h.addEventListener("mouseenter",()=>{setTimeout(()=>{v.style.display="unset"},150)}),h.addEventListener("mouseleave",()=>{setTimeout(()=>{v.style.display="none"},150)}),!e[i].length)continue;let E=document.createElement("div");E.className="lexsidebarsubentrycontainer",l?l.appendChild(E):this.content.appendChild(E);for(var $=0;$<e[i].length;++$){let y=e[i][$],x=y.options??{},L=Object.keys(y)[0],b=document.createElement("div");if(b.innerHTML=`<span>${L}</span>`,x.action){let w=LX.makeIcon(x.action.icon??"MoreHorizontal",x.action.name);b.appendChild(w),w.addEventListener("click",e=>{e.preventDefault(),e.stopImmediatePropagation();let t=x.action.callback;t&&t.call(this,L,e)})}b.className="lexsidebarentry",b.id=L,E.appendChild(b),b.addEventListener("click",e=>{let t=x.callback;t&&t.call(this,L,b,e),this.root.querySelectorAll(".lexsidebarentry").forEach(e=>e.classList.remove("selected")),n.classList.add("selected")})}}}}LX.SideBar=SideBar;class Widget{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=[Widget.BUTTON,Widget.LIST,Widget.FILE,Widget.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){Widget.NO_CONTEXT_TYPES.includes(this.type)||addContextMenu(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===Widget.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 Widget.TEXT:return"Text";case Widget.TEXTAREA:return"TextArea";case Widget.BUTTON:return"Button";case Widget.DROPDOWN:return"Dropdown";case Widget.CHECKBOX:return"Checkbox";case Widget.TOGGLE:return"Toggle";case Widget.RADIO:return"Radio";case Widget.COLOR:return"Color";case Widget.RANGE:return"Range";case Widget.NUMBER:return"Number";case Widget.VECTOR:return"Vector";case Widget.TREE:return"Tree";case Widget.PROGRESS:return"Progress";case Widget.FILE:return"File";case Widget.LAYERS:return"Layers";case Widget.ARRAY:return"Array";case Widget.LIST:return"List";case Widget.TAGS:return"Tags";case Widget.CURVE:return"Curve";case Widget.KNOB:return"Knob";case Widget.SIZE:return"Size";case Widget.PAD:return"Pad";case Widget.FORM:return"Form";case Widget.DIAL:return"Dial";case Widget.COUNTER:return"Counter";case Widget.TABLE:return"Table";case Widget.CUSTOM:return this.customName}console.error(`Unknown Widget type: ${this.type}`)}refresh(){}}function ADD_CUSTOM_WIDGET(e,t={}){let i=simple_guidGenerator();Panel.prototype["add"+e]=function(a,l,n){let s=this.create_widget(a,Widget.CUSTOM,t);s.customName=e,s.customIdx=i,s.onGetValue=()=>l,s.onSetValue=(e,t)=>{l=e,h(),r.querySelector(".lexcustomitems").toggleAttribute("hidden",!1),t||this._trigger(new IEvent(a,l,null),n)};let r=s.domEl;r.style.flexWrap="wrap";let o,d,c=t.default??{},h=()=>{l&&(s.instance=l=Object.assign(deepCopy(c),l)),o&&o.remove(),d&&d.remove(),(o=document.createElement("div")).className="lexcustomcontainer",o.style.width="calc( 100% - "+LX.DEFAULT_NAME_WIDTH+")",this.queue(o);let i="<a class='fa-solid "+(t.icon??"fa-cube")+"' style='float:left'></a>";i+=e+(l?"":" [empty]"),i+="<a class='fa-solid "+(l?"fa-bars-staggered":" ")+" menu' style='float:right; width:5%;'></a>";let u=this.addButton(null,i,(t,i)=>{l?r.querySelector(".lexcustomitems").toggleAttribute("hidden"):addContextMenu(null,i,t=>{t.add("New "+e,()=>{l={},h(),r.querySelector(".lexcustomitems").toggleAttribute("hidden",!1)})})},{buttonClass:"custom"});if(this.clearQueue(),l&&u.querySelector("a.menu").addEventListener("click",e=>{e.stopImmediatePropagation(),e.stopPropagation(),addContextMenu(null,e,e=>{e.add("Clear",()=>{l=null,h()})})}),(d=document.createElement("div")).className="lexcustomitems",d.toggleAttribute("hidden",!0),r.appendChild(o),r.appendChild(d),l){this.queue(d);let p=(e,t,i)=>{l[e]=t,this._trigger(new IEvent(a,l,i),n)};for(let m in c){let g=l[m]??c[m];switch(g.constructor){case String:"#"===g[0]?this.addColor(m,g,p.bind(this,m)):this.addText(m,g,p.bind(this,m));break;case Number:this.addNumber(m,g,p.bind(this,m));break;case Boolean:this.addCheckbox(m,g,p.bind(this,m));break;case Array:g.length>4?this.addArray(m,g,p.bind(this,m)):this._add_vector(g.length,m,g,p.bind(this,m))}}this.clearQueue()}};h()}}LX.Widget=Widget,LX.ADD_CUSTOM_WIDGET=ADD_CUSTOM_WIDGET;class NodeTree{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,t,i=0,a){let l=this,n=this.domEl.querySelector("#lexnodetree_filter");if(t.children=t.children??[],n&&!t.id.includes(n.value)||void 0!=a&&a!=t.id){for(var s=0;s<t.children.length;++s)this._create_item(t,t.children[s],i+1,a);return}let r=this.domEl.querySelector("ul");t.visible=t.visible??!0,t.parent=e;let o=t.children.length>0,d=this.selected.indexOf(t)>-1||t.selected;if(this.options.onlyFolders){let c=!1;t.children.forEach(e=>c|="folder"==e.type),o=!!c}let h=document.createElement("li");h.className="lextreeitem datalevel"+i+(o?" parent":"")+(d?" selected":""),h.id=LX.getSupportedDOMName(t.id),h.tabIndex="0";let u=this.options.skip_default_icon??!0?"":"fa-solid fa-square";o&&(u=t.closed?"fa-solid fa-caret-right":"fa-solid fa-caret-down"),h.innerHTML="<a class='"+u+" hierarchy'></a>",u=t.icon,t.icon&&(t.icon.includes("fa-")?h.innerHTML+="<a class='"+t.icon+" tree-item-icon'></a>":h.innerHTML+="<img src='https://raw.githubusercontent.com/jxarco/lexgui.js/master/"+t.icon+"'>"),h.innerHTML+=t.rename?"":t.id,h.setAttribute("draggable",!0),h.style.paddingLeft=(o?0:3)+(3+(i+1)*15)+"px",r.appendChild(h),h.addEventListener("click",e=>{if(m){m=!1;return}e.shiftKey||(r.querySelectorAll("li").forEach(e=>{e.classList.remove("selected")}),this.selected.length=0);let i=this.selected.indexOf(t);if(i>-1?(h.classList.remove("selected"),this.selected.splice(i,1)):(h.classList.add("selected"),this.selected.push(t)),o&&t.id.length>1){if(t.closed=!1,l.onevent){let a=new TreeEvent(TreeEvent.NODE_CARETCHANGED,t,t.closed);l.onevent(a)}l.frefresh(t.id)}if(l.onevent){let n=new TreeEvent(TreeEvent.NODE_SELECTED,e.shiftKey?this.selected:t);n.multiple=e.shiftKey,l.onevent(n)}}),h.addEventListener("dblclick",function(){if((l.options.rename??!0)&&(t.rename=!0,l.refresh()),l.onevent){let e=new TreeEvent(TreeEvent.NODE_DBLCLICKED,t);l.onevent(e)}}),h.addEventListener("contextmenu",e=>{if(e.preventDefault(),!l.onevent)return;let i=new TreeEvent(TreeEvent.NODE_CONTEXTMENU,this.selected.length>1?this.selected:t,e);i.multiple=this.selected.length>1,LX.addContextMenu(i.multiple?"Selected Nodes":i.node.id,i.value,e=>{i.panel=e}),l.onevent(i),(this.options.addDefault??!1)==!0&&(i.panel.items&&i.panel.add(""),i.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(t)}),i.panel.add("Delete",{callback:()=>{if(!t.parent)return;if(l.onevent){let i=new TreeEvent(TreeEvent.NODE_DELETED,t,e);l.onevent(i)}let a=t.parent.children,n=a.indexOf(t);a.splice(n,1),this.refresh()}}))}),h.addEventListener("keydown",e=>{if(!t.rename){if(e.preventDefault(),"Delete"==e.key){if(l.onevent){let i=new TreeEvent(TreeEvent.NODE_DELETED,this.selected.length>1?this.selected:t,e);i.multiple=this.selected.length>1,l.onevent(i)}for(let a of this.selected){let n=a.parent.children,s=n.indexOf(a);n.splice(s,1)}this.selected.length=0,this.refresh()}else if("ArrowUp"==e.key||"ArrowDown"==e.key){var r=this.selected.length>1?"ArrowUp"==e.key?this.selected.shift():this.selected.pop():this.selected[0],o=this.domEl.querySelector("#"+LX.getSupportedDOMName(r.id)),d="ArrowUp"==e.key?o.previousSibling:o.nextSibling;d&&d.click()}}});let p=document.createElement("input");p.toggleAttribute("hidden",!t.rename),p.value=t.id,h.appendChild(p),t.rename&&(h.classList.add("selected"),p.focus()),p.addEventListener("keyup",function(e){if("Enter"==e.key){if(this.value=this.value.replace(/\s/g,"_"),l.onevent){let i=new TreeEvent(TreeEvent.NODE_RENAMED,t,this.value);l.onevent(i)}t.id=LX.getSupportedDOMName(this.value),delete t.rename,l.frefresh(t.id),r.querySelector("#"+t.id).classList.add("selected")}else"Escape"==e.key&&(delete t.rename,l.frefresh(t.id))}),p.addEventListener("blur",function(e){delete t.rename,l.refresh()}),(this.options.draggable??!0)&&(e&&h.addEventListener("dragstart",e=>{window.__tree_node_dragged=t}),h.addEventListener("dragover",e=>{e.preventDefault()},!1),h.addEventListener("dragenter",e=>{e.target.classList.add("draggingover")}),h.addEventListener("dragleave",e=>{e.target.classList.remove("draggingover")}),h.addEventListener("drop",e=>{e.preventDefault();let i=window.__tree_node_dragged;if(!i)return;let a=t;if(i.id==a.id){console.warn("Cannot parent node to itself!");return}let n=function(e,t){var i=!1;for(var a of t.children){if(a.id==e.id)return!0;i|=n(e,a)}return i};if(n(a,i)){console.warn("Cannot parent node to a current child!");return}if(l.onevent){let s=new TreeEvent(TreeEvent.NODE_DRAGGED,i,a);l.onevent(s)}let r=i.parent.children.findIndex(e=>e.id==i.id),o=i.parent.children.splice(r,1);a.children.push(o[0]),l.refresh(),delete window.__tree_node_dragged}));let m=!1;if(o&&h.querySelector("a.hierarchy").addEventListener("click",function(e){if(m=!0,e.stopImmediatePropagation(),e.stopPropagation(),t.closed=!t.closed,l.onevent){let i=new TreeEvent(TreeEvent.NODE_CARETCHANGED,t,t.closed);l.onevent(i)}l.frefresh(t.id)}),!t.skipVisibility){let g=document.createElement("a");g.className="itemicon fa-solid fa-eye"+(t.visible?"":"-slash"),g.title="Toggle visible",g.addEventListener("click",function(e){if(e.stopPropagation(),t.visible=void 0!==t.visible&&!t.visible,this.className="itemicon fa-solid fa-eye"+(t.visible?"":"-slash"),l.onevent){let i=new TreeEvent(TreeEvent.NODE_VISIBILITY,t,t.visible);l.onevent(i)}}),h.appendChild(g)}if(t.actions)for(var s=0;s<t.actions.length;++s){let f=t.actions[s];var v=document.createElement("a");v.className="itemicon "+f.icon,v.title=f.name,v.addEventListener("click",function(e){f.callback(t,v),e.stopPropagation()}),h.appendChild(v)}if(void 0!=a&&t.id==a&&(this.selected=[t],h.click()),!t.closed)for(var s=0;s<t.children.length;++s){let E=t.children[s];(!this.options.onlyFolders||"folder"==E.type)&&this._create_item(t,E,i+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 Panel{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 t=this.widgets[e].options.signal;for(let i=0;i<LX.signals[t].length;i++)LX.signals[t][i]==this.widgets[e]&&(LX.signals[t]=[...LX.signals[t].slice(0,i),...LX.signals[t].slice(i+1)])}if(this.signals)for(let a=0;a<this.signals.length;a++){let l=Object.values(this.signals[a])[0],n=l.options.signal;for(let s=0;s<LX.signals[n].length;s++)LX.signals[n][s]==l&&(LX.signals[n]=[...LX.signals[n].slice(0,s),...LX.signals[n].slice(s+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 Branch(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 n=new CustomEvent(t,{detail:i,bubbles:a,cancelable:l});e.dispatchEvent(n)}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,t,i={}){let a=new Widget(e,t,i),l=document.createElement("div");if(l.className="lexwidget",l.id=i.id??"",l.title=i.title??"",i.className&&(l.className+=" "+i.className),t!=Widget.TITLE&&(l.style.width="calc(100% - "+(this.current_branch||t==Widget.FILE?10:20)+"px)",i.width&&(l.style.width=l.style.minWidth=i.width),i.maxWidth&&(l.style.maxWidth=i.maxWidth),i.minWidth&&(l.style.minWidth=i.minWidth),i.height&&(l.style.height=l.style.minHeight=i.height)),void 0!=e){if(!i.hideName){let n=document.createElement("div");n.className="lexwidgetname",i.justifyName&&n.classList.add("float-"+i.justifyName),n.innerHTML=e||"",n.title=i.title??n.innerHTML,n.style.width=i.nameWidth||LX.DEFAULT_NAME_WIDTH,l.appendChild(n),l.domName=n,n.addEventListener("contextmenu",function(e){e.preventDefault(),a.oncontextmenu(e)})}this.widgets[e]=a}return i.signal&&(e||(this.signals||(this.signals=[]),this.signals.push({[i.signal]:a})),LX.addSignal(i.signal,a)),a.domEl=l,l.jsInstance=a,this._inline_widgets_left>0&&!i.skipInlineCount?(this._inlineWidgets||(this._inlineWidgets=[]),(e=>{this.queuedContainer?this._inlineWidgets.push([e,this.queuedContainer]):this._inlineWidgets.push(e)})(l),this._inline_widgets_left--,this._inline_widgets_left||this.endLine()):(e=>{i.container?i.container.appendChild(e):this.queuedContainer?this.queuedContainer.appendChild(e):this.current_branch?(i.skipWidget||this.current_branch.widgets.push(a),this.current_branch.content.appendChild(e)):(e.classList.add("nobranch"),this.root.appendChild(e))})(l),a}_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,Widget.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 n of i.widgets){if(!l){if(!n.name)continue;t.toLowerCase();let s=n.name.toLowerCase();if(!s.includes(t))continue}this.queuedContainer.appendChild(n.domEl)}this.clearQueue();return}}_filterOptions(e,t){let i=!t.length,a=[];for(let l=0;l<e.length;l++){let n=e[l];if(!i){let s="string"==typeof n?n:n.value,r=t.toLowerCase(),o=s.toLowerCase();if(!o.includes(r))continue}a.push(n)}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,Widget.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,Widget.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 n=document.createElement("a");n.innerText=e,n.href=t.link,n.target=t.target??"",n.className="lextitle link",Object.assign(n.style,t.style??{}),i.replaceWith(n)}return i}addText(e,t,i,a={}){let l=this.create_widget(e,Widget.TEXT,a);l.onGetValue=()=>r.value,l.onSetValue=(e,t)=>{this.disabled?r.innerText=e:r.value=e,Panel._dispatch_event(r,"focusout",t)},l.valid=()=>{if(""==r.pattern)return!0;let e=RegExp(r.pattern);return e.test(r.value)};let n=l.domEl;l.name&&!a.skipReset&&Panel._add_reset_property(n.domName,function(){r.value=r.iValue,this.style.display="none",Panel._dispatch_event(r,"focusout")});let s=document.createElement("div");s.className="lextext"+(a.warning?" lexwarning":""),s.style.width=a.inputWidth||"calc( 100% - "+LX.DEFAULT_NAME_WIDTH+" )",s.style.display="flex",a.textClass&&s.classList.add(a.textClass),this.disabled=(a.disabled||a.warning)??!!a.url;let r=null;if(this.disabled){r=document.createElement(a.url?"a":"div"),a.url&&(r.href=a.url,r.target="_blank");let o=a.warning?'<i class="fa-solid fa-triangle-exclamation"></i>':"";r.innerHTML=o+t||"",r.style.width="100%",r.style.textAlign=a.float??""}else{(r=document.createElement("input")).type=a.type||"",r.value=r.iValue=t||"",r.style.width="100%",r.style.textAlign=a.float??"",r.setAttribute("placeholder",a.placeholder??""),a.required&&r.setAttribute("required",a.required),a.pattern&&r.setAttribute("pattern",a.pattern);var d=(function(t,a){if(!l.valid())return;let s=a.detail,o=n.querySelector(".lexwidgetname .lexicon");o&&(o.style.display=t!=r.iValue?"block":"none"),s||this._trigger(new IEvent(e,t,a),i)}).bind(this);let c=a.trigger??"default";if("default"==c?(r.addEventListener("keyup",function(e){"Enter"==e.key&&d(e.target.value,e)}),r.addEventListener("focusout",function(e){d(e.target.value,e)})):"input"==c&&r.addEventListener("input",function(e){d(e.target.value,e)}),r.addEventListener("mousedown",function(e){e.stopImmediatePropagation(),e.stopPropagation()}),a.icon){let h=document.createElement("a");h.className="inputicon "+a.icon,s.appendChild(h)}}return Object.assign(r.style,a.style??{}),s.appendChild(r),n.appendChild(s),l.name||(n.className+=" noname",s.style.width="100%"),l}addTextArea(e,t,i,a={}){let l=this.create_widget(e,Widget.TEXTAREA,a);l.onGetValue=()=>r.value,l.onSetValue=(e,t)=>{r.value=e,Panel._dispatch_event(r,"focusout",t)};let n=l.domEl;l.name&&!a.skipReset&&Panel._add_reset_property(n.domName,function(){r.value=r.iValue,this.style.display="none",Panel._dispatch_event(r,"focusout")});let s=document.createElement("div");s.className="lextextarea",s.style.width=a.inputWidth||"calc( 100% - "+LX.DEFAULT_NAME_WIDTH+" )",s.style.height=a.height,s.style.display="flex";let r=document.createElement("textarea");r.value=r.iValue=t||"",r.style.width="100%",r.style.textAlign=a.float??"",Object.assign(r.style,a.style??{}),a.disabled&&r.setAttribute("disabled",!0),a.placeholder&&r.setAttribute("placeholder",a.placeholder);var o=(function(t,a){let l=a.detail,s=n.querySelector(".lexwidgetname .lexicon");s&&(s.style.display=t!=r.iValue?"block":"none"),l||this._trigger(new IEvent(e,t,a),i)}).bind(this);let d=a.trigger??"default";if("default"==d?(r.addEventListener("keyup",function(e){"Enter"==e.key&&o(e.target.value,e)}),r.addEventListener("focusout",function(e){o(e.target.value,e)})):"input"==d&&r.addEventListener("input",function(e){o(e.target.value,e)}),a.icon){let c=document.createElement("a");c.className="inputicon "+a.icon,s.appendChild(c)}return s.appendChild(r),n.appendChild(s),l.name||(n.className+=" noname",s.style.width="100%"),doAsync(()=>{a.fitHeight&&(r.style.height=r.scrollHeight+"px")},10),l}addLabel(e,t={}){return t.disabled=!0,this.addText(null,e,null,t)}addButton(e,t,i,a={}){let l=this.create_widget(e,Widget.BUTTON,a);l.onGetValue=()=>s.innerText,l.onSetValue=(e,t)=>{s.innerHTML=a.icon?"<a class='"+a.icon+"'></a>":a.img?"<img src='"+a.img+"'>":"<span>"+(e||"")+"</span>"};let n=l.domEl;var s=document.createElement("button");return s.title=a.title??"",s.className="lexbutton "+(a.buttonClass??""),a.selected&&s.classList.add("selected"),s.innerHTML=a.icon?"<a class='"+a.icon+"'></a>":a.img?"<img src='"+a.img+"'>":"<span>"+(t||"")+"</span>",s.style.width="calc( 100% - "+(a.nameWidth??LX.DEFAULT_NAME_WIDTH)+")",a.disabled&&s.setAttribute("disabled",!0),s.addEventListener("click",l=>{a.selectable&&(a.parent&&a.parent.querySelectorAll(".lexbutton.selected").forEach(e=>{e!=s&&e.classList.remove("selected")}),s.classList.toggle("selected")),this._trigger(new IEvent(e,t,l),i)}),n.appendChild(s),l.name||(s.className+=" noname",s.style.width="100%"),n}addComboButtons(e,t,i={}){let a=this.create_widget(e,Widget.BUTTON,i),l=a.domEl,n=this,s=document.createElement("div");s.className="lexcombobuttons ",i.float&&(s.className+=i.float),s.style.width="calc( 100% - "+LX.DEFAULT_NAME_WIDTH+")";let r=document.createElement("div");r.className="lexcombobuttonsbox ";let o=!i.noSelection,d=o&&(i.toggle??!1);for(let c of t){if(!c.value)throw"Set 'value' for each button!";let h=document.createElement("button");h.className="lexbutton combo",h.title=c.icon?c.value:"",h.id=c.id??"",i.buttonClass&&h.classList.add(i.buttonClass),o&&(c.selected||i.selected==c.value)&&h.classList.add("selected"),h.innerHTML=(c.icon?"<a class='"+c.icon+"'></a>":"")+"<span>"+(c.icon?"":c.value)+"</span>",c.disabled&&h.setAttribute("disabled",!0),h.addEventListener("click",function(t){o&&(d?this.classList.toggle("selected"):(s.querySelectorAll("button").forEach(e=>e.classList.remove("selected")),this.classList.add("selected"))),n._trigger(new IEvent(e,c.value,t),c.callback)}),r.appendChild(h)}return a.name||(l.className+=" noname",s.style.width="100%"),s.appendChild(r),l.appendChild(s),a}addCard(e,t={}){t.hideName=!0;let i=this.create_widget(e,Widget.CARD,t),a=i.domEl,l=document.createElement("div");if(l.className="lexcard",l.style.width="100%",t.img){let n=document.createElement("img");n.src=t.img,l.appendChild(n),void 0!=t.link&&(n.style.cursor="pointer",n.addEventListener("click",function(){let e=l.querySelector("a");e&&e.click()}))}let s=document.createElement("span");if(s.innerText=e,void 0!=t.link){let r=document.createElement("a");r.innerText=e,r.href=t.link,r.target=t.target??"",s.innerText="",s.appendChild(r)}return l.appendChild(s),t.callback&&(l.style.cursor="pointer",l.addEventListener("click",i=>{this._trigger(new IEvent(e,null,i),t.callback)})),a.appendChild(l),i}addForm(e,t,i,a={}){if(t.constructor!=Object){console.error("Form data must be an Object");return}a.hideName=!0;let l=this.create_widget(e,Widget.FORM,a);l.onGetValue=()=>s.formData,l.onSetValue=(e,t)=>{s.formData=e;let i=s.querySelectorAll(".lexwidget");for(let a=0;a<i.length;++a){let l=i[a];if(l.jsInstance.type!=LX.Widget.TEXT)continue;let n=i[a].querySelector(".lexwidgetname").innerText,r=i[a].querySelector(".lextext input");r.value=e[n]??"",Panel._dispatch_event(r,"focusout",t)}};let n=l.domEl,s=document.createElement("div");for(let r in s.className="lexformdata",this.queue(s),s.formData={},t){let o=t[r];o.constructor!=Object&&(o={}),o.placeholder=o.placeholder??r,o.width="calc(100% - 10px)",this.addLabel(r,{textClass:"formlabel"}),o.textWidget=this.addText(null,o.constructor==Object?o.value:o,e=>{s.formData[r]=e},o),s.formData[r]=o.constructor==Object?o.value:o}return this.addBlank(),this.addButton(null,a.actionName??"Submit",(e,a)=>{for(let l in t)if(!t[l].textWidget.valid())return;i&&i(s.formData,a)},{buttonClass:"primary",width:"calc(100% - 10px)"}),this.clearQueue(),n.appendChild(s),(!l.name||a.hideName)&&(n.className+=" noname",s.style.width="100%"),l}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,Widget.CONTENT,t);return a.domEl.appendChild(e),a}async addImage(e,t={}){if(!e)return;t.hideName=!0;let i=this.create_widget(null,Widget.IMAGE,t),a=i.domEl,l=document.createElement("div");l.className="leximage",l.style.width="100%";let n=document.createElement("img");for(let s in n.src=e,t.style)n.style[s]=t.style[s];return await n.decode(),l.appendChild(n),a.appendChild(l),i}addDropdown(e,t,i,a,l={}){let n=this.create_widget(e,Widget.DROPDOWN,l);n.onGetValue=()=>s.querySelector("li.selected").getAttribute("value"),n.onSetValue=(t,l)=>{let n=s.querySelector(".lexwidgetname .lexicon");n&&(n.style.display=t!=d.iValue?"block":"none"),i=t,m.querySelectorAll("li").forEach(e=>{e.getAttribute("value")==i&&e.click()}),l||this._trigger(new IEvent(e,i,null),a)};let s=n.domEl,r=this;n.name&&!l.skipReset&&Panel._add_reset_property(s.domName,function(){i=d.iValue,m.querySelectorAll("li").forEach(e=>{e.getAttribute("value")==i&&e.click()}),this.style.display="none"});let o=document.createElement("div");o.className="lexdropdown",o.style.width=l.inputWidth||"calc( 100% - "+LX.DEFAULT_NAME_WIDTH+")";let d=document.createElement("div");d.className="lexdropdown lexoption",d.name=e,d.iValue=i;let c=i;c+="<a class='fa-solid fa-angle-down' style='float:right; margin-right: 3px;'></a>",this.queue(o);let h=e=>{let t=e.getParentArea(),i=u.getBoundingClientRect(),a=e.parentElement.closest("dialog");{let l=e.offsetHeight,n=i.y,s=window.innerHeight;if(t){let r=t.getBoundingClientRect();s=r.y+r.height}if(a){let o=a.getBoundingClientRect();n-=o.y}e.style.top=n+u.offsetHeight+"px";let d=n+l>s;d&&(e.style.top=n-l+"px",e.classList.add("place-above"))}{let c=e.offsetWidth,h=i.x;if(e.style.minWidth=i.width+"px",a){let p=a.getBoundingClientRect();h-=p.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")}},u=this.addButton(null,c,(e,t)=>{if(m.unfocus_event){delete m.unfocus_event;return}p.classList.remove("place-above");let i=p.hasAttribute("open");i?p.close():(p.show(),h(p)),g&&g.querySelector("input").focus()},{buttonClass:"array",skipInlineCount:!0,disabled:l.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)};let p=document.createElement("dialog");p.className="lexdropdownoptions";let m=document.createElement("ul");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;else if("lexinput-filter"==e.target.className)return;p.close()});let g=null;l.filter&&(g=this._addFilter(l.placeholder??"Search...",{container:m,callback:this._filterOptions.bind(m,t)}),m.appendChild(g),g.addEventListener("focusout",function(e){!(e.relatedTarget&&"UL"==e.relatedTarget.tagName&&e.relatedTarget.classList.contains("lexoptions"))&&p.close()}));let f=document.createElement("span");return f.style.height="calc(100% - 25px)",m.appendChild(f),m.refresh=l=>{if(f.innerHTML="",!l.length){let n=l.emptyMsg??"No options found.",o=document.createElement("div");o.className="option",o.style.flexDirection="unset",o.innerHTML=n;let c=document.createElement("li");c.className="lexdropdownitem empty",c.appendChild(o),f.appendChild(c);return}for(let h=0;h<l.length;h++){let v=l[h],E=document.createElement("li"),$=document.createElement("div");if($.className="option",E.appendChild($),E.addEventListener("click",l=>{p.close();let n=s.querySelector(".lexoptions .selected");n&&n.classList.remove("selected"),i=l.currentTarget.getAttribute("value"),l.currentTarget.toggleAttribute("hidden",!1),l.currentTarget.classList.add("selected"),u.refresh(i);let o=s.querySelector(".lexwidgetname .lexicon");o&&(o.style.display=i!=d.iValue?"block":"none"),r._trigger(new IEvent(e,i,null),a),g&&(g.querySelector("input").value="",this._filterOptions.bind(m,t,"")())}),v.constructor!=Object)$.style.flexDirection="unset",$.innerHTML="</a><span>"+v+"</span><a class='fa-solid fa-check'>",$.value=v,E.setAttribute("value",v),E.className="lexdropdownitem",v==i&&(E.classList.add("selected"),d.innerHTML=v);else{let y=document.createElement("img");y.src=v.src,E.setAttribute("value",v.value),E.className="lexlistitem",$.innerText=v.value,$.className+=" media",$.prepend(y),$.setAttribute("value",v.value),$.setAttribute("data-index",h),$.setAttribute("data-src",v.src),$.setAttribute("title",v.value),i==v.value&&E.classList.add("selected")}f.appendChild(E)}},m.refresh(t),o.appendChild(p),s.appendChild(o),n.name||(s.className+=" noname",o.style.width="100%"),n}addCurve(e,t,i,a={}){if(!e)throw"Set Widget Name!";let l=this,n=this.create_widget(e,Widget.CURVE,a);n.onGetValue=()=>JSON.parse(JSON.stringify(d.element.value)),n.onSetValue=(t,a)=>{let n=s.querySelector(".lexwidgetname .lexicon");n&&(n.style.display=t!=d.element.value?"block":"none"),d.element.value=JSON.parse(JSON.stringify(t)),d.redraw(),a||l._trigger(new IEvent(e,d.element.value,null),i)};let s=n.domEl,r=JSON.parse(JSON.stringify(t));a.skipReset||Panel._add_reset_property(s.domName,function(t){this.style.display="none",d.element.value=JSON.parse(JSON.stringify(r)),d.redraw(),l._trigger(new IEvent(e,d.element.value,t),i)});var o=document.createElement("div");o.className="lexcurve",o.style.width="calc( 100% - "+LX.DEFAULT_NAME_WIDTH+")",a.callback=(t,a)=>{let n=s.querySelector(".lexwidgetname .lexicon");n&&(n.style.display=t!=r?"block":"none"),l._trigger(new IEvent(e,t,a),i)},a.name=e;let d=new Curve(this,t,a);return o.appendChild(d.element),s.appendChild(o),n.onresize=d.redraw.bind(d),n.curveInstance=d,doAsync(()=>{d.canvas.width=o.offsetWidth,d.redraw()}),n}addDial(e,t,i,a={}){let l=this,n=this.create_widget(e,Widget.DIAL,a);n.onGetValue=()=>JSON.parse(JSON.stringify(d.element.value)),n.onSetValue=(t,a)=>{let n=s.querySelector(".lexwidgetname .lexicon");n&&(n.style.display=t!=d.element.value?"block":"none"),d.element.value=JSON.parse(JSON.stringify(t)),d.redraw(),a||l._trigger(new IEvent(e,d.element.value,null),i)};let s=n.domEl,r=JSON.parse(JSON.stringify(t));n.name&&!a.skipReset&&Panel._add_reset_property(s.domName,function(t){this.style.display="none",d.element.value=JSON.parse(JSON.stringify(r)),d.redraw(),l._trigger(new IEvent(e,d.element.value,t),i)});var o=document.createElement("div");o.className="lexcurve",o.style.width=n.name?"calc( 100% - "+LX.DEFAULT_NAME_WIDTH+")":"100%",a.callback=(t,a)=>{let n=s.querySelector(".lexwidgetname .lexicon");n&&(n.style.display=t!=r?"block":"none"),l._trigger(new IEvent(e,t,a),i)},a.name=e;let d=new Dial(this,t,a);return o.appendChild(d.element),s.appendChild(o),n.onresize=d.redraw.bind(d),n.curveInstance=d,doAsync(()=>{d.element.style.height=d.element.offsetWidth+"px",d.canvas.width=d.element.offsetWidth,o.style.width=d.element.offsetWidth+"px",d.canvas.height=d.canvas.width,d.redraw()}),n}addLayers(e,t,i,a={}){if(!e)throw"Set Widget Name!";let l=this,n=this.create_widget(e,Widget.LAYERS,a);n.onGetValue=()=>s.value,n.onSetValue=(a,n)=>{let r=s.querySelector(".lexwidgetname .lexicon");r&&(r.style.display=a!=o?"block":"none"),t=s.value=a,d(),n||l._trigger(new IEvent(e,t),i)};let s=n.domEl;Panel._add_reset_property(s.domName,function(a){this.style.display="none",t=s.value=o,d(),l._trigger(new IEvent(e,t,a),i)});var r=document.createElement("div");r.className="lexlayers",r.style.width="calc( 100% - "+LX.DEFAULT_NAME_WIDTH+")";let o=s.value=t,d=()=>{r.innerHTML="";let a=t.toString(2),l=a.length;for(var n=0;n<16-l;++n)a="0"+a;for(let d=0;d<16;++d){let c=document.createElement("div");if(c.className="lexlayer",void 0!=t){let h=a[16-d-1];void 0!=h&&"1"==h&&c.classList.add("selected")}c.innerText=d+1,c.title="Bit "+d+", value "+(1<<d),r.appendChild(c),c.addEventListener("click",a=>{a.stopPropagation(),a.stopImmediatePropagation(),a.target.classList.toggle("selected"),t^=1<<d,s.value=t;let l=s.querySelector(".lexwidgetname .lexicon");l&&(l.style.display=t!=o?"block":"none"),this._trigger(new IEvent(e,t,a),i)})}};return d(),s.appendChild(r),n}addArray(e,t=[],i,a={}){if(!e)throw"Set Widget Name!";let l=this.create_widget(e,Widget.ARRAY,a);l.onGetValue=()=>{let e=n.querySelectorAll("input"),t=[];for(var i of e)t.push(i.value);return t},l.onSetValue=(a,l)=>{t=a,c(),l||this._trigger(new IEvent(e,t,null),i)};let n=l.domEl;n.style.flexWrap="wrap";var s=document.createElement("div");s.className="lexarray",s.style.width="calc( 100% - "+LX.DEFAULT_NAME_WIDTH+")",this.queue(s);let r="<a class='fa-solid fa-angle-down' style='float:right; margin-right: 3px;'></a>",o="Array (size "+t.length+")";o+=r,this.addButton(null,o,()=>{n.querySelector(".lexarrayitems").toggleAttribute("hidden")},{buttonClass:"array"}),this.clearQueue();let d=document.createElement("div");d.className="lexarrayitems",d.toggleAttribute("hidden",!0),n.appendChild(s),n.appendChild(d);let c=()=>{let l=n.querySelector(".lexbutton.array span");l.innerHTML="Array (size "+t.length+")",l.innerHTML+=r,d.innerHTML="",this.queue(d);for(let s=0;s<t.length;++s){let h=t[s],u=a.innerValues?"dropdown":h.constructor;switch(this.sameLine(2),u){case String:this.addText(s+"",h,function(e,a){t[s]=e,i(t)},{nameWidth:"4%",inputWidth:"95%",skipReset:!0});break;case Number:this.addNumber(s+"",h,function(e,a){t[s]=e,i(t)},{nameWidth:"4%",inputWidth:"95%",skipReset:!0});break;case"dropdown":this.addDropdown(s+"",a.innerValues,h,function(e,a){t[s]=e,i(t)},{nameWidth:"4%",inputWidth:"95%",skipReset:!0})}this.addButton(null,"<a class='lexicon fa-solid fa-trash'></a>",(a,l)=>{t.splice(t.indexOf(h),1),c(),this._trigger(new IEvent(e,t,l),i)},{title:"Remove item",className:"micro"})}o="Add item",o+="<a class='fa-solid fa-plus' style='float:right; margin-right: 3px; margin-top: 2px;'></a>",this.addButton(null,o,(l,n)=>{t.push(a.innerValues?a.innerValues[0]:""),c(),this._trigger(new IEvent(e,t,n),i)},{buttonClass:"array"}),this.clearQueue()};return c(),l}addList(e,t,i,a,l={}){let n=this.create_widget(e,Widget.LIST,l);n.onGetValue=()=>i,n.onSetValue=(l,n)=>{r.querySelectorAll(".lexlistitem").forEach(e=>e.classList.remove("selected"));let s=t.indexOf(l);-1==s||(r.children[s].classList.toggle("selected"),i=l,n||this._trigger(new IEvent(e,l),a))},n.updateValues=l=>{t=l,r.innerHTML="";for(let n=0;n<t.length;++n){let s=null,o=t[n];o.constructor===Array&&(s=o[1],o=o[0]);let d=document.createElement("div");d.className="lexlistitem"+(i==o?" selected":""),d.innerHTML="<span>"+o+"</span>"+(s?"<a class='"+s+"'></a>":""),d.addEventListener("click",t=>{r.querySelectorAll(".lexlistitem").forEach(e=>e.classList.remove("selected")),d.classList.toggle("selected"),i=o,this._trigger(new IEvent(e,o,t),a)}),r.appendChild(d)}};let s=n.domEl,r=document.createElement("div");return r.className="lexlist",r.style.width="calc( 100% - "+LX.DEFAULT_NAME_WIDTH+")",n.updateValues(t),n.name||(s.className+=" noname",r.style.width="100%"),s.appendChild(r),n}addTags(e,t,i,a={}){let l=[].concat(t=t.replace(/\s/g,"").split(",")),n=this.create_widget(e,Widget.TAGS,a);n.onGetValue=()=>[].concat(t),n.onSetValue=(a,n)=>{t=[].concat(a),d();let o=s.querySelector(".lexwidgetname .lexicon");o&&(o.style.display=a!=l?"block":"none"),n||r._trigger(new IEvent(e,t),i)};let s=n.domEl,r=this;n.name&&Panel._add_reset_property(s.domName,function(a){this.style.display="none",t=[].concat(l),d(),r._trigger(new IEvent(e,t,a),i)});let o=document.createElement("div");o.className="lextags",o.style.width="calc( 100% - "+LX.DEFAULT_NAME_WIDTH+")";let d=()=>{o.innerHTML="";for(let a=0;a<t.length;++a){let n=t[a],c=document.createElement("span");c.className="lextag",c.innerHTML=n;let h=document.createElement("a");h.className="lextagrmb fa-solid fa-xmark lexicon",c.appendChild(h),h.addEventListener("click",a=>{c.remove(),t.splice(t.indexOf(n),1);let o=s.querySelector(".lexwidgetname .lexicon");o&&(o.style.display=t!=l?"block":"none"),r._trigger(new IEvent(e,t,a),i)}),o.appendChild(c)}let u=document.createElement("input");u.value="",u.placeholder="Add tag...",o.appendChild(u),u.onkeydown=function(a){let l=this.value.replace(/\s/g,"");if(" "==a.key||"Enter"==a.key){if(a.preventDefault(),!l.length||t.indexOf(l)>-1)return;t.push(l),d();let n=s.querySelector(".lexwidgetname .lexicon");n&&(n.style.display="block"),r._trigger(new IEvent(e,t,a),i)}},u.focus()};return d(),n.name||(s.className+=" noname",o.style.width="100%"),s.appendChild(o),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,Widget.CHECKBOX,a);l.onGetValue=()=>r.checked,l.onSetValue=(e,t)=>{r.checked!==e&&(r.checked=e,Panel._dispatch_event(r,"change",t))};let n=l.domEl;e&&Panel._add_reset_property(n.domName,function(){r.checked=!r.checked,Panel._dispatch_event(r,"change")});var s=document.createElement("div");s.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",s.appendChild(r),s.appendChild(o),r.addEventListener("change",t=>{let a=t.detail?.constructor==Number?null:t.detail;if(!a){let l=n.querySelector(".lexwidgetname .lexicon");l&&(l.style.display=r.checked!=r.iValue?"block":"none")}let s=n.querySelector(".lexcheckboxsubmenu");s&&s.toggleAttribute("hidden",!r.checked),a||this._trigger(new IEvent(e,r.checked,t),i)}),n.appendChild(s),a.suboptions){n.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(),n.appendChild(d)}return l}addToggle(e,t,i,a={}){if(!e)throw"Set Widget Name!";let l=this.create_widget(e,Widget.TOGGLE,a);l.onGetValue=()=>r.checked,l.onSetValue=(e,t)=>{r.checked!==e&&(r.checked=e,Panel._dispatch_event(r,"change",t))};let n=l.domEl;Panel._add_reset_property(n.domName,function(){r.checked=!r.checked,Panel._dispatch_event(r,"change")});var s=document.createElement("div");s.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",s.appendChild(r),s.appendChild(o),r.addEventListener("change",t=>{let a=t.detail?.constructor==Number?null:t.detail;if(!a){let l=n.querySelector(".lexwidgetname .lexicon");l&&(l.style.display=r.checked!=r.iValue?"block":"none")}let s=n.querySelector(".lextogglesubmenu");s&&s.toggleAttribute("hidden",!r.checked),a||this._trigger(new IEvent(e,r.checked,t),i)}),n.appendChild(s),a.suboptions){n.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(),n.appendChild(d)}return l}addRadioGroup(e,t,i,a={}){let l=this.create_widget(null,Widget.RADIO,a);l.onGetValue=()=>{let e=s.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=s.querySelectorAll("button");for(let a=0;a<i.length;++a){let l=i[a];e==a&&Panel._dispatch_event(l,"click",t)}};let n=l.domEl;var s=document.createElement("div");s.className="lexradiogroup "+(a.className??"");let r=document.createElement("span");r.innerHTML=e,s.appendChild(r);let o=this;for(let d=0;d<t.length;++d){let c=document.createElement("div");c.className="lexradiogroupitem",s.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;s.querySelectorAll("button").forEach(e=>{e.checked=!1,e.classList.remove("checked")}),this.checked=!this.checked,this.classList.toggle("checked"),a||o._trigger(new IEvent(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)),n.appendChild(s),l}addColor(e,t,i,a={}){if(!e)throw"Set Widget Name!";let l=this.create_widget(e,Widget.COLOR,a);l.onGetValue=()=>o.value,l.onSetValue=(e,t)=>{o.value=e,Panel._dispatch_event(o,"input",t)};let n=l.domEl,s=!1;Panel._add_reset_property(n.domName,function(){this.style.display="none",o.value=o.iValue,Panel._dispatch_event(o,"input")});var r=document.createElement("span");r.className="lexcolor",r.style.width="calc( 100% - "+LX.DEFAULT_NAME_WIDTH+")";let o=document.createElement("input");o.style.width="32px",o.type="color",o.className="colorinput",o.id="color"+simple_guidGenerator(),o.useRGB=a.useRGB??!1,o.value=o.iValue=t.constructor===Array?rgbToHex(t):t,a.disabled&&(o.disabled=!0),o.addEventListener("input",t=>{let a=t.target.value,l=t.detail;if(s||d.set(a),!l){let r=n.querySelector(".lexwidgetname .lexicon");r&&(r.style.display=a!=o.iValue?"block":"none")}o.useRGB&&(a=hexToRgb(a)),l||this._trigger(new IEvent(e,a,t),i)},!1),r.appendChild(o),this.queue(r);let d=this.addText(null,o.value,e=>{s=!0,l.set(e),s=!1},{width:"calc( 100% - 32px )"});return d.domEl.style.marginLeft="4px",this.clearQueue(),n.appendChild(r),l}addRange(e,t,i,a={}){let l=this.create_widget(e,Widget.RANGE,a);l.onGetValue=()=>+r.value,l.onSetValue=(e,t)=>{r.value=e,Panel._dispatch_event(r,"input",t)};let n=l.domEl;l.name&&Panel._add_reset_property(n.domName,function(){this.style.display="none",r.value=r.iValue,Panel._dispatch_event(r,"input")});var s=document.createElement("div");s.className="lexrange",s.style.width=a.inputWidth||"calc( 100% - "+LX.DEFAULT_NAME_WIDTH+")";let r=document.createElement("input");return r.className="lexrangeslider "+(a.className??""),r.value=r.iValue=t,r.min=a.min,r.max=a.max,r.step=a.step??1,r.type="range",r.disabled=a.disabled??!1,a.left&&r.classList.add("left"),(a.fill??!0)||r.classList.add("no-fill"),r.addEventListener("input",t=>{if(isNaN(t.target.valueAsNumber))return;let l=t.detail,s=t.target.value=clamp(+t.target.valueAsNumber,+r.min,+r.max);if(r.value=s,!l){let o=n.querySelector(".lexwidgetname .lexicon");o&&(o.style.display=s!=r.iValue?"block":"none")}a.left&&(s=+r.max-s+ +r.min),l||this._trigger(new IEvent(e,s,t),i)},{passive:!1}),r.addEventListener("mousedown",function(e){a.onPress&&a.onPress.bind(r)(e,r)},!1),r.addEventListener("mouseup",function(e){a.onRelease&&a.onRelease.bind(r)(e,r)},!1),l.setLimits=(e,t,i)=>{r.min=e??r.min,r.max=t??r.max,r.step=i??r.step,Panel._dispatch_event(r,"input",!0)},t.constructor==Number&&(t=clamp(t,+r.min,+r.max)),s.appendChild(r),n.appendChild(s),l.name||(n.className+=" noname",s.style.width="100%"),l}addNumber(e,t,i,a={}){let l=this.create_widget(e,Widget.NUMBER,a);l.onGetValue=()=>+o.value,l.onSetValue=(e,t)=>{o.value=round(e,a.precision),Panel._dispatch_event(o,"change",t)};let n=l.domEl;l.name&&Panel._add_reset_property(n.domName,function(){this.style.display="none",o.value=o.iValue,Panel._dispatch_event(o,"change")});var s=document.createElement("div");s.className="lexnumber",s.style.width=a.inputWidth||"calc( 100% - "+LX.DEFAULT_NAME_WIDTH+")";let r=document.createElement("div");r.className="numberbox";let o=document.createElement("input");if(o.id="number_"+simple_guidGenerator(),o.className="vecinput",o.min=a.min??-1e24,o.max=a.max??1e24,o.step=a.step??"any",o.type="number",t.constructor==Number&&(t=clamp(t,+o.min,+o.max),t=round(t,a.precision)),o.value=o.iValue=t,r.appendChild(o),a.units){let d=document.createElement("span");d.className="lexunit",d.innerText=a.units,d.style.left=measureRealWidth(o.value)+"px",o.unitSpan=d,r.appendChild(d)}let c=document.createElement("a");if(c.className="fa-solid fa-arrows-up-down drag-icon hidden",r.appendChild(c),a.disabled&&(o.disabled=!0),!a.skipSlider&&void 0!==a.min&&void 0!==a.max){let h=document.createElement("input");h.className="lexinputslider",h.min=a.min,h.max=a.max,h.step=a.step??1,h.type="range",h.value=t,h.addEventListener("input",function(e){let t=+this.valueAsNumber;o.value=round(t,a.precision),Panel._dispatch_event(o,"change")},!1),h.addEventListener("mousedown",function(e){a.onPress&&a.onPress.bind(h)(e,h)},!1),h.addEventListener("mouseup",function(e){a.onRelease&&a.onRelease.bind(h)(e,h)},!1),r.appendChild(h),l.setLimits=(e,t,i)=>{o.min=h.min=e??o.min,o.max=h.max=t??o.max,o.step=i??o.step,h.step=i??h.step,Panel._dispatch_event(o,"change",!0)}}o.addEventListener("input",function(e){let t=+this.valueAsNumber;o.value=round(t,a.precision),a.units&&(o.unitSpan.style.left=measureRealWidth(o.value)+"px")},!1),o.addEventListener("wheel",function(e){if(e.preventDefault(),this!==document.activeElement)return;let t=a.step??1;e.shiftKey?t*=10:e.altKey&&(t*=.1);let i=+this.valueAsNumber-t*(e.deltaY>0?1:-1);this.value=round(i,a.precision),Panel._dispatch_event(o,"change")},{passive:!1}),o.addEventListener("change",t=>{if(isNaN(t.target.valueAsNumber))return;let l=t.detail,s=t.target.value=clamp(+t.target.valueAsNumber,+o.min,+o.max);if(s=a.precision?round(s,a.precision):s,r.querySelector(".lexinputslider")&&(r.querySelector(".lexinputslider").value=s),o.value=s,a.units&&(o.unitSpan.style.left=measureRealWidth(o.value)+"px"),!l){let d=n.querySelector(".lexwidgetname .lexicon");d&&(d.style.display=s!=o.iValue?"block":"none")}l||this._trigger(new IEvent(e,s,t),i)},{passive:!1}),o.addEventListener("mousedown",function e(t){if(document.activeElement!=o){var i=u.root.ownerDocument;i.addEventListener("mousemove",p),i.addEventListener("mouseup",m),document.body.classList.add("noevents"),c.classList.remove("hidden"),t.stopImmediatePropagation(),t.stopPropagation(),document.pointerLockElement||o.requestPointerLock(),a.onPress&&a.onPress.bind(o)(t,o)}});var u=this;function p(e){let t=-e.movementY;if(0!=t){let i=a.step??1;e.shiftKey?i*=10:e.altKey&&(i*=.1);let l=+o.valueAsNumber+i*t;o.value=(+l).toFixed(4).replace(/([0-9]+(\.[0-9]+[1-9])?)(\.?0+$)/,"$1"),Panel._dispatch_event(o,"change")}e.stopPropagation(),e.preventDefault()}function m(e){var t=u.root.ownerDocument;t.removeEventListener("mousemove",p),t.removeEventListener("mouseup",m),document.body.classList.remove("noevents"),c.classList.add("hidden"),document.pointerLockElement&&document.exitPointerLock(),a.onRelease&&a.onRelease.bind(o)(e,o)}return s.appendChild(r),n.appendChild(s),l.name||(n.className+=" noname",s.style.width="100%"),l}static VECTOR_COMPONENTS={0:"x",1:"y",2:"z",3:"w"};_add_vector(e,t,i,a,l={}){if(e=clamp(e,2,4),i=i??Array(e).fill(0),!t)throw"Set Widget Name!";let n=this.create_widget(t,Widget.VECTOR,l);n.onGetValue=()=>{let e=s.querySelectorAll("input"),t=[];for(var i of e)t.push(+i.value);return t},n.onSetValue=(e,t)=>{let i=s.querySelectorAll(".vecinput");if(i.length==e.length){console.error("Input length does not match vector length.");return}for(let a=0;a<i.length;++a){let n=e[a];i[a].value=round(n,l.precision)??0,Panel._dispatch_event(i[a],"change",t)}};let s=n.domEl;Panel._add_reset_property(s.domName,function(){for(let e of(this.style.display="none",s.querySelectorAll(".vecinput")))e.value=e.iValue,Panel._dispatch_event(e,"change")});var r=document.createElement("div");r.className="lexvector",r.style.width="calc( 100% - "+LX.DEFAULT_NAME_WIDTH+")";for(let o=0;o<e;++o){let d=document.createElement("div");d.className="vecbox",d.innerHTML="<span class='"+Panel.VECTOR_COMPONENTS[o]+"'></span>";let c=document.createElement("input");c.className="vecinput v"+e,c.min=l.min??-1e24,c.max=l.max??1e24,c.step=l.step??"any",c.type="number",c.id="vec"+e+"_"+simple_guidGenerator(),c.idx=o,i[o].constructor==Number&&(i[o]=clamp(i[o],+c.min,+c.max),i[o]=round(i[o],l.precision)),c.value=c.iValue=i[o];let h=document.createElement("a");h.className="fa-solid fa-arrows-up-down drag-icon hidden",d.appendChild(h),l.disabled&&(c.disabled=!0),c.addEventListener("wheel",function(e){if(e.preventDefault(),this!==document.activeElement)return;let t=l.step??1;if(e.shiftKey?t=10:e.altKey&&(t=.1),f.locked)for(let i of s.querySelectorAll(".vecinput"))i.value=round(+i.valueAsNumber-t*(e.deltaY>0?1:-1),l.precision),Panel._dispatch_event(i,"change");else this.value=round(+this.valueAsNumber-t*(e.deltaY>0?1:-1),l.precision),Panel._dispatch_event(c,"change")},{passive:!1}),c.addEventListener("change",e=>{if(isNaN(e.target.value))return;let n=e.detail,r=e.target.value=clamp(e.target.value,+c.min,+c.max);if(r=round(r,l.precision),!n){let o=s.querySelector(".lexwidgetname .lexicon");o&&(o.style.display=r!=c.iValue?"block":"none")}if(f.locked)for(let d of s.querySelectorAll(".vecinput"))d.value=r,i[d.idx]=r;else c.value=r,i[e.target.idx]=r;n||this._trigger(new IEvent(t,i,e),a)},!1),c.addEventListener("mousedown",p);var u=this;function p(e){if(document.activeElement!=c){var t=u.root.ownerDocument;t.addEventListener("mousemove",m),t.addEventListener("mouseup",g),document.body.classList.add("noevents"),h.classList.remove("hidden"),e.stopImmediatePropagation(),e.stopPropagation(),document.pointerLockElement||c.requestPointerLock(),l.onPress&&l.onPress.bind(c)(e,c)}}function m(e){let t=-e.movementY;if(0!=t){let i=l.step??1;if(e.shiftKey?i=10:e.altKey&&(i=.1),f.locked)for(let a of s.querySelectorAll(".vecinput"))a.value=round(+a.valueAsNumber+i*t,l.precision),Panel._dispatch_event(a,"change");else c.value=round(+c.valueAsNumber+i*t,l.precision),Panel._dispatch_event(c,"change")}e.stopPropagation(),e.preventDefault()}function g(e){var t=u.root.ownerDocument;t.removeEventListener("mousemove",m),t.removeEventListener("mouseup",g),document.body.classList.remove("noevents"),h.classList.add("hidden"),document.pointerLockElement&&document.exitPointerLock(),l.onRelease&&l.onRelease.bind(c)(e,c)}d.appendChild(c),r.appendChild(d)}(void 0!==l.min||void 0!==l.max)&&(n.setLimits=(e,l,n)=>{let r=s.querySelectorAll(".vecinput");for(let o of r)o.min=e??o.min,o.max=l??o.max,o.step=n??o.step,Panel._dispatch_event(o,"change",!0);this._trigger(new IEvent(t,i),a)});let f=document.createElement("a");return f.title="Lock",f.className="fa-solid fa-lock-open lexicon lock",r.appendChild(f),f.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),s.appendChild(r),n}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,Widget.SIZE,a);l.onGetValue=()=>{let e=[];for(let t=0;t<n.dimensions.length;++t)e.push(n.dimensions[t].value());return e},l.onSetValue=(e,t)=>{for(let i=0;i<n.dimensions.length;++i)n.dimensions[i].set(e[i],t)};let n=l.domEl;this.queue(n),n.aspectRatio=2==t.length?t[0]/t[1]:null,n.dimensions=[];for(let s=0;s<t.length;++s)if(n.dimensions[s]=this.addNumber(null,t[s],e=>{let t=l.value();if(n.locked){let a=0==s?1/n.aspectRatio:n.aspectRatio,r=(1+s)%2;t[r]=e*a,n.dimensions[r].set(t[r],!0)}i&&i(t)},{min:0,disabled:a.disabled,precision:a.precision}),s+1!=t.length){let r=document.createElement("a");r.className="lexsizecross fa-solid fa-xmark",n.appendChild(r)}if(this.clearQueue(),a.units){let o=document.createElement("span");o.className="lexunit",o.innerText=a.units,n.appendChild(o)}if(n.aspectRatio){let d=document.createElement("a");d.title="Lock Aspect Ratio",d.className="fa-solid fa-lock-open lexicon lock",n.appendChild(d),d.addEventListener("click",function(e){if(n.locked=!n.locked,n.locked){this.classList.add("fa-lock"),this.classList.remove("fa-lock-open");let t=l.value();n.aspectRatio=t[0]/t[1]}else this.classList.add("fa-lock-open"),this.classList.remove("fa-lock")},!1)}return l.name||(n.className+=" noname",container.style.width="100%"),l}addPad(e,t,i,a={}){if(!e)throw"Set Widget Name!";let l=this.create_widget(e,Widget.PAD,a);l.onGetValue=()=>o.value.xy,l.onSetValue=(t,a)=>{o.value.set(t[0],t[1]),d(o.value),a||this._trigger(new IEvent(e,o.value.xy),i)};let n=l.domEl;var s=document.createElement("div");s.className="lexpad",s.style.width="calc( 100% - "+LX.DEFAULT_NAME_WIDTH+")";let r=document.createElement("div");r.id="lexpad-"+e,r.className="lexinnerpad",r.style.width=a.padSize??"96px",r.style.height=a.padSize??"96px";let o=document.createElement("div");o.className="lexpadthumb",o.value=new LX.vec2(t[0],t[1]),o.min=a.min??0,o.max=a.max??1;let d=e=>{let[t,i]=[r.offsetWidth,r.offsetHeight],a=new LX.vec2(remapRange(e.x,o.min,o.max,0,1),remapRange(e.y,o.min,o.max,0,1));o.style.transform=`translate(calc( ${t*a.x}px - 50% ), calc( ${i*a.y}px - 50%)`};doAsync(()=>{d(o.value)}),r.appendChild(o),s.appendChild(r),n.appendChild(s),r.addEventListener("mousedown",function e(t){if(document.activeElement!=o){var i=c.root.ownerDocument;i.addEventListener("mousemove",h),i.addEventListener("mouseup",u),document.body.classList.add("nocursor"),document.body.classList.add("noevents"),t.stopImmediatePropagation(),t.stopPropagation(),a.onPress&&a.onPress.bind(o)(t,o)}});let c=this;function h(t){let a=r.getBoundingClientRect(),l=new LX.vec2(t.x-a.x,t.y-a.y);l.clp(0,r.offsetWidth,l);let[n,s]=[r.offsetWidth,r.offsetHeight],d=l.div(new LX.vec2(r.offsetWidth,r.offsetHeight));o.style.transform=`translate(calc( ${n*d.x}px - 50% ), calc( ${s*d.y}px - 50%)`,o.value=new LX.vec2(remapRange(d.x,0,1,o.min,o.max),remapRange(d.y,0,1,o.min,o.max)),c._trigger(new IEvent(e,o.value.xy,t),i),t.stopPropagation(),t.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(o)(e,o)}return l}addProgress(e,t,i={}){if(!e)throw"Set Widget Name!";let a=this.create_widget(e,Widget.PROGRESS,i);a.onGetValue=()=>s.value,a.onSetValue=(e,t)=>{l.querySelector("meter").value=e,r(),l.querySelector("span")&&(l.querySelector("span").innerText=e)};let l=a.domEl;var n=document.createElement("div");n.className="lexprogress",n.style.width="calc( 100% - "+LX.DEFAULT_NAME_WIDTH+")";let s=document.createElement("meter");s.id="lexprogressbar-"+e,s.className="lexprogressbar",s.step="any",s.min=i.min??0,s.max=i.max??1,s.low=i.low??s.low,s.high=i.high??s.high,s.optimum=i.optimum??s.optimum,s.value=t;let r=()=>{let e=LX.getThemeColor("global-selected");void 0!=s.low&&s.value<s.low?e=LX.getThemeColor("global-color-error"):void 0!=s.high&&s.value<s.high&&(e=LX.getThemeColor("global-color-warning")),s.style.background=`color-mix(in srgb, ${e} 20%, transparent)`};if(n.appendChild(s),l.appendChild(n),i.showValue){document.getElementById("progressvalue-"+e)&&document.getElementById("progressvalue-"+e).remove();let o=document.createElement("span");o.id="progressvalue-"+e,o.style.padding="0px 5px",o.innerText=t,n.appendChild(o)}if(i.editable){s.classList.add("editable"),s.addEventListener("mousedown",function t(i){var a=d.root.ownerDocument;a.addEventListener("mousemove",c),a.addEventListener("mouseup",h),document.body.classList.add("noevents"),s.classList.add("grabbing"),i.stopImmediatePropagation(),i.stopPropagation();let l=s.getBoundingClientRect(),n=round(remapRange(i.offsetX,0,l.width,s.min,s.max));d.setValue(e,n)});let d=this;function c(t){if(0!=t.movementX){let a=s.getBoundingClientRect(),l=round(remapRange(t.offsetX-a.x,0,a.width,s.min,s.max));d.setValue(e,l),i.callback&&i.callback(l,t)}t.stopPropagation(),t.preventDefault()}function h(e){var t=d.root.ownerDocument;t.removeEventListener("mousemove",c),t.removeEventListener("mouseup",h),document.body.classList.remove("noevents"),s.classList.remove("grabbing")}}return r(),a}addFile(e,t,i={}){if(!e)throw"Set Widget Name!";let a=this.create_widget(e,Widget.FILE,i),l=a.domEl,n=i.local??!0,s=i.type??"text",r=i.read??!0,o=document.createElement("input");if(o.className="lexfileinput",o.style.width="calc( 100% - "+LX.DEFAULT_NAME_WIDTH+" - 10%)",o.type="file",o.disabled=i.disabled??!1,i.placeholder&&(o.placeholder=i.placeholder),o.addEventListener("change",function(e){let a=e.target.files;if(a.length){if(r){i.onBeforeRead&&i.onBeforeRead();let l=new FileReader;"text"===s?l.readAsText(a[0]):"buffer"===s?l.readAsArrayBuffer(a[0]):"bin"===s?l.readAsBinaryString(a[0]):"url"===s&&l.readAsDataURL(a[0]),l.onload=e=>{t.call(this,e.target.result,a[0])}}else t(a[0])}}),o.addEventListener("cancel",function(e){t(null)}),l.appendChild(o),this.queue(l),n){let d=null;this.addButton(null,"<a style='margin-top: 0px;' class='fa-solid fa-gear'></a>",()=>{!d&&(d=new Dialog("Load Settings",e=>{e.addDropdown("Type",["text","buffer","bin","url"],s,e=>{s=e}),e.addButton(null,"Reload",e=>{o.dispatchEvent(new Event("change"))})},{onclose(e){e.remove(),d=null}}))},{className:"micro",skipInlineCount:!0,title:"Settings"})}return this.clearQueue(),a}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 n=document.createElement("div");if(n.className="lextreetools",e||(n.className+=" notitle"),i.icons)for(let s of i.icons){let r=document.createElement("a");r.title=s.name,r.className="lexicon "+s.icon,r.addEventListener("click",s.callback),n.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",n.appendChild(o),n.appendChild(d)}(i.icons||i.filter)&&a.appendChild(n);let c=document.createElement("ul");c.addEventListener("contextmenu",function(e){e.preventDefault()}),a.appendChild(c),this.root.appendChild(a);let h=new NodeTree(a,t,i);return h}addSeparator(){var e=document.createElement("div");e.className="lexseparator";let t=new Widget(null,Widget.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),n=document.createElement("div");n.className="lextabscontainer",a||(n.className+=" horizontal");let s=document.createElement("div");s.className="tabs",n.appendChild(s),i.appendChild(n);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),n.appendChild(h),c.addEventListener("click",e=>{s.querySelectorAll(".lextab").forEach(e=>{e.classList.remove("selected")}),e.target.classList.add("selected"),n.querySelectorAll(".widgets").forEach(e=>{e.toggleAttribute("hidden",!0)});let t=n.querySelector("#"+h.id);t.toggleAttribute("hidden"),o.onSelect&&o.onSelect(this,h)}),s.appendChild(c),o.onCreate&&(this.queue(h),o.onCreate(this,h),this.clearQueue())}this.addSeparator()}addCounter(e,t,i,a={}){let l=this.create_widget(e,Widget.COUNTER,a);l.onGetValue=()=>u.count,l.onSetValue=(e,t)=>{d(e,t)};let n=l.domEl,s=a.min??0,r=a.max??100,o=a.step??1,d=(t,a,l)=>{t=clamp(t,s,r),u.count=t,u.innerHTML=t,a||this._trigger(new IEvent(e,t,l),i)},c=document.createElement("div");c.className="lexcounter",n.appendChild(c),this.queue(c),this.addButton(null,"<a style='margin-top: 0px;' class='fa-solid fa-minus'></a>",(e,t)=>{let i=o??1;t.shiftKey&&(i*=10),d(u.count-i,!1,t)},{className:"micro",skipInlineCount:!0,title:"Minus"}),this.clearQueue();let h=document.createElement("div");h.className="lexcounterbox",c.appendChild(h);let u=document.createElement("span");if(u.className="lexcountervalue",u.innerHTML=t,u.count=t,h.appendChild(u),a.label){let p=document.createElement("span");p.className="lexcounterlabel",p.innerHTML=a.label,h.appendChild(p)}return this.queue(c),this.addButton(null,"<a style='margin-top: 0px;' class='fa-solid fa-plus'></a>",(e,t)=>{let i=o??1;t.shiftKey&&(i*=10),d(u.count+i,!1,t)},{className:"micro",skipInlineCount:!0,title:"Plus"}),this.clearQueue(),l}addTable(e,t,i={}){if(!t)throw"Data is needed to create a table!";let a=this.create_widget(e,Widget.TABLE,i);a.onGetValue=()=>{},a.onSetValue=(e,t)=>{};let l=a.domEl,n=document.createElement("div");n.className="lextable",n.style.width="calc( 100% - "+LX.DEFAULT_NAME_WIDTH+")";let s=document.createElement("table");function r(e,t,i,a){return i[e]<a[e]?-t:i[e]>a[e]?t:0}return n.appendChild(s),t.head=t.head??[],t.body=t.body??[],t.orderMap={},t.checkMap={},a.refreshTable=()=>{s.innerHTML="";{let e=document.createElement("thead");e.className="lextablehead",s.appendChild(e);let l=document.createElement("tr");if(i.selectable){let n=document.createElement("th"),o=document.createElement("input");o.type="checkbox",o.className="lexcheckbox",o.checked=t.checkMap[":root"]??!1,n.appendChild(o),o.addEventListener("change",function(){t.checkMap[":root"]=this.checked;let e=s.querySelector("tbody");for(let i of e.childNodes)t.checkMap[i.getAttribute("rowId")]=this.checked,i.querySelector("input").checked=this.checked}),l.appendChild(n)}for(let d of t.head){let c=document.createElement("th");c.innerHTML=`${d} <a class="fa-solid fa-sort"></a>`,c.querySelector("a").addEventListener("click",()=>{t.orderMap[d]||(t.orderMap[d]=1);let e=t.head.indexOf(d);t.body=t.body.sort(r.bind(this,e,t.orderMap[d])),t.orderMap[d]=-t.orderMap[d],a.refreshTable()}),l.appendChild(c)}if(i.rowActions){let h=document.createElement("th");h.className="sm",l.appendChild(h)}e.appendChild(l)}{let u=document.createElement("tbody");u.className="lextablebody",s.appendChild(u);for(let p=0;p<t.body.length;++p){let m=t.body[p],g=document.createElement("tr"),f=LX.getSupportedDOMName(m.join("-"));if(g.setAttribute("rowId",f),i.selectable){let v=document.createElement("td"),E=document.createElement("input");E.type="checkbox",E.className="lexcheckbox",E.checked=t.checkMap[f],v.appendChild(E),E.addEventListener("change",function(){if(t.checkMap[f]=this.checked,!this.checked){let e=s.querySelector("thead input[type='checkbox']");e.checked=t.checkMap[":root"]=!1}}),g.appendChild(v)}for(let $ of m){let y=document.createElement("td");y.innerHTML=`${$}`,g.appendChild(y)}if(i.rowActions){let x=document.createElement("td");x.className="sm";let L=document.createElement("div");for(let b of(L.className="lextablebuttons",x.appendChild(L),i.rowActions)){let w=document.createElement("a");w.className="lexicon","delete"==b?(w.className+=" fa-solid fa-trash-can",w.addEventListener("click",function(){t.body.splice(p,1),g.remove()})):"menu"==b?(w.className+=" fa-solid fa-ellipsis",w.addEventListener("click",function(e){addContextMenu(null,e,e=>{if(i.onMenuAction){i.onMenuAction(e);return}console.warn("Using <Menu action> without action callbacks.")})})):(console.assert(b.constructor==Object),w.className+=` ${b.icon}`),L.appendChild(w)}g.appendChild(x)}u.appendChild(g)}}},a.refreshTable(),a.name||(l.className+=" noname",n.style.width="100%"),l.appendChild(n),a}}LX.Panel=Panel;class Branch{constructor(e,t={}){this.name=e;var i=document.createElement("div");i.className="lexbranch",t.id&&(i.id=t.id),t.className&&(i.className+=" "+t.className),i.style.width="calc(100% - 7px)",i.style.margin="0 auto";var a=this;this.root=i,this.widgets=[];var l=document.createElement("div");l.className="lexbranchtitle",l.innerHTML="<a class='fa-solid fa-angle-up switch-branch-button'></a>",t.icon&&(l.innerHTML+="<a class='branchicon "+t.icon+"' style='margin-right: 8px; margin-bottom: -2px;'>"),l.innerHTML+=e||"Branch",i.appendChild(l);var n=document.createElement("div");n.id=e.replace(/\s/g,""),n.className="lexbranchcontent",i.appendChild(n),this.content=n,this._addBranchSeparator(),t.closed&&(l.className+=" closed",i.className+=" closed",this.grabber.setAttribute("hidden",!0),doAsync(()=>{this.content.setAttribute("hidden",!0)},15)),this.onclick=function(e){e.stopPropagation(),this.classList.toggle("closed"),this.parentElement.classList.toggle("closed"),a.content.toggleAttribute("hidden"),a.grabber.toggleAttribute("hidden"),LX.emit("@on_branch_closed",this.classList.contains("closed"),{target:a.panel})},this.oncontextmenu=function(e){e.preventDefault(),e.stopPropagation(),!this.parentElement.classList.contains("dialog")&&addContextMenu("Dock",e,t=>{e.preventDefault(),t.add("Floating",a._on_make_floating.bind(a))},{icon:"fa-regular fa-window-restore"})},l.addEventListener("click",this.onclick),l.addEventListener("contextmenu",this.oncontextmenu)}_on_make_floating(){let e=new Dialog(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 t=document.createElement("div");t.innerHTML="▾",e.appendChild(t),doAsync(()=>{t.style.marginLeft=parseFloat(LX.DEFAULT_NAME_WIDTH)/100*this.content.offsetWidth+"px"},10);let i=document.createElement("div");i.style.width="1px",i.style.marginLeft="6px",i.style.marginTop="2px",i.style.height="0px",t.appendChild(i),t.addEventListener("mousedown",function e(t){var s=a.root.ownerDocument;s.addEventListener("mouseup",n),s.addEventListener("mousemove",l),t.stopPropagation(),t.preventDefault();let r=a.root.offsetHeight-a.root.children[0].offsetHeight;i.style.height=r-3+"px",document.body.classList.add("nocursor")}),this.grabber=t;let a=this;function l(e){let i=e.movementX;if(0!=i){let l=parseFloat(t.style.marginLeft);t.style.marginLeft=clamp(l+i,32,a.content.offsetWidth-32)+"px"}}function n(e){a._updateWidgets(),i.style.height="0px";var t=a.root.ownerDocument;t.removeEventListener("mouseup",n),t.removeEventListener("mousemove",l),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],n=a.children[1];l.style.width=e;let s="0px";i.type===Widget.FILE&&(s="10%"),n.style.width="-moz-calc( 100% - "+e+" - "+s+" )",n.style.width="-webkit-calc( 100% - "+e+" - "+s+" )",n.style.width="calc( 100% - "+e+" - "+s+" )",i.onresize&&i.onresize()}}}LX.Branch=Branch;class Footer{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 n=document.createElement("div");n.className="col",a.appendChild(n);let s=document.createElement("h2");if(s.innerHTML=l.title,n.appendChild(s),!l.items||!l.items.length)continue;let r=document.createElement("ul");for(let o of(n.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)}}LX.Footer=Footer;class Dialog{static _last_id=0;constructor(e,t,i={}){t||console.warn("Content is empty, add some widgets using 'callback' parameter!"),this._oncreate=t,this.id=simple_guidGenerator();let a=i.size??[],l=i.position??[],n=i.draggable??!0,s=i.modal??!1;var r=document.createElement("dialog");r.className="lexdialog "+(i.className??""),r.id=i.id??"dialog"+Dialog._last_id++,LX.root.appendChild(r),doAsync(()=>{s?r.showModal():r.show()},10);let o=this;var d=document.createElement("div");if(e&&(d.className="lexdialogtitle",d.innerHTML=e,d.setAttribute("draggable",!1),d.oncontextmenu=function(t){t.preventDefault(),t.stopPropagation(),LX.main_area&&"horizontal"===LX.main_area.type&&addContextMenu("Dock",t,i=>{t.preventDefault();let a=function(e){let t=e.panels[0];if(t)return t;for(var i of e.sections)if(t=a(i))return t},l=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)),o.widgets))i.content.appendChild(a.domEl);i.widgets=o.widgets,t.root.querySelectorAll(".lexbranch.last").forEach(e=>{e.classList.remove("last")}),i.root.classList.add("last"),r.remove()},n=a(LX.main_area.sections[1]);i.add('<i class="fa-regular fa-window-maximize fa-window-maximize fa-rotate-90">',{disabled:!n,id:"dock_options0",callback(){l(n)}});let s=a(LX.main_area.sections[0]);i.add('<i class="fa-regular fa-window-maximize fa-window-maximize fa-rotate-270">',{disabled:!s,id:"dock_options1",callback(){l(s)}})},{icon:"fa-regular fa-window-restore"})},r.appendChild(d)),i.closable??!0){this.close=()=>{i.onBeforeClose&&i.onBeforeClose(this),i.onclose?i.onclose(this.root):(r.close(),doAsync(()=>{o.panel.clear(),r.remove()},150))};var c=document.createElement("a");c.className="lexdialogcloser fa-solid fa-xmark",c.title="Close",c.addEventListener("click",this.close),e?d.appendChild(c):(c.classList.add("notitle"),r.appendChild(c))}let h=new Panel;h.root.classList.add("lexdialogcontent"),e||h.root.classList.add("notitle"),t&&t.call(this,h),r.appendChild(h.root),h.root.querySelectorAll(".lexbranch").forEach(e=>e.classList.add("dialog")),this.panel=h,this.root=r,this.title=d,n&&makeDraggable(r,Object.assign({targetClass:"lexdialogtitle"},i)),a.length&&"string"!=typeof a[0]&&(a[0]+="px"),a.length&&"string"!=typeof a[1]&&(a[1]+="px"),r.style.width=a[0]?a[0]:"25%",r.style.height=a[1]?a[1]:"auto",r.style.translate=i.position?"unset":"-50% -50%",i.size&&(this.size=a),r.style.left=l[0]??"50%",r.style.top=l[1]??"50%",h.root.style.width="calc( 100% - 30px )",h.root.style.height=e?"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){let t=this.root.querySelector(".lexdialogtitle");t&&(t.innerText=e)}}LX.Dialog=Dialog;class PocketDialog extends Dialog{static TOP=0;static BOTTOM=1;constructor(e,t,i={}){i.draggable=i.draggable??!1,i.closable=i.closable??!1;super(e,t,i);let a=this;if(LX.addSignal("@on_branch_closed",this.panel,e=>{this.dock_pos==PocketDialog.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",i.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=PocketDialog.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==PocketDialog.BOTTOM&&(a.root.style.top=this.root.classList.contains("minimized")?"calc(100% - "+(a.title.offsetHeight+6)+"px)":"calc(100% - "+(a.root.offsetHeight+3)+"px)")}),!i.draggable){let l=i.float;if(l)for(var n=0;n<l.length;n++){let s=l[n];switch(s){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=i.position?i.position[1]:"3px"}}this.root.classList.add("dockable"),this.title.addEventListener("keydown",function(e){e.ctrlKey&&(a.root.style.right="unset","ArrowLeft"==e.key?a.root.style.left="0px":"ArrowRight"==e.key?a.root.style.left="calc(100% - "+(a.root.offsetWidth+3)+"px)":"ArrowUp"==e.key?(a.root.style.top="0px",a.dock_pos=PocketDialog.TOP):"ArrowDown"==e.key&&(a.root.style.top="calc(100% - "+(a.root.offsetHeight+3)+"px)",a.dock_pos=PocketDialog.BOTTOM))})}}}LX.PocketDialog=PocketDialog;class ContextMenu{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 n=a.width;a.left<0?e.style.left=t+"px":window.innerWidth-a.right<0&&(e.style.left=window.innerWidth-n-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 n=0;n<e[t].length;++n){let s=e[t][n],r=Object.keys(s)[0];this._create_entry(s,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,t,i,a){let l=e[t].length,n=document.createElement("div");n.className="lexmenuboxentry"+(e.className?" "+e.className:""),n.id=e.id??"eId"+getSupportedDOMName(t),n.innerHTML="";let s=e.icon;s&&(n.innerHTML+="<a class='"+s+" fa-sm'></a>");let r=e.disabled;if(n.innerHTML+="<div class='lexentryname"+(r?" disabled":"")+"'>"+t+"</div>",i.appendChild(n),this.colors[t]&&(n.style.borderColor=this.colors[t]),""==t){n.className+=" cmseparator";return}if(n.addEventListener("click",i=>{if(i.stopPropagation(),i.stopImmediatePropagation(),r)return;let s=e.callback;s&&(s.call(this,t,n),this.root.remove()),l&&"click"==LX.OPEN_CONTEXTMENU_ENTRY&&this._create_submenu(e,t,n,++a)}),!l)return;let o=document.createElement("a");o.className="fa-solid fa-bars-staggered fa-xs",n.appendChild(o),"mouseover"==LX.OPEN_CONTEXTMENU_ENTRY&&n.addEventListener("mouseover",i=>{n.built||(n.built=!0,this._create_submenu(e,t,n,++a),i.stopPropagation())}),n.addEventListener("mouseleave",()=>{a=-1,i.querySelectorAll(".lexcontextmenu").forEach(e=>e.remove())})}onCreate(){doAsync(()=>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,n=(e,a)=>{if(void 0==e)return;let s=null;if(a.forEach(t=>{let i=Object.keys(t),a=i.find(t=>t==e);a&&(s=t[a])}),s)n(i[l++],s);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),n(o,r[e])}};n(i[l++],this.items);let s=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 n=Object.keys(l)[0];for(var r=0;r<l[n].length;++r)s(l)}}};for(let r of this.items)s(r);for(let o of this.items){let d=Object.keys(o)[0],c="eId"+getSupportedDOMName(d),h="#"+(o.id??c);this.root.querySelector(h)||this._create_entry(o,d,this.root,-1)}}setColor(e,t){"#"!==t[0]&&(t=rgbToHex(t)),this.colors[e]=t}}function addContextMenu(e,t,i,a){var l=new ContextMenu(t,e,a);return LX.root.appendChild(l.root),i&&i(l),l.onCreate(),l}LX.ContextMenu=ContextMenu,LX.addContextMenu=addContextMenu;class Curve{constructor(e,t,i={}){let a=document.createElement("div");a.className="curve "+(i.className?i.className:""),a.style.minHeight="50px",a.style.width=i.width||"100%",a.style.minWidth="50px",a.style.minHeight="20px",a.bgcolor=i.bgColor||LX.getThemeColor("global-intense-background"),a.pointscolor=i.pointsColor||LX.getThemeColor("global-selected-light"),a.linecolor=i.lineColor||"#555",a.value=t||[],a.xrange=i.xrange||[0,1],a.yrange=i.yrange||[0,1],a.defaulty=null!=i.defaulty?i.defaulty:0,a.no_overlap=i.noOverlap||!1,a.show_samples=i.showSamples||0,a.allow_add_values=i.allowAddValues??!0,a.draggable_x=i.draggableX??!0,a.draggable_y=i.draggableY??!0,a.smooth=(i.smooth&&"number"==typeof i.smooth?i.smooth:.3)||!1,a.move_out=i.moveOutAction??LX.CURVE_MOVEOUT_DELETE,LX.addSignal("@on_new_color_scheme",(e,t)=>{a.bgcolor=i.bgColor||LX.getThemeColor("global-intense-background"),a.pointscolor=i.pointsColor||LX.getThemeColor("global-selected-light"),this.redraw()}),this.element=a;let l=document.createElement("canvas");function n(e){return[l.width*(e[0]-a.xrange[0])/a.xrange[1],l.height*(e[1]-a.yrange[0])/a.yrange[1]]}function s(e){return[e[0]*a.xrange[1]/l.width+a.xrange[0],e[1]*a.yrange[1]/l.height+a.yrange[0]]}l.width=i.width||200,l.height=i.height||50,a.appendChild(l),this.canvas=l,a.addEventListener("mousedown",d),a.getValueAt=function(e){if(e<a.xrange[0]||e>a.xrange[1])return a.defaulty;for(var t=[a.xrange[0],a.defaulty],i=0,l=0;l<a.value.length;l+=1){var n=a.value[l];if(e==n[0])return n[1];if(e<n[0])return i=(e-t[0])/(n[0]-t[0]),t[1]*(1-i)+n[1]*i;t=n}return n=[a.xrange[1],a.defaulty],i=(e-t[0])/(n[0]-t[0]),t[1]*(1-i)+n[1]*i},a.resample=function(e){for(var t=[],i=(a.xrange[1]-a.xrange[0])/e,l=a.xrange[0];l<=a.xrange[1];l+=i)t.push(a.getValueAt(l));return t},a.addValue=function(e){for(var t=0;t<a.value;t++)if(!(a.value[t][0]<e[0])){a.value.splice(t,0,e),redraw();return}a.value.push(e),redraw()};var r=-1;a.redraw=function(e={}){e.value&&(a.value=e.value),e.xrange&&(a.xrange=e.xrange),e.yrange&&(a.yrange=e.yrange),e.smooth&&(a.smooth=e.smooth);var t=l.parentElement.getBoundingClientRect();l.parentElement.parentElement&&(t=l.parentElement.parentElement.getBoundingClientRect()),t&&l.width!=t.width&&t.width&&t.width<1e3&&(l.width=t.width);var i=l.getContext("2d");i.setTransform(1,0,0,1,0,0),i.translate(0,l.height),i.scale(1,-1),i.fillStyle=a.bgcolor,i.fillRect(0,0,l.width,l.height),i.strokeStyle=a.linecolor,i.beginPath();var s=n([a.xrange[0],a.defaulty]);i.moveTo(s[0],s[1]);let o=[s[0],s[1]];for(var d in a.value){var c=a.value[d];s=n(c),o.push(s[0]),o.push(s[1]),a.smooth||i.lineTo(s[0],s[1])}s=n([a.xrange[1],a.defaulty]),o.push(s[0]),o.push(s[1]),a.smooth?LX.UTILS.drawSpline(i,o,a.smooth):(i.lineTo(s[0],s[1]),i.stroke());for(var d=0;d<a.value.length;d+=1){var c=a.value[d];s=n(c),r==d?i.fillStyle="white":i.fillStyle=a.pointscolor,i.beginPath(),i.arc(s[0],s[1],r==d?4:3,0,2*Math.PI),i.fill()}if(a.show_samples){var h=a.resample(a.show_samples);i.fillStyle="#888";for(var d=0;d<h.length;d+=1){var c=[d*((a.xrange[1]-a.xrange[0])/a.show_samples)+a.xrange[0],h[d]];s=n(c),i.beginPath(),i.arc(s[0],s[1],2,0,2*Math.PI),i.fill()}}};var o=[0,0];function d(e){document.addEventListener("mousemove",c),document.addEventListener("mouseup",h);var t=l.getBoundingClientRect(),i=e.clientX-t.left,n=e.clientY-t.top;if(r=m(i,l.height-n),e.button==LX.MOUSE_LEFT_CLICK&&-1==r&&a.allow_add_values){var d=s([i,l.height-n]);a.value.push(d),g(),r=a.value.indexOf(d)}o=[i,n],a.redraw(),e.preventDefault(),e.stopPropagation()}function c(e){var t=l.getBoundingClientRect(),i=e.clientX-t.left,n=e.clientY-t.top;i<0?i=0:i>l.width&&(i=l.width),n<0?n=0:n>l.height&&(n=l.height);let d=[e.clientX-t.left,e.clientY-t.top];if(-1!=r&&p(d,[i,n])>.5*l.height){if(a.move_out==LX.CURVE_MOVEOUT_DELETE)a.value.splice(r,1);else{let c=[d[0]-i,d[1]-n],m=a.value[r];m[0]=0==c[0]?m[0]:c[0]<0?a.xrange[0]:a.xrange[1],m[1]=0==c[1]?m[1]:c[1]<0?a.yrange[1]:a.yrange[0]}h(e);return}var f,v=s([-(a.draggable_x?o[0]-i:0),a.draggable_y?o[1]-n:0]);if(-1!=r){var E=a.xrange[0],$=a.xrange[1];a.no_overlap&&(r>0&&(E=a.value[r-1][0]),r<a.value.length-1&&($=a.value[r+1][0]));var y=a.value[r];y[0]+=v[0],y[1]+=v[1],y[0]<E?y[0]=E:y[0]>$&&(y[0]=$),y[1]<a.yrange[0]?y[1]=a.yrange[0]:y[1]>a.yrange[1]&&(y[1]=a.yrange[1])}g(),a.redraw(),o[0]=i,o[1]=n,u(e),e.preventDefault(),e.stopPropagation()}function h(e){r=-1,a.redraw(),document.removeEventListener("mousemove",c),document.removeEventListener("mouseup",h),u(e),e.preventDefault(),e.stopPropagation()}function u(e){i.callback&&i.callback.call(a,a.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(e,t){for(var i=1e5,l=-1,s=0;s<a.value.length;s++){var r=n(a.value[s]),o=p([e,t],r);o<i&&o<8&&(i=o,l=s)}return l}function g(){var e=null;-1!=r&&(e=a.value[r]),a.value.sort(function(e,t){return e[0]-t[0]}),e&&(r=a.value.indexOf(e))}return a.redraw(),this}redraw(e={}){this.element.redraw(e)}}LX.Curve=Curve;class Dial{constructor(e,t,i={}){let a=document.createElement("div");a.className="dial "+(i.className?i.className:""),a.style.width=a.style.height=i.size||"100%",a.style.minWidth=a.style.minHeight="50px",a.bgcolor=i.bgColor||LX.getThemeColor("global-dark-background"),a.pointscolor=i.pointsColor||LX.getThemeColor("global-selected-light"),a.linecolor=i.lineColor||"#555",a.value=t||[],a.xrange=i.xrange||[0,1],a.yrange=i.yrange||[0,1],a.defaulty=null!=i.defaulty?i.defaulty:0,a.no_overlap=i.noOverlap||!1,a.show_samples=i.showSamples||0,a.allow_add_values=i.allowAddValues??!0,a.draggable_x=i.draggableX??!0,a.draggable_y=i.draggableY??!0,a.smooth=(i.smooth&&"number"==typeof i.smooth?i.smooth:.3)||!1,a.move_out=i.moveOutAction??LX.CURVE_MOVEOUT_DELETE,this.element=a;let l=document.createElement("canvas");function n(e,t){return e[0],[l.width*(e[0]-a.xrange[0])/a.xrange[1],l.height*(e[1]-a.yrange[0])/a.yrange[1]]}function s(e){return[e[0]*a.xrange[1]/l.width+a.xrange[0],e[1]*a.yrange[1]/l.height+a.yrange[0]]}l.width=l.height=i.size||200,a.appendChild(l),this.canvas=l,a.addEventListener("mousedown",d),a.getValueAt=function(e){if(e<a.xrange[0]||e>a.xrange[1])return a.defaulty;for(var t=[a.xrange[0],a.defaulty],i=0,l=0;l<a.value.length;l+=1){var n=a.value[l];if(e==n[0])return n[1];if(e<n[0])return i=(e-t[0])/(n[0]-t[0]),t[1]*(1-i)+n[1]*i;t=n}return n=[a.xrange[1],a.defaulty],i=(e-t[0])/(n[0]-t[0]),t[1]*(1-i)+n[1]*i},a.resample=function(e){for(var t=[],i=(a.xrange[1]-a.xrange[0])/e,l=a.xrange[0];l<=a.xrange[1];l+=i)t.push(a.getValueAt(l));return t},a.addValue=function(e){for(var t=0;t<a.value;t++)if(!(a.value[t][0]<e[0])){a.value.splice(t,0,e),redraw();return}a.value.push(e),redraw()};var r=-1;a.redraw=function(e={}){e.value&&(a.value=e.value),e.xrange&&(a.xrange=e.xrange),e.yrange&&(a.yrange=e.yrange),e.smooth&&(a.smooth=e.smooth);var t=l.parentElement.getBoundingClientRect();l.parentElement.parentElement&&(t=l.parentElement.parentElement.getBoundingClientRect()),t&&l.width!=t.width&&t.width&&t.width<1e3&&(l.width=t.width);var i=l.getContext("2d");i.setTransform(1,0,0,1,0,0),i.translate(0,l.height),i.scale(1,-1),i.fillStyle=a.bgcolor,i.fillRect(0,0,l.width,l.height),i.strokeStyle=a.linecolor,i.beginPath();var s=n([a.xrange[0],a.defaulty]);i.moveTo(s[0],s[1]);let o=[s[0],s[1]];for(var d in a.value){var c=a.value[d];s=n(c),o.push(s[0]),o.push(s[1])}s=n([a.xrange[1],a.defaulty]),o.push(s[0]),o.push(s[1]),s=n([0,0]),i.fillStyle="gray",i.beginPath(),i.arc(s[0],s[1],3,0,2*Math.PI),i.fill();for(var d=0;d<a.value.length;d+=1){var c=a.value[d];s=n(c),r==d?i.fillStyle="white":i.fillStyle=a.pointscolor,i.beginPath(),i.arc(s[0],s[1],r==d?4:3,0,2*Math.PI),i.fill()}if(a.show_samples){var h=a.resample(a.show_samples);i.fillStyle="#888";for(var d=0;d<h.length;d+=1){var c=[d*((a.xrange[1]-a.xrange[0])/a.show_samples)+a.xrange[0],h[d]];s=n(c),i.beginPath(),i.arc(s[0],s[1],2,0,2*Math.PI),i.fill()}}};var o=[0,0];function d(e){document.addEventListener("mousemove",c),document.addEventListener("mouseup",h);var t=l.getBoundingClientRect(),i=e.clientX-t.left,n=e.clientY-t.top;if(r=m(i,l.height-n),e.button==LX.MOUSE_LEFT_CLICK&&-1==r&&a.allow_add_values){var d=s([i,l.height-n]);a.value.push(d),g(),r=a.value.indexOf(d)}o=[i,n],a.redraw(),e.preventDefault(),e.stopPropagation()}function c(e){var t=l.getBoundingClientRect(),i=e.clientX-t.left,n=e.clientY-t.top;i<0?i=0:i>l.width&&(i=l.width),n<0?n=0:n>l.height&&(n=l.height);let d=[e.clientX-t.left,e.clientY-t.top];if(-1!=r&&p(d,[i,n])>.5*l.height){if(a.move_out==LX.CURVE_MOVEOUT_DELETE)a.value.splice(r,1);else{let c=[d[0]-i,d[1]-n],m=a.value[r];m[0]=0==c[0]?m[0]:c[0]<0?a.xrange[0]:a.xrange[1],m[1]=0==c[1]?m[1]:c[1]<0?a.yrange[1]:a.yrange[0]}h(e);return}var f,v=s([-(a.draggable_x?o[0]-i:0),a.draggable_y?o[1]-n:0]);if(-1!=r){var E=a.xrange[0],$=a.xrange[1];a.no_overlap&&(r>0&&(E=a.value[r-1][0]),r<a.value.length-1&&($=a.value[r+1][0]));var y=a.value[r];y[0]+=v[0],y[1]+=v[1],y[0]<E?y[0]=E:y[0]>$&&(y[0]=$),y[1]<a.yrange[0]?y[1]=a.yrange[0]:y[1]>a.yrange[1]&&(y[1]=a.yrange[1])}g(),a.redraw(),o[0]=i,o[1]=n,u(e),e.preventDefault(),e.stopPropagation()}function h(e){r=-1,a.redraw(),document.removeEventListener("mousemove",c),document.removeEventListener("mouseup",h),u(e),e.preventDefault(),e.stopPropagation()}function u(e){i.callback&&i.callback.call(a,a.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(e,t){for(var i=1e5,l=-1,s=0;s<a.value.length;s++){var r=n(a.value[s]),o=p([e,t],r);o<i&&o<8&&(i=o,l=s)}return l}function g(){var e=null;-1!=r&&(e=a.value[r]),a.value.sort(function(e,t){return e[0]-t[0]}),e&&(r=a.value.indexOf(e))}return a.redraw(),this}redraw(e={}){this.element.redraw(e)}}LX.Dial=Dial;class AssetViewEvent{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||TreeEvent.NONE,this.item=t,this.value=i,this.multiple=!1}string(){switch(this.type){case AssetViewEvent.NONE:return"assetview_event_none";case AssetViewEvent.ASSET_SELECTED:return"assetview_event_selected";case AssetViewEvent.ASSET_DELETED:return"assetview_event_deleted";case AssetViewEvent.ASSET_RENAMED:return"assetview_event_renamed";case AssetViewEvent.ASSET_CLONED:return"assetview_event_cloned";case AssetViewEvent.ASSET_DBLCLICKED:return"assetview_event_dblclicked";case AssetViewEvent.ENTER_FOLDER:return"assetview_event_enter_folder";case AssetViewEvent.ASSET_CHECKED:return"assetview_event_checked"}}}LX.AssetViewEvent=AssetViewEvent;class AssetView{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??AssetView.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 t=document.createElement("div");t.className="lexassetbrowser",this.root=t;let i=new LX.Area({height:"100%"});t.appendChild(i.root);let a,l,n=i;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||([a,l]=i.split({type:"horizontal",sizes:["15%","85%"]}),n=l,a.setLimitBox(210,0),l.setLimitBox(512,0)),this.skipPreview||([n,l]=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(a),this._createContentPanel(n),this.skipPreview||(this.previewPanel=l.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 t=e=>{if(!e)return;let i=(e.children?e.children:e)[0];i&&i.folder&&(this.path.push(i.folder.id??"@"),t(i.folder.folder))};t(e),LX.emit("@on_folder_change",this.path.reverse().join("/"))}_createTreePanel(e){this.leftPanel?this.leftPanel.clear():this.leftPanel=e.addPanel({className:"lexassetbrowserpanel"});let t={id:"/",children:this.data};this.tree=this.leftPanel.addTree("Content Browser",t,{filter:!1,onlyFolders:this.onlyFolders,onevent:e=>{let t=e.node,i=e.value;switch(e.type){case LX.TreeEvent.NODE_SELECTED:e.multiple||this._enterFolder(t),t.parent||(this.prevData.push(this.currentData),this.currentData=this.data,this._refreshContent(),this.path=["@"],LX.emit("@on_folder_change",this.path.join("/")));break;case LX.TreeEvent.NODE_DRAGGED:t.folder=i,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=addContextMenu("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=addContextMenu("Layout",t,e=>{e.add("Content",()=>this._setContentLayout(AssetView.LAYOUT_CONTENT)),e.add(""),e.add("List",()=>this._setContentLayout(AssetView.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)/AssetView.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)/AssetView.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,t){let i=this.layout==AssetView.LAYOUT_CONTENT;this.filter=t??this.filter??"None",this.searchValue=e??this.searchValue??"",this.content.innerHTML="",this.content.className=i?"lexassetscontent":"lexassetscontent list";let a=this,l=function(e){let t=e.type.charAt(0).toUpperCase()+e.type.slice(1),l=getExtension(e.id),n="Folder"===t,s=document.createElement("li");if(s.className="lexassetitem "+e.type.toLowerCase(),s.tabIndex=-1,a.content.appendChild(s),a.useNativeTitle)s.title=t+": "+e.id;else{let r=document.createElement("span");r.className="lexitemdesc",r.innerHTML="File: "+e.id+"<br>Type: "+t,a.content.appendChild(r),s.addEventListener("mousemove",e=>{if(!i)return;let t=s.getBoundingClientRect(),a=e.target.getBoundingClientRect(),l=r.parentElement.getBoundingClientRect(),n=a.x-l.x-(a.x-t.x),o=a.y-l.y-(a.y-t.y);e.target.classList.contains("lexassettitle")&&(o+=a.y-t.y),r.style.left=n+e.offsetX+12+"px",r.style.top=o+e.offsetY+"px"}),s.addEventListener("mouseenter",()=>{i&&(r.style.display="unset")}),s.addEventListener("mouseleave",()=>{i&&setTimeout(()=>{r.style.display="none"},100)})}if(a.allowMultipleSelection){let o=document.createElement("input");o.type="checkbox",o.className="lexcheckbox",o.checked=e.selected,o.addEventListener("change",(t,i)=>{if(e.selected=!e.selected,a.onevent){let l=new AssetViewEvent(AssetViewEvent.ASSET_CHECKED,t.shiftKey?[e]:e);l.multiple=!!t.shiftKey,a.onevent(l)}t.stopPropagation(),t.stopImmediatePropagation()}),s.appendChild(o)}let d=document.createElement("span");if(d.className="lexassettitle",d.innerText=e.id,s.appendChild(d),!a.skipPreview){let c=null,h=e.src&&(["png","jpg"].indexOf(getExtension(e.src))>-1||e.src.includes("data:image/"));if(h||n||!i){c=document.createElement("img");let u=e.unknown_extension?a.rootPath+"images/file.png":n?a.rootPath+"images/folder.png":e.src;c.src=i||n?u:a.rootPath+"images/file.png",s.appendChild(c)}else{(c=document.createElement("svg")).className="asset-file-preview",s.appendChild(c);let p=document.createElement("text");c.appendChild(p),p.innerText=l&&l!=e.id?"."+l.toUpperCase():e.type.toUpperCase();var m,g=2.5/p.innerText.length;g<1&&(p.style.fontSize=64*g+"px",c.style.paddingTop="calc(50% - "+(.5*p.offsetHeight+10)+"px)")}}if(!n){let f=document.createElement("span");f.className="lexassetinfo",f.innerText=t,s.appendChild(f)}return s.addEventListener("click",function(t){t.stopImmediatePropagation(),t.stopPropagation();let i=t.detail==LX.MOUSE_DOUBLE_CLICK;if(i){if(n){a._enterFolder(e);return}}else t.shiftKey||a.content.querySelectorAll(".lexassetitem").forEach(e=>e.classList.remove("selected")),this.classList.add("selected"),a.selectedItem=e,a.skipPreview||a._previewAsset(e);if(a.onevent){let l=new AssetViewEvent(i?AssetViewEvent.ASSET_DBLCLICKED:AssetViewEvent.ASSET_SELECTED,t.shiftKey?[e]:e);l.multiple=!!t.shiftKey,a.onevent(l)}}),a.contextMenu&&s.addEventListener("contextmenu",function(t){t.preventDefault();let i=a.content.querySelectorAll(".selected").length;LX.addContextMenu(i>1?i+" selected":n?e.id:e.type,t,t=>{i<=1&&t.add("Rename"),n||t.add("Clone",a._cloneItem.bind(a,e)),i<=1&&t.add("Properties"),t.add(""),t.add("Delete",a._deleteItem.bind(a,e))})}),s.addEventListener("dragstart",function(e){e.preventDefault()},!1),s},n=new FileReader,s=this.currentData.filter(e=>("None"==this.filter||e.type.toLowerCase()==this.filter.toLowerCase())&&e.id.toLowerCase().includes(this.searchValue.toLowerCase()));(t||e)&&(this.contentPage=1);let r=(this.contentPage-1)*AssetView.MAX_PAGE_ELEMENTS,o=Math.min(r+AssetView.MAX_PAGE_ELEMENTS,s.length);for(let d=r;d<o;++d){let c=s[d];c.path?LX.request({url:c.path,dataType:"blob",success:i=>{c.bytesize=i.size,n.readAsDataURL(i),n.onload=i=>{c.src=i.currentTarget.result,c._path=c.path,delete c.path,this._refreshContent(e,t)}}}):c.domEl=l(c)}this.allowNextPage=s.length-1>AssetView.MAX_PAGE_ELEMENTS,LX.emit("@on_page_change","Page "+this.contentPage+" / "+(((s.length-1)/AssetView.MAX_PAGE_ELEMENTS|0)+1)),this.onRefreshContent&&this.onRefreshContent(e,t)}_previewAsset(e){let t=e.src&&e.src.includes("data:image/");if(this.previewPanel.clear(),this.previewPanel.branch("Asset"),"image"==e.type||e.src){let i=["png","jpg"].indexOf(getExtension(e.src))>-1||t;i&&this.previewPanel.addImage(e.src,{style:{width:"100%"}})}let a={disabled:!0};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._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();let l=[...this.previewActions];for(let n of(l.length||l.push({name:"Download",callback:()=>LX.downloadURL(e.src,e.id)}),l))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],n=this.currentData.find(e=>e.id===l.name);n||(t.readAsDataURL(l),t.onload=e=>{let t=l.name.substr(l.name.lastIndexOf(".")+1).toLowerCase(),n={id:l.name,src:e.currentTarget.result,extension:t,lastModified:l.lastModified};switch(t){case"png":case"jpg":n.type="image";break;case"js":case"css":n.type="script";break;case"json":n.type="json";break;case"obj":n.type="mesh";break;default:n.type=t,n.unknown_extension=!0}this.currentData.push(n),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 AssetViewEvent(AssetViewEvent.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 AssetViewEvent(AssetViewEvent.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=deepCopy(e);if(this.currentData.splice(t,0,i),this._refreshContent(this.searchValue,this.filter),this.onevent){let a=new AssetViewEvent(AssetViewEvent.ASSET_CLONED,e);this.onevent(a)}this._processData(this.data)}}LX.AssetView=AssetView,Object.assign(LX,{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(n){if(e.error)e.error(n);else throw n}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 n=e.length,s=[];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){n--,s.push(this),n?a&&a(this.original_src,this.num):t&&t(s)},i&&(o.onerror=function(e){i(e,this.original_src,this.num)}),document.getElementsByTagName("head")[0].appendChild(o)}},downloadURL(e,t){let i=new FileReader,a=function(e){var i=document.createElement("a");i.href=e,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i)};e.includes("http")?LX.request({url:e,dataType:"blob",success(e){i.readAsDataURL(e),i.onload=e=>{a(e.currentTarget.result)}}}):a(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),n=document.createElement("a");n.setAttribute("href",l),n.setAttribute("download",e),n.style.display="none",document.body.appendChild(n),n.click(),document.body.removeChild(n),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}},LX.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>'},LX.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:simple_guidGenerator,deleteElement(e){e&&e.remove()},flushCss(e){e.offsetHeight},getControlPoints(e,t,i,a,l,n,s){var r=Math.sqrt(Math.pow(i-e,2)+Math.pow(a-t,2)),o=s*r/(r+Math.sqrt(Math.pow(l-i,2)+Math.pow(n-a,2))),d=s-o;return[i+o*(e-l),a+o*(t-n),i-d*(e-l),a-d*(t-n)]},drawSpline(e,t,i){e.save();for(var a=[],l=t.length,n=0;n<l-4;n+=2)a=a.concat(LX.UTILS.getControlPoints(t[n],t[n+1],t[n+2],t[n+3],t[n+4],t[n+5],i));for(var n=2;n<t.length-5;n+=2)e.beginPath(),e.moveTo(t[n],t[n+1]),e.bezierCurveTo(a[2*n-2],a[2*n-1],a[2*n],a[2*n+1],t[n+2],t[n+3]),e.stroke(),e.closePath();e.beginPath(),e.moveTo(t[0],t[1]),e.quadraticCurveTo(a[0],a[1],t[2],t[3]),e.stroke(),e.closePath(),e.beginPath(),e.moveTo(t[l-2],t[l-1]),e.quadraticCurveTo(a[2*l-10],a[2*l-9],t[l-4],t[l-3]),e.stroke(),e.closePath(),e.restore()}};export{LX};
|
|
1
|
+
var y={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,i){return(e-t)*(i-n)/(a-t)+n}y.MOUSE_LEFT_CLICK=0,y.MOUSE_MIDDLE_CLICK=1,y.MOUSE_RIGHT_CLICK=2,y.MOUSE_DOUBLE_CLICK=2,y.MOUSE_TRIPLE_CLICK=3,y.CURVE_MOVEOUT_CLAMP=0,y.CURVE_MOVEOUT_DELETE=1,y.DRAGGABLE_Z_INDEX=101,y.clamp=f,y.round=E,y.remapRange=p,"undefined"!=typeof performance?y.getTime=performance.now.bind(performance):"undefined"!=typeof Date&&Date.now?y.getTime=Date.now.bind(Date):"undefined"!=typeof process?y.getTime=function(){var e=process.hrtime();return.001*e[0]+1e-6*e[1]}:y.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 y.UTILS.deleteElement(a),e.width+t}function b(){function e(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return e()+"-"+e()+"-"+e()}function x(s,t={}){let l=0,r=0,n=null,a=t.targetClass,o=t.dragMargin??3,i=(e,t,a)=>{var n=s.parentElement?s.parentElement.getBoundingClientRect():{x:0,y:0,width:0,height:0},i="fixed"==s.style.position?new y.vec2(n.x,n.y):new y.vec2;a=a??e.clientX-l-n.x,t=t??e.clientY-r-n.y,s.style.left=f(a,o+i.x,i.x+n.width-s.offsetWidth-o)+"px",s.style.top=f(t,o+i.y,i.y+n.height-s.offsetHeight-o)+"px",s.style.translate="none"};t.autoAdjust&&i(null,parseInt(s.style.left),parseInt(s.style.top));var e=y.UTILS.uidGenerator();s["draggable-id"]=e;let d=t.onMove?e=>{n&&t.onMove&&t.onMove(n)}:e=>{n&&i(e)},c=t.onDragStart;s.setAttribute("draggable",!0),s.addEventListener("mousedown",function(e){n=e.target.classList.contains(a)||!a?e.target:null}),s.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 y.vec2(a.x,a.y):new y.vec2,l=e.clientX-t.x-a.x,r=e.clientY-t.y-a.y,document.addEventListener("mousemove",d),n._eventCatched=!0,y.activeDraggable&&(y.activeDraggable.style.zIndex=y.DRAGGABLE_Z_INDEX),y.activeDraggable=s,y.activeDraggable.style.zIndex=y.DRAGGABLE_Z_INDEX+1,c)&&c(n,e)},!1),document.addEventListener("mouseup",e=>{n&&(n=null,document.removeEventListener("mousemove",d))})}y.doAsync=m,y.getSupportedDOMName=c,y.has=function(e){return-1<y.components.indexOf(e)},y.getExtension=d,y.deepCopy=g,y.setTheme=function(e){e="light"==e?"light":"dark",document.documentElement.setAttribute("data-theme",e),y.emit("@on_new_color_scheme",e)},y.setThemeColor=function(e,t){document.querySelector(":root").style.setProperty("--"+e,t)},y.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},y.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")},y.hexToRgb=h,y.rgbToHex=u,y.measureRealWidth=v,y.guidGenerator=b,y.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},y.makeDraggable=x,y.makeCollapsible=function(e,t,a,n={}){e.classList.add("collapsible");var n=n.collapsed??!0,i=y.makeIcon("Right");i.classList.add("collapser"),i.dataset.collapsed=n,i.style.marginLeft="auto",i.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(i),(a=a??e.parentElement).appendChild(t)},y.makeCodeSnippet=function(e,t,a={}){if(y.has("CodeEditor")){var n,i,s,l=document.createElement("div"),t=(l.className="lexcodesnippet",l.style.width=t?t[0]:"auto",l.style.height=t?t[1]:"auto",new _({noAppend:!0})),r=new y.CodeEditor(t,{skipInfo:!0,disableEdition:!0,allowAddScripts:!1,name:a.tabName});if(r.setText(e,a.language??"Plain Text"),a.linesAdded){let t=r.root.querySelector(".code");for(var o of a.linesAdded)if(o.constructor==Number)t.childNodes[o-1].classList.add("added");else if(o.constructor==Array)for(let e=o[0]-1;e<=o[1]-1;e++)t.childNodes[e].classList.add("added")}if(a.linesRemoved){let t=r.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&&((e=document.createElement("div")).className="lexwindowbuttons",(n=document.createElement("span")).style.background="#ee4f50",(i=document.createElement("span")).style.background="#f5b720",(s=document.createElement("span")).style.background="#53ca29",e.appendChild(n),e.appendChild(i),e.appendChild(s),r.root.querySelector(".lexareatabs").prepend(e)),(a.lineNumbers??!0)||r.root.classList.add("no-gutter"),l.appendChild(t.root),l}console.error("Import the CodeEditor component to create snippets!")},y.makeIcon=function(e,t,a=""){var n=document.createElement("a");return n.title=t??"",n.className="lexicon "+a,n.innerHTML=y.ICONS[e]??"",n},y.registerCommandbarEntry=function(e,t){y.extraCommandbarEntries.push({name:e,callback:t})};y.vec2=class o{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 o){return t.set(this.x+e.x,this.y+e.y),t}sub(e,t=new o){return t.set(this.x-e.x,this.y-e.y),t}mul(e,t=new o){return e.constructor==Number&&(e=new o(e)),t.set(this.x*e.x,this.y*e.y),t}div(e,t=new o){return e.constructor==Number&&(e=new o(e)),t.set(this.x/e.x,this.y/e.y),t}abs(e=new o){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 o){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 o){return a.set(f(this.x,e,t),f(this.y,e,t)),a}},y.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=(e=>{let l=document.createElement("dialog"),r=(l.className="commandbar",l.tabIndex=-1,e.appendChild(l),[]),o=null;l.addEventListener("keydown",function(e){var t,a;e.stopPropagation(),e.stopImmediatePropagation(),o=o??-1,"Escape"==e.key?(this.close(),h(!0)):"Enter"==e.key?(t=r[o])&&(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&&o<r.length-1?(o++,l.querySelectorAll(".hovered").forEach(e=>e.classList.remove("hovered")),r[o].classList.add("hovered"),0<(a=r[o].offsetHeight*(o+1)-d.offsetHeight)&&d.scrollTo({top:a,behavior:"smooth"})):"ArrowUp"==e.key&&0<o&&(o--,l.querySelectorAll(".hovered").forEach(e=>e.classList.remove("hovered")),r[o].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(),y.setCommandbarState(!0);else for(var t of y.components){var a;if(y[t]&&y[t].prototype.onKeyPressed)for(a of y.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);let 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 i,d=(n.add("All",document.createElement("div"),{selected:!0,onSelect:(e,t)=>{i=t}}),document.createElement("div")),c=(d.className="searchitembox",null),h=e=>{d.innerHTML="",r.length=0,o=null,e&&(a.value="")},u=(e,t,a,n)=>{var i,s;e.length&&(c&&c.classList.remove("last"),(i=document.createElement("div")).className="searchitem last",s=n&&n.type&&"checkbox"===n.type,i.innerHTML=s?"<a class='fa fa-check'></a><span>"+(a+e)+"</span>":a+e,i.entry_name=e,i.callback=t,i.item=n,i.addEventListener("click",function(e){this.callback.call(window,this.entry_name),y.setCommandbarState(!1),h(!0)}),i.addEventListener("mouseenter",function(e){l.querySelectorAll(".hovered").forEach(e=>e.classList.remove("hovered")),this.classList.add("hovered"),o=r.indexOf(this)}),i.addEventListener("mouseleave",function(e){this.classList.remove("hovered")}),r.push(i),d.appendChild(i),c=i)},p=(e,t,a)=>{var n=Object.keys(e)[0],i=e.name??a+n;if(i.toLowerCase().includes(t)&&e.callback&&u(e.name??n,e.callback,a,e),!e.name){a+=n+" > ";for(var s of e[n])p(s,t,a)}};return l._addElements=e=>{h();for(var t of y.menubars)for(var a of t.items)p(a,e,"");for(var n of y.extraCommandbarEntries){var i=n.name;i.toLowerCase().includes(e)&&u(i,n.callback,"",{})}if(y.has("CodeEditor")){let a=y.CodeEditor.getInstances();if(a.length){var s=a[0].languages;for(let t of Object.keys(s)){var l="Language: "+t,r=a[0]._getFileIcon(null,s[t].ext),r=r.includes("fa-")?"<i class='"+r+"'></i>":"<img src='https://raw.githubusercontent.com/jxarco/lexgui.js/master/"+r+"'>";r+=l+" <span class='lang-ext'>("+s[t].ext+")</span>",l.toLowerCase().includes(e)&&u(r,()=>{for(var e of a)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&&(y.setTheme("light"),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",e=>{y.setTheme(e.matches?"dark":"light")}))),this.main_area},y.setCommandbarState=function(e,t=!0){var a=this.commandbar;e?(a.show(),a.querySelector("input").focus(),t&&a._addElements(void 0)):a.close()},y.message=function(t,e,a={}){if(t)return a.modal=!0,new A(e,e=>{e.addTextArea(null,t,null,{disabled:!0,fitHeight:!0})},a);throw"No message to show"},y.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;let i=new A(e,e=>{e.addTextArea(null,t,null,{disabled:!0,fitHeight:!0})},a);return setTimeout(()=>{i.close()},Math.max(n,150)),i},y.prompt=function t(a,n,i,s={}){s.modal=!0,s.className="prompt";let l="",r=new A(n,e=>{e.addTextArea(null,a,null,{disabled:!0,fitHeight:!0}),(s.input??!0)&&e.addText(null,s.input||l,e=>l=e,{placeholder:"..."}),e.sameLine(2),e.addButton(null,"Cancel",()=>{s.on_cancel&&s.on_cancel(),r.close()}),e.addButton(null,s.accept||"Continue",()=>{s.required&&""===l?(a+=a.includes("You must fill the input text.")?"":"\nYou must fill the input text.",r.close(),t(a,n,i,s)):(i&&i.call(this,l),r.close())},{buttonClass:"primary"})},s);return(s.input??!0)&&r.root.querySelector("input").focus(),r},y.toast=function(e,t,a={}){if(!e)throw"The toast needs at least a title!";console.assert(this.notifications);let 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 i=document.createElement("div"),s=(i.className="lextoastcontent",n.appendChild(i),document.createElement("div"));s.className="title",s.innerHTML=e,i.appendChild(s),t&&((e=document.createElement("div")).className="desc",e.innerHTML=t,i.appendChild(e)),a.action&&((s=new k).addButton(null,a.action.name??"Accept",a.action.callback.bind(this,n),{width:"auto",maxWidth:"150px",className:"right",buttonClass:"outline"}),n.appendChild(s.root.childNodes[0]));let 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!=(i=a.timeout??3e3)&&m(()=>{n.close()},i)},y.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},y.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 w{constructor(e,t,a){this.name=e,this.value=t,this.domEvent=a}}y.IEvent=w;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"}}}y.TreeEvent=L,y.emit=function(e,t,a={}){var n=y.signals[e];if(n){var i=a.target;if(i)i[e]&&i[e].call(i,t);else for(var s of n)s.constructor===T?(s.set(t,a.skipCallback??!0),s.options&&s.options.callback&&s.options.callback(t,n)):s(null,t)}},y.addSignal=function(e,t,a){t[e]=a,y.signals[e]||(y.signals[e]=[]),-1<y.signals[e].indexOf(t)||y.signals[e].push(t)};class _{constructor(e={}){var n,i,t=document.createElement("div"),a=(t.className="lexarea",e.id&&(t.id=e.id),e.className&&(t.className+=" "+e.className),e.width||"calc( 100% )"),s=e.height||"100%",a=(this.setLimitBox(e.minWidth,e.minHeight,e.maxWidth,e.maxHeight),a.constructor==Number&&(a+="px"),s.constructor==Number&&(s+="px"),t.style.width=a,t.style.height=s,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=i[0]-e.x,a=n.root.offsetWidth+t;n.root.style.width=a+"px";break;case"left":t=i[0]-e.x,a=Math.min(document.body.clientWidth-y.DEFAULT_SPLITBAR_SIZE,n.root.offsetWidth-t);n.root.style.width=a+"px",n.splitBar.style.left=a+y.DEFAULT_SPLITBAR_SIZE/2+"px";break;case"top":t=i[1]-e.y,a=Math.min(document.body.clientHeight-y.DEFAULT_SPLITBAR_SIZE,n.root.offsetHeight-t);n.root.style.height=a+"px",n.splitBar.style.top=a+y.DEFAULT_SPLITBAR_SIZE/2+"px";break;case"bottom":t=i[1]-e.y,a=n.root.offsetHeight+t;n.root.style.height=a+"px"}i[0]=e.x,i[1]=e.y,e.stopPropagation(),e.preventDefault(),n.onresize&&n.onresize(n.root.getBoundingClientRect())}function r(e){var t=n.root.ownerDocument;t.removeEventListener("mousemove",l),t.removeEventListener("mouseup",r),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)&&x(t,e),e.resizeable&&t.classList.add("resizeable"),e.resize)&&(this.splitBar=document.createElement("div"),s="left"==a||"right"==a?"horizontal":"vertical",this.type=a,this.splitBar.className="lexsplitbar "+s,"right"==a?(this.splitBar.style.width=y.DEFAULT_SPLITBAR_SIZE+"px",this.splitBar.style.left=-y.DEFAULT_SPLITBAR_SIZE/2+"px"):"left"==a?(t=Math.min(document.body.clientWidth-y.DEFAULT_SPLITBAR_SIZE,this.root.clientWidth),this.splitBar.style.width=y.DEFAULT_SPLITBAR_SIZE+"px",this.splitBar.style.left=t+y.DEFAULT_SPLITBAR_SIZE/2+"px"):"top"==a?(e=Math.min(document.body.clientHeight-y.DEFAULT_SPLITBAR_SIZE,this.root.clientHeight),this.splitBar.style.height=y.DEFAULT_SPLITBAR_SIZE+"px",this.splitBar.style.top=e+y.DEFAULT_SPLITBAR_SIZE/2+"px"):"bottom"==a&&(this.splitBar.style.height=y.DEFAULT_SPLITBAR_SIZE+"px",this.splitBar.style.top=-y.DEFAULT_SPLITBAR_SIZE/2+"px"),this.splitBar.addEventListener("mousedown",function(e){var t=n.root.ownerDocument;t.addEventListener("mousemove",l),t.addEventListener("mouseup",r),i[0]=e.x,i[1]=e.y,e.stopPropagation(),e.preventDefault(),document.body.classList.add("nocursor"),n.splitBar.classList.add("nocursor")}),this.root.appendChild(this.splitBar),n=this,i=[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 i=t.top||0;e.constructor==Number&&(e=e+i+"px"),n[1]="calc( 100% - "+e+" )"}var s,l,i=new _({skipAppend:!0,className:"split"+(t.menubar||t.sidebar?"":" origin")}),r=new _({skipAppend:!0,className:"split"}),o=(i.parentArea=this,r.parentArea=this,t.minimizable??!1),t=(t.resize??!0)||o,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=y.DEFAULT_SPLITBAR_SIZE+"px":this.splitBar.style.height=y.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=y.DEFAULT_SPLITBAR_SIZE/2+"px",o)&&(this.splitExtended=!1,r.root.addEventListener("animationend",e=>{var t=getComputedStyle(r.root).opacity;r.root.classList.remove(e.animationName+"-"+a),r.root.style.opacity=t,C(r.root)}),this.splitBar.addEventListener("contextmenu",e=>{e.preventDefault(),S(null,e,e=>{e.add("Extend",{disabled:this.splitExtended,callback:()=>{this.extend()}}),e.add("Reduce",{disabled:!this.splitExtended,callback:()=>{this.reduce()}})})})),"horizontal"==a?(o=n[0],s=n[1],o.constructor==Number&&(o+="px"),s.constructor==Number&&(s+="px"),i.root.style.width="calc( "+o+" - "+d+" )",i.root.style.height="calc(100% - 0px)",r.root.style.width="calc( "+s+" - "+d+" )",r.root.style.height="calc(100% - 0px)",this.root.style.display="flex"):(i.root.style.width="100%",r.root.style.width="100%",e?(i.root.style.height="auto",new ResizeObserver(e=>{for(var t of e){t=t.contentRect;r.root.style.height="calc(100% - "+(t.height+4)+"px )"}}).observe(i.root)):(o=n[0],s=n[1],o.constructor==Number&&(o+="px"),s.constructor==Number&&(s+="px"),i.root.style.width="100%",i.root.style.height="auto"==o?o:"calc( "+o+" - "+d+" )",r.root.style.height="auto"==s?s:"calc( "+s+" - "+d+" )")),this.root.appendChild(i.root),t&&this.root.appendChild(this.splitBar),this.root.appendChild(r.root),this.sections=[i,r],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 i(t),[e,n]=(e&&e(a),y.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(),y.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(n,i={}){if(this.sections.length)this.sections[1].addOverlayButtons(n,i);else{console.assert(n.constructor==Array&&n.length),this.root.style.position="relative",i.className="lexoverlaybuttons";let s=this.addPanel(i),l=null,e=document.createElement("div"),t=(e.className="lexoverlaybuttonscontainer",e.appendChild(s.root),this.attach(e),i.float);if(t)for(var r=0;r<t.length;r++)switch(t[r]){case"h":break;case"v":e.className+=" vertical";break;case"t":break;case"m":e.className+=" middle";break;case"b":e.className+=" bottom";break;case"l":break;case"c":e.className+=" center";break;case"r":e.className+=" right"}let a=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",s.queuedContainer=l),a.parent=l);let i=n.callback;n.options?s.addDropdown(null,n.options,n.name,i,a):s.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),i(e,t)},a),l&&t&&(s.root.appendChild(l),l=null,s.clearQueue())};var o,d;s.clear();for(d of n)if(d.constructor===Array)for(let e=0;e<d.length;++e){var c=d[e];c.group=d,a(c,!0,e==d.length-1)}else a(d);t&&(o=0,s.root.childNodes.forEach(e=>{o+=e.offsetHeight}),e.className.includes("middle"))&&(e.style.top="-moz-calc( 50% - "+.5*o+"px )",e.style.top="-webkit-calc( 50% - "+.5*o+"px )",e.style.top="calc( 50% - "+.5*o+"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 i,s=this.sections[0],l=s.root,r=(l.classList.contains("origin")||(l=l.parentElement),this.sections[1]),o=r.root,d=" - "+y.DEFAULT_SPLITBAR_SIZE+"px";let e=null;a||(e=l.style.transition,l.style.transition=o.style.transition="none",C(l),C(o)),"horizontal"==this.type?(i=Math.max(o.offsetWidth+t,parseInt(r.minWidth)),l.style.width="-moz-calc( 100% - "+(i=n?n:i)+"px "+d+" )",l.style.width="-webkit-calc( 100% - "+i+"px "+d+" )",l.style.width="calc( 100% - "+i+"px "+d+" )",l.style.minWidth=parseInt(s.minWidth)+"px",o.style.width=i+"px",s.maxWidth!=1/0&&(o.style.minWidth="calc( 100% - "+parseInt(s.maxWidth)+"px )")):(i=Math.max(o.offsetHeight+t+r.offset,parseInt(r.minHeight)),l.style.height="-moz-calc( 100% - "+(i=n?n:i)+"px "+d+" )",l.style.height="-webkit-calc( 100% - "+i+"px "+d+" )",l.style.height="calc( 100% - "+i+"px "+d+" )",l.style.minHeight=s.minHeight+"px",o.style.height=i-r.offset+"px"),a||(l.style.transition=o.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}y.Area=_;class l{static TAB_SIZE=28;static TAB_ID=0;constructor(a,e={}){this.onclose=e.onclose;var t=document.createElement("div"),n=(t.className="lexareatabs "+(e.fit?"fit":"row"),e.folding??!1);n&&t.classList.add("folding");let i=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"),i.area.attach(e),this.classList.remove("dockingtab"),y.emit("@on_tab_docked"),t.instance=i,t.click(),i.tabs[t.dataset.name]=e)}),a.root.classList.add("lexareatabscontainer"),a.split({type:"vertical",sizes:e.sizes??"auto",resize:!1,top:6}),a.sections[0].attach(t),this.area=a.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)),n&&(this.folded=!0,"up"==(this.folding=n)&&a.root.insertChildAtIndex(a.sections[1].root,0),new ResizeObserver(e=>{for(var t of e){t=t.contentRect;a.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,i=(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);i.originalDisplay=i.style.display,i.style.display=n?i.originalDisplay:"none",i.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 s=document.createElement("span");s.dataset.name=e,s.className="lexareatab"+(n?" selected":""),s.innerHTML=(a.icon??"")+e,s.id=e.replace(/\s/g,"")+l.TAB_ID++,s.title=a.title??"",s.selected=n??!1,s.fixed=a.fixed,s.instance=this,i.id=s.id+"_content",s.selected&&(this.selected=e),y.addSignal("@on_tab_docked",s,function(){1==this.parentElement.childNodes.length&&this.parentElement.childNodes[0].click()}),s.addEventListener("click",e=>{var t;e.preventDefault(),e.stopPropagation(),s.fixed||(t=s.selected,s.parentElement.querySelectorAll("span").forEach(e=>e.selected=!1),s.selected=!t,s.parentElement.querySelectorAll("span").forEach(e=>e.classList.remove("selected")),s.classList.toggle("selected",this.folding&&s.selected),s.instance.area.root.querySelectorAll(".lextabcontent").forEach(e=>e.style.display="none"),i.style.display=i.originalDisplay,s.instance.selected=s.dataset.name),this.folding&&(this.folded=s.selected,this.area.root.classList.toggle("folded",!this.folded)),a.onSelect&&a.onSelect(e,s.dataset.name),this.thumb&&(this.thumb.style.transform="translate( "+s.childIndex*s.offsetWidth+"px )",this.thumb.style.width=s.offsetWidth-5+"px",this.thumb.style.height=s.offsetHeight-6+"px",this.thumb.item=s)}),s.addEventListener("contextmenu",e=>{e.preventDefault(),e.stopPropagation(),a.onContextMenu&&a.onContextMenu(e,s.dataset.name)}),s.addEventListener("mouseup",e=>{e.preventDefault(),e.stopPropagation(),1==e.button&&this.delete(s.dataset.name)}),s.setAttribute("draggable",!0),s.addEventListener("dragstart",function(e){1==this.parentElement.childNodes.length?e.preventDefault():e.dataTransfer.setData("source",e.target.id)}),s.childIndex=this.root.childElementCount-1,this.root.appendChild(s),this.area.attach(i),this.tabDOMs[e]=s,this.tabs[e]=t,setTimeout(()=>{a.onCreate&&a.onCreate.call(this,this.area.root.getBoundingClientRect()),n&&this.thumb&&(this.thumb.style.transform="translate( "+s.childIndex*s.offsetWidth+"px )",this.thumb.style.width=s.offsetWidth-5+"px",this.thumb.style.height=s.offsetHeight-6+"px",this.thumb.item=s)},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()}}y.Tabs=l;class i{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}),y.root.querySelectorAll(".lexmenubox").forEach(e=>e.remove()),this.focused=!1}_createSubmenu(e,t,a,l){let r=document.createElement("div"),n=(r.className="lexmenubox",r.tabIndex="0",((a.currentMenu=r).parentEntry=a).classList.contains("lexmenuboxentry"));n&&(r.dataset.submenu=!0),r._updatePosition=()=>{let t=r.style.transition;r.style.transition="none",C(r),m(()=>{var e=a.getBoundingClientRect();e.x+=document.scrollingElement.scrollLeft,e.y+=document.scrollingElement.scrollTop,r.style.left=(n?e.x+e.width:e.x)+"px",r.style.top=(n?e.y:e.y+e.height-4)+"px",r.style.transition=t})},r._updatePosition(),m(()=>{r.dataset.open=!0},10),y.root.appendChild(r);for(var o=0;o<e[t].length;++o){let a=e[t][o],n=Object.keys(a)[0];var d,c,h=a[n].length,u="checkbox"==a.type;let i=document.createElement("div"),s=(i.className="lexmenuboxentry",i.className+=(o==e[t].length-1?" last":"")+(a.disabled?" disabled":""),""==n?i.className=" lexseparator":(i.id=n,(d=document.createElement("div")).innerHTML="",d.classList="lexmenuboxentrycontainer",i.appendChild(d),c=this.icons[n],u?d.innerHTML+="<input type='checkbox' >":c?d.innerHTML+="<a class='"+c+" fa-sm'></a>":(d.innerHTML+="<a class='fa-solid fa-sm noicon'></a>",d.classList.add("noicon")),d.innerHTML+="<div class='lexentryname'>"+n+"</div>"),i.querySelector("input"));s&&(s.checked=a.checked??!1,s.addEventListener("change",e=>{a.checked=s.checked;var t=a.callback;t&&(t.call(this,a.checked,n,i),this._resetMenubar()),e.stopPropagation(),e.stopImmediatePropagation()})),r.appendChild(i),""!=n&&(r.addEventListener("keydown",e=>{e.preventDefault();let t=this.shorts[n];t&&(t=1==t.length?t.toLowerCase():t)==e.key&&i.click()}),i.addEventListener("click",e=>{s&&(a.checked=!a.checked);var t=a.callback;t&&(t.call(this,s?a.checked:n,s?n:i),this._resetMenubar()),e.stopPropagation(),e.stopImmediatePropagation()}),h?((u=document.createElement("a")).className="fa-solid fa-angle-right fa-xs",i.appendChild(u),i.addEventListener("mouseover",e=>{i.built||(i.built=!0,this._createSubmenu(a,n,i,++l),e.stopPropagation())}),i.addEventListener("mouseleave",e=>{i.currentMenu&&i.currentMenu!=e.toElement&&(l=-1,delete i.built,i.currentMenu.remove(),delete i.currentMenu)})):this.shorts[n]&&((c=document.createElement("div")).className="lexentryshort",c.innerText=this.shorts[n],i.appendChild(c)))}r.style.width=r.offsetWidth+"px"}add(e,s={}){s.constructor==Function&&(s={callback:s});let l=e.split("/");e=l[l.length-1];this.icons[e]=s.icon,this.shorts[e]=s.short;let r=0,o=(n,e)=>{if(null!=n){let a=null;var t,i;e.forEach(e=>{var t=Object.keys(e).find(e=>e==n);t&&(a=e[t])}),a?o(l[r++],a):((t={})[n]=[],(i=l[r++])||(t.callback=s.callback,t.disabled=s.disabled,t.type=s.type,t.checked=s.checked),e.push(t),o(i,t[n]))}};o(l[r++],this.items);for(let i of this.items){let n=Object.keys(i)[0];var d=n.replace(/\s/g,"").replaceAll(".","");if(!this.root.querySelector("#"+d)){let t=document.createElement("div"),a=(t.className="lexmenuentry",t.id=d,t.innerHTML="<span>"+n+"</span>",t.tabIndex="1","left"==s.position?this.root.prepend(t):("right"==s.position&&(t.right=!0),this.root.lastChild&&this.root.lastChild.right?this.root.lastChild.before(t):this.root.appendChild(t)),()=>{this._resetMenubar(),t.classList.add("selected"),t.built=!0,this._createSubmenu(i,n,t,-1)});t.addEventListener("click",()=>{var e=i.callback;e?e.call(this,n,t):(a(),this.focused=!0)}),t.addEventListener("mouseover",e=>{this.focused&&!t.built&&a()}),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,n,i,s={}){if(!e)throw"Set Button Name!";let l=this.buttons[e];if(l)l.querySelector("a").className="fa-solid "+n+" lexicon";else{l=document.createElement("div");let t=s.disabled??!1,a=(l.className="lexmenubutton main"+(t?" disabled":""),l.title=e,l.innerHTML="<a class='"+n+" lexicon'></a>","right"==s.float&&(l.right=!0),this.root.lastChild&&this.root.lastChild.right?this.root.lastChild.before(l):"left"==s.float?this.root.prepend(l):this.root.appendChild(l),l.querySelector("a"));a.addEventListener("click",e=>{i&&!t&&i.call(this,a,e)}),this.buttons[e]=l}}setButtonImage(e,n,i,s={}){if(!e)throw"Set Button Name!";let l=this.buttons[e];if(l)l.querySelector("img").src=n;else{l=document.createElement("div");let t=s.disabled??!1,a=(l.className="lexmenubutton"+(t?" disabled":""),l.title=e,l.innerHTML="<a><image src='"+n+"' class='lexicon' style='height:32px;'></a>","right"==s.float&&(l.right=!0),this.root.lastChild&&this.root.lastChild.right?this.root.lastChild.before(l):"left"==s.float?this.root.prepend(l):this.root.appendChild(l),l.querySelector("a"));a.addEventListener("click",e=>{i&&!t&&i.call(this,a,e)}),this.buttons[e]=l}}addButtons(s,e={}){if(!s)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<s.length;++t){let a=s[t],n=document.createElement("label");var l=a.title;let i=a.disabled??!1;n.className="lexmenubutton"+(i?" disabled":""),n.title=l??"",this.buttonContainer.appendChild(n);var r=document.createElement("a");r.className=a.icon+" lexicon",n.appendChild(r);let e=r;a.swap&&(n.classList.add("swap"),r.classList.add("swap-off"),(r=document.createElement("input")).type="checkbox",n.prepend(r),e=r,(r=document.createElement("a")).className=a.swap+" swap-on lexicon",n.appendChild(r),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&&!i&&(t=n.querySelector("input"),a.callback.call(this,e,t?.checked))}),l&&(this.buttons[l]=n)}}}y.Menubar=i;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(var 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=y.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=y.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=y.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),y.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,s={}){s.constructor==Function&&(s={callback:s});let l=e.split("/");e=l[l.length-1];this.icons[e]=s.icon;let r=0,o=(n,e)=>{if(null!=n){let a=null;var t,i;e.forEach(e=>{var t=Object.keys(e).find(e=>e==n);t&&(a=e[t])}),a?o(l[r++],a):((t={})[n]=[],(i=l[r++])||(t.callback=s.callback,t.group=this.currentGroup,t.options=s),e.push(t),o(i,t[n]))}};o(l[r++],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 r of this.items){let n=r.options??{};if(!r.dom){let l=Object.keys(r)[0];if(!this.filterString.length||l.toLowerCase().includes(this.filterString.toLowerCase())){var i=l.replace(/\s/g,"").replaceAll(".","");let t=null,s=document.createElement("div");if(s.className="lexsidebarentry "+(n.className??""),s.id=r.name=i,r.group){var a=r.group.replace(/\s/g,"").replaceAll(".","");if(t=this.content.querySelector("#"+a)){if(!t.classList.contains("lexsidebargroup"))throw"Bad id: "+r.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=r.group,a.appendChild(o),null!=this.groups[r.group]&&((o=document.createElement("a")).className=(this.groups[r.group].icon??"")+" lexicon",a.appendChild(o),o.addEventListener("click",e=>{this.groups[r.group].callback&&this.groups[r.group].callback(r.group,e)}))}}if(""==i){a=document.createElement("div");a.className="lexsidebarseparator",this.content.appendChild(a)}else{this.collapseContainer?(this.collapseContainer.appendChild(s),this.collapseQueue--,this.collapseQueue||delete this.collapseContainer):(t||this.content).appendChild(s);let a=document.createElement("div");s.appendChild(a),r.dom=s,"checkbox"==n.type?(r.value=n.value??!1,o=new k,r.checkbox=o.addCheckbox(null,r.value,(e,t)=>{t.preventDefault(),t.stopPropagation();var a=n.callback;r.value=e,a&&a.call(this,l,e,t)},{label:l,signal:"@checkbox_"+l}),a.appendChild(o.root.childNodes[0])):(n.icon&&((i=document.createElement("i")).className=n.icon,a.appendChild(i)),(i=document.createElement("a")).innerHTML=l,a.appendChild(i)),s.addEventListener("click",e=>{var t;e.target&&e.target.classList.contains("lexcheckbox")||(n.collapsable?a.querySelector(".collapser").click():((t=n.callback)&&t.call(this,l,r.value,e),r.checkbox&&(r.value=!r.value,r.checkbox.set(r.value,!0))),this.root.querySelectorAll(".lexsidebarentry").forEach(e=>e.classList.remove("selected")),s.classList.add("selected"))});var d,i=null!=n.collapsable?n.collapsable:n.collapsable||r[l].length;n.action?(d=y.makeIcon(n.action.icon??"MoreHorizontal",n.action.name),a.appendChild(d),d.addEventListener("click",e=>{e.preventDefault(),e.stopImmediatePropagation();var t=n.action.callback;t&&t.call(this,l,e)})):i&&(d=document.createElement("div"),Object.assign(d.style,{width:"100%",display:"none"}),y.makeCollapsible(a,d,t??this.content),this.collapseQueue=n.collapsable,this.collapseContainer=d);let e=document.createElement("span");if(e.className="lexsidebarentrydesc",e.innerHTML=l,s.appendChild(e),a.addEventListener("mouseenter",()=>{setTimeout(()=>{e.style.display="unset"},150)}),a.addEventListener("mouseleave",()=>{setTimeout(()=>{e.style.display="none"},150)}),r[l].length){var c=document.createElement("div");c.className="lexsidebarsubentrycontainer",i?(this.collapseContainer.appendChild(c),delete this.collapseContainer):(t||this.content).appendChild(c);for(let e=0;e<r[l].length;++e){var h=r[l][e];let n=h.options??{},i=Object.keys(h)[0];if(!this.filterString.length||i.toLowerCase().includes(this.filterString.toLowerCase())){let a=document.createElement("div");a.innerHTML=`<span>${i}</span>`,n.action&&(h=y.makeIcon(n.action.icon??"MoreHorizontal",n.action.name),a.appendChild(h),h.addEventListener("click",e=>{e.preventDefault(),e.stopImmediatePropagation();var t=n.action.callback;t&&t.call(this,i,e)})),a.className="lexsidebarentry",a.id=i,c.appendChild(a),a.addEventListener("click",e=>{var t=n.callback;t&&t.call(this,i,a,e),this.root.querySelectorAll(".lexsidebarentry").forEach(e=>e.classList.remove("selected")),s.classList.add("selected")})}}}}}}}}}y.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)||S(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(){}}y.Widget=T,y.ADD_CUSTOM_WIDGET=function(p,m={}){let e=b();k.prototype["add"+p]=function(i,s,l){let r=this._createWidget(T.CUSTOM,i,null,m),o=(r.customName=p,r.customIdx=e,r.onGetValue=()=>s,r.onSetValue=(e,t,a)=>{s=e,u(),o.querySelector(".lexcustomitems").toggleAttribute("hidden",!1),t||this._trigger(new w(i,s,a),l)},r.domEl);o.style.flexWrap="wrap";let d,c,h=m.default??{},u=()=>{s&&(r.instance=s=Object.assign(g(h),s)),d&&d.remove(),c&&c.remove(),(d=document.createElement("div")).className="lexcustomcontainer",d.style.width="calc( 100% - "+y.DEFAULT_NAME_WIDTH+")",this.queue(d);var e="<a class='fa-solid "+(m.icon??"fa-cube")+"' style='float:left'></a>",e=(e=e+(p+(s?"":" [empty]"))+("<a class='fa-solid "+(s?"fa-bars-staggered":" ")+" menu' style='float:right; width:5%;'></a>"),this.addButton(null,e,(e,t)=>{s?o.querySelector(".lexcustomitems").toggleAttribute("hidden"):S(null,t,e=>{e.add("New "+p,()=>{s={},u(),o.querySelector(".lexcustomitems").toggleAttribute("hidden",!1)})})},{buttonClass:"custom"}));if(this.clearQueue(),s&&e.querySelector("a.menu").addEventListener("click",e=>{e.stopImmediatePropagation(),e.stopPropagation(),S(null,e,e=>{e.add("Clear",()=>{s=null,u()})})}),(c=document.createElement("div")).className="lexcustomitems",c.toggleAttribute("hidden",!0),o.appendChild(d),o.appendChild(c),s){this.queue(c);var t,a=(e,t,a)=>{s[e]=t,this._trigger(new w(i,s,a),l)};for(t in h){var n=s[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,s,t=0,a){let l=this;var n=this.domEl.querySelector("#lexnodetree_filter");if(s.children=s.children??[],n&&!s.id.includes(n.value)||null!=a&&a!=s.id){for(var i=0;i<s.children.length;++i)this._create_item(s,s.children[i],t+1,a);return}let r=this.domEl.querySelector("ul"),o=(s.visible=s.visible??!0,s.parent=e,0<s.children.length);n=-1<this.selected.indexOf(s)||s.selected;if(this.options.onlyFolders){let t=!1;s.children.forEach(e=>t|="folder"==e.type),o=!!t}let d=document.createElement("li"),c=(d.className="lextreeitem datalevel"+t+(o?" parent":"")+(n?" selected":""),d.id=y.getSupportedDOMName(s.id),d.tabIndex="0",this.options.skip_default_icon??!0?"":"fa-solid fa-square");o&&(c=s.closed?"fa-solid fa-caret-right":"fa-solid fa-caret-down"),d.innerHTML="<a class='"+c+" hierarchy'></a>",c=s.icon,s.icon&&(s.icon.includes("fa-")?d.innerHTML+="<a class='"+s.icon+" tree-item-icon'></a>":d.innerHTML+="<img src='https://raw.githubusercontent.com/jxarco/lexgui.js/master/"+s.icon+"'>"),d.innerHTML+=s.rename?"":s.id,d.setAttribute("draggable",!0),d.style.paddingLeft=(o?0:3)+(3+15*(t+1))+"px",r.appendChild(d),d.addEventListener("click",e=>{var t;h?h=!1:(e.shiftKey||(r.querySelectorAll("li").forEach(e=>{e.classList.remove("selected")}),this.selected.length=0),-1<(t=this.selected.indexOf(s))?(d.classList.remove("selected"),this.selected.splice(t,1)):(d.classList.add("selected"),this.selected.push(s)),o&&1<s.id.length&&(s.closed=!1,l.onevent&&(t=new L(L.NODE_CARETCHANGED,s,s.closed),l.onevent(t)),l.frefresh(s.id)),l.onevent&&((t=new L(L.NODE_SELECTED,e.shiftKey?this.selected:s)).multiple=e.shiftKey,l.onevent(t)))}),d.addEventListener("dblclick",function(){var e;(l.options.rename??!0)&&(s.rename=!0,l.refresh()),l.onevent&&(e=new L(L.NODE_DBLCLICKED,s),l.onevent(e))}),d.addEventListener("contextmenu",a=>{if(a.preventDefault(),l.onevent){let t=new L(L.NODE_CONTEXTMENU,1<this.selected.length?this.selected:s,a);t.multiple=1<this.selected.length,y.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",()=>{let 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(s)}),t.panel.add("Delete",{callback:()=>{var e,t;s.parent&&(l.onevent&&(e=new L(L.NODE_DELETED,s,a),l.onevent(e)),t=(e=s.parent.children).indexOf(s),e.splice(t,1),this.refresh())}}))}}),d.addEventListener("keydown",e=>{if(!s.rename)if(e.preventDefault(),"Delete"==e.key){var t;l.onevent&&((i=new L(L.NODE_DELETED,1<this.selected.length?this.selected:s,e)).multiple=1<this.selected.length,l.onevent(i));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 i;("ArrowUp"==e.key||"ArrowDown"==e.key)&&(i=1<this.selected.length?"ArrowUp"==e.key?this.selected.shift():this.selected.pop():this.selected[0],i=this.domEl.querySelector("#"+y.getSupportedDOMName(i.id)),e="ArrowUp"==e.key?i.previousSibling:i.nextSibling)&&e.click()}});n=document.createElement("input");n.toggleAttribute("hidden",!s.rename),n.value=s.id,d.appendChild(n),s.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,s,this.value),l.onevent(t)),s.id=y.getSupportedDOMName(this.value),delete s.rename,l.frefresh(s.id),r.querySelector("#"+s.id).classList.add("selected")):"Escape"==e.key&&(delete s.rename,l.frefresh(s.id))}),n.addEventListener("blur",function(e){delete s.rename,l.refresh()}),(this.options.draggable??!0)&&(e&&d.addEventListener("dragstart",e=>{window.__tree_node_dragged=s}),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=s;if(t.id==e.id)console.warn("Cannot parent node to itself!");else{let i=function(e,t){var a,n=!1;for(a of t.children){if(a.id==e.id)return!0;n|=i(e,a)}return n};i(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;o&&d.querySelector("a.hierarchy").addEventListener("click",function(e){h=!0,e.stopImmediatePropagation(),e.stopPropagation(),s.closed=!s.closed,l.onevent&&(e=new L(L.NODE_CARETCHANGED,s,s.closed),l.onevent(e)),l.frefresh(s.id)});var u=document.createElement("div");if(d.appendChild(u),s.actions)for(let e=0;e<s.actions.length;++e){let t=s.actions[e],a=document.createElement("a");a.className="lexicon "+t.icon,a.title=t.name,a.addEventListener("click",function(e){t.callback(s,a),e.stopPropagation()}),u.appendChild(a)}if(s.skipVisibility||((n=document.createElement("a")).className="lexicon fa-solid fa-eye"+(s.visible?"":"-slash"),n.title="Toggle visible",n.addEventListener("click",function(e){e.stopPropagation(),s.visible=void 0!==s.visible&&!s.visible,this.className="lexicon fa-solid fa-eye"+(s.visible?"":"-slash"),l.onevent&&(e=new L(L.NODE_VISIBILITY,s,s.visible),l.onevent(e))}),u.appendChild(n)),null!=a&&s.id==a&&(this.selected=[s],d.click()),!s.closed)for(i=0;i<s.children.length;++i){var p=s.children[i];this.options.onlyFolders&&"folder"!=p.type||this._create_item(s,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<y.signals[a].length;e++)y.signals[a][e]==this.widgets[t]&&(y.signals[a]=[...y.signals[a].slice(0,e),...y.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],i=n.options.signal;for(let e=0;e<y.signals[i].length;e++)y.signals[i][e]==n&&(y.signals[i]=[...y.signals[i].slice(0,e),...y.signals[i].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,i){t=new CustomEvent(t,{detail:a,bubbles:n,cancelable:i});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={}){y.CREATED_INSTANCES||(y.CREATED_INSTANCES=[]),y.CREATED_INSTANCES[e]=!0;let i=new T(t,e,a,n);var s=document.createElement("div"),a=(s.className="lexwidget",s.id=n.id??"",s.title=n.title??"",n.className&&(s.className+=" "+n.className),e!=T.TITLE&&(s.style.width="calc(100% - "+(this._currentBranch||e==T.FILE||e==T.TREE?10:20)+"px)",n.width&&(s.style.width=s.style.minWidth=n.width),n.maxWidth&&(s.style.maxWidth=n.maxWidth),n.minWidth&&(s.style.minWidth=n.minWidth),n.height)&&(s.style.height=s.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||y.DEFAULT_NAME_WIDTH,s.appendChild(e),(s.domName=e).addEventListener("contextmenu",function(e){e.preventDefault(),i.oncontextmenu(e)}),n.skipReset)||null==a||k._add_reset_property(e,function(e){i.set(i._initialValue,!1,e),this.style.display="none"}),this.widgets[t]=i):n.hideName=!0,n.signal&&(t||(this.signals||(this.signals=[]),this.signals.push({[n.signal]:i})),y.addSignal(n.signal,i)),(i.domEl=s).jsInstance=i,e=>{(n.container||this.queuedContainer||(this._currentBranch?(n.skipWidget||this._currentBranch.widgets.push(i),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(s),this._inline_widgets_left--,this._inline_widgets_left||this.endLine()):a(s),i}_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 i,s=!t.length;for(i of a.widgets){if(!s){if(!i.name)continue;t.toLowerCase();if(!i.name.toLowerCase().includes(t))continue}this.queuedContainer.appendChild(i.domEl)}return void this.clearQueue()}}_filterOptions(t,a){var n=!a.length,i=[];for(let e=0;e<t.length;e++){var s=t[e];if(!n){var l="string"==typeof s?s:s.value,r=a.toLowerCase();if(!l.toLowerCase().includes(r))continue}i.push(s)}this.refresh(i)}_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,i,s,l={}){let r=this._createWidget(T.TEXT,n,String(i),l);r.onGetValue=()=>i,r.onSetValue=(e,t,a)=>{r.valid(e)&&this._lastValueTriggered!=e&&(this._lastValueTriggered=i=e,l.disabled?o.innerText=e:o.value=e,t||this._trigger(new w(n,e,a),s))},r.valid=e=>!e.length||""==o.pattern||new RegExp(o.pattern).test(e);var e,t=r.domEl,a=document.createElement("div");a.className="lextext"+(l.warning?" lexwarning":""),a.style.width=l.inputWidth||"calc( 100% - "+y.DEFAULT_NAME_WIDTH+" )",a.style.display="flex",l.textClass&&a.classList.add(l.textClass),this.disabled=(l.disabled||l.warning)??!!l.url;let o=null;return this.disabled?(o=document.createElement(l.url?"a":"div"),l.url&&(o.href=l.url,o.target="_blank"),o.innerHTML=(l.warning?'<i class="fa-solid fa-triangle-exclamation"></i>':"")+i||"",o.style.width="100%",o.style.textAlign=l.float??""):((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),"default"==(e=l.trigger??"default")?(o.addEventListener("keyup",function(e){"Enter"==e.key&&o.blur()}),o.addEventListener("focusout",function(e){r.set(e.target.value,!1,e)})):"input"==e&&o.addEventListener("input",function(e){r.set(e.target.value,!1,e)}),o.addEventListener("mousedown",function(e){e.stopImmediatePropagation(),e.stopPropagation()}),l.icon&&((e=document.createElement("a")).className="inputicon "+l.icon,a.appendChild(e))),Object.assign(o.style,l.style??{}),a.appendChild(o),t.appendChild(a),l.hideName&&(t.className+=" noname",a.style.width="100%"),r}addTextArea(n,i,s,e={}){let t=this._createWidget(T.TEXTAREA,n,i,e);t.onGetValue=()=>i,t.onSetValue=(e,t,a)=>{r.value=i=e,t||this._trigger(new w(n,e,a),s)};var a=t.domEl,l=document.createElement("div");l.className="lextextarea",l.style.width=e.inputWidth||"calc( 100% - "+y.DEFAULT_NAME_WIDTH+" )",l.style.height=e.height,l.style.display="flex";let r=document.createElement("textarea");r.value=r.iValue=i||"",r.style.width="100%",r.style.textAlign=e.float??"",Object.assign(r.style,e.style??{}),e.disabled&&r.setAttribute("disabled",!0),e.placeholder&&r.setAttribute("placeholder",e.placeholder);var o=e.trigger??"default",o=("default"==o?(r.addEventListener("keyup",function(e){"Enter"==e.key&&r.blur()}),r.addEventListener("focusout",function(e){t.set(e.target.value,!1,e)})):"input"==o&&r.addEventListener("input",function(e){t.set(e.target.value,!1,e)}),e.icon&&((o=document.createElement("a")).className="inputicon "+e.icon,l.appendChild(o)),l.appendChild(r),a.appendChild(l),!e.hideName);return o||(a.className+=" noname",l.style.width="100%"),m(()=>{e.fitHeight&&(r.style.height=r.scrollHeight+"px")},10),t}addLabel(e,t={}){return t.disabled=!0,this.addText(null,e,null,t)}addButton(t,a,n,i={}){var e=this._createWidget(T.BUTTON,t,null,i),e=(e.onGetValue=()=>s.innerText,e.onSetValue=(e,t,a)=>{s.innerHTML=i.icon?"<a class='"+i.icon+"'></a>":i.img?"<img src='"+i.img+"'>":"<span>"+(e||"")+"</span>"},e.domEl),s=document.createElement("button"),l=(s.title=i.title??"",s.className="lexbutton "+(i.buttonClass??""),i.selected&&s.classList.add("selected"),s.innerHTML=i.icon?"<a class='"+i.icon+"'></a>":i.img?"<img src='"+i.img+"'>":"<span>"+(a||"")+"</span>",s.style.width="calc( 100% - "+(i.nameWidth??y.DEFAULT_NAME_WIDTH)+")",i.disabled&&s.setAttribute("disabled",!0),s.addEventListener("click",e=>{i.selectable&&(i.parent&&i.parent.querySelectorAll(".lexbutton.selected").forEach(e=>{e!=s&&e.classList.remove("selected")}),s.classList.toggle("selected")),this._trigger(new w(t,a,e),n)}),e.appendChild(s),!i.hideName&&!(i.icon||i.img));return l||(s.className+=" noname",s.style.width="100%"),e}addComboButtons(a,e,n={}){var t=this._createWidget(T.BUTTONS,a,null,n),i=t.domEl;let s=this,l=document.createElement("div");l.className="lexcombobuttons ",n.float&&(l.className+=n.float),l.style.width="calc( 100% - "+y.DEFAULT_NAME_WIDTH+")";var r=document.createElement("div");r.className="lexcombobuttonsbox ";let o=!n.noSelection,d=o&&(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),o&&(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){o&&(d?this.classList.toggle("selected"):(l.querySelectorAll("button").forEach(e=>e.classList.remove("selected")),this.classList.add("selected"))),s._trigger(new w(a,t.value,e),t.callback)}),r.appendChild(c)}return!n.hideName||(i.className+=" noname",l.style.width="100%"),l.appendChild(r),i.appendChild(l),t}addCard(t,a={}){a.hideName=!0;var e=this._createWidget(T.CARD,t,null,a),n=e.domEl;let i=document.createElement("div");i.className="lexcard",i.style.width="100%",a.img&&((l=document.createElement("img")).src=a.img,i.appendChild(l),null!=a.link)&&(l.style.cursor="pointer",l.addEventListener("click",function(){var e=i.querySelector("a");e&&e.click()}));var s,l=document.createElement("span");return l.innerText=t,null!=a.link&&((s=document.createElement("a")).innerText=t,s.href=a.link,s.target=a.target??"",l.innerText="",l.appendChild(s)),i.appendChild(l),a.callback&&(i.style.cursor="pointer",i.addEventListener("click",e=>{this._trigger(new w(t,null,e),a.callback)})),n.appendChild(i),e}addForm(e,n,i,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,i,s=l.querySelectorAll(".lexwidget");for(let e=0;e<s.length;++e)s[e].jsInstance.type==y.Widget.TEXT&&(n=s[e].querySelector(".lexwidgetname").innerText,(i=s[e].querySelector(".lextext input")).value=t[n]??"",k._dispatch_event(i,"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;i&&i(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),i=e.domEl,s=document.createElement("div"),l=(s.className="leximage",s.style.width="100%",document.createElement("img"));for(n in l.src=t,a.style)l.style[n]=a.style[n];return await l.decode(),s.appendChild(l),i.appendChild(s),e}addDropdown(n,r,o,i,e={}){let d=this._createWidget(T.DROPDOWN,n,o,e),c=(d.onGetValue=()=>c.querySelector("li.selected").getAttribute("value"),d.onSetValue=(e,t,a)=>{o=e,m.querySelectorAll("li").forEach(e=>{e.getAttribute("value")==o&&e.click()}),t||this._trigger(new w(n,o,a),i)},d.domEl);var t=document.createElement("div");t.className="lexdropdown",t.style.width=e.inputWidth||"calc( 100% - "+y.DEFAULT_NAME_WIDTH+")";let h=document.createElement("div");h.className="lexdropdown lexoption",h.name=n;var a=h.iValue=o;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();let i=u.getBoundingClientRect();var s=a.parentElement.closest("dialog");{var l=a.offsetHeight;let t=i.y,e=window.innerHeight;if(n&&(r=n.getBoundingClientRect(),e=r.y+r.height),s){let e=s.getBoundingClientRect();t-=e.y}a.style.top=t+u.offsetHeight+"px",t+l>e&&(a.style.top=t-l+"px",a.classList.add("place-above"))}{var r=a.offsetWidth;let t=i.x;if(a.style.minWidth=i.width+"px",s){let e=s.getBoundingClientRect();t-=e.x}a.style.left=t+"px";let e=window.innerWidth;n&&(l=n.getBoundingClientRect(),e=l.x+l.width),t+r>e&&(a.style.left=t-(r-i.width)+"px")}})(p)),g&&g.querySelector("input").focus())},{buttonClass:"array",skipInlineCount:!0,disabled:e.disabled}),p=(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)},document.createElement("dialog")),m=(p.className="lexdropdownoptions",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),v=(e.filter&&(g=this._addFilter(e.placeholder??"Search...",{container:m,callback:this._filterOptions.bind(m,r)}),m.appendChild(g),g.addEventListener("focusout",function(e){e.relatedTarget&&"UL"==e.relatedTarget.tagName&&e.relatedTarget.classList.contains("lexoptions")||p.close()})),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,i=t[e],s=document.createElement("li"),l=document.createElement("div");l.className="option",s.appendChild(l),s.addEventListener("click",e=>{p.close();var t=c.querySelector(".lexoptions .selected");t&&t.classList.remove("selected"),o=e.currentTarget.getAttribute("value"),e.currentTarget.toggleAttribute("hidden",!1),e.currentTarget.classList.add("selected"),u.refresh(o),d.set(o,!1,e),g&&(g.querySelector("input").value="",this._filterOptions.bind(m,r,"")())}),i.constructor!=Object?(l.style.flexDirection="unset",l.innerHTML="</a><span>"+i+"</span><a class='fa-solid fa-check'>",l.value=i,s.setAttribute("value",i),s.className="lexdropdownitem",i==o&&(s.classList.add("selected"),h.innerHTML=i)):((n=document.createElement("img")).src=i.src,s.setAttribute("value",i.value),s.className="lexlistitem",l.innerText=i.value,l.className+=" media",l.prepend(n),l.setAttribute("value",i.value),l.setAttribute("data-index",e),l.setAttribute("data-src",i.src),l.setAttribute("title",i.value),o==i.value&&s.classList.add("selected")),v.appendChild(s)}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(r),t.appendChild(p),c.appendChild(t),e.hideName&&(c.className+=" noname",t.style.width="100%"),d}addCurve(n,e,i,t={}){var a=JSON.parse(JSON.stringify(e));let s=this;var a=this._createWidget(T.CURVE,n,a,t),l=(a.onGetValue=()=>JSON.parse(JSON.stringify(o.element.value)),a.onSetValue=(e,t,a)=>{o.element.value=JSON.parse(JSON.stringify(e)),o.redraw(),t||s._trigger(new w(n,o.element.value,a),i)},a.domEl),r=document.createElement("div");r.className="lexcurve",r.style.width="calc( 100% - "+y.DEFAULT_NAME_WIDTH+")",t.callback=(e,t)=>{s._trigger(new w(n,e,t),i)},t.name=n;let o=new D(this,e,t);return r.appendChild(o.element),l.appendChild(r),a.onresize=o.redraw.bind(o),a.curveInstance=o,m(()=>{o.canvas.width=r.offsetWidth,o.redraw()}),a}addDial(n,e,i,t={}){var a=JSON.parse(JSON.stringify(e));let s=this;var a=this._createWidget(T.DIAL,n,a,t),l=(a.onGetValue=()=>JSON.parse(JSON.stringify(o.element.value)),a.onSetValue=(e,t,a)=>{o.element.value=JSON.parse(JSON.stringify(e)),o.redraw(),t||s._trigger(new w(n,o.element.value,a),i)},a.domEl),r=document.createElement("div");r.className="lexcurve",r.style.width=a.name?"calc( 100% - "+y.DEFAULT_NAME_WIDTH+")":"100%",t.callback=(e,t)=>{s._trigger(new w(n,e,t),i)},t.name=n;let o=new M(this,e,t);return r.appendChild(o.element),l.appendChild(r),a.onresize=o.redraw.bind(o),a.curveInstance=o,m(()=>{o.element.style.height=o.element.offsetWidth+"px",o.canvas.width=o.element.offsetWidth,r.style.width=o.element.offsetWidth+"px",o.canvas.height=o.canvas.width,o.redraw()}),a}addLayers(n,s,i,e={}){let l=this,r=this._createWidget(T.LAYERS,n,s,e),o=(r.onGetValue=()=>o.value,r.onSetValue=(e,t,a)=>{s=o.value=e,c(),t||l._trigger(new w(n,s,a),i)},r.domEl);var d=document.createElement("div");d.className="lexlayers",d.style.width="calc( 100% - "+y.DEFAULT_NAME_WIDTH+")",o.value=s;let c=()=>{d.innerHTML="";let e=s.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,i=document.createElement("div");i.className="lexlayer",null!=s&&null!=(n=e[16-t-1])&&"1"==n&&i.classList.add("selected"),i.innerText=t+1,i.title="Bit "+t+", value "+(1<<t),d.appendChild(i),i.addEventListener("click",e=>{e.stopPropagation(),e.stopImmediatePropagation(),e.target.classList.toggle("selected"),s^=1<<t,r.set(s,!1,e)})}};return c(),o.appendChild(d),r}addArray(i,s=[],l,r={}){var e=this._createWidget(T.ARRAY,i,null,r);e.onGetValue=()=>{var e,t=[];for(e of a.querySelectorAll("input"))t.push(e.value);return t},e.onSetValue=(e,t,a)=>{s=e,h(),t||this._trigger(new w(i,s,a),l)};let a=e.domEl,o=(a.style.flexWrap="wrap","4%"),t=document.createElement("div"),n=(t.className="lexarray",t.style.width="calc( 100% - "+y.DEFAULT_NAME_WIDTH+")",this.queue(t),"<a class='fa-solid fa-angle-down' style='float:right; margin-right: 3px;'></a>"),d="Array (size "+s.length+")",c=(d+=n,this.addButton(null,d,()=>{a.querySelector(".lexarrayitems").toggleAttribute("hidden")},{buttonClass:"array"}),this.clearQueue(),document.createElement("div")),h=(c.className="lexarrayitems",c.toggleAttribute("hidden",!0),a.appendChild(t),a.appendChild(c),()=>{var e=a.querySelector(".lexbutton.array span");e.innerHTML="Array (size "+s.length+")",e.innerHTML+=n,c.innerHTML="",this.queue(c);for(let n=0;n<s.length;++n){let a=s[n];var t=r.innerValues?"dropdown":a.constructor;switch(this.sameLine(2),t){case String:this.addText(n+"",a,function(e,t){s[n]=e,l(s)},{nameWidth:o,inputWidth:"95%",skipReset:!0});break;case Number:this.addNumber(n+"",a,function(e,t){s[n]=e,l(s)},{nameWidth:o,inputWidth:"95%",skipReset:!0});break;case"dropdown":this.addDropdown(n+"",r.innerValues,a,function(e,t){s[n]=e,l(s)},{nameWidth:o,inputWidth:"95%",skipReset:!0})}this.addButton(null,"<a class='lexicon fa-solid fa-trash'></a>",(e,t)=>{s.splice(s.indexOf(a),1),h(),this._trigger(new w(i,s,t),l)},{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,(e,t)=>{s.push(r.innerValues?r.innerValues[0]:""),h(),this._trigger(new w(i,s,t),l)},{buttonClass:"array"}),this.clearQueue()});return h(),e}addList(i,s,l,r,e={}){var t=this._createWidget(T.LIST,i,l,e),a=(t.onGetValue=()=>l,t.onSetValue=(e,t,a)=>{o.querySelectorAll(".lexlistitem").forEach(e=>e.classList.remove("selected"));var n=s.indexOf(e);-1==n||(o.children[n].classList.toggle("selected"),l=e,t)||this._trigger(new w(i,e,a),r)},t.updateValues=e=>{s=e,o.innerHTML="";for(let n=0;n<s.length;++n){let e=null,t=s[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=>{o.querySelectorAll(".lexlistitem").forEach(e=>e.classList.remove("selected")),a.classList.toggle("selected"),l=t,this._trigger(new w(i,t,e),r)}),o.appendChild(a)}},t.domEl);let o=document.createElement("div");return o.className="lexlist",o.style.width="calc( 100% - "+y.DEFAULT_NAME_WIDTH+")",t.updateValues(s),e.hideName&&(a.className+=" noname",o.style.width="100%"),a.appendChild(o),t}addTags(n,i,s,e={}){i=i.replace(/\s/g,"").split(",");var t=[].concat(i);let l=this._createWidget(T.TAGS,n,t,e);l.onGetValue=()=>[].concat(i),l.onSetValue=(e,t,a)=>{i=[].concat(e),d(),t||r._trigger(new w(n,i,a),s)};t=l.domEl;let r=this,o=document.createElement("div"),d=(o.className="lextags",o.style.width="calc( 100% - "+y.DEFAULT_NAME_WIDTH+")",()=>{o.innerHTML="";for(let e=0;e<i.length;++e){let t=i[e],a=document.createElement("span");a.className="lextag",a.innerHTML=t;var n=document.createElement("a");n.className="lextagrmb fa-solid fa-xmark lexicon",a.appendChild(n),n.addEventListener("click",e=>{a.remove(),i.splice(i.indexOf(t),1),l.set(i,!1,e)}),o.appendChild(a)}var e=document.createElement("input");e.value="",e.placeholder="Add tag...",o.appendChild(e),e.onkeydown=function(e){var t=this.value.replace(/\s/g,"");" "!=e.key&&"Enter"!=e.key||(e.preventDefault(),!t.length)||-1<i.indexOf(t)||(i.push(t),l.set(i,!1,e))},e.focus()});return d(),e.hideName&&(t.className+=" noname",o.style.width="100%"),t.appendChild(o),l}addCheckbox(n,i,s,e={}){if(!n&&!e.label)throw"Set Widget Name or at least a label!";let t=this._createWidget(T.CHECKBOX,n,i,e),l=(t.onGetValue=()=>i,t.onSetValue=(e,t,a)=>{e==i||(r.checked=i=e,l.querySelector(".lexcheckboxsubmenu")?.toggleAttribute("hidden",!e),t)||this._trigger(new w(n,e,a),s)},t.domEl),a=document.createElement("div"),r=(a.className="lexcheckboxcont",document.createElement("input"));r.type="checkbox",r.className="lexcheckbox "+(e.className??""),r.checked=i,r.disabled=e.disabled??!1;var o=document.createElement("span");return o.className="checkboxtext",o.innerHTML=e.label??"On",a.appendChild(r),a.appendChild(o),r.addEventListener("change",e=>{t.set(r.checked,!1,e)}),l.appendChild(a),e.suboptions&&(l.style.flexWrap="wrap",(o=document.createElement("div")).className="lexcheckboxsubmenu",o.toggleAttribute("hidden",!r.checked),this.queue(o),e.suboptions.call(this,this),this.clearQueue(),l.appendChild(o)),t}addToggle(n,i,s,e={}){let t=this._createWidget(T.TOGGLE,n,i,e),l=(t.onGetValue=()=>r.checked,t.onSetValue=(e,t,a)=>{e==i||(r.checked=i=e,l.querySelector(".lextogglesubmenu")?.toggleAttribute("hidden",!e),t)||this._trigger(new w(n,e,a),s)},t.domEl),a=document.createElement("div"),r=(a.className="lextogglecont",document.createElement("input"));r.type="checkbox",r.className="lextoggle "+(e.className??""),r.checked=i,r.iValue=i,r.disabled=e.disabled??!1;var o=document.createElement("span");return o.className="toggletext",o.innerHTML="On",a.appendChild(r),a.appendChild(o),r.addEventListener("change",e=>{t.set(r.checked,!1,e)}),l.appendChild(a),e.suboptions&&(l.style.flexWrap="wrap",(o=document.createElement("div")).className="lextogglesubmenu",o.toggleAttribute("hidden",!r.checked),this.queue(o),e.suboptions.call(this,this),this.clearQueue(),l.appendChild(o)),t}addRadioGroup(e,t,i,s,a={}){let n=this._createWidget(T.RADIO,e,null,a),l=null;n.onGetValue=()=>{var e=r.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=r.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 w(null,[e,i[e]],a),s)};var e=n.domEl,r=document.createElement("div"),o=(r.className="lexradiogroup "+(a.className??""),document.createElement("span"));o.innerHTML=t,r.appendChild(o);let d=this;for(let t=0;t<i.length;++t){var c=document.createElement("div"),h=(c.className="lexradiogroupitem",r.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=i[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(r),n}addColor(n,i,s,e={}){i=i.constructor===Array?u(i):i;let t=this._createWidget(T.COLOR,n,i,e);t.onGetValue=()=>i,t.onSetValue=(e,t,a)=>{r.useRGB&&(e=h(e)),a&&o.set(e,!0,a),r.value=i=e,t||this._trigger(new w(n,e,a),s)};var a=t.domEl,l=document.createElement("span");l.className="lexcolor",l.style.width="calc( 100% - "+y.DEFAULT_NAME_WIDTH+")";let r=document.createElement("input"),o=(r.style.width="32px",r.type="color",r.className="colorinput",r.id="color"+b(),r.useRGB=e.useRGB??!1,r.value=r.iValue=i,e.disabled&&(r.disabled=!0),r.addEventListener("input",e=>{t.set(e.target.value,!1,e)},!1),l.appendChild(r),this.queue(l),this.addText(null,r.value,e=>{t.set(e)},{width:"calc( 100% - 32px )"}));return o.domEl.style.marginLeft="4px",this.clearQueue(),a.appendChild(l),t}addRange(n,i,s,l={}){let t=this._createWidget(T.RANGE,n,i,l);t.onGetValue=()=>i,t.onSetValue=(e,t,a)=>{isNaN(e)||(r.value=i=f(+e,+r.min,+r.max),t)||this._trigger(new w(n,l.left?+r.max-i+ +r.min:i,a),s)};var e=t.domEl,a=document.createElement("div");a.className="lexrange",a.style.width=l.inputWidth||"calc( 100% - "+y.DEFAULT_NAME_WIDTH+")";let r=document.createElement("input");return r.className="lexrangeslider "+(l.className??""),r.value=r.iValue=i,r.min=l.min,r.max=l.max,r.step=l.step??1,r.type="range",r.disabled=l.disabled??!1,l.left&&r.classList.add("left"),(l.fill??!0)||r.classList.add("no-fill"),r.addEventListener("input",e=>{t.set(e.target.valueAsNumber,!1,e)},{passive:!1}),r.addEventListener("mousedown",function(e){l.onPress&&l.onPress.bind(r)(e,r)},!1),r.addEventListener("mouseup",function(e){l.onRelease&&l.onRelease.bind(r)(e,r)},!1),t.setLimits=(e,t,a)=>{r.min=e??r.min,r.max=t??r.max,r.step=a??r.step,k._dispatch_event(r,"input",!0)},i.constructor==Number&&(i=f(i,+r.min,+r.max)),a.appendChild(r),e.appendChild(a),l.hideName&&(e.className+=" noname",a.style.width="100%"),t}addNumber(n,i,s,l={}){let r=this._createWidget(T.NUMBER,n,i,l);r.onGetValue=()=>i,r.onSetValue=(e,t,a)=>{isNaN(e)||(i=f(+e,+d.min,+d.max),d.value=i=E(i,l.precision),o.querySelector(".lexinputslider")&&(o.querySelector(".lexinputslider").value=i),l.units&&(d.unitSpan.style.left=v(i)+"px"),t)||this._trigger(new w(n,i,a),s)};var e,t=r.domEl,a=document.createElement("div");a.className="lexnumber",a.style.width=l.inputWidth||"calc( 100% - "+y.DEFAULT_NAME_WIDTH+")";let o=document.createElement("div"),d=(o.className="numberbox",document.createElement("input")),c=(d.id="number_"+b(),d.className="vecinput",d.min=l.min??-1e24,d.max=l.max??1e24,d.step=l.step??"any",d.type="number",i.constructor==Number&&(i=E(i=f(i,+d.min,+d.max),l.precision)),d.value=d.iValue=i,o.appendChild(d),l.units&&((e=document.createElement("span")).className="lexunit",e.innerText=l.units,e.style.left=v(d.value)+"px",d.unitSpan=e,o.appendChild(e)),document.createElement("a"));if(c.className="fa-solid fa-arrows-up-down drag-icon hidden",o.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=i,n.addEventListener("input",function(e){r.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),o.appendChild(n),r.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,r.set(i,!0)}}d.addEventListener("input",function(e){i=E(i=+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),i=+this.valueAsNumber-e*(0<t.deltaY?1:-1),r.set(i,!1,t)}},{passive:!1}),d.addEventListener("change",function(e){r.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),i=+d.valueAsNumber+e*a,r.set(i,!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(o),t.appendChild(a),l.hideName&&(t.className+=" noname",a.style.width="100%"),r}static VECTOR_COMPONENTS={0:"x",1:"y",2:"z",3:"w"};_add_vector(t,i,s,l,r={}){t=f(t,2,4),s=s??new Array(t).fill(0);let o=this._createWidget(T.VECTOR,i,[].concat(s),r),d=(o.onGetValue=()=>{var e,t=[];for(e of d.querySelectorAll("input"))t.push(+e.value);return t},o.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),r.precision)??0,c[e].value=t[e]=n}e||this._trigger(new w(i,t,a),l)}},o.domEl),c=[],n=document.createElement("div");n.className="lexvector",n.style.width="calc( 100% - "+y.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 i=document.createElement("input"),a=(i.className="vecinput v"+t,i.min=r.min??-1e24,i.max=r.max??1e24,i.step=r.step??"any",i.type="number",i.id="vec"+t+"_"+b(),i.idx=e,c[e]=i,s[e].constructor==Number&&(s[e]=f(s[e],+i.min,+i.max),s[e]=E(s[e],r.precision)),i.value=i.iValue=s[e],document.createElement("a"));a.className="fa-solid fa-arrows-up-down drag-icon hidden",h.appendChild(a),r.disabled&&(i.disabled=!0),i.addEventListener("wheel",function(t){if(t.preventDefault(),this===document.activeElement){let e=r.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),r.precision),k._dispatch_event(a,"change");else this.value=E(+this.valueAsNumber-e*(0<t.deltaY?1:-1),r.precision),k._dispatch_event(i,"change")}},{passive:!1}),i.addEventListener("change",e=>{if(!isNaN(e.target.value)){var t=E(f(e.target.value,+i.min,+i.max),r.precision);if(v.locked)for(var a of c)a.value=t,s[a.idx]=t;else i.value=t,s[e.target.idx]=t;o.set(s,!1,e)}},!1),i.addEventListener("mousedown",p);var u=this;function p(e){var t;document.activeElement!=i&&((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||i.requestPointerLock(),r.onPress)&&r.onPress.bind(i)(e,i)}function m(t){var a=-t.movementY;if(0!=a){let e=r.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,r.precision),k._dispatch_event(n,"change");else i.value=E(+i.valueAsNumber+e*a,r.precision),k._dispatch_event(i,"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(),r.onRelease&&r.onRelease.bind(i)(e,i)}h.appendChild(i),n.appendChild(h)}void 0===r.min&&void 0===r.max||(o.setLimits=(e,t,a)=>{for(var n of c)n.min=e??n.min,n.max=t??n.max,n.step=a??n.step;o.set(s,!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),o}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,s,a={}){let l=this._createWidget(T.SIZE,e,t,a),r=(l.onGetValue=()=>{var t=[];for(let e=0;e<r.dimensions.length;++e)t.push(r.dimensions[e].value());return t},l.onSetValue=(t,a,e)=>{for(let e=0;e<r.dimensions.length;++e)r.dimensions[e].set(t[e],a)},l.domEl);this.queue(r),r.aspectRatio=2==t.length?t[0]/t[1]:null,r.dimensions=[];for(let i=0;i<t.length;++i){var n;r.dimensions[i]=this.addNumber(null,t[i],e=>{var t,a,n=l.value();r.locked&&(t=0==i?1/r.aspectRatio:r.aspectRatio,n[a=(1+i)%2]=e*t,r.dimensions[a].set(n[a],!0)),s&&s(n)},{min:0,disabled:a.disabled,precision:a.precision}),i+1!=t.length&&((n=document.createElement("a")).className="lexsizecross fa-solid fa-xmark",r.appendChild(n))}this.clearQueue(),a.units&&((e=document.createElement("span")).className="lexunit",e.innerText=a.units,r.appendChild(e)),r.aspectRatio&&((e=document.createElement("a")).title="Lock Aspect Ratio",e.className="fa-solid fa-lock-open lexicon lock",r.appendChild(e),e.addEventListener("click",function(e){var t;r.locked=!r.locked,r.locked?(this.classList.add("fa-lock"),this.classList.remove("fa-lock-open"),t=l.value(),r.aspectRatio=t[0]/t[1]):(this.classList.add("fa-lock-open"),this.classList.remove("fa-lock"))},!1));e=!a.hideName;return e||(r.className+=" noname",container.style.width="100%"),l}addPad(i,e,s,a={}){var t=this._createWidget(T.PAD,i,null,a),n=(t.onGetValue=()=>o.value.xy,t.onSetValue=(e,t,a)=>{o.value.set(e[0],e[1]),d(o.value),t||this._trigger(new w(i,o.value.xy),s)},t.domEl),l=document.createElement("div");l.className="lexpad",l.style.width="calc( 100% - "+y.DEFAULT_NAME_WIDTH+")";let r=document.createElement("div"),o=(r.id="lexpad-"+i,r.className="lexinnerpad",r.style.width=a.padSize??"96px",r.style.height=a.padSize??"96px",document.createElement("div")),d=(o.className="lexpadthumb",o.value=new y.vec2(e[0],e[1]),o.min=a.min??0,o.max=a.max??1,e=>{var[t,a]=[r.offsetWidth,r.offsetHeight],e=new y.vec2(p(e.x,o.min,o.max,0,1),p(e.y,o.min,o.max,0,1));o.style.transform=`translate(calc( ${t*e.x}px - 50% ), calc( ${a*e.y}px - 50%)`}),c=(m(()=>{d(o.value)}),r.appendChild(o),l.appendChild(r),n.appendChild(l),r.addEventListener("mousedown",function(e){var t;document.activeElement!=o&&((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(o)(e,o)}),this);function h(e){var t=r.getBoundingClientRect(),t=new y.vec2(e.x-t.x,e.y-t.y),[a,n]=(t.clp(0,r.offsetWidth,t),[r.offsetWidth,r.offsetHeight]),t=t.div(new y.vec2(r.offsetWidth,r.offsetHeight));o.style.transform=`translate(calc( ${a*t.x}px - 50% ), calc( ${n*t.y}px - 50%)`,o.value=new y.vec2(p(t.x,0,1,o.min,o.max),p(t.y,0,1,o.min,o.max)),c._trigger(new w(i,o.value.xy,e),s),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(o)(e,o)}return t}addProgress(n,e,i={}){var t,a=this._createWidget(T.PROGRESS,n,e,i);a.onGetValue=()=>r.value,a.onSetValue=(e,t,a)=>{s.querySelector("meter").value=e,o(),s.querySelector("span")&&(s.querySelector("span").innerText=e)};let s=a.domEl,l=document.createElement("div"),r=(l.className="lexprogress",l.style.width="calc( 100% - "+y.DEFAULT_NAME_WIDTH+")",document.createElement("meter")),o=(r.id="lexprogressbar-"+n,r.className="lexprogressbar",r.step="any",r.min=i.min??0,r.max=i.max??1,r.low=i.low??r.low,r.high=i.high??r.high,r.optimum=i.optimum??r.optimum,r.value=e,()=>{let e=y.getThemeColor("global-selected");null!=r.low&&r.value<r.low?e=y.getThemeColor("global-color-error"):null!=r.high&&r.value<r.high&&(e=y.getThemeColor("global-color-warning")),r.style.background=`color-mix(in srgb, ${e} 20%, transparent)`});if(l.appendChild(r),s.appendChild(l),i.showValue&&(document.getElementById("progressvalue-"+n)&&document.getElementById("progressvalue-"+n).remove(),(t=document.createElement("span")).id="progressvalue-"+n,t.style.padding="0px 5px",t.innerText=e,l.appendChild(t)),i.editable){r.classList.add("editable"),r.addEventListener("mousedown",function(e){var t=a.root.ownerDocument;t.addEventListener("mousemove",d),t.addEventListener("mouseup",c),document.body.classList.add("noevents"),r.classList.add("grabbing"),e.stopImmediatePropagation(),e.stopPropagation();t=r.getBoundingClientRect(),e=E(p(e.offsetX,0,t.width,r.min,r.max));a.setValue(n,e)});let a=this;function d(e){var t;0!=e.movementX&&(t=r.getBoundingClientRect(),t=E(p(e.offsetX-t.x,0,t.width,r.min,r.max)),a.setValue(n,t),i.callback)&&i.callback(t,e),e.stopPropagation(),e.preventDefault()}function c(e){var t=a.root.ownerDocument;t.removeEventListener("mousemove",d),t.removeEventListener("mouseup",c),document.body.classList.remove("noevents"),r.classList.remove("grabbing")}}return o(),a}addFile(e,a,n={}){var e=this._createWidget(T.FILE,e,null,n),t=e.domEl,i=n.local??!0;let s=n.type??"text",l=n.read??!0,r=document.createElement("input");if(r.className="lexfileinput",r.style.width="calc( 100% - "+y.DEFAULT_NAME_WIDTH+" - 10%)",r.type="file",r.disabled=n.disabled??!1,n.placeholder&&(r.placeholder=n.placeholder),r.addEventListener("change",function(e){let t=e.target.files;t.length&&(l?(n.onBeforeRead&&n.onBeforeRead(),e=new FileReader,"text"===s?e.readAsText(t[0]):"buffer"===s?e.readAsArrayBuffer(t[0]):"bin"===s?e.readAsBinaryString(t[0]):"url"===s&&e.readAsDataURL(t[0]),e.onload=e=>{a.call(this,e.target.result,t[0])}):a(t[0]))}),r.addEventListener("cancel",function(e){a(null)}),t.appendChild(r),this.queue(t),i){let t=null;this.addButton(null,"<a style='margin-top: 0px;' class='fa-solid fa-gear'></a>",()=>{t=t||new A("Load Settings",e=>{e.addDropdown("Type",["text","buffer","bin","url"],s,e=>{s=e}),e.addButton(null,"Reload",e=>{r.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,i=document.createElement("div"),s=(i.className="lextree",n.appendChild(i),e&&((n=document.createElement("span")).innerHTML=e,i.appendChild(n)),document.createElement("div"));if(s.className="lextreetools",e||(s.className+=" notitle"),a.icons)for(var l of a.icons){var r=document.createElement("a");r.title=l.name,r.className="lexicon "+l.icon,r.addEventListener("click",l.callback),s.appendChild(r)}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(){o.refresh()}),(e=document.createElement("a")).className="lexicon fa-solid fa-magnifying-glass",s.appendChild(n),s.appendChild(e)),(a.icons||a.filter)&&i.appendChild(s),n=document.createElement("ul");n.addEventListener("contextmenu",function(e){e.preventDefault()}),i.appendChild(n);let o=new N(i,t,a);return o}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(i,e={}){var t=this._createWidget(T.TABS,null,null,e).domEl;if(i.constructor!=Array)throw"Param @tabs must be an Array!";var a=e.vertical??!0,s=!a&&(e.showNames??!1);let l=document.createElement("div"),r=(l.className="lextabscontainer",a||(l.className+=" horizontal"),document.createElement("div"));r.className="tabs",l.appendChild(r),t.appendChild(l);for(let e=0;e<i.length;++e){let t=i[e];console.assert(t.name);var o=0==e;let a=document.createElement("div"),n=(a.className="lextab "+(e==i.length-1?"last":"")+(o?"selected":""),a.innerHTML=(s?t.name:"")+"<a class='"+(t.icon||"fa fa-hashtag")+" "+(s?"withname":"")+"'></a>",a.title=t.name,document.createElement("div"));n.id=t.name.replace(/\s/g,""),n.className="widgets",o||n.toggleAttribute("hidden",!0),l.appendChild(n),a.addEventListener("click",e=>{r.querySelectorAll(".lextab").forEach(e=>{e.classList.remove("selected")}),a.classList.add("selected"),l.querySelectorAll(".widgets").forEach(e=>{e.toggleAttribute("hidden",!0)}),l.querySelector("#"+n.id).toggleAttribute("hidden"),t.onSelect&&t.onSelect(this,n)}),r.appendChild(a),t.onCreate&&(this.queue(n),t.onCreate(this,n),this.clearQueue())}this.addSeparator()}addCounter(n,e,i,t={}){let s=this._createWidget(T.COUNTER,n,e,t);s.onGetValue=()=>c.count,s.onSetValue=(e,t,a)=>{e=f(e,l,r),c.count=e,c.innerHTML=e,t||this._trigger(new w(n,e,a),i)};var a=s.domEl;let l=t.min??0,r=t.max??100,o=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=o??1;t.shiftKey&&(a*=10),s.set(c.count-a,!1,t)},{className:"micro",skipInlineCount:!0,title:"Minus"}),this.clearQueue(),document.createElement("div"));a.className="lexcounterbox",d.appendChild(a);let 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=o??1;t.shiftKey&&(a*=10),s.set(c.count+a,!1,t)},{className:"micro",skipInlineCount:!0,title:"Plus"}),this.clearQueue(),s}addTable(e,m,g={}){if(!m)throw"Data is needed to create a table!";let v=this._createWidget(T.TABLE,e,null,g);v.onGetValue=()=>{},v.onSetValue=(e,t,a)=>{};var e=v.domEl,t=document.createElement("div");t.className="lextable",t.style.width="calc( 100% - "+y.DEFAULT_NAME_WIDTH+")";let f=document.createElement("table");function E(e,t,a,n){return a[e]<n[e]?-t:a[e]>n[e]?t:0}return t.appendChild(f),m.head=m.head??[],m.body=m.body??[],m.orderMap={},m.checkMap={},v.refreshTable=()=>{f.innerHTML="";var e,t,a=document.createElement("thead"),n=(a.className="lextablehead",f.appendChild(a),document.createElement("tr"));g.selectable&&(e=document.createElement("th"),(t=document.createElement("input")).type="checkbox",t.className="lexcheckbox",t.checked=m.checkMap[":root"]??!1,e.appendChild(t),t.addEventListener("change",function(){var e;m.checkMap[":root"]=this.checked;for(e of f.querySelector("tbody").childNodes)m.checkMap[e.getAttribute("rowId")]=this.checked,e.querySelector("input").checked=this.checked}),n.appendChild(e));for(let t of m.head){var i=document.createElement("th");i.innerHTML=t+' <a class="fa-solid fa-sort"></a>',i.querySelector("a").addEventListener("click",()=>{m.orderMap[t]||(m.orderMap[t]=1);var e=m.head.indexOf(t);m.body=m.body.sort(E.bind(this,e,m.orderMap[t])),m.orderMap[t]=-m.orderMap[t],v.refreshTable()}),n.appendChild(i)}g.rowActions&&((t=document.createElement("th")).className="sm",n.appendChild(t)),a.appendChild(n);var s=document.createElement("tbody");s.className="lextablebody",f.appendChild(s);for(let a=0;a<m.body.length;++a){var l,r,o=m.body[a];let e=document.createElement("tr"),t=y.getSupportedDOMName(o.join("-"));e.setAttribute("rowId",t),g.selectable&&(l=document.createElement("td"),(h=document.createElement("input")).type="checkbox",h.className="lexcheckbox",h.checked=m.checkMap[t],l.appendChild(h),h.addEventListener("change",function(){m.checkMap[t]=this.checked,this.checked||(f.querySelector("thead input[type='checkbox']").checked=m.checkMap[":root"]=!1)}),e.appendChild(l));for(r of o){var d=document.createElement("td");d.innerHTML=""+r,e.appendChild(d)}if(g.rowActions){var c,h=document.createElement("td"),u=(h.className="sm",document.createElement("div"));u.className="lextablebuttons",h.appendChild(u);for(c of g.rowActions){var p=document.createElement("a");p.className="lexicon","delete"==c?(p.className+=" fa-solid fa-trash-can",p.addEventListener("click",function(){m.body.splice(a,1),e.remove()})):"menu"==c?(p.className+=" fa-solid fa-ellipsis",p.addEventListener("click",function(e){S(null,e,e=>{g.onMenuAction?g.onMenuAction(e):console.warn("Using <Menu action> without action callbacks.")})})):(console.assert(c.constructor==Object),p.className+=" "+c.icon),u.appendChild(p)}e.appendChild(h)}s.appendChild(e)}},v.refreshTable(),g.hideName&&(e.className+=" noname",t.style.width="100%"),e.appendChild(t),v}}y.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),i=(this.root=a,this.widgets=[],document.createElement("div")),s=(i.className="lexbranchtitle",t.icon&&(i.innerHTML="<a class='branchicon "+t.icon+"'>"),i.innerHTML+=e||"Branch",i.innerHTML+="<a class='fa-solid fa-angle-up switch-branch-button'></a>",a.appendChild(i),document.createElement("div"));s.id=e.replace(/\s/g,""),s.className="lexbranchcontent",a.appendChild(s),this.content=s,this._addBranchSeparator(),t.closed&&(i.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"),y.emit("@on_branch_closed",this.classList.contains("closed"),{target:n.panel})},this.oncontextmenu=function(t){t.preventDefault(),t.stopPropagation(),this.parentElement.classList.contains("dialog")||S("Dock",t,e=>{t.preventDefault(),e.add("Floating",n._on_make_floating.bind(n))},{icon:"fa-regular fa-window-restore"})},i.addEventListener("click",this.onclick),i.addEventListener("contextmenu",this.oncontextmenu)}_on_make_floating(){new A(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";let a=document.createElement("div"),n=(a.innerHTML="▾",e.appendChild(a),m(()=>{a.style.marginLeft=parseFloat(y.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=i.root.ownerDocument;t.addEventListener("mouseup",l),t.addEventListener("mousemove",s),e.stopPropagation(),e.preventDefault();t=i.root.offsetHeight-i.root.children[0].offsetHeight;n.style.height=t-3+"px",document.body.classList.add("nocursor")}),this.grabber=a;let i=this;function s(e){var t,e=e.movementX;0!=e&&(t=parseFloat(a.style.marginLeft),a.style.marginLeft=f(t+e,32,i.content.offsetWidth-32)+"px")}function l(e){i._updateWidgets(),n.style.height="0px";var t=i.root.ownerDocument;t.removeEventListener("mouseup",l),t.removeEventListener("mousemove",s),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 i=n.children[0],n=n.children[1];i.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()}}}}y.Branch=a;y.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,i=document.createElement("div");i.className="columns",i.style.gridTemplateColumns="1fr ".repeat(e.columns.length),a.appendChild(i);for(n of e.columns){var s=document.createElement("div"),l=(s.className="col",i.appendChild(s),document.createElement("h2"));if(l.innerHTML=n.title,s.appendChild(l),n.items&&n.items.length){var r,o=document.createElement("ul");s.appendChild(o);for(r of n.items){var d=document.createElement("li");d.innerHTML=`<a class="" href="${r.link}">${r.title}</a>`,o.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 A{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=b();let a=t.size??[],n=t.position??[],i=t.draggable??!0,s=t.modal??!1;var r=document.createElement("dialog");r.className="lexdialog "+(t.className??""),r.id=t.id??"dialog"+A._last_id++,y.root.appendChild(r),m(()=>{s?r.showModal():r.show()},10);let o=this,d=document.createElement("div"),c;l&&(d.className="lexdialogtitle",d.innerHTML=l,d.setAttribute("draggable",!1),d.oncontextmenu=function(s){s.preventDefault(),s.stopPropagation(),y.main_area&&"horizontal"===y.main_area.type&&S("Dock",s,e=>{s.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 o.widgets)t.content.appendChild(a.domEl);t.widgets=o.widgets,e.root.querySelectorAll(".lexbranch.last").forEach(e=>{e.classList.remove("last")}),t.root.classList.add("last"),r.remove()}let a=n(y.main_area.sections[1]),i=(e.add('<i class="fa-regular fa-window-maximize fa-window-maximize fa-rotate-90">',{disabled:!a,id:"dock_options0",callback:()=>{t(a)}}),n(y.main_area.sections[0]));e.add('<i class="fa-regular fa-window-maximize fa-window-maximize fa-rotate-270">',{disabled:!i,id:"dock_options1",callback:()=>{t(i)}})},{icon:"fa-regular fa-window-restore"})},r.appendChild(d)),(t.closable??!0)&&(this.close=()=>{t.onBeforeClose&&t.onBeforeClose(this),t.onclose?t.onclose(this.root):(r.close(),m(()=>{o.panel.clear(),r.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"),r)).appendChild(c));var h=new k;h.root.classList.add("lexdialogcontent"),l||h.root.classList.add("notitle"),e&&e.call(this,h),r.appendChild(h.root),h.root.querySelectorAll(".lexbranch").forEach(e=>e.classList.add("dialog")),this.panel=h,this.root=r,this.title=d,i&&x(r,Object.assign({targetClass:"lexdialogtitle"},t)),a.length&&"string"!=typeof a[0]&&(a[0]+="px"),a.length&&"string"!=typeof a[1]&&(a[1]+="px"),r.style.width=a[0]||"25%",r.style.height=a[1]||"auto",r.style.translate=t.position?"unset":"-50% -50%",t.size&&(this.size=a),r.style.left=n[0]??"50%",r.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)}}y.Dialog=A;class r extends A{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(y.addSignal("@on_branch_closed",this.panel,e=>{this.dock_pos==r.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=r.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==r.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 i=a.float;if(i)for(var s=0;s<i.length;s++)switch(i[s]){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=r.TOP):"ArrowDown"==e.key&&(n.root.style.top="calc(100% - "+(n.root.offsetHeight+3)+"px)",n.dock_pos=r.BOTTOM))})}}}y.PocketDialog=r;class s{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 i=document.createElement("div");i.className="lexcontextmenu",a.appendChild(i);for(var s=0;s<e[t].length;++s){var l=e[t][s],r=Object.keys(l)[0];this._createEntry(l,r,i,n)}var o=a.getBoundingClientRect();i.style.left=o.width+"px",i.style.marginTop=3.5-a.offsetHeight+"px",this._adjustPosition(i,6,!0)}_createEntry(t,a,e,n){let i=t[a].length,s=document.createElement("div");s.className="lexmenuboxentry"+(t.className?" "+t.className:""),s.id=t.id??"eId"+c(a),s.innerHTML="";var l=t.icon;l&&(s.innerHTML+="<a class='"+l+" fa-sm'></a>");let r=t.disabled;s.innerHTML+="<div class='lexentryname"+(r?" disabled":"")+"'>"+a+"</div>",e.appendChild(s),this.colors[a]&&(s.style.borderColor=this.colors[a]),""==a?s.className+=" cmseparator":(s.addEventListener("click",e=>{e.stopPropagation(),e.stopImmediatePropagation(),r||((e=t.callback)&&(e.call(this,a,s),this.root.remove()),i&&"click"==y.OPEN_CONTEXTMENU_ENTRY&&this._createSubmenu(t,a,s,++n))}),i&&((l=document.createElement("a")).className="fa-solid fa-bars-staggered fa-xs",s.appendChild(l),"mouseover"==y.OPEN_CONTEXTMENU_ENTRY&&s.addEventListener("mouseover",e=>{s.built||(s.built=!0,this._createSubmenu(t,a,s,++n),e.stopPropagation())}),s.addEventListener("mouseleave",()=>{n=-1,e.querySelectorAll(".lexcontextmenu").forEach(e=>e.remove())})))}onCreate(){m(()=>this._adjustPosition(this.root,6))}add(e,s={}){s.constructor==Function&&(s={callback:s});let l=(e+="").split("/");var t,a,e=l[l.length-1];this.colors[e]=s.color;let r=0,o=(n,e)=>{if(null!=n){let a=null;var t,i;e.forEach(e=>{var t=Object.keys(e).find(e=>e==n);t&&(a=e[t])}),a?o(l[r++],a):((t={})[n]=[],(i=l[r++])||(t.id=s.id,t.callback=s.callback,t.disabled=s.disabled??!1),e.push(t),o(i,t[n]))}},d=(o(l[r++],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 i=Object.keys(a)[0],s=0;s<a[i].length;++s)d(a)}});for(t of this.items)d(t);for(a of this.items){var n=Object.keys(a)[0],i="eId"+c(n),i="#"+(a.id??i);this.root.querySelector(i)||this._createEntry(a,n,this.root,-1)}}setColor(e,t){"#"!==t[0]&&(t=u(t)),this.colors[e]=t}}function S(e,t,a,n){t=new s(t,e,n);return y.root.appendChild(t.root),a&&a(t),t.onCreate(),t}y.ContextMenu=s,y.addContextMenu=S;class D{constructor(e,t,a={}){let r=document.createElement("div"),o=(r.className="curve "+(a.className||""),r.style.minHeight="50px",r.style.width=a.width||"100%",r.style.minWidth="50px",r.style.minHeight="20px",r.bgcolor=a.bgColor||y.getThemeColor("global-intense-background"),r.pointscolor=a.pointsColor||y.getThemeColor("global-selected-light"),r.linecolor=a.lineColor||"#555",r.value=t||[],r.xrange=a.xrange||[0,1],r.yrange=a.yrange||[0,1],r.defaulty=null!=a.defaulty?a.defaulty:0,r.no_overlap=a.noOverlap||!1,r.show_samples=a.showSamples||0,r.allow_add_values=a.allowAddValues??!0,r.draggable_x=a.draggableX??!0,r.draggable_y=a.draggableY??!0,r.smooth=(a.smooth&&"number"==typeof a.smooth?a.smooth:.3)||!1,r.move_out=a.moveOutAction??y.CURVE_MOVEOUT_DELETE,y.addSignal("@on_new_color_scheme",(e,t)=>{r.bgcolor=a.bgColor||y.getThemeColor("global-intense-background"),r.pointscolor=a.pointsColor||y.getThemeColor("global-selected-light"),this.redraw()}),this.element=r,document.createElement("canvas"));function l(e){return[o.width*(e[0]-r.xrange[0])/r.xrange[1],o.height*(e[1]-r.yrange[0])/r.yrange[1]]}function d(e){return[e[0]*r.xrange[1]/o.width+r.xrange[0],e[1]*r.yrange[1]/o.height+r.yrange[0]]}o.width=a.width||200,o.height=a.height||50,r.appendChild(o),this.canvas=o,r.addEventListener("mousedown",function(e){document.addEventListener("mousemove",i),document.addEventListener("mouseup",u);var t=o.getBoundingClientRect(),a=e.clientX-t.left,t=e.clientY-t.top;{var n;c=((e,t)=>{for(var a=1e5,n=-1,i=0;i<r.value.length;i++){var s=l(r.value[i]),s=m([e,t],s);s<a&&s<8&&(a=s,n=i)}return n})(a,o.height-t),e.button==y.MOUSE_LEFT_CLICK&&-1==c&&r.allow_add_values&&(n=d([a,o.height-t]),r.value.push(n),g(),c=r.value.indexOf(n))}h=[a,t],r.redraw(),e.preventDefault(),e.stopPropagation()}),r.getValueAt=function(e){if(e<r.xrange[0]||e>r.xrange[1])return r.defaulty;for(var t=[r.xrange[0],r.defaulty],a=0,n=0;n<r.value.length;n+=1){var i=r.value[n];if(e==i[0])return i[1];if(e<i[0])return a=(e-t[0])/(i[0]-t[0]),t[1]*(1-a)+i[1]*a;t=i}return i=[r.xrange[1],r.defaulty],a=(e-t[0])/(i[0]-t[0]),t[1]*(1-a)+i[1]*a},r.resample=function(e){for(var t=[],a=(r.xrange[1]-r.xrange[0])/e,n=r.xrange[0];n<=r.xrange[1];n+=a)t.push(r.getValueAt(n));return t},r.addValue=function(e){for(var t=0;t<r.value;t++){var a=r.value[t];if(!(a[0]<e[0]))return r.value.splice(t,0,e),void redraw()}r.value.push(e),redraw()};var c=-1,h=(r.redraw=function(e={}){e.value&&(r.value=e.value),e.xrange&&(r.xrange=e.xrange),e.yrange&&(r.yrange=e.yrange),e.smooth&&(r.smooth=e.smooth);var e=o.parentElement.getBoundingClientRect(),t=((e=o.parentElement.parentElement?o.parentElement.parentElement.getBoundingClientRect():e)&&o.width!=e.width&&e.width&&e.width<1e3&&(o.width=e.width),o.getContext("2d")),a=(t.setTransform(1,0,0,1,0,0),t.translate(0,o.height),t.scale(1,-1),t.fillStyle=r.bgcolor,t.fillRect(0,0,o.width,o.height),t.strokeStyle=r.linecolor,t.beginPath(),l([r.xrange[0],r.defaulty])),n=(t.moveTo(a[0],a[1]),[a[0],a[1]]);for(i in r.value){a=l(r.value[i]);n.push(a[0]),n.push(a[1]),r.smooth||t.lineTo(a[0],a[1])}a=l([r.xrange[1],r.defaulty]),n.push(a[0]),n.push(a[1]),r.smooth?y.UTILS.drawSpline(t,n,r.smooth):(t.lineTo(a[0],a[1]),t.stroke());for(var i=0;i<r.value.length;i+=1)a=l(r.value[i]),t.fillStyle=c==i?"white":r.pointscolor,t.beginPath(),t.arc(a[0],a[1],c==i?4:3,0,2*Math.PI),t.fill();if(r.show_samples){var s=r.resample(r.show_samples);t.fillStyle="#888";for(i=0;i<s.length;i+=1)a=l([i*((r.xrange[1]-r.xrange[0])/r.show_samples)+r.xrange[0],s[i]]),t.beginPath(),t.arc(a[0],a[1],2,0,2*Math.PI),t.fill()}},[0,0]);function i(e){var t,a,n,i=o.getBoundingClientRect(),s=e.clientX-i.left,l=e.clientY-i.top,i=(s<0?s=0:s>o.width&&(s=o.width),l<0?l=0:l>o.height&&(l=o.height),[e.clientX-i.left,e.clientY-i.top]);-1!=c&&m(i,[s,l])>.5*o.height?(r.move_out==y.CURVE_MOVEOUT_DELETE?r.value.splice(c,1):(i=[i[0]-s,i[1]-l],(t=r.value[c])[0]=0==i[0]?t[0]:i[0]<0?r.xrange[0]:r.xrange[1],t[1]=0==i[1]?t[1]:i[1]<0?r.yrange[1]:r.yrange[0]),u(e)):(t=d([-(r.draggable_x?h[0]-s:0),r.draggable_y?h[1]-l:0]),-1!=c&&(i=r.xrange[0],a=r.xrange[1],r.no_overlap&&(0<c&&(i=r.value[c-1][0]),c<r.value.length-1)&&(a=r.value[c+1][0]),(n=r.value[c])[0]+=t[0],n[1]+=t[1],n[0]<i?n[0]=i:n[0]>a&&(n[0]=a),n[1]<r.yrange[0]?n[1]=r.yrange[0]:n[1]>r.yrange[1]&&(n[1]=r.yrange[1])),g(),r.redraw(),h[0]=s,h[1]=l,p(e),e.preventDefault(),e.stopPropagation())}function u(e){c=-1,r.redraw(),document.removeEventListener("mousemove",i),document.removeEventListener("mouseup",u),p(e),e.preventDefault(),e.stopPropagation()}function p(e){a.callback&&a.callback.call(r,r.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=r.value[c]),r.value.sort(function(e,t){return e[0]-t[0]}),e&&(c=r.value.indexOf(e))}return r.redraw(),this}redraw(e={}){this.element.redraw(e)}}y.Curve=D;class M{constructor(e,t,a={}){let r=document.createElement("div"),o=(r.className="dial "+(a.className||""),r.style.width=r.style.height=a.size||"100%",r.style.minWidth=r.style.minHeight="50px",r.bgcolor=a.bgColor||y.getThemeColor("global-dark-background"),r.pointscolor=a.pointsColor||y.getThemeColor("global-selected-light"),r.linecolor=a.lineColor||"#555",r.value=t||[],r.xrange=a.xrange||[0,1],r.yrange=a.yrange||[0,1],r.defaulty=null!=a.defaulty?a.defaulty:0,r.no_overlap=a.noOverlap||!1,r.show_samples=a.showSamples||0,r.allow_add_values=a.allowAddValues??!0,r.draggable_x=a.draggableX??!0,r.draggable_y=a.draggableY??!0,r.smooth=(a.smooth&&"number"==typeof a.smooth?a.smooth:.3)||!1,r.move_out=a.moveOutAction??y.CURVE_MOVEOUT_DELETE,this.element=r,document.createElement("canvas"));function l(e){return Math.pow(e[0],2),[o.width*(e[0]-r.xrange[0])/r.xrange[1],o.height*(e[1]-r.yrange[0])/r.yrange[1]]}function d(e){return[e[0]*r.xrange[1]/o.width+r.xrange[0],e[1]*r.yrange[1]/o.height+r.yrange[0]]}o.width=o.height=a.size||200,r.appendChild(o),this.canvas=o,r.addEventListener("mousedown",function(e){document.addEventListener("mousemove",i),document.addEventListener("mouseup",u);var t=o.getBoundingClientRect(),a=e.clientX-t.left,t=e.clientY-t.top;{var n;c=((e,t)=>{for(var a=1e5,n=-1,i=0;i<r.value.length;i++){var s=l(r.value[i]),s=m([e,t],s);s<a&&s<8&&(a=s,n=i)}return n})(a,o.height-t),e.button==y.MOUSE_LEFT_CLICK&&-1==c&&r.allow_add_values&&(n=d([a,o.height-t]),r.value.push(n),g(),c=r.value.indexOf(n))}h=[a,t],r.redraw(),e.preventDefault(),e.stopPropagation()}),r.getValueAt=function(e){if(e<r.xrange[0]||e>r.xrange[1])return r.defaulty;for(var t=[r.xrange[0],r.defaulty],a=0,n=0;n<r.value.length;n+=1){var i=r.value[n];if(e==i[0])return i[1];if(e<i[0])return a=(e-t[0])/(i[0]-t[0]),t[1]*(1-a)+i[1]*a;t=i}return i=[r.xrange[1],r.defaulty],a=(e-t[0])/(i[0]-t[0]),t[1]*(1-a)+i[1]*a},r.resample=function(e){for(var t=[],a=(r.xrange[1]-r.xrange[0])/e,n=r.xrange[0];n<=r.xrange[1];n+=a)t.push(r.getValueAt(n));return t},r.addValue=function(e){for(var t=0;t<r.value;t++){var a=r.value[t];if(!(a[0]<e[0]))return r.value.splice(t,0,e),void redraw()}r.value.push(e),redraw()};var c=-1,h=(r.redraw=function(e={}){e.value&&(r.value=e.value),e.xrange&&(r.xrange=e.xrange),e.yrange&&(r.yrange=e.yrange),e.smooth&&(r.smooth=e.smooth);var e=o.parentElement.getBoundingClientRect(),t=((e=o.parentElement.parentElement?o.parentElement.parentElement.getBoundingClientRect():e)&&o.width!=e.width&&e.width&&e.width<1e3&&(o.width=e.width),o.getContext("2d")),a=(t.setTransform(1,0,0,1,0,0),t.translate(0,o.height),t.scale(1,-1),t.fillStyle=r.bgcolor,t.fillRect(0,0,o.width,o.height),t.strokeStyle=r.linecolor,t.beginPath(),l([r.xrange[0],r.defaulty])),n=(t.moveTo(a[0],a[1]),[a[0],a[1]]);for(i in r.value){a=l(r.value[i]);n.push(a[0]),n.push(a[1])}a=l([r.xrange[1],r.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 i=0;i<r.value.length;i+=1)a=l(r.value[i]),t.fillStyle=c==i?"white":r.pointscolor,t.beginPath(),t.arc(a[0],a[1],c==i?4:3,0,2*Math.PI),t.fill();if(r.show_samples){var s=r.resample(r.show_samples);t.fillStyle="#888";for(i=0;i<s.length;i+=1)a=l([i*((r.xrange[1]-r.xrange[0])/r.show_samples)+r.xrange[0],s[i]]),t.beginPath(),t.arc(a[0],a[1],2,0,2*Math.PI),t.fill()}},[0,0]);function i(e){var t,a,n,i=o.getBoundingClientRect(),s=e.clientX-i.left,l=e.clientY-i.top,i=(s<0?s=0:s>o.width&&(s=o.width),l<0?l=0:l>o.height&&(l=o.height),[e.clientX-i.left,e.clientY-i.top]);-1!=c&&m(i,[s,l])>.5*o.height?(r.move_out==y.CURVE_MOVEOUT_DELETE?r.value.splice(c,1):(i=[i[0]-s,i[1]-l],(t=r.value[c])[0]=0==i[0]?t[0]:i[0]<0?r.xrange[0]:r.xrange[1],t[1]=0==i[1]?t[1]:i[1]<0?r.yrange[1]:r.yrange[0]),u(e)):(t=d([-(r.draggable_x?h[0]-s:0),r.draggable_y?h[1]-l:0]),-1!=c&&(i=r.xrange[0],a=r.xrange[1],r.no_overlap&&(0<c&&(i=r.value[c-1][0]),c<r.value.length-1)&&(a=r.value[c+1][0]),(n=r.value[c])[0]+=t[0],n[1]+=t[1],n[0]<i?n[0]=i:n[0]>a&&(n[0]=a),n[1]<r.yrange[0]?n[1]=r.yrange[0]:n[1]>r.yrange[1]&&(n[1]=r.yrange[1])),g(),r.redraw(),h[0]=s,h[1]=l,p(e),e.preventDefault(),e.stopPropagation())}function u(e){c=-1,r.redraw(),document.removeEventListener("mousemove",i),document.removeEventListener("mouseup",u),p(e),e.preventDefault(),e.stopPropagation()}function p(e){a.callback&&a.callback.call(r,r.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=r.value[c]),r.value.sort(function(e,t){return e[0]-t[0]}),e&&(c=r.value.indexOf(e))}return r.redraw(),this}redraw(e={}){this.element.redraw(e)}}y.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"}}}y.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 y.Area({height:"100%"}));t.appendChild(a.root);let n,i,s=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,i]=a.split({type:"horizontal",sizes:["15%","85%"]}),s=i,n.setLimitBox(210,0),i.setLimitBox(512,0)),this.skipPreview||([s,i]=s.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(s),this.skipPreview||(this.previewPanel=i.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;let t=e=>{e&&(e=(e.children||e)[0])&&e.folder&&(this.path.push(e.folder.id??"@"),t(e.folder.folder))};t(e),y.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 y.TreeEvent.NODE_SELECTED:e.multiple||this._enterFolder(t),t.parent||(this.prevData.push(this.currentData),this.currentData=this.data,this._refreshContent(),this.path=["@"],y.emit("@on_folder_change",this.path.join("/")));break;case y.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=S("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=S("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){let o=this.layout==O.LAYOUT_CONTENT,s=(this.filter=n??this.filter??"None",this.searchValue=a??this.searchValue??"",this.content.innerHTML="",this.content.className=o?"lexassetscontent":"lexassetscontent list",this);let i=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),r=Math.min(t+O.MAX_PAGE_ELEMENTS,l.length);for(let e=t;e<r;++e){let t=l[e];t.path?y.request({url:t.path,dataType:"blob",success:e=>{t.bytesize=e.size,i.readAsDataURL(e),i.onload=e=>{t.src=e.currentTarget.result,t._path=t.path,delete t.path,this._refreshContent(a,n)}}}):t.domEl=(n=>{var e=n.type.charAt(0).toUpperCase()+n.type.slice(1),t=d(n.id);let a="Folder"===e,r=document.createElement("li");if(r.className="lexassetitem "+n.type.toLowerCase(),r.tabIndex=-1,s.content.appendChild(r),s.useNativeTitle)r.title=e+": "+n.id;else{let l=document.createElement("span");l.className="lexitemdesc",l.innerHTML="File: "+n.id+"<br>Type: "+e,s.content.appendChild(l),r.addEventListener("mousemove",t=>{if(o){var a=r.getBoundingClientRect(),n=t.target.getBoundingClientRect(),i=l.parentElement.getBoundingClientRect(),s=n.x-i.x-(n.x-a.x);let e=n.y-i.y-(n.y-a.y);t.target.classList.contains("lexassettitle")&&(e+=n.y-a.y),l.style.left=s+t.offsetX+12+"px",l.style.top=e+t.offsetY+"px"}}),r.addEventListener("mouseenter",()=>{o&&(l.style.display="unset")}),r.addEventListener("mouseleave",()=>{o&&setTimeout(()=>{l.style.display="none"},100)})}s.allowMultipleSelection&&((i=document.createElement("input")).type="checkbox",i.className="lexcheckbox",i.checked=n.selected,i.addEventListener("change",(e,t)=>{var a;n.selected=!n.selected,s.onevent&&((a=new P(P.ASSET_CHECKED,e.shiftKey?[n]:n)).multiple=!!e.shiftKey,s.onevent(a)),e.stopPropagation(),e.stopImmediatePropagation()}),r.appendChild(i));var i=document.createElement("span");if(i.className="lexassettitle",i.innerText=n.id,r.appendChild(i),!s.skipPreview){let e=null;n.src&&(-1<["png","jpg"].indexOf(d(n.src))||n.src.includes("data:image/"))||a||!o?(e=document.createElement("img"),i=n.unknown_extension?s.rootPath+"images/file.png":a?s.rootPath+"images/folder.png":n.src,e.src=o||a?i:s.rootPath+"images/file.png",r.appendChild(e)):((e=document.createElement("svg")).className="asset-file-preview",r.appendChild(e),i=document.createElement("text"),e.appendChild(i),i.innerText=t&&t!=n.id?"."+t.toUpperCase():n.type.toUpperCase(),(t=2.5/i.innerText.length)<1&&(i.style.fontSize=64*t+"px",e.style.paddingTop="calc(50% - "+(.5*i.offsetHeight+10)+"px)"))}return a||((t=document.createElement("span")).className="lexassetinfo",t.innerText=e,r.appendChild(t)),r.addEventListener("click",function(e){e.stopImmediatePropagation(),e.stopPropagation();var t=e.detail==y.MOUSE_DOUBLE_CLICK;if(t){if(a)return void s._enterFolder(n)}else e.shiftKey||s.content.querySelectorAll(".lexassetitem").forEach(e=>e.classList.remove("selected")),this.classList.add("selected"),s.selectedItem=n,s.skipPreview||s._previewAsset(n);s.onevent&&((t=new P(t?P.ASSET_DBLCLICKED:P.ASSET_SELECTED,e.shiftKey?[n]:n)).multiple=!!e.shiftKey,s.onevent(t))}),s.contextMenu&&r.addEventListener("contextmenu",function(e){e.preventDefault();let t=s.content.querySelectorAll(".selected").length;y.addContextMenu(1<t?t+" selected":a?n.id:n.type,e,e=>{t<=1&&e.add("Rename"),a||e.add("Clone",s._cloneItem.bind(s,n)),t<=1&&e.add("Properties"),e.add(""),e.add("Delete",s._deleteItem.bind(s,n))})}),r.addEventListener("dragstart",function(e){e.preventDefault()},!1),r})(t)}this.allowNextPage=l.length-1>O.MAX_PAGE_ELEMENTS,y.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:()=>y.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;let s=e.dataTransfer.files.length;for(let i=0;i<e.dataTransfer.files.length;++i){let n=e.dataTransfer.files[i];this.currentData.find(e=>e.id===n.name)||(t.readAsDataURL(n),t.onload=e=>{var t=n.name.substr(n.name.lastIndexOf(".")+1).toLowerCase(),a={id:n.name,src:e.currentTarget.result,extension:t,lastModified:n.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),i==s-1&&(this._refreshContent(),this.skipBrowser||this.tree.refresh())})}}_sortData(n,i=!1){n=n??this._lastSortBy??"id",this.currentData=this.currentData.sort((e,t)=>{var a=i?t[n].localeCompare(e[n]):e[n].localeCompare(t[n]);return a=0==a?i?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))}}y.AssetView=O,Object.assign(y,{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 i in n.data)a.append(i,n.data[i]);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,i){if(!e)throw"invalid URL";var s,l=(e=e.constructor===String?[e]:e).length,r=[];for(s in e){var o=document.createElement("script");o.num=s,o.type="text/javascript",o.src=e[s]+(i?"?version="+i:""),o.original_src=e[s],o.async=!1,o.onload=function(e){l--,r.push(this),l?n&&n(this.original_src,this.num):t&&t(r)},a&&(o.onerror=function(e){a(e,this.original_src,this.num)}),document.getElementsByTagName("head")[0].appendChild(o)}},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)}let n=new FileReader;e.includes("http")?y.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,i;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,i=URL.createObjectURL(n),(a=document.createElement("a")).setAttribute("href",i),a.setAttribute("download",e),a.style.display="none",document.body.appendChild(a),a.click(),document.body.removeChild(a),setTimeout(function(){URL.revokeObjectURL(i)},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}},y.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>'},y.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:b,deleteElement(e){e&&e.remove()},flushCss(e){e.offsetHeight},getControlPoints(e,t,a,n,i,s,l){var r=Math.sqrt(Math.pow(a-e,2)+Math.pow(n-t,2)),r=l*r/(r+Math.sqrt(Math.pow(i-a,2)+Math.pow(s-n,2))),l=l-r;return[a+r*(e-i),n+r*(t-s),a-l*(e-i),n-l*(t-s)]},drawSpline(e,t,a){e.save();for(var n=[],i=t.length,s=0;s<i-4;s+=2)n=n.concat(y.UTILS.getControlPoints(t[s],t[s+1],t[s+2],t[s+3],t[s+4],t[s+5],a));for(s=2;s<t.length-5;s+=2)e.beginPath(),e.moveTo(t[s],t[s+1]),e.bezierCurveTo(n[2*s-2],n[2*s-1],n[2*s],n[2*s+1],t[s+2],t[s+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[i-2],t[i-1]),e.quadraticCurveTo(n[2*i-10],n[2*i-9],t[i-4],t[i-3]),e.stroke(),e.closePath(),e.restore()}};export{y as LX};
|