@coderundebug/ui-web
Version:
A collection of UI web components that can be used in any web project.
2 lines • 59.5 kB
JavaScript
/* By Stephen Paul Hassall (web: https://coderundebug.com) */
import{UiTools as t}from"./ui-tools.js";class i{static t(t){if(!(t instanceof HTMLElement))return;let i=!0;for(;t;){if(!0===i){let i=t.scrollWidth>t.clientWidth,s=t.scrollHeight>t.clientHeight;const e=window.getComputedStyle(t).getPropertyValue("overflow");let r=!1;if(-1!==e.indexOf("scroll")&&(r=!0),-1!==e.indexOf("auto")&&(r=!0),!0===r&&(!0===i||!0===s))return t}if(t.assignedSlot)t=t.assignedSlot,i=!1;else if(t.parentElement)t=t.parentElement,i=!0;else if(t.parentNode)t=t.parentNode,i=!1;else{if(!t.host)break;t=t.host,i=!0}}return document.scrollingElement||document.documentElement}}class s{static i(t){return t.o}static h(t,i,s,e){t.l=!0;const r=[];let h=null,l=[],a=1;for(const i of t.children)if(null!==h&&1===a&&(h.nextRowFirstElement=i),l.push(i),a++,a>t.o){const t={nextRowFirstElement:null};t.rowElementList=l,h=t,r.push(t),l=[],a=1}if(e){if(r.length-1!==s.length)throw new Error("Number of elements given did not match the number in the table")}else if(r.length!==s.length)throw new Error("Number of elements given did not match the number in the table");n.u(t,i),e&&(s.splice(0,0,e),e.setAttribute("slot","header")),r.forEach((t=>{t.beforeElement=null,-1===i?t.beforeElement=t.rowElementList[0]:i<t.rowElementList.length?t.beforeElement=t.rowElementList[i]:t.beforeElement=t.nextRowFirstElement}));const u=t.hasAttribute("drag-row-cells");let d=0;r.forEach((e=>{const r=s[d];r.v=!0,!0===u&&(r.v=!1),t.insertBefore(r,e.beforeElement),-1===i?e.rowElementList.splice(0,0,r):i!==e.rowElementList.length?e.rowElementList.splice(i,0,r):e.rowElementList.push(r);t.m.children.item(d).firstElementChild.assign(...e.rowElementList),d++})),t.o++,t.p.h(i),t._(),t.k(),o.C(t),t.p.R(),t.T.R(),t.$.style.gridTemplateColumns=t.p.D(t.o)}static U(t,i){if(i>t.o)return;if(i<1)return;t.l=!0,n.I(t,i);const s=i-1,e=[];let r=[],h=1;for(const i of t.children)if(r.push(i),h++,h>t.o){const t={};t.rowElementList=r,t.deleteElement=r[s],e.push(t),r=[],h=1}let l=0;e.forEach((i=>{i.rowElementList.splice(s,1),i.deleteElement.remove();t.m.children.item(l).firstElementChild.assign(...i.rowElementList),l++})),t.o--,t.p.U(i),t._(),t.k(),o.C(t),t.p.R(),t.T.R(),t.$.style.gridTemplateColumns=t.p.D(t.o)}static S(t,i,s){o.S(t,i,s),o.C(t)}static A(t,i){const e=s.H(t,i);if(!e)return-1;if(e.length<7)return-1;const r=e[e.length-5],n=e[e.length-7],o=r.firstElementChild.assignedElements();for(let t=0;t<o.length;t++){if(o[t]===n)return t+1}return-1}static L(t){let i=t.m.childElementCount;return 0===i?0:(!1===t.m.firstElementChild.M&&i--,i)}static N(t,i,s){if(t.l=!0,i.length!==t.o)throw new Error("Number of elements is not the same as the number of columns");const e=[];if(!0===t.hasAttribute("drag-row-cells")){t.getAttribute("drag-row-cells").split(",").forEach((t=>{e.push(parseInt(t))}))}for(let t=0;t<i.length;t++){const s=i[t];s.v=!0,0!==e.length&&-1===e.indexOf(t+1)&&(s.v=!1)}let r=t.m.childElementCount,n=!1;0!==r&&!1===t.m.firstElementChild.M&&(r--,n=!0);let o=null;void 0!==s&&(-1===s?!0===n?0!==r&&(o=t.children.item(t.o)):o=t.firstElementChild:s>=r||(o=!0===n?t.children.item(t.o*(s+1)):t.children.item(t.o*s))),i.forEach((i=>{t.insertBefore(i,o)}));const h=t.N(t,i,"row",s);h.v=!1,!0===t.hasAttribute("drag-drop-row")&&(h.v=!0)}static K(t,i){let s=t.m.childElementCount,e=!1;0!==s&&!1===t.m.firstElementChild.M&&(s--,e=!0);let r=i;!1===e&&(r=i-1);const n=t.m.children.item(r);if(!n)return;t.l=!0;n.firstElementChild.assignedElements().forEach((t=>{t.remove()})),t.P(t,n)}static B(t){t.m.querySelectorAll(".row").forEach((i=>{const s=i.firstElementChild.assignedElements();t.P(t,i),s.forEach((t=>{t.remove()}))}))}static F(t,i,s){let e=t.m.childElementCount,r=!1;if(0!==e&&!1===t.m.firstElementChild.M&&(e--,r=!0),i<1)return;if(i>e)return;if(s<-1)return;if(0===s)return;if(s>e)return;t.l=!0;let o=null;o=!1===r?t.m.children.item(i-1):t.m.children.item(i);let h=null;-1===s?h=!1===r?t.m.children.item(0):t.m.children.item(1):s===e||(h=!1===r?t.m.children.item(s):t.m.children.item(s+1)),t.m.insertBefore(o,h),n.Y(t,o,h)}static j(t,i){const e=s.V(t,i);e&&e.classList.add("selected")}static W(t,i){const e=s.V(t,i);e&&e.classList.remove("selected")}static V(t,i){let s=t.m.childElementCount,e=!1;return 0!==s&&!1===t.m.firstElementChild.M&&(s--,e=!0),i<=0||i>s?null:!0===e?t.m.children.item(i):t.m.children.item(i-1)}static O(t,i){const e=s.V(t,i);if(!e)return null;return e.firstElementChild.assignedElements()}static q(t,i){const e=s.H(t,i);if(!e)return-1;if(e.length<7)return-1;const r=e[e.length-5];if(!0!==r.M)return-1;let n=1;for(const i of t.m.children)if(!1!==i.M){if(i===r)return n;n++}return-1}static G(t,i){t.l=!0;const s=t.m.firstElementChild;if(s&&!1===s.M){const i=s.firstElementChild.assignedElements();t.P(t,s),i.forEach((t=>{t.remove()}))}const e=t.firstElementChild;i.forEach((i=>{i.setAttribute("slot","header"),t.insertBefore(i,e)})),t.N(t,i,"header",-1),t.o=i.length,t._(),t.k(),o.C(t),t.p.R(),t.T.R(),t.$.style.gridTemplateColumns=t.p.D(t.o)}static J(t){if(0===t.m.childElementCount)return null;const i=t.m.firstElementChild;if(!i)return null;if(!0===i.M)return null;return i.firstElementChild.assignedElements()}static X(t,i){const e=s.J(t);return null===e||i<1||i>e.length?null:e[i-1]}static Z(t,i,s){if(0===t.m.childElementCount)return;const e=t.m.firstElementChild;if(!e)return;if(!0===e.M)return;const r=e.firstElementChild,n=r.assignedElements();if(i<1||i>n.length)return;t.l=!0;const o=n[i-1],h=o.nextSibling;s.setAttribute("slot","header"),s.tt=o.tt,s.v=o.v,s.it=o.it,!0===o.v&&(s.style.cursor="grab",s.setAttribute("tabindex","0")),n[i-1]=s,t.removeChild(o),t.insertBefore(s,h),r.assign(...n)}static st(t,i,s){let e=t.m.childElementCount,r=!1;if(0!==e&&!1===t.m.firstElementChild.M&&(e--,r=!0),i<1)return null;if(i>e)return null;const n=t.o;if(s<1)return null;if(s>n)return null;let o=(i-1)*n+s-1;if(!0===r&&(o+=n),o>=t.childElementCount)return null;return t.children.item(o)}static et(t,i,e,r){const n=s.V(t,i);if(!n)return;const o=n.firstElementChild,h=o.assignedElements();if(e<1||e>h.length)return;t.l=!0;const l=h[e-1],a=l.nextSibling;r.v=l.v,h[e-1]=r,t.removeChild(l),t.insertBefore(r,a),o.assign(...h)}static H(t,i){const s=[];let e=i;for(;;){if(!e)return null;if(s.push(e),e===t)return s;if(e.assignedSlot)e=e.assignedSlot;else if(e.parentElement)e=e.parentElement;else if(e.parentNode)e=e.parentNode;else{if(!e.host)return s;e=e.host}}}}class e{constructor(t){this.rt=t}update(){const t=window.getComputedStyle(this.rt);this.nt=t.getPropertyValue("--ui-tp"),this.ot=t.getPropertyValue("--ui-tad"),this.ht=t.getPropertyValue("--ui-tdrbg"),this.lt=t.getPropertyValue("--ui-tdrf"),this.ut=t.getPropertyValue("--ui-tdrb"),this.dt=t.getPropertyValue("--ui-tdrbr"),this.ct=t.getPropertyValue("--ui-tdrs"),this.ft=t.getPropertyValue("--ui-tdro"),this.vt=t.getPropertyValue("--ui-tdhbg"),this.gt=t.getPropertyValue("--ui-tdhf"),this.bt=t.getPropertyValue("--ui-tdhb"),this.wt=t.getPropertyValue("--ui-tdhbr"),this._t=t.getPropertyValue("--ui-tdhs"),this.xt=t.getPropertyValue("--ui-tdho"),this.kt=t.getPropertyValue("--ui-thbg"),this.yt=t.getPropertyValue("--ui-thfg"),this.Et=t.getPropertyValue("--ui-thfs"),this.Ct=t.getPropertyValue("--ui-thfw"),this.Rt=t.getPropertyValue("--ui-tclw"),this.Tt=t.getPropertyValue("--ui-tcls"),this.zt=t.getPropertyValue("--ui-tclc")}}class r{static $t=null;static Dt=null;static Ut=0;static It=0;static St=0;static At=0}class n{static Ht(t,i){const s=i.querySelector("slot").assignedElements(),e=document.createElement("div"),r=[];s.forEach((t=>{r.push(t.clientWidth.toString()+"px")})),e.style.position="absolute",e.style.width=i.clientWidth.toString()+"px",e.style.height=i.clientHeight.toString()+"px",e.style.display="grid",e.style.gridTemplateColumns=r.join(" "),e.style.background=t.Lt.ht,e.style.color=t.Lt.lt,e.style.border=t.Lt.ut,e.style.borderRadius=t.Lt.dt,e.style.boxShadow=t.Lt.ct,e.style.opacity=t.Lt.ft;const n=t.hasAttribute("column-lines");for(let i=0;i<s.length;i++){const r=s[i].cloneNode(!0);r.style.padding=t.Lt.nt,!0===n&&0!==i&&(r.style.borderInlineStartWidth=t.Lt.Rt,r.style.borderInlineStartStyle=t.Lt.Tt,r.style.borderInlineStartColor=t.Lt.zt),e.appendChild(r)}return e}static F(t,i,s){let e=0;null===s&&(e=-1);const o=[];let h=!1;for(const r of t.m.children)if(!1!==r.M)if(r!==i){if(r===s){if(!0===h)break;e=1,h=!0}!0===h&&o.push(r)}else{if(!0===h)break;e=-1,h=!0}o.forEach((t=>{if(!0===t.Mt){if(t.Nt===e)return;t.removeEventListener("animationend",n.Kt),t.classList.remove("move-animation-up"),t.classList.remove("move-animation-down")}t.addEventListener("animationend",n.Kt),t.Mt=!0,t.Nt=e,-1===e&&t.classList.add("move-animation-up"),1===e&&t.classList.add("move-animation-down")})),t.m.insertBefore(i,s),r.It=n.q(t,i)}static Kt(t){t.target.Mt=!1,t.target.removeEventListener("animationend",n.Kt),t.target.classList.remove("move-animation-up"),t.target.classList.remove("move-animation-down")}static Y(t,i,s){const e=i.firstElementChild.assignedElements();if(t.l=!0,null===s)return void e.forEach((i=>{t.insertBefore(i,null)}));const r=s.firstElementChild.assignedElements();if(e.length!==r.length)return;const n=r[0];for(let i=0;i<e.length;i++){const s=e[i];t.insertBefore(s,n)}}static Pt(t,i){const s=t.getAttribute("drag-name"),e=i.getAttribute("drag-name");if(!s||!e)return!1;if(s===e)return!0;if(!1===i.hasAttribute("drag-accept"))return!1;return-1!==i.getAttribute("drag-accept").split(",").indexOf(s)}static q(t,i){let s=1;for(const e of t.m.children)if(!1!==e.M){if(e===i)return s;s++}return-1}static Bt(t){if(0===r.It)return;if(r.Dt||(r.Dt=r.$t),r.$t===r.Dt&&r.Ut===r.It)return;const i=new CustomEvent("rowmoved",{detail:{fromTable:r.$t,toTable:r.Dt,fromRow:r.Ut,toRow:r.It}});t.dispatchEvent(i)}static u(t,i){if(!1===t.hasAttribute("drag-row-cells"))return;if(i===t.o)return;-1===i&&(i=0);const s=t.getAttribute("drag-row-cells").split(",");if(0!==s.length){for(let t=0;t<s.length;t++){const e=s[t];let r=parseInt(e);r<=i||(r++,s[t]=r.toString())}n.Ft(t,s)}}static I(t,i){if(!1===t.hasAttribute("drag-row-cells"))return;const s=t.getAttribute("drag-row-cells").split(",");if(0!==s.length){for(let t=0;t<s.length;t++){const e=s[t];if(parseInt(e)===i){s.splice(t,1);break}}for(let t=0;t<s.length;t++){const e=s[t];let r=parseInt(e);r<i||(r--,s[t]=r.toString())}n.Ft(t,s)}}static Yt(t,i,s){if(!1===t.hasAttribute("drag-row-cells"))return;const e=t.getAttribute("drag-row-cells").split(",");if(0===e.length)return;let r=0;r=-1===s?1:i>s?s+1:s;const o=[];for(let t=0;t<e.length;t++){const s=e[t];let n=parseInt(s);n===i||n===r?n!==i?n!==r||o.push(i.toString()):o.push(r.toString()):o.push(s)}n.Ft(t,o)}static Ft(t,i){i.sort(((t,i)=>{const s=parseInt(t),e=parseInt(i);return s>e?1:s<e?-1:0}));const s=i.join(",");t.setAttribute("drag-row-cells",s)}}class o{static jt(t,i){const s=document.createElement("div");s.style.position="absolute",s.style.width=i.clientWidth.toString()+"px",s.style.height=i.clientHeight.toString()+"px",s.style.display="grid",s.style.gridTemplateColumns="1fr",s.style.gridTemplateRows="1fr",s.style.background=t.Lt.vt,s.style.color=t.Lt.gt,s.style.fontSize=t.Lt.Et,s.style.fontWeight=t.Lt.Ct,s.style.border=t.Lt.bt,s.style.borderRadius=t.Lt.wt,s.style.boxShadow=t.Lt._t,s.style.opacity=t.Lt.xt;const e=i.cloneNode(!0);return e.style.padding=t.Lt.nt,s.appendChild(e),s}static S(t,i,s){if(i<=0)return;if(i>t.o)return;if(i===s)return;if(i===s+1)return;if(1===i&&-1===s)return;const e=[];let r=null,o=[],h=1;for(const i of t.children)if(null!==r&&1===h&&(r.nextRowFirstElement=i),o.push(i),h++,h>t.o){const t={nextRowFirstElement:null};t.elementList=o,r=t,e.push(t),o=[],h=1}e.forEach((t=>{t.fromElement=t.elementList[i-1],t.beforeElement=null,-1===s?t.beforeElement=t.elementList[0]:s<t.elementList.length?t.beforeElement=t.elementList[s]:t.beforeElement=t.nextRowFirstElement;for(let i=0;i<t.elementList.length;i++)if(t.elementList[i]===t.fromElement){t.elementList.splice(i,1);break}if(-1===s)t.elementList.splice(0,0,t.fromElement);else if(s<t.elementList.length+1){for(let i=0;i<t.elementList.length;i++)if(t.elementList[i]===t.beforeElement){t.elementList.splice(i,0,t.fromElement);break}}else t.elementList.push(t.fromElement)})),t.l=!0,n.Yt(t,i,s);let l=0;e.forEach((i=>{t.insertBefore(i.fromElement,i.beforeElement);t.m.children.item(l).firstElementChild.assign(...i.elementList),l++})),t._(),t.k(),t.p.S(i,s)}static C(t){const i=t.m.firstElementChild;if(!i)return;if(!0===i.M)return;const s=i.firstElementChild.assignedElements();if(0!==s.length){const i=[];if(!0===t.hasAttribute("drag-header-cells")){t.getAttribute("drag-header-cells").split(",").forEach((t=>{i.push(parseInt(t))}))}if(s.forEach((t=>{t.v=!1})),!0===t.hasAttribute("drag-drop-header")){let e=1;!0===t.hasAttribute("column-drag-from")&&(e=parseInt(t.getAttribute("column-drag-from")),e<=0&&(e=1));let r=1;s.forEach((t=>{t.v=!0,0!==i.length&&-1===i.indexOf(r)&&(t.v=!1),r<e&&(t.v=!1),!0===t.v?(t.tt=!0,t.style.cursor="grab",t.setAttribute("tabindex","0")):(t.tt=!1,t.style.cursor="unset",t.removeAttribute("tabindex","0")),r++}))}}}static Vt(t){if(0===r.At)return;if(r.St===r.At)return;const i=new CustomEvent("columnmoved",{detail:{table:t,fromColumn:r.St,toColumn:r.At}});t.dispatchEvent(i)}}class h{constructor(t){this.rt=t,this.Wt=!1,this.Ot=this.Ot.bind(this),this.qt=this.qt.bind(this),this.Gt=this.Gt.bind(this),this.Jt=this.Jt.bind(this),this.Qt=this.Qt.bind(this),this.Xt=this.Xt.bind(this)}Zt(){this.rt.m.addEventListener("pointerdown",this.Ot),this.rt.m.addEventListener("pointerup",this.qt),this.rt.m.addEventListener("pointermove",this.Gt)}ti(){this.rt.m.removeEventListener("pointerdown",this.Ot),this.rt.m.removeEventListener("pointerup",this.qt),this.rt.m.removeEventListener("pointermove",this.Gt)}Ot(t){if(!1===t.isPrimary)return;if(0!==t.button)return;const i=this.ii(t.target);if(!i)return;if(!0===i.hasAttribute("slot"))return;if(!1===i.v)return;const s=this.si(t.target);if(!s)return;if(!1===s.v)return;r.Ut=n.q(this.rt,s),r.It=0,this.Wt=!0,t.target.setPointerCapture(t.pointerId);const e=s.getBoundingClientRect();this.ei=t.clientX-e.x,this.ri=t.clientY-e.y}qt(t){!1!==this.Wt&&(!0===this.ni&&(!1===this.oi(t)&&(this.hi(t.clientX,t.clientY),n.Y(this.rt,this.li,this.li.nextSibling)),this.ai(t),r.Dt&&(r.Dt.removeAttribute("dragging-valid"),r.Dt.removeAttribute("dragging-from")),r.$t.removeAttribute("dragging-valid"),r.$t.removeAttribute("dragging-to"),n.Bt(this.rt),r.$t=null,r.Dt=null),this.Wt=!1,t.target.releasePointerCapture(t.pointerId))}Gt(t){if(!0===this.Wt){!0!==this.ni&&this.ui(t);const i=t.clientX-this.ei,s=t.clientY-this.ri;this.di.style.left=i.toString()+"px",this.di.style.top=s.toString()+"px",this.ci=t.clientX,this.fi=t.clientY,this.gi(t.clientX,t.clientY),this.bi(t.clientX,t.clientY)}}ui(t){if(this.mi=this.ii(t.target),!this.mi)return;const i=this.si(t.target);if(!i)return;this.rt.Lt.update();const s=i.getBoundingClientRect();this.wi=document.createElement("div"),this.wi.style.position="fixed",this.wi.style.inset="0",this.wi.style.backgroundColor="transparent",this.wi.style.zIndex="999999",this.li=i,this.li.classList.add("drop-row"),this.pi=document.createElement("div"),this.pi.classList.add("dropzone"),this.li.appendChild(this.pi),this._i=this.li.nextSibling,this.di=n.Ht(this.rt,i),this.di.style.left=s.x.toString()+"px",this.di.style.top=s.y.toString()+"px",document.body.appendChild(this.wi),this.wi.appendChild(this.di),this.mi.style.cursor="grabbing",this.xi=setInterval(this.Jt,500),r.$t=this.rt,this.ni=!0}ki(t){this.rt.Lt.update(),this.li=document.createElement("div"),this.li.style.height=t.yi.li.clientHeight.toString()+"px",this.li.style.gridColumn="1/-1",this.li.classList.add("row"),this.li.classList.add("drop-row"),this.pi=document.createElement("div"),this.pi.classList.add("dropzone"),this.li.appendChild(this.pi),this.rt.m.appendChild(this.li),this.ei=t.yi.ei,this.ri=t.yi.ri}ai(t){this.di.addEventListener("transitionend",this.Qt),this.di.style.transition="top "+this.rt.Lt.ot+", left "+this.rt.Lt.ot;const i=this.li.getBoundingClientRect(),s=this.di.getBoundingClientRect();this.di.style.left=i.x.toString()+"px",this.di.style.top=i.y.toString()+"px",this.mi.removeAttribute("style"),clearInterval(this.xi),s.top===i.top&&s.left===i.left&&this.Qt()}Qt(){!1!==this.ni&&(this.di.removeEventListener("transitionend",this.Qt),this.li.removeChild(this.pi),this.li.classList.remove("drop-row"),this.wi.removeChild(this.di),document.body.removeChild(this.wi),this.di=void 0,this.li=void 0,this.wi=void 0,this.pi=void 0,this._i=void 0,this.Wt=!1,this.ni=!1)}Ei(){this.li&&(this.li.addEventListener("transitionend",this.Xt),this.li.style.transition="height "+this.rt.Lt.ot,this.li.style.height="0")}Xt(){this.li.removeEventListener("transitionend",this.Xt),this.li.remove(),this.li=void 0}Ci(t){for(;;){if(!t)return null;if("UI-TABLE"===t.nodeName)return t;t.assignedSlot?t=t.assignedSlot:t=t.parentElement}}ii(t){for(;;){if(!t)return null;if(t.assignedSlot)return t;t=t.parentElement}}si(t){for(;;){if(!t)return null;if(!0===t.M)return t;t.assignedSlot?t=t.assignedSlot:t=t.parentElement}}Jt(){!1!==this.Wt&&!0!==this.Ri()&&this.Ti()}Ri(){const t=this.rt.getBoundingClientRect();let s=0,e=!0,r=!1;if(this.fi>t.bottom&&(s=1,e=!1),this.fi>.9*this.wi.clientHeight&&(s=1,r=!0),this.fi<t.top&&(s=-1,e=!1),this.fi<.1*this.wi.clientHeight&&(s=-1,r=!0),0===s)return!1;let n=i.t(this.rt),o=!0;if(!0===e&&!0===r&&(o=!0),!0===e&&!1===r)return!1;if(!1===e&&!1===r&&(o=!0),!1===e&&!0===r&&(o=!1),1===s)for(;;){if(!n)return!1;if(n!==document.documentElement&&!1===o){if(Math.abs(n.scrollHeight-n.clientHeight-n.scrollTop)<=1){n=i.t(n.parentElement);continue}}return(!0!==o||!1!==r||n===this.rt)&&(n.scrollBy({top:50,behavior:"smooth"}),this.gi(this.ci,this.fi),this.bi(this.ci,this.fi),!0)}if(-1===s)for(;;){if(!n)return!1;if(n===document.documentElement||!1!==o||0!==n.scrollTop)return(!0!==o||!1!==r||n===this.rt)&&(n.scrollBy({top:-50,behavior:"smooth"}),this.gi(this.ci,this.fi),this.bi(this.ci,this.fi),!0);n=i.t(n.parentElement)}return!1}Ti(){const t=this.rt.getBoundingClientRect();let s=0,e=!0,r=!1;if(this.ci>t.right&&(s=1,e=!1),this.ci>.9*this.wi.clientWidth&&(s=1,r=!0),this.ci<t.left&&(s=-1,e=!1),this.ci<.1*this.wi.clientWidth&&(s=-1,r=!0),0===s)return;let n=i.t(this.rt),o=!0;if(!0===e&&!0===r&&(o=!0),!0!==e||!1!==r){if(!1===e&&!1===r&&(o=!0),!1===e&&!0===r&&(o=!1),1===s)for(;;){if(!n)return;if(n!==document.documentElement&&!1===o){if(Math.abs(n.scrollWidth-n.clientWidth-n.scrollLeft)<=1){n=i.t(n.parentElement);continue}}if(!0===o&&!1===r&&n!==this.rt)return;return n.scrollBy({left:50,behavior:"smooth"}),this.gi(this.ci,this.fi),void this.bi(this.ci,this.fi)}if(-1===s)for(;;){if(!n)return;if(n===document.documentElement||!1!==o||0!==n.scrollLeft){if(!0===o&&!1===r&&n!==this.rt)return;return n.scrollBy({left:-50,behavior:"smooth"}),this.gi(this.ci,this.fi),void this.bi(this.ci,this.fi)}n=i.t(n.parentElement)}}}gi(t,i){const s=t-this.ei+this.di.clientWidth/2,e=i-this.ri+this.di.clientHeight/2,n=this.rt.getBoundingClientRect();if(e>=n.top&&e<=n.bottom&&s>=n.left&&s<=n.right)return null!==r.Dt&&r.Dt!==this.rt&&(r.Dt.removeAttribute("dragging-from"),r.Dt.removeAttribute("dragging-valid"),r.Dt.yi.Ei(),r.Dt=null),void this.rt.removeAttribute("dragging-to");let o=null;for(let t=0;t<UiTable.zi.length;t++){const i=UiTable.zi[t],r=i.getBoundingClientRect();if(!(e<r.top)&&!(e>r.bottom||s<r.left||s>r.right)){o=i;break}}if(null===o)return void(null!==r.Dt&&r.Dt!==this.rt&&(r.Dt.removeAttribute("dragging-from"),r.Dt.removeAttribute("dragging-valid"),r.Dt.yi.Ei(),r.Dt=null));null!==r.Dt&&r.Dt!==o&&r.Dt!==this.rt&&(r.Dt.removeAttribute("dragging-from"),r.Dt.removeAttribute("dragging-valid"),r.Dt.yi.Ei(),r.Dt=null),r.Dt=o;const h=this.rt.getAttribute("drag-name"),l=o.getAttribute("drag-name");if(!h||!l)return;let a=!1;if(h===l&&(a=!0),!0===o.hasAttribute("drag-accept")){-1!==o.getAttribute("drag-accept").split(",").indexOf(h)&&(a=!0)}this.rt.setAttribute("dragging-to",l),o.setAttribute("dragging-from",h),!1!==a&&(this.rt.setAttribute("dragging-valid",""),o.setAttribute("dragging-valid",""),r.Dt.yi.li||r.Dt.yi.ki(this.rt),r.Dt.yi.bi(t,i))}bi(t,i){const s=[];for(const t of this.rt.m.children)!1!==t.M&&s.push(t);const e=t-this.ei+this.li.clientWidth/2,r=i-this.ri+this.li.clientHeight/2,o=this.rt.getBoundingClientRect();if(r<o.top||r>o.bottom||e<o.left||e>o.right){if(s.length>0&&s[s.length-1]===this.li)return;n.F(this.rt,this.li,null,!1)}else for(let t=0;t<s.length;t++){const i=s[t],e=i.getBoundingClientRect();if(r>e.top&&r<e.bottom){const o=e.top+e.height/2;if(i===this.li)return;if(r<o){if(0!==t&&s[t-1]===this.li)return;n.F(this.rt,this.li,i,!1)}else{if(t+1<s.length&&s[t+1]===this.li)return;n.F(this.rt,this.li,i.nextSibling,!1)}return}}}oi(t){const i=t.clientX-this.ei+this.di.clientWidth/2,s=t.clientY-this.ri+this.di.clientHeight/2,e=this.rt.getBoundingClientRect();if(s>=e.top&&s<=e.bottom&&i>=e.left&&i<=e.right)return!1;let r=null;for(let t=0;t<UiTable.zi.length;t++){const e=UiTable.zi[t],n=e.getBoundingClientRect();if(!(s<n.top)&&!(s>n.bottom||i<n.left||i>n.right)){r=e;break}}return null!==r&&(!1!==n.Pt(this.rt,r)&&(this.$i(r),!0))}hi(t,i){this.ei,this.di.clientWidth;if(i-this.ri+this.di.clientHeight/2<this.rt.getBoundingClientRect().top)return n.F(this.rt,this.li,this._i,!1),void n.Y(this.rt,this.li,this._i)}$i(t){this.rt.l=!0;const i=this.li.firstElementChild.assignedElements();this.rt.P(this.rt,this.li),i.forEach((t=>{this.rt.removeChild(t)})),t.l=!0;let s=null;if(t.yi.li.nextSibling){const i=t.yi.li.nextSibling.firstElementChild.assignedElements();i.length>0&&(s=i[0])}i.forEach((i=>{t.insertBefore(i,s)}));const e=this.rt.N(t,i,"row");this.li=e,this.li.classList.add("row"),this.li.classList.add("drop-row"),this.pi=document.createElement("div"),this.pi.classList.add("dropzone"),this.li.appendChild(this.pi),r.Dt.yi.li.replaceWith(e),r.Dt.yi.li=null}}class l{constructor(t){this.rt=t,this.Wt=!1,this.Di=this.Di.bind(this),this.Ui=this.Ui.bind(this),this.Ii=this.Ii.bind(this),this.Si=this.Si.bind(this),this.Ai=this.Ai.bind(this)}Zt(){this.rt.addEventListener("keydown",this.Di)}ti(){this.rt.removeEventListener("keydown",this.Di)}Di(t){if("Space"===t.code){if(!0===this.Wt)return;if(!0===this.rt.yi.Wt)return t.preventDefault(),void t.stopPropagation();if(!this.rt.Hi)return;return this.Li=this.rt.Hi,r.Ut=n.q(this.rt,this.Li),r.It=0,this.Mi(this.rt.Hi),t.preventDefault(),void t.stopPropagation()}}Ui(t){if(t.preventDefault(),"Space"===t.code){if(r.$t!==this.rt)return;return r.Dt!==this.rt?this.$i(r.Dt):n.Y(this.rt,this.li,this.li.nextSibling),this.Ni(!1),r.Dt&&(r.Dt.removeAttribute("dragging-valid"),r.Dt.removeAttribute("dragging-from"),r.Dt.removeAttribute("dragging-to")),this.rt.removeAttribute("dragging-valid"),this.rt.removeAttribute("dragging-from"),this.rt.removeAttribute("dragging-to"),n.Bt(this.rt),r.$t=null,r.Dt=null,void t.preventDefault()}if(!0===this.Wt){if("ArrowUp"===t.key||"ArrowDown"===t.key||"ArrowLeft"===t.key||"ArrowRight"===t.key){if(!0===this.Ki)return;this.Ki=!0,setTimeout((()=>{this.Ki=!1}),100)}if("ArrowUp"===t.key){if(!r.Dt.Pi.li.previousSibling)return void this.Bi(-1);if(!0===r.Dt.Pi.li.previousSibling.classList.contains("header")){if(0!==r.Dt.scrollTop){r.Dt.scrollTop=0,this.di.style.transition="top "+this.rt.Lt.ot;const t=r.Dt.Pi.li.getBoundingClientRect();this.di.style.top=t.y.toString()+"px"}else this.Bi(-1);return}n.F(r.Dt,r.Dt.Pi.li,r.Dt.Pi.li.previousSibling),r.Dt.Pi.Fi(this)}if("ArrowDown"===t.key){const t=r.Dt.Pi.li.nextSibling;if(!t)return void this.Bi(1);n.F(r.Dt,r.Dt.Pi.li,t.nextSibling),r.Dt.Pi.Fi(this)}if("ArrowLeft"===t.key||"ArrowRight"===t.key){let i=this.li.getBoundingClientRect();null!==r.Dt&&r.Dt!==this.rt&&(i=r.Dt.Pi.li.getBoundingClientRect(),r.Dt.removeAttribute("dragging-from"),r.Dt.removeAttribute("dragging-valid"),r.Dt.Pi.li&&(r.Dt.Pi.li.remove(),r.Dt.Pi.li=null));let s=1;"ArrowLeft"===t.key&&(s=-1);const e=this.Yi(r.Dt,s);if(null===e)return;r.Dt=e,r.Dt!==this.rt&&(r.Dt.Pi.ji(this.rt),n.F(this.rt,this.li,null));const o=this.rt.getAttribute("drag-name"),h=e.getAttribute("drag-name");this.rt.setAttribute("dragging-to",h),e.setAttribute("dragging-from",o),this.rt.setAttribute("dragging-valid",""),e.setAttribute("dragging-valid","");const l=i.top+i.height/2,a=this.Vi(l,e);n.F(r.Dt,r.Dt.Pi.li,a),r.Dt.Pi.Fi(this)}"Escape"===t.key&&this.Wi()}}Bi(t){null!==r.Dt&&r.Dt!==this.rt&&(r.Dt.removeAttribute("dragging-from"),r.Dt.removeAttribute("dragging-valid"),r.Dt.Pi.li&&(r.Dt.Pi.li.remove(),r.Dt.Pi.li=null));const i=this.Yi(r.Dt,t);if(null===i)return;r.Dt=i,r.Dt!==this.rt&&(r.Dt.Pi.ji(this.rt),n.F(this.rt,this.li,null));const s=this.rt.getAttribute("drag-name"),e=i.getAttribute("drag-name");this.rt.setAttribute("dragging-to",e),i.setAttribute("dragging-from",s),this.rt.setAttribute("dragging-valid",""),i.setAttribute("dragging-valid","");let o=null,h=null,l=null;const a=i.getBoundingClientRect();for(const t of i.m.children){if(!1===t.M)continue;const i=t.getBoundingClientRect();i.top<a.top||(i.bottom>a.bottom||(null===h&&(h=t),l=t))}-1===t&&(o=l),1===t&&(o=h),n.F(r.Dt,r.Dt.Pi.li,o),r.Dt.Pi.Fi(this)}Ii(t){!0!==l.Oi&&this.Wi()}Si(){this.Wi()}Mi(t){this.rt.Lt.update();const i=t.getBoundingClientRect();this.wi=document.createElement("div"),this.wi.style.position="fixed",this.wi.style.inset="0",this.wi.style.backgroundColor="transparent",this.wi.style.zIndex="999999",this.li=t,this.li.classList.add("drop-row"),this.pi=document.createElement("div"),this.pi.classList.add("dropzone"),this.li.appendChild(this.pi),this._i=this.li.nextSibling,this.di=n.Ht(this.rt,t);let s=i.x+20;this.di.style.left=s.toString()+"px",this.di.style.top=i.y.toString()+"px",document.body.appendChild(this.wi),this.wi.appendChild(this.di),t.blur(),r.$t=this.rt,r.Dt=this.rt,document.addEventListener("keydown",this.Ui),document.addEventListener("scroll",this.Ii),document.addEventListener("click",this.Si),this.Wt=!0,this.Ki=!1}ji(t){this.rt.Lt.update(),this.li=document.createElement("div"),this.li.style.height=t.Pi.li.clientHeight.toString()+"px",this.li.style.gridColumn="1/-1",this.li.classList.add("row"),this.li.classList.add("drop-row"),this.pi=document.createElement("div"),this.pi.classList.add("dropzone"),this.li.appendChild(this.pi),this.rt.m.appendChild(this.li),this.ei=t.Pi.ei,this.ri=t.Pi.ri}Ni(t){const i=this.li.getBoundingClientRect();if(!0===t)return this.di.style.left=i.x.toString()+"px",this.di.style.top=i.y.toString()+"px",void this.Ai();this.di.addEventListener("transitionend",this.Ai),this.di.style.transition="top "+this.rt.Lt.ot+", left "+this.rt.Lt.ot,this.di.style.left=i.x.toString()+"px",this.di.style.top=i.y.toString()+"px"}Ai(){!1!==this.Wt&&(this.di.removeEventListener("transitionend",this.Ai),this.li.removeChild(this.pi),this.li.classList.remove("drop-row"),this.wi.removeChild(this.di),document.body.removeChild(this.wi),this.di=void 0,this.li=void 0,this.wi=void 0,this.pi=void 0,document.removeEventListener("keydown",this.Ui),document.removeEventListener("scroll",this.Ii),document.removeEventListener("click",this.Si),this.Li.focus(),this.Wt=!1)}Wi(){r.Dt!==this.rt?this.$i(r.Dt):n.Y(this.rt,this.li,this.li.nextSibling),this.Ni(!0),r.Dt&&(r.Dt.removeAttribute("dragging-valid"),r.Dt.removeAttribute("dragging-from"),r.Dt.removeAttribute("dragging-to")),n.Bt(this.rt),this.rt.removeAttribute("dragging-valid"),this.rt.removeAttribute("dragging-from"),this.rt.removeAttribute("dragging-to"),r.$t=null,r.Dt=null}qi(){let t=this.rt.getBoundingClientRect(),s=this.li.getBoundingClientRect();if(s.bottom>window.innerHeight&&t.bottom>window.innerHeight){const t=i.t(this.rt.parentElement);let e=window.innerHeight-16-s.bottom;return t.scrollBy({top:-e}),this.Gi(),!1}if(s.top<0&&t.top<0){const t=i.t(this.rt.parentElement);let e=s.top-16;return t.scrollBy({top:e}),this.Gi(),!1}let e=!0;if(s.top<t.top||s.bottom>t.bottom){let r=!0;if(s.top+s.height/2>t.top+t.height/2&&(r=!1),!0===r&&(t.top<0||t.top>window.innerHeight)){i.t(this.rt.parentElement).scrollBy({top:t.top}),e=!1}if(!1===r&&(t.bottom<0||t.bottom>window.innerHeight)){const s=i.t(this.rt.parentElement);let r=window.innerHeight-16-t.bottom;s.scrollBy({top:-r}),e=!1}}if(t.left<0){i.t(this.rt.parentElement).scrollBy({left:t.left-16}),e=!1}else if(t.right>window.innerWidth&&t.width<window.innerWidth){const s=i.t(this.rt.parentElement);let r=window.innerWidth-16-t.right;s.scrollBy({left:-r}),e=!1}if(!1===e&&this.Gi(),s.top<t.top){const i=t.top-s.top;return this.rt.scrollBy({top:-i,behavior:"smooth"}),e}if(s.bottom>t.bottom){const i=s.bottom-t.bottom;return this.rt.scrollBy({top:i,behavior:"smooth"}),e}return!1}Gi(){l.Oi=!0,l.Ji=Date.now()+1e3,setTimeout((()=>{l.Ji>=Date.now()||(l.Oi=!1)}),1200)}Fi(t){if(!0===this.qi())return;t.di.style.transition="top "+this.rt.Lt.ot+", left "+this.rt.Lt.ot;const i=this.li.getBoundingClientRect();let s=i.x+20;t.di.style.left=s.toString()+"px",t.di.style.top=i.y.toString()+"px"}Yi(t,i){const s=[];if(UiTable.zi.forEach((t=>{!1!==n.Pt(this.rt,t)&&s.push(t)})),s.length<=1)return null;let e=s.indexOf(t);return-1!==e?(1===i?e++:e--,e<0?e=s.length-1:e>=s.length&&(e=0),s[e]):void 0}Vi(t,i){for(const s of i.m.children){if(!1===s.M)continue;const i=s.getBoundingClientRect();if(!(t<i.top)&&!(t>i.bottom))return s}return null}$i(t){this.rt.l=!0;const i=this.li.firstElementChild.assignedElements();this.rt.P(this.rt,this.li),i.forEach((t=>{this.rt.removeChild(t)})),t.l=!0;let s=null;if(t.Pi.li.nextSibling){const i=t.Pi.li.nextSibling.firstElementChild.assignedElements();i.length>0&&(s=i[0])}i.forEach((i=>{t.insertBefore(i,s)})),this.Li=this.rt.N(t,i,"row"),this.li=this.Li,this.li.classList.add("row"),this.li.classList.add("drop-row"),this.pi=document.createElement("div"),this.pi.classList.add("dropzone"),this.li.appendChild(this.pi),r.Dt.Pi.li.replaceWith(this.Li),r.Dt.Pi.li=null}}class a{constructor(t){this.rt=t,this.Qi=document.createElement("div"),this.Qi.classList.add("overlay"),this.Wt=!1,this.Ot=this.Ot.bind(this),this.qt=this.qt.bind(this),this.Gt=this.Gt.bind(this),this.Jt=this.Jt.bind(this),this.Ui=this.Ui.bind(this),this.Xi=!1,this.Zi=[]}Zt(){this.rt.m.addEventListener("pointerdown",this.Ot),this.rt.m.addEventListener("pointerup",this.qt),this.rt.m.addEventListener("pointermove",this.Gt)}ti(){this.rt.m.addEventListener("pointerdown",this.Ot),this.rt.m.addEventListener("pointerup",this.qt),this.rt.m.addEventListener("pointermove",this.Gt)}Ot(t){if(!1===t.isPrimary)return;if(0!==t.button)return;const i=this.ts(t.target);if(!i)return;if(!1===i.hasAttribute("slot"))return;if(!1===i.v)return;this.ss=i.it,this.es=null,r.St=i.it,r.At=0,this.Wt=!0,t.target.setPointerCapture(t.pointerId);const s=i.getBoundingClientRect();this.rs=t.clientX-s.x,this.ns=t.clientY-s.y,!0===this.Xi&&(this.rt.$.style.gridTemplateColumns=this.rt.p.D(this.rt.o)),this.os=1,!0===this.rt.hasAttribute("column-drag-from")&&(this.os=parseInt(this.rt.getAttribute("column-drag-from")),this.os<=0&&(this.os=1))}qt(t){!1!==this.Wt&&(!0===this.ni&&(this.ai(t),null!==this.es&&(o.S(this.rt,this.ss,this.es),-1===this.es?r.At=1:this.ss>this.es?r.At=this.es+1:r.At=this.es,o.Vt(this.rt))),this.Wt=!1,t.target.releasePointerCapture(t.pointerId))}Gt(t){if(!0===this.Wt){!0!==this.ni&&this.ui(t);const i=t.clientX-this.rs,s=t.clientY-this.ns;this.hs.style.left=i.toString()+"px",this.hs.style.top=s.toString()+"px",this.ci=t.clientX,this.fi=t.clientY,this.ls(t.clientX)}}Ui(t){!0===this.Wt&&"Escape"===t.key&&(this.ai(!0),t.preventDefault())}ui(t){if(this.us=this.ts(t.target),!this.us)return;this.rt.Lt.update();const i=this.us.getBoundingClientRect();this.wi=document.createElement("div"),this.wi.style.position="fixed",this.wi.style.inset="0",this.wi.style.backgroundColor="transparent",this.wi.style.zIndex="999999",this.hs=o.jt(this.rt,this.us),this.hs.style.left=i.x.toString()+"px",this.hs.style.top=i.y.toString()+"px",document.body.appendChild(this.wi),this.wi.appendChild(this.hs),this.us.style.cursor="grabbing",this.xi=setInterval(this.Jt,500),document.addEventListener("keydown",this.Ui),this.us.setAttribute("selected",""),this.ni=!0}ai(t){this.us.style.cursor="grab",clearInterval(this.xi),this.wi.removeChild(this.hs),document.body.removeChild(this.wi),this.hs=void 0,this.wi=void 0,this.Zi.forEach((t=>{t.classList.remove("selected")})),document.removeEventListener("keydown",this.Ui),this.us.removeAttribute("selected"),this.Wt=!1,this.ni=!1}ls(t){let i=0,s=1,e=null,r=0;this.Zi.forEach((n=>{if(r++,r<this.os)return;const o=n.getBoundingClientRect(),h=Math.abs(o.x-t);if(null===e)return i=h,s=r,void(e=n);h>i||(i=h,s=r,e=n)})),s===this.Zi.length&&1!==this.os||(this.Zi.forEach((t=>{t.classList.remove("selected")})),null!==e&&e.classList.add("selected"),s===this.Zi.length&&(s=-1),this.es=s)}ts(t){for(;;){if(!t)return null;if(t.assignedSlot)return t;t=t.parentElement}}Jt(){if(!1===this.Wt)return;const t=this.rt.getBoundingClientRect();let s=0,e=!0,r=!1;if(this.ci>t.right&&(s=1,e=!1),this.ci>.9*this.wi.clientWidth&&(s=1,r=!0),this.ci<t.left&&(s=-1,e=!1),this.ci<.1*this.wi.clientWidth&&(s=-1,r=!0),0===s)return;let n=i.t(this.rt),o=!0;if(!0===e&&!0===r&&(o=!0),!0!==e||!1!==r){if(!1===e&&!1===r&&(o=!0),!1===e&&!0===r&&(o=!1),1===s)for(;;){if(!n)return;if(n!==document.documentElement&&!1===o){if(Math.abs(n.scrollWidth-n.clientWidth-n.scrollLeft)<=1){n=i.t(n.parentElement);continue}}if(!0===o&&!1===r&&n!==this.rt)return;return n.scrollBy({left:50,behavior:"smooth"}),void this.ls(this.ci)}if(-1===s)for(;;){if(!n)return;if(n===document.documentElement||!1!==o||0!==n.scrollLeft){if(!0===o&&!1===r&&n!==this.rt)return;return n.scrollBy({left:-50,behavior:"smooth"}),void this.ls(this.ci)}n=i.t(n.parentElement)}}}R(){!0===this.rt.hasAttribute("drag-drop-header")?!1===this.Xi&&(this.rt.$.appendChild(this.Qi),this.Xi=!0):!0===this.Xi&&(this.rt.$.removeChild(this.Qi),this.Xi=!1),this.Zi=[];const t=this.rt.o;if(t<=1)return;for(let i=0;i<t;i++){const t=document.createElement("div");t.classList.add("bar"),t.style.gridColumn=(i+1).toString(),t.style.gridRow="1",this.Qi.appendChild(t),this.Zi.push(t)}const i=document.createElement("div");i.classList.add("bar"),i.style.justifySelf="start",i.style.gridColumn="1",i.style.gridRow="1",this.Qi.appendChild(i),this.Zi.push(i)}ds(){const t=this.rt.m.firstElementChild;if(!t)return;const i=t.firstElementChild.assignedElements(),s=[];i.forEach((t=>{s.push(t.offsetWidth)}));return s.join(" ")}}class u{constructor(t){this.rt=t,this.Wt=!1,this.Di=this.Di.bind(this),this.Ui=this.Ui.bind(this),this.Si=this.Si.bind(this)}Zt(){this.rt.addEventListener("keydown",this.Di)}ti(){this.rt.removeEventListener("keydown",this.Di)}Di(t){if("Space"===t.code){if(!0===this.Wt)return;if(!0===this.rt.T.Wt)return t.preventDefault(),void t.stopPropagation();if(this.us=this.ts(t.target),!this.us)return;if(!1===this.us.hasAttribute("slot"))return;return!1===this.us.v?(t.preventDefault(),void t.stopPropagation()):(this.ss=this.us.it,r.St=this.us.it,r.At=0,this.Mi(t),t.preventDefault(),void t.stopPropagation())}}Ui(t){if(t.preventDefault(),"Space"===t.code)return this.ai(),this.us.focus(),void o.Vt(this.rt);if(!0===this.Wt){if("ArrowLeft"===t.key||"ArrowRight"===t.key){if(!0===this.Ki)return;this.Ki=!0,setTimeout((()=>{this.Ki=!1}),100)}if("ArrowLeft"===t.key){if(1===this.ss)return;let t=1;if(!0===this.rt.hasAttribute("column-drag-from")&&(t=parseInt(this.rt.getAttribute("column-drag-from")),t<=0&&(t=1)),this.ss<=t)return;let i=-1;this.ss>2&&(i=this.ss-2),o.S(this.rt,this.ss,i),this.ss--,r.At=this.ss,this.qi(),this.cs()}if("ArrowRight"===t.key){if(this.ss===this.rt.o)return;o.S(this.rt,this.ss,this.ss+1),this.ss++,r.At=this.ss,this.qi(),this.cs()}"Escape"===t.key&&(this.ai(),o.Vt(this.rt))}}Si(){this.ai()}Mi(t){if(this.us=this.ts(t.target),!this.us)return;this.rt.Lt.update();const i=this.us.getBoundingClientRect();this.wi=document.createElement("div"),this.wi.style.position="fixed",this.wi.style.inset="0",this.wi.style.backgroundColor="transparent",this.wi.style.zIndex="999999",this.hs=o.jt(this.rt,this.us);let s=i.x+20,e=i.y+20;this.hs.style.left=s.toString()+"px",this.hs.style.top=e.toString()+"px",document.body.appendChild(this.wi),this.wi.appendChild(this.hs),this.us.blur(),document.addEventListener("keydown",this.Ui),document.addEventListener("click",this.Si),this.us.setAttribute("selected",""),this.Wt=!0,this.Ki=!1}ai(){this.us.style.cursor="grab",clearInterval(this.xi),this.wi.removeChild(this.hs),document.body.removeChild(this.wi),this.hs=void 0,this.wi=void 0,document.removeEventListener("keydown",this.Ui),document.removeEventListener("click",this.Si),this.us.removeAttribute("selected"),this.Wt=!1,this.ni=!1}cs(){const t=this.us.getBoundingClientRect();let i=t.x+20,s=t.y+20;this.hs.style.left=i.toString()+"px",this.hs.style.top=s.toString()+"px"}ts(t){for(;;){if(!t)return null;if(t.assignedSlot)return t;t=t.parentElement}}qi(){let t=this.us.getBoundingClientRect();if(t.left<0){i.t(this.rt.parentElement).scrollBy({left:t.left-16})}else if(t.right>window.innerWidth){const s=i.t(this.rt.parentElement);let e=window.innerWidth-16-t.right;s.scrollBy({left:-e})}}}class d{constructor(t){this.rt=t,this.Qi=document.createElement("div"),this.Qi.classList.add("overlay"),this.Ot=this.Ot.bind(this),this.qt=this.qt.bind(this),this.Gt=this.Gt.bind(this),this.Xi=!1,this.Zi=[],this.Wt=!1}Ot(t){if(!1===t.isPrimary)return;if(0!==t.button)return;let i=t.target;!1===i.classList.contains("bar")&&(i=t.target.parentElement),i.classList.add("selected"),this.fs(),this.vs(i),this.gs=t.clientX,this.bs=this.ws[this.ps],this._s=this.ws[this.xs],t.target.setPointerCapture(t.pointerId),this.Wt=!0}qt(t){let i=t.target;!1===i.classList.contains("bar")&&(i=t.target.parentElement),i.classList.remove("selected"),t.target.releasePointerCapture(t.pointerId),this.ks(),this.Wt=!1,this.ys()}Gt(t){if(!1===this.Wt)return;if(t.clientX<this.Es)return;if(t.clientX>this.Cs)return;const i=t.clientX-this.gs;this.ws[this.ps]=this.bs+i,this.ws[this.xs]=this._s-i;let s=[];this.ws.forEach((t=>{s.push(t.toString()+"px")}));const e=s.join(" ");this.rt.$.style.gridTemplateColumns=e}D(t){if(!1===this.rt.hasAttribute("column-widths")){return"var(--ui-table-template-columns, "+"1fr ".repeat(t)+")"}let i=this.rt.getAttribute("column-widths");return-1!==i.indexOf(",")&&(i=i.replaceAll(","," ")),i}R(){!0===this.rt.hasAttribute("column-bars")?!1===this.Xi&&(this.rt.$.appendChild(this.Qi),this.Xi=!0):!0===this.Xi&&(this.rt.$.removeChild(this.Qi),this.Xi=!1),this.Zi.forEach((t=>{t.removeEventListener("pointerdown",this.Ot),t.removeEventListener("pointerup",this.qt),t.removeEventListener("pointermove",this.Gt),this.Qi.removeChild(t)})),this.Zi=[];const t=this.rt.o-1;if(!(t<=0))for(let i=0;i<t;i++){const t=document.createElement("div");t.classList.add("bar"),t.addEventListener("pointerdown",this.Ot),t.addEventListener("pointerup",this.qt),t.addEventListener("pointermove",this.Gt);const i=document.createElement("div");t.appendChild(i),this.Qi.appendChild(t),this.Zi.push(t)}}fs(){const t=this.rt.m.firstElementChild;if(!t)return;const i=t.firstElementChild.assignedElements();this.ws=[],i.forEach((t=>{this.ws.push(t.offsetWidth)}))}ks(){const t=this.rt.m.firstElementChild;if(!t)return;const i=t.firstElementChild.assignedElements();let s=0;i.forEach((t=>{s+=t.offsetWidth}));const e=[];i.forEach((t=>{const i=t.offsetWidth/s*100;e.push(i.toFixed(2)+"%")}));const r=e.join(" ");this.rt.$.style.gridTemplateColumns=r,this.rt.setAttribute("column-widths",r)}vs(t){this.ps=-1,this.xs=-1;let i=null,s=null,e=!1;if(this.Zi.length>1){const t=this.Zi[0].getBoundingClientRect(),i=this.Zi[1].getBoundingClientRect();t.x>i.x&&(e=!0)}if(!1===e){for(let e=0;e<this.Zi.length;e++)if(this.Zi[e]===t){this.ps=e,this.xs=e+1,0!==e&&(i=this.Zi[e-1]),e+1<this.Zi.length&&(s=this.Zi[e+1]);break}}else for(let e=this.Zi.length-1;e>=0;e--)if(this.Zi[e]===t){this.ps=e+1,this.xs=e,0!==e&&(s=this.Zi[e-1]),e+1<this.Zi.length&&(i=this.Zi[e+1]);break}const r=this.rt.getBoundingClientRect();let n=null,o=null;null!==i&&(n=i.getBoundingClientRect()),null!==s&&(o=s.getBoundingClientRect()),this.Es=0,this.Cs=window.innerWidth,n&&(this.Es=n.x+32),n||(this.Es=r.x+32),this.Es<0&&(this.Es=0),o&&(this.Cs=o.right-32),o||(this.Cs=r.right-32),this.Cs>window.innerWidth&&(this.Cs=window.innerWidth)}ys(){const t=new Event("columnsized");this.rt.dispatchEvent(t)}h(t){if(!1===this.rt.hasAttribute("column-widths"))return;let i=this.rt.getAttribute("column-widths");-1!==i.indexOf(",")&&(i=i.replaceAll(","," "));const s=i.split(" ");if(0===s.length)return void this.rt.setAttribute("column-widths","1fr");if(!1===s[0].endsWith("%"))return-1===t?s.splice(0,0,"1fr"):t!==s.length?s.splice(t,0,"1fr"):s.push("1fr"),void this.rt.setAttribute("column-widths",s.join(" "));const e=1/(s.length+1);let r=0;for(let t=0;t<s.length;t++){let i=parseFloat(s[t]);i-=i*e,r+=i,s[t]=i.toFixed(2)+"%"}const n=(100-r).toFixed(2)+"%";-1===t?s.splice(0,0,n):t!==s.length?s.splice(t,0,n):s.push(n),this.rt.setAttribute("column-widths",s.join(" "))}U(t){if(!1===this.rt.hasAttribute("column-widths"))return;let i=this.rt.getAttribute("column-widths");-1!==i.indexOf(",")&&(i=i.replaceAll(","," "));const s=i.split(" ");if(0===s.length)return void this.rt.setAttribute("column-widths","1fr");if(!1===s[0].endsWith("%"))return s.splice(t-1,1),void this.rt.setAttribute("column-widths",s.join(" "));const e=parseFloat(s[t-1])/100,r=e/(1-e);let n=0;s.splice(t-1,1);for(let t=0;t<s.length;t++){if(t===s.length-1){s[t]=(100-n).toFixed(2)+"%";break}let i=parseFloat(s[t]);i+=i*r,n+=i,s[t]=i.toFixed(2)+"%"}this.rt.setAttribute("column-widths",s.join(" "))}S(t,i){const s=this.rt.m.firstElementChild;if(!s)return;const e=s.firstElementChild.assignedElements();let r=0;e.forEach((t=>{r+=t.offsetWidth}));const n=[];e.forEach((t=>{const i=t.offsetWidth/r*100;n.push(i.toFixed(2)+"%")}));let o=n[t-1];-1===i?(n.splice(t-1,1),n.splice(0,0,o)):i>t?(n.splice(i,0,o),n.splice(t-1,1)):(n.splice(i,0,o),n.splice(t,1));const h=n.join(" ");this.rt.$.style.gridTemplateColumns=h,this.rt.setAttribute("column-widths",h)}}export class UiTable extends HTMLElement{constructor(){super(),this.p=new d(this),this.yi=new h(this),this.Pi=new l(this),this.T=new a(this),this.Rs=new u(this),this.Lt=new e(this),this.attachShadow({mode:"open",slotAssignment:"manual"}),this.shadowRoot.innerHTML=UiTable.uiHtml,this.shadowRoot.adoptedStyleSheets=[UiTable.uiCssStyleSheet],this.$=this.shadowRoot.getElementById("column-control"),this.m=this.shadowRoot.getElementById("base"),this.Ts=this.Ts.bind(this),this.zs=this.zs.bind(this),this.$s=this.$s.bind(this),this.Ds=this.Ds.bind(this),this.l=!1}getColumnCount(){return s.i(this)}addColumn(t,i,e){s.h(this,t,i,e)}deleteColumn(t){s.U(this,t)}moveColumn(t,i){s.S(this,t,i)}getColumnNumber(t){return s.A(this,t)}getRowCount(){return s.L(this)}addRow(t,i){s.N(this,t,i)}deleteRow(t){s.K(this,t)}clearRows(t){s.B(this)}moveRow(t,i){s.F(this,t,i)}selectRow(t){s.j(this,t)}unselectRow(t){s.W(this,t)}getRowElementList(t){return s.O(this,t)}getRowNumber(t){return s.q(this,t)}setHeaders(t){s.G(this,t)}getHeaderElementList(){return s.J(this)}getHeaderElement(t){return s.X(this,t)}replaceHeaderElement(t,i){s.Z(this,t,i)}getElement(t,i){return s.st(this,t,i)}replaceElement(t,i,e){s.et(this,t,i,e)}connectedCallback(){!0===this.Us()&&this.Is(),UiTable.Ss(this),this.yi.Zt(),this.Pi.Zt(),this.T.Zt(),this.Rs.Zt(),this.Hi=null,this.As=new MutationObserver(this.Ts),this.As.observe(this,{childList:!0})}disconnectedCallback(){this.As.disconnect(),this.As=void 0,UiTable.Hs(this),this.yi.ti(),this.Pi.ti(),this.T.ti(),this.Rs.ti()}attributeChangedCallback(t,i,s){"columns"===t&&!0===this.Us()&&this.Is()}static get observedAttributes(){return["columns"]}Ts(t,i){if(!0===this.l)return void(this.l=!1);if(!0===this.Us())return void this.Is();let s=[],e=0;t.forEach((t=>{if(t.addedNodes)for(const i of t.addedNodes)s.push(i),e++,e>=this.o&&(this.N(this,s,"row"),s=[],e=0)}))}static Ss(t){UiTable.zi||(UiTable.zi=[]),UiTable.zi.push(t)}static Hs(t){if(UiTable.zi)for(let i=0;i<UiTable.zi.length;i++){if(UiTable.zi[i]===t)return void UiTable.zi.splice(i,1)}}Us(){const t=this.querySelectorAll('[slot="header"]');0===t.length?this.m.removeAttribute("has-headers"):this.m.setAttribute("has-headers","");let i=1;return!0===this.hasAttribute("columns")&&(i=parseInt(this.getAttribute("columns"))),i<=0&&(i=1),t.length>i&&(i=t.length),i!==this.o&&(this.o=i,!0)}Is(){this.Ls(),this._(),this.k(),this.p.R(),this.T.R()}Ls(){this.m.innerHTML="";const t=this.querySelectorAll('[slot="header"]');0!==t.length&&(this.N(this,t,"header"),o.C(this)),this.$.style.gridTemplateColumns=this.p.D(this.o);const i=[];if(!0===this.hasAttribute("drag-row-cells")){this.getAttribute("drag-row-cells").split(",").forEach((t=>{i.push(parseInt(t))}))}let s=[],e=1;const r=this.hasAttribute("drag-drop-row");for(const t of this.children)if(!0!==t.hasAttribute("slot")&&(t.v=!0,0!==i.length&&-1===i.indexOf(e)&&(t.v=!1),s.push(t),e++,e>this.o)){const t=this.N(this,s,"row");t.v=!1,!0===r&&(t.v=!0),s=[],e=1}}async _(){const t=[],i=[],s=this.o;for(let e=1;e<=s;e++){const r=`& slot:not([name])::slotted(*:nth-child(${2*s}n + ${s+e}))`,n=`& slot:not([name])::slotted(*:nth-child(${2*s}n + ${e}))`;t.push(r),i.push(n)}t.join(","),i.join(",");const e=[],r=[];for(let t=1;t<=s;t+=2){const i=`& slot:not([name])::slotted(*:nth-child(${s}n + ${t}))`;e.push(i),1!=t&&r.push(i)}const n=e.join(","),o=r.join(",");let h=`\n /* Vertical */\n :host([vertical][striped]) #base:not([has-headers]) .row:nth-child(even) slot:not([name])::slotted(*:nth-child(${s}n+1)),\n :host([vertical][striped]) #base[has-headers] .row:nth-child(odd) slot:not([name])::slotted(*:nth-child(${s}n+1)),\n :host([vertical][hover]) .row:hover slot:not([name])::slotted(*:nth-child(${s}n+1)),\n :host([vertical]) .row slot:not([name])::slotted(*:nth-child(${s}n+1)) {\n background: var(--ui-tvbg);\n color: var(--ui-tvfg);\n font-family: inherit;\n font-size: var(--ui-tvfs);\n font-weight: var(--ui-tvfw);\n padding: var(--ui-tvp);\n }\n\n /* Cells (everything except header and vertical) */\n :host([vertical]) .row slot:not([name])::slotted(*:not(:nth-child(${s}n+1))),\n :host(:not([vertical])) .row slot:not([name])::slotted(*) {\n background-color: var(--ui-table-background);\n color: var(--ui-table-foreground);\n font-family: inherit;\n font-size: var(--ui-tfs);\n font-weight: var(--ui-tfw);\n padding: var(--ui-tp);\n }\n\n /* Row lines */\n :host([row-lines]) ::slotted(*:not(:nth-last-child(-n + ${s}))) {\n border-block-end:\n var(--ui-trlw)\n var(--ui-trls)\n var(--ui-trlc);\n }\n\n /* Column lines */\n :host([column-lines]) ::slotted(*:not(:nth-child(${s}n + ${s}))) {\n border-inline-end:\n var(--ui-tclw)\n var(--ui-tcls)\n var(--ui-tclc);\n }\n\n /* Rounded */\n :host([rounded]) #base > *:first-child ::slotted(*:first-child) {\n border-start-start-radius: var(--ui-trr);\n }\n\n :host([rounded]) #base > *:first-child ::slotted(*:nth-child(${s})) {\n border-start-end-radius: var(--ui-trr);\n }\n\n :host([rounded]) ::slotted(*:nth-last-child(${s})) {\n border-end-start-radius: var(--ui-trr);\n }\n\n :host([rounded]) ::slotted(*:last-child) {\n border-end-end-radius: var(--ui-trr);\n }\n\n /* Boxed */\n :host([boxed]) #base > *:first-child ::slotted(*) {\n border-block-start:\n var(--ui-tbw)\n var(--ui-tbs)\n var(--ui-tbc);\n }\n\n :host([boxed]) ::slotted(*:nth-last-child(-n + ${s})) {\n border-block-end:\n var(--ui-tbw)\n var(--ui-tbs)\n var(--ui-tbc);\n }\n\n :host([boxed]) ::slotted(*:nth-child(${s}n + ${s})) {\n border-inline-end:\n var(--ui-tbw)\n var(--ui-tbs)\n var(--ui-tbc);\n }\n\n :host([boxed]) ::slotted(*:nth-child(${s}n + 1)) {\n border-inline-start:\n var(--ui-tbw)\n var(--ui-tbs)\n var(--ui-tbc);\n }\n\n /* But not the header parts */\n :host([boxed]) #base > .header:first-child ::slotted(*) {\n border-block-start: none;\n }\n\n :host([boxed]) #base > .header ::slotted(*:nth-child(${s}n + ${s})) {\n border-inline-end: none;\n }\n\n :host([boxed]) #base > .header ::slotted(*:nth-child(${s}n + 1)) {\n border-inline-start: none;\n }\n\n /* Striped column */\n :host([striped-column]:not([vertical])) .row {\n ${n} {\n background-color: var(--ui-tsb);\n color: var(--ui-tsf);\n }\n }\n :host([striped-column][vertical]) .row {\n ${o} {\n background-color: var(--ui-tsb);\n color: var(--ui-tsf);\n }\n }\n\n /* Sticky Column */\n :host([sticky-column]) ::slotted(*:nth-child(${s}n + 1)) {\n position: sticky;\n inset-inline-start: 0;\n }\n `,l="\n :host([drag-drop-row]) .row slot:not([name])::slotted(*) {\n cursor: grab;\n }\n ";const a=[];if(!0===this.hasAttribute("drag-row-cells")){this.getAttribute("drag-row-cells").split(",").forEach((t=>{const i=parseInt(t)-1,e=`& slot:not([name])::slotted(*:nth-child(${s}n + ${i+1}))`;a.push(e)}));l=`\n :host([drag-drop-row]) .row {\n ${a.join(",")} {\n cursor: grab;\n