@dynamix-layout/core 1.2.0 → 2.0.0
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/CHANGELOG.md +28 -0
- package/README.md +23 -192
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +519 -0
- package/dist/index.d.ts +519 -0
- package/dist/index.js +1338 -0
- package/dist/index.umd.js +1 -0
- package/package.json +12 -11
- package/dist/core.cjs +0 -57
- package/dist/core.es.js +0 -1381
- package/dist/core.iife.js +0 -57
- package/dist/core.umd.js +0 -57
- package/dist/types/index.d.cts +0 -522
- package/dist/types/index.d.ts +0 -522
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! @dynamix-layout/core | MIT License */ (function(x,$){typeof exports=="object"&&typeof module<"u"?$(exports):typeof define=="function"&&define.amd?define(["exports"],$):(x=typeof globalThis<"u"?globalThis:x||self,$(x.DynamixLayoutCore={}))})(this,(function(x){"use strict";function $(){return typeof process>"u"||process.env.NODE_ENV!=="production"}const jt=t=>{$()&&console.warn(`[dynamix-layout] ${t.message}`)},w=t=>t.type==="row";function A(t){const e=[],n=i=>{w(i)?i.children.forEach(n):e.push(i)};return t.children.forEach(n),e}function Wt(t){return A(t).flatMap(e=>e.children.map(n=>n.id))}function dt(t){const e=[],n=i=>{e.push(i.id),w(i)&&i.children.forEach(n)};return n(t),e}function z(t,e){return A(t).find(n=>n.id===e)}function v(t,e){return A(t).find(n=>n.children.some(i=>i.id===e))}function H(t,e){for(const n of t.children){if(n.id===e)return t;if(w(n)){const i=H(n,e);if(i)return i}}}const Kt=6;function lt(t,e,n,i){if(n.type==="root")return ft(e.container,n.position);if(n.type==="tabset"){const f=e.tabsets.get(n.tabsetId);return f?n.position!=="center"?ft(f,n.position):z(t.root,n.tabsetId)?.isFolded?f:{x:f.x+f.width*.1,y:f.y+f.height*.1,width:f.width*.8,height:f.height*.8}:null}const o=v(t.root,n.tabId),r=o&&i?.tabBars.get(o.id)?.tabs,a=r?.findIndex(f=>f.id===n.tabId)??-1;if(!r||a<0)return null;const d=r.length>1?Math.max(2,r[1].rect.x-(r[0].rect.x+r[0].rect.width)):Kt,{rect:s}=r[a];return{x:n.position==="before"?s.x-d+1:s.x+s.width+1,y:s.y,width:Math.max(2,d-2),height:s.height}}function ft(t,e){const{x:n,y:i,width:o,height:r}=t;switch(e){case"left":return{x:n,y:i,width:o/2,height:r};case"right":return{x:n+o/2,y:i,width:o/2,height:r};case"top":return{x:n,y:i,width:o,height:r/2};case"bottom":return{x:n,y:i+r/2,width:o,height:r/2}}}const Yt=(t,e)=>t.length===e.length&&t.every((n,i)=>n===e[i]);function N(t,e){return Yt(t.children,e)?t:{...t,children:e}}function D(t,e,n){if(t.id===e){const o=n(t);if(Array.isArray(o)||!w(o))throw new Error("The root can only be replaced by a row.");return o}const i=o=>{const r=[];for(const a of o.children)if(a.id===e){const d=n(a);Array.isArray(d)?r.push(...d):r.push(d)}else r.push(w(a)?i(a):a);return N(o,r)};return i(t)}const M=100,ht=t=>Number.isFinite(t)&&t>=0?t:M;function Gt(t){if(t.children.length===0)return null;const e=ht(t.weight),n=t.children.some(i=>i.id===t.activeTabId);return e===t.weight&&n?t:{...t,weight:e,activeTabId:n?t.activeTabId:t.children[0].id}}function ut(t){const e=[];for(const o of t.children){if(!w(o)){const a=Gt(o);a&&e.push(a);continue}let r=ut(o);w(r)&&r.children.length===1&&(r=r.children[0]),!(w(r)&&r.children.length===0)&&(w(r)&&r.direction===t.direction?e.push(...r.children):e.push(r))}const n=ht(t.weight),i=N(t,e);return n===t.weight?i:{...i,weight:n}}function _(t){let e=ut(t);for(;e.children.length===1&&w(e.children[0]);){const i=e.children[0];e={...e,weight:i.weight,direction:i.direction,children:i.children}}return(e.children.length<=1||e.direction==="horizontal")&&(e.direction!=="horizontal"||e.weight!==M)&&(e={...e,direction:"horizontal",weight:M}),e}const Ht=t=>t==="horizontal"?"vertical":"horizontal";function V(t,e){return{type:"tabset",id:e("tabset",t),weight:M,activeTabId:t,isFolded:!1,children:[{type:"tab",id:t}]}}function Jt(t,e,n="root"){const i=(o,r,a)=>{const d=o.length<=2?o.map(s=>V(s,e)):[V(o[0],e),i(o.slice(1),Ht(r),e("row"))];return{type:"row",id:a,weight:M,direction:r,children:d}};return i(t,"horizontal",n)}const bt=t=>t==="horizontal"?"vertical":"horizontal",J=t=>t==="top"||t==="left",gt=(t,e)=>(t==="left"||t==="right")==(e==="horizontal");function j(t,e,n,i,o){return D(t,e,r=>{const a=r,d=[...a.children];return d.splice(i,0,...n),{...a,children:d,activeTabId:o,isFolded:!1}})}function pt(t,e,n,i,o){const r=H(t,e),a=z(t,e);if(!r||!a)return t;if(gt(i,r.direction)){const f=r.children.indexOf(a)+(J(i)?0:1),p=[...r.children];return p.splice(f,0,n),D(t,r.id,()=>N(r,p))}const d={...a,weight:M,isFolded:!1},s={type:"row",id:o("row"),weight:a.weight,direction:bt(r.direction),children:J(i)?[n,d]:[d,n]};return D(t,e,()=>s)}function mt(t,e,n,i){const o=J(n);if(t.children.length===0)return N(t,[e]);if(gt(n,t.direction))return N(t,o?[e,...t.children]:[...t.children,e]);const r=t.children.length===1?t.children[0]:{type:"row",id:i("row"),weight:t.weight,direction:t.direction,children:t.children};return{...t,weight:M,direction:bt(t.direction),children:o?[e,r]:[r,e]}}function k(t,e){const n=v(t,e);if(!n)return t;const i=n.children.filter(r=>r.id!==e),o=D(t,n.id,()=>i.length===0?[]:{...n,children:i,activeTabId:n.activeTabId===e?i[0].id:n.activeTabId});return _(o)}function kt(t,e){return _(D(t,e,()=>[]))}const yt=(t,e)=>t.foldOrder.indexOf(e)+1;function wt(t,e,n){let i=null;for(const o of e)o.id===n||w(o)||!o.isFolded||(!i||yt(t,o.id)>yt(t,i.id))&&(i=o);return e.map(o=>o===i?{...i,isFolded:!1}:o)}const Tt=t=>!w(t)&&t.isFolded;function qt(t){return A(t).length>1}function R(t){const e=d=>{let s=d.children;return s.length>0&&s.every(Tt)&&(s=wt(t,s)),s=s.map(f=>w(f)?e(f):f.isFolded&&s.length<2?{...f,isFolded:!1}:f),N(d,s)},n=e(t.root),i=new Set(dt(n)),o=t.maximizedTabsetId&&z(n,t.maximizedTabsetId)?t.maximizedTabsetId:null,r=t.foldOrder.filter(d=>i.has(d)),a=t.lastActiveTabsetId&&z(n,t.lastActiveTabsetId)?t.lastActiveTabsetId:null;return n===t.root&&o===t.maximizedTabsetId&&r.length===t.foldOrder.length&&a===t.lastActiveTabsetId?t:{root:n,maximizedTabsetId:o,foldOrder:r,lastActiveTabsetId:a}}function Zt(t,e){return t.maximizedTabsetId===e||!z(t.root,e)||!qt(t.root)?null:{...t,maximizedTabsetId:e}}function It(t){return t.maximizedTabsetId?{...t,maximizedTabsetId:null}:null}function Xt(t,e){const n=z(t.root,e),i=H(t.root,e);if(!n||!i||n.isFolded||i.children.length<2)return null;const o=[...t.foldOrder.filter(s=>s!==e),e],r={...t,foldOrder:o,maximizedTabsetId:null};let a=i.children.map(s=>s===n?{...n,isFolded:!0}:s);a.every(Tt)&&(a=wt(r,a,e));const d=D(t.root,i.id,()=>N(i,a));return R({...r,root:d})}function Qt(t,e){const n=z(t.root,e);if(!n||!n.isFolded)return null;const i=D(t.root,e,()=>({...n,isFolded:!1}));return R({...t,root:i})}function xt(t,e){return e.type==="tab"?v(t,e.tabId):z(t,e.tabsetId)}function q(t,e,n){const i=xt(t,e);if(!i||A(t).length===1&&(e.type==="tabset"||i.children.length===1))return!1;switch(n.type){case"root":return!0;case"tab":{const a=v(t,n.tabId);return a?e.type==="tab"?e.tabId!==n.tabId:a!==i:!1}case"tabset":{const a=z(t,n.tabsetId);return a?e.type==="tabset"?a!==i:a!==i?!0:i.children.length<2?!1:n.position!=="center"||i.children[i.children.length-1].id!==e.tabId:!1}}}function Z(t,e,n,i){if(!q(t.root,e,n))return null;const o=xt(t.root,e),r=e.type==="tab"?[{type:"tab",id:e.tabId}]:o.children,a=e.type==="tab"?e.tabId:r[r.length-1].id,d=()=>e.type==="tab"?V(e.tabId,i):{...o,isFolded:!1};let s=e.type==="tab"?k(t.root,e.tabId):kt(t.root,o.id);switch(n.type){case"tab":{const f=v(s,n.tabId),p=f.children.findIndex(c=>c.id===n.tabId)+(n.position==="after"?1:0);s=j(s,f.id,r,p,a);break}case"tabset":{if(n.position==="center"){const f=z(s,n.tabsetId);s=j(s,f.id,r,f.children.length,a)}else s=pt(s,n.tabsetId,d(),n.position,i);break}case"root":s=mt(s,d(),n.position,i);break}return s=_(s),R({...t,root:s,maximizedTabsetId:null,lastActiveTabsetId:v(s,a)?.id??null})}const te=["left","right","top","bottom"],X=(t,e)=>e.x>=t.x&&e.x<=t.x+t.width&&e.y>=t.y&&e.y<=t.y+t.height;function zt(t,e,n={}){const{length:i=.25,thickness:o=8}=n,{x:r,y:a,width:d,height:s}=t;switch(e){case"left":return{x:r,y:a+s*(1-i)/2,width:o,height:s*i};case"right":return{x:r+d-o,y:a+s*(1-i)/2,width:o,height:s*i};case"top":return{x:r+d*(1-i)/2,y:a,width:d*i,height:o};case"bottom":return{x:r+d*(1-i)/2,y:a+s-o,width:d*i,height:o}}}function ee(t,e){const n=e.x-t.x,i=e.y-t.y;return n<t.width/3?"left":n>2*t.width/3?"right":i<t.height/3?"top":i>2*t.height/3?"bottom":"center"}function ie(t,e){if(t.length===0)return null;const n=t[t.length-1];if(e.x>n.rect.x+n.rect.width)return{type:"tab",tabId:n.id,position:"after"};if(e.x<t[0].rect.x)return{type:"tab",tabId:t[0].id,position:"before"};let i=t[0],o=1/0;for(const a of t){const d=a.rect.x+a.rect.width/2;Math.abs(e.x-d)<o&&(o=Math.abs(e.x-d),i=a)}const r=i.rect.x+i.rect.width/2;return{type:"tab",tabId:i.id,position:e.x<r?"before":"after"}}function St(t,e,n,i,o,r){const a=s=>s&&q(t.root,i,s)?s:null;for(const s of te)if(X(zt(e.container,s,r),n))return a({type:"root",position:s});const d=A(t.root);for(const s of d){const f=o?.tabBars.get(s.id);if(!(!f||!X(f.rect,n)))return f.isRotated||s.isFolded?a({type:"tabset",tabsetId:s.id,position:"center"}):a(ie(f.tabs,n))}for(const s of d){if(t.maximizedTabsetId&&t.maximizedTabsetId!==s.id)continue;const f=e.tabsets.get(s.id);if(!f||!X(f,n))continue;const p=s.isFolded?"center":ee(f,n);return a({type:"tabset",tabsetId:s.id,position:p})}return null}function Q(t,e){const n=new Map,{width:i,height:o}=e.minPanelSize,r=(a,d)=>{let s;if(w(a)){let f=0,p=0,c=0,l=0;for(const u of a.children){const h=r(u,a.direction);c+=h.horizontalCount,l+=h.verticalCount,a.direction==="horizontal"?(f+=h.width,p=Math.max(p,h.height)):(p+=h.height,f=Math.max(f,h.width))}const b=(a.children.length-1)*e.splitterSize;a.direction==="horizontal"?f+=b:p+=b,s={width:f,height:p,horizontalCount:c,verticalCount:l}}else{const f=d==="horizontal";s=a.isFolded?f?{width:e.foldedSize,height:o,horizontalCount:0,verticalCount:0}:{width:i,height:e.foldedSize,horizontalCount:0,verticalCount:0}:{width:i,height:o,horizontalCount:f?1:0,verticalCount:f?0:1}}return n.set(a.id,s),s};return r(t,t.direction),n}function ne(t,e){const n=(i,o)=>i*o+Math.max(0,i-1)*e.splitterSize;return{width:Math.max(t.width,n(t.horizontalCount,e.minPanelSize.width)),height:Math.max(t.height,n(t.verticalCount,e.minPanelSize.height))}}const tt=(t,e)=>`${t}~${e}`,et=(t,e)=>{if(t.size!==e.size)return!1;const n=e.entries();for(const[i,o]of t){const[r,a]=n.next().value;if(i!==r||o!==a)return!1}return!0},vt=(t,e)=>!!t&&t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height;function At(t,e,n,i,o){const r=Q(t,n),a=ne(r.get(t.id),n),d={x:e.x,y:e.y,width:Math.max(e.width,a.width),height:Math.max(e.height,a.height)},s=new Map,f=new Map,p=new Map,c=(u,h,g,m)=>u.set(g,vt(h?.get(g),m)?h.get(g):m),l=(u,h)=>{c(s,o?.rows,u.id,h);const g=u.direction==="horizontal",m=r.get(u.id),y=g?h.width-m.width:h.height-m.height,T=y<0;let E=0,F,B=0;for(const I of u.children)!w(I)&&I.isFolded||(E+=I.weight,F=I.id,B++);const C=E===0,P=I=>C?1:I;C&&(E=B);let U=0,K=0,Y=0;u.children.forEach((I,Ee)=>{const Bt=r.get(I.id),Fe=w(I)||!I.isFolded;let ct=0;if(!T&&Fe&&E>0){K+=P(I.weight);const G=I.id===F?y:Math.round(y*K/E);ct=G-Y,Y=G}const S=g?{x:h.x+U,y:h.y,width:Bt.width+ct,height:h.height}:{x:h.x,y:h.y+U,width:h.width,height:Bt.height+ct};U+=(g?S.width:S.height)+n.splitterSize,w(I)?l(I,S):c(f,o?.tabsets,I.id,S);const Ut=u.children[Ee+1];if(Ut){const G=g?{x:S.x+S.width,y:S.y,width:n.splitterSize,height:S.height}:{x:S.x,y:S.y+S.height,width:S.width,height:n.splitterSize};c(p,o?.splitters,tt(I.id,Ut.id),G)}})};l(t,d),i&&f.has(i)&&c(f,o?.tabsets,i,d);const b=vt(o?.container,d)?o.container:d;return o&&b===o.container&&et(s,o.rows)&&et(f,o.tabsets)&&et(p,o.splitters)?o:{container:b,rows:s,tabsets:f,splitters:p}}function Dt(t,e){const n=i=>{for(let o=0;o<i.children.length;o++){const r=i.children[o],a=i.children[o+1];if(a&&tt(r.id,a.id)===e)return{row:i,before:r,after:a};if(w(r)){const d=n(r);if(d)return d}}return null};return n(t)}const Ot=t=>!w(t)&&t.isFolded;function re(t){return Ot(t.before)||Ot(t.after)}const W=(t,e)=>(w(e)?t.rows:t.tabsets).get(e.id);function oe(t,e,n,i){const o=Dt(t,i);if(!o)return null;const r=W(e,o.before),a=W(e,o.after);if(!r||!a)return null;const d=Q(t,n),s=o.row.direction==="horizontal",f=c=>s?c.width:c.height,p=c=>{const l=d.get(c.id);return s?l.width:l.height};return{value:f(r),min:p(o.before),max:f(r)+f(a)-p(o.after)}}function Et(t,e,n,i,o){const r=Dt(t,i);if(!r||re(r))return null;const a=W(e,r.before),d=W(e,r.after);if(!a||!d)return null;const s=Q(t,n),f=r.row.direction==="horizontal",p=f?a.x:a.y,c=f?d.x+d.width:d.y+d.height,l=s.get(r.before.id),b=s.get(r.after.id),u=f?l.width:l.height,h=f?b.width:b.height,g=n.splitterSize/2,m=f?o.x:o.y,y=Math.max(p+u+g,Math.min(c-h-g,m)),T=y-g-p,E=c-(y+g),F=Math.max(0,T-u),B=Math.max(0,E-h),C=F+B,P=r.before.weight+r.after.weight,U=C>0?F/C*P:P/2,K=C>0?B/C*P:P/2,Y=r.row.children.map(I=>I===r.before?{...I,weight:U}:I===r.after?{...I,weight:K}:I);return D(t,r.row.id,()=>N(r.row,Y))}const se=t=>({type:"tabset",id:t.id,weight:t.weight,activeTabId:t.activeTabId,...t.isFolded?{isFolded:!0}:{},children:t.children.map(e=>({type:"tab",id:e.id}))}),Ft=t=>({type:"row",id:t.id,weight:t.weight,direction:t.direction,children:t.children.map(e=>w(e)?Ft(e):se(e))});function Nt(t){return{version:2,root:Ft(t.root),...t.maximizedTabsetId?{maximizedTabsetId:t.maximizedTabsetId}:{}}}const ae=(t,e)=>{for(const n of Object.keys(t)){const i=t[n],o=e[n];if(Array.isArray(i)&&Array.isArray(o)){if(i.length!==o.length||i.some((r,a)=>r!==o[a]))return!1}else if(i!==o)return!1}return!0},it=t=>$()?Object.freeze(t):t;function nt(t,e){if(!e)return t.forEach(r=>it(r)),t;let n=t.size!==e.size;const i=[...e.keys()];let o=0;for(const[r,a]of t){const d=e.get(r);d&&ae(d,a)?t.set(r,d):(it(a),n=!0),i[o++]!==r&&(n=!0)}return n?t:e}function $t(t,e,n,i){if(i&&i.root===t.root&&i.maximizedTabsetId===t.maximizedTabsetId&&i.rects===e&&i.drag===n)return i;const o=new Map,r=new Map,a=new Map,d=t.maximizedTabsetId;let s=0;const f=c=>c.children.forEach(l=>w(l)?f(l):s++);f(t.root);const p=c=>{c.children.forEach((l,b)=>{if(w(l))p(l);else{const h=l.id===d,g=!!d&&!h,m=l.isFolded&&!h;o.set(l.id,{id:l.id,tabIds:l.children.map(y=>y.id),activeTabId:l.activeTabId,parentDirection:c.direction,isFolded:m,isMaximized:h,isHidden:g,canFold:c.children.length>1,canMaximize:s>1});for(const y of l.children){const T=y.id===l.activeTabId;a.set(y.id,{id:y.id,tabsetId:l.id,isActive:T,isVisible:T&&!m&&!g})}}const u=c.children[b+1];if(u){const h=tt(l.id,u.id),g=m=>!w(m)&&m.isFolded;r.set(h,{id:h,rowId:c.id,direction:c.direction,beforeId:l.id,afterId:u.id,isLocked:g(l)||g(u),isHidden:!!d})}})};return p(t.root),it({root:t.root,tabsets:nt(o,i?.tabsets),splitters:nt(r,i?.splitters),tabs:nt(a,i?.tabs),rects:e,maximizedTabsetId:d,drag:n})}function ce(t,e,n,i){const o=new Set;let r=t,a=e,d={x:0,y:0,width:0,height:0},s=At(r.root,d,a,r.maximizedTabsetId),f=null,p=$t(r,s,null),c=!1,l=null;const b=()=>{s=At(r.root,d,a,r.maximizedTabsetId,s);const h=le(p.drag,f)?p.drag:f&&de(f),g=$t(r,s,h,p);g!==p&&(p=g,o.forEach(m=>m(p)))},u=()=>(l&&l.model.root===r.root&&l.model.maximizedTabsetId===r.maximizedTabsetId||(l={model:r,value:Nt(r)}),l.value);return{get model(){return r},get rects(){return s},get config(){return a},get snapshot(){return p},get drag(){return f},get isDestroyed(){return c},subscribe(h){return o.add(h),()=>o.delete(h)},setContainer(h){d=h,c||b()},setConfig(h){a=h,c||b()},update(h){c||(h.model&&(r=h.model),h.drag!==void 0&&(f=h.drag),b())},commit(h,g){return c?(i({code:"DESTROYED",message:"This layout was destroyed; the call was ignored."}),!1):!h||h===r?!1:(r=h,b(),g&&n?.(u(),g),!0)},report(h){c||n?.(u(),h)},toJSON:u,destroy(){c=!0,f=null,o.clear()}}}const de=({source:t,target:e,indicator:n})=>({source:t,target:e,indicator:n});function le(t,e){return!t||!e?t===e:t.source===e.source&&t.target===e.target&&t.indicator===e.indicator}function fe(t,e){return t===e?!0:!t||!e||t.type!==e.type||t.position!==e.position?!1:t.type==="tab"?t.tabId===e.tabId:t.type==="tabset"?t.tabsetId===e.tabsetId:!0}function he(t,e){const n={startDrag(i){if(t.isDestroyed)return!1;const{snapshot:o,model:r}=t;if(i.type==="splitter"){const a=o.splitters.get(i.splitterId);if(!a||a.isLocked||r.maximizedTabsetId)return!1}else{if(!(i.type==="tab"?o.tabs.has(i.tabId):o.tabsets.has(i.tabsetId)))return!1;t.commit(It(r),"maximize")}return t.update({drag:{source:i,target:null,indicator:null,startRoot:t.model.root}}),!0},updateDrag(i,o){const{drag:r,model:a,rects:d,config:s}=t;if(r){if(r.source.type==="splitter"){const f=Et(a.root,d,s,r.source.splitterId,i);f&&t.update({model:{...a,root:f}});return}n.setDragTarget(St(a,d,i,r.source,o),o)}},setDragTarget(i,o){const{drag:r,model:a,rects:d}=t;if(!r||r.source.type==="splitter"||fe(r.target,i))return;const s=i&<(a,d,i,o);t.update({drag:{...r,target:i,indicator:s}})},endDrag(){const{drag:i,model:o}=t;if(!i)return!1;if(t.update({drag:null}),i.source.type==="splitter")return o.root===i.startRoot?!1:(t.report("resize"),!0);const r=i.target&&Z(o,i.source,i.target,e);return t.commit(r,"move")},cancelDrag(){const{drag:i,model:o}=t;if(!i)return;const r=i.source.type==="splitter"&&o.root!==i.startRoot;t.update({drag:null,...r?{model:{...o,root:i.startRoot}}:{}})}};return n}const ue=["center","left","right","top","bottom"],be=["left","right","top","bottom"];function ge(t,e){const n=[];for(const i of A(t.root))for(const o of ue)n.push({type:"tabset",tabsetId:i.id,position:o});for(const i of be)n.push({type:"root",position:i});return n.filter(i=>q(t.root,e,i))}class L extends Error{code;path;constructor(e,n,i){super(i?`${n} (at ${i})`:n),this.name="DynamixLayoutError",this.code=e,this.path=i}}const pe={minPanelSize:{width:40,height:40},splitterSize:10,foldedSize:40},Mt={row:"row",tabset:"ts"};function me(t){const e=new Set;let n=0;return{createId:(o,r)=>{if(t){const d=t(o,r);return e.add(d),d}let a=r===void 0?"":`${Mt[o]}-${r}`;for(;a===""||e.has(a);)a=`${Mt[o]}-${++n}`;return e.add(a),a},reserve(o){for(const r of o)e.add(r)},reset(){e.clear(),n=0}}}const rt=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),O=(t,e)=>{throw new L("INVALID_LAYOUT",t,e)},ye=["horizontal","vertical"];function ot(t,e){const n=new Set,i=new Set,o=(c,l)=>{(typeof c.id!="string"||c.id==="")&&O("Expected a non-empty string id",`${l}.id`);const b=c.id;return n.has(b)&&O(`Duplicate node id "${b}"`,`${l}.id`),n.add(b),b},r=(c,l)=>{const b=c.weight;return typeof b=="number"&&Number.isFinite(b)&&b>=0?b:(e({code:"INVALID_WEIGHT",message:"Invalid weight replaced by 100",path:`${l}.weight`}),100)},a=(c,l)=>{const b=o(c,l);Array.isArray(c.children)||O("Expected a children array",`${l}.children`);const u=c.children.flatMap((g,m)=>{const y=`${l}.children[${m}]`;(!rt(g)||g.type!=="tab"||typeof g.id!="string"||g.id==="")&&O('Expected { type: "tab", id: string }',y);const T=g.id;return i.has(T)?(e({code:"DUPLICATE_TAB_ID",message:`Duplicate tab "${T}" dropped`,path:y}),[]):(i.add(T),[{type:"tab",id:T}])}),h=c.activeTabId;return h!==void 0&&!u.some(g=>g.id===h)&&e({code:"INVALID_ACTIVE_TAB",message:`Active tab "${String(h)}" is not in the tabset`,path:`${l}.activeTabId`}),{type:"tabset",id:b,weight:r(c,l),activeTabId:typeof h=="string"?h:u[0]?.id??"",isFolded:c.isFolded===!0,children:u}},d=(c,l)=>{const b=o(c,l);ye.includes(c.direction)||O('Expected direction "horizontal" or "vertical"',`${l}.direction`),Array.isArray(c.children)||O("Expected a children array",`${l}.children`);const u=c.children.map((h,g)=>{const m=`${l}.children[${g}]`;return rt(h)?h.type==="row"?d(h,m):h.type==="tabset"?a(h,m):O('Expected type "row" or "tabset"',`${m}.type`):O("Expected a row or tabset",m)});return{type:"row",id:b,weight:r(c,l),direction:c.direction,children:u}};(!rt(t.root)||t.root.type!=="row")&&O("Expected a root row","root");const s=_(d(t.root,"root")),f=typeof t.maximizedTabsetId=="string"?t.maximizedTabsetId:null,p=R({root:s,maximizedTabsetId:f,lastActiveTabsetId:null,foldOrder:[]});return{root:p.root,maximizedTabsetId:p.maximizedTabsetId}}function st(t){return typeof t=="object"&&t!==null&&!("version"in t)&&typeof t.typNode=="string"}const we=t=>typeof t=="number"&&Number.isFinite(t)&&t>=0;function Rt(t,e={}){const n=e.onWarning??(()=>{}),i=(u,h)=>we(u.nodPart)?u.nodPart:(n({code:"INVALID_WEIGHT",message:"Invalid weight replaced by 100",path:`${h}.nodPart`}),100);if(!st(t))throw new L("INVALID_LAYOUT","Not a v1 layout","");const o=new Set,r=u=>{typeof u.uidNode=="string"&&o.add(u.uidNode),u.nodKids?.forEach(r)};r(t);const a=u=>{let h=u;for(let g=1;o.has(h);g++)h=`${u}-${g}`;return o.add(h),h},d=(u,h)=>typeof u.uidNode=="string"&&u.uidNode!==""?u.uidNode:a(h),s=new Set,f=(u,h)=>u.flatMap((g,m)=>{if(g?.typNode!=="tab")return[];const y=g.nodName;return typeof y!="string"||y===""||s.has(y)?(n({code:"DUPLICATE_TAB_ID",message:`Duplicate or unnamed tab "${String(y)}" dropped`,path:`${h}.nodKids[${m}]`}),[]):(s.add(y),[{type:"tab",id:y}])}),p=(u,h)=>{const g=f(u.nodKids??[],h),m=typeof u.nodOpen=="string"?u.nodOpen:"",y=g.some(T=>T.id===m);return m&&!y&&g.length>0&&n({code:"INVALID_ACTIVE_TAB",message:`Active tab "${m}" is not in the tabset`,path:`${h}.nodOpen`}),{type:"tabset",id:d(u,"ts"),weight:i(u,h),...g.length>0?{activeTabId:y?m:g[0].id}:{},...u.nodFold===!0?{isFolded:!0}:{},children:g}},c=(u,h,g)=>{const m=h%2===0?"horizontal":"vertical",y=[];return(u.nodKids??[]).forEach((T,E)=>{const F=`${g}.nodKids[${E}]`;T?.typNode==="row"?y.push(c(T,h+1,F)):T?.typNode==="tabset"?y.push(p(T,F)):T?.typNode==="tab"&&y.push({...p({...T,uidNode:a(`ts-${T.nodName}`),nodKids:[T],nodOpen:T.nodName},F)})}),{type:"row",id:d(u,"row"),weight:i(u,g),direction:m,children:y}},b={root:t.typNode==="row"?c(t,0,"root"):t.typNode==="tabset"?{type:"row",id:a("root"),weight:100,direction:"horizontal",children:[p(t,"root")]}:(()=>{throw new L("INVALID_LAYOUT",`A v1 layout root must be a row, not "${t.typNode}"`,"root")})(),...typeof t.nodMaxd=="string"?{maximizedTabsetId:t.nodMaxd}:{}};return Nt(ot(b,n))}const at=2,Te=t=>typeof t=="object"&&t!==null&&!Array.isArray(t);function Ie(t,e){if(st(t))return e({code:"MIGRATED_FROM_V1",message:"Loaded a v1 layout; save it again to store the v2 format."}),ot(Rt(t,{onWarning:e}),e);if(!Te(t))throw new L("INVALID_LAYOUT","Expected a layout object");if(t.version!==at)throw new L("UNSUPPORTED_VERSION",`Unsupported layout version ${String(t.version)}; expected ${at}`,"version");return ot(t,e)}function xe(t,e){return t.lastActiveTabsetId&&z(e,t.lastActiveTabsetId)?t.lastActiveTabsetId:A(e)[0]?.id}function Lt(t,e,n,i=!0){if(v(t.root,e.id))return t;const o={type:"tab",id:e.id},r=e.target;let a=t.root;const d=s=>{const f=z(a,s),p=i?e.id:f.activeTabId;return j(a,s,[o],f.children.length,p)};if(r?.type==="tab"&&v(a,r.tabId)){const s=v(a,r.tabId),f=s.children.findIndex(p=>p.id===r.tabId)+(r.position==="after"?1:0);a=j(a,s.id,[o],f,i?e.id:s.activeTabId)}else r?.type==="tabset"&&z(a,r.tabsetId)?a=r.position==="center"?d(r.tabsetId):pt(a,r.tabsetId,V(e.id,n),r.position,n):r?.type==="root"||A(a).length===0?a=mt(a,V(e.id,n),r?.type==="root"?r.position:"right",n):a=d(xe(t,a));return a=_(a),R({...t,root:a,lastActiveTabsetId:i?v(a,e.id)?.id??null:t.lastActiveTabsetId})}function Ct(t,e,n,i=!0){const o=new Set(e.map(d=>d.id));let r=t.root;for(const d of Wt(r))o.has(d)||(r=k(r,d));let a=r===t.root?t:R({...t,root:r});for(const d of e)a=Lt(a,d,n,i);return a}const Pt="root";function ze(t){const e=t.onWarning??jt,n=me(t.createId),{createId:i,reserve:o}=n;let r=Vt(t.tabs,e);const a=c=>{const l=Ie(c,e);o(dt(l.root));const b={...l,lastActiveTabsetId:null,foldOrder:[]};return Ct(b,r,i,!1)},d=()=>{if(t.initialLayout)return a(t.initialLayout);o([Pt]);const c=r.map(l=>l.id);return{root:Jt(c,i,Pt),maximizedTabsetId:null,lastActiveTabsetId:null,foldOrder:[]}},s=ce(d(),_t(t,pe),t.onLayoutChange,e),f=(c,l)=>(e({code:"UNKNOWN_ID",message:`Unknown ${c} "${l}"`}),!1),p={getSnapshot:()=>s.snapshot,subscribe:c=>s.subscribe(c),setContainerRect:c=>s.setContainer(c),setOptions:c=>s.setConfig(_t(c,s.config)),setTabs(c){r=Vt(c,e),s.commit(Ct(s.model,r,i,!0),"tabs")},moveTab:(c,l)=>s.commit(Z(s.model,{type:"tab",tabId:c},l,i),"move"),moveTabset:(c,l)=>s.commit(Z(s.model,{type:"tabset",tabsetId:c},l,i),"move"),selectTab(c){const{model:l}=s,b=v(l.root,c);if(!b)return f("tab",c);if(b.activeTabId===c&&l.lastActiveTabsetId===b.id)return!1;const u=D(l.root,b.id,()=>({...b,activeTabId:c}));return s.commit({...l,root:u,lastActiveTabsetId:b.id},"select")},addTab(c,l){if(r.some(u=>u.id===c.id))return!1;const b=l?{...c,target:l}:c;return r=[...r,b],s.commit(Lt(s.model,b,i,!0),"tabs")},removeTab(c){if(!r.some(u=>u.id===c))return f("tab",c);r=r.filter(u=>u.id!==c);const{model:l}=s,b=k(l.root,c);return s.commit(R({...l,root:b}),"tabs")},resizeSplitter(c,l){const{model:b,rects:u,config:h}=s;if(b.maximizedTabsetId)return!1;const g=Et(b.root,u,h,c,l);return s.commit(g&&{...b,root:g},"resize")},moveSplitterBy(c,l){const b=s.rects.splitters.get(c),u=s.snapshot.splitters.get(c);if(!b||!u)return f("splitter",c);const h=b.x+b.width/2,g=b.y+b.height/2,m=u.direction==="horizontal"?{x:h+l,y:g}:{x:h,y:g+l};return p.resizeSplitter(c,m)},maximize:c=>s.commit(Zt(s.model,c),"maximize"),restore:()=>s.commit(It(s.model),"maximize"),toggleMaximize:c=>s.model.maximizedTabsetId===c?p.restore():p.maximize(c),fold:c=>s.commit(Xt(s.model,c),"fold"),unfold:c=>s.commit(Qt(s.model,c),"fold"),toggleFold(c){const l=s.snapshot.tabsets.get(c);return l?l.isFolded?p.unfold(c):p.fold(c):f("tabset",c)},...he(s,i),getDropTarget:(c,l,b)=>l.type==="splitter"?null:St(s.model,s.rects,c,l,b),getDropIndicatorRect:(c,l)=>lt(s.model,s.rects,c,l),listDropTargets:c=>c.type==="splitter"?[]:ge(s.model,c),getSplitterBounds:c=>oe(s.model.root,s.rects,s.config,c),load:c=>{s.commit(a(c))},reset(){n.reset(),s.commit(d(),"reset")},toJSON:()=>s.toJSON(),destroy:()=>s.destroy()};return p}function _t(t,e){return{minPanelSize:t.minPanelSize??e.minPanelSize,splitterSize:t.splitterSize??e.splitterSize,foldedSize:t.foldedSize??t.minPanelSize?.height??e.foldedSize}}function Vt(t,e){const n=new Set;return t.filter(i=>{if(!n.has(i.id))return n.add(i.id),!0;if($())throw new L("DUPLICATE_TAB_ID",`Duplicate tab id "${i.id}"`);return e({code:"DUPLICATE_TAB_ID",message:`Duplicate tab id "${i.id}" ignored`}),!1})}function Se(t,e,n){const{x:i,y:o,width:r,height:a}=t;return e.isFolded&&e.parentDirection==="horizontal"?{rect:{x:i+r,y:o,width:a,height:r},isRotated:!0}:{rect:{x:i,y:o,width:r,height:n},isRotated:!1}}function ve(t,e){return{x:t.x,y:t.y+e,width:t.width,height:Math.max(0,t.height-e)}}function Ae(t,e){const{style:n}=t;n.left=`${e.x}px`,n.top=`${e.y}px`,n.width=`${e.width}px`,n.height=`${e.height}px`}function De(t){let e=null,n=null;const i=()=>{n=null;const o=e;e=null,o&&t(o.value)};return{schedule(o){e={value:o},n===null&&(n=requestAnimationFrame(i))},flush(){n!==null&&(cancelAnimationFrame(n),i())},cancel(){n!==null&&cancelAnimationFrame(n),n=null,e=null}}}const Oe="2.0.0";x.DynamixLayoutError=L,x.LAYOUT_VERSION=at,x.applyRect=Ae,x.createFrameScheduler=De,x.createLayout=ze,x.getRootDropZoneRect=zt,x.getTabBarPlacement=Se,x.getTabContentRect=ve,x.isLayoutV1=st,x.migrateLayoutFromV1=Rt,x.version=Oe,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamix-layout/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Dynamix Layout/Core is a JavaScript package for creating dynamic layouts with ease.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dynamix-layout",
|
|
@@ -28,21 +28,23 @@
|
|
|
28
28
|
"url": "https://github.com/xcode-studio/dynamix-layout/issues"
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/xcode-studio/dynamix-layout#readme",
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
31
|
+
"type": "module",
|
|
32
|
+
"main": "./dist/index.cjs",
|
|
33
|
+
"module": "./dist/index.js",
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"unpkg": "./dist/index.umd.js",
|
|
35
36
|
"exports": {
|
|
36
37
|
".": {
|
|
37
38
|
"import": {
|
|
38
|
-
"types": "./dist/
|
|
39
|
-
"default": "./dist/
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"default": "./dist/index.js"
|
|
40
41
|
},
|
|
41
42
|
"require": {
|
|
42
|
-
"types": "./dist/
|
|
43
|
-
"default": "./dist/
|
|
43
|
+
"types": "./dist/index.d.cts",
|
|
44
|
+
"default": "./dist/index.cjs"
|
|
44
45
|
}
|
|
45
|
-
}
|
|
46
|
+
},
|
|
47
|
+
"./package.json": "./package.json"
|
|
46
48
|
},
|
|
47
49
|
"files": [
|
|
48
50
|
"dist",
|
|
@@ -55,7 +57,6 @@
|
|
|
55
57
|
"publishConfig": {
|
|
56
58
|
"access": "public"
|
|
57
59
|
},
|
|
58
|
-
"type": "module",
|
|
59
60
|
"engines": {
|
|
60
61
|
"node": ">=18"
|
|
61
62
|
},
|
package/dist/core.cjs
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class x{buffer;head=0;tail=0;count=0;capacity;constructor(t=16,e=[]){this.capacity=Math.max(t,e.length),this.buffer=new Array(this.capacity),e.forEach(n=>{this.enqueue(n)})}enqueue(t){this.count===this.capacity&&this.resize(),this.buffer[this.tail]=t,this.tail=(this.tail+1)%this.capacity,this.count++}enqueueFront(t){this.count===this.capacity&&this.resize(),this.head=(this.head-1+this.capacity)%this.capacity,this.buffer[this.head]=t,this.count++}insert(t,e){if(t<0||t>this.count)return!1;if(t===0)return this.enqueueFront(e),!0;if(t===this.count)return this.enqueue(e),!0;this.count===this.capacity&&this.resize();const n=t,i=this.count-t;return n<=i?this.shiftLeft(t,e):this.shiftRight(t,e),this.count++,!0}insertArray(t,e){if(t<0||t>this.count)return!1;if(e.length===0)return!0;if(t===0){for(let r=e.length-1;r>=0;r--)this.enqueueFront(e[r]);return!0}if(t===this.count)return e.forEach(r=>this.enqueue(r)),!0;for(;this.count+e.length>this.capacity;)this.resize();const n=t,i=this.count-t,s=e.length;return n<=i?this.shiftLeftArray(t,e):this.shiftRightArray(t,e),this.count+=s,!0}insertQueue(t,e){if(t<0||t>this.count)return!1;if(e.isEmpty())return!0;const n=e.size();if(t===0){const h=e.toArray();for(let u=h.length-1;u>=0;u--)this.enqueueFront(h[u]);return!0}if(t===this.count){for(const h of e)this.enqueue(h);return!0}for(;this.count+n>this.capacity;)this.resize();const i=e.toArray(),s=t,r=this.count-t;return s<=r?this.shiftLeftArray(t,i):this.shiftRightArray(t,i),this.count+=n,!0}push(t){this.enqueue(t)}unshift(t){this.enqueueFront(t)}dequeue(){if(this.count===0)return;const t=this.buffer[this.head];return this.head=(this.head+1)%this.capacity,this.count--,t}dequeueBack(){if(this.count===0)return;this.tail=(this.tail-1+this.capacity)%this.capacity;const t=this.buffer[this.tail];return this.count--,t}indexOf(t){for(let e=0;e<this.count;e++){const n=(this.head+e)%this.capacity;if(this.buffer[n]===t)return e}return-1}remove(t){const e=this.indexOf(t);return e===-1?!1:(this.removeAt(e),!0)}removeAt(t){if(t<0||t>=this.count)return;if(t===0)return this.dequeue();if(t===this.count-1)return this.dequeueBack();const e=(this.head+t)%this.capacity,n=this.buffer[e],i=t,s=this.count-t-1;return i<=s?this.shiftRightForRemoval(t):this.shiftLeftForRemoval(t),this.count--,n}shift(){return this.dequeue()}pop(){return this.dequeueBack()}fifoAdd(t){this.enqueue(t)}fifoRemove(){return this.dequeue()}filoAdd(t){this.enqueue(t)}filoRemove(){return this.dequeueBack()}lifoAdd(t){this.enqueueFront(t)}lifoRemove(){return this.dequeue()}liloAdd(t){this.enqueueFront(t)}liloRemove(){return this.dequeueBack()}get(t){if(t<0||t>=this.count)return;const e=(this.head+t)%this.capacity;return this.buffer[e]}set(t,e){if(t<0||t>=this.count)return!1;const n=(this.head+t)%this.capacity;return this.buffer[n]=e,!0}peek(){return this.count>0?this.buffer[this.head]:void 0}peekBack(){if(this.count===0)return;const t=(this.tail-1+this.capacity)%this.capacity;return this.buffer[t]}front(){return this.peek()}back(){return this.peekBack()}size(){return this.count}getCapacity(){return this.capacity}isEmpty(){return this.count===0}isFull(){return this.count===this.capacity}clear(){this.head=0,this.tail=0,this.count=0}toArray(){const t=[];for(let e=0;e<this.count;e++){const n=(this.head+e)%this.capacity;t.push(this.buffer[n])}return t}*[Symbol.iterator](){for(let t=0;t<this.count;t++){const e=(this.head+t)%this.capacity;yield this.buffer[e]}}*forward(){for(let t=0;t<this.count;t++){const e=(this.head+t)%this.capacity;yield this.buffer[e]}}*reverse(){for(let t=this.count-1;t>=0;t--){const e=(this.head+t)%this.capacity;yield this.buffer[e]}}*entries(){for(let t=0;t<this.count;t++){const e=(this.head+t)%this.capacity;yield[t,this.buffer[e]]}}*keys(){for(let t=0;t<this.count;t++)yield t}*values(){for(let t=0;t<this.count;t++){const e=(this.head+t)%this.capacity;yield this.buffer[e]}}toString(){return`Queue(${this.toArray().join(", ")})`}resize(){const t=this.capacity*2,e=new Array(t);for(let n=0;n<this.count;n++){const i=(this.head+n)%this.capacity;e[n]=this.buffer[i]}this.buffer=e,this.capacity=t,this.head=0,this.tail=this.count}shiftLeft(t,e){this.head=(this.head-1+this.capacity)%this.capacity;for(let i=0;i<t;i++){const s=(this.head+1+i)%this.capacity,r=(this.head+i)%this.capacity;this.buffer[r]=this.buffer[s]}const n=(this.head+t)%this.capacity;this.buffer[n]=e}shiftRight(t,e){for(let i=this.count-1;i>=t;i--){const s=(this.head+i)%this.capacity,r=(this.head+i+1)%this.capacity;this.buffer[r]=this.buffer[s]}const n=(this.head+t)%this.capacity;this.buffer[n]=e,this.tail=(this.tail+1)%this.capacity}shiftRightForRemoval(t){for(let e=t;e>0;e--){const n=(this.head+e-1)%this.capacity,i=(this.head+e)%this.capacity;this.buffer[i]=this.buffer[n]}this.head=(this.head+1)%this.capacity}shiftLeftForRemoval(t){for(let e=t;e<this.count-1;e++){const n=(this.head+e+1)%this.capacity,i=(this.head+e)%this.capacity;this.buffer[i]=this.buffer[n]}this.tail=(this.tail-1+this.capacity)%this.capacity}shiftLeftArray(t,e){const n=e.length;this.head=(this.head-n+this.capacity)%this.capacity;for(let i=0;i<t;i++){const s=(this.head+n+i)%this.capacity,r=(this.head+i)%this.capacity;this.buffer[r]=this.buffer[s]}for(let i=0;i<n;i++){const s=(this.head+t+i)%this.capacity;this.buffer[s]=e[i]}}shiftRightArray(t,e){const n=e.length;for(let i=this.count-1;i>=t;i--){const s=(this.head+i)%this.capacity,r=(this.head+i+n)%this.capacity;this.buffer[r]=this.buffer[s]}for(let i=0;i<n;i++){const s=(this.head+t+i)%this.capacity;this.buffer[s]=e[i]}this.tail=(this.tail+n)%this.capacity}}function N(o,t=(e,n)=>e===n){let e=o;const n=new Set;let i=[];const s=()=>e,r=(l,m=!1)=>{if(m){e=l;return}t(e,l)||(e=l,n.forEach(p=>p(e)),i.forEach(p=>p(e)),i=[])},h=()=>{n.forEach(l=>l(e)),i.forEach(l=>l(e)),i=[]},u=l=>(n.add(l),()=>n.delete(l)),f=()=>new Promise(l=>{i.push(l)});return{get:s,set:r,onChange:u,nextChange:f,triggerChange:h,onChangePromise:l=>{let m=!0;return(async()=>{for(;m;){const I=await f();if(!m)break;l(I)}})(),()=>{m=!1}}}}function T(o,t){if(o.size!==t.size)return!1;for(const[e,n]of o.entries()){const i=t.get(e);if(!i||!O(n,i))return!1}return!0}function O(o,t){if(o.typNode!==t.typNode||o.nodName!==t.nodName||o.uidNode!==t.uidNode||o.nodPart!==t.nodPart||o.nodFold!==t.nodFold||o.nodMaxd!==t.nodMaxd||o.nodHidden!==t.nodHidden||o.nodLocked!==t.nodLocked)return!1;const e=o.nodDims,n=t.nodDims;return e.x===n.x&&e.y===n.y&&e.w===n.w&&e.h===n.h}const A=()=>crypto.randomUUID(),S={set:(o,t)=>setTimeout(o,t),clear:o=>clearTimeout(o)},c={createId:A,timer:S,root:void 0,tree:null,minW:40,minH:40,bond:10,inst:null,maximized:null,collapsedSize:40,foldSeq:0};class a{static cache={dimMins:new Map,mapDirs:new Map,tabCnts:new Map,mapElem:new Map,tabOpts:N(new Map,T),nodOpts:N(new Map,T),bndOpts:N(new Map,T)};kids=new x;dims={w:0,h:0,x:0,y:0};unId;next=null;prev=null;type="row";name="";part=0;host=null;open="";collapsed=!1;foldedAt=0;constructor(t={}){const e={type:"row",host:null,name:"",part:100,dims:{w:0,h:0,x:0,y:0},unId:c.createId(),open:""};this.type=t.type??e.type,this.host=t.host??e.host,this.name=t.name??e.name,this.part=t.part??e.part,this.dims=t.dims??e.dims,this.open=t.open??e.open,this.unId=t.unId||e.unId}addBond(t,e=null){if(!e)return;const n=new E(t,this,e);a.cache.mapElem.set(n.unId,n)}getReqDimension(){const t=a.cache.dimMins.get(this.unId),e=a.cache.tabCnts.get(this.unId),n=Math.max(t.minWidth,e.horizontal*c.minW+Math.max(0,e.horizontal-1)*c.bond),i=Math.max(t.minHeight,e.vertical*c.minH+Math.max(0,e.vertical-1)*c.bond);return{width:n,height:i}}calcDimensions(){const t=a.cache.mapDirs.get(this.unId);if(!this.kids)return;let e=0;const n=a.cache.dimMins.get(this.unId)||{minWidth:0,minHeight:0};let i=0,s;for(const d of this.kids)d.collapsed||(e+=d.part,s=d);if(e===0)return;let r;t?r=this.dims.w-n.minWidth:r=this.dims.h-n.minHeight;const h=r<0;let u=0,f=0;for(const d of this.kids){const l=a.cache.dimMins.get(d.unId)||{minWidth:0,minHeight:0};let m=0;if(!h&&!d.collapsed){u+=d.part;const p=d===s?r:Math.round(r*u/e);m=p-f,f=p}t?(d.dims.w=l.minWidth+m,d.dims.h=this.dims.h,d.dims.x=this.dims.x+i,d.dims.y=this.dims.y,i+=d.dims.w+c.bond):(d.dims.h=l.minHeight+m,d.dims.w=this.dims.w,d.dims.y=this.dims.y+i,d.dims.x=this.dims.x,i+=d.dims.h+c.bond),d.next&&(t?d.next.dims={w:c.bond,h:d.dims.h,x:d.dims.x+d.dims.w,y:d.dims.y}:d.next.dims={w:d.dims.w,h:c.bond,x:d.dims.x,y:d.dims.y+d.dims.h})}}toJSON(){const t=[];for(const n of this.kids)t.push(n.toJSON());const e={typNode:this.type,nodPart:this.part,nodName:this.name,uidNode:this.unId};return this.open&&(e.nodOpen=this.open),this.collapsed&&(e.nodFold=!0),this===c.root&&c.maximized&&(e.nodMaxd=c.maximized),t.length>0&&(e.nodKids=t),e}}class E{dims={w:0,h:0,x:0,y:0};unId=c.createId();next=null;prev=null;host=null;constructor(t=null,e=null,n=null){this.host=t,this.next=e,this.prev=n,this.next&&(this.next.prev=this),this.prev&&(this.prev.next=this)}toJSON(){return{nodName:this.host?.name||"",typNode:"bond",uidNode:this.unId,nodPart:0,nodOpen:"",nodKids:[]}}}function*L(o){const t=new x;for(t.enqueue(o);!t.isEmpty();){const e=t.dequeue();if(e&&(yield e,e.nodKids&&e.nodKids.length>0))for(const n of e.nodKids)t.enqueue(n)}}function*P(o){const t=new x;for(t.enqueue(o);!t.isEmpty();){const e=t.dequeue();if(e&&(a.cache.mapElem.set(e.unId,e),yield e,e.kids.size()>0))for(const n of e.kids)t.enqueue(n)}}function*K(o,t){for(const e of t.kids)yield*o.NodeLayoutRecursiveIterator(e);yield t}function U(o,t){const e=a.cache.mapDirs.get(t.unId);if(e===void 0){console.warn(`Cannot update child directions for node ${t.unId}; its own direction is not set.`);return}for(const n of t.kids)a.cache.mapDirs.set(n.unId,!e),n.kids.size()>0&&(n.host=t,o.updateChildDirections(n),n.next&&a.cache.mapDirs.set(n.next.unId,!e))}function $(o,t=c.tree){if(!t)return;const e=o.JSONLayoutIterator(t),n=o.NodeLayoutIterator(c.root);for(a.cache.mapDirs.set(c.root.unId,!0);;){const i=e.next(),s=n.next();if(i.done||s.done)break;const r=i.value,h=s.value;!r||!h||o.createNodeTreeFromJSONTree(r,h)}o.calcTabsetCountAndMinDim()}function _(o,t,e){const n=a.cache.mapDirs.get(e.unId);for(const i of t.nodKids||[]){const s=o.createNodeFromJSON(i),r=e.kids.peekBack();s.host=e,s.addBond(s.host,r),e.kids.enqueue(s),a.cache.mapDirs.set(s.unId,!n)}e.type==="tabset"&&a.cache.mapElem.set(e.unId,e),e.type==="tab"&&a.cache.mapElem.set(e.unId,e)}function Y(o,t,e=c.root){const n=new x;for(n.enqueue(e),a.cache.mapDirs.set(c.root.unId,!0);!t.isEmpty();){const i=n.dequeue();if(!i)break;const s=a.cache.mapDirs.get(i.unId);if(t.size()===1){const d=t.dequeue(),l=new a({type:"tabset",host:i}),m=new a({type:"tab",host:l,name:d,unId:o.tabsIds.get(d??"")??c.createId()});l.open=m.name,l.kids.enqueue(m),i.kids.enqueue(l),a.cache.mapDirs.set(l.unId,!s),a.cache.mapDirs.set(m.unId,s),a.cache.mapElem.set(l.unId,l),a.cache.mapElem.set(m.unId,m);break}if(t.size()==2){const d=t.dequeue(),l=t.dequeue(),m=new a({type:"tabset",host:i}),p=new a({type:"tabset",host:i}),I=new a({type:"tab",host:m,name:d,unId:o.tabsIds.get(d??"")??c.createId()}),y=new a({type:"tab",host:p,name:l,unId:o.tabsIds.get(l??"")??c.createId()});m.open=I.name,p.open=y.name,m.kids.enqueue(I),p.kids.enqueue(y),i.kids.enqueue(m),i.kids.enqueue(p),p.addBond(i,m),a.cache.mapDirs.set(m.unId,!s),a.cache.mapDirs.set(p.unId,!s),a.cache.mapElem.set(m.unId,m),a.cache.mapElem.set(p.unId,p),a.cache.mapDirs.set(I.unId,s),a.cache.mapDirs.set(y.unId,s),a.cache.mapElem.set(I.unId,I),a.cache.mapElem.set(y.unId,y);break}const r=t.dequeue(),h=new a({type:"tabset",host:i}),u=new a({type:"row",host:i}),f=new a({type:"tab",host:h,name:r,unId:o.tabsIds.get(r??"")??c.createId()});h.open=f.name,h.kids.enqueue(f),i.kids.enqueue(h),i.kids.enqueue(u),u.addBond(i,h),a.cache.mapDirs.set(h.unId,!s),a.cache.mapDirs.set(u.unId,!s),a.cache.mapElem.set(h.unId,h),a.cache.mapDirs.set(f.unId,s),a.cache.mapElem.set(f.unId,f),n.enqueue(u)}o.calcTabsetCountAndMinDim()}function G(o,t){const e=new a({type:t.typNode,name:t.nodName,unId:t.uidNode,part:t.nodPart,dims:{w:0,h:0,x:0,y:0},open:typeof t.nodOpen=="string"?t.nodOpen:""});return e.collapsed=t.typNode==="tabset"&&t.nodFold===!0,t.typNode==="tab"&&(e.unId=o.tabsIds.get(t.nodName)||t.uidNode),e}function v(o){const t=a.cache.mapElem.get(o);return t instanceof a&&t.type==="tabset"?t:null}function J(o=c.root){let t=0;const e=n=>{n.type==="tabset"&&t++;for(const i of n.kids)e(i)};return e(o),t}function D(o){return o.type==="tabset"&&!!o.host&&o.host.kids.size()>1}function R(){return J()>1}function H(){const o=c.maximized;return o?v(o):null}function M(o,t){let e=null;for(const n of o.kids)n===t||!n.collapsed||(!e||n.foldedAt>e.foldedAt)&&(e=n);e&&(e.collapsed=!1)}function Q(o=c.root){let t=!1;const e=n=>{n.type==="tabset"&&(n.unId===c.maximized&&(t=!0),n.collapsed&&!D(n)&&(n.collapsed=!1)),n.type!=="tab"&&n.kids.size()>0&&[...n.kids].every(s=>s.collapsed)&&M(n);for(const i of n.kids)e(i)};e(o),t||(c.maximized=null)}function z(o,t){return!v(t)||!R()||c.maximized===t?!1:(c.maximized=t,o.calcDimensions(),!0)}function q(o){return c.maximized?(c.maximized=null,o.calcDimensions(),!0):!1}function j(o,t){return c.maximized===t?q(o):z(o,t)}function F(o,t){const e=v(t);if(!e||e.collapsed||!D(e))return!1;c.maximized=null,e.collapsed=!0,e.foldedAt=++c.foldSeq;const n=e.host;return[...n.kids].every(i=>i.collapsed)&&M(n,e),o.calcTabsetCountAndMinDim(),o.calcDimensions(),!0}function B(o,t){const e=v(t);return!e||!e.collapsed?!1:(e.collapsed=!1,o.calcTabsetCountAndMinDim(),o.calcDimensions(),!0)}function V(o,t){const e=v(t);return e?e.collapsed?B(o,t):F(o,t):!1}function X(o,t=c.root,e=!0){t===c.root&&e&&(Q(t),a.cache.tabCnts.clear(),a.cache.dimMins.clear(),a.cache.mapElem.clear(),a.cache.nodOpts.get().clear(),a.cache.bndOpts.get().clear());for(const n of o.NodeLayoutRecursiveIterator(t)){const i=a.cache.tabCnts,s=a.cache.dimMins;a.cache.mapElem.set(n.unId,n);const r=i.set(n.unId,{horizontal:0,vertical:0}).get(n.unId),h=s.set(n.unId,{minWidth:0,minHeight:0}).get(n.unId),u=a.cache.mapDirs.get(n.unId);if(n.type==="tab"&&(a.cache.mapElem.set(n.unId,n),s.set(n.unId,{minWidth:0,minHeight:0})),n.next&&a.cache.mapElem.set(n.next.unId,n.next),n.type==="tabset"&&(a.cache.mapElem.set(n.unId,n),s.set(n.unId,{minWidth:c.minW,minHeight:c.minH}),u?i.set(n.unId,{horizontal:0,vertical:1}):i.set(n.unId,{horizontal:1,vertical:0}),n.collapsed&&n.host&&(a.cache.mapDirs.get(n.host.unId)?(s.set(n.unId,{minWidth:c.collapsedSize,minHeight:c.minH}),i.get(n.unId).horizontal=0):(s.set(n.unId,{minWidth:c.minW,minHeight:c.collapsedSize}),i.get(n.unId).vertical=0))),n.type==="row"){for(const f of n.kids){const d=i.get(f.unId),l=s.get(f.unId);d&&(r.horizontal+=d.horizontal,r.vertical+=d.vertical,u?(h.minHeight=Math.max(h.minHeight,l.minHeight),h.minWidth+=l.minWidth):(h.minHeight+=l.minHeight,h.minWidth=Math.max(h.minWidth,l.minWidth)))}u?h.minWidth+=(n.kids.size()-1)*c.bond:h.minHeight+=(n.kids.size()-1)*c.bond}}t===c.root&&e&&o.pruneStaleDirections()}function Z(){for(const o of a.cache.mapDirs.keys())a.cache.mapElem.has(o)||a.cache.mapDirs.delete(o)}function tt(){const o=c.root.getReqDimension();let t=!1,e=c.root.dims.w,n=c.root.dims.h;return c.root.dims.w<o.width&&(e=o.width,t=!0),c.root.dims.h<o.height&&(n=o.height,t=!0),t&&(c.root.dims.w=e,c.root.dims.h=n),{adjustedW:e,adjustedH:n,wasAdjusted:t}}function et(o,t=c.root,e=!1){const n=t===c.root,i=d=>n?new Map:new Map(d.get()),s=i(a.cache.nodOpts),r=i(a.cache.bndOpts),h=i(a.cache.tabOpts);n&&o.calculateRootAdjustment();const u=H(),f=R();for(const d of o.NodeLayoutIterator(t)){d.calcDimensions();const l=a.cache.mapDirs.get(d.unId);if(d.type==="tabset"){const m=d===u,p=!!u&&!m,I=m?{...c.root.dims}:{...d.dims},y={typNode:d.type,nodName:d.name,uidNode:d.unId,nodPart:d.part,nodOpen:d.open,nodeDir:l,nodFold:d.collapsed&&!m,nodMaxd:m,nodHidden:p,nodFoldable:D(d),nodMaximizable:f,nodKids:Array.from(d.kids).map(b=>{const k={typNode:b.type,nodName:b.name,uidNode:b.unId,nodPart:b.part,nodOpen:d.open===b.name,nodeDir:!l,nodHidden:p,nodFold:d.collapsed&&!m,nodDims:{...I}};return h.set(b.unId,k),k}),nodDims:I};s.set(d.unId,y)}if(d.next&&d.type!=="tab"){const m={typNode:"bond",nodName:d.name,uidNode:d.next.unId,nodeDir:l,nodPart:0,nodHidden:!!u,nodLocked:d.collapsed||!!d.next.next?.collapsed,nodDims:{...d.next.dims}};r.set(d.next.unId,m)}}a.cache.nodOpts.set(s,e),a.cache.bndOpts.set(r,e),a.cache.tabOpts.set(h,e)}function nt(o,t,e=!1,n=2){if(c.root.dims=t,e){o.calcDimensions(c.root);return}o.cntdown&&(c.timer.clear(o.cntdown),o.cntdown=null),o.cntdown=c.timer.set(()=>{o.cntdown=null,o.calcDimensions()},n)}function it(o,t,e,n=!1,i=2){if(n){o.updateSliderDimension(t,e);return}o.cntdown&&(c.timer.clear(o.cntdown),o.cntdown=null),o.cntdown=c.timer.set(()=>{o.cntdown=null,o.updateSliderDimension(t,e)},i)}function ot(o,t,e){const n=a.cache.mapElem.get(t);if(!n||!(n instanceof E)){console.warn(`Bond with id ${t} not found or is not a Bond instance`);return}const i=a.cache.mapDirs.get(n.host.unId),s=n.prev,r=n.next,h=n.host;if(!s||!r||!h){console.warn("Missing prev, next, or host node",s,r,h);return}if(s.collapsed||r.collapsed||c.maximized)return;const u=a.cache.dimMins.get(s.unId)||{minWidth:0,minHeight:0},f=a.cache.dimMins.get(r.unId)||{minWidth:0,minHeight:0},d=c.bond/2;if(i){const l=r.dims.x+r.dims.w,m=s.dims.x+u.minWidth+d,p=l-f.minWidth-d,I=Math.max(m,Math.min(p,e.x));n.dims.x=I-d,s.dims.w=n.dims.x-s.dims.x,r.dims.x=I+d,r.dims.w=l-r.dims.x;const y=Math.max(0,s.dims.w-u.minWidth),b=Math.max(0,r.dims.w-f.minWidth),k=y+b,g=s.part+r.part;k>0?(s.part=y/k*g,r.part=b/k*g):(s.part=g/2,r.part=g/2)}else{const l=r.dims.y+r.dims.h,m=s.dims.y+u.minHeight+d,p=l-f.minHeight-d,I=Math.max(m,Math.min(p,e.y));n.dims.y=I-d,s.dims.h=n.dims.y-s.dims.y,r.dims.y=I+d,r.dims.h=l-r.dims.y;const y=Math.max(0,s.dims.h-u.minHeight),b=Math.max(0,r.dims.h-f.minHeight),k=y+b,g=s.part+r.part;k>0?(s.part=y/k*g,r.part=b/k*g):(s.part=g/2,r.part=g/2)}o.calcDimensions(h)}function st(o,t,e,n){const i=a.cache.mapElem.get(t);let s=a.cache.mapElem.get(e);return!i||!(i instanceof a)||!s||!(s instanceof a)?(console.warn(`Source node ${t} not found or is not a Node instance`),!1):i?.type=="tab"&&i.host===s&&s.kids.size()<2?(console.warn("Cannot move to self as it has only one tab"),!1):i?.type=="tabset"&&s?.host===i?(console.warn("Cannot move tabset to self as it is already a child"),!1):!i||!s?(console.warn(`Source or destination node not found: ${t}, ${e}`),!1):i===s?(console.warn("Source and destination nodes are the same, no action taken."),!1):!i.host||!s.host&&s.type!=="row"?(console.warn(`Source node or destination node's host is null: ${i.unId}, ${s.unId}`),!1):s.type==="row"&&s!==c.root?(console.warn(`Cannot move relative to a nested row: ${s.unId}`),!1):s.type==="row"&&n==="contain"?(console.warn(`Cannot move to a row with 'contain' layout: ${s.unId}`),!1):i.type==="row"||(s.type==="tabset"&&n==="contain"&&(s=s.kids.peekBack()||s),i===s)?!1:o.isOnlyContent(i)?(console.warn("Cannot move the only tabset or tab in the layout"),!1):(c.maximized=null,i.collapsed=!1,s.type==="tab"&&(n==="contain"||n==="left"||n==="right")?o.moveNodeAsTab(i,s,n):s.type==="row"&&n!=="contain"?o.moveRelativeToRoot(i,s,n):s.type==="tabset"&&n!=="contain"&&o.moveRelativeToTabset(i,s,n),o.calcTabsetCountAndMinDim(),o.calcDimensions(c.root,!0),!0)}function at(o,t){let e=0;for(const n of o.NodeLayoutRecursiveIterator(c.root))n.type==="tabset"&&e++;return e!==1?!1:t.type==="tabset"||t.type==="tab"&&t.host?.kids.size()===1}function rt(o,t,e,n){if(!e||!e.host){console.warn(`Destination node ${e.unId} has no host, cannot move.`);return}o.removeNode(t);const i=e.host,s=i.kids.indexOf(e);if(s===void 0||s===-1)return;const r=n==="contain"||n==="left",h=r?s:s+1,u=i.kids.get(h+1),f=i.kids.get(h-1),d=e.next,l=e.prev;if(!r&&d?a.cache.mapElem.delete(d.unId):r&&l&&a.cache.mapElem.delete(l.unId),t.type=="tab")r?(f&&t.addBond(i,f),e.addBond(i,t)):(t.addBond(i,e),u&&u.addBond(i,t)),i.kids.insert(h,t),t.host=i,i.open=t.name,i.collapsed=!1;else if(t.type=="tabset"){const m=t.kids.peek(),p=t.kids.peekBack();r?(m&&f&&m.addBond(i,f),p&&e&&e.addBond(i,p)):(m&&e&&m.addBond(i,e),p&&u&&u.addBond(i,p)),i.kids.insertQueue(h,t.kids);for(const I of t.kids)I.host=i,I.next&&(I.next.host=i);i.open=p?p.name:"",i.collapsed=!1}o.updateChildDirections(i)}const dt={root:(o,t)=>o===t,tabset:(o,t)=>o!==t};function C(o,t,e,n,i){if(o.removeNode(t),t.type!=="tab"&&t.type!=="tabset")return;const s=a.cache.mapDirs.get(e.unId)===!1,r=n==="left"||n==="right",h=n==="top"||n==="left";let u=t;t.type==="tab"&&(u=new a({type:"tabset",host:e.host}),u.kids.enqueue(t),u.open=t.name,t.host=u),dt[i](s,r)?o.insertNodeWithNewParent(u,e,h):o.insertNode(e,u,h)}function ct(o,t,e,n){C(o,t,e,n,"root")}function ht(o,t,e,n){C(o,t,e,n,"tabset")}function ut(o,t,e,n){const i=t.host;if(t==c.root){const l=c.root.kids.peek(),m=c.root.kids.peekBack();n?(c.root.kids.enqueueFront(e),l&&l.addBond(c.root,e)):(c.root.kids.enqueue(e),m&&e.addBond(c.root,m)),e.host=c.root,o.updateChildDirections(c.root);return}if(!i){console.warn(`Destination node ${t.unId} has no host, cannot insert.`);return}const s=i.kids.indexOf(t);if(s===-1){console.warn(`Destination node ${t.unId} not found in its host's kids.`);return}const r=a.cache.mapDirs.get(i.unId);r&&a.cache.mapDirs.set(e.unId,!r);const h=i.kids.get(s+1),u=i.kids.get(s-1),f=t.next,d=t.prev;e.host=i,n?(i.kids.insert(s,e),t.addBond(i,e),u&&e.addBond(i,u),d&&a.cache.mapElem.delete(d.unId)):(i.kids.insert(s+1,e),e.addBond(i,t),h&&h.addBond(i,e),f&&a.cache.mapElem.delete(f.unId)),o.updateChildDirections(i)}function lt(o,t,e,n){const i=new x,s=new a({type:"tabset",host:e.host});if(!e||!t){console.warn(`Destination node ${e.unId} has no host, cannot insert.`);return}if(e===c.root){const h=new a({type:"row",host:e});if(e.kids.size()===0)e.kids.enqueue(t),t.host=e;else if(e.kids.size()==1&&e.kids.peek()?.type==="tabset"){const u=e.kids.dequeue();if(!u){console.warn(`No kid found in destination node ${e.unId}, cannot insert.`);return}n?(h.kids.enqueue(t),h.kids.enqueue(u),e.kids.enqueue(h),u.addBond(h,t)):(h.kids.enqueue(u),h.kids.enqueue(t),t.addBond(h,u),e.kids.enqueue(h)),t.host=h,u.host=h}else if(e.kids.size()==1&&e.kids.peek()?.type==="row"){const u=e.kids.peek(),f=u?.kids.peek(),d=u?.kids.peekBack();n&&u?(u.kids.enqueueFront(t),f&&f.addBond(u,t)):u&&(u.kids.enqueue(t),d&&t.addBond(u,d)),t.host=u}else if(e.kids.size()>1){const u=new a({type:"row",host:e}),f=new a({type:"row",host:u});for(const d of e.kids)f.kids.enqueue(d),d.host=f,d.next&&(d.next.host=f);t.host=u,e.kids.clear(),n?(u.kids.enqueueFront(t),u.kids.enqueue(f),f.addBond(u,t)):(u.kids.enqueue(f),u.kids.enqueue(t),t.addBond(u,f)),e.kids.enqueue(u)}o.updateChildDirections(e);return}t.host=e,s.host=e,s.kids=e.kids,s.open=e.open;const r=a.cache.mapDirs.get(e.unId);for(const h of s.kids)h.host=s,h.next&&(h.next.host=s),a.cache.mapDirs.set(h.unId,r);for(const h of t.kids)h.host=t,h.next&&(h.next.host=t),a.cache.mapDirs.set(h.unId,r);a.cache.mapDirs.set(s.unId,!r),a.cache.mapDirs.set(t.unId,!r),n?(i.enqueue(t),i.enqueue(s),e.kids=i,e.type="row",s.addBond(e,t)):(i.enqueue(s),i.enqueue(t),e.kids=i,e.type="row",t.addBond(e,s))}function ft(o,t){if(!t.host||!t.host.host){console.warn(`Source node ${t.unId} has no host, cannot move.`);return}const e=t.host,n=t.host.host,i=n.kids.indexOf(e),s=n.kids.get(i-1),r=n.kids.get(i+1),h=t.kids.peek(),u=t.kids.peekBack();o.removeKid(e);let f=i;if(t.type=="row"&&e){s&&h&&h.addBond(n,s),r&&u&&r.addBond(n,u);for(const d of t.kids)d.host=n,d.next&&(d.next.host=n),n.kids.insert(f,d),a.cache.mapDirs.set(d.unId,!a.cache.mapDirs.get(n.unId)),a.cache.dimMins.delete(d.unId),f++}else if(t.type=="tabset"){s&&t.addBond(n,s),r&&r.addBond(n,t),n.kids.insert(f,t),t.host=n,a.cache.mapDirs.set(t.unId,!a.cache.mapDirs.get(n.unId));for(const d of t.kids)a.cache.mapDirs.set(d.unId,a.cache.mapDirs.get(n.unId)),a.cache.dimMins.delete(d.unId)}}function mt(o,t=!0){const e=o.host,n=o.prev,i=o.next;if(o.host=null,o.next=null,o.prev=null,n&&(n.next=null),i&&(i.prev=null),!t)return o;n&&i&&n.prev&&i.next?n.prev.addBond(e,i.next):n&&n.prev?n.prev.next=null:i&&i.next&&(i.next.prev=null)}function pt(o,t){if(!t.host){console.warn("Kid node has no host, cannot remove.");return}const e=t?.host,n=e?.host;if(o.removeKid(t),t.type==="tabset"&&e.kids.size()===1){const i=e.kids.peek();i&&o.moveAdjacentNodeToGrandParent(i)}else if(t.type==="tab"&&e.kids.size()===0&&n.kids.size()===2){o.removeKid(e);const i=n?.kids.peek();i&&o.moveAdjacentNodeToGrandParent(i)}else if(t.type==="tab"&&e.kids.size()===0&&n.kids.size()>2)o.removeKid(e);else if(t.type==="tab"&&e.open===t.name&&e.kids.size()>0){const i=e.kids.peek();i&&(e.open=i.name)}}function It(o){if(!o.host){console.warn("Kid node has no host, cannot remove.");return}const t=o.host,e=t.kids.indexOf(o),n=t.kids.get(e+1),i=t.kids.get(e-1),s=o.next,r=o.prev;if(e===-1){console.warn("Kid node not found in its host's kids.");return}s&&a.cache.mapElem.delete(s.unId),r&&a.cache.mapElem.delete(r.unId),n&&i?n.addBond(t,i):n?n.prev=null:i&&(i.next=null),t.kids.removeAt(e),a.cache.mapElem.delete(o.unId),a.cache.dimMins.delete(o.unId),a.cache.mapDirs.delete(o.unId),a.cache.tabCnts.delete(o.unId),o.type==="tabset"&&a.cache.mapElem.delete(o.unId),o.type==="tab"&&a.cache.mapElem.delete(o.unId),o.host=null,o.next=null,o.prev=null}function yt(){a.cache.dimMins.clear(),a.cache.mapDirs.clear(),a.cache.tabCnts.clear(),a.cache.mapElem.clear(),a.cache.nodOpts.get().clear(),a.cache.bndOpts.get().clear()}class w{static get _root(){return c.root}static set _root(t){c.root=t}static get _tree(){return c.tree}static set _tree(t){c.tree=t}static get _minW(){return c.minW}static set _minW(t){c.minW=t}static get _minH(){return c.minH}static set _minH(t){c.minH=t}static get _bond(){return c.bond}static set _bond(t){c.bond=t}static get _inst(){return c.inst}static set _inst(t){c.inst=t}nodeOps;cntdown=null;tabsIds=new Map;constructor(t={}){const e={tabs:[],tree:null,minW:40,minH:40,bond:10,uqid:"dynamix-layout-root",tabsIds:new Map,...t};this.tabsIds=e.tabsIds,c.createId=e.createId??A,c.timer=e.timer??S,c.collapsedSize=e.collapsedSize??e.minH,w._tree=e.tree??null,c.maximized=e.tree?.nodMaxd??null,w._root=new a({unId:e.uqid,name:e.uqid,type:"row"}),this.nodeOps=N(new Map,T),w._minW=e.minW,w._minH=e.minH,w._bond=e.bond;const n=new x(e.tabs.length,e.tabs);w._tree?this.createNodeLayout():this.createBinaryNodeTreeFromQueue(n),w._inst=this}*JSONLayoutIterator(t){yield*L(t)}*NodeLayoutIterator(t){yield*P(t)}*NodeLayoutRecursiveIterator(t){yield*K(this,t)}updateChildDirections(t){return U(this,t)}createNodeLayout(t=w._tree){return $(this,t)}createNodeTreeFromJSONTree(t,e){return _(this,t,e)}createBinaryNodeTreeFromQueue(t,e=w._root){return Y(this,t,e)}createNodeFromJSON(t){return G(this,t)}calcTabsetCountAndMinDim(t=w._root,e=!0){return X(this,t,e)}pruneStaleDirections(){return Z()}calculateRootAdjustment(){return tt()}calcDimensions(t=w._root,e=!1){return et(this,t,e)}updateDimension(t,e=!1,n=2){return nt(this,t,e,n)}updateSlider(t,e,n=!1,i=2){return it(this,t,e,n,i)}updateSliderDimension(t,e){return ot(this,t,e)}updateTree(t,e,n){return st(this,t,e,n)}isOnlyContent(t){return at(this,t)}moveNodeAsTab(t,e,n){return rt(this,t,e,n)}moveRelativeToRoot(t,e,n){return ct(this,t,e,n)}moveRelativeToTabset(t,e,n){return ht(this,t,e,n)}insertNode(t,e,n){return ut(this,t,e,n)}insertNodeWithNewParent(t,e,n){return lt(this,t,e,n)}moveAdjacentNodeToGrandParent(t){return ft(this,t)}removeRelation(t,e=!0){return mt(t,e)}removeNode(t){return pt(this,t)}removeKid(t){return It(t)}clearAllCache(){return yt()}get maximizedId(){return H()?.unId??null}maximize(t){return z(this,t)}restore(){return q(this)}toggleMaximize(t){return j(this,t)}collapse(t){return F(this,t)}expand(t){return B(this,t)}toggleCollapse(t){return V(this,t)}}const wt=6;function bt(o,t,e){const{left:n,top:i,width:s,height:r}=o,h=t-n,u=e-i;return h<s/3?{area:"left",left:n,top:i,width:s/2,height:r}:h>2*s/3?{area:"right",left:n+s/2,top:i,width:s/2,height:r}:u<r/3?{area:"top",left:n,top:i,width:s,height:r/2}:u>2*r/3?{area:"bottom",left:n,top:i+r/2,width:s,height:r/2}:{area:"contain",left:n+s*.1,top:i+r*.1,width:s*.8,height:r*.8}}function kt(o,t){const{x:e,y:n,w:i,h:s}=o;switch(t){case"left":return{area:t,left:e,top:n,width:i/2,height:s};case"right":return{area:t,left:e+i/2,top:n,width:i/2,height:s};case"top":return{area:t,left:e,top:n,width:i,height:s/2};case"bottom":return{area:t,left:e,top:n+s/2,width:i,height:s/2}}}function gt(o,t,e,n){if(t.length===0||n<o.top||n>o.bottom)return null;const i=t[0],s=t[t.length-1];let r=wt;if(e>s.right)return{index:t.length-1,area:"right",left:s.right+1,top:s.top,width:r-2,height:s.height};if(e<i.left)return{index:0,area:"left",left:i.left-r+1,top:i.top,width:r-2,height:i.height};let h=0,u=1/0,f=!1;t.forEach((m,p)=>{const I=m.left+m.width/2,y=Math.abs(e-I);y<u&&(u=y,h=p,f=e<I)});const d=f?h>0:h<t.length-1;t.length>1&&d&&(r=t[1].left-i.right);const l=t[h];return{index:h,area:f?"left":"right",left:f?l.left-r+1:l.right+1,top:l.top,width:r-2,height:l.height}}function xt(o,t){return o.area===t.area&&o.left===t.left&&o.top===t.top&&o.width===t.width&&o.height===t.height}function W(o,{x:t,y:e,w:n,h:i}){o.style.left=`${t}px`,o.style.top=`${e}px`,o.style.width=`${n}px`,o.style.height=`${i}px`}function Nt(o,t){return{x:o.x,y:o.y+t,w:o.w,h:Math.max(0,o.h-t)}}function Tt(o,t){const{x:e,y:n,w:i,h:s}=o.nodDims,r=o.nodeDir===!1;return o.nodFold&&r?{rect:{x:e+i,y:n,w:s,h:i},rotated:!0}:{rect:{x:e,y:n,w:i,h:t},rotated:!1}}function vt(o,t){W(o,t.rect),o.style.transformOrigin="0 0",o.style.transform=t.rotated?"rotate(90deg)":""}function Et(o){let t=null,e=null;const n=()=>{e=null;const i=t;t=null,i&&o(i.value)};return{schedule(i){t={value:i},e===null&&(e=requestAnimationFrame(n))},flush(){e!==null&&(cancelAnimationFrame(e),n())},cancel(){e!==null&&cancelAnimationFrame(e),e=null,t=null}}}(()=>{if(typeof window>"u")return;const o="color: #03A9F4; font-weight: bold; line-height: 1.2;",t="color: #E0E0E0; font-size: 12px;",e="color: #42a5f5; font-size: 12px;",n="color: #9E9E9E; font-size: 10px;",i=`
|
|
2
|
-
██████╗ ██╗ ██╗ ███╗ ██╗ █████╗ ███╗ ███╗ ██████╗ ██╗ ██╗
|
|
3
|
-
██╔══██╗╚██╗ ██╔╝ ████╗ ██║ ██╔══██╗ ████╗ ████║ ╚═██╔═╝ ╚██╗██╔╝
|
|
4
|
-
██║ ██║ ╚████╔╝ ██╔██╗ ██║ ███████║ ██╔████╔██║ ██║ ╚███╔╝
|
|
5
|
-
██║ ██║ ╚██╔╝ ██║╚██╗██║ ██╔══██║ ██║╚██╔╝██║ ██║ ██╔██╗
|
|
6
|
-
██████╔╝ ██║ ██║ ╚████║ ██║ ██║ ██║ ╚═╝ ██║ ██████╗ ██╔╝ ██╗
|
|
7
|
-
╚═════╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
|
|
8
|
-
██╗ █████╗ ██╗ ██╗ ██████╗ ██╗ ██╗████████╗
|
|
9
|
-
██║ ██╔══██╗ ╚██╗ ██╔╝ ██╔═══██╗ ██║ ██║╚══██╔══╝
|
|
10
|
-
██║ ███████║ ╚████╔╝ ██║ ██║ ██║ ██║ ██║
|
|
11
|
-
██║ ██╔══██║ ╚██╔╝ ██║ ██║ ██║ ██║ ██║
|
|
12
|
-
███████╗ ██║ ██║ ██║ ╚██████╔╝ ╚█████╔╝ ██║
|
|
13
|
-
╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚════╝ ╚═╝
|
|
14
|
-
`;console.groupCollapsed("%cDYNAMIX LAYOUT (click to expand)","color: #03A9F4; font-weight: bold; font-size: 14px;"),console.log(`%c${i}`,o),console.log("%c A powerful, dynamic layout system 🚀",t),console.log(`%c ⚡ For docs and more info,
|
|
15
|
-
⚡ visit: https://github.com/xcode-studio/dynamix-layout`,e),console.log(`%cMIT License
|
|
16
|
-
|
|
17
|
-
Copyright (c) 2025 Akash Aman <sir.akashaman@gmail.com> (https://akash.cx)
|
|
18
|
-
|
|
19
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
20
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
21
|
-
in the Software without restriction, including without limitation the rights
|
|
22
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
23
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
24
|
-
furnished to do so, subject to the following conditions:
|
|
25
|
-
|
|
26
|
-
The above copyright notice and this permission notice shall be included in all
|
|
27
|
-
copies or substantial portions of the Software.
|
|
28
|
-
|
|
29
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
30
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
31
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
32
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
33
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
34
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
35
|
-
SOFTWARE.
|
|
36
|
-
`,n),console.groupEnd(),typeof window<"u"&&(window.__DYNAMIX_LAYOUT__={__LICENSE__:`MIT License
|
|
37
|
-
|
|
38
|
-
Copyright (c) 2025 Akash Aman <sir.akashaman@gmail.com> (https://akash.cx)
|
|
39
|
-
|
|
40
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
41
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
42
|
-
in the Software without restriction, including without limitation the rights
|
|
43
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
44
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
45
|
-
furnished to do so, subject to the following conditions:
|
|
46
|
-
|
|
47
|
-
The above copyright notice and this permission notice shall be included in all
|
|
48
|
-
copies or substantial portions of the Software.
|
|
49
|
-
|
|
50
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
51
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
52
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
53
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
54
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
55
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
56
|
-
SOFTWARE.
|
|
57
|
-
`,__LAYOUT__:w})})();exports.Bond=E;exports.DynamixLayoutCore=w;exports.Node=a;exports.Queue=x;exports.areNodeOptionsEqual=O;exports.areNodeOptionsMapEqual=T;exports.createFrameScheduler=Et;exports.createReactiveState=N;exports.getNavbarDropPreview=gt;exports.getRootSplitPreview=kt;exports.getTabBodyRect=Nt;exports.getTabbarPlacement=Tt;exports.getTabsetDropPreview=bt;exports.isSameDropPreview=xt;exports.placeTabbar=vt;exports.setElementRect=W;
|